Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoltan Varga <vargaz@gmail.com>2020-09-09 00:52:33 +0300
committerGitHub <noreply@github.com>2020-09-09 00:52:33 +0300
commit6e103e7191dcb17120032f2516cc7f8e9e04c32e (patch)
treea3ee2ea7450809dac229fc084683df3f335942ad
parent427395f4c6a18466c26d0cf782bed106d05e77ae (diff)
Remove netcore/ directory from the mono/mono repository. (#20361)
-rw-r--r--Makefile.am3
-rw-r--r--netcore/.gitignore16
-rw-r--r--netcore/CoreFX.issues.rsp898
-rw-r--r--netcore/CoreFX.issues_interpreter.rsp31
-rw-r--r--netcore/CoreFX.issues_linux.rsp39
-rw-r--r--netcore/CoreFX.issues_linux_arm64.rsp2
-rw-r--r--netcore/CoreFX.issues_mac.rsp2
-rw-r--r--netcore/CoreFX.issues_windows.rsp73
-rw-r--r--netcore/Directory.Build.props61
-rw-r--r--netcore/Directory.Build.targets3
-rw-r--r--netcore/Makefile345
-rw-r--r--netcore/NuGet.config26
-rw-r--r--netcore/README.md48
-rw-r--r--netcore/System.Private.CoreLib/AssemblyInfo.cs7
-rw-r--r--netcore/System.Private.CoreLib/Makefile12
-rw-r--r--netcore/System.Private.CoreLib/System.Private.CoreLib.csproj305
-rw-r--r--netcore/System.Private.CoreLib/resources/SR.common.cs38
-rw-r--r--netcore/System.Private.CoreLib/resources/SR.cs1225
-rw-r--r--netcore/System.Private.CoreLib/resources/Strings.resx3661
-rw-r--r--netcore/System.Private.CoreLib/shared/CodeAnalysis.ruleset206
-rw-r--r--netcore/System.Private.CoreLib/shared/Internal/IO/File.Unix.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/Internal/IO/File.Windows.cs76
-rw-r--r--netcore/System.Private.CoreLib/shared/Internal/IO/File.cs77
-rw-r--r--netcore/System.Private.CoreLib/shared/Internal/Padding.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/Internal/Resources/PRIExceptionInfo.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/Internal/Resources/WindowsRuntimeResourceManagerBase.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/Internal/Runtime/CompilerServices/Unsafe.cs439
-rw-r--r--netcore/System.Private.CoreLib/shared/Internal/Threading/Tasks/AsyncCausalitySupport.cs45
-rw-r--r--netcore/System.Private.CoreLib/shared/Internal/Win32/RegistryKey.cs487
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.Errors.cs210
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.IOErrors.cs173
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.Libraries.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Casing.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Collation.cs59
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.ICU.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Idna.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Locale.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Utils.cs48
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Access.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ChDir.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Close.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FLock.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FSync.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FTruncate.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs24
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCwd.cs73
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetEUid.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetHostName.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetPid.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetPwUid.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetRandomBytes.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetSystemTimeAsTicks.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetTimestamp.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetUnixName.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetUnixRelease.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.LSeek.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.LockFileRegion.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MksTemps.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MountPoints.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Open.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.OpenFlags.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.PathConf.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Permissions.cs32
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.PosixFAdvise.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Read.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ReadDir.cs69
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ReadLink.cs64
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Stat.cs66
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.SysConf.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.SysLog.cs58
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Unlink.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Write.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.ActivityControl.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EVENT_INFO_CLASS.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EtwEnableCallback.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventActivityIdControl.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventRegister.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventSetInformation.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventTraceGuidsEx.cs58
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventUnregister.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventWriteString.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventWriteTransfer.cs49
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.LookupAccountNameW.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCloseKey.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCreateKeyEx.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteKeyEx.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteValue.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumKeyEx.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumValue.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegFlushKey.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegOpenKeyEx.cs35
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryInfoKey.cs34
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryValueEx.cs53
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegSetValueEx.cs62
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegistryConstants.cs65
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.BCryptGenRandom.GetRandomBytes.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.BCryptGenRandom.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.NTSTATUS.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.BOOL.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.BOOLEAN.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.Errors.cs46
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.Libraries.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CancelIoEx.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CloseHandle.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CompletionPort.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Constants.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.EventWaitHandle.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ExpandEnvironmentStrings.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FILE_INFO_BY_HANDLE_CLASS.cs35
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FILE_TIME.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileAttributes.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileTimeToSystemTime.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileTypes.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindClose.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FlushFileBuffers.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FormatMessage.cs88
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FreeEnvironmentStrings.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FreeLibrary.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GET_FILEEX_INFO_LEVELS.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCPInfo.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetComputerName.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentDirectory.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcess_IntPtr.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetEnvironmentStrings.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetEnvironmentVariable.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileInformationByHandleEx.cs24
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileType_SafeHandle.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetLogicalDrives.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetProcessMemoryInfo.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetProcessTimes.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemDirectoryW.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemInfo.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTime.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimeAsFileTime.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimePreciseAsFileTime.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimes.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetTempFileNameW.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetTempPathW.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetVersionExW.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GlobalMemoryStatusEx.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Globalization.cs145
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.HandleTypes.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.IsWow64Process_IntPtr.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LoadLibraryEx.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LocalAlloc.cs24
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LockFile.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MAX_PATH.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MEMORYSTATUSEX.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MEMORY_BASIC_INFORMATION.cs24
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MUI.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MultiByteToWideChar.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Mutex.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OSVERSIONINFOEX.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OutputDebugString.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceCounter.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceFrequency.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryUnbiasedInterruptTime.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_IntPtr.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_NativeOverlapped.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ResolveLocaleName.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SECURITY_ATTRIBUTES.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SYSTEM_INFO.cs38
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SecurityOptions.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Semaphore.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetCurrentDirectory.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetEndOfFile.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetEnvironmentVariable.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetFilePointerEx.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetThreadErrorMode.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SystemTimeToFileTime.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TimeZone.Registry.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TimeZone.cs93
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TzSpecificLocalTimeToSystemTime.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerSetConditionMask.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerifyVersionExW.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualAlloc.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualFree.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualQuery.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WIN32_FILE_ATTRIBUTE_DATA.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WIN32_FIND_DATA.cs32
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WideCharToMultiByte.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_IntPtr.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_NativeOverlapped.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Normaliz/Interop.Idna.cs34
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Normaliz/Interop.Normalization.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/NtDll/Interop.NtQueryInformationFile.cs46
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/NtDll/Interop.NtQuerySystemInformation.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoCreateGuid.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoTaskMemAlloc.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringByteLen.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringLen.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysFreeString.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Secur32/Interop.GetUserNameExW.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs320
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.Constants.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.LoadString.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.SendMessageTimeout.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/CriticalHandleMinusOneIsInvalid.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/CriticalHandleZeroOrMinusOneIsInvalid.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs138
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs37
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFindHandle.Windows.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeHandleMinusOneIsInvalid.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeHandleZeroOrMinusOneIsInvalid.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeRegistryHandle.Windows.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeWaitHandle.Windows.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/README.md19
-rw-r--r--netcore/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems1379
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AccessViolationException.cs50
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Action.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs147
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Activator.cs55
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AggregateException.cs467
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AppContext.cs156
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AppContextConfigHelper.cs88
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AppDomain.Unix.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AppDomain.Windows.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AppDomain.cs433
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AppDomainSetup.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ApplicationException.cs58
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ArgumentException.cs102
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ArgumentNullException.cs55
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ArgumentOutOfRangeException.cs96
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ArithmeticException.cs53
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Array.Enumerators.cs212
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Array.cs2269
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ArraySegment.cs326
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ArrayTypeMismatchException.cs53
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AssemblyLoadEventArgs.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AssemblyLoadEventHandler.cs8
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AsyncCallback.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Attribute.cs139
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AttributeTargets.cs35
-rw-r--r--netcore/System.Private.CoreLib/shared/System/AttributeUsageAttribute.cs52
-rw-r--r--netcore/System.Private.CoreLib/shared/System/BadImageFormatException.cs118
-rw-r--r--netcore/System.Private.CoreLib/shared/System/BitConverter.cs475
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Boolean.cs381
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffer.Unix.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffer.Windows.cs24
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffer.cs554
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/ArrayPool.cs102
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/ArrayPoolEventSource.cs104
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Binary/Reader.cs128
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Binary/ReaderBigEndian.cs192
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Binary/ReaderLittleEndian.cs192
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Binary/WriterBigEndian.cs180
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Binary/WriterLittleEndian.cs180
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs265
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/IMemoryOwner.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/IPinnable.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/MemoryHandle.cs57
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/MemoryManager.cs74
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/OperationStatus.cs34
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/StandardFormat.cs209
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/FormattingHelpers.CountDigits.cs138
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Constants.cs34
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs256
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Boolean.cs105
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs92
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.L.cs66
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.O.cs104
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.R.cs66
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.cs153
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.E.cs104
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.F.cs101
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.G.cs107
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.cs119
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Float.cs122
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs219
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.Default.cs148
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.N.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.cs52
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.Default.cs135
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs58
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs46
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.cs52
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.cs208
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs222
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/ParserHelpers.cs74
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs61
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Default.cs96
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.G.cs177
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Helpers.cs162
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.O.cs290
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.R.cs221
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.cs138
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs79
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs184
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs243
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.D.cs443
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.N.cs383
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.cs199
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.D.cs354
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.N.cs336
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.X.cs341
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.cs192
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Number.cs324
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.BigG.cs132
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.C.cs66
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.LittleG.cs62
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.cs191
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpanSplitter.cs223
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs501
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Buffers/Utilities.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ByReference.cs38
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Byte.cs276
-rw-r--r--netcore/System.Private.CoreLib/shared/System/CLSCompliantAttribute.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/CannotUnloadAppDomainException.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Char.cs995
-rw-r--r--netcore/System.Private.CoreLib/shared/System/CharEnumerator.cs77
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/ArrayList.cs2713
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Comparer.cs73
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/CompatibleComparer.cs61
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs817
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueueSegment.cs340
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/IProducerConsumerCollection.cs70
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/IProducerConsumerCollectionDebugView.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/DictionaryEntry.cs45
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs1056
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/Comparer.cs149
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs1663
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/EqualityComparer.cs191
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IAsyncEnumerable.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IAsyncEnumerator.cs24
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/ICollection.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/ICollectionDebugView.cs34
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IComparer.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IDictionary.cs50
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IDictionaryDebugView.cs80
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEnumerable.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEnumerator.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEqualityComparer.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IList.cs32
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyCollection.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyDictionary.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyList.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/KeyNotFoundException.cs35
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/KeyValuePair.cs78
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/List.cs1147
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/NonRandomizedStringEqualityComparer.cs34
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Generic/ValueListBuilder.cs86
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/HashHelpers.SerializationInfoTable.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/HashHelpers.cs111
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/Hashtable.cs1550
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/ICollection.cs67
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/IComparer.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/IDictionary.cs47
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/IDictionaryEnumerator.cs68
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/IEnumerable.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/IEnumerator.cs38
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/IEqualityComparer.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/IHashCodeProvider.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/IList.cs57
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/IStructuralComparable.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/IStructuralEquatable.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/KeyValuePairs.cs34
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/ListDictionaryInternal.cs437
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs365
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs228
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs250
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ComponentModel/EditorBrowsableAttribute.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ComponentModel/EditorBrowsableState.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Configuration/Assemblies/AssemblyHashAlgorithm.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Configuration/Assemblies/AssemblyVersionCompatibility.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Convert.Base64.cs218
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Convert.cs2870
-rw-r--r--netcore/System.Private.CoreLib/shared/System/CoreLib.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/CurrentSystemTimeZone.cs195
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DBNull.cs118
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DataMisalignedException.cs42
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DateTime.Unix.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DateTime.Win32.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DateTime.Windows.cs215
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DateTime.cs1602
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DateTimeKind.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DateTimeOffset.cs855
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DayOfWeek.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Decimal.DecCalc.cs2699
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Decimal.cs1025
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DefaultBinder.cs1276
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Delegate.cs127
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/NullableAttributes.cs128
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/SuppressMessageAttribute.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/ConditionalAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractException.cs55
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractFailedEventArgs.cs47
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs702
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Debug.cs251
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.Unix.cs107
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.Windows.cs77
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.cs111
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggableAttribute.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerBrowsableAttribute.cs41
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerDisplayAttribute.cs51
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerHiddenAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerNonUserCodeAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerStepThroughAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerStepperBoundaryAttribute.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerTypeProxyAttribute.cs46
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerVisualizerAttribute.cs97
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/StackFrame.cs248
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/StackTrace.cs421
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/StackTraceHiddenAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.Unix.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.Windows.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.cs142
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/SymbolStore/ISymbolDocumentWriter.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/ActivityTracker.cs663
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterGroup.cs263
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterPayload.cs130
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/DiagnosticCounter.cs168
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventActivityOptions.cs41
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventCounter.cs202
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventDescriptor.cs145
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs1353
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs6204
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSourceException.cs52
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/FrameworkEventSource.cs161
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IEventProvider.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingEventCounter.cs94
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingPollingCounter.cs96
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/PollingCounter.cs86
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/StubEnvironment.cs376
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ArrayTypeInfo.cs66
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs129
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ConcurrentSetItem.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/DataCollector.cs368
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EmptyStruct.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EnumHelper.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EnumerableTypeInfo.cs68
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventDataAttribute.cs148
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventFieldAttribute.cs78
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventFieldFormat.cs130
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventIgnoreAttribute.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventPayload.cs150
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventSourceActivity.cs314
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs107
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs230
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/InvokeTypeInfo.cs95
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs126
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyAnalysis.cs41
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs272
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs299
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/Statics.cs693
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingDataCollector.cs125
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingDataType.cs351
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs890
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTraits.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs243
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingMetadataCollector.cs381
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs179
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs104
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/Winmeta.cs185
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DivideByZeroException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DllNotFoundException.cs45
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Double.cs448
-rw-r--r--netcore/System.Private.CoreLib/shared/System/DuplicateWaitObjectException.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Empty.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/EntryPointNotFoundException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Enum.cs1147
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Environment.NoRegistry.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Environment.SpecialFolder.cs115
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Environment.SpecialFolderOption.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Environment.Unix.cs466
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Environment.Variables.Windows.cs166
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Environment.Win32.cs455
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Environment.Windows.cs140
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Environment.cs198
-rw-r--r--netcore/System.Private.CoreLib/shared/System/EnvironmentVariableTarget.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/EventArgs.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/EventHandler.cs10
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Exception.cs202
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ExecutionEngineException.cs49
-rw-r--r--netcore/System.Private.CoreLib/shared/System/FieldAccessException.cs42
-rw-r--r--netcore/System.Private.CoreLib/shared/System/FlagsAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/FormatException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/FormattableString.cs104
-rw-r--r--netcore/System.Private.CoreLib/shared/System/GCMemoryInfo.cs61
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Gen2GcCallback.cs113
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/BidiCategory.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/Calendar.cs732
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CalendarAlgorithmType.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.Unix.cs460
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.Windows.cs448
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.cs380
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CalendarWeekRule.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CalendricalCalculationsHelper.cs412
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CharUnicodeInfo.cs321
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CharUnicodeInfoData.cs1576
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/ChineseLunisolarCalendar.cs302
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Invariant.cs249
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs1148
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Windows.cs606
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs1503
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CompareOptions.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Unix.cs421
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs718
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.cs2252
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Unix.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Windows.cs59
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.cs1166
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CultureNotFoundException.cs104
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/CultureTypes.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs1380
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfo.cs2604
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs712
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs6106
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeStyles.cs49
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/DaylightTime.cs45
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/DigitShapes.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/EastAsianLunisolarCalendar.cs692
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/GlobalizationExtensions.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs488
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendarHelper.cs660
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendarTypes.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/HebrewCalendar.cs904
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/HebrewNumber.cs447
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.Unix.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.Win32.cs83
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.cs473
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/ISOWeek.cs162
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.Unix.cs145
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.Windows.cs129
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.cs871
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/InternalGlobalizationHelper.cs48
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Unix.cs96
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Win32.cs198
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.cs294
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseLunisolarCalendar.cs216
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/JulianCalendar.cs371
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/KoreanCalendar.cs187
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/KoreanLunisolarCalendar.cs1235
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/LocaleData.Unix.cs4573
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/Normalization.Unix.cs134
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/Normalization.Windows.cs148
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/NumberFormatInfo.cs750
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/NumberStyles.cs70
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/PersianCalendar.cs418
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/RegionInfo.cs198
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/SortKey.cs110
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/SortVersion.cs83
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/StringInfo.cs296
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanCalendar.cs198
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanLunisolarCalendar.cs234
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/TextElementEnumerator.cs92
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.Unix.cs57
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.Windows.cs55
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs870
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/ThaiBuddhistCalendar.cs168
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanFormat.cs658
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs1705
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanStyles.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/UmAlQuraCalendar.cs653
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Globalization/UnicodeCategory.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Guid.Unix.cs37
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Guid.Windows.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Guid.cs1175
-rw-r--r--netcore/System.Private.CoreLib/shared/System/HResults.cs128
-rw-r--r--netcore/System.Private.CoreLib/shared/System/HashCode.cs423
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IAsyncDisposable.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IAsyncResult.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ICloneable.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IComparable.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IConvertible.cs62
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ICustomFormatter.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IDisposable.cs60
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IEquatable.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IFormatProvider.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IFormattable.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/BinaryReader.cs611
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/BinaryWriter.cs469
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/DirectoryNotFoundException.cs42
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/DisableMediaInsertionPrompt.cs41
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/DriveInfoInternal.Unix.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/DriveInfoInternal.Windows.cs87
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/EncodingCache.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/EndOfStreamException.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/Error.cs42
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileAccess.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileLoadException.cs85
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileMode.cs38
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs107
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileOptions.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileShare.cs43
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileStream.Linux.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileStream.OSX.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs852
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileStream.Win32.cs107
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs1627
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileStream.cs915
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs259
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/IOException.cs41
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/MemoryStream.cs868
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/Path.Unix.cs147
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/Path.Windows.cs286
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/Path.cs930
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/PathHelper.Windows.cs251
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/PathInternal.Unix.cs98
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs414
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/PathInternal.cs248
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/PathTooLongException.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/PersistedFiles.Names.Unix.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/PersistedFiles.Unix.cs164
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/PinnedBufferMemoryStream.cs61
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/SeekOrigin.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/Stream.cs1400
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/StreamHelpers.CopyValidation.cs70
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/StreamReader.cs1347
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/StreamWriter.cs1078
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/TextReader.cs406
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/TextWriter.cs1016
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryAccessor.cs668
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs951
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStreamWrapper.cs195
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IO/Win32Marshal.cs101
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IObservable.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IObserver.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IProgress.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ISpanFormattable.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Index.cs150
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IndexOutOfRangeException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/InsufficientExecutionStackException.cs35
-rw-r--r--netcore/System.Private.CoreLib/shared/System/InsufficientMemoryException.cs48
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Int16.cs289
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Int32.cs270
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Int64.cs257
-rw-r--r--netcore/System.Private.CoreLib/shared/System/IntPtr.cs195
-rw-r--r--netcore/System.Private.CoreLib/shared/System/InvalidCastException.cs47
-rw-r--r--netcore/System.Private.CoreLib/shared/System/InvalidOperationException.cs45
-rw-r--r--netcore/System.Private.CoreLib/shared/System/InvalidProgramException.cs42
-rw-r--r--netcore/System.Private.CoreLib/shared/System/InvalidTimeZoneException.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Lazy.cs536
-rw-r--r--netcore/System.Private.CoreLib/shared/System/LocalAppContextSwitches.Common.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/LocalAppContextSwitches.cs45
-rw-r--r--netcore/System.Private.CoreLib/shared/System/LocalDataStoreSlot.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MarshalByRefObject.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Marvin.OrdinalIgnoreCase.cs97
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Marvin.cs256
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Math.cs1036
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MathF.cs410
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MemberAccessException.cs50
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Memory.cs517
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MemoryDebugView.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Globalization.cs416
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Trim.cs921
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MemoryExtensions.cs2004
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MethodAccessException.cs42
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MidpointRounding.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MissingFieldException.cs58
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MissingMemberException.cs76
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MissingMethodException.cs57
-rw-r--r--netcore/System.Private.CoreLib/shared/System/MulticastNotSupportedException.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/System/NonSerializedAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/NotFiniteNumberException.cs68
-rw-r--r--netcore/System.Private.CoreLib/shared/System/NotImplementedException.cs43
-rw-r--r--netcore/System.Private.CoreLib/shared/System/NotSupportedException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/NullReferenceException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Nullable.cs133
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Number.BigInteger.cs1245
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Number.DiyFp.cs157
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Number.Dragon4.cs483
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Number.Formatting.cs2539
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Number.Grisu3.cs1054
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Number.NumberBuffer.cs124
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Number.NumberToFloatingPointBits.cs630
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Number.Parsing.cs2024
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/BitOperations.cs371
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/ConstantHelper.cs143
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/ConstantHelper.tt62
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/GenerationConfig.ttinclude186
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Hashing/HashHelpers.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Matrix3x2.cs807
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Matrix4x4.cs2208
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Plane.cs368
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Quaternion.cs792
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Register.cs173
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Register.tt47
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Vector.cs4469
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Vector.tt1729
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Vector2.cs465
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Vector2_Intrinsics.cs297
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Vector3.cs483
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Vector3_Intrinsics.cs320
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Vector4.cs531
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Vector4_Intrinsics.cs351
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/VectorMath.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Numerics/Vector_Operations.cs896
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Object.cs85
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ObjectDisposedException.cs74
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ObsoleteAttribute.cs52
-rw-r--r--netcore/System.Private.CoreLib/shared/System/OperatingSystem.cs83
-rw-r--r--netcore/System.Private.CoreLib/shared/System/OperationCanceledException.cs73
-rw-r--r--netcore/System.Private.CoreLib/shared/System/OutOfMemoryException.cs43
-rw-r--r--netcore/System.Private.CoreLib/shared/System/OverflowException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ParamArrayAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ParamsArray.cs76
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ParseNumbers.cs659
-rw-r--r--netcore/System.Private.CoreLib/shared/System/PasteArguments.Unix.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/System/PasteArguments.Windows.cs64
-rw-r--r--netcore/System.Private.CoreLib/shared/System/PasteArguments.cs99
-rw-r--r--netcore/System.Private.CoreLib/shared/System/PlatformID.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/PlatformNotSupportedException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Progress.cs103
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Random.cs256
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Range.cs124
-rw-r--r--netcore/System.Private.CoreLib/shared/System/RankException.cs45
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ReadOnlyMemory.cs439
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ReadOnlySpan.cs393
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AmbiguousMatchException.cs35
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Assembly.cs354
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyAlgorithmIdAttribute.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCompanyAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyConfigurationAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyContentType.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCopyrightAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCultureAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDefaultAliasAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDelaySignAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDescriptionAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyFileVersionAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyFlagsAttribute.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyInformationalVersionAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyKeyFileAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyKeyNameAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyMetadataAttribute.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs478
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFlags.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFormatter.cs154
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyProductAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblySignatureKeyAttribute.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyTitleAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyTrademarkAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyVersionAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Binder.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/BindingFlags.cs51
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/CallingConventions.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ConstructorInfo.cs50
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/CorElementType.cs46
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeExtensions.cs175
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeFormatException.cs34
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs75
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeTypedArgument.cs82
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/DefaultMemberAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/AssemblyBuilderAccess.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/EventToken.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/FieldToken.cs37
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/FlowControl.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/Label.cs45
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/MethodToken.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OpCodeType.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OpCodes.cs2549
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs125
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OperandType.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PEFileKinds.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PackingSize.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/ParameterToken.cs32
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PropertyToken.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/SignatureToken.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/StackBehaviour.cs49
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/StringToken.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Emit/TypeToken.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/EventAttributes.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/EventInfo.cs125
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ExceptionHandlingClause.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ExceptionHandlingClauseOptions.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/FieldAttributes.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs82
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/GenericParameterAttributes.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ICustomAttributeProvider.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/IReflect.cs76
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/IReflectableType.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ImageFileMachine.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/InterfaceMapping.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/IntrospectionExtensions.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/InvalidFilterCriteriaException.cs34
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/LocalVariableInfo.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ManifestResourceInfo.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/MemberFilter.cs8
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs69
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/MemberTypes.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/MethodAttributes.cs50
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs121
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/MethodBody.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/MethodImplAttributes.cs38
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/MethodInfo.Internal.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Missing.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Module.cs168
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ModuleResolveEventHandler.cs8
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ObfuscateAssemblyAttribute.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ObfuscationAttribute.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ParameterAttributes.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ParameterInfo.cs110
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ParameterModifier.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/Pointer.cs51
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/PortableExecutableKinds.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ProcessorArchitecture.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/PropertyAttributes.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs84
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ReflectionContext.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ReflectionTypeLoadException.cs73
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ResourceAttributes.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/ResourceLocation.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/SignatureArrayType.cs46
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/SignatureByRefType.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs85
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/SignatureGenericMethodParameterType.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/SignatureGenericParameterType.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/SignatureHasElementType.cs47
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/SignaturePointerType.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs146
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs224
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/StrongNameKeyPair.cs45
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/TargetException.cs34
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/TargetInvocationException.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/TargetParameterCountException.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/TypeAttributes.cs61
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs131
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/TypeFilter.cs8
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Reflection/TypeInfo.cs94
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ResolveEventArgs.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ResolveEventHandler.cs10
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/FastResourceComparer.cs142
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/FileBasedResourceGroveler.cs121
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/IResourceGroveler.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/IResourceReader.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs501
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/MissingManifestResourceException.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/MissingSatelliteAssemblyException.cs60
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/NeutralResourcesLanguageAttribute.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/ResourceFallbackManager.cs83
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.Uap.cs198
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs811
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs169
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/ResourceReader.cs1094
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs260
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/ResourceTypeCode.cs47
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs464
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/SatelliteContractVersionAttribute.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Resources/UltimateResourceFallbackLocation.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/AmbiguousImplementationException.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AccessedThroughPropertyAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncIteratorMethodBuilder.cs66
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncIteratorStateMachineAttribute.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilderAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs158
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncStateMachineAttribute.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskCache.cs66
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilder.cs144
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs607
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs175
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs513
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncVoidMethodBuilder.cs163
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerArgumentExpressionAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerFilePathAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerLineNumberAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilationRelaxations.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilationRelaxationsAttribute.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilerGeneratedAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilerGlobalScopeAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs806
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredAsyncDisposable.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredCancelableAsyncEnumerable.cs78
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs225
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs156
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CustomConstantAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DateTimeConstantAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DecimalConstantAttribute.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DefaultDependencyAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DependencyAttribute.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DisablePrivateReflectionAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DiscardableAttribute.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ExtensionAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FixedAddressValueTypeAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FixedBufferAttribute.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FormattableStringFactory.cs58
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IAsyncStateMachine.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IAsyncStateMachineBox.cs24
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ICastable.cs61
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/INotifyCompletion.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ITuple.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IndexerNameAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/InternalsVisibleToAttribute.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IntrinsicAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsByRefLikeAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsConst.cs10
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsReadOnlyAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsVolatile.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IteratorStateMachineAttribute.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/LoadHint.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodCodeType.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodImplAttribute.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodImplOptions.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/PreserveDependencyAttribute.cs62
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ReferenceAssemblyAttribute.cs32
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeCompatibilityAttribute.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs42
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs109
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs41
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/SpecialNameAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StateMachineAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StringFreezingAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StrongBox.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/SuppressIldasmAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs556
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TupleElementNamesAttribute.cs57
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TypeForwardedToAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/UnsafeValueTypeAttribute.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs198
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/YieldAwaitable.cs195
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/Cer.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/Consistency.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/CriticalFinalizerObject.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/ReliabilityContractAttribute.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs83
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/HandleProcessCorruptedStateExceptionsAttribute.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/GCSettings.cs69
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs74
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BestFitMappingAttribute.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs74
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CallingConvention.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CharSet.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CollectionsMarshal.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComImportAttribute.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComInterfaceType.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs37
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IBindCtx.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPoint.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPointContainer.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnectionPoints.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnections.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumMoniker.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumString.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumVARIANT.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IMoniker.cs49
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IPersistFile.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IRunningObjectTable.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IStream.cs43
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeComp.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo.cs303
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo2.cs51
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib2.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CriticalHandle.cs211
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultCharSetAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultDllImportSearchPathsAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs23
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportAttribute.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportSearchPath.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs81
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/FieldOffsetAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandle.cs195
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandleType.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GuidAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InterfaceTypeAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs41
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LCIDConversionAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LayoutKind.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.NoCom.cs204
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs66
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs131
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs978
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalAsAttribute.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs535
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeCallableAttribute.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs248
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OptionalAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OutAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/PreserveSigAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs47
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs393
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs253
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/StructLayoutAttribute.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs65
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs20
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedType.cs48
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VarEnum.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationToken.cs34
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/AdvSimd.PlatformNotSupported.cs2172
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/AdvSimd.cs2174
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Aes.PlatformNotSupported.cs48
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Aes.cs48
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/ArmBase.PlatformNotSupported.cs81
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/ArmBase.cs82
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Crc32.PlatformNotSupported.cs82
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Crc32.cs82
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha1.PlatformNotSupported.cs62
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha1.cs62
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha256.PlatformNotSupported.cs48
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha256.cs48
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs1859
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128DebugView_1.cs118
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs192
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs1962
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256DebugView_1.cs118
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs193
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs694
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64DebugView_1.cs118
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs146
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Aes.PlatformNotSupported.cs59
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Aes.cs56
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx.PlatformNotSupported.cs1227
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx.cs1226
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx2.PlatformNotSupported.cs2191
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx2.cs2669
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi1.PlatformNotSupported.cs119
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi1.cs119
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi2.PlatformNotSupported.cs97
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi2.cs97
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Enums.cs169
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Fma.PlatformNotSupported.cs191
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Fma.cs190
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Lzcnt.PlatformNotSupported.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Lzcnt.cs41
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Pclmulqdq.PlatformNotSupported.cs32
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Pclmulqdq.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Popcnt.PlatformNotSupported.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Popcnt.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse.PlatformNotSupported.cs574
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse.cs573
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse2.PlatformNotSupported.cs1680
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse2.cs1684
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse3.PlatformNotSupported.cs92
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse3.cs90
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse41.PlatformNotSupported.cs713
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse41.cs713
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse42.PlatformNotSupported.cs57
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse42.cs57
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Ssse3.PlatformNotSupported.cs165
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Ssse3.cs165
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs801
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.Unix.cs68
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.Windows.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.Unix.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.Windows.cs102
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.cs404
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Remoting/ObjectHandle.cs21
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationToken.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationTracker.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IDeserializationCallback.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IFormatterConverter.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IObjectReference.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/ISafeSerializationData.cs207
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/ISerializable.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationException.cs38
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs642
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs127
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/StreamingContext.cs52
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Versioning/NonVersionableAttribute.cs33
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Runtime/Versioning/TargetFrameworkAttribute.cs41
-rw-r--r--netcore/System.Private.CoreLib/shared/System/RuntimeType.cs390
-rw-r--r--netcore/System.Private.CoreLib/shared/System/SByte.cs306
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/AllowPartiallyTrustedCallersAttribute.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/CryptographicException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/IPermission.cs15
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/ISecurityEncodable.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/IStackWalk.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/PartialTrustVisibilityLevel.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/PermissionSet.cs53
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/Permissions/PermissionState.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/Principal/IIdentity.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/Principal/IPrincipal.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/Principal/PrincipalPolicy.cs19
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecureString.Unix.cs38
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs52
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecureString.cs480
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecurityCriticalAttribute.cs35
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecurityCriticalScope.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecurityElement.cs606
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecurityException.cs89
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecurityRuleSet.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecurityRulesAttribute.cs27
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecuritySafeCriticalAttribute.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecurityTransparentAttribute.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SecurityTreatAsSafeAttribute.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/SuppressUnmanagedCodeSecurityAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/UnverifiableCodeAttribute.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Security/VerificationException.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/SerializableAttribute.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Single.cs440
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Span.cs479
-rw-r--r--netcore/System.Private.CoreLib/shared/System/SpanDebugView.cs26
-rw-r--r--netcore/System.Private.CoreLib/shared/System/SpanHelpers.BinarySearch.cs81
-rw-r--r--netcore/System.Private.CoreLib/shared/System/SpanHelpers.Byte.cs1663
-rw-r--r--netcore/System.Private.CoreLib/shared/System/SpanHelpers.Char.cs1087
-rw-r--r--netcore/System.Private.CoreLib/shared/System/SpanHelpers.T.cs924
-rw-r--r--netcore/System.Private.CoreLib/shared/System/SpanHelpers.cs417
-rw-r--r--netcore/System.Private.CoreLib/shared/System/StackOverflowException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/String.Comparison.cs933
-rw-r--r--netcore/System.Private.CoreLib/shared/System/String.Manipulation.cs1875
-rw-r--r--netcore/System.Private.CoreLib/shared/System/String.Searching.cs491
-rw-r--r--netcore/System.Private.CoreLib/shared/System/String.cs718
-rw-r--r--netcore/System.Private.CoreLib/shared/System/StringComparer.cs358
-rw-r--r--netcore/System.Private.CoreLib/shared/System/StringComparison.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/StringSplitOptions.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/SystemException.cs35
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/ASCIIEncoding.cs879
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/ASCIIUtility.Helpers.cs108
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/ASCIIUtility.cs1732
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/CodePageDataItem.cs32
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Decoder.cs339
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs218
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/DecoderExceptionFallback.cs113
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/DecoderFallback.cs324
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/DecoderNLS.cs434
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/DecoderReplacementFallback.cs171
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Encoder.cs333
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs217
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/EncoderExceptionFallback.cs137
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs384
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/EncoderNLS.cs388
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/EncoderReplacementFallback.cs194
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Encoding.Internal.cs1288
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Encoding.cs1491
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/EncodingData.cs296
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/EncodingInfo.cs39
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/EncodingNLS.cs296
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/EncodingProvider.cs132
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/EncodingTable.cs193
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Latin1Encoding.cs877
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/NormalizationForm.cs14
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Rune.cs1338
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/SpanRuneEnumerator.cs51
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.Debug.cs43
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs2662
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/StringBuilderCache.cs64
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/StringRuneEnumerator.cs70
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/TrimType.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/UTF32Encoding.cs1192
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/UTF7Encoding.cs925
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/UTF8Encoding.Sealed.cs108
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs858
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.Validation.cs434
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.cs215
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8.cs221
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Helpers.cs862
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Transcoding.cs1479
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Validation.cs738
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.WhiteSpace.cs138
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.cs112
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/UnicodeDebug.cs52
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/UnicodeEncoding.cs1877
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/UnicodeUtility.cs186
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.AppendFormat.cs355
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs310
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ThreadAttributes.cs28
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ThreadStaticAttribute.cs25
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/AbandonedMutexException.cs74
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ApartmentState.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs497
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/AutoResetEvent.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/CancellationToken.cs356
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenRegistration.cs170
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs1041
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/CompressedStack.cs46
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/DeferredDisposableLifetime.cs114
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/EventResetMode.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.Windows.cs97
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.cs53
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs639
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/IOCompletionCallback.cs9
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/IThreadPoolWorkItem.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs289
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/LazyThreadSafetyMode.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/LockRecursionException.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/LowLevelLifoSemaphore.Windows.cs79
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/LowLevelLifoSemaphore.cs295
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ManualResetEvent.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ManualResetEventSlim.cs726
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs97
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Mutex.cs62
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/NativeOverlapped.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ParameterizedThreadStart.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.CpuUtilizationReader.Unix.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.CpuUtilizationReader.Windows.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.GateThread.cs144
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.HillClimbing.Complex.cs40
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.HillClimbing.cs455
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.ThreadCounts.cs85
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.WaitThread.cs421
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.WorkerThread.cs259
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.cs308
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPoolEventSource.cs123
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ReaderWriterLockSlim.cs1656
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Semaphore.Windows.cs88
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Semaphore.cs67
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/SemaphoreFullException.cs29
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/SemaphoreSlim.cs937
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/SendOrPostCallback.cs8
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/SpinLock.cs648
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/SpinWait.cs349
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs62
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/SynchronizationLockException.cs45
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/AsyncCausalityTracer.Noop.cs46
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/AsyncCausalityTracerConstants.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs773
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs1377
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs2108
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ProducerConsumerQueues.cs369
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs82
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs279
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs6614
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskAsyncEnumerableExtensions.cs38
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCanceledException.cs97
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCompletionSource.cs341
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs820
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExceptionHolder.cs309
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExtensions.cs48
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskFactory.cs3042
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs649
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskSchedulerException.cs76
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskToApm.cs121
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ThreadPoolTaskScheduler.cs124
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TplEventSource.cs571
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs796
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Thread.Unix.cs13
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Thread.Windows.cs12
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Thread.cs390
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadAbortException.cs37
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadInt64PersistentCounter.cs144
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadInterruptedException.cs43
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadLocal.cs813
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.Portable.cs431
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs1295
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadPoolBoundHandle.PlatformNotSupported.cs72
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadPriority.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadStart.cs18
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadStartException.cs30
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadState.cs24
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/ThreadStateException.cs46
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Timeout.cs17
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/TimeoutHelper.cs54
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Timer.cs863
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Portable.cs139
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Unix.cs11
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Windows.cs38
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/Volatile.cs232
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/WaitHandle.cs425
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Threading/WaitHandleCannotBeOpenedException.cs32
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ThrowHelper.cs1009
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeSpan.cs494
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeZone.cs274
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.AdjustmentRule.cs275
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.StringSerializer.cs625
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.TransitionTime.cs161
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs1745
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs980
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.cs2002
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeZoneNotFoundException.cs31
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TimeoutException.cs44
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Tuple.cs1142
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TupleExtensions.cs932
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Type.Enum.cs183
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Type.Helpers.cs502
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Type.cs413
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TypeAccessException.cs37
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TypeCode.cs47
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TypeInitializationException.cs69
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TypeLoadException.cs67
-rw-r--r--netcore/System.Private.CoreLib/shared/System/TypeUnloadedException.cs36
-rw-r--r--netcore/System.Private.CoreLib/shared/System/UInt16.cs278
-rw-r--r--netcore/System.Private.CoreLib/shared/System/UInt32.cs264
-rw-r--r--netcore/System.Private.CoreLib/shared/System/UInt64.cs263
-rw-r--r--netcore/System.Private.CoreLib/shared/System/UIntPtr.cs185
-rw-r--r--netcore/System.Private.CoreLib/shared/System/UnauthorizedAccessException.cs48
-rw-r--r--netcore/System.Private.CoreLib/shared/System/UnhandledExceptionEventArgs.cs22
-rw-r--r--netcore/System.Private.CoreLib/shared/System/UnhandledExceptionEventHandler.cs8
-rw-r--r--netcore/System.Private.CoreLib/shared/System/UnitySerializationHolder.cs64
-rw-r--r--netcore/System.Private.CoreLib/shared/System/ValueTuple.cs2246
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Version.cs436
-rw-r--r--netcore/System.Private.CoreLib/shared/System/Void.cs16
-rw-r--r--netcore/System.Private.CoreLib/shared/System/WeakReference.T.cs74
-rw-r--r--netcore/System.Private.CoreLib/shared/System/WeakReference.cs51
-rw-r--r--netcore/System.Private.CoreLib/shared/System/WinRTFolderPaths.cs104
-rw-r--r--netcore/System.Private.CoreLib/src/LinkerDescriptor/System.Private.CoreLib.xml735
-rw-r--r--netcore/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.Unix.Mono.cs22
-rw-r--r--netcore/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs50
-rw-r--r--netcore/System.Private.CoreLib/src/Mono/MonoDomain.cs24
-rw-r--r--netcore/System.Private.CoreLib/src/Mono/MonoDomainSetup.cs45
-rw-r--r--netcore/System.Private.CoreLib/src/Mono/MonoListItem.cs13
-rw-r--r--netcore/System.Private.CoreLib/src/Mono/RuntimeHandles.cs240
-rw-r--r--netcore/System.Private.CoreLib/src/Mono/RuntimeMarshal.cs78
-rw-r--r--netcore/System.Private.CoreLib/src/Mono/RuntimeStructs.cs123
-rw-r--r--netcore/System.Private.CoreLib/src/Mono/SafeGPtrArrayHandle.cs38
-rw-r--r--netcore/System.Private.CoreLib/src/Mono/SafeStringMarshal.cs51
-rw-r--r--netcore/System.Private.CoreLib/src/System/ArgIterator.cs104
-rw-r--r--netcore/System.Private.CoreLib/src/System/Array.Mono.cs632
-rw-r--r--netcore/System.Private.CoreLib/src/System/Attribute.Mono.cs62
-rw-r--r--netcore/System.Private.CoreLib/src/System/Buffer.Mono.cs38
-rw-r--r--netcore/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.Mono.cs16
-rw-r--r--netcore/System.Private.CoreLib/src/System/Collections/Generic/Comparer.Mono.cs50
-rw-r--r--netcore/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.Mono.cs84
-rw-r--r--netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs525
-rw-r--r--netcore/System.Private.CoreLib/src/System/Diagnostics/Debugger.cs44
-rw-r--r--netcore/System.Private.CoreLib/src/System/Diagnostics/StackFrame.Mono.cs54
-rw-r--r--netcore/System.Private.CoreLib/src/System/Diagnostics/StackTrace.Mono.cs86
-rw-r--r--netcore/System.Private.CoreLib/src/System/Enum.Mono.cs132
-rw-r--r--netcore/System.Private.CoreLib/src/System/Environment.Mono.in84
-rw-r--r--netcore/System.Private.CoreLib/src/System/Environment.Unix.Mono.cs103
-rw-r--r--netcore/System.Private.CoreLib/src/System/Exception.Mono.cs146
-rw-r--r--netcore/System.Private.CoreLib/src/System/GC.Mono.cs268
-rw-r--r--netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs20
-rw-r--r--netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.Mono.cs33
-rw-r--r--netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Windows.Mono.cs13
-rw-r--r--netcore/System.Private.CoreLib/src/System/IO/FileLoadException.Mono.cs14
-rw-r--r--netcore/System.Private.CoreLib/src/System/IO/MonoIOError.cs1827
-rw-r--r--netcore/System.Private.CoreLib/src/System/IO/Stream.Mono.cs17
-rw-r--r--netcore/System.Private.CoreLib/src/System/Math.Mono.cs99
-rw-r--r--netcore/System.Private.CoreLib/src/System/MathF.Mono.cs93
-rw-r--r--netcore/System.Private.CoreLib/src/System/MissingMemberException.Mono.cs14
-rw-r--r--netcore/System.Private.CoreLib/src/System/ModuleHandle.cs142
-rw-r--r--netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs262
-rw-r--r--netcore/System.Private.CoreLib/src/System/NotImplemented.cs29
-rw-r--r--netcore/System.Private.CoreLib/src/System/Nullable.Mono.cs41
-rw-r--r--netcore/System.Private.CoreLib/src/System/Object.Mono.cs22
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs97
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/AssemblyName.Mono.cs135
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs720
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeData.cs187
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.Mono.cs17
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs591
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs373
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorOnTypeBuilderInst.cs227
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs552
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs470
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILInfo.cs133
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs481
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.notsupported.cs156
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs432
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs143
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventOnTypeBuilderInst.cs135
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs241
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldOnTypeBuilderInst.cs140
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs476
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs1173
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/LocalBuilder.Mono.cs111
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs743
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs315
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs932
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/MonoArrayMethod.cs158
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.Mono.cs146
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs218
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs165
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs410
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs1892
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs512
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Emit/UnmanagedMarshal.cs138
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs109
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/MemberInfo.Mono.cs28
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/Metadata/AssemblyExtensions.cs12
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/MethodBase.Mono.cs78
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs451
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs220
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/RuntimeExceptionHandlingClause.cs31
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs289
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/RuntimeLocalVariableInfo.cs26
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs43
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs913
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs391
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs294
-rw-r--r--netcore/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs459
-rw-r--r--netcore/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.Mono.cs17
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/DependentHandle.cs73
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/JitHelpers.cs15
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/PreserveDependencyAttribute.cs46
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.Mono.cs19
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs141
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/GCSettings.Mono.cs29
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.Mono.cs13
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.Mono.cs23
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs448
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/MarshalAsAttribute.Mono.cs11
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.Mono.cs39
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeHandle.Mono.cs14
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs23
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs159
-rw-r--r--netcore/System.Private.CoreLib/src/System/Runtime/Remoting/Contexts/Context.cs44
-rw-r--r--netcore/System.Private.CoreLib/src/System/RuntimeArgumentHandle.cs12
-rw-r--r--netcore/System.Private.CoreLib/src/System/RuntimeFieldHandle.cs85
-rw-r--r--netcore/System.Private.CoreLib/src/System/RuntimeMethodHandle.cs90
-rw-r--r--netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs2565
-rw-r--r--netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs332
-rw-r--r--netcore/System.Private.CoreLib/src/System/Security/DynamicSecurityMethodAttribute.cs21
-rw-r--r--netcore/System.Private.CoreLib/src/System/String.Mono.cs144
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Unix.Mono.cs91
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/Interlocked.cs165
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Unix.Mono.cs131
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/LowLevelLock.cs41
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/LowLevelSpinWaiter.cs55
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs178
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/Mutex.Unix.Mono.cs72
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/Overlapped.cs320
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/PreAllocatedOverlapped.cs13
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/Semaphore.Unix.Mono.cs102
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs17
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs356
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs49
-rw-r--r--netcore/System.Private.CoreLib/src/System/Threading/WaitHandle.Mono.cs51
-rw-r--r--netcore/System.Private.CoreLib/src/System/Type.Mono.cs135
-rw-r--r--netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs221
-rw-r--r--netcore/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs30
-rw-r--r--netcore/System.Private.CoreLib/src/System/TypeNameParser.cs409
-rw-r--r--netcore/System.Private.CoreLib/src/System/TypeSpec.cs620
-rw-r--r--netcore/System.Private.CoreLib/src/System/TypedReference.cs108
-rw-r--r--netcore/System.Private.CoreLib/src/System/ValueType.cs77
-rw-r--r--netcore/System.Private.CoreLib/src/System/WeakReference.Mono.cs46
-rw-r--r--netcore/System.Private.CoreLib/src/System/WeakReference.T.Mono.cs43
-rw-r--r--netcore/System.Private.CoreLib/src/System/__ComObject.cs14
-rw-r--r--netcore/build.cmd2
-rw-r--r--netcore/build.ps1148
-rwxr-xr-xnetcore/build.sh163
-rw-r--r--netcore/build.targets200
-rw-r--r--netcore/corefx-restore.csproj14
-rw-r--r--netcore/corefx-tests-restore.proj39
-rw-r--r--netcore/corerun/.gitignore2
-rw-r--r--netcore/corerun/Makefile.am9
-rw-r--r--netcore/corerun/coreclrhost.h125
-rw-r--r--netcore/corerun/corerun.cpp162
-rw-r--r--netcore/corerun/coreruncommon.cpp520
-rw-r--r--netcore/corerun/coreruncommon.h56
-rw-r--r--netcore/gen-xunit-runner/Program.cs467
-rw-r--r--netcore/gen-xunit-runner/README.md46
-rw-r--r--netcore/gen-xunit-runner/gen-test.csproj.template36
-rw-r--r--netcore/gen-xunit-runner/gen-xunit-runner.csproj22
-rw-r--r--netcore/init-tools.ps15
-rwxr-xr-xnetcore/init-tools.sh10
-rw-r--r--netcore/metapackage-llvm.nuspec18
-rw-r--r--netcore/metapackage.nuspec20
-rw-r--r--netcore/roslyn-restore.csproj13
-rw-r--r--netcore/run-tests-corefx.ps1120
-rw-r--r--netcore/runtime-llvm.nuspec17
-rw-r--r--netcore/runtime.nuspec17
-rw-r--r--netcore/sample/AspNetCore/AspNetCore.csproj7
-rw-r--r--netcore/sample/AspNetCore/Program.cs26
-rw-r--r--netcore/sample/AspNetCore/Properties/launchSettings.json27
-rw-r--r--netcore/sample/AspNetCore/Startup.cs41
-rw-r--r--netcore/sample/AspNetCore/appsettings.Development.json9
-rw-r--r--netcore/sample/AspNetCore/appsettings.json10
-rw-r--r--netcore/sample/HelloWorld/HelloWorld.csproj11
-rw-r--r--netcore/sample/HelloWorld/Program.cs16
-rw-r--r--netcore/tests/HwIntrinsics/HwIntrinsics.csproj11
-rw-r--r--netcore/tests/HwIntrinsics/Program.cs844
-rw-r--r--netcore/tests/HwIntrinsics/SRI-reference-data.txt595
-rw-r--r--netcore/tools/jitdiff/jitdiff.cs216
-rwxr-xr-xnetcore/tools/jitdiff/jitdiff.csproj7
-rwxr-xr-xnetcore/xunit-summary.py73
1505 files changed, 1 insertions, 348679 deletions
diff --git a/Makefile.am b/Makefile.am
index 930f0762457..96694ea5467 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,7 +4,7 @@ AM_CFLAGS = $(WERROR_CFLAGS)
SUBDIRS = @MONO_SUBDIRS@
noinst_SUBDIRS = @MONO_NOINST_SUBDIRS@
-DIST_SUBDIRS = $(SUBDIRS) m4 netcore
+DIST_SUBDIRS = $(SUBDIRS) m4
if !ENABLE_NETCORE
@@ -24,7 +24,6 @@ EXTRA_DIST= \
winconfig.h \
code_of_conduct.md \
external \
- netcore/Makefile \
mcs/class/referencesource
DISTCHECK_CONFIGURE_FLAGS = EXTERNAL_RUNTIME=false
diff --git a/netcore/.gitignore b/netcore/.gitignore
deleted file mode 100644
index 2e52576a08b..00000000000
--- a/netcore/.gitignore
+++ /dev/null
@@ -1,16 +0,0 @@
-LICENSE.txt
-ThirdPartyNotices.txt
-tests
-/shared
-sdk
-dotnet*
-aspnetcore-runtime-*
-netcoreapp2.0/
-netcoreapp3.0/
-packs/
-/corefx
-/roslyn
-/obj
-.configured
-/System.Private.CoreLib/src/System/Environment.Mono.cs
-/config.make
diff --git a/netcore/CoreFX.issues.rsp b/netcore/CoreFX.issues.rsp
deleted file mode 100644
index fd840b454a5..00000000000
--- a/netcore/CoreFX.issues.rsp
+++ /dev/null
@@ -1,898 +0,0 @@
--notrait category=OuterLoop
--notrait category=RequiresElevation
--notrait category=nonnetcoreapptests
--notrait category=nonmonotests
--notrait category=failing
--notrait category=IgnoreForCI
-
-####################################################################
-## Microsoft.VisualBasic.Core.Tests
-####################################################################
-
-# https://github.com/mono/mono/issues/14854
--nomethod Microsoft.VisualBasic.Tests.ErrObjectTests.Clear
-
-# Windows-only tests, incorrect platform guards (https://github.com/dotnet/corefx/pull/40365)
--nomethod Microsoft.VisualBasic.Tests.InteractionTests.SaveSetting
--nomethod Microsoft.VisualBasic.Tests.InteractionTests.DeleteSetting
--nomethod Microsoft.VisualBasic.Tests.InteractionTests.GetAllSettings
--nomethod Microsoft.VisualBasic.Tests.InteractionTests.GetSetting
-
-####################################################################
-## System.Collections.Specialized.Tests
-####################################################################
-
-# TODO: Wrong exception
-# https://github.com/mono/mono/issues/14858
--nomethod System.Collections.Specialized.Tests.NameValueCollectionCtorTests.Ctor_NegativeCapacity_ThrowsArgumentOutOfRangeException
-
-####################################################################
-## System.Diagnostics.Tracing.Tests
-####################################################################
-
-# System.SR needs implemented.
-# https://github.com/mono/mono/issues/14907
--nomethod BasicEventSourceTests.TestsManifestNegative.Test_GenerateManifest_InvalidEventSources
-
-####################################################################
-## System.Drawing.Common.Tests
-####################################################################
-
-# System.ArgumentException Arg_ObjObjEx
--nomethod System.Drawing.Imaging.Tests.ImageAttributesTests.SetColorMatrix_InvalidFlags_ThrowsArgumentException
-
-####################################################################
-## System.Dynamic.Runtime.Tests
-####################################################################
-
-# ambigous methods
-# https://github.com/mono/mono/issues/14906
--nomethod ManagedTests.DynamicCSharp.Conformance.dynamic.overloadResolution.Methods.Oneclass2methods.twoprms004.twoprms004.Test.DynamicCSharpRunTest
-
-####################################################################
-## System.IO.Tests
-####################################################################
-
-# flaky test (The process cannot access the file ...)
--nomethod System.IO.Tests.*.CopyFileWithData_MemberData
-
-####################################################################
-## System.Linq.Expressions.Tests
-####################################################################
-
-# OOM Exception gets thrown for the 68 (currently) tests that fail.
-# https://github.com/mono/mono/issues/14912
--nomethod System.Linq.Expressions.Tests.ArrayBoundsTests.NewArrayBounds*
-
-# Exceptions are different.
-# https://github.com/mono/mono/issues/14918
--nomethod System.Linq.Expressions.Tests.BindTests.ConstantField
-
-# System.Reflection.Emit type load / init exception https://github.com/mono/mono/issues/14919
--nomethod System.Linq.Expressions.Tests.Return.TailCallThenReturn
--nomethod System.Linq.Expressions.Tests.UnaryArithmeticNegateCheckedNullableTests.VerifyIL_NullableShortNegateChecked
--noclass System.Linq.Expressions.Tests.StackSpillerTests
--noclass System.Linq.Expressions.Tests.LambdaTests
--nomethod System.Linq.Expressions.Tests.BinaryCoalesceTests.VerifyIL_NullableIntCoalesceToNullableInt
--nomethod System.Linq.Expressions.Tests.UnaryArithmeticNegateCheckedTests.VerifyIL_ShortNegateChecked
--nomethod System.Linq.Expressions.Tests.BlockTests.InsignificantBlock
--nomethod System.Linq.Expressions.Tests.CompilerTests.VerifyIL_*
-
-# InvalidOperationException - Sequence contains no matching element
-# https://github.com/mono/mono/issues/14920
--nomethod System.Linq.Expressions.Tests.ArrayAccessTests.ArrayAccess_MultiDimensionalOf1
--nomethod System.Linq.Expressions.Tests.ArrayAccessTests.ArrayIndex_MultiDimensionalOf1
--nomethod System.Linq.Expressions.Tests.MemberAccessTests.Property_NoGetOrSetAccessors_ThrowsArgumentException
--nomethod System.Linq.Expressions.Tests.IndexExpressionTests.NoAccessorIndexedProperty
-
-# IndexOutOfRangeException
-# https://github.com/mono/mono/issues/14921
--nomethod System.Linq.Expressions.Tests.ArrayAccessTests.NonZeroBasedOneDimensionalArrayAccess
-
-# System.InvalidOperationException : Operation is not valid due to the current state of the object.
-# https://github.com/mono/mono/issues/14924
--nomethod System.Linq.Expressions.Tests.ExceptionHandlingExpressions.ExceptionThrownInFilter
-
-# legit test failure... Expected 4 / actual 0
-# https://github.com/mono/mono/issues/14925
--nomethod System.Linq.Expressions.Tests.ExceptionHandlingExpressions.ExpressionsUnwrapeExternallyThrownRuntimeWrappedException
-
-# Expected exception but none was thrown
-# https://github.com/mono/mono/issues/14927
--nomethod System.Linq.Expressions.Tests.IndexExpressionTests.IndexedPropertySetterValueTypeNotMatchPropertyType
--nomethod System.Linq.Expressions.Tests.IndexExpressionTests.IndexedPropertyGetReturnsWrongType
-
-# Expected ArgumentException got IndexOutOfRangeException https://github.com/mono/mono/issues/14930
--nomethod System.Linq.Expressions.Tests.ArrayIndexTests.NonZeroBasedOneDimensionalArrayIndex
--nomethod System.Linq.Expressions.Tests.ArrayIndexTests.NonZeroBasedOneDimensionalArrayIndexMethod
-
-# OOM Exception. Weird
-# https://github.com/mono/mono/issues/14933
--nomethod System.Linq.Expressions.Tests.ArrayBoundsTests.SingleNegativeBoundErrorMessage
-
-# Arithmetic operation resulted in an overflow.
-# https://github.com/mono/mono/issues/14934
--nomethod System.Linq.Expressions.Tests.ArrayBoundsTests.MultipleNegativeBoundErrorMessage
-
-####################################################################
-## System.Linq.Parallel.Tests
-####################################################################
-
-# fails w/ an ArgumentException: Arg_ObjObjEx https://github.com/mono/mono/issues/14956
--nomethod System.Linq.Parallel.Tests.PlinqModesTests.WithExecutionMode_Multiple
-
-####################################################################
-## System.Memory.Tests
-####################################################################
-
-# Reflection TargetException: Non-static method requires a target.
-# https://github.com/mono/mono/issues/14962
--nomethod System.SpanTests.SpanTests.ReadOnlyMemory_PropertyReturningReadOnlySpan
-
-# Should throw NotSupportedException, but we do not.
-# https://github.com/mono/mono/issues/14993
--nomethod System.SpanTests.SpanTests.ReadOnlySpan_Constructor
--nomethod System.SpanTests.SpanTests.Span_Constructor
-
-# Should throw NotSupportedException - Non static method requires a target
-# https://github.com/mono/mono/issues/14998
--nomethod System.SpanTests.SpanTests.Span_InstanceMethod
--nomethod System.SpanTests.SpanTests.Memory_PropertyReturningSpan
--nomethod System.SpanTests.SpanTests.ReadOnlySpan_InstanceMethod
-
-# Should throw OutOfMemory Exception, but does not throw
-# https://github.com/mono/mono/issues/15002
--nomethod System.Buffers.Tests.ArrayBufferWriterTests_String.Invalid_Ctor
--nomethod System.Buffers.Tests.ArrayBufferWriterTests_Char.Invalid_Ctor
--nomethod System.Buffers.Tests.ArrayBufferWriterTests_Byte.Invalid_Ctor
-
-####################################################################
-## System.Net.Http.Functional.Tests
-####################################################################
-
-# TODO: Crashes runtime inside Interop.Http.MultiPerform (marshalling issue?)
-# https://github.com/mono/mono/issues/15005
--nomethod *PlatformHandler*
-
-# Works, but may trigger UI!
-# NOTE: KEEPING THIS HERE BUT COMMENTED OUT - in the event the UI is shown (wasn't for me)
-#-nomethod System.Net.Http.Functional.Tests.SocketsHttpHandler_HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test.SetDelegate_ConnectionSucceeds
-
-# When test is run, xunit claims it's not a part of the test suite
-#-nomethod System.Net.Http.Functional.Tests.SocketsHttpHandler_HttpClientHandler_ClientCertificates_Test.AutomaticOrManual_DoesntFailRegardlessOfWhetherClientCertsAreAvailable
-
-####################################################################
-## System.Net.Sockets.Tests
-####################################################################
-
-# flaky test
--nomethod System.Net.Sockets.Tests.SocketOptionNameTest.MulticastInterface_Set_AnyInterface_Succeeds
-
-####################################################################
-## System.Reflection.Emit.ILGeneration.Tests
-####################################################################
-
-# System.Reflection implementation to do.
--noclass System.Reflection.Emit.Tests.CustomAttributeBuilderTests
--nomethod System.Reflection.Emit.Tests.SignatureHelperAddArgument.*
--nomethod System.Reflection.Emit.Tests.SignatureHelperGetPropertySigHelper.*
--nomethod System.Reflection.Emit.Tests.ILGeneratorEmit3.Emit_OpCodes_LocalBuilder_TooManyLocals_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.ILGeneratorEmit3.Emit_OpCodes_LocalBuilder_LocalFromDifferentMethod_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.ILGeneratorDeclareLocal.DeclareLocal_TypeCreated_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.ILGeneratorDeclareLocal.DeclareLocal_GlobalFunctionsCreated_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.SignatureHelperGetMethodSigHelper.GetMethodSigHelper_Module_CallingConventions_Type_Length_ReturnsThree
--nomethod System.Reflection.Emit.Tests.SignatureHelperGetMethodSigHelper.GetMethodSigHelper_Module_Type_TypeArray
--nomethod System.Reflection.Emit.Tests.SignatureHelperGetMethodSigHelper.GetMethodSigHelper_CallingConventions_Type_Length_ReturnsThree
--nomethod System.Reflection.Emit.Tests.SignatureHelperGetMethodSigHelper.GetMethodSigHelper_Module_Type_TypeArray_NullObjectInParameterType_ThrowsArgumentNullException
--nomethod System.Reflection.Emit.Tests.ILGeneratorEmit2.Emit_OpCodes_LocalBuilder_TooManyLocals_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.ILGeneratorEmit2.Emit_OpCodes_LocalBuilder_LocalFromDifferentMethod_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.SetCustomAttributeTests.SetCustomAttribute_NullArgument_ThrowsArgumentNullException
--nomethod System.Reflection.Emit.Tests.ILGeneratorEmit4.TestEmitCalliNonBlittable
--nomethod System.Reflection.Emit.Tests.SignatureHelperAddArguments.AddArgument_NullObjectInRequiredCustomModifiers_ThrowsArgumentNullException
--nomethod System.Reflection.Emit.Tests.SignatureHelperAddArguments.AddArgument_NullObjectInOptionalCustomModifiers_ThrowsArgumentNullException
--nomethod System.Reflection.Emit.Tests.SignatureHelperAddArguments.AddArgument_DifferentCountsForCustomModifiers_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.SignatureHelperAddArguments.AddArguments_SignatureFinished_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.SignatureHelperAddArguments.AddArguments
-
-####################################################################
-## System.Reflection.Emit.Tests
-####################################################################
-
-# Mono behaves like coreclr but the test doesn't detect it
--nomethod System.Reflection.Emit.Tests.AssemblyTests.DefineDynamicModule
-
--nomethod System.Reflection.Emit.Tests.MethodBuilderEquals.Equals
--nomethod System.Reflection.Emit.Tests.ConstructorBuilderToString.ToString_NullRequiredOptionalCustomModifiers
--nomethod System.Reflection.Emit.Tests.ConstructorBuilderToString.ToString_NoRequiredOptionalCustomModifiers
--nomethod System.Reflection.Emit.Tests.EnumBuilderMethodTests.DefineLiteral
--nomethod System.Reflection.Emit.Tests.EnumBuilderMethodTests.DefineLiteral_InvalidLiteralValue_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.EnumBuilderMethodTests.SetCustomAttribute_ConstructorInfo_ByteArray
--nomethod System.Reflection.Emit.Tests.EnumBuilderMethodTests.SetCustomAttribute_CustomAttributeBuilder
--nomethod System.Reflection.Emit.Tests.EnumBuilderPropertyTests.Guid_TypeCreated
--nomethod System.Reflection.Emit.Tests.FieldBuilderSetConstant.SetConstant_InvalidType_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.GenericTypeParameterBuilderSetInterfaceConstraints.SetInterfaceConstraints_OneCustomInterface
--nomethod System.Reflection.Emit.Tests.GenericTypeParameterBuilderSetInterfaceConstraints.SetInterfaceConstraints_MultipleCustomInterfaces
--nomethod System.Reflection.Emit.Tests.MethodBuilderDefineGenericParameters.DefineGenericParameters_SingleTypeParameter_SetImplementationFlagsCalled_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.MethodBuilderDefineGenericParameters.DefineGenericParameters_TwoTypeParameters_SetImplementationFlagsCalled_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.MethodBuilderDefineGenericParameters.DefineGenericParameters_SingleTypeParameter_AlreadyDefined_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.MethodBuilderDefineGenericParameters.DefineGenericParameters_TwoTypeParameters_AlreadyDefined_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.MethodBuilderGetILGenerator.GetILGenerator_NoMethodBody_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.MethodBuilderMakeGenericMethod.TestNotThrowsExceptionOnNull
--nomethod System.Reflection.Emit.Tests.MethodBuilderMakeGenericMethod.TestNotThrowsExceptionOnEmptyArray1
--nomethod System.Reflection.Emit.Tests.MethodBuilderMakeGenericMethod.TestNotThrowsExceptionOnEmptyArray2
--nomethod System.Reflection.Emit.Tests.MethodBuilderReturnParameter.ReturnParameter_NoBody_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.MethodBuilderSetParameters.SetParameters
--nomethod System.Reflection.Emit.Tests.MethodBuilderSetParameters.SetParameters_NullParameter_ThrowsArgumentNullException
--nomethod System.Reflection.Emit.Tests.MethodBuilderToString.ToString_AllFieldsSet
--nomethod System.Reflection.Emit.Tests.MethodBuilderToString.ToString_NameAndAttributeSet
--nomethod System.Reflection.Emit.Tests.MethodBuilderToString.ToString_NameAttributeAndSignatureSetSet
--nomethod System.Reflection.Emit.Tests.MethodBuilderToString.ToString_NonGenericMethod
--nomethod System.Reflection.Emit.Tests.MethodBuilderToString.ToString_GenericMethod
--nomethod System.Reflection.Emit.Tests.ModuleBuilderDefineEnum.DefineEnum
--nomethod System.Reflection.Emit.Tests.ModuleBuilderDefineEnum.DefineEnum_DynamicUnderlyingType_Works
--nomethod System.Reflection.Emit.Tests.ModuleBuilderDefineEnum.DefineEnum_ByRefUnderlyingType_ThrowsCOMExceptionOnCreation
--nomethod System.Reflection.Emit.Tests.ModuleBuilderDefineType.DefineType
--nomethod System.Reflection.Emit.Tests.ModuleBuilderGetArrayMethod.GetArrayMethod_ValidArrayValues_VoidReturnType
--nomethod System.Reflection.Emit.Tests.ModuleBuilderGetArrayMethod.GetArrayMethod_ValidArrayValues_ValueReturnType
--nomethod System.Reflection.Emit.Tests.ModuleBuilderGetArrayMethod.GetArrayMethod_ValidArrayValues_ReferenceReturnType
--nomethod System.Reflection.Emit.Tests.ModuleBuilderGetArrayMethod.GetArrayMethod_ValidArrayValues_ValueParameterType
--nomethod System.Reflection.Emit.Tests.ModuleBuilderGetArrayMethod.GetArrayMethod_ValidArrayValues_ReferenceParameterType
--nomethod System.Reflection.Emit.Tests.ModuleBuilderGetArrayMethod.GetArrayMethod_JaggedArray
--nomethod System.Reflection.Emit.Tests.ModuleBuilderGetArrayMethod.GetArrayMethod_MultiDimensionalArray
--nomethod System.Reflection.Emit.Tests.ModuleBuilderGetArrayMethod.GetArrayMethod_NullParameters
--nomethod System.Reflection.Emit.Tests.ModuleBuilderGetArrayMethod.GetArrayMethod_ArrayClassNotArray_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.ModuleBuilderGetArrayMethod.GetArrayMethod_InvalidArgument_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.PropertyBuilderTest2.AddOtherMethod
--nomethod System.Reflection.Emit.Tests.PropertyBuilderTest11.SetConstant
--nomethod System.Reflection.Emit.Tests.PropertyBuilderTest11.SetConstant_TypeNotConstant_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.PropertyBuilderTest12.SetCustomAttribute_CustomAttributeBuilder_TypeNotCreated_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.PropertyBuilderTest12.SetCustomAttribute_ConstructorInfo_ByteArray_TypeAlreadyCreated_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.PropertyBuilderTest15.TestThrowsExceptionForCreateTypeCalled
--nomethod System.Reflection.Emit.Tests.PropertyBuilderTest16.SetValue_ThrowsNotSupportedException
--nomethod System.Reflection.Emit.Tests.TypeBuilderAddInterfaceImplementation.AddInterfaceImplementation_TypeNotInterface_ThrowsTypeLoadExceptionOnCreation
--nomethod System.Reflection.Emit.Tests.TypeBuilderAddInterfaceImplementation.AddInterfaceImplementation_TypeDoesntImplementInterface_ThrowsTypeLoadExceptionOnCreation
--nomethod System.Reflection.Emit.Tests.TypeBuilderAssemblyQualifiedName.AssemblyQualifiedName
--nomethod System.Reflection.Emit.Tests.TypeBuilderCreateType.CreateType_BadAttributes
--nomethod System.Reflection.Emit.Tests.TypeBuilderCreateTypeInfo.CreateType_InvalidTypeAttributes_Throws
-
-# Extra RTSpecialName attribute
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineConstructor.DefineConstructor
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineConstructor.DefineConstructor_NullRequiredAndOptionalCustomModifiers
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineDefaultConstructor.DefineDefaultConstructor
--nomethod System.Reflection.Emit.Tests.MethodBuilderDefineTypeInitializer.DefineTypeInitializer
-
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineMethodTests.DefineMethod
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineFieldTests.DefineField
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineFieldTests.DefineField_InvalidFieldAttributes_ThrowsTypeLoadExceptionOnCreation
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineFieldTests.DefineField_DynamicFieldTypeNotCreated_ThrowsTypeLoadException
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineGenericParameters.DefineGenericParameters_AlreadyDefinedGenericParameters_ThrowsInvalidOperationException
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineEvent.DefineEvent
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineEvent.DefineProperty_InvalidUnicodeChars
--nomethod System.Reflection.Emit.Tests.MethodBuilderDefineMethodOverride.DefineMethodOverride_NothingToOverride_ThrowsTypeLoadExceptionOnCreation
--nomethod System.Reflection.Emit.Tests.MethodBuilderDefineMethodOverride.DefineMethodOverride_ClassDoesNotImplementOrInheritMethod_ThrowsTypeLoadExceptionOnCreation
--nomethod System.Reflection.Emit.Tests.MethodBuilderDefineMethodOverride.DefineMethodOverride_BodyAndDeclarationTheSame_ThrowsTypeLoadExceptionOnCreation
--nomethod System.Reflection.Emit.Tests.MethodBuilderDefineMethodOverride.DefineMethodOverride_CalledTwiceWithDifferentBodies_ThrowsTypeLoadExceptionOnCreation
--nomethod System.Reflection.Emit.Tests.MethodBuilderDefineMethodOverride.DefineMethodOverride_BodyAndDeclarationHaveDifferentSignatures_ThrowsTypeLoadExceptionOnCreation
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineNestedType.DefineNestedType
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineNestedType.DefineNestedType_LongName_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineNestedType.DefineNestedType_InvalidAttributes_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineNestedType.DefineNestedType_InvalidParent_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineNestedType.DefineNestedType_InvalidInterfaceType_ThrowsTypeLoadExceptionOnCreation
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineProperty.DefineProperty
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineProperty.DefineProperty_OpenGenericReturnType_ThrowsBadImageFormatExceptionGettingCreatedPropertyType
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineProperty.DefineProperty_NullParameterType_ThrowsArgumentNullException
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineProperty.DefineProperty_OpenGenericParameterType_ThrowsBadImageFormatExceptionGettingCreatedPropertyType
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineProperty.DefineProperty_DynamicPropertyTypeNotCreated_ThrowsTypeLoadException
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineProperty.DefineProperty_DynamicParameterTypeNotCreated_ThrowsTypeLoadException
--nomethod System.Reflection.Emit.Tests.TypeBuilderDefineProperty.DefineProperty_CalledMultipleTimes_Works
--nomethod System.Reflection.Emit.Tests.TypeBuilderGetConstructor.GetConstructor_TypeNotTypeBuilder_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderGetConstructor.GetConstructor_DeclaringTypeOfConstructorNotGenericTypeDefinitionOfType_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderGetConstructor.GetConstructor_TypeNotGeneric_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderGetField.GetField_TypeNotTypeBuilder_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderGetField.GetField_DeclaringTypeOfFieldNotGenericTypeDefinitionOfType_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderGetField.GetField_TypeNotGeneric_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderGetMethod.GetMethod_TypeNotTypeBuilder_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderGetMethod.GetMethod_MethodDefinitionNotInTypeGenericDefinition_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderGetMethod.GetMethod_MethodNotGenericTypeDefinition_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderGetMethod.GetMethod_TypeIsNotGeneric_ThrowsArgumentException
--nomethod System.Reflection.Emit.Tests.TypeBuilderGUID.Guid_TypeCreated_NotEmpty
-
--nomethod System.Reflection.Emit.Tests.AssemblyTests.DefineDynamicAssembly_AssemblyName_AssemblyBuilderAccess
--nomethod System.Reflection.Emit.Tests.AssemblyTests.DefineDynamicAssembly_AssemblyName_AssemblyBuilderAccess_CustomAttributeBuilder
-
-# need to reflect https://github.com/dotnet/coreclr/pull/24937 changes
--nomethod System.Reflection.Emit.Tests.MethodBuilderSetSignature.SetSignature_AllParametersNull
--nomethod System.Reflection.Emit.Tests.MethodBuilderSetReturnType.SetReturnType_NullReturnType_ReturnsVoid
--nomethod System.Reflection.Emit.Tests.MethodBuilderGetGenericArguments.GetGenericArguments_NonGenericMethod_ReturnsEmptyArray
--nomethod System.Reflection.Emit.Tests.MethodBuilderSetSignature.SetSignature_NullReturnType_CustomModifiersSetToWrongTypes
-
-####################################################################
-## System.Reflection.Tests
-####################################################################
-
-# Expected ArgumentException, but none was thrown
-# https://github.com/mono/mono/issues/15024
--nomethod System.Reflection.Tests.MethodInfoTests.Invoke_OptionalParameterUnassingableFromMissing_WithMissingValue_ThrowsArgumentException
-
-# Static ctors cannot be invoke with one Invoke overload
-# https://github.com/mono/mono/issues/15025
--nomethod System.Reflection.Tests.ConstructorInfoTests.Invoke_StaticConstructor_ThrowsMemberAccessException
-
-# Expected MemberAccessException, but we're throwing TargetException
-# https://github.com/mono/mono/issues/15026
--nomethod System.Reflection.Tests.ConstructorInfoTests.Invoke_AbstractClass_ThrowsMemberAccessException
-
-# Expected TargetParameterCountException, but we have ArgumentException
-# https://github.com/mono/mono/issues/15027
--nomethod System.Reflection.Tests.PropertyInfoTests.GetValue_Invalid
-
-# Expected empty string, but got enumType instead
-# https://github.com/mono/mono/issues/15028
--nomethod System.Reflection.Tests.TypeInfoTests.IsEnumDefined_Invalid
-
-# Fails because our Object class has extra instance methods
-# https://github.com/mono/mono/issues/15029
--nomethod System.Reflection.Tests.TypeInfoTests.FindMembers
--nomethod System.Reflection.Tests.TypeInfoTests.GetMethods
--nomethod System.Reflection.Tests.TypeInfoTests.GetMembers
--nomethod System.Reflection.Tests.TypeInfoTests.GetMethod
-
-# CustomConstantAttribute not supported
-# https://github.com/mono/mono/issues/15037
--nomethod System.Reflection.Tests.ParameterInfoTests.RawDefaultValueFromAttribute
-
-# SKIPPED
--nomethod System.Reflection.Tests.MemberInfoNetCoreAppTests.HasSameMetadataDefinitionAs__CornerCase_HasElementTypes
-
-# Assertion failed... Not sure why
-# https://github.com/mono/mono/issues/15069
--nomethod System.Reflection.Tests.MemberInfoNetCoreAppTests.HasSameMetadataDefinitionAs_GenericTypeParameters
-
-# relies on specific exception message
--nomethod System.Reflection.Tests.AssemblyTests.LoadFile_ValidPEBadIL_ThrowsBadImageFormatExceptionWithPath
--nomethod System.Reflection.Tests.AssemblyTests.LoadFile_PartiallyQualifiedPath_ThrowsArgumentException
--nomethod System.Reflection.Tests.AssemblyTests.LoadFile_NoSuchPath_ThrowsFileNotFoundException
-
-####################################################################
-## System.Runtime.InteropServices.Tests
-####################################################################
-
-# Marshal Methods WILL NOT BE Implemented in MonoVM
-# https://github.com/mono/mono/issues/15085
--nomethod System.Runtime.InteropServices.Tests.IntPtrTests.ReadIntPtr_NotReadable_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.IntPtrTests.WriteIntPtr_BlittableObject_Roundtrips
--nomethod System.Runtime.InteropServices.Tests.IntPtrTests.WriteIntPtr_StructWithReferenceTypes_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.Int64Tests.WriteInt64_StructWithReferenceTypes_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.Int64Tests.ReadInt64_BlittableObject_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.Int16Tests.ReadInt16_NullObject_ThrowsAccessViolationException
--nomethod System.Runtime.InteropServices.Tests.Int16Tests.ReadInt16_NotReadable_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.Int16Tests.WriteInt16_NotReadable_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.Int16Tests.WriteInt16_BlittableObject_Roundtrips
--nomethod System.Runtime.InteropServices.Tests.Int16Tests.ReadInt16_StructWithReferenceTypes_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.Int16Tests.WriteInt16_NullObject_ThrowsAccessViolationException
--nomethod System.Runtime.InteropServices.Tests.Int16Tests.ReadInt16_BlittableObject_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.Int16Tests.WriteInt16_StructWithReferenceTypes_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.IntPtrTests.ReadIntPtr_BlittableObject_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.Int64Tests.WriteInt64_NotReadable_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.Int64Tests.WriteInt64_BlittableObject_Roundtrips
--nomethod System.Runtime.InteropServices.Tests.Int64Tests.WriteInt64_NullObject_ThrowsAccessViolationException
--nomethod System.Runtime.InteropServices.Tests.Int64Tests.ReadInt64_NotReadable_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.Int32Tests.ReadInt32_NullObject_ThrowsAccessViolationException
--nomethod System.Runtime.InteropServices.Tests.Int32Tests.WriteInt32_NullObject_ThrowsAccessViolationException
--nomethod System.Runtime.InteropServices.Tests.Int32Tests.WriteInt32_BlittableObject_Roundtrips
--nomethod System.Runtime.InteropServices.Tests.Int32Tests.WriteInt32_NotReadable_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.Int32Tests.WriteInt32_StructWithReferenceTypes_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.Int32Tests.ReadInt32_StructWithReferenceTypes_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.Int32Tests.ReadInt32_NotReadable_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.Int32Tests.ReadInt32_BlittableObject_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.IntPtrTests.ReadIntPtr_NullObject_ThrowsAccessViolationException
--nomethod System.Runtime.InteropServices.Tests.IntPtrTests.WriteIntPtr_NullObject_ThrowsAccessViolationException
--nomethod System.Runtime.InteropServices.Tests.IntPtrTests.WriteIntPtr_NotReadable_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.IntPtrTests.ReadIntPtr_StructWithReferenceTypes_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.ByteTests.ReadByte_BlittableObject_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.ByteTests.WriteByte_NullObject_ThrowsAccessViolationException
--nomethod System.Runtime.InteropServices.Tests.ByteTests.WriteByte_StructWithReferenceTypes_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.ByteTests.ReadByte_StructWithReferenceTypes_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.ByteTests.WriteByte_BlittableObject_Roundtrips
--nomethod System.Runtime.InteropServices.Tests.ByteTests.WriteByte_NotReadable_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.ByteTests.ReadByte_NullObject_ThrowsAccessViolationException
--nomethod System.Runtime.InteropServices.Tests.ByteTests.ReadByte_NotReadable_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.Int64Tests.ReadInt64_NullObject_ThrowsAccessViolationException
--nomethod System.Runtime.InteropServices.Tests.Int64Tests.ReadInt64_StructWithReferenceTypes_ReturnsExpected
--nomethod System.Runtime.InteropServices.Tests.GetExceptionCodeTests.*
--nomethod System.Runtime.InteropServices.Tests.GetExceptionPointersTests.GetExceptionPointers_ReturnsExpected
-
-
-# Not sure what to check
-# Expected ArgumentException to be thrown, but none was
-# https://github.com/mono/mono/issues/15087
--nomethod System.Runtime.InteropServices.Tests.DestroyStructureTests.DestroyStructure_NonRuntimeType_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.OffsetOfTests.OffsetOf_NotMarshallable_ThrowsArgumentException
--nomethod System.Runtime.InteropServices.Tests.SizeOfTests.SizeOf_InvalidType_ThrowsArgumentException
-
-# Wants exception messages to be non-empty
-# https://github.com/mono/mono/issues/15093
--nomethod System.Runtime.InteropServices.Tests.GetExceptionForHRTests.GetExceptionForHR_ErrorInfo_ReturnsValidException
--nomethod System.Runtime.InteropServices.Tests.GetExceptionForHRTests.GetExceptionForHR_NoErrorInfo_ReturnsValidException
--nomethod System.Runtime.InteropServices.Tests.ThrowExceptionForHRTests.ThrowExceptionForHR_NoErrorInfo_ReturnsValidException
--nomethod System.Runtime.InteropServices.Tests.ThrowExceptionForHRTests.ThrowExceptionForHR_ErrorInfo_ReturnsValidException
-
-# Supported on Mono
-# Expected ArgumentException
-# https://github.com/mono/mono/issues/15097
--nomethod System.Runtime.InteropServices.Tests.GetFunctionPointerForDelegateTests.GetFunctionPointer_GenericDelegate_ThrowsArgumentException
-
-# AE with The structure must not be a value class;
-# https://github.com/mono/mono/issues/15101
--nomethod System.Runtime.InteropServices.Tests.PtrToStructureTests.PtrToStructure_ZeroPointer_ThrowsArgumentNullException
-
-# Expected 255 / Actual 1
-# https://github.com/mono/mono/issues/15102
--nomethod System.Runtime.InteropServices.Tests.StructureToPtrTests.StructureToPtr_ByValBoolArray_Success
-
-# MarshalDirectiveException
-# https://github.com/mono/mono/issues/15103
--nomethod System.Runtime.InteropServices.Tests.StructureToPtrTests.StructureToPtr_ByValDateArray_Success
-
-# Expects AE but none was thrown
-# https://github.com/mono/mono/issues/15104
--nomethod System.Runtime.InteropServices.Tests.StructureToPtrTests.StructureToPtr_InvalidLengthByValArrayInStruct_ThrowsArgumentException
-
-####################################################################
-## System.Runtime.Serialization.Formatters.Tests
-####################################################################
-
-# Expected MemberAccessException but none was thrown
-# https://github.com/mono/mono/issues/15111
--nomethod System.Runtime.Serialization.Formatters.Tests.FormatterServicesTests.GetUninitializedObject_OpenGenericClass_ThrowsMemberAccessException
-
-# NotNull Assertion failure
-# https://github.com/mono/mono/issues/15112
--nomethod System.Runtime.Serialization.Formatters.Tests.SerializationGuardTests.BlockReflectionDodging
-
-# Expected AE but none thrown
-# https://github.com/mono/mono/issues/15113
--nomethod System.Runtime.Serialization.Formatters.Tests.FormatterServicesTests.GetUninitializedObject_NotSupportedType_ThrowsArgumentException
-
-# Expected TypeInitializationException but none thrown
-# https://github.com/mono/mono/issues/15114
--nomethod System.Runtime.Serialization.Formatters.Tests.FormatterServicesTests.GetUninitializedObject_StaticConstructorThrows_ThrowsTypeInitializationException
-
-# Object reference not set to an instance of an object error
-# https://github.com/mono/mono/issues/15115
--nomethod System.Runtime.Serialization.Formatters.Tests.BinaryFormatterTests.ValidateAgainstBlobs
-
-####################################################################
-## System.Runtime.Tests
-####################################################################
-
-# https://github.com/mono/mono/issues/14291 incorrect line numbers
-# See https://github.com/mono/mono/issues/15140 and https://github.com/mono/mono/issues/15141
--nomethod System.Tests.ExceptionTests.ThrowStatementDoesNotResetExceptionStackLineSameMethod
--nomethod System.Tests.ExceptionTests.ThrowStatementDoesNotResetExceptionStackLineOtherMethod
-
-# RuntimeAssembly.IsCollectible is not implemented yet
-# Implementation task https://github.com/mono/mono/issues/15142
--nomethod System.Reflection.Tests.IsCollectibleTests.*
-
-# Mono ignores [Optional] attribute defined on parameters in delegates
-# https://github.com/mono/mono/issues/15148
--nomethod System.Tests.DelegateTests.DynamicInvoke_OptionalParameterUnassingableFromMissing_WithMissingValue
--nomethod System.Tests.DelegateTests.DynamicInvoke_OptionalParameter_WithMissingValue
--nomethod System.Tests.DelegateTests.DynamicInvoke_ParameterSpecification_ArrayOfMissing
-
-# mono doesn't support termination signals, the test kills a process via libc's kill(pid)
-# and expects it to trigger domain.ProcessExit event
--nomethod System.Tests.ExitCodeTests.SigTermExitCode
-
-# error: Invalid IL code in (wrapper dynamic-method) object:<xsl:apply-templates> (System.Xml.Xsl.Runtime.XmlQueryRuntime,System.Xml.XPath.XPathNavigator,double): IL_0179: ret
--nomethod System.Tests.Types.VoidTests.IsByRef_Get_ReturnsExpected
-
-# throws ArgumentException
-# https://github.com/mono/mono/issues/15152
--nomethod System.Reflection.Tests.PointerTests.PointerPropertyGetValue
-
-# GCSettings.LatencyMode is not implemented
--nomethod System.Tests.GCTests.LatencyRoundtrips
-
-# GC.GetGCMemoryInfo is not implemented
--nomethod System.Tests.GCExtendedTests.GetGCMemoryInfo
-
-# flaky test, System.ArgumentNullException : Key cannot be null. Parameter name: key
--nomethod System.Tests.GetEnvironmentVariable.EnvironmentVariablesAreHashtable
-
-####################################################################
-## System.Threading.Tests
-####################################################################
-
-# Process hangs and test fails with [ERROR] FATAL UNHANDLED EXCEPTION: System.Threading.WaitHandleCannotBeOpenedException: No handle of the given name exists.
-# https://github.com/mono/mono/issues/15157
--nomethod System.Threading.Tests.MutexTests.CrossProcess_NamedMutex_ProtectedFileAccessAtomic
-
-# Fails with typeof(System.Threading.WaitHandleCannotBeOpenedException): A WaitHandle with system-wide name '' cannot be created. A WaitHandle of a different type might have the same name.
-# Expects an ArgumentException
-# https://github.com/mono/mono/issues/15158
--nomethod System.Threading.Tests.MutexTests.OpenExisting_InvalidNames
-
-# Expects ArgumentException but none is thrown
-# https://github.com/mono/mono/issues/15159
--nomethod System.Threading.Tests.MutexTests.Ctor_InvalidNames_Unix
-
-# Expects PlatformNotSupportedException, but we give an ArgumentNullException
-# https://github.com/mono/mono/issues/15160
--nomethod System.Threading.Tests.SemaphoreTests.OpenExisting_NotSupported_Unix
-
-# Expects PlatformNotSupportedException but none thrown
-# https://github.com/mono/mono/issues/15161
--nomethod System.Threading.Tests.SemaphoreTests.Ctor_NamesArentSupported_Unix
-
-####################################################################
-## System.Threading.Tests
-####################################################################
-
-# Requires precise GC (should be ignored in dotnet/corefx for mono)
--nomethod System.Threading.Tasks.Tests.ExecutionContextFlowTest.TaskCompletionSourceDoesntCaptureExecutionContext
-
-####################################################################
-## System.Threading.ThreadPool.Tests
-####################################################################
-
-# Tests for ThreadPool.SetMaxThreads(-1, -1) == true, which only happens to work on CoreCLR because
-# the managed SetMaxThreadsNative prototype uses "int"s while the unmanaged code uses "DWORD"s and
-# thus it interprets it as large positive numbers.
-#
-# https://github.com/mono/mono/issues/15164
--nomethod System.Threading.ThreadPools.Tests.ThreadPoolTests.SetMinMaxThreadsTest
-
-# TODO: Differences in behaviour between NetFX and CoreFX
--nomethod System.Threading.ThreadPools.Tests.ThreadPoolTests.SetMinThreadsTo0Test
-
-# Explicitly skipped if it's MonoVM (SkipOnTargetFramework)
--nomethod System.Threading.ThreadPools.Tests.ThreadPoolTests.SetMinMaxThreadsTest_ChangedInDotNetCore
-
-####################################################################
-## System.ComponentModel.Composition.Tests
-####################################################################
-
--nomethod System.ComponentModel.Composition.CompositionServicesTests.GetDefaultContractNameTest
--nomethod System.ComponentModel.Composition.MetadataViewProviderTests.GetMetadataView_InterfaceWithIndexer_ShouldThrowNotSupportedException
--nomethod Tests.Integration.ExportFactoryTests.ExportFactoryStandardImports_ShouldWorkProperly
-
-# flaky test - System.TypeLoadException : Could not load type '_proxy_System.ComponentModel.Composition.IStronglyTypedStructure_3b7f133d-79c7-449e-8f68-22aa093dbb8d' from assembly ''.
--nomethod System.ComponentModel.Composition.MetadataAttributeTests.StronglyTypedStructureTest
--nomethod System.ComponentModel.Composition.MetadataAttributeTests.StronglyTypedStructureTestWithTransparentViews
--nomethod System.ComponentModel.Composition.MetadataViewProviderTests.GetMetadataView_IMetadataViewWithDefaultedInt64
--nomethod System.ComponentModel.Composition.ExportCollectionTests.ImportCollectionsFromContainerOnly
-# disable the whole namespace, https://github.com/mono/mono/issues/16417
--nonamespace System.ComponentModel.Composition
-# same issue (only System.ComponentModel.Composition uses this namespace)
--nonamespace Tests.Integration
-
-####################################################################
-## System.Data.Common.Tests
-####################################################################
-
-# Invalid IL - IL_00bc: castclass 0x0100000d
--nomethod System.Data.Tests.SqlTypes.SqlCharsTest.ReadWriteXmlTest
-
-# Invalid IL code in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSqlInt32:Read1_int (): IL_00bc: castclass 0x0100000d
-# https://github.com/mono/mono/issues/15174
--nomethod System.Data.Tests.SqlTypes.SqlInt32Test.ReadWriteXmlTest
-
-# System.InvalidProgramException : Invalid IL code in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSqlInt64:Read1_long (): IL_00bc: castclass 0x0100000d
-# https://github.com/mono/mono/issues/15175
--nomethod System.Data.Tests.SqlTypes.SqlInt64Test.ReadWriteXmlTest
-
-# System.InvalidProgramException : Invalid IL code in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSqlDouble:Read1_double (): IL_00bc: castclass 0x0100000d
-# https://github.com/mono/mono/issues/15176
--nomethod System.Data.Tests.SqlTypes.SqlDoubleTest.ReadWriteXmlTest
-
-# System.InvalidProgramException : Invalid IL code in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSqlInt16:Read1_short (): IL_00bc: castclass 0x0100000d
-# https://github.com/mono/mono/issues/15177
--nomethod System.Data.Tests.SqlTypes.SqlInt16Test.ReadWriteXmlTest
-
-# System.InvalidProgramException : Invalid IL code in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSqlDecimal:Read1_decimal (): IL_00bc: castclass 0x0100000d
-# https://github.com/mono/mono/issues/15178
--nomethod System.Data.Tests.SqlTypes.SqlDecimalTest.ReadWriteXmlTest
-
-# System.InvalidProgramException : Invalid IL code in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSqlString:Read1_string (): IL_00bc: castclass 0x0100000d
-# https://github.com/mono/mono/issues/15179
--nomethod System.Data.Tests.SqlTypes.SqlStringTest.ReadWriteXmlTest
-
-# Assert IsNotNull failure
-# https://github.com/mono/mono/issues/15180
--nomethod System.Data.Common.Tests.DbConnectionTests.ProviderFactoryTest
-
-####################################################################
-## System.Diagnostics.StackTrace.Tests
-####################################################################
-
-# Expected -1, but got 0
-# https://github.com/mono/mono/issues/15183
--nomethod System.Diagnostics.Tests.StackFrameTests.Ctor_SkipFrames
-
-# Assertion differences
-# https://github.com/mono/mono/issues/15184
--nomethod System.Diagnostics.Tests.StackFrameTests.Ctor_Filename_LineNumber_ColNumber
-
-# A little off
-# Assert.Equal() Failure
-# ↓ (pos 0)
-# Expected: MoveNext at offset 90 in file:line:column···
-# Actual: .ctor at offset 90 in file:line:column Fi···
-# https://github.com/mono/mono/issues/15186
--nomethod System.Diagnostics.Tests.StackFrameTests.ToString_Invoke_ReturnsExpected
-
-# Assertion differences. Expects -1, got 0
-# https://github.com/mono/mono/issues/15187
--nomethod System.Diagnostics.Tests.StackFrameTests.Ctor_SkipFrames_FNeedFileInfo
-
-# JIT should not inline custom throw helpers
--nomethod System.Diagnostics.Tests.StackTraceTests.Ctor_Exception_SkipFrames
--nomethod System.Diagnostics.Tests.StackTraceTests.Ctor_Exception_SkipFrames_FNeedFileInfo
-
-####################################################################
-## System.Numerics.Vectors.Tests
-####################################################################
-
-# Expects NotSupportedException, but actual was TypeInitializationException
-# https://github.com/mono/mono/issues/15190
--nomethod System.Numerics.Tests.GenericVectorTests.ConstructorWithUnsupportedTypes_DateTime
--nomethod System.Numerics.Tests.GenericVectorTests.ConstructorWithUnsupportedTypes_Char
--nomethod System.Numerics.Tests.GenericVectorTests.ConstructorWithUnsupportedTypes_Guid
-
-####################################################################
-## System.Reflection.Context.Tests
-####################################################################
-
-# System.ArgumentNullException : Value cannot be null.
-# Parameter name: attributeType
-# https://github.com/mono/mono/issues/15191
--nomethod System.Reflection.Context.Tests.CustomReflectionContextTests.MapType_MemberAttributes_Success
--nomethod System.Reflection.Context.Tests.CustomReflectionContextTests.MapType_ParameterAttributes_Success
--nomethod System.Reflection.Context.Tests.CustomReflectionContextTests.MapType_Interface_Throws
-
-####################################################################
-## System.Reflection.Metadata.Tests
-####################################################################
-
-# Assertion... Expected true, got false
-# https://github.com/mono/mono/issues/15194
--nomethod System.Reflection.Tests.MetadataTokenTests.SuccessImpliesNonNilWithCorrectTable
-# Test broken on Mono, added in https://github.com/dotnet/corefx/pull/40581
--nomethod System.Reflection.Tests.MetadataLoadContextTests.RelocatableAssembly
-
-####################################################################
-## System.Runtime.Loader.RefEmitLoadContext.Tests
-####################################################################
-
-# Relies on AssemblyLoadContext.GetLoadContext, which is not implemented
--nomethod System.Runtime.Loader.Tests.RefEmitLoadContextTests.LoadRefEmitAssembly
-
-####################################################################
-## System.Threading.Overlapped.Tests
-####################################################################
-
-# Overflow Exception
-# https://github.com/mono/mono/issues/15197
-# https://github.com/mono/mono/issues/15311
-# These tests should be ignored on x64 in dotnet/corefx
--nomethod OverlappedTests.PropertyTest2
--nomethod OverlappedTests.PropertyTest3
-
-# NRE
-# https://github.com/mono/mono/issues/15312
--nomethod ThreadPoolBoundHandleTests.BindHandle_MinusOneAsHandle_ThrowsArgumentException
-
-# No Exception thrown
-# https://github.com/mono/mono/issues/15313
--nomethod ThreadPoolBoundHandleTests.PreAllocatedOverlapped_NonBlittableTypeAsPinData_Throws
--nomethod ThreadPoolBoundHandleTests.PreAllocatedOverlapped_ObjectArrayWithNonBlittableTypeAsPinData_Throws
--nomethod ThreadPoolBoundHandleTests.GetNativeOverlappedState_NullAsNativeOverlapped_ThrowsArgumentNullException
-
-# NRE on BindHandle
-# https://github.com/mono/mono/issues/15314
--nomethod ThreadPoolBoundHandleTests.BindHandle_ZeroAsHandle_ThrowsArgumentException
--nomethod ThreadPoolBoundHandleTests.BindHandle_NullAsHandle_ThrowsArgumentNullException
--nomethod ThreadPoolBoundHandleTests.BindHandle_ValidHandle_ThrowsPlatformNotSupportedException
-
-# Test not run
--nomethod ThreadPoolBoundHandleTests.PreAllocatedOverlapped_NullAsCallback_ThrowsArgumentNullException
-
-####################################################################
-## System.Runtime.Extensions.Tests
-####################################################################
-
-# Mono expands generic Types in stacktraces unlike the .NET Core (sounds more like a feature: https://gist.github.com/EgorBo/3abb37d2ff4fc904bc7472c62498f933)
-# https://github.com/mono/mono/issues/15315
--nomethod System.Tests.EnvironmentStackTrace.StackTraceTest
-
-# These events are not wired up in mono
-# https://github.com/mono/mono/issues/16246
--nomethod System.Tests.AppDomainTests.ResourceResolve
--nomethod System.Tests.AppDomainTests.FirstChanceException_Called
--nomethod System.Tests.AppDomainTests.AssemblyResolve_FirstChanceException
-
-# AssemblyLoadContext.SetProfileOptimizationRoot is no-op (not implemented)
--nomethod System.Runtime.Tests.ProfileOptimizationTest.ProfileOptimization_CheckFileExists
-
-####################################################################
-## System.Runtime.Handles.Tests
-####################################################################
-
-# NRE in SafeHandle.Dispose
-# https://github.com/mono/mono/issues/17224
--noclass SafeWaitHandleExtensions_4000_Tests
--noclass SafeWaitHandle_4000_Tests
-
-####################################################################
-## System.Reflection.TypeExtensions.Tests
-####################################################################
-
-# Assertion difference. Expects 2, but got 1
-# https://github.com/mono/mono/issues/15316
--nomethod System.Reflection.Tests.ConstructorInfoInvokeArrayTests.Invoke_1DArrayConstructor
-
-# Exception difference
-# https://github.com/mono/mono/issues/15317
--nomethod System.Reflection.Tests.ConstructorInfoTests.Invoke_Invalid
-
-# Large Array support
-# https://github.com/mono/mono/issues/15318
--nomethod System.Reflection.Tests.ConstructorInfoInvokeArrayTests.Invoke_LargeDimensionalArrayConstructor
-
-# Throws a lot of different exceptions
-# https://github.com/mono/mono/issues/15319
--nomethod System.Reflection.Tests.PropertyInfoTests.GetGetMethod_GetSetMethod
-
-# Extra methods
-# https://github.com/mono/mono/issues/15320
--nomethod System.Reflection.Tests.TypeTests.GetMethods
-
-####################################################################
-## System.Reflection.Emit.Lightweight.Tests
-####################################################################
-
-# A different CreateDelegate issue
-# https://github.com/mono/mono/issues/15321
--nomethod System.Reflection.Emit.Tests.DynamicMethodGetILGenerator1.GetILGenerator_Int_Module_CoreclrIgnoresSkipVisibility
--nomethod System.Reflection.Emit.Tests.DynamicMethodGetILGenerator1.GetILGenerator_Module_CoreclrIgnoresSkipVisibility
--nomethod System.Reflection.Emit.Tests.DynamicILInfoTests.GetTokenFor_IntGenerics_Success
-
-# Need to implement System.Reflection.Emit.DynamicILInfo.SetLocalSignature(Byte[] localSignature)
--nomethod System.Reflection.Emit.Tests.DynamicILInfoTests.Test_TwoDimTest
--nomethod System.Reflection.Emit.Tests.DynamicILInfoTests.Test_GenericMethod
--nomethod System.Reflection.Emit.Tests.DynamicILInfoTests.GetTokenFor_CtorMethodAndField_Success
--nomethod System.Reflection.Emit.Tests.DynamicILInfoTests.GetTokenFor_String_Success
--nomethod System.Reflection.Emit.Tests.DynamicILInfoTests.GetTokenFor_StringGenerics_Success
--nomethod System.Reflection.Emit.Tests.DynamicILInfoTests.Test_CallGM
--nomethod System.Reflection.Emit.Tests.DynamicILInfoTests.GetTokenFor_Exception_Success
--nomethod System.Reflection.Emit.Tests.DynamicILInfoTests.GetTokenFor_DynamicMethod_Success
-
-# Need to implement System.Reflection.Emit.DynamicILInfo.SetExceptions(Byte* exceptions, Int32 exceptionsSize)
--nomethod System.Reflection.Emit.Tests.DynamicILInfoTests.SetX_NullInput_ThrowsArgumentNullException
--nomethod System.Reflection.Emit.Tests.DynamicMethodctor1.InvalidOwner_ThrowsArgumentException
-
-# Expected: typeof(System.ArgumentOutOfRangeException)
-# Actual: typeof(System.OverflowException): Arithmetic operation resulted in an overflow.
-# https://github.com/mono/mono/issues/15334
--nomethod System.Reflection.Emit.Tests.DynamicILInfoTests.SetX_NegativeInputSize_ThrowsArgumentOutOfRangeException
-
-####################################################################
-## System.Runtime.Loader.Tests
-####################################################################
-
-# NOTE: Not run (relies on collectible ALCs)
--nomethod System.Runtime.Loader.Tests.ContextualReflectionTest.*
-
-# relies on collectible AssemblyLoadContext
--nomethod System.Runtime.Loader.Tests.AssemblyLoadContextTest.Unload_*
--nomethod System.Runtime.Loader.Tests.AssemblyLoadContextTest.Finalizer_CollectibleWithNoAssemblyLoaded
--nomethod System.Runtime.Loader.Tests.AssemblyLoadContextTest.PublicConstructor_Theory
--nomethod System.Runtime.Loader.Tests.AssemblyLoadContextTest.Unsupported_FixedAddressValueType
-
-# relies on specific exception message
--nomethod System.Runtime.Loader.Tests.AssemblyLoadContextTest.LoadFromAssemblyPath_PartiallyQualifiedPath_ThrowsArgumentException
--nomethod System.Runtime.Loader.Tests.AssemblyLoadContextTest.LoadFromNativeImagePath_PartiallyQualifiedPath_ThrowsArgumentException
--nomethod System.Runtime.Loader.Tests.AssemblyLoadContextTest.LoadFromNativeImagePath_PartiallyQualifiedPath_ThrowsArgumentException2
-
-####################################################################
-## System.Reflection.MetadataLoadContext.Tests
-####################################################################
-
-# https://github.com/mono/mono/issues/15340
--nomethod System.Reflection.Tests.CustomAttributeTests.TestDllImportPseudoCustomAttribute
--nomethod System.Reflection.Tests.CustomAttributeTests.TestMarshalAsPseudoCustomAttribute
--nomethod System.Reflection.Tests.ParameterTests.TestPseudoCustomAttributes
--nomethod System.Reflection.Tests.TypeTests.TestExplicitOffsetPseudoCustomAttribute
-
-# Assertion failure: Expected: true, Actual: false
-# https://github.com/mono/mono/issues/15344
--nomethod System.Reflection.Tests.TypeInvariants.TestInvariantCode
-
-# flaky tests
--nomethod System.Reflection.Tests.TypeInfoDeclaredImplementedInterfacesTests.*
-
-####################################################################
-## System.Utf8String.Experimental.Tests
-####################################################################
-
-# Experimental feature
-# Will be removed and we can skip for now.
--nomethod System.Tests.MemoryTests.*
--nomethod System.Tests.Utf8StringTests.*
--nomethod System.Tests.Utf8ExtensionsTests.*
--nomethod System.Tests.ReflectionTests.*
--nomethod System.Net.Http.Tests.Utf8StringContentTests.*
-
-####################################################################
-## System.ComponentModel.Composition.Registration.Tests
-####################################################################
-
-# System.ComponentModel.Composition.Registration APIs are not supported on this platform.
--nomethod System.ComponentModel.Composition.Registration.Tests.RegistrationBuilderTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.PartBuilderUnitTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.PartBuilderOfTInheritanceTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.ExportBuilderUnitTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.RegistrationBuilderAttributedOverrideUnitTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.PartBuilderOfTTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.PartBuilderTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.ExportBuilderTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.ImportBuilderTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.RegistrationBuilderUnitTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.RegistrationBuilderExportFuncUnitTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.PartBuilderInterfaceTests.*
--nomethod System.ComponentModel.Composition.Registration.Tests.ExportInterfacesContractExclusionTests.*
-
-####################################################################
-## System.Xml.Xsl.XslTransformApi.Tests
-####################################################################
-
-# Xml differences... Looks like the parsing isn't working
-# https://github.com/mono/mono/issues/15353
--nomethod System.Xml.Tests.CXmlResolverTest.TC_AbsolutePath_Transform
--nomethod System.Xml.Tests.CTransformResolverTest.TC_AbsolutePath_Transform
-
-####################################################################
-## System.Security.Cryptography.X509Certificates.Tests
-####################################################################
-
-# Passes local, but leaving here because it may be flaky
--nomethod System.Security.Cryptography.X509Certificates.Tests.DynamicChainTests.TestInvalidAia
-
-# disabled in CoreCLR too
--noclass System.Security.Cryptography.X509Certificates.Tests.X509Certificate2UITests
-
--nomethod System.IO.Tests.File_Move_Tests.File_Move_From_Unwatched_To_Watched
-
-# unxpected non-breaking space in strings (char(160) - char(32))
--nomethod DataContractJsonSerializerTests.DCJS_VerifyDateTimeForDateTimeFormat
--nomethod DataContractJsonSerializerTests.DCJS_VerifyDateTimeForFormatStringDCJsonSerSettings
-
-# GetCustomAttribute should ignore NullableContextAttribute?
--nomethod System.Reflection.Tests.GetCustomAttributes_MemberInfo.GetCustomAttributeAll
--nomethod System.Tests.AttributeGetCustomAttributes.MultipleAttributesTest
-
-# Unexpected IntPtr.Zero from Interop.Mmap
--nomethod System.IO.MemoryMappedFiles.Tests.MemoryMappedViewAccessorTests.ValidAccessLevelCombinations
--nomethod System.IO.MemoryMappedFiles.Tests.MemoryMappedViewStreamTests.ValidAccessLevelCombinations
-
-# requires precise gc (to be ignored in dotnet/corefx, e.g. https://github.com/dotnet/corefx/pull/39176)
--nomethod System.IO.Tests.FileStream_Dispose.Dispose_CallsVirtualDispose_TrueArg
--nomethod System.Net.Sockets.Tests.DisposedSocket.NonDisposedSocket_SafeHandlesCollected
--nomethod System.Diagnostics.TraceSourceTests.SwitchClassTests.PruneTest
-
-# Flaky test (FileSystemWatcher)
--nomethod System.IO.Tests.Directory_NotifyFilter_Tests.FileSystemWatcher_Directory_NotifyFilter_LastWriteTime
-
-####################################################################
-## System.Security.Cryptography.Encoding.Tests
-####################################################################
-
-# Broken array copying (https://github.com/mono/mono/issues/16686)
--nomethod System.Security.Cryptography.Encoding.Tests.OidTests.LookupOidByFriendlyName_Method_InverseCase
--nomethod System.Security.Cryptography.Encoding.Tests.OidTests.LookupOidByValue_Ctor
--nomethod System.Security.Cryptography.Encoding.Tests.OidTests.Oid_StringString_NullFriendlyName
--nomethod System.Security.Cryptography.Encoding.Tests.OidTests.LookupOidByFriendlyName_Ctor
-
--nomethod System.Tests.StringComparerTests.CreateCultureOptions_InvalidArguments_Throws
diff --git a/netcore/CoreFX.issues_interpreter.rsp b/netcore/CoreFX.issues_interpreter.rsp
deleted file mode 100644
index 0e6ac78479e..00000000000
--- a/netcore/CoreFX.issues_interpreter.rsp
+++ /dev/null
@@ -1,31 +0,0 @@
--nomethod System.Runtime.CompilerServices.Tests.RuntimeFeatureTests.DynamicCode_Jit
--nomethod System.Net.Security.Tests.SslStreamStreamToStreamTest_*
--nomethod System.IO.Compression.DeflateStreamUnitTests.*
--nomethod System.IO.Compression.GzipStreamUnitTests.*
--nomethod System.Net.Tests.ServicePointManagerTest.FindServicePoint_Collectible
--nomethod System.Security.Cryptography.Hashing.Tests.HashAlgorithmTest.VerifyComputeHashAsync
-
-# crashes on Interpreter
--nomethod System.Net.Http.Functional.Tests.SocketsHttpHandler*
--nonamespace System.Net.Http.Functional.Tests
-
-# Dereferencing of random pointers crashes instead of throwing
--nonamespace System.Runtime.InteropServices.Tests
-
-# BrotliStream.BaseStream returned more bytes than requested in Read on Interpreter
--nomethod System.IO.Compression.BrotliStreamUnitTests.Read
--nomethod System.IO.Compression.BrotliStreamUnitTests.Read_SequentialReadsOnMemoryStream_Return_SameBytes
--nomethod System.IO.Compression.BrotliStreamUnitTests.Parallel_CompressDecompressMultipleStreamsConcurrently
--nomethod System.IO.Compression.BrotliStreamUnitTests.Read_BaseStreamSlowly
--nomethod System.IO.Compression.BrotliStreamUnitTests.CompressDecompress_RoundTrip
--nomethod System.IO.Compression.BrotliStreamUnitTests.Flush_RoundTrip
--nomethod System.IO.Compression.BrotliStreamUnitTests.Flush_BeforeFirstWrites
--nomethod System.IO.Compression.BrotliStreamUnitTests.Flush_Consecutive
-
-# extremely slow or hangs on Interpreter
--nomethod System.IO.Compression.BrotliStreamUnitTests.WrapStreamReturningBadReadValues
--nomethod System.Runtime.Serialization.Formatters.Tests.BinaryFormatterTests.*
--nomethod System.Net.Sockets.Tests.SendReceiveSyncForceNonBlocking.TcpReceiveSendGetsCanceledByDispose
-
-# flaky test, likely fixed in dotnet/runtime: https://github.com/mono/mono/issues/18695
--nomethod System.Net.NetworkInformation.Tests.NetworkInterfaceBasicTest.BasicTest_AccessInstanceProperties_NoExceptions_Linux
diff --git a/netcore/CoreFX.issues_linux.rsp b/netcore/CoreFX.issues_linux.rsp
deleted file mode 100644
index b442e548ecd..00000000000
--- a/netcore/CoreFX.issues_linux.rsp
+++ /dev/null
@@ -1,39 +0,0 @@
-# See TODO in AssemblyLoadContext.InternalLoadFromPath()
--nomethod System.Tests.ActivatorTests.TestingCreateInstanceFromObjectHandleFullSignature
--nomethod System.Tests.ActivatorTests.TestingCreateInstanceFromObjectHandle
--nomethod System.Tests.AppDomainTests.TestingCreateInstanceFromObjectHandleFullSignature
--nomethod System.Tests.AppDomainTests.TestingCreateInstanceFromObjectHandle
-
-# hangs
--nomethod *.HttpClientUsesSslCertEnvironmentVariables
--nomethod System.Threading.Tasks.Dataflow.Tests.DataflowBlockExtensionsTests.*
-
-# dllmap is not working
--nonamespace System.IO.MemoryMappedFiles
--nonamespace System.Diagnostics.Tests
--nonamespace System.IO.Tests
--nomethod System.IO.Pipes.Tests.NamedPipeTest_CreateClient.NotSupportedPipePath_Throws_PlatformNotSupportedException
--nomethod System.Net.Sockets.Tests.SocketOptionNameTest.ReuseAddressUdp
-
--nomethod System.Tests.WeakReferenceTests.Generic
--nomethod System.Reflection.Tests.AssemblyTests.CreateInstance
-
-# StackOverflow somewhere here
--nonamespace System.Threading.Tasks.Tests
-
-# Requires precise GC (should be ignored in dotnet/corefx for mono)
--nomethod System.Collections.Concurrent.Tests.ConcurrentQueueTests.ReferenceTypes_NulledAfterDequeue
--nomethod System.Threading.Tests.ThreadLocalTests.RunThreadLocalTest7_WeakReference
--nomethod System.ComponentModel.EventBasedAsync.Tests.BackgroundWorkerTests.TestFinalization
-
-# fails with some OpenSSL error
--nomethod System.Net.Security.Tests.ServerRequireEncryptionTest.ServerRequireEncryption_ClientNoEncryption_NoConnect
--nomethod System.Net.Security.Tests.SslStreamAlpnTests.SslStream_StreamToStream_Alpn_NonMatchingProtocols_Fail
--nomethod System.Net.Security.Tests.ClientDefaultEncryptionTest.ClientDefaultEncryption_ServerNoEncryption_NoConnect
--nomethod System.Net.Security.Tests.ServerNoEncryptionTest.ServerNoEncryption_ClientRequireEncryption_NoConnect
--nomethod System.Net.Security.Tests.ClientAsyncAuthenticateTest.ClientAsyncAuthenticate_ServerNoEncryption_NoConnect
--nomethod System.Net.Security.Tests.ServerAsyncAuthenticateTest.ServerAsyncAuthenticate_MismatchProtocols_Fails
--nomethod System.Net.Security.Tests.ClientAsyncAuthenticateTest.ClientAsyncAuthenticate_MismatchProtocols_Fails
-
-# https://github.com/mono/mono/issues/18067 LLVM: try-catch doesn't catch an exception
--nomethod System.Reflection.Tests.BindingFlagsDoNotWrapTests.*
diff --git a/netcore/CoreFX.issues_linux_arm64.rsp b/netcore/CoreFX.issues_linux_arm64.rsp
deleted file mode 100644
index 9e071c9b1c2..00000000000
--- a/netcore/CoreFX.issues_linux_arm64.rsp
+++ /dev/null
@@ -1,2 +0,0 @@
-# these tests are extremly slow on our arm64 CI
--nonamespace System.Transactions.Tests
diff --git a/netcore/CoreFX.issues_mac.rsp b/netcore/CoreFX.issues_mac.rsp
deleted file mode 100644
index d9eacab5d1c..00000000000
--- a/netcore/CoreFX.issues_mac.rsp
+++ /dev/null
@@ -1,2 +0,0 @@
-# https://github.com/mono/mono/issues/17547
--nomethod System.IO.Tests.FileSystemWatcherTests_netstandard17.DroppedWatcher_Collectible
diff --git a/netcore/CoreFX.issues_windows.rsp b/netcore/CoreFX.issues_windows.rsp
deleted file mode 100644
index d9e73653adc..00000000000
--- a/netcore/CoreFX.issues_windows.rsp
+++ /dev/null
@@ -1,73 +0,0 @@
-# GCSettings.SetGCLatencyMode is not implemented
--nomethod System.Tests.GCTests.LatencyRoundtrips_LowLatency
-
-# Type.GetTypeFromCLSID is not implemented
--nomethod System.Tests.TypeTestsNetcore.*
-
-# these math functions should be portable, e.g. see HAVE_COMPATIBLE_EXP in coreclr
--nomethod System.Tests.MathFTests.Acosh
--nomethod System.Tests.MathFTests.Atanh
--nomethod System.Tests.MathFTests.Asinh
--nomethod System.Tests.MathTests.Acosh
--nomethod System.Tests.MathTests.Atanh
--nomethod System.Tests.MathTests.Asinh
--nomethod Microsoft.VisualBasic.Tests.ConversionTests.Val
-
-# segfault
--nomethod Microsoft.VisualBasic.Tests.FileSystemTests.Input_Object_Write
-
-# TODO: investigate (too many failures or stuck)
--nomethod System.Threading.Tests.WaitHandleTests.SignalAndWait
--nomethod System.Threading.Tests.WaitHandleTests.WaitAll_SameNames
--nomethod System.Tests.ActivatorTests.TestingCreateInstanceObjectHandleFullSignatureWinRT
--nonamespace System.IO.Pipes.Tests
--nonamespace System.IO.Tests
--nonamespace System.Net
--nonamespace System.Threading.Tasks.Dataflow.Tests
--nonamespace System.Security.Cryptography.Pkcs
--nonamespace System.Runtime.InteropServices.WindowsRuntime
--nonamespace System.Management.Tests
--nonamespace System.Data.SqlClient.Tests
--nonamespace System.Threading.Overlapped.Tests
--nonamespace System.ComponentModel.Composition
--nonamespace BasicEventSourceTests
--nonamespace System.ComponentModel.TypeConverterTests
-
--nomethod System.Diagnostics.Tests.CounterSampleTests.*
--nomethod Tests.Integration.DiscoveryTests.DiscoverAddinsWithCombinedCustomExportAndMetadataAttribute
--nomethod WindowAndCursorProps.*
--nomethod System.Diagnostics.Tests.ProcessStartInfoTests.StartInfo_BadVerb
--nomethod System.Diagnostics.Tests.ProcessStartInfoTests.StartInfo_BadExe
--nomethod System.Diagnostics.Tests.ProcessTests.ProcessStart_UseShellExecute_Executes
--nomethod System.Diagnostics.Tests.ProcessTests.ProcessStart_UseShellExecute_WorkingDirectory
--nomethod System.Diagnostics.TraceSourceTests.SwitchClassTests.PruneTest
--nomethod System.DirectoryServices.AccountManagement.Tests.PrincipalContextTests.Ctor_ContextType
--nomethod System.DirectoryServices.AccountManagement.Tests.PrincipalContextTests.ValidateCredentials_Invoke_ReturnsExpected
--nomethod System.DirectoryServices.AccountManagement.Tests.ComputerPrincipalTest.Ctor_MachineContext_NoException
--nomethod System.DirectoryServices.ActiveDirectory.Tests.DomainControllerTests.GetDomainController_InvalidIPV6
--nomethod System.DirectoryServices.Tests.DirectoryEntryTests.DeleteTree_NoObject_ThrowsCOMException
--nomethod System.DirectoryServices.ActiveDirectory.Tests.ForestTests.GetForest_NonNullNameAndNotRootedDomain_ThrowsActiveDirectoryObjectNotFoundException
--nomethod System.Reflection.Internal.Tests.AbstractMemoryBlockTests.FileStream
--nomethod System.Reflection.Internal.Tests.AbstractMemoryBlockTests.FileStreamUnix
--nomethod System.Reflection.Tests.MemberInfoNetCoreAppTests.*
--nomethod System.Reflection.Tests.AssemblyNameTests.GetAssemblyName_LockedFile
--nomethod System.Resources.Extensions.Tests.PreserializedResourceWriterTests.*
--nomethod System.Resources.Tests.ResourceManagerTests.*
--nomethod MonoTests.System.Runtime.Caching.HostFileChangeMonitorTest.*
--nomethod SafeHandle_4000_Tests.SafeHandle_DangerousReleasePreservesLastError
--nomethod System.Security.Cryptography.X509Certificates.Tests.FindTests.*
--nomethod OverlappedTests.PackPosTest1
--nomethod OverlappedTests.PackPosTest
--nomethod ThreadPoolBoundHandleTests.*
--nomethod System.Threading.Tests.EventWaitHandleTests.*
--nomethod System.Threading.Tests.MutexTests.*
--nomethod System.Threading.Tests.SemaphoreTests.*
--nomethod System.Threading.Threads.Tests.ThreadTests.*
--nomethod System.ComponentModel.TypeConverterTests
--nomethod System.Xml.Tests.CTransformResolverTest.TC_AbsolutePath_Transform
--nomethod System.Tests.StringTests.NormalizationTest
--nomethod System.Globalization.Tests.StringNormalizationAllTests.Normalize
--nomethod System.Globalization.Tests.StringNormalizationTests.IsNormalized
-
-# * Assertion at method-to-ir.c:12425, condition `var->opcode == OP_REGOFFSET' not met
--nomethod System.Runtime.Tests.NullableMetadataTests.ShimsHaveOnlyTypeForwards \ No newline at end of file
diff --git a/netcore/Directory.Build.props b/netcore/Directory.Build.props
deleted file mode 100644
index 2b58132e60e..00000000000
--- a/netcore/Directory.Build.props
+++ /dev/null
@@ -1,61 +0,0 @@
-<Project TreatAsLocalProperty="ExcludeRestorePackageImports">
-
- <PropertyGroup>
- <!--
- For non-SDK projects that import this file and then import Microsoft.Common.props,
- tell Microsoft.Common.props not to import Directory.Build.props again
- -->
- <ImportDirectoryBuildProps>false</ImportDirectoryBuildProps>
-
- <!-- We use the compiler toolset that comes from NuGet Packages rather than the SDK built-in.
- This one sets UseSharedCompilation to false by default. -->
- <UseSharedCompilation>true</UseSharedCompilation>
-
- <ToolSetCommonDirectory>$(MSBuildThisFileDirectory)artifacts\toolset\Common\</ToolSetCommonDirectory>
- <IsSourceProject>$([System.Text.RegularExpressions.Regex]::IsMatch($(MSBuildProjectDirectory), 'src%24'))</IsSourceProject>
- </PropertyGroup>
-
- <PropertyGroup>
- <RestoreSources Condition="'$(DotNetBuildOffline)' != 'true'">
- https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json;
- https://dotnetfeed.blob.core.windows.net/dotnet-coreclr/index.json;
- https://api.nuget.org/v3/index.json;
- $(OverridePackageSource);
- $(RestoreSources)
- </RestoreSources>
- </PropertyGroup>
-
- <!-- Informs build tools to apply .NET Framework metadata if not a test project -->
- <PropertyGroup>
- <IsDotNetFrameworkProductAssembly>true</IsDotNetFrameworkProductAssembly>
- </PropertyGroup>
-
- <!-- Indicates this is not an officially supported release. Release branches should set this to false. -->
- <PropertyGroup>
- <IsPrerelease>true</IsPrerelease>
- </PropertyGroup>
-
- <Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" />
-
- <PropertyGroup Condition="'$(CopyrightNetFoundation)' != ''">
- <Copyright>$(CopyrightNetFoundation)</Copyright>
- <PackageLicenseExpression>MIT</PackageLicenseExpression>
- </PropertyGroup>
-
-
- <!-- Language configuration -->
- <PropertyGroup>
- <!-- default to allowing all language features -->
- <LangVersion>preview</LangVersion>
- <!-- Enables Strict mode for Roslyn compiler -->
- <Features>strict</Features>
- <WarningLevel>4</WarningLevel>
- <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
- <Deterministic>true</Deterministic>
-
- <!-- Suppress preview message as we are usually using preview SDK versions. -->
- <SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
-
- <GenFacadesIgnoreBuildAndRevisionMismatch>true</GenFacadesIgnoreBuildAndRevisionMismatch>
- </PropertyGroup>
-</Project> \ No newline at end of file
diff --git a/netcore/Directory.Build.targets b/netcore/Directory.Build.targets
deleted file mode 100644
index bc6bef528fb..00000000000
--- a/netcore/Directory.Build.targets
+++ /dev/null
@@ -1,3 +0,0 @@
-<Project>
- <Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
-</Project> \ No newline at end of file
diff --git a/netcore/Makefile b/netcore/Makefile
deleted file mode 100644
index d96668e68ed..00000000000
--- a/netcore/Makefile
+++ /dev/null
@@ -1,345 +0,0 @@
-ifneq ($(wildcard config.make),)
-
-include config.make
-
-NETCORETESTS_VERSION := $(shell cat ../eng/Versions.props | sed -n 's/.*MicrosoftPrivateCoreFxNETCoreAppVersion>\(.*\)<\/MicrosoftPrivateCoreFxNETCoreAppVersion.*/\1/p' )
-NETCOREAPP_VERSION := $(shell cat ../eng/Versions.props | sed -n 's/.*MicrosoftNETCoreAppVersion>\(.*\)<\/MicrosoftNETCoreAppVersion.*/\1/p' )
-ROSLYN_VERSION:= $(shell cat ../eng/Versions.props | sed -n 's/.*MicrosoftNetCompilersVersion>\(.*\)<\/MicrosoftNetCompilersVersion.*/\1/p' )
-
-# Should be automated but not sure how for now
-# the name is misleading osx version is used for any unix like systems
-# the url is manually extracted from coreclr-outerloop (https://dev.azure.com/dnceng/public/_build?definitionId=98&_a=summary) Build artifacts published page
-CORECLR_TESTS:=https://dev.azure.com/dnceng/9ee6d478-d288-47f7-aacc-f6e6d082ae6d/_apis/build/builds/368250/artifacts?artifactName=Tests_OSX_x64_checked_outerloop&api-version=5.2-preview.5&%24format=zip
-
-# runtime version used by $(DOTNET) - local .net core sdk to bootstrap stuff
-# it doesn't match NETCOREAPP_VERSION
-BOOTSTRAP_RUNTIME = $(shell ls ../.dotnet/shared/Microsoft.NETCore.App | tail -1)
-
-ifeq ($(HOST_PLATFORM),win32)
-PLATFORM_AOT_SUFFIX := .dll
-PLATFORM_AOT_PREFIX :=
-NETCORESDK_EXT = zip
-UNZIPCMD = $(PYTHON) -c "import zipfile,sys; zipfile.ZipFile(sys.argv[1], 'r').extractall()"
-XUNIT_INNER_ARGS = -notrait category=nonwindowstests @../../../../CoreFX.issues_windows.rsp
-TESTS_PLATFORM = Windows_NT.x64
-ON_RUNTIME_EXTRACT = chmod -R 755 {host,shared,./dotnet}
-DOTNET := $(shell powershell -ExecutionPolicy Bypass -Command "./init-tools.ps1")/dotnet.exe
-DOTNET := "$(subst \,/,$(DOTNET))"
-endif
-
-ifeq ($(HOST_PLATFORM),macos)
-PLATFORM_AOT_SUFFIX := .dylib
-PLATFORM_AOT_PREFIX := lib
-OBJDUMP = objdump -x86-asm-syntax=intel --no-show-raw-insn -no-leading-addr -no-leading-headers -d
-NETCORESDK_EXT = tar.gz
-UNZIPCMD = tar -xvf
-XUNIT_INNER_ARGS = -notrait category=nonosxtests @../../../../CoreFX.issues_mac.rsp
-TESTS_PLATFORM = OSX.x64
-DOTNET := $(shell ./init-tools.sh | tail -1)
-endif
-
-ifeq ($(HOST_PLATFORM),linux)
-PLATFORM_AOT_SUFFIX := .so
-PLATFORM_AOT_PREFIX := lib
-OBJDUMP = objdump -M intel --no-show-raw-insn -d
-NETCORESDK_EXT = tar.gz
-UNZIPCMD = tar -xvf
-XUNIT_INNER_ARGS = -notrait category=nonlinuxtests @../../../../CoreFX.issues_linux.rsp
-ifeq ($(COREARCH), arm64)
-XUNIT_INNER_ARGS += @../../../../CoreFX.issues_linux_arm64.rsp
-endif
-TESTS_PLATFORM = Linux.x64
-DOTNET := $(shell ./init-tools.sh | tail -1)
-endif
-
-NETCORESDK_FILE := dotnet-runtime-$(NETCOREAPP_VERSION)-$(RID).$(NETCORESDK_EXT)
-NETCORE_URL := https://dotnetcli.blob.core.windows.net/dotnet/Runtime/$(NETCOREAPP_VERSION)/$(NETCORESDK_FILE)
-FEED_BASE_URL := https://dotnetfeed.blob.core.windows.net/dotnet-core
-TEST_ASSETS_PATH := corefx-tests/$(NETCORETESTS_VERSION)/$(TESTS_PLATFORM)/netcoreapp/corefx-test-assets.xml
-
-# used to calculate exact version number for generating nupkg
-BLAME = $(shell git blame ../configure.ac | grep AC_INIT | cut -f1 -d' ')
-VERSTUB = .$(shell git rev-list --count $(BLAME)..HEAD)-preview
-
-all: bcl
-
-$(NETCORESDK_FILE):
- curl $(NETCORE_URL) --output $(NETCORESDK_FILE)
- rm -rf shared/Microsoft.NETCore.App
- $(UNZIPCMD) $(NETCORESDK_FILE)
- $(ON_RUNTIME_EXTRACT)
-
-update-corefx: corefx/.stamp-dl-corefx-$(NETCORETESTS_VERSION)
-
-corefx/.stamp-dl-corefx-$(NETCORETESTS_VERSION): corefx-restore.csproj
- $(DOTNET) build corefx-restore.csproj --runtime $(RID) --packages corefx/packages -p:MicrosoftPrivateCoreFxNETCoreAppVersion=$(NETCORETESTS_VERSION) -p:OutputPath=corefx/restore/ -p:UseSharedCompilation=false
- touch $@
-
-update-roslyn: roslyn/packages/microsoft.net.compilers.toolset/$(ROSLYN_VERSION)/microsoft.net.compilers.toolset.nuspec
-
-roslyn/packages/microsoft.net.compilers.toolset/$(ROSLYN_VERSION)/microsoft.net.compilers.toolset.nuspec:
- $(DOTNET) restore roslyn-restore.csproj -p:RoslynVersion=$(ROSLYN_VERSION) --packages roslyn/packages -p:OutputPath=roslyn/restore/ -p:UseSharedCompilation=false
-
-run-sample: prepare
- $(DOTNET) build sample/HelloWorld
- MONO_ENV_OPTIONS="--debug" COMPlus_DebugWriteToStdErr=1 ./dotnet --fx-version "$(NETCOREAPP_VERSION)" sample/HelloWorld/bin/netcoreapp3.0/HelloWorld.dll
-
-run-sample-dbg: prepare
- $(DOTNET) build sample/HelloWorld
- MONO_ENV_OPTIONS="--debug --debugger-agent=transport=dt_socket,address=127.0.0.1:1235,server=y,suspend=y" COMPlus_DebugWriteToStdErr=1 ./dotnet --fx-version "$(NETCOREAPP_VERSION)" sample/HelloWorld/bin/netcoreapp3.0/HelloWorld.dll
-
-run-sample-coreclr:
- cd sample/HelloWorld && $(DOTNET) run
-
-# build any app in "self contained" mode and patch coreclr.dll and corelib with mono bits
-# e.g. `make patch-app APP_PATH=/my/aspnetapp`
-patch-app: prepare
- @if test -z "$(APP_PATH)"; then echo "APP_PATH is not set"; exit 1; fi
- cp NuGet.config $(APP_PATH)
- cd $(APP_PATH) && $(DOTNET) publish -c Release -r $(RID) -f netcoreapp3.0
- cp ../mono/mini/.libs/libmonosgen-2.0$(PLATFORM_AOT_SUFFIX) $(APP_PATH)/bin/Release/netcoreapp3.0/$(RID)/publish/$(PLATFORM_AOT_PREFIX)coreclr$(PLATFORM_AOT_SUFFIX)
- cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.dll $(APP_PATH)/bin/Release/netcoreapp3.0/$(RID)/publish
- cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.pdb $(APP_PATH)/bin/Release/netcoreapp3.0/$(RID)/publish
-
-# makes $(DOTNET) to use mono runtime (to run real-world apps using '$(DOTNET) run')
-patch-local-dotnet: prepare
- cp ../mono/mini/.libs/libmonosgen-2.0$(PLATFORM_AOT_SUFFIX) ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME)/$(PLATFORM_AOT_PREFIX)coreclr$(PLATFORM_AOT_SUFFIX)
- cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.dll ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME)
- cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.pdb ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME)
-
-# Precompile BCL libs in $(DOTNET) using LLVM (requires `--enable-llvm` build)
-patch-local-dotnet-aot-llvm: patch-local-dotnet
- for assembly in ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME)/*.dll; do \
- echo "[AOT] $$assembly"; \
- PATH="../llvm/usr/bin/:$(PATH)" \
- MONO_ENV_OPTIONS="--aot=llvm,mcpu=native" \
- $(DOTNET) $$assembly ; \
- done; \
-
-# run 'dotnet/performance' benchmarks
-# e.g. 'make run-benchmarks DOTNET_PERF_REPO=/prj/performance'
-# you can append BDN parameters at the end, e.g. ` -- --filter Burgers --keepFiles`
-# NOTE: we have to delete a couple of System.Drawing files to make it work
-run-benchmarks: patch-local-dotnet
- @if test -z "$(DOTNET_PERF_REPO)"; then echo "DOTNET_PERF_REPO is not set"; exit 1; fi
- cd $(DOTNET_PERF_REPO)/src/benchmarks/micro/ && \
- > corefx/System.Drawing/Perf_Color.cs && \
- > corefx/System.Drawing/Perf_Graphics_DrawBeziers.cs && \
- > corefx/System.Drawing/Perf_Graphics_Transforms.cs && \
- > corefx/System.Drawing/Perf_Image_Load.cs && \
- $(DOTNET) run -c Release -f netcoreapp5.0 --cli $(CURDIR)/../.dotnet/dotnet
-
-# run HelloWorld using --aot=llvm (requires `--enable-llvm` build)
-run-sample-local-dotnet-llvm: patch-local-dotnet
- $(DOTNET) build -c Release sample/HelloWorld
- PATH="../llvm/usr/bin/:$(PATH)" \
- MONO_ENV_OPTIONS="--aot=llvm,mcpu=native" \
- $(DOTNET) sample/HelloWorld/bin/netcoreapp3.0/HelloWorld.dll
- $(DOTNET) sample/HelloWorld/bin/netcoreapp3.0/HelloWorld.dll
-
-# COREHOST_TRACE=1
-SHAREDRUNTIME := shared/Microsoft.NETCore.App/$(NETCOREAPP_VERSION)
-
-System.Private.CoreLib/src/System/Environment.Mono.cs: System.Private.CoreLib/src/System/Environment.Mono.in config.make
- test -n '$(MONO_CORLIB_VERSION)'
- sed -e 's,@''MONO_CORLIB_VERSION@,$(MONO_CORLIB_VERSION),' $< > $@
-
-CORLIB_BUILD_FLAGS?=-c Release
-
-bcl: update-roslyn System.Private.CoreLib/src/System/Environment.Mono.cs
- $(DOTNET) build $(CORETARGETS) $(CORLIB_BUILD_FLAGS) -p:UseSharedCompilation=false -p:BuildArch=$(COREARCH) \
- -p:OutputPath=bin/$(COREARCH) \
- -p:RoslynPropsFile="../roslyn/packages/microsoft.net.compilers.toolset/$(ROSLYN_VERSION)/build/Microsoft.Net.Compilers.Toolset.props" \
- System.Private.CoreLib/System.Private.CoreLib.csproj
-
-debug-bcl:
- $(MAKE) bcl CORLIB_BUILD_FLAGS="-c Debug"
-
-runtime:
- $(MAKE) -C ../mono
-
-link-mono: $(SHAREDRUNTIME)/.stamp-link-mono
-
-$(SHAREDRUNTIME)/.stamp-link-mono: ../mono/mini/.libs/libmonosgen-2.0$(PLATFORM_AOT_SUFFIX) System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.dll System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.pdb
- cp ../mono/mini/.libs/libmonosgen-2.0$(PLATFORM_AOT_SUFFIX) $(SHAREDRUNTIME)/$(PLATFORM_AOT_PREFIX)coreclr$(PLATFORM_AOT_SUFFIX)
- cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.dll $(SHAREDRUNTIME)
- cp System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.pdb $(SHAREDRUNTIME)
- touch $@
-
-prepare: $(NETCORESDK_FILE) update-corefx update-roslyn link-mono
-
-pack-%:
- $(DOTNET) pack roslyn-restore.csproj -p:IsPackable=true -p:NuspecFile=$*.nuspec -p:NuspecProperties=\"RID=$(RID)\;VERSION=$(VERSION)$(VERSTUB)\;PLATFORM_AOT_SUFFIX=$(PLATFORM_AOT_SUFFIX)\;COREARCH=$(COREARCH)\;PLATFORM_AOT_PREFIX=$(PLATFORM_AOT_PREFIX)\" --output ../artifacts/ --no-build
-
-nupkg: pack-metapackage pack-runtime
-nupkg-llvm: pack-metapackage-llvm pack-runtime-llvm
-
-clean:
- rm -rf .configured ../.dotnet sdk shared host dotnet tests obj corefx roslyn LICENSE.txt ThirdPartyNotices.txt $(NETCORESDK_FILE)
-
-
-update-tests-corefx: corefx/.stamp-dl-corefx-tests-$(NETCORETESTS_VERSION)
-
-corefx/.stamp-dl-corefx-tests-$(NETCORETESTS_VERSION):
- rm -rf corefx/tests
- $(DOTNET) msbuild corefx-tests-restore.proj -m -t:DownloadAllTests -p:TEST_ASSETS_PATH="$(TEST_ASSETS_PATH)" -p:FEED_BASE_URL="$(FEED_BASE_URL)"
- rm -rf corefx/tests/extracted/System.Utf8String.Experimental.Tests
- touch $@
-
-#
-# Running CoreFX tests
-#
-# You can run either individual test assembly or run all CoreFX tests. The tests are automatically downloaded
-# from the shared location and built locally.
-#
-# Running all test: `make run-tests-corefx`
-#
-# Running individual test: MONO_ENV_OPTIONS="--debug" make run-tests-corefx-System.Collections.Tests
-#
-
-run-tests-corefx: prepare update-tests-corefx
- @rm -f .failures; \
- counter=0; \
- tests_count=$(words $(dir $(wildcard corefx/tests/extracted/*/))); \
- for testdir in corefx/tests/extracted/*; do \
- counter=$$((counter+1)); \
- testname=$$(basename $$testdir); \
- if [ -n "$$USE_TIMEOUT" ]; then timeoutcmd="../scripts/ci/run-step.sh --label=$$testname --timeout=10m --fatal"; fi; \
- $$timeoutcmd $(MAKE) run-tests-corefx-$$testname XUNIT_MONO_ENV_OPTIONS="$(XUNIT_MONO_ENV_OPTIONS)" XUNIT_ARGS="$(XUNIT_ARGS)" TEST_COUNTER="($$counter / $$tests_count) " || echo $$testname >> .failures; \
- done; \
- $(MAKE) xunit-summary; \
- if [ -e ".failures" ]; then \
- echo ""; \
- echo "Failures in test suites:"; \
- cat .failures; \
- echo ""; \
- exit 1; \
- fi
-
-run-tests-corefx-%: prepare update-tests-corefx
- @echo ""
- @echo "***************** $* $${TEST_COUNTER}*********************"
- @cp corefx/restore/corefx-restore.deps.json corefx/tests/extracted/$*/$*.deps.json
- @cp corefx/restore/corefx-restore.runtimeconfig.dev.json corefx/tests/extracted/$*/$*.runtimeconfig.dev.json
- @cp corefx/restore/corefx-restore.dll corefx/tests/extracted/$*/corefx-restore.dll
- @sed -i -e 's/5.0.0\"/$(NETCOREAPP_VERSION)\"/g' corefx/tests/extracted/$*/*.runtimeconfig.json
- cd corefx/tests/extracted/$* && \
- MONO_ENV_OPTIONS="--debug $(XUNIT_MONO_ENV_OPTIONS)" COMPlus_DebugWriteToStdErr=1 $(CURDIR)/./dotnet exec \
- --runtimeconfig $*.runtimeconfig.json --additional-deps $*.deps.json \
- --fx-version "$(NETCOREAPP_VERSION)" xunit.console.dll $*.dll \
- -html ../../TestResult-$*.html -xml ../../TestResult-$*-netcore-xunit.xml \
- $(XUNIT_INNER_ARGS) @../../../../CoreFX.issues.rsp \
- $(XUNIT_ARGS)
-
-# build a test assembly in COREFX_ROOT (path to a fully built corefx repo) and copy it to corefx/tests/extracted
-# e.g. `make build-test-corefx-System.Runtime COREFX_ROOT=/prj/corefx-master`
-build-test-corefx-%:
- cd $(COREFX_ROOT)/src/$*/tests && $(DOTNET) msbuild /p:OutputPath=tmp
- cp $(COREFX_ROOT)/src/$*/tests/tmp/$*.Tests.{dll,pdb} $(CURDIR)/corefx/tests/extracted/$*.Tests/
- rm -rf $(COREFX_ROOT)/src/$*/tests/tmp
-
-xunit-summary:
- ./xunit-summary.py "corefx/tests"
-
-
-update-tests-coreclr: coreclr/.stamp-tests
-
-coreclr/.stamp-tests:
- rm -rf coreclr/tests
- curl -L "$(CORECLR_TESTS)" --output coreclr/tests.zip
- tar -xvf coreclr/tests.zip -C coreclr/
- mkdir coreclr/tests
- tar -xvf coreclr/Tests_OSX_x64_checked_outerloop/Tests_OSX_x64_checked_outerloop.tar.gz -C coreclr/tests
- touch $@
-
-.PHONY: corerun
-corerun:
- $(MAKE) -C corerun
- cp corerun/corerun $(SHAREDRUNTIME)
-
-run-tests-coreclr: prepare update-tests-coreclr corerun
- rm -rf coreclr/output.log
- @counter=0; \
- failures=0; \
- test_files=$$(find coreclr/tests -type f -name "*.sh"); \
- for testdir in $$test_files; do \
- counter=$$((counter+1)); \
- echo "Running $$testdir"; \
- if sh $$testdir -coreroot=$(realpath $(SHAREDRUNTIME)) >>coreclr/output.log 2>&1 ; then \
- echo "FAILED"; \
- failures=$$((failures+1)); \
- fi; \
- done; \
- echo "Tests Count: $$counter"; \
- echo "Failed: $$failures"
-endif
-
-run-tests-mono: prepare
- failures=0; \
- counter=0; \
- test_prj_dir=''; \
- test_prj_name=''; \
- test_projects=$$(find tests -type f -name "*.csproj"); \
- for test_prj in $$test_projects; do \
- counter=$$((counter+1)); \
- echo "Running $$test_prj_dir"; \
- test_prj_dir=$$(dirname $$test_prj); \
- test_prj_name=$$(basename $$test_prj); \
- test_prj_name=$${test_prj_name%.*}; \
- $(DOTNET) build -c Release $$test_prj; \
- MONO_ENV_OPTIONS="--debug $(MONO_ENV_OPTIONS)" COMPlus_DebugWriteToStdErr=1 ./dotnet --fx-version "$(NETCOREAPP_VERSION)" $$test_prj_dir/bin/netcoreapp3.0/$$test_prj_name.dll; \
- if [ $$? -ne 0 ]; then \
- failures=$$((failures+1)); \
- fi; \
- done; \
- echo "======================"; \
- echo "Tests Count: $$counter"; \
- echo "Failed: $$failures"
-
-run-tests-coreclr-%: prepare update-tests-coreclr
- @echo ""
- @echo "***************** $* *********************"
- @test_sh=$$(find . -type f -name "$*.sh" | head -n 1); \
- if [ ! -z "$$test_sh" ]; then \
- MONO_ENV_OPTIONS="--debug" COMPlus_DebugWriteToStdErr=1 sh $$test_sh -coreroot="$(realpath $(SHAREDRUNTIME))"; \
- else \
- echo "Test file $*.sh not found"; \
- fi
-
-# dump asm for all methods in BCL using LLVM AOT, e.g.:
-# make dump-asm-bcl DUMPASM_OUT=dumps/before-my-jit-fix
-dump-asm-bcl: patch-local-dotnet
- @if test -z "$(DUMPASM_OUT)"; then echo "DUMPASM_OUT is not set"; exit 1; fi
- mkdir -p $(DUMPASM_OUT)
- for assembly in ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME)/*.dll; do \
- printf "\n[AOT] $$(basename $$assembly):\n\n"; \
- $(MAKE) dump-asm-lib DUMPASM_LIB=$$assembly ; \
- done; \
- cd ../.dotnet/shared/Microsoft.NETCore.App/$(BOOTSTRAP_RUNTIME) && rm *.dll$(PLATFORM_AOT_SUFFIX)
-
-# dump asm for a specific assembly using LLVM AOT, e.g.:
-# make dump-asm-lib DUMPASM_OUT=dumps/before-my-jit-fix DUMPASM_LIB=/path/to/System.Private.CoreLib.dll
-dump-asm-lib: patch-local-dotnet
- @if test -z "$(DUMPASM_LIB)"; then echo "DUMPASM_LIB is not set"; exit 1; fi
- @if test -z "$(DUMPASM_OUT)"; then echo "DUMPASM_OUT is not set"; exit 1; fi
- mkdir -p $(DUMPASM_OUT)
- PATH="../llvm/usr/bin/:$(PATH)" \
- MONO_ENV_OPTIONS="--aot=llvm,mcpu=native" \
- $(DOTNET) $(DUMPASM_LIB)
- $(OBJDUMP) "$(DUMPASM_LIB)$(PLATFORM_AOT_SUFFIX)" > "$(DUMPASM_OUT)/$(notdir $(DUMPASM_LIB))$(PLATFORM_AOT_SUFFIX).dasm"
-
-# Generate asm diffs, a typical workflow may look like this:
-#
-# make dump-asm-bcl DUMPASM_OUT=dumps/before-my-jit-fix
-# (apply some runtime changes)
-# make runtime
-# make dump-asm-bcl DUMPASM_OUT=dumps/after-my-jit-fix
-# make jitdiff BEFORE=dumps/before-my-jit-fix AFTER=dumps/after-my-jit-fix
-#
-jitdiff:
- @if test -z "$(BEFORE)"; then echo "BEFORE is not set"; exit 1; fi
- @if test -z "$(AFTER)"; then echo "AFTER is not set"; exit 1; fi
- cd tools/jitdiff && $(DOTNET) run -c Release -- "$(BEFORE)" "$(AFTER)"
-
-distdir:
-distclean:
diff --git a/netcore/NuGet.config b/netcore/NuGet.config
deleted file mode 100644
index aae82481915..00000000000
--- a/netcore/NuGet.config
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
- <packageRestore>
- <add key="enabled" value="True" />
- </packageRestore>
- <config>
- <add key="repositoryPath" value="packages" />
- </config>
- <packageSources>
- <clear />
- <add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
- <add key="extensions" value="https://dotnetfeed.blob.core.windows.net/aspnet-extensions/index.json" />
- <add key="entityframeworkcore" value="https://dotnetfeed.blob.core.windows.net/aspnet-entityframeworkcore/index.json" />
- <add key="entityframework6" value="https://dotnetfeed.blob.core.windows.net/aspnet-entityframework6/index.json" />
- <add key="aspnetcore-tooling" value="https://dotnetfeed.blob.core.windows.net/aspnet-aspnetcore-tooling/index.json" />
- <add key="aspnetcore" value="https://dotnetfeed.blob.core.windows.net/aspnet-aspnetcore/index.json" />
- <add key="aspnet-blazor" value="https://dotnetfeed.blob.core.windows.net/aspnet-blazor/index.json" />
- <add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
- </packageSources>
- <disabledPackageSources>
- <clear />
- </disabledPackageSources>
- <activePackageSource>
- <add key="All" value="(Aggregate source)" />
- </activePackageSource>
-</configuration>
diff --git a/netcore/README.md b/netcore/README.md
deleted file mode 100644
index 98fe7dddf24..00000000000
--- a/netcore/README.md
+++ /dev/null
@@ -1,48 +0,0 @@
-# Introduction
-
-Netcore support in mono consists of two parts:
-* The runtime compiled in netcore mode
-* An implementation of System.Private.CoreLib
-
-# Building
-
-Everything below should be executed with the current dir set to 'netcore'.
-
-For bootstrap, do
- ./build.sh
-
-To rebuild the runtime, do
- make runtime
-
-To rebuild System.Private.CoreLib, do
- make bcl
-
-These two targets will copy the results into shared/Microsoft.NETCore.App/<version>.
-
-# Running with netcore
-
-## Running through the 'dotnet' tool.
-
-Run ```dotnet publish -c Release -r osx-x64``` to create a published version of the app.
-Copy
-```mono/mini/.libs/libmonosgen-2.0.dylib```
-into
-```bin/netcoreapp3.0/osx-x64/publish/libcoreclr.dylib```
-Copy
-```netcore/System.Private.CoreLib/bin/x86/System.Private.CoreLib.{dll,pdb}```
-to
-```bin/netcoreapp3.0/osx-x64/publish```
-
-## Running with the mono runtime executable
-
-DYLD_LIBRARY_PATH=shared/Microsoft.NETCore.App/<dotnet version> MONO_PATH=shared/Microsoft.NETCore.App/<dotnet version> ../mono/mini/mono-sgen --assembly-loader=strict sample/HelloWorld/bin/netcoreapp3.0/HelloWorld.dll
-
-## How to set up managed debugging
-
-Change the DebugType to full in your .csproj
- <DebugType>full</DebugType>
-Enable debugger agent using the environment variable MONO_ENV_OPTIONS
- export MONO_ENV_OPTIONS="--debug --debugger-agent=transport=dt_socket,address=127.0.0.1:1235,server=y,suspend=y"
-Run
- ./dotnet --fx-version "5.0.0-alpha1.19409.2" sample/HelloWorld/bin/netcoreapp3.0/HelloWorld.dll
-
diff --git a/netcore/System.Private.CoreLib/AssemblyInfo.cs b/netcore/System.Private.CoreLib/AssemblyInfo.cs
deleted file mode 100644
index 63c70c6f47a..00000000000
--- a/netcore/System.Private.CoreLib/AssemblyInfo.cs
+++ /dev/null
@@ -1,7 +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 System;
-
-[assembly: CLSCompliant (true)]
diff --git a/netcore/System.Private.CoreLib/Makefile b/netcore/System.Private.CoreLib/Makefile
deleted file mode 100644
index 4992c1bf907..00000000000
--- a/netcore/System.Private.CoreLib/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-dirs := $(dir $(wildcard */*))
-files := $(wildcard */*.cs)
-
-all-local:
- make -C .. bcl
-
-dist-local:
- mkdir -p $(distdir)
- cp -a Makefile $(distdir)
- cp -a *.csproj $(distdir)
- for i in $(dirs); do mkdir -p $(distdir)/$$i; done
- for i in $(files); do cp -a $$i $(distdir)/$$i; done
diff --git a/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj b/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj
deleted file mode 100644
index 3a4ce0022ed..00000000000
--- a/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj
+++ /dev/null
@@ -1,305 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <EnableDefaultItems>false</EnableDefaultItems>
- <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
- <GenerateResxSourceOmitGetResourceString>true</GenerateResxSourceOmitGetResourceString>
- <GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
- <EnsureRuntimePackageDependencies>false</EnsureRuntimePackageDependencies>
- <EnableSourceControlManagerQueries>false</EnableSourceControlManagerQueries>
-
- <OutputType>Library</OutputType>
- <TargetFramework>netcoreapp2.1</TargetFramework>
-
- <!-- Ensure a portable PDB is emitted for the project. A PDB is needed for crossgen. -->
- <DebugType>Portable</DebugType>
- <DebugSymbols>true</DebugSymbols>
-
- <Configurations>Debug;Release;Checked</Configurations>
- <Configuration>Release</Configuration>
- <Platforms>x64;x86;arm;arm64;wasm32</Platforms>
-
- <Features>strict;nullablePublicOnly</Features>
- </PropertyGroup>
-
- <PropertyGroup Condition="'$(TargetsUnix)'=='' AND '$(TargetsOSX)'=='' AND '$(TargetsWindows)'==''">
- <TargetsUnix>true</TargetsUnix>
- <TargetsOSX>true</TargetsOSX>
- <TargetsWindows>false</TargetsWindows>
- <BuildArch>x64</BuildArch>
- <OutputPath>bin/x64</OutputPath>
- </PropertyGroup>
-
- <!-- Compilation options -->
- <PropertyGroup>
- <Configuration Condition=" '$(BuildType)' != '' ">$(BuildType)</Configuration>
- <Platform Condition=" '$(BuildArch)' != '' ">$(BuildArch)</Platform>
- <Platform Condition=" '$(Platform)' == 'armel' ">arm</Platform>
- <ProjectGuid>{DD18B4BA-3B49-437B-9E34-41EF8A640CE0}</ProjectGuid>
-
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <!-- This prevents the default MsBuild targets from referencing System.Core.dll -->
- <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
- <!-- These prevent the default MsBuild targets from referencing System.dll and mscorlib.dll -->
- <ExcludeMscorlibFacade>true</ExcludeMscorlibFacade>
- <NoStdLib>true</NoStdLib>
- <NoCompilerStandardLib>true</NoCompilerStandardLib>
- <SubsystemVersion>6.00</SubsystemVersion>
- <Utf8Output>true</Utf8Output>
- <HighEntropyVA>true</HighEntropyVA>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
- <NoWarn>$(NoWarn),0419,0649,1573,1591,3021,CA2002</NoWarn>
- <Nullable>enable</Nullable>
-
- <!-- Ignore all previous constants since SPCL is sensitive to what is defined and the Sdk adds some by default -->
- <DefineConstants>$(DefineConstants);netcoreapp</DefineConstants>
- <DisableImplicitConfigurationDefines>true</DisableImplicitConfigurationDefines>
-
- <!-- We don't use any of MSBuild's resolution logic for resolving the framework, so just set these two properties to any folder that exists to skip
- the GenerateReferenceAssemblyPaths task (not target) and to prevent it from outputting a warning (MSB3644). -->
- <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory)/Documentation</_TargetFrameworkDirectories>
- <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)/Documentation</_FullFrameworkReferenceAssemblyPaths>
- <SkipCommonResourcesIncludes>true</SkipCommonResourcesIncludes>
- <DocumentationFile>$(OutputPath)$(MSBuildProjectName).xml</DocumentationFile>
- </PropertyGroup>
- <!-- Platform specific properties -->
- <PropertyGroup Condition="'$(Platform)' == 'x64'">
- <PlatformTarget>x64</PlatformTarget>
- <Prefer32Bit>false</Prefer32Bit>
- <DefineConstants>BIT64;AMD64;$(DefineConstants)</DefineConstants>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Platform)' == 'x86'">
- <PlatformTarget>x86</PlatformTarget>
- <DefineConstants>BIT32;$(DefineConstants)</DefineConstants>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Platform)' == 'arm'">
- <PlatformTarget>arm</PlatformTarget>
- <DefineConstants>BIT32;ARM;$(DefineConstants)</DefineConstants>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Platform)' == 'arm64'">
- <PlatformTarget>AnyCPU</PlatformTarget>
- <DefineConstants>BIT64;ARM64;$(DefineConstants)</DefineConstants>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Platform)' == 'wasm32'">
- <PlatformTarget>AnyCPU</PlatformTarget>
- <DefineConstants>BIT32;$(DefineConstants)</DefineConstants>
- </PropertyGroup>
- <!-- Configuration specific properties -->
- <PropertyGroup Condition="'$(Configuration)' == 'Debug' or '$(Configuration)' == 'Checked'">
- <Optimize Condition="'$(Optimize)' == '' and '$(Configuration)' == 'Debug'">false</Optimize>
- <Optimize Condition="'$(Optimize)' == '' and '$(Configuration)' == 'Checked'">true</Optimize>
- <DefineConstants>_LOGGING;DEBUG;$(DefineConstants)</DefineConstants>
- <DefineConstants Condition="'$(Platform)' == 'x86' or '$(Platform)' == 'x64'">CODE_ANALYSIS;$(DefineConstants)</DefineConstants>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)' == 'Release'">
- <Optimize Condition="'$(Optimize)' == ''">true</Optimize>
- </PropertyGroup>
- <PropertyGroup Condition="'$(TargetsOSX)' == 'true'">
- <DefineConstants>PLATFORM_OSX;$(DefineConstants)</DefineConstants>
- </PropertyGroup>
-
- <!-- Assembly attributes -->
- <PropertyGroup>
- <!-- SDK sets product to assembly but we want it to be our product name -->
- <Product>Microsoft%AE .NET Core</Product>
- <AssemblyName>System.Private.CoreLib</AssemblyName>
- <AssemblyVersion>5.0.0.0</AssemblyVersion>
- <ExcludeAssemblyInfoPartialFile>true</ExcludeAssemblyInfoPartialFile>
- <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
- <Description>$(AssemblyName)</Description>
- </PropertyGroup>
-
- <!-- Signing -->
- <PropertyGroup>
- <SignAssembly>true</SignAssembly>
- <StrongNameKeyId>SilverlightPlatform</StrongNameKeyId>
- </PropertyGroup>
-
- <!--
- Helper Paths
- -->
- <PropertyGroup>
- <CommonPath>$(MSBuildThisFileDirectory)Common</CommonPath>
- <BclSourcesRoot>$(MSBuildThisFileDirectory)src</BclSourcesRoot>
- <SharedBclSourcesRoot>$(MSBuildThisFileDirectory)shared</SharedBclSourcesRoot>
- </PropertyGroup>
-
- <!-- Mono specific build changes -->
- <PropertyGroup>
- <!-- Disable nullability-related warnings -->
- <NoWarn>$(NoWarn),CS8597,CS8600,CS8601,CS8602,CS8603,CS8604,CS8609,CS8611,CS8618,CS8620,CS8625,CS8631,CS8632,CS8634</NoWarn>
- <NoWarn>$(NoWarn),618,67</NoWarn>
-
- <DefineConstants>FEATURE_DEFAULT_INTERFACES;FEATURE_MANAGED_ETW_CHANNELS;$(DefineConstants)</DefineConstants>
- <DefineConstants>MONO;NETCORE;DISABLE_REMOTING;MONO_FEATURE_SRE;$(DefineConstants)</DefineConstants>
-
- <FeaturePortableTimer>true</FeaturePortableTimer>
- <FeaturePortableThreadPool>true</FeaturePortableThreadPool>
- <FeaturePerfTracing>true</FeaturePerfTracing>
-
- <RuntimeMetadataVersion>v4.0.30319</RuntimeMetadataVersion>
- </PropertyGroup>
-
- <!-- Sources -->
- <ItemGroup>
- <Compile Include="AssemblyInfo.cs" />
- <Compile Include="resources\SR.common.cs" />
- <Compile Include="resources\SR.cs" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="src\Microsoft\Win32\UnsafeNativeMethods.cs" />
- <Compile Include="src\Mono\MonoListItem.cs" />
- <Compile Include="src\Mono\MonoDomain.cs" />
- <Compile Include="src\Mono\MonoDomainSetup.cs" />
- <Compile Include="src\Mono\RuntimeHandles.cs" />
- <Compile Include="src\System\ArgIterator.cs" />
- <Compile Include="src\System\Array.Mono.cs" />
- <Compile Include="src\System\Attribute.Mono.cs" />
- <Compile Include="src\System\Buffer.Mono.cs" />
- <Compile Include="src\System\Delegate.Mono.cs" />
- <Compile Include="src\System\Enum.Mono.cs" />
- <Compile Include="src\System\Environment.Mono.cs" />
- <Compile Include="src\System\Exception.Mono.cs" />
- <Compile Include="src\System\GC.Mono.cs" />
- <Compile Include="src\System\Object.Mono.cs" />
- <Compile Include="src\System\Math.Mono.cs" />
- <Compile Include="src\System\MathF.Mono.cs" />
- <Compile Include="src\System\MissingMemberException.Mono.cs" />
- <Compile Include="src\System\ModuleHandle.cs" />
- <Compile Include="src\System\MulticastDelegate.cs" />
- <Compile Include="src\System\NotImplemented.cs" />
- <Compile Include="src\System\Nullable.Mono.cs" />
- <Compile Include="src\System\RuntimeArgumentHandle.cs" />
- <Compile Include="src\System\RuntimeFieldHandle.cs" />
- <Compile Include="src\System\RuntimeMethodHandle.cs" />
- <Compile Include="src\System\RuntimeType.Mono.cs" />
- <Compile Include="src\System\RuntimeTypeHandle.cs" />
- <Compile Include="src\System\String.Mono.cs" />
- <Compile Include="src\System\Type.Mono.cs" />
- <Compile Include="src\System\TypeIdentifier.cs" />
- <Compile Include="src\System\TypedReference.cs" />
- <Compile Include="src\System\TypeLoadException.Mono.cs" />
- <Compile Include="src\System\TypeNameParser.cs" />
- <Compile Include="src\System\ValueType.cs" />
- <Compile Include="src\System\WeakReference.Mono.cs" />
- <Compile Include="src\System\WeakReference.T.Mono.cs" />
- <Compile Include="src\System\__ComObject.cs" />
- <Compile Include="src\System\Globalization\GlobalizationMode.Mono.cs" />
- <Compile Include="src\System\Collections\Generic\ArraySortHelper.Mono.cs" />
- <Compile Include="src\System\Collections\Generic\Comparer.Mono.cs" />
- <Compile Include="src\System\Collections\Generic\EqualityComparer.Mono.cs" />
- <Compile Include="src\System\Diagnostics\Debugger.cs" />
- <Compile Include="src\System\Diagnostics\StackFrame.Mono.cs" />
- <Compile Include="src\System\Diagnostics\StackTrace.Mono.cs" />
- <Compile Include="src\System\IO\Stream.Mono.cs" />
- <Compile Include="src\System\IO\FileLoadException.Mono.cs" />
- <Compile Include="src\System\Reflection\Assembly.Mono.cs" />
- <Compile Include="src\System\Reflection\AssemblyName.Mono.cs" />
- <Compile Include="src\System\Reflection\CustomAttribute.cs" />
- <Compile Include="src\System\Reflection\CustomAttributeData.cs" />
- <Compile Include="src\System\Reflection\CustomAttributeTypedArgument.Mono.cs" />
- <Compile Include="src\System\Reflection\FieldInfo.Mono.cs" />
- <Compile Include="src\System\Reflection\MemberInfo.Mono.cs" />
- <Compile Include="src\System\Reflection\MethodBase.Mono.cs" />
- <Compile Include="src\System\Reflection\RuntimeAssembly.cs" />
- <Compile Include="src\System\Reflection\RuntimeEventInfo.cs" />
- <Compile Include="src\System\Reflection\RuntimeFieldInfo.cs" />
- <Compile Include="src\System\Reflection\RuntimeLocalVariableInfo.cs" />
- <Compile Include="src\System\Reflection\RuntimeMethodBody.cs" />
- <Compile Include="src\System\Reflection\RuntimeMethodInfo.cs" />
- <Compile Include="src\System\Reflection\RuntimeModule.cs" />
- <Compile Include="src\System\Reflection\RuntimeParameterInfo.cs" />
- <Compile Include="src\System\Reflection\RuntimePropertyInfo.cs" />
- <Compile Include="src\System\Reflection\RuntimeExceptionHandlingClause.cs" />
- <Compile Include="src\System\Reflection\Emit\AssemblyBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\ConstructorBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\ConstructorOnTypeBuilderInst.cs" />
- <Compile Include="src\System\Reflection\Emit\CustomAttributeBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\DerivedTypes.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\DynamicILInfo.cs" />
- <Compile Include="src\System\Reflection\Emit\DynamicMethod.cs" />
- <Compile Include="src\System\Reflection\Emit\DynamicMethod.notsupported.cs" />
- <Compile Include="src\System\Reflection\Emit\EnumBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\EventBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\EventOnTypeBuilderInst.cs" />
- <Compile Include="src\System\Reflection\Emit\FieldBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\FieldOnTypeBuilderInst.cs" />
- <Compile Include="src\System\Reflection\Emit\GenericTypeParameterBuilder.cs" />
- <Compile Include="src\System\Reflection\Emit\ILGenerator.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\LocalBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\MethodBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\MethodOnTypeBuilderInst.cs" />
- <Compile Include="src\System\Reflection\Emit\ModuleBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\MonoArrayMethod.cs" />
- <Compile Include="src\System\Reflection\Emit\ParameterBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\PropertyBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\PropertyOnTypeBuilderInst.cs" />
- <Compile Include="src\System\Reflection\Emit\SignatureHelper.cs" />
- <Compile Include="src\System\Reflection\Emit\TypeBuilder.Mono.cs" />
- <Compile Include="src\System\Reflection\Emit\TypeBuilderInstantiation.cs" />
- <Compile Include="src\System\Reflection\Emit\UnmanagedMarshal.cs" />
- <Compile Include="src\System\Reflection\Metadata\AssemblyExtensions.cs" />
- <Compile Include="src\System\Resources\ManifestBasedResourceGroveler.Mono.cs" />
- <Compile Include="src\System\Runtime\GCSettings.Mono.cs" />
- <Compile Include="src\System\Runtime\CompilerServices\DependentHandle.cs" />
- <Compile Include="src\System\Runtime\CompilerServices\JitHelpers.cs" />
- <Compile Include="src\System\Runtime\CompilerServices\RuntimeHelpers.Mono.cs" />
- <Compile Include="src\System\Runtime\CompilerServices\RuntimeFeature.Mono.cs" />
- <Compile Include="src\System\Runtime\InteropServices\CriticalHandle.Mono.cs" />
- <Compile Include="src\System\Runtime\InteropServices\GCHandle.Mono.cs" />
- <Compile Include="src\System\Runtime\InteropServices\Marshal.Mono.cs" />
- <Compile Include="src\System\Runtime\InteropServices\MarshalAsAttribute.Mono.cs" />
- <Compile Include="src\System\Runtime\InteropServices\NativeLibrary.Mono.cs" />
- <Compile Include="src\System\Runtime\InteropServices\SafeHandle.Mono.cs" />
- <Compile Include="src\System\Runtime\Loader\AssemblyLoadContext.Mono.cs" />
- <Compile Include="src\System\Runtime\Loader\AssemblyDependencyResolver.cs" />
- <Compile Include="src\System\Runtime\Remoting\Contexts\Context.cs" />
- <Compile Include="src\System\Security\DynamicSecurityMethodAttribute.cs" />
- <Compile Include="src\System\Threading\Interlocked.cs" />
- <Compile Include="src\System\Threading\Monitor.cs" />
- <Compile Include="src\System\Threading\Overlapped.cs" />
- <Compile Include="src\System\Threading\PreAllocatedOverlapped.cs" />
- <Compile Include="src\System\Threading\StackCrawlMark.cs" />
- <Compile Include="src\System\Threading\Thread.Mono.cs" />
- <Compile Include="src\System\Threading\ThreadPool.Mono.cs" />
- <Compile Include="src\System\Threading\LowLevelLock.cs" />
- <Compile Include="src\System\Threading\LowLevelSpinWaiter.cs" />
- <Compile Include="src\System\Threading\WaitHandle.Mono.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetsUnix)' == 'true'">
- <Compile Include="src\Microsoft\Win32\SafeHandles\SafeWaitHandle.Unix.Mono.cs" />
- <Compile Include="src\System\Environment.Unix.Mono.cs" />
- <Compile Include="src\System\Globalization\GlobalizationMode.Unix.Mono.cs" />
- <Compile Include="src\System\Threading\EventWaitHandle.Unix.Mono.cs" />
- <Compile Include="src\System\Threading\Mutex.Unix.Mono.cs" />
- <Compile Include="src\System\Threading\Semaphore.Unix.Mono.cs" />
- <Compile Include="src\System\Threading\LowLevelLifoSemaphore.Unix.Mono.cs" />
-
- <Compile Include="src\System\IO\MonoIOError.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetsWindows)' == 'true'">
- <Compile Include="src\System\Globalization\GlobalizationMode.Windows.Mono.cs" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="src\Mono\RuntimeStructs.cs" />
- <Compile Include="src\Mono\RuntimeMarshal.cs" />
- <Compile Include="src\Mono\SafeStringMarshal.cs" />
- <Compile Include="src\Mono\SafeGPtrArrayHandle.cs" />
-
- <Compile Include="src\System\TypeSpec.cs" />
-
- <Compile Include="src\System\Runtime\CompilerServices\PreserveDependencyAttribute.cs" />
- </ItemGroup>
-
- <Import Project="shared\System.Private.CoreLib.Shared.projitems" />
-
- <!-- Use Roslyn Compilers to build -->
- <Import Project="../roslyn/packages/microsoft.net.compilers.toolset/$(MicrosoftNetCompilersVersion)/build/Microsoft.Net.Compilers.Toolset.props" />
-
- <ItemGroup>
- <EmbeddedResource LogicalName="System.Private.CoreLib.xml" Include="src\LinkerDescriptor\System.Private.CoreLib.xml"/>
- </ItemGroup>
-</Project>
-
diff --git a/netcore/System.Private.CoreLib/resources/SR.common.cs b/netcore/System.Private.CoreLib/resources/SR.common.cs
deleted file mode 100644
index a05c8f71414..00000000000
--- a/netcore/System.Private.CoreLib/resources/SR.common.cs
+++ /dev/null
@@ -1,38 +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 System.Globalization;
-
-static partial class SR
-{
- internal static string Format (string resourceFormat, object? p1)
- {
- return string.Format (CultureInfo.InvariantCulture, resourceFormat, p1);
- }
-
- internal static string Format (string resourceFormat, object p1, object p2)
- {
- return string.Format (CultureInfo.InvariantCulture, resourceFormat, p1, p2);
- }
-
- internal static string Format (CultureInfo ci, string resourceFormat, object p1, object p2)
- {
- return string.Format (ci, resourceFormat, p1, p2);
- }
-
- internal static string Format (string resourceFormat, object p1, object p2, object p3)
- {
- return string.Format (CultureInfo.InvariantCulture, resourceFormat, p1, p2, p3);
- }
-
- internal static string Format (string resourceFormat, params object[] args)
- {
- if (args != null)
- return string.Format (CultureInfo.InvariantCulture, resourceFormat, args);
-
- return resourceFormat;
- }
-
- internal static string GetResourceString (string str) => str;
-} \ No newline at end of file
diff --git a/netcore/System.Private.CoreLib/resources/SR.cs b/netcore/System.Private.CoreLib/resources/SR.cs
deleted file mode 100644
index 29f3c0e084f..00000000000
--- a/netcore/System.Private.CoreLib/resources/SR.cs
+++ /dev/null
@@ -1,1225 +0,0 @@
-//
-// This file was generated by resx2sr tool
-//
-
-partial class SR
-{
- public const string Acc_CreateAbst = "Cannot create an abstract class.";
- public const string Acc_CreateAbstEx = "Cannot create an instance of {0} because it is an abstract class.";
- public const string Acc_CreateArgIterator = "Cannot dynamically create an instance of ArgIterator.";
- public const string Acc_CreateGeneric = "Cannot create a type for which Type.ContainsGenericParameters is true.";
- public const string Acc_CreateGenericEx = "Cannot create an instance of {0} because Type.ContainsGenericParameters is true.";
- public const string Acc_CreateInterface = "Cannot create an instance of an interface.";
- public const string Acc_CreateInterfaceEx = "Cannot create an instance of {0} because it is an interface.";
- public const string Acc_CreateVoid = "Cannot dynamically create an instance of System.Void.";
- public const string Acc_NotClassInit = "Type initializer was not callable.";
- public const string Acc_ReadOnly = "Cannot set a constant field.";
- public const string Access_Void = "Cannot create an instance of void.";
- public const string AggregateException_ctor_DefaultMessage = "One or more errors occurred.";
- public const string AggregateException_ctor_InnerExceptionNull = "An element of innerExceptions was null.";
- public const string AggregateException_DeserializationFailure = "The serialization stream contains no inner exceptions.";
- public const string AggregateException_InnerException = "(Inner Exception #{0}) "; // {entry.Item3}
- public const string AppDomain_AppBaseNotSet = "The ApplicationBase must be set before retrieving this property.";
- public const string AppDomain_Name = "Name:";
- public const string AppDomain_NoContextPolicies = "There are no context policies.";
- public const string AppDomain_Policy_PrincipalTwice = "Default principal object cannot be set twice.";
- public const string AmbiguousImplementationException_NullMessage = "Ambiguous implementation found.";
- public const string Arg_AccessException = "Cannot access member.";
- public const string Arg_AccessViolationException = "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.";
- public const string Arg_AmbiguousMatchException = "Ambiguous match found.";
- public const string Arg_ApplicationException = "Error in the application.";
- public const string Arg_ArgumentException = "Value does not fall within the expected range.";
- public const string Arg_ArgumentOutOfRangeException = "Specified argument was out of the range of valid values.";
- public const string Arg_ArithmeticException = "Overflow or underflow in the arithmetic operation.";
- public const string Arg_ArrayLengthsDiffer = "Array lengths must be the same.";
- public const string Arg_ArrayPlusOffTooSmall = "Destination array is not long enough to copy all the items in the collection. Check array index and length.";
- public const string Arg_ArrayTypeMismatchException = "Attempted to access an element as a type incompatible with the array.";
- public const string Arg_ArrayZeroError = "Array must not be of length zero.";
- public const string Arg_BadDecimal = "Read an invalid decimal value from the buffer.";
- public const string Arg_BadImageFormatException = "Format of the executable (.exe) or library (.dll) is invalid.";
- public const string Arg_BadLiteralFormat = "Encountered an invalid type for a default value.";
- public const string Arg_BogusIComparer = "Unable to sort because the IComparer.Compare() method returns inconsistent results. Either a value does not compare equal to itself, or one value repeatedly compared to another value yields different results. IComparer: '{0}'.";
- public const string Arg_BufferTooSmall = "Not enough space available in the buffer.";
- public const string Arg_CannotBeNaN = "TimeSpan does not accept floating point Not-a-Number values.";
- public const string Arg_CannotHaveNegativeValue = "String cannot contain a minus sign if the base is not 10.";
- public const string Arg_CannotMixComparisonInfrastructure = "The usage of IKeyComparer and IHashCodeProvider/IComparer interfaces cannot be mixed; use one or the other.";
- public const string Arg_CannotUnloadAppDomainException = "Attempt to unload the AppDomain failed.";
- public const string Arg_CATypeResolutionFailed = "Failed to resolve type from string \"{0}\" which was embedded in custom attribute blob.";
- public const string Arg_COMAccess = "Must specify property Set or Get or method call for a COM Object.";
- public const string Arg_COMException = "Error HRESULT E_FAIL has been returned from a call to a COM component.";
- public const string Arg_COMPropSetPut = "Only one of the following binding flags can be set: BindingFlags.SetProperty, BindingFlags.PutDispProperty, BindingFlags.PutRefDispProperty.";
- public const string Arg_CreatInstAccess = "Cannot specify both CreateInstance and another access type.";
- public const string Arg_CryptographyException = "Error occurred during a cryptographic operation.";
- public const string Arg_CustomAttributeFormatException = "Binary format of the specified custom attribute was invalid.";
- public const string Arg_DataMisalignedException = "A datatype misalignment was detected in a load or store instruction.";
- public const string Arg_DateTimeRange = "Combination of arguments to the DateTime constructor is out of the legal range.";
- public const string Arg_DecBitCtor = "Decimal byte array constructor requires an array of length four containing valid decimal bytes.";
- public const string Arg_DirectoryNotFoundException = "Attempted to access a path that is not on the disk.";
- public const string Arg_DivideByZero = "Attempted to divide by zero.";
- public const string Arg_DlgtNullInst = "Delegate to an instance method cannot have null 'this'.";
- public const string Arg_DlgtTargMeth = "Cannot bind to the target method because its signature is not compatible with that of the delegate type.";
- public const string Arg_DlgtTypeMis = "Delegates must be of the same type.";
- public const string Arg_DllNotFoundException = "Dll was not found.";
- public const string Arg_DriveNotFoundException = "Attempted to access a drive that is not available.";
- public const string Arg_DuplicateWaitObjectException = "Duplicate objects in argument.";
- public const string Arg_EHClauseNotClause = "This ExceptionHandlingClause is not a clause.";
- public const string Arg_EHClauseNotFilter = "This ExceptionHandlingClause is not a filter.";
- public const string Arg_EmptyArray = "Array may not be empty.";
- public const string Arg_EmptyOrNullString = "String may not be empty or null.";
- public const string Arg_EndOfStreamException = "Attempted to read past the end of the stream.";
- public const string Arg_EntryPointNotFoundException = "Entry point was not found.";
- public const string Arg_EnumAndObjectMustBeSameType = "Object must be the same type as the enum. The type passed in was '{0}'; the enum type was '{1}'.";
- public const string Arg_EnumFormatUnderlyingTypeAndObjectMustBeSameType = "Enum underlying type and the object must be same type or object. Type passed in was '{0}'; the enum underlying type was '{1}'.";
- public const string Arg_EnumIllegalVal = "Illegal enum value: {0}.";
- public const string Arg_EnumLitValueNotFound = "Literal value was not found.";
- public const string Arg_EnumUnderlyingTypeAndObjectMustBeSameType = "Enum underlying type and the object must be same type or object must be a String. Type passed in was '{0}'; the enum underlying type was '{1}'.";
- public const string Arg_EnumValueNotFound = "Requested value '{0}' was not found.";
- public const string Arg_ExecutionEngineException = "Internal error in the runtime.";
- public const string Arg_ExternalException = "External component has thrown an exception.";
- public const string Arg_FieldAccessException = "Attempted to access a field that is not accessible by the caller.";
- public const string Arg_FieldDeclTarget = "Field '{0}' defined on type '{1}' is not a field on the target object which is of type '{2}'.";
- public const string Arg_FldGetArgErr = "No arguments can be provided to Get a field value.";
- public const string Arg_FldGetPropSet = "Cannot specify both GetField and SetProperty.";
- public const string Arg_FldSetArgErr = "Only the field value can be specified to set a field value.";
- public const string Arg_FldSetGet = "Cannot specify both Get and Set on a field.";
- public const string Arg_FldSetInvoke = "Cannot specify Set on a Field and Invoke on a method.";
- public const string Arg_FldSetPropGet = "Cannot specify both SetField and GetProperty.";
- public const string Arg_FormatException = "One of the identified items was in an invalid format.";
- public const string Arg_GenericParameter = "Method must be called on a Type for which Type.IsGenericParameter is false.";
- public const string Arg_GetMethNotFnd = "Property Get method was not found.";
- public const string Arg_GuidArrayCtor = "Byte array for GUID must be exactly {0} bytes long.";
- public const string Arg_HandleNotAsync = "Handle does not support asynchronous operations. The parameters to the FileStream constructor may need to be changed to indicate that the handle was opened synchronously (that is, it was not opened for overlapped I/O).";
- public const string Arg_HandleNotSync = "Handle does not support synchronous operations. The parameters to the FileStream constructor may need to be changed to indicate that the handle was opened asynchronously (that is, it was opened explicitly for overlapped I/O).";
- public const string Arg_HexStyleNotSupported = "The number style AllowHexSpecifier is not supported on floating point data types.";
- public const string Arg_HTCapacityOverflow = "Hashtable's capacity overflowed and went negative. Check load factor, capacity and the current size of the table.";
- public const string Arg_IndexMustBeInt = "All indexes must be of type Int32.";
- public const string Arg_IndexOutOfRangeException = "Index was outside the bounds of the array.";
- public const string Arg_InsufficientExecutionStackException = "Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space.";
- public const string Arg_InvalidANSIString = "The ANSI string passed in could not be converted from the default ANSI code page to Unicode.";
- public const string Arg_InvalidBase = "Invalid Base.";
- public const string Arg_InvalidCastException = "Specified cast is not valid.";
- public const string Arg_InvalidComObjectException = "Attempt has been made to use a COM object that does not have a backing class factory.";
- public const string Arg_InvalidFilterCriteriaException = "Specified filter criteria was invalid.";
- public const string Arg_InvalidHandle = "Invalid handle.";
- public const string Arg_InvalidHexStyle = "With the AllowHexSpecifier bit set in the enum bit field, the only other valid bits that can be combined into the enum value must be a subset of those in HexNumber.";
- public const string Arg_InvalidNeutralResourcesLanguage_Asm_Culture = "The NeutralResourcesLanguageAttribute on the assembly \"{0}\" specifies an invalid culture name: \"{1}\".";
- public const string Arg_InvalidNeutralResourcesLanguage_FallbackLoc = "The NeutralResourcesLanguageAttribute specifies an invalid or unrecognized ultimate resource fallback location: \"{0}\".";
- public const string Arg_InvalidSatelliteContract_Asm_Ver = "Satellite contract version attribute on the assembly '{0}' specifies an invalid version: {1}.";
- public const string Arg_InvalidOleVariantTypeException = "Specified OLE variant was invalid.";
- public const string Arg_InvalidOperationException = "Operation is not valid due to the current state of the object.";
- public const string Arg_InvalidSearchPattern = "Search pattern '{0}' cannot contain \"..\" to move up directories and can be contained only internally in file/directory names, as in \"a..b\".";
- public const string Arg_InvalidTypeInRetType = "The return Type must be a type provided by the runtime.";
- public const string Arg_InvalidTypeInSignature = "The signature Type array contains some invalid type (i.e. null, void)";
- public const string Arg_InvalidUTF8String = "The UTF8 string passed in could not be converted to Unicode.";
- public const string Arg_IOException = "I/O error occurred.";
- public const string Arg_KeyNotFound = "The given key was not present in the dictionary.";
- public const string Arg_KeyNotFoundWithKey = "The given key '{0}' was not present in the dictionary.";
- public const string Arg_LongerThanDestArray = "Destination array was not long enough. Check the destination index, length, and the array's lower bounds.";
- public const string Arg_LongerThanSrcArray = "Source array was not long enough. Check the source index, length, and the array's lower bounds.";
- public const string Arg_LongerThanSrcString = "Source string was not long enough. Check sourceIndex and count.";
- public const string Arg_LowerBoundsMustMatch = "The arrays' lower bounds must be identical.";
- public const string Arg_MarshalAsAnyRestriction = "AsAny cannot be used on return types, ByRef parameters, ArrayWithOffset, or parameters passed from unmanaged to managed.";
- public const string Arg_MarshalDirectiveException = "Marshaling directives are invalid.";
- public const string Arg_MethodAccessException = "Attempt to access the method failed.";
- public const string Arg_MethodAccessException_WithMethodName = "Attempt to access the method \"{0}\" on type \"{1}\" failed.";
- public const string Arg_MissingFieldException = "Attempted to access a non-existing field.";
- public const string Arg_MissingManifestResourceException = "Unable to find manifest resource.";
- public const string Arg_MissingMemberException = "Attempted to access a missing member.";
- public const string Arg_MissingMethodException = "Attempted to access a missing method.";
- public const string Arg_MulticastNotSupportedException = "Attempted to add multiple callbacks to a delegate that does not support multicast.";
- public const string Arg_MustBeBoolean = "Object must be of type Boolean.";
- public const string Arg_MustBeByte = "Object must be of type Byte.";
- public const string Arg_MustBeChar = "Object must be of type Char.";
- public const string Arg_MustBeDateTime = "Object must be of type DateTime.";
- public const string Arg_MustBeDateTimeOffset = "Object must be of type DateTimeOffset.";
- public const string Arg_MustBeDecimal = "Object must be of type Decimal.";
- public const string Arg_MustBeDelegate = "Type must derive from Delegate.";
- public const string Arg_MustBeDouble = "Object must be of type Double.";
- public const string Arg_MustBeDriveLetterOrRootDir = "Drive name must be a root directory (i.e. 'C:\\') or a drive letter ('C').";
- public const string Arg_MustBeEnum = "Type provided must be an Enum.";
- public const string Arg_MustBeEnumBaseTypeOrEnum = "The value passed in must be an enum base or an underlying type for an enum, such as an Int32.";
- public const string Arg_MustBeGuid = "Object must be of type GUID.";
- public const string Arg_MustBeInt16 = "Object must be of type Int16.";
- public const string Arg_MustBeInt32 = "Object must be of type Int32.";
- public const string Arg_MustBeInt64 = "Object must be of type Int64.";
- public const string Arg_MustBeInterface = "Type passed must be an interface.";
- public const string Arg_MustBePointer = "Type must be a Pointer.";
- public const string Arg_MustBePrimArray = "Object must be an array of primitives.";
- public const string Arg_MustBeSByte = "Object must be of type SByte.";
- public const string Arg_MustBeSingle = "Object must be of type Single.";
- public const string Arg_MustBeStatic = "Method must be a static method.";
- public const string Arg_MustBeString = "Object must be of type String.";
- public const string Arg_MustBeTimeSpan = "Object must be of type TimeSpan.";
- public const string Arg_MustBeType = "Type must be a type provided by the runtime.";
- public const string Arg_MustBeTrue = "Argument must be true.";
- public const string Arg_MustBeUInt16 = "Object must be of type UInt16.";
- public const string Arg_MustBeUInt32 = "Object must be of type UInt32.";
- public const string Arg_MustBeUInt64 = "Object must be of type UInt64.";
- public const string Arg_MustBeVersion = "Object must be of type Version.";
- public const string Arg_MustContainEnumInfo = "Must specify valid information for parsing in the string.";
- public const string Arg_NamedParamNull = "Named parameter value must not be null.";
- public const string Arg_NamedParamTooBig = "Named parameter array cannot be bigger than argument array.";
- public const string Arg_NDirectBadObject = "No PInvoke conversion exists for value passed to Object-typed parameter.";
- public const string Arg_Need1DArray = "Array was not a one-dimensional array.";
- public const string Arg_Need2DArray = "Array was not a two-dimensional array.";
- public const string Arg_Need3DArray = "Array was not a three-dimensional array.";
- public const string Arg_NeedAtLeast1Rank = "Must provide at least one rank.";
- public const string Arg_NegativeArgCount = "Argument count must not be negative.";
- public const string Arg_NoAccessSpec = "Must specify binding flags describing the invoke operation required (BindingFlags.InvokeMethod CreateInstance GetField SetField GetProperty SetProperty).";
- public const string Arg_NoDefCTor = "No parameterless constructor defined for type '{0}'.";
- public const string Arg_NoITypeInfo = "Specified TypeInfo was invalid because it did not support the ITypeInfo interface.";
- public const string Arg_NoITypeLib = "Specified TypeLib was invalid because it did not support the ITypeLib interface.";
- public const string Arg_NonZeroLowerBound = "The lower bound of target array must be zero.";
- public const string Arg_NoStaticVirtual = "Method cannot be both static and virtual.";
- public const string Arg_NotFiniteNumberException = "Number encountered was not a finite quantity.";
- public const string Arg_NotFoundIFace = "Interface not found.";
- public const string Arg_NotGenericMethodDefinition = "{0} is not a GenericMethodDefinition. MakeGenericMethod may only be called on a method for which MethodBase.IsGenericMethodDefinition is true.";
- public const string Arg_NotGenericParameter = "Method may only be called on a Type for which Type.IsGenericParameter is true.";
- public const string Arg_NotGenericTypeDefinition = "{0} is not a GenericTypeDefinition. MakeGenericType may only be called on a type for which Type.IsGenericTypeDefinition is true.";
- public const string Arg_NotImplementedException = "The method or operation is not implemented.";
- public const string Arg_NotSupportedException = "Specified method is not supported.";
- public const string Arg_NullIndex = "Arrays indexes must be set to an object instance.";
- public const string Arg_NullReferenceException = "Object reference not set to an instance of an object.";
- public const string Arg_ObjObj = "Object type cannot be converted to target type.";
- public const string Arg_ObjObjEx = "Object of type '{0}' cannot be converted to type '{1}'.";
- public const string Arg_OleAutDateInvalid = "Not a legal OleAut date.";
- public const string Arg_OleAutDateScale = "OleAut date did not convert to a DateTime correctly.";
- public const string Arg_OverflowException = "Arithmetic operation resulted in an overflow.";
- public const string Arg_OutOfMemoryException = "Insufficient memory to continue the execution of the program.";
- public const string Arg_ParamName_Name = "Parameter name: {0}";
- public const string Arg_ParmArraySize = "Must specify one or more parameters.";
- public const string Arg_ParmCnt = "Parameter count mismatch.";
- public const string Arg_PathEmpty = "The path is empty.";
- public const string Arg_PathIllegalUNC_Path = "The UNC path '{0}' should be of the form \\\\\\\\server\\\\share.";
- public const string Arg_PlatformNotSupported = "Operation is not supported on this platform.";
- public const string Arg_PrimWiden = "Cannot widen from source type to target type either because the source type is a not a primitive type or the conversion cannot be accomplished.";
- public const string Arg_PropSetGet = "Cannot specify both Get and Set on a property.";
- public const string Arg_PropSetInvoke = "Cannot specify Set on a property and Invoke on a method.";
- public const string Arg_RankException = "Attempted to operate on an array with the incorrect number of dimensions.";
- public const string Arg_RankIndices = "Indices length does not match the array rank.";
- public const string Arg_RankMultiDimNotSupported = "Only single dimensional arrays are supported for the requested action.";
- public const string Arg_RanksAndBounds = "Number of lengths and lowerBounds must match.";
- public const string Arg_RegGetOverflowBug = "RegistryKey.GetValue does not allow a String that has a length greater than Int32.MaxValue.";
- public const string Arg_RegKeyNotFound = "The specified registry key does not exist.";
- public const string Arg_RegSubKeyValueAbsent = "No value exists with that name.";
- public const string Arg_RegValStrLenBug = "Registry value names should not be greater than 16,383 characters.";
- public const string Arg_ResMgrNotResSet = "Type parameter must refer to a subclass of ResourceSet.";
- public const string Arg_ResourceFileUnsupportedVersion = "The ResourceReader class does not know how to read this version of .resources files. Expected version: {0} This file: {1}";
- public const string Arg_ResourceNameNotExist = "The specified resource name \"{0}\" does not exist in the resource file.";
- public const string Arg_SafeArrayRankMismatchException = "Specified array was not of the expected rank.";
- public const string Arg_SafeArrayTypeMismatchException = "Specified array was not of the expected type.";
- public const string Arg_SecurityException = "Security error.";
- public const string SerializationException = "Serialization error.";
- public const string Arg_SetMethNotFnd = "Property set method not found.";
- public const string Arg_StackOverflowException = "Operation caused a stack overflow.";
- public const string Arg_SurrogatesNotAllowedAsSingleChar = "Unicode surrogate characters must be written out as pairs together in the same call, not individually. Consider passing in a character array instead.";
- public const string Arg_SynchronizationLockException = "Object synchronization method was called from an unsynchronized block of code.";
- public const string Arg_SystemException = "System error.";
- public const string Arg_TargetInvocationException = "Exception has been thrown by the target of an invocation.";
- public const string Arg_TargetParameterCountException = "Number of parameters specified does not match the expected number.";
- public const string Arg_ThreadStartException = "Thread failed to start.";
- public const string Arg_ThreadStateException = "Thread was in an invalid state for the operation being executed.";
- public const string Arg_TimeoutException = "The operation has timed out.";
- public const string Arg_TypeAccessException = "Attempt to access the type failed.";
- public const string Arg_TypedReference_Null = "The TypedReference must be initialized.";
- public const string Arg_TypeLoadException = "Failure has occurred while loading a type.";
- public const string Arg_TypeLoadNullStr = "A null or zero length string does not represent a valid Type.";
- public const string Arg_TypeRefPrimitve = "TypedReferences cannot be redefined as primitives. Field name '{0}'.";
- public const string Arg_TypeUnloadedException = "Type had been unloaded.";
- public const string Arg_UnauthorizedAccessException = "Attempted to perform an unauthorized operation.";
- public const string Arg_UnboundGenField = "Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true.";
- public const string Arg_UnboundGenParam = "Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.";
- public const string Arg_UnknownTypeCode = "Unknown TypeCode value.";
- public const string Arg_VarMissNull = "Missing parameter does not have a default value.";
- public const string Arg_VersionString = "Version string portion was too short or too long.";
- public const string Arg_WrongAsyncResult = "IAsyncResult object did not come from the corresponding async method on this type.";
- public const string Arg_WrongType = "The value \"{0}\" is not of type \"{1}\" and cannot be used in this generic collection.";
- public const string Argument_AbsolutePathRequired = "Absolute path information is required.";
- public const string Argument_AddingDuplicate = "An item with the same key has already been added.";
- public const string Argument_AddingDuplicate__ = "Item has already been added. Key in dictionary: '{0}' Key being added: '{1}'";
- public const string Argument_AddingDuplicateWithKey = "An item with the same key has already been added. Key: {0}";
- public const string Argument_AdjustmentRulesNoNulls = "The AdjustmentRule array cannot contain null elements.";
- public const string Argument_AdjustmentRulesOutOfOrder = "The elements of the AdjustmentRule array must be in chronological order and must not overlap.";
- public const string Argument_AlreadyACCW = "The object already has a CCW associated with it.";
- public const string Argument_AlreadyBoundOrSyncHandle = "'handle' has already been bound to the thread pool, or was not opened for asynchronous I/O.";
- public const string Argument_ArgumentZero = "Argument cannot be zero.";
- public const string Argument_ArrayGetInterfaceMap = "Interface maps for generic interfaces on arrays cannot be retrieved.";
- public const string Argument_ArraysInvalid = "Array or pointer types are not valid.";
- public const string Argument_AttributeNamesMustBeUnique = "Attribute names must be unique.";
- public const string Argument_BadAttributeOnInterfaceMethod = "Interface method must be abstract and virtual.";
- public const string Argument_BadConstantValue = "Bad default value.";
- public const string Argument_BadConstructor = "Cannot have private or static constructor.";
- public const string Argument_BadConstructorCallConv = "Constructor must have standard calling convention.";
- public const string Argument_BadExceptionCodeGen = "Incorrect code generation for exception block.";
- public const string Argument_BadFieldForConstructorBuilder = "Field must be on the same type of the given ConstructorInfo.";
- public const string Argument_BadFieldSig = "Field signatures do not have return types.";
- public const string Argument_BadFieldType = "Bad field type in defining field.";
- public const string Argument_BadFormatSpecifier = "Format specifier was invalid.";
- public const string Argument_BadImageFormatExceptionResolve = "A BadImageFormatException has been thrown while parsing the signature. This is likely due to lack of a generic context. Ensure genericTypeArguments and genericMethodArguments are provided and contain enough context.";
- public const string Argument_BadLabel = "Bad label in ILGenerator.";
- public const string Argument_BadLabelContent = "Bad label content in ILGenerator.";
- public const string Argument_BadNestedTypeFlags = "Visibility of interfaces must be one of the following: NestedAssembly, NestedFamANDAssem, NestedFamily, NestedFamORAssem, NestedPrivate or NestedPublic.";
- public const string Argument_BadObjRef = "Invalid ObjRef provided to '{0}'.";
- public const string Argument_BadParameterCountsForConstructor = "Parameter count does not match passed in argument value count.";
- public const string Argument_BadParameterTypeForCAB = "Cannot emit a CustomAttribute with argument of type {0}.";
- public const string Argument_BadPropertyForConstructorBuilder = "Property must be on the same type of the given ConstructorInfo.";
- public const string Argument_BadSigFormat = "Incorrect signature format.";
- public const string Argument_BadSizeForData = "Data size must be > 1 and < 0x3f0000";
- public const string Argument_BadTypeAttrInvalidLayout = "Bad type attributes. Invalid layout attribute specified.";
- public const string Argument_BadTypeAttrNestedVisibilityOnNonNestedType = "Bad type attributes. Nested visibility flag set on a non-nested type.";
- public const string Argument_BadTypeAttrNonNestedVisibilityNestedType = "Bad type attributes. Non-nested visibility flag set on a nested type.";
- public const string Argument_BadTypeAttrReservedBitsSet = "Bad type attributes. Reserved bits set on the type.";
- public const string Argument_BadTypeInCustomAttribute = "An invalid type was used as a custom attribute constructor argument, field or property.";
- public const string Argument_CannotCreateTypedReference = "Cannot use function evaluation to create a TypedReference object.";
- public const string Argument_CannotGetTypeTokenForByRef = "Cannot get TypeToken for a ByRef type.";
- public const string Argument_CannotSetParentToInterface = "Cannot set parent to an interface.";
- public const string Argument_CodepageNotSupported = "{0} is not a supported code page.";
- public const string Argument_CompareOptionOrdinal = "CompareOption.Ordinal cannot be used with other options.";
- public const string Argument_ConflictingDateTimeRoundtripStyles = "The DateTimeStyles value RoundtripKind cannot be used with the values AssumeLocal, AssumeUniversal or AdjustToUniversal.";
- public const string Argument_ConflictingDateTimeStyles = "The DateTimeStyles values AssumeLocal and AssumeUniversal cannot be used together.";
- public const string Argument_ConstantDoesntMatch = "Constant does not match the defined type.";
- public const string Argument_ConstantNotSupported = "{0} is not a supported constant type.";
- public const string Argument_ConstantNull = "Null is not a valid constant value for this type.";
- public const string Argument_ConstructorNeedGenericDeclaringType = "The specified constructor must be declared on a generic type definition.";
- public const string Argument_ConversionOverflow = "Conversion buffer overflow.";
- public const string Argument_ConvertMismatch = "The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local.";
- public const string Argument_CORDBBadMethod = "Cannot find the method on the object instance.";
- public const string Argument_CORDBBadVarArgCallConv = "Cannot evaluate a VarArgs function.";
- public const string Argument_CultureIetfNotSupported = "Culture IETF Name {0} is not a recognized IETF name.";
- public const string Argument_CultureInvalidIdentifier = "{0} is an invalid culture identifier.";
- public const string Argument_CultureIsNeutral = "Culture ID {0} (0x{0:X4}) is a neutral culture; a region cannot be created from it.";
- public const string Argument_CultureNotSupported = "Culture is not supported.";
- public const string Argument_CustomAssemblyLoadContextRequestedNameMismatch = "Resolved assembly's simple name should be the same as of the requested assembly.";
- public const string Argument_CustomCultureCannotBePassedByNumber = "Customized cultures cannot be passed by LCID, only by name.";
- public const string Argument_DateTimeBadBinaryData = "The binary data must result in a DateTime with ticks between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.";
- public const string Argument_DateTimeHasTicks = "The supplied DateTime must have the Year, Month, and Day properties set to 1. The time cannot be specified more precisely than whole milliseconds.";
- public const string Argument_DateTimeHasTimeOfDay = "The supplied DateTime includes a TimeOfDay setting. This is not supported.";
- public const string Argument_DateTimeIsInvalid = "The supplied DateTime represents an invalid time. For example, when the clock is adjusted forward, any time in the period that is skipped is invalid.";
- public const string Argument_DateTimeIsNotAmbiguous = "The supplied DateTime is not in an ambiguous time range.";
- public const string Argument_DateTimeKindMustBeUnspecified = "The supplied DateTime must have the Kind property set to DateTimeKind.Unspecified.";
- public const string Argument_DateTimeKindMustBeUnspecifiedOrUtc = "The supplied DateTime must have the Kind property set to DateTimeKind.Unspecified or DateTimeKind.Utc.";
- public const string Argument_DateTimeOffsetInvalidDateTimeStyles = "The DateTimeStyles value 'NoCurrentDateDefault' is not allowed when parsing DateTimeOffset.";
- public const string Argument_DateTimeOffsetIsNotAmbiguous = "The supplied DateTimeOffset is not in an ambiguous time range.";
- public const string Argument_DestinationTooShort = "Destination is too short.";
- public const string Argument_DuplicateTypeName = "Duplicate type name within an assembly.";
- public const string Argument_EmitWriteLineType = "EmitWriteLine does not support this field or local type.";
- public const string Argument_EmptyDecString = "Decimal separator cannot be the empty string.";
- public const string Argument_EmptyFileName = "Empty file name is not legal.";
- public const string Argument_EmptyName = "Empty name is not legal.";
- public const string Argument_EmptyPath = "Empty path name is not legal.";
- public const string Argument_EmptyWaithandleArray = "Waithandle array may not be empty.";
- public const string Argument_EncoderFallbackNotEmpty = "Must complete Convert() operation or call Encoder.Reset() before calling GetBytes() or GetByteCount(). Encoder '{0}' fallback '{1}'.";
- public const string Argument_EncodingConversionOverflowBytes = "The output byte buffer is too small to contain the encoded data, encoding '{0}' fallback '{1}'.";
- public const string Argument_EncodingConversionOverflowChars = "The output char buffer is too small to contain the decoded characters, encoding '{0}' fallback '{1}'.";
- public const string Argument_EncodingNotSupported = "'{0}' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.";
- public const string Argument_EnumTypeDoesNotMatch = "The argument type, '{0}', is not the same as the enum type '{1}'.";
- public const string Argument_FallbackBufferNotEmpty = "Cannot change fallback when buffer is not empty. Previous Convert() call left data in the fallback buffer.";
- public const string Argument_FieldDeclaringTypeGeneric = "Cannot resolve field {0} because the declaring type of the field handle {1} is generic. Explicitly provide the declaring type to GetFieldFromHandle.";
- public const string Argument_FieldNeedGenericDeclaringType = "The specified field must be declared on a generic type definition.";
- public const string Argument_GenConstraintViolation = "GenericArguments[{0}], '{1}', on '{2}' violates the constraint of type '{3}'.";
- public const string Argument_GenericArgsCount = "The number of generic arguments provided doesn't equal the arity of the generic type definition.";
- public const string Argument_GenericsInvalid = "Generic types are not valid.";
- public const string Argument_GlobalFunctionHasToBeStatic = "Global members must be static.";
- public const string Argument_HandleLeak = "Cannot pass a GCHandle across AppDomains.";
- public const string Argument_HasToBeArrayClass = "Must be an array type.";
- public const string Argument_IdnBadBidi = "Left to right characters may not be mixed with right to left characters in IDN labels.";
- public const string Argument_IdnBadLabelSize = "IDN labels must be between 1 and 63 characters long.";
- public const string Argument_IdnBadNameSize = "IDN names must be between 1 and {0} characters long.";
- public const string Argument_IdnBadPunycode = "Invalid IDN encoded string.";
- public const string Argument_IdnBadStd3 = "Label contains character '{0}' not allowed with UseStd3AsciiRules";
- public const string Argument_IdnIllegalName = "Decoded string is not a valid IDN name.";
- public const string Argument_IllegalEnvVarName = "Environment variable name cannot contain equal character.";
- public const string Argument_IllegalName = "Illegal name.";
- public const string Argument_ImplementIComparable = "At least one object must implement IComparable.";
- public const string Argument_IndexOutOfArrayBounds = "The specified index is out of bounds of the specified array.";
- public const string Argument_InsufficientSpaceToCopyCollection = "The specified space is not sufficient to copy the elements from this Collection.";
- public const string Argument_InterfaceMap = "'this' type cannot be an interface itself.";
- public const string Argument_InvalidAppendMode = "Append access can be requested only in write-only mode.";
- public const string Argument_InvalidArgumentForComparison = "Type of argument is not compatible with the generic comparer.";
- public const string Argument_InvalidArrayLength = "Length of the array must be {0}.";
- public const string Argument_InvalidArrayType = "Target array type is not compatible with the type of items in the collection.";
- public const string Argument_InvalidAssemblyName = "Assembly names may not begin with whitespace or contain the characters '/', or '\\\\' or ':'.";
- public const string Argument_InvalidCalendar = "Not a valid calendar for the given culture.";
- public const string Argument_InvalidCharSequence = "Invalid Unicode code point found at index {0}.";
- public const string Argument_InvalidCharSequenceNoIndex = "String contains invalid Unicode code points.";
- public const string Argument_InvalidCodePageBytesIndex = "Unable to translate bytes {0} at index {1} from specified code page to Unicode.";
- public const string Argument_InvalidCodePageConversionIndex = "Unable to translate Unicode character \\\\u{0:X4} at index {1} to specified code page.";
- public const string Argument_InvalidConstructorDeclaringType = "The specified constructor must be declared on the generic type definition of the specified type.";
- public const string Argument_InvalidConstructorInfo = "The ConstructorInfo object is not valid.";
- public const string Argument_InvalidCultureName = "Culture name '{0}' is not supported.";
- public const string Argument_InvalidDateTimeKind = "Invalid DateTimeKind value.";
- public const string Argument_InvalidDateTimeStyles = "An undefined DateTimeStyles value is being used.";
- public const string Argument_InvalidDigitSubstitution = "The DigitSubstitution property must be of a valid member of the DigitShapes enumeration. Valid entries include Context, NativeNational or None.";
- public const string Argument_InvalidElementName = "Invalid element name '{0}'.";
- public const string Argument_InvalidElementTag = "Invalid element tag '{0}'.";
- public const string Argument_InvalidElementText = "Invalid element text '{0}'.";
- public const string Argument_InvalidElementValue = "Invalid element value '{0}'.";
- public const string Argument_InvalidEnum = "The Enum type should contain one and only one instance field.";
- public const string Argument_InvalidEnumValue = "The value '{0}' is not valid for this usage of the type {1}.";
- public const string Argument_InvalidFieldDeclaringType = "The specified field must be declared on the generic type definition of the specified type.";
- public const string Argument_InvalidFileModeAndAccessCombo = "Combining FileMode: {0} with FileAccess: {1} is invalid.";
- public const string Argument_InvalidFlag = "Value of flags is invalid.";
- public const string Argument_InvalidGenericArg = "The generic type parameter was not valid";
- public const string Argument_InvalidGenericInstArray = "Generic arguments must be provided for each generic parameter and each generic argument must be a RuntimeType.";
- public const string Argument_InvalidGroupSize = "Every element in the value array should be between one and nine, except for the last element, which can be zero.";
- public const string Argument_InvalidHandle = "The handle is invalid.";
- public const string Argument_InvalidHighSurrogate = "Found a high surrogate char without a following low surrogate at index: {0}. The input may not be in this encoding, or may not contain valid Unicode (UTF-16) characters.";
- public const string Argument_InvalidId = "The specified ID parameter '{0}' is not supported.";
- public const string Argument_InvalidKindOfTypeForCA = "This type cannot be represented as a custom attribute.";
- public const string Argument_InvalidLabel = "Invalid Label.";
- public const string Argument_InvalidLowSurrogate = "Found a low surrogate char without a preceding high surrogate at index: {0}. The input may not be in this encoding, or may not contain valid Unicode (UTF-16) characters.";
- public const string Argument_InvalidMemberForNamedArgument = "The member must be either a field or a property.";
- public const string Argument_InvalidMethodDeclaringType = "The specified method must be declared on the generic type definition of the specified type.";
- public const string Argument_InvalidName = "Invalid name.";
- public const string Argument_InvalidNativeDigitCount = "The NativeDigits array must contain exactly ten members.";
- public const string Argument_InvalidNativeDigitValue = "Each member of the NativeDigits array must be a single text element (one or more UTF16 code points) with a Unicode Nd (Number, Decimal Digit) property indicating it is a digit.";
- public const string Argument_InvalidNeutralRegionName = "The region name {0} should not correspond to neutral culture; a specific culture name is required.";
- public const string Argument_InvalidNormalizationForm = "Invalid or unsupported normalization form.";
- public const string Argument_InvalidNumberStyles = "An undefined NumberStyles value is being used.";
- public const string Argument_InvalidOffLen = "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.";
- public const string Argument_InvalidOpCodeOnDynamicMethod = "Ldtoken, Ldftn and Ldvirtftn OpCodes cannot target DynamicMethods.";
- public const string Argument_InvalidParameterInfo = "The ParameterInfo object is not valid.";
- public const string Argument_InvalidParamInfo = "Invalid type for ParameterInfo member in Attribute class.";
- public const string Argument_InvalidPathChars = "Illegal characters in path.";
- public const string Argument_InvalidRegistryViewCheck = "The specified RegistryView value is invalid.";
- public const string Argument_InvalidResourceCultureName = "The given culture name '{0}' cannot be used to locate a resource file. Resource filenames must consist of only letters, numbers, hyphens or underscores.";
- public const string Argument_InvalidSafeBufferOffLen = "Offset and length were greater than the size of the SafeBuffer.";
- public const string Argument_InvalidSeekOrigin = "Invalid seek origin.";
- public const string Argument_InvalidSerializedString = "The specified serialized string '{0}' is not supported.";
- public const string Argument_InvalidStartupHookSyntax = "The syntax of the startup hook variable was invalid.";
- public const string Argument_InvalidStartupHookSignature = "The signature of the startup hook '{0}' in assembly '{1}' was invalid. It must be 'public static void Initialize()'.";
- public const string Argument_InvalidTimeSpanStyles = "An undefined TimeSpanStyles value is being used.";
- public const string Argument_InvalidToken = "Token {0:x} is not valid in the scope of module {1}.";
- public const string Argument_InvalidTypeForCA = "Cannot build type parameter for custom attribute with a type that does not support the AssemblyQualifiedName property. The type instance supplied was of type '{0}'.";
- public const string Argument_InvalidTypeForDynamicMethod = "Invalid type owner for DynamicMethod.";
- public const string Argument_InvalidTypeName = "The name of the type is invalid.";
- public const string Argument_InvalidTypeWithPointersNotSupported = "Cannot use type '{0}'. Only value types without pointers or references are supported.";
- public const string Argument_InvalidUnity = "Type '{0}' is not deserializable.";
- public const string Argument_InvalidValue = "Value was invalid.";
- public const string Argument_LargeInteger = "Integer or token was too large to be encoded.";
- public const string Argument_LongEnvVarValue = "Environment variable name or value is too long.";
- public const string Argument_MethodDeclaringTypeGeneric = "Cannot resolve method {0} because the declaring type of the method handle {1} is generic. Explicitly provide the declaring type to GetMethodFromHandle.";
- public const string Argument_MethodDeclaringTypeGenericLcg = "Method '{0}' has a generic declaring type '{1}'. Explicitly provide the declaring type to GetTokenFor.";
- public const string Argument_MethodNeedGenericDeclaringType = "The specified method cannot be dynamic or global and must be declared on a generic type definition.";
- public const string Argument_MinMaxValue = "'{0}' cannot be greater than {1}.";
- public const string Argument_MismatchedArrays = "Two arrays, {0} and {1}, must be of the same size.";
- public const string Argument_MissingDefaultConstructor = "was missing default constructor.";
- public const string Argument_MustBeFalse = "Argument must be initialized to false";
- public const string Argument_MustBeRuntimeAssembly = "Assembly must be a runtime Assembly object.";
- public const string Argument_MustBeRuntimeFieldInfo = "FieldInfo must be a runtime FieldInfo object.";
- public const string Argument_MustBeRuntimeMethodInfo = "MethodInfo must be a runtime MethodInfo object.";
- public const string Argument_MustBeRuntimeReflectionObject = "The object must be a runtime Reflection object.";
- public const string Argument_MustBeRuntimeType = "Type must be a runtime Type object.";
- public const string Argument_MustBeTypeBuilder = "'type' must contain a TypeBuilder as a generic argument.";
- public const string Argument_MustHaveAttributeBaseClass = "Type passed in must be derived from System.Attribute or System.Attribute itself.";
- public const string Argument_MustHaveLayoutOrBeBlittable = "The specified structure must be blittable or have layout information.";
- public const string Argument_NativeOverlappedAlreadyFree = "'overlapped' has already been freed.";
- public const string Argument_NativeOverlappedWrongBoundHandle = "'overlapped' was not allocated by this ThreadPoolBoundHandle instance.";
- public const string Argument_NeedGenericMethodDefinition = "Method must represent a generic method definition on a generic type definition.";
- public const string Argument_NeedNonGenericObject = "The specified object must not be an instance of a generic type.";
- public const string Argument_NeedNonGenericType = "The specified Type must not be a generic type definition.";
- public const string Argument_NeedStructWithNoRefs = "The specified Type must be a struct containing no references.";
- public const string Argument_NeverValidGenericArgument = "The type '{0}' may not be used as a type argument.";
- public const string Argument_NoDomainManager = "The domain manager specified by the host could not be instantiated.";
- public const string Argument_NoEra = "No Era was supplied.";
- public const string Argument_NoModuleFileExtension = "Module file name '{0}' must have file extension.";
- public const string Argument_NoRegionInvariantCulture = "There is no region associated with the Invariant Culture (Culture ID: 0x7F).";
- public const string Argument_NotATP = "Type must be a TransparentProxy";
- public const string Argument_NotAWritableProperty = "Not a writable property.";
- public const string Argument_NotEnoughBytesToRead = "There are not enough bytes remaining in the accessor to read at this position.";
- public const string Argument_NotEnoughBytesToWrite = "There are not enough bytes remaining in the accessor to write at this position.";
- public const string Argument_NotEnoughGenArguments = "The type or method has {1} generic parameter(s), but {0} generic argument(s) were provided. A generic argument must be provided for each generic parameter.";
- public const string Argument_NotExceptionType = "Does not extend Exception.";
- public const string Argument_NotInExceptionBlock = "Not currently in an exception block.";
- public const string Argument_NotMethodCallOpcode = "The specified opcode cannot be passed to EmitCall.";
- public const string Argument_NotSerializable = "Argument passed in is not serializable.";
- public const string Argument_NoUnderlyingCCW = "The object has no underlying COM data associated with it.";
- public const string Argument_NoUninitializedStrings = "Uninitialized Strings cannot be created.";
- public const string Argument_ObjIsWinRTObject = "The object's type must not be a Windows Runtime type.";
- public const string Argument_ObjNotComObject = "The object's type must be __ComObject or derived from __ComObject.";
- public const string Argument_OffsetAndCapacityOutOfBounds = "Offset and capacity were greater than the size of the view.";
- public const string Argument_OffsetLocalMismatch = "The UTC Offset of the local dateTime parameter does not match the offset argument.";
- public const string Argument_OffsetOfFieldNotFound = "Field passed in is not a marshaled member of the type '{0}'.";
- public const string Argument_OffsetOutOfRange = "Offset must be within plus or minus 14 hours.";
- public const string Argument_OffsetPrecision = "Offset must be specified in whole minutes.";
- public const string Argument_OffsetUtcMismatch = "The UTC Offset for Utc DateTime instances must be 0.";
- public const string Argument_OneOfCulturesNotSupported = "Culture name {0} or {1} is not supported.";
- public const string Argument_OnlyMscorlib = "Only mscorlib's assembly is valid.";
- public const string Argument_OutOfOrderDateTimes = "The DateStart property must come before the DateEnd property.";
- public const string Argument_PathEmpty = "Path cannot be the empty string or all whitespace.";
- public const string Argument_PathFormatNotSupported_Path = "The format of the path '{0}' is not supported.";
- public const string Argument_PreAllocatedAlreadyAllocated = "'preAllocated' is already in use.";
- public const string Argument_RecursiveFallback = "Recursive fallback not allowed for character \\\\u{0:X4}.";
- public const string Argument_RecursiveFallbackBytes = "Recursive fallback not allowed for bytes {0}.";
- public const string Argument_RedefinedLabel = "Label multiply defined.";
- public const string Argument_ResolveField = "Token {0:x} is not a valid FieldInfo token in the scope of module {1}.";
- public const string Argument_ResolveFieldHandle = "Type handle '{0}' and field handle with declaring type '{1}' are incompatible. Get RuntimeFieldHandle and declaring RuntimeTypeHandle off the same FieldInfo.";
- public const string Argument_ResolveMember = "Token {0:x} is not a valid MemberInfo token in the scope of module {1}.";
- public const string Argument_ResolveMethod = "Token {0:x} is not a valid MethodBase token in the scope of module {1}.";
- public const string Argument_ResolveMethodHandle = "Type handle '{0}' and method handle with declaring type '{1}' are incompatible. Get RuntimeMethodHandle and declaring RuntimeTypeHandle off the same MethodBase.";
- public const string Argument_ResolveModuleType = "Token {0} resolves to the special module type representing this module.";
- public const string Argument_ResolveString = "Token {0:x} is not a valid string token in the scope of module {1}.";
- public const string Argument_ResolveType = "Token {0:x} is not a valid Type token in the scope of module {1}.";
- public const string Argument_ResultCalendarRange = "The result is out of the supported range for this calendar. The result should be between {0} (Gregorian date) and {1} (Gregorian date), inclusive.";
- public const string Argument_SemaphoreInitialMaximum = "The initial count for the semaphore must be greater than or equal to zero and less than the maximum count.";
- public const string Argument_ShouldNotSpecifyExceptionType = "Should not specify exception type for catch clause for filter block.";
- public const string Argument_ShouldOnlySetVisibilityFlags = "Should only set visibility flags when creating EnumBuilder.";
- public const string Argument_SigIsFinalized = "Completed signature cannot be modified.";
- public const string Argument_SpansMustHaveSameLength = "Length of items must be same as length of keys.";
- public const string Argument_StreamNotReadable = "Stream was not readable.";
- public const string Argument_StreamNotWritable = "Stream was not writable.";
- public const string Argument_StringFirstCharIsZero = "The first char in the string is the null character.";
- public const string Argument_StringZeroLength = "String cannot be of zero length.";
- public const string Argument_StructMustNotBeValueClass = "The structure must not be a value class.";
- public const string Argument_TimeSpanHasSeconds = "The TimeSpan parameter cannot be specified more precisely than whole minutes.";
- public const string Argument_TimeZoneInfoBadTZif = "The tzfile does not begin with the magic characters 'TZif'. Please verify that the file is not corrupt.";
- public const string Argument_TimeZoneInfoInvalidTZif = "The TZif data structure is corrupt.";
- public const string Argument_ToExclusiveLessThanFromExclusive = "fromInclusive must be less than or equal to toExclusive.";
- public const string Argument_TooManyFinallyClause = "Exception blocks may have at most one finally clause.";
- public const string Argument_TransitionTimesAreIdentical = "The DaylightTransitionStart property must not equal the DaylightTransitionEnd property.";
- public const string Argument_TypedReferenceInvalidField = "Field '{0}' in TypedReferences cannot be static.";
- public const string Argument_TypeIsWinRTType = "The type must not be a Windows Runtime type.";
- public const string Argument_TypeMustBeVisibleFromCom = "The specified type must be visible from COM.";
- public const string Argument_TypeMustNotBeComImport = "The type must not be imported from COM.";
- public const string Argument_TypeNameTooLong = "Type name was too long. The fully qualified type name must be less than 1,024 characters.";
- public const string Argument_TypeNotActivatableViaWindowsRuntime = "Type '{0}' does not have an activation factory because it is not activatable by Windows Runtime.";
- public const string Argument_TypeNotComObject = "The type must be __ComObject or be derived from __ComObject.";
- public const string Argument_TypeNotValid = "The Type object is not valid.";
- public const string Argument_UnclosedExceptionBlock = "The IL Generator cannot be used while there are unclosed exceptions.";
- public const string Argument_Unexpected_TypeSource = "Unexpected TypeKind when marshaling Windows.Foundation.TypeName.";
- public const string Argument_UnknownUnmanagedCallConv = "Unknown unmanaged calling convention for function signature.";
- public const string Argument_UnmanagedMemAccessorWrapAround = "The UnmanagedMemoryAccessor capacity and offset would wrap around the high end of the address space.";
- public const string Argument_UnmatchedMethodForLocal = "Local passed in does not belong to this ILGenerator.";
- public const string Argument_UnmatchingSymScope = "Non-matching symbol scope.";
- public const string Argument_UTCOutOfRange = "The UTC time represented when the offset is applied must be between year 0 and 10,000.";
- public const string Argument_VerStringTooLong = "The unmanaged Version information is too large to persist.";
- public const string Argument_WaitHandleNameTooLong = "The length of the name exceeds the maximum limit.";
- public const string Argument_WinRTSystemRuntimeType = "Cannot marshal type '{0}' to Windows Runtime. Only 'System.RuntimeType' is supported.";
- public const string ArgumentException_BadMethodImplBody = "MethodOverride's body must be from this type.";
- public const string ArgumentException_BufferNotFromPool = "The buffer is not associated with this pool and may not be returned to it.";
- public const string ArgumentException_OtherNotArrayOfCorrectLength = "Object is not a array with the same number of elements as the array to compare it to.";
- public const string ArgumentException_NotIsomorphic = "Object contains non-primitive or non-blittable data.";
- public const string ArgumentException_TupleIncorrectType = "Argument must be of type {0}.";
- public const string ArgumentException_TupleLastArgumentNotATuple = "The last element of an eight element tuple must be a Tuple.";
- public const string ArgumentException_ValueTupleIncorrectType = "Argument must be of type {0}.";
- public const string ArgumentException_ValueTupleLastArgumentNotAValueTuple = "The last element of an eight element ValueTuple must be a ValueTuple.";
- public const string ArgumentNull_Array = "Array cannot be null.";
- public const string ArgumentNull_ArrayElement = "At least one element in the specified array was null.";
- public const string ArgumentNull_ArrayValue = "Found a null value within an array.";
- public const string ArgumentNull_Assembly = "Assembly cannot be null.";
- public const string ArgumentNull_AssemblyName = "AssemblyName cannot be null.";
- public const string ArgumentNull_AssemblyNameName = "AssemblyName.Name cannot be null or an empty string.";
- public const string ArgumentNull_Buffer = "Buffer cannot be null.";
- public const string ArgumentNull_Child = "Cannot have a null child.";
- public const string ArgumentNull_Collection = "Collection cannot be null.";
- public const string ArgumentNull_Dictionary = "Dictionary cannot be null.";
- public const string ArgumentNull_FileName = "File name cannot be null.";
- public const string ArgumentNull_Generic = "Value cannot be null.";
- public const string ArgumentNull_GUID = "GUID cannot be null.";
- public const string ArgumentNull_Key = "Key cannot be null.";
- public const string ArgumentNull_Path = "Path cannot be null.";
- public const string ArgumentNull_SafeHandle = "SafeHandle cannot be null.";
- public const string ArgumentNull_Stream = "Stream cannot be null.";
- public const string ArgumentNull_String = "String reference not set to an instance of a String.";
- public const string ArgumentNull_Type = "Type cannot be null.";
- public const string ArgumentNull_TypedRefType = "Type in TypedReference cannot be null.";
- public const string ArgumentNull_Waithandles = "The waitHandles parameter cannot be null.";
- public const string ArgumentOutOfRange_ActualValue = "Actual value was {0}.";
- public const string ArgumentOutOfRange_AddressSpace = "The number of bytes cannot exceed the virtual address space on a 32 bit machine.";
- public const string ArgumentOutOfRange_AddValue = "Value to add was out of range.";
- public const string ArgumentOutOfRange_ArrayLB = "Number was less than the array's lower bound in the first dimension.";
- public const string ArgumentOutOfRange_ArrayLBAndLength = "Higher indices will exceed Int32.MaxValue because of large lower bound and/or length.";
- public const string ArgumentOutOfRange_BadHourMinuteSecond = "Hour, Minute, and Second parameters describe an un-representable DateTime.";
- public const string ArgumentOutOfRange_BadYearMonthDay = "Year, Month, and Day parameters describe an un-representable DateTime.";
- public const string ArgumentOutOfRange_BiggerThanCollection = "Larger than collection size.";
- public const string ArgumentOutOfRange_BinaryReaderFillBuffer = "The number of bytes requested does not fit into BinaryReader's internal buffer.";
- public const string ArgumentOutOfRange_Bounds_Lower_Upper = "Argument must be between {0} and {1}.";
- public const string ArgumentOutOfRange_CalendarRange = "Specified time is not supported in this calendar. It should be between {0} (Gregorian date) and {1} (Gregorian date), inclusive.";
- public const string ArgumentOutOfRange_Capacity = "Capacity exceeds maximum capacity.";
- public const string ArgumentOutOfRange_Count = "Count must be positive and count must refer to a location within the string/array/collection.";
- public const string ArgumentOutOfRange_DateArithmetic = "The added or subtracted value results in an un-representable DateTime.";
- public const string ArgumentOutOfRange_DateTimeBadMonths = "Months value must be between +/-120000.";
- public const string ArgumentOutOfRange_DateTimeBadTicks = "Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.";
- public const string ArgumentOutOfRange_DateTimeBadYears = "Years value must be between +/-10000.";
- public const string ArgumentOutOfRange_Day = "Day must be between 1 and {0} for month {1}.";
- public const string ArgumentOutOfRange_DayOfWeek = "The DayOfWeek enumeration must be in the range 0 through 6.";
- public const string ArgumentOutOfRange_DayParam = "The Day parameter must be in the range 1 through 31.";
- public const string ArgumentOutOfRange_DecimalRound = "Decimal can only round to between 0 and 28 digits of precision.";
- public const string ArgumentOutOfRange_DecimalScale = "Decimal's scale value must be between 0 and 28, inclusive.";
- public const string ArgumentOutOfRange_EndIndexStartIndex = "endIndex cannot be greater than startIndex.";
- public const string ArgumentOutOfRange_Enum = "Enum value was out of legal range.";
- public const string ArgumentOutOfRange_Era = "Time value was out of era range.";
- public const string ArgumentOutOfRange_FileLengthTooBig = "Specified file length was too large for the file system.";
- public const string ArgumentOutOfRange_FileTimeInvalid = "Not a valid Win32 FileTime.";
- public const string ArgumentOutOfRange_GenericPositive = "Value must be positive.";
- public const string ArgumentOutOfRange_GetByteCountOverflow = "Too many characters. The resulting number of bytes is larger than what can be returned as an int.";
- public const string ArgumentOutOfRange_GetCharCountOverflow = "Too many bytes. The resulting number of chars is larger than what can be returned as an int.";
- public const string ArgumentOutOfRange_HashtableLoadFactor = "Load factor needs to be between 0.1 and 1.0.";
- public const string ArgumentOutOfRange_HugeArrayNotSupported = "Arrays larger than 2GB are not supported.";
- public const string ArgumentOutOfRange_Index = "Index was out of range. Must be non-negative and less than the size of the collection.";
- public const string ArgumentOutOfRange_IndexCount = "Index and count must refer to a location within the string.";
- public const string ArgumentOutOfRange_IndexCountBuffer = "Index and count must refer to a location within the buffer.";
- public const string ArgumentOutOfRange_IndexLargerThanMaxValue = "This collection cannot work with indices larger than Int32.MaxValue - 1 (0x7FFFFFFF - 1).";
- public const string ArgumentOutOfRange_IndexLength = "Index and length must refer to a location within the string.";
- public const string ArgumentOutOfRange_IndexString = "Index was out of range. Must be non-negative and less than the length of the string.";
- public const string ArgumentOutOfRange_InvalidEraValue = "Era value was not valid.";
- public const string ArgumentOutOfRange_InvalidHighSurrogate = "A valid high surrogate character is between 0xd800 and 0xdbff, inclusive.";
- public const string ArgumentOutOfRange_InvalidLowSurrogate = "A valid low surrogate character is between 0xdc00 and 0xdfff, inclusive.";
- public const string ArgumentOutOfRange_InvalidUTF32 = "A valid UTF32 value is between 0x000000 and 0x10ffff, inclusive, and should not include surrogate codepoint values (0x00d800 ~ 0x00dfff).";
- public const string ArgumentOutOfRange_Length = "The specified length exceeds maximum capacity of SecureString.";
- public const string ArgumentOutOfRange_LengthGreaterThanCapacity = "The length cannot be greater than the capacity.";
- public const string ArgumentOutOfRange_LengthTooLarge = "The specified length exceeds the maximum value of {0}.";
- public const string ArgumentOutOfRange_LessEqualToIntegerMaxVal = "Argument must be less than or equal to 2^31 - 1 milliseconds.";
- public const string ArgumentOutOfRange_ListInsert = "Index must be within the bounds of the List.";
- public const string ArgumentOutOfRange_Month = "Month must be between one and twelve.";
- public const string ArgumentOutOfRange_MonthParam = "The Month parameter must be in the range 1 through 12.";
- public const string ArgumentOutOfRange_MustBeNonNegInt32 = "Value must be non-negative and less than or equal to Int32.MaxValue.";
- public const string ArgumentOutOfRange_MustBeNonNegNum = "'{0}' must be non-negative.";
- public const string ArgumentOutOfRange_MustBePositive = "'{0}' must be greater than zero.";
- public const string ArgumentOutOfRange_NeedNonNegNum = "Non-negative number required.";
- public const string ArgumentOutOfRange_NeedNonNegOrNegative1 = "Number must be either non-negative and less than or equal to Int32.MaxValue or -1.";
- public const string ArgumentOutOfRange_NeedPosNum = "Positive number required.";
- public const string ArgumentOutOfRange_NeedValidId = "The ID parameter must be in the range {0} through {1}.";
- public const string ArgumentOutOfRange_NegativeCapacity = "Capacity must be positive.";
- public const string ArgumentOutOfRange_NegativeCount = "Count cannot be less than zero.";
- public const string ArgumentOutOfRange_NegativeLength = "Length cannot be less than zero.";
- public const string ArgumentOutOfRange_OffsetLength = "Offset and length must refer to a position in the string.";
- public const string ArgumentOutOfRange_OffsetOut = "Either offset did not refer to a position in the string, or there is an insufficient length of destination character array.";
- public const string ArgumentOutOfRange_ParamSequence = "The specified parameter index is not in range.";
- public const string ArgumentOutOfRange_PartialWCHAR = "Pointer startIndex and length do not refer to a valid string.";
- public const string ArgumentOutOfRange_PeriodTooLarge = "Period must be less than 2^32-2.";
- public const string ArgumentOutOfRange_PositionLessThanCapacityRequired = "The position may not be greater or equal to the capacity of the accessor.";
- public const string ArgumentOutOfRange_Range = "Valid values are between {0} and {1}, inclusive.";
- public const string ArgumentOutOfRange_RoundingDigits = "Rounding digits must be between 0 and 15, inclusive.";
- public const string ArgumentOutOfRange_SmallCapacity = "capacity was less than the current size.";
- public const string ArgumentOutOfRange_SmallMaxCapacity = "MaxCapacity must be one or greater.";
- public const string ArgumentOutOfRange_StartIndex = "StartIndex cannot be less than zero.";
- public const string ArgumentOutOfRange_StartIndexLargerThanLength = "startIndex cannot be larger than length of string.";
- public const string ArgumentOutOfRange_StartIndexLessThanLength = "startIndex must be less than length of string.";
- public const string ArgumentOutOfRange_StreamLength = "Stream length must be non-negative and less than 2^31 - 1 - origin.";
- public const string ArgumentOutOfRange_TimeoutTooLarge = "Time-out interval must be less than 2^32-2.";
- public const string ArgumentOutOfRange_UIntPtrMax = "The length of the buffer must be less than the maximum UIntPtr value for your platform.";
- public const string ArgumentOutOfRange_UnmanagedMemStreamLength = "UnmanagedMemoryStream length must be non-negative and less than 2^63 - 1 - baseAddress.";
- public const string ArgumentOutOfRange_UnmanagedMemStreamWrapAround = "The UnmanagedMemoryStream capacity would wrap around the high end of the address space.";
- public const string ArgumentOutOfRange_UtcOffset = "The TimeSpan parameter must be within plus or minus 14.0 hours.";
- public const string ArgumentOutOfRange_UtcOffsetAndDaylightDelta = "The sum of the BaseUtcOffset and DaylightDelta properties must within plus or minus 14.0 hours.";
- public const string ArgumentOutOfRange_Version = "Version's parameters must be greater than or equal to zero.";
- public const string ArgumentOutOfRange_Week = "The Week parameter must be in the range 1 through 5.";
- public const string ArgumentOutOfRange_Year = "Year must be between 1 and 9999.";
- public const string Arithmetic_NaN = "Function does not accept floating point Not-a-Number values.";
- public const string ArrayTypeMismatch_CantAssignType = "Source array type cannot be assigned to destination array type.";
- public const string ArrayTypeMismatch_ConstrainedCopy = "Array.ConstrainedCopy will only work on array types that are provably compatible, without any form of boxing, unboxing, widening, or casting of each array element. Change the array types (i.e., copy a Derived[] to a Base[]), or use a mitigation strategy in the CER for Array.Copy's less powerful reliability contract, such as cloning the array or throwing away the potentially corrupt destination array.";
- public const string AssemblyLoadContext_Constructor_CannotInstantiateWhileUnloading = "Cannot instantiate AssemblyLoadContext while the current process is exiting.";
- public const string AssemblyLoadContext_Unload_CannotUnloadIfNotCollectible = "Cannot unload non-collectible AssemblyLoadContext.";
- public const string AssemblyLoadContext_Unload_AlreadyUnloaded = "Unload called on AssemblyLoadContext that is unloading or that was already unloaded.";
- public const string AssemblyLoadContext_Verify_NotUnloading = "AssemblyLoadContext is unloading or was already unloaded.";
- public const string AssertionFailed = "Assertion failed.";
- public const string AssertionFailed_Cnd = "Assertion failed: {0}";
- public const string AssumptionFailed = "Assumption failed.";
- public const string AssumptionFailed_Cnd = "Assumption failed: {0}";
- public const string AsyncMethodBuilder_InstanceNotInitialized = "The builder was not properly initialized.";
- public const string BadImageFormat_BadILFormat = "Bad IL format.";
- public const string BadImageFormat_InvalidType = "Corrupt .resources file. The specified type doesn't exist.";
- public const string BadImageFormat_NegativeStringLength = "Corrupt .resources file. String length must be non-negative.";
- public const string BadImageFormat_ParameterSignatureMismatch = "The parameters and the signature of the method don't match.";
- public const string BadImageFormat_ResType_SerBlobMismatch = "The type serialized in the .resources file was not the same type that the .resources file said it contained. Expected '{0}' but read '{1}'.";
- public const string BadImageFormat_ResourceDataLengthInvalid = "Corrupt .resources file. The specified data length '{0}' is not a valid position in the stream.";
- public const string BadImageFormat_ResourceNameCorrupted = "Corrupt .resources file. A resource name extends past the end of the stream.";
- public const string BadImageFormat_ResourceNameCorrupted_NameIndex = "Corrupt .resources file. The resource name for name index {0} extends past the end of the stream.";
- public const string BadImageFormat_ResourcesDataInvalidOffset = "Corrupt .resources file. Invalid offset '{0}' into data section.";
- public const string BadImageFormat_ResourcesHeaderCorrupted = "Corrupt .resources file. Unable to read resources from this file because of invalid header information. Try regenerating the .resources file.";
- public const string BadImageFormat_ResourcesIndexTooLong = "Corrupt .resources file. String for name index '{0}' extends past the end of the file.";
- public const string BadImageFormat_ResourcesNameInvalidOffset = "Corrupt .resources file. Invalid offset '{0}' into name section.";
- public const string BadImageFormat_ResourcesNameTooLong = "Corrupt .resources file. Resource name extends past the end of the file.";
- public const string BadImageFormat_TypeMismatch = "Corrupt .resources file. The specified type doesn't match the available data in the stream.";
- public const string CancellationToken_CreateLinkedToken_TokensIsEmpty = "No tokens were supplied.";
- public const string CancellationToken_SourceDisposed = "The CancellationTokenSource associated with this CancellationToken has been disposed.";
- public const string CancellationTokenSource_Disposed = "The CancellationTokenSource has been disposed.";
- public const string ConcurrentCollection_SyncRoot_NotSupported = "The SyncRoot property may not be used for the synchronization of concurrent collections.";
- public const string event_SpinLock_FastPathFailed = "SpinLock beginning to spin.";
- public const string event_SpinWait_NextSpinWillYield = "Next spin will yield.";
- public const string event_TaskCompleted = "Task {2} completed.";
- public const string event_TaskScheduled = "Task {2} scheduled to TaskScheduler {0}.";
- public const string event_TaskStarted = "Task {2} executing.";
- public const string event_TaskWaitBegin = "Beginning wait ({3}) on Task {2}.";
- public const string event_TaskWaitEnd = "Ending wait on Task {2}.";
- public const string EventSource_AbstractMustNotDeclareEventMethods = "Abstract event source must not declare event methods ({0} with ID {1}).";
- public const string EventSource_AbstractMustNotDeclareKTOC = "Abstract event source must not declare {0} nested type.";
- public const string EventSource_AddScalarOutOfRange = "Getting out of bounds during scalar addition.";
- public const string EventSource_BadHexDigit = "Bad Hexidecimal digit \"{0}\".";
- public const string EventSource_ChannelTypeDoesNotMatchEventChannelValue = "Channel {0} does not match event channel value {1}.";
- public const string EventSource_DataDescriptorsOutOfRange = "Data descriptors are out of range.";
- public const string EventSource_DuplicateStringKey = "Multiple definitions for string \"{0}\".";
- public const string EventSource_EnumKindMismatch = "The type of {0} is not expected in {1}.";
- public const string EventSource_EvenHexDigits = "Must have an even number of Hexidecimal digits.";
- public const string EventSource_EventChannelOutOfRange = "Channel {0} has a value of {1} which is outside the legal range (16-254).";
- public const string EventSource_EventIdReused = "Event {0} has ID {1} which is already in use.";
- public const string EventSource_EventMustHaveTaskIfNonDefaultOpcode = "Event {0} (with ID {1}) has a non-default opcode but not a task.";
- public const string EventSource_EventMustNotBeExplicitImplementation = "Event method {0} (with ID {1}) is an explicit interface method implementation. Re-write method as implicit implementation.";
- public const string EventSource_EventNameDoesNotEqualTaskPlusOpcode = "Event {0} (with ID {1}) has a name that is not the concatenation of its task name and opcode.";
- public const string EventSource_EventNameReused = "Event name {0} used more than once. If you wish to overload a method, the overloaded method should have a NonEvent attribute.";
- public const string EventSource_EventParametersMismatch = "Event {0} was called with {1} argument(s), but it is defined with {2} parameter(s).";
- public const string EventSource_EventSourceGuidInUse = "An instance of EventSource with Guid {0} already exists.";
- public const string EventSource_EventTooBig = "The payload for a single event is too large.";
- public const string EventSource_EventWithAdminChannelMustHaveMessage = "Event {0} specifies an Admin channel {1}. It must specify a Message property.";
- public const string EventSource_IllegalKeywordsValue = "Keyword {0} has a value of {1} which is outside the legal range (0-0x0000080000000000).";
- public const string EventSource_IllegalOpcodeValue = "Opcode {0} has a value of {1} which is outside the legal range (11-238).";
- public const string EventSource_IllegalTaskValue = "Task {0} has a value of {1} which is outside the legal range (1-65535).";
- public const string EventSource_IllegalValue = "Illegal value \"{0}\" (prefix strings with @ to indicate a literal string).";
- public const string EventSource_IncorrentlyAuthoredTypeInfo = "Incorrectly-authored TypeInfo - a type should be serialized as one field or as one group";
- public const string EventSource_InvalidCommand = "Invalid command value.";
- public const string EventSource_InvalidEventFormat = "Can't specify both etw event format flags.";
- public const string EventSource_KeywordCollision = "Keywords {0} and {1} are defined with the same value ({2}).";
- public const string EventSource_KeywordNeedPowerOfTwo = "Value {0} for keyword {1} needs to be a power of 2.";
- public const string EventSource_ListenerCreatedInsideCallback = "Creating an EventListener inside a EventListener callback.";
- public const string EventSource_ListenerNotFound = "Listener not found.";
- public const string EventSource_ListenerWriteFailure = "An error occurred when writing to a listener.";
- public const string EventSource_MaxChannelExceeded = "Attempt to define more than the maximum limit of 8 channels for a provider.";
- public const string EventSource_MismatchIdToWriteEvent = "Event {0} was assigned event ID {1} but {2} was passed to WriteEvent.";
- public const string EventSource_NeedGuid = "The Guid of an EventSource must be non zero.";
- public const string EventSource_NeedName = "The name of an EventSource must not be null.";
- public const string EventSource_NeedPositiveId = "Event IDs must be positive integers.";
- public const string EventSource_NoFreeBuffers = "No Free Buffers available from the operating system (e.g. event rate too fast).";
- public const string EventSource_NonCompliantTypeError = "The API supports only anonymous types or types decorated with the EventDataAttribute. Non-compliant type: {0} dataType.";
- public const string EventSource_NoRelatedActivityId = "EventSource expects the first parameter of the Event method to be of type Guid and to be named \"relatedActivityId\" when calling WriteEventWithRelatedActivityId.";
- public const string EventSource_NotSupportedArrayOfBinary = "Arrays of Binary are not supported.";
- public const string EventSource_NotSupportedArrayOfNil = "Arrays of Nil are not supported.";
- public const string EventSource_NotSupportedArrayOfNullTerminatedString = "Arrays of null-terminated string are not supported.";
- public const string EventSource_NotSupportedCustomSerializedData = "Enumerables of custom-serialized data are not supported";
- public const string EventSource_NotSupportedNestedArraysEnums = "Nested arrays/enumerables are not supported.";
- public const string EventSource_NullInput = "Null passed as a event argument.";
- public const string EventSource_OpcodeCollision = "Opcodes {0} and {1} are defined with the same value ({2}).";
- public const string EventSource_PinArrayOutOfRange = "Pins are out of range.";
- public const string EventSource_RecursiveTypeDefinition = "Recursive type definition is not supported.";
- public const string EventSource_SessionIdError = "Bit position in AllKeywords ({0}) must equal the command argument named \"EtwSessionKeyword\" ({1}).";
- public const string EventSource_StopsFollowStarts = "An event with stop suffix must follow a corresponding event with a start suffix.";
- public const string EventSource_TaskCollision = "Tasks {0} and {1} are defined with the same value ({2}).";
- public const string EventSource_TaskOpcodePairReused = "Event {0} (with ID {1}) has the same task/opcode pair as event {2} (with ID {3}).";
- public const string EventSource_TooManyArgs = "Too many arguments.";
- public const string EventSource_TooManyFields = "Too many fields in structure.";
- public const string EventSource_ToString = "EventSource({0}, {1})";
- public const string EventSource_TraitEven = "There must be an even number of trait strings (they are key-value pairs).";
- public const string EventSource_TypeMustBeSealedOrAbstract = "Event source types must be sealed or abstract.";
- public const string EventSource_TypeMustDeriveFromEventSource = "Event source types must derive from EventSource.";
- public const string EventSource_UndefinedChannel = "Use of undefined channel value {0} for event {1}.";
- public const string EventSource_UndefinedKeyword = "Use of undefined keyword value {0} for event {1}.";
- public const string EventSource_UndefinedOpcode = "Use of undefined opcode value {0} for event {1}.";
- public const string EventSource_UnknownEtwTrait = "Unknown ETW trait \"{0}\".";
- public const string EventSource_UnsupportedEventTypeInManifest = "Unsupported type {0} in event source.";
- public const string EventSource_UnsupportedMessageProperty = "Event {0} specifies an illegal or unsupported formatting message (\"{1}\").";
- public const string EventSource_VarArgsParameterMismatch = "The parameters to the Event method do not match the parameters to the WriteEvent method. This may cause the event to be displayed incorrectly.";
- public const string Exception_EndOfInnerExceptionStack = "--- End of inner exception stack trace ---";
- public const string Exception_EndStackTraceFromPreviousThrow = "--- End of stack trace from previous location where exception was thrown ---";
- public const string Exception_WasThrown = "Exception of type '{0}' was thrown.";
- public const string ExecutionContext_ExceptionInAsyncLocalNotification = "An exception was not handled in an AsyncLocal<T> notification callback.";
- public const string FieldAccess_InitOnly = "InitOnly (aka ReadOnly) fields can only be initialized in the type/instance constructor.";
- public const string FileNotFound_ResolveAssembly = "Could not resolve assembly '{0}'.";
- public const string Format_AttributeUsage = "Duplicate AttributeUsageAttribute found on attribute type {0}.";
- public const string Format_Bad7BitInt32 = "Too many bytes in what should have been a 7 bit encoded Int32.";
- public const string Format_BadBase = "Invalid digits for the specified base.";
- public const string Format_BadBase64Char = "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.";
- public const string Format_BadBase64CharArrayLength = "Invalid length for a Base-64 char array or string.";
- public const string Format_BadBoolean = "String '{0}' was not recognized as a valid Boolean.";
- public const string Format_BadDatePattern = "Could not determine the order of year, month, and date from '{0}'.";
- public const string Format_BadDateTime = "String '{0}' was not recognized as a valid DateTime.";
- public const string Format_BadDateTimeCalendar = "The DateTime represented by the string '{0}' is not supported in calendar '{1}'.";
- public const string Format_BadDayOfWeek = "String '{0}' was not recognized as a valid DateTime because the day of week was incorrect.";
- public const string Format_BadFormatSpecifier = "Format specifier '{0}' was invalid.";
- public const string Format_NoFormatSpecifier = "No format specifiers were provided.";
- public const string Format_BadQuote = "Cannot find a matching quote character for the character '{0}'.";
- public const string Format_BadTimeSpan = "String '{0}' was not recognized as a valid TimeSpan.";
- public const string Format_DateOutOfRange = "The DateTime represented by the string '{0}' is out of range.";
- public const string Format_EmptyInputString = "Input string was either empty or contained only whitespace.";
- public const string Format_ExtraJunkAtEnd = "Additional non-parsable characters are at the end of the string.";
- public const string Format_GuidBrace = "Expected {0xdddddddd, etc}.";
- public const string Format_GuidBraceAfterLastNumber = "Could not find a brace, or the length between the previous token and the brace was zero (i.e., '0x,'etc.).";
- public const string Format_GuidComma = "Could not find a comma, or the length between the previous token and the comma was zero (i.e., '0x,'etc.).";
- public const string Format_GuidDashes = "Dashes are in the wrong position for GUID parsing.";
- public const string Format_GuidEndBrace = "Could not find the ending brace.";
- public const string Format_GuidHexPrefix = "Expected 0x prefix.";
- public const string Format_GuidInvalidChar = "Guid string should only contain hexadecimal characters.";
- public const string Format_GuidInvLen = "Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).";
- public const string Format_GuidUnrecognized = "Unrecognized Guid format.";
- public const string Format_IndexOutOfRange = "Index (zero based) must be greater than or equal to zero and less than the size of the argument list.";
- public const string Format_InvalidEnumFormatSpecification = "Format string can be only \"G\", \"g\", \"X\", \"x\", \"F\", \"f\", \"D\" or \"d\".";
- public const string Format_InvalidGuidFormatSpecification = "Format string can be only \"D\", \"d\", \"N\", \"n\", \"P\", \"p\", \"B\", \"b\", \"X\" or \"x\".";
- public const string Format_InvalidString = "Input string was not in a correct format.";
- public const string Format_MissingIncompleteDate = "There must be at least a partial date with a year present in the input string '{0}'.";
- public const string Format_NeedSingleChar = "String must be exactly one character long.";
- public const string Format_NoParsibleDigits = "Could not find any recognizable digits.";
- public const string Format_OffsetOutOfRange = "The time zone offset of string '{0}' must be within plus or minus 14 hours.";
- public const string Format_RepeatDateTimePattern = "DateTime pattern '{0}' appears more than once with different values.";
- public const string Format_StringZeroLength = "String cannot have zero length.";
- public const string Format_UnknownDateTimeWord = "The string '{0}' was not recognized as a valid DateTime. There is an unknown word starting at index '{1}'.";
- public const string Format_UTCOutOfRange = "The UTC representation of the date '{0}' falls outside the year range 1-9999.";
- public const string Globalization_cp_1200 = "Unicode";
- public const string Globalization_cp_12000 = "Unicode (UTF-32)";
- public const string Globalization_cp_12001 = "Unicode (UTF-32 Big-Endian)";
- public const string Globalization_cp_1201 = "Unicode (Big-Endian)";
- public const string Globalization_cp_20127 = "US-ASCII";
- public const string Globalization_cp_28591 = "Western European (ISO)";
- public const string Globalization_cp_65000 = "Unicode (UTF-7)";
- public const string Globalization_cp_65001 = "Unicode (UTF-8)";
- public const string IndexOutOfRange_ArrayRankIndex = "Array does not have that many dimensions.";
- public const string IndexOutOfRange_UMSPosition = "Unmanaged memory stream position was beyond the capacity of the stream.";
- public const string InsufficientMemory_MemFailPoint = "Insufficient available memory to meet the expected demands of an operation at this time. Please try again later.";
- public const string InsufficientMemory_MemFailPoint_TooBig = "Insufficient memory to meet the expected demands of an operation, and this system is likely to never satisfy this request. If this is a 32 bit system, consider booting in 3 GB mode.";
- public const string InsufficientMemory_MemFailPoint_VAFrag = "Insufficient available memory to meet the expected demands of an operation at this time, possibly due to virtual address space fragmentation. Please try again later.";
- public const string Interop_COM_TypeMismatch = "Type mismatch between source and destination types.";
- public const string Interop_Marshal_Unmappable_Char = "Cannot marshal: Encountered unmappable character.";
- public const string InvalidCast_CannotCastNullToValueType = "Null object cannot be converted to a value type.";
- public const string InvalidCast_CannotCoerceByRefVariant = "Object cannot be coerced to the original type of the ByRef VARIANT it was obtained from.";
- public const string InvalidCast_DBNull = "Object cannot be cast to DBNull.";
- public const string InvalidCast_DownCastArrayElement = "At least one element in the source array could not be cast down to the destination array type.";
- public const string InvalidCast_Empty = "Object cannot be cast to Empty.";
- public const string InvalidCast_FromDBNull = "Object cannot be cast from DBNull to other types.";
- public const string InvalidCast_FromTo = "Invalid cast from '{0}' to '{1}'.";
- public const string InvalidCast_IConvertible = "Object must implement IConvertible.";
- public const string InvalidCast_OATypeMismatch = "OleAut reported a type mismatch.";
- public const string InvalidCast_StoreArrayElement = "Object cannot be stored in an array of this type.";
- public const string InvalidCast_WinRTIPropertyValueArrayCoersion = "Object in an IPropertyValue is of type '{0}' which cannot be convereted to a '{1}' due to array element '{2}': {3}.";
- public const string InvalidCast_WinRTIPropertyValueCoersion = "Object in an IPropertyValue is of type '{0}' with value '{1}', which cannot be converted to a '{2}'.";
- public const string InvalidCast_WinRTIPropertyValueElement = "Object in an IPropertyValue is of type '{0}', which cannot be converted to a '{1}'.";
- public const string InvalidOperation_AsyncFlowCtrlCtxMismatch = "AsyncFlowControl objects can be used to restore flow only on a Context that had its flow suppressed.";
- public const string InvalidOperation_AsyncIOInProgress = "The stream is currently in use by a previous operation on the stream.";
- public const string InvalidOperation_BadEmptyMethodBody = "Method '{0}' does not have a method body.";
- public const string InvalidOperation_BadILGeneratorUsage = "ILGenerator usage is invalid.";
- public const string InvalidOperation_BadInstructionOrIndexOutOfBound = "MSIL instruction is invalid or index is out of bounds.";
- public const string InvalidOperation_BadInterfaceNotAbstract = "Interface must be declared abstract.";
- public const string InvalidOperation_BadMethodBody = "Method '{0}' cannot have a method body.";
- public const string InvalidOperation_BadTypeAttributesNotAbstract = "Type must be declared abstract if any of its methods are abstract.";
- public const string InvalidOperation_CalledTwice = "The method cannot be called twice on the same instance.";
- public const string InvalidOperation_CannotImportGlobalFromDifferentModule = "Unable to import a global method or field from a different module.";
- public const string InvalidOperation_CannotRegisterSecondResolver = "A resolver is already set for the assembly.";
- public const string InvalidOperation_CannotRemoveLastFromEmptyCollection = "Cannot remove the last element from an empty collection.";
- public const string InvalidOperation_CannotRestoreUnsupressedFlow = "Cannot restore context flow when it is not suppressed.";
- public const string InvalidOperation_CannotSupressFlowMultipleTimes = "Context flow is already suppressed.";
- public const string InvalidOperation_CannotUseAFCMultiple = "AsyncFlowControl object can be used only once to call Undo().";
- public const string InvalidOperation_CannotUseAFCOtherThread = "AsyncFlowControl object must be used on the thread where it was created.";
- public const string InvalidOperation_CantInstantiateAbstractClass = "Instances of abstract classes cannot be created.";
- public const string InvalidOperation_CantInstantiateFunctionPointer = "Instances of function pointers cannot be created.";
- public const string InvalidOperation_CollectionBackingDictionaryTooLarge = "The collection backing this Dictionary contains too many elements.";
- public const string InvalidOperation_CollectionBackingListTooLarge = "The collection backing this List contains too many elements.";
- public const string InvalidOperation_CollectionCorrupted = "A prior operation on this collection was interrupted by an exception. Collection's state is no longer trusted.";
- public const string InvalidOperation_ComputerName = "Computer name could not be obtained.";
- public const string InvalidOperation_ConcurrentOperationsNotSupported = "Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.";
- public const string InvalidOperation_ConstructorNotAllowedOnInterface = "Interface cannot have constructors.";
- public const string InvalidOperation_DateTimeParsing = "Internal Error in DateTime and Calendar operations.";
- public const string InvalidOperation_DebuggerLaunchFailed = "Debugger unable to launch.";
- public const string InvalidOperation_DefaultConstructorILGen = "Unable to access ILGenerator on a constructor created with DefineDefaultConstructor.";
- public const string InvalidOperation_EndReadCalledMultiple = "EndRead can only be called once for each asynchronous operation.";
- public const string InvalidOperation_EndWriteCalledMultiple = "EndWrite can only be called once for each asynchronous operation.";
- public const string InvalidOperation_EnumEnded = "Enumeration already finished.";
- public const string InvalidOperation_EnumFailedVersion = "Collection was modified; enumeration operation may not execute.";
- public const string InvalidOperation_EnumNotStarted = "Enumeration has not started. Call MoveNext.";
- public const string InvalidOperation_EnumOpCantHappen = "Enumeration has either not started or has already finished.";
- public const string InvalidOperation_EventInfoNotAvailable = "This API does not support EventInfo tokens.";
- public const string InvalidOperation_EventTokenTableRequiresDelegate = "Type '{0}' is not a delegate type. EventTokenTable may only be used with delegate types.";
- public const string InvalidOperation_GenericParametersAlreadySet = "The generic parameters are already defined on this MethodBuilder.";
- public const string InvalidOperation_GetVersion = "OSVersion's call to GetVersionEx failed.";
- public const string InvalidOperation_GlobalsHaveBeenCreated = "Type definition of the global function has been completed.";
- public const string InvalidOperation_HandleIsNotInitialized = "Handle is not initialized.";
- public const string InvalidOperation_HandleIsNotPinned = "Handle is not pinned.";
- public const string InvalidOperation_HashInsertFailed = "Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.";
- public const string InvalidOperation_IComparerFailed = "Failed to compare two elements in the array.";
- public const string InvalidOperation_MethodBaked = "Type definition of the method is complete.";
- public const string InvalidOperation_MethodBuilderBaked = "The signature of the MethodBuilder can no longer be modified because an operation on the MethodBuilder caused the methodDef token to be created. For example, a call to SetCustomAttribute requires the methodDef token to emit the CustomAttribute token.";
- public const string InvalidOperation_MethodHasBody = "Method already has a body.";
- public const string InvalidOperation_MustCallInitialize = "You must call Initialize on this object instance before using it.";
- public const string InvalidOperation_NativeOverlappedReused = "NativeOverlapped cannot be reused for multiple operations.";
- public const string InvalidOperation_NoMultiModuleAssembly = "You cannot have more than one dynamic module in each dynamic assembly in this version of the runtime.";
- public const string InvalidOperation_NoPublicAddMethod = "Cannot add the event handler since no public add method exists for the event.";
- public const string InvalidOperation_NoPublicRemoveMethod = "Cannot remove the event handler since no public remove method exists for the event.";
- public const string InvalidOperation_NotADebugModule = "Not a debug ModuleBuilder.";
- public const string InvalidOperation_NotAllowedInDynamicMethod = "The requested operation is invalid for DynamicMethod.";
- public const string InvalidOperation_NotAVarArgCallingConvention = "Calling convention must be VarArgs.";
- public const string InvalidOperation_NotGenericType = "This operation is only valid on generic types.";
- public const string InvalidOperation_NotSupportedOnWinRTEvent = "Adding or removing event handlers dynamically is not supported on WinRT events.";
- public const string InvalidOperation_NotWithConcurrentGC = "This API is not available when the concurrent GC is enabled.";
- public const string InvalidOperation_NoUnderlyingTypeOnEnum = "Underlying type information on enumeration is not specified.";
- public const string InvalidOperation_NoValue = "Nullable object must have a value.";
- public const string InvalidOperation_NullArray = "The underlying array is null.";
- public const string InvalidOperation_NullContext = "Cannot call Set on a null context";
- public const string InvalidOperation_NullModuleHandle = "The requested operation is invalid when called on a null ModuleHandle.";
- public const string InvalidOperation_OpenLocalVariableScope = "Local variable scope was not properly closed.";
- public const string InvalidOperation_Overlapped_Pack = "Cannot pack a packed Overlapped again.";
- public const string InvalidOperation_PropertyInfoNotAvailable = "This API does not support PropertyInfo tokens.";
- public const string InvalidOperation_ReadOnly = "Instance is read-only.";
- public const string InvalidOperation_ResMgrBadResSet_Type = "'{0}': ResourceSet derived classes must provide a constructor that takes a String file name and a constructor that takes a Stream.";
- public const string InvalidOperation_ResourceNotStream_Name = "Resource '{0}' was not a Stream - call GetObject instead.";
- public const string InvalidOperation_ResourceNotString_Name = "Resource '{0}' was not a String - call GetObject instead.";
- public const string InvalidOperation_ResourceNotString_Type = "Resource was of type '{0}' instead of String - call GetObject instead.";
- public const string InvalidOperation_SetData_OnlyOnce = "SetData can only be used to set the value of a given name once.";
- public const string InvalidOperation_SetLatencyModeNoGC = "The NoGCRegion mode is in progress.End it and then set a different mode.";
- public const string InvalidOperation_ShouldNotHaveMethodBody = "Method body should not exist.";
- public const string InvalidOperation_ThreadWrongThreadStart = "The thread was created with a ThreadStart delegate that does not accept a parameter.";
- public const string InvalidOperation_TimeoutsNotSupported = "Timeouts are not supported on this stream.";
- public const string InvalidOperation_TimerAlreadyClosed = "The Timer was already closed using an incompatible Dispose method.";
- public const string InvalidOperation_TypeCannotBeBoxed = "The given type cannot be boxed.";
- public const string InvalidOperation_TypeHasBeenCreated = "Unable to change after type has been created.";
- public const string InvalidOperation_TypeNotCreated = "Type has not been created.";
- public const string InvalidOperation_UnderlyingArrayListChanged = "This range in the underlying list is invalid. A possible cause is that elements were removed.";
- public const string InvalidOperation_UnknownEnumType = "Unknown enum type.";
- public const string InvalidOperation_WriteOnce = "This property has already been set and cannot be modified.";
- public const string InvalidOperation_WrongAsyncResultOrEndCalledMultiple = "Either the IAsyncResult object did not come from the corresponding async method on this type, or the End method was called multiple times with the same IAsyncResult.";
- public const string InvalidOperation_WrongAsyncResultOrEndReadCalledMultiple = "Either the IAsyncResult object did not come from the corresponding async method on this type, or EndRead was called multiple times with the same IAsyncResult.";
- public const string InvalidOperation_WrongAsyncResultOrEndWriteCalledMultiple = "Either the IAsyncResult object did not come from the corresponding async method on this type, or EndWrite was called multiple times with the same IAsyncResult.";
- public const string InvalidProgram_Default = "Common Language Runtime detected an invalid program.";
- public const string InvalidTimeZone_InvalidFileData = "The time zone ID '{0}' was found on the local computer, but the file at '{1}' was corrupt.";
- public const string InvalidTimeZone_InvalidRegistryData = "The time zone ID '{0}' was found on the local computer, but the registry information was corrupt.";
- public const string InvalidTimeZone_InvalidJulianDay = "Invalid Julian day in POSIX strings.";
- public const string InvalidTimeZone_NJulianDayNotSupported = "Julian n day in POSIX strings is not supported.";
- public const string InvalidTimeZone_NoTTInfoStructures = "There are no ttinfo structures in the tzfile. At least one ttinfo structure is required in order to construct a TimeZoneInfo object.";
- public const string InvalidTimeZone_UnparseablePosixMDateString = "'{0}' is not a valid POSIX-TZ-environment-variable MDate rule. A valid rule has the format 'Mm.w.d'.";
- public const string InvariantFailed = "Invariant failed.";
- public const string InvariantFailed_Cnd = "Invariant failed: {0}";
- public const string IO_DriveNotFound_Drive = "Could not find the drive '{0}'. The drive might not be ready or might not be mapped.";
- public const string IO_EOF_ReadBeyondEOF = "Unable to read beyond the end of the stream.";
- public const string IO_FileLoad = "Could not load the specified file.";
- public const string IO_FileName_Name = "File name: '{0}'";
- public const string IO_FileNotFound = "Unable to find the specified file.";
- public const string IO_FileNotFound_FileName = "Could not find file '{0}'.";
- public const string IO_AlreadyExists_Name = "Cannot create '{0}' because a file or directory with the same name already exists.";
- public const string IO_BindHandleFailed = "BindHandle for ThreadPool failed on this handle.";
- public const string IO_FileExists_Name = "The file '{0}' already exists.";
- public const string IO_FileStreamHandlePosition = "The OS handle's position is not what FileStream expected. Do not use a handle simultaneously in one FileStream and in Win32 code or another FileStream. This may cause data loss.";
- public const string IO_FileTooLong2GB = "The file is too long. This operation is currently limited to supporting files less than 2 gigabytes in size.";
- public const string IO_FileTooLongOrHandleNotSync = "IO operation will not work. Most likely the file will become too long or the handle was not opened to support synchronous IO operations.";
- public const string IO_FixedCapacity = "Unable to expand length of this stream beyond its capacity.";
- public const string IO_InvalidStringLen_Len = "BinaryReader encountered an invalid string length of {0} characters.";
- public const string IO_SeekAppendOverwrite = "Unable seek backward to overwrite data that previously existed in a file opened in Append mode.";
- public const string IO_SeekBeforeBegin = "An attempt was made to move the position before the beginning of the stream.";
- public const string IO_SetLengthAppendTruncate = "Unable to truncate data that previously existed in a file opened in Append mode.";
- public const string IO_SharingViolation_File = "The process cannot access the file '{0}' because it is being used by another process.";
- public const string IO_SharingViolation_NoFileName = "The process cannot access the file because it is being used by another process.";
- public const string IO_StreamTooLong = "Stream was too long.";
- public const string IO_PathNotFound_NoPathName = "Could not find a part of the path.";
- public const string IO_PathNotFound_Path = "Could not find a part of the path '{0}'.";
- public const string IO_PathTooLong = "The specified file name or path is too long, or a component of the specified path is too long.";
- public const string IO_PathTooLong_Path = "The path '{0}' is too long, or a component of the specified path is too long.";
- public const string IO_UnknownFileName = "[Unknown]";
- public const string Lazy_CreateValue_NoParameterlessCtorForT = "The lazily-initialized type does not have a public, parameterless constructor.";
- public const string Lazy_ctor_ModeInvalid = "The mode argument specifies an invalid value.";
- public const string Lazy_StaticInit_InvalidOperation = "ValueFactory returned null.";
- public const string Lazy_ToString_ValueNotCreated = "Value is not created.";
- public const string Lazy_Value_RecursiveCallsToValue = "ValueFactory attempted to access the Value property of this instance.";
- public const string Loader_ContextPolicies = "Context Policies:";
- public const string Loader_Name = "Name:";
- public const string Loader_NoContextPolicies = "There are no context policies.";
- public const string ManualResetEventSlim_ctor_SpinCountOutOfRange = "The spinCount argument must be in the range 0 to {0}, inclusive.";
- public const string ManualResetEventSlim_ctor_TooManyWaiters = "There are too many threads currently waiting on the event. A maximum of {0} waiting threads are supported.";
- public const string ManualResetEventSlim_Disposed = "The event has been disposed.";
- public const string Marshaler_StringTooLong = "Marshaler restriction: Excessively long string.";
- public const string MissingConstructor_Name = "Constructor on type '{0}' not found.";
- public const string MissingField = "Field not found.";
- public const string MissingField_Name = "Field '{0}' not found.";
- public const string MissingManifestResource_LooselyLinked = "Could not find a manifest resource entry called \"{0}\" in assembly \"{1}\". Please check spelling, capitalization, and build rules to ensure \"{0}\" is being linked into the assembly.";
- public const string MissingManifestResource_MultipleBlobs = "A case-insensitive lookup for resource file \"{0}\" in assembly \"{1}\" found multiple entries. Remove the duplicates or specify the exact case.";
- public const string MissingManifestResource_NoNeutralAsm = "Could not find any resources appropriate for the specified culture or the neutral culture. Make sure \"{0}\" was correctly embedded or linked into assembly \"{1}\" at compile time, or that all the satellite assemblies required are loadable and fully signed.";
- public const string MissingManifestResource_NoNeutralDisk = "Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.";
- public const string MissingManifestResource_NoPRIresources = "Unable to open Package Resource Index.";
- public const string MissingManifestResource_ResWFileNotLoaded = "Unable to load resources for resource file \"{0}\" in package \"{1}\".";
- public const string MissingMember = "Member not found.";
- public const string MissingMember_Name = "Member '{0}' not found.";
- public const string MissingMemberNestErr = "TypedReference can only be made on nested value Types.";
- public const string MissingMemberTypeRef = "FieldInfo does not match the target Type.";
- public const string MissingMethod_Name = "Method '{0}' not found.";
- public const string MissingSatelliteAssembly_Culture_Name = "The satellite assembly named \"{1}\" for fallback culture \"{0}\" either could not be found or could not be loaded. This is generally a setup problem. Please consider reinstalling or repairing the application.";
- public const string MissingSatelliteAssembly_Default = "Resource lookup fell back to the ultimate fallback resources in a satellite assembly, but that satellite either was not found or could not be loaded. Please consider reinstalling or repairing the application.";
- public const string Multicast_Combine = "Delegates that are not of type MulticastDelegate may not be combined.";
- public const string MustUseCCRewrite = "An assembly (probably \"{1}\") must be rewritten using the code contracts binary rewriter (CCRewrite) because it is calling Contract.{0} and the CONTRACTS_FULL symbol is defined. Remove any explicit definitions of the CONTRACTS_FULL symbol from your project and rebuild. CCRewrite can be downloaded from http://go.microsoft.com/fwlink/?LinkID=169180. \\r\\nAfter the rewriter is installed, it can be enabled in Visual Studio from the project's Properties page on the Code Contracts pane. Ensure that \"Perform Runtime Contract Checking\" is enabled, which will define CONTRACTS_FULL.";
- public const string NotImplemented_ResourcesLongerThanInt64Max = "Resource files longer than 2^63 bytes are not currently implemented.";
- public const string NotSupported_AbstractNonCLS = "This non-CLS method is not implemented.";
- public const string NotSupported_ActivAttr = "Activation Attributes are not supported.";
- public const string NotSupported_AppX = "{0} is not supported in AppX.";
- public const string NotSupported_AssemblyLoadFromHash = "Assembly.LoadFrom with hashValue is not supported.";
- public const string NotSupported_ByRefLike = "Cannot create boxed ByRef-like values.";
- public const string NotSupported_ByRefLikeArray = "Cannot create arrays of ByRef-like values.";
- public const string NotSupported_ByRefToByRefLikeReturn = "ByRef to ByRef-like return values are not supported in reflection invocation.";
- public const string NotSupported_ByRefToVoidReturn = "ByRef to void return values are not supported in reflection invocation.";
- public const string NotSupported_CallToVarArg = "Vararg calling convention not supported.";
- public const string NotSupported_CannotCallEqualsOnSpan = "Equals() on Span and ReadOnlySpan is not supported. Use operator== instead.";
- public const string NotSupported_CannotCallGetHashCodeOnSpan = "GetHashCode() on Span and ReadOnlySpan is not supported.";
- public const string NotSupported_ChangeType = "ChangeType operation is not supported.";
- public const string NotSupported_CollectibleAssemblyResolve = "Resolving to a collectible assembly is not supported.";
- public const string NotSupported_CollectibleBoundNonCollectible = "A non-collectible assembly may not reference a collectible assembly.";
- public const string NotSupported_CollectibleWinRT = "WinRT Interop is not supported for collectible types.";
- public const string NotSupported_CreateInstanceWithTypeBuilder = "CreateInstance cannot be used with an object of type TypeBuilder.";
- public const string NotSupported_DBNullSerial = "Only one DBNull instance may exist, and calls to DBNull deserialization methods are not allowed.";
- public const string NotSupported_DelegateMarshalToWrongDomain = "Delegates cannot be marshaled from native code into a domain other than their home domain.";
- public const string NotSupported_DelegateSerHolderSerial = "DelegateSerializationHolder objects are designed to represent a delegate during serialization and are not serializable themselves.";
- public const string NotSupported_DynamicAssembly = "The invoked member is not supported in a dynamic assembly.";
- public const string NotSupported_DynamicMethodFlags = "Wrong MethodAttributes or CallingConventions for DynamicMethod. Only public, static, standard supported";
- public const string NotSupported_DynamicModule = "The invoked member is not supported in a dynamic module.";
- public const string NotSupported_FileStreamOnNonFiles = "FileStream was asked to open a device that was not a file. For support for devices like 'com1:' or 'lpt1:', call CreateFile, then use the FileStream constructors that take an OS handle as an IntPtr.";
- public const string NotSupported_FixedSizeCollection = "Collection was of a fixed size.";
- public const string NotSupported_GenericMethod = "Generic methods with NativeCallableAttribute are not supported.";
- public const string NotSupported_GlobalMethodSerialization = "Serialization of global methods (including implicit serialization via the use of asynchronous delegates) is not supported.";
- public const string NotSupported_IDispInvokeDefaultMemberWithNamedArgs = "Invoking default method with named arguments is not supported.";
- public const string NotSupported_IllegalOneByteBranch = "Illegal one-byte branch at position: {0}. Requested branch was: {1}.";
- public const string NotSupported_KeyCollectionSet = "Mutating a key collection derived from a dictionary is not allowed.";
- public const string NotSupported_ManagedActivation = "Cannot create uninitialized instances of types requiring managed activation.";
- public const string NotSupported_MaxWaitHandles = "The number of WaitHandles must be less than or equal to 64.";
- public const string NotSupported_MemStreamNotExpandable = "Memory stream is not expandable.";
- public const string NotSupported_MustBeModuleBuilder = "Module argument must be a ModuleBuilder.";
- public const string NotSupported_NativeCallableTarget = "Methods with NativeCallableAttribute cannot be used as delegate target.";
- public const string NotSupported_NoCodepageData = "No data is available for encoding {0}. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.";
- public const string NotSupported_NonBlittableTypes = "Non-blittable parameter types are not supported for NativeCallable methods.";
- public const string NotSupported_NonReflectedType = "Not supported in a non-reflected type.";
- public const string NotSupported_NonStaticMethod = "Non-static methods with NativeCallableAttribute are not supported.";
- public const string NotSupported_NoParentDefaultConstructor = "Parent does not have a default constructor. The default constructor must be explicitly defined.";
- public const string NotSupported_NoTypeInfo = "Cannot resolve {0} to a TypeInfo object.";
- public const string NotSupported_NYI = "This feature is not currently implemented.";
- public const string NotSupported_ObsoleteResourcesFile = "Found an obsolete .resources file in assembly '{0}'. Rebuild that .resources file then rebuild that assembly.";
- public const string NotSupported_OleAutBadVarType = "The given Variant type is not supported by this OleAut function.";
- public const string NotSupported_OpenType = "Cannot create arrays of open type.";
- public const string NotSupported_OutputStreamUsingTypeBuilder = "Output streams do not support TypeBuilders.";
- public const string NotSupported_PIAInAppxProcess = "A Primary Interop Assembly is not supported in AppX.";
- public const string NotSupported_RangeCollection = "The specified operation is not supported on Ranges.";
- public const string NotSupported_Reading = "Accessor does not support reading.";
- public const string NotSupported_ReadOnlyCollection = "Collection is read-only.";
- public const string NotSupported_ResourceObjectSerialization = "Cannot read resources that depend on serialization.";
- public const string NotSupported_SignalAndWaitSTAThread = "SignalAndWait on a STA thread is not supported.";
- public const string NotSupported_StringComparison = "The string comparison type passed in is currently not supported.";
- public const string NotSupported_SubclassOverride = "Derived classes must provide an implementation.";
- public const string NotSupported_SymbolMethod = "Not supported in an array method of a type definition that is not complete.";
- public const string NotSupported_TooManyArgs = "Stack size too deep. Possibly too many arguments.";
- public const string NotSupported_Type = "Type is not supported.";
- public const string NotSupported_TypeCannotDeserialized = "Direct deserialization of type '{0}' is not supported.";
- public const string NotSupported_TypeNotYetCreated = "The invoked member is not supported before the type is created.";
- public const string NotSupported_UmsSafeBuffer = "This operation is not supported for an UnmanagedMemoryStream created from a SafeBuffer.";
- public const string NotSupported_UnitySerHolder = "The UnitySerializationHolder object is designed to transmit information about other types and is not serializable itself.";
- public const string NotSupported_UnknownTypeCode = "TypeCode '{0}' was not valid.";
- public const string NotSupported_WaitAllSTAThread = "WaitAll for multiple handles on a STA thread is not supported.";
- public const string NotSupported_UnreadableStream = "Stream does not support reading.";
- public const string NotSupported_UnseekableStream = "Stream does not support seeking.";
- public const string NotSupported_UnwritableStream = "Stream does not support writing.";
- public const string NotSupported_ValueClassCM = "Custom marshalers for value types are not currently supported.";
- public const string NotSupported_ValueCollectionSet = "Mutating a value collection derived from a dictionary is not allowed.";
- public const string NotSupported_VoidArray = "Arrays of System.Void are not supported.";
- public const string NotSupported_WinRT_PartialTrust = "Windows Runtime is not supported in partial trust.";
- public const string NotSupported_Writing = "Accessor does not support writing.";
- public const string NotSupported_WrongResourceReader_Type = "This .resources file should not be read with this reader. The resource reader type is \"{0}\".";
- public const string NullReference_This = "The pointer for this method was null.";
- public const string ObjectDisposed_FileClosed = "Cannot access a closed file.";
- public const string ObjectDisposed_Generic = "Cannot access a disposed object.";
- public const string ObjectDisposed_ObjectName_Name = "Object name: '{0}'.";
- public const string ObjectDisposed_WriterClosed = "Cannot write to a closed TextWriter.";
- public const string ObjectDisposed_ReaderClosed = "Cannot read from a closed TextReader.";
- public const string ObjectDisposed_ResourceSet = "Cannot access a closed resource set.";
- public const string ObjectDisposed_StreamClosed = "Cannot access a closed Stream.";
- public const string ObjectDisposed_ViewAccessorClosed = "Cannot access a closed accessor.";
- public const string ObjectDisposed_SafeHandleClosed = "Safe handle has been closed.";
- public const string OperationCanceled = "The operation was canceled.";
- public const string OutOfMemory_GCHandleMDA = "The GCHandle MDA has run out of available cookies.";
- public const string Overflow_Byte = "Value was either too large or too small for an unsigned byte.";
- public const string Overflow_Char = "Value was either too large or too small for a character.";
- public const string Overflow_Currency = "Value was either too large or too small for a Currency.";
- public const string Overflow_Decimal = "Value was either too large or too small for a Decimal.";
- public const string Overflow_Duration = "The duration cannot be returned for TimeSpan.MinValue because the absolute value of TimeSpan.MinValue exceeds the value of TimeSpan.MaxValue.";
- public const string Overflow_Int16 = "Value was either too large or too small for an Int16.";
- public const string Overflow_Int32 = "Value was either too large or too small for an Int32.";
- public const string Overflow_Int64 = "Value was either too large or too small for an Int64.";
- public const string Overflow_NegateTwosCompNum = "Negating the minimum value of a twos complement number is invalid.";
- public const string Overflow_NegativeUnsigned = "The string was being parsed as an unsigned number and could not have a negative sign.";
- public const string Overflow_SByte = "Value was either too large or too small for a signed byte.";
- public const string Overflow_TimeSpanElementTooLarge = "The TimeSpan string '{0}' could not be parsed because at least one of the numeric components is out of range or contains too many digits.";
- public const string Overflow_TimeSpanTooLong = "TimeSpan overflowed because the duration is too long.";
- public const string Overflow_UInt16 = "Value was either too large or too small for a UInt16.";
- public const string Overflow_UInt32 = "Value was either too large or too small for a UInt32.";
- public const string Overflow_UInt64 = "Value was either too large or too small for a UInt64.";
- public const string PlatformNotSupported_ArgIterator = "ArgIterator is not supported on this platform.";
- public const string PlatformNotSupported_ComInterop = "COM Interop is not supported on this platform.";
- public const string PlatformNotSupported_NamedSynchronizationPrimitives = "The named version of this synchronization primitive is not supported on this platform.";
- public const string PlatformNotSupported_NamedSyncObjectWaitAnyWaitAll = "Wait operations on multiple wait handles including a named synchronization primitive are not supported on this platform.";
- public const string PlatformNotSupported_OSXFileLocking = "Locking/unlocking file regions is not supported on this platform. Use FileShare on the entire file instead.";
- public const string PlatformNotSupported_ReflectionOnly = "ReflectionOnly loading is not supported on this platform.";
- public const string PlatformNotSupported_Remoting = "Remoting is not supported on this platform.";
- public const string PlatformNotSupported_SecureBinarySerialization = "Secure binary serialization is not supported on this platform.";
- public const string PlatformNotSupported_StrongNameSigning = "Strong-name signing is not supported on this platform.";
- public const string PlatformNotSupported_WinRT = "Windows Runtime is not supported on this operating system.";
- public const string PlatformNotSupported_OverlappedIO = "This API is specific to the way in which Windows handles asynchronous I/O, and is not supported on this platform.";
- public const string PlatformNotSupported_ITypeInfo = "Marshalling a System.Type to an unmanaged ITypeInfo or marshalling an ITypeInfo to a System.Type is not supported on this platform.";
- public const string PlatformNotSupported_IExpando = "Marshalling an IDispatchEx to an IReflect or IExpando is not supported on this platform.";
- public const string PlatformNotSupported_AppDomains = "Secondary AppDomains are not supported on this platform.";
- public const string PlatformNotSupported_CAS = "Code Access Security is not supported on this platform.";
- public const string PlatformNotSupported_AppDomain_ResMon = "AppDomain resource monitoring is not supported on this platform.";
- public const string PlatformNotSupported_Principal = "Windows Principal functionality is not supported on this platform.";
- public const string PlatformNotSupported_ThreadAbort = "Thread abort is not supported on this platform.";
- public const string PlatformNotSupported_ThreadSuspend = "Thread suspend is not supported on this platform.";
- public const string Policy_CannotLoadSemiTrustAssembliesDuringInit = "All assemblies loaded as part of AppDomain initialization must be fully trusted.";
- public const string PostconditionFailed = "Postcondition failed.";
- public const string PostconditionFailed_Cnd = "Postcondition failed: {0}";
- public const string PostconditionOnExceptionFailed = "Postcondition failed after throwing an exception.";
- public const string PostconditionOnExceptionFailed_Cnd = "Postcondition failed after throwing an exception: {0}";
- public const string PreconditionFailed = "Precondition failed.";
- public const string PreconditionFailed_Cnd = "Precondition failed: {0}";
- public const string PersistedFiles_NoHomeDirectory = "The home directory of the current user could not be determined.";
- public const string Rank_MultiDimNotSupported = "Only single dimension arrays are supported here.";
- public const string Rank_MustMatch = "The specified arrays must have the same number of dimensions.";
- public const string ReflectionTypeLoad_LoadFailed = "Unable to load one or more of the requested types.";
- public const string ResourceReaderIsClosed = "ResourceReader is closed.";
- public const string Resources_StreamNotValid = "Stream is not a valid resource file.";
- public const string RFLCT_AmbigCust = "Multiple custom attributes of the same type found.";
- public const string RFLCT_Ambiguous = "Ambiguous match found.";
- public const string InvalidFilterCriteriaException_CritInt = "An Int32 must be provided for the filter criteria.";
- public const string InvalidFilterCriteriaException_CritString = "A String must be provided for the filter criteria.";
- public const string RFLCT_InvalidFieldFail = "'{0}' field specified was not found.";
- public const string RFLCT_InvalidPropFail = "'{0}' property specified was not found.";
- public const string RFLCT_Targ_ITargMismatch = "Object does not match target type.";
- public const string RFLCT_Targ_StatFldReqTarg = "Non-static field requires a target.";
- public const string RFLCT_Targ_StatMethReqTarg = "Non-static method requires a target.";
- public const string RuntimeWrappedException = "An object that does not derive from System.Exception has been wrapped in a RuntimeWrappedException.";
- public const string Security_CannotReadFileData = "The time zone ID '{0}' was found on the local computer, but the application does not have permission to read the file.";
- public const string Security_CannotReadRegistryData = "The time zone ID '{0}' was found on the local computer, but the application does not have permission to read the registry information.";
- public const string Security_RegistryPermission = "Requested registry access is not allowed.";
- public const string SemaphoreSlim_ctor_InitialCountWrong = "The initialCount argument must be non-negative and less than or equal to the maximumCount.";
- public const string SemaphoreSlim_ctor_MaxCountWrong = "The maximumCount argument must be a positive number. If a maximum is not required, use the constructor without a maxCount parameter.";
- public const string SemaphoreSlim_Disposed = "The semaphore has been disposed.";
- public const string SemaphoreSlim_Release_CountWrong = "The releaseCount argument must be greater than zero.";
- public const string SemaphoreSlim_Wait_TimeoutWrong = "The timeout must represent a value between -1 and Int32.MaxValue, inclusive.";
- public const string Serialization_BadParameterInfo = "Non existent ParameterInfo. Position bigger than member's parameters length.";
- public const string Serialization_CorruptField = "The value of the field '{0}' is invalid. The serialized data is corrupt.";
- public const string Serialization_DateTimeTicksOutOfRange = "Invalid serialized DateTime data. Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.";
- public const string Serialization_DelegatesNotSupported = "Serializing delegates is not supported on this platform.";
- public const string Serialization_InsufficientDeserializationState = "Insufficient state to deserialize the object. Missing field '{0}'. More information is needed.";
- public const string Serialization_InsufficientState = "Insufficient state to return the real object.";
- public const string Serialization_InvalidData = "An error occurred while deserializing the object. The serialized data is corrupt.";
- public const string Serialization_InvalidDelegateType = "Cannot serialize delegates over unmanaged function pointers, dynamic methods or methods outside the delegate creator's assembly.";
- public const string Serialization_InvalidEscapeSequence = "The serialized data contained an invalid escape sequence '\\\\{0}'.";
- public const string Serialization_InvalidFieldState = "Object fields may not be properly initialized.";
- public const string Serialization_InvalidOnDeser = "OnDeserialization method was called while the object was not being deserialized.";
- public const string Serialization_InvalidPtrValue = "An IntPtr or UIntPtr with an eight byte value cannot be deserialized on a machine with a four byte word size.";
- public const string Serialization_InvalidType = "Only system-provided types can be passed to the GetUninitializedObject method. '{0}' is not a valid instance of a type.";
- public const string Serialization_KeyValueDifferentSizes = "The keys and values arrays have different sizes.";
- public const string Serialization_MemberOutOfRange = "The deserialized value of the member \"{0}\" in the class \"{1}\" is out of range.";
- public const string Serialization_MemberTypeNotRecognized = "Unknown member type.";
- public const string Serialization_MissField = "Field {0} is missing.";
- public const string Serialization_MissingDateTimeData = "Invalid serialized DateTime data. Unable to find 'ticks' or 'dateData'.";
- public const string Serialization_MissingKeys = "The Keys for this Hashtable are missing.";
- public const string Serialization_MissingValues = "The values for this dictionary are missing.";
- public const string Serialization_NonSerType = "Type '{0}' in Assembly '{1}' is not marked as serializable.";
- public const string Serialization_NoParameterInfo = "Serialized member does not have a ParameterInfo.";
- public const string Serialization_NotFound = "Member '{0}' was not found.";
- public const string Serialization_NullKey = "One of the serialized keys is null.";
- public const string Serialization_NullSignature = "The method signature cannot be null.";
- public const string Serialization_OptionalFieldVersionValue = "Version value must be positive.";
- public const string Serialization_SameNameTwice = "Cannot add the same member twice to a SerializationInfo object.";
- public const string Serialization_StringBuilderCapacity = "The serialized Capacity property of StringBuilder must be positive, less than or equal to MaxCapacity and greater than or equal to the String length.";
- public const string Serialization_StringBuilderMaxCapacity = "The serialized MaxCapacity property of StringBuilder must be positive and greater than or equal to the String length.";
- public const string Serialization_UnableToFindModule = "The given module {0} cannot be found within the assembly {1}.";
- public const string Serialization_UnknownMember = "Cannot get the member '{0}'.";
- public const string SpinLock_Exit_SynchronizationLockException = "The calling thread does not hold the lock.";
- public const string SpinLock_IsHeldByCurrentThread = "Thread tracking is disabled.";
- public const string SpinLock_TryEnter_ArgumentOutOfRange = "The timeout must be a value between -1 and Int32.MaxValue, inclusive.";
- public const string SpinLock_TryEnter_LockRecursionException = "The calling thread already holds the lock.";
- public const string SpinLock_TryReliableEnter_ArgumentException = "The tookLock argument must be set to false before calling this method.";
- public const string SpinWait_SpinUntil_ArgumentNull = "The condition argument is null.";
- public const string SpinWait_SpinUntil_TimeoutWrong = "The timeout must represent a value between -1 and Int32.MaxValue, inclusive.";
- public const string StackTrace_InFileLineNumber = "in {0}:line {1}";
- public const string Task_ContinueWith_ESandLR = "The specified TaskContinuationOptions combined LongRunning and ExecuteSynchronously. Synchronous continuations should not be long running.";
- public const string Task_ContinueWith_NotOnAnything = "The specified TaskContinuationOptions excluded all continuation kinds.";
- public const string Task_Delay_InvalidDelay = "The value needs to translate in milliseconds to -1 (signifying an infinite timeout), 0 or a positive integer less than or equal to Int32.MaxValue.";
- public const string Task_Delay_InvalidMillisecondsDelay = "The value needs to be either -1 (signifying an infinite timeout), 0 or a positive integer.";
- public const string Task_Dispose_NotCompleted = "A task may only be disposed if it is in a completion state (RanToCompletion, Faulted or Canceled).";
- public const string Task_FromAsync_LongRunning = "It is invalid to specify TaskCreationOptions.LongRunning in calls to FromAsync.";
- public const string Task_FromAsync_PreferFairness = "It is invalid to specify TaskCreationOptions.PreferFairness in calls to FromAsync.";
- public const string Task_MultiTaskContinuation_EmptyTaskList = "The tasks argument contains no tasks.";
- public const string Task_MultiTaskContinuation_FireOptions = "It is invalid to exclude specific continuation kinds for continuations off of multiple tasks.";
- public const string Task_MultiTaskContinuation_NullTask = "The tasks argument included a null value.";
- public const string Task_RunSynchronously_AlreadyStarted = "RunSynchronously may not be called on a task that was already started.";
- public const string Task_RunSynchronously_Continuation = "RunSynchronously may not be called on a continuation task.";
- public const string Task_RunSynchronously_Promise = "RunSynchronously may not be called on a task not bound to a delegate, such as the task returned from an asynchronous method.";
- public const string Task_RunSynchronously_TaskCompleted = "RunSynchronously may not be called on a task that has already completed.";
- public const string Task_Start_AlreadyStarted = "Start may not be called on a task that was already started.";
- public const string Task_Start_ContinuationTask = "Start may not be called on a continuation task.";
- public const string Task_Start_Promise = "Start may not be called on a promise-style task.";
- public const string Task_Start_TaskCompleted = "Start may not be called on a task that has completed.";
- public const string Task_ThrowIfDisposed = "The task has been disposed.";
- public const string Task_WaitMulti_NullTask = "The tasks array included at least one null element.";
- public const string TaskCanceledException_ctor_DefaultMessage = "A task was canceled.";
- public const string TaskCompletionSourceT_TrySetException_NoExceptions = "The exceptions collection was empty.";
- public const string TaskCompletionSourceT_TrySetException_NullException = "The exceptions collection included at least one null element.";
- public const string TaskExceptionHolder_UnhandledException = "A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.";
- public const string TaskExceptionHolder_UnknownExceptionType = "(Internal)Expected an Exception or an IEnumerable<Exception>";
- public const string TaskScheduler_ExecuteTask_WrongTaskScheduler = "ExecuteTask may not be called for a task which was previously queued to a different TaskScheduler.";
- public const string TaskScheduler_FromCurrentSynchronizationContext_NoCurrent = "The current SynchronizationContext may not be used as a TaskScheduler.";
- public const string TaskScheduler_InconsistentStateAfterTryExecuteTaskInline = "The TryExecuteTaskInline call to the underlying scheduler succeeded, but the task body was not invoked.";
- public const string TaskSchedulerException_ctor_DefaultMessage = "An exception was thrown by a TaskScheduler.";
- public const string TaskT_DebuggerNoResult = "{Not yet computed}";
- public const string TaskT_TransitionToFinal_AlreadyCompleted = "An attempt was made to transition a task to a final state when it had already completed.";
- public const string Thread_ApartmentState_ChangeFailed = "Failed to set the specified COM apartment state.";
- public const string Thread_GetSetCompressedStack_NotSupported = "Use CompressedStack.(Capture/Run) instead.";
- public const string Thread_Operation_RequiresCurrentThread = "This operation must be performed on the same thread as that represented by the Thread instance.";
- public const string Threading_AbandonedMutexException = "The wait completed due to an abandoned mutex.";
- public const string Threading_WaitHandleCannotBeOpenedException = "No handle of the given name exists.";
- public const string Threading_WaitHandleCannotBeOpenedException_InvalidHandle = "A WaitHandle with system-wide name '{0}' cannot be created. A WaitHandle of a different type might have the same name.";
- public const string Threading_WaitHandleTooManyPosts = "The WaitHandle cannot be signaled because it would exceed its maximum count.";
- public const string Threading_SemaphoreFullException = "Adding the specified count to the semaphore would cause it to exceed its maximum count.";
- public const string Threading_ThreadInterrupted = "Thread was interrupted from a waiting state.";
- public const string ThreadLocal_Disposed = "The ThreadLocal object has been disposed.";
- public const string ThreadLocal_Value_RecursiveCallsToValue = "ValueFactory attempted to access the Value property of this instance.";
- public const string ThreadLocal_ValuesNotAvailable = "The ThreadLocal object is not tracking values. To use the Values property, use a ThreadLocal constructor that accepts the trackAllValues parameter and set the parameter to true.";
- public const string TimeZoneNotFound_MissingData = "The time zone ID '{0}' was not found on the local computer.";
- public const string TypeInitialization_Default = "Type constructor threw an exception.";
- public const string TypeInitialization_Type = "The type initializer for '{0}' threw an exception.";
- public const string TypeLoad_ResolveNestedType = "Could not resolve nested type '{0}' in type \"{1}'.";
- public const string TypeLoad_ResolveType = "Could not resolve type '{0}'.";
- public const string TypeLoad_ResolveTypeFromAssembly = "Could not resolve type '{0}' in assembly '{1}'.";
- public const string UnauthorizedAccess_IODenied_NoPathName = "Access to the path is denied.";
- public const string UnauthorizedAccess_IODenied_Path = "Access to the path '{0}' is denied.";
- public const string UnauthorizedAccess_MemStreamBuffer = "MemoryStream's internal buffer cannot be accessed.";
- public const string UnauthorizedAccess_RegistryKeyGeneric_Key = "Access to the registry key '{0}' is denied.";
- public const string UnknownError_Num = "Unknown error \"{0}\".";
- public const string Verification_Exception = "Operation could destabilize the runtime.";
- public const string Word_At = "at";
- public const string DebugAssertBanner = "---- DEBUG ASSERTION FAILED ----";
- public const string DebugAssertLongMessage = "---- Assert Long Message ----";
- public const string DebugAssertShortMessage = "---- Assert Short Message ----";
- public const string LockRecursionException_ReadAfterWriteNotAllowed = "A read lock may not be acquired with the write lock held in this mode.";
- public const string LockRecursionException_RecursiveReadNotAllowed = "Recursive read lock acquisitions not allowed in this mode.";
- public const string LockRecursionException_RecursiveWriteNotAllowed = "Recursive write lock acquisitions not allowed in this mode.";
- public const string LockRecursionException_RecursiveUpgradeNotAllowed = "Recursive upgradeable lock acquisitions not allowed in this mode.";
- public const string LockRecursionException_WriteAfterReadNotAllowed = "Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Please ensure that read locks are released before taking a write lock. If an upgrade is necessary, use an upgrade lock in place of the read lock.";
- public const string SynchronizationLockException_MisMatchedUpgrade = "The upgradeable lock is being released without being held.";
- public const string SynchronizationLockException_MisMatchedRead = "The read lock is being released without being held.";
- public const string SynchronizationLockException_IncorrectDispose = "The lock is being disposed while still being used. It either is being held by a thread and/or has active waiters waiting to acquire the lock.";
- public const string LockRecursionException_UpgradeAfterReadNotAllowed = "Upgradeable lock may not be acquired with read lock held.";
- public const string LockRecursionException_UpgradeAfterWriteNotAllowed = "Upgradeable lock may not be acquired with write lock held in this mode. Acquiring Upgradeable lock gives the ability to read along with an option to upgrade to a writer.";
- public const string SynchronizationLockException_MisMatchedWrite = "The write lock is being released without being held.";
- public const string NotSupported_SignatureType = "This method is not supported on signature types.";
- public const string MemoryDisposed = "Memory<T> has been disposed.";
- public const string Memory_OutstandingReferences = "Release all references before disposing this instance.";
- public const string HashCode_HashCodeNotSupported = "HashCode is a mutable struct and should not be compared with other HashCodes. Use ToHashCode to retrieve the computed hash code.";
- public const string HashCode_EqualityNotSupported = "HashCode is a mutable struct and should not be compared with other HashCodes.";
- public const string Arg_TypeNotSupported = "Specified type is not supported";
- public const string IO_InvalidReadLength = "The read operation returned an invalid length.";
- public const string Arg_BasePathNotFullyQualified = "Basepath argument is not fully qualified.";
- public const string Arg_ElementsInSourceIsGreaterThanDestination = "Number of elements in source vector is greater than the destination array";
- public const string Arg_NullArgumentNullRef = "The method was called with a null array argument.";
- public const string Argument_CannotPrepareAbstract = "Abstract methods cannot be prepared.";
- public const string Argument_InvalidGenericInstantiation = "The given generic instantiation was invalid.";
- public const string Argument_OverlapAlignmentMismatch = "Overlapping spans have mismatching alignment.";
- public const string Arg_InsufficientNumberOfElements = "At least {0} element(s) are expected in the parameter \"{1}\".";
- public const string Arg_MustBeNullTerminatedString = "The string must be null-terminated.";
- public const string ArgumentOutOfRange_Week_ISO = "The week parameter must be in the range 1 through 53.";
- public const string Argument_BadPInvokeMethod = "PInvoke methods must be static and native and cannot be abstract.";
- public const string Argument_BadPInvokeOnInterface = "PInvoke methods cannot exist on interfaces.";
- public const string Argument_MethodRedefined = "Method has been already defined.";
- public const string Argument_CannotExtractScalar = "Cannot extract a Unicode scalar value from the specified index in the input.";
- public const string Argument_CannotParsePrecision = "Characters following the format symbol must be a number of {0} or less.";
- public const string Argument_GWithPrecisionNotSupported = "The 'G' format combined with a precision is not supported.";
- public const string Argument_PrecisionTooLarge = "Precision cannot be larger than {0}.";
- public const string AssemblyDependencyResolver_FailedToLoadHostpolicy = "Cannot load hostpolicy library. AssemblyDependencyResolver is currently only supported if the runtime is hosted through hostpolicy library.";
- public const string AssemblyDependencyResolver_FailedToResolveDependencies = "Dependency resolution failed for component {0} with error code {1}. Detailed error: {2}";
- public const string Arg_EnumNotCloneable = "The supplied object does not implement ICloneable.";
- public const string InvalidOp_InvalidNewEnumVariant = "The returned enumerator does not implement IEnumVARIANT.";
- public const string Argument_StructArrayTooLarge = "Array size exceeds addressing limitations.";
- public const string IndexOutOfRange_ArrayWithOffset = "ArrayWithOffset: offset exceeds array size.";
- public const string Serialization_DangerousDeserialization = "An action was attempted during deserialization that could lead to a security vulnerability. The action has been aborted.";
- public const string Serialization_DangerousDeserialization_Switch = "An action was attempted during deserialization that could lead to a security vulnerability. The action has been aborted. To allow the action, set the '{0}' AppContext switch to true.";
- public const string Arg_MustBeRuntimeAssembly = "Object must be of type RuntimeAssembly.";
- public const string InvalidOperation_SpanOverlappedOperation = "This operation is invalid on overlapping buffers.";
- public const string SetterHasNoParams = "Setter must have parameters.";
- public const string NotSupported_Overlapped = "This API is not supported on this platform.";
-}
diff --git a/netcore/System.Private.CoreLib/resources/Strings.resx b/netcore/System.Private.CoreLib/resources/Strings.resx
deleted file mode 100644
index ec16a896ff2..00000000000
--- a/netcore/System.Private.CoreLib/resources/Strings.resx
+++ /dev/null
@@ -1,3661 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<root>
- <!--
- Microsoft ResX Schema
-
- Version 2.0
-
- The primary goals of this format is to allow a simple XML format
- that is mostly human readable. The generation and parsing of the
- various data types are done through the TypeConverter classes
- associated with the data types.
-
- Example:
-
- ... ado.net/XML headers & schema ...
- <resheader name="resmimetype">text/microsoft-resx</resheader>
- <resheader name="version">2.0</resheader>
- <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
- <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
- <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
- <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
- <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
- <value>[base64 mime encoded serialized .NET Framework object]</value>
- </data>
- <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
- <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
- <comment>This is a comment</comment>
- </data>
-
- There are any number of "resheader" rows that contain simple
- name/value pairs.
-
- Each data row contains a name, and value. The row also contains a
- type or mimetype. Type corresponds to a .NET class that support
- text/value conversion through the TypeConverter architecture.
- Classes that don't support this are serialized and stored with the
- mimetype set.
-
- The mimetype is used for serialized objects, and tells the
- ResXResourceReader how to depersist the object. This is currently not
- extensible. For a given mimetype the value must be set accordingly:
-
- Note - application/x-microsoft.net.object.binary.base64 is the format
- that the ResXResourceWriter will generate, however the reader can
- read any of the formats listed below.
-
- mimetype: application/x-microsoft.net.object.binary.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.soap.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.bytearray.base64
- value : The object must be serialized into a byte array
- : using a System.ComponentModel.TypeConverter
- : and then encoded with base64 encoding.
- -->
- <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
- <xsd:element name="root" msdata:IsDataSet="true">
- <xsd:complexType>
- <xsd:choice maxOccurs="unbounded">
- <xsd:element name="metadata">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" />
- </xsd:sequence>
- <xsd:attribute name="name" use="required" type="xsd:string" />
- <xsd:attribute name="type" type="xsd:string" />
- <xsd:attribute name="mimetype" type="xsd:string" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="assembly">
- <xsd:complexType>
- <xsd:attribute name="alias" type="xsd:string" />
- <xsd:attribute name="name" type="xsd:string" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="data">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
- <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
- <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="resheader">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" />
- </xsd:complexType>
- </xsd:element>
- </xsd:choice>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
- <resheader name="resmimetype">
- <value>text/microsoft-resx</value>
- </resheader>
- <resheader name="version">
- <value>2.0</value>
- </resheader>
- <resheader name="reader">
- <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
- <resheader name="writer">
- <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
- <data name="Acc_CreateAbst" xml:space="preserve">
- <value>Cannot create an abstract class.</value>
- </data>
- <data name="Acc_CreateAbstEx" xml:space="preserve">
- <value>Cannot create an instance of {0} because it is an abstract class.</value>
- </data>
- <data name="Acc_CreateArgIterator" xml:space="preserve">
- <value>Cannot dynamically create an instance of ArgIterator.</value>
- </data>
- <data name="Acc_CreateGeneric" xml:space="preserve">
- <value>Cannot create a type for which Type.ContainsGenericParameters is true.</value>
- </data>
- <data name="Acc_CreateGenericEx" xml:space="preserve">
- <value>Cannot create an instance of {0} because Type.ContainsGenericParameters is true.</value>
- </data>
- <data name="Acc_CreateInterface" xml:space="preserve">
- <value>Cannot create an instance of an interface.</value>
- </data>
- <data name="Acc_CreateInterfaceEx" xml:space="preserve">
- <value>Cannot create an instance of {0} because it is an interface.</value>
- </data>
- <data name="Acc_CreateVoid" xml:space="preserve">
- <value>Cannot dynamically create an instance of System.Void.</value>
- </data>
- <data name="Acc_NotClassInit" xml:space="preserve">
- <value>Type initializer was not callable.</value>
- </data>
- <data name="Acc_ReadOnly" xml:space="preserve">
- <value>Cannot set a constant field.</value>
- </data>
- <data name="Access_Void" xml:space="preserve">
- <value>Cannot create an instance of void.</value>
- </data>
- <data name="AggregateException_ctor_DefaultMessage" xml:space="preserve">
- <value>One or more errors occurred.</value>
- </data>
- <data name="AggregateException_ctor_InnerExceptionNull" xml:space="preserve">
- <value>An element of innerExceptions was null.</value>
- </data>
- <data name="AggregateException_DeserializationFailure" xml:space="preserve">
- <value>The serialization stream contains no inner exceptions.</value>
- </data>
- <data name="AggregateException_InnerException" xml:space="preserve">
- <value>(Inner Exception #{0}) </value>
- <comment>This text is prepended to each inner exception description during aggregate exception formatting</comment>
- </data>
- <data name="AppDomain_AppBaseNotSet" xml:space="preserve">
- <value>The ApplicationBase must be set before retrieving this property.</value>
- </data>
- <data name="Arg_AccessException" xml:space="preserve">
- <value>Cannot access member.</value>
- </data>
- <data name="Arg_AccessViolationException" xml:space="preserve">
- <value>Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</value>
- </data>
- <data name="Arg_AmbiguousMatchException" xml:space="preserve">
- <value>Ambiguous match found.</value>
- </data>
- <data name="Arg_ApplicationException" xml:space="preserve">
- <value>Error in the application.</value>
- </data>
- <data name="Arg_ArgumentException" xml:space="preserve">
- <value>Value does not fall within the expected range.</value>
- </data>
- <data name="Arg_ArgumentOutOfRangeException" xml:space="preserve">
- <value>Specified argument was out of the range of valid values.</value>
- </data>
- <data name="Arg_ArithmeticException" xml:space="preserve">
- <value>Overflow or underflow in the arithmetic operation.</value>
- </data>
- <data name="Arg_ArrayLengthsDiffer" xml:space="preserve">
- <value>Array lengths must be the same.</value>
- </data>
- <data name="Arg_ArrayPlusOffTooSmall" xml:space="preserve">
- <value>Destination array is not long enough to copy all the items in the collection. Check array index and length.</value>
- </data>
- <data name="Arg_ArrayTypeMismatchException" xml:space="preserve">
- <value>Attempted to access an element as a type incompatible with the array.</value>
- </data>
- <data name="Arg_ArrayZeroError" xml:space="preserve">
- <value>Array must not be of length zero.</value>
- </data>
- <data name="Arg_BadDecimal" xml:space="preserve">
- <value>Read an invalid decimal value from the buffer.</value>
- </data>
- <data name="Arg_BadImageFormatException" xml:space="preserve">
- <value>Format of the executable (.exe) or library (.dll) is invalid.</value>
- </data>
- <data name="Arg_BadLiteralFormat" xml:space="preserve">
- <value>Encountered an invalid type for a default value.</value>
- </data>
- <data name="Arg_BogusIComparer" xml:space="preserve">
- <value>Unable to sort because the IComparer.Compare() method returns inconsistent results. Either a value does not compare equal to itself, or one value repeatedly compared to another value yields different results. IComparer: '{0}'.</value>
- </data>
- <data name="Arg_BufferTooSmall" xml:space="preserve">
- <value>Not enough space available in the buffer.</value>
- </data>
- <data name="Arg_CannotBeNaN" xml:space="preserve">
- <value>TimeSpan does not accept floating point Not-a-Number values.</value>
- </data>
- <data name="Arg_CannotHaveNegativeValue" xml:space="preserve">
- <value>String cannot contain a minus sign if the base is not 10.</value>
- </data>
- <data name="Arg_CannotMixComparisonInfrastructure" xml:space="preserve">
- <value>The usage of IKeyComparer and IHashCodeProvider/IComparer interfaces cannot be mixed; use one or the other.</value>
- </data>
- <data name="Arg_CATypeResolutionFailed" xml:space="preserve">
- <value>Failed to resolve type from string "{0}" which was embedded in custom attribute blob.</value>
- </data>
- <data name="Arg_COMAccess" xml:space="preserve">
- <value>Must specify property Set or Get or method call for a COM Object.</value>
- </data>
- <data name="Arg_COMException" xml:space="preserve">
- <value>Error HRESULT E_FAIL has been returned from a call to a COM component.</value>
- </data>
- <data name="Arg_COMPropSetPut" xml:space="preserve">
- <value>Only one of the following binding flags can be set: BindingFlags.SetProperty, BindingFlags.PutDispProperty, BindingFlags.PutRefDispProperty.</value>
- </data>
- <data name="Arg_CreatInstAccess" xml:space="preserve">
- <value>Cannot specify both CreateInstance and another access type.</value>
- </data>
- <data name="Arg_CryptographyException" xml:space="preserve">
- <value>Error occurred during a cryptographic operation.</value>
- </data>
- <data name="Arg_CustomAttributeFormatException" xml:space="preserve">
- <value>Binary format of the specified custom attribute was invalid.</value>
- </data>
- <data name="Arg_DataMisalignedException" xml:space="preserve">
- <value>A datatype misalignment was detected in a load or store instruction.</value>
- </data>
- <data name="Arg_DateTimeRange" xml:space="preserve">
- <value>Combination of arguments to the DateTime constructor is out of the legal range.</value>
- </data>
- <data name="Arg_DecBitCtor" xml:space="preserve">
- <value>Decimal byte array constructor requires an array of length four containing valid decimal bytes.</value>
- </data>
- <data name="Arg_DirectoryNotFoundException" xml:space="preserve">
- <value>Attempted to access a path that is not on the disk.</value>
- </data>
- <data name="Arg_DivideByZero" xml:space="preserve">
- <value>Attempted to divide by zero.</value>
- </data>
- <data name="Arg_DlgtNullInst" xml:space="preserve">
- <value>Delegate to an instance method cannot have null 'this'.</value>
- </data>
- <data name="Arg_DlgtTargMeth" xml:space="preserve">
- <value>Cannot bind to the target method because its signature is not compatible with that of the delegate type.</value>
- </data>
- <data name="Arg_DlgtTypeMis" xml:space="preserve">
- <value>Delegates must be of the same type.</value>
- </data>
- <data name="Arg_DllNotFoundException" xml:space="preserve">
- <value>Dll was not found.</value>
- </data>
- <data name="Arg_DriveNotFoundException" xml:space="preserve">
- <value>Attempted to access a drive that is not available.</value>
- </data>
- <data name="Arg_DuplicateWaitObjectException" xml:space="preserve">
- <value>Duplicate objects in argument.</value>
- </data>
- <data name="Arg_EHClauseNotClause" xml:space="preserve">
- <value>This ExceptionHandlingClause is not a clause.</value>
- </data>
- <data name="Arg_EHClauseNotFilter" xml:space="preserve">
- <value>This ExceptionHandlingClause is not a filter.</value>
- </data>
- <data name="Arg_EmptyArray" xml:space="preserve">
- <value>Array may not be empty.</value>
- </data>
- <data name="Arg_EmptyOrNullString" xml:space="preserve">
- <value>String may not be empty or null.</value>
- </data>
- <data name="Arg_EndOfStreamException" xml:space="preserve">
- <value>Attempted to read past the end of the stream.</value>
- </data>
- <data name="Arg_EntryPointNotFoundException" xml:space="preserve">
- <value>Entry point was not found.</value>
- </data>
- <data name="Arg_EnumAndObjectMustBeSameType" xml:space="preserve">
- <value>Object must be the same type as the enum. The type passed in was '{0}'; the enum type was '{1}'.</value>
- </data>
- <data name="Arg_EnumFormatUnderlyingTypeAndObjectMustBeSameType" xml:space="preserve">
- <value>Enum underlying type and the object must be same type or object. Type passed in was '{0}'; the enum underlying type was '{1}'.</value>
- </data>
- <data name="Arg_EnumIllegalVal" xml:space="preserve">
- <value>Illegal enum value: {0}.</value>
- </data>
- <data name="Arg_EnumLitValueNotFound" xml:space="preserve">
- <value>Literal value was not found.</value>
- </data>
- <data name="Arg_EnumUnderlyingTypeAndObjectMustBeSameType" xml:space="preserve">
- <value>Enum underlying type and the object must be same type or object must be a String. Type passed in was '{0}'; the enum underlying type was '{1}'.</value>
- </data>
- <data name="Arg_EnumValueNotFound" xml:space="preserve">
- <value>Requested value '{0}' was not found.</value>
- </data>
- <data name="Arg_ExecutionEngineException" xml:space="preserve">
- <value>Internal error in the runtime.</value>
- </data>
- <data name="Arg_ExternalException" xml:space="preserve">
- <value>External component has thrown an exception.</value>
- </data>
- <data name="Arg_FieldAccessException" xml:space="preserve">
- <value>Attempted to access a field that is not accessible by the caller.</value>
- </data>
- <data name="Arg_FieldDeclTarget" xml:space="preserve">
- <value>Field '{0}' defined on type '{1}' is not a field on the target object which is of type '{2}'.</value>
- </data>
- <data name="Arg_FldGetArgErr" xml:space="preserve">
- <value>No arguments can be provided to Get a field value.</value>
- </data>
- <data name="Arg_FldGetPropSet" xml:space="preserve">
- <value>Cannot specify both GetField and SetProperty.</value>
- </data>
- <data name="Arg_FldSetArgErr" xml:space="preserve">
- <value>Only the field value can be specified to set a field value.</value>
- </data>
- <data name="Arg_FldSetGet" xml:space="preserve">
- <value>Cannot specify both Get and Set on a field.</value>
- </data>
- <data name="Arg_FldSetInvoke" xml:space="preserve">
- <value>Cannot specify Set on a Field and Invoke on a method.</value>
- </data>
- <data name="Arg_FldSetPropGet" xml:space="preserve">
- <value>Cannot specify both SetField and GetProperty.</value>
- </data>
- <data name="Arg_FormatException" xml:space="preserve">
- <value>One of the identified items was in an invalid format.</value>
- </data>
- <data name="Arg_GenericParameter" xml:space="preserve">
- <value>Method must be called on a Type for which Type.IsGenericParameter is false.</value>
- </data>
- <data name="Arg_GetMethNotFnd" xml:space="preserve">
- <value>Property Get method was not found.</value>
- </data>
- <data name="Arg_GuidArrayCtor" xml:space="preserve">
- <value>Byte array for GUID must be exactly {0} bytes long.</value>
- </data>
- <data name="Arg_HandleNotAsync" xml:space="preserve">
- <value>Handle does not support asynchronous operations. The parameters to the FileStream constructor may need to be changed to indicate that the handle was opened synchronously (that is, it was not opened for overlapped I/O).</value>
- </data>
- <data name="Arg_HandleNotSync" xml:space="preserve">
- <value>Handle does not support synchronous operations. The parameters to the FileStream constructor may need to be changed to indicate that the handle was opened asynchronously (that is, it was opened explicitly for overlapped I/O).</value>
- </data>
- <data name="Arg_HexStyleNotSupported" xml:space="preserve">
- <value>The number style AllowHexSpecifier is not supported on floating point data types.</value>
- </data>
- <data name="Arg_HTCapacityOverflow" xml:space="preserve">
- <value>Hashtable's capacity overflowed and went negative. Check load factor, capacity and the current size of the table.</value>
- </data>
- <data name="Arg_IndexMustBeInt" xml:space="preserve">
- <value>All indexes must be of type Int32.</value>
- </data>
- <data name="Arg_IndexOutOfRangeException" xml:space="preserve">
- <value>Index was outside the bounds of the array.</value>
- </data>
- <data name="Arg_InsufficientExecutionStackException" xml:space="preserve">
- <value>Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space.</value>
- </data>
- <data name="Arg_InvalidANSIString" xml:space="preserve">
- <value>The ANSI string passed in could not be converted from the default ANSI code page to Unicode.</value>
- </data>
- <data name="Arg_InvalidBase" xml:space="preserve">
- <value>Invalid Base.</value>
- </data>
- <data name="Arg_InvalidCastException" xml:space="preserve">
- <value>Specified cast is not valid.</value>
- </data>
- <data name="Arg_InvalidComObjectException" xml:space="preserve">
- <value>Attempt has been made to use a COM object that does not have a backing class factory.</value>
- </data>
- <data name="Arg_InvalidFilterCriteriaException" xml:space="preserve">
- <value>Specified filter criteria was invalid.</value>
- </data>
- <data name="Arg_InvalidHandle" xml:space="preserve">
- <value>Invalid handle.</value>
- </data>
- <data name="Arg_InvalidHexStyle" xml:space="preserve">
- <value>With the AllowHexSpecifier bit set in the enum bit field, the only other valid bits that can be combined into the enum value must be a subset of those in HexNumber.</value>
- </data>
- <data name="Arg_InvalidNeutralResourcesLanguage_Asm_Culture" xml:space="preserve">
- <value>The NeutralResourcesLanguageAttribute on the assembly "{0}" specifies an invalid culture name: "{1}".</value>
- </data>
- <data name="Arg_InvalidNeutralResourcesLanguage_FallbackLoc" xml:space="preserve">
- <value>The NeutralResourcesLanguageAttribute specifies an invalid or unrecognized ultimate resource fallback location: "{0}".</value>
- </data>
- <data name="Arg_InvalidOleVariantTypeException" xml:space="preserve">
- <value>Specified OLE variant was invalid.</value>
- </data>
- <data name="Arg_InvalidOperationException" xml:space="preserve">
- <value>Operation is not valid due to the current state of the object.</value>
- </data>
- <data name="Arg_InvalidSearchPattern" xml:space="preserve">
- <value>Search pattern '{0}' cannot contain ".." to move up directories and can be contained only internally in file/directory names, as in "a..b".</value>
- </data>
- <data name="Arg_InvalidTypeInRetType" xml:space="preserve">
- <value>The return Type must be a type provided by the runtime.</value>
- </data>
- <data name="Arg_InvalidTypeInSignature" xml:space="preserve">
- <value>The signature Type array contains some invalid type (i.e. null, void)</value>
- </data>
- <data name="Arg_InvalidUTF8String" xml:space="preserve">
- <value>The UTF8 string passed in could not be converted to Unicode.</value>
- </data>
- <data name="Arg_IOException" xml:space="preserve">
- <value>I/O error occurred.</value>
- </data>
- <data name="Arg_KeyNotFound" xml:space="preserve">
- <value>The given key was not present in the dictionary.</value>
- </data>
- <data name="Arg_KeyNotFoundWithKey" xml:space="preserve">
- <value>The given key '{0}' was not present in the dictionary.</value>
- </data>
- <data name="Arg_LongerThanDestArray" xml:space="preserve">
- <value>Destination array was not long enough. Check the destination index, length, and the array's lower bounds.</value>
- </data>
- <data name="Arg_LongerThanSrcArray" xml:space="preserve">
- <value>Source array was not long enough. Check the source index, length, and the array's lower bounds.</value>
- </data>
- <data name="Arg_LongerThanSrcString" xml:space="preserve">
- <value>Source string was not long enough. Check sourceIndex and count.</value>
- </data>
- <data name="Arg_LowerBoundsMustMatch" xml:space="preserve">
- <value>The arrays' lower bounds must be identical.</value>
- </data>
- <data name="Arg_MarshalAsAnyRestriction" xml:space="preserve">
- <value>AsAny cannot be used on return types, ByRef parameters, ArrayWithOffset, or parameters passed from unmanaged to managed.</value>
- </data>
- <data name="Arg_MarshalDirectiveException" xml:space="preserve">
- <value>Marshaling directives are invalid.</value>
- </data>
- <data name="Arg_MethodAccessException" xml:space="preserve">
- <value>Attempt to access the method failed.</value>
- </data>
- <data name="Arg_MethodAccessException_WithMethodName" xml:space="preserve">
- <value>Attempt to access the method "{0}" on type "{1}" failed.</value>
- </data>
- <data name="Arg_MissingFieldException" xml:space="preserve">
- <value>Attempted to access a non-existing field.</value>
- </data>
- <data name="Arg_MissingManifestResourceException" xml:space="preserve">
- <value>Unable to find manifest resource.</value>
- </data>
- <data name="Arg_MissingMemberException" xml:space="preserve">
- <value>Attempted to access a missing member.</value>
- </data>
- <data name="Arg_MissingMethodException" xml:space="preserve">
- <value>Attempted to access a missing method.</value>
- </data>
- <data name="Arg_MulticastNotSupportedException" xml:space="preserve">
- <value>Attempted to add multiple callbacks to a delegate that does not support multicast.</value>
- </data>
- <data name="Arg_MustBeBoolean" xml:space="preserve">
- <value>Object must be of type Boolean.</value>
- </data>
- <data name="Arg_MustBeByte" xml:space="preserve">
- <value>Object must be of type Byte.</value>
- </data>
- <data name="Arg_MustBeChar" xml:space="preserve">
- <value>Object must be of type Char.</value>
- </data>
- <data name="Arg_MustBeDateTime" xml:space="preserve">
- <value>Object must be of type DateTime.</value>
- </data>
- <data name="Arg_MustBeDateTimeOffset" xml:space="preserve">
- <value>Object must be of type DateTimeOffset.</value>
- </data>
- <data name="Arg_MustBeDecimal" xml:space="preserve">
- <value>Object must be of type Decimal.</value>
- </data>
- <data name="Arg_MustBeDelegate" xml:space="preserve">
- <value>Type must derive from Delegate.</value>
- </data>
- <data name="Arg_MustBeDouble" xml:space="preserve">
- <value>Object must be of type Double.</value>
- </data>
- <data name="Arg_MustBeEnum" xml:space="preserve">
- <value>Type provided must be an Enum.</value>
- </data>
- <data name="Arg_MustBeEnumBaseTypeOrEnum" xml:space="preserve">
- <value>The value passed in must be an enum base or an underlying type for an enum, such as an Int32.</value>
- </data>
- <data name="Arg_MustBeGuid" xml:space="preserve">
- <value>Object must be of type GUID.</value>
- </data>
- <data name="Arg_MustBeInt16" xml:space="preserve">
- <value>Object must be of type Int16.</value>
- </data>
- <data name="Arg_MustBeInt32" xml:space="preserve">
- <value>Object must be of type Int32.</value>
- </data>
- <data name="Arg_MustBeInt64" xml:space="preserve">
- <value>Object must be of type Int64.</value>
- </data>
- <data name="Arg_MustBeInterface" xml:space="preserve">
- <value>Type passed must be an interface.</value>
- </data>
- <data name="Arg_MustBePointer" xml:space="preserve">
- <value>Type must be a Pointer.</value>
- </data>
- <data name="Arg_MustBePrimArray" xml:space="preserve">
- <value>Object must be an array of primitives.</value>
- </data>
- <data name="Arg_MustBeSByte" xml:space="preserve">
- <value>Object must be of type SByte.</value>
- </data>
- <data name="Arg_MustBeSingle" xml:space="preserve">
- <value>Object must be of type Single.</value>
- </data>
- <data name="Arg_MustBeStatic" xml:space="preserve">
- <value>Method must be a static method.</value>
- </data>
- <data name="Arg_MustBeString" xml:space="preserve">
- <value>Object must be of type String.</value>
- </data>
- <data name="Arg_MustBeTimeSpan" xml:space="preserve">
- <value>Object must be of type TimeSpan.</value>
- </data>
- <data name="Arg_MustBeType" xml:space="preserve">
- <value>Type must be a type provided by the runtime.</value>
- </data>
- <data name="Arg_MustBeUInt16" xml:space="preserve">
- <value>Object must be of type UInt16.</value>
- </data>
- <data name="Arg_MustBeUInt32" xml:space="preserve">
- <value>Object must be of type UInt32.</value>
- </data>
- <data name="Arg_MustBeUInt64" xml:space="preserve">
- <value>Object must be of type UInt64.</value>
- </data>
- <data name="Arg_MustBeVersion" xml:space="preserve">
- <value>Object must be of type Version.</value>
- </data>
- <data name="Arg_MustContainEnumInfo" xml:space="preserve">
- <value>Must specify valid information for parsing in the string.</value>
- </data>
- <data name="Arg_NamedParamNull" xml:space="preserve">
- <value>Named parameter value must not be null.</value>
- </data>
- <data name="Arg_NamedParamTooBig" xml:space="preserve">
- <value>Named parameter array cannot be bigger than argument array.</value>
- </data>
- <data name="Arg_NDirectBadObject" xml:space="preserve">
- <value>No PInvoke conversion exists for value passed to Object-typed parameter.</value>
- </data>
- <data name="Arg_Need1DArray" xml:space="preserve">
- <value>Array was not a one-dimensional array.</value>
- </data>
- <data name="Arg_Need2DArray" xml:space="preserve">
- <value>Array was not a two-dimensional array.</value>
- </data>
- <data name="Arg_Need3DArray" xml:space="preserve">
- <value>Array was not a three-dimensional array.</value>
- </data>
- <data name="Arg_NeedAtLeast1Rank" xml:space="preserve">
- <value>Must provide at least one rank.</value>
- </data>
- <data name="Arg_NegativeArgCount" xml:space="preserve">
- <value>Argument count must not be negative.</value>
- </data>
- <data name="Arg_NoAccessSpec" xml:space="preserve">
- <value>Must specify binding flags describing the invoke operation required (BindingFlags.InvokeMethod CreateInstance GetField SetField GetProperty SetProperty).</value>
- </data>
- <data name="Arg_NoDefCTor" xml:space="preserve">
- <value>No parameterless constructor defined for type '{0}'.</value>
- </data>
- <data name="Arg_NoITypeInfo" xml:space="preserve">
- <value>Specified TypeInfo was invalid because it did not support the ITypeInfo interface.</value>
- </data>
- <data name="Arg_NoITypeLib" xml:space="preserve">
- <value>Specified TypeLib was invalid because it did not support the ITypeLib interface.</value>
- </data>
- <data name="Arg_NonZeroLowerBound" xml:space="preserve">
- <value>The lower bound of target array must be zero.</value>
- </data>
- <data name="Arg_NoStaticVirtual" xml:space="preserve">
- <value>Method cannot be both static and virtual.</value>
- </data>
- <data name="Arg_NotFiniteNumberException" xml:space="preserve">
- <value>Number encountered was not a finite quantity.</value>
- </data>
- <data name="Arg_NotFoundIFace" xml:space="preserve">
- <value>Interface not found.</value>
- </data>
- <data name="Arg_NotGenericMethodDefinition" xml:space="preserve">
- <value>{0} is not a GenericMethodDefinition. MakeGenericMethod may only be called on a method for which MethodBase.IsGenericMethodDefinition is true.</value>
- </data>
- <data name="Arg_NotGenericParameter" xml:space="preserve">
- <value>Method may only be called on a Type for which Type.IsGenericParameter is true.</value>
- </data>
- <data name="Arg_NotGenericTypeDefinition" xml:space="preserve">
- <value>{0} is not a GenericTypeDefinition. MakeGenericType may only be called on a type for which Type.IsGenericTypeDefinition is true.</value>
- </data>
- <data name="Arg_NotImplementedException" xml:space="preserve">
- <value>The method or operation is not implemented.</value>
- </data>
- <data name="Arg_NotSupportedException" xml:space="preserve">
- <value>Specified method is not supported.</value>
- </data>
- <data name="Arg_NullIndex" xml:space="preserve">
- <value>Arrays indexes must be set to an object instance.</value>
- </data>
- <data name="Arg_NullReferenceException" xml:space="preserve">
- <value>Object reference not set to an instance of an object.</value>
- </data>
- <data name="Arg_ObjObj" xml:space="preserve">
- <value>Object type cannot be converted to target type.</value>
- </data>
- <data name="Arg_ObjObjEx" xml:space="preserve">
- <value>Object of type '{0}' cannot be converted to type '{1}'.</value>
- </data>
- <data name="Arg_OleAutDateInvalid" xml:space="preserve">
- <value>Not a legal OleAut date.</value>
- </data>
- <data name="Arg_OleAutDateScale" xml:space="preserve">
- <value>OleAut date did not convert to a DateTime correctly.</value>
- </data>
- <data name="Arg_OverflowException" xml:space="preserve">
- <value>Arithmetic operation resulted in an overflow.</value>
- </data>
- <data name="Arg_OutOfMemoryException" xml:space="preserve">
- <value>Insufficient memory to continue the execution of the program.</value>
- </data>
- <data name="Arg_ParamName_Name" xml:space="preserve">
- <value>Parameter name: {0}</value>
- </data>
- <data name="Arg_ParmArraySize" xml:space="preserve">
- <value>Must specify one or more parameters.</value>
- </data>
- <data name="Arg_ParmCnt" xml:space="preserve">
- <value>Parameter count mismatch.</value>
- </data>
- <data name="Arg_PathEmpty" xml:space="preserve">
- <value>The path is empty.</value>
- </data>
- <data name="Arg_PathIllegalUNC_Path" xml:space="preserve">
- <value>The UNC path '{0}' should be of the form \\\\server\\share.</value>
- </data>
- <data name="Arg_PlatformNotSupported" xml:space="preserve">
- <value>Operation is not supported on this platform.</value>
- </data>
- <data name="Arg_PrimWiden" xml:space="preserve">
- <value>Cannot widen from source type to target type either because the source type is a not a primitive type or the conversion cannot be accomplished.</value>
- </data>
- <data name="Arg_PropSetGet" xml:space="preserve">
- <value>Cannot specify both Get and Set on a property.</value>
- </data>
- <data name="Arg_PropSetInvoke" xml:space="preserve">
- <value>Cannot specify Set on a property and Invoke on a method.</value>
- </data>
- <data name="Arg_RankException" xml:space="preserve">
- <value>Attempted to operate on an array with the incorrect number of dimensions.</value>
- </data>
- <data name="Arg_RankIndices" xml:space="preserve">
- <value>Indices length does not match the array rank.</value>
- </data>
- <data name="Arg_RankMultiDimNotSupported" xml:space="preserve">
- <value>Only single dimensional arrays are supported for the requested action.</value>
- </data>
- <data name="Arg_RanksAndBounds" xml:space="preserve">
- <value>Number of lengths and lowerBounds must match.</value>
- </data>
- <data name="Arg_RegGetOverflowBug" xml:space="preserve">
- <value>RegistryKey.GetValue does not allow a String that has a length greater than Int32.MaxValue.</value>
- </data>
- <data name="Arg_RegKeyNotFound" xml:space="preserve">
- <value>The specified registry key does not exist.</value>
- </data>
- <data name="Arg_RegSubKeyValueAbsent" xml:space="preserve">
- <value>No value exists with that name.</value>
- </data>
- <data name="Arg_RegValStrLenBug" xml:space="preserve">
- <value>Registry value names should not be greater than 16,383 characters.</value>
- </data>
- <data name="Arg_ResMgrNotResSet" xml:space="preserve">
- <value>Type parameter must refer to a subclass of ResourceSet.</value>
- </data>
- <data name="Arg_ResourceFileUnsupportedVersion" xml:space="preserve">
- <value>The ResourceReader class does not know how to read this version of .resources files. Expected version: {0} This file: {1}</value>
- </data>
- <data name="Arg_ResourceNameNotExist" xml:space="preserve">
- <value>The specified resource name "{0}" does not exist in the resource file.</value>
- </data>
- <data name="Arg_SafeArrayRankMismatchException" xml:space="preserve">
- <value>Specified array was not of the expected rank.</value>
- </data>
- <data name="Arg_SafeArrayTypeMismatchException" xml:space="preserve">
- <value>Specified array was not of the expected type.</value>
- </data>
- <data name="Arg_SecurityException" xml:space="preserve">
- <value>Security error.</value>
- </data>
- <data name="SerializationException" xml:space="preserve">
- <value>Serialization error.</value>
- </data>
- <data name="Arg_SetMethNotFnd" xml:space="preserve">
- <value>Property set method not found.</value>
- </data>
- <data name="Arg_StackOverflowException" xml:space="preserve">
- <value>Operation caused a stack overflow.</value>
- </data>
- <data name="Arg_SurrogatesNotAllowedAsSingleChar" xml:space="preserve">
- <value>Unicode surrogate characters must be written out as pairs together in the same call, not individually. Consider passing in a character array instead.</value>
- </data>
- <data name="Arg_SynchronizationLockException" xml:space="preserve">
- <value>Object synchronization method was called from an unsynchronized block of code.</value>
- </data>
- <data name="Arg_SystemException" xml:space="preserve">
- <value>System error.</value>
- </data>
- <data name="Arg_TargetInvocationException" xml:space="preserve">
- <value>Exception has been thrown by the target of an invocation.</value>
- </data>
- <data name="Arg_TargetParameterCountException" xml:space="preserve">
- <value>Number of parameters specified does not match the expected number.</value>
- </data>
- <data name="Arg_ThreadStartException" xml:space="preserve">
- <value>Thread failed to start.</value>
- </data>
- <data name="Arg_ThreadStateException" xml:space="preserve">
- <value>Thread was in an invalid state for the operation being executed.</value>
- </data>
- <data name="Arg_TimeoutException" xml:space="preserve">
- <value>The operation has timed out.</value>
- </data>
- <data name="Arg_TypeAccessException" xml:space="preserve">
- <value>Attempt to access the type failed.</value>
- </data>
- <data name="Arg_TypedReference_Null" xml:space="preserve">
- <value>The TypedReference must be initialized.</value>
- </data>
- <data name="Arg_TypeLoadException" xml:space="preserve">
- <value>Failure has occurred while loading a type.</value>
- </data>
- <data name="Arg_TypeLoadNullStr" xml:space="preserve">
- <value>A null or zero length string does not represent a valid Type.</value>
- </data>
- <data name="Arg_TypeRefPrimitve" xml:space="preserve">
- <value>TypedReferences cannot be redefined as primitives. Field name '{0}'.</value>
- </data>
- <data name="Arg_TypeUnloadedException" xml:space="preserve">
- <value>Type had been unloaded.</value>
- </data>
- <data name="Arg_UnauthorizedAccessException" xml:space="preserve">
- <value>Attempted to perform an unauthorized operation.</value>
- </data>
- <data name="Arg_UnboundGenField" xml:space="preserve">
- <value>Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true.</value>
- </data>
- <data name="Arg_UnboundGenParam" xml:space="preserve">
- <value>Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.</value>
- </data>
- <data name="Arg_UnknownTypeCode" xml:space="preserve">
- <value>Unknown TypeCode value.</value>
- </data>
- <data name="Arg_VarMissNull" xml:space="preserve">
- <value>Missing parameter does not have a default value.</value>
- </data>
- <data name="Arg_VersionString" xml:space="preserve">
- <value>Version string portion was too short or too long.</value>
- </data>
- <data name="Arg_WrongAsyncResult" xml:space="preserve">
- <value>IAsyncResult object did not come from the corresponding async method on this type.</value>
- </data>
- <data name="Arg_WrongType" xml:space="preserve">
- <value>The value "{0}" is not of type "{1}" and cannot be used in this generic collection.</value>
- </data>
- <data name="Argument_AbsolutePathRequired" xml:space="preserve">
- <value>Absolute path information is required.</value>
- </data>
- <data name="Argument_AddingDuplicate" xml:space="preserve">
- <value>An item with the same key has already been added.</value>
- </data>
- <data name="Argument_AddingDuplicate__" xml:space="preserve">
- <value>Item has already been added. Key in dictionary: '{0}' Key being added: '{1}'</value>
- </data>
- <data name="Argument_AddingDuplicateWithKey" xml:space="preserve">
- <value>An item with the same key has already been added. Key: {0}</value>
- </data>
- <data name="Argument_AdjustmentRulesNoNulls" xml:space="preserve">
- <value>The AdjustmentRule array cannot contain null elements.</value>
- </data>
- <data name="Argument_AdjustmentRulesOutOfOrder" xml:space="preserve">
- <value>The elements of the AdjustmentRule array must be in chronological order and must not overlap.</value>
- </data>
- <data name="Argument_AlreadyACCW" xml:space="preserve">
- <value>The object already has a CCW associated with it.</value>
- </data>
- <data name="Argument_AlreadyBoundOrSyncHandle" xml:space="preserve">
- <value>'handle' has already been bound to the thread pool, or was not opened for asynchronous I/O.</value>
- </data>
- <data name="Argument_ArgumentZero" xml:space="preserve">
- <value>Argument cannot be zero.</value>
- </data>
- <data name="Argument_ArrayGetInterfaceMap" xml:space="preserve">
- <value>Interface maps for generic interfaces on arrays cannot be retrieved.</value>
- </data>
- <data name="Argument_ArraysInvalid" xml:space="preserve">
- <value>Array or pointer types are not valid.</value>
- </data>
- <data name="Argument_BadAttributeOnInterfaceMethod" xml:space="preserve">
- <value>Interface method must be abstract and virtual.</value>
- </data>
- <data name="Argument_BadConstantValue" xml:space="preserve">
- <value>Bad default value.</value>
- </data>
- <data name="Argument_BadConstructor" xml:space="preserve">
- <value>Cannot have private or static constructor.</value>
- </data>
- <data name="Argument_BadConstructorCallConv" xml:space="preserve">
- <value>Constructor must have standard calling convention.</value>
- </data>
- <data name="Argument_BadExceptionCodeGen" xml:space="preserve">
- <value>Incorrect code generation for exception block.</value>
- </data>
- <data name="Argument_BadFieldForConstructorBuilder" xml:space="preserve">
- <value>Field must be on the same type of the given ConstructorInfo.</value>
- </data>
- <data name="Argument_BadFieldSig" xml:space="preserve">
- <value>Field signatures do not have return types.</value>
- </data>
- <data name="Argument_BadFieldType" xml:space="preserve">
- <value>Bad field type in defining field.</value>
- </data>
- <data name="Argument_BadFormatSpecifier" xml:space="preserve">
- <value>Format specifier was invalid.</value>
- </data>
- <data name="Argument_BadImageFormatExceptionResolve" xml:space="preserve">
- <value>A BadImageFormatException has been thrown while parsing the signature. This is likely due to lack of a generic context. Ensure genericTypeArguments and genericMethodArguments are provided and contain enough context.</value>
- </data>
- <data name="Argument_BadLabel" xml:space="preserve">
- <value>Bad label in ILGenerator.</value>
- </data>
- <data name="Argument_BadLabelContent" xml:space="preserve">
- <value>Bad label content in ILGenerator.</value>
- </data>
- <data name="Argument_BadNestedTypeFlags" xml:space="preserve">
- <value>Visibility of interfaces must be one of the following: NestedAssembly, NestedFamANDAssem, NestedFamily, NestedFamORAssem, NestedPrivate or NestedPublic.</value>
- </data>
- <data name="Argument_BadObjRef" xml:space="preserve">
- <value>Invalid ObjRef provided to '{0}'.</value>
- </data>
- <data name="Argument_BadParameterCountsForConstructor" xml:space="preserve">
- <value>Parameter count does not match passed in argument value count.</value>
- </data>
- <data name="Argument_BadParameterTypeForCAB" xml:space="preserve">
- <value>Cannot emit a CustomAttribute with argument of type {0}.</value>
- </data>
- <data name="Argument_BadPropertyForConstructorBuilder" xml:space="preserve">
- <value>Property must be on the same type of the given ConstructorInfo.</value>
- </data>
- <data name="Argument_BadSigFormat" xml:space="preserve">
- <value>Incorrect signature format.</value>
- </data>
- <data name="Argument_BadSizeForData" xml:space="preserve">
- <value>Data size must be &gt; 1 and &lt; 0x3f0000</value>
- </data>
- <data name="Argument_BadTypeAttrInvalidLayout" xml:space="preserve">
- <value>Bad type attributes. Invalid layout attribute specified.</value>
- </data>
- <data name="Argument_BadTypeAttrNestedVisibilityOnNonNestedType" xml:space="preserve">
- <value>Bad type attributes. Nested visibility flag set on a non-nested type.</value>
- </data>
- <data name="Argument_BadTypeAttrNonNestedVisibilityNestedType" xml:space="preserve">
- <value>Bad type attributes. Non-nested visibility flag set on a nested type.</value>
- </data>
- <data name="Argument_BadTypeAttrReservedBitsSet" xml:space="preserve">
- <value>Bad type attributes. Reserved bits set on the type.</value>
- </data>
- <data name="Argument_BadTypeInCustomAttribute" xml:space="preserve">
- <value>An invalid type was used as a custom attribute constructor argument, field or property.</value>
- </data>
- <data name="Argument_CannotCreateTypedReference" xml:space="preserve">
- <value>Cannot use function evaluation to create a TypedReference object.</value>
- </data>
- <data name="Argument_CannotGetTypeTokenForByRef" xml:space="preserve">
- <value>Cannot get TypeToken for a ByRef type.</value>
- </data>
- <data name="Argument_CannotSetParentToInterface" xml:space="preserve">
- <value>Cannot set parent to an interface.</value>
- </data>
- <data name="Argument_CodepageNotSupported" xml:space="preserve">
- <value>{0} is not a supported code page.</value>
- </data>
- <data name="Argument_CompareOptionOrdinal" xml:space="preserve">
- <value>CompareOption.Ordinal cannot be used with other options.</value>
- </data>
- <data name="Argument_ConflictingDateTimeRoundtripStyles" xml:space="preserve">
- <value>The DateTimeStyles value RoundtripKind cannot be used with the values AssumeLocal, AssumeUniversal or AdjustToUniversal.</value>
- </data>
- <data name="Argument_ConflictingDateTimeStyles" xml:space="preserve">
- <value>The DateTimeStyles values AssumeLocal and AssumeUniversal cannot be used together.</value>
- </data>
- <data name="Argument_ConstantDoesntMatch" xml:space="preserve">
- <value>Constant does not match the defined type.</value>
- </data>
- <data name="Argument_ConstantNotSupported" xml:space="preserve">
- <value>{0} is not a supported constant type.</value>
- </data>
- <data name="Argument_ConstantNull" xml:space="preserve">
- <value>Null is not a valid constant value for this type.</value>
- </data>
- <data name="Argument_ConstructorNeedGenericDeclaringType" xml:space="preserve">
- <value>The specified constructor must be declared on a generic type definition.</value>
- </data>
- <data name="Argument_ConversionOverflow" xml:space="preserve">
- <value>Conversion buffer overflow.</value>
- </data>
- <data name="Argument_ConvertMismatch" xml:space="preserve">
- <value>The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local.</value>
- </data>
- <data name="Argument_CORDBBadMethod" xml:space="preserve">
- <value>Cannot find the method on the object instance.</value>
- </data>
- <data name="Argument_CORDBBadVarArgCallConv" xml:space="preserve">
- <value>Cannot evaluate a VarArgs function.</value>
- </data>
- <data name="Argument_CultureIetfNotSupported" xml:space="preserve">
- <value>Culture IETF Name {0} is not a recognized IETF name.</value>
- </data>
- <data name="Argument_CultureInvalidIdentifier" xml:space="preserve">
- <value>{0} is an invalid culture identifier.</value>
- </data>
- <data name="Argument_CultureIsNeutral" xml:space="preserve">
- <value>Culture ID {0} (0x{0:X4}) is a neutral culture; a region cannot be created from it.</value>
- </data>
- <data name="Argument_CultureNotSupported" xml:space="preserve">
- <value>Culture is not supported.</value>
- </data>
- <data name="Argument_CustomAssemblyLoadContextRequestedNameMismatch" xml:space="preserve">
- <value>Resolved assembly's simple name should be the same as of the requested assembly.</value>
- </data>
- <data name="Argument_CustomCultureCannotBePassedByNumber" xml:space="preserve">
- <value>Customized cultures cannot be passed by LCID, only by name.</value>
- </data>
- <data name="Argument_DateTimeBadBinaryData" xml:space="preserve">
- <value>The binary data must result in a DateTime with ticks between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.</value>
- </data>
- <data name="Argument_DateTimeHasTicks" xml:space="preserve">
- <value>The supplied DateTime must have the Year, Month, and Day properties set to 1. The time cannot be specified more precisely than whole milliseconds.</value>
- </data>
- <data name="Argument_DateTimeHasTimeOfDay" xml:space="preserve">
- <value>The supplied DateTime includes a TimeOfDay setting. This is not supported.</value>
- </data>
- <data name="Argument_DateTimeIsInvalid" xml:space="preserve">
- <value>The supplied DateTime represents an invalid time. For example, when the clock is adjusted forward, any time in the period that is skipped is invalid.</value>
- </data>
- <data name="Argument_DateTimeIsNotAmbiguous" xml:space="preserve">
- <value>The supplied DateTime is not in an ambiguous time range.</value>
- </data>
- <data name="Argument_DateTimeKindMustBeUnspecified" xml:space="preserve">
- <value>The supplied DateTime must have the Kind property set to DateTimeKind.Unspecified.</value>
- </data>
- <data name="Argument_DateTimeKindMustBeUnspecifiedOrUtc" xml:space="preserve">
- <value>The supplied DateTime must have the Kind property set to DateTimeKind.Unspecified or DateTimeKind.Utc.</value>
- </data>
- <data name="Argument_DateTimeOffsetInvalidDateTimeStyles" xml:space="preserve">
- <value>The DateTimeStyles value 'NoCurrentDateDefault' is not allowed when parsing DateTimeOffset.</value>
- </data>
- <data name="Argument_DateTimeOffsetIsNotAmbiguous" xml:space="preserve">
- <value>The supplied DateTimeOffset is not in an ambiguous time range.</value>
- </data>
- <data name="Argument_DestinationTooShort" xml:space="preserve">
- <value>Destination is too short.</value>
- </data>
- <data name="Argument_DuplicateTypeName" xml:space="preserve">
- <value>Duplicate type name within an assembly.</value>
- </data>
- <data name="Argument_EmitWriteLineType" xml:space="preserve">
- <value>EmitWriteLine does not support this field or local type.</value>
- </data>
- <data name="Argument_EmptyDecString" xml:space="preserve">
- <value>Decimal separator cannot be the empty string.</value>
- </data>
- <data name="Argument_EmptyFileName" xml:space="preserve">
- <value>Empty file name is not legal.</value>
- </data>
- <data name="Argument_EmptyName" xml:space="preserve">
- <value>Empty name is not legal.</value>
- </data>
- <data name="Argument_EmptyPath" xml:space="preserve">
- <value>Empty path name is not legal.</value>
- </data>
- <data name="Argument_EmptyWaithandleArray" xml:space="preserve">
- <value>Waithandle array may not be empty.</value>
- </data>
- <data name="Argument_EncoderFallbackNotEmpty" xml:space="preserve">
- <value>Must complete Convert() operation or call Encoder.Reset() before calling GetBytes() or GetByteCount(). Encoder '{0}' fallback '{1}'.</value>
- </data>
- <data name="Argument_EncodingConversionOverflowBytes" xml:space="preserve">
- <value>The output byte buffer is too small to contain the encoded data, encoding '{0}' fallback '{1}'.</value>
- </data>
- <data name="Argument_EncodingConversionOverflowChars" xml:space="preserve">
- <value>The output char buffer is too small to contain the decoded characters, encoding '{0}' fallback '{1}'.</value>
- </data>
- <data name="Argument_EncodingNotSupported" xml:space="preserve">
- <value>'{0}' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.</value>
- </data>
- <data name="Argument_EnumTypeDoesNotMatch" xml:space="preserve">
- <value>The argument type, '{0}', is not the same as the enum type '{1}'.</value>
- </data>
- <data name="Argument_FallbackBufferNotEmpty" xml:space="preserve">
- <value>Cannot change fallback when buffer is not empty. Previous Convert() call left data in the fallback buffer.</value>
- </data>
- <data name="Argument_FieldDeclaringTypeGeneric" xml:space="preserve">
- <value>Cannot resolve field {0} because the declaring type of the field handle {1} is generic. Explicitly provide the declaring type to GetFieldFromHandle.</value>
- </data>
- <data name="Argument_FieldNeedGenericDeclaringType" xml:space="preserve">
- <value>The specified field must be declared on a generic type definition.</value>
- </data>
- <data name="Argument_GenConstraintViolation" xml:space="preserve">
- <value>GenericArguments[{0}], '{1}', on '{2}' violates the constraint of type '{3}'.</value>
- </data>
- <data name="Argument_GenericArgsCount" xml:space="preserve">
- <value>The number of generic arguments provided doesn't equal the arity of the generic type definition.</value>
- </data>
- <data name="Argument_GenericsInvalid" xml:space="preserve">
- <value>Generic types are not valid.</value>
- </data>
- <data name="Argument_GlobalFunctionHasToBeStatic" xml:space="preserve">
- <value>Global members must be static.</value>
- </data>
- <data name="Argument_HandleLeak" xml:space="preserve">
- <value>Cannot pass a GCHandle across AppDomains.</value>
- </data>
- <data name="Argument_HasToBeArrayClass" xml:space="preserve">
- <value>Must be an array type.</value>
- </data>
- <data name="Argument_IdnBadBidi" xml:space="preserve">
- <value>Left to right characters may not be mixed with right to left characters in IDN labels.</value>
- </data>
- <data name="Argument_IdnBadLabelSize" xml:space="preserve">
- <value>IDN labels must be between 1 and 63 characters long.</value>
- </data>
- <data name="Argument_IdnBadNameSize" xml:space="preserve">
- <value>IDN names must be between 1 and {0} characters long.</value>
- </data>
- <data name="Argument_IdnBadPunycode" xml:space="preserve">
- <value>Invalid IDN encoded string.</value>
- </data>
- <data name="Argument_IdnBadStd3" xml:space="preserve">
- <value>Label contains character '{0}' not allowed with UseStd3AsciiRules</value>
- </data>
- <data name="Argument_IdnIllegalName" xml:space="preserve">
- <value>Decoded string is not a valid IDN name.</value>
- </data>
- <data name="Argument_IllegalEnvVarName" xml:space="preserve">
- <value>Environment variable name cannot contain equal character.</value>
- </data>
- <data name="Argument_IllegalName" xml:space="preserve">
- <value>Illegal name.</value>
- </data>
- <data name="Argument_ImplementIComparable" xml:space="preserve">
- <value>At least one object must implement IComparable.</value>
- </data>
- <data name="Argument_IndexOutOfArrayBounds" xml:space="preserve">
- <value>The specified index is out of bounds of the specified array.</value>
- </data>
- <data name="Argument_InsufficientSpaceToCopyCollection" xml:space="preserve">
- <value>The specified space is not sufficient to copy the elements from this Collection.</value>
- </data>
- <data name="Argument_InterfaceMap" xml:space="preserve">
- <value>'this' type cannot be an interface itself.</value>
- </data>
- <data name="Argument_InvalidAppendMode" xml:space="preserve">
- <value>Append access can be requested only in write-only mode.</value>
- </data>
- <data name="Argument_InvalidArgumentForComparison" xml:space="preserve">
- <value>Type of argument is not compatible with the generic comparer.</value>
- </data>
- <data name="Argument_InvalidArrayLength" xml:space="preserve">
- <value>Length of the array must be {0}.</value>
- </data>
- <data name="Argument_InvalidArrayType" xml:space="preserve">
- <value>Target array type is not compatible with the type of items in the collection.</value>
- </data>
- <data name="Argument_InvalidAssemblyName" xml:space="preserve">
- <value>Assembly names may not begin with whitespace or contain the characters '/', or '\\' or ':'.</value>
- </data>
- <data name="Argument_InvalidCalendar" xml:space="preserve">
- <value>Not a valid calendar for the given culture.</value>
- </data>
- <data name="Argument_InvalidCharSequence" xml:space="preserve">
- <value>Invalid Unicode code point found at index {0}.</value>
- </data>
- <data name="Argument_InvalidCharSequenceNoIndex" xml:space="preserve">
- <value>String contains invalid Unicode code points.</value>
- </data>
- <data name="Argument_InvalidCodePageBytesIndex" xml:space="preserve">
- <value>Unable to translate bytes {0} at index {1} from specified code page to Unicode.</value>
- </data>
- <data name="Argument_InvalidCodePageConversionIndex" xml:space="preserve">
- <value>Unable to translate Unicode character \\u{0:X4} at index {1} to specified code page.</value>
- </data>
- <data name="Argument_InvalidConstructorDeclaringType" xml:space="preserve">
- <value>The specified constructor must be declared on the generic type definition of the specified type.</value>
- </data>
- <data name="Argument_InvalidConstructorInfo" xml:space="preserve">
- <value>The ConstructorInfo object is not valid.</value>
- </data>
- <data name="Argument_InvalidCultureName" xml:space="preserve">
- <value>Culture name '{0}' is not supported.</value>
- </data>
- <data name="Argument_InvalidDateTimeKind" xml:space="preserve">
- <value>Invalid DateTimeKind value.</value>
- </data>
- <data name="Argument_InvalidDateTimeStyles" xml:space="preserve">
- <value>An undefined DateTimeStyles value is being used.</value>
- </data>
- <data name="Argument_InvalidDigitSubstitution" xml:space="preserve">
- <value>The DigitSubstitution property must be of a valid member of the DigitShapes enumeration. Valid entries include Context, NativeNational or None.</value>
- </data>
- <data name="Argument_InvalidEnum" xml:space="preserve">
- <value>The Enum type should contain one and only one instance field.</value>
- </data>
- <data name="Argument_InvalidEnumValue" xml:space="preserve">
- <value>The value '{0}' is not valid for this usage of the type {1}.</value>
- </data>
- <data name="Argument_InvalidFieldDeclaringType" xml:space="preserve">
- <value>The specified field must be declared on the generic type definition of the specified type.</value>
- </data>
- <data name="Argument_InvalidFileModeAndAccessCombo" xml:space="preserve">
- <value>Combining FileMode: {0} with FileAccess: {1} is invalid.</value>
- </data>
- <data name="Argument_InvalidFlag" xml:space="preserve">
- <value>Value of flags is invalid.</value>
- </data>
- <data name="Argument_InvalidGenericArg" xml:space="preserve">
- <value>The generic type parameter was not valid</value>
- </data>
- <data name="Argument_InvalidGenericInstArray" xml:space="preserve">
- <value>Generic arguments must be provided for each generic parameter and each generic argument must be a RuntimeType.</value>
- </data>
- <data name="Argument_InvalidGroupSize" xml:space="preserve">
- <value>Every element in the value array should be between one and nine, except for the last element, which can be zero.</value>
- </data>
- <data name="Argument_InvalidHandle" xml:space="preserve">
- <value>The handle is invalid.</value>
- </data>
- <data name="Argument_InvalidHighSurrogate" xml:space="preserve">
- <value>Found a high surrogate char without a following low surrogate at index: {0}. The input may not be in this encoding, or may not contain valid Unicode (UTF-16) characters.</value>
- </data>
- <data name="Argument_InvalidId" xml:space="preserve">
- <value>The specified ID parameter '{0}' is not supported.</value>
- </data>
- <data name="Argument_InvalidKindOfTypeForCA" xml:space="preserve">
- <value>This type cannot be represented as a custom attribute.</value>
- </data>
- <data name="Argument_InvalidLabel" xml:space="preserve">
- <value>Invalid Label.</value>
- </data>
- <data name="Argument_InvalidLowSurrogate" xml:space="preserve">
- <value>Found a low surrogate char without a preceding high surrogate at index: {0}. The input may not be in this encoding, or may not contain valid Unicode (UTF-16) characters.</value>
- </data>
- <data name="Argument_InvalidMemberForNamedArgument" xml:space="preserve">
- <value>The member must be either a field or a property.</value>
- </data>
- <data name="Argument_InvalidMethodDeclaringType" xml:space="preserve">
- <value>The specified method must be declared on the generic type definition of the specified type.</value>
- </data>
- <data name="Argument_InvalidName" xml:space="preserve">
- <value>Invalid name.</value>
- </data>
- <data name="Argument_InvalidNativeDigitCount" xml:space="preserve">
- <value>The NativeDigits array must contain exactly ten members.</value>
- </data>
- <data name="Argument_InvalidNativeDigitValue" xml:space="preserve">
- <value>Each member of the NativeDigits array must be a single text element (one or more UTF16 code points) with a Unicode Nd (Number, Decimal Digit) property indicating it is a digit.</value>
- </data>
- <data name="Argument_InvalidNeutralRegionName" xml:space="preserve">
- <value>The region name {0} should not correspond to neutral culture; a specific culture name is required.</value>
- </data>
- <data name="Argument_InvalidNormalizationForm" xml:space="preserve">
- <value>Invalid or unsupported normalization form.</value>
- </data>
- <data name="Argument_InvalidNumberStyles" xml:space="preserve">
- <value>An undefined NumberStyles value is being used.</value>
- </data>
- <data name="Argument_InvalidOffLen" xml:space="preserve">
- <value>Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.</value>
- </data>
- <data name="Argument_InvalidOpCodeOnDynamicMethod" xml:space="preserve">
- <value>Ldtoken, Ldftn and Ldvirtftn OpCodes cannot target DynamicMethods.</value>
- </data>
- <data name="Argument_InvalidParameterInfo" xml:space="preserve">
- <value>The ParameterInfo object is not valid.</value>
- </data>
- <data name="Argument_InvalidParamInfo" xml:space="preserve">
- <value>Invalid type for ParameterInfo member in Attribute class.</value>
- </data>
- <data name="Argument_InvalidPathChars" xml:space="preserve">
- <value>Illegal characters in path.</value>
- </data>
- <data name="Argument_InvalidRegistryViewCheck" xml:space="preserve">
- <value>The specified RegistryView value is invalid.</value>
- </data>
- <data name="Argument_InvalidResourceCultureName" xml:space="preserve">
- <value>The given culture name '{0}' cannot be used to locate a resource file. Resource filenames must consist of only letters, numbers, hyphens or underscores.</value>
- </data>
- <data name="Argument_InvalidSafeBufferOffLen" xml:space="preserve">
- <value>Offset and length were greater than the size of the SafeBuffer.</value>
- </data>
- <data name="Argument_InvalidSeekOrigin" xml:space="preserve">
- <value>Invalid seek origin.</value>
- </data>
- <data name="Argument_InvalidSerializedString" xml:space="preserve">
- <value>The specified serialized string '{0}' is not supported.</value>
- </data>
- <data name="Argument_InvalidStartupHookSyntax" xml:space="preserve">
- <value>The syntax of the startup hook variable was invalid.</value>
- </data>
- <data name="Argument_InvalidStartupHookSignature" xml:space="preserve">
- <value>The signature of the startup hook '{0}' in assembly '{1}' was invalid. It must be 'public static void Initialize()'.</value>
- </data>
- <data name="Argument_InvalidTimeSpanStyles" xml:space="preserve">
- <value>An undefined TimeSpanStyles value is being used.</value>
- </data>
- <data name="Argument_InvalidToken" xml:space="preserve">
- <value>Token {0:x} is not valid in the scope of module {1}.</value>
- </data>
- <data name="Argument_InvalidTypeForCA" xml:space="preserve">
- <value>Cannot build type parameter for custom attribute with a type that does not support the AssemblyQualifiedName property. The type instance supplied was of type '{0}'.</value>
- </data>
- <data name="Argument_InvalidTypeForDynamicMethod" xml:space="preserve">
- <value>Invalid type owner for DynamicMethod.</value>
- </data>
- <data name="Argument_InvalidTypeName" xml:space="preserve">
- <value>The name of the type is invalid.</value>
- </data>
- <data name="Argument_InvalidTypeWithPointersNotSupported" xml:space="preserve">
- <value>Cannot use type '{0}'. Only value types without pointers or references are supported.</value>
- </data>
- <data name="Argument_InvalidUnity" xml:space="preserve">
- <value>Type '{0}' is not deserializable.</value>
- </data>
- <data name="Argument_InvalidValue" xml:space="preserve">
- <value>Value was invalid.</value>
- </data>
- <data name="Argument_LargeInteger" xml:space="preserve">
- <value>Integer or token was too large to be encoded.</value>
- </data>
- <data name="Argument_LongEnvVarValue" xml:space="preserve">
- <value>Environment variable name or value is too long.</value>
- </data>
- <data name="Argument_MethodDeclaringTypeGeneric" xml:space="preserve">
- <value>Cannot resolve method {0} because the declaring type of the method handle {1} is generic. Explicitly provide the declaring type to GetMethodFromHandle.</value>
- </data>
- <data name="Argument_MethodDeclaringTypeGenericLcg" xml:space="preserve">
- <value>Method '{0}' has a generic declaring type '{1}'. Explicitly provide the declaring type to GetTokenFor.</value>
- </data>
- <data name="Argument_MethodNeedGenericDeclaringType" xml:space="preserve">
- <value>The specified method cannot be dynamic or global and must be declared on a generic type definition.</value>
- </data>
- <data name="Argument_MinMaxValue" xml:space="preserve">
- <value>'{0}' cannot be greater than {1}.</value>
- </data>
- <data name="Argument_MismatchedArrays" xml:space="preserve">
- <value>Two arrays, {0} and {1}, must be of the same size.</value>
- </data>
- <data name="Argument_MissingDefaultConstructor" xml:space="preserve">
- <value>was missing default constructor.</value>
- </data>
- <data name="Argument_MustBeFalse" xml:space="preserve">
- <value>Argument must be initialized to false</value>
- </data>
- <data name="Argument_MustBeRuntimeAssembly" xml:space="preserve">
- <value>Assembly must be a runtime Assembly object.</value>
- </data>
- <data name="Argument_MustBeRuntimeFieldInfo" xml:space="preserve">
- <value>FieldInfo must be a runtime FieldInfo object.</value>
- </data>
- <data name="Argument_MustBeRuntimeMethodInfo" xml:space="preserve">
- <value>MethodInfo must be a runtime MethodInfo object.</value>
- </data>
- <data name="Argument_MustBeRuntimeReflectionObject" xml:space="preserve">
- <value>The object must be a runtime Reflection object.</value>
- </data>
- <data name="Argument_MustBeRuntimeType" xml:space="preserve">
- <value>Type must be a runtime Type object.</value>
- </data>
- <data name="Argument_MustBeTypeBuilder" xml:space="preserve">
- <value>'type' must contain a TypeBuilder as a generic argument.</value>
- </data>
- <data name="Argument_MustHaveAttributeBaseClass" xml:space="preserve">
- <value>Type passed in must be derived from System.Attribute or System.Attribute itself.</value>
- </data>
- <data name="Argument_MustHaveLayoutOrBeBlittable" xml:space="preserve">
- <value>The specified structure must be blittable or have layout information.</value>
- </data>
- <data name="Argument_NativeOverlappedAlreadyFree" xml:space="preserve">
- <value>'overlapped' has already been freed.</value>
- </data>
- <data name="Argument_NativeOverlappedWrongBoundHandle" xml:space="preserve">
- <value>'overlapped' was not allocated by this ThreadPoolBoundHandle instance.</value>
- </data>
- <data name="Argument_NeedGenericMethodDefinition" xml:space="preserve">
- <value>Method must represent a generic method definition on a generic type definition.</value>
- </data>
- <data name="Argument_NeedNonGenericObject" xml:space="preserve">
- <value>The specified object must not be an instance of a generic type.</value>
- </data>
- <data name="Argument_NeedNonGenericType" xml:space="preserve">
- <value>The specified Type must not be a generic type definition.</value>
- </data>
- <data name="Argument_NeedStructWithNoRefs" xml:space="preserve">
- <value>The specified Type must be a struct containing no references.</value>
- </data>
- <data name="Argument_NeverValidGenericArgument" xml:space="preserve">
- <value>The type '{0}' may not be used as a type argument.</value>
- </data>
- <data name="Argument_NoDomainManager" xml:space="preserve">
- <value>The domain manager specified by the host could not be instantiated.</value>
- </data>
- <data name="Argument_NoEra" xml:space="preserve">
- <value>No Era was supplied.</value>
- </data>
- <data name="Argument_NoModuleFileExtension" xml:space="preserve">
- <value>Module file name '{0}' must have file extension.</value>
- </data>
- <data name="Argument_NoRegionInvariantCulture" xml:space="preserve">
- <value>There is no region associated with the Invariant Culture (Culture ID: 0x7F).</value>
- </data>
- <data name="Argument_NotATP" xml:space="preserve">
- <value>Type must be a TransparentProxy</value>
- </data>
- <data name="Argument_NotAWritableProperty" xml:space="preserve">
- <value>Not a writable property.</value>
- </data>
- <data name="Argument_NotEnoughBytesToRead" xml:space="preserve">
- <value>There are not enough bytes remaining in the accessor to read at this position.</value>
- </data>
- <data name="Argument_NotEnoughBytesToWrite" xml:space="preserve">
- <value>There are not enough bytes remaining in the accessor to write at this position.</value>
- </data>
- <data name="Argument_NotEnoughGenArguments" xml:space="preserve">
- <value>The type or method has {1} generic parameter(s), but {0} generic argument(s) were provided. A generic argument must be provided for each generic parameter.</value>
- </data>
- <data name="Argument_NotExceptionType" xml:space="preserve">
- <value>Does not extend Exception.</value>
- </data>
- <data name="Argument_NotInExceptionBlock" xml:space="preserve">
- <value>Not currently in an exception block.</value>
- </data>
- <data name="Argument_NotMethodCallOpcode" xml:space="preserve">
- <value>The specified opcode cannot be passed to EmitCall.</value>
- </data>
- <data name="Argument_NotSerializable" xml:space="preserve">
- <value>Argument passed in is not serializable.</value>
- </data>
- <data name="Argument_NoUnderlyingCCW" xml:space="preserve">
- <value>The object has no underlying COM data associated with it.</value>
- </data>
- <data name="Argument_NoUninitializedStrings" xml:space="preserve">
- <value>Uninitialized Strings cannot be created.</value>
- </data>
- <data name="Argument_ObjIsWinRTObject" xml:space="preserve">
- <value>The object's type must not be a Windows Runtime type.</value>
- </data>
- <data name="Argument_ObjNotComObject" xml:space="preserve">
- <value>The object's type must be __ComObject or derived from __ComObject.</value>
- </data>
- <data name="Argument_OffsetAndCapacityOutOfBounds" xml:space="preserve">
- <value>Offset and capacity were greater than the size of the view.</value>
- </data>
- <data name="Argument_OffsetLocalMismatch" xml:space="preserve">
- <value>The UTC Offset of the local dateTime parameter does not match the offset argument.</value>
- </data>
- <data name="Argument_OffsetOfFieldNotFound" xml:space="preserve">
- <value>Field passed in is not a marshaled member of the type '{0}'.</value>
- </data>
- <data name="Argument_OffsetOutOfRange" xml:space="preserve">
- <value>Offset must be within plus or minus 14 hours.</value>
- </data>
- <data name="Argument_OffsetPrecision" xml:space="preserve">
- <value>Offset must be specified in whole minutes.</value>
- </data>
- <data name="Argument_OffsetUtcMismatch" xml:space="preserve">
- <value>The UTC Offset for Utc DateTime instances must be 0.</value>
- </data>
- <data name="Argument_OneOfCulturesNotSupported" xml:space="preserve">
- <value>Culture name {0} or {1} is not supported.</value>
- </data>
- <data name="Argument_OnlyMscorlib" xml:space="preserve">
- <value>Only mscorlib's assembly is valid.</value>
- </data>
- <data name="Argument_OutOfOrderDateTimes" xml:space="preserve">
- <value>The DateStart property must come before the DateEnd property.</value>
- </data>
- <data name="Argument_PathEmpty" xml:space="preserve">
- <value>Path cannot be the empty string or all whitespace.</value>
- </data>
- <data name="Argument_PathFormatNotSupported_Path" xml:space="preserve">
- <value>The format of the path '{0}' is not supported.</value>
- </data>
- <data name="Argument_PreAllocatedAlreadyAllocated" xml:space="preserve">
- <value>'preAllocated' is already in use.</value>
- </data>
- <data name="Argument_RecursiveFallback" xml:space="preserve">
- <value>Recursive fallback not allowed for character \\u{0:X4}.</value>
- </data>
- <data name="Argument_RecursiveFallbackBytes" xml:space="preserve">
- <value>Recursive fallback not allowed for bytes {0}.</value>
- </data>
- <data name="Argument_RedefinedLabel" xml:space="preserve">
- <value>Label multiply defined.</value>
- </data>
- <data name="Argument_ResolveField" xml:space="preserve">
- <value>Token {0:x} is not a valid FieldInfo token in the scope of module {1}.</value>
- </data>
- <data name="Argument_ResolveFieldHandle" xml:space="preserve">
- <value>Type handle '{0}' and field handle with declaring type '{1}' are incompatible. Get RuntimeFieldHandle and declaring RuntimeTypeHandle off the same FieldInfo.</value>
- </data>
- <data name="Argument_ResolveMember" xml:space="preserve">
- <value>Token {0:x} is not a valid MemberInfo token in the scope of module {1}.</value>
- </data>
- <data name="Argument_ResolveMethod" xml:space="preserve">
- <value>Token {0:x} is not a valid MethodBase token in the scope of module {1}.</value>
- </data>
- <data name="Argument_ResolveMethodHandle" xml:space="preserve">
- <value>Type handle '{0}' and method handle with declaring type '{1}' are incompatible. Get RuntimeMethodHandle and declaring RuntimeTypeHandle off the same MethodBase.</value>
- </data>
- <data name="Argument_ResolveModuleType" xml:space="preserve">
- <value>Token {0} resolves to the special module type representing this module.</value>
- </data>
- <data name="Argument_ResolveString" xml:space="preserve">
- <value>Token {0:x} is not a valid string token in the scope of module {1}.</value>
- </data>
- <data name="Argument_ResolveType" xml:space="preserve">
- <value>Token {0:x} is not a valid Type token in the scope of module {1}.</value>
- </data>
- <data name="Argument_ResultCalendarRange" xml:space="preserve">
- <value>The result is out of the supported range for this calendar. The result should be between {0} (Gregorian date) and {1} (Gregorian date), inclusive.</value>
- </data>
- <data name="Argument_SemaphoreInitialMaximum" xml:space="preserve">
- <value>The initial count for the semaphore must be greater than or equal to zero and less than the maximum count.</value>
- </data>
- <data name="Argument_ShouldNotSpecifyExceptionType" xml:space="preserve">
- <value>Should not specify exception type for catch clause for filter block.</value>
- </data>
- <data name="Argument_ShouldOnlySetVisibilityFlags" xml:space="preserve">
- <value>Should only set visibility flags when creating EnumBuilder.</value>
- </data>
- <data name="Argument_SigIsFinalized" xml:space="preserve">
- <value>Completed signature cannot be modified.</value>
- </data>
- <data name="Argument_SpansMustHaveSameLength" xml:space="preserve">
- <value>Length of items must be same as length of keys.</value>
- </data>
- <data name="Argument_StreamNotReadable" xml:space="preserve">
- <value>Stream was not readable.</value>
- </data>
- <data name="Argument_StreamNotWritable" xml:space="preserve">
- <value>Stream was not writable.</value>
- </data>
- <data name="Argument_StringFirstCharIsZero" xml:space="preserve">
- <value>The first char in the string is the null character.</value>
- </data>
- <data name="Argument_StringZeroLength" xml:space="preserve">
- <value>String cannot be of zero length.</value>
- </data>
- <data name="Argument_StructMustNotBeValueClass" xml:space="preserve">
- <value>The structure must not be a value class.</value>
- </data>
- <data name="Argument_TimeSpanHasSeconds" xml:space="preserve">
- <value>The TimeSpan parameter cannot be specified more precisely than whole minutes.</value>
- </data>
- <data name="Argument_TimeZoneInfoBadTZif" xml:space="preserve">
- <value>The tzfile does not begin with the magic characters 'TZif'. Please verify that the file is not corrupt.</value>
- </data>
- <data name="Argument_TimeZoneInfoInvalidTZif" xml:space="preserve">
- <value>The TZif data structure is corrupt.</value>
- </data>
- <data name="Argument_ToExclusiveLessThanFromExclusive" xml:space="preserve">
- <value>fromInclusive must be less than or equal to toExclusive.</value>
- </data>
- <data name="Argument_TooManyFinallyClause" xml:space="preserve">
- <value>Exception blocks may have at most one finally clause.</value>
- </data>
- <data name="Argument_TransitionTimesAreIdentical" xml:space="preserve">
- <value>The DaylightTransitionStart property must not equal the DaylightTransitionEnd property.</value>
- </data>
- <data name="Argument_TypedReferenceInvalidField" xml:space="preserve">
- <value>Field '{0}' in TypedReferences cannot be static.</value>
- </data>
- <data name="Argument_TypeIsWinRTType" xml:space="preserve">
- <value>The type must not be a Windows Runtime type.</value>
- </data>
- <data name="Argument_TypeMustBeVisibleFromCom" xml:space="preserve">
- <value>The specified type must be visible from COM.</value>
- </data>
- <data name="Argument_TypeMustNotBeComImport" xml:space="preserve">
- <value>The type must not be imported from COM.</value>
- </data>
- <data name="Argument_TypeNameTooLong" xml:space="preserve">
- <value>Type name was too long. The fully qualified type name must be less than 1,024 characters.</value>
- </data>
- <data name="Argument_TypeNotActivatableViaWindowsRuntime" xml:space="preserve">
- <value>Type '{0}' does not have an activation factory because it is not activatable by Windows Runtime.</value>
- </data>
- <data name="Argument_TypeNotComObject" xml:space="preserve">
- <value>The type must be __ComObject or be derived from __ComObject.</value>
- </data>
- <data name="Argument_TypeNotValid" xml:space="preserve">
- <value>The Type object is not valid.</value>
- </data>
- <data name="Argument_UnclosedExceptionBlock" xml:space="preserve">
- <value>The IL Generator cannot be used while there are unclosed exceptions.</value>
- </data>
- <data name="Argument_Unexpected_TypeSource" xml:space="preserve">
- <value>Unexpected TypeKind when marshaling Windows.Foundation.TypeName.</value>
- </data>
- <data name="Argument_UnknownUnmanagedCallConv" xml:space="preserve">
- <value>Unknown unmanaged calling convention for function signature.</value>
- </data>
- <data name="Argument_UnmanagedMemAccessorWrapAround" xml:space="preserve">
- <value>The UnmanagedMemoryAccessor capacity and offset would wrap around the high end of the address space.</value>
- </data>
- <data name="Argument_UnmatchedMethodForLocal" xml:space="preserve">
- <value>Local passed in does not belong to this ILGenerator.</value>
- </data>
- <data name="Argument_UnmatchingSymScope" xml:space="preserve">
- <value>Non-matching symbol scope.</value>
- </data>
- <data name="Argument_UTCOutOfRange" xml:space="preserve">
- <value>The UTC time represented when the offset is applied must be between year 0 and 10,000.</value>
- </data>
- <data name="Argument_VerStringTooLong" xml:space="preserve">
- <value>The unmanaged Version information is too large to persist.</value>
- </data>
- <data name="Argument_WaitHandleNameTooLong" xml:space="preserve">
- <value>The length of the name exceeds the maximum limit.</value>
- </data>
- <data name="Argument_WinRTSystemRuntimeType" xml:space="preserve">
- <value>Cannot marshal type '{0}' to Windows Runtime. Only 'System.RuntimeType' is supported.</value>
- </data>
- <data name="ArgumentException_BadMethodImplBody" xml:space="preserve">
- <value>MethodOverride's body must be from this type.</value>
- </data>
- <data name="ArgumentException_BufferNotFromPool" xml:space="preserve">
- <value>The buffer is not associated with this pool and may not be returned to it.</value>
- </data>
- <data name="ArgumentException_OtherNotArrayOfCorrectLength" xml:space="preserve">
- <value>Object is not a array with the same number of elements as the array to compare it to.</value>
- </data>
- <data name="ArgumentException_TupleIncorrectType" xml:space="preserve">
- <value>Argument must be of type {0}.</value>
- </data>
- <data name="ArgumentException_TupleLastArgumentNotATuple" xml:space="preserve">
- <value>The last element of an eight element tuple must be a Tuple.</value>
- </data>
- <data name="ArgumentException_ValueTupleIncorrectType" xml:space="preserve">
- <value>Argument must be of type {0}.</value>
- </data>
- <data name="ArgumentException_ValueTupleLastArgumentNotAValueTuple" xml:space="preserve">
- <value>The last element of an eight element ValueTuple must be a ValueTuple.</value>
- </data>
- <data name="ArgumentNull_Array" xml:space="preserve">
- <value>Array cannot be null.</value>
- </data>
- <data name="ArgumentNull_ArrayElement" xml:space="preserve">
- <value>At least one element in the specified array was null.</value>
- </data>
- <data name="ArgumentNull_ArrayValue" xml:space="preserve">
- <value>Found a null value within an array.</value>
- </data>
- <data name="ArgumentNull_Assembly" xml:space="preserve">
- <value>Assembly cannot be null.</value>
- </data>
- <data name="ArgumentNull_AssemblyName" xml:space="preserve">
- <value>AssemblyName cannot be null.</value>
- </data>
- <data name="ArgumentNull_AssemblyNameName" xml:space="preserve">
- <value>AssemblyName.Name cannot be null or an empty string.</value>
- </data>
- <data name="ArgumentNull_Buffer" xml:space="preserve">
- <value>Buffer cannot be null.</value>
- </data>
- <data name="ArgumentNull_Collection" xml:space="preserve">
- <value>Collection cannot be null.</value>
- </data>
- <data name="ArgumentNull_Dictionary" xml:space="preserve">
- <value>Dictionary cannot be null.</value>
- </data>
- <data name="ArgumentNull_FileName" xml:space="preserve">
- <value>File name cannot be null.</value>
- </data>
- <data name="ArgumentNull_Generic" xml:space="preserve">
- <value>Value cannot be null.</value>
- </data>
- <data name="ArgumentNull_GUID" xml:space="preserve">
- <value>GUID cannot be null.</value>
- </data>
- <data name="ArgumentNull_Key" xml:space="preserve">
- <value>Key cannot be null.</value>
- </data>
- <data name="ArgumentNull_Path" xml:space="preserve">
- <value>Path cannot be null.</value>
- </data>
- <data name="ArgumentNull_SafeHandle" xml:space="preserve">
- <value>SafeHandle cannot be null.</value>
- </data>
- <data name="ArgumentNull_Stream" xml:space="preserve">
- <value>Stream cannot be null.</value>
- </data>
- <data name="ArgumentNull_String" xml:space="preserve">
- <value>String reference not set to an instance of a String.</value>
- </data>
- <data name="ArgumentNull_Type" xml:space="preserve">
- <value>Type cannot be null.</value>
- </data>
- <data name="ArgumentNull_TypedRefType" xml:space="preserve">
- <value>Type in TypedReference cannot be null.</value>
- </data>
- <data name="ArgumentNull_Waithandles" xml:space="preserve">
- <value>The waitHandles parameter cannot be null.</value>
- </data>
- <data name="ArgumentOutOfRange_ActualValue" xml:space="preserve">
- <value>Actual value was {0}.</value>
- </data>
- <data name="ArgumentOutOfRange_AddressSpace" xml:space="preserve">
- <value>The number of bytes cannot exceed the virtual address space on a 32 bit machine.</value>
- </data>
- <data name="ArgumentOutOfRange_AddValue" xml:space="preserve">
- <value>Value to add was out of range.</value>
- </data>
- <data name="ArgumentOutOfRange_ArrayLB" xml:space="preserve">
- <value>Number was less than the array's lower bound in the first dimension.</value>
- </data>
- <data name="ArgumentOutOfRange_ArrayLBAndLength" xml:space="preserve">
- <value>Higher indices will exceed Int32.MaxValue because of large lower bound and/or length.</value>
- </data>
- <data name="ArgumentOutOfRange_BadHourMinuteSecond" xml:space="preserve">
- <value>Hour, Minute, and Second parameters describe an un-representable DateTime.</value>
- </data>
- <data name="ArgumentOutOfRange_BadYearMonthDay" xml:space="preserve">
- <value>Year, Month, and Day parameters describe an un-representable DateTime.</value>
- </data>
- <data name="ArgumentOutOfRange_BiggerThanCollection" xml:space="preserve">
- <value>Larger than collection size.</value>
- </data>
- <data name="ArgumentOutOfRange_BinaryReaderFillBuffer" xml:space="preserve">
- <value>The number of bytes requested does not fit into BinaryReader's internal buffer.</value>
- </data>
- <data name="ArgumentOutOfRange_Bounds_Lower_Upper" xml:space="preserve">
- <value>Argument must be between {0} and {1}.</value>
- </data>
- <data name="ArgumentOutOfRange_CalendarRange" xml:space="preserve">
- <value>Specified time is not supported in this calendar. It should be between {0} (Gregorian date) and {1} (Gregorian date), inclusive.</value>
- </data>
- <data name="ArgumentOutOfRange_Capacity" xml:space="preserve">
- <value>Capacity exceeds maximum capacity.</value>
- </data>
- <data name="ArgumentOutOfRange_Count" xml:space="preserve">
- <value>Count must be positive and count must refer to a location within the string/array/collection.</value>
- </data>
- <data name="ArgumentOutOfRange_DateArithmetic" xml:space="preserve">
- <value>The added or subtracted value results in an un-representable DateTime.</value>
- </data>
- <data name="ArgumentOutOfRange_DateTimeBadMonths" xml:space="preserve">
- <value>Months value must be between +/-120000.</value>
- </data>
- <data name="ArgumentOutOfRange_DateTimeBadTicks" xml:space="preserve">
- <value>Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.</value>
- </data>
- <data name="ArgumentOutOfRange_DateTimeBadYears" xml:space="preserve">
- <value>Years value must be between +/-10000.</value>
- </data>
- <data name="ArgumentOutOfRange_Day" xml:space="preserve">
- <value>Day must be between 1 and {0} for month {1}.</value>
- </data>
- <data name="ArgumentOutOfRange_DayOfWeek" xml:space="preserve">
- <value>The DayOfWeek enumeration must be in the range 0 through 6.</value>
- </data>
- <data name="ArgumentOutOfRange_DayParam" xml:space="preserve">
- <value>The Day parameter must be in the range 1 through 31.</value>
- </data>
- <data name="ArgumentOutOfRange_DecimalRound" xml:space="preserve">
- <value>Decimal can only round to between 0 and 28 digits of precision.</value>
- </data>
- <data name="ArgumentOutOfRange_DecimalScale" xml:space="preserve">
- <value>Decimal's scale value must be between 0 and 28, inclusive.</value>
- </data>
- <data name="ArgumentOutOfRange_EndIndexStartIndex" xml:space="preserve">
- <value>endIndex cannot be greater than startIndex.</value>
- </data>
- <data name="ArgumentOutOfRange_Enum" xml:space="preserve">
- <value>Enum value was out of legal range.</value>
- </data>
- <data name="ArgumentOutOfRange_Era" xml:space="preserve">
- <value>Time value was out of era range.</value>
- </data>
- <data name="ArgumentOutOfRange_FileLengthTooBig" xml:space="preserve">
- <value>Specified file length was too large for the file system.</value>
- </data>
- <data name="ArgumentOutOfRange_FileTimeInvalid" xml:space="preserve">
- <value>Not a valid Win32 FileTime.</value>
- </data>
- <data name="ArgumentOutOfRange_GenericPositive" xml:space="preserve">
- <value>Value must be positive.</value>
- </data>
- <data name="ArgumentOutOfRange_GetByteCountOverflow" xml:space="preserve">
- <value>Too many characters. The resulting number of bytes is larger than what can be returned as an int.</value>
- </data>
- <data name="ArgumentOutOfRange_GetCharCountOverflow" xml:space="preserve">
- <value>Too many bytes. The resulting number of chars is larger than what can be returned as an int.</value>
- </data>
- <data name="ArgumentOutOfRange_HashtableLoadFactor" xml:space="preserve">
- <value>Load factor needs to be between 0.1 and 1.0.</value>
- </data>
- <data name="ArgumentOutOfRange_HugeArrayNotSupported" xml:space="preserve">
- <value>Arrays larger than 2GB are not supported.</value>
- </data>
- <data name="ArgumentOutOfRange_Index" xml:space="preserve">
- <value>Index was out of range. Must be non-negative and less than the size of the collection.</value>
- </data>
- <data name="ArgumentOutOfRange_IndexCount" xml:space="preserve">
- <value>Index and count must refer to a location within the string.</value>
- </data>
- <data name="ArgumentOutOfRange_IndexCountBuffer" xml:space="preserve">
- <value>Index and count must refer to a location within the buffer.</value>
- </data>
- <data name="ArgumentOutOfRange_IndexLargerThanMaxValue" xml:space="preserve">
- <value>This collection cannot work with indices larger than Int32.MaxValue - 1 (0x7FFFFFFF - 1).</value>
- </data>
- <data name="ArgumentOutOfRange_IndexLength" xml:space="preserve">
- <value>Index and length must refer to a location within the string.</value>
- </data>
- <data name="ArgumentOutOfRange_IndexString" xml:space="preserve">
- <value>Index was out of range. Must be non-negative and less than the length of the string.</value>
- </data>
- <data name="ArgumentOutOfRange_InvalidEraValue" xml:space="preserve">
- <value>Era value was not valid.</value>
- </data>
- <data name="ArgumentOutOfRange_InvalidHighSurrogate" xml:space="preserve">
- <value>A valid high surrogate character is between 0xd800 and 0xdbff, inclusive.</value>
- </data>
- <data name="ArgumentOutOfRange_InvalidLowSurrogate" xml:space="preserve">
- <value>A valid low surrogate character is between 0xdc00 and 0xdfff, inclusive.</value>
- </data>
- <data name="ArgumentOutOfRange_InvalidUTF32" xml:space="preserve">
- <value>A valid UTF32 value is between 0x000000 and 0x10ffff, inclusive, and should not include surrogate codepoint values (0x00d800 ~ 0x00dfff).</value>
- </data>
- <data name="ArgumentOutOfRange_Length" xml:space="preserve">
- <value>The specified length exceeds maximum capacity of SecureString.</value>
- </data>
- <data name="ArgumentOutOfRange_LengthGreaterThanCapacity" xml:space="preserve">
- <value>The length cannot be greater than the capacity.</value>
- </data>
- <data name="ArgumentOutOfRange_LengthTooLarge" xml:space="preserve">
- <value>The specified length exceeds the maximum value of {0}.</value>
- </data>
- <data name="ArgumentOutOfRange_LessEqualToIntegerMaxVal" xml:space="preserve">
- <value>Argument must be less than or equal to 2^31 - 1 milliseconds.</value>
- </data>
- <data name="ArgumentOutOfRange_ListInsert" xml:space="preserve">
- <value>Index must be within the bounds of the List.</value>
- </data>
- <data name="ArgumentOutOfRange_Month" xml:space="preserve">
- <value>Month must be between one and twelve.</value>
- </data>
- <data name="ArgumentOutOfRange_MonthParam" xml:space="preserve">
- <value>The Month parameter must be in the range 1 through 12.</value>
- </data>
- <data name="ArgumentOutOfRange_MustBeNonNegInt32" xml:space="preserve">
- <value>Value must be non-negative and less than or equal to Int32.MaxValue.</value>
- </data>
- <data name="ArgumentOutOfRange_MustBeNonNegNum" xml:space="preserve">
- <value>'{0}' must be non-negative.</value>
- </data>
- <data name="ArgumentOutOfRange_MustBePositive" xml:space="preserve">
- <value>'{0}' must be greater than zero.</value>
- </data>
- <data name="ArgumentOutOfRange_NeedNonNegNum" xml:space="preserve">
- <value>Non-negative number required.</value>
- </data>
- <data name="ArgumentOutOfRange_NeedNonNegOrNegative1" xml:space="preserve">
- <value>Number must be either non-negative and less than or equal to Int32.MaxValue or -1.</value>
- </data>
- <data name="ArgumentOutOfRange_NeedPosNum" xml:space="preserve">
- <value>Positive number required.</value>
- </data>
- <data name="ArgumentOutOfRange_NeedValidId" xml:space="preserve">
- <value>The ID parameter must be in the range {0} through {1}.</value>
- </data>
- <data name="ArgumentOutOfRange_NegativeCapacity" xml:space="preserve">
- <value>Capacity must be positive.</value>
- </data>
- <data name="ArgumentOutOfRange_NegativeCount" xml:space="preserve">
- <value>Count cannot be less than zero.</value>
- </data>
- <data name="ArgumentOutOfRange_NegativeLength" xml:space="preserve">
- <value>Length cannot be less than zero.</value>
- </data>
- <data name="ArgumentOutOfRange_OffsetLength" xml:space="preserve">
- <value>Offset and length must refer to a position in the string.</value>
- </data>
- <data name="ArgumentOutOfRange_OffsetOut" xml:space="preserve">
- <value>Either offset did not refer to a position in the string, or there is an insufficient length of destination character array.</value>
- </data>
- <data name="ArgumentOutOfRange_ParamSequence" xml:space="preserve">
- <value>The specified parameter index is not in range.</value>
- </data>
- <data name="ArgumentOutOfRange_PartialWCHAR" xml:space="preserve">
- <value>Pointer startIndex and length do not refer to a valid string.</value>
- </data>
- <data name="ArgumentOutOfRange_PeriodTooLarge" xml:space="preserve">
- <value>Period must be less than 2^32-2.</value>
- </data>
- <data name="ArgumentOutOfRange_PositionLessThanCapacityRequired" xml:space="preserve">
- <value>The position may not be greater or equal to the capacity of the accessor.</value>
- </data>
- <data name="ArgumentOutOfRange_Range" xml:space="preserve">
- <value>Valid values are between {0} and {1}, inclusive.</value>
- </data>
- <data name="ArgumentOutOfRange_RoundingDigits" xml:space="preserve">
- <value>Rounding digits must be between 0 and 15, inclusive.</value>
- </data>
- <data name="ArgumentOutOfRange_SmallCapacity" xml:space="preserve">
- <value>capacity was less than the current size.</value>
- </data>
- <data name="ArgumentOutOfRange_SmallMaxCapacity" xml:space="preserve">
- <value>MaxCapacity must be one or greater.</value>
- </data>
- <data name="ArgumentOutOfRange_StartIndex" xml:space="preserve">
- <value>StartIndex cannot be less than zero.</value>
- </data>
- <data name="ArgumentOutOfRange_StartIndexLargerThanLength" xml:space="preserve">
- <value>startIndex cannot be larger than length of string.</value>
- </data>
- <data name="ArgumentOutOfRange_StartIndexLessThanLength" xml:space="preserve">
- <value>startIndex must be less than length of string.</value>
- </data>
- <data name="ArgumentOutOfRange_StreamLength" xml:space="preserve">
- <value>Stream length must be non-negative and less than 2^31 - 1 - origin.</value>
- </data>
- <data name="ArgumentOutOfRange_TimeoutTooLarge" xml:space="preserve">
- <value>Time-out interval must be less than 2^32-2.</value>
- </data>
- <data name="ArgumentOutOfRange_UIntPtrMax" xml:space="preserve">
- <value>The length of the buffer must be less than the maximum UIntPtr value for your platform.</value>
- </data>
- <data name="ArgumentOutOfRange_UnmanagedMemStreamLength" xml:space="preserve">
- <value>UnmanagedMemoryStream length must be non-negative and less than 2^63 - 1 - baseAddress.</value>
- </data>
- <data name="ArgumentOutOfRange_UnmanagedMemStreamWrapAround" xml:space="preserve">
- <value>The UnmanagedMemoryStream capacity would wrap around the high end of the address space.</value>
- </data>
- <data name="ArgumentOutOfRange_UtcOffset" xml:space="preserve">
- <value>The TimeSpan parameter must be within plus or minus 14.0 hours.</value>
- </data>
- <data name="ArgumentOutOfRange_UtcOffsetAndDaylightDelta" xml:space="preserve">
- <value>The sum of the BaseUtcOffset and DaylightDelta properties must within plus or minus 14.0 hours.</value>
- </data>
- <data name="ArgumentOutOfRange_Version" xml:space="preserve">
- <value>Version's parameters must be greater than or equal to zero.</value>
- </data>
- <data name="ArgumentOutOfRange_Week" xml:space="preserve">
- <value>The Week parameter must be in the range 1 through 5.</value>
- </data>
- <data name="ArgumentOutOfRange_Year" xml:space="preserve">
- <value>Year must be between 1 and 9999.</value>
- </data>
- <data name="Arithmetic_NaN" xml:space="preserve">
- <value>Function does not accept floating point Not-a-Number values.</value>
- </data>
- <data name="ArrayTypeMismatch_CantAssignType" xml:space="preserve">
- <value>Source array type cannot be assigned to destination array type.</value>
- </data>
- <data name="ArrayTypeMismatch_ConstrainedCopy" xml:space="preserve">
- <value>Array.ConstrainedCopy will only work on array types that are provably compatible, without any form of boxing, unboxing, widening, or casting of each array element. Change the array types (i.e., copy a Derived[] to a Base[]), or use a mitigation strategy in the CER for Array.Copy's less powerful reliability contract, such as cloning the array or throwing away the potentially corrupt destination array.</value>
- </data>
- <data name="AssemblyLoadContext_Constructor_CannotInstantiateWhileUnloading" xml:space="preserve">
- <value>Cannot instantiate AssemblyLoadContext while the current process is exiting.</value>
- </data>
- <data name="AssemblyLoadContext_Unload_CannotUnloadIfNotCollectible" xml:space="preserve">
- <value>Cannot unload non-collectible AssemblyLoadContext.</value>
- </data>
- <data name="AssemblyLoadContext_Unload_AlreadyUnloaded" xml:space="preserve">
- <value>Unload called on AssemblyLoadContext that is unloading or that was already unloaded.</value>
- </data>
- <data name="AssemblyLoadContext_Verify_NotUnloading" xml:space="preserve">
- <value>AssemblyLoadContext is unloading or was already unloaded.</value>
- </data>
- <data name="AssertionFailed" xml:space="preserve">
- <value>Assertion failed.</value>
- </data>
- <data name="AssertionFailed_Cnd" xml:space="preserve">
- <value>Assertion failed: {0}</value>
- </data>
- <data name="AssumptionFailed" xml:space="preserve">
- <value>Assumption failed.</value>
- </data>
- <data name="AssumptionFailed_Cnd" xml:space="preserve">
- <value>Assumption failed: {0}</value>
- </data>
- <data name="AsyncMethodBuilder_InstanceNotInitialized" xml:space="preserve">
- <value>The builder was not properly initialized.</value>
- </data>
- <data name="BadImageFormat_BadILFormat" xml:space="preserve">
- <value>Bad IL format.</value>
- </data>
- <data name="BadImageFormat_InvalidType" xml:space="preserve">
- <value>Corrupt .resources file. The specified type doesn't exist.</value>
- </data>
- <data name="BadImageFormat_NegativeStringLength" xml:space="preserve">
- <value>Corrupt .resources file. String length must be non-negative.</value>
- </data>
- <data name="BadImageFormat_ParameterSignatureMismatch" xml:space="preserve">
- <value>The parameters and the signature of the method don't match.</value>
- </data>
- <data name="BadImageFormat_ResType_SerBlobMismatch" xml:space="preserve">
- <value>The type serialized in the .resources file was not the same type that the .resources file said it contained. Expected '{0}' but read '{1}'.</value>
- </data>
- <data name="BadImageFormat_ResourceDataLengthInvalid" xml:space="preserve">
- <value>Corrupt .resources file. The specified data length '{0}' is not a valid position in the stream.</value>
- </data>
- <data name="BadImageFormat_ResourceNameCorrupted" xml:space="preserve">
- <value>Corrupt .resources file. A resource name extends past the end of the stream.</value>
- </data>
- <data name="BadImageFormat_ResourceNameCorrupted_NameIndex" xml:space="preserve">
- <value>Corrupt .resources file. The resource name for name index {0} extends past the end of the stream.</value>
- </data>
- <data name="BadImageFormat_ResourcesDataInvalidOffset" xml:space="preserve">
- <value>Corrupt .resources file. Invalid offset '{0}' into data section.</value>
- </data>
- <data name="BadImageFormat_ResourcesHeaderCorrupted" xml:space="preserve">
- <value>Corrupt .resources file. Unable to read resources from this file because of invalid header information. Try regenerating the .resources file.</value>
- </data>
- <data name="BadImageFormat_ResourcesIndexTooLong" xml:space="preserve">
- <value>Corrupt .resources file. String for name index '{0}' extends past the end of the file.</value>
- </data>
- <data name="BadImageFormat_ResourcesNameInvalidOffset" xml:space="preserve">
- <value>Corrupt .resources file. Invalid offset '{0}' into name section.</value>
- </data>
- <data name="BadImageFormat_ResourcesNameTooLong" xml:space="preserve">
- <value>Corrupt .resources file. Resource name extends past the end of the file.</value>
- </data>
- <data name="BadImageFormat_TypeMismatch" xml:space="preserve">
- <value>Corrupt .resources file. The specified type doesn't match the available data in the stream.</value>
- </data>
- <data name="CancellationToken_CreateLinkedToken_TokensIsEmpty" xml:space="preserve">
- <value>No tokens were supplied.</value>
- </data>
- <data name="CancellationToken_SourceDisposed" xml:space="preserve">
- <value>The CancellationTokenSource associated with this CancellationToken has been disposed.</value>
- </data>
- <data name="CancellationTokenSource_Disposed" xml:space="preserve">
- <value>The CancellationTokenSource has been disposed.</value>
- </data>
- <data name="ConcurrentCollection_SyncRoot_NotSupported" xml:space="preserve">
- <value>The SyncRoot property may not be used for the synchronization of concurrent collections.</value>
- </data>
- <data name="event_SpinLock_FastPathFailed" xml:space="preserve">
- <value>SpinLock beginning to spin.</value>
- </data>
- <data name="event_SpinWait_NextSpinWillYield" xml:space="preserve">
- <value>Next spin will yield.</value>
- </data>
- <data name="event_TaskCompleted" xml:space="preserve">
- <value>Task {2} completed.</value>
- </data>
- <data name="event_TaskScheduled" xml:space="preserve">
- <value>Task {2} scheduled to TaskScheduler {0}.</value>
- </data>
- <data name="event_TaskStarted" xml:space="preserve">
- <value>Task {2} executing.</value>
- </data>
- <data name="event_TaskWaitBegin" xml:space="preserve">
- <value>Beginning wait ({3}) on Task {2}.</value>
- </data>
- <data name="event_TaskWaitEnd" xml:space="preserve">
- <value>Ending wait on Task {2}.</value>
- </data>
- <data name="EventSource_AbstractMustNotDeclareEventMethods" xml:space="preserve">
- <value>Abstract event source must not declare event methods ({0} with ID {1}).</value>
- </data>
- <data name="EventSource_AbstractMustNotDeclareKTOC" xml:space="preserve">
- <value>Abstract event source must not declare {0} nested type.</value>
- </data>
- <data name="EventSource_AddScalarOutOfRange" xml:space="preserve">
- <value>Getting out of bounds during scalar addition.</value>
- </data>
- <data name="EventSource_BadHexDigit" xml:space="preserve">
- <value>Bad Hexidecimal digit "{0}".</value>
- </data>
- <data name="EventSource_ChannelTypeDoesNotMatchEventChannelValue" xml:space="preserve">
- <value>Channel {0} does not match event channel value {1}.</value>
- </data>
- <data name="EventSource_DataDescriptorsOutOfRange" xml:space="preserve">
- <value>Data descriptors are out of range.</value>
- </data>
- <data name="EventSource_DuplicateStringKey" xml:space="preserve">
- <value>Multiple definitions for string "{0}".</value>
- </data>
- <data name="EventSource_EnumKindMismatch" xml:space="preserve">
- <value>The type of {0} is not expected in {1}.</value>
- </data>
- <data name="EventSource_EvenHexDigits" xml:space="preserve">
- <value>Must have an even number of Hexidecimal digits.</value>
- </data>
- <data name="EventSource_EventChannelOutOfRange" xml:space="preserve">
- <value>Channel {0} has a value of {1} which is outside the legal range (16-254).</value>
- </data>
- <data name="EventSource_EventIdReused" xml:space="preserve">
- <value>Event {0} has ID {1} which is already in use.</value>
- </data>
- <data name="EventSource_EventMustHaveTaskIfNonDefaultOpcode" xml:space="preserve">
- <value>Event {0} (with ID {1}) has a non-default opcode but not a task.</value>
- </data>
- <data name="EventSource_EventMustNotBeExplicitImplementation" xml:space="preserve">
- <value>Event method {0} (with ID {1}) is an explicit interface method implementation. Re-write method as implicit implementation.</value>
- </data>
- <data name="EventSource_EventNameDoesNotEqualTaskPlusOpcode" xml:space="preserve">
- <value>Event {0} (with ID {1}) has a name that is not the concatenation of its task name and opcode.</value>
- </data>
- <data name="EventSource_EventNameReused" xml:space="preserve">
- <value>Event name {0} used more than once. If you wish to overload a method, the overloaded method should have a NonEvent attribute.</value>
- </data>
- <data name="EventSource_EventParametersMismatch" xml:space="preserve">
- <value>Event {0} was called with {1} argument(s), but it is defined with {2} parameter(s).</value>
- </data>
- <data name="EventSource_EventSourceGuidInUse" xml:space="preserve">
- <value>An instance of EventSource with Guid {0} already exists.</value>
- </data>
- <data name="EventSource_EventTooBig" xml:space="preserve">
- <value>The payload for a single event is too large.</value>
- </data>
- <data name="EventSource_EventWithAdminChannelMustHaveMessage" xml:space="preserve">
- <value>Event {0} specifies an Admin channel {1}. It must specify a Message property.</value>
- </data>
- <data name="EventSource_IllegalKeywordsValue" xml:space="preserve">
- <value>Keyword {0} has a value of {1} which is outside the legal range (0-0x0000080000000000).</value>
- </data>
- <data name="EventSource_IllegalOpcodeValue" xml:space="preserve">
- <value>Opcode {0} has a value of {1} which is outside the legal range (11-238).</value>
- </data>
- <data name="EventSource_IllegalTaskValue" xml:space="preserve">
- <value>Task {0} has a value of {1} which is outside the legal range (1-65535).</value>
- </data>
- <data name="EventSource_IllegalValue" xml:space="preserve">
- <value>Illegal value "{0}" (prefix strings with @ to indicate a literal string).</value>
- </data>
- <data name="EventSource_IncorrentlyAuthoredTypeInfo" xml:space="preserve">
- <value>Incorrectly-authored TypeInfo - a type should be serialized as one field or as one group</value>
- </data>
- <data name="EventSource_InvalidCommand" xml:space="preserve">
- <value>Invalid command value.</value>
- </data>
- <data name="EventSource_InvalidEventFormat" xml:space="preserve">
- <value>Can't specify both etw event format flags.</value>
- </data>
- <data name="EventSource_KeywordCollision" xml:space="preserve">
- <value>Keywords {0} and {1} are defined with the same value ({2}).</value>
- </data>
- <data name="EventSource_KeywordNeedPowerOfTwo" xml:space="preserve">
- <value>Value {0} for keyword {1} needs to be a power of 2.</value>
- </data>
- <data name="EventSource_ListenerCreatedInsideCallback" xml:space="preserve">
- <value>Creating an EventListener inside a EventListener callback.</value>
- </data>
- <data name="EventSource_ListenerNotFound" xml:space="preserve">
- <value>Listener not found.</value>
- </data>
- <data name="EventSource_ListenerWriteFailure" xml:space="preserve">
- <value>An error occurred when writing to a listener.</value>
- </data>
- <data name="EventSource_MaxChannelExceeded" xml:space="preserve">
- <value>Attempt to define more than the maximum limit of 8 channels for a provider.</value>
- </data>
- <data name="EventSource_MismatchIdToWriteEvent" xml:space="preserve">
- <value>Event {0} was assigned event ID {1} but {2} was passed to WriteEvent.</value>
- </data>
- <data name="EventSource_NeedGuid" xml:space="preserve">
- <value>The Guid of an EventSource must be non zero.</value>
- </data>
- <data name="EventSource_NeedName" xml:space="preserve">
- <value>The name of an EventSource must not be null.</value>
- </data>
- <data name="EventSource_NeedPositiveId" xml:space="preserve">
- <value>Event IDs must be positive integers.</value>
- </data>
- <data name="EventSource_NoFreeBuffers" xml:space="preserve">
- <value>No Free Buffers available from the operating system (e.g. event rate too fast).</value>
- </data>
- <data name="EventSource_NonCompliantTypeError" xml:space="preserve">
- <value>The API supports only anonymous types or types decorated with the EventDataAttribute. Non-compliant type: {0} dataType.</value>
- </data>
- <data name="EventSource_NoRelatedActivityId" xml:space="preserve">
- <value>EventSource expects the first parameter of the Event method to be of type Guid and to be named "relatedActivityId" when calling WriteEventWithRelatedActivityId.</value>
- </data>
- <data name="EventSource_NotSupportedArrayOfBinary" xml:space="preserve">
- <value>Arrays of Binary are not supported.</value>
- </data>
- <data name="EventSource_NotSupportedArrayOfNil" xml:space="preserve">
- <value>Arrays of Nil are not supported.</value>
- </data>
- <data name="EventSource_NotSupportedArrayOfNullTerminatedString" xml:space="preserve">
- <value>Arrays of null-terminated string are not supported.</value>
- </data>
- <data name="EventSource_NotSupportedCustomSerializedData" xml:space="preserve">
- <value>Enumerables of custom-serialized data are not supported</value>
- </data>
- <data name="EventSource_NotSupportedNestedArraysEnums" xml:space="preserve">
- <value>Nested arrays/enumerables are not supported.</value>
- </data>
- <data name="EventSource_NullInput" xml:space="preserve">
- <value>Null passed as a event argument.</value>
- </data>
- <data name="EventSource_OpcodeCollision" xml:space="preserve">
- <value>Opcodes {0} and {1} are defined with the same value ({2}).</value>
- </data>
- <data name="EventSource_PinArrayOutOfRange" xml:space="preserve">
- <value>Pins are out of range.</value>
- </data>
- <data name="EventSource_RecursiveTypeDefinition" xml:space="preserve">
- <value>Recursive type definition is not supported.</value>
- </data>
- <data name="EventSource_SessionIdError" xml:space="preserve">
- <value>Bit position in AllKeywords ({0}) must equal the command argument named "EtwSessionKeyword" ({1}).</value>
- </data>
- <data name="EventSource_StopsFollowStarts" xml:space="preserve">
- <value>An event with stop suffix must follow a corresponding event with a start suffix.</value>
- </data>
- <data name="EventSource_TaskCollision" xml:space="preserve">
- <value>Tasks {0} and {1} are defined with the same value ({2}).</value>
- </data>
- <data name="EventSource_TaskOpcodePairReused" xml:space="preserve">
- <value>Event {0} (with ID {1}) has the same task/opcode pair as event {2} (with ID {3}).</value>
- </data>
- <data name="EventSource_TooManyArgs" xml:space="preserve">
- <value>Too many arguments.</value>
- </data>
- <data name="EventSource_TooManyFields" xml:space="preserve">
- <value>Too many fields in structure.</value>
- </data>
- <data name="EventSource_ToString" xml:space="preserve">
- <value>EventSource({0}, {1})</value>
- </data>
- <data name="EventSource_TraitEven" xml:space="preserve">
- <value>There must be an even number of trait strings (they are key-value pairs).</value>
- </data>
- <data name="EventSource_TypeMustBeSealedOrAbstract" xml:space="preserve">
- <value>Event source types must be sealed or abstract.</value>
- </data>
- <data name="EventSource_TypeMustDeriveFromEventSource" xml:space="preserve">
- <value>Event source types must derive from EventSource.</value>
- </data>
- <data name="EventSource_UndefinedChannel" xml:space="preserve">
- <value>Use of undefined channel value {0} for event {1}.</value>
- </data>
- <data name="EventSource_UndefinedKeyword" xml:space="preserve">
- <value>Use of undefined keyword value {0} for event {1}.</value>
- </data>
- <data name="EventSource_UndefinedOpcode" xml:space="preserve">
- <value>Use of undefined opcode value {0} for event {1}.</value>
- </data>
- <data name="EventSource_UnknownEtwTrait" xml:space="preserve">
- <value>Unknown ETW trait "{0}".</value>
- </data>
- <data name="EventSource_UnsupportedEventTypeInManifest" xml:space="preserve">
- <value>Unsupported type {0} in event source.</value>
- </data>
- <data name="EventSource_UnsupportedMessageProperty" xml:space="preserve">
- <value>Event {0} specifies an illegal or unsupported formatting message ("{1}").</value>
- </data>
- <data name="EventSource_VarArgsParameterMismatch" xml:space="preserve">
- <value>The parameters to the Event method do not match the parameters to the WriteEvent method. This may cause the event to be displayed incorrectly.</value>
- </data>
- <data name="Exception_EndOfInnerExceptionStack" xml:space="preserve">
- <value>--- End of inner exception stack trace ---</value>
- </data>
- <data name="Exception_EndStackTraceFromPreviousThrow" xml:space="preserve">
- <value>--- End of stack trace from previous location where exception was thrown ---</value>
- </data>
- <data name="Exception_WasThrown" xml:space="preserve">
- <value>Exception of type '{0}' was thrown.</value>
- </data>
- <data name="ExecutionContext_ExceptionInAsyncLocalNotification" xml:space="preserve">
- <value>An exception was not handled in an AsyncLocal&lt;T&gt; notification callback.</value>
- </data>
- <data name="FieldAccess_InitOnly" xml:space="preserve">
- <value>InitOnly (aka ReadOnly) fields can only be initialized in the type/instance constructor.</value>
- </data>
- <data name="FileNotFound_ResolveAssembly" xml:space="preserve">
- <value>Could not resolve assembly '{0}'.</value>
- </data>
- <data name="Format_AttributeUsage" xml:space="preserve">
- <value>Duplicate AttributeUsageAttribute found on attribute type {0}.</value>
- </data>
- <data name="Format_Bad7BitInt32" xml:space="preserve">
- <value>Too many bytes in what should have been a 7 bit encoded Int32.</value>
- </data>
- <data name="Format_BadBase" xml:space="preserve">
- <value>Invalid digits for the specified base.</value>
- </data>
- <data name="Format_BadBase64Char" xml:space="preserve">
- <value>The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.</value>
- </data>
- <data name="Format_BadBase64CharArrayLength" xml:space="preserve">
- <value>Invalid length for a Base-64 char array or string.</value>
- </data>
- <data name="Format_BadBoolean" xml:space="preserve">
- <value>String '{0}' was not recognized as a valid Boolean.</value>
- </data>
- <data name="Format_BadDatePattern" xml:space="preserve">
- <value>Could not determine the order of year, month, and date from '{0}'.</value>
- </data>
- <data name="Format_BadDateTime" xml:space="preserve">
- <value>String '{0}' was not recognized as a valid DateTime.</value>
- </data>
- <data name="Format_BadDateTimeCalendar" xml:space="preserve">
- <value>The DateTime represented by the string '{0}' is not supported in calendar '{1}'.</value>
- </data>
- <data name="Format_BadDayOfWeek" xml:space="preserve">
- <value>String '{0}' was not recognized as a valid DateTime because the day of week was incorrect.</value>
- </data>
- <data name="Format_BadFormatSpecifier" xml:space="preserve">
- <value>Format specifier '{0}' was invalid.</value>
- </data>
- <data name="Format_NoFormatSpecifier" xml:space="preserve">
- <value>No format specifiers were provided.</value>
- </data>
- <data name="Format_BadQuote" xml:space="preserve">
- <value>Cannot find a matching quote character for the character '{0}'.</value>
- </data>
- <data name="Format_BadTimeSpan" xml:space="preserve">
- <value>String '{0}' was not recognized as a valid TimeSpan.</value>
- </data>
- <data name="Format_DateOutOfRange" xml:space="preserve">
- <value>The DateTime represented by the string '{0}' is out of range.</value>
- </data>
- <data name="Format_EmptyInputString" xml:space="preserve">
- <value>Input string was either empty or contained only whitespace.</value>
- </data>
- <data name="Format_ExtraJunkAtEnd" xml:space="preserve">
- <value>Additional non-parsable characters are at the end of the string.</value>
- </data>
- <data name="Format_GuidBrace" xml:space="preserve">
- <value>Expected {0xdddddddd, etc}.</value>
- </data>
- <data name="Format_GuidBraceAfterLastNumber" xml:space="preserve">
- <value>Could not find a brace, or the length between the previous token and the brace was zero (i.e., '0x,'etc.).</value>
- </data>
- <data name="Format_GuidComma" xml:space="preserve">
- <value>Could not find a comma, or the length between the previous token and the comma was zero (i.e., '0x,'etc.).</value>
- </data>
- <data name="Format_GuidDashes" xml:space="preserve">
- <value>Dashes are in the wrong position for GUID parsing.</value>
- </data>
- <data name="Format_GuidEndBrace" xml:space="preserve">
- <value>Could not find the ending brace.</value>
- </data>
- <data name="Format_GuidHexPrefix" xml:space="preserve">
- <value>Expected 0x prefix.</value>
- </data>
- <data name="Format_GuidInvalidChar" xml:space="preserve">
- <value>Guid string should only contain hexadecimal characters.</value>
- </data>
- <data name="Format_GuidInvLen" xml:space="preserve">
- <value>Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).</value>
- </data>
- <data name="Format_GuidUnrecognized" xml:space="preserve">
- <value>Unrecognized Guid format.</value>
- </data>
- <data name="Format_IndexOutOfRange" xml:space="preserve">
- <value>Index (zero based) must be greater than or equal to zero and less than the size of the argument list.</value>
- </data>
- <data name="Format_InvalidEnumFormatSpecification" xml:space="preserve">
- <value>Format string can be only "G", "g", "X", "x", "F", "f", "D" or "d".</value>
- </data>
- <data name="Format_InvalidGuidFormatSpecification" xml:space="preserve">
- <value>Format string can be only "D", "d", "N", "n", "P", "p", "B", "b", "X" or "x".</value>
- </data>
- <data name="Format_InvalidString" xml:space="preserve">
- <value>Input string was not in a correct format.</value>
- </data>
- <data name="Format_MissingIncompleteDate" xml:space="preserve">
- <value>There must be at least a partial date with a year present in the input string '{0}'.</value>
- </data>
- <data name="Format_NeedSingleChar" xml:space="preserve">
- <value>String must be exactly one character long.</value>
- </data>
- <data name="Format_NoParsibleDigits" xml:space="preserve">
- <value>Could not find any recognizable digits.</value>
- </data>
- <data name="Format_OffsetOutOfRange" xml:space="preserve">
- <value>The time zone offset of string '{0}' must be within plus or minus 14 hours.</value>
- </data>
- <data name="Format_RepeatDateTimePattern" xml:space="preserve">
- <value>DateTime pattern '{0}' appears more than once with different values.</value>
- </data>
- <data name="Format_StringZeroLength" xml:space="preserve">
- <value>String cannot have zero length.</value>
- </data>
- <data name="Format_UnknownDateTimeWord" xml:space="preserve">
- <value>The string '{0}' was not recognized as a valid DateTime. There is an unknown word starting at index '{1}'.</value>
- </data>
- <data name="Format_UTCOutOfRange" xml:space="preserve">
- <value>The UTC representation of the date '{0}' falls outside the year range 1-9999.</value>
- </data>
- <data name="Globalization_cp_1200" xml:space="preserve">
- <value>Unicode</value>
- </data>
- <data name="Globalization_cp_12000" xml:space="preserve">
- <value>Unicode (UTF-32)</value>
- </data>
- <data name="Globalization_cp_12001" xml:space="preserve">
- <value>Unicode (UTF-32 Big-Endian)</value>
- </data>
- <data name="Globalization_cp_1201" xml:space="preserve">
- <value>Unicode (Big-Endian)</value>
- </data>
- <data name="Globalization_cp_20127" xml:space="preserve">
- <value>US-ASCII</value>
- </data>
- <data name="Globalization_cp_28591" xml:space="preserve">
- <value>Western European (ISO)</value>
- </data>
- <data name="Globalization_cp_65000" xml:space="preserve">
- <value>Unicode (UTF-7)</value>
- </data>
- <data name="Globalization_cp_65001" xml:space="preserve">
- <value>Unicode (UTF-8)</value>
- </data>
- <data name="IndexOutOfRange_ArrayRankIndex" xml:space="preserve">
- <value>Array does not have that many dimensions.</value>
- </data>
- <data name="IndexOutOfRange_UMSPosition" xml:space="preserve">
- <value>Unmanaged memory stream position was beyond the capacity of the stream.</value>
- </data>
- <data name="InsufficientMemory_MemFailPoint" xml:space="preserve">
- <value>Insufficient available memory to meet the expected demands of an operation at this time. Please try again later.</value>
- </data>
- <data name="InsufficientMemory_MemFailPoint_TooBig" xml:space="preserve">
- <value>Insufficient memory to meet the expected demands of an operation, and this system is likely to never satisfy this request. If this is a 32 bit system, consider booting in 3 GB mode.</value>
- </data>
- <data name="InsufficientMemory_MemFailPoint_VAFrag" xml:space="preserve">
- <value>Insufficient available memory to meet the expected demands of an operation at this time, possibly due to virtual address space fragmentation. Please try again later.</value>
- </data>
- <data name="Interop_COM_TypeMismatch" xml:space="preserve">
- <value>Type mismatch between source and destination types.</value>
- </data>
- <data name="Interop_Marshal_Unmappable_Char" xml:space="preserve">
- <value>Cannot marshal: Encountered unmappable character.</value>
- </data>
- <data name="InvalidCast_CannotCastNullToValueType" xml:space="preserve">
- <value>Null object cannot be converted to a value type.</value>
- </data>
- <data name="InvalidCast_CannotCoerceByRefVariant" xml:space="preserve">
- <value>Object cannot be coerced to the original type of the ByRef VARIANT it was obtained from.</value>
- </data>
- <data name="InvalidCast_DBNull" xml:space="preserve">
- <value>Object cannot be cast to DBNull.</value>
- </data>
- <data name="InvalidCast_DownCastArrayElement" xml:space="preserve">
- <value>At least one element in the source array could not be cast down to the destination array type.</value>
- </data>
- <data name="InvalidCast_Empty" xml:space="preserve">
- <value>Object cannot be cast to Empty.</value>
- </data>
- <data name="InvalidCast_FromDBNull" xml:space="preserve">
- <value>Object cannot be cast from DBNull to other types.</value>
- </data>
- <data name="InvalidCast_FromTo" xml:space="preserve">
- <value>Invalid cast from '{0}' to '{1}'.</value>
- </data>
- <data name="InvalidCast_IConvertible" xml:space="preserve">
- <value>Object must implement IConvertible.</value>
- </data>
- <data name="InvalidCast_OATypeMismatch" xml:space="preserve">
- <value>OleAut reported a type mismatch.</value>
- </data>
- <data name="InvalidCast_StoreArrayElement" xml:space="preserve">
- <value>Object cannot be stored in an array of this type.</value>
- </data>
- <data name="InvalidCast_WinRTIPropertyValueArrayCoersion" xml:space="preserve">
- <value>Object in an IPropertyValue is of type '{0}' which cannot be convereted to a '{1}' due to array element '{2}': {3}.</value>
- </data>
- <data name="InvalidCast_WinRTIPropertyValueCoersion" xml:space="preserve">
- <value>Object in an IPropertyValue is of type '{0}' with value '{1}', which cannot be converted to a '{2}'.</value>
- </data>
- <data name="InvalidCast_WinRTIPropertyValueElement" xml:space="preserve">
- <value>Object in an IPropertyValue is of type '{0}', which cannot be converted to a '{1}'.</value>
- </data>
- <data name="InvalidOperation_AsyncFlowCtrlCtxMismatch" xml:space="preserve">
- <value>AsyncFlowControl objects can be used to restore flow only on a Context that had its flow suppressed.</value>
- </data>
- <data name="InvalidOperation_AsyncIOInProgress" xml:space="preserve">
- <value>The stream is currently in use by a previous operation on the stream.</value>
- </data>
- <data name="InvalidOperation_BadEmptyMethodBody" xml:space="preserve">
- <value>Method '{0}' does not have a method body.</value>
- </data>
- <data name="InvalidOperation_BadILGeneratorUsage" xml:space="preserve">
- <value>ILGenerator usage is invalid.</value>
- </data>
- <data name="InvalidOperation_BadInstructionOrIndexOutOfBound" xml:space="preserve">
- <value>MSIL instruction is invalid or index is out of bounds.</value>
- </data>
- <data name="InvalidOperation_BadInterfaceNotAbstract" xml:space="preserve">
- <value>Interface must be declared abstract.</value>
- </data>
- <data name="InvalidOperation_BadMethodBody" xml:space="preserve">
- <value>Method '{0}' cannot have a method body.</value>
- </data>
- <data name="InvalidOperation_BadTypeAttributesNotAbstract" xml:space="preserve">
- <value>Type must be declared abstract if any of its methods are abstract.</value>
- </data>
- <data name="InvalidOperation_CalledTwice" xml:space="preserve">
- <value>The method cannot be called twice on the same instance.</value>
- </data>
- <data name="InvalidOperation_CannotImportGlobalFromDifferentModule" xml:space="preserve">
- <value>Unable to import a global method or field from a different module.</value>
- </data>
- <data name="InvalidOperation_CannotRemoveLastFromEmptyCollection" xml:space="preserve">
- <value>Cannot remove the last element from an empty collection.</value>
- </data>
- <data name="InvalidOperation_CannotRestoreUnsupressedFlow" xml:space="preserve">
- <value>Cannot restore context flow when it is not suppressed.</value>
- </data>
- <data name="InvalidOperation_CannotSupressFlowMultipleTimes" xml:space="preserve">
- <value>Context flow is already suppressed.</value>
- </data>
- <data name="InvalidOperation_CannotUseAFCMultiple" xml:space="preserve">
- <value>AsyncFlowControl object can be used only once to call Undo().</value>
- </data>
- <data name="InvalidOperation_CannotUseAFCOtherThread" xml:space="preserve">
- <value>AsyncFlowControl object must be used on the thread where it was created.</value>
- </data>
- <data name="InvalidOperation_CantInstantiateAbstractClass" xml:space="preserve">
- <value>Instances of abstract classes cannot be created.</value>
- </data>
- <data name="InvalidOperation_CantInstantiateFunctionPointer" xml:space="preserve">
- <value>Instances of function pointers cannot be created.</value>
- </data>
- <data name="InvalidOperation_CollectionBackingDictionaryTooLarge" xml:space="preserve">
- <value>The collection backing this Dictionary contains too many elements.</value>
- </data>
- <data name="InvalidOperation_CollectionBackingListTooLarge" xml:space="preserve">
- <value>The collection backing this List contains too many elements.</value>
- </data>
- <data name="InvalidOperation_CollectionCorrupted" xml:space="preserve">
- <value>A prior operation on this collection was interrupted by an exception. Collection's state is no longer trusted.</value>
- </data>
- <data name="InvalidOperation_ConcurrentOperationsNotSupported" xml:space="preserve">
- <value>Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.</value>
- </data>
- <data name="InvalidOperation_ConstructorNotAllowedOnInterface" xml:space="preserve">
- <value>Interface cannot have constructors.</value>
- </data>
- <data name="InvalidOperation_DateTimeParsing" xml:space="preserve">
- <value>Internal Error in DateTime and Calendar operations.</value>
- </data>
- <data name="InvalidOperation_DebuggerLaunchFailed" xml:space="preserve">
- <value>Debugger unable to launch.</value>
- </data>
- <data name="InvalidOperation_DefaultConstructorILGen" xml:space="preserve">
- <value>Unable to access ILGenerator on a constructor created with DefineDefaultConstructor.</value>
- </data>
- <data name="InvalidOperation_EndReadCalledMultiple" xml:space="preserve">
- <value>EndRead can only be called once for each asynchronous operation.</value>
- </data>
- <data name="InvalidOperation_EndWriteCalledMultiple" xml:space="preserve">
- <value>EndWrite can only be called once for each asynchronous operation.</value>
- </data>
- <data name="InvalidOperation_EnumEnded" xml:space="preserve">
- <value>Enumeration already finished.</value>
- </data>
- <data name="InvalidOperation_EnumFailedVersion" xml:space="preserve">
- <value>Collection was modified; enumeration operation may not execute.</value>
- </data>
- <data name="InvalidOperation_EnumNotStarted" xml:space="preserve">
- <value>Enumeration has not started. Call MoveNext.</value>
- </data>
- <data name="InvalidOperation_EnumOpCantHappen" xml:space="preserve">
- <value>Enumeration has either not started or has already finished.</value>
- </data>
- <data name="InvalidOperation_EventInfoNotAvailable" xml:space="preserve">
- <value>This API does not support EventInfo tokens.</value>
- </data>
- <data name="InvalidOperation_EventTokenTableRequiresDelegate" xml:space="preserve">
- <value>Type '{0}' is not a delegate type. EventTokenTable may only be used with delegate types.</value>
- </data>
- <data name="InvalidOperation_GenericParametersAlreadySet" xml:space="preserve">
- <value>The generic parameters are already defined on this MethodBuilder.</value>
- </data>
- <data name="InvalidOperation_GetVersion" xml:space="preserve">
- <value>OSVersion's call to GetVersionEx failed.</value>
- </data>
- <data name="InvalidOperation_GlobalsHaveBeenCreated" xml:space="preserve">
- <value>Type definition of the global function has been completed.</value>
- </data>
- <data name="InvalidOperation_HandleIsNotInitialized" xml:space="preserve">
- <value>Handle is not initialized.</value>
- </data>
- <data name="InvalidOperation_HandleIsNotPinned" xml:space="preserve">
- <value>Handle is not pinned.</value>
- </data>
- <data name="InvalidOperation_HashInsertFailed" xml:space="preserve">
- <value>Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.</value>
- </data>
- <data name="InvalidOperation_IComparerFailed" xml:space="preserve">
- <value>Failed to compare two elements in the array.</value>
- </data>
- <data name="InvalidOperation_MethodBaked" xml:space="preserve">
- <value>Type definition of the method is complete.</value>
- </data>
- <data name="InvalidOperation_MethodBuilderBaked" xml:space="preserve">
- <value>The signature of the MethodBuilder can no longer be modified because an operation on the MethodBuilder caused the methodDef token to be created. For example, a call to SetCustomAttribute requires the methodDef token to emit the CustomAttribute token.</value>
- </data>
- <data name="InvalidOperation_MethodHasBody" xml:space="preserve">
- <value>Method already has a body.</value>
- </data>
- <data name="InvalidOperation_MustCallInitialize" xml:space="preserve">
- <value>You must call Initialize on this object instance before using it.</value>
- </data>
- <data name="InvalidOperation_NativeOverlappedReused" xml:space="preserve">
- <value>NativeOverlapped cannot be reused for multiple operations.</value>
- </data>
- <data name="InvalidOperation_NoMultiModuleAssembly" xml:space="preserve">
- <value>You cannot have more than one dynamic module in each dynamic assembly in this version of the runtime.</value>
- </data>
- <data name="InvalidOperation_NoPublicAddMethod" xml:space="preserve">
- <value>Cannot add the event handler since no public add method exists for the event.</value>
- </data>
- <data name="InvalidOperation_NoPublicRemoveMethod" xml:space="preserve">
- <value>Cannot remove the event handler since no public remove method exists for the event.</value>
- </data>
- <data name="InvalidOperation_NotADebugModule" xml:space="preserve">
- <value>Not a debug ModuleBuilder.</value>
- </data>
- <data name="InvalidOperation_NotAllowedInDynamicMethod" xml:space="preserve">
- <value>The requested operation is invalid for DynamicMethod.</value>
- </data>
- <data name="InvalidOperation_NotAVarArgCallingConvention" xml:space="preserve">
- <value>Calling convention must be VarArgs.</value>
- </data>
- <data name="InvalidOperation_NotGenericType" xml:space="preserve">
- <value>This operation is only valid on generic types.</value>
- </data>
- <data name="InvalidOperation_NotSupportedOnWinRTEvent" xml:space="preserve">
- <value>Adding or removing event handlers dynamically is not supported on WinRT events.</value>
- </data>
- <data name="InvalidOperation_NotWithConcurrentGC" xml:space="preserve">
- <value>This API is not available when the concurrent GC is enabled.</value>
- </data>
- <data name="InvalidOperation_NoUnderlyingTypeOnEnum" xml:space="preserve">
- <value>Underlying type information on enumeration is not specified.</value>
- </data>
- <data name="InvalidOperation_NoValue" xml:space="preserve">
- <value>Nullable object must have a value.</value>
- </data>
- <data name="InvalidOperation_NullArray" xml:space="preserve">
- <value>The underlying array is null.</value>
- </data>
- <data name="InvalidOperation_NullContext" xml:space="preserve">
- <value>Cannot call Set on a null context</value>
- </data>
- <data name="InvalidOperation_NullModuleHandle" xml:space="preserve">
- <value>The requested operation is invalid when called on a null ModuleHandle.</value>
- </data>
- <data name="InvalidOperation_OpenLocalVariableScope" xml:space="preserve">
- <value>Local variable scope was not properly closed.</value>
- </data>
- <data name="InvalidOperation_Overlapped_Pack" xml:space="preserve">
- <value>Cannot pack a packed Overlapped again.</value>
- </data>
- <data name="InvalidOperation_PropertyInfoNotAvailable" xml:space="preserve">
- <value>This API does not support PropertyInfo tokens.</value>
- </data>
- <data name="InvalidOperation_ReadOnly" xml:space="preserve">
- <value>Instance is read-only.</value>
- </data>
- <data name="InvalidOperation_ResMgrBadResSet_Type" xml:space="preserve">
- <value>'{0}': ResourceSet derived classes must provide a constructor that takes a String file name and a constructor that takes a Stream.</value>
- </data>
- <data name="InvalidOperation_ResourceNotStream_Name" xml:space="preserve">
- <value>Resource '{0}' was not a Stream - call GetObject instead.</value>
- </data>
- <data name="InvalidOperation_ResourceNotString_Name" xml:space="preserve">
- <value>Resource '{0}' was not a String - call GetObject instead.</value>
- </data>
- <data name="InvalidOperation_ResourceNotString_Type" xml:space="preserve">
- <value>Resource was of type '{0}' instead of String - call GetObject instead.</value>
- </data>
- <data name="InvalidOperation_SetData_OnlyOnce" xml:space="preserve">
- <value>SetData can only be used to set the value of a given name once.</value>
- </data>
- <data name="InvalidOperation_ShouldNotHaveMethodBody" xml:space="preserve">
- <value>Method body should not exist.</value>
- </data>
- <data name="InvalidOperation_ThreadWrongThreadStart" xml:space="preserve">
- <value>The thread was created with a ThreadStart delegate that does not accept a parameter.</value>
- </data>
- <data name="InvalidOperation_TimeoutsNotSupported" xml:space="preserve">
- <value>Timeouts are not supported on this stream.</value>
- </data>
- <data name="InvalidOperation_TimerAlreadyClosed" xml:space="preserve">
- <value>The Timer was already closed using an incompatible Dispose method.</value>
- </data>
- <data name="InvalidOperation_TypeCannotBeBoxed" xml:space="preserve">
- <value>The given type cannot be boxed.</value>
- </data>
- <data name="InvalidOperation_TypeHasBeenCreated" xml:space="preserve">
- <value>Unable to change after type has been created.</value>
- </data>
- <data name="InvalidOperation_TypeNotCreated" xml:space="preserve">
- <value>Type has not been created.</value>
- </data>
- <data name="InvalidOperation_UnknownEnumType" xml:space="preserve">
- <value>Unknown enum type.</value>
- </data>
- <data name="InvalidOperation_WriteOnce" xml:space="preserve">
- <value>This property has already been set and cannot be modified.</value>
- </data>
- <data name="InvalidOperation_WrongAsyncResultOrEndCalledMultiple" xml:space="preserve">
- <value>Either the IAsyncResult object did not come from the corresponding async method on this type, or the End method was called multiple times with the same IAsyncResult.</value>
- </data>
- <data name="InvalidOperation_WrongAsyncResultOrEndReadCalledMultiple" xml:space="preserve">
- <value>Either the IAsyncResult object did not come from the corresponding async method on this type, or EndRead was called multiple times with the same IAsyncResult.</value>
- </data>
- <data name="InvalidOperation_WrongAsyncResultOrEndWriteCalledMultiple" xml:space="preserve">
- <value>Either the IAsyncResult object did not come from the corresponding async method on this type, or EndWrite was called multiple times with the same IAsyncResult.</value>
- </data>
- <data name="InvalidProgram_Default" xml:space="preserve">
- <value>Common Language Runtime detected an invalid program.</value>
- </data>
- <data name="InvalidTimeZone_InvalidFileData" xml:space="preserve">
- <value>The time zone ID '{0}' was found on the local computer, but the file at '{1}' was corrupt.</value>
- </data>
- <data name="InvalidTimeZone_InvalidRegistryData" xml:space="preserve">
- <value>The time zone ID '{0}' was found on the local computer, but the registry information was corrupt.</value>
- </data>
- <data name="InvalidTimeZone_InvalidJulianDay" xml:space="preserve">
- <value>Invalid Julian day in POSIX strings.</value>
- </data>
- <data name="InvalidTimeZone_NJulianDayNotSupported" xml:space="preserve">
- <value>Julian n day in POSIX strings is not supported.</value>
- </data>
- <data name="InvalidTimeZone_NoTTInfoStructures" xml:space="preserve">
- <value>There are no ttinfo structures in the tzfile. At least one ttinfo structure is required in order to construct a TimeZoneInfo object.</value>
- </data>
- <data name="InvalidTimeZone_UnparseablePosixMDateString" xml:space="preserve">
- <value>'{0}' is not a valid POSIX-TZ-environment-variable MDate rule. A valid rule has the format 'Mm.w.d'.</value>
- </data>
- <data name="InvariantFailed" xml:space="preserve">
- <value>Invariant failed.</value>
- </data>
- <data name="InvariantFailed_Cnd" xml:space="preserve">
- <value>Invariant failed: {0}</value>
- </data>
- <data name="IO_DriveNotFound_Drive" xml:space="preserve">
- <value>Could not find the drive '{0}'. The drive might not be ready or might not be mapped.</value>
- </data>
- <data name="IO_EOF_ReadBeyondEOF" xml:space="preserve">
- <value>Unable to read beyond the end of the stream.</value>
- </data>
- <data name="IO_FileLoad" xml:space="preserve">
- <value>Could not load the specified file.</value>
- </data>
- <data name="IO_FileName_Name" xml:space="preserve">
- <value>File name: '{0}'</value>
- </data>
- <data name="IO_FileNotFound" xml:space="preserve">
- <value>Unable to find the specified file.</value>
- </data>
- <data name="IO_FileNotFound_FileName" xml:space="preserve">
- <value>Could not find file '{0}'.</value>
- </data>
- <data name="IO_AlreadyExists_Name" xml:space="preserve">
- <value>Cannot create '{0}' because a file or directory with the same name already exists.</value>
- </data>
- <data name="IO_BindHandleFailed" xml:space="preserve">
- <value>BindHandle for ThreadPool failed on this handle.</value>
- </data>
- <data name="IO_FileExists_Name" xml:space="preserve">
- <value>The file '{0}' already exists.</value>
- </data>
- <data name="IO_FileStreamHandlePosition" xml:space="preserve">
- <value>The OS handle's position is not what FileStream expected. Do not use a handle simultaneously in one FileStream and in Win32 code or another FileStream. This may cause data loss.</value>
- </data>
- <data name="IO_FileTooLong2GB" xml:space="preserve">
- <value>The file is too long. This operation is currently limited to supporting files less than 2 gigabytes in size.</value>
- </data>
- <data name="IO_FileTooLongOrHandleNotSync" xml:space="preserve">
- <value>IO operation will not work. Most likely the file will become too long or the handle was not opened to support synchronous IO operations.</value>
- </data>
- <data name="IO_FixedCapacity" xml:space="preserve">
- <value>Unable to expand length of this stream beyond its capacity.</value>
- </data>
- <data name="IO_InvalidStringLen_Len" xml:space="preserve">
- <value>BinaryReader encountered an invalid string length of {0} characters.</value>
- </data>
- <data name="IO_SeekAppendOverwrite" xml:space="preserve">
- <value>Unable seek backward to overwrite data that previously existed in a file opened in Append mode.</value>
- </data>
- <data name="IO_SeekBeforeBegin" xml:space="preserve">
- <value>An attempt was made to move the position before the beginning of the stream.</value>
- </data>
- <data name="IO_SetLengthAppendTruncate" xml:space="preserve">
- <value>Unable to truncate data that previously existed in a file opened in Append mode.</value>
- </data>
- <data name="IO_SharingViolation_File" xml:space="preserve">
- <value>The process cannot access the file '{0}' because it is being used by another process.</value>
- </data>
- <data name="IO_SharingViolation_NoFileName" xml:space="preserve">
- <value>The process cannot access the file because it is being used by another process.</value>
- </data>
- <data name="IO_StreamTooLong" xml:space="preserve">
- <value>Stream was too long.</value>
- </data>
- <data name="IO_PathNotFound_NoPathName" xml:space="preserve">
- <value>Could not find a part of the path.</value>
- </data>
- <data name="IO_PathNotFound_Path" xml:space="preserve">
- <value>Could not find a part of the path '{0}'.</value>
- </data>
- <data name="IO_PathTooLong" xml:space="preserve">
- <value>The specified file name or path is too long, or a component of the specified path is too long.</value>
- </data>
- <data name="IO_PathTooLong_Path" xml:space="preserve">
- <value>The path '{0}' is too long, or a component of the specified path is too long.</value>
- </data>
- <data name="IO_UnknownFileName" xml:space="preserve">
- <value>[Unknown]</value>
- </data>
- <data name="Lazy_CreateValue_NoParameterlessCtorForT" xml:space="preserve">
- <value>The lazily-initialized type does not have a public, parameterless constructor.</value>
- </data>
- <data name="Lazy_ctor_ModeInvalid" xml:space="preserve">
- <value>The mode argument specifies an invalid value.</value>
- </data>
- <data name="Lazy_StaticInit_InvalidOperation" xml:space="preserve">
- <value>ValueFactory returned null.</value>
- </data>
- <data name="Lazy_ToString_ValueNotCreated" xml:space="preserve">
- <value>Value is not created.</value>
- </data>
- <data name="Lazy_Value_RecursiveCallsToValue" xml:space="preserve">
- <value>ValueFactory attempted to access the Value property of this instance.</value>
- </data>
- <data name="Loader_ContextPolicies" xml:space="preserve">
- <value>Context Policies:</value>
- </data>
- <data name="Loader_Name" xml:space="preserve">
- <value>Name:</value>
- </data>
- <data name="Loader_NoContextPolicies" xml:space="preserve">
- <value>There are no context policies.</value>
- </data>
- <data name="ManualResetEventSlim_ctor_SpinCountOutOfRange" xml:space="preserve">
- <value>The spinCount argument must be in the range 0 to {0}, inclusive.</value>
- </data>
- <data name="ManualResetEventSlim_ctor_TooManyWaiters" xml:space="preserve">
- <value>There are too many threads currently waiting on the event. A maximum of {0} waiting threads are supported.</value>
- </data>
- <data name="ManualResetEventSlim_Disposed" xml:space="preserve">
- <value>The event has been disposed.</value>
- </data>
- <data name="Marshaler_StringTooLong" xml:space="preserve">
- <value>Marshaler restriction: Excessively long string.</value>
- </data>
- <data name="MissingConstructor_Name" xml:space="preserve">
- <value>Constructor on type '{0}' not found.</value>
- </data>
- <data name="MissingField" xml:space="preserve">
- <value>Field not found.</value>
- </data>
- <data name="MissingField_Name" xml:space="preserve">
- <value>Field '{0}' not found.</value>
- </data>
- <data name="MissingManifestResource_LooselyLinked" xml:space="preserve">
- <value>Could not find a manifest resource entry called "{0}" in assembly "{1}". Please check spelling, capitalization, and build rules to ensure "{0}" is being linked into the assembly.</value>
- </data>
- <data name="MissingManifestResource_MultipleBlobs" xml:space="preserve">
- <value>A case-insensitive lookup for resource file "{0}" in assembly "{1}" found multiple entries. Remove the duplicates or specify the exact case.</value>
- </data>
- <data name="MissingManifestResource_NoNeutralAsm" xml:space="preserve">
- <value>Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "{0}" was correctly embedded or linked into assembly "{1}" at compile time, or that all the satellite assemblies required are loadable and fully signed.</value>
- </data>
- <data name="MissingManifestResource_NoNeutralDisk" xml:space="preserve">
- <value>Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.</value>
- </data>
- <data name="MissingManifestResource_NoPRIresources" xml:space="preserve">
- <value>Unable to open Package Resource Index.</value>
- </data>
- <data name="MissingManifestResource_ResWFileNotLoaded" xml:space="preserve">
- <value>Unable to load resources for resource file "{0}" in package "{1}".</value>
- </data>
- <data name="MissingMember" xml:space="preserve">
- <value>Member not found.</value>
- </data>
- <data name="MissingMember_Name" xml:space="preserve">
- <value>Member '{0}' not found.</value>
- </data>
- <data name="MissingMemberNestErr" xml:space="preserve">
- <value>TypedReference can only be made on nested value Types.</value>
- </data>
- <data name="MissingMemberTypeRef" xml:space="preserve">
- <value>FieldInfo does not match the target Type.</value>
- </data>
- <data name="MissingMethod_Name" xml:space="preserve">
- <value>Method '{0}' not found.</value>
- </data>
- <data name="MissingSatelliteAssembly_Culture_Name" xml:space="preserve">
- <value>The satellite assembly named "{1}" for fallback culture "{0}" either could not be found or could not be loaded. This is generally a setup problem. Please consider reinstalling or repairing the application.</value>
- </data>
- <data name="MissingSatelliteAssembly_Default" xml:space="preserve">
- <value>Resource lookup fell back to the ultimate fallback resources in a satellite assembly, but that satellite either was not found or could not be loaded. Please consider reinstalling or repairing the application.</value>
- </data>
- <data name="Multicast_Combine" xml:space="preserve">
- <value>Delegates that are not of type MulticastDelegate may not be combined.</value>
- </data>
- <data name="MustUseCCRewrite" xml:space="preserve">
- <value>An assembly (probably "{1}") must be rewritten using the code contracts binary rewriter (CCRewrite) because it is calling Contract.{0} and the CONTRACTS_FULL symbol is defined. Remove any explicit definitions of the CONTRACTS_FULL symbol from your project and rebuild. CCRewrite can be downloaded from http://go.microsoft.com/fwlink/?LinkID=169180. \r\nAfter the rewriter is installed, it can be enabled in Visual Studio from the project's Properties page on the Code Contracts pane. Ensure that "Perform Runtime Contract Checking" is enabled, which will define CONTRACTS_FULL.</value>
- </data>
- <data name="NotImplemented_ResourcesLongerThanInt64Max" xml:space="preserve">
- <value>Resource files longer than 2^63 bytes are not currently implemented.</value>
- </data>
- <data name="NotSupported_AbstractNonCLS" xml:space="preserve">
- <value>This non-CLS method is not implemented.</value>
- </data>
- <data name="NotSupported_ActivAttr" xml:space="preserve">
- <value>Activation Attributes are not supported.</value>
- </data>
- <data name="NotSupported_AppX" xml:space="preserve">
- <value>{0} is not supported in AppX.</value>
- </data>
- <data name="NotSupported_AssemblyLoadFromHash" xml:space="preserve">
- <value>Assembly.LoadFrom with hashValue is not supported.</value>
- </data>
- <data name="NotSupported_ByRefLike" xml:space="preserve">
- <value>Cannot create boxed ByRef-like values.</value>
- </data>
- <data name="NotSupported_ByRefLikeArray" xml:space="preserve">
- <value>Cannot create arrays of ByRef-like values.</value>
- </data>
- <data name="NotSupported_ByRefToByRefLikeReturn" xml:space="preserve">
- <value>ByRef to ByRef-like return values are not supported in reflection invocation.</value>
- </data>
- <data name="NotSupported_ByRefToVoidReturn" xml:space="preserve">
- <value>ByRef to void return values are not supported in reflection invocation.</value>
- </data>
- <data name="NotSupported_CallToVarArg" xml:space="preserve">
- <value>Vararg calling convention not supported.</value>
- </data>
- <data name="NotSupported_CannotCallEqualsOnSpan" xml:space="preserve">
- <value>Equals() on Span and ReadOnlySpan is not supported. Use operator== instead.</value>
- </data>
- <data name="NotSupported_CannotCallGetHashCodeOnSpan" xml:space="preserve">
- <value>GetHashCode() on Span and ReadOnlySpan is not supported.</value>
- </data>
- <data name="NotSupported_ChangeType" xml:space="preserve">
- <value>ChangeType operation is not supported.</value>
- </data>
- <data name="NotSupported_CollectibleAssemblyResolve" xml:space="preserve">
- <value>Resolving to a collectible assembly is not supported.</value>
- </data>
- <data name="NotSupported_CollectibleBoundNonCollectible" xml:space="preserve">
- <value>A non-collectible assembly may not reference a collectible assembly.</value>
- </data>
- <data name="NotSupported_CollectibleWinRT" xml:space="preserve">
- <value>WinRT Interop is not supported for collectible types.</value>
- </data>
- <data name="NotSupported_CreateInstanceWithTypeBuilder" xml:space="preserve">
- <value>CreateInstance cannot be used with an object of type TypeBuilder.</value>
- </data>
- <data name="NotSupported_DBNullSerial" xml:space="preserve">
- <value>Only one DBNull instance may exist, and calls to DBNull deserialization methods are not allowed.</value>
- </data>
- <data name="NotSupported_DelegateMarshalToWrongDomain" xml:space="preserve">
- <value>Delegates cannot be marshaled from native code into a domain other than their home domain.</value>
- </data>
- <data name="NotSupported_DelegateSerHolderSerial" xml:space="preserve">
- <value>DelegateSerializationHolder objects are designed to represent a delegate during serialization and are not serializable themselves.</value>
- </data>
- <data name="NotSupported_DynamicAssembly" xml:space="preserve">
- <value>The invoked member is not supported in a dynamic assembly.</value>
- </data>
- <data name="NotSupported_DynamicMethodFlags" xml:space="preserve">
- <value>Wrong MethodAttributes or CallingConventions for DynamicMethod. Only public, static, standard supported</value>
- </data>
- <data name="NotSupported_DynamicModule" xml:space="preserve">
- <value>The invoked member is not supported in a dynamic module.</value>
- </data>
- <data name="NotSupported_FileStreamOnNonFiles" xml:space="preserve">
- <value>FileStream was asked to open a device that was not a file. For support for devices like 'com1:' or 'lpt1:', call CreateFile, then use the FileStream constructors that take an OS handle as an IntPtr.</value>
- </data>
- <data name="NotSupported_FixedSizeCollection" xml:space="preserve">
- <value>Collection was of a fixed size.</value>
- </data>
- <data name="NotSupported_GenericMethod" xml:space="preserve">
- <value>Generic methods with NativeCallableAttribute are not supported.</value>
- </data>
- <data name="NotSupported_GlobalMethodSerialization" xml:space="preserve">
- <value>Serialization of global methods (including implicit serialization via the use of asynchronous delegates) is not supported.</value>
- </data>
- <data name="NotSupported_IDispInvokeDefaultMemberWithNamedArgs" xml:space="preserve">
- <value>Invoking default method with named arguments is not supported.</value>
- </data>
- <data name="NotSupported_IllegalOneByteBranch" xml:space="preserve">
- <value>Illegal one-byte branch at position: {0}. Requested branch was: {1}.</value>
- </data>
- <data name="NotSupported_KeyCollectionSet" xml:space="preserve">
- <value>Mutating a key collection derived from a dictionary is not allowed.</value>
- </data>
- <data name="NotSupported_ManagedActivation" xml:space="preserve">
- <value>Cannot create uninitialized instances of types requiring managed activation.</value>
- </data>
- <data name="NotSupported_MaxWaitHandles" xml:space="preserve">
- <value>The number of WaitHandles must be less than or equal to 64.</value>
- </data>
- <data name="NotSupported_MemStreamNotExpandable" xml:space="preserve">
- <value>Memory stream is not expandable.</value>
- </data>
- <data name="NotSupported_MustBeModuleBuilder" xml:space="preserve">
- <value>Module argument must be a ModuleBuilder.</value>
- </data>
- <data name="NotSupported_NativeCallableTarget" xml:space="preserve">
- <value>Methods with NativeCallableAttribute cannot be used as delegate target.</value>
- </data>
- <data name="NotSupported_NoCodepageData" xml:space="preserve">
- <value>No data is available for encoding {0}. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.</value>
- </data>
- <data name="NotSupported_NonBlittableTypes" xml:space="preserve">
- <value>Non-blittable parameter types are not supported for NativeCallable methods.</value>
- </data>
- <data name="NotSupported_NonReflectedType" xml:space="preserve">
- <value>Not supported in a non-reflected type.</value>
- </data>
- <data name="NotSupported_NonStaticMethod" xml:space="preserve">
- <value>Non-static methods with NativeCallableAttribute are not supported.</value>
- </data>
- <data name="NotSupported_NoParentDefaultConstructor" xml:space="preserve">
- <value>Parent does not have a default constructor. The default constructor must be explicitly defined.</value>
- </data>
- <data name="NotSupported_NoTypeInfo" xml:space="preserve">
- <value>Cannot resolve {0} to a TypeInfo object.</value>
- </data>
- <data name="NotSupported_NYI" xml:space="preserve">
- <value>This feature is not currently implemented.</value>
- </data>
- <data name="NotSupported_ObsoleteResourcesFile" xml:space="preserve">
- <value>Found an obsolete .resources file in assembly '{0}'. Rebuild that .resources file then rebuild that assembly.</value>
- </data>
- <data name="NotSupported_OleAutBadVarType" xml:space="preserve">
- <value>The given Variant type is not supported by this OleAut function.</value>
- </data>
- <data name="NotSupported_OpenType" xml:space="preserve">
- <value>Cannot create arrays of open type.</value>
- </data>
- <data name="NotSupported_OutputStreamUsingTypeBuilder" xml:space="preserve">
- <value>Output streams do not support TypeBuilders.</value>
- </data>
- <data name="NotSupported_PIAInAppxProcess" xml:space="preserve">
- <value>A Primary Interop Assembly is not supported in AppX.</value>
- </data>
- <data name="NotSupported_Reading" xml:space="preserve">
- <value>Accessor does not support reading.</value>
- </data>
- <data name="NotSupported_ReadOnlyCollection" xml:space="preserve">
- <value>Collection is read-only.</value>
- </data>
- <data name="NotSupported_ResourceObjectSerialization" xml:space="preserve">
- <value>Cannot read resources that depend on serialization.</value>
- </data>
- <data name="NotSupported_SignalAndWaitSTAThread" xml:space="preserve">
- <value>SignalAndWait on a STA thread is not supported.</value>
- </data>
- <data name="NotSupported_StringComparison" xml:space="preserve">
- <value>The string comparison type passed in is currently not supported.</value>
- </data>
- <data name="NotSupported_SubclassOverride" xml:space="preserve">
- <value>Derived classes must provide an implementation.</value>
- </data>
- <data name="NotSupported_SymbolMethod" xml:space="preserve">
- <value>Not supported in an array method of a type definition that is not complete.</value>
- </data>
- <data name="NotSupported_TooManyArgs" xml:space="preserve">
- <value>Stack size too deep. Possibly too many arguments.</value>
- </data>
- <data name="NotSupported_Type" xml:space="preserve">
- <value>Type is not supported.</value>
- </data>
- <data name="NotSupported_TypeCannotDeserialized" xml:space="preserve">
- <value>Direct deserialization of type '{0}' is not supported.</value>
- </data>
- <data name="NotSupported_TypeNotYetCreated" xml:space="preserve">
- <value>The invoked member is not supported before the type is created.</value>
- </data>
- <data name="NotSupported_UmsSafeBuffer" xml:space="preserve">
- <value>This operation is not supported for an UnmanagedMemoryStream created from a SafeBuffer.</value>
- </data>
- <data name="NotSupported_UnitySerHolder" xml:space="preserve">
- <value>The UnitySerializationHolder object is designed to transmit information about other types and is not serializable itself.</value>
- </data>
- <data name="NotSupported_UnknownTypeCode" xml:space="preserve">
- <value>TypeCode '{0}' was not valid.</value>
- </data>
- <data name="NotSupported_WaitAllSTAThread" xml:space="preserve">
- <value>WaitAll for multiple handles on a STA thread is not supported.</value>
- </data>
- <data name="NotSupported_UnreadableStream" xml:space="preserve">
- <value>Stream does not support reading.</value>
- </data>
- <data name="NotSupported_UnseekableStream" xml:space="preserve">
- <value>Stream does not support seeking.</value>
- </data>
- <data name="NotSupported_UnwritableStream" xml:space="preserve">
- <value>Stream does not support writing.</value>
- </data>
- <data name="NotSupported_ValueClassCM" xml:space="preserve">
- <value>Custom marshalers for value types are not currently supported.</value>
- </data>
- <data name="NotSupported_ValueCollectionSet" xml:space="preserve">
- <value>Mutating a value collection derived from a dictionary is not allowed.</value>
- </data>
- <data name="NotSupported_VoidArray" xml:space="preserve">
- <value>Arrays of System.Void are not supported.</value>
- </data>
- <data name="NotSupported_WinRT_PartialTrust" xml:space="preserve">
- <value>Windows Runtime is not supported in partial trust.</value>
- </data>
- <data name="NotSupported_Writing" xml:space="preserve">
- <value>Accessor does not support writing.</value>
- </data>
- <data name="NotSupported_WrongResourceReader_Type" xml:space="preserve">
- <value>This .resources file should not be read with this reader. The resource reader type is "{0}".</value>
- </data>
- <data name="NullReference_This" xml:space="preserve">
- <value>The pointer for this method was null.</value>
- </data>
- <data name="ObjectDisposed_FileClosed" xml:space="preserve">
- <value>Cannot access a closed file.</value>
- </data>
- <data name="ObjectDisposed_Generic" xml:space="preserve">
- <value>Cannot access a disposed object.</value>
- </data>
- <data name="ObjectDisposed_ObjectName_Name" xml:space="preserve">
- <value>Object name: '{0}'.</value>
- </data>
- <data name="ObjectDisposed_WriterClosed" xml:space="preserve">
- <value>Cannot write to a closed TextWriter.</value>
- </data>
- <data name="ObjectDisposed_ReaderClosed" xml:space="preserve">
- <value>Cannot read from a closed TextReader.</value>
- </data>
- <data name="ObjectDisposed_ResourceSet" xml:space="preserve">
- <value>Cannot access a closed resource set.</value>
- </data>
- <data name="ObjectDisposed_StreamClosed" xml:space="preserve">
- <value>Cannot access a closed Stream.</value>
- </data>
- <data name="ObjectDisposed_ViewAccessorClosed" xml:space="preserve">
- <value>Cannot access a closed accessor.</value>
- </data>
- <data name="OperationCanceled" xml:space="preserve">
- <value>The operation was canceled.</value>
- </data>
- <data name="OutOfMemory_GCHandleMDA" xml:space="preserve">
- <value>The GCHandle MDA has run out of available cookies.</value>
- </data>
- <data name="Overflow_Byte" xml:space="preserve">
- <value>Value was either too large or too small for an unsigned byte.</value>
- </data>
- <data name="Overflow_Char" xml:space="preserve">
- <value>Value was either too large or too small for a character.</value>
- </data>
- <data name="Overflow_Currency" xml:space="preserve">
- <value>Value was either too large or too small for a Currency.</value>
- </data>
- <data name="Overflow_Decimal" xml:space="preserve">
- <value>Value was either too large or too small for a Decimal.</value>
- </data>
- <data name="Overflow_Duration" xml:space="preserve">
- <value>The duration cannot be returned for TimeSpan.MinValue because the absolute value of TimeSpan.MinValue exceeds the value of TimeSpan.MaxValue.</value>
- </data>
- <data name="Overflow_Int16" xml:space="preserve">
- <value>Value was either too large or too small for an Int16.</value>
- </data>
- <data name="Overflow_Int32" xml:space="preserve">
- <value>Value was either too large or too small for an Int32.</value>
- </data>
- <data name="Overflow_Int64" xml:space="preserve">
- <value>Value was either too large or too small for an Int64.</value>
- </data>
- <data name="Overflow_NegateTwosCompNum" xml:space="preserve">
- <value>Negating the minimum value of a twos complement number is invalid.</value>
- </data>
- <data name="Overflow_NegativeUnsigned" xml:space="preserve">
- <value>The string was being parsed as an unsigned number and could not have a negative sign.</value>
- </data>
- <data name="Overflow_SByte" xml:space="preserve">
- <value>Value was either too large or too small for a signed byte.</value>
- </data>
- <data name="Overflow_TimeSpanElementTooLarge" xml:space="preserve">
- <value>The TimeSpan string '{0}' could not be parsed because at least one of the numeric components is out of range or contains too many digits.</value>
- </data>
- <data name="Overflow_TimeSpanTooLong" xml:space="preserve">
- <value>TimeSpan overflowed because the duration is too long.</value>
- </data>
- <data name="Overflow_UInt16" xml:space="preserve">
- <value>Value was either too large or too small for a UInt16.</value>
- </data>
- <data name="Overflow_UInt32" xml:space="preserve">
- <value>Value was either too large or too small for a UInt32.</value>
- </data>
- <data name="Overflow_UInt64" xml:space="preserve">
- <value>Value was either too large or too small for a UInt64.</value>
- </data>
- <data name="PlatformNotSupported_ArgIterator" xml:space="preserve">
- <value>ArgIterator is not supported on this platform.</value>
- </data>
- <data name="PlatformNotSupported_ComInterop" xml:space="preserve">
- <value>COM Interop is not supported on this platform.</value>
- </data>
- <data name="PlatformNotSupported_NamedSynchronizationPrimitives" xml:space="preserve">
- <value>The named version of this synchronization primitive is not supported on this platform.</value>
- </data>
- <data name="PlatformNotSupported_NamedSyncObjectWaitAnyWaitAll" xml:space="preserve">
- <value>Wait operations on multiple wait handles including a named synchronization primitive are not supported on this platform.</value>
- </data>
- <data name="PlatformNotSupported_OSXFileLocking" xml:space="preserve">
- <value>Locking/unlocking file regions is not supported on this platform. Use FileShare on the entire file instead.</value>
- </data>
- <data name="PlatformNotSupported_ReflectionOnly" xml:space="preserve">
- <value>ReflectionOnly loading is not supported on this platform.</value>
- </data>
- <data name="PlatformNotSupported_Remoting" xml:space="preserve">
- <value>Remoting is not supported on this platform.</value>
- </data>
- <data name="PlatformNotSupported_SecureBinarySerialization" xml:space="preserve">
- <value>Secure binary serialization is not supported on this platform.</value>
- </data>
- <data name="PlatformNotSupported_StrongNameSigning" xml:space="preserve">
- <value>Strong-name signing is not supported on this platform.</value>
- </data>
- <data name="PlatformNotSupported_WinRT" xml:space="preserve">
- <value>Windows Runtime is not supported on this operating system.</value>
- </data>
- <data name="PlatformNotSupported_OverlappedIO" xml:space="preserve">
- <value>This API is specific to the way in which Windows handles asynchronous I/O, and is not supported on this platform.</value>
- </data>
- <data name="PlatformNotSupported_ITypeInfo" xml:space="preserve">
- <value>Marshalling a System.Type to an unmanaged ITypeInfo or marshalling an ITypeInfo to a System.Type is not supported on this platform.</value>
- </data>
- <data name="PlatformNotSupported_IExpando" xml:space="preserve">
- <value>Marshalling an IDispatchEx to an IReflect or IExpando is not supported on this platform.</value>
- </data>
- <data name="Policy_CannotLoadSemiTrustAssembliesDuringInit" xml:space="preserve">
- <value>All assemblies loaded as part of AppDomain initialization must be fully trusted.</value>
- </data>
- <data name="PostconditionFailed" xml:space="preserve">
- <value>Postcondition failed.</value>
- </data>
- <data name="PostconditionFailed_Cnd" xml:space="preserve">
- <value>Postcondition failed: {0}</value>
- </data>
- <data name="PostconditionOnExceptionFailed" xml:space="preserve">
- <value>Postcondition failed after throwing an exception.</value>
- </data>
- <data name="PostconditionOnExceptionFailed_Cnd" xml:space="preserve">
- <value>Postcondition failed after throwing an exception: {0}</value>
- </data>
- <data name="PreconditionFailed" xml:space="preserve">
- <value>Precondition failed.</value>
- </data>
- <data name="PreconditionFailed_Cnd" xml:space="preserve">
- <value>Precondition failed: {0}</value>
- </data>
- <data name="Rank_MultiDimNotSupported" xml:space="preserve">
- <value>Only single dimension arrays are supported here.</value>
- </data>
- <data name="Rank_MustMatch" xml:space="preserve">
- <value>The specified arrays must have the same number of dimensions.</value>
- </data>
- <data name="ReflectionTypeLoad_LoadFailed" xml:space="preserve">
- <value>Unable to load one or more of the requested types.</value>
- </data>
- <data name="ResourceReaderIsClosed" xml:space="preserve">
- <value>ResourceReader is closed.</value>
- </data>
- <data name="Resources_StreamNotValid" xml:space="preserve">
- <value>Stream is not a valid resource file.</value>
- </data>
- <data name="RFLCT_AmbigCust" xml:space="preserve">
- <value>Multiple custom attributes of the same type found.</value>
- </data>
- <data name="RFLCT_Ambiguous" xml:space="preserve">
- <value>Ambiguous match found.</value>
- </data>
- <data name="InvalidFilterCriteriaException_CritInt" xml:space="preserve">
- <value>An Int32 must be provided for the filter criteria.</value>
- </data>
- <data name="InvalidFilterCriteriaException_CritString" xml:space="preserve">
- <value>A String must be provided for the filter criteria.</value>
- </data>
- <data name="RFLCT_InvalidFieldFail" xml:space="preserve">
- <value>'{0}' field specified was not found.</value>
- </data>
- <data name="RFLCT_InvalidPropFail" xml:space="preserve">
- <value>'{0}' property specified was not found.</value>
- </data>
- <data name="RFLCT_Targ_ITargMismatch" xml:space="preserve">
- <value>Object does not match target type.</value>
- </data>
- <data name="RFLCT_Targ_StatFldReqTarg" xml:space="preserve">
- <value>Non-static field requires a target.</value>
- </data>
- <data name="RFLCT_Targ_StatMethReqTarg" xml:space="preserve">
- <value>Non-static method requires a target.</value>
- </data>
- <data name="RuntimeWrappedException" xml:space="preserve">
- <value>An object that does not derive from System.Exception has been wrapped in a RuntimeWrappedException.</value>
- </data>
- <data name="Security_CannotReadFileData" xml:space="preserve">
- <value>The time zone ID '{0}' was found on the local computer, but the application does not have permission to read the file.</value>
- </data>
- <data name="Security_CannotReadRegistryData" xml:space="preserve">
- <value>The time zone ID '{0}' was found on the local computer, but the application does not have permission to read the registry information.</value>
- </data>
- <data name="Security_RegistryPermission" xml:space="preserve">
- <value>Requested registry access is not allowed.</value>
- </data>
- <data name="SemaphoreSlim_ctor_InitialCountWrong" xml:space="preserve">
- <value>The initialCount argument must be non-negative and less than or equal to the maximumCount.</value>
- </data>
- <data name="SemaphoreSlim_ctor_MaxCountWrong" xml:space="preserve">
- <value>The maximumCount argument must be a positive number. If a maximum is not required, use the constructor without a maxCount parameter.</value>
- </data>
- <data name="SemaphoreSlim_Disposed" xml:space="preserve">
- <value>The semaphore has been disposed.</value>
- </data>
- <data name="SemaphoreSlim_Release_CountWrong" xml:space="preserve">
- <value>The releaseCount argument must be greater than zero.</value>
- </data>
- <data name="SemaphoreSlim_Wait_TimeoutWrong" xml:space="preserve">
- <value>The timeout must represent a value between -1 and Int32.MaxValue, inclusive.</value>
- </data>
- <data name="Serialization_BadParameterInfo" xml:space="preserve">
- <value>Non existent ParameterInfo. Position bigger than member's parameters length.</value>
- </data>
- <data name="Serialization_CorruptField" xml:space="preserve">
- <value>The value of the field '{0}' is invalid. The serialized data is corrupt.</value>
- </data>
- <data name="Serialization_DateTimeTicksOutOfRange" xml:space="preserve">
- <value>Invalid serialized DateTime data. Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.</value>
- </data>
- <data name="Serialization_DelegatesNotSupported" xml:space="preserve">
- <value>Serializing delegates is not supported on this platform.</value>
- </data>
- <data name="Serialization_InsufficientDeserializationState" xml:space="preserve">
- <value>Insufficient state to deserialize the object. Missing field '{0}'. More information is needed.</value>
- </data>
- <data name="Serialization_InsufficientState" xml:space="preserve">
- <value>Insufficient state to return the real object.</value>
- </data>
- <data name="Serialization_InvalidData" xml:space="preserve">
- <value>An error occurred while deserializing the object. The serialized data is corrupt.</value>
- </data>
- <data name="Serialization_InvalidDelegateType" xml:space="preserve">
- <value>Cannot serialize delegates over unmanaged function pointers, dynamic methods or methods outside the delegate creator's assembly.</value>
- </data>
- <data name="Serialization_InvalidEscapeSequence" xml:space="preserve">
- <value>The serialized data contained an invalid escape sequence '\\{0}'.</value>
- </data>
- <data name="Serialization_InvalidFieldState" xml:space="preserve">
- <value>Object fields may not be properly initialized.</value>
- </data>
- <data name="Serialization_InvalidOnDeser" xml:space="preserve">
- <value>OnDeserialization method was called while the object was not being deserialized.</value>
- </data>
- <data name="Serialization_InvalidPtrValue" xml:space="preserve">
- <value>An IntPtr or UIntPtr with an eight byte value cannot be deserialized on a machine with a four byte word size.</value>
- </data>
- <data name="Serialization_InvalidType" xml:space="preserve">
- <value>Only system-provided types can be passed to the GetUninitializedObject method. '{0}' is not a valid instance of a type.</value>
- </data>
- <data name="Serialization_KeyValueDifferentSizes" xml:space="preserve">
- <value>The keys and values arrays have different sizes.</value>
- </data>
- <data name="Serialization_MemberOutOfRange" xml:space="preserve">
- <value>The deserialized value of the member "{0}" in the class "{1}" is out of range.</value>
- </data>
- <data name="Serialization_MemberTypeNotRecognized" xml:space="preserve">
- <value>Unknown member type.</value>
- </data>
- <data name="Serialization_MissField" xml:space="preserve">
- <value>Field {0} is missing.</value>
- </data>
- <data name="Serialization_MissingDateTimeData" xml:space="preserve">
- <value>Invalid serialized DateTime data. Unable to find 'ticks' or 'dateData'.</value>
- </data>
- <data name="Serialization_MissingKeys" xml:space="preserve">
- <value>The Keys for this Hashtable are missing.</value>
- </data>
- <data name="Serialization_MissingValues" xml:space="preserve">
- <value>The values for this dictionary are missing.</value>
- </data>
- <data name="Serialization_NonSerType" xml:space="preserve">
- <value>Type '{0}' in Assembly '{1}' is not marked as serializable.</value>
- </data>
- <data name="Serialization_NoParameterInfo" xml:space="preserve">
- <value>Serialized member does not have a ParameterInfo.</value>
- </data>
- <data name="Serialization_NotFound" xml:space="preserve">
- <value>Member '{0}' was not found.</value>
- </data>
- <data name="Serialization_NullKey" xml:space="preserve">
- <value>One of the serialized keys is null.</value>
- </data>
- <data name="Serialization_NullSignature" xml:space="preserve">
- <value>The method signature cannot be null.</value>
- </data>
- <data name="Serialization_OptionalFieldVersionValue" xml:space="preserve">
- <value>Version value must be positive.</value>
- </data>
- <data name="Serialization_SameNameTwice" xml:space="preserve">
- <value>Cannot add the same member twice to a SerializationInfo object.</value>
- </data>
- <data name="Serialization_StringBuilderCapacity" xml:space="preserve">
- <value>The serialized Capacity property of StringBuilder must be positive, less than or equal to MaxCapacity and greater than or equal to the String length.</value>
- </data>
- <data name="Serialization_StringBuilderMaxCapacity" xml:space="preserve">
- <value>The serialized MaxCapacity property of StringBuilder must be positive and greater than or equal to the String length.</value>
- </data>
- <data name="Serialization_UnableToFindModule" xml:space="preserve">
- <value>The given module {0} cannot be found within the assembly {1}.</value>
- </data>
- <data name="Serialization_UnknownMember" xml:space="preserve">
- <value>Cannot get the member '{0}'.</value>
- </data>
- <data name="SpinLock_Exit_SynchronizationLockException" xml:space="preserve">
- <value>The calling thread does not hold the lock.</value>
- </data>
- <data name="SpinLock_IsHeldByCurrentThread" xml:space="preserve">
- <value>Thread tracking is disabled.</value>
- </data>
- <data name="SpinLock_TryEnter_ArgumentOutOfRange" xml:space="preserve">
- <value>The timeout must be a value between -1 and Int32.MaxValue, inclusive.</value>
- </data>
- <data name="SpinLock_TryEnter_LockRecursionException" xml:space="preserve">
- <value>The calling thread already holds the lock.</value>
- </data>
- <data name="SpinLock_TryReliableEnter_ArgumentException" xml:space="preserve">
- <value>The tookLock argument must be set to false before calling this method.</value>
- </data>
- <data name="SpinWait_SpinUntil_ArgumentNull" xml:space="preserve">
- <value>The condition argument is null.</value>
- </data>
- <data name="SpinWait_SpinUntil_TimeoutWrong" xml:space="preserve">
- <value>The timeout must represent a value between -1 and Int32.MaxValue, inclusive.</value>
- </data>
- <data name="StackTrace_InFileLineNumber" xml:space="preserve">
- <value>in {0}:line {1}</value>
- </data>
- <data name="Task_ContinueWith_ESandLR" xml:space="preserve">
- <value>The specified TaskContinuationOptions combined LongRunning and ExecuteSynchronously. Synchronous continuations should not be long running.</value>
- </data>
- <data name="Task_ContinueWith_NotOnAnything" xml:space="preserve">
- <value>The specified TaskContinuationOptions excluded all continuation kinds.</value>
- </data>
- <data name="Task_Delay_InvalidDelay" xml:space="preserve">
- <value>The value needs to translate in milliseconds to -1 (signifying an infinite timeout), 0 or a positive integer less than or equal to Int32.MaxValue.</value>
- </data>
- <data name="Task_Delay_InvalidMillisecondsDelay" xml:space="preserve">
- <value>The value needs to be either -1 (signifying an infinite timeout), 0 or a positive integer.</value>
- </data>
- <data name="Task_Dispose_NotCompleted" xml:space="preserve">
- <value>A task may only be disposed if it is in a completion state (RanToCompletion, Faulted or Canceled).</value>
- </data>
- <data name="Task_FromAsync_LongRunning" xml:space="preserve">
- <value>It is invalid to specify TaskCreationOptions.LongRunning in calls to FromAsync.</value>
- </data>
- <data name="Task_FromAsync_PreferFairness" xml:space="preserve">
- <value>It is invalid to specify TaskCreationOptions.PreferFairness in calls to FromAsync.</value>
- </data>
- <data name="Task_MultiTaskContinuation_EmptyTaskList" xml:space="preserve">
- <value>The tasks argument contains no tasks.</value>
- </data>
- <data name="Task_MultiTaskContinuation_FireOptions" xml:space="preserve">
- <value>It is invalid to exclude specific continuation kinds for continuations off of multiple tasks.</value>
- </data>
- <data name="Task_MultiTaskContinuation_NullTask" xml:space="preserve">
- <value>The tasks argument included a null value.</value>
- </data>
- <data name="Task_RunSynchronously_AlreadyStarted" xml:space="preserve">
- <value>RunSynchronously may not be called on a task that was already started.</value>
- </data>
- <data name="Task_RunSynchronously_Continuation" xml:space="preserve">
- <value>RunSynchronously may not be called on a continuation task.</value>
- </data>
- <data name="Task_RunSynchronously_Promise" xml:space="preserve">
- <value>RunSynchronously may not be called on a task not bound to a delegate, such as the task returned from an asynchronous method.</value>
- </data>
- <data name="Task_RunSynchronously_TaskCompleted" xml:space="preserve">
- <value>RunSynchronously may not be called on a task that has already completed.</value>
- </data>
- <data name="Task_Start_AlreadyStarted" xml:space="preserve">
- <value>Start may not be called on a task that was already started.</value>
- </data>
- <data name="Task_Start_ContinuationTask" xml:space="preserve">
- <value>Start may not be called on a continuation task.</value>
- </data>
- <data name="Task_Start_Promise" xml:space="preserve">
- <value>Start may not be called on a promise-style task.</value>
- </data>
- <data name="Task_Start_TaskCompleted" xml:space="preserve">
- <value>Start may not be called on a task that has completed.</value>
- </data>
- <data name="Task_ThrowIfDisposed" xml:space="preserve">
- <value>The task has been disposed.</value>
- </data>
- <data name="Task_WaitMulti_NullTask" xml:space="preserve">
- <value>The tasks array included at least one null element.</value>
- </data>
- <data name="TaskCanceledException_ctor_DefaultMessage" xml:space="preserve">
- <value>A task was canceled.</value>
- </data>
- <data name="TaskCompletionSourceT_TrySetException_NoExceptions" xml:space="preserve">
- <value>The exceptions collection was empty.</value>
- </data>
- <data name="TaskCompletionSourceT_TrySetException_NullException" xml:space="preserve">
- <value>The exceptions collection included at least one null element.</value>
- </data>
- <data name="TaskExceptionHolder_UnhandledException" xml:space="preserve">
- <value>A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.</value>
- </data>
- <data name="TaskExceptionHolder_UnknownExceptionType" xml:space="preserve">
- <value>(Internal)Expected an Exception or an IEnumerable&lt;Exception&gt;</value>
- </data>
- <data name="TaskScheduler_ExecuteTask_WrongTaskScheduler" xml:space="preserve">
- <value>ExecuteTask may not be called for a task which was previously queued to a different TaskScheduler.</value>
- </data>
- <data name="TaskScheduler_FromCurrentSynchronizationContext_NoCurrent" xml:space="preserve">
- <value>The current SynchronizationContext may not be used as a TaskScheduler.</value>
- </data>
- <data name="TaskScheduler_InconsistentStateAfterTryExecuteTaskInline" xml:space="preserve">
- <value>The TryExecuteTaskInline call to the underlying scheduler succeeded, but the task body was not invoked.</value>
- </data>
- <data name="TaskSchedulerException_ctor_DefaultMessage" xml:space="preserve">
- <value>An exception was thrown by a TaskScheduler.</value>
- </data>
- <data name="TaskT_DebuggerNoResult" xml:space="preserve">
- <value>{Not yet computed}</value>
- </data>
- <data name="TaskT_TransitionToFinal_AlreadyCompleted" xml:space="preserve">
- <value>An attempt was made to transition a task to a final state when it had already completed.</value>
- </data>
- <data name="Threading_AbandonedMutexException" xml:space="preserve">
- <value>The wait completed due to an abandoned mutex.</value>
- </data>
- <data name="Threading_WaitHandleCannotBeOpenedException" xml:space="preserve">
- <value>No handle of the given name exists.</value>
- </data>
- <data name="Threading_WaitHandleCannotBeOpenedException_InvalidHandle" xml:space="preserve">
- <value>A WaitHandle with system-wide name '{0}' cannot be created. A WaitHandle of a different type might have the same name.</value>
- </data>
- <data name="Threading_WaitHandleTooManyPosts" xml:space="preserve">
- <value>The WaitHandle cannot be signaled because it would exceed its maximum count.</value>
- </data>
- <data name="Threading_SemaphoreFullException" xml:space="preserve">
- <value>Adding the specified count to the semaphore would cause it to exceed its maximum count.</value>
- </data>
- <data name="Threading_ThreadInterrupted" xml:space="preserve">
- <value>Thread was interrupted from a waiting state.</value>
- </data>
- <data name="ThreadLocal_Disposed" xml:space="preserve">
- <value>The ThreadLocal object has been disposed.</value>
- </data>
- <data name="ThreadLocal_Value_RecursiveCallsToValue" xml:space="preserve">
- <value>ValueFactory attempted to access the Value property of this instance.</value>
- </data>
- <data name="ThreadLocal_ValuesNotAvailable" xml:space="preserve">
- <value>The ThreadLocal object is not tracking values. To use the Values property, use a ThreadLocal constructor that accepts the trackAllValues parameter and set the parameter to true.</value>
- </data>
- <data name="TimeZoneNotFound_MissingData" xml:space="preserve">
- <value>The time zone ID '{0}' was not found on the local computer.</value>
- </data>
- <data name="TypeInitialization_Default" xml:space="preserve">
- <value>Type constructor threw an exception.</value>
- </data>
- <data name="TypeInitialization_Type" xml:space="preserve">
- <value>The type initializer for '{0}' threw an exception.</value>
- </data>
- <data name="TypeLoad_ResolveNestedType" xml:space="preserve">
- <value>Could not resolve nested type '{0}' in type "{1}'.</value>
- </data>
- <data name="TypeLoad_ResolveType" xml:space="preserve">
- <value>Could not resolve type '{0}'.</value>
- </data>
- <data name="TypeLoad_ResolveTypeFromAssembly" xml:space="preserve">
- <value>Could not resolve type '{0}' in assembly '{1}'.</value>
- </data>
- <data name="UnauthorizedAccess_IODenied_NoPathName" xml:space="preserve">
- <value>Access to the path is denied.</value>
- </data>
- <data name="UnauthorizedAccess_IODenied_Path" xml:space="preserve">
- <value>Access to the path '{0}' is denied.</value>
- </data>
- <data name="UnauthorizedAccess_MemStreamBuffer" xml:space="preserve">
- <value>MemoryStream's internal buffer cannot be accessed.</value>
- </data>
- <data name="UnauthorizedAccess_RegistryKeyGeneric_Key" xml:space="preserve">
- <value>Access to the registry key '{0}' is denied.</value>
- </data>
- <data name="UnknownError_Num" xml:space="preserve">
- <value>Unknown error "{0}".</value>
- </data>
- <data name="Verification_Exception" xml:space="preserve">
- <value>Operation could destabilize the runtime.</value>
- </data>
- <data name="Word_At" xml:space="preserve">
- <value>at</value>
- </data>
- <data name="DebugAssertBanner" xml:space="preserve">
- <value>---- DEBUG ASSERTION FAILED ----</value>
- </data>
- <data name="DebugAssertLongMessage" xml:space="preserve">
- <value>---- Assert Long Message ----</value>
- </data>
- <data name="DebugAssertShortMessage" xml:space="preserve">
- <value>---- Assert Short Message ----</value>
- </data>
- <data name="LockRecursionException_ReadAfterWriteNotAllowed" xml:space="preserve">
- <value>A read lock may not be acquired with the write lock held in this mode.</value>
- </data>
- <data name="LockRecursionException_RecursiveReadNotAllowed" xml:space="preserve">
- <value>Recursive read lock acquisitions not allowed in this mode.</value>
- </data>
- <data name="LockRecursionException_RecursiveWriteNotAllowed" xml:space="preserve">
- <value>Recursive write lock acquisitions not allowed in this mode.</value>
- </data>
- <data name="LockRecursionException_RecursiveUpgradeNotAllowed" xml:space="preserve">
- <value>Recursive upgradeable lock acquisitions not allowed in this mode.</value>
- </data>
- <data name="LockRecursionException_WriteAfterReadNotAllowed" xml:space="preserve">
- <value>Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Please ensure that read locks are released before taking a write lock. If an upgrade is necessary, use an upgrade lock in place of the read lock.</value>
- </data>
- <data name="SynchronizationLockException_MisMatchedUpgrade" xml:space="preserve">
- <value>The upgradeable lock is being released without being held.</value>
- </data>
- <data name="SynchronizationLockException_MisMatchedRead" xml:space="preserve">
- <value>The read lock is being released without being held.</value>
- </data>
- <data name="SynchronizationLockException_IncorrectDispose" xml:space="preserve">
- <value>The lock is being disposed while still being used. It either is being held by a thread and/or has active waiters waiting to acquire the lock.</value>
- </data>
- <data name="LockRecursionException_UpgradeAfterReadNotAllowed" xml:space="preserve">
- <value>Upgradeable lock may not be acquired with read lock held.</value>
- </data>
- <data name="LockRecursionException_UpgradeAfterWriteNotAllowed" xml:space="preserve">
- <value>Upgradeable lock may not be acquired with write lock held in this mode. Acquiring Upgradeable lock gives the ability to read along with an option to upgrade to a writer.</value>
- </data>
- <data name="SynchronizationLockException_MisMatchedWrite" xml:space="preserve">
- <value>The write lock is being released without being held.</value>
- </data>
- <data name="ConcurrentStack_PushPopRange_CountOutOfRange" xml:space="preserve">
- <value>The count argument must be greater than or equal to zero.</value>
- </data>
- <data name="ConcurrentStack_PushPopRange_InvalidCount" xml:space="preserve">
- <value>The sum of the startIndex and count arguments must be less than or equal to the collection's Count.</value>
- </data>
- <data name="ConcurrentStack_PushPopRange_StartOutOfRange" xml:space="preserve">
- <value>The startIndex argument must be greater than or equal to zero.</value>
- </data>
- <data name="NotSupported_SignatureType" xml:space="preserve">
- <value>This method is not supported on signature types.</value>
- </data>
- <data name="MemoryDisposed" xml:space="preserve">
- <value>Memory&lt;T&gt; has been disposed.</value>
- </data>
- <data name="Memory_OutstandingReferences" xml:space="preserve">
- <value>Release all references before disposing this instance.</value>
- </data>
- <data name="HashCode_HashCodeNotSupported" xml:space="preserve">
- <value>HashCode is a mutable struct and should not be compared with other HashCodes. Use ToHashCode to retrieve the computed hash code.</value>
- </data>
- <data name="HashCode_EqualityNotSupported" xml:space="preserve">
- <value>HashCode is a mutable struct and should not be compared with other HashCodes.</value>
- </data>
- <data name="Arg_TypeNotSupported" xml:space="preserve">
- <value>Specified type is not supported</value>
- </data>
- <data name="IO_InvalidReadLength" xml:space="preserve">
- <value>The read operation returned an invalid length.</value>
- </data>
- <data name="Arg_BasePathNotFullyQualified" xml:space="preserve">
- <value>Basepath argument is not fully qualified.</value>
- </data>
- <data name="Arg_ElementsInSourceIsGreaterThanDestination" xml:space="preserve">
- <value>Number of elements in source vector is greater than the destination array</value>
- </data>
- <data name="Arg_NullArgumentNullRef" xml:space="preserve">
- <value>The method was called with a null array argument.</value>
- </data>
- <data name="Argument_CannotPrepareAbstract" xml:space="preserve">
- <value>Abstract methods cannot be prepared.</value>
- </data>
- <data name="Argument_InvalidGenericInstantiation" xml:space="preserve">
- <value>The given generic instantiation was invalid.</value>
- </data>
- <data name="Argument_OverlapAlignmentMismatch" xml:space="preserve">
- <value>Overlapping spans have mismatching alignment.</value>
- </data>
- <data name="Arg_InsufficientNumberOfElements" xml:space="preserve">
- <value>At least {0} element(s) are expected in the parameter "{1}".</value>
- </data>
- <data name="Arg_MustBeNullTerminatedString" xml:space="preserve">
- <value>The string must be null-terminated.</value>
- </data>
- <data name="ArgumentOutOfRange_Week_ISO" xml:space="preserve">
- <value>The week parameter must be in the range 1 through 53.</value>
- </data>
- <data name="Argument_BadPInvokeMethod" xml:space="preserve">
- <value>PInvoke methods must be static and native and cannot be abstract.</value>
- </data>
- <data name="Argument_BadPInvokeOnInterface" xml:space="preserve">
- <value>PInvoke methods cannot exist on interfaces.</value>
- </data>
- <data name="Argument_MethodRedefined" xml:space="preserve">
- <value>Method has been already defined.</value>
- </data>
- <data name="Argument_CannotExtractScalar" xml:space="preserve">
- <value>Cannot extract a Unicode scalar value from the specified index in the input.</value>
- </data>
- <data name="Argument_CannotParsePrecision" xml:space="preserve">
- <value>Characters following the format symbol must be a number of {0} or less.</value>
- </data>
- <data name="Argument_GWithPrecisionNotSupported" xml:space="preserve">
- <value>The 'G' format combined with a precision is not supported.</value>
- </data>
- <data name="Argument_PrecisionTooLarge" xml:space="preserve">
- <value>Precision cannot be larger than {0}.</value>
- </data>
- <data name="Arg_EnumNotCloneable" xml:space="preserve">
- <value>The supplied object does not implement ICloneable.</value>
- </data>
- <data name="InvalidOp_InvalidNewEnumVariant" xml:space="preserve">
- <value>The returned enumerator does not implement IEnumVARIANT.</value>
- </data>
-</root>
diff --git a/netcore/System.Private.CoreLib/shared/CodeAnalysis.ruleset b/netcore/System.Private.CoreLib/shared/CodeAnalysis.ruleset
deleted file mode 100644
index 646deabaf86..00000000000
--- a/netcore/System.Private.CoreLib/shared/CodeAnalysis.ruleset
+++ /dev/null
@@ -1,206 +0,0 @@
-<RuleSet Name="Microsoft.Analyzers.ManagedCodeAnalysis" Description="Microsoft.Analyzers.ManagedCodeAnalysis" ToolsVersion="14.0">
- <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
- <Rule Id="CA1000" Action="None" /> <!-- Do not declare static members on generic types -->
- <Rule Id="CA1001" Action="None" /> <!-- Non disposable class owns disposable fields -->
- <Rule Id="CA1010" Action="None" /> <!-- Collections should implement generic interface -->
- <Rule Id="CA1028" Action="None" /> <!-- Enum storage should be Int32 -->
- <Rule Id="CA1030" Action="None" /> <!-- Use events where appropriate -->
- <Rule Id="CA1031" Action="None" /> <!-- Do not catch general exception types -->
- <Rule Id="CA1032" Action="None" /> <!-- Implement standard exception constructors -->
- <Rule Id="CA1034" Action="None" /> <!-- Nested types should not be visible -->
- <Rule Id="CA1036" Action="None" /> <!-- Overload comparison operators when implementing System.IComparable -->
- <Rule Id="CA1041" Action="None" /> <!-- Provide ObsoleteAttribute message -->
- <Rule Id="CA1043" Action="None" /> <!-- Use integral or string argument for indexers -->
- <Rule Id="CA1044" Action="None" /> <!-- Properties should not be write only -->
- <Rule Id="CA1051" Action="None" /> <!-- Do not declare visible instance fields -->
- <Rule Id="CA1052" Action="None" /> <!-- Static holder types should be sealed -->
- <Rule Id="CA1054" Action="None" /> <!-- URI parameters should not be strings -->
- <Rule Id="CA1055" Action="None" /> <!-- URI return values should not be strings -->
- <Rule Id="CA1056" Action="None" /> <!-- URI properties should not be strings -->
- <Rule Id="CA1058" Action="None" /> <!-- Types should not extend certain base types -->
- <Rule Id="CA1061" Action="None" /> <!-- Do not hide base class methods -->
- <Rule Id="CA1062" Action="None" /> <!-- Validate arguments of public methods -->
- <Rule Id="CA1063" Action="None" /> <!-- Implement IDisposable correctly -->
- <Rule Id="CA1064" Action="None" /> <!-- Exceptions should be public -->
- <Rule Id="CA1065" Action="None" /> <!-- Do not raise exceptions in unexpected locations -->
- <Rule Id="CA1066" Action="None" /> <!-- Type should implement IEquatable -->
- <Rule Id="CA1067" Action="None" /> <!-- Override Object.Equals(object) when implementing IEquatable -->
- <Rule Id="CA1068" Action="None" /> <!-- CancellationToken parameters must come last -->
- <Rule Id="CA1303" Action="None" /> <!-- Do not pass literals as localized parameters -->
- <Rule Id="CA1304" Action="None" /> <!-- Specify CultureInfo -->
- <Rule Id="CA1305" Action="None" /> <!-- Specify IFormatProvider -->
- <Rule Id="CA1307" Action="None" /> <!-- Specify StringComparison -->
- <Rule Id="CA1308" Action="None" /> <!-- Normalize strings to upper case -->
- <Rule Id="CA1707" Action="None" /> <!-- Identifers should not contain underscores -->
- <Rule Id="CA1710" Action="None" /> <!-- Identifers should have correct suffix -->
- <Rule Id="CA1712" Action="None" /> <!-- Do not prefix enum values with type name -->
- <Rule Id="CA1714" Action="None" /> <!-- Flags enums should have plural names -->
- <Rule Id="CA1715" Action="None" /> <!-- Type parameters names should be prefixed with T -->
- <Rule Id="CA1716" Action="None" /> <!-- Identifiers should not match keywords -->
- <Rule Id="CA1717" Action="None" /> <!-- Only FlagsAttribute enums should have plural names -->
- <Rule Id="CA1720" Action="None" /> <!-- Identifier contains type name -->
- <Rule Id="CA1721" Action="None" /> <!-- Property names should not match get methods -->
- <Rule Id="CA1724" Action="None" /> <!-- Type names should not match namespaces -->
- <Rule Id="CA1801" Action="None" /> <!-- Review unused parameters -->
- <Rule Id="CA1806" Action="None" /> <!-- Do not ignore method results -->
- <Rule Id="CA1812" Action="None" /> <!-- Avoid uninstantiated internal classes -->
- <Rule Id="CA1814" Action="None" /> <!-- Prefer jagged arrays over multidimensional -->
- <Rule Id="CA1815" Action="None" /> <!-- Override equals and operator equals on value types -->
- <Rule Id="CA1816" Action="None" /> <!-- Dispose methods should call SuppressFinalize -->
- <Rule Id="CA1819" Action="None" /> <!-- Properties should not return arrays -->
- <Rule Id="CA1820" Action="None" /> <!-- Test for empty strings using string length -->
- <Rule Id="CA1822" Action="None" /> <!-- Mark members as static -->
- <Rule Id="CA1827" Action="None" /> <!-- Do not use Count() when Any() can be used -->
- <Rule Id="CA2000" Action="None" /> <!-- Dispose objects before losing scope -->
- <Rule Id="CA2002" Action="None" /> <!-- Do not lock on objects with weak identity -->
- <Rule Id="CA2010" Action="None" /> <!-- Always consume the value returned by methods marked with PreserveSigAttribute -->
- <Rule Id="CA2100" Action="None" /> <!-- Review SQL queries for security vulnerabilities -->
- <Rule Id="CA2101" Action="None" /> <!-- Specify marshaling for P/Invoke string arguments -->
- <Rule Id="CA2119" Action="None" /> <!-- Seal methods that satisfy private interfaces -->
- <Rule Id="CA2208" Action="None" /> <!-- Instantiate exception arguments correctly -->
- <Rule Id="CA2211" Action="None" /> <!-- Non-constant fields should not be visible -->
- <Rule Id="CA2213" Action="None" /> <!-- Disposable Fields should be disposed -->
- <Rule Id="CA2214" Action="None" /> <!-- Do not call overridable methods in constructors -->
- <Rule Id="CA2216" Action="None" /> <!-- Disposable types should declare finalizer -->
- <Rule Id="CA2219" Action="None" /> <!-- Do not raise exceptions in finally clauses -->
- <Rule Id="CA2225" Action="None" /> <!-- Operator overloads have named alternates -->
- <Rule Id="CA2227" Action="None" /> <!-- Collection properties should be read only -->
- <Rule Id="CA2231" Action="None" /> <!-- Overload operator equals when overriding ValueType.Equals -->
- <Rule Id="CA2235" Action="None" /> <!-- Serializable type has non serializable field -->
- <Rule Id="CA2237" Action="None" /> <!-- Add [Serializable] to types that implement ISerializable -->
- <Rule Id="CA5366" Action="None" /> <!-- Use XmlReader For DataSet Read Xml -->
- <Rule Id="CA5369" Action="None" /> <!-- Use XmlReader For Deserialize -->
- <Rule Id="CA5371" Action="None" /> <!-- Use XmlReader For Schema Read -->
- <Rule Id="CA5372" Action="None" /> <!-- Use XmlReader For XPathDocument -->
- <Rule Id="CA5397" Action="None" /> <!-- Security protocol version is deprecated -->
- </Rules>
- <Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
- <Rule Id="AD0001" Action="None" /> <!-- Analyzer threw an exception -->
- <Rule Id="SA0001" Action="None" /> <!-- XML comments -->
- <Rule Id="SA1002" Action="None" /> <!-- Semicolons should not be preceded by a space -->
- <Rule Id="SA1003" Action="None" /> <!-- Operator should not appear at the end of a line -->
- <Rule Id="SA1004" Action="None" /> <!-- Documentation line should begin with a space -->
- <Rule Id="SA1005" Action="None" /> <!-- Single line comment should begin with a space -->
- <Rule Id="SA1008" Action="None" /> <!-- Opening parenthesis should not be preceded by a space -->
- <Rule Id="SA1009" Action="None" /> <!-- Closing parenthesis should not be followed by a space -->
- <Rule Id="SA1010" Action="None" /> <!-- Opening square brackets should not be preceded by a space -->
- <Rule Id="SA1011" Action="None" /> <!-- Closing square bracket should be followed by a space -->
- <Rule Id="SA1012" Action="None" /> <!-- Opening brace should be followed by a space -->
- <Rule Id="SA1013" Action="None" /> <!-- Closing brace should be preceded by a space -->
- <Rule Id="SA1015" Action="None" /> <!-- Closing generic bracket should not be followed by a space -->
- <Rule Id="SA1021" Action="None" /> <!-- Negative sign should be preceded by a space -->
- <Rule Id="SA1023" Action="None" /> <!-- Dereference symbol '*' should not be preceded by a space." -->
- <Rule Id="SA1024" Action="None" /> <!-- Colon should be followed by a space -->
- <Rule Id="SA1025" Action="None" /> <!-- Code should not contain multiple whitespace characters in a row -->
- <Rule Id="SA1100" Action="None" /> <!-- Do not prefix calls with base unless local implementation exists -->
- <Rule Id="SA1101" Action="None" /> <!-- Prefix local calls with this -->
- <Rule Id="SA1106" Action="None" /> <!-- Code should not contain empty statements -->
- <Rule Id="SA1107" Action="None" /> <!-- Code should not contain multiple statements on one line -->
- <Rule Id="SA1108" Action="None" /> <!-- Block statements should not contain embedded comments -->
- <Rule Id="SA1110" Action="None" /> <!-- Opening parenthesis or bracket should be on declaration line -->
- <Rule Id="SA1111" Action="None" /> <!-- Closing parenthesis should be on line of last parameter -->
- <Rule Id="SA1114" Action="None" /> <!-- Parameter list should follow declaration -->
- <Rule Id="SA1116" Action="None" /> <!-- Split parameters should start on line after declaration -->
- <Rule Id="SA1117" Action="None" /> <!-- Parameters should be on same line or separate lines -->
- <Rule Id="SA1118" Action="None" /> <!-- Parameter should not span multiple lines -->
- <Rule Id="SA1119" Action="None" /> <!-- Statement should not use unnecessary parenthesis -->
- <Rule Id="SA1120" Action="None" /> <!-- Comments should contain text -->
- <Rule Id="SA1122" Action="None" /> <!-- Use string.Empty for empty strings -->
- <Rule Id="SA1123" Action="None" /> <!-- Region should not be located within a code element -->
- <Rule Id="SA1124" Action="None" /> <!-- Do not use regions -->
- <Rule Id="SA1125" Action="None" /> <!-- Use shorthand for nullable types -->
- <Rule Id="SA1127" Action="None" /> <!-- Generic type constraints should be on their own line -->
- <Rule Id="SA1128" Action="None" /> <!-- Put constructor initializers on their own line -->
- <Rule Id="SA1130" Action="None" /> <!-- Use lambda syntax -->
- <Rule Id="SA1131" Action="None" /> <!-- Constant values should appear on the right-hand side of comparisons -->
- <Rule Id="SA1132" Action="None" /> <!-- Do not combine fields -->
- <Rule Id="SA1133" Action="None" /> <!-- Do not combine attributes -->
- <Rule Id="SA1134" Action="None" /> <!-- Each attribute should be placed on its own line of code -->
- <Rule Id="SA1135" Action="None" /> <!-- Using directive should be qualified -->
- <Rule Id="SA1136" Action="None" /> <!-- Enum values should be on separate lines -->
- <Rule Id="SA1137" Action="None" /> <!-- Elements should have the same indentation -->
- <Rule Id="SA1139" Action="None" /> <!-- Use literal suffix notation instead of casting -->
- <Rule Id="SA1200" Action="None" /> <!-- Using directive should appear within a namespace declaration -->
- <Rule Id="SA1201" Action="None" /> <!-- Elements should appear in the correct order -->
- <Rule Id="SA1202" Action="None" /> <!-- Elements should be ordered by access -->
- <Rule Id="SA1203" Action="None" /> <!-- Constants should appear before fields -->
- <Rule Id="SA1204" Action="None" /> <!-- Static elements should appear before instance elements -->
- <Rule Id="SA1208" Action="None" /> <!-- Using directive ordering -->
- <Rule Id="SA1209" Action="None" /> <!-- Using alias directives should be placed after all using namespace directives -->
- <Rule Id="SA1210" Action="None" /> <!-- Using directives should be ordered alphabetically by the namespaces -->
- <Rule Id="SA1211" Action="None" /> <!-- Using alias directive ordering -->
- <Rule Id="SA1214" Action="None" /> <!-- Readonly fields should appear before non-readonly fields -->
- <Rule Id="SA1216" Action="None" /> <!-- Using static directives should be placed at the correct location -->
- <Rule Id="SA1300" Action="None" /> <!-- Element should begin with an uppercase letter -->
- <Rule Id="SA1303" Action="None" /> <!-- Const field names should begin with upper-case letter -->
- <Rule Id="SA1304" Action="None" /> <!-- Non-private readonly fields should begin with upper-case letter -->
- <Rule Id="SA1306" Action="None" /> <!-- Field should begin with lower-case letter -->
- <Rule Id="SA1307" Action="None" /> <!-- Field should begin with upper-case letter -->
- <Rule Id="SA1308" Action="None" /> <!-- Field should not begin with the prefix 's_' -->
- <Rule Id="SA1309" Action="None" /> <!-- Field names should not begin with underscore -->
- <Rule Id="SA1310" Action="None" /> <!-- Field should not contain an underscore -->
- <Rule Id="SA1311" Action="None" /> <!-- Static readonly fields should begin with upper-case letter -->
- <Rule Id="SA1312" Action="None" /> <!-- Variable should begin with lower-case letter -->
- <Rule Id="SA1313" Action="None" /> <!-- Parameter should begin with lower-case letter -->
- <Rule Id="SA1314" Action="None" /> <!-- Type parameter names should begin with T -->
- <Rule Id="SA1316" Action="None" /> <!-- Tuple element names should use correct casing -->
- <Rule Id="SA1401" Action="None" /> <!-- Fields should be private -->
- <Rule Id="SA1402" Action="None" /> <!-- File may only contain a single type -->
- <Rule Id="SA1403" Action="None" /> <!-- File may only contain a single namespace -->
- <Rule Id="SA1404" Action="None" /> <!-- Code analysis suppression should have justification -->
- <Rule Id="SA1405" Action="None" /> <!-- Debug.Assert should provide message text -->
- <Rule Id="SA1407" Action="None" /> <!-- Arithmetic expressions should declare precedence -->
- <Rule Id="SA1408" Action="None" /> <!-- Conditional expressions should declare precedence -->
- <Rule Id="SA1413" Action="None" /> <!-- Use trailing comma in multi-line initializers -->
- <Rule Id="SA1414" Action="None" /> <!-- Tuple types in signatures should have element names -->
- <Rule Id="SA1500" Action="None" /> <!-- Braces for multi-line statements should not share line -->
- <Rule Id="SA1501" Action="None" /> <!-- Statement should not be on a single line -->
- <Rule Id="SA1502" Action="None" /> <!-- Element should not be on a single line -->
- <Rule Id="SA1503" Action="None" /> <!-- Braces should not be omitted -->
- <Rule Id="SA1504" Action="None" /> <!-- All accessors should be single-line or multi-line -->
- <Rule Id="SA1505" Action="None" /> <!-- An opening brace should not be followed by a blank line -->
- <Rule Id="SA1506" Action="None" /> <!-- Element documentation headers should not be followed by blank line -->
- <Rule Id="SA1507" Action="None" /> <!-- Code should not contain multiple blank lines in a row -->
- <Rule Id="SA1508" Action="None" /> <!-- A closing brace should not be preceded by a blank line -->
- <Rule Id="SA1509" Action="None" /> <!-- Opening braces should not be preceded by blank line -->
- <Rule Id="SA1510" Action="None" /> <!-- 'else' statement should not be preceded by a blank line -->
- <Rule Id="SA1512" Action="None" /> <!-- Single-line comments should not be followed by blank line -->
- <Rule Id="SA1513" Action="None" /> <!-- Closing brace should be followed by blank line -->
- <Rule Id="SA1514" Action="None" /> <!-- Element documentation header should be preceded by blank line -->
- <Rule Id="SA1515" Action="None" /> <!-- Single-line comment should be preceded by blank line -->
- <Rule Id="SA1516" Action="None" /> <!-- Elements should be separated by blank line -->
- <Rule Id="SA1519" Action="None" /> <!-- Braces should not be omitted from multi-line child statement -->
- <Rule Id="SA1520" Action="None" /> <!-- Use braces consistently -->
- <Rule Id="SA1600" Action="None" /> <!-- Elements should be documented -->
- <Rule Id="SA1601" Action="None" /> <!-- Partial elements should be documented -->
- <Rule Id="SA1602" Action="None" /> <!-- Enumeration items should be documented -->
- <Rule Id="SA1604" Action="None" /> <!-- Element documentation should have summary -->
- <Rule Id="SA1605" Action="None" /> <!-- Partial element documentation should have summary -->
- <Rule Id="SA1606" Action="None" /> <!-- Element documentation should have summary text -->
- <Rule Id="SA1608" Action="None" /> <!-- Element documentation should not have default summary -->
- <Rule Id="SA1610" Action="None" /> <!-- Property documentation should have value text -->
- <Rule Id="SA1611" Action="None" /> <!-- The documentation for parameter 'message' is missing -->
- <Rule Id="SA1612" Action="None" /> <!-- The parameter documentation is at incorrect position -->
- <Rule Id="SA1614" Action="None" /> <!-- Element parameter documentation should have text -->
- <Rule Id="SA1615" Action="None" /> <!-- Element return value should be documented -->
- <Rule Id="SA1616" Action="None" /> <!-- Element return value documentation should have text -->
- <Rule Id="SA1618" Action="None" /> <!-- The documentation for type parameter is missing -->
- <Rule Id="SA1619" Action="None" /> <!-- The documentation for type parameter is missing -->
- <Rule Id="SA1622" Action="None" /> <!-- Generic type parameter documentation should have text -->
- <Rule Id="SA1623" Action="None" /> <!-- Property documentation text -->
- <Rule Id="SA1624" Action="None" /> <!-- Because the property only contains a visible get accessor, the documentation summary text should begin with 'Gets' -->
- <Rule Id="SA1625" Action="None" /> <!-- Element documentation should not be copied and pasted -->
- <Rule Id="SA1626" Action="None" /> <!-- Single-line comments should not use documentation style slashes -->
- <Rule Id="SA1627" Action="None" /> <!-- The documentation text within the \'exception\' tag should not be empty -->
- <Rule Id="SA1629" Action="None" /> <!-- Documentation text should end with a period -->
- <Rule Id="SA1633" Action="None" /> <!-- File should have header -->
- <Rule Id="SA1642" Action="None" /> <!-- Constructor summary documentation should begin with standard text -->
- <Rule Id="SA1643" Action="None" /> <!-- Destructor summary documentation should begin with standard text -->
- <Rule Id="SA1649" Action="None" /> <!-- File name should match first type name -->
- </Rules>
- <Rules AnalyzerId="xunit.analyzers" RuleNamespace="xunit.analyzers">
- <Rule Id="xUnit1024" Action="None" /> <!-- Test methods cannot have overloads -->
- <Rule Id="xUnit2013" Action="None" /> <!-- Do not use equality check to check for collection size. -->
- <Rule Id="xUnit2017" Action="None" /> <!-- Do not use Contains() to check if a value exists in a collection -->
- </Rules>
-</RuleSet>
diff --git a/netcore/System.Private.CoreLib/shared/Internal/IO/File.Unix.cs b/netcore/System.Private.CoreLib/shared/Internal/IO/File.Unix.cs
deleted file mode 100644
index 50fa0f0d0c4..00000000000
--- a/netcore/System.Private.CoreLib/shared/Internal/IO/File.Unix.cs
+++ /dev/null
@@ -1,25 +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.
-
-namespace Internal.IO
-{
- internal static partial class File
- {
- internal static bool InternalExists(string fullPath)
- {
- Interop.Sys.FileStatus fileinfo;
-
- // First use stat, as we want to follow symlinks. If that fails, it could be because the symlink
- // is broken, we don't have permissions, etc., in which case fall back to using LStat to evaluate
- // based on the symlink itself.
- if (Interop.Sys.Stat(fullPath, out fileinfo) < 0 &&
- Interop.Sys.LStat(fullPath, out fileinfo) < 0)
- {
- return false;
- }
-
- return ((fileinfo.Mode & Interop.Sys.FileTypes.S_IFMT) != Interop.Sys.FileTypes.S_IFDIR);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Internal/IO/File.Windows.cs b/netcore/System.Private.CoreLib/shared/Internal/IO/File.Windows.cs
deleted file mode 100644
index c19279d5514..00000000000
--- a/netcore/System.Private.CoreLib/shared/Internal/IO/File.Windows.cs
+++ /dev/null
@@ -1,76 +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.IO;
-using System.Runtime.InteropServices;
-
-namespace Internal.IO
-{
- internal static partial class File
- {
- internal static bool InternalExists(string fullPath)
- {
- Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = default;
- int errorCode = FillAttributeInfo(fullPath, ref data, returnErrorOnNotFound: true);
-
- return (errorCode == 0) && (data.dwFileAttributes != -1)
- && ((data.dwFileAttributes & Interop.Kernel32.FileAttributes.FILE_ATTRIBUTE_DIRECTORY) == 0);
- }
-
- /// <summary>
- /// Returns 0 on success, otherwise a Win32 error code. Note that
- /// classes should use -1 as the uninitialized state for dataInitialized.
- /// </summary>
- /// <param name="returnErrorOnNotFound">Return the error code for not found errors?</param>
- internal static int FillAttributeInfo(string path, ref Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data, bool returnErrorOnNotFound)
- {
- int errorCode = Interop.Errors.ERROR_SUCCESS;
-
- using (DisableMediaInsertionPrompt.Create())
- {
- if (!Interop.Kernel32.GetFileAttributesEx(path, Interop.Kernel32.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, ref data))
- {
- errorCode = Marshal.GetLastWin32Error();
- if (errorCode == Interop.Errors.ERROR_ACCESS_DENIED)
- {
- // Files that are marked for deletion will not let you GetFileAttributes,
- // ERROR_ACCESS_DENIED is given back without filling out the data struct.
- // FindFirstFile, however, will. Historically we always gave back attributes
- // for marked-for-deletion files.
-
- Interop.Kernel32.WIN32_FIND_DATA findData = default;
- using (SafeFindHandle handle = Interop.Kernel32.FindFirstFile(path, ref findData))
- {
- if (handle.IsInvalid)
- {
- errorCode = Marshal.GetLastWin32Error();
- }
- else
- {
- errorCode = Interop.Errors.ERROR_SUCCESS;
- data.PopulateFrom(ref findData);
- }
- }
- }
- }
- }
-
- if (errorCode != Interop.Errors.ERROR_SUCCESS && !returnErrorOnNotFound)
- {
- switch (errorCode)
- {
- case Interop.Errors.ERROR_FILE_NOT_FOUND:
- case Interop.Errors.ERROR_PATH_NOT_FOUND:
- case Interop.Errors.ERROR_NOT_READY: // Removable media not ready
- // Return default value for backward compatibility
- data.dwFileAttributes = -1;
- return Interop.Errors.ERROR_SUCCESS;
- }
- }
-
- return errorCode;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Internal/IO/File.cs b/netcore/System.Private.CoreLib/shared/Internal/IO/File.cs
deleted file mode 100644
index a835be480b1..00000000000
--- a/netcore/System.Private.CoreLib/shared/Internal/IO/File.cs
+++ /dev/null
@@ -1,77 +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 System;
-using System.Diagnostics;
-using System.Security;
-using System.IO;
-
-namespace Internal.IO
-{
- //
- // Subsetted clone of System.IO.File for internal runtime use.
- // Keep in sync with https://github.com/dotnet/corefx/tree/master/src/System.IO.FileSystem.
- //
- internal static partial class File
- {
- // Tests if a file exists. The result is true if the file
- // given by the specified path exists; otherwise, the result is
- // false. Note that if path describes a directory,
- // Exists will return true.
- public static bool Exists(string? path)
- {
- try
- {
- if (path == null)
- return false;
- if (path.Length == 0)
- return false;
-
- path = Path.GetFullPath(path);
-
- // After normalizing, check whether path ends in directory separator.
- // Otherwise, FillAttributeInfo removes it and we may return a false positive.
- // GetFullPath should never return null
- Debug.Assert(path != null, "File.Exists: GetFullPath returned null");
- if (path.Length > 0 && PathInternal.IsDirectorySeparator(path[^1]))
- {
- return false;
- }
-
- return InternalExists(path);
- }
- catch (ArgumentException) { }
- catch (NotSupportedException) { } // Security can throw this on ":"
- catch (SecurityException) { }
- catch (IOException) { }
- catch (UnauthorizedAccessException) { }
-
- return false;
- }
-
- public static byte[] ReadAllBytes(string path)
- {
- // bufferSize == 1 used to avoid unnecessary buffer in FileStream
- using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 1))
- {
- long fileLength = fs.Length;
- if (fileLength > int.MaxValue)
- throw new IOException(SR.IO_FileTooLong2GB);
-
- int index = 0;
- int count = (int)fileLength;
- byte[] bytes = new byte[count];
- while (count > 0)
- {
- int n = fs.Read(bytes, index, count);
- if (n == 0)
- throw Error.GetEndOfFile();
- index += n;
- count -= n;
- }
- return bytes;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Internal/Padding.cs b/netcore/System.Private.CoreLib/shared/Internal/Padding.cs
deleted file mode 100644
index 905fbde7cf1..00000000000
--- a/netcore/System.Private.CoreLib/shared/Internal/Padding.cs
+++ /dev/null
@@ -1,25 +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 System.Runtime.InteropServices;
-
-namespace Internal
-{
- /// <summary>A class for common padding constants and eventually routines.</summary>
- internal static class PaddingHelpers
- {
- /// <summary>A size greater than or equal to the size of the most common CPU cache lines.</summary>
-#if ARM64
- internal const int CACHE_LINE_SIZE = 128;
-#else
- internal const int CACHE_LINE_SIZE = 64;
-#endif
- }
-
- /// <summary>Padding structure used to minimize false sharing</summary>
- [StructLayout(LayoutKind.Explicit, Size = PaddingHelpers.CACHE_LINE_SIZE - sizeof(int))]
- internal struct PaddingFor32
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Internal/Resources/PRIExceptionInfo.cs b/netcore/System.Private.CoreLib/shared/Internal/Resources/PRIExceptionInfo.cs
deleted file mode 100644
index 2b097a9d939..00000000000
--- a/netcore/System.Private.CoreLib/shared/Internal/Resources/PRIExceptionInfo.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace Internal.Resources
-{
- public class PRIExceptionInfo
- {
- public string? PackageSimpleName;
- public string? ResWFile;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Internal/Resources/WindowsRuntimeResourceManagerBase.cs b/netcore/System.Private.CoreLib/shared/Internal/Resources/WindowsRuntimeResourceManagerBase.cs
deleted file mode 100644
index 173b2372c95..00000000000
--- a/netcore/System.Private.CoreLib/shared/Internal/Resources/WindowsRuntimeResourceManagerBase.cs
+++ /dev/null
@@ -1,33 +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 System.Globalization;
-
-namespace Internal.Resources
-{
- // This is implemented in System.Runtime.WindowsRuntime as System.Resources.WindowsRuntimeResourceManager,
- // allowing us to ask for a WinRT-specific ResourceManager.
- public abstract class WindowsRuntimeResourceManagerBase
- {
- public abstract bool Initialize(string libpath, string reswFilename, out PRIExceptionInfo? exceptionInfo);
-
- public abstract string GetString(string stringName, string? startingCulture, string? neutralResourcesCulture);
-
- public abstract CultureInfo? GlobalResourceContextBestFitCultureInfo
- {
- get;
- }
-
- public abstract bool SetGlobalResourceContextDefaultCulture(CultureInfo ci);
-
- /// <summary>
- /// Check whether CultureData exists for specified cultureName
- /// This API is used for WindowsRuntimeResourceManager in System.Runtime.WindowsRuntime
- /// </summary>
- public static bool IsValidCulture(string? cultureName)
- {
- return CultureData.GetCultureData(cultureName, /* useUserOverride */ true) != null;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Internal/Runtime/CompilerServices/Unsafe.cs b/netcore/System.Private.CoreLib/shared/Internal/Runtime/CompilerServices/Unsafe.cs
deleted file mode 100644
index 7c5f9f70b92..00000000000
--- a/netcore/System.Private.CoreLib/shared/Internal/Runtime/CompilerServices/Unsafe.cs
+++ /dev/null
@@ -1,439 +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.
-
-#pragma warning disable IDE0060 // implementations provided by the JIT
-using System;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.Versioning;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-#if !CORECLR
-#if BIT64
-using nint = System.Int64;
-#else
-using nint = System.Int32;
-#endif
-#endif
-
-//
-// The implementations of most the methods in this file are provided as intrinsics.
-// In CoreCLR, the body of the functions are replaced by the EE with unsafe code. See see getILIntrinsicImplementationForUnsafe for details.
-// In CoreRT, see Internal.IL.Stubs.UnsafeIntrinsics for details.
-//
-
-namespace Internal.Runtime.CompilerServices
-{
- //
- // Subsetted clone of System.Runtime.CompilerServices.Unsafe for internal runtime use.
- // Keep in sync with https://github.com/dotnet/corefx/tree/master/src/System.Runtime.CompilerServices.Unsafe.
- //
-
- /// <summary>
- /// For internal use only. Contains generic, low-level functionality for manipulating pointers.
- /// </summary>
- [CLSCompliant(false)]
- public static unsafe partial class Unsafe
- {
- /// <summary>
- /// Returns a pointer to the given by-ref parameter.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void* AsPointer<T>(ref T value)
- {
- throw new PlatformNotSupportedException();
-
- // ldarg.0
- // conv.u
- // ret
- }
-
- /// <summary>
- /// Returns the size of an object of the given type parameter.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int SizeOf<T>()
- {
-#if CORECLR
- typeof(T).ToString(); // Type token used by the actual method body
-#endif
- throw new PlatformNotSupportedException();
-
- // sizeof !!0
- // ret
- }
-
- /// <summary>
- /// Casts the given object to the specified type, performs no dynamic type checking.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [return: NotNullIfNotNull("value")]
- public static T As<T>(object? value) where T : class?
- {
- throw new PlatformNotSupportedException();
-
- // ldarg.0
- // ret
- }
-
- /// <summary>
- /// Reinterprets the given reference as a reference to a value of type <typeparamref name="TTo"/>.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref TTo As<TFrom, TTo>(ref TFrom source)
- {
- throw new PlatformNotSupportedException();
-
- // ldarg.0
- // ret
- }
-
- /// <summary>
- /// Adds an element offset to the given reference.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref T Add<T>(ref T source, int elementOffset)
- {
-#if CORECLR
- typeof(T).ToString(); // Type token used by the actual method body
- throw new PlatformNotSupportedException();
-#else
- return ref AddByteOffset(ref source, (IntPtr)(elementOffset * (nint)SizeOf<T>()));
-#endif
- }
-
- /// <summary>
- /// Adds an element offset to the given reference.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref T Add<T>(ref T source, IntPtr elementOffset)
- {
-#if CORECLR
- typeof(T).ToString(); // Type token used by the actual method body
- throw new PlatformNotSupportedException();
-#else
- return ref AddByteOffset(ref source, (IntPtr)((nint)elementOffset * (nint)SizeOf<T>()));
-#endif
- }
-
- /// <summary>
- /// Adds an element offset to the given pointer.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void* Add<T>(void* source, int elementOffset)
- {
-#if CORECLR
- typeof(T).ToString(); // Type token used by the actual method body
- throw new PlatformNotSupportedException();
-#else
- return (byte*)source + (elementOffset * (nint)SizeOf<T>());
-#endif
- }
-
- /// <summary>
- /// Adds an element offset to the given reference.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static ref T AddByteOffset<T>(ref T source, nuint byteOffset)
- {
- return ref AddByteOffset(ref source, (IntPtr)(void*)byteOffset);
- }
-
- /// <summary>
- /// Determines whether the specified references point to the same location.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool AreSame<T>(ref T left, ref T right)
- {
- throw new PlatformNotSupportedException();
-
- // ldarg.0
- // ldarg.1
- // ceq
- // ret
- }
-
- /// <summary>
- /// Determines whether the memory address referenced by <paramref name="left"/> is greater than
- /// the memory address referenced by <paramref name="right"/>.
- /// </summary>
- /// <remarks>
- /// This check is conceptually similar to "(void*)(&amp;left) &gt; (void*)(&amp;right)".
- /// </remarks>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsAddressGreaterThan<T>(ref T left, ref T right)
- {
- throw new PlatformNotSupportedException();
-
- // ldarg.0
- // ldarg.1
- // cgt.un
- // ret
- }
-
- /// <summary>
- /// Determines whether the memory address referenced by <paramref name="left"/> is less than
- /// the memory address referenced by <paramref name="right"/>.
- /// </summary>
- /// <remarks>
- /// This check is conceptually similar to "(void*)(&amp;left) &lt; (void*)(&amp;right)".
- /// </remarks>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsAddressLessThan<T>(ref T left, ref T right)
- {
- throw new PlatformNotSupportedException();
-
- // ldarg.0
- // ldarg.1
- // clt.un
- // ret
- }
-
- /// <summary>
- /// Initializes a block of memory at the given location with a given initial value
- /// without assuming architecture dependent alignment of the address.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void InitBlockUnaligned(ref byte startAddress, byte value, uint byteCount)
- {
- for (uint i = 0; i < byteCount; i++)
- AddByteOffset(ref startAddress, i) = value;
- }
-
- /// <summary>
- /// Reads a value of type <typeparamref name="T"/> from the given location.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static T ReadUnaligned<T>(void* source)
- {
-#if CORECLR
- typeof(T).ToString(); // Type token used by the actual method body
- throw new PlatformNotSupportedException();
-#else
- return Unsafe.As<byte, T>(ref *(byte*)source);
-#endif
- }
-
- /// <summary>
- /// Reads a value of type <typeparamref name="T"/> from the given location.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static T ReadUnaligned<T>(ref byte source)
- {
-#if CORECLR
- typeof(T).ToString(); // Type token used by the actual method body
- throw new PlatformNotSupportedException();
-#else
- return Unsafe.As<byte, T>(ref source);
-#endif
- }
-
- /// <summary>
- /// Writes a value of type <typeparamref name="T"/> to the given location.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteUnaligned<T>(void* destination, T value)
- {
-#if CORECLR
- typeof(T).ToString(); // Type token used by the actual method body
- throw new PlatformNotSupportedException();
-#else
- Unsafe.As<byte, T>(ref *(byte*)destination) = value;
-#endif
- }
-
- /// <summary>
- /// Writes a value of type <typeparamref name="T"/> to the given location.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteUnaligned<T>(ref byte destination, T value)
- {
-#if CORECLR
- typeof(T).ToString(); // Type token used by the actual method body
- throw new PlatformNotSupportedException();
-#else
- Unsafe.As<byte, T>(ref destination) = value;
-#endif
- }
-
- /// <summary>
- /// Adds an element offset to the given reference.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref T AddByteOffset<T>(ref T source, IntPtr byteOffset)
- {
- // This method is implemented by the toolchain
- throw new PlatformNotSupportedException();
-
- // ldarg.0
- // ldarg.1
- // add
- // ret
- }
-
- /// <summary>
- /// Reads a value of type <typeparamref name="T"/> from the given location.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static T Read<T>(void* source)
- {
- return Unsafe.As<byte, T>(ref *(byte*)source);
- }
-
- /// <summary>
- /// Reads a value of type <typeparamref name="T"/> from the given location.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static T Read<T>(ref byte source)
- {
- return Unsafe.As<byte, T>(ref source);
- }
-
- /// <summary>
- /// Writes a value of type <typeparamref name="T"/> to the given location.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Write<T>(void* destination, T value)
- {
- Unsafe.As<byte, T>(ref *(byte*)destination) = value;
- }
-
- /// <summary>
- /// Writes a value of type <typeparamref name="T"/> to the given location.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Write<T>(ref byte destination, T value)
- {
- Unsafe.As<byte, T>(ref destination) = value;
- }
-
- /// <summary>
- /// Reinterprets the given location as a reference to a value of type <typeparamref name="T"/>.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref T AsRef<T>(void* source)
- {
- return ref Unsafe.As<byte, T>(ref *(byte*)source);
- }
-
- /// <summary>
- /// Reinterprets the given location as a reference to a value of type <typeparamref name="T"/>.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref T AsRef<T>(in T source)
- {
- throw new PlatformNotSupportedException();
- }
-
- /// <summary>
- /// Determines the byte offset from origin to target from the given references.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static IntPtr ByteOffset<T>(ref T origin, ref T target)
- {
- throw new PlatformNotSupportedException();
- }
-
- /// <summary>
- /// Returns a by-ref to type <typeparamref name="T"/> that is a null reference.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref T NullRef<T>()
- {
- return ref Unsafe.AsRef<T>(null);
-
- // ldc.i4.0
- // conv.u
- // ret
- }
-
- /// <summary>
- /// Returns if a given by-ref to type <typeparamref name="T"/> is a null reference.
- /// </summary>
- /// <remarks>
- /// This check is conceptually similar to "(void*)(&amp;source) == nullptr".
- /// </remarks>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsNullRef<T>(ref T source)
- {
- return Unsafe.AsPointer(ref source) == null;
-
- // ldarg.0
- // ldc.i4.0
- // conv.u
- // ceq
- // ret
- }
-
- /// <summary>
- /// Bypasses definite assignment rules by taking advantage of <c>out</c> semantics.
- /// </summary>
- [Intrinsic]
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void SkipInit<T>(out T value)
- {
- throw new PlatformNotSupportedException();
-
- // ret
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Internal/Threading/Tasks/AsyncCausalitySupport.cs b/netcore/System.Private.CoreLib/shared/Internal/Threading/Tasks/AsyncCausalitySupport.cs
deleted file mode 100644
index f05a201ee11..00000000000
--- a/netcore/System.Private.CoreLib/shared/Internal/Threading/Tasks/AsyncCausalitySupport.cs
+++ /dev/null
@@ -1,45 +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 System.Threading.Tasks;
-using System.Runtime.CompilerServices;
-
-namespace Internal.Threading.Tasks
-{
- /// <summary>Internal contract exposing just enough async debugger support needed by the AsTask() extension methods in the WindowsRuntimeSystemExtensions class.</summary>
- public static class AsyncCausalitySupport
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void AddToActiveTasks(Task task)
- {
- if (Task.s_asyncDebuggingEnabled)
- Task.AddToActiveTasks(task);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void RemoveFromActiveTasks(Task task)
- {
- if (Task.s_asyncDebuggingEnabled)
- Task.RemoveFromActiveTasks(task);
- }
-
- public static bool LoggingOn
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => AsyncCausalityTracer.LoggingOn;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void TraceOperationCreation(Task task, string operationName) =>
- AsyncCausalityTracer.TraceOperationCreation(task, operationName);
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void TraceOperationCompletedSuccess(Task task) =>
- AsyncCausalityTracer.TraceOperationCompletion(task, AsyncCausalityStatus.Completed);
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void TraceOperationCompletedError(Task task) =>
- AsyncCausalityTracer.TraceOperationCompletion(task, AsyncCausalityStatus.Error);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Internal/Win32/RegistryKey.cs b/netcore/System.Private.CoreLib/shared/Internal/Win32/RegistryKey.cs
deleted file mode 100644
index c4b3de8a04d..00000000000
--- a/netcore/System.Private.CoreLib/shared/Internal/Win32/RegistryKey.cs
+++ /dev/null
@@ -1,487 +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 System;
-using System.Buffers;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.IO;
-using System.Security;
-
-using Internal.Win32.SafeHandles;
-
-//
-// A minimal version of RegistryKey that supports just what CoreLib needs.
-//
-// Internal.Win32 namespace avoids confusion with the public standalone Microsoft.Win32.Registry implementation
-// that lives in corefx.
-//
-namespace Internal.Win32
-{
- internal sealed class RegistryKey : IDisposable
- {
- // MSDN defines the following limits for registry key names & values:
- // Key Name: 255 characters
- // Value name: 16,383 Unicode characters
- // Value: either 1 MB or current available memory, depending on registry format.
- private const int MaxKeyLength = 255;
- private const int MaxValueLength = 16383;
-
- private readonly SafeRegistryHandle _hkey;
-
- private RegistryKey(SafeRegistryHandle hkey)
- {
- _hkey = hkey;
- }
-
- void IDisposable.Dispose()
- {
- if (_hkey != null)
- {
- _hkey.Dispose();
- }
- }
-
- public void DeleteValue(string name, bool throwOnMissingValue)
- {
- int errorCode = Interop.Advapi32.RegDeleteValue(_hkey, name);
-
- //
- // From windows 2003 server, if the name is too long we will get error code ERROR_FILENAME_EXCED_RANGE
- // This still means the name doesn't exist. We need to be consistent with previous OS.
- //
- if (errorCode == Interop.Errors.ERROR_FILE_NOT_FOUND ||
- errorCode == Interop.Errors.ERROR_FILENAME_EXCED_RANGE)
- {
- if (throwOnMissingValue)
- {
- throw new ArgumentException(SR.Arg_RegSubKeyValueAbsent);
- }
- else
- {
- // Otherwise, reset and just return giving no indication to the user.
- // (For compatibility)
- errorCode = 0;
- }
- }
- // We really should throw an exception here if errorCode was bad,
- // but we can't for compatibility reasons.
- Debug.Assert(errorCode == 0, "RegDeleteValue failed. Here's your error code: " + errorCode);
- }
-
- internal static RegistryKey OpenBaseKey(IntPtr hKey)
- {
- return new RegistryKey(new SafeRegistryHandle(hKey, false));
- }
-
- public RegistryKey? OpenSubKey(string name)
- {
- return OpenSubKey(name, false);
- }
-
- public RegistryKey? OpenSubKey(string name, bool writable)
- {
- // Make sure that the name does not contain double slahes
- Debug.Assert(!name.Contains(@"\\"));
-
- int ret = Interop.Advapi32.RegOpenKeyEx(_hkey,
- name,
- 0,
- writable ?
- Interop.Advapi32.RegistryOperations.KEY_READ | Interop.Advapi32.RegistryOperations.KEY_WRITE :
- Interop.Advapi32.RegistryOperations.KEY_READ,
- out SafeRegistryHandle result);
-
- if (ret == 0 && !result.IsInvalid)
- {
- return new RegistryKey(result);
- }
-
- // Return null if we didn't find the key.
- if (ret == Interop.Errors.ERROR_ACCESS_DENIED || ret == Interop.Errors.ERROR_BAD_IMPERSONATION_LEVEL)
- {
- // We need to throw SecurityException here for compatibility reasons,
- // although UnauthorizedAccessException will make more sense.
- throw new SecurityException(SR.Security_RegistryPermission);
- }
-
- return null;
- }
-
- public string[] GetSubKeyNames()
- {
- var names = new List<string>();
- char[] name = ArrayPool<char>.Shared.Rent(MaxKeyLength + 1);
-
- try
- {
- int result;
- int nameLength = name.Length;
-
- while ((result = Interop.Advapi32.RegEnumKeyEx(
- _hkey,
- names.Count,
- name,
- ref nameLength,
- null,
- null,
- null,
- null)) != Interop.Errors.ERROR_NO_MORE_ITEMS)
- {
- switch (result)
- {
- case Interop.Errors.ERROR_SUCCESS:
- names.Add(new string(name, 0, nameLength));
- nameLength = name.Length;
- break;
- default:
- // Throw the error
- Win32Error(result, null);
- break;
- }
- }
- }
- finally
- {
- ArrayPool<char>.Shared.Return(name);
- }
-
- return names.ToArray();
- }
-
- public unsafe string[] GetValueNames()
- {
- var names = new List<string>();
-
- // Names in the registry aren't usually very long, although they can go to as large
- // as 16383 characters (MaxValueLength).
- //
- // Every call to RegEnumValue will allocate another buffer to get the data from
- // NtEnumerateValueKey before copying it back out to our passed in buffer. This can
- // add up quickly- we'll try to keep the memory pressure low and grow the buffer
- // only if needed.
-
- char[]? name = ArrayPool<char>.Shared.Rent(100);
-
- try
- {
- int result;
- int nameLength = name.Length;
-
- while ((result = Interop.Advapi32.RegEnumValue(
- _hkey,
- names.Count,
- name,
- ref nameLength,
- IntPtr.Zero,
- null,
- null,
- null)) != Interop.Errors.ERROR_NO_MORE_ITEMS)
- {
- switch (result)
- {
- // The size is only ever reported back correctly in the case
- // of ERROR_SUCCESS. It will almost always be changed, however.
- case Interop.Errors.ERROR_SUCCESS:
- names.Add(new string(name, 0, nameLength));
- break;
- case Interop.Errors.ERROR_MORE_DATA:
- {
- char[] oldName = name;
- int oldLength = oldName.Length;
- name = null;
- ArrayPool<char>.Shared.Return(oldName);
- name = ArrayPool<char>.Shared.Rent(checked(oldLength * 2));
- }
- break;
- default:
- // Throw the error
- Win32Error(result, null);
- break;
- }
-
- // Always set the name length back to the buffer size
- nameLength = name.Length;
- }
- }
- finally
- {
- if (name != null)
- ArrayPool<char>.Shared.Return(name);
- }
-
- return names.ToArray();
- }
-
- public object? GetValue(string name)
- {
- return GetValue(name, null);
- }
-
- [return: NotNullIfNotNull("defaultValue")]
- public object? GetValue(string name, object? defaultValue)
- {
- object? data = defaultValue;
- int type = 0;
- int datasize = 0;
-
- int ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, (byte[]?)null, ref datasize);
-
- if (ret != 0)
- {
- // For stuff like ERROR_FILE_NOT_FOUND, we want to return null (data).
- // Some OS's returned ERROR_MORE_DATA even in success cases, so we
- // want to continue on through the function.
- if (ret != Interop.Errors.ERROR_MORE_DATA)
- return data;
- }
-
- if (datasize < 0)
- {
- // unexpected code path
- Debug.Fail("[InternalGetValue] RegQueryValue returned ERROR_SUCCESS but gave a negative datasize");
- datasize = 0;
- }
-
-
- switch (type)
- {
- case Interop.Advapi32.RegistryValues.REG_NONE:
- case Interop.Advapi32.RegistryValues.REG_DWORD_BIG_ENDIAN:
- case Interop.Advapi32.RegistryValues.REG_BINARY:
- {
- byte[] blob = new byte[datasize];
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
- data = blob;
- }
- break;
- case Interop.Advapi32.RegistryValues.REG_QWORD:
- { // also REG_QWORD_LITTLE_ENDIAN
- if (datasize > 8)
- {
- // prevent an AV in the edge case that datasize is larger than sizeof(long)
- goto case Interop.Advapi32.RegistryValues.REG_BINARY;
- }
- long blob = 0;
- Debug.Assert(datasize == 8, "datasize==8");
- // Here, datasize must be 8 when calling this
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, ref blob, ref datasize);
-
- data = blob;
- }
- break;
- case Interop.Advapi32.RegistryValues.REG_DWORD:
- { // also REG_DWORD_LITTLE_ENDIAN
- if (datasize > 4)
- {
- // prevent an AV in the edge case that datasize is larger than sizeof(int)
- goto case Interop.Advapi32.RegistryValues.REG_QWORD;
- }
- int blob = 0;
- Debug.Assert(datasize == 4, "datasize==4");
- // Here, datasize must be four when calling this
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, ref blob, ref datasize);
-
- data = blob;
- }
- break;
-
- case Interop.Advapi32.RegistryValues.REG_SZ:
- {
- if (datasize % 2 == 1)
- {
- // handle the case where the registry contains an odd-byte length (corrupt data?)
- try
- {
- datasize = checked(datasize + 1);
- }
- catch (OverflowException e)
- {
- throw new IOException(SR.Arg_RegGetOverflowBug, e);
- }
- }
- char[] blob = new char[datasize / 2];
-
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
- if (blob.Length > 0 && blob[^1] == (char)0)
- {
- data = new string(blob, 0, blob.Length - 1);
- }
- else
- {
- // in the very unlikely case the data is missing null termination,
- // pass in the whole char[] to prevent truncating a character
- data = new string(blob);
- }
- }
- break;
-
- case Interop.Advapi32.RegistryValues.REG_EXPAND_SZ:
- {
- if (datasize % 2 == 1)
- {
- // handle the case where the registry contains an odd-byte length (corrupt data?)
- try
- {
- datasize = checked(datasize + 1);
- }
- catch (OverflowException e)
- {
- throw new IOException(SR.Arg_RegGetOverflowBug, e);
- }
- }
- char[] blob = new char[datasize / 2];
-
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
-
- if (blob.Length > 0 && blob[^1] == (char)0)
- {
- data = new string(blob, 0, blob.Length - 1);
- }
- else
- {
- // in the very unlikely case the data is missing null termination,
- // pass in the whole char[] to prevent truncating a character
- data = new string(blob);
- }
-
- data = Environment.ExpandEnvironmentVariables((string)data);
- }
- break;
- case Interop.Advapi32.RegistryValues.REG_MULTI_SZ:
- {
- if (datasize % 2 == 1)
- {
- // handle the case where the registry contains an odd-byte length (corrupt data?)
- try
- {
- datasize = checked(datasize + 1);
- }
- catch (OverflowException e)
- {
- throw new IOException(SR.Arg_RegGetOverflowBug, e);
- }
- }
- char[] blob = new char[datasize / 2];
-
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
-
- // make sure the string is null terminated before processing the data
- if (blob.Length > 0 && blob[^1] != (char)0)
- {
- Array.Resize(ref blob, blob.Length + 1);
- }
-
- string[] strings = Array.Empty<string>();
- int stringsCount = 0;
-
- int cur = 0;
- int len = blob.Length;
-
- while (ret == 0 && cur < len)
- {
- int nextNull = cur;
- while (nextNull < len && blob[nextNull] != (char)0)
- {
- nextNull++;
- }
-
- string? toAdd = null;
- if (nextNull < len)
- {
- Debug.Assert(blob[nextNull] == (char)0, "blob[nextNull] should be 0");
- if (nextNull - cur > 0)
- {
- toAdd = new string(blob, cur, nextNull - cur);
- }
- else
- {
- // we found an empty string. But if we're at the end of the data,
- // it's just the extra null terminator.
- if (nextNull != len - 1)
- {
- toAdd = string.Empty;
- }
- }
- }
- else
- {
- toAdd = new string(blob, cur, len - cur);
- }
- cur = nextNull + 1;
-
- if (toAdd != null)
- {
- if (strings.Length == stringsCount)
- {
- Array.Resize(ref strings, stringsCount > 0 ? stringsCount * 2 : 4);
- }
- strings[stringsCount++] = toAdd;
- }
- }
-
- Array.Resize(ref strings, stringsCount);
- data = strings;
- }
- break;
- case Interop.Advapi32.RegistryValues.REG_LINK:
- default:
- break;
- }
-
- return data;
- }
-
- // The actual api is SetValue(string name, object value) but we only need to set Strings
- // so this is a cut-down version that supports on that.
- internal void SetValue(string name, string value)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- if (name != null && name.Length > MaxValueLength)
- throw new ArgumentException(SR.Arg_RegValStrLenBug, nameof(name));
-
- int ret = Interop.Advapi32.RegSetValueEx(_hkey,
- name,
- 0,
- Interop.Advapi32.RegistryValues.REG_SZ,
- value,
- checked(value.Length * 2 + 2));
-
- if (ret != 0)
- {
- Win32Error(ret, null);
- }
- }
-
- internal static void Win32Error(int errorCode, string? str)
- {
- switch (errorCode)
- {
- case Interop.Errors.ERROR_ACCESS_DENIED:
- if (str != null)
- throw new UnauthorizedAccessException(SR.Format(SR.UnauthorizedAccess_RegistryKeyGeneric_Key, str));
- else
- throw new UnauthorizedAccessException();
-
- case Interop.Errors.ERROR_FILE_NOT_FOUND:
- throw new IOException(SR.Arg_RegKeyNotFound, errorCode);
-
- default:
- throw new IOException(Interop.Kernel32.GetMessage(errorCode), errorCode);
- }
- }
- }
-
- internal static class Registry
- {
- /// <summary>Current User Key. This key should be used as the root for all user specific settings.</summary>
- public static readonly RegistryKey CurrentUser = RegistryKey.OpenBaseKey(unchecked((IntPtr)(int)0x80000001));
-
- /// <summary>Local Machine key. This key should be used as the root for all machine specific settings.</summary>
- public static readonly RegistryKey LocalMachine = RegistryKey.OpenBaseKey(unchecked((IntPtr)(int)0x80000002));
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.Errors.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.Errors.cs
deleted file mode 100644
index 943df86c229..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.Errors.cs
+++ /dev/null
@@ -1,210 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- /// <summary>Common Unix errno error codes.</summary>
- internal enum Error
- {
- // These values were defined in src/Native/System.Native/fxerrno.h
- //
- // They compare against values obtained via Interop.Sys.GetLastError() not Marshal.GetLastWin32Error()
- // which obtains the raw errno that varies between unixes. The strong typing as an enum is meant to
- // prevent confusing the two. Casting to or from int is suspect. Use GetLastErrorInfo() if you need to
- // correlate these to the underlying platform values or obtain the corresponding error message.
- //
-
- SUCCESS = 0,
-
- E2BIG = 0x10001, // Argument list too long.
- EACCES = 0x10002, // Permission denied.
- EADDRINUSE = 0x10003, // Address in use.
- EADDRNOTAVAIL = 0x10004, // Address not available.
- EAFNOSUPPORT = 0x10005, // Address family not supported.
- EAGAIN = 0x10006, // Resource unavailable, try again (same value as EWOULDBLOCK),
- EALREADY = 0x10007, // Connection already in progress.
- EBADF = 0x10008, // Bad file descriptor.
- EBADMSG = 0x10009, // Bad message.
- EBUSY = 0x1000A, // Device or resource busy.
- ECANCELED = 0x1000B, // Operation canceled.
- ECHILD = 0x1000C, // No child processes.
- ECONNABORTED = 0x1000D, // Connection aborted.
- ECONNREFUSED = 0x1000E, // Connection refused.
- ECONNRESET = 0x1000F, // Connection reset.
- EDEADLK = 0x10010, // Resource deadlock would occur.
- EDESTADDRREQ = 0x10011, // Destination address required.
- EDOM = 0x10012, // Mathematics argument out of domain of function.
- EDQUOT = 0x10013, // Reserved.
- EEXIST = 0x10014, // File exists.
- EFAULT = 0x10015, // Bad address.
- EFBIG = 0x10016, // File too large.
- EHOSTUNREACH = 0x10017, // Host is unreachable.
- EIDRM = 0x10018, // Identifier removed.
- EILSEQ = 0x10019, // Illegal byte sequence.
- EINPROGRESS = 0x1001A, // Operation in progress.
- EINTR = 0x1001B, // Interrupted function.
- EINVAL = 0x1001C, // Invalid argument.
- EIO = 0x1001D, // I/O error.
- EISCONN = 0x1001E, // Socket is connected.
- EISDIR = 0x1001F, // Is a directory.
- ELOOP = 0x10020, // Too many levels of symbolic links.
- EMFILE = 0x10021, // File descriptor value too large.
- EMLINK = 0x10022, // Too many links.
- EMSGSIZE = 0x10023, // Message too large.
- EMULTIHOP = 0x10024, // Reserved.
- ENAMETOOLONG = 0x10025, // Filename too long.
- ENETDOWN = 0x10026, // Network is down.
- ENETRESET = 0x10027, // Connection aborted by network.
- ENETUNREACH = 0x10028, // Network unreachable.
- ENFILE = 0x10029, // Too many files open in system.
- ENOBUFS = 0x1002A, // No buffer space available.
- ENODEV = 0x1002C, // No such device.
- ENOENT = 0x1002D, // No such file or directory.
- ENOEXEC = 0x1002E, // Executable file format error.
- ENOLCK = 0x1002F, // No locks available.
- ENOLINK = 0x10030, // Reserved.
- ENOMEM = 0x10031, // Not enough space.
- ENOMSG = 0x10032, // No message of the desired type.
- ENOPROTOOPT = 0x10033, // Protocol not available.
- ENOSPC = 0x10034, // No space left on device.
- ENOSYS = 0x10037, // Function not supported.
- ENOTCONN = 0x10038, // The socket is not connected.
- ENOTDIR = 0x10039, // Not a directory or a symbolic link to a directory.
- ENOTEMPTY = 0x1003A, // Directory not empty.
- ENOTRECOVERABLE = 0x1003B, // State not recoverable.
- ENOTSOCK = 0x1003C, // Not a socket.
- ENOTSUP = 0x1003D, // Not supported (same value as EOPNOTSUP).
- ENOTTY = 0x1003E, // Inappropriate I/O control operation.
- ENXIO = 0x1003F, // No such device or address.
- EOVERFLOW = 0x10040, // Value too large to be stored in data type.
- EOWNERDEAD = 0x10041, // Previous owner died.
- EPERM = 0x10042, // Operation not permitted.
- EPIPE = 0x10043, // Broken pipe.
- EPROTO = 0x10044, // Protocol error.
- EPROTONOSUPPORT = 0x10045, // Protocol not supported.
- EPROTOTYPE = 0x10046, // Protocol wrong type for socket.
- ERANGE = 0x10047, // Result too large.
- EROFS = 0x10048, // Read-only file system.
- ESPIPE = 0x10049, // Invalid seek.
- ESRCH = 0x1004A, // No such process.
- ESTALE = 0x1004B, // Reserved.
- ETIMEDOUT = 0x1004D, // Connection timed out.
- ETXTBSY = 0x1004E, // Text file busy.
- EXDEV = 0x1004F, // Cross-device link.
- ESOCKTNOSUPPORT = 0x1005E, // Socket type not supported.
- EPFNOSUPPORT = 0x10060, // Protocol family not supported.
- ESHUTDOWN = 0x1006C, // Socket shutdown.
- EHOSTDOWN = 0x10070, // Host is down.
- ENODATA = 0x10071, // No data available.
-
- // Custom Error codes to track errors beyond kernel interface.
- EHOSTNOTFOUND = 0x20001, // Name lookup failed
-
- // POSIX permits these to have the same value and we make them always equal so
- // that CoreFX cannot introduce a dependency on distinguishing between them that
- // would not work on all platforms.
- EOPNOTSUPP = ENOTSUP, // Operation not supported on socket.
- EWOULDBLOCK = EAGAIN, // Operation would block.
- }
-
-
- // Represents a platform-agnostic Error and underlying platform-specific errno
- internal struct ErrorInfo
- {
- private Error _error;
- private int _rawErrno;
-
- internal ErrorInfo(int errno)
- {
- _error = Interop.Sys.ConvertErrorPlatformToPal(errno);
- _rawErrno = errno;
- }
-
- internal ErrorInfo(Error error)
- {
- _error = error;
- _rawErrno = -1;
- }
-
- internal Error Error
- {
- get { return _error; }
- }
-
- internal int RawErrno
- {
- get { return _rawErrno == -1 ? (_rawErrno = Interop.Sys.ConvertErrorPalToPlatform(_error)) : _rawErrno; }
- }
-
- internal string GetErrorMessage()
- {
- return Interop.Sys.StrError(RawErrno);
- }
-
- public override string ToString()
- {
- return $"RawErrno: {RawErrno} Error: {Error} GetErrorMessage: {GetErrorMessage()}"; // No localization required; text is member names used for debugging purposes
- }
- }
-
- internal static partial class Sys
- {
- internal static Error GetLastError()
- {
- return ConvertErrorPlatformToPal(Marshal.GetLastWin32Error());
- }
-
- internal static ErrorInfo GetLastErrorInfo()
- {
- return new ErrorInfo(Marshal.GetLastWin32Error());
- }
-
- internal static unsafe string StrError(int platformErrno)
- {
- int maxBufferLength = 1024; // should be long enough for most any UNIX error
- byte* buffer = stackalloc byte[maxBufferLength];
- byte* message = StrErrorR(platformErrno, buffer, maxBufferLength);
-
- if (message == null)
- {
- // This means the buffer was not large enough, but still contains
- // as much of the error message as possible and is guaranteed to
- // be null-terminated. We're not currently resizing/retrying because
- // maxBufferLength is large enough in practice, but we could do
- // so here in the future if necessary.
- message = buffer;
- }
-
- return Marshal.PtrToStringAnsi((IntPtr)message)!;
- }
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ConvertErrorPlatformToPal")]
- internal static extern Error ConvertErrorPlatformToPal(int platformErrno);
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ConvertErrorPalToPlatform")]
- internal static extern int ConvertErrorPalToPlatform(Error error);
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_StrErrorR")]
- private static extern unsafe byte* StrErrorR(int platformErrno, byte* buffer, int bufferSize);
- }
-}
-
-// NOTE: extension method can't be nested inside Interop class.
-internal static class InteropErrorExtensions
-{
- // Intended usage is e.g. Interop.Error.EFAIL.Info() for brevity
- // vs. new Interop.ErrorInfo(Interop.Error.EFAIL) for synthesizing
- // errors. Errors originated from the system should be obtained
- // via GetLastErrorInfo(), not GetLastError().Info() as that will
- // convert twice, which is not only inefficient but also lossy if
- // we ever encounter a raw errno that no equivalent in the Error
- // enum.
- public static Interop.ErrorInfo Info(this Interop.Error error)
- {
- return new Interop.ErrorInfo(error);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.IOErrors.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.IOErrors.cs
deleted file mode 100644
index 666220ea194..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.IOErrors.cs
+++ /dev/null
@@ -1,173 +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.
-
-#nullable enable
-using System;
-using System.Diagnostics;
-using System.IO;
-using System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-internal static partial class Interop
-{
- private static void ThrowExceptionForIoErrno(ErrorInfo errorInfo, string? path, bool isDirectory, Func<ErrorInfo, ErrorInfo>? errorRewriter)
- {
- Debug.Assert(errorInfo.Error != Error.SUCCESS);
- Debug.Assert(errorInfo.Error != Error.EINTR, "EINTR errors should be handled by the native shim and never bubble up to managed code");
-
- if (errorRewriter != null)
- {
- errorInfo = errorRewriter(errorInfo);
- }
-
- throw Interop.GetExceptionForIoErrno(errorInfo, path, isDirectory);
- }
-
- internal static void CheckIo(Error error, string? path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo>? errorRewriter = null)
- {
- if (error != Interop.Error.SUCCESS)
- {
- ThrowExceptionForIoErrno(error.Info(), path, isDirectory, errorRewriter);
- }
- }
-
- /// <summary>
- /// Validates the result of system call that returns greater than or equal to 0 on success
- /// and less than 0 on failure, with errno set to the error code.
- /// If the system call failed for any reason, an exception is thrown. Otherwise, the system call succeeded.
- /// </summary>
- /// <param name="result">The result of the system call.</param>
- /// <param name="path">The path with which this error is associated. This may be null.</param>
- /// <param name="isDirectory">true if the <paramref name="path"/> is known to be a directory; otherwise, false.</param>
- /// <param name="errorRewriter">Optional function to change an error code prior to processing it.</param>
- /// <returns>
- /// On success, returns the non-negative result long that was validated.
- /// </returns>
- internal static long CheckIo(long result, string? path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo>? errorRewriter = null)
- {
- if (result < 0)
- {
- ThrowExceptionForIoErrno(Sys.GetLastErrorInfo(), path, isDirectory, errorRewriter);
- }
-
- return result;
- }
-
- /// <summary>
- /// Validates the result of system call that returns greater than or equal to 0 on success
- /// and less than 0 on failure, with errno set to the error code.
- /// If the system call failed for any reason, an exception is thrown. Otherwise, the system call succeeded.
- /// </summary>
- /// <returns>
- /// On success, returns the non-negative result int that was validated.
- /// </returns>
- internal static int CheckIo(int result, string? path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo>? errorRewriter = null)
- {
- CheckIo((long)result, path, isDirectory, errorRewriter);
-
- return result;
- }
-
- /// <summary>
- /// Validates the result of system call that returns greater than or equal to 0 on success
- /// and less than 0 on failure, with errno set to the error code.
- /// If the system call failed for any reason, an exception is thrown. Otherwise, the system call succeeded.
- /// </summary>
- /// <returns>
- /// On success, returns the non-negative result IntPtr that was validated.
- /// </returns>
- internal static IntPtr CheckIo(IntPtr result, string? path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo>? errorRewriter = null)
- {
- CheckIo((long)result, path, isDirectory, errorRewriter);
-
- return result;
- }
-
- /// <summary>
- /// Validates the result of system call that returns greater than or equal to 0 on success
- /// and less than 0 on failure, with errno set to the error code.
- /// If the system call failed for any reason, an exception is thrown. Otherwise, the system call succeeded.
- /// </summary>
- /// <returns>
- /// On success, returns the valid SafeFileHandle that was validated.
- /// </returns>
- internal static TSafeHandle CheckIo<TSafeHandle>(TSafeHandle handle, string? path = null, bool isDirectory = false, Func<ErrorInfo, ErrorInfo>? errorRewriter = null)
- where TSafeHandle : SafeHandle
- {
- if (handle.IsInvalid)
- {
- ThrowExceptionForIoErrno(Sys.GetLastErrorInfo(), path, isDirectory, errorRewriter);
- }
-
- return handle;
- }
-
- /// <summary>
- /// Gets an Exception to represent the supplied error info.
- /// </summary>
- /// <param name="errorInfo">The error info</param>
- /// <param name="path">The path with which this error is associated. This may be null.</param>
- /// <param name="isDirectory">true if the <paramref name="path"/> is known to be a directory; otherwise, false.</param>
- /// <returns></returns>
- internal static Exception GetExceptionForIoErrno(ErrorInfo errorInfo, string? path = null, bool isDirectory = false)
- {
- // Translate the errno into a known set of exception types. For cases where multiple errnos map
- // to the same exception type, include an inner exception with the details.
- switch (errorInfo.Error)
- {
- case Error.ENOENT:
- if (isDirectory)
- {
- return !string.IsNullOrEmpty(path) ?
- new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, path)) :
- new DirectoryNotFoundException(SR.IO_PathNotFound_NoPathName);
- }
- else
- {
- return !string.IsNullOrEmpty(path) ?
- new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, path), path) :
- new FileNotFoundException(SR.IO_FileNotFound);
- }
-
- case Error.EACCES:
- case Error.EBADF:
- case Error.EPERM:
- Exception inner = GetIOException(errorInfo);
- return !string.IsNullOrEmpty(path) ?
- new UnauthorizedAccessException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, path), inner) :
- new UnauthorizedAccessException(SR.UnauthorizedAccess_IODenied_NoPathName, inner);
-
- case Error.ENAMETOOLONG:
- return !string.IsNullOrEmpty(path) ?
- new PathTooLongException(SR.Format(SR.IO_PathTooLong_Path, path)) :
- new PathTooLongException(SR.IO_PathTooLong);
-
- case Error.EWOULDBLOCK:
- return !string.IsNullOrEmpty(path) ?
- new IOException(SR.Format(SR.IO_SharingViolation_File, path), errorInfo.RawErrno) :
- new IOException(SR.IO_SharingViolation_NoFileName, errorInfo.RawErrno);
-
- case Error.ECANCELED:
- return new OperationCanceledException();
-
- case Error.EFBIG:
- return new ArgumentOutOfRangeException("value", SR.ArgumentOutOfRange_FileLengthTooBig);
-
- case Error.EEXIST:
- if (!string.IsNullOrEmpty(path))
- {
- return new IOException(SR.Format(SR.IO_FileExists_Name, path), errorInfo.RawErrno);
- }
- goto default;
-
- default:
- return GetIOException(errorInfo);
- }
- }
-
- internal static Exception GetIOException(Interop.ErrorInfo errorInfo)
- {
- return new IOException(errorInfo.GetErrorMessage(), errorInfo.RawErrno);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.Libraries.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.Libraries.cs
deleted file mode 100644
index 02d00924450..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/Interop.Libraries.cs
+++ /dev/null
@@ -1,12 +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.
-
-internal static partial class Interop
-{
- internal static partial class Libraries
- {
- internal const string GlobalizationNative = "System.Globalization.Native";
- internal const string SystemNative = "System.Native";
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs
deleted file mode 100644
index 764bdaf85af..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs
+++ /dev/null
@@ -1,33 +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 System;
-using System.Globalization;
-using System.Runtime.InteropServices;
-using System.Text;
-
-internal static partial class Interop
-{
- internal static partial class Globalization
- {
- internal delegate void EnumCalendarInfoCallback(
- [MarshalAs(UnmanagedType.LPWStr)] string calendarString,
- IntPtr context);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendars")]
- internal static extern int GetCalendars(string localeName, CalendarId[] calendars, int calendarsCapacity);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendarInfo")]
- internal static extern unsafe ResultCode GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType calendarDataType, char* result, int resultCapacity);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")]
- internal static extern bool EnumCalendarInfo(EnumCalendarInfoCallback callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context);
-
- [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLatestJapaneseEra")]
- internal static extern int GetLatestJapaneseEra();
-
- [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetJapaneseEraStartDate")]
- internal static extern bool GetJapaneseEraStartDate(int era, out int startYear, out int startMonth, out int startDay);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Casing.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Casing.cs
deleted file mode 100644
index 503a864d693..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Casing.cs
+++ /dev/null
@@ -1,23 +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 System;
-using System.Runtime.InteropServices;
-using System.Security;
-using System.Text;
-
-internal static partial class Interop
-{
- internal static partial class Globalization
- {
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCase")]
- internal static extern unsafe void ChangeCase(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseInvariant")]
- internal static extern unsafe void ChangeCaseInvariant(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseTurkish")]
- internal static extern unsafe void ChangeCaseTurkish(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Collation.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Collation.cs
deleted file mode 100644
index 7d0175473d7..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Collation.cs
+++ /dev/null
@@ -1,59 +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 System;
-using System.Globalization;
-using System.Runtime.InteropServices;
-using System.Security;
-
-internal static partial class Interop
-{
- internal static partial class Globalization
- {
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Ansi, EntryPoint = "GlobalizationNative_GetSortHandle")]
- internal static extern unsafe ResultCode GetSortHandle(string localeName, out IntPtr sortHandle);
-
- [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_CloseSortHandle")]
- internal static extern unsafe void CloseSortHandle(IntPtr handle);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CompareString")]
- internal static extern unsafe int CompareString(IntPtr sortHandle, char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len, CompareOptions options);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOf")]
- internal static extern unsafe int IndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_LastIndexOf")]
- internal static extern unsafe int LastIndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOfOrdinalIgnoreCase")]
- internal static extern unsafe int IndexOfOrdinalIgnoreCase(string target, int cwTargetLength, char* pSource, int cwSourceLength, bool findLast);
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOfOrdinalIgnoreCase")]
- internal static extern unsafe int IndexOfOrdinalIgnoreCase(char* target, int cwTargetLength, char* pSource, int cwSourceLength, bool findLast);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_StartsWith")]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern unsafe bool StartsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EndsWith")]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern unsafe bool EndsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_StartsWith")]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern unsafe bool StartsWith(IntPtr sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EndsWith")]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern unsafe bool EndsWith(IntPtr sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortKey")]
- internal static extern unsafe int GetSortKey(IntPtr sortHandle, char* str, int strLength, byte* sortKey, int sortKeyLength, CompareOptions options);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CompareStringOrdinalIgnoreCase")]
- internal static extern unsafe int CompareStringOrdinalIgnoreCase(char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len);
-
- [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortVersion")]
- internal static extern int GetSortVersion(IntPtr sortHandle);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.ICU.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.ICU.cs
deleted file mode 100644
index a16c813b2f5..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.ICU.cs
+++ /dev/null
@@ -1,16 +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 System;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-
-internal static partial class Interop
-{
- internal static partial class Globalization
- {
- [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_LoadICU")]
- internal static extern int LoadICU();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Idna.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Idna.cs
deleted file mode 100644
index 89b6c3cebec..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Idna.cs
+++ /dev/null
@@ -1,21 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Globalization
- {
- internal const int AllowUnassigned = 0x1;
- internal const int UseStd3AsciiRules = 0x2;
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToAscii")]
- internal static extern unsafe int ToAscii(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToUnicode")]
- internal static extern unsafe int ToUnicode(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Locale.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Locale.cs
deleted file mode 100644
index b563752bc00..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Locale.cs
+++ /dev/null
@@ -1,39 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Globalization
- {
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleName")]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern unsafe bool GetLocaleName(string localeName, char* value, int valueLength);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoString")]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern unsafe bool GetLocaleInfoString(string localeName, uint localeStringData, char* value, int valueLength);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetDefaultLocaleName")]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern unsafe bool GetDefaultLocaleName(char* value, int valueLength);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleTimeFormat")]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern unsafe bool GetLocaleTimeFormat(string localeName, bool shortFormat, char* value, int valueLength);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoInt")]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetLocaleInfoInt(string localeName, uint localeNumberData, ref int value);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoGroupingSizes")]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetLocaleInfoGroupingSizes(string localeName, uint localeGroupingData, ref int primaryGroupSize, ref int secondaryGroupSize);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocales")]
- internal static extern int GetLocales([Out] char[]? value, int valueLength);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs
deleted file mode 100644
index d442da0ea13..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs
+++ /dev/null
@@ -1,19 +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 System;
-using System.Runtime.InteropServices;
-using System.Text;
-
-internal static partial class Interop
-{
- internal static partial class Globalization
- {
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IsNormalized")]
- internal static extern int IsNormalized(NormalizationForm normalizationForm, string src, int srcLen);
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_NormalizeString")]
- internal static extern int NormalizeString(NormalizationForm normalizationForm, string src, int srcLen, [Out] char[] dstBuffer, int dstBufferCapacity);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs
deleted file mode 100644
index 4a9933f9291..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs
+++ /dev/null
@@ -1,18 +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.
-
-internal static partial class Interop
-{
- internal static partial class Globalization
- {
- // needs to be kept in sync with ResultCode in System.Globalization.Native
- internal enum ResultCode
- {
- Success = 0,
- UnknownError = 1,
- InsufficentBuffer = 2,
- OutOfMemory = 3
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs
deleted file mode 100644
index df488b6ffa1..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs
+++ /dev/null
@@ -1,28 +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 System.Runtime.InteropServices;
-using System.Text;
-
-internal static partial class Interop
-{
- internal static partial class Globalization
- {
- // needs to be kept in sync with TimeZoneDisplayNameType in System.Globalization.Native
- internal enum TimeZoneDisplayNameType
- {
- Generic = 0,
- Standard = 1,
- DaylightSavings = 2,
- }
-
- [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetTimeZoneDisplayName")]
- internal static extern unsafe ResultCode GetTimeZoneDisplayName(
- string localeName,
- string timeZoneId,
- TimeZoneDisplayNameType type,
- char* result,
- int resultLength);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Utils.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Utils.cs
deleted file mode 100644
index 627ab56c918..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Globalization.Native/Interop.Utils.cs
+++ /dev/null
@@ -1,48 +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 System;
-using System.Diagnostics;
-using System.Buffers;
-using System.Text;
-
-internal static partial class Interop
-{
- /// <summary>
- /// Helper for making interop calls that return a string, but we don't know
- /// the correct size of buffer to make. So invoke the interop call with an
- /// increasing buffer until the size is big enough.
- /// </summary>
- internal static bool CallStringMethod<TArg1, TArg2, TArg3>(
- SpanFunc<char, TArg1, TArg2, TArg3, Interop.Globalization.ResultCode> interopCall,
- TArg1 arg1, TArg2 arg2, TArg3 arg3,
- out string? result)
- {
- const int InitialSize = 256; // arbitrary stack allocation size
- const int MaxHeapSize = 1280; // max from previous version of the code, starting at 80 and doubling four times
-
- Span<char> buffer = stackalloc char[InitialSize];
- Interop.Globalization.ResultCode resultCode = interopCall(buffer, arg1, arg2, arg3);
-
- if (resultCode == Interop.Globalization.ResultCode.Success)
- {
- result = buffer.Slice(0, buffer.IndexOf('\0')).ToString();
- return true;
- }
-
- if (resultCode == Interop.Globalization.ResultCode.InsufficentBuffer)
- {
- // Increase the string size and try again
- buffer = new char[MaxHeapSize];
- if (interopCall(buffer, arg1, arg2, arg3) == Interop.Globalization.ResultCode.Success)
- {
- result = buffer.Slice(0, buffer.IndexOf('\0')).ToString();
- return true;
- }
- }
-
- result = null;
- return false;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Access.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Access.cs
deleted file mode 100644
index a723f572a5b..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Access.cs
+++ /dev/null
@@ -1,23 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- internal enum AccessMode : int
- {
- F_OK = 0, /* Check for existence */
- X_OK = 1, /* Check for execute */
- W_OK = 2, /* Check for write */
- R_OK = 4, /* Check for read */
- }
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Access", SetLastError = true)]
- internal static extern int Access(string path, AccessMode mode);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ChDir.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ChDir.cs
deleted file mode 100644
index 3c66995182a..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ChDir.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ChDir", SetLastError = true)]
- internal static extern int ChDir(string path);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Close.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Close.cs
deleted file mode 100644
index 8d192398a03..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Close.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Close", SetLastError = true)]
- internal static extern int Close(IntPtr fd);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FLock.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FLock.cs
deleted file mode 100644
index 22934a3e77d..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FLock.cs
+++ /dev/null
@@ -1,31 +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 System;
-using System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- internal enum LockOperations : int
- {
- LOCK_SH = 1, /* shared lock */
- LOCK_EX = 2, /* exclusive lock */
- LOCK_NB = 4, /* don't block when locking*/
- LOCK_UN = 8, /* unlock */
- }
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FLock", SetLastError = true)]
- internal static extern int FLock(SafeFileHandle fd, LockOperations operation);
-
- /// <summary>
- /// Exposing this for SafeFileHandle.ReleaseHandle() to call.
- /// Normal callers should use FLock(SafeFileHandle fd).
- /// </summary>
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FLock", SetLastError = true)]
- internal static extern int FLock(IntPtr fd, LockOperations operation);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FSync.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FSync.cs
deleted file mode 100644
index e3ab9709313..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FSync.cs
+++ /dev/null
@@ -1,15 +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 System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FSync", SetLastError = true)]
- internal static extern int FSync(SafeFileHandle fd);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FTruncate.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FTruncate.cs
deleted file mode 100644
index 5dad650362d..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.FTruncate.cs
+++ /dev/null
@@ -1,15 +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 System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FTruncate", SetLastError = true)]
- internal static extern int FTruncate(SafeFileHandle fd, long length);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs
deleted file mode 100644
index a630a3e82c3..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCpuUtilization.cs
+++ /dev/null
@@ -1,24 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal unsafe partial class Sys
- {
- [StructLayout(LayoutKind.Sequential)]
- internal struct ProcessCpuInformation
- {
- internal ulong lastRecordedCurrentTime;
- internal ulong lastRecordedKernelTime;
- internal ulong lastRecordedUserTime;
- }
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetCpuUtilization")]
- internal static extern unsafe int GetCpuUtilization(ref ProcessCpuInformation previousCpuInfo);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCwd.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCwd.cs
deleted file mode 100644
index b339ab2f596..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetCwd.cs
+++ /dev/null
@@ -1,73 +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 System;
-using System.Buffers;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetCwd", SetLastError = true)]
- private static extern unsafe byte* GetCwd(byte* buffer, int bufferLength);
-
- internal static unsafe string GetCwd()
- {
- const int StackLimit = 256;
-
- // First try to get the path into a buffer on the stack
- byte* stackBuf = stackalloc byte[StackLimit];
- string? result = GetCwdHelper(stackBuf, StackLimit);
- if (result != null)
- {
- return result;
- }
-
- // If that was too small, try increasing large buffer sizes
- int bufferSize = StackLimit;
- while (true)
- {
- checked { bufferSize *= 2; }
- byte[] buf = ArrayPool<byte>.Shared.Rent(bufferSize);
- try
- {
- fixed (byte* ptr = &buf[0])
- {
- result = GetCwdHelper(ptr, buf.Length);
- if (result != null)
- {
- return result;
- }
- }
- }
- finally
- {
- ArrayPool<byte>.Shared.Return(buf);
- }
- }
- }
-
- private static unsafe string? GetCwdHelper(byte* ptr, int bufferSize)
- {
- // Call the real getcwd
- byte* result = GetCwd(ptr, bufferSize);
-
- // If it returned non-null, the null-terminated path is in the buffer
- if (result != null)
- {
- return Marshal.PtrToStringAnsi((IntPtr)ptr);
- }
-
- // Otherwise, if it failed due to the buffer being too small, return null;
- // for anything else, throw.
- ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
- if (errorInfo.Error == Interop.Error.ERANGE)
- {
- return null;
- }
- throw Interop.GetExceptionForIoErrno(errorInfo);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetEUid.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetEUid.cs
deleted file mode 100644
index 8b525fa3272..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetEUid.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEUid")]
- internal static extern uint GetEUid();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetHostName.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetHostName.cs
deleted file mode 100644
index f2555b0fc82..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetHostName.cs
+++ /dev/null
@@ -1,40 +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 System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetHostName", SetLastError = true)]
- private static extern unsafe int GetHostName(byte* name, int nameLength);
-
- internal static unsafe string GetHostName()
- {
- const int HOST_NAME_MAX = 255;
- const int ArrLength = HOST_NAME_MAX + 1;
-
- byte* name = stackalloc byte[ArrLength];
- int err = GetHostName(name, ArrLength);
- if (err != 0)
- {
- // This should never happen. According to the man page,
- // the only possible errno for gethostname is ENAMETOOLONG,
- // which should only happen if the buffer we supply isn't big
- // enough, and we're using a buffer size that the man page
- // says is the max for POSIX (and larger than the max for Linux).
- Debug.Fail($"GetHostName failed with error {err}");
- throw new InvalidOperationException($"{nameof(GetHostName)}: {err}");
- }
-
- // If the hostname is truncated, it is unspecified whether the returned buffer includes a terminating null byte.
- name[ArrLength - 1] = 0;
-
- return Marshal.PtrToStringAnsi((IntPtr)name)!;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetPid.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetPid.cs
deleted file mode 100644
index 02d259db7d1..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetPid.cs
+++ /dev/null
@@ -1,17 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPid")]
- internal static extern int GetPid();
- }
-
- internal static uint GetCurrentProcessId() => (uint)Sys.GetPid();
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetPwUid.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetPwUid.cs
deleted file mode 100644
index 28b2309d03e..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetPwUid.cs
+++ /dev/null
@@ -1,31 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- internal unsafe struct Passwd
- {
- internal const int InitialBufferSize = 256;
-
- internal byte* Name;
- internal byte* Password;
- internal uint UserId;
- internal uint GroupId;
- internal byte* UserInfo;
- internal byte* HomeDirectory;
- internal byte* Shell;
- }
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPwUidR", SetLastError = false)]
- internal static extern unsafe int GetPwUidR(uint uid, out Passwd pwd, byte* buf, int bufLen);
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPwNamR", SetLastError = false)]
- internal static extern unsafe int GetPwNamR(string name, out Passwd pwd, byte* buf, int bufLen);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetRandomBytes.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetRandomBytes.cs
deleted file mode 100644
index 858506935ae..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetRandomBytes.cs
+++ /dev/null
@@ -1,21 +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 System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal unsafe partial class Sys
- {
- [DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetNonCryptographicallySecureRandomBytes")]
- internal static extern unsafe void GetNonCryptographicallySecureRandomBytes(byte* buffer, int length);
- }
-
- internal static unsafe void GetRandomBytes(byte* buffer, int length)
- {
- Sys.GetNonCryptographicallySecureRandomBytes(buffer, length);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetSystemTimeAsTicks.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetSystemTimeAsTicks.cs
deleted file mode 100644
index f02ecac13b9..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetSystemTimeAsTicks.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal unsafe partial class Sys
- {
- [DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetSystemTimeAsTicks")]
- internal static extern long GetSystemTimeAsTicks();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetTimestamp.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetTimestamp.cs
deleted file mode 100644
index 53acdbc3cc3..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetTimestamp.cs
+++ /dev/null
@@ -1,18 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTimestampResolution", ExactSpelling = true)]
- internal static extern ulong GetTimestampResolution();
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTimestamp", ExactSpelling = true)]
- [SuppressGCTransition]
- internal static extern ulong GetTimestamp();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetUnixName.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetUnixName.cs
deleted file mode 100644
index fb925b9dca9..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetUnixName.cs
+++ /dev/null
@@ -1,21 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUnixName")]
- private static extern IntPtr GetUnixNamePrivate();
-
- internal static string GetUnixName()
- {
- IntPtr ptr = GetUnixNamePrivate();
- return Marshal.PtrToStringAnsi(ptr)!;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetUnixRelease.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetUnixRelease.cs
deleted file mode 100644
index 5e41ae98046..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.GetUnixRelease.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUnixRelease", CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern string GetUnixRelease();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.LSeek.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.LSeek.cs
deleted file mode 100644
index 7f8df7c6bf9..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.LSeek.cs
+++ /dev/null
@@ -1,22 +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 System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- internal enum SeekWhence
- {
- SEEK_SET = 0,
- SEEK_CUR = 1,
- SEEK_END = 2
- }
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LSeek", SetLastError = true)]
- internal static extern long LSeek(SafeFileHandle fd, long offset, SeekWhence whence);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.LockFileRegion.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.LockFileRegion.cs
deleted file mode 100644
index 1deb9a43132..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.LockFileRegion.cs
+++ /dev/null
@@ -1,21 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- internal enum LockType : short
- {
- F_WRLCK = 1, // exclusive or write lock
- F_UNLCK = 2 // unlock
- }
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LockFileRegion", SetLastError=true)]
- internal static extern int LockFileRegion(SafeHandle fd, long offset, long length, LockType lockType);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MksTemps.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MksTemps.cs
deleted file mode 100644
index 14c2d989130..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MksTemps.cs
+++ /dev/null
@@ -1,17 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MksTemps", SetLastError = true)]
- internal static extern IntPtr MksTemps(
- byte[] template,
- int suffixlen);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MountPoints.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MountPoints.cs
deleted file mode 100644
index 134dcb92037..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.MountPoints.cs
+++ /dev/null
@@ -1,40 +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 System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private unsafe delegate void MountPointFound(byte* name);
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetAllMountPoints", SetLastError = true)]
- private static extern int GetAllMountPoints(MountPointFound mpf);
-
- internal static string[] GetAllMountPoints()
- {
- int count = 0;
- var found = new string[4];
-
- unsafe
- {
- int result = GetAllMountPoints((byte* name) =>
- {
- if (count == found.Length)
- {
- Array.Resize(ref found, count * 2);
- }
- found[count++] = Marshal.PtrToStringAnsi((IntPtr)name)!;
- });
- }
-
- Array.Resize(ref found, count);
- return found;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Open.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Open.cs
deleted file mode 100644
index a9a994c78c0..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Open.cs
+++ /dev/null
@@ -1,15 +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 System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Open", SetLastError = true)]
- internal static extern SafeFileHandle Open(string filename, OpenFlags flags, int mode);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.OpenFlags.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.OpenFlags.cs
deleted file mode 100644
index f9e54c3cbcf..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.OpenFlags.cs
+++ /dev/null
@@ -1,27 +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 System;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [Flags]
- internal enum OpenFlags
- {
- // Access modes (mutually exclusive)
- O_RDONLY = 0x0000,
- O_WRONLY = 0x0001,
- O_RDWR = 0x0002,
-
- // Flags (combinable)
- O_CLOEXEC = 0x0010,
- O_CREAT = 0x0020,
- O_EXCL = 0x0040,
- O_TRUNC = 0x0080,
- O_SYNC = 0x0100,
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.PathConf.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.PathConf.cs
deleted file mode 100644
index 7213cb02640..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.PathConf.cs
+++ /dev/null
@@ -1,28 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- internal enum PathConfName : int
- {
- PC_LINK_MAX = 1,
- PC_MAX_CANON = 2,
- PC_MAX_INPUT = 3,
- PC_NAME_MAX = 4,
- PC_PATH_MAX = 5,
- PC_PIPE_BUF = 6,
- PC_CHOWN_RESTRICTED = 7,
- PC_NO_TRUNC = 8,
- PC_VDISABLE = 9,
- }
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PathConf", SetLastError = true)]
- private static extern int PathConf(string path, PathConfName name);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Permissions.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Permissions.cs
deleted file mode 100644
index f1d13787d25..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Permissions.cs
+++ /dev/null
@@ -1,32 +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 System;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [Flags]
- internal enum Permissions
- {
- Mask = S_IRWXU | S_IRWXG | S_IRWXO,
-
- S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR,
- S_IRUSR = 0x100,
- S_IWUSR = 0x80,
- S_IXUSR = 0x40,
-
- S_IRWXG = S_IRGRP | S_IWGRP | S_IXGRP,
- S_IRGRP = 0x20,
- S_IWGRP = 0x10,
- S_IXGRP = 0x8,
-
- S_IRWXO = S_IROTH | S_IWOTH | S_IXOTH,
- S_IROTH = 0x4,
- S_IWOTH = 0x2,
- S_IXOTH = 0x1,
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.PosixFAdvise.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.PosixFAdvise.cs
deleted file mode 100644
index ad8b73aed21..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.PosixFAdvise.cs
+++ /dev/null
@@ -1,36 +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 System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- internal enum FileAdvice : int
- {
- POSIX_FADV_NORMAL = 0, /* no special advice, the default value */
- POSIX_FADV_RANDOM = 1, /* random I/O access */
- POSIX_FADV_SEQUENTIAL = 2, /* sequential I/O access */
- POSIX_FADV_WILLNEED = 3, /* will need specified pages */
- POSIX_FADV_DONTNEED = 4, /* don't need the specified pages */
- POSIX_FADV_NOREUSE = 5, /* data will only be accessed once */
- }
-
- /// <summary>
- /// Notifies the OS kernel that the specified file will be accessed in a particular way soon; this allows the kernel to
- /// potentially optimize the access pattern of the file.
- /// </summary>
- /// <param name="fd">The file descriptor of the file</param>
- /// <param name="offset">The start of the region to advise about</param>
- /// <param name="length">The number of bytes of the region (until the end of the file if 0)</param>
- /// <param name="advice">The type of advice to give the kernel about the specified region</param>
- /// <returns>
- /// Returns 0 on success; otherwise, the error code is returned
- /// </returns>
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PosixFAdvise", SetLastError = false /* this is explicitly called out in the man page */)]
- internal static extern int PosixFAdvise(SafeFileHandle fd, long offset, long length, FileAdvice advice);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Read.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Read.cs
deleted file mode 100644
index 233feabdbb6..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Read.cs
+++ /dev/null
@@ -1,25 +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 System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- /// <summary>
- /// Reads a number of bytes from an open file descriptor into a specified buffer.
- /// </summary>
- /// <param name="fd">The open file descriptor to try to read from</param>
- /// <param name="buffer">The buffer to read info into</param>
- /// <param name="count">The size of the buffer</param>
- /// <returns>
- /// Returns the number of bytes read on success; otherwise, -1 is returned
- /// Note - on fail. the position of the stream may change depending on the platform; consult man 2 read for more info
- /// </returns>
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Read", SetLastError = true)]
- internal static extern unsafe int Read(SafeHandle fd, byte* buffer, int count);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ReadDir.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ReadDir.cs
deleted file mode 100644
index cacb3664db0..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ReadDir.cs
+++ /dev/null
@@ -1,69 +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 System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Text;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- 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
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal unsafe struct DirectoryEntry
- {
- internal byte* Name;
- internal int NameLength;
- internal NodeType InodeType;
- internal const int NameBufferSize = 256; // sizeof(dirent->d_name) == NAME_MAX + 1
-
- internal ReadOnlySpan<char> GetName(Span<char> buffer)
- {
- // -1 for null terminator (buffer will not include one),
- // and -1 because GetMaxCharCount pessimistically assumes the buffer may start with a partial surrogate
- Debug.Assert(buffer.Length >= Encoding.UTF8.GetMaxCharCount(NameBufferSize - 1 - 1));
-
- 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).IndexOf<byte>(0))
- : new ReadOnlySpan<byte>(Name, NameLength);
-
- Debug.Assert(nameBytes.Length > 0, "we shouldn't have gotten a garbage value from the OS");
-
- 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 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)]
- 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);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ReadLink.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ReadLink.cs
deleted file mode 100644
index b945bc982c5..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.ReadLink.cs
+++ /dev/null
@@ -1,64 +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.
-
-#nullable enable
-using System.Runtime.InteropServices;
-using System.Buffers;
-using System.Text;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- /// <summary>
- /// Takes a path to a symbolic link and attempts to place the link target path into the buffer. If the buffer is too
- /// small, the path will be truncated. No matter what, the buffer will not be null terminated.
- /// </summary>
- /// <param name="path">The path to the symlink</param>
- /// <param name="buffer">The buffer to hold the output path</param>
- /// <param name="bufferSize">The size of the buffer</param>
- /// <returns>
- /// Returns the number of bytes placed into the buffer on success; bufferSize if the buffer is too small; and -1 on error.
- /// </returns>
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadLink", SetLastError = true)]
- private static extern unsafe int ReadLink(string path, byte[] buffer, int bufferSize);
-
- /// <summary>
- /// Takes a path to a symbolic link and returns the link target path.
- /// </summary>
- /// <param name="path">The path to the symlink</param>
- /// <returns>
- /// Returns the link to the target path on success; and null otherwise.
- /// </returns>
- public static string? ReadLink(string path)
- {
- int bufferSize = 256;
- while (true)
- {
- byte[] buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
- try
- {
- int resultLength = Interop.Sys.ReadLink(path, buffer, buffer.Length);
- if (resultLength < 0)
- {
- // error
- return null;
- }
- else if (resultLength < buffer.Length)
- {
- // success
- return Encoding.UTF8.GetString(buffer, 0, resultLength);
- }
- }
- finally
- {
- ArrayPool<byte>.Shared.Return(buffer);
- }
-
- // buffer was too small, loop around again and try with a larger buffer.
- bufferSize *= 2;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Stat.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Stat.cs
deleted file mode 100644
index d06fbda7185..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Stat.cs
+++ /dev/null
@@ -1,66 +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 System;
-using System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- // Even though csc will by default use a sequential layout, a CS0649 warning as error
- // is produced for un-assigned fields when no StructLayout is specified.
- //
- // Explicitly saying Sequential disables that warning/error for consumers which only
- // use Stat in debug builds.
- [StructLayout(LayoutKind.Sequential)]
- internal struct FileStatus
- {
- internal FileStatusFlags Flags;
- internal int Mode;
- internal uint Uid;
- internal uint Gid;
- internal long Size;
- internal long ATime;
- internal long ATimeNsec;
- internal long MTime;
- internal long MTimeNsec;
- internal long CTime;
- internal long CTimeNsec;
- internal long BirthTime;
- internal long BirthTimeNsec;
- internal long Dev;
- internal long Ino;
- internal uint UserFlags;
- }
-
- internal static class FileTypes
- {
- internal const int S_IFMT = 0xF000;
- internal const int S_IFIFO = 0x1000;
- internal const int S_IFCHR = 0x2000;
- internal const int S_IFDIR = 0x4000;
- internal const int S_IFREG = 0x8000;
- internal const int S_IFLNK = 0xA000;
- internal const int S_IFSOCK = 0xC000;
- }
-
- [Flags]
- internal enum FileStatusFlags
- {
- None = 0,
- HasBirthTime = 1,
- }
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FStat", SetLastError = true)]
- internal static extern int FStat(SafeFileHandle fd, out FileStatus output);
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Stat", SetLastError = true)]
- internal static extern int Stat(string path, out FileStatus output);
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LStat", SetLastError = true)]
- internal static extern int LStat(string path, out FileStatus output);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.SysConf.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.SysConf.cs
deleted file mode 100644
index be0c0dee7bb..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.SysConf.cs
+++ /dev/null
@@ -1,20 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- internal enum SysConfName
- {
- _SC_CLK_TCK = 1,
- _SC_PAGESIZE = 2
- }
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SysConf", SetLastError = true)]
- internal static extern long SysConf(SysConfName name);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.SysLog.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.SysLog.cs
deleted file mode 100644
index 2edde6fbc11..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.SysLog.cs
+++ /dev/null
@@ -1,58 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- internal enum SysLogPriority : int
- {
- // Priorities
- LOG_EMERG = 0, /* system is unusable */
- LOG_ALERT = 1, /* action must be taken immediately */
- LOG_CRIT = 2, /* critical conditions */
- LOG_ERR = 3, /* error conditions */
- LOG_WARNING = 4, /* warning conditions */
- LOG_NOTICE = 5, /* normal but significant condition */
- LOG_INFO = 6, /* informational */
- LOG_DEBUG = 7, /* debug-level messages */
- // Facilities
- LOG_KERN = (0<<3), /* kernel messages */
- LOG_USER = (1<<3), /* random user-level messages */
- LOG_MAIL = (2<<3), /* mail system */
- LOG_DAEMON = (3<<3), /* system daemons */
- LOG_AUTH = (4<<3), /* authorization messages */
- LOG_SYSLOG = (5<<3), /* messages generated internally by syslogd */
- LOG_LPR = (6<<3), /* line printer subsystem */
- LOG_NEWS = (7<<3), /* network news subsystem */
- LOG_UUCP = (8<<3), /* UUCP subsystem */
- LOG_CRON = (9<<3), /* clock daemon */
- LOG_AUTHPRIV = (10<<3), /* authorization messages (private) */
- LOG_FTP = (11<<3), /* ftp daemon */
- // Between FTP and Local is reserved for system use
- LOG_LOCAL0 = (16<<3), /* reserved for local use */
- LOG_LOCAL1 = (17<<3), /* reserved for local use */
- LOG_LOCAL2 = (18<<3), /* reserved for local use */
- LOG_LOCAL3 = (19<<3), /* reserved for local use */
- LOG_LOCAL4 = (20<<3), /* reserved for local use */
- LOG_LOCAL5 = (21<<3), /* reserved for local use */
- LOG_LOCAL6 = (22<<3), /* reserved for local use */
- LOG_LOCAL7 = (23<<3), /* reserved for local use */
- }
-
- /// <summary>
- /// Write a message to the system logger, which in turn writes the message to the system console, log files, etc.
- /// See man 3 syslog for more info
- /// </summary>
- /// <param name="priority">
- /// The OR of a priority and facility in the SysLogPriority enum to declare the priority and facility of the log entry
- /// </param>
- /// <param name="message">The message to put in the log entry</param>
- /// <param name="arg1">Like printf, the argument is passed to the variadic part of the C++ function to wildcards in the message</param>
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SysLog")]
- internal static extern void SysLog(SysLogPriority priority, string message, string arg1);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Unlink.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Unlink.cs
deleted file mode 100644
index 829210fa7e0..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Unlink.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Unlink", SetLastError = true)]
- internal static extern int Unlink(string pathname);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Write.cs b/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Write.cs
deleted file mode 100644
index fb06d463beb..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Write.cs
+++ /dev/null
@@ -1,27 +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 System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-internal static partial class Interop
-{
- internal static partial class Sys
- {
- /// <summary>
- /// Writes the specified buffer to the provided open file descriptor
- /// </summary>
- /// <param name="fd">The file descriptor to try and write to</param>
- /// <param name="buffer">The data to attempt to write</param>
- /// <param name="bufferSize">The amount of data to write, in bytes</param>
- /// <returns>
- /// Returns the number of bytes written on success; otherwise, returns -1 and sets errno
- /// </returns>
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Write", SetLastError = true)]
- internal static extern unsafe int Write(SafeHandle fd, byte* buffer, int bufferSize);
-
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Write", SetLastError = true)]
- internal static extern unsafe int Write(int fd, byte* buffer, int bufferSize);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.ActivityControl.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.ActivityControl.cs
deleted file mode 100644
index 093755659de..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.ActivityControl.cs
+++ /dev/null
@@ -1,18 +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.
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- internal enum ActivityControl : uint
- {
- EVENT_ACTIVITY_CTRL_GET_ID = 1,
- EVENT_ACTIVITY_CTRL_SET_ID = 2,
- EVENT_ACTIVITY_CTRL_CREATE_ID = 3,
- EVENT_ACTIVITY_CTRL_GET_SET_ID = 4,
- EVENT_ACTIVITY_CTRL_CREATE_SET_ID = 5
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EVENT_INFO_CLASS.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EVENT_INFO_CLASS.cs
deleted file mode 100644
index fae4d2e5c30..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EVENT_INFO_CLASS.cs
+++ /dev/null
@@ -1,16 +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.
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- internal enum EVENT_INFO_CLASS
- {
- BinaryTrackInfo,
- SetEnableAllKeywords,
- SetTraits,
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EtwEnableCallback.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EtwEnableCallback.cs
deleted file mode 100644
index 33f6ae631d9..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EtwEnableCallback.cs
+++ /dev/null
@@ -1,33 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- internal const int EVENT_CONTROL_CODE_DISABLE_PROVIDER = 0;
- internal const int EVENT_CONTROL_CODE_ENABLE_PROVIDER = 1;
- internal const int EVENT_CONTROL_CODE_CAPTURE_STATE = 2;
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct EVENT_FILTER_DESCRIPTOR
- {
- public long Ptr;
- public int Size;
- public int Type;
- }
-
- internal unsafe delegate void EtwEnableCallback(
- in Guid sourceId,
- int isEnabled,
- byte level,
- long matchAnyKeywords,
- long matchAllKeywords,
- EVENT_FILTER_DESCRIPTOR* filterData,
- void* callbackContext);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventActivityIdControl.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventActivityIdControl.cs
deleted file mode 100644
index 2d73e3e50a7..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventActivityIdControl.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, ExactSpelling = true)]
- internal static extern int EventActivityIdControl(ActivityControl ControlCode, ref Guid ActivityId);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventRegister.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventRegister.cs
deleted file mode 100644
index 1c1af36bfc0..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventRegister.cs
+++ /dev/null
@@ -1,19 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, ExactSpelling = true)]
- internal static extern unsafe uint EventRegister(
- in Guid providerId,
- EtwEnableCallback enableCallback,
- void* callbackContext,
- ref long registrationHandle);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventSetInformation.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventSetInformation.cs
deleted file mode 100644
index b3a8851428c..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventSetInformation.cs
+++ /dev/null
@@ -1,18 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, ExactSpelling = true)]
- internal static extern unsafe int EventSetInformation(
- long registrationHandle,
- EVENT_INFO_CLASS informationClass,
- void* eventInformation,
- int informationLength);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventTraceGuidsEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventTraceGuidsEx.cs
deleted file mode 100644
index d85b2e5ba5f..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventTraceGuidsEx.cs
+++ /dev/null
@@ -1,58 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- internal enum TRACE_QUERY_INFO_CLASS
- {
- TraceGuidQueryList,
- TraceGuidQueryInfo,
- TraceGuidQueryProcess,
- TraceStackTracingInfo,
- MaxTraceSetInfoClass
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct TRACE_GUID_INFO
- {
- public int InstanceCount;
- public int Reserved;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct TRACE_PROVIDER_INSTANCE_INFO
- {
- public int NextOffset;
- public int EnableCount;
- public int Pid;
- public int Flags;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct TRACE_ENABLE_INFO
- {
- public int IsEnabled;
- public byte Level;
- public byte Reserved1;
- public ushort LoggerId;
- public int EnableProperty;
- public int Reserved2;
- public long MatchAnyKeyword;
- public long MatchAllKeyword;
- }
-
- [DllImport(Interop.Libraries.Advapi32, ExactSpelling = true)]
- internal static extern unsafe int EnumerateTraceGuidsEx(
- TRACE_QUERY_INFO_CLASS TraceQueryInfoClass,
- void* InBuffer,
- int InBufferSize,
- void* OutBuffer,
- int OutBufferSize,
- out int ReturnLength);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventUnregister.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventUnregister.cs
deleted file mode 100644
index 1943cb314e4..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventUnregister.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, ExactSpelling = true)]
- internal static extern uint EventUnregister(long registrationHandle);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventWriteString.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventWriteString.cs
deleted file mode 100644
index 9c60558e129..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventWriteString.cs
+++ /dev/null
@@ -1,18 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, ExactSpelling = true)]
- internal static extern int EventWriteString(
- long registrationHandle,
- byte level,
- long keyword,
- string msg);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventWriteTransfer.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventWriteTransfer.cs
deleted file mode 100644
index 1bc116fdd66..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.EventWriteTransfer.cs
+++ /dev/null
@@ -1,49 +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 System;
-using System.Runtime.InteropServices;
-#if ES_BUILD_STANDALONE
-using Microsoft.Diagnostics.Tracing;
-#else
-using System.Diagnostics.Tracing;
-#endif
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- /// <summary>
- /// Call the ETW native API EventWriteTransfer and checks for invalid argument error.
- /// The implementation of EventWriteTransfer on some older OSes (Windows 2008) does not accept null relatedActivityId.
- /// So, for these cases we will retry the call with an empty Guid.
- /// </summary>
- internal static unsafe int EventWriteTransfer(
- long registrationHandle,
- in EventDescriptor eventDescriptor,
- Guid* activityId,
- Guid* relatedActivityId,
- int userDataCount,
- EventProvider.EventData* userData)
- {
- int HResult = EventWriteTransfer_PInvoke(registrationHandle, in eventDescriptor, activityId, relatedActivityId, userDataCount, userData);
- if (HResult == Errors.ERROR_INVALID_PARAMETER && relatedActivityId == null)
- {
- Guid emptyGuid = Guid.Empty;
- HResult = EventWriteTransfer_PInvoke(registrationHandle, in eventDescriptor, activityId, &emptyGuid, userDataCount, userData);
- }
-
- return HResult;
- }
-
- [DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, EntryPoint = "EventWriteTransfer")]
- private static extern unsafe int EventWriteTransfer_PInvoke(
- long registrationHandle,
- in EventDescriptor eventDescriptor,
- Guid* activityId,
- Guid* relatedActivityId,
- int userDataCount,
- EventProvider.EventData* userData);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.LookupAccountNameW.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.LookupAccountNameW.cs
deleted file mode 100644
index a254e694af5..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.LookupAccountNameW.cs
+++ /dev/null
@@ -1,21 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
- internal static extern bool LookupAccountNameW(
- string? lpSystemName,
- ref char lpAccountName,
- ref byte Sid,
- ref uint cbSid,
- ref char ReferencedDomainName,
- ref uint cchReferencedDomainName,
- out uint peUse);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCloseKey.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCloseKey.cs
deleted file mode 100644
index c4a69448e03..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCloseKey.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32)]
- internal static extern int RegCloseKey(IntPtr hKey);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCreateKeyEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCreateKeyEx.cs
deleted file mode 100644
index bb9da06c11d..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCreateKeyEx.cs
+++ /dev/null
@@ -1,31 +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.
-
-#nullable enable
-#if REGISTRY_ASSEMBLY
-using Microsoft.Win32.SafeHandles;
-#else
-using Internal.Win32.SafeHandles;
-#endif
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- // Note: RegCreateKeyEx won't set the last error on failure - it returns
- // an error code if it fails.
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegCreateKeyExW")]
- internal static extern int RegCreateKeyEx(
- SafeRegistryHandle hKey,
- string lpSubKey,
- int Reserved,
- string? lpClass,
- int dwOptions,
- int samDesired,
- ref Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs,
- out SafeRegistryHandle hkResult,
- out int lpdwDisposition);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteKeyEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteKeyEx.cs
deleted file mode 100644
index 487caf8b6d7..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteKeyEx.cs
+++ /dev/null
@@ -1,19 +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.
-
-#if REGISTRY_ASSEMBLY
-using Microsoft.Win32.SafeHandles;
-#else
-using Internal.Win32.SafeHandles;
-#endif
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegDeleteKeyExW")]
- internal static extern int RegDeleteKeyEx(SafeRegistryHandle hKey, string lpSubKey, int samDesired, int Reserved);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteValue.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteValue.cs
deleted file mode 100644
index 43cf683c2bd..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteValue.cs
+++ /dev/null
@@ -1,20 +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.
-
-#nullable enable
-#if REGISTRY_ASSEMBLY
-using Microsoft.Win32.SafeHandles;
-#else
-using Internal.Win32.SafeHandles;
-#endif
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegDeleteValueW")]
- internal static extern int RegDeleteValue(SafeRegistryHandle hKey, string? lpValueName);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumKeyEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumKeyEx.cs
deleted file mode 100644
index 11165cc91a9..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumKeyEx.cs
+++ /dev/null
@@ -1,28 +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.
-
-#nullable enable
-#if REGISTRY_ASSEMBLY
-using Microsoft.Win32.SafeHandles;
-#else
-using Internal.Win32.SafeHandles;
-#endif
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegEnumKeyExW")]
- internal static extern unsafe int RegEnumKeyEx(
- SafeRegistryHandle hKey,
- int dwIndex,
- char[] lpName,
- ref int lpcbName,
- int[]? lpReserved,
- [Out] char[]? lpClass,
- int[]? lpcbClass,
- long[]? lpftLastWriteTime);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumValue.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumValue.cs
deleted file mode 100644
index e2ab45dea19..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumValue.cs
+++ /dev/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.
-
-#nullable enable
-#if REGISTRY_ASSEMBLY
-using Microsoft.Win32.SafeHandles;
-#else
-using Internal.Win32.SafeHandles;
-#endif
-using System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegEnumValueW")]
- internal static extern unsafe int RegEnumValue(
- SafeRegistryHandle hKey,
- int dwIndex,
- char[] lpValueName,
- ref int lpcbValueName,
- IntPtr lpReserved_MustBeZero,
- int[]? lpType,
- byte[]? lpData,
- int[]? lpcbData);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegFlushKey.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegFlushKey.cs
deleted file mode 100644
index ccbecb60897..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegFlushKey.cs
+++ /dev/null
@@ -1,19 +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.
-
-#if REGISTRY_ASSEMBLY
-using Microsoft.Win32.SafeHandles;
-#else
-using Internal.Win32.SafeHandles;
-#endif
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32)]
- internal static extern int RegFlushKey(SafeRegistryHandle hKey);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegOpenKeyEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegOpenKeyEx.cs
deleted file mode 100644
index 5f5b6b6e372..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegOpenKeyEx.cs
+++ /dev/null
@@ -1,35 +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.
-
-#nullable enable
-#if REGISTRY_ASSEMBLY
-using Microsoft.Win32.SafeHandles;
-#else
-using Internal.Win32.SafeHandles;
-#endif
-using System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegOpenKeyExW")]
- internal static extern int RegOpenKeyEx(
- SafeRegistryHandle hKey,
- string? lpSubKey,
- int ulOptions,
- int samDesired,
- out SafeRegistryHandle hkResult);
-
-
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegOpenKeyExW")]
- internal static extern int RegOpenKeyEx(
- IntPtr hKey,
- string? lpSubKey,
- int ulOptions,
- int samDesired,
- out SafeRegistryHandle hkResult);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryInfoKey.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryInfoKey.cs
deleted file mode 100644
index c2bb82fab56..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryInfoKey.cs
+++ /dev/null
@@ -1,34 +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.
-
-#nullable enable
-#if REGISTRY_ASSEMBLY
-using Microsoft.Win32.SafeHandles;
-#else
-using Internal.Win32.SafeHandles;
-#endif
-using System;
-using System.Runtime.InteropServices;
-using System.Text;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegQueryInfoKeyW")]
- internal static extern int RegQueryInfoKey(
- SafeRegistryHandle hKey,
- [Out] char[]? lpClass,
- int[]? lpcbClass,
- IntPtr lpReserved_MustBeZero,
- ref int lpcSubKeys,
- int[]? lpcbMaxSubKeyLen,
- int[]? lpcbMaxClassLen,
- ref int lpcValues,
- int[]? lpcbMaxValueNameLen,
- int[]? lpcbMaxValueLen,
- int[]? lpcbSecurityDescriptor,
- int[]? lpftLastWriteTime);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryValueEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryValueEx.cs
deleted file mode 100644
index 72b8aa8f7bc..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryValueEx.cs
+++ /dev/null
@@ -1,53 +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.
-
-#nullable enable
-#if REGISTRY_ASSEMBLY
-using Microsoft.Win32.SafeHandles;
-#else
-using Internal.Win32.SafeHandles;
-#endif
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegQueryValueExW")]
- internal static extern int RegQueryValueEx(
- SafeRegistryHandle hKey,
- string? lpValueName,
- int[]? lpReserved,
- ref int lpType,
- [Out] byte[]? lpData,
- ref int lpcbData);
-
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegQueryValueExW")]
- internal static extern int RegQueryValueEx(
- SafeRegistryHandle hKey,
- string? lpValueName,
- int[]? lpReserved,
- ref int lpType,
- ref int lpData,
- ref int lpcbData);
-
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegQueryValueExW")]
- internal static extern int RegQueryValueEx(
- SafeRegistryHandle hKey,
- string? lpValueName,
- int[]? lpReserved,
- ref int lpType,
- ref long lpData,
- ref int lpcbData);
-
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegQueryValueExW")]
- internal static extern int RegQueryValueEx(
- SafeRegistryHandle hKey,
- string? lpValueName,
- int[]? lpReserved,
- ref int lpType,
- [Out] char[]? lpData,
- ref int lpcbData);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegSetValueEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegSetValueEx.cs
deleted file mode 100644
index 847d28fa1c5..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegSetValueEx.cs
+++ /dev/null
@@ -1,62 +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.
-
-#nullable enable
-#if REGISTRY_ASSEMBLY
-using Microsoft.Win32.SafeHandles;
-#else
-using Internal.Win32.SafeHandles;
-#endif
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegSetValueExW")]
- internal static extern int RegSetValueEx(
- SafeRegistryHandle hKey,
- string? lpValueName,
- int Reserved,
- int dwType,
- byte[]? lpData,
- int cbData);
-
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegSetValueExW")]
- internal static extern int RegSetValueEx(
- SafeRegistryHandle hKey,
- string? lpValueName,
- int Reserved,
- int dwType,
- char[]? lpData,
- int cbData);
-
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegSetValueExW")]
- internal static extern int RegSetValueEx(
- SafeRegistryHandle hKey,
- string? lpValueName,
- int Reserved,
- int dwType,
- ref int lpData,
- int cbData);
-
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegSetValueExW")]
- internal static extern int RegSetValueEx(
- SafeRegistryHandle hKey,
- string? lpValueName,
- int Reserved,
- int dwType,
- ref long lpData,
- int cbData);
-
- [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegSetValueExW")]
- internal static extern int RegSetValueEx(
- SafeRegistryHandle hKey,
- string? lpValueName,
- int Reserved,
- int dwType,
- string? lpData,
- int cbData);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegistryConstants.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegistryConstants.cs
deleted file mode 100644
index 48ea1f27c52..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegistryConstants.cs
+++ /dev/null
@@ -1,65 +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.
-
-internal static partial class Interop
-{
- internal static partial class Advapi32
- {
- internal static class RegistryOptions
- {
- internal const int REG_OPTION_NON_VOLATILE = 0x0000; // (default) keys are persisted beyond reboot/unload
- internal const int REG_OPTION_VOLATILE = 0x0001; // All keys created by the function are volatile
- internal const int REG_OPTION_CREATE_LINK = 0x0002; // They key is a symbolic link
- internal const int REG_OPTION_BACKUP_RESTORE = 0x0004; // Use SE_BACKUP_NAME process special privileges
- }
-
- internal static class RegistryView
- {
- internal const int KEY_WOW64_64KEY = 0x0100;
- internal const int KEY_WOW64_32KEY = 0x0200;
- }
-
- internal static class RegistryOperations
- {
- internal const int KEY_QUERY_VALUE = 0x0001;
- internal const int KEY_SET_VALUE = 0x0002;
- internal const int KEY_CREATE_SUB_KEY = 0x0004;
- internal const int KEY_ENUMERATE_SUB_KEYS = 0x0008;
- internal const int KEY_NOTIFY = 0x0010;
- internal const int KEY_CREATE_LINK = 0x0020;
- internal const int KEY_READ = ((STANDARD_RIGHTS_READ |
- KEY_QUERY_VALUE |
- KEY_ENUMERATE_SUB_KEYS |
- KEY_NOTIFY)
- &
- (~SYNCHRONIZE));
-
- internal const int KEY_WRITE = ((STANDARD_RIGHTS_WRITE |
- KEY_SET_VALUE |
- KEY_CREATE_SUB_KEY)
- &
- (~SYNCHRONIZE));
-
- internal const int SYNCHRONIZE = 0x00100000;
- internal const int READ_CONTROL = 0x00020000;
- internal const int STANDARD_RIGHTS_READ = READ_CONTROL;
- internal const int STANDARD_RIGHTS_WRITE = READ_CONTROL;
- }
-
- internal static class RegistryValues
- {
- internal const int REG_NONE = 0; // No value type
- internal const int REG_SZ = 1; // Unicode nul terminated string
- internal const int REG_EXPAND_SZ = 2; // Unicode nul terminated string
- // (with environment variable references)
- internal const int REG_BINARY = 3; // Free form binary
- internal const int REG_DWORD = 4; // 32-bit number
- internal const int REG_DWORD_LITTLE_ENDIAN = 4; // 32-bit number (same as REG_DWORD)
- internal const int REG_DWORD_BIG_ENDIAN = 5; // 32-bit number
- internal const int REG_LINK = 6; // Symbolic Link (Unicode)
- internal const int REG_MULTI_SZ = 7; // Multiple Unicode strings
- internal const int REG_QWORD = 11; // 64-bit number
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.BCryptGenRandom.GetRandomBytes.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.BCryptGenRandom.GetRandomBytes.cs
deleted file mode 100644
index 42824c7eb73..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.BCryptGenRandom.GetRandomBytes.cs
+++ /dev/null
@@ -1,28 +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 System;
-using System.Diagnostics;
-
-internal static partial class Interop
-{
- internal static unsafe void GetRandomBytes(byte* buffer, int length)
- {
- Debug.Assert(buffer != null);
- Debug.Assert(length >= 0);
-
- BCrypt.NTSTATUS status = BCrypt.BCryptGenRandom(IntPtr.Zero, buffer, length, BCrypt.BCRYPT_USE_SYSTEM_PREFERRED_RNG);
- if (status != BCrypt.NTSTATUS.STATUS_SUCCESS)
- {
- if (status == BCrypt.NTSTATUS.STATUS_NO_MEMORY)
- {
- throw new OutOfMemoryException();
- }
- else
- {
- throw new InvalidOperationException();
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.BCryptGenRandom.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.BCryptGenRandom.cs
deleted file mode 100644
index 1e6452f8fa9..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.BCryptGenRandom.cs
+++ /dev/null
@@ -1,17 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class BCrypt
- {
- internal const int BCRYPT_USE_SYSTEM_PREFERRED_RNG = 0x00000002;
-
- [DllImport(Libraries.BCrypt, CharSet = CharSet.Unicode)]
- internal static extern unsafe NTSTATUS BCryptGenRandom(IntPtr hAlgorithm, byte* pbBuffer, int cbBuffer, int dwFlags);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.NTSTATUS.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.NTSTATUS.cs
deleted file mode 100644
index af646aea985..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/BCrypt/Interop.NTSTATUS.cs
+++ /dev/null
@@ -1,18 +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.
-
-internal static partial class Interop
-{
- internal static partial class BCrypt
- {
- internal enum NTSTATUS : uint
- {
- STATUS_SUCCESS = 0x0,
- STATUS_NOT_FOUND = 0xc0000225,
- STATUS_INVALID_PARAMETER = 0xc000000d,
- STATUS_NO_MEMORY = 0xc0000017,
- STATUS_AUTH_TAG_MISMATCH = 0xc000a002,
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs
deleted file mode 100644
index cce01906ff6..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs
+++ /dev/null
@@ -1,21 +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 System.Runtime.InteropServices;
-using System.Security;
-
-internal static partial class Interop
-{
- internal static partial class Crypt32
- {
- internal const uint CRYPTPROTECTMEMORY_BLOCK_SIZE = 16;
- internal const uint CRYPTPROTECTMEMORY_SAME_PROCESS = 0;
-
- [DllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern bool CryptProtectMemory(SafeBuffer pData, uint cbData, uint dwFlags);
-
- [DllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern bool CryptUnprotectMemory(SafeBuffer pData, uint cbData, uint dwFlags);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.BOOL.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.BOOL.cs
deleted file mode 100644
index b79d90fbe9f..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.BOOL.cs
+++ /dev/null
@@ -1,21 +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.
-
-internal static partial class Interop
-{
- /// <summary>
- /// Blittable version of Windows BOOL type. It is convenient in situations where
- /// manual marshalling is required, or to avoid overhead of regular bool marshalling.
- /// </summary>
- /// <remarks>
- /// Some Windows APIs return arbitrary integer values although the return type is defined
- /// as BOOL. It is best to never compare BOOL to TRUE. Always use bResult != BOOL.FALSE
- /// or bResult == BOOL.FALSE .
- /// </remarks>
- internal enum BOOL : int
- {
- FALSE = 0,
- TRUE = 1,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.BOOLEAN.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.BOOLEAN.cs
deleted file mode 100644
index 8158ffabde5..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.BOOLEAN.cs
+++ /dev/null
@@ -1,21 +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.
-
-internal static partial class Interop
-{
- /// <summary>
- /// Blittable version of Windows BOOLEAN type. It is convenient in situations where
- /// manual marshalling is required, or to avoid overhead of regular bool marshalling.
- /// </summary>
- /// <remarks>
- /// Some Windows APIs return arbitrary integer values although the return type is defined
- /// as BOOLEAN. It is best to never compare BOOLEAN to TRUE. Always use bResult != BOOLEAN.FALSE
- /// or bResult == BOOLEAN.FALSE .
- /// </remarks>
- internal enum BOOLEAN : byte
- {
- FALSE = 0,
- TRUE = 1,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.Errors.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.Errors.cs
deleted file mode 100644
index cb6125de765..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.Errors.cs
+++ /dev/null
@@ -1,46 +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.
-
-internal static partial class Interop
-{
- // As defined in winerror.h and https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382.aspx
- internal static partial class Errors
- {
- internal const int ERROR_SUCCESS = 0x0;
- internal const int ERROR_FILE_NOT_FOUND = 0x2;
- internal const int ERROR_PATH_NOT_FOUND = 0x3;
- internal const int ERROR_ACCESS_DENIED = 0x5;
- internal const int ERROR_INVALID_HANDLE = 0x6;
- internal const int ERROR_NOT_ENOUGH_MEMORY = 0x8;
- internal const int ERROR_INVALID_DRIVE = 0xF;
- internal const int ERROR_NO_MORE_FILES = 0x12;
- internal const int ERROR_NOT_READY = 0x15;
- internal const int ERROR_SHARING_VIOLATION = 0x20;
- internal const int ERROR_HANDLE_EOF = 0x26;
- internal const int ERROR_NOT_SUPPORTED = 0x32;
- internal const int ERROR_FILE_EXISTS = 0x50;
- internal const int ERROR_INVALID_PARAMETER = 0x57;
- internal const int ERROR_BROKEN_PIPE = 0x6D;
- internal const int ERROR_INSUFFICIENT_BUFFER = 0x7A;
- internal const int ERROR_INVALID_NAME = 0x7B;
- internal const int ERROR_BAD_PATHNAME = 0xA1;
- internal const int ERROR_ALREADY_EXISTS = 0xB7;
- internal const int ERROR_ENVVAR_NOT_FOUND = 0xCB;
- internal const int ERROR_FILENAME_EXCED_RANGE = 0xCE;
- internal const int ERROR_NO_DATA = 0xE8;
- internal const int ERROR_MORE_DATA = 0xEA;
- internal const int ERROR_NO_MORE_ITEMS = 0x103;
- internal const int ERROR_NOT_OWNER = 0x120;
- internal const int ERROR_TOO_MANY_POSTS = 0x12A;
- internal const int ERROR_ARITHMETIC_OVERFLOW = 0x216;
- internal const int ERROR_MUTANT_LIMIT_EXCEEDED = 0x24B;
- internal const int ERROR_OPERATION_ABORTED = 0x3E3;
- internal const int ERROR_IO_PENDING = 0x3E5;
- internal const int ERROR_NO_UNICODE_TRANSLATION = 0x459;
- internal const int ERROR_NOT_FOUND = 0x490;
- internal const int ERROR_BAD_IMPERSONATION_LEVEL = 0x542;
- internal const int ERROR_NO_SYSTEM_RESOURCES = 0x5AA;
- internal const int ERROR_TIMEOUT = 0x000005B4;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.Libraries.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.Libraries.cs
deleted file mode 100644
index 8cbc8bfb266..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Interop.Libraries.cs
+++ /dev/null
@@ -1,20 +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.
-
-internal static partial class Interop
-{
- internal static partial class Libraries
- {
- internal const string Advapi32 = "advapi32.dll";
- internal const string BCrypt = "BCrypt.dll";
- internal const string Crypt32 = "crypt32.dll";
- internal const string Kernel32 = "kernel32.dll";
- internal const string Ole32 = "ole32.dll";
- internal const string OleAut32 = "oleaut32.dll";
- internal const string User32 = "user32.dll";
- internal const string NtDll = "ntdll.dll";
- internal const string Secur32 = "secur32.dll";
- internal const string Shell32 = "shell32.dll";
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CancelIoEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CancelIoEx.cs
deleted file mode 100644
index 057ebb924f4..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CancelIoEx.cs
+++ /dev/null
@@ -1,19 +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 System;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern unsafe bool CancelIoEx(SafeHandle handle, NativeOverlapped* lpOverlapped);
-
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern unsafe bool CancelIoEx(IntPtr handle, NativeOverlapped* lpOverlapped);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CloseHandle.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CloseHandle.cs
deleted file mode 100644
index c4385997185..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CloseHandle.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool CloseHandle(IntPtr handle);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CompletionPort.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CompletionPort.cs
deleted file mode 100644
index 326f0e9df00..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CompletionPort.cs
+++ /dev/null
@@ -1,23 +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 System;
-using System.Runtime.InteropServices;
-
-internal partial class Interop
-{
- internal partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern IntPtr CreateIoCompletionPort(IntPtr FileHandle, IntPtr ExistingCompletionPort, UIntPtr CompletionKey, int NumberOfConcurrentThreads);
-
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool PostQueuedCompletionStatus(IntPtr CompletionPort, int dwNumberOfBytesTransferred, UIntPtr CompletionKey, IntPtr lpOverlapped);
-
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetQueuedCompletionStatus(IntPtr CompletionPort, out int lpNumberOfBytes, out UIntPtr CompletionKey, out IntPtr lpOverlapped, int dwMilliseconds);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Constants.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Constants.cs
deleted file mode 100644
index b13cdfd03fe..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Constants.cs
+++ /dev/null
@@ -1,15 +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.
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal const int MAXIMUM_ALLOWED = 0x02000000;
- internal const int SYNCHRONIZE = 0x00100000;
- internal const int MUTEX_MODIFY_STATE = 0x00000001;
- internal const int SEMAPHORE_MODIFY_STATE = 0x00000002;
- internal const int EVENT_MODIFY_STATE = 0x00000002;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs
deleted file mode 100644
index 9ebac4f6640..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs
+++ /dev/null
@@ -1,40 +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.IO;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- /// <summary>
- /// WARNING: This method does not implicitly handle long paths. Use CreateFile.
- /// </summary>
- [DllImport(Libraries.Kernel32, EntryPoint = "CreateFileW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
- private static extern SafeFileHandle CreateFilePrivate(
- string lpFileName,
- int dwDesiredAccess,
- System.IO.FileShare dwShareMode,
- ref SECURITY_ATTRIBUTES securityAttrs,
- System.IO.FileMode dwCreationDisposition,
- int dwFlagsAndAttributes,
- IntPtr hTemplateFile);
-
- internal static SafeFileHandle CreateFile(
- string lpFileName,
- int dwDesiredAccess,
- System.IO.FileShare dwShareMode,
- ref SECURITY_ATTRIBUTES securityAttrs,
- System.IO.FileMode dwCreationDisposition,
- int dwFlagsAndAttributes,
- IntPtr hTemplateFile)
- {
- lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName);
- return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.EventWaitHandle.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.EventWaitHandle.cs
deleted file mode 100644
index c3adfadb53d..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.EventWaitHandle.cs
+++ /dev/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.
-
-#nullable enable
-using Microsoft.Win32.SafeHandles;
-using System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal const uint CREATE_EVENT_INITIAL_SET = 0x2;
- internal const uint CREATE_EVENT_MANUAL_RESET = 0x1;
-
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool SetEvent(SafeWaitHandle handle);
-
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool ResetEvent(SafeWaitHandle handle);
-
- [DllImport(Libraries.Kernel32, EntryPoint = "CreateEventExW", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern SafeWaitHandle CreateEventEx(IntPtr lpSecurityAttributes, string? name, uint flags, uint desiredAccess);
-
- [DllImport(Libraries.Kernel32, EntryPoint = "OpenEventW", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern SafeWaitHandle OpenEvent(uint desiredAccess, bool inheritHandle, string name);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ExpandEnvironmentStrings.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ExpandEnvironmentStrings.cs
deleted file mode 100644
index fbd5da84b8e..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ExpandEnvironmentStrings.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, EntryPoint = "ExpandEnvironmentStringsW", CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern uint ExpandEnvironmentStrings(string lpSrc, ref char lpDst, uint nSize);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FILE_INFO_BY_HANDLE_CLASS.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FILE_INFO_BY_HANDLE_CLASS.cs
deleted file mode 100644
index 5ea23ea96ad..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FILE_INFO_BY_HANDLE_CLASS.cs
+++ /dev/null
@@ -1,35 +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.
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal enum FILE_INFO_BY_HANDLE_CLASS : uint
- {
- FileBasicInfo = 0x0u,
- FileStandardInfo = 0x1u,
- FileNameInfo = 0x2u,
- FileRenameInfo = 0x3u,
- FileDispositionInfo = 0x4u,
- FileAllocationInfo = 0x5u,
- FileEndOfFileInfo = 0x6u,
- FileStreamInfo = 0x7u,
- FileCompressionInfo = 0x8u,
- FileAttributeTagInfo = 0x9u,
- FileIdBothDirectoryInfo = 0xAu,
- FileIdBothDirectoryRestartInfo = 0xBu,
- FileIoPriorityHintInfo = 0xCu,
- FileRemoteProtocolInfo = 0xDu,
- FileFullDirectoryInfo = 0xEu,
- FileFullDirectoryRestartInfo = 0xFu,
- FileStorageInfo = 0x10u,
- FileAlignmentInfo = 0x11u,
- FileIdInfo = 0x12u,
- FileIdExtdDirectoryInfo = 0x13u,
- FileIdExtdDirectoryRestartInfo = 0x14u,
- MaximumFileInfoByHandleClass = 0x15u,
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FILE_TIME.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FILE_TIME.cs
deleted file mode 100644
index 6a6464c4c8e..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FILE_TIME.cs
+++ /dev/null
@@ -1,27 +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 System;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal struct FILE_TIME
- {
- internal uint dwLowDateTime;
- internal uint dwHighDateTime;
-
- internal FILE_TIME(long fileTime)
- {
- dwLowDateTime = (uint)fileTime;
- dwHighDateTime = (uint)(fileTime >> 32);
- }
-
- internal long ToTicks() => ((long)dwHighDateTime << 32) + dwLowDateTime;
- internal DateTime ToDateTimeUtc() => DateTime.FromFileTimeUtc(ToTicks());
- internal DateTimeOffset ToDateTimeOffset() => DateTimeOffset.FromFileTime(ToTicks());
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileAttributes.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileAttributes.cs
deleted file mode 100644
index 2cf4e287d3c..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileAttributes.cs
+++ /dev/null
@@ -1,17 +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.
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal partial class FileAttributes
- {
- internal const int FILE_ATTRIBUTE_NORMAL = 0x00000080;
- internal const int FILE_ATTRIBUTE_READONLY = 0x00000001;
- internal const int FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
- internal const int FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileTimeToSystemTime.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileTimeToSystemTime.cs
deleted file mode 100644
index 676e344a51d..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileTimeToSystemTime.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe Interop.BOOL FileTimeToSystemTime(long* lpFileTime, Interop.Kernel32.SYSTEMTIME* lpSystemTime);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileTypes.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileTypes.cs
deleted file mode 100644
index a23ba1a3a0b..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FileTypes.cs
+++ /dev/null
@@ -1,17 +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.
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal partial class FileTypes
- {
- internal const int FILE_TYPE_UNKNOWN = 0x0000;
- internal const int FILE_TYPE_DISK = 0x0001;
- internal const int FILE_TYPE_CHAR = 0x0002;
- internal const int FILE_TYPE_PIPE = 0x0003;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindClose.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindClose.cs
deleted file mode 100644
index 4bd534933d6..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindClose.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool FindClose(IntPtr hFindFile);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs
deleted file mode 100644
index 6ab52b4d0e9..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs
+++ /dev/null
@@ -1,44 +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.
-
-#nullable enable
-using Microsoft.Win32.SafeHandles;
-using System;
-using System.IO;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- /// <summary>
- /// WARNING: This method does not implicitly handle long paths. Use FindFirstFile.
- /// </summary>
- [DllImport(Libraries.Kernel32, EntryPoint = "FindFirstFileExW", SetLastError = true, CharSet = CharSet.Unicode)]
- private static extern SafeFindHandle FindFirstFileExPrivate(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags);
-
- internal static SafeFindHandle FindFirstFile(string fileName, ref WIN32_FIND_DATA data)
- {
- fileName = PathInternal.EnsureExtendedPrefixIfNeeded(fileName);
-
- // use FindExInfoBasic since we don't care about short name and it has better perf
- return FindFirstFileExPrivate(fileName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0);
- }
-
- internal enum FINDEX_INFO_LEVELS : uint
- {
- FindExInfoStandard = 0x0u,
- FindExInfoBasic = 0x1u,
- FindExInfoMaxInfoLevel = 0x2u,
- }
-
- internal enum FINDEX_SEARCH_OPS : uint
- {
- FindExSearchNameMatch = 0x0u,
- FindExSearchLimitToDirectories = 0x1u,
- FindExSearchLimitToDevices = 0x2u,
- FindExSearchMaxSearchOp = 0x3u,
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FlushFileBuffers.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FlushFileBuffers.cs
deleted file mode 100644
index 2b145d3d7dd..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FlushFileBuffers.cs
+++ /dev/null
@@ -1,15 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool FlushFileBuffers(SafeHandle hHandle);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FormatMessage.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FormatMessage.cs
deleted file mode 100644
index 2eda58f2504..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FormatMessage.cs
+++ /dev/null
@@ -1,88 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- private const int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
- private const int FORMAT_MESSAGE_FROM_HMODULE = 0x00000800;
- private const int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
- private const int FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000;
- private const int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
- private const int ERROR_INSUFFICIENT_BUFFER = 0x7A;
-
- [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true, BestFitMapping = true)]
- private static extern unsafe int FormatMessage(
- int dwFlags,
- IntPtr lpSource,
- uint dwMessageId,
- int dwLanguageId,
- void* lpBuffer,
- int nSize,
- IntPtr arguments);
-
- /// <summary>
- /// Returns a string message for the specified Win32 error code.
- /// </summary>
- internal static string GetMessage(int errorCode) =>
- GetMessage(errorCode, IntPtr.Zero);
-
- internal static unsafe string GetMessage(int errorCode, IntPtr moduleHandle)
- {
- int flags = FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY;
- if (moduleHandle != IntPtr.Zero)
- {
- flags |= FORMAT_MESSAGE_FROM_HMODULE;
- }
-
- // First try to format the message into the stack based buffer. Most error messages willl fit.
- Span<char> stackBuffer = stackalloc char[256]; // arbitrary stack limit
- fixed (char* bufferPtr = stackBuffer)
- {
- int length = FormatMessage(flags, moduleHandle, unchecked((uint)errorCode), 0, bufferPtr, stackBuffer.Length, IntPtr.Zero);
- if (length > 0)
- {
- return GetAndTrimString(stackBuffer.Slice(0, length));
- }
- }
-
- // We got back an error. If the error indicated that there wasn't enough room to store
- // the error message, then call FormatMessage again, but this time rather than passing in
- // a buffer, have the method allocate one, which we then need to free.
- if (Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER)
- {
- IntPtr nativeMsgPtr = default;
- try
- {
- int length = FormatMessage(flags | FORMAT_MESSAGE_ALLOCATE_BUFFER, moduleHandle, unchecked((uint)errorCode), 0, &nativeMsgPtr, 0, IntPtr.Zero);
- if (length > 0)
- {
- return GetAndTrimString(new Span<char>((char*)nativeMsgPtr, length));
- }
- }
- finally
- {
- Marshal.FreeHGlobal(nativeMsgPtr);
- }
- }
-
- // Couldn't get a message, so manufacture one.
- return string.Format("Unknown error (0x{0:x})", errorCode);
- }
-
- private static string GetAndTrimString(Span<char> buffer)
- {
- int length = buffer.Length;
- while (length > 0 && buffer[length - 1] <= 32)
- {
- length--; // trim off spaces and non-printable ASCII chars at the end of the resource
- }
- return buffer.Slice(0, length).ToString();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FreeEnvironmentStrings.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FreeEnvironmentStrings.cs
deleted file mode 100644
index c222db8ef91..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FreeEnvironmentStrings.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, EntryPoint = "FreeEnvironmentStringsW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
- internal static extern unsafe bool FreeEnvironmentStrings(char* lpszEnvironmentBlock);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FreeLibrary.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FreeLibrary.cs
deleted file mode 100644
index 56d52fefbb0..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FreeLibrary.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
- internal static extern bool FreeLibrary(IntPtr hModule);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GET_FILEEX_INFO_LEVELS.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GET_FILEEX_INFO_LEVELS.cs
deleted file mode 100644
index 4ee86420322..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GET_FILEEX_INFO_LEVELS.cs
+++ /dev/null
@@ -1,15 +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.
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal enum GET_FILEEX_INFO_LEVELS : uint
- {
- GetFileExInfoStandard = 0x0u,
- GetFileExMaxInfoLevel = 0x1u,
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCPInfo.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCPInfo.cs
deleted file mode 100644
index b22a149b123..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCPInfo.cs
+++ /dev/null
@@ -1,23 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [StructLayout(LayoutKind.Sequential)]
- internal unsafe struct CPINFO
- {
- internal int MaxCharSize;
-
- internal fixed byte DefaultChar[2 /* MAX_DEFAULTCHAR */];
- internal fixed byte LeadByte[12 /* MAX_LEADBYTES */];
- }
-
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe Interop.BOOL GetCPInfo(uint codePage, CPINFO* lpCpInfo);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetComputerName.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetComputerName.cs
deleted file mode 100644
index 011430da5c7..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetComputerName.cs
+++ /dev/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.
-
-#nullable enable
-using System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "GetComputerNameW")]
- private static extern unsafe int GetComputerName(ref char lpBuffer, ref uint nSize);
-
- // maximum length of the NETBIOS name (not including NULL)
- private const int MAX_COMPUTERNAME_LENGTH = 15;
-
- internal static unsafe string? GetComputerName()
- {
- Span<char> buffer = stackalloc char[MAX_COMPUTERNAME_LENGTH + 1];
- uint length = (uint)buffer.Length;
-
- return GetComputerName(ref MemoryMarshal.GetReference(buffer), ref length) != 0 ?
- buffer.Slice(0, (int)length).ToString() :
- null;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentDirectory.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentDirectory.cs
deleted file mode 100644
index 4e30a8be432..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentDirectory.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, EntryPoint = "GetCurrentDirectoryW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
- internal static extern uint GetCurrentDirectory(uint nBufferLength, ref char lpBuffer);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs
deleted file mode 100644
index 5369a8049df..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs
+++ /dev/null
@@ -1,17 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- [SuppressGCTransition]
- internal static extern uint GetCurrentProcessId();
- }
-
- internal static uint GetCurrentProcessId() => Kernel32.GetCurrentProcessId();
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcess_IntPtr.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcess_IntPtr.cs
deleted file mode 100644
index a763735651a..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcess_IntPtr.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern IntPtr GetCurrentProcess();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs
deleted file mode 100644
index 775ddabfb6a..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs
+++ /dev/null
@@ -1,16 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, ExactSpelling = true)]
- [SuppressGCTransition]
- public static extern int GetCurrentThreadId();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetEnvironmentStrings.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetEnvironmentStrings.cs
deleted file mode 100644
index 5594fe7a4cb..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetEnvironmentStrings.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, EntryPoint = "GetEnvironmentStringsW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
- internal static extern unsafe char* GetEnvironmentStrings();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetEnvironmentVariable.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetEnvironmentVariable.cs
deleted file mode 100644
index 43463e52304..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetEnvironmentVariable.cs
+++ /dev/null
@@ -1,23 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal static unsafe int GetEnvironmentVariable(string lpName, Span<char> buffer)
- {
- fixed (char* bufferPtr = &MemoryMarshal.GetReference(buffer))
- {
- return GetEnvironmentVariable(lpName, bufferPtr, buffer.Length);
- }
- }
-
- [DllImport(Libraries.Kernel32, EntryPoint = "GetEnvironmentVariableW", SetLastError = true, CharSet = CharSet.Unicode)]
- private static extern unsafe int GetEnvironmentVariable(string lpName, char* lpBuffer, int nSize);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs
deleted file mode 100644
index 8d2e754edba..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs
+++ /dev/null
@@ -1,25 +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.
-
-#nullable enable
-using System.IO;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- /// <summary>
- /// WARNING: This method does not implicitly handle long paths. Use GetFileAttributesEx.
- /// </summary>
- [DllImport(Libraries.Kernel32, EntryPoint = "GetFileAttributesExW", SetLastError = true, CharSet = CharSet.Unicode)]
- private static extern bool GetFileAttributesExPrivate(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
-
- internal static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
- {
- name = PathInternal.EnsureExtendedPrefixIfNeeded(name);
- return GetFileAttributesExPrivate(name, fileInfoLevel, ref lpFileInformation);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileInformationByHandleEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileInformationByHandleEx.cs
deleted file mode 100644
index 92bee35cf42..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileInformationByHandleEx.cs
+++ /dev/null
@@ -1,24 +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.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool GetFileInformationByHandleEx(SafeFileHandle hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, out FILE_STANDARD_INFO lpFileInformation, uint dwBufferSize);
-
- internal struct FILE_STANDARD_INFO
- {
- internal long AllocationSize;
- internal long EndOfFile;
- internal uint NumberOfLinks;
- internal BOOL DeletePending;
- internal BOOL Directory;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileType_SafeHandle.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileType_SafeHandle.cs
deleted file mode 100644
index cdde2f0e4d9..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileType_SafeHandle.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern int GetFileType(SafeHandle hFile);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs
deleted file mode 100644
index 1bb63e7ed1d..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs
+++ /dev/null
@@ -1,18 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- /// <summary>
- /// WARNING: This method does not implicitly handle long paths. Use GetFullPathName or PathHelper.
- /// </summary>
- [DllImport(Libraries.Kernel32, SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
- internal static extern uint GetFullPathNameW(ref char lpFileName, uint nBufferLength, ref char lpBuffer, IntPtr lpFilePart);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetLogicalDrives.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetLogicalDrives.cs
deleted file mode 100644
index 2400eb3aac4..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetLogicalDrives.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern int GetLogicalDrives();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs
deleted file mode 100644
index 189c8e8cfe3..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs
+++ /dev/null
@@ -1,17 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- /// <summary>
- /// WARNING: This method does not implicitly handle long paths. Use GetFullPath/PathHelper.
- /// </summary>
- [DllImport(Libraries.Kernel32, SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
- internal static extern uint GetLongPathNameW(ref char lpszShortPath, ref char lpszLongPath, uint cchBuffer);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetProcessMemoryInfo.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetProcessMemoryInfo.cs
deleted file mode 100644
index 1d004bb8e91..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetProcessMemoryInfo.cs
+++ /dev/null
@@ -1,30 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [StructLayout(LayoutKind.Sequential)]
- internal struct PROCESS_MEMORY_COUNTERS
- {
- public uint cb;
- public uint PageFaultCount;
- public UIntPtr PeakWorkingSetSize;
- public UIntPtr WorkingSetSize;
- public UIntPtr QuotaPeakPagedPoolUsage;
- public UIntPtr QuotaPagedPoolUsage;
- public UIntPtr QuotaPeakNonPagedPoolUsage;
- public UIntPtr QuotaNonPagedPoolUsage;
- public UIntPtr PagefileUsage;
- public UIntPtr PeakPagefileUsage;
- }
-
- [DllImport(Libraries.Kernel32, EntryPoint="K32GetProcessMemoryInfo")]
- internal static extern bool GetProcessMemoryInfo(IntPtr Process, ref PROCESS_MEMORY_COUNTERS ppsmemCounters, uint cb);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetProcessTimes.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetProcessTimes.cs
deleted file mode 100644
index 451394539c6..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetProcessTimes.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool GetProcessTimes(IntPtr handleProcess, out long creation, out long exit, out long kernel, out long user);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs
deleted file mode 100644
index c73c86e935e..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs
+++ /dev/null
@@ -1,16 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- [SuppressGCTransition]
- internal static extern IntPtr GetStdHandle(int nStdHandle); // param is NOT a handle, but it returns one!
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemDirectoryW.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemDirectoryW.cs
deleted file mode 100644
index 197f6f5eadc..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemDirectoryW.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern uint GetSystemDirectoryW(ref char lpBuffer, uint uSize);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemInfo.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemInfo.cs
deleted file mode 100644
index 9e5b21c6b7f..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemInfo.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern void GetSystemInfo(out SYSTEM_INFO lpSystemInfo);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTime.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTime.cs
deleted file mode 100644
index ed0aa147454..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTime.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe void GetSystemTime(Interop.Kernel32.SYSTEMTIME* lpSystemTime);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimeAsFileTime.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimeAsFileTime.cs
deleted file mode 100644
index fc8b030a4c1..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimeAsFileTime.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe void GetSystemTimeAsFileTime(long* lpSystemTimeAsFileTime);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimePreciseAsFileTime.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimePreciseAsFileTime.cs
deleted file mode 100644
index 0067d90a808..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimePreciseAsFileTime.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe void GetSystemTimePreciseAsFileTime(long* lpSystemTimeAsFileTime);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimes.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimes.cs
deleted file mode 100644
index 34f8ad7b6df..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetSystemTimes.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool GetSystemTimes(out long idle, out long kernel, out long user);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetTempFileNameW.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetTempFileNameW.cs
deleted file mode 100644
index d7f9b828c0c..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetTempFileNameW.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
- internal static extern uint GetTempFileNameW(ref char lpPathName, string lpPrefixString, uint uUnique, ref char lpTempFileName);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetTempPathW.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetTempPathW.cs
deleted file mode 100644
index 8d2b0b199ed..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetTempPathW.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, BestFitMapping = false)]
- internal static extern uint GetTempPathW(int bufferLen, ref char buffer);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetVersionExW.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetVersionExW.cs
deleted file mode 100644
index 5899bdb5259..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetVersionExW.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern bool GetVersionExW(ref OSVERSIONINFOEX osvi);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GlobalMemoryStatusEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GlobalMemoryStatusEx.cs
deleted file mode 100644
index e25c8ef4f59..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GlobalMemoryStatusEx.cs
+++ /dev/null
@@ -1,20 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal static unsafe bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX buffer)
- {
- buffer.length = sizeof(MEMORYSTATUSEX);
- return GlobalMemoryStatusExNative(ref buffer);
- }
-
- [DllImport(Libraries.Kernel32, SetLastError = true, EntryPoint = "GlobalMemoryStatusEx")]
- private static extern bool GlobalMemoryStatusExNative(ref MEMORYSTATUSEX lpBuffer);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Globalization.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Globalization.cs
deleted file mode 100644
index 192e555bba8..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Globalization.cs
+++ /dev/null
@@ -1,145 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static unsafe partial class Kernel32
- {
- internal const uint LOCALE_ALLOW_NEUTRAL_NAMES = 0x08000000; // Flag to allow returning neutral names/lcids for name conversion
- internal const uint LOCALE_ILANGUAGE = 0x00000001;
- internal const uint LOCALE_SUPPLEMENTAL = 0x00000002;
- internal const uint LOCALE_REPLACEMENT = 0x00000008;
- internal const uint LOCALE_NEUTRALDATA = 0x00000010;
- internal const uint LOCALE_SPECIFICDATA = 0x00000020;
- internal const uint LOCALE_SISO3166CTRYNAME = 0x0000005A;
- internal const uint LOCALE_SNAME = 0x0000005C;
- internal const uint LOCALE_INEUTRAL = 0x00000071;
- internal const uint LOCALE_SSHORTTIME = 0x00000079;
- internal const uint LOCALE_STIMEFORMAT = 0x00001003;
- internal const uint LOCALE_IFIRSTDAYOFWEEK = 0x0000100C;
- internal const uint LOCALE_RETURN_NUMBER = 0x20000000;
- internal const uint LOCALE_NOUSEROVERRIDE = 0x80000000;
-
- internal const uint LCMAP_SORTHANDLE = 0x20000000;
- internal const uint LCMAP_HASH = 0x00040000;
-
- internal const int COMPARE_STRING = 0x0001;
-
- internal const uint TIME_NOSECONDS = 0x00000002;
-
- internal const string LOCALE_NAME_USER_DEFAULT = null;
- internal const string LOCALE_NAME_SYSTEM_DEFAULT = "!x-sys-default-locale";
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern int LCIDToLocaleName(int locale, char* pLocaleName, int cchName, uint dwFlags);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern int LocaleNameToLCID(string lpName, uint dwFlags);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern int LCMapStringEx(
- string? lpLocaleName,
- uint dwMapFlags,
- char* lpSrcStr,
- int cchSrc,
- void* lpDestStr,
- int cchDest,
- void* lpVersionInformation,
- void* lpReserved,
- IntPtr sortHandle);
-
- [DllImport("kernel32.dll", EntryPoint = "FindNLSStringEx")]
- internal static extern int FindNLSStringEx(
- char* lpLocaleName,
- uint dwFindNLSStringFlags,
- char* lpStringSource,
- int cchSource,
- char* lpStringValue,
- int cchValue,
- int* pcchFound,
- void* lpVersionInformation,
- void* lpReserved,
- IntPtr sortHandle);
-
- [DllImport("kernel32.dll", EntryPoint = "CompareStringEx")]
- internal static extern int CompareStringEx(
- char* lpLocaleName,
- uint dwCmpFlags,
- char* lpString1,
- int cchCount1,
- char* lpString2,
- int cchCount2,
- void* lpVersionInformation,
- void* lpReserved,
- IntPtr lParam);
-
- [DllImport("kernel32.dll", EntryPoint = "CompareStringOrdinal")]
- internal static extern int CompareStringOrdinal(
- char* lpString1,
- int cchCount1,
- char* lpString2,
- int cchCount2,
- bool bIgnoreCase);
-
- [DllImport("kernel32.dll", EntryPoint = "FindStringOrdinal")]
- internal static extern int FindStringOrdinal(
- uint dwFindStringOrdinalFlags,
- char* lpStringSource,
- int cchSource,
- char* lpStringValue,
- int cchValue,
- int bIgnoreCase);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern bool IsNLSDefinedString(
- int Function,
- uint dwFlags,
- IntPtr lpVersionInformation,
- char* lpString,
- int cchStr);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
- internal static extern Interop.BOOL GetUserPreferredUILanguages(uint dwFlags, uint* pulNumLanguages, char* pwszLanguagesBuffer, uint* pcchLanguagesBuffer);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern int GetLocaleInfoEx(string lpLocaleName, uint LCType, void* lpLCData, int cchData);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern bool EnumSystemLocalesEx(EnumLocalesProcEx lpLocaleEnumProcEx, uint dwFlags, void* lParam, IntPtr reserved);
-
- internal delegate BOOL EnumLocalesProcEx(char* lpLocaleString, uint dwFlags, void* lParam);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern bool EnumTimeFormatsEx(EnumTimeFormatsProcEx lpTimeFmtEnumProcEx, string lpLocaleName, uint dwFlags, void* lParam);
-
- internal delegate BOOL EnumTimeFormatsProcEx(char* lpTimeFormatString, void* lParam);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern int GetCalendarInfoEx(string? lpLocaleName, uint Calendar, IntPtr lpReserved, uint CalType, IntPtr lpCalData, int cchData, out int lpValue);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern int GetCalendarInfoEx(string? lpLocaleName, uint Calendar, IntPtr lpReserved, uint CalType, IntPtr lpCalData, int cchData, IntPtr lpValue);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern bool EnumCalendarInfoExEx(EnumCalendarInfoProcExEx pCalInfoEnumProcExEx, string lpLocaleName, uint Calendar, string? lpReserved, uint CalType, void* lParam);
-
- internal delegate BOOL EnumCalendarInfoProcExEx(char* lpCalendarInfoString, uint Calendar, IntPtr lpReserved, void* lParam);
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct NlsVersionInfoEx
- {
- internal int dwNLSVersionInfoSize;
- internal int dwNLSVersion;
- internal int dwDefinedVersion;
- internal int dwEffectiveId;
- internal Guid guidCustomVersion;
- }
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern bool GetNLSVersionEx(int function, string localeName, NlsVersionInfoEx* lpVersionInformation);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.HandleTypes.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.HandleTypes.cs
deleted file mode 100644
index a5a42af560e..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.HandleTypes.cs
+++ /dev/null
@@ -1,16 +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.
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal partial class HandleTypes
- {
- internal const int STD_INPUT_HANDLE = -10;
- internal const int STD_OUTPUT_HANDLE = -11;
- internal const int STD_ERROR_HANDLE = -12;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.IsWow64Process_IntPtr.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.IsWow64Process_IntPtr.cs
deleted file mode 100644
index 43936ab3fae..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.IsWow64Process_IntPtr.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool IsWow64Process(IntPtr hProcess, out bool Wow64Process);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LoadLibraryEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LoadLibraryEx.cs
deleted file mode 100644
index 7693f628075..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LoadLibraryEx.cs
+++ /dev/null
@@ -1,19 +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 static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal const int LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
- internal const int LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800;
-
- [DllImport(Libraries.Kernel32, EntryPoint = "LoadLibraryExW", CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern SafeLibraryHandle LoadLibraryEx(string libFilename, IntPtr reserved, int flags);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LocalAlloc.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LocalAlloc.cs
deleted file mode 100644
index 14486c2b533..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LocalAlloc.cs
+++ /dev/null
@@ -1,24 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal const uint LMEM_FIXED = 0x0000;
- internal const uint LMEM_MOVEABLE = 0x0002;
-
- [DllImport(Libraries.Kernel32)]
- internal static extern IntPtr LocalAlloc(uint uFlags, UIntPtr uBytes);
-
- [DllImport(Libraries.Kernel32)]
- internal static extern IntPtr LocalReAlloc(IntPtr hMem, IntPtr uBytes, uint uFlags);
-
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern IntPtr LocalFree(IntPtr hMem);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LockFile.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LockFile.cs
deleted file mode 100644
index 82c7e4998b8..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LockFile.cs
+++ /dev/null
@@ -1,18 +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.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool LockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh);
-
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool UnlockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MAX_PATH.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MAX_PATH.cs
deleted file mode 100644
index 9de12c94041..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MAX_PATH.cs
+++ /dev/null
@@ -1,11 +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.
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal const int MAX_PATH = 260;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MEMORYSTATUSEX.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MEMORYSTATUSEX.cs
deleted file mode 100644
index 83d1d860d1b..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MEMORYSTATUSEX.cs
+++ /dev/null
@@ -1,26 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [StructLayout(LayoutKind.Sequential)]
- internal struct MEMORYSTATUSEX
- {
- // The length field must be set to the size of this data structure.
- internal int length;
- internal int memoryLoad;
- internal ulong totalPhys;
- internal ulong availPhys;
- internal ulong totalPageFile;
- internal ulong availPageFile;
- internal ulong totalVirtual;
- internal ulong availVirtual;
- internal ulong availExtendedVirtual;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MEMORY_BASIC_INFORMATION.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MEMORY_BASIC_INFORMATION.cs
deleted file mode 100644
index ce49fb58179..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MEMORY_BASIC_INFORMATION.cs
+++ /dev/null
@@ -1,24 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [StructLayout(LayoutKind.Sequential)]
- internal unsafe struct MEMORY_BASIC_INFORMATION
- {
- internal void* BaseAddress;
- internal void* AllocationBase;
- internal uint AllocationProtect;
- internal UIntPtr RegionSize;
- internal uint State;
- internal uint Protect;
- internal uint Type;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MUI.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MUI.cs
deleted file mode 100644
index 12867a8527b..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MUI.cs
+++ /dev/null
@@ -1,16 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal const uint MUI_PREFERRED_UI_LANGUAGES = 0x10;
-
- [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
- internal static extern unsafe bool GetFileMUIPath(uint dwFlags, string pcwszFilePath, char* pwszLanguage, ref int pcchLanguage, char* pwszFileMUIPath, ref int pcchFileMUIPath, ref long pululEnumerator);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MultiByteToWideChar.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MultiByteToWideChar.cs
deleted file mode 100644
index d369cb49c7c..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.MultiByteToWideChar.cs
+++ /dev/null
@@ -1,19 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe int MultiByteToWideChar(
- uint CodePage, uint dwFlags,
- byte* lpMultiByteStr, int cbMultiByte,
- char* lpWideCharStr, int cchWideChar);
-
- internal const uint MB_PRECOMPOSED = 0x00000001;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Mutex.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Mutex.cs
deleted file mode 100644
index 6adaf987370..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Mutex.cs
+++ /dev/null
@@ -1,25 +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.
-
-#nullable enable
-using Microsoft.Win32.SafeHandles;
-using System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal const uint CREATE_MUTEX_INITIAL_OWNER = 0x1;
-
- [DllImport(Libraries.Kernel32, EntryPoint = "OpenMutexW", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern SafeWaitHandle OpenMutex(uint desiredAccess, bool inheritHandle, string name);
-
- [DllImport(Libraries.Kernel32, EntryPoint = "CreateMutexExW", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern SafeWaitHandle CreateMutexEx(IntPtr lpMutexAttributes, string? name, uint flags, uint desiredAccess);
-
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool ReleaseMutex(SafeWaitHandle handle);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OSVERSIONINFOEX.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OSVERSIONINFOEX.cs
deleted file mode 100644
index 0f6e2e6b333..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OSVERSIONINFOEX.cs
+++ /dev/null
@@ -1,27 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal unsafe struct OSVERSIONINFOEX
- {
- public int dwOSVersionInfoSize;
- public int dwMajorVersion;
- public int dwMinorVersion;
- public int dwBuildNumber;
- public int dwPlatformId;
- public fixed char szCSDVersion[128];
- public ushort wServicePackMajor;
- public ushort wServicePackMinor;
- public ushort wSuiteMask;
- public byte wProductType;
- public byte wReserved;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OutputDebugString.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OutputDebugString.cs
deleted file mode 100644
index 3ad3edde73d..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OutputDebugString.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "OutputDebugStringW", ExactSpelling = true)]
- internal static extern void OutputDebugString(string message);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceCounter.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceCounter.cs
deleted file mode 100644
index 63f68473234..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceCounter.cs
+++ /dev/null
@@ -1,23 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- // The actual native signature is:
- // BOOL WINAPI QueryPerformanceCounter(
- // _Out_ LARGE_INTEGER* lpPerformanceCount
- // );
- //
- // We take a long* (rather than a out long) to avoid the pinning overhead.
- // We don't set last error since we don't need the extended error info.
-
- [DllImport(Libraries.Kernel32, ExactSpelling = true)]
- [SuppressGCTransition]
- internal static extern unsafe BOOL QueryPerformanceCounter(long* lpPerformanceCount);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceFrequency.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceFrequency.cs
deleted file mode 100644
index 641451b671f..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryPerformanceFrequency.cs
+++ /dev/null
@@ -1,22 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- // The actual native signature is:
- // BOOL WINAPI QueryPerformanceFrequency(
- // _Out_ LARGE_INTEGER* lpFrequency
- // );
- //
- // We take a long* (rather than a out long) to avoid the pinning overhead.
- // We don't set last error since we don't need the extended error info.
-
- [DllImport(Libraries.Kernel32, ExactSpelling = true)]
- internal static extern unsafe BOOL QueryPerformanceFrequency(long* lpFrequency);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryUnbiasedInterruptTime.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryUnbiasedInterruptTime.cs
deleted file mode 100644
index f7264d4dc8c..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryUnbiasedInterruptTime.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern bool QueryUnbiasedInterruptTime(out ulong UnbiasedTime);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_IntPtr.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_IntPtr.cs
deleted file mode 100644
index b9f1c9584d8..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_IntPtr.cs
+++ /dev/null
@@ -1,20 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern unsafe int ReadFile(
- SafeHandle handle,
- byte* bytes,
- int numBytesToRead,
- out int numBytesRead,
- IntPtr mustBeZero);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_NativeOverlapped.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_NativeOverlapped.cs
deleted file mode 100644
index a3c72547f96..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_NativeOverlapped.cs
+++ /dev/null
@@ -1,21 +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 System;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern unsafe int ReadFile(
- SafeHandle handle,
- byte* bytes,
- int numBytesToRead,
- IntPtr numBytesRead_mustBeZero,
- NativeOverlapped* overlapped);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ResolveLocaleName.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ResolveLocaleName.cs
deleted file mode 100644
index c349129d515..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.ResolveLocaleName.cs
+++ /dev/null
@@ -1,16 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static unsafe partial class Kernel32
- {
- internal const int LOCALE_NAME_MAX_LENGTH = 85;
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
- internal static extern int ResolveLocaleName(string lpNameToResolve, char* lpLocaleName, int cchLocaleName);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SECURITY_ATTRIBUTES.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SECURITY_ATTRIBUTES.cs
deleted file mode 100644
index f2f32fd2775..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SECURITY_ATTRIBUTES.cs
+++ /dev/null
@@ -1,20 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [StructLayout(LayoutKind.Sequential)]
- internal struct SECURITY_ATTRIBUTES
- {
- internal uint nLength;
- internal IntPtr lpSecurityDescriptor;
- internal BOOL bInheritHandle;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SYSTEM_INFO.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SYSTEM_INFO.cs
deleted file mode 100644
index 0ebeeff1933..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SYSTEM_INFO.cs
+++ /dev/null
@@ -1,38 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [StructLayout(LayoutKind.Sequential)]
- internal struct SYSTEM_INFO
- {
- internal ushort wProcessorArchitecture;
- internal ushort wReserved;
- internal int dwPageSize;
- internal IntPtr lpMinimumApplicationAddress;
- internal IntPtr lpMaximumApplicationAddress;
- internal IntPtr dwActiveProcessorMask;
- internal int dwNumberOfProcessors;
- internal int dwProcessorType;
- internal int dwAllocationGranularity;
- internal short wProcessorLevel;
- internal short wProcessorRevision;
- }
-
- internal enum ProcessorArchitecture : ushort
- {
- Processor_Architecture_INTEL = 0,
- Processor_Architecture_ARM = 5,
- Processor_Architecture_IA64 = 6,
- Processor_Architecture_AMD64 = 9,
- Processor_Architecture_ARM64 = 12,
- Processor_Architecture_UNKNOWN = 0xFFFF
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SecurityOptions.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SecurityOptions.cs
deleted file mode 100644
index bc9f5806771..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SecurityOptions.cs
+++ /dev/null
@@ -1,18 +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.
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal static partial class SecurityOptions
- {
- internal const int SECURITY_SQOS_PRESENT = 0x00100000;
- internal const int SECURITY_ANONYMOUS = 0 << 16;
- internal const int SECURITY_IDENTIFICATION = 1 << 16;
- internal const int SECURITY_IMPERSONATION = 2 << 16;
- internal const int SECURITY_DELEGATION = 3 << 16;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Semaphore.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Semaphore.cs
deleted file mode 100644
index 4f6d8de8768..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.Semaphore.cs
+++ /dev/null
@@ -1,23 +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.
-
-#nullable enable
-using Microsoft.Win32.SafeHandles;
-using System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, EntryPoint = "OpenSemaphoreW", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern SafeWaitHandle OpenSemaphore(uint desiredAccess, bool inheritHandle, string name);
-
- [DllImport(Libraries.Kernel32, EntryPoint = "CreateSemaphoreExW", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern SafeWaitHandle CreateSemaphoreEx(IntPtr lpSecurityAttributes, int initialCount, int maximumCount, string? name, uint flags, uint desiredAccess);
-
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool ReleaseSemaphore(SafeWaitHandle handle, int releaseCount, out int previousCount);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetCurrentDirectory.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetCurrentDirectory.cs
deleted file mode 100644
index d268d4daa6f..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetCurrentDirectory.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, EntryPoint = "SetCurrentDirectoryW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
- internal static extern bool SetCurrentDirectory(string path);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetEndOfFile.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetEndOfFile.cs
deleted file mode 100644
index 6d93e151cf6..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetEndOfFile.cs
+++ /dev/null
@@ -1,15 +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.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool SetEndOfFile(SafeFileHandle hFile);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetEnvironmentVariable.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetEnvironmentVariable.cs
deleted file mode 100644
index 243bd6562e0..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetEnvironmentVariable.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, EntryPoint = "SetEnvironmentVariableW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
- internal static extern bool SetEnvironmentVariable(string lpName, string? lpValue);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetFilePointerEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetFilePointerEx.cs
deleted file mode 100644
index e83806697f1..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetFilePointerEx.cs
+++ /dev/null
@@ -1,15 +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.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern bool SetFilePointerEx(SafeFileHandle hFile, long liDistanceToMove, out long lpNewFilePointer, uint dwMoveMethod);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetThreadErrorMode.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetThreadErrorMode.cs
deleted file mode 100644
index f582c20c58e..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SetThreadErrorMode.cs
+++ /dev/null
@@ -1,17 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true, ExactSpelling = true)]
- [SuppressGCTransition]
- internal static extern bool SetThreadErrorMode(uint dwNewMode, out uint lpOldMode);
-
- internal const uint SEM_FAILCRITICALERRORS = 1;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SystemTimeToFileTime.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SystemTimeToFileTime.cs
deleted file mode 100644
index c347eeae7f8..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.SystemTimeToFileTime.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe Interop.BOOL SystemTimeToFileTime(Interop.Kernel32.SYSTEMTIME* lpSystemTime, long* lpFileTime);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TimeZone.Registry.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TimeZone.Registry.cs
deleted file mode 100644
index 14993bcca62..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TimeZone.Registry.cs
+++ /dev/null
@@ -1,30 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [StructLayout(LayoutKind.Sequential)]
- internal struct REG_TZI_FORMAT
- {
- internal int Bias;
- internal int StandardBias;
- internal int DaylightBias;
- internal SYSTEMTIME StandardDate;
- internal SYSTEMTIME DaylightDate;
-
- internal REG_TZI_FORMAT(in TIME_ZONE_INFORMATION tzi)
- {
- Bias = tzi.Bias;
- StandardDate = tzi.StandardDate;
- StandardBias = tzi.StandardBias;
- DaylightDate = tzi.DaylightDate;
- DaylightBias = tzi.DaylightBias;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TimeZone.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TimeZone.cs
deleted file mode 100644
index 7be40ca8f4c..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TimeZone.cs
+++ /dev/null
@@ -1,93 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal struct SYSTEMTIME
- {
- internal ushort Year;
- internal ushort Month;
- internal ushort DayOfWeek;
- internal ushort Day;
- internal ushort Hour;
- internal ushort Minute;
- internal ushort Second;
- internal ushort Milliseconds;
-
- internal bool Equals(in SYSTEMTIME other) =>
- Year == other.Year &&
- Month == other.Month &&
- DayOfWeek == other.DayOfWeek &&
- Day == other.Day &&
- Hour == other.Hour &&
- Minute == other.Minute &&
- Second == other.Second &&
- Milliseconds == other.Milliseconds;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal unsafe struct TIME_DYNAMIC_ZONE_INFORMATION
- {
- internal int Bias;
- internal fixed char StandardName[32];
- internal SYSTEMTIME StandardDate;
- internal int StandardBias;
- internal fixed char DaylightName[32];
- internal SYSTEMTIME DaylightDate;
- internal int DaylightBias;
- internal fixed char TimeZoneKeyName[128];
- internal byte DynamicDaylightTimeDisabled;
-
- internal string GetTimeZoneKeyName()
- {
- fixed (char* p = TimeZoneKeyName)
- return new string(p);
- }
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal unsafe struct TIME_ZONE_INFORMATION
- {
- internal int Bias;
- internal fixed char StandardName[32];
- internal SYSTEMTIME StandardDate;
- internal int StandardBias;
- internal fixed char DaylightName[32];
- internal SYSTEMTIME DaylightDate;
- internal int DaylightBias;
-
- internal TIME_ZONE_INFORMATION(in TIME_DYNAMIC_ZONE_INFORMATION dtzi)
- {
- // The start of TIME_DYNAMIC_ZONE_INFORMATION has identical layout as TIME_ZONE_INFORMATION
- fixed (TIME_ZONE_INFORMATION* pTo = &this)
- fixed (TIME_DYNAMIC_ZONE_INFORMATION* pFrom = &dtzi)
- *pTo = *(TIME_ZONE_INFORMATION*)pFrom;
- }
-
- internal string GetStandardName()
- {
- fixed (char* p = StandardName)
- return new string(p);
- }
-
- internal string GetDaylightName()
- {
- fixed (char* p = DaylightName)
- return new string(p);
- }
- }
-
- internal const uint TIME_ZONE_ID_INVALID = unchecked((uint)-1);
-
- [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
- internal static extern uint GetDynamicTimeZoneInformation(out TIME_DYNAMIC_ZONE_INFORMATION pTimeZoneInformation);
-
- [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
- internal static extern uint GetTimeZoneInformation(out TIME_ZONE_INFORMATION lpTimeZoneInformation);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TzSpecificLocalTimeToSystemTime.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TzSpecificLocalTimeToSystemTime.cs
deleted file mode 100644
index 5cea7e071cf..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.TzSpecificLocalTimeToSystemTime.cs
+++ /dev/null
@@ -1,18 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe Interop.BOOL TzSpecificLocalTimeToSystemTime(
- IntPtr lpTimeZoneInformation,
- Interop.Kernel32.SYSTEMTIME* lpLocalTime,
- Interop.Kernel32.SYSTEMTIME* lpUniversalTime);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerSetConditionMask.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerSetConditionMask.cs
deleted file mode 100644
index 96e6172bc63..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerSetConditionMask.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern ulong VerSetConditionMask(ulong ConditionMask, uint TypeMask, byte Condition);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerifyVersionExW.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerifyVersionExW.cs
deleted file mode 100644
index f8bd85a2a71..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerifyVersionExW.cs
+++ /dev/null
@@ -1,20 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal const byte VER_GREATER_EQUAL = 0x3;
- internal const uint VER_MAJORVERSION = 0x0000002;
- internal const uint VER_MINORVERSION = 0x0000001;
- internal const uint VER_SERVICEPACKMAJOR = 0x0000020;
- internal const uint VER_SERVICEPACKMINOR = 0x0000010;
-
- [DllImport(Libraries.Kernel32)]
- internal static extern bool VerifyVersionInfoW(ref OSVERSIONINFOEX lpVersionInfo, uint dwTypeMask, ulong dwlConditionMask);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualAlloc.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualAlloc.cs
deleted file mode 100644
index 6fa12851417..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualAlloc.cs
+++ /dev/null
@@ -1,21 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal const int MEM_COMMIT = 0x1000;
- internal const int MEM_RESERVE = 0x2000;
- internal const int MEM_RELEASE = 0x8000;
- internal const int MEM_FREE = 0x10000;
- internal const int PAGE_READWRITE = 0x04;
-
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe void* VirtualAlloc(void* lpAddress, UIntPtr dwSize, int flAllocationType, int flProtect);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualFree.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualFree.cs
deleted file mode 100644
index 75dbdf04777..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualFree.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe bool VirtualFree(void* lpAddress, UIntPtr dwSize, int dwFreeType);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualQuery.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualQuery.cs
deleted file mode 100644
index 1c9655693d9..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VirtualQuery.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern unsafe UIntPtr VirtualQuery(void* lpAddress, ref MEMORY_BASIC_INFORMATION lpBuffer, UIntPtr dwLength);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WIN32_FILE_ATTRIBUTE_DATA.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WIN32_FILE_ATTRIBUTE_DATA.cs
deleted file mode 100644
index 05607443da4..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WIN32_FILE_ATTRIBUTE_DATA.cs
+++ /dev/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.
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- internal struct WIN32_FILE_ATTRIBUTE_DATA
- {
- internal int dwFileAttributes;
- internal FILE_TIME ftCreationTime;
- internal FILE_TIME ftLastAccessTime;
- internal FILE_TIME ftLastWriteTime;
- internal uint nFileSizeHigh;
- internal uint nFileSizeLow;
-
- internal void PopulateFrom(ref WIN32_FIND_DATA findData)
- {
- dwFileAttributes = (int)findData.dwFileAttributes;
- ftCreationTime = findData.ftCreationTime;
- ftLastAccessTime = findData.ftLastAccessTime;
- ftLastWriteTime = findData.ftLastWriteTime;
- nFileSizeHigh = findData.nFileSizeHigh;
- nFileSizeLow = findData.nFileSizeLow;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WIN32_FIND_DATA.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WIN32_FIND_DATA.cs
deleted file mode 100644
index f1ed25f83b4..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WIN32_FIND_DATA.cs
+++ /dev/null
@@ -1,32 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal unsafe struct WIN32_FIND_DATA
- {
- internal uint dwFileAttributes;
- internal FILE_TIME ftCreationTime;
- internal FILE_TIME ftLastAccessTime;
- internal FILE_TIME ftLastWriteTime;
- internal uint nFileSizeHigh;
- internal uint nFileSizeLow;
- internal uint dwReserved0;
- internal uint dwReserved1;
- private fixed char _cFileName[MAX_PATH];
- private fixed char _cAlternateFileName[14];
-
- internal ReadOnlySpan<char> cFileName
- {
- get { fixed (char* c = _cFileName) return new ReadOnlySpan<char>(c, MAX_PATH); }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WideCharToMultiByte.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WideCharToMultiByte.cs
deleted file mode 100644
index 1925a8c5785..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WideCharToMultiByte.cs
+++ /dev/null
@@ -1,22 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe int WideCharToMultiByte(
- uint CodePage, uint dwFlags,
- char* lpWideCharStr, int cchWideChar,
- byte* lpMultiByteStr, int cbMultiByte,
- IntPtr lpDefaultChar, IntPtr lpUsedDefaultChar);
-
- internal const uint CP_ACP = 0;
- internal const uint WC_NO_BEST_FIT_CHARS = 0x00000400;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_IntPtr.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_IntPtr.cs
deleted file mode 100644
index e25d205259d..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_IntPtr.cs
+++ /dev/null
@@ -1,22 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- // Note there are two different WriteFile prototypes - this is to use
- // the type system to force you to not trip across a "feature" in
- // Win32's async IO support. You can't do the following three things
- // simultaneously: overlapped IO, free the memory for the overlapped
- // struct in a callback (or an EndWrite method called by that callback),
- // and pass in an address for the numBytesRead parameter.
-
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern unsafe int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_NativeOverlapped.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_NativeOverlapped.cs
deleted file mode 100644
index 9c01f0a5fb7..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_NativeOverlapped.cs
+++ /dev/null
@@ -1,22 +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 System;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-internal static partial class Interop
-{
- internal static partial class Kernel32
- {
- // Note there are two different WriteFile prototypes - this is to use
- // the type system to force you to not trip across a "feature" in
- // Win32's async IO support. You can't do the following three things
- // simultaneously: overlapped IO, free the memory for the overlapped
- // struct in a callback (or an EndWrite method called by that callback),
- // and pass in an address for the numBytesRead parameter.
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static extern unsafe int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, IntPtr numBytesWritten_mustBeZero, NativeOverlapped* lpOverlapped);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Normaliz/Interop.Idna.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Normaliz/Interop.Idna.cs
deleted file mode 100644
index 039e34b5157..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Normaliz/Interop.Idna.cs
+++ /dev/null
@@ -1,34 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Normaliz
- {
- //
- // Idn APIs
- //
-
- [DllImport("Normaliz.dll", CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern unsafe int IdnToAscii(
- uint dwFlags,
- char* lpUnicodeCharStr,
- int cchUnicodeChar,
- char* lpASCIICharStr,
- int cchASCIIChar);
-
- [DllImport("Normaliz.dll", CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern unsafe int IdnToUnicode(
- uint dwFlags,
- char* lpASCIICharStr,
- int cchASCIIChar,
- char* lpUnicodeCharStr,
- int cchUnicodeChar);
-
- internal const int IDN_ALLOW_UNASSIGNED = 0x1;
- internal const int IDN_USE_STD3_ASCII_RULES = 0x2;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Normaliz/Interop.Normalization.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Normaliz/Interop.Normalization.cs
deleted file mode 100644
index 3e954483d18..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Normaliz/Interop.Normalization.cs
+++ /dev/null
@@ -1,23 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Normaliz
- {
- [DllImport("Normaliz.dll", CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern bool IsNormalizedString(int normForm, string source, int length);
-
- [DllImport("Normaliz.dll", CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern int NormalizeString(
- int normForm,
- string source,
- int sourceLength,
- [System.Runtime.InteropServices.OutAttribute]
- char[]? destination,
- int destinationLength);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/NtDll/Interop.NtQueryInformationFile.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/NtDll/Interop.NtQueryInformationFile.cs
deleted file mode 100644
index ed36e7898b3..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/NtDll/Interop.NtQueryInformationFile.cs
+++ /dev/null
@@ -1,46 +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 static partial class Interop
-{
- internal static partial class NtDll
- {
- [DllImport(Libraries.NtDll, ExactSpelling = true)]
- internal static extern unsafe int NtQueryInformationFile(
- SafeFileHandle FileHandle,
- out IO_STATUS_BLOCK IoStatusBlock,
- void* FileInformation,
- uint Length,
- uint FileInformationClass);
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct IO_STATUS_BLOCK
- {
- private IO_STATUS Status;
- private IntPtr Information;
- }
-
- // This isn't an actual Windows type, we have to separate it out as the size of IntPtr varies by architecture
- // and we can't specify the size at compile time to offset the Information pointer in the status block.
- [StructLayout(LayoutKind.Explicit)]
- internal struct IO_STATUS
- {
- [FieldOffset(0)]
- private int Status;
-
- [FieldOffset(0)]
- private IntPtr Pointer;
- }
-
- internal const uint FileModeInformation = 16;
- internal const uint FILE_SYNCHRONOUS_IO_ALERT = 0x00000010;
- internal const uint FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020;
-
- internal const int STATUS_INVALID_HANDLE = unchecked((int)0xC0000008);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/NtDll/Interop.NtQuerySystemInformation.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/NtDll/Interop.NtQuerySystemInformation.cs
deleted file mode 100644
index dc8be886d6c..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/NtDll/Interop.NtQuerySystemInformation.cs
+++ /dev/null
@@ -1,23 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class NtDll
- {
- [DllImport(Libraries.NtDll)]
- internal static extern unsafe int NtQuerySystemInformation(int SystemInformationClass, void* SystemInformation, int SystemInformationLength, uint* ReturnLength);
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct SYSTEM_LEAP_SECOND_INFORMATION
- {
- public bool Enabled;
- public uint Flags;
- }
-
- internal const int SystemLeapSecondInformation = 206;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoCreateGuid.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoCreateGuid.cs
deleted file mode 100644
index 57accbe7c00..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoCreateGuid.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Ole32
- {
- [DllImport(Interop.Libraries.Ole32)]
- internal static extern int CoCreateGuid(out Guid guid);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoTaskMemAlloc.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoTaskMemAlloc.cs
deleted file mode 100644
index e51dc99550c..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoTaskMemAlloc.cs
+++ /dev/null
@@ -1,21 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Ole32
- {
- [DllImport(Libraries.Ole32)]
- internal static extern IntPtr CoTaskMemAlloc(UIntPtr cb);
-
- [DllImport(Libraries.Ole32)]
- internal static extern IntPtr CoTaskMemRealloc(IntPtr pv, UIntPtr cb);
-
- [DllImport(Libraries.Ole32)]
- internal static extern void CoTaskMemFree(IntPtr ptr);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringByteLen.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringByteLen.cs
deleted file mode 100644
index 7c97ecdca7a..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringByteLen.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class OleAut32
- {
- [DllImport(Libraries.OleAut32)]
- internal static extern IntPtr SysAllocStringByteLen(byte[]? str, uint len);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringLen.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringLen.cs
deleted file mode 100644
index ac9459907bf..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringLen.cs
+++ /dev/null
@@ -1,16 +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 System;
-using System.Runtime.InteropServices;
-using System.Security;
-
-internal static partial class Interop
-{
- internal static partial class OleAut32
- {
- [DllImport(Libraries.OleAut32, CharSet = CharSet.Unicode)]
- internal static extern IntPtr SysAllocStringLen(string? src, int len);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysFreeString.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysFreeString.cs
deleted file mode 100644
index fea22df406a..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysFreeString.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class OleAut32
- {
- [DllImport(Libraries.OleAut32)]
- internal static extern void SysFreeString(IntPtr bstr);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Secur32/Interop.GetUserNameExW.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Secur32/Interop.GetUserNameExW.cs
deleted file mode 100644
index e88864cd9e7..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Secur32/Interop.GetUserNameExW.cs
+++ /dev/null
@@ -1,16 +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 System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Secur32
- {
- [DllImport(Libraries.Secur32, CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern BOOLEAN GetUserNameExW(int NameFormat, ref char lpNameBuffer, ref uint lpnSize);
-
- internal const int NameSamCompatible = 2;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
deleted file mode 100644
index 3e72b01e1f6..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
+++ /dev/null
@@ -1,320 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class Shell32
- {
- internal const int COR_E_PLATFORMNOTSUPPORTED = unchecked((int)0x80131539);
-
- // https://msdn.microsoft.com/en-us/library/windows/desktop/bb762188.aspx
- [DllImport(Libraries.Shell32, CharSet = CharSet.Unicode, SetLastError = false, BestFitMapping = false, ExactSpelling = true)]
- internal static extern int SHGetKnownFolderPath(
- [MarshalAs(UnmanagedType.LPStruct)] Guid rfid,
- uint dwFlags,
- IntPtr hToken,
- out string ppszPath);
-
- // https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457.aspx
- internal static class KnownFolders
- {
- /// <summary>
- /// (CSIDL_ADMINTOOLS) Per user Administrative Tools
- /// "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Administrative Tools"
- /// </summary>
- internal const string AdminTools = "{724EF170-A42D-4FEF-9F26-B60E846FBA4F}";
-
- /// <summary>
- /// (CSIDL_CDBURN_AREA) Temporary Burn folder
- /// "%LOCALAPPDATA%\Microsoft\Windows\Burn\Burn"
- /// </summary>
- internal const string CDBurning = "{9E52AB10-F80D-49DF-ACB8-4330F5687855}";
-
- /// <summary>
- /// (CSIDL_COMMON_ADMINTOOLS) Common Administrative Tools
- /// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Administrative Tools"
- /// </summary>
- internal const string CommonAdminTools = "{D0384E7D-BAC3-4797-8F14-CBA229B392B5}";
-
- /// <summary>
- /// (CSIDL_COMMON_OEM_LINKS) OEM Links folder
- /// "%ALLUSERSPROFILE%\OEM Links"
- /// </summary>
- internal const string CommonOEMLinks = "{C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D}";
-
- /// <summary>
- /// (CSIDL_COMMON_PROGRAMS) Common Programs folder
- /// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs"
- /// </summary>
- internal const string CommonPrograms = "{0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8}";
-
- /// <summary>
- /// (CSIDL_COMMON_STARTMENU) Common Start Menu folder
- /// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu"
- /// </summary>
- internal const string CommonStartMenu = "{A4115719-D62E-491D-AA7C-E74B8BE3B067}";
-
- /// <summary>
- /// (CSIDL_COMMON_STARTUP, CSIDL_COMMON_ALTSTARTUP) Common Startup folder
- /// "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\StartUp"
- /// </summary>
- internal const string CommonStartup = "{82A5EA35-D9CD-47C5-9629-E15D2F714E6E}";
-
- /// <summary>
- /// (CSIDL_COMMON_TEMPLATES) Common Templates folder
- /// "%ALLUSERSPROFILE%\Microsoft\Windows\Templates"
- /// </summary>
- internal const string CommonTemplates = "{B94237E7-57AC-4347-9151-B08C6C32D1F7}";
-
- /// <summary>
- /// (CSIDL_DRIVES) Computer virtual folder
- /// </summary>
- internal const string ComputerFolder = "{0AC0837C-BBF8-452A-850D-79D08E667CA7}";
-
- /// <summary>
- /// (CSIDL_CONNECTIONS) Network Connections virtual folder
- /// </summary>
- internal const string ConnectionsFolder = "{6F0CD92B-2E97-45D1-88FF-B0D186B8DEDD}";
-
- /// <summary>
- /// (CSIDL_CONTROLS) Control Panel virtual folder
- /// </summary>
- internal const string ControlPanelFolder = "{82A74AEB-AEB4-465C-A014-D097EE346D63}";
-
- /// <summary>
- /// (CSIDL_COOKIES) Cookies folder
- /// "%APPDATA%\Microsoft\Windows\Cookies"
- /// </summary>
- internal const string Cookies = "{2B0F765D-C0E9-4171-908E-08A611B84FF6}";
-
- /// <summary>
- /// (CSIDL_DESKTOP, CSIDL_DESKTOPDIRECTORY) Desktop folder
- /// "%USERPROFILE%\Desktop"
- /// </summary>
- internal const string Desktop = "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}";
-
- /// <summary>
- /// (CSIDL_MYDOCUMENTS, CSIDL_PERSONAL) Documents (My Documents) folder
- /// "%USERPROFILE%\Documents"
- /// </summary>
- internal const string Documents = "{FDD39AD0-238F-46AF-ADB4-6C85480369C7}";
-
- /// <summary>
- /// (CSIDL_FAVORITES, CSIDL_COMMON_FAVORITES) Favorites folder
- /// "%USERPROFILE%\Favorites"
- /// </summary>
- internal const string Favorites = "{1777F761-68AD-4D8A-87BD-30B759FA33DD}";
-
- /// <summary>
- /// (CSIDL_FONTS) Fonts folder
- /// "%windir%\Fonts"
- /// </summary>
- internal const string Fonts = "{FD228CB7-AE11-4AE3-864C-16F3910AB8FE}";
-
- /// <summary>
- /// (CSIDL_HISTORY) History folder
- /// "%LOCALAPPDATA%\Microsoft\Windows\History"
- /// </summary>
- internal const string History = "{D9DC8A3B-B784-432E-A781-5A1130A75963}";
-
- /// <summary>
- /// (CSIDL_INTERNET_CACHE) Temporary Internet Files folder
- /// "%LOCALAPPDATA%\Microsoft\Windows\Temporary Internet Files"
- /// </summary>
- internal const string InternetCache = "{352481E8-33BE-4251-BA85-6007CAEDCF9D}";
-
- /// <summary>
- /// (CSIDL_INTERNET) The Internet virtual folder
- /// </summary>
- internal const string InternetFolder = "{4D9F7874-4E0C-4904-967B-40B0D20C3E4B}";
-
- /// <summary>
- /// (CSIDL_LOCAL_APPDATA) Local folder
- /// "%LOCALAPPDATA%" ("%USERPROFILE%\AppData\Local")
- /// </summary>
- internal const string LocalAppData = "{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}";
-
- /// <summary>
- /// (CSIDL_RESOURCES_LOCALIZED) Fixed localized resources folder
- /// "%windir%\resources\0409" (per active codepage)
- /// </summary>
- internal const string LocalizedResourcesDir = "{2A00375E-224C-49DE-B8D1-440DF7EF3DDC}";
-
- /// <summary>
- /// (CSIDL_MYMUSIC) Music folder
- /// "%USERPROFILE%\Music"
- /// </summary>
- internal const string Music = "{4BD8D571-6D19-48D3-BE97-422220080E43}";
-
- /// <summary>
- /// (CSIDL_NETHOOD) Network shortcuts folder "%APPDATA%\Microsoft\Windows\Network Shortcuts"
- /// </summary>
- internal const string NetHood = "{C5ABBF53-E17F-4121-8900-86626FC2C973}";
-
- /// <summary>
- /// (CSIDL_NETWORK, CSIDL_COMPUTERSNEARME) Network virtual folder
- /// </summary>
- internal const string NetworkFolder = "{D20BEEC4-5CA8-4905-AE3B-BF251EA09B53}";
-
- /// <summary>
- /// (CSIDL_MYPICTURES) Pictures folder "%USERPROFILE%\Pictures"
- /// </summary>
- internal const string Pictures = "{33E28130-4E1E-4676-835A-98395C3BC3BB}";
-
- /// <summary>
- /// (CSIDL_PRINTERS) Printers virtual folder
- /// </summary>
- internal const string PrintersFolder = "{76FC4E2D-D6AD-4519-A663-37BD56068185}";
-
- /// <summary>
- /// (CSIDL_PRINTHOOD) Printer Shortcuts folder
- /// "%APPDATA%\Microsoft\Windows\Printer Shortcuts"
- /// </summary>
- internal const string PrintHood = "{9274BD8D-CFD1-41C3-B35E-B13F55A758F4}";
-
- /// <summary>
- /// (CSIDL_PROFILE) The root users profile folder "%USERPROFILE%"
- /// ("%SystemDrive%\Users\%USERNAME%")
- /// </summary>
- internal const string Profile = "{5E6C858F-0E22-4760-9AFE-EA3317B67173}";
-
- /// <summary>
- /// (CSIDL_COMMON_APPDATA) ProgramData folder
- /// "%ALLUSERSPROFILE%" ("%ProgramData%", "%SystemDrive%\ProgramData")
- /// </summary>
- internal const string ProgramData = "{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}";
-
- /// <summary>
- /// (CSIDL_PROGRAM_FILES) Program Files folder for the current process architecture
- /// "%ProgramFiles%" ("%SystemDrive%\Program Files")
- /// </summary>
- internal const string ProgramFiles = "{905e63b6-c1bf-494e-b29c-65b732d3d21a}";
-
- /// <summary>
- /// (CSIDL_PROGRAM_FILESX86) 32 bit Program Files folder (available to both 32/64 bit processes)
- /// </summary>
- internal const string ProgramFilesX86 = "{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}";
-
- /// <summary>
- /// (CSIDL_PROGRAM_FILES_COMMON) Common Program Files folder for the current process architecture
- /// "%ProgramFiles%\Common Files"
- /// </summary>
- internal const string ProgramFilesCommon = "{F7F1ED05-9F6D-47A2-AAAE-29D317C6F066}";
-
- /// <summary>
- /// (CSIDL_PROGRAM_FILES_COMMONX86) Common 32 bit Program Files folder (available to both 32/64 bit processes)
- /// </summary>
- internal const string ProgramFilesCommonX86 = "{DE974D24-D9C6-4D3E-BF91-F4455120B917}";
-
- /// <summary>
- /// (CSIDL_PROGRAMS) Start menu Programs folder
- /// "%APPDATA%\Microsoft\Windows\Start Menu\Programs"
- /// </summary>
- internal const string Programs = "{A77F5D77-2E2B-44C3-A6A2-ABA601054A51}";
-
- /// <summary>
- /// (CSIDL_COMMON_DESKTOPDIRECTORY) Public Desktop folder
- /// "%PUBLIC%\Desktop"
- /// </summary>
- internal const string PublicDesktop = "{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}";
-
- /// <summary>
- /// (CSIDL_COMMON_DOCUMENTS) Public Documents folder
- /// "%PUBLIC%\Documents"
- /// </summary>
- internal const string PublicDocuments = "{ED4824AF-DCE4-45A8-81E2-FC7965083634}";
-
- /// <summary>
- /// (CSIDL_COMMON_MUSIC) Public Music folder
- /// "%PUBLIC%\Music"
- /// </summary>
- internal const string PublicMusic = "{3214FAB5-9757-4298-BB61-92A9DEAA44FF}";
-
- /// <summary>
- /// (CSIDL_COMMON_PICTURES) Public Pictures folder
- /// "%PUBLIC%\Pictures"
- /// </summary>
- internal const string PublicPictures = "{B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5}";
-
- /// <summary>
- /// (CSIDL_COMMON_VIDEO) Public Videos folder
- /// "%PUBLIC%\Videos"
- /// </summary>
- internal const string PublicVideos = "{2400183A-6185-49FB-A2D8-4A392A602BA3}";
-
- /// <summary>
- /// (CSIDL_RECENT) Recent Items folder
- /// "%APPDATA%\Microsoft\Windows\Recent"
- /// </summary>
- internal const string Recent = "{AE50C081-EBD2-438A-8655-8A092E34987A}";
-
- /// <summary>
- /// (CSIDL_BITBUCKET) Recycle Bin virtual folder
- /// </summary>
- internal const string RecycleBinFolder = "{B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC}";
-
- /// <summary>
- /// (CSIDL_RESOURCES) Resources fixed folder
- /// "%windir%\Resources"
- /// </summary>
- internal const string ResourceDir = "{8AD10C31-2ADB-4296-A8F7-E4701232C972}";
-
- /// <summary>
- /// (CSIDL_APPDATA) Roaming user application data folder
- /// "%APPDATA%" ("%USERPROFILE%\AppData\Roaming")
- /// </summary>
- internal const string RoamingAppData = "{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}";
-
- /// <summary>
- /// (CSIDL_SENDTO) SendTo folder
- /// "%APPDATA%\Microsoft\Windows\SendTo"
- /// </summary>
- internal const string SendTo = "{8983036C-27C0-404B-8F08-102D10DCFD74}";
-
- /// <summary>
- /// (CSIDL_STARTMENU) Start Menu folder
- /// "%APPDATA%\Microsoft\Windows\Start Menu"
- /// </summary>
- internal const string StartMenu = "{625B53C3-AB48-4EC1-BA1F-A1EF4146FC19}";
-
- /// <summary>
- /// (CSIDL_STARTUP, CSIDL_ALTSTARTUP) Startup folder
- /// "%APPDATA%\Microsoft\Windows\Start Menu\Programs\StartUp"
- /// </summary>
- internal const string Startup = "{B97D20BB-F46A-4C97-BA10-5E3608430854}";
-
- /// <summary>
- /// (CSIDL_SYSTEM) System32 folder
- /// "%windir%\system32"
- /// </summary>
- internal const string System = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}";
-
- /// <summary>
- /// (CSIDL_SYSTEMX86) X86 System32 folder
- /// "%windir%\system32" or "%windir%\syswow64"
- /// </summary>
- internal const string SystemX86 = "{D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}";
-
- /// <summary>
- /// (CSIDL_TEMPLATES) Templates folder
- /// "%APPDATA%\Microsoft\Windows\Templates"
- /// </summary>
- internal const string Templates = "{A63293E8-664E-48DB-A079-DF759E0509F7}";
-
- /// <summary>
- /// (CSIDL_MYVIDEO) Videos folder
- /// "%USERPROFILE%\Videos"
- /// </summary>
- internal const string Videos = "{18989B1D-99B5-455B-841C-AB7C74E4DDFC}";
-
- /// <summary>
- /// (CSIDL_WINDOWS) Windows folder "%windir%"
- /// </summary>
- internal const string Windows = "{F38BF404-1D43-42F2-9305-67DE0B28FC23}";
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.Constants.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.Constants.cs
deleted file mode 100644
index a48329fb6b1..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.Constants.cs
+++ /dev/null
@@ -1,12 +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.
-
-internal static partial class Interop
-{
- internal static partial class User32
- {
- internal const int HWND_BROADCAST = 0xffff;
- internal const int WM_SETTINGCHANGE = 0x001A;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.LoadString.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.LoadString.cs
deleted file mode 100644
index e328e9b0c1e..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.LoadString.cs
+++ /dev/null
@@ -1,15 +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 System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-internal static partial class Interop
-{
- internal static partial class User32
- {
- [DllImport(Libraries.User32, SetLastError = true, EntryPoint = "LoadStringW", CharSet = CharSet.Unicode)]
- internal static extern unsafe int LoadString(SafeLibraryHandle hInstance, uint uID, char* lpBuffer, int cchBufferMax);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.SendMessageTimeout.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.SendMessageTimeout.cs
deleted file mode 100644
index f73c0aceaa8..00000000000
--- a/netcore/System.Private.CoreLib/shared/Interop/Windows/User32/Interop.SendMessageTimeout.cs
+++ /dev/null
@@ -1,15 +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 System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class User32
- {
- [DllImport(Libraries.User32, EntryPoint = "SendMessageTimeoutW", CharSet = CharSet.Unicode)]
- public static extern IntPtr SendMessageTimeout(IntPtr hWnd, int msg, IntPtr wParam, string lParam, int flags, int timeout, IntPtr pdwResult);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/CriticalHandleMinusOneIsInvalid.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/CriticalHandleMinusOneIsInvalid.cs
deleted file mode 100644
index a76c51d9666..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/CriticalHandleMinusOneIsInvalid.cs
+++ /dev/null
@@ -1,20 +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 System;
-using System.Runtime.InteropServices;
-
-namespace Microsoft.Win32.SafeHandles
-{
- // Class of critical handle which uses only -1 as an invalid handle.
- public abstract class CriticalHandleMinusOneIsInvalid : CriticalHandle
- {
- protected CriticalHandleMinusOneIsInvalid()
- : base(new IntPtr(-1))
- {
- }
-
- public override bool IsInvalid => handle == new IntPtr(-1);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/CriticalHandleZeroOrMinusOneIsInvalid.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/CriticalHandleZeroOrMinusOneIsInvalid.cs
deleted file mode 100644
index 28d02194896..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/CriticalHandleZeroOrMinusOneIsInvalid.cs
+++ /dev/null
@@ -1,20 +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 System;
-using System.Runtime.InteropServices;
-
-namespace Microsoft.Win32.SafeHandles
-{
- // Class of critical handle which uses 0 or -1 as an invalid handle.
- public abstract class CriticalHandleZeroOrMinusOneIsInvalid : CriticalHandle
- {
- protected CriticalHandleZeroOrMinusOneIsInvalid()
- : base(IntPtr.Zero)
- {
- }
-
- public override bool IsInvalid => handle == IntPtr.Zero || handle == new IntPtr(-1);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs
deleted file mode 100644
index ad9e3eaba0c..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs
+++ /dev/null
@@ -1,138 +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 System;
-using System.Diagnostics;
-using System.IO;
-using System.Runtime.InteropServices;
-
-namespace Microsoft.Win32.SafeHandles
-{
- public sealed class SafeFileHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- private SafeFileHandle() : this(ownsHandle: true)
- {
- }
-
- private SafeFileHandle(bool ownsHandle)
- : base(ownsHandle)
- {
- SetHandle(new IntPtr(-1));
- }
-
- public SafeFileHandle(IntPtr preexistingHandle, bool ownsHandle) : this(ownsHandle)
- {
- SetHandle(preexistingHandle);
- }
-
- internal bool? IsAsync { get; set; }
-
- /// <summary>Opens the specified file with the requested flags and mode.</summary>
- /// <param name="path">The path to the file.</param>
- /// <param name="flags">The flags with which to open the file.</param>
- /// <param name="mode">The mode for opening the file.</param>
- /// <returns>A SafeFileHandle for the opened file.</returns>
- internal static SafeFileHandle Open(string path, Interop.Sys.OpenFlags flags, int mode)
- {
- Debug.Assert(path != null);
- SafeFileHandle handle = Interop.Sys.Open(path, flags, mode);
-
- if (handle.IsInvalid)
- {
- handle.Dispose();
- Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
-
- // If we fail to open the file due to a path not existing, we need to know whether to blame
- // the file itself or its directory. If we're creating the file, then we blame the directory,
- // otherwise we blame the file.
- //
- // When opening, we need to align with Windows, which considers a missing path to be
- // FileNotFound only if the containing directory exists.
-
- bool isDirectory = (error.Error == Interop.Error.ENOENT) &&
- ((flags & Interop.Sys.OpenFlags.O_CREAT) != 0
- || !DirectoryExists(Path.GetDirectoryName(Path.TrimEndingDirectorySeparator(path!))!));
-
- Interop.CheckIo(
- error.Error,
- path,
- isDirectory,
- errorRewriter: e => (e.Error == Interop.Error.EISDIR) ? Interop.Error.EACCES.Info() : e);
- }
-
- // Make sure it's not a directory; we do this after opening it once we have a file descriptor
- // to avoid race conditions.
- Interop.Sys.FileStatus status;
- if (Interop.Sys.FStat(handle, out status) != 0)
- {
- handle.Dispose();
- throw Interop.GetExceptionForIoErrno(Interop.Sys.GetLastErrorInfo(), path);
- }
- if ((status.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR)
- {
- handle.Dispose();
- throw Interop.GetExceptionForIoErrno(Interop.Error.EACCES.Info(), path, isDirectory: true);
- }
-
- return handle;
- }
-
- private static bool DirectoryExists(string fullPath)
- {
- Interop.Sys.FileStatus fileinfo;
-
- // First use stat, as we want to follow symlinks. If that fails, it could be because the symlink
- // is broken, we don't have permissions, etc., in which case fall back to using LStat to evaluate
- // based on the symlink itself.
- if (Interop.Sys.Stat(fullPath, out fileinfo) < 0 &&
- Interop.Sys.LStat(fullPath, out fileinfo) < 0)
- {
- return false;
- }
-
- return ((fileinfo.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR);
- }
-
- /// <summary>Opens a SafeFileHandle for a file descriptor created by a provided delegate.</summary>
- /// <param name="fdFunc">
- /// The function that creates the file descriptor. Returns the file descriptor on success, or an invalid
- /// file descriptor on error with Marshal.GetLastWin32Error() set to the error code.
- /// </param>
- /// <returns>The created SafeFileHandle.</returns>
- internal static SafeFileHandle Open(Func<SafeFileHandle> fdFunc)
- {
- SafeFileHandle handle = Interop.CheckIo(fdFunc());
-
- Debug.Assert(!handle.IsInvalid, "File descriptor is invalid");
- return handle;
- }
-
- protected override bool ReleaseHandle()
- {
- // When the SafeFileHandle was opened, we likely issued an flock on the created descriptor in order to add
- // an advisory lock. This lock should be removed via closing the file descriptor, but close can be
- // interrupted, and we don't retry closes. As such, we could end up leaving the file locked,
- // which could prevent subsequent usage of the file until this process dies. To avoid that, we proactively
- // try to release the lock before we close the handle. (If it's not locked, there's no behavioral
- // problem trying to unlock it.)
- Interop.Sys.FLock(handle, Interop.Sys.LockOperations.LOCK_UN); // ignore any errors
-
- // Close the descriptor. Although close is documented to potentially fail with EINTR, we never want
- // to retry, as the descriptor could actually have been closed, been subsequently reassigned, and
- // be in use elsewhere in the process. Instead, we simply check whether the call was successful.
- int result = Interop.Sys.Close(handle);
- Debug.Assert(result == 0, $"Close failed with result {result} and error {Interop.Sys.GetLastErrorInfo()}");
- return result == 0;
- }
-
- public override bool IsInvalid
- {
- get
- {
- long h = (long)handle;
- return h < 0 || h > int.MaxValue;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
deleted file mode 100644
index c54218e5b5f..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
+++ /dev/null
@@ -1,37 +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 System;
-using System.Threading;
-
-namespace Microsoft.Win32.SafeHandles
-{
- public sealed class SafeFileHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- private bool? _isAsync;
-
- private SafeFileHandle() : base(true)
- {
- _isAsync = null;
- }
-
- public SafeFileHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle)
- {
- SetHandle(preexistingHandle);
-
- _isAsync = null;
- }
-
- internal bool? IsAsync
- {
- get => _isAsync;
- set => _isAsync = value;
- }
-
- internal ThreadPoolBoundHandle? ThreadPoolBinding { get; set; }
-
- protected override bool ReleaseHandle() =>
- Interop.Kernel32.CloseHandle(handle);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFindHandle.Windows.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFindHandle.Windows.cs
deleted file mode 100644
index c16b22d4f57..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeFindHandle.Windows.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace Microsoft.Win32.SafeHandles
-{
- internal sealed class SafeFindHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- internal SafeFindHandle() : base(true) { }
-
- protected override bool ReleaseHandle()
- {
- return Interop.Kernel32.FindClose(handle);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeHandleMinusOneIsInvalid.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeHandleMinusOneIsInvalid.cs
deleted file mode 100644
index 5415f2c35d3..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeHandleMinusOneIsInvalid.cs
+++ /dev/null
@@ -1,19 +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 System;
-using System.Runtime.InteropServices;
-
-namespace Microsoft.Win32.SafeHandles
-{
- // Class of safe handle which uses only -1 as an invalid handle.
- public abstract class SafeHandleMinusOneIsInvalid : SafeHandle
- {
- protected SafeHandleMinusOneIsInvalid(bool ownsHandle) : base(new IntPtr(-1), ownsHandle)
- {
- }
-
- public override bool IsInvalid => handle == new IntPtr(-1);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeHandleZeroOrMinusOneIsInvalid.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeHandleZeroOrMinusOneIsInvalid.cs
deleted file mode 100644
index 8d0220bf905..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeHandleZeroOrMinusOneIsInvalid.cs
+++ /dev/null
@@ -1,19 +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 System;
-using System.Runtime.InteropServices;
-
-namespace Microsoft.Win32.SafeHandles
-{
- // Class of safe handle which uses 0 or -1 as an invalid handle.
- public abstract class SafeHandleZeroOrMinusOneIsInvalid : SafeHandle
- {
- protected SafeHandleZeroOrMinusOneIsInvalid(bool ownsHandle) : base(IntPtr.Zero, ownsHandle)
- {
- }
-
- public override bool IsInvalid => handle == IntPtr.Zero || handle == new IntPtr(-1);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs
deleted file mode 100644
index dce7834389b..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace Microsoft.Win32.SafeHandles
-{
- internal sealed class SafeLibraryHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- internal SafeLibraryHandle() : base(true) { }
-
- protected override bool ReleaseHandle()
- {
- return Interop.Kernel32.FreeLibrary(handle);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeRegistryHandle.Windows.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeRegistryHandle.Windows.cs
deleted file mode 100644
index cb3506bac4c..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeRegistryHandle.Windows.cs
+++ /dev/null
@@ -1,23 +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;
-
-#if REGISTRY_ASSEMBLY
-namespace Microsoft.Win32.SafeHandles
-#else
-namespace Internal.Win32.SafeHandles
-#endif
-{
-#if REGISTRY_ASSEMBLY
- public
-#else
- internal
-#endif
- sealed partial class SafeRegistryHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- protected override bool ReleaseHandle() =>
- Interop.Advapi32.RegCloseKey(handle) == Interop.Errors.ERROR_SUCCESS;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs
deleted file mode 100644
index 37e350031b8..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs
+++ /dev/null
@@ -1,28 +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;
-
-#if REGISTRY_ASSEMBLY
-namespace Microsoft.Win32.SafeHandles
-#else
-namespace Internal.Win32.SafeHandles
-#endif
-{
-#if REGISTRY_ASSEMBLY
- public
-#else
- internal
-#endif
- sealed partial class SafeRegistryHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- internal SafeRegistryHandle() : base(true) { }
-
- public SafeRegistryHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle)
- {
- SetHandle(preexistingHandle);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeWaitHandle.Windows.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeWaitHandle.Windows.cs
deleted file mode 100644
index 66f17f0af70..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeWaitHandle.Windows.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace Microsoft.Win32.SafeHandles
-{
- public sealed partial class SafeWaitHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- protected override bool ReleaseHandle() => Interop.Kernel32.CloseHandle(handle);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs b/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs
deleted file mode 100644
index edb0cdfcafe..00000000000
--- a/netcore/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs
+++ /dev/null
@@ -1,21 +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 System;
-
-namespace Microsoft.Win32.SafeHandles
-{
- public sealed partial class SafeWaitHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- // Called by P/Invoke marshaler
- private SafeWaitHandle() : base(true)
- {
- }
-
- public SafeWaitHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle)
- {
- SetHandle(existingHandle);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/README.md b/netcore/System.Private.CoreLib/shared/README.md
deleted file mode 100644
index 28c9e733a38..00000000000
--- a/netcore/System.Private.CoreLib/shared/README.md
+++ /dev/null
@@ -1,19 +0,0 @@
-# System.Private.CoreLib Shared Sources
-
-This directory contains the shared sources for System.Private.CoreLib. These are shared between [mono/mono](https://github.com/mono/mono/tree/master/netcore/System.Private.CoreLib/shared), [dotnet/coreclr](https://github.com/dotnet/coreclr/tree/master/src/System.Private.CoreLib/shared) and [dotnet/corefx](https://github.com/dotnet/corefx/tree/master/src/Common/src/CoreLib).
-
-The sources are synchronized with a mirroring tool that watches for new commits on either side and creates new pull requests (as @dotnet-bot) in the other repository.
-
-## Conventions
-
-Code in the shared directory should have no code specific to CoreCLR, CoreRT or CoreFX. Parts of classes that need to have different implementations on different runtimes should use partial classes and &#42;.CoreCLR.cs/&#42;.CoreFX.cs files in the non shared portion. Code that is different based on platform (Windows/Unix) is fine to leave in the shared portion. Remember to follow the [style guidelines](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md).
-
-## Getting clean CI and merging the mirror PRs
-
-Once the mirror PR is created there is a chance that the new code will require changes to get a clean CI. Any changes can be added to the PR by checking out the PR branch and adding new commits. Please follow the following guidelines for modifying these PRs.
-
- - **DO NOT** modify the commits made by @dotnet-bot in any way.
- - **TRY** to only make changes outside of shared.
- - Changes made in the shared folder in additional commits will get mirrored properly if the mirror PR is merged with a **REBASE**
- - **ALWAYS** Merge the mirror PR with the **REBASE** option.
- - Using one of the other options will cause the mirror to miss commits
diff --git a/netcore/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/netcore/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
deleted file mode 100644
index ac793c38fc2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
+++ /dev/null
@@ -1,1379 +0,0 @@
-<Project>
- <PropertyGroup>
- <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
- <HasSharedItems>true</HasSharedItems>
- <SharedGUID>c5ed3c1d-b572-46f1-8f96-522a85ce1179</SharedGUID>
- </PropertyGroup>
- <PropertyGroup Label="Configuration">
- <Import_RootNamespace />
- </PropertyGroup>
- <PropertyGroup>
- <Nullable>enable</Nullable>
- </PropertyGroup>
- <PropertyGroup>
- <TargetsWindows Condition="'$(TargetsWindows)' != 'true'">false</TargetsWindows>
- <TargetsUnix Condition="'$(TargetsUnix)' != 'true'">false</TargetsUnix>
- <TargetsOSX Condition="'$(TargetsOSX)' != 'true'">false</TargetsOSX>
- </PropertyGroup>
- <ItemDefinitionGroup>
- <Compile>
- <Visible>true</Visible>
- </Compile>
- </ItemDefinitionGroup>
- <ItemGroup>
- <Compile Include="$(MSBuildThisFileDirectory)Internal\IO\File.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Internal\Padding.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Internal\Runtime\CompilerServices\Unsafe.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Internal\Threading\Tasks\AsyncCausalitySupport.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\CriticalHandleMinusOneIsInvalid.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\CriticalHandleZeroOrMinusOneIsInvalid.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeHandleMinusOneIsInvalid.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeHandleZeroOrMinusOneIsInvalid.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeWaitHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Action.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Activator.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Activator.RuntimeType.cs" Condition="'$(TargetsCoreRT)' != 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AccessViolationException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AppContext.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AppDomain.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AppDomainSetup.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ApplicationException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AggregateException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ArgumentException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ArgumentNullException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ArgumentOutOfRangeException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ArithmeticException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Array.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Array.Enumerators.cs" Condition="'$(TargetsCoreRT)' != 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ArraySegment.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ArrayTypeMismatchException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AssemblyLoadEventArgs.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AssemblyLoadEventHandler.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AsyncCallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Attribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AttributeTargets.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AttributeUsageAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\BadImageFormatException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\BitConverter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Boolean.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\ArrayPool.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\ArrayPoolEventSource.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\ConfigurableArrayPool.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\IMemoryOwner.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\IPinnable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\MemoryHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\MemoryManager.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\OperationStatus.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\StandardFormat.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\TlsOverPerCoreLockedStacksArrayPool.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Utilities.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Binary\Reader.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Binary\ReaderBigEndian.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Binary\ReaderLittleEndian.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Binary\WriterBigEndian.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Binary\WriterLittleEndian.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\FormattingHelpers.CountDigits.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Constants.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\FormattingHelpers.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Boolean.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Date.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Date.G.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Date.L.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Date.O.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Date.R.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Decimal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Decimal.E.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Decimal.F.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Decimal.G.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Float.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Guid.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Integer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Integer.Signed.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Integer.Signed.D.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Integer.Signed.Default.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Integer.Signed.N.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Integer.Unsigned.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Integer.Unsigned.D.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Integer.Unsigned.Default.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Integer.Unsigned.N.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.Integer.Unsigned.X.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Formatter\Utf8Formatter.TimeSpan.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\ParserHelpers.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Boolean.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Date.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Date.Default.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Date.G.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Date.Helpers.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Date.O.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Date.R.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Decimal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Float.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Guid.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Integer.Signed.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Integer.Signed.D.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Integer.Signed.N.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Integer.Unsigned.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Integer.Unsigned.D.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Integer.Unsigned.N.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Integer.Unsigned.X.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.Number.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.TimeSpan.BigG.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.TimeSpan.C.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.TimeSpan.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.TimeSpan.LittleG.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.TimeSpanSplitter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Byte.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ByReference.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\CannotUnloadAppDomainException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Char.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\CharEnumerator.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\CLSCompliantAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\ArrayList.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Comparer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Concurrent\ConcurrentQueue.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Concurrent\ConcurrentQueueSegment.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Concurrent\IProducerConsumerCollection.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Concurrent\IProducerConsumerCollectionDebugView.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\DictionaryEntry.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\ArraySortHelper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\Comparer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\Dictionary.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\EqualityComparer.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" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IDictionary.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IDictionaryDebugView.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IEnumerable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IEnumerator.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IEqualityComparer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IList.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IReadOnlyCollection.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IReadOnlyDictionary.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IReadOnlyList.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\KeyNotFoundException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\KeyValuePair.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\NonRandomizedStringEqualityComparer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\ValueListBuilder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\List.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\CompatibleComparer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Hashtable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\HashHelpers.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\HashHelpers.SerializationInfoTable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\ICollection.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\IComparer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\IDictionary.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\IDictionaryEnumerator.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\IEnumerable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\IEnumerator.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\IEqualityComparer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\IHashCodeProvider.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\IList.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\IStructuralComparable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\IStructuralEquatable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\KeyValuePairs.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\ListDictionaryInternal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\ObjectModel\Collection.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Collections\ObjectModel\ReadOnlyCollection.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ComponentModel\DefaultValueAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ComponentModel\EditorBrowsableAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ComponentModel\EditorBrowsableState.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Configuration\Assemblies\AssemblyHashAlgorithm.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Configuration\Assemblies\AssemblyVersionCompatibility.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Convert.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Convert.Base64.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\CoreLib.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\CurrentSystemTimeZone.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DataMisalignedException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DateTime.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DateTimeKind.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DateTimeOffset.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DayOfWeek.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DBNull.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Decimal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Decimal.DecCalc.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DefaultBinder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Delegate.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\SuppressMessageAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\CodeAnalysis\NullableAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\ConditionalAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Contracts\ContractException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Contracts\ContractFailedEventArgs.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Contracts\Contracts.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Debug.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggableAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerBrowsableAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerDisplayAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerHiddenAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerNonUserCodeAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerStepThroughAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerStepperBoundaryAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerTypeProxyAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebuggerVisualizerAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebugProvider.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\StackFrame.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\StackTrace.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\StackTraceHiddenAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\SymbolStore\ISymbolDocumentWriter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Stopwatch.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DivideByZeroException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DllNotFoundException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Double.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DuplicateWaitObjectException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Empty.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\EntryPointNotFoundException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Environment.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Environment.SpecialFolder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Environment.SpecialFolderOption.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\EnvironmentVariableTarget.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Enum.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\EventArgs.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\EventHandler.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Exception.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ExecutionEngineException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\FieldAccessException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\FlagsAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\FormatException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\FormattableString.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\GCMemoryInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Gen2GcCallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\BidiCategory.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\Calendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CalendarAlgorithmType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CalendarData.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CalendarWeekRule.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CalendricalCalculationsHelper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CharUnicodeInfoData.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CultureData.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CultureInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CharUnicodeInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\ChineseLunisolarCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CompareInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CompareInfo.Invariant.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CompareOptions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CultureNotFoundException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CultureTypes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\DateTimeFormat.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\DateTimeFormatInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\DateTimeFormatInfoScanner.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\DateTimeParse.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\DateTimeStyles.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\DaylightTime.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\DigitShapes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\EastAsianLunisolarCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GlobalizationExtensions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GregorianCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GregorianCalendarHelper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GregorianCalendarTypes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\HebrewCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\HebrewNumber.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\HijriCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\IdnMapping.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\InternalGlobalizationHelper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\ISOWeek.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\JapaneseCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\JapaneseLunisolarCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\JulianCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\KoreanCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\KoreanLunisolarCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\NumberFormatInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\NumberStyles.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\PersianCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\RegionInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\SortKey.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\SortVersion.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\StringInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\TaiwanCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\TaiwanLunisolarCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\TextElementEnumerator.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\TextInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\ThaiBuddhistCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\TimeSpanFormat.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\TimeSpanParse.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\TimeSpanStyles.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\UmAlQuraCalendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\UnicodeCategory.cs" />
- <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" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IConvertible.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ICustomFormatter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IDisposable.cs" />
- <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\InsufficientMemoryException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\InvalidCastException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\InvalidOperationException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\InvalidProgramException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\InvalidTimeZoneException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\BinaryReader.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\BinaryWriter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\DirectoryNotFoundException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\EncodingCache.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\EndOfStreamException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\Error.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileAccess.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileLoadException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileMode.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileNotFoundException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileOptions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileShare.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\IOException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\MemoryStream.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\Path.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\PathInternal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\PathTooLongException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\PinnedBufferMemoryStream.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\SeekOrigin.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\Stream.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\StreamHelpers.CopyValidation.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\StreamReader.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\StreamWriter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\TextReader.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\TextWriter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\UnmanagedMemoryAccessor.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\UnmanagedMemoryStream.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\UnmanagedMemoryStreamWrapper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IObservable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IObserver.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IProgress.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ISpanFormattable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Int16.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Int32.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Int64.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IntPtr.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Lazy.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\LocalAppContextSwitches.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\LocalAppContextSwitches.Common.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\LocalDataStoreSlot.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Marvin.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Marvin.OrdinalIgnoreCase.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Math.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MathF.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MarshalByRefObject.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MemberAccessException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Memory.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MemoryDebugView.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MemoryExtensions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MemoryExtensions.Globalization.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MemoryExtensions.Trim.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MethodAccessException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MidpointRounding.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MissingFieldException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MissingMemberException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MissingMethodException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\MulticastNotSupportedException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\NotFiniteNumberException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\NotImplementedException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\NonSerializedAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\NotSupportedException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Nullable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Number.BigInteger.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Number.DiyFp.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Number.Dragon4.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Number.Formatting.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Number.Grisu3.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Number.NumberBuffer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Number.NumberToFloatingPointBits.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Number.Parsing.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\BitOperations.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Matrix3x2.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Matrix4x4.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Plane.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Quaternion.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Vector2.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Vector2_Intrinsics.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Vector3.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Vector3_Intrinsics.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Vector4.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Vector4_Intrinsics.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\VectorMath.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\NullReferenceException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Object.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ObjectDisposedException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ObsoleteAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\OperatingSystem.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\OperationCanceledException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\OutOfMemoryException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\OverflowException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ParamArrayAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ParamsArray.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ParseNumbers.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\PasteArguments.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\PlatformID.cs" />
- <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\ReadOnlyMemory.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AmbiguousMatchException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Assembly.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyAlgorithmIdAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyCompanyAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyConfigurationAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyContentType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyCopyrightAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyCultureAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyDefaultAliasAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyDelaySignAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyDescriptionAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyFileVersionAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyFlagsAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyInformationalVersionAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyKeyFileAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyKeyNameAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyMetadataAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyName.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyNameFlags.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyNameFormatter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyProductAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblySignatureKeyAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyTitleAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyTrademarkAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\AssemblyVersionAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Binder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\BindingFlags.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CallingConventions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ConstructorInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CorElementType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CustomAttributeExtensions.cs" Condition="'$(TargetsCoreRT)' != 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CustomAttributeFormatException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CustomAttributeNamedArgument.cs" Condition="'$(TargetsCoreRT)' != 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CustomAttributeTypedArgument.cs" Condition="'$(TargetsCoreRT)' != 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\DefaultMemberAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\AssemblyBuilderAccess.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\EventToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\FieldToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\FlowControl.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\Label.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\MethodToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\OpCodeType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\OpCodes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\Opcode.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\OperandType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\PEFileKinds.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\PackingSize.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\ParameterToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\PropertyToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\SignatureToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\StackBehaviour.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\StringToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\TypeToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\EventAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\EventInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ExceptionHandlingClause.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ExceptionHandlingClauseOptions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\FieldAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\FieldInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\GenericParameterAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ICustomAttributeProvider.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ImageFileMachine.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\InterfaceMapping.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\IntrospectionExtensions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\InvalidFilterCriteriaException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\IReflect.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\IReflectableType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\LocalVariableInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ManifestResourceInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberFilter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberTypes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodBase.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodBody.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodImplAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodInfo.Internal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Missing.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Module.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ModuleResolveEventHandler.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscateAssemblyAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscationAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ParameterAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ParameterInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ParameterModifier.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Pointer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\PortableExecutableKinds.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ProcessorArchitecture.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\PropertyAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\PropertyInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ReflectionContext.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ReflectionTypeLoadException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ResourceAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ResourceLocation.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\SignatureArrayType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\SignatureByRefType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\SignatureConstructedGenericType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\SignatureGenericMethodParameterType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\SignatureGenericParameterType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\SignatureHasElementType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\SignaturePointerType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\SignatureType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\SignatureTypeExtensions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\StrongNameKeyPair.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TargetException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TargetInvocationException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TargetParameterCountException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeDelegator.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeFilter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ResolveEventArgs.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ResolveEventHandler.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\FastResourceComparer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\FileBasedResourceGroveler.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\IResourceGroveler.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\IResourceReader.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\ManifestBasedResourceGroveler.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\MissingManifestResourceException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\MissingSatelliteAssemblyException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\NeutralResourcesLanguageAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\ResourceFallbackManager.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\ResourceManager.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\ResourceReader.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\ResourceReader.Core.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\ResourceSet.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\ResourceTypeCode.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\RuntimeResourceSet.cs" />
- <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\AsyncIteratorMethodBuilder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncIteratorStateMachineAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncMethodBuilderAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncMethodBuilderCore.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncStateMachineAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncTaskCache.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncTaskMethodBuilder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncTaskMethodBuilderT.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncValueTaskMethodBuilder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncValueTaskMethodBuilderT.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\AsyncVoidMethodBuilder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\CallerArgumentExpressionAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\CallerFilePathAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\CallerLineNumberAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\CallerMemberNameAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\CompilationRelaxations.cs" />
- <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\ConditionalWeakTable.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\ContractHelper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\CustomConstantAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\DateTimeConstantAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\DecimalConstantAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\DefaultDependencyAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\DependencyAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\DisablePrivateReflectionAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\DiscardableAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ExtensionAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\FixedAddressValueTypeAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\FixedBufferAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\FormattableStringFactory.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IAsyncStateMachine.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IAsyncStateMachineBox.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ICastable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IndexerNameAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\INotifyCompletion.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\InternalsVisibleToAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IntrinsicAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsConst.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsByRefLikeAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsVolatile.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IteratorStateMachineAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ITuple.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\LoadHint.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\MethodCodeType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\MethodImplAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\MethodImplOptions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsReadOnlyAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ReferenceAssemblyAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeCompatibilityAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeFeature.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeHelpers.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeWrappedException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\SpecialNameAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\StateMachineAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\StringFreezingAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\StrongBox.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\SuppressIldasmAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TaskAwaiter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TupleElementNamesAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TypeForwardedFromAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TypeForwardedToAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\UnsafeValueTypeAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ValueTaskAwaiter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\YieldAwaitable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\Cer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\Consistency.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\CriticalFinalizerObject.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ConstrainedExecution\ReliabilityContractAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ExceptionServices\ExceptionDispatchInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ExceptionServices\ExceptionNotification.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ExceptionServices\HandleProcessCorruptedStateExceptionsAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IBindCtx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IConnectionPoint.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IConnectionPointContainer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IEnumConnectionPoints.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IEnumConnections.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IEnumMoniker.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IEnumString.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IEnumVARIANT.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IMoniker.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IPersistFile.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IRunningObjectTable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\IStream.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\ITypeComp.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\ITypeInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\ITypeInfo2.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\ITypeLib.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComTypes\ITypeLib2.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\AllowReversePInvokeCallsAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ArrayWithOffset.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\BStrWrapper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\BestFitMappingAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CallingConvention.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\COMException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CharSet.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ClassInterfaceAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ClassInterfaceType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CoClassAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CollectionsMarshal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComDefaultInterfaceAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComEventInterfaceAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComImportAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComInterfaceType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComMemberType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComSourceInterfacesAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComVisibleAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CriticalHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CurrencyWrapper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CustomQueryInterfaceMode.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CustomQueryInterfaceResult.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\DefaultCharSetAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\DefaultDllImportSearchPathsAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\DefaultParameterValueAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\DispatchWrapper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\DispIdAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\DllImportAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\DllImportSearchPath.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ErrorWrapper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ExternalException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\FieldOffsetAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\GuidAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\GCHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\GCHandleType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\HandleRef.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ICustomAdapter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ICustomFactory.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ICustomMarshaler.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ICustomQueryInterface.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\InAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\InvalidComObjectException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\InvalidOleVariantTypeException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\InterfaceTypeAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\LCIDConversionAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\LayoutKind.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Marshal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MarshalAsAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MarshalDirectiveException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MemoryMarshal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NativeCallableAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NativeLibrary.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\OptionalAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\OutAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\PreserveSigAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ProgIdAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SafeArrayRankMismatchException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SafeArrayTypeMismatchException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SafeBuffer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SafeHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SEHException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StructLayoutAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SuppressGCTransitionAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\TypeIdentifierAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnknownWrapper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedFunctionPointerAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\VarEnum.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\VariantWrapper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Vector64.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Vector64_1.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Vector64DebugView_1.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Vector128.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Vector128_1.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Vector128DebugView_1.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Vector256.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Vector256_1.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Vector256DebugView_1.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Enums.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Loader\AssemblyLoadContext.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Loader\LibraryNameVariation.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Remoting\ObjectHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\DeserializationToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\DeserializationTracker.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\IDeserializationCallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\IFormatterConverter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\IObjectReference.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\ISafeSerializationData.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\ISerializable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\OnDeserializedAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\OnDeserializingAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\OnSerializedAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\OnSerializingAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\OptionalFieldAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\SafeSerializationEventArgs.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\SerializationException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\SerializationInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\SerializationInfoEnumerator.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\StreamingContext.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Versioning\NonVersionableAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Versioning\TargetFrameworkAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\AmbiguousImplementationException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\GCSettings.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\MemoryFailPoint.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\RuntimeType.cs" Condition="'$(TargetsCoreRT)' != 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\SByte.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\AllowPartiallyTrustedCallersAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\CryptographicException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\IPermission.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\ISecurityEncodable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\IStackWalk.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\PartialTrustVisibilityLevel.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\PermissionSet.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\Permissions\PermissionState.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\Principal\IIdentity.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\Principal\IPrincipal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\Principal\PrincipalPolicy.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecurityCriticalAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecurityCriticalScope.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecurityElement.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecurityException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecurityRulesAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecurityRuleSet.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecuritySafeCriticalAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecurityTransparentAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecurityTreatAsSafeAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SuppressUnmanagedCodeSecurityAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\UnverifiableCodeAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\VerificationException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\SerializableAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Single.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Span.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\SpanDebugView.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\SpanHelpers.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\SpanHelpers.BinarySearch.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\SpanHelpers.Byte.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\SpanHelpers.Char.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\SpanHelpers.T.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\String.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\String.Comparison.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\String.Manipulation.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\String.Searching.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\StackOverflowException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\StringComparer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\StringComparison.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\StringSplitOptions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\SystemException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\ASCIIEncoding.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\ASCIIUtility.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\ASCIIUtility.Helpers.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\StringBuilderCache.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\CodePageDataItem.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Decoder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\DecoderNLS.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\DecoderBestFitFallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\DecoderExceptionFallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\DecoderFallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\DecoderReplacementFallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Encoder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncoderNLS.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncoderBestFitFallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncoderExceptionFallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncoderFallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncoderReplacementFallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Encoding.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Encoding.Internal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncodingData.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncodingInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncodingNLS.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncodingProvider.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\EncodingTable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Latin1Encoding.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\NormalizationForm.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Rune.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\SpanRuneEnumerator.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\StringBuilder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\StringBuilder.Debug.cs" Condition="'$(Configuration)' == 'Debug'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\StringRuneEnumerator.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\TrimType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\UnicodeDebug.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\UnicodeEncoding.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\UnicodeUtility.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\UTF32Encoding.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\UTF7Encoding.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\UTF8Encoding.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\UTF8Encoding.Sealed.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\ValueStringBuilder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\ValueStringBuilder.AppendFormat.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Unicode\Utf16Utility.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Unicode\Utf16Utility.Validation.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Unicode\Utf8.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Unicode\Utf8Utility.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Unicode\Utf8Utility.Helpers.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Unicode\Utf8Utility.Transcoding.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Unicode\Utf8Utility.Validation.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Text\Unicode\Utf8Utility.WhiteSpace.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeSpan.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ThreadAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\AbandonedMutexException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ApartmentState.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\AsyncLocal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\AutoResetEvent.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\CancellationToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\CancellationTokenRegistration.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\CancellationTokenSource.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\CompressedStack.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\DeferredDisposableLifetime.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\EventResetMode.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\EventWaitHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ExecutionContext.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\IOCompletionCallback.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" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ManualResetEvent.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ManualResetEventSlim.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Mutex.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\NativeOverlapped.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ParameterizedThreadStart.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ReaderWriterLockSlim.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Semaphore.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SemaphoreFullException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SemaphoreSlim.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SendOrPostCallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SpinLock.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SpinWait.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SynchronizationContext.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SynchronizationLockException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Thread.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadLocal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Volatile.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\AsyncCausalityTracerConstants.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\ConcurrentExclusiveSchedulerPair.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\Future.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\FutureFactory.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\ProducerConsumerQueues.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\Task.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskAsyncEnumerableExtensions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskCanceledException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskCompletionSource.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskContinuation.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskExceptionHolder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskExtensions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskFactory.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskToApm.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskScheduler.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskSchedulerException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\ThreadPoolTaskScheduler.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TplEventSource.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\ThreadInterruptedException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadPool.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadPriority.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadStart.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadStartException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadState.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadStateException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Timeout.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\TimeoutHelper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Timer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\TimerQueue.Portable.cs" Condition="'$(FeaturePortableTimer)' == 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\WaitHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\WaitHandleCannotBeOpenedException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ThreadStaticAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\ThrowHelper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeoutException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeZone.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.AdjustmentRule.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.StringSerializer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.TransitionTime.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneNotFoundException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Tuple.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TupleExtensions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Type.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Type.Enum.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Type.Helpers.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TypeAccessException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TypeCode.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TypeInitializationException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TypeLoadException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TypeUnloadedException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\UInt16.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\UInt32.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\UInt64.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\UIntPtr.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\UnauthorizedAccessException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\UnhandledExceptionEventArgs.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\UnhandledExceptionEventHandler.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\UnitySerializationHolder.cs"/>
- <Compile Include="$(MSBuildThisFileDirectory)System\ValueTuple.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Version.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Void.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\WeakReference.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\WeakReference.T.cs" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.ActivityControl.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.EtwEnableCallback.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.EVENT_INFO_CLASS.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\ActivityTracker.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\DiagnosticCounter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\CounterGroup.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\CounterPayload.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventActivityOptions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventCounter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventDescriptor.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventProvider.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventSource.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventSourceException.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\FrameworkEventSource.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\IEventProvider.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\IncrementingEventCounter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\IncrementingPollingCounter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\PollingCounter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\StubEnvironment.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\Winmeta.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\ArrayTypeInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\ConcurrentSet.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\ConcurrentSetItem.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\DataCollector.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\EmptyStruct.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\EnumerableTypeInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\EnumHelper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\EventDataAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\EventFieldAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\EventFieldFormat.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\EventIgnoreAttribute.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\EventPayload.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\EventSourceActivity.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\EventSourceOptions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\FieldMetadata.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\InvokeTypeInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\NameInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\PropertyAnalysis.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\PropertyValue.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\SimpleEventTypes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\SimpleTypeInfos.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\Statics.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\TraceLoggingDataCollector.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\TraceLoggingDataType.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\TraceLoggingEventSource.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\TraceLoggingEventTraits.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\TraceLoggingEventTypes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\TraceLoggingMetadataCollector.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\TraceLoggingTypeInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\TypeAnalysis.cs" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\ConstantHelper.cs">
- <AutoGen>True</AutoGen>
- <DesignTime>True</DesignTime>
- <DependentUpon>ConstantHelper.tt</DependentUpon>
- </Compile>
- <Content Include="$(MSBuildThisFileDirectory)System\Numerics\ConstantHelper.tt">
- <Generator>TextTemplatingFileGenerator</Generator>
- <LastGenOutput>ConstantHelper.cs</LastGenOutput>
- </Content>
- <None Include="$(MSBuildThisFileDirectory)System\Numerics\GenerationConfig.ttinclude" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Register.cs">
- <AutoGen>True</AutoGen>
- <DesignTime>True</DesignTime>
- <DependentUpon>Register.tt</DependentUpon>
- </Compile>
- <Content Include="$(MSBuildThisFileDirectory)System\Numerics\Register.tt">
- <Generator>TextTemplatingFileGenerator</Generator>
- <LastGenOutput>Register.cs</LastGenOutput>
- </Content>
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Vector.cs">
- <AutoGen>True</AutoGen>
- <DesignTime>True</DesignTime>
- <DependentUpon>Vector.tt</DependentUpon>
- </Compile>
- <Content Include="$(MSBuildThisFileDirectory)System\Numerics\Vector.tt">
- <Generator>TextTemplatingFileGenerator</Generator>
- <LastGenOutput>Vector.cs</LastGenOutput>
- </Content>
- <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Vector_Operations.cs" />
- </ItemGroup>
- <ItemGroup Condition="$(TargetsWindows)">
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.EventActivityIdControl.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.EventRegister.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.EventSetInformation.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.EventTraceGuidsEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.EventUnregister.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.EventWriteString.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.EventWriteTransfer.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.LookupAccountNameW.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\BCrypt\Interop.BCryptGenRandom.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\BCrypt\Interop.BCryptGenRandom.GetRandomBytes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\BCrypt\Interop.NTSTATUS.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Crypt32\Interop.CryptProtectMemory.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Interop.BOOL.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Interop.BOOLEAN.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Interop.Libraries.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CancelIoEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CompletionPort.cs" Condition="'$(FeaturePortableThreadPool)' == 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.ExpandEnvironmentStrings.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FileAttributes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FILE_INFO_BY_HANDLE_CLASS.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FILE_TIME.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FileTimeToSystemTime.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FileTypes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FindClose.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FindFirstFileEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FlushFileBuffers.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GET_FILEEX_INFO_LEVELS.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetComputerName.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetCPInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetCurrentProcessId.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetCurrentProcess_IntPtr.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetCurrentDirectory.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetFileAttributesEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetFileInformationByHandleEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetFileType_SafeHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetFullPathNameW.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetLongPathNameW.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetLogicalDrives.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetProcessMemoryInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetProcessTimes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetSystemDirectoryW.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetSystemInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetSystemTime.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetSystemTimeAsFileTime.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetSystemTimePreciseAsFileTime.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetSystemTimes.cs" Condition="'$(FeaturePerfTracing)' == 'true' OR '$(FeaturePortableThreadPool)' == 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetTempFileNameW.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetTempPathW.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetVersionExW.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.Globalization.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GlobalMemoryStatusEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.IsWow64Process_IntPtr.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.LockFile.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.MAX_PATH.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.MEMORY_BASIC_INFORMATION.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.MEMORYSTATUSEX.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.MultiByteToWideChar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.OutputDebugString.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.QueryPerformanceCounter.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.QueryPerformanceFrequency.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.QueryUnbiasedInterruptTime.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.ReadFile_SafeHandle_IntPtr.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.ReadFile_SafeHandle_NativeOverlapped.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.ResolveLocaleName.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.SECURITY_ATTRIBUTES.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.SecurityOptions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.SetCurrentDirectory.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.SetEndOfFile.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.SetThreadErrorMode.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.SetFilePointerEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.SystemTimeToFileTime.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.SYSTEM_INFO.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.TimeZone.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.TzSpecificLocalTimeToSystemTime.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.VirtualAlloc.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.VirtualFree.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.VirtualQuery.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WIN32_FILE_ATTRIBUTE_DATA.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WIN32_FIND_DATA.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WideCharToMultiByte.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_NativeOverlapped.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Normaliz\Interop.Idna.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Normaliz\Interop.Normalization.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Ole32\Interop.CoCreateGuid.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Secur32\Interop.GetUserNameExW.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Shell32\Interop.SHGetKnownFolderPath.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Internal\IO\File.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeFileHandle.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeFindHandle.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AppDomain.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffer.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DateTime.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Environment.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebugProvider.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Stopwatch.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CalendarData.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CultureInfo.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CompareInfo.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CultureData.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\IdnMapping.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\Normalization.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\TextInfo.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Guid.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStreamCompletionSource.Win32.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\Path.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\PathHelper.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\PathInternal.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\DisableMediaInsertionPrompt.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\PasteArguments.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Loader\LibraryNameVariation.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\MemoryFailPoint.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Marshal.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Thread.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\TimerQueue.Windows.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(FeatureAsyncCausalityTracer)' != 'true'">
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\AsyncCausalityTracer.Noop.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(FeatureCominterop)' != 'true'">
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Marshal.NoCom.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComEventsHelpers.NoCom.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(FeatureCominterop)' == 'true'">
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\WindowsRuntime\EventRegistrationToken.cs" />
- </ItemGroup>
- <ItemGroup Condition="$(TargetsWindows)">
- <Compile Include="$(MSBuildThisFileDirectory)Internal\Win32\RegistryKey.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegCloseKey.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegCreateKeyEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegDeleteKeyEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegDeleteValue.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegEnumKeyEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegEnumValue.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegFlushKey.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegistryConstants.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegOpenKeyEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegQueryValueEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegSetValueEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeRegistryHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeRegistryHandle.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CreateFile.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FreeLibrary.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.LoadLibraryEx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.MUI.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.TimeZone.Registry.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.VerifyVersionExW.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.VerSetConditionMask.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\NtDll\Interop.NtQuerySystemInformation.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\NtDll\Interop.NtQueryInformationFile.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.Constants.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.LoadString.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.SendMessageTimeout.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeLibraryHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DateTime.Win32.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Environment.Win32.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\HijriCalendar.Win32.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\JapaneseCalendar.Win32.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Win32.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Win32.cs" />
- </ItemGroup>
- <ItemGroup Condition="$(TargetsWindows) or '$(FeaturePal)'=='true'">
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeWaitHandle.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Interop.Errors.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysAllocStringLen.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysFreeString.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CloseHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.Constants.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.EventWaitHandle.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetEnvironmentVariable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetEnvironmentStrings.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FreeEnvironmentStrings.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FormatMessage.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.Mutex.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.OSVERSIONINFOEX.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.Semaphore.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.SetEnvironmentVariable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Environment.Variables.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\Win32Marshal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Mutex.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Semaphore.Windows.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\EventWaitHandle.Windows.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(FeatureAppX)' == 'true'">
- <Compile Include="$(MSBuildThisFileDirectory)Internal\Resources\PRIExceptionInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Internal\Resources\WindowsRuntimeResourceManagerBase.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Resources\ResourceManager.Uap.cs" />
- </ItemGroup>
- <ItemGroup Condition="$(TargetsUnix)">
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\Interop.Errors.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\Interop.IOErrors.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\Interop.Libraries.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Globalization.Native\Interop.Calendar.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Globalization.Native\Interop.Casing.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Globalization.Native\Interop.Collation.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Globalization.Native\Interop.ICU.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Globalization.Native\Interop.Idna.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Globalization.Native\Interop.Locale.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Globalization.Native\Interop.Normalization.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Globalization.Native\Interop.ResultCode.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Globalization.Native\Interop.TimeZoneInfo.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Globalization.Native\Interop.Utils.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.Access.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.ChDir.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.Close.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.FLock.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.FSync.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.FTruncate.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.GetCpuUtilization.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.GetCwd.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.GetEUid.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.GetHostName.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.GetPid.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.GetPwUid.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.GetRandomBytes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.GetSystemTimeAsTicks.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.GetTimestamp.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.GetUnixName.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.GetUnixRelease.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.LockFileRegion.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.LSeek.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.MksTemps.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.MountPoints.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.Open.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.OpenFlags.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.PathConf.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.Permissions.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.PosixFAdvise.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.Read.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.ReadDir.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.ReadLink.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.Stat.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.SysConf.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.SysLog.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.Unlink.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.Write.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Internal\IO\File.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeFileHandle.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\AppDomain.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Buffer.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\DateTime.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebugProvider.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Stopwatch.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Environment.NoRegistry.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Environment.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CalendarData.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CompareInfo.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CultureData.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CultureInfo.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\HijriCalendar.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\IdnMapping.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\JapaneseCalendar.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\LocaleData.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\Normalization.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\TextInfo.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Guid.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.OSX.cs" Condition="'$(TargetsOSX)' == 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Linux.cs" Condition="'$(TargetsOSX)' != 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\Path.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\PathInternal.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\PersistedFiles.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\IO\PersistedFiles.Names.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\PasteArguments.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Loader\LibraryNameVariation.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\MemoryFailPoint.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Marshal.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Thread.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\TimerQueue.Unix.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Unix.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(FeatureHardwareIntrinsics)' == 'true' AND ('$(Platform)' == 'x64' OR ('$(Platform)' == 'x86' AND '$(TargetsUnix)' != 'true'))">
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Aes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Avx.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Avx2.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Bmi1.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Bmi2.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Fma.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Lzcnt.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Pclmulqdq.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Popcnt.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Sse.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Sse2.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Sse3.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Sse41.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Sse42.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Ssse3.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(FeatureHardwareIntrinsics)' != 'true' OR ('$(Platform)' != 'x64' AND ('$(Platform)' != 'x86' OR ('$(Platform)' == 'x86' AND '$(TargetsUnix)' == 'true')))">
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Aes.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Avx.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Avx2.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Bmi1.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Bmi2.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Fma.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Lzcnt.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Pclmulqdq.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Popcnt.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Sse.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Sse2.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Sse3.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Sse41.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Sse42.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Ssse3.PlatformNotSupported.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(FeatureHardwareIntrinsics)' == 'true' AND '$(Platform)' == 'arm64'">
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\AdvSimd.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\Aes.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\ArmBase.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\Crc32.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\Sha1.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\Sha256.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(FeatureHardwareIntrinsics)' != 'true' OR '$(Platform)' != 'arm64'">
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\AdvSimd.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\Aes.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\ArmBase.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\Crc32.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\Sha1.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Arm\Sha256.PlatformNotSupported.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(FeaturePortableThreadPool)' == 'true'">
- <Compile Include="$(MSBuildThisFileDirectory)System\AppContextConfigHelper.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadPool.Portable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadPoolBoundHandle.PlatformNotSupported.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPoolEventSource.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.GateThread.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.HillClimbing.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.HillClimbing.Complex.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.ThreadCounts.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.WaitThread.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.WorkerThread.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.CpuUtilizationReader.Unix.cs" Condition="'$(TargetsUnix)' == 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.CpuUtilizationReader.Windows.cs" Condition="'$(TargetsWindows)'=='true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphore.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphore.Windows.cs" Condition="'$(TargetsWindows)'=='true'" />
- </ItemGroup>
- <ItemGroup Condition="'$(FeaturePortableThreadPool)' == 'true' OR '$(FeatureThreadInt64PersistentCounter)' == 'true'">
- <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadInt64PersistentCounter.cs" />
- </ItemGroup>
-</Project>
diff --git a/netcore/System.Private.CoreLib/shared/System/AccessViolationException.cs b/netcore/System.Private.CoreLib/shared/System/AccessViolationException.cs
deleted file mode 100644
index 800142d9f3d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AccessViolationException.cs
+++ /dev/null
@@ -1,50 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class representing an AV that was deemed unsafe and may have corrupted the application.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class AccessViolationException : SystemException
- {
- public AccessViolationException()
- : base(SR.Arg_AccessViolationException)
- {
- HResult = HResults.E_POINTER;
- }
-
- public AccessViolationException(string? message)
- : base(message)
- {
- HResult = HResults.E_POINTER;
- }
-
- public AccessViolationException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.E_POINTER;
- }
-
- protected AccessViolationException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
-
-#pragma warning disable CA1823, 169 // Field is not used from managed.
- private IntPtr _ip; // Address of faulting instruction.
- private IntPtr _target; // Address that could not be accessed.
- private int _accessType; // 0:read, 1:write
-#pragma warning restore CA1823, 169
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Action.cs b/netcore/System.Private.CoreLib/shared/System/Action.cs
deleted file mode 100644
index 54ca7aaf532..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Action.cs
+++ /dev/null
@@ -1,40 +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.
-
-namespace System
-{
- public delegate void Action();
- public delegate void Action<in T>(T obj);
- public delegate void Action<in T1, in T2>(T1 arg1, T2 arg2);
- public delegate void Action<in T1, in T2, in T3>(T1 arg1, T2 arg2, T3 arg3);
- public delegate void Action<in T1, in T2, in T3, in T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
- public delegate void Action<in T1, in T2, in T3, in T4, in T5>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
- public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
- public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);
- public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);
-
- public delegate TResult Func<out TResult>();
- public delegate TResult Func<in T, out TResult>(T arg);
- public delegate TResult Func<in T1, in T2, out TResult>(T1 arg1, T2 arg2);
- public delegate TResult Func<in T1, in T2, in T3, out TResult>(T1 arg1, T2 arg2, T3 arg3);
- public delegate TResult Func<in T1, in T2, in T3, in T4, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
- public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
- public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
- public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);
- public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);
-
- public delegate int Comparison<in T>(T x, T y);
-
- public delegate TOutput Converter<in TInput, out TOutput>(TInput input);
-
- public delegate bool Predicate<in T>(T obj);
-}
-
-namespace System.Buffers
-{
- public delegate void SpanAction<T, in TArg>(Span<T> span, TArg arg);
- public delegate void ReadOnlySpanAction<T, in TArg>(ReadOnlySpan<T> span, TArg arg);
-
- internal delegate TResult SpanFunc<TSpan, in T1, in T2, in T3, out TResult>(Span<TSpan> span, T1 arg1, T2 arg2, T3 arg3);
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs b/netcore/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs
deleted file mode 100644
index a679e60bbce..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs
+++ /dev/null
@@ -1,147 +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 System.Reflection;
-using System.Globalization;
-using System.Runtime.Loader;
-using System.Runtime.Remoting;
-using System.Threading;
-
-namespace System
-{
- public static partial class Activator
- {
- public static object? CreateInstance(Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture, object?[]? activationAttributes)
- {
- if (type is null)
- throw new ArgumentNullException(nameof(type));
-
- if (type is System.Reflection.Emit.TypeBuilder)
- throw new NotSupportedException(SR.NotSupported_CreateInstanceWithTypeBuilder);
-
- // If they didn't specify a lookup, then we will provide the default lookup.
- const int LookupMask = 0x000000FF;
- if ((bindingAttr & (BindingFlags)LookupMask) == 0)
- bindingAttr |= ConstructorDefault;
-
- if (activationAttributes?.Length > 0)
- throw new PlatformNotSupportedException(SR.NotSupported_ActivAttr);
-
- if (type.UnderlyingSystemType is RuntimeType rt)
- return rt.CreateInstanceImpl(bindingAttr, binder, args, culture);
-
- throw new ArgumentException(SR.Arg_MustBeType, nameof(type));
- }
-
- [System.Security.DynamicSecurityMethod]
- public static ObjectHandle? CreateInstance(string assemblyName, string typeName)
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return CreateInstanceInternal(assemblyName,
- typeName,
- false,
- ConstructorDefault,
- null,
- null,
- null,
- null,
- ref stackMark);
- }
-
- [System.Security.DynamicSecurityMethod]
- public static ObjectHandle? CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture, object?[]? activationAttributes)
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return CreateInstanceInternal(assemblyName,
- typeName,
- ignoreCase,
- bindingAttr,
- binder,
- args,
- culture,
- activationAttributes,
- ref stackMark);
- }
-
- [System.Security.DynamicSecurityMethod]
- public static ObjectHandle? CreateInstance(string assemblyName, string typeName, object?[]? activationAttributes)
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return CreateInstanceInternal(assemblyName,
- typeName,
- false,
- ConstructorDefault,
- null,
- null,
- null,
- activationAttributes,
- ref stackMark);
- }
-
- public static object? CreateInstance(Type type, bool nonPublic) =>
- CreateInstance(type, nonPublic, wrapExceptions: true);
-
- internal static object? CreateInstance(Type type, bool nonPublic, bool wrapExceptions)
- {
- if (type is null)
- throw new ArgumentNullException(nameof(type));
-
- if (type.UnderlyingSystemType is RuntimeType rt)
- return rt.CreateInstanceDefaultCtor(publicOnly: !nonPublic, skipCheckThis: false, fillCache: true, wrapExceptions: wrapExceptions);
-
- throw new ArgumentException(SR.Arg_MustBeType, nameof(type));
- }
-
- private static ObjectHandle? CreateInstanceInternal(string assemblyString,
- string typeName,
- bool ignoreCase,
- BindingFlags bindingAttr,
- Binder? binder,
- object?[]? args,
- CultureInfo? culture,
- object?[]? activationAttributes,
- ref StackCrawlMark stackMark)
- {
- Type? type = null;
- Assembly? assembly = null;
- if (assemblyString == null)
- {
- assembly = Assembly.GetExecutingAssembly(ref stackMark);
- }
- else
- {
- AssemblyName assemblyName = new AssemblyName(assemblyString);
-
- if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
- {
- // WinRT type - we have to use Type.GetType
- type = Type.GetType(typeName + ", " + assemblyString, throwOnError: true, ignoreCase);
- }
- else
- {
- // Classic managed type
- assembly = RuntimeAssembly.InternalLoadAssemblyName(
- assemblyName, ref stackMark, AssemblyLoadContext.CurrentContextualReflectionContext);
- }
- }
-
- if (type == null)
- {
- type = assembly!.GetType(typeName, throwOnError: true, ignoreCase);
- }
-
- object? o = CreateInstance(type!, bindingAttr, binder, args, culture, activationAttributes);
-
- return o != null ? new ObjectHandle(o) : null;
- }
-
- [System.Runtime.CompilerServices.Intrinsic]
- public static T CreateInstance<T>()
- {
- return (T)((RuntimeType)typeof(T)).CreateInstanceDefaultCtor(publicOnly: true, skipCheckThis: true, fillCache: true, wrapExceptions: true);
- }
-
- private static T CreateDefaultInstance<T>() where T : struct => default;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Activator.cs b/netcore/System.Private.CoreLib/shared/System/Activator.cs
deleted file mode 100644
index 0426211c763..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Activator.cs
+++ /dev/null
@@ -1,55 +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 System.Diagnostics;
-using System.Globalization;
-using System.Reflection;
-using System.Runtime.Remoting;
-
-namespace System
-{
- /// <summary>
- /// Activator contains the Activation (CreateInstance/New) methods for late bound support.
- /// </summary>
- public static partial class Activator
- {
- private const BindingFlags ConstructorDefault = BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance;
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static object? CreateInstance(Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture) =>
- CreateInstance(type, bindingAttr, binder, args, culture, null);
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static object? CreateInstance(Type type, params object?[]? args) =>
- CreateInstance(type, ConstructorDefault, null, args, null, null);
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static object? CreateInstance(Type type, object?[]? args, object?[]? activationAttributes) =>
- CreateInstance(type, ConstructorDefault, null, args, null, activationAttributes);
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static object? CreateInstance(Type type) =>
- CreateInstance(type, nonPublic: false);
-
- public static ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName) =>
- CreateInstanceFrom(assemblyFile, typeName, false, ConstructorDefault, null, null, null, null);
-
- public static ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName, object?[]? activationAttributes) =>
- CreateInstanceFrom(assemblyFile, typeName, false, ConstructorDefault, null, null, null, activationAttributes);
-
- public static ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture, object?[]? activationAttributes)
- {
- Assembly assembly = Assembly.LoadFrom(assemblyFile);
- Type t = assembly.GetType(typeName, throwOnError: true, ignoreCase)!;
-
- object? o = CreateInstance(t, bindingAttr, binder, args, culture, activationAttributes);
-
- return o != null ? new ObjectHandle(o) : null;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AggregateException.cs b/netcore/System.Private.CoreLib/shared/System/AggregateException.cs
deleted file mode 100644
index 46baebfddd6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AggregateException.cs
+++ /dev/null
@@ -1,467 +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 System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.Globalization;
-using System.Runtime.ExceptionServices;
-using System.Runtime.Serialization;
-using System.Text;
-
-namespace System
-{
- /// <summary>Represents one or more errors that occur during application execution.</summary>
- /// <remarks>
- /// <see cref="AggregateException"/> is used to consolidate multiple failures into a single, throwable
- /// exception object.
- /// </remarks>
- [Serializable]
- [DebuggerDisplay("Count = {InnerExceptionCount}")]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class AggregateException : Exception
- {
- private readonly ReadOnlyCollection<Exception> m_innerExceptions; // Complete set of exceptions. Do not rename (binary serialization)
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AggregateException"/> class.
- /// </summary>
- public AggregateException()
- : base(SR.AggregateException_ctor_DefaultMessage)
- {
- m_innerExceptions = new ReadOnlyCollection<Exception>(Array.Empty<Exception>());
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AggregateException"/> class with
- /// a specified error message.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- public AggregateException(string? message)
- : base(message)
- {
- m_innerExceptions = new ReadOnlyCollection<Exception>(Array.Empty<Exception>());
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AggregateException"/> class with a specified error
- /// message and a reference to the inner exception that is the cause of this exception.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- /// <param name="innerException">The exception that is the cause of the current exception.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="innerException"/> argument
- /// is null.</exception>
- public AggregateException(string? message, Exception innerException)
- : base(message, innerException)
- {
- if (innerException == null)
- {
- throw new ArgumentNullException(nameof(innerException));
- }
-
- m_innerExceptions = new ReadOnlyCollection<Exception>(new Exception[] { innerException });
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AggregateException"/> class with
- /// references to the inner exceptions that are the cause of this exception.
- /// </summary>
- /// <param name="innerExceptions">The exceptions that are the cause of the current exception.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="innerExceptions"/> argument
- /// is null.</exception>
- /// <exception cref="System.ArgumentException">An element of <paramref name="innerExceptions"/> is
- /// null.</exception>
- public AggregateException(IEnumerable<Exception> innerExceptions) :
- this(SR.AggregateException_ctor_DefaultMessage, innerExceptions)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AggregateException"/> class with
- /// references to the inner exceptions that are the cause of this exception.
- /// </summary>
- /// <param name="innerExceptions">The exceptions that are the cause of the current exception.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="innerExceptions"/> argument
- /// is null.</exception>
- /// <exception cref="System.ArgumentException">An element of <paramref name="innerExceptions"/> is
- /// null.</exception>
- public AggregateException(params Exception[] innerExceptions) :
- this(SR.AggregateException_ctor_DefaultMessage, innerExceptions)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AggregateException"/> class with a specified error
- /// message and references to the inner exceptions that are the cause of this exception.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- /// <param name="innerExceptions">The exceptions that are the cause of the current exception.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="innerExceptions"/> argument
- /// is null.</exception>
- /// <exception cref="System.ArgumentException">An element of <paramref name="innerExceptions"/> is
- /// null.</exception>
- public AggregateException(string? message, IEnumerable<Exception> innerExceptions)
- // If it's already an IList, pass that along (a defensive copy will be made in the delegated ctor). If it's null, just pass along
- // null typed correctly. Otherwise, create an IList from the enumerable and pass that along.
- : this(message, innerExceptions as IList<Exception> ?? (innerExceptions == null ? (List<Exception>)null! : new List<Exception>(innerExceptions)))
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AggregateException"/> class with a specified error
- /// message and references to the inner exceptions that are the cause of this exception.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- /// <param name="innerExceptions">The exceptions that are the cause of the current exception.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="innerExceptions"/> argument
- /// is null.</exception>
- /// <exception cref="System.ArgumentException">An element of <paramref name="innerExceptions"/> is
- /// null.</exception>
- public AggregateException(string? message, params Exception[] innerExceptions) :
- this(message, (IList<Exception>)innerExceptions)
- {
- }
-
- /// <summary>
- /// Allocates a new aggregate exception with the specified message and list of inner exceptions.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- /// <param name="innerExceptions">The exceptions that are the cause of the current exception.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="innerExceptions"/> argument
- /// is null.</exception>
- /// <exception cref="System.ArgumentException">An element of <paramref name="innerExceptions"/> is
- /// null.</exception>
- private AggregateException(string? message, IList<Exception> innerExceptions)
- : base(message, innerExceptions != null && innerExceptions.Count > 0 ? innerExceptions[0] : null)
- {
- if (innerExceptions == null)
- {
- throw new ArgumentNullException(nameof(innerExceptions));
- }
-
- // Copy exceptions to our internal array and validate them. We must copy them,
- // because we're going to put them into a ReadOnlyCollection which simply reuses
- // the list passed in to it. We don't want callers subsequently mutating.
- Exception[] exceptionsCopy = new Exception[innerExceptions.Count];
-
- for (int i = 0; i < exceptionsCopy.Length; i++)
- {
- exceptionsCopy[i] = innerExceptions[i];
-
- if (exceptionsCopy[i] == null)
- {
- throw new ArgumentException(SR.AggregateException_ctor_InnerExceptionNull);
- }
- }
-
- m_innerExceptions = new ReadOnlyCollection<Exception>(exceptionsCopy);
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AggregateException"/> class with
- /// references to the inner exception dispatch info objects that represent the cause of this exception.
- /// </summary>
- /// <param name="innerExceptionInfos">
- /// Information about the exceptions that are the cause of the current exception.
- /// </param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="innerExceptionInfos"/> argument
- /// is null.</exception>
- /// <exception cref="System.ArgumentException">An element of <paramref name="innerExceptionInfos"/> is
- /// null.</exception>
- internal AggregateException(IEnumerable<ExceptionDispatchInfo> innerExceptionInfos) :
- this(SR.AggregateException_ctor_DefaultMessage, innerExceptionInfos)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AggregateException"/> class with a specified error
- /// message and references to the inner exception dispatch info objects that represent the cause of
- /// this exception.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- /// <param name="innerExceptionInfos">
- /// Information about the exceptions that are the cause of the current exception.
- /// </param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="innerExceptionInfos"/> argument
- /// is null.</exception>
- /// <exception cref="System.ArgumentException">An element of <paramref name="innerExceptionInfos"/> is
- /// null.</exception>
- internal AggregateException(string message, IEnumerable<ExceptionDispatchInfo> innerExceptionInfos)
- // If it's already an IList, pass that along (a defensive copy will be made in the delegated ctor). If it's null, just pass along
- // null typed correctly. Otherwise, create an IList from the enumerable and pass that along.
- : this(message, innerExceptionInfos as IList<ExceptionDispatchInfo> ??
- (innerExceptionInfos == null ?
- (List<ExceptionDispatchInfo>)null! :
- new List<ExceptionDispatchInfo>(innerExceptionInfos)))
- {
- }
-
- /// <summary>
- /// Allocates a new aggregate exception with the specified message and list of inner
- /// exception dispatch info objects.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- /// <param name="innerExceptionInfos">
- /// Information about the exceptions that are the cause of the current exception.
- /// </param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="innerExceptionInfos"/> argument
- /// is null.</exception>
- /// <exception cref="System.ArgumentException">An element of <paramref name="innerExceptionInfos"/> is
- /// null.</exception>
- private AggregateException(string message, IList<ExceptionDispatchInfo> innerExceptionInfos)
- : base(message, innerExceptionInfos != null && innerExceptionInfos.Count > 0 && innerExceptionInfos[0] != null ?
- innerExceptionInfos[0].SourceException : null)
- {
- if (innerExceptionInfos == null)
- {
- throw new ArgumentNullException(nameof(innerExceptionInfos));
- }
-
- // Copy exceptions to our internal array and validate them. We must copy them,
- // because we're going to put them into a ReadOnlyCollection which simply reuses
- // the list passed in to it. We don't want callers subsequently mutating.
- Exception[] exceptionsCopy = new Exception[innerExceptionInfos.Count];
-
- for (int i = 0; i < exceptionsCopy.Length; i++)
- {
- ExceptionDispatchInfo edi = innerExceptionInfos[i];
- if (edi != null) exceptionsCopy[i] = edi.SourceException;
-
- if (exceptionsCopy[i] == null)
- {
- throw new ArgumentException(SR.AggregateException_ctor_InnerExceptionNull);
- }
- }
-
- m_innerExceptions = new ReadOnlyCollection<Exception>(exceptionsCopy);
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AggregateException"/> class with serialized data.
- /// </summary>
- /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/> that holds
- /// the serialized object data about the exception being thrown.</param>
- /// <param name="context">The <see cref="System.Runtime.Serialization.StreamingContext"/> that
- /// contains contextual information about the source or destination. </param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="info"/> argument is null.</exception>
- /// <exception cref="System.Runtime.Serialization.SerializationException">The exception could not be deserialized correctly.</exception>
- protected AggregateException(SerializationInfo info, StreamingContext context) :
- base(info, context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- Exception[]? innerExceptions = info.GetValue("InnerExceptions", typeof(Exception[])) as Exception[];
- if (innerExceptions is null)
- {
- throw new SerializationException(SR.AggregateException_DeserializationFailure);
- }
-
- m_innerExceptions = new ReadOnlyCollection<Exception>(innerExceptions);
- }
-
- /// <summary>
- /// Sets the <see cref="System.Runtime.Serialization.SerializationInfo"/> with information about
- /// the exception.
- /// </summary>
- /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/> that holds
- /// the serialized object data about the exception being thrown.</param>
- /// <param name="context">The <see cref="System.Runtime.Serialization.StreamingContext"/> that
- /// contains contextual information about the source or destination. </param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="info"/> argument is null.</exception>
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
-
- Exception[] innerExceptions = new Exception[m_innerExceptions.Count];
- m_innerExceptions.CopyTo(innerExceptions, 0);
- info.AddValue("InnerExceptions", innerExceptions, typeof(Exception[]));
- }
-
- /// <summary>
- /// Returns the <see cref="System.AggregateException"/> that is the root cause of this exception.
- /// </summary>
- public override Exception GetBaseException()
- {
- // Returns the first inner AggregateException that contains more or less than one inner exception
-
- // Recursively traverse the inner exceptions as long as the inner exception of type AggregateException and has only one inner exception
- Exception? back = this;
- AggregateException? backAsAggregate = this;
- while (backAsAggregate != null && backAsAggregate.InnerExceptions.Count == 1)
- {
- back = back!.InnerException;
- backAsAggregate = back as AggregateException;
- }
- return back!;
- }
-
- /// <summary>
- /// Gets a read-only collection of the <see cref="System.Exception"/> instances that caused the
- /// current exception.
- /// </summary>
- public ReadOnlyCollection<Exception> InnerExceptions => m_innerExceptions;
-
-
- /// <summary>
- /// Invokes a handler on each <see cref="System.Exception"/> contained by this <see
- /// cref="AggregateException"/>.
- /// </summary>
- /// <param name="predicate">The predicate to execute for each exception. The predicate accepts as an
- /// argument the <see cref="System.Exception"/> to be processed and returns a Boolean to indicate
- /// whether the exception was handled.</param>
- /// <remarks>
- /// Each invocation of the <paramref name="predicate"/> returns true or false to indicate whether the
- /// <see cref="System.Exception"/> was handled. After all invocations, if any exceptions went
- /// unhandled, all unhandled exceptions will be put into a new <see cref="AggregateException"/>
- /// which will be thrown. Otherwise, the <see cref="Handle"/> method simply returns. If any
- /// invocations of the <paramref name="predicate"/> throws an exception, it will halt the processing
- /// of any more exceptions and immediately propagate the thrown exception as-is.
- /// </remarks>
- /// <exception cref="AggregateException">An exception contained by this <see
- /// cref="AggregateException"/> was not handled.</exception>
- /// <exception cref="System.ArgumentNullException">The <paramref name="predicate"/> argument is
- /// null.</exception>
- public void Handle(Func<Exception, bool> predicate)
- {
- if (predicate == null)
- {
- throw new ArgumentNullException(nameof(predicate));
- }
-
- List<Exception>? unhandledExceptions = null;
- for (int i = 0; i < m_innerExceptions.Count; i++)
- {
- // If the exception was not handled, lazily allocate a list of unhandled
- // exceptions (to be rethrown later) and add it.
- if (!predicate(m_innerExceptions[i]))
- {
- unhandledExceptions ??= new List<Exception>();
- unhandledExceptions.Add(m_innerExceptions[i]);
- }
- }
-
- // If there are unhandled exceptions remaining, throw them.
- if (unhandledExceptions != null)
- {
- throw new AggregateException(Message, unhandledExceptions);
- }
- }
-
-
- /// <summary>
- /// Flattens the inner instances of <see cref="AggregateException"/> by expanding its contained <see cref="Exception"/> instances
- /// into a new <see cref="AggregateException"/>
- /// </summary>
- /// <returns>A new, flattened <see cref="AggregateException"/>.</returns>
- /// <remarks>
- /// If any inner exceptions are themselves instances of
- /// <see cref="AggregateException"/>, this method will recursively flatten all of them. The
- /// inner exceptions returned in the new <see cref="AggregateException"/>
- /// will be the union of all of the inner exceptions from exception tree rooted at the provided
- /// <see cref="AggregateException"/> instance.
- /// </remarks>
- public AggregateException Flatten()
- {
- // Initialize a collection to contain the flattened exceptions.
- List<Exception> flattenedExceptions = new List<Exception>();
-
- // Create a list to remember all aggregates to be flattened, this will be accessed like a FIFO queue
- var exceptionsToFlatten = new List<AggregateException> { this };
- int nDequeueIndex = 0;
-
- // Continue removing and recursively flattening exceptions, until there are no more.
- while (exceptionsToFlatten.Count > nDequeueIndex)
- {
- // dequeue one from exceptionsToFlatten
- IList<Exception> currentInnerExceptions = exceptionsToFlatten[nDequeueIndex++].InnerExceptions;
-
- for (int i = 0; i < currentInnerExceptions.Count; i++)
- {
- Exception currentInnerException = currentInnerExceptions[i];
-
- if (currentInnerException == null)
- {
- continue;
- }
-
- // If this exception is an aggregate, keep it around for later. Otherwise,
- // simply add it to the list of flattened exceptions to be returned.
- if (currentInnerException is AggregateException currentInnerAsAggregate)
- {
- exceptionsToFlatten.Add(currentInnerAsAggregate);
- }
- else
- {
- flattenedExceptions.Add(currentInnerException);
- }
- }
- }
-
-
- return new AggregateException(Message, flattenedExceptions);
- }
-
- /// <summary>Gets a message that describes the exception.</summary>
- public override string Message
- {
- get
- {
- if (m_innerExceptions.Count == 0)
- {
- return base.Message;
- }
-
- StringBuilder sb = StringBuilderCache.Acquire();
- sb.Append(base.Message);
- sb.Append(' ');
- for (int i = 0; i < m_innerExceptions.Count; i++)
- {
- sb.Append('(');
- sb.Append(m_innerExceptions[i].Message);
- sb.Append(") ");
- }
- sb.Length--;
- return StringBuilderCache.GetStringAndRelease(sb);
- }
- }
-
- /// <summary>
- /// Creates and returns a string representation of the current <see cref="AggregateException"/>.
- /// </summary>
- /// <returns>A string representation of the current exception.</returns>
- public override string ToString()
- {
- StringBuilder text = new StringBuilder();
- text.Append(base.ToString());
-
- for (int i = 0; i < m_innerExceptions.Count; i++)
- {
- if (m_innerExceptions[i] == InnerException)
- continue; // Already logged in base.ToString()
-
- text.Append(Environment.NewLineConst + InnerExceptionPrefix);
- text.AppendFormat(CultureInfo.InvariantCulture, SR.AggregateException_InnerException, i);
- text.Append(m_innerExceptions[i].ToString());
- text.Append("<---");
- text.AppendLine();
- }
-
- return text.ToString();
- }
-
- /// <summary>
- /// This helper property is used by the DebuggerDisplay.
- ///
- /// Note that we don't want to remove this property and change the debugger display to {InnerExceptions.Count}
- /// because DebuggerDisplay should be a single property access or parameterless method call, so that the debugger
- /// can use a fast path without using the expression evaluator.
- ///
- /// See https://docs.microsoft.com/en-us/visualstudio/debugger/using-the-debuggerdisplay-attribute
- /// </summary>
- private int InnerExceptionCount => InnerExceptions.Count;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AppContext.cs b/netcore/System.Private.CoreLib/shared/System/AppContext.cs
deleted file mode 100644
index c79e8ee9f96..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AppContext.cs
+++ /dev/null
@@ -1,156 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Reflection;
-using System.Runtime.ExceptionServices;
-using System.Runtime.Loader;
-using System.Runtime.Versioning;
-using System.Threading;
-
-namespace System
-{
- public static partial class AppContext
- {
- private static Dictionary<string, object?>? s_dataStore;
- private static Dictionary<string, bool>? s_switches;
- private static string? s_defaultBaseDirectory;
-
- public static string BaseDirectory =>
- // The value of APP_CONTEXT_BASE_DIRECTORY key has to be a string and it is not allowed to be any other type.
- // Otherwise the caller will get invalid cast exception
- (string?)GetData("APP_CONTEXT_BASE_DIRECTORY") ??
- (s_defaultBaseDirectory ??= GetBaseDirectoryCore());
-
- public static string? TargetFrameworkName =>
- // The Target framework is not the framework that the process is actually running on.
- // It is the value read from the TargetFrameworkAttribute on the .exe that started the process.
- Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName;
-
- public static object? GetData(string name)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- if (s_dataStore == null)
- return null;
-
- object? data;
- lock (s_dataStore)
- {
- s_dataStore.TryGetValue(name, out data);
- }
- return data;
- }
-
- public static void SetData(string name, object? data)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- if (s_dataStore == null)
- {
- Interlocked.CompareExchange(ref s_dataStore, new Dictionary<string, object?>(), null);
- }
-
- lock (s_dataStore)
- {
- s_dataStore[name] = data;
- }
- }
-
-#pragma warning disable CS0067 // events raised by the VM
- public static event UnhandledExceptionEventHandler? UnhandledException;
-
- public static event System.EventHandler<FirstChanceExceptionEventArgs>? FirstChanceException;
-#pragma warning restore CS0067
-
- public static event System.EventHandler? ProcessExit;
-
- internal static void OnProcessExit()
- {
- AssemblyLoadContext.OnProcessExit();
-
- ProcessExit?.Invoke(AppDomain.CurrentDomain, EventArgs.Empty);
- }
-
- /// <summary>
- /// Try to get the value of the switch.
- /// </summary>
- /// <param name="switchName">The name of the switch</param>
- /// <param name="isEnabled">A variable where to place the value of the switch</param>
- /// <returns>A return value of true represents that the switch was set and <paramref name="isEnabled"/> contains the value of the switch</returns>
- public static bool TryGetSwitch(string switchName, out bool isEnabled)
- {
- if (switchName == null)
- throw new ArgumentNullException(nameof(switchName));
- if (switchName.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(switchName));
-
- if (s_switches != null)
- {
- lock (s_switches)
- {
- if (s_switches.TryGetValue(switchName, out isEnabled))
- return true;
- }
- }
-
- if (GetData(switchName) is string value && bool.TryParse(value, out isEnabled))
- {
- return true;
- }
-
- isEnabled = false;
- return false;
- }
-
- /// <summary>
- /// Assign a switch a value
- /// </summary>
- /// <param name="switchName">The name of the switch</param>
- /// <param name="isEnabled">The value to assign</param>
- public static void SetSwitch(string switchName, bool isEnabled)
- {
- if (switchName == null)
- throw new ArgumentNullException(nameof(switchName));
- if (switchName.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(switchName));
-
- if (s_switches == null)
- {
- // Compatibility switches are rarely used. Initialize the Dictionary lazily
- Interlocked.CompareExchange(ref s_switches, new Dictionary<string, bool>(), null);
- }
-
- lock (s_switches)
- {
- s_switches[switchName] = isEnabled;
- }
- }
-
-#if !CORERT
- internal static unsafe void Setup(char** pNames, char** pValues, int count)
- {
- Debug.Assert(s_dataStore == null, "s_dataStore is not expected to be inited before Setup is called");
- s_dataStore = new Dictionary<string, object?>(count);
- for (int i = 0; i < count; i++)
- {
- s_dataStore.Add(new string(pNames[i]), new string(pValues[i]));
- }
- }
-
- private static string GetBaseDirectoryCore()
- {
- // Fallback path for hosts that do not set APP_CONTEXT_BASE_DIRECTORY explicitly
- string? directory = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
- if (directory != null && !Path.EndsInDirectorySeparator(directory))
- directory += PathInternal.DirectorySeparatorCharAsString;
- return directory ?? string.Empty;
- }
-#endif
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AppContextConfigHelper.cs b/netcore/System.Private.CoreLib/shared/System/AppContextConfigHelper.cs
deleted file mode 100644
index 466e1636a01..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AppContextConfigHelper.cs
+++ /dev/null
@@ -1,88 +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 System.Globalization;
-
-namespace System
-{
- internal static class AppContextConfigHelper
- {
- internal static int GetInt32Config(string configName, int defaultValue, bool allowNegative = true)
- {
- try
- {
- object config = AppContext.GetData(configName);
- int result = defaultValue;
- switch (config)
- {
- case string str:
- if (str.StartsWith("0x"))
- {
- result = Convert.ToInt32(str, 16);
- }
- else if (str.StartsWith("0"))
- {
- result = Convert.ToInt32(str, 8);
- }
- else
- {
- result = int.Parse(str, NumberStyles.AllowLeadingSign, NumberFormatInfo.InvariantInfo);
- }
- break;
- case IConvertible convertible:
- result = convertible.ToInt32(NumberFormatInfo.InvariantInfo);
- break;
- }
- return !allowNegative && result < 0 ? defaultValue : result;
- }
- catch (FormatException)
- {
- return defaultValue;
- }
- catch (OverflowException)
- {
- return defaultValue;
- }
- }
-
-
- internal static short GetInt16Config(string configName, short defaultValue, bool allowNegative = true)
- {
- try
- {
- object config = AppContext.GetData(configName);
- short result = defaultValue;
- switch (config)
- {
- case string str:
- if (str.StartsWith("0x"))
- {
- result = Convert.ToInt16(str, 16);
- }
- else if (str.StartsWith("0"))
- {
- result = Convert.ToInt16(str, 8);
- }
- else
- {
- result = short.Parse(str, NumberStyles.AllowLeadingSign, NumberFormatInfo.InvariantInfo);
- }
- break;
- case IConvertible convertible:
- result = convertible.ToInt16(NumberFormatInfo.InvariantInfo);
- break;
- }
- return !allowNegative && result < 0 ? defaultValue : result;
- }
- catch (FormatException)
- {
- return defaultValue;
- }
- catch (OverflowException)
- {
- return defaultValue;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AppDomain.Unix.cs b/netcore/System.Private.CoreLib/shared/System/AppDomain.Unix.cs
deleted file mode 100644
index 3c1ef889f97..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AppDomain.Unix.cs
+++ /dev/null
@@ -1,26 +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.
-
-namespace System
-{
- public sealed partial class AppDomain
- {
- public TimeSpan MonitoringTotalProcessorTime
- {
- get
- {
- Interop.Sys.ProcessCpuInformation cpuInfo = default;
- Interop.Sys.GetCpuUtilization(ref cpuInfo);
-
- ulong userTime100Nanoseconds = cpuInfo.lastRecordedUserTime / 100; // nanoseconds to 100-nanoseconds
- if (userTime100Nanoseconds > long.MaxValue)
- {
- userTime100Nanoseconds = long.MaxValue;
- }
-
- return new TimeSpan((long)userTime100Nanoseconds);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AppDomain.Windows.cs b/netcore/System.Private.CoreLib/shared/System/AppDomain.Windows.cs
deleted file mode 100644
index 07633273e24..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AppDomain.Windows.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System
-{
- public sealed partial class AppDomain
- {
- public TimeSpan MonitoringTotalProcessorTime =>
- Interop.Kernel32.GetProcessTimes(Interop.Kernel32.GetCurrentProcess(), out _, out _, out _, out long userTime100Nanoseconds) ?
- new TimeSpan(userTime100Nanoseconds) :
- TimeSpan.Zero;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AppDomain.cs b/netcore/System.Private.CoreLib/shared/System/AppDomain.cs
deleted file mode 100644
index 340b34d942f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AppDomain.cs
+++ /dev/null
@@ -1,433 +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.
-
-#pragma warning disable CS0067 // events are declared but not used
-
-using System.Diagnostics;
-using System.IO;
-using System.Reflection;
-using System.Runtime.ExceptionServices;
-using System.Runtime.Loader;
-using System.Runtime.Remoting;
-using System.Security;
-using System.Security.Permissions;
-using System.Security.Principal;
-using System.Threading;
-
-namespace System
-{
- public sealed partial class AppDomain : MarshalByRefObject
- {
- private static readonly AppDomain s_domain = new AppDomain();
- private readonly object _forLock = new object();
- private IPrincipal? _defaultPrincipal;
- private PrincipalPolicy _principalPolicy = PrincipalPolicy.NoPrincipal;
- private Func<IPrincipal>? s_getWindowsPrincipal;
- private Func<IPrincipal>? s_getUnauthenticatedPrincipal;
-
- private AppDomain() { }
-
- public static AppDomain CurrentDomain => s_domain;
-
- public string? BaseDirectory => AppContext.BaseDirectory;
-
- public string? RelativeSearchPath => null;
-
- public AppDomainSetup SetupInformation => new AppDomainSetup();
-
- public PermissionSet PermissionSet => new PermissionSet(PermissionState.Unrestricted);
-
- public event UnhandledExceptionEventHandler? UnhandledException
- {
- add { AppContext.UnhandledException += value; }
- remove { AppContext.UnhandledException -= value; }
- }
-
- public string? DynamicDirectory => null;
-
- [Obsolete("AppDomain.SetDynamicBase has been deprecated. Please investigate the use of AppDomainSetup.DynamicBase instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- public void SetDynamicBase(string? path) { }
-
- public string FriendlyName
- {
- get
- {
- Assembly? assembly = Assembly.GetEntryAssembly();
- return assembly != null ? assembly.GetName().Name! : "DefaultDomain";
- }
- }
-
- public int Id => 1;
-
- public bool IsFullyTrusted => true;
-
- public bool IsHomogenous => true;
-
- public event EventHandler? DomainUnload;
-
- public event EventHandler<FirstChanceExceptionEventArgs>? FirstChanceException
- {
- add { AppContext.FirstChanceException += value; }
- remove { AppContext.FirstChanceException -= value; }
- }
-
- public event EventHandler? ProcessExit
- {
- add { AppContext.ProcessExit += value; }
- remove { AppContext.ProcessExit -= value; }
- }
-
- public string ApplyPolicy(string assemblyName)
- {
- if (assemblyName == null)
- {
- throw new ArgumentNullException(nameof(assemblyName));
- }
- if (assemblyName.Length == 0 || assemblyName[0] == '\0')
- {
- throw new ArgumentException(SR.Argument_StringZeroLength, nameof(assemblyName));
- }
-
- return assemblyName;
- }
-
- public static AppDomain CreateDomain(string friendlyName)
- {
- if (friendlyName == null) throw new ArgumentNullException(nameof(friendlyName));
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_AppDomains);
- }
-
- public int ExecuteAssembly(string assemblyFile) => ExecuteAssembly(assemblyFile, null);
-
- public int ExecuteAssembly(string assemblyFile, string?[]? args)
- {
- if (assemblyFile == null)
- {
- throw new ArgumentNullException(nameof(assemblyFile));
- }
- string fullPath = Path.GetFullPath(assemblyFile);
- Assembly assembly = Assembly.LoadFile(fullPath);
- return ExecuteAssembly(assembly, args);
- }
-
- public int ExecuteAssembly(string assemblyFile, string?[]? args, byte[]? hashValue, Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_CAS); // This api is only meaningful for very specific partial trust/CAS scenarios
- }
-
- private static int ExecuteAssembly(Assembly assembly, string?[]? args)
- {
- MethodInfo? entry = assembly.EntryPoint;
- if (entry == null)
- {
- throw new MissingMethodException(SR.Arg_EntryPointNotFoundException);
- }
-
- object? result = entry.Invoke(
- obj: null,
- invokeAttr: BindingFlags.DoNotWrapExceptions,
- binder: null,
- parameters: entry.GetParameters().Length > 0 ? new object?[] { args } : null,
- culture: null);
-
- return result != null ? (int)result : 0;
- }
-
- public int ExecuteAssemblyByName(AssemblyName assemblyName, params string?[]? args) =>
- ExecuteAssembly(Assembly.Load(assemblyName), args);
-
- public int ExecuteAssemblyByName(string assemblyName) =>
- ExecuteAssemblyByName(assemblyName, null);
-
- public int ExecuteAssemblyByName(string assemblyName, params string?[]? args) =>
- ExecuteAssembly(Assembly.Load(assemblyName), args);
-
- public object? GetData(string name) => AppContext.GetData(name);
-
- public void SetData(string name, object? data) => AppContext.SetData(name, data);
-
- public bool? IsCompatibilitySwitchSet(string value)
- {
- bool result;
- return AppContext.TryGetSwitch(value, out result) ? result : default(bool?);
- }
-
- public bool IsDefaultAppDomain() => true;
-
- public bool IsFinalizingForUnload() => false;
-
- public override string ToString() =>
- SR.AppDomain_Name + FriendlyName + Environment.NewLineConst + SR.AppDomain_NoContextPolicies;
-
- public static void Unload(AppDomain domain)
- {
- if (domain == null)
- {
- throw new ArgumentNullException(nameof(domain));
- }
- throw new CannotUnloadAppDomainException(SR.Arg_PlatformNotSupported);
- }
-
- public Assembly Load(byte[] rawAssembly) => Assembly.Load(rawAssembly);
-
- public Assembly Load(byte[] rawAssembly, byte[]? rawSymbolStore) => Assembly.Load(rawAssembly, rawSymbolStore);
-
- public Assembly Load(AssemblyName assemblyRef) => Assembly.Load(assemblyRef);
-
- public Assembly Load(string assemblyString) => Assembly.Load(assemblyString);
-
- public Assembly[] ReflectionOnlyGetAssemblies() => Array.Empty<Assembly>();
-
- public static bool MonitoringIsEnabled
- {
- get => true;
- set
- {
- if (!value)
- {
- throw new ArgumentException(SR.Arg_MustBeTrue);
- }
- }
- }
-
- public long MonitoringSurvivedMemorySize => MonitoringSurvivedProcessMemorySize;
-
- public static long MonitoringSurvivedProcessMemorySize
- {
- get
- {
- GCMemoryInfo mi = GC.GetGCMemoryInfo();
- return mi.HeapSizeBytes - mi.FragmentedBytes;
- }
- }
-
- public long MonitoringTotalAllocatedMemorySize => GC.GetTotalAllocatedBytes(precise: false);
-
- [Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. https://go.microsoft.com/fwlink/?linkid=14202", false)]
- public static int GetCurrentThreadId() => Environment.CurrentManagedThreadId;
-
- public bool ShadowCopyFiles => false;
-
- [Obsolete("AppDomain.AppendPrivatePath has been deprecated. Please investigate the use of AppDomainSetup.PrivateBinPath instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- public void AppendPrivatePath(string? path) { }
-
- [Obsolete("AppDomain.ClearPrivatePath has been deprecated. Please investigate the use of AppDomainSetup.PrivateBinPath instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- public void ClearPrivatePath() { }
-
- [Obsolete("AppDomain.ClearShadowCopyPath has been deprecated. Please investigate the use of AppDomainSetup.ShadowCopyDirectories instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- public void ClearShadowCopyPath() { }
-
- [Obsolete("AppDomain.SetCachePath has been deprecated. Please investigate the use of AppDomainSetup.CachePath instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- public void SetCachePath(string? path) { }
-
- [Obsolete("AppDomain.SetShadowCopyFiles has been deprecated. Please investigate the use of AppDomainSetup.ShadowCopyFiles instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- public void SetShadowCopyFiles() { }
-
- [Obsolete("AppDomain.SetShadowCopyPath has been deprecated. Please investigate the use of AppDomainSetup.ShadowCopyDirectories instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- public void SetShadowCopyPath(string? path) { }
-
- public Assembly[] GetAssemblies() => AssemblyLoadContext.GetLoadedAssemblies();
-
- public event AssemblyLoadEventHandler? AssemblyLoad
- {
- add { AssemblyLoadContext.AssemblyLoad += value; }
- remove { AssemblyLoadContext.AssemblyLoad -= value; }
- }
-
- public event ResolveEventHandler? AssemblyResolve
- {
- add { AssemblyLoadContext.AssemblyResolve += value; }
- remove { AssemblyLoadContext.AssemblyResolve -= value; }
- }
-
- public event ResolveEventHandler? ReflectionOnlyAssemblyResolve;
-
- public event ResolveEventHandler? TypeResolve
- {
- add { AssemblyLoadContext.TypeResolve += value; }
- remove { AssemblyLoadContext.TypeResolve -= value; }
- }
-
- public event ResolveEventHandler? ResourceResolve
- {
- add { AssemblyLoadContext.ResourceResolve += value; }
- remove { AssemblyLoadContext.ResourceResolve -= value; }
- }
-
- public void SetPrincipalPolicy(PrincipalPolicy policy)
- {
- _principalPolicy = policy;
- }
-
- public void SetThreadPrincipal(IPrincipal principal)
- {
- if (principal == null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
- lock (_forLock)
- {
- // Check that principal has not been set previously.
- if (_defaultPrincipal != null)
- {
- throw new SystemException(SR.AppDomain_Policy_PrincipalTwice);
- }
- _defaultPrincipal = principal;
- }
- }
-
- public ObjectHandle? CreateInstance(string assemblyName, string typeName)
- {
- if (assemblyName == null)
- {
- throw new ArgumentNullException(nameof(assemblyName));
- }
-
- return Activator.CreateInstance(assemblyName, typeName);
- }
-
- public ObjectHandle? CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object?[]? args, System.Globalization.CultureInfo? culture, object?[]? activationAttributes)
- {
- if (assemblyName == null)
- {
- throw new ArgumentNullException(nameof(assemblyName));
- }
-
- return Activator.CreateInstance(assemblyName,
- typeName,
- ignoreCase,
- bindingAttr,
- binder,
- args,
- culture,
- activationAttributes);
- }
-
- public ObjectHandle? CreateInstance(string assemblyName, string typeName, object?[]? activationAttributes)
- {
- if (assemblyName == null)
- {
- throw new ArgumentNullException(nameof(assemblyName));
- }
-
- return Activator.CreateInstance(assemblyName, typeName, activationAttributes);
- }
-
- public object? CreateInstanceAndUnwrap(string assemblyName, string typeName)
- {
- ObjectHandle? oh = CreateInstance(assemblyName, typeName);
- return oh?.Unwrap();
- }
-
- public object? CreateInstanceAndUnwrap(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object?[]? args, System.Globalization.CultureInfo? culture, object?[]? activationAttributes)
- {
- ObjectHandle? oh = CreateInstance(assemblyName,
- typeName,
- ignoreCase,
- bindingAttr,
- binder,
- args,
- culture,
- activationAttributes);
- return oh?.Unwrap();
- }
-
- public object? CreateInstanceAndUnwrap(string assemblyName, string typeName, object?[]? activationAttributes)
- {
- ObjectHandle? oh = CreateInstance(assemblyName, typeName, activationAttributes);
- return oh?.Unwrap();
- }
-
- public ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName)
- {
- return Activator.CreateInstanceFrom(assemblyFile, typeName);
- }
-
- public ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object?[]? args, System.Globalization.CultureInfo? culture, object?[]? activationAttributes)
- {
- return Activator.CreateInstanceFrom(assemblyFile,
- typeName,
- ignoreCase,
- bindingAttr,
- binder,
- args,
- culture,
- activationAttributes);
- }
-
- public ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName, object?[]? activationAttributes)
- {
- return Activator.CreateInstanceFrom(assemblyFile, typeName, activationAttributes);
- }
-
- public object? CreateInstanceFromAndUnwrap(string assemblyFile, string typeName)
- {
- ObjectHandle? oh = CreateInstanceFrom(assemblyFile, typeName);
- return oh?.Unwrap();
- }
-
- public object? CreateInstanceFromAndUnwrap(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object?[]? args, System.Globalization.CultureInfo? culture, object?[]? activationAttributes)
- {
- ObjectHandle? oh = CreateInstanceFrom(assemblyFile,
- typeName,
- ignoreCase,
- bindingAttr,
- binder,
- args,
- culture,
- activationAttributes);
- return oh?.Unwrap();
- }
-
- public object? CreateInstanceFromAndUnwrap(string assemblyFile, string typeName, object?[]? activationAttributes)
- {
- ObjectHandle? oh = CreateInstanceFrom(assemblyFile, typeName, activationAttributes);
- return oh?.Unwrap();
- }
-
- internal IPrincipal? GetThreadPrincipal()
- {
- IPrincipal? principal = _defaultPrincipal;
- if (principal == null)
- {
- switch (_principalPolicy)
- {
- case PrincipalPolicy.UnauthenticatedPrincipal:
- if (s_getUnauthenticatedPrincipal == null)
- {
- Type type = Type.GetType("System.Security.Principal.GenericPrincipal, System.Security.Claims", throwOnError: true)!;
- MethodInfo? mi = type.GetMethod("GetDefaultInstance", BindingFlags.NonPublic | BindingFlags.Static);
- Debug.Assert(mi != null);
- // Don't throw PNSE if null like for WindowsPrincipal as UnauthenticatedPrincipal should
- // be available on all platforms.
- Volatile.Write(ref s_getUnauthenticatedPrincipal,
- (Func<IPrincipal>)mi.CreateDelegate(typeof(Func<IPrincipal>)));
- }
-
- principal = s_getUnauthenticatedPrincipal();
- break;
-
- case PrincipalPolicy.WindowsPrincipal:
- if (s_getWindowsPrincipal == null)
- {
- Type type = Type.GetType("System.Security.Principal.WindowsPrincipal, System.Security.Principal.Windows", throwOnError: true)!;
- MethodInfo? mi = type.GetMethod("GetDefaultInstance", BindingFlags.NonPublic | BindingFlags.Static);
- if (mi == null)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_Principal);
- }
- Volatile.Write(ref s_getWindowsPrincipal,
- (Func<IPrincipal>)mi.CreateDelegate(typeof(Func<IPrincipal>)));
- }
-
- principal = s_getWindowsPrincipal();
- break;
- }
- }
-
- return principal;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AppDomainSetup.cs b/netcore/System.Private.CoreLib/shared/System/AppDomainSetup.cs
deleted file mode 100644
index 925ef7404b2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AppDomainSetup.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System
-{
- public sealed class AppDomainSetup
- {
- internal AppDomainSetup() { }
- public string? ApplicationBase => AppContext.BaseDirectory;
- public string? TargetFrameworkName => AppContext.TargetFrameworkName;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ApplicationException.cs b/netcore/System.Private.CoreLib/shared/System/ApplicationException.cs
deleted file mode 100644
index f12381a0752..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ApplicationException.cs
+++ /dev/null
@@ -1,58 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: The base class for all "less serious" exceptions that must be
-** declared or caught.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- // The ApplicationException is the base class for nonfatal,
- // application errors that occur. These exceptions are generated
- // (i.e., thrown) by an application, not the Runtime. Applications that need
- // to create their own exceptions do so by extending this class.
- // ApplicationException extends but adds no new functionality to
- // RecoverableException.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ApplicationException : Exception
- {
- // Creates a new ApplicationException with its message string set to
- // the empty string, its HRESULT set to COR_E_APPLICATION,
- // and its ExceptionInfo reference set to null.
- public ApplicationException()
- : base(SR.Arg_ApplicationException)
- {
- HResult = HResults.COR_E_APPLICATION;
- }
-
- // Creates a new ApplicationException with its message string set to
- // message, its HRESULT set to COR_E_APPLICATION,
- // and its ExceptionInfo reference set to null.
- //
- public ApplicationException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_APPLICATION;
- }
-
- public ApplicationException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_APPLICATION;
- }
-
- protected ApplicationException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ArgumentException.cs b/netcore/System.Private.CoreLib/shared/System/ArgumentException.cs
deleted file mode 100644
index 1a66f14e479..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ArgumentException.cs
+++ /dev/null
@@ -1,102 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class for invalid arguments to a method.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- // The ArgumentException is thrown when an argument does not meet
- // the contract of the method. Ideally it should give a meaningful error
- // message describing what was wrong and which parameter is incorrect.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ArgumentException : SystemException
- {
- private readonly string? _paramName;
-
- // Creates a new ArgumentException with its message
- // string set to the empty string.
- public ArgumentException()
- : base(SR.Arg_ArgumentException)
- {
- HResult = HResults.COR_E_ARGUMENT;
- }
-
- // Creates a new ArgumentException with its message
- // string set to message.
- //
- public ArgumentException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_ARGUMENT;
- }
-
- public ArgumentException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_ARGUMENT;
- }
-
- public ArgumentException(string? message, string? paramName, Exception? innerException)
- : base(message, innerException)
- {
- _paramName = paramName;
- HResult = HResults.COR_E_ARGUMENT;
- }
-
- public ArgumentException(string? message, string? paramName)
- : base(message)
- {
- _paramName = paramName;
- HResult = HResults.COR_E_ARGUMENT;
- }
-
- protected ArgumentException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- _paramName = info.GetString("ParamName");
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("ParamName", _paramName, typeof(string));
- }
-
- public override string Message
- {
- get
- {
- SetMessageField();
-
- string s = base.Message;
- if (!string.IsNullOrEmpty(_paramName))
- {
- s += " " + SR.Format(SR.Arg_ParamName_Name, _paramName);
- }
-
- return s;
- }
- }
-
- private void SetMessageField()
- {
- if (_message == null && HResult == System.HResults.COR_E_ARGUMENT)
- {
- _message = SR.Arg_ArgumentException;
- }
- }
-
- public virtual string? ParamName => _paramName;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ArgumentNullException.cs b/netcore/System.Private.CoreLib/shared/System/ArgumentNullException.cs
deleted file mode 100644
index 6cdf17bbf2d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ArgumentNullException.cs
+++ /dev/null
@@ -1,55 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class for null arguments to a method.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- // The ArgumentException is thrown when an argument
- // is null when it shouldn't be.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ArgumentNullException : ArgumentException
- {
- // Creates a new ArgumentNullException with its message
- // string set to a default message explaining an argument was null.
- public ArgumentNullException()
- : base(SR.ArgumentNull_Generic)
- {
- // Use E_POINTER - COM used that for null pointers. Description is "invalid pointer"
- HResult = HResults.E_POINTER;
- }
-
- public ArgumentNullException(string? paramName)
- : base(SR.ArgumentNull_Generic, paramName)
- {
- HResult = HResults.E_POINTER;
- }
-
- public ArgumentNullException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.E_POINTER;
- }
-
- public ArgumentNullException(string? paramName, string? message)
- : base(message, paramName)
- {
- HResult = HResults.E_POINTER;
- }
-
- protected ArgumentNullException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ArgumentOutOfRangeException.cs b/netcore/System.Private.CoreLib/shared/System/ArgumentOutOfRangeException.cs
deleted file mode 100644
index cba74213d20..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ArgumentOutOfRangeException.cs
+++ /dev/null
@@ -1,96 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class for method arguments outside of the legal range.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- // The ArgumentOutOfRangeException is thrown when an argument
- // is outside the legal range for that argument.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ArgumentOutOfRangeException : ArgumentException
- {
- private readonly object? _actualValue;
-
- // Creates a new ArgumentOutOfRangeException with its message
- // string set to a default message explaining an argument was out of range.
- public ArgumentOutOfRangeException()
- : base(SR.Arg_ArgumentOutOfRangeException)
- {
- HResult = HResults.COR_E_ARGUMENTOUTOFRANGE;
- }
-
- public ArgumentOutOfRangeException(string? paramName)
- : base(SR.Arg_ArgumentOutOfRangeException, paramName)
- {
- HResult = HResults.COR_E_ARGUMENTOUTOFRANGE;
- }
-
- public ArgumentOutOfRangeException(string? paramName, string? message)
- : base(message, paramName)
- {
- HResult = HResults.COR_E_ARGUMENTOUTOFRANGE;
- }
-
- public ArgumentOutOfRangeException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_ARGUMENTOUTOFRANGE;
- }
-
- // We will not use this in the classlibs, but we'll provide it for
- // anyone that's really interested so they don't have to stick a bunch
- // of printf's in their code.
- public ArgumentOutOfRangeException(string? paramName, object? actualValue, string? message)
- : base(message, paramName)
- {
- _actualValue = actualValue;
- HResult = HResults.COR_E_ARGUMENTOUTOFRANGE;
- }
-
- protected ArgumentOutOfRangeException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- _actualValue = info.GetValue("ActualValue", typeof(object));
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("ActualValue", _actualValue, typeof(object));
- }
-
- public override string Message
- {
- get
- {
- string s = base.Message;
- if (_actualValue != null)
- {
- string valueMessage = SR.Format(SR.ArgumentOutOfRange_ActualValue, _actualValue);
- if (s == null)
- return valueMessage;
- return s + Environment.NewLineConst + valueMessage;
- }
- return s;
- }
- }
-
- // Gets the value of the argument that caused the exception.
- // Note - we don't set this anywhere in the class libraries in
- // version 1, but it might come in handy for other developers who
- // want to avoid sticking printf's in their code.
- public virtual object? ActualValue => _actualValue;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ArithmeticException.cs b/netcore/System.Private.CoreLib/shared/System/ArithmeticException.cs
deleted file mode 100644
index b80a51247e7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ArithmeticException.cs
+++ /dev/null
@@ -1,53 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class for bad arithmetic conditions!
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- // The ArithmeticException is thrown when overflow or underflow
- // occurs.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ArithmeticException : SystemException
- {
- // Creates a new ArithmeticException with its message string set to
- // the empty string, its HRESULT set to COR_E_ARITHMETIC,
- // and its ExceptionInfo reference set to null.
- public ArithmeticException()
- : base(SR.Arg_ArithmeticException)
- {
- HResult = HResults.COR_E_ARITHMETIC;
- }
-
- // Creates a new ArithmeticException with its message string set to
- // message, its HRESULT set to COR_E_ARITHMETIC,
- // and its ExceptionInfo reference set to null.
- //
- public ArithmeticException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_ARITHMETIC;
- }
-
- public ArithmeticException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_ARITHMETIC;
- }
-
- protected ArithmeticException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Array.Enumerators.cs b/netcore/System.Private.CoreLib/shared/System/Array.Enumerators.cs
deleted file mode 100644
index 08c8f652f49..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Array.Enumerators.cs
+++ /dev/null
@@ -1,212 +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 System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace System
-{
- internal sealed class ArrayEnumerator : IEnumerator, ICloneable
- {
- private readonly Array array;
- private int index;
- private readonly int endIndex;
- private readonly int startIndex; // Save for Reset.
- private readonly int[] _indices; // The current position in a multidim array
- private bool _complete;
-
- internal ArrayEnumerator(Array array, int index, int count)
- {
- this.array = array;
- this.index = index - 1;
- startIndex = index;
- endIndex = index + count;
- _indices = new int[array.Rank];
- int checkForZero = 1; // Check for dimensions of size 0.
- for (int i = 0; i < array.Rank; i++)
- {
- _indices[i] = array.GetLowerBound(i);
- checkForZero *= array.GetLength(i);
- }
- // To make MoveNext simpler, decrement least significant index.
- _indices[^1]--;
- _complete = (checkForZero == 0);
- }
-
- private void IncArray()
- {
- // This method advances us to the next valid array index,
- // handling all the multiple dimension & bounds correctly.
- // Think of it like an odometer in your car - we start with
- // the last digit, increment it, and check for rollover. If
- // it rolls over, we set all digits to the right and including
- // the current to the appropriate lower bound. Do these overflow
- // checks for each dimension, and if the most significant digit
- // has rolled over it's upper bound, we're done.
- //
- int rank = array.Rank;
- _indices[rank - 1]++;
- for (int dim = rank - 1; dim >= 0; dim--)
- {
- if (_indices[dim] > array.GetUpperBound(dim))
- {
- if (dim == 0)
- {
- _complete = true;
- break;
- }
- for (int j = dim; j < rank; j++)
- _indices[j] = array.GetLowerBound(j);
- _indices[dim - 1]++;
- }
- }
- }
-
- public object Clone()
- {
- return MemberwiseClone();
- }
-
- public bool MoveNext()
- {
- if (_complete)
- {
- index = endIndex;
- return false;
- }
- index++;
- IncArray();
- return !_complete;
- }
-
- public object? Current
- {
- get
- {
- if (index < startIndex) ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumNotStarted();
- if (_complete) ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded();
- return array.GetValue(_indices);
- }
- }
-
- public void Reset()
- {
- index = startIndex - 1;
- int checkForZero = 1;
- for (int i = 0; i < array.Rank; i++)
- {
- _indices[i] = array.GetLowerBound(i);
- checkForZero *= array.GetLength(i);
- }
- _complete = (checkForZero == 0);
- // To make MoveNext simpler, decrement least significant index.
- _indices[^1]--;
- }
- }
-
- internal sealed class SZArrayEnumerator : IEnumerator, ICloneable
- {
- private readonly Array _array;
- private int _index;
- private readonly int _endIndex; // Cache Array.Length, since it's a little slow.
-
- internal SZArrayEnumerator(Array array)
- {
- Debug.Assert(array.Rank == 1 && array.GetLowerBound(0) == 0, "SZArrayEnumerator only works on single dimension arrays w/ a lower bound of zero.");
-
- _array = array;
- _index = -1;
- _endIndex = array.Length;
- }
-
- public object Clone()
- {
- return MemberwiseClone();
- }
-
- public bool MoveNext()
- {
- if (_index < _endIndex)
- {
- _index++;
- return _index < _endIndex;
- }
- return false;
- }
-
- public object? Current
- {
- get
- {
- if (_index < 0)
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumNotStarted();
- if (_index >= _endIndex)
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded();
- return _array.GetValue(_index);
- }
- }
-
- public void Reset()
- {
- _index = -1;
- }
- }
-
- internal sealed class SZGenericArrayEnumerator<T> : IEnumerator<T>
- {
- private readonly T[] _array;
- private int _index;
-
- // Array.Empty is intentionally omitted here, since we don't want to pay for generic instantiations that
- // wouldn't have otherwise been used.
-#pragma warning disable CA1825
- internal static readonly SZGenericArrayEnumerator<T> Empty = new SZGenericArrayEnumerator<T>(new T[0]);
-#pragma warning restore CA1825
-
- internal SZGenericArrayEnumerator(T[] array)
- {
- Debug.Assert(array != null);
-
- _array = array;
- _index = -1;
- }
-
- public bool MoveNext()
- {
- int index = _index + 1;
- if ((uint)index >= (uint)_array.Length)
- {
- _index = _array.Length;
- return false;
- }
- _index = index;
- return true;
- }
-
- public T Current
- {
- get
- {
- int index = _index;
- T[] array = _array;
-
- if ((uint)index >= (uint)array.Length)
- {
- ThrowHelper.ThrowInvalidOperationException_EnumCurrent(index);
- }
-
- return array[index];
- }
- }
-
- object? IEnumerator.Current => Current;
-
- void IEnumerator.Reset() => _index = -1;
-
- public void Dispose()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Array.cs b/netcore/System.Private.CoreLib/shared/System/Array.cs
deleted file mode 100644
index f280123b395..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Array.cs
+++ /dev/null
@@ -1,2269 +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 System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public abstract partial class Array : ICloneable, IList, IStructuralComparable, IStructuralEquatable
- {
- // We impose limits on maximum array length in each dimension to allow efficient
- // implementation of advanced range check elimination in future.
- // Keep in sync with vm\gcscan.cpp and HashHelpers.MaxPrimeArrayLength.
- // The constants are defined in this method: inline SIZE_T MaxArrayLength(SIZE_T componentSize) from gcscan
- // We have different max sizes for arrays with elements of size 1 for backwards compatibility
- internal const int MaxArrayLength = 0X7FEFFFFF;
- internal const int MaxByteArrayLength = 0x7FFFFFC7;
-
- // This ctor exists solely to prevent C# from generating a protected .ctor that violates the surface area.
- private protected Array() { }
-
- public static ReadOnlyCollection<T> AsReadOnly<T>(T[] array)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- // T[] implements IList<T>.
- return new ReadOnlyCollection<T>(array);
- }
-
- public static void Resize<T>([NotNull] ref T[]? array, int newSize)
- {
- if (newSize < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.newSize, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
-
- T[]? larray = array;
- if (larray == null)
- {
- array = new T[newSize];
- return;
- }
-
- if (larray.Length != newSize)
- {
- T[] newArray = new T[newSize];
- Copy(larray, 0, newArray, 0, larray.Length > newSize ? newSize : larray.Length);
- array = newArray;
- }
- }
-
- public static Array CreateInstance(Type elementType, params long[] lengths)
- {
- if (lengths == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths);
- }
- if (lengths.Length == 0)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank);
-
- int[] intLengths = new int[lengths.Length];
-
- for (int i = 0; i < lengths.Length; ++i)
- {
- long len = lengths[i];
- int ilen = (int)len;
- if (len != ilen)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.len, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
- intLengths[i] = ilen;
- }
-
- return Array.CreateInstance(elementType, intLengths);
- }
-
- public static void Copy(Array sourceArray, Array destinationArray, long length)
- {
- int ilength = (int)length;
- if (length != ilength)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
-
- Copy(sourceArray, destinationArray, ilength);
- }
-
- public static void Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length)
- {
- int isourceIndex = (int)sourceIndex;
- int idestinationIndex = (int)destinationIndex;
- int ilength = (int)length;
-
- if (sourceIndex != isourceIndex)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.sourceIndex, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
- if (destinationIndex != idestinationIndex)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.destinationIndex, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
- if (length != ilength)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
-
- Copy(sourceArray, isourceIndex, destinationArray, idestinationIndex, ilength);
- }
-
- public object? GetValue(long index)
- {
- int iindex = (int)index;
- if (index != iindex)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
-
- return this.GetValue(iindex);
- }
-
- public object? GetValue(long index1, long index2)
- {
- int iindex1 = (int)index1;
- int iindex2 = (int)index2;
-
- if (index1 != iindex1)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
- if (index2 != iindex2)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
-
- return this.GetValue(iindex1, iindex2);
- }
-
- public object? GetValue(long index1, long index2, long index3)
- {
- int iindex1 = (int)index1;
- int iindex2 = (int)index2;
- int iindex3 = (int)index3;
-
- if (index1 != iindex1)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
- if (index2 != iindex2)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
- if (index3 != iindex3)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index3, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
-
- return this.GetValue(iindex1, iindex2, iindex3);
- }
-
- public object? GetValue(params long[] indices)
- {
- if (indices == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices);
- if (Rank != indices.Length)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices);
-
- int[] intIndices = new int[indices.Length];
-
- for (int i = 0; i < indices.Length; ++i)
- {
- long index = indices[i];
- int iindex = (int)index;
- if (index != iindex)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
- intIndices[i] = iindex;
- }
-
- return this.GetValue(intIndices);
- }
-
- public void SetValue(object? value, long index)
- {
- int iindex = (int)index;
-
- if (index != iindex)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
-
- this.SetValue(value, iindex);
- }
-
- public void SetValue(object? value, long index1, long index2)
- {
- int iindex1 = (int)index1;
- int iindex2 = (int)index2;
-
- if (index1 != iindex1)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
- if (index2 != iindex2)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
-
- this.SetValue(value, iindex1, iindex2);
- }
-
- public void SetValue(object? value, long index1, long index2, long index3)
- {
- int iindex1 = (int)index1;
- int iindex2 = (int)index2;
- int iindex3 = (int)index3;
-
- if (index1 != iindex1)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
- if (index2 != iindex2)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
- if (index3 != iindex3)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index3, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
-
- this.SetValue(value, iindex1, iindex2, iindex3);
- }
-
- public void SetValue(object? value, params long[] indices)
- {
- if (indices == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices);
- if (Rank != indices.Length)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices);
-
- int[] intIndices = new int[indices.Length];
-
- for (int i = 0; i < indices.Length; ++i)
- {
- long index = indices[i];
- int iindex = (int)index;
- if (index != iindex)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
- intIndices[i] = iindex;
- }
-
- this.SetValue(value, intIndices);
- }
-
- private static int GetMedian(int low, int hi)
- {
- // Note both may be negative, if we are dealing with arrays w/ negative lower bounds.
- Debug.Assert(low <= hi);
- Debug.Assert(hi - low >= 0, "Length overflow!");
- return low + ((hi - low) >> 1);
- }
-
- public long GetLongLength(int dimension)
- {
- // This method should throw an IndexOufOfRangeException for compat if dimension < 0 or >= Rank
- return GetLength(dimension);
- }
-
- // Number of elements in the Array.
- int ICollection.Count => Length;
-
- // Returns an object appropriate for synchronizing access to this
- // Array.
- public object SyncRoot => this;
-
- // Is this Array read-only?
- public bool IsReadOnly => false;
-
- public bool IsFixedSize => true;
-
- // Is this Array synchronized (i.e., thread-safe)? If you want a synchronized
- // collection, you can use SyncRoot as an object to synchronize your
- // collection with. You could also call GetSynchronized()
- // to get a synchronized wrapper around the Array.
- public bool IsSynchronized => false;
-
- object? IList.this[int index]
- {
- get => GetValue(index);
- set => SetValue(value, index);
- }
-
- int IList.Add(object? value)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
- return default;
- }
-
- bool IList.Contains(object? value)
- {
- return Array.IndexOf(this, value) >= this.GetLowerBound(0);
- }
-
- void IList.Clear()
- {
- Array.Clear(this, this.GetLowerBound(0), this.Length);
- }
-
- int IList.IndexOf(object? value)
- {
- return Array.IndexOf(this, value);
- }
-
- void IList.Insert(int index, object? value)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
- }
-
- void IList.Remove(object? value)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
- }
-
- void IList.RemoveAt(int index)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
- }
-
- // Make a new array which is a shallow copy of the original array.
- //
- public object Clone()
- {
- return MemberwiseClone();
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null)
- {
- return 1;
- }
-
- Array? o = other as Array;
-
- if (o == null || this.Length != o.Length)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.ArgumentException_OtherNotArrayOfCorrectLength, ExceptionArgument.other);
- }
-
- int i = 0;
- int c = 0;
-
- while (i < o.Length && c == 0)
- {
- object? left = GetValue(i);
- object? right = o.GetValue(i);
-
- c = comparer.Compare(left, right);
- i++;
- }
-
- return c;
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null)
- {
- return false;
- }
-
- if (object.ReferenceEquals(this, other))
- {
- return true;
- }
-
- if (!(other is Array o) || o.Length != this.Length)
- {
- return false;
- }
-
- int i = 0;
- while (i < o.Length)
- {
- object? left = GetValue(i);
- object? right = o.GetValue(i);
-
- if (!comparer.Equals(left, right))
- {
- return false;
- }
- i++;
- }
-
- return true;
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- if (comparer == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer);
-
- int ret = 0;
-
- for (int i = (this.Length >= 8 ? this.Length - 8 : 0); i < this.Length; i++)
- {
- ret = HashCode.Combine(ret, comparer.GetHashCode(GetValue(i)!));
- }
-
- return ret;
- }
-
- // Searches an array for a given element using a binary search algorithm.
- // Elements of the array are compared to the search value using the
- // IComparable interface, which must be implemented by all elements
- // of the array and the given search value. This method assumes that the
- // array is already sorted according to the IComparable interface;
- // if this is not the case, the result will be incorrect.
- //
- // The method returns the index of the given value in the array. If the
- // array does not contain the given value, the method returns a negative
- // integer. The bitwise complement operator (~) can be applied to a
- // negative result to produce the index of the first element (if any) that
- // is larger than the given search value.
- //
- public static int BinarySearch(Array array, object? value)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- return BinarySearch(array, array.GetLowerBound(0), array.Length, value, null);
- }
-
- // Searches a section of an array for a given element using a binary search
- // algorithm. Elements of the array are compared to the search value using
- // the IComparable interface, which must be implemented by all
- // elements of the array and the given search value. This method assumes
- // that the array is already sorted according to the IComparable
- // interface; if this is not the case, the result will be incorrect.
- //
- // The method returns the index of the given value in the array. If the
- // array does not contain the given value, the method returns a negative
- // integer. The bitwise complement operator (~) can be applied to a
- // negative result to produce the index of the first element (if any) that
- // is larger than the given search value.
- //
- public static int BinarySearch(Array array, int index, int length, object? value)
- {
- return BinarySearch(array, index, length, value, null);
- }
-
- // Searches an array for a given element using a binary search algorithm.
- // Elements of the array are compared to the search value using the given
- // IComparer interface. If comparer is null, elements of the
- // array are compared to the search value using the IComparable
- // interface, which in that case must be implemented by all elements of the
- // array and the given search value. This method assumes that the array is
- // already sorted; if this is not the case, the result will be incorrect.
- //
- // The method returns the index of the given value in the array. If the
- // array does not contain the given value, the method returns a negative
- // integer. The bitwise complement operator (~) can be applied to a
- // negative result to produce the index of the first element (if any) that
- // is larger than the given search value.
- //
- public static int BinarySearch(Array array, object? value, IComparer? comparer)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- return BinarySearch(array, array.GetLowerBound(0), array.Length, value, comparer);
- }
-
- // Searches a section of an array for a given element using a binary search
- // algorithm. Elements of the array are compared to the search value using
- // the given IComparer interface. If comparer is null,
- // elements of the array are compared to the search value using the
- // IComparable interface, which in that case must be implemented by
- // all elements of the array and the given search value. This method
- // assumes that the array is already sorted; if this is not the case, the
- // result will be incorrect.
- //
- // The method returns the index of the given value in the array. If the
- // array does not contain the given value, the method returns a negative
- // integer. The bitwise complement operator (~) can be applied to a
- // negative result to produce the index of the first element (if any) that
- // is larger than the given search value.
- //
- public static int BinarySearch(Array array, int index, int length, object? value, IComparer? comparer)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lb = array.GetLowerBound(0);
- if (index < lb)
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- if (length < 0)
- ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
- if (array.Length - (index - lb) < length)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
- if (array.Rank != 1)
- ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
-
- comparer ??= Comparer.Default;
-
- int lo = index;
- int hi = index + length - 1;
- if (array is object[] objArray)
- {
- while (lo <= hi)
- {
- // i might overflow if lo and hi are both large positive numbers.
- int i = GetMedian(lo, hi);
-
- int c;
- try
- {
- c = comparer.Compare(objArray[i], value);
- }
- catch (Exception e)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
- return default;
- }
- if (c == 0) return i;
- if (c < 0)
- {
- lo = i + 1;
- }
- else
- {
- hi = i - 1;
- }
- }
- return ~lo;
- }
-
- if (comparer == Comparer.Default)
- {
- CorElementType et = array.GetCorElementTypeOfElementType();
- if (et.IsPrimitiveType()
- // IntPtr/UIntPtr does not implement IComparable
- && (et != CorElementType.ELEMENT_TYPE_I) && (et != CorElementType.ELEMENT_TYPE_U))
- {
- if (value == null)
- return ~index;
-
- if (array.IsValueOfElementType(value))
- {
- int adjustedIndex = index - lb;
- int result = -1;
- switch (et)
- {
- case CorElementType.ELEMENT_TYPE_I1:
- result = GenericBinarySearch<sbyte>(array, adjustedIndex, length, value);
- break;
- case CorElementType.ELEMENT_TYPE_U1:
- case CorElementType.ELEMENT_TYPE_BOOLEAN:
- result = GenericBinarySearch<byte>(array, adjustedIndex, length, value);
- break;
- case CorElementType.ELEMENT_TYPE_I2:
- result = GenericBinarySearch<short>(array, adjustedIndex, length, value);
- break;
- case CorElementType.ELEMENT_TYPE_U2:
- case CorElementType.ELEMENT_TYPE_CHAR:
- result = GenericBinarySearch<ushort>(array, adjustedIndex, length, value);
- break;
- case CorElementType.ELEMENT_TYPE_I4:
- result = GenericBinarySearch<int>(array, adjustedIndex, length, value);
- break;
- case CorElementType.ELEMENT_TYPE_U4:
- result = GenericBinarySearch<uint>(array, adjustedIndex, length, value);
- break;
- case CorElementType.ELEMENT_TYPE_I8:
- result = GenericBinarySearch<long>(array, adjustedIndex, length, value);
- break;
- case CorElementType.ELEMENT_TYPE_U8:
- result = GenericBinarySearch<ulong>(array, adjustedIndex, length, value);
- break;
- case CorElementType.ELEMENT_TYPE_R4:
- result = GenericBinarySearch<float>(array, adjustedIndex, length, value);
- break;
- case CorElementType.ELEMENT_TYPE_R8:
- result = GenericBinarySearch<double>(array, adjustedIndex, length, value);
- break;
- default:
- Debug.Fail("All primitive types should be handled above");
- break;
- }
-
- return (result >= 0) ? (index + result) : ~(index + ~result);
-
- static int GenericBinarySearch<T>(Array array, int adjustedIndex, int length, object value) where T: struct, IComparable<T>
- => UnsafeArrayAsSpan<T>(array, adjustedIndex, length).BinarySearch(Unsafe.As<byte, T>(ref value.GetRawData()));
- }
- }
- }
-
- while (lo <= hi)
- {
- int i = GetMedian(lo, hi);
-
- int c;
- try
- {
- c = comparer.Compare(array.GetValue(i), value);
- }
- catch (Exception e)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
- return default;
- }
- if (c == 0) return i;
- if (c < 0)
- {
- lo = i + 1;
- }
- else
- {
- hi = i - 1;
- }
- }
- return ~lo;
- }
-
- public static int BinarySearch<T>(T[] array, T value)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- return BinarySearch<T>(array, 0, array.Length, value, null);
- }
-
- public static int BinarySearch<T>(T[] array, T value, System.Collections.Generic.IComparer<T>? comparer)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- return BinarySearch<T>(array, 0, array.Length, value, comparer);
- }
-
- public static int BinarySearch<T>(T[] array, int index, int length, T value)
- {
- return BinarySearch<T>(array, index, length, value, null);
- }
-
- public static int BinarySearch<T>(T[] array, int index, int length, T value, System.Collections.Generic.IComparer<T>? comparer)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (index < 0)
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- if (length < 0)
- ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
-
- if (array.Length - index < length)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
-
- return ArraySortHelper<T>.Default.BinarySearch(array, index, length, value, comparer);
- }
-
- public static TOutput[] ConvertAll<TInput, TOutput>(TInput[] array, Converter<TInput, TOutput> converter)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (converter == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.converter);
- }
-
- TOutput[] newArray = new TOutput[array.Length];
- for (int i = 0; i < array.Length; i++)
- {
- newArray[i] = converter(array[i]);
- }
- return newArray;
- }
-
- // CopyTo copies a collection into an Array, starting at a particular
- // index into the array.
- //
- // This method is to support the ICollection interface, and calls
- // Array.Copy internally. If you aren't using ICollection explicitly,
- // call Array.Copy to avoid an extra indirection.
- //
- public void CopyTo(Array array, int index)
- {
- if (array != null && array.Rank != 1)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
- // Note: Array.Copy throws a RankException and we want a consistent ArgumentException for all the IList CopyTo methods.
- Array.Copy(this, GetLowerBound(0), array!, index, Length);
- }
-
- public void CopyTo(Array array, long index)
- {
- int iindex = (int)index;
- if (index != iindex)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported);
-
- this.CopyTo(array, iindex);
- }
-
- private static class EmptyArray<T>
- {
-#pragma warning disable CA1825 // this is the implementation of Array.Empty<T>()
- internal static readonly T[] Value = new T[0];
-#pragma warning restore CA1825
- }
-
- public static T[] Empty<T>()
- {
- return EmptyArray<T>.Value;
- }
-
- public static bool Exists<T>(T[] array, Predicate<T> match)
- {
- return Array.FindIndex(array, match) != -1;
- }
-
- public static void Fill<T>(T[] array, T value)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = value;
- }
- }
-
- public static void Fill<T>(T[] array, T value, int startIndex, int count)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (startIndex < 0 || startIndex > array.Length)
- {
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- }
-
- if (count < 0 || startIndex > array.Length - count)
- {
- ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
- }
-
- for (int i = startIndex; i < startIndex + count; i++)
- {
- array[i] = value;
- }
- }
-
- [return: MaybeNull]
- public static T Find<T>(T[] array, Predicate<T> match)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- for (int i = 0; i < array.Length; i++)
- {
- if (match(array[i]))
- {
- return array[i];
- }
- }
- return default!;
- }
-
- public static T[] FindAll<T>(T[] array, Predicate<T> match)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- List<T> list = new List<T>();
- for (int i = 0; i < array.Length; i++)
- {
- if (match(array[i]))
- {
- list.Add(array[i]);
- }
- }
- return list.ToArray();
- }
-
- public static int FindIndex<T>(T[] array, Predicate<T> match)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- return FindIndex(array, 0, array.Length, match);
- }
-
- public static int FindIndex<T>(T[] array, int startIndex, Predicate<T> match)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- return FindIndex(array, startIndex, array.Length - startIndex, match);
- }
-
- public static int FindIndex<T>(T[] array, int startIndex, int count, Predicate<T> match)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (startIndex < 0 || startIndex > array.Length)
- {
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- }
-
- if (count < 0 || startIndex > array.Length - count)
- {
- ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
- }
-
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- int endIndex = startIndex + count;
- for (int i = startIndex; i < endIndex; i++)
- {
- if (match(array[i]))
- return i;
- }
- return -1;
- }
-
- [return: MaybeNull]
- public static T FindLast<T>(T[] array, Predicate<T> match)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- for (int i = array.Length - 1; i >= 0; i--)
- {
- if (match(array[i]))
- {
- return array[i];
- }
- }
- return default!;
- }
-
- public static int FindLastIndex<T>(T[] array, Predicate<T> match)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- return FindLastIndex(array, array.Length - 1, array.Length, match);
- }
-
- public static int FindLastIndex<T>(T[] array, int startIndex, Predicate<T> match)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- return FindLastIndex(array, startIndex, startIndex + 1, match);
- }
-
- public static int FindLastIndex<T>(T[] array, int startIndex, int count, Predicate<T> match)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- if (array.Length == 0)
- {
- // Special case for 0 length List
- if (startIndex != -1)
- {
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- }
- }
- else
- {
- // Make sure we're not out of range
- if (startIndex < 0 || startIndex >= array.Length)
- {
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- }
- }
-
- // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
- if (count < 0 || startIndex - count + 1 < 0)
- {
- ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
- }
-
- int endIndex = startIndex - count;
- for (int i = startIndex; i > endIndex; i--)
- {
- if (match(array[i]))
- {
- return i;
- }
- }
- return -1;
- }
-
- public static void ForEach<T>(T[] array, Action<T> action)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (action == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.action);
- }
-
- for (int i = 0; i < array.Length; i++)
- {
- action(array[i]);
- }
- }
-
- // Returns the index of the first occurrence of a given value in an array.
- // The array is searched forwards, and the elements of the array are
- // compared to the given value using the Object.Equals method.
- //
- public static int IndexOf(Array array, object? value)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- return IndexOf(array, value, array.GetLowerBound(0), array.Length);
- }
-
- // Returns the index of the first occurrence of a given value in a range of
- // an array. The array is searched forwards, starting at index
- // startIndex and ending at the last element of the array. The
- // elements of the array are compared to the given value using the
- // Object.Equals method.
- //
- public static int IndexOf(Array array, object? value, int startIndex)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lb = array.GetLowerBound(0);
- return IndexOf(array, value, startIndex, array.Length - startIndex + lb);
- }
-
- // Returns the index of the first occurrence of a given value in a range of
- // an array. The array is searched forwards, starting at index
- // startIndex and upto count elements. The
- // elements of the array are compared to the given value using the
- // Object.Equals method.
- //
- public static int IndexOf(Array array, object? value, int startIndex, int count)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (array.Rank != 1)
- ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
-
- int lb = array.GetLowerBound(0);
- if (startIndex < lb || startIndex > array.Length + lb)
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- if (count < 0 || count > array.Length - startIndex + lb)
- ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
-
- int endIndex = startIndex + count;
- if (array is object[] objArray)
- {
- if (value == null)
- {
- for (int i = startIndex; i < endIndex; i++)
- {
- if (objArray[i] == null)
- return i;
- }
- }
- else
- {
- for (int i = startIndex; i < endIndex; i++)
- {
- object obj = objArray[i];
- if (obj != null && obj.Equals(value))
- return i;
- }
- }
- return -1;
- }
-
- CorElementType et = array.GetCorElementTypeOfElementType();
- if (et.IsPrimitiveType())
- {
- if (value == null)
- return lb - 1;
-
- if (array.IsValueOfElementType(value))
- {
- int adjustedIndex = startIndex - lb;
- int result = -1;
- switch (et)
- {
- case CorElementType.ELEMENT_TYPE_I1:
- case CorElementType.ELEMENT_TYPE_U1:
- case CorElementType.ELEMENT_TYPE_BOOLEAN:
- result = GenericIndexOf<byte>(array, value, adjustedIndex, count);
- break;
- case CorElementType.ELEMENT_TYPE_I2:
- case CorElementType.ELEMENT_TYPE_U2:
- case CorElementType.ELEMENT_TYPE_CHAR:
- result = GenericIndexOf<char>(array, value, adjustedIndex, count);
- break;
- case CorElementType.ELEMENT_TYPE_I4:
- case CorElementType.ELEMENT_TYPE_U4:
-#if !BIT64
- case CorElementType.ELEMENT_TYPE_I:
- case CorElementType.ELEMENT_TYPE_U:
-#endif
- result = GenericIndexOf<int>(array, value, adjustedIndex, count);
- break;
- case CorElementType.ELEMENT_TYPE_I8:
- case CorElementType.ELEMENT_TYPE_U8:
-#if BIT64
- case CorElementType.ELEMENT_TYPE_I:
- case CorElementType.ELEMENT_TYPE_U:
-#endif
- result = GenericIndexOf<long>(array, value, adjustedIndex, count);
- break;
- case CorElementType.ELEMENT_TYPE_R4:
- result = GenericIndexOf<float>(array, value, adjustedIndex, count);
- break;
- case CorElementType.ELEMENT_TYPE_R8:
- result = GenericIndexOf<double>(array, value, adjustedIndex, count);
- break;
- default:
- Debug.Fail("All primitive types should be handled above");
- break;
- }
-
- return (result >= 0 ? startIndex : lb) + result;
-
- static int GenericIndexOf<T>(Array array, object value, int adjustedIndex, int length) where T : struct, IEquatable<T>
- => UnsafeArrayAsSpan<T>(array, adjustedIndex, length).IndexOf(Unsafe.As<byte, T>(ref value.GetRawData()));
- }
- }
-
- for (int i = startIndex; i < endIndex; i++)
- {
- object? obj = array.GetValue(i);
- if (obj == null)
- {
- if (value == null)
- return i;
- }
- else
- {
- if (obj.Equals(value))
- return i;
- }
- }
- // Return one less than the lower bound of the array. This way,
- // for arrays with a lower bound of -1 we will not return -1 when the
- // item was not found. And for SZArrays (the vast majority), -1 still
- // works for them.
- return lb - 1;
- }
-
- public static int IndexOf<T>(T[] array, T value)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- return IndexOf(array, value, 0, array.Length);
- }
-
- public static int IndexOf<T>(T[] array, T value, int startIndex)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- return IndexOf(array, value, startIndex, array.Length - startIndex);
- }
-
- public static int IndexOf<T>(T[] array, T value, int startIndex, int count)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if ((uint)startIndex > (uint)array.Length)
- {
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- }
-
- if ((uint)count > (uint)(array.Length - startIndex))
- {
- ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
- }
-
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- {
- int result = SpanHelpers.IndexOf(
- ref Unsafe.Add(ref array.GetRawSzArrayData(), startIndex),
- Unsafe.As<T, byte>(ref value),
- count);
- return (result >= 0 ? startIndex : 0) + result;
- }
- else if (Unsafe.SizeOf<T>() == sizeof(char))
- {
- int result = SpanHelpers.IndexOf(
- ref Unsafe.Add(ref Unsafe.As<byte, char>(ref array.GetRawSzArrayData()), startIndex),
- Unsafe.As<T, char>(ref value),
- count);
- return (result >= 0 ? startIndex : 0) + result;
- }
- else if (Unsafe.SizeOf<T>() == sizeof(int))
- {
- int result = SpanHelpers.IndexOf(
- ref Unsafe.Add(ref Unsafe.As<byte, int>(ref array.GetRawSzArrayData()), startIndex),
- Unsafe.As<T, int>(ref value),
- count);
- return (result >= 0 ? startIndex : 0) + result;
- }
- else if (Unsafe.SizeOf<T>() == sizeof(long))
- {
- int result = SpanHelpers.IndexOf(
- ref Unsafe.Add(ref Unsafe.As<byte, long>(ref array.GetRawSzArrayData()), startIndex),
- Unsafe.As<T, long>(ref value),
- count);
- return (result >= 0 ? startIndex : 0) + result;
- }
- }
-
-#if !CORERT
- return EqualityComparer<T>.Default.IndexOf(array, value, startIndex, count);
-#else
- return IndexOfImpl(array, value, startIndex, count);
-#endif
- }
-
- // Returns the index of the last occurrence of a given value in an array.
- // The array is searched backwards, and the elements of the array are
- // compared to the given value using the Object.Equals method.
- //
- public static int LastIndexOf(Array array, object? value)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lb = array.GetLowerBound(0);
- return LastIndexOf(array, value, array.Length - 1 + lb, array.Length);
- }
-
- // Returns the index of the last occurrence of a given value in a range of
- // an array. The array is searched backwards, starting at index
- // startIndex and ending at index 0. The elements of the array are
- // compared to the given value using the Object.Equals method.
- //
- public static int LastIndexOf(Array array, object? value, int startIndex)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lb = array.GetLowerBound(0);
- return LastIndexOf(array, value, startIndex, startIndex + 1 - lb);
- }
-
- // Returns the index of the last occurrence of a given value in a range of
- // an array. The array is searched backwards, starting at index
- // startIndex and counting uptocount elements. The elements of
- // the array are compared to the given value using the Object.Equals
- // method.
- //
- public static int LastIndexOf(Array array, object? value, int startIndex, int count)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lb = array.GetLowerBound(0);
- if (array.Length == 0)
- {
- return lb - 1;
- }
-
- if (startIndex < lb || startIndex >= array.Length + lb)
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- if (count < 0)
- ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
- if (count > startIndex - lb + 1)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.endIndex, ExceptionResource.ArgumentOutOfRange_EndIndexStartIndex);
- if (array.Rank != 1)
- ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
-
- int endIndex = startIndex - count + 1;
- if (array is object[] objArray)
- {
- if (value == null)
- {
- for (int i = startIndex; i >= endIndex; i--)
- {
- if (objArray[i] == null)
- return i;
- }
- }
- else
- {
- for (int i = startIndex; i >= endIndex; i--)
- {
- object obj = objArray[i];
- if (obj != null && obj.Equals(value))
- return i;
- }
- }
- return -1;
- }
-
- CorElementType et = array.GetCorElementTypeOfElementType();
- if (et.IsPrimitiveType())
- {
- if (value == null)
- return lb - 1;
-
- if (array.IsValueOfElementType(value))
- {
- int adjustedIndex = endIndex - lb;
- int result = -1;
- switch (et)
- {
- case CorElementType.ELEMENT_TYPE_I1:
- case CorElementType.ELEMENT_TYPE_U1:
- case CorElementType.ELEMENT_TYPE_BOOLEAN:
- result = GenericLastIndexOf<byte>(array, value, adjustedIndex, count);
- break;
- case CorElementType.ELEMENT_TYPE_I2:
- case CorElementType.ELEMENT_TYPE_U2:
- case CorElementType.ELEMENT_TYPE_CHAR:
- result = GenericLastIndexOf<char>(array, value, adjustedIndex, count);
- break;
- case CorElementType.ELEMENT_TYPE_I4:
- case CorElementType.ELEMENT_TYPE_U4:
-#if !BIT64
- case CorElementType.ELEMENT_TYPE_I:
- case CorElementType.ELEMENT_TYPE_U:
-#endif
- result = GenericLastIndexOf<int>(array, value, adjustedIndex, count);
- break;
- case CorElementType.ELEMENT_TYPE_I8:
- case CorElementType.ELEMENT_TYPE_U8:
-#if BIT64
- case CorElementType.ELEMENT_TYPE_I:
- case CorElementType.ELEMENT_TYPE_U:
-#endif
- result = GenericLastIndexOf<long>(array, value, adjustedIndex, count);
- break;
- case CorElementType.ELEMENT_TYPE_R4:
- result = GenericLastIndexOf<float>(array, value, adjustedIndex, count);
- break;
- case CorElementType.ELEMENT_TYPE_R8:
- result = GenericLastIndexOf<double>(array, value, adjustedIndex, count);
- break;
- default:
- Debug.Fail("All primitive types should be handled above");
- break;
- }
-
- return (result >= 0 ? endIndex : lb) + result;
-
- static int GenericLastIndexOf<T>(Array array, object value, int adjustedIndex, int length) where T : struct, IEquatable<T>
- => UnsafeArrayAsSpan<T>(array, adjustedIndex, length).LastIndexOf(Unsafe.As<byte, T>(ref value.GetRawData()));
- }
- }
-
- for (int i = startIndex; i >= endIndex; i--)
- {
- object? obj = array.GetValue(i);
- if (obj == null)
- {
- if (value == null)
- return i;
- }
- else
- {
- if (obj.Equals(value))
- return i;
- }
- }
- return lb - 1; // Return lb-1 for arrays with negative lower bounds.
- }
-
- public static int LastIndexOf<T>(T[] array, T value)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- return LastIndexOf(array, value, array.Length - 1, array.Length);
- }
-
- public static int LastIndexOf<T>(T[] array, T value, int startIndex)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
- // if array is empty and startIndex is 0, we need to pass 0 as count
- return LastIndexOf(array, value, startIndex, (array.Length == 0) ? 0 : (startIndex + 1));
- }
-
- public static int LastIndexOf<T>(T[] array, T value, int startIndex, int count)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (array.Length == 0)
- {
- //
- // Special case for 0 length List
- // accept -1 and 0 as valid startIndex for compablility reason.
- //
- if (startIndex != -1 && startIndex != 0)
- {
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- }
-
- // only 0 is a valid value for count if array is empty
- if (count != 0)
- {
- ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
- }
- return -1;
- }
-
- // Make sure we're not out of range
- if ((uint)startIndex >= (uint)array.Length)
- {
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- }
-
- // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
- if (count < 0 || startIndex - count + 1 < 0)
- {
- ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
- }
-
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- {
- int endIndex = startIndex - count + 1;
- int result = SpanHelpers.LastIndexOf(
- ref Unsafe.Add(ref array.GetRawSzArrayData(), endIndex),
- Unsafe.As<T, byte>(ref value),
- count);
-
- return (result >= 0 ? endIndex : 0) + result;
- }
- else if (Unsafe.SizeOf<T>() == sizeof(char))
- {
- int endIndex = startIndex - count + 1;
- int result = SpanHelpers.LastIndexOf(
- ref Unsafe.Add(ref Unsafe.As<byte, char>(ref array.GetRawSzArrayData()), endIndex),
- Unsafe.As<T, char>(ref value),
- count);
-
- return (result >= 0 ? endIndex : 0) + result;
- }
- else if (Unsafe.SizeOf<T>() == sizeof(int))
- {
- int endIndex = startIndex - count + 1;
- int result = SpanHelpers.LastIndexOf(
- ref Unsafe.Add(ref Unsafe.As<byte, int>(ref array.GetRawSzArrayData()), endIndex),
- Unsafe.As<T, int>(ref value),
- count);
-
- return (result >= 0 ? endIndex : 0) + result;
- }
- else if (Unsafe.SizeOf<T>() == sizeof(long))
- {
- int endIndex = startIndex - count + 1;
- int result = SpanHelpers.LastIndexOf(
- ref Unsafe.Add(ref Unsafe.As<byte, long>(ref array.GetRawSzArrayData()), endIndex),
- Unsafe.As<T, long>(ref value),
- count);
-
- return (result >= 0 ? endIndex : 0) + result;
- }
- }
-
-#if !CORERT
- return EqualityComparer<T>.Default.LastIndexOf(array, value, startIndex, count);
-#else
- return LastIndexOfImpl(array, value, startIndex, count);
-#endif
- }
-
- // Reverses all elements of the given array. Following a call to this
- // method, an element previously located at index i will now be
- // located at index length - i - 1, where length is the
- // length of the array.
- //
- public static void Reverse(Array array)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- Reverse(array, array.GetLowerBound(0), array.Length);
- }
-
- // Reverses the elements in a range of an array. Following a call to this
- // method, an element in the range given by index and count
- // which was previously located at index i will now be located at
- // index index + (index + count - i - 1).
- // Reliability note: This may fail because it may have to box objects.
- //
- public static void Reverse(Array array, int index, int length)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lowerBound = array.GetLowerBound(0);
- if (index < lowerBound)
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- if (length < 0)
- ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
-
- if (array.Length - (index - lowerBound) < length)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
- if (array.Rank != 1)
- ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
-
- if (length <= 1)
- return;
-
- int adjustedIndex = index - lowerBound;
- switch (array.GetCorElementTypeOfElementType())
- {
- case CorElementType.ELEMENT_TYPE_I1:
- case CorElementType.ELEMENT_TYPE_U1:
- case CorElementType.ELEMENT_TYPE_BOOLEAN:
- UnsafeArrayAsSpan<byte>(array, adjustedIndex, length).Reverse();
- return;
- case CorElementType.ELEMENT_TYPE_I2:
- case CorElementType.ELEMENT_TYPE_U2:
- case CorElementType.ELEMENT_TYPE_CHAR:
- UnsafeArrayAsSpan<short>(array, adjustedIndex, length).Reverse();
- return;
- case CorElementType.ELEMENT_TYPE_I4:
- case CorElementType.ELEMENT_TYPE_U4:
-#if !BIT64
- case CorElementType.ELEMENT_TYPE_I:
- case CorElementType.ELEMENT_TYPE_U:
-#endif
- case CorElementType.ELEMENT_TYPE_R4:
- UnsafeArrayAsSpan<int>(array, adjustedIndex, length).Reverse();
- return;
- case CorElementType.ELEMENT_TYPE_I8:
- case CorElementType.ELEMENT_TYPE_U8:
-#if BIT64
- case CorElementType.ELEMENT_TYPE_I:
- case CorElementType.ELEMENT_TYPE_U:
-#endif
- case CorElementType.ELEMENT_TYPE_R8:
- UnsafeArrayAsSpan<long>(array, adjustedIndex, length).Reverse();
- return;
- case CorElementType.ELEMENT_TYPE_OBJECT:
- case CorElementType.ELEMENT_TYPE_ARRAY:
- case CorElementType.ELEMENT_TYPE_SZARRAY:
- UnsafeArrayAsSpan<object>(array, adjustedIndex, length).Reverse();
- return;
- }
-
- int i = index;
- int j = index + length - 1;
- while (i < j)
- {
- object? temp = array.GetValue(i);
- array.SetValue(array.GetValue(j), i);
- array.SetValue(temp, j);
- i++;
- j--;
- }
- }
-
- public static void Reverse<T>(T[] array)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- Reverse(array, 0, array.Length);
- }
-
- public static void Reverse<T>(T[] array, int index, int length)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (index < 0)
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- if (length < 0)
- ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
- if (array.Length - index < length)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
-
- if (length <= 1)
- return;
-
- ref T first = ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), index);
- ref T last = ref Unsafe.Add(ref Unsafe.Add(ref first, length), -1);
- do
- {
- T temp = first;
- first = last;
- last = temp;
- first = ref Unsafe.Add(ref first, 1);
- last = ref Unsafe.Add(ref last, -1);
- } while (Unsafe.IsAddressLessThan(ref first, ref last));
- }
-
- // Sorts the elements of an array. The sort compares the elements to each
- // other using the IComparable interface, which must be implemented
- // by all elements of the array.
- //
- public static void Sort(Array array)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- Sort(array, null, array.GetLowerBound(0), array.Length, null);
- }
-
- // Sorts the elements of two arrays based on the keys in the first array.
- // Elements in the keys array specify the sort keys for
- // corresponding elements in the items array. The sort compares the
- // keys to each other using the IComparable interface, which must be
- // implemented by all elements of the keys array.
- //
- public static void Sort(Array keys, Array? items)
- {
- if (keys == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
- Sort(keys, items, keys.GetLowerBound(0), keys.Length, null);
- }
-
- // Sorts the elements in a section of an array. The sort compares the
- // elements to each other using the IComparable interface, which
- // must be implemented by all elements in the given section of the array.
- //
- public static void Sort(Array array, int index, int length)
- {
- Sort(array, null, index, length, null);
- }
-
- // Sorts the elements in a section of two arrays based on the keys in the
- // first array. Elements in the keys array specify the sort keys for
- // corresponding elements in the items array. The sort compares the
- // keys to each other using the IComparable interface, which must be
- // implemented by all elements of the keys array.
- //
- public static void Sort(Array keys, Array? items, int index, int length)
- {
- Sort(keys, items, index, length, null);
- }
-
- // Sorts the elements of an array. The sort compares the elements to each
- // other using the given IComparer interface. If comparer is
- // null, the elements are compared to each other using the
- // IComparable interface, which in that case must be implemented by
- // all elements of the array.
- //
- public static void Sort(Array array, IComparer? comparer)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- Sort(array, null, array.GetLowerBound(0), array.Length, comparer);
- }
-
- // Sorts the elements of two arrays based on the keys in the first array.
- // Elements in the keys array specify the sort keys for
- // corresponding elements in the items array. The sort compares the
- // keys to each other using the given IComparer interface. If
- // comparer is null, the elements are compared to each other using
- // the IComparable interface, which in that case must be implemented
- // by all elements of the keys array.
- //
- public static void Sort(Array keys, Array? items, IComparer? comparer)
- {
- if (keys == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
- Sort(keys, items, keys.GetLowerBound(0), keys.Length, comparer);
- }
-
- // Sorts the elements in a section of an array. The sort compares the
- // elements to each other using the given IComparer interface. If
- // comparer is null, the elements are compared to each other using
- // the IComparable interface, which in that case must be implemented
- // by all elements in the given section of the array.
- //
- public static void Sort(Array array, int index, int length, IComparer? comparer)
- {
- Sort(array, null, index, length, comparer);
- }
-
- // Sorts the elements in a section of two arrays based on the keys in the
- // first array. Elements in the keys array specify the sort keys for
- // corresponding elements in the items array. The sort compares the
- // keys to each other using the given IComparer interface. If
- // comparer is null, the elements are compared to each other using
- // the IComparable interface, which in that case must be implemented
- // by all elements of the given section of the keys array.
- //
- public static void Sort(Array keys, Array? items, int index, int length, IComparer? comparer)
- {
- if (keys == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
- if (keys.Rank != 1 || (items != null && items.Rank != 1))
- ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
- int keysLowerBound = keys.GetLowerBound(0);
- if (items != null && keysLowerBound != items.GetLowerBound(0))
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_LowerBoundsMustMatch);
- if (index < keysLowerBound)
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- if (length < 0)
- ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
-
- if (keys.Length - (index - keysLowerBound) < length || (items != null && (index - keysLowerBound) > items.Length - length))
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
-
- if (length <= 1)
- return;
-
- comparer ??= Comparer.Default;
-
- if (keys is object[] objKeys)
- {
- object[]? objItems = items as object[];
- if (items == null || objItems != null)
- {
- new SorterObjectArray(objKeys, objItems, comparer).Sort(index, length);
- return;
- }
- }
-
- if (comparer == Comparer.Default)
- {
- CorElementType et = keys.GetCorElementTypeOfElementType();
- if (items == null || items.GetCorElementTypeOfElementType() == et)
- {
- int adjustedIndex = index - keysLowerBound;
- switch (et)
- {
- case CorElementType.ELEMENT_TYPE_I1:
- GenericSort<sbyte>(keys, items, adjustedIndex, length);
- return;
- case CorElementType.ELEMENT_TYPE_U1:
- case CorElementType.ELEMENT_TYPE_BOOLEAN:
- GenericSort<byte>(keys, items, adjustedIndex, length);
- return;
- case CorElementType.ELEMENT_TYPE_I2:
- GenericSort<short>(keys, items, adjustedIndex, length);
- return;
- case CorElementType.ELEMENT_TYPE_U2:
- case CorElementType.ELEMENT_TYPE_CHAR:
- GenericSort<ushort>(keys, items, adjustedIndex, length);
- return;
- case CorElementType.ELEMENT_TYPE_I4:
- GenericSort<int>(keys, items, adjustedIndex, length);
- return;
- case CorElementType.ELEMENT_TYPE_U4:
- GenericSort<uint>(keys, items, adjustedIndex, length);
- return;
- case CorElementType.ELEMENT_TYPE_I8:
- GenericSort<long>(keys, items, adjustedIndex, length);
- return;
- case CorElementType.ELEMENT_TYPE_U8:
- GenericSort<ulong>(keys, items, adjustedIndex, length);
- return;
- case CorElementType.ELEMENT_TYPE_R4:
- GenericSort<float>(keys, items, adjustedIndex, length);
- return;
- case CorElementType.ELEMENT_TYPE_R8:
- GenericSort<double>(keys, items, adjustedIndex, length);
- return;
- case CorElementType.ELEMENT_TYPE_I:
- case CorElementType.ELEMENT_TYPE_U:
- // IntPtr/UIntPtr does not implement IComparable
- break;
- }
-
- static void GenericSort<T>(Array keys, Array? items, int adjustedIndex, int length) where T: struct
- {
- Span<T> keysSpan = UnsafeArrayAsSpan<T>(keys, adjustedIndex, length);
- if (items != null)
- {
- keysSpan.Sort<T, T>(UnsafeArrayAsSpan<T>(items, adjustedIndex, length));
- }
- else
- {
- keysSpan.Sort<T>();
- }
- }
- }
- }
-
- new SorterGenericArray(keys, items, comparer).Sort(index, length);
- }
-
- public static void Sort<T>(T[] array)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
-
- if (array.Length > 1)
- {
- var span = new Span<T>(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), array.Length);
- ArraySortHelper<T>.Default.Sort(span, null);
- }
- }
-
- public static void Sort<TKey, TValue>(TKey[] keys, TValue[]? items)
- {
- if (keys == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
- Sort<TKey, TValue>(keys, items, 0, keys.Length, null);
- }
-
- public static void Sort<T>(T[] array, int index, int length)
- {
- Sort<T>(array, index, length, null);
- }
-
- public static void Sort<TKey, TValue>(TKey[] keys, TValue[]? items, int index, int length)
- {
- Sort<TKey, TValue>(keys, items, index, length, null);
- }
-
- public static void Sort<T>(T[] array, System.Collections.Generic.IComparer<T>? comparer)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- Sort<T>(array, 0, array.Length, comparer);
- }
-
- public static void Sort<TKey, TValue>(TKey[] keys, TValue[]? items, System.Collections.Generic.IComparer<TKey>? comparer)
- {
- if (keys == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
- Sort<TKey, TValue>(keys, items, 0, keys.Length, comparer);
- }
-
- public static void Sort<T>(T[] array, int index, int length, System.Collections.Generic.IComparer<T>? comparer)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (index < 0)
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- if (length < 0)
- ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
- if (array.Length - index < length)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
-
- if (length > 1)
- {
- var span = new Span<T>(ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), index), length);
- ArraySortHelper<T>.Default.Sort(span, comparer);
- }
- }
-
- public static void Sort<TKey, TValue>(TKey[] keys, TValue[]? items, int index, int length, System.Collections.Generic.IComparer<TKey>? comparer)
- {
- if (keys == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
- if (index < 0)
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- if (length < 0)
- ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
- if (keys.Length - index < length || (items != null && index > items.Length - length))
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
-
- if (length > 1)
- {
- if (items == null)
- {
- Sort<TKey>(keys, index, length, comparer);
- return;
- }
-
- var spanKeys = new Span<TKey>(ref Unsafe.Add(ref Unsafe.As<byte, TKey>(ref keys.GetRawSzArrayData()), index), length);
- var spanItems = new Span<TValue>(ref Unsafe.Add(ref Unsafe.As<byte, TValue>(ref items.GetRawSzArrayData()), index), length);
- ArraySortHelper<TKey, TValue>.Default.Sort(spanKeys, spanItems, comparer);
- }
- }
-
- public static void Sort<T>(T[] array, Comparison<T> comparison)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (comparison == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison);
- }
-
- var span = new Span<T>(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), array.Length);
- ArraySortHelper<T>.Sort(span, comparison);
- }
-
- public static bool TrueForAll<T>(T[] array, Predicate<T> match)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- for (int i = 0; i < array.Length; i++)
- {
- if (!match(array[i]))
- {
- return false;
- }
- }
- return true;
- }
-
- // Private value type used by the Sort methods.
- private readonly struct SorterObjectArray
- {
- private readonly object[] keys;
- private readonly object?[]? items;
- private readonly IComparer comparer;
-
- internal SorterObjectArray(object[] keys, object?[]? items, IComparer comparer)
- {
- this.keys = keys;
- this.items = items;
- this.comparer = comparer;
- }
-
- internal void SwapIfGreater(int a, int b)
- {
- if (a != b)
- {
- if (comparer.Compare(keys[a], keys[b]) > 0)
- {
- object temp = keys[a];
- keys[a] = keys[b];
- keys[b] = temp;
- if (items != null)
- {
- object? item = items[a];
- items[a] = items[b];
- items[b] = item;
- }
- }
- }
- }
-
- private void Swap(int i, int j)
- {
- object t = keys[i];
- keys[i] = keys[j];
- keys[j] = t;
-
- if (items != null)
- {
- object? item = items[i];
- items[i] = items[j];
- items[j] = item;
- }
- }
-
- internal void Sort(int left, int length)
- {
- IntrospectiveSort(left, length);
- }
-
- private void IntrospectiveSort(int left, int length)
- {
- if (length < 2)
- return;
-
- try
- {
- IntroSort(left, length + left - 1, 2 * IntrospectiveSortUtilities.FloorLog2PlusOne(length));
- }
- catch (IndexOutOfRangeException)
- {
- IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
- }
- catch (Exception e)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
- }
- }
-
- private void IntroSort(int lo, int hi, int depthLimit)
- {
- while (hi > lo)
- {
- int partitionSize = hi - lo + 1;
- if (partitionSize <= IntrospectiveSortUtilities.IntrosortSizeThreshold)
- {
- if (partitionSize == 1)
- {
- return;
- }
- if (partitionSize == 2)
- {
- SwapIfGreater(lo, hi);
- return;
- }
- if (partitionSize == 3)
- {
- SwapIfGreater(lo, hi - 1);
- SwapIfGreater(lo, hi);
- SwapIfGreater(hi - 1, hi);
- return;
- }
-
- InsertionSort(lo, hi);
- return;
- }
-
- if (depthLimit == 0)
- {
- Heapsort(lo, hi);
- return;
- }
- depthLimit--;
-
- int p = PickPivotAndPartition(lo, hi);
- IntroSort(p + 1, hi, depthLimit);
- hi = p - 1;
- }
- }
-
- private int PickPivotAndPartition(int lo, int hi)
- {
- // Compute median-of-three. But also partition them, since we've done the comparison.
- int mid = lo + (hi - lo) / 2;
- // Sort lo, mid and hi appropriately, then pick mid as the pivot.
- SwapIfGreater(lo, mid);
- SwapIfGreater(lo, hi);
- SwapIfGreater(mid, hi);
-
- object pivot = keys[mid];
- Swap(mid, hi - 1);
- int left = lo, right = hi - 1; // We already partitioned lo and hi and put the pivot in hi - 1. And we pre-increment & decrement below.
-
- while (left < right)
- {
- while (comparer.Compare(keys[++left], pivot) < 0) ;
- while (comparer.Compare(pivot, keys[--right]) < 0) ;
-
- if (left >= right)
- break;
-
- Swap(left, right);
- }
-
- // Put pivot in the right location.
- Swap(left, hi - 1);
- return left;
- }
-
- private void Heapsort(int lo, int hi)
- {
- int n = hi - lo + 1;
- for (int i = n / 2; i >= 1; i--)
- {
- DownHeap(i, n, lo);
- }
- for (int i = n; i > 1; i--)
- {
- Swap(lo, lo + i - 1);
-
- DownHeap(1, i - 1, lo);
- }
- }
-
- private void DownHeap(int i, int n, int lo)
- {
- object d = keys[lo + i - 1];
- object? dt = items?[lo + i - 1];
- int child;
- while (i <= n / 2)
- {
- child = 2 * i;
- if (child < n && comparer.Compare(keys[lo + child - 1], keys[lo + child]) < 0)
- {
- child++;
- }
- if (!(comparer.Compare(d, keys[lo + child - 1]) < 0))
- break;
- keys[lo + i - 1] = keys[lo + child - 1];
- if (items != null)
- items[lo + i - 1] = items[lo + child - 1];
- i = child;
- }
- keys[lo + i - 1] = d;
- if (items != null)
- items[lo + i - 1] = dt;
- }
-
- private void InsertionSort(int lo, int hi)
- {
- int i, j;
- object t;
- object? ti;
- for (i = lo; i < hi; i++)
- {
- j = i;
- t = keys[i + 1];
- ti = items?[i + 1];
- while (j >= lo && comparer.Compare(t, keys[j]) < 0)
- {
- keys[j + 1] = keys[j];
- if (items != null)
- items[j + 1] = items[j];
- j--;
- }
- keys[j + 1] = t;
- if (items != null)
- items[j + 1] = ti;
- }
- }
- }
-
- // Private value used by the Sort methods for instances of Array.
- // This is slower than the one for Object[], since we can't use the JIT helpers
- // to access the elements. We must use GetValue & SetValue.
- private readonly struct SorterGenericArray
- {
- private readonly Array keys;
- private readonly Array? items;
- private readonly IComparer comparer;
-
- internal SorterGenericArray(Array keys, Array? items, IComparer comparer)
- {
- this.keys = keys;
- this.items = items;
- this.comparer = comparer;
- }
-
- internal void SwapIfGreater(int a, int b)
- {
- if (a != b)
- {
- if (comparer.Compare(keys.GetValue(a), keys.GetValue(b)) > 0)
- {
- object? key = keys.GetValue(a);
- keys.SetValue(keys.GetValue(b), a);
- keys.SetValue(key, b);
- if (items != null)
- {
- object? item = items.GetValue(a);
- items.SetValue(items.GetValue(b), a);
- items.SetValue(item, b);
- }
- }
- }
- }
-
- private void Swap(int i, int j)
- {
- object? t1 = keys.GetValue(i);
- keys.SetValue(keys.GetValue(j), i);
- keys.SetValue(t1, j);
-
- if (items != null)
- {
- object? t2 = items.GetValue(i);
- items.SetValue(items.GetValue(j), i);
- items.SetValue(t2, j);
- }
- }
-
- internal void Sort(int left, int length)
- {
- IntrospectiveSort(left, length);
- }
-
- private void IntrospectiveSort(int left, int length)
- {
- if (length < 2)
- return;
-
- try
- {
- IntroSort(left, length + left - 1, 2 * IntrospectiveSortUtilities.FloorLog2PlusOne(length));
- }
- catch (IndexOutOfRangeException)
- {
- IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
- }
- catch (Exception e)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e);
- }
- }
-
- private void IntroSort(int lo, int hi, int depthLimit)
- {
- while (hi > lo)
- {
- int partitionSize = hi - lo + 1;
- if (partitionSize <= IntrospectiveSortUtilities.IntrosortSizeThreshold)
- {
- if (partitionSize == 1)
- {
- return;
- }
- if (partitionSize == 2)
- {
- SwapIfGreater(lo, hi);
- return;
- }
- if (partitionSize == 3)
- {
- SwapIfGreater(lo, hi - 1);
- SwapIfGreater(lo, hi);
- SwapIfGreater(hi - 1, hi);
- return;
- }
-
- InsertionSort(lo, hi);
- return;
- }
-
- if (depthLimit == 0)
- {
- Heapsort(lo, hi);
- return;
- }
- depthLimit--;
-
- int p = PickPivotAndPartition(lo, hi);
- IntroSort(p + 1, hi, depthLimit);
- hi = p - 1;
- }
- }
-
- private int PickPivotAndPartition(int lo, int hi)
- {
- // Compute median-of-three. But also partition them, since we've done the comparison.
- int mid = lo + (hi - lo) / 2;
-
- SwapIfGreater(lo, mid);
- SwapIfGreater(lo, hi);
- SwapIfGreater(mid, hi);
-
- object? pivot = keys.GetValue(mid);
- Swap(mid, hi - 1);
- int left = lo, right = hi - 1; // We already partitioned lo and hi and put the pivot in hi - 1. And we pre-increment & decrement below.
-
- while (left < right)
- {
- while (comparer.Compare(keys.GetValue(++left), pivot) < 0) ;
- while (comparer.Compare(pivot, keys.GetValue(--right)) < 0) ;
-
- if (left >= right)
- break;
-
- Swap(left, right);
- }
-
- // Put pivot in the right location.
- Swap(left, hi - 1);
- return left;
- }
-
- private void Heapsort(int lo, int hi)
- {
- int n = hi - lo + 1;
- for (int i = n / 2; i >= 1; i--)
- {
- DownHeap(i, n, lo);
- }
- for (int i = n; i > 1; i--)
- {
- Swap(lo, lo + i - 1);
-
- DownHeap(1, i - 1, lo);
- }
- }
-
- private void DownHeap(int i, int n, int lo)
- {
- object? d = keys.GetValue(lo + i - 1);
- object? dt = items?.GetValue(lo + i - 1);
- int child;
- while (i <= n / 2)
- {
- child = 2 * i;
- if (child < n && comparer.Compare(keys.GetValue(lo + child - 1), keys.GetValue(lo + child)) < 0)
- {
- child++;
- }
-
- if (!(comparer.Compare(d, keys.GetValue(lo + child - 1)) < 0))
- break;
-
- keys.SetValue(keys.GetValue(lo + child - 1), lo + i - 1);
- if (items != null)
- items.SetValue(items.GetValue(lo + child - 1), lo + i - 1);
- i = child;
- }
- keys.SetValue(d, lo + i - 1);
- if (items != null)
- items.SetValue(dt, lo + i - 1);
- }
-
- private void InsertionSort(int lo, int hi)
- {
- int i, j;
- object? t;
- object? dt;
- for (i = lo; i < hi; i++)
- {
- j = i;
- t = keys.GetValue(i + 1);
- dt = items?.GetValue(i + 1);
-
- while (j >= lo && comparer.Compare(t, keys.GetValue(j)) < 0)
- {
- keys.SetValue(keys.GetValue(j), j + 1);
- if (items != null)
- items.SetValue(items.GetValue(j), j + 1);
- j--;
- }
-
- keys.SetValue(t, j + 1);
- if (items != null)
- items.SetValue(dt, j + 1);
- }
- }
- }
-
- private static Span<T> UnsafeArrayAsSpan<T>(Array array, int adjustedIndex, int length) =>
- new Span<T>(ref Unsafe.As<byte, T>(ref array.GetRawArrayData()), array.Length).Slice(adjustedIndex, length);
-
-#if !CORERT
- public IEnumerator GetEnumerator()
- {
- int lowerBound = GetLowerBound(0);
- if (Rank == 1 && lowerBound == 0)
- return new SZArrayEnumerator(this);
- else
- return new ArrayEnumerator(this, lowerBound, Length);
- }
-#endif // !CORERT
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ArraySegment.cs b/netcore/System.Private.CoreLib/shared/System/ArraySegment.cs
deleted file mode 100644
index d99be334efb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ArraySegment.cs
+++ /dev/null
@@ -1,326 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Convenient wrapper for an array, an offset, and
-** a count. Ideally used in streams & collections.
-** Net Classes will consume an array of these.
-**
-**
-===========================================================*/
-
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace System
-{
- // Note: users should make sure they copy the fields out of an ArraySegment onto their stack
- // then validate that the fields describe valid bounds within the array. This must be done
- // because assignments to value types are not atomic, and also because one thread reading
- // three fields from an ArraySegment may not see the same ArraySegment from one call to another
- // (ie, users could assign a new value to the old location).
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct ArraySegment<T> : IList<T>, IReadOnlyList<T>
- {
- // Do not replace the array allocation with Array.Empty. We don't want to have the overhead of
- // instantiating another generic type in addition to ArraySegment<T> for new type parameters.
-#pragma warning disable CA1825
- public static ArraySegment<T> Empty { get; } = new ArraySegment<T>(new T[0]);
-#pragma warning restore CA1825
-
- private readonly T[]? _array; // Do not rename (binary serialization)
- private readonly int _offset; // Do not rename (binary serialization)
- private readonly int _count; // Do not rename (binary serialization)
-
- public ArraySegment(T[] array)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
-
- _array = array;
- _offset = 0;
- _count = array.Length;
- }
-
- public ArraySegment(T[] array, int offset, int count)
- {
- // Validate arguments, check is minimal instructions with reduced branching for inlinable fast-path
- // Negative values discovered though conversion to high values when converted to unsigned
- // Failure should be rare and location determination and message is delegated to failure functions
- if (array == null || (uint)offset > (uint)array.Length || (uint)count > (uint)(array.Length - offset))
- ThrowHelper.ThrowArraySegmentCtorValidationFailedExceptions(array, offset, count);
-
- _array = array;
- _offset = offset;
- _count = count;
- }
-
- public T[]? Array => _array;
-
- public int Offset => _offset;
-
- public int Count => _count;
-
- public T this[int index]
- {
- get
- {
- if ((uint)index >= (uint)_count)
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
-
- return _array![_offset + index];
- }
- set
- {
- if ((uint)index >= (uint)_count)
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
-
- _array![_offset + index] = value;
- }
- }
-
- public Enumerator GetEnumerator()
- {
- ThrowInvalidOperationIfDefault();
- return new Enumerator(this);
- }
-
- public override int GetHashCode() =>
- _array is null ? 0 : HashCode.Combine(_offset, _count, _array.GetHashCode());
-
- public void CopyTo(T[] destination) => CopyTo(destination, 0);
-
- public void CopyTo(T[] destination, int destinationIndex)
- {
- ThrowInvalidOperationIfDefault();
- System.Array.Copy(_array!, _offset, destination, destinationIndex, _count);
- }
-
- public void CopyTo(ArraySegment<T> destination)
- {
- ThrowInvalidOperationIfDefault();
- destination.ThrowInvalidOperationIfDefault();
-
- if (_count > destination._count)
- {
- ThrowHelper.ThrowArgumentException_DestinationTooShort();
- }
-
- System.Array.Copy(_array!, _offset, destination._array!, destination._offset, _count);
- }
-
- public override bool Equals(object? obj) =>
- obj is ArraySegment<T> && Equals((ArraySegment<T>)obj);
-
- public bool Equals(ArraySegment<T> obj) =>
- obj._array == _array && obj._offset == _offset && obj._count == _count;
-
- public ArraySegment<T> Slice(int index)
- {
- ThrowInvalidOperationIfDefault();
-
- if ((uint)index > (uint)_count)
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
-
- return new ArraySegment<T>(_array!, _offset + index, _count - index);
- }
-
- public ArraySegment<T> Slice(int index, int count)
- {
- ThrowInvalidOperationIfDefault();
-
- if ((uint)index > (uint)_count || (uint)count > (uint)(_count - index))
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
-
- return new ArraySegment<T>(_array!, _offset + index, count);
- }
-
- public T[] ToArray()
- {
- ThrowInvalidOperationIfDefault();
-
- if (_count == 0)
- {
- return Empty._array!;
- }
-
- var array = new T[_count];
- System.Array.Copy(_array!, _offset, array, 0, _count);
- return array;
- }
-
- public static bool operator ==(ArraySegment<T> a, ArraySegment<T> b) => a.Equals(b);
-
- public static bool operator !=(ArraySegment<T> a, ArraySegment<T> b) => !(a == b);
-
- public static implicit operator ArraySegment<T>(T[] array) => array != null ? new ArraySegment<T>(array) : default;
-
- #region IList<T>
- T IList<T>.this[int index]
- {
- get
- {
- ThrowInvalidOperationIfDefault();
- if (index < 0 || index >= _count)
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
-
- return _array![_offset + index];
- }
-
- set
- {
- ThrowInvalidOperationIfDefault();
- if (index < 0 || index >= _count)
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
-
- _array![_offset + index] = value;
- }
- }
-
- int IList<T>.IndexOf(T item)
- {
- ThrowInvalidOperationIfDefault();
-
- int index = System.Array.IndexOf<T>(_array!, item, _offset, _count);
-
- Debug.Assert(index == -1 ||
- (index >= _offset && index < _offset + _count));
-
- return index >= 0 ? index - _offset : -1;
- }
-
- void IList<T>.Insert(int index, T item) => ThrowHelper.ThrowNotSupportedException();
-
- void IList<T>.RemoveAt(int index) => ThrowHelper.ThrowNotSupportedException();
- #endregion
-
- #region IReadOnlyList<T>
- T IReadOnlyList<T>.this[int index]
- {
- get
- {
- ThrowInvalidOperationIfDefault();
- if (index < 0 || index >= _count)
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
-
- return _array![_offset + index];
- }
- }
- #endregion IReadOnlyList<T>
-
- #region ICollection<T>
- bool ICollection<T>.IsReadOnly =>
- // the indexer setter does not throw an exception although IsReadOnly is true.
- // This is to match the behavior of arrays.
- true;
-
- void ICollection<T>.Add(T item) => ThrowHelper.ThrowNotSupportedException();
-
- void ICollection<T>.Clear() => ThrowHelper.ThrowNotSupportedException();
-
- bool ICollection<T>.Contains(T item)
- {
- ThrowInvalidOperationIfDefault();
-
- int index = System.Array.IndexOf<T>(_array!, item, _offset, _count);
-
- Debug.Assert(index == -1 ||
- (index >= _offset && index < _offset + _count));
-
- return index >= 0;
- }
-
- bool ICollection<T>.Remove(T item)
- {
- ThrowHelper.ThrowNotSupportedException();
- return default;
- }
- #endregion
-
- #region IEnumerable<T>
-
- IEnumerator<T> IEnumerable<T>.GetEnumerator() => GetEnumerator();
- #endregion
-
- #region IEnumerable
-
- IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
- #endregion
-
- private void ThrowInvalidOperationIfDefault()
- {
- if (_array == null)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_NullArray);
- }
- }
-
- public struct Enumerator : IEnumerator<T>
- {
- private readonly T[]? _array;
- private readonly int _start;
- private readonly int _end; // cache Offset + Count, since it's a little slow
- private int _current;
-
- internal Enumerator(ArraySegment<T> arraySegment)
- {
- Debug.Assert(arraySegment.Array != null);
- Debug.Assert(arraySegment.Offset >= 0);
- Debug.Assert(arraySegment.Count >= 0);
- Debug.Assert(arraySegment.Offset + arraySegment.Count <= arraySegment.Array.Length);
-
- _array = arraySegment.Array;
- _start = arraySegment.Offset;
- _end = arraySegment.Offset + arraySegment.Count;
- _current = arraySegment.Offset - 1;
- }
-
- public bool MoveNext()
- {
- if (_current < _end)
- {
- _current++;
- return _current < _end;
- }
- return false;
- }
-
- public T Current
- {
- get
- {
- if (_current < _start)
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumNotStarted();
- if (_current >= _end)
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded();
- return _array![_current];
- }
- }
-
- object? IEnumerator.Current => Current;
-
- void IEnumerator.Reset()
- {
- _current = _start - 1;
- }
-
- public void Dispose()
- {
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ArrayTypeMismatchException.cs b/netcore/System.Private.CoreLib/shared/System/ArrayTypeMismatchException.cs
deleted file mode 100644
index cb1fa437773..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ArrayTypeMismatchException.cs
+++ /dev/null
@@ -1,53 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: The arrays are of different primitive types.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- // The ArrayMismatchException is thrown when an attempt to store
- // an object of the wrong type within an array occurs.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ArrayTypeMismatchException : SystemException
- {
- // Creates a new ArrayMismatchException with its message string set to
- // the empty string, its HRESULT set to COR_E_ARRAYTYPEMISMATCH,
- // and its ExceptionInfo reference set to null.
- public ArrayTypeMismatchException()
- : base(SR.Arg_ArrayTypeMismatchException)
- {
- HResult = HResults.COR_E_ARRAYTYPEMISMATCH;
- }
-
- // Creates a new ArrayMismatchException with its message string set to
- // message, its HRESULT set to COR_E_ARRAYTYPEMISMATCH,
- // and its ExceptionInfo reference set to null.
- //
- public ArrayTypeMismatchException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_ARRAYTYPEMISMATCH;
- }
-
- public ArrayTypeMismatchException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_ARRAYTYPEMISMATCH;
- }
-
- protected ArrayTypeMismatchException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AssemblyLoadEventArgs.cs b/netcore/System.Private.CoreLib/shared/System/AssemblyLoadEventArgs.cs
deleted file mode 100644
index d7e52496933..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AssemblyLoadEventArgs.cs
+++ /dev/null
@@ -1,18 +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 System.Reflection;
-
-namespace System
-{
- public class AssemblyLoadEventArgs : EventArgs
- {
- public AssemblyLoadEventArgs(Assembly loadedAssembly)
- {
- LoadedAssembly = loadedAssembly;
- }
-
- public Assembly LoadedAssembly { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AssemblyLoadEventHandler.cs b/netcore/System.Private.CoreLib/shared/System/AssemblyLoadEventHandler.cs
deleted file mode 100644
index 0d5a2823c91..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AssemblyLoadEventHandler.cs
+++ /dev/null
@@ -1,8 +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.
-
-namespace System
-{
- public delegate void AssemblyLoadEventHandler(object? sender, AssemblyLoadEventArgs args);
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AsyncCallback.cs b/netcore/System.Private.CoreLib/shared/System/AsyncCallback.cs
deleted file mode 100644
index 036d44a4b97..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AsyncCallback.cs
+++ /dev/null
@@ -1,16 +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.
-
-/*============================================================
-**
-** Interface: AsyncCallbackDelegate
-**
-** Purpose: Type of callback for async operations
-**
-===========================================================*/
-
-namespace System
-{
- public delegate void AsyncCallback(IAsyncResult ar);
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Attribute.cs b/netcore/System.Private.CoreLib/shared/System/Attribute.cs
deleted file mode 100644
index 8f33c3e9df7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Attribute.cs
+++ /dev/null
@@ -1,139 +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 System.Diagnostics;
-using System.Reflection;
-
-namespace System
-{
- [AttributeUsage(AttributeTargets.All, Inherited = true, AllowMultiple = false)]
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public abstract partial class Attribute
- {
- protected Attribute() { }
-
-#if !CORERT
- public override bool Equals(object? obj)
- {
- if (obj == null)
- return false;
-
- if (this.GetType() != obj.GetType())
- return false;
-
- Type thisType = this.GetType();
- object thisObj = this;
- object? thisResult, thatResult;
-
- while (thisType != typeof(Attribute))
- {
- FieldInfo[] thisFields = thisType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
-
- for (int i = 0; i < thisFields.Length; i++)
- {
- thisResult = thisFields[i].GetValue(thisObj);
- thatResult = thisFields[i].GetValue(obj);
-
- if (!AreFieldValuesEqual(thisResult, thatResult))
- {
- return false;
- }
- }
- thisType = thisType.BaseType!;
- }
-
- return true;
- }
-
- public override int GetHashCode()
- {
- Type type = GetType();
-
- while (type != typeof(Attribute))
- {
- FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
- object? vThis = null;
-
- for (int i = 0; i < fields.Length; i++)
- {
- object? fieldValue = fields[i].GetValue(this);
-
- // The hashcode of an array ignores the contents of the array, so it can produce
- // different hashcodes for arrays with the same contents.
- // Since we do deep comparisons of arrays in Equals(), this means Equals and GetHashCode will
- // be inconsistent for arrays. Therefore, we ignore hashes of arrays.
- if (fieldValue != null && !fieldValue.GetType().IsArray)
- vThis = fieldValue;
-
- if (vThis != null)
- break;
- }
-
- if (vThis != null)
- return vThis.GetHashCode();
-
- type = type.BaseType!;
- }
-
- return type.GetHashCode();
- }
-#endif
-
- // Compares values of custom-attribute fields.
- private static bool AreFieldValuesEqual(object? thisValue, object? thatValue)
- {
- if (thisValue == null && thatValue == null)
- return true;
- if (thisValue == null || thatValue == null)
- return false;
-
- Type thisValueType = thisValue.GetType();
-
- if (thisValueType.IsArray)
- {
- // Ensure both are arrays of the same type.
- if (!thisValueType.Equals(thatValue.GetType()))
- {
- return false;
- }
-
- Array thisValueArray = (Array)thisValue;
- Array thatValueArray = (Array)thatValue;
- if (thisValueArray.Length != thatValueArray.Length)
- {
- return false;
- }
-
- // Attributes can only contain single-dimension arrays, so we don't need to worry about
- // multidimensional arrays.
- Debug.Assert(thisValueArray.Rank == 1 && thatValueArray.Rank == 1);
- for (int j = 0; j < thisValueArray.Length; j++)
- {
- if (!AreFieldValuesEqual(thisValueArray.GetValue(j), thatValueArray.GetValue(j)))
- {
- return false;
- }
- }
- }
- else
- {
- // An object of type Attribute will cause a stack overflow.
- // However, this should never happen because custom attributes cannot contain values other than
- // constants, single-dimensional arrays and typeof expressions.
- Debug.Assert(!(thisValue is Attribute));
- if (!thisValue.Equals(thatValue))
- return false;
- }
-
- return true;
- }
-
- public virtual object TypeId => GetType();
-
- public virtual bool Match(object? obj) => Equals(obj);
-
- public virtual bool IsDefaultAttribute() => false;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AttributeTargets.cs b/netcore/System.Private.CoreLib/shared/System/AttributeTargets.cs
deleted file mode 100644
index c33d19e85ea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AttributeTargets.cs
+++ /dev/null
@@ -1,35 +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.
-
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-
-namespace System
-{
- // Enum used to indicate all the elements of the
- // VOS it is valid to attach this element to.
- [Flags]
- public enum AttributeTargets
- {
- Assembly = 0x0001,
- Module = 0x0002,
- Class = 0x0004,
- Struct = 0x0008,
- Enum = 0x0010,
- Constructor = 0x0020,
- Method = 0x0040,
- Property = 0x0080,
- Field = 0x0100,
- Event = 0x0200,
- Interface = 0x0400,
- Parameter = 0x0800,
- Delegate = 0x1000,
- ReturnValue = 0x2000,
- GenericParameter = 0x4000,
-
- All = Assembly | Module | Class | Struct | Enum | Constructor |
- Method | Property | Field | Event | Interface | Parameter |
- Delegate | ReturnValue | GenericParameter
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/AttributeUsageAttribute.cs b/netcore/System.Private.CoreLib/shared/System/AttributeUsageAttribute.cs
deleted file mode 100644
index bd94a49e44d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/AttributeUsageAttribute.cs
+++ /dev/null
@@ -1,52 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: The class denotes how to specify the usage of an attribute
-**
-**
-===========================================================*/
-
-namespace System
-{
- /* By default, attributes are inherited and multiple attributes are not allowed */
- [AttributeUsage(AttributeTargets.Class, Inherited = true)]
- public sealed class AttributeUsageAttribute : Attribute
- {
- private readonly AttributeTargets _attributeTarget; // Defaults to all
- private bool _allowMultiple = false; // Defaults to false
- private bool _inherited = true; // Defaults to true
-
- internal static readonly AttributeUsageAttribute Default = new AttributeUsageAttribute(AttributeTargets.All);
-
- public AttributeUsageAttribute(AttributeTargets validOn)
- {
- _attributeTarget = validOn;
- }
-
- internal AttributeUsageAttribute(AttributeTargets validOn, bool allowMultiple, bool inherited)
- {
- _attributeTarget = validOn;
- _allowMultiple = allowMultiple;
- _inherited = inherited;
- }
-
- public AttributeTargets ValidOn => _attributeTarget;
-
- public bool AllowMultiple
- {
- get => _allowMultiple;
- set => _allowMultiple = value;
- }
-
- public bool Inherited
- {
- get => _inherited;
- set => _inherited = value;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/BadImageFormatException.cs b/netcore/System.Private.CoreLib/shared/System/BadImageFormatException.cs
deleted file mode 100644
index c241eed32df..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/BadImageFormatException.cs
+++ /dev/null
@@ -1,118 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Exception to an invalid dll or executable format.
-**
-**
-===========================================================*/
-
-using System.IO;
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public partial class BadImageFormatException : SystemException
- {
- private readonly string? _fileName; // The name of the corrupt PE file.
- private readonly string? _fusionLog; // fusion log (when applicable)
-
- public BadImageFormatException()
- : base(SR.Arg_BadImageFormatException)
- {
- HResult = HResults.COR_E_BADIMAGEFORMAT;
- }
-
- public BadImageFormatException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_BADIMAGEFORMAT;
- }
-
- public BadImageFormatException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_BADIMAGEFORMAT;
- }
-
- public BadImageFormatException(string? message, string? fileName) : base(message)
- {
- HResult = HResults.COR_E_BADIMAGEFORMAT;
- _fileName = fileName;
- }
-
- public BadImageFormatException(string? message, string? fileName, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_BADIMAGEFORMAT;
- _fileName = fileName;
- }
-
- protected BadImageFormatException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- _fileName = info.GetString("BadImageFormat_FileName");
- _fusionLog = info.GetString("BadImageFormat_FusionLog");
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("BadImageFormat_FileName", _fileName, typeof(string));
- info.AddValue("BadImageFormat_FusionLog", _fusionLog, typeof(string));
- }
-
- public override string Message
- {
- get
- {
- SetMessageField();
- return _message!;
- }
- }
-
- private void SetMessageField()
- {
- if (_message == null)
- {
- if ((_fileName == null) &&
- (HResult == HResults.COR_E_EXCEPTION))
- _message = SR.Arg_BadImageFormatException;
- else
- _message = FileLoadException.FormatFileLoadExceptionMessage(_fileName, HResult);
- }
- }
-
- public string? FileName => _fileName;
-
- public override string ToString()
- {
- string s = GetType().ToString() + ": " + Message;
-
- if (!string.IsNullOrEmpty(_fileName))
- s += Environment.NewLineConst + SR.Format(SR.IO_FileName_Name, _fileName);
-
- if (InnerException != null)
- s += InnerExceptionPrefix + InnerException.ToString();
-
- if (StackTrace != null)
- s += Environment.NewLineConst + StackTrace;
-
- if (_fusionLog != null)
- {
- s ??= " ";
- s += Environment.NewLineConst + Environment.NewLineConst + _fusionLog;
- }
-
- return s;
- }
-
- public string? FusionLog => _fusionLog;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/BitConverter.cs b/netcore/System.Private.CoreLib/shared/System/BitConverter.cs
deleted file mode 100644
index 8085e9cb38a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/BitConverter.cs
+++ /dev/null
@@ -1,475 +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 System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- // The BitConverter class contains methods for
- // converting an array of bytes to one of the base data
- // types, as well as for converting a base data type to an
- // array of bytes.
- public static class BitConverter
- {
- // This field indicates the "endianess" of the architecture.
- // The value is set to true if the architecture is
- // little endian; false if it is big endian.
-#if BIGENDIAN
- [Intrinsic]
- public static readonly bool IsLittleEndian /* = false */;
-#else
- [Intrinsic]
- public static readonly bool IsLittleEndian = true;
-#endif
-
- // Converts a Boolean into an array of bytes with length one.
- public static byte[] GetBytes(bool value)
- {
- byte[] r = new byte[1];
- r[0] = (value ? (byte)1 : (byte)0);
- return r;
- }
-
- // Converts a Boolean into a Span of bytes with length one.
- public static bool TryWriteBytes(Span<byte> destination, bool value)
- {
- if (destination.Length < sizeof(byte))
- return false;
-
- Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value ? (byte)1 : (byte)0);
- return true;
- }
-
- // Converts a char into an array of bytes with length two.
- public static byte[] GetBytes(char value)
- {
- byte[] bytes = new byte[sizeof(char)];
- Unsafe.As<byte, char>(ref bytes[0]) = value;
- return bytes;
- }
-
- // Converts a char into a Span
- public static bool TryWriteBytes(Span<byte> destination, char value)
- {
- if (destination.Length < sizeof(char))
- return false;
-
- Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
- return true;
- }
-
- // Converts a short into an array of bytes with length
- // two.
- public static byte[] GetBytes(short value)
- {
- byte[] bytes = new byte[sizeof(short)];
- Unsafe.As<byte, short>(ref bytes[0]) = value;
- return bytes;
- }
-
- // Converts a short into a Span
- public static bool TryWriteBytes(Span<byte> destination, short value)
- {
- if (destination.Length < sizeof(short))
- return false;
-
- Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
- return true;
- }
-
- // Converts an int into an array of bytes with length
- // four.
- public static byte[] GetBytes(int value)
- {
- byte[] bytes = new byte[sizeof(int)];
- Unsafe.As<byte, int>(ref bytes[0]) = value;
- return bytes;
- }
-
- // Converts an int into a Span
- public static bool TryWriteBytes(Span<byte> destination, int value)
- {
- if (destination.Length < sizeof(int))
- return false;
-
- Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
- return true;
- }
-
- // Converts a long into an array of bytes with length
- // eight.
- public static byte[] GetBytes(long value)
- {
- byte[] bytes = new byte[sizeof(long)];
- Unsafe.As<byte, long>(ref bytes[0]) = value;
- return bytes;
- }
-
- // Converts a long into a Span
- public static bool TryWriteBytes(Span<byte> destination, long value)
- {
- if (destination.Length < sizeof(long))
- return false;
-
- Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
- return true;
- }
-
- // Converts an ushort into an array of bytes with
- // length two.
- [CLSCompliant(false)]
- public static byte[] GetBytes(ushort value)
- {
- byte[] bytes = new byte[sizeof(ushort)];
- Unsafe.As<byte, ushort>(ref bytes[0]) = value;
- return bytes;
- }
-
- // Converts a ushort into a Span
- [CLSCompliant(false)]
- public static bool TryWriteBytes(Span<byte> destination, ushort value)
- {
- if (destination.Length < sizeof(ushort))
- return false;
-
- Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
- return true;
- }
-
- // Converts an uint into an array of bytes with
- // length four.
- [CLSCompliant(false)]
- public static byte[] GetBytes(uint value)
- {
- byte[] bytes = new byte[sizeof(uint)];
- Unsafe.As<byte, uint>(ref bytes[0]) = value;
- return bytes;
- }
-
- // Converts a uint into a Span
- [CLSCompliant(false)]
- public static bool TryWriteBytes(Span<byte> destination, uint value)
- {
- if (destination.Length < sizeof(uint))
- return false;
-
- Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
- return true;
- }
-
- // Converts an unsigned long into an array of bytes with
- // length eight.
- [CLSCompliant(false)]
- public static byte[] GetBytes(ulong value)
- {
- byte[] bytes = new byte[sizeof(ulong)];
- Unsafe.As<byte, ulong>(ref bytes[0]) = value;
- return bytes;
- }
-
- // Converts a ulong into a Span
- [CLSCompliant(false)]
- public static bool TryWriteBytes(Span<byte> destination, ulong value)
- {
- if (destination.Length < sizeof(ulong))
- return false;
-
- Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
- return true;
- }
-
- // Converts a float into an array of bytes with length
- // four.
- public static byte[] GetBytes(float value)
- {
- byte[] bytes = new byte[sizeof(float)];
- Unsafe.As<byte, float>(ref bytes[0]) = value;
- return bytes;
- }
-
- // Converts a float into a Span
- public static bool TryWriteBytes(Span<byte> destination, float value)
- {
- if (destination.Length < sizeof(float))
- return false;
-
- Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
- return true;
- }
-
- // Converts a double into an array of bytes with length
- // eight.
- public static byte[] GetBytes(double value)
- {
- byte[] bytes = new byte[sizeof(double)];
- Unsafe.As<byte, double>(ref bytes[0]) = value;
- return bytes;
- }
-
- // Converts a double into a Span
- public static bool TryWriteBytes(Span<byte> destination, double value)
- {
- if (destination.Length < sizeof(double))
- return false;
-
- Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
- return true;
- }
-
- // Converts an array of bytes into a char.
- public static char ToChar(byte[] value, int startIndex) => unchecked((char)ToInt16(value, startIndex));
-
- // Converts a Span into a char
- public static char ToChar(ReadOnlySpan<byte> value)
- {
- if (value.Length < sizeof(char))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<char>(ref MemoryMarshal.GetReference(value));
- }
-
- // Converts an array of bytes into a short.
- public static short ToInt16(byte[] value, int startIndex)
- {
- if (value == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- if (unchecked((uint)startIndex) >= unchecked((uint)value.Length))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
- if (startIndex > value.Length - sizeof(short))
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value);
-
- return Unsafe.ReadUnaligned<short>(ref value[startIndex]);
- }
-
- // Converts a Span into a short
- public static short ToInt16(ReadOnlySpan<byte> value)
- {
- if (value.Length < sizeof(short))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<short>(ref MemoryMarshal.GetReference(value));
- }
-
- // Converts an array of bytes into an int.
- public static int ToInt32(byte[] value, int startIndex)
- {
- if (value == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- if (unchecked((uint)startIndex) >= unchecked((uint)value.Length))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
- if (startIndex > value.Length - sizeof(int))
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value);
-
- return Unsafe.ReadUnaligned<int>(ref value[startIndex]);
- }
-
- // Converts a Span into an int
- public static int ToInt32(ReadOnlySpan<byte> value)
- {
- if (value.Length < sizeof(int))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<int>(ref MemoryMarshal.GetReference(value));
- }
-
- // Converts an array of bytes into a long.
- public static long ToInt64(byte[] value, int startIndex)
- {
- if (value == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- if (unchecked((uint)startIndex) >= unchecked((uint)value.Length))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
- if (startIndex > value.Length - sizeof(long))
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value);
-
- return Unsafe.ReadUnaligned<long>(ref value[startIndex]);
- }
-
- // Converts a Span into a long
- public static long ToInt64(ReadOnlySpan<byte> value)
- {
- if (value.Length < sizeof(long))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<long>(ref MemoryMarshal.GetReference(value));
- }
-
- // Converts an array of bytes into an ushort.
- //
- [CLSCompliant(false)]
- public static ushort ToUInt16(byte[] value, int startIndex) => unchecked((ushort)ToInt16(value, startIndex));
-
- // Converts a Span into a ushort
- [CLSCompliant(false)]
- public static ushort ToUInt16(ReadOnlySpan<byte> value)
- {
- if (value.Length < sizeof(ushort))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<ushort>(ref MemoryMarshal.GetReference(value));
- }
-
- // Converts an array of bytes into an uint.
- //
- [CLSCompliant(false)]
- public static uint ToUInt32(byte[] value, int startIndex) => unchecked((uint)ToInt32(value, startIndex));
-
- // Convert a Span into a uint
- [CLSCompliant(false)]
- public static uint ToUInt32(ReadOnlySpan<byte> value)
- {
- if (value.Length < sizeof(uint))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<uint>(ref MemoryMarshal.GetReference(value));
- }
-
- // Converts an array of bytes into an unsigned long.
- //
- [CLSCompliant(false)]
- public static ulong ToUInt64(byte[] value, int startIndex) => unchecked((ulong)ToInt64(value, startIndex));
-
- // Converts a Span into an unsigned long
- [CLSCompliant(false)]
- public static ulong ToUInt64(ReadOnlySpan<byte> value)
- {
- if (value.Length < sizeof(ulong))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<ulong>(ref MemoryMarshal.GetReference(value));
- }
-
- // Converts an array of bytes into a float.
- public static float ToSingle(byte[] value, int startIndex) => Int32BitsToSingle(ToInt32(value, startIndex));
-
- // Converts a Span into a float
- public static float ToSingle(ReadOnlySpan<byte> value)
- {
- if (value.Length < sizeof(float))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<float>(ref MemoryMarshal.GetReference(value));
- }
-
- // Converts an array of bytes into a double.
- public static double ToDouble(byte[] value, int startIndex) => Int64BitsToDouble(ToInt64(value, startIndex));
-
- // Converts a Span into a double
- public static double ToDouble(ReadOnlySpan<byte> value)
- {
- if (value.Length < sizeof(double))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<double>(ref MemoryMarshal.GetReference(value));
- }
-
- // Converts an array of bytes into a String.
- public static string ToString(byte[] value, int startIndex, int length)
- {
- if (value == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- if (startIndex < 0 || startIndex >= value.Length && startIndex > 0)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
- if (length < 0)
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_GenericPositive);
- if (startIndex > value.Length - length)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value);
-
- if (length == 0)
- {
- return string.Empty;
- }
-
- if (length > (int.MaxValue / 3))
- {
- // (int.MaxValue / 3) == 715,827,882 Bytes == 699 MB
- throw new ArgumentOutOfRangeException(nameof(length), SR.Format(SR.ArgumentOutOfRange_LengthTooLarge, int.MaxValue / 3));
- }
-
- return string.Create(length * 3 - 1, (value, startIndex, length), (dst, state) =>
- {
- const string HexValues = "0123456789ABCDEF";
-
- var src = new ReadOnlySpan<byte>(state.value, state.startIndex, state.length);
-
- int i = 0;
- int j = 0;
-
- byte b = src[i++];
- dst[j++] = HexValues[b >> 4];
- dst[j++] = HexValues[b & 0xF];
-
- while (i < src.Length)
- {
- b = src[i++];
- dst[j++] = '-';
- dst[j++] = HexValues[b >> 4];
- dst[j++] = HexValues[b & 0xF];
- }
- });
- }
-
- // Converts an array of bytes into a String.
- public static string ToString(byte[] value)
- {
- if (value == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- return ToString(value, 0, value.Length);
- }
-
- // Converts an array of bytes into a String.
- public static string ToString(byte[] value, int startIndex)
- {
- if (value == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- return ToString(value, startIndex, value.Length - startIndex);
- }
-
- /*==================================ToBoolean===================================
- **Action: Convert an array of bytes to a boolean value. We treat this array
- ** as if the first 4 bytes were an Int4 an operate on this value.
- **Returns: True if the Int4 value of the first 4 bytes is non-zero.
- **Arguments: value -- The byte array
- ** startIndex -- The position within the array.
- **Exceptions: See ToInt4.
- ==============================================================================*/
- // Converts an array of bytes into a boolean.
- public static bool ToBoolean(byte[] value, int startIndex)
- {
- if (value == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- if (startIndex < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
- if (startIndex > value.Length - 1)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); // differs from other overloads, which throw base ArgumentException
-
- return value[startIndex] != 0;
- }
-
- public static bool ToBoolean(ReadOnlySpan<byte> value)
- {
- if (value.Length < sizeof(byte))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<byte>(ref MemoryMarshal.GetReference(value)) != 0;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe long DoubleToInt64Bits(double value)
- {
- return *((long*)&value);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe double Int64BitsToDouble(long value)
- {
- return *((double*)&value);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe int SingleToInt32Bits(float value)
- {
- return *((int*)&value);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe float Int32BitsToSingle(int value)
- {
- return *((float*)&value);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Boolean.cs b/netcore/System.Private.CoreLib/shared/System/Boolean.cs
deleted file mode 100644
index d1d0614bcd2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Boolean.cs
+++ /dev/null
@@ -1,381 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: The boolean class serves as a wrapper for the primitive
-** type boolean.
-**
-**
-===========================================================*/
-
-using System.Runtime.CompilerServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct Boolean : IComparable, IConvertible, IComparable<bool>, IEquatable<bool>
- {
- //
- // Member Variables
- //
- private readonly bool m_value; // Do not rename (binary serialization)
-
- // The true value.
- //
- internal const int True = 1;
-
- // The false value.
- //
- internal const int False = 0;
-
- //
- // Internal Constants are real consts for performance.
- //
-
- // The internal string representation of true.
- //
- internal const string TrueLiteral = "True";
-
- // The internal string representation of false.
- //
- internal const string FalseLiteral = "False";
-
- //
- // Public Constants
- //
-
- // The public string representation of true.
- //
- public static readonly string TrueString = TrueLiteral;
-
- // The public string representation of false.
- //
- public static readonly string FalseString = FalseLiteral;
-
- //
- // Overriden Instance Methods
- //
- /*=================================GetHashCode==================================
- **Args: None
- **Returns: 1 or 0 depending on whether this instance represents true or false.
- **Exceptions: None
- **Overriden From: Value
- ==============================================================================*/
- // Provides a hash code for this instance.
- public override int GetHashCode()
- {
- return (m_value) ? True : False;
- }
-
- /*===================================ToString===================================
- **Args: None
- **Returns: "True" or "False" depending on the state of the boolean.
- **Exceptions: None.
- ==============================================================================*/
- // Converts the boolean value of this instance to a String.
- public override string ToString()
- {
- if (false == m_value)
- {
- return FalseLiteral;
- }
- return TrueLiteral;
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return ToString();
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten)
- {
- if (m_value)
- {
- if ((uint)destination.Length > 3) // uint cast, per https://github.com/dotnet/coreclr/issues/18688
- {
- destination[0] = 'T';
- destination[1] = 'r';
- destination[2] = 'u';
- destination[3] = 'e';
- charsWritten = 4;
- return true;
- }
- }
- else
- {
- if ((uint)destination.Length > 4)
- {
- destination[0] = 'F';
- destination[1] = 'a';
- destination[2] = 'l';
- destination[3] = 's';
- destination[4] = 'e';
- charsWritten = 5;
- return true;
- }
- }
-
- charsWritten = 0;
- return false;
- }
-
- // Determines whether two Boolean objects are equal.
- public override bool Equals(object? obj)
- {
- // If it's not a boolean, we're definitely not equal
- if (!(obj is bool))
- {
- return false;
- }
-
- return m_value == ((bool)obj).m_value;
- }
-
- [NonVersionable]
- public bool Equals(bool obj)
- {
- return m_value == obj;
- }
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship. For booleans, false sorts before true.
- // null is considered to be less than any instance.
- // If object is not of type boolean, this method throws an ArgumentException.
- //
- // Returns a value less than zero if this object
- //
- public int CompareTo(object? obj)
- {
- if (obj == null)
- {
- return 1;
- }
- if (!(obj is bool))
- {
- throw new ArgumentException(SR.Arg_MustBeBoolean);
- }
-
- if (m_value == ((bool)obj).m_value)
- {
- return 0;
- }
- else if (m_value == false)
- {
- return -1;
- }
- return 1;
- }
-
- public int CompareTo(bool value)
- {
- if (m_value == value)
- {
- return 0;
- }
- else if (m_value == false)
- {
- return -1;
- }
- return 1;
- }
-
- //
- // Static Methods
- //
-
- // Custom string compares for early application use by config switches, etc
- //
- internal static bool IsTrueStringIgnoreCase(ReadOnlySpan<char> value)
- {
- return value.Length == 4 &&
- (value[0] == 't' || value[0] == 'T') &&
- (value[1] == 'r' || value[1] == 'R') &&
- (value[2] == 'u' || value[2] == 'U') &&
- (value[3] == 'e' || value[3] == 'E');
- }
-
- internal static bool IsFalseStringIgnoreCase(ReadOnlySpan<char> value)
- {
- return value.Length == 5 &&
- (value[0] == 'f' || value[0] == 'F') &&
- (value[1] == 'a' || value[1] == 'A') &&
- (value[2] == 'l' || value[2] == 'L') &&
- (value[3] == 's' || value[3] == 'S') &&
- (value[4] == 'e' || value[4] == 'E');
- }
-
- // Determines whether a String represents true or false.
- //
- public static bool Parse(string value)
- {
- if (value == null) throw new ArgumentNullException(nameof(value));
- return Parse(value.AsSpan());
- }
-
- public static bool Parse(ReadOnlySpan<char> value) =>
- TryParse(value, out bool result) ? result : throw new FormatException(SR.Format(SR.Format_BadBoolean, new string(value)));
-
- // Determines whether a String represents true or false.
- //
- public static bool TryParse(string? value, out bool result)
- {
- if (value == null)
- {
- result = false;
- return false;
- }
-
- return TryParse(value.AsSpan(), out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> value, out bool result)
- {
- if (IsTrueStringIgnoreCase(value))
- {
- result = true;
- return true;
- }
-
- if (IsFalseStringIgnoreCase(value))
- {
- result = false;
- return true;
- }
-
- // Special case: Trim whitespace as well as null characters.
- value = TrimWhiteSpaceAndNull(value);
-
- if (IsTrueStringIgnoreCase(value))
- {
- result = true;
- return true;
- }
-
- if (IsFalseStringIgnoreCase(value))
- {
- result = false;
- return true;
- }
-
- result = false;
- return false;
- }
-
- private static ReadOnlySpan<char> TrimWhiteSpaceAndNull(ReadOnlySpan<char> value)
- {
- const char nullChar = (char)0x0000;
-
- int start = 0;
- while (start < value.Length)
- {
- if (!char.IsWhiteSpace(value[start]) && value[start] != nullChar)
- {
- break;
- }
- start++;
- }
-
- int end = value.Length - 1;
- while (end >= start)
- {
- if (!char.IsWhiteSpace(value[end]) && value[end] != nullChar)
- {
- break;
- }
- end--;
- }
-
- return value.Slice(start, end - start + 1);
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.Boolean;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return m_value;
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Boolean", "Char"));
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Boolean", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffer.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Buffer.Unix.cs
deleted file mode 100644
index 036ebddd724..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffer.Unix.cs
+++ /dev/null
@@ -1,27 +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.
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- public static partial class Buffer
- {
-#if ARM64
- // Managed code is currently faster than glibc unoptimized memmove
- // TODO-ARM64-UNIX-OPT revisit when glibc optimized memmove is in Linux distros
- // https://github.com/dotnet/coreclr/issues/13844
- private const nuint MemmoveNativeThreshold = ulong.MaxValue;
-#elif ARM
- private const nuint MemmoveNativeThreshold = 512;
-#else
- private const nuint MemmoveNativeThreshold = 2048;
-#endif
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffer.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Buffer.Windows.cs
deleted file mode 100644
index 35c627c04b5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffer.Windows.cs
+++ /dev/null
@@ -1,24 +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.
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- public static partial class Buffer
- {
-#if ARM64
- // Determine optimal value for Windows.
- // https://github.com/dotnet/coreclr/issues/13843
- private const nuint MemmoveNativeThreshold = ulong.MaxValue;
-#else
- private const nuint MemmoveNativeThreshold = 2048;
-#endif
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffer.cs b/netcore/System.Private.CoreLib/shared/System/Buffer.cs
deleted file mode 100644
index 18064bca07a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffer.cs
+++ /dev/null
@@ -1,554 +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.
-
-#if AMD64 || ARM64 || (BIT32 && !ARM)
-#define HAS_CUSTOM_BLOCKS
-#endif
-
-using System.Diagnostics;
-using System.Runtime;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nint = System.Int64;
-using nuint = System.UInt64;
-#else
-using nint = System.Int32;
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- public static partial class Buffer
- {
- // Copies from one primitive array to another primitive array without
- // respecting types. This calls memmove internally. The count and
- // offset parameters here are in bytes. If you want to use traditional
- // array element indices and counts, use Array.Copy.
- public static unsafe void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
- {
- if (src == null)
- throw new ArgumentNullException(nameof(src));
- if (dst == null)
- throw new ArgumentNullException(nameof(dst));
-
- nuint uSrcLen = (nuint)src.LongLength;
- if (src.GetType() != typeof(byte[]))
- {
- if (!src.GetCorElementTypeOfElementType().IsPrimitiveType())
- throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(src));
- uSrcLen *= (nuint)src.GetElementSize();
- }
-
- nuint uDstLen = uSrcLen;
- if (src != dst)
- {
- uDstLen = (nuint)dst.LongLength;
- if (dst.GetType() != typeof(byte[]))
- {
- if (!dst.GetCorElementTypeOfElementType().IsPrimitiveType())
- throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(dst));
- uDstLen *= (nuint)dst.GetElementSize();
- }
- }
-
- if (srcOffset < 0)
- throw new ArgumentOutOfRangeException(nameof(srcOffset), SR.ArgumentOutOfRange_MustBeNonNegInt32);
- if (dstOffset < 0)
- throw new ArgumentOutOfRangeException(nameof(dstOffset), SR.ArgumentOutOfRange_MustBeNonNegInt32);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_MustBeNonNegInt32);
-
- nuint uCount = (nuint)count;
- nuint uSrcOffset = (nuint)srcOffset;
- nuint uDstOffset = (nuint)dstOffset;
-
- if ((uSrcLen < uSrcOffset + uCount) || (uDstLen < uDstOffset + uCount))
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- Memmove(ref Unsafe.AddByteOffset(ref dst.GetRawArrayData(), uDstOffset), ref Unsafe.AddByteOffset(ref src.GetRawArrayData(), uSrcOffset), uCount);
- }
-
- public static int ByteLength(Array array)
- {
- // Is the array present?
- if (array == null)
- throw new ArgumentNullException(nameof(array));
-
- // Is it of primitive types?
- if (!array.GetCorElementTypeOfElementType().IsPrimitiveType())
- throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(array));
-
- nuint byteLength = (nuint)array.LongLength * (nuint)array.GetElementSize();
-
- // This API is explosed both as Buffer.ByteLength and also used indirectly in argument
- // checks for Buffer.GetByte/SetByte.
- //
- // If somebody called Get/SetByte on 2GB+ arrays, there is a decent chance that
- // the computation of the index has overflowed. Thus we intentionally always
- // throw on 2GB+ arrays in Get/SetByte argument checks (even for indicies <2GB)
- // to prevent people from running into a trap silently.
-
- return checked((int)byteLength);
- }
-
- public static byte GetByte(Array array, int index)
- {
- // array argument validation done via ByteLength
- if ((uint)index >= (uint)ByteLength(array))
- throw new ArgumentOutOfRangeException(nameof(index));
-
- return Unsafe.Add<byte>(ref array.GetRawArrayData(), index);
- }
-
- public static void SetByte(Array array, int index, byte value)
- {
- // array argument validation done via ByteLength
- if ((uint)index >= (uint)ByteLength(array))
- throw new ArgumentOutOfRangeException(nameof(index));
-
- Unsafe.Add<byte>(ref array.GetRawArrayData(), index) = value;
- }
-
- // This method has different signature for x64 and other platforms and is done for performance reasons.
- internal static unsafe void ZeroMemory(byte* dest, nuint len)
- {
- SpanHelpers.ClearWithoutReferences(ref *dest, len);
- }
-
- // The attributes on this method are chosen for best JIT performance.
- // Please do not edit unless intentional.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe void MemoryCopy(void* source, void* destination, long destinationSizeInBytes, long sourceBytesToCopy)
- {
- if (sourceBytesToCopy > destinationSizeInBytes)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.sourceBytesToCopy);
- }
- Memmove((byte*)destination, (byte*)source, checked((nuint)sourceBytesToCopy));
- }
-
- // The attributes on this method are chosen for best JIT performance.
- // Please do not edit unless intentional.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe void MemoryCopy(void* source, void* destination, ulong destinationSizeInBytes, ulong sourceBytesToCopy)
- {
- if (sourceBytesToCopy > destinationSizeInBytes)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.sourceBytesToCopy);
- }
- Memmove((byte*)destination, (byte*)source, checked((nuint)sourceBytesToCopy));
- }
-
- // This method has different signature for x64 and other platforms and is done for performance reasons.
- internal static unsafe void Memmove(byte* dest, byte* src, nuint len)
- {
- // P/Invoke into the native version when the buffers are overlapping.
- if (((nuint)dest - (nuint)src < len) || ((nuint)src - (nuint)dest < len))
- {
- goto PInvoke;
- }
-
- byte* srcEnd = src + len;
- byte* destEnd = dest + len;
-
- if (len <= 16) goto MCPY02;
- if (len > 64) goto MCPY05;
-
- MCPY00:
- // Copy bytes which are multiples of 16 and leave the remainder for MCPY01 to handle.
- Debug.Assert(len > 16 && len <= 64);
-#if HAS_CUSTOM_BLOCKS
- *(Block16*)dest = *(Block16*)src; // [0,16]
-#elif BIT64
- *(long*)dest = *(long*)src;
- *(long*)(dest + 8) = *(long*)(src + 8); // [0,16]
-#else
- *(int*)dest = *(int*)src;
- *(int*)(dest + 4) = *(int*)(src + 4);
- *(int*)(dest + 8) = *(int*)(src + 8);
- *(int*)(dest + 12) = *(int*)(src + 12); // [0,16]
-#endif
- if (len <= 32) goto MCPY01;
-#if HAS_CUSTOM_BLOCKS
- *(Block16*)(dest + 16) = *(Block16*)(src + 16); // [0,32]
-#elif BIT64
- *(long*)(dest + 16) = *(long*)(src + 16);
- *(long*)(dest + 24) = *(long*)(src + 24); // [0,32]
-#else
- *(int*)(dest + 16) = *(int*)(src + 16);
- *(int*)(dest + 20) = *(int*)(src + 20);
- *(int*)(dest + 24) = *(int*)(src + 24);
- *(int*)(dest + 28) = *(int*)(src + 28); // [0,32]
-#endif
- if (len <= 48) goto MCPY01;
-#if HAS_CUSTOM_BLOCKS
- *(Block16*)(dest + 32) = *(Block16*)(src + 32); // [0,48]
-#elif BIT64
- *(long*)(dest + 32) = *(long*)(src + 32);
- *(long*)(dest + 40) = *(long*)(src + 40); // [0,48]
-#else
- *(int*)(dest + 32) = *(int*)(src + 32);
- *(int*)(dest + 36) = *(int*)(src + 36);
- *(int*)(dest + 40) = *(int*)(src + 40);
- *(int*)(dest + 44) = *(int*)(src + 44); // [0,48]
-#endif
-
- MCPY01:
- // Unconditionally copy the last 16 bytes using destEnd and srcEnd and return.
- Debug.Assert(len > 16 && len <= 64);
-#if HAS_CUSTOM_BLOCKS
- *(Block16*)(destEnd - 16) = *(Block16*)(srcEnd - 16);
-#elif BIT64
- *(long*)(destEnd - 16) = *(long*)(srcEnd - 16);
- *(long*)(destEnd - 8) = *(long*)(srcEnd - 8);
-#else
- *(int*)(destEnd - 16) = *(int*)(srcEnd - 16);
- *(int*)(destEnd - 12) = *(int*)(srcEnd - 12);
- *(int*)(destEnd - 8) = *(int*)(srcEnd - 8);
- *(int*)(destEnd - 4) = *(int*)(srcEnd - 4);
-#endif
- return;
-
- MCPY02:
- // Copy the first 8 bytes and then unconditionally copy the last 8 bytes and return.
- if ((len & 24) == 0) goto MCPY03;
- Debug.Assert(len >= 8 && len <= 16);
-#if BIT64
- *(long*)dest = *(long*)src;
- *(long*)(destEnd - 8) = *(long*)(srcEnd - 8);
-#else
- *(int*)dest = *(int*)src;
- *(int*)(dest + 4) = *(int*)(src + 4);
- *(int*)(destEnd - 8) = *(int*)(srcEnd - 8);
- *(int*)(destEnd - 4) = *(int*)(srcEnd - 4);
-#endif
- return;
-
- MCPY03:
- // Copy the first 4 bytes and then unconditionally copy the last 4 bytes and return.
- if ((len & 4) == 0) goto MCPY04;
- Debug.Assert(len >= 4 && len < 8);
- *(int*)dest = *(int*)src;
- *(int*)(destEnd - 4) = *(int*)(srcEnd - 4);
- return;
-
- MCPY04:
- // Copy the first byte. For pending bytes, do an unconditionally copy of the last 2 bytes and return.
- Debug.Assert(len < 4);
- if (len == 0) return;
- *dest = *src;
- if ((len & 2) == 0) return;
- *(short*)(destEnd - 2) = *(short*)(srcEnd - 2);
- return;
-
- MCPY05:
- // PInvoke to the native version when the copy length exceeds the threshold.
- if (len > MemmoveNativeThreshold)
- {
- goto PInvoke;
- }
-
- // Copy 64-bytes at a time until the remainder is less than 64.
- // If remainder is greater than 16 bytes, then jump to MCPY00. Otherwise, unconditionally copy the last 16 bytes and return.
- Debug.Assert(len > 64 && len <= MemmoveNativeThreshold);
- nuint n = len >> 6;
-
- MCPY06:
-#if HAS_CUSTOM_BLOCKS
- *(Block64*)dest = *(Block64*)src;
-#elif BIT64
- *(long*)dest = *(long*)src;
- *(long*)(dest + 8) = *(long*)(src + 8);
- *(long*)(dest + 16) = *(long*)(src + 16);
- *(long*)(dest + 24) = *(long*)(src + 24);
- *(long*)(dest + 32) = *(long*)(src + 32);
- *(long*)(dest + 40) = *(long*)(src + 40);
- *(long*)(dest + 48) = *(long*)(src + 48);
- *(long*)(dest + 56) = *(long*)(src + 56);
-#else
- *(int*)dest = *(int*)src;
- *(int*)(dest + 4) = *(int*)(src + 4);
- *(int*)(dest + 8) = *(int*)(src + 8);
- *(int*)(dest + 12) = *(int*)(src + 12);
- *(int*)(dest + 16) = *(int*)(src + 16);
- *(int*)(dest + 20) = *(int*)(src + 20);
- *(int*)(dest + 24) = *(int*)(src + 24);
- *(int*)(dest + 28) = *(int*)(src + 28);
- *(int*)(dest + 32) = *(int*)(src + 32);
- *(int*)(dest + 36) = *(int*)(src + 36);
- *(int*)(dest + 40) = *(int*)(src + 40);
- *(int*)(dest + 44) = *(int*)(src + 44);
- *(int*)(dest + 48) = *(int*)(src + 48);
- *(int*)(dest + 52) = *(int*)(src + 52);
- *(int*)(dest + 56) = *(int*)(src + 56);
- *(int*)(dest + 60) = *(int*)(src + 60);
-#endif
- dest += 64;
- src += 64;
- n--;
- if (n != 0) goto MCPY06;
-
- len %= 64;
- if (len > 16) goto MCPY00;
-#if HAS_CUSTOM_BLOCKS
- *(Block16*)(destEnd - 16) = *(Block16*)(srcEnd - 16);
-#elif BIT64
- *(long*)(destEnd - 16) = *(long*)(srcEnd - 16);
- *(long*)(destEnd - 8) = *(long*)(srcEnd - 8);
-#else
- *(int*)(destEnd - 16) = *(int*)(srcEnd - 16);
- *(int*)(destEnd - 12) = *(int*)(srcEnd - 12);
- *(int*)(destEnd - 8) = *(int*)(srcEnd - 8);
- *(int*)(destEnd - 4) = *(int*)(srcEnd - 4);
-#endif
- return;
-
- PInvoke:
- _Memmove(dest, src, len);
- }
-
- // This method has different signature for x64 and other platforms and is done for performance reasons.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void Memmove<T>(ref T destination, ref T source, nuint elementCount)
- {
- if (!RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- // Blittable memmove
-
- Memmove(
- ref Unsafe.As<T, byte>(ref destination),
- ref Unsafe.As<T, byte>(ref source),
- elementCount * (nuint)Unsafe.SizeOf<T>());
- }
- else
- {
- // Non-blittable memmove
- BulkMoveWithWriteBarrier(
- ref Unsafe.As<T, byte>(ref destination),
- ref Unsafe.As<T, byte>(ref source),
- elementCount * (nuint)Unsafe.SizeOf<T>());
- }
- }
-
- // This method has different signature for x64 and other platforms and is done for performance reasons.
- private static void Memmove(ref byte dest, ref byte src, nuint len)
- {
- // P/Invoke into the native version when the buffers are overlapping.
- if (((nuint)Unsafe.ByteOffset(ref src, ref dest) < len) || ((nuint)Unsafe.ByteOffset(ref dest, ref src) < len))
- {
- goto BuffersOverlap;
- }
-
- // Use "(IntPtr)(nint)len" to avoid overflow checking on the explicit cast to IntPtr
-
- ref byte srcEnd = ref Unsafe.Add(ref src, (IntPtr)(nint)len);
- ref byte destEnd = ref Unsafe.Add(ref dest, (IntPtr)(nint)len);
-
- if (len <= 16)
- goto MCPY02;
- if (len > 64)
- goto MCPY05;
-
- MCPY00:
- // Copy bytes which are multiples of 16 and leave the remainder for MCPY01 to handle.
- Debug.Assert(len > 16 && len <= 64);
-#if HAS_CUSTOM_BLOCKS
- Unsafe.As<byte, Block16>(ref dest) = Unsafe.As<byte, Block16>(ref src); // [0,16]
-#elif BIT64
- Unsafe.As<byte, long>(ref dest) = Unsafe.As<byte, long>(ref src);
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 8)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 8)); // [0,16]
-#else
- Unsafe.As<byte, int>(ref dest) = Unsafe.As<byte, int>(ref src);
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 4)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 4));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 8)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 8));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 12)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 12)); // [0,16]
-#endif
- if (len <= 32)
- goto MCPY01;
-#if HAS_CUSTOM_BLOCKS
- Unsafe.As<byte, Block16>(ref Unsafe.Add(ref dest, 16)) = Unsafe.As<byte, Block16>(ref Unsafe.Add(ref src, 16)); // [0,32]
-#elif BIT64
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 16)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 16));
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 24)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 24)); // [0,32]
-#else
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 16)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 16));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 20)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 20));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 24)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 24));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 28)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 28)); // [0,32]
-#endif
- if (len <= 48)
- goto MCPY01;
-#if HAS_CUSTOM_BLOCKS
- Unsafe.As<byte, Block16>(ref Unsafe.Add(ref dest, 32)) = Unsafe.As<byte, Block16>(ref Unsafe.Add(ref src, 32)); // [0,48]
-#elif BIT64
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 32)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 32));
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 40)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 40)); // [0,48]
-#else
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 32)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 32));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 36)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 36));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 40)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 40));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 44)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 44)); // [0,48]
-#endif
-
- MCPY01:
- // Unconditionally copy the last 16 bytes using destEnd and srcEnd and return.
- Debug.Assert(len > 16 && len <= 64);
-#if HAS_CUSTOM_BLOCKS
- Unsafe.As<byte, Block16>(ref Unsafe.Add(ref destEnd, -16)) = Unsafe.As<byte, Block16>(ref Unsafe.Add(ref srcEnd, -16));
-#elif BIT64
- Unsafe.As<byte, long>(ref Unsafe.Add(ref destEnd, -16)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref srcEnd, -16));
- Unsafe.As<byte, long>(ref Unsafe.Add(ref destEnd, -8)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref srcEnd, -8));
-#else
- Unsafe.As<byte, int>(ref Unsafe.Add(ref destEnd, -16)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref srcEnd, -16));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref destEnd, -12)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref srcEnd, -12));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref destEnd, -8)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref srcEnd, -8));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref destEnd, -4)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref srcEnd, -4));
-#endif
- return;
-
- MCPY02:
- // Copy the first 8 bytes and then unconditionally copy the last 8 bytes and return.
- if ((len & 24) == 0)
- goto MCPY03;
- Debug.Assert(len >= 8 && len <= 16);
-#if BIT64
- Unsafe.As<byte, long>(ref dest) = Unsafe.As<byte, long>(ref src);
- Unsafe.As<byte, long>(ref Unsafe.Add(ref destEnd, -8)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref srcEnd, -8));
-#else
- Unsafe.As<byte, int>(ref dest) = Unsafe.As<byte, int>(ref src);
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 4)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 4));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref destEnd, -8)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref srcEnd, -8));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref destEnd, -4)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref srcEnd, -4));
-#endif
- return;
-
- MCPY03:
- // Copy the first 4 bytes and then unconditionally copy the last 4 bytes and return.
- if ((len & 4) == 0)
- goto MCPY04;
- Debug.Assert(len >= 4 && len < 8);
- Unsafe.As<byte, int>(ref dest) = Unsafe.As<byte, int>(ref src);
- Unsafe.As<byte, int>(ref Unsafe.Add(ref destEnd, -4)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref srcEnd, -4));
- return;
-
- MCPY04:
- // Copy the first byte. For pending bytes, do an unconditionally copy of the last 2 bytes and return.
- Debug.Assert(len < 4);
- if (len == 0)
- return;
- dest = src;
- if ((len & 2) == 0)
- return;
- Unsafe.As<byte, short>(ref Unsafe.Add(ref destEnd, -2)) = Unsafe.As<byte, short>(ref Unsafe.Add(ref srcEnd, -2));
- return;
-
- MCPY05:
- // PInvoke to the native version when the copy length exceeds the threshold.
- if (len > MemmoveNativeThreshold)
- {
- goto PInvoke;
- }
-
- // Copy 64-bytes at a time until the remainder is less than 64.
- // If remainder is greater than 16 bytes, then jump to MCPY00. Otherwise, unconditionally copy the last 16 bytes and return.
- Debug.Assert(len > 64 && len <= MemmoveNativeThreshold);
- nuint n = len >> 6;
-
- MCPY06:
-#if HAS_CUSTOM_BLOCKS
- Unsafe.As<byte, Block64>(ref dest) = Unsafe.As<byte, Block64>(ref src);
-#elif BIT64
- Unsafe.As<byte, long>(ref dest) = Unsafe.As<byte, long>(ref src);
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 8)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 8));
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 16)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 16));
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 24)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 24));
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 32)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 32));
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 40)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 40));
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 48)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 48));
- Unsafe.As<byte, long>(ref Unsafe.Add(ref dest, 56)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref src, 56));
-#else
- Unsafe.As<byte, int>(ref dest) = Unsafe.As<byte, int>(ref src);
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 4)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 4));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 8)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 8));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 12)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 12));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 16)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 16));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 20)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 20));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 24)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 24));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 28)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 28));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 32)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 32));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 36)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 36));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 40)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 40));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 44)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 44));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 48)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 48));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 52)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 52));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 56)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 56));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref dest, 60)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref src, 60));
-#endif
- dest = ref Unsafe.Add(ref dest, 64);
- src = ref Unsafe.Add(ref src, 64);
- n--;
- if (n != 0)
- goto MCPY06;
-
- len %= 64;
- if (len > 16)
- goto MCPY00;
-#if HAS_CUSTOM_BLOCKS
- Unsafe.As<byte, Block16>(ref Unsafe.Add(ref destEnd, -16)) = Unsafe.As<byte, Block16>(ref Unsafe.Add(ref srcEnd, -16));
-#elif BIT64
- Unsafe.As<byte, long>(ref Unsafe.Add(ref destEnd, -16)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref srcEnd, -16));
- Unsafe.As<byte, long>(ref Unsafe.Add(ref destEnd, -8)) = Unsafe.As<byte, long>(ref Unsafe.Add(ref srcEnd, -8));
-#else
- Unsafe.As<byte, int>(ref Unsafe.Add(ref destEnd, -16)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref srcEnd, -16));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref destEnd, -12)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref srcEnd, -12));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref destEnd, -8)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref srcEnd, -8));
- Unsafe.As<byte, int>(ref Unsafe.Add(ref destEnd, -4)) = Unsafe.As<byte, int>(ref Unsafe.Add(ref srcEnd, -4));
-#endif
- return;
-
- BuffersOverlap:
- // If the buffers overlap perfectly, there's no point to copying the data.
- if (Unsafe.AreSame(ref dest, ref src))
- {
- return;
- }
-
- PInvoke:
- _Memmove(ref dest, ref src, len);
- }
-
- // Non-inlinable wrapper around the QCall that avoids polluting the fast path
- // with P/Invoke prolog/epilog.
- [MethodImpl(MethodImplOptions.NoInlining)]
- private static unsafe void _Memmove(byte* dest, byte* src, nuint len)
- {
- __Memmove(dest, src, len);
- }
-
- // Non-inlinable wrapper around the QCall that avoids polluting the fast path
- // with P/Invoke prolog/epilog.
- [MethodImpl(MethodImplOptions.NoInlining)]
- private static unsafe void _Memmove(ref byte dest, ref byte src, nuint len)
- {
- fixed (byte* pDest = &dest)
- fixed (byte* pSrc = &src)
- __Memmove(pDest, pSrc, len);
- }
-
-#if HAS_CUSTOM_BLOCKS
- [StructLayout(LayoutKind.Sequential, Size = 16)]
- private struct Block16 { }
-
- [StructLayout(LayoutKind.Sequential, Size = 64)]
- private struct Block64 { }
-#endif // HAS_CUSTOM_BLOCKS
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/ArrayPool.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/ArrayPool.cs
deleted file mode 100644
index 0587f8fc1ab..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/ArrayPool.cs
+++ /dev/null
@@ -1,102 +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.
-
-namespace System.Buffers
-{
- /// <summary>
- /// Provides a resource pool that enables reusing instances of arrays.
- /// </summary>
- /// <remarks>
- /// <para>
- /// Renting and returning buffers with an <see cref="ArrayPool{T}"/> can increase performance
- /// in situations where arrays are created and destroyed frequently, resulting in significant
- /// memory pressure on the garbage collector.
- /// </para>
- /// <para>
- /// This class is thread-safe. All members may be used by multiple threads concurrently.
- /// </para>
- /// </remarks>
- public abstract class ArrayPool<T>
- {
- // Store the shared ArrayPool in a field of its derived sealed type so the Jit can "see" the exact type
- // when the Shared property is inlined which will allow it to devirtualize calls made on it.
- private static readonly TlsOverPerCoreLockedStacksArrayPool<T> s_shared = new TlsOverPerCoreLockedStacksArrayPool<T>();
-
- /// <summary>
- /// Retrieves a shared <see cref="ArrayPool{T}"/> instance.
- /// </summary>
- /// <remarks>
- /// The shared pool provides a default implementation of <see cref="ArrayPool{T}"/>
- /// that's intended for general applicability. It maintains arrays of multiple sizes, and
- /// may hand back a larger array than was actually requested, but will never hand back a smaller
- /// array than was requested. Renting a buffer from it with <see cref="Rent"/> will result in an
- /// existing buffer being taken from the pool if an appropriate buffer is available or in a new
- /// buffer being allocated if one is not available.
- /// byte[] and char[] are the most commonly pooled array types. For these we use a special pool type
- /// optimized for very fast access speeds, at the expense of more memory consumption.
- /// The shared pool instance is created lazily on first access.
- /// </remarks>
- public static ArrayPool<T> Shared => s_shared;
-
- /// <summary>
- /// Creates a new <see cref="ArrayPool{T}"/> instance using default configuration options.
- /// </summary>
- /// <returns>A new <see cref="ArrayPool{T}"/> instance.</returns>
- public static ArrayPool<T> Create() => new ConfigurableArrayPool<T>();
-
- /// <summary>
- /// Creates a new <see cref="ArrayPool{T}"/> instance using custom configuration options.
- /// </summary>
- /// <param name="maxArrayLength">The maximum length of array instances that may be stored in the pool.</param>
- /// <param name="maxArraysPerBucket">
- /// The maximum number of array instances that may be stored in each bucket in the pool. The pool
- /// groups arrays of similar lengths into buckets for faster access.
- /// </param>
- /// <returns>A new <see cref="ArrayPool{T}"/> instance with the specified configuration options.</returns>
- /// <remarks>
- /// The created pool will group arrays into buckets, with no more than <paramref name="maxArraysPerBucket"/>
- /// in each bucket and with those arrays not exceeding <paramref name="maxArrayLength"/> in length.
- /// </remarks>
- public static ArrayPool<T> Create(int maxArrayLength, int maxArraysPerBucket) =>
- new ConfigurableArrayPool<T>(maxArrayLength, maxArraysPerBucket);
-
- /// <summary>
- /// Retrieves a buffer that is at least the requested length.
- /// </summary>
- /// <param name="minimumLength">The minimum length of the array needed.</param>
- /// <returns>
- /// An array that is at least <paramref name="minimumLength"/> in length.
- /// </returns>
- /// <remarks>
- /// This buffer is loaned to the caller and should be returned to the same pool via
- /// <see cref="Return"/> so that it may be reused in subsequent usage of <see cref="Rent"/>.
- /// It is not a fatal error to not return a rented buffer, but failure to do so may lead to
- /// decreased application performance, as the pool may need to create a new buffer to replace
- /// the one lost.
- /// </remarks>
- public abstract T[] Rent(int minimumLength);
-
- /// <summary>
- /// Returns to the pool an array that was previously obtained via <see cref="Rent"/> on the same
- /// <see cref="ArrayPool{T}"/> instance.
- /// </summary>
- /// <param name="array">
- /// The buffer previously obtained from <see cref="Rent"/> to return to the pool.
- /// </param>
- /// <param name="clearArray">
- /// If <c>true</c> and if the pool will store the buffer to enable subsequent reuse, <see cref="Return"/>
- /// will clear <paramref name="array"/> of its contents so that a subsequent consumer via <see cref="Rent"/>
- /// will not see the previous consumer's content. If <c>false</c> or if the pool will release the buffer,
- /// the array's contents are left unchanged.
- /// </param>
- /// <remarks>
- /// Once a buffer has been returned to the pool, the caller gives up all ownership of the buffer
- /// and must not use it. The reference returned from a given call to <see cref="Rent"/> must only be
- /// returned via <see cref="Return"/> once. The default <see cref="ArrayPool{T}"/>
- /// may hold onto the returned buffer in order to rent it again, or it may release the returned buffer
- /// if it's determined that the pool already has enough buffers stored.
- /// </remarks>
- public abstract void Return(T[] array, bool clearArray = false);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/ArrayPoolEventSource.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/ArrayPoolEventSource.cs
deleted file mode 100644
index f4cfe549c94..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/ArrayPoolEventSource.cs
+++ /dev/null
@@ -1,104 +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 System.Diagnostics.Tracing;
-
-namespace System.Buffers
-{
- [EventSource(Guid = "0866B2B8-5CEF-5DB9-2612-0C0FFD814A44", Name = "System.Buffers.ArrayPoolEventSource")]
- internal sealed class ArrayPoolEventSource : EventSource
- {
- internal static readonly ArrayPoolEventSource Log = new ArrayPoolEventSource();
-
- /// <summary>The reason for a BufferAllocated event.</summary>
- internal enum BufferAllocatedReason : int
- {
- /// <summary>The pool is allocating a buffer to be pooled in a bucket.</summary>
- Pooled,
- /// <summary>The requested buffer size was too large to be pooled.</summary>
- OverMaximumSize,
- /// <summary>The pool has already allocated for pooling as many buffers of a particular size as it's allowed.</summary>
- PoolExhausted
- }
-
- // The ArrayPoolEventSource GUID is {0866b2b8-5cef-5db9-2612-0c0ffd814a44}
- private ArrayPoolEventSource() : base(new Guid(0x0866b2b8, 0x5cef, 0x5db9, 0x26, 0x12, 0x0c, 0x0f, 0xfd, 0x81, 0x4a, 0x44), "System.Buffers.ArrayPoolEventSource") { }
-
- /// <summary>
- /// Event for when a buffer is rented. This is invoked once for every successful call to Rent,
- /// regardless of whether a buffer is allocated or a buffer is taken from the pool. In a
- /// perfect situation where all rented buffers are returned, we expect to see the number
- /// of BufferRented events exactly match the number of BuferReturned events, with the number
- /// of BufferAllocated events being less than or equal to those numbers (ideally significantly
- /// less than).
- /// </summary>
- [Event(1, Level = EventLevel.Verbose)]
- internal unsafe void BufferRented(int bufferId, int bufferSize, int poolId, int bucketId)
- {
- EventData* payload = stackalloc EventData[4];
- payload[0].Size = sizeof(int);
- payload[0].DataPointer = ((IntPtr)(&bufferId));
- payload[0].Reserved = 0;
- payload[1].Size = sizeof(int);
- payload[1].DataPointer = ((IntPtr)(&bufferSize));
- payload[1].Reserved = 0;
- payload[2].Size = sizeof(int);
- payload[2].DataPointer = ((IntPtr)(&poolId));
- payload[2].Reserved = 0;
- payload[3].Size = sizeof(int);
- payload[3].DataPointer = ((IntPtr)(&bucketId));
- payload[3].Reserved = 0;
- WriteEventCore(1, 4, payload);
- }
-
- /// <summary>
- /// Event for when a buffer is allocated by the pool. In an ideal situation, the number
- /// of BufferAllocated events is significantly smaller than the number of BufferRented and
- /// BufferReturned events.
- /// </summary>
- [Event(2, Level = EventLevel.Informational)]
- internal unsafe void BufferAllocated(int bufferId, int bufferSize, int poolId, int bucketId, BufferAllocatedReason reason)
- {
- EventData* payload = stackalloc EventData[5];
- payload[0].Size = sizeof(int);
- payload[0].DataPointer = ((IntPtr)(&bufferId));
- payload[0].Reserved = 0;
- payload[1].Size = sizeof(int);
- payload[1].DataPointer = ((IntPtr)(&bufferSize));
- payload[1].Reserved = 0;
- payload[2].Size = sizeof(int);
- payload[2].DataPointer = ((IntPtr)(&poolId));
- payload[2].Reserved = 0;
- payload[3].Size = sizeof(int);
- payload[3].DataPointer = ((IntPtr)(&bucketId));
- payload[3].Reserved = 0;
- payload[4].Size = sizeof(BufferAllocatedReason);
- payload[4].DataPointer = ((IntPtr)(&reason));
- payload[4].Reserved = 0;
- WriteEventCore(2, 5, payload);
- }
-
- /// <summary>
- /// Event raised when a buffer is returned to the pool. This event is raised regardless of whether
- /// the returned buffer is stored or dropped. In an ideal situation, the number of BufferReturned
- /// events exactly matches the number of BufferRented events.
- /// </summary>
- [Event(3, Level = EventLevel.Verbose)]
- internal void BufferReturned(int bufferId, int bufferSize, int poolId) => WriteEvent(3, bufferId, bufferSize, poolId);
-
- /// <summary>
- /// Event raised when we attempt to free a buffer due to inactivity or memory pressure (by no longer
- /// referencing it). It is possible (although not commmon) this buffer could be rented as we attempt
- /// to free it. A rent event before or after this event for the same ID, is a rare, but expected case.
- /// </summary>
- [Event(4, Level = EventLevel.Informational)]
- internal void BufferTrimmed(int bufferId, int bufferSize, int poolId) => WriteEvent(4, bufferId, bufferSize, poolId);
-
- /// <summary>
- /// Event raised when we check to trim buffers.
- /// </summary>
- [Event(5, Level = EventLevel.Informational)]
- internal void BufferTrimPoll(int milliseconds, int pressure) => WriteEvent(5, milliseconds, pressure);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/Reader.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/Reader.cs
deleted file mode 100644
index 069636b0357..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/Reader.cs
+++ /dev/null
@@ -1,128 +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 System.Numerics;
-using System.Runtime.CompilerServices;
-
-namespace System.Buffers.Binary
-{
- /// <summary>
- /// Reads bytes as primitives with specific endianness
- /// </summary>
- /// <remarks>
- /// For native formats, MemoryExtensions.Read{T}; should be used.
- /// Use these helpers when you need to read specific endinanness.
- /// </remarks>
- public static partial class BinaryPrimitives
- {
- /// <summary>
- /// This is a no-op and added only for consistency.
- /// This allows the caller to read a struct of numeric primitives and reverse each field
- /// rather than having to skip sbyte fields.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static sbyte ReverseEndianness(sbyte value)
- {
- return value;
- }
-
- /// <summary>
- /// Reverses a primitive value - performs an endianness swap
- /// </summary>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static short ReverseEndianness(short value) => (short)ReverseEndianness((ushort)value);
-
- /// <summary>
- /// Reverses a primitive value - performs an endianness swap
- /// </summary>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int ReverseEndianness(int value) => (int)ReverseEndianness((uint)value);
-
- /// <summary>
- /// Reverses a primitive value - performs an endianness swap
- /// </summary>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static long ReverseEndianness(long value) => (long)ReverseEndianness((ulong)value);
-
- /// <summary>
- /// This is a no-op and added only for consistency.
- /// This allows the caller to read a struct of numeric primitives and reverse each field
- /// rather than having to skip byte fields.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static byte ReverseEndianness(byte value)
- {
- return value;
- }
-
- /// <summary>
- /// Reverses a primitive value - performs an endianness swap
- /// </summary>
- [CLSCompliant(false)]
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ushort ReverseEndianness(ushort value)
- {
- // Don't need to AND with 0xFF00 or 0x00FF since the final
- // cast back to ushort will clear out all bits above [ 15 .. 00 ].
- // This is normally implemented via "movzx eax, ax" on the return.
- // Alternatively, the compiler could elide the movzx instruction
- // entirely if it knows the caller is only going to access "ax"
- // instead of "eax" / "rax" when the function returns.
-
- return (ushort)((value >> 8) + (value << 8));
- }
-
- /// <summary>
- /// Reverses a primitive value - performs an endianness swap
- /// </summary>
- [CLSCompliant(false)]
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static uint ReverseEndianness(uint value)
- {
- // This takes advantage of the fact that the JIT can detect
- // ROL32 / ROR32 patterns and output the correct intrinsic.
- //
- // Input: value = [ ww xx yy zz ]
- //
- // First line generates : [ ww xx yy zz ]
- // & [ 00 FF 00 FF ]
- // = [ 00 xx 00 zz ]
- // ROR32(8) = [ zz 00 xx 00 ]
- //
- // Second line generates: [ ww xx yy zz ]
- // & [ FF 00 FF 00 ]
- // = [ ww 00 yy 00 ]
- // ROL32(8) = [ 00 yy 00 ww ]
- //
- // (sum) = [ zz yy xx ww ]
- //
- // Testing shows that throughput increases if the AND
- // is performed before the ROL / ROR.
-
- return BitOperations.RotateRight(value & 0x00FF00FFu, 8) // xx zz
- + BitOperations.RotateLeft(value & 0xFF00FF00u, 8); // ww yy
- }
-
- /// <summary>
- /// Reverses a primitive value - performs an endianness swap
- /// </summary>
- [CLSCompliant(false)]
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ulong ReverseEndianness(ulong value)
- {
- // Operations on 32-bit values have higher throughput than
- // operations on 64-bit values, so decompose.
-
- return ((ulong)ReverseEndianness((uint)value) << 32)
- + ReverseEndianness((uint)(value >> 32));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/ReaderBigEndian.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/ReaderBigEndian.cs
deleted file mode 100644
index c641638e6a2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/ReaderBigEndian.cs
+++ /dev/null
@@ -1,192 +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 System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Buffers.Binary
-{
- public static partial class BinaryPrimitives
- {
- /// <summary>
- /// Reads an Int16 out of a read-only span of bytes as big endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static short ReadInt16BigEndian(ReadOnlySpan<byte> source)
- {
- short result = MemoryMarshal.Read<short>(source);
- if (BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads an Int32 out of a read-only span of bytes as big endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int ReadInt32BigEndian(ReadOnlySpan<byte> source)
- {
- int result = MemoryMarshal.Read<int>(source);
- if (BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads an Int64 out of a read-only span of bytes as big endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static long ReadInt64BigEndian(ReadOnlySpan<byte> source)
- {
- long result = MemoryMarshal.Read<long>(source);
- if (BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads a UInt16 out of a read-only span of bytes as big endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ushort ReadUInt16BigEndian(ReadOnlySpan<byte> source)
- {
- ushort result = MemoryMarshal.Read<ushort>(source);
- if (BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads a UInt32 out of a read-only span of bytes as big endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static uint ReadUInt32BigEndian(ReadOnlySpan<byte> source)
- {
- uint result = MemoryMarshal.Read<uint>(source);
- if (BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads a UInt64 out of a read-only span of bytes as big endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ulong ReadUInt64BigEndian(ReadOnlySpan<byte> source)
- {
- ulong result = MemoryMarshal.Read<ulong>(source);
- if (BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads an Int16 out of a read-only span of bytes as big endian.
- /// <returns>If the span is too small to contain an Int16, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadInt16BigEndian(ReadOnlySpan<byte> source, out short value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
-
- /// <summary>
- /// Reads an Int32 out of a read-only span of bytes as big endian.
- /// <returns>If the span is too small to contain an Int32, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadInt32BigEndian(ReadOnlySpan<byte> source, out int value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
-
- /// <summary>
- /// Reads an Int64 out of a read-only span of bytes as big endian.
- /// <returns>If the span is too small to contain an Int64, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadInt64BigEndian(ReadOnlySpan<byte> source, out long value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
-
- /// <summary>
- /// Reads a UInt16 out of a read-only span of bytes as big endian.
- /// <returns>If the span is too small to contain a UInt16, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadUInt16BigEndian(ReadOnlySpan<byte> source, out ushort value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
-
- /// <summary>
- /// Reads a UInt32 out of a read-only span of bytes as big endian.
- /// <returns>If the span is too small to contain a UInt32, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadUInt32BigEndian(ReadOnlySpan<byte> source, out uint value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
-
- /// <summary>
- /// Reads a UInt64 out of a read-only span of bytes as big endian.
- /// <returns>If the span is too small to contain a UInt64, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadUInt64BigEndian(ReadOnlySpan<byte> source, out ulong value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/ReaderLittleEndian.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/ReaderLittleEndian.cs
deleted file mode 100644
index bd832f8995a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/ReaderLittleEndian.cs
+++ /dev/null
@@ -1,192 +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 System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Buffers.Binary
-{
- public static partial class BinaryPrimitives
- {
- /// <summary>
- /// Reads an Int16 out of a read-only span of bytes as little endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static short ReadInt16LittleEndian(ReadOnlySpan<byte> source)
- {
- short result = MemoryMarshal.Read<short>(source);
- if (!BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads an Int32 out of a read-only span of bytes as little endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int ReadInt32LittleEndian(ReadOnlySpan<byte> source)
- {
- int result = MemoryMarshal.Read<int>(source);
- if (!BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads an Int64 out of a read-only span of bytes as little endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static long ReadInt64LittleEndian(ReadOnlySpan<byte> source)
- {
- long result = MemoryMarshal.Read<long>(source);
- if (!BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads a UInt16 out of a read-only span of bytes as little endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ushort ReadUInt16LittleEndian(ReadOnlySpan<byte> source)
- {
- ushort result = MemoryMarshal.Read<ushort>(source);
- if (!BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads a UInt32 out of a read-only span of bytes as little endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static uint ReadUInt32LittleEndian(ReadOnlySpan<byte> source)
- {
- uint result = MemoryMarshal.Read<uint>(source);
- if (!BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads a UInt64 out of a read-only span of bytes as little endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ulong ReadUInt64LittleEndian(ReadOnlySpan<byte> source)
- {
- ulong result = MemoryMarshal.Read<ulong>(source);
- if (!BitConverter.IsLittleEndian)
- {
- result = ReverseEndianness(result);
- }
- return result;
- }
-
- /// <summary>
- /// Reads an Int16 out of a read-only span of bytes as little endian.
- /// <returns>If the span is too small to contain an Int16, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadInt16LittleEndian(ReadOnlySpan<byte> source, out short value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
-
- /// <summary>
- /// Reads an Int32 out of a read-only span of bytes as little endian.
- /// <returns>If the span is too small to contain an Int32, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadInt32LittleEndian(ReadOnlySpan<byte> source, out int value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
-
- /// <summary>
- /// Reads an Int64 out of a read-only span of bytes as little endian.
- /// <returns>If the span is too small to contain an Int64, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadInt64LittleEndian(ReadOnlySpan<byte> source, out long value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
-
- /// <summary>
- /// Reads a UInt16 out of a read-only span of bytes as little endian.
- /// <returns>If the span is too small to contain a UInt16, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadUInt16LittleEndian(ReadOnlySpan<byte> source, out ushort value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
-
- /// <summary>
- /// Reads a UInt32 out of a read-only span of bytes as little endian.
- /// <returns>If the span is too small to contain a UInt32, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadUInt32LittleEndian(ReadOnlySpan<byte> source, out uint value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
-
- /// <summary>
- /// Reads a UInt64 out of a read-only span of bytes as little endian.
- /// <returns>If the span is too small to contain a UInt64, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryReadUInt64LittleEndian(ReadOnlySpan<byte> source, out ulong value)
- {
- bool success = MemoryMarshal.TryRead(source, out value);
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return success;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/WriterBigEndian.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/WriterBigEndian.cs
deleted file mode 100644
index 78be9b5a035..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/WriterBigEndian.cs
+++ /dev/null
@@ -1,180 +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 System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Buffers.Binary
-{
- public static partial class BinaryPrimitives
- {
- /// <summary>
- /// Writes an Int16 into a span of bytes as big endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteInt16BigEndian(Span<byte> destination, short value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Writes an Int32 into a span of bytes as big endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteInt32BigEndian(Span<byte> destination, int value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Writes an Int64 into a span of bytes as big endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteInt64BigEndian(Span<byte> destination, long value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt16 into a span of bytes as big endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteUInt16BigEndian(Span<byte> destination, ushort value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt32 into a span of bytes as big endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteUInt32BigEndian(Span<byte> destination, uint value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt64 into a span of bytes as big endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteUInt64BigEndian(Span<byte> destination, ulong value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Writes an Int16 into a span of bytes as big endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteInt16BigEndian(Span<byte> destination, short value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
-
- /// <summary>
- /// Writes an Int32 into a span of bytes as big endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteInt32BigEndian(Span<byte> destination, int value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
-
- /// <summary>
- /// Writes an Int64 into a span of bytes as big endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteInt64BigEndian(Span<byte> destination, long value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt16 into a span of bytes as big endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteUInt16BigEndian(Span<byte> destination, ushort value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt32 into a span of bytes as big endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteUInt32BigEndian(Span<byte> destination, uint value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt64 into a span of bytes as big endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteUInt64BigEndian(Span<byte> destination, ulong value)
- {
- if (BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/WriterLittleEndian.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/WriterLittleEndian.cs
deleted file mode 100644
index 5d63ee5f0b4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Binary/WriterLittleEndian.cs
+++ /dev/null
@@ -1,180 +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 System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Buffers.Binary
-{
- public static partial class BinaryPrimitives
- {
- /// <summary>
- /// Writes an Int16 into a span of bytes as little endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteInt16LittleEndian(Span<byte> destination, short value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Writes an Int32 into a span of bytes as little endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteInt32LittleEndian(Span<byte> destination, int value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Writes an Int64 into a span of bytes as little endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteInt64LittleEndian(Span<byte> destination, long value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt16 into a span of bytes as little endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteUInt16LittleEndian(Span<byte> destination, ushort value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt32 into a span of bytes as little endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteUInt32LittleEndian(Span<byte> destination, uint value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt64 into a span of bytes as little endian.
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteUInt64LittleEndian(Span<byte> destination, ulong value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- MemoryMarshal.Write(destination, ref value);
- }
-
- /// <summary>
- /// Writes an Int16 into a span of bytes as little endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteInt16LittleEndian(Span<byte> destination, short value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
-
- /// <summary>
- /// Writes an Int32 into a span of bytes as little endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteInt32LittleEndian(Span<byte> destination, int value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
-
- /// <summary>
- /// Writes an Int64 into a span of bytes as little endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteInt64LittleEndian(Span<byte> destination, long value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt16 into a span of bytes as little endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteUInt16LittleEndian(Span<byte> destination, ushort value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt32 into a span of bytes as little endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteUInt32LittleEndian(Span<byte> destination, uint value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
-
- /// <summary>
- /// Write a UInt64 into a span of bytes as little endian.
- /// <returns>If the span is too small to contain the value, return false.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWriteUInt64LittleEndian(Span<byte> destination, ulong value)
- {
- if (!BitConverter.IsLittleEndian)
- {
- value = ReverseEndianness(value);
- }
- return MemoryMarshal.TryWrite(destination, ref value);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs
deleted file mode 100644
index f24ddf49d0e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs
+++ /dev/null
@@ -1,265 +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 System.Diagnostics;
-using System.Threading;
-
-namespace System.Buffers
-{
- internal sealed partial class ConfigurableArrayPool<T> : ArrayPool<T>
- {
- /// <summary>The default maximum length of each array in the pool (2^20).</summary>
- private const int DefaultMaxArrayLength = 1024 * 1024;
- /// <summary>The default maximum number of arrays per bucket that are available for rent.</summary>
- private const int DefaultMaxNumberOfArraysPerBucket = 50;
-
- private readonly Bucket[] _buckets;
-
- internal ConfigurableArrayPool() : this(DefaultMaxArrayLength, DefaultMaxNumberOfArraysPerBucket)
- {
- }
-
- internal ConfigurableArrayPool(int maxArrayLength, int maxArraysPerBucket)
- {
- if (maxArrayLength <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(maxArrayLength));
- }
- if (maxArraysPerBucket <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(maxArraysPerBucket));
- }
-
- // Our bucketing algorithm has a min length of 2^4 and a max length of 2^30.
- // Constrain the actual max used to those values.
- const int MinimumArrayLength = 0x10, MaximumArrayLength = 0x40000000;
- if (maxArrayLength > MaximumArrayLength)
- {
- maxArrayLength = MaximumArrayLength;
- }
- else if (maxArrayLength < MinimumArrayLength)
- {
- maxArrayLength = MinimumArrayLength;
- }
-
- // Create the buckets.
- int poolId = Id;
- int maxBuckets = Utilities.SelectBucketIndex(maxArrayLength);
- var buckets = new Bucket[maxBuckets + 1];
- for (int i = 0; i < buckets.Length; i++)
- {
- buckets[i] = new Bucket(Utilities.GetMaxSizeForBucket(i), maxArraysPerBucket, poolId);
- }
- _buckets = buckets;
- }
-
- /// <summary>Gets an ID for the pool to use with events.</summary>
- private int Id => GetHashCode();
-
- public override T[] Rent(int minimumLength)
- {
- // Arrays can't be smaller than zero. We allow requesting zero-length arrays (even though
- // pooling such an array isn't valuable) as it's a valid length array, and we want the pool
- // to be usable in general instead of using `new`, even for computed lengths.
- if (minimumLength < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(minimumLength));
- }
- else if (minimumLength == 0)
- {
- // No need for events with the empty array. Our pool is effectively infinite
- // and we'll never allocate for rents and never store for returns.
- return Array.Empty<T>();
- }
-
- ArrayPoolEventSource log = ArrayPoolEventSource.Log;
- T[]? buffer;
-
- int index = Utilities.SelectBucketIndex(minimumLength);
- if (index < _buckets.Length)
- {
- // Search for an array starting at the 'index' bucket. If the bucket is empty, bump up to the
- // next higher bucket and try that one, but only try at most a few buckets.
- const int MaxBucketsToTry = 2;
- int i = index;
- do
- {
- // Attempt to rent from the bucket. If we get a buffer from it, return it.
- buffer = _buckets[i].Rent();
- if (buffer != null)
- {
- if (log.IsEnabled())
- {
- log.BufferRented(buffer.GetHashCode(), buffer.Length, Id, _buckets[i].Id);
- }
- return buffer;
- }
- }
- while (++i < _buckets.Length && i != index + MaxBucketsToTry);
-
- // The pool was exhausted for this buffer size. Allocate a new buffer with a size corresponding
- // to the appropriate bucket.
- buffer = new T[_buckets[index]._bufferLength];
- }
- else
- {
- // The request was for a size too large for the pool. Allocate an array of exactly the requested length.
- // When it's returned to the pool, we'll simply throw it away.
- buffer = new T[minimumLength];
- }
-
- if (log.IsEnabled())
- {
- int bufferId = buffer.GetHashCode(), bucketId = -1; // no bucket for an on-demand allocated buffer
- log.BufferRented(bufferId, buffer.Length, Id, bucketId);
- log.BufferAllocated(bufferId, buffer.Length, Id, bucketId, index >= _buckets.Length ?
- ArrayPoolEventSource.BufferAllocatedReason.OverMaximumSize : ArrayPoolEventSource.BufferAllocatedReason.PoolExhausted);
- }
-
- return buffer;
- }
-
- public override void Return(T[] array, bool clearArray = false)
- {
- if (array == null)
- {
- throw new ArgumentNullException(nameof(array));
- }
- else if (array.Length == 0)
- {
- // Ignore empty arrays. When a zero-length array is rented, we return a singleton
- // rather than actually taking a buffer out of the lowest bucket.
- return;
- }
-
- // Determine with what bucket this array length is associated
- int bucket = Utilities.SelectBucketIndex(array.Length);
-
- // If we can tell that the buffer was allocated, drop it. Otherwise, check if we have space in the pool
- if (bucket < _buckets.Length)
- {
- // Clear the array if the user requests
- if (clearArray)
- {
- Array.Clear(array, 0, array.Length);
- }
-
- // Return the buffer to its bucket. In the future, we might consider having Return return false
- // instead of dropping a bucket, in which case we could try to return to a lower-sized bucket,
- // just as how in Rent we allow renting from a higher-sized bucket.
- _buckets[bucket].Return(array);
- }
-
- // Log that the buffer was returned
- ArrayPoolEventSource log = ArrayPoolEventSource.Log;
- if (log.IsEnabled())
- {
- log.BufferReturned(array.GetHashCode(), array.Length, Id);
- }
- }
-
- /// <summary>Provides a thread-safe bucket containing buffers that can be Rent'd and Return'd.</summary>
- private sealed class Bucket
- {
- internal readonly int _bufferLength;
- private readonly T[]?[] _buffers;
- private readonly int _poolId;
-
- private SpinLock _lock; // do not make this readonly; it's a mutable struct
- private int _index;
-
- /// <summary>
- /// Creates the pool with numberOfBuffers arrays where each buffer is of bufferLength length.
- /// </summary>
- internal Bucket(int bufferLength, int numberOfBuffers, int poolId)
- {
- _lock = new SpinLock(Debugger.IsAttached); // only enable thread tracking if debugger is attached; it adds non-trivial overheads to Enter/Exit
- _buffers = new T[numberOfBuffers][];
- _bufferLength = bufferLength;
- _poolId = poolId;
- }
-
- /// <summary>Gets an ID for the bucket to use with events.</summary>
- internal int Id => GetHashCode();
-
- /// <summary>Takes an array from the bucket. If the bucket is empty, returns null.</summary>
- internal T[]? Rent()
- {
- T[]?[] buffers = _buffers;
- T[]? buffer = null;
-
- // While holding the lock, grab whatever is at the next available index and
- // update the index. We do as little work as possible while holding the spin
- // lock to minimize contention with other threads. The try/finally is
- // necessary to properly handle thread aborts on platforms which have them.
- bool lockTaken = false, allocateBuffer = false;
- try
- {
- _lock.Enter(ref lockTaken);
-
- if (_index < buffers.Length)
- {
- buffer = buffers[_index];
- buffers[_index++] = null;
- allocateBuffer = buffer == null;
- }
- }
- finally
- {
- if (lockTaken) _lock.Exit(false);
- }
-
- // While we were holding the lock, we grabbed whatever was at the next available index, if
- // there was one. If we tried and if we got back null, that means we hadn't yet allocated
- // for that slot, in which case we should do so now.
- if (allocateBuffer)
- {
- buffer = new T[_bufferLength];
-
- ArrayPoolEventSource log = ArrayPoolEventSource.Log;
- if (log.IsEnabled())
- {
- log.BufferAllocated(buffer.GetHashCode(), _bufferLength, _poolId, Id,
- ArrayPoolEventSource.BufferAllocatedReason.Pooled);
- }
- }
-
- return buffer;
- }
-
- /// <summary>
- /// Attempts to return the buffer to the bucket. If successful, the buffer will be stored
- /// in the bucket and true will be returned; otherwise, the buffer won't be stored, and false
- /// will be returned.
- /// </summary>
- internal void Return(T[] array)
- {
- // Check to see if the buffer is the correct size for this bucket
- if (array.Length != _bufferLength)
- {
- throw new ArgumentException(SR.ArgumentException_BufferNotFromPool, nameof(array));
- }
-
- // While holding the spin lock, if there's room available in the bucket,
- // put the buffer into the next available slot. Otherwise, we just drop it.
- // The try/finally is necessary to properly handle thread aborts on platforms
- // which have them.
- bool lockTaken = false;
- try
- {
- _lock.Enter(ref lockTaken);
-
- if (_index != 0)
- {
- _buffers[--_index] = array;
- }
- }
- finally
- {
- if (lockTaken) _lock.Exit(false);
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/IMemoryOwner.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/IMemoryOwner.cs
deleted file mode 100644
index 44f16c58273..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/IMemoryOwner.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Buffers
-{
- /// <summary>
- /// Owner of Memory<typeparamref name="T"/> that is responsible for disposing the underlying memory appropriately.
- /// </summary>
- public interface IMemoryOwner<T> : IDisposable
- {
- /// <summary>
- /// Returns a Memory<typeparamref name="T"/>.
- /// </summary>
- Memory<T> Memory { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/IPinnable.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/IPinnable.cs
deleted file mode 100644
index 623e716a053..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/IPinnable.cs
+++ /dev/null
@@ -1,25 +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.
-
-namespace System.Buffers
-{
- /// <summary>
- /// Provides a mechanism for pinning and unpinning objects to prevent the GC from moving them.
- /// </summary>
- public interface IPinnable
- {
- /// <summary>
- /// Call this method to indicate that the IPinnable object can not be moved by the garbage collector.
- /// The address of the pinned object can be taken.
- /// <param name="elementIndex">The offset to the element within the memory at which the returned <see cref="MemoryHandle"/> points to.</param>
- /// </summary>
- MemoryHandle Pin(int elementIndex);
-
- /// <summary>
- /// Call this method to indicate that the IPinnable object no longer needs to be pinned.
- /// The garbage collector is free to move the object now.
- /// </summary>
- void Unpin();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/MemoryHandle.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/MemoryHandle.cs
deleted file mode 100644
index f1da6d273ea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/MemoryHandle.cs
+++ /dev/null
@@ -1,57 +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 System.Runtime.InteropServices;
-
-namespace System.Buffers
-{
- /// <summary>
- /// A handle for the memory.
- /// </summary>
- public unsafe struct MemoryHandle : IDisposable
- {
- private void* _pointer;
- private GCHandle _handle;
- private IPinnable? _pinnable;
-
- /// <summary>
- /// Creates a new memory handle for the memory.
- /// </summary>
- /// <param name="pointer">pointer to memory</param>
- /// <param name="pinnable">reference to manually managed object, or default if there is no memory manager</param>
- /// <param name="handle">handle used to pin array buffers</param>
- [CLSCompliant(false)]
- public MemoryHandle(void* pointer, GCHandle handle = default, IPinnable? pinnable = default)
- {
- _pointer = pointer;
- _handle = handle;
- _pinnable = pinnable;
- }
-
- /// <summary>
- /// Returns the pointer to memory, where the memory is assumed to be pinned and hence the address won't change.
- /// </summary>
- [CLSCompliant(false)]
- public void* Pointer => _pointer;
-
- /// <summary>
- /// Frees the pinned handle and releases IPinnable.
- /// </summary>
- public void Dispose()
- {
- if (_handle.IsAllocated)
- {
- _handle.Free();
- }
-
- if (_pinnable != null)
- {
- _pinnable.Unpin();
- _pinnable = null;
- }
-
- _pointer = null;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/MemoryManager.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/MemoryManager.cs
deleted file mode 100644
index c0bb0216cc2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/MemoryManager.cs
+++ /dev/null
@@ -1,74 +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 System.Runtime.CompilerServices;
-
-namespace System.Buffers
-{
- /// <summary>
- /// Manager of <see cref="System.Memory{T}"/> that provides the implementation.
- /// </summary>
- public abstract class MemoryManager<T> : IMemoryOwner<T>, IPinnable
- {
- /// <summary>
- /// Returns a <see cref="System.Memory{T}"/>.
- /// </summary>
- public virtual Memory<T> Memory => new Memory<T>(this, GetSpan().Length);
-
- /// <summary>
- /// Returns a span wrapping the underlying memory.
- /// </summary>
- public abstract Span<T> GetSpan();
-
- /// <summary>
- /// Returns a handle to the memory that has been pinned and hence its address can be taken.
- /// </summary>
- /// <param name="elementIndex">The offset to the element within the memory at which the returned <see cref="MemoryHandle"/> points to. (default = 0)</param>
- public abstract MemoryHandle Pin(int elementIndex = 0);
-
- /// <summary>
- /// Lets the garbage collector know that the object is free to be moved now.
- /// </summary>
- public abstract void Unpin();
-
- /// <summary>
- /// Returns a <see cref="System.Memory{T}"/> for the current <see cref="MemoryManager{T}"/>.
- /// </summary>
- /// <param name="length">The element count in the memory, starting at offset 0.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- protected Memory<T> CreateMemory(int length) => new Memory<T>(this, length);
-
- /// <summary>
- /// Returns a <see cref="System.Memory{T}"/> for the current <see cref="MemoryManager{T}"/>.
- /// </summary>
- /// <param name="start">The offset to the element which the returned memory starts at.</param>
- /// <param name="length">The element count in the memory, starting at element offset <paramref name="start"/>.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- protected Memory<T> CreateMemory(int start, int length) => new Memory<T>(this, start, length);
-
- /// <summary>
- /// Returns an array segment.
- /// <remarks>Returns the default array segment if not overriden.</remarks>
- /// </summary>
- protected internal virtual bool TryGetArray(out ArraySegment<T> segment)
- {
- segment = default;
- return false;
- }
-
- /// <summary>
- /// Implements IDisposable.
- /// </summary>
- void IDisposable.Dispose()
- {
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
-
- /// <summary>
- /// Clean up of any leftover managed and unmanaged resources.
- /// </summary>
- protected abstract void Dispose(bool disposing);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/OperationStatus.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/OperationStatus.cs
deleted file mode 100644
index e9ddcab5714..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/OperationStatus.cs
+++ /dev/null
@@ -1,34 +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.
-
-namespace System.Buffers
-{
- /// <summary>
- /// This enum defines the various potential status that can be returned from Span-based operations
- /// that support processing of input contained in multiple discontiguous buffers.
- /// </summary>
- public enum OperationStatus
- {
- /// <summary>
- /// The entire input buffer has been processed and the operation is complete.
- /// </summary>
- Done,
- /// <summary>
- /// The input is partially processed, up to what could fit into the destination buffer.
- /// The caller can enlarge the destination buffer, slice the buffers appropriately, and retry.
- /// </summary>
- DestinationTooSmall,
- /// <summary>
- /// The input is partially processed, up to the last valid chunk of the input that could be consumed.
- /// The caller can stitch the remaining unprocessed input with more data, slice the buffers appropriately, and retry.
- /// </summary>
- NeedMoreData,
- /// <summary>
- /// The input contained invalid bytes which could not be processed. If the input is partially processed,
- /// the destination contains the partial result. This guarantees that no additional data appended to the input
- /// will make the invalid sequence valid.
- /// </summary>
- InvalidData,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/StandardFormat.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/StandardFormat.cs
deleted file mode 100644
index 24a49838308..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/StandardFormat.cs
+++ /dev/null
@@ -1,209 +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 System.Diagnostics;
-
-namespace System.Buffers
-{
- /// <summary>
- /// Represents a standard formatting string without using an actual String. A StandardFormat consists of a character (such as 'G', 'D' or 'X')
- /// and an optional precision ranging from 0..99, or the special value NoPrecision.
- /// </summary>
- public readonly struct StandardFormat : IEquatable<StandardFormat>
- {
- /// <summary>
- /// Precision values for format that don't use a precision, or for when the precision is to be unspecified.
- /// </summary>
- public const byte NoPrecision = byte.MaxValue;
-
- /// <summary>
- /// The maximum valid precision value.
- /// </summary>
- public const byte MaxPrecision = 99;
-
- private readonly byte _format;
- private readonly byte _precision;
-
- /// <summary>
- /// The character component of the format.
- /// </summary>
- public char Symbol => (char)_format;
-
- /// <summary>
- /// The precision component of the format. Ranges from 0..9 or the special value NoPrecision.
- /// </summary>
- public byte Precision => _precision;
-
- /// <summary>
- /// true if Precision is a value other than NoPrecision
- /// </summary>
- public bool HasPrecision => _precision != NoPrecision;
-
- /// <summary>
- /// true if the StandardFormat == default(StandardFormat)
- /// </summary>
- public bool IsDefault => _format == 0 && _precision == 0;
-
- /// <summary>
- /// Create a StandardFormat.
- /// </summary>
- /// <param name="symbol">A type-specific formatting character such as 'G', 'D' or 'X'</param>
- /// <param name="precision">An optional precision ranging from 0..9 or the special value NoPrecision (the default)</param>
- public StandardFormat(char symbol, byte precision = NoPrecision)
- {
- if (precision != NoPrecision && precision > MaxPrecision)
- ThrowHelper.ThrowArgumentOutOfRangeException_PrecisionTooLarge();
- if (symbol != (byte)symbol)
- ThrowHelper.ThrowArgumentOutOfRangeException_SymbolDoesNotFit();
-
- _format = (byte)symbol;
- _precision = precision;
- }
-
- /// <summary>
- /// Converts a character to a StandardFormat using the NoPrecision precision.
- /// </summary>
- public static implicit operator StandardFormat(char symbol) => new StandardFormat(symbol);
-
- /// <summary>
- /// Converts a <see cref="ReadOnlySpan{Char}"/> into a StandardFormat
- /// </summary>
- public static StandardFormat Parse(ReadOnlySpan<char> format)
- {
- ParseHelper(format, out StandardFormat standardFormat, throws: true);
-
- return standardFormat;
- }
-
- /// <summary>
- /// Converts a classic .NET format string into a StandardFormat
- /// </summary>
- public static StandardFormat Parse(string? format) => format == null ? default : Parse(format.AsSpan());
-
- /// <summary>
- /// Tries to convert a <see cref="ReadOnlySpan{Char}"/> into a StandardFormat. A return value indicates whether the conversion succeeded or failed.
- /// </summary>
- public static bool TryParse(ReadOnlySpan<char> format, out StandardFormat result)
- {
- return ParseHelper(format, out result);
- }
-
- private static bool ParseHelper(ReadOnlySpan<char> format, out StandardFormat standardFormat, bool throws = false)
- {
- standardFormat = default;
-
- if (format.Length == 0)
- return true;
-
- char symbol = format[0];
- byte precision;
- if (format.Length == 1)
- {
- precision = NoPrecision;
- }
- else
- {
- uint parsedPrecision = 0;
- for (int srcIndex = 1; srcIndex < format.Length; srcIndex++)
- {
- uint digit = format[srcIndex] - 48u; // '0'
- if (digit > 9)
- {
- return throws ? throw new FormatException(SR.Format(SR.Argument_CannotParsePrecision, MaxPrecision)) : false;
- }
- parsedPrecision = parsedPrecision * 10 + digit;
- if (parsedPrecision > MaxPrecision)
- {
- return throws ? throw new FormatException(SR.Format(SR.Argument_PrecisionTooLarge, MaxPrecision)) : false;
- }
- }
-
- precision = (byte)parsedPrecision;
- }
-
- standardFormat = new StandardFormat(symbol, precision);
- return true;
- }
-
- /// <summary>
- /// Returns true if both the Symbol and Precision are equal.
- /// </summary>
- public override bool Equals(object? obj) => obj is StandardFormat other && Equals(other);
-
- /// <summary>
- /// Compute a hash code.
- /// </summary>
- public override int GetHashCode() => _format.GetHashCode() ^ _precision.GetHashCode();
-
- /// <summary>
- /// Returns true if both the Symbol and Precision are equal.
- /// </summary>
- public bool Equals(StandardFormat other) => _format == other._format && _precision == other._precision;
-
- /// <summary>
- /// Returns the format in classic .NET format.
- /// </summary>
- public override string ToString()
- {
- Span<char> buffer = stackalloc char[FormatStringLength];
- int charsWritten = Format(buffer);
- return new string(buffer.Slice(0, charsWritten));
- }
-
- /// <summary>The exact buffer length required by <see cref="Format"/>.</summary>
- internal const int FormatStringLength = 3;
-
- /// <summary>
- /// Formats the format in classic .NET format.
- /// </summary>
- internal int Format(Span<char> destination)
- {
- Debug.Assert(destination.Length == FormatStringLength);
-
- int count = 0;
- char symbol = Symbol;
-
- if (symbol != default &&
- (uint)destination.Length == FormatStringLength) // to eliminate bounds checks
- {
- destination[0] = symbol;
- count = 1;
-
- uint precision = Precision;
- if (precision != NoPrecision)
- {
- // Note that Precision is stored as a byte, so in theory it could contain
- // values > MaxPrecision (99). But all supported mechanisms for creating a
- // StandardFormat limit values to being <= MaxPrecision, so the only way a value
- // could be larger than that is if unsafe code or the equivalent were used
- // to force a larger invalid value in, in which case we don't need to
- // guarantee such an invalid value is properly roundtripped through here;
- // we just need to make sure things aren't corrupted further.
-
- if (precision >= 10)
- {
- uint div = Math.DivRem(precision, 10, out precision);
- destination[1] = (char)('0' + div % 10);
- count = 2;
- }
-
- destination[count] = (char)('0' + precision);
- count++;
- }
- }
-
- return count;
- }
-
- /// <summary>
- /// Returns true if both the Symbol and Precision are equal.
- /// </summary>
- public static bool operator ==(StandardFormat left, StandardFormat right) => left.Equals(right);
-
- /// <summary>
- /// Returns false if both the Symbol and Precision are equal.
- /// </summary>
- public static bool operator !=(StandardFormat left, StandardFormat right) => !left.Equals(right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/FormattingHelpers.CountDigits.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/FormattingHelpers.CountDigits.cs
deleted file mode 100644
index 8235339820d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/FormattingHelpers.CountDigits.cs
+++ /dev/null
@@ -1,138 +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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-
-namespace System.Buffers.Text
-{
- internal static partial class FormattingHelpers
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int CountDigits(ulong value)
- {
- int digits = 1;
- uint part;
- if (value >= 10000000)
- {
- if (value >= 100000000000000)
- {
- part = (uint)(value / 100000000000000);
- digits += 14;
- }
- else
- {
- part = (uint)(value / 10000000);
- digits += 7;
- }
- }
- else
- {
- part = (uint)value;
- }
-
- if (part < 10)
- {
- // no-op
- }
- else if (part < 100)
- {
- digits++;
- }
- else if (part < 1000)
- {
- digits += 2;
- }
- else if (part < 10000)
- {
- digits += 3;
- }
- else if (part < 100000)
- {
- digits += 4;
- }
- else if (part < 1000000)
- {
- digits += 5;
- }
- else
- {
- Debug.Assert(part < 10000000);
- digits += 6;
- }
-
- return digits;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int CountDigits(uint value)
- {
- int digits = 1;
- if (value >= 100000)
- {
- value /= 100000;
- digits += 5;
- }
-
- if (value < 10)
- {
- // no-op
- }
- else if (value < 100)
- {
- digits++;
- }
- else if (value < 1000)
- {
- digits += 2;
- }
- else if (value < 10000)
- {
- digits += 3;
- }
- else
- {
- Debug.Assert(value < 100000);
- digits += 4;
- }
-
- return digits;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int CountHexDigits(ulong value)
- {
- return (64 - BitOperations.LeadingZeroCount(value | 1) + 3) >> 2;
- }
-
- // Counts the number of trailing '0' digits in a decimal number.
- // e.g., value = 0 => retVal = 0, valueWithoutTrailingZeros = 0
- // value = 1234 => retVal = 0, valueWithoutTrailingZeros = 1234
- // value = 320900 => retVal = 2, valueWithoutTrailingZeros = 3209
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int CountDecimalTrailingZeros(uint value, out uint valueWithoutTrailingZeros)
- {
- int zeroCount = 0;
-
- if (value != 0)
- {
- while (true)
- {
- uint temp = value / 10;
- if (value != (temp * 10))
- {
- break;
- }
-
- value = temp;
- zeroCount++;
- }
- }
-
- valueWithoutTrailingZeros = value;
- return zeroCount;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Constants.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Constants.cs
deleted file mode 100644
index e2f70f0b10e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Constants.cs
+++ /dev/null
@@ -1,34 +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.
-
-namespace System.Buffers.Text
-{
- internal static partial class Utf8Constants
- {
- public const byte Colon = (byte)':';
- public const byte Comma = (byte)',';
- public const byte Minus = (byte)'-';
- public const byte Period = (byte)'.';
- public const byte Plus = (byte)'+';
- public const byte Slash = (byte)'/';
- public const byte Space = (byte)' ';
- public const byte Hyphen = (byte)'-';
-
- public const byte Separator = (byte)',';
-
- // Invariant formatting uses groups of 3 for each number group separated by commas.
- // ex. 1,234,567,890
- public const int GroupSize = 3;
-
- public static readonly TimeSpan NullUtcOffset = TimeSpan.MinValue; // Utc offsets must range from -14:00 to 14:00 so this is never a valid offset.
-
- public const int DateTimeMaxUtcOffsetHours = 14; // The UTC offset portion of a TimeSpan or DateTime can be no more than 14 hours and no less than -14 hours.
-
- public const int DateTimeNumFractionDigits = 7; // TimeSpan and DateTime formats allow exactly up to many digits for specifying the fraction after the seconds.
- public const int MaxDateTimeFraction = 9999999; // ... and hence, the largest fraction expressible is this.
-
- public const ulong BillionMaxUIntValue = (ulong)uint.MaxValue * Billion; // maximum value that can be split into two uint32 {1-10 digits}{9 digits}
- public const uint Billion = 1000000000; // 10^9, used to split int64/uint64 into three uint32 {1-2 digits}{9 digits}{9 digits}
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs
deleted file mode 100644
index 16480d08f73..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs
+++ /dev/null
@@ -1,256 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Buffers.Text
-{
- // All the helper methods in this class assume that the by-ref is valid and that there is
- // enough space to fit the items that will be written into the underlying memory. The calling
- // code must have already done all the necessary validation.
- internal static partial class FormattingHelpers
- {
- // A simple lookup table for converting numbers to hex.
- internal const string HexTableLower = "0123456789abcdef";
-
- internal const string HexTableUpper = "0123456789ABCDEF";
-
- /// <summary>
- /// Returns the symbol contained within the standard format. If the standard format
- /// has not been initialized, returns the provided fallback symbol.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static char GetSymbolOrDefault(in StandardFormat format, char defaultSymbol)
- {
- // This is equivalent to the line below, but it is written in such a way
- // that the JIT is able to perform more optimizations.
- //
- // return (format.IsDefault) ? defaultSymbol : format.Symbol;
-
- char symbol = format.Symbol;
- if (symbol == default && format.Precision == default)
- {
- symbol = defaultSymbol;
- }
- return symbol;
- }
-
- #region UTF-8 Helper methods
-
- /// <summary>
- /// Fills a buffer with the ASCII character '0' (0x30).
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void FillWithAsciiZeros(Span<byte> buffer)
- {
- // This is a faster implementation of Span<T>.Fill().
- for (int i = 0; i < buffer.Length; i++)
- {
- buffer[i] = (byte)'0';
- }
- }
-
- public enum HexCasing : uint
- {
- // Output [ '0' .. '9' ] and [ 'A' .. 'F' ].
- Uppercase = 0,
-
- // Output [ '0' .. '9' ] and [ 'a' .. 'f' ].
- // This works because values in the range [ 0x30 .. 0x39 ] ([ '0' .. '9' ])
- // already have the 0x20 bit set, so ORing them with 0x20 is a no-op,
- // while outputs in the range [ 0x41 .. 0x46 ] ([ 'A' .. 'F' ])
- // don't have the 0x20 bit set, so ORing them maps to
- // [ 0x61 .. 0x66 ] ([ 'a' .. 'f' ]), which is what we want.
- Lowercase = 0x2020U,
- }
-
- // The JIT can elide bounds checks if 'startingIndex' is constant and if the caller is
- // writing to a span of known length (or the caller has already checked the bounds of the
- // furthest access).
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteHexByte(byte value, Span<byte> buffer, int startingIndex = 0, HexCasing casing = HexCasing.Uppercase)
- {
- // We want to pack the incoming byte into a single integer [ 0000 HHHH 0000 LLLL ],
- // where HHHH and LLLL are the high and low nibbles of the incoming byte. Then
- // subtract this integer from a constant minuend as shown below.
- //
- // [ 1000 1001 1000 1001 ]
- // - [ 0000 HHHH 0000 LLLL ]
- // =========================
- // [ *YYY **** *ZZZ **** ]
- //
- // The end result of this is that YYY is 0b000 if HHHH <= 9, and YYY is 0b111 if HHHH >= 10.
- // Similarly, ZZZ is 0b000 if LLLL <= 9, and ZZZ is 0b111 if LLLL >= 10.
- // (We don't care about the value of asterisked bits.)
- //
- // To turn a nibble in the range [ 0 .. 9 ] into hex, we calculate hex := nibble + 48 (ascii '0').
- // To turn a nibble in the range [ 10 .. 15 ] into hex, we calculate hex := nibble - 10 + 65 (ascii 'A').
- // => hex := nibble + 55.
- // The difference in the starting ASCII offset is (55 - 48) = 7, depending on whether the nibble is <= 9 or >= 10.
- // Since 7 is 0b111, this conveniently matches the YYY or ZZZ value computed during the earlier subtraction.
-
- // The commented out code below is code that directly implements the logic described above.
-
- // uint packedOriginalValues = (((uint)value & 0xF0U) << 4) + ((uint)value & 0x0FU);
- // uint difference = 0x8989U - packedOriginalValues;
- // uint add7Mask = (difference & 0x7070U) >> 4; // line YYY and ZZZ back up with the packed values
- // uint packedResult = packedOriginalValues + add7Mask + 0x3030U /* ascii '0' */;
-
- // The code below is equivalent to the commented out code above but has been tweaked
- // to allow codegen to make some extra optimizations.
-
- uint difference = (((uint)value & 0xF0U) << 4) + ((uint)value & 0x0FU) - 0x8989U;
- uint packedResult = ((((uint)(-(int)difference) & 0x7070U) >> 4) + difference + 0xB9B9U) | (uint)casing;
-
- // The low byte of the packed result contains the hex representation of the incoming byte's low nibble.
- // The adjacent byte of the packed result contains the hex representation of the incoming byte's high nibble.
-
- // Finally, write to the output buffer starting with the *highest* index so that codegen can
- // elide all but the first bounds check. (This only works if 'startingIndex' is a compile-time constant.)
-
- buffer[startingIndex + 1] = (byte)(packedResult);
- buffer[startingIndex] = (byte)(packedResult >> 8);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteDigits(ulong value, Span<byte> buffer)
- {
- // We can mutate the 'value' parameter since it's a copy-by-value local.
- // It'll be used to represent the value left over after each division by 10.
-
- for (int i = buffer.Length - 1; i >= 1; i--)
- {
- ulong temp = '0' + value;
- value /= 10;
- buffer[i] = (byte)(temp - (value * 10));
- }
-
- Debug.Assert(value < 10);
- buffer[0] = (byte)('0' + value);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteDigitsWithGroupSeparator(ulong value, Span<byte> buffer)
- {
- // We can mutate the 'value' parameter since it's a copy-by-value local.
- // It'll be used to represent the value left over after each division by 10.
-
- int digitsWritten = 0;
- for (int i = buffer.Length - 1; i >= 1; i--)
- {
- ulong temp = '0' + value;
- value /= 10;
- buffer[i] = (byte)(temp - (value * 10));
- if (digitsWritten == Utf8Constants.GroupSize - 1)
- {
- buffer[--i] = Utf8Constants.Comma;
- digitsWritten = 0;
- }
- else
- {
- digitsWritten++;
- }
- }
-
- Debug.Assert(value < 10);
- buffer[0] = (byte)('0' + value);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteDigits(uint value, Span<byte> buffer)
- {
- // We can mutate the 'value' parameter since it's a copy-by-value local.
- // It'll be used to represent the value left over after each division by 10.
-
- for (int i = buffer.Length - 1; i >= 1; i--)
- {
- uint temp = '0' + value;
- value /= 10;
- buffer[i] = (byte)(temp - (value * 10));
- }
-
- Debug.Assert(value < 10);
- buffer[0] = (byte)('0' + value);
- }
-
- /// <summary>
- /// Writes a value [ 0000 .. 9999 ] to the buffer starting at the specified offset.
- /// This method performs best when the starting index is a constant literal.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteFourDecimalDigits(uint value, Span<byte> buffer, int startingIndex = 0)
- {
- Debug.Assert(value <= 9999);
-
- uint temp = '0' + value;
- value /= 10;
- buffer[startingIndex + 3] = (byte)(temp - (value * 10));
-
- temp = '0' + value;
- value /= 10;
- buffer[startingIndex + 2] = (byte)(temp - (value * 10));
-
- temp = '0' + value;
- value /= 10;
- buffer[startingIndex + 1] = (byte)(temp - (value * 10));
-
- buffer[startingIndex] = (byte)('0' + value);
- }
-
- /// <summary>
- /// Writes a value [ 00 .. 99 ] to the buffer starting at the specified offset.
- /// This method performs best when the starting index is a constant literal.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteTwoDecimalDigits(uint value, Span<byte> buffer, int startingIndex = 0)
- {
- Debug.Assert(value <= 99);
-
- uint temp = '0' + value;
- value /= 10;
- buffer[startingIndex + 1] = (byte)(temp - (value * 10));
-
- buffer[startingIndex] = (byte)('0' + value);
- }
-
- #endregion UTF-8 Helper methods
-
- #region Math Helper methods
-
- /// <summary>
- /// We don't have access to Math.DivRem, so this is a copy of the implementation.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ulong DivMod(ulong numerator, ulong denominator, out ulong modulo)
- {
- ulong div = numerator / denominator;
- modulo = numerator - (div * denominator);
- return div;
- }
-
- /// <summary>
- /// We don't have access to Math.DivRem, so this is a copy of the implementation.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static uint DivMod(uint numerator, uint denominator, out uint modulo)
- {
- uint div = numerator / denominator;
- modulo = numerator - (div * denominator);
- return div;
- }
-
- #endregion Math Helper methods
-
- //
- // Enable use of ThrowHelper from TryFormat() routines without introducing dozens of non-code-coveraged "bytesWritten = 0; return false" boilerplate.
- //
- public static bool TryFormatThrowFormatException(out int bytesWritten)
- {
- bytesWritten = 0;
- ThrowHelper.ThrowFormatException_BadFormatSpecifier();
- return false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Boolean.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Boolean.cs
deleted file mode 100644
index d2bbcb82cc0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Boolean.cs
+++ /dev/null
@@ -1,105 +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 System.Buffers.Binary;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- /// <summary>
- /// Formats a Boolean as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G (default) True/False
- /// l true/false
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryFormat(bool value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- {
- char symbol = FormattingHelpers.GetSymbolOrDefault(format, 'G');
-
- if (value)
- {
- if (symbol == 'G')
- {
- // By having each branch perform its own call to TryWriteUInt32BigEndian, we ensure that a
- // constant value is passed to this routine, which means the compiler can reverse endianness
- // at compile time instead of runtime if necessary.
- const uint TrueValueUppercase = ('T' << 24) + ('r' << 16) + ('u' << 8) + ('e' << 0);
- if (!BinaryPrimitives.TryWriteUInt32BigEndian(destination, TrueValueUppercase))
- {
- goto BufferTooSmall;
- }
- }
- else if (symbol == 'l')
- {
- const uint TrueValueLowercase = ('t' << 24) + ('r' << 16) + ('u' << 8) + ('e' << 0);
- if (!BinaryPrimitives.TryWriteUInt32BigEndian(destination, TrueValueLowercase))
- {
- goto BufferTooSmall;
- }
- }
- else
- {
- goto BadFormat;
- }
-
- bytesWritten = 4;
- return true;
- }
- else
- {
- if (symbol == 'G')
- {
- // This check can't be performed earlier because we need to throw if an invalid symbol is
- // provided, even if the buffer is too small.
- if ((uint)4 >= (uint)destination.Length)
- {
- goto BufferTooSmall;
- }
-
- const uint FalsValueUppercase = ('F' << 24) + ('a' << 16) + ('l' << 8) + ('s' << 0);
- BinaryPrimitives.WriteUInt32BigEndian(destination, FalsValueUppercase);
- }
- else if (symbol == 'l')
- {
- if ((uint)4 >= (uint)destination.Length)
- {
- goto BufferTooSmall;
- }
-
- const uint FalsValueLowercase = ('f' << 24) + ('a' << 16) + ('l' << 8) + ('s' << 0);
- BinaryPrimitives.WriteUInt32BigEndian(destination, FalsValueLowercase);
- }
- else
- {
- goto BadFormat;
- }
-
- destination[4] = (byte)'e';
- bytesWritten = 5;
- return true;
- }
-
- BufferTooSmall:
- bytesWritten = 0;
- return false;
-
- BadFormat:
- return FormattingHelpers.TryFormatThrowFormatException(out bytesWritten);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs
deleted file mode 100644
index 7c4a2e342d8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs
+++ /dev/null
@@ -1,92 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- //
- // 'G' format for DateTime.
- //
- // 0123456789012345678
- // ---------------------------------
- // 05/25/2017 10:30:15
- //
- // Also handles the default ToString() format for DateTimeOffset
- //
- // 01234567890123456789012345
- // --------------------------
- // 05/25/2017 10:30:15 -08:00
- //
- private static bool TryFormatDateTimeG(DateTime value, TimeSpan offset, Span<byte> destination, out int bytesWritten)
- {
- const int MinimumBytesNeeded = 19;
-
- int bytesRequired = MinimumBytesNeeded;
-
- if (offset != Utf8Constants.NullUtcOffset)
- {
- bytesRequired += 7; // Space['+'|'-']hh:mm
- }
-
- if (destination.Length < bytesRequired)
- {
- bytesWritten = 0;
- return false;
- }
-
- bytesWritten = bytesRequired;
-
- // Hoist most of the bounds checks on buffer.
- { var unused = destination[MinimumBytesNeeded - 1]; }
-
- // TODO: Introduce an API which can parse DateTime instances efficiently, pulling out
- // all their properties (Month, Day, etc.) in one shot. This would help avoid the
- // duplicate work that implicitly results from calling these properties individually.
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Month, destination, 0);
- destination[2] = Utf8Constants.Slash;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Day, destination, 3);
- destination[5] = Utf8Constants.Slash;
-
- FormattingHelpers.WriteFourDecimalDigits((uint)value.Year, destination, 6);
- destination[10] = Utf8Constants.Space;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Hour, destination, 11);
- destination[13] = Utf8Constants.Colon;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Minute, destination, 14);
- destination[16] = Utf8Constants.Colon;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Second, destination, 17);
-
- if (offset != Utf8Constants.NullUtcOffset)
- {
- byte sign;
-
- if (offset < default(TimeSpan) /* a "const" version of TimeSpan.Zero */)
- {
- sign = Utf8Constants.Minus;
- offset = TimeSpan.FromTicks(-offset.Ticks);
- }
- else
- {
- sign = Utf8Constants.Plus;
- }
-
- // Writing the value backward allows the JIT to optimize by
- // performing a single bounds check against buffer.
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)offset.Minutes, destination, 24);
- destination[23] = Utf8Constants.Colon;
- FormattingHelpers.WriteTwoDecimalDigits((uint)offset.Hours, destination, 21);
- destination[20] = sign;
- destination[19] = Utf8Constants.Space;
- }
-
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.L.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.L.cs
deleted file mode 100644
index 699f91f39c8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.L.cs
+++ /dev/null
@@ -1,66 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- // Rfc1123 - lowercase
- //
- // 01234567890123456789012345678
- // -----------------------------
- // tue, 03 jan 2017 08:08:05 gmt
- //
- private static bool TryFormatDateTimeL(DateTime value, Span<byte> destination, out int bytesWritten)
- {
- // Writing the check in this fashion elides all bounds checks on 'buffer'
- // for the remainder of the method.
- if ((uint)28 >= (uint)destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
-
- uint dayAbbrev = s_dayAbbreviationsLowercase[(int)value.DayOfWeek];
-
- destination[0] = (byte)dayAbbrev;
- dayAbbrev >>= 8;
- destination[1] = (byte)dayAbbrev;
- dayAbbrev >>= 8;
- destination[2] = (byte)dayAbbrev;
- destination[3] = Utf8Constants.Comma;
- destination[4] = Utf8Constants.Space;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Day, destination, 5);
- destination[7] = Utf8Constants.Space;
-
- uint monthAbbrev = s_monthAbbreviationsLowercase[value.Month - 1];
- destination[8] = (byte)monthAbbrev;
- monthAbbrev >>= 8;
- destination[9] = (byte)monthAbbrev;
- monthAbbrev >>= 8;
- destination[10] = (byte)monthAbbrev;
- destination[11] = Utf8Constants.Space;
-
- FormattingHelpers.WriteFourDecimalDigits((uint)value.Year, destination, 12);
- destination[16] = Utf8Constants.Space;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Hour, destination, 17);
- destination[19] = Utf8Constants.Colon;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Minute, destination, 20);
- destination[22] = Utf8Constants.Colon;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Second, destination, 23);
- destination[25] = Utf8Constants.Space;
-
- destination[26] = GMT1Lowercase;
- destination[27] = GMT2Lowercase;
- destination[28] = GMT3Lowercase;
-
- bytesWritten = 29;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.O.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.O.cs
deleted file mode 100644
index 2bbfcaaee8a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.O.cs
+++ /dev/null
@@ -1,104 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- //
- // Roundtrippable format. One of
- //
- // 012345678901234567890123456789012
- // ---------------------------------
- // 2017-06-12T05:30:45.7680000-07:00
- // 2017-06-12T05:30:45.7680000Z (Z is short for "+00:00" but also distinguishes DateTimeKind.Utc from DateTimeKind.Local)
- // 2017-06-12T05:30:45.7680000 (interpreted as local time wrt to current time zone)
- //
- private static bool TryFormatDateTimeO(DateTime value, TimeSpan offset, Span<byte> destination, out int bytesWritten)
- {
- const int MinimumBytesNeeded = 27;
-
- int bytesRequired = MinimumBytesNeeded;
- DateTimeKind kind = DateTimeKind.Local;
-
- if (offset == Utf8Constants.NullUtcOffset)
- {
- kind = value.Kind;
- if (kind == DateTimeKind.Local)
- {
- offset = TimeZoneInfo.Local.GetUtcOffset(value);
- bytesRequired += 6;
- }
- else if (kind == DateTimeKind.Utc)
- {
- bytesRequired++;
- }
- }
- else
- {
- bytesRequired += 6;
- }
-
- if (destination.Length < bytesRequired)
- {
- bytesWritten = 0;
- return false;
- }
-
- bytesWritten = bytesRequired;
-
- // Hoist most of the bounds checks on buffer.
- { _ = destination[MinimumBytesNeeded - 1]; }
-
- FormattingHelpers.WriteFourDecimalDigits((uint)value.Year, destination, 0);
- destination[4] = Utf8Constants.Minus;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Month, destination, 5);
- destination[7] = Utf8Constants.Minus;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Day, destination, 8);
- destination[10] = TimeMarker;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Hour, destination, 11);
- destination[13] = Utf8Constants.Colon;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Minute, destination, 14);
- destination[16] = Utf8Constants.Colon;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Second, destination, 17);
- destination[19] = Utf8Constants.Period;
-
- FormattingHelpers.WriteDigits((uint)((ulong)value.Ticks % (ulong)TimeSpan.TicksPerSecond), destination.Slice(20, 7));
-
- if (kind == DateTimeKind.Local)
- {
- byte sign;
-
- if (offset < default(TimeSpan) /* a "const" version of TimeSpan.Zero */)
- {
- sign = Utf8Constants.Minus;
- offset = TimeSpan.FromTicks(-offset.Ticks);
- }
- else
- {
- sign = Utf8Constants.Plus;
- }
-
- // Writing the value backward allows the JIT to optimize by
- // performing a single bounds check against buffer.
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)offset.Minutes, destination, 31);
- destination[30] = Utf8Constants.Colon;
- FormattingHelpers.WriteTwoDecimalDigits((uint)offset.Hours, destination, 28);
- destination[27] = sign;
- }
- else if (kind == DateTimeKind.Utc)
- {
- destination[27] = UtcMarker;
- }
-
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.R.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.R.cs
deleted file mode 100644
index dd9ec459b7b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.R.cs
+++ /dev/null
@@ -1,66 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- // Rfc1123
- //
- // 01234567890123456789012345678
- // -----------------------------
- // Tue, 03 Jan 2017 08:08:05 GMT
- //
- private static bool TryFormatDateTimeR(DateTime value, Span<byte> destination, out int bytesWritten)
- {
- // Writing the check in this fashion elides all bounds checks on 'buffer'
- // for the remainder of the method.
- if ((uint)28 >= (uint)destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
-
- uint dayAbbrev = s_dayAbbreviations[(int)value.DayOfWeek];
-
- destination[0] = (byte)dayAbbrev;
- dayAbbrev >>= 8;
- destination[1] = (byte)dayAbbrev;
- dayAbbrev >>= 8;
- destination[2] = (byte)dayAbbrev;
- destination[3] = Utf8Constants.Comma;
- destination[4] = Utf8Constants.Space;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Day, destination, 5);
- destination[7] = Utf8Constants.Space;
-
- uint monthAbbrev = s_monthAbbreviations[value.Month - 1];
- destination[8] = (byte)monthAbbrev;
- monthAbbrev >>= 8;
- destination[9] = (byte)monthAbbrev;
- monthAbbrev >>= 8;
- destination[10] = (byte)monthAbbrev;
- destination[11] = Utf8Constants.Space;
-
- FormattingHelpers.WriteFourDecimalDigits((uint)value.Year, destination, 12);
- destination[16] = Utf8Constants.Space;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Hour, destination, 17);
- destination[19] = Utf8Constants.Colon;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Minute, destination, 20);
- destination[22] = Utf8Constants.Colon;
-
- FormattingHelpers.WriteTwoDecimalDigits((uint)value.Second, destination, 23);
- destination[25] = Utf8Constants.Space;
-
- destination[26] = GMT1;
- destination[27] = GMT2;
- destination[28] = GMT3;
-
- bytesWritten = 29;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.cs
deleted file mode 100644
index 122c490ccaa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.cs
+++ /dev/null
@@ -1,153 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- private const byte TimeMarker = (byte)'T';
- private const byte UtcMarker = (byte)'Z';
-
- private const byte GMT1 = (byte)'G';
- private const byte GMT2 = (byte)'M';
- private const byte GMT3 = (byte)'T';
-
- private const byte GMT1Lowercase = (byte)'g';
- private const byte GMT2Lowercase = (byte)'m';
- private const byte GMT3Lowercase = (byte)'t';
-
- // The three-letter abbreviation is packed into a 24-bit unsigned integer
- // where the least significant byte represents the first letter.
- private static readonly uint[] s_dayAbbreviations = new uint[]
- {
- 'S' + ('u' << 8) + ('n' << 16),
- 'M' + ('o' << 8) + ('n' << 16),
- 'T' + ('u' << 8) + ('e' << 16),
- 'W' + ('e' << 8) + ('d' << 16),
- 'T' + ('h' << 8) + ('u' << 16),
- 'F' + ('r' << 8) + ('i' << 16),
- 'S' + ('a' << 8) + ('t' << 16),
- };
-
- private static readonly uint[] s_dayAbbreviationsLowercase = new uint[]
- {
- 's' + ('u' << 8) + ('n' << 16),
- 'm' + ('o' << 8) + ('n' << 16),
- 't' + ('u' << 8) + ('e' << 16),
- 'w' + ('e' << 8) + ('d' << 16),
- 't' + ('h' << 8) + ('u' << 16),
- 'f' + ('r' << 8) + ('i' << 16),
- 's' + ('a' << 8) + ('t' << 16)
- };
-
- private static readonly uint[] s_monthAbbreviations = new uint[]
- {
- 'J' + ('a' << 8) + ('n' << 16),
- 'F' + ('e' << 8) + ('b' << 16),
- 'M' + ('a' << 8) + ('r' << 16),
- 'A' + ('p' << 8) + ('r' << 16),
- 'M' + ('a' << 8) + ('y' << 16),
- 'J' + ('u' << 8) + ('n' << 16),
- 'J' + ('u' << 8) + ('l' << 16),
- 'A' + ('u' << 8) + ('g' << 16),
- 'S' + ('e' << 8) + ('p' << 16),
- 'O' + ('c' << 8) + ('t' << 16),
- 'N' + ('o' << 8) + ('v' << 16),
- 'D' + ('e' << 8) + ('c' << 16),
- };
-
- private static readonly uint[] s_monthAbbreviationsLowercase = new uint[]
- {
- 'j' + ('a' << 8) + ('n' << 16),
- 'f' + ('e' << 8) + ('b' << 16),
- 'm' + ('a' << 8) + ('r' << 16),
- 'a' + ('p' << 8) + ('r' << 16),
- 'm' + ('a' << 8) + ('y' << 16),
- 'j' + ('u' << 8) + ('n' << 16),
- 'j' + ('u' << 8) + ('l' << 16),
- 'a' + ('u' << 8) + ('g' << 16),
- 's' + ('e' << 8) + ('p' << 16),
- 'o' + ('c' << 8) + ('t' << 16),
- 'n' + ('o' << 8) + ('v' << 16),
- 'd' + ('e' << 8) + ('c' << 16),
- };
-
- /// <summary>
- /// Formats a DateTimeOffset as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <exceptions>
- /// <remarks>
- /// Formats supported:
- /// default 05/25/2017 10:30:15 -08:00
- /// G 05/25/2017 10:30:15
- /// R Tue, 03 Jan 2017 08:08:05 GMT (RFC 1123)
- /// l tue, 03 jan 2017 08:08:05 gmt (Lowercase RFC 1123)
- /// O 2017-06-12T05:30:45.7680000-07:00 (Round-trippable)
- /// </remarks>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryFormat(DateTimeOffset value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- {
- TimeSpan offset = Utf8Constants.NullUtcOffset;
- char symbol = format.Symbol;
- if (format.IsDefault)
- {
- symbol = 'G';
- offset = value.Offset;
- }
-
- return symbol switch
- {
- 'R' => TryFormatDateTimeR(value.UtcDateTime, destination, out bytesWritten),
- 'l' => TryFormatDateTimeL(value.UtcDateTime, destination, out bytesWritten),
- 'O' => TryFormatDateTimeO(value.DateTime, value.Offset, destination, out bytesWritten),
- 'G' => TryFormatDateTimeG(value.DateTime, offset, destination, out bytesWritten),
- _ => FormattingHelpers.TryFormatThrowFormatException(out bytesWritten),
- };
- }
-
- /// <summary>
- /// Formats a DateTime as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G (default) 05/25/2017 10:30:15
- /// R Tue, 03 Jan 2017 08:08:05 GMT (RFC 1123)
- /// l tue, 03 jan 2017 08:08:05 gmt (Lowercase RFC 1123)
- /// O 2017-06-12T05:30:45.7680000-07:00 (Round-trippable)
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryFormat(DateTime value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- {
- char symbol = FormattingHelpers.GetSymbolOrDefault(format, 'G');
-
- return symbol switch
- {
- 'R' => TryFormatDateTimeR(value, destination, out bytesWritten),
- 'l' => TryFormatDateTimeL(value, destination, out bytesWritten),
- 'O' => TryFormatDateTimeO(value, Utf8Constants.NullUtcOffset, destination, out bytesWritten),
- 'G' => TryFormatDateTimeG(value, Utf8Constants.NullUtcOffset, destination, out bytesWritten),
- _ => FormattingHelpers.TryFormatThrowFormatException(out bytesWritten),
- };
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.E.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.E.cs
deleted file mode 100644
index 89b54f2fd59..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.E.cs
+++ /dev/null
@@ -1,104 +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 System.Diagnostics;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- private static bool TryFormatDecimalE(ref Number.NumberBuffer number, Span<byte> destination, out int bytesWritten, byte precision, byte exponentSymbol)
- {
- const int NumExponentDigits = 3;
-
- int scale = number.Scale;
- ReadOnlySpan<byte> digits = number.Digits;
-
- int numBytesNeeded =
- ((number.IsNegative) ? 1 : 0) // minus sign
- + 1 // digits before the decimal point (exactly 1)
- + ((precision == 0) ? 0 : (precision + 1)) // period and the digits after the decimal point
- + 2 // 'E' or 'e' followed by '+' or '-'
- + NumExponentDigits; // exponent digits
-
- if (destination.Length < numBytesNeeded)
- {
- bytesWritten = 0;
- return false;
- }
-
- int dstIndex = 0;
- int srcIndex = 0;
- if (number.IsNegative)
- {
- destination[dstIndex++] = Utf8Constants.Minus;
- }
-
- //
- // Emit exactly one digit before the decimal point.
- //
- int exponent;
- byte firstDigit = digits[srcIndex];
- if (firstDigit == 0)
- {
- destination[dstIndex++] = (byte)'0'; // Special case: number before the decimal point is exactly 0: Number does not store the zero in this case.
- exponent = 0;
- }
- else
- {
- destination[dstIndex++] = firstDigit;
- srcIndex++;
- exponent = scale - 1;
- }
-
- if (precision > 0)
- {
- destination[dstIndex++] = Utf8Constants.Period;
-
- //
- // Emit digits after the decimal point.
- //
- int numDigitsEmitted = 0;
- while (numDigitsEmitted < precision)
- {
- byte digit = digits[srcIndex];
- if (digit == 0)
- {
- while (numDigitsEmitted++ < precision)
- {
- destination[dstIndex++] = (byte)'0';
- }
- break;
- }
- destination[dstIndex++] = digit;
- srcIndex++;
- numDigitsEmitted++;
- }
- }
-
- // Emit the exponent symbol
- destination[dstIndex++] = exponentSymbol;
- if (exponent >= 0)
- {
- destination[dstIndex++] = Utf8Constants.Plus;
- }
- else
- {
- destination[dstIndex++] = Utf8Constants.Minus;
- exponent = -exponent;
- }
-
- Debug.Assert(exponent < Number.DecimalPrecision, "If you're trying to reuse this routine for double/float, you'll need to review the code carefully for Decimal-specific assumptions.");
-
- // Emit exactly three digits for the exponent.
- destination[dstIndex++] = (byte)'0'; // The exponent for Decimal can never exceed 28 (let alone 99)
- destination[dstIndex++] = (byte)((exponent / 10) + '0');
- destination[dstIndex++] = (byte)((exponent % 10) + '0');
-
- Debug.Assert(dstIndex == numBytesNeeded);
- bytesWritten = numBytesNeeded;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.F.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.F.cs
deleted file mode 100644
index 51bc20b8d2d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.F.cs
+++ /dev/null
@@ -1,101 +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 System.Diagnostics;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- private static bool TryFormatDecimalF(ref Number.NumberBuffer number, Span<byte> destination, out int bytesWritten, byte precision)
- {
- int scale = number.Scale;
- ReadOnlySpan<byte> digits = number.Digits;
-
- int numBytesNeeded =
- ((number.IsNegative) ? 1 : 0) // minus sign
- + ((scale <= 0) ? 1 : scale) // digits before the decimal point (minimum 1)
- + ((precision == 0) ? 0 : (precision + 1)); // if specified precision != 0, the decimal point and the digits after the decimal point (padded with zeroes if needed)
-
- if (destination.Length < numBytesNeeded)
- {
- bytesWritten = 0;
- return false;
- }
-
- int srcIndex = 0;
- int dstIndex = 0;
- if (number.IsNegative)
- {
- destination[dstIndex++] = Utf8Constants.Minus;
- }
-
- //
- // Emit digits before the decimal point.
- //
- if (scale <= 0)
- {
- destination[dstIndex++] = (byte)'0'; // The integer portion is 0 and not stored. The formatter, however, needs to emit it.
- }
- else
- {
- while (srcIndex < scale)
- {
- byte digit = digits[srcIndex];
- if (digit == 0)
- {
- int numTrailingZeroes = scale - srcIndex;
- for (int i = 0; i < numTrailingZeroes; i++)
- {
- destination[dstIndex++] = (byte)'0';
- }
- break;
- }
-
- destination[dstIndex++] = digit;
- srcIndex++;
- }
- }
-
- if (precision > 0)
- {
- destination[dstIndex++] = Utf8Constants.Period;
-
- //
- // Emit digits after the decimal point.
- //
- int numDigitsEmitted = 0;
- if (scale < 0)
- {
- int numLeadingZeroesToEmit = Math.Min((int)precision, -scale);
- for (int i = 0; i < numLeadingZeroesToEmit; i++)
- {
- destination[dstIndex++] = (byte)'0';
- }
- numDigitsEmitted += numLeadingZeroesToEmit;
- }
-
- while (numDigitsEmitted < precision)
- {
- byte digit = digits[srcIndex];
- if (digit == 0)
- {
- while (numDigitsEmitted++ < precision)
- {
- destination[dstIndex++] = (byte)'0';
- }
- break;
- }
- destination[dstIndex++] = digit;
- srcIndex++;
- numDigitsEmitted++;
- }
- }
-
- Debug.Assert(dstIndex == numBytesNeeded);
- bytesWritten = numBytesNeeded;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.G.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.G.cs
deleted file mode 100644
index b867eaec1a1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.G.cs
+++ /dev/null
@@ -1,107 +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 System.Diagnostics;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- private static bool TryFormatDecimalG(ref Number.NumberBuffer number, Span<byte> destination, out int bytesWritten)
- {
- int scale = number.Scale;
- ReadOnlySpan<byte> digits = number.Digits;
- int numDigits = number.DigitsCount;
-
- bool isFraction = scale < numDigits;
- int numBytesNeeded;
- if (isFraction)
- {
- numBytesNeeded = numDigits + 1; // A fraction. Must include one for the decimal point.
- if (scale <= 0)
- {
- numBytesNeeded += 1 + (-scale); // A fraction of the form 0.ddd. Need to emit the non-stored 0 before the decimal point plus (-scale) leading 0's after the decimal point.
- }
- }
- else
- {
- numBytesNeeded = ((scale <= 0) ? 1 : scale); // An integral. Just emit the digits before the decimal point (minimum 1) and no decimal point.
- }
-
- if (number.IsNegative)
- {
- numBytesNeeded++; // And the minus sign.
- }
-
- if (destination.Length < numBytesNeeded)
- {
- bytesWritten = 0;
- return false;
- }
-
- int srcIndex = 0;
- int dstIndex = 0;
-
- if (number.IsNegative)
- {
- destination[dstIndex++] = Utf8Constants.Minus;
- }
-
- //
- // Emit digits before the decimal point.
- //
- if (scale <= 0)
- {
- destination[dstIndex++] = (byte)'0'; // The integer portion is 0 and not stored. The formatter, however, needs to emit it.
- }
- else
- {
- while (srcIndex < scale)
- {
- byte digit = digits[srcIndex];
- if (digit == 0)
- {
- int numTrailingZeroes = scale - srcIndex;
- for (int i = 0; i < numTrailingZeroes; i++)
- {
- destination[dstIndex++] = (byte)'0';
- }
- break;
- }
-
- destination[dstIndex++] = digit;
- srcIndex++;
- }
- }
-
- if (isFraction)
- {
- destination[dstIndex++] = Utf8Constants.Period;
-
- //
- // Emit digits after the decimal point.
- //
- if (scale < 0)
- {
- int numLeadingZeroesToEmit = -scale;
- for (int i = 0; i < numLeadingZeroesToEmit; i++)
- {
- destination[dstIndex++] = (byte)'0';
- }
- }
-
- byte digit;
- while ((digit = digits[srcIndex++]) != 0)
- {
- destination[dstIndex++] = digit;
- }
- }
-
- Debug.Assert(dstIndex == numBytesNeeded);
-
- bytesWritten = numBytesNeeded;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.cs
deleted file mode 100644
index 164146a50b8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Decimal.cs
+++ /dev/null
@@ -1,119 +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 System.Diagnostics;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- /// <summary>
- /// Formats a Decimal as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// F/f 12.45 Fixed point
- /// E/e 1.245000e1 Exponential
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static unsafe bool TryFormat(decimal value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- {
- if (format.IsDefault)
- {
- format = 'G';
- }
-
- switch (format.Symbol)
- {
- case 'g':
- case 'G':
- {
- if (format.Precision != StandardFormat.NoPrecision)
- throw new NotSupportedException(SR.Argument_GWithPrecisionNotSupported);
-
- byte* pDigits = stackalloc byte[Number.DecimalNumberBufferLength];
- Number.NumberBuffer number = new Number.NumberBuffer(Number.NumberBufferKind.Decimal, pDigits, Number.DecimalNumberBufferLength);
-
- Number.DecimalToNumber(ref value, ref number);
- if (number.Digits[0] == 0)
- {
- number.IsNegative = false; // For Decimals, -0 must print as normal 0.
- }
- bool success = TryFormatDecimalG(ref number, destination, out bytesWritten);
-#if DEBUG
- // This DEBUG segment exists to close a code coverage hole inside TryFormatDecimalG(). Because we don't call RoundNumber() on this path, we have no way to feed
- // TryFormatDecimalG() a number where trailing zeros before the decimal point have been cropped. So if the chance comes up, we'll crop the zeroes
- // ourselves and make a second call to ensure we get the same outcome.
- if (success)
- {
- Span<byte> digits = number.Digits;
- int numDigits = number.DigitsCount;
- if (numDigits != 0 && number.Scale == numDigits && digits[numDigits - 1] == '0')
- {
- while (numDigits != 0 && digits[numDigits - 1] == '0')
- {
- digits[numDigits - 1] = 0;
- numDigits--;
- }
-
- number.DigitsCount = numDigits;
- number.CheckConsistency();
-
- byte[] buffer2 = new byte[destination.Length];
- bool success2 = TryFormatDecimalG(ref number, buffer2, out int bytesWritten2);
- Debug.Assert(success2);
- Debug.Assert(bytesWritten2 == bytesWritten);
- for (int i = 0; i < bytesWritten; i++)
- {
- Debug.Assert(destination[i] == buffer2[i]);
- }
- }
- }
-#endif // DEBUG
- return success;
- }
-
- case 'f':
- case 'F':
- {
- byte* pDigits = stackalloc byte[Number.DecimalNumberBufferLength];
- Number.NumberBuffer number = new Number.NumberBuffer(Number.NumberBufferKind.Decimal, pDigits, Number.DecimalNumberBufferLength);
-
- Number.DecimalToNumber(ref value, ref number);
- byte precision = (format.Precision == StandardFormat.NoPrecision) ? (byte)2 : format.Precision;
- Number.RoundNumber(ref number, number.Scale + precision, isCorrectlyRounded: false);
- Debug.Assert((number.Digits[0] != 0) || !number.IsNegative); // For Decimals, -0 must print as normal 0. As it happens, Number.RoundNumber already ensures this invariant.
- return TryFormatDecimalF(ref number, destination, out bytesWritten, precision);
- }
-
- case 'e':
- case 'E':
- {
- byte* pDigits = stackalloc byte[Number.DecimalNumberBufferLength];
- Number.NumberBuffer number = new Number.NumberBuffer(Number.NumberBufferKind.Decimal, pDigits, Number.DecimalNumberBufferLength);
-
- Number.DecimalToNumber(ref value, ref number);
- byte precision = (format.Precision == StandardFormat.NoPrecision) ? (byte)6 : format.Precision;
- Number.RoundNumber(ref number, precision + 1, isCorrectlyRounded: false);
- Debug.Assert((number.Digits[0] != 0) || !number.IsNegative); // For Decimals, -0 must print as normal 0. As it happens, Number.RoundNumber already ensures this invariant.
- return TryFormatDecimalE(ref number, destination, out bytesWritten, precision, exponentSymbol: (byte)format.Symbol);
- }
-
- default:
- return FormattingHelpers.TryFormatThrowFormatException(out bytesWritten);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Float.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Float.cs
deleted file mode 100644
index 41ce6833da6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Float.cs
+++ /dev/null
@@ -1,122 +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 System.Globalization;
-using System.Text;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- /// <summary>
- /// Formats a Double as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// F/f 12.45 Fixed point
- /// E/e 1.245000e1 Exponential
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryFormat(double value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- {
- return TryFormatFloatingPoint<double>(value, destination, out bytesWritten, format);
- }
-
- /// <summary>
- /// Formats a Single as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// F/f 12.45 Fixed point
- /// E/e 1.245000e1 Exponential
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryFormat(float value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- {
- return TryFormatFloatingPoint<float>(value, destination, out bytesWritten, format);
- }
-
- private static bool TryFormatFloatingPoint<T>(T value, Span<byte> destination, out int bytesWritten, StandardFormat format) where T : IFormattable, ISpanFormattable
- {
- Span<char> formatText = stackalloc char[0];
-
- if (!format.IsDefault)
- {
- formatText = stackalloc char[StandardFormat.FormatStringLength];
- int formatTextLength = format.Format(formatText);
- formatText = formatText.Slice(0, formatTextLength);
- }
-
- // We first try to format into a stack-allocated buffer, and if it succeeds, we can avoid
- // all allocation. If that fails, we fall back to allocating strings. If it proves impactful,
- // that allocation (as well as roundtripping from byte to char and back to byte) could be avoided by
- // calling into a refactored Number.FormatSingle/Double directly.
-
- const int StackBufferLength = 128; // large enough to handle the majority cases
- Span<char> stackBuffer = stackalloc char[StackBufferLength];
- ReadOnlySpan<char> utf16Text = stackalloc char[0];
-
- // Try to format into the stack buffer. If we're successful, we can avoid all allocations.
- if (value.TryFormat(stackBuffer, out int formattedLength, formatText, CultureInfo.InvariantCulture))
- {
- utf16Text = stackBuffer.Slice(0, formattedLength);
- }
- else
- {
- // The stack buffer wasn't large enough. If the destination buffer isn't at least as
- // big as the stack buffer, we know the whole operation will eventually fail, so we
- // can just fail now.
- if (destination.Length <= StackBufferLength)
- {
- bytesWritten = 0;
- return false;
- }
-
- // Fall back to using a string format and allocating a string for the resulting formatted value.
- utf16Text = value.ToString(new string(formatText), CultureInfo.InvariantCulture);
- }
-
- // Copy the value to the destination, if it's large enough.
-
- if (utf16Text.Length > destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
-
- try
- {
- bytesWritten = Encoding.UTF8.GetBytes(utf16Text, destination);
- return true;
- }
- catch
- {
- bytesWritten = 0;
- return false;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs
deleted file mode 100644
index 63a9fa248ab..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs
+++ /dev/null
@@ -1,219 +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 System.Runtime.InteropServices;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- #region Constants
-
- private const byte OpenBrace = (byte)'{';
- private const byte CloseBrace = (byte)'}';
-
- private const byte OpenParen = (byte)'(';
- private const byte CloseParen = (byte)')';
-
- private const byte Dash = (byte)'-';
-
- #endregion Constants
-
- /// <summary>
- /// Formats a Guid as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// D (default) nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
- /// B {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}
- /// P (nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn)
- /// N nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryFormat(Guid value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- {
- const int INSERT_DASHES = unchecked((int)0x80000000);
- const int NO_DASHES = 0;
- const int INSERT_CURLY_BRACES = (CloseBrace << 16) | (OpenBrace << 8);
- const int INSERT_ROUND_BRACES = (CloseParen << 16) | (OpenParen << 8);
- const int NO_BRACES = 0;
- const int LEN_GUID_BASE = 32;
- const int LEN_ADD_DASHES = 4;
- const int LEN_ADD_BRACES = 2;
-
- // This is a 32-bit value whose contents (where 0 is the low byte) are:
- // 0th byte: minimum required length of the output buffer,
- // 1st byte: the ASCII byte to insert for the opening brace position (or 0 if no braces),
- // 2nd byte: the ASCII byte to insert for the closing brace position (or 0 if no braces),
- // 3rd byte: high bit set if dashes are to be inserted.
- //
- // The reason for keeping a single flag instead of separate vars is that we can avoid register spillage
- // as we build up the output value.
- int flags;
-
- switch (FormattingHelpers.GetSymbolOrDefault(format, 'D'))
- {
- case 'D': // nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
- flags = INSERT_DASHES + NO_BRACES + LEN_GUID_BASE + LEN_ADD_DASHES;
- break;
-
- case 'B': // {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}
- flags = INSERT_DASHES + INSERT_CURLY_BRACES + LEN_GUID_BASE + LEN_ADD_DASHES + LEN_ADD_BRACES;
- break;
-
- case 'P': // (nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn)
- flags = INSERT_DASHES + INSERT_ROUND_BRACES + LEN_GUID_BASE + LEN_ADD_DASHES + LEN_ADD_BRACES;
- break;
-
- case 'N': // nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
- flags = NO_BRACES + NO_DASHES + LEN_GUID_BASE;
- break;
-
- default:
- return FormattingHelpers.TryFormatThrowFormatException(out bytesWritten);
- }
-
- // At this point, the low byte of flags contains the minimum required length
-
- if ((byte)flags > destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
-
- bytesWritten = (byte)flags;
- flags >>= 8;
-
- // At this point, the low byte of flags contains the opening brace char (if any)
-
- if ((byte)flags != 0)
- {
- destination[0] = (byte)flags;
- destination = destination.Slice(1);
- }
- flags >>= 8;
-
- // At this point, the low byte of flags contains the closing brace char (if any)
- // And since we're performing arithmetic shifting the high bit of flags is set (flags is negative) if dashes are required
-
- DecomposedGuid guidAsBytes = default;
- guidAsBytes.Guid = value;
-
- // When a GUID is blitted, the first three components are little-endian, and the last component is big-endian.
-
- // The line below forces the JIT to hoist the bounds check for the following segment.
- // The JIT will optimize away the read, but it cannot optimize away the bounds check
- // because it may have an observable side effect (throwing).
- // We use 8 instead of 7 so that we also capture the dash if we're asked to insert one.
-
- { _ = destination[8]; }
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte03, destination, 0, FormattingHelpers.HexCasing.Lowercase);
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte02, destination, 2, FormattingHelpers.HexCasing.Lowercase);
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte01, destination, 4, FormattingHelpers.HexCasing.Lowercase);
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte00, destination, 6, FormattingHelpers.HexCasing.Lowercase);
-
- if (flags < 0 /* use dash? */)
- {
- destination[8] = Dash;
- destination = destination.Slice(9);
- }
- else
- {
- destination = destination.Slice(8);
- }
-
- { _ = destination[4]; }
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte05, destination, 0, FormattingHelpers.HexCasing.Lowercase);
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte04, destination, 2, FormattingHelpers.HexCasing.Lowercase);
-
- if (flags < 0 /* use dash? */)
- {
- destination[4] = Dash;
- destination = destination.Slice(5);
- }
- else
- {
- destination = destination.Slice(4);
- }
-
- { _ = destination[4]; }
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte07, destination, 0, FormattingHelpers.HexCasing.Lowercase);
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte06, destination, 2, FormattingHelpers.HexCasing.Lowercase);
-
- if (flags < 0 /* use dash? */)
- {
- destination[4] = Dash;
- destination = destination.Slice(5);
- }
- else
- {
- destination = destination.Slice(4);
- }
-
- { _ = destination[4]; }
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte08, destination, 0, FormattingHelpers.HexCasing.Lowercase);
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte09, destination, 2, FormattingHelpers.HexCasing.Lowercase);
-
- if (flags < 0 /* use dash? */)
- {
- destination[4] = Dash;
- destination = destination.Slice(5);
- }
- else
- {
- destination = destination.Slice(4);
- }
-
- { _ = destination[11]; } // can't hoist bounds check on the final brace (if exists)
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte10, destination, 0, FormattingHelpers.HexCasing.Lowercase);
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte11, destination, 2, FormattingHelpers.HexCasing.Lowercase);
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte12, destination, 4, FormattingHelpers.HexCasing.Lowercase);
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte13, destination, 6, FormattingHelpers.HexCasing.Lowercase);
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte14, destination, 8, FormattingHelpers.HexCasing.Lowercase);
- FormattingHelpers.WriteHexByte(guidAsBytes.Byte15, destination, 10, FormattingHelpers.HexCasing.Lowercase);
-
- if ((byte)flags != 0)
- {
- destination[12] = (byte)flags;
- }
-
- return true;
- }
-
- /// <summary>
- /// Used to provide access to the individual bytes of a GUID.
- /// </summary>
- [StructLayout(LayoutKind.Explicit)]
- private struct DecomposedGuid
- {
- [FieldOffset(00)] public Guid Guid;
- [FieldOffset(00)] public byte Byte00;
- [FieldOffset(01)] public byte Byte01;
- [FieldOffset(02)] public byte Byte02;
- [FieldOffset(03)] public byte Byte03;
- [FieldOffset(04)] public byte Byte04;
- [FieldOffset(05)] public byte Byte05;
- [FieldOffset(06)] public byte Byte06;
- [FieldOffset(07)] public byte Byte07;
- [FieldOffset(08)] public byte Byte08;
- [FieldOffset(09)] public byte Byte09;
- [FieldOffset(10)] public byte Byte10;
- [FieldOffset(11)] public byte Byte11;
- [FieldOffset(12)] public byte Byte12;
- [FieldOffset(13)] public byte Byte13;
- [FieldOffset(14)] public byte Byte14;
- [FieldOffset(15)] public byte Byte15;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs
deleted file mode 100644
index 7532f0cf15a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs
+++ /dev/null
@@ -1,27 +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 System.Runtime.CompilerServices;
-
-namespace System.Buffers.Text
-{
- /// <summary>
- /// Methods to format common data types as Utf8 strings.
- /// </summary>
- public static partial class Utf8Formatter
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryFormatInt64D(long value, byte precision, Span<byte> destination, out int bytesWritten)
- {
- bool insertNegationSign = false;
- if (value < 0)
- {
- insertNegationSign = true;
- value = -value;
- }
-
- return TryFormatUInt64D((ulong)value, precision, destination, insertNegationSign, out bytesWritten);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.Default.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.Default.cs
deleted file mode 100644
index 046f5baf664..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.Default.cs
+++ /dev/null
@@ -1,148 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Buffers.Text
-{
- /// <summary>
- /// Methods to format common data types as Utf8 strings.
- /// </summary>
- public static partial class Utf8Formatter
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryFormatInt64Default(long value, Span<byte> destination, out int bytesWritten)
- {
- if ((ulong)value < 10)
- {
- return TryFormatUInt32SingleDigit((uint)value, destination, out bytesWritten);
- }
-
- if (IntPtr.Size == 8) // x64
- {
- return TryFormatInt64MultipleDigits(value, destination, out bytesWritten);
- }
- else // x86
- {
- if (value <= int.MaxValue && value >= int.MinValue)
- {
- return TryFormatInt32MultipleDigits((int)value, destination, out bytesWritten);
- }
- else
- {
- if (value <= (long)Utf8Constants.BillionMaxUIntValue && value >= -(long)Utf8Constants.BillionMaxUIntValue)
- {
- return value < 0 ?
- TryFormatInt64MoreThanNegativeBillionMaxUInt(-value, destination, out bytesWritten) :
- TryFormatUInt64LessThanBillionMaxUInt((ulong)value, destination, out bytesWritten);
- }
- else
- {
- return value < 0 ?
- TryFormatInt64LessThanNegativeBillionMaxUInt(-value, destination, out bytesWritten) :
- TryFormatUInt64MoreThanBillionMaxUInt((ulong)value, destination, out bytesWritten);
- }
- }
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryFormatInt32MultipleDigits(int value, Span<byte> destination, out int bytesWritten)
- {
- if (value < 0)
- {
- value = -value;
- int digitCount = FormattingHelpers.CountDigits((uint)value);
- // WriteDigits does not do bounds checks
- if (digitCount >= destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
- destination[0] = Utf8Constants.Minus;
- bytesWritten = digitCount + 1;
- FormattingHelpers.WriteDigits((uint)value, destination.Slice(1, digitCount));
- return true;
- }
- else
- {
- return TryFormatUInt32MultipleDigits((uint)value, destination, out bytesWritten);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryFormatInt64MultipleDigits(long value, Span<byte> destination, out int bytesWritten)
- {
- if (value < 0)
- {
- value = -value;
- int digitCount = FormattingHelpers.CountDigits((ulong)value);
- // WriteDigits does not do bounds checks
- if (digitCount >= destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
- destination[0] = Utf8Constants.Minus;
- bytesWritten = digitCount + 1;
- FormattingHelpers.WriteDigits((ulong)value, destination.Slice(1, digitCount));
- return true;
- }
- else
- {
- return TryFormatUInt64MultipleDigits((ulong)value, destination, out bytesWritten);
- }
- }
-
- // Split long into two parts that can each fit in a uint - {1-10 digits}{9 digits}
- private static bool TryFormatInt64MoreThanNegativeBillionMaxUInt(long value, Span<byte> destination, out int bytesWritten)
- {
- uint overNineDigits = (uint)(value / Utf8Constants.Billion);
- uint lastNineDigits = (uint)(value - (overNineDigits * Utf8Constants.Billion));
-
- int digitCountOverNineDigits = FormattingHelpers.CountDigits(overNineDigits);
- Debug.Assert(digitCountOverNineDigits >= 1 && digitCountOverNineDigits <= 10);
- int digitCount = digitCountOverNineDigits + 9;
- // WriteDigits does not do bounds checks
- if (digitCount >= destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
- destination[0] = Utf8Constants.Minus;
- bytesWritten = digitCount + 1;
- FormattingHelpers.WriteDigits(overNineDigits, destination.Slice(1, digitCountOverNineDigits));
- FormattingHelpers.WriteDigits(lastNineDigits, destination.Slice(digitCountOverNineDigits + 1, 9));
- return true;
- }
-
- // Split long into three parts that can each fit in a uint - {1 digit}{9 digits}{9 digits}
- private static bool TryFormatInt64LessThanNegativeBillionMaxUInt(long value, Span<byte> destination, out int bytesWritten)
- {
- // value can still be negative if value == long.MinValue
- // Therefore, cast to ulong, since (ulong)value actually equals abs(long.MinValue)
- ulong overNineDigits = (ulong)value / Utf8Constants.Billion;
- uint lastNineDigits = (uint)((ulong)value - (overNineDigits * Utf8Constants.Billion));
- uint overEighteenDigits = (uint)(overNineDigits / Utf8Constants.Billion);
- uint middleNineDigits = (uint)(overNineDigits - (overEighteenDigits * Utf8Constants.Billion));
-
- int digitCountOverEighteenDigits = FormattingHelpers.CountDigits(overEighteenDigits);
- Debug.Assert(digitCountOverEighteenDigits == 1);
- int digitCount = digitCountOverEighteenDigits + 18;
- // WriteDigits does not do bounds checks
- if (digitCount >= destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
- destination[0] = Utf8Constants.Minus;
- bytesWritten = digitCount + 1;
- FormattingHelpers.WriteDigits(overEighteenDigits, destination.Slice(1, digitCountOverEighteenDigits));
- FormattingHelpers.WriteDigits(middleNineDigits, destination.Slice(digitCountOverEighteenDigits + 1, 9));
- FormattingHelpers.WriteDigits(lastNineDigits, destination.Slice(digitCountOverEighteenDigits + 1 + 9, 9));
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.N.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.N.cs
deleted file mode 100644
index 1c01b8d60d4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.N.cs
+++ /dev/null
@@ -1,27 +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 System.Runtime.CompilerServices;
-
-namespace System.Buffers.Text
-{
- /// <summary>
- /// Methods to format common data types as Utf8 strings.
- /// </summary>
- public static partial class Utf8Formatter
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryFormatInt64N(long value, byte precision, Span<byte> destination, out int bytesWritten)
- {
- bool insertNegationSign = false;
- if (value < 0)
- {
- insertNegationSign = true;
- value = -value;
- }
-
- return TryFormatUInt64N((ulong)value, precision, destination, insertNegationSign, out bytesWritten);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.cs
deleted file mode 100644
index fcd20b312d7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.cs
+++ /dev/null
@@ -1,52 +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 System.Runtime.CompilerServices;
-
-namespace System.Buffers.Text
-{
- /// <summary>
- /// Methods to format common data types as Utf8 strings.
- /// </summary>
- public static partial class Utf8Formatter
- {
- //
- // Common worker for all signed integer TryFormat overloads
- //
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryFormatInt64(long value, ulong mask, Span<byte> destination, out int bytesWritten, StandardFormat format)
- {
- if (format.IsDefault)
- {
- return TryFormatInt64Default(value, destination, out bytesWritten);
- }
-
- switch (format.Symbol)
- {
- case 'G':
- case 'g':
- if (format.HasPrecision)
- throw new NotSupportedException(SR.Argument_GWithPrecisionNotSupported); // With a precision, 'G' can produce exponential format, even for integers.
- return TryFormatInt64D(value, format.Precision, destination, out bytesWritten);
-
- case 'd':
- case 'D':
- return TryFormatInt64D(value, format.Precision, destination, out bytesWritten);
-
- case 'n':
- case 'N':
- return TryFormatInt64N(value, format.Precision, destination, out bytesWritten);
-
- case 'x':
- return TryFormatUInt64X((ulong)value & mask, format.Precision, true, destination, out bytesWritten);
-
- case 'X':
- return TryFormatUInt64X((ulong)value & mask, format.Precision, false, destination, out bytesWritten);
-
- default:
- return FormattingHelpers.TryFormatThrowFormatException(out bytesWritten);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs
deleted file mode 100644
index 9cb8d64bc0c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs
+++ /dev/null
@@ -1,54 +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.
-
-namespace System.Buffers.Text
-{
- /// <summary>
- /// Methods to format common data types as Utf8 strings.
- /// </summary>
- public static partial class Utf8Formatter
- {
- private static bool TryFormatUInt64D(ulong value, byte precision, Span<byte> destination, bool insertNegationSign, out int bytesWritten)
- {
- // Calculate the actual digit count and the number of padding zeroes requested.
- // From all of this we can get the required buffer length.
-
- int digitCount = FormattingHelpers.CountDigits(value);
- int leadingZeroCount = ((precision == StandardFormat.NoPrecision) ? 0 : (int)precision) - digitCount;
- if (leadingZeroCount < 0)
- {
- leadingZeroCount = 0;
- }
-
- int requiredBufferLength = digitCount + leadingZeroCount;
-
- if (insertNegationSign)
- {
- requiredBufferLength++;
- }
-
- if (requiredBufferLength > destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
-
- bytesWritten = requiredBufferLength;
-
- if (insertNegationSign)
- {
- destination[0] = Utf8Constants.Minus;
- destination = destination.Slice(1);
- }
-
- if (leadingZeroCount > 0)
- {
- FormattingHelpers.FillWithAsciiZeros(destination.Slice(0, leadingZeroCount));
- }
- FormattingHelpers.WriteDigits(value, destination.Slice(leadingZeroCount, digitCount));
-
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.Default.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.Default.cs
deleted file mode 100644
index d83591ed980..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.Default.cs
+++ /dev/null
@@ -1,135 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Buffers.Text
-{
- /// <summary>
- /// Methods to format common data types as Utf8 strings.
- /// </summary>
- public static partial class Utf8Formatter
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryFormatUInt64Default(ulong value, Span<byte> destination, out int bytesWritten)
- {
- if (value < 10)
- {
- return TryFormatUInt32SingleDigit((uint)value, destination, out bytesWritten);
- }
-
- if (IntPtr.Size == 8) // x64
- {
- return TryFormatUInt64MultipleDigits(value, destination, out bytesWritten);
- }
- else // x86
- {
- if (value <= uint.MaxValue)
- {
- return TryFormatUInt32MultipleDigits((uint)value, destination, out bytesWritten);
- }
- else
- {
- if (value <= Utf8Constants.BillionMaxUIntValue)
- {
- return TryFormatUInt64LessThanBillionMaxUInt(value, destination, out bytesWritten);
- }
- else
- {
- return TryFormatUInt64MoreThanBillionMaxUInt(value, destination, out bytesWritten);
- }
- }
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryFormatUInt32SingleDigit(uint value, Span<byte> destination, out int bytesWritten)
- {
- if (destination.Length == 0)
- {
- bytesWritten = 0;
- return false;
- }
- destination[0] = (byte)('0' + value);
- bytesWritten = 1;
- return true;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryFormatUInt32MultipleDigits(uint value, Span<byte> destination, out int bytesWritten)
- {
- int digitCount = FormattingHelpers.CountDigits(value);
- // WriteDigits does not do bounds checks
- if (digitCount > destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
- bytesWritten = digitCount;
- FormattingHelpers.WriteDigits(value, destination.Slice(0, digitCount));
- return true;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryFormatUInt64MultipleDigits(ulong value, Span<byte> destination, out int bytesWritten)
- {
- int digitCount = FormattingHelpers.CountDigits(value);
- // WriteDigits does not do bounds checks
- if (digitCount > destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
- bytesWritten = digitCount;
- FormattingHelpers.WriteDigits(value, destination.Slice(0, digitCount));
- return true;
- }
-
- // Split ulong into two parts that can each fit in a uint - {1-10 digits}{9 digits}
- private static bool TryFormatUInt64LessThanBillionMaxUInt(ulong value, Span<byte> destination, out int bytesWritten)
- {
- uint overNineDigits = (uint)(value / Utf8Constants.Billion);
- uint lastNineDigits = (uint)(value - (overNineDigits * Utf8Constants.Billion));
-
- int digitCountOverNineDigits = FormattingHelpers.CountDigits(overNineDigits);
- Debug.Assert(digitCountOverNineDigits >= 1 && digitCountOverNineDigits <= 10);
- int digitCount = digitCountOverNineDigits + 9;
- // WriteDigits does not do bounds checks
- if (digitCount > destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
- bytesWritten = digitCount;
- FormattingHelpers.WriteDigits(overNineDigits, destination.Slice(0, digitCountOverNineDigits));
- FormattingHelpers.WriteDigits(lastNineDigits, destination.Slice(digitCountOverNineDigits, 9));
- return true;
- }
-
- // Split ulong into three parts that can each fit in a uint - {1-2 digits}{9 digits}{9 digits}
- private static bool TryFormatUInt64MoreThanBillionMaxUInt(ulong value, Span<byte> destination, out int bytesWritten)
- {
- ulong overNineDigits = value / Utf8Constants.Billion;
- uint lastNineDigits = (uint)(value - (overNineDigits * Utf8Constants.Billion));
- uint overEighteenDigits = (uint)(overNineDigits / Utf8Constants.Billion);
- uint middleNineDigits = (uint)(overNineDigits - (overEighteenDigits * Utf8Constants.Billion));
-
- int digitCountOverEighteenDigits = FormattingHelpers.CountDigits(overEighteenDigits);
- Debug.Assert(digitCountOverEighteenDigits >= 1 && digitCountOverEighteenDigits <= 2);
- int digitCount = digitCountOverEighteenDigits + 18;
- // WriteDigits does not do bounds checks
- if (digitCount > destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
- bytesWritten = digitCount;
- FormattingHelpers.WriteDigits(overEighteenDigits, destination.Slice(0, digitCountOverEighteenDigits));
- FormattingHelpers.WriteDigits(middleNineDigits, destination.Slice(digitCountOverEighteenDigits, 9));
- FormattingHelpers.WriteDigits(lastNineDigits, destination.Slice(digitCountOverEighteenDigits + 9, 9));
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs
deleted file mode 100644
index ce21c0d3ddd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs
+++ /dev/null
@@ -1,58 +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.
-
-namespace System.Buffers.Text
-{
- /// <summary>
- /// Methods to format common data types as Utf8 strings.
- /// </summary>
- public static partial class Utf8Formatter
- {
- private static bool TryFormatUInt64N(ulong value, byte precision, Span<byte> destination, bool insertNegationSign, out int bytesWritten)
- {
- // Calculate the actual digit count, number of group separators required, and the
- // number of trailing zeros requested. From all of this we can get the required
- // buffer length.
-
- int digitCount = FormattingHelpers.CountDigits(value);
- int commaCount = (digitCount - 1) / 3;
- int trailingZeroCount = (precision == StandardFormat.NoPrecision) ? 2 /* default for 'N' */ : precision;
-
- int requiredBufferLength = digitCount + commaCount;
- if (trailingZeroCount > 0)
- {
- requiredBufferLength += trailingZeroCount + 1;
- }
-
- if (insertNegationSign)
- {
- requiredBufferLength++;
- }
-
- if (requiredBufferLength > destination.Length)
- {
- bytesWritten = 0;
- return false;
- }
-
- bytesWritten = requiredBufferLength;
-
- if (insertNegationSign)
- {
- destination[0] = Utf8Constants.Minus;
- destination = destination.Slice(1);
- }
-
- FormattingHelpers.WriteDigitsWithGroupSeparator(value, destination.Slice(0, digitCount + commaCount));
-
- if (trailingZeroCount > 0)
- {
- destination[digitCount + commaCount] = Utf8Constants.Period;
- FormattingHelpers.FillWithAsciiZeros(destination.Slice(digitCount + commaCount + 1, trailingZeroCount));
- }
-
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs
deleted file mode 100644
index 4cf4d52b5c8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs
+++ /dev/null
@@ -1,46 +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.
-
-namespace System.Buffers.Text
-{
- /// <summary>
- /// Methods to format common data types as Utf8 strings.
- /// </summary>
- public static partial class Utf8Formatter
- {
- private static bool TryFormatUInt64X(ulong value, byte precision, bool useLower, Span<byte> destination, out int bytesWritten)
- {
- int actualDigitCount = FormattingHelpers.CountHexDigits(value);
- int computedOutputLength = (precision == StandardFormat.NoPrecision)
- ? actualDigitCount
- : Math.Max(precision, actualDigitCount);
-
- if (destination.Length < computedOutputLength)
- {
- bytesWritten = 0;
- return false;
- }
-
- bytesWritten = computedOutputLength;
- string hexTable = (useLower) ? FormattingHelpers.HexTableLower : FormattingHelpers.HexTableUpper;
-
- // Writing the output backward in this manner allows the JIT to elide
- // bounds checking on the output buffer. The JIT won't elide the bounds
- // check on the hex table lookup, but we can live with that for now.
-
- // It doesn't quite make sense to use the fast hex conversion functionality
- // for this method since that routine works on bytes, and here we're working
- // directly with nibbles. There may be opportunity for improvement by special-
- // casing output lengths of 2, 4, 8, and 16 and running them down optimized
- // code paths.
-
- while ((uint)(--computedOutputLength) < (uint)destination.Length)
- {
- destination[computedOutputLength] = (byte)hexTable[(int)value & 0xf];
- value >>= 4;
- }
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.cs
deleted file mode 100644
index 0040c5075a6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.cs
+++ /dev/null
@@ -1,52 +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 System.Runtime.CompilerServices;
-
-namespace System.Buffers.Text
-{
- /// <summary>
- /// Methods to format common data types as Utf8 strings.
- /// </summary>
- public static partial class Utf8Formatter
- {
- //
- // Common worker for all unsigned integer TryFormat overloads
- //
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool TryFormatUInt64(ulong value, Span<byte> destination, out int bytesWritten, StandardFormat format)
- {
- if (format.IsDefault)
- {
- return TryFormatUInt64Default(value, destination, out bytesWritten);
- }
-
- switch (format.Symbol)
- {
- case 'G':
- case 'g':
- if (format.HasPrecision)
- throw new NotSupportedException(SR.Argument_GWithPrecisionNotSupported); // With a precision, 'G' can produce exponential format, even for integers.
- return TryFormatUInt64D(value, format.Precision, destination, insertNegationSign: false, out bytesWritten);
-
- case 'd':
- case 'D':
- return TryFormatUInt64D(value, format.Precision, destination, insertNegationSign: false, out bytesWritten);
-
- case 'n':
- case 'N':
- return TryFormatUInt64N(value, format.Precision, destination, insertNegationSign: false, out bytesWritten);
-
- case 'x':
- return TryFormatUInt64X(value, format.Precision, true /* useLower */, destination, out bytesWritten);
-
- case 'X':
- return TryFormatUInt64X(value, format.Precision, false /* useLower */, destination, out bytesWritten);
-
- default:
- return FormattingHelpers.TryFormatThrowFormatException(out bytesWritten);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.cs
deleted file mode 100644
index 7e73edc1c72..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.cs
+++ /dev/null
@@ -1,208 +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.
-
-namespace System.Buffers.Text
-{
- /// <summary>
- /// Methods to format common data types as Utf8 strings.
- /// </summary>
- public static partial class Utf8Formatter
- {
- /// <summary>
- /// Formats a Byte as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryFormat(byte value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- => TryFormatUInt64(value, destination, out bytesWritten, format);
-
- /// <summary>
- /// Formats an SByte as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- [CLSCompliant(false)]
- public static bool TryFormat(sbyte value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- => TryFormatInt64(value, 0xff, destination, out bytesWritten, format);
-
- /// <summary>
- /// Formats a Unt16 as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- [CLSCompliant(false)]
- public static bool TryFormat(ushort value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- => TryFormatUInt64(value, destination, out bytesWritten, format);
-
- /// <summary>
- /// Formats an Int16 as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryFormat(short value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- => TryFormatInt64(value, 0xffff, destination, out bytesWritten, format);
-
- /// <summary>
- /// Formats a UInt32 as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- [CLSCompliant(false)]
- public static bool TryFormat(uint value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- => TryFormatUInt64(value, destination, out bytesWritten, format);
-
- /// <summary>
- /// Formats an Int32 as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryFormat(int value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- => TryFormatInt64(value, 0xffffffff, destination, out bytesWritten, format);
-
- /// <summary>
- /// Formats a UInt64 as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- [CLSCompliant(false)]
- public static bool TryFormat(ulong value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- => TryFormatUInt64(value, destination, out bytesWritten, format);
-
- /// <summary>
- /// Formats an Int64 as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryFormat(long value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- => TryFormatInt64(value, 0xffffffffffffffff, destination, out bytesWritten, format);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs
deleted file mode 100644
index c21fddc9d10..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs
+++ /dev/null
@@ -1,222 +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 System.Diagnostics;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Formatter
- {
- /// <summary>
- /// Formats a TimeSpan as a UTF8 string.
- /// </summary>
- /// <param name="value">Value to format</param>
- /// <param name="destination">Buffer to write the UTF8-formatted value to</param>
- /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param>
- /// <param name="format">The standard format to use</param>
- /// <returns>
- /// true for success. "bytesWritten" contains the length of the formatted text in bytes.
- /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// c/t/T (default) [-][d.]hh:mm:ss[.fffffff] (constant format)
- /// G [-]d:hh:mm:ss.fffffff (general long)
- /// g [-][d:][h]h:mm:ss[.f[f[f[f[f[f[f]]]]]] (general short)
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryFormat(TimeSpan value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
- {
- char symbol = FormattingHelpers.GetSymbolOrDefault(format, 'c');
-
- switch (symbol)
- {
- case 'c':
- case 'G':
- case 'g':
- break;
-
- case 't':
- case 'T':
- symbol = 'c';
- break;
-
- default:
- return FormattingHelpers.TryFormatThrowFormatException(out bytesWritten);
- }
-
- // First, calculate how large an output buffer is needed to hold the entire output.
-
- int requiredOutputLength = 8; // start with "hh:mm:ss" and adjust as necessary
-
- uint fraction;
- ulong totalSecondsRemaining;
- {
- // Turn this into a non-negative TimeSpan if possible.
- long ticks = value.Ticks;
- if (ticks < 0)
- {
- ticks = -ticks;
- if (ticks < 0)
- {
- Debug.Assert(ticks == long.MinValue /* -9223372036854775808 */);
-
- // We computed these ahead of time; they're straight from the decimal representation of Int64.MinValue.
- fraction = 4775808;
- totalSecondsRemaining = 922337203685;
- goto AfterComputeFraction;
- }
- }
-
- totalSecondsRemaining = FormattingHelpers.DivMod((ulong)Math.Abs(value.Ticks), TimeSpan.TicksPerSecond, out ulong fraction64);
- fraction = (uint)fraction64;
- }
-
- AfterComputeFraction:
-
- int fractionDigits = 0;
- if (symbol == 'c')
- {
- // Only write out the fraction if it's non-zero, and in that
- // case write out the entire fraction (all digits).
- if (fraction != 0)
- {
- fractionDigits = Utf8Constants.DateTimeNumFractionDigits;
- }
- }
- else if (symbol == 'G')
- {
- // Always write out the fraction, even if it's zero.
- fractionDigits = Utf8Constants.DateTimeNumFractionDigits;
- }
- else
- {
- // Only write out the fraction if it's non-zero, and in that
- // case write out only the most significant digits.
- if (fraction != 0)
- {
- fractionDigits = Utf8Constants.DateTimeNumFractionDigits - FormattingHelpers.CountDecimalTrailingZeros(fraction, out fraction);
- }
- }
-
- Debug.Assert(fraction < 10_000_000);
-
- // If we're going to write out a fraction, also need to write the leading decimal.
- if (fractionDigits != 0)
- {
- requiredOutputLength += fractionDigits + 1;
- }
-
- ulong totalMinutesRemaining = 0;
- ulong seconds = 0;
- if (totalSecondsRemaining > 0)
- {
- // Only compute minutes if the TimeSpan has an absolute value of >= 1 minute.
- totalMinutesRemaining = FormattingHelpers.DivMod(totalSecondsRemaining, 60 /* seconds per minute */, out seconds);
- }
-
- Debug.Assert(seconds < 60);
-
- ulong totalHoursRemaining = 0;
- ulong minutes = 0;
- if (totalMinutesRemaining > 0)
- {
- // Only compute hours if the TimeSpan has an absolute value of >= 1 hour.
- totalHoursRemaining = FormattingHelpers.DivMod(totalMinutesRemaining, 60 /* minutes per hour */, out minutes);
- }
-
- Debug.Assert(minutes < 60);
-
- // At this point, we can switch over to 32-bit divmod since the data has shrunk far enough.
- Debug.Assert(totalHoursRemaining <= uint.MaxValue);
-
- uint days = 0;
- uint hours = 0;
- if (totalHoursRemaining > 0)
- {
- // Only compute days if the TimeSpan has an absolute value of >= 1 day.
- days = FormattingHelpers.DivMod((uint)totalHoursRemaining, 24 /* hours per day */, out hours);
- }
-
- Debug.Assert(hours < 24);
-
- int hourDigits = 2;
- if (hours < 10 && symbol == 'g')
- {
- // Only writing a one-digit hour, not a two-digit hour
- hourDigits--;
- requiredOutputLength--;
- }
-
- int dayDigits = 0;
- if (days == 0)
- {
- if (symbol == 'G')
- {
- requiredOutputLength += 2; // for the leading "0:"
- dayDigits = 1;
- }
- }
- else
- {
- dayDigits = FormattingHelpers.CountDigits(days);
- requiredOutputLength += dayDigits + 1; // for the leading "d:" (or "d.")
- }
-
- if (value.Ticks < 0)
- {
- requiredOutputLength++; // for the leading '-' sign
- }
-
- if (destination.Length < requiredOutputLength)
- {
- bytesWritten = 0;
- return false;
- }
-
- bytesWritten = requiredOutputLength;
-
- int idx = 0;
-
- // Write leading '-' if necessary
- if (value.Ticks < 0)
- {
- destination[idx++] = Utf8Constants.Minus;
- }
-
- // Write day (and separator) if necessary
- if (dayDigits > 0)
- {
- FormattingHelpers.WriteDigits(days, destination.Slice(idx, dayDigits));
- idx += dayDigits;
- destination[idx++] = (symbol == 'c') ? Utf8Constants.Period : Utf8Constants.Colon;
- }
-
- // Write "[h]h:mm:ss"
- FormattingHelpers.WriteDigits(hours, destination.Slice(idx, hourDigits));
- idx += hourDigits;
- destination[idx++] = Utf8Constants.Colon;
- FormattingHelpers.WriteDigits((uint)minutes, destination.Slice(idx, 2));
- idx += 2;
- destination[idx++] = Utf8Constants.Colon;
- FormattingHelpers.WriteDigits((uint)seconds, destination.Slice(idx, 2));
- idx += 2;
-
- // Write fraction (and separator) if necessary
- if (fractionDigits > 0)
- {
- destination[idx++] = Utf8Constants.Period;
- FormattingHelpers.WriteDigits(fraction, destination.Slice(idx, fractionDigits));
- idx += fractionDigits;
- }
-
- // And we're done!
-
- Debug.Assert(idx == requiredOutputLength);
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/ParserHelpers.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/ParserHelpers.cs
deleted file mode 100644
index d5f50473f24..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/ParserHelpers.cs
+++ /dev/null
@@ -1,74 +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 System.Runtime.CompilerServices;
-
-namespace System.Buffers.Text
-{
- internal static class ParserHelpers
- {
- public const int ByteOverflowLength = 3;
- public const int ByteOverflowLengthHex = 2;
- public const int UInt16OverflowLength = 5;
- public const int UInt16OverflowLengthHex = 4;
- public const int UInt32OverflowLength = 10;
- public const int UInt32OverflowLengthHex = 8;
- public const int UInt64OverflowLength = 20;
- public const int UInt64OverflowLengthHex = 16;
-
- public const int SByteOverflowLength = 3;
- public const int SByteOverflowLengthHex = 2;
- public const int Int16OverflowLength = 5;
- public const int Int16OverflowLengthHex = 4;
- public const int Int32OverflowLength = 10;
- public const int Int32OverflowLengthHex = 8;
- public const int Int64OverflowLength = 19;
- public const int Int64OverflowLengthHex = 16;
-
- public static ReadOnlySpan<byte> HexLookup => new byte[] // rely on C# compiler optimization to reference static data
- {
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 15
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 31
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 47
- 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 63
- 0xFF, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 79
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 95
- 0xFF, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 111
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 127
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 143
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 159
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 175
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 191
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 207
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 223
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 239
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF // 255
- };
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsDigit(int i)
- {
- return (uint)(i - '0') <= ('9' - '0');
- }
-
- //
- // Enable use of ThrowHelper from TryParse() routines without introducing dozens of non-code-coveraged "value= default; bytesConsumed = 0; return false" boilerplate.
- //
- public static bool TryParseThrowFormatException(out int bytesConsumed)
- {
- bytesConsumed = 0;
- ThrowHelper.ThrowFormatException_BadFormatSpecifier();
- return false;
- }
-
- //
- // Enable use of ThrowHelper from TryParse() routines without introducing dozens of non-code-coveraged "value= default; bytesConsumed = 0; return false" boilerplate.
- //
- public static bool TryParseThrowFormatException<T>(out T value, out int bytesConsumed) where T : struct
- {
- value = default;
- return TryParseThrowFormatException(out bytesConsumed);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs
deleted file mode 100644
index 1c5e4f243e1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Boolean.cs
+++ /dev/null
@@ -1,61 +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 System.Buffers.Binary;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- /// <summary>
- /// Parses a Boolean at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G (default) True/False
- /// l true/false
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryParse(ReadOnlySpan<byte> source, out bool value, out int bytesConsumed, char standardFormat = default)
- {
- if (!(standardFormat == default(char) || standardFormat == 'G' || standardFormat == 'l'))
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
-
- if (source.Length >= 4)
- {
- int dw = BinaryPrimitives.ReadInt32LittleEndian(source) & ~0x20202020;
- if (dw == 0x45555254 /* 'EURT' */)
- {
- bytesConsumed = 4;
- value = true;
- return true;
- }
-
- if (source.Length >= 5)
- {
- if (dw == 0x534c4146 /* 'SLAF' */ && (source[4] & ~0x20) == 'E')
- {
- bytesConsumed = 5;
- value = false;
- return true;
- }
- }
- }
-
- bytesConsumed = 0;
- value = default;
- return false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Default.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Default.cs
deleted file mode 100644
index 77d7e1224be..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Default.cs
+++ /dev/null
@@ -1,96 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- //
- // ToString() format for DateTimeOffset. Does not have a corresponding format symbol but it
- // is the "G" format postpended with the UTC offset.
- //
- // 01234567890123456789012345
- // --------------------------
- // 05/25/2017 10:30:15 -08:00
- //
- private static bool TryParseDateTimeOffsetDefault(ReadOnlySpan<byte> source, out DateTimeOffset value, out int bytesConsumed)
- {
- if (source.Length < 26)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
-
- if (!TryParseDateTimeG(source, out DateTime dateTime, out _, out _))
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
-
- if (source[19] != Utf8Constants.Space)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
-
- byte sign = source[20];
- if (sign != Utf8Constants.Plus && sign != Utf8Constants.Minus)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
-
- int offsetHours;
- {
- uint digit1 = source[21] - 48u; // '0'
- uint digit2 = source[22] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
-
- offsetHours = (int)(digit1 * 10 + digit2);
- }
-
- if (source[23] != Utf8Constants.Colon)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
-
- int offsetMinutes;
- {
- uint digit1 = source[24] - 48u; // '0'
- uint digit2 = source[25] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
-
- offsetMinutes = (int)(digit1 * 10 + digit2);
- }
-
- if (!TryCreateDateTimeOffset(dateTime: dateTime, offsetNegative: sign == Utf8Constants.Minus, offsetHours: offsetHours, offsetMinutes: offsetMinutes, out value))
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
-
- bytesConsumed = 26;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.G.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.G.cs
deleted file mode 100644
index 6e8edbcbdf8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.G.cs
+++ /dev/null
@@ -1,177 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- //
- // 'G' format for DateTime.
- //
- // 0123456789012345678
- // ---------------------------------
- // 05/25/2017 10:30:15
- //
- private static bool TryParseDateTimeG(ReadOnlySpan<byte> source, out DateTime value, out DateTimeOffset valueAsOffset, out int bytesConsumed)
- {
- if (source.Length < 19)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- int month;
- {
- uint digit1 = source[0] - 48u; // '0'
- uint digit2 = source[1] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- month = (int)(digit1 * 10 + digit2);
- }
-
- if (source[2] != Utf8Constants.Slash)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- int day;
- {
- uint digit1 = source[3] - 48u; // '0'
- uint digit2 = source[4] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- day = (int)(digit1 * 10 + digit2);
- }
-
- if (source[5] != Utf8Constants.Slash)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- int year;
- {
- uint digit1 = source[6] - 48u; // '0'
- uint digit2 = source[7] - 48u; // '0'
- uint digit3 = source[8] - 48u; // '0'
- uint digit4 = source[9] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9 || digit3 > 9 || digit4 > 9)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- year = (int)(digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4);
- }
-
- if (source[10] != Utf8Constants.Space)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- int hour;
- {
- uint digit1 = source[11] - 48u; // '0'
- uint digit2 = source[12] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- hour = (int)(digit1 * 10 + digit2);
- }
-
- if (source[13] != Utf8Constants.Colon)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- int minute;
- {
- uint digit1 = source[14] - 48u; // '0'
- uint digit2 = source[15] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- minute = (int)(digit1 * 10 + digit2);
- }
-
- if (source[16] != Utf8Constants.Colon)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- int second;
- {
- uint digit1 = source[17] - 48u; // '0'
- uint digit2 = source[18] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- second = (int)(digit1 * 10 + digit2);
- }
-
- if (!TryCreateDateTimeOffsetInterpretingDataAsLocalTime(year: year, month: month, day: day, hour: hour, minute: minute, second: second, fraction: 0, out valueAsOffset))
- {
- bytesConsumed = 0;
- value = default;
- valueAsOffset = default;
- return false;
- }
-
- bytesConsumed = 19;
- value = valueAsOffset.DateTime;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Helpers.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Helpers.cs
deleted file mode 100644
index d2fb06829a6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.Helpers.cs
+++ /dev/null
@@ -1,162 +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 System.Diagnostics;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- /// <summary>
- /// Overflow-safe DateTimeOffset factory.
- /// </summary>
- private static bool TryCreateDateTimeOffset(DateTime dateTime, bool offsetNegative, int offsetHours, int offsetMinutes, out DateTimeOffset value)
- {
- if (((uint)offsetHours) > Utf8Constants.DateTimeMaxUtcOffsetHours)
- {
- value = default;
- return false;
- }
-
- if (((uint)offsetMinutes) > 59)
- {
- value = default;
- return false;
- }
-
- if (offsetHours == Utf8Constants.DateTimeMaxUtcOffsetHours && offsetMinutes != 0)
- {
- value = default;
- return false;
- }
-
- long offsetTicks = (((long)offsetHours) * 3600 + ((long)offsetMinutes) * 60) * TimeSpan.TicksPerSecond;
- if (offsetNegative)
- {
- offsetTicks = -offsetTicks;
- }
-
- try
- {
- value = new DateTimeOffset(ticks: dateTime.Ticks, offset: new TimeSpan(ticks: offsetTicks));
- }
- catch (ArgumentOutOfRangeException)
- {
- // If we got here, the combination of the DateTime + UTC offset strayed outside the 1..9999 year range. This case seems rare enough
- // that it's better to catch the exception rather than replicate DateTime's range checking (which it's going to do anyway.)
- value = default;
- return false;
- }
-
- return true;
- }
-
- /// <summary>
- /// Overflow-safe DateTimeOffset factory.
- /// </summary>
- private static bool TryCreateDateTimeOffset(int year, int month, int day, int hour, int minute, int second, int fraction, bool offsetNegative, int offsetHours, int offsetMinutes, out DateTimeOffset value)
- {
- if (!TryCreateDateTime(year: year, month: month, day: day, hour: hour, minute: minute, second: second, fraction: fraction, kind: DateTimeKind.Unspecified, out DateTime dateTime))
- {
- value = default;
- return false;
- }
-
- if (!TryCreateDateTimeOffset(dateTime: dateTime, offsetNegative: offsetNegative, offsetHours: offsetHours, offsetMinutes: offsetMinutes, out value))
- {
- value = default;
- return false;
- }
-
- return true;
- }
-
- /// <summary>
- /// Overflow-safe DateTimeOffset/Local time conversion factory.
- /// </summary>
- private static bool TryCreateDateTimeOffsetInterpretingDataAsLocalTime(int year, int month, int day, int hour, int minute, int second, int fraction, out DateTimeOffset value)
- {
- if (!TryCreateDateTime(year: year, month: month, day: day, hour: hour, minute: minute, second: second, fraction: fraction, DateTimeKind.Local, out DateTime dateTime))
- {
- value = default;
- return false;
- }
-
- try
- {
- value = new DateTimeOffset(dateTime);
- }
- catch (ArgumentOutOfRangeException)
- {
- // If we got here, the combination of the DateTime + UTC offset strayed outside the 1..9999 year range. This case seems rare enough
- // that it's better to catch the exception rather than replicate DateTime's range checking (which it's going to do anyway.)
-
- value = default;
- return false;
- }
-
- return true;
- }
-
- /// <summary>
- /// Overflow-safe DateTime factory.
- /// </summary>
- private static bool TryCreateDateTime(int year, int month, int day, int hour, int minute, int second, int fraction, DateTimeKind kind, out DateTime value)
- {
- if (year == 0)
- {
- value = default;
- return false;
- }
-
- Debug.Assert(year <= 9999); // All of our callers to date parse the year from fixed 4-digit fields so this value is trusted.
-
- if ((((uint)month) - 1) >= 12)
- {
- value = default;
- return false;
- }
-
- uint dayMinusOne = ((uint)day) - 1;
- if (dayMinusOne >= 28 && dayMinusOne >= DateTime.DaysInMonth(year, month))
- {
- value = default;
- return false;
- }
-
- if (((uint)hour) > 23)
- {
- value = default;
- return false;
- }
-
- if (((uint)minute) > 59)
- {
- value = default;
- return false;
- }
-
- if (((uint)second) > 59)
- {
- value = default;
- return false;
- }
-
- Debug.Assert(fraction >= 0 && fraction <= Utf8Constants.MaxDateTimeFraction); // All of our callers to date parse the fraction from fixed 7-digit fields so this value is trusted.
-
- int[] days = DateTime.IsLeapYear(year) ? s_daysToMonth366 : s_daysToMonth365;
- int yearMinusOne = year - 1;
- int totalDays = (yearMinusOne * 365) + (yearMinusOne / 4) - (yearMinusOne / 100) + (yearMinusOne / 400) + days[month - 1] + day - 1;
- long ticks = totalDays * TimeSpan.TicksPerDay;
- int totalSeconds = (hour * 3600) + (minute * 60) + second;
- ticks += totalSeconds * TimeSpan.TicksPerSecond;
- ticks += fraction;
- value = new DateTime(ticks: ticks, kind: kind);
- return true;
- }
-
- private static readonly int[] s_daysToMonth365 = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
- private static readonly int[] s_daysToMonth366 = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.O.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.O.cs
deleted file mode 100644
index 8d2c681f68e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.O.cs
+++ /dev/null
@@ -1,290 +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 System.Diagnostics;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- //
- // Roundtrippable format. One of
- //
- // 012345678901234567890123456789012
- // ---------------------------------
- // 2017-06-12T05:30:45.7680000-07:00
- // 2017-06-12T05:30:45.7680000Z (Z is short for "+00:00" but also distinguishes DateTimeKind.Utc from DateTimeKind.Local)
- // 2017-06-12T05:30:45.7680000 (interpreted as local time wrt to current time zone)
- //
- private static bool TryParseDateTimeOffsetO(ReadOnlySpan<byte> source, out DateTimeOffset value, out int bytesConsumed, out DateTimeKind kind)
- {
- if (source.Length < 27)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- int year;
- {
- uint digit1 = source[0] - 48u; // '0'
- uint digit2 = source[1] - 48u; // '0'
- uint digit3 = source[2] - 48u; // '0'
- uint digit4 = source[3] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9 || digit3 > 9 || digit4 > 9)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- year = (int)(digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4);
- }
-
- if (source[4] != Utf8Constants.Hyphen)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- int month;
- {
- uint digit1 = source[5] - 48u; // '0'
- uint digit2 = source[6] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- month = (int)(digit1 * 10 + digit2);
- }
-
- if (source[7] != Utf8Constants.Hyphen)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- int day;
- {
- uint digit1 = source[8] - 48u; // '0'
- uint digit2 = source[9] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- day = (int)(digit1 * 10 + digit2);
- }
-
- if (source[10] != 'T')
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- int hour;
- {
- uint digit1 = source[11] - 48u; // '0'
- uint digit2 = source[12] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- hour = (int)(digit1 * 10 + digit2);
- }
-
- if (source[13] != Utf8Constants.Colon)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- int minute;
- {
- uint digit1 = source[14] - 48u; // '0'
- uint digit2 = source[15] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- minute = (int)(digit1 * 10 + digit2);
- }
-
- if (source[16] != Utf8Constants.Colon)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- int second;
- {
- uint digit1 = source[17] - 48u; // '0'
- uint digit2 = source[18] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- second = (int)(digit1 * 10 + digit2);
- }
-
- if (source[19] != Utf8Constants.Period)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- int fraction;
- {
- uint digit1 = source[20] - 48u; // '0'
- uint digit2 = source[21] - 48u; // '0'
- uint digit3 = source[22] - 48u; // '0'
- uint digit4 = source[23] - 48u; // '0'
- uint digit5 = source[24] - 48u; // '0'
- uint digit6 = source[25] - 48u; // '0'
- uint digit7 = source[26] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9 || digit3 > 9 || digit4 > 9 || digit5 > 9 || digit6 > 9 || digit7 > 9)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- fraction = (int)(digit1 * 1000000 + digit2 * 100000 + digit3 * 10000 + digit4 * 1000 + digit5 * 100 + digit6 * 10 + digit7);
- }
-
- byte offsetChar = (source.Length <= 27) ? default : source[27];
- if (offsetChar != 'Z' && offsetChar != Utf8Constants.Plus && offsetChar != Utf8Constants.Minus)
- {
- if (!TryCreateDateTimeOffsetInterpretingDataAsLocalTime(year: year, month: month, day: day, hour: hour, minute: minute, second: second, fraction: fraction, out value))
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
- bytesConsumed = 27;
- kind = DateTimeKind.Unspecified;
- return true;
- }
-
- if (offsetChar == 'Z')
- {
- // Same as specifying an offset of "+00:00", except that DateTime's Kind gets set to UTC rather than Local
- if (!TryCreateDateTimeOffset(year: year, month: month, day: day, hour: hour, minute: minute, second: second, fraction: fraction, offsetNegative: false, offsetHours: 0, offsetMinutes: 0, out value))
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- bytesConsumed = 28;
- kind = DateTimeKind.Utc;
- return true;
- }
-
- Debug.Assert(offsetChar == Utf8Constants.Plus || offsetChar == Utf8Constants.Minus);
- if (source.Length < 33)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- int offsetHours;
- {
- uint digit1 = source[28] - 48u; // '0'
- uint digit2 = source[29] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- offsetHours = (int)(digit1 * 10 + digit2);
- }
-
- if (source[30] != Utf8Constants.Colon)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- int offsetMinutes;
- {
- uint digit1 = source[31] - 48u; // '0'
- uint digit2 = source[32] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- offsetMinutes = (int)(digit1 * 10 + digit2);
- }
-
- if (!TryCreateDateTimeOffset(year: year, month: month, day: day, hour: hour, minute: minute, second: second, fraction: fraction, offsetNegative: offsetChar == Utf8Constants.Minus, offsetHours: offsetHours, offsetMinutes: offsetMinutes, out value))
- {
- value = default;
- bytesConsumed = 0;
- kind = default;
- return false;
- }
-
- bytesConsumed = 33;
- kind = DateTimeKind.Local;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.R.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.R.cs
deleted file mode 100644
index 566384c4c37..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.R.cs
+++ /dev/null
@@ -1,221 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- //
- // Parse an RFC1123 date string.
- //
- // 01234567890123456789012345678
- // -----------------------------
- // Tue, 03 Jan 2017 08:08:05 GMT
- //
- private static bool TryParseDateTimeOffsetR(ReadOnlySpan<byte> source, uint caseFlipXorMask, out DateTimeOffset dateTimeOffset, out int bytesConsumed)
- {
- if (source.Length < 29)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- DayOfWeek dayOfWeek;
- {
- uint dow0 = source[0] ^ caseFlipXorMask;
- uint dow1 = source[1];
- uint dow2 = source[2];
- uint comma = source[3];
- uint dowString = (dow0 << 24) | (dow1 << 16) | (dow2 << 8) | comma;
- switch (dowString)
- {
- case 0x53756E2c /* 'Sun,' */: dayOfWeek = DayOfWeek.Sunday; break;
- case 0x4d6f6e2c /* 'Mon,' */: dayOfWeek = DayOfWeek.Monday; break;
- case 0x5475652c /* 'Tue,' */: dayOfWeek = DayOfWeek.Tuesday; break;
- case 0x5765642c /* 'Wed,' */: dayOfWeek = DayOfWeek.Wednesday; break;
- case 0x5468752c /* 'Thu,' */: dayOfWeek = DayOfWeek.Thursday; break;
- case 0x4672692c /* 'Fri,' */: dayOfWeek = DayOfWeek.Friday; break;
- case 0x5361742c /* 'Sat,' */: dayOfWeek = DayOfWeek.Saturday; break;
- default:
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
- }
-
- if (source[4] != Utf8Constants.Space)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- int day;
- {
- uint digit1 = source[5] - 48u; // '0'
- uint digit2 = source[6] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- day = (int)(digit1 * 10 + digit2);
- }
-
- if (source[7] != Utf8Constants.Space)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- int month;
- {
- uint mon0 = source[8] ^ caseFlipXorMask;
- uint mon1 = source[9];
- uint mon2 = source[10];
- uint space = source[11];
- uint monthString = (mon0 << 24) | (mon1 << 16) | (mon2 << 8) | space;
- switch (monthString)
- {
- case 0x4a616e20: /* 'Jan ' */ month = 1; break;
- case 0x46656220: /* 'Feb ' */ month = 2; break;
- case 0x4d617220: /* 'Mar ' */ month = 3; break;
- case 0x41707220: /* 'Apr ' */ month = 4; break;
- case 0x4d617920: /* 'May ' */ month = 5; break;
- case 0x4a756e20: /* 'Jun ' */ month = 6; break;
- case 0x4a756c20: /* 'Jul ' */ month = 7; break;
- case 0x41756720: /* 'Aug ' */ month = 8; break;
- case 0x53657020: /* 'Sep ' */ month = 9; break;
- case 0x4f637420: /* 'Oct ' */ month = 10; break;
- case 0x4e6f7620: /* 'Nov ' */ month = 11; break;
- case 0x44656320: /* 'Dec ' */ month = 12; break;
- default:
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
- }
-
- int year;
- {
- uint digit1 = source[12] - 48u; // '0'
- uint digit2 = source[13] - 48u; // '0'
- uint digit3 = source[14] - 48u; // '0'
- uint digit4 = source[15] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9 || digit3 > 9 || digit4 > 9)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- year = (int)(digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4);
- }
-
- if (source[16] != Utf8Constants.Space)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- int hour;
- {
- uint digit1 = source[17] - 48u; // '0'
- uint digit2 = source[18] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- hour = (int)(digit1 * 10 + digit2);
- }
-
- if (source[19] != Utf8Constants.Colon)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- int minute;
- {
- uint digit1 = source[20] - 48u; // '0'
- uint digit2 = source[21] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- minute = (int)(digit1 * 10 + digit2);
- }
-
- if (source[22] != Utf8Constants.Colon)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- int second;
- {
- uint digit1 = source[23] - 48u; // '0'
- uint digit2 = source[24] - 48u; // '0'
-
- if (digit1 > 9 || digit2 > 9)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- second = (int)(digit1 * 10 + digit2);
- }
-
- {
- uint space = source[25];
- uint g = source[26] ^ caseFlipXorMask;
- uint m = source[27] ^ caseFlipXorMask;
- uint t = source[28] ^ caseFlipXorMask;
- uint gmtString = (space << 24) | (g << 16) | (m << 8) | t;
- if (gmtString != 0x20474d54 /* ' GMT' */)
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
- }
-
- if (!TryCreateDateTimeOffset(year: year, month: month, day: day, hour: hour, minute: minute, second: second, fraction: 0, offsetNegative: false, offsetHours: 0, offsetMinutes: 0, out dateTimeOffset))
- {
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- if (dayOfWeek != dateTimeOffset.DayOfWeek)
- {
- // If we got here, the day of week did not match the actual date.
- bytesConsumed = 0;
- dateTimeOffset = default;
- return false;
- }
-
- bytesConsumed = 29;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.cs
deleted file mode 100644
index 7fb6f0c6081..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.cs
+++ /dev/null
@@ -1,138 +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 System.Diagnostics;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- /// <summary>
- /// Parses a DateTime at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// default 05/25/2017 10:30:15 -08:00
- /// G 05/25/2017 10:30:15
- /// R Tue, 03 Jan 2017 08:08:05 GMT (RFC 1123)
- /// l tue, 03 jan 2017 08:08:05 gmt (Lowercase RFC 1123)
- /// O 2017-06-12T05:30:45.7680000-07:00 (Round-trippable)
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryParse(ReadOnlySpan<byte> source, out DateTime value, out int bytesConsumed, char standardFormat = default)
- {
- switch (standardFormat)
- {
- case 'R':
- {
- if (!TryParseDateTimeOffsetR(source, NoFlipCase, out DateTimeOffset dateTimeOffset, out bytesConsumed))
- {
- value = default;
- return false;
- }
- value = dateTimeOffset.DateTime; // (returns a DateTimeKind.Unspecified to match DateTime.ParseExact(). Maybe better to return UtcDateTime instead?)
- return true;
- }
-
- case 'l':
- {
- if (!TryParseDateTimeOffsetR(source, FlipCase, out DateTimeOffset dateTimeOffset, out bytesConsumed))
- {
- value = default;
- return false;
- }
- value = dateTimeOffset.DateTime; // (returns a DateTimeKind.Unspecified to match DateTime.ParseExact(). Maybe better to return UtcDateTime instead?)
- return true;
- }
-
- case 'O':
- {
- // Emulates DateTime.ParseExact(text, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind)
- // In particular, the formatted string "encodes" the DateTimeKind according to the following table:
- //
- // 2017-06-12T05:30:45.7680000 - Unspecified
- // 2017-06-12T05:30:45.7680000+00:00 - Local
- // 2017-06-12T05:30:45.7680000Z - Utc
-
- if (!TryParseDateTimeOffsetO(source, out DateTimeOffset dateTimeOffset, out bytesConsumed, out DateTimeKind kind))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- switch (kind)
- {
- case DateTimeKind.Local:
- value = dateTimeOffset.LocalDateTime;
- break;
- case DateTimeKind.Utc:
- value = dateTimeOffset.UtcDateTime;
- break;
- default:
- Debug.Assert(kind == DateTimeKind.Unspecified);
- value = dateTimeOffset.DateTime;
- break;
- }
-
- return true;
- }
-
- case default(char):
- case 'G':
- return TryParseDateTimeG(source, out value, out _, out bytesConsumed);
-
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
- }
-
- /// <summary>
- /// Parses a DateTimeOffset at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G (default) 05/25/2017 10:30:15
- /// R Tue, 03 Jan 2017 08:08:05 GMT (RFC 1123)
- /// l tue, 03 jan 2017 08:08:05 gmt (Lowercase RFC 1123)
- /// O 2017-06-12T05:30:45.7680000-07:00 (Round-trippable)
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryParse(ReadOnlySpan<byte> source, out DateTimeOffset value, out int bytesConsumed, char standardFormat = default)
- {
- return standardFormat switch
- {
- 'R' => TryParseDateTimeOffsetR(source, NoFlipCase, out value, out bytesConsumed),
- 'l' => TryParseDateTimeOffsetR(source, FlipCase, out value, out bytesConsumed),
- 'O' => TryParseDateTimeOffsetO(source, out value, out bytesConsumed, out _),
- default(char) => TryParseDateTimeOffsetDefault(source, out value, out bytesConsumed),
- 'G' => TryParseDateTimeG(source, out DateTime _, out value, out bytesConsumed),
- _ => ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed),
- };
- }
-
- private const uint FlipCase = 0x00000020u; // XOR mask to flip the case of a letter.
- private const uint NoFlipCase = 0x00000000u;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs
deleted file mode 100644
index c3f6cdc1565..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Decimal.cs
+++ /dev/null
@@ -1,79 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- /// <summary>
- /// Parses a Decimal at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// F/f 12.45 Fixed point
- /// E/e 1.245000e1 Exponential
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static unsafe bool TryParse(ReadOnlySpan<byte> source, out decimal value, out int bytesConsumed, char standardFormat = default)
- {
- ParseNumberOptions options;
- switch (standardFormat)
- {
- case default(char):
- case 'G':
- case 'g':
- case 'E':
- case 'e':
- options = ParseNumberOptions.AllowExponent;
- break;
-
- case 'F':
- case 'f':
- options = default;
- break;
-
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
-
- byte* pDigits = stackalloc byte[Number.DecimalNumberBufferLength];
- Number.NumberBuffer number = new Number.NumberBuffer(Number.NumberBufferKind.Decimal, pDigits, Number.DecimalNumberBufferLength);
-
- if (!TryParseNumber(source, ref number, out bytesConsumed, options, out bool textUsedExponentNotation))
- {
- value = default;
- return false;
- }
-
- if ((!textUsedExponentNotation) && (standardFormat == 'E' || standardFormat == 'e'))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- value = default;
-
- if (!Number.TryNumberToDecimal(ref number, ref value))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs
deleted file mode 100644
index 26274e829df..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Float.cs
+++ /dev/null
@@ -1,184 +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 System.Buffers.Binary;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- /// <summary>
- /// Parses a Single at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// F/f 12.45 Fixed point
- /// E/e 1.245000e1 Exponential
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static unsafe bool TryParse(ReadOnlySpan<byte> source, out float value, out int bytesConsumed, char standardFormat = default)
- {
- byte* pDigits = stackalloc byte[Number.SingleNumberBufferLength];
- Number.NumberBuffer number = new Number.NumberBuffer(Number.NumberBufferKind.FloatingPoint, pDigits, Number.SingleNumberBufferLength);
-
- if (TryParseNormalAsFloatingPoint(source, ref number, out bytesConsumed, standardFormat))
- {
- value = Number.NumberToSingle(ref number);
- return true;
- }
-
- return TryParseAsSpecialFloatingPoint(source, float.PositiveInfinity, float.NegativeInfinity, float.NaN, out value, out bytesConsumed);
- }
-
- /// <summary>
- /// Parses a Double at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// F/f 12.45 Fixed point
- /// E/e 1.245000e1 Exponential
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static unsafe bool TryParse(ReadOnlySpan<byte> source, out double value, out int bytesConsumed, char standardFormat = default)
- {
- byte* pDigits = stackalloc byte[Number.DoubleNumberBufferLength];
- Number.NumberBuffer number = new Number.NumberBuffer(Number.NumberBufferKind.FloatingPoint, pDigits, Number.DoubleNumberBufferLength);
-
- if (TryParseNormalAsFloatingPoint(source, ref number, out bytesConsumed, standardFormat))
- {
- value = Number.NumberToDouble(ref number);
- return true;
- }
-
- return TryParseAsSpecialFloatingPoint(source, double.PositiveInfinity, double.NegativeInfinity, double.NaN, out value, out bytesConsumed);
- }
-
- //
- // Attempt to parse the regular floating points (the ones without names like "Infinity" and "NaN")
- //
- private static bool TryParseNormalAsFloatingPoint(ReadOnlySpan<byte> source, ref Number.NumberBuffer number, out int bytesConsumed, char standardFormat)
- {
- ParseNumberOptions options;
- switch (standardFormat)
- {
- case default(char):
- case 'G':
- case 'g':
- case 'E':
- case 'e':
- options = ParseNumberOptions.AllowExponent;
- break;
- case 'F':
- case 'f':
- options = default;
- break;
- default:
- return ParserHelpers.TryParseThrowFormatException(out bytesConsumed);
- }
- if (!TryParseNumber(source, ref number, out bytesConsumed, options, out bool textUsedExponentNotation))
- {
- return false;
- }
- if ((!textUsedExponentNotation) && (standardFormat == 'E' || standardFormat == 'e'))
- {
- bytesConsumed = 0;
- return false;
- }
- return true;
- }
-
- //
- // Assuming the text doesn't look like a normal floating point, we attempt to parse it as one the special floating point values.
- //
- private static bool TryParseAsSpecialFloatingPoint<T>(ReadOnlySpan<byte> source, T positiveInfinity, T negativeInfinity, T nan, out T value, out int bytesConsumed) where T : struct
- {
- int srcIndex = 0;
- int remaining = source.Length;
- bool isNegative = false;
-
- // We need at least 4 characters to process a sign
- if (remaining >= 4)
- {
- byte c = source[srcIndex];
-
- switch (c)
- {
- case Utf8Constants.Minus:
- {
- isNegative = true;
- goto case Utf8Constants.Plus;
- }
-
- case Utf8Constants.Plus:
- {
- srcIndex++;
- remaining--;
- break;
- }
- }
- }
-
- // We can efficiently do an ASCII IsLower check by xor'ing with the expected
- // result and validating that it returns either 0 or exactly 0x20 (which is the
- // delta between lowercase and uppercase ASCII characters).
-
- if (remaining >= 3)
- {
- if ((((source[srcIndex] ^ (byte)('n')) & ~0x20) == 0) &&
- (((source[srcIndex + 1] ^ (byte)('a')) & ~0x20) == 0) &&
- (((source[srcIndex + 2] ^ (byte)('n')) & ~0x20) == 0))
- {
- value = nan;
- bytesConsumed = 3 + srcIndex;
- return true;
- }
-
- if (remaining >= 8)
- {
- const int infi = 0x69666E69;
- int diff = (BinaryPrimitives.ReadInt32LittleEndian(source.Slice(srcIndex)) ^ infi);
-
- if ((diff & ~0x20202020) == 0)
- {
- const int nity = 0x7974696E;
- diff = (BinaryPrimitives.ReadInt32LittleEndian(source.Slice(srcIndex + 4)) ^ nity);
-
- if ((diff & ~0x20202020) == 0)
- {
- value = isNegative ? negativeInfinity : positiveInfinity;
- bytesConsumed = 8 + srcIndex;
- return true;
- }
- }
- }
- }
-
- value = default;
- bytesConsumed = 0;
- return false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs
deleted file mode 100644
index cd2a821ff5f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Guid.cs
+++ /dev/null
@@ -1,243 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- /// <summary>
- /// Parses a Guid at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// D (default) nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
- /// B {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}
- /// P (nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn)
- /// N nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryParse(ReadOnlySpan<byte> source, out Guid value, out int bytesConsumed, char standardFormat = default)
- {
- switch (standardFormat)
- {
- case default(char):
- case 'D':
- return TryParseGuidCore(source, false, ' ', ' ', out value, out bytesConsumed);
- case 'B':
- return TryParseGuidCore(source, true, '{', '}', out value, out bytesConsumed);
- case 'P':
- return TryParseGuidCore(source, true, '(', ')', out value, out bytesConsumed);
- case 'N':
- return TryParseGuidN(source, out value, out bytesConsumed);
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
- }
-
- // nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn (not very Guid-like, but the format is what it is...)
- private static bool TryParseGuidN(ReadOnlySpan<byte> text, out Guid value, out int bytesConsumed)
- {
- if (text.Length < 32)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- if (!TryParseUInt32X(text.Slice(0, 8), out uint i1, out int justConsumed) || justConsumed != 8)
- {
- value = default;
- bytesConsumed = 0;
- return false; // 8 digits
- }
-
- if (!TryParseUInt16X(text.Slice(8, 4), out ushort i2, out justConsumed) || justConsumed != 4)
- {
- value = default;
- bytesConsumed = 0;
- return false; // next 4 digits
- }
-
- if (!TryParseUInt16X(text.Slice(12, 4), out ushort i3, out justConsumed) || justConsumed != 4)
- {
- value = default;
- bytesConsumed = 0;
- return false; // next 4 digits
- }
-
- if (!TryParseUInt16X(text.Slice(16, 4), out ushort i4, out justConsumed) || justConsumed != 4)
- {
- value = default;
- bytesConsumed = 0;
- return false; // next 4 digits
- }
-
- if (!TryParseUInt64X(text.Slice(20), out ulong i5, out justConsumed) || justConsumed != 12)
- {
- value = default;
- bytesConsumed = 0;
- return false; // next 4 digits
- }
-
- bytesConsumed = 32;
- value = new Guid((int)i1, (short)i2, (short)i3, (byte)(i4 >> 8), (byte)i4,
- (byte)(i5 >> 40), (byte)(i5 >> 32), (byte)(i5 >> 24), (byte)(i5 >> 16), (byte)(i5 >> 8), (byte)i5);
- return true;
- }
-
- // {8-4-4-4-12}, where number is the number of hex digits, and {/} are ends.
- private static bool TryParseGuidCore(ReadOnlySpan<byte> source, bool ends, char begin, char end, out Guid value, out int bytesConsumed)
- {
- int expectedCodingUnits = 36 + (ends ? 2 : 0); // 32 hex digits + 4 delimiters + 2 optional ends
-
- if (source.Length < expectedCodingUnits)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- if (ends)
- {
- if (source[0] != begin)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- source = source.Slice(1); // skip begining
- }
-
- if (!TryParseUInt32X(source, out uint i1, out int justConsumed))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- if (justConsumed != 8)
- {
- value = default;
- bytesConsumed = 0;
- return false; // 8 digits
- }
-
- if (source[justConsumed] != '-')
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- source = source.Slice(9); // justConsumed + 1 for delimiter
-
- if (!TryParseUInt16X(source, out ushort i2, out justConsumed))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- if (justConsumed != 4)
- {
- value = default;
- bytesConsumed = 0;
- return false; // 4 digits
- }
-
- if (source[justConsumed] != '-')
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- source = source.Slice(5); // justConsumed + 1 for delimiter
-
- if (!TryParseUInt16X(source, out ushort i3, out justConsumed))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- if (justConsumed != 4)
- {
- value = default;
- bytesConsumed = 0;
- return false; // 4 digits
- }
-
- if (source[justConsumed] != '-')
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- source = source.Slice(5); // justConsumed + 1 for delimiter
-
- if (!TryParseUInt16X(source, out ushort i4, out justConsumed))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- if (justConsumed != 4)
- {
- value = default;
- bytesConsumed = 0;
- return false; // 4 digits
- }
-
- if (source[justConsumed] != '-')
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- source = source.Slice(5); // justConsumed + 1 for delimiter
-
- if (!TryParseUInt64X(source, out ulong i5, out justConsumed))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- if (justConsumed != 12)
- {
- value = default;
- bytesConsumed = 0;
- return false; // 12 digits
- }
-
- if (ends && source[justConsumed] != end)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- bytesConsumed = expectedCodingUnits;
- value = new Guid((int)i1, (short)i2, (short)i3, (byte)(i4 >> 8), (byte)i4,
- (byte)(i5 >> 40), (byte)(i5 >> 32), (byte)(i5 >> 24), (byte)(i5 >> 16), (byte)(i5 >> 8), (byte)i5);
-
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.D.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.D.cs
deleted file mode 100644
index bf1871a1c94..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.D.cs
+++ /dev/null
@@ -1,443 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- private static bool TryParseSByteD(ReadOnlySpan<byte> source, out sbyte value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int sign = 1;
- int index = 0;
- int num = source[index];
- if (num == '-')
- {
- sign = -1;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- num = source[index];
- }
- else if (num == '+')
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- num = source[index];
- }
-
- int answer = 0;
-
- if (ParserHelpers.IsDigit(num))
- {
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- } while (num == '0');
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- }
-
- answer = num - '0';
- index++;
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- // Potential overflow
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = answer * 10 + num - '0';
- // if sign < 0, (-1 * sign + 1) / 2 = 1
- // else, (-1 * sign + 1) / 2 = 0
- if ((uint)answer > (uint)sbyte.MaxValue + (-1 * sign + 1) / 2)
- goto FalseExit; // Overflow
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- if (!ParserHelpers.IsDigit(source[index]))
- goto Done;
-
- // Guaranteed overflow
- goto FalseExit;
- }
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = (sbyte)(answer * sign);
- return true;
- }
-
- private static bool TryParseInt16D(ReadOnlySpan<byte> source, out short value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int sign = 1;
- int index = 0;
- int num = source[index];
- if (num == '-')
- {
- sign = -1;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- num = source[index];
- }
- else if (num == '+')
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- num = source[index];
- }
-
- int answer = 0;
-
- if (ParserHelpers.IsDigit(num))
- {
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- } while (num == '0');
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- }
-
- answer = num - '0';
- index++;
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- // Potential overflow
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = answer * 10 + num - '0';
- // if sign < 0, (-1 * sign + 1) / 2 = 1
- // else, (-1 * sign + 1) / 2 = 0
- if ((uint)answer > (uint)short.MaxValue + (-1 * sign + 1) / 2)
- goto FalseExit; // Overflow
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- if (!ParserHelpers.IsDigit(source[index]))
- goto Done;
-
- // Guaranteed overflow
- goto FalseExit;
- }
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = (short)(answer * sign);
- return true;
- }
-
- private static bool TryParseInt32D(ReadOnlySpan<byte> source, out int value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int sign = 1;
- int index = 0;
- int num = source[index];
- if (num == '-')
- {
- sign = -1;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- num = source[index];
- }
- else if (num == '+')
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- num = source[index];
- }
-
- int answer = 0;
-
- if (ParserHelpers.IsDigit(num))
- {
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- } while (num == '0');
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- }
-
- answer = num - '0';
- index++;
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- // Potential overflow
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- if (answer > int.MaxValue / 10)
- goto FalseExit; // Overflow
- answer = answer * 10 + num - '0';
- // if sign < 0, (-1 * sign + 1) / 2 = 1
- // else, (-1 * sign + 1) / 2 = 0
- if ((uint)answer > (uint)int.MaxValue + (-1 * sign + 1) / 2)
- goto FalseExit; // Overflow
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- if (!ParserHelpers.IsDigit(source[index]))
- goto Done;
-
- // Guaranteed overflow
- goto FalseExit;
- }
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = answer * sign;
- return true;
- }
-
- private static bool TryParseInt64D(ReadOnlySpan<byte> source, out long value, out int bytesConsumed)
- {
- if (source.Length < 1)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
-
- int indexOfFirstDigit = 0;
- int sign = 1;
- if (source[0] == '-')
- {
- indexOfFirstDigit = 1;
- sign = -1;
-
- if (source.Length <= indexOfFirstDigit)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- }
- else if (source[0] == '+')
- {
- indexOfFirstDigit = 1;
-
- if (source.Length <= indexOfFirstDigit)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- }
-
- int overflowLength = ParserHelpers.Int64OverflowLength + indexOfFirstDigit;
-
- // Parse the first digit separately. If invalid here, we need to return false.
- long firstDigit = source[indexOfFirstDigit] - 48; // '0'
- if (firstDigit < 0 || firstDigit > 9)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- ulong parsedValue = (ulong)firstDigit;
-
- if (source.Length < overflowLength)
- {
- // Length is less than Parsers.Int64OverflowLength; overflow is not possible
- for (int index = indexOfFirstDigit + 1; index < source.Length; index++)
- {
- long nextDigit = source[index] - 48; // '0'
- if (nextDigit < 0 || nextDigit > 9)
- {
- bytesConsumed = index;
- value = ((long)parsedValue) * sign;
- return true;
- }
- parsedValue = parsedValue * 10 + (ulong)nextDigit;
- }
- }
- else
- {
- // Length is greater than Parsers.Int64OverflowLength; overflow is only possible after Parsers.Int64OverflowLength
- // digits. There may be no overflow after Parsers.Int64OverflowLength if there are leading zeroes.
- for (int index = indexOfFirstDigit + 1; index < overflowLength - 1; index++)
- {
- long nextDigit = source[index] - 48; // '0'
- if (nextDigit < 0 || nextDigit > 9)
- {
- bytesConsumed = index;
- value = ((long)parsedValue) * sign;
- return true;
- }
- parsedValue = parsedValue * 10 + (ulong)nextDigit;
- }
- for (int index = overflowLength - 1; index < source.Length; index++)
- {
- long nextDigit = source[index] - 48; // '0'
- if (nextDigit < 0 || nextDigit > 9)
- {
- bytesConsumed = index;
- value = ((long)parsedValue) * sign;
- return true;
- }
- // If parsedValue > (long.MaxValue / 10), any more appended digits will cause overflow.
- // if parsedValue == (long.MaxValue / 10), any nextDigit greater than 7 or 8 (depending on sign) implies overflow.
- bool positive = sign > 0;
- bool nextDigitTooLarge = nextDigit > 8 || (positive && nextDigit > 7);
- if (parsedValue > long.MaxValue / 10 || parsedValue == long.MaxValue / 10 && nextDigitTooLarge)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- parsedValue = parsedValue * 10 + (ulong)nextDigit;
- }
- }
-
- bytesConsumed = source.Length;
- value = ((long)parsedValue) * sign;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.N.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.N.cs
deleted file mode 100644
index 10f33f692ee..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.N.cs
+++ /dev/null
@@ -1,383 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- private static bool TryParseSByteN(ReadOnlySpan<byte> source, out sbyte value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int sign = 1;
- int index = 0;
- int c = source[index];
- if (c == '-')
- {
- sign = -1;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
- else if (c == '+')
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
-
- int answer;
-
- // Handle the first digit (or period) as a special case. This ensures some compatible edge-case behavior with the classic parse routines
- // (at least one digit must precede any commas, and a string without any digits prior to the decimal point must have at least
- // one digit after the decimal point.)
- if (c == Utf8Constants.Period)
- goto FractionalPartWithoutLeadingDigits;
- if (!ParserHelpers.IsDigit(c))
- goto FalseExit;
- answer = c - '0';
-
- while (true)
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
-
- c = source[index];
- if (c == Utf8Constants.Comma)
- continue;
-
- if (c == Utf8Constants.Period)
- goto FractionalDigits;
-
- if (!ParserHelpers.IsDigit(c))
- goto Done;
-
- answer = answer * 10 + c - '0';
-
- // if sign < 0, (-1 * sign + 1) / 2 = 1
- // else, (-1 * sign + 1) / 2 = 0
- if (answer > sbyte.MaxValue + (-1 * sign + 1) / 2)
- goto FalseExit; // Overflow
- }
-
- FractionalPartWithoutLeadingDigits: // If we got here, we found a decimal point before we found any digits. This is legal as long as there's at least one zero after the decimal point.
- answer = 0;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- if (source[index] != '0')
- goto FalseExit;
-
- FractionalDigits: // "N" format allows a fractional portion despite being an integer format but only if the post-fraction digits are all 0.
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- c = source[index];
- }
- while (c == '0');
-
- if (ParserHelpers.IsDigit(c))
- goto FalseExit; // The fractional portion contained a non-zero digit. Treat this as an error, not an early termination.
- goto Done;
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = (sbyte)(answer * sign);
- return true;
- }
-
- private static bool TryParseInt16N(ReadOnlySpan<byte> source, out short value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int sign = 1;
- int index = 0;
- int c = source[index];
- if (c == '-')
- {
- sign = -1;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
- else if (c == '+')
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
-
- int answer;
-
- // Handle the first digit (or period) as a special case. This ensures some compatible edge-case behavior with the classic parse routines
- // (at least one digit must precede any commas, and a string without any digits prior to the decimal point must have at least
- // one digit after the decimal point.)
- if (c == Utf8Constants.Period)
- goto FractionalPartWithoutLeadingDigits;
- if (!ParserHelpers.IsDigit(c))
- goto FalseExit;
- answer = c - '0';
-
- while (true)
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
-
- c = source[index];
- if (c == Utf8Constants.Comma)
- continue;
-
- if (c == Utf8Constants.Period)
- goto FractionalDigits;
-
- if (!ParserHelpers.IsDigit(c))
- goto Done;
-
- answer = answer * 10 + c - '0';
-
- // if sign < 0, (-1 * sign + 1) / 2 = 1
- // else, (-1 * sign + 1) / 2 = 0
- if (answer > short.MaxValue + (-1 * sign + 1) / 2)
- goto FalseExit; // Overflow
- }
-
- FractionalPartWithoutLeadingDigits: // If we got here, we found a decimal point before we found any digits. This is legal as long as there's at least one zero after the decimal point.
- answer = 0;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- if (source[index] != '0')
- goto FalseExit;
-
- FractionalDigits: // "N" format allows a fractional portion despite being an integer format but only if the post-fraction digits are all 0.
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- c = source[index];
- }
- while (c == '0');
-
- if (ParserHelpers.IsDigit(c))
- goto FalseExit; // The fractional portion contained a non-zero digit. Treat this as an error, not an early termination.
- goto Done;
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = (short)(answer * sign);
- return true;
- }
-
- private static bool TryParseInt32N(ReadOnlySpan<byte> source, out int value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int sign = 1;
- int index = 0;
- int c = source[index];
- if (c == '-')
- {
- sign = -1;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
- else if (c == '+')
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
-
- int answer;
-
- // Handle the first digit (or period) as a special case. This ensures some compatible edge-case behavior with the classic parse routines
- // (at least one digit must precede any commas, and a string without any digits prior to the decimal point must have at least
- // one digit after the decimal point.)
- if (c == Utf8Constants.Period)
- goto FractionalPartWithoutLeadingDigits;
- if (!ParserHelpers.IsDigit(c))
- goto FalseExit;
- answer = c - '0';
-
- while (true)
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
-
- c = source[index];
- if (c == Utf8Constants.Comma)
- continue;
-
- if (c == Utf8Constants.Period)
- goto FractionalDigits;
-
- if (!ParserHelpers.IsDigit(c))
- goto Done;
-
- if (((uint)answer) > int.MaxValue / 10)
- goto FalseExit;
-
- answer = answer * 10 + c - '0';
-
- // if sign < 0, (-1 * sign + 1) / 2 = 1
- // else, (-1 * sign + 1) / 2 = 0
- if ((uint)answer > (uint)int.MaxValue + (-1 * sign + 1) / 2)
- goto FalseExit; // Overflow
- }
-
- FractionalPartWithoutLeadingDigits: // If we got here, we found a decimal point before we found any digits. This is legal as long as there's at least one zero after the decimal point.
- answer = 0;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- if (source[index] != '0')
- goto FalseExit;
-
- FractionalDigits: // "N" format allows a fractional portion despite being an integer format but only if the post-fraction digits are all 0.
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- c = source[index];
- }
- while (c == '0');
-
- if (ParserHelpers.IsDigit(c))
- goto FalseExit; // The fractional portion contained a non-zero digit. Treat this as an error, not an early termination.
- goto Done;
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = answer * sign;
- return true;
- }
-
- private static bool TryParseInt64N(ReadOnlySpan<byte> source, out long value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int sign = 1;
- int index = 0;
- int c = source[index];
- if (c == '-')
- {
- sign = -1;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
- else if (c == '+')
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
-
- long answer;
-
- // Handle the first digit (or period) as a special case. This ensures some compatible edge-case behavior with the classic parse routines
- // (at least one digit must precede any commas, and a string without any digits prior to the decimal point must have at least
- // one digit after the decimal point.)
- if (c == Utf8Constants.Period)
- goto FractionalPartWithoutLeadingDigits;
- if (!ParserHelpers.IsDigit(c))
- goto FalseExit;
- answer = c - '0';
-
- while (true)
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
-
- c = source[index];
- if (c == Utf8Constants.Comma)
- continue;
-
- if (c == Utf8Constants.Period)
- goto FractionalDigits;
-
- if (!ParserHelpers.IsDigit(c))
- goto Done;
-
- if (((ulong)answer) > long.MaxValue / 10)
- goto FalseExit;
-
- answer = answer * 10 + c - '0';
-
- // if sign < 0, (-1 * sign + 1) / 2 = 1
- // else, (-1 * sign + 1) / 2 = 0
- if ((ulong)answer > (ulong)(long.MaxValue + (-1 * sign + 1) / 2))
- goto FalseExit; // Overflow
- }
-
- FractionalPartWithoutLeadingDigits: // If we got here, we found a decimal point before we found any digits. This is legal as long as there's at least one zero after the decimal point.
- answer = 0;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- if (source[index] != '0')
- goto FalseExit;
-
- FractionalDigits: // "N" format allows a fractional portion despite being an integer format but only if the post-fraction digits are all 0.
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- c = source[index];
- }
- while (c == '0');
-
- if (ParserHelpers.IsDigit(c))
- goto FalseExit; // The fractional portion contained a non-zero digit. Treat this as an error, not an early termination.
- goto Done;
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = answer * sign;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.cs
deleted file mode 100644
index d6cc01b8a70..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Signed.cs
+++ /dev/null
@@ -1,199 +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 Internal.Runtime.CompilerServices;
-
-namespace System.Buffers.Text
-{
- /// <summary>
- /// Methods to parse common data types to Utf8 strings.
- /// </summary>
- public static partial class Utf8Parser
- {
- /// <summary>
- /// Parses a SByte at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<byte> source, out sbyte value, out int bytesConsumed, char standardFormat = default)
- {
- switch (standardFormat)
- {
- case default(char):
- case 'g':
- case 'G':
- case 'd':
- case 'D':
- return TryParseSByteD(source, out value, out bytesConsumed);
-
- case 'n':
- case 'N':
- return TryParseSByteN(source, out value, out bytesConsumed);
-
- case 'x':
- case 'X':
- value = default;
- return TryParseByteX(source, out Unsafe.As<sbyte, byte>(ref value), out bytesConsumed);
-
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
- }
-
- /// <summary>
- /// Parses an Int16 at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryParse(ReadOnlySpan<byte> source, out short value, out int bytesConsumed, char standardFormat = default)
- {
- switch (standardFormat)
- {
- case default(char):
- case 'g':
- case 'G':
- case 'd':
- case 'D':
- return TryParseInt16D(source, out value, out bytesConsumed);
-
- case 'n':
- case 'N':
- return TryParseInt16N(source, out value, out bytesConsumed);
-
- case 'x':
- case 'X':
- value = default;
- return TryParseUInt16X(source, out Unsafe.As<short, ushort>(ref value), out bytesConsumed);
-
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
- }
-
- /// <summary>
- /// Parses an Int32 at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryParse(ReadOnlySpan<byte> source, out int value, out int bytesConsumed, char standardFormat = default)
- {
- switch (standardFormat)
- {
- case default(char):
- case 'g':
- case 'G':
- case 'd':
- case 'D':
- return TryParseInt32D(source, out value, out bytesConsumed);
-
- case 'n':
- case 'N':
- return TryParseInt32N(source, out value, out bytesConsumed);
-
- case 'x':
- case 'X':
- value = default;
- return TryParseUInt32X(source, out Unsafe.As<int, uint>(ref value), out bytesConsumed);
-
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
- }
-
- /// <summary>
- /// Parses an Int64 at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryParse(ReadOnlySpan<byte> source, out long value, out int bytesConsumed, char standardFormat = default)
- {
- switch (standardFormat)
- {
- case default(char):
- case 'g':
- case 'G':
- case 'd':
- case 'D':
- return TryParseInt64D(source, out value, out bytesConsumed);
-
- case 'n':
- case 'N':
- return TryParseInt64N(source, out value, out bytesConsumed);
-
- case 'x':
- case 'X':
- value = default;
- return TryParseUInt64X(source, out Unsafe.As<long, ulong>(ref value), out bytesConsumed);
-
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.D.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.D.cs
deleted file mode 100644
index 46753f5c57d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.D.cs
+++ /dev/null
@@ -1,354 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- private static bool TryParseByteD(ReadOnlySpan<byte> source, out byte value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int index = 0;
- int num = source[index];
- int answer = 0;
-
- if (ParserHelpers.IsDigit(num))
- {
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- } while (num == '0');
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- }
-
- answer = num - '0';
- index++;
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- // Potential overflow
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = answer * 10 + num - '0';
- if ((uint)answer > byte.MaxValue)
- goto FalseExit; // Overflow
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- if (!ParserHelpers.IsDigit(source[index]))
- goto Done;
-
- // Guaranteed overflow
- goto FalseExit;
- }
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = (byte)answer;
- return true;
- }
-
- private static bool TryParseUInt16D(ReadOnlySpan<byte> source, out ushort value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int index = 0;
- int num = source[index];
- int answer = 0;
-
- if (ParserHelpers.IsDigit(num))
- {
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- } while (num == '0');
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- }
-
- answer = num - '0';
- index++;
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- // Potential overflow
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = answer * 10 + num - '0';
- if ((uint)answer > ushort.MaxValue)
- goto FalseExit; // Overflow
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- if (!ParserHelpers.IsDigit(source[index]))
- goto Done;
-
- // Guaranteed overflow
- goto FalseExit;
- }
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = (ushort)answer;
- return true;
- }
-
- private static bool TryParseUInt32D(ReadOnlySpan<byte> source, out uint value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int index = 0;
- int num = source[index];
- int answer = 0;
-
- if (ParserHelpers.IsDigit(num))
- {
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- } while (num == '0');
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- }
-
- answer = num - '0';
- index++;
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- answer = 10 * answer + num - '0';
-
- // Potential overflow
- if ((uint)index >= (uint)source.Length)
- goto Done;
- num = source[index];
- if (!ParserHelpers.IsDigit(num))
- goto Done;
- index++;
- if (((uint)answer) > uint.MaxValue / 10 || (((uint)answer) == uint.MaxValue / 10 && num > '5'))
- goto FalseExit; // Overflow
- answer = answer * 10 + num - '0';
-
- if ((uint)index >= (uint)source.Length)
- goto Done;
- if (!ParserHelpers.IsDigit(source[index]))
- goto Done;
-
- // Guaranteed overflow
- goto FalseExit;
- }
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = (uint)answer;
- return true;
- }
-
- private static bool TryParseUInt64D(ReadOnlySpan<byte> source, out ulong value, out int bytesConsumed)
- {
- if (source.Length < 1)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
-
- // Parse the first digit separately. If invalid here, we need to return false.
- ulong firstDigit = source[0] - 48u; // '0'
- if (firstDigit > 9)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- ulong parsedValue = firstDigit;
-
- if (source.Length < ParserHelpers.Int64OverflowLength)
- {
- // Length is less than Parsers.Int64OverflowLength; overflow is not possible
- for (int index = 1; index < source.Length; index++)
- {
- ulong nextDigit = source[index] - 48u; // '0'
- if (nextDigit > 9)
- {
- bytesConsumed = index;
- value = parsedValue;
- return true;
- }
- parsedValue = parsedValue * 10 + nextDigit;
- }
- }
- else
- {
- // Length is greater than Parsers.Int64OverflowLength; overflow is only possible after Parsers.Int64OverflowLength
- // digits. There may be no overflow after Parsers.Int64OverflowLength if there are leading zeroes.
- for (int index = 1; index < ParserHelpers.Int64OverflowLength - 1; index++)
- {
- ulong nextDigit = source[index] - 48u; // '0'
- if (nextDigit > 9)
- {
- bytesConsumed = index;
- value = parsedValue;
- return true;
- }
- parsedValue = parsedValue * 10 + nextDigit;
- }
- for (int index = ParserHelpers.Int64OverflowLength - 1; index < source.Length; index++)
- {
- ulong nextDigit = source[index] - 48u; // '0'
- if (nextDigit > 9)
- {
- bytesConsumed = index;
- value = parsedValue;
- return true;
- }
- // If parsedValue > (ulong.MaxValue / 10), any more appended digits will cause overflow.
- // if parsedValue == (ulong.MaxValue / 10), any nextDigit greater than 5 implies overflow.
- if (parsedValue > ulong.MaxValue / 10 || (parsedValue == ulong.MaxValue / 10 && nextDigit > 5))
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- parsedValue = parsedValue * 10 + nextDigit;
- }
- }
-
- bytesConsumed = source.Length;
- value = parsedValue;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.N.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.N.cs
deleted file mode 100644
index 6fa38ebfe3b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.N.cs
+++ /dev/null
@@ -1,336 +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.
-
-namespace System.Buffers.Text
-{
- //
- // Parsing unsigned integers for the 'N' format. Emulating int.TryParse(NumberStyles.AllowThousands | NumberStyles.Integer | NumberStyles.AllowDecimalPoint)
- //
- public static partial class Utf8Parser
- {
- private static bool TryParseByteN(ReadOnlySpan<byte> source, out byte value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int index = 0;
- int c = source[index];
- if (c == '+')
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
-
- int answer;
-
- // Handle the first digit (or period) as a special case. This ensures some compatible edge-case behavior with the classic parse routines
- // (at least one digit must precede any commas, and a string without any digits prior to the decimal point must have at least
- // one digit after the decimal point.)
- if (c == Utf8Constants.Period)
- goto FractionalPartWithoutLeadingDigits;
- if (!ParserHelpers.IsDigit(c))
- goto FalseExit;
- answer = c - '0';
-
- while (true)
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
-
- c = source[index];
- if (c == Utf8Constants.Comma)
- continue;
-
- if (c == Utf8Constants.Period)
- goto FractionalDigits;
-
- if (!ParserHelpers.IsDigit(c))
- goto Done;
-
- answer = answer * 10 + c - '0';
-
- if (answer > byte.MaxValue)
- goto FalseExit; // Overflow
- }
-
- FractionalPartWithoutLeadingDigits: // If we got here, we found a decimal point before we found any digits. This is legal as long as there's at least one zero after the decimal point.
- answer = 0;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- if (source[index] != '0')
- goto FalseExit;
-
- FractionalDigits: // "N" format allows a fractional portion despite being an integer format but only if the post-fraction digits are all 0.
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- c = source[index];
- }
- while (c == '0');
-
- if (ParserHelpers.IsDigit(c))
- goto FalseExit; // The fractional portion contained a non-zero digit. Treat this as an error, not an early termination.
- goto Done;
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = (byte)answer;
- return true;
- }
-
- private static bool TryParseUInt16N(ReadOnlySpan<byte> source, out ushort value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int index = 0;
- int c = source[index];
- if (c == '+')
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
-
- int answer;
-
- // Handle the first digit (or period) as a special case. This ensures some compatible edge-case behavior with the classic parse routines
- // (at least one digit must precede any commas, and a string without any digits prior to the decimal point must have at least
- // one digit after the decimal point.)
- if (c == Utf8Constants.Period)
- goto FractionalPartWithoutLeadingDigits;
- if (!ParserHelpers.IsDigit(c))
- goto FalseExit;
- answer = c - '0';
-
- while (true)
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
-
- c = source[index];
- if (c == Utf8Constants.Comma)
- continue;
-
- if (c == Utf8Constants.Period)
- goto FractionalDigits;
-
- if (!ParserHelpers.IsDigit(c))
- goto Done;
-
- answer = answer * 10 + c - '0';
-
- if (answer > ushort.MaxValue)
- goto FalseExit; // Overflow
- }
-
- FractionalPartWithoutLeadingDigits: // If we got here, we found a decimal point before we found any digits. This is legal as long as there's at least one zero after the decimal point.
- answer = 0;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- if (source[index] != '0')
- goto FalseExit;
-
- FractionalDigits: // "N" format allows a fractional portion despite being an integer format but only if the post-fraction digits are all 0.
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- c = source[index];
- }
- while (c == '0');
-
- if (ParserHelpers.IsDigit(c))
- goto FalseExit; // The fractional portion contained a non-zero digit. Treat this as an error, not an early termination.
- goto Done;
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = (ushort)answer;
- return true;
- }
-
- private static bool TryParseUInt32N(ReadOnlySpan<byte> source, out uint value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int index = 0;
- int c = source[index];
- if (c == '+')
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
-
- int answer;
-
- // Handle the first digit (or period) as a special case. This ensures some compatible edge-case behavior with the classic parse routines
- // (at least one digit must precede any commas, and a string without any digits prior to the decimal point must have at least
- // one digit after the decimal point.)
- if (c == Utf8Constants.Period)
- goto FractionalPartWithoutLeadingDigits;
- if (!ParserHelpers.IsDigit(c))
- goto FalseExit;
- answer = c - '0';
-
- while (true)
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
-
- c = source[index];
- if (c == Utf8Constants.Comma)
- continue;
-
- if (c == Utf8Constants.Period)
- goto FractionalDigits;
-
- if (!ParserHelpers.IsDigit(c))
- goto Done;
-
- if (((uint)answer) > uint.MaxValue / 10 || (((uint)answer) == uint.MaxValue / 10 && c > '5'))
- goto FalseExit; // Overflow
-
- answer = answer * 10 + c - '0';
- }
-
- FractionalPartWithoutLeadingDigits: // If we got here, we found a decimal point before we found any digits. This is legal as long as there's at least one zero after the decimal point.
- answer = 0;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- if (source[index] != '0')
- goto FalseExit;
-
- FractionalDigits: // "N" format allows a fractional portion despite being an integer format but only if the post-fraction digits are all 0.
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- c = source[index];
- }
- while (c == '0');
-
- if (ParserHelpers.IsDigit(c))
- goto FalseExit; // The fractional portion contained a non-zero digit. Treat this as an error, not an early termination.
- goto Done;
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = (uint)answer;
- return true;
- }
-
- private static bool TryParseUInt64N(ReadOnlySpan<byte> source, out ulong value, out int bytesConsumed)
- {
- if (source.Length < 1)
- goto FalseExit;
-
- int index = 0;
- int c = source[index];
- if (c == '+')
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- c = source[index];
- }
-
- long answer;
-
- // Handle the first digit (or period) as a special case. This ensures some compatible edge-case behavior with the classic parse routines
- // (at least one digit must precede any commas, and a string without any digits prior to the decimal point must have at least
- // one digit after the decimal point.)
- if (c == Utf8Constants.Period)
- goto FractionalPartWithoutLeadingDigits;
- if (!ParserHelpers.IsDigit(c))
- goto FalseExit;
- answer = c - '0';
-
- while (true)
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
-
- c = source[index];
- if (c == Utf8Constants.Comma)
- continue;
-
- if (c == Utf8Constants.Period)
- goto FractionalDigits;
-
- if (!ParserHelpers.IsDigit(c))
- goto Done;
-
- if (((ulong)answer) > ulong.MaxValue / 10 || (((ulong)answer) == ulong.MaxValue / 10 && c > '5'))
- goto FalseExit; // Overflow
-
- answer = answer * 10 + c - '0';
- }
-
- FractionalPartWithoutLeadingDigits: // If we got here, we found a decimal point before we found any digits. This is legal as long as there's at least one zero after the decimal point.
- answer = 0;
- index++;
- if ((uint)index >= (uint)source.Length)
- goto FalseExit;
- if (source[index] != '0')
- goto FalseExit;
-
- FractionalDigits: // "N" format allows a fractional portion despite being an integer format but only if the post-fraction digits are all 0.
- do
- {
- index++;
- if ((uint)index >= (uint)source.Length)
- goto Done;
- c = source[index];
- }
- while (c == '0');
-
- if (ParserHelpers.IsDigit(c))
- goto FalseExit; // The fractional portion contained a non-zero digit. Treat this as an error, not an early termination.
- goto Done;
-
- FalseExit:
- bytesConsumed = default;
- value = default;
- return false;
-
- Done:
- bytesConsumed = index;
- value = (ulong)answer;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.X.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.X.cs
deleted file mode 100644
index 1d07e9ef7de..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.X.cs
+++ /dev/null
@@ -1,341 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- private static bool TryParseByteX(ReadOnlySpan<byte> source, out byte value, out int bytesConsumed)
- {
- if (source.Length < 1)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- byte nextCharacter;
- byte nextDigit;
-
- // Cache Parsers.s_HexLookup in order to avoid static constructor checks
- ReadOnlySpan<byte> hexLookup = ParserHelpers.HexLookup;
-
- // Parse the first digit separately. If invalid here, we need to return false.
- nextCharacter = source[0];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- uint parsedValue = nextDigit;
-
- if (source.Length <= ParserHelpers.ByteOverflowLengthHex)
- {
- // Length is less than or equal to Parsers.ByteOverflowLengthHex; overflow is not possible
- for (int index = 1; index < source.Length; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = (byte)(parsedValue);
- return true;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- }
- else
- {
- // Length is greater than Parsers.ByteOverflowLengthHex; overflow is only possible after Parsers.ByteOverflowLengthHex
- // digits. There may be no overflow after Parsers.ByteOverflowLengthHex if there are leading zeroes.
- for (int index = 1; index < ParserHelpers.ByteOverflowLengthHex; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = (byte)(parsedValue);
- return true;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- for (int index = ParserHelpers.ByteOverflowLengthHex; index < source.Length; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = (byte)(parsedValue);
- return true;
- }
- // If we try to append a digit to anything larger than byte.MaxValue / 0x10, there will be overflow
- if (parsedValue > byte.MaxValue / 0x10)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- }
-
- bytesConsumed = source.Length;
- value = (byte)(parsedValue);
- return true;
- }
-
- private static bool TryParseUInt16X(ReadOnlySpan<byte> source, out ushort value, out int bytesConsumed)
- {
- if (source.Length < 1)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- byte nextCharacter;
- byte nextDigit;
-
- // Cache Parsers.s_HexLookup in order to avoid static constructor checks
- ReadOnlySpan<byte> hexLookup = ParserHelpers.HexLookup;
-
- // Parse the first digit separately. If invalid here, we need to return false.
- nextCharacter = source[0];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- uint parsedValue = nextDigit;
-
- if (source.Length <= ParserHelpers.Int16OverflowLengthHex)
- {
- // Length is less than or equal to Parsers.Int16OverflowLengthHex; overflow is not possible
- for (int index = 1; index < source.Length; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = (ushort)(parsedValue);
- return true;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- }
- else
- {
- // Length is greater than Parsers.Int16OverflowLengthHex; overflow is only possible after Parsers.Int16OverflowLengthHex
- // digits. There may be no overflow after Parsers.Int16OverflowLengthHex if there are leading zeroes.
- for (int index = 1; index < ParserHelpers.Int16OverflowLengthHex; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = (ushort)(parsedValue);
- return true;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- for (int index = ParserHelpers.Int16OverflowLengthHex; index < source.Length; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = (ushort)(parsedValue);
- return true;
- }
- // If we try to append a digit to anything larger than ushort.MaxValue / 0x10, there will be overflow
- if (parsedValue > ushort.MaxValue / 0x10)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- }
-
- bytesConsumed = source.Length;
- value = (ushort)(parsedValue);
- return true;
- }
-
- private static bool TryParseUInt32X(ReadOnlySpan<byte> source, out uint value, out int bytesConsumed)
- {
- if (source.Length < 1)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- byte nextCharacter;
- byte nextDigit;
-
- // Cache Parsers.s_HexLookup in order to avoid static constructor checks
- ReadOnlySpan<byte> hexLookup = ParserHelpers.HexLookup;
-
- // Parse the first digit separately. If invalid here, we need to return false.
- nextCharacter = source[0];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- uint parsedValue = nextDigit;
-
- if (source.Length <= ParserHelpers.Int32OverflowLengthHex)
- {
- // Length is less than or equal to Parsers.Int32OverflowLengthHex; overflow is not possible
- for (int index = 1; index < source.Length; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = parsedValue;
- return true;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- }
- else
- {
- // Length is greater than Parsers.Int32OverflowLengthHex; overflow is only possible after Parsers.Int32OverflowLengthHex
- // digits. There may be no overflow after Parsers.Int32OverflowLengthHex if there are leading zeroes.
- for (int index = 1; index < ParserHelpers.Int32OverflowLengthHex; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = parsedValue;
- return true;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- for (int index = ParserHelpers.Int32OverflowLengthHex; index < source.Length; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = parsedValue;
- return true;
- }
- // If we try to append a digit to anything larger than uint.MaxValue / 0x10, there will be overflow
- if (parsedValue > uint.MaxValue / 0x10)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- }
-
- bytesConsumed = source.Length;
- value = parsedValue;
- return true;
- }
-
- private static bool TryParseUInt64X(ReadOnlySpan<byte> source, out ulong value, out int bytesConsumed)
- {
- if (source.Length < 1)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- byte nextCharacter;
- byte nextDigit;
-
- // Cache Parsers.s_HexLookup in order to avoid static constructor checks
- ReadOnlySpan<byte> hexLookup = ParserHelpers.HexLookup;
-
- // Parse the first digit separately. If invalid here, we need to return false.
- nextCharacter = source[0];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- ulong parsedValue = nextDigit;
-
- if (source.Length <= ParserHelpers.Int64OverflowLengthHex)
- {
- // Length is less than or equal to Parsers.Int64OverflowLengthHex; overflow is not possible
- for (int index = 1; index < source.Length; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = parsedValue;
- return true;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- }
- else
- {
- // Length is greater than Parsers.Int64OverflowLengthHex; overflow is only possible after Parsers.Int64OverflowLengthHex
- // digits. There may be no overflow after Parsers.Int64OverflowLengthHex if there are leading zeroes.
- for (int index = 1; index < ParserHelpers.Int64OverflowLengthHex; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = parsedValue;
- return true;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- for (int index = ParserHelpers.Int64OverflowLengthHex; index < source.Length; index++)
- {
- nextCharacter = source[index];
- nextDigit = hexLookup[nextCharacter];
- if (nextDigit == 0xFF)
- {
- bytesConsumed = index;
- value = parsedValue;
- return true;
- }
- // If we try to append a digit to anything larger than ulong.MaxValue / 0x10, there will be overflow
- if (parsedValue > ulong.MaxValue / 0x10)
- {
- bytesConsumed = 0;
- value = default;
- return false;
- }
- parsedValue = (parsedValue << 4) + nextDigit;
- }
- }
-
- bytesConsumed = source.Length;
- value = parsedValue;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.cs
deleted file mode 100644
index 476889c1fb0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Integer.Unsigned.cs
+++ /dev/null
@@ -1,192 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- /// <summary>
- /// Parses a Byte at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryParse(ReadOnlySpan<byte> source, out byte value, out int bytesConsumed, char standardFormat = default)
- {
- switch (standardFormat)
- {
- case default(char):
- case 'g':
- case 'G':
- case 'd':
- case 'D':
- return TryParseByteD(source, out value, out bytesConsumed);
-
- case 'n':
- case 'N':
- return TryParseByteN(source, out value, out bytesConsumed);
-
- case 'x':
- case 'X':
- return TryParseByteX(source, out value, out bytesConsumed);
-
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
- }
-
- /// <summary>
- /// Parses a UInt16 at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<byte> source, out ushort value, out int bytesConsumed, char standardFormat = default)
- {
- switch (standardFormat)
- {
- case default(char):
- case 'g':
- case 'G':
- case 'd':
- case 'D':
- return TryParseUInt16D(source, out value, out bytesConsumed);
-
- case 'n':
- case 'N':
- return TryParseUInt16N(source, out value, out bytesConsumed);
-
- case 'x':
- case 'X':
- return TryParseUInt16X(source, out value, out bytesConsumed);
-
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
- }
-
- /// <summary>
- /// Parses a UInt32 at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<byte> source, out uint value, out int bytesConsumed, char standardFormat = default)
- {
- switch (standardFormat)
- {
- case default(char):
- case 'g':
- case 'G':
- case 'd':
- case 'D':
- return TryParseUInt32D(source, out value, out bytesConsumed);
-
- case 'n':
- case 'N':
- return TryParseUInt32N(source, out value, out bytesConsumed);
-
- case 'x':
- case 'X':
- return TryParseUInt32X(source, out value, out bytesConsumed);
-
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
- }
-
- /// <summary>
- /// Parses a UInt64 at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// G/g (default)
- /// D/d 32767
- /// N/n 32,767
- /// X/x 7fff
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<byte> source, out ulong value, out int bytesConsumed, char standardFormat = default)
- {
- switch (standardFormat)
- {
- case default(char):
- case 'g':
- case 'G':
- case 'd':
- case 'D':
- return TryParseUInt64D(source, out value, out bytesConsumed);
-
- case 'n':
- case 'N':
- return TryParseUInt64N(source, out value, out bytesConsumed);
-
- case 'x':
- case 'X':
- return TryParseUInt64X(source, out value, out bytesConsumed);
-
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Number.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Number.cs
deleted file mode 100644
index 0551f6a8bd1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Number.cs
+++ /dev/null
@@ -1,324 +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 System.Diagnostics;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- [Flags]
- private enum ParseNumberOptions
- {
- AllowExponent = 0x00000001,
- }
-
- private static bool TryParseNumber(ReadOnlySpan<byte> source, ref Number.NumberBuffer number, out int bytesConsumed, ParseNumberOptions options, out bool textUsedExponentNotation)
- {
- Debug.Assert(number.DigitsCount == 0);
- Debug.Assert(number.Scale == 0);
- Debug.Assert(!number.IsNegative);
- Debug.Assert(!number.HasNonZeroTail);
-
- number.CheckConsistency();
- textUsedExponentNotation = false;
-
- if (source.Length == 0)
- {
- bytesConsumed = 0;
- return false;
- }
-
- Span<byte> digits = number.Digits;
-
- int srcIndex = 0;
- int dstIndex = 0;
-
- // Consume the leading sign if any.
- byte c = source[srcIndex];
- switch (c)
- {
- case Utf8Constants.Minus:
- number.IsNegative = true;
- goto case Utf8Constants.Plus;
-
- case Utf8Constants.Plus:
- srcIndex++;
- if (srcIndex == source.Length)
- {
- bytesConsumed = 0;
- return false;
- }
- c = source[srcIndex];
- break;
-
- default:
- break;
- }
-
- int startIndexDigitsBeforeDecimal = srcIndex;
- int digitCount = 0;
- int maxDigitCount = digits.Length - 1;
-
- // Throw away any leading zeroes
- while (srcIndex != source.Length)
- {
- c = source[srcIndex];
- if (c != '0')
- break;
- srcIndex++;
- }
-
- if (srcIndex == source.Length)
- {
- bytesConsumed = srcIndex;
- number.CheckConsistency();
- return true;
- }
-
- int startIndexNonLeadingDigitsBeforeDecimal = srcIndex;
-
- int hasNonZeroTail = 0;
- while (srcIndex != source.Length)
- {
- c = source[srcIndex];
- int value = (byte)(c - (byte)('0'));
-
- if (value > 9)
- {
- break;
- }
-
- srcIndex++;
- digitCount++;
-
- if (digitCount >= maxDigitCount)
- {
- // For decimal and binary floating-point numbers, we only
- // need to store digits up to maxDigCount. However, we still
- // need to keep track of whether any additional digits past
- // maxDigCount were non-zero, as that can impact rounding
- // for an input that falls evenly between two representable
- // results.
-
- hasNonZeroTail |= value;
- }
- }
- number.HasNonZeroTail = (hasNonZeroTail != 0);
-
- int numDigitsBeforeDecimal = srcIndex - startIndexDigitsBeforeDecimal;
- int numNonLeadingDigitsBeforeDecimal = srcIndex - startIndexNonLeadingDigitsBeforeDecimal;
-
- Debug.Assert(dstIndex == 0);
- int numNonLeadingDigitsBeforeDecimalToCopy = Math.Min(numNonLeadingDigitsBeforeDecimal, maxDigitCount);
- source.Slice(startIndexNonLeadingDigitsBeforeDecimal, numNonLeadingDigitsBeforeDecimalToCopy).CopyTo(digits);
- dstIndex = numNonLeadingDigitsBeforeDecimalToCopy;
- number.Scale = numNonLeadingDigitsBeforeDecimal;
-
- if (srcIndex == source.Length)
- {
- digits[dstIndex] = 0;
- number.DigitsCount = dstIndex;
- bytesConsumed = srcIndex;
- number.CheckConsistency();
- return true;
- }
-
- int numDigitsAfterDecimal = 0;
- if (c == Utf8Constants.Period)
- {
- //
- // Parse the digits after the decimal point.
- //
-
- srcIndex++;
- int startIndexDigitsAfterDecimal = srcIndex;
-
- while (srcIndex != source.Length)
- {
- c = source[srcIndex];
- int value = (byte)(c - (byte)('0'));
-
- if (value > 9)
- {
- break;
- }
-
- srcIndex++;
- digitCount++;
-
- if (digitCount >= maxDigitCount)
- {
- // For decimal and binary floating-point numbers, we only
- // need to store digits up to maxDigCount. However, we still
- // need to keep track of whether any additional digits past
- // maxDigCount were non-zero, as that can impact rounding
- // for an input that falls evenly between two representable
- // results.
-
- hasNonZeroTail |= value;
- }
- }
- number.HasNonZeroTail = (hasNonZeroTail != 0);
-
- numDigitsAfterDecimal = srcIndex - startIndexDigitsAfterDecimal;
-
- int startIndexOfDigitsAfterDecimalToCopy = startIndexDigitsAfterDecimal;
- if (dstIndex == 0)
- {
- // Not copied any digits to the Number struct yet. This means we must continue discarding leading zeroes even though they appeared after the decimal point.
- while (startIndexOfDigitsAfterDecimalToCopy < srcIndex && source[startIndexOfDigitsAfterDecimalToCopy] == '0')
- {
- number.Scale--;
- startIndexOfDigitsAfterDecimalToCopy++;
- }
- }
-
- int numDigitsAfterDecimalToCopy = Math.Min(srcIndex - startIndexOfDigitsAfterDecimalToCopy, maxDigitCount - dstIndex);
- source.Slice(startIndexOfDigitsAfterDecimalToCopy, numDigitsAfterDecimalToCopy).CopyTo(digits.Slice(dstIndex));
- dstIndex += numDigitsAfterDecimalToCopy;
- // We "should" really NUL terminate, but there are multiple places we'd have to do this and it is a precondition that the caller pass in a fully zero=initialized Number.
-
- if (srcIndex == source.Length)
- {
- if (numDigitsBeforeDecimal == 0 && numDigitsAfterDecimal == 0)
- {
- // For compatibility. You can say "5." and ".5" but you can't say "."
- bytesConsumed = 0;
- return false;
- }
-
- digits[dstIndex] = 0;
- number.DigitsCount = dstIndex;
- bytesConsumed = srcIndex;
- number.CheckConsistency();
- return true;
- }
- }
-
- if (numDigitsBeforeDecimal == 0 && numDigitsAfterDecimal == 0)
- {
- bytesConsumed = 0;
- return false;
- }
-
- if ((c & ~0x20u) != 'E')
- {
- digits[dstIndex] = 0;
- number.DigitsCount = dstIndex;
- bytesConsumed = srcIndex;
- number.CheckConsistency();
- return true;
- }
-
- //
- // Parse the exponent after the "E"
- //
- textUsedExponentNotation = true;
- srcIndex++;
-
- if ((options & ParseNumberOptions.AllowExponent) == 0)
- {
- bytesConsumed = 0;
- return false;
- }
-
- if (srcIndex == source.Length)
- {
- bytesConsumed = 0;
- return false;
- }
-
- bool exponentIsNegative = false;
- c = source[srcIndex];
- switch (c)
- {
- case Utf8Constants.Minus:
- exponentIsNegative = true;
- goto case Utf8Constants.Plus;
-
- case Utf8Constants.Plus:
- srcIndex++;
- if (srcIndex == source.Length)
- {
- bytesConsumed = 0;
- return false;
- }
- c = source[srcIndex];
- break;
-
- default:
- break;
- }
-
- // If the next character isn't a digit, an exponent wasn't specified
- if ((byte)(c - (byte)('0')) > 9)
- {
- bytesConsumed = 0;
- return false;
- }
-
- if (!TryParseUInt32D(source.Slice(srcIndex), out uint absoluteExponent, out int bytesConsumedByExponent))
- {
- // Since we found at least one digit, we know that any failure to parse means we had an
- // exponent that was larger than uint.MaxValue, and we can just eat characters until the end
- absoluteExponent = uint.MaxValue;
-
- // This also means that we know there was at least 10 characters and we can "eat" those, and
- // continue eating digits from there
- srcIndex += 10;
-
- while (srcIndex != source.Length)
- {
- c = source[srcIndex];
- int value = (byte)(c - (byte)('0'));
-
- if (value > 9)
- {
- break;
- }
-
- srcIndex++;
- }
- }
-
- srcIndex += bytesConsumedByExponent;
-
- if (exponentIsNegative)
- {
- if (number.Scale < int.MinValue + (long)absoluteExponent)
- {
- // A scale underflow means all non-zero digits are all so far to the right of the decimal point, no
- // number format we have will be able to see them. Just pin the scale at the absolute minimum
- // and let the converter produce a 0 with the max precision available for that type.
- number.Scale = int.MinValue;
- }
- else
- {
- number.Scale -= (int)absoluteExponent;
- }
- }
- else
- {
- if (number.Scale > int.MaxValue - (long)absoluteExponent)
- {
- // A scale overflow means all non-zero digits are all so far to the right of the decimal point, no
- // number format we have will be able to see them. Just pin the scale at the absolute maximum
- // and let the converter produce a 0 with the max precision available for that type.
- number.Scale = int.MaxValue;
- }
- else
- {
- number.Scale += (int)absoluteExponent;
- }
- }
-
- digits[dstIndex] = 0;
- number.DigitsCount = dstIndex;
- bytesConsumed = srcIndex;
- number.CheckConsistency();
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.BigG.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.BigG.cs
deleted file mode 100644
index 6bcb4d52777..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.BigG.cs
+++ /dev/null
@@ -1,132 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- private static bool TryParseTimeSpanBigG(ReadOnlySpan<byte> source, out TimeSpan value, out int bytesConsumed)
- {
- int srcIndex = 0;
- byte c = default;
- while (srcIndex != source.Length)
- {
- c = source[srcIndex];
- if (!(c == ' ' || c == '\t'))
- break;
- srcIndex++;
- }
-
- if (srcIndex == source.Length)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- bool isNegative = false;
- if (c == Utf8Constants.Minus)
- {
- isNegative = true;
- srcIndex++;
- if (srcIndex == source.Length)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
- }
-
- if (!TryParseUInt32D(source.Slice(srcIndex), out uint days, out int justConsumed))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
- srcIndex += justConsumed;
-
- if (srcIndex == source.Length || source[srcIndex++] != Utf8Constants.Colon)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- if (!TryParseUInt32D(source.Slice(srcIndex), out uint hours, out justConsumed))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
- srcIndex += justConsumed;
-
- if (srcIndex == source.Length || source[srcIndex++] != Utf8Constants.Colon)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- if (!TryParseUInt32D(source.Slice(srcIndex), out uint minutes, out justConsumed))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
- srcIndex += justConsumed;
-
- if (srcIndex == source.Length || source[srcIndex++] != Utf8Constants.Colon)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- if (!TryParseUInt32D(source.Slice(srcIndex), out uint seconds, out justConsumed))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
- srcIndex += justConsumed;
-
- if (srcIndex == source.Length || source[srcIndex++] != Utf8Constants.Period)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- if (!TryParseTimeSpanFraction(source.Slice(srcIndex), out uint fraction, out justConsumed))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- srcIndex += justConsumed;
-
- if (!TryCreateTimeSpan(isNegative: isNegative, days: days, hours: hours, minutes: minutes, seconds: seconds, fraction: fraction, out value))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- //
- // There cannot legally be a sixth number. If the next character is a period or colon, treat this as a error as it's likely
- // to indicate the start of a sixth number. Otherwise, treat as end of parse with data left over.
- //
- if (srcIndex != source.Length && (source[srcIndex] == Utf8Constants.Period || source[srcIndex] == Utf8Constants.Colon))
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- bytesConsumed = srcIndex;
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.C.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.C.cs
deleted file mode 100644
index 57ce2c83d6a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.C.cs
+++ /dev/null
@@ -1,66 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- private static bool TryParseTimeSpanC(ReadOnlySpan<byte> source, out TimeSpan value, out int bytesConsumed)
- {
- TimeSpanSplitter s = default;
- if (!s.TrySplitTimeSpan(source, periodUsedToSeparateDay: true, out bytesConsumed))
- {
- value = default;
- return false;
- }
-
- bool isNegative = s.IsNegative;
-
- bool success;
- switch (s.Separators)
- {
- case 0x00000000: // dd
- success = TryCreateTimeSpan(isNegative: isNegative, days: s.V1, hours: 0, minutes: 0, seconds: 0, fraction: 0, out value);
- break;
-
- case 0x01000000: // hh:mm
- success = TryCreateTimeSpan(isNegative: isNegative, days: 0, hours: s.V1, minutes: s.V2, seconds: 0, fraction: 0, out value);
- break;
-
- case 0x02010000: // dd.hh:mm
- success = TryCreateTimeSpan(isNegative: isNegative, days: s.V1, hours: s.V2, minutes: s.V3, seconds: 0, fraction: 0, out value);
- break;
-
- case 0x01010000: // hh:mm:ss
- success = TryCreateTimeSpan(isNegative: isNegative, days: 0, hours: s.V1, minutes: s.V2, seconds: s.V3, fraction: 0, out value);
- break;
-
- case 0x02010100: // dd.hh:mm:ss
- success = TryCreateTimeSpan(isNegative: isNegative, days: s.V1, hours: s.V2, minutes: s.V3, seconds: s.V4, fraction: 0, out value);
- break;
-
- case 0x01010200: // hh:mm:ss.fffffff
- success = TryCreateTimeSpan(isNegative: isNegative, days: 0, hours: s.V1, minutes: s.V2, seconds: s.V3, fraction: s.V4, out value);
- break;
-
- case 0x02010102: // dd.hh:mm:ss.fffffff
- success = TryCreateTimeSpan(isNegative: isNegative, days: s.V1, hours: s.V2, minutes: s.V3, seconds: s.V4, fraction: s.V5, out value);
- break;
-
- default:
- value = default;
- success = false;
- break;
- }
-
- if (!success)
- {
- bytesConsumed = 0;
- return false;
- }
-
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.LittleG.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.LittleG.cs
deleted file mode 100644
index 19208b9eace..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.LittleG.cs
+++ /dev/null
@@ -1,62 +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.
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- private static bool TryParseTimeSpanLittleG(ReadOnlySpan<byte> source, out TimeSpan value, out int bytesConsumed)
- {
- TimeSpanSplitter s = default;
- if (!s.TrySplitTimeSpan(source, periodUsedToSeparateDay: false, out bytesConsumed))
- {
- value = default;
- return false;
- }
-
- bool isNegative = s.IsNegative;
-
- bool success;
- switch (s.Separators)
- {
- case 0x00000000: // dd
- success = TryCreateTimeSpan(isNegative: isNegative, days: s.V1, hours: 0, minutes: 0, seconds: 0, fraction: 0, out value);
- break;
-
- case 0x01000000: // hh:mm
- success = TryCreateTimeSpan(isNegative: isNegative, days: 0, hours: s.V1, minutes: s.V2, seconds: 0, fraction: 0, out value);
- break;
-
- case 0x01010000: // hh:mm:ss
- success = TryCreateTimeSpan(isNegative: isNegative, days: 0, hours: s.V1, minutes: s.V2, seconds: s.V3, fraction: 0, out value);
- break;
-
- case 0x01010100: // dd:hh:mm:ss
- success = TryCreateTimeSpan(isNegative: isNegative, days: s.V1, hours: s.V2, minutes: s.V3, seconds: s.V4, fraction: 0, out value);
- break;
-
- case 0x01010200: // hh:mm:ss.fffffff
- success = TryCreateTimeSpan(isNegative: isNegative, days: 0, hours: s.V1, minutes: s.V2, seconds: s.V3, fraction: s.V4, out value);
- break;
-
- case 0x01010102: // dd:hh:mm:ss.fffffff
- success = TryCreateTimeSpan(isNegative: isNegative, days: s.V1, hours: s.V2, minutes: s.V3, seconds: s.V4, fraction: s.V5, out value);
- break;
-
- default:
- value = default;
- success = false;
- break;
- }
-
- if (!success)
- {
- bytesConsumed = 0;
- return false;
- }
-
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.cs
deleted file mode 100644
index f99bf1e2e2b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpan.cs
+++ /dev/null
@@ -1,191 +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 System.Diagnostics;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- /// <summary>
- /// Parses a TimeSpan at the start of a Utf8 string.
- /// </summary>
- /// <param name="source">The Utf8 string to parse</param>
- /// <param name="value">Receives the parsed value</param>
- /// <param name="bytesConsumed">On a successful parse, receives the length in bytes of the substring that was parsed </param>
- /// <param name="standardFormat">Expected format of the Utf8 string</param>
- /// <returns>
- /// true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
- /// false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
- /// </returns>
- /// <remarks>
- /// Formats supported:
- /// c/t/T (default) [-][d.]hh:mm:ss[.fffffff] (constant format)
- /// G [-]d:hh:mm:ss.fffffff (general long)
- /// g [-][d:]h:mm:ss[.f[f[f[f[f[f[f[]]]]]]] (general short)
- /// </remarks>
- /// <exceptions>
- /// <cref>System.FormatException</cref> if the format is not valid for this data type.
- /// </exceptions>
- public static bool TryParse(ReadOnlySpan<byte> source, out TimeSpan value, out int bytesConsumed, char standardFormat = default)
- {
- switch (standardFormat)
- {
- case default(char):
- case 'c':
- case 't':
- case 'T':
- return TryParseTimeSpanC(source, out value, out bytesConsumed);
-
- case 'G':
- return TryParseTimeSpanBigG(source, out value, out bytesConsumed);
-
- case 'g':
- return TryParseTimeSpanLittleG(source, out value, out bytesConsumed);
-
- default:
- return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
- }
- }
-
- /// <summary>
- /// Parse the fraction portion of a TimeSpan. Must be 1..7 digits. If fewer than 7, zeroes are implied to the right. If more than 7, the TimeSpan
- /// parser rejects the string (even if the extra digits are all zeroes.)
- /// </summary>
- private static bool TryParseTimeSpanFraction(ReadOnlySpan<byte> source, out uint value, out int bytesConsumed)
- {
- int srcIndex = 0;
-
- if (srcIndex == source.Length)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
-
- uint digit = source[srcIndex] - 48u; // '0'
- if (digit > 9)
- {
- value = default;
- bytesConsumed = 0;
- return false;
- }
- srcIndex++;
-
- uint fraction = digit;
- int digitCount = 1;
-
- while (srcIndex != source.Length)
- {
- digit = source[srcIndex] - 48u; // '0'
- if (digit > 9)
- break;
- srcIndex++;
- digitCount++;
- if (digitCount > Utf8Constants.DateTimeNumFractionDigits)
- {
- // Yes, TimeSpan fraction parsing is that picky.
- value = default;
- bytesConsumed = 0;
- return false;
- }
- fraction = 10 * fraction + digit;
- }
-
- switch (digitCount)
- {
- case 7:
- break;
-
- case 6:
- fraction *= 10;
- break;
-
- case 5:
- fraction *= 100;
- break;
-
- case 4:
- fraction *= 1000;
- break;
-
- case 3:
- fraction *= 10000;
- break;
-
- case 2:
- fraction *= 100000;
- break;
-
- default:
- Debug.Assert(digitCount == 1);
- fraction *= 1000000;
- break;
- }
-
- value = fraction;
- bytesConsumed = srcIndex;
- return true;
- }
-
- /// <summary>
- /// Overflow-safe TryCreateTimeSpan
- /// </summary>
- private static bool TryCreateTimeSpan(bool isNegative, uint days, uint hours, uint minutes, uint seconds, uint fraction, out TimeSpan timeSpan)
- {
- const long MaxMilliSeconds = long.MaxValue / TimeSpan.TicksPerMillisecond;
- const long MinMilliSeconds = long.MinValue / TimeSpan.TicksPerMillisecond;
-
- if (hours > 23 || minutes > 59 || seconds > 59)
- {
- timeSpan = default;
- return false;
- }
-
- Debug.Assert(fraction <= Utf8Constants.MaxDateTimeFraction); // This value comes from TryParseTimeSpanFraction() which already rejects any fraction string longer than 7 digits.
-
- long millisecondsWithoutFraction = (((long)days) * 3600 * 24 + ((long)hours) * 3600 + ((long)minutes) * 60 + seconds) * 1000;
-
- long ticks;
- if (isNegative)
- {
- millisecondsWithoutFraction = -millisecondsWithoutFraction;
- if (millisecondsWithoutFraction < MinMilliSeconds)
- {
- timeSpan = default;
- return false;
- }
-
- long ticksWithoutFraction = millisecondsWithoutFraction * TimeSpan.TicksPerMillisecond;
- if (ticksWithoutFraction < long.MinValue + fraction)
- {
- timeSpan = default;
- return false;
- }
-
- ticks = ticksWithoutFraction - fraction;
- }
- else
- {
- if (millisecondsWithoutFraction > MaxMilliSeconds)
- {
- timeSpan = default;
- return false;
- }
-
- long ticksWithoutFraction = millisecondsWithoutFraction * TimeSpan.TicksPerMillisecond;
- if (ticksWithoutFraction > long.MaxValue - fraction)
- {
- timeSpan = default;
- return false;
- }
-
- ticks = ticksWithoutFraction + fraction;
- }
-
- timeSpan = new TimeSpan(ticks);
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpanSplitter.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpanSplitter.cs
deleted file mode 100644
index 8baf946d310..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.TimeSpanSplitter.cs
+++ /dev/null
@@ -1,223 +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 System.Diagnostics;
-
-namespace System.Buffers.Text
-{
- public static partial class Utf8Parser
- {
- private enum ComponentParseResult : byte
- {
- // Do not change or add values in this enum unless you review every use of the TimeSpanSplitter.Separators field. That field is an "array of four
- // ComponentParseResults" encoded as a 32-bit integer with each of its four bytes containing one of 0 (NoMoreData), 1 (Colon) or 2 (Period).
- // (So a value of 0x01010200 means the string parsed as "nn:nn:nn.nnnnnnn")
- NoMoreData = 0,
- Colon = 1,
- Period = 2,
- ParseFailure = 3,
- }
-
- private struct TimeSpanSplitter
- {
- public uint V1;
- public uint V2;
- public uint V3;
- public uint V4;
- public uint V5;
-
- public bool IsNegative;
-
- // Encodes an "array of four ComponentParseResults" as a 32-bit integer with each of its four bytes containing one of 0 (NoMoreData), 1 (Colon) or 2 (Period).
- // (So a value of 0x01010200 means the string parsed as "nn:nn:nn.nnnnnnn")
- public uint Separators;
-
- public bool TrySplitTimeSpan(ReadOnlySpan<byte> source, bool periodUsedToSeparateDay, out int bytesConsumed)
- {
- int srcIndex = 0;
- byte c = default;
-
- // Unlike many other data types, TimeSpan allow leading whitespace.
- while (srcIndex != source.Length)
- {
- c = source[srcIndex];
- if (!(c == ' ' || c == '\t'))
- break;
- srcIndex++;
- }
-
- if (srcIndex == source.Length)
- {
- bytesConsumed = 0;
- return false;
- }
-
- // Check for an option negative sign. ('+' is not allowed.)
- if (c == Utf8Constants.Minus)
- {
- IsNegative = true;
- srcIndex++;
- if (srcIndex == source.Length)
- {
- bytesConsumed = 0;
- return false;
- }
- }
-
- // From here, we terminate on anything that's not a digit, ':' or '.' The '.' is only allowed after at least three components have
- // been specified. If we see it earlier, we'll assume that's an error and fail out rather than treating it as the end of data.
-
- //
- // Timespan has to start with a number - parse the first one.
- //
- if (!TryParseUInt32D(source.Slice(srcIndex), out V1, out int justConsumed))
- {
- bytesConsumed = 0;
- return false;
- }
- srcIndex += justConsumed;
-
- //
- // Split out the second number (if any) For the 'c' format, a period might validly appear here as it;s used both to separate the day and the fraction - however,
- // the fraction is always the fourth component at earliest, so if we do see a period at this stage, always parse the integer as a regular integer, not as
- // a fraction.
- //
- ComponentParseResult result = ParseComponent(source, neverParseAsFraction: periodUsedToSeparateDay, ref srcIndex, out V2);
- if (result == ComponentParseResult.ParseFailure)
- {
- bytesConsumed = 0;
- return false;
- }
- else if (result == ComponentParseResult.NoMoreData)
- {
- bytesConsumed = srcIndex;
- return true;
- }
- else
- {
- Debug.Assert(result == ComponentParseResult.Colon || result == ComponentParseResult.Period);
- Separators |= ((uint)result) << 24;
- }
-
- //
- // Split out the third number (if any)
- //
- result = ParseComponent(source, false, ref srcIndex, out V3);
- if (result == ComponentParseResult.ParseFailure)
- {
- bytesConsumed = 0;
- return false;
- }
- else if (result == ComponentParseResult.NoMoreData)
- {
- bytesConsumed = srcIndex;
- return true;
- }
- else
- {
- Debug.Assert(result == ComponentParseResult.Colon || result == ComponentParseResult.Period);
- Separators |= ((uint)result) << 16;
- }
-
- //
- // Split out the fourth number (if any)
- //
- result = ParseComponent(source, false, ref srcIndex, out V4);
- if (result == ComponentParseResult.ParseFailure)
- {
- bytesConsumed = 0;
- return false;
- }
- else if (result == ComponentParseResult.NoMoreData)
- {
- bytesConsumed = srcIndex;
- return true;
- }
- else
- {
- Debug.Assert(result == ComponentParseResult.Colon || result == ComponentParseResult.Period);
- Separators |= ((uint)result) << 8;
- }
-
- //
- // Split out the fifth number (if any)
- //
- result = ParseComponent(source, false, ref srcIndex, out V5);
- if (result == ComponentParseResult.ParseFailure)
- {
- bytesConsumed = 0;
- return false;
- }
- else if (result == ComponentParseResult.NoMoreData)
- {
- bytesConsumed = srcIndex;
- return true;
- }
- else
- {
- Debug.Assert(result == ComponentParseResult.Colon || result == ComponentParseResult.Period);
- Separators |= (uint)result;
- }
-
- //
- // There cannot legally be a sixth number. If the next character is a period or colon, treat this as a error as it's likely
- // to indicate the start of a sixth number. Otherwise, treat as end of parse with data left over.
- //
- if (srcIndex != source.Length && (source[srcIndex] == Utf8Constants.Period || source[srcIndex] == Utf8Constants.Colon))
- {
- bytesConsumed = 0;
- return false;
- }
-
- bytesConsumed = srcIndex;
- return true;
- }
-
- //
- // Look for a separator followed by an unsigned integer.
- //
- private static ComponentParseResult ParseComponent(ReadOnlySpan<byte> source, bool neverParseAsFraction, ref int srcIndex, out uint value)
- {
- if (srcIndex == source.Length)
- {
- value = default;
- return ComponentParseResult.NoMoreData;
- }
-
- byte c = source[srcIndex];
- if (c == Utf8Constants.Colon || (c == Utf8Constants.Period && neverParseAsFraction))
- {
- srcIndex++;
-
- if (!TryParseUInt32D(source.Slice(srcIndex), out value, out int bytesConsumed))
- {
- value = default;
- return ComponentParseResult.ParseFailure;
- }
-
- srcIndex += bytesConsumed;
- return c == Utf8Constants.Colon ? ComponentParseResult.Colon : ComponentParseResult.Period;
- }
- else if (c == Utf8Constants.Period)
- {
- srcIndex++;
-
- if (!TryParseTimeSpanFraction(source.Slice(srcIndex), out value, out int bytesConsumed))
- {
- value = default;
- return ComponentParseResult.ParseFailure;
- }
-
- srcIndex += bytesConsumed;
- return ComponentParseResult.Period;
- }
- else
- {
- value = default;
- return ComponentParseResult.NoMoreData;
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs
deleted file mode 100644
index c1f0d82b6f7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs
+++ /dev/null
@@ -1,501 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Threading;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Buffers
-{
- /// <summary>
- /// Provides an ArrayPool implementation meant to be used as the singleton returned from ArrayPool.Shared.
- /// </summary>
- /// <remarks>
- /// The implementation uses a tiered caching scheme, with a small per-thread cache for each array size, followed
- /// by a cache per array size shared by all threads, split into per-core stacks meant to be used by threads
- /// running on that core. Locks are used to protect each per-core stack, because a thread can migrate after
- /// checking its processor number, because multiple threads could interleave on the same core, and because
- /// a thread is allowed to check other core's buckets if its core's bucket is empty/full.
- /// </remarks>
- internal sealed partial class TlsOverPerCoreLockedStacksArrayPool<T> : ArrayPool<T>
- {
- // TODO: #7747: "Investigate optimizing ArrayPool heuristics"
- // - Explore caching in TLS more than one array per size per thread, and moving stale buffers to the global queue.
- // - Explore changing the size of each per-core bucket, potentially dynamically or based on other factors like array size.
- // - Explore changing number of buckets and what sizes of arrays are cached.
- // - Investigate whether false sharing is causing any issues, in particular on LockedStack's count and the contents of its array.
- // ...
-
- /// <summary>The number of buckets (array sizes) in the pool, one for each array length, starting from length 16.</summary>
- private const int NumBuckets = 17; // Utilities.SelectBucketIndex(2*1024*1024)
- /// <summary>Maximum number of per-core stacks to use per array size.</summary>
- private const int MaxPerCorePerArraySizeStacks = 64; // selected to avoid needing to worry about processor groups
- /// <summary>The maximum number of buffers to store in a bucket's global queue.</summary>
- private const int MaxBuffersPerArraySizePerCore = 8;
-
- /// <summary>The length of arrays stored in the corresponding indices in <see cref="_buckets"/> and <see cref="t_tlsBuckets"/>.</summary>
- private readonly int[] _bucketArraySizes;
- /// <summary>
- /// An array of per-core array stacks. The slots are lazily initialized to avoid creating
- /// lots of overhead for unused array sizes.
- /// </summary>
- private readonly PerCoreLockedStacks?[] _buckets = new PerCoreLockedStacks[NumBuckets];
- /// <summary>A per-thread array of arrays, to cache one array per array size per thread.</summary>
- [ThreadStatic]
- private static T[]?[]? t_tlsBuckets;
-
- private int _callbackCreated;
-
- private static readonly bool s_trimBuffers = GetTrimBuffers();
-
- /// <summary>
- /// Used to keep track of all thread local buckets for trimming if needed
- /// </summary>
- private static readonly ConditionalWeakTable<T[]?[], object?>? s_allTlsBuckets =
- s_trimBuffers ? new ConditionalWeakTable<T[]?[], object?>() : null;
-
- /// <summary>Initialize the pool.</summary>
- public TlsOverPerCoreLockedStacksArrayPool()
- {
- var sizes = new int[NumBuckets];
- for (int i = 0; i < sizes.Length; i++)
- {
- sizes[i] = Utilities.GetMaxSizeForBucket(i);
- }
- _bucketArraySizes = sizes;
- }
-
- /// <summary>Allocate a new PerCoreLockedStacks and try to store it into the <see cref="_buckets"/> array.</summary>
- private PerCoreLockedStacks CreatePerCoreLockedStacks(int bucketIndex)
- {
- var inst = new PerCoreLockedStacks();
- return Interlocked.CompareExchange(ref _buckets[bucketIndex], inst, null) ?? inst;
- }
-
- /// <summary>Gets an ID for the pool to use with events.</summary>
- private int Id => GetHashCode();
-
- public override T[] Rent(int minimumLength)
- {
- // Arrays can't be smaller than zero. We allow requesting zero-length arrays (even though
- // pooling such an array isn't valuable) as it's a valid length array, and we want the pool
- // to be usable in general instead of using `new`, even for computed lengths.
- if (minimumLength < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(minimumLength));
- }
- else if (minimumLength == 0)
- {
- // No need to log the empty array. Our pool is effectively infinite
- // and we'll never allocate for rents and never store for returns.
- return Array.Empty<T>();
- }
-
- ArrayPoolEventSource log = ArrayPoolEventSource.Log;
- T[]? buffer;
-
- // Get the bucket number for the array length
- int bucketIndex = Utilities.SelectBucketIndex(minimumLength);
-
- // If the array could come from a bucket...
- if (bucketIndex < _buckets.Length)
- {
- // First try to get it from TLS if possible.
- T[]?[]? tlsBuckets = t_tlsBuckets;
- if (tlsBuckets != null)
- {
- buffer = tlsBuckets[bucketIndex];
- if (buffer != null)
- {
- tlsBuckets[bucketIndex] = null;
- if (log.IsEnabled())
- {
- log.BufferRented(buffer.GetHashCode(), buffer.Length, Id, bucketIndex);
- }
- return buffer;
- }
- }
-
- // We couldn't get a buffer from TLS, so try the global stack.
- PerCoreLockedStacks? b = _buckets[bucketIndex];
- if (b != null)
- {
- buffer = b.TryPop();
- if (buffer != null)
- {
- if (log.IsEnabled())
- {
- log.BufferRented(buffer.GetHashCode(), buffer.Length, Id, bucketIndex);
- }
- return buffer;
- }
- }
-
- // No buffer available. Allocate a new buffer with a size corresponding to the appropriate bucket.
- buffer = GC.AllocateUninitializedArray<T>(_bucketArraySizes[bucketIndex]);
- }
- else
- {
- // The request was for a size too large for the pool. Allocate an array of exactly the requested length.
- // When it's returned to the pool, we'll simply throw it away.
- buffer = GC.AllocateUninitializedArray<T>(minimumLength);
- }
-
- if (log.IsEnabled())
- {
- int bufferId = buffer.GetHashCode(), bucketId = -1; // no bucket for an on-demand allocated buffer
- log.BufferRented(bufferId, buffer.Length, Id, bucketId);
- log.BufferAllocated(bufferId, buffer.Length, Id, bucketId, bucketIndex >= _buckets.Length ?
- ArrayPoolEventSource.BufferAllocatedReason.OverMaximumSize :
- ArrayPoolEventSource.BufferAllocatedReason.PoolExhausted);
- }
-
- return buffer;
- }
-
- public override void Return(T[] array, bool clearArray = false)
- {
- if (array == null)
- {
- throw new ArgumentNullException(nameof(array));
- }
-
- // Determine with what bucket this array length is associated
- int bucketIndex = Utilities.SelectBucketIndex(array.Length);
-
- // If we can tell that the buffer was allocated (or empty), drop it. Otherwise, check if we have space in the pool.
- if (bucketIndex < _buckets.Length)
- {
- // Clear the array if the user requests.
- if (clearArray)
- {
- Array.Clear(array, 0, array.Length);
- }
-
- // Check to see if the buffer is the correct size for this bucket
- if (array.Length != _bucketArraySizes[bucketIndex])
- {
- throw new ArgumentException(SR.ArgumentException_BufferNotFromPool, nameof(array));
- }
-
- // Write through the TLS bucket. If there weren't any buckets, create them
- // and store this array into it. If there were, store this into it, and
- // if there was a previous one there, push that to the global stack. This
- // helps to keep LIFO access such that the most recently pushed stack will
- // be in TLS and the first to be popped next.
- T[]?[]? tlsBuckets = t_tlsBuckets;
- if (tlsBuckets == null)
- {
- t_tlsBuckets = tlsBuckets = new T[NumBuckets][];
- tlsBuckets[bucketIndex] = array;
- if (s_trimBuffers)
- {
- Debug.Assert(s_allTlsBuckets != null, "Should be non-null iff s_trimBuffers is true");
- s_allTlsBuckets.Add(tlsBuckets, null);
- if (Interlocked.Exchange(ref _callbackCreated, 1) != 1)
- {
- Gen2GcCallback.Register(Gen2GcCallbackFunc, this);
- }
- }
- }
- else
- {
- T[]? prev = tlsBuckets[bucketIndex];
- tlsBuckets[bucketIndex] = array;
-
- if (prev != null)
- {
- PerCoreLockedStacks stackBucket = _buckets[bucketIndex] ?? CreatePerCoreLockedStacks(bucketIndex);
- stackBucket.TryPush(prev);
- }
- }
- }
-
- // Log that the buffer was returned
- ArrayPoolEventSource log = ArrayPoolEventSource.Log;
- if (log.IsEnabled())
- {
- log.BufferReturned(array.GetHashCode(), array.Length, Id);
- }
- }
-
- public bool Trim()
- {
- Debug.Assert(s_trimBuffers);
- Debug.Assert(s_allTlsBuckets != null);
-
- int milliseconds = Environment.TickCount;
- MemoryPressure pressure = GetMemoryPressure();
-
- ArrayPoolEventSource log = ArrayPoolEventSource.Log;
- if (log.IsEnabled())
- log.BufferTrimPoll(milliseconds, (int)pressure);
-
- PerCoreLockedStacks?[] perCoreBuckets = _buckets;
- for (int i = 0; i < perCoreBuckets.Length; i++)
- {
- perCoreBuckets[i]?.Trim((uint)milliseconds, Id, pressure, _bucketArraySizes[i]);
- }
-
- if (pressure == MemoryPressure.High)
- {
- // Under high pressure, release all thread locals
- if (log.IsEnabled())
- {
- foreach (KeyValuePair<T[]?[], object?> tlsBuckets in s_allTlsBuckets)
- {
- T[]?[] buckets = tlsBuckets.Key;
- for (int i = 0; i < buckets.Length; i++)
- {
- T[]? buffer = Interlocked.Exchange(ref buckets[i], null);
- if (buffer != null)
- {
- // As we don't want to take a perf hit in the rent path it
- // is possible that a buffer could be rented as we "free" it.
- log.BufferTrimmed(buffer.GetHashCode(), buffer.Length, Id);
- }
- }
- }
- }
- else
- {
- foreach (KeyValuePair<T[]?[], object?> tlsBuckets in s_allTlsBuckets)
- {
- T[]?[] buckets = tlsBuckets.Key;
- Array.Clear(buckets, 0, buckets.Length);
- }
- }
- }
-
- return true;
- }
-
- /// <summary>
- /// This is the static function that is called from the gen2 GC callback.
- /// The input object is the instance we want the callback on.
- /// </summary>
- /// <remarks>
- /// The reason that we make this function static and take the instance as a parameter is that
- /// we would otherwise root the instance to the Gen2GcCallback object, leaking the instance even when
- /// the application no longer needs it.
- /// </remarks>
- private static bool Gen2GcCallbackFunc(object target)
- {
- return ((TlsOverPerCoreLockedStacksArrayPool<T>)(target)).Trim();
- }
-
- private enum MemoryPressure
- {
- Low,
- Medium,
- High
- }
-
- private static MemoryPressure GetMemoryPressure()
- {
- const double HighPressureThreshold = .90; // Percent of GC memory pressure threshold we consider "high"
- const double MediumPressureThreshold = .70; // Percent of GC memory pressure threshold we consider "medium"
-
- GCMemoryInfo memoryInfo = GC.GetGCMemoryInfo();
- if (memoryInfo.MemoryLoadBytes >= memoryInfo.HighMemoryLoadThresholdBytes * HighPressureThreshold)
- {
- return MemoryPressure.High;
- }
- else if (memoryInfo.MemoryLoadBytes >= memoryInfo.HighMemoryLoadThresholdBytes * MediumPressureThreshold)
- {
- return MemoryPressure.Medium;
- }
- return MemoryPressure.Low;
- }
-
- private static bool GetTrimBuffers()
- {
- // Environment uses ArrayPool, so we have to hit the API directly.
-#if !CORECLR
- // P/Invokes are different for CoreCLR/RT- for RT we'll not allow
- // enabling/disabling for now.
- return true;
-#else
- return CLRConfig.GetBoolValueWithFallbacks("System.Buffers.ArrayPool.TrimShared", "DOTNET_SYSTEM_BUFFERS_ARRAYPOOL_TRIMSHARED", defaultValue: true);
-#endif
- }
-
- /// <summary>
- /// Stores a set of stacks of arrays, with one stack per core.
- /// </summary>
- private sealed class PerCoreLockedStacks
- {
- /// <summary>The stacks.</summary>
- private readonly LockedStack[] _perCoreStacks;
-
- /// <summary>Initializes the stacks.</summary>
- public PerCoreLockedStacks()
- {
- // Create the stacks. We create as many as there are processors, limited by our max.
- var stacks = new LockedStack[Math.Min(Environment.ProcessorCount, MaxPerCorePerArraySizeStacks)];
- for (int i = 0; i < stacks.Length; i++)
- {
- stacks[i] = new LockedStack();
- }
- _perCoreStacks = stacks;
- }
-
- /// <summary>Try to push the array into the stacks. If each is full when it's tested, the array will be dropped.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void TryPush(T[] array)
- {
- // Try to push on to the associated stack first. If that fails,
- // round-robin through the other stacks.
- LockedStack[] stacks = _perCoreStacks;
- int index = Thread.GetCurrentProcessorId() % stacks.Length;
- for (int i = 0; i < stacks.Length; i++)
- {
- if (stacks[index].TryPush(array)) return;
- if (++index == stacks.Length) index = 0;
- }
- }
-
- /// <summary>Try to get an array from the stacks. If each is empty when it's tested, null will be returned.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public T[]? TryPop()
- {
- // Try to pop from the associated stack first. If that fails,
- // round-robin through the other stacks.
- T[]? arr;
- LockedStack[] stacks = _perCoreStacks;
- int index = Thread.GetCurrentProcessorId() % stacks.Length;
- for (int i = 0; i < stacks.Length; i++)
- {
- if ((arr = stacks[index].TryPop()) != null) return arr;
- if (++index == stacks.Length) index = 0;
- }
- return null;
- }
-
- public void Trim(uint tickCount, int id, MemoryPressure pressure, int bucketSize)
- {
- LockedStack[] stacks = _perCoreStacks;
- for (int i = 0; i < stacks.Length; i++)
- {
- stacks[i].Trim(tickCount, id, pressure, bucketSize);
- }
- }
- }
-
- /// <summary>Provides a simple stack of arrays, protected by a lock.</summary>
- private sealed class LockedStack
- {
- private readonly T[]?[] _arrays = new T[MaxBuffersPerArraySizePerCore][];
- private int _count;
- private uint _firstStackItemMS;
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool TryPush(T[] array)
- {
- bool enqueued = false;
- Monitor.Enter(this);
- if (_count < MaxBuffersPerArraySizePerCore)
- {
- if (s_trimBuffers && _count == 0)
- {
- // Stash the time the bottom of the stack was filled
- _firstStackItemMS = (uint)Environment.TickCount;
- }
-
- _arrays[_count++] = array;
- enqueued = true;
- }
- Monitor.Exit(this);
- return enqueued;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public T[]? TryPop()
- {
- T[]? arr = null;
- Monitor.Enter(this);
- if (_count > 0)
- {
- arr = _arrays[--_count];
- _arrays[_count] = null;
- }
- Monitor.Exit(this);
- return arr;
- }
-
- public void Trim(uint tickCount, int id, MemoryPressure pressure, int bucketSize)
- {
- const uint StackTrimAfterMS = 60 * 1000; // Trim after 60 seconds for low/moderate pressure
- const uint StackHighTrimAfterMS = 10 * 1000; // Trim after 10 seconds for high pressure
- const uint StackRefreshMS = StackTrimAfterMS / 4; // Time bump after trimming (1/4 trim time)
- const int StackLowTrimCount = 1; // Trim one item when pressure is low
- const int StackMediumTrimCount = 2; // Trim two items when pressure is moderate
- const int StackHighTrimCount = MaxBuffersPerArraySizePerCore; // Trim all items when pressure is high
- const int StackLargeBucket = 16384; // If the bucket is larger than this we'll trim an extra when under high pressure
- const int StackModerateTypeSize = 16; // If T is larger than this we'll trim an extra when under high pressure
- const int StackLargeTypeSize = 32; // If T is larger than this we'll trim an extra (additional) when under high pressure
-
- if (_count == 0)
- return;
- uint trimTicks = pressure == MemoryPressure.High ? StackHighTrimAfterMS : StackTrimAfterMS;
-
- lock (this)
- {
- if (_count > 0 && _firstStackItemMS > tickCount || (tickCount - _firstStackItemMS) > trimTicks)
- {
- // We've wrapped the tick count or elapsed enough time since the
- // first item went into the stack. Drop the top item so it can
- // be collected and make the stack look a little newer.
-
- ArrayPoolEventSource log = ArrayPoolEventSource.Log;
- int trimCount = StackLowTrimCount;
- switch (pressure)
- {
- case MemoryPressure.High:
- trimCount = StackHighTrimCount;
-
- // When pressure is high, aggressively trim larger arrays.
- if (bucketSize > StackLargeBucket)
- {
- trimCount++;
- }
- if (Unsafe.SizeOf<T>() > StackModerateTypeSize)
- {
- trimCount++;
- }
- if (Unsafe.SizeOf<T>() > StackLargeTypeSize)
- {
- trimCount++;
- }
- break;
- case MemoryPressure.Medium:
- trimCount = StackMediumTrimCount;
- break;
- }
-
- while (_count > 0 && trimCount-- > 0)
- {
- T[]? array = _arrays[--_count];
- Debug.Assert(array != null, "No nulls should have been present in slots < _count.");
- _arrays[_count] = null;
-
- if (log.IsEnabled())
- {
- log.BufferTrimmed(array.GetHashCode(), array.Length, id);
- }
- }
-
- if (_count > 0 && _firstStackItemMS < uint.MaxValue - StackRefreshMS)
- {
- // Give the remaining items a bit more time
- _firstStackItemMS += StackRefreshMS;
- }
- }
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Buffers/Utilities.cs b/netcore/System.Private.CoreLib/shared/System/Buffers/Utilities.cs
deleted file mode 100644
index 7e1caa039b3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Buffers/Utilities.cs
+++ /dev/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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-
-namespace System.Buffers
-{
- internal static class Utilities
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static int SelectBucketIndex(int bufferSize)
- {
- Debug.Assert(bufferSize >= 0);
- uint bits = ((uint)bufferSize - 1) >> 4;
- return 32 - BitOperations.LeadingZeroCount(bits);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static int GetMaxSizeForBucket(int binIndex)
- {
- int maxSize = 16 << binIndex;
- Debug.Assert(maxSize >= 0);
- return maxSize;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ByReference.cs b/netcore/System.Private.CoreLib/shared/System/ByReference.cs
deleted file mode 100644
index 82d4e5cf219..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ByReference.cs
+++ /dev/null
@@ -1,38 +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 System.Runtime.CompilerServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- // ByReference<T> is meant to be used to represent "ref T" fields. It is working
- // around lack of first class support for byref fields in C# and IL. The JIT and
- // type loader has special handling for it that turns it into a thin wrapper around ref T.
- [NonVersionable]
- internal readonly ref struct ByReference<T>
- {
-#pragma warning disable CA1823, 169 // private field '{blah}' is never used
- private readonly IntPtr _value;
-#pragma warning restore CA1823, 169
-
- [Intrinsic]
- public ByReference(ref T value)
- {
- // Implemented as a JIT intrinsic - This default implementation is for
- // completeness and to provide a concrete error if called via reflection
- // or if intrinsic is missed.
- throw new PlatformNotSupportedException();
- }
-
- public ref T Value
- {
- // Implemented as a JIT intrinsic - This default implementation is for
- // completeness and to provide a concrete error if called via reflection
- // or if the intrinsic is missed.
- [Intrinsic]
- get => throw new PlatformNotSupportedException();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Byte.cs b/netcore/System.Private.CoreLib/shared/System/Byte.cs
deleted file mode 100644
index 88d349a4bd8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Byte.cs
+++ /dev/null
@@ -1,276 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- [Serializable]
- [StructLayout(LayoutKind.Sequential)]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct Byte : IComparable, IConvertible, IFormattable, IComparable<byte>, IEquatable<byte>, ISpanFormattable
- {
- 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;
-
- // The minimum value that a Byte may represent: 0.
- public const byte MinValue = 0;
-
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type byte, this method throws an ArgumentException.
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
- if (!(value is byte))
- {
- throw new ArgumentException(SR.Arg_MustBeByte);
- }
-
- return m_value - (((byte)value).m_value);
- }
-
- public int CompareTo(byte value)
- {
- return m_value - value;
- }
-
- // Determines whether two Byte objects are equal.
- public override bool Equals(object? obj)
- {
- if (!(obj is byte))
- {
- return false;
- }
- return m_value == ((byte)obj).m_value;
- }
-
- [NonVersionable]
- public bool Equals(byte obj)
- {
- return m_value == obj;
- }
-
- // Gets a hash code for this instance.
- public override int GetHashCode()
- {
- return m_value;
- }
-
- public static byte Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- public static byte Parse(string s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, style, NumberFormatInfo.CurrentInfo);
- }
-
- public static byte Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- // Parses an unsigned byte from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- public static byte Parse(string s, NumberStyles style, IFormatProvider? provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- public static byte Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- private static byte Parse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info)
- {
- Number.ParsingStatus status = Number.TryParseUInt32(s, style, info, out uint i);
- if (status != Number.ParsingStatus.OK)
- {
- Number.ThrowOverflowOrFormatException(status, TypeCode.Byte);
- }
-
- if (i > MaxValue) Number.ThrowOverflowException(TypeCode.Byte);
- return (byte)i;
- }
-
- public static bool TryParse(string? s, out byte result)
- {
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, out byte result)
- {
- return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out byte result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
-
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out byte result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- private static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info, out byte result)
- {
- if (Number.TryParseUInt32(s, style, info, out uint i) != Number.ParsingStatus.OK
- || i > MaxValue)
- {
- result = 0;
- return false;
- }
- result = (byte)i;
- return true;
- }
-
- public override string ToString()
- {
- return Number.UInt32ToDecStr(m_value, -1);
- }
-
- public string ToString(string? format)
- {
- return Number.FormatUInt32(m_value, format, null);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return Number.FormatUInt32(m_value, null, provider);
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- return Number.FormatUInt32(m_value, format, provider);
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
- {
- return Number.TryFormatUInt32(m_value, format, provider, destination, out charsWritten);
- }
-
- //
- // IConvertible implementation
- //
- public TypeCode GetTypeCode()
- {
- return TypeCode.Byte;
- }
-
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return m_value;
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Byte", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/CLSCompliantAttribute.cs b/netcore/System.Private.CoreLib/shared/System/CLSCompliantAttribute.cs
deleted file mode 100644
index ecb5557624a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/CLSCompliantAttribute.cs
+++ /dev/null
@@ -1,27 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Container for assemblies.
-**
-**
-=============================================================================*/
-
-namespace System
-{
- [AttributeUsage(AttributeTargets.All, Inherited = true, AllowMultiple = false)]
- public sealed class CLSCompliantAttribute : Attribute
- {
- private readonly bool _compliant;
-
- public CLSCompliantAttribute(bool isCompliant)
- {
- _compliant = isCompliant;
- }
- public bool IsCompliant => _compliant;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/CannotUnloadAppDomainException.cs b/netcore/System.Private.CoreLib/shared/System/CannotUnloadAppDomainException.cs
deleted file mode 100644
index 865eb093e67..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/CannotUnloadAppDomainException.cs
+++ /dev/null
@@ -1,36 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class CannotUnloadAppDomainException : SystemException
- {
- internal const int COR_E_CANNOTUNLOADAPPDOMAIN = unchecked((int)0x80131015); // corresponds to __HResults.COR_E_CANNOTUNLOADAPPDOMAIN in corelib
- public CannotUnloadAppDomainException()
- : base(SR.Arg_CannotUnloadAppDomainException)
- {
- HResult = COR_E_CANNOTUNLOADAPPDOMAIN;
- }
-
- public CannotUnloadAppDomainException(string? message)
- : base(message)
- {
- HResult = COR_E_CANNOTUNLOADAPPDOMAIN;
- }
-
- public CannotUnloadAppDomainException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = COR_E_CANNOTUNLOADAPPDOMAIN;
- }
-
- protected CannotUnloadAppDomainException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Char.cs b/netcore/System.Private.CoreLib/shared/System/Char.cs
deleted file mode 100644
index da9e1224f98..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Char.cs
+++ /dev/null
@@ -1,995 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: This is the value class representing a Unicode character
-** Char methods until we create this functionality.
-**
-**
-===========================================================*/
-
-using System.Diagnostics;
-using System.Globalization;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System
-{
- [Serializable]
- [StructLayout(LayoutKind.Sequential)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct Char : IComparable, IComparable<char>, IEquatable<char>, IConvertible
- {
- //
- // Member Variables
- //
- private readonly char m_value; // Do not rename (binary serialization)
-
- //
- // Public Constants
- //
- // The maximum character value.
- public const char MaxValue = (char)0xFFFF;
- // The minimum character value.
- public const char MinValue = (char)0x00;
-
- private const byte IsWhiteSpaceFlag = 0x80;
- private const byte IsUpperCaseLetterFlag = 0x40;
- private const byte IsLowerCaseLetterFlag = 0x20;
- private const byte UnicodeCategoryMask = 0x1F;
-
- // Contains information about the C0, Basic Latin, C1, and Latin-1 Supplement ranges [ U+0000..U+00FF ], with:
- // - 0x80 bit if set means 'is whitespace'
- // - 0x40 bit if set means 'is uppercase letter'
- // - 0x20 bit if set means 'is lowercase letter'
- // - bottom 5 bits are the UnicodeCategory of the character
- //
- // n.b. This data is locked to an earlier version of the Unicode standard (2.0, perhaps?), so
- // the UnicodeCategory data contained here doesn't necessarily reflect the UnicodeCategory data
- // contained within the CharUnicodeInfo or Rune types, which generally follow the latest Unicode
- // standard.
- private static ReadOnlySpan<byte> Latin1CharInfo => new byte[]
- {
- 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x8E, 0x8E, 0x8E, 0x8E, 0x8E, 0x0E, 0x0E, // U+0000..U+000F
- 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, // U+0010..U+001F
- 0x8B, 0x18, 0x18, 0x18, 0x1A, 0x18, 0x18, 0x18, 0x14, 0x15, 0x18, 0x19, 0x18, 0x13, 0x18, 0x18, // U+0020..U+002F
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x18, 0x18, 0x19, 0x19, 0x19, 0x18, // U+0030..U+003F
- 0x18, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, // U+0040..U+004F
- 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x14, 0x18, 0x15, 0x1B, 0x12, // U+0050..U+005F
- 0x1B, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, // U+0060..U+006F
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x14, 0x19, 0x15, 0x19, 0x0E, // U+0070..U+007F
- 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x8E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, // U+0080..U+008F
- 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, // U+0090..U+009F
- 0x8B, 0x18, 0x1A, 0x1A, 0x1A, 0x1A, 0x1C, 0x1C, 0x1B, 0x1C, 0x21, 0x16, 0x19, 0x13, 0x1C, 0x1B, // U+00A0..U+00AF
- 0x1C, 0x19, 0x0A, 0x0A, 0x1B, 0x21, 0x1C, 0x18, 0x1B, 0x0A, 0x21, 0x17, 0x0A, 0x0A, 0x0A, 0x18, // U+00B0..U+00BF
- 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, // U+00C0..U+00CF
- 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x19, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x21, // U+00D0..U+00DF
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, // U+00E0..U+00EF
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x19, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, // U+00F0..U+00FF
- };
-
- // Return true for all characters below or equal U+00ff, which is ASCII + Latin-1 Supplement.
- private static bool IsLatin1(char ch)
- {
- return (uint)ch < (uint)Latin1CharInfo.Length;
- }
-
- // Return true for all characters below or equal U+007f, which is ASCII.
- private static bool IsAscii(char ch)
- {
- return (uint)ch <= '\x007f';
- }
-
- // Return the Unicode category for Unicode character <= 0x00ff.
- private static UnicodeCategory GetLatin1UnicodeCategory(char ch)
- {
- Debug.Assert(IsLatin1(ch), "char.GetLatin1UnicodeCategory(): ch should be <= 00ff");
- return (UnicodeCategory)(Latin1CharInfo[ch] & UnicodeCategoryMask);
- }
-
- //
- // Private Constants
- //
-
- //
- // Overriden Instance Methods
- //
-
- // Calculate a hashcode for a 2 byte Unicode character.
- public override int GetHashCode()
- {
- return (int)m_value | ((int)m_value << 16);
- }
-
- // Used for comparing two boxed Char objects.
- //
- public override bool Equals(object? obj)
- {
- if (!(obj is char))
- {
- return false;
- }
- return m_value == ((char)obj).m_value;
- }
-
- [System.Runtime.Versioning.NonVersionable]
- public bool Equals(char obj)
- {
- return m_value == obj;
- }
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type Char, this method throws an ArgumentException.
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
- if (!(value is char))
- {
- throw new ArgumentException(SR.Arg_MustBeChar);
- }
-
- return m_value - ((char)value).m_value;
- }
-
- public int CompareTo(char value)
- {
- return m_value - value;
- }
-
- // Overrides System.Object.ToString.
- public override string ToString()
- {
- return char.ToString(m_value);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return char.ToString(m_value);
- }
-
- //
- // Formatting Methods
- //
-
- /*===================================ToString===================================
- **This static methods takes a character and returns the String representation of it.
- ==============================================================================*/
- // Provides a string representation of a character.
- public static string ToString(char c) => string.CreateFromChar(c);
-
- public static char Parse(string s)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- if (s.Length != 1)
- {
- throw new FormatException(SR.Format_NeedSingleChar);
- }
- return s[0];
- }
-
- public static bool TryParse(string? s, out char result)
- {
- result = '\0';
- if (s == null)
- {
- return false;
- }
- if (s.Length != 1)
- {
- return false;
- }
- result = s[0];
- return true;
- }
-
- //
- // Static Methods
- //
- /*=================================ISDIGIT======================================
- **A wrapper for char. Returns a boolean indicating whether **
- **character c is considered to be a digit. **
- ==============================================================================*/
- // Determines whether a character is a digit.
- public static bool IsDigit(char c)
- {
- if (IsLatin1(c))
- {
- return IsInRange(c, '0', '9');
- }
- return CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.DecimalDigitNumber;
- }
-
- internal static bool IsInRange(char c, char min, char max) => (uint)(c - min) <= (uint)(max - min);
-
- private static bool IsInRange(UnicodeCategory c, UnicodeCategory min, UnicodeCategory max) => (uint)(c - min) <= (uint)(max - min);
-
- /*=================================CheckLetter=====================================
- ** Check if the specified UnicodeCategory belongs to the letter categories.
- ==============================================================================*/
- internal static bool CheckLetter(UnicodeCategory uc)
- {
- return IsInRange(uc, UnicodeCategory.UppercaseLetter, UnicodeCategory.OtherLetter);
- }
-
- /*=================================ISLETTER=====================================
- **A wrapper for char. Returns a boolean indicating whether **
- **character c is considered to be a letter. **
- ==============================================================================*/
- // Determines whether a character is a letter.
- public static bool IsLetter(char c)
- {
- if (IsLatin1(c))
- {
- // For the version of the Unicode standard the Char type is locked to, the
- // Latin-1 range doesn't include letters in categories other than "upper" and "lower".
- return (Latin1CharInfo[c] & (IsUpperCaseLetterFlag | IsLowerCaseLetterFlag)) != 0;
- }
- return CheckLetter(CharUnicodeInfo.GetUnicodeCategory(c));
- }
-
- private static bool IsWhiteSpaceLatin1(char c)
- {
- Debug.Assert(IsLatin1(c));
- return (Latin1CharInfo[c] & IsWhiteSpaceFlag) != 0;
- }
-
- /*===============================ISWHITESPACE===================================
- **A wrapper for char. Returns a boolean indicating whether **
- **character c is considered to be a whitespace character. **
- ==============================================================================*/
- // Determines whether a character is whitespace.
- public static bool IsWhiteSpace(char c)
- {
- if (IsLatin1(c))
- {
- return IsWhiteSpaceLatin1(c);
- }
- return CheckSeparator(CharUnicodeInfo.GetUnicodeCategory(c));
- }
-
- /*===================================IsUpper====================================
- **Arguments: c -- the characater to be checked.
- **Returns: True if c is an uppercase character.
- ==============================================================================*/
- // Determines whether a character is upper-case.
- public static bool IsUpper(char c)
- {
- if (IsLatin1(c))
- {
- return (Latin1CharInfo[c] & IsUpperCaseLetterFlag) != 0;
- }
- return CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.UppercaseLetter;
- }
-
- /*===================================IsLower====================================
- **Arguments: c -- the characater to be checked.
- **Returns: True if c is an lowercase character.
- ==============================================================================*/
- // Determines whether a character is lower-case.
- public static bool IsLower(char c)
- {
- if (IsLatin1(c))
- {
- return (Latin1CharInfo[c] & IsLowerCaseLetterFlag) != 0;
- }
- return CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.LowercaseLetter;
- }
-
- internal static bool CheckPunctuation(UnicodeCategory uc)
- {
- return IsInRange(uc, UnicodeCategory.ConnectorPunctuation, UnicodeCategory.OtherPunctuation);
- }
-
- /*================================IsPunctuation=================================
- **Arguments: c -- the characater to be checked.
- **Returns: True if c is an punctuation mark
- ==============================================================================*/
- // Determines whether a character is a punctuation mark.
- public static bool IsPunctuation(char c)
- {
- if (IsLatin1(c))
- {
- return CheckPunctuation(GetLatin1UnicodeCategory(c));
- }
- return CheckPunctuation(CharUnicodeInfo.GetUnicodeCategory(c));
- }
-
- /*=================================CheckLetterOrDigit=====================================
- ** Check if the specified UnicodeCategory belongs to the letter or digit categories.
- ==============================================================================*/
- internal static bool CheckLetterOrDigit(UnicodeCategory uc)
- {
- return CheckLetter(uc) || uc == UnicodeCategory.DecimalDigitNumber;
- }
-
- // Determines whether a character is a letter or a digit.
- public static bool IsLetterOrDigit(char c)
- {
- if (IsLatin1(c))
- {
- return CheckLetterOrDigit(GetLatin1UnicodeCategory(c));
- }
- return CheckLetterOrDigit(CharUnicodeInfo.GetUnicodeCategory(c));
- }
-
- /*===================================ToUpper====================================
- **
- ==============================================================================*/
- // Converts a character to upper-case for the specified culture.
- // <;<;Not fully implemented>;>;
- public static char ToUpper(char c, CultureInfo culture)
- {
- if (culture == null)
- throw new ArgumentNullException(nameof(culture));
- return culture.TextInfo.ToUpper(c);
- }
-
- /*=================================TOUPPER======================================
- **A wrapper for char.ToUpperCase. Converts character c to its **
- **uppercase equivalent. If c is already an uppercase character or is not an **
- **alphabetic, nothing happens. **
- ==============================================================================*/
- // Converts a character to upper-case for the default culture.
- //
- public static char ToUpper(char c)
- {
- return CultureInfo.CurrentCulture.TextInfo.ToUpper(c);
- }
-
- // Converts a character to upper-case for invariant culture.
- public static char ToUpperInvariant(char c)
- {
- return CultureInfo.InvariantCulture.TextInfo.ToUpper(c);
- }
-
- /*===================================ToLower====================================
- **
- ==============================================================================*/
- // Converts a character to lower-case for the specified culture.
- // <;<;Not fully implemented>;>;
- public static char ToLower(char c, CultureInfo culture)
- {
- if (culture == null)
- throw new ArgumentNullException(nameof(culture));
- return culture.TextInfo.ToLower(c);
- }
-
- /*=================================TOLOWER======================================
- **A wrapper for char.ToLowerCase. Converts character c to its **
- **lowercase equivalent. If c is already a lowercase character or is not an **
- **alphabetic, nothing happens. **
- ==============================================================================*/
- // Converts a character to lower-case for the default culture.
- public static char ToLower(char c)
- {
- return CultureInfo.CurrentCulture.TextInfo.ToLower(c);
- }
-
- // Converts a character to lower-case for invariant culture.
- public static char ToLowerInvariant(char c)
- {
- return CultureInfo.InvariantCulture.TextInfo.ToLower(c);
- }
-
- //
- // IConvertible implementation
- //
- public TypeCode GetTypeCode()
- {
- return TypeCode.Char;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Boolean"));
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- return m_value;
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Single"));
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Double"));
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "Decimal"));
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Char", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
-
- public static bool IsControl(char c)
- {
- if (IsLatin1(c))
- {
- return GetLatin1UnicodeCategory(c) == UnicodeCategory.Control;
- }
- return CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.Control;
- }
-
- public static bool IsControl(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- char c = s[index];
- if (IsLatin1(c))
- {
- return GetLatin1UnicodeCategory(c) == UnicodeCategory.Control;
- }
- return CharUnicodeInfo.GetUnicodeCategory(s, index) == UnicodeCategory.Control;
- }
-
- public static bool IsDigit(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- char c = s[index];
- if (IsLatin1(c))
- {
- return IsInRange(c, '0', '9');
- }
- return CharUnicodeInfo.GetUnicodeCategory(s, index) == UnicodeCategory.DecimalDigitNumber;
- }
-
- public static bool IsLetter(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- char c = s[index];
- if (IsLatin1(c))
- {
- // The Latin-1 range doesn't include letters in categories other than "upper" and "lower"
- return (Latin1CharInfo[c] & (IsUpperCaseLetterFlag | IsLowerCaseLetterFlag)) != 0;
- }
- return CheckLetter(CharUnicodeInfo.GetUnicodeCategory(s, index));
- }
-
- public static bool IsLetterOrDigit(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- char c = s[index];
- if (IsLatin1(c))
- {
- return CheckLetterOrDigit(GetLatin1UnicodeCategory(c));
- }
- return CheckLetterOrDigit(CharUnicodeInfo.GetUnicodeCategory(s, index));
- }
-
- public static bool IsLower(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- char c = s[index];
- if (IsLatin1(c))
- {
- return (Latin1CharInfo[c] & IsLowerCaseLetterFlag) != 0;
- }
-
- return CharUnicodeInfo.GetUnicodeCategory(s, index) == UnicodeCategory.LowercaseLetter;
- }
-
- /*=================================CheckNumber=====================================
- ** Check if the specified UnicodeCategory belongs to the number categories.
- ==============================================================================*/
-
- internal static bool CheckNumber(UnicodeCategory uc)
- {
- return IsInRange(uc, UnicodeCategory.DecimalDigitNumber, UnicodeCategory.OtherNumber);
- }
-
- public static bool IsNumber(char c)
- {
- if (IsLatin1(c))
- {
- if (IsAscii(c))
- {
- return IsInRange(c, '0', '9');
- }
- return CheckNumber(GetLatin1UnicodeCategory(c));
- }
- return CheckNumber(CharUnicodeInfo.GetUnicodeCategory(c));
- }
-
- public static bool IsNumber(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- char c = s[index];
- if (IsLatin1(c))
- {
- if (IsAscii(c))
- {
- return IsInRange(c, '0', '9');
- }
- return CheckNumber(GetLatin1UnicodeCategory(c));
- }
- return CheckNumber(CharUnicodeInfo.GetUnicodeCategory(s, index));
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // IsPunctuation
- //
- // Determines if the given character is a punctuation character.
- //
- ////////////////////////////////////////////////////////////////////////
-
- public static bool IsPunctuation(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- char c = s[index];
- if (IsLatin1(c))
- {
- return CheckPunctuation(GetLatin1UnicodeCategory(c));
- }
- return CheckPunctuation(CharUnicodeInfo.GetUnicodeCategory(s, index));
- }
-
- /*================================= CheckSeparator ============================
- ** Check if the specified UnicodeCategory belongs to the seprator categories.
- ==============================================================================*/
-
- internal static bool CheckSeparator(UnicodeCategory uc)
- {
- return IsInRange(uc, UnicodeCategory.SpaceSeparator, UnicodeCategory.ParagraphSeparator);
- }
-
- private static bool IsSeparatorLatin1(char c)
- {
- // U+00a0 = NO-BREAK SPACE
- // There is no LineSeparator or ParagraphSeparator in Latin 1 range.
- return c == '\x0020' || c == '\x00a0';
- }
-
- public static bool IsSeparator(char c)
- {
- if (IsLatin1(c))
- {
- return IsSeparatorLatin1(c);
- }
- return CheckSeparator(CharUnicodeInfo.GetUnicodeCategory(c));
- }
-
- public static bool IsSeparator(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- char c = s[index];
- if (IsLatin1(c))
- {
- return IsSeparatorLatin1(c);
- }
- return CheckSeparator(CharUnicodeInfo.GetUnicodeCategory(s, index));
- }
-
- public static bool IsSurrogate(char c)
- {
- return IsInRange(c, CharUnicodeInfo.HIGH_SURROGATE_START, CharUnicodeInfo.LOW_SURROGATE_END);
- }
-
- public static bool IsSurrogate(string s, int index)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- return IsSurrogate(s[index]);
- }
-
- /*================================= CheckSymbol ============================
- ** Check if the specified UnicodeCategory belongs to the symbol categories.
- ==============================================================================*/
-
- internal static bool CheckSymbol(UnicodeCategory uc)
- {
- return IsInRange(uc, UnicodeCategory.MathSymbol, UnicodeCategory.OtherSymbol);
- }
-
- public static bool IsSymbol(char c)
- {
- if (IsLatin1(c))
- {
- return CheckSymbol(GetLatin1UnicodeCategory(c));
- }
- return CheckSymbol(CharUnicodeInfo.GetUnicodeCategory(c));
- }
-
- public static bool IsSymbol(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- char c = s[index];
- if (IsLatin1(c))
- {
- return CheckSymbol(GetLatin1UnicodeCategory(c));
- }
- return CheckSymbol(CharUnicodeInfo.GetUnicodeCategory(s, index));
- }
-
- public static bool IsUpper(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- char c = s[index];
- if (IsLatin1(c))
- {
- return (Latin1CharInfo[c] & IsUpperCaseLetterFlag) != 0;
- }
-
- return CharUnicodeInfo.GetUnicodeCategory(s, index) == UnicodeCategory.UppercaseLetter;
- }
-
- public static bool IsWhiteSpace(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
-
- char ch = s[index];
-
- if (IsLatin1(ch))
- {
- return IsWhiteSpaceLatin1(ch);
- }
-
- return CheckSeparator(CharUnicodeInfo.GetUnicodeCategory(s, index));
- }
-
- public static UnicodeCategory GetUnicodeCategory(char c)
- {
- if (IsLatin1(c))
- {
- return GetLatin1UnicodeCategory(c);
- }
- return CharUnicodeInfo.GetUnicodeCategory((int)c);
- }
-
- public static UnicodeCategory GetUnicodeCategory(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- if (IsLatin1(s[index]))
- {
- return GetLatin1UnicodeCategory(s[index]);
- }
- return CharUnicodeInfo.InternalGetUnicodeCategory(s, index);
- }
-
- public static double GetNumericValue(char c)
- {
- return CharUnicodeInfo.GetNumericValue(c);
- }
-
- public static double GetNumericValue(string s, int index)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- return CharUnicodeInfo.GetNumericValue(s, index);
- }
-
- /*================================= IsHighSurrogate ============================
- ** Check if a char is a high surrogate.
- ==============================================================================*/
- public static bool IsHighSurrogate(char c)
- {
- return IsInRange(c, CharUnicodeInfo.HIGH_SURROGATE_START, CharUnicodeInfo.HIGH_SURROGATE_END);
- }
-
- public static bool IsHighSurrogate(string s, int index)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
- if (index < 0 || index >= s.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- return IsHighSurrogate(s[index]);
- }
-
- /*================================= IsLowSurrogate ============================
- ** Check if a char is a low surrogate.
- ==============================================================================*/
- public static bool IsLowSurrogate(char c)
- {
- return IsInRange(c, CharUnicodeInfo.LOW_SURROGATE_START, CharUnicodeInfo.LOW_SURROGATE_END);
- }
-
- public static bool IsLowSurrogate(string s, int index)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
- if (index < 0 || index >= s.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- return IsLowSurrogate(s[index]);
- }
-
- /*================================= IsSurrogatePair ============================
- ** Check if the string specified by the index starts with a surrogate pair.
- ==============================================================================*/
- public static bool IsSurrogatePair(string s, int index)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
- if (index < 0 || index >= s.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- if (index + 1 < s.Length)
- {
- return IsSurrogatePair(s[index], s[index + 1]);
- }
- return false;
- }
-
- public static bool IsSurrogatePair(char highSurrogate, char lowSurrogate)
- {
- // Since both the high and low surrogate ranges are exactly 0x400 elements
- // wide, and since this is a power of two, we can perform a single comparison
- // by baselining each value to the start of its respective range and taking
- // the logical OR of them.
-
- uint highSurrogateOffset = (uint)highSurrogate - CharUnicodeInfo.HIGH_SURROGATE_START;
- uint lowSurrogateOffset = (uint)lowSurrogate - CharUnicodeInfo.LOW_SURROGATE_START;
- return (highSurrogateOffset | lowSurrogateOffset) <= CharUnicodeInfo.HIGH_SURROGATE_RANGE;
- }
-
- internal const int UNICODE_PLANE00_END = 0x00ffff;
- // The starting codepoint for Unicode plane 1. Plane 1 contains 0x010000 ~ 0x01ffff.
- internal const int UNICODE_PLANE01_START = 0x10000;
- // The end codepoint for Unicode plane 16. This is the maximum code point value allowed for Unicode.
- // Plane 16 contains 0x100000 ~ 0x10ffff.
- internal const int UNICODE_PLANE16_END = 0x10ffff;
-
- /*================================= ConvertFromUtf32 ============================
- ** Convert an UTF32 value into a surrogate pair.
- ==============================================================================*/
-
- public static string ConvertFromUtf32(int utf32)
- {
- if (!UnicodeUtility.IsValidUnicodeScalar((uint)utf32))
- {
- throw new ArgumentOutOfRangeException(nameof(utf32), SR.ArgumentOutOfRange_InvalidUTF32);
- }
-
- return Rune.UnsafeCreate((uint)utf32).ToString();
- }
-
- /*=============================ConvertToUtf32===================================
- ** Convert a surrogate pair to UTF32 value
- ==============================================================================*/
-
- public static int ConvertToUtf32(char highSurrogate, char lowSurrogate)
- {
- // First, extend both to 32 bits, then calculate the offset of
- // each candidate surrogate char from the start of its range.
-
- uint highSurrogateOffset = (uint)highSurrogate - CharUnicodeInfo.HIGH_SURROGATE_START;
- uint lowSurrogateOffset = (uint)lowSurrogate - CharUnicodeInfo.LOW_SURROGATE_START;
-
- // This is a single comparison which allows us to check both for validity at once since
- // both the high surrogate range and the low surrogate range are the same length.
- // If the comparison fails, we call to a helper method to throw the correct exception message.
-
- if ((highSurrogateOffset | lowSurrogateOffset) > CharUnicodeInfo.HIGH_SURROGATE_RANGE)
- {
- ConvertToUtf32_ThrowInvalidArgs(highSurrogateOffset);
- }
-
- // The 0x40u << 10 below is to account for uuuuu = wwww + 1 in the surrogate encoding.
- return ((int)highSurrogateOffset << 10) + (lowSurrogate - CharUnicodeInfo.LOW_SURROGATE_START) + (0x40 << 10);
- }
-
- [StackTraceHidden]
- private static void ConvertToUtf32_ThrowInvalidArgs(uint highSurrogateOffset)
- {
- // If the high surrogate is not within its expected range, throw an exception
- // whose message fingers it as invalid. If it's within the expected range,
- // change the message to read that the low surrogate was the problem.
-
- if (highSurrogateOffset > CharUnicodeInfo.HIGH_SURROGATE_RANGE)
- {
- throw new ArgumentOutOfRangeException(
- paramName: "highSurrogate",
- message: SR.ArgumentOutOfRange_InvalidHighSurrogate);
- }
- else
- {
- throw new ArgumentOutOfRangeException(
- paramName: "lowSurrogate",
- message: SR.ArgumentOutOfRange_InvalidLowSurrogate);
- }
- }
-
- /*=============================ConvertToUtf32===================================
- ** Convert a character or a surrogate pair starting at index of the specified string
- ** to UTF32 value.
- ** The char pointed by index should be a surrogate pair or a BMP character.
- ** This method throws if a high-surrogate is not followed by a low surrogate.
- ** This method throws if a low surrogate is seen without preceding a high-surrogate.
- ==============================================================================*/
-
- public static int ConvertToUtf32(string s, int index)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- if (index < 0 || index >= s.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
- // Check if the character at index is a high surrogate.
- int temp1 = (int)s[index] - CharUnicodeInfo.HIGH_SURROGATE_START;
- if (temp1 >= 0 && temp1 <= 0x7ff)
- {
- // Found a surrogate char.
- if (temp1 <= 0x3ff)
- {
- // Found a high surrogate.
- if (index < s.Length - 1)
- {
- int temp2 = (int)s[index + 1] - CharUnicodeInfo.LOW_SURROGATE_START;
- if (temp2 >= 0 && temp2 <= 0x3ff)
- {
- // Found a low surrogate.
- return (temp1 * 0x400) + temp2 + UNICODE_PLANE01_START;
- }
- else
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidHighSurrogate, index), nameof(s));
- }
- }
- else
- {
- // Found a high surrogate at the end of the string.
- throw new ArgumentException(SR.Format(SR.Argument_InvalidHighSurrogate, index), nameof(s));
- }
- }
- else
- {
- // Find a low surrogate at the character pointed by index.
- throw new ArgumentException(SR.Format(SR.Argument_InvalidLowSurrogate, index), nameof(s));
- }
- }
- // Not a high-surrogate or low-surrogate. Genereate the UTF32 value for the BMP characters.
- return (int)s[index];
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/CharEnumerator.cs b/netcore/System.Private.CoreLib/shared/System/CharEnumerator.cs
deleted file mode 100644
index 955a2eefac2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/CharEnumerator.cs
+++ /dev/null
@@ -1,77 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Enumerates the characters on a string. skips range
-** checks.
-**
-**
-============================================================*/
-
-using System.Collections;
-using System.Collections.Generic;
-
-namespace System
-{
- public sealed class CharEnumerator : IEnumerator, IEnumerator<char>, IDisposable, ICloneable
- {
- private string? _str;
- private int _index;
- private char _currentElement;
-
- internal CharEnumerator(string str)
- {
- _str = str;
- _index = -1;
- }
-
- public object Clone()
- {
- return MemberwiseClone();
- }
-
- public bool MoveNext()
- {
- if (_index < (_str!.Length - 1))
- {
- _index++;
- _currentElement = _str[_index];
- return true;
- }
- else
- _index = _str.Length;
- return false;
- }
-
- public void Dispose()
- {
- if (_str != null)
- _index = _str.Length;
- _str = null;
- }
-
- object? IEnumerator.Current => Current;
-
- public char Current
- {
- get
- {
- if (_index == -1)
- throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted);
- if (_index >= _str!.Length)
- throw new InvalidOperationException(SR.InvalidOperation_EnumEnded);
- return _currentElement;
- }
- }
-
- public void Reset()
- {
- _currentElement = (char)0;
- _index = -1;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/ArrayList.cs b/netcore/System.Private.CoreLib/shared/System/Collections/ArrayList.cs
deleted file mode 100644
index cb7f2cdde7f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/ArrayList.cs
+++ /dev/null
@@ -1,2713 +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.
-
-/*============================================================
-**
-** Class: ArrayList
-**
-** Purpose: Implements a dynamically sized List as an array,
-** and provides many convenience methods for treating
-** an array as an IList.
-**
-===========================================================*/
-
-using System.Diagnostics;
-
-namespace System.Collections
-{
- // Implements a variable-size List that uses an array of objects to store the
- // elements. A ArrayList has a capacity, which is the allocated length
- // of the internal array. As elements are added to a ArrayList, the capacity
- // of the ArrayList is automatically increased as required by reallocating the
- // internal array.
- //
- [DebuggerTypeProxy(typeof(System.Collections.ArrayList.ArrayListDebugView))]
- [DebuggerDisplay("Count = {Count}")]
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ArrayList : IList, ICloneable
- {
- private object?[] _items = null!; // Do not rename (binary serialization)
- private int _size; // Do not rename (binary serialization)
- private int _version; // Do not rename (binary serialization)
-
- private const int _defaultCapacity = 4;
-
- // Note: this constructor is a bogus constructor that does nothing
- // and is for use only with SyncArrayList.
- internal ArrayList(bool trash)
- {
- }
-
- // Constructs a ArrayList. The list is initially empty and has a capacity
- // of zero. Upon adding the first element to the list the capacity is
- // increased to _defaultCapacity, and then increased in multiples of two as required.
- public ArrayList()
- {
- _items = Array.Empty<object>();
- }
-
- // Constructs a ArrayList with a given initial capacity. The list is
- // initially empty, but will have room for the given number of elements
- // before any reallocations are required.
- //
- public ArrayList(int capacity)
- {
- if (capacity < 0) throw new ArgumentOutOfRangeException(nameof(capacity), SR.Format(SR.ArgumentOutOfRange_MustBeNonNegNum, nameof(capacity)));
-
- if (capacity == 0)
- _items = Array.Empty<object>();
- else
- _items = new object[capacity];
- }
-
- // Constructs a ArrayList, copying the contents of the given collection. The
- // size and capacity of the new list will both be equal to the size of the
- // given collection.
- //
- public ArrayList(ICollection c)
- {
- if (c == null)
- throw new ArgumentNullException(nameof(c), SR.ArgumentNull_Collection);
-
- int count = c.Count;
- if (count == 0)
- {
- _items = Array.Empty<object>();
- }
- else
- {
- _items = new object[count];
- AddRange(c);
- }
- }
-
- // Gets and sets the capacity of this list. The capacity is the size of
- // the internal array used to hold items. When set, the internal
- // array of the list is reallocated to the given capacity.
- //
- public virtual int Capacity
- {
- get => _items.Length;
- set
- {
- if (value < _size)
- {
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_SmallCapacity);
- }
-
- // We don't want to update the version number when we change the capacity.
- // Some existing applications have dependency on this.
- if (value != _items.Length)
- {
- if (value > 0)
- {
- object[] newItems = new object[value];
- if (_size > 0)
- {
- Array.Copy(_items, newItems, _size);
- }
- _items = newItems;
- }
- else
- {
- _items = new object[_defaultCapacity];
- }
- }
- }
- }
-
- // Read-only property describing how many elements are in the List.
- public virtual int Count => _size;
-
- public virtual bool IsFixedSize => false;
-
-
- // Is this ArrayList read-only?
- public virtual bool IsReadOnly => false;
-
- // Is this ArrayList synchronized (thread-safe)?
- public virtual bool IsSynchronized => false;
-
- // Synchronization root for this object.
- public virtual object SyncRoot => this;
-
- // Sets or Gets the element at the given index.
- //
- public virtual object? this[int index]
- {
- get
- {
- if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- return _items[index];
- }
- set
- {
- if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- _items[index] = value;
- _version++;
- }
- }
-
- // Creates a ArrayList wrapper for a particular IList. This does not
- // copy the contents of the IList, but only wraps the IList. So any
- // changes to the underlying list will affect the ArrayList. This would
- // be useful if you want to Reverse a subrange of an IList, or want to
- // use a generic BinarySearch or Sort method without implementing one yourself.
- // However, since these methods are generic, the performance may not be
- // nearly as good for some operations as they would be on the IList itself.
- //
- public static ArrayList Adapter(IList list)
- {
- if (list == null)
- throw new ArgumentNullException(nameof(list));
- return new IListWrapper(list);
- }
-
- // Adds the given object to the end of this list. The size of the list is
- // increased by one. If required, the capacity of the list is doubled
- // before adding the new element.
- //
- public virtual int Add(object? value)
- {
- if (_size == _items.Length) EnsureCapacity(_size + 1);
- _items[_size] = value;
- _version++;
- return _size++;
- }
-
- // Adds the elements of the given collection to the end of this list. If
- // required, the capacity of the list is increased to twice the previous
- // capacity or the new size, whichever is larger.
- //
- public virtual void AddRange(ICollection c)
- {
- InsertRange(_size, c);
- }
-
- // Searches a section of the list for a given element using a binary search
- // algorithm. Elements of the list are compared to the search value using
- // the given IComparer interface. If comparer is null, elements of
- // the list are compared to the search value using the IComparable
- // interface, which in that case must be implemented by all elements of the
- // list and the given search value. This method assumes that the given
- // section of the list is already sorted; if this is not the case, the
- // result will be incorrect.
- //
- // The method returns the index of the given value in the list. If the
- // list does not contain the given value, the method returns a negative
- // integer. The bitwise complement operator (~) can be applied to a
- // negative result to produce the index of the first element (if any) that
- // is larger than the given search value. This is also the index at which
- // the search value should be inserted into the list in order for the list
- // to remain sorted.
- //
- // The method uses the Array.BinarySearch method to perform the
- // search.
- //
- public virtual int BinarySearch(int index, int count, object? value, IComparer? comparer)
- {
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_size - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- return Array.BinarySearch((Array)_items, index, count, value, comparer);
- }
-
- public virtual int BinarySearch(object? value)
- {
- return BinarySearch(0, Count, value, null);
- }
-
- public virtual int BinarySearch(object? value, IComparer? comparer)
- {
- return BinarySearch(0, Count, value, comparer);
- }
-
-
- // Clears the contents of ArrayList.
- public virtual void Clear()
- {
- if (_size > 0)
- {
- Array.Clear(_items, 0, _size); // Don't need to doc this but we clear the elements so that the gc can reclaim the references.
- _size = 0;
- }
- _version++;
- }
-
- // Clones this ArrayList, doing a shallow copy. (A copy is made of all
- // Object references in the ArrayList, but the Objects pointed to
- // are not cloned).
- public virtual object Clone()
- {
- ArrayList la = new ArrayList(_size);
- la._size = _size;
- la._version = _version;
- Array.Copy(_items, la._items, _size);
- return la;
- }
-
-
- // Contains returns true if the specified element is in the ArrayList.
- // It does a linear, O(n) search. Equality is determined by calling
- // item.Equals().
- //
- public virtual bool Contains(object? item)
- {
- if (item == null)
- {
- for (int i = 0; i < _size; i++)
- if (_items[i] == null)
- return true;
- return false;
- }
- else
- {
- for (int i = 0; i < _size; i++)
- if ((_items[i] != null) && (_items[i]!.Equals(item))) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- return true;
- return false;
- }
- }
-
- // Copies this ArrayList into array, which must be of a
- // compatible array type.
- //
- public virtual void CopyTo(Array array)
- {
- CopyTo(array, 0);
- }
-
- // Copies this ArrayList into array, which must be of a
- // compatible array type.
- //
- public virtual void CopyTo(Array array, int arrayIndex)
- {
- if ((array != null) && (array.Rank != 1))
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));
-
- // Delegate rest of error checking to Array.Copy.
- Array.Copy(_items, 0, array!, arrayIndex, _size);
- }
-
- // Copies a section of this list to the given array at the given index.
- //
- // The method uses the Array.Copy method to copy the elements.
- //
- public virtual void CopyTo(int index, Array array, int arrayIndex, int count)
- {
- if (_size - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- if ((array != null) && (array.Rank != 1))
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));
-
- // Delegate rest of error checking to Array.Copy.
- Array.Copy(_items, index, array!, arrayIndex, count);
- }
-
- // Ensures that the capacity of this list is at least the given minimum
- // value. If the current capacity of the list is less than min, the
- // capacity is increased to twice the current capacity or to min,
- // whichever is larger.
- private void EnsureCapacity(int min)
- {
- if (_items.Length < min)
- {
- int newCapacity = _items.Length == 0 ? _defaultCapacity : _items.Length * 2;
- // Allow the list to grow to maximum possible capacity (~2G elements) before encountering overflow.
- // Note that this check works even when _items.Length overflowed thanks to the (uint) cast
- if ((uint)newCapacity > Array.MaxArrayLength) newCapacity = Array.MaxArrayLength;
- if (newCapacity < min) newCapacity = min;
- Capacity = newCapacity;
- }
- }
-
- // Returns a list wrapper that is fixed at the current size. Operations
- // that add or remove items will fail, however, replacing items is allowed.
- //
- public static IList FixedSize(IList list)
- {
- if (list == null)
- throw new ArgumentNullException(nameof(list));
- return new FixedSizeList(list);
- }
-
- // Returns a list wrapper that is fixed at the current size. Operations
- // that add or remove items will fail, however, replacing items is allowed.
- //
- public static ArrayList FixedSize(ArrayList list)
- {
- if (list == null)
- throw new ArgumentNullException(nameof(list));
- return new FixedSizeArrayList(list);
- }
-
- // Returns an enumerator for this list with the given
- // permission for removal of elements. If modifications made to the list
- // while an enumeration is in progress, the MoveNext and
- // GetObject methods of the enumerator will throw an exception.
- //
- public virtual IEnumerator GetEnumerator()
- {
- return new ArrayListEnumeratorSimple(this);
- }
-
- // Returns an enumerator for a section of this list with the given
- // permission for removal of elements. If modifications made to the list
- // while an enumeration is in progress, the MoveNext and
- // GetObject methods of the enumerator will throw an exception.
- //
- public virtual IEnumerator GetEnumerator(int index, int count)
- {
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_size - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- return new ArrayListEnumerator(this, index, count);
- }
-
- // Returns the index of the first occurrence of a given value in a range of
- // this list. The list is searched forwards from beginning to end.
- // The elements of the list are compared to the given value using the
- // Object.Equals method.
- //
- // This method uses the Array.IndexOf method to perform the
- // search.
- //
- public virtual int IndexOf(object? value)
- {
- return Array.IndexOf((Array)_items, value, 0, _size);
- }
-
- // Returns the index of the first occurrence of a given value in a range of
- // this list. The list is searched forwards, starting at index
- // startIndex and ending at count number of elements. The
- // elements of the list are compared to the given value using the
- // Object.Equals method.
- //
- // This method uses the Array.IndexOf method to perform the
- // search.
- //
- public virtual int IndexOf(object? value, int startIndex)
- {
- if (startIndex > _size)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- return Array.IndexOf((Array)_items, value, startIndex, _size - startIndex);
- }
-
- // Returns the index of the first occurrence of a given value in a range of
- // this list. The list is searched forwards, starting at index
- // startIndex and up to count number of elements. The
- // elements of the list are compared to the given value using the
- // Object.Equals method.
- //
- // This method uses the Array.IndexOf method to perform the
- // search.
- //
- public virtual int IndexOf(object? value, int startIndex, int count)
- {
- if (startIndex > _size)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- if (count < 0 || startIndex > _size - count) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
- return Array.IndexOf((Array)_items, value, startIndex, count);
- }
-
- // Inserts an element into this list at a given index. The size of the list
- // is increased by one. If required, the capacity of the list is doubled
- // before inserting the new element.
- //
- public virtual void Insert(int index, object? value)
- {
- // Note that insertions at the end are legal.
- if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
-
- if (_size == _items.Length) EnsureCapacity(_size + 1);
- if (index < _size)
- {
- Array.Copy(_items, index, _items, index + 1, _size - index);
- }
- _items[index] = value;
- _size++;
- _version++;
- }
-
- // Inserts the elements of the given collection at a given index. If
- // required, the capacity of the list is increased to twice the previous
- // capacity or the new size, whichever is larger. Ranges may be added
- // to the end of the list by setting index to the ArrayList's size.
- //
- public virtual void InsertRange(int index, ICollection c)
- {
- if (c == null)
- throw new ArgumentNullException(nameof(c), SR.ArgumentNull_Collection);
- if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
-
- int count = c.Count;
- if (count > 0)
- {
- EnsureCapacity(_size + count);
- // shift existing items
- if (index < _size)
- {
- Array.Copy(_items, index, _items, index + count, _size - index);
- }
-
- object[] itemsToInsert = new object[count];
- c.CopyTo(itemsToInsert, 0);
- itemsToInsert.CopyTo(_items, index);
- _size += count;
- _version++;
- }
- }
-
- // Returns the index of the last occurrence of a given value in a range of
- // this list. The list is searched backwards, starting at the end
- // and ending at the first element in the list. The elements of the list
- // are compared to the given value using the Object.Equals method.
- //
- // This method uses the Array.LastIndexOf method to perform the
- // search.
- //
- public virtual int LastIndexOf(object? value)
- {
- return LastIndexOf(value, _size - 1, _size);
- }
-
- // Returns the index of the last occurrence of a given value in a range of
- // this list. The list is searched backwards, starting at index
- // startIndex and ending at the first element in the list. The
- // elements of the list are compared to the given value using the
- // Object.Equals method.
- //
- // This method uses the Array.LastIndexOf method to perform the
- // search.
- //
- public virtual int LastIndexOf(object? value, int startIndex)
- {
- if (startIndex >= _size)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- return LastIndexOf(value, startIndex, startIndex + 1);
- }
-
- // Returns the index of the last occurrence of a given value in a range of
- // this list. The list is searched backwards, starting at index
- // startIndex and up to count elements. The elements of
- // the list are compared to the given value using the Object.Equals
- // method.
- //
- // This method uses the Array.LastIndexOf method to perform the
- // search.
- //
- public virtual int LastIndexOf(object? value, int startIndex, int count)
- {
- if (Count != 0 && (startIndex < 0 || count < 0))
- throw new ArgumentOutOfRangeException(startIndex < 0 ? nameof(startIndex) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (_size == 0) // Special case for an empty list
- return -1;
-
- if (startIndex >= _size || count > startIndex + 1)
- throw new ArgumentOutOfRangeException(startIndex >= _size ? nameof(startIndex) : nameof(count), SR.ArgumentOutOfRange_BiggerThanCollection);
-
- return Array.LastIndexOf((Array)_items, value, startIndex, count);
- }
-
- // Returns a read-only IList wrapper for the given IList.
- //
- public static IList ReadOnly(IList list)
- {
- if (list == null)
- throw new ArgumentNullException(nameof(list));
- return new ReadOnlyList(list);
- }
-
- // Returns a read-only ArrayList wrapper for the given ArrayList.
- //
- public static ArrayList ReadOnly(ArrayList list)
- {
- if (list == null)
- throw new ArgumentNullException(nameof(list));
- return new ReadOnlyArrayList(list);
- }
-
- // Removes the element at the given index. The size of the list is
- // decreased by one.
- //
- public virtual void Remove(object? obj)
- {
- int index = IndexOf(obj);
- if (index >= 0)
- RemoveAt(index);
- }
-
- // Removes the element at the given index. The size of the list is
- // decreased by one.
- //
- public virtual void RemoveAt(int index)
- {
- if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
-
- _size--;
- if (index < _size)
- {
- Array.Copy(_items, index + 1, _items, index, _size - index);
- }
- _items[_size] = null;
- _version++;
- }
-
- // Removes a range of elements from this list.
- //
- public virtual void RemoveRange(int index, int count)
- {
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_size - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- if (count > 0)
- {
- int i = _size;
- _size -= count;
- if (index < _size)
- {
- Array.Copy(_items, index + count, _items, index, _size - index);
- }
- while (i > _size) _items[--i] = null;
- _version++;
- }
- }
-
- // Returns an IList that contains count copies of value.
- //
- public static ArrayList Repeat(object? value, int count)
- {
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- ArrayList list = new ArrayList((count > _defaultCapacity) ? count : _defaultCapacity);
- for (int i = 0; i < count; i++)
- list.Add(value);
- return list;
- }
-
- // Reverses the elements in this list.
- public virtual void Reverse()
- {
- Reverse(0, Count);
- }
-
- // Reverses the elements in a range of this list. Following a call to this
- // method, an element in the range given by index and count
- // which was previously located at index i will now be located at
- // index index + (index + count - i - 1).
- //
- // This method uses the Array.Reverse method to reverse the
- // elements.
- //
- public virtual void Reverse(int index, int count)
- {
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_size - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- Array.Reverse(_items, index, count);
- _version++;
- }
-
- // Sets the elements starting at the given index to the elements of the
- // given collection.
- //
- public virtual void SetRange(int index, ICollection c)
- {
- if (c == null) throw new ArgumentNullException(nameof(c), SR.ArgumentNull_Collection);
-
- int count = c.Count;
- if (index < 0 || index > _size - count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
-
- if (count > 0)
- {
- c.CopyTo(_items, index);
- _version++;
- }
- }
-
- public virtual ArrayList GetRange(int index, int count)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_size - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- return new Range(this, index, count);
- }
-
- // Sorts the elements in this list. Uses the default comparer and
- // Array.Sort.
- public virtual void Sort()
- {
- Sort(0, Count, Comparer.Default);
- }
-
- // Sorts the elements in this list. Uses Array.Sort with the
- // provided comparer.
- public virtual void Sort(IComparer? comparer)
- {
- Sort(0, Count, comparer);
- }
-
- // Sorts the elements in a section of this list. The sort compares the
- // elements to each other using the given IComparer interface. If
- // comparer is null, the elements are compared to each other using
- // the IComparable interface, which in that case must be implemented by all
- // elements of the list.
- //
- // This method uses the Array.Sort method to sort the elements.
- //
- public virtual void Sort(int index, int count, IComparer? comparer)
- {
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_size - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- Array.Sort(_items, index, count, comparer);
- _version++;
- }
-
- // Returns a thread-safe wrapper around an IList.
- //
- public static IList Synchronized(IList list)
- {
- if (list == null)
- throw new ArgumentNullException(nameof(list));
- return new SyncIList(list);
- }
-
- // Returns a thread-safe wrapper around a ArrayList.
- //
- public static ArrayList Synchronized(ArrayList list)
- {
- if (list == null)
- throw new ArgumentNullException(nameof(list));
- return new SyncArrayList(list);
- }
-
- // ToArray returns a new Object array containing the contents of the ArrayList.
- // This requires copying the ArrayList, which is an O(n) operation.
- public virtual object?[] ToArray()
- {
- if (_size == 0)
- return Array.Empty<object>();
-
- object?[] array = new object[_size];
- Array.Copy(_items, array, _size);
- return array;
- }
-
- // ToArray returns a new array of a particular type containing the contents
- // of the ArrayList. This requires copying the ArrayList and potentially
- // downcasting all elements. This copy may fail and is an O(n) operation.
- // Internally, this implementation calls Array.Copy.
- //
- public virtual Array ToArray(Type type)
- {
- if (type == null)
- throw new ArgumentNullException(nameof(type));
-
- Array array = Array.CreateInstance(type, _size);
- Array.Copy(_items, array, _size);
- return array;
- }
-
- // Sets the capacity of this list to the size of the list. This method can
- // be used to minimize a list's memory overhead once it is known that no
- // new elements will be added to the list. To completely clear a list and
- // release all memory referenced by the list, execute the following
- // statements:
- //
- // list.Clear();
- // list.TrimToSize();
- //
- public virtual void TrimToSize()
- {
- Capacity = _size;
- }
-
-
- // This class wraps an IList, exposing it as a ArrayList
- // Note this requires reimplementing half of ArrayList...
- private class IListWrapper : ArrayList
- {
- private readonly IList _list;
-
- internal IListWrapper(IList list)
- {
- _list = list;
- _version = 0; // list doesn't not contain a version number
- }
-
- public override int Capacity
- {
- get => _list.Count;
- set
- {
- if (value < Count) throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_SmallCapacity);
- }
- }
-
- public override int Count => _list.Count;
-
- public override bool IsReadOnly => _list.IsReadOnly;
-
- public override bool IsFixedSize => _list.IsFixedSize;
-
-
- public override bool IsSynchronized => _list.IsSynchronized;
-
- public override object? this[int index]
- {
- get => _list[index];
- set
- {
- _list[index] = value;
- _version++;
- }
- }
-
- public override object SyncRoot => _list.SyncRoot;
-
- public override int Add(object? obj)
- {
- int i = _list.Add(obj);
- _version++;
- return i;
- }
-
- public override void AddRange(ICollection c)
- {
- InsertRange(Count, c);
- }
-
- // Other overloads with automatically work
- public override int BinarySearch(int index, int count, object? value, IComparer? comparer)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (Count - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- comparer ??= Comparer.Default;
-
- int lo = index;
- int hi = index + count - 1;
- int mid;
- while (lo <= hi)
- {
- mid = (lo + hi) / 2;
- int r = comparer.Compare(value, _list[mid]);
- if (r == 0)
- return mid;
- if (r < 0)
- hi = mid - 1;
- else
- lo = mid + 1;
- }
- // return bitwise complement of the first element greater than value.
- // Since hi is less than lo now, ~lo is the correct item.
- return ~lo;
- }
-
- public override void Clear()
- {
- // If _list is an array, it will support Clear method.
- // We shouldn't allow clear operation on a FixedSized ArrayList
- if (_list.IsFixedSize)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- _list.Clear();
- _version++;
- }
-
- public override object Clone()
- {
- // This does not do a shallow copy of _list into a ArrayList!
- // This clones the IListWrapper, creating another wrapper class!
- return new IListWrapper(_list);
- }
-
- public override bool Contains(object? obj)
- {
- return _list.Contains(obj);
- }
-
- public override void CopyTo(Array array, int index)
- {
- _list.CopyTo(array, index);
- }
-
- public override void CopyTo(int index, Array array, int arrayIndex, int count)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
- if (index < 0 || arrayIndex < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(arrayIndex), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - arrayIndex < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- if (array.Rank != 1)
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));
-
- if (_list.Count - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- for (int i = index; i < index + count; i++)
- array.SetValue(_list[i], arrayIndex++);
- }
-
- public override IEnumerator GetEnumerator()
- {
- return _list.GetEnumerator();
- }
-
- public override IEnumerator GetEnumerator(int index, int count)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (_list.Count - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- return new IListWrapperEnumWrapper(this, index, count);
- }
-
- public override int IndexOf(object? value)
- {
- return _list.IndexOf(value);
- }
-
- public override int IndexOf(object? value, int startIndex)
- {
- return IndexOf(value, startIndex, _list.Count - startIndex);
- }
-
- public override int IndexOf(object? value, int startIndex, int count)
- {
- if (startIndex < 0 || startIndex > Count) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- if (count < 0 || startIndex > Count - count) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
-
- int endIndex = startIndex + count;
- if (value == null)
- {
- for (int i = startIndex; i < endIndex; i++)
- if (_list[i] == null)
- return i;
- return -1;
- }
- else
- {
- for (int i = startIndex; i < endIndex; i++)
- if (_list[i] != null && _list[i]!.Equals(value)) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- return i;
- return -1;
- }
- }
-
- public override void Insert(int index, object? obj)
- {
- _list.Insert(index, obj);
- _version++;
- }
-
- public override void InsertRange(int index, ICollection c)
- {
- if (c == null)
- throw new ArgumentNullException(nameof(c), SR.ArgumentNull_Collection);
- if (index < 0 || index > Count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
-
- if (c.Count > 0)
- {
- if (_list is ArrayList al)
- {
- // We need to special case ArrayList.
- // When c is a range of _list, we need to handle this in a special way.
- // See ArrayList.InsertRange for details.
- al.InsertRange(index, c);
- }
- else
- {
- IEnumerator en = c.GetEnumerator();
- while (en.MoveNext())
- {
- _list.Insert(index++, en.Current);
- }
- }
- _version++;
- }
- }
-
- public override int LastIndexOf(object? value)
- {
- return LastIndexOf(value, _list.Count - 1, _list.Count);
- }
-
- public override int LastIndexOf(object? value, int startIndex)
- {
- return LastIndexOf(value, startIndex, startIndex + 1);
- }
-
- public override int LastIndexOf(object? value, int startIndex, int count)
- {
- if (_list.Count == 0)
- return -1;
-
- if (startIndex < 0 || startIndex >= _list.Count) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- if (count < 0 || count > startIndex + 1) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
-
- int endIndex = startIndex - count + 1;
- if (value == null)
- {
- for (int i = startIndex; i >= endIndex; i--)
- if (_list[i] == null)
- return i;
- return -1;
- }
- else
- {
- for (int i = startIndex; i >= endIndex; i--)
- if (_list[i] != null && _list[i]!.Equals(value)) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- return i;
- return -1;
- }
- }
-
- public override void Remove(object? value)
- {
- int index = IndexOf(value);
- if (index >= 0)
- RemoveAt(index);
- }
-
- public override void RemoveAt(int index)
- {
- _list.RemoveAt(index);
- _version++;
- }
-
- public override void RemoveRange(int index, int count)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (_list.Count - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- if (count > 0) // be consistent with ArrayList
- _version++;
-
- while (count > 0)
- {
- _list.RemoveAt(index);
- count--;
- }
- }
-
- public override void Reverse(int index, int count)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (_list.Count - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- int i = index;
- int j = index + count - 1;
- while (i < j)
- {
- object? tmp = _list[i];
- _list[i++] = _list[j];
- _list[j--] = tmp;
- }
- _version++;
- }
-
- public override void SetRange(int index, ICollection c)
- {
- if (c == null)
- {
- throw new ArgumentNullException(nameof(c), SR.ArgumentNull_Collection);
- }
-
- if (index < 0 || index > _list.Count - c.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
-
- if (c.Count > 0)
- {
- IEnumerator en = c.GetEnumerator();
- while (en.MoveNext())
- {
- _list[index++] = en.Current;
- }
- _version++;
- }
- }
-
- public override ArrayList GetRange(int index, int count)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_list.Count - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- return new Range(this, index, count);
- }
-
- public override void Sort(int index, int count, IComparer? comparer)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_list.Count - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- object[] array = new object[count];
- CopyTo(index, array, 0, count);
- Array.Sort(array, 0, count, comparer);
- for (int i = 0; i < count; i++)
- _list[i + index] = array[i];
-
- _version++;
- }
-
-
- public override object?[] ToArray()
- {
- if (Count == 0)
- return Array.Empty<object?>();
-
- object?[] array = new object[Count];
- _list.CopyTo(array, 0);
- return array;
- }
-
- public override Array ToArray(Type type)
- {
- if (type == null)
- throw new ArgumentNullException(nameof(type));
-
- Array array = Array.CreateInstance(type, _list.Count);
- _list.CopyTo(array, 0);
- return array;
- }
-
- public override void TrimToSize()
- {
- // Can't really do much here...
- }
-
- // This is the enumerator for an IList that's been wrapped in another
- // class that implements all of ArrayList's methods.
- private sealed class IListWrapperEnumWrapper : IEnumerator, ICloneable
- {
- private IEnumerator _en = null!;
- private int _remaining;
- private int _initialStartIndex; // for reset
- private int _initialCount; // for reset
- private bool _firstCall; // firstCall to MoveNext
-
- internal IListWrapperEnumWrapper(IListWrapper listWrapper, int startIndex, int count)
- {
- _en = listWrapper.GetEnumerator();
- _initialStartIndex = startIndex;
- _initialCount = count;
- while (startIndex-- > 0 && _en.MoveNext()) ;
- _remaining = count;
- _firstCall = true;
- }
-
- private IListWrapperEnumWrapper() { }
-
- public object Clone()
- {
- var clone = new IListWrapperEnumWrapper();
- clone._en = (IEnumerator)((ICloneable)_en).Clone();
- clone._initialStartIndex = _initialStartIndex;
- clone._initialCount = _initialCount;
- clone._remaining = _remaining;
- clone._firstCall = _firstCall;
- return clone;
- }
-
- public bool MoveNext()
- {
- if (_firstCall)
- {
- _firstCall = false;
- return _remaining-- > 0 && _en.MoveNext();
- }
- if (_remaining < 0)
- return false;
- bool r = _en.MoveNext();
- return r && _remaining-- > 0;
- }
-
- public object? Current
- {
- get
- {
- if (_firstCall)
- throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted);
- if (_remaining < 0)
- throw new InvalidOperationException(SR.InvalidOperation_EnumEnded);
- return _en.Current;
- }
- }
-
- public void Reset()
- {
- _en.Reset();
- int startIndex = _initialStartIndex;
- while (startIndex-- > 0 && _en.MoveNext()) ;
- _remaining = _initialCount;
- _firstCall = true;
- }
- }
- }
-
- private class SyncArrayList : ArrayList
- {
- private readonly ArrayList _list;
- private readonly object _root;
-
- internal SyncArrayList(ArrayList list)
- : base(false)
- {
- _list = list;
- _root = list.SyncRoot;
- }
-
- public override int Capacity
- {
- get
- {
- lock (_root)
- {
- return _list.Capacity;
- }
- }
- set
- {
- lock (_root)
- {
- _list.Capacity = value;
- }
- }
- }
-
- public override int Count
- {
- get { lock (_root) { return _list.Count; } }
- }
-
- public override bool IsReadOnly => _list.IsReadOnly;
-
- public override bool IsFixedSize => _list.IsFixedSize;
-
-
- public override bool IsSynchronized => true;
-
- public override object? this[int index]
- {
- get
- {
- lock (_root)
- {
- return _list[index];
- }
- }
- set
- {
- lock (_root)
- {
- _list[index] = value;
- }
- }
- }
-
- public override object SyncRoot => _root;
-
- public override int Add(object? value)
- {
- lock (_root)
- {
- return _list.Add(value);
- }
- }
-
- public override void AddRange(ICollection c)
- {
- lock (_root)
- {
- _list.AddRange(c);
- }
- }
-
- public override int BinarySearch(object? value)
- {
- lock (_root)
- {
- return _list.BinarySearch(value);
- }
- }
-
- public override int BinarySearch(object? value, IComparer? comparer)
- {
- lock (_root)
- {
- return _list.BinarySearch(value, comparer);
- }
- }
-
- public override int BinarySearch(int index, int count, object? value, IComparer? comparer)
- {
- lock (_root)
- {
- return _list.BinarySearch(index, count, value, comparer);
- }
- }
-
- public override void Clear()
- {
- lock (_root)
- {
- _list.Clear();
- }
- }
-
- public override object Clone()
- {
- lock (_root)
- {
- return new SyncArrayList((ArrayList)_list.Clone());
- }
- }
-
- public override bool Contains(object? item)
- {
- lock (_root)
- {
- return _list.Contains(item);
- }
- }
-
- public override void CopyTo(Array array)
- {
- lock (_root)
- {
- _list.CopyTo(array);
- }
- }
-
- public override void CopyTo(Array array, int index)
- {
- lock (_root)
- {
- _list.CopyTo(array, index);
- }
- }
-
- public override void CopyTo(int index, Array array, int arrayIndex, int count)
- {
- lock (_root)
- {
- _list.CopyTo(index, array, arrayIndex, count);
- }
- }
-
- public override IEnumerator GetEnumerator()
- {
- lock (_root)
- {
- return _list.GetEnumerator();
- }
- }
-
- public override IEnumerator GetEnumerator(int index, int count)
- {
- lock (_root)
- {
- return _list.GetEnumerator(index, count);
- }
- }
-
- public override int IndexOf(object? value)
- {
- lock (_root)
- {
- return _list.IndexOf(value);
- }
- }
-
- public override int IndexOf(object? value, int startIndex)
- {
- lock (_root)
- {
- return _list.IndexOf(value, startIndex);
- }
- }
-
- public override int IndexOf(object? value, int startIndex, int count)
- {
- lock (_root)
- {
- return _list.IndexOf(value, startIndex, count);
- }
- }
-
- public override void Insert(int index, object? value)
- {
- lock (_root)
- {
- _list.Insert(index, value);
- }
- }
-
- public override void InsertRange(int index, ICollection c)
- {
- lock (_root)
- {
- _list.InsertRange(index, c);
- }
- }
-
- public override int LastIndexOf(object? value)
- {
- lock (_root)
- {
- return _list.LastIndexOf(value);
- }
- }
-
- public override int LastIndexOf(object? value, int startIndex)
- {
- lock (_root)
- {
- return _list.LastIndexOf(value, startIndex);
- }
- }
-
- public override int LastIndexOf(object? value, int startIndex, int count)
- {
- lock (_root)
- {
- return _list.LastIndexOf(value, startIndex, count);
- }
- }
-
- public override void Remove(object? value)
- {
- lock (_root)
- {
- _list.Remove(value);
- }
- }
-
- public override void RemoveAt(int index)
- {
- lock (_root)
- {
- _list.RemoveAt(index);
- }
- }
-
- public override void RemoveRange(int index, int count)
- {
- lock (_root)
- {
- _list.RemoveRange(index, count);
- }
- }
-
- public override void Reverse(int index, int count)
- {
- lock (_root)
- {
- _list.Reverse(index, count);
- }
- }
-
- public override void SetRange(int index, ICollection c)
- {
- lock (_root)
- {
- _list.SetRange(index, c);
- }
- }
-
- public override ArrayList GetRange(int index, int count)
- {
- lock (_root)
- {
- return _list.GetRange(index, count);
- }
- }
-
- public override void Sort()
- {
- lock (_root)
- {
- _list.Sort();
- }
- }
-
- public override void Sort(IComparer? comparer)
- {
- lock (_root)
- {
- _list.Sort(comparer);
- }
- }
-
- public override void Sort(int index, int count, IComparer? comparer)
- {
- lock (_root)
- {
- _list.Sort(index, count, comparer);
- }
- }
-
- public override object?[] ToArray()
- {
- lock (_root)
- {
- return _list.ToArray();
- }
- }
-
- public override Array ToArray(Type type)
- {
- lock (_root)
- {
- return _list.ToArray(type);
- }
- }
-
- public override void TrimToSize()
- {
- lock (_root)
- {
- _list.TrimToSize();
- }
- }
- }
-
-
- private class SyncIList : IList
- {
- private readonly IList _list;
- private readonly object _root;
-
- internal SyncIList(IList list)
- {
- _list = list;
- _root = list.SyncRoot;
- }
-
- public virtual int Count
- {
- get { lock (_root) { return _list.Count; } }
- }
-
- public virtual bool IsReadOnly => _list.IsReadOnly;
-
- public virtual bool IsFixedSize => _list.IsFixedSize;
-
-
- public virtual bool IsSynchronized => true;
-
- public virtual object? this[int index]
- {
- get
- {
- lock (_root)
- {
- return _list[index];
- }
- }
- set
- {
- lock (_root)
- {
- _list[index] = value;
- }
- }
- }
-
- public virtual object SyncRoot => _root;
-
- public virtual int Add(object? value)
- {
- lock (_root)
- {
- return _list.Add(value);
- }
- }
-
-
- public virtual void Clear()
- {
- lock (_root)
- {
- _list.Clear();
- }
- }
-
- public virtual bool Contains(object? item)
- {
- lock (_root)
- {
- return _list.Contains(item);
- }
- }
-
- public virtual void CopyTo(Array array, int index)
- {
- lock (_root)
- {
- _list.CopyTo(array, index);
- }
- }
-
- public virtual IEnumerator GetEnumerator()
- {
- lock (_root)
- {
- return _list.GetEnumerator();
- }
- }
-
- public virtual int IndexOf(object? value)
- {
- lock (_root)
- {
- return _list.IndexOf(value);
- }
- }
-
- public virtual void Insert(int index, object? value)
- {
- lock (_root)
- {
- _list.Insert(index, value);
- }
- }
-
- public virtual void Remove(object? value)
- {
- lock (_root)
- {
- _list.Remove(value);
- }
- }
-
- public virtual void RemoveAt(int index)
- {
- lock (_root)
- {
- _list.RemoveAt(index);
- }
- }
- }
-
- private class FixedSizeList : IList
- {
- private readonly IList _list;
-
- internal FixedSizeList(IList l)
- {
- _list = l;
- }
-
- public virtual int Count => _list.Count;
-
- public virtual bool IsReadOnly => _list.IsReadOnly;
-
- public virtual bool IsFixedSize => true;
-
- public virtual bool IsSynchronized => _list.IsSynchronized;
-
- public virtual object? this[int index]
- {
- get => _list[index];
- set => _list[index] = value;
- }
-
- public virtual object SyncRoot => _list.SyncRoot;
-
- public virtual int Add(object? obj)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public virtual void Clear()
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public virtual bool Contains(object? obj)
- {
- return _list.Contains(obj);
- }
-
- public virtual void CopyTo(Array array, int index)
- {
- _list.CopyTo(array, index);
- }
-
- public virtual IEnumerator GetEnumerator()
- {
- return _list.GetEnumerator();
- }
-
- public virtual int IndexOf(object? value)
- {
- return _list.IndexOf(value);
- }
-
- public virtual void Insert(int index, object? obj)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public virtual void Remove(object? value)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public virtual void RemoveAt(int index)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
- }
-
- private class FixedSizeArrayList : ArrayList
- {
- private ArrayList _list;
-
- internal FixedSizeArrayList(ArrayList l)
- {
- _list = l;
- _version = _list._version;
- }
-
- public override int Count => _list.Count;
-
- public override bool IsReadOnly => _list.IsReadOnly;
-
- public override bool IsFixedSize => true;
-
- public override bool IsSynchronized => _list.IsSynchronized;
-
- public override object? this[int index]
- {
- get => _list[index];
- set
- {
- _list[index] = value;
- _version = _list._version;
- }
- }
-
- public override object SyncRoot => _list.SyncRoot;
-
- public override int Add(object? obj)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public override void AddRange(ICollection c)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public override int BinarySearch(int index, int count, object? value, IComparer? comparer)
- {
- return _list.BinarySearch(index, count, value, comparer);
- }
-
- public override int Capacity
- {
- get => _list.Capacity;
- set => throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public override void Clear()
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public override object Clone()
- {
- FixedSizeArrayList arrayList = new FixedSizeArrayList(_list);
- arrayList._list = (ArrayList)_list.Clone();
- return arrayList;
- }
-
- public override bool Contains(object? obj)
- {
- return _list.Contains(obj);
- }
-
- public override void CopyTo(Array array, int index)
- {
- _list.CopyTo(array, index);
- }
-
- public override void CopyTo(int index, Array array, int arrayIndex, int count)
- {
- _list.CopyTo(index, array, arrayIndex, count);
- }
-
- public override IEnumerator GetEnumerator()
- {
- return _list.GetEnumerator();
- }
-
- public override IEnumerator GetEnumerator(int index, int count)
- {
- return _list.GetEnumerator(index, count);
- }
-
- public override int IndexOf(object? value)
- {
- return _list.IndexOf(value);
- }
-
- public override int IndexOf(object? value, int startIndex)
- {
- return _list.IndexOf(value, startIndex);
- }
-
- public override int IndexOf(object? value, int startIndex, int count)
- {
- return _list.IndexOf(value, startIndex, count);
- }
-
- public override void Insert(int index, object? obj)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public override void InsertRange(int index, ICollection c)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public override int LastIndexOf(object? value)
- {
- return _list.LastIndexOf(value);
- }
-
- public override int LastIndexOf(object? value, int startIndex)
- {
- return _list.LastIndexOf(value, startIndex);
- }
-
- public override int LastIndexOf(object? value, int startIndex, int count)
- {
- return _list.LastIndexOf(value, startIndex, count);
- }
-
- public override void Remove(object? value)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public override void RemoveAt(int index)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public override void RemoveRange(int index, int count)
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
-
- public override void SetRange(int index, ICollection c)
- {
- _list.SetRange(index, c);
- _version = _list._version;
- }
-
- public override ArrayList GetRange(int index, int count)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (Count - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- return new Range(this, index, count);
- }
-
- public override void Reverse(int index, int count)
- {
- _list.Reverse(index, count);
- _version = _list._version;
- }
-
- public override void Sort(int index, int count, IComparer? comparer)
- {
- _list.Sort(index, count, comparer);
- _version = _list._version;
- }
-
- public override object?[] ToArray()
- {
- return _list.ToArray();
- }
-
- public override Array ToArray(Type type)
- {
- return _list.ToArray(type);
- }
-
- public override void TrimToSize()
- {
- throw new NotSupportedException(SR.NotSupported_FixedSizeCollection);
- }
- }
-
- private class ReadOnlyList : IList
- {
- private readonly IList _list;
-
- internal ReadOnlyList(IList l)
- {
- _list = l;
- }
-
- public virtual int Count => _list.Count;
-
- public virtual bool IsReadOnly => true;
-
- public virtual bool IsFixedSize => true;
-
- public virtual bool IsSynchronized => _list.IsSynchronized;
-
- public virtual object? this[int index]
- {
- get => _list[index];
- set => throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public virtual object SyncRoot => _list.SyncRoot;
-
- public virtual int Add(object? obj)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public virtual void Clear()
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public virtual bool Contains(object? obj)
- {
- return _list.Contains(obj);
- }
-
- public virtual void CopyTo(Array array, int index)
- {
- _list.CopyTo(array, index);
- }
-
- public virtual IEnumerator GetEnumerator()
- {
- return _list.GetEnumerator();
- }
-
- public virtual int IndexOf(object? value)
- {
- return _list.IndexOf(value);
- }
-
- public virtual void Insert(int index, object? obj)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public virtual void Remove(object? value)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public virtual void RemoveAt(int index)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
- }
-
- private class ReadOnlyArrayList : ArrayList
- {
- private ArrayList _list;
-
- internal ReadOnlyArrayList(ArrayList l)
- {
- _list = l;
- }
-
- public override int Count => _list.Count;
-
- public override bool IsReadOnly => true;
-
- public override bool IsFixedSize => true;
-
- public override bool IsSynchronized => _list.IsSynchronized;
-
- public override object? this[int index]
- {
- get => _list[index];
- set => throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override object SyncRoot => _list.SyncRoot;
-
- public override int Add(object? obj)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override void AddRange(ICollection c)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override int BinarySearch(int index, int count, object? value, IComparer? comparer)
- {
- return _list.BinarySearch(index, count, value, comparer);
- }
-
-
- public override int Capacity
- {
- get => _list.Capacity;
- set => throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override void Clear()
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override object Clone()
- {
- ReadOnlyArrayList arrayList = new ReadOnlyArrayList(_list);
- arrayList._list = (ArrayList)_list.Clone();
- return arrayList;
- }
-
- public override bool Contains(object? obj)
- {
- return _list.Contains(obj);
- }
-
- public override void CopyTo(Array array, int index)
- {
- _list.CopyTo(array, index);
- }
-
- public override void CopyTo(int index, Array array, int arrayIndex, int count)
- {
- _list.CopyTo(index, array, arrayIndex, count);
- }
-
- public override IEnumerator GetEnumerator()
- {
- return _list.GetEnumerator();
- }
-
- public override IEnumerator GetEnumerator(int index, int count)
- {
- return _list.GetEnumerator(index, count);
- }
-
- public override int IndexOf(object? value)
- {
- return _list.IndexOf(value);
- }
-
- public override int IndexOf(object? value, int startIndex)
- {
- return _list.IndexOf(value, startIndex);
- }
-
- public override int IndexOf(object? value, int startIndex, int count)
- {
- return _list.IndexOf(value, startIndex, count);
- }
-
- public override void Insert(int index, object? obj)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override void InsertRange(int index, ICollection c)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override int LastIndexOf(object? value)
- {
- return _list.LastIndexOf(value);
- }
-
- public override int LastIndexOf(object? value, int startIndex)
- {
- return _list.LastIndexOf(value, startIndex);
- }
-
- public override int LastIndexOf(object? value, int startIndex, int count)
- {
- return _list.LastIndexOf(value, startIndex, count);
- }
-
- public override void Remove(object? value)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override void RemoveAt(int index)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override void RemoveRange(int index, int count)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override void SetRange(int index, ICollection c)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override ArrayList GetRange(int index, int count)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (Count - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- return new Range(this, index, count);
- }
-
- public override void Reverse(int index, int count)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override void Sort(int index, int count, IComparer? comparer)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public override object?[] ToArray()
- {
- return _list.ToArray();
- }
-
- public override Array ToArray(Type type)
- {
- return _list.ToArray(type);
- }
-
- public override void TrimToSize()
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
- }
-
-
- // Implements an enumerator for a ArrayList. The enumerator uses the
- // internal version number of the list to ensure that no modifications are
- // made to the list while an enumeration is in progress.
- private sealed class ArrayListEnumerator : IEnumerator, ICloneable
- {
- private readonly ArrayList _list;
- private int _index;
- private readonly int _endIndex; // Where to stop.
- private readonly int _version;
- private object? _currentElement;
- private readonly int _startIndex; // Save this for Reset.
-
- internal ArrayListEnumerator(ArrayList list, int index, int count)
- {
- _list = list;
- _startIndex = index;
- _index = index - 1;
- _endIndex = _index + count; // last valid index
- _version = list._version;
- _currentElement = null;
- }
-
- public object Clone() => MemberwiseClone();
-
- public bool MoveNext()
- {
- if (_version != _list._version) throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- if (_index < _endIndex)
- {
- _currentElement = _list[++_index];
- return true;
- }
- else
- {
- _index = _endIndex + 1;
- }
-
- return false;
- }
-
- public object? Current
- {
- get
- {
- if (_index < _startIndex)
- throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted);
- else if (_index > _endIndex)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumEnded);
- }
- return _currentElement;
- }
- }
-
- public void Reset()
- {
- if (_version != _list._version) throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- _index = _startIndex - 1;
- }
- }
-
- // Implementation of a generic list subrange. An instance of this class
- // is returned by the default implementation of List.GetRange.
- private class Range : ArrayList
- {
- private ArrayList _baseList;
- private readonly int _baseIndex;
- private int _baseSize;
- private int _baseVersion;
-
- internal Range(ArrayList list, int index, int count) : base(false)
- {
- _baseList = list;
- _baseIndex = index;
- _baseSize = count;
- _baseVersion = list._version;
- // we also need to update _version field to make Range of Range work
- _version = list._version;
- }
-
- private void InternalUpdateRange()
- {
- if (_baseVersion != _baseList._version)
- throw new InvalidOperationException(SR.InvalidOperation_UnderlyingArrayListChanged);
- }
-
- private void InternalUpdateVersion()
- {
- _baseVersion++;
- _version++;
- }
-
- public override int Add(object? value)
- {
- InternalUpdateRange();
- _baseList.Insert(_baseIndex + _baseSize, value);
- InternalUpdateVersion();
- return _baseSize++;
- }
-
- public override void AddRange(ICollection c)
- {
- if (c == null)
- {
- throw new ArgumentNullException(nameof(c));
- }
-
- InternalUpdateRange();
- int count = c.Count;
- if (count > 0)
- {
- _baseList.InsertRange(_baseIndex + _baseSize, c);
- InternalUpdateVersion();
- _baseSize += count;
- }
- }
-
- public override int BinarySearch(int index, int count, object? value, IComparer? comparer)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_baseSize - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- InternalUpdateRange();
-
- int i = _baseList.BinarySearch(_baseIndex + index, count, value, comparer);
- if (i >= 0) return i - _baseIndex;
- return i + _baseIndex;
- }
-
- public override int Capacity
- {
- get => _baseList.Capacity;
-
- set
- {
- if (value < Count) throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_SmallCapacity);
- }
- }
-
-
- public override void Clear()
- {
- InternalUpdateRange();
- if (_baseSize != 0)
- {
- _baseList.RemoveRange(_baseIndex, _baseSize);
- InternalUpdateVersion();
- _baseSize = 0;
- }
- }
-
- public override object Clone()
- {
- InternalUpdateRange();
- Range arrayList = new Range(_baseList, _baseIndex, _baseSize);
- arrayList._baseList = (ArrayList)_baseList.Clone();
- return arrayList;
- }
-
- public override bool Contains(object? item)
- {
- InternalUpdateRange();
- if (item == null)
- {
- for (int i = 0; i < _baseSize; i++)
- if (_baseList[_baseIndex + i] == null)
- return true;
- return false;
- }
- else
- {
- for (int i = 0; i < _baseSize; i++)
- if (_baseList[_baseIndex + i] != null && _baseList[_baseIndex + i]!.Equals(item)) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- return true;
- return false;
- }
- }
-
- public override void CopyTo(Array array, int index)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
- if (array.Rank != 1)
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - index < _baseSize)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- InternalUpdateRange();
- _baseList.CopyTo(_baseIndex, array, index, _baseSize);
- }
-
- public override void CopyTo(int index, Array array, int arrayIndex, int count)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
- if (array.Rank != 1)
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - arrayIndex < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- if (_baseSize - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- InternalUpdateRange();
- _baseList.CopyTo(_baseIndex + index, array, arrayIndex, count);
- }
-
- public override int Count
- {
- get
- {
- InternalUpdateRange();
- return _baseSize;
- }
- }
-
- public override bool IsReadOnly => _baseList.IsReadOnly;
-
- public override bool IsFixedSize => _baseList.IsFixedSize;
-
- public override bool IsSynchronized => _baseList.IsSynchronized;
-
- public override IEnumerator GetEnumerator()
- {
- return GetEnumerator(0, _baseSize);
- }
-
- public override IEnumerator GetEnumerator(int index, int count)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_baseSize - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- InternalUpdateRange();
- return _baseList.GetEnumerator(_baseIndex + index, count);
- }
-
- public override ArrayList GetRange(int index, int count)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_baseSize - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- InternalUpdateRange();
- return new Range(this, index, count);
- }
-
- public override object SyncRoot => _baseList.SyncRoot;
-
-
- public override int IndexOf(object? value)
- {
- InternalUpdateRange();
- int i = _baseList.IndexOf(value, _baseIndex, _baseSize);
- if (i >= 0) return i - _baseIndex;
- return -1;
- }
-
- public override int IndexOf(object? value, int startIndex)
- {
- if (startIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (startIndex > _baseSize)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
-
- InternalUpdateRange();
- int i = _baseList.IndexOf(value, _baseIndex + startIndex, _baseSize - startIndex);
- if (i >= 0) return i - _baseIndex;
- return -1;
- }
-
- public override int IndexOf(object? value, int startIndex, int count)
- {
- if (startIndex < 0 || startIndex > _baseSize)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
-
- if (count < 0 || (startIndex > _baseSize - count))
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
-
- InternalUpdateRange();
- int i = _baseList.IndexOf(value, _baseIndex + startIndex, count);
- if (i >= 0) return i - _baseIndex;
- return -1;
- }
-
- public override void Insert(int index, object? value)
- {
- if (index < 0 || index > _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
-
- InternalUpdateRange();
- _baseList.Insert(_baseIndex + index, value);
- InternalUpdateVersion();
- _baseSize++;
- }
-
- public override void InsertRange(int index, ICollection c)
- {
- if (index < 0 || index > _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- if (c == null)
- {
- throw new ArgumentNullException(nameof(c));
- }
-
- InternalUpdateRange();
- int count = c.Count;
- if (count > 0)
- {
- _baseList.InsertRange(_baseIndex + index, c);
- _baseSize += count;
- InternalUpdateVersion();
- }
- }
-
- public override int LastIndexOf(object? value)
- {
- InternalUpdateRange();
- int i = _baseList.LastIndexOf(value, _baseIndex + _baseSize - 1, _baseSize);
- if (i >= 0) return i - _baseIndex;
- return -1;
- }
-
- public override int LastIndexOf(object? value, int startIndex)
- {
- return LastIndexOf(value, startIndex, startIndex + 1);
- }
-
- public override int LastIndexOf(object? value, int startIndex, int count)
- {
- InternalUpdateRange();
- if (_baseSize == 0)
- return -1;
-
- if (startIndex >= _baseSize)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- if (startIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- int i = _baseList.LastIndexOf(value, _baseIndex + startIndex, count);
- if (i >= 0) return i - _baseIndex;
- return -1;
- }
-
- // Don't need to override Remove
-
- public override void RemoveAt(int index)
- {
- if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
-
- InternalUpdateRange();
- _baseList.RemoveAt(_baseIndex + index);
- InternalUpdateVersion();
- _baseSize--;
- }
-
- public override void RemoveRange(int index, int count)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_baseSize - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- InternalUpdateRange();
- // No need to call _bastList.RemoveRange if count is 0.
- // In addition, _baseList won't change the version number if count is 0.
- if (count > 0)
- {
- _baseList.RemoveRange(_baseIndex + index, count);
- InternalUpdateVersion();
- _baseSize -= count;
- }
- }
-
- public override void Reverse(int index, int count)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_baseSize - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- InternalUpdateRange();
- _baseList.Reverse(_baseIndex + index, count);
- InternalUpdateVersion();
- }
-
- public override void SetRange(int index, ICollection c)
- {
- InternalUpdateRange();
- if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- _baseList.SetRange(_baseIndex + index, c);
- if (c.Count > 0)
- {
- InternalUpdateVersion();
- }
- }
-
- public override void Sort(int index, int count, IComparer? comparer)
- {
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_baseSize - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- InternalUpdateRange();
- _baseList.Sort(_baseIndex + index, count, comparer);
- InternalUpdateVersion();
- }
-
- public override object? this[int index]
- {
- get
- {
- InternalUpdateRange();
- if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- return _baseList[_baseIndex + index];
- }
- set
- {
- InternalUpdateRange();
- if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- _baseList[_baseIndex + index] = value;
- InternalUpdateVersion();
- }
- }
-
- public override object?[] ToArray()
- {
- InternalUpdateRange();
- if (_baseSize == 0)
- return Array.Empty<object?>();
- object[] array = new object[_baseSize];
- Array.Copy(_baseList._items, _baseIndex, array, 0, _baseSize);
- return array;
- }
-
- public override Array ToArray(Type type)
- {
- if (type == null)
- throw new ArgumentNullException(nameof(type));
-
- InternalUpdateRange();
- Array array = Array.CreateInstance(type, _baseSize);
- _baseList.CopyTo(_baseIndex, array, 0, _baseSize);
- return array;
- }
-
- public override void TrimToSize()
- {
- throw new NotSupportedException(SR.NotSupported_RangeCollection);
- }
- }
-
- private sealed class ArrayListEnumeratorSimple : IEnumerator, ICloneable
- {
- private readonly ArrayList _list;
- private int _index;
- private readonly int _version;
- private object? _currentElement;
- private readonly bool _isArrayList;
- // this object is used to indicate enumeration has not started or has terminated
- private static readonly object s_dummyObject = new object();
-
- internal ArrayListEnumeratorSimple(ArrayList list)
- {
- _list = list;
- _index = -1;
- _version = list._version;
- _isArrayList = (list.GetType() == typeof(ArrayList));
- _currentElement = s_dummyObject;
- }
-
- public object Clone() => MemberwiseClone();
-
- public bool MoveNext()
- {
- if (_version != _list._version)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- }
-
- if (_isArrayList)
- { // avoid calling virtual methods if we are operating on ArrayList to improve performance
- if (_index < _list._size - 1)
- {
- _currentElement = _list._items[++_index];
- return true;
- }
- else
- {
- _currentElement = s_dummyObject;
- _index = _list._size;
- return false;
- }
- }
- else
- {
- if (_index < _list.Count - 1)
- {
- _currentElement = _list[++_index];
- return true;
- }
- else
- {
- _index = _list.Count;
- _currentElement = s_dummyObject;
- return false;
- }
- }
- }
-
- public object? Current
- {
- get
- {
- object? temp = _currentElement;
- if (s_dummyObject == temp)
- { // check if enumeration has not started or has terminated
- if (_index == -1)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted);
- }
- else
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumEnded);
- }
- }
-
- return temp;
- }
- }
-
- public void Reset()
- {
- if (_version != _list._version)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- }
-
- _currentElement = s_dummyObject;
- _index = -1;
- }
- }
-
- internal class ArrayListDebugView
- {
- private readonly ArrayList _arrayList;
-
- public ArrayListDebugView(ArrayList arrayList)
- {
- if (arrayList == null)
- throw new ArgumentNullException(nameof(arrayList));
-
- _arrayList = arrayList;
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public object?[] Items => _arrayList.ToArray();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Comparer.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Comparer.cs
deleted file mode 100644
index 102d2c9f8b6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Comparer.cs
+++ /dev/null
@@ -1,73 +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.
-
-/*============================================================
-**
-** Purpose: Default IComparer implementation.
-**
-===========================================================*/
-
-using System.Globalization;
-using System.Runtime.Serialization;
-
-namespace System.Collections
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class Comparer : IComparer, ISerializable
- {
- private readonly CompareInfo _compareInfo;
-
- public static readonly Comparer Default = new Comparer(CultureInfo.CurrentCulture);
- public static readonly Comparer DefaultInvariant = new Comparer(CultureInfo.InvariantCulture);
-
- public Comparer(CultureInfo culture)
- {
- if (culture == null)
- throw new ArgumentNullException(nameof(culture));
-
- _compareInfo = culture.CompareInfo;
- }
-
- private Comparer(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- throw new ArgumentNullException(nameof(info));
-
- _compareInfo = (CompareInfo)info.GetValue("CompareInfo", typeof(CompareInfo))!;
- }
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- throw new ArgumentNullException(nameof(info));
-
- info.AddValue("CompareInfo", _compareInfo);
- }
-
- // Compares two Objects by calling CompareTo.
- // If a == b, 0 is returned.
- // If a implements IComparable, a.CompareTo(b) is returned.
- // If a doesn't implement IComparable and b does, -(b.CompareTo(a)) is returned.
- // Otherwise an exception is thrown.
- //
- public int Compare(object? a, object? b)
- {
- if (a == b) return 0;
- if (a == null) return -1;
- if (b == null) return 1;
-
- if (a is string sa && b is string sb)
- return _compareInfo.Compare(sa, sb);
-
- if (a is IComparable ia)
- return ia.CompareTo(b);
-
- if (b is IComparable ib)
- return -ib.CompareTo(a);
-
- throw new ArgumentException(SR.Argument_ImplementIComparable);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/CompatibleComparer.cs b/netcore/System.Private.CoreLib/shared/System/Collections/CompatibleComparer.cs
deleted file mode 100644
index f4042e50029..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/CompatibleComparer.cs
+++ /dev/null
@@ -1,61 +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.
-
-#nullable enable
-#pragma warning disable 618 // obsolete types
-
-namespace System.Collections
-{
- internal sealed class CompatibleComparer : IEqualityComparer
- {
- private readonly IHashCodeProvider? _hcp;
- private readonly IComparer? _comparer;
-
- internal CompatibleComparer(IHashCodeProvider? hashCodeProvider, IComparer? comparer)
- {
- _hcp = hashCodeProvider;
- _comparer = comparer;
- }
-
- internal IHashCodeProvider? HashCodeProvider => _hcp;
-
- internal IComparer? Comparer => _comparer;
-
- public new bool Equals(object? a, object? b) => Compare(a, b) == 0;
-
- public int Compare(object? a, object? b)
- {
- if (a == b)
- return 0;
- if (a == null)
- return -1;
- if (b == null)
- return 1;
-
- if (_comparer != null)
- {
- return _comparer.Compare(a, b);
- }
-
- if (a is IComparable ia)
- {
- return ia.CompareTo(b);
- }
-
- throw new ArgumentException(SR.Argument_ImplementIComparable);
- }
-
- public int GetHashCode(object obj)
- {
- if (obj == null)
- {
- throw new ArgumentNullException(nameof(obj));
- }
-
- return _hcp != null ?
- _hcp.GetHashCode(obj) :
- obj.GetHashCode();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs
deleted file mode 100644
index 7ba4c09440c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs
+++ /dev/null
@@ -1,817 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Threading;
-
-namespace System.Collections.Concurrent
-{
- /// <summary>
- /// Represents a thread-safe first-in, first-out collection of objects.
- /// </summary>
- /// <typeparam name="T">Specifies the type of elements in the queue.</typeparam>
- /// <remarks>
- /// All public and protected members of <see cref="ConcurrentQueue{T}"/> are thread-safe and may be used
- /// concurrently from multiple threads.
- /// </remarks>
- [DebuggerDisplay("Count = {Count}")]
- [DebuggerTypeProxy(typeof(IProducerConsumerCollectionDebugView<>))]
- public class ConcurrentQueue<T> : IProducerConsumerCollection<T>, IReadOnlyCollection<T>
- {
- // This implementation provides an unbounded, multi-producer multi-consumer queue
- // that supports the standard Enqueue/TryDequeue operations, as well as support for
- // snapshot enumeration (GetEnumerator, ToArray, CopyTo), peeking, and Count/IsEmpty.
- // It is composed of a linked list of bounded ring buffers, each of which has a head
- // and a tail index, isolated from each other to minimize false sharing. As long as
- // the number of elements in the queue remains less than the size of the current
- // buffer (Segment), no additional allocations are required for enqueued items. When
- // the number of items exceeds the size of the current segment, the current segment is
- // "frozen" to prevent further enqueues, and a new segment is linked from it and set
- // as the new tail segment for subsequent enqueues. As old segments are consumed by
- // dequeues, the head reference is updated to point to the segment that dequeuers should
- // try next. To support snapshot enumeration, segments also support the notion of
- // preserving for observation, whereby they avoid overwriting state as part of dequeues.
- // Any operation that requires a snapshot results in all current segments being
- // both frozen for enqueues and preserved for observation: any new enqueues will go
- // to new segments, and dequeuers will consume from the existing segments but without
- // overwriting the existing data.
-
- /// <summary>Initial length of the segments used in the queue.</summary>
- private const int InitialSegmentLength = 32;
- /// <summary>
- /// Maximum length of the segments used in the queue. This is a somewhat arbitrary limit:
- /// larger means that as long as we don't exceed the size, we avoid allocating more segments,
- /// but if we do exceed it, then the segment becomes garbage.
- /// </summary>
- private const int MaxSegmentLength = 1024 * 1024;
-
- /// <summary>
- /// Lock used to protect cross-segment operations, including any updates to <see cref="_tail"/> or <see cref="_head"/>
- /// and any operations that need to get a consistent view of them.
- /// </summary>
- private readonly object _crossSegmentLock;
- /// <summary>The current tail segment.</summary>
- private volatile ConcurrentQueueSegment<T> _tail;
- /// <summary>The current head segment.</summary>
- private volatile ConcurrentQueueSegment<T> _head; // SOS's ThreadPool command depends on this name
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ConcurrentQueue{T}"/> class.
- /// </summary>
- public ConcurrentQueue()
- {
- _crossSegmentLock = new object();
- _tail = _head = new ConcurrentQueueSegment<T>(InitialSegmentLength);
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ConcurrentQueue{T}"/> class that contains elements copied
- /// from the specified collection.
- /// </summary>
- /// <param name="collection">
- /// The collection whose elements are copied to the new <see cref="ConcurrentQueue{T}"/>.
- /// </param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="collection"/> argument is null.</exception>
- public ConcurrentQueue(IEnumerable<T> collection)
- {
- if (collection == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
- }
-
- _crossSegmentLock = new object();
-
- // Determine the initial segment size. We'll use the default,
- // unless the collection is known to be larger than that, in which
- // case we round its length up to a power of 2, as all segments must
- // be a power of 2 in length.
- int length = InitialSegmentLength;
- if (collection is ICollection<T> c)
- {
- int count = c.Count;
- if (count > length)
- {
- length = Math.Min(ConcurrentQueueSegment<T>.RoundUpToPowerOf2(count), MaxSegmentLength);
- }
- }
-
- // Initialize the segment and add all of the data to it.
- _tail = _head = new ConcurrentQueueSegment<T>(length);
- foreach (T item in collection)
- {
- Enqueue(item);
- }
- }
-
- /// <summary>
- /// Copies the elements of the <see cref="ICollection"/> to an <see
- /// cref="Array"/>, starting at a particular <see cref="Array"/> index.
- /// </summary>
- /// <param name="array">
- /// The one-dimensional <see cref="Array">Array</see> that is the destination of the
- /// elements copied from the <see cref="ConcurrentQueue{T}"/>. <paramref name="array"/> must have
- /// zero-based indexing.
- /// </param>
- /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
- /// <exception cref="ArgumentNullException"><paramref name="array"/> is a null reference (Nothing in
- /// Visual Basic).</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than
- /// zero.</exception>
- /// <exception cref="ArgumentException">
- /// <paramref name="array"/> is multidimensional. -or-
- /// <paramref name="array"/> does not have zero-based indexing. -or-
- /// <paramref name="index"/> is equal to or greater than the length of the <paramref name="array"/>
- /// -or- The number of elements in the source <see cref="ICollection"/> is
- /// greater than the available space from <paramref name="index"/> to the end of the destination
- /// <paramref name="array"/>. -or- The type of the source <see
- /// cref="ICollection"/> cannot be cast automatically to the type of the
- /// destination <paramref name="array"/>.
- /// </exception>
- void ICollection.CopyTo(Array array, int index)
- {
- // Special-case when the Array is actually a T[], taking a faster path
- if (array is T[] szArray)
- {
- CopyTo(szArray, index);
- return;
- }
-
- // Validate arguments.
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- // Otherwise, fall back to the slower path that first copies the contents
- // to an array, and then uses that array's non-generic CopyTo to do the copy.
- ToArray().CopyTo(array, index);
- }
-
- /// <summary>
- /// Gets a value indicating whether access to the <see cref="ICollection"/> is
- /// synchronized with the SyncRoot.
- /// </summary>
- /// <value>true if access to the <see cref="ICollection"/> is synchronized
- /// with the SyncRoot; otherwise, false. For <see cref="ConcurrentQueue{T}"/>, this property always
- /// returns false.</value>
- bool ICollection.IsSynchronized => false; // always false, as true implies synchronization via SyncRoot
-
- /// <summary>
- /// Gets an object that can be used to synchronize access to the <see
- /// cref="ICollection"/>. This property is not supported.
- /// </summary>
- /// <exception cref="NotSupportedException">The SyncRoot property is not supported.</exception>
- object ICollection.SyncRoot { get { ThrowHelper.ThrowNotSupportedException(ExceptionResource.ConcurrentCollection_SyncRoot_NotSupported); return default; } }
-
- /// <summary>Returns an enumerator that iterates through a collection.</summary>
- /// <returns>An <see cref="IEnumerator"/> that can be used to iterate through the collection.</returns>
- IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable<T>)this).GetEnumerator();
-
- /// <summary>
- /// Attempts to add an object to the <see cref="Concurrent.IProducerConsumerCollection{T}"/>.
- /// </summary>
- /// <param name="item">The object to add to the <see
- /// cref="Concurrent.IProducerConsumerCollection{T}"/>. The value can be a null
- /// reference (Nothing in Visual Basic) for reference types.
- /// </param>
- /// <returns>true if the object was added successfully; otherwise, false.</returns>
- /// <remarks>For <see cref="ConcurrentQueue{T}"/>, this operation will always add the object to the
- /// end of the <see cref="ConcurrentQueue{T}"/>
- /// and return true.</remarks>
- bool IProducerConsumerCollection<T>.TryAdd(T item)
- {
- Enqueue(item);
- return true;
- }
-
- /// <summary>
- /// Attempts to remove and return an object from the <see cref="Concurrent.IProducerConsumerCollection{T}"/>.
- /// </summary>
- /// <param name="item">
- /// When this method returns, if the operation was successful, <paramref name="item"/> contains the
- /// object removed. If no object was available to be removed, the value is unspecified.
- /// </param>
- /// <returns>true if an element was removed and returned successfully; otherwise, false.</returns>
- /// <remarks>For <see cref="ConcurrentQueue{T}"/>, this operation will attempt to remove the object
- /// from the beginning of the <see cref="ConcurrentQueue{T}"/>.
- /// </remarks>
- bool IProducerConsumerCollection<T>.TryTake(out T item) => TryDequeue(out item);
-
- /// <summary>
- /// Gets a value that indicates whether the <see cref="ConcurrentQueue{T}"/> is empty.
- /// </summary>
- /// <value>true if the <see cref="ConcurrentQueue{T}"/> is empty; otherwise, false.</value>
- /// <remarks>
- /// For determining whether the collection contains any items, use of this property is recommended
- /// rather than retrieving the number of items from the <see cref="Count"/> property and comparing it
- /// to 0. However, as this collection is intended to be accessed concurrently, it may be the case
- /// that another thread will modify the collection after <see cref="IsEmpty"/> returns, thus invalidating
- /// the result.
- /// </remarks>
- public bool IsEmpty =>
- // IsEmpty == !TryPeek. We use a "resultUsed:false" peek in order to avoid marking
- // segments as preserved for observation, making IsEmpty a cheaper way than either
- // TryPeek(out T) or Count == 0 to check whether any elements are in the queue.
- !TryPeek(out _, resultUsed: false);
-
- /// <summary>Copies the elements stored in the <see cref="ConcurrentQueue{T}"/> to a new array.</summary>
- /// <returns>A new array containing a snapshot of elements copied from the <see cref="ConcurrentQueue{T}"/>.</returns>
- public T[] ToArray()
- {
- // Snap the current contents for enumeration.
- ConcurrentQueueSegment<T> head, tail;
- int headHead, tailTail;
- SnapForObservation(out head, out headHead, out tail, out tailTail);
-
- // Count the number of items in that snapped set, and use it to allocate an
- // array of the right size.
- long count = GetCount(head, headHead, tail, tailTail);
- T[] arr = new T[count];
-
- // Now enumerate the contents, copying each element into the array.
- using (IEnumerator<T> e = Enumerate(head, headHead, tail, tailTail))
- {
- int i = 0;
- while (e.MoveNext())
- {
- arr[i++] = e.Current;
- }
- Debug.Assert(count == i);
- }
-
- // And return it.
- return arr;
- }
-
- /// <summary>
- /// Gets the number of elements contained in the <see cref="ConcurrentQueue{T}"/>.
- /// </summary>
- /// <value>The number of elements contained in the <see cref="ConcurrentQueue{T}"/>.</value>
- /// <remarks>
- /// For determining whether the collection contains any items, use of the <see cref="IsEmpty"/>
- /// property is recommended rather than retrieving the number of items from the <see cref="Count"/>
- /// property and comparing it to 0.
- /// </remarks>
- public int Count
- {
- get
- {
- SpinWait spinner = default;
- while (true)
- {
- // Capture the head and tail, as well as the head's head and tail.
- ConcurrentQueueSegment<T> head = _head;
- ConcurrentQueueSegment<T> tail = _tail;
- int headHead = Volatile.Read(ref head._headAndTail.Head);
- int headTail = Volatile.Read(ref head._headAndTail.Tail);
-
- if (head == tail)
- {
- // There was a single segment in the queue. If the captured segments still
- // match, then we can trust the values to compute the segment's count. (It's
- // theoretically possible the values could have looped around and still exactly match,
- // but that would required at least ~4 billion elements to have been enqueued and
- // dequeued between the reads.)
- if (head == _head &&
- tail == _tail &&
- headHead == Volatile.Read(ref head._headAndTail.Head) &&
- headTail == Volatile.Read(ref head._headAndTail.Tail))
- {
- return GetCount(head, headHead, headTail);
- }
- }
- else if (head._nextSegment == tail)
- {
- // There were two segments in the queue. Get the positions from the tail, and as above,
- // if the captured values match the previous reads, return the sum of the counts from both segments.
- int tailHead = Volatile.Read(ref tail._headAndTail.Head);
- int tailTail = Volatile.Read(ref tail._headAndTail.Tail);
- if (head == _head &&
- tail == _tail &&
- headHead == Volatile.Read(ref head._headAndTail.Head) &&
- headTail == Volatile.Read(ref head._headAndTail.Tail) &&
- tailHead == Volatile.Read(ref tail._headAndTail.Head) &&
- tailTail == Volatile.Read(ref tail._headAndTail.Tail))
- {
- return GetCount(head, headHead, headTail) + GetCount(tail, tailHead, tailTail);
- }
- }
- else
- {
- // There were more than two segments in the queue. Fall back to taking the cross-segment lock,
- // which will ensure that the head and tail segments we read are stable (since the lock is needed to change them);
- // for the two-segment case above, we can simply rely on subsequent comparisons, but for the two+ case, we need
- // to be able to trust the internal segments between the head and tail.
- lock (_crossSegmentLock)
- {
- // Now that we hold the lock, re-read the previously captured head and tail segments and head positions.
- // If either has changed, start over.
- if (head == _head && tail == _tail)
- {
- // Get the positions from the tail, and as above, if the captured values match the previous reads,
- // we can use the values to compute the count of the head and tail segments.
- int tailHead = Volatile.Read(ref tail._headAndTail.Head);
- int tailTail = Volatile.Read(ref tail._headAndTail.Tail);
- if (headHead == Volatile.Read(ref head._headAndTail.Head) &&
- headTail == Volatile.Read(ref head._headAndTail.Tail) &&
- tailHead == Volatile.Read(ref tail._headAndTail.Head) &&
- tailTail == Volatile.Read(ref tail._headAndTail.Tail))
- {
- // We got stable values for the head and tail segments, so we can just compute the sizes
- // based on those and add them. Note that this and the below additions to count may overflow: previous
- // implementations allowed that, so we don't check, either, and it is theoretically possible for the
- // queue to store more than int.MaxValue items.
- int count = GetCount(head, headHead, headTail) + GetCount(tail, tailHead, tailTail);
-
- // Now add the counts for each internal segment. Since there were segments before these,
- // for counting purposes we consider them to start at the 0th element, and since there is at
- // least one segment after each, each was frozen, so we can count until each's frozen tail.
- // With the cross-segment lock held, we're guaranteed that all of these internal segments are
- // consistent, as the head and tail segment can't be changed while we're holding the lock, and
- // dequeueing and enqueueing can only be done from the head and tail segments, which these aren't.
- for (ConcurrentQueueSegment<T> s = head._nextSegment!; s != tail; s = s._nextSegment!)
- {
- Debug.Assert(s._frozenForEnqueues, "Internal segment must be frozen as there's a following segment.");
- count += s._headAndTail.Tail - s.FreezeOffset;
- }
-
- return count;
- }
- }
- }
- }
-
- // We raced with enqueues/dequeues and captured an inconsistent picture of the queue.
- // Spin and try again.
- spinner.SpinOnce();
- }
- }
- }
-
- /// <summary>Computes the number of items in a segment based on a fixed head and tail in that segment.</summary>
- private static int GetCount(ConcurrentQueueSegment<T> s, int head, int tail)
- {
- if (head != tail && head != tail - s.FreezeOffset)
- {
- head &= s._slotsMask;
- tail &= s._slotsMask;
- return head < tail ? tail - head : s._slots.Length - head + tail;
- }
- return 0;
- }
-
- /// <summary>Gets the number of items in snapped region.</summary>
- private static long GetCount(ConcurrentQueueSegment<T> head, int headHead, ConcurrentQueueSegment<T> tail, int tailTail)
- {
- // All of the segments should have been both frozen for enqueues and preserved for observation.
- // Validate that here for head and tail; we'll validate it for intermediate segments later.
- Debug.Assert(head._preservedForObservation);
- Debug.Assert(head._frozenForEnqueues);
- Debug.Assert(tail._preservedForObservation);
- Debug.Assert(tail._frozenForEnqueues);
-
- long count = 0;
-
- // Head segment. We've already marked it as frozen for enqueues, so its tail position is fixed,
- // and we've already marked it as preserved for observation (before we grabbed the head), so we
- // can safely enumerate from its head to its tail and access its elements.
- int headTail = (head == tail ? tailTail : Volatile.Read(ref head._headAndTail.Tail)) - head.FreezeOffset;
- if (headHead < headTail)
- {
- // Mask the head and tail for the head segment
- headHead &= head._slotsMask;
- headTail &= head._slotsMask;
-
- // Increase the count by either the one or two regions, based on whether tail
- // has wrapped to be less than head.
- count += headHead < headTail ?
- headTail - headHead :
- head._slots.Length - headHead + headTail;
- }
-
- // We've enumerated the head. If the tail is different from the head, we need to
- // enumerate the remaining segments.
- if (head != tail)
- {
- // Count the contents of each segment between head and tail, not including head and tail.
- // Since there were segments before these, for our purposes we consider them to start at
- // the 0th element, and since there is at least one segment after each, each was frozen
- // by the time we snapped it, so we can iterate until each's frozen tail.
- for (ConcurrentQueueSegment<T> s = head._nextSegment!; s != tail; s = s._nextSegment!)
- {
- Debug.Assert(s._preservedForObservation);
- Debug.Assert(s._frozenForEnqueues);
- count += s._headAndTail.Tail - s.FreezeOffset;
- }
-
- // Finally, enumerate the tail. As with the intermediate segments, there were segments
- // before this in the snapped region, so we can start counting from the beginning. Unlike
- // the intermediate segments, we can't just go until the Tail, as that could still be changing;
- // instead we need to go until the tail we snapped for observation.
- count += tailTail - tail.FreezeOffset;
- }
-
- // Return the computed count.
- return count;
- }
-
- /// <summary>
- /// Copies the <see cref="ConcurrentQueue{T}"/> elements to an existing one-dimensional <see
- /// cref="Array">Array</see>, starting at the specified array index.
- /// </summary>
- /// <param name="array">The one-dimensional <see cref="Array">Array</see> that is the
- /// destination of the elements copied from the
- /// <see cref="ConcurrentQueue{T}"/>. The <see cref="Array">Array</see> must have zero-based
- /// indexing.</param>
- /// <param name="index">The zero-based index in <paramref name="array"/> at which copying
- /// begins.</param>
- /// <exception cref="ArgumentNullException"><paramref name="array"/> is a null reference (Nothing in
- /// Visual Basic).</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than
- /// zero.</exception>
- /// <exception cref="ArgumentException"><paramref name="index"/> is equal to or greater than the
- /// length of the <paramref name="array"/>
- /// -or- The number of elements in the source <see cref="ConcurrentQueue{T}"/> is greater than the
- /// available space from <paramref name="index"/> to the end of the destination <paramref
- /// name="array"/>.
- /// </exception>
- public void CopyTo(T[] array, int index)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
- if (index < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index);
- }
-
- // Snap for enumeration
- ConcurrentQueueSegment<T> head, tail;
- int headHead, tailTail;
- SnapForObservation(out head, out headHead, out tail, out tailTail);
-
- // Get the number of items to be enumerated
- long count = GetCount(head, headHead, tail, tailTail);
- if (index > array.Length - count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
- }
-
- // Copy the items to the target array
- int i = index;
- using (IEnumerator<T> e = Enumerate(head, headHead, tail, tailTail))
- {
- while (e.MoveNext())
- {
- array[i++] = e.Current;
- }
- }
- Debug.Assert(count == i - index);
- }
-
- /// <summary>Returns an enumerator that iterates through the <see cref="ConcurrentQueue{T}"/>.</summary>
- /// <returns>An enumerator for the contents of the <see
- /// cref="ConcurrentQueue{T}"/>.</returns>
- /// <remarks>
- /// The enumeration represents a moment-in-time snapshot of the contents
- /// of the queue. It does not reflect any updates to the collection after
- /// <see cref="GetEnumerator"/> was called. The enumerator is safe to use
- /// concurrently with reads from and writes to the queue.
- /// </remarks>
- public IEnumerator<T> GetEnumerator()
- {
- ConcurrentQueueSegment<T> head, tail;
- int headHead, tailTail;
- SnapForObservation(out head, out headHead, out tail, out tailTail);
- return Enumerate(head, headHead, tail, tailTail);
- }
-
- /// <summary>
- /// Gets the head and tail information of the current contents of the queue.
- /// After this call returns, the specified region can be enumerated any number
- /// of times and will not change.
- /// </summary>
- private void SnapForObservation(out ConcurrentQueueSegment<T> head, out int headHead, out ConcurrentQueueSegment<T> tail, out int tailTail)
- {
- lock (_crossSegmentLock) // _head and _tail may only change while the lock is held.
- {
- // Snap the head and tail
- head = _head;
- tail = _tail;
- Debug.Assert(head != null);
- Debug.Assert(tail != null);
- Debug.Assert(tail._nextSegment == null);
-
- // Mark them and all segments in between as preserving, and ensure no additional items
- // can be added to the tail.
- for (ConcurrentQueueSegment<T> s = head; ; s = s._nextSegment!)
- {
- s._preservedForObservation = true;
- if (s == tail) break;
- Debug.Assert(s._frozenForEnqueues); // any non-tail should already be marked
- }
- tail.EnsureFrozenForEnqueues(); // we want to prevent the tailTail from moving
-
- // At this point, any dequeues from any segment won't overwrite the value, and
- // none of the existing segments can have new items enqueued.
-
- headHead = Volatile.Read(ref head._headAndTail.Head);
- tailTail = Volatile.Read(ref tail._headAndTail.Tail);
- }
- }
-
- /// <summary>Gets the item stored in the <paramref name="i"/>th entry in <paramref name="segment"/>.</summary>
- private static T GetItemWhenAvailable(ConcurrentQueueSegment<T> segment, int i)
- {
- Debug.Assert(segment._preservedForObservation);
-
- // Get the expected value for the sequence number
- int expectedSequenceNumberAndMask = (i + 1) & segment._slotsMask;
-
- // If the expected sequence number is not yet written, we're still waiting for
- // an enqueuer to finish storing it. Spin until it's there.
- if ((segment._slots[i].SequenceNumber & segment._slotsMask) != expectedSequenceNumberAndMask)
- {
- SpinWait spinner = default;
- while ((Volatile.Read(ref segment._slots[i].SequenceNumber) & segment._slotsMask) != expectedSequenceNumberAndMask)
- {
- spinner.SpinOnce();
- }
- }
-
- // Return the value from the slot.
- return segment._slots[i].Item;
- }
-
- private IEnumerator<T> Enumerate(ConcurrentQueueSegment<T> head, int headHead, ConcurrentQueueSegment<T> tail, int tailTail)
- {
- Debug.Assert(head._preservedForObservation);
- Debug.Assert(head._frozenForEnqueues);
- Debug.Assert(tail._preservedForObservation);
- Debug.Assert(tail._frozenForEnqueues);
-
- // Head segment. We've already marked it as not accepting any more enqueues,
- // so its tail position is fixed, and we've already marked it as preserved for
- // enumeration (before we grabbed its head), so we can safely enumerate from
- // its head to its tail.
- int headTail = (head == tail ? tailTail : Volatile.Read(ref head._headAndTail.Tail)) - head.FreezeOffset;
- if (headHead < headTail)
- {
- headHead &= head._slotsMask;
- headTail &= head._slotsMask;
-
- if (headHead < headTail)
- {
- for (int i = headHead; i < headTail; i++) yield return GetItemWhenAvailable(head, i);
- }
- else
- {
- for (int i = headHead; i < head._slots.Length; i++) yield return GetItemWhenAvailable(head, i);
- for (int i = 0; i < headTail; i++) yield return GetItemWhenAvailable(head, i);
- }
- }
-
- // We've enumerated the head. If the tail is the same, we're done.
- if (head != tail)
- {
- // Each segment between head and tail, not including head and tail. Since there were
- // segments before these, for our purposes we consider it to start at the 0th element.
- for (ConcurrentQueueSegment<T> s = head._nextSegment!; s != tail; s = s._nextSegment!)
- {
- Debug.Assert(s._preservedForObservation, "Would have had to been preserved as a segment part of enumeration");
- Debug.Assert(s._frozenForEnqueues, "Would have had to be frozen for enqueues as it's intermediate");
-
- int sTail = s._headAndTail.Tail - s.FreezeOffset;
- for (int i = 0; i < sTail; i++)
- {
- yield return GetItemWhenAvailable(s, i);
- }
- }
-
- // Enumerate the tail. Since there were segments before this, we can just start at
- // its beginning, and iterate until the tail we already grabbed.
- tailTail -= tail.FreezeOffset;
- for (int i = 0; i < tailTail; i++)
- {
- yield return GetItemWhenAvailable(tail, i);
- }
- }
- }
-
- /// <summary>Adds an object to the end of the <see cref="ConcurrentQueue{T}"/>.</summary>
- /// <param name="item">
- /// The object to add to the end of the <see cref="ConcurrentQueue{T}"/>.
- /// The value can be a null reference (Nothing in Visual Basic) for reference types.
- /// </param>
- public void Enqueue(T item)
- {
- // Try to enqueue to the current tail.
- if (!_tail.TryEnqueue(item))
- {
- // If we're unable to, we need to take a slow path that will
- // try to add a new tail segment.
- EnqueueSlow(item);
- }
- }
-
- /// <summary>Adds to the end of the queue, adding a new segment if necessary.</summary>
- private void EnqueueSlow(T item)
- {
- while (true)
- {
- ConcurrentQueueSegment<T> tail = _tail;
-
- // Try to append to the existing tail.
- if (tail.TryEnqueue(item))
- {
- return;
- }
-
- // If we were unsuccessful, take the lock so that we can compare and manipulate
- // the tail. Assuming another enqueuer hasn't already added a new segment,
- // do so, then loop around to try enqueueing again.
- lock (_crossSegmentLock)
- {
- if (tail == _tail)
- {
- // Make sure no one else can enqueue to this segment.
- tail.EnsureFrozenForEnqueues();
-
- // We determine the new segment's length based on the old length.
- // In general, we double the size of the segment, to make it less likely
- // that we'll need to grow again. However, if the tail segment is marked
- // as preserved for observation, something caused us to avoid reusing this
- // segment, and if that happens a lot and we grow, we'll end up allocating
- // lots of wasted space. As such, in such situations we reset back to the
- // initial segment length; if these observations are happening frequently,
- // this will help to avoid wasted memory, and if they're not, we'll
- // relatively quickly grow again to a larger size.
- int nextSize = tail._preservedForObservation ? InitialSegmentLength : Math.Min(tail.Capacity * 2, MaxSegmentLength);
- var newTail = new ConcurrentQueueSegment<T>(nextSize);
-
- // Hook up the new tail.
- tail._nextSegment = newTail;
- _tail = newTail;
- }
- }
- }
- }
-
- /// <summary>
- /// Attempts to remove and return the object at the beginning of the <see
- /// cref="ConcurrentQueue{T}"/>.
- /// </summary>
- /// <param name="result">
- /// When this method returns, if the operation was successful, <paramref name="result"/> contains the
- /// object removed. If no object was available to be removed, the value is unspecified.
- /// </param>
- /// <returns>
- /// true if an element was removed and returned from the beginning of the
- /// <see cref="ConcurrentQueue{T}"/> successfully; otherwise, false.
- /// </returns>
- public bool TryDequeue([MaybeNullWhen(false)] out T result) =>
- _head.TryDequeue(out result) || // fast-path that operates just on the head segment
- TryDequeueSlow(out result); // slow path that needs to fix up segments
-
- /// <summary>Tries to dequeue an item, removing empty segments as needed.</summary>
- private bool TryDequeueSlow([MaybeNullWhen(false)] out T item)
- {
- while (true)
- {
- // Get the current head
- ConcurrentQueueSegment<T> head = _head;
-
- // Try to take. If we're successful, we're done.
- if (head.TryDequeue(out item))
- {
- return true;
- }
-
- // Check to see whether this segment is the last. If it is, we can consider
- // this to be a moment-in-time empty condition (even though between the TryDequeue
- // check and this check, another item could have arrived).
- if (head._nextSegment == null)
- {
- item = default!;
- return false;
- }
-
- // At this point we know that head.Next != null, which means
- // this segment has been frozen for additional enqueues. But between
- // the time that we ran TryDequeue and checked for a next segment,
- // another item could have been added. Try to dequeue one more time
- // to confirm that the segment is indeed empty.
- Debug.Assert(head._frozenForEnqueues);
- if (head.TryDequeue(out item))
- {
- return true;
- }
-
- // This segment is frozen (nothing more can be added) and empty (nothing is in it).
- // Update head to point to the next segment in the list, assuming no one's beat us to it.
- lock (_crossSegmentLock)
- {
- if (head == _head)
- {
- _head = head._nextSegment;
- }
- }
- }
- }
-
- /// <summary>
- /// Attempts to return an object from the beginning of the <see cref="ConcurrentQueue{T}"/>
- /// without removing it.
- /// </summary>
- /// <param name="result">
- /// When this method returns, <paramref name="result"/> contains an object from
- /// the beginning of the <see cref="Concurrent.ConcurrentQueue{T}"/> or default(T)
- /// if the operation failed.
- /// </param>
- /// <returns>true if and object was returned successfully; otherwise, false.</returns>
- /// <remarks>
- /// For determining whether the collection contains any items, use of the <see cref="IsEmpty"/>
- /// property is recommended rather than peeking.
- /// </remarks>
- public bool TryPeek([MaybeNullWhen(false)] out T result) => TryPeek(out result, resultUsed: true);
-
- /// <summary>Attempts to retrieve the value for the first element in the queue.</summary>
- /// <param name="result">The value of the first element, if found.</param>
- /// <param name="resultUsed">true if the result is needed; otherwise false if only the true/false outcome is needed.</param>
- /// <returns>true if an element was found; otherwise, false.</returns>
- private bool TryPeek([MaybeNullWhen(false)] out T result, bool resultUsed)
- {
- // Starting with the head segment, look through all of the segments
- // for the first one we can find that's not empty.
- ConcurrentQueueSegment<T> s = _head;
- while (true)
- {
- // Grab the next segment from this one, before we peek.
- // This is to be able to see whether the value has changed
- // during the peek operation.
- ConcurrentQueueSegment<T>? next = Volatile.Read(ref s._nextSegment);
-
- // Peek at the segment. If we find an element, we're done.
- if (s.TryPeek(out result, resultUsed))
- {
- return true;
- }
-
- // The current segment was empty at the moment we checked.
-
- if (next != null)
- {
- // If prior to the peek there was already a next segment, then
- // during the peek no additional items could have been enqueued
- // to it and we can just move on to check the next segment.
- Debug.Assert(next == s._nextSegment);
- s = next;
- }
- else if (Volatile.Read(ref s._nextSegment) == null)
- {
- // The next segment is null. Nothing more to peek at.
- break;
- }
-
- // The next segment was null before we peeked but non-null after.
- // That means either when we peeked the first segment had
- // already been frozen but the new segment not yet added,
- // or that the first segment was empty and between the time
- // that we peeked and then checked _nextSegment, so many items
- // were enqueued that we filled the first segment and went
- // into the next. Since we need to peek in order, we simply
- // loop around again to peek on the same segment. The next
- // time around on this segment we'll then either successfully
- // peek or we'll find that next was non-null before peeking,
- // and we'll traverse to that segment.
- }
-
- result = default!;
- return false;
- }
-
- /// <summary>
- /// Removes all objects from the <see cref="ConcurrentQueue{T}"/>.
- /// </summary>
- public void Clear()
- {
- lock (_crossSegmentLock)
- {
- // Simply substitute a new segment for the existing head/tail,
- // as is done in the constructor. Operations currently in flight
- // may still read from or write to an existing segment that's
- // getting dropped, meaning that in flight operations may not be
- // linear with regards to this clear operation. To help mitigate
- // in-flight operations enqueuing onto the tail that's about to
- // be dropped, we first freeze it; that'll force enqueuers to take
- // this lock to synchronize and see the new tail.
- _tail.EnsureFrozenForEnqueues();
- _tail = _head = new ConcurrentQueueSegment<T>(InitialSegmentLength);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueueSegment.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueueSegment.cs
deleted file mode 100644
index 621d8163813..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueueSegment.cs
+++ /dev/null
@@ -1,340 +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.
-
-#nullable enable
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-namespace System.Collections.Concurrent
-{
- /// <summary>
- /// Provides a multi-producer, multi-consumer thread-safe bounded segment. When the queue is full,
- /// enqueues fail and return false. When the queue is empty, dequeues fail and return null.
- /// These segments are linked together to form the unbounded <see cref="ConcurrentQueue{T}"/>.
- /// </summary>
- [DebuggerDisplay("Capacity = {Capacity}")]
- internal sealed class ConcurrentQueueSegment<T>
- {
- // Segment design is inspired by the algorithm outlined at:
- // http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue
-
- /// <summary>The array of items in this queue. Each slot contains the item in that slot and its "sequence number".</summary>
- internal readonly Slot[] _slots; // SOS's ThreadPool command depends on this name
- /// <summary>Mask for quickly accessing a position within the queue's array.</summary>
- internal readonly int _slotsMask;
- /// <summary>The head and tail positions, with padding to help avoid false sharing contention.</summary>
- /// <remarks>Dequeuing happens from the head, enqueuing happens at the tail.</remarks>
- internal PaddedHeadAndTail _headAndTail; // mutable struct: do not make this readonly
-
- /// <summary>Indicates whether the segment has been marked such that dequeues don't overwrite the removed data.</summary>
- internal bool _preservedForObservation;
- /// <summary>Indicates whether the segment has been marked such that no additional items may be enqueued.</summary>
- internal bool _frozenForEnqueues;
-#pragma warning disable 0649 // some builds don't assign to this field
- /// <summary>The segment following this one in the queue, or null if this segment is the last in the queue.</summary>
- internal ConcurrentQueueSegment<T>? _nextSegment; // SOS's ThreadPool command depends on this name
-#pragma warning restore 0649
-
- /// <summary>Creates the segment.</summary>
- /// <param name="boundedLength">
- /// The maximum number of elements the segment can contain. Must be a power of 2.
- /// </param>
- internal ConcurrentQueueSegment(int boundedLength)
- {
- // Validate the length
- Debug.Assert(boundedLength >= 2, $"Must be >= 2, got {boundedLength}");
- Debug.Assert((boundedLength & (boundedLength - 1)) == 0, $"Must be a power of 2, got {boundedLength}");
-
- // Initialize the slots and the mask. The mask is used as a way of quickly doing "% _slots.Length",
- // instead letting us do "& _slotsMask".
- _slots = new Slot[boundedLength];
- _slotsMask = boundedLength - 1;
-
- // Initialize the sequence number for each slot. The sequence number provides a ticket that
- // allows dequeuers to know whether they can dequeue and enqueuers to know whether they can
- // enqueue. An enqueuer at position N can enqueue when the sequence number is N, and a dequeuer
- // for position N can dequeue when the sequence number is N + 1. When an enqueuer is done writing
- // at position N, it sets the sequence number to N + 1 so that a dequeuer will be able to dequeue,
- // and when a dequeuer is done dequeueing at position N, it sets the sequence number to N + _slots.Length,
- // so that when an enqueuer loops around the slots, it'll find that the sequence number at
- // position N is N. This also means that when an enqueuer finds that at position N the sequence
- // number is < N, there is still a value in that slot, i.e. the segment is full, and when a
- // dequeuer finds that the value in a slot is < N + 1, there is nothing currently available to
- // dequeue. (It is possible for multiple enqueuers to enqueue concurrently, writing into
- // subsequent slots, and to have the first enqueuer take longer, so that the slots for 1, 2, 3, etc.
- // may have values, but the 0th slot may still be being filled... in that case, TryDequeue will
- // return false.)
- for (int i = 0; i < _slots.Length; i++)
- {
- _slots[i].SequenceNumber = i;
- }
- }
-
- /// <summary>Round the specified value up to the next power of 2, if it isn't one already.</summary>
- internal static int RoundUpToPowerOf2(int i)
- {
- // Based on https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
- --i;
- i |= i >> 1;
- i |= i >> 2;
- i |= i >> 4;
- i |= i >> 8;
- i |= i >> 16;
- return i + 1;
- }
-
- /// <summary>Gets the number of elements this segment can store.</summary>
- internal int Capacity => _slots.Length;
-
- /// <summary>Gets the "freeze offset" for this segment.</summary>
- internal int FreezeOffset => _slots.Length * 2;
-
- /// <summary>
- /// Ensures that the segment will not accept any subsequent enqueues that aren't already underway.
- /// </summary>
- /// <remarks>
- /// When we mark a segment as being frozen for additional enqueues,
- /// we set the <see cref="_frozenForEnqueues"/> bool, but that's mostly
- /// as a small helper to avoid marking it twice. The real marking comes
- /// by modifying the Tail for the segment, increasing it by this
- /// <see cref="FreezeOffset"/>. This effectively knocks it off the
- /// sequence expected by future enqueuers, such that any additional enqueuer
- /// will be unable to enqueue due to it not lining up with the expected
- /// sequence numbers. This value is chosen specially so that Tail will grow
- /// to a value that maps to the same slot but that won't be confused with
- /// any other enqueue/dequeue sequence number.
- /// </remarks>
- internal void EnsureFrozenForEnqueues() // must only be called while queue's segment lock is held
- {
- if (!_frozenForEnqueues) // flag used to ensure we don't increase the Tail more than once if frozen more than once
- {
- _frozenForEnqueues = true;
-
- // Increase the tail by FreezeOffset, spinning until we're successful in doing so.
- int tail = _headAndTail.Tail;
- while (true)
- {
- int oldTail = Interlocked.CompareExchange(ref _headAndTail.Tail, tail + FreezeOffset, tail);
- if (oldTail == tail)
- {
- break;
- }
- tail = oldTail;
- }
- }
- }
-
- /// <summary>Tries to dequeue an element from the queue.</summary>
- public bool TryDequeue([MaybeNullWhen(false)] out T item)
- {
- Slot[] slots = _slots;
-
- // Loop in case of contention...
- SpinWait spinner = default;
- while (true)
- {
- // Get the head at which to try to dequeue.
- int currentHead = Volatile.Read(ref _headAndTail.Head);
- int slotsIndex = currentHead & _slotsMask;
-
- // Read the sequence number for the head position.
- int sequenceNumber = Volatile.Read(ref slots[slotsIndex].SequenceNumber);
-
- // We can dequeue from this slot if it's been filled by an enqueuer, which
- // would have left the sequence number at pos+1.
- int diff = sequenceNumber - (currentHead + 1);
- if (diff == 0)
- {
- // We may be racing with other dequeuers. Try to reserve the slot by incrementing
- // the head. Once we've done that, no one else will be able to read from this slot,
- // and no enqueuer will be able to read from this slot until we've written the new
- // sequence number. WARNING: The next few lines are not reliable on a runtime that
- // supports thread aborts. If a thread abort were to sneak in after the CompareExchange
- // but before the Volatile.Write, enqueuers trying to enqueue into this slot would
- // spin indefinitely. If this implementation is ever used on such a platform, this
- // if block should be wrapped in a finally / prepared region.
- if (Interlocked.CompareExchange(ref _headAndTail.Head, currentHead + 1, currentHead) == currentHead)
- {
- // Successfully reserved the slot. Note that after the above CompareExchange, other threads
- // trying to dequeue from this slot will end up spinning until we do the subsequent Write.
- item = slots[slotsIndex].Item;
- if (!Volatile.Read(ref _preservedForObservation))
- {
- // If we're preserving, though, we don't zero out the slot, as we need it for
- // enumerations, peeking, ToArray, etc. And we don't update the sequence number,
- // so that an enqueuer will see it as full and be forced to move to a new segment.
- slots[slotsIndex].Item = default;
- Volatile.Write(ref slots[slotsIndex].SequenceNumber, currentHead + slots.Length);
- }
- return true;
- }
- }
- else if (diff < 0)
- {
- // The sequence number was less than what we needed, which means this slot doesn't
- // yet contain a value we can dequeue, i.e. the segment is empty. Technically it's
- // possible that multiple enqueuers could have written concurrently, with those
- // getting later slots actually finishing first, so there could be elements after
- // this one that are available, but we need to dequeue in order. So before declaring
- // failure and that the segment is empty, we check the tail to see if we're actually
- // empty or if we're just waiting for items in flight or after this one to become available.
- bool frozen = _frozenForEnqueues;
- int currentTail = Volatile.Read(ref _headAndTail.Tail);
- if (currentTail - currentHead <= 0 || (frozen && (currentTail - FreezeOffset - currentHead <= 0)))
- {
- item = default!;
- return false;
- }
-
- // It's possible it could have become frozen after we checked _frozenForEnqueues
- // and before reading the tail. That's ok: in that rare race condition, we just
- // loop around again.
- }
-
- // Lost a race. Spin a bit, then try again.
- spinner.SpinOnce(sleep1Threshold: -1);
- }
- }
-
- /// <summary>Tries to peek at an element from the queue, without removing it.</summary>
- public bool TryPeek([MaybeNullWhen(false)] out T result, bool resultUsed)
- {
- if (resultUsed)
- {
- // In order to ensure we don't get a torn read on the value, we mark the segment
- // as preserving for observation. Additional items can still be enqueued to this
- // segment, but no space will be freed during dequeues, such that the segment will
- // no longer be reusable.
- _preservedForObservation = true;
- Interlocked.MemoryBarrier();
- }
-
- Slot[] slots = _slots;
-
- // Loop in case of contention...
- SpinWait spinner = default;
- while (true)
- {
- // Get the head at which to try to peek.
- int currentHead = Volatile.Read(ref _headAndTail.Head);
- int slotsIndex = currentHead & _slotsMask;
-
- // Read the sequence number for the head position.
- int sequenceNumber = Volatile.Read(ref slots[slotsIndex].SequenceNumber);
-
- // We can peek from this slot if it's been filled by an enqueuer, which
- // would have left the sequence number at pos+1.
- int diff = sequenceNumber - (currentHead + 1);
- if (diff == 0)
- {
- result = resultUsed ? slots[slotsIndex].Item : default!;
- return true;
- }
- else if (diff < 0)
- {
- // The sequence number was less than what we needed, which means this slot doesn't
- // yet contain a value we can peek, i.e. the segment is empty. Technically it's
- // possible that multiple enqueuers could have written concurrently, with those
- // getting later slots actually finishing first, so there could be elements after
- // this one that are available, but we need to peek in order. So before declaring
- // failure and that the segment is empty, we check the tail to see if we're actually
- // empty or if we're just waiting for items in flight or after this one to become available.
- bool frozen = _frozenForEnqueues;
- int currentTail = Volatile.Read(ref _headAndTail.Tail);
- if (currentTail - currentHead <= 0 || (frozen && (currentTail - FreezeOffset - currentHead <= 0)))
- {
- result = default!;
- return false;
- }
-
- // It's possible it could have become frozen after we checked _frozenForEnqueues
- // and before reading the tail. That's ok: in that rare race condition, we just
- // loop around again.
- }
-
- // Lost a race. Spin a bit, then try again.
- spinner.SpinOnce(sleep1Threshold: -1);
- }
- }
-
- /// <summary>
- /// Attempts to enqueue the item. If successful, the item will be stored
- /// in the queue and true will be returned; otherwise, the item won't be stored, and false
- /// will be returned.
- /// </summary>
- public bool TryEnqueue(T item)
- {
- Slot[] slots = _slots;
-
- // Loop in case of contention...
- SpinWait spinner = default;
- while (true)
- {
- // Get the tail at which to try to return.
- int currentTail = Volatile.Read(ref _headAndTail.Tail);
- int slotsIndex = currentTail & _slotsMask;
-
- // Read the sequence number for the tail position.
- int sequenceNumber = Volatile.Read(ref slots[slotsIndex].SequenceNumber);
-
- // The slot is empty and ready for us to enqueue into it if its sequence
- // number matches the slot.
- int diff = sequenceNumber - currentTail;
- if (diff == 0)
- {
- // We may be racing with other enqueuers. Try to reserve the slot by incrementing
- // the tail. Once we've done that, no one else will be able to write to this slot,
- // and no dequeuer will be able to read from this slot until we've written the new
- // sequence number. WARNING: The next few lines are not reliable on a runtime that
- // supports thread aborts. If a thread abort were to sneak in after the CompareExchange
- // but before the Volatile.Write, other threads will spin trying to access this slot.
- // If this implementation is ever used on such a platform, this if block should be
- // wrapped in a finally / prepared region.
- if (Interlocked.CompareExchange(ref _headAndTail.Tail, currentTail + 1, currentTail) == currentTail)
- {
- // Successfully reserved the slot. Note that after the above CompareExchange, other threads
- // trying to return will end up spinning until we do the subsequent Write.
- slots[slotsIndex].Item = item;
- Volatile.Write(ref slots[slotsIndex].SequenceNumber, currentTail + 1);
- return true;
- }
- }
- else if (diff < 0)
- {
- // The sequence number was less than what we needed, which means this slot still
- // contains a value, i.e. the segment is full. Technically it's possible that multiple
- // dequeuers could have read concurrently, with those getting later slots actually
- // finishing first, so there could be spaces after this one that are available, but
- // we need to enqueue in order.
- return false;
- }
-
- // Lost a race. Spin a bit, then try again.
- spinner.SpinOnce(sleep1Threshold: -1);
- }
- }
-
- /// <summary>Represents a slot in the queue.</summary>
- [StructLayout(LayoutKind.Auto)]
- [DebuggerDisplay("Item = {Item}, SequenceNumber = {SequenceNumber}")]
- internal struct Slot
- {
- /// <summary>The item.</summary>
- [AllowNull, MaybeNull] public T Item; // SOS's ThreadPool command depends on this being at the beginning of the struct when T is a reference type
- /// <summary>The sequence number for this slot, used to synchronize between enqueuers and dequeuers.</summary>
- public int SequenceNumber;
- }
- }
-
- /// <summary>Padded head and tail indices, to avoid false sharing between producers and consumers.</summary>
- [DebuggerDisplay("Head = {Head}, Tail = {Tail}")]
- [StructLayout(LayoutKind.Explicit, Size = 3 * Internal.PaddingHelpers.CACHE_LINE_SIZE)] // padding before/between/after fields
- internal struct PaddedHeadAndTail
- {
- [FieldOffset(1 * Internal.PaddingHelpers.CACHE_LINE_SIZE)] public int Head;
- [FieldOffset(2 * Internal.PaddingHelpers.CACHE_LINE_SIZE)] public int Tail;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/IProducerConsumerCollection.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/IProducerConsumerCollection.cs
deleted file mode 100644
index 6100e216247..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/IProducerConsumerCollection.cs
+++ /dev/null
@@ -1,70 +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 System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Collections.Concurrent
-{
- /// <summary>
- /// A common interface for all concurrent collections.
- /// Defines methods to manipulate thread-safe collections intended for producer/consumer usage.
- /// </summary>
- /// <typeparam name="T">Specifies the type of elements in the collection.</typeparam>
- /// <remarks>
- /// All implementations of this interface must enable all members of this interface
- /// to be used concurrently from multiple threads.
- /// </remarks>
- public interface IProducerConsumerCollection<T> : IEnumerable<T>, ICollection
- {
- /// <summary>
- /// Copies the elements of the <see cref="IProducerConsumerCollection{T}"/> to
- /// an
- /// <see cref="System.Array"/>, starting at a specified index.
- /// </summary>
- /// <param name="array">The one-dimensional <see cref="System.Array"/> that is the destination of
- /// the elements copied from the <see cref="IProducerConsumerCollection{T}"/>.
- /// The array must have zero-based indexing.</param>
- /// <param name="index">The zero-based index in <paramref name="array"/> at which copying
- /// begins.</param>
- /// <exception cref="ArgumentNullException"><paramref name="array"/> is a null reference (Nothing in
- /// Visual Basic).</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than
- /// zero.</exception>
- /// <exception cref="ArgumentException"><paramref name="index"/> is equal to or greater than the
- /// length of the <paramref name="array"/>
- /// -or- The number of elements in the source <see cref="ConcurrentQueue{T}"/> is greater than the
- /// available space from <paramref name="index"/> to the end of the destination <paramref
- /// name="array"/>.
- /// </exception>
- void CopyTo(T[] array, int index);
-
- /// <summary>
- /// Attempts to add an object to the <see
- /// cref="IProducerConsumerCollection{T}"/>.
- /// </summary>
- /// <param name="item">The object to add to the <see
- /// cref="IProducerConsumerCollection{T}"/>.</param>
- /// <returns>true if the object was added successfully; otherwise, false.</returns>
- /// <exception cref="System.ArgumentException">The <paramref name="item"/> was invalid for this collection.</exception>
- bool TryAdd(T item);
-
- /// <summary>
- /// Attempts to remove and return an object from the <see cref="IProducerConsumerCollection{T}"/>.
- /// </summary>
- /// <param name="item">
- /// When this method returns, if the object was removed and returned successfully, <paramref
- /// name="item"/> contains the removed object. If no object was available to be removed, the value is
- /// unspecified.
- /// </param>
- /// <returns>true if an object was removed and returned successfully; otherwise, false.</returns>
- bool TryTake([MaybeNullWhen(false)] out T item);
-
- /// <summary>
- /// Copies the elements contained in the <see cref="IProducerConsumerCollection{T}"/> to a new array.
- /// </summary>
- /// <returns>A new array containing the elements copied from the <see cref="IProducerConsumerCollection{T}"/>.</returns>
- T[] ToArray();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/IProducerConsumerCollectionDebugView.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/IProducerConsumerCollectionDebugView.cs
deleted file mode 100644
index 15121989e4b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/IProducerConsumerCollectionDebugView.cs
+++ /dev/null
@@ -1,33 +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 System.Diagnostics;
-
-namespace System.Collections.Concurrent
-{
- /// <summary>
- /// A debugger view of the IProducerConsumerCollection that makes it simple to browse the
- /// collection's contents at a point in time.
- /// </summary>
- /// <typeparam name="T">The type of elements stored within.</typeparam>
- internal sealed class IProducerConsumerCollectionDebugView<T>
- {
- private readonly IProducerConsumerCollection<T> _collection; // The collection being viewed.
-
- /// <summary>
- /// Constructs a new debugger view object for the provided collection object.
- /// </summary>
- /// <param name="collection">A collection to browse in the debugger.</param>
- public IProducerConsumerCollectionDebugView(IProducerConsumerCollection<T> collection)
- {
- _collection = collection ?? throw new ArgumentNullException(nameof(collection));
- }
-
- /// <summary>
- /// Returns a snapshot of the underlying collection's elements.
- /// </summary>
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public T[] Items => _collection.ToArray();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/DictionaryEntry.cs b/netcore/System.Private.CoreLib/shared/System/Collections/DictionaryEntry.cs
deleted file mode 100644
index d328692b9ab..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/DictionaryEntry.cs
+++ /dev/null
@@ -1,45 +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 System.ComponentModel;
-
-namespace System.Collections
-{
- // A DictionaryEntry holds a key and a value from a dictionary.
- // It is returned by IDictionaryEnumerator::GetEntry().
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct DictionaryEntry
- {
- private object _key; // Do not rename (binary serialization)
- private object? _value; // Do not rename (binary serialization)
-
- // Constructs a new DictionaryEnumerator by setting the Key
- // and Value fields appropriately.
- public DictionaryEntry(object key, object? value)
- {
- _key = key;
- _value = value;
- }
-
- public object Key
- {
- get => _key;
- set => _key = value;
- }
-
- public object? Value
- {
- get => _value;
- set => _value = value;
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void Deconstruct(out object key, out object? value)
- {
- key = Key;
- value = Value;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs
deleted file mode 100644
index 46b9890dfe4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs
+++ /dev/null
@@ -1,1056 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: class to sort arrays
-**
-**
-===========================================================*/
-
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-
-namespace System.Collections.Generic
-{
- #region ArraySortHelper for single arrays
-
- internal static class IntrospectiveSortUtilities
- {
- // This is the threshold where Introspective sort switches to Insertion sort.
- // Empirically, 16 seems to speed up most cases without slowing down others, at least for integers.
- // Large value types may benefit from a smaller number.
- internal const int IntrosortSizeThreshold = 16;
-
- internal static int FloorLog2PlusOne(int n)
- {
- int result = 0;
- while (n >= 1)
- {
- result++;
- n /= 2;
- }
- return result;
- }
-
- [DoesNotReturn]
- internal static void ThrowOrIgnoreBadComparer(object? comparer)
- {
- throw new ArgumentException(SR.Format(SR.Arg_BogusIComparer, comparer));
- }
- }
-
- internal partial class ArraySortHelper<T>
- {
- #region IArraySortHelper<T> Members
-
- public void Sort(Span<T> keys, IComparer<T>? comparer)
- {
- // Add a try block here to detect IComparers (or their
- // underlying IComparables, etc) that are bogus.
- try
- {
- comparer ??= Comparer<T>.Default;
- IntrospectiveSort(keys, comparer.Compare);
- }
- catch (IndexOutOfRangeException)
- {
- IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
- }
- catch (Exception e)
- {
- throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
- }
- }
-
- public int BinarySearch(T[] array, int index, int length, T value, IComparer<T>? comparer)
- {
- try
- {
- comparer ??= Comparer<T>.Default;
- return InternalBinarySearch(array, index, length, value, comparer);
- }
- catch (Exception e)
- {
- throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
- }
- }
-
- #endregion
-
- internal static void Sort(Span<T> keys, Comparison<T> comparer)
- {
- Debug.Assert(comparer != null, "Check the arguments in the caller!");
-
- // Add a try block here to detect bogus comparisons
- try
- {
- IntrospectiveSort(keys, comparer);
- }
- catch (IndexOutOfRangeException)
- {
- IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
- }
- catch (Exception e)
- {
- throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
- }
- }
-
- internal static int InternalBinarySearch(T[] array, int index, int length, T value, IComparer<T> comparer)
- {
- Debug.Assert(array != null, "Check the arguments in the caller!");
- Debug.Assert(index >= 0 && length >= 0 && (array.Length - index >= length), "Check the arguments in the caller!");
-
- int lo = index;
- int hi = index + length - 1;
- while (lo <= hi)
- {
- int i = lo + ((hi - lo) >> 1);
- int order = comparer.Compare(array[i], value);
-
- if (order == 0) return i;
- if (order < 0)
- {
- lo = i + 1;
- }
- else
- {
- hi = i - 1;
- }
- }
-
- return ~lo;
- }
-
- private static void SwapIfGreater(Span<T> keys, Comparison<T> comparer, int i, int j)
- {
- if (i != j)
- {
- if (comparer(keys[i], keys[j]) > 0)
- {
- T key = keys[i];
- keys[i] = keys[j];
- keys[j] = key;
- }
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void Swap(Span<T> a, int i, int j)
- {
- if (i != j)
- {
- T t = a[i];
- a[i] = a[j];
- a[j] = t;
- }
- }
-
- internal static void IntrospectiveSort(Span<T> keys, Comparison<T> comparer)
- {
- Debug.Assert(comparer != null);
-
- if (keys.Length > 1)
- {
- IntroSort(keys, 2 * IntrospectiveSortUtilities.FloorLog2PlusOne(keys.Length), comparer);
- }
- }
-
- private static void IntroSort(Span<T> keys, int depthLimit, Comparison<T> comparer)
- {
- int lo = 0;
- int hi = keys.Length - 1;
-
- Debug.Assert(comparer != null);
-
- while (hi > lo)
- {
- int partitionSize = hi - lo + 1;
- if (partitionSize <= IntrospectiveSortUtilities.IntrosortSizeThreshold)
- {
- if (partitionSize == 1)
- {
- return;
- }
-
- if (partitionSize == 2)
- {
- SwapIfGreater(keys, comparer, lo, hi);
- return;
- }
-
- if (partitionSize == 3)
- {
- SwapIfGreater(keys, comparer, lo, hi - 1);
- SwapIfGreater(keys, comparer, lo, hi);
- SwapIfGreater(keys, comparer, hi - 1, hi);
- return;
- }
-
- InsertionSort(keys[lo..(hi+1)], comparer);
- return;
- }
-
- if (depthLimit == 0)
- {
- HeapSort(keys[lo..(hi+1)], comparer);
- return;
- }
- depthLimit--;
-
- int p = PickPivotAndPartition(keys[lo..(hi+1)], comparer);
-
- // Note we've already partitioned around the pivot and do not have to move the pivot again.
- IntroSort(keys[(p+1)..(hi+1)], depthLimit, comparer);
- hi = p - 1;
- }
- }
-
- private static int PickPivotAndPartition(Span<T> keys, Comparison<T> comparer)
- {
- Debug.Assert(comparer != null);
- Debug.Assert(!keys.IsEmpty);
-
- int lo = 0;
- int hi = keys.Length - 1;
-
- // Compute median-of-three. But also partition them, since we've done the comparison.
- int middle = lo + ((hi - lo) / 2);
-
- // Sort lo, mid and hi appropriately, then pick mid as the pivot.
- SwapIfGreater(keys, comparer, lo, middle); // swap the low with the mid point
- SwapIfGreater(keys, comparer, lo, hi); // swap the low with the high
- SwapIfGreater(keys, comparer, middle, hi); // swap the middle with the high
-
- T pivot = keys[middle];
- Swap(keys, middle, hi - 1);
- int left = lo, right = hi - 1; // We already partitioned lo and hi and put the pivot in hi - 1. And we pre-increment & decrement below.
-
- while (left < right)
- {
- while (comparer(keys[++left], pivot) < 0) ;
- while (comparer(pivot, keys[--right]) < 0) ;
-
- if (left >= right)
- break;
-
- Swap(keys, left, right);
- }
-
- // Put pivot in the right location.
- Swap(keys, left, hi - 1);
- return left;
- }
-
- private static void HeapSort(Span<T> keys, Comparison<T> comparer)
- {
- Debug.Assert(comparer != null);
- Debug.Assert(!keys.IsEmpty);
-
- int lo = 0;
- int hi = keys.Length - 1;
-
- int n = hi - lo + 1;
-
- for (int i = n / 2; i >= 1; i--)
- {
- DownHeap(keys, i, n, lo, comparer);
- }
-
- for (int i = n; i > 1; i--)
- {
- Swap(keys, lo, lo + i - 1);
- DownHeap(keys, 1, i - 1, lo, comparer);
- }
- }
-
- private static void DownHeap(Span<T> keys, int i, int n, int lo, Comparison<T> comparer)
- {
- Debug.Assert(comparer != null);
- Debug.Assert(lo >= 0);
- Debug.Assert(lo < keys.Length);
-
- T d = keys[lo + i - 1];
- while (i <= n / 2)
- {
- int child = 2 * i;
- if (child < n && comparer(keys[lo + child - 1], keys[lo + child]) < 0)
- {
- child++;
- }
-
- if (!(comparer(d, keys[lo + child - 1]) < 0))
- break;
-
- keys[lo + i - 1] = keys[lo + child - 1];
- i = child;
- }
-
- keys[lo + i - 1] = d;
- }
-
- private static void InsertionSort(Span<T> keys, Comparison<T> comparer)
- {
- for (int i = 0; i < keys.Length - 1; i++)
- {
- T t = keys[i + 1];
-
- int j = i;
- while (j >= 0 && comparer(t, keys[j]) < 0)
- {
- keys[j + 1] = keys[j];
- j--;
- }
-
- keys[j + 1] = t;
- }
- }
- }
-
- internal partial class GenericArraySortHelper<T>
- where T : IComparable<T>
- {
- // Do not add a constructor to this class because ArraySortHelper<T>.CreateSortHelper will not execute it
-
- #region IArraySortHelper<T> Members
-
- public void Sort(Span<T> keys, IComparer<T>? comparer)
- {
- try
- {
- if (comparer == null || comparer == Comparer<T>.Default)
- {
- IntrospectiveSort(keys);
- }
- else
- {
- ArraySortHelper<T>.IntrospectiveSort(keys, comparer.Compare);
- }
- }
- catch (IndexOutOfRangeException)
- {
- IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
- }
- catch (Exception e)
- {
- throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
- }
- }
-
- public int BinarySearch(T[] array, int index, int length, T value, IComparer<T>? comparer)
- {
- Debug.Assert(array != null, "Check the arguments in the caller!");
- Debug.Assert(index >= 0 && length >= 0 && (array.Length - index >= length), "Check the arguments in the caller!");
-
- try
- {
- if (comparer == null || comparer == Comparer<T>.Default)
- {
- return BinarySearch(array, index, length, value);
- }
- else
- {
- return ArraySortHelper<T>.InternalBinarySearch(array, index, length, value, comparer);
- }
- }
- catch (Exception e)
- {
- throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
- }
- }
-
- #endregion
-
- // This function is called when the user doesn't specify any comparer.
- // Since T is constrained here, we can call IComparable<T>.CompareTo here.
- // We can avoid boxing for value type and casting for reference types.
- private static int BinarySearch(T[] array, int index, int length, T value)
- {
- int lo = index;
- int hi = index + length - 1;
- while (lo <= hi)
- {
- int i = lo + ((hi - lo) >> 1);
- int order;
- if (array[i] == null)
- {
- order = (value == null) ? 0 : -1;
- }
- else
- {
- order = array[i].CompareTo(value);
- }
-
- if (order == 0)
- {
- return i;
- }
-
- if (order < 0)
- {
- lo = i + 1;
- }
- else
- {
- hi = i - 1;
- }
- }
-
- return ~lo;
- }
-
- private static void SwapIfGreater(Span<T> keys, int i, int j)
- {
- Debug.Assert(0 <= i && i < keys.Length);
- Debug.Assert(0 <= j && j < keys.Length);
-
- if (i != j)
- {
- if (keys[i] != null && keys[i].CompareTo(keys[j]) > 0)
- {
- T key = keys[i];
- keys[i] = keys[j];
- keys[j] = key;
- }
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void Swap(Span<T> a, int i, int j)
- {
- if (i != j)
- {
- T t = a[i];
- a[i] = a[j];
- a[j] = t;
- }
- }
-
- internal static void IntrospectiveSort(Span<T> keys)
- {
- if (keys.Length > 1)
- {
- IntroSort(keys, 2 * IntrospectiveSortUtilities.FloorLog2PlusOne(keys.Length));
- }
- }
-
- private static void IntroSort(Span<T> keys, int depthLimit)
- {
- int lo = 0;
- int hi = keys.Length - 1;
-
- while (hi > lo)
- {
- int partitionSize = hi - lo + 1;
- if (partitionSize <= IntrospectiveSortUtilities.IntrosortSizeThreshold)
- {
- if (partitionSize == 1)
- {
- return;
- }
- if (partitionSize == 2)
- {
- SwapIfGreater(keys, lo, hi);
- return;
- }
- if (partitionSize == 3)
- {
- SwapIfGreater(keys, lo, hi - 1);
- SwapIfGreater(keys, lo, hi);
- SwapIfGreater(keys, hi - 1, hi);
- return;
- }
-
- InsertionSort(keys[lo..(hi+1)]);
- return;
- }
-
- if (depthLimit == 0)
- {
- HeapSort(keys[lo..(hi+1)]);
- return;
- }
- depthLimit--;
-
- int p = PickPivotAndPartition(keys[lo..(hi+1)]);
-
- // Note we've already partitioned around the pivot and do not have to move the pivot again.
- IntroSort(keys[(p+1)..(hi+1)], depthLimit);
- hi = p - 1;
- }
- }
-
- private static int PickPivotAndPartition(Span<T> keys)
- {
- Debug.Assert(!keys.IsEmpty);
-
- int lo = 0;
- int hi = keys.Length - 1;
-
- // Compute median-of-three. But also partition them, since we've done the comparison.
- int middle = lo + ((hi - lo) / 2);
-
- // Sort lo, mid and hi appropriately, then pick mid as the pivot.
- SwapIfGreater(keys, lo, middle); // swap the low with the mid point
- SwapIfGreater(keys, lo, hi); // swap the low with the high
- SwapIfGreater(keys, middle, hi); // swap the middle with the high
-
- T pivot = keys[middle];
- Swap(keys, middle, hi - 1);
- int left = lo, right = hi - 1; // We already partitioned lo and hi and put the pivot in hi - 1. And we pre-increment & decrement below.
-
- while (left < right)
- {
- if (pivot == null)
- {
- while (left < (hi - 1) && keys[++left] == null) ;
- while (right > lo && keys[--right] != null) ;
- }
- else
- {
- while (pivot.CompareTo(keys[++left]) > 0) ;
- while (pivot.CompareTo(keys[--right]) < 0) ;
- }
-
- if (left >= right)
- break;
-
- Swap(keys, left, right);
- }
-
- // Put pivot in the right location.
- Swap(keys, left, hi - 1);
- return left;
- }
-
- private static void HeapSort(Span<T> keys)
- {
- Debug.Assert(!keys.IsEmpty);
-
- int lo = 0;
- int hi = keys.Length - 1;
-
- int n = hi - lo + 1;
- for (int i = n / 2; i >= 1; i = i - 1)
- {
- DownHeap(keys, i, n, lo);
- }
-
- for (int i = n; i > 1; i--)
- {
- Swap(keys, lo, lo + i - 1);
- DownHeap(keys, 1, i - 1, lo);
- }
- }
-
- private static void DownHeap(Span<T> keys, int i, int n, int lo)
- {
- Debug.Assert(lo >= 0);
- Debug.Assert(lo < keys.Length);
-
- T d = keys[lo + i - 1];
- while (i <= n / 2)
- {
- int child = 2 * i;
- if (child < n && (keys[lo + child - 1] == null || keys[lo + child - 1].CompareTo(keys[lo + child]) < 0))
- {
- child++;
- }
-
- if (keys[lo + child - 1] == null || keys[lo + child - 1].CompareTo(d) < 0)
- break;
-
- keys[lo + i - 1] = keys[lo + child - 1];
- i = child;
- }
-
- keys[lo + i - 1] = d;
- }
-
- private static void InsertionSort(Span<T> keys)
- {
- for (int i = 0; i < keys.Length - 1; i++)
- {
- T t = keys[i + 1];
-
- int j = i;
- while (j >= 0 && (t == null || t.CompareTo(keys[j]) < 0))
- {
- keys[j + 1] = keys[j];
- j--;
- }
-
- keys[j + 1] = t;
- }
- }
- }
-
- #endregion
-
- #region ArraySortHelper for paired key and value arrays
-
- internal partial class ArraySortHelper<TKey, TValue>
- {
- public void Sort(Span<TKey> keys, Span<TValue> values, IComparer<TKey>? comparer)
- {
- // Add a try block here to detect IComparers (or their
- // underlying IComparables, etc) that are bogus.
- try
- {
- IntrospectiveSort(keys, values, comparer ?? Comparer<TKey>.Default);
- }
- catch (IndexOutOfRangeException)
- {
- IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
- }
- catch (Exception e)
- {
- throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
- }
- }
-
- private static void SwapIfGreaterWithValues(Span<TKey> keys, Span<TValue> values, IComparer<TKey> comparer, int i, int j)
- {
- Debug.Assert(comparer != null);
- Debug.Assert(0 <= i && i < keys.Length && i < values.Length);
- Debug.Assert(0 <= j && j < keys.Length && j < values.Length);
-
- if (i != j)
- {
- if (comparer.Compare(keys[i], keys[j]) > 0)
- {
- TKey key = keys[i];
- keys[i] = keys[j];
- keys[j] = key;
-
- TValue value = values[i];
- values[i] = values[j];
- values[j] = value;
- }
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void Swap(Span<TKey> keys, Span<TValue> values, int i, int j)
- {
- if (i != j)
- {
- TKey k = keys[i];
- keys[i] = keys[j];
- keys[j] = k;
-
- TValue v = values[i];
- values[i] = values[j];
- values[j] = v;
- }
- }
-
- internal static void IntrospectiveSort(Span<TKey> keys, Span<TValue> values, IComparer<TKey> comparer)
- {
- Debug.Assert(comparer != null);
- Debug.Assert(keys.Length == values.Length);
-
- if (keys.Length > 1)
- {
- IntroSort(keys, values, 2 * IntrospectiveSortUtilities.FloorLog2PlusOne(keys.Length), comparer);
- }
- }
-
- private static void IntroSort(Span<TKey> keys, Span<TValue> values, int depthLimit, IComparer<TKey> comparer)
- {
- Debug.Assert(comparer != null);
-
- int lo = 0;
- int hi = keys.Length - 1;
-
- while (hi > lo)
- {
- int partitionSize = hi - lo + 1;
- if (partitionSize <= IntrospectiveSortUtilities.IntrosortSizeThreshold)
- {
- if (partitionSize == 1)
- {
- return;
- }
-
- if (partitionSize == 2)
- {
- SwapIfGreaterWithValues(keys, values, comparer, lo, hi);
- return;
- }
-
- if (partitionSize == 3)
- {
- SwapIfGreaterWithValues(keys, values, comparer, lo, hi - 1);
- SwapIfGreaterWithValues(keys, values, comparer, lo, hi);
- SwapIfGreaterWithValues(keys, values, comparer, hi - 1, hi);
- return;
- }
-
- InsertionSort(keys[lo..(hi+1)], values[lo..(hi+1)], comparer);
- return;
- }
-
- if (depthLimit == 0)
- {
- HeapSort(keys[lo..(hi+1)], values[lo..(hi+1)], comparer);
- return;
- }
- depthLimit--;
-
- int p = PickPivotAndPartition(keys[lo..(hi+1)], values[lo..(hi+1)], comparer);
-
- // Note we've already partitioned around the pivot and do not have to move the pivot again.
- IntroSort(keys[(p+1)..(hi+1)], values[(p+1)..(hi+1)], depthLimit, comparer);
- hi = p - 1;
- }
- }
-
- private static int PickPivotAndPartition(Span<TKey> keys, Span<TValue> values, IComparer<TKey> comparer)
- {
- Debug.Assert(comparer != null);
- Debug.Assert(!keys.IsEmpty);
-
- int lo = 0;
- int hi = keys.Length - 1;
-
- // Compute median-of-three. But also partition them, since we've done the comparison.
- int middle = lo + ((hi - lo) / 2);
-
- // Sort lo, mid and hi appropriately, then pick mid as the pivot.
- SwapIfGreaterWithValues(keys, values, comparer, lo, middle); // swap the low with the mid point
- SwapIfGreaterWithValues(keys, values, comparer, lo, hi); // swap the low with the high
- SwapIfGreaterWithValues(keys, values, comparer, middle, hi); // swap the middle with the high
-
- TKey pivot = keys[middle];
- Swap(keys, values, middle, hi - 1);
- int left = lo, right = hi - 1; // We already partitioned lo and hi and put the pivot in hi - 1. And we pre-increment & decrement below.
-
- while (left < right)
- {
- while (comparer.Compare(keys[++left], pivot) < 0) ;
- while (comparer.Compare(pivot, keys[--right]) < 0) ;
-
- if (left >= right)
- break;
-
- Swap(keys, values, left, right);
- }
-
- // Put pivot in the right location.
- Swap(keys, values, left, hi - 1);
- return left;
- }
-
- private static void HeapSort(Span<TKey> keys, Span<TValue> values, IComparer<TKey> comparer)
- {
- Debug.Assert(comparer != null);
- Debug.Assert(!keys.IsEmpty);
-
- int lo = 0;
- int hi = keys.Length - 1;
-
- int n = hi - lo + 1;
- for (int i = n / 2; i >= 1; i--)
- {
- DownHeap(keys, values, i, n, lo, comparer);
- }
-
- for (int i = n; i > 1; i--)
- {
- Swap(keys, values, lo, lo + i - 1);
- DownHeap(keys, values, 1, i - 1, lo, comparer);
- }
- }
-
- private static void DownHeap(Span<TKey> keys, Span<TValue> values, int i, int n, int lo, IComparer<TKey> comparer)
- {
- Debug.Assert(comparer != null);
- Debug.Assert(lo >= 0);
- Debug.Assert(lo < keys.Length);
-
- TKey d = keys[lo + i - 1];
- TValue dValue = values[lo + i - 1];
-
- while (i <= n / 2)
- {
- int child = 2 * i;
- if (child < n && comparer.Compare(keys[lo + child - 1], keys[lo + child]) < 0)
- {
- child++;
- }
-
- if (!(comparer.Compare(d, keys[lo + child - 1]) < 0))
- break;
-
- keys[lo + i - 1] = keys[lo + child - 1];
- values[lo + i - 1] = values[lo + child - 1];
- i = child;
- }
-
- keys[lo + i - 1] = d;
- values[lo + i - 1] = dValue;
- }
-
- private static void InsertionSort(Span<TKey> keys, Span<TValue> values, IComparer<TKey> comparer)
- {
- Debug.Assert(comparer != null);
-
- for (int i = 0; i < keys.Length - 1; i++)
- {
- TKey t = keys[i + 1];
- TValue tValue = values[i + 1];
-
- int j = i;
- while (j >= 0 && comparer.Compare(t, keys[j]) < 0)
- {
- keys[j + 1] = keys[j];
- values[j + 1] = values[j];
- j--;
- }
-
- keys[j + 1] = t;
- values[j + 1] = tValue;
- }
- }
- }
-
- internal partial class GenericArraySortHelper<TKey, TValue>
- where TKey : IComparable<TKey>
- {
- public void Sort(Span<TKey> keys, Span<TValue> values, IComparer<TKey>? comparer)
- {
- // Add a try block here to detect IComparers (or their
- // underlying IComparables, etc) that are bogus.
- try
- {
- if (comparer == null || comparer == Comparer<TKey>.Default)
- {
- IntrospectiveSort(keys, values);
- }
- else
- {
- ArraySortHelper<TKey, TValue>.IntrospectiveSort(keys, values, comparer);
- }
- }
- catch (IndexOutOfRangeException)
- {
- IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
- }
- catch (Exception e)
- {
- throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
- }
- }
-
- private static void SwapIfGreaterWithValues(Span<TKey> keys, Span<TValue> values, int i, int j)
- {
- if (i != j)
- {
- if (keys[i] != null && keys[i].CompareTo(keys[j]) > 0)
- {
- TKey key = keys[i];
- keys[i] = keys[j];
- keys[j] = key;
-
- TValue value = values[i];
- values[i] = values[j];
- values[j] = value;
- }
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void Swap(Span<TKey> keys, Span<TValue> values, int i, int j)
- {
- if (i != j)
- {
- TKey k = keys[i];
- keys[i] = keys[j];
- keys[j] = k;
-
- TValue v = values[i];
- values[i] = values[j];
- values[j] = v;
- }
- }
-
- internal static void IntrospectiveSort(Span<TKey> keys, Span<TValue> values)
- {
- Debug.Assert(keys.Length == values.Length);
-
- if (keys.Length > 1)
- {
- IntroSort(keys, values, 2 * IntrospectiveSortUtilities.FloorLog2PlusOne(keys.Length));
- }
- }
-
- private static void IntroSort(Span<TKey> keys, Span<TValue> values, int depthLimit)
- {
- int lo = 0;
- int hi = keys.Length - 1;
-
- while (hi > lo)
- {
- int partitionSize = hi - lo + 1;
- if (partitionSize <= IntrospectiveSortUtilities.IntrosortSizeThreshold)
- {
- if (partitionSize == 1)
- {
- return;
- }
-
- if (partitionSize == 2)
- {
- SwapIfGreaterWithValues(keys, values, lo, hi);
- return;
- }
-
- if (partitionSize == 3)
- {
- SwapIfGreaterWithValues(keys, values, lo, hi - 1);
- SwapIfGreaterWithValues(keys, values, lo, hi);
- SwapIfGreaterWithValues(keys, values, hi - 1, hi);
- return;
- }
-
- InsertionSort(keys[lo..(hi+1)], values[lo..(hi+1)]);
- return;
- }
-
- if (depthLimit == 0)
- {
- HeapSort(keys[lo..(hi+1)], values[lo..(hi+1)]);
- return;
- }
- depthLimit--;
-
- int p = PickPivotAndPartition(keys[lo..(hi+1)], values[lo..(hi+1)]);
-
- // Note we've already partitioned around the pivot and do not have to move the pivot again.
- IntroSort(keys[(p+1)..(hi+1)], values[(p+1)..(hi+1)], depthLimit);
- hi = p - 1;
- }
- }
-
- private static int PickPivotAndPartition(Span<TKey> keys, Span<TValue> values)
- {
- Debug.Assert(!keys.IsEmpty);
-
- int lo = 0;
- int hi = keys.Length - 1;
-
- // Compute median-of-three. But also partition them, since we've done the comparison.
- int middle = lo + ((hi - lo) / 2);
-
- // Sort lo, mid and hi appropriately, then pick mid as the pivot.
- SwapIfGreaterWithValues(keys, values, lo, middle); // swap the low with the mid point
- SwapIfGreaterWithValues(keys, values, lo, hi); // swap the low with the high
- SwapIfGreaterWithValues(keys, values, middle, hi); // swap the middle with the high
-
- TKey pivot = keys[middle];
- Swap(keys, values, middle, hi - 1);
- int left = lo, right = hi - 1; // We already partitioned lo and hi and put the pivot in hi - 1. And we pre-increment & decrement below.
-
- while (left < right)
- {
- if (pivot == null)
- {
- while (left < (hi - 1) && keys[++left] == null) ;
- while (right > lo && keys[--right] != null) ;
- }
- else
- {
- while (pivot.CompareTo(keys[++left]) > 0) ;
- while (pivot.CompareTo(keys[--right]) < 0) ;
- }
-
- if (left >= right)
- break;
-
- Swap(keys, values, left, right);
- }
-
- // Put pivot in the right location.
- Swap(keys, values, left, hi - 1);
- return left;
- }
-
- private static void HeapSort(Span<TKey> keys, Span<TValue> values)
- {
- Debug.Assert(!keys.IsEmpty);
-
- int lo = 0;
- int hi = keys.Length - 1;
-
- int n = hi - lo + 1;
- for (int i = n / 2; i >= 1; i--)
- {
- DownHeap(keys, values, i, n, lo);
- }
-
- for (int i = n; i > 1; i--)
- {
- Swap(keys, values, lo, lo + i - 1);
- DownHeap(keys, values, 1, i - 1, lo);
- }
- }
-
- private static void DownHeap(Span<TKey> keys, Span<TValue> values, int i, int n, int lo)
- {
- Debug.Assert(lo >= 0);
- Debug.Assert(lo < keys.Length);
-
- TKey d = keys[lo + i - 1];
- TValue dValue = values[lo + i - 1];
-
- while (i <= n / 2)
- {
- int child = 2 * i;
- if (child < n && (keys[lo + child - 1] == null || keys[lo + child - 1].CompareTo(keys[lo + child]) < 0))
- {
- child++;
- }
-
- if (keys[lo + child - 1] == null || keys[lo + child - 1].CompareTo(d) < 0)
- break;
-
- keys[lo + i - 1] = keys[lo + child - 1];
- values[lo + i - 1] = values[lo + child - 1];
- i = child;
- }
-
- keys[lo + i - 1] = d;
- values[lo + i - 1] = dValue;
- }
-
- private static void InsertionSort(Span<TKey> keys, Span<TValue> values)
- {
- for (int i = 0; i < keys.Length - 1; i++)
- {
- TKey t = keys[i + 1];
- TValue tValue = values[i + 1];
-
- int j = i;
- while (j >= 0 && (t == null || t.CompareTo(keys[j]) < 0))
- {
- keys[j + 1] = keys[j];
- values[j + 1] = values[j];
- j--;
- }
-
- keys[j + 1] = t;
- values[j + 1] = tValue;
- }
- }
- }
-
- #endregion
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Comparer.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Comparer.cs
deleted file mode 100644
index ec2535e2010..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Comparer.cs
+++ /dev/null
@@ -1,149 +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 System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-
-namespace System.Collections.Generic
-{
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public abstract partial class Comparer<T> : IComparer, IComparer<T>
- {
- // public static Comparer<T> Default is runtime-specific
-
- public static Comparer<T> Create(Comparison<T> comparison)
- {
- if (comparison == null)
- throw new ArgumentNullException(nameof(comparison));
-
- return new ComparisonComparer<T>(comparison);
- }
-
- public abstract int Compare([AllowNull] T x, [AllowNull] T y);
-
- int IComparer.Compare(object? x, object? y)
- {
- if (x == null) return y == null ? 0 : -1;
- if (y == null) return 1;
- if (x is T && y is T) return Compare((T)x, (T)y);
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArgumentForComparison);
- return 0;
- }
- }
-
- internal sealed class ComparisonComparer<T> : Comparer<T>
- {
- private readonly Comparison<T> _comparison;
-
- public ComparisonComparer(Comparison<T> comparison)
- {
- _comparison = comparison;
- }
-
- public override int Compare(T x, T y)
- {
- return _comparison(x, y);
- }
- }
-
- // Note: although there is a lot of shared code in the following
- // comparers, we do not incorporate it into a base class for perf
- // reasons. Adding another base class (even one with no fields)
- // means another generic instantiation, which can be costly esp.
- // for value types.
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- // Needs to be public to support binary serialization compatibility
- public sealed partial class GenericComparer<T> : Comparer<T> where T : IComparable<T>
- {
- public override int Compare([AllowNull] T x, [AllowNull] T y)
- {
- if (x != null)
- {
- if (y != null) return x.CompareTo(y);
- return 1;
- }
- if (y != null) return -1;
- return 0;
- }
-
- // Equals method for the comparer itself.
- public override bool Equals(object? obj) =>
- obj != null && GetType() == obj.GetType();
-
- public override int GetHashCode() =>
- GetType().GetHashCode();
- }
-
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- // Needs to be public to support binary serialization compatibility
- public sealed partial class NullableComparer<T> : Comparer<T?> where T : struct, IComparable<T>
- {
- public override int Compare(T? x, T? y)
- {
- if (x.HasValue)
- {
- if (y.HasValue) return x.value.CompareTo(y.value);
- return 1;
- }
- if (y.HasValue) return -1;
- return 0;
- }
-
- // Equals method for the comparer itself.
- public override bool Equals(object? obj) =>
- obj != null && GetType() == obj.GetType();
-
- public override int GetHashCode() =>
- GetType().GetHashCode();
- }
-
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- // Needs to be public to support binary serialization compatibility
- public sealed partial class ObjectComparer<T> : Comparer<T>
- {
- public override int Compare([AllowNull] T x, [AllowNull] T y)
- {
- return System.Collections.Comparer.Default.Compare(x, y);
- }
-
- // Equals method for the comparer itself.
- public override bool Equals(object? obj) =>
- obj != null && GetType() == obj.GetType();
-
- public override int GetHashCode() =>
- GetType().GetHashCode();
- }
-
- [Serializable]
- internal sealed partial class EnumComparer<T> : Comparer<T>, ISerializable where T : struct, Enum
- {
- internal EnumComparer() { }
-
- // Used by the serialization engine.
- private EnumComparer(SerializationInfo info, StreamingContext context) { }
-
- // public override int Compare(T x, T y) is runtime-specific
-
- // Equals method for the comparer itself.
- public override bool Equals(object? obj) =>
- obj != null && GetType() == obj.GetType();
-
- public override int GetHashCode() =>
- GetType().GetHashCode();
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- // Previously Comparer<T> was not specialized for enums,
- // and instead fell back to ObjectComparer which uses boxing.
- // Set the type as ObjectComparer here so code that serializes
- // Comparer for enums will not break.
- info.SetType(typeof(ObjectComparer<T>));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs
deleted file mode 100644
index 3680216b6aa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs
+++ /dev/null
@@ -1,1663 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-
-using Internal.Runtime.CompilerServices;
-
-namespace System.Collections.Generic
-{
- /// <summary>
- /// Used internally to control behavior of insertion into a <see cref="Dictionary{TKey, TValue}"/>.
- /// </summary>
- internal enum InsertionBehavior : byte
- {
- /// <summary>
- /// The default insertion behavior.
- /// </summary>
- None = 0,
-
- /// <summary>
- /// Specifies that an existing entry with the same key should be overwritten if encountered.
- /// </summary>
- OverwriteExisting = 1,
-
- /// <summary>
- /// Specifies that if an existing entry with the same key is encountered, an exception should be thrown.
- /// </summary>
- ThrowOnExisting = 2
- }
-
- [DebuggerTypeProxy(typeof(IDictionaryDebugView<,>))]
- [DebuggerDisplay("Count = {Count}")]
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>, ISerializable, IDeserializationCallback where TKey : notnull
- {
- private struct Entry
- {
- public uint hashCode;
- // 0-based index of next entry in chain: -1 means end of chain
- // also encodes whether this entry _itself_ is part of the free list by changing sign and subtracting 3,
- // so -2 means end of free list, -3 means index 0 but on free list, -4 means index 1 but on free list, etc.
- public int next;
- public TKey key; // Key of entry
- public TValue value; // Value of entry
- }
-
- private int[]? _buckets;
- private Entry[]? _entries;
-#if BIT64
- private ulong _fastModMultiplier;
-#endif
- private int _count;
- private int _freeList;
- private int _freeCount;
- private int _version;
- private IEqualityComparer<TKey>? _comparer;
- private KeyCollection? _keys;
- private ValueCollection? _values;
- private const int StartOfFreeList = -3;
-
- // constants for serialization
- private const string VersionName = "Version"; // Do not rename (binary serialization)
- private const string HashSizeName = "HashSize"; // Do not rename (binary serialization). Must save buckets.Length
- private const string KeyValuePairsName = "KeyValuePairs"; // Do not rename (binary serialization)
- private const string ComparerName = "Comparer"; // Do not rename (binary serialization)
-
- public Dictionary() : this(0, null) { }
-
- public Dictionary(int capacity) : this(capacity, null) { }
-
- public Dictionary(IEqualityComparer<TKey>? comparer) : this(0, comparer) { }
-
- public Dictionary(int capacity, IEqualityComparer<TKey>? comparer)
- {
- if (capacity < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
- if (capacity > 0) Initialize(capacity);
- if (comparer != EqualityComparer<TKey>.Default)
- {
- _comparer = comparer;
- }
-
- if (typeof(TKey) == typeof(string) && _comparer == null)
- {
- // To start, move off default comparer for string which is randomised
- _comparer = (IEqualityComparer<TKey>)NonRandomizedStringEqualityComparer.Default;
- }
- }
-
- public Dictionary(IDictionary<TKey, TValue> dictionary) : this(dictionary, null) { }
-
- public Dictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey>? comparer) :
- this(dictionary != null ? dictionary.Count : 0, comparer)
- {
- if (dictionary == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
- }
-
- // It is likely that the passed-in dictionary is Dictionary<TKey,TValue>. When this is the case,
- // avoid the enumerator allocation and overhead by looping through the entries array directly.
- // We only do this when dictionary is Dictionary<TKey,TValue> and not a subclass, to maintain
- // back-compat with subclasses that may have overridden the enumerator behavior.
- if (dictionary.GetType() == typeof(Dictionary<TKey, TValue>))
- {
- Dictionary<TKey, TValue> d = (Dictionary<TKey, TValue>)dictionary;
- int count = d._count;
- Entry[]? entries = d._entries;
- for (int i = 0; i < count; i++)
- {
- if (entries![i].next >= -1)
- {
- Add(entries[i].key, entries[i].value);
- }
- }
- return;
- }
-
- foreach (KeyValuePair<TKey, TValue> pair in dictionary)
- {
- Add(pair.Key, pair.Value);
- }
- }
-
- public Dictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection) : this(collection, null) { }
-
- public Dictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey>? comparer) :
- this((collection as ICollection<KeyValuePair<TKey, TValue>>)?.Count ?? 0, comparer)
- {
- if (collection == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
- }
-
- foreach (KeyValuePair<TKey, TValue> pair in collection)
- {
- Add(pair.Key, pair.Value);
- }
- }
-
- protected Dictionary(SerializationInfo info, StreamingContext context)
- {
- // We can't do anything with the keys and values until the entire graph has been deserialized
- // and we have a resonable estimate that GetHashCode is not going to fail. For the time being,
- // we'll just cache this. The graph is not valid until OnDeserialization has been called.
- HashHelpers.SerializationInfoTable.Add(this, info);
- }
-
- public IEqualityComparer<TKey> Comparer =>
- (_comparer == null || _comparer is NonRandomizedStringEqualityComparer) ?
- EqualityComparer<TKey>.Default :
- _comparer;
-
- public int Count => _count - _freeCount;
-
- public KeyCollection Keys => _keys ??= new KeyCollection(this);
-
- ICollection<TKey> IDictionary<TKey, TValue>.Keys => _keys ??= new KeyCollection(this);
-
- IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys => _keys ??= new KeyCollection(this);
-
- public ValueCollection Values => _values ??= new ValueCollection(this);
-
- ICollection<TValue> IDictionary<TKey, TValue>.Values => _values ??= new ValueCollection(this);
-
- IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => _values ??= new ValueCollection(this);
-
- public TValue this[TKey key]
- {
- get
- {
- ref TValue value = ref FindValue(key);
- if (!Unsafe.IsNullRef(ref value))
- {
- return value;
- }
- ThrowHelper.ThrowKeyNotFoundException(key);
- return default;
- }
- set
- {
- bool modified = TryInsert(key, value, InsertionBehavior.OverwriteExisting);
- Debug.Assert(modified);
- }
- }
-
- public void Add(TKey key, TValue value)
- {
- bool modified = TryInsert(key, value, InsertionBehavior.ThrowOnExisting);
- Debug.Assert(modified); // If there was an existing key and the Add failed, an exception will already have been thrown.
- }
-
- void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> keyValuePair)
- => Add(keyValuePair.Key, keyValuePair.Value);
-
- bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> keyValuePair)
- {
- ref TValue value = ref FindValue(keyValuePair.Key);
- if (!Unsafe.IsNullRef(ref value) && EqualityComparer<TValue>.Default.Equals(value, keyValuePair.Value))
- {
- return true;
- }
- return false;
- }
-
- bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> keyValuePair)
- {
- ref TValue value = ref FindValue(keyValuePair.Key);
- if (!Unsafe.IsNullRef(ref value) && EqualityComparer<TValue>.Default.Equals(value, keyValuePair.Value))
- {
- Remove(keyValuePair.Key);
- return true;
- }
- return false;
- }
-
- public void Clear()
- {
- int count = _count;
- if (count > 0)
- {
- Debug.Assert(_buckets != null, "_buckets should be non-null");
- Debug.Assert(_entries != null, "_entries should be non-null");
-
- Array.Clear(_buckets, 0, _buckets.Length);
-
- _count = 0;
- _freeList = -1;
- _freeCount = 0;
- Array.Clear(_entries, 0, count);
- }
- }
-
- public bool ContainsKey(TKey key)
- => !Unsafe.IsNullRef(ref FindValue(key));
-
- public bool ContainsValue(TValue value)
- {
- Entry[]? entries = _entries;
- if (value == null)
- {
- for (int i = 0; i < _count; i++)
- {
- if (entries![i].next >= -1 && entries[i].value == null) return true;
- }
- }
- else
- {
- if (default(TValue)! != null) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- // ValueType: Devirtualize with EqualityComparer<TValue>.Default intrinsic
- for (int i = 0; i < _count; i++)
- {
- if (entries![i].next >= -1 && EqualityComparer<TValue>.Default.Equals(entries[i].value, value)) return true;
- }
- }
- else
- {
- // Object type: Shared Generic, EqualityComparer<TValue>.Default won't devirtualize
- // https://github.com/dotnet/coreclr/issues/17273
- // So cache in a local rather than get EqualityComparer per loop iteration
- EqualityComparer<TValue> defaultComparer = EqualityComparer<TValue>.Default;
- for (int i = 0; i < _count; i++)
- {
- if (entries![i].next >= -1 && defaultComparer.Equals(entries[i].value, value)) return true;
- }
- }
- }
- return false;
- }
-
- private void CopyTo(KeyValuePair<TKey, TValue>[] array, int index)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if ((uint)index > (uint)array.Length)
- {
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- }
-
- if (array.Length - index < Count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
- }
-
- int count = _count;
- Entry[]? entries = _entries;
- for (int i = 0; i < count; i++)
- {
- if (entries![i].next >= -1)
- {
- array[index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value);
- }
- }
- }
-
- public Enumerator GetEnumerator()
- => new Enumerator(this, Enumerator.KeyValuePair);
-
- IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
- => new Enumerator(this, Enumerator.KeyValuePair);
-
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.info);
- }
-
- info.AddValue(VersionName, _version);
- info.AddValue(ComparerName, _comparer ?? EqualityComparer<TKey>.Default, typeof(IEqualityComparer<TKey>));
- info.AddValue(HashSizeName, _buckets == null ? 0 : _buckets.Length); // This is the length of the bucket array
-
- if (_buckets != null)
- {
- var array = new KeyValuePair<TKey, TValue>[Count];
- CopyTo(array, 0);
- info.AddValue(KeyValuePairsName, array, typeof(KeyValuePair<TKey, TValue>[]));
- }
- }
-
- private ref TValue FindValue(TKey key)
- {
- if (key == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
-
- ref Entry entry = ref Unsafe.NullRef<Entry>();
- if (_buckets != null)
- {
- Debug.Assert(_entries != null, "expected entries to be != null");
- IEqualityComparer<TKey>? comparer = _comparer;
- if (comparer == null)
- {
- uint hashCode = (uint)key.GetHashCode();
- int i = GetBucket(hashCode);
- Entry[]? entries = _entries;
- uint collisionCount = 0;
- if (default(TKey)! != null) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- // ValueType: Devirtualize with EqualityComparer<TValue>.Default intrinsic
-
- // Value in _buckets is 1-based; subtract 1 from i. We do it here so it fuses with the following conditional.
- i--;
- do
- {
- // Should be a while loop https://github.com/dotnet/coreclr/issues/15476
- // Test in if to drop range check for following array access
- if ((uint)i >= (uint)entries.Length)
- {
- goto ReturnNotFound;
- }
-
- entry = ref entries[i];
- if (entry.hashCode == hashCode && EqualityComparer<TKey>.Default.Equals(entry.key, key))
- {
- goto ReturnFound;
- }
-
- i = entry.next;
-
- collisionCount++;
- } while (collisionCount <= (uint)entries.Length);
- // The chain of entries forms a loop; which means a concurrent update has happened.
- // Break out of the loop and throw, rather than looping forever.
- goto ConcurrentOperation;
- }
- else
- {
- // Object type: Shared Generic, EqualityComparer<TValue>.Default won't devirtualize
- // https://github.com/dotnet/coreclr/issues/17273
- // So cache in a local rather than get EqualityComparer per loop iteration
- EqualityComparer<TKey> defaultComparer = EqualityComparer<TKey>.Default;
-
- // Value in _buckets is 1-based; subtract 1 from i. We do it here so it fuses with the following conditional.
- i--;
- do
- {
- // Should be a while loop https://github.com/dotnet/coreclr/issues/15476
- // Test in if to drop range check for following array access
- if ((uint)i >= (uint)entries.Length)
- {
- goto ReturnNotFound;
- }
-
- entry = ref entries[i];
- if (entry.hashCode == hashCode && defaultComparer.Equals(entry.key, key))
- {
- goto ReturnFound;
- }
-
- i = entry.next;
-
- collisionCount++;
- } while (collisionCount <= (uint)entries.Length);
- // The chain of entries forms a loop; which means a concurrent update has happened.
- // Break out of the loop and throw, rather than looping forever.
- goto ConcurrentOperation;
- }
- }
- else
- {
- uint hashCode = (uint)comparer.GetHashCode(key);
- int i = GetBucket(hashCode);
- Entry[]? entries = _entries;
- uint collisionCount = 0;
- // Value in _buckets is 1-based; subtract 1 from i. We do it here so it fuses with the following conditional.
- i--;
- do
- {
- // Should be a while loop https://github.com/dotnet/coreclr/issues/15476
- // Test in if to drop range check for following array access
- if ((uint)i >= (uint)entries.Length)
- {
- goto ReturnNotFound;
- }
-
- entry = ref entries[i];
- if (entry.hashCode == hashCode && comparer.Equals(entry.key, key))
- {
- goto ReturnFound;
- }
-
- i = entry.next;
-
- collisionCount++;
- } while (collisionCount <= (uint)entries.Length);
- // The chain of entries forms a loop; which means a concurrent update has happened.
- // Break out of the loop and throw, rather than looping forever.
- goto ConcurrentOperation;
- }
- }
-
- goto ReturnNotFound;
-
- ConcurrentOperation:
- ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported();
- ReturnFound:
- ref TValue value = ref entry.value;
- Return:
- return ref value;
- ReturnNotFound:
- value = ref Unsafe.NullRef<TValue>();
- goto Return;
- }
-
- private int Initialize(int capacity)
- {
- int size = HashHelpers.GetPrime(capacity);
- int[] buckets = new int[size];
- Entry[] entries = new Entry[size];
-
- // Assign member variables after both arrays allocated to guard against corruption from OOM if second fails
- _freeList = -1;
-#if BIT64
- _fastModMultiplier = HashHelpers.GetFastModMultiplier((uint)size);
-#endif
- _buckets = buckets;
- _entries = entries;
-
- return size;
- }
-
- private bool TryInsert(TKey key, TValue value, InsertionBehavior behavior)
- {
- if (key == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
-
- if (_buckets == null)
- {
- Initialize(0);
- }
- Debug.Assert(_buckets != null);
-
- Entry[]? entries = _entries;
- Debug.Assert(entries != null, "expected entries to be non-null");
-
- IEqualityComparer<TKey>? comparer = _comparer;
- uint hashCode = (uint)((comparer == null) ? key.GetHashCode() : comparer.GetHashCode(key));
-
- uint collisionCount = 0;
- ref int bucket = ref GetBucket(hashCode);
- // Value in _buckets is 1-based
- int i = bucket - 1;
-
- if (comparer == null)
- {
- if (default(TKey)! != null) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- // ValueType: Devirtualize with EqualityComparer<TValue>.Default intrinsic
- while (true)
- {
- // Should be a while loop https://github.com/dotnet/coreclr/issues/15476
- // Test uint in if rather than loop condition to drop range check for following array access
- if ((uint)i >= (uint)entries.Length)
- {
- break;
- }
-
- if (entries[i].hashCode == hashCode && EqualityComparer<TKey>.Default.Equals(entries[i].key, key))
- {
- if (behavior == InsertionBehavior.OverwriteExisting)
- {
- entries[i].value = value;
- _version++;
- return true;
- }
-
- if (behavior == InsertionBehavior.ThrowOnExisting)
- {
- ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException(key);
- }
-
- return false;
- }
-
- i = entries[i].next;
-
- collisionCount++;
- if (collisionCount > (uint)entries.Length)
- {
- // The chain of entries forms a loop; which means a concurrent update has happened.
- // Break out of the loop and throw, rather than looping forever.
- ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported();
- }
- }
- }
- else
- {
- // Object type: Shared Generic, EqualityComparer<TValue>.Default won't devirtualize
- // https://github.com/dotnet/coreclr/issues/17273
- // So cache in a local rather than get EqualityComparer per loop iteration
- EqualityComparer<TKey> defaultComparer = EqualityComparer<TKey>.Default;
- while (true)
- {
- // Should be a while loop https://github.com/dotnet/coreclr/issues/15476
- // Test uint in if rather than loop condition to drop range check for following array access
- if ((uint)i >= (uint)entries.Length)
- {
- break;
- }
-
- if (entries[i].hashCode == hashCode && defaultComparer.Equals(entries[i].key, key))
- {
- if (behavior == InsertionBehavior.OverwriteExisting)
- {
- entries[i].value = value;
- _version++;
- return true;
- }
-
- if (behavior == InsertionBehavior.ThrowOnExisting)
- {
- ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException(key);
- }
-
- return false;
- }
-
- i = entries[i].next;
-
- collisionCount++;
- if (collisionCount > (uint)entries.Length)
- {
- // The chain of entries forms a loop; which means a concurrent update has happened.
- // Break out of the loop and throw, rather than looping forever.
- ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported();
- }
- }
- }
- }
- else
- {
- while (true)
- {
- // Should be a while loop https://github.com/dotnet/coreclr/issues/15476
- // Test uint in if rather than loop condition to drop range check for following array access
- if ((uint)i >= (uint)entries.Length)
- {
- break;
- }
-
- if (entries[i].hashCode == hashCode && comparer.Equals(entries[i].key, key))
- {
- if (behavior == InsertionBehavior.OverwriteExisting)
- {
- entries[i].value = value;
- _version++;
- return true;
- }
-
- if (behavior == InsertionBehavior.ThrowOnExisting)
- {
- ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException(key);
- }
-
- return false;
- }
-
- i = entries[i].next;
-
- collisionCount++;
- if (collisionCount > (uint)entries.Length)
- {
- // The chain of entries forms a loop; which means a concurrent update has happened.
- // Break out of the loop and throw, rather than looping forever.
- ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported();
- }
- }
- }
-
- bool updateFreeList = false;
- int index;
- if (_freeCount > 0)
- {
- index = _freeList;
- updateFreeList = true;
- _freeCount--;
- }
- else
- {
- int count = _count;
- if (count == entries.Length)
- {
- Resize();
- bucket = ref GetBucket(hashCode);
- }
- index = count;
- _count = count + 1;
- entries = _entries;
- }
-
- ref Entry entry = ref entries![index];
-
- if (updateFreeList)
- {
- Debug.Assert((StartOfFreeList - entries[_freeList].next) >= -1, "shouldn't overflow because `next` cannot underflow");
-
- _freeList = StartOfFreeList - entries[_freeList].next;
- }
- entry.hashCode = hashCode;
- // Value in _buckets is 1-based
- entry.next = bucket - 1;
- entry.key = key;
- entry.value = value;
- // Value in _buckets is 1-based
- bucket = index + 1;
- _version++;
-
- // Value types never rehash
- if (default(TKey)! == null && collisionCount > HashHelpers.HashCollisionThreshold && comparer is NonRandomizedStringEqualityComparer) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- // If we hit the collision threshold we'll need to switch to the comparer which is using randomized string hashing
- // i.e. EqualityComparer<string>.Default.
- _comparer = null;
- Resize(entries.Length, true);
- }
-
- return true;
- }
-
- public virtual void OnDeserialization(object? sender)
- {
- HashHelpers.SerializationInfoTable.TryGetValue(this, out SerializationInfo? siInfo);
-
- if (siInfo == null)
- {
- // We can return immediately if this function is called twice.
- // Note we remove the serialization info from the table at the end of this method.
- return;
- }
-
- int realVersion = siInfo.GetInt32(VersionName);
- int hashsize = siInfo.GetInt32(HashSizeName);
- _comparer = (IEqualityComparer<TKey>)siInfo.GetValue(ComparerName, typeof(IEqualityComparer<TKey>))!; // When serialized if comparer is null, we use the default.
-
- if (hashsize != 0)
- {
- Initialize(hashsize);
-
- KeyValuePair<TKey, TValue>[]? array = (KeyValuePair<TKey, TValue>[]?)
- siInfo.GetValue(KeyValuePairsName, typeof(KeyValuePair<TKey, TValue>[]));
-
- if (array == null)
- {
- ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_MissingKeys);
- }
-
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i].Key == null)
- {
- ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_NullKey);
- }
- Add(array[i].Key, array[i].Value);
- }
- }
- else
- {
- _buckets = null;
- }
-
- _version = realVersion;
- HashHelpers.SerializationInfoTable.Remove(this);
- }
-
- private void Resize()
- => Resize(HashHelpers.ExpandPrime(_count), false);
-
- private void Resize(int newSize, bool forceNewHashCodes)
- {
- // Value types never rehash
- Debug.Assert(!forceNewHashCodes || default(TKey)! == null); // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- Debug.Assert(_entries != null, "_entries should be non-null");
- Debug.Assert(newSize >= _entries.Length);
-
- Entry[] entries = new Entry[newSize];
-
- int count = _count;
- Array.Copy(_entries, entries, count);
-
- if (default(TKey)! == null && forceNewHashCodes) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- for (int i = 0; i < count; i++)
- {
- if (entries[i].next >= -1)
- {
- Debug.Assert(_comparer == null);
- entries[i].hashCode = (uint)entries[i].key.GetHashCode();
- }
- }
- }
-
- // Assign member variables after both arrays allocated to guard against corruption from OOM if second fails
- _buckets = new int[newSize];
-#if BIT64
- _fastModMultiplier = HashHelpers.GetFastModMultiplier((uint)newSize);
-#endif
- for (int i = 0; i < count; i++)
- {
- if (entries[i].next >= -1)
- {
- ref int bucket = ref GetBucket(entries[i].hashCode);
- // Value in _buckets is 1-based
- entries[i].next = bucket - 1;
- // Value in _buckets is 1-based
- bucket = i + 1;
- }
- }
-
- _entries = entries;
- }
-
- // The overload Remove(TKey key, out TValue value) is a copy of this method with one additional
- // statement to copy the value for entry being removed into the output parameter.
- // Code has been intentionally duplicated for performance reasons.
- public bool Remove(TKey key)
- {
- if (key == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
-
- if (_buckets != null)
- {
- Debug.Assert(_entries != null, "entries should be non-null");
- uint collisionCount = 0;
- uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key.GetHashCode());
- ref int bucket = ref GetBucket(hashCode);
- Entry[]? entries = _entries;
- int last = -1;
- // Value in buckets is 1-based
- int i = bucket - 1;
- while (i >= 0)
- {
- ref Entry entry = ref entries[i];
-
- if (entry.hashCode == hashCode && (_comparer?.Equals(entry.key, key) ?? EqualityComparer<TKey>.Default.Equals(entry.key, key)))
- {
- if (last < 0)
- {
- // Value in buckets is 1-based
- bucket = entry.next + 1;
- }
- else
- {
- entries[last].next = entry.next;
- }
-
- Debug.Assert((StartOfFreeList - _freeList) < 0, "shouldn't underflow because max hashtable length is MaxPrimeArrayLength = 0x7FEFFFFD(2146435069) _freelist underflow threshold 2147483646");
-
- entry.next = StartOfFreeList - _freeList;
-
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TKey>())
- {
- entry.key = default!;
- }
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TValue>())
- {
- entry.value = default!;
- }
- _freeList = i;
- _freeCount++;
- return true;
- }
-
- last = i;
- i = entry.next;
-
- collisionCount++;
- if (collisionCount > (uint)entries.Length)
- {
- // The chain of entries forms a loop; which means a concurrent update has happened.
- // Break out of the loop and throw, rather than looping forever.
- ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported();
- }
- }
- }
- return false;
- }
-
- // This overload is a copy of the overload Remove(TKey key) with one additional
- // statement to copy the value for entry being removed into the output parameter.
- // Code has been intentionally duplicated for performance reasons.
- public bool Remove(TKey key, [MaybeNullWhen(false)] out TValue value)
- {
- if (key == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
-
- if (_buckets != null)
- {
- Debug.Assert(_entries != null, "entries should be non-null");
- uint collisionCount = 0;
- uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key.GetHashCode());
- ref int bucket = ref GetBucket(hashCode);
- Entry[]? entries = _entries;
- int last = -1;
- // Value in buckets is 1-based
- int i = bucket - 1;
- while (i >= 0)
- {
- ref Entry entry = ref entries[i];
-
- if (entry.hashCode == hashCode && (_comparer?.Equals(entry.key, key) ?? EqualityComparer<TKey>.Default.Equals(entry.key, key)))
- {
- if (last < 0)
- {
- // Value in buckets is 1-based
- bucket = entry.next + 1;
- }
- else
- {
- entries[last].next = entry.next;
- }
-
- value = entry.value;
-
- Debug.Assert((StartOfFreeList - _freeList) < 0, "shouldn't underflow because max hashtable length is MaxPrimeArrayLength = 0x7FEFFFFD(2146435069) _freelist underflow threshold 2147483646");
-
- entry.next = StartOfFreeList - _freeList;
-
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TKey>())
- {
- entry.key = default!;
- }
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TValue>())
- {
- entry.value = default!;
- }
- _freeList = i;
- _freeCount++;
- return true;
- }
-
- last = i;
- i = entry.next;
-
- collisionCount++;
- if (collisionCount > (uint)entries.Length)
- {
- // The chain of entries forms a loop; which means a concurrent update has happened.
- // Break out of the loop and throw, rather than looping forever.
- ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported();
- }
- }
- }
- value = default!;
- return false;
- }
-
- public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
- {
- ref TValue valRef = ref FindValue(key);
- if (!Unsafe.IsNullRef(ref valRef))
- {
- value = valRef;
- return true;
- }
- value = default!;
- return false;
- }
-
- public bool TryAdd(TKey key, TValue value)
- => TryInsert(key, value, InsertionBehavior.None);
-
- bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly => false;
-
- void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int index)
- => CopyTo(array, index);
-
- void ICollection.CopyTo(Array array, int index)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (array.Rank != 1)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
- if (array.GetLowerBound(0) != 0)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
- if ((uint)index > (uint)array.Length)
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- if (array.Length - index < Count)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
-
- if (array is KeyValuePair<TKey, TValue>[] pairs)
- {
- CopyTo(pairs, index);
- }
- else if (array is DictionaryEntry[] dictEntryArray)
- {
- Entry[]? entries = _entries;
- for (int i = 0; i < _count; i++)
- {
- if (entries![i].next >= -1)
- {
- dictEntryArray[index++] = new DictionaryEntry(entries[i].key, entries[i].value);
- }
- }
- }
- else
- {
- object[]? objects = array as object[];
- if (objects == null)
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
-
- try
- {
- int count = _count;
- Entry[]? entries = _entries;
- for (int i = 0; i < count; i++)
- {
- if (entries![i].next >= -1)
- {
- objects[index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value);
- }
- }
- }
- catch (ArrayTypeMismatchException)
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
- }
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- => new Enumerator(this, Enumerator.KeyValuePair);
-
- /// <summary>
- /// Ensures that the dictionary can hold up to 'capacity' entries without any further expansion of its backing storage
- /// </summary>
- public int EnsureCapacity(int capacity)
- {
- if (capacity < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
- int currentCapacity = _entries == null ? 0 : _entries.Length;
- if (currentCapacity >= capacity)
- return currentCapacity;
- _version++;
- if (_buckets == null)
- return Initialize(capacity);
-
- int newSize = HashHelpers.GetPrime(capacity);
- Resize(newSize, forceNewHashCodes: false);
- return newSize;
- }
-
- /// <summary>
- /// Sets the capacity of this dictionary to what it would be if it had been originally initialized with all its entries
- ///
- /// This method can be used to minimize the memory overhead
- /// once it is known that no new elements will be added.
- ///
- /// To allocate minimum size storage array, execute the following statements:
- ///
- /// dictionary.Clear();
- /// dictionary.TrimExcess();
- /// </summary>
- public void TrimExcess()
- => TrimExcess(Count);
-
- /// <summary>
- /// Sets the capacity of this dictionary to hold up 'capacity' entries without any further expansion of its backing storage
- ///
- /// This method can be used to minimize the memory overhead
- /// once it is known that no new elements will be added.
- /// </summary>
- public void TrimExcess(int capacity)
- {
- if (capacity < Count)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
-
- int newSize = HashHelpers.GetPrime(capacity);
- Entry[]? oldEntries = _entries;
- int currentCapacity = oldEntries == null ? 0 : oldEntries.Length;
- if (newSize >= currentCapacity)
- return;
-
- int oldCount = _count;
- _version++;
- Initialize(newSize);
- Entry[]? entries = _entries;
- int count = 0;
- for (int i = 0; i < oldCount; i++)
- {
- uint hashCode = oldEntries![i].hashCode; // At this point, we know we have entries.
- if (oldEntries[i].next >= -1)
- {
- ref Entry entry = ref entries![count];
- entry = oldEntries[i];
- ref int bucket = ref GetBucket(hashCode);
- // Value in _buckets is 1-based
- entry.next = bucket - 1;
- // Value in _buckets is 1-based
- bucket = count + 1;
- count++;
- }
- }
- _count = count;
- _freeCount = 0;
- }
-
- bool ICollection.IsSynchronized => false;
-
- object ICollection.SyncRoot => this;
-
- bool IDictionary.IsFixedSize => false;
-
- bool IDictionary.IsReadOnly => false;
-
- ICollection IDictionary.Keys => (ICollection)Keys;
-
- ICollection IDictionary.Values => (ICollection)Values;
-
- object? IDictionary.this[object key]
- {
- get
- {
- if (IsCompatibleKey(key))
- {
- ref TValue value = ref FindValue((TKey)key);
- if (!Unsafe.IsNullRef(ref value))
- {
- return value;
- }
- }
- return null;
- }
- set
- {
- if (key == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
- ThrowHelper.IfNullAndNullsAreIllegalThenThrow<TValue>(value, ExceptionArgument.value);
-
- try
- {
- TKey tempKey = (TKey)key;
- try
- {
- this[tempKey] = (TValue)value!;
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(TValue));
- }
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
- }
- }
- }
-
- private static bool IsCompatibleKey(object key)
- {
- if (key == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
- return key is TKey;
- }
-
- void IDictionary.Add(object key, object? value)
- {
- if (key == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
- ThrowHelper.IfNullAndNullsAreIllegalThenThrow<TValue>(value, ExceptionArgument.value);
-
- try
- {
- TKey tempKey = (TKey)key;
-
- try
- {
- Add(tempKey, (TValue)value!);
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(TValue));
- }
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
- }
- }
-
- bool IDictionary.Contains(object key)
- {
- if (IsCompatibleKey(key))
- {
- return ContainsKey((TKey)key);
- }
-
- return false;
- }
-
- IDictionaryEnumerator IDictionary.GetEnumerator()
- => new Enumerator(this, Enumerator.DictEntry);
-
- void IDictionary.Remove(object key)
- {
- if (IsCompatibleKey(key))
- {
- Remove((TKey)key);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private ref int GetBucket(uint hashCode)
- {
- int[] buckets = _buckets!;
-#if BIT64
- return ref buckets[HashHelpers.FastMod(hashCode, (uint)buckets.Length, _fastModMultiplier)];
-#else
- return ref buckets[hashCode % (uint)buckets.Length];
-#endif
- }
-
- public struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>,
- IDictionaryEnumerator
- {
- private readonly Dictionary<TKey, TValue> _dictionary;
- private readonly int _version;
- private int _index;
- private KeyValuePair<TKey, TValue> _current;
- private readonly int _getEnumeratorRetType; // What should Enumerator.Current return?
-
- internal const int DictEntry = 1;
- internal const int KeyValuePair = 2;
-
- internal Enumerator(Dictionary<TKey, TValue> dictionary, int getEnumeratorRetType)
- {
- _dictionary = dictionary;
- _version = dictionary._version;
- _index = 0;
- _getEnumeratorRetType = getEnumeratorRetType;
- _current = default;
- }
-
- public bool MoveNext()
- {
- if (_version != _dictionary._version)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
- }
-
- // Use unsigned comparison since we set index to dictionary.count+1 when the enumeration ends.
- // dictionary.count+1 could be negative if dictionary.count is int.MaxValue
- while ((uint)_index < (uint)_dictionary._count)
- {
- ref Entry entry = ref _dictionary._entries![_index++];
-
- if (entry.next >= -1)
- {
- _current = new KeyValuePair<TKey, TValue>(entry.key, entry.value);
- return true;
- }
- }
-
- _index = _dictionary._count + 1;
- _current = default;
- return false;
- }
-
- public KeyValuePair<TKey, TValue> Current => _current;
-
- public void Dispose()
- {
- }
-
- object? IEnumerator.Current
- {
- get
- {
- if (_index == 0 || (_index == _dictionary._count + 1))
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
- }
-
- if (_getEnumeratorRetType == DictEntry)
- {
- return new DictionaryEntry(_current.Key, _current.Value);
- }
- else
- {
- return new KeyValuePair<TKey, TValue>(_current.Key, _current.Value);
- }
- }
- }
-
- void IEnumerator.Reset()
- {
- if (_version != _dictionary._version)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
- }
-
- _index = 0;
- _current = default;
- }
-
- DictionaryEntry IDictionaryEnumerator.Entry
- {
- get
- {
- if (_index == 0 || (_index == _dictionary._count + 1))
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
- }
-
- return new DictionaryEntry(_current.Key, _current.Value);
- }
- }
-
- object IDictionaryEnumerator.Key
- {
- get
- {
- if (_index == 0 || (_index == _dictionary._count + 1))
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
- }
-
- return _current.Key;
- }
- }
-
- object? IDictionaryEnumerator.Value
- {
- get
- {
- if (_index == 0 || (_index == _dictionary._count + 1))
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
- }
-
- return _current.Value;
- }
- }
- }
-
- [DebuggerTypeProxy(typeof(DictionaryKeyCollectionDebugView<,>))]
- [DebuggerDisplay("Count = {Count}")]
- public sealed class KeyCollection : ICollection<TKey>, ICollection, IReadOnlyCollection<TKey>
- {
- private readonly Dictionary<TKey, TValue> _dictionary;
-
- public KeyCollection(Dictionary<TKey, TValue> dictionary)
- {
- if (dictionary == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
- }
- _dictionary = dictionary;
- }
-
- public Enumerator GetEnumerator()
- => new Enumerator(_dictionary);
-
- public void CopyTo(TKey[] array, int index)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (index < 0 || index > array.Length)
- {
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- }
-
- if (array.Length - index < _dictionary.Count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
- }
-
- int count = _dictionary._count;
- Entry[]? entries = _dictionary._entries;
- for (int i = 0; i < count; i++)
- {
- if (entries![i].next >= -1) array[index++] = entries[i].key;
- }
- }
-
- public int Count => _dictionary.Count;
-
- bool ICollection<TKey>.IsReadOnly => true;
-
- void ICollection<TKey>.Add(TKey item)
- => ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_KeyCollectionSet);
-
- void ICollection<TKey>.Clear()
- => ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_KeyCollectionSet);
-
- bool ICollection<TKey>.Contains(TKey item)
- => _dictionary.ContainsKey(item);
-
- bool ICollection<TKey>.Remove(TKey item)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_KeyCollectionSet);
- return false;
- }
-
- IEnumerator<TKey> IEnumerable<TKey>.GetEnumerator()
- => new Enumerator(_dictionary);
-
- IEnumerator IEnumerable.GetEnumerator()
- => new Enumerator(_dictionary);
-
- void ICollection.CopyTo(Array array, int index)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (array.Rank != 1)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
- if (array.GetLowerBound(0) != 0)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
- if ((uint)index > (uint)array.Length)
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- if (array.Length - index < _dictionary.Count)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
-
- if (array is TKey[] keys)
- {
- CopyTo(keys, index);
- }
- else
- {
- object[]? objects = array as object[];
- if (objects == null)
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
-
- int count = _dictionary._count;
- Entry[]? entries = _dictionary._entries;
- try
- {
- for (int i = 0; i < count; i++)
- {
- if (entries![i].next >= -1) objects[index++] = entries[i].key;
- }
- }
- catch (ArrayTypeMismatchException)
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
- }
- }
-
- bool ICollection.IsSynchronized => false;
-
- object ICollection.SyncRoot => ((ICollection)_dictionary).SyncRoot;
-
- public struct Enumerator : IEnumerator<TKey>, IEnumerator
- {
- private readonly Dictionary<TKey, TValue> _dictionary;
- private int _index;
- private readonly int _version;
- [AllowNull, MaybeNull] private TKey _currentKey;
-
- internal Enumerator(Dictionary<TKey, TValue> dictionary)
- {
- _dictionary = dictionary;
- _version = dictionary._version;
- _index = 0;
- _currentKey = default;
- }
-
- public void Dispose()
- {
- }
-
- public bool MoveNext()
- {
- if (_version != _dictionary._version)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
- }
-
- while ((uint)_index < (uint)_dictionary._count)
- {
- ref Entry entry = ref _dictionary._entries![_index++];
-
- if (entry.next >= -1)
- {
- _currentKey = entry.key;
- return true;
- }
- }
-
- _index = _dictionary._count + 1;
- _currentKey = default;
- return false;
- }
-
- public TKey Current => _currentKey!;
-
- object? IEnumerator.Current
- {
- get
- {
- if (_index == 0 || (_index == _dictionary._count + 1))
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
- }
-
- return _currentKey;
- }
- }
-
- void IEnumerator.Reset()
- {
- if (_version != _dictionary._version)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
- }
-
- _index = 0;
- _currentKey = default;
- }
- }
- }
-
- [DebuggerTypeProxy(typeof(DictionaryValueCollectionDebugView<,>))]
- [DebuggerDisplay("Count = {Count}")]
- public sealed class ValueCollection : ICollection<TValue>, ICollection, IReadOnlyCollection<TValue>
- {
- private readonly Dictionary<TKey, TValue> _dictionary;
-
- public ValueCollection(Dictionary<TKey, TValue> dictionary)
- {
- if (dictionary == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
- }
- _dictionary = dictionary;
- }
-
- public Enumerator GetEnumerator()
- => new Enumerator(_dictionary);
-
- public void CopyTo(TValue[] array, int index)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if ((uint)index > array.Length)
- {
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- }
-
- if (array.Length - index < _dictionary.Count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
- }
-
- int count = _dictionary._count;
- Entry[]? entries = _dictionary._entries;
- for (int i = 0; i < count; i++)
- {
- if (entries![i].next >= -1) array[index++] = entries[i].value;
- }
- }
-
- public int Count => _dictionary.Count;
-
- bool ICollection<TValue>.IsReadOnly => true;
-
- void ICollection<TValue>.Add(TValue item)
- => ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ValueCollectionSet);
-
- bool ICollection<TValue>.Remove(TValue item)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ValueCollectionSet);
- return false;
- }
-
- void ICollection<TValue>.Clear()
- => ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ValueCollectionSet);
-
- bool ICollection<TValue>.Contains(TValue item)
- => _dictionary.ContainsValue(item);
-
- IEnumerator<TValue> IEnumerable<TValue>.GetEnumerator()
- => new Enumerator(_dictionary);
-
- IEnumerator IEnumerable.GetEnumerator()
- => new Enumerator(_dictionary);
-
- void ICollection.CopyTo(Array array, int index)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (array.Rank != 1)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
- if (array.GetLowerBound(0) != 0)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
- if ((uint)index > (uint)array.Length)
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- if (array.Length - index < _dictionary.Count)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
-
- if (array is TValue[] values)
- {
- CopyTo(values, index);
- }
- else
- {
- object[]? objects = array as object[];
- if (objects == null)
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
-
- int count = _dictionary._count;
- Entry[]? entries = _dictionary._entries;
- try
- {
- for (int i = 0; i < count; i++)
- {
- if (entries![i].next >= -1) objects[index++] = entries[i].value!;
- }
- }
- catch (ArrayTypeMismatchException)
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
- }
- }
-
- bool ICollection.IsSynchronized => false;
-
- object ICollection.SyncRoot => ((ICollection)_dictionary).SyncRoot;
-
- public struct Enumerator : IEnumerator<TValue>, IEnumerator
- {
- private readonly Dictionary<TKey, TValue> _dictionary;
- private int _index;
- private readonly int _version;
- [AllowNull, MaybeNull] private TValue _currentValue;
-
- internal Enumerator(Dictionary<TKey, TValue> dictionary)
- {
- _dictionary = dictionary;
- _version = dictionary._version;
- _index = 0;
- _currentValue = default;
- }
-
- public void Dispose()
- {
- }
-
- public bool MoveNext()
- {
- if (_version != _dictionary._version)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
- }
-
- while ((uint)_index < (uint)_dictionary._count)
- {
- ref Entry entry = ref _dictionary._entries![_index++];
-
- if (entry.next >= -1)
- {
- _currentValue = entry.value;
- return true;
- }
- }
- _index = _dictionary._count + 1;
- _currentValue = default;
- return false;
- }
-
- public TValue Current => _currentValue!;
-
- object? IEnumerator.Current
- {
- get
- {
- if (_index == 0 || (_index == _dictionary._count + 1))
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
- }
-
- return _currentValue;
- }
- }
-
- void IEnumerator.Reset()
- {
- if (_version != _dictionary._version)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
- }
- _index = 0;
- _currentValue = default;
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/EqualityComparer.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/EqualityComparer.cs
deleted file mode 100644
index 670715fc5a5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/EqualityComparer.cs
+++ /dev/null
@@ -1,191 +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 System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-
-namespace System.Collections.Generic
-{
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public abstract partial class EqualityComparer<T> : IEqualityComparer, IEqualityComparer<T>
- {
- // public static EqualityComparer<T> Default is runtime-specific
-
- public abstract bool Equals([AllowNull] T x, [AllowNull] T y);
- public abstract int GetHashCode([DisallowNull] T obj);
-
- int IEqualityComparer.GetHashCode(object? obj)
- {
- if (obj == null) return 0;
- if (obj is T) return GetHashCode((T)obj);
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArgumentForComparison);
- return 0;
- }
-
- bool IEqualityComparer.Equals(object? x, object? y)
- {
- if (x == y) return true;
- if (x == null || y == null) return false;
- if ((x is T) && (y is T)) return Equals((T)x, (T)y);
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArgumentForComparison);
- return false;
- }
- }
-
- // The methods in this class look identical to the inherited methods, but the calls
- // to Equal bind to IEquatable<T>.Equals(T) instead of Object.Equals(Object)
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- // Needs to be public to support binary serialization compatibility
- public sealed partial class GenericEqualityComparer<T> : EqualityComparer<T>
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override bool Equals([AllowNull] T x, [AllowNull] T y)
- {
- if (x != null)
- {
- if (y != null) return x.Equals(y);
- return false;
- }
- if (y != null) return false;
- return true;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetHashCode([DisallowNull] T obj) => obj?.GetHashCode() ?? 0;
-
- // Equals method for the comparer itself.
- // If in the future this type is made sealed, change the is check to obj != null && GetType() == obj.GetType().
- public override bool Equals(object? obj) =>
- obj is GenericEqualityComparer<T>;
-
- // If in the future this type is made sealed, change typeof(...) to GetType().
- public override int GetHashCode() =>
- typeof(GenericEqualityComparer<T>).GetHashCode();
- }
-
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- // Needs to be public to support binary serialization compatibility
- public sealed partial class NullableEqualityComparer<T> : EqualityComparer<T?> where T : struct,
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- IEquatable<T>
-#nullable restore
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override bool Equals(T? x, T? y)
- {
- if (x.HasValue)
- {
- if (y.HasValue) return x.value.Equals(y.value);
- return false;
- }
- if (y.HasValue) return false;
- return true;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetHashCode(T? obj) => obj.GetHashCode();
-
- // Equals method for the comparer itself.
- public override bool Equals(object? obj) =>
- obj != null && GetType() == obj.GetType();
-
- public override int GetHashCode() =>
- GetType().GetHashCode();
- }
-
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- // Needs to be public to support binary serialization compatibility
- public sealed partial class ObjectEqualityComparer<T> : EqualityComparer<T>
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override bool Equals([AllowNull] T x, [AllowNull] T y)
- {
- if (x != null)
- {
- if (y != null) return x.Equals(y);
- return false;
- }
- if (y != null) return false;
- return true;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetHashCode([DisallowNull] T obj) => obj?.GetHashCode() ?? 0;
-
- // Equals method for the comparer itself.
- public override bool Equals(object? obj) =>
- obj != null && GetType() == obj.GetType();
-
- public override int GetHashCode() =>
- GetType().GetHashCode();
- }
-
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- // Needs to be public to support binary serialization compatibility
- public sealed partial class ByteEqualityComparer : EqualityComparer<byte>
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override bool Equals(byte x, byte y)
- {
- return x == y;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetHashCode(byte b)
- {
- return b.GetHashCode();
- }
-
- // Equals method for the comparer itself.
- public override bool Equals(object? obj) =>
- obj != null && GetType() == obj.GetType();
-
- public override int GetHashCode() =>
- GetType().GetHashCode();
- }
-
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- // Needs to be public to support binary serialization compatibility
- public sealed partial class EnumEqualityComparer<T> : EqualityComparer<T>, ISerializable where T : struct, Enum
- {
- internal EnumEqualityComparer() { }
-
- // This is used by the serialization engine.
- private EnumEqualityComparer(SerializationInfo information, StreamingContext context) { }
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- // For back-compat we need to serialize the comparers for enums with underlying types other than int as ObjectEqualityComparer
- if (Type.GetTypeCode(Enum.GetUnderlyingType(typeof(T))) != TypeCode.Int32)
- {
- info.SetType(typeof(ObjectEqualityComparer<T>));
- }
- }
-
- // public override bool Equals(T x, T y) is runtime-specific
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetHashCode(T obj)
- {
- return obj.GetHashCode();
- }
-
- // Equals method for the comparer itself.
- public override bool Equals(object? obj) =>
- obj != null && GetType() == obj.GetType();
-
- public override int GetHashCode() =>
- GetType().GetHashCode();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IAsyncEnumerable.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IAsyncEnumerable.cs
deleted file mode 100644
index 302b9648550..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IAsyncEnumerable.cs
+++ /dev/null
@@ -1,18 +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 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);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IAsyncEnumerator.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IAsyncEnumerator.cs
deleted file mode 100644
index 0d9afc1914f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IAsyncEnumerator.cs
+++ /dev/null
@@ -1,24 +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 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; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ICollection.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ICollection.cs
deleted file mode 100644
index 22614688452..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ICollection.cs
+++ /dev/null
@@ -1,28 +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.
-
-namespace System.Collections.Generic
-{
- // Base interface for all collections, defining enumerators, size, and
- // synchronization methods.
- public interface ICollection<T> : IEnumerable<T>
- {
- // Number of items in the collections.
- int Count { get; }
-
- bool IsReadOnly { get; }
-
- void Add(T item);
-
- void Clear();
-
- bool Contains(T item);
-
- // CopyTo copies a collection into an Array, starting at a particular
- // index into the array.
- void CopyTo(T[] array, int arrayIndex);
-
- bool Remove(T item);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ICollectionDebugView.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ICollectionDebugView.cs
deleted file mode 100644
index 9916e857e2c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ICollectionDebugView.cs
+++ /dev/null
@@ -1,34 +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 System.Diagnostics;
-
-namespace System.Collections.Generic
-{
- internal sealed class ICollectionDebugView<T>
- {
- private readonly ICollection<T> _collection;
-
- public ICollectionDebugView(ICollection<T> collection)
- {
- if (collection == null)
- {
- throw new ArgumentNullException(nameof(collection));
- }
-
- _collection = collection;
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public T[] Items
- {
- get
- {
- T[] items = new T[_collection.Count];
- _collection.CopyTo(items, 0);
- return items;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IComparer.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IComparer.cs
deleted file mode 100644
index d4fae2ecff9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IComparer.cs
+++ /dev/null
@@ -1,20 +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 System.Diagnostics.CodeAnalysis;
-
-namespace System.Collections.Generic
-{
- // The generic IComparer interface implements a method that compares
- // two objects. It is used in conjunction with the Sort and
- // BinarySearch methods on the Array, List, and SortedList classes.
- public interface IComparer<in T>
- {
- // Compares two objects. An implementation of this method must return a
- // value less than zero if x is less than y, zero if x is equal to y, or a
- // value greater than zero if x is greater than y.
- //
- int Compare([AllowNull] T x, [AllowNull] T y);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IDictionary.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IDictionary.cs
deleted file mode 100644
index a79782c9d20..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IDictionary.cs
+++ /dev/null
@@ -1,50 +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 System.Diagnostics.CodeAnalysis;
-
-namespace System.Collections.Generic
-{
- // An IDictionary is a possibly unordered set of key-value pairs.
- // Keys can be any non-null object. Values can be any object.
- // You can look up a value in an IDictionary via the default indexed
- // property, Items.
- public interface IDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>> where TKey : notnull
- {
- // Interfaces are not serializable
- // The Item property provides methods to read and edit entries
- // in the Dictionary.
- TValue this[TKey key]
- {
- get;
- set;
- }
-
- // Returns a collections of the keys in this dictionary.
- ICollection<TKey> Keys
- {
- get;
- }
-
- // Returns a collections of the values in this dictionary.
- ICollection<TValue> Values
- {
- get;
- }
-
- // Returns whether this dictionary contains a particular key.
- //
- bool ContainsKey(TKey key);
-
- // Adds a key-value pair to the dictionary.
- //
- void Add(TKey key, TValue value);
-
- // Removes a particular key from the dictionary.
- //
- bool Remove(TKey key);
-
- bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IDictionaryDebugView.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IDictionaryDebugView.cs
deleted file mode 100644
index 3168aa1bb18..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IDictionaryDebugView.cs
+++ /dev/null
@@ -1,80 +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 System.Diagnostics;
-
-namespace System.Collections.Generic
-{
- internal sealed class IDictionaryDebugView<K, V> where K : notnull
- {
- private readonly IDictionary<K, V> _dict;
-
- public IDictionaryDebugView(IDictionary<K, V> dictionary)
- {
- if (dictionary == null)
- throw new ArgumentNullException(nameof(dictionary));
-
- _dict = dictionary;
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public KeyValuePair<K, V>[] Items
- {
- get
- {
- KeyValuePair<K, V>[] items = new KeyValuePair<K, V>[_dict.Count];
- _dict.CopyTo(items, 0);
- return items;
- }
- }
- }
-
- internal sealed class DictionaryKeyCollectionDebugView<TKey, TValue>
- {
- private readonly ICollection<TKey> _collection;
-
- public DictionaryKeyCollectionDebugView(ICollection<TKey> collection)
- {
- if (collection == null)
- throw new ArgumentNullException(nameof(collection));
-
- _collection = collection;
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public TKey[] Items
- {
- get
- {
- TKey[] items = new TKey[_collection.Count];
- _collection.CopyTo(items, 0);
- return items;
- }
- }
- }
-
- internal sealed class DictionaryValueCollectionDebugView<TKey, TValue>
- {
- private readonly ICollection<TValue> _collection;
-
- public DictionaryValueCollectionDebugView(ICollection<TValue> collection)
- {
- if (collection == null)
- throw new ArgumentNullException(nameof(collection));
-
- _collection = collection;
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public TValue[] Items
- {
- get
- {
- TValue[] items = new TValue[_collection.Count];
- _collection.CopyTo(items, 0);
- return items;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEnumerable.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEnumerable.cs
deleted file mode 100644
index 5548ffc19db..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEnumerable.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Collections.Generic
-{
- // Implement this interface if you need to support foreach semantics.
- public interface IEnumerable<out T> : IEnumerable
- {
- // Returns an IEnumerator for this enumerable Object. The enumerator provides
- // a simple way to access all the contents of a collection.
- new IEnumerator<T> GetEnumerator();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEnumerator.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEnumerator.cs
deleted file mode 100644
index 284bbe540ab..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEnumerator.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Collections.Generic
-{
- // Base interface for all generic enumerators, providing a simple approach
- // to iterating over a collection.
- public interface IEnumerator<out T> : IDisposable, IEnumerator
- {
- // Returns the current element of the enumeration. The returned value is
- // undefined before the first call to MoveNext and following a
- // call to MoveNext that returned false. Multiple calls to
- // GetCurrent with no intervening calls to MoveNext
- // will return the same object.
- new T Current
- {
- get;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEqualityComparer.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEqualityComparer.cs
deleted file mode 100644
index 61a6bd1e742..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IEqualityComparer.cs
+++ /dev/null
@@ -1,17 +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 System.Diagnostics.CodeAnalysis;
-
-namespace System.Collections.Generic
-{
- // The generic IEqualityComparer interface implements methods to if check two objects are equal
- // and generate Hashcode for an object.
- // It is use in Dictionary class.
- public interface IEqualityComparer<in T>
- {
- bool Equals([AllowNull] T x, [AllowNull] T y);
- int GetHashCode([DisallowNull] T obj);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IList.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IList.cs
deleted file mode 100644
index 581b1d3bd40..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IList.cs
+++ /dev/null
@@ -1,32 +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.
-
-namespace System.Collections.Generic
-{
- // An IList is an ordered collection of objects. The exact ordering
- // is up to the implementation of the list, ranging from a sorted
- // order to insertion order.
- public interface IList<T> : ICollection<T>
- {
- // The Item property provides methods to read and edit entries in the List.
- T this[int index]
- {
- get;
- set;
- }
-
- // Returns the index of a particular item, if it is in the list.
- // Returns -1 if the item isn't in the list.
- int IndexOf(T item);
-
- // Inserts value into the list at position index.
- // index must be non-negative and less than or equal to the
- // number of elements in the list. If index equals the number
- // of items in the list, then value is appended to the end.
- void Insert(int index, T item);
-
- // Removes the item at position index.
- void RemoveAt(int index);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyCollection.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyCollection.cs
deleted file mode 100644
index b9a80ffa8b5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyCollection.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Collections.Generic
-{
- // Provides a read-only, covariant view of a generic list.
- public interface IReadOnlyCollection<out T> : IEnumerable<T>
- {
- int Count { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyDictionary.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyDictionary.cs
deleted file mode 100644
index af7ff0871dc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyDictionary.cs
+++ /dev/null
@@ -1,19 +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 System.Diagnostics.CodeAnalysis;
-
-namespace System.Collections.Generic
-{
- // Provides a read-only view of a generic dictionary.
- public interface IReadOnlyDictionary<TKey, TValue> : IReadOnlyCollection<KeyValuePair<TKey, TValue>> where TKey : notnull
- {
- bool ContainsKey(TKey key);
- bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value);
-
- TValue this[TKey key] { get; }
- IEnumerable<TKey> Keys { get; }
- IEnumerable<TValue> Values { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyList.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyList.cs
deleted file mode 100644
index ea54506fa82..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/IReadOnlyList.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Collections.Generic
-{
- // Provides a read-only, covariant view of a generic list.
- public interface IReadOnlyList<out T> : IReadOnlyCollection<T>
- {
- T this[int index] { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/KeyNotFoundException.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/KeyNotFoundException.cs
deleted file mode 100644
index 35a81591b06..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/KeyNotFoundException.cs
+++ /dev/null
@@ -1,35 +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 System.Runtime.Serialization;
-
-namespace System.Collections.Generic
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class KeyNotFoundException : SystemException
- {
- public KeyNotFoundException()
- : base(SR.Arg_KeyNotFound)
- {
- HResult = HResults.COR_E_KEYNOTFOUND;
- }
-
- public KeyNotFoundException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_KEYNOTFOUND;
- }
-
- public KeyNotFoundException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_KEYNOTFOUND;
- }
-
- protected KeyNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/KeyValuePair.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/KeyValuePair.cs
deleted file mode 100644
index 9e1526f05d6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/KeyValuePair.cs
+++ /dev/null
@@ -1,78 +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 System.ComponentModel;
-using System.Text;
-
-namespace System.Collections.Generic
-{
- // Provides the Create factory method for KeyValuePair<TKey, TValue>.
- public static class KeyValuePair
- {
- // Creates a new KeyValuePair<TKey, TValue> from the given values.
- public static KeyValuePair<TKey, TValue> Create<TKey, TValue>(TKey key, TValue value)
- {
- return new KeyValuePair<TKey, TValue>(key, value);
- }
-
- /// <summary>
- /// Used by KeyValuePair.ToString to reduce generic code
- /// </summary>
- internal static string PairToString(object? key, object? value)
- {
- var s = new ValueStringBuilder(stackalloc char[64]);
-
- s.Append('[');
-
- if (key != null)
- {
- s.Append(key.ToString());
- }
-
- s.Append(", ");
-
- if (value != null)
- {
- s.Append(value.ToString());
- }
-
- s.Append(']');
-
- return s.ToString();
- }
- }
-
- // A KeyValuePair holds a key and a value from a dictionary.
- // It is used by the IEnumerable<T> implementation for both IDictionary<TKey, TValue>
- // and IReadOnlyDictionary<TKey, TValue>.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct KeyValuePair<TKey, TValue>
- {
- private readonly TKey key; // Do not rename (binary serialization)
- private readonly TValue value; // Do not rename (binary serialization)
-
- public KeyValuePair(TKey key, TValue value)
- {
- this.key = key;
- this.value = value;
- }
-
- public TKey Key => key;
-
- public TValue Value => value;
-
- public override string ToString()
- {
- return KeyValuePair.PairToString(Key, Value);
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void Deconstruct(out TKey key, out TValue value)
- {
- key = Key;
- value = Value;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/List.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/List.cs
deleted file mode 100644
index ac626c57d8f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/List.cs
+++ /dev/null
@@ -1,1147 +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 System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-
-namespace System.Collections.Generic
-{
- // Implements a variable-size List that uses an array of objects to store the
- // elements. A List has a capacity, which is the allocated length
- // of the internal array. As elements are added to a List, the capacity
- // of the List is automatically increased as required by reallocating the
- // internal array.
- //
- [DebuggerTypeProxy(typeof(ICollectionDebugView<>))]
- [DebuggerDisplay("Count = {Count}")]
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class List<T> : IList<T>, IList, IReadOnlyList<T>
- {
- private const int DefaultCapacity = 4;
-
- internal T[] _items; // Do not rename (binary serialization)
- internal int _size; // Do not rename (binary serialization)
- private int _version; // Do not rename (binary serialization)
-
-#pragma warning disable CA1825 // avoid the extra generic instantiation for Array.Empty<T>()
- private static readonly T[] s_emptyArray = new T[0];
-#pragma warning restore CA1825
-
- // Constructs a List. The list is initially empty and has a capacity
- // of zero. Upon adding the first element to the list the capacity is
- // increased to DefaultCapacity, and then increased in multiples of two
- // as required.
- public List()
- {
- _items = s_emptyArray;
- }
-
- // Constructs a List with a given initial capacity. The list is
- // initially empty, but will have room for the given number of elements
- // before any reallocations are required.
- //
- public List(int capacity)
- {
- if (capacity < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
-
- if (capacity == 0)
- _items = s_emptyArray;
- else
- _items = new T[capacity];
- }
-
- // Constructs a List, copying the contents of the given collection. The
- // size and capacity of the new list will both be equal to the size of the
- // given collection.
- //
- public List(IEnumerable<T> collection)
- {
- if (collection == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
-
- if (collection is ICollection<T> c)
- {
- int count = c.Count;
- if (count == 0)
- {
- _items = s_emptyArray;
- }
- else
- {
- _items = new T[count];
- c.CopyTo(_items, 0);
- _size = count;
- }
- }
- else
- {
- _size = 0;
- _items = s_emptyArray;
- using (IEnumerator<T> en = collection!.GetEnumerator())
- {
- while (en.MoveNext())
- {
- Add(en.Current);
- }
- }
- }
- }
-
- // Gets and sets the capacity of this list. The capacity is the size of
- // the internal array used to hold items. When set, the internal
- // array of the list is reallocated to the given capacity.
- //
- public int Capacity
- {
- get => _items.Length;
- set
- {
- if (value < _size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value, ExceptionResource.ArgumentOutOfRange_SmallCapacity);
- }
-
- if (value != _items.Length)
- {
- if (value > 0)
- {
- T[] newItems = new T[value];
- if (_size > 0)
- {
- Array.Copy(_items, newItems, _size);
- }
- _items = newItems;
- }
- else
- {
- _items = s_emptyArray;
- }
- }
- }
- }
-
- // Read-only property describing how many elements are in the List.
- public int Count => _size;
-
- bool IList.IsFixedSize => false;
-
- // Is this List read-only?
- bool ICollection<T>.IsReadOnly => false;
-
- bool IList.IsReadOnly => false;
-
- // Is this List synchronized (thread-safe)?
- bool ICollection.IsSynchronized => false;
-
- // Synchronization root for this object.
- object ICollection.SyncRoot => this;
-
- // Sets or Gets the element at the given index.
- public T this[int index]
- {
- get
- {
- // Following trick can reduce the range check by one
- if ((uint)index >= (uint)_size)
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
- return _items[index];
- }
-
- set
- {
- if ((uint)index >= (uint)_size)
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
- _items[index] = value;
- _version++;
- }
- }
-
- private static bool IsCompatibleObject(object? value)
- {
- // Non-null values are fine. Only accept nulls if T is a class or Nullable<U>.
- // Note that default(T) is not equal to null for value types except when T is Nullable<U>.
- return (value is T) || (value == null && default(T)! == null); // default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- }
-
- object? IList.this[int index]
- {
- get => this[index];
- set
- {
- ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
-
- try
- {
- this[index] = (T)value!;
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
- }
- }
- }
-
- // Adds the given object to the end of this list. The size of the list is
- // increased by one. If required, the capacity of the list is doubled
- // before adding the new element.
- //
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Add(T item)
- {
- _version++;
- T[] array = _items;
- int size = _size;
- if ((uint)size < (uint)array.Length)
- {
- _size = size + 1;
- array[size] = item;
- }
- else
- {
- AddWithResize(item);
- }
- }
-
- // Non-inline from List.Add to improve its code quality as uncommon path
- [MethodImpl(MethodImplOptions.NoInlining)]
- private void AddWithResize(T item)
- {
- int size = _size;
- EnsureCapacity(size + 1);
- _size = size + 1;
- _items[size] = item;
- }
-
- int IList.Add(object? item)
- {
- ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(item, ExceptionArgument.item);
-
- try
- {
- Add((T)item!);
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
- }
-
- return Count - 1;
- }
-
- // Adds the elements of the given collection to the end of this list. If
- // required, the capacity of the list is increased to twice the previous
- // capacity or the new size, whichever is larger.
- //
- public void AddRange(IEnumerable<T> collection)
- => InsertRange(_size, collection);
-
- public ReadOnlyCollection<T> AsReadOnly()
- => new ReadOnlyCollection<T>(this);
-
- // Searches a section of the list for a given element using a binary search
- // algorithm. Elements of the list are compared to the search value using
- // the given IComparer interface. If comparer is null, elements of
- // the list are compared to the search value using the IComparable
- // interface, which in that case must be implemented by all elements of the
- // list and the given search value. This method assumes that the given
- // section of the list is already sorted; if this is not the case, the
- // result will be incorrect.
- //
- // The method returns the index of the given value in the list. If the
- // list does not contain the given value, the method returns a negative
- // integer. The bitwise complement operator (~) can be applied to a
- // negative result to produce the index of the first element (if any) that
- // is larger than the given search value. This is also the index at which
- // the search value should be inserted into the list in order for the list
- // to remain sorted.
- //
- // The method uses the Array.BinarySearch method to perform the
- // search.
- //
- public int BinarySearch(int index, int count, T item, IComparer<T>? comparer)
- {
- if (index < 0)
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- if (count < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- if (_size - index < count)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
-
- return Array.BinarySearch<T>(_items, index, count, item, comparer);
- }
-
- public int BinarySearch(T item)
- => BinarySearch(0, Count, item, null);
-
- public int BinarySearch(T item, IComparer<T>? comparer)
- => BinarySearch(0, Count, item, comparer);
-
- // Clears the contents of List.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Clear()
- {
- _version++;
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- int size = _size;
- _size = 0;
- if (size > 0)
- {
- Array.Clear(_items, 0, size); // Clear the elements so that the gc can reclaim the references.
- }
- }
- else
- {
- _size = 0;
- }
- }
-
- // Contains returns true if the specified element is in the List.
- // It does a linear, O(n) search. Equality is determined by calling
- // EqualityComparer<T>.Default.Equals().
- //
- public bool Contains(T item)
- {
- // PERF: IndexOf calls Array.IndexOf, which internally
- // calls EqualityComparer<T>.Default.IndexOf, which
- // is specialized for different types. This
- // boosts performance since instead of making a
- // virtual method call each iteration of the loop,
- // via EqualityComparer<T>.Default.Equals, we
- // only make one virtual call to EqualityComparer.IndexOf.
-
- return _size != 0 && IndexOf(item) != -1;
- }
-
- bool IList.Contains(object? item)
- {
- if (IsCompatibleObject(item))
- {
- return Contains((T)item!);
- }
- return false;
- }
-
- public List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter)
- {
- if (converter == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.converter);
- }
-
- List<TOutput> list = new List<TOutput>(_size);
- for (int i = 0; i < _size; i++)
- {
- list._items[i] = converter(_items[i]);
- }
- list._size = _size;
- return list;
- }
-
- // Copies this List into array, which must be of a
- // compatible array type.
- public void CopyTo(T[] array)
- => CopyTo(array, 0);
-
- // Copies this List into array, which must be of a
- // compatible array type.
- void ICollection.CopyTo(Array array, int arrayIndex)
- {
- if ((array != null) && (array.Rank != 1))
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
- }
-
- try
- {
- // Array.Copy will check for NULL.
- Array.Copy(_items, 0, array!, arrayIndex, _size);
- }
- catch (ArrayTypeMismatchException)
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
- }
-
- // Copies a section of this list to the given array at the given index.
- //
- // The method uses the Array.Copy method to copy the elements.
- //
- public void CopyTo(int index, T[] array, int arrayIndex, int count)
- {
- if (_size - index < count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
- }
-
- // Delegate rest of error checking to Array.Copy.
- Array.Copy(_items, index, array, arrayIndex, count);
- }
-
- public void CopyTo(T[] array, int arrayIndex)
- {
- // Delegate rest of error checking to Array.Copy.
- Array.Copy(_items, 0, array, arrayIndex, _size);
- }
-
- // Ensures that the capacity of this list is at least the given minimum
- // value. If the current capacity of the list is less than min, the
- // capacity is increased to twice the current capacity or to min,
- // whichever is larger.
- //
- private void EnsureCapacity(int min)
- {
- if (_items.Length < min)
- {
- int newCapacity = _items.Length == 0 ? DefaultCapacity : _items.Length * 2;
- // Allow the list to grow to maximum possible capacity (~2G elements) before encountering overflow.
- // Note that this check works even when _items.Length overflowed thanks to the (uint) cast
- if ((uint)newCapacity > Array.MaxArrayLength) newCapacity = Array.MaxArrayLength;
- if (newCapacity < min) newCapacity = min;
- Capacity = newCapacity;
- }
- }
-
- public bool Exists(Predicate<T> match)
- => FindIndex(match) != -1;
-
- [return: MaybeNull]
- public T Find(Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- for (int i = 0; i < _size; i++)
- {
- if (match(_items[i]))
- {
- return _items[i];
- }
- }
- return default!;
- }
-
- public List<T> FindAll(Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- List<T> list = new List<T>();
- for (int i = 0; i < _size; i++)
- {
- if (match(_items[i]))
- {
- list.Add(_items[i]);
- }
- }
- return list;
- }
-
- public int FindIndex(Predicate<T> match)
- => FindIndex(0, _size, match);
-
- public int FindIndex(int startIndex, Predicate<T> match)
- => FindIndex(startIndex, _size - startIndex, match);
-
- public int FindIndex(int startIndex, int count, Predicate<T> match)
- {
- if ((uint)startIndex > (uint)_size)
- {
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- }
-
- if (count < 0 || startIndex > _size - count)
- {
- ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
- }
-
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- int endIndex = startIndex + count;
- for (int i = startIndex; i < endIndex; i++)
- {
- if (match(_items[i])) return i;
- }
- return -1;
- }
-
- [return: MaybeNull]
- public T FindLast(Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- for (int i = _size - 1; i >= 0; i--)
- {
- if (match(_items[i]))
- {
- return _items[i];
- }
- }
- return default!;
- }
-
- public int FindLastIndex(Predicate<T> match)
- => FindLastIndex(_size - 1, _size, match);
-
- public int FindLastIndex(int startIndex, Predicate<T> match)
- => FindLastIndex(startIndex, startIndex + 1, match);
-
- public int FindLastIndex(int startIndex, int count, Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- if (_size == 0)
- {
- // Special case for 0 length List
- if (startIndex != -1)
- {
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- }
- }
- else
- {
- // Make sure we're not out of range
- if ((uint)startIndex >= (uint)_size)
- {
- ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
- }
- }
-
- // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
- if (count < 0 || startIndex - count + 1 < 0)
- {
- ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
- }
-
- int endIndex = startIndex - count;
- for (int i = startIndex; i > endIndex; i--)
- {
- if (match(_items[i]))
- {
- return i;
- }
- }
- return -1;
- }
-
- public void ForEach(Action<T> action)
- {
- if (action == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.action);
- }
-
- int version = _version;
-
- for (int i = 0; i < _size; i++)
- {
- if (version != _version)
- {
- break;
- }
- action(_items[i]);
- }
-
- if (version != _version)
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
- }
-
- // Returns an enumerator for this list with the given
- // permission for removal of elements. If modifications made to the list
- // while an enumeration is in progress, the MoveNext and
- // GetObject methods of the enumerator will throw an exception.
- //
- public Enumerator GetEnumerator()
- => new Enumerator(this);
-
- IEnumerator<T> IEnumerable<T>.GetEnumerator()
- => new Enumerator(this);
-
- IEnumerator IEnumerable.GetEnumerator()
- => new Enumerator(this);
-
- public List<T> GetRange(int index, int count)
- {
- if (index < 0)
- {
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- }
-
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (_size - index < count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
- }
-
- List<T> list = new List<T>(count);
- Array.Copy(_items, index, list._items, 0, count);
- list._size = count;
- return list;
- }
-
- // Returns the index of the first occurrence of a given value in a range of
- // this list. The list is searched forwards from beginning to end.
- // The elements of the list are compared to the given value using the
- // Object.Equals method.
- //
- // This method uses the Array.IndexOf method to perform the
- // search.
- //
- public int IndexOf(T item)
- => Array.IndexOf(_items, item, 0, _size);
-
- int IList.IndexOf(object? item)
- {
- if (IsCompatibleObject(item))
- {
- return IndexOf((T)item!);
- }
- return -1;
- }
-
- // Returns the index of the first occurrence of a given value in a range of
- // this list. The list is searched forwards, starting at index
- // index and ending at count number of elements. The
- // elements of the list are compared to the given value using the
- // Object.Equals method.
- //
- // This method uses the Array.IndexOf method to perform the
- // search.
- //
- public int IndexOf(T item, int index)
- {
- if (index > _size)
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- return Array.IndexOf(_items, item, index, _size - index);
- }
-
- // Returns the index of the first occurrence of a given value in a range of
- // this list. The list is searched forwards, starting at index
- // index and upto count number of elements. The
- // elements of the list are compared to the given value using the
- // Object.Equals method.
- //
- // This method uses the Array.IndexOf method to perform the
- // search.
- //
- public int IndexOf(T item, int index, int count)
- {
- if (index > _size)
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
-
- if (count < 0 || index > _size - count)
- ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
-
- return Array.IndexOf(_items, item, index, count);
- }
-
- // Inserts an element into this list at a given index. The size of the list
- // is increased by one. If required, the capacity of the list is doubled
- // before inserting the new element.
- //
- public void Insert(int index, T item)
- {
- // Note that insertions at the end are legal.
- if ((uint)index > (uint)_size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
- }
- if (_size == _items.Length) EnsureCapacity(_size + 1);
- if (index < _size)
- {
- Array.Copy(_items, index, _items, index + 1, _size - index);
- }
- _items[index] = item;
- _size++;
- _version++;
- }
-
- void IList.Insert(int index, object? item)
- {
- ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(item, ExceptionArgument.item);
-
- try
- {
- Insert(index, (T)item!);
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
- }
- }
-
- // Inserts the elements of the given collection at a given index. If
- // required, the capacity of the list is increased to twice the previous
- // capacity or the new size, whichever is larger. Ranges may be added
- // to the end of the list by setting index to the List's size.
- //
- public void InsertRange(int index, IEnumerable<T> collection)
- {
- if (collection == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
- }
-
- if ((uint)index > (uint)_size)
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
-
- if (collection is ICollection<T> c)
- {
- int count = c.Count;
- if (count > 0)
- {
- EnsureCapacity(_size + count);
- if (index < _size)
- {
- Array.Copy(_items, index, _items, index + count, _size - index);
- }
-
- // If we're inserting a List into itself, we want to be able to deal with that.
- if (this == c)
- {
- // Copy first part of _items to insert location
- Array.Copy(_items, 0, _items, index, index);
- // Copy last part of _items back to inserted location
- Array.Copy(_items, index + count, _items, index * 2, _size - index);
- }
- else
- {
- c.CopyTo(_items, index);
- }
- _size += count;
- }
- }
- else
- {
- using (IEnumerator<T> en = collection.GetEnumerator())
- {
- while (en.MoveNext())
- {
- Insert(index++, en.Current);
- }
- }
- }
- _version++;
- }
-
- // Returns the index of the last occurrence of a given value in a range of
- // this list. The list is searched backwards, starting at the end
- // and ending at the first element in the list. The elements of the list
- // are compared to the given value using the Object.Equals method.
- //
- // This method uses the Array.LastIndexOf method to perform the
- // search.
- //
- public int LastIndexOf(T item)
- {
- if (_size == 0)
- { // Special case for empty list
- return -1;
- }
- else
- {
- return LastIndexOf(item, _size - 1, _size);
- }
- }
-
- // Returns the index of the last occurrence of a given value in a range of
- // this list. The list is searched backwards, starting at index
- // index and ending at the first element in the list. The
- // elements of the list are compared to the given value using the
- // Object.Equals method.
- //
- // This method uses the Array.LastIndexOf method to perform the
- // search.
- //
- public int LastIndexOf(T item, int index)
- {
- if (index >= _size)
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- return LastIndexOf(item, index, index + 1);
- }
-
- // Returns the index of the last occurrence of a given value in a range of
- // this list. The list is searched backwards, starting at index
- // index and upto count elements. The elements of
- // the list are compared to the given value using the Object.Equals
- // method.
- //
- // This method uses the Array.LastIndexOf method to perform the
- // search.
- //
- public int LastIndexOf(T item, int index, int count)
- {
- if ((Count != 0) && (index < 0))
- {
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- }
-
- if ((Count != 0) && (count < 0))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (_size == 0)
- { // Special case for empty list
- return -1;
- }
-
- if (index >= _size)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_BiggerThanCollection);
- }
-
- if (count > index + 1)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_BiggerThanCollection);
- }
-
- return Array.LastIndexOf(_items, item, index, count);
- }
-
- // Removes the element at the given index. The size of the list is
- // decreased by one.
- public bool Remove(T item)
- {
- int index = IndexOf(item);
- if (index >= 0)
- {
- RemoveAt(index);
- return true;
- }
-
- return false;
- }
-
- void IList.Remove(object? item)
- {
- if (IsCompatibleObject(item))
- {
- Remove((T)item!);
- }
- }
-
- // This method removes all items which matches the predicate.
- // The complexity is O(n).
- public int RemoveAll(Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- int freeIndex = 0; // the first free slot in items array
-
- // Find the first item which needs to be removed.
- while (freeIndex < _size && !match(_items[freeIndex])) freeIndex++;
- if (freeIndex >= _size) return 0;
-
- int current = freeIndex + 1;
- while (current < _size)
- {
- // Find the first item which needs to be kept.
- while (current < _size && match(_items[current])) current++;
-
- if (current < _size)
- {
- // copy item to the free slot.
- _items[freeIndex++] = _items[current++];
- }
- }
-
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- Array.Clear(_items, freeIndex, _size - freeIndex); // Clear the elements so that the gc can reclaim the references.
- }
-
- int result = _size - freeIndex;
- _size = freeIndex;
- _version++;
- return result;
- }
-
- // Removes the element at the given index. The size of the list is
- // decreased by one.
- public void RemoveAt(int index)
- {
- if ((uint)index >= (uint)_size)
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
- _size--;
- if (index < _size)
- {
- Array.Copy(_items, index + 1, _items, index, _size - index);
- }
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- _items[_size] = default!;
- }
- _version++;
- }
-
- // Removes a range of elements from this list.
- public void RemoveRange(int index, int count)
- {
- if (index < 0)
- {
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- }
-
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (_size - index < count)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
-
- if (count > 0)
- {
- _size -= count;
- if (index < _size)
- {
- Array.Copy(_items, index + count, _items, index, _size - index);
- }
-
- _version++;
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- Array.Clear(_items, _size, count);
- }
- }
- }
-
- // Reverses the elements in this list.
- public void Reverse()
- => Reverse(0, Count);
-
- // Reverses the elements in a range of this list. Following a call to this
- // method, an element in the range given by index and count
- // which was previously located at index i will now be located at
- // index index + (index + count - i - 1).
- //
- public void Reverse(int index, int count)
- {
- if (index < 0)
- {
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- }
-
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (_size - index < count)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
-
- if (count > 1)
- {
- Array.Reverse(_items, index, count);
- }
- _version++;
- }
-
- // Sorts the elements in this list. Uses the default comparer and
- // Array.Sort.
- public void Sort()
- => Sort(0, Count, null);
-
- // Sorts the elements in this list. Uses Array.Sort with the
- // provided comparer.
- public void Sort(IComparer<T>? comparer)
- => Sort(0, Count, comparer);
-
- // Sorts the elements in a section of this list. The sort compares the
- // elements to each other using the given IComparer interface. If
- // comparer is null, the elements are compared to each other using
- // the IComparable interface, which in that case must be implemented by all
- // elements of the list.
- //
- // This method uses the Array.Sort method to sort the elements.
- //
- public void Sort(int index, int count, IComparer<T>? comparer)
- {
- if (index < 0)
- {
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- }
-
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (_size - index < count)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
-
- if (count > 1)
- {
- Array.Sort<T>(_items, index, count, comparer);
- }
- _version++;
- }
-
- public void Sort(Comparison<T> comparison)
- {
- if (comparison == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison);
- }
-
- if (_size > 1)
- {
- ArraySortHelper<T>.Sort(new Span<T>(_items, 0, _size), comparison);
- }
- _version++;
- }
-
- // ToArray returns an array containing the contents of the List.
- // This requires copying the List, which is an O(n) operation.
- public T[] ToArray()
- {
- if (_size == 0)
- {
- return s_emptyArray;
- }
-
- T[] array = new T[_size];
- Array.Copy(_items, array, _size);
- return array;
- }
-
- // Sets the capacity of this list to the size of the list. This method can
- // be used to minimize a list's memory overhead once it is known that no
- // new elements will be added to the list. To completely clear a list and
- // release all memory referenced by the list, execute the following
- // statements:
- //
- // list.Clear();
- // list.TrimExcess();
- //
- public void TrimExcess()
- {
- int threshold = (int)(((double)_items.Length) * 0.9);
- if (_size < threshold)
- {
- Capacity = _size;
- }
- }
-
- public bool TrueForAll(Predicate<T> match)
- {
- if (match == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
- }
-
- for (int i = 0; i < _size; i++)
- {
- if (!match(_items[i]))
- {
- return false;
- }
- }
- return true;
- }
-
- public struct Enumerator : IEnumerator<T>, IEnumerator
- {
- private readonly List<T> _list;
- private int _index;
- private readonly int _version;
- [AllowNull, MaybeNull] private T _current;
-
- internal Enumerator(List<T> list)
- {
- _list = list;
- _index = 0;
- _version = list._version;
- _current = default;
- }
-
- public void Dispose()
- {
- }
-
- public bool MoveNext()
- {
- List<T> localList = _list;
-
- if (_version == localList._version && ((uint)_index < (uint)localList._size))
- {
- _current = localList._items[_index];
- _index++;
- return true;
- }
- return MoveNextRare();
- }
-
- private bool MoveNextRare()
- {
- if (_version != _list._version)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
- }
-
- _index = _list._size + 1;
- _current = default;
- return false;
- }
-
- public T Current => _current!;
-
- object? IEnumerator.Current
- {
- get
- {
- if (_index == 0 || _index == _list._size + 1)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
- }
- return Current;
- }
- }
-
- void IEnumerator.Reset()
- {
- if (_version != _list._version)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
- }
-
- _index = 0;
- _current = default;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/NonRandomizedStringEqualityComparer.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/NonRandomizedStringEqualityComparer.cs
deleted file mode 100644
index 1acda3fa9bd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/NonRandomizedStringEqualityComparer.cs
+++ /dev/null
@@ -1,34 +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 System.Runtime.Serialization;
-
-namespace System.Collections.Generic
-{
- // NonRandomizedStringEqualityComparer is the comparer used by default with the Dictionary<string,...>
- // We use NonRandomizedStringEqualityComparer as default comparer as it doesnt use the randomized string hashing which
- // keeps the performance not affected till we hit collision threshold and then we switch to the comparer which is using
- // randomized string hashing.
- [Serializable] // Required for compatibility with .NET Core 2.0 as we exposed the NonRandomizedStringEqualityComparer inside the serialization blob
- // Needs to be public to support binary serialization compatibility
- public sealed class NonRandomizedStringEqualityComparer : EqualityComparer<string?>, ISerializable
- {
- internal static new IEqualityComparer<string?> Default { get; } = new NonRandomizedStringEqualityComparer();
-
- private NonRandomizedStringEqualityComparer() { }
-
- // This is used by the serialization engine.
- private NonRandomizedStringEqualityComparer(SerializationInfo information, StreamingContext context) { }
-
- public sealed override bool Equals(string? x, string? y) => string.Equals(x, y);
-
- public sealed override int GetHashCode(string? obj) => obj?.GetNonRandomizedHashCode() ?? 0;
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- // We are doing this to stay compatible with .NET Framework.
- info.SetType(typeof(GenericEqualityComparer<string>));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ValueListBuilder.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ValueListBuilder.cs
deleted file mode 100644
index cce86c23e4e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/ValueListBuilder.cs
+++ /dev/null
@@ -1,86 +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.
-
-#nullable enable
-using System.Buffers;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Collections.Generic
-{
- internal ref partial struct ValueListBuilder<T>
- {
- private Span<T> _span;
- private T[]? _arrayFromPool;
- private int _pos;
-
- public ValueListBuilder(Span<T> initialSpan)
- {
- _span = initialSpan;
- _arrayFromPool = null;
- _pos = 0;
- }
-
- public int Length
- {
- get => _pos;
- set
- {
- Debug.Assert(value >= 0);
- Debug.Assert(value <= _span.Length);
- _pos = value;
- }
- }
-
- public ref T this[int index]
- {
- get
- {
- Debug.Assert(index < _pos);
- return ref _span[index];
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Append(T item)
- {
- int pos = _pos;
- if (pos >= _span.Length)
- Grow();
-
- _span[pos] = item;
- _pos = pos + 1;
- }
-
- public ReadOnlySpan<T> AsSpan()
- {
- return _span.Slice(0, _pos);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Dispose()
- {
- if (_arrayFromPool != null)
- {
- ArrayPool<T>.Shared.Return(_arrayFromPool);
- _arrayFromPool = null;
- }
- }
-
- private void Grow()
- {
- T[] array = ArrayPool<T>.Shared.Rent(_span.Length * 2);
-
- bool success = _span.TryCopyTo(array);
- Debug.Assert(success);
-
- T[]? toReturn = _arrayFromPool;
- _span = _arrayFromPool = array;
- if (toReturn != null)
- {
- ArrayPool<T>.Shared.Return(toReturn);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/HashHelpers.SerializationInfoTable.cs b/netcore/System.Private.CoreLib/shared/System/Collections/HashHelpers.SerializationInfoTable.cs
deleted file mode 100644
index f1be500f20e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/HashHelpers.SerializationInfoTable.cs
+++ /dev/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.
-
-// Used by Hashtable and Dictionary's SeralizationInfo .ctor's to store the SeralizationInfo
-// object until OnDeserialization is called.
-
-using System.Threading;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-
-namespace System.Collections
-{
- internal static partial class HashHelpers
- {
- private static ConditionalWeakTable<object, SerializationInfo>? s_serializationInfoTable;
-
- public static ConditionalWeakTable<object, SerializationInfo> SerializationInfoTable
- {
- get
- {
- if (s_serializationInfoTable == null)
- Interlocked.CompareExchange(ref s_serializationInfoTable, new ConditionalWeakTable<object, SerializationInfo>(), null);
-
- return s_serializationInfoTable;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/HashHelpers.cs b/netcore/System.Private.CoreLib/shared/System/Collections/HashHelpers.cs
deleted file mode 100644
index b01b01d8746..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/HashHelpers.cs
+++ /dev/null
@@ -1,111 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Collections
-{
- internal static partial class HashHelpers
- {
- public const uint HashCollisionThreshold = 100;
-
- // This is the maximum prime smaller than Array.MaxArrayLength
- public const int MaxPrimeArrayLength = 0x7FEFFFFD;
-
- public const int HashPrime = 101;
-
- // Table of prime numbers to use as hash table sizes.
- // A typical resize algorithm would pick the smallest prime number in this array
- // that is larger than twice the previous capacity.
- // Suppose our Hashtable currently has capacity x and enough elements are added
- // such that a resize needs to occur. Resizing first computes 2x then finds the
- // first prime in the table greater than 2x, i.e. if primes are ordered
- // p_1, p_2, ..., p_i, ..., it finds p_n such that p_n-1 < 2x < p_n.
- // Doubling is important for preserving the asymptotic complexity of the
- // hashtable operations such as add. Having a prime guarantees that double
- // hashing does not lead to infinite loops. IE, your hash function will be
- // h1(key) + i*h2(key), 0 <= i < size. h2 and the size must be relatively prime.
- // We prefer the low computation costs of higher prime numbers over the increased
- // memory allocation of a fixed prime number i.e. when right sizing a HashSet.
- private static readonly int[] s_primes =
- {
- 3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,
- 1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591,
- 17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437,
- 187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263,
- 1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369
- };
-
- public static bool IsPrime(int candidate)
- {
- if ((candidate & 1) != 0)
- {
- int limit = (int)Math.Sqrt(candidate);
- for (int divisor = 3; divisor <= limit; divisor += 2)
- {
- if ((candidate % divisor) == 0)
- return false;
- }
- return true;
- }
- return candidate == 2;
- }
-
- public static int GetPrime(int min)
- {
- if (min < 0)
- throw new ArgumentException(SR.Arg_HTCapacityOverflow);
-
- foreach (int prime in s_primes)
- {
- if (prime >= min)
- return prime;
- }
-
- // Outside of our predefined table. Compute the hard way.
- for (int i = (min | 1); i < int.MaxValue; i += 2)
- {
- if (IsPrime(i) && ((i - 1) % HashPrime != 0))
- return i;
- }
- return min;
- }
-
- // Returns size of hashtable to grow to.
- public static int ExpandPrime(int oldSize)
- {
- int newSize = 2 * oldSize;
-
- // Allow the hashtables to grow to maximum possible size (~2G elements) before encountering capacity overflow.
- // Note that this check works even when _items.Length overflowed thanks to the (uint) cast
- if ((uint)newSize > MaxPrimeArrayLength && MaxPrimeArrayLength > oldSize)
- {
- Debug.Assert(MaxPrimeArrayLength == GetPrime(MaxPrimeArrayLength), "Invalid MaxPrimeArrayLength");
- return MaxPrimeArrayLength;
- }
-
- return GetPrime(newSize);
- }
-
-#if BIT64
- public static ulong GetFastModMultiplier(uint divisor)
- => ulong.MaxValue / divisor + 1;
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static uint FastMod(uint value, uint divisor, ulong multiplier)
- {
- // Using fastmod from Daniel Lemire https://lemire.me/blog/2019/02/08/faster-remainders-when-the-divisor-is-a-constant-beating-compilers-and-libdivide/
-
- ulong lowbits = multiplier * value;
- // 64bit * 64bit => 128bit isn't currently supported by Math https://github.com/dotnet/corefx/issues/41822
- // otherwise we'd want this to be (uint)Math.MultiplyHigh(lowbits, divisor)
- uint high = (uint)((((ulong)(uint)lowbits * divisor >> 32) + (lowbits >> 32) * divisor) >> 32);
-
- Debug.Assert(high == value % divisor);
- return high;
- }
-#endif
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/Hashtable.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Hashtable.cs
deleted file mode 100644
index 7d10ecdefc7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/Hashtable.cs
+++ /dev/null
@@ -1,1550 +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.
-
-/*============================================================
-**
-** Class: Hashtable
-**
-** Purpose: Represents a collection of key/value pairs
-** that are organized based on the hash code
-** of the key.
-**
-===========================================================*/
-
-using System.Diagnostics;
-using System.Runtime.Serialization;
-using System.Threading;
-
-namespace System.Collections
-{
- // The Hashtable class represents a dictionary of associated keys and values
- // with constant lookup time.
- //
- // Objects used as keys in a hashtable must implement the GetHashCode
- // and Equals methods (or they can rely on the default implementations
- // inherited from Object if key equality is simply reference
- // equality). Furthermore, the GetHashCode and Equals methods of
- // a key object must produce the same results given the same parameters for the
- // entire time the key is present in the hashtable. In practical terms, this
- // means that key objects should be immutable, at least for the time they are
- // used as keys in a hashtable.
- //
- // When entries are added to a hashtable, they are placed into
- // buckets based on the hashcode of their keys. Subsequent lookups of
- // keys will use the hashcode of the keys to only search a particular bucket,
- // thus substantially reducing the number of key comparisons required to find
- // an entry. A hashtable's maximum load factor, which can be specified
- // when the hashtable is instantiated, determines the maximum ratio of
- // hashtable entries to hashtable buckets. Smaller load factors cause faster
- // average lookup times at the cost of increased memory consumption. The
- // default maximum load factor of 1.0 generally provides the best balance
- // between speed and size. As entries are added to a hashtable, the hashtable's
- // actual load factor increases, and when the actual load factor reaches the
- // maximum load factor value, the number of buckets in the hashtable is
- // automatically increased by approximately a factor of two (to be precise, the
- // number of hashtable buckets is increased to the smallest prime number that
- // is larger than twice the current number of hashtable buckets).
- //
- // Each object provides their own hash function, accessed by calling
- // GetHashCode(). However, one can write their own object
- // implementing IEqualityComparer and pass it to a constructor on
- // the Hashtable. That hash function (and the equals method on the
- // IEqualityComparer) would be used for all objects in the table.
- //
- [DebuggerTypeProxy(typeof(System.Collections.Hashtable.HashtableDebugView))]
- [DebuggerDisplay("Count = {Count}")]
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Hashtable : IDictionary, ISerializable, IDeserializationCallback, ICloneable
- {
- /*
- This Hashtable uses double hashing. There are hashsize buckets in the
- table, and each bucket can contain 0 or 1 element. We use a bit to mark
- whether there's been a collision when we inserted multiple elements
- (ie, an inserted item was hashed at least a second time and we probed
- this bucket, but it was already in use). Using the collision bit, we
- can terminate lookups & removes for elements that aren't in the hash
- table more quickly. We steal the most significant bit from the hash code
- to store the collision bit.
-
- Our hash function is of the following form:
-
- h(key, n) = h1(key) + n*h2(key)
-
- where n is the number of times we've hit a collided bucket and rehashed
- (on this particular lookup). Here are our hash functions:
-
- h1(key) = GetHash(key); // default implementation calls key.GetHashCode();
- h2(key) = 1 + (((h1(key) >> 5) + 1) % (hashsize - 1));
-
- The h1 can return any number. h2 must return a number between 1 and
- hashsize - 1 that is relatively prime to hashsize (not a problem if
- hashsize is prime). (Knuth's Art of Computer Programming, Vol. 3, p. 528-9)
- If this is true, then we are guaranteed to visit every bucket in exactly
- hashsize probes, since the least common multiple of hashsize and h2(key)
- will be hashsize * h2(key). (This is the first number where adding h2 to
- h1 mod hashsize will be 0 and we will search the same bucket twice).
-
- We previously used a different h2(key, n) that was not constant. That is a
- horrifically bad idea, unless you can prove that series will never produce
- any identical numbers that overlap when you mod them by hashsize, for all
- subranges from i to i+hashsize, for all i. It's not worth investigating,
- since there was no clear benefit from using that hash function, and it was
- broken.
-
- For efficiency reasons, we've implemented this by storing h1 and h2 in a
- temporary, and setting a variable called seed equal to h1. We do a probe,
- and if we collided, we simply add h2 to seed each time through the loop.
-
- A good test for h2() is to subclass Hashtable, provide your own implementation
- of GetHash() that returns a constant, then add many items to the hash table.
- Make sure Count equals the number of items you inserted.
-
- Note that when we remove an item from the hash table, we set the key
- equal to buckets, if there was a collision in this bucket. Otherwise
- we'd either wipe out the collision bit, or we'd still have an item in
- the hash table.
-
- --
- */
-
- private const int InitialSize = 3;
-
- private const string LoadFactorName = "LoadFactor"; // Do not rename (binary serialization)
- private const string VersionName = "Version"; // Do not rename (binary serialization)
- private const string ComparerName = "Comparer"; // Do not rename (binary serialization)
- private const string HashCodeProviderName = "HashCodeProvider"; // Do not rename (binary serialization)
- private const string HashSizeName = "HashSize"; // Must save buckets.Length. Do not rename (binary serialization)
- private const string KeysName = "Keys"; // Do not rename (binary serialization)
- private const string ValuesName = "Values"; // Do not rename (binary serialization)
- private const string KeyComparerName = "KeyComparer"; // Do not rename (binary serialization)
-
- // Deleted entries have their key set to buckets
-
- // The hash table data.
- // This cannot be serialized
- private struct bucket
- {
- public object? key;
- public object? val;
- public int hash_coll; // Store hash code; sign bit means there was a collision.
- }
-
- private bucket[] _buckets = null!;
-
- // The total number of entries in the hash table.
- private int _count;
-
- // The total number of collision bits set in the hashtable
- private int _occupancy;
-
- private int _loadsize;
- private float _loadFactor;
-
- private volatile int _version;
- private volatile bool _isWriterInProgress;
-
- private ICollection? _keys;
- private ICollection? _values;
-
- private IEqualityComparer? _keycomparer;
-
- [Obsolete("Please use EqualityComparer property.")]
- protected IHashCodeProvider? hcp
- {
- get
- {
- if (_keycomparer is CompatibleComparer)
- {
- return ((CompatibleComparer)_keycomparer).HashCodeProvider;
- }
- else if (_keycomparer == null)
- {
- return null;
- }
- else
- {
- throw new ArgumentException(SR.Arg_CannotMixComparisonInfrastructure);
- }
- }
- set
- {
- if (_keycomparer is CompatibleComparer keyComparer)
- {
- _keycomparer = new CompatibleComparer(value, keyComparer.Comparer);
- }
- else if (_keycomparer == null)
- {
- _keycomparer = new CompatibleComparer(value, (IComparer?)null);
- }
- else
- {
- throw new ArgumentException(SR.Arg_CannotMixComparisonInfrastructure);
- }
- }
- }
-
- [Obsolete("Please use KeyComparer properties.")]
- protected IComparer? comparer
- {
- get
- {
- if (_keycomparer is CompatibleComparer)
- {
- return ((CompatibleComparer)_keycomparer).Comparer;
- }
- else if (_keycomparer == null)
- {
- return null;
- }
- else
- {
- throw new ArgumentException(SR.Arg_CannotMixComparisonInfrastructure);
- }
- }
- set
- {
- if (_keycomparer is CompatibleComparer keyComparer)
- {
- _keycomparer = new CompatibleComparer(keyComparer.HashCodeProvider, value);
- }
- else if (_keycomparer == null)
- {
- _keycomparer = new CompatibleComparer((IHashCodeProvider?)null, value);
- }
- else
- {
- throw new ArgumentException(SR.Arg_CannotMixComparisonInfrastructure);
- }
- }
- }
-
- protected IEqualityComparer? EqualityComparer => _keycomparer;
-
- // Note: this constructor is a bogus constructor that does nothing
- // and is for use only with SyncHashtable.
- internal Hashtable(bool trash)
- {
- }
-
- // Constructs a new hashtable. The hashtable is created with an initial
- // capacity of zero and a load factor of 1.0.
- public Hashtable() : this(0, 1.0f)
- {
- }
-
- // Constructs a new hashtable with the given initial capacity and a load
- // factor of 1.0. The capacity argument serves as an indication of
- // the number of entries the hashtable will contain. When this number (or
- // an approximation) is known, specifying it in the constructor can
- // eliminate a number of resizing operations that would otherwise be
- // performed when elements are added to the hashtable.
- //
- public Hashtable(int capacity) : this(capacity, 1.0f)
- {
- }
-
- // Constructs a new hashtable with the given initial capacity and load
- // factor. The capacity argument serves as an indication of the
- // number of entries the hashtable will contain. When this number (or an
- // approximation) is known, specifying it in the constructor can eliminate
- // a number of resizing operations that would otherwise be performed when
- // elements are added to the hashtable. The loadFactor argument
- // indicates the maximum ratio of hashtable entries to hashtable buckets.
- // Smaller load factors cause faster average lookup times at the cost of
- // increased memory consumption. A load factor of 1.0 generally provides
- // the best balance between speed and size.
- //
- public Hashtable(int capacity, float loadFactor)
- {
- if (capacity < 0)
- throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (!(loadFactor >= 0.1f && loadFactor <= 1.0f))
- throw new ArgumentOutOfRangeException(nameof(loadFactor), SR.Format(SR.ArgumentOutOfRange_HashtableLoadFactor, .1, 1.0));
-
- // Based on perf work, .72 is the optimal load factor for this table.
- _loadFactor = 0.72f * loadFactor;
-
- double rawsize = capacity / _loadFactor;
- if (rawsize > int.MaxValue)
- throw new ArgumentException(SR.Arg_HTCapacityOverflow, nameof(capacity));
-
- // Avoid awfully small sizes
- int hashsize = (rawsize > InitialSize) ? HashHelpers.GetPrime((int)rawsize) : InitialSize;
- _buckets = new bucket[hashsize];
-
- _loadsize = (int)(_loadFactor * hashsize);
- _isWriterInProgress = false;
- // Based on the current algorithm, loadsize must be less than hashsize.
- Debug.Assert(_loadsize < hashsize, "Invalid hashtable loadsize!");
- }
-
- public Hashtable(int capacity, float loadFactor, IEqualityComparer? equalityComparer) : this(capacity, loadFactor)
- {
- _keycomparer = equalityComparer;
- }
-
- [Obsolete("Please use Hashtable(IEqualityComparer) instead.")]
- public Hashtable(IHashCodeProvider? hcp, IComparer? comparer)
- : this(0, 1.0f, hcp, comparer)
- {
- }
-
- public Hashtable(IEqualityComparer? equalityComparer) : this(0, 1.0f, equalityComparer)
- {
- }
-
- [Obsolete("Please use Hashtable(int, IEqualityComparer) instead.")]
- public Hashtable(int capacity, IHashCodeProvider? hcp, IComparer? comparer)
- : this(capacity, 1.0f, hcp, comparer)
- {
- }
-
- public Hashtable(int capacity, IEqualityComparer? equalityComparer)
- : this(capacity, 1.0f, equalityComparer)
- {
- }
-
- // Constructs a new hashtable containing a copy of the entries in the given
- // dictionary. The hashtable is created with a load factor of 1.0.
- //
- public Hashtable(IDictionary d) : this(d, 1.0f)
- {
- }
-
- // Constructs a new hashtable containing a copy of the entries in the given
- // dictionary. The hashtable is created with the given load factor.
- //
- public Hashtable(IDictionary d, float loadFactor)
- : this(d, loadFactor, (IEqualityComparer?)null)
- {
- }
-
- [Obsolete("Please use Hashtable(IDictionary, IEqualityComparer) instead.")]
- public Hashtable(IDictionary d, IHashCodeProvider? hcp, IComparer? comparer)
- : this(d, 1.0f, hcp, comparer)
- {
- }
-
- public Hashtable(IDictionary d, IEqualityComparer? equalityComparer)
- : this(d, 1.0f, equalityComparer)
- {
- }
-
- [Obsolete("Please use Hashtable(int, float, IEqualityComparer) instead.")]
- public Hashtable(int capacity, float loadFactor, IHashCodeProvider? hcp, IComparer? comparer)
- : this(capacity, loadFactor)
- {
- if (hcp != null || comparer != null)
- {
- _keycomparer = new CompatibleComparer(hcp, comparer);
- }
- }
-
- [Obsolete("Please use Hashtable(IDictionary, float, IEqualityComparer) instead.")]
- public Hashtable(IDictionary d, float loadFactor, IHashCodeProvider? hcp, IComparer? comparer)
- : this(d != null ? d.Count : 0, loadFactor, hcp, comparer)
- {
- if (d == null)
- throw new ArgumentNullException(nameof(d), SR.ArgumentNull_Dictionary);
-
- IDictionaryEnumerator e = d.GetEnumerator();
- while (e.MoveNext())
- Add(e.Key, e.Value);
- }
-
- public Hashtable(IDictionary d, float loadFactor, IEqualityComparer? equalityComparer)
- : this(d != null ? d.Count : 0, loadFactor, equalityComparer)
- {
- if (d == null)
- throw new ArgumentNullException(nameof(d), SR.ArgumentNull_Dictionary);
-
- IDictionaryEnumerator e = d.GetEnumerator();
- while (e.MoveNext())
- Add(e.Key, e.Value);
- }
-
- protected Hashtable(SerializationInfo info, StreamingContext context)
- {
- // We can't do anything with the keys and values until the entire graph has been deserialized
- // and we have a reasonable estimate that GetHashCode is not going to fail. For the time being,
- // we'll just cache this. The graph is not valid until OnDeserialization has been called.
- HashHelpers.SerializationInfoTable.Add(this, info);
- }
-
- // ?InitHash? is basically an implementation of classic DoubleHashing (see http://en.wikipedia.org/wiki/Double_hashing)
- //
- // 1) The only ?correctness? requirement is that the ?increment? used to probe
- // a. Be non-zero
- // b. Be relatively prime to the table size ?hashSize?. (This is needed to insure you probe all entries in the table before you ?wrap? and visit entries already probed)
- // 2) Because we choose table sizes to be primes, we just need to insure that the increment is 0 < incr < hashSize
- //
- // Thus this function would work: Incr = 1 + (seed % (hashSize-1))
- //
- // While this works well for ?uniformly distributed? keys, in practice, non-uniformity is common.
- // In particular in practice we can see ?mostly sequential? where you get long clusters of keys that ?pack?.
- // To avoid bad behavior you want it to be the case that the increment is ?large? even for ?small? values (because small
- // values tend to happen more in practice). Thus we multiply ?seed? by a number that will make these small values
- // bigger (and not hurt large values). We picked HashPrime (101) because it was prime, and if ?hashSize-1? is not a multiple of HashPrime
- // (enforced in GetPrime), then incr has the potential of being every value from 1 to hashSize-1. The choice was largely arbitrary.
- //
- // Computes the hash function: H(key, i) = h1(key) + i*h2(key, hashSize).
- // The out parameter seed is h1(key), while the out parameter
- // incr is h2(key, hashSize). Callers of this function should
- // add incr each time through a loop.
- private uint InitHash(object key, int hashsize, out uint seed, out uint incr)
- {
- // Hashcode must be positive. Also, we must not use the sign bit, since
- // that is used for the collision bit.
- uint hashcode = (uint)GetHash(key) & 0x7FFFFFFF;
- seed = (uint)hashcode;
- // Restriction: incr MUST be between 1 and hashsize - 1, inclusive for
- // the modular arithmetic to work correctly. This guarantees you'll
- // visit every bucket in the table exactly once within hashsize
- // iterations. Violate this and it'll cause obscure bugs forever.
- // If you change this calculation for h2(key), update putEntry too!
- incr = (uint)(1 + ((seed * HashHelpers.HashPrime) % ((uint)hashsize - 1)));
- return hashcode;
- }
-
- // Adds an entry with the given key and value to this hashtable. An
- // ArgumentException is thrown if the key is null or if the key is already
- // present in the hashtable.
- //
- public virtual void Add(object key, object? value)
- {
- Insert(key, value, true);
- }
-
- // Removes all entries from this hashtable.
- public virtual void Clear()
- {
- Debug.Assert(!_isWriterInProgress, "Race condition detected in usages of Hashtable - multiple threads appear to be writing to a Hashtable instance simultaneously! Don't do that - use Hashtable.Synchronized.");
-
- if (_count == 0 && _occupancy == 0)
- return;
-
- _isWriterInProgress = true;
- for (int i = 0; i < _buckets.Length; i++)
- {
- _buckets[i].hash_coll = 0;
- _buckets[i].key = null;
- _buckets[i].val = null;
- }
-
- _count = 0;
- _occupancy = 0;
- UpdateVersion();
- _isWriterInProgress = false;
- }
-
- // Clone returns a virtually identical copy of this hash table. This does
- // a shallow copy - the Objects in the table aren't cloned, only the references
- // to those Objects.
- public virtual object Clone()
- {
- bucket[] lbuckets = _buckets;
- Hashtable ht = new Hashtable(_count, _keycomparer);
- ht._version = _version;
- ht._loadFactor = _loadFactor;
- ht._count = 0;
-
- int bucket = lbuckets.Length;
- while (bucket > 0)
- {
- bucket--;
- object? keyv = lbuckets[bucket].key;
- if ((keyv != null) && (keyv != lbuckets))
- {
- ht[keyv] = lbuckets[bucket].val;
- }
- }
-
- return ht;
- }
-
- // Checks if this hashtable contains the given key.
- public virtual bool Contains(object key)
- {
- return ContainsKey(key);
- }
-
- // Checks if this hashtable contains an entry with the given key. This is
- // an O(1) operation.
- //
- public virtual bool ContainsKey(object key)
- {
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
- }
-
- uint seed;
- uint incr;
- // Take a snapshot of buckets, in case another thread resizes table
- bucket[] lbuckets = _buckets;
- uint hashcode = InitHash(key, lbuckets.Length, out seed, out incr);
- int ntry = 0;
-
- bucket b;
- int bucketNumber = (int)(seed % (uint)lbuckets.Length);
- do
- {
- b = lbuckets[bucketNumber];
- if (b.key == null)
- {
- return false;
- }
- if (((b.hash_coll & 0x7FFFFFFF) == hashcode) &&
- KeyEquals(b.key, key))
- return true;
- bucketNumber = (int)(((long)bucketNumber + incr) % (uint)lbuckets.Length);
- } while (b.hash_coll < 0 && ++ntry < lbuckets.Length);
- return false;
- }
-
- // Checks if this hashtable contains an entry with the given value. The
- // values of the entries of the hashtable are compared to the given value
- // using the Object.Equals method. This method performs a linear
- // search and is thus be substantially slower than the ContainsKey
- // method.
- //
- public virtual bool ContainsValue(object? value)
- {
- if (value == null)
- {
- for (int i = _buckets.Length; --i >= 0;)
- {
- if (_buckets[i].key != null && _buckets[i].key != _buckets && _buckets[i].val == null)
- return true;
- }
- }
- else
- {
- for (int i = _buckets.Length; --i >= 0;)
- {
- object? val = _buckets[i].val;
- if (val != null && val.Equals(value))
- return true;
- }
- }
- return false;
- }
-
- // Copies the keys of this hashtable to a given array starting at a given
- // index. This method is used by the implementation of the CopyTo method in
- // the KeyCollection class.
- private void CopyKeys(Array array, int arrayIndex)
- {
- Debug.Assert(array != null);
- Debug.Assert(array.Rank == 1);
-
- bucket[] lbuckets = _buckets;
- for (int i = lbuckets.Length; --i >= 0;)
- {
- object? keyv = lbuckets[i].key;
- if ((keyv != null) && (keyv != _buckets))
- {
- array.SetValue(keyv, arrayIndex++);
- }
- }
- }
-
- // Copies the keys of this hashtable to a given array starting at a given
- // index. This method is used by the implementation of the CopyTo method in
- // the KeyCollection class.
- private void CopyEntries(Array array, int arrayIndex)
- {
- Debug.Assert(array != null);
- Debug.Assert(array.Rank == 1);
-
- bucket[] lbuckets = _buckets;
- for (int i = lbuckets.Length; --i >= 0;)
- {
- object? keyv = lbuckets[i].key;
- if ((keyv != null) && (keyv != _buckets))
- {
- DictionaryEntry entry = new DictionaryEntry(keyv, lbuckets[i].val);
- array.SetValue(entry, arrayIndex++);
- }
- }
- }
-
- // Copies the values in this hash table to an array at
- // a given index. Note that this only copies values, and not keys.
- public virtual void CopyTo(Array array, int arrayIndex)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array), SR.ArgumentNull_Array);
- if (array.Rank != 1)
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));
- if (arrayIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(arrayIndex), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - arrayIndex < Count)
- throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
-
- CopyEntries(array, arrayIndex);
- }
-
- // Copies the values in this Hashtable to an KeyValuePairs array.
- // KeyValuePairs is different from Dictionary Entry in that it has special
- // debugger attributes on its fields.
-
- internal virtual KeyValuePairs[] ToKeyValuePairsArray()
- {
- KeyValuePairs[] array = new KeyValuePairs[_count];
- int index = 0;
- bucket[] lbuckets = _buckets;
- for (int i = lbuckets.Length; --i >= 0;)
- {
- object? keyv = lbuckets[i].key;
- if ((keyv != null) && (keyv != _buckets))
- {
- array[index++] = new KeyValuePairs(keyv, lbuckets[i].val);
- }
- }
-
- return array;
- }
-
- // Copies the values of this hashtable to a given array starting at a given
- // index. This method is used by the implementation of the CopyTo method in
- // the ValueCollection class.
- private void CopyValues(Array array, int arrayIndex)
- {
- Debug.Assert(array != null);
- Debug.Assert(array.Rank == 1);
-
- bucket[] lbuckets = _buckets;
- for (int i = lbuckets.Length; --i >= 0;)
- {
- object? keyv = lbuckets[i].key;
- if ((keyv != null) && (keyv != _buckets))
- {
- array.SetValue(lbuckets[i].val, arrayIndex++);
- }
- }
- }
-
- // Returns the value associated with the given key. If an entry with the
- // given key is not found, the returned value is null.
- //
- public virtual object? this[object key]
- {
- get
- {
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
- }
-
- uint seed;
- uint incr;
-
- // Take a snapshot of buckets, in case another thread does a resize
- bucket[] lbuckets = _buckets;
- uint hashcode = InitHash(key, lbuckets.Length, out seed, out incr);
- int ntry = 0;
-
- bucket b;
- int bucketNumber = (int)(seed % (uint)lbuckets.Length);
- do
- {
- int currentversion;
-
- // A read operation on hashtable has three steps:
- // (1) calculate the hash and find the slot number.
- // (2) compare the hashcode, if equal, go to step 3. Otherwise end.
- // (3) compare the key, if equal, go to step 4. Otherwise end.
- // (4) return the value contained in the bucket.
- // After step 3 and before step 4. A writer can kick in a remove the old item and add a new one
- // in the same bucket. So in the reader we need to check if the hash table is modified during above steps.
- //
- // Writers (Insert, Remove, Clear) will set 'isWriterInProgress' flag before it starts modifying
- // the hashtable and will ckear the flag when it is done. When the flag is cleared, the 'version'
- // will be increased. We will repeat the reading if a writer is in progress or done with the modification
- // during the read.
- //
- // Our memory model guarantee if we pick up the change in bucket from another processor,
- // we will see the 'isWriterProgress' flag to be true or 'version' is changed in the reader.
- //
- SpinWait spin = default;
- while (true)
- {
- // this is volatile read, following memory accesses can not be moved ahead of it.
- currentversion = _version;
- b = lbuckets[bucketNumber];
-
- if (!_isWriterInProgress && (currentversion == _version))
- break;
-
- spin.SpinOnce();
- }
-
- if (b.key == null)
- {
- return null;
- }
- if (((b.hash_coll & 0x7FFFFFFF) == hashcode) &&
- KeyEquals(b.key, key))
- return b.val;
- bucketNumber = (int)(((long)bucketNumber + incr) % (uint)lbuckets.Length);
- } while (b.hash_coll < 0 && ++ntry < lbuckets.Length);
- return null;
- }
-
- set => Insert(key, value, false);
- }
-
- // Increases the bucket count of this hashtable. This method is called from
- // the Insert method when the actual load factor of the hashtable reaches
- // the upper limit specified when the hashtable was constructed. The number
- // of buckets in the hashtable is increased to the smallest prime number
- // that is larger than twice the current number of buckets, and the entries
- // in the hashtable are redistributed into the new buckets using the cached
- // hashcodes.
- private void expand()
- {
- int rawsize = HashHelpers.ExpandPrime(_buckets.Length);
- rehash(rawsize);
- }
-
- // We occasionally need to rehash the table to clean up the collision bits.
- private void rehash()
- {
- rehash(_buckets.Length);
- }
-
- private void UpdateVersion()
- {
- // Version might become negative when version is int.MaxValue, but the oddity will be still be correct.
- // So we don't need to special case this.
- _version++;
- }
-
- private void rehash(int newsize)
- {
- // reset occupancy
- _occupancy = 0;
-
- // Don't replace any internal state until we've finished adding to the
- // new bucket[]. This serves two purposes:
- // 1) Allow concurrent readers to see valid hashtable contents
- // at all times
- // 2) Protect against an OutOfMemoryException while allocating this
- // new bucket[].
- bucket[] newBuckets = new bucket[newsize];
-
- // rehash table into new buckets
- int nb;
- for (nb = 0; nb < _buckets.Length; nb++)
- {
- bucket oldb = _buckets[nb];
- if ((oldb.key != null) && (oldb.key != _buckets))
- {
- int hashcode = oldb.hash_coll & 0x7FFFFFFF;
- putEntry(newBuckets, oldb.key, oldb.val, hashcode);
- }
- }
-
- // New bucket[] is good to go - replace buckets and other internal state.
- _isWriterInProgress = true;
- _buckets = newBuckets;
- _loadsize = (int)(_loadFactor * newsize);
- UpdateVersion();
- _isWriterInProgress = false;
- // minimum size of hashtable is 3 now and maximum loadFactor is 0.72 now.
- Debug.Assert(_loadsize < newsize, "Our current implementation means this is not possible.");
- }
-
- // Returns an enumerator for this hashtable.
- // If modifications made to the hashtable while an enumeration is
- // in progress, the MoveNext and Current methods of the
- // enumerator will throw an exception.
- //
- IEnumerator IEnumerable.GetEnumerator()
- {
- return new HashtableEnumerator(this, HashtableEnumerator.DictEntry);
- }
-
- // Returns a dictionary enumerator for this hashtable.
- // If modifications made to the hashtable while an enumeration is
- // in progress, the MoveNext and Current methods of the
- // enumerator will throw an exception.
- //
- public virtual IDictionaryEnumerator GetEnumerator()
- {
- return new HashtableEnumerator(this, HashtableEnumerator.DictEntry);
- }
-
- // Internal method to get the hash code for an Object. This will call
- // GetHashCode() on each object if you haven't provided an IHashCodeProvider
- // instance. Otherwise, it calls hcp.GetHashCode(obj).
- protected virtual int GetHash(object key)
- {
- if (_keycomparer != null)
- return _keycomparer.GetHashCode(key);
- return key.GetHashCode();
- }
-
- // Is this Hashtable read-only?
- public virtual bool IsReadOnly => false;
-
- public virtual bool IsFixedSize => false;
-
- // Is this Hashtable synchronized? See SyncRoot property
- public virtual bool IsSynchronized => false;
-
- // Internal method to compare two keys. If you have provided an IComparer
- // instance in the constructor, this method will call comparer.Compare(item, key).
- // Otherwise, it will call item.Equals(key).
- //
- protected virtual bool KeyEquals(object? item, object key)
- {
- Debug.Assert(key != null, "key can't be null here!");
- if (object.ReferenceEquals(_buckets, item))
- {
- return false;
- }
-
- if (object.ReferenceEquals(item, key))
- return true;
-
- if (_keycomparer != null)
- return _keycomparer.Equals(item, key);
- return item == null ? false : item.Equals(key);
- }
-
- // Returns a collection representing the keys of this hashtable. The order
- // in which the returned collection represents the keys is unspecified, but
- // it is guaranteed to be buckets = newBuckets; the same order in which a collection returned by
- // GetValues represents the values of the hashtable.
- //
- // The returned collection is live in the sense that any changes
- // to the hash table are reflected in this collection. It is not
- // a static copy of all the keys in the hash table.
- //
- public virtual ICollection Keys => _keys ??= new KeyCollection(this);
-
- // Returns a collection representing the values of this hashtable. The
- // order in which the returned collection represents the values is
- // unspecified, but it is guaranteed to be the same order in which a
- // collection returned by GetKeys represents the keys of the
- // hashtable.
- //
- // The returned collection is live in the sense that any changes
- // to the hash table are reflected in this collection. It is not
- // a static copy of all the keys in the hash table.
- //
- public virtual ICollection Values => _values ??= new ValueCollection(this);
-
- // Inserts an entry into this hashtable. This method is called from the Set
- // and Add methods. If the add parameter is true and the given key already
- // exists in the hashtable, an exception is thrown.
- private void Insert(object key, object? nvalue, bool add)
- {
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
- }
-
- if (_count >= _loadsize)
- {
- expand();
- }
- else if (_occupancy > _loadsize && _count > 100)
- {
- rehash();
- }
-
- uint seed;
- uint incr;
- // Assume we only have one thread writing concurrently. Modify
- // buckets to contain new data, as long as we insert in the right order.
- uint hashcode = InitHash(key, _buckets.Length, out seed, out incr);
- int ntry = 0;
- int emptySlotNumber = -1; // We use the empty slot number to cache the first empty slot. We chose to reuse slots
- // create by remove that have the collision bit set over using up new slots.
- int bucketNumber = (int)(seed % (uint)_buckets.Length);
- do
- {
- // Set emptySlot number to current bucket if it is the first available bucket that we have seen
- // that once contained an entry and also has had a collision.
- // We need to search this entire collision chain because we have to ensure that there are no
- // duplicate entries in the table.
- if (emptySlotNumber == -1 && (_buckets[bucketNumber].key == _buckets) && (_buckets[bucketNumber].hash_coll < 0))// (((buckets[bucketNumber].hash_coll & unchecked(0x80000000))!=0)))
- emptySlotNumber = bucketNumber;
-
- // Insert the key/value pair into this bucket if this bucket is empty and has never contained an entry
- // OR
- // This bucket once contained an entry but there has never been a collision
- if ((_buckets[bucketNumber].key == null) ||
- (_buckets[bucketNumber].key == _buckets && ((_buckets[bucketNumber].hash_coll & unchecked(0x80000000)) == 0)))
- {
- // If we have found an available bucket that has never had a collision, but we've seen an available
- // bucket in the past that has the collision bit set, use the previous bucket instead
- if (emptySlotNumber != -1) // Reuse slot
- bucketNumber = emptySlotNumber;
-
- // We pretty much have to insert in this order. Don't set hash
- // code until the value & key are set appropriately.
- _isWriterInProgress = true;
- _buckets[bucketNumber].val = nvalue;
- _buckets[bucketNumber].key = key;
- _buckets[bucketNumber].hash_coll |= (int)hashcode;
- _count++;
- UpdateVersion();
- _isWriterInProgress = false;
-
- return;
- }
-
- // The current bucket is in use
- // OR
- // it is available, but has had the collision bit set and we have already found an available bucket
- if (((_buckets[bucketNumber].hash_coll & 0x7FFFFFFF) == hashcode) &&
- KeyEquals(_buckets[bucketNumber].key, key))
- {
- if (add)
- {
- throw new ArgumentException(SR.Format(SR.Argument_AddingDuplicate__, _buckets[bucketNumber].key, key));
- }
- _isWriterInProgress = true;
- _buckets[bucketNumber].val = nvalue;
- UpdateVersion();
- _isWriterInProgress = false;
-
- return;
- }
-
- // The current bucket is full, and we have therefore collided. We need to set the collision bit
- // unless we have remembered an available slot previously.
- if (emptySlotNumber == -1)
- {// We don't need to set the collision bit here since we already have an empty slot
- if (_buckets[bucketNumber].hash_coll >= 0)
- {
- _buckets[bucketNumber].hash_coll |= unchecked((int)0x80000000);
- _occupancy++;
- }
- }
-
- bucketNumber = (int)(((long)bucketNumber + incr) % (uint)_buckets.Length);
- } while (++ntry < _buckets.Length);
-
- // This code is here if and only if there were no buckets without a collision bit set in the entire table
- if (emptySlotNumber != -1)
- {
- // We pretty much have to insert in this order. Don't set hash
- // code until the value & key are set appropriately.
- _isWriterInProgress = true;
- _buckets[emptySlotNumber].val = nvalue;
- _buckets[emptySlotNumber].key = key;
- _buckets[emptySlotNumber].hash_coll |= (int)hashcode;
- _count++;
- UpdateVersion();
- _isWriterInProgress = false;
-
- return;
- }
-
- // If you see this assert, make sure load factor & count are reasonable.
- // Then verify that our double hash function (h2, described at top of file)
- // meets the requirements described above. You should never see this assert.
- Debug.Fail("hash table insert failed! Load factor too high, or our double hashing function is incorrect.");
- throw new InvalidOperationException(SR.InvalidOperation_HashInsertFailed);
- }
-
- private void putEntry(bucket[] newBuckets, object key, object? nvalue, int hashcode)
- {
- Debug.Assert(hashcode >= 0, "hashcode >= 0"); // make sure collision bit (sign bit) wasn't set.
-
- uint seed = (uint)hashcode;
- uint incr = unchecked((uint)(1 + ((seed * HashHelpers.HashPrime) % ((uint)newBuckets.Length - 1))));
- int bucketNumber = (int)(seed % (uint)newBuckets.Length);
- while (true)
- {
- if ((newBuckets[bucketNumber].key == null) || (newBuckets[bucketNumber].key == _buckets))
- {
- newBuckets[bucketNumber].val = nvalue;
- newBuckets[bucketNumber].key = key;
- newBuckets[bucketNumber].hash_coll |= hashcode;
- return;
- }
-
- if (newBuckets[bucketNumber].hash_coll >= 0)
- {
- newBuckets[bucketNumber].hash_coll |= unchecked((int)0x80000000);
- _occupancy++;
- }
- bucketNumber = (int)(((long)bucketNumber + incr) % (uint)newBuckets.Length);
- }
- }
-
- // Removes an entry from this hashtable. If an entry with the specified
- // key exists in the hashtable, it is removed. An ArgumentException is
- // thrown if the key is null.
- //
- public virtual void Remove(object key)
- {
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
- }
-
- Debug.Assert(!_isWriterInProgress, "Race condition detected in usages of Hashtable - multiple threads appear to be writing to a Hashtable instance simultaneously! Don't do that - use Hashtable.Synchronized.");
-
- uint seed;
- uint incr;
- // Assuming only one concurrent writer, write directly into buckets.
- uint hashcode = InitHash(key, _buckets.Length, out seed, out incr);
- int ntry = 0;
-
- bucket b;
- int bn = (int)(seed % (uint)_buckets.Length); // bucketNumber
- do
- {
- b = _buckets[bn];
- if (((b.hash_coll & 0x7FFFFFFF) == hashcode) &&
- KeyEquals(b.key, key))
- {
- _isWriterInProgress = true;
- // Clear hash_coll field, then key, then value
- _buckets[bn].hash_coll &= unchecked((int)0x80000000);
- if (_buckets[bn].hash_coll != 0)
- {
- _buckets[bn].key = _buckets;
- }
- else
- {
- _buckets[bn].key = null;
- }
- _buckets[bn].val = null; // Free object references sooner & simplify ContainsValue.
- _count--;
- UpdateVersion();
- _isWriterInProgress = false;
- return;
- }
- bn = (int)(((long)bn + incr) % (uint)_buckets.Length);
- } while (b.hash_coll < 0 && ++ntry < _buckets.Length);
- }
-
- // Returns the object to synchronize on for this hash table.
- public virtual object SyncRoot => this;
-
- // Returns the number of associations in this hashtable.
- //
- public virtual int Count => _count;
-
- // Returns a thread-safe wrapper for a Hashtable.
- //
- public static Hashtable Synchronized(Hashtable table)
- {
- if (table == null)
- throw new ArgumentNullException(nameof(table));
- return new SyncHashtable(table);
- }
-
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- // This is imperfect - it only works well if all other writes are
- // also using our synchronized wrapper. But it's still a good idea.
- lock (SyncRoot)
- {
- // This method hasn't been fully tweaked to be safe for a concurrent writer.
- int oldVersion = _version;
- info.AddValue(LoadFactorName, _loadFactor);
- info.AddValue(VersionName, _version);
-
- //
- // We need to maintain serialization compatibility with Everett and RTM.
- // If the comparer is null or a compatible comparer, serialize Hashtable
- // in a format that can be deserialized on Everett and RTM.
- //
- // Also, if the Hashtable is using randomized hashing, serialize the old
- // view of the _keycomparer so perevious frameworks don't see the new types
-#pragma warning disable 618
- IEqualityComparer? keyComparerForSerilization = _keycomparer;
-
- if (keyComparerForSerilization == null)
- {
- info.AddValue(ComparerName, null, typeof(IComparer));
- info.AddValue(HashCodeProviderName, null, typeof(IHashCodeProvider));
- }
- else if (keyComparerForSerilization is CompatibleComparer)
- {
- CompatibleComparer c = (keyComparerForSerilization as CompatibleComparer)!;
- info.AddValue(ComparerName, c.Comparer, typeof(IComparer));
- info.AddValue(HashCodeProviderName, c.HashCodeProvider, typeof(IHashCodeProvider));
- }
- else
- {
- info.AddValue(KeyComparerName, keyComparerForSerilization, typeof(IEqualityComparer));
- }
-#pragma warning restore 618
-
- info.AddValue(HashSizeName, _buckets.Length); // This is the length of the bucket array.
- object[] serKeys = new object[_count];
- object[] serValues = new object[_count];
- CopyKeys(serKeys, 0);
- CopyValues(serValues, 0);
- info.AddValue(KeysName, serKeys, typeof(object[]));
- info.AddValue(ValuesName, serValues, typeof(object[]));
-
- // Explicitly check to see if anyone changed the Hashtable while we
- // were serializing it. That's a race in their code.
- if (_version != oldVersion)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- }
- }
- }
-
- //
- // DeserializationEvent Listener
- //
- public virtual void OnDeserialization(object? sender)
- {
- if (_buckets != null)
- {
- // Somebody had a dependency on this hashtable and fixed us up before the ObjectManager got to it.
- return;
- }
-
- SerializationInfo? siInfo;
- HashHelpers.SerializationInfoTable.TryGetValue(this, out siInfo);
-
- if (siInfo == null)
- {
- throw new SerializationException(SR.Serialization_InvalidOnDeser);
- }
-
- int hashsize = 0;
- IComparer? c = null;
-
-#pragma warning disable 618
- IHashCodeProvider? hcp = null;
-#pragma warning restore 618
-
- object[]? serKeys = null;
- object?[]? serValues = null;
-
- SerializationInfoEnumerator enumerator = siInfo.GetEnumerator();
-
- while (enumerator.MoveNext())
- {
- switch (enumerator.Name)
- {
- case LoadFactorName:
- _loadFactor = siInfo.GetSingle(LoadFactorName);
- break;
- case HashSizeName:
- hashsize = siInfo.GetInt32(HashSizeName);
- break;
- case KeyComparerName:
- _keycomparer = (IEqualityComparer?)siInfo.GetValue(KeyComparerName, typeof(IEqualityComparer));
- break;
- case ComparerName:
- c = (IComparer?)siInfo.GetValue(ComparerName, typeof(IComparer));
- break;
- case HashCodeProviderName:
-#pragma warning disable 618
- hcp = (IHashCodeProvider?)siInfo.GetValue(HashCodeProviderName, typeof(IHashCodeProvider));
-#pragma warning restore 618
- break;
- case KeysName:
- serKeys = (object[]?)siInfo.GetValue(KeysName, typeof(object[]));
- break;
- case ValuesName:
- serValues = (object?[]?)siInfo.GetValue(ValuesName, typeof(object[]));
- break;
- }
- }
-
- _loadsize = (int)(_loadFactor * hashsize);
-
- // V1 object doesn't has _keycomparer field.
- if ((_keycomparer == null) && ((c != null) || (hcp != null)))
- {
- _keycomparer = new CompatibleComparer(hcp, c);
- }
-
- _buckets = new bucket[hashsize];
-
- if (serKeys == null)
- {
- throw new SerializationException(SR.Serialization_MissingKeys);
- }
- if (serValues == null)
- {
- throw new SerializationException(SR.Serialization_MissingValues);
- }
- if (serKeys.Length != serValues.Length)
- {
- throw new SerializationException(SR.Serialization_KeyValueDifferentSizes);
- }
- for (int i = 0; i < serKeys.Length; i++)
- {
- if (serKeys[i] == null)
- {
- throw new SerializationException(SR.Serialization_NullKey);
- }
- Insert(serKeys[i], serValues[i], true);
- }
-
- _version = siInfo.GetInt32(VersionName);
-
- HashHelpers.SerializationInfoTable.Remove(this);
- }
-
- // Implements a Collection for the keys of a hashtable. An instance of this
- // class is created by the GetKeys method of a hashtable.
- private class KeyCollection : ICollection
- {
- private readonly Hashtable _hashtable;
-
- internal KeyCollection(Hashtable hashtable)
- {
- _hashtable = hashtable;
- }
-
- public virtual void CopyTo(Array array, int arrayIndex)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
- if (array.Rank != 1)
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));
- if (arrayIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(arrayIndex), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - arrayIndex < _hashtable._count)
- throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
- _hashtable.CopyKeys(array, arrayIndex);
- }
-
- public virtual IEnumerator GetEnumerator()
- {
- return new HashtableEnumerator(_hashtable, HashtableEnumerator.Keys);
- }
-
- public virtual bool IsSynchronized => _hashtable.IsSynchronized;
-
- public virtual object SyncRoot => _hashtable.SyncRoot;
-
- public virtual int Count => _hashtable._count;
- }
-
- // Implements a Collection for the values of a hashtable. An instance of
- // this class is created by the GetValues method of a hashtable.
- private class ValueCollection : ICollection
- {
- private readonly Hashtable _hashtable;
-
- internal ValueCollection(Hashtable hashtable)
- {
- _hashtable = hashtable;
- }
-
- public virtual void CopyTo(Array array, int arrayIndex)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
- if (array.Rank != 1)
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));
- if (arrayIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(arrayIndex), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - arrayIndex < _hashtable._count)
- throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
- _hashtable.CopyValues(array, arrayIndex);
- }
-
- public virtual IEnumerator GetEnumerator()
- {
- return new HashtableEnumerator(_hashtable, HashtableEnumerator.Values);
- }
-
- public virtual bool IsSynchronized => _hashtable.IsSynchronized;
-
- public virtual object SyncRoot => _hashtable.SyncRoot;
-
- public virtual int Count => _hashtable._count;
- }
-
- // Synchronized wrapper for hashtable
- private class SyncHashtable : Hashtable, IEnumerable
- {
- protected Hashtable _table;
-
- internal SyncHashtable(Hashtable table) : base(false)
- {
- _table = table;
- }
-
- internal SyncHashtable(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- throw new PlatformNotSupportedException();
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- public override int Count => _table.Count;
-
- public override bool IsReadOnly => _table.IsReadOnly;
-
- public override bool IsFixedSize => _table.IsFixedSize;
-
- public override bool IsSynchronized => true;
-
- public override object? this[object key]
- {
- get => _table[key];
- set
- {
- lock (_table.SyncRoot)
- {
- _table[key] = value;
- }
- }
- }
-
- public override object SyncRoot => _table.SyncRoot;
-
- public override void Add(object key, object? value)
- {
- lock (_table.SyncRoot)
- {
- _table.Add(key, value);
- }
- }
-
- public override void Clear()
- {
- lock (_table.SyncRoot)
- {
- _table.Clear();
- }
- }
-
- public override bool Contains(object key)
- {
- return _table.Contains(key);
- }
-
- public override bool ContainsKey(object key)
- {
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
- }
- return _table.ContainsKey(key);
- }
-
- public override bool ContainsValue(object? key)
- {
- lock (_table.SyncRoot)
- {
- return _table.ContainsValue(key);
- }
- }
-
- public override void CopyTo(Array array, int arrayIndex)
- {
- lock (_table.SyncRoot)
- {
- _table.CopyTo(array, arrayIndex);
- }
- }
-
- public override object Clone()
- {
- lock (_table.SyncRoot)
- {
- return Hashtable.Synchronized((Hashtable)_table.Clone());
- }
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return _table.GetEnumerator();
- }
-
- public override IDictionaryEnumerator GetEnumerator()
- {
- return _table.GetEnumerator();
- }
-
- public override ICollection Keys
- {
- get
- {
- lock (_table.SyncRoot)
- {
- return _table.Keys;
- }
- }
- }
-
- public override ICollection Values
- {
- get
- {
- lock (_table.SyncRoot)
- {
- return _table.Values;
- }
- }
- }
-
- public override void Remove(object key)
- {
- lock (_table.SyncRoot)
- {
- _table.Remove(key);
- }
- }
-
- public override void OnDeserialization(object? sender)
- {
- // Does nothing. We have to implement this because our parent HT implements it,
- // but it doesn't do anything meaningful. The real work will be done when we
- // call OnDeserialization on our parent table.
- }
-
- internal override KeyValuePairs[] ToKeyValuePairsArray()
- {
- return _table.ToKeyValuePairsArray();
- }
- }
-
- // Implements an enumerator for a hashtable. The enumerator uses the
- // internal version number of the hashtable to ensure that no modifications
- // are made to the hashtable while an enumeration is in progress.
- private class HashtableEnumerator : IDictionaryEnumerator, ICloneable
- {
- private readonly Hashtable _hashtable;
- private int _bucket;
- private readonly int _version;
- private bool _current;
- private readonly int _getObjectRetType; // What should GetObject return?
- private object? _currentKey;
- private object? _currentValue;
-
- internal const int Keys = 1;
- internal const int Values = 2;
- internal const int DictEntry = 3;
-
- internal HashtableEnumerator(Hashtable hashtable, int getObjRetType)
- {
- _hashtable = hashtable;
- _bucket = hashtable._buckets.Length;
- _version = hashtable._version;
- _current = false;
- _getObjectRetType = getObjRetType;
- }
-
- public object Clone() => MemberwiseClone();
-
- public virtual object Key
- {
- get
- {
- if (!_current)
- throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted);
- return _currentKey!;
- }
- }
-
- public virtual bool MoveNext()
- {
- if (_version != _hashtable._version)
- throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- while (_bucket > 0)
- {
- _bucket--;
- object? keyv = _hashtable._buckets[_bucket].key;
- if ((keyv != null) && (keyv != _hashtable._buckets))
- {
- _currentKey = keyv;
- _currentValue = _hashtable._buckets[_bucket].val;
- _current = true;
- return true;
- }
- }
- _current = false;
- return false;
- }
-
- public virtual DictionaryEntry Entry
- {
- get
- {
- if (!_current)
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
- return new DictionaryEntry(_currentKey!, _currentValue);
- }
- }
-
- public virtual object? Current
- {
- get
- {
- if (!_current)
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
-
- if (_getObjectRetType == Keys)
- return _currentKey;
- else if (_getObjectRetType == Values)
- return _currentValue;
- else
- return new DictionaryEntry(_currentKey!, _currentValue);
- }
- }
-
- public virtual object? Value
- {
- get
- {
- if (!_current)
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
- return _currentValue;
- }
- }
-
- public virtual void Reset()
- {
- if (_version != _hashtable._version)
- throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- _current = false;
- _bucket = _hashtable._buckets.Length;
- _currentKey = null;
- _currentValue = null;
- }
- }
-
- // internal debug view class for hashtable
- internal class HashtableDebugView
- {
- private readonly Hashtable _hashtable;
-
- public HashtableDebugView(Hashtable hashtable)
- {
- if (hashtable == null)
- {
- throw new ArgumentNullException(nameof(hashtable));
- }
-
- _hashtable = hashtable;
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public KeyValuePairs[] Items => _hashtable.ToKeyValuePairsArray();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/ICollection.cs b/netcore/System.Private.CoreLib/shared/System/Collections/ICollection.cs
deleted file mode 100644
index 814e0eeffa9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/ICollection.cs
+++ /dev/null
@@ -1,67 +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.
-
-namespace System.Collections
-{
- // Base interface for all collections, defining enumerators, size, and
- // synchronization methods.
- public interface ICollection : IEnumerable
- {
- // Interfaces are not serializable
- // CopyTo copies a collection into an Array, starting at a particular
- // index into the array.
- //
- void CopyTo(Array array, int index);
-
- // Number of items in the collections.
- int Count
- { get; }
-
-
- // SyncRoot will return an Object to use for synchronization
- // (thread safety). You can use this object in your code to take a
- // lock on the collection, even if this collection is a wrapper around
- // another collection. The intent is to tunnel through to a real
- // implementation of a collection, and use one of the internal objects
- // found in that code.
- //
- // In the absence of a static Synchronized method on a collection,
- // the expected usage for SyncRoot would look like this:
- //
- // ICollection col = ...
- // lock (col.SyncRoot) {
- // // Some operation on the collection, which is now thread safe.
- // // This may include multiple operations.
- // }
- //
- //
- // The system-provided collections have a static method called
- // Synchronized which will create a thread-safe wrapper around the
- // collection. All access to the collection that you want to be
- // thread-safe should go through that wrapper collection. However, if
- // you need to do multiple calls on that collection (such as retrieving
- // two items, or checking the count then doing something), you should
- // NOT use our thread-safe wrapper since it only takes a lock for the
- // duration of a single method call. Instead, use Monitor.Enter/Exit
- // or your language's equivalent to the C# lock keyword as mentioned
- // above.
- //
- // For collections with no publicly available underlying store, the
- // expected implementation is to simply return the this pointer. Note
- // that the this pointer may not be sufficient for collections that
- // wrap other collections; those should return the underlying
- // collection's SyncRoot property.
- object SyncRoot
- { get; }
-
- // Is this collection synchronized (i.e., thread-safe)? If you want a
- // thread-safe collection, you can use SyncRoot as an object to
- // synchronize your collection with. If you're using one of the
- // collections in System.Collections, you could call the static
- // Synchronized method to get a thread-safe wrapper around the
- // underlying collection.
- bool IsSynchronized
- { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/IComparer.cs b/netcore/System.Private.CoreLib/shared/System/Collections/IComparer.cs
deleted file mode 100644
index c5fddbb93a2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/IComparer.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Collections
-{
- // The IComparer interface implements a method that compares two objects. It is
- // used in conjunction with the Sort and BinarySearch methods on
- // the Array and List classes.
- //
- // Interfaces are not serializable
- public interface IComparer
- {
- // Compares two objects. An implementation of this method must return a
- // value less than zero if x is less than y, zero if x is equal to y, or a
- // value greater than zero if x is greater than y.
- //
- int Compare(object? x, object? y);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/IDictionary.cs b/netcore/System.Private.CoreLib/shared/System/Collections/IDictionary.cs
deleted file mode 100644
index bf5bb1a81b7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/IDictionary.cs
+++ /dev/null
@@ -1,47 +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.
-
-namespace System.Collections
-{
- // An IDictionary is a possibly unordered set of key-value pairs.
- // Keys can be any non-null object. Values can be any object.
- // You can look up a value in an IDictionary via the default indexed
- // property, Items.
- public interface IDictionary : ICollection
- {
- // Interfaces are not serializable
- // The Item property provides methods to read and edit entries
- // in the Dictionary.
- object? this[object key]
- {
- get;
- set;
- }
-
- // Returns a collections of the keys in this dictionary.
- ICollection Keys { get; }
-
- // Returns a collections of the values in this dictionary.
- ICollection Values { get; }
-
- // Returns whether this dictionary contains a particular key.
- bool Contains(object key);
-
- // Adds a key-value pair to the dictionary.
- void Add(object key, object? value);
-
- // Removes all pairs from the dictionary.
- void Clear();
-
- bool IsReadOnly { get; }
-
- bool IsFixedSize { get; }
-
- // Returns an IDictionaryEnumerator for this dictionary.
- new IDictionaryEnumerator GetEnumerator();
-
- // Removes a particular key from the dictionary.
- void Remove(object key);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/IDictionaryEnumerator.cs b/netcore/System.Private.CoreLib/shared/System/Collections/IDictionaryEnumerator.cs
deleted file mode 100644
index 7a590246ac8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/IDictionaryEnumerator.cs
+++ /dev/null
@@ -1,68 +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.
-
-namespace System.Collections
-{
- // This interface represents an enumerator that allows sequential access to the
- // elements of a dictionary. Upon creation, an enumerator is conceptually
- // positioned before the first element of the enumeration. The first call to the
- // MoveNext method brings the first element of the enumeration into view,
- // and each successive call to MoveNext brings the next element into
- // view until MoveNext returns false, indicating that there are no more
- // elements to enumerate. Following each call to MoveNext, the
- // Key and Value methods are used to obtain the key and
- // value of the element currently in view. The values returned by calls to
- // Key and Value are undefined before the first call to
- // MoveNext and following a call to MoveNext that returned false.
- // Enumerators are typically used in while loops of the form
- //
- // IDictionaryEnumerator e = ...;
- // while (e.MoveNext()) {
- // Object key = e.Key;
- // Object value = e.Value;
- // ...
- // }
- //
- // The IDictionaryEnumerator interface extends the IEnumerator
- // inerface and can thus be used as a regular enumerator. The Current
- // method of an IDictionaryEnumerator returns a DictionaryEntry containing
- // the current key and value pair. However, the GetEntry method will
- // return the same DictionaryEntry and avoids boxing the DictionaryEntry (boxing
- // is somewhat expensive).
- //
- public interface IDictionaryEnumerator : IEnumerator
- {
- // Returns the key of the current element of the enumeration. The returned
- // value is undefined before the first call to GetNext and following
- // a call to GetNext that returned false. Multiple calls to
- // GetKey with no intervening calls to GetNext will return
- // the same object.
- //
- object Key
- {
- get;
- }
-
- // Returns the value of the current element of the enumeration. The
- // returned value is undefined before the first call to GetNext and
- // following a call to GetNext that returned false. Multiple calls
- // to GetValue with no intervening calls to GetNext will
- // return the same object.
- //
- object? Value
- {
- get;
- }
-
- // GetBlock will copy dictionary values into the given Array. It will either
- // fill up the array, or if there aren't enough elements, it will
- // copy as much as possible into the Array. The number of elements
- // copied is returned.
- //
- DictionaryEntry Entry
- {
- get;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/IEnumerable.cs b/netcore/System.Private.CoreLib/shared/System/Collections/IEnumerable.cs
deleted file mode 100644
index e3b74317320..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/IEnumerable.cs
+++ /dev/null
@@ -1,17 +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 System.Runtime.InteropServices;
-
-namespace System.Collections
-{
- [Guid("496B0ABE-CDEE-11d3-88E8-00902754C43A")]
- [ComVisible(true)]
- public interface IEnumerable
- {
- // Returns an IEnumerator for this enumerable Object. The enumerator provides
- // a simple way to access all the contents of a collection.
- IEnumerator GetEnumerator();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/IEnumerator.cs b/netcore/System.Private.CoreLib/shared/System/Collections/IEnumerator.cs
deleted file mode 100644
index cce1fa9c65e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/IEnumerator.cs
+++ /dev/null
@@ -1,38 +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.
-
-namespace System.Collections
-{
- // Base interface for all enumerators, providing a simple approach
- // to iterating over a collection.
- public interface IEnumerator
- {
- // Advances the enumerator to the next element of the enumeration and
- // returns a boolean indicating whether an element is available. Upon
- // creation, an enumerator is conceptually positioned before the first
- // element of the enumeration, and the first call to MoveNext
- // brings the first element of the enumeration into view.
- //
- bool MoveNext();
-
- // Returns the current element of the enumeration. The returned value is
- // undefined before the first call to MoveNext and following a
- // call to MoveNext that returned false. Multiple calls to
- // GetCurrent with no intervening calls to MoveNext
- // will return the same object.
- //
- object? Current
- {
- get;
- }
-
- // Resets the enumerator to the beginning of the enumeration, starting over.
- // The preferred behavior for Reset is to return the exact same enumeration.
- // This means if you modify the underlying collection then call Reset, your
- // IEnumerator will be invalid, just as it would have been if you had called
- // MoveNext or Current.
- //
- void Reset();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/IEqualityComparer.cs b/netcore/System.Private.CoreLib/shared/System/Collections/IEqualityComparer.cs
deleted file mode 100644
index cc60060279d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/IEqualityComparer.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Collections
-{
- // An IEqualityComparer is a mechanism to consume custom performant comparison infrastructure
- // that can be consumed by some of the common collections.
- public interface IEqualityComparer
- {
- bool Equals(object? x, object? y);
- int GetHashCode(object obj);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/IHashCodeProvider.cs b/netcore/System.Private.CoreLib/shared/System/Collections/IHashCodeProvider.cs
deleted file mode 100644
index 7d6c63f9f1d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/IHashCodeProvider.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Collections
-{
- /// <summary>
- /// Provides a mechanism for a <see cref="Hashtable"/> user to override the default
- /// GetHashCode() function on Objects, providing their own hash function.
- /// </summary>
- [Obsolete("Please use IEqualityComparer instead.")]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public interface IHashCodeProvider
- {
- /// <summary>Returns a hash code for the given object.</summary>
- int GetHashCode(object obj);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/IList.cs b/netcore/System.Private.CoreLib/shared/System/Collections/IList.cs
deleted file mode 100644
index a6b7e5a2aea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/IList.cs
+++ /dev/null
@@ -1,57 +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.
-
-namespace System.Collections
-{
- // An IList is an ordered collection of objects. The exact ordering
- // is up to the implementation of the list, ranging from a sorted
- // order to insertion order.
- public interface IList : ICollection
- {
- // The Item property provides methods to read and edit entries in the List.
- object? this[int index]
- {
- get;
- set;
- }
-
- // Adds an item to the list. The exact position in the list is
- // implementation-dependent, so while ArrayList may always insert
- // in the last available location, a SortedList most likely would not.
- // The return value is the position the new element was inserted in.
- int Add(object? value);
-
- // Returns whether the list contains a particular item.
- bool Contains(object? value);
-
- // Removes all items from the list.
- void Clear();
-
- bool IsReadOnly
- { get; }
-
-
- bool IsFixedSize
- {
- get;
- }
-
-
- // Returns the index of a particular item, if it is in the list.
- // Returns -1 if the item isn't in the list.
- int IndexOf(object? value);
-
- // Inserts value into the list at position index.
- // index must be non-negative and less than or equal to the
- // number of elements in the list. If index equals the number
- // of items in the list, then value is appended to the end.
- void Insert(int index, object? value);
-
- // Removes an item from the list.
- void Remove(object? value);
-
- // Removes the item at position index.
- void RemoveAt(int index);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/IStructuralComparable.cs b/netcore/System.Private.CoreLib/shared/System/Collections/IStructuralComparable.cs
deleted file mode 100644
index b1bb10e919e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/IStructuralComparable.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Collections
-{
- public interface IStructuralComparable
- {
- int CompareTo(object? other, IComparer comparer);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/IStructuralEquatable.cs b/netcore/System.Private.CoreLib/shared/System/Collections/IStructuralEquatable.cs
deleted file mode 100644
index a244e8417a5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/IStructuralEquatable.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Collections
-{
- public interface IStructuralEquatable
- {
- bool Equals(object? other, IEqualityComparer comparer);
- int GetHashCode(IEqualityComparer comparer);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/KeyValuePairs.cs b/netcore/System.Private.CoreLib/shared/System/Collections/KeyValuePairs.cs
deleted file mode 100644
index 4bbca18c54a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/KeyValuePairs.cs
+++ /dev/null
@@ -1,34 +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.
-
-/*============================================================
-**
-** Class: KeyValuePairs
-**
-** Purpose: Defines key/value pairs for displaying items
-** in a collection class under the debugger.
-**
-===========================================================*/
-
-#nullable enable
-using System.Diagnostics;
-
-namespace System.Collections
-{
- [DebuggerDisplay("{_value}", Name = "[{_key}]")]
- internal class KeyValuePairs
- {
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- private readonly object _key;
-
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- private readonly object? _value;
-
- public KeyValuePairs(object key, object? value)
- {
- _value = value;
- _key = key;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/ListDictionaryInternal.cs b/netcore/System.Private.CoreLib/shared/System/Collections/ListDictionaryInternal.cs
deleted file mode 100644
index fab72af425e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/ListDictionaryInternal.cs
+++ /dev/null
@@ -1,437 +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.
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: List for exceptions.
-**
-**
-===========================================================*/
-
-namespace System.Collections
-{
- /// This is a simple implementation of IDictionary using a singly linked list. This
- /// will be smaller and faster than a Hashtable if the number of elements is 10 or less.
- /// This should not be used if performance is important for large numbers of elements.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- // Needs to be public to support binary serialization compatibility
- public class ListDictionaryInternal : IDictionary
- {
- private DictionaryNode? head; // Do not rename (binary serialization)
- private int version; // Do not rename (binary serialization)
- private int count; // Do not rename (binary serialization)
-
- public ListDictionaryInternal()
- {
- }
-
- public object? this[object key]
- {
- get
- {
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
- }
- DictionaryNode? node = head;
-
- while (node != null)
- {
- if (node.key.Equals(key))
- {
- return node.value;
- }
- node = node.next;
- }
- return null;
- }
- set
- {
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
- }
-
- version++;
- DictionaryNode? last = null;
- DictionaryNode? node;
- for (node = head; node != null; node = node.next)
- {
- if (node.key.Equals(key))
- {
- break;
- }
- last = node;
- }
- if (node != null)
- {
- // Found it
- node.value = value;
- return;
- }
- // Not found, so add a new one
- DictionaryNode newNode = new DictionaryNode();
- newNode.key = key;
- newNode.value = value;
- if (last != null)
- {
- last.next = newNode;
- }
- else
- {
- head = newNode;
- }
- count++;
- }
- }
-
- public int Count => count;
-
- public ICollection Keys => new NodeKeyValueCollection(this, true);
-
- public bool IsReadOnly => false;
-
- public bool IsFixedSize => false;
-
- public bool IsSynchronized => false;
-
- public object SyncRoot => this;
-
- public ICollection Values => new NodeKeyValueCollection(this, false);
-
- public void Add(object key, object? value)
- {
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
- }
-
- version++;
- DictionaryNode? last = null;
- DictionaryNode? node;
- for (node = head; node != null; node = node.next)
- {
- if (node.key.Equals(key))
- {
- throw new ArgumentException(SR.Format(SR.Argument_AddingDuplicate__, node.key, key));
- }
- last = node;
- }
- if (node != null)
- {
- // Found it
- node.value = value;
- return;
- }
- // Not found, so add a new one
- DictionaryNode newNode = new DictionaryNode();
- newNode.key = key;
- newNode.value = value;
- if (last != null)
- {
- last.next = newNode;
- }
- else
- {
- head = newNode;
- }
- count++;
- }
-
- public void Clear()
- {
- count = 0;
- head = null;
- version++;
- }
-
- public bool Contains(object key)
- {
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
- }
- for (DictionaryNode? node = head; node != null; node = node.next)
- {
- if (node.key.Equals(key))
- {
- return true;
- }
- }
- return false;
- }
-
- public void CopyTo(Array array, int index)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
-
- if (array.Rank != 1)
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported);
-
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (array.Length - index < this.Count)
- throw new ArgumentException(SR.ArgumentOutOfRange_Index, nameof(index));
-
- for (DictionaryNode? node = head; node != null; node = node.next)
- {
- array.SetValue(new DictionaryEntry(node.key, node.value), index);
- index++;
- }
- }
-
- public IDictionaryEnumerator GetEnumerator()
- {
- return new NodeEnumerator(this);
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return new NodeEnumerator(this);
- }
-
- public void Remove(object key)
- {
- if (key == null)
- {
- throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
- }
- version++;
- DictionaryNode? last = null;
- DictionaryNode? node;
- for (node = head; node != null; node = node.next)
- {
- if (node.key.Equals(key))
- {
- break;
- }
- last = node;
- }
- if (node == null)
- {
- return;
- }
- if (node == head)
- {
- head = node.next;
- }
- else
- {
- last!.next = node.next;
- }
- count--;
- }
-
- private class NodeEnumerator : IDictionaryEnumerator
- {
- private readonly ListDictionaryInternal list;
- private DictionaryNode? current;
- private readonly int version;
- private bool start;
-
- public NodeEnumerator(ListDictionaryInternal list)
- {
- this.list = list;
- version = list.version;
- start = true;
- current = null;
- }
-
- public object Current => Entry;
-
- public DictionaryEntry Entry
- {
- get
- {
- if (current == null)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
- }
- return new DictionaryEntry(current.key, current.value);
- }
- }
-
- public object Key
- {
- get
- {
- if (current == null)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
- }
- return current.key;
- }
- }
-
- public object? Value
- {
- get
- {
- if (current == null)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
- }
- return current.value;
- }
- }
-
- public bool MoveNext()
- {
- if (version != list.version)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- }
- if (start)
- {
- current = list.head;
- start = false;
- }
- else
- {
- if (current != null)
- {
- current = current.next;
- }
- }
- return current != null;
- }
-
- public void Reset()
- {
- if (version != list.version)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- }
- start = true;
- current = null;
- }
- }
-
- private class NodeKeyValueCollection : ICollection
- {
- private readonly ListDictionaryInternal list;
- private readonly bool isKeys;
-
- public NodeKeyValueCollection(ListDictionaryInternal list, bool isKeys)
- {
- this.list = list;
- this.isKeys = isKeys;
- }
-
- void ICollection.CopyTo(Array array, int index)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
- if (array.Rank != 1)
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported);
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - index < list.Count)
- throw new ArgumentException(SR.ArgumentOutOfRange_Index, nameof(index));
- for (DictionaryNode? node = list.head; node != null; node = node.next)
- {
- array.SetValue(isKeys ? node.key : node.value, index);
- index++;
- }
- }
-
- int ICollection.Count
- {
- get
- {
- int count = 0;
- for (DictionaryNode? node = list.head; node != null; node = node.next)
- {
- count++;
- }
- return count;
- }
- }
-
- bool ICollection.IsSynchronized => false;
-
- object ICollection.SyncRoot => list.SyncRoot;
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return new NodeKeyValueEnumerator(list, isKeys);
- }
-
- private class NodeKeyValueEnumerator : IEnumerator
- {
- private readonly ListDictionaryInternal list;
- private DictionaryNode? current;
- private readonly int version;
- private readonly bool isKeys;
- private bool start;
-
- public NodeKeyValueEnumerator(ListDictionaryInternal list, bool isKeys)
- {
- this.list = list;
- this.isKeys = isKeys;
- version = list.version;
- start = true;
- current = null;
- }
-
- public object? Current
- {
- get
- {
- if (current == null)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
- }
- return isKeys ? current.key : current.value;
- }
- }
-
- public bool MoveNext()
- {
- if (version != list.version)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- }
- if (start)
- {
- current = list.head;
- start = false;
- }
- else
- {
- if (current != null)
- {
- current = current.next;
- }
- }
- return current != null;
- }
-
- public void Reset()
- {
- if (version != list.version)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- }
- start = true;
- current = null;
- }
- }
- }
-
- [Serializable]
- private class DictionaryNode
- {
- public object key = null!;
- public object? value;
- public DictionaryNode? next;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs b/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs
deleted file mode 100644
index 11a45cf0bb5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs
+++ /dev/null
@@ -1,365 +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 System.Collections.Generic;
-using System.Diagnostics;
-
-namespace System.Collections.ObjectModel
-{
- [Serializable]
- [DebuggerTypeProxy(typeof(ICollectionDebugView<>))]
- [DebuggerDisplay("Count = {Count}")]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Collection<T> : IList<T>, IList, IReadOnlyList<T>
- {
- private readonly IList<T> items; // Do not rename (binary serialization)
-
- public Collection()
- {
- items = new List<T>();
- }
-
- public Collection(IList<T> list)
- {
- if (list == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list);
- }
- items = list;
- }
-
- public int Count => items.Count;
-
- protected IList<T> Items => items;
-
- public T this[int index]
- {
- get => items[index];
- set
- {
- if (items.IsReadOnly)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- if ((uint)index >= (uint)items.Count)
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
-
- SetItem(index, value);
- }
- }
-
- public void Add(T item)
- {
- if (items.IsReadOnly)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- int index = items.Count;
- InsertItem(index, item);
- }
-
- public void Clear()
- {
- if (items.IsReadOnly)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- ClearItems();
- }
-
- public void CopyTo(T[] array, int index)
- {
- items.CopyTo(array, index);
- }
-
- public bool Contains(T item)
- {
- return items.Contains(item);
- }
-
- public IEnumerator<T> GetEnumerator()
- {
- return items.GetEnumerator();
- }
-
- public int IndexOf(T item)
- {
- return items.IndexOf(item);
- }
-
- public void Insert(int index, T item)
- {
- if (items.IsReadOnly)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- if ((uint)index > (uint)items.Count)
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
-
- InsertItem(index, item);
- }
-
- public bool Remove(T item)
- {
- if (items.IsReadOnly)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- int index = items.IndexOf(item);
- if (index < 0) return false;
- RemoveItem(index);
- return true;
- }
-
- public void RemoveAt(int index)
- {
- if (items.IsReadOnly)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- if ((uint)index >= (uint)items.Count)
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
-
- RemoveItem(index);
- }
-
- protected virtual void ClearItems()
- {
- items.Clear();
- }
-
- protected virtual void InsertItem(int index, T item)
- {
- items.Insert(index, item);
- }
-
- protected virtual void RemoveItem(int index)
- {
- items.RemoveAt(index);
- }
-
- protected virtual void SetItem(int index, T item)
- {
- items[index] = item;
- }
-
- bool ICollection<T>.IsReadOnly => items.IsReadOnly;
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return ((IEnumerable)items).GetEnumerator();
- }
-
- bool ICollection.IsSynchronized => false;
-
- object ICollection.SyncRoot => items is ICollection coll ? coll.SyncRoot : this;
-
- void ICollection.CopyTo(Array array, int index)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (array.Rank != 1)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
- }
-
- if (array.GetLowerBound(0) != 0)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
- }
-
- if (index < 0)
- {
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- }
-
- if (array.Length - index < Count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
- }
-
- if (array is T[] tArray)
- {
- items.CopyTo(tArray, index);
- }
- else
- {
- //
- // Catch the obvious case assignment will fail.
- // We can't find all possible problems by doing the check though.
- // For example, if the element type of the Array is derived from T,
- // we can't figure out if we can successfully copy the element beforehand.
- //
- Type targetType = array.GetType().GetElementType()!;
- Type sourceType = typeof(T);
- if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType)))
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
-
- //
- // We can't cast array of value type to object[], so we don't support
- // widening of primitive types here.
- //
- object?[]? objects = array as object[];
- if (objects == null)
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
-
- int count = items.Count;
- try
- {
- for (int i = 0; i < count; i++)
- {
- objects[index++] = items[i];
- }
- }
- catch (ArrayTypeMismatchException)
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
- }
- }
-
- object? IList.this[int index]
- {
- get => items[index];
- set
- {
- ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
-
- T item = default!;
-
- try
- {
- item = (T)value!;
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
- }
-
- this[index] = item;
- }
- }
-
- bool IList.IsReadOnly => items.IsReadOnly;
-
- bool IList.IsFixedSize
- {
- get
- {
- // There is no IList<T>.IsFixedSize, so we must assume that only
- // 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.
- if (items is IList list)
- {
- return list.IsFixedSize;
- }
- return items.IsReadOnly;
- }
- }
-
- int IList.Add(object? value)
- {
- if (items.IsReadOnly)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
- ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
-
- T item = default!;
-
- try
- {
- item = (T)value!;
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
- }
-
- Add(item);
-
- return this.Count - 1;
- }
-
- bool IList.Contains(object? value)
- {
- if (IsCompatibleObject(value))
- {
- return Contains((T)value!);
- }
- return false;
- }
-
- int IList.IndexOf(object? value)
- {
- if (IsCompatibleObject(value))
- {
- return IndexOf((T)value!);
- }
- return -1;
- }
-
- void IList.Insert(int index, object? value)
- {
- if (items.IsReadOnly)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
- ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
-
- T item = default!;
-
- try
- {
- item = (T)value!;
- }
- catch (InvalidCastException)
- {
- ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
- }
-
- Insert(index, item);
- }
-
- void IList.Remove(object? value)
- {
- if (items.IsReadOnly)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- if (IsCompatibleObject(value))
- {
- Remove((T)value!);
- }
- }
-
- private static bool IsCompatibleObject(object? value)
- {
- // Non-null values are fine. Only accept nulls if T is a class or Nullable<U>.
- // Note that default(T) is not equal to null for value types except when T is Nullable<U>.
- return (value is T) || (value == null && default(T)! == null);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs b/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs
deleted file mode 100644
index 850b72d1c61..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs
+++ /dev/null
@@ -1,228 +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 System.Collections.Generic;
-using System.Diagnostics;
-
-namespace System.Collections.ObjectModel
-{
- [Serializable]
- [DebuggerTypeProxy(typeof(ICollectionDebugView<>))]
- [DebuggerDisplay("Count = {Count}")]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ReadOnlyCollection<T> : IList<T>, IList, IReadOnlyList<T>
- {
- private readonly IList<T> list; // Do not rename (binary serialization)
-
- public ReadOnlyCollection(IList<T> list)
- {
- if (list == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list);
- }
- this.list = list;
- }
-
- public int Count => list.Count;
-
- public T this[int index] => list[index];
-
- public bool Contains(T value)
- {
- return list.Contains(value);
- }
-
- public void CopyTo(T[] array, int index)
- {
- list.CopyTo(array, index);
- }
-
- public IEnumerator<T> GetEnumerator()
- {
- return list.GetEnumerator();
- }
-
- public int IndexOf(T value)
- {
- return list.IndexOf(value);
- }
-
- protected IList<T> Items => list;
-
- bool ICollection<T>.IsReadOnly => true;
-
- T IList<T>.this[int index]
- {
- get => list[index];
- set => ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- void ICollection<T>.Add(T value)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- void ICollection<T>.Clear()
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- void IList<T>.Insert(int index, T value)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- bool ICollection<T>.Remove(T value)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- return false;
- }
-
- void IList<T>.RemoveAt(int index)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return ((IEnumerable)list).GetEnumerator();
- }
-
- bool ICollection.IsSynchronized => false;
-
- object ICollection.SyncRoot => list is ICollection coll ? coll.SyncRoot : this;
-
- void ICollection.CopyTo(Array array, int index)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- if (array.Rank != 1)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
- }
-
- if (array.GetLowerBound(0) != 0)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
- }
-
- if (index < 0)
- {
- ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
- }
-
- if (array.Length - index < Count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
- }
-
- if (array is T[] items)
- {
- list.CopyTo(items, index);
- }
- else
- {
- //
- // Catch the obvious case assignment will fail.
- // We can't find all possible problems by doing the check though.
- // For example, if the element type of the Array is derived from T,
- // we can't figure out if we can successfully copy the element beforehand.
- //
- Type targetType = array.GetType().GetElementType()!;
- Type sourceType = typeof(T);
- if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType)))
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
-
- //
- // We can't cast array of value type to object[], so we don't support
- // widening of primitive types here.
- //
- object?[]? objects = array as object[];
- if (objects == null)
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
-
- int count = list.Count;
- try
- {
- for (int i = 0; i < count; i++)
- {
- objects[index++] = list[i];
- }
- }
- catch (ArrayTypeMismatchException)
- {
- ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
- }
- }
- }
-
- bool IList.IsFixedSize => true;
-
- bool IList.IsReadOnly => true;
-
- object? IList.this[int index]
- {
- get => list[index];
- set => ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- int IList.Add(object? value)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- return -1;
- }
-
- void IList.Clear()
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- private static bool IsCompatibleObject(object? value)
- {
- // Non-null values are fine. Only accept nulls if T is a class or Nullable<U>.
- // Note that default(T) is not equal to null for value types except when T is Nullable<U>.
- return (value is T) || (value == null && default(T)! == null);
- }
-
- bool IList.Contains(object? value)
- {
- if (IsCompatibleObject(value))
- {
- return Contains((T)value!);
- }
- return false;
- }
-
- int IList.IndexOf(object? value)
- {
- if (IsCompatibleObject(value))
- {
- return IndexOf((T)value!);
- }
- return -1;
- }
-
- void IList.Insert(int index, object? value)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- void IList.Remove(object? value)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- void IList.RemoveAt(int index)
- {
- ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs b/netcore/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs
deleted file mode 100644
index b15719bbb87..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ComponentModel/DefaultValueAttribute.cs
+++ /dev/null
@@ -1,250 +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 System.Globalization;
-using System.Reflection;
-using System.Threading;
-
-namespace System.ComponentModel
-{
- /// <summary>
- /// Specifies the default value for a property.
- /// </summary>
- [AttributeUsage(AttributeTargets.All)]
- public class DefaultValueAttribute : Attribute
- {
- /// <summary>
- /// This is the default value.
- /// </summary>
- private object? _value;
-
- // Delegate ad hoc created 'TypeDescriptor.ConvertFromInvariantString' reflection object cache
- private static object? s_convertFromInvariantString;
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class, converting the specified value to the specified type, and using the U.S. English
- /// culture as the translation context.
- /// </summary>
- public DefaultValueAttribute(Type type, string? value)
- {
- // The null check and try/catch here are because attributes should never throw exceptions.
- // We would fail to load an otherwise normal class.
-
- if (type == null)
- {
- return;
- }
-
- try
- {
- if (TryConvertFromInvariantString(type, value, out object? convertedValue))
- {
- _value = convertedValue;
- }
- else if (type.IsSubclassOf(typeof(Enum)) && value != null)
- {
- _value = Enum.Parse(type, value, true);
- }
- else if (type == typeof(TimeSpan) && value != null)
- {
- _value = TimeSpan.Parse(value);
- }
- else
- {
- _value = Convert.ChangeType(value, type, CultureInfo.InvariantCulture);
- }
-
- // Looking for ad hoc created TypeDescriptor.ConvertFromInvariantString(Type, string)
- static bool TryConvertFromInvariantString(Type? typeToConvert, string? stringValue, out object? conversionResult)
- {
- conversionResult = null;
-
- // lazy init reflection objects
- if (s_convertFromInvariantString == null)
- {
- Type? typeDescriptorType = Type.GetType("System.ComponentModel.TypeDescriptor, System.ComponentModel.TypeConverter", throwOnError: false);
- MethodInfo? mi = typeDescriptorType?.GetMethod("ConvertFromInvariantString", BindingFlags.NonPublic | BindingFlags.Static);
- Volatile.Write(ref s_convertFromInvariantString, mi == null ? new object() : mi.CreateDelegate(typeof(Func<Type, string, object>)));
- }
-
- if (!(s_convertFromInvariantString is Func<Type?, string?, object> convertFromInvariantString))
- return false;
-
- try
- {
- conversionResult = convertFromInvariantString(typeToConvert, stringValue);
- }
- catch
- {
- return false;
- }
-
- return true;
- }
- }
- catch
- {
- }
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a Unicode character.
- /// </summary>
- public DefaultValueAttribute(char value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using an 8-bit unsigned integer.
- /// </summary>
- public DefaultValueAttribute(byte value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a 16-bit signed integer.
- /// </summary>
- public DefaultValueAttribute(short value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a 32-bit signed integer.
- /// </summary>
- public DefaultValueAttribute(int value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a 64-bit signed integer.
- /// </summary>
- public DefaultValueAttribute(long value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a single-precision floating point number.
- /// </summary>
- public DefaultValueAttribute(float value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a double-precision floating point number.
- /// </summary>
- public DefaultValueAttribute(double value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a <see cref='bool'/> value.
- /// </summary>
- public DefaultValueAttribute(bool value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a <see cref='string'/>.
- /// </summary>
- public DefaultValueAttribute(string? value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class.
- /// </summary>
- public DefaultValueAttribute(object? value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a <see cref='sbyte'/> value.
- /// </summary>
- [CLSCompliant(false)]
- public DefaultValueAttribute(sbyte value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a <see cref='ushort'/> value.
- /// </summary>
- [CLSCompliant(false)]
- public DefaultValueAttribute(ushort value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a <see cref='uint'/> value.
- /// </summary>
- [CLSCompliant(false)]
- public DefaultValueAttribute(uint value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref='System.ComponentModel.DefaultValueAttribute'/>
- /// class using a <see cref='ulong'/> value.
- /// </summary>
- [CLSCompliant(false)]
- public DefaultValueAttribute(ulong value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Gets the default value of the property this attribute is bound to.
- /// </summary>
- public virtual object? Value => _value;
-
- public override bool Equals(object? obj)
- {
- if (obj == this)
- {
- return true;
- }
- if (!(obj is DefaultValueAttribute other))
- {
- return false;
- }
-
- if (Value == null)
- {
- return other.Value == null;
- }
-
- return Value.Equals(other.Value);
- }
-
- public override int GetHashCode() => base.GetHashCode();
-
- protected void SetValue(object? value) => _value = value;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ComponentModel/EditorBrowsableAttribute.cs b/netcore/System.Private.CoreLib/shared/System/ComponentModel/EditorBrowsableAttribute.cs
deleted file mode 100644
index 050708661c1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ComponentModel/EditorBrowsableAttribute.cs
+++ /dev/null
@@ -1,33 +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.
-
-namespace System.ComponentModel
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Delegate | AttributeTargets.Interface)]
- public sealed class EditorBrowsableAttribute : Attribute
- {
- public EditorBrowsableAttribute(EditorBrowsableState state)
- {
- State = state;
- }
-
- public EditorBrowsableAttribute() : this(EditorBrowsableState.Always)
- {
- }
-
- public EditorBrowsableState State { get; }
-
- public override bool Equals(object? obj)
- {
- if (obj == this)
- {
- return true;
- }
-
- return (obj is EditorBrowsableAttribute other) && other.State == State;
- }
-
- public override int GetHashCode() => base.GetHashCode();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ComponentModel/EditorBrowsableState.cs b/netcore/System.Private.CoreLib/shared/System/ComponentModel/EditorBrowsableState.cs
deleted file mode 100644
index a98669c4e96..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ComponentModel/EditorBrowsableState.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.ComponentModel
-{
- public enum EditorBrowsableState
- {
- Always,
- Never,
- Advanced
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Configuration/Assemblies/AssemblyHashAlgorithm.cs b/netcore/System.Private.CoreLib/shared/System/Configuration/Assemblies/AssemblyHashAlgorithm.cs
deleted file mode 100644
index aca8da5932b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Configuration/Assemblies/AssemblyHashAlgorithm.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.Configuration.Assemblies
-{
- public enum AssemblyHashAlgorithm
- {
- None = 0,
- MD5 = 0x8003,
- SHA1 = 0x8004,
- SHA256 = 0x800c,
- SHA384 = 0x800d,
- SHA512 = 0x800e,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Configuration/Assemblies/AssemblyVersionCompatibility.cs b/netcore/System.Private.CoreLib/shared/System/Configuration/Assemblies/AssemblyVersionCompatibility.cs
deleted file mode 100644
index ef7b3eb45f0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Configuration/Assemblies/AssemblyVersionCompatibility.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Configuration.Assemblies
-{
- public enum AssemblyVersionCompatibility
- {
- SameMachine = 1,
- SameProcess = 2,
- SameDomain = 3,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Convert.Base64.cs b/netcore/System.Private.CoreLib/shared/System/Convert.Base64.cs
deleted file mode 100644
index 869d89936ad..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Convert.Base64.cs
+++ /dev/null
@@ -1,218 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- public static partial class Convert
- {
- /// <summary>
- /// Decode the span of UTF-16 encoded text represented as base 64 into binary data.
- /// If the input is not a multiple of 4, or contains illegal characters, it will decode as much as it can, to the largest possible multiple of 4.
- /// This invariant allows continuation of the parse with a slower, whitespace-tolerant algorithm.
- ///
- /// <param name="utf16">The input span which contains UTF-16 encoded text in base 64 that needs to be decoded.</param>
- /// <param name="bytes">The output span which contains the result of the operation, i.e. the decoded binary data.</param>
- /// <param name="consumed">The number of input bytes consumed during the operation. This can be used to slice the input for subsequent calls, if necessary.</param>
- /// <param name="written">The number of bytes written into the output span. This can be used to slice the output for subsequent calls, if necessary.</param>
- /// </summary>
- /// <returns>Returns:
- /// - true - The entire input span was successfully parsed.
- /// - false - Only a part of the input span was successfully parsed. Failure causes may include embedded or trailing whitespace,
- /// other illegal Base64 characters, trailing characters after an encoding pad ('='), an input span whose length is not divisible by 4
- /// or a destination span that's too small. <paramref name="consumed"/> and <paramref name="written"/> are set so that
- /// parsing can continue with a slower whitespace-tolerant algorithm.
- ///
- /// Note: This is a cut down version of the implementation of Base64.DecodeFromUtf8(), modified the accept UTF16 chars and act as a fast-path
- /// helper for the Convert routines when the input string contains no whitespace.
- /// </returns>
- private static bool TryDecodeFromUtf16(ReadOnlySpan<char> utf16, Span<byte> bytes, out int consumed, out int written)
- {
- ref char srcChars = ref MemoryMarshal.GetReference(utf16);
- ref byte destBytes = ref MemoryMarshal.GetReference(bytes);
-
- int srcLength = utf16.Length & ~0x3; // only decode input up to the closest multiple of 4.
- int destLength = bytes.Length;
-
- int sourceIndex = 0;
- int destIndex = 0;
-
- if (utf16.Length == 0)
- goto DoneExit;
-
- ref sbyte decodingMap = ref MemoryMarshal.GetReference(DecodingMap);
-
- // Last bytes could have padding characters, so process them separately and treat them as valid.
- const int skipLastChunk = 4;
-
- int maxSrcLength;
- if (destLength >= (srcLength >> 2) * 3)
- {
- maxSrcLength = srcLength - skipLastChunk;
- }
- else
- {
- // This should never overflow since destLength here is less than int.MaxValue / 4 * 3 (i.e. 1610612733)
- // Therefore, (destLength / 3) * 4 will always be less than 2147483641
- maxSrcLength = (destLength / 3) * 4;
- }
-
- while (sourceIndex < maxSrcLength)
- {
- int result = Decode(ref Unsafe.Add(ref srcChars, sourceIndex), ref decodingMap);
- if (result < 0)
- goto InvalidExit;
- WriteThreeLowOrderBytes(ref Unsafe.Add(ref destBytes, destIndex), result);
- destIndex += 3;
- sourceIndex += 4;
- }
-
- if (maxSrcLength != srcLength - skipLastChunk)
- goto InvalidExit;
-
- // If input is less than 4 bytes, srcLength == sourceIndex == 0
- // If input is not a multiple of 4, sourceIndex == srcLength != 0
- if (sourceIndex == srcLength)
- {
- goto InvalidExit;
- }
-
- int i0 = Unsafe.Add(ref srcChars, srcLength - 4);
- int i1 = Unsafe.Add(ref srcChars, srcLength - 3);
- int i2 = Unsafe.Add(ref srcChars, srcLength - 2);
- int i3 = Unsafe.Add(ref srcChars, srcLength - 1);
- if (((i0 | i1 | i2 | i3) & 0xffffff00) != 0)
- goto InvalidExit;
-
- i0 = Unsafe.Add(ref decodingMap, i0);
- i1 = Unsafe.Add(ref decodingMap, i1);
-
- i0 <<= 18;
- i1 <<= 12;
-
- i0 |= i1;
-
- if (i3 != EncodingPad)
- {
- i2 = Unsafe.Add(ref decodingMap, i2);
- i3 = Unsafe.Add(ref decodingMap, i3);
-
- i2 <<= 6;
-
- i0 |= i3;
- i0 |= i2;
-
- if (i0 < 0)
- goto InvalidExit;
- if (destIndex > destLength - 3)
- goto InvalidExit;
- WriteThreeLowOrderBytes(ref Unsafe.Add(ref destBytes, destIndex), i0);
- destIndex += 3;
- }
- else if (i2 != EncodingPad)
- {
- i2 = Unsafe.Add(ref decodingMap, i2);
-
- i2 <<= 6;
-
- i0 |= i2;
-
- if (i0 < 0)
- goto InvalidExit;
- if (destIndex > destLength - 2)
- goto InvalidExit;
- Unsafe.Add(ref destBytes, destIndex) = (byte)(i0 >> 16);
- Unsafe.Add(ref destBytes, destIndex + 1) = (byte)(i0 >> 8);
- destIndex += 2;
- }
- else
- {
- if (i0 < 0)
- goto InvalidExit;
- if (destIndex > destLength - 1)
- goto InvalidExit;
- Unsafe.Add(ref destBytes, destIndex) = (byte)(i0 >> 16);
- destIndex++;
- }
-
- sourceIndex += 4;
-
- if (srcLength != utf16.Length)
- goto InvalidExit;
-
- DoneExit:
- consumed = sourceIndex;
- written = destIndex;
- return true;
-
- InvalidExit:
- consumed = sourceIndex;
- written = destIndex;
- Debug.Assert((consumed % 4) == 0);
- return false;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int Decode(ref char encodedChars, ref sbyte decodingMap)
- {
- int i0 = encodedChars;
- int i1 = Unsafe.Add(ref encodedChars, 1);
- int i2 = Unsafe.Add(ref encodedChars, 2);
- int i3 = Unsafe.Add(ref encodedChars, 3);
-
- if (((i0 | i1 | i2 | i3) & 0xffffff00) != 0)
- return -1; // One or more chars falls outside the 00..ff range. This cannot be a valid Base64 character.
-
- i0 = Unsafe.Add(ref decodingMap, i0);
- i1 = Unsafe.Add(ref decodingMap, i1);
- i2 = Unsafe.Add(ref decodingMap, i2);
- i3 = Unsafe.Add(ref decodingMap, i3);
-
- i0 <<= 18;
- i1 <<= 12;
- i2 <<= 6;
-
- i0 |= i3;
- i1 |= i2;
-
- i0 |= i1;
- return i0;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void WriteThreeLowOrderBytes(ref byte destination, int value)
- {
- destination = (byte)(value >> 16);
- Unsafe.Add(ref destination, 1) = (byte)(value >> 8);
- Unsafe.Add(ref destination, 2) = (byte)value;
- }
-
- // Pre-computing this table using a custom string(s_characters) and GenerateDecodingMapAndVerify (found in tests)
- private static ReadOnlySpan<sbyte> DecodingMap => new sbyte[] // rely on C# compiler optimization to reference static data
- {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, // 62 is placed at index 43 (for +), 63 at index 47 (for /)
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, // 52-61 are placed at index 48-57 (for 0-9), 64 at index 61 (for =)
- -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, // 0-25 are placed at index 65-90 (for A-Z)
- -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, // 26-51 are placed at index 97-122 (for a-z)
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // Bytes over 122 ('z') are invalid and cannot be decoded
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // Hence, padding the map with 255, which indicates invalid input
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- };
-
- private const byte EncodingPad = (byte)'='; // '=', for padding
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Convert.cs b/netcore/System.Private.CoreLib/shared/System/Convert.cs
deleted file mode 100644
index 074a39492cb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Convert.cs
+++ /dev/null
@@ -1,2870 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System
-{
- [Flags]
- public enum Base64FormattingOptions
- {
- None = 0,
- InsertLineBreaks = 1
- }
-
- // Returns the type code of this object. An implementation of this method
- // must not return TypeCode.Empty (which represents a null reference) or
- // TypeCode.Object (which represents an object that doesn't implement the
- // IConvertible interface). An implementation of this method should return
- // TypeCode.DBNull if the value of this object is a database null. For
- // example, a nullable integer type should return TypeCode.DBNull if the
- // value of the object is the database null. Otherwise, an implementation
- // of this method should return the TypeCode that best describes the
- // internal representation of the object.
- // The Value class provides conversion and querying methods for values. The
- // Value class contains static members only, and it is not possible to create
- // instances of the class.
- //
- // The statically typed conversion methods provided by the Value class are all
- // of the form:
- //
- // public static XXX ToXXX(YYY value)
- //
- // where XXX is the target type and YYY is the source type. The matrix below
- // shows the set of supported conversions. The set of conversions is symmetric
- // such that for every ToXXX(YYY) there is also a ToYYY(XXX).
- //
- // From: To: Bol Chr SBy Byt I16 U16 I32 U32 I64 U64 Sgl Dbl Dec Dat Str
- // ----------------------------------------------------------------------
- // Boolean x x x x x x x x x x x x x
- // Char x x x x x x x x x x
- // SByte x x x x x x x x x x x x x x
- // Byte x x x x x x x x x x x x x x
- // Int16 x x x x x x x x x x x x x x
- // UInt16 x x x x x x x x x x x x x x
- // Int32 x x x x x x x x x x x x x x
- // UInt32 x x x x x x x x x x x x x x
- // Int64 x x x x x x x x x x x x x x
- // UInt64 x x x x x x x x x x x x x x
- // Single x x x x x x x x x x x x x
- // Double x x x x x x x x x x x x x
- // Decimal x x x x x x x x x x x x x
- // DateTime x x
- // String x x x x x x x x x x x x x x x
- // ----------------------------------------------------------------------
- //
- // For dynamic conversions, the Value class provides a set of methods of the
- // form:
- //
- // public static XXX ToXXX(object value)
- //
- // where XXX is the target type (Boolean, Char, SByte, Byte, Int16, UInt16,
- // Int32, UInt32, Int64, UInt64, Single, Double, Decimal, DateTime,
- // or String). The implementations of these methods all take the form:
- //
- // public static XXX toXXX(object value) {
- // return value == null? XXX.Default: ((IConvertible)value).ToXXX();
- // }
- //
- // The code first checks if the given value is a null reference (which is the
- // same as Value.Empty), in which case it returns the default value for type
- // XXX. Otherwise, a cast to IConvertible is performed, and the appropriate ToXXX()
- // method is invoked on the object. An InvalidCastException is thrown if the
- // cast to IConvertible fails, and that exception is simply allowed to propagate out
- // of the conversion method.
-
- // Constant representing the database null value. This value is used in
- // database applications to indicate the absence of a known value. Note
- // that Value.DBNull is NOT the same as a null object reference, which is
- // represented by Value.Empty.
- //
- // The Equals() method of DBNull always returns false, even when the
- // argument is itself DBNull.
- //
- // When passed Value.DBNull, the Value.GetTypeCode() method returns
- // TypeCode.DBNull.
- //
- // When passed Value.DBNull, the Value.ToXXX() methods all throw an
- // InvalidCastException.
-
- public static partial class Convert
- {
- // A typeof operation is fairly expensive (does a system call), so we'll cache these here
- // statically. These are exactly lined up with the TypeCode, eg. ConvertType[TypeCode.Int16]
- // will give you the type of an short.
- internal static readonly Type[] ConvertTypes = {
- typeof(System.Empty),
- typeof(object),
- typeof(System.DBNull),
- typeof(bool),
- typeof(char),
- typeof(sbyte),
- typeof(byte),
- typeof(short),
- typeof(ushort),
- typeof(int),
- typeof(uint),
- typeof(long),
- typeof(ulong),
- typeof(float),
- typeof(double),
- typeof(decimal),
- typeof(DateTime),
- typeof(object), // TypeCode is discontinuous so we need a placeholder.
- typeof(string)
- };
-
- // Need to special case Enum because typecode will be underlying type, e.g. Int32
- private static readonly Type EnumType = typeof(Enum);
-
- internal static readonly char[] base64Table = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
- 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
- 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
- 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', '+', '/', '=' };
-
- private const int base64LineBreakPosition = 76;
-
-#if DEBUG
- static Convert()
- {
- Debug.Assert(ConvertTypes != null, "[Convert.cctor]ConvertTypes!=null");
- Debug.Assert(ConvertTypes.Length == ((int)TypeCode.String + 1), "[Convert.cctor]ConvertTypes.Length == ((int)TypeCode.String + 1)");
- Debug.Assert(ConvertTypes[(int)TypeCode.Empty] == typeof(System.Empty),
- "[Convert.cctor]ConvertTypes[(int)TypeCode.Empty]==typeof(System.Empty)");
- Debug.Assert(ConvertTypes[(int)TypeCode.String] == typeof(string),
- "[Convert.cctor]ConvertTypes[(int)TypeCode.String]==typeof(System.String)");
- Debug.Assert(ConvertTypes[(int)TypeCode.Int32] == typeof(int),
- "[Convert.cctor]ConvertTypes[(int)TypeCode.Int32]==typeof(int)");
- }
-#endif
-
- public static readonly object DBNull = System.DBNull.Value;
-
- // Returns the type code for the given object. If the argument is null,
- // the result is TypeCode.Empty. If the argument is not a value (i.e. if
- // the object does not implement IConvertible), the result is TypeCode.Object.
- // Otherwise, the result is the type code of the object, as determined by
- // the object's implementation of IConvertible.
- public static TypeCode GetTypeCode(object? value)
- {
- if (value == null) return TypeCode.Empty;
- if (value is IConvertible temp)
- {
- return temp.GetTypeCode();
- }
- return TypeCode.Object;
- }
-
- // Returns true if the given object is a database null. This operation
- // corresponds to "value.GetTypeCode() == TypeCode.DBNull".
- public static bool IsDBNull(object? value)
- {
- if (value == System.DBNull.Value) return true;
- return value is IConvertible convertible ? convertible.GetTypeCode() == TypeCode.DBNull : false;
- }
-
- // Converts the given object to the given type. In general, this method is
- // equivalent to calling the Value.ToXXX(value) method for the given
- // typeCode and boxing the result.
- //
- // The method first checks if the given object implements IConvertible. If not,
- // the only permitted conversion is from a null to TypeCode.Empty, the
- // result of which is null.
- //
- // If the object does implement IConvertible, a check is made to see if the
- // object already has the given type code, in which case the object is
- // simply returned. Otherwise, the appropriate ToXXX() is invoked on the
- // object's implementation of IConvertible.
- [return: NotNullIfNotNull("value")]
- public static object? ChangeType(object? value, TypeCode typeCode)
- {
- return ChangeType(value, typeCode, CultureInfo.CurrentCulture);
- }
-
- [return: NotNullIfNotNull("value")]
- public static object? ChangeType(object? value, TypeCode typeCode, IFormatProvider? provider)
- {
- if (value == null && (typeCode == TypeCode.Empty || typeCode == TypeCode.String || typeCode == TypeCode.Object))
- {
- return null;
- }
-
- if (!(value is IConvertible v))
- {
- throw new InvalidCastException(SR.InvalidCast_IConvertible);
- }
-
- // This line is invalid for things like Enums that return a TypeCode
- // of int, but the object can't actually be cast to an int.
- // if (v.GetTypeCode() == typeCode) return value;
- return typeCode switch
- {
- TypeCode.Boolean => v.ToBoolean(provider),
- TypeCode.Char => v.ToChar(provider),
- TypeCode.SByte => v.ToSByte(provider),
- TypeCode.Byte => v.ToByte(provider),
- TypeCode.Int16 => v.ToInt16(provider),
- TypeCode.UInt16 => v.ToUInt16(provider),
- TypeCode.Int32 => v.ToInt32(provider),
- TypeCode.UInt32 => v.ToUInt32(provider),
- TypeCode.Int64 => v.ToInt64(provider),
- TypeCode.UInt64 => v.ToUInt64(provider),
- TypeCode.Single => v.ToSingle(provider),
- TypeCode.Double => v.ToDouble(provider),
- TypeCode.Decimal => v.ToDecimal(provider),
- TypeCode.DateTime => v.ToDateTime(provider),
- TypeCode.String => v.ToString(provider),
- TypeCode.Object => value,
- TypeCode.DBNull => throw new InvalidCastException(SR.InvalidCast_DBNull),
- TypeCode.Empty => throw new InvalidCastException(SR.InvalidCast_Empty),
- _ => throw new ArgumentException(SR.Arg_UnknownTypeCode),
- };
- }
-
- internal static object DefaultToType(IConvertible value, Type targetType, IFormatProvider? provider)
- {
- Debug.Assert(value != null, "[Convert.DefaultToType]value!=null");
- if (targetType == null)
- {
- throw new ArgumentNullException(nameof(targetType));
- }
-
- if (ReferenceEquals(value.GetType(), targetType))
- {
- return value;
- }
-
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.Boolean]))
- return value.ToBoolean(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.Char]))
- return value.ToChar(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.SByte]))
- return value.ToSByte(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.Byte]))
- return value.ToByte(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.Int16]))
- return value.ToInt16(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.UInt16]))
- return value.ToUInt16(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.Int32]))
- return value.ToInt32(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.UInt32]))
- return value.ToUInt32(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.Int64]))
- return value.ToInt64(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.UInt64]))
- return value.ToUInt64(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.Single]))
- return value.ToSingle(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.Double]))
- return value.ToDouble(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.Decimal]))
- return value.ToDecimal(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.DateTime]))
- return value.ToDateTime(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.String]))
- return value.ToString(provider);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.Object]))
- return (object)value;
- // Need to special case Enum because typecode will be underlying type, e.g. Int32
- if (ReferenceEquals(targetType, EnumType))
- return (Enum)value;
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.DBNull]))
- throw new InvalidCastException(SR.InvalidCast_DBNull);
- if (ReferenceEquals(targetType, ConvertTypes[(int)TypeCode.Empty]))
- throw new InvalidCastException(SR.InvalidCast_Empty);
-
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, value.GetType().FullName, targetType.FullName));
- }
-
- [return: NotNullIfNotNull("value")]
- public static object? ChangeType(object? value, Type conversionType)
- {
- return ChangeType(value, conversionType, CultureInfo.CurrentCulture);
- }
-
- [return: NotNullIfNotNull("value")]
- public static object? ChangeType(object? value, Type conversionType, IFormatProvider? provider)
- {
- if (conversionType is null)
- {
- throw new ArgumentNullException(nameof(conversionType));
- }
-
- if (value == null)
- {
- if (conversionType.IsValueType)
- {
- throw new InvalidCastException(SR.InvalidCast_CannotCastNullToValueType);
- }
- return null;
- }
-
- if (!(value is IConvertible ic))
- {
- if (value.GetType() == conversionType)
- {
- return value;
- }
- throw new InvalidCastException(SR.InvalidCast_IConvertible);
- }
-
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.Boolean]))
- return ic.ToBoolean(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.Char]))
- return ic.ToChar(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.SByte]))
- return ic.ToSByte(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.Byte]))
- return ic.ToByte(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.Int16]))
- return ic.ToInt16(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.UInt16]))
- return ic.ToUInt16(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.Int32]))
- return ic.ToInt32(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.UInt32]))
- return ic.ToUInt32(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.Int64]))
- return ic.ToInt64(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.UInt64]))
- return ic.ToUInt64(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.Single]))
- return ic.ToSingle(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.Double]))
- return ic.ToDouble(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.Decimal]))
- return ic.ToDecimal(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.DateTime]))
- return ic.ToDateTime(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.String]))
- return ic.ToString(provider);
- if (ReferenceEquals(conversionType, ConvertTypes[(int)TypeCode.Object]))
- return (object)value;
-
- return ic.ToType(conversionType, provider);
- }
-
- [DoesNotReturn]
- private static void ThrowCharOverflowException() { throw new OverflowException(SR.Overflow_Char); }
-
- [DoesNotReturn]
- private static void ThrowByteOverflowException() { throw new OverflowException(SR.Overflow_Byte); }
-
- [DoesNotReturn]
- private static void ThrowSByteOverflowException() { throw new OverflowException(SR.Overflow_SByte); }
-
- [DoesNotReturn]
- private static void ThrowInt16OverflowException() { throw new OverflowException(SR.Overflow_Int16); }
-
- [DoesNotReturn]
- private static void ThrowUInt16OverflowException() { throw new OverflowException(SR.Overflow_UInt16); }
-
- [DoesNotReturn]
- private static void ThrowInt32OverflowException() { throw new OverflowException(SR.Overflow_Int32); }
-
- [DoesNotReturn]
- private static void ThrowUInt32OverflowException() { throw new OverflowException(SR.Overflow_UInt32); }
-
- [DoesNotReturn]
- private static void ThrowInt64OverflowException() { throw new OverflowException(SR.Overflow_Int64); }
-
- [DoesNotReturn]
- private static void ThrowUInt64OverflowException() { throw new OverflowException(SR.Overflow_UInt64); }
-
- // Conversions to Boolean
- public static bool ToBoolean(object? value)
- {
- return value == null ? false : ((IConvertible)value).ToBoolean(null);
- }
-
- public static bool ToBoolean(object? value, IFormatProvider? provider)
- {
- return value == null ? false : ((IConvertible)value).ToBoolean(provider);
- }
-
- public static bool ToBoolean(bool value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static bool ToBoolean(sbyte value)
- {
- return value != 0;
- }
-
- // To be consistent with IConvertible in the base data types else we get different semantics
- // with widening operations. Without this operator this widen succeeds,with this API the widening throws.
- public static bool ToBoolean(char value)
- {
- return ((IConvertible)value).ToBoolean(null);
- }
-
- public static bool ToBoolean(byte value)
- {
- return value != 0;
- }
-
- public static bool ToBoolean(short value)
- {
- return value != 0;
- }
-
- [CLSCompliant(false)]
- public static bool ToBoolean(ushort value)
- {
- return value != 0;
- }
-
- public static bool ToBoolean(int value)
- {
- return value != 0;
- }
-
- [CLSCompliant(false)]
- public static bool ToBoolean(uint value)
- {
- return value != 0;
- }
-
- public static bool ToBoolean(long value)
- {
- return value != 0;
- }
-
- [CLSCompliant(false)]
- public static bool ToBoolean(ulong value)
- {
- return value != 0;
- }
-
- public static bool ToBoolean(string? value)
- {
- if (value == null)
- return false;
- return bool.Parse(value);
- }
-
- public static bool ToBoolean(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return false;
- return bool.Parse(value);
- }
-
- public static bool ToBoolean(float value)
- {
- return value != 0;
- }
-
- public static bool ToBoolean(double value)
- {
- return value != 0;
- }
-
- public static bool ToBoolean(decimal value)
- {
- return value != 0;
- }
-
- public static bool ToBoolean(DateTime value)
- {
- return ((IConvertible)value).ToBoolean(null);
- }
-
- // Disallowed conversions to Boolean
- // public static bool ToBoolean(TimeSpan value)
-
- // Conversions to Char
-
- public static char ToChar(object? value)
- {
- return value == null ? (char)0 : ((IConvertible)value).ToChar(null);
- }
-
- public static char ToChar(object? value, IFormatProvider? provider)
- {
- return value == null ? (char)0 : ((IConvertible)value).ToChar(provider);
- }
-
- public static char ToChar(bool value)
- {
- return ((IConvertible)value).ToChar(null);
- }
-
- public static char ToChar(char value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static char ToChar(sbyte value)
- {
- if (value < 0) ThrowCharOverflowException();
- return (char)value;
- }
-
- public static char ToChar(byte value)
- {
- return (char)value;
- }
-
- public static char ToChar(short value)
- {
- if (value < 0) ThrowCharOverflowException();
- return (char)value;
- }
-
- [CLSCompliant(false)]
- public static char ToChar(ushort value)
- {
- return (char)value;
- }
-
- public static char ToChar(int value)
- {
- if (value < 0 || value > char.MaxValue) ThrowCharOverflowException();
- return (char)value;
- }
-
- [CLSCompliant(false)]
- public static char ToChar(uint value)
- {
- if (value > char.MaxValue) ThrowCharOverflowException();
- return (char)value;
- }
-
- public static char ToChar(long value)
- {
- if (value < 0 || value > char.MaxValue) ThrowCharOverflowException();
- return (char)value;
- }
-
- [CLSCompliant(false)]
- public static char ToChar(ulong value)
- {
- if (value > char.MaxValue) ThrowCharOverflowException();
- return (char)value;
- }
-
- //
- // @VariantSwitch
- // Remove FormatExceptions;
- //
- public static char ToChar(string value)
- {
- return ToChar(value, null);
- }
-
- public static char ToChar(string value, IFormatProvider? provider)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- if (value.Length != 1)
- throw new FormatException(SR.Format_NeedSingleChar);
-
- return value[0];
- }
-
- // To be consistent with IConvertible in the base data types else we get different semantics
- // with widening operations. Without this operator this widen succeeds,with this API the widening throws.
- public static char ToChar(float value)
- {
- return ((IConvertible)value).ToChar(null);
- }
-
- // To be consistent with IConvertible in the base data types else we get different semantics
- // with widening operations. Without this operator this widen succeeds,with this API the widening throws.
- public static char ToChar(double value)
- {
- return ((IConvertible)value).ToChar(null);
- }
-
- // To be consistent with IConvertible in the base data types else we get different semantics
- // with widening operations. Without this operator this widen succeeds,with this API the widening throws.
- public static char ToChar(decimal value)
- {
- return ((IConvertible)value).ToChar(null);
- }
-
- public static char ToChar(DateTime value)
- {
- return ((IConvertible)value).ToChar(null);
- }
-
- // Disallowed conversions to Char
- // public static char ToChar(TimeSpan value)
-
- // Conversions to SByte
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(object? value)
- {
- return value == null ? (sbyte)0 : ((IConvertible)value).ToSByte(null);
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(object? value, IFormatProvider? provider)
- {
- return value == null ? (sbyte)0 : ((IConvertible)value).ToSByte(provider);
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(bool value)
- {
- return value ? (sbyte)bool.True : (sbyte)bool.False;
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(sbyte value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(char value)
- {
- if (value > sbyte.MaxValue) ThrowSByteOverflowException();
- return (sbyte)value;
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(byte value)
- {
- if (value > sbyte.MaxValue) ThrowSByteOverflowException();
- return (sbyte)value;
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(short value)
- {
- if (value < sbyte.MinValue || value > sbyte.MaxValue) ThrowSByteOverflowException();
- return (sbyte)value;
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(ushort value)
- {
- if (value > sbyte.MaxValue) ThrowSByteOverflowException();
- return (sbyte)value;
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(int value)
- {
- if (value < sbyte.MinValue || value > sbyte.MaxValue) ThrowSByteOverflowException();
- return (sbyte)value;
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(uint value)
- {
- if (value > sbyte.MaxValue) ThrowSByteOverflowException();
- return (sbyte)value;
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(long value)
- {
- if (value < sbyte.MinValue || value > sbyte.MaxValue) ThrowSByteOverflowException();
- return (sbyte)value;
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(ulong value)
- {
- if (value > (ulong)sbyte.MaxValue) ThrowSByteOverflowException();
- return (sbyte)value;
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(float value)
- {
- return ToSByte((double)value);
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(double value)
- {
- return ToSByte(ToInt32(value));
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(decimal value)
- {
- return decimal.ToSByte(decimal.Round(value, 0));
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(string? value)
- {
- if (value == null)
- return 0;
- return sbyte.Parse(value, CultureInfo.CurrentCulture);
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(string value, IFormatProvider? provider)
- {
- return sbyte.Parse(value, NumberStyles.Integer, provider);
- }
-
- [CLSCompliant(false)]
- public static sbyte ToSByte(DateTime value)
- {
- return ((IConvertible)value).ToSByte(null);
- }
-
- // Disallowed conversions to SByte
- // public static sbyte ToSByte(TimeSpan value)
-
- // Conversions to Byte
-
- public static byte ToByte(object? value)
- {
- return value == null ? (byte)0 : ((IConvertible)value).ToByte(null);
- }
-
- public static byte ToByte(object? value, IFormatProvider? provider)
- {
- return value == null ? (byte)0 : ((IConvertible)value).ToByte(provider);
- }
-
- public static byte ToByte(bool value)
- {
- return value ? (byte)bool.True : (byte)bool.False;
- }
-
- public static byte ToByte(byte value)
- {
- return value;
- }
-
- public static byte ToByte(char value)
- {
- if (value > byte.MaxValue) ThrowByteOverflowException();
- return (byte)value;
- }
-
- [CLSCompliant(false)]
- public static byte ToByte(sbyte value)
- {
- if (value < byte.MinValue) ThrowByteOverflowException();
- return (byte)value;
- }
-
- public static byte ToByte(short value)
- {
- if (value < byte.MinValue || value > byte.MaxValue) ThrowByteOverflowException();
- return (byte)value;
- }
-
- [CLSCompliant(false)]
- public static byte ToByte(ushort value)
- {
- if (value > byte.MaxValue) ThrowByteOverflowException();
- return (byte)value;
- }
-
- public static byte ToByte(int value)
- {
- if (value < byte.MinValue || value > byte.MaxValue) ThrowByteOverflowException();
- return (byte)value;
- }
-
- [CLSCompliant(false)]
- public static byte ToByte(uint value)
- {
- if (value > byte.MaxValue) ThrowByteOverflowException();
- return (byte)value;
- }
-
- public static byte ToByte(long value)
- {
- if (value < byte.MinValue || value > byte.MaxValue) ThrowByteOverflowException();
- return (byte)value;
- }
-
- [CLSCompliant(false)]
- public static byte ToByte(ulong value)
- {
- if (value > byte.MaxValue) ThrowByteOverflowException();
- return (byte)value;
- }
-
- public static byte ToByte(float value)
- {
- return ToByte((double)value);
- }
-
- public static byte ToByte(double value)
- {
- return ToByte(ToInt32(value));
- }
-
- public static byte ToByte(decimal value)
- {
- return decimal.ToByte(decimal.Round(value, 0));
- }
-
- public static byte ToByte(string? value)
- {
- if (value == null)
- return 0;
- return byte.Parse(value, CultureInfo.CurrentCulture);
- }
-
- public static byte ToByte(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return 0;
- return byte.Parse(value, NumberStyles.Integer, provider);
- }
-
- public static byte ToByte(DateTime value)
- {
- return ((IConvertible)value).ToByte(null);
- }
-
- // Disallowed conversions to Byte
- // public static byte ToByte(TimeSpan value)
-
- // Conversions to Int16
-
- public static short ToInt16(object? value)
- {
- return value == null ? (short)0 : ((IConvertible)value).ToInt16(null);
- }
-
- public static short ToInt16(object? value, IFormatProvider? provider)
- {
- return value == null ? (short)0 : ((IConvertible)value).ToInt16(provider);
- }
-
- public static short ToInt16(bool value)
- {
- return value ? (short)bool.True : (short)bool.False;
- }
-
- public static short ToInt16(char value)
- {
- if (value > short.MaxValue) ThrowInt16OverflowException();
- return (short)value;
- }
-
- [CLSCompliant(false)]
- public static short ToInt16(sbyte value)
- {
- return value;
- }
-
- public static short ToInt16(byte value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static short ToInt16(ushort value)
- {
- if (value > short.MaxValue) ThrowInt16OverflowException();
- return (short)value;
- }
-
- public static short ToInt16(int value)
- {
- if (value < short.MinValue || value > short.MaxValue) ThrowInt16OverflowException();
- return (short)value;
- }
-
- [CLSCompliant(false)]
- public static short ToInt16(uint value)
- {
- if (value > short.MaxValue) ThrowInt16OverflowException();
- return (short)value;
- }
-
- public static short ToInt16(short value)
- {
- return value;
- }
-
- public static short ToInt16(long value)
- {
- if (value < short.MinValue || value > short.MaxValue) ThrowInt16OverflowException();
- return (short)value;
- }
-
- [CLSCompliant(false)]
- public static short ToInt16(ulong value)
- {
- if (value > (ulong)short.MaxValue) ThrowInt16OverflowException();
- return (short)value;
- }
-
- public static short ToInt16(float value)
- {
- return ToInt16((double)value);
- }
-
- public static short ToInt16(double value)
- {
- return ToInt16(ToInt32(value));
- }
-
- public static short ToInt16(decimal value)
- {
- return decimal.ToInt16(decimal.Round(value, 0));
- }
-
- public static short ToInt16(string? value)
- {
- if (value == null)
- return 0;
- return short.Parse(value, CultureInfo.CurrentCulture);
- }
-
- public static short ToInt16(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return 0;
- return short.Parse(value, NumberStyles.Integer, provider);
- }
-
- public static short ToInt16(DateTime value)
- {
- return ((IConvertible)value).ToInt16(null);
- }
-
- // Disallowed conversions to Int16
- // public static short ToInt16(TimeSpan value)
-
- // Conversions to UInt16
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(object? value)
- {
- return value == null ? (ushort)0 : ((IConvertible)value).ToUInt16(null);
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(object? value, IFormatProvider? provider)
- {
- return value == null ? (ushort)0 : ((IConvertible)value).ToUInt16(provider);
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(bool value)
- {
- return value ? (ushort)bool.True : (ushort)bool.False;
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(char value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(sbyte value)
- {
- if (value < 0) ThrowUInt16OverflowException();
- return (ushort)value;
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(byte value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(short value)
- {
- if (value < 0) ThrowUInt16OverflowException();
- return (ushort)value;
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(int value)
- {
- if (value < 0 || value > ushort.MaxValue) ThrowUInt16OverflowException();
- return (ushort)value;
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(ushort value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(uint value)
- {
- if (value > ushort.MaxValue) ThrowUInt16OverflowException();
- return (ushort)value;
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(long value)
- {
- if (value < 0 || value > ushort.MaxValue) ThrowUInt16OverflowException();
- return (ushort)value;
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(ulong value)
- {
- if (value > ushort.MaxValue) ThrowUInt16OverflowException();
- return (ushort)value;
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(float value)
- {
- return ToUInt16((double)value);
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(double value)
- {
- return ToUInt16(ToInt32(value));
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(decimal value)
- {
- return decimal.ToUInt16(decimal.Round(value, 0));
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(string? value)
- {
- if (value == null)
- return 0;
- return ushort.Parse(value, CultureInfo.CurrentCulture);
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return 0;
- return ushort.Parse(value, NumberStyles.Integer, provider);
- }
-
- [CLSCompliant(false)]
- public static ushort ToUInt16(DateTime value)
- {
- return ((IConvertible)value).ToUInt16(null);
- }
-
- // Disallowed conversions to UInt16
- // public static ushort ToUInt16(TimeSpan value)
-
- // Conversions to Int32
-
- public static int ToInt32(object? value)
- {
- return value == null ? 0 : ((IConvertible)value).ToInt32(null);
- }
-
- public static int ToInt32(object? value, IFormatProvider? provider)
- {
- return value == null ? 0 : ((IConvertible)value).ToInt32(provider);
- }
-
- public static int ToInt32(bool value)
- {
- return value ? bool.True : bool.False;
- }
-
- public static int ToInt32(char value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static int ToInt32(sbyte value)
- {
- return value;
- }
-
- public static int ToInt32(byte value)
- {
- return value;
- }
-
- public static int ToInt32(short value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static int ToInt32(ushort value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static int ToInt32(uint value)
- {
- if (value > int.MaxValue) ThrowInt32OverflowException();
- return (int)value;
- }
-
- public static int ToInt32(int value)
- {
- return value;
- }
-
- public static int ToInt32(long value)
- {
- if (value < int.MinValue || value > int.MaxValue) ThrowInt32OverflowException();
- return (int)value;
- }
-
- [CLSCompliant(false)]
- public static int ToInt32(ulong value)
- {
- if (value > int.MaxValue) ThrowInt32OverflowException();
- return (int)value;
- }
-
- public static int ToInt32(float value)
- {
- return ToInt32((double)value);
- }
-
- public static int ToInt32(double value)
- {
- if (value >= 0)
- {
- if (value < 2147483647.5)
- {
- int result = (int)value;
- double dif = value - result;
- if (dif > 0.5 || dif == 0.5 && (result & 1) != 0) result++;
- return result;
- }
- }
- else
- {
- if (value >= -2147483648.5)
- {
- int result = (int)value;
- double dif = value - result;
- if (dif < -0.5 || dif == -0.5 && (result & 1) != 0) result--;
- return result;
- }
- }
- throw new OverflowException(SR.Overflow_Int32);
- }
-
- public static int ToInt32(decimal value)
- {
- return decimal.ToInt32(decimal.Round(value, 0));
- }
-
- public static int ToInt32(string? value)
- {
- if (value == null)
- return 0;
- return int.Parse(value, CultureInfo.CurrentCulture);
- }
-
- public static int ToInt32(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return 0;
- return int.Parse(value, NumberStyles.Integer, provider);
- }
-
- public static int ToInt32(DateTime value)
- {
- return ((IConvertible)value).ToInt32(null);
- }
-
- // Disallowed conversions to Int32
- // public static int ToInt32(TimeSpan value)
-
- // Conversions to UInt32
-
- [CLSCompliant(false)]
- public static uint ToUInt32(object? value)
- {
- return value == null ? 0 : ((IConvertible)value).ToUInt32(null);
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(object? value, IFormatProvider? provider)
- {
- return value == null ? 0 : ((IConvertible)value).ToUInt32(provider);
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(bool value)
- {
- return value ? (uint)bool.True : (uint)bool.False;
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(char value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(sbyte value)
- {
- if (value < 0) ThrowUInt32OverflowException();
- return (uint)value;
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(byte value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(short value)
- {
- if (value < 0) ThrowUInt32OverflowException();
- return (uint)value;
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(ushort value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(int value)
- {
- if (value < 0) ThrowUInt32OverflowException();
- return (uint)value;
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(uint value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(long value)
- {
- if (value < 0 || value > uint.MaxValue) ThrowUInt32OverflowException();
- return (uint)value;
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(ulong value)
- {
- if (value > uint.MaxValue) ThrowUInt32OverflowException();
- return (uint)value;
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(float value)
- {
- return ToUInt32((double)value);
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(double value)
- {
- if (value >= -0.5 && value < 4294967295.5)
- {
- uint result = (uint)value;
- double dif = value - result;
- if (dif > 0.5 || dif == 0.5 && (result & 1) != 0) result++;
- return result;
- }
- throw new OverflowException(SR.Overflow_UInt32);
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(decimal value)
- {
- return decimal.ToUInt32(decimal.Round(value, 0));
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(string? value)
- {
- if (value == null)
- return 0;
- return uint.Parse(value, CultureInfo.CurrentCulture);
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return 0;
- return uint.Parse(value, NumberStyles.Integer, provider);
- }
-
- [CLSCompliant(false)]
- public static uint ToUInt32(DateTime value)
- {
- return ((IConvertible)value).ToUInt32(null);
- }
-
- // Disallowed conversions to UInt32
- // public static uint ToUInt32(TimeSpan value)
-
- // Conversions to Int64
-
- public static long ToInt64(object? value)
- {
- return value == null ? 0 : ((IConvertible)value).ToInt64(null);
- }
-
- public static long ToInt64(object? value, IFormatProvider? provider)
- {
- return value == null ? 0 : ((IConvertible)value).ToInt64(provider);
- }
-
- public static long ToInt64(bool value)
- {
- return value ? bool.True : bool.False;
- }
-
- public static long ToInt64(char value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static long ToInt64(sbyte value)
- {
- return value;
- }
-
- public static long ToInt64(byte value)
- {
- return value;
- }
-
- public static long ToInt64(short value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static long ToInt64(ushort value)
- {
- return value;
- }
-
- public static long ToInt64(int value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static long ToInt64(uint value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static long ToInt64(ulong value)
- {
- if (value > long.MaxValue) ThrowInt64OverflowException();
- return (long)value;
- }
-
- public static long ToInt64(long value)
- {
- return value;
- }
-
- public static long ToInt64(float value)
- {
- return ToInt64((double)value);
- }
-
- public static long ToInt64(double value)
- {
- return checked((long)Math.Round(value));
- }
-
- public static long ToInt64(decimal value)
- {
- return decimal.ToInt64(decimal.Round(value, 0));
- }
-
- public static long ToInt64(string? value)
- {
- if (value == null)
- return 0;
- return long.Parse(value, CultureInfo.CurrentCulture);
- }
-
- public static long ToInt64(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return 0;
- return long.Parse(value, NumberStyles.Integer, provider);
- }
-
- public static long ToInt64(DateTime value)
- {
- return ((IConvertible)value).ToInt64(null);
- }
-
- // Disallowed conversions to Int64
- // public static long ToInt64(TimeSpan value)
-
- // Conversions to UInt64
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(object? value)
- {
- return value == null ? 0 : ((IConvertible)value).ToUInt64(null);
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(object? value, IFormatProvider? provider)
- {
- return value == null ? 0 : ((IConvertible)value).ToUInt64(provider);
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(bool value)
- {
- return value ? (ulong)bool.True : (ulong)bool.False;
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(char value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(sbyte value)
- {
- if (value < 0) ThrowUInt64OverflowException();
- return (ulong)value;
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(byte value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(short value)
- {
- if (value < 0) ThrowUInt64OverflowException();
- return (ulong)value;
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(ushort value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(int value)
- {
- if (value < 0) ThrowUInt64OverflowException();
- return (ulong)value;
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(uint value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(long value)
- {
- if (value < 0) ThrowUInt64OverflowException();
- return (ulong)value;
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(ulong value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(float value)
- {
- return ToUInt64((double)value);
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(double value)
- {
- return checked((ulong)Math.Round(value));
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(decimal value)
- {
- return decimal.ToUInt64(decimal.Round(value, 0));
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(string? value)
- {
- if (value == null)
- return 0;
- return ulong.Parse(value, CultureInfo.CurrentCulture);
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return 0;
- return ulong.Parse(value, NumberStyles.Integer, provider);
- }
-
- [CLSCompliant(false)]
- public static ulong ToUInt64(DateTime value)
- {
- return ((IConvertible)value).ToUInt64(null);
- }
-
- // Disallowed conversions to UInt64
- // public static ulong ToUInt64(TimeSpan value)
-
- // Conversions to Single
-
- public static float ToSingle(object? value)
- {
- return value == null ? 0 : ((IConvertible)value).ToSingle(null);
- }
-
- public static float ToSingle(object? value, IFormatProvider? provider)
- {
- return value == null ? 0 : ((IConvertible)value).ToSingle(provider);
- }
-
- [CLSCompliant(false)]
- public static float ToSingle(sbyte value)
- {
- return value;
- }
-
- public static float ToSingle(byte value)
- {
- return value;
- }
-
- public static float ToSingle(char value)
- {
- return ((IConvertible)value).ToSingle(null);
- }
-
- public static float ToSingle(short value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static float ToSingle(ushort value)
- {
- return value;
- }
-
- public static float ToSingle(int value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static float ToSingle(uint value)
- {
- return value;
- }
-
- public static float ToSingle(long value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static float ToSingle(ulong value)
- {
- return value;
- }
-
- public static float ToSingle(float value)
- {
- return value;
- }
-
- public static float ToSingle(double value)
- {
- return (float)value;
- }
-
- public static float ToSingle(decimal value)
- {
- return (float)value;
- }
-
- public static float ToSingle(string? value)
- {
- if (value == null)
- return 0;
- return float.Parse(value, CultureInfo.CurrentCulture);
- }
-
- public static float ToSingle(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return 0;
- return float.Parse(value, NumberStyles.Float | NumberStyles.AllowThousands, provider);
- }
-
- public static float ToSingle(bool value)
- {
- return value ? bool.True : bool.False;
- }
-
- public static float ToSingle(DateTime value)
- {
- return ((IConvertible)value).ToSingle(null);
- }
-
- // Disallowed conversions to Single
- // public static float ToSingle(TimeSpan value)
-
- // Conversions to Double
-
- public static double ToDouble(object? value)
- {
- return value == null ? 0 : ((IConvertible)value).ToDouble(null);
- }
-
- public static double ToDouble(object? value, IFormatProvider? provider)
- {
- return value == null ? 0 : ((IConvertible)value).ToDouble(provider);
- }
-
- [CLSCompliant(false)]
- public static double ToDouble(sbyte value)
- {
- return value;
- }
-
- public static double ToDouble(byte value)
- {
- return value;
- }
-
- public static double ToDouble(short value)
- {
- return value;
- }
-
- public static double ToDouble(char value)
- {
- return ((IConvertible)value).ToDouble(null);
- }
-
- [CLSCompliant(false)]
- public static double ToDouble(ushort value)
- {
- return value;
- }
-
- public static double ToDouble(int value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static double ToDouble(uint value)
- {
- return value;
- }
-
- public static double ToDouble(long value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static double ToDouble(ulong value)
- {
- return value;
- }
-
- public static double ToDouble(float value)
- {
- return value;
- }
-
- public static double ToDouble(double value)
- {
- return value;
- }
-
- public static double ToDouble(decimal value)
- {
- return (double)value;
- }
-
- public static double ToDouble(string? value)
- {
- if (value == null)
- return 0;
- return double.Parse(value, CultureInfo.CurrentCulture);
- }
-
- public static double ToDouble(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return 0;
- return double.Parse(value, NumberStyles.Float | NumberStyles.AllowThousands, provider);
- }
-
- public static double ToDouble(bool value)
- {
- return value ? bool.True : bool.False;
- }
-
- public static double ToDouble(DateTime value)
- {
- return ((IConvertible)value).ToDouble(null);
- }
-
- // Disallowed conversions to Double
- // public static double ToDouble(TimeSpan value)
-
- // Conversions to Decimal
-
- public static decimal ToDecimal(object? value)
- {
- return value == null ? 0 : ((IConvertible)value).ToDecimal(null);
- }
-
- public static decimal ToDecimal(object? value, IFormatProvider? provider)
- {
- return value == null ? 0 : ((IConvertible)value).ToDecimal(provider);
- }
-
- [CLSCompliant(false)]
- public static decimal ToDecimal(sbyte value)
- {
- return value;
- }
-
- public static decimal ToDecimal(byte value)
- {
- return value;
- }
-
- public static decimal ToDecimal(char value)
- {
- return ((IConvertible)value).ToDecimal(null);
- }
-
- public static decimal ToDecimal(short value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static decimal ToDecimal(ushort value)
- {
- return value;
- }
-
- public static decimal ToDecimal(int value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static decimal ToDecimal(uint value)
- {
- return value;
- }
-
- public static decimal ToDecimal(long value)
- {
- return value;
- }
-
- [CLSCompliant(false)]
- public static decimal ToDecimal(ulong value)
- {
- return value;
- }
-
- public static decimal ToDecimal(float value)
- {
- return (decimal)value;
- }
-
- public static decimal ToDecimal(double value)
- {
- return (decimal)value;
- }
-
- public static decimal ToDecimal(string? value)
- {
- if (value == null)
- return 0m;
- return decimal.Parse(value, CultureInfo.CurrentCulture);
- }
-
- public static decimal ToDecimal(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return 0m;
- return decimal.Parse(value, NumberStyles.Number, provider);
- }
-
- public static decimal ToDecimal(decimal value)
- {
- return value;
- }
-
- public static decimal ToDecimal(bool value)
- {
- return value ? bool.True : bool.False;
- }
-
- public static decimal ToDecimal(DateTime value)
- {
- return ((IConvertible)value).ToDecimal(null);
- }
-
- // Disallowed conversions to Decimal
- // public static decimal ToDecimal(TimeSpan value)
-
- // Conversions to DateTime
-
- public static DateTime ToDateTime(DateTime value)
- {
- return value;
- }
-
- public static DateTime ToDateTime(object? value)
- {
- return value == null ? DateTime.MinValue : ((IConvertible)value).ToDateTime(null);
- }
-
- public static DateTime ToDateTime(object? value, IFormatProvider? provider)
- {
- return value == null ? DateTime.MinValue : ((IConvertible)value).ToDateTime(provider);
- }
-
- public static DateTime ToDateTime(string? value)
- {
- if (value == null)
- return new DateTime(0);
- return DateTime.Parse(value, CultureInfo.CurrentCulture);
- }
-
- public static DateTime ToDateTime(string? value, IFormatProvider? provider)
- {
- if (value == null)
- return new DateTime(0);
- return DateTime.Parse(value, provider);
- }
-
- [CLSCompliant(false)]
- public static DateTime ToDateTime(sbyte value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- public static DateTime ToDateTime(byte value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- public static DateTime ToDateTime(short value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- [CLSCompliant(false)]
- public static DateTime ToDateTime(ushort value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- public static DateTime ToDateTime(int value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- [CLSCompliant(false)]
- public static DateTime ToDateTime(uint value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- public static DateTime ToDateTime(long value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- [CLSCompliant(false)]
- public static DateTime ToDateTime(ulong value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- public static DateTime ToDateTime(bool value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- public static DateTime ToDateTime(char value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- public static DateTime ToDateTime(float value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- public static DateTime ToDateTime(double value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- public static DateTime ToDateTime(decimal value)
- {
- return ((IConvertible)value).ToDateTime(null);
- }
-
- // Disallowed conversions to DateTime
- // public static DateTime ToDateTime(TimeSpan value)
-
- // Conversions to String
-
- public static string? ToString(object? value)
- {
- return ToString(value, null);
- }
-
- public static string? ToString(object? value, IFormatProvider? provider)
- {
- if (value is IConvertible ic)
- return ic.ToString(provider);
- if (value is IFormattable formattable)
- return formattable.ToString(null, provider);
- return value == null ? string.Empty : value.ToString();
- }
-
- public static string ToString(bool value)
- {
- return value.ToString();
- }
-
- public static string ToString(bool value, IFormatProvider? provider)
- {
- return value.ToString();
- }
-
- public static string ToString(char value)
- {
- return char.ToString(value);
- }
-
- public static string ToString(char value, IFormatProvider? provider)
- {
- return value.ToString();
- }
-
- [CLSCompliant(false)]
- public static string ToString(sbyte value)
- {
- return value.ToString(CultureInfo.CurrentCulture);
- }
-
- [CLSCompliant(false)]
- public static string ToString(sbyte value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- public static string ToString(byte value)
- {
- return value.ToString(CultureInfo.CurrentCulture);
- }
-
- public static string ToString(byte value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- public static string ToString(short value)
- {
- return value.ToString(CultureInfo.CurrentCulture);
- }
-
- public static string ToString(short value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- [CLSCompliant(false)]
- public static string ToString(ushort value)
- {
- return value.ToString(CultureInfo.CurrentCulture);
- }
-
- [CLSCompliant(false)]
- public static string ToString(ushort value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- public static string ToString(int value)
- {
- return value.ToString(CultureInfo.CurrentCulture);
- }
-
- public static string ToString(int value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- [CLSCompliant(false)]
- public static string ToString(uint value)
- {
- return value.ToString(CultureInfo.CurrentCulture);
- }
-
- [CLSCompliant(false)]
- public static string ToString(uint value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- public static string ToString(long value)
- {
- return value.ToString(CultureInfo.CurrentCulture);
- }
-
- public static string ToString(long value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- [CLSCompliant(false)]
- public static string ToString(ulong value)
- {
- return value.ToString(CultureInfo.CurrentCulture);
- }
-
- [CLSCompliant(false)]
- public static string ToString(ulong value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- public static string ToString(float value)
- {
- return value.ToString(CultureInfo.CurrentCulture);
- }
-
- public static string ToString(float value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- public static string ToString(double value)
- {
- return value.ToString(CultureInfo.CurrentCulture);
- }
-
- public static string ToString(double value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- public static string ToString(decimal value)
- {
- return value.ToString(CultureInfo.CurrentCulture);
- }
-
- public static string ToString(decimal value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- public static string ToString(DateTime value)
- {
- return value.ToString();
- }
-
- public static string ToString(DateTime value, IFormatProvider? provider)
- {
- return value.ToString(provider);
- }
-
- [return: NotNullIfNotNull("value")]
- public static string? ToString(string? value)
- {
- return value;
- }
-
- [return: NotNullIfNotNull("value")]
- public static string? ToString(string? value, IFormatProvider? provider)
- {
- return value;
- }
-
- //
- // Conversions which understand Base XXX numbers.
- //
- // Parses value in base base. base can only
- // be 2, 8, 10, or 16. If base is 16, the number may be preceded
- // by 0x; any other leading or trailing characters cause an error.
- //
- public static byte ToByte(string? value, int fromBase)
- {
- if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
-
- if (value == null)
- {
- return 0;
- }
-
- int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsUnsigned);
- if (r < byte.MinValue || r > byte.MaxValue)
- ThrowByteOverflowException();
- return (byte)r;
- }
-
- // Parses value in base fromBase. fromBase can only
- // be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
- // by 0x; any other leading or trailing characters cause an error.
- //
- [CLSCompliant(false)]
- public static sbyte ToSByte(string? value, int fromBase)
- {
- if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
-
- if (value == null)
- {
- return 0;
- }
-
- int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsI1);
- if (fromBase != 10 && r <= byte.MaxValue)
- return (sbyte)r;
-
- if (r < sbyte.MinValue || r > sbyte.MaxValue)
- ThrowSByteOverflowException();
- return (sbyte)r;
- }
-
- // Parses value in base fromBase. fromBase can only
- // be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
- // by 0x; any other leading or trailing characters cause an error.
- //
- public static short ToInt16(string? value, int fromBase)
- {
- if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
-
- if (value == null)
- {
- return 0;
- }
-
- int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsI2);
- if (fromBase != 10 && r <= ushort.MaxValue)
- return (short)r;
-
- if (r < short.MinValue || r > short.MaxValue)
- ThrowInt16OverflowException();
- return (short)r;
- }
-
- // Parses value in base fromBase. fromBase can only
- // be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
- // by 0x; any other leading or trailing characters cause an error.
- //
- [CLSCompliant(false)]
- public static ushort ToUInt16(string? value, int fromBase)
- {
- if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
-
- if (value == null)
- {
- return 0;
- }
-
- int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsUnsigned);
- if (r < ushort.MinValue || r > ushort.MaxValue)
- ThrowUInt16OverflowException();
- return (ushort)r;
- }
-
- // Parses value in base fromBase. fromBase can only
- // be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
- // by 0x; any other leading or trailing characters cause an error.
- //
- public static int ToInt32(string? value, int fromBase)
- {
- if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
- return value != null ?
- ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight) :
- 0;
- }
-
- // Parses value in base fromBase. fromBase can only
- // be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
- // by 0x; any other leading or trailing characters cause an error.
- //
- [CLSCompliant(false)]
- public static uint ToUInt32(string? value, int fromBase)
- {
- if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
- return value != null ?
- (uint)ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.TreatAsUnsigned | ParseNumbers.IsTight) :
- 0;
- }
-
- // Parses value in base fromBase. fromBase can only
- // be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
- // by 0x; any other leading or trailing characters cause an error.
- //
- public static long ToInt64(string? value, int fromBase)
- {
- if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
- return value != null ?
- ParseNumbers.StringToLong(value.AsSpan(), fromBase, ParseNumbers.IsTight) :
- 0;
- }
-
- // Parses value in base fromBase. fromBase can only
- // be 2, 8, 10, or 16. If fromBase is 16, the number may be preceded
- // by 0x; any other leading or trailing characters cause an error.
- //
- [CLSCompliant(false)]
- public static ulong ToUInt64(string? value, int fromBase)
- {
- if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
- return value != null ?
- (ulong)ParseNumbers.StringToLong(value.AsSpan(), fromBase, ParseNumbers.TreatAsUnsigned | ParseNumbers.IsTight) :
- 0;
- }
-
- // Convert the byte value to a string in base fromBase
- public static string ToString(byte value, int toBase)
- {
- if (toBase != 2 && toBase != 8 && toBase != 10 && toBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
- return ParseNumbers.IntToString((int)value, toBase, -1, ' ', ParseNumbers.PrintAsI1);
- }
-
- // Convert the Int16 value to a string in base fromBase
- public static string ToString(short value, int toBase)
- {
- if (toBase != 2 && toBase != 8 && toBase != 10 && toBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
- return ParseNumbers.IntToString((int)value, toBase, -1, ' ', ParseNumbers.PrintAsI2);
- }
-
- // Convert the Int32 value to a string in base toBase
- public static string ToString(int value, int toBase)
- {
- if (toBase != 2 && toBase != 8 && toBase != 10 && toBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
- return ParseNumbers.IntToString(value, toBase, -1, ' ', 0);
- }
-
- // Convert the Int64 value to a string in base toBase
- public static string ToString(long value, int toBase)
- {
- if (toBase != 2 && toBase != 8 && toBase != 10 && toBase != 16)
- {
- throw new ArgumentException(SR.Arg_InvalidBase);
- }
- return ParseNumbers.LongToString(value, toBase, -1, ' ', 0);
- }
-
- public static string ToBase64String(byte[] inArray)
- {
- if (inArray == null)
- {
- throw new ArgumentNullException(nameof(inArray));
- }
- return ToBase64String(new ReadOnlySpan<byte>(inArray), Base64FormattingOptions.None);
- }
-
- public static string ToBase64String(byte[] inArray, Base64FormattingOptions options)
- {
- if (inArray == null)
- {
- throw new ArgumentNullException(nameof(inArray));
- }
- return ToBase64String(new ReadOnlySpan<byte>(inArray), options);
- }
-
- public static string ToBase64String(byte[] inArray, int offset, int length)
- {
- return ToBase64String(inArray, offset, length, Base64FormattingOptions.None);
- }
-
- public static string ToBase64String(byte[] inArray, int offset, int length, Base64FormattingOptions options)
- {
- if (inArray == null)
- throw new ArgumentNullException(nameof(inArray));
- if (length < 0)
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Index);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_GenericPositive);
- if (offset > (inArray.Length - length))
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_OffsetLength);
-
- return ToBase64String(new ReadOnlySpan<byte>(inArray, offset, length), options);
- }
-
- public static string ToBase64String(ReadOnlySpan<byte> bytes, Base64FormattingOptions options = Base64FormattingOptions.None)
- {
- if (options < Base64FormattingOptions.None || options > Base64FormattingOptions.InsertLineBreaks)
- {
- throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)options), nameof(options));
- }
-
- if (bytes.Length == 0)
- {
- return string.Empty;
- }
-
- bool insertLineBreaks = (options == Base64FormattingOptions.InsertLineBreaks);
- string result = string.FastAllocateString(ToBase64_CalculateAndValidateOutputLength(bytes.Length, insertLineBreaks));
-
- unsafe
- {
- fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
- fixed (char* charsPtr = result)
- {
- int charsWritten = ConvertToBase64Array(charsPtr, bytesPtr, 0, bytes.Length, insertLineBreaks);
- Debug.Assert(result.Length == charsWritten, $"Expected {result.Length} == {charsWritten}");
- }
- }
-
- return result;
- }
-
- public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut)
- {
- return ToBase64CharArray(inArray, offsetIn, length, outArray, offsetOut, Base64FormattingOptions.None);
- }
-
- public static unsafe int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut, Base64FormattingOptions options)
- {
- // Do data verfication
- if (inArray == null)
- throw new ArgumentNullException(nameof(inArray));
- if (outArray == null)
- throw new ArgumentNullException(nameof(outArray));
- if (length < 0)
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Index);
- if (offsetIn < 0)
- throw new ArgumentOutOfRangeException(nameof(offsetIn), SR.ArgumentOutOfRange_GenericPositive);
- if (offsetOut < 0)
- throw new ArgumentOutOfRangeException(nameof(offsetOut), SR.ArgumentOutOfRange_GenericPositive);
-
- if (options < Base64FormattingOptions.None || options > Base64FormattingOptions.InsertLineBreaks)
- {
- throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)options), nameof(options));
- }
-
- int retVal;
-
- int inArrayLength;
- int outArrayLength;
- int numElementsToCopy;
-
- inArrayLength = inArray.Length;
-
- if (offsetIn > (int)(inArrayLength - length))
- throw new ArgumentOutOfRangeException(nameof(offsetIn), SR.ArgumentOutOfRange_OffsetLength);
-
- if (inArrayLength == 0)
- return 0;
-
- bool insertLineBreaks = (options == Base64FormattingOptions.InsertLineBreaks);
- // This is the maximally required length that must be available in the char array
- outArrayLength = outArray.Length;
-
- // Length of the char buffer required
- numElementsToCopy = ToBase64_CalculateAndValidateOutputLength(length, insertLineBreaks);
-
- if (offsetOut > (int)(outArrayLength - numElementsToCopy))
- throw new ArgumentOutOfRangeException(nameof(offsetOut), SR.ArgumentOutOfRange_OffsetOut);
-
- fixed (char* outChars = &outArray[offsetOut])
- {
- fixed (byte* inData = &inArray[0])
- {
- retVal = ConvertToBase64Array(outChars, inData, offsetIn, length, insertLineBreaks);
- }
- }
-
- return retVal;
- }
-
- public static unsafe bool TryToBase64Chars(ReadOnlySpan<byte> bytes, Span<char> chars, out int charsWritten, Base64FormattingOptions options = Base64FormattingOptions.None)
- {
- if (options < Base64FormattingOptions.None || options > Base64FormattingOptions.InsertLineBreaks)
- {
- throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)options), nameof(options));
- }
-
- if (bytes.Length == 0)
- {
- charsWritten = 0;
- return true;
- }
-
- bool insertLineBreaks = (options == Base64FormattingOptions.InsertLineBreaks);
-
- int charLengthRequired = ToBase64_CalculateAndValidateOutputLength(bytes.Length, insertLineBreaks);
- if (charLengthRequired > chars.Length)
- {
- charsWritten = 0;
- return false;
- }
-
- fixed (char* outChars = &MemoryMarshal.GetReference(chars))
- fixed (byte* inData = &MemoryMarshal.GetReference(bytes))
- {
- charsWritten = ConvertToBase64Array(outChars, inData, 0, bytes.Length, insertLineBreaks);
- return true;
- }
- }
-
- private static unsafe int ConvertToBase64Array(char* outChars, byte* inData, int offset, int length, bool insertLineBreaks)
- {
- int lengthmod3 = length % 3;
- int calcLength = offset + (length - lengthmod3);
- int j = 0;
- int charcount = 0;
- // Convert three bytes at a time to base64 notation. This will consume 4 chars.
- int i;
-
- // get a pointer to the base64Table to avoid unnecessary range checking
- fixed (char* base64 = &base64Table[0])
- {
- for (i = offset; i < calcLength; i += 3)
- {
- if (insertLineBreaks)
- {
- if (charcount == base64LineBreakPosition)
- {
- outChars[j++] = '\r';
- outChars[j++] = '\n';
- charcount = 0;
- }
- charcount += 4;
- }
- outChars[j] = base64[(inData[i] & 0xfc) >> 2];
- outChars[j + 1] = base64[((inData[i] & 0x03) << 4) | ((inData[i + 1] & 0xf0) >> 4)];
- outChars[j + 2] = base64[((inData[i + 1] & 0x0f) << 2) | ((inData[i + 2] & 0xc0) >> 6)];
- outChars[j + 3] = base64[inData[i + 2] & 0x3f];
- j += 4;
- }
-
- // Where we left off before
- i = calcLength;
-
- if (insertLineBreaks && (lengthmod3 != 0) && (charcount == base64LineBreakPosition))
- {
- outChars[j++] = '\r';
- outChars[j++] = '\n';
- }
-
- switch (lengthmod3)
- {
- case 2: // One character padding needed
- outChars[j] = base64[(inData[i] & 0xfc) >> 2];
- outChars[j + 1] = base64[((inData[i] & 0x03) << 4) | ((inData[i + 1] & 0xf0) >> 4)];
- outChars[j + 2] = base64[(inData[i + 1] & 0x0f) << 2];
- outChars[j + 3] = base64[64]; // Pad
- j += 4;
- break;
- case 1: // Two character padding needed
- outChars[j] = base64[(inData[i] & 0xfc) >> 2];
- outChars[j + 1] = base64[(inData[i] & 0x03) << 4];
- outChars[j + 2] = base64[64]; // Pad
- outChars[j + 3] = base64[64]; // Pad
- j += 4;
- break;
- }
- }
-
- return j;
- }
-
- private static int ToBase64_CalculateAndValidateOutputLength(int inputLength, bool insertLineBreaks)
- {
- long outlen = ((long)inputLength) / 3 * 4; // the base length - we want integer division here.
- outlen += ((inputLength % 3) != 0) ? 4 : 0; // at most 4 more chars for the remainder
-
- if (outlen == 0)
- return 0;
-
- if (insertLineBreaks)
- {
- long newLines = outlen / base64LineBreakPosition;
- if ((outlen % base64LineBreakPosition) == 0)
- {
- --newLines;
- }
- outlen += newLines * 2; // the number of line break chars we'll add, "\r\n"
- }
-
- // If we overflow an int then we cannot allocate enough
- // memory to output the value so throw
- if (outlen > int.MaxValue)
- throw new OutOfMemoryException();
-
- return (int)outlen;
- }
-
- /// <summary>
- /// Converts the specified string, which encodes binary data as Base64 digits, to the equivalent byte array.
- /// </summary>
- /// <param name="s">The string to convert</param>
- /// <returns>The array of bytes represented by the specified Base64 string.</returns>
- public static byte[] FromBase64String(string s)
- {
- // "s" is an unfortunate parameter name, but we need to keep it for backward compat.
-
- if (s == null)
- throw new ArgumentNullException(nameof(s));
-
- unsafe
- {
- fixed (char* sPtr = s)
- {
- return FromBase64CharPtr(sPtr, s.Length);
- }
- }
- }
-
- public static bool TryFromBase64String(string s, Span<byte> bytes, out int bytesWritten)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- return TryFromBase64Chars(s.AsSpan(), bytes, out bytesWritten);
- }
-
- public static bool TryFromBase64Chars(ReadOnlySpan<char> chars, Span<byte> bytes, out int bytesWritten)
- {
- // This is actually local to one of the nested blocks but is being declared at the top as we don't want multiple stackallocs
- // for each iteraton of the loop.
- Span<char> tempBuffer = stackalloc char[4]; // Note: The tempBuffer size could be made larger than 4 but the size must be a multiple of 4.
-
- bytesWritten = 0;
-
- while (chars.Length != 0)
- {
- // Attempt to decode a segment that doesn't contain whitespace.
- bool complete = TryDecodeFromUtf16(chars, bytes, out int consumedInThisIteration, out int bytesWrittenInThisIteration);
- bytesWritten += bytesWrittenInThisIteration;
- if (complete)
- return true;
-
- chars = chars.Slice(consumedInThisIteration);
- bytes = bytes.Slice(bytesWrittenInThisIteration);
-
- Debug.Assert(chars.Length != 0); // If TryDecodeFromUtf16() consumed the entire buffer, it could not have returned false.
- if (chars[0].IsSpace())
- {
- // If we got here, the very first character not consumed was a whitespace. We can skip past any consecutive whitespace, then continue decoding.
-
- int indexOfFirstNonSpace = 1;
- while (true)
- {
- if (indexOfFirstNonSpace == chars.Length)
- break;
- if (!chars[indexOfFirstNonSpace].IsSpace())
- break;
- indexOfFirstNonSpace++;
- }
-
- chars = chars.Slice(indexOfFirstNonSpace);
-
- if ((bytesWrittenInThisIteration % 3) != 0 && chars.Length != 0)
- {
- // If we got here, the last successfully decoded block encountered an end-marker, yet we have trailing non-whitespace characters.
- // That is not allowed.
- bytesWritten = default;
- return false;
- }
-
- // We now loop again to decode the next run of non-space characters.
- }
- else
- {
- Debug.Assert(chars.Length != 0 && !chars[0].IsSpace());
-
- // If we got here, it is possible that there is whitespace that occurred in the middle of a 4-byte chunk. That is, we still have
- // up to three Base64 characters that were left undecoded by the fast-path helper because they didn't form a complete 4-byte chunk.
- // This is hopefully the rare case (multiline-formatted base64 message with a non-space character width that's not a multiple of 4.)
- // We'll filter out whitespace and copy the remaining characters into a temporary buffer.
- CopyToTempBufferWithoutWhiteSpace(chars, tempBuffer, out int consumedFromChars, out int charsWritten);
- if ((charsWritten & 0x3) != 0)
- {
- // Even after stripping out whitespace, the number of characters is not divisible by 4. This cannot be a legal Base64 string.
- bytesWritten = default;
- return false;
- }
-
- tempBuffer = tempBuffer.Slice(0, charsWritten);
- if (!TryDecodeFromUtf16(tempBuffer, bytes, out int consumedFromTempBuffer, out int bytesWrittenFromTempBuffer))
- {
- bytesWritten = default;
- return false;
- }
- bytesWritten += bytesWrittenFromTempBuffer;
- chars = chars.Slice(consumedFromChars);
- bytes = bytes.Slice(bytesWrittenFromTempBuffer);
-
- if ((bytesWrittenFromTempBuffer % 3) != 0)
- {
- // If we got here, this decode contained one or more padding characters ('='). We can accept trailing whitespace after this
- // but nothing else.
- for (int i = 0; i < chars.Length; i++)
- {
- if (!chars[i].IsSpace())
- {
- bytesWritten = default;
- return false;
- }
- }
- return true;
- }
-
- // We now loop again to decode the next run of non-space characters.
- }
- }
-
- return true;
- }
-
- private static void CopyToTempBufferWithoutWhiteSpace(ReadOnlySpan<char> chars, Span<char> tempBuffer, out int consumed, out int charsWritten)
- {
- Debug.Assert(tempBuffer.Length != 0); // We only bound-check after writing a character to the tempBuffer.
-
- charsWritten = 0;
- for (int i = 0; i < chars.Length; i++)
- {
- char c = chars[i];
- if (!c.IsSpace())
- {
- tempBuffer[charsWritten++] = c;
- if (charsWritten == tempBuffer.Length)
- {
- consumed = i + 1;
- return;
- }
- }
- }
- consumed = chars.Length;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsSpace(this char c) => c == ' ' || c == '\t' || c == '\r' || c == '\n';
-
- /// <summary>
- /// Converts the specified range of a Char array, which encodes binary data as Base64 digits, to the equivalent byte array.
- /// </summary>
- /// <param name="inArray">Chars representing Base64 encoding characters</param>
- /// <param name="offset">A position within the input array.</param>
- /// <param name="length">Number of element to convert.</param>
- /// <returns>The array of bytes represented by the specified Base64 encoding characters.</returns>
- public static byte[] FromBase64CharArray(char[] inArray, int offset, int length)
- {
- if (inArray == null)
- throw new ArgumentNullException(nameof(inArray));
-
- if (length < 0)
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Index);
-
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_GenericPositive);
-
- if (offset > inArray.Length - length)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_OffsetLength);
-
- if (inArray.Length == 0)
- {
- return Array.Empty<byte>();
- }
-
- unsafe
- {
- fixed (char* inArrayPtr = &inArray[0])
- {
- return FromBase64CharPtr(inArrayPtr + offset, length);
- }
- }
- }
-
- /// <summary>
- /// Convert Base64 encoding characters to bytes:
- /// - Compute result length exactly by actually walking the input;
- /// - Allocate new result array based on computation;
- /// - Decode input into the new array;
- /// </summary>
- /// <param name="inputPtr">Pointer to the first input char</param>
- /// <param name="inputLength">Number of input chars</param>
- /// <returns></returns>
- private static unsafe byte[] FromBase64CharPtr(char* inputPtr, int inputLength)
- {
- // The validity of parameters much be checked by callers, thus we are Critical here.
-
- Debug.Assert(0 <= inputLength);
-
- // We need to get rid of any trailing white spaces.
- // Otherwise we would be rejecting input such as "abc= ":
- while (inputLength > 0)
- {
- int lastChar = inputPtr[inputLength - 1];
- if (lastChar != (int)' ' && lastChar != (int)'\n' && lastChar != (int)'\r' && lastChar != (int)'\t')
- break;
- inputLength--;
- }
-
- // Compute the output length:
- int resultLength = FromBase64_ComputeResultLength(inputPtr, inputLength);
-
- Debug.Assert(0 <= resultLength);
-
- // resultLength can be zero. We will still enter FromBase64_Decode and process the input.
- // It may either simply write no bytes (e.g. input = " ") or throw (e.g. input = "ab").
-
- // Create result byte blob:
- byte[] decodedBytes = new byte[resultLength];
-
- // Convert Base64 chars into bytes:
- if (!TryFromBase64Chars(new ReadOnlySpan<char>(inputPtr, inputLength), decodedBytes, out int _))
- throw new FormatException(SR.Format_BadBase64Char);
-
- // Note that the number of bytes written can differ from resultLength if the caller is modifying the array
- // as it is being converted. Silently ignore the failure.
- // Consider throwing exception in an non in-place release.
-
- // We are done:
- return decodedBytes;
- }
-
- /// <summary>
- /// Compute the number of bytes encoded in the specified Base 64 char array:
- /// Walk the entire input counting white spaces and padding chars, then compute result length
- /// based on 3 bytes per 4 chars.
- /// </summary>
- private static unsafe int FromBase64_ComputeResultLength(char* inputPtr, int inputLength)
- {
- const uint intEq = (uint)'=';
- const uint intSpace = (uint)' ';
-
- Debug.Assert(0 <= inputLength);
-
- char* inputEndPtr = inputPtr + inputLength;
- int usefulInputLength = inputLength;
- int padding = 0;
-
- while (inputPtr < inputEndPtr)
- {
- uint c = (uint)(*inputPtr);
- inputPtr++;
-
- // We want to be as fast as possible and filter out spaces with as few comparisons as possible.
- // We end up accepting a number of illegal chars as legal white-space chars.
- // This is ok: as soon as we hit them during actual decode we will recognise them as illegal and throw.
- if (c <= intSpace)
- usefulInputLength--;
- else if (c == intEq)
- {
- usefulInputLength--;
- padding++;
- }
- }
-
- Debug.Assert(0 <= usefulInputLength);
-
- // For legal input, we can assume that 0 <= padding < 3. But it may be more for illegal input.
- // We will notice it at decode when we see a '=' at the wrong place.
- Debug.Assert(0 <= padding);
-
- // Perf: reuse the variable that stored the number of '=' to store the number of bytes encoded by the
- // last group that contains the '=':
- if (padding != 0)
- {
- if (padding == 1)
- padding = 2;
- else if (padding == 2)
- padding = 1;
- else
- throw new FormatException(SR.Format_BadBase64Char);
- }
-
- // Done:
- return (usefulInputLength / 4) * 3 + padding;
- }
- } // class Convert
-} // namespace
diff --git a/netcore/System.Private.CoreLib/shared/System/CoreLib.cs b/netcore/System.Private.CoreLib/shared/System/CoreLib.cs
deleted file mode 100644
index 9c5d1c1aa37..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/CoreLib.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System
-{
- // This class is used to define the name of the base class library
- internal static class CoreLib
- {
- public const string Name = "System.Private.CoreLib";
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/CurrentSystemTimeZone.cs b/netcore/System.Private.CoreLib/shared/System/CurrentSystemTimeZone.cs
deleted file mode 100644
index 23dd63f5e2d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/CurrentSystemTimeZone.cs
+++ /dev/null
@@ -1,195 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose:
-** This class represents the current system timezone. It is
-** the only meaningful implementation of the TimeZone class
-** available in this version.
-**
-** The only TimeZone that we support in version 1 is the
-** CurrentTimeZone as determined by the system timezone.
-**
-**
-============================================================*/
-
-using System.Collections;
-using System.Globalization;
-
-namespace System
-{
- [Obsolete("System.CurrentSystemTimeZone has been deprecated. Please investigate the use of System.TimeZoneInfo.Local instead.")]
- internal class CurrentSystemTimeZone : TimeZone
- {
- // Standard offset in ticks to the Universal time if
- // no daylight saving is in used.
- // E.g. the offset for PST (Pacific Standard time) should be -8 * 60 * 60 * 1000 * 10000.
- // (1 millisecond = 10000 ticks)
- private readonly long m_ticksOffset;
- private readonly string m_standardName;
- private readonly string m_daylightName;
-
- internal CurrentSystemTimeZone()
- {
- TimeZoneInfo local = TimeZoneInfo.Local;
-
- m_ticksOffset = local.BaseUtcOffset.Ticks;
- m_standardName = local.StandardName;
- m_daylightName = local.DaylightName;
- }
-
- public override string StandardName => m_standardName;
-
- public override string DaylightName => m_daylightName;
-
- internal long GetUtcOffsetFromUniversalTime(DateTime time, ref bool isAmbiguousLocalDst)
- {
- // Get the daylight changes for the year of the specified time.
- TimeSpan offset = new TimeSpan(m_ticksOffset);
- DaylightTime daylightTime = GetDaylightChanges(time.Year);
- isAmbiguousLocalDst = false;
-
- if (daylightTime == null || daylightTime.Delta.Ticks == 0)
- {
- return offset.Ticks;
- }
-
- // The start and end times represent the range of universal times that are in DST for that year.
- // Within that there is an ambiguous hour, usually right at the end, but at the beginning in
- // the unusual case of a negative daylight savings delta.
- DateTime startTime = daylightTime.Start - offset;
- DateTime endTime = daylightTime.End - offset - daylightTime.Delta;
- DateTime ambiguousStart;
- DateTime ambiguousEnd;
-
- if (daylightTime.Delta.Ticks > 0)
- {
- ambiguousStart = endTime - daylightTime.Delta;
- ambiguousEnd = endTime;
- }
- else
- {
- ambiguousStart = startTime;
- ambiguousEnd = startTime - daylightTime.Delta;
- }
-
- bool isDst;
- if (startTime > endTime)
- {
- // In southern hemisphere, the daylight saving time starts later in the year, and ends in the beginning of next year.
- // Note, the summer in the southern hemisphere begins late in the year.
- isDst = (time < endTime || time >= startTime);
- }
- else
- {
- // In northern hemisphere, the daylight saving time starts in the middle of the year.
- isDst = (time >= startTime && time < endTime);
- }
-
- if (isDst)
- {
- offset += daylightTime.Delta;
-
- // See if the resulting local time becomes ambiguous. This must be captured here or the
- // DateTime will not be able to round-trip back to UTC accurately.
- if (time >= ambiguousStart && time < ambiguousEnd)
- {
- isAmbiguousLocalDst = true;
- }
- }
- return offset.Ticks;
- }
-
- public override DateTime ToLocalTime(DateTime time)
- {
- if (time.Kind == DateTimeKind.Local)
- {
- return time;
- }
- bool isAmbiguousLocalDst = false;
- long offset = GetUtcOffsetFromUniversalTime(time, ref isAmbiguousLocalDst);
- long tick = time.Ticks + offset;
- if (tick > DateTime.MaxTicks)
- {
- return new DateTime(DateTime.MaxTicks, DateTimeKind.Local);
- }
- if (tick < DateTime.MinTicks)
- {
- return new DateTime(DateTime.MinTicks, DateTimeKind.Local);
- }
- return new DateTime(tick, DateTimeKind.Local, isAmbiguousLocalDst);
- }
-
- public override DaylightTime GetDaylightChanges(int year)
- {
- if (year < 1 || year > 9999)
- {
- throw new ArgumentOutOfRangeException(nameof(year), SR.Format(SR.ArgumentOutOfRange_Range, 1, 9999));
- }
-
- return GetCachedDaylightChanges(year);
- }
-
- private static DaylightTime CreateDaylightChanges(int year)
- {
- DateTime start = DateTime.MinValue;
- DateTime end = DateTime.MinValue;
- TimeSpan delta = TimeSpan.Zero;
-
- if (TimeZoneInfo.Local.SupportsDaylightSavingTime)
- {
- foreach (TimeZoneInfo.AdjustmentRule rule in TimeZoneInfo.Local.GetAdjustmentRules())
- {
- if (rule.DateStart.Year <= year && rule.DateEnd.Year >= year && rule.DaylightDelta != TimeSpan.Zero)
- {
- start = TimeZoneInfo.TransitionTimeToDateTime(year, rule.DaylightTransitionStart);
- end = TimeZoneInfo.TransitionTimeToDateTime(year, rule.DaylightTransitionEnd);
- delta = rule.DaylightDelta;
- break;
- }
- }
- }
-
- return new DaylightTime(start, end, delta);
- }
-
- public override TimeSpan GetUtcOffset(DateTime time)
- {
- if (time.Kind == DateTimeKind.Utc)
- {
- return TimeSpan.Zero;
- }
- else
- {
- return new TimeSpan(TimeZone.CalculateUtcOffset(time, GetDaylightChanges(time.Year)).Ticks + m_ticksOffset);
- }
- }
-
- private DaylightTime GetCachedDaylightChanges(int year)
- {
- object objYear = (object)year;
-
- if (!m_CachedDaylightChanges.Contains(objYear))
- {
- DaylightTime currentDaylightChanges = CreateDaylightChanges(year);
- lock (m_CachedDaylightChanges)
- {
- if (!m_CachedDaylightChanges.Contains(objYear))
- {
- m_CachedDaylightChanges.Add(objYear, currentDaylightChanges);
- }
- }
- }
-
- return (DaylightTime)m_CachedDaylightChanges[objYear]!;
- }
-
- // The per-year information is cached in this instance value. As a result it can
- // be cleaned up by CultureInfo.ClearCachedData, which will clear the instance of this object
- private readonly Hashtable m_CachedDaylightChanges = new Hashtable();
- } // class CurrentSystemTimeZone
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DBNull.cs b/netcore/System.Private.CoreLib/shared/System/DBNull.cs
deleted file mode 100644
index e01071c77bf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DBNull.cs
+++ /dev/null
@@ -1,118 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- public sealed class DBNull : ISerializable, IConvertible
- {
- private DBNull()
- {
- }
-
- private DBNull(SerializationInfo info, StreamingContext context)
- {
- throw new NotSupportedException(SR.NotSupported_DBNullSerial);
- }
-
- public static readonly DBNull Value = new DBNull();
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- UnitySerializationHolder.GetUnitySerializationInfo(info, UnitySerializationHolder.NullUnity);
- }
-
- public override string ToString()
- {
- return string.Empty;
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return string.Empty;
- }
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.DBNull;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.InvalidCast_FromDBNull);
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DataMisalignedException.cs b/netcore/System.Private.CoreLib/shared/System/DataMisalignedException.cs
deleted file mode 100644
index 927abe0edc7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DataMisalignedException.cs
+++ /dev/null
@@ -1,42 +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.
-
-/*=============================================================================
-**
-**
-** Purpose: The exception class for a misaligned access exception
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class DataMisalignedException : SystemException
- {
- public DataMisalignedException()
- : base(SR.Arg_DataMisalignedException)
- {
- HResult = HResults.COR_E_DATAMISALIGNED;
- }
-
- public DataMisalignedException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_DATAMISALIGNED;
- }
-
- public DataMisalignedException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_DATAMISALIGNED;
- }
-
- private DataMisalignedException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DateTime.Unix.cs b/netcore/System.Private.CoreLib/shared/System/DateTime.Unix.cs
deleted file mode 100644
index 2c4de3e1a85..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DateTime.Unix.cs
+++ /dev/null
@@ -1,27 +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.
-
-namespace System
-{
- public readonly partial struct DateTime
- {
- internal const bool s_systemSupportsLeapSeconds = false;
-
-#if !CORECLR
- public static DateTime UtcNow
- {
- get
- {
- return new DateTime(((ulong)(Interop.Sys.GetSystemTimeAsTicks() + UnixEpochTicks)) | KindUtc);
- }
- }
-#endif
-
- private static DateTime FromFileTimeLeapSecondsAware(long fileTime) => default;
- private static long ToFileTimeLeapSecondsAware(long ticks) => default;
-
- // IsValidTimeWithLeapSeconds is not expected to be called at all for now on non-Windows platforms
- internal static bool IsValidTimeWithLeapSeconds(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind) => false;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DateTime.Win32.cs b/netcore/System.Private.CoreLib/shared/System/DateTime.Win32.cs
deleted file mode 100644
index d33ccfea6fd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DateTime.Win32.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System
-{
- public readonly partial struct DateTime
- {
- private static unsafe bool SystemSupportsLeapSeconds()
- {
- Interop.NtDll.SYSTEM_LEAP_SECOND_INFORMATION slsi;
-
- return Interop.NtDll.NtQuerySystemInformation(
- Interop.NtDll.SystemLeapSecondInformation,
- (void*)&slsi,
- sizeof(Interop.NtDll.SYSTEM_LEAP_SECOND_INFORMATION),
- null) == 0 && slsi.Enabled;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DateTime.Windows.cs b/netcore/System.Private.CoreLib/shared/System/DateTime.Windows.cs
deleted file mode 100644
index 134e83697e0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DateTime.Windows.cs
+++ /dev/null
@@ -1,215 +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 System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System
-{
- public readonly partial struct DateTime
- {
- internal static readonly bool s_systemSupportsLeapSeconds = SystemSupportsLeapSeconds();
-
- public static unsafe DateTime UtcNow
- {
- get
- {
- if (s_systemSupportsLeapSeconds)
- {
- FullSystemTime time;
- GetSystemTimeWithLeapSecondsHandling(&time);
- return CreateDateTimeFromSystemTime(in time);
- }
-
- return new DateTime(((ulong)(GetSystemTimeAsFileTime() + FileTimeOffset)) | KindUtc);
- }
- }
-
- internal static unsafe bool IsValidTimeWithLeapSeconds(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind)
- {
- DateTime dt = new DateTime(year, month, day);
- FullSystemTime time = new FullSystemTime(year, month, dt.DayOfWeek, day, hour, minute, second);
-
- return kind switch
- {
- DateTimeKind.Local => ValidateSystemTime(&time.systemTime, localTime: true),
- DateTimeKind.Utc => ValidateSystemTime(&time.systemTime, localTime: false),
- _ => ValidateSystemTime(&time.systemTime, localTime: true) || ValidateSystemTime(&time.systemTime, localTime: false),
- };
- }
-
- private static unsafe DateTime FromFileTimeLeapSecondsAware(long fileTime)
- {
- FullSystemTime time;
- if (FileTimeToSystemTime(fileTime, &time))
- {
- return CreateDateTimeFromSystemTime(in time);
- }
-
- throw new ArgumentOutOfRangeException(nameof(fileTime), SR.ArgumentOutOfRange_DateTimeBadTicks);
- }
-
- private static unsafe long ToFileTimeLeapSecondsAware(long ticks)
- {
- FullSystemTime time = new FullSystemTime(ticks);
- long fileTime;
-
- if (SystemTimeToFileTime(&time.systemTime, &fileTime))
- {
- return fileTime + ticks % TicksPerMillisecond;
- }
-
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_FileTimeInvalid);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static DateTime CreateDateTimeFromSystemTime(in FullSystemTime time)
- {
- long ticks = DateToTicks(time.systemTime.Year, time.systemTime.Month, time.systemTime.Day);
- ticks += TimeToTicks(time.systemTime.Hour, time.systemTime.Minute, time.systemTime.Second);
- ticks += time.systemTime.Milliseconds * TicksPerMillisecond;
- ticks += time.hundredNanoSecond;
- return new DateTime(((ulong)(ticks)) | KindUtc);
- }
-
- // FullSystemTime struct is the SYSTEMTIME struct with extra hundredNanoSecond field to store more precise time.
- [StructLayout(LayoutKind.Sequential)]
- private struct FullSystemTime
- {
- internal Interop.Kernel32.SYSTEMTIME systemTime;
- internal long hundredNanoSecond;
-
- internal FullSystemTime(int year, int month, DayOfWeek dayOfWeek, int day, int hour, int minute, int second)
- {
- systemTime.Year = (ushort)year;
- systemTime.Month = (ushort)month;
- systemTime.DayOfWeek = (ushort)dayOfWeek;
- systemTime.Day = (ushort)day;
- systemTime.Hour = (ushort)hour;
- systemTime.Minute = (ushort)minute;
- systemTime.Second = (ushort)second;
- systemTime.Milliseconds = 0;
- hundredNanoSecond = 0;
- }
-
- internal FullSystemTime(long ticks)
- {
- DateTime dt = new DateTime(ticks);
-
- int year, month, day;
- dt.GetDatePart(out year, out month, out day);
-
- systemTime.Year = (ushort)year;
- systemTime.Month = (ushort)month;
- systemTime.DayOfWeek = (ushort)dt.DayOfWeek;
- systemTime.Day = (ushort)day;
- systemTime.Hour = (ushort)dt.Hour;
- systemTime.Minute = (ushort)dt.Minute;
- systemTime.Second = (ushort)dt.Second;
- systemTime.Milliseconds = (ushort)dt.Millisecond;
- hundredNanoSecond = 0;
- }
- }
-
-#if !CORECLR
- internal static readonly bool s_systemSupportsPreciseSystemTime = SystemSupportsPreciseSystemTime();
-
- private static unsafe bool SystemSupportsPreciseSystemTime()
- {
- if (Environment.IsWindows8OrAbove)
- {
- // GetSystemTimePreciseAsFileTime exists and we'd like to use it. However, on
- // misconfigured systems, it's possible for the "precise" time to be inaccurate:
- // https://github.com/dotnet/coreclr/issues/14187
- // If it's inaccurate, though, we expect it to be wildly inaccurate, so as a
- // workaround/heuristic, we get both the "normal" and "precise" times, and as
- // long as they're close, we use the precise one. This workaround can be removed
- // when we better understand what's causing the drift and the issue is no longer
- // a problem or can be better worked around on all targeted OSes.
-
- long systemTimeResult;
- Interop.Kernel32.GetSystemTimeAsFileTime(&systemTimeResult);
-
- long preciseSystemTimeResult;
- Interop.Kernel32.GetSystemTimePreciseAsFileTime(&preciseSystemTimeResult);
-
- return Math.Abs(preciseSystemTimeResult - systemTimeResult) <= 100 * TicksPerMillisecond;
- }
-
- return false;
- }
-
- private static unsafe bool ValidateSystemTime(Interop.Kernel32.SYSTEMTIME* time, bool localTime)
- {
- if (localTime)
- {
- Interop.Kernel32.SYSTEMTIME st;
- return Interop.Kernel32.TzSpecificLocalTimeToSystemTime(IntPtr.Zero, time, &st) != Interop.BOOL.FALSE;
- }
- else
- {
- long timestamp;
- return Interop.Kernel32.SystemTimeToFileTime(time, &timestamp) != Interop.BOOL.FALSE;
- }
- }
-
- private static unsafe bool FileTimeToSystemTime(long fileTime, FullSystemTime* time)
- {
- if (Interop.Kernel32.FileTimeToSystemTime(&fileTime, &time->systemTime) != Interop.BOOL.FALSE)
- {
- // to keep the time precision
- time->hundredNanoSecond = fileTime % TicksPerMillisecond;
- if (time->systemTime.Second > 59)
- {
- // we have a leap second, force it to last second in the minute as DateTime doesn't account for leap seconds in its calculation.
- // we use the maxvalue from the milliseconds and the 100-nano seconds to avoid reporting two out of order 59 seconds
- time->systemTime.Second = 59;
- time->systemTime.Milliseconds = 999;
- time->hundredNanoSecond = 9999;
- }
- return true;
- }
- return false;
- }
-
- private static unsafe void GetSystemTimeWithLeapSecondsHandling(FullSystemTime* time)
- {
- if (!FileTimeToSystemTime(GetSystemTimeAsFileTime(), time))
- {
- Interop.Kernel32.GetSystemTime(&time->systemTime);
- time->hundredNanoSecond = 0;
- if (time->systemTime.Second > 59)
- {
- // we have a leap second, force it to last second in the minute as DateTime doesn't account for leap seconds in its calculation.
- // we use the maxvalue from the milliseconds and the 100-nano seconds to avoid reporting two out of order 59 seconds
- time->systemTime.Second = 59;
- time->systemTime.Milliseconds = 999;
- time->hundredNanoSecond = 9999;
- }
- }
- }
-
- private static unsafe bool SystemTimeToFileTime(Interop.Kernel32.SYSTEMTIME* time, long* fileTime)
- {
- return Interop.Kernel32.SystemTimeToFileTime(time, fileTime) != Interop.BOOL.FALSE;
- }
-
- private static unsafe long GetSystemTimeAsFileTime()
- {
- long timestamp;
-
- if (s_systemSupportsPreciseSystemTime)
- {
- Interop.Kernel32.GetSystemTimePreciseAsFileTime(&timestamp);
- }
- else
- {
- Interop.Kernel32.GetSystemTimeAsFileTime(&timestamp);
- }
-
- return timestamp;
- }
-#endif
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DateTime.cs b/netcore/System.Private.CoreLib/shared/System/DateTime.cs
deleted file mode 100644
index 8452e89c071..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DateTime.cs
+++ /dev/null
@@ -1,1602 +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 System.Diagnostics;
-using System.Globalization;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-using CultureInfo = System.Globalization.CultureInfo;
-using Calendar = System.Globalization.Calendar;
-
-namespace System
-{
- // This value type represents a date and time. Every DateTime
- // object has a private field (Ticks) of type Int64 that stores the
- // date and time as the number of 100 nanosecond intervals since
- // 12:00 AM January 1, year 1 A.D. in the proleptic Gregorian Calendar.
- //
- // Starting from V2.0, DateTime also stored some context about its time
- // zone in the form of a 3-state value representing Unspecified, Utc or
- // Local. This is stored in the two top bits of the 64-bit numeric value
- // with the remainder of the bits storing the tick count. This information
- // is only used during time zone conversions and is not part of the
- // identity of the DateTime. Thus, operations like Compare and Equals
- // ignore this state. This is to stay compatible with earlier behavior
- // and performance characteristics and to avoid forcing people into dealing
- // with the effects of daylight savings. Note, that this has little effect
- // on how the DateTime works except in a context where its specific time
- // zone is needed, such as during conversions and some parsing and formatting
- // cases.
- //
- // There is also 4th state stored that is a special type of Local value that
- // is used to avoid data loss when round-tripping between local and UTC time.
- // See below for more information on this 4th state, although it is
- // effectively hidden from most users, who just see the 3-state DateTimeKind
- // enumeration.
- //
- // For compatibility, DateTime does not serialize the Kind data when used in
- // binary serialization.
- //
- // For a description of various calendar issues, look at
- //
- //
- [StructLayout(LayoutKind.Auto)]
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly partial struct DateTime : IComparable, IFormattable, IConvertible, IComparable<DateTime>, IEquatable<DateTime>, ISerializable, ISpanFormattable
- {
- // Number of 100ns ticks per time unit
- private const long TicksPerMillisecond = 10000;
- private const long TicksPerSecond = TicksPerMillisecond * 1000;
- private const long TicksPerMinute = TicksPerSecond * 60;
- private const long TicksPerHour = TicksPerMinute * 60;
- private const long TicksPerDay = TicksPerHour * 24;
-
- // Number of milliseconds per time unit
- private const int MillisPerSecond = 1000;
- private const int MillisPerMinute = MillisPerSecond * 60;
- private const int MillisPerHour = MillisPerMinute * 60;
- private const int MillisPerDay = MillisPerHour * 24;
-
- // Number of days in a non-leap year
- private const int DaysPerYear = 365;
- // Number of days in 4 years
- private const int DaysPer4Years = DaysPerYear * 4 + 1; // 1461
- // Number of days in 100 years
- private const int DaysPer100Years = DaysPer4Years * 25 - 1; // 36524
- // Number of days in 400 years
- private const int DaysPer400Years = DaysPer100Years * 4 + 1; // 146097
-
- // Number of days from 1/1/0001 to 12/31/1600
- private const int DaysTo1601 = DaysPer400Years * 4; // 584388
- // Number of days from 1/1/0001 to 12/30/1899
- private const int DaysTo1899 = DaysPer400Years * 4 + DaysPer100Years * 3 - 367;
- // Number of days from 1/1/0001 to 12/31/1969
- internal const int DaysTo1970 = DaysPer400Years * 4 + DaysPer100Years * 3 + DaysPer4Years * 17 + DaysPerYear; // 719,162
- // Number of days from 1/1/0001 to 12/31/9999
- private const int DaysTo10000 = DaysPer400Years * 25 - 366; // 3652059
-
- internal const long MinTicks = 0;
- internal const long MaxTicks = DaysTo10000 * TicksPerDay - 1;
- private const long MaxMillis = (long)DaysTo10000 * MillisPerDay;
-
- internal const long UnixEpochTicks = DaysTo1970 * TicksPerDay;
- private const long FileTimeOffset = DaysTo1601 * TicksPerDay;
- private const long DoubleDateOffset = DaysTo1899 * TicksPerDay;
- // The minimum OA date is 0100/01/01 (Note it's year 100).
- // The maximum OA date is 9999/12/31
- private const long OADateMinAsTicks = (DaysPer100Years - DaysPerYear) * TicksPerDay;
- // All OA dates must be greater than (not >=) OADateMinAsDouble
- private const double OADateMinAsDouble = -657435.0;
- // All OA dates must be less than (not <=) OADateMaxAsDouble
- private const double OADateMaxAsDouble = 2958466.0;
-
- private const int DatePartYear = 0;
- private const int DatePartDayOfYear = 1;
- private const int DatePartMonth = 2;
- private const int DatePartDay = 3;
-
- private static readonly int[] s_daysToMonth365 = {
- 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
- private static readonly int[] s_daysToMonth366 = {
- 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
-
- public static readonly DateTime MinValue = new DateTime(MinTicks, DateTimeKind.Unspecified);
- public static readonly DateTime MaxValue = new DateTime(MaxTicks, DateTimeKind.Unspecified);
- public static readonly DateTime UnixEpoch = new DateTime(UnixEpochTicks, DateTimeKind.Utc);
-
- private const ulong TicksMask = 0x3FFFFFFFFFFFFFFF;
- private const ulong FlagsMask = 0xC000000000000000;
- private const ulong LocalMask = 0x8000000000000000;
- private const long TicksCeiling = 0x4000000000000000;
- private const ulong KindUnspecified = 0x0000000000000000;
- private const ulong KindUtc = 0x4000000000000000;
- private const ulong KindLocal = 0x8000000000000000;
- private const ulong KindLocalAmbiguousDst = 0xC000000000000000;
- private const int KindShift = 62;
-
- private const string TicksField = "ticks"; // Do not rename (binary serialization)
- private const string DateDataField = "dateData"; // Do not rename (binary serialization)
-
- // The data is stored as an unsigned 64-bit integer
- // Bits 01-62: The value of 100-nanosecond ticks where 0 represents 1/1/0001 12:00am, up until the value
- // 12/31/9999 23:59:59.9999999
- // Bits 63-64: A four-state value that describes the DateTimeKind value of the date time, with a 2nd
- // value for the rare case where the date time is local, but is in an overlapped daylight
- // savings time hour and it is in daylight savings time. This allows distinction of these
- // otherwise ambiguous local times and prevents data loss when round tripping from Local to
- // UTC time.
- private readonly ulong _dateData;
-
- // Constructs a DateTime from a tick count. The ticks
- // argument specifies the date as the number of 100-nanosecond intervals
- // that have elapsed since 1/1/0001 12:00am.
- //
- public DateTime(long ticks)
- {
- if (ticks < MinTicks || ticks > MaxTicks)
- throw new ArgumentOutOfRangeException(nameof(ticks), SR.ArgumentOutOfRange_DateTimeBadTicks);
- _dateData = (ulong)ticks;
- }
-
- private DateTime(ulong dateData)
- {
- this._dateData = dateData;
- }
-
- public DateTime(long ticks, DateTimeKind kind)
- {
- if (ticks < MinTicks || ticks > MaxTicks)
- {
- throw new ArgumentOutOfRangeException(nameof(ticks), SR.ArgumentOutOfRange_DateTimeBadTicks);
- }
- if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
- {
- throw new ArgumentException(SR.Argument_InvalidDateTimeKind, nameof(kind));
- }
- _dateData = ((ulong)ticks | ((ulong)kind << KindShift));
- }
-
- internal DateTime(long ticks, DateTimeKind kind, bool isAmbiguousDst)
- {
- if (ticks < MinTicks || ticks > MaxTicks)
- {
- throw new ArgumentOutOfRangeException(nameof(ticks), SR.ArgumentOutOfRange_DateTimeBadTicks);
- }
- Debug.Assert(kind == DateTimeKind.Local, "Internal Constructor is for local times only");
- _dateData = ((ulong)ticks | (isAmbiguousDst ? KindLocalAmbiguousDst : KindLocal));
- }
-
- // Constructs a DateTime from a given year, month, and day. The
- // time-of-day of the resulting DateTime is always midnight.
- //
- public DateTime(int year, int month, int day)
- {
- _dateData = (ulong)DateToTicks(year, month, day);
- }
-
- // Constructs a DateTime from a given year, month, and day for
- // the specified calendar. The
- // time-of-day of the resulting DateTime is always midnight.
- //
- public DateTime(int year, int month, int day, Calendar calendar)
- : this(year, month, day, 0, 0, 0, calendar)
- {
- }
-
- // Constructs a DateTime from a given year, month, day, hour,
- // minute, and second.
- //
- public DateTime(int year, int month, int day, int hour, int minute, int second)
- {
- if (second == 60 && s_systemSupportsLeapSeconds && IsValidTimeWithLeapSeconds(year, month, day, hour, minute, second, DateTimeKind.Unspecified))
- {
- // if we have leap second (second = 60) then we'll need to check if it is valid time.
- // if it is valid, then we adjust the second to 59 so DateTime will consider this second is last second
- // in the specified minute.
- // if it is not valid time, we'll eventually throw.
- second = 59;
- }
- _dateData = (ulong)(DateToTicks(year, month, day) + TimeToTicks(hour, minute, second));
- }
-
- public DateTime(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind)
- {
- if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
- {
- throw new ArgumentException(SR.Argument_InvalidDateTimeKind, nameof(kind));
- }
-
- if (second == 60 && s_systemSupportsLeapSeconds && IsValidTimeWithLeapSeconds(year, month, day, hour, minute, second, kind))
- {
- // if we have leap second (second = 60) then we'll need to check if it is valid time.
- // if it is valid, then we adjust the second to 59 so DateTime will consider this second is last second
- // in the specified minute.
- // if it is not valid time, we'll eventually throw.
- second = 59;
- }
-
- long ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second);
- _dateData = ((ulong)ticks | ((ulong)kind << KindShift));
- }
-
- // Constructs a DateTime from a given year, month, day, hour,
- // minute, and second for the specified calendar.
- //
- public DateTime(int year, int month, int day, int hour, int minute, int second, Calendar calendar)
- {
- if (calendar == null)
- throw new ArgumentNullException(nameof(calendar));
-
- int originalSecond = second;
- if (second == 60 && s_systemSupportsLeapSeconds)
- {
- // Reset the second value now and then we'll validate it later when we get the final Gregorian date.
- second = 59;
- }
-
- _dateData = (ulong)calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
-
- if (originalSecond == 60)
- {
- DateTime dt = new DateTime(_dateData);
- if (!IsValidTimeWithLeapSeconds(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 60, DateTimeKind.Unspecified))
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond);
- }
- }
- }
-
- // Constructs a DateTime from a given year, month, day, hour,
- // minute, and second.
- //
- public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
- {
- if (millisecond < 0 || millisecond >= MillisPerSecond)
- {
- throw new ArgumentOutOfRangeException(nameof(millisecond), SR.Format(SR.ArgumentOutOfRange_Range, 0, MillisPerSecond - 1));
- }
-
- if (second == 60 && s_systemSupportsLeapSeconds && IsValidTimeWithLeapSeconds(year, month, day, hour, minute, second, DateTimeKind.Unspecified))
- {
- // if we have leap second (second = 60) then we'll need to check if it is valid time.
- // if it is valid, then we adjust the second to 59 so DateTime will consider this second is last second
- // in the specified minute.
- // if it is not valid time, we'll eventually throw.
- second = 59;
- }
-
- long ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second);
- ticks += millisecond * TicksPerMillisecond;
- if (ticks < MinTicks || ticks > MaxTicks)
- throw new ArgumentException(SR.Arg_DateTimeRange);
- _dateData = (ulong)ticks;
- }
-
- public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind)
- {
- if (millisecond < 0 || millisecond >= MillisPerSecond)
- {
- throw new ArgumentOutOfRangeException(nameof(millisecond), SR.Format(SR.ArgumentOutOfRange_Range, 0, MillisPerSecond - 1));
- }
- if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
- {
- throw new ArgumentException(SR.Argument_InvalidDateTimeKind, nameof(kind));
- }
-
- if (second == 60 && s_systemSupportsLeapSeconds && IsValidTimeWithLeapSeconds(year, month, day, hour, minute, second, kind))
- {
- // if we have leap second (second = 60) then we'll need to check if it is valid time.
- // if it is valid, then we adjust the second to 59 so DateTime will consider this second is last second
- // in the specified minute.
- // if it is not valid time, we'll eventually throw.
- second = 59;
- }
-
- long ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second);
- ticks += millisecond * TicksPerMillisecond;
- if (ticks < MinTicks || ticks > MaxTicks)
- throw new ArgumentException(SR.Arg_DateTimeRange);
- _dateData = ((ulong)ticks | ((ulong)kind << KindShift));
- }
-
- // Constructs a DateTime from a given year, month, day, hour,
- // minute, and second for the specified calendar.
- //
- public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar)
- {
- if (calendar == null)
- throw new ArgumentNullException(nameof(calendar));
- if (millisecond < 0 || millisecond >= MillisPerSecond)
- {
- throw new ArgumentOutOfRangeException(nameof(millisecond), SR.Format(SR.ArgumentOutOfRange_Range, 0, MillisPerSecond - 1));
- }
-
- int originalSecond = second;
- if (second == 60 && s_systemSupportsLeapSeconds)
- {
- // Reset the second value now and then we'll validate it later when we get the final Gregorian date.
- second = 59;
- }
-
- long ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
- ticks += millisecond * TicksPerMillisecond;
- if (ticks < MinTicks || ticks > MaxTicks)
- throw new ArgumentException(SR.Arg_DateTimeRange);
- _dateData = (ulong)ticks;
-
- if (originalSecond == 60)
- {
- DateTime dt = new DateTime(_dateData);
- if (!IsValidTimeWithLeapSeconds(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 60, DateTimeKind.Unspecified))
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond);
- }
- }
- }
-
- public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, DateTimeKind kind)
- {
- if (calendar == null)
- throw new ArgumentNullException(nameof(calendar));
- if (millisecond < 0 || millisecond >= MillisPerSecond)
- {
- throw new ArgumentOutOfRangeException(nameof(millisecond), SR.Format(SR.ArgumentOutOfRange_Range, 0, MillisPerSecond - 1));
- }
- if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
- {
- throw new ArgumentException(SR.Argument_InvalidDateTimeKind, nameof(kind));
- }
-
- int originalSecond = second;
- if (second == 60 && s_systemSupportsLeapSeconds)
- {
- // Reset the second value now and then we'll validate it later when we get the final Gregorian date.
- second = 59;
- }
-
- long ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
- ticks += millisecond * TicksPerMillisecond;
- if (ticks < MinTicks || ticks > MaxTicks)
- throw new ArgumentException(SR.Arg_DateTimeRange);
- _dateData = ((ulong)ticks | ((ulong)kind << KindShift));
-
- if (originalSecond == 60)
- {
- DateTime dt = new DateTime(_dateData);
- if (!IsValidTimeWithLeapSeconds(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 60, kind))
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond);
- }
- }
- }
-
- private DateTime(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- throw new ArgumentNullException(nameof(info));
-
- bool foundTicks = false;
- bool foundDateData = false;
- long serializedTicks = 0;
- ulong serializedDateData = 0;
-
- // Get the data
- SerializationInfoEnumerator enumerator = info.GetEnumerator();
- while (enumerator.MoveNext())
- {
- switch (enumerator.Name)
- {
- case TicksField:
- serializedTicks = Convert.ToInt64(enumerator.Value, CultureInfo.InvariantCulture);
- foundTicks = true;
- break;
- case DateDataField:
- serializedDateData = Convert.ToUInt64(enumerator.Value, CultureInfo.InvariantCulture);
- foundDateData = true;
- break;
- default:
- // Ignore other fields for forward compatibility.
- break;
- }
- }
- if (foundDateData)
- {
- _dateData = serializedDateData;
- }
- else if (foundTicks)
- {
- _dateData = (ulong)serializedTicks;
- }
- else
- {
- throw new SerializationException(SR.Serialization_MissingDateTimeData);
- }
- long ticks = InternalTicks;
- if (ticks < MinTicks || ticks > MaxTicks)
- {
- throw new SerializationException(SR.Serialization_DateTimeTicksOutOfRange);
- }
- }
-
- internal long InternalTicks => (long)(_dateData & TicksMask);
-
- private ulong InternalKind => _dateData & FlagsMask;
-
- // Returns the DateTime resulting from adding the given
- // TimeSpan to this DateTime.
- //
- public DateTime Add(TimeSpan value)
- {
- return AddTicks(value._ticks);
- }
-
- // Returns the DateTime resulting from adding a fractional number of
- // time units to this DateTime.
- private DateTime Add(double value, int scale)
- {
- double millis_double = value * (double)scale + (value >= 0 ? 0.5 : -0.5);
-
- if (millis_double <= (double)-MaxMillis || millis_double >= (double)MaxMillis)
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_AddValue);
-
- return AddTicks((long)millis_double * TicksPerMillisecond);
- }
-
- // Returns the DateTime resulting from adding a fractional number of
- // days to this DateTime. The result is computed by rounding the
- // fractional number of days given by value to the nearest
- // millisecond, and adding that interval to this DateTime. The
- // value argument is permitted to be negative.
- //
- public DateTime AddDays(double value)
- {
- return Add(value, MillisPerDay);
- }
-
- // Returns the DateTime resulting from adding a fractional number of
- // hours to this DateTime. The result is computed by rounding the
- // fractional number of hours given by value to the nearest
- // millisecond, and adding that interval to this DateTime. The
- // value argument is permitted to be negative.
- //
- public DateTime AddHours(double value)
- {
- return Add(value, MillisPerHour);
- }
-
- // Returns the DateTime resulting from the given number of
- // milliseconds to this DateTime. The result is computed by rounding
- // the number of milliseconds given by value to the nearest integer,
- // and adding that interval to this DateTime. The value
- // argument is permitted to be negative.
- //
- public DateTime AddMilliseconds(double value)
- {
- return Add(value, 1);
- }
-
- // Returns the DateTime resulting from adding a fractional number of
- // minutes to this DateTime. The result is computed by rounding the
- // fractional number of minutes given by value to the nearest
- // millisecond, and adding that interval to this DateTime. The
- // value argument is permitted to be negative.
- //
- public DateTime AddMinutes(double value)
- {
- return Add(value, MillisPerMinute);
- }
-
- // Returns the DateTime resulting from adding the given number of
- // months to this DateTime. The result is computed by incrementing
- // (or decrementing) the year and month parts of this DateTime by
- // months months, and, if required, adjusting the day part of the
- // resulting date downwards to the last day of the resulting month in the
- // resulting year. The time-of-day part of the result is the same as the
- // time-of-day part of this DateTime.
- //
- // In more precise terms, considering this DateTime to be of the
- // form y / m / d + t, where y is the
- // year, m is the month, d is the day, and t is the
- // time-of-day, the result is y1 / m1 / d1 + t,
- // where y1 and m1 are computed by adding months months
- // to y and m, and d1 is the largest value less than
- // or equal to d that denotes a valid day in month m1 of year
- // y1.
- //
- public DateTime AddMonths(int months)
- {
- if (months < -120000 || months > 120000) throw new ArgumentOutOfRangeException(nameof(months), SR.ArgumentOutOfRange_DateTimeBadMonths);
- GetDatePart(out int y, out int m, out int d);
- int i = m - 1 + months;
- if (i >= 0)
- {
- m = i % 12 + 1;
- y += i / 12;
- }
- else
- {
- m = 12 + (i + 1) % 12;
- y += (i - 11) / 12;
- }
- if (y < 1 || y > 9999)
- {
- throw new ArgumentOutOfRangeException(nameof(months), SR.ArgumentOutOfRange_DateArithmetic);
- }
- int days = DaysInMonth(y, m);
- if (d > days) d = days;
- return new DateTime((ulong)(DateToTicks(y, m, d) + InternalTicks % TicksPerDay) | InternalKind);
- }
-
- // Returns the DateTime resulting from adding a fractional number of
- // seconds to this DateTime. The result is computed by rounding the
- // fractional number of seconds given by value to the nearest
- // millisecond, and adding that interval to this DateTime. The
- // value argument is permitted to be negative.
- //
- public DateTime AddSeconds(double value)
- {
- return Add(value, MillisPerSecond);
- }
-
- // Returns the DateTime resulting from adding the given number of
- // 100-nanosecond ticks to this DateTime. The value argument
- // is permitted to be negative.
- //
- public DateTime AddTicks(long value)
- {
- long ticks = InternalTicks;
- if (value > MaxTicks - ticks || value < MinTicks - ticks)
- {
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_DateArithmetic);
- }
- return new DateTime((ulong)(ticks + value) | InternalKind);
- }
-
- // TryAddTicks is exact as AddTicks except it doesn't throw
- internal bool TryAddTicks(long value, out DateTime result)
- {
- long ticks = InternalTicks;
- if (value > MaxTicks - ticks || value < MinTicks - ticks)
- {
- result = default;
- return false;
- }
- result = new DateTime((ulong)(ticks + value) | InternalKind);
- return true;
- }
-
- // Returns the DateTime resulting from adding the given number of
- // years to this DateTime. The result is computed by incrementing
- // (or decrementing) the year part of this DateTime by value
- // years. If the month and day of this DateTime is 2/29, and if the
- // resulting year is not a leap year, the month and day of the resulting
- // DateTime becomes 2/28. Otherwise, the month, day, and time-of-day
- // parts of the result are the same as those of this DateTime.
- //
- public DateTime AddYears(int value)
- {
- if (value < -10000 || value > 10000)
- {
- // DateTimeOffset.AddYears(int years) is implemented on top of DateTime.AddYears(int value). Use the more appropriate
- // parameter name out of the two for the exception.
- throw new ArgumentOutOfRangeException("years", SR.ArgumentOutOfRange_DateTimeBadYears);
- }
- return AddMonths(value * 12);
- }
-
- // Compares two DateTime values, returning an integer that indicates
- // their relationship.
- //
- public static int Compare(DateTime t1, DateTime t2)
- {
- long ticks1 = t1.InternalTicks;
- long ticks2 = t2.InternalTicks;
- if (ticks1 > ticks2) return 1;
- if (ticks1 < ticks2) return -1;
- return 0;
- }
-
- // Compares this DateTime to a given object. This method provides an
- // implementation of the IComparable interface. The object
- // argument must be another DateTime, or otherwise an exception
- // occurs. Null is considered less than any instance.
- //
- // Returns a value less than zero if this object
- public int CompareTo(object? value)
- {
- if (value == null) return 1;
- if (!(value is DateTime))
- {
- throw new ArgumentException(SR.Arg_MustBeDateTime);
- }
-
- return Compare(this, (DateTime)value);
- }
-
- public int CompareTo(DateTime value)
- {
- return Compare(this, value);
- }
-
- // Returns the tick count corresponding to the given year, month, and day.
- // Will check the if the parameters are valid.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static long DateToTicks(int year, int month, int day)
- {
- if (year < 1 || year > 9999 || month < 1 || month > 12 || day < 1)
- {
- ThrowHelper.ThrowArgumentOutOfRange_BadYearMonthDay();
- }
-
- int[] days = IsLeapYear(year) ? s_daysToMonth366 : s_daysToMonth365;
- if (day > days[month] - days[month - 1])
- {
- ThrowHelper.ThrowArgumentOutOfRange_BadYearMonthDay();
- }
-
- int y = year - 1;
- int n = y * 365 + y / 4 - y / 100 + y / 400 + days[month - 1] + day - 1;
- return n * TicksPerDay;
- }
-
- // Return the tick count corresponding to the given hour, minute, second.
- // Will check the if the parameters are valid.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static long TimeToTicks(int hour, int minute, int second)
- {
- // TimeSpan.TimeToTicks is a family access function which does no error checking, so
- // we need to put some error checking out here.
- if ((uint)hour >= 24 || (uint)minute >= 60 || (uint)second >= 60)
- {
- ThrowHelper.ThrowArgumentOutOfRange_BadHourMinuteSecond();
- }
-
- return TimeSpan.TimeToTicks(hour, minute, second);
- }
-
- // Returns the number of days in the month given by the year and
- // month arguments.
- //
- public static int DaysInMonth(int year, int month)
- {
- if (month < 1 || month > 12) throw new ArgumentOutOfRangeException(nameof(month), SR.ArgumentOutOfRange_Month);
- // IsLeapYear checks the year argument
- int[] days = IsLeapYear(year) ? s_daysToMonth366 : s_daysToMonth365;
- return days[month] - days[month - 1];
- }
-
- // Converts an OLE Date to a tick count.
- // This function is duplicated in COMDateTime.cpp
- internal static long DoubleDateToTicks(double value)
- {
- // The check done this way will take care of NaN
- if (!(value < OADateMaxAsDouble) || !(value > OADateMinAsDouble))
- throw new ArgumentException(SR.Arg_OleAutDateInvalid);
-
- // Conversion to long will not cause an overflow here, as at this point the "value" is in between OADateMinAsDouble and OADateMaxAsDouble
- long millis = (long)(value * MillisPerDay + (value >= 0 ? 0.5 : -0.5));
- // The interesting thing here is when you have a value like 12.5 it all positive 12 days and 12 hours from 01/01/1899
- // However if you a value of -12.25 it is minus 12 days but still positive 6 hours, almost as though you meant -11.75 all negative
- // This line below fixes up the millis in the negative case
- if (millis < 0)
- {
- millis -= (millis % MillisPerDay) * 2;
- }
-
- millis += DoubleDateOffset / TicksPerMillisecond;
-
- if (millis < 0 || millis >= MaxMillis) throw new ArgumentException(SR.Arg_OleAutDateScale);
- return millis * TicksPerMillisecond;
- }
-
- // Checks if this DateTime is equal to a given object. Returns
- // true if the given object is a boxed DateTime and its value
- // is equal to the value of this DateTime. Returns false
- // otherwise.
- //
- public override bool Equals(object? value)
- {
- if (value is DateTime)
- {
- return InternalTicks == ((DateTime)value).InternalTicks;
- }
- return false;
- }
-
- public bool Equals(DateTime value)
- {
- return InternalTicks == value.InternalTicks;
- }
-
- // Compares two DateTime values for equality. Returns true if
- // the two DateTime values are equal, or false if they are
- // not equal.
- //
- public static bool Equals(DateTime t1, DateTime t2)
- {
- return t1.InternalTicks == t2.InternalTicks;
- }
-
- public static DateTime FromBinary(long dateData)
- {
- if ((dateData & (unchecked((long)LocalMask))) != 0)
- {
- // Local times need to be adjusted as you move from one time zone to another,
- // just as they are when serializing in text. As such the format for local times
- // changes to store the ticks of the UTC time, but with flags that look like a
- // local date.
- long ticks = dateData & (unchecked((long)TicksMask));
- // Negative ticks are stored in the top part of the range and should be converted back into a negative number
- if (ticks > TicksCeiling - TicksPerDay)
- {
- ticks -= TicksCeiling;
- }
- // Convert the ticks back to local. If the UTC ticks are out of range, we need to default to
- // the UTC offset from MinValue and MaxValue to be consistent with Parse.
- bool isAmbiguousLocalDst = false;
- long offsetTicks;
- if (ticks < MinTicks)
- {
- offsetTicks = TimeZoneInfo.GetLocalUtcOffset(DateTime.MinValue, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks;
- }
- else if (ticks > MaxTicks)
- {
- offsetTicks = TimeZoneInfo.GetLocalUtcOffset(DateTime.MaxValue, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks;
- }
- else
- {
- // Because the ticks conversion between UTC and local is lossy, we need to capture whether the
- // time is in a repeated hour so that it can be passed to the DateTime constructor.
- DateTime utcDt = new DateTime(ticks, DateTimeKind.Utc);
- bool isDaylightSavings = false;
- offsetTicks = TimeZoneInfo.GetUtcOffsetFromUtc(utcDt, TimeZoneInfo.Local, out isDaylightSavings, out isAmbiguousLocalDst).Ticks;
- }
- ticks += offsetTicks;
- // Another behaviour of parsing is to cause small times to wrap around, so that they can be used
- // to compare times of day
- if (ticks < 0)
- {
- ticks += TicksPerDay;
- }
- if (ticks < MinTicks || ticks > MaxTicks)
- {
- throw new ArgumentException(SR.Argument_DateTimeBadBinaryData, nameof(dateData));
- }
- return new DateTime(ticks, DateTimeKind.Local, isAmbiguousLocalDst);
- }
- else
- {
- return DateTime.FromBinaryRaw(dateData);
- }
- }
-
- // A version of ToBinary that uses the real representation and does not adjust local times. This is needed for
- // scenarios where the serialized data must maintain compatibility
- internal static DateTime FromBinaryRaw(long dateData)
- {
- long ticks = dateData & (long)TicksMask;
- if (ticks < MinTicks || ticks > MaxTicks)
- throw new ArgumentException(SR.Argument_DateTimeBadBinaryData, nameof(dateData));
- return new DateTime((ulong)dateData);
- }
-
- // Creates a DateTime from a Windows filetime. A Windows filetime is
- // a long representing the date and time as the number of
- // 100-nanosecond intervals that have elapsed since 1/1/1601 12:00am.
- //
- public static DateTime FromFileTime(long fileTime)
- {
- return FromFileTimeUtc(fileTime).ToLocalTime();
- }
-
- public static DateTime FromFileTimeUtc(long fileTime)
- {
- if (fileTime < 0 || fileTime > MaxTicks - FileTimeOffset)
- {
- throw new ArgumentOutOfRangeException(nameof(fileTime), SR.ArgumentOutOfRange_FileTimeInvalid);
- }
-
-#pragma warning disable 162 // Unrechable code on Unix
- if (s_systemSupportsLeapSeconds)
- {
- return FromFileTimeLeapSecondsAware(fileTime);
- }
-#pragma warning restore 162
-
- // This is the ticks in Universal time for this fileTime.
- long universalTicks = fileTime + FileTimeOffset;
- return new DateTime(universalTicks, DateTimeKind.Utc);
- }
-
- // Creates a DateTime from an OLE Automation Date.
- //
- public static DateTime FromOADate(double d)
- {
- return new DateTime(DoubleDateToTicks(d), DateTimeKind.Unspecified);
- }
-
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- // Serialize both the old and the new format
- info.AddValue(TicksField, InternalTicks);
- info.AddValue(DateDataField, _dateData);
- }
-
- public bool IsDaylightSavingTime()
- {
- if (Kind == DateTimeKind.Utc)
- {
- return false;
- }
- return TimeZoneInfo.Local.IsDaylightSavingTime(this, TimeZoneInfoOptions.NoThrowOnInvalidTime);
- }
-
- public static DateTime SpecifyKind(DateTime value, DateTimeKind kind)
- {
- return new DateTime(value.InternalTicks, kind);
- }
-
- public long ToBinary()
- {
- if (Kind == DateTimeKind.Local)
- {
- // Local times need to be adjusted as you move from one time zone to another,
- // just as they are when serializing in text. As such the format for local times
- // changes to store the ticks of the UTC time, but with flags that look like a
- // local date.
-
- // To match serialization in text we need to be able to handle cases where
- // the UTC value would be out of range. Unused parts of the ticks range are
- // used for this, so that values just past max value are stored just past the
- // end of the maximum range, and values just below minimum value are stored
- // at the end of the ticks area, just below 2^62.
- TimeSpan offset = TimeZoneInfo.GetLocalUtcOffset(this, TimeZoneInfoOptions.NoThrowOnInvalidTime);
- long ticks = Ticks;
- long storedTicks = ticks - offset.Ticks;
- if (storedTicks < 0)
- {
- storedTicks = TicksCeiling + storedTicks;
- }
- return storedTicks | (unchecked((long)LocalMask));
- }
- else
- {
- return (long)_dateData;
- }
- }
-
- // Returns the date part of this DateTime. The resulting value
- // corresponds to this DateTime with the time-of-day part set to
- // zero (midnight).
- //
- public DateTime Date
- {
- get
- {
- long ticks = InternalTicks;
- return new DateTime((ulong)(ticks - ticks % TicksPerDay) | InternalKind);
- }
- }
-
- // Returns a given date part of this DateTime. This method is used
- // to compute the year, day-of-year, month, or day part.
- private int GetDatePart(int part)
- {
- long ticks = InternalTicks;
- // n = number of days since 1/1/0001
- int n = (int)(ticks / TicksPerDay);
- // y400 = number of whole 400-year periods since 1/1/0001
- int y400 = n / DaysPer400Years;
- // n = day number within 400-year period
- n -= y400 * DaysPer400Years;
- // y100 = number of whole 100-year periods within 400-year period
- int y100 = n / DaysPer100Years;
- // Last 100-year period has an extra day, so decrement result if 4
- if (y100 == 4) y100 = 3;
- // n = day number within 100-year period
- n -= y100 * DaysPer100Years;
- // y4 = number of whole 4-year periods within 100-year period
- int y4 = n / DaysPer4Years;
- // n = day number within 4-year period
- n -= y4 * DaysPer4Years;
- // y1 = number of whole years within 4-year period
- int y1 = n / DaysPerYear;
- // Last year has an extra day, so decrement result if 4
- if (y1 == 4) y1 = 3;
- // If year was requested, compute and return it
- if (part == DatePartYear)
- {
- return y400 * 400 + y100 * 100 + y4 * 4 + y1 + 1;
- }
- // n = day number within year
- n -= y1 * DaysPerYear;
- // If day-of-year was requested, return it
- if (part == DatePartDayOfYear) return n + 1;
- // Leap year calculation looks different from IsLeapYear since y1, y4,
- // and y100 are relative to year 1, not year 0
- bool leapYear = y1 == 3 && (y4 != 24 || y100 == 3);
- int[] days = leapYear ? s_daysToMonth366 : s_daysToMonth365;
- // All months have less than 32 days, so n >> 5 is a good conservative
- // estimate for the month
- int m = (n >> 5) + 1;
- // m = 1-based month number
- while (n >= days[m]) m++;
- // If month was requested, return it
- if (part == DatePartMonth) return m;
- // Return 1-based day-of-month
- return n - days[m - 1] + 1;
- }
-
- // Exactly the same as GetDatePart(int part), except computing all of
- // year/month/day rather than just one of them. Used when all three
- // are needed rather than redoing the computations for each.
- internal void GetDatePart(out int year, out int month, out int day)
- {
- long ticks = InternalTicks;
- // n = number of days since 1/1/0001
- int n = (int)(ticks / TicksPerDay);
- // y400 = number of whole 400-year periods since 1/1/0001
- int y400 = n / DaysPer400Years;
- // n = day number within 400-year period
- n -= y400 * DaysPer400Years;
- // y100 = number of whole 100-year periods within 400-year period
- int y100 = n / DaysPer100Years;
- // Last 100-year period has an extra day, so decrement result if 4
- if (y100 == 4) y100 = 3;
- // n = day number within 100-year period
- n -= y100 * DaysPer100Years;
- // y4 = number of whole 4-year periods within 100-year period
- int y4 = n / DaysPer4Years;
- // n = day number within 4-year period
- n -= y4 * DaysPer4Years;
- // y1 = number of whole years within 4-year period
- int y1 = n / DaysPerYear;
- // Last year has an extra day, so decrement result if 4
- if (y1 == 4) y1 = 3;
- // compute year
- year = y400 * 400 + y100 * 100 + y4 * 4 + y1 + 1;
- // n = day number within year
- n -= y1 * DaysPerYear;
- // dayOfYear = n + 1;
- // Leap year calculation looks different from IsLeapYear since y1, y4,
- // and y100 are relative to year 1, not year 0
- bool leapYear = y1 == 3 && (y4 != 24 || y100 == 3);
- int[] days = leapYear ? s_daysToMonth366 : s_daysToMonth365;
- // All months have less than 32 days, so n >> 5 is a good conservative
- // estimate for the month
- int m = (n >> 5) + 1;
- // m = 1-based month number
- while (n >= days[m]) m++;
- // compute month and day
- month = m;
- day = n - days[m - 1] + 1;
- }
-
- // Returns the day-of-month part of this DateTime. The returned
- // value is an integer between 1 and 31.
- //
- public int Day => GetDatePart(DatePartDay);
-
- // Returns the day-of-week part of this DateTime. The returned value
- // is an integer between 0 and 6, where 0 indicates Sunday, 1 indicates
- // Monday, 2 indicates Tuesday, 3 indicates Wednesday, 4 indicates
- // Thursday, 5 indicates Friday, and 6 indicates Saturday.
- //
- public DayOfWeek DayOfWeek => (DayOfWeek)((InternalTicks / TicksPerDay + 1) % 7);
-
- // Returns the day-of-year part of this DateTime. The returned value
- // is an integer between 1 and 366.
- //
- public int DayOfYear => GetDatePart(DatePartDayOfYear);
-
- // Returns the hash code for this DateTime.
- //
- public override int GetHashCode()
- {
- long ticks = InternalTicks;
- return unchecked((int)ticks) ^ (int)(ticks >> 32);
- }
-
- // Returns the hour part of this DateTime. The returned value is an
- // integer between 0 and 23.
- //
- public int Hour => (int)((InternalTicks / TicksPerHour) % 24);
-
- internal bool IsAmbiguousDaylightSavingTime() =>
- InternalKind == KindLocalAmbiguousDst;
-
- public DateTimeKind Kind =>
- InternalKind switch
- {
- KindUnspecified => DateTimeKind.Unspecified,
- KindUtc => DateTimeKind.Utc,
- _ => DateTimeKind.Local,
- };
-
- // Returns the millisecond part of this DateTime. The returned value
- // is an integer between 0 and 999.
- //
- public int Millisecond => (int)((InternalTicks / TicksPerMillisecond) % 1000);
-
- // Returns the minute part of this DateTime. The returned value is
- // an integer between 0 and 59.
- //
- public int Minute => (int)((InternalTicks / TicksPerMinute) % 60);
-
- // Returns the month part of this DateTime. The returned value is an
- // integer between 1 and 12.
- //
- public int Month => GetDatePart(DatePartMonth);
-
- // Returns a DateTime representing the current date and time. The
- // resolution of the returned value depends on the system timer.
- public static DateTime Now
- {
- get
- {
- DateTime utc = UtcNow;
- bool isAmbiguousLocalDst;
- long offset = TimeZoneInfo.GetDateTimeNowUtcOffsetFromUtc(utc, out isAmbiguousLocalDst).Ticks;
- long tick = utc.Ticks + offset;
- if (tick > DateTime.MaxTicks)
- {
- return new DateTime(DateTime.MaxTicks, DateTimeKind.Local);
- }
- if (tick < DateTime.MinTicks)
- {
- return new DateTime(DateTime.MinTicks, DateTimeKind.Local);
- }
- return new DateTime(tick, DateTimeKind.Local, isAmbiguousLocalDst);
- }
- }
-
- // Returns the second part of this DateTime. The returned value is
- // an integer between 0 and 59.
- //
- public int Second => (int)((InternalTicks / TicksPerSecond) % 60);
-
- // Returns the tick count for this DateTime. The returned value is
- // the number of 100-nanosecond intervals that have elapsed since 1/1/0001
- // 12:00am.
- //
- public long Ticks => InternalTicks;
-
- // Returns the time-of-day part of this DateTime. The returned value
- // is a TimeSpan that indicates the time elapsed since midnight.
- //
- public TimeSpan TimeOfDay => new TimeSpan(InternalTicks % TicksPerDay);
-
- // Returns a DateTime representing the current date. The date part
- // of the returned value is the current date, and the time-of-day part of
- // the returned value is zero (midnight).
- //
- public static DateTime Today => DateTime.Now.Date;
-
- // Returns the year part of this DateTime. The returned value is an
- // integer between 1 and 9999.
- //
- public int Year => GetDatePart(DatePartYear);
-
- // Checks whether a given year is a leap year. This method returns true if
- // year is a leap year, or false if not.
- //
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsLeapYear(int year)
- {
- if (year < 1 || year > 9999)
- {
- ThrowHelper.ThrowArgumentOutOfRange_Year();
- }
- return (year & 3) == 0 && ((year & 15) == 0 || (year % 25) != 0);
- }
-
- // Constructs a DateTime from a string. The string must specify a
- // date and optionally a time in a culture-specific or universal format.
- // Leading and trailing whitespace characters are allowed.
- //
- public static DateTime Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return DateTimeParse.Parse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None);
- }
-
- // Constructs a DateTime from a string. The string must specify a
- // date and optionally a time in a culture-specific or universal format.
- // Leading and trailing whitespace characters are allowed.
- //
- public static DateTime Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), DateTimeStyles.None);
- }
-
- public static DateTime Parse(string s, IFormatProvider? provider, DateTimeStyles styles)
- {
- DateTimeFormatInfo.ValidateStyles(styles, nameof(styles));
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), styles);
- }
-
- public static DateTime Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null, DateTimeStyles styles = DateTimeStyles.None)
- {
- DateTimeFormatInfo.ValidateStyles(styles, nameof(styles));
- return DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), styles);
- }
-
- // Constructs a DateTime from a string. The string must specify a
- // date and optionally a time in a culture-specific or universal format.
- // Leading and trailing whitespace characters are allowed.
- //
- public static DateTime ParseExact(string s, string format, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format);
- return DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), DateTimeStyles.None);
- }
-
- // Constructs a DateTime from a string. The string must specify a
- // date and optionally a time in a culture-specific or universal format.
- // Leading and trailing whitespace characters are allowed.
- //
- public static DateTime ParseExact(string s, string format, IFormatProvider? provider, DateTimeStyles style)
- {
- DateTimeFormatInfo.ValidateStyles(style, nameof(style));
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format);
- return DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style);
- }
-
- public static DateTime ParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, IFormatProvider? provider, DateTimeStyles style = DateTimeStyles.None)
- {
- DateTimeFormatInfo.ValidateStyles(style, nameof(style));
- return DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style);
- }
-
- public static DateTime ParseExact(string s, string[] formats, IFormatProvider? provider, DateTimeStyles style)
- {
- DateTimeFormatInfo.ValidateStyles(style, nameof(style));
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return DateTimeParse.ParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style);
- }
-
- public static DateTime ParseExact(ReadOnlySpan<char> s, string[] formats, IFormatProvider? provider, DateTimeStyles style = DateTimeStyles.None)
- {
- DateTimeFormatInfo.ValidateStyles(style, nameof(style));
- return DateTimeParse.ParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style);
- }
-
- public TimeSpan Subtract(DateTime value)
- {
- return new TimeSpan(InternalTicks - value.InternalTicks);
- }
-
- public DateTime Subtract(TimeSpan value)
- {
- long ticks = InternalTicks;
- long valueTicks = value._ticks;
- if (ticks - MinTicks < valueTicks || ticks - MaxTicks > valueTicks)
- {
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_DateArithmetic);
- }
- return new DateTime((ulong)(ticks - valueTicks) | InternalKind);
- }
-
- // This function is duplicated in COMDateTime.cpp
- private static double TicksToOADate(long value)
- {
- if (value == 0)
- return 0.0; // Returns OleAut's zero'ed date value.
- if (value < TicksPerDay) // This is a fix for VB. They want the default day to be 1/1/0001 rathar then 12/30/1899.
- value += DoubleDateOffset; // We could have moved this fix down but we would like to keep the bounds check.
- if (value < OADateMinAsTicks)
- throw new OverflowException(SR.Arg_OleAutDateInvalid);
- // Currently, our max date == OA's max date (12/31/9999), so we don't
- // need an overflow check in that direction.
- long millis = (value - DoubleDateOffset) / TicksPerMillisecond;
- if (millis < 0)
- {
- long frac = millis % MillisPerDay;
- if (frac != 0) millis -= (MillisPerDay + frac) * 2;
- }
- return (double)millis / MillisPerDay;
- }
-
- // Converts the DateTime instance into an OLE Automation compatible
- // double date.
- public double ToOADate()
- {
- return TicksToOADate(InternalTicks);
- }
-
- public long ToFileTime()
- {
- // Treats the input as local if it is not specified
- return ToUniversalTime().ToFileTimeUtc();
- }
-
- public long ToFileTimeUtc()
- {
- // Treats the input as universal if it is not specified
- long ticks = ((InternalKind & LocalMask) != 0) ? ToUniversalTime().InternalTicks : this.InternalTicks;
-
-#pragma warning disable 162 // Unrechable code on Unix
- if (s_systemSupportsLeapSeconds)
- {
- return ToFileTimeLeapSecondsAware(ticks);
- }
-#pragma warning restore 162
-
- ticks -= FileTimeOffset;
- if (ticks < 0)
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_FileTimeInvalid);
- }
-
- return ticks;
- }
-
- public DateTime ToLocalTime()
- {
- return ToLocalTime(false);
- }
-
- internal DateTime ToLocalTime(bool throwOnOverflow)
- {
- if (Kind == DateTimeKind.Local)
- {
- return this;
- }
- bool isDaylightSavings = false;
- bool isAmbiguousLocalDst = false;
- long offset = TimeZoneInfo.GetUtcOffsetFromUtc(this, TimeZoneInfo.Local, out isDaylightSavings, out isAmbiguousLocalDst).Ticks;
- long tick = Ticks + offset;
- if (tick > DateTime.MaxTicks)
- {
- if (throwOnOverflow)
- throw new ArgumentException(SR.Arg_ArgumentOutOfRangeException);
- else
- return new DateTime(DateTime.MaxTicks, DateTimeKind.Local);
- }
- if (tick < DateTime.MinTicks)
- {
- if (throwOnOverflow)
- throw new ArgumentException(SR.Arg_ArgumentOutOfRangeException);
- else
- return new DateTime(DateTime.MinTicks, DateTimeKind.Local);
- }
- return new DateTime(tick, DateTimeKind.Local, isAmbiguousLocalDst);
- }
-
- public string ToLongDateString()
- {
- return DateTimeFormat.Format(this, "D", null);
- }
-
- public string ToLongTimeString()
- {
- return DateTimeFormat.Format(this, "T", null);
- }
-
- public string ToShortDateString()
- {
- return DateTimeFormat.Format(this, "d", null);
- }
-
- public string ToShortTimeString()
- {
- return DateTimeFormat.Format(this, "t", null);
- }
-
- public override string ToString()
- {
- return DateTimeFormat.Format(this, null, null);
- }
-
- public string ToString(string? format)
- {
- return DateTimeFormat.Format(this, format, null);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return DateTimeFormat.Format(this, null, provider);
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- return DateTimeFormat.Format(this, format, provider);
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null) =>
- DateTimeFormat.TryFormat(this, destination, out charsWritten, format, provider);
-
- public DateTime ToUniversalTime()
- {
- return TimeZoneInfo.ConvertTimeToUtc(this, TimeZoneInfoOptions.NoThrowOnInvalidTime);
- }
-
- public static bool TryParse(string? s, out DateTime result)
- {
- if (s == null)
- {
- result = default;
- return false;
- }
- return DateTimeParse.TryParse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, out DateTime result)
- {
- return DateTimeParse.TryParse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out result);
- }
-
- public static bool TryParse(string? s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result)
- {
- DateTimeFormatInfo.ValidateStyles(styles, nameof(styles));
-
- if (s == null)
- {
- result = default;
- return false;
- }
-
- return DateTimeParse.TryParse(s, DateTimeFormatInfo.GetInstance(provider), styles, out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result)
- {
- DateTimeFormatInfo.ValidateStyles(styles, nameof(styles));
- return DateTimeParse.TryParse(s, DateTimeFormatInfo.GetInstance(provider), styles, out result);
- }
-
- public static bool TryParseExact(string? s, string? format, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
- {
- DateTimeFormatInfo.ValidateStyles(style, nameof(style));
-
- if (s == null || format == null)
- {
- result = default;
- return false;
- }
-
- return DateTimeParse.TryParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style, out result);
- }
-
- public static bool TryParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
- {
- DateTimeFormatInfo.ValidateStyles(style, nameof(style));
- return DateTimeParse.TryParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style, out result);
- }
-
- public static bool TryParseExact(string? s, string?[]? formats, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
- {
- DateTimeFormatInfo.ValidateStyles(style, nameof(style));
-
- if (s == null)
- {
- result = default;
- return false;
- }
-
- return DateTimeParse.TryParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style, out result);
- }
-
- public static bool TryParseExact(ReadOnlySpan<char> s, string?[]? formats, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
- {
- DateTimeFormatInfo.ValidateStyles(style, nameof(style));
- return DateTimeParse.TryParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style, out result);
- }
-
- public static DateTime operator +(DateTime d, TimeSpan t)
- {
- long ticks = d.InternalTicks;
- long valueTicks = t._ticks;
- if (valueTicks > MaxTicks - ticks || valueTicks < MinTicks - ticks)
- {
- throw new ArgumentOutOfRangeException(nameof(t), SR.ArgumentOutOfRange_DateArithmetic);
- }
- return new DateTime((ulong)(ticks + valueTicks) | d.InternalKind);
- }
-
- public static DateTime operator -(DateTime d, TimeSpan t)
- {
- long ticks = d.InternalTicks;
- long valueTicks = t._ticks;
- if (ticks - MinTicks < valueTicks || ticks - MaxTicks > valueTicks)
- {
- throw new ArgumentOutOfRangeException(nameof(t), SR.ArgumentOutOfRange_DateArithmetic);
- }
- return new DateTime((ulong)(ticks - valueTicks) | d.InternalKind);
- }
-
- public static TimeSpan operator -(DateTime d1, DateTime d2) => new TimeSpan(d1.InternalTicks - d2.InternalTicks);
-
- public static bool operator ==(DateTime d1, DateTime d2) => d1.InternalTicks == d2.InternalTicks;
-
- public static bool operator !=(DateTime d1, DateTime d2) => d1.InternalTicks != d2.InternalTicks;
-
- public static bool operator <(DateTime t1, DateTime t2) => t1.InternalTicks < t2.InternalTicks;
-
- public static bool operator <=(DateTime t1, DateTime t2) => t1.InternalTicks <= t2.InternalTicks;
-
- public static bool operator >(DateTime t1, DateTime t2) => t1.InternalTicks > t2.InternalTicks;
-
- public static bool operator >=(DateTime t1, DateTime t2) => t1.InternalTicks >= t2.InternalTicks;
-
- // Returns a string array containing all of the known date and time options for the
- // current culture. The strings returned are properly formatted date and
- // time strings for the current instance of DateTime.
- public string[] GetDateTimeFormats()
- {
- return GetDateTimeFormats(CultureInfo.CurrentCulture);
- }
-
- // Returns a string array containing all of the known date and time options for the
- // using the information provided by IFormatProvider. The strings returned are properly formatted date and
- // time strings for the current instance of DateTime.
- public string[] GetDateTimeFormats(IFormatProvider? provider)
- {
- return DateTimeFormat.GetAllDateTimes(this, DateTimeFormatInfo.GetInstance(provider));
- }
-
- // Returns a string array containing all of the date and time options for the
- // given format format and current culture. The strings returned are properly formatted date and
- // time strings for the current instance of DateTime.
- public string[] GetDateTimeFormats(char format)
- {
- return GetDateTimeFormats(format, CultureInfo.CurrentCulture);
- }
-
- // Returns a string array containing all of the date and time options for the
- // given format format and given culture. The strings returned are properly formatted date and
- // time strings for the current instance of DateTime.
- public string[] GetDateTimeFormats(char format, IFormatProvider? provider)
- {
- return DateTimeFormat.GetAllDateTimes(this, format, DateTimeFormatInfo.GetInstance(provider));
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.DateTime;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "Boolean"));
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "Char"));
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "SByte"));
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "Byte"));
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "Int16"));
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "UInt16"));
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "Int32"));
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "UInt32"));
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "Int64"));
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "UInt64"));
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "Single"));
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "Double"));
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "Decimal"));
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- return this;
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
-
- // Tries to construct a DateTime from a given year, month, day, hour,
- // minute, second and millisecond.
- //
- internal static bool TryCreate(int year, int month, int day, int hour, int minute, int second, int millisecond, out DateTime result)
- {
- result = DateTime.MinValue;
- if (year < 1 || year > 9999 || month < 1 || month > 12)
- {
- return false;
- }
- int[] days = IsLeapYear(year) ? s_daysToMonth366 : s_daysToMonth365;
- if (day < 1 || day > days[month] - days[month - 1])
- {
- return false;
- }
- if (hour < 0 || hour >= 24 || minute < 0 || minute >= 60 || second < 0 || second > 60)
- {
- return false;
- }
- if (millisecond < 0 || millisecond >= MillisPerSecond)
- {
- return false;
- }
-
- if (second == 60)
- {
- if (s_systemSupportsLeapSeconds && IsValidTimeWithLeapSeconds(year, month, day, hour, minute, second, DateTimeKind.Unspecified))
- {
- // if we have leap second (second = 60) then we'll need to check if it is valid time.
- // if it is valid, then we adjust the second to 59 so DateTime will consider this second is last second
- // of this minute.
- // if it is not valid time, we'll eventually throw.
- // although this is unspecified datetime kind, we'll assume the passed time is UTC to check the leap seconds.
- second = 59;
- }
- else
- {
- return false;
- }
- }
-
- long ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second);
-
- ticks += millisecond * TicksPerMillisecond;
- if (ticks < MinTicks || ticks > MaxTicks)
- {
- return false;
- }
- result = new DateTime(ticks, DateTimeKind.Unspecified);
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DateTimeKind.cs b/netcore/System.Private.CoreLib/shared/System/DateTimeKind.cs
deleted file mode 100644
index cb40c2a1898..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DateTimeKind.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System
-{
- // This enum is used to indentify DateTime instances in cases when they are known to be in local time,
- // UTC time or if this information has not been specified or is not applicable.
-
- public enum DateTimeKind
- {
- Unspecified = 0,
- Utc = 1,
- Local = 2,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DateTimeOffset.cs b/netcore/System.Private.CoreLib/shared/System/DateTimeOffset.cs
deleted file mode 100644
index 81a06124163..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DateTimeOffset.cs
+++ /dev/null
@@ -1,855 +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 System.Diagnostics;
-using System.Globalization;
-using System.Runtime.InteropServices;
-using System.Runtime.Serialization;
-
-namespace System
-{
- // DateTimeOffset is a value type that consists of a DateTime and a time zone offset,
- // ie. how far away the time is from GMT. The DateTime is stored whole, and the offset
- // is stored as an Int16 internally to save space, but presented as a TimeSpan.
- //
- // The range is constrained so that both the represented clock time and the represented
- // UTC time fit within the boundaries of MaxValue. This gives it the same range as DateTime
- // for actual UTC times, and a slightly constrained range on one end when an offset is
- // present.
- //
- // This class should be substitutable for date time in most cases; so most operations
- // effectively work on the clock time. However, the underlying UTC time is what counts
- // for the purposes of identity, sorting and subtracting two instances.
- //
- //
- // There are theoretically two date times stored, the UTC and the relative local representation
- // or the 'clock' time. It actually does not matter which is stored in m_dateTime, so it is desirable
- // for most methods to go through the helpers UtcDateTime and ClockDateTime both to abstract this
- // out and for internal readability.
-
- [StructLayout(LayoutKind.Auto)]
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct DateTimeOffset : IComparable, IFormattable, IComparable<DateTimeOffset>, IEquatable<DateTimeOffset>, ISerializable, IDeserializationCallback, ISpanFormattable
- {
- // Constants
- internal const long MaxOffset = TimeSpan.TicksPerHour * 14;
- internal const long MinOffset = -MaxOffset;
-
- private const long UnixEpochSeconds = DateTime.UnixEpochTicks / TimeSpan.TicksPerSecond; // 62,135,596,800
- private const long UnixEpochMilliseconds = DateTime.UnixEpochTicks / TimeSpan.TicksPerMillisecond; // 62,135,596,800,000
-
- internal const long UnixMinSeconds = DateTime.MinTicks / TimeSpan.TicksPerSecond - UnixEpochSeconds;
- internal const long UnixMaxSeconds = DateTime.MaxTicks / TimeSpan.TicksPerSecond - UnixEpochSeconds;
-
- // Static Fields
- public static readonly DateTimeOffset MinValue = new DateTimeOffset(DateTime.MinTicks, TimeSpan.Zero);
- public static readonly DateTimeOffset MaxValue = new DateTimeOffset(DateTime.MaxTicks, TimeSpan.Zero);
- public static readonly DateTimeOffset UnixEpoch = new DateTimeOffset(DateTime.UnixEpochTicks, TimeSpan.Zero);
-
- // Instance Fields
- private readonly DateTime _dateTime;
- private readonly short _offsetMinutes;
-
- // Constructors
-
- // Constructs a DateTimeOffset from a tick count and offset
- public DateTimeOffset(long ticks, TimeSpan offset)
- {
- _offsetMinutes = ValidateOffset(offset);
- // Let the DateTime constructor do the range checks
- DateTime dateTime = new DateTime(ticks);
- _dateTime = ValidateDate(dateTime, offset);
- }
-
- // Constructs a DateTimeOffset from a DateTime. For Local and Unspecified kinds,
- // extracts the local offset. For UTC, creates a UTC instance with a zero offset.
- public DateTimeOffset(DateTime dateTime)
- {
- TimeSpan offset;
- if (dateTime.Kind != DateTimeKind.Utc)
- {
- // Local and Unspecified are both treated as Local
- offset = TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
- }
- else
- {
- offset = new TimeSpan(0);
- }
- _offsetMinutes = ValidateOffset(offset);
- _dateTime = ValidateDate(dateTime, offset);
- }
-
- // Constructs a DateTimeOffset from a DateTime. And an offset. Always makes the clock time
- // consistent with the DateTime. For Utc ensures the offset is zero. For local, ensures that
- // the offset corresponds to the local.
- public DateTimeOffset(DateTime dateTime, TimeSpan offset)
- {
- if (dateTime.Kind == DateTimeKind.Local)
- {
- if (offset != TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime))
- {
- throw new ArgumentException(SR.Argument_OffsetLocalMismatch, nameof(offset));
- }
- }
- else if (dateTime.Kind == DateTimeKind.Utc)
- {
- if (offset != TimeSpan.Zero)
- {
- throw new ArgumentException(SR.Argument_OffsetUtcMismatch, nameof(offset));
- }
- }
- _offsetMinutes = ValidateOffset(offset);
- _dateTime = ValidateDate(dateTime, offset);
- }
-
- // Constructs a DateTimeOffset from a given year, month, day, hour,
- // minute, second and offset.
- public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, TimeSpan offset)
- {
- _offsetMinutes = ValidateOffset(offset);
-
- int originalSecond = second;
- if (second == 60 && DateTime.s_systemSupportsLeapSeconds)
- {
- // Reset the leap second to 59 for now and then we'll validate it after getting the final UTC time.
- second = 59;
- }
-
- _dateTime = ValidateDate(new DateTime(year, month, day, hour, minute, second), offset);
-
- if (originalSecond == 60 &&
- !DateTime.IsValidTimeWithLeapSeconds(_dateTime.Year, _dateTime.Month, _dateTime.Day, _dateTime.Hour, _dateTime.Minute, 60, DateTimeKind.Utc))
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond);
- }
- }
-
- // Constructs a DateTimeOffset from a given year, month, day, hour,
- // minute, second, millsecond and offset
- public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset)
- {
- _offsetMinutes = ValidateOffset(offset);
-
- int originalSecond = second;
- if (second == 60 && DateTime.s_systemSupportsLeapSeconds)
- {
- // Reset the leap second to 59 for now and then we'll validate it after getting the final UTC time.
- second = 59;
- }
-
- _dateTime = ValidateDate(new DateTime(year, month, day, hour, minute, second, millisecond), offset);
-
- if (originalSecond == 60 &&
- !DateTime.IsValidTimeWithLeapSeconds(_dateTime.Year, _dateTime.Month, _dateTime.Day, _dateTime.Hour, _dateTime.Minute, 60, DateTimeKind.Utc))
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond);
- }
- }
-
- // Constructs a DateTimeOffset from a given year, month, day, hour,
- // minute, second, millsecond, Calendar and offset.
- public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, TimeSpan offset)
- {
- _offsetMinutes = ValidateOffset(offset);
-
- int originalSecond = second;
- if (second == 60 && DateTime.s_systemSupportsLeapSeconds)
- {
- // Reset the leap second to 59 for now and then we'll validate it after getting the final UTC time.
- second = 59;
- }
-
- _dateTime = ValidateDate(new DateTime(year, month, day, hour, minute, second, millisecond, calendar), offset);
-
- if (originalSecond == 60 &&
- !DateTime.IsValidTimeWithLeapSeconds(_dateTime.Year, _dateTime.Month, _dateTime.Day, _dateTime.Hour, _dateTime.Minute, 60, DateTimeKind.Utc))
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond);
- }
- }
-
- // Returns a DateTimeOffset representing the current date and time. The
- // resolution of the returned value depends on the system timer.
- public static DateTimeOffset Now => ToLocalTime(DateTime.UtcNow, true);
-
- public static DateTimeOffset UtcNow => new DateTimeOffset(DateTime.UtcNow);
-
- public DateTime DateTime => ClockDateTime;
-
- public DateTime UtcDateTime => DateTime.SpecifyKind(_dateTime, DateTimeKind.Utc);
-
- public DateTime LocalDateTime => UtcDateTime.ToLocalTime();
-
- // Adjust to a given offset with the same UTC time. Can throw ArgumentException
- //
- public DateTimeOffset ToOffset(TimeSpan offset) =>
- new DateTimeOffset((_dateTime + offset).Ticks, offset);
-
- // Instance Properties
-
- // The clock or visible time represented. This is just a wrapper around the internal date because this is
- // the chosen storage mechanism. Going through this helper is good for readability and maintainability.
- // This should be used for display but not identity.
- private DateTime ClockDateTime => new DateTime((_dateTime + Offset).Ticks, DateTimeKind.Unspecified);
-
- // Returns the date part of this DateTimeOffset. The resulting value
- // corresponds to this DateTimeOffset with the time-of-day part set to
- // zero (midnight).
- //
- public DateTime Date => ClockDateTime.Date;
-
- // Returns the day-of-month part of this DateTimeOffset. The returned
- // value is an integer between 1 and 31.
- //
- public int Day => ClockDateTime.Day;
-
- // Returns the day-of-week part of this DateTimeOffset. The returned value
- // is an integer between 0 and 6, where 0 indicates Sunday, 1 indicates
- // Monday, 2 indicates Tuesday, 3 indicates Wednesday, 4 indicates
- // Thursday, 5 indicates Friday, and 6 indicates Saturday.
- //
- public DayOfWeek DayOfWeek => ClockDateTime.DayOfWeek;
-
- // Returns the day-of-year part of this DateTimeOffset. The returned value
- // is an integer between 1 and 366.
- //
- public int DayOfYear => ClockDateTime.DayOfYear;
-
- // Returns the hour part of this DateTimeOffset. The returned value is an
- // integer between 0 and 23.
- //
- public int Hour => ClockDateTime.Hour;
-
- // Returns the millisecond part of this DateTimeOffset. The returned value
- // is an integer between 0 and 999.
- //
- public int Millisecond => ClockDateTime.Millisecond;
-
- // Returns the minute part of this DateTimeOffset. The returned value is
- // an integer between 0 and 59.
- //
- public int Minute => ClockDateTime.Minute;
-
- // Returns the month part of this DateTimeOffset. The returned value is an
- // integer between 1 and 12.
- //
- public int Month => ClockDateTime.Month;
-
- public TimeSpan Offset => new TimeSpan(0, _offsetMinutes, 0);
-
- // Returns the second part of this DateTimeOffset. The returned value is
- // an integer between 0 and 59.
- //
- public int Second => ClockDateTime.Second;
-
- // Returns the tick count for this DateTimeOffset. The returned value is
- // the number of 100-nanosecond intervals that have elapsed since 1/1/0001
- // 12:00am.
- //
- public long Ticks => ClockDateTime.Ticks;
-
- public long UtcTicks => UtcDateTime.Ticks;
-
- // Returns the time-of-day part of this DateTimeOffset. The returned value
- // is a TimeSpan that indicates the time elapsed since midnight.
- //
- public TimeSpan TimeOfDay => ClockDateTime.TimeOfDay;
-
- // Returns the year part of this DateTimeOffset. The returned value is an
- // integer between 1 and 9999.
- //
- public int Year => ClockDateTime.Year;
-
- // Returns the DateTimeOffset resulting from adding the given
- // TimeSpan to this DateTimeOffset.
- //
- public DateTimeOffset Add(TimeSpan timeSpan) =>
- new DateTimeOffset(ClockDateTime.Add(timeSpan), Offset);
-
- // Returns the DateTimeOffset resulting from adding a fractional number of
- // days to this DateTimeOffset. The result is computed by rounding the
- // fractional number of days given by value to the nearest
- // millisecond, and adding that interval to this DateTimeOffset. The
- // value argument is permitted to be negative.
- //
- public DateTimeOffset AddDays(double days) =>
- new DateTimeOffset(ClockDateTime.AddDays(days), Offset);
-
- // Returns the DateTimeOffset resulting from adding a fractional number of
- // hours to this DateTimeOffset. The result is computed by rounding the
- // fractional number of hours given by value to the nearest
- // millisecond, and adding that interval to this DateTimeOffset. The
- // value argument is permitted to be negative.
- //
- public DateTimeOffset AddHours(double hours) =>
- new DateTimeOffset(ClockDateTime.AddHours(hours), Offset);
-
- // Returns the DateTimeOffset resulting from the given number of
- // milliseconds to this DateTimeOffset. The result is computed by rounding
- // the number of milliseconds given by value to the nearest integer,
- // and adding that interval to this DateTimeOffset. The value
- // argument is permitted to be negative.
- //
- public DateTimeOffset AddMilliseconds(double milliseconds) =>
- new DateTimeOffset(ClockDateTime.AddMilliseconds(milliseconds), Offset);
-
- // Returns the DateTimeOffset resulting from adding a fractional number of
- // minutes to this DateTimeOffset. The result is computed by rounding the
- // fractional number of minutes given by value to the nearest
- // millisecond, and adding that interval to this DateTimeOffset. The
- // value argument is permitted to be negative.
- //
- public DateTimeOffset AddMinutes(double minutes) =>
- new DateTimeOffset(ClockDateTime.AddMinutes(minutes), Offset);
-
- public DateTimeOffset AddMonths(int months) =>
- new DateTimeOffset(ClockDateTime.AddMonths(months), Offset);
-
- // Returns the DateTimeOffset resulting from adding a fractional number of
- // seconds to this DateTimeOffset. The result is computed by rounding the
- // fractional number of seconds given by value to the nearest
- // millisecond, and adding that interval to this DateTimeOffset. The
- // value argument is permitted to be negative.
- //
- public DateTimeOffset AddSeconds(double seconds) =>
- new DateTimeOffset(ClockDateTime.AddSeconds(seconds), Offset);
-
- // Returns the DateTimeOffset resulting from adding the given number of
- // 100-nanosecond ticks to this DateTimeOffset. The value argument
- // is permitted to be negative.
- //
- public DateTimeOffset AddTicks(long ticks) =>
- new DateTimeOffset(ClockDateTime.AddTicks(ticks), Offset);
-
- // Returns the DateTimeOffset resulting from adding the given number of
- // years to this DateTimeOffset. The result is computed by incrementing
- // (or decrementing) the year part of this DateTimeOffset by value
- // years. If the month and day of this DateTimeOffset is 2/29, and if the
- // resulting year is not a leap year, the month and day of the resulting
- // DateTimeOffset becomes 2/28. Otherwise, the month, day, and time-of-day
- // parts of the result are the same as those of this DateTimeOffset.
- //
- public DateTimeOffset AddYears(int years) =>
- new DateTimeOffset(ClockDateTime.AddYears(years), Offset);
-
- // Compares two DateTimeOffset values, returning an integer that indicates
- // their relationship.
- //
- public static int Compare(DateTimeOffset first, DateTimeOffset second) =>
- DateTime.Compare(first.UtcDateTime, second.UtcDateTime);
-
- // Compares this DateTimeOffset to a given object. This method provides an
- // implementation of the IComparable interface. The object
- // argument must be another DateTimeOffset, or otherwise an exception
- // occurs. Null is considered less than any instance.
- //
- int IComparable.CompareTo(object? obj)
- {
- if (obj == null) return 1;
- if (!(obj is DateTimeOffset))
- {
- throw new ArgumentException(SR.Arg_MustBeDateTimeOffset);
- }
-
- DateTime objUtc = ((DateTimeOffset)obj).UtcDateTime;
- DateTime utc = UtcDateTime;
- if (utc > objUtc) return 1;
- if (utc < objUtc) return -1;
- return 0;
- }
-
- public int CompareTo(DateTimeOffset other)
- {
- DateTime otherUtc = other.UtcDateTime;
- DateTime utc = UtcDateTime;
- if (utc > otherUtc) return 1;
- if (utc < otherUtc) return -1;
- return 0;
- }
-
- // Checks if this DateTimeOffset is equal to a given object. Returns
- // true if the given object is a boxed DateTimeOffset and its value
- // is equal to the value of this DateTimeOffset. Returns false
- // otherwise.
- //
- public override bool Equals(object? obj) =>
- obj is DateTimeOffset && UtcDateTime.Equals(((DateTimeOffset)obj).UtcDateTime);
-
- public bool Equals(DateTimeOffset other) =>
- UtcDateTime.Equals(other.UtcDateTime);
-
- public bool EqualsExact(DateTimeOffset other) =>
- //
- // returns true when the ClockDateTime, Kind, and Offset match
- //
- // currently the Kind should always be Unspecified, but there is always the possibility that a future version
- // of DateTimeOffset overloads the Kind field
- //
- ClockDateTime == other.ClockDateTime && Offset == other.Offset && ClockDateTime.Kind == other.ClockDateTime.Kind;
-
- // Compares two DateTimeOffset values for equality. Returns true if
- // the two DateTimeOffset values are equal, or false if they are
- // not equal.
- //
- public static bool Equals(DateTimeOffset first, DateTimeOffset second) =>
- DateTime.Equals(first.UtcDateTime, second.UtcDateTime);
-
- // Creates a DateTimeOffset from a Windows filetime. A Windows filetime is
- // a long representing the date and time as the number of
- // 100-nanosecond intervals that have elapsed since 1/1/1601 12:00am.
- //
- public static DateTimeOffset FromFileTime(long fileTime) =>
- ToLocalTime(DateTime.FromFileTimeUtc(fileTime), true);
-
- public static DateTimeOffset FromUnixTimeSeconds(long seconds)
- {
- if (seconds < UnixMinSeconds || seconds > UnixMaxSeconds)
- {
- throw new ArgumentOutOfRangeException(nameof(seconds),
- SR.Format(SR.ArgumentOutOfRange_Range, UnixMinSeconds, UnixMaxSeconds));
- }
-
- long ticks = seconds * TimeSpan.TicksPerSecond + DateTime.UnixEpochTicks;
- return new DateTimeOffset(ticks, TimeSpan.Zero);
- }
-
- public static DateTimeOffset FromUnixTimeMilliseconds(long milliseconds)
- {
- const long MinMilliseconds = DateTime.MinTicks / TimeSpan.TicksPerMillisecond - UnixEpochMilliseconds;
- const long MaxMilliseconds = DateTime.MaxTicks / TimeSpan.TicksPerMillisecond - UnixEpochMilliseconds;
-
- if (milliseconds < MinMilliseconds || milliseconds > MaxMilliseconds)
- {
- throw new ArgumentOutOfRangeException(nameof(milliseconds),
- SR.Format(SR.ArgumentOutOfRange_Range, MinMilliseconds, MaxMilliseconds));
- }
-
- long ticks = milliseconds * TimeSpan.TicksPerMillisecond + DateTime.UnixEpochTicks;
- return new DateTimeOffset(ticks, TimeSpan.Zero);
- }
-
- // ----- SECTION: private serialization instance methods ----------------*
-
- void IDeserializationCallback.OnDeserialization(object? sender)
- {
- try
- {
- ValidateOffset(Offset);
- ValidateDate(ClockDateTime, Offset);
- }
- catch (ArgumentException e)
- {
- throw new SerializationException(SR.Serialization_InvalidData, e);
- }
- }
-
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- info.AddValue("DateTime", _dateTime); // Do not rename (binary serialization)
- info.AddValue("OffsetMinutes", _offsetMinutes); // Do not rename (binary serialization)
- }
-
- private DateTimeOffset(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- _dateTime = (DateTime)info.GetValue("DateTime", typeof(DateTime))!; // Do not rename (binary serialization)
- _offsetMinutes = (short)info.GetValue("OffsetMinutes", typeof(short))!; // Do not rename (binary serialization)
- }
-
- // Returns the hash code for this DateTimeOffset.
- //
- public override int GetHashCode() => UtcDateTime.GetHashCode();
-
- // Constructs a DateTimeOffset from a string. The string must specify a
- // date and optionally a time in a culture-specific or universal format.
- // Leading and trailing whitespace characters are allowed.
- //
- public static DateTimeOffset Parse(string input)
- {
- if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
-
- TimeSpan offset;
- DateTime dateResult = DateTimeParse.Parse(input,
- DateTimeFormatInfo.CurrentInfo,
- DateTimeStyles.None,
- out offset);
- return new DateTimeOffset(dateResult.Ticks, offset);
- }
-
- // Constructs a DateTimeOffset from a string. The string must specify a
- // date and optionally a time in a culture-specific or universal format.
- // Leading and trailing whitespace characters are allowed.
- //
- public static DateTimeOffset Parse(string input, IFormatProvider? formatProvider)
- {
- if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
- return Parse(input, formatProvider, DateTimeStyles.None);
- }
-
- public static DateTimeOffset Parse(string input, IFormatProvider? formatProvider, DateTimeStyles styles)
- {
- styles = ValidateStyles(styles, nameof(styles));
- if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
-
- TimeSpan offset;
- DateTime dateResult = DateTimeParse.Parse(input,
- DateTimeFormatInfo.GetInstance(formatProvider),
- styles,
- out offset);
- return new DateTimeOffset(dateResult.Ticks, offset);
- }
-
- public static DateTimeOffset Parse(ReadOnlySpan<char> input, IFormatProvider? formatProvider = null, DateTimeStyles styles = DateTimeStyles.None)
- {
- styles = ValidateStyles(styles, nameof(styles));
- DateTime dateResult = DateTimeParse.Parse(input, DateTimeFormatInfo.GetInstance(formatProvider), styles, out TimeSpan offset);
- return new DateTimeOffset(dateResult.Ticks, offset);
- }
-
- // Constructs a DateTimeOffset from a string. The string must specify a
- // date and optionally a time in a culture-specific or universal format.
- // Leading and trailing whitespace characters are allowed.
- //
- public static DateTimeOffset ParseExact(string input, string format, IFormatProvider? formatProvider)
- {
- if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
- if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format);
- return ParseExact(input, format, formatProvider, DateTimeStyles.None);
- }
-
- // Constructs a DateTimeOffset from a string. The string must specify a
- // date and optionally a time in a culture-specific or universal format.
- // Leading and trailing whitespace characters are allowed.
- //
- public static DateTimeOffset ParseExact(string input, string format, IFormatProvider? formatProvider, DateTimeStyles styles)
- {
- styles = ValidateStyles(styles, nameof(styles));
- if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
- if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format);
-
- TimeSpan offset;
- DateTime dateResult = DateTimeParse.ParseExact(input,
- format,
- DateTimeFormatInfo.GetInstance(formatProvider),
- styles,
- out offset);
- return new DateTimeOffset(dateResult.Ticks, offset);
- }
-
- public static DateTimeOffset ParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, DateTimeStyles styles = DateTimeStyles.None)
- {
- styles = ValidateStyles(styles, nameof(styles));
- DateTime dateResult = DateTimeParse.ParseExact(input, format, DateTimeFormatInfo.GetInstance(formatProvider), styles, out TimeSpan offset);
- return new DateTimeOffset(dateResult.Ticks, offset);
- }
-
- public static DateTimeOffset ParseExact(string input, string[] formats, IFormatProvider? formatProvider, DateTimeStyles styles)
- {
- styles = ValidateStyles(styles, nameof(styles));
- if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
-
- TimeSpan offset;
- DateTime dateResult = DateTimeParse.ParseExactMultiple(input,
- formats,
- DateTimeFormatInfo.GetInstance(formatProvider),
- styles,
- out offset);
- return new DateTimeOffset(dateResult.Ticks, offset);
- }
-
- public static DateTimeOffset ParseExact(ReadOnlySpan<char> input, string[] formats, IFormatProvider? formatProvider, DateTimeStyles styles = DateTimeStyles.None)
- {
- styles = ValidateStyles(styles, nameof(styles));
- DateTime dateResult = DateTimeParse.ParseExactMultiple(input, formats, DateTimeFormatInfo.GetInstance(formatProvider), styles, out TimeSpan offset);
- return new DateTimeOffset(dateResult.Ticks, offset);
- }
-
- public TimeSpan Subtract(DateTimeOffset value) =>
- UtcDateTime.Subtract(value.UtcDateTime);
-
- public DateTimeOffset Subtract(TimeSpan value) =>
- new DateTimeOffset(ClockDateTime.Subtract(value), Offset);
-
- public long ToFileTime() => UtcDateTime.ToFileTime();
-
- public long ToUnixTimeSeconds()
- {
- // Truncate sub-second precision before offsetting by the Unix Epoch to avoid
- // the last digit being off by one for dates that result in negative Unix times.
- //
- // For example, consider the DateTimeOffset 12/31/1969 12:59:59.001 +0
- // ticks = 621355967990010000
- // ticksFromEpoch = ticks - DateTime.UnixEpochTicks = -9990000
- // secondsFromEpoch = ticksFromEpoch / TimeSpan.TicksPerSecond = 0
- //
- // Notice that secondsFromEpoch is rounded *up* by the truncation induced by integer division,
- // whereas we actually always want to round *down* when converting to Unix time. This happens
- // automatically for positive Unix time values. Now the example becomes:
- // seconds = ticks / TimeSpan.TicksPerSecond = 62135596799
- // secondsFromEpoch = seconds - UnixEpochSeconds = -1
- //
- // In other words, we want to consistently round toward the time 1/1/0001 00:00:00,
- // rather than toward the Unix Epoch (1/1/1970 00:00:00).
- long seconds = UtcDateTime.Ticks / TimeSpan.TicksPerSecond;
- return seconds - UnixEpochSeconds;
- }
-
- public long ToUnixTimeMilliseconds()
- {
- // Truncate sub-millisecond precision before offsetting by the Unix Epoch to avoid
- // the last digit being off by one for dates that result in negative Unix times
- long milliseconds = UtcDateTime.Ticks / TimeSpan.TicksPerMillisecond;
- return milliseconds - UnixEpochMilliseconds;
- }
-
- public DateTimeOffset ToLocalTime() =>
- ToLocalTime(false);
-
- internal DateTimeOffset ToLocalTime(bool throwOnOverflow) =>
- ToLocalTime(UtcDateTime, throwOnOverflow);
-
- private static DateTimeOffset ToLocalTime(DateTime utcDateTime, bool throwOnOverflow)
- {
- TimeSpan offset = TimeZoneInfo.GetLocalUtcOffset(utcDateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
- long localTicks = utcDateTime.Ticks + offset.Ticks;
- if (localTicks < DateTime.MinTicks || localTicks > DateTime.MaxTicks)
- {
- if (throwOnOverflow)
- throw new ArgumentException(SR.Arg_ArgumentOutOfRangeException);
-
- localTicks = localTicks < DateTime.MinTicks ? DateTime.MinTicks : DateTime.MaxTicks;
- }
-
- return new DateTimeOffset(localTicks, offset);
- }
-
- public override string ToString() =>
- DateTimeFormat.Format(ClockDateTime, null, null, Offset);
-
- public string ToString(string? format) =>
- DateTimeFormat.Format(ClockDateTime, format, null, Offset);
-
- public string ToString(IFormatProvider? formatProvider) =>
- DateTimeFormat.Format(ClockDateTime, null, formatProvider, Offset);
-
- public string ToString(string? format, IFormatProvider? formatProvider) =>
- DateTimeFormat.Format(ClockDateTime, format, formatProvider, Offset);
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? formatProvider = null) =>
- DateTimeFormat.TryFormat(ClockDateTime, destination, out charsWritten, format, formatProvider, Offset);
-
- public DateTimeOffset ToUniversalTime() =>
- new DateTimeOffset(UtcDateTime);
-
- public static bool TryParse(string? input, out DateTimeOffset result)
- {
- TimeSpan offset;
- DateTime dateResult;
- bool parsed = DateTimeParse.TryParse(input,
- DateTimeFormatInfo.CurrentInfo,
- DateTimeStyles.None,
- out dateResult,
- out offset);
- result = new DateTimeOffset(dateResult.Ticks, offset);
- return parsed;
- }
-
- public static bool TryParse(ReadOnlySpan<char> input, out DateTimeOffset result)
- {
- bool parsed = DateTimeParse.TryParse(input, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out DateTime dateResult, out TimeSpan offset);
- result = new DateTimeOffset(dateResult.Ticks, offset);
- return parsed;
- }
-
- public static bool TryParse(string? input, IFormatProvider? formatProvider, DateTimeStyles styles, out DateTimeOffset result)
- {
- styles = ValidateStyles(styles, nameof(styles));
- if (input == null)
- {
- result = default;
- return false;
- }
-
- TimeSpan offset;
- DateTime dateResult;
- bool parsed = DateTimeParse.TryParse(input,
- DateTimeFormatInfo.GetInstance(formatProvider),
- styles,
- out dateResult,
- out offset);
- result = new DateTimeOffset(dateResult.Ticks, offset);
- return parsed;
- }
-
- public static bool TryParse(ReadOnlySpan<char> input, IFormatProvider? formatProvider, DateTimeStyles styles, out DateTimeOffset result)
- {
- styles = ValidateStyles(styles, nameof(styles));
- bool parsed = DateTimeParse.TryParse(input, DateTimeFormatInfo.GetInstance(formatProvider), styles, out DateTime dateResult, out TimeSpan offset);
- result = new DateTimeOffset(dateResult.Ticks, offset);
- return parsed;
- }
-
- public static bool TryParseExact(string? input, string? format, IFormatProvider? formatProvider, DateTimeStyles styles,
- out DateTimeOffset result)
- {
- styles = ValidateStyles(styles, nameof(styles));
- if (input == null || format == null)
- {
- result = default;
- return false;
- }
-
- TimeSpan offset;
- DateTime dateResult;
- bool parsed = DateTimeParse.TryParseExact(input,
- format,
- DateTimeFormatInfo.GetInstance(formatProvider),
- styles,
- out dateResult,
- out offset);
- result = new DateTimeOffset(dateResult.Ticks, offset);
- return parsed;
- }
-
- public static bool TryParseExact(
- ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, DateTimeStyles styles, out DateTimeOffset result)
- {
- styles = ValidateStyles(styles, nameof(styles));
- bool parsed = DateTimeParse.TryParseExact(input, format, DateTimeFormatInfo.GetInstance(formatProvider), styles, out DateTime dateResult, out TimeSpan offset);
- result = new DateTimeOffset(dateResult.Ticks, offset);
- return parsed;
- }
-
- public static bool TryParseExact(string? input, string?[]? formats, IFormatProvider? formatProvider, DateTimeStyles styles,
- out DateTimeOffset result)
- {
- styles = ValidateStyles(styles, nameof(styles));
- if (input == null)
- {
- result = default;
- return false;
- }
-
- TimeSpan offset;
- DateTime dateResult;
- bool parsed = DateTimeParse.TryParseExactMultiple(input,
- formats,
- DateTimeFormatInfo.GetInstance(formatProvider),
- styles,
- out dateResult,
- out offset);
- result = new DateTimeOffset(dateResult.Ticks, offset);
- return parsed;
- }
-
- public static bool TryParseExact(
- ReadOnlySpan<char> input, string?[]? formats, IFormatProvider? formatProvider, DateTimeStyles styles, out DateTimeOffset result)
- {
- styles = ValidateStyles(styles, nameof(styles));
- bool parsed = DateTimeParse.TryParseExactMultiple(input, formats, DateTimeFormatInfo.GetInstance(formatProvider), styles, out DateTime dateResult, out TimeSpan offset);
- result = new DateTimeOffset(dateResult.Ticks, offset);
- return parsed;
- }
-
- // Ensures the TimeSpan is valid to go in a DateTimeOffset.
- private static short ValidateOffset(TimeSpan offset)
- {
- long ticks = offset.Ticks;
- if (ticks % TimeSpan.TicksPerMinute != 0)
- {
- throw new ArgumentException(SR.Argument_OffsetPrecision, nameof(offset));
- }
- if (ticks < MinOffset || ticks > MaxOffset)
- {
- throw new ArgumentOutOfRangeException(nameof(offset), SR.Argument_OffsetOutOfRange);
- }
- return (short)(offset.Ticks / TimeSpan.TicksPerMinute);
- }
-
- // Ensures that the time and offset are in range.
- private static DateTime ValidateDate(DateTime dateTime, TimeSpan offset)
- {
- // The key validation is that both the UTC and clock times fit. The clock time is validated
- // by the DateTime constructor.
- Debug.Assert(offset.Ticks >= MinOffset && offset.Ticks <= MaxOffset, "Offset not validated.");
-
- // This operation cannot overflow because offset should have already been validated to be within
- // 14 hours and the DateTime instance is more than that distance from the boundaries of long.
- long utcTicks = dateTime.Ticks - offset.Ticks;
- if (utcTicks < DateTime.MinTicks || utcTicks > DateTime.MaxTicks)
- {
- throw new ArgumentOutOfRangeException(nameof(offset), SR.Argument_UTCOutOfRange);
- }
- // make sure the Kind is set to Unspecified
- //
- return new DateTime(utcTicks, DateTimeKind.Unspecified);
- }
-
- private static DateTimeStyles ValidateStyles(DateTimeStyles style, string parameterName)
- {
- if ((style & DateTimeFormatInfo.InvalidDateTimeStyles) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidDateTimeStyles, parameterName);
- }
- if (((style & (DateTimeStyles.AssumeLocal)) != 0) && ((style & (DateTimeStyles.AssumeUniversal)) != 0))
- {
- throw new ArgumentException(SR.Argument_ConflictingDateTimeStyles, parameterName);
- }
- if ((style & DateTimeStyles.NoCurrentDateDefault) != 0)
- {
- throw new ArgumentException(SR.Argument_DateTimeOffsetInvalidDateTimeStyles, parameterName);
- }
-
- // RoundtripKind does not make sense for DateTimeOffset; ignore this flag for backward compatibility with DateTime
- style &= ~DateTimeStyles.RoundtripKind;
-
- // AssumeLocal is also ignored as that is what we do by default with DateTimeOffset.Parse
- style &= ~DateTimeStyles.AssumeLocal;
-
- return style;
- }
-
- // Operators
-
- public static implicit operator DateTimeOffset(DateTime dateTime) =>
- new DateTimeOffset(dateTime);
-
- public static DateTimeOffset operator +(DateTimeOffset dateTimeOffset, TimeSpan timeSpan) =>
- new DateTimeOffset(dateTimeOffset.ClockDateTime + timeSpan, dateTimeOffset.Offset);
-
- public static DateTimeOffset operator -(DateTimeOffset dateTimeOffset, TimeSpan timeSpan) =>
- new DateTimeOffset(dateTimeOffset.ClockDateTime - timeSpan, dateTimeOffset.Offset);
-
- public static TimeSpan operator -(DateTimeOffset left, DateTimeOffset right) =>
- left.UtcDateTime - right.UtcDateTime;
-
- public static bool operator ==(DateTimeOffset left, DateTimeOffset right) =>
- left.UtcDateTime == right.UtcDateTime;
-
- public static bool operator !=(DateTimeOffset left, DateTimeOffset right) =>
- left.UtcDateTime != right.UtcDateTime;
-
- public static bool operator <(DateTimeOffset left, DateTimeOffset right) =>
- left.UtcDateTime < right.UtcDateTime;
-
- public static bool operator <=(DateTimeOffset left, DateTimeOffset right) =>
- left.UtcDateTime <= right.UtcDateTime;
-
- public static bool operator >(DateTimeOffset left, DateTimeOffset right) =>
- left.UtcDateTime > right.UtcDateTime;
-
- public static bool operator >=(DateTimeOffset left, DateTimeOffset right) =>
- left.UtcDateTime >= right.UtcDateTime;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DayOfWeek.cs b/netcore/System.Private.CoreLib/shared/System/DayOfWeek.cs
deleted file mode 100644
index f67d10e1815..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DayOfWeek.cs
+++ /dev/null
@@ -1,26 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Enum for the day of the week.
-**
-**
-============================================================*/
-
-namespace System
-{
- public enum DayOfWeek
- {
- Sunday = 0,
- Monday = 1,
- Tuesday = 2,
- Wednesday = 3,
- Thursday = 4,
- Friday = 5,
- Saturday = 6,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Decimal.DecCalc.cs b/netcore/System.Private.CoreLib/shared/System/Decimal.DecCalc.cs
deleted file mode 100644
index eb5deb9cc98..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Decimal.DecCalc.cs
+++ /dev/null
@@ -1,2699 +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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using Internal.Runtime.CompilerServices;
-using X86 = System.Runtime.Intrinsics.X86;
-
-namespace System
-{
- public partial struct Decimal
- {
- // Low level accessors used by a DecCalc and formatting
- internal uint High => (uint)hi;
- internal uint Low => (uint)lo;
- internal uint Mid => (uint)mid;
-
- internal bool IsNegative => flags < 0;
-
- internal int Scale => (byte)(flags >> ScaleShift);
-
-#if BIGENDIAN
- private ulong Low64 => ((ulong)Mid << 32) | Low;
-#else
- private ulong Low64 => Unsafe.As<int, ulong>(ref Unsafe.AsRef(in lo));
-#endif
-
- private static ref DecCalc AsMutable(ref decimal d) => ref Unsafe.As<decimal, DecCalc>(ref d);
-
- #region APIs need by number formatting.
-
- internal static uint DecDivMod1E9(ref decimal value)
- {
- return DecCalc.DecDivMod1E9(ref AsMutable(ref value));
- }
-
- #endregion
-
- /// <summary>
- /// Class that contains all the mathematical calculations for decimal. Most of which have been ported from oleaut32.
- /// </summary>
- [StructLayout(LayoutKind.Explicit)]
- private struct DecCalc
- {
- // NOTE: Do not change the offsets of these fields. This structure must have the same layout as Decimal.
- [FieldOffset(0)]
- private uint uflags;
- [FieldOffset(4)]
- private uint uhi;
- [FieldOffset(8)]
- private uint ulo;
- [FieldOffset(12)]
- private uint umid;
-
- /// <summary>
- /// The low and mid fields combined in little-endian order
- /// </summary>
- [FieldOffset(8)]
- private ulong ulomidLE;
-
- private uint High
- {
- get => uhi;
- set => uhi = value;
- }
-
- private uint Low
- {
- get => ulo;
- set => ulo = value;
- }
-
- private uint Mid
- {
- get => umid;
- set => umid = value;
- }
-
- private bool IsNegative => (int)uflags < 0;
-
- private int Scale => (byte)(uflags >> ScaleShift);
-
- private ulong Low64
- {
-#if BIGENDIAN
- get { return ((ulong)umid << 32) | ulo; }
- set { umid = (uint)(value >> 32); ulo = (uint)value; }
-#else
- get => ulomidLE;
- set => ulomidLE = value;
-#endif
- }
-
- private const uint SignMask = 0x80000000;
- private const uint ScaleMask = 0x00FF0000;
-
- private const int DEC_SCALE_MAX = 28;
-
- private const uint TenToPowerNine = 1000000000;
- private const ulong TenToPowerEighteen = 1000000000000000000;
-
- // The maximum power of 10 that a 32 bit integer can store
- private const int MaxInt32Scale = 9;
- // The maximum power of 10 that a 64 bit integer can store
- private const int MaxInt64Scale = 19;
-
- // Fast access for 10^n where n is 0-9
- private static readonly uint[] s_powers10 = new uint[] {
- 1,
- 10,
- 100,
- 1000,
- 10000,
- 100000,
- 1000000,
- 10000000,
- 100000000,
- 1000000000
- };
-
- // Fast access for 10^n where n is 1-19
- private static readonly ulong[] s_ulongPowers10 = new ulong[] {
- 10,
- 100,
- 1000,
- 10000,
- 100000,
- 1000000,
- 10000000,
- 100000000,
- 1000000000,
- 10000000000,
- 100000000000,
- 1000000000000,
- 10000000000000,
- 100000000000000,
- 1000000000000000,
- 10000000000000000,
- 100000000000000000,
- 1000000000000000000,
- 10000000000000000000,
- };
-
- private static readonly double[] s_doublePowers10 = new double[] {
- 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
- 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
- 1e20, 1e21, 1e22, 1e23, 1e24, 1e25, 1e26, 1e27, 1e28, 1e29,
- 1e30, 1e31, 1e32, 1e33, 1e34, 1e35, 1e36, 1e37, 1e38, 1e39,
- 1e40, 1e41, 1e42, 1e43, 1e44, 1e45, 1e46, 1e47, 1e48, 1e49,
- 1e50, 1e51, 1e52, 1e53, 1e54, 1e55, 1e56, 1e57, 1e58, 1e59,
- 1e60, 1e61, 1e62, 1e63, 1e64, 1e65, 1e66, 1e67, 1e68, 1e69,
- 1e70, 1e71, 1e72, 1e73, 1e74, 1e75, 1e76, 1e77, 1e78, 1e79,
- 1e80
- };
-
- // Used to fill uninitialized stack variables with non-zero pattern in debug builds
- [Conditional("DEBUG")]
- private static unsafe void DebugPoison<T>(ref T s) where T : unmanaged
- {
- MemoryMarshal.AsBytes(MemoryMarshal.CreateSpan(ref s, 1)).Fill(0xCD);
- }
-
- #region Decimal Math Helpers
-
- private static unsafe uint GetExponent(float f)
- {
- // Based on pulling out the exp from this single struct layout
- // typedef struct {
- // ULONG mant:23;
- // ULONG exp:8;
- // ULONG sign:1;
- // } SNGSTRUCT;
-
- return (byte)(*(uint*)&f >> 23);
- }
-
- private static unsafe uint GetExponent(double d)
- {
- // Based on pulling out the exp from this double struct layout
- // typedef struct {
- // DWORDLONG mant:52;
- // DWORDLONG signexp:12;
- // } DBLSTRUCT;
-
- return (uint)(*(ulong*)&d >> 52) & 0x7FFu;
- }
-
- private static ulong UInt32x32To64(uint a, uint b)
- {
- return (ulong)a * (ulong)b;
- }
-
- private static void UInt64x64To128(ulong a, ulong b, ref DecCalc result)
- {
- ulong low = UInt32x32To64((uint)a, (uint)b); // lo partial prod
- ulong mid = UInt32x32To64((uint)a, (uint)(b >> 32)); // mid 1 partial prod
- ulong high = UInt32x32To64((uint)(a >> 32), (uint)(b >> 32));
- high += mid >> 32;
- low += mid <<= 32;
- if (low < mid) // test for carry
- high++;
-
- mid = UInt32x32To64((uint)(a >> 32), (uint)b);
- high += mid >> 32;
- low += mid <<= 32;
- if (low < mid) // test for carry
- high++;
-
- if (high > uint.MaxValue)
- Number.ThrowOverflowException(TypeCode.Decimal);
- result.Low64 = low;
- result.High = (uint)high;
- }
-
- /// <summary>
- /// Do full divide, yielding 96-bit result and 32-bit remainder.
- /// </summary>
- /// <param name="bufNum">96-bit dividend as array of uints, least-sig first</param>
- /// <param name="den">32-bit divisor</param>
- /// <returns>Returns remainder. Quotient overwrites dividend.</returns>
- private static uint Div96By32(ref Buf12 bufNum, uint den)
- {
- // TODO: https://github.com/dotnet/coreclr/issues/3439
- ulong tmp, div;
- if (bufNum.U2 != 0)
- {
- tmp = bufNum.High64;
- div = tmp / den;
- bufNum.High64 = div;
- tmp = ((tmp - (uint)div * den) << 32) | bufNum.U0;
- if (tmp == 0)
- return 0;
- uint div32 = (uint)(tmp / den);
- bufNum.U0 = div32;
- return (uint)tmp - div32 * den;
- }
-
- tmp = bufNum.Low64;
- if (tmp == 0)
- return 0;
- div = tmp / den;
- bufNum.Low64 = div;
- return (uint)(tmp - div * den);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool Div96ByConst(ref ulong high64, ref uint low, uint pow)
- {
-#if BIT64
- ulong div64 = high64 / pow;
- uint div = (uint)((((high64 - div64 * pow) << 32) + low) / pow);
- if (low == div * pow)
- {
- high64 = div64;
- low = div;
- return true;
- }
-#else
- // 32-bit RyuJIT doesn't convert 64-bit division by constant into multiplication by reciprocal. Do half-width divisions instead.
- Debug.Assert(pow <= ushort.MaxValue);
- uint num, mid32, low16, div;
- if (high64 <= uint.MaxValue)
- {
- num = (uint)high64;
- mid32 = num / pow;
- num = (num - mid32 * pow) << 16;
-
- num += low >> 16;
- low16 = num / pow;
- num = (num - low16 * pow) << 16;
-
- num += (ushort)low;
- div = num / pow;
- if (num == div * pow)
- {
- high64 = mid32;
- low = (low16 << 16) + div;
- return true;
- }
- }
- else
- {
- num = (uint)(high64 >> 32);
- uint high32 = num / pow;
- num = (num - high32 * pow) << 16;
-
- num += (uint)high64 >> 16;
- mid32 = num / pow;
- num = (num - mid32 * pow) << 16;
-
- num += (ushort)high64;
- div = num / pow;
- num = (num - div * pow) << 16;
- mid32 = div + (mid32 << 16);
-
- num += low >> 16;
- low16 = num / pow;
- num = (num - low16 * pow) << 16;
-
- num += (ushort)low;
- div = num / pow;
- if (num == div * pow)
- {
- high64 = ((ulong)high32 << 32) | mid32;
- low = (low16 << 16) + div;
- return true;
- }
- }
-#endif
- return false;
- }
-
- /// <summary>
- /// Normalize (unscale) the number by trying to divide out 10^8, 10^4, 10^2, and 10^1.
- /// If a division by one of these powers returns a zero remainder, then we keep the quotient.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void Unscale(ref uint low, ref ulong high64, ref int scale)
- {
- // Since 10 = 2 * 5, there must be a factor of 2 for every power of 10 we can extract.
- // We use this as a quick test on whether to try a given power.
-
-#if BIT64
- while ((byte)low == 0 && scale >= 8 && Div96ByConst(ref high64, ref low, 100000000))
- scale -= 8;
-
- if ((low & 0xF) == 0 && scale >= 4 && Div96ByConst(ref high64, ref low, 10000))
- scale -= 4;
-#else
- while ((low & 0xF) == 0 && scale >= 4 && Div96ByConst(ref high64, ref low, 10000))
- scale -= 4;
-#endif
-
- if ((low & 3) == 0 && scale >= 2 && Div96ByConst(ref high64, ref low, 100))
- scale -= 2;
-
- if ((low & 1) == 0 && scale >= 1 && Div96ByConst(ref high64, ref low, 10))
- scale--;
- }
-
- /// <summary>
- /// Do partial divide, yielding 32-bit result and 64-bit remainder.
- /// Divisor must be larger than upper 64 bits of dividend.
- /// </summary>
- /// <param name="bufNum">96-bit dividend as array of uints, least-sig first</param>
- /// <param name="den">64-bit divisor</param>
- /// <returns>Returns quotient. Remainder overwrites lower 64-bits of dividend.</returns>
- private static uint Div96By64(ref Buf12 bufNum, ulong den)
- {
- Debug.Assert(den > bufNum.High64);
- uint quo;
- ulong num;
- uint num2 = bufNum.U2;
- if (num2 == 0)
- {
- num = bufNum.Low64;
- if (num < den)
- // Result is zero. Entire dividend is remainder.
- return 0;
-
- // TODO: https://github.com/dotnet/coreclr/issues/3439
- quo = (uint)(num / den);
- num -= quo * den; // remainder
- bufNum.Low64 = num;
- return quo;
- }
-
- uint denHigh32 = (uint)(den >> 32);
- if (num2 >= denHigh32)
- {
- // Divide would overflow. Assume a quotient of 2^32, and set
- // up remainder accordingly.
- //
- num = bufNum.Low64;
- num -= den << 32;
- quo = 0;
-
- // Remainder went negative. Add divisor back in until it's positive,
- // a max of 2 times.
- //
- do
- {
- quo--;
- num += den;
- } while (num >= den);
-
- bufNum.Low64 = num;
- return quo;
- }
-
- // Hardware divide won't overflow
- //
- ulong num64 = bufNum.High64;
- if (num64 < denHigh32)
- // Result is zero. Entire dividend is remainder.
- //
- return 0;
-
- // TODO: https://github.com/dotnet/coreclr/issues/3439
- quo = (uint)(num64 / denHigh32);
- num = bufNum.U0 | ((num64 - quo * denHigh32) << 32); // remainder
-
- // Compute full remainder, rem = dividend - (quo * divisor).
- //
- ulong prod = UInt32x32To64(quo, (uint)den); // quo * lo divisor
- num -= prod;
-
- if (num > ~prod)
- {
- // Remainder went negative. Add divisor back in until it's positive,
- // a max of 2 times.
- //
- do
- {
- quo--;
- num += den;
- } while (num >= den);
- }
-
- bufNum.Low64 = num;
- return quo;
- }
-
- /// <summary>
- /// Do partial divide, yielding 32-bit result and 96-bit remainder.
- /// Top divisor uint must be larger than top dividend uint. This is
- /// assured in the initial call because the divisor is normalized
- /// and the dividend can't be. In subsequent calls, the remainder
- /// is multiplied by 10^9 (max), so it can be no more than 1/4 of
- /// the divisor which is effectively multiplied by 2^32 (4 * 10^9).
- /// </summary>
- /// <param name="bufNum">128-bit dividend as array of uints, least-sig first</param>
- /// <param name="bufDen">96-bit divisor</param>
- /// <returns>Returns quotient. Remainder overwrites lower 96-bits of dividend.</returns>
- private static uint Div128By96(ref Buf16 bufNum, ref Buf12 bufDen)
- {
- Debug.Assert(bufDen.U2 > bufNum.U3);
- ulong dividend = bufNum.High64;
- uint den = bufDen.U2;
- if (dividend < den)
- // Result is zero. Entire dividend is remainder.
- //
- return 0;
-
- // TODO: https://github.com/dotnet/coreclr/issues/3439
- uint quo = (uint)(dividend / den);
- uint remainder = (uint)dividend - quo * den;
-
- // Compute full remainder, rem = dividend - (quo * divisor).
- //
- ulong prod1 = UInt32x32To64(quo, bufDen.U0); // quo * lo divisor
- ulong prod2 = UInt32x32To64(quo, bufDen.U1); // quo * mid divisor
- prod2 += prod1 >> 32;
- prod1 = (uint)prod1 | (prod2 << 32);
- prod2 >>= 32;
-
- ulong num = bufNum.Low64;
- num -= prod1;
- remainder -= (uint)prod2;
-
- // Propagate carries
- //
- if (num > ~prod1)
- {
- remainder--;
- if (remainder < ~(uint)prod2)
- goto PosRem;
- }
- else if (remainder <= ~(uint)prod2)
- goto PosRem;
- {
- // Remainder went negative. Add divisor back in until it's positive,
- // a max of 2 times.
- //
- prod1 = bufDen.Low64;
-
- while (true)
- {
- quo--;
- num += prod1;
- remainder += den;
-
- if (num < prod1)
- {
- // Detected carry. Check for carry out of top
- // before adding it in.
- //
- if (remainder++ < den)
- break;
- }
- if (remainder < den)
- break; // detected carry
- }
- }
-PosRem:
-
- bufNum.Low64 = num;
- bufNum.U2 = remainder;
- return quo;
- }
-
- /// <summary>
- /// Multiply the two numbers. The low 96 bits of the result overwrite
- /// the input. The last 32 bits of the product are the return value.
- /// </summary>
- /// <param name="bufNum">96-bit number as array of uints, least-sig first</param>
- /// <param name="power">Scale factor to multiply by</param>
- /// <returns>Returns highest 32 bits of product</returns>
- private static uint IncreaseScale(ref Buf12 bufNum, uint power)
- {
- ulong tmp = UInt32x32To64(bufNum.U0, power);
- bufNum.U0 = (uint)tmp;
- tmp >>= 32;
- tmp += UInt32x32To64(bufNum.U1, power);
- bufNum.U1 = (uint)tmp;
- tmp >>= 32;
- tmp += UInt32x32To64(bufNum.U2, power);
- bufNum.U2 = (uint)tmp;
- return (uint)(tmp >> 32);
- }
-
- private static void IncreaseScale64(ref Buf12 bufNum, uint power)
- {
- ulong tmp = UInt32x32To64(bufNum.U0, power);
- bufNum.U0 = (uint)tmp;
- tmp >>= 32;
- tmp += UInt32x32To64(bufNum.U1, power);
- bufNum.High64 = tmp;
- }
-
- /// <summary>
- /// See if we need to scale the result to fit it in 96 bits.
- /// Perform needed scaling. Adjust scale factor accordingly.
- /// </summary>
- /// <param name="bufRes">Array of uints with value, least-significant first</param>
- /// <param name="hiRes">Index of last non-zero value in bufRes</param>
- /// <param name="scale">Scale factor for this value, range 0 - 2 * DEC_SCALE_MAX</param>
- /// <returns>Returns new scale factor. bufRes updated in place, always 3 uints.</returns>
- private static unsafe int ScaleResult(Buf24* bufRes, uint hiRes, int scale)
- {
- Debug.Assert(hiRes < bufRes->Length);
- uint* result = (uint*)bufRes;
-
- // See if we need to scale the result. The combined scale must
- // be <= DEC_SCALE_MAX and the upper 96 bits must be zero.
- //
- // Start by figuring a lower bound on the scaling needed to make
- // the upper 96 bits zero. hiRes is the index into result[]
- // of the highest non-zero uint.
- //
- int newScale = 0;
- if (hiRes > 2)
- {
- newScale = (int)hiRes * 32 - 64 - 1;
- newScale -= BitOperations.LeadingZeroCount(result[hiRes]);
-
- // Multiply bit position by log10(2) to figure it's power of 10.
- // We scale the log by 256. log(2) = .30103, * 256 = 77. Doing this
- // with a multiply saves a 96-byte lookup table. The power returned
- // is <= the power of the number, so we must add one power of 10
- // to make it's integer part zero after dividing by 256.
- //
- // Note: the result of this multiplication by an approximation of
- // log10(2) have been exhaustively checked to verify it gives the
- // correct result. (There were only 95 to check...)
- //
- newScale = ((newScale * 77) >> 8) + 1;
-
- // newScale = min scale factor to make high 96 bits zero, 0 - 29.
- // This reduces the scale factor of the result. If it exceeds the
- // current scale of the result, we'll overflow.
- //
- if (newScale > scale)
- goto ThrowOverflow;
- }
-
- // Make sure we scale by enough to bring the current scale factor
- // into valid range.
- //
- if (newScale < scale - DEC_SCALE_MAX)
- newScale = scale - DEC_SCALE_MAX;
-
- if (newScale != 0)
- {
- // Scale by the power of 10 given by newScale. Note that this is
- // NOT guaranteed to bring the number within 96 bits -- it could
- // be 1 power of 10 short.
- //
- scale -= newScale;
- uint sticky = 0;
- uint quotient, remainder = 0;
-
- while (true)
- {
- sticky |= remainder; // record remainder as sticky bit
-
- uint power;
- // Scaling loop specialized for each power of 10 because division by constant is an order of magnitude faster (especially for 64-bit division that's actually done by 128bit DIV on x64)
- switch (newScale)
- {
- case 1:
- power = DivByConst(result, hiRes, out quotient, out remainder, 10);
- break;
- case 2:
- power = DivByConst(result, hiRes, out quotient, out remainder, 100);
- break;
- case 3:
- power = DivByConst(result, hiRes, out quotient, out remainder, 1000);
- break;
- case 4:
- power = DivByConst(result, hiRes, out quotient, out remainder, 10000);
- break;
-#if BIT64
- case 5:
- power = DivByConst(result, hiRes, out quotient, out remainder, 100000);
- break;
- case 6:
- power = DivByConst(result, hiRes, out quotient, out remainder, 1000000);
- break;
- case 7:
- power = DivByConst(result, hiRes, out quotient, out remainder, 10000000);
- break;
- case 8:
- power = DivByConst(result, hiRes, out quotient, out remainder, 100000000);
- break;
- default:
- power = DivByConst(result, hiRes, out quotient, out remainder, TenToPowerNine);
- break;
-#else
- default:
- goto case 4;
-#endif
- }
- result[hiRes] = quotient;
- // If first quotient was 0, update hiRes.
- //
- if (quotient == 0 && hiRes != 0)
- hiRes--;
-
-#if BIT64
- newScale -= MaxInt32Scale;
-#else
- newScale -= 4;
-#endif
- if (newScale > 0)
- continue; // scale some more
-
- // If we scaled enough, hiRes would be 2 or less. If not,
- // divide by 10 more.
- //
- if (hiRes > 2)
- {
- if (scale == 0)
- goto ThrowOverflow;
- newScale = 1;
- scale--;
- continue; // scale by 10
- }
-
- // Round final result. See if remainder >= 1/2 of divisor.
- // If remainder == 1/2 divisor, round up if odd or sticky bit set.
- //
- power >>= 1; // power of 10 always even
- if (power <= remainder && (power < remainder || ((result[0] & 1) | sticky) != 0) && ++result[0] == 0)
- {
- uint cur = 0;
- do
- {
- Debug.Assert(cur + 1 < bufRes->Length);
- }
- while (++result[++cur] == 0);
-
- if (cur > 2)
- {
- // The rounding caused us to carry beyond 96 bits.
- // Scale by 10 more.
- //
- if (scale == 0)
- goto ThrowOverflow;
- hiRes = cur;
- sticky = 0; // no sticky bit
- remainder = 0; // or remainder
- newScale = 1;
- scale--;
- continue; // scale by 10
- }
- }
-
- break;
- } // while (true)
- }
- return scale;
-
-ThrowOverflow:
- Number.ThrowOverflowException(TypeCode.Decimal);
- return 0;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe uint DivByConst(uint* result, uint hiRes, out uint quotient, out uint remainder, uint power)
- {
- uint high = result[hiRes];
- remainder = high - (quotient = high / power) * power;
- for (uint i = hiRes - 1; (int)i >= 0; i--)
- {
-#if BIT64
- ulong num = result[i] + ((ulong)remainder << 32);
- remainder = (uint)num - (result[i] = (uint)(num / power)) * power;
-#else
- // 32-bit RyuJIT doesn't convert 64-bit division by constant into multiplication by reciprocal. Do half-width divisions instead.
- Debug.Assert(power <= ushort.MaxValue);
-#if BIGENDIAN
- const int low16 = 2, high16 = 0;
-#else
- const int low16 = 0, high16 = 2;
-#endif
- // byte* is used here because Roslyn doesn't do constant propagation for pointer arithmetic
- uint num = *(ushort*)((byte*)result + i * 4 + high16) + (remainder << 16);
- uint div = num / power;
- remainder = num - div * power;
- *(ushort*)((byte*)result + i * 4 + high16) = (ushort)div;
-
- num = *(ushort*)((byte*)result + i * 4 + low16) + (remainder << 16);
- div = num / power;
- remainder = num - div * power;
- *(ushort*)((byte*)result + i * 4 + low16) = (ushort)div;
-#endif
- }
- return power;
- }
-
- /// <summary>
- /// Adjust the quotient to deal with an overflow.
- /// We need to divide by 10, feed in the high bit to undo the overflow and then round as required.
- /// </summary>
- private static int OverflowUnscale(ref Buf12 bufQuo, int scale, bool sticky)
- {
- if (--scale < 0)
- Number.ThrowOverflowException(TypeCode.Decimal);
-
- Debug.Assert(bufQuo.U2 == 0);
-
- // We have overflown, so load the high bit with a one.
- const ulong highbit = 1UL << 32;
- bufQuo.U2 = (uint)(highbit / 10);
- ulong tmp = ((highbit % 10) << 32) + bufQuo.U1;
- uint div = (uint)(tmp / 10);
- bufQuo.U1 = div;
- tmp = ((tmp - div * 10) << 32) + bufQuo.U0;
- div = (uint)(tmp / 10);
- bufQuo.U0 = div;
- uint remainder = (uint)(tmp - div * 10);
- // The remainder is the last digit that does not fit, so we can use it to work out if we need to round up
- if (remainder > 5 || remainder == 5 && (sticky || (bufQuo.U0 & 1) != 0))
- Add32To96(ref bufQuo, 1);
- return scale;
- }
-
- /// <summary>
- /// Determine the max power of 10, &lt;= 9, that the quotient can be scaled
- /// up by and still fit in 96 bits.
- /// </summary>
- /// <param name="bufQuo">96-bit quotient</param>
- /// <param name="scale ">Scale factor of quotient, range -DEC_SCALE_MAX to DEC_SCALE_MAX-1</param>
- /// <returns>power of 10 to scale by</returns>
- private static int SearchScale(ref Buf12 bufQuo, int scale)
- {
- const uint OVFL_MAX_9_HI = 4;
- const uint OVFL_MAX_8_HI = 42;
- const uint OVFL_MAX_7_HI = 429;
- const uint OVFL_MAX_6_HI = 4294;
- const uint OVFL_MAX_5_HI = 42949;
- const uint OVFL_MAX_4_HI = 429496;
- const uint OVFL_MAX_3_HI = 4294967;
- const uint OVFL_MAX_2_HI = 42949672;
- const uint OVFL_MAX_1_HI = 429496729;
- const ulong OVFL_MAX_9_MIDLO = 5441186219426131129;
-
- uint resHi = bufQuo.U2;
- ulong resMidLo = bufQuo.Low64;
- int curScale = 0;
-
- // Quick check to stop us from trying to scale any more.
- //
- if (resHi > OVFL_MAX_1_HI)
- {
- goto HaveScale;
- }
-
- PowerOvfl[] powerOvfl = PowerOvflValues;
- if (scale > DEC_SCALE_MAX - 9)
- {
- // We can't scale by 10^9 without exceeding the max scale factor.
- // See if we can scale to the max. If not, we'll fall into
- // standard search for scale factor.
- //
- curScale = DEC_SCALE_MAX - scale;
- if (resHi < powerOvfl[curScale - 1].Hi)
- goto HaveScale;
- }
- else if (resHi < OVFL_MAX_9_HI || resHi == OVFL_MAX_9_HI && resMidLo <= OVFL_MAX_9_MIDLO)
- return 9;
-
- // Search for a power to scale by < 9. Do a binary search.
- //
- if (resHi > OVFL_MAX_5_HI)
- {
- if (resHi > OVFL_MAX_3_HI)
- {
- curScale = 2;
- if (resHi > OVFL_MAX_2_HI)
- curScale--;
- }
- else
- {
- curScale = 4;
- if (resHi > OVFL_MAX_4_HI)
- curScale--;
- }
- }
- else
- {
- if (resHi > OVFL_MAX_7_HI)
- {
- curScale = 6;
- if (resHi > OVFL_MAX_6_HI)
- curScale--;
- }
- else
- {
- curScale = 8;
- if (resHi > OVFL_MAX_8_HI)
- curScale--;
- }
- }
-
- // In all cases, we already found we could not use the power one larger.
- // So if we can use this power, it is the biggest, and we're done. If
- // we can't use this power, the one below it is correct for all cases
- // unless it's 10^1 -- we might have to go to 10^0 (no scaling).
- //
- if (resHi == powerOvfl[curScale - 1].Hi && resMidLo > powerOvfl[curScale - 1].MidLo)
- curScale--;
-
- HaveScale:
- // curScale = largest power of 10 we can scale by without overflow,
- // curScale < 9. See if this is enough to make scale factor
- // positive if it isn't already.
- //
- if (curScale + scale < 0)
- Number.ThrowOverflowException(TypeCode.Decimal);
-
- return curScale;
- }
-
- /// <summary>
- /// Add a 32-bit uint to an array of 3 uints representing a 96-bit integer.
- /// </summary>
- /// <returns>Returns false if there is an overflow</returns>
- private static bool Add32To96(ref Buf12 bufNum, uint value)
- {
- if ((bufNum.Low64 += value) < value)
- {
- if (++bufNum.U2 == 0)
- return false;
- }
- return true;
- }
-
- /// <summary>
- /// Adds or subtracts two decimal values.
- /// On return, d1 contains the result of the operation and d2 is trashed.
- /// </summary>
- /// <param name="sign">True means subtract and false means add.</param>
- internal static unsafe void DecAddSub(ref DecCalc d1, ref DecCalc d2, bool sign)
- {
- ulong low64 = d1.Low64;
- uint high = d1.High, flags = d1.uflags, d2flags = d2.uflags;
-
- uint xorflags = d2flags ^ flags;
- sign ^= (xorflags & SignMask) != 0;
-
- if ((xorflags & ScaleMask) == 0)
- {
- // Scale factors are equal, no alignment necessary.
- //
- goto AlignedAdd;
- }
- else
- {
- // Scale factors are not equal. Assume that a larger scale
- // factor (more decimal places) is likely to mean that number
- // is smaller. Start by guessing that the right operand has
- // the larger scale factor. The result will have the larger
- // scale factor.
- //
- uint d1flags = flags;
- flags = d2flags & ScaleMask | flags & SignMask; // scale factor of "smaller", but sign of "larger"
- int scale = (int)(flags - d1flags) >> ScaleShift;
-
- if (scale < 0)
- {
- // Guessed scale factor wrong. Swap operands.
- //
- scale = -scale;
- flags = d1flags;
- if (sign)
- flags ^= SignMask;
- low64 = d2.Low64;
- high = d2.High;
- d2 = d1;
- }
-
- uint power;
- ulong tmp64, tmpLow;
-
- // d1 will need to be multiplied by 10^scale so
- // it will have the same scale as d2. We could be
- // extending it to up to 192 bits of precision.
-
- // Scan for zeros in the upper words.
- //
- if (high == 0)
- {
- if (low64 <= uint.MaxValue)
- {
- if ((uint)low64 == 0)
- {
- // Left arg is zero, return right.
- //
- uint signFlags = flags & SignMask;
- if (sign)
- signFlags ^= SignMask;
- d1 = d2;
- d1.uflags = d2.uflags & ScaleMask | signFlags;
- return;
- }
-
- do
- {
- if (scale <= MaxInt32Scale)
- {
- low64 = UInt32x32To64((uint)low64, s_powers10[scale]);
- goto AlignedAdd;
- }
- scale -= MaxInt32Scale;
- low64 = UInt32x32To64((uint)low64, TenToPowerNine);
- } while (low64 <= uint.MaxValue);
- }
-
- do
- {
- power = TenToPowerNine;
- if (scale < MaxInt32Scale)
- power = s_powers10[scale];
- tmpLow = UInt32x32To64((uint)low64, power);
- tmp64 = UInt32x32To64((uint)(low64 >> 32), power) + (tmpLow >> 32);
- low64 = (uint)tmpLow + (tmp64 << 32);
- high = (uint)(tmp64 >> 32);
- if ((scale -= MaxInt32Scale) <= 0)
- goto AlignedAdd;
- } while (high == 0);
- }
-
- while (true)
- {
- // Scaling won't make it larger than 4 uints
- //
- power = TenToPowerNine;
- if (scale < MaxInt32Scale)
- power = s_powers10[scale];
- tmpLow = UInt32x32To64((uint)low64, power);
- tmp64 = UInt32x32To64((uint)(low64 >> 32), power) + (tmpLow >> 32);
- low64 = (uint)tmpLow + (tmp64 << 32);
- tmp64 >>= 32;
- tmp64 += UInt32x32To64(high, power);
-
- scale -= MaxInt32Scale;
- if (tmp64 > uint.MaxValue)
- break;
-
- high = (uint)tmp64;
- // Result fits in 96 bits. Use standard aligned add.
- if (scale <= 0)
- goto AlignedAdd;
- }
-
- // Have to scale by a bunch. Move the number to a buffer where it has room to grow as it's scaled.
- //
- Unsafe.SkipInit(out Buf24 bufNum);
- DebugPoison(ref bufNum);
-
- bufNum.Low64 = low64;
- bufNum.Mid64 = tmp64;
- uint hiProd = 3;
-
- // Scaling loop, up to 10^9 at a time. hiProd stays updated with index of highest non-zero uint.
- //
- for (; scale > 0; scale -= MaxInt32Scale)
- {
- power = TenToPowerNine;
- if (scale < MaxInt32Scale)
- power = s_powers10[scale];
- tmp64 = 0;
- uint* rgulNum = (uint*)&bufNum;
- for (uint cur = 0; ;)
- {
- Debug.Assert(cur < bufNum.Length);
- tmp64 += UInt32x32To64(rgulNum[cur], power);
- rgulNum[cur] = (uint)tmp64;
- cur++;
- tmp64 >>= 32;
- if (cur > hiProd)
- break;
- }
-
- if ((uint)tmp64 != 0)
- {
- // We're extending the result by another uint.
- Debug.Assert(hiProd + 1 < bufNum.Length);
- rgulNum[++hiProd] = (uint)tmp64;
- }
- }
-
- // Scaling complete, do the add. Could be subtract if signs differ.
- //
- tmp64 = bufNum.Low64;
- low64 = d2.Low64;
- uint tmpHigh = bufNum.U2;
- high = d2.High;
-
- if (sign)
- {
- // Signs differ, subtract.
- //
- low64 = tmp64 - low64;
- high = tmpHigh - high;
-
- // Propagate carry
- //
- if (low64 > tmp64)
- {
- high--;
- if (high < tmpHigh)
- goto NoCarry;
- }
- else if (high <= tmpHigh)
- goto NoCarry;
-
- // Carry the subtraction into the higher bits.
- //
- uint* number = (uint*)&bufNum;
- uint cur = 3;
- do
- {
- Debug.Assert(cur < bufNum.Length);
- } while (number[cur++]-- == 0);
- Debug.Assert(hiProd < bufNum.Length);
- if (number[hiProd] == 0 && --hiProd <= 2)
- goto ReturnResult;
- }
- else
- {
- // Signs the same, add.
- //
- low64 += tmp64;
- high += tmpHigh;
-
- // Propagate carry
- //
- if (low64 < tmp64)
- {
- high++;
- if (high > tmpHigh)
- goto NoCarry;
- }
- else if (high >= tmpHigh)
- goto NoCarry;
-
- uint* number = (uint*)&bufNum;
- for (uint cur = 3; ++number[cur++] == 0;)
- {
- Debug.Assert(cur < bufNum.Length);
- if (hiProd < cur)
- {
- number[cur] = 1;
- hiProd = cur;
- break;
- }
- }
- }
-NoCarry:
-
- bufNum.Low64 = low64;
- bufNum.U2 = high;
- scale = ScaleResult(&bufNum, hiProd, (byte)(flags >> ScaleShift));
- flags = (flags & ~ScaleMask) | ((uint)scale << ScaleShift);
- low64 = bufNum.Low64;
- high = bufNum.U2;
- goto ReturnResult;
- }
-
-SignFlip:
- {
- // Got negative result. Flip its sign.
- flags ^= SignMask;
- high = ~high;
- low64 = (ulong)-(long)low64;
- if (low64 == 0)
- high++;
- goto ReturnResult;
- }
-
-AlignedScale:
- {
- // The addition carried above 96 bits.
- // Divide the value by 10, dropping the scale factor.
- //
- if ((flags & ScaleMask) == 0)
- Number.ThrowOverflowException(TypeCode.Decimal);
- flags -= 1 << ScaleShift;
-
- const uint den = 10;
- ulong num = high + (1UL << 32);
- high = (uint)(num / den);
- num = ((num - high * den) << 32) + (low64 >> 32);
- uint div = (uint)(num / den);
- num = ((num - div * den) << 32) + (uint)low64;
- low64 = div;
- low64 <<= 32;
- div = (uint)(num / den);
- low64 += div;
- div = (uint)num - div * den;
-
- // See if we need to round up.
- //
- if (div >= 5 && (div > 5 || (low64 & 1) != 0))
- {
- if (++low64 == 0)
- high++;
- }
- goto ReturnResult;
- }
-
-AlignedAdd:
- {
- ulong d1Low64 = low64;
- uint d1High = high;
- if (sign)
- {
- // Signs differ - subtract
- //
- low64 = d1Low64 - d2.Low64;
- high = d1High - d2.High;
-
- // Propagate carry
- //
- if (low64 > d1Low64)
- {
- high--;
- if (high >= d1High)
- goto SignFlip;
- }
- else if (high > d1High)
- goto SignFlip;
- }
- else
- {
- // Signs are the same - add
- //
- low64 = d1Low64 + d2.Low64;
- high = d1High + d2.High;
-
- // Propagate carry
- //
- if (low64 < d1Low64)
- {
- high++;
- if (high <= d1High)
- goto AlignedScale;
- }
- else if (high < d1High)
- goto AlignedScale;
- }
- goto ReturnResult;
- }
-
-ReturnResult:
- d1.uflags = flags;
- d1.High = high;
- d1.Low64 = low64;
- return;
- }
-
-#endregion
-
- /// <summary>
- /// Convert Decimal to Currency (similar to OleAut32 api.)
- /// </summary>
- internal static long VarCyFromDec(ref DecCalc pdecIn)
- {
- long value;
-
- int scale = pdecIn.Scale - 4;
- // Need to scale to get 4 decimal places. -4 <= scale <= 24.
- //
- if (scale < 0)
- {
- if (pdecIn.High != 0)
- goto ThrowOverflow;
- uint pwr = s_powers10[-scale];
- ulong high = UInt32x32To64(pwr, pdecIn.Mid);
- if (high > uint.MaxValue)
- goto ThrowOverflow;
- ulong low = UInt32x32To64(pwr, pdecIn.Low);
- low += high <<= 32;
- if (low < high)
- goto ThrowOverflow;
- value = (long)low;
- }
- else
- {
- if (scale != 0)
- InternalRound(ref pdecIn, (uint)scale, MidpointRounding.ToEven);
- if (pdecIn.High != 0)
- goto ThrowOverflow;
- value = (long)pdecIn.Low64;
- }
-
- if (value < 0 && (value != long.MinValue || !pdecIn.IsNegative))
- goto ThrowOverflow;
-
- if (pdecIn.IsNegative)
- value = -value;
-
- return value;
-
-ThrowOverflow:
- throw new OverflowException(SR.Overflow_Currency);
- }
-
- /// <summary>
- /// Decimal Compare updated to return values similar to ICompareTo
- /// </summary>
- internal static int VarDecCmp(in decimal d1, in decimal d2)
- {
- if ((d2.Low | d2.Mid | d2.High) == 0)
- {
- if ((d1.Low | d1.Mid | d1.High) == 0)
- return 0;
- return (d1.flags >> 31) | 1;
- }
- if ((d1.Low | d1.Mid | d1.High) == 0)
- return -((d2.flags >> 31) | 1);
-
- int sign = (d1.flags >> 31) - (d2.flags >> 31);
- if (sign != 0)
- return sign;
- return VarDecCmpSub(in d1, in d2);
- }
-
- private static int VarDecCmpSub(in decimal d1, in decimal d2)
- {
- int flags = d2.flags;
- int sign = (flags >> 31) | 1;
- int scale = flags - d1.flags;
-
- ulong low64 = d1.Low64;
- uint high = d1.High;
-
- ulong d2Low64 = d2.Low64;
- uint d2High = d2.High;
-
- if (scale != 0)
- {
- scale >>= ScaleShift;
-
- // Scale factors are not equal. Assume that a larger scale factor (more decimal places) is likely to mean that number is smaller.
- // Start by guessing that the right operand has the larger scale factor.
- if (scale < 0)
- {
- // Guessed scale factor wrong. Swap operands.
- scale = -scale;
- sign = -sign;
-
- ulong tmp64 = low64;
- low64 = d2Low64;
- d2Low64 = tmp64;
-
- uint tmp = high;
- high = d2High;
- d2High = tmp;
- }
-
- // d1 will need to be multiplied by 10^scale so it will have the same scale as d2.
- // Scaling loop, up to 10^9 at a time.
- do
- {
- uint power = scale >= MaxInt32Scale ? TenToPowerNine : s_powers10[scale];
- ulong tmpLow = UInt32x32To64((uint)low64, power);
- ulong tmp = UInt32x32To64((uint)(low64 >> 32), power) + (tmpLow >> 32);
- low64 = (uint)tmpLow + (tmp << 32);
- tmp >>= 32;
- tmp += UInt32x32To64(high, power);
- // If the scaled value has more than 96 significant bits then it's greater than d2
- if (tmp > uint.MaxValue)
- return sign;
- high = (uint)tmp;
- } while ((scale -= MaxInt32Scale) > 0);
- }
-
- uint cmpHigh = high - d2High;
- if (cmpHigh != 0)
- {
- // check for overflow
- if (cmpHigh > high)
- sign = -sign;
- return sign;
- }
-
- ulong cmpLow64 = low64 - d2Low64;
- if (cmpLow64 == 0)
- sign = 0;
- // check for overflow
- else if (cmpLow64 > low64)
- sign = -sign;
- return sign;
- }
-
- /// <summary>
- /// Decimal Multiply
- /// </summary>
- internal static unsafe void VarDecMul(ref DecCalc d1, ref DecCalc d2)
- {
- int scale = (byte)(d1.uflags + d2.uflags >> ScaleShift);
-
- ulong tmp;
- uint hiProd;
- Unsafe.SkipInit(out Buf24 bufProd);
- DebugPoison(ref bufProd);
-
- if ((d1.High | d1.Mid) == 0)
- {
- if ((d2.High | d2.Mid) == 0)
- {
- // Upper 64 bits are zero.
- //
- ulong low64 = UInt32x32To64(d1.Low, d2.Low);
- if (scale > DEC_SCALE_MAX)
- {
- // Result scale is too big. Divide result by power of 10 to reduce it.
- // If the amount to divide by is > 19 the result is guaranteed
- // less than 1/2. [max value in 64 bits = 1.84E19]
- //
- if (scale > DEC_SCALE_MAX + MaxInt64Scale)
- goto ReturnZero;
-
- scale -= DEC_SCALE_MAX + 1;
- ulong power = s_ulongPowers10[scale];
-
- // TODO: https://github.com/dotnet/coreclr/issues/3439
- tmp = low64 / power;
- ulong remainder = low64 - tmp * power;
- low64 = tmp;
-
- // Round result. See if remainder >= 1/2 of divisor.
- // Divisor is a power of 10, so it is always even.
- //
- power >>= 1;
- if (remainder >= power && (remainder > power || ((uint)low64 & 1) > 0))
- low64++;
-
- scale = DEC_SCALE_MAX;
- }
- d1.Low64 = low64;
- d1.uflags = ((d2.uflags ^ d1.uflags) & SignMask) | ((uint)scale << ScaleShift);
- return;
- }
- else
- {
- // Left value is 32-bit, result fits in 4 uints
- tmp = UInt32x32To64(d1.Low, d2.Low);
- bufProd.U0 = (uint)tmp;
-
- tmp = UInt32x32To64(d1.Low, d2.Mid) + (tmp >> 32);
- bufProd.U1 = (uint)tmp;
- tmp >>= 32;
-
- if (d2.High != 0)
- {
- tmp += UInt32x32To64(d1.Low, d2.High);
- if (tmp > uint.MaxValue)
- {
- bufProd.Mid64 = tmp;
- hiProd = 3;
- goto SkipScan;
- }
- }
- bufProd.U2 = (uint)tmp;
- hiProd = 2;
- }
- }
- else if ((d2.High | d2.Mid) == 0)
- {
- // Right value is 32-bit, result fits in 4 uints
- tmp = UInt32x32To64(d2.Low, d1.Low);
- bufProd.U0 = (uint)tmp;
-
- tmp = UInt32x32To64(d2.Low, d1.Mid) + (tmp >> 32);
- bufProd.U1 = (uint)tmp;
- tmp >>= 32;
-
- if (d1.High != 0)
- {
- tmp += UInt32x32To64(d2.Low, d1.High);
- if (tmp > uint.MaxValue)
- {
- bufProd.Mid64 = tmp;
- hiProd = 3;
- goto SkipScan;
- }
- }
- bufProd.U2 = (uint)tmp;
- hiProd = 2;
- }
- else
- {
- // Both operands have bits set in the upper 64 bits.
- //
- // Compute and accumulate the 9 partial products into a
- // 192-bit (24-byte) result.
- //
- // [l-h][l-m][l-l] left high, middle, low
- // x [r-h][r-m][r-l] right high, middle, low
- // ------------------------------
- //
- // [0-h][0-l] l-l * r-l
- // [1ah][1al] l-l * r-m
- // [1bh][1bl] l-m * r-l
- // [2ah][2al] l-m * r-m
- // [2bh][2bl] l-l * r-h
- // [2ch][2cl] l-h * r-l
- // [3ah][3al] l-m * r-h
- // [3bh][3bl] l-h * r-m
- // [4-h][4-l] l-h * r-h
- // ------------------------------
- // [p-5][p-4][p-3][p-2][p-1][p-0] prod[] array
- //
-
- tmp = UInt32x32To64(d1.Low, d2.Low);
- bufProd.U0 = (uint)tmp;
-
- ulong tmp2 = UInt32x32To64(d1.Low, d2.Mid) + (tmp >> 32);
-
- tmp = UInt32x32To64(d1.Mid, d2.Low);
- tmp += tmp2; // this could generate carry
- bufProd.U1 = (uint)tmp;
- if (tmp < tmp2) // detect carry
- tmp2 = (tmp >> 32) | (1UL << 32);
- else
- tmp2 = tmp >> 32;
-
- tmp = UInt32x32To64(d1.Mid, d2.Mid) + tmp2;
-
- if ((d1.High | d2.High) > 0)
- {
- // Highest 32 bits is non-zero. Calculate 5 more partial products.
- //
- tmp2 = UInt32x32To64(d1.Low, d2.High);
- tmp += tmp2; // this could generate carry
- uint tmp3 = 0;
- if (tmp < tmp2) // detect carry
- tmp3 = 1;
-
- tmp2 = UInt32x32To64(d1.High, d2.Low);
- tmp += tmp2; // this could generate carry
- bufProd.U2 = (uint)tmp;
- if (tmp < tmp2) // detect carry
- tmp3++;
- tmp2 = ((ulong)tmp3 << 32) | (tmp >> 32);
-
- tmp = UInt32x32To64(d1.Mid, d2.High);
- tmp += tmp2; // this could generate carry
- tmp3 = 0;
- if (tmp < tmp2) // detect carry
- tmp3 = 1;
-
- tmp2 = UInt32x32To64(d1.High, d2.Mid);
- tmp += tmp2; // this could generate carry
- bufProd.U3 = (uint)tmp;
- if (tmp < tmp2) // detect carry
- tmp3++;
- tmp = ((ulong)tmp3 << 32) | (tmp >> 32);
-
- bufProd.High64 = UInt32x32To64(d1.High, d2.High) + tmp;
-
- hiProd = 5;
- }
- else
- {
- bufProd.Mid64 = tmp;
- hiProd = 3;
- }
- }
-
- // Check for leading zero uints on the product
- //
- uint* product = (uint*)&bufProd;
- while (product[(int)hiProd] == 0)
- {
- if (hiProd == 0)
- goto ReturnZero;
- hiProd--;
- }
-
-SkipScan:
- if (hiProd > 2 || scale > DEC_SCALE_MAX)
- {
- scale = ScaleResult(&bufProd, hiProd, scale);
- }
-
- d1.Low64 = bufProd.Low64;
- d1.High = bufProd.U2;
- d1.uflags = ((d2.uflags ^ d1.uflags) & SignMask) | ((uint)scale << ScaleShift);
- return;
-
-ReturnZero:
- d1 = default;
- }
-
- /// <summary>
- /// Convert float to Decimal
- /// </summary>
- internal static void VarDecFromR4(float input, out DecCalc result)
- {
- result = default;
-
- // The most we can scale by is 10^28, which is just slightly more
- // than 2^93. So a float with an exponent of -94 could just
- // barely reach 0.5, but smaller exponents will always round to zero.
- //
- const uint SNGBIAS = 126;
- int exp = (int)(GetExponent(input) - SNGBIAS);
- if (exp < -94)
- return; // result should be zeroed out
-
- if (exp > 96)
- Number.ThrowOverflowException(TypeCode.Decimal);
-
- uint flags = 0;
- if (input < 0)
- {
- input = -input;
- flags = SignMask;
- }
-
- // Round the input to a 7-digit integer. The R4 format has
- // only 7 digits of precision, and we want to keep garbage digits
- // out of the Decimal were making.
- //
- // Calculate max power of 10 input value could have by multiplying
- // the exponent by log10(2). Using scaled integer multiplcation,
- // log10(2) * 2 ^ 16 = .30103 * 65536 = 19728.3.
- //
- double dbl = input;
- int power = 6 - ((exp * 19728) >> 16);
- // power is between -22 and 35
-
- if (power >= 0)
- {
- // We have less than 7 digits, scale input up.
- //
- if (power > DEC_SCALE_MAX)
- power = DEC_SCALE_MAX;
-
- dbl *= s_doublePowers10[power];
- }
- else
- {
- if (power != -1 || dbl >= 1E7)
- dbl /= s_doublePowers10[-power];
- else
- power = 0; // didn't scale it
- }
-
- Debug.Assert(dbl < 1E7);
- if (dbl < 1E6 && power < DEC_SCALE_MAX)
- {
- dbl *= 10;
- power++;
- Debug.Assert(dbl >= 1E6);
- }
-
- // Round to integer
- //
- uint mant;
- // with SSE4.1 support ROUNDSD can be used
- if (X86.Sse41.IsSupported)
- mant = (uint)(int)Math.Round(dbl);
- else
- {
- mant = (uint)(int)dbl;
- dbl -= (int)mant; // difference between input & integer
- if (dbl > 0.5 || dbl == 0.5 && (mant & 1) != 0)
- mant++;
- }
-
- if (mant == 0)
- return; // result should be zeroed out
-
- if (power < 0)
- {
- // Add -power factors of 10, -power <= (29 - 7) = 22.
- //
- power = -power;
- if (power < 10)
- {
- result.Low64 = UInt32x32To64(mant, s_powers10[power]);
- }
- else
- {
- // Have a big power of 10.
- //
- if (power > 18)
- {
- ulong low64 = UInt32x32To64(mant, s_powers10[power - 18]);
- UInt64x64To128(low64, TenToPowerEighteen, ref result);
- }
- else
- {
- ulong low64 = UInt32x32To64(mant, s_powers10[power - 9]);
- ulong hi64 = UInt32x32To64(TenToPowerNine, (uint)(low64 >> 32));
- low64 = UInt32x32To64(TenToPowerNine, (uint)low64);
- result.Low = (uint)low64;
- hi64 += low64 >> 32;
- result.Mid = (uint)hi64;
- hi64 >>= 32;
- result.High = (uint)hi64;
- }
- }
- }
- else
- {
- // Factor out powers of 10 to reduce the scale, if possible.
- // The maximum number we could factor out would be 6. This
- // comes from the fact we have a 7-digit number, and the
- // MSD must be non-zero -- but the lower 6 digits could be
- // zero. Note also the scale factor is never negative, so
- // we can't scale by any more than the power we used to
- // get the integer.
- //
- int lmax = power;
- if (lmax > 6)
- lmax = 6;
-
- if ((mant & 0xF) == 0 && lmax >= 4)
- {
- const uint den = 10000;
- uint div = mant / den;
- if (mant == div * den)
- {
- mant = div;
- power -= 4;
- lmax -= 4;
- }
- }
-
- if ((mant & 3) == 0 && lmax >= 2)
- {
- const uint den = 100;
- uint div = mant / den;
- if (mant == div * den)
- {
- mant = div;
- power -= 2;
- lmax -= 2;
- }
- }
-
- if ((mant & 1) == 0 && lmax >= 1)
- {
- const uint den = 10;
- uint div = mant / den;
- if (mant == div * den)
- {
- mant = div;
- power--;
- }
- }
-
- flags |= (uint)power << ScaleShift;
- result.Low = mant;
- }
-
- result.uflags = flags;
- }
-
- /// <summary>
- /// Convert double to Decimal
- /// </summary>
- internal static void VarDecFromR8(double input, out DecCalc result)
- {
- result = default;
-
- // The most we can scale by is 10^28, which is just slightly more
- // than 2^93. So a float with an exponent of -94 could just
- // barely reach 0.5, but smaller exponents will always round to zero.
- //
- const uint DBLBIAS = 1022;
- int exp = (int)(GetExponent(input) - DBLBIAS);
- if (exp < -94)
- return; // result should be zeroed out
-
- if (exp > 96)
- Number.ThrowOverflowException(TypeCode.Decimal);
-
- uint flags = 0;
- if (input < 0)
- {
- input = -input;
- flags = SignMask;
- }
-
- // Round the input to a 15-digit integer. The R8 format has
- // only 15 digits of precision, and we want to keep garbage digits
- // out of the Decimal were making.
- //
- // Calculate max power of 10 input value could have by multiplying
- // the exponent by log10(2). Using scaled integer multiplcation,
- // log10(2) * 2 ^ 16 = .30103 * 65536 = 19728.3.
- //
- double dbl = input;
- int power = 14 - ((exp * 19728) >> 16);
- // power is between -14 and 43
-
- if (power >= 0)
- {
- // We have less than 15 digits, scale input up.
- //
- if (power > DEC_SCALE_MAX)
- power = DEC_SCALE_MAX;
-
- dbl *= s_doublePowers10[power];
- }
- else
- {
- if (power != -1 || dbl >= 1E15)
- dbl /= s_doublePowers10[-power];
- else
- power = 0; // didn't scale it
- }
-
- Debug.Assert(dbl < 1E15);
- if (dbl < 1E14 && power < DEC_SCALE_MAX)
- {
- dbl *= 10;
- power++;
- Debug.Assert(dbl >= 1E14);
- }
-
- // Round to int64
- //
- ulong mant;
- // with SSE4.1 support ROUNDSD can be used
- if (X86.Sse41.IsSupported)
- mant = (ulong)(long)Math.Round(dbl);
- else
- {
- mant = (ulong)(long)dbl;
- dbl -= (long)mant; // difference between input & integer
- if (dbl > 0.5 || dbl == 0.5 && (mant & 1) != 0)
- mant++;
- }
-
- if (mant == 0)
- return; // result should be zeroed out
-
- if (power < 0)
- {
- // Add -power factors of 10, -power <= (29 - 15) = 14.
- //
- power = -power;
- if (power < 10)
- {
- uint pow10 = s_powers10[power];
- ulong low64 = UInt32x32To64((uint)mant, pow10);
- ulong hi64 = UInt32x32To64((uint)(mant >> 32), pow10);
- result.Low = (uint)low64;
- hi64 += low64 >> 32;
- result.Mid = (uint)hi64;
- hi64 >>= 32;
- result.High = (uint)hi64;
- }
- else
- {
- // Have a big power of 10.
- //
- Debug.Assert(power <= 14);
- UInt64x64To128(mant, s_ulongPowers10[power - 1], ref result);
- }
- }
- else
- {
- // Factor out powers of 10 to reduce the scale, if possible.
- // The maximum number we could factor out would be 14. This
- // comes from the fact we have a 15-digit number, and the
- // MSD must be non-zero -- but the lower 14 digits could be
- // zero. Note also the scale factor is never negative, so
- // we can't scale by any more than the power we used to
- // get the integer.
- //
- int lmax = power;
- if (lmax > 14)
- lmax = 14;
-
- if ((byte)mant == 0 && lmax >= 8)
- {
- const uint den = 100000000;
- ulong div = mant / den;
- if ((uint)mant == (uint)(div * den))
- {
- mant = div;
- power -= 8;
- lmax -= 8;
- }
- }
-
- if (((uint)mant & 0xF) == 0 && lmax >= 4)
- {
- const uint den = 10000;
- ulong div = mant / den;
- if ((uint)mant == (uint)(div * den))
- {
- mant = div;
- power -= 4;
- lmax -= 4;
- }
- }
-
- if (((uint)mant & 3) == 0 && lmax >= 2)
- {
- const uint den = 100;
- ulong div = mant / den;
- if ((uint)mant == (uint)(div * den))
- {
- mant = div;
- power -= 2;
- lmax -= 2;
- }
- }
-
- if (((uint)mant & 1) == 0 && lmax >= 1)
- {
- const uint den = 10;
- ulong div = mant / den;
- if ((uint)mant == (uint)(div * den))
- {
- mant = div;
- power--;
- }
- }
-
- flags |= (uint)power << ScaleShift;
- result.Low64 = mant;
- }
-
- result.uflags = flags;
- }
-
- /// <summary>
- /// Convert Decimal to float
- /// </summary>
- internal static float VarR4FromDec(in decimal value)
- {
- return (float)VarR8FromDec(in value);
- }
-
- /// <summary>
- /// Convert Decimal to double
- /// </summary>
- internal static double VarR8FromDec(in decimal value)
- {
- // Value taken via reverse engineering the double that corresponds to 2^64. (oleaut32 has ds2to64 = DEFDS(0, 0, DBLBIAS + 65, 0))
- const double ds2to64 = 1.8446744073709552e+019;
-
- double dbl = ((double)value.Low64 +
- (double)value.High * ds2to64) / s_doublePowers10[value.Scale];
-
- if (value.IsNegative)
- dbl = -dbl;
-
- return dbl;
- }
-
- internal static int GetHashCode(in decimal d)
- {
- if ((d.Low | d.Mid | d.High) == 0)
- return 0;
-
- uint flags = (uint)d.flags;
- if ((flags & ScaleMask) == 0 || (d.Low & 1) != 0)
- return (int)(flags ^ d.High ^ d.Mid ^ d.Low);
-
- int scale = (byte)(flags >> ScaleShift);
- uint low = d.Low;
- ulong high64 = ((ulong)d.High << 32) | d.Mid;
-
- Unscale(ref low, ref high64, ref scale);
-
- flags = (flags & ~ScaleMask) | (uint)scale << ScaleShift;
- return (int)(flags ^ (uint)(high64 >> 32) ^ (uint)high64 ^ low);
- }
-
- /// <summary>
- /// Divides two decimal values.
- /// On return, d1 contains the result of the operation.
- /// </summary>
- internal static unsafe void VarDecDiv(ref DecCalc d1, ref DecCalc d2)
- {
- Unsafe.SkipInit(out Buf12 bufQuo);
- DebugPoison(ref bufQuo);
-
- uint power;
- int curScale;
-
- int scale = (sbyte)(d1.uflags - d2.uflags >> ScaleShift);
- bool unscale = false;
- uint tmp;
-
- if ((d2.High | d2.Mid) == 0)
- {
- // Divisor is only 32 bits. Easy divide.
- //
- uint den = d2.Low;
- if (den == 0)
- throw new DivideByZeroException();
-
- bufQuo.Low64 = d1.Low64;
- bufQuo.U2 = d1.High;
- uint remainder = Div96By32(ref bufQuo, den);
-
- while (true)
- {
- if (remainder == 0)
- {
- if (scale < 0)
- {
- curScale = Math.Min(9, -scale);
- goto HaveScale;
- }
- break;
- }
-
- // We need to unscale if and only if we have a non-zero remainder
- unscale = true;
-
- // We have computed a quotient based on the natural scale
- // ( <dividend scale> - <divisor scale> ). We have a non-zero
- // remainder, so now we should increase the scale if possible to
- // include more quotient bits.
- //
- // If it doesn't cause overflow, we'll loop scaling by 10^9 and
- // computing more quotient bits as long as the remainder stays
- // non-zero. If scaling by that much would cause overflow, we'll
- // drop out of the loop and scale by as much as we can.
- //
- // Scaling by 10^9 will overflow if bufQuo[2].bufQuo[1] >= 2^32 / 10^9
- // = 4.294 967 296. So the upper limit is bufQuo[2] == 4 and
- // bufQuo[1] == 0.294 967 296 * 2^32 = 1,266,874,889.7+. Since
- // quotient bits in bufQuo[0] could be all 1's, then 1,266,874,888
- // is the largest value in bufQuo[1] (when bufQuo[2] == 4) that is
- // assured not to overflow.
- //
- if (scale == DEC_SCALE_MAX || (curScale = SearchScale(ref bufQuo, scale)) == 0)
- {
- // No more scaling to be done, but remainder is non-zero.
- // Round quotient.
- //
- tmp = remainder << 1;
- if (tmp < remainder || tmp >= den && (tmp > den || (bufQuo.U0 & 1) != 0))
- goto RoundUp;
- break;
- }
-
- HaveScale:
- power = s_powers10[curScale];
- scale += curScale;
-
- if (IncreaseScale(ref bufQuo, power) != 0)
- goto ThrowOverflow;
-
- ulong num = UInt32x32To64(remainder, power);
- // TODO: https://github.com/dotnet/coreclr/issues/3439
- uint div = (uint)(num / den);
- remainder = (uint)num - div * den;
-
- if (!Add32To96(ref bufQuo, div))
- {
- scale = OverflowUnscale(ref bufQuo, scale, remainder != 0);
- break;
- }
- } // while (true)
- }
- else
- {
- // Divisor has bits set in the upper 64 bits.
- //
- // Divisor must be fully normalized (shifted so bit 31 of the most
- // significant uint is 1). Locate the MSB so we know how much to
- // normalize by. The dividend will be shifted by the same amount so
- // the quotient is not changed.
- //
- tmp = d2.High;
- if (tmp == 0)
- tmp = d2.Mid;
-
- curScale = BitOperations.LeadingZeroCount(tmp);
-
- // Shift both dividend and divisor left by curScale.
- //
- Unsafe.SkipInit(out Buf16 bufRem);
- DebugPoison(ref bufRem);
-
- bufRem.Low64 = d1.Low64 << curScale;
- bufRem.High64 = (d1.Mid + ((ulong)d1.High << 32)) >> (32 - curScale);
-
- ulong divisor = d2.Low64 << curScale;
-
- if (d2.High == 0)
- {
- // Have a 64-bit divisor in sdlDivisor. The remainder
- // (currently 96 bits spread over 4 uints) will be < divisor.
- //
- bufQuo.U2 = 0;
- bufQuo.U1 = Div96By64(ref *(Buf12*)&bufRem.U1, divisor);
- bufQuo.U0 = Div96By64(ref *(Buf12*)&bufRem, divisor);
-
- while (true)
- {
- if (bufRem.Low64 == 0)
- {
- if (scale < 0)
- {
- curScale = Math.Min(9, -scale);
- goto HaveScale64;
- }
- break;
- }
-
- // We need to unscale if and only if we have a non-zero remainder
- unscale = true;
-
- // Remainder is non-zero. Scale up quotient and remainder by
- // powers of 10 so we can compute more significant bits.
- //
- if (scale == DEC_SCALE_MAX || (curScale = SearchScale(ref bufQuo, scale)) == 0)
- {
- // No more scaling to be done, but remainder is non-zero.
- // Round quotient.
- //
- ulong tmp64 = bufRem.Low64;
- if ((long)tmp64 < 0 || (tmp64 <<= 1) > divisor ||
- (tmp64 == divisor && (bufQuo.U0 & 1) != 0))
- goto RoundUp;
- break;
- }
-
- HaveScale64:
- power = s_powers10[curScale];
- scale += curScale;
-
- if (IncreaseScale(ref bufQuo, power) != 0)
- goto ThrowOverflow;
-
- IncreaseScale64(ref *(Buf12*)&bufRem, power);
- tmp = Div96By64(ref *(Buf12*)&bufRem, divisor);
- if (!Add32To96(ref bufQuo, tmp))
- {
- scale = OverflowUnscale(ref bufQuo, scale, bufRem.Low64 != 0);
- break;
- }
- } // while (true)
- }
- else
- {
- // Have a 96-bit divisor in bufDivisor.
- //
- // Start by finishing the shift left by curScale.
- //
- Unsafe.SkipInit(out Buf12 bufDivisor);
- DebugPoison(ref bufDivisor);
-
- bufDivisor.Low64 = divisor;
- bufDivisor.U2 = (uint)((d2.Mid + ((ulong)d2.High << 32)) >> (32 - curScale));
-
- // The remainder (currently 96 bits spread over 4 uints) will be < divisor.
- //
- bufQuo.Low64 = Div128By96(ref bufRem, ref bufDivisor);
- bufQuo.U2 = 0;
-
- while (true)
- {
- if ((bufRem.Low64 | bufRem.U2) == 0)
- {
- if (scale < 0)
- {
- curScale = Math.Min(9, -scale);
- goto HaveScale96;
- }
- break;
- }
-
- // We need to unscale if and only if we have a non-zero remainder
- unscale = true;
-
- // Remainder is non-zero. Scale up quotient and remainder by
- // powers of 10 so we can compute more significant bits.
- //
- if (scale == DEC_SCALE_MAX || (curScale = SearchScale(ref bufQuo, scale)) == 0)
- {
- // No more scaling to be done, but remainder is non-zero.
- // Round quotient.
- //
- if ((int)bufRem.U2 < 0)
- {
- goto RoundUp;
- }
-
- tmp = bufRem.U1 >> 31;
- bufRem.Low64 <<= 1;
- bufRem.U2 = (bufRem.U2 << 1) + tmp;
-
- if (bufRem.U2 > bufDivisor.U2 || bufRem.U2 == bufDivisor.U2 &&
- (bufRem.Low64 > bufDivisor.Low64 || bufRem.Low64 == bufDivisor.Low64 &&
- (bufQuo.U0 & 1) != 0))
- goto RoundUp;
- break;
- }
-
- HaveScale96:
- power = s_powers10[curScale];
- scale += curScale;
-
- if (IncreaseScale(ref bufQuo, power) != 0)
- goto ThrowOverflow;
-
- bufRem.U3 = IncreaseScale(ref *(Buf12*)&bufRem, power);
- tmp = Div128By96(ref bufRem, ref bufDivisor);
- if (!Add32To96(ref bufQuo, tmp))
- {
- scale = OverflowUnscale(ref bufQuo, scale, (bufRem.Low64 | bufRem.High64) != 0);
- break;
- }
- } // while (true)
- }
- }
-
-Unscale:
- if (unscale)
- {
- uint low = bufQuo.U0;
- ulong high64 = bufQuo.High64;
- Unscale(ref low, ref high64, ref scale);
- d1.Low = low;
- d1.Mid = (uint)high64;
- d1.High = (uint)(high64 >> 32);
- }
- else
- {
- d1.Low64 = bufQuo.Low64;
- d1.High = bufQuo.U2;
- }
-
- d1.uflags = ((d1.uflags ^ d2.uflags) & SignMask) | ((uint)scale << ScaleShift);
- return;
-
-RoundUp:
- {
- if (++bufQuo.Low64 == 0 && ++bufQuo.U2 == 0)
- {
- scale = OverflowUnscale(ref bufQuo, scale, true);
- }
- goto Unscale;
- }
-
-ThrowOverflow:
- Number.ThrowOverflowException(TypeCode.Decimal);
- }
-
- /// <summary>
- /// Computes the remainder between two decimals.
- /// On return, d1 contains the result of the operation and d2 is trashed.
- /// </summary>
- internal static void VarDecMod(ref DecCalc d1, ref DecCalc d2)
- {
- if ((d2.ulo | d2.umid | d2.uhi) == 0)
- throw new DivideByZeroException();
-
- if ((d1.ulo | d1.umid | d1.uhi) == 0)
- return;
-
- // In the operation x % y the sign of y does not matter. Result will have the sign of x.
- d2.uflags = (d2.uflags & ~SignMask) | (d1.uflags & SignMask);
-
- int cmp = VarDecCmpSub(in Unsafe.As<DecCalc, decimal>(ref d1), in Unsafe.As<DecCalc, decimal>(ref d2));
- if (cmp == 0)
- {
- d1.ulo = 0;
- d1.umid = 0;
- d1.uhi = 0;
- if (d2.uflags > d1.uflags)
- d1.uflags = d2.uflags;
- return;
- }
- if ((cmp ^ (int)(d1.uflags & SignMask)) < 0)
- return;
-
- // The divisor is smaller than the dividend and both are non-zero. Calculate the integer remainder using the larger scaling factor.
-
- int scale = (sbyte)(d1.uflags - d2.uflags >> ScaleShift);
- if (scale > 0)
- {
- // Divisor scale can always be increased to dividend scale for remainder calculation.
- do
- {
- uint power = scale >= MaxInt32Scale ? TenToPowerNine : s_powers10[scale];
- ulong tmp = UInt32x32To64(d2.Low, power);
- d2.Low = (uint)tmp;
- tmp >>= 32;
- tmp += (d2.Mid + ((ulong)d2.High << 32)) * power;
- d2.Mid = (uint)tmp;
- d2.High = (uint)(tmp >> 32);
- } while ((scale -= MaxInt32Scale) > 0);
- scale = 0;
- }
-
- do
- {
- if (scale < 0)
- {
- d1.uflags = d2.uflags;
- // Try to scale up dividend to match divisor.
- Unsafe.SkipInit(out Buf12 bufQuo);
- DebugPoison(ref bufQuo);
-
- bufQuo.Low64 = d1.Low64;
- bufQuo.U2 = d1.High;
- do
- {
- int iCurScale = SearchScale(ref bufQuo, DEC_SCALE_MAX + scale);
- if (iCurScale == 0)
- break;
- uint power = iCurScale >= MaxInt32Scale ? TenToPowerNine : s_powers10[iCurScale];
- scale += iCurScale;
- ulong tmp = UInt32x32To64(bufQuo.U0, power);
- bufQuo.U0 = (uint)tmp;
- tmp >>= 32;
- bufQuo.High64 = tmp + bufQuo.High64 * power;
- if (power != TenToPowerNine)
- break;
- }
- while (scale < 0);
- d1.Low64 = bufQuo.Low64;
- d1.High = bufQuo.U2;
- }
-
- if (d1.High == 0)
- {
- Debug.Assert(d2.High == 0);
- Debug.Assert(scale == 0);
- d1.Low64 %= d2.Low64;
- return;
- }
- else if ((d2.High | d2.Mid) == 0)
- {
- uint den = d2.Low;
- ulong tmp = ((ulong)d1.High << 32) | d1.Mid;
- tmp = ((tmp % den) << 32) | d1.Low;
- d1.Low64 = tmp % den;
- d1.High = 0;
- }
- else
- {
- VarDecModFull(ref d1, ref d2, scale);
- return;
- }
- } while (scale < 0);
- }
-
- private static unsafe void VarDecModFull(ref DecCalc d1, ref DecCalc d2, int scale)
- {
- // Divisor has bits set in the upper 64 bits.
- //
- // Divisor must be fully normalized (shifted so bit 31 of the most significant uint is 1).
- // Locate the MSB so we know how much to normalize by.
- // The dividend will be shifted by the same amount so the quotient is not changed.
- //
- uint tmp = d2.High;
- if (tmp == 0)
- tmp = d2.Mid;
- int shift = BitOperations.LeadingZeroCount(tmp);
-
- Unsafe.SkipInit(out Buf28 b);
- DebugPoison(ref b);
-
- b.Buf24.Low64 = d1.Low64 << shift;
- b.Buf24.Mid64 = (d1.Mid + ((ulong)d1.High << 32)) >> (32 - shift);
-
- // The dividend might need to be scaled up to 221 significant bits.
- // Maximum scaling is required when the divisor is 2^64 with scale 28 and is left shifted 31 bits
- // and the dividend is decimal.MaxValue: (2^96 - 1) * 10^28 << 31 = 221 bits.
- uint high = 3;
- while (scale < 0)
- {
- uint power = scale <= -MaxInt32Scale ? TenToPowerNine : s_powers10[-scale];
- uint* buf = (uint*)&b;
- ulong tmp64 = UInt32x32To64(b.Buf24.U0, power);
- b.Buf24.U0 = (uint)tmp64;
- for (int i = 1; i <= high; i++)
- {
- tmp64 >>= 32;
- tmp64 += UInt32x32To64(buf[i], power);
- buf[i] = (uint)tmp64;
- }
- // The high bit of the dividend must not be set.
- if (tmp64 > int.MaxValue)
- {
- Debug.Assert(high + 1 < b.Length);
- buf[++high] = (uint)(tmp64 >> 32);
- }
-
- scale += MaxInt32Scale;
- }
-
- if (d2.High == 0)
- {
- ulong divisor = d2.Low64 << shift;
- switch (high)
- {
- case 6:
- Div96By64(ref *(Buf12*)&b.Buf24.U4, divisor);
- goto case 5;
- case 5:
- Div96By64(ref *(Buf12*)&b.Buf24.U3, divisor);
- goto case 4;
- case 4:
- Div96By64(ref *(Buf12*)&b.Buf24.U2, divisor);
- break;
- }
- Div96By64(ref *(Buf12*)&b.Buf24.U1, divisor);
- Div96By64(ref *(Buf12*)&b, divisor);
-
- d1.Low64 = b.Buf24.Low64 >> shift;
- d1.High = 0;
- }
- else
- {
- Unsafe.SkipInit(out Buf12 bufDivisor);
- DebugPoison(ref bufDivisor);
-
- bufDivisor.Low64 = d2.Low64 << shift;
- bufDivisor.U2 = (uint)((d2.Mid + ((ulong)d2.High << 32)) >> (32 - shift));
-
- switch (high)
- {
- case 6:
- Div128By96(ref *(Buf16*)&b.Buf24.U3, ref bufDivisor);
- goto case 5;
- case 5:
- Div128By96(ref *(Buf16*)&b.Buf24.U2, ref bufDivisor);
- goto case 4;
- case 4:
- Div128By96(ref *(Buf16*)&b.Buf24.U1, ref bufDivisor);
- break;
- }
- Div128By96(ref *(Buf16*)&b, ref bufDivisor);
-
- d1.Low64 = (b.Buf24.Low64 >> shift) + ((ulong)b.Buf24.U2 << (32 - shift) << 32);
- d1.High = b.Buf24.U2 >> shift;
- }
- }
-
- // Does an in-place round by the specified scale
- internal static void InternalRound(ref DecCalc d, uint scale, MidpointRounding mode)
- {
- // the scale becomes the desired decimal count
- d.uflags -= scale << ScaleShift;
-
- uint remainder, sticky = 0, power;
- // First divide the value by constant 10^9 up to three times
- while (scale >= MaxInt32Scale)
- {
- scale -= MaxInt32Scale;
-
- const uint divisor = TenToPowerNine;
- uint n = d.uhi;
- if (n == 0)
- {
- ulong tmp = d.Low64;
- ulong div = tmp / divisor;
- d.Low64 = div;
- remainder = (uint)(tmp - div * divisor);
- }
- else
- {
- uint q;
- d.uhi = q = n / divisor;
- remainder = n - q * divisor;
- n = d.umid;
- if ((n | remainder) != 0)
- {
- d.umid = q = (uint)((((ulong)remainder << 32) | n) / divisor);
- remainder = n - q * divisor;
- }
- n = d.ulo;
- if ((n | remainder) != 0)
- {
- d.ulo = q = (uint)((((ulong)remainder << 32) | n) / divisor);
- remainder = n - q * divisor;
- }
- }
- power = divisor;
- if (scale == 0)
- goto checkRemainder;
- sticky |= remainder;
- }
-
- {
- power = s_powers10[scale];
- // TODO: https://github.com/dotnet/coreclr/issues/3439
- uint n = d.uhi;
- if (n == 0)
- {
- ulong tmp = d.Low64;
- if (tmp == 0)
- {
- if (mode <= MidpointRounding.ToZero)
- goto done;
- remainder = 0;
- goto checkRemainder;
- }
- ulong div = tmp / power;
- d.Low64 = div;
- remainder = (uint)(tmp - div * power);
- }
- else
- {
- uint q;
- d.uhi = q = n / power;
- remainder = n - q * power;
- n = d.umid;
- if ((n | remainder) != 0)
- {
- d.umid = q = (uint)((((ulong)remainder << 32) | n) / power);
- remainder = n - q * power;
- }
- n = d.ulo;
- if ((n | remainder) != 0)
- {
- d.ulo = q = (uint)((((ulong)remainder << 32) | n) / power);
- remainder = n - q * power;
- }
- }
- }
-
-checkRemainder:
- if (mode == MidpointRounding.ToZero)
- goto done;
- else if (mode == MidpointRounding.ToEven)
- {
- // To do IEEE rounding, we add LSB of result to sticky bits so either causes round up if remainder * 2 == last divisor.
- remainder <<= 1;
- if ((sticky | d.ulo & 1) != 0)
- remainder++;
- if (power >= remainder)
- goto done;
- }
- else if (mode == MidpointRounding.AwayFromZero)
- {
- // Round away from zero at the mid point.
- remainder <<= 1;
- if (power > remainder)
- goto done;
- }
- else if (mode == MidpointRounding.ToNegativeInfinity)
- {
- // Round toward -infinity if we have chopped off a non-zero amount from a negative value.
- if ((remainder | sticky) == 0 || !d.IsNegative)
- goto done;
- }
- else
- {
- Debug.Assert(mode == MidpointRounding.ToPositiveInfinity);
- // Round toward infinity if we have chopped off a non-zero amount from a positive value.
- if ((remainder | sticky) == 0 || d.IsNegative)
- goto done;
- }
- if (++d.Low64 == 0)
- d.uhi++;
-done:
- return;
- }
-
- internal static uint DecDivMod1E9(ref DecCalc value)
- {
- ulong high64 = ((ulong)value.uhi << 32) + value.umid;
- ulong div64 = high64 / TenToPowerNine;
- value.uhi = (uint)(div64 >> 32);
- value.umid = (uint)div64;
-
- ulong num = ((high64 - (uint)div64 * TenToPowerNine) << 32) + value.ulo;
- uint div = (uint)(num / TenToPowerNine);
- value.ulo = div;
- return (uint)num - div * TenToPowerNine;
- }
-
- private struct PowerOvfl
- {
- public readonly uint Hi;
- public readonly ulong MidLo;
-
- public PowerOvfl(uint hi, uint mid, uint lo)
- {
- Hi = hi;
- MidLo = ((ulong)mid << 32) + lo;
- }
- }
-
- private static readonly PowerOvfl[] PowerOvflValues = new[]
- {
- // This is a table of the largest values that can be in the upper two
- // uints of a 96-bit number that will not overflow when multiplied
- // by a given power. For the upper word, this is a table of
- // 2^32 / 10^n for 1 <= n <= 8. For the lower word, this is the
- // remaining fraction part * 2^32. 2^32 = 4294967296.
- //
- new PowerOvfl(429496729, 2576980377, 2576980377), // 10^1 remainder 0.6
- new PowerOvfl(42949672, 4123168604, 687194767), // 10^2 remainder 0.16
- new PowerOvfl(4294967, 1271310319, 2645699854), // 10^3 remainder 0.616
- new PowerOvfl(429496, 3133608139, 694066715), // 10^4 remainder 0.1616
- new PowerOvfl(42949, 2890341191, 2216890319), // 10^5 remainder 0.51616
- new PowerOvfl(4294, 4154504685, 2369172679), // 10^6 remainder 0.551616
- new PowerOvfl(429, 2133437386, 4102387834), // 10^7 remainder 0.9551616
- new PowerOvfl(42, 4078814305, 410238783), // 10^8 remainder 0.09991616
- };
-
- [StructLayout(LayoutKind.Explicit)]
- private struct Buf12
- {
- [FieldOffset(0 * 4)]
- public uint U0;
- [FieldOffset(1 * 4)]
- public uint U1;
- [FieldOffset(2 * 4)]
- public uint U2;
-
- [FieldOffset(0)]
- private ulong ulo64LE;
- [FieldOffset(4)]
- private ulong uhigh64LE;
-
- public ulong Low64
- {
-#if BIGENDIAN
- get => ((ulong)U1 << 32) | U0;
- set { U1 = (uint)(value >> 32); U0 = (uint)value; }
-#else
- get => ulo64LE;
- set => ulo64LE = value;
-#endif
- }
-
- /// <summary>
- /// U1-U2 combined (overlaps with Low64)
- /// </summary>
- public ulong High64
- {
-#if BIGENDIAN
- get => ((ulong)U2 << 32) | U1;
- set { U2 = (uint)(value >> 32); U1 = (uint)value; }
-#else
- get => uhigh64LE;
- set => uhigh64LE = value;
-#endif
- }
- }
-
- [StructLayout(LayoutKind.Explicit)]
- private struct Buf16
- {
- [FieldOffset(0 * 4)]
- public uint U0;
- [FieldOffset(1 * 4)]
- public uint U1;
- [FieldOffset(2 * 4)]
- public uint U2;
- [FieldOffset(3 * 4)]
- public uint U3;
-
- [FieldOffset(0 * 8)]
- private ulong ulo64LE;
- [FieldOffset(1 * 8)]
- private ulong uhigh64LE;
-
- public ulong Low64
- {
-#if BIGENDIAN
- get => ((ulong)U1 << 32) | U0;
- set { U1 = (uint)(value >> 32); U0 = (uint)value; }
-#else
- get => ulo64LE;
- set => ulo64LE = value;
-#endif
- }
-
- public ulong High64
- {
-#if BIGENDIAN
- get => ((ulong)U3 << 32) | U2;
- set { U3 = (uint)(value >> 32); U2 = (uint)value; }
-#else
- get => uhigh64LE;
- set => uhigh64LE = value;
-#endif
- }
- }
-
- [StructLayout(LayoutKind.Explicit)]
- private struct Buf24
- {
- [FieldOffset(0 * 4)]
- public uint U0;
- [FieldOffset(1 * 4)]
- public uint U1;
- [FieldOffset(2 * 4)]
- public uint U2;
- [FieldOffset(3 * 4)]
- public uint U3;
- [FieldOffset(4 * 4)]
- public uint U4;
- [FieldOffset(5 * 4)]
- public uint U5;
-
- [FieldOffset(0 * 8)]
- private ulong ulo64LE;
- [FieldOffset(1 * 8)]
- private ulong umid64LE;
- [FieldOffset(2 * 8)]
- private ulong uhigh64LE;
-
- public ulong Low64
- {
-#if BIGENDIAN
- get => ((ulong)U1 << 32) | U0;
- set { U1 = (uint)(value >> 32); U0 = (uint)value; }
-#else
- get => ulo64LE;
- set => ulo64LE = value;
-#endif
- }
-
- public ulong Mid64
- {
-#if BIGENDIAN
- get => ((ulong)U3 << 32) | U2;
- set { U3 = (uint)(value >> 32); U2 = (uint)value; }
-#else
- get => umid64LE;
- set => umid64LE = value;
-#endif
- }
-
- public ulong High64
- {
-#if BIGENDIAN
- get => ((ulong)U5 << 32) | U4;
- set { U5 = (uint)(value >> 32); U4 = (uint)value; }
-#else
- get => uhigh64LE;
- set => uhigh64LE = value;
-#endif
- }
-
- public int Length => 6;
- }
-
- private struct Buf28
- {
- public Buf24 Buf24;
- public uint U6;
-
- public int Length => 7;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Decimal.cs b/netcore/System.Private.CoreLib/shared/System/Decimal.cs
deleted file mode 100644
index 5366e58a23c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Decimal.cs
+++ /dev/null
@@ -1,1025 +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 System.Buffers.Binary;
-using System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Serialization;
-
-namespace System
-{
- // Implements the Decimal data type. The Decimal data type can
- // represent values ranging from -79,228,162,514,264,337,593,543,950,335 to
- // 79,228,162,514,264,337,593,543,950,335 with 28 significant digits. The
- // Decimal data type is ideally suited to financial calculations that
- // require a large number of significant digits and no round-off errors.
- //
- // The finite set of values of type Decimal are of the form m
- // / 10e, where m is an integer such that
- // -296 <; m <; 296, and e is an integer
- // between 0 and 28 inclusive.
- //
- // Contrary to the float and double data types, decimal
- // fractional numbers such as 0.1 can be represented exactly in the
- // Decimal representation. In the float and double
- // representations, such numbers are often infinite fractions, making those
- // representations more prone to round-off errors.
- //
- // The Decimal class implements widening conversions from the
- // ubyte, char, short, int, and long types
- // to Decimal. These widening conversions never loose any information
- // and never throw exceptions. The Decimal class also implements
- // narrowing conversions from Decimal to ubyte, char,
- // short, int, and long. These narrowing conversions round
- // the Decimal value towards zero to the nearest integer, and then
- // converts that integer to the destination type. An OverflowException
- // is thrown if the result is not within the range of the destination type.
- //
- // The Decimal class provides a widening conversion from
- // Currency to Decimal. This widening conversion never loses any
- // information and never throws exceptions. The Currency class provides
- // a narrowing conversion from Decimal to Currency. This
- // narrowing conversion rounds the Decimal to four decimals and then
- // converts that number to a Currency. An OverflowException
- // is thrown if the result is not within the range of the Currency type.
- //
- // The Decimal class provides narrowing conversions to and from the
- // float and double types. A conversion from Decimal to
- // float or double may loose precision, but will not loose
- // information about the overall magnitude of the numeric value, and will never
- // throw an exception. A conversion from float or double to
- // Decimal throws an OverflowException if the value is not within
- // the range of the Decimal type.
- [StructLayout(LayoutKind.Sequential)]
- [Serializable]
- [System.Runtime.Versioning.NonVersionable] // This only applies to field layout
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly partial struct Decimal : IFormattable, IComparable, IConvertible, IComparable<decimal>, IEquatable<decimal>, IDeserializationCallback, ISpanFormattable
- {
- // Sign mask for the flags field. A value of zero in this bit indicates a
- // positive Decimal value, and a value of one in this bit indicates a
- // negative Decimal value.
- //
- // Look at OleAut's DECIMAL_NEG constant to check for negative values
- // in native code.
- private const int SignMask = unchecked((int)0x80000000);
-
- // Scale mask for the flags field. This byte in the flags field contains
- // the power of 10 to divide the Decimal value by. The scale byte must
- // contain a value between 0 and 28 inclusive.
- private const int ScaleMask = 0x00FF0000;
-
- // Number of bits scale is shifted by.
- private const int ScaleShift = 16;
-
- // Constant representing the Decimal value 0.
- public const decimal Zero = 0m;
-
- // Constant representing the Decimal value 1.
- public const decimal One = 1m;
-
- // Constant representing the Decimal value -1.
- public const decimal MinusOne = -1m;
-
- // Constant representing the largest possible Decimal value. The value of
- // this constant is 79,228,162,514,264,337,593,543,950,335.
- public const decimal MaxValue = 79228162514264337593543950335m;
-
- // Constant representing the smallest possible Decimal value. The value of
- // this constant is -79,228,162,514,264,337,593,543,950,335.
- public const decimal MinValue = -79228162514264337593543950335m;
-
- // The lo, mid, hi, and flags fields contain the representation of the
- // Decimal value. The lo, mid, and hi fields contain the 96-bit integer
- // part of the Decimal. Bits 0-15 (the lower word) of the flags field are
- // unused and must be zero; bits 16-23 contain must contain a value between
- // 0 and 28, indicating the power of 10 to divide the 96-bit integer part
- // by to produce the Decimal value; bits 24-30 are unused and must be zero;
- // and finally bit 31 indicates the sign of the Decimal value, 0 meaning
- // positive and 1 meaning negative.
- //
- // NOTE: Do not change the order in which these fields are declared. The
- // native methods in this class rely on this particular order.
- // Do not rename (binary serialization).
- private readonly int flags;
- private readonly int hi;
- private readonly int lo;
- private readonly int mid;
-
- // Constructs a Decimal from an integer value.
- //
- public Decimal(int value)
- {
- if (value >= 0)
- {
- flags = 0;
- }
- else
- {
- flags = SignMask;
- value = -value;
- }
- lo = value;
- mid = 0;
- hi = 0;
- }
-
- // Constructs a Decimal from an unsigned integer value.
- //
- [CLSCompliant(false)]
- public Decimal(uint value)
- {
- flags = 0;
- lo = (int)value;
- mid = 0;
- hi = 0;
- }
-
- // Constructs a Decimal from a long value.
- //
- public Decimal(long value)
- {
- if (value >= 0)
- {
- flags = 0;
- }
- else
- {
- flags = SignMask;
- value = -value;
- }
- lo = (int)value;
- mid = (int)(value >> 32);
- hi = 0;
- }
-
- // Constructs a Decimal from an unsigned long value.
- //
- [CLSCompliant(false)]
- public Decimal(ulong value)
- {
- flags = 0;
- lo = (int)value;
- mid = (int)(value >> 32);
- hi = 0;
- }
-
- // Constructs a Decimal from a float value.
- //
- public Decimal(float value)
- {
- DecCalc.VarDecFromR4(value, out AsMutable(ref this));
- }
-
- // Constructs a Decimal from a double value.
- //
- public Decimal(double value)
- {
- DecCalc.VarDecFromR8(value, out AsMutable(ref this));
- }
-
- //
- // Decimal <==> Currency conversion.
- //
- // A Currency represents a positive or negative decimal value with 4 digits past the decimal point. The actual Int64 representation used by these methods
- // is the currency value multiplied by 10,000. For example, a currency value of $12.99 would be represented by the Int64 value 129,900.
- //
- public static decimal FromOACurrency(long cy)
- {
- ulong absoluteCy; // has to be ulong to accommodate the case where cy == long.MinValue.
- bool isNegative = false;
- if (cy < 0)
- {
- isNegative = true;
- absoluteCy = (ulong)(-cy);
- }
- else
- {
- absoluteCy = (ulong)cy;
- }
-
- // In most cases, FromOACurrency() produces a Decimal with Scale set to 4. Unless, that is, some of the trailing digits past the decimal point are zero,
- // in which case, for compatibility with .Net, we reduce the Scale by the number of zeros. While the result is still numerically equivalent, the scale does
- // affect the ToString() value. In particular, it prevents a converted currency value of $12.95 from printing uglily as "12.9500".
- int scale = 4;
- if (absoluteCy != 0) // For compatibility, a currency of 0 emits the Decimal "0.0000" (scale set to 4).
- {
- while (scale != 0 && ((absoluteCy % 10) == 0))
- {
- scale--;
- absoluteCy /= 10;
- }
- }
-
- return new decimal((int)absoluteCy, (int)(absoluteCy >> 32), 0, isNegative, (byte)scale);
- }
-
- public static long ToOACurrency(decimal value)
- {
- return DecCalc.VarCyFromDec(ref AsMutable(ref value));
- }
-
- private static bool IsValid(int flags) => (flags & ~(SignMask | ScaleMask)) == 0 && ((uint)(flags & ScaleMask) <= (28 << ScaleShift));
-
- // Constructs a Decimal from an integer array containing a binary
- // representation. The bits argument must be a non-null integer
- // array with four elements. bits[0], bits[1], and
- // bits[2] contain the low, middle, and high 32 bits of the 96-bit
- // integer part of the Decimal. bits[3] contains the scale factor
- // and sign of the Decimal: bits 0-15 (the lower word) are unused and must
- // be zero; bits 16-23 must contain a value between 0 and 28, indicating
- // the power of 10 to divide the 96-bit integer part by to produce the
- // Decimal value; bits 24-30 are unused and must be zero; and finally bit
- // 31 indicates the sign of the Decimal value, 0 meaning positive and 1
- // meaning negative.
- //
- // Note that there are several possible binary representations for the
- // same numeric value. For example, the value 1 can be represented as {1,
- // 0, 0, 0} (integer value 1 with a scale factor of 0) and equally well as
- // {1000, 0, 0, 0x30000} (integer value 1000 with a scale factor of 3).
- // The possible binary representations of a particular value are all
- // equally valid, and all are numerically equivalent.
- //
- public Decimal(int[] bits)
- {
- if (bits == null)
- throw new ArgumentNullException(nameof(bits));
- if (bits.Length == 4)
- {
- int f = bits[3];
- if (IsValid(f))
- {
- lo = bits[0];
- mid = bits[1];
- hi = bits[2];
- flags = f;
- return;
- }
- }
- throw new ArgumentException(SR.Arg_DecBitCtor);
- }
-
- // Constructs a Decimal from its constituent parts.
- //
- public Decimal(int lo, int mid, int hi, bool isNegative, byte scale)
- {
- if (scale > 28)
- throw new ArgumentOutOfRangeException(nameof(scale), SR.ArgumentOutOfRange_DecimalScale);
- this.lo = lo;
- this.mid = mid;
- this.hi = hi;
- flags = ((int)scale) << 16;
- if (isNegative)
- flags |= SignMask;
- }
-
- void IDeserializationCallback.OnDeserialization(object? sender)
- {
- // OnDeserialization is called after each instance of this class is deserialized.
- // This callback method performs decimal validation after being deserialized.
- if (!IsValid(flags))
- throw new SerializationException(SR.Overflow_Decimal);
- }
-
- // Constructs a Decimal from its constituent parts.
- private Decimal(int lo, int mid, int hi, int flags)
- {
- if (IsValid(flags))
- {
- this.lo = lo;
- this.mid = mid;
- this.hi = hi;
- this.flags = flags;
- return;
- }
- throw new ArgumentException(SR.Arg_DecBitCtor);
- }
-
- private Decimal(in decimal d, int flags)
- {
- this = d;
- this.flags = flags;
- }
-
- // Returns the absolute value of the given Decimal. If d is
- // positive, the result is d. If d is negative, the result
- // is -d.
- //
- internal static decimal Abs(in decimal d)
- {
- return new decimal(in d, d.flags & ~SignMask);
- }
-
- // Adds two Decimal values.
- //
- public static decimal Add(decimal d1, decimal d2)
- {
- DecCalc.DecAddSub(ref AsMutable(ref d1), ref AsMutable(ref d2), false);
- return d1;
- }
-
- // Rounds a Decimal to an integer value. The Decimal argument is rounded
- // towards positive infinity.
- public static decimal Ceiling(decimal d)
- {
- int flags = d.flags;
- if ((flags & ScaleMask) != 0)
- DecCalc.InternalRound(ref AsMutable(ref d), (byte)(flags >> ScaleShift), MidpointRounding.ToPositiveInfinity);
- return d;
- }
-
- // Compares two Decimal values, returning an integer that indicates their
- // relationship.
- //
- public static int Compare(decimal d1, decimal d2)
- {
- return DecCalc.VarDecCmp(in d1, in d2);
- }
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type Decimal, this method throws an ArgumentException.
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- return 1;
- if (!(value is decimal))
- throw new ArgumentException(SR.Arg_MustBeDecimal);
-
- decimal other = (decimal)value;
- return DecCalc.VarDecCmp(in this, in other);
- }
-
- public int CompareTo(decimal value)
- {
- return DecCalc.VarDecCmp(in this, in value);
- }
-
- // Divides two Decimal values.
- //
- public static decimal Divide(decimal d1, decimal d2)
- {
- DecCalc.VarDecDiv(ref AsMutable(ref d1), ref AsMutable(ref d2));
- return d1;
- }
-
- // Checks if this Decimal is equal to a given object. Returns true
- // if the given object is a boxed Decimal and its value is equal to the
- // value of this Decimal. Returns false otherwise.
- //
- public override bool Equals(object? value) =>
- value is decimal other &&
- DecCalc.VarDecCmp(in this, in other) == 0;
-
- public bool Equals(decimal value) =>
- DecCalc.VarDecCmp(in this, in value) == 0;
-
- // Returns the hash code for this Decimal.
- //
- public override int GetHashCode() => DecCalc.GetHashCode(in this);
-
- // Compares two Decimal values for equality. Returns true if the two
- // Decimal values are equal, or false if they are not equal.
- //
- public static bool Equals(decimal d1, decimal d2)
- {
- return DecCalc.VarDecCmp(in d1, in d2) == 0;
- }
-
- // Rounds a Decimal to an integer value. The Decimal argument is rounded
- // towards negative infinity.
- //
- public static decimal Floor(decimal d)
- {
- int flags = d.flags;
- if ((flags & ScaleMask) != 0)
- DecCalc.InternalRound(ref AsMutable(ref d), (byte)(flags >> ScaleShift), MidpointRounding.ToNegativeInfinity);
- return d;
- }
-
- // Converts this Decimal to a string. The resulting string consists of an
- // optional minus sign ("-") followed to a sequence of digits ("0" - "9"),
- // optionally followed by a decimal point (".") and another sequence of
- // digits.
- //
- public override string ToString()
- {
- return Number.FormatDecimal(this, null, NumberFormatInfo.CurrentInfo);
- }
-
- public string ToString(string? format)
- {
- return Number.FormatDecimal(this, format, NumberFormatInfo.CurrentInfo);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return Number.FormatDecimal(this, null, NumberFormatInfo.GetInstance(provider));
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- return Number.FormatDecimal(this, format, NumberFormatInfo.GetInstance(provider));
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
- {
- return Number.TryFormatDecimal(this, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten);
- }
-
- // Converts a string to a Decimal. The string must consist of an optional
- // minus sign ("-") followed by a sequence of digits ("0" - "9"). The
- // sequence of digits may optionally contain a single decimal point (".")
- // character. Leading and trailing whitespace characters are allowed.
- // Parse also allows a currency symbol, a trailing negative sign, and
- // parentheses in the number.
- //
- public static decimal Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseDecimal(s, NumberStyles.Number, NumberFormatInfo.CurrentInfo);
- }
-
- public static decimal Parse(string s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseDecimal(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- public static decimal Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseDecimal(s, NumberStyles.Number, NumberFormatInfo.GetInstance(provider));
- }
-
- public static decimal Parse(string s, NumberStyles style, IFormatProvider? provider)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseDecimal(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- public static decimal Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Number, IFormatProvider? provider = null)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- return Number.ParseDecimal(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- public static bool TryParse(string? s, out decimal result)
- {
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return Number.TryParseDecimal(s, NumberStyles.Number, NumberFormatInfo.CurrentInfo, out result) == Number.ParsingStatus.OK;
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, out decimal result)
- {
- return Number.TryParseDecimal(s, NumberStyles.Number, NumberFormatInfo.CurrentInfo, out result) == Number.ParsingStatus.OK;
- }
-
- public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out decimal result)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
-
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return Number.TryParseDecimal(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK;
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out decimal result)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- return Number.TryParseDecimal(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK;
- }
-
- // Returns a binary representation of a Decimal. The return value is an
- // integer array with four elements. Elements 0, 1, and 2 contain the low,
- // middle, and high 32 bits of the 96-bit integer part of the Decimal.
- // Element 3 contains the scale factor and sign of the Decimal: bits 0-15
- // (the lower word) are unused; bits 16-23 contain a value between 0 and
- // 28, indicating the power of 10 to divide the 96-bit integer part by to
- // produce the Decimal value; bits 24-30 are unused; and finally bit 31
- // indicates the sign of the Decimal value, 0 meaning positive and 1
- // meaning negative.
- //
- public static int[] GetBits(decimal d)
- {
- return new int[] { d.lo, d.mid, d.hi, d.flags };
- }
-
- internal static void GetBytes(in decimal d, byte[] buffer)
- {
- Debug.Assert(buffer != null && buffer.Length >= 16, "[GetBytes]buffer != null && buffer.Length >= 16");
- buffer[0] = (byte)d.lo;
- buffer[1] = (byte)(d.lo >> 8);
- buffer[2] = (byte)(d.lo >> 16);
- buffer[3] = (byte)(d.lo >> 24);
-
- buffer[4] = (byte)d.mid;
- buffer[5] = (byte)(d.mid >> 8);
- buffer[6] = (byte)(d.mid >> 16);
- buffer[7] = (byte)(d.mid >> 24);
-
- buffer[8] = (byte)d.hi;
- buffer[9] = (byte)(d.hi >> 8);
- buffer[10] = (byte)(d.hi >> 16);
- buffer[11] = (byte)(d.hi >> 24);
-
- buffer[12] = (byte)d.flags;
- buffer[13] = (byte)(d.flags >> 8);
- buffer[14] = (byte)(d.flags >> 16);
- buffer[15] = (byte)(d.flags >> 24);
- }
-
- internal static decimal ToDecimal(ReadOnlySpan<byte> span)
- {
- Debug.Assert(span.Length >= 16, "span.Length >= 16");
- int lo = BinaryPrimitives.ReadInt32LittleEndian(span);
- int mid = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(4));
- int hi = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(8));
- int flags = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(12));
- return new decimal(lo, mid, hi, flags);
- }
-
- // Returns the larger of two Decimal values.
- //
- internal static ref readonly decimal Max(in decimal d1, in decimal d2)
- {
- return ref DecCalc.VarDecCmp(in d1, in d2) >= 0 ? ref d1 : ref d2;
- }
-
- // Returns the smaller of two Decimal values.
- //
- internal static ref readonly decimal Min(in decimal d1, in decimal d2)
- {
- return ref DecCalc.VarDecCmp(in d1, in d2) < 0 ? ref d1 : ref d2;
- }
-
- public static decimal Remainder(decimal d1, decimal d2)
- {
- DecCalc.VarDecMod(ref AsMutable(ref d1), ref AsMutable(ref d2));
- return d1;
- }
-
- // Multiplies two Decimal values.
- //
- public static decimal Multiply(decimal d1, decimal d2)
- {
- DecCalc.VarDecMul(ref AsMutable(ref d1), ref AsMutable(ref d2));
- return d1;
- }
-
- // Returns the negated value of the given Decimal. If d is non-zero,
- // the result is -d. If d is zero, the result is zero.
- //
- public static decimal Negate(decimal d)
- {
- return new decimal(in d, d.flags ^ SignMask);
- }
-
- // Rounds a Decimal value to a given number of decimal places. The value
- // given by d is rounded to the number of decimal places given by
- // decimals. The decimals argument must be an integer between
- // 0 and 28 inclusive.
- //
- // By default a mid-point value is rounded to the nearest even number. If the mode is
- // passed in, it can also round away from zero.
-
- public static decimal Round(decimal d) => Round(ref d, 0, MidpointRounding.ToEven);
- public static decimal Round(decimal d, int decimals) => Round(ref d, decimals, MidpointRounding.ToEven);
- public static decimal Round(decimal d, MidpointRounding mode) => Round(ref d, 0, mode);
- public static decimal Round(decimal d, int decimals, MidpointRounding mode) => Round(ref d, decimals, mode);
-
- private static decimal Round(ref decimal d, int decimals, MidpointRounding mode)
- {
- if ((uint)decimals > 28)
- throw new ArgumentOutOfRangeException(nameof(decimals), SR.ArgumentOutOfRange_DecimalRound);
- if ((uint)mode > (uint)MidpointRounding.ToPositiveInfinity)
- throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, nameof(MidpointRounding)), nameof(mode));
-
- int scale = d.Scale - decimals;
- if (scale > 0)
- DecCalc.InternalRound(ref AsMutable(ref d), (uint)scale, mode);
- return d;
- }
-
- internal static int Sign(in decimal d) => (d.lo | d.mid | d.hi) == 0 ? 0 : (d.flags >> 31) | 1;
-
- // Subtracts two Decimal values.
- //
- public static decimal Subtract(decimal d1, decimal d2)
- {
- DecCalc.DecAddSub(ref AsMutable(ref d1), ref AsMutable(ref d2), true);
- return d1;
- }
-
- // Converts a Decimal to an unsigned byte. The Decimal value is rounded
- // towards zero to the nearest integer value, and the result of this
- // operation is returned as a byte.
- //
- public static byte ToByte(decimal value)
- {
- uint temp;
- try
- {
- temp = ToUInt32(value);
- }
- catch (OverflowException)
- {
- Number.ThrowOverflowException(TypeCode.Byte);
- throw;
- }
- if (temp != (byte)temp) Number.ThrowOverflowException(TypeCode.Byte);
- return (byte)temp;
- }
-
- // Converts a Decimal to a signed byte. The Decimal value is rounded
- // towards zero to the nearest integer value, and the result of this
- // operation is returned as a byte.
- //
- [CLSCompliant(false)]
- public static sbyte ToSByte(decimal value)
- {
- int temp;
- try
- {
- temp = ToInt32(value);
- }
- catch (OverflowException)
- {
- Number.ThrowOverflowException(TypeCode.SByte);
- throw;
- }
- if (temp != (sbyte)temp) Number.ThrowOverflowException(TypeCode.SByte);
- return (sbyte)temp;
- }
-
- // Converts a Decimal to a short. The Decimal value is
- // rounded towards zero to the nearest integer value, and the result of
- // this operation is returned as a short.
- //
- public static short ToInt16(decimal value)
- {
- int temp;
- try
- {
- temp = ToInt32(value);
- }
- catch (OverflowException)
- {
- Number.ThrowOverflowException(TypeCode.Int16);
- throw;
- }
- if (temp != (short)temp) Number.ThrowOverflowException(TypeCode.Int16);
- return (short)temp;
- }
-
- // Converts a Decimal to a double. Since a double has fewer significant
- // digits than a Decimal, this operation may produce round-off errors.
- //
- public static double ToDouble(decimal d)
- {
- return DecCalc.VarR8FromDec(in d);
- }
-
- // Converts a Decimal to an integer. The Decimal value is rounded towards
- // zero to the nearest integer value, and the result of this operation is
- // returned as an integer.
- //
- public static int ToInt32(decimal d)
- {
- Truncate(ref d);
- if ((d.hi | d.mid) == 0)
- {
- int i = d.lo;
- if (!d.IsNegative)
- {
- if (i >= 0) return i;
- }
- else
- {
- i = -i;
- if (i <= 0) return i;
- }
- }
- throw new OverflowException(SR.Overflow_Int32);
- }
-
- // Converts a Decimal to a long. The Decimal value is rounded towards zero
- // to the nearest integer value, and the result of this operation is
- // returned as a long.
- //
- public static long ToInt64(decimal d)
- {
- Truncate(ref d);
- if (d.hi == 0)
- {
- long l = (long)d.Low64;
- if (!d.IsNegative)
- {
- if (l >= 0) return l;
- }
- else
- {
- l = -l;
- if (l <= 0) return l;
- }
- }
- throw new OverflowException(SR.Overflow_Int64);
- }
-
- // Converts a Decimal to an ushort. The Decimal
- // value is rounded towards zero to the nearest integer value, and the
- // result of this operation is returned as an ushort.
- //
- [CLSCompliant(false)]
- public static ushort ToUInt16(decimal value)
- {
- uint temp;
- try
- {
- temp = ToUInt32(value);
- }
- catch (OverflowException)
- {
- Number.ThrowOverflowException(TypeCode.UInt16);
- throw;
- }
- if (temp != (ushort)temp) Number.ThrowOverflowException(TypeCode.UInt16);
- return (ushort)temp;
- }
-
- // Converts a Decimal to an unsigned integer. The Decimal
- // value is rounded towards zero to the nearest integer value, and the
- // result of this operation is returned as an unsigned integer.
- //
- [CLSCompliant(false)]
- public static uint ToUInt32(decimal d)
- {
- Truncate(ref d);
- if ((d.hi | d.mid) == 0)
- {
- uint i = d.Low;
- if (!d.IsNegative || i == 0)
- return i;
- }
- throw new OverflowException(SR.Overflow_UInt32);
- }
-
- // Converts a Decimal to an unsigned long. The Decimal
- // value is rounded towards zero to the nearest integer value, and the
- // result of this operation is returned as a long.
- //
- [CLSCompliant(false)]
- public static ulong ToUInt64(decimal d)
- {
- Truncate(ref d);
- if (d.hi == 0)
- {
- ulong l = d.Low64;
- if (!d.IsNegative || l == 0)
- return l;
- }
- throw new OverflowException(SR.Overflow_UInt64);
- }
-
- // Converts a Decimal to a float. Since a float has fewer significant
- // digits than a Decimal, this operation may produce round-off errors.
- //
- public static float ToSingle(decimal d)
- {
- return DecCalc.VarR4FromDec(in d);
- }
-
- // Truncates a Decimal to an integer value. The Decimal argument is rounded
- // towards zero to the nearest integer value, corresponding to removing all
- // digits after the decimal point.
- //
- public static decimal Truncate(decimal d)
- {
- Truncate(ref d);
- return d;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void Truncate(ref decimal d)
- {
- int flags = d.flags;
- if ((flags & ScaleMask) != 0)
- DecCalc.InternalRound(ref AsMutable(ref d), (byte)(flags >> ScaleShift), MidpointRounding.ToZero);
- }
-
- public static implicit operator decimal(byte value) => new decimal((uint)value);
-
- [CLSCompliant(false)]
- public static implicit operator decimal(sbyte value) => new decimal(value);
-
- public static implicit operator decimal(short value) => new decimal(value);
-
- [CLSCompliant(false)]
- public static implicit operator decimal(ushort value) => new decimal((uint)value);
-
- public static implicit operator decimal(char value) => new decimal((uint)value);
-
- public static implicit operator decimal(int value) => new decimal(value);
-
- [CLSCompliant(false)]
- public static implicit operator decimal(uint value) => new decimal(value);
-
- public static implicit operator decimal(long value) => new decimal(value);
-
- [CLSCompliant(false)]
- public static implicit operator decimal(ulong value) => new decimal(value);
-
- public static explicit operator decimal(float value) => new decimal(value);
-
- public static explicit operator decimal(double value) => new decimal(value);
-
- public static explicit operator byte(decimal value) => ToByte(value);
-
- [CLSCompliant(false)]
- public static explicit operator sbyte(decimal value) => ToSByte(value);
-
- public static explicit operator char(decimal value)
- {
- ushort temp;
- try
- {
- temp = ToUInt16(value);
- }
- catch (OverflowException e)
- {
- throw new OverflowException(SR.Overflow_Char, e);
- }
- return (char)temp;
- }
-
- public static explicit operator short(decimal value) => ToInt16(value);
-
- [CLSCompliant(false)]
- public static explicit operator ushort(decimal value) => ToUInt16(value);
-
- public static explicit operator int(decimal value) => ToInt32(value);
-
- [CLSCompliant(false)]
- public static explicit operator uint(decimal value) => ToUInt32(value);
-
- public static explicit operator long(decimal value) => ToInt64(value);
-
- [CLSCompliant(false)]
- public static explicit operator ulong(decimal value) => ToUInt64(value);
-
- public static explicit operator float(decimal value) => ToSingle(value);
-
- public static explicit operator double(decimal value) => ToDouble(value);
-
- public static decimal operator +(decimal d) => d;
-
- public static decimal operator -(decimal d) => new decimal(in d, d.flags ^ SignMask);
-
- public static decimal operator ++(decimal d) => Add(d, One);
-
- public static decimal operator --(decimal d) => Subtract(d, One);
-
- public static decimal operator +(decimal d1, decimal d2)
- {
- DecCalc.DecAddSub(ref AsMutable(ref d1), ref AsMutable(ref d2), false);
- return d1;
- }
-
- public static decimal operator -(decimal d1, decimal d2)
- {
- DecCalc.DecAddSub(ref AsMutable(ref d1), ref AsMutable(ref d2), true);
- return d1;
- }
-
- public static decimal operator *(decimal d1, decimal d2)
- {
- DecCalc.VarDecMul(ref AsMutable(ref d1), ref AsMutable(ref d2));
- return d1;
- }
-
- public static decimal operator /(decimal d1, decimal d2)
- {
- DecCalc.VarDecDiv(ref AsMutable(ref d1), ref AsMutable(ref d2));
- return d1;
- }
-
- public static decimal operator %(decimal d1, decimal d2)
- {
- DecCalc.VarDecMod(ref AsMutable(ref d1), ref AsMutable(ref d2));
- return d1;
- }
-
- public static bool operator ==(decimal d1, decimal d2) => DecCalc.VarDecCmp(in d1, in d2) == 0;
-
- public static bool operator !=(decimal d1, decimal d2) => DecCalc.VarDecCmp(in d1, in d2) != 0;
-
- public static bool operator <(decimal d1, decimal d2) => DecCalc.VarDecCmp(in d1, in d2) < 0;
-
- public static bool operator <=(decimal d1, decimal d2) => DecCalc.VarDecCmp(in d1, in d2) <= 0;
-
- public static bool operator >(decimal d1, decimal d2) => DecCalc.VarDecCmp(in d1, in d2) > 0;
-
- public static bool operator >=(decimal d1, decimal d2) => DecCalc.VarDecCmp(in d1, in d2) >= 0;
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.Decimal;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(this);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Decimal", "Char"));
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(this);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(this);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(this);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(this);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(this);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(this);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(this);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(this);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(this);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(this);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return this;
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Decimal", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DefaultBinder.cs b/netcore/System.Private.CoreLib/shared/System/DefaultBinder.cs
deleted file mode 100644
index fed9a020fd8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DefaultBinder.cs
+++ /dev/null
@@ -1,1276 +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 System.Reflection;
-using System.Diagnostics;
-using CultureInfo = System.Globalization.CultureInfo;
-
-namespace System
-{
-#if CORERT
- public sealed
-#else
- internal
-#endif
- partial class DefaultBinder : Binder
- {
- // This method is passed a set of methods and must choose the best
- // fit. The methods all have the same number of arguments and the object
- // array args. On exit, this method will choice the best fit method
- // and coerce the args to match that method. By match, we mean all primitive
- // arguments are exact matchs and all object arguments are exact or subclasses
- // of the target. If the target OR is an interface, the object must implement
- // that interface. There are a couple of exceptions
- // thrown when a method cannot be returned. If no method matchs the args and
- // ArgumentException is thrown. If multiple methods match the args then
- // an AmbiguousMatchException is thrown.
- //
- // The most specific match will be selected.
- //
- public sealed override MethodBase BindToMethod(
- BindingFlags bindingAttr, MethodBase[] match, ref object?[] args,
- ParameterModifier[]? modifiers, CultureInfo? cultureInfo, string[]? names, out object? state)
- {
- if (match == null || match.Length == 0)
- throw new ArgumentException(SR.Arg_EmptyArray, nameof(match));
-
- MethodBase?[] candidates = (MethodBase[])match.Clone();
-
- int i;
- int j;
-
- state = null;
-
-#region Map named parameters to candidate parameter positions
- // We are creating an paramOrder array to act as a mapping
- // between the order of the args and the actual order of the
- // parameters in the method. This order may differ because
- // named parameters (names) may change the order. If names
- // is not provided, then we assume the default mapping (0,1,...)
- int[][] paramOrder = new int[candidates.Length][];
-
- for (i = 0; i < candidates.Length; i++)
- {
- ParameterInfo[] par = candidates[i]!.GetParametersNoCopy();
-
- // args.Length + 1 takes into account the possibility of a last paramArray that can be omitted
- paramOrder[i] = new int[(par.Length > args.Length) ? par.Length : args.Length];
-
- if (names == null)
- {
- // Default mapping
- for (j = 0; j < args.Length; j++)
- paramOrder[i][j] = j;
- }
- else
- {
- // Named parameters, reorder the mapping. If CreateParamOrder fails, it means that the method
- // doesn't have a name that matchs one of the named parameters so we don't consider it any further.
- if (!CreateParamOrder(paramOrder[i], par, names))
- candidates[i] = null;
- }
- }
-#endregion
-
- Type[] paramArrayTypes = new Type[candidates.Length];
-
- Type[] argTypes = new Type[args.Length];
-
-#region Cache the type of the provided arguments
- // object that contain a null are treated as if they were typeless (but match either object
- // references or value classes). We mark this condition by placing a null in the argTypes array.
- for (i = 0; i < args.Length; i++)
- {
- if (args[i] != null)
- {
- argTypes[i] = args[i]!.GetType();
- }
- }
-#endregion
-
- // Find the method that matches...
- int CurIdx = 0;
- bool defaultValueBinding = ((bindingAttr & BindingFlags.OptionalParamBinding) != 0);
-
- Type? paramArrayType;
-
-#region Filter methods by parameter count and type
- for (i = 0; i < candidates.Length; i++)
- {
- paramArrayType = null;
-
- // If we have named parameters then we may have a hole in the candidates array.
- if (candidates[i] == null)
- continue;
-
- // Validate the parameters.
- ParameterInfo[] par = candidates[i]!.GetParametersNoCopy(); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
-
-#region Match method by parameter count
- if (par.Length == 0)
- {
-#region No formal parameters
- if (args.Length != 0)
- {
- if ((candidates[i]!.CallingConvention & CallingConventions.VarArgs) == 0) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- continue;
- }
-
- // This is a valid routine so we move it up the candidates list.
- paramOrder[CurIdx] = paramOrder[i];
- candidates[CurIdx++] = candidates[i];
-
- continue;
-#endregion
- }
- else if (par.Length > args.Length)
- {
-#region Shortage of provided parameters
- // If the number of parameters is greater than the number of args then
- // we are in the situation were we may be using default values.
- for (j = args.Length; j < par.Length - 1; j++)
- {
- if (par[j].DefaultValue == System.DBNull.Value)
- break;
- }
-
- if (j != par.Length - 1)
- continue;
-
- if (par[j].DefaultValue == System.DBNull.Value)
- {
- if (!par[j].ParameterType.IsArray)
- continue;
-
- if (!par[j].IsDefined(typeof(ParamArrayAttribute), true))
- continue;
-
- paramArrayType = par[j].ParameterType.GetElementType();
- }
-#endregion
- }
- else if (par.Length < args.Length)
- {
-#region Excess provided parameters
- // test for the ParamArray case
- int lastArgPos = par.Length - 1;
-
- if (!par[lastArgPos].ParameterType.IsArray)
- continue;
-
- if (!par[lastArgPos].IsDefined(typeof(ParamArrayAttribute), true))
- continue;
-
- if (paramOrder[i][lastArgPos] != lastArgPos)
- continue;
-
- paramArrayType = par[lastArgPos].ParameterType.GetElementType();
-#endregion
- }
- else
- {
-#region Test for paramArray, save paramArray type
- int lastArgPos = par.Length - 1;
-
- if (par[lastArgPos].ParameterType.IsArray
- && par[lastArgPos].IsDefined(typeof(ParamArrayAttribute), true)
- && paramOrder[i][lastArgPos] == lastArgPos)
- {
- if (!par[lastArgPos].ParameterType.IsAssignableFrom(argTypes[lastArgPos]))
- paramArrayType = par[lastArgPos].ParameterType.GetElementType();
- }
-#endregion
- }
-#endregion
-
- Type pCls;
- int argsToCheck = (paramArrayType != null) ? par.Length - 1 : args.Length;
-
-#region Match method by parameter type
- for (j = 0; j < argsToCheck; j++)
- {
-#region Classic argument coersion checks
- // get the formal type
- pCls = par[j].ParameterType;
-
- if (pCls.IsByRef)
- pCls = pCls.GetElementType()!;
-
- // the type is the same
- if (pCls == argTypes[paramOrder[i][j]])
- continue;
-
- // a default value is available
- if (defaultValueBinding && args[paramOrder[i][j]] == Type.Missing)
- continue;
-
- // the argument was null, so it matches with everything
- if (args[paramOrder[i][j]] == null)
- continue;
-
- // the type is Object, so it will match everything
- if (pCls == typeof(object))
- continue;
-
- // now do a "classic" type check
- if (pCls.IsPrimitive)
- {
- if (argTypes[paramOrder[i][j]] == null || !CanChangePrimitive(args[paramOrder[i][j]]?.GetType(), pCls))
- {
- break;
- }
- }
- else
- {
- if (argTypes[paramOrder[i][j]] == null)
- continue;
-
- if (!pCls.IsAssignableFrom(argTypes[paramOrder[i][j]]))
- {
- if (argTypes[paramOrder[i][j]].IsCOMObject)
- {
- if (pCls.IsInstanceOfType(args[paramOrder[i][j]]))
- continue;
- }
- break;
- }
- }
-#endregion
- }
-
- if (paramArrayType != null && j == par.Length - 1)
- {
-#region Check that excess arguments can be placed in the param array
- for (; j < args.Length; j++)
- {
- if (paramArrayType.IsPrimitive)
- {
- if (argTypes[j] == null || !CanChangePrimitive(args[j]?.GetType(), paramArrayType))
- break;
- }
- else
- {
- if (argTypes[j] == null)
- continue;
-
- if (!paramArrayType.IsAssignableFrom(argTypes[j]))
- {
- if (argTypes[j].IsCOMObject)
- {
- if (paramArrayType.IsInstanceOfType(args[j]))
- continue;
- }
-
- break;
- }
- }
- }
-#endregion
- }
-#endregion
-
- if (j == args.Length)
- {
-#region This is a valid routine so we move it up the candidates list
- paramOrder[CurIdx] = paramOrder[i];
- paramArrayTypes[CurIdx] = paramArrayType!;
- candidates[CurIdx++] = candidates[i];
-#endregion
- }
- }
-#endregion
-
- // If we didn't find a method
- if (CurIdx == 0)
- throw new MissingMethodException(SR.MissingMember);
-
- if (CurIdx == 1)
- {
-#region Found only one method
- if (names != null)
- {
- state = new BinderState((int[])paramOrder[0].Clone(), args.Length, paramArrayTypes[0] != null);
- ReorderParams(paramOrder[0], args);
- }
-
- // If the parameters and the args are not the same length or there is a paramArray
- // then we need to create a argument array.
- ParameterInfo[] parms = candidates[0]!.GetParametersNoCopy();
-
- if (parms.Length == args.Length)
- {
- if (paramArrayTypes[0] != null)
- {
- object[] objs = new object[parms.Length];
- int lastPos = parms.Length - 1;
- Array.Copy(args, objs, lastPos);
- objs[lastPos] = Array.CreateInstance(paramArrayTypes[0], 1);
- ((Array)objs[lastPos]).SetValue(args[lastPos], 0);
- args = objs;
- }
- }
- else if (parms.Length > args.Length)
- {
- object?[] objs = new object[parms.Length];
-
- for (i = 0; i < args.Length; i++)
- objs[i] = args[i];
-
- for (; i < parms.Length - 1; i++)
- objs[i] = parms[i].DefaultValue;
-
- if (paramArrayTypes[0] != null)
- objs[i] = Array.CreateInstance(paramArrayTypes[0], 0); // create an empty array for the
-
- else
- objs[i] = parms[i].DefaultValue;
-
- args = objs;
- }
- else
- {
- if ((candidates[0]!.CallingConvention & CallingConventions.VarArgs) == 0)
- {
- object[] objs = new object[parms.Length];
- int paramArrayPos = parms.Length - 1;
- Array.Copy(args, objs, paramArrayPos);
- objs[paramArrayPos] = Array.CreateInstance(paramArrayTypes[0], args.Length - paramArrayPos);
- Array.Copy(args, paramArrayPos, (System.Array)objs[paramArrayPos], 0, args.Length - paramArrayPos);
- args = objs;
- }
- }
-#endregion
-
- return candidates[0]!;
- }
-
- int currentMin = 0;
- bool ambig = false;
- for (i = 1; i < CurIdx; i++)
- {
-#region Walk all of the methods looking the most specific method to invoke
- int newMin = FindMostSpecificMethod(candidates[currentMin]!, paramOrder[currentMin], paramArrayTypes[currentMin],
- candidates[i]!, paramOrder[i], paramArrayTypes[i], argTypes, args);
-
- if (newMin == 0)
- {
- ambig = true;
- }
- else if (newMin == 2)
- {
- currentMin = i;
- ambig = false;
- }
-#endregion
- }
-
- if (ambig)
- throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
-
- // Reorder (if needed)
- if (names != null)
- {
- state = new BinderState((int[])paramOrder[currentMin].Clone(), args.Length, paramArrayTypes[currentMin] != null);
- ReorderParams(paramOrder[currentMin], args);
- }
-
- // If the parameters and the args are not the same length or there is a paramArray
- // then we need to create a argument array.
- ParameterInfo[] parameters = candidates[currentMin]!.GetParametersNoCopy();
- if (parameters.Length == args.Length)
- {
- if (paramArrayTypes[currentMin] != null)
- {
- object[] objs = new object[parameters.Length];
- int lastPos = parameters.Length - 1;
- Array.Copy(args, objs, lastPos);
- objs[lastPos] = Array.CreateInstance(paramArrayTypes[currentMin], 1);
- ((Array)objs[lastPos]).SetValue(args[lastPos], 0);
- args = objs;
- }
- }
- else if (parameters.Length > args.Length)
- {
- object?[] objs = new object[parameters.Length];
-
- for (i = 0; i < args.Length; i++)
- objs[i] = args[i];
-
- for (; i < parameters.Length - 1; i++)
- objs[i] = parameters[i].DefaultValue;
-
- if (paramArrayTypes[currentMin] != null)
- {
- objs[i] = Array.CreateInstance(paramArrayTypes[currentMin], 0);
- }
- else
- {
- objs[i] = parameters[i].DefaultValue;
- }
-
- args = objs;
- }
- else
- {
- if ((candidates[currentMin]!.CallingConvention & CallingConventions.VarArgs) == 0)
- {
- object[] objs = new object[parameters.Length];
- int paramArrayPos = parameters.Length - 1;
- Array.Copy(args, objs, paramArrayPos);
- objs[paramArrayPos] = Array.CreateInstance(paramArrayTypes[currentMin], args.Length - paramArrayPos);
- Array.Copy(args, paramArrayPos, (System.Array)objs[paramArrayPos], 0, args.Length - paramArrayPos);
- args = objs;
- }
- }
-
- return candidates[currentMin]!;
- }
-
- // Given a set of fields that match the base criteria, select a field.
- // if value is null then we have no way to select a field
- public sealed override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo[] match, object value, CultureInfo? cultureInfo)
- {
- if (match == null)
- {
- throw new ArgumentNullException(nameof(match));
- }
-
- int i;
- // Find the method that match...
- int CurIdx = 0;
-
- Type valueType;
-
- FieldInfo[] candidates = (FieldInfo[])match.Clone();
-
- // If we are a FieldSet, then use the value's type to disambiguate
- if ((bindingAttr & BindingFlags.SetField) != 0)
- {
- valueType = value.GetType();
-
- for (i = 0; i < candidates.Length; i++)
- {
- Type pCls = candidates[i].FieldType;
- if (pCls == valueType)
- {
- candidates[CurIdx++] = candidates[i];
- continue;
- }
- if (value == Empty.Value)
- {
- // the object passed in was null which would match any non primitive non value type
- if (pCls.IsClass)
- {
- candidates[CurIdx++] = candidates[i];
- continue;
- }
- }
- if (pCls == typeof(object))
- {
- candidates[CurIdx++] = candidates[i];
- continue;
- }
- if (pCls.IsPrimitive)
- {
- if (CanChangePrimitive(valueType, pCls))
- {
- candidates[CurIdx++] = candidates[i];
- continue;
- }
- }
- else
- {
- if (pCls.IsAssignableFrom(valueType))
- {
- candidates[CurIdx++] = candidates[i];
- continue;
- }
- }
- }
- if (CurIdx == 0)
- throw new MissingFieldException(SR.MissingField);
- if (CurIdx == 1)
- return candidates[0];
- }
-
- // Walk all of the methods looking the most specific method to invoke
- int currentMin = 0;
- bool ambig = false;
- for (i = 1; i < CurIdx; i++)
- {
- int newMin = FindMostSpecificField(candidates[currentMin], candidates[i]);
- if (newMin == 0)
- ambig = true;
- else
- {
- if (newMin == 2)
- {
- currentMin = i;
- ambig = false;
- }
- }
- }
- if (ambig)
- throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
- return candidates[currentMin];
- }
-
- // Given a set of methods that match the base criteria, select a method based
- // upon an array of types. This method should return null if no method matchs
- // the criteria.
- public sealed override MethodBase? SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[]? modifiers)
- {
- int i;
- int j;
-
- Type[] realTypes = new Type[types.Length];
- for (i = 0; i < types.Length; i++)
- {
- realTypes[i] = types[i].UnderlyingSystemType;
- if (!(realTypes[i].IsRuntimeImplemented() || realTypes[i] is SignatureType))
- throw new ArgumentException(SR.Arg_MustBeType, nameof(types));
- }
- types = realTypes;
-
- // We don't automatically jump out on exact match.
- if (match == null || match.Length == 0)
- throw new ArgumentException(SR.Arg_EmptyArray, nameof(match));
-
- MethodBase[] candidates = (MethodBase[])match.Clone();
-
- // Find all the methods that can be described by the types parameter.
- // Remove all of them that cannot.
- int CurIdx = 0;
- for (i = 0; i < candidates.Length; i++)
- {
- ParameterInfo[] par = candidates[i].GetParametersNoCopy();
- if (par.Length != types.Length)
- continue;
- for (j = 0; j < types.Length; j++)
- {
- Type pCls = par[j].ParameterType;
- if (types[j].MatchesParameterTypeExactly(par[j]))
- continue;
- if (pCls == typeof(object))
- continue;
-
- Type? type = types[j];
- if (type is SignatureType signatureType)
- {
- if (!(candidates[i] is MethodInfo methodInfo))
- break;
- type = signatureType.TryResolveAgainstGenericMethod(methodInfo);
- if (type == null)
- break;
- }
-
- if (pCls.IsPrimitive)
- {
- if (!type.UnderlyingSystemType.IsRuntimeImplemented() ||
- !CanChangePrimitive(type.UnderlyingSystemType, pCls.UnderlyingSystemType))
- break;
- }
- else
- {
- if (!pCls.IsAssignableFrom(type))
- break;
- }
- }
- if (j == types.Length)
- candidates[CurIdx++] = candidates[i];
- }
- if (CurIdx == 0)
- return null;
- if (CurIdx == 1)
- return candidates[0];
-
- // Walk all of the methods looking the most specific method to invoke
- int currentMin = 0;
- bool ambig = false;
- int[] paramOrder = new int[types.Length];
- for (i = 0; i < types.Length; i++)
- paramOrder[i] = i;
- for (i = 1; i < CurIdx; i++)
- {
- int newMin = FindMostSpecificMethod(candidates[currentMin], paramOrder, null, candidates[i], paramOrder, null, types, null);
- if (newMin == 0)
- ambig = true;
- else
- {
- if (newMin == 2)
- {
- currentMin = i;
- ambig = false;
- currentMin = i;
- }
- }
- }
- if (ambig)
- throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
- return candidates[currentMin];
- }
-
- // Given a set of properties that match the base criteria, select one.
- public sealed override PropertyInfo? SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type? returnType,
- Type[]? indexes, ParameterModifier[]? modifiers)
- {
- // Allow a null indexes array. But if it is not null, every element must be non-null as well.
- if (indexes != null)
- {
- foreach (Type index in indexes)
- {
- if (index == null)
- throw new ArgumentNullException(nameof(indexes));
- }
- }
-
- if (match == null || match.Length == 0)
- throw new ArgumentException(SR.Arg_EmptyArray, nameof(match));
-
- PropertyInfo[] candidates = (PropertyInfo[])match.Clone();
-
- int i, j = 0;
-
- // Find all the properties that can be described by type indexes parameter
- int CurIdx = 0;
- int indexesLength = (indexes != null) ? indexes.Length : 0;
- for (i = 0; i < candidates.Length; i++)
- {
- if (indexes != null)
- {
- ParameterInfo[] par = candidates[i].GetIndexParameters();
- if (par.Length != indexesLength)
- continue;
-
- for (j = 0; j < indexesLength; j++)
- {
- Type pCls = par[j].ParameterType;
-
- // If the classes exactly match continue
- if (pCls == indexes[j])
- continue;
- if (pCls == typeof(object))
- continue;
-
- if (pCls.IsPrimitive)
- {
- if (!indexes[j].UnderlyingSystemType.IsRuntimeImplemented() ||
- !CanChangePrimitive(indexes[j].UnderlyingSystemType, pCls.UnderlyingSystemType))
- break;
- }
- else
- {
- if (!pCls.IsAssignableFrom(indexes[j]))
- break;
- }
- }
- }
-
- if (j == indexesLength)
- {
- if (returnType != null)
- {
- if (candidates[i].PropertyType.IsPrimitive)
- {
- if (!returnType.UnderlyingSystemType.IsRuntimeImplemented() ||
- !CanChangePrimitive(returnType.UnderlyingSystemType, candidates[i].PropertyType.UnderlyingSystemType))
- continue;
- }
- else
- {
- if (!candidates[i].PropertyType.IsAssignableFrom(returnType))
- continue;
- }
- }
- candidates[CurIdx++] = candidates[i];
- }
- }
- if (CurIdx == 0)
- return null;
- if (CurIdx == 1)
- return candidates[0];
-
- // Walk all of the properties looking the most specific method to invoke
- int currentMin = 0;
- bool ambig = false;
- int[] paramOrder = new int[indexesLength];
- for (i = 0; i < indexesLength; i++)
- paramOrder[i] = i;
- for (i = 1; i < CurIdx; i++)
- {
- int newMin = FindMostSpecificType(candidates[currentMin].PropertyType, candidates[i].PropertyType, returnType);
- if (newMin == 0 && indexes != null)
- newMin = FindMostSpecific(candidates[currentMin].GetIndexParameters(),
- paramOrder,
- null,
- candidates[i].GetIndexParameters(),
- paramOrder,
- null,
- indexes,
- null);
- if (newMin == 0)
- {
- newMin = FindMostSpecificProperty(candidates[currentMin], candidates[i]);
- if (newMin == 0)
- ambig = true;
- }
- if (newMin == 2)
- {
- ambig = false;
- currentMin = i;
- }
- }
-
- if (ambig)
- throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
- return candidates[currentMin];
- }
-
- // ChangeType
- // The default binder doesn't support any change type functionality.
- // This is because the default is built into the low level invoke code.
- public override object ChangeType(object value, Type type, CultureInfo? cultureInfo)
- {
- throw new NotSupportedException(SR.NotSupported_ChangeType);
- }
-
- public sealed override void ReorderArgumentArray(ref object?[] args, object state)
- {
- BinderState binderState = (BinderState)state;
- ReorderParams(binderState._argsMap, args);
- if (binderState._isParamArray)
- {
- int paramArrayPos = args.Length - 1;
- if (args.Length == binderState._originalSize)
- {
- args[paramArrayPos] = ((object[])args[paramArrayPos]!)[0];
- }
- else
- {
- // must be args.Length < state.originalSize
- object[] newArgs = new object[args.Length];
- Array.Copy(args, newArgs, paramArrayPos);
- for (int i = paramArrayPos, j = 0; i < newArgs.Length; i++, j++)
- {
- newArgs[i] = ((object[])args[paramArrayPos]!)[j];
- }
- args = newArgs;
- }
- }
- else
- {
- if (args.Length > binderState._originalSize)
- {
- object[] newArgs = new object[binderState._originalSize];
- Array.Copy(args, newArgs, binderState._originalSize);
- args = newArgs;
- }
- }
- }
-
- // Return any exact bindings that may exist. (This method is not defined on the
- // Binder and is used by RuntimeType.)
- public static MethodBase? ExactBinding(MethodBase[] match, Type[] types, ParameterModifier[]? modifiers)
- {
- if (match == null)
- throw new ArgumentNullException(nameof(match));
-
- MethodBase[] aExactMatches = new MethodBase[match.Length];
- int cExactMatches = 0;
-
- for (int i = 0; i < match.Length; i++)
- {
- ParameterInfo[] par = match[i].GetParametersNoCopy();
- if (par.Length == 0)
- {
- continue;
- }
- int j;
- for (j = 0; j < types.Length; j++)
- {
- Type pCls = par[j].ParameterType;
-
- // If the classes exactly match continue
- if (!pCls.Equals(types[j]))
- break;
- }
- if (j < types.Length)
- continue;
-
- // Add the exact match to the array of exact matches.
- aExactMatches[cExactMatches] = match[i];
- cExactMatches++;
- }
-
- if (cExactMatches == 0)
- return null;
-
- if (cExactMatches == 1)
- return aExactMatches[0];
-
- return FindMostDerivedNewSlotMeth(aExactMatches, cExactMatches);
- }
-
- // Return any exact bindings that may exist. (This method is not defined on the
- // Binder and is used by RuntimeType.)
- public static PropertyInfo? ExactPropertyBinding(PropertyInfo[] match, Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
- {
- if (match == null)
- throw new ArgumentNullException(nameof(match));
-
- PropertyInfo? bestMatch = null;
- int typesLength = (types != null) ? types.Length : 0;
- for (int i = 0; i < match.Length; i++)
- {
- ParameterInfo[] par = match[i].GetIndexParameters();
- int j;
- for (j = 0; j < typesLength; j++)
- {
- Type pCls = par[j].ParameterType;
-
- // If the classes exactly match continue
- if (pCls != types![j])
- break;
- }
- if (j < typesLength)
- continue;
- if (returnType != null && returnType != match[i].PropertyType)
- continue;
-
- if (bestMatch != null)
- throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
-
- bestMatch = match[i];
- }
- return bestMatch;
- }
-
- private static int FindMostSpecific(ParameterInfo[] p1, int[] paramOrder1, Type? paramArrayType1,
- ParameterInfo[] p2, int[] paramOrder2, Type? paramArrayType2,
- Type[] types, object?[]? args)
- {
- // A method using params is always less specific than one not using params
- if (paramArrayType1 != null && paramArrayType2 == null) return 2;
- if (paramArrayType2 != null && paramArrayType1 == null) return 1;
-
- // now either p1 and p2 both use params or neither does.
-
- bool p1Less = false;
- bool p2Less = false;
-
- for (int i = 0; i < types.Length; i++)
- {
- if (args != null && args[i] == Type.Missing)
- continue;
-
- Type c1, c2;
-
- // If a param array is present, then either
- // the user re-ordered the parameters in which case
- // the argument to the param array is either an array
- // in which case the params is conceptually ignored and so paramArrayType1 == null
- // or the argument to the param array is a single element
- // in which case paramOrder[i] == p1.Length - 1 for that element
- // or the user did not re-order the parameters in which case
- // the paramOrder array could contain indexes larger than p.Length - 1 (see VSW 577286)
- // so any index >= p.Length - 1 is being put in the param array
-
- if (paramArrayType1 != null && paramOrder1[i] >= p1.Length - 1)
- c1 = paramArrayType1;
- else
- c1 = p1[paramOrder1[i]].ParameterType;
-
- if (paramArrayType2 != null && paramOrder2[i] >= p2.Length - 1)
- c2 = paramArrayType2;
- else
- c2 = p2[paramOrder2[i]].ParameterType;
-
- if (c1 == c2) continue;
-
- switch (FindMostSpecificType(c1, c2, types[i]))
- {
- case 0: return 0;
- case 1: p1Less = true; break;
- case 2: p2Less = true; break;
- }
- }
-
- // Two way p1Less and p2Less can be equal. All the arguments are the
- // same they both equal false, otherwise there were things that both
- // were the most specific type on....
- if (p1Less == p2Less)
- {
- // if we cannot tell which is a better match based on parameter types (p1Less == p2Less),
- // let's see which one has the most matches without using the params array (the longer one wins).
- if (!p1Less && args != null)
- {
- if (p1.Length > p2.Length)
- {
- return 1;
- }
- else if (p2.Length > p1.Length)
- {
- return 2;
- }
- }
-
- return 0;
- }
- else
- {
- return p1Less ? 1 : 2;
- }
- }
-
- private static int FindMostSpecificType(Type c1, Type c2, Type? t)
- {
- // If the two types are exact move on...
- if (c1 == c2)
- return 0;
-
- if (t is SignatureType signatureType)
- {
- if (signatureType.MatchesExactly(c1))
- return 1;
-
- if (signatureType.MatchesExactly(c2))
- return 2;
- }
- else
- {
- if (c1 == t)
- return 1;
-
- if (c2 == t)
- return 2;
- }
-
- bool c1FromC2;
- bool c2FromC1;
-
- if (c1.IsByRef || c2.IsByRef)
- {
- if (c1.IsByRef && c2.IsByRef)
- {
- c1 = c1.GetElementType()!;
- c2 = c2.GetElementType()!;
- }
- else if (c1.IsByRef)
- {
- if (c1.GetElementType() == c2)
- return 2;
-
- c1 = c1.GetElementType()!;
- }
- else // if (c2.IsByRef)
- {
- if (c2.GetElementType() == c1)
- return 1;
-
- c2 = c2.GetElementType()!;
- }
- }
-
- if (c1.IsPrimitive && c2.IsPrimitive)
- {
- c1FromC2 = CanChangePrimitive(c2, c1);
- c2FromC1 = CanChangePrimitive(c1, c2);
- }
- else
- {
- c1FromC2 = c1.IsAssignableFrom(c2);
- c2FromC1 = c2.IsAssignableFrom(c1);
- }
-
- if (c1FromC2 == c2FromC1)
- return 0;
-
- if (c1FromC2)
- {
- return 2;
- }
- else
- {
- return 1;
- }
- }
-
- private static int FindMostSpecificMethod(MethodBase m1, int[] paramOrder1, Type? paramArrayType1,
- MethodBase m2, int[] paramOrder2, Type? paramArrayType2,
- Type[] types, object?[]? args)
- {
- // Find the most specific method based on the parameters.
- int res = FindMostSpecific(m1.GetParametersNoCopy(), paramOrder1, paramArrayType1,
- m2.GetParametersNoCopy(), paramOrder2, paramArrayType2, types, args);
-
- // If the match was not ambigous then return the result.
- if (res != 0)
- return res;
-
- // Check to see if the methods have the exact same name and signature.
- if (CompareMethodSig(m1, m2))
- {
- // Determine the depth of the declaring types for both methods.
- int hierarchyDepth1 = GetHierarchyDepth(m1.DeclaringType!);
- int hierarchyDepth2 = GetHierarchyDepth(m2.DeclaringType!);
-
- // The most derived method is the most specific one.
- if (hierarchyDepth1 == hierarchyDepth2)
- {
- return 0;
- }
- else if (hierarchyDepth1 < hierarchyDepth2)
- {
- return 2;
- }
- else
- {
- return 1;
- }
- }
-
- // The match is ambigous.
- return 0;
- }
-
- private static int FindMostSpecificField(FieldInfo cur1, FieldInfo cur2)
- {
- // Check to see if the fields have the same name.
- if (cur1.Name == cur2.Name)
- {
- int hierarchyDepth1 = GetHierarchyDepth(cur1.DeclaringType!);
- int hierarchyDepth2 = GetHierarchyDepth(cur2.DeclaringType!);
-
- if (hierarchyDepth1 == hierarchyDepth2)
- {
- Debug.Assert(cur1.IsStatic != cur2.IsStatic, "hierarchyDepth1 == hierarchyDepth2");
- return 0;
- }
- else if (hierarchyDepth1 < hierarchyDepth2)
- return 2;
- else
- return 1;
- }
-
- // The match is ambigous.
- return 0;
- }
-
- private static int FindMostSpecificProperty(PropertyInfo cur1, PropertyInfo cur2)
- {
- // Check to see if the fields have the same name.
- if (cur1.Name == cur2.Name)
- {
- int hierarchyDepth1 = GetHierarchyDepth(cur1.DeclaringType!);
- int hierarchyDepth2 = GetHierarchyDepth(cur2.DeclaringType!);
-
- if (hierarchyDepth1 == hierarchyDepth2)
- {
- return 0;
- }
- else if (hierarchyDepth1 < hierarchyDepth2)
- return 2;
- else
- return 1;
- }
-
- // The match is ambigous.
- return 0;
- }
-
- public static bool CompareMethodSig(MethodBase m1, MethodBase m2)
- {
- ParameterInfo[] params1 = m1.GetParametersNoCopy();
- ParameterInfo[] params2 = m2.GetParametersNoCopy();
-
- if (params1.Length != params2.Length)
- return false;
-
- int numParams = params1.Length;
- for (int i = 0; i < numParams; i++)
- {
- if (params1[i].ParameterType != params2[i].ParameterType)
- return false;
- }
-
- return true;
- }
-
- private static int GetHierarchyDepth(Type t)
- {
- int depth = 0;
-
- Type? currentType = t;
- do
- {
- depth++;
- currentType = currentType.BaseType;
- } while (currentType != null);
-
- return depth;
- }
-
- internal static MethodBase? FindMostDerivedNewSlotMeth(MethodBase[] match, int cMatches)
- {
- int deepestHierarchy = 0;
- MethodBase? methWithDeepestHierarchy = null;
-
- for (int i = 0; i < cMatches; i++)
- {
- // Calculate the depth of the hierarchy of the declaring type of the
- // current method.
- int currentHierarchyDepth = GetHierarchyDepth(match[i].DeclaringType!);
-
- // The two methods have the same name, signature, and hierarchy depth.
- // This can only happen if at least one is vararg or generic.
- if (currentHierarchyDepth == deepestHierarchy)
- {
- throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
- }
-
- // Check to see if this method is on the most derived class.
- if (currentHierarchyDepth > deepestHierarchy)
- {
- deepestHierarchy = currentHierarchyDepth;
- methWithDeepestHierarchy = match[i];
- }
- }
-
- return methWithDeepestHierarchy;
- }
-
- // This method will sort the vars array into the mapping order stored
- // in the paramOrder array.
- private static void ReorderParams(int[] paramOrder, object?[] vars)
- {
- object?[] varsCopy = new object[vars.Length];
- for (int i = 0; i < vars.Length; i++)
- varsCopy[i] = vars[i];
-
- for (int i = 0; i < vars.Length; i++)
- vars[i] = varsCopy[paramOrder[i]];
- }
-
- // This method will create the mapping between the Parameters and the underlying
- // data based upon the names array. The names array is stored in the same order
- // as the values and maps to the parameters of the method. We store the mapping
- // from the parameters to the names in the paramOrder array. All parameters that
- // don't have matching names are then stored in the array in order.
- private static bool CreateParamOrder(int[] paramOrder, ParameterInfo[] pars, string[] names)
- {
- bool[] used = new bool[pars.Length];
-
- // Mark which parameters have not been found in the names list
- for (int i = 0; i < pars.Length; i++)
- paramOrder[i] = -1;
- // Find the parameters with names.
- for (int i = 0; i < names.Length; i++)
- {
- int j;
- for (j = 0; j < pars.Length; j++)
- {
- if (names[i].Equals(pars[j].Name))
- {
- paramOrder[j] = i;
- used[i] = true;
- break;
- }
- }
- // This is an error condition. The name was not found. This
- // method must not match what we sent.
- if (j == pars.Length)
- return false;
- }
-
- // Now we fill in the holes with the parameters that are unused.
- int pos = 0;
- for (int i = 0; i < pars.Length; i++)
- {
- if (paramOrder[i] == -1)
- {
- for (; pos < pars.Length; pos++)
- {
- if (!used[pos])
- {
- paramOrder[i] = pos;
- pos++;
- break;
- }
- }
- }
- }
- return true;
- }
-
- // CanChangePrimitive
- // This will determine if the source can be converted to the target type
- internal static bool CanChangePrimitive(Type? source, Type? target)
- {
- if ((source == typeof(IntPtr) && target == typeof(IntPtr)) ||
- (source == typeof(UIntPtr) && target == typeof(UIntPtr)))
- return true;
-
- Primitives widerCodes = s_primitiveConversions[(int)(Type.GetTypeCode(source))];
- Primitives targetCode = (Primitives)(1 << (int)(Type.GetTypeCode(target)));
-
- return (widerCodes & targetCode) != 0;
- }
-
- private static readonly Primitives[] s_primitiveConversions = {
- /* Empty */ 0, // not primitive
- /* Object */ 0, // not primitive
- /* DBNull */ 0, // not primitive
- /* Boolean */ Primitives.Boolean,
- /* Char */ Primitives.Char | Primitives.UInt16 | Primitives.UInt32 | Primitives.Int32 | Primitives.UInt64 | Primitives.Int64 | Primitives.Single | Primitives.Double,
- /* SByte */ Primitives.SByte | Primitives.Int16 | Primitives.Int32 | Primitives.Int64 | Primitives.Single | Primitives.Double,
- /* Byte */ Primitives.Byte | Primitives.Char | Primitives.UInt16 | Primitives.Int16 | Primitives.UInt32 | Primitives.Int32 | Primitives.UInt64 | Primitives.Int64 | Primitives.Single | Primitives.Double,
- /* Int16 */ Primitives.Int16 | Primitives.Int32 | Primitives.Int64 | Primitives.Single | Primitives.Double,
- /* UInt16 */ Primitives.UInt16 | Primitives.UInt32 | Primitives.Int32 | Primitives.UInt64 | Primitives.Int64 | Primitives.Single | Primitives.Double,
- /* Int32 */ Primitives.Int32 | Primitives.Int64 | Primitives.Single | Primitives.Double,
- /* UInt32 */ Primitives.UInt32 | Primitives.UInt64 | Primitives.Int64 | Primitives.Single | Primitives.Double,
- /* Int64 */ Primitives.Int64 | Primitives.Single | Primitives.Double,
- /* UInt64 */ Primitives.UInt64 | Primitives.Single | Primitives.Double,
- /* Single */ Primitives.Single | Primitives.Double,
- /* Double */ Primitives.Double,
- /* Decimal */ Primitives.Decimal,
- /* DateTime */ Primitives.DateTime,
- /* [Unused] */ 0,
- /* String */ Primitives.String,
- };
-
- [Flags]
- private enum Primitives
- {
- Boolean = 1 << TypeCode.Boolean,
- Char = 1 << TypeCode.Char,
- SByte = 1 << TypeCode.SByte,
- Byte = 1 << TypeCode.Byte,
- Int16 = 1 << TypeCode.Int16,
- UInt16 = 1 << TypeCode.UInt16,
- Int32 = 1 << TypeCode.Int32,
- UInt32 = 1 << TypeCode.UInt32,
- Int64 = 1 << TypeCode.Int64,
- UInt64 = 1 << TypeCode.UInt64,
- Single = 1 << TypeCode.Single,
- Double = 1 << TypeCode.Double,
- Decimal = 1 << TypeCode.Decimal,
- DateTime = 1 << TypeCode.DateTime,
- String = 1 << TypeCode.String,
- }
-
- internal class BinderState
- {
- internal readonly int[] _argsMap;
- internal readonly int _originalSize;
- internal readonly bool _isParamArray;
-
- internal BinderState(int[] argsMap, int originalSize, bool isParamArray)
- {
- _argsMap = argsMap;
- _originalSize = originalSize;
- _isParamArray = isParamArray;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Delegate.cs b/netcore/System.Private.CoreLib/shared/System/Delegate.cs
deleted file mode 100644
index 63aa97b8d64..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Delegate.cs
+++ /dev/null
@@ -1,127 +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 System.Diagnostics.CodeAnalysis;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-
-namespace System
-{
- public abstract partial class Delegate : ICloneable, ISerializable
- {
- public virtual object Clone() => MemberwiseClone();
-
- [return: NotNullIfNotNull("a")]
- [return: NotNullIfNotNull("b")]
- public static Delegate? Combine(Delegate? a, Delegate? b)
- {
- if (a is null)
- return b;
-
- return a.CombineImpl(b);
- }
-
- public static Delegate? Combine(params Delegate?[]? delegates)
- {
- if (delegates == null || delegates.Length == 0)
- return null;
-
- Delegate? d = delegates[0];
- for (int i = 1; i < delegates.Length; i++)
- d = Combine(d, delegates[i]);
-
- return d;
- }
-
- // V2 api: Creates open or closed delegates to static or instance methods - relaxed signature checking allowed.
- public static Delegate CreateDelegate(Type type, object? firstArgument, MethodInfo method) => CreateDelegate(type, firstArgument, method, throwOnBindFailure: true)!;
-
- // V1 api: Creates open delegates to static or instance methods - relaxed signature checking allowed.
- public static Delegate CreateDelegate(Type type, MethodInfo method) => CreateDelegate(type, method, throwOnBindFailure: true)!;
-
- // V1 api: Creates closed delegates to instance methods only, relaxed signature checking disallowed.
- public static Delegate CreateDelegate(Type type, object target, string method) => CreateDelegate(type, target, method, ignoreCase: false, throwOnBindFailure: true)!;
- public static Delegate CreateDelegate(Type type, object target, string method, bool ignoreCase) => CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure: true)!;
-
- // V1 api: Creates open delegates to static methods only, relaxed signature checking disallowed.
- public static Delegate CreateDelegate(Type type, Type target, string method) => CreateDelegate(type, target, method, ignoreCase: false, throwOnBindFailure: true)!;
- public static Delegate CreateDelegate(Type type, Type target, string method, bool ignoreCase) => CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure: true)!;
-
-#if !CORERT
- protected virtual Delegate CombineImpl(Delegate? d) => throw new MulticastNotSupportedException(SR.Multicast_Combine);
-
- protected virtual Delegate? RemoveImpl(Delegate d) => d.Equals(this) ? null : this;
-
- public virtual Delegate[] GetInvocationList() => new Delegate[] { this };
-
- public object? DynamicInvoke(params object?[]? args)
- {
- return DynamicInvokeImpl(args);
- }
-#endif
-
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context) => throw new PlatformNotSupportedException();
-
- public MethodInfo Method => GetMethodImpl();
-
- public static Delegate? Remove(Delegate? source, Delegate? value)
- {
- if (source == null)
- return null;
-
- if (value == null)
- return source;
-
- if (!InternalEqualTypes(source, value))
- throw new ArgumentException(SR.Arg_DlgtTypeMis);
-
- return source.RemoveImpl(value);
- }
-
- public static Delegate? RemoveAll(Delegate? source, Delegate? value)
- {
- Delegate? newDelegate;
-
- do
- {
- newDelegate = source;
- source = Remove(source, value);
- }
- while (newDelegate != source);
-
- return newDelegate;
- }
-
- // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Delegate? d1, Delegate? d2)
- {
- // Test d2 first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (d2 is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (d1 is null) ? true : false;
- }
-
- return ReferenceEquals(d2, d1) ? true : d2.Equals((object?)d1);
- }
-
- // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(Delegate? d1, Delegate? d2)
- {
- // Test d2 first to allow branch elimination when inlined for not null checks (!= null)
- // so it can become a simple test
- if (d2 is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (d1 is null) ? false : true;
- }
-
- return ReferenceEquals(d2, d1) ? false : !d2.Equals(d1);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/NullableAttributes.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
deleted file mode 100644
index 3770a5ff0ba..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
+++ /dev/null
@@ -1,128 +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.
-
-namespace System.Diagnostics.CodeAnalysis
-{
- /// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary>
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
-#if INTERNAL_NULLABLE_ATTRIBUTES
- internal
-#else
- public
-#endif
- sealed class AllowNullAttribute : Attribute { }
-
- /// <summary>Specifies that null is disallowed as an input even if the corresponding type allows it.</summary>
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
-#if INTERNAL_NULLABLE_ATTRIBUTES
- internal
-#else
- public
-#endif
- sealed class DisallowNullAttribute : Attribute { }
-
- /// <summary>Specifies that an output may be null even if the corresponding type disallows it.</summary>
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
-#if INTERNAL_NULLABLE_ATTRIBUTES
- internal
-#else
- public
-#endif
- sealed class MaybeNullAttribute : Attribute { }
-
- /// <summary>Specifies that an output will not be null even if the corresponding type allows it.</summary>
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
-#if INTERNAL_NULLABLE_ATTRIBUTES
- internal
-#else
- public
-#endif
- sealed class NotNullAttribute : Attribute { }
-
- /// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter may be null even if the corresponding type disallows it.</summary>
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
-#if INTERNAL_NULLABLE_ATTRIBUTES
- internal
-#else
- public
-#endif
- sealed class MaybeNullWhenAttribute : Attribute
- {
- /// <summary>Initializes the attribute with the specified return value condition.</summary>
- /// <param name="returnValue">
- /// The return value condition. If the method returns this value, the associated parameter may be null.
- /// </param>
- public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
-
- /// <summary>Gets the return value condition.</summary>
- public bool ReturnValue { get; }
- }
-
- /// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter will not be null even if the corresponding type allows it.</summary>
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
-#if INTERNAL_NULLABLE_ATTRIBUTES
- internal
-#else
- public
-#endif
- sealed class NotNullWhenAttribute : Attribute
- {
- /// <summary>Initializes the attribute with the specified return value condition.</summary>
- /// <param name="returnValue">
- /// The return value condition. If the method returns this value, the associated parameter will not be null.
- /// </param>
- public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
-
- /// <summary>Gets the return value condition.</summary>
- public bool ReturnValue { get; }
- }
-
- /// <summary>Specifies that the output will be non-null if the named parameter is non-null.</summary>
- [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
-#if INTERNAL_NULLABLE_ATTRIBUTES
- internal
-#else
- public
-#endif
- sealed class NotNullIfNotNullAttribute : Attribute
- {
- /// <summary>Initializes the attribute with the associated parameter name.</summary>
- /// <param name="parameterName">
- /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null.
- /// </param>
- public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName;
-
- /// <summary>Gets the associated parameter name.</summary>
- public string ParameterName { get; }
- }
-
- /// <summary>Applied to a method that will never return under any circumstance.</summary>
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
-#if INTERNAL_NULLABLE_ATTRIBUTES
- internal
-#else
- public
-#endif
- sealed class DoesNotReturnAttribute : Attribute { }
-
- /// <summary>Specifies that the method will not return if the associated Boolean parameter is passed the specified value.</summary>
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
-#if INTERNAL_NULLABLE_ATTRIBUTES
- internal
-#else
- public
-#endif
- sealed class DoesNotReturnIfAttribute : Attribute
- {
- /// <summary>Initializes the attribute with the specified parameter value.</summary>
- /// <param name="parameterValue">
- /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to
- /// the associated parameter matches this value.
- /// </param>
- public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue;
-
- /// <summary>Gets the condition parameter value.</summary>
- public bool ParameterValue { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/SuppressMessageAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/SuppressMessageAttribute.cs
deleted file mode 100644
index 8b03897752e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/SuppressMessageAttribute.cs
+++ /dev/null
@@ -1,39 +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.
-
-/*============================================================
-**
-**
-**
-** An attribute to suppress violation messages/warnings
-** by static code analysis tools.
-**
-**
-===========================================================*/
-
-namespace System.Diagnostics.CodeAnalysis
-{
- [AttributeUsage(
- AttributeTargets.All,
- Inherited = false,
- AllowMultiple = true
- )
- ]
- [Conditional("CODE_ANALYSIS")]
- public sealed class SuppressMessageAttribute : Attribute
- {
- public SuppressMessageAttribute(string category, string checkId)
- {
- Category = category;
- CheckId = checkId;
- }
-
- public string Category { get; }
- public string CheckId { get; }
- public string? Scope { get; set; }
- public string? Target { get; set; }
- public string? MessageId { get; set; }
- public string? Justification { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/ConditionalAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/ConditionalAttribute.cs
deleted file mode 100644
index 416625b779d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/ConditionalAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Diagnostics
-{
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
- public sealed class ConditionalAttribute : Attribute
- {
- public ConditionalAttribute(string conditionString)
- {
- ConditionString = conditionString;
- }
-
- public string ConditionString { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractException.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractException.cs
deleted file mode 100644
index 96d6eccd9c3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractException.cs
+++ /dev/null
@@ -1,55 +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 System.Runtime.Serialization;
-
-namespace System.Diagnostics.Contracts
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- // Needs to be public to support binary serialization compatibility
- public sealed class ContractException : Exception
- {
- private readonly ContractFailureKind _kind;
- private readonly string? _userMessage;
- private readonly string? _condition;
-
- public ContractFailureKind Kind => _kind;
- public string Failure => this.Message;
- public string? UserMessage => _userMessage;
- public string? Condition => _condition;
-
- // Called by COM Interop, if we see COR_E_CODECONTRACTFAILED as an HRESULT.
- private ContractException()
- {
- HResult = HResults.COR_E_CODECONTRACTFAILED;
- }
-
- public ContractException(ContractFailureKind kind, string? failure, string? userMessage, string? condition, Exception? innerException)
- : base(failure, innerException)
- {
- HResult = HResults.COR_E_CODECONTRACTFAILED;
- _kind = kind;
- _userMessage = userMessage;
- _condition = condition;
- }
-
- private ContractException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- _kind = (ContractFailureKind)info.GetInt32("Kind");
- _userMessage = info.GetString("UserMessage");
- _condition = info.GetString("Condition");
- }
-
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("Kind", _kind);
- info.AddValue("UserMessage", _userMessage);
- info.AddValue("Condition", _condition);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractFailedEventArgs.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractFailedEventArgs.cs
deleted file mode 100644
index 61b7c3c19c3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/ContractFailedEventArgs.cs
+++ /dev/null
@@ -1,47 +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.
-
-namespace System.Diagnostics.Contracts
-{
- public sealed class ContractFailedEventArgs : EventArgs
- {
- private readonly ContractFailureKind _failureKind;
- private readonly string? _message;
- private readonly string? _condition;
- private readonly Exception? _originalException;
- private bool _handled;
- private bool _unwind;
-
- internal Exception? thrownDuringHandler;
-
- public ContractFailedEventArgs(ContractFailureKind failureKind, string? message, string? condition, Exception? originalException)
- {
- Debug.Assert(originalException == null || failureKind == ContractFailureKind.PostconditionOnException);
- _failureKind = failureKind;
- _message = message;
- _condition = condition;
- _originalException = originalException;
- }
-
- public string? Message => _message;
- public string? Condition => _condition;
- public ContractFailureKind FailureKind => _failureKind;
- public Exception? OriginalException => _originalException;
-
- // Whether the event handler "handles" this contract failure, or to fail via escalation policy.
- public bool Handled => _handled;
-
- public void SetHandled()
- {
- _handled = true;
- }
-
- public bool Unwind => _unwind;
-
- public void SetUnwind()
- {
- _unwind = true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs
deleted file mode 100644
index 507c63499e0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs
+++ /dev/null
@@ -1,702 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: The contract class allows for expressing preconditions,
-** postconditions, and object invariants about methods in source
-** code for runtime checking & static analysis.
-**
-** Two classes (Contract and ContractHelper) are split into partial classes
-** in order to share the public front for multiple platforms (this file)
-** while providing separate implementation details for each platform.
-**
-===========================================================*/
-#define DEBUG // The behavior of this contract library should be consistent regardless of build type.
-
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-namespace System.Diagnostics.Contracts
-{
- #region Attributes
-
- /// <summary>
- /// Methods and classes marked with this attribute can be used within calls to Contract methods. Such methods not make any visible state changes.
- /// </summary>
- [Conditional("CONTRACTS_FULL")]
- [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Delegate | AttributeTargets.Class | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
- public sealed class PureAttribute : Attribute
- {
- }
-
- /// <summary>
- /// Types marked with this attribute specify that a separate type contains the contracts for this type.
- /// </summary>
- [Conditional("CONTRACTS_FULL")]
- [Conditional("DEBUG")]
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
- public sealed class ContractClassAttribute : Attribute
- {
- private readonly Type _typeWithContracts;
-
- public ContractClassAttribute(Type typeContainingContracts)
- {
- _typeWithContracts = typeContainingContracts;
- }
-
- public Type TypeContainingContracts => _typeWithContracts;
- }
-
- /// <summary>
- /// Types marked with this attribute specify that they are a contract for the type that is the argument of the constructor.
- /// </summary>
- [Conditional("CONTRACTS_FULL")]
- [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
- public sealed class ContractClassForAttribute : Attribute
- {
- private readonly Type _typeIAmAContractFor;
-
- public ContractClassForAttribute(Type typeContractsAreFor)
- {
- _typeIAmAContractFor = typeContractsAreFor;
- }
-
- public Type TypeContractsAreFor => _typeIAmAContractFor;
- }
-
- /// <summary>
- /// This attribute is used to mark a method as being the invariant
- /// method for a class. The method can have any name, but it must
- /// return "void" and take no parameters. The body of the method
- /// must consist solely of one or more calls to the method
- /// Contract.Invariant. A suggested name for the method is
- /// "ObjectInvariant".
- /// </summary>
- [Conditional("CONTRACTS_FULL")]
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
- public sealed class ContractInvariantMethodAttribute : Attribute
- {
- }
-
- /// <summary>
- /// Attribute that specifies that an assembly is a reference assembly with contracts.
- /// </summary>
- [AttributeUsage(AttributeTargets.Assembly)]
- public sealed class ContractReferenceAssemblyAttribute : Attribute
- {
- }
-
- /// <summary>
- /// Methods (and properties) marked with this attribute can be used within calls to Contract methods, but have no runtime behavior associated with them.
- /// </summary>
- [Conditional("CONTRACTS_FULL")]
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
- public sealed class ContractRuntimeIgnoredAttribute : Attribute
- {
- }
-
- /// <summary>
- /// Instructs downstream tools whether to assume the correctness of this assembly, type or member without performing any verification or not.
- /// Can use [ContractVerification(false)] to explicitly mark assembly, type or member as one to *not* have verification performed on it.
- /// Most specific element found (member, type, then assembly) takes precedence.
- /// (That is useful if downstream tools allow a user to decide which polarity is the default, unmarked case.)
- /// </summary>
- /// <remarks>
- /// Apply this attribute to a type to apply to all members of the type, including nested types.
- /// Apply this attribute to an assembly to apply to all types and members of the assembly.
- /// Apply this attribute to a property to apply to both the getter and setter.
- /// </remarks>
- [Conditional("CONTRACTS_FULL")]
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property)]
- public sealed class ContractVerificationAttribute : Attribute
- {
- private readonly bool _value;
-
- public ContractVerificationAttribute(bool value) { _value = value; }
-
- public bool Value => _value;
- }
-
- /// <summary>
- /// Allows a field f to be used in the method contracts for a method m when f has less visibility than m.
- /// For instance, if the method is public, but the field is private.
- /// </summary>
- [Conditional("CONTRACTS_FULL")]
- [AttributeUsage(AttributeTargets.Field)]
- public sealed class ContractPublicPropertyNameAttribute : Attribute
- {
- private readonly string _publicName;
-
- public ContractPublicPropertyNameAttribute(string name)
- {
- _publicName = name;
- }
-
- public string Name => _publicName;
- }
-
- /// <summary>
- /// Enables factoring legacy if-then-throw into separate methods for reuse and full control over
- /// thrown exception and arguments
- /// </summary>
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
- [Conditional("CONTRACTS_FULL")]
- public sealed class ContractArgumentValidatorAttribute : Attribute
- {
- }
-
- /// <summary>
- /// Enables writing abbreviations for contracts that get copied to other methods
- /// </summary>
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
- [Conditional("CONTRACTS_FULL")]
- public sealed class ContractAbbreviatorAttribute : Attribute
- {
- }
-
- /// <summary>
- /// Allows setting contract and tool options at assembly, type, or method granularity.
- /// </summary>
- [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
- [Conditional("CONTRACTS_FULL")]
- public sealed class ContractOptionAttribute : Attribute
- {
- private readonly string _category;
- private readonly string _setting;
- private readonly bool _enabled;
- private readonly string? _value;
-
- public ContractOptionAttribute(string category, string setting, bool enabled)
- {
- _category = category;
- _setting = setting;
- _enabled = enabled;
- }
-
- public ContractOptionAttribute(string category, string setting, string value)
- {
- _category = category;
- _setting = setting;
- _value = value;
- }
-
- public string Category => _category;
-
- public string Setting => _setting;
-
- public bool Enabled => _enabled;
-
- public string? Value => _value;
- }
-
- #endregion Attributes
-
- /// <summary>
- /// Contains static methods for representing program contracts such as preconditions, postconditions, and invariants.
- /// </summary>
- /// <remarks>
- /// WARNING: A binary rewriter must be used to insert runtime enforcement of these contracts.
- /// Otherwise some contracts like Ensures can only be checked statically and will not throw exceptions during runtime when contracts are violated.
- /// Please note this class uses conditional compilation to help avoid easy mistakes. Defining the preprocessor
- /// symbol CONTRACTS_PRECONDITIONS will include all preconditions expressed using Contract.Requires in your
- /// build. The symbol CONTRACTS_FULL will include postconditions and object invariants, and requires the binary rewriter.
- /// </remarks>
- public static partial class Contract
- {
- #region User Methods
-
- #region Assume
-
- /// <summary>
- /// Instructs code analysis tools to assume the expression <paramref name="condition"/> is true even if it can not be statically proven to always be true.
- /// </summary>
- /// <param name="condition">Expression to assume will always be true.</param>
- /// <remarks>
- /// At runtime this is equivalent to an <seealso cref="System.Diagnostics.Contracts.Contract.Assert(bool)"/>.
- /// </remarks>
- [Pure]
- [Conditional("DEBUG")]
- [Conditional("CONTRACTS_FULL")]
- public static void Assume([DoesNotReturnIf(false)] bool condition)
- {
- if (!condition)
- {
- ReportFailure(ContractFailureKind.Assume, null, null, null);
- }
- }
-
- /// <summary>
- /// Instructs code analysis tools to assume the expression <paramref name="condition"/> is true even if it can not be statically proven to always be true.
- /// </summary>
- /// <param name="condition">Expression to assume will always be true.</param>
- /// <param name="userMessage">If it is not a constant string literal, then the contract may not be understood by tools.</param>
- /// <remarks>
- /// At runtime this is equivalent to an <seealso cref="System.Diagnostics.Contracts.Contract.Assert(bool)"/>.
- /// </remarks>
- [Pure]
- [Conditional("DEBUG")]
- [Conditional("CONTRACTS_FULL")]
- public static void Assume([DoesNotReturnIf(false)] bool condition, string? userMessage)
- {
- if (!condition)
- {
- ReportFailure(ContractFailureKind.Assume, userMessage, null, null);
- }
- }
-
- #endregion Assume
-
- #region Assert
-
- /// <summary>
- /// In debug builds, perform a runtime check that <paramref name="condition"/> is true.
- /// </summary>
- /// <param name="condition">Expression to check to always be true.</param>
- [Pure]
- [Conditional("DEBUG")]
- [Conditional("CONTRACTS_FULL")]
- public static void Assert([DoesNotReturnIf(false)] bool condition)
- {
- if (!condition)
- ReportFailure(ContractFailureKind.Assert, null, null, null);
- }
-
- /// <summary>
- /// In debug builds, perform a runtime check that <paramref name="condition"/> is true.
- /// </summary>
- /// <param name="condition">Expression to check to always be true.</param>
- /// <param name="userMessage">If it is not a constant string literal, then the contract may not be understood by tools.</param>
- [Pure]
- [Conditional("DEBUG")]
- [Conditional("CONTRACTS_FULL")]
- public static void Assert([DoesNotReturnIf(false)] bool condition, string? userMessage)
- {
- if (!condition)
- ReportFailure(ContractFailureKind.Assert, userMessage, null, null);
- }
-
- #endregion Assert
-
- #region Requires
-
- /// <summary>
- /// Specifies a contract such that the expression <paramref name="condition"/> must be true before the enclosing method or property is invoked.
- /// </summary>
- /// <param name="condition">Boolean expression representing the contract.</param>
- /// <remarks>
- /// This call must happen at the beginning of a method or property before any other code.
- /// This contract is exposed to clients so must only reference members at least as visible as the enclosing method.
- /// Use this form when backward compatibility does not force you to throw a particular exception.
- /// </remarks>
- [Pure]
- [Conditional("CONTRACTS_FULL")]
- public static void Requires(bool condition)
- {
- AssertMustUseRewriter(ContractFailureKind.Precondition, "Requires");
- }
-
- /// <summary>
- /// Specifies a contract such that the expression <paramref name="condition"/> must be true before the enclosing method or property is invoked.
- /// </summary>
- /// <param name="condition">Boolean expression representing the contract.</param>
- /// <param name="userMessage">If it is not a constant string literal, then the contract may not be understood by tools.</param>
- /// <remarks>
- /// This call must happen at the beginning of a method or property before any other code.
- /// This contract is exposed to clients so must only reference members at least as visible as the enclosing method.
- /// Use this form when backward compatibility does not force you to throw a particular exception.
- /// </remarks>
- [Pure]
- [Conditional("CONTRACTS_FULL")]
- public static void Requires(bool condition, string? userMessage)
- {
- AssertMustUseRewriter(ContractFailureKind.Precondition, "Requires");
- }
-
- /// <summary>
- /// Specifies a contract such that the expression <paramref name="condition"/> must be true before the enclosing method or property is invoked.
- /// </summary>
- /// <param name="condition">Boolean expression representing the contract.</param>
- /// <remarks>
- /// This call must happen at the beginning of a method or property before any other code.
- /// This contract is exposed to clients so must only reference members at least as visible as the enclosing method.
- /// Use this form when you want to throw a particular exception.
- /// </remarks>
- [Pure]
- public static void Requires<TException>(bool condition) where TException : Exception
- {
- AssertMustUseRewriter(ContractFailureKind.Precondition, "Requires<TException>");
- }
-
- /// <summary>
- /// Specifies a contract such that the expression <paramref name="condition"/> must be true before the enclosing method or property is invoked.
- /// </summary>
- /// <param name="condition">Boolean expression representing the contract.</param>
- /// <param name="userMessage">If it is not a constant string literal, then the contract may not be understood by tools.</param>
- /// <remarks>
- /// This call must happen at the beginning of a method or property before any other code.
- /// This contract is exposed to clients so must only reference members at least as visible as the enclosing method.
- /// Use this form when you want to throw a particular exception.
- /// </remarks>
- [Pure]
- public static void Requires<TException>(bool condition, string? userMessage) where TException : Exception
- {
- AssertMustUseRewriter(ContractFailureKind.Precondition, "Requires<TException>");
- }
-
- #endregion Requires
-
- #region Ensures
-
- /// <summary>
- /// Specifies a public contract such that the expression <paramref name="condition"/> will be true when the enclosing method or property returns normally.
- /// </summary>
- /// <param name="condition">Boolean expression representing the contract. May include <seealso cref="OldValue"/> and <seealso cref="Result"/>.</param>
- /// <remarks>
- /// This call must happen at the beginning of a method or property before any other code.
- /// This contract is exposed to clients so must only reference members at least as visible as the enclosing method.
- /// The contract rewriter must be used for runtime enforcement of this postcondition.
- /// </remarks>
- [Pure]
- [Conditional("CONTRACTS_FULL")]
- public static void Ensures(bool condition)
- {
- AssertMustUseRewriter(ContractFailureKind.Postcondition, "Ensures");
- }
-
- /// <summary>
- /// Specifies a public contract such that the expression <paramref name="condition"/> will be true when the enclosing method or property returns normally.
- /// </summary>
- /// <param name="condition">Boolean expression representing the contract. May include <seealso cref="OldValue"/> and <seealso cref="Result"/>.</param>
- /// <param name="userMessage">If it is not a constant string literal, then the contract may not be understood by tools.</param>
- /// <remarks>
- /// This call must happen at the beginning of a method or property before any other code.
- /// This contract is exposed to clients so must only reference members at least as visible as the enclosing method.
- /// The contract rewriter must be used for runtime enforcement of this postcondition.
- /// </remarks>
- [Pure]
- [Conditional("CONTRACTS_FULL")]
- public static void Ensures(bool condition, string? userMessage)
- {
- AssertMustUseRewriter(ContractFailureKind.Postcondition, "Ensures");
- }
-
- /// <summary>
- /// Specifies a contract such that if an exception of type <typeparamref name="TException"/> is thrown then the expression <paramref name="condition"/> will be true when the enclosing method or property terminates abnormally.
- /// </summary>
- /// <typeparam name="TException">Type of exception related to this postcondition.</typeparam>
- /// <param name="condition">Boolean expression representing the contract. May include <seealso cref="OldValue"/> and <seealso cref="Result"/>.</param>
- /// <remarks>
- /// This call must happen at the beginning of a method or property before any other code.
- /// This contract is exposed to clients so must only reference types and members at least as visible as the enclosing method.
- /// The contract rewriter must be used for runtime enforcement of this postcondition.
- /// </remarks>
- [Pure]
- [Conditional("CONTRACTS_FULL")]
- public static void EnsuresOnThrow<TException>(bool condition) where TException : Exception
- {
- AssertMustUseRewriter(ContractFailureKind.PostconditionOnException, "EnsuresOnThrow");
- }
-
- /// <summary>
- /// Specifies a contract such that if an exception of type <typeparamref name="TException"/> is thrown then the expression <paramref name="condition"/> will be true when the enclosing method or property terminates abnormally.
- /// </summary>
- /// <typeparam name="TException">Type of exception related to this postcondition.</typeparam>
- /// <param name="condition">Boolean expression representing the contract. May include <seealso cref="OldValue"/> and <seealso cref="Result"/>.</param>
- /// <param name="userMessage">If it is not a constant string literal, then the contract may not be understood by tools.</param>
- /// <remarks>
- /// This call must happen at the beginning of a method or property before any other code.
- /// This contract is exposed to clients so must only reference types and members at least as visible as the enclosing method.
- /// The contract rewriter must be used for runtime enforcement of this postcondition.
- /// </remarks>
- [Pure]
- [Conditional("CONTRACTS_FULL")]
- public static void EnsuresOnThrow<TException>(bool condition, string? userMessage) where TException : Exception
- {
- AssertMustUseRewriter(ContractFailureKind.PostconditionOnException, "EnsuresOnThrow");
- }
-
- #region Old, Result, and Out Parameters
-
- /// <summary>
- /// Represents the result (a.k.a. return value) of a method or property.
- /// </summary>
- /// <typeparam name="T">Type of return value of the enclosing method or property.</typeparam>
- /// <returns>Return value of the enclosing method or property.</returns>
- /// <remarks>
- /// This method can only be used within the argument to the <seealso cref="Ensures(bool)"/> contract.
- /// </remarks>
- [Pure]
- public static T Result<T>() { return default!; }
-
- /// <summary>
- /// Represents the final (output) value of an out parameter when returning from a method.
- /// </summary>
- /// <typeparam name="T">Type of the out parameter.</typeparam>
- /// <param name="value">The out parameter.</param>
- /// <returns>The output value of the out parameter.</returns>
- /// <remarks>
- /// This method can only be used within the argument to the <seealso cref="Ensures(bool)"/> contract.
- /// </remarks>
- [Pure]
- public static T ValueAtReturn<T>(out T value) { value = default!; return value; }
-
- /// <summary>
- /// Represents the value of <paramref name="value"/> as it was at the start of the method or property.
- /// </summary>
- /// <typeparam name="T">Type of <paramref name="value"/>. This can be inferred.</typeparam>
- /// <param name="value">Value to represent. This must be a field or parameter.</param>
- /// <returns>Value of <paramref name="value"/> at the start of the method or property.</returns>
- /// <remarks>
- /// This method can only be used within the argument to the <seealso cref="Ensures(bool)"/> contract.
- /// </remarks>
- [Pure]
- public static T OldValue<T>(T value) { return default!; }
-
- #endregion Old, Result, and Out Parameters
-
- #endregion Ensures
-
- #region Invariant
-
- /// <summary>
- /// Specifies a contract such that the expression <paramref name="condition"/> will be true after every method or property on the enclosing class.
- /// </summary>
- /// <param name="condition">Boolean expression representing the contract.</param>
- /// <remarks>
- /// This contact can only be specified in a dedicated invariant method declared on a class.
- /// This contract is not exposed to clients so may reference members less visible as the enclosing method.
- /// The contract rewriter must be used for runtime enforcement of this invariant.
- /// </remarks>
- [Pure]
- [Conditional("CONTRACTS_FULL")]
- public static void Invariant(bool condition)
- {
- AssertMustUseRewriter(ContractFailureKind.Invariant, "Invariant");
- }
-
- /// <summary>
- /// Specifies a contract such that the expression <paramref name="condition"/> will be true after every method or property on the enclosing class.
- /// </summary>
- /// <param name="condition">Boolean expression representing the contract.</param>
- /// <param name="userMessage">If it is not a constant string literal, then the contract may not be understood by tools.</param>
- /// <remarks>
- /// This contact can only be specified in a dedicated invariant method declared on a class.
- /// This contract is not exposed to clients so may reference members less visible as the enclosing method.
- /// The contract rewriter must be used for runtime enforcement of this invariant.
- /// </remarks>
- [Pure]
- [Conditional("CONTRACTS_FULL")]
- public static void Invariant(bool condition, string? userMessage)
- {
- AssertMustUseRewriter(ContractFailureKind.Invariant, "Invariant");
- }
-
- #endregion Invariant
-
- #region Quantifiers
-
- #region ForAll
-
- /// <summary>
- /// Returns whether the <paramref name="predicate"/> returns <c>true</c>
- /// for all integers starting from <paramref name="fromInclusive"/> to <paramref name="toExclusive"/> - 1.
- /// </summary>
- /// <param name="fromInclusive">First integer to pass to <paramref name="predicate"/>.</param>
- /// <param name="toExclusive">One greater than the last integer to pass to <paramref name="predicate"/>.</param>
- /// <param name="predicate">Function that is evaluated from <paramref name="fromInclusive"/> to <paramref name="toExclusive"/> - 1.</param>
- /// <returns><c>true</c> if <paramref name="predicate"/> returns <c>true</c> for all integers
- /// starting from <paramref name="fromInclusive"/> to <paramref name="toExclusive"/> - 1.</returns>
- /// <seealso cref="System.Collections.Generic.List&lt;T&gt;.TrueForAll"/>
- [Pure]
- public static bool ForAll(int fromInclusive, int toExclusive, Predicate<int> predicate)
- {
- if (fromInclusive > toExclusive)
- throw new ArgumentException(SR.Argument_ToExclusiveLessThanFromExclusive);
- if (predicate == null)
- throw new ArgumentNullException(nameof(predicate));
-
- for (int i = fromInclusive; i < toExclusive; i++)
- if (!predicate(i)) return false;
- return true;
- }
-
-
- /// <summary>
- /// Returns whether the <paramref name="predicate"/> returns <c>true</c>
- /// for all elements in the <paramref name="collection"/>.
- /// </summary>
- /// <param name="collection">The collection from which elements will be drawn from to pass to <paramref name="predicate"/>.</param>
- /// <param name="predicate">Function that is evaluated on elements from <paramref name="collection"/>.</param>
- /// <returns><c>true</c> if and only if <paramref name="predicate"/> returns <c>true</c> for all elements in
- /// <paramref name="collection"/>.</returns>
- /// <seealso cref="System.Collections.Generic.List&lt;T&gt;.TrueForAll"/>
- [Pure]
- public static bool ForAll<T>(IEnumerable<T> collection, Predicate<T> predicate)
- {
- if (collection == null)
- throw new ArgumentNullException(nameof(collection));
- if (predicate == null)
- throw new ArgumentNullException(nameof(predicate));
-
- foreach (T t in collection)
- if (!predicate(t)) return false;
- return true;
- }
-
- #endregion ForAll
-
- #region Exists
-
- /// <summary>
- /// Returns whether the <paramref name="predicate"/> returns <c>true</c>
- /// for any integer starting from <paramref name="fromInclusive"/> to <paramref name="toExclusive"/> - 1.
- /// </summary>
- /// <param name="fromInclusive">First integer to pass to <paramref name="predicate"/>.</param>
- /// <param name="toExclusive">One greater than the last integer to pass to <paramref name="predicate"/>.</param>
- /// <param name="predicate">Function that is evaluated from <paramref name="fromInclusive"/> to <paramref name="toExclusive"/> - 1.</param>
- /// <returns><c>true</c> if <paramref name="predicate"/> returns <c>true</c> for any integer
- /// starting from <paramref name="fromInclusive"/> to <paramref name="toExclusive"/> - 1.</returns>
- /// <seealso cref="System.Collections.Generic.List&lt;T&gt;.Exists"/>
- [Pure]
- public static bool Exists(int fromInclusive, int toExclusive, Predicate<int> predicate)
- {
- if (fromInclusive > toExclusive)
- throw new ArgumentException(SR.Argument_ToExclusiveLessThanFromExclusive);
- if (predicate == null)
- throw new ArgumentNullException(nameof(predicate));
-
- for (int i = fromInclusive; i < toExclusive; i++)
- if (predicate(i)) return true;
- return false;
- }
-
- /// <summary>
- /// Returns whether the <paramref name="predicate"/> returns <c>true</c>
- /// for any element in the <paramref name="collection"/>.
- /// </summary>
- /// <param name="collection">The collection from which elements will be drawn from to pass to <paramref name="predicate"/>.</param>
- /// <param name="predicate">Function that is evaluated on elements from <paramref name="collection"/>.</param>
- /// <returns><c>true</c> if and only if <paramref name="predicate"/> returns <c>true</c> for an element in
- /// <paramref name="collection"/>.</returns>
- /// <seealso cref="System.Collections.Generic.List&lt;T&gt;.Exists"/>
- [Pure]
- public static bool Exists<T>(IEnumerable<T> collection, Predicate<T> predicate)
- {
- if (collection == null)
- throw new ArgumentNullException(nameof(collection));
- if (predicate == null)
- throw new ArgumentNullException(nameof(predicate));
-
- foreach (T t in collection)
- if (predicate(t)) return true;
- return false;
- }
-
- #endregion Exists
-
- #endregion Quantifiers
-
- #region Misc.
-
- /// <summary>
- /// Marker to indicate the end of the contract section of a method.
- /// </summary>
- [Conditional("CONTRACTS_FULL")]
- public static void EndContractBlock() { }
-
- #endregion
-
- #endregion User Methods
-
- #region Private Methods
-
- /// <summary>
- /// This method is used internally to trigger a failure indicating to the "programmer" that he is using the interface incorrectly.
- /// It is NEVER used to indicate failure of actual contracts at runtime.
- /// </summary>
- private static void AssertMustUseRewriter(ContractFailureKind kind, string contractKind)
- {
- // For better diagnostics, report which assembly is at fault. Walk up stack and
- // find the first non-mscorlib assembly.
- Assembly thisAssembly = typeof(Contract).Assembly; // In case we refactor mscorlib, use Contract class instead of Object.
- StackTrace stack = new StackTrace();
- Assembly? probablyNotRewritten = null;
- for (int i = 0; i < stack.FrameCount; i++)
- {
- Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType!.Assembly;
- if (caller != null && caller != thisAssembly)
- {
- probablyNotRewritten = caller;
- break;
- }
- }
-
- probablyNotRewritten ??= thisAssembly;
- string? simpleName = probablyNotRewritten.GetName().Name;
- ContractHelper.TriggerFailure(kind, SR.Format(SR.MustUseCCRewrite, contractKind, simpleName), null, null, null);
- }
-
- #endregion Private Methods
-
- #region Failure Behavior
-
- /// <summary>
- /// Without contract rewriting, failing Assert/Assumes end up calling this method.
- /// Code going through the contract rewriter never calls this method. Instead, the rewriter produced failures call
- /// ContractHelper.RaiseContractFailedEvent, followed by ContractHelper.TriggerFailure.
- /// </summary>
- [System.Diagnostics.DebuggerNonUserCode]
- private static void ReportFailure(ContractFailureKind failureKind, string? userMessage, string? conditionText, Exception? innerException)
- {
- if (failureKind < ContractFailureKind.Precondition || failureKind > ContractFailureKind.Assume)
- throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, failureKind), nameof(failureKind));
-
- // displayMessage == null means: yes we handled it. Otherwise it is the localized failure message
- string? displayMessage = ContractHelper.RaiseContractFailedEvent(failureKind, userMessage, conditionText, innerException);
- if (displayMessage == null)
- return;
-
- ContractHelper.TriggerFailure(failureKind, displayMessage, userMessage, conditionText, innerException);
- }
-
- /// <summary>
- /// Allows a managed application environment such as an interactive interpreter (IronPython)
- /// to be notified of contract failures and
- /// potentially "handle" them, either by throwing a particular exception type, etc. If any of the
- /// event handlers sets the Cancel flag in the ContractFailedEventArgs, then the Contract class will
- /// not pop up an assert dialog box or trigger escalation policy. Hooking this event requires
- /// full trust, because it will inform you of bugs in the appdomain and because the event handler
- /// could allow you to continue execution.
- /// </summary>
- public static event EventHandler<ContractFailedEventArgs>? ContractFailed
- {
- add
- {
- ContractHelper.InternalContractFailed += value;
- }
- remove
- {
- ContractHelper.InternalContractFailed -= value;
- }
- }
-
- #endregion Failure Behavior
- }
-
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public enum ContractFailureKind
- {
- Precondition,
- Postcondition,
- PostconditionOnException,
- Invariant,
- Assert,
- Assume,
- }
-} // namespace System.Runtime.CompilerServices
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Debug.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Debug.cs
deleted file mode 100644
index ea1c0a897c6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Debug.cs
+++ /dev/null
@@ -1,251 +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.
-
-// Do not remove this, it is needed to retain calls to these conditional methods in release builds
-#define DEBUG
-
-using System.Diagnostics.CodeAnalysis;
-using System.Threading;
-
-namespace System.Diagnostics
-{
- /// <summary>
- /// Provides a set of properties and methods for debugging code.
- /// </summary>
- public static partial class Debug
- {
- private static volatile DebugProvider s_provider = new DebugProvider();
-
- public static DebugProvider SetProvider(DebugProvider provider)
- {
- if (provider == null)
- throw new ArgumentNullException(nameof(provider));
-
- return Interlocked.Exchange(ref s_provider, provider);
- }
-
- public static bool AutoFlush
- {
- get => true;
- set { }
- }
-
- [ThreadStatic]
- private static int t_indentLevel;
- public static int IndentLevel
- {
- get => t_indentLevel;
- set
- {
- t_indentLevel = value < 0 ? 0 : value;
- s_provider.OnIndentLevelChanged(t_indentLevel);
- }
- }
-
- private static volatile int s_indentSize = 4;
- public static int IndentSize
- {
- get => s_indentSize;
- set
- {
- s_indentSize = value < 0 ? 0 : value;
- s_provider.OnIndentSizeChanged(s_indentSize);
- }
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Close() { }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Flush() { }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Indent() =>
- IndentLevel++;
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Unindent() =>
- IndentLevel--;
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Print(string? message) =>
- WriteLine(message);
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Print(string format, params object?[] args) =>
- WriteLine(string.Format(null, format, args));
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Assert([DoesNotReturnIf(false)] bool condition) =>
- Assert(condition, string.Empty, string.Empty);
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Assert([DoesNotReturnIf(false)] bool condition, string? message) =>
- Assert(condition, message, string.Empty);
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Assert([DoesNotReturnIf(false)] bool condition, string? message, string? detailMessage)
- {
- if (!condition)
- {
- Fail(message, detailMessage);
- }
- }
-
- internal static void ContractFailure(string message, string detailMessage, string failureKindMessage)
- {
- string stackTrace;
- try
- {
- stackTrace = new StackTrace(2, true).ToString(System.Diagnostics.StackTrace.TraceFormat.Normal);
- }
- catch
- {
- stackTrace = "";
- }
- s_provider.WriteAssert(stackTrace, message, detailMessage);
- DebugProvider.FailCore(stackTrace, message, detailMessage, failureKindMessage);
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- [DoesNotReturn]
- public static void Fail(string? message) =>
- Fail(message, string.Empty);
-
- [System.Diagnostics.Conditional("DEBUG")]
- [DoesNotReturn]
- public static void Fail(string? message, string? detailMessage) =>
- s_provider.Fail(message, detailMessage);
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Assert([DoesNotReturnIf(false)] bool condition, string? message, string detailMessageFormat, params object?[] args) =>
- Assert(condition, message, string.Format(detailMessageFormat, args));
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLine(string? message) =>
- s_provider.WriteLine(message);
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Write(string? message) =>
- s_provider.Write(message);
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLine(object? value) =>
- WriteLine(value?.ToString());
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLine(object? value, string? category) =>
- WriteLine(value?.ToString(), category);
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLine(string format, params object?[] args) =>
- WriteLine(string.Format(null, format, args));
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLine(string? message, string? category)
- {
- if (category == null)
- {
- WriteLine(message);
- }
- else
- {
- WriteLine(category + ": " + message);
- }
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Write(object? value) =>
- Write(value?.ToString());
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Write(string? message, string? category)
- {
- if (category == null)
- {
- Write(message);
- }
- else
- {
- Write(category + ": " + message);
- }
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void Write(object? value, string? category) =>
- Write(value?.ToString(), category);
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteIf(bool condition, string? message)
- {
- if (condition)
- {
- Write(message);
- }
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteIf(bool condition, object? value)
- {
- if (condition)
- {
- Write(value);
- }
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteIf(bool condition, string? message, string? category)
- {
- if (condition)
- {
- Write(message, category);
- }
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteIf(bool condition, object? value, string? category)
- {
- if (condition)
- {
- Write(value, category);
- }
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLineIf(bool condition, object? value)
- {
- if (condition)
- {
- WriteLine(value);
- }
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLineIf(bool condition, object? value, string? category)
- {
- if (condition)
- {
- WriteLine(value, category);
- }
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLineIf(bool condition, string? message)
- {
- if (condition)
- {
- WriteLine(message);
- }
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- public static void WriteLineIf(bool condition, string? message, string? category)
- {
- if (condition)
- {
- WriteLine(message, category);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.Unix.cs
deleted file mode 100644
index 9259c4fbe66..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.Unix.cs
+++ /dev/null
@@ -1,107 +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;
-
-namespace System.Diagnostics
-{
- public partial class DebugProvider
- {
- private static readonly bool s_shouldWriteToStdErr = Environment.GetEnvironmentVariable("COMPlus_DebugWriteToStdErr") == "1";
-
- public static void FailCore(string stackTrace, string? message, string? detailMessage, string errorSource)
- {
- if (s_FailCore != null)
- {
- s_FailCore(stackTrace, message, detailMessage, errorSource);
- return;
- }
-
- if (Debugger.IsAttached)
- {
- Debugger.Break();
- }
- else
- {
- // In Core, we do not show a dialog.
- // Fail in order to avoid anyone catching an exception and masking
- // an assert failure.
- DebugAssertException ex = new DebugAssertException(message, detailMessage, stackTrace);
- Environment.FailFast(ex.Message, ex, errorSource);
- }
- }
-
- public static void WriteCore(string message)
- {
- if (s_WriteCore != null)
- {
- s_WriteCore(message);
- return;
- }
-
- WriteToDebugger(message);
-
- if (s_shouldWriteToStdErr)
- {
- WriteToStderr(message);
- }
- }
-
- private static void WriteToDebugger(string message)
- {
- if (Debugger.IsLogging())
- {
- Debugger.Log(0, null, message);
- }
- else
- {
- Interop.Sys.SysLog(Interop.Sys.SysLogPriority.LOG_USER | Interop.Sys.SysLogPriority.LOG_DEBUG, "%s", message);
- }
- }
-
- private static void WriteToStderr(string message)
- {
- // We don't want to write UTF-16 to a file like standard error. Ideally we would transcode this
- // to UTF8, but the downside of that is it pulls in a bunch of stuff into what is ideally
- // a path with minimal dependencies (as to prevent re-entrency), so we'll take the strategy
- // of just throwing away any non ASCII characters from the message and writing the rest
-
- const int BufferLength = 256;
-
- unsafe
- {
- byte* buf = stackalloc byte[BufferLength];
- int bufCount;
- int i = 0;
-
- while (i < message.Length)
- {
- for (bufCount = 0; bufCount < BufferLength && i < message.Length; i++)
- {
- if (message[i] <= 0x7F)
- {
- buf[bufCount] = (byte)message[i];
- bufCount++;
- }
- }
-
- int totalBytesWritten = 0;
- while (bufCount > 0)
- {
- int bytesWritten = Interop.Sys.Write(2 /* stderr */, buf + totalBytesWritten, bufCount);
- if (bytesWritten < 0)
- {
- // On error, simply stop writing the debug output. This could commonly happen if stderr
- // was piped to a program that ended before this program did, resulting in EPIPE errors.
- return;
- }
-
- bufCount -= bytesWritten;
- totalBytesWritten += bytesWritten;
- }
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.Windows.cs
deleted file mode 100644
index f8db18062ac..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.Windows.cs
+++ /dev/null
@@ -1,77 +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.
-
-namespace System.Diagnostics
-{
- public partial class DebugProvider
- {
- public static void FailCore(string stackTrace, string? message, string? detailMessage, string errorSource)
- {
- if (s_FailCore != null)
- {
- s_FailCore(stackTrace, message, detailMessage, errorSource);
- return;
- }
-
- if (Debugger.IsAttached)
- {
- Debugger.Break();
- }
- else
- {
- // In Core, we do not show a dialog.
- // Fail in order to avoid anyone catching an exception and masking
- // an assert failure.
- DebugAssertException ex = new DebugAssertException(message, detailMessage, stackTrace);
- Environment.FailFast(ex.Message, ex, errorSource);
- }
- }
-
- private static readonly object s_ForLock = new object();
-
- public static void WriteCore(string message)
- {
- if (s_WriteCore != null)
- {
- s_WriteCore(message);
- return;
- }
-
- // really huge messages mess up both VS and dbmon, so we chop it up into
- // reasonable chunks if it's too big. This is the number of characters
- // that OutputDebugstring chunks at.
- const int WriteChunkLength = 4091;
-
- // We don't want output from multiple threads to be interleaved.
- lock (s_ForLock)
- {
- if (message.Length <= WriteChunkLength)
- {
- WriteToDebugger(message);
- }
- else
- {
- int offset;
- for (offset = 0; offset < message.Length - WriteChunkLength; offset += WriteChunkLength)
- {
- WriteToDebugger(message.Substring(offset, WriteChunkLength));
- }
- WriteToDebugger(message.Substring(offset));
- }
- }
- }
-
- private static void WriteToDebugger(string message)
- {
- if (Debugger.IsLogging())
- {
- Debugger.Log(0, null, message);
- }
- else
- {
- Interop.Kernel32.OutputDebugString(message ?? string.Empty);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.cs
deleted file mode 100644
index cf4dfe1effd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebugProvider.cs
+++ /dev/null
@@ -1,111 +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.
-
-// Do not remove this, it is needed to retain calls to these conditional methods in release builds
-#define DEBUG
-
-namespace System.Diagnostics
-{
- /// <summary>
- /// Provides default implementation for Write and Fail methods in Debug class.
- /// </summary>
- public partial class DebugProvider
- {
- public virtual void Fail(string? message, string? detailMessage)
- {
- string stackTrace;
- try
- {
- stackTrace = new StackTrace(0, true).ToString(System.Diagnostics.StackTrace.TraceFormat.Normal);
- }
- catch
- {
- stackTrace = "";
- }
- WriteAssert(stackTrace, message, detailMessage);
- FailCore(stackTrace, message, detailMessage, "Assertion failed.");
- }
-
- internal void WriteAssert(string stackTrace, string? message, string? detailMessage)
- {
- WriteLine(SR.DebugAssertBanner + Environment.NewLineConst
- + SR.DebugAssertShortMessage + Environment.NewLineConst
- + message + Environment.NewLineConst
- + SR.DebugAssertLongMessage + Environment.NewLineConst
- + detailMessage + Environment.NewLineConst
- + stackTrace);
- }
-
- public virtual void Write(string? message)
- {
- lock (s_lock)
- {
- if (message == null)
- {
- WriteCore(string.Empty);
- return;
- }
- if (_needIndent)
- {
- message = GetIndentString() + message;
- _needIndent = false;
- }
- WriteCore(message);
- if (message.EndsWith(Environment.NewLineConst))
- {
- _needIndent = true;
- }
- }
- }
-
- public virtual void WriteLine(string? message)
- {
- Write(message + Environment.NewLineConst);
- }
-
- public virtual void OnIndentLevelChanged(int indentLevel) { }
-
- public virtual void OnIndentSizeChanged(int indentSize) { }
-
- private static readonly object s_lock = new object();
-
- private sealed class DebugAssertException : Exception
- {
- internal DebugAssertException(string? message, string? detailMessage, string? stackTrace) :
- base(Terminate(message) + Terminate(detailMessage) + stackTrace)
- {
- }
-
- private static string? Terminate(string? s)
- {
- if (s == null)
- return s;
-
- s = s.Trim();
- if (s.Length > 0)
- s += Environment.NewLineConst;
-
- return s;
- }
- }
-
- private bool _needIndent = true;
-
- private string? _indentString;
-
- private string GetIndentString()
- {
- int indentCount = Debug.IndentSize * Debug.IndentLevel;
- if (_indentString?.Length == indentCount)
- {
- return _indentString;
- }
- return _indentString = new string(' ', indentCount);
- }
-
- // internal and not readonly so that the tests can swap this out.
- internal static Action<string, string?, string?, string>? s_FailCore = null;
- internal static Action<string>? s_WriteCore = null;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggableAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggableAttribute.cs
deleted file mode 100644
index cfb9321256a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggableAttribute.cs
+++ /dev/null
@@ -1,54 +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.
-
-namespace System.Diagnostics
-{
- // Attribute class used by the compiler to mark modules.
- // If present, then debugging information for everything in the
- // assembly was generated by the compiler, and will be preserved
- // by the Runtime so that the debugger can provide full functionality
- // in the case of JIT attach. If not present, then the compiler may
- // or may not have included debugging information, and the Runtime
- // won't preserve the debugging info, which will make debugging after
- // a JIT attach difficult.
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module, AllowMultiple = false)]
- public sealed class DebuggableAttribute : Attribute
- {
- [Flags]
- public enum DebuggingModes
- {
- None = 0x0,
- Default = 0x1,
- DisableOptimizations = 0x100,
- IgnoreSymbolStoreSequencePoints = 0x2,
- EnableEditAndContinue = 0x4
- }
-
- public DebuggableAttribute(bool isJITTrackingEnabled, bool isJITOptimizerDisabled)
- {
- DebuggingFlags = 0;
-
- if (isJITTrackingEnabled)
- {
- DebuggingFlags |= DebuggingModes.Default;
- }
-
- if (isJITOptimizerDisabled)
- {
- DebuggingFlags |= DebuggingModes.DisableOptimizations;
- }
- }
-
- public DebuggableAttribute(DebuggingModes modes)
- {
- DebuggingFlags = modes;
- }
-
- public bool IsJITTrackingEnabled => (DebuggingFlags & DebuggingModes.Default) != 0;
-
- public bool IsJITOptimizerDisabled => (DebuggingFlags & DebuggingModes.DisableOptimizations) != 0;
-
- public DebuggingModes DebuggingFlags { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerBrowsableAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerBrowsableAttribute.cs
deleted file mode 100644
index 9d670b20c40..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerBrowsableAttribute.cs
+++ /dev/null
@@ -1,41 +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.
-
-namespace System.Diagnostics
-{
- // DebuggerBrowsableState states are defined as follows:
- // Never element should never show
- // Expanded expansion of the class is done, so that all visible internal members are shown
- // Collapsed expansion of the class is not performed. Internal visible members are hidden
- // RootHidden The target element itself should not be shown, but should instead be
- // automatically expanded to have its members displayed.
- // Default value is collapsed
-
- // Please also change the code which validates DebuggerBrowsableState variable (in this file)
- // if you change this enum.
- public enum DebuggerBrowsableState
- {
- Never = 0,
- // Expanded is not supported in this release
- // Expanded = 1,
- Collapsed = 2,
- RootHidden = 3
- }
-
-
- // the one currently supported with the csee.dat
- // (mcee.dat, autoexp.dat) file.
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
- public sealed class DebuggerBrowsableAttribute : Attribute
- {
- public DebuggerBrowsableAttribute(DebuggerBrowsableState state)
- {
- if (state < DebuggerBrowsableState.Never || state > DebuggerBrowsableState.RootHidden)
- throw new ArgumentOutOfRangeException(nameof(state));
-
- State = state;
- }
- public DebuggerBrowsableState State { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerDisplayAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerDisplayAttribute.cs
deleted file mode 100644
index b91f275f973..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerDisplayAttribute.cs
+++ /dev/null
@@ -1,51 +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.
-
-namespace System.Diagnostics
-{
- // This attribute is used to control what is displayed for the given class or field
- // in the data windows in the debugger. The single argument to this attribute is
- // the string that will be displayed in the value column for instances of the type.
- // This string can include text between { and } which can be either a field,
- // property or method (as will be documented in mscorlib). In the C# case,
- // a general expression will be allowed which only has implicit access to the this pointer
- // for the current instance of the target type. The expression will be limited,
- // however: there is no access to aliases, locals, or pointers.
- // In addition, attributes on properties referenced in the expression are not processed.
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Assembly, AllowMultiple = true)]
- public sealed class DebuggerDisplayAttribute : Attribute
- {
- private Type? _target;
-
- public DebuggerDisplayAttribute(string? value)
- {
- Value = value ?? "";
- Name = "";
- Type = "";
- }
-
- public string Value { get; }
-
- public string? Name { get; set; }
-
- public string? Type { get; set; }
-
- public Type? Target
- {
- get => _target;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- TargetTypeName = value.AssemblyQualifiedName;
- _target = value;
- }
- }
-
- public string? TargetTypeName { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerHiddenAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerHiddenAttribute.cs
deleted file mode 100644
index ace452e911c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerHiddenAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Diagnostics
-{
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor, Inherited = false)]
- public sealed class DebuggerHiddenAttribute : Attribute
- {
- public DebuggerHiddenAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerNonUserCodeAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerNonUserCodeAttribute.cs
deleted file mode 100644
index 1b61cb72628..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerNonUserCodeAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Diagnostics
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)]
- public sealed class DebuggerNonUserCodeAttribute : Attribute
- {
- public DebuggerNonUserCodeAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerStepThroughAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerStepThroughAttribute.cs
deleted file mode 100644
index 1a62b922e07..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerStepThroughAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Diagnostics
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)]
- public sealed class DebuggerStepThroughAttribute : Attribute
- {
- public DebuggerStepThroughAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerStepperBoundaryAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerStepperBoundaryAttribute.cs
deleted file mode 100644
index 647f2fdb00a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerStepperBoundaryAttribute.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Diagnostics
-{
- /// <summary>Indicates the code following the attribute is to be executed in run, not step, mode.</summary>
- [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method, Inherited = false)]
- public sealed class DebuggerStepperBoundaryAttribute : Attribute
- {
- public DebuggerStepperBoundaryAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerTypeProxyAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerTypeProxyAttribute.cs
deleted file mode 100644
index 579e88d22ea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerTypeProxyAttribute.cs
+++ /dev/null
@@ -1,46 +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.
-
-namespace System.Diagnostics
-{
- [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
- public sealed class DebuggerTypeProxyAttribute : Attribute
- {
- private Type? _target;
-
- public DebuggerTypeProxyAttribute(Type type)
- {
- if (type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
-
- ProxyTypeName = type.AssemblyQualifiedName!;
- }
-
- public DebuggerTypeProxyAttribute(string typeName)
- {
- ProxyTypeName = typeName;
- }
-
- public string ProxyTypeName { get; }
-
- public Type? Target
- {
- get => _target;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- TargetTypeName = value.AssemblyQualifiedName;
- _target = value;
- }
- }
-
- public string? TargetTypeName { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerVisualizerAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerVisualizerAttribute.cs
deleted file mode 100644
index bffe88fddfe..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/DebuggerVisualizerAttribute.cs
+++ /dev/null
@@ -1,97 +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.
-
-namespace System.Diagnostics
-{
- /// <summary>
- /// Signifies that the attributed type has a visualizer which is pointed
- /// to by the parameter type name strings.
- /// </summary>
- [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
- public sealed class DebuggerVisualizerAttribute : Attribute
- {
- private Type? _target;
-
- public DebuggerVisualizerAttribute(string visualizerTypeName)
- {
- VisualizerTypeName = visualizerTypeName;
- }
-
- public DebuggerVisualizerAttribute(string visualizerTypeName, string? visualizerObjectSourceTypeName)
- {
- VisualizerTypeName = visualizerTypeName;
- VisualizerObjectSourceTypeName = visualizerObjectSourceTypeName;
- }
-
- public DebuggerVisualizerAttribute(string visualizerTypeName, Type visualizerObjectSource)
- {
- if (visualizerObjectSource == null)
- {
- throw new ArgumentNullException(nameof(visualizerObjectSource));
- }
-
- VisualizerTypeName = visualizerTypeName;
- VisualizerObjectSourceTypeName = visualizerObjectSource.AssemblyQualifiedName;
- }
-
- public DebuggerVisualizerAttribute(Type visualizer)
- {
- if (visualizer == null)
- {
- throw new ArgumentNullException(nameof(visualizer));
- }
-
- VisualizerTypeName = visualizer.AssemblyQualifiedName!;
- }
-
- public DebuggerVisualizerAttribute(Type visualizer, Type visualizerObjectSource)
- {
- if (visualizer == null)
- {
- throw new ArgumentNullException(nameof(visualizer));
- }
- if (visualizerObjectSource == null)
- {
- throw new ArgumentNullException(nameof(visualizerObjectSource));
- }
-
- VisualizerTypeName = visualizer.AssemblyQualifiedName!;
- VisualizerObjectSourceTypeName = visualizerObjectSource.AssemblyQualifiedName;
- }
-
- public DebuggerVisualizerAttribute(Type visualizer, string? visualizerObjectSourceTypeName)
- {
- if (visualizer == null)
- {
- throw new ArgumentNullException(nameof(visualizer));
- }
-
- VisualizerTypeName = visualizer.AssemblyQualifiedName!;
- VisualizerObjectSourceTypeName = visualizerObjectSourceTypeName;
- }
-
- public string? VisualizerObjectSourceTypeName { get; }
-
- public string VisualizerTypeName { get; }
-
- public string? Description { get; set; }
-
- public Type? Target
- {
- get => _target;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- TargetTypeName = value.AssemblyQualifiedName;
- _target = value;
- }
- }
-
- public string? TargetTypeName { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/StackFrame.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/StackFrame.cs
deleted file mode 100644
index 087a7402e4b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/StackFrame.cs
+++ /dev/null
@@ -1,248 +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 System.Text;
-using System.Reflection;
-
-namespace System.Diagnostics
-{
- /// <summary>
- /// There is no good reason for the methods of this class to be virtual.
- /// </summary>
- public partial class StackFrame
- {
- /// <summary>
- /// Reflection information for the method if available, null otherwise.
- /// </summary>
- private MethodBase? _method;
-
- /// <summary>
- /// Native offset of the current instruction within the current method if available,
- /// OFFSET_UNKNOWN otherwise.
- /// </summary>
- private int _nativeOffset;
-
- /// <summary>
- /// IL offset of the current instruction within the current method if available,
- /// OFFSET_UNKNOWN otherwise.
- /// </summary>
- private int _ilOffset;
-
- /// <summary>
- /// Source file name representing the current code location if available, null otherwise.
- /// </summary>
- private string? _fileName;
-
- /// <summary>
- /// Line number representing the current code location if available, 0 otherwise.
- /// </summary>
- private int _lineNumber;
-
- /// <summary>
- /// Column number representing the current code location if available, 0 otherwise.
- /// </summary>
- private int _columnNumber;
-
- /// <summary>
- /// This flag is set to true when the frame represents a rethrow marker.
- /// </summary>
- private bool _isLastFrameFromForeignExceptionStackTrace;
-
- private void InitMembers()
- {
- _nativeOffset = OFFSET_UNKNOWN;
- _ilOffset = OFFSET_UNKNOWN;
- }
-
- /// <summary>
- /// Constructs a StackFrame corresponding to the active stack frame.
- /// </summary>
- public StackFrame()
- {
- InitMembers();
- BuildStackFrame(StackTrace.METHODS_TO_SKIP, false);
- }
-
- /// <summary>
- /// Constructs a StackFrame corresponding to the active stack frame.
- /// </summary>
- public StackFrame(bool needFileInfo)
- {
- InitMembers();
- BuildStackFrame(StackTrace.METHODS_TO_SKIP, needFileInfo);
- }
-
- /// <summary>
- /// Constructs a StackFrame corresponding to a calling stack frame.
- /// </summary>
- public StackFrame(int skipFrames)
- {
- InitMembers();
- BuildStackFrame(skipFrames + StackTrace.METHODS_TO_SKIP, false);
- }
-
- /// <summary>
- /// Constructs a StackFrame corresponding to a calling stack frame.
- /// </summary>
- public StackFrame(int skipFrames, bool needFileInfo)
- {
- InitMembers();
- BuildStackFrame(skipFrames + StackTrace.METHODS_TO_SKIP, needFileInfo);
- }
-
- /// <summary>
- /// Constructs a "fake" stack frame, just containing the given file
- /// name and line number. Use when you don't want to use the
- /// debugger's line mapping logic.
- /// </summary>
- public StackFrame(string? fileName, int lineNumber)
- {
- InitMembers();
-
- BuildStackFrame(StackTrace.METHODS_TO_SKIP, false);
- _fileName = fileName;
- _lineNumber = lineNumber;
- }
-
- /// <summary>
- /// Constructs a "fake" stack frame, just containing the given file
- /// name, line number and column number. Use when you don't want to
- /// use the debugger's line mapping logic.
- /// </summary>
- public StackFrame(string? fileName, int lineNumber, int colNumber)
- : this(fileName, lineNumber)
- {
- _columnNumber = colNumber;
- }
-
- /// <summary>
- /// Constant returned when the native or IL offset is unknown
- /// </summary>
- public const int OFFSET_UNKNOWN = -1;
-
- internal bool IsLastFrameFromForeignExceptionStackTrace => _isLastFrameFromForeignExceptionStackTrace;
-
- /// <summary>
- /// Returns the method the frame is executing
- /// </summary>
- public virtual MethodBase? GetMethod()
- {
- return _method;
- }
-
- /// <summary>
- /// Returns the offset from the start of the native (jitted) code for the
- /// method being executed
- /// </summary>
- public virtual int GetNativeOffset()
- {
- return _nativeOffset;
- }
-
-
- /// <summary>
- /// Returns the offset from the start of the IL code for the
- /// method being executed. This offset may be approximate depending
- /// on whether the jitter is generating debuggable code or not.
- /// </summary>
- public virtual int GetILOffset()
- {
- return _ilOffset;
- }
-
- /// <summary>
- /// Returns the file name containing the code being executed. This
- /// information is normally extracted from the debugging symbols
- /// for the executable.
- /// </summary>
- public virtual string? GetFileName()
- {
- return _fileName;
- }
-
- /// <summary>
- /// Returns the line number in the file containing the code being executed.
- /// This information is normally extracted from the debugging symbols
- /// for the executable.
- /// </summary>
- public virtual int GetFileLineNumber()
- {
- return _lineNumber;
- }
-
- /// <summary>
- /// Returns the column number in the line containing the code being executed.
- /// This information is normally extracted from the debugging symbols
- /// for the executable.
- /// </summary>
- public virtual int GetFileColumnNumber()
- {
- return _columnNumber;
- }
-
- /// <summary>
- /// Builds a readable representation of the stack frame
- /// </summary>
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder(255);
- bool includeFileInfoIfAvailable;
-
- if (_method != null)
- {
- sb.Append(_method.Name);
-
- // deal with the generic portion of the method
- if (_method is MethodInfo methodInfo && methodInfo.IsGenericMethod)
- {
- Type[] typars = methodInfo.GetGenericArguments();
-
- sb.Append('<');
- int k = 0;
- bool fFirstTyParam = true;
- while (k < typars.Length)
- {
- if (!fFirstTyParam)
- sb.Append(',');
- else
- fFirstTyParam = false;
-
- sb.Append(typars[k].Name);
- k++;
- }
-
- sb.Append('>');
- }
- includeFileInfoIfAvailable = true;
- }
- else
- {
- includeFileInfoIfAvailable = AppendStackFrameWithoutMethodBase(sb);
- }
-
- if (includeFileInfoIfAvailable)
- {
- sb.Append(" at offset ");
- if (_nativeOffset == OFFSET_UNKNOWN)
- sb.Append("<offset unknown>");
- else
- sb.Append(_nativeOffset);
-
- sb.Append(" in file:line:column ");
- sb.Append(_fileName ?? "<filename unknown>");
- sb.Append(':');
- sb.Append(_lineNumber);
- sb.Append(':');
- sb.Append(_columnNumber);
- }
- else
- {
- sb.Append("<null>");
- }
- sb.Append(Environment.NewLineConst);
-
- return sb.ToString();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/StackTrace.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/StackTrace.cs
deleted file mode 100644
index d67a6a33b37..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/StackTrace.cs
+++ /dev/null
@@ -1,421 +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 System.Collections;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System.Diagnostics
-{
- /// <summary>
- /// Class which represents a description of a stack trace
- /// There is no good reason for the methods of this class to be virtual.
- /// </summary>
- public partial class StackTrace
- {
- public const int METHODS_TO_SKIP = 0;
-
- private int _numOfFrames;
- private int _methodsToSkip;
-
- /// <summary>
- /// Stack frames comprising this stack trace.
- /// </summary>
- private StackFrame[]? _stackFrames;
-
- /// <summary>
- /// Constructs a stack trace from the current location.
- /// </summary>
- public StackTrace()
- {
- InitializeForCurrentThread(METHODS_TO_SKIP, false);
- }
-
- /// <summary>
- /// Constructs a stack trace from the current location.
- /// </summary>
- public StackTrace(bool fNeedFileInfo)
- {
- InitializeForCurrentThread(METHODS_TO_SKIP, fNeedFileInfo);
- }
-
- /// <summary>
- /// Constructs a stack trace from the current location, in a caller's
- /// frame
- /// </summary>
- public StackTrace(int skipFrames)
- {
- if (skipFrames < 0)
- throw new ArgumentOutOfRangeException(nameof(skipFrames),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- InitializeForCurrentThread(skipFrames + METHODS_TO_SKIP, false);
- }
-
- /// <summary>
- /// Constructs a stack trace from the current location, in a caller's
- /// frame
- /// </summary>
- public StackTrace(int skipFrames, bool fNeedFileInfo)
- {
- if (skipFrames < 0)
- throw new ArgumentOutOfRangeException(nameof(skipFrames),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- InitializeForCurrentThread(skipFrames + METHODS_TO_SKIP, fNeedFileInfo);
- }
-
- /// <summary>
- /// Constructs a stack trace from the current location.
- /// </summary>
- public StackTrace(Exception e)
- {
- if (e == null)
- throw new ArgumentNullException(nameof(e));
-
- InitializeForException(e, METHODS_TO_SKIP, false);
- }
-
- /// <summary>
- /// Constructs a stack trace from the current location.
- /// </summary>
- public StackTrace(Exception e, bool fNeedFileInfo)
- {
- if (e == null)
- throw new ArgumentNullException(nameof(e));
-
- InitializeForException(e, METHODS_TO_SKIP, fNeedFileInfo);
- }
-
- /// <summary>
- /// Constructs a stack trace from the current location, in a caller's
- /// frame
- /// </summary>
- public StackTrace(Exception e, int skipFrames)
- {
- if (e == null)
- throw new ArgumentNullException(nameof(e));
-
- if (skipFrames < 0)
- throw new ArgumentOutOfRangeException(nameof(skipFrames),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- InitializeForException(e, skipFrames + METHODS_TO_SKIP, false);
- }
-
- /// <summary>
- /// Constructs a stack trace from the current location, in a caller's
- /// frame
- /// </summary>
- public StackTrace(Exception e, int skipFrames, bool fNeedFileInfo)
- {
- if (e == null)
- throw new ArgumentNullException(nameof(e));
-
- if (skipFrames < 0)
- throw new ArgumentOutOfRangeException(nameof(skipFrames),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- InitializeForException(e, skipFrames + METHODS_TO_SKIP, fNeedFileInfo);
- }
-
- /// <summary>
- /// Constructs a "fake" stack trace, just containing a single frame.
- /// Does not have the overhead of a full stack trace.
- /// </summary>
- public StackTrace(StackFrame frame)
- {
- _stackFrames = new StackFrame[] { frame };
- _numOfFrames = 1;
- }
-
- /// <summary>
- /// Property to get the number of frames in the stack trace
- /// </summary>
- public virtual int FrameCount => _numOfFrames;
-
- /// <summary>
- /// Returns a given stack frame. Stack frames are numbered starting at
- /// zero, which is the last stack frame pushed.
- /// </summary>
- public virtual StackFrame? GetFrame(int index)
- {
- if (_stackFrames != null && index < _numOfFrames && index >= 0)
- return _stackFrames[index + _methodsToSkip];
-
- return null;
- }
-
- /// <summary>
- /// Returns an array of all stack frames for this stacktrace.
- /// The array is ordered and sized such that GetFrames()[i] == GetFrame(i)
- /// The nth element of this array is the same as GetFrame(n).
- /// The length of the array is the same as FrameCount.
- /// </summary>
- public virtual StackFrame[] GetFrames()
- {
- if (_stackFrames == null || _numOfFrames <= 0)
- return Array.Empty<StackFrame>();
-
- // We have to return a subset of the array. Unfortunately this
- // means we have to allocate a new array and copy over.
- StackFrame[] array = new StackFrame[_numOfFrames];
- Array.Copy(_stackFrames, _methodsToSkip, array, 0, _numOfFrames);
- return array;
- }
-
- /// <summary>
- /// Builds a readable representation of the stack trace
- /// </summary>
- public override string ToString()
- {
- // Include a trailing newline for backwards compatibility
- return ToString(TraceFormat.TrailingNewLine);
- }
-
- /// <summary>
- /// TraceFormat is used to specify options for how the
- /// string-representation of a StackTrace should be generated.
- /// </summary>
- internal enum TraceFormat
- {
- Normal,
- TrailingNewLine, // include a trailing new line character
- }
-
-#if !CORERT
- /// <summary>
- /// Builds a readable representation of the stack trace, specifying
- /// the format for backwards compatibility.
- /// </summary>
- internal string ToString(TraceFormat traceFormat)
- {
- var sb = new StringBuilder(256);
- ToString(traceFormat, sb);
- return sb.ToString();
- }
-
- internal void ToString(TraceFormat traceFormat, StringBuilder sb)
- {
- string word_At = SR.Word_At;
- string inFileLineNum = SR.StackTrace_InFileLineNumber;
- bool fFirstFrame = true;
- for (int iFrameIndex = 0; iFrameIndex < _numOfFrames; iFrameIndex++)
- {
- StackFrame? sf = GetFrame(iFrameIndex);
- MethodBase? mb = sf?.GetMethod();
- if (mb != null && (ShowInStackTrace(mb) ||
- (iFrameIndex == _numOfFrames - 1))) // Don't filter last frame
- {
- // We want a newline at the end of every line except for the last
- if (fFirstFrame)
- fFirstFrame = false;
- else
- sb.AppendLine();
-
- sb.AppendFormat(CultureInfo.InvariantCulture, " {0} ", word_At);
-
- bool isAsync = false;
- Type? declaringType = mb.DeclaringType;
- string methodName = mb.Name;
- bool methodChanged = false;
- if (declaringType != null && declaringType.IsDefined(typeof(CompilerGeneratedAttribute), inherit: false))
- {
- isAsync = typeof(IAsyncStateMachine).IsAssignableFrom(declaringType);
- if (isAsync || typeof(IEnumerator).IsAssignableFrom(declaringType))
- {
- methodChanged = TryResolveStateMachineMethod(ref mb, out declaringType);
- }
- }
-
- // if there is a type (non global method) print it
- // ResolveStateMachineMethod may have set declaringType to null
- if (declaringType != null)
- {
- // Append t.FullName, replacing '+' with '.'
- string fullName = declaringType.FullName!;
- for (int i = 0; i < fullName.Length; i++)
- {
- char ch = fullName[i];
- sb.Append(ch == '+' ? '.' : ch);
- }
- sb.Append('.');
- }
- sb.Append(mb.Name);
-
- // deal with the generic portion of the method
- if (mb is MethodInfo mi && mi.IsGenericMethod)
- {
- Type[] typars = mi.GetGenericArguments();
- sb.Append('[');
- int k = 0;
- bool fFirstTyParam = true;
- while (k < typars.Length)
- {
- if (!fFirstTyParam)
- sb.Append(',');
- else
- fFirstTyParam = false;
-
- sb.Append(typars[k].Name);
- k++;
- }
- sb.Append(']');
- }
-
- ParameterInfo[]? pi = null;
- try
- {
- pi = mb.GetParameters();
- }
- catch
- {
- // The parameter info cannot be loaded, so we don't
- // append the parameter list.
- }
- if (pi != null)
- {
- // arguments printing
- sb.Append('(');
- bool fFirstParam = true;
- for (int j = 0; j < pi.Length; j++)
- {
- if (!fFirstParam)
- sb.Append(", ");
- else
- fFirstParam = false;
-
- string typeName = "<UnknownType>";
- if (pi[j].ParameterType != null)
- typeName = pi[j].ParameterType.Name;
- sb.Append(typeName);
- sb.Append(' ');
- sb.Append(pi[j].Name);
- }
- sb.Append(')');
- }
-
- if (methodChanged)
- {
- // Append original method name e.g. +MoveNext()
- sb.Append('+');
- sb.Append(methodName);
- sb.Append('(').Append(')');
- }
-
- // source location printing
- if (sf!.GetILOffset() != -1)
- {
- // If we don't have a PDB or PDB-reading is disabled for the module,
- // then the file name will be null.
- string? fileName = sf.GetFileName();
-
- if (fileName != null)
- {
- // tack on " in c:\tmp\MyFile.cs:line 5"
- sb.Append(' ');
- sb.AppendFormat(CultureInfo.InvariantCulture, inFileLineNum, fileName, sf.GetFileLineNumber());
- }
- }
-
- // Skip EDI boundary for async
- if (sf.IsLastFrameFromForeignExceptionStackTrace && !isAsync)
- {
- sb.AppendLine();
- sb.Append(SR.Exception_EndStackTraceFromPreviousThrow);
- }
- }
- }
-
- if (traceFormat == TraceFormat.TrailingNewLine)
- sb.AppendLine();
- }
-#endif // !CORERT
-
- private static bool ShowInStackTrace(MethodBase mb)
- {
- Debug.Assert(mb != null);
-
- if ((mb.MethodImplementationFlags & MethodImplAttributes.AggressiveInlining) != 0)
- {
- // Aggressive Inlines won't normally show in the StackTrace; however for Tier0 Jit and
- // cross-assembly AoT/R2R these inlines will be blocked until Tier1 Jit re-Jits
- // them when they will inline. We don't show them in the StackTrace to bring consistency
- // between this first-pass asm and fully optimized asm.
- return false;
- }
-
- if (mb.IsDefined(typeof(StackTraceHiddenAttribute), inherit: false))
- {
- // Don't show where StackTraceHidden is applied to the method.
- return false;
- }
-
- Type? declaringType = mb.DeclaringType;
- // Methods don't always have containing types, for example dynamic RefEmit generated methods.
- if (declaringType != null &&
- declaringType.IsDefined(typeof(StackTraceHiddenAttribute), inherit: false))
- {
- // Don't show where StackTraceHidden is applied to the containing Type of the method.
- return false;
- }
-
- return true;
- }
-
- private static bool TryResolveStateMachineMethod(ref MethodBase method, out Type declaringType)
- {
- Debug.Assert(method != null);
- Debug.Assert(method.DeclaringType != null);
-
- declaringType = method.DeclaringType;
-
- Type? parentType = declaringType.DeclaringType;
- if (parentType == null)
- {
- return false;
- }
-
- MethodInfo[]? methods = parentType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
- if (methods == null)
- {
- return false;
- }
-
- foreach (MethodInfo candidateMethod in methods)
- {
- IEnumerable<StateMachineAttribute>? attributes = candidateMethod.GetCustomAttributes<StateMachineAttribute>(inherit: false);
- if (attributes == null)
- {
- continue;
- }
-
- bool foundAttribute = false, foundIteratorAttribute = false;
- foreach (StateMachineAttribute asma in attributes)
- {
- if (asma.StateMachineType == declaringType)
- {
- foundAttribute = true;
- foundIteratorAttribute |= asma is IteratorStateMachineAttribute || asma is AsyncIteratorStateMachineAttribute;
- }
- }
-
- if (foundAttribute)
- {
- // If this is an iterator (sync or async), mark the iterator as changed, so it gets the + annotation
- // of the original method. Non-iterator async state machines resolve directly to their builder methods
- // so aren't marked as changed.
- method = candidateMethod;
- declaringType = candidateMethod.DeclaringType!;
- return foundIteratorAttribute;
- }
- }
-
- return false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/StackTraceHiddenAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/StackTraceHiddenAttribute.cs
deleted file mode 100644
index 474274ac085..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/StackTraceHiddenAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Diagnostics
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)]
- internal sealed class StackTraceHiddenAttribute : Attribute
- {
- public StackTraceHiddenAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.Unix.cs
deleted file mode 100644
index 13beddde046..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.Unix.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Diagnostics
-{
- public partial class Stopwatch
- {
- private static long QueryPerformanceFrequency()
- {
- return (long)Interop.Sys.GetTimestampResolution();
- }
-
- private static long QueryPerformanceCounter()
- {
- return (long)Interop.Sys.GetTimestamp();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.Windows.cs
deleted file mode 100644
index 20f5656cbf1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.Windows.cs
+++ /dev/null
@@ -1,31 +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.
-
-namespace System.Diagnostics
-{
- public partial class Stopwatch
- {
- private static unsafe long QueryPerformanceFrequency()
- {
- long resolution;
-
- Interop.BOOL result = Interop.Kernel32.QueryPerformanceFrequency(&resolution);
- // The P/Invoke is documented to never fail on Windows XP or later
- Debug.Assert(result != Interop.BOOL.FALSE);
-
- return resolution;
- }
-
- private static unsafe long QueryPerformanceCounter()
- {
- long timestamp;
-
- Interop.BOOL result = Interop.Kernel32.QueryPerformanceCounter(&timestamp);
- // The P/Invoke is documented to never fail on Windows XP or later
- Debug.Assert(result != Interop.BOOL.FALSE);
-
- return timestamp;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.cs
deleted file mode 100644
index 3b7c0bac5c9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Stopwatch.cs
+++ /dev/null
@@ -1,142 +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.
-
-namespace System.Diagnostics
-{
- // This class uses high-resolution performance counter if the installed
- // hardware supports it. Otherwise, the class will fall back to DateTime
- // and uses ticks as a measurement.
-
- public partial class Stopwatch
- {
- private const long TicksPerMillisecond = 10000;
- private const long TicksPerSecond = TicksPerMillisecond * 1000;
-
- private long _elapsed;
- private long _startTimeStamp;
- private bool _isRunning;
-
- // "Frequency" stores the frequency of the high-resolution performance counter,
- // if one exists. Otherwise it will store TicksPerSecond.
- // The frequency cannot change while the system is running,
- // so we only need to initialize it once.
- public static readonly long Frequency = QueryPerformanceFrequency();
- public static readonly bool IsHighResolution = true;
-
- // performance-counter frequency, in counts per ticks.
- // This can speed up conversion from high frequency performance-counter
- // to ticks.
- private static readonly double s_tickFrequency = (double)TicksPerSecond / Frequency;
-
- public Stopwatch()
- {
- Reset();
- }
-
- public void Start()
- {
- // Calling start on a running Stopwatch is a no-op.
- if (!_isRunning)
- {
- _startTimeStamp = GetTimestamp();
- _isRunning = true;
- }
- }
-
- public static Stopwatch StartNew()
- {
- Stopwatch s = new Stopwatch();
- s.Start();
- return s;
- }
-
- public void Stop()
- {
- // Calling stop on a stopped Stopwatch is a no-op.
- if (_isRunning)
- {
- long endTimeStamp = GetTimestamp();
- long elapsedThisPeriod = endTimeStamp - _startTimeStamp;
- _elapsed += elapsedThisPeriod;
- _isRunning = false;
-
- if (_elapsed < 0)
- {
- // When measuring small time periods the Stopwatch.Elapsed*
- // properties can return negative values. This is due to
- // bugs in the basic input/output system (BIOS) or the hardware
- // abstraction layer (HAL) on machines with variable-speed CPUs
- // (e.g. Intel SpeedStep).
-
- _elapsed = 0;
- }
- }
- }
-
- public void Reset()
- {
- _elapsed = 0;
- _isRunning = false;
- _startTimeStamp = 0;
- }
-
- // Convenience method for replacing {sw.Reset(); sw.Start();} with a single sw.Restart()
- public void Restart()
- {
- _elapsed = 0;
- _startTimeStamp = GetTimestamp();
- _isRunning = true;
- }
-
- public bool IsRunning
- {
- get { return _isRunning; }
- }
-
- public TimeSpan Elapsed
- {
- get { return new TimeSpan(GetElapsedDateTimeTicks()); }
- }
-
- public long ElapsedMilliseconds
- {
- get { return GetElapsedDateTimeTicks() / TicksPerMillisecond; }
- }
-
- public long ElapsedTicks
- {
- get { return GetRawElapsedTicks(); }
- }
-
- public static long GetTimestamp()
- {
- Debug.Assert(IsHighResolution);
- return QueryPerformanceCounter();
- }
-
- // Get the elapsed ticks.
- private long GetRawElapsedTicks()
- {
- long timeElapsed = _elapsed;
-
- if (_isRunning)
- {
- // If the Stopwatch is running, add elapsed time since
- // the Stopwatch is started last time.
- long currentTimeStamp = GetTimestamp();
- long elapsedUntilNow = currentTimeStamp - _startTimeStamp;
- timeElapsed += elapsedUntilNow;
- }
- return timeElapsed;
- }
-
- // Get the elapsed ticks.
- private long GetElapsedDateTimeTicks()
- {
- Debug.Assert(IsHighResolution);
- // convert high resolution perf counter to DateTime ticks
- return unchecked((long)(GetRawElapsedTicks() * s_tickFrequency));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/SymbolStore/ISymbolDocumentWriter.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/SymbolStore/ISymbolDocumentWriter.cs
deleted file mode 100644
index 4980ed76f6c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/SymbolStore/ISymbolDocumentWriter.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Diagnostics.SymbolStore
-{
- public interface ISymbolDocumentWriter
- {
- void SetCheckSum(Guid algorithmId, byte[] checkSum);
- void SetSource(byte[] source);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/ActivityTracker.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/ActivityTracker.cs
deleted file mode 100644
index 07c2112878f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/ActivityTracker.cs
+++ /dev/null
@@ -1,663 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#else
-using System.Threading.Tasks;
-#endif
-using System.Threading;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Tracks activities. This is meant to be a singleton (accessed by the ActivityTracer.Instance static property)
- ///
- /// Logically this is simply holds the m_current variable that holds the async local that holds the current ActivityInfo
- /// An ActivityInfo is represents a activity (which knows its creator and thus knows its path).
- ///
- /// Most of the magic is in the async local (it gets copied to new tasks)
- ///
- /// On every start event call OnStart
- ///
- /// Guid activityID;
- /// Guid relatedActivityID;
- /// if (OnStart(activityName, out activityID, out relatedActivityID, ForceStop, options))
- /// // Log Start event with activityID and relatedActivityID
- ///
- /// On every stop event call OnStop
- ///
- /// Guid activityID;
- /// if (OnStop(activityName, ref activityID ForceStop))
- /// // Stop event with activityID
- ///
- /// On any normal event log the event with activityTracker.CurrentActivityId
- /// </summary>
- internal class ActivityTracker
- {
- /// <summary>
- /// Called on work item begins. The activity name = providerName + activityName without 'Start' suffix.
- /// It updates CurrentActivityId to track.
- ///
- /// It returns true if the Start should be logged, otherwise (if it is illegal recursion) it return false.
- ///
- /// The start event should use as its activity ID the CurrentActivityId AFTER calling this routine and its
- /// RelatedActivityID the CurrentActivityId BEFORE calling this routine (the creator).
- ///
- /// If activity tracing is not on, then activityId and relatedActivityId are not set
- /// </summary>
- public void OnStart(string providerName, string activityName, int task, ref Guid activityId, ref Guid relatedActivityId, EventActivityOptions options, bool useTplSource = true)
- {
- if (m_current == null) // We are not enabled
- {
- // We used to rely on the TPL provider turning us on, but that has the disadvantage that you don't get Start-Stop tracking
- // until you use Tasks for the first time (which you may never do). Thus we change it to pull rather tan push for whether
- // we are enabled.
- if (m_checkedForEnable)
- return;
- m_checkedForEnable = true;
- if (useTplSource && TplEventSource.Log.IsEnabled(EventLevel.Informational, TplEventSource.Keywords.TasksFlowActivityIds))
- Enable();
- if (m_current == null)
- return;
- }
-
- Debug.Assert((options & EventActivityOptions.Disable) == 0);
-
- ActivityInfo? currentActivity = m_current.Value;
- string fullActivityName = NormalizeActivityName(providerName, activityName, task);
-
- TplEventSource? log = useTplSource ? TplEventSource.Log : null;
- bool tplDebug = log != null && log.Debug;
- if (tplDebug)
- {
- log!.DebugFacilityMessage("OnStartEnter", fullActivityName);
- log!.DebugFacilityMessage("OnStartEnterActivityState", ActivityInfo.LiveActivities(currentActivity));
- }
-
- if (currentActivity != null)
- {
- // Stop activity tracking if we reached the maximum allowed depth
- if (currentActivity.m_level >= MAX_ACTIVITY_DEPTH)
- {
- activityId = Guid.Empty;
- relatedActivityId = Guid.Empty;
- if (tplDebug)
- log!.DebugFacilityMessage("OnStartRET", "Fail");
- return;
- }
- // Check for recursion, and force-stop any activities if the activity already started.
- if ((options & EventActivityOptions.Recursive) == 0)
- {
- ActivityInfo? existingActivity = FindActiveActivity(fullActivityName, currentActivity);
- if (existingActivity != null)
- {
- OnStop(providerName, activityName, task, ref activityId);
- currentActivity = m_current.Value;
- }
- }
- }
-
- // Get a unique ID for this activity.
- long id;
- if (currentActivity == null)
- id = Interlocked.Increment(ref m_nextId);
- else
- id = Interlocked.Increment(ref currentActivity.m_lastChildID);
-
- // The previous ID is my 'causer' and becomes my related activity ID
- relatedActivityId = EventSource.CurrentThreadActivityId;
-
- // Add to the list of started but not stopped activities.
- ActivityInfo newActivity = new ActivityInfo(fullActivityName, id, currentActivity, relatedActivityId, options);
- m_current.Value = newActivity;
-
- // Remember the current ID so we can log it
- activityId = newActivity.ActivityId;
-
- if (tplDebug)
- {
- log!.DebugFacilityMessage("OnStartRetActivityState", ActivityInfo.LiveActivities(newActivity));
- log!.DebugFacilityMessage1("OnStartRet", activityId.ToString(), relatedActivityId.ToString());
- }
- }
-
- /// <summary>
- /// Called when a work item stops. The activity name = providerName + activityName without 'Stop' suffix.
- /// It updates m_current variable to track this fact. The Stop event associated with stop should log the ActivityID associated with the event.
- ///
- /// If activity tracing is not on, then activityId and relatedActivityId are not set
- /// </summary>
- public void OnStop(string providerName, string activityName, int task, ref Guid activityId, bool useTplSource = true)
- {
- if (m_current == null) // We are not enabled
- return;
-
- string fullActivityName = NormalizeActivityName(providerName, activityName, task);
-
- TplEventSource? log = useTplSource ? TplEventSource.Log : null;
- bool tplDebug = log != null && log.Debug;
- if (tplDebug)
- {
- log!.DebugFacilityMessage("OnStopEnter", fullActivityName);
- log!.DebugFacilityMessage("OnStopEnterActivityState", ActivityInfo.LiveActivities(m_current.Value));
- }
-
- while (true) // This is a retry loop.
- {
- ActivityInfo? currentActivity = m_current.Value;
- ActivityInfo? newCurrentActivity = null; // if we have seen any live activities (orphans), at he first one we have seen.
-
- // Search to find the activity to stop in one pass. This insures that we don't let one mistake
- // (stopping something that was not started) cause all active starts to be stopped
- // By first finding the target start to stop we are more robust.
- ActivityInfo? activityToStop = FindActiveActivity(fullActivityName, currentActivity);
-
- // ignore stops where we can't find a start because we may have popped them previously.
- if (activityToStop == null)
- {
- activityId = Guid.Empty;
- // TODO add some logging about this. Basically could not find matching start.
- if (tplDebug)
- log!.DebugFacilityMessage("OnStopRET", "Fail");
- return;
- }
-
- activityId = activityToStop.ActivityId;
-
- // See if there are any orphans that need to be stopped.
- ActivityInfo? orphan = currentActivity;
- while (orphan != activityToStop && orphan != null)
- {
- if (orphan.m_stopped != 0) // Skip dead activities.
- {
- orphan = orphan.m_creator;
- continue;
- }
- if (orphan.CanBeOrphan())
- {
- // We can't pop anything after we see a valid orphan, remember this for later when we update m_current.
- newCurrentActivity ??= orphan;
- }
- else
- {
- orphan.m_stopped = 1;
- Debug.Assert(orphan.m_stopped != 0);
- }
- orphan = orphan.m_creator;
- }
-
- // try to Stop the activity atomically. Other threads may be trying to do this as well.
- if (Interlocked.CompareExchange(ref activityToStop.m_stopped, 1, 0) == 0)
- {
- // I succeeded stopping this activity. Now we update our m_current pointer
-
- // If I haven't yet determined the new current activity, it is my creator.
- newCurrentActivity ??= activityToStop.m_creator;
-
- m_current.Value = newCurrentActivity;
-
- if (tplDebug)
- {
- log!.DebugFacilityMessage("OnStopRetActivityState", ActivityInfo.LiveActivities(newCurrentActivity));
- log!.DebugFacilityMessage("OnStopRet", activityId.ToString());
- }
- return;
- }
- // We failed to stop it. We must have hit a race to stop it. Just start over and try again.
- }
- }
-
- /// <summary>
- /// Turns on activity tracking. It is sticky, once on it stays on (race issues otherwise)
- /// </summary>
- public void Enable()
- {
- if (m_current == null)
- {
- // Catch the not Implemented
- try
- {
- m_current = new AsyncLocal<ActivityInfo?>(ActivityChanging);
- }
- catch (NotImplementedException)
- {
-#if (!ES_BUILD_PCL && !ES_BUILD_PN)
- // send message to debugger without delay
- System.Diagnostics.Debugger.Log(0, null, "Activity Enabled() called but AsyncLocals Not Supported (pre V4.6). Ignoring Enable");
-#endif
- }
- }
- }
-
- /// <summary>
- /// An activity tracker is a singleton, this is how you get the one and only instance.
- /// </summary>
- public static ActivityTracker Instance => s_activityTrackerInstance;
-
- #region private
-
- /// <summary>
- /// Searched for a active (nonstopped) activity with the given name. Returns null if not found.
- /// </summary>
- private static ActivityInfo? FindActiveActivity(string name, ActivityInfo? startLocation)
- {
- ActivityInfo? activity = startLocation;
- while (activity != null)
- {
- if (name == activity.m_name && activity.m_stopped == 0)
- return activity;
- activity = activity.m_creator;
- }
- return null;
- }
-
- /// <summary>
- /// Strip out "Start" or "End" suffix from activity name and add providerName prefix.
- /// If 'task' it does not end in Start or Stop and Task is non-zero use that as the name of the activity
- /// </summary>
- private static string NormalizeActivityName(string providerName, string activityName, int task)
- {
- // We use provider name to distinguish between activities from different providers.
-
- if (activityName.EndsWith(EventSource.s_ActivityStartSuffix, StringComparison.Ordinal))
- {
-#if ES_BUILD_STANDALONE
- return string.Concat(providerName, activityName.Substring(0, activityName.Length - EventSource.s_ActivityStartSuffix.Length));
-#else
- return string.Concat(providerName, activityName.AsSpan(0, activityName.Length - EventSource.s_ActivityStartSuffix.Length));
-#endif
- }
- else if (activityName.EndsWith(EventSource.s_ActivityStopSuffix, StringComparison.Ordinal))
- {
-#if ES_BUILD_STANDALONE
- return string.Concat(providerName, activityName.Substring(0, activityName.Length - EventSource.s_ActivityStopSuffix.Length));
-#else
- return string.Concat(providerName, activityName.AsSpan(0, activityName.Length - EventSource.s_ActivityStopSuffix.Length));
-#endif
- }
- else if (task != 0)
- {
- return providerName + "task" + task.ToString();
- }
- else
- {
- return providerName + activityName;
- }
- }
-
- // *******************************************************************************
- /// <summary>
- /// An ActivityInfo represents a particular activity. It is almost read-only. The only
- /// fields that change after creation are
- /// m_lastChildID - used to generate unique IDs for the children activities and for the most part can be ignored.
- /// m_stopped - indicates that this activity is dead
- /// This read-only-ness is important because an activity's m_creator chain forms the
- /// 'Path of creation' for the activity (which is also its unique ID) but is also used as
- /// the 'list of live parents' which indicate of those ancestors, which are alive (if they
- /// are not marked dead they are alive).
- /// </summary>
- private class ActivityInfo
- {
- public ActivityInfo(string name, long uniqueId, ActivityInfo? creator, Guid activityIDToRestore, EventActivityOptions options)
- {
- m_name = name;
- m_eventOptions = options;
- m_creator = creator;
- m_uniqueId = uniqueId;
- m_level = creator != null ? creator.m_level + 1 : 0;
- m_activityIdToRestore = activityIDToRestore;
-
- // Create a nice GUID that encodes the chain of activities that started this one.
- CreateActivityPathGuid(out m_guid, out m_activityPathGuidOffset);
- }
-
- public Guid ActivityId => m_guid;
-
- public static string Path(ActivityInfo? activityInfo)
- {
- if (activityInfo == null)
- return "";
- return Path(activityInfo.m_creator) + "/" + activityInfo.m_uniqueId.ToString();
- }
-
- public override string ToString()
- {
- return m_name + "(" + Path(this) + (m_stopped != 0 ? ",DEAD)" : ")");
- }
-
- public static string LiveActivities(ActivityInfo? list)
- {
- if (list == null)
- return "";
- return list.ToString() + ";" + LiveActivities(list.m_creator);
- }
-
- public bool CanBeOrphan()
- {
- if ((m_eventOptions & EventActivityOptions.Detachable) != 0)
- return true;
- return false;
- }
-
- #region private
-
- #region CreateActivityPathGuid
- /// <summary>
- /// Logically every activity Path (see Path()) that describes the activities that caused this
- /// (rooted in an activity that predates activity tracking.
- ///
- /// We wish to encode this path in the Guid to the extent that we can. Many of the paths have
- /// many small numbers in them and we take advantage of this in the encoding to output as long
- /// a path in the GUID as possible.
- ///
- /// Because of the possibility of GUID collision, we only use 96 of the 128 bits of the GUID
- /// for encoding the path. The last 32 bits are a simple checksum (and random number) that
- /// identifies this as using the convention defined here.
- ///
- /// It returns both the GUID which has the path as well as the offset that points just beyond
- /// the end of the activity (so it can be appended to). Note that if the end is in a nibble
- /// (it uses nibbles instead of bytes as the unit of encoding, then it will point at the unfinished
- /// byte (since the top nibble can't be zero you can determine if this is true by seeing if
- /// this byte is nonZero. This offset is needed to efficiently create the ID for child activities.
- /// </summary>
- private unsafe void CreateActivityPathGuid(out Guid idRet, out int activityPathGuidOffset)
- {
- fixed (Guid* outPtr = &idRet)
- {
- int activityPathGuidOffsetStart = 0;
- if (m_creator != null)
- {
- activityPathGuidOffsetStart = m_creator.m_activityPathGuidOffset;
- idRet = m_creator.m_guid;
- }
- else
- {
- // TODO FIXME - differentiate between AD inside PCL
- int appDomainID = 0;
-#if (!ES_BUILD_STANDALONE && !ES_BUILD_PN)
- appDomainID = System.Threading.Thread.GetDomainID();
-#endif
- // We start with the appdomain number to make this unique among appdomains.
- activityPathGuidOffsetStart = AddIdToGuid(outPtr, activityPathGuidOffsetStart, (uint)appDomainID);
- }
-
- activityPathGuidOffset = AddIdToGuid(outPtr, activityPathGuidOffsetStart, (uint)m_uniqueId);
-
- // If the path does not fit, Make a GUID by incrementing rather than as a path, keeping as much of the path as possible
- if (12 < activityPathGuidOffset)
- CreateOverflowGuid(outPtr);
- }
- }
-
- /// <summary>
- /// If we can't fit the activity Path into the GUID we come here. What we do is simply
- /// generate a 4 byte number (s_nextOverflowId). Then look for an ancestor that has
- /// sufficient space for this ID. By doing this, we preserve the fact that this activity
- /// is a child (of unknown depth) from that ancestor.
- /// </summary>
- private unsafe void CreateOverflowGuid(Guid* outPtr)
- {
- // Search backwards for an ancestor that has sufficient space to put the ID.
- for (ActivityInfo? ancestor = m_creator; ancestor != null; ancestor = ancestor.m_creator)
- {
- if (ancestor.m_activityPathGuidOffset <= 10) // we need at least 2 bytes.
- {
- uint id = unchecked((uint)Interlocked.Increment(ref ancestor.m_lastChildID)); // Get a unique ID
- // Try to put the ID into the GUID
- *outPtr = ancestor.m_guid;
- int endId = AddIdToGuid(outPtr, ancestor.m_activityPathGuidOffset, id, true);
-
- // Does it fit?
- if (endId <= 12)
- break;
- }
- }
- }
-
- /// <summary>
- /// The encoding for a list of numbers used to make Activity GUIDs. Basically
- /// we operate on nibbles (which are nice because they show up as hex digits). The
- /// list is ended with a end nibble (0) and depending on the nibble value (Below)
- /// the value is either encoded into nibble itself or it can spill over into the
- /// bytes that follow.
- /// </summary>
- private enum NumberListCodes : byte
- {
- End = 0x0, // ends the list. No valid value has this prefix.
- LastImmediateValue = 0xA,
-
- PrefixCode = 0xB, // all the 'long' encodings go here. If the next nibble is MultiByte1-4
- // than this is a 'overflow' id. Unlike the hierarchical IDs these are
- // allocated densely but don't tell you anything about nesting. we use
- // these when we run out of space in the GUID to store the path.
-
- MultiByte1 = 0xC, // 1 byte follows. If this Nibble is in the high bits, it the high bits of the number are stored in the low nibble.
- // commented out because the code does not explicitly reference the names (but they are logically defined).
- // MultiByte2 = 0xD, // 2 bytes follow (we don't bother with the nibble optimization)
- // MultiByte3 = 0xE, // 3 bytes follow (we don't bother with the nibble optimization)
- // MultiByte4 = 0xF, // 4 bytes follow (we don't bother with the nibble optimization)
- }
-
- /// Add the activity id 'id' to the output Guid 'outPtr' starting at the offset 'whereToAddId'
- /// Thus if this number is 6 that is where 'id' will be added. This will return 13 (12
- /// is the maximum number of bytes that fit in a GUID) if the path did not fit.
- /// If 'overflow' is true, then the number is encoded as an 'overflow number (which has a
- /// special (longer prefix) that indicates that this ID is allocated differently
- private static unsafe int AddIdToGuid(Guid* outPtr, int whereToAddId, uint id, bool overflow = false)
- {
- byte* ptr = (byte*)outPtr;
- byte* endPtr = ptr + 12;
- ptr += whereToAddId;
- if (endPtr <= ptr)
- return 13; // 12 means we might exactly fit, 13 means we definitely did not fit
-
- if (0 < id && id <= (uint)NumberListCodes.LastImmediateValue && !overflow)
- WriteNibble(ref ptr, endPtr, id);
- else
- {
- uint len = 4;
- if (id <= 0xFF)
- len = 1;
- else if (id <= 0xFFFF)
- len = 2;
- else if (id <= 0xFFFFFF)
- len = 3;
-
- if (overflow)
- {
- if (endPtr <= ptr + 2) // I need at least 2 bytes
- return 13;
-
- // Write out the prefix code nibble and the length nibble
- WriteNibble(ref ptr, endPtr, (uint)NumberListCodes.PrefixCode);
- }
- // The rest is the same for overflow and non-overflow case
- WriteNibble(ref ptr, endPtr, (uint)NumberListCodes.MultiByte1 + (len - 1));
-
- // Do we have an odd nibble? If so flush it or use it for the 12 byte case.
- if (ptr < endPtr && *ptr != 0)
- {
- // If the value < 4096 we can use the nibble we are otherwise just outputting as padding.
- if (id < 4096)
- {
- // Indicate this is a 1 byte multicode with 4 high order bits in the lower nibble.
- *ptr = (byte)(((uint)NumberListCodes.MultiByte1 << 4) + (id >> 8));
- id &= 0xFF; // Now we only want the low order bits.
- }
- ptr++;
- }
-
- // Write out the bytes.
- while (0 < len)
- {
- if (endPtr <= ptr)
- {
- ptr++; // Indicate that we have overflowed
- break;
- }
- *ptr++ = (byte)id;
- id >>= 8;
- --len;
- }
- }
-
- // Compute the checksum
- uint* sumPtr = (uint*)outPtr;
- // We set the last DWORD the sum of the first 3 DWORDS in the GUID. This
- // This last number is a random number (it identifies us as us) the process ID to make it unique per process.
- sumPtr[3] = (sumPtr[0] + sumPtr[1] + sumPtr[2] + 0x599D99AD) ^ EventSource.s_currentPid;
-
- return (int)(ptr - ((byte*)outPtr));
- }
-
- /// <summary>
- /// Write a single Nible 'value' (must be 0-15) to the byte buffer represented by *ptr.
- /// Will not go past 'endPtr'. Also it assumes that we never write 0 so we can detect
- /// whether a nibble has already been written to ptr because it will be nonzero.
- /// Thus if it is non-zero it adds to the current byte, otherwise it advances and writes
- /// the new byte (in the high bits) of the next byte.
- /// </summary>
- private static unsafe void WriteNibble(ref byte* ptr, byte* endPtr, uint value)
- {
- Debug.Assert(value < 16);
- Debug.Assert(ptr < endPtr);
-
- if (*ptr != 0)
- *ptr++ |= (byte)value;
- else
- *ptr = (byte)(value << 4);
- }
-
- #endregion // CreateGuidForActivityPath
-
- internal readonly string m_name; // The name used in the 'start' and 'stop' APIs to help match up
- private readonly long m_uniqueId; // a small number that makes this activity unique among its siblings
- internal readonly Guid m_guid; // Activity Guid, it is basically an encoding of the Path() (see CreateActivityPathGuid)
- internal readonly int m_activityPathGuidOffset; // Keeps track of where in m_guid the causality path stops (used to generated child GUIDs)
- internal readonly int m_level; // current depth of the Path() of the activity (used to keep recursion under control)
- internal readonly EventActivityOptions m_eventOptions; // Options passed to start.
- internal long m_lastChildID; // used to create a unique ID for my children activities
- internal int m_stopped; // This work item has stopped
- internal readonly ActivityInfo? m_creator; // My parent (creator). Forms the Path() for the activity.
- internal readonly Guid m_activityIdToRestore; // The Guid to restore after a stop.
- #endregion
- }
-
- // This callback is used to initialize the m_current AsyncLocal Variable.
- // Its job is to keep the ETW Activity ID (part of thread local storage) in sync
- // with m_current.ActivityID
- private void ActivityChanging(AsyncLocalValueChangedArgs<ActivityInfo?> args)
- {
- ActivityInfo? cur = args.CurrentValue;
- ActivityInfo? prev = args.PreviousValue;
-
- // Are we popping off a value? (we have a prev, and it creator is cur)
- // Then check if we should use the GUID at the time of the start event
- if (prev != null && prev.m_creator == cur)
- {
- // If the saved activity ID is not the same as the creator activity
- // that takes precedence (it means someone explicitly did a SetActivityID)
- // Set it to that and get out
- if (cur == null || prev.m_activityIdToRestore != cur.ActivityId)
- {
- EventSource.SetCurrentThreadActivityId(prev.m_activityIdToRestore);
- return;
- }
- }
-
- // OK we did not have an explicit SetActivityID set. Then we should be
- // setting the activity to current ActivityInfo. However that activity
- // might be dead, in which case we should skip it, so we never set
- // the ID to dead things.
- while (cur != null)
- {
- // We found a live activity (typically the first time), set it to that.
- if (cur.m_stopped == 0)
- {
- EventSource.SetCurrentThreadActivityId(cur.ActivityId);
- return;
- }
- cur = cur.m_creator;
- }
- // we can get here if there is no information on our activity stack (everything is dead)
- // currently we do nothing, as that seems better than setting to Guid.Emtpy.
- }
-
- /// <summary>
- /// Async local variables have the property that the are automatically copied whenever a task is created and used
- /// while that task is running. Thus m_current 'flows' to any task that is caused by the current thread that
- /// last set it.
- ///
- /// This variable points to a linked list that represents all Activities that have started but have not stopped.
- /// </summary>
- private AsyncLocal<ActivityInfo?>? m_current;
- private bool m_checkedForEnable;
-
- // Singleton
- private static readonly ActivityTracker s_activityTrackerInstance = new ActivityTracker();
-
- // Used to create unique IDs at the top level. Not used for nested Ids (each activity has its own id generator)
- private static long m_nextId = 0;
- private const ushort MAX_ACTIVITY_DEPTH = 100; // Limit maximum depth of activities to be tracked at 100.
- // This will avoid leaking memory in case of activities that are never stopped.
-
- #endregion
- }
-
-#if ES_BUILD_STANDALONE
- /******************************** SUPPORT *****************************/
- /// <summary>
- /// This is supplied by the framework. It is has the semantics that the value is copied to any new Tasks that is created
- /// by the current task. Thus all causally related code gets this value. Note that reads and writes to this VARIABLE
- /// (not what it points it) to this does not need to be protected by locks because it is inherently thread local (you always
- /// only get your thread local copy which means that you never have races.
- /// </summary>
- ///
- [EventSource(Name = "Microsoft.Tasks.Nuget")]
- internal class TplEventSource : EventSource
- {
- public class Keywords
- {
- public const EventKeywords TasksFlowActivityIds = (EventKeywords)0x80;
- public const EventKeywords Debug = (EventKeywords)0x20000;
- }
-
- public static TplEventSource Log = new TplEventSource();
- public bool Debug { get { return IsEnabled(EventLevel.Verbose, Keywords.Debug); } }
-
- public void DebugFacilityMessage(string Facility, string Message) { WriteEvent(1, Facility, Message); }
- public void DebugFacilityMessage1(string Facility, string Message, string Arg) { WriteEvent(2, Facility, Message, Arg); }
- public void SetActivityId(Guid Id) { WriteEvent(3, Id); }
- }
-#endif
-
-#if ES_BUILD_AGAINST_DOTNET_V35 || ES_BUILD_PCL || NO_ASYNC_LOCAL
- // In these cases we don't have any Async local support. Do nothing.
- internal sealed class AsyncLocalValueChangedArgs<T>
- {
- public T PreviousValue { get { return default(T); } }
- public T CurrentValue { get { return default(T); } }
-
- }
-
- internal sealed class AsyncLocal<T>
- {
- public AsyncLocal(Action<AsyncLocalValueChangedArgs<T>> valueChangedHandler) {
- throw new NotImplementedException("AsyncLocal only available on V4.6 and above");
- }
- public T Value
- {
- get { return default(T); }
- set { }
- }
- }
-#endif
-
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterGroup.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterGroup.cs
deleted file mode 100644
index e4086d1d6e2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterGroup.cs
+++ /dev/null
@@ -1,263 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-using System.Collections.Generic;
-using System.Threading;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- internal class CounterGroup
- {
- private readonly EventSource _eventSource;
- private readonly List<DiagnosticCounter> _counters;
- private static readonly object s_counterGroupLock = new object();
-
- internal CounterGroup(EventSource eventSource)
- {
- _eventSource = eventSource;
- _counters = new List<DiagnosticCounter>();
- RegisterCommandCallback();
- }
-
- internal void Add(DiagnosticCounter eventCounter)
- {
- lock (s_counterGroupLock) // Lock the CounterGroup
- _counters.Add(eventCounter);
- }
-
- internal void Remove(DiagnosticCounter eventCounter)
- {
- lock (s_counterGroupLock) // Lock the CounterGroup
- _counters.Remove(eventCounter);
- }
-
-#region EventSource Command Processing
-
- private void RegisterCommandCallback()
- {
- _eventSource.EventCommandExecuted += OnEventSourceCommand;
- }
-
- private void OnEventSourceCommand(object? sender, EventCommandEventArgs e)
- {
- if (e.Command == EventCommand.Enable || e.Command == EventCommand.Update)
- {
- Debug.Assert(e.Arguments != null);
-
- if (e.Arguments.TryGetValue("EventCounterIntervalSec", out string? valueStr) && float.TryParse(valueStr, out float value))
- {
- lock (s_counterGroupLock) // Lock the CounterGroup
- {
- EnableTimer(value);
- }
- }
- }
- else if (e.Command == EventCommand.Disable)
- {
- lock (s_counterGroupLock)
- {
- DisableTimer();
- }
- }
- }
-
-#endregion // EventSource Command Processing
-
-#region Global CounterGroup Array management
-
- // We need eventCounters to 'attach' themselves to a particular EventSource.
- // this table provides the mapping from EventSource -> CounterGroup
- // which represents this 'attached' information.
- private static WeakReference<CounterGroup>[]? s_counterGroups;
-
- private static void EnsureEventSourceIndexAvailable(int eventSourceIndex)
- {
- Debug.Assert(Monitor.IsEntered(s_counterGroupLock));
- if (CounterGroup.s_counterGroups == null)
- {
- CounterGroup.s_counterGroups = new WeakReference<CounterGroup>[eventSourceIndex + 1];
- }
- else if (eventSourceIndex >= CounterGroup.s_counterGroups.Length)
- {
- WeakReference<CounterGroup>[] newCounterGroups = new WeakReference<CounterGroup>[eventSourceIndex + 1];
- Array.Copy(CounterGroup.s_counterGroups, newCounterGroups, CounterGroup.s_counterGroups.Length);
- CounterGroup.s_counterGroups = newCounterGroups;
- }
- }
-
- internal static CounterGroup GetCounterGroup(EventSource eventSource)
- {
- lock (s_counterGroupLock)
- {
- int eventSourceIndex = EventListener.EventSourceIndex(eventSource);
- EnsureEventSourceIndexAvailable(eventSourceIndex);
- Debug.Assert(s_counterGroups != null);
- WeakReference<CounterGroup> weakRef = CounterGroup.s_counterGroups[eventSourceIndex];
- CounterGroup? ret = null;
- if (weakRef == null || !weakRef.TryGetTarget(out ret))
- {
- ret = new CounterGroup(eventSource);
- CounterGroup.s_counterGroups[eventSourceIndex] = new WeakReference<CounterGroup>(ret);
- }
- return ret;
- }
- }
-
-#endregion // Global CounterGroup Array management
-
-#region Timer Processing
-
- private DateTime _timeStampSinceCollectionStarted;
- private int _pollingIntervalInMilliseconds;
- private DateTime _nextPollingTimeStamp;
-
- private void EnableTimer(float pollingIntervalInSeconds)
- {
- Debug.Assert(Monitor.IsEntered(s_counterGroupLock));
- if (pollingIntervalInSeconds <= 0)
- {
- _pollingIntervalInMilliseconds = 0;
- }
- else if (_pollingIntervalInMilliseconds == 0 || pollingIntervalInSeconds * 1000 < _pollingIntervalInMilliseconds)
- {
- _pollingIntervalInMilliseconds = (int)(pollingIntervalInSeconds * 1000);
- ResetCounters(); // Reset statistics for counters before we start the thread.
-
- _timeStampSinceCollectionStarted = DateTime.UtcNow;
- // Don't capture the current ExecutionContext and its AsyncLocals onto the timer causing them to live forever
- bool restoreFlow = false;
- try
- {
- if (!ExecutionContext.IsFlowSuppressed())
- {
- ExecutionContext.SuppressFlow();
- restoreFlow = true;
- }
-
- _nextPollingTimeStamp = DateTime.UtcNow + new TimeSpan(0, 0, (int)pollingIntervalInSeconds);
-
- // Create the polling thread and init all the shared state if needed
- if (s_pollingThread == null)
- {
- s_pollingThreadSleepEvent = new AutoResetEvent(false);
- s_counterGroupEnabledList = new List<CounterGroup>();
- s_pollingThread = new Thread(PollForValues) { IsBackground = true };
- s_pollingThread.Start();
- }
-
- if (!s_counterGroupEnabledList!.Contains(this))
- {
- s_counterGroupEnabledList.Add(this);
- }
-
- // notify the polling thread that the polling interval may have changed and the sleep should
- // be recomputed
- s_pollingThreadSleepEvent!.Set();
- }
- finally
- {
- // Restore the current ExecutionContext
- if (restoreFlow)
- ExecutionContext.RestoreFlow();
- }
- }
- }
-
- private void DisableTimer()
- {
- _pollingIntervalInMilliseconds = 0;
- s_counterGroupEnabledList?.Remove(this);
- }
-
- private void ResetCounters()
- {
- lock (s_counterGroupLock) // Lock the CounterGroup
- {
- foreach (DiagnosticCounter counter in _counters)
- {
- if (counter is IncrementingEventCounter ieCounter)
- {
- ieCounter.UpdateMetric();
- }
- else if (counter is IncrementingPollingCounter ipCounter)
- {
- ipCounter.UpdateMetric();
- }
- else if (counter is EventCounter eCounter)
- {
- eCounter.ResetStatistics();
- }
- }
- }
- }
-
- private void OnTimer()
- {
- Debug.Assert(Monitor.IsEntered(s_counterGroupLock));
- if (_eventSource.IsEnabled())
- {
- DateTime now = DateTime.UtcNow;
- TimeSpan elapsed = now - _timeStampSinceCollectionStarted;
-
- foreach (DiagnosticCounter counter in _counters)
- {
- counter.WritePayload((float)elapsed.TotalSeconds, _pollingIntervalInMilliseconds);
- }
- _timeStampSinceCollectionStarted = now;
-
- do
- {
- _nextPollingTimeStamp += new TimeSpan(0, 0, 0, 0, _pollingIntervalInMilliseconds);
- } while (_nextPollingTimeStamp <= now);
- }
- }
-
- private static Thread? s_pollingThread;
- // Used for sleeping for a certain amount of time while allowing the thread to be woken up
- private static AutoResetEvent? s_pollingThreadSleepEvent;
-
- private static List<CounterGroup>? s_counterGroupEnabledList;
-
- private static void PollForValues()
- {
- AutoResetEvent? sleepEvent = null;
- while (true)
- {
- int sleepDurationInMilliseconds = int.MaxValue;
- lock (s_counterGroupLock)
- {
- sleepEvent = s_pollingThreadSleepEvent;
- foreach (CounterGroup counterGroup in s_counterGroupEnabledList!)
- {
- DateTime now = DateTime.UtcNow;
- if (counterGroup._nextPollingTimeStamp < now + new TimeSpan(0, 0, 0, 0, 1))
- {
- counterGroup.OnTimer();
- }
-
- int millisecondsTillNextPoll = (int)((counterGroup._nextPollingTimeStamp - now).TotalMilliseconds);
- millisecondsTillNextPoll = Math.Max(1, millisecondsTillNextPoll);
- sleepDurationInMilliseconds = Math.Min(sleepDurationInMilliseconds, millisecondsTillNextPoll);
- }
- }
- if (sleepDurationInMilliseconds == int.MaxValue)
- {
- sleepDurationInMilliseconds = -1; // WaitOne uses -1 to mean infinite
- }
- sleepEvent?.WaitOne(sleepDurationInMilliseconds);
- }
- }
-
-#endregion // Timer Processing
-
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterPayload.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterPayload.cs
deleted file mode 100644
index d81fdafca31..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterPayload.cs
+++ /dev/null
@@ -1,130 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-using System.Collections;
-using System.Collections.Generic;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- [EventData]
- internal class CounterPayload : IEnumerable<KeyValuePair<string, object?>>
- {
- public string? Name { get; set; }
-
- public string? DisplayName { get; set; }
-
- public double Mean { get; set; }
-
- public double StandardDeviation { get; set; }
-
- public int Count { get; set; }
-
- public double Min { get; set; }
-
- public double Max { get; set; }
-
- public float IntervalSec { get; internal set; }
-
- public string? Series { get; set; }
-
- public string? CounterType { get; set; }
-
- public string? Metadata { get; set; }
-
- public string? DisplayUnits { get; set; }
-
-#region Implementation of the IEnumerable interface
-
- public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
- {
- return ForEnumeration.GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return ForEnumeration.GetEnumerator();
- }
-
- private IEnumerable<KeyValuePair<string, object?>> ForEnumeration
- {
- get
- {
- yield return new KeyValuePair<string, object?>("Name", Name);
- yield return new KeyValuePair<string, object?>("DisplayName", DisplayName);
- yield return new KeyValuePair<string, object?>("DisplayUnits", DisplayUnits);
- yield return new KeyValuePair<string, object?>("Mean", Mean);
- yield return new KeyValuePair<string, object?>("StandardDeviation", StandardDeviation);
- yield return new KeyValuePair<string, object?>("Count", Count);
- yield return new KeyValuePair<string, object?>("Min", Min);
- yield return new KeyValuePair<string, object?>("Max", Max);
- yield return new KeyValuePair<string, object?>("IntervalSec", IntervalSec);
- yield return new KeyValuePair<string, object?>("Series", $"Interval={IntervalSec}");
- yield return new KeyValuePair<string, object?>("CounterType", "Mean");
- yield return new KeyValuePair<string, object?>("Metadata", Metadata);
- }
- }
-
-#endregion // Implementation of the IEnumerable interface
- }
-
- [EventData]
- internal class IncrementingCounterPayload : IEnumerable<KeyValuePair<string, object?>>
- {
- public string? Name { get; set; }
-
- public string? DisplayName { get; set; }
-
- public string? DisplayRateTimeScale { get; set; }
-
- public double Increment { get; set; }
-
- public float IntervalSec { get; internal set; }
-
- public string? Metadata { get; set; }
-
- public string? Series { get; set; }
-
- public string? CounterType { get; set; }
-
- public string? DisplayUnits { get; set; }
-
-#region Implementation of the IEnumerable interface
-
- public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
- {
- return ForEnumeration.GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return ForEnumeration.GetEnumerator();
- }
-
- private IEnumerable<KeyValuePair<string, object?>> ForEnumeration
- {
- get
- {
- yield return new KeyValuePair<string, object?>("Name", Name);
- yield return new KeyValuePair<string, object?>("DisplayName", DisplayName);
- yield return new KeyValuePair<string, object?>("DisplayRateTimeScale", DisplayRateTimeScale);
- yield return new KeyValuePair<string, object?>("Increment", Increment);
- yield return new KeyValuePair<string, object?>("IntervalSec", IntervalSec);
- yield return new KeyValuePair<string, object?>("Series", $"Interval={IntervalSec}");
- yield return new KeyValuePair<string, object?>("CounterType", "Sum");
- yield return new KeyValuePair<string, object?>("Metadata", Metadata);
- yield return new KeyValuePair<string, object?>("DisplayUnits", DisplayUnits);
- }
- }
-
-#endregion // Implementation of the IEnumerable interface
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/DiagnosticCounter.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/DiagnosticCounter.cs
deleted file mode 100644
index 577e9f193f8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/DiagnosticCounter.cs
+++ /dev/null
@@ -1,168 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-using System.Collections.Generic;
-using System.Text;
-using System.Threading;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// DiagnosticCounter is an abstract class that serves as the parent class for various Counter* classes,
- /// namely EventCounter, PollingCounter, IncrementingEventCounter, and IncrementingPollingCounter.
- /// </summary>
- public abstract class DiagnosticCounter : IDisposable
- {
- /// <summary>
- /// All Counters live as long as the EventSource that they are attached to unless they are
- /// explicitly Disposed.
- /// </summary>
- /// <param name="name">The name.</param>
- /// <param name="eventSource">The event source.</param>
- internal DiagnosticCounter(string name, EventSource eventSource)
- {
- if (name == null)
- {
- throw new ArgumentNullException(nameof(Name));
- }
-
- if (eventSource == null)
- {
- throw new ArgumentNullException(nameof(EventSource));
- }
-
- Name = name;
- EventSource = eventSource;
- }
-
- /// <summary>Adds the counter to the set that the EventSource will report on.</summary>
- /// <remarks>
- /// Must only be invoked once, and only after the instance has been fully initialized.
- /// This should be invoked by a derived type's ctor as the last thing it does.
- /// </remarks>
- private protected void Publish()
- {
- Debug.Assert(_group is null);
- Debug.Assert(Name != null);
- Debug.Assert(EventSource != null);
-
- _group = CounterGroup.GetCounterGroup(EventSource);
- _group.Add(this);
- }
-
- /// <summary>
- /// Removes the counter from set that the EventSource will report on. After being disposed, this
- /// counter will do nothing and its resource will be reclaimed if all references to it are removed.
- /// If an EventCounter is not explicitly disposed it will be cleaned up automatically when the
- /// EventSource it is attached to dies.
- /// </summary>
- public void Dispose()
- {
- if (_group != null)
- {
- _group.Remove(this);
- _group = null;
- }
- }
-
- /// <summary>
- /// Adds a key-value metadata to the EventCounter that will be included as a part of the payload
- /// </summary>
- public void AddMetadata(string key, string? value)
- {
- lock (this)
- {
- _metadata ??= new Dictionary<string, string?>();
- _metadata.Add(key, value);
- }
- }
-
- private string _displayName = "";
- public string DisplayName
- {
- get => _displayName;
- set
- {
- if (value == null)
- throw new ArgumentNullException(nameof(DisplayName));
- _displayName = value;
- }
- }
-
- private string _displayUnits = "";
- public string DisplayUnits
- {
- get => _displayUnits;
- set
- {
- if (value == null)
- throw new ArgumentNullException(nameof(DisplayUnits));
- _displayUnits = value;
- }
- }
-
- public string Name { get; }
-
- public EventSource EventSource { get; }
-
- #region private implementation
-
- private CounterGroup? _group;
- private Dictionary<string, string?>? _metadata;
-
- internal abstract void WritePayload(float intervalSec, int pollingIntervalMillisec);
-
- internal void ReportOutOfBandMessage(string message)
- {
- EventSource.ReportOutOfBandMessage(message);
- }
-
- internal string GetMetadataString()
- {
- Debug.Assert(Monitor.IsEntered(this));
-
- if (_metadata == null)
- {
- return "";
- }
-
- // The dictionary is only initialized to non-null when there's metadata to add, and no items
- // are ever removed, so if the dictionary is non-null, there must also be at least one element.
- Dictionary<string, string?>.Enumerator enumerator = _metadata.GetEnumerator();
- Debug.Assert(_metadata.Count > 0);
- bool gotOne = enumerator.MoveNext();
- Debug.Assert(gotOne);
-
- // If there's only one element, just concat a string for it.
- KeyValuePair<string, string?> current = enumerator.Current;
- if (!enumerator.MoveNext())
- {
- return current.Key + ":" + current.Value;
- }
-
- // Otherwise, append it, then append the element we moved to, and then
- // iterate through the remainder of the elements, appending each.
- StringBuilder sb = new StringBuilder().Append(current.Key).Append(':').Append(current.Value);
- do
- {
- current = enumerator.Current;
- sb.Append(',').Append(current.Key).Append(':').Append(current.Value);
- }
- while (enumerator.MoveNext());
-
- // Return the final string.
- return sb.ToString();
- }
-
- #endregion // private implementation
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventActivityOptions.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventActivityOptions.cs
deleted file mode 100644
index 02f60379c1e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventActivityOptions.cs
+++ /dev/null
@@ -1,41 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// EventActivityOptions flags allow to specify different activity related characteristics.
- /// </summary>
- [Flags]
- public enum EventActivityOptions
- {
- /// <summary>
- /// No special options are added to the event.
- /// </summary>
- None = 0,
-
- /// <summary>
- /// Disable Implicit Activity Tracking
- /// </summary>
- Disable = 0x2,
-
- /// <summary>
- /// Allow activity event to call itself (directly or indirectly)
- /// </summary>
- Recursive = 0x4,
-
- /// <summary>
- /// Allows event activity to live beyond its parent.
- /// </summary>
- Detachable = 0x8
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventCounter.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventCounter.cs
deleted file mode 100644
index ae3a5d7fceb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventCounter.cs
+++ /dev/null
@@ -1,202 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-using System.Threading;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Provides the ability to collect statistics through EventSource
- ///
- /// See https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.Tracing/documentation/EventCounterTutorial.md
- /// for a tutorial guide.
- ///
- /// See https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestEventCounter.cs
- /// which shows tests, which are also useful in seeing actual use.
- /// </summary>
- public partial class EventCounter : DiagnosticCounter
- {
- /// <summary>
- /// Initializes a new instance of the <see cref="EventCounter"/> class.
- /// EVentCounters live as long as the EventSource that they are attached to unless they are
- /// explicitly Disposed.
- /// </summary>
- /// <param name="name">The name.</param>
- /// <param name="eventSource">The event source.</param>
- public EventCounter(string name, EventSource eventSource) : base(name, eventSource)
- {
- _min = double.PositiveInfinity;
- _max = double.NegativeInfinity;
-
- InitializeBuffer();
- Publish();
- }
-
- /// <summary>
- /// Writes 'value' to the stream of values tracked by the counter. This updates the sum and other statistics that will
- /// be logged on the next timer interval.
- /// </summary>
- /// <param name="value">The value.</param>
- public void WriteMetric(float value)
- {
- Enqueue((double)value);
- }
-
- public void WriteMetric(double value)
- {
- Enqueue(value);
- }
-
- public override string ToString()
- {
- int count = Volatile.Read(ref _count);
- return count == 0 ?
- $"EventCounter '{Name}' Count 0" :
- $"EventCounter '{Name}' Count {count} Mean {(_sum / count).ToString("n3")}";
- }
-
- #region Statistics Calculation
-
- // Statistics
- private int _count;
- private double _sum;
- private double _sumSquared;
- private double _min;
- private double _max;
-
- internal void OnMetricWritten(double value)
- {
- Debug.Assert(Monitor.IsEntered(this));
- _sum += value;
- _sumSquared += value * value;
- if (value > _max)
- _max = value;
-
- if (value < _min)
- _min = value;
-
- _count++;
- }
-
- internal override void WritePayload(float intervalSec, int pollingIntervalMillisec)
- {
- lock (this)
- {
- Flush();
- CounterPayload payload = new CounterPayload();
- payload.Count = _count;
- payload.IntervalSec = intervalSec;
- if (0 < _count)
- {
- payload.Mean = _sum / _count;
- payload.StandardDeviation = Math.Sqrt(_sumSquared / _count - _sum * _sum / _count / _count);
- }
- else
- {
- payload.Mean = 0;
- payload.StandardDeviation = 0;
- }
- payload.Min = _min;
- payload.Max = _max;
- payload.Series = $"Interval={pollingIntervalMillisec}"; // TODO: This may need to change when we support multi-session
- payload.CounterType = "Mean";
- payload.Metadata = GetMetadataString();
- payload.DisplayName = DisplayName ?? "";
- payload.DisplayUnits = DisplayUnits ?? "";
- payload.Name = Name;
- ResetStatistics();
- EventSource.Write("EventCounters", new EventSourceOptions() { Level = EventLevel.LogAlways }, new CounterPayloadType(payload));
- }
- }
-
- internal void ResetStatistics()
- {
- lock (this)
- {
- _count = 0;
- _sum = 0;
- _sumSquared = 0;
- _min = double.PositiveInfinity;
- _max = double.NegativeInfinity;
- }
- }
-
- #endregion // Statistics Calculation
-
- // Values buffering
- private const int BufferedSize = 10;
- private const double UnusedBufferSlotValue = double.NegativeInfinity;
- private volatile double[] _bufferedValues = null!;
- private volatile int _bufferedValuesIndex;
-
- private void InitializeBuffer()
- {
- _bufferedValues = new double[BufferedSize];
- for (int i = 0; i < _bufferedValues.Length; i++)
- {
- _bufferedValues[i] = UnusedBufferSlotValue;
- }
- }
-
- private void Enqueue(double value)
- {
- // It is possible that two threads read the same bufferedValuesIndex, but only one will be able to write the slot, so that is okay.
- int i = _bufferedValuesIndex;
- while (true)
- {
- double result = Interlocked.CompareExchange(ref _bufferedValues[i], value, UnusedBufferSlotValue);
- i++;
- if (_bufferedValues.Length <= i)
- {
- // It is possible that two threads both think the buffer is full, but only one get to actually flush it, the other
- // will eventually enter this code path and potentially calling Flushing on a buffer that is not full, and that's okay too.
- lock (this) // Lock the counter
- Flush();
- i = 0;
- }
-
- if (result == UnusedBufferSlotValue)
- {
- // CompareExchange succeeded
- _bufferedValuesIndex = i;
- return;
- }
- }
- }
-
- protected void Flush()
- {
- Debug.Assert(Monitor.IsEntered(this));
- for (int i = 0; i < _bufferedValues.Length; i++)
- {
- double value = Interlocked.Exchange(ref _bufferedValues[i], UnusedBufferSlotValue);
- if (value != UnusedBufferSlotValue)
- {
- OnMetricWritten(value);
- }
- }
-
- _bufferedValuesIndex = 0;
- }
- }
-
-
- /// <summary>
- /// This is the payload that is sent in the with EventSource.Write
- /// </summary>
- [EventData]
- internal class CounterPayloadType
- {
- public CounterPayloadType(CounterPayload payload) { Payload = payload; }
- public CounterPayload Payload { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventDescriptor.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventDescriptor.cs
deleted file mode 100644
index 02ba4d715ea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventDescriptor.cs
+++ /dev/null
@@ -1,145 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using Environment = Microsoft.Diagnostics.Tracing.Internal.Environment;
-#endif
-using System.Runtime.InteropServices;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- [StructLayout(LayoutKind.Explicit, Size = 16)]
-#if ES_BUILD_STANDALONE
- [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
-#endif
-
- /*
- EventDescriptor was public in the separate System.Diagnostics.Tracing assembly(pre NS2.0),
- now the move to CoreLib marked them as private.
- While they are technically private (it's a contract used between the library and the ILC toolchain),
- we need them to be rooted and exported from shared library for the system to work.
- For now I'm simply marking them as public again.A cleaner solution might be to use.rd.xml to
- root them and modify shared library definition to force export them.
- */
-#if ES_BUILD_PN
- public
-#else
- internal
-#endif
- struct EventDescriptor
- {
- #region private
- [FieldOffset(0)]
- private readonly int m_traceloggingId;
- [FieldOffset(0)]
- private readonly ushort m_id;
- [FieldOffset(2)]
- private readonly byte m_version;
- [FieldOffset(3)]
- private readonly byte m_channel;
- [FieldOffset(4)]
- private readonly byte m_level;
- [FieldOffset(5)]
- private readonly byte m_opcode;
- [FieldOffset(6)]
- private readonly ushort m_task;
- [FieldOffset(8)]
- private readonly long m_keywords;
- #endregion
-
- public EventDescriptor(
- int traceloggingId,
- byte level,
- byte opcode,
- long keywords
- )
- {
- this.m_id = 0;
- this.m_version = 0;
- this.m_channel = 0;
- this.m_traceloggingId = traceloggingId;
- this.m_level = level;
- this.m_opcode = opcode;
- this.m_task = 0;
- this.m_keywords = keywords;
- }
-
- public EventDescriptor(
- int id,
- byte version,
- byte channel,
- byte level,
- byte opcode,
- int task,
- long keywords
- )
- {
- if (id < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(id), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (id > ushort.MaxValue)
- {
- throw new ArgumentOutOfRangeException(nameof(id), SR.Format(SR.ArgumentOutOfRange_NeedValidId, 1, ushort.MaxValue));
- }
-
- m_traceloggingId = 0;
- m_id = (ushort)id;
- m_version = version;
- m_channel = channel;
- m_level = level;
- m_opcode = opcode;
- m_keywords = keywords;
-
- if (task < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(task), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (task > ushort.MaxValue)
- {
- throw new ArgumentOutOfRangeException(nameof(task), SR.Format(SR.ArgumentOutOfRange_NeedValidId, 1, ushort.MaxValue));
- }
-
- m_task = (ushort)task;
- }
-
- public int EventId => m_id;
- public byte Version => m_version;
- public byte Channel => m_channel;
- public byte Level => m_level;
- public byte Opcode => m_opcode;
- public int Task => m_task;
- public long Keywords => m_keywords;
-
- internal int TraceLoggingId => m_traceloggingId;
-
- public override bool Equals(object? obj) =>
- obj is EventDescriptor ed && Equals(ed);
-
- public override int GetHashCode() =>
- m_id ^ m_version ^ m_channel ^ m_level ^ m_opcode ^ m_task ^ (int)m_keywords;
-
- public bool Equals(EventDescriptor other) =>
- m_id == other.m_id &&
- m_version == other.m_version &&
- m_channel == other.m_channel &&
- m_level == other.m_level &&
- m_opcode == other.m_opcode &&
- m_task == other.m_task &&
- m_keywords == other.m_keywords;
-
- public static bool operator ==(EventDescriptor event1, EventDescriptor event2) =>
- event1.Equals(event2);
-
- public static bool operator !=(EventDescriptor event1, EventDescriptor event2) =>
- !event1.Equals(event2);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs
deleted file mode 100644
index b1787019a16..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs
+++ /dev/null
@@ -1,1353 +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.
-
-#if ES_BUILD_STANDALONE
-using Microsoft.Win32;
-using System;
-using System.Diagnostics;
-using System.Security.Permissions;
-using BitOperations = Microsoft.Diagnostics.Tracing.Internal.BitOperations;
-#endif
-using System.Collections.Generic;
-using System.Globalization;
-using System.Numerics;
-using System.Runtime.InteropServices;
-#if CORECLR && PLATFORM_WINDOWS
-using Internal.Win32;
-#endif
-#if ES_BUILD_AGAINST_DOTNET_V35
-using Microsoft.Internal; // for Tuple (can't define alias for open generic types so we "use" the whole namespace)
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- internal enum EventProviderType
- {
- None = 0,
- ETW,
- EventPipe
- }
-
- internal enum ControllerCommand
- {
- // Strictly Positive numbers are for provider-specific commands, negative number are for 'shared' commands. 256
- // The first 256 negative numbers are reserved for the framework.
- Update = 0, // Not used by EventProviderBase.
- SendManifest = -1,
- Enable = -2,
- Disable = -3,
- }
-
- /// <summary>
- /// Only here because System.Diagnostics.EventProvider needs one more extensibility hook (when it gets a
- /// controller callback)
- /// </summary>
-#if ES_BUILD_STANDALONE
- [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
-#endif
- internal class EventProvider : IDisposable
- {
- // This is the windows EVENT_DATA_DESCRIPTOR structure. We expose it because this is what
- // subclasses of EventProvider use when creating efficient (but unsafe) version of
- // EventWrite. We do make it a nested type because we really don't expect anyone to use
- // it except subclasses (and then only rarely).
- [StructLayout(LayoutKind.Sequential)]
- public struct EventData
- {
- internal unsafe ulong Ptr;
- internal uint Size;
- internal uint Reserved;
- }
-
- /// <summary>
- /// A struct characterizing ETW sessions (identified by the etwSessionId) as
- /// activity-tracing-aware or legacy. A session that's activity-tracing-aware
- /// has specified one non-zero bit in the reserved range 44-47 in the
- /// 'allKeywords' value it passed in for a specific EventProvider.
- /// </summary>
- public struct SessionInfo
- {
- internal int sessionIdBit; // the index of the bit used for tracing in the "reserved" field of AllKeywords
- internal int etwSessionId; // the machine-wide ETW session ID
-
- internal SessionInfo(int sessionIdBit_, int etwSessionId_)
- { sessionIdBit = sessionIdBit_; etwSessionId = etwSessionId_; }
- }
-
- internal IEventProvider m_eventProvider; // The interface that implements the specific logging mechanism functions.
- private Interop.Advapi32.EtwEnableCallback? m_etwCallback; // Trace Callback function
- private long m_regHandle; // Trace Registration Handle
- private byte m_level; // Tracing Level
- private long m_anyKeywordMask; // Trace Enable Flags
- private long m_allKeywordMask; // Match all keyword
- private List<SessionInfo>? m_liveSessions; // current live sessions (Tuple<sessionIdBit, etwSessionId>)
- private bool m_enabled; // Enabled flag from Trace callback
- private string? m_providerName; // Control name
- private Guid m_providerId; // Control Guid
- internal bool m_disposed; // when true provider has unregistered
-
- [ThreadStatic]
- private static WriteEventErrorCode s_returnCode; // The last return code
-
- private const int s_basicTypeAllocationBufferSize = 16;
- private const int s_etwMaxNumberArguments = 128;
- private const int s_etwAPIMaxRefObjCount = 8;
- private const int s_traceEventMaximumSize = 65482;
-
- public enum WriteEventErrorCode : int
- {
- // check mapping to runtime codes
- NoError = 0,
- NoFreeBuffers = 1,
- EventTooBig = 2,
- NullInput = 3,
- TooManyArgs = 4,
- Other = 5,
- }
-
- // Because callbacks happen on registration, and we need the callbacks for those setup
- // we can't call Register in the constructor.
- //
- // Note that EventProvider should ONLY be used by EventSource. In particular because
- // it registers a callback from native code you MUST dispose it BEFORE shutdown, otherwise
- // you may get native callbacks during shutdown when we have destroyed the delegate.
- // EventSource has special logic to do this, no one else should be calling EventProvider.
- internal EventProvider(EventProviderType providerType)
- {
- m_eventProvider = providerType switch
- {
-#if PLATFORM_WINDOWS
- EventProviderType.ETW => new EtwEventProvider(),
-#endif
-#if FEATURE_PERFTRACING
- EventProviderType.EventPipe => new EventPipeEventProvider(),
-#endif
- _ => new NoOpEventProvider(),
- };
- }
-
- /// <summary>
- /// This method registers the controlGuid of this class with ETW. We need to be running on
- /// Vista or above. If not a PlatformNotSupported exception will be thrown. If for some
- /// reason the ETW Register call failed a NotSupported exception will be thrown.
- /// </summary>
- // <SecurityKernel Critical="True" Ring="0">
- // <CallsSuppressUnmanagedCode Name="Interop.Advapi32.EventRegister(System.Guid&,Microsoft.Win32.Interop.Advapi32+EtwEnableCallback,System.Void*,System.Int64&):System.UInt32" />
- // <SatisfiesLinkDemand Name="Win32Exception..ctor(System.Int32)" />
- // <ReferencesCritical Name="Method: EtwEnableCallBack(Guid&, Int32, Byte, Int64, Int64, Void*, Void*):Void" Ring="1" />
- // </SecurityKernel>
- internal unsafe void Register(EventSource eventSource)
- {
- uint status;
- m_etwCallback = new Interop.Advapi32.EtwEnableCallback(EtwEnableCallBack);
-
- status = EventRegister(eventSource, m_etwCallback);
- if (status != 0)
- {
-#if PLATFORM_WINDOWS && !ES_BUILD_STANDALONE
- throw new ArgumentException(Interop.Kernel32.GetMessage(unchecked((int)status)));
-#else
- throw new ArgumentException(Convert.ToString(unchecked((int)status)));
-#endif
- }
- }
-
- //
- // implement Dispose Pattern to early deregister from ETW insted of waiting for
- // the finalizer to call deregistration.
- // Once the user is done with the provider it needs to call Close() or Dispose()
- // If neither are called the finalizer will unregister the provider anyway
- //
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- // <SecurityKernel Critical="True" TreatAsSafe="Does not expose critical resource" Ring="1">
- // <ReferencesCritical Name="Method: Deregister():Void" Ring="1" />
- // </SecurityKernel>
- protected virtual void Dispose(bool disposing)
- {
- //
- // explicit cleanup is done by calling Dispose with true from
- // Dispose() or Close(). The disposing arguement is ignored because there
- // are no unmanaged resources.
- // The finalizer calls Dispose with false.
- //
-
- //
- // check if the object has been already disposed
- //
- if (m_disposed)
- return;
-
- // Disable the provider.
- m_enabled = false;
-
- // Do most of the work under a lock to avoid shutdown race.
-
- long registrationHandle = 0;
- lock (EventListener.EventListenersLock)
- {
- // Double check
- if (m_disposed)
- return;
-
- registrationHandle = m_regHandle;
- m_regHandle = 0;
- m_disposed = true;
- }
-
- // We do the Unregistration outside the EventListenerLock because there is a lock
- // inside the ETW routines. This lock is taken before ETW issues commands
- // Thus the ETW lock gets taken first and then our EventListenersLock gets taken
- // in SendCommand(), and also here. If we called EventUnregister after taking
- // the EventListenersLock then the take-lock order is reversed and we can have
- // deadlocks in race conditions (dispose racing with an ETW command).
- //
- // We solve by Unregistering after releasing the EventListenerLock.
- if (registrationHandle != 0)
- EventUnregister(registrationHandle);
- }
-
- /// <summary>
- /// This method deregisters the controlGuid of this class with ETW.
- ///
- /// </summary>
- public virtual void Close()
- {
- Dispose();
- }
-
- ~EventProvider()
- {
- Dispose(false);
- }
-
- // <SecurityKernel Critical="True" Ring="0">
- // <UsesUnsafeCode Name="Parameter filterData of type: Void*" />
- // <UsesUnsafeCode Name="Parameter callbackContext of type: Void*" />
- // </SecurityKernel>
- private unsafe void EtwEnableCallBack(
- in System.Guid sourceId,
- int controlCode,
- byte setLevel,
- long anyKeyword,
- long allKeyword,
- Interop.Advapi32.EVENT_FILTER_DESCRIPTOR* filterData,
- void* callbackContext
- )
- {
- // This is an optional callback API. We will therefore ignore any failures that happen as a
- // result of turning on this provider as to not crash the app.
- // EventSource has code to validate whether initialization it expected to occur actually occurred
- try
- {
- ControllerCommand command = ControllerCommand.Update;
- IDictionary<string, string?>? args = null;
- bool skipFinalOnControllerCommand = false;
- if (controlCode == Interop.Advapi32.EVENT_CONTROL_CODE_ENABLE_PROVIDER)
- {
- m_enabled = true;
- m_level = setLevel;
- m_anyKeywordMask = anyKeyword;
- m_allKeywordMask = allKeyword;
-
- List<Tuple<SessionInfo, bool>> sessionsChanged = GetSessions();
-
- // The GetSessions() logic was here to support the idea that different ETW sessions
- // could have different user-defined filters. (I believe it is currently broken but that is another matter.)
- // However in particular GetSessions() does not support EventPipe, only ETW, which is
- // the immediate problem. We work-around establishing the invariant that we always get a
- // OnControllerCallback under all circumstances, even if we can't find a delta in the
- // ETW logic. This fixes things for the EventPipe case.
- //
- // All this session based logic should be reviewed and likely removed, but that is a larger
- // change that needs more careful staging.
- if (sessionsChanged.Count == 0)
- sessionsChanged.Add(new Tuple<SessionInfo, bool>(new SessionInfo(0, 0), true));
-
- foreach (Tuple<SessionInfo, bool> session in sessionsChanged)
- {
- int sessionChanged = session.Item1.sessionIdBit;
- int etwSessionId = session.Item1.etwSessionId;
- bool bEnabling = session.Item2;
-
- skipFinalOnControllerCommand = true;
- args = null; // reinitialize args for every session...
-
- // if we get more than one session changed we have no way
- // of knowing which one "filterData" belongs to
- if (sessionsChanged.Count > 1)
- filterData = null;
-
- // read filter data only when a session is being *added*
- byte[]? data;
- int keyIndex;
- if (bEnabling &&
- GetDataFromController(etwSessionId, filterData, out command, out data, out keyIndex))
- {
- args = new Dictionary<string, string?>(4);
- // data can be null if the filterArgs had a very large size which failed our sanity check
- if (data != null)
- {
- while (keyIndex < data.Length)
- {
- int keyEnd = FindNull(data, keyIndex);
- int valueIdx = keyEnd + 1;
- int valueEnd = FindNull(data, valueIdx);
- if (valueEnd < data.Length)
- {
- string key = System.Text.Encoding.UTF8.GetString(data, keyIndex, keyEnd - keyIndex);
- string value = System.Text.Encoding.UTF8.GetString(data, valueIdx, valueEnd - valueIdx);
- args[key] = value;
- }
- keyIndex = valueEnd + 1;
- }
- }
- }
-
- // execute OnControllerCommand once for every session that has changed.
- OnControllerCommand(command, args, bEnabling ? sessionChanged : -sessionChanged, etwSessionId);
- }
- }
- else if (controlCode == Interop.Advapi32.EVENT_CONTROL_CODE_DISABLE_PROVIDER)
- {
- m_enabled = false;
- m_level = 0;
- m_anyKeywordMask = 0;
- m_allKeywordMask = 0;
- m_liveSessions = null;
- }
- else if (controlCode == Interop.Advapi32.EVENT_CONTROL_CODE_CAPTURE_STATE)
- {
- command = ControllerCommand.SendManifest;
- }
- else
- return; // per spec you ignore commands you don't recognize.
-
- if (!skipFinalOnControllerCommand)
- OnControllerCommand(command, args, 0, 0);
- }
- catch
- {
- // We want to ignore any failures that happen as a result of turning on this provider as to
- // not crash the app.
- }
- }
-
- protected virtual void OnControllerCommand(ControllerCommand command, IDictionary<string, string?>? arguments, int sessionId, int etwSessionId) { }
-
- protected EventLevel Level
- {
- get => (EventLevel)m_level;
- set => m_level = (byte)value;
- }
-
- protected EventKeywords MatchAnyKeyword
- {
- get => (EventKeywords)m_anyKeywordMask;
- set => m_anyKeywordMask = unchecked((long)value);
- }
-
- protected EventKeywords MatchAllKeyword
- {
- get => (EventKeywords)m_allKeywordMask;
- set => m_allKeywordMask = unchecked((long)value);
- }
-
- private static int FindNull(byte[] buffer, int idx)
- {
- while (idx < buffer.Length && buffer[idx] != 0)
- idx++;
- return idx;
- }
-
- /// <summary>
- /// Determines the ETW sessions that have been added and/or removed to the set of
- /// sessions interested in the current provider. It does so by (1) enumerating over all
- /// ETW sessions that enabled 'this.m_Guid' for the current process ID, and (2)
- /// comparing the current list with a list it cached on the previous invocation.
- ///
- /// The return value is a list of tuples, where the SessionInfo specifies the
- /// ETW session that was added or remove, and the bool specifies whether the
- /// session was added or whether it was removed from the set.
- /// </summary>
- private List<Tuple<SessionInfo, bool>> GetSessions()
- {
- List<SessionInfo>? liveSessionList = null;
-
- GetSessionInfo(
- (int etwSessionId, long matchAllKeywords, ref List<SessionInfo>? sessionList) =>
- GetSessionInfoCallback(etwSessionId, matchAllKeywords, ref sessionList),
- ref liveSessionList);
-
- List<Tuple<SessionInfo, bool>> changedSessionList = new List<Tuple<SessionInfo, bool>>();
-
- // first look for sessions that have gone away (or have changed)
- // (present in the m_liveSessions but not in the new liveSessionList)
- if (m_liveSessions != null)
- {
- foreach (SessionInfo s in m_liveSessions)
- {
- int idx;
- if ((idx = IndexOfSessionInList(liveSessionList, s.etwSessionId)) < 0 ||
- (liveSessionList![idx].sessionIdBit != s.sessionIdBit))
- changedSessionList.Add(Tuple.Create(s, false));
- }
- }
- // next look for sessions that were created since the last callback (or have changed)
- // (present in the new liveSessionList but not in m_liveSessions)
- if (liveSessionList != null)
- {
- foreach (SessionInfo s in liveSessionList)
- {
- int idx;
- if ((idx = IndexOfSessionInList(m_liveSessions, s.etwSessionId)) < 0 ||
- (m_liveSessions![idx].sessionIdBit != s.sessionIdBit))
- changedSessionList.Add(Tuple.Create(s, true));
- }
- }
-
- m_liveSessions = liveSessionList;
- return changedSessionList;
- }
-
- /// <summary>
- /// This method is the callback used by GetSessions() when it calls into GetSessionInfo().
- /// It updates a List{SessionInfo} based on the etwSessionId and matchAllKeywords that
- /// GetSessionInfo() passes in.
- /// </summary>
- private static void GetSessionInfoCallback(int etwSessionId, long matchAllKeywords,
- ref List<SessionInfo>? sessionList)
- {
- uint sessionIdBitMask = (uint)SessionMask.FromEventKeywords(unchecked((ulong)matchAllKeywords));
- // an ETW controller that specifies more than the mandated bit for our EventSource
- // will be ignored...
- int val = BitOperations.PopCount(sessionIdBitMask);
- if (val > 1)
- return;
-
- sessionList ??= new List<SessionInfo>(8);
-
- if (val == 1)
- {
- // activity-tracing-aware etw session
- val = BitOperations.TrailingZeroCount(sessionIdBitMask);
- }
- else
- {
- // legacy etw session
- val = BitOperations.PopCount((uint)SessionMask.All);
- }
-
- sessionList.Add(new SessionInfo(val + 1, etwSessionId));
- }
-
- private delegate void SessionInfoCallback(int etwSessionId, long matchAllKeywords, ref List<SessionInfo>? sessionList);
-
- /// <summary>
- /// This method enumerates over all active ETW sessions that have enabled 'this.m_Guid'
- /// for the current process ID, calling 'action' for each session, and passing it the
- /// ETW session and the 'AllKeywords' the session enabled for the current provider.
- /// </summary>
- private unsafe void GetSessionInfo(SessionInfoCallback action, ref List<SessionInfo>? sessionList)
- {
- // We wish the EventSource package to be legal for Windows Store applications.
- // Currently EnumerateTraceGuidsEx is not an allowed API, so we avoid its use here
- // and use the information in the registry instead. This means that ETW controllers
- // that do not publish their intent to the registry (basically all controllers EXCEPT
- // TraceEventSesion) will not work properly
-
- // However the framework version of EventSource DOES have ES_SESSION_INFO defined and thus
- // does not have this issue.
-#if (PLATFORM_WINDOWS && (ES_SESSION_INFO || !ES_BUILD_STANDALONE))
- int buffSize = 256; // An initial guess that probably works most of the time.
- byte* buffer;
- while (true)
- {
- byte* space = stackalloc byte[buffSize];
- buffer = space;
- int hr = 0;
-
- fixed (Guid* provider = &m_providerId)
- {
- hr = Interop.Advapi32.EnumerateTraceGuidsEx(Interop.Advapi32.TRACE_QUERY_INFO_CLASS.TraceGuidQueryInfo,
- provider, sizeof(Guid), buffer, buffSize, out buffSize);
- }
- if (hr == 0)
- break;
- if (hr != Interop.Errors.ERROR_INSUFFICIENT_BUFFER)
- return;
- }
-
- var providerInfos = (Interop.Advapi32.TRACE_GUID_INFO*)buffer;
- var providerInstance = (Interop.Advapi32.TRACE_PROVIDER_INSTANCE_INFO*)&providerInfos[1];
- int processId = unchecked((int)Interop.Kernel32.GetCurrentProcessId());
- // iterate over the instances of the EventProvider in all processes
- for (int i = 0; i < providerInfos->InstanceCount; i++)
- {
- if (providerInstance->Pid == processId)
- {
- var enabledInfos = (Interop.Advapi32.TRACE_ENABLE_INFO*)&providerInstance[1];
- // iterate over the list of active ETW sessions "listening" to the current provider
- for (int j = 0; j < providerInstance->EnableCount; j++)
- action(enabledInfos[j].LoggerId, enabledInfos[j].MatchAllKeyword, ref sessionList);
- }
- if (providerInstance->NextOffset == 0)
- break;
- Debug.Assert(0 <= providerInstance->NextOffset && providerInstance->NextOffset < buffSize);
- byte* structBase = (byte*)providerInstance;
- providerInstance = (Interop.Advapi32.TRACE_PROVIDER_INSTANCE_INFO*)&structBase[providerInstance->NextOffset];
- }
-#else
-#if !ES_BUILD_PCL && PLATFORM_WINDOWS // TODO command arguments don't work on PCL builds...
- // This code is only used in the Nuget Package Version of EventSource. because
- // the code above is using APIs baned from UWP apps.
- //
- // TODO: In addition to only working when TraceEventSession enables the provider, this code
- // also has a problem because TraceEvent does not clean up if the registry is stale
- // It is unclear if it is worth keeping, but for now we leave it as it does work
- // at least some of the time.
-
- // Determine our session from what is in the registry.
- string regKey = @"\Microsoft\Windows\CurrentVersion\Winevt\Publishers\{" + m_providerName + "}";
- if (IntPtr.Size == 8)
- regKey = @"Software" + @"\Wow6432Node" + regKey;
- else
- regKey = @"Software" + regKey;
-
- using (var key = Registry.LocalMachine.OpenSubKey(regKey))
- {
- if (key != null)
- {
- foreach (string valueName in key.GetValueNames())
- {
- if (valueName.StartsWith("ControllerData_Session_", StringComparison.Ordinal))
- {
- string strId = valueName.Substring(23); // strip of the ControllerData_Session_
- int etwSessionId;
- if (int.TryParse(strId, out etwSessionId))
- {
-#if ES_BUILD_STANDALONE
- // we need to assert this permission for partial trust scenarios
- (new RegistryPermission(RegistryPermissionAccess.Read, regKey)).Assert();
-#endif
- var data = key.GetValue(valueName) as byte[];
- if (data != null)
- {
- var dataAsString = System.Text.Encoding.UTF8.GetString(data);
- int keywordIdx = dataAsString.IndexOf("EtwSessionKeyword", StringComparison.Ordinal);
- if (0 <= keywordIdx)
- {
- int startIdx = keywordIdx + 18;
- int endIdx = dataAsString.IndexOf('\0', startIdx);
- string keywordBitString = dataAsString.Substring(startIdx, endIdx - startIdx);
- int keywordBit;
- if (0 < endIdx && int.TryParse(keywordBitString, out keywordBit))
- action(etwSessionId, 1L << keywordBit, ref sessionList);
- }
- }
- }
- }
- }
- }
- }
-#endif
-#endif
- }
-
- /// <summary>
- /// Returns the index of the SesisonInfo from 'sessions' that has the specified 'etwSessionId'
- /// or -1 if the value is not present.
- /// </summary>
- private static int IndexOfSessionInList(List<SessionInfo>? sessions, int etwSessionId)
- {
- if (sessions == null)
- return -1;
- // for non-coreclr code we could use List<T>.FindIndex(Predicate<T>), but we need this to compile
- // on coreclr as well
- for (int i = 0; i < sessions.Count; ++i)
- if (sessions[i].etwSessionId == etwSessionId)
- return i;
-
- return -1;
- }
-
- /// <summary>
- /// Gets any data to be passed from the controller to the provider. It starts with what is passed
- /// into the callback, but unfortunately this data is only present for when the provider is active
- /// at the time the controller issues the command. To allow for providers to activate after the
- /// controller issued a command, we also check the registry and use that to get the data. The function
- /// returns an array of bytes representing the data, the index into that byte array where the data
- /// starts, and the command being issued associated with that data.
- /// </summary>
- private unsafe bool GetDataFromController(int etwSessionId,
- Interop.Advapi32.EVENT_FILTER_DESCRIPTOR* filterData, out ControllerCommand command, out byte[]? data, out int dataStart)
- {
- data = null;
- dataStart = 0;
- if (filterData == null)
- {
-#if (!ES_BUILD_PCL && !ES_BUILD_PN && PLATFORM_WINDOWS)
- string regKey = @"\Microsoft\Windows\CurrentVersion\Winevt\Publishers\{" + m_providerId + "}";
- if (IntPtr.Size == 8)
- regKey = @"Software\Wow6432Node" + regKey;
- else
- regKey = "Software" + regKey;
-
- string valueName = "ControllerData_Session_" + etwSessionId.ToString(CultureInfo.InvariantCulture);
-
- // we need to assert this permission for partial trust scenarios
-#if ES_BUILD_STANDALONE
- (new RegistryPermission(RegistryPermissionAccess.Read, regKey)).Assert();
-#endif
- using (RegistryKey? key = Registry.LocalMachine.OpenSubKey(regKey))
- {
- data = key?.GetValue(valueName, null) as byte[];
- if (data != null)
- {
- // We only used the persisted data from the registry for updates.
- command = ControllerCommand.Update;
- return true;
- }
- }
-#endif
- }
- else
- {
- // ETW limited filter data to 1024 bytes but EventPipe doesn't. DiagnosticSourceEventSource
- // can legitimately use large filter data buffers to encode a large set of events and properties
- // that should be gathered so I am bumping the limit from 1K -> 100K.
- if (filterData->Ptr != 0 && 0 < filterData->Size && filterData->Size <= 100*1024)
- {
- data = new byte[filterData->Size];
- Marshal.Copy((IntPtr)filterData->Ptr, data, 0, data.Length);
- }
- command = (ControllerCommand)filterData->Type;
- return true;
- }
-
- command = ControllerCommand.Update;
- return false;
- }
-
- /// <summary>
- /// IsEnabled, method used to test if provider is enabled
- /// </summary>
- public bool IsEnabled()
- {
- return m_enabled;
- }
-
- /// <summary>
- /// IsEnabled, method used to test if event is enabled
- /// </summary>
- /// <param name="level">
- /// Level to test
- /// </param>
- /// <param name="keywords">
- /// Keyword to test
- /// </param>
- public bool IsEnabled(byte level, long keywords)
- {
- //
- // If not enabled at all, return false.
- //
- if (!m_enabled)
- {
- return false;
- }
-
- // This also covers the case of Level == 0.
- if ((level <= m_level) ||
- (m_level == 0))
- {
- //
- // Check if Keyword is enabled
- //
-
- if ((keywords == 0) ||
- (((keywords & m_anyKeywordMask) != 0) &&
- ((keywords & m_allKeywordMask) == m_allKeywordMask)))
- {
- return true;
- }
- }
-
- return false;
- }
-
- public static WriteEventErrorCode GetLastWriteEventError()
- {
- return s_returnCode;
- }
-
- //
- // Helper function to set the last error on the thread
- //
- private static void SetLastError(WriteEventErrorCode error)
- {
- s_returnCode = error;
- }
-
- // <SecurityKernel Critical="True" Ring="0">
- // <UsesUnsafeCode Name="Local intptrPtr of type: IntPtr*" />
- // <UsesUnsafeCode Name="Local intptrPtr of type: Int32*" />
- // <UsesUnsafeCode Name="Local longptr of type: Int64*" />
- // <UsesUnsafeCode Name="Local uintptr of type: UInt32*" />
- // <UsesUnsafeCode Name="Local ulongptr of type: UInt64*" />
- // <UsesUnsafeCode Name="Local charptr of type: Char*" />
- // <UsesUnsafeCode Name="Local byteptr of type: Byte*" />
- // <UsesUnsafeCode Name="Local shortptr of type: Int16*" />
- // <UsesUnsafeCode Name="Local sbyteptr of type: SByte*" />
- // <UsesUnsafeCode Name="Local ushortptr of type: UInt16*" />
- // <UsesUnsafeCode Name="Local floatptr of type: Single*" />
- // <UsesUnsafeCode Name="Local doubleptr of type: Double*" />
- // <UsesUnsafeCode Name="Local boolptr of type: Boolean*" />
- // <UsesUnsafeCode Name="Local guidptr of type: Guid*" />
- // <UsesUnsafeCode Name="Local decimalptr of type: Decimal*" />
- // <UsesUnsafeCode Name="Local booleanptr of type: Boolean*" />
- // <UsesUnsafeCode Name="Parameter dataDescriptor of type: EventData*" />
- // <UsesUnsafeCode Name="Parameter dataBuffer of type: Byte*" />
- // </SecurityKernel>
- private static unsafe object? EncodeObject(ref object? data, ref EventData* dataDescriptor, ref byte* dataBuffer, ref uint totalEventSize)
- /*++
-
- Routine Description:
-
- This routine is used by WriteEvent to unbox the object type and
- to fill the passed in ETW data descriptor.
-
- Arguments:
-
- data - argument to be decoded
-
- dataDescriptor - pointer to the descriptor to be filled (updated to point to the next empty entry)
-
- dataBuffer - storage buffer for storing user data, needed because cant get the address of the object
- (updated to point to the next empty entry)
-
- Return Value:
-
- null if the object is a basic type other than string or byte[]. String otherwise
-
- --*/
- {
- Again:
- dataDescriptor->Reserved = 0;
-
- string? sRet = data as string;
- byte[]? blobRet = null;
-
- if (sRet != null)
- {
- dataDescriptor->Size = ((uint)sRet.Length + 1) * 2;
- }
- else if ((blobRet = data as byte[]) != null)
- {
- // first store array length
- *(int*)dataBuffer = blobRet.Length;
- dataDescriptor->Ptr = (ulong)dataBuffer;
- dataDescriptor->Size = 4;
- totalEventSize += dataDescriptor->Size;
-
- // then the array parameters
- dataDescriptor++;
- dataBuffer += s_basicTypeAllocationBufferSize;
- dataDescriptor->Size = (uint)blobRet.Length;
- }
- else if (data is IntPtr)
- {
- dataDescriptor->Size = (uint)sizeof(IntPtr);
- IntPtr* intptrPtr = (IntPtr*)dataBuffer;
- *intptrPtr = (IntPtr)data;
- dataDescriptor->Ptr = (ulong)intptrPtr;
- }
- else if (data is int)
- {
- dataDescriptor->Size = (uint)sizeof(int);
- int* intptr = (int*)dataBuffer;
- *intptr = (int)data;
- dataDescriptor->Ptr = (ulong)intptr;
- }
- else if (data is long)
- {
- dataDescriptor->Size = (uint)sizeof(long);
- long* longptr = (long*)dataBuffer;
- *longptr = (long)data;
- dataDescriptor->Ptr = (ulong)longptr;
- }
- else if (data is uint)
- {
- dataDescriptor->Size = (uint)sizeof(uint);
- uint* uintptr = (uint*)dataBuffer;
- *uintptr = (uint)data;
- dataDescriptor->Ptr = (ulong)uintptr;
- }
- else if (data is ulong)
- {
- dataDescriptor->Size = (uint)sizeof(ulong);
- ulong* ulongptr = (ulong*)dataBuffer;
- *ulongptr = (ulong)data;
- dataDescriptor->Ptr = (ulong)ulongptr;
- }
- else if (data is char)
- {
- dataDescriptor->Size = (uint)sizeof(char);
- char* charptr = (char*)dataBuffer;
- *charptr = (char)data;
- dataDescriptor->Ptr = (ulong)charptr;
- }
- else if (data is byte)
- {
- dataDescriptor->Size = (uint)sizeof(byte);
- byte* byteptr = (byte*)dataBuffer;
- *byteptr = (byte)data;
- dataDescriptor->Ptr = (ulong)byteptr;
- }
- else if (data is short)
- {
- dataDescriptor->Size = (uint)sizeof(short);
- short* shortptr = (short*)dataBuffer;
- *shortptr = (short)data;
- dataDescriptor->Ptr = (ulong)shortptr;
- }
- else if (data is sbyte)
- {
- dataDescriptor->Size = (uint)sizeof(sbyte);
- sbyte* sbyteptr = (sbyte*)dataBuffer;
- *sbyteptr = (sbyte)data;
- dataDescriptor->Ptr = (ulong)sbyteptr;
- }
- else if (data is ushort)
- {
- dataDescriptor->Size = (uint)sizeof(ushort);
- ushort* ushortptr = (ushort*)dataBuffer;
- *ushortptr = (ushort)data;
- dataDescriptor->Ptr = (ulong)ushortptr;
- }
- else if (data is float)
- {
- dataDescriptor->Size = (uint)sizeof(float);
- float* floatptr = (float*)dataBuffer;
- *floatptr = (float)data;
- dataDescriptor->Ptr = (ulong)floatptr;
- }
- else if (data is double)
- {
- dataDescriptor->Size = (uint)sizeof(double);
- double* doubleptr = (double*)dataBuffer;
- *doubleptr = (double)data;
- dataDescriptor->Ptr = (ulong)doubleptr;
- }
- else if (data is bool)
- {
- // WIN32 Bool is 4 bytes
- dataDescriptor->Size = 4;
- int* intptr = (int*)dataBuffer;
- if ((bool)data)
- {
- *intptr = 1;
- }
- else
- {
- *intptr = 0;
- }
- dataDescriptor->Ptr = (ulong)intptr;
- }
- else if (data is Guid)
- {
- dataDescriptor->Size = (uint)sizeof(Guid);
- Guid* guidptr = (Guid*)dataBuffer;
- *guidptr = (Guid)data;
- dataDescriptor->Ptr = (ulong)guidptr;
- }
- else if (data is decimal)
- {
- dataDescriptor->Size = (uint)sizeof(decimal);
- decimal* decimalptr = (decimal*)dataBuffer;
- *decimalptr = (decimal)data;
- dataDescriptor->Ptr = (ulong)decimalptr;
- }
- else if (data is DateTime)
- {
- const long UTCMinTicks = 504911232000000000;
- long dateTimeTicks = 0;
- // We cannot translate dates sooner than 1/1/1601 in UTC.
- // To avoid getting an ArgumentOutOfRangeException we compare with 1/1/1601 DateTime ticks
- if (((DateTime)data).Ticks > UTCMinTicks)
- dateTimeTicks = ((DateTime)data).ToFileTimeUtc();
- dataDescriptor->Size = (uint)sizeof(long);
- long* longptr = (long*)dataBuffer;
- *longptr = dateTimeTicks;
- dataDescriptor->Ptr = (ulong)longptr;
- }
- else
- {
- if (data is System.Enum)
- {
- try
- {
- Type underlyingType = Enum.GetUnderlyingType(data.GetType());
- if (underlyingType == typeof(ulong))
- data = (ulong)data;
- else if (underlyingType == typeof(long))
- data = (long)data;
- else
- data = (int)Convert.ToInt64(data); // This handles all int/uint or below (we treat them like 32 bit ints)
- goto Again;
- }
- catch { } // On wierd cases (e.g. enums of type double), give up and for compat simply tostring.
- }
-
- // To our eyes, everything else is a just a string
- if (data == null)
- sRet = "";
- else
- sRet = data.ToString()!;
- dataDescriptor->Size = ((uint)sRet.Length + 1) * 2;
- }
-
- totalEventSize += dataDescriptor->Size;
-
- // advance buffers
- dataDescriptor++;
- dataBuffer += s_basicTypeAllocationBufferSize;
-
- return (object?)sRet ?? (object?)blobRet;
- }
-
- /// <summary>
- /// WriteEvent, method to write a parameters with event schema properties
- /// </summary>
- /// <param name="eventDescriptor">
- /// Event Descriptor for this event.
- /// </param>
- /// <param name="activityID">
- /// A pointer to the activity ID GUID to log
- /// </param>
- /// <param name="childActivityID">
- /// childActivityID is marked as 'related' to the current activity ID.
- /// </param>
- /// <param name="eventPayload">
- /// Payload for the ETW event.
- /// </param>
- // <SecurityKernel Critical="True" Ring="0">
- // <CallsSuppressUnmanagedCode Name="Interop.Advapi32.EventWrite(System.Int64,EventDescriptor&,System.UInt32,System.Void*):System.UInt32" />
- // <UsesUnsafeCode Name="Local dataBuffer of type: Byte*" />
- // <UsesUnsafeCode Name="Local pdata of type: Char*" />
- // <UsesUnsafeCode Name="Local userData of type: EventData*" />
- // <UsesUnsafeCode Name="Local userDataPtr of type: EventData*" />
- // <UsesUnsafeCode Name="Local currentBuffer of type: Byte*" />
- // <UsesUnsafeCode Name="Local v0 of type: Char*" />
- // <UsesUnsafeCode Name="Local v1 of type: Char*" />
- // <UsesUnsafeCode Name="Local v2 of type: Char*" />
- // <UsesUnsafeCode Name="Local v3 of type: Char*" />
- // <UsesUnsafeCode Name="Local v4 of type: Char*" />
- // <UsesUnsafeCode Name="Local v5 of type: Char*" />
- // <UsesUnsafeCode Name="Local v6 of type: Char*" />
- // <UsesUnsafeCode Name="Local v7 of type: Char*" />
- // <ReferencesCritical Name="Method: EncodeObject(Object&, EventData*, Byte*):String" Ring="1" />
- // </SecurityKernel>
- internal unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, IntPtr eventHandle, Guid* activityID, Guid* childActivityID, params object?[] eventPayload)
- {
- WriteEventErrorCode status = WriteEventErrorCode.NoError;
-
- if (IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords))
- {
- int argCount = eventPayload.Length;
-
- if (argCount > s_etwMaxNumberArguments)
- {
- s_returnCode = WriteEventErrorCode.TooManyArgs;
- return false;
- }
-
- uint totalEventSize = 0;
- int index;
- int refObjIndex = 0;
- List<int> refObjPosition = new List<int>(s_etwAPIMaxRefObjCount);
- List<object?> dataRefObj = new List<object?>(s_etwAPIMaxRefObjCount);
- EventData* userData = stackalloc EventData[2 * argCount];
- for (int i = 0; i < 2 * argCount; i++)
- userData[i] = default;
- EventData* userDataPtr = (EventData*)userData;
- byte* dataBuffer = stackalloc byte[s_basicTypeAllocationBufferSize * 2 * argCount]; // Assume 16 chars for non-string argument
- byte* currentBuffer = dataBuffer;
-
- //
- // The loop below goes through all the arguments and fills in the data
- // descriptors. For strings save the location in the dataString array.
- // Calculates the total size of the event by adding the data descriptor
- // size value set in EncodeObject method.
- //
- bool hasNonStringRefArgs = false;
- for (index = 0; index < eventPayload.Length; index++)
- {
- if (eventPayload[index] != null)
- {
- object? supportedRefObj = EncodeObject(ref eventPayload[index], ref userDataPtr, ref currentBuffer, ref totalEventSize);
-
- if (supportedRefObj != null)
- {
- // EncodeObject advanced userDataPtr to the next empty slot
- int idx = (int)(userDataPtr - userData - 1);
- if (!(supportedRefObj is string))
- {
- if (eventPayload.Length + idx + 1 - index > s_etwMaxNumberArguments)
- {
- s_returnCode = WriteEventErrorCode.TooManyArgs;
- return false;
- }
- hasNonStringRefArgs = true;
- }
- dataRefObj.Add(supportedRefObj);
- refObjPosition.Add(idx);
- refObjIndex++;
- }
- }
- else
- {
- s_returnCode = WriteEventErrorCode.NullInput;
- return false;
- }
- }
-
- // update argCount based on actual number of arguments written to 'userData'
- argCount = (int)(userDataPtr - userData);
-
- if (totalEventSize > s_traceEventMaximumSize)
- {
- s_returnCode = WriteEventErrorCode.EventTooBig;
- return false;
- }
-
- // the optimized path (using "fixed" instead of allocating pinned GCHandles
- if (!hasNonStringRefArgs && (refObjIndex < s_etwAPIMaxRefObjCount))
- {
- // Fast path: at most 8 string arguments
-
- // ensure we have at least s_etwAPIMaxStringCount in dataString, so that
- // the "fixed" statement below works
- while (refObjIndex < s_etwAPIMaxRefObjCount)
- {
- dataRefObj.Add(null);
- ++refObjIndex;
- }
-
- //
- // now fix any string arguments and set the pointer on the data descriptor
- //
- fixed (char* v0 = (string?)dataRefObj[0], v1 = (string?)dataRefObj[1], v2 = (string?)dataRefObj[2], v3 = (string?)dataRefObj[3],
- v4 = (string?)dataRefObj[4], v5 = (string?)dataRefObj[5], v6 = (string?)dataRefObj[6], v7 = (string?)dataRefObj[7])
- {
- userDataPtr = (EventData*)userData;
- if (dataRefObj[0] != null)
- {
- userDataPtr[refObjPosition[0]].Ptr = (ulong)v0;
- }
- if (dataRefObj[1] != null)
- {
- userDataPtr[refObjPosition[1]].Ptr = (ulong)v1;
- }
- if (dataRefObj[2] != null)
- {
- userDataPtr[refObjPosition[2]].Ptr = (ulong)v2;
- }
- if (dataRefObj[3] != null)
- {
- userDataPtr[refObjPosition[3]].Ptr = (ulong)v3;
- }
- if (dataRefObj[4] != null)
- {
- userDataPtr[refObjPosition[4]].Ptr = (ulong)v4;
- }
- if (dataRefObj[5] != null)
- {
- userDataPtr[refObjPosition[5]].Ptr = (ulong)v5;
- }
- if (dataRefObj[6] != null)
- {
- userDataPtr[refObjPosition[6]].Ptr = (ulong)v6;
- }
- if (dataRefObj[7] != null)
- {
- userDataPtr[refObjPosition[7]].Ptr = (ulong)v7;
- }
-
- status = m_eventProvider.EventWriteTransfer(m_regHandle, in eventDescriptor, eventHandle, activityID, childActivityID, argCount, userData);
- }
- }
- else
- {
- // Slow path: use pinned handles
- userDataPtr = (EventData*)userData;
-
- GCHandle[] rgGCHandle = new GCHandle[refObjIndex];
- for (int i = 0; i < refObjIndex; ++i)
- {
- // below we still use "fixed" to avoid taking dependency on the offset of the first field
- // in the object (the way we would need to if we used GCHandle.AddrOfPinnedObject)
- rgGCHandle[i] = GCHandle.Alloc(dataRefObj[i], GCHandleType.Pinned);
- if (dataRefObj[i] is string)
- {
- fixed (char* p = (string?)dataRefObj[i])
- userDataPtr[refObjPosition[i]].Ptr = (ulong)p;
- }
- else
- {
- fixed (byte* p = (byte[]?)dataRefObj[i])
- userDataPtr[refObjPosition[i]].Ptr = (ulong)p;
- }
- }
-
- status = m_eventProvider.EventWriteTransfer(m_regHandle, in eventDescriptor, eventHandle, activityID, childActivityID, argCount, userData);
-
- for (int i = 0; i < refObjIndex; ++i)
- {
- rgGCHandle[i].Free();
- }
- }
- }
-
- if (status != WriteEventErrorCode.NoError)
- {
- SetLastError(status);
- return false;
- }
-
- return true;
- }
-
- /// <summary>
- /// WriteEvent, method to be used by generated code on a derived class
- /// </summary>
- /// <param name="eventDescriptor">
- /// Event Descriptor for this event.
- /// </param>
- /// <param name="activityID">
- /// A pointer to the activity ID to log
- /// </param>
- /// <param name="childActivityID">
- /// If this event is generating a child activity (WriteEventTransfer related activity) this is child activity
- /// This can be null for events that do not generate a child activity.
- /// </param>
- /// <param name="dataCount">
- /// number of event descriptors
- /// </param>
- /// <param name="data">
- /// pointer do the event data
- /// </param>
- // <SecurityKernel Critical="True" Ring="0">
- // <CallsSuppressUnmanagedCode Name="Interop.Advapi32.EventWrite(System.Int64,EventDescriptor&,System.UInt32,System.Void*):System.UInt32" />
- // </SecurityKernel>
- protected internal unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, IntPtr eventHandle, Guid* activityID, Guid* childActivityID, int dataCount, IntPtr data)
- {
- if (childActivityID != null)
- {
- // activity transfers are supported only for events that specify the Send or Receive opcode
- Debug.Assert((EventOpcode)eventDescriptor.Opcode == EventOpcode.Send ||
- (EventOpcode)eventDescriptor.Opcode == EventOpcode.Receive ||
- (EventOpcode)eventDescriptor.Opcode == EventOpcode.Start ||
- (EventOpcode)eventDescriptor.Opcode == EventOpcode.Stop);
- }
-
- WriteEventErrorCode status = m_eventProvider.EventWriteTransfer(m_regHandle, in eventDescriptor, eventHandle, activityID, childActivityID, dataCount, (EventData*)data);
-
- if (status != 0)
- {
- SetLastError(status);
- return false;
- }
- return true;
- }
-
- internal unsafe bool WriteEventRaw(
- ref EventDescriptor eventDescriptor,
- IntPtr eventHandle,
- Guid* activityID,
- Guid* relatedActivityID,
- int dataCount,
- IntPtr data)
- {
- WriteEventErrorCode status = m_eventProvider.EventWriteTransfer(
- m_regHandle,
- in eventDescriptor,
- eventHandle,
- activityID,
- relatedActivityID,
- dataCount,
- (EventData*)data);
-
- if (status != WriteEventErrorCode.NoError)
- {
- SetLastError(status);
- return false;
- }
-
- return true;
- }
-
- // These are look-alikes to the Manifest based ETW OS APIs that have been shimmed to work
- // either with Manifest ETW or Classic ETW (if Manifest based ETW is not available).
- private unsafe uint EventRegister(EventSource eventSource, Interop.Advapi32.EtwEnableCallback enableCallback)
- {
- m_providerName = eventSource.Name;
- m_providerId = eventSource.Guid;
- m_etwCallback = enableCallback;
- return m_eventProvider.EventRegister(eventSource, enableCallback, null, ref m_regHandle);
- }
-
- private void EventUnregister(long registrationHandle) =>
- m_eventProvider.EventUnregister(registrationHandle);
-
-#if PLATFORM_WINDOWS
- private static bool m_setInformationMissing;
-
- internal unsafe int SetInformation(
- Interop.Advapi32.EVENT_INFO_CLASS eventInfoClass,
- IntPtr data,
- uint dataSize)
- {
- int status = Interop.Errors.ERROR_NOT_SUPPORTED;
-
- if (!m_setInformationMissing)
- {
- try
- {
- status = Interop.Advapi32.EventSetInformation(
- m_regHandle,
- eventInfoClass,
- (void*)data,
- (int)dataSize);
- }
- catch (TypeLoadException)
- {
- m_setInformationMissing = true;
- }
- }
-
- return status;
- }
-#endif
- }
-
-#if PLATFORM_WINDOWS
-
- // A wrapper around the ETW-specific API calls.
- internal sealed class EtwEventProvider : IEventProvider
- {
- // Register an event provider.
- unsafe uint IEventProvider.EventRegister(
- EventSource eventSource,
- Interop.Advapi32.EtwEnableCallback enableCallback,
- void* callbackContext,
- ref long registrationHandle)
- {
- Guid providerId = eventSource.Guid;
- return Interop.Advapi32.EventRegister(
- in providerId,
- enableCallback,
- callbackContext,
- ref registrationHandle);
- }
-
- // Unregister an event provider.
- uint IEventProvider.EventUnregister(long registrationHandle)
- {
- return Interop.Advapi32.EventUnregister(registrationHandle);
- }
-
- // Write an event.
- unsafe EventProvider.WriteEventErrorCode IEventProvider.EventWriteTransfer(
- long registrationHandle,
- in EventDescriptor eventDescriptor,
- IntPtr eventHandle,
- Guid* activityId,
- Guid* relatedActivityId,
- int userDataCount,
- EventProvider.EventData* userData)
- {
- int error = Interop.Advapi32.EventWriteTransfer(
- registrationHandle,
- in eventDescriptor,
- activityId,
- relatedActivityId,
- userDataCount,
- userData);
-
- switch (error)
- {
- case Interop.Errors.ERROR_ARITHMETIC_OVERFLOW:
- case Interop.Errors.ERROR_MORE_DATA:
- return EventProvider.WriteEventErrorCode.EventTooBig;
- case Interop.Errors.ERROR_NOT_ENOUGH_MEMORY:
- return EventProvider.WriteEventErrorCode.NoFreeBuffers;
- }
-
- return EventProvider.WriteEventErrorCode.NoError;
- }
-
- // Get or set the per-thread activity ID.
- int IEventProvider.EventActivityIdControl(Interop.Advapi32.ActivityControl ControlCode, ref Guid ActivityId)
- {
- return Interop.Advapi32.EventActivityIdControl(
- ControlCode,
- ref ActivityId);
- }
-
- // Define an EventPipeEvent handle.
- unsafe IntPtr IEventProvider.DefineEventHandle(uint eventID, string eventName, long keywords, uint eventVersion, uint level, byte* pMetadata, uint metadataLength)
- {
- throw new System.NotSupportedException();
- }
- }
-
-#endif
- internal sealed class NoOpEventProvider : IEventProvider
- {
- unsafe uint IEventProvider.EventRegister(
- EventSource eventSource,
- Interop.Advapi32.EtwEnableCallback enableCallback,
- void* callbackContext,
- ref long registrationHandle)
- {
- return 0;
- }
-
- uint IEventProvider.EventUnregister(long registrationHandle)
- {
- return 0;
- }
-
- unsafe EventProvider.WriteEventErrorCode IEventProvider.EventWriteTransfer(
- long registrationHandle,
- in EventDescriptor eventDescriptor,
- IntPtr eventHandle,
- Guid* activityId,
- Guid* relatedActivityId,
- int userDataCount,
- EventProvider.EventData* userData)
- {
- return EventProvider.WriteEventErrorCode.NoError;
- }
-
- int IEventProvider.EventActivityIdControl(Interop.Advapi32.ActivityControl ControlCode, ref Guid ActivityId)
- {
- return 0;
- }
-
- // Define an EventPipeEvent handle.
- unsafe IntPtr IEventProvider.DefineEventHandle(uint eventID, string eventName, long keywords, uint eventVersion, uint level, byte* pMetadata, uint metadataLength)
- {
- return IntPtr.Zero;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs
deleted file mode 100644
index e639f7c610c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs
+++ /dev/null
@@ -1,6204 +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.
-
-// This program uses code hyperlinks available as part of the HyperAddin Visual Studio plug-in.
-// It is available from http://www.codeplex.com/hyperAddin
-#if ES_BUILD_STANDALONE
-#define FEATURE_MANAGED_ETW_CHANNELS
-// #define FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
-#endif
-
-/* DESIGN NOTES DESIGN NOTES DESIGN NOTES DESIGN NOTES */
-// DESIGN NOTES
-// Over the years EventSource has become more complex and so it is important to understand
-// the basic structure of the code to insure that it does not grow more complex.
-//
-// Basic Model
-//
-// PRINCIPLE: EventSource - ETW decoupling
-//
-// Conceptually an EventSouce is something that takes event logging data from the source methods
-// to the EventListener that can subscribe to them. Note that CONCEPTUALLY EVENTSOURCES DON'T
-// KNOW ABOUT ETW!. The MODEL of the system is that there is a special EventListener which
-// we will call the EtwEventListener, that forwards commands from ETW to EventSources and
-// listens to EventSources and forwards on those events to ETW. Thus the model should
-// be that you DON'T NEED ETW.
-//
-// Now in actual practice, EventSouce have rather intimate knowledge of ETW and send events
-// to it directly, but this can be VIEWED AS AN OPTIMIZATION.
-//
-// Basic Event Data Flow:
-//
-// There are two ways for event Data to enter the system
-// 1) WriteEvent* and friends. This is called the 'contract' based approach because
-// you write a method per event which forms a contract that is know at compile time.
-// In this scheme each event is given an EVENTID (small integer), which is its identity
-// 2) Write<T> methods. This is called the 'dynamic' approach because new events
-// can be created on the fly. Event identity is determined by the event NAME, and these
-// are not quite as efficient at runtime since you have at least a hash table lookup
-// on every event write.
-//
-// EventSource-EventListener transfer fully supports both ways of writing events (either contract
-// based (WriteEvent*) or dynamic (Write<T>)). Both ways fully support the same set of data
-// types. It is recommended, however, that you use the contract based approach when the event scheme
-// is known at compile time (that is whenever possible). It is more efficient, but more importantly
-// it makes the contract very explicit, and centralizes all policy about logging. These are good
-// things. The Write<T> API is really meant for more ad-hoc cases.
-//
-// Allowed Data:
-//
-// Note that EventSource-EventListeners have a conceptual serialization-deserialization that happens
-// during the transfer. In particular object identity is not preserved, some objects are morphed,
-// and not all data types are supported. In particular you can pass
-//
-// A Valid type to log to an EventSource include
-// * Primitive data types
-// * IEnumerable<T> of valid types T (this include arrays) (* New for V4.6)
-// * Explicitly Opted in class or struct with public property Getters over Valid types. (* New for V4.6)
-//
-// This set of types is roughly a generalization of JSON support (basically primitives, bags, and arrays).
-//
-// Explicitly allowed structs include (* New for V4.6)
-// * Marked with the EventData attribute
-// * implicitly defined (e.g the C# new {x = 3, y = 5} syntax)
-// * KeyValuePair<K,V> (thus dictionaries can be passed since they are an IEnumerable of KeyValuePair)
-//
-// When classes are returned in an EventListener, what is returned is something that implements
-// IDictionary<string, T>. Thus when objects are passed to an EventSource they are transformed
-// into a key-value bag (the IDictionary<string, T>) for consumption in the listener. These
-// are obviously NOT the original objects.
-//
-// ETW serialization formats:
-//
-// As mentioned, conceptually EventSources send data to EventListeners and there is a conceptual
-// copy/morph of that data as described above. In addition the .NET framework supports a conceptual
-// ETWListener that will send the data to the ETW stream. If you use this feature, the data needs
-// to be serialized in a way that ETW supports. ETW supports the following serialization formats
-//
-// 1) Manifest Based serialization.
-// 2) SelfDescribing serialization (TraceLogging style in the TraceLogging directory)
-//
-// A key factor is that the Write<T> method, which supports on the fly definition of events, can't
-// support the manifest based serialization because the manifest needs the schema of all events
-// to be known before any events are emitted. This implies the following:
-//
-// If you use Write<T> and the output goes to ETW it will use the SelfDescribing format.
-// If you use the EventSource(string) constructor for an eventSource (in which you don't
-// create a subclass), the default is also to use Self-Describing serialization. In addition
-// you can use the EventSoruce(EventSourceSettings) constructor to also explicitly specify
-// Self-Describing serialization format. These affect the WriteEvent* APIs going to ETW.
-//
-// Note that none of this ETW serialization logic affects EventListeners. Only the ETW listener.
-//
-// *************************************************************************************
-// *** INTERNALS: Event Propagation
-//
-// Data enters the system either though
-//
-// 1) A user defined method in the user defined subclass of EventSource which calls
-// A) A typesafe type specific overload of WriteEvent(ID, ...) e.g. WriteEvent(ID, string, string)
-// * which calls into the unsafe WriteEventCore(ID COUNT EventData*) WriteEventWithRelatedActivityIdCore()
-// B) The typesafe overload WriteEvent(ID, object[]) which calls the private helper WriteEventVarargs(ID, Guid* object[])
-// C) Directly into the unsafe WriteEventCore(ID, COUNT EventData*) or WriteEventWithRelatedActivityIdCore()
-//
-// All event data eventually flows to one of
-// * WriteEventWithRelatedActivityIdCore(ID, Guid*, COUNT, EventData*)
-// * WriteEventVarargs(ID, Guid*, object[])
-//
-// 2) A call to one of the overloads of Write<T>. All these overloads end up in
-// * WriteImpl<T>(EventName, Options, Data, Guid*, Guid*)
-//
-// On output there are the following routines
-// Writing to all listeners that are NOT ETW, we have the following routines
-// * WriteToAllListeners(ID, Guid*, Guid*, COUNT, EventData*)
-// * WriteToAllListeners(ID, Guid*, Guid*, object[])
-// * WriteToAllListeners(NAME, Guid*, Guid*, EventPayload)
-//
-// EventPayload is the internal type that implements the IDictionary<string, object> interface
-// The EventListeners will pass back for serialized classes for nested object, but
-// WriteToAllListeners(NAME, Guid*, Guid*, EventPayload) unpacks this and uses the fields as if they
-// were parameters to a method.
-//
-// The first two are used for the WriteEvent* case, and the later is used for the Write<T> case.
-//
-// Writing to ETW, Manifest Based
-// EventProvider.WriteEvent(EventDescriptor, Guid*, COUNT, EventData*)
-// EventProvider.WriteEvent(EventDescriptor, Guid*, object[])
-// Writing to ETW, Self-Describing format
-// WriteMultiMerge(NAME, Options, Types, EventData*)
-// WriteMultiMerge(NAME, Options, Types, object[])
-// WriteImpl<T> has logic that knows how to serialize (like WriteMultiMerge) but also knows
-// where it will write it to
-//
-// All ETW writes eventually call
-// EventWriteTransfer
-// EventProvider.WriteEventRaw - sets last error
-// EventSource.WriteEventRaw - Does EventSource exception handling logic
-// WriteMultiMerge
-// WriteImpl<T>
-// EventProvider.WriteEvent(EventDescriptor, Guid*, COUNT, EventData*)
-// EventProvider.WriteEvent(EventDescriptor, Guid*, object[])
-//
-// Serialization: We have a bit of a hodge-podge of serializers right now. Only the one for ETW knows
-// how to deal with nested classes or arrays. I will call this serializer the 'TypeInfo' serializer
-// since it is the TraceLoggingTypeInfo structure that knows how to do this. Effectively for a type you
-// can call one of these
-// WriteMetadata - transforms the type T into serialization meta data blob for that type
-// WriteObjectData - transforms an object of T into serialization data blob for that instance
-// GetData - transforms an object of T into its deserialized form suitable for passing to EventListener.
-// The first two are used to serialize something for ETW. The second one is used to transform the object
-// for use by the EventListener. We also have a 'DecodeObject' method that will take a EventData* and
-// deserialize to pass to an EventListener, but it only works on primitive types (types supported in version V4.5).
-//
-// It is an important observation that while EventSource does support users directly calling with EventData*
-// blobs, we ONLY support that for the primitive types (V4.5 level support). Thus while there is a EventData*
-// path through the system it is only for some types. The object[] path is the more general (but less efficient) path.
-//
-// TODO There is cleanup needed There should be no divergence until WriteEventRaw.
-//
-// TODO: We should have a single choke point (right now we always have this parallel EventData* and object[] path. This
-// was historical (at one point we tried to pass object directly from EventSoruce to EventListener. That was always
-// fragile and a compatibility headache, but we have finally been forced into the idea that there is always a transformation.
-// This allows us to use the EventData* form to be the canonical data format in the low level APIs. This also gives us the
-// opportunity to expose this format to EventListeners in the future.
-//
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-using System.Security.Permissions;
-using EventDescriptor = Microsoft.Diagnostics.Tracing.EventDescriptor;
-using BitOperations = Microsoft.Diagnostics.Tracing.Internal.BitOperations;
-#else
-using System.Threading.Tasks;
-#endif
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.Numerics;
-using System.Reflection;
-using System.Resources;
-using System.Text;
-using System.Threading;
-using Microsoft.Reflection;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// This class is meant to be inherited by a user-defined event source in order to define a managed
- /// ETW provider. Please See DESIGN NOTES above for the internal architecture.
- /// The minimal definition of an EventSource simply specifies a number of ETW event methods that
- /// call one of the EventSource.WriteEvent overloads, <see cref="EventSource.WriteEventCore"/>,
- /// or <see cref="EventSource.WriteEventWithRelatedActivityIdCore"/> to log them. This functionality
- /// is sufficient for many users.
- /// <para>
- /// To achieve more control over the ETW provider manifest exposed by the event source type, the
- /// [<see cref="EventAttribute"/>] attributes can be specified for the ETW event methods.
- /// </para><para>
- /// For very advanced EventSources, it is possible to intercept the commands being given to the
- /// eventSource and change what filtering is done (see EventListener.EnableEvents and
- /// <see cref="EventListener.DisableEvents"/>) or cause actions to be performed by the eventSource,
- /// e.g. dumping a data structure (see EventSource.SendCommand and
- /// <see cref="EventSource.OnEventCommand"/>).
- /// </para><para>
- /// The eventSources can be turned on with Windows ETW controllers (e.g. logman), immediately.
- /// It is also possible to control and intercept the data dispatcher programmatically. See
- /// <see cref="EventListener"/> for more.
- /// </para>
- /// </summary>
- /// <remarks>
- /// This is a minimal definition for a custom event source:
- /// <code>
- /// [EventSource(Name="Samples-Demos-Minimal")]
- /// sealed class MinimalEventSource : EventSource
- /// {
- /// public static MinimalEventSource Log = new MinimalEventSource();
- /// public void Load(long ImageBase, string Name) { WriteEvent(1, ImageBase, Name); }
- /// public void Unload(long ImageBase) { WriteEvent(2, ImageBase); }
- /// private MinimalEventSource() {}
- /// }
- /// </code>
- /// </remarks>
- public partial class EventSource : IDisposable
- {
-#if FEATURE_EVENTSOURCE_XPLAT
-#pragma warning disable CA1823 // field is used to keep listener alive
- private static readonly EventListener? persistent_Xplat_Listener = XplatEventLogger.InitializePersistentListener();
-#pragma warning restore CA1823
-#endif //FEATURE_EVENTSOURCE_XPLAT
-
- /// <summary>
- /// The human-friendly name of the eventSource. It defaults to the simple name of the class
- /// </summary>
- public string Name => m_name;
- /// <summary>
- /// Every eventSource is assigned a GUID to uniquely identify it to the system.
- /// </summary>
- public Guid Guid => m_guid;
-
- /// <summary>
- /// Returns true if the eventSource has been enabled at all. This is the preferred test
- /// to be performed before a relatively expensive EventSource operation.
- /// </summary>
- public bool IsEnabled()
- {
- return m_eventSourceEnabled;
- }
-
- /// <summary>
- /// Returns true if events with greater than or equal 'level' and have one of 'keywords' set are enabled.
- ///
- /// Note that the result of this function is only an approximation on whether a particular
- /// event is active or not. It is only meant to be used as way of avoiding expensive
- /// computation for logging when logging is not on, therefore it sometimes returns false
- /// positives (but is always accurate when returning false). EventSources are free to
- /// have additional filtering.
- /// </summary>
- public bool IsEnabled(EventLevel level, EventKeywords keywords)
- {
- return IsEnabled(level, keywords, EventChannel.None);
- }
-
- /// <summary>
- /// Returns true if events with greater than or equal 'level' and have one of 'keywords' set are enabled, or
- /// if 'keywords' specifies a channel bit for a channel that is enabled.
- ///
- /// Note that the result of this function only an approximation on whether a particular
- /// event is active or not. It is only meant to be used as way of avoiding expensive
- /// computation for logging when logging is not on, therefore it sometimes returns false
- /// positives (but is always accurate when returning false). EventSources are free to
- /// have additional filtering.
- /// </summary>
- public bool IsEnabled(EventLevel level, EventKeywords keywords, EventChannel channel)
- {
- if (!m_eventSourceEnabled)
- return false;
-
- if (!IsEnabledCommon(m_eventSourceEnabled, m_level, m_matchAnyKeyword, level, keywords, channel))
- return false;
-
- return true;
- }
-
- /// <summary>
- /// Returns the settings for the event source instance
- /// </summary>
- public EventSourceSettings Settings => m_config;
-
- // Manifest support
- /// <summary>
- /// Returns the GUID that uniquely identifies the eventSource defined by 'eventSourceType'.
- /// This API allows you to compute this without actually creating an instance of the EventSource.
- /// It only needs to reflect over the type.
- /// </summary>
- public static Guid GetGuid(Type eventSourceType)
- {
- if (eventSourceType == null)
- throw new ArgumentNullException(nameof(eventSourceType));
-
- EventSourceAttribute? attrib = (EventSourceAttribute?)GetCustomAttributeHelper(eventSourceType, typeof(EventSourceAttribute));
- string name = eventSourceType.Name;
- if (attrib != null)
- {
- if (attrib.Guid != null)
- {
-#if !ES_BUILD_AGAINST_DOTNET_V35
- if (Guid.TryParse(attrib.Guid, out Guid g))
- return g;
-#else
- try { return new Guid(attrib.Guid); }
- catch (Exception) { }
-#endif
- }
-
- if (attrib.Name != null)
- name = attrib.Name;
- }
-
- if (name == null)
- {
- throw new ArgumentException(SR.Argument_InvalidTypeName, nameof(eventSourceType));
- }
- return GenerateGuidFromName(name.ToUpperInvariant()); // Make it case insensitive.
- }
- /// <summary>
- /// Returns the official ETW Provider name for the eventSource defined by 'eventSourceType'.
- /// This API allows you to compute this without actually creating an instance of the EventSource.
- /// It only needs to reflect over the type.
- /// </summary>
- public static string GetName(Type eventSourceType)
- {
- return GetName(eventSourceType, EventManifestOptions.None);
- }
-
- /// <summary>
- /// Returns a string of the XML manifest associated with the eventSourceType. The scheme for this XML is
- /// documented at in EventManifest Schema https://docs.microsoft.com/en-us/windows/desktop/WES/eventmanifestschema-schema.
- /// This is the preferred way of generating a manifest to be embedded in the ETW stream as it is fast and
- /// the fact that it only includes localized entries for the current UI culture is an acceptable tradeoff.
- /// </summary>
- /// <param name="eventSourceType">The type of the event source class for which the manifest is generated</param>
- /// <param name="assemblyPathToIncludeInManifest">The manifest XML fragment contains the string name of the DLL name in
- /// which it is embedded. This parameter specifies what name will be used</param>
- /// <returns>The XML data string</returns>
- public static string? GenerateManifest(Type eventSourceType, string? assemblyPathToIncludeInManifest)
- {
- return GenerateManifest(eventSourceType, assemblyPathToIncludeInManifest, EventManifestOptions.None);
- }
- /// <summary>
- /// Returns a string of the XML manifest associated with the eventSourceType. The scheme for this XML is
- /// documented at in EventManifest Schema https://docs.microsoft.com/en-us/windows/desktop/WES/eventmanifestschema-schema.
- /// Pass EventManifestOptions.AllCultures when generating a manifest to be registered on the machine. This
- /// ensures that the entries in the event log will be "optimally" localized.
- /// </summary>
- /// <param name="eventSourceType">The type of the event source class for which the manifest is generated</param>
- /// <param name="assemblyPathToIncludeInManifest">The manifest XML fragment contains the string name of the DLL name in
- /// which it is embedded. This parameter specifies what name will be used</param>
- /// <param name="flags">The flags to customize manifest generation. If flags has bit OnlyIfNeededForRegistration specified
- /// this returns null when the eventSourceType does not require explicit registration</param>
- /// <returns>The XML data string or null</returns>
- public static string? GenerateManifest(Type eventSourceType, string? assemblyPathToIncludeInManifest, EventManifestOptions flags)
- {
- if (eventSourceType == null)
- throw new ArgumentNullException(nameof(eventSourceType));
-
- byte[]? manifestBytes = EventSource.CreateManifestAndDescriptors(eventSourceType, assemblyPathToIncludeInManifest, null, flags);
- return (manifestBytes == null) ? null : Encoding.UTF8.GetString(manifestBytes, 0, manifestBytes.Length);
- }
-
- // EventListener support
- /// <summary>
- /// returns a list (IEnumerable) of all sources in the appdomain). EventListeners typically need this.
- /// </summary>
- /// <returns></returns>
- public static IEnumerable<EventSource> GetSources()
- {
- var ret = new List<EventSource>();
- lock (EventListener.EventListenersLock)
- {
- Debug.Assert(EventListener.s_EventSources != null);
-
- foreach (WeakReference<EventSource> eventSourceRef in EventListener.s_EventSources)
- {
- if (eventSourceRef.TryGetTarget(out EventSource? eventSource) && !eventSource.IsDisposed)
- ret.Add(eventSource);
- }
- }
- return ret;
- }
-
- /// <summary>
- /// Send a command to a particular EventSource identified by 'eventSource'.
- /// Calling this routine simply forwards the command to the EventSource.OnEventCommand
- /// callback. What the EventSource does with the command and its arguments are from
- /// that point EventSource-specific.
- /// </summary>
- /// <param name="eventSource">The instance of EventSource to send the command to</param>
- /// <param name="command">A positive user-defined EventCommand, or EventCommand.SendManifest</param>
- /// <param name="commandArguments">A set of (name-argument, value-argument) pairs associated with the command</param>
- public static void SendCommand(EventSource eventSource, EventCommand command, IDictionary<string, string?>? commandArguments)
- {
- if (eventSource == null)
- throw new ArgumentNullException(nameof(eventSource));
-
- // User-defined EventCommands should not conflict with the reserved commands.
- if ((int)command <= (int)EventCommand.Update && (int)command != (int)EventCommand.SendManifest)
- {
- throw new ArgumentException(SR.EventSource_InvalidCommand, nameof(command));
- }
-
- eventSource.SendCommand(null, EventProviderType.ETW, 0, 0, command, true, EventLevel.LogAlways, EventKeywords.None, commandArguments);
- }
-
- // Error APIs. (We don't throw by default, but you can probe for status)
- /// <summary>
- /// Because
- ///
- /// 1) Logging is often optional and thus should not generate fatal errors (exceptions)
- /// 2) EventSources are often initialized in class constructors (which propagate exceptions poorly)
- ///
- /// The event source constructor does not throw exceptions. Instead we remember any exception that
- /// was generated (it is also logged to Trace.WriteLine).
- /// </summary>
- public Exception? ConstructionException => m_constructionException;
-
- /// <summary>
- /// EventSources can have arbitrary string key-value pairs associated with them called Traits.
- /// These traits are not interpreted by the EventSource but may be interpreted by EventListeners
- /// (e.g. like the built in ETW listener). These traits are specified at EventSource
- /// construction time and can be retrieved by using this GetTrait API.
- /// </summary>
- /// <param name="key">The key to look up in the set of key-value pairs passed to the EventSource constructor</param>
- /// <returns>The value string associated with key. Will return null if there is no such key.</returns>
- public string? GetTrait(string key)
- {
- if (m_traits != null)
- {
- for (int i = 0; i < m_traits.Length - 1; i += 2)
- {
- if (m_traits[i] == key)
- return m_traits[i + 1];
- }
- }
-
- return null;
- }
-
- /// <summary>
- /// Displays the name and GUID for the eventSource for debugging purposes.
- /// </summary>
- public override string ToString()
- {
- return SR.Format(SR.EventSource_ToString, Name, Guid);
- }
-
- /// <summary>
- /// Fires when a Command (e.g. Enable) comes from a an EventListener.
- /// </summary>
- public event EventHandler<EventCommandEventArgs>? EventCommandExecuted
- {
- add
- {
- if (value == null)
- return;
-
- m_eventCommandExecuted += value;
-
- // If we have an EventHandler<EventCommandEventArgs> attached to the EventSource before the first command arrives
- // It should get a chance to handle the deferred commands.
- EventCommandEventArgs? deferredCommands = m_deferredCommands;
- while (deferredCommands != null)
- {
- value(this, deferredCommands);
- deferredCommands = deferredCommands.nextCommand;
- }
- }
- remove
- {
- m_eventCommandExecuted -= value;
- }
- }
-
-#region ActivityID
-
- /// <summary>
- /// When a thread starts work that is on behalf of 'something else' (typically another
- /// thread or network request) it should mark the thread as working on that other work.
- /// This API marks the current thread as working on activity 'activityID'. This API
- /// should be used when the caller knows the thread's current activity (the one being
- /// overwritten) has completed. Otherwise, callers should prefer the overload that
- /// return the oldActivityThatWillContinue (below).
- ///
- /// All events created with the EventSource on this thread are also tagged with the
- /// activity ID of the thread.
- ///
- /// It is common, and good practice after setting the thread to an activity to log an event
- /// with a 'start' opcode to indicate that precise time/thread where the new activity
- /// started.
- /// </summary>
- /// <param name="activityId">A Guid that represents the new activity with which to mark
- /// the current thread</param>
- public static void SetCurrentThreadActivityId(Guid activityId)
- {
- if (TplEventSource.Log != null)
- TplEventSource.Log.SetActivityId(activityId);
-
- // We ignore errors to keep with the convention that EventSources do not throw errors.
- // Note we can't access m_throwOnWrites because this is a static method.
-#if FEATURE_MANAGED_ETW
-#if FEATURE_PERFTRACING
- // Set the activity id via EventPipe.
- EventPipeInternal.EventActivityIdControl(
- (uint)Interop.Advapi32.ActivityControl.EVENT_ACTIVITY_CTRL_SET_ID,
- ref activityId);
-#endif // FEATURE_PERFTRACING
-#if PLATFORM_WINDOWS
- // Set the activity id via ETW.
- Interop.Advapi32.EventActivityIdControl(
- Interop.Advapi32.ActivityControl.EVENT_ACTIVITY_CTRL_SET_ID,
- ref activityId);
-#endif // PLATFORM_WINDOWS
-#endif // FEATURE_MANAGED_ETW
- }
-
- /// <summary>
- /// Retrieves the ETW activity ID associated with the current thread.
- /// </summary>
- public static Guid CurrentThreadActivityId
- {
- get
- {
- // We ignore errors to keep with the convention that EventSources do not throw
- // errors. Note we can't access m_throwOnWrites because this is a static method.
- Guid retVal = default;
-#if FEATURE_MANAGED_ETW
-#if PLATFORM_WINDOWS
- Interop.Advapi32.EventActivityIdControl(
- Interop.Advapi32.ActivityControl.EVENT_ACTIVITY_CTRL_GET_ID,
- ref retVal);
-#elif FEATURE_PERFTRACING
- EventPipeInternal.EventActivityIdControl(
- (uint)Interop.Advapi32.ActivityControl.EVENT_ACTIVITY_CTRL_GET_ID,
- ref retVal);
-#endif // PLATFORM_WINDOWS
-#endif // FEATURE_MANAGED_ETW
- return retVal;
- }
- }
-
- /// <summary>
- /// When a thread starts work that is on behalf of 'something else' (typically another
- /// thread or network request) it should mark the thread as working on that other work.
- /// This API marks the current thread as working on activity 'activityID'. It returns
- /// whatever activity the thread was previously marked with. There is a convention that
- /// callers can assume that callees restore this activity mark before the callee returns.
- /// To encourage this, this API returns the old activity, so that it can be restored later.
- ///
- /// All events created with the EventSource on this thread are also tagged with the
- /// activity ID of the thread.
- ///
- /// It is common, and good practice after setting the thread to an activity to log an event
- /// with a 'start' opcode to indicate that precise time/thread where the new activity
- /// started.
- /// </summary>
- /// <param name="activityId">A Guid that represents the new activity with which to mark
- /// the current thread</param>
- /// <param name="oldActivityThatWillContinue">The Guid that represents the current activity
- /// which will continue at some point in the future, on the current thread</param>
- public static void SetCurrentThreadActivityId(Guid activityId, out Guid oldActivityThatWillContinue)
- {
- oldActivityThatWillContinue = activityId;
-#if FEATURE_MANAGED_ETW
- // We ignore errors to keep with the convention that EventSources do not throw errors.
- // Note we can't access m_throwOnWrites because this is a static method.
-
-#if FEATURE_PERFTRACING && PLATFORM_WINDOWS
- EventPipeInternal.EventActivityIdControl(
- (uint)Interop.Advapi32.ActivityControl.EVENT_ACTIVITY_CTRL_SET_ID,
- ref oldActivityThatWillContinue);
-#elif FEATURE_PERFTRACING
- EventPipeInternal.EventActivityIdControl(
- (uint)Interop.Advapi32.ActivityControl.EVENT_ACTIVITY_CTRL_GET_SET_ID,
- ref oldActivityThatWillContinue);
-#endif // FEATURE_PERFTRACING && PLATFORM_WINDOWS
-
-#if PLATFORM_WINDOWS
- Interop.Advapi32.EventActivityIdControl(
- Interop.Advapi32.ActivityControl.EVENT_ACTIVITY_CTRL_GET_SET_ID,
- ref oldActivityThatWillContinue);
-#endif // PLATFORM_WINDOWS
-#endif // FEATURE_MANAGED_ETW
-
- // We don't call the activityDying callback here because the caller has declared that
- // it is not dying.
- if (TplEventSource.Log != null)
- TplEventSource.Log.SetActivityId(activityId);
- }
-#endregion
-
-#region protected
- /// <summary>
- /// This is the constructor that most users will use to create their eventSource. It takes
- /// no parameters. The ETW provider name and GUID of the EventSource are determined by the EventSource
- /// custom attribute (so you can determine these things declaratively). If the GUID for the eventSource
- /// is not specified in the EventSourceAttribute (recommended), it is Generated by hashing the name.
- /// If the ETW provider name of the EventSource is not given, the name of the EventSource class is used as
- /// the ETW provider name.
- /// </summary>
- protected EventSource()
- : this(EventSourceSettings.EtwManifestEventFormat)
- {
- }
-
- /// <summary>
- /// By default calling the 'WriteEvent' methods do NOT throw on errors (they silently discard the event).
- /// This is because in most cases users assume logging is not 'precious' and do NOT wish to have logging failures
- /// crash the program. However for those applications where logging is 'precious' and if it fails the caller
- /// wishes to react, setting 'throwOnEventWriteErrors' will cause an exception to be thrown if WriteEvent
- /// fails. Note the fact that EventWrite succeeds does not necessarily mean that the event reached its destination
- /// only that operation of writing it did not fail. These EventSources will not generate self-describing ETW events.
- ///
- /// For compatibility only use the EventSourceSettings.ThrowOnEventWriteErrors flag instead.
- /// </summary>
- // [Obsolete("Use the EventSource(EventSourceSettings) overload")]
- protected EventSource(bool throwOnEventWriteErrors)
- : this(EventSourceSettings.EtwManifestEventFormat | (throwOnEventWriteErrors ? EventSourceSettings.ThrowOnEventWriteErrors : 0))
- { }
-
- /// <summary>
- /// Construct an EventSource with additional non-default settings (see EventSourceSettings for more)
- /// </summary>
- protected EventSource(EventSourceSettings settings) : this(settings, null) { }
-
- /// <summary>
- /// Construct an EventSource with additional non-default settings.
- ///
- /// Also specify a list of key-value pairs called traits (you must pass an even number of strings).
- /// The first string is the key and the second is the value. These are not interpreted by EventSource
- /// itself but may be interpreted the listeners. Can be fetched with GetTrait(string).
- /// </summary>
- /// <param name="settings">See EventSourceSettings for more.</param>
- /// <param name="traits">A collection of key-value strings (must be an even number).</param>
- protected EventSource(EventSourceSettings settings, params string[]? traits)
- {
- m_config = ValidateSettings(settings);
-
- Guid eventSourceGuid;
- string? eventSourceName;
-
- GetMetadata(out eventSourceGuid, out eventSourceName, out _, out _);
-
- if (eventSourceGuid.Equals(Guid.Empty) || eventSourceName == null)
- {
- Type myType = this.GetType();
- eventSourceGuid = GetGuid(myType);
- eventSourceName = GetName(myType);
- }
-
- Initialize(eventSourceGuid, eventSourceName, traits);
- }
-
-#if FEATURE_PERFTRACING
- // Generate the serialized blobs that describe events for all strongly typed events (that is events that define strongly
- // typed event methods. Dynamically defined events (that use Write) hare defined on the fly and are handled elsewhere.
- private unsafe void DefineEventPipeEvents()
- {
- // If the EventSource is set to emit all events as TraceLogging events, skip this initialization.
- // Events will be defined when they are emitted for the first time.
- if (SelfDescribingEvents)
- {
- return;
- }
-
- Debug.Assert(m_eventData != null);
- Debug.Assert(m_eventPipeProvider != null);
- int cnt = m_eventData.Length;
- for (int i = 0; i < cnt; i++)
- {
- uint eventID = (uint)m_eventData[i].Descriptor.EventId;
- if (eventID == 0)
- continue;
-
- byte[]? metadata = EventPipeMetadataGenerator.Instance.GenerateEventMetadata(m_eventData[i]);
- uint metadataLength = (metadata != null) ? (uint)metadata.Length : 0;
-
- string eventName = m_eventData[i].Name;
- long keywords = m_eventData[i].Descriptor.Keywords;
- uint eventVersion = m_eventData[i].Descriptor.Version;
- uint level = m_eventData[i].Descriptor.Level;
-
- fixed (byte* pMetadata = metadata)
- {
- IntPtr eventHandle = m_eventPipeProvider.m_eventProvider.DefineEventHandle(
- eventID,
- eventName,
- keywords,
- eventVersion,
- level,
- pMetadata,
- metadataLength);
-
- Debug.Assert(eventHandle != IntPtr.Zero);
- m_eventData[i].EventHandle = eventHandle;
- }
- }
- }
-#endif
-
- internal virtual void GetMetadata(out Guid eventSourceGuid, out string? eventSourceName, out EventMetadata[]? eventData, out byte[]? manifestBytes)
- {
- //
- // In ProjectN subclasses need to override this method, and return the data from their EventSourceAttribute and EventAttribute annotations.
- // On other architectures it is a no-op.
- //
- // eventDescriptors needs to contain one EventDescriptor for each event; the event's ID should be the same as its index in this array.
- // manifestBytes is a UTF-8 encoding of the ETW manifest for the type.
- //
- // This will be implemented by an IL rewriter, so we can't make this method abstract or the initial build of the subclass would fail.
- //
- eventSourceGuid = Guid.Empty;
- eventSourceName = null;
- eventData = null;
- manifestBytes = null;
-
- return;
- }
-
- /// <summary>
- /// This method is called when the eventSource is updated by the controller.
- /// </summary>
- protected virtual void OnEventCommand(EventCommandEventArgs command) { }
-
-#pragma warning disable 1591
- // optimized for common signatures (no args)
- protected unsafe void WriteEvent(int eventId)
- {
- WriteEventCore(eventId, 0, null);
- }
-
- // optimized for common signatures (ints)
- protected unsafe void WriteEvent(int eventId, int arg1)
- {
- if (m_eventSourceEnabled)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[1];
- descrs[0].DataPointer = (IntPtr)(&arg1);
- descrs[0].Size = 4;
- descrs[0].Reserved = 0;
- WriteEventCore(eventId, 1, descrs);
- }
- }
-
- protected unsafe void WriteEvent(int eventId, int arg1, int arg2)
- {
- if (m_eventSourceEnabled)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
- descrs[0].DataPointer = (IntPtr)(&arg1);
- descrs[0].Size = 4;
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)(&arg2);
- descrs[1].Size = 4;
- descrs[1].Reserved = 0;
- WriteEventCore(eventId, 2, descrs);
- }
- }
-
- protected unsafe void WriteEvent(int eventId, int arg1, int arg2, int arg3)
- {
- if (m_eventSourceEnabled)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
- descrs[0].DataPointer = (IntPtr)(&arg1);
- descrs[0].Size = 4;
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)(&arg2);
- descrs[1].Size = 4;
- descrs[1].Reserved = 0;
- descrs[2].DataPointer = (IntPtr)(&arg3);
- descrs[2].Size = 4;
- descrs[2].Reserved = 0;
- WriteEventCore(eventId, 3, descrs);
- }
- }
-
- // optimized for common signatures (longs)
- protected unsafe void WriteEvent(int eventId, long arg1)
- {
- if (m_eventSourceEnabled)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[1];
- descrs[0].DataPointer = (IntPtr)(&arg1);
- descrs[0].Size = 8;
- descrs[0].Reserved = 0;
- WriteEventCore(eventId, 1, descrs);
- }
- }
-
- protected unsafe void WriteEvent(int eventId, long arg1, long arg2)
- {
- if (m_eventSourceEnabled)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
- descrs[0].DataPointer = (IntPtr)(&arg1);
- descrs[0].Size = 8;
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)(&arg2);
- descrs[1].Size = 8;
- descrs[1].Reserved = 0;
- WriteEventCore(eventId, 2, descrs);
- }
- }
-
- protected unsafe void WriteEvent(int eventId, long arg1, long arg2, long arg3)
- {
- if (m_eventSourceEnabled)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
- descrs[0].DataPointer = (IntPtr)(&arg1);
- descrs[0].Size = 8;
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)(&arg2);
- descrs[1].Size = 8;
- descrs[1].Reserved = 0;
- descrs[2].DataPointer = (IntPtr)(&arg3);
- descrs[2].Size = 8;
- descrs[2].Reserved = 0;
- WriteEventCore(eventId, 3, descrs);
- }
- }
-
- // optimized for common signatures (strings)
- protected unsafe void WriteEvent(int eventId, string? arg1)
- {
- if (m_eventSourceEnabled)
- {
- arg1 ??= "";
- fixed (char* string1Bytes = arg1)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[1];
- descrs[0].DataPointer = (IntPtr)string1Bytes;
- descrs[0].Size = ((arg1.Length + 1) * 2);
- descrs[0].Reserved = 0;
- WriteEventCore(eventId, 1, descrs);
- }
- }
- }
-
- protected unsafe void WriteEvent(int eventId, string? arg1, string? arg2)
- {
- if (m_eventSourceEnabled)
- {
- arg1 ??= "";
- arg2 ??= "";
- fixed (char* string1Bytes = arg1)
- fixed (char* string2Bytes = arg2)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
- descrs[0].DataPointer = (IntPtr)string1Bytes;
- descrs[0].Size = ((arg1.Length + 1) * 2);
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)string2Bytes;
- descrs[1].Size = ((arg2.Length + 1) * 2);
- descrs[1].Reserved = 0;
- WriteEventCore(eventId, 2, descrs);
- }
- }
- }
-
- protected unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3)
- {
- if (m_eventSourceEnabled)
- {
- arg1 ??= "";
- arg2 ??= "";
- arg3 ??= "";
- fixed (char* string1Bytes = arg1)
- fixed (char* string2Bytes = arg2)
- fixed (char* string3Bytes = arg3)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
- descrs[0].DataPointer = (IntPtr)string1Bytes;
- descrs[0].Size = ((arg1.Length + 1) * 2);
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)string2Bytes;
- descrs[1].Size = ((arg2.Length + 1) * 2);
- descrs[1].Reserved = 0;
- descrs[2].DataPointer = (IntPtr)string3Bytes;
- descrs[2].Size = ((arg3.Length + 1) * 2);
- descrs[2].Reserved = 0;
- WriteEventCore(eventId, 3, descrs);
- }
- }
- }
-
- // optimized for common signatures (string and ints)
- protected unsafe void WriteEvent(int eventId, string? arg1, int arg2)
- {
- if (m_eventSourceEnabled)
- {
- arg1 ??= "";
- fixed (char* string1Bytes = arg1)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
- descrs[0].DataPointer = (IntPtr)string1Bytes;
- descrs[0].Size = ((arg1.Length + 1) * 2);
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)(&arg2);
- descrs[1].Size = 4;
- descrs[1].Reserved = 0;
- WriteEventCore(eventId, 2, descrs);
- }
- }
- }
-
- protected unsafe void WriteEvent(int eventId, string? arg1, int arg2, int arg3)
- {
- if (m_eventSourceEnabled)
- {
- arg1 ??= "";
- fixed (char* string1Bytes = arg1)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
- descrs[0].DataPointer = (IntPtr)string1Bytes;
- descrs[0].Size = ((arg1.Length + 1) * 2);
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)(&arg2);
- descrs[1].Size = 4;
- descrs[1].Reserved = 0;
- descrs[2].DataPointer = (IntPtr)(&arg3);
- descrs[2].Size = 4;
- descrs[2].Reserved = 0;
- WriteEventCore(eventId, 3, descrs);
- }
- }
- }
-
- // optimized for common signatures (string and longs)
- protected unsafe void WriteEvent(int eventId, string? arg1, long arg2)
- {
- if (m_eventSourceEnabled)
- {
- arg1 ??= "";
- fixed (char* string1Bytes = arg1)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
- descrs[0].DataPointer = (IntPtr)string1Bytes;
- descrs[0].Size = ((arg1.Length + 1) * 2);
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)(&arg2);
- descrs[1].Size = 8;
- descrs[1].Reserved = 0;
- WriteEventCore(eventId, 2, descrs);
- }
- }
- }
-
- // optimized for common signatures (long and string)
- protected unsafe void WriteEvent(int eventId, long arg1, string? arg2)
- {
- if (m_eventSourceEnabled)
- {
- arg2 ??= "";
- fixed (char* string2Bytes = arg2)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
- descrs[0].DataPointer = (IntPtr)(&arg1);
- descrs[0].Size = 8;
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)string2Bytes;
- descrs[1].Size = ((arg2.Length + 1) * 2);
- descrs[1].Reserved = 0;
- WriteEventCore(eventId, 2, descrs);
- }
- }
- }
-
- // optimized for common signatures (int and string)
- protected unsafe void WriteEvent(int eventId, int arg1, string? arg2)
- {
- if (m_eventSourceEnabled)
- {
- arg2 ??= "";
- fixed (char* string2Bytes = arg2)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
- descrs[0].DataPointer = (IntPtr)(&arg1);
- descrs[0].Size = 4;
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)string2Bytes;
- descrs[1].Size = ((arg2.Length + 1) * 2);
- descrs[1].Reserved = 0;
- WriteEventCore(eventId, 2, descrs);
- }
- }
- }
-
- protected unsafe void WriteEvent(int eventId, byte[]? arg1)
- {
- if (m_eventSourceEnabled)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
- if (arg1 == null || arg1.Length == 0)
- {
- int blobSize = 0;
- descrs[0].DataPointer = (IntPtr)(&blobSize);
- descrs[0].Size = 4;
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)(&blobSize); // valid address instead of empty content
- descrs[1].Size = 0;
- descrs[1].Reserved = 0;
- WriteEventCore(eventId, 2, descrs);
- }
- else
- {
- int blobSize = arg1.Length;
- fixed (byte* blob = &arg1[0])
- {
- descrs[0].DataPointer = (IntPtr)(&blobSize);
- descrs[0].Size = 4;
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)blob;
- descrs[1].Size = blobSize;
- descrs[1].Reserved = 0;
- WriteEventCore(eventId, 2, descrs);
- }
- }
- }
- }
-
- protected unsafe void WriteEvent(int eventId, long arg1, byte[]? arg2)
- {
- if (m_eventSourceEnabled)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
- descrs[0].DataPointer = (IntPtr)(&arg1);
- descrs[0].Size = 8;
- descrs[0].Reserved = 0;
- if (arg2 == null || arg2.Length == 0)
- {
- int blobSize = 0;
- descrs[1].DataPointer = (IntPtr)(&blobSize);
- descrs[1].Size = 4;
- descrs[1].Reserved = 0;
- descrs[2].DataPointer = (IntPtr)(&blobSize); // valid address instead of empty contents
- descrs[2].Size = 0;
- descrs[2].Reserved = 0;
- WriteEventCore(eventId, 3, descrs);
- }
- else
- {
- int blobSize = arg2.Length;
- fixed (byte* blob = &arg2[0])
- {
- descrs[1].DataPointer = (IntPtr)(&blobSize);
- descrs[1].Size = 4;
- descrs[1].Reserved = 0;
- descrs[2].DataPointer = (IntPtr)blob;
- descrs[2].Size = blobSize;
- descrs[2].Reserved = 0;
- WriteEventCore(eventId, 3, descrs);
- }
- }
- }
- }
-
-#pragma warning restore 1591
-
- /// <summary>
- /// Used to construct the data structure to be passed to the native ETW APIs - EventWrite and EventWriteTransfer.
- /// </summary>
- protected internal struct EventData
- {
- /// <summary>
- /// Address where the one argument lives (if this points to managed memory you must ensure the
- /// managed object is pinned.
- /// </summary>
- public unsafe IntPtr DataPointer
- {
- get => (IntPtr)(void*)m_Ptr;
- set => m_Ptr = unchecked((ulong)(void*)value);
- }
-
- /// <summary>
- /// Size of the argument referenced by DataPointer
- /// </summary>
- public int Size
- {
- get => m_Size;
- set => m_Size = value;
- }
-
- /// <summary>
- /// Reserved by ETW. This property is present to ensure that we can zero it
- /// since System.Private.CoreLib uses are not zero'd.
- /// </summary>
- internal int Reserved
- {
- get => m_Reserved;
- set => m_Reserved = value;
- }
-
-#region private
- /// <summary>
- /// Initializes the members of this EventData object to point at a previously-pinned
- /// tracelogging-compatible metadata blob.
- /// </summary>
- /// <param name="pointer">Pinned tracelogging-compatible metadata blob.</param>
- /// <param name="size">The size of the metadata blob.</param>
- /// <param name="reserved">Value for reserved: 2 for per-provider metadata, 1 for per-event metadata</param>
- internal unsafe void SetMetadata(byte* pointer, int size, int reserved)
- {
- this.m_Ptr = (ulong)pointer;
- this.m_Size = size;
- this.m_Reserved = reserved; // Mark this descriptor as containing tracelogging-compatible metadata.
- }
-
- // Important, we pass this structure directly to the Win32 EventWrite API, so this structure must
- // be layed out exactly the way EventWrite wants it.
- internal ulong m_Ptr;
- internal int m_Size;
-#pragma warning disable 0649
- internal int m_Reserved; // Used to pad the size to match the Win32 API
-#pragma warning restore 0649
-#endregion
- }
-
- /// <summary>
- /// This routine allows you to create efficient WriteEvent helpers, however the code that you use to
- /// do this, while straightforward, is unsafe.
- /// </summary>
- /// <remarks>
- /// <code>
- /// protected unsafe void WriteEvent(int eventId, string arg1, long arg2)
- /// {
- /// if (IsEnabled())
- /// {
- /// arg2 ??= "";
- /// fixed (char* string2Bytes = arg2)
- /// {
- /// EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
- /// descrs[0].DataPointer = (IntPtr)(&amp;arg1);
- /// descrs[0].Size = 8;
- /// descrs[0].Reserved = 0;
- /// descrs[1].DataPointer = (IntPtr)string2Bytes;
- /// descrs[1].Size = ((arg2.Length + 1) * 2);
- /// descrs[1].Reserved = 0;
- /// WriteEventCore(eventId, 2, descrs);
- /// }
- /// }
- /// }
- /// </code>
- /// </remarks>
- [CLSCompliant(false)]
- protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSource.EventData* data)
- {
- WriteEventWithRelatedActivityIdCore(eventId, null, eventDataCount, data);
- }
-
- /// <summary>
- /// This routine allows you to create efficient WriteEventWithRelatedActivityId helpers, however the code
- /// that you use to do this, while straightforward, is unsafe. The only difference from
- /// <see cref="WriteEventCore"/> is that you pass the relatedActivityId from caller through to this API
- /// </summary>
- /// <remarks>
- /// <code>
- /// protected unsafe void WriteEventWithRelatedActivityId(int eventId, Guid relatedActivityId, string arg1, long arg2)
- /// {
- /// if (IsEnabled())
- /// {
- /// arg2 ??= "";
- /// fixed (char* string2Bytes = arg2)
- /// {
- /// EventSource.EventData* descrs = stackalloc EventSource.EventData[2];
- /// descrs[0].DataPointer = (IntPtr)(&amp;arg1);
- /// descrs[0].Size = 8;
- /// descrs[1].DataPointer = (IntPtr)string2Bytes;
- /// descrs[1].Size = ((arg2.Length + 1) * 2);
- /// WriteEventWithRelatedActivityIdCore(eventId, relatedActivityId, 2, descrs);
- /// }
- /// }
- /// }
- /// </code>
- /// </remarks>
- [CLSCompliant(false)]
- protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* relatedActivityId, int eventDataCount, EventSource.EventData* data)
- {
- if (m_eventSourceEnabled)
- {
- Debug.Assert(m_eventData != null); // You must have initialized this if you enabled the source.
- try
- {
- if (relatedActivityId != null)
- ValidateEventOpcodeForTransfer(ref m_eventData[eventId], m_eventData[eventId].Name);
-
- EventOpcode opcode = (EventOpcode)m_eventData[eventId].Descriptor.Opcode;
- EventActivityOptions activityOptions = m_eventData[eventId].ActivityOptions;
- Guid* pActivityId = null;
- Guid activityId = Guid.Empty;
- Guid relActivityId = Guid.Empty;
-
- if (opcode != EventOpcode.Info && relatedActivityId == null &&
- ((activityOptions & EventActivityOptions.Disable) == 0))
- {
- if (opcode == EventOpcode.Start)
- {
- m_activityTracker.OnStart(m_name, m_eventData[eventId].Name, m_eventData[eventId].Descriptor.Task, ref activityId, ref relActivityId, m_eventData[eventId].ActivityOptions);
- }
- else if (opcode == EventOpcode.Stop)
- {
- m_activityTracker.OnStop(m_name, m_eventData[eventId].Name, m_eventData[eventId].Descriptor.Task, ref activityId);
- }
-
- if (activityId != Guid.Empty)
- pActivityId = &activityId;
- if (relActivityId != Guid.Empty)
- relatedActivityId = &relActivityId;
- }
-
-#if FEATURE_MANAGED_ETW
- if (m_eventData[eventId].EnabledForETW
-#if FEATURE_PERFTRACING
- || m_eventData[eventId].EnabledForEventPipe
-#endif // FEATURE_PERFTRACING
- )
- {
- if (!SelfDescribingEvents)
- {
- if (!m_etwProvider.WriteEvent(ref m_eventData[eventId].Descriptor, m_eventData[eventId].EventHandle, pActivityId, relatedActivityId, eventDataCount, (IntPtr)data))
- ThrowEventSourceException(m_eventData[eventId].Name);
-#if FEATURE_PERFTRACING
- if (!m_eventPipeProvider.WriteEvent(ref m_eventData[eventId].Descriptor, m_eventData[eventId].EventHandle, pActivityId, relatedActivityId, eventDataCount, (IntPtr)data))
- ThrowEventSourceException(m_eventData[eventId].Name);
-#endif // FEATURE_PERFTRACING
- }
- else
- {
- TraceLoggingEventTypes? tlet = m_eventData[eventId].TraceLoggingEventTypes;
- if (tlet == null)
- {
- tlet = new TraceLoggingEventTypes(m_eventData[eventId].Name,
- m_eventData[eventId].Tags,
- m_eventData[eventId].Parameters);
- Interlocked.CompareExchange(ref m_eventData[eventId].TraceLoggingEventTypes, tlet, null);
- }
- EventSourceOptions opt = new EventSourceOptions
- {
- Keywords = (EventKeywords)m_eventData[eventId].Descriptor.Keywords,
- Level = (EventLevel)m_eventData[eventId].Descriptor.Level,
- Opcode = (EventOpcode)m_eventData[eventId].Descriptor.Opcode
- };
-
- WriteMultiMerge(m_eventData[eventId].Name, ref opt, tlet, pActivityId, relatedActivityId, data);
- }
- }
-#endif // FEATURE_MANAGED_ETW
-
- if (m_Dispatchers != null && m_eventData[eventId].EnabledForAnyListener)
- WriteToAllListeners(eventId, pActivityId, relatedActivityId, eventDataCount, data);
- }
- catch (Exception ex)
- {
- if (ex is EventSourceException)
- throw;
- else
- ThrowEventSourceException(m_eventData[eventId].Name, ex);
- }
- }
- }
-
- // fallback varags helpers.
- /// <summary>
- /// This is the varargs helper for writing an event. It does create an array and box all the arguments so it is
- /// relatively inefficient and should only be used for relatively rare events (e.g. less than 100 / sec). If your
- /// rates are faster than that you should use <see cref="WriteEventCore"/> to create fast helpers for your particular
- /// method signature. Even if you use this for rare events, this call should be guarded by an <see cref="IsEnabled()"/>
- /// check so that the varargs call is not made when the EventSource is not active.
- /// </summary>
- protected unsafe void WriteEvent(int eventId, params object?[] args)
- {
- WriteEventVarargs(eventId, null, args);
- }
-
- /// <summary>
- /// This is the varargs helper for writing an event which also specifies a related activity. It is completely analogous
- /// to corresponding WriteEvent (they share implementation). It does create an array and box all the arguments so it is
- /// relatively inefficient and should only be used for relatively rare events (e.g. less than 100 / sec). If your
- /// rates are faster than that you should use <see cref="WriteEventWithRelatedActivityIdCore"/> to create fast helpers for your
- /// particular method signature. Even if you use this for rare events, this call should be guarded by an <see cref="IsEnabled()"/>
- /// check so that the varargs call is not made when the EventSource is not active.
- /// </summary>
- protected unsafe void WriteEventWithRelatedActivityId(int eventId, Guid relatedActivityId, params object?[] args)
- {
- WriteEventVarargs(eventId, &relatedActivityId, args);
- }
-
-#endregion
-
-#region IDisposable Members
- /// <summary>
- /// Disposes of an EventSource.
- /// </summary>
- public void Dispose()
- {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
- /// <summary>
- /// Disposes of an EventSource.
- /// </summary>
- /// <remarks>
- /// Called from Dispose() with disposing=true, and from the finalizer (~EventSource) with disposing=false.
- /// Guidelines:
- /// 1. We may be called more than once: do nothing after the first call.
- /// 2. Avoid throwing exceptions if disposing is false, i.e. if we're being finalized.
- /// </remarks>
- /// <param name="disposing">True if called from Dispose(), false if called from the finalizer.</param>
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
-#if FEATURE_MANAGED_ETW
- // Send the manifest one more time to ensure circular buffers have a chance to get to this information
- // even in scenarios with a high volume of ETW events.
- if (m_eventSourceEnabled)
- {
- try
- {
- SendManifest(m_rawManifest);
- }
- catch { } // If it fails, simply give up.
- m_eventSourceEnabled = false;
- }
- if (m_etwProvider != null)
- {
- m_etwProvider.Dispose();
- m_etwProvider = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
- }
-#endif
-#if FEATURE_PERFTRACING
- if (m_eventPipeProvider != null)
- {
- m_eventPipeProvider.Dispose();
- m_eventPipeProvider = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
- }
-#endif
- }
- m_eventSourceEnabled = false;
- m_eventSourceDisposed = true;
- }
- /// <summary>
- /// Finalizer for EventSource
- /// </summary>
- ~EventSource()
- {
- this.Dispose(false);
- }
-#endregion
-
-#region private
-
- private unsafe void WriteEventRaw(
- string? eventName,
- ref EventDescriptor eventDescriptor,
- IntPtr eventHandle,
- Guid* activityID,
- Guid* relatedActivityID,
- int dataCount,
- IntPtr data)
- {
-#if FEATURE_MANAGED_ETW
- if (m_etwProvider == null)
- {
- ThrowEventSourceException(eventName);
- }
- else
- {
- if (!m_etwProvider.WriteEventRaw(ref eventDescriptor, eventHandle, activityID, relatedActivityID, dataCount, data))
- ThrowEventSourceException(eventName);
- }
-#endif // FEATURE_MANAGED_ETW
-#if FEATURE_PERFTRACING
- if (m_eventPipeProvider == null)
- {
- ThrowEventSourceException(eventName);
- }
- else
- {
- if (!m_eventPipeProvider.WriteEventRaw(ref eventDescriptor, eventHandle, activityID, relatedActivityID, dataCount, data))
- ThrowEventSourceException(eventName);
- }
-#endif // FEATURE_PERFTRACING
- }
-
- // FrameworkEventSource is on the startup path for the framework, so we have this internal overload that it can use
- // to prevent the working set hit from looking at the custom attributes on the type to get the Guid.
- internal EventSource(Guid eventSourceGuid, string eventSourceName)
- : this(eventSourceGuid, eventSourceName, EventSourceSettings.EtwManifestEventFormat)
- { }
-
- // Used by the internal FrameworkEventSource constructor and the TraceLogging-style event source constructor
- internal EventSource(Guid eventSourceGuid, string eventSourceName, EventSourceSettings settings, string[]? traits = null)
- {
- m_config = ValidateSettings(settings);
- Initialize(eventSourceGuid, eventSourceName, traits);
- }
-
- /// <summary>
- /// This method is responsible for the common initialization path from our constructors. It must
- /// not leak any exceptions (otherwise, since most EventSource classes define a static member,
- /// "Log", such an exception would become a cached exception for the initialization of the static
- /// member, and any future access to the "Log" would throw the cached exception).
- /// </summary>
- private unsafe void Initialize(Guid eventSourceGuid, string eventSourceName, string[]? traits)
- {
- try
- {
- m_traits = traits;
- if (m_traits != null && m_traits.Length % 2 != 0)
- {
- throw new ArgumentException(SR.EventSource_TraitEven, nameof(traits));
- }
-
- if (eventSourceGuid == Guid.Empty)
- {
- throw new ArgumentException(SR.EventSource_NeedGuid);
- }
-
- if (eventSourceName == null)
- {
- throw new ArgumentException(SR.EventSource_NeedName);
- }
-
- m_name = eventSourceName;
- m_guid = eventSourceGuid;
-
- // Enable Implicit Activity tracker
- m_activityTracker = ActivityTracker.Instance;
-
-#if FEATURE_MANAGED_ETW || FEATURE_PERFTRACING
- // Create and register our provider traits. We do this early because it is needed to log errors
- // In the self-describing event case.
- this.InitializeProviderMetadata();
-#endif
-#if FEATURE_MANAGED_ETW
- // Register the provider with ETW
- var etwProvider = new OverideEventProvider(this, EventProviderType.ETW);
- etwProvider.Register(this);
-#endif
-#if FEATURE_PERFTRACING
- // Register the provider with EventPipe
- var eventPipeProvider = new OverideEventProvider(this, EventProviderType.EventPipe);
- lock (EventListener.EventListenersLock)
- {
- eventPipeProvider.Register(this);
- }
-#endif
- // Add the eventSource to the global (weak) list.
- // This also sets m_id, which is the index in the list.
- EventListener.AddEventSource(this);
-
-#if FEATURE_MANAGED_ETW
- // OK if we get this far without an exception, then we can at least write out error messages.
- // Set m_provider, which allows this.
- m_etwProvider = etwProvider;
-
-#if PLATFORM_WINDOWS
-#if (!ES_BUILD_STANDALONE && !ES_BUILD_PN)
- // API available on OS >= Win 8 and patched Win 7.
- // Disable only for FrameworkEventSource to avoid recursion inside exception handling.
- if (this.Name != "System.Diagnostics.Eventing.FrameworkEventSource" || Environment.IsWindows8OrAbove)
-#endif
- {
- int setInformationResult;
- System.Runtime.InteropServices.GCHandle metadataHandle =
- System.Runtime.InteropServices.GCHandle.Alloc(this.providerMetadata, System.Runtime.InteropServices.GCHandleType.Pinned);
- IntPtr providerMetadata = metadataHandle.AddrOfPinnedObject();
-
- setInformationResult = m_etwProvider.SetInformation(
- Interop.Advapi32.EVENT_INFO_CLASS.SetTraits,
- providerMetadata,
- (uint)this.providerMetadata.Length);
-
- metadataHandle.Free();
- }
-#endif // PLATFORM_WINDOWS
-#endif // FEATURE_MANAGED_ETW
-
-#if FEATURE_PERFTRACING
- m_eventPipeProvider = eventPipeProvider;
-#endif
- Debug.Assert(!m_eventSourceEnabled); // We can't be enabled until we are completely initted.
- // We are logically completely initialized at this point.
- m_completelyInited = true;
- }
- catch (Exception e)
- {
- m_constructionException ??= e;
- ReportOutOfBandMessage("ERROR: Exception during construction of EventSource " + Name + ": " + e.Message);
- }
-
- // Once m_completelyInited is set, you can have concurrency, so all work is under the lock.
- lock (EventListener.EventListenersLock)
- {
- // If there are any deferred commands, we can do them now.
- // This is the most likely place for exceptions to happen.
- // Note that we are NOT resetting m_deferredCommands to NULL here,
- // We are giving for EventHandler<EventCommandEventArgs> that will be attached later
- EventCommandEventArgs? deferredCommands = m_deferredCommands;
- while (deferredCommands != null)
- {
- DoCommand(deferredCommands); // This can never throw, it catches them and reports the errors.
- deferredCommands = deferredCommands.nextCommand;
- }
- }
- }
-
- private static string GetName(Type eventSourceType, EventManifestOptions flags)
- {
- if (eventSourceType == null)
- throw new ArgumentNullException(nameof(eventSourceType));
-
- EventSourceAttribute? attrib = (EventSourceAttribute?)GetCustomAttributeHelper(eventSourceType, typeof(EventSourceAttribute), flags);
- if (attrib != null && attrib.Name != null)
- return attrib.Name;
-
- return eventSourceType.Name;
- }
-
- /// <summary>
- /// Implements the SHA1 hashing algorithm. Note that this
- /// implementation is for hashing public information. Do not
- /// use this code to hash private data, as this implementation does
- /// not take any steps to avoid information disclosure.
- /// </summary>
- private struct Sha1ForNonSecretPurposes
- {
- private long length; // Total message length in bits
- private uint[] w; // Workspace
- private int pos; // Length of current chunk in bytes
-
- /// <summary>
- /// Call Start() to initialize the hash object.
- /// </summary>
- public void Start()
- {
- this.w ??= new uint[85];
-
- this.length = 0;
- this.pos = 0;
- this.w[80] = 0x67452301;
- this.w[81] = 0xEFCDAB89;
- this.w[82] = 0x98BADCFE;
- this.w[83] = 0x10325476;
- this.w[84] = 0xC3D2E1F0;
- }
-
- /// <summary>
- /// Adds an input byte to the hash.
- /// </summary>
- /// <param name="input">Data to include in the hash.</param>
- public void Append(byte input)
- {
- this.w[this.pos / 4] = (this.w[this.pos / 4] << 8) | input;
- if (64 == ++this.pos)
- {
- this.Drain();
- }
- }
-
- /// <summary>
- /// Adds input bytes to the hash.
- /// </summary>
- /// <param name="input">
- /// Data to include in the hash. Must not be null.
- /// </param>
- public void Append(byte[] input)
- {
- foreach (byte b in input)
- {
- this.Append(b);
- }
- }
-
- /// <summary>
- /// Retrieves the hash value.
- /// Note that after calling this function, the hash object should
- /// be considered uninitialized. Subsequent calls to Append or
- /// Finish will produce useless results. Call Start() to
- /// reinitialize.
- /// </summary>
- /// <param name="output">
- /// Buffer to receive the hash value. Must not be null.
- /// Up to 20 bytes of hash will be written to the output buffer.
- /// If the buffer is smaller than 20 bytes, the remaining hash
- /// bytes will be lost. If the buffer is larger than 20 bytes, the
- /// rest of the buffer is left unmodified.
- /// </param>
- public void Finish(byte[] output)
- {
- long l = this.length + 8 * this.pos;
- this.Append(0x80);
- while (this.pos != 56)
- {
- this.Append(0x00);
- }
-
- unchecked
- {
- this.Append((byte)(l >> 56));
- this.Append((byte)(l >> 48));
- this.Append((byte)(l >> 40));
- this.Append((byte)(l >> 32));
- this.Append((byte)(l >> 24));
- this.Append((byte)(l >> 16));
- this.Append((byte)(l >> 8));
- this.Append((byte)l);
-
- int end = output.Length < 20 ? output.Length : 20;
- for (int i = 0; i != end; i++)
- {
- uint temp = this.w[80 + i / 4];
- output[i] = (byte)(temp >> 24);
- this.w[80 + i / 4] = temp << 8;
- }
- }
- }
-
- /// <summary>
- /// Called when this.pos reaches 64.
- /// </summary>
- private void Drain()
- {
- for (int i = 16; i != 80; i++)
- {
- this.w[i] = BitOperations.RotateLeft(this.w[i - 3] ^ this.w[i - 8] ^ this.w[i - 14] ^ this.w[i - 16], 1);
- }
-
- unchecked
- {
- uint a = this.w[80];
- uint b = this.w[81];
- uint c = this.w[82];
- uint d = this.w[83];
- uint e = this.w[84];
-
- for (int i = 0; i != 20; i++)
- {
- const uint k = 0x5A827999;
- uint f = (b & c) | ((~b) & d);
- uint temp = BitOperations.RotateLeft(a, 5) + f + e + k + this.w[i]; e = d; d = c; c = BitOperations.RotateLeft(b, 30); b = a; a = temp;
- }
-
- for (int i = 20; i != 40; i++)
- {
- uint f = b ^ c ^ d;
- const uint k = 0x6ED9EBA1;
- uint temp = BitOperations.RotateLeft(a, 5) + f + e + k + this.w[i]; e = d; d = c; c = BitOperations.RotateLeft(b, 30); b = a; a = temp;
- }
-
- for (int i = 40; i != 60; i++)
- {
- uint f = (b & c) | (b & d) | (c & d);
- const uint k = 0x8F1BBCDC;
- uint temp = BitOperations.RotateLeft(a, 5) + f + e + k + this.w[i]; e = d; d = c; c = BitOperations.RotateLeft(b, 30); b = a; a = temp;
- }
-
- for (int i = 60; i != 80; i++)
- {
- uint f = b ^ c ^ d;
- const uint k = 0xCA62C1D6;
- uint temp = BitOperations.RotateLeft(a, 5) + f + e + k + this.w[i]; e = d; d = c; c = BitOperations.RotateLeft(b, 30); b = a; a = temp;
- }
-
- this.w[80] += a;
- this.w[81] += b;
- this.w[82] += c;
- this.w[83] += d;
- this.w[84] += e;
- }
-
- this.length += 512; // 64 bytes == 512 bits
- this.pos = 0;
- }
- }
-
- private static Guid GenerateGuidFromName(string name)
- {
- if (namespaceBytes == null)
- {
- namespaceBytes = new byte[] {
- 0x48, 0x2C, 0x2D, 0xB2, 0xC3, 0x90, 0x47, 0xC8,
- 0x87, 0xF8, 0x1A, 0x15, 0xBF, 0xC1, 0x30, 0xFB,
- };
- }
-
- byte[] bytes = Encoding.BigEndianUnicode.GetBytes(name);
- Sha1ForNonSecretPurposes hash = default;
- hash.Start();
- hash.Append(namespaceBytes);
- hash.Append(bytes);
- Array.Resize(ref bytes, 16);
- hash.Finish(bytes);
-
- bytes[7] = unchecked((byte)((bytes[7] & 0x0F) | 0x50)); // Set high 4 bits of octet 7 to 5, as per RFC 4122
- return new Guid(bytes);
- }
-
- private unsafe object? DecodeObject(int eventId, int parameterId, ref EventSource.EventData* data)
- {
- // TODO FIX : We use reflection which in turn uses EventSource, right now we carefully avoid
- // the recursion, but can we do this in a robust way?
-
- IntPtr dataPointer = data->DataPointer;
- // advance to next EventData in array
- ++data;
-
- Debug.Assert(m_eventData != null);
- Type dataType = GetDataType(m_eventData[eventId], parameterId);
-
- Again:
- if (dataType == typeof(IntPtr))
- {
- return *((IntPtr*)dataPointer);
- }
- else if (dataType == typeof(int))
- {
- return *((int*)dataPointer);
- }
- else if (dataType == typeof(uint))
- {
- return *((uint*)dataPointer);
- }
- else if (dataType == typeof(long))
- {
- return *((long*)dataPointer);
- }
- else if (dataType == typeof(ulong))
- {
- return *((ulong*)dataPointer);
- }
- else if (dataType == typeof(byte))
- {
- return *((byte*)dataPointer);
- }
- else if (dataType == typeof(sbyte))
- {
- return *((sbyte*)dataPointer);
- }
- else if (dataType == typeof(short))
- {
- return *((short*)dataPointer);
- }
- else if (dataType == typeof(ushort))
- {
- return *((ushort*)dataPointer);
- }
- else if (dataType == typeof(float))
- {
- return *((float*)dataPointer);
- }
- else if (dataType == typeof(double))
- {
- return *((double*)dataPointer);
- }
- else if (dataType == typeof(decimal))
- {
- return *((decimal*)dataPointer);
- }
- else if (dataType == typeof(bool))
- {
- // The manifest defines a bool as a 32bit type (WIN32 BOOL), not 1 bit as CLR Does.
- return *((int*)dataPointer) == 1;
- }
- else if (dataType == typeof(Guid))
- {
- return *((Guid*)dataPointer);
- }
- else if (dataType == typeof(char))
- {
- return *((char*)dataPointer);
- }
- else if (dataType == typeof(DateTime))
- {
- long dateTimeTicks = *((long*)dataPointer);
- return DateTime.FromFileTimeUtc(dateTimeTicks);
- }
- else if (dataType == typeof(byte[]))
- {
- // byte[] are written to EventData* as an int followed by a blob
- int cbSize = *((int*)dataPointer);
- byte[] blob = new byte[cbSize];
- dataPointer = data->DataPointer;
- data++;
- for (int i = 0; i < cbSize; ++i)
- blob[i] = *((byte*)(dataPointer + i));
- return blob;
- }
- else if (dataType == typeof(byte*))
- {
- // TODO: how do we want to handle this? For now we ignore it...
- return null;
- }
- else
- {
- if (m_EventSourcePreventRecursion && m_EventSourceInDecodeObject)
- {
- return null;
- }
-
- try
- {
- m_EventSourceInDecodeObject = true;
-
- if (dataType.IsEnum())
- {
- dataType = Enum.GetUnderlyingType(dataType);
-#if ES_BUILD_PN
- int dataTypeSize = (int)dataType.TypeHandle.ToEETypePtr().ValueTypeSize;
-#else
- int dataTypeSize = System.Runtime.InteropServices.Marshal.SizeOf(dataType);
-#endif
- if (dataTypeSize < sizeof(int))
- dataType = typeof(int);
- goto Again;
- }
-
- // Everything else is marshaled as a string.
- // ETW strings are NULL-terminated, so marshal everything up to the first
- // null in the string.
- if (dataPointer == IntPtr.Zero)
- {
- return null;
- }
-
- return new string((char*)dataPointer);
- }
- finally
- {
- m_EventSourceInDecodeObject = false;
- }
- }
- }
-
- // Finds the Dispatcher (which holds the filtering state), for a given dispatcher for the current
- // eventSource).
- private EventDispatcher? GetDispatcher(EventListener? listener)
- {
- EventDispatcher? dispatcher = m_Dispatchers;
- while (dispatcher != null)
- {
- if (dispatcher.m_Listener == listener)
- return dispatcher;
- dispatcher = dispatcher.m_Next;
- }
- return dispatcher;
- }
-
- private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object?[] args)
- {
- if (m_eventSourceEnabled)
- {
- Debug.Assert(m_eventData != null); // You must have initialized this if you enabled the source.
- try
- {
- if (childActivityID != null)
- {
- ValidateEventOpcodeForTransfer(ref m_eventData[eventId], m_eventData[eventId].Name);
-
- // If you use WriteEventWithRelatedActivityID you MUST declare the first argument to be a GUID
- // with the name 'relatedActivityID, and NOT pass this argument to the WriteEvent method.
- // During manifest creation we modify the ParameterInfo[] that we store to strip out any
- // first parameter that is of type Guid and named "relatedActivityId." Thus, if you call
- // WriteEventWithRelatedActivityID from a method that doesn't name its first parameter correctly
- // we can end up in a state where the ParameterInfo[] doesn't have its first parameter stripped,
- // and this leads to a mismatch between the number of arguments and the number of ParameterInfos,
- // which would cause a cryptic IndexOutOfRangeException later if we don't catch it here.
- if (!m_eventData[eventId].HasRelatedActivityID)
- {
- throw new ArgumentException(SR.EventSource_NoRelatedActivityId);
- }
- }
-
- LogEventArgsMismatches(eventId, args);
-
- Guid* pActivityId = null;
- Guid activityId = Guid.Empty;
- Guid relatedActivityId = Guid.Empty;
- EventOpcode opcode = (EventOpcode)m_eventData[eventId].Descriptor.Opcode;
- EventActivityOptions activityOptions = m_eventData[eventId].ActivityOptions;
-
- if (childActivityID == null &&
- ((activityOptions & EventActivityOptions.Disable) == 0))
- {
- if (opcode == EventOpcode.Start)
- {
- m_activityTracker.OnStart(m_name, m_eventData[eventId].Name, m_eventData[eventId].Descriptor.Task, ref activityId, ref relatedActivityId, m_eventData[eventId].ActivityOptions);
- }
- else if (opcode == EventOpcode.Stop)
- {
- m_activityTracker.OnStop(m_name, m_eventData[eventId].Name, m_eventData[eventId].Descriptor.Task, ref activityId);
- }
-
- if (activityId != Guid.Empty)
- pActivityId = &activityId;
- if (relatedActivityId != Guid.Empty)
- childActivityID = &relatedActivityId;
- }
-
-#if FEATURE_MANAGED_ETW
- if (m_eventData[eventId].EnabledForETW
-#if FEATURE_PERFTRACING
- || m_eventData[eventId].EnabledForEventPipe
-#endif // FEATURE_PERFTRACING
- )
- {
- if (!SelfDescribingEvents)
- {
- if (!m_etwProvider.WriteEvent(ref m_eventData[eventId].Descriptor, m_eventData[eventId].EventHandle, pActivityId, childActivityID, args))
- ThrowEventSourceException(m_eventData[eventId].Name);
-#if FEATURE_PERFTRACING
- if (!m_eventPipeProvider.WriteEvent(ref m_eventData[eventId].Descriptor, m_eventData[eventId].EventHandle, pActivityId, childActivityID, args))
- ThrowEventSourceException(m_eventData[eventId].Name);
-#endif // FEATURE_PERFTRACING
- }
- else
- {
- TraceLoggingEventTypes? tlet = m_eventData[eventId].TraceLoggingEventTypes;
- if (tlet == null)
- {
- tlet = new TraceLoggingEventTypes(m_eventData[eventId].Name,
- EventTags.None,
- m_eventData[eventId].Parameters);
- Interlocked.CompareExchange(ref m_eventData[eventId].TraceLoggingEventTypes, tlet, null);
- }
- // TODO: activity ID support
- EventSourceOptions opt = new EventSourceOptions
- {
- Keywords = (EventKeywords)m_eventData[eventId].Descriptor.Keywords,
- Level = (EventLevel)m_eventData[eventId].Descriptor.Level,
- Opcode = (EventOpcode)m_eventData[eventId].Descriptor.Opcode
- };
-
- WriteMultiMerge(m_eventData[eventId].Name, ref opt, tlet, pActivityId, childActivityID, args);
- }
- }
-#endif // FEATURE_MANAGED_ETW
- if (m_Dispatchers != null && m_eventData[eventId].EnabledForAnyListener)
- {
-#if !ES_BUILD_STANDALONE
- // Maintain old behavior - object identity is preserved
- if (LocalAppContextSwitches.PreserveEventListnerObjectIdentity)
- {
- WriteToAllListeners(
- eventId: eventId,
- osThreadId: null,
- timeStamp: null,
- activityID: pActivityId,
- childActivityID: childActivityID,
- args: args);
- }
- else
-#endif // !ES_BUILD_STANDALONE
- {
- object?[] serializedArgs = SerializeEventArgs(eventId, args);
- WriteToAllListeners(
- eventId: eventId,
- osThreadId: null,
- timeStamp: null,
- activityID: pActivityId,
- childActivityID: childActivityID,
- args: serializedArgs);
- }
- }
- }
- catch (Exception ex)
- {
- if (ex is EventSourceException)
- throw;
- else
- ThrowEventSourceException(m_eventData[eventId].Name, ex);
- }
- }
- }
-
- private unsafe object?[] SerializeEventArgs(int eventId, object?[] args)
- {
- Debug.Assert(m_eventData != null);
- TraceLoggingEventTypes? eventTypes = m_eventData[eventId].TraceLoggingEventTypes;
- if (eventTypes == null)
- {
- eventTypes = new TraceLoggingEventTypes(m_eventData[eventId].Name,
- EventTags.None,
- m_eventData[eventId].Parameters);
- Interlocked.CompareExchange(ref m_eventData[eventId].TraceLoggingEventTypes, eventTypes, null);
- }
- int paramCount = Math.Min(eventTypes.typeInfos.Length, args.Length); // parameter count mismatch get logged in LogEventArgsMismatches
- var eventData = new object?[eventTypes.typeInfos.Length];
- for (int i = 0; i < paramCount; i++)
- {
- eventData[i] = eventTypes.typeInfos[i].GetData(args[i]);
- }
- return eventData;
- }
-
- /// <summary>
- /// We expect that the arguments to the Event method and the arguments to WriteEvent match. This function
- /// checks that they in fact match and logs a warning to the debugger if they don't.
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void LogEventArgsMismatches(int eventId, object?[] args)
- {
- Debug.Assert(m_eventData != null);
- ParameterInfo[] infos = m_eventData[eventId].Parameters;
-
- if (args.Length != infos.Length)
- {
- ReportOutOfBandMessage(SR.Format(SR.EventSource_EventParametersMismatch, eventId, args.Length, infos.Length));
- return;
- }
-
- int i = 0;
- while (i < args.Length)
- {
- Type pType = infos[i].ParameterType;
- object? arg = args[i];
-
- // Checking to see if the Parameter types (from the Event method) match the supplied argument types.
- // Fail if one of two things hold : either the argument type is not equal or assignable to the parameter type, or the
- // argument is null and the parameter type is a non-Nullable<T> value type.
- if ((arg != null && !pType.IsAssignableFrom(arg.GetType()))
- || (arg == null && (pType.IsValueType && !(pType.IsGenericType && pType.GetGenericTypeDefinition() == typeof(Nullable<>))))
- )
- {
- ReportOutOfBandMessage(SR.Format(SR.EventSource_VarArgsParameterMismatch, eventId, infos[i].Name));
- return;
- }
-
- ++i;
- }
- }
-
- private unsafe void WriteToAllListeners(int eventId, Guid* activityID, Guid* childActivityID, int eventDataCount, EventSource.EventData* data)
- {
- Debug.Assert(m_eventData != null);
- // We represent a byte[] as a integer denoting the length and then a blob of bytes in the data pointer. This causes a spurious
- // warning because eventDataCount is off by one for the byte[] case since a byte[] has 2 items associated it. So we want to check
- // that the number of parameters is correct against the byte[] case, but also we the args array would be one too long if
- // we just used the modifiedParamCount here -- so we need both.
- int paramCount = GetParameterCount(m_eventData[eventId]);
- int modifiedParamCount = 0;
- for (int i = 0; i < paramCount; i++)
- {
- Type parameterType = GetDataType(m_eventData[eventId], i);
- if (parameterType == typeof(byte[]))
- {
- modifiedParamCount += 2;
- }
- else
- {
- modifiedParamCount++;
- }
- }
- if (eventDataCount != modifiedParamCount)
- {
- ReportOutOfBandMessage(SR.Format(SR.EventSource_EventParametersMismatch, eventId, eventDataCount, paramCount));
- paramCount = Math.Min(paramCount, eventDataCount);
- }
-
- object?[] args = new object[paramCount];
-
- EventSource.EventData* dataPtr = data;
- for (int i = 0; i < paramCount; i++)
- args[i] = DecodeObject(eventId, i, ref dataPtr);
- WriteToAllListeners(
- eventId: eventId,
- osThreadId: null,
- timeStamp: null,
- activityID: activityID,
- childActivityID: childActivityID,
- args: args);
- }
-
- // helper for writing to all EventListeners attached the current eventSource.
- internal unsafe void WriteToAllListeners(int eventId, uint* osThreadId, DateTime* timeStamp, Guid* activityID, Guid* childActivityID, params object?[] args)
- {
- EventWrittenEventArgs eventCallbackArgs = new EventWrittenEventArgs(this);
- eventCallbackArgs.EventId = eventId;
- if (osThreadId != null)
- eventCallbackArgs.OSThreadId = (int)*osThreadId;
- if (timeStamp != null)
- eventCallbackArgs.TimeStamp = *timeStamp;
- if (activityID != null)
- eventCallbackArgs.ActivityId = *activityID;
- if (childActivityID != null)
- eventCallbackArgs.RelatedActivityId = *childActivityID;
-
- Debug.Assert(m_eventData != null);
- eventCallbackArgs.EventName = m_eventData[eventId].Name;
- eventCallbackArgs.Message = m_eventData[eventId].Message;
- eventCallbackArgs.Payload = new ReadOnlyCollection<object?>(args);
-
- DispatchToAllListeners(eventId, eventCallbackArgs);
- }
-
- private unsafe void DispatchToAllListeners(int eventId, EventWrittenEventArgs eventCallbackArgs)
- {
- Exception? lastThrownException = null;
- for (EventDispatcher? dispatcher = m_Dispatchers; dispatcher != null; dispatcher = dispatcher.m_Next)
- {
- Debug.Assert(dispatcher.m_EventEnabled != null);
- if (eventId == -1 || dispatcher.m_EventEnabled[eventId])
- {
- {
- try
- {
- dispatcher.m_Listener.OnEventWritten(eventCallbackArgs);
- }
- catch (Exception e)
- {
- ReportOutOfBandMessage("ERROR: Exception during EventSource.OnEventWritten: "
- + e.Message);
- lastThrownException = e;
- }
- }
- }
- }
-
- if (lastThrownException != null)
- {
- throw new EventSourceException(lastThrownException);
- }
- }
-
- private unsafe void WriteEventString(EventLevel level, long keywords, string msgString)
- {
-#if FEATURE_MANAGED_ETW
- if (m_etwProvider != null)
- {
- const string EventName = "EventSourceMessage";
- if (SelfDescribingEvents)
- {
- EventSourceOptions opt = new EventSourceOptions
- {
- Keywords = (EventKeywords)unchecked(keywords),
- Level = level
- };
- var msg = new { message = msgString };
- var tlet = new TraceLoggingEventTypes(EventName, EventTags.None, new Type[] { msg.GetType() });
- WriteMultiMergeInner(EventName, ref opt, tlet, null, null, msg);
- }
- else
- {
- // We want the name of the provider to show up so if we don't have a manifest we create
- // on that at least has the provider name (I don't define any events).
- if (m_rawManifest == null && m_outOfBandMessageCount == 1)
- {
- ManifestBuilder manifestBuilder = new ManifestBuilder(Name, Guid, Name, null, EventManifestOptions.None);
- manifestBuilder.StartEvent(EventName, new EventAttribute(0) { Level = EventLevel.LogAlways, Task = (EventTask)0xFFFE });
- manifestBuilder.AddEventParameter(typeof(string), "message");
- manifestBuilder.EndEvent();
- SendManifest(manifestBuilder.CreateManifest());
- }
-
- // We use this low level routine to bypass the enabled checking, since the eventSource itself is only partially inited.
- fixed (char* msgStringPtr = msgString)
- {
- EventDescriptor descr = new EventDescriptor(0, 0, 0, (byte)level, 0, 0, keywords);
- EventProvider.EventData data = default;
- data.Ptr = (ulong)msgStringPtr;
- data.Size = (uint)(2 * (msgString.Length + 1));
- data.Reserved = 0;
- m_etwProvider.WriteEvent(ref descr, IntPtr.Zero, null, null, 1, (IntPtr)((void*)&data));
- }
- }
- }
-#endif // FEATURE_MANAGED_ETW
- }
-
- /// <summary>
- /// Since this is a means of reporting errors (see ReportoutOfBandMessage) any failure encountered
- /// while writing the message to any one of the listeners will be silently ignored.
- /// </summary>
- private void WriteStringToAllListeners(string eventName, string msg)
- {
- EventWrittenEventArgs eventCallbackArgs = new EventWrittenEventArgs(this);
- eventCallbackArgs.EventId = 0;
- eventCallbackArgs.Message = msg;
- eventCallbackArgs.Payload = new ReadOnlyCollection<object?>(new List<object?>() { msg });
- eventCallbackArgs.PayloadNames = new ReadOnlyCollection<string>(new List<string> { "message" });
- eventCallbackArgs.EventName = eventName;
-
- for (EventDispatcher? dispatcher = m_Dispatchers; dispatcher != null; dispatcher = dispatcher.m_Next)
- {
- bool dispatcherEnabled = false;
- if (dispatcher.m_EventEnabled == null)
- {
- // if the listeners that weren't correctly initialized, we will send to it
- // since this is an error message and we want to see it go out.
- dispatcherEnabled = true;
- }
- else
- {
- // if there's *any* enabled event on the dispatcher we'll write out the string
- // otherwise we'll treat the listener as disabled and skip it
- for (int evtId = 0; evtId < dispatcher.m_EventEnabled.Length; ++evtId)
- {
- if (dispatcher.m_EventEnabled[evtId])
- {
- dispatcherEnabled = true;
- break;
- }
- }
- }
- try
- {
- if (dispatcherEnabled)
- dispatcher.m_Listener.OnEventWritten(eventCallbackArgs);
- }
- catch
- {
- // ignore any exceptions thrown by listeners' OnEventWritten
- }
- }
- }
-
- /// <summary>
- /// Returns true if 'eventNum' is enabled if you only consider the level and matchAnyKeyword filters.
- /// It is possible that eventSources turn off the event based on additional filtering criteria.
- /// </summary>
- private bool IsEnabledByDefault(int eventNum, bool enable, EventLevel currentLevel, EventKeywords currentMatchAnyKeyword)
- {
- if (!enable)
- return false;
-
- Debug.Assert(m_eventData != null);
- EventLevel eventLevel = (EventLevel)m_eventData[eventNum].Descriptor.Level;
- EventKeywords eventKeywords = unchecked((EventKeywords)((ulong)m_eventData[eventNum].Descriptor.Keywords & (~(SessionMask.All.ToEventKeywords()))));
-
-#if FEATURE_MANAGED_ETW_CHANNELS
- EventChannel channel = unchecked((EventChannel)m_eventData[eventNum].Descriptor.Channel);
-#else
- EventChannel channel = EventChannel.None;
-#endif
-
- return IsEnabledCommon(enable, currentLevel, currentMatchAnyKeyword, eventLevel, eventKeywords, channel);
- }
-
- private bool IsEnabledCommon(bool enabled, EventLevel currentLevel, EventKeywords currentMatchAnyKeyword,
- EventLevel eventLevel, EventKeywords eventKeywords, EventChannel eventChannel)
- {
- if (!enabled)
- return false;
-
- // does is pass the level test?
- if ((currentLevel != 0) && (currentLevel < eventLevel))
- return false;
-
- // if yes, does it pass the keywords test?
- if (currentMatchAnyKeyword != 0 && eventKeywords != 0)
- {
-#if FEATURE_MANAGED_ETW_CHANNELS
- // is there a channel with keywords that match currentMatchAnyKeyword?
- if (eventChannel != EventChannel.None && this.m_channelData != null && this.m_channelData.Length > (int)eventChannel)
- {
- EventKeywords channel_keywords = unchecked((EventKeywords)(m_channelData[(int)eventChannel] | (ulong)eventKeywords));
- if (channel_keywords != 0 && (channel_keywords & currentMatchAnyKeyword) == 0)
- return false;
- }
- else
-#endif
- {
- if ((unchecked((ulong)eventKeywords & (ulong)currentMatchAnyKeyword)) == 0)
- return false;
- }
- }
- return true;
- }
- [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
- private void ThrowEventSourceException(string? eventName, Exception? innerEx = null)
- {
- // If we fail during out of band logging we may end up trying
- // to throw another EventSourceException, thus hitting a StackOverflowException.
- // Avoid StackOverflow by making sure we do not recursively call this method.
- if (m_EventSourceExceptionRecurenceCount > 0)
- return;
- try
- {
- m_EventSourceExceptionRecurenceCount++;
-
- string errorPrefix = "EventSourceException";
- if (eventName != null)
- {
- errorPrefix += " while processing event \"" + eventName + "\"";
- }
-
- // TODO Create variations of EventSourceException that indicate more information using the error code.
- switch (EventProvider.GetLastWriteEventError())
- {
- case EventProvider.WriteEventErrorCode.EventTooBig:
- ReportOutOfBandMessage(errorPrefix + ": " + SR.EventSource_EventTooBig);
- if (ThrowOnEventWriteErrors) throw new EventSourceException(SR.EventSource_EventTooBig, innerEx);
- break;
- case EventProvider.WriteEventErrorCode.NoFreeBuffers:
- ReportOutOfBandMessage(errorPrefix + ": " + SR.EventSource_NoFreeBuffers);
- if (ThrowOnEventWriteErrors) throw new EventSourceException(SR.EventSource_NoFreeBuffers, innerEx);
- break;
- case EventProvider.WriteEventErrorCode.NullInput:
- ReportOutOfBandMessage(errorPrefix + ": " + SR.EventSource_NullInput);
- if (ThrowOnEventWriteErrors) throw new EventSourceException(SR.EventSource_NullInput, innerEx);
- break;
- case EventProvider.WriteEventErrorCode.TooManyArgs:
- ReportOutOfBandMessage(errorPrefix + ": " + SR.EventSource_TooManyArgs);
- if (ThrowOnEventWriteErrors) throw new EventSourceException(SR.EventSource_TooManyArgs, innerEx);
- break;
- default:
- if (innerEx != null)
- {
- innerEx = innerEx.GetBaseException();
- ReportOutOfBandMessage(errorPrefix + ": " + innerEx.GetType() + ":" + innerEx.Message);
- }
- else
- ReportOutOfBandMessage(errorPrefix);
- if (ThrowOnEventWriteErrors) throw new EventSourceException(innerEx);
- break;
- }
- }
- finally
- {
- m_EventSourceExceptionRecurenceCount--;
- }
- }
-
- private void ValidateEventOpcodeForTransfer(ref EventMetadata eventData, string? eventName)
- {
- if ((EventOpcode)eventData.Descriptor.Opcode != EventOpcode.Send &&
- (EventOpcode)eventData.Descriptor.Opcode != EventOpcode.Receive &&
- (EventOpcode)eventData.Descriptor.Opcode != EventOpcode.Start)
- {
- ThrowEventSourceException(eventName);
- }
- }
-
- internal static EventOpcode GetOpcodeWithDefault(EventOpcode opcode, string? eventName)
- {
- if (opcode == EventOpcode.Info && eventName != null)
- {
- if (eventName.EndsWith(s_ActivityStartSuffix, StringComparison.Ordinal))
- {
- return EventOpcode.Start;
- }
- else if (eventName.EndsWith(s_ActivityStopSuffix, StringComparison.Ordinal))
- {
- return EventOpcode.Stop;
- }
- }
-
- return opcode;
- }
-
-#if FEATURE_MANAGED_ETW
- /// <summary>
- /// This class lets us hook the 'OnEventCommand' from the eventSource.
- /// </summary>
- private class OverideEventProvider : EventProvider
- {
- public OverideEventProvider(EventSource eventSource, EventProviderType providerType)
- : base(providerType)
- {
- this.m_eventSource = eventSource;
- this.m_eventProviderType = providerType;
- }
- protected override void OnControllerCommand(ControllerCommand command, IDictionary<string, string?>? arguments,
- int perEventSourceSessionId, int etwSessionId)
- {
- // We use null to represent the ETW EventListener.
- EventListener? listener = null;
- m_eventSource.SendCommand(listener, m_eventProviderType, perEventSourceSessionId, etwSessionId,
- (EventCommand)command, IsEnabled(), Level, MatchAnyKeyword, arguments);
- }
- private readonly EventSource m_eventSource;
- private readonly EventProviderType m_eventProviderType;
- }
-#endif
-
- /// <summary>
- /// Used to hold all the static information about an event. This includes everything in the event
- /// descriptor as well as some stuff we added specifically for EventSource. see the
- /// code:m_eventData for where we use this.
- /// </summary>
-
- /*
- EventMetadata was public in the separate System.Diagnostics.Tracing assembly(pre NS2.0),
- now the move to CoreLib marked them as private.
- While they are technically private (it's a contract used between the library and the ILC toolchain),
- we need them to be rooted and exported from shared library for the system to work.
- For now I'm simply marking them as public again.A cleaner solution might be to use.rd.xml to
- root them and modify shared library definition to force export them.
- */
-#if ES_BUILD_PN
- public
-#else
- internal
-#endif
- partial struct EventMetadata
- {
-#if ES_BUILD_PN
- public EventMetadata(EventDescriptor descriptor,
- EventTags tags,
- bool enabledForAnyListener,
- bool enabledForETW,
- string name,
- string message,
- EventParameterType[] parameterTypes)
- {
- this.Descriptor = descriptor;
- this.Tags = tags;
- this.EnabledForAnyListener = enabledForAnyListener;
- this.EnabledForETW = enabledForETW;
-#if FEATURE_PERFTRACING
- this.EnabledForEventPipe = false;
-#endif
- this.TriggersActivityTracking = 0;
- this.Name = name;
- this.Message = message;
- this.Parameters = null!;
- this.TraceLoggingEventTypes = null;
- this.ActivityOptions = EventActivityOptions.None;
- this.ParameterTypes = parameterTypes;
- this.HasRelatedActivityID = false;
- this.EventHandle = IntPtr.Zero;
- }
-#endif
-
- public EventDescriptor Descriptor;
- public IntPtr EventHandle; // EventPipeEvent handle.
- public EventTags Tags;
- public bool EnabledForAnyListener; // true if any dispatcher has this event turned on
- public bool EnabledForETW; // is this event on for ETW?
-#if FEATURE_PERFTRACING
- public bool EnabledForEventPipe; // is this event on for EventPipe?
-#endif
-
- public bool HasRelatedActivityID; // Set if the event method's first parameter is a Guid named 'relatedActivityId'
-#pragma warning disable 0649
- public byte TriggersActivityTracking; // count of listeners that marked this event as trigger for start of activity logging.
-#pragma warning restore 0649
- public string Name; // the name of the event
- public string? Message; // If the event has a message associated with it, this is it.
- public ParameterInfo[] Parameters; // TODO can we remove?
-
- public TraceLoggingEventTypes? TraceLoggingEventTypes;
- public EventActivityOptions ActivityOptions;
-
-#if ES_BUILD_PN
- public EventParameterType[] ParameterTypes;
-#endif
- }
-
-#if !ES_BUILD_PN
- private static int GetParameterCount(EventMetadata eventData)
- {
- return eventData.Parameters.Length;
- }
-
- private static Type GetDataType(EventMetadata eventData, int parameterId)
- {
- return eventData.Parameters[parameterId].ParameterType;
- }
-
- private const bool m_EventSourcePreventRecursion = false;
-#else
- private static int GetParameterCount(EventMetadata eventData)
- {
- int paramCount;
- if (eventData.Parameters == null)
- {
- paramCount = eventData.ParameterTypes.Length;
- }
- else
- {
- paramCount = eventData.Parameters.Length;
- }
-
- return paramCount;
- }
-
- private static Type GetDataType(EventMetadata eventData, int parameterId)
- {
- Type dataType;
- if (eventData.Parameters == null)
- {
- dataType = EventTypeToType(eventData.ParameterTypes[parameterId]);
- }
- else
- {
- dataType = eventData.Parameters[parameterId].ParameterType;
- }
-
- return dataType;
- }
-
- private static readonly bool m_EventSourcePreventRecursion = true;
-
- public enum EventParameterType
- {
- Boolean,
- Byte,
- SByte,
- Char,
- Int16,
- UInt16,
- Int32,
- UInt32,
- Int64,
- UInt64,
- IntPtr,
- Single,
- Double,
- Decimal,
- Guid,
- String
- }
-
- private static Type EventTypeToType(EventParameterType type)
- {
- switch (type)
- {
- case EventParameterType.Boolean:
- return typeof(bool);
- case EventParameterType.Byte:
- return typeof(byte);
- case EventParameterType.SByte:
- return typeof(sbyte);
- case EventParameterType.Char:
- return typeof(char);
- case EventParameterType.Int16:
- return typeof(short);
- case EventParameterType.UInt16:
- return typeof(ushort);
- case EventParameterType.Int32:
- return typeof(int);
- case EventParameterType.UInt32:
- return typeof(uint);
- case EventParameterType.Int64:
- return typeof(long);
- case EventParameterType.UInt64:
- return typeof(ulong);
- case EventParameterType.IntPtr:
- return typeof(IntPtr);
- case EventParameterType.Single:
- return typeof(float);
- case EventParameterType.Double:
- return typeof(double);
- case EventParameterType.Decimal:
- return typeof(decimal);
- case EventParameterType.Guid:
- return typeof(Guid);
- case EventParameterType.String:
- return typeof(string);
- default:
- // TODO: should I throw an exception here?
- return null!;
- }
- }
-#endif
-
- // This is the internal entry point that code:EventListeners call when wanting to send a command to a
- // eventSource. The logic is as follows
- //
- // * if Command == Update
- // * perEventSourceSessionId specifies the per-provider ETW session ID that the command applies
- // to (if listener != null)
- // perEventSourceSessionId = 0 - reserved for EventListeners
- // perEventSourceSessionId = 1..SessionMask.MAX - reserved for activity tracing aware ETW sessions
- // perEventSourceSessionId-1 represents the bit in the reserved field (bits 44..47) in
- // Keywords that identifies the session
- // perEventSourceSessionId = SessionMask.MAX+1 - reserved for legacy ETW sessions; these are
- // discriminated by etwSessionId
- // * etwSessionId specifies a machine-wide ETW session ID; this allows correlation of
- // activity tracing across different providers (which might have different sessionIds
- // for the same ETW session)
- // * enable, level, matchAnyKeywords are used to set a default for all events for the
- // eventSource. In particular, if 'enabled' is false, 'level' and
- // 'matchAnyKeywords' are not used.
- // * OnEventCommand is invoked, which may cause calls to
- // code:EventSource.EnableEventForDispatcher which may cause changes in the filtering
- // depending on the logic in that routine.
- // * else (command != Update)
- // * Simply call OnEventCommand. The expectation is that filtering is NOT changed.
- // * The 'enabled' 'level', matchAnyKeyword' arguments are ignored (must be true, 0, 0).
- //
- // dispatcher == null has special meaning. It is the 'ETW' dispatcher.
- internal void SendCommand(EventListener? listener, EventProviderType eventProviderType, int perEventSourceSessionId, int etwSessionId,
- EventCommand command, bool enable,
- EventLevel level, EventKeywords matchAnyKeyword,
- IDictionary<string, string?>? commandArguments)
- {
- var commandArgs = new EventCommandEventArgs(command, commandArguments, this, listener, eventProviderType, perEventSourceSessionId, etwSessionId, enable, level, matchAnyKeyword);
- lock (EventListener.EventListenersLock)
- {
- if (m_completelyInited)
- {
- // After the first command arrive after construction, we are ready to get rid of the deferred commands
- this.m_deferredCommands = null;
- // We are fully initialized, do the command
- DoCommand(commandArgs);
- }
- else
- {
- // We can't do the command, simply remember it and we do it when we are fully constructed.
- if (m_deferredCommands == null)
- {
- m_deferredCommands = commandArgs; // create the first entry
- }
- else
- {
- // We have one or more entries, find the last one and add it to that.
- EventCommandEventArgs lastCommand = m_deferredCommands;
- while (lastCommand.nextCommand != null)
- lastCommand = lastCommand.nextCommand;
- lastCommand.nextCommand = commandArgs;
- }
- }
- }
- }
-
- /// <summary>
- /// We want the eventSource to be fully initialized when we do commands because that way we can send
- /// error messages and other logging directly to the event stream. Unfortunately we can get callbacks
- /// when we are not fully initialized. In that case we store them in 'commandArgs' and do them later.
- /// This helper actually does all actual command logic.
- /// </summary>
- internal void DoCommand(EventCommandEventArgs commandArgs)
- {
- // PRECONDITION: We should be holding the EventListener.EventListenersLock
- // We defer commands until we are completely inited. This allows error messages to be sent.
- Debug.Assert(m_completelyInited);
-
-#if FEATURE_MANAGED_ETW
- if (m_etwProvider == null) // If we failed to construct
- return;
-#endif // FEATURE_MANAGED_ETW
-#if FEATURE_PERFTRACING
- if (m_eventPipeProvider == null)
- return;
-#endif
-
- m_outOfBandMessageCount = 0;
- try
- {
- EnsureDescriptorsInitialized();
- Debug.Assert(m_eventData != null);
-
- // Find the per-EventSource dispatcher corresponding to registered dispatcher
- commandArgs.dispatcher = GetDispatcher(commandArgs.listener);
- if (commandArgs.dispatcher == null && commandArgs.listener != null) // dispatcher == null means ETW dispatcher
- {
- throw new ArgumentException(SR.EventSource_ListenerNotFound);
- }
-
- commandArgs.Arguments ??= new Dictionary<string, string?>();
-
- if (commandArgs.Command == EventCommand.Update)
- {
- // Set it up using the 'standard' filtering bitfields (use the "global" enable, not session specific one)
- for (int i = 0; i < m_eventData.Length; i++)
- EnableEventForDispatcher(commandArgs.dispatcher, commandArgs.eventProviderType, i, IsEnabledByDefault(i, commandArgs.enable, commandArgs.level, commandArgs.matchAnyKeyword));
-
- if (commandArgs.enable)
- {
- if (!m_eventSourceEnabled)
- {
- // EventSource turned on for the first time, simply copy the bits.
- m_level = commandArgs.level;
- m_matchAnyKeyword = commandArgs.matchAnyKeyword;
- }
- else
- {
- // Already enabled, make it the most verbose of the existing and new filter
- if (commandArgs.level > m_level)
- m_level = commandArgs.level;
- if (commandArgs.matchAnyKeyword == 0)
- m_matchAnyKeyword = 0;
- else if (m_matchAnyKeyword != 0)
- m_matchAnyKeyword = unchecked(m_matchAnyKeyword | commandArgs.matchAnyKeyword);
- }
- }
-
- // interpret perEventSourceSessionId's sign, and adjust perEventSourceSessionId to
- // represent 0-based positive values
- bool bSessionEnable = (commandArgs.perEventSourceSessionId >= 0);
- if (commandArgs.perEventSourceSessionId == 0 && !commandArgs.enable)
- bSessionEnable = false;
-
- if (commandArgs.listener == null)
- {
- if (!bSessionEnable)
- commandArgs.perEventSourceSessionId = -commandArgs.perEventSourceSessionId;
- // for "global" enable/disable (passed in with listener == null and
- // perEventSourceSessionId == 0) perEventSourceSessionId becomes -1
- --commandArgs.perEventSourceSessionId;
- }
-
- commandArgs.Command = bSessionEnable ? EventCommand.Enable : EventCommand.Disable;
-
- // perEventSourceSessionId = -1 when ETW sent a notification, but the set of active sessions
- // hasn't changed.
- // sesisonId = SessionMask.MAX when one of the legacy ETW sessions changed
- // 0 <= perEventSourceSessionId < SessionMask.MAX for activity-tracing aware sessions
- Debug.Assert(commandArgs.perEventSourceSessionId >= -1 && commandArgs.perEventSourceSessionId <= SessionMask.MAX);
-
- // Send the manifest if we are enabling an ETW session
- if (bSessionEnable && commandArgs.dispatcher == null)
- {
- // eventSourceDispatcher == null means this is the ETW manifest
-
- // Note that we unconditionally send the manifest whenever we are enabled, even if
- // we were already enabled. This is because there may be multiple sessions active
- // and we can't know that all the sessions have seen the manifest.
- if (!SelfDescribingEvents)
- SendManifest(m_rawManifest);
- }
-
- // Turn on the enable bit before making the OnEventCommand callback This allows you to do useful
- // things like log messages, or test if keywords are enabled in the callback.
- if (commandArgs.enable)
- {
- Debug.Assert(m_eventData != null);
- m_eventSourceEnabled = true;
- }
-
- this.OnEventCommand(commandArgs);
- this.m_eventCommandExecuted?.Invoke(this, commandArgs);
-
- if (!commandArgs.enable)
- {
- // If we are disabling, maybe we can turn on 'quick checks' to filter
- // quickly. These are all just optimizations (since later checks will still filter)
-
- // There is a good chance EnabledForAnyListener are not as accurate as
- // they could be, go ahead and get a better estimate.
- for (int i = 0; i < m_eventData.Length; i++)
- {
- bool isEnabledForAnyListener = false;
- for (EventDispatcher? dispatcher = m_Dispatchers; dispatcher != null; dispatcher = dispatcher.m_Next)
- {
- Debug.Assert(dispatcher.m_EventEnabled != null);
-
- if (dispatcher.m_EventEnabled[i])
- {
- isEnabledForAnyListener = true;
- break;
- }
- }
- m_eventData[i].EnabledForAnyListener = isEnabledForAnyListener;
- }
-
- // If no events are enabled, disable the global enabled bit.
- if (!AnyEventEnabled())
- {
- m_level = 0;
- m_matchAnyKeyword = 0;
- m_eventSourceEnabled = false;
- }
- }
- }
- else
- {
-#if !FEATURE_PERFTRACING
- if (commandArgs.Command == EventCommand.SendManifest)
- {
- // TODO: should we generate the manifest here if we hadn't already?
- if (m_rawManifest != null)
- SendManifest(m_rawManifest);
- }
-#endif
-
- // These are not used for non-update commands and thus should always be 'default' values
- // Debug.Assert(enable == true);
- // Debug.Assert(level == EventLevel.LogAlways);
- // Debug.Assert(matchAnyKeyword == EventKeywords.None);
-
- this.OnEventCommand(commandArgs);
- m_eventCommandExecuted?.Invoke(this, commandArgs);
- }
- }
- catch (Exception e)
- {
- // When the ETW session is created after the EventSource has registered with the ETW system
- // we can send any error messages here.
- ReportOutOfBandMessage("ERROR: Exception in Command Processing for EventSource " + Name + ": " + e.Message);
- // We never throw when doing a command.
- }
- }
-
- /// <summary>
- /// If 'value is 'true' then set the eventSource so that 'dispatcher' will receive event with the eventId
- /// of 'eventId. If value is 'false' disable the event for that dispatcher. If 'eventId' is out of
- /// range return false, otherwise true.
- /// </summary>
- internal bool EnableEventForDispatcher(EventDispatcher? dispatcher, EventProviderType eventProviderType, int eventId, bool value)
- {
- Debug.Assert(m_eventData != null);
-
- if (dispatcher == null)
- {
- if (eventId >= m_eventData.Length)
- return false;
-#if FEATURE_MANAGED_ETW
- if (m_etwProvider != null && eventProviderType == EventProviderType.ETW)
- m_eventData[eventId].EnabledForETW = value;
-#endif
-#if FEATURE_PERFTRACING
- if (m_eventPipeProvider != null && eventProviderType == EventProviderType.EventPipe)
- m_eventData[eventId].EnabledForEventPipe = value;
-#endif
- }
- else
- {
- Debug.Assert(dispatcher.m_EventEnabled != null);
- if (eventId >= dispatcher.m_EventEnabled.Length)
- return false;
- dispatcher.m_EventEnabled[eventId] = value;
- if (value)
- m_eventData[eventId].EnabledForAnyListener = true;
- }
- return true;
- }
-
- /// <summary>
- /// Returns true if any event at all is on.
- /// </summary>
- private bool AnyEventEnabled()
- {
- Debug.Assert(m_eventData != null);
-
- for (int i = 0; i < m_eventData.Length; i++)
- if (m_eventData[i].EnabledForETW || m_eventData[i].EnabledForAnyListener
-#if FEATURE_PERFTRACING
- || m_eventData[i].EnabledForEventPipe
-#endif // FEATURE_PERFTRACING
- )
- return true;
- return false;
- }
-
- private bool IsDisposed => m_eventSourceDisposed;
-
- private void EnsureDescriptorsInitialized()
- {
-#if !ES_BUILD_STANDALONE
- Debug.Assert(Monitor.IsEntered(EventListener.EventListenersLock));
-#endif
- if (m_eventData == null)
- {
- Guid eventSourceGuid = Guid.Empty;
- string? eventSourceName = null;
- EventMetadata[]? eventData = null;
- byte[]? manifest = null;
-
- // Try the GetMetadata provided by the ILTransform in ProjectN. The default sets all to null, and in that case we fall back
- // to the reflection approach.
- GetMetadata(out eventSourceGuid, out eventSourceName, out eventData, out manifest);
-
- if (eventSourceGuid.Equals(Guid.Empty) || eventSourceName == null || eventData == null || manifest == null)
- {
- // GetMetadata failed, so we have to set it via reflection.
- Debug.Assert(m_rawManifest == null);
-
- m_rawManifest = CreateManifestAndDescriptors(this.GetType(), Name, this);
- Debug.Assert(m_eventData != null);
- }
- else
- {
- // GetMetadata worked, so set the fields as appropriate.
- m_name = eventSourceName;
- m_guid = eventSourceGuid;
- m_eventData = eventData;
- m_rawManifest = manifest;
- }
- // TODO Enforce singleton pattern
- Debug.Assert(EventListener.s_EventSources != null, "should be called within lock on EventListener.EventListenersLock which ensures s_EventSources to be initialized");
- foreach (WeakReference<EventSource> eventSourceRef in EventListener.s_EventSources)
- {
- if (eventSourceRef.TryGetTarget(out EventSource? eventSource) && eventSource.Guid == m_guid && !eventSource.IsDisposed)
- {
- if (eventSource != this)
- {
- throw new ArgumentException(SR.Format(SR.EventSource_EventSourceGuidInUse, m_guid));
- }
- }
- }
-
- // Make certain all dispatchers also have their arrays initialized
- EventDispatcher? dispatcher = m_Dispatchers;
- while (dispatcher != null)
- {
- dispatcher.m_EventEnabled ??= new bool[m_eventData.Length];
- dispatcher = dispatcher.m_Next;
- }
-#if FEATURE_PERFTRACING
- // Initialize the EventPipe event handles.
- DefineEventPipeEvents();
-#endif
- }
- if (s_currentPid == 0)
- {
-#if ES_BUILD_STANDALONE
- // for non-BCL EventSource we must assert SecurityPermission
- new SecurityPermission(PermissionState.Unrestricted).Assert();
-#endif
- s_currentPid = Interop.GetCurrentProcessId();
- }
- }
-
- // Send out the ETW manifest XML out to ETW
- // Today, we only send the manifest to ETW, custom listeners don't get it.
- private unsafe void SendManifest(byte[]? rawManifest)
- {
- if (rawManifest == null)
- return;
-
- Debug.Assert(!SelfDescribingEvents);
-
-#if FEATURE_MANAGED_ETW
- fixed (byte* dataPtr = rawManifest)
- {
- // we don't want the manifest to show up in the event log channels so we specify as keywords
- // everything but the first 8 bits (reserved for the 8 channels)
- var manifestDescr = new EventDescriptor(0xFFFE, 1, 0, 0, 0xFE, 0xFFFE, 0x00ffFFFFffffFFFF);
- ManifestEnvelope envelope = default;
-
- envelope.Format = ManifestEnvelope.ManifestFormats.SimpleXmlFormat;
- envelope.MajorVersion = 1;
- envelope.MinorVersion = 0;
- envelope.Magic = 0x5B; // An unusual number that can be checked for consistency.
- int dataLeft = rawManifest.Length;
- envelope.ChunkNumber = 0;
-
- EventProvider.EventData* dataDescrs = stackalloc EventProvider.EventData[2];
-
- dataDescrs[0].Ptr = (ulong)&envelope;
- dataDescrs[0].Size = (uint)sizeof(ManifestEnvelope);
- dataDescrs[0].Reserved = 0;
-
- dataDescrs[1].Ptr = (ulong)dataPtr;
- dataDescrs[1].Reserved = 0;
-
- int chunkSize = ManifestEnvelope.MaxChunkSize;
- TRY_AGAIN_WITH_SMALLER_CHUNK_SIZE:
- envelope.TotalChunks = (ushort)((dataLeft + (chunkSize - 1)) / chunkSize);
- while (dataLeft > 0)
- {
- dataDescrs[1].Size = (uint)Math.Min(dataLeft, chunkSize);
- if (m_etwProvider != null)
- {
- if (!m_etwProvider.WriteEvent(ref manifestDescr, IntPtr.Zero, null, null, 2, (IntPtr)dataDescrs))
- {
- // Turns out that if users set the BufferSize to something less than 64K then WriteEvent
- // can fail. If we get this failure on the first chunk try again with something smaller
- // The smallest BufferSize is 1K so if we get to 256 (to account for envelope overhead), we can give up making it smaller.
- if (EventProvider.GetLastWriteEventError() == EventProvider.WriteEventErrorCode.EventTooBig)
- {
- if (envelope.ChunkNumber == 0 && chunkSize > 256)
- {
- chunkSize /= 2;
- goto TRY_AGAIN_WITH_SMALLER_CHUNK_SIZE;
- }
- }
-
- if (ThrowOnEventWriteErrors)
- ThrowEventSourceException("SendManifest");
- break;
- }
- }
- dataLeft -= chunkSize;
- dataDescrs[1].Ptr += (uint)chunkSize;
- envelope.ChunkNumber++;
-
- // For large manifests we want to not overflow any receiver's buffer. Most manifests will fit within
- // 5 chunks, so only the largest manifests will hit the pause.
- if ((envelope.ChunkNumber % 5) == 0)
- {
- Thread.Sleep(15);
- }
- }
- }
-#endif // FEATURE_MANAGED_ETW
- }
-
-#if (ES_BUILD_PCL)
- internal static Attribute GetCustomAttributeHelper(Type type, Type attributeType, EventManifestOptions flags = EventManifestOptions.None)
- {
- return GetCustomAttributeHelper(type.GetTypeInfo(), attributeType, flags);
- }
-#endif
-
- // Helper to deal with the fact that the type we are reflecting over might be loaded in the ReflectionOnly context.
- // When that is the case, we have the build the custom assemblies on a member by hand.
- internal static Attribute? GetCustomAttributeHelper(MemberInfo member, Type attributeType, EventManifestOptions flags = EventManifestOptions.None)
- {
-#if !ES_BUILD_PN
- // On ProjectN, ReflectionOnly() always equals false. AllowEventSourceOverride is an option that allows either Microsoft.Diagnostics.Tracing or
- // System.Diagnostics.Tracing EventSource to be considered valid. This should not mattter anywhere but in Microsoft.Diagnostics.Tracing (nuget package).
- if (!member.Module.Assembly.ReflectionOnly() && (flags & EventManifestOptions.AllowEventSourceOverride) == 0)
-#endif // !ES_BUILD_PN
- {
- // Let the runtime to the work for us, since we can execute code in this context.
- Attribute? firstAttribute = null;
- foreach (object attribute in member.GetCustomAttributes(attributeType, false))
- {
- firstAttribute = (Attribute)attribute;
- break;
- }
- return firstAttribute;
- }
-
-#if (!ES_BUILD_PCL && !ES_BUILD_PN)
- foreach (CustomAttributeData data in CustomAttributeData.GetCustomAttributes(member))
- {
- if (AttributeTypeNamesMatch(attributeType, data.Constructor.ReflectedType!))
- {
- Attribute? attr = null;
-
- Debug.Assert(data.ConstructorArguments.Count <= 1);
-
- if (data.ConstructorArguments.Count == 1)
- {
- attr = (Attribute?)Activator.CreateInstance(attributeType, new object?[] { data.ConstructorArguments[0].Value });
- }
- else if (data.ConstructorArguments.Count == 0)
- {
- attr = (Attribute?)Activator.CreateInstance(attributeType);
- }
-
- if (attr != null)
- {
- Type t = attr.GetType();
-
- foreach (CustomAttributeNamedArgument namedArgument in data.NamedArguments)
- {
- PropertyInfo p = t.GetProperty(namedArgument.MemberInfo.Name, BindingFlags.Public | BindingFlags.Instance)!;
- object value = namedArgument.TypedValue.Value!;
-
- if (p.PropertyType.IsEnum)
- {
- string val = value.ToString()!;
- value = Enum.Parse(p.PropertyType, val);
- }
-
- p.SetValue(attr, value, null);
- }
-
- return attr;
- }
- }
- }
-
- return null;
-#else // ES_BUILD_PCL && ES_BUILD_PN
- // Don't use nameof here because the resource doesn't exist on some platforms, which results in a compilation error.
- throw new ArgumentException("EventSource_PCLPlatformNotSupportedReflection", "EventSource");
-#endif
- }
-
- /// <summary>
- /// Evaluates if two related "EventSource"-domain types should be considered the same
- /// </summary>
- /// <param name="attributeType">The attribute type in the load context - it's associated with the running
- /// EventSource type. This type may be different fromt he base type of the user-defined EventSource.</param>
- /// <param name="reflectedAttributeType">The attribute type in the reflection context - it's associated with
- /// the user-defined EventSource, and is in the same assembly as the eventSourceType passed to
- /// </param>
- /// <returns>True - if the types should be considered equivalent, False - otherwise</returns>
- private static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAttributeType)
- {
- return
- // are these the same type?
- attributeType == reflectedAttributeType ||
- // are the full typenames equal?
- string.Equals(attributeType.FullName, reflectedAttributeType.FullName, StringComparison.Ordinal) ||
- // are the typenames equal and the namespaces under "Diagnostics.Tracing" (typically
- // either Microsoft.Diagnostics.Tracing or System.Diagnostics.Tracing)?
- string.Equals(attributeType.Name, reflectedAttributeType.Name, StringComparison.Ordinal) &&
- attributeType.Namespace!.EndsWith("Diagnostics.Tracing", StringComparison.Ordinal) &&
- (reflectedAttributeType.Namespace!.EndsWith("Diagnostics.Tracing", StringComparison.Ordinal)
-#if EVENT_SOURCE_LEGACY_NAMESPACE_SUPPORT
- || reflectedAttributeType.Namespace.EndsWith("Diagnostics.Eventing", StringComparison.Ordinal)
-#endif
-);
- }
-
- private static Type? GetEventSourceBaseType(Type eventSourceType, bool allowEventSourceOverride, bool reflectionOnly)
- {
- Type? ret = eventSourceType;
-
- // return false for "object" and interfaces
- if (ret.BaseType() == null)
- return null;
-
- // now go up the inheritance chain until hitting a concrete type ("object" at worse)
- do
- {
- ret = ret.BaseType();
- }
- while (ret != null && ret.IsAbstract());
-
- if (ret != null)
- {
- if (!allowEventSourceOverride)
- {
- if (reflectionOnly && ret.FullName != typeof(EventSource).FullName ||
- !reflectionOnly && ret != typeof(EventSource))
- return null;
- }
- else
- {
- if (ret.Name != "EventSource")
- return null;
- }
- }
- return ret;
- }
-
- // Use reflection to look at the attributes of a class, and generate a manifest for it (as UTF8) and
- // return the UTF8 bytes. It also sets up the code:EventData structures needed to dispatch events
- // at run time. 'source' is the event source to place the descriptors. If it is null,
- // then the descriptors are not creaed, and just the manifest is generated.
- private static byte[]? CreateManifestAndDescriptors(Type eventSourceType, string? eventSourceDllName, EventSource? source,
- EventManifestOptions flags = EventManifestOptions.None)
- {
- ManifestBuilder? manifest = null;
- bool bNeedsManifest = source != null ? !source.SelfDescribingEvents : true;
- Exception? exception = null; // exception that might get raised during validation b/c we couldn't/didn't recover from a previous error
- byte[]? res = null;
-
- if (eventSourceType.IsAbstract() && (flags & EventManifestOptions.Strict) == 0)
- return null;
-
- try
- {
- MethodInfo[] methods = eventSourceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
- EventAttribute defaultEventAttribute;
- int eventId = 1; // The number given to an event that does not have a explicitly given ID.
- EventMetadata[]? eventData = null;
- Dictionary<string, string>? eventsByName = null;
- if (source != null || (flags & EventManifestOptions.Strict) != 0)
- {
- eventData = new EventMetadata[methods.Length + 1];
- eventData[0].Name = ""; // Event 0 is the 'write messages string' event, and has an empty name.
- }
-
- // See if we have localization information.
- ResourceManager? resources = null;
- EventSourceAttribute? eventSourceAttrib = (EventSourceAttribute?)GetCustomAttributeHelper(eventSourceType, typeof(EventSourceAttribute), flags);
- if (eventSourceAttrib != null && eventSourceAttrib.LocalizationResources != null)
- resources = new ResourceManager(eventSourceAttrib.LocalizationResources, eventSourceType.Assembly());
-
- manifest = new ManifestBuilder(GetName(eventSourceType, flags), GetGuid(eventSourceType), eventSourceDllName,
- resources, flags);
-
- // Add an entry unconditionally for event ID 0 which will be for a string message.
- manifest.StartEvent("EventSourceMessage", new EventAttribute(0) { Level = EventLevel.LogAlways, Task = (EventTask)0xFFFE });
- manifest.AddEventParameter(typeof(string), "message");
- manifest.EndEvent();
-
- // eventSourceType must be sealed and must derive from this EventSource
- if ((flags & EventManifestOptions.Strict) != 0)
- {
- bool typeMatch = GetEventSourceBaseType(eventSourceType, (flags & EventManifestOptions.AllowEventSourceOverride) != 0, eventSourceType.Assembly().ReflectionOnly()) != null;
-
- if (!typeMatch)
- {
- manifest.ManifestError(SR.EventSource_TypeMustDeriveFromEventSource);
- }
- if (!eventSourceType.IsAbstract() && !eventSourceType.IsSealed())
- {
- manifest.ManifestError(SR.EventSource_TypeMustBeSealedOrAbstract);
- }
- }
-
- // Collect task, opcode, keyword and channel information
-#if FEATURE_MANAGED_ETW_CHANNELS && FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
- foreach (var providerEnumKind in new string[] { "Keywords", "Tasks", "Opcodes", "Channels" })
-#else
- foreach (string providerEnumKind in new string[] { "Keywords", "Tasks", "Opcodes" })
-#endif
- {
- Type? nestedType = eventSourceType.GetNestedType(providerEnumKind);
- if (nestedType != null)
- {
- if (eventSourceType.IsAbstract())
- {
- manifest.ManifestError(SR.Format(SR.EventSource_AbstractMustNotDeclareKTOC, nestedType.Name));
- }
- else
- {
- foreach (FieldInfo staticField in nestedType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static))
- {
- AddProviderEnumKind(manifest, staticField, providerEnumKind);
- }
- }
- }
- }
- // ensure we have keywords for the session-filtering reserved bits
- {
- manifest.AddKeyword("Session3", (long)0x1000 << 32);
- manifest.AddKeyword("Session2", (long)0x2000 << 32);
- manifest.AddKeyword("Session1", (long)0x4000 << 32);
- manifest.AddKeyword("Session0", (long)0x8000 << 32);
- }
-
- if (eventSourceType != typeof(EventSource))
- {
- for (int i = 0; i < methods.Length; i++)
- {
- MethodInfo method = methods[i];
- ParameterInfo[] args = method.GetParameters();
-
- // Get the EventDescriptor (from the Custom attributes)
- EventAttribute? eventAttribute = (EventAttribute?)GetCustomAttributeHelper(method, typeof(EventAttribute), flags);
-
- // Compat: until v4.5.1 we ignored any non-void returning methods as well as virtual methods for
- // the only reason of limiting the number of methods considered to be events. This broke a common
- // design of having event sources implement specific interfaces. To fix this in a compatible way
- // we will now allow both non-void returning and virtual methods to be Event methods, as long
- // as they are marked with the [Event] attribute
- if (/* method.IsVirtual || */ method.IsStatic)
- {
- continue;
- }
-
- if (eventSourceType.IsAbstract())
- {
- if (eventAttribute != null)
- {
- manifest.ManifestError(SR.Format(SR.EventSource_AbstractMustNotDeclareEventMethods, method.Name, eventAttribute.EventId));
- }
- continue;
- }
- else if (eventAttribute == null)
- {
- // Methods that don't return void can't be events, if they're NOT marked with [Event].
- // (see Compat comment above)
- if (method.ReturnType != typeof(void))
- {
- continue;
- }
-
- // Continue to ignore virtual methods if they do NOT have the [Event] attribute
- // (see Compat comment above)
- if (method.IsVirtual)
- {
- continue;
- }
-
- // If we explicitly mark the method as not being an event, then honor that.
- if (GetCustomAttributeHelper(method, typeof(NonEventAttribute), flags) != null)
- continue;
-
- defaultEventAttribute = new EventAttribute(eventId);
- eventAttribute = defaultEventAttribute;
- }
- else if (eventAttribute.EventId <= 0)
- {
- manifest.ManifestError(SR.Format(SR.EventSource_NeedPositiveId, method.Name), true);
- continue; // don't validate anything else for this event
- }
- if (method.Name.LastIndexOf('.') >= 0)
- {
- manifest.ManifestError(SR.Format(SR.EventSource_EventMustNotBeExplicitImplementation, method.Name, eventAttribute.EventId));
- }
-
- eventId++;
- string eventName = method.Name;
-
- if (eventAttribute.Opcode == EventOpcode.Info) // We are still using the default opcode.
- {
- // By default pick a task ID derived from the EventID, starting with the highest task number and working back
- bool noTask = (eventAttribute.Task == EventTask.None);
- if (noTask)
- eventAttribute.Task = (EventTask)(0xFFFE - eventAttribute.EventId);
-
- // Unless we explicitly set the opcode to Info (to override the auto-generate of Start or Stop opcodes,
- // pick a default opcode based on the event name (either Info or start or stop if the name ends with that suffix).
- if (!eventAttribute.IsOpcodeSet)
- eventAttribute.Opcode = GetOpcodeWithDefault(EventOpcode.Info, eventName);
-
- // Make the stop opcode have the same task as the start opcode.
- if (noTask)
- {
- if (eventAttribute.Opcode == EventOpcode.Start)
- {
- string taskName = eventName.Substring(0, eventName.Length - s_ActivityStartSuffix.Length); // Remove the Stop suffix to get the task name
- if (string.Compare(eventName, 0, taskName, 0, taskName.Length) == 0 &&
- string.Compare(eventName, taskName.Length, s_ActivityStartSuffix, 0, Math.Max(eventName.Length - taskName.Length, s_ActivityStartSuffix.Length)) == 0)
- {
- // Add a task that is just the task name for the start event. This suppress the auto-task generation
- // That would otherwise happen (and create 'TaskName'Start as task name rather than just 'TaskName'
- manifest.AddTask(taskName, (int)eventAttribute.Task);
- }
- }
- else if (eventAttribute.Opcode == EventOpcode.Stop)
- {
- // Find the start associated with this stop event. We require start to be immediately before the stop
- int startEventId = eventAttribute.EventId - 1;
- if (eventData != null && startEventId < eventData.Length)
- {
- Debug.Assert(0 <= startEventId); // Since we reserve id 0, we know that id-1 is <= 0
- EventMetadata startEventMetadata = eventData[startEventId];
-
- // If you remove the Stop and add a Start does that name match the Start Event's Name?
- // Ideally we would throw an error
- string taskName = eventName.Substring(0, eventName.Length - s_ActivityStopSuffix.Length); // Remove the Stop suffix to get the task name
- if (startEventMetadata.Descriptor.Opcode == (byte)EventOpcode.Start &&
- string.Compare(startEventMetadata.Name, 0, taskName, 0, taskName.Length) == 0 &&
- string.Compare(startEventMetadata.Name, taskName.Length, s_ActivityStartSuffix, 0, Math.Max(startEventMetadata.Name.Length - taskName.Length, s_ActivityStartSuffix.Length)) == 0)
- {
- // Make the stop event match the start event
- eventAttribute.Task = (EventTask)startEventMetadata.Descriptor.Task;
- noTask = false;
- }
- }
- if (noTask && (flags & EventManifestOptions.Strict) != 0) // Throw an error if we can compatibly.
- {
- throw new ArgumentException(SR.EventSource_StopsFollowStarts);
- }
- }
- }
- }
-
- bool hasRelatedActivityID = RemoveFirstArgIfRelatedActivityId(ref args);
- if (!(source != null && source.SelfDescribingEvents))
- {
- manifest.StartEvent(eventName, eventAttribute);
- for (int fieldIdx = 0; fieldIdx < args.Length; fieldIdx++)
- {
- manifest.AddEventParameter(args[fieldIdx].ParameterType, args[fieldIdx].Name!);
- }
- manifest.EndEvent();
- }
-
- if (source != null || (flags & EventManifestOptions.Strict) != 0)
- {
- Debug.Assert(eventData != null);
- // Do checking for user errors (optional, but not a big deal so we do it).
- DebugCheckEvent(ref eventsByName, eventData, method, eventAttribute, manifest, flags);
-
-#if FEATURE_MANAGED_ETW_CHANNELS
- // add the channel keyword for Event Viewer channel based filters. This is added for creating the EventDescriptors only
- // and is not required for the manifest
- if (eventAttribute.Channel != EventChannel.None)
- {
- unchecked
- {
- eventAttribute.Keywords |= (EventKeywords)manifest.GetChannelKeyword(eventAttribute.Channel, (ulong)eventAttribute.Keywords);
- }
- }
-#endif
- string eventKey = "event_" + eventName;
- string? msg = manifest.GetLocalizedMessage(eventKey, CultureInfo.CurrentUICulture, etwFormat: false);
- // overwrite inline message with the localized message
- if (msg != null) eventAttribute.Message = msg;
-
- AddEventDescriptor(ref eventData, eventName, eventAttribute, args, hasRelatedActivityID);
- }
- }
- }
-
- // Tell the TraceLogging stuff where to start allocating its own IDs.
- NameInfo.ReserveEventIDsBelow(eventId);
-
- if (source != null)
- {
- Debug.Assert(eventData != null);
- TrimEventDescriptors(ref eventData);
- source.m_eventData = eventData; // officially initialize it. We do this at most once (it is racy otherwise).
-#if FEATURE_MANAGED_ETW_CHANNELS
- source.m_channelData = manifest.GetChannelData();
-#endif
- }
-
- // if this is an abstract event source we've already performed all the validation we can
- if (!eventSourceType.IsAbstract() && (source == null || !source.SelfDescribingEvents))
- {
- bNeedsManifest = (flags & EventManifestOptions.OnlyIfNeededForRegistration) == 0
-#if FEATURE_MANAGED_ETW_CHANNELS
- || manifest.GetChannelData().Length > 0
-#endif
-;
-
- // if the manifest is not needed and we're not requested to validate the event source return early
- if (!bNeedsManifest && (flags & EventManifestOptions.Strict) == 0)
- return null;
-
- res = manifest.CreateManifest();
- }
- }
- catch (Exception e)
- {
- // if this is a runtime manifest generation let the exception propagate
- if ((flags & EventManifestOptions.Strict) == 0)
- throw;
- // else store it to include it in the Argument exception we raise below
- exception = e;
- }
-
- if ((flags & EventManifestOptions.Strict) != 0 && (manifest?.Errors.Count > 0 || exception != null))
- {
- string msg = string.Empty;
-
- if (manifest?.Errors.Count > 0)
- {
- bool firstError = true;
- foreach (string error in manifest.Errors)
- {
- if (!firstError)
- msg += Environment.NewLine;
- firstError = false;
- msg += error;
- }
- }
- else
- msg = "Unexpected error: " + exception!.Message;
-
- throw new ArgumentException(msg, exception);
- }
-
- return bNeedsManifest ? res : null;
- }
-
- private static bool RemoveFirstArgIfRelatedActivityId(ref ParameterInfo[] args)
- {
- // If the first parameter is (case insensitive) 'relatedActivityId' then skip it.
- if (args.Length > 0 && args[0].ParameterType == typeof(Guid) &&
- string.Equals(args[0].Name, "relatedActivityId", StringComparison.OrdinalIgnoreCase))
- {
- var newargs = new ParameterInfo[args.Length - 1];
- Array.Copy(args, 1, newargs, 0, args.Length - 1);
- args = newargs;
-
- return true;
- }
-
- return false;
- }
-
- // adds a enumeration (keyword, opcode, task or channel) represented by 'staticField'
- // to the manifest.
- private static void AddProviderEnumKind(ManifestBuilder manifest, FieldInfo staticField, string providerEnumKind)
- {
- bool reflectionOnly = staticField.Module.Assembly.ReflectionOnly();
- Type staticFieldType = staticField.FieldType;
- if (!reflectionOnly && (staticFieldType == typeof(EventOpcode)) || AttributeTypeNamesMatch(staticFieldType, typeof(EventOpcode)))
- {
- if (providerEnumKind != "Opcodes") goto Error;
- int value = (int)staticField.GetRawConstantValue()!;
- manifest.AddOpcode(staticField.Name, value);
- }
- else if (!reflectionOnly && (staticFieldType == typeof(EventTask)) || AttributeTypeNamesMatch(staticFieldType, typeof(EventTask)))
- {
- if (providerEnumKind != "Tasks") goto Error;
- int value = (int)staticField.GetRawConstantValue()!;
- manifest.AddTask(staticField.Name, value);
- }
- else if (!reflectionOnly && (staticFieldType == typeof(EventKeywords)) || AttributeTypeNamesMatch(staticFieldType, typeof(EventKeywords)))
- {
- if (providerEnumKind != "Keywords") goto Error;
- ulong value = unchecked((ulong)(long)staticField.GetRawConstantValue()!);
- manifest.AddKeyword(staticField.Name, value);
- }
-#if FEATURE_MANAGED_ETW_CHANNELS && FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
- else if (!reflectionOnly && (staticFieldType == typeof(EventChannel)) || AttributeTypeNamesMatch(staticFieldType, typeof(EventChannel)))
- {
- if (providerEnumKind != "Channels") goto Error;
- var channelAttribute = (EventChannelAttribute)GetCustomAttributeHelper(staticField, typeof(EventChannelAttribute));
- manifest.AddChannel(staticField.Name, (byte)staticField.GetRawConstantValue(), channelAttribute);
- }
-#endif
- return;
- Error:
- manifest.ManifestError(SR.Format(SR.EventSource_EnumKindMismatch, staticField.Name, staticField.FieldType.Name, providerEnumKind));
- }
-
- // Helper used by code:CreateManifestAndDescriptors to add a code:EventData descriptor for a method
- // with the code:EventAttribute 'eventAttribute'. resourceManger may be null in which case we populate it
- // it is populated if we need to look up message resources
- private static void AddEventDescriptor(
- [NotNull] ref EventMetadata[] eventData,
- string eventName,
- EventAttribute eventAttribute,
- ParameterInfo[] eventParameters,
- bool hasRelatedActivityID)
- {
- if (eventData.Length <= eventAttribute.EventId)
- {
- EventMetadata[] newValues = new EventMetadata[Math.Max(eventData.Length + 16, eventAttribute.EventId + 1)];
- Array.Copy(eventData, newValues, eventData.Length);
- eventData = newValues;
- }
-
- eventData[eventAttribute.EventId].Descriptor = new EventDescriptor(
- eventAttribute.EventId,
- eventAttribute.Version,
-#if FEATURE_MANAGED_ETW_CHANNELS
- (byte)eventAttribute.Channel,
-#else
- (byte)0,
-#endif
- (byte)eventAttribute.Level,
- (byte)eventAttribute.Opcode,
- (int)eventAttribute.Task,
- unchecked((long)((ulong)eventAttribute.Keywords | SessionMask.All.ToEventKeywords())));
-
- eventData[eventAttribute.EventId].Tags = eventAttribute.Tags;
- eventData[eventAttribute.EventId].Name = eventName;
- eventData[eventAttribute.EventId].Parameters = eventParameters;
- eventData[eventAttribute.EventId].Message = eventAttribute.Message;
- eventData[eventAttribute.EventId].ActivityOptions = eventAttribute.ActivityOptions;
- eventData[eventAttribute.EventId].HasRelatedActivityID = hasRelatedActivityID;
- eventData[eventAttribute.EventId].EventHandle = IntPtr.Zero;
- }
-
- // Helper used by code:CreateManifestAndDescriptors that trims the m_eventData array to the correct
- // size after all event descriptors have been added.
- private static void TrimEventDescriptors(ref EventMetadata[] eventData)
- {
- int idx = eventData.Length;
- while (0 < idx)
- {
- --idx;
- if (eventData[idx].Descriptor.EventId != 0)
- break;
- }
- if (eventData.Length - idx > 2) // allow one wasted slot.
- {
- EventMetadata[] newValues = new EventMetadata[idx + 1];
- Array.Copy(eventData, newValues, newValues.Length);
- eventData = newValues;
- }
- }
-
- // Helper used by code:EventListener.AddEventSource and code:EventListener.EventListener
- // when a listener gets attached to a eventSource
- internal void AddListener(EventListener listener)
- {
- lock (EventListener.EventListenersLock)
- {
- bool[]? enabledArray = null;
- if (m_eventData != null)
- enabledArray = new bool[m_eventData.Length];
- m_Dispatchers = new EventDispatcher(m_Dispatchers, enabledArray, listener);
- listener.OnEventSourceCreated(this);
- }
- }
-
- // Helper used by code:CreateManifestAndDescriptors to find user mistakes like reusing an event
- // index for two distinct events etc. Throws exceptions when it finds something wrong.
- private static void DebugCheckEvent(ref Dictionary<string, string>? eventsByName,
- EventMetadata[] eventData, MethodInfo method, EventAttribute eventAttribute,
- ManifestBuilder manifest, EventManifestOptions options)
- {
- int evtId = eventAttribute.EventId;
- string evtName = method.Name;
- int eventArg = GetHelperCallFirstArg(method);
- if (eventArg >= 0 && evtId != eventArg)
- {
- manifest.ManifestError(SR.Format(SR.EventSource_MismatchIdToWriteEvent, evtName, evtId, eventArg), true);
- }
-
- if (evtId < eventData.Length && eventData[evtId].Descriptor.EventId != 0)
- {
- manifest.ManifestError(SR.Format(SR.EventSource_EventIdReused, evtName, evtId, eventData[evtId].Name), true);
- }
-
- // We give a task to things if they don't have one.
- // TODO this is moderately expensive (N*N). We probably should not even bother....
- Debug.Assert(eventAttribute.Task != EventTask.None || eventAttribute.Opcode != EventOpcode.Info);
- for (int idx = 0; idx < eventData.Length; ++idx)
- {
- // skip unused Event IDs.
- if (eventData[idx].Name == null)
- continue;
-
- if (eventData[idx].Descriptor.Task == (int)eventAttribute.Task && eventData[idx].Descriptor.Opcode == (int)eventAttribute.Opcode)
- {
- manifest.ManifestError(SR.Format(SR.EventSource_TaskOpcodePairReused,
- evtName, evtId, eventData[idx].Name, idx));
- // If we are not strict stop on first error. We have had problems with really large providers taking forever. because of many errors.
- if ((options & EventManifestOptions.Strict) == 0)
- break;
- }
- }
-
- // for non-default event opcodes the user must define a task!
- if (eventAttribute.Opcode != EventOpcode.Info)
- {
- bool failure = false;
- if (eventAttribute.Task == EventTask.None)
- failure = true;
- else
- {
- // If you have the auto-assigned Task, then you did not explicitly set one.
- // This is OK for Start events because we have special logic to assign the task to a prefix derived from the event name
- // But all other cases we want to catch the omission.
- var autoAssignedTask = (EventTask)(0xFFFE - evtId);
- if (eventAttribute.Opcode != EventOpcode.Start && eventAttribute.Opcode != EventOpcode.Stop && eventAttribute.Task == autoAssignedTask)
- failure = true;
- }
- if (failure)
- {
- manifest.ManifestError(SR.Format(SR.EventSource_EventMustHaveTaskIfNonDefaultOpcode, evtName, evtId));
- }
- }
-
- // If we ever want to enforce the rule: MethodName = TaskName + OpcodeName here's how:
- // (the reason we don't is backwards compat and the need for handling this as a non-fatal error
- // by eventRegister.exe)
- // taskName & opcodeName could be passed in by the caller which has opTab & taskTab handy
- // if (!(((int)eventAttribute.Opcode == 0 && evtName == taskName) || (evtName == taskName+opcodeName)))
- // {
- // throw new WarningException(SR.EventSource_EventNameDoesNotEqualTaskPlusOpcode);
- // }
-
- eventsByName ??= new Dictionary<string, string>();
-
- if (eventsByName.ContainsKey(evtName))
- {
- manifest.ManifestError(SR.Format(SR.EventSource_EventNameReused, evtName), true);
- }
-
- eventsByName[evtName] = evtName;
- }
-
- /// <summary>
- /// This method looks at the IL and tries to pattern match against the standard
- /// 'boilerplate' event body
- /// <code>
- /// { if (Enabled()) WriteEvent(#, ...) }
- /// </code>
- /// If the pattern matches, it returns the literal number passed as the first parameter to
- /// the WriteEvent. This is used to find common user errors (mismatching this
- /// number with the EventAttribute ID). It is only used for validation.
- /// </summary>
- /// <param name="method">The method to probe.</param>
- /// <returns>The literal value or -1 if the value could not be determined. </returns>
- private static int GetHelperCallFirstArg(MethodInfo method)
- {
-#if (!ES_BUILD_PCL && !ES_BUILD_PN)
- // Currently searches for the following pattern
- //
- // ... // CAN ONLY BE THE INSTRUCTIONS BELOW
- // LDARG0
- // LDC.I4 XXX
- // ... // CAN ONLY BE THE INSTRUCTIONS BELOW CAN'T BE A BRANCH OR A CALL
- // CALL
- // NOP // 0 or more times
- // RET
- //
- // If we find this pattern we return the XXX. Otherwise we return -1.
-#if ES_BUILD_STANDALONE
- (new ReflectionPermission(ReflectionPermissionFlag.MemberAccess)).Assert();
-#endif
- byte[] instrs = method.GetMethodBody()!.GetILAsByteArray()!;
- int retVal = -1;
- for (int idx = 0; idx < instrs.Length;)
- {
- switch (instrs[idx])
- {
- case 0: // NOP
- case 1: // BREAK
- case 2: // LDARG_0
- case 3: // LDARG_1
- case 4: // LDARG_2
- case 5: // LDARG_3
- case 6: // LDLOC_0
- case 7: // LDLOC_1
- case 8: // LDLOC_2
- case 9: // LDLOC_3
- case 10: // STLOC_0
- case 11: // STLOC_1
- case 12: // STLOC_2
- case 13: // STLOC_3
- break;
- case 14: // LDARG_S
- case 16: // STARG_S
- idx++;
- break;
- case 20: // LDNULL
- break;
- case 21: // LDC_I4_M1
- case 22: // LDC_I4_0
- case 23: // LDC_I4_1
- case 24: // LDC_I4_2
- case 25: // LDC_I4_3
- case 26: // LDC_I4_4
- case 27: // LDC_I4_5
- case 28: // LDC_I4_6
- case 29: // LDC_I4_7
- case 30: // LDC_I4_8
- if (idx > 0 && instrs[idx - 1] == 2) // preceeded by LDARG0
- retVal = instrs[idx] - 22;
- break;
- case 31: // LDC_I4_S
- if (idx > 0 && instrs[idx - 1] == 2) // preceeded by LDARG0
- retVal = instrs[idx + 1];
- idx++;
- break;
- case 32: // LDC_I4
- idx += 4;
- break;
- case 37: // DUP
- break;
- case 40: // CALL
- idx += 4;
-
- if (retVal >= 0)
- {
- // Is this call just before return?
- for (int search = idx + 1; search < instrs.Length; search++)
- {
- if (instrs[search] == 42) // RET
- return retVal;
- if (instrs[search] != 0) // NOP
- break;
- }
- }
- retVal = -1;
- break;
- case 44: // BRFALSE_S
- case 45: // BRTRUE_S
- retVal = -1;
- idx++;
- break;
- case 57: // BRFALSE
- case 58: // BRTRUE
- retVal = -1;
- idx += 4;
- break;
- case 103: // CONV_I1
- case 104: // CONV_I2
- case 105: // CONV_I4
- case 106: // CONV_I8
- case 109: // CONV_U4
- case 110: // CONV_U8
- break;
- case 140: // BOX
- case 141: // NEWARR
- idx += 4;
- break;
- case 162: // STELEM_REF
- break;
- case 254: // PREFIX
- idx++;
- // Covers the CEQ instructions used in debug code for some reason.
- if (idx >= instrs.Length || instrs[idx] >= 6)
- goto default;
- break;
- default:
- /* Debug.Fail("Warning: User validation code sub-optimial: Unsuported opcode " + instrs[idx] +
- " at " + idx + " in method " + method.Name); */
- return -1;
- }
- idx++;
- }
-#endif
- return -1;
- }
-
- /// <summary>
- /// Sends an error message to the debugger (outputDebugString), as well as the EventListeners
- /// It will do this even if the EventSource is not enabled.
- /// </summary>
- internal void ReportOutOfBandMessage(string msg)
- {
- try
- {
-#if (!ES_BUILD_PCL && !ES_BUILD_PN)
- // send message to debugger without delay
- System.Diagnostics.Debugger.Log(0, null, string.Format("EventSource Error: {0}{1}", msg, Environment.NewLine));
-#endif
-
- // Send it to all listeners.
- if (m_outOfBandMessageCount < 16 - 1) // Note this is only if size byte
- m_outOfBandMessageCount++;
- else
- {
- if (m_outOfBandMessageCount == 16)
- return;
- m_outOfBandMessageCount = 16; // Mark that we hit the limit. Notify them that this is the case.
- msg = "Reached message limit. End of EventSource error messages.";
- }
-
- WriteEventString(EventLevel.LogAlways, -1, msg);
- WriteStringToAllListeners("EventSourceMessage", msg);
- }
- catch { } // If we fail during last chance logging, well, we have to give up....
- }
-
- private EventSourceSettings ValidateSettings(EventSourceSettings settings)
- {
- const EventSourceSettings evtFormatMask = EventSourceSettings.EtwManifestEventFormat |
- EventSourceSettings.EtwSelfDescribingEventFormat;
- if ((settings & evtFormatMask) == evtFormatMask)
- {
- throw new ArgumentException(SR.EventSource_InvalidEventFormat, nameof(settings));
- }
-
- // If you did not explicitly ask for manifest, you get self-describing.
- if ((settings & evtFormatMask) == 0)
- settings |= EventSourceSettings.EtwSelfDescribingEventFormat;
- return settings;
- }
-
- private bool ThrowOnEventWriteErrors => (m_config & EventSourceSettings.ThrowOnEventWriteErrors) != 0;
-
- private bool SelfDescribingEvents
- {
- get
- {
- Debug.Assert(((m_config & EventSourceSettings.EtwManifestEventFormat) != 0) !=
- ((m_config & EventSourceSettings.EtwSelfDescribingEventFormat) != 0));
- return (m_config & EventSourceSettings.EtwSelfDescribingEventFormat) != 0;
- }
- }
-
- // private instance state
- private string m_name = null!; // My friendly name (privided in ctor)
- internal int m_id; // A small integer that is unique to this instance.
- private Guid m_guid; // GUID representing the ETW eventSource to the OS.
- internal volatile EventMetadata[]? m_eventData; // None per-event data
- private volatile byte[]? m_rawManifest; // Bytes to send out representing the event schema
-
- private EventHandler<EventCommandEventArgs>? m_eventCommandExecuted;
-
- private readonly EventSourceSettings m_config; // configuration information
-
- private bool m_eventSourceDisposed; // has Dispose been called.
-
- // Enabling bits
- private bool m_eventSourceEnabled; // am I enabled (any of my events are enabled for any dispatcher)
- internal EventLevel m_level; // highest level enabled by any output dispatcher
- internal EventKeywords m_matchAnyKeyword; // the logical OR of all levels enabled by any output dispatcher (zero is a special case) meaning 'all keywords'
-
- // Dispatching state
- internal volatile EventDispatcher? m_Dispatchers; // Linked list of code:EventDispatchers we write the data to (we also do ETW specially)
-#if FEATURE_MANAGED_ETW
- private volatile OverideEventProvider m_etwProvider = null!; // This hooks up ETW commands to our 'OnEventCommand' callback
-#endif
-#if FEATURE_PERFTRACING
- private volatile OverideEventProvider m_eventPipeProvider = null!;
-#endif
- private bool m_completelyInited; // The EventSource constructor has returned without exception.
- private Exception? m_constructionException; // If there was an exception construction, this is it
- private byte m_outOfBandMessageCount; // The number of out of band messages sent (we throttle them
- private EventCommandEventArgs? m_deferredCommands; // If we get commands before we are fully we store them here and run the when we are fully inited.
-
- private string[]? m_traits; // Used to implement GetTraits
-
- internal static uint s_currentPid; // current process id, used in synthesizing quasi-GUIDs
- [ThreadStatic]
- private static byte m_EventSourceExceptionRecurenceCount; // current recursion count inside ThrowEventSourceException
-
- [ThreadStatic]
- private static bool m_EventSourceInDecodeObject;
-
-#if FEATURE_MANAGED_ETW_CHANNELS
- internal volatile ulong[]? m_channelData;
-#endif
-
- // We use a single instance of ActivityTracker for all EventSources instances to allow correlation between multiple event providers.
- // We have m_activityTracker field simply because instance field is more efficient than static field fetch.
- private ActivityTracker m_activityTracker = null!;
- internal const string s_ActivityStartSuffix = "Start";
- internal const string s_ActivityStopSuffix = "Stop";
-
- // WARNING: Do not depend upon initialized statics during creation of EventSources, as it is possible for creation of an EventSource to trigger
- // creation of yet another EventSource. When this happens, these statics may not yet be initialized.
- // Rather than depending on initialized statics, use lazy initialization to ensure that the statics are initialized exactly when they are needed.
-
- // used for generating GUID from eventsource name
- private static byte[]? namespaceBytes;
-
-#endregion
- }
-
- /// <summary>
- /// Enables specifying event source configuration options to be used in the EventSource constructor.
- /// </summary>
- [Flags]
- public enum EventSourceSettings
- {
- /// <summary>
- /// This specifies none of the special configuration options should be enabled.
- /// </summary>
- Default = 0,
- /// <summary>
- /// Normally an EventSource NEVER throws; setting this option will tell it to throw when it encounters errors.
- /// </summary>
- ThrowOnEventWriteErrors = 1,
- /// <summary>
- /// Setting this option is a directive to the ETW listener should use manifest-based format when
- /// firing events. This is the default option when defining a type derived from EventSource
- /// (using the protected EventSource constructors).
- /// Only one of EtwManifestEventFormat or EtwSelfDescribingEventFormat should be specified
- /// </summary>
- EtwManifestEventFormat = 4,
- /// <summary>
- /// Setting this option is a directive to the ETW listener should use self-describing event format
- /// when firing events. This is the default option when creating a new instance of the EventSource
- /// type (using the public EventSource constructors).
- /// Only one of EtwManifestEventFormat or EtwSelfDescribingEventFormat should be specified
- /// </summary>
- EtwSelfDescribingEventFormat = 8,
- }
-
- /// <summary>
- /// An EventListener represents a target for the events generated by EventSources (that is subclasses
- /// of <see cref="EventSource"/>), in the current appdomain. When a new EventListener is created
- /// it is logically attached to all eventSources in that appdomain. When the EventListener is Disposed, then
- /// it is disconnected from the event eventSources. Note that there is a internal list of STRONG references
- /// to EventListeners, which means that relying on the lack of references to EventListeners to clean up
- /// EventListeners will NOT work. You must call EventListener.Dispose explicitly when a dispatcher is no
- /// longer needed.
- /// <para>
- /// Once created, EventListeners can enable or disable on a per-eventSource basis using verbosity levels
- /// (<see cref="EventLevel"/>) and bitfields (<see cref="EventKeywords"/>) to further restrict the set of
- /// events to be sent to the dispatcher. The dispatcher can also send arbitrary commands to a particular
- /// eventSource using the 'SendCommand' method. The meaning of the commands are eventSource specific.
- /// </para><para>
- /// The Null Guid (that is (new Guid()) has special meaning as a wildcard for 'all current eventSources in
- /// the appdomain'. Thus it is relatively easy to turn on all events in the appdomain if desired.
- /// </para><para>
- /// It is possible for there to be many EventListener's defined in a single appdomain. Each dispatcher is
- /// logically independent of the other listeners. Thus when one dispatcher enables or disables events, it
- /// affects only that dispatcher (other listeners get the events they asked for). It is possible that
- /// commands sent with 'SendCommand' would do a semantic operation that would affect the other listeners
- /// (like doing a GC, or flushing data ...), but this is the exception rather than the rule.
- /// </para><para>
- /// Thus the model is that each EventSource keeps a list of EventListeners that it is sending events
- /// to. Associated with each EventSource-dispatcher pair is a set of filtering criteria that determine for
- /// that eventSource what events that dispatcher will receive.
- /// </para><para>
- /// Listeners receive the events on their 'OnEventWritten' method. Thus subclasses of EventListener must
- /// override this method to do something useful with the data.
- /// </para><para>
- /// In addition, when new eventSources are created, the 'OnEventSourceCreate' method is called. The
- /// invariant associated with this callback is that every eventSource gets exactly one
- /// 'OnEventSourceCreate' call for ever eventSource that can potentially send it log messages. In
- /// particular when a EventListener is created, typically a series of OnEventSourceCreate' calls are
- /// made to notify the new dispatcher of all the eventSources that existed before the EventListener was
- /// created.
- /// </para>
- /// </summary>
- public class EventListener : IDisposable
- {
- private event EventHandler<EventSourceCreatedEventArgs>? _EventSourceCreated;
-
- /// <summary>
- /// This event is raised whenever a new eventSource is 'attached' to the dispatcher.
- /// This can happen for all existing EventSources when the EventListener is created
- /// as well as for any EventSources that come into existence after the EventListener
- /// has been created.
- ///
- /// These 'catch up' events are called during the construction of the EventListener.
- /// Subclasses need to be prepared for that.
- ///
- /// In a multi-threaded environment, it is possible that 'EventSourceEventWrittenCallback'
- /// events for a particular eventSource to occur BEFORE the EventSourceCreatedCallback is issued.
- /// </summary>
- public event EventHandler<EventSourceCreatedEventArgs>? EventSourceCreated
- {
- add
- {
- CallBackForExistingEventSources(false, value);
-
- this._EventSourceCreated = (EventHandler<EventSourceCreatedEventArgs>?)Delegate.Combine(_EventSourceCreated, value);
- }
- remove
- {
- this._EventSourceCreated = (EventHandler<EventSourceCreatedEventArgs>?)Delegate.Remove(_EventSourceCreated, value);
- }
- }
-
- /// <summary>
- /// This event is raised whenever an event has been written by a EventSource for which
- /// the EventListener has enabled events.
- /// </summary>
- public event EventHandler<EventWrittenEventArgs>? EventWritten;
-
- static EventListener()
- {
-#if FEATURE_PERFTRACING
- // Ensure that NativeRuntimeEventSource is initialized so that EventListeners get an opportunity to subscribe to its events.
- // This is required because NativeRuntimeEventSource never emit events on its own, and thus will never be initialized
- // in the normal way that EventSources are initialized.
- GC.KeepAlive(NativeRuntimeEventSource.Log);
-#endif // FEATURE_PERFTRACING
- }
-
- /// <summary>
- /// Create a new EventListener in which all events start off turned off (use EnableEvents to turn
- /// them on).
- /// </summary>
- public EventListener()
- {
- // This will cause the OnEventSourceCreated callback to fire.
- CallBackForExistingEventSources(true, (obj, args) =>
- args.EventSource!.AddListener((EventListener)obj!));
- }
-
- /// <summary>
- /// Dispose should be called when the EventListener no longer desires 'OnEvent*' callbacks. Because
- /// there is an internal list of strong references to all EventListeners, calling 'Dispose' directly
- /// is the only way to actually make the listen die. Thus it is important that users of EventListener
- /// call Dispose when they are done with their logging.
- /// </summary>
-#if ES_BUILD_STANDALONE
-#endif
- public virtual void Dispose()
- {
- lock (EventListenersLock)
- {
- if (s_Listeners != null)
- {
- if (this == s_Listeners)
- {
- EventListener cur = s_Listeners;
- s_Listeners = this.m_Next;
- RemoveReferencesToListenerInEventSources(cur);
- }
- else
- {
- // Find 'this' from the s_Listeners linked list.
- EventListener prev = s_Listeners;
- while (true)
- {
- EventListener? cur = prev.m_Next;
- if (cur == null)
- break;
- if (cur == this)
- {
- // Found our Listener, remove references to it in the eventSources
- prev.m_Next = cur.m_Next; // Remove entry.
- RemoveReferencesToListenerInEventSources(cur);
- break;
- }
- prev = cur;
- }
- }
- }
- Validate();
- }
- }
- // We don't expose a Dispose(bool), because the contract is that you don't have any non-syncronous
- // 'cleanup' associated with this object
-
- /// <summary>
- /// Enable all events from the eventSource identified by 'eventSource' to the current
- /// dispatcher that have a verbosity level of 'level' or lower.
- ///
- /// This call can have the effect of REDUCING the number of events sent to the
- /// dispatcher if 'level' indicates a less verbose level than was previously enabled.
- ///
- /// This call never has an effect on other EventListeners.
- ///
- /// </summary>
- public void EnableEvents(EventSource eventSource, EventLevel level)
- {
- EnableEvents(eventSource, level, EventKeywords.None);
- }
- /// <summary>
- /// Enable all events from the eventSource identified by 'eventSource' to the current
- /// dispatcher that have a verbosity level of 'level' or lower and have a event keyword
- /// matching any of the bits in 'matchAnyKeyword'.
- ///
- /// This call can have the effect of REDUCING the number of events sent to the
- /// dispatcher if 'level' indicates a less verbose level than was previously enabled or
- /// if 'matchAnyKeyword' has fewer keywords set than where previously set.
- ///
- /// This call never has an effect on other EventListeners.
- /// </summary>
- public void EnableEvents(EventSource eventSource, EventLevel level, EventKeywords matchAnyKeyword)
- {
- EnableEvents(eventSource, level, matchAnyKeyword, null);
- }
- /// <summary>
- /// Enable all events from the eventSource identified by 'eventSource' to the current
- /// dispatcher that have a verbosity level of 'level' or lower and have a event keyword
- /// matching any of the bits in 'matchAnyKeyword' as well as any (eventSource specific)
- /// effect passing additional 'key-value' arguments 'arguments' might have.
- ///
- /// This call can have the effect of REDUCING the number of events sent to the
- /// dispatcher if 'level' indicates a less verbose level than was previously enabled or
- /// if 'matchAnyKeyword' has fewer keywords set than where previously set.
- ///
- /// This call never has an effect on other EventListeners.
- /// </summary>
- public void EnableEvents(EventSource eventSource, EventLevel level, EventKeywords matchAnyKeyword, IDictionary<string, string?>? arguments)
- {
- if (eventSource == null)
- {
- throw new ArgumentNullException(nameof(eventSource));
- }
-
- eventSource.SendCommand(this, EventProviderType.None, 0, 0, EventCommand.Update, true, level, matchAnyKeyword, arguments);
-
-#if FEATURE_PERFTRACING
- if (eventSource.GetType() == typeof(NativeRuntimeEventSource))
- {
- EventPipeEventDispatcher.Instance.SendCommand(this, EventCommand.Update, true, level, matchAnyKeyword);
- }
-#endif // FEATURE_PERFTRACING
- }
- /// <summary>
- /// Disables all events coming from eventSource identified by 'eventSource'.
- ///
- /// This call never has an effect on other EventListeners.
- /// </summary>
- public void DisableEvents(EventSource eventSource)
- {
- if (eventSource == null)
- {
- throw new ArgumentNullException(nameof(eventSource));
- }
-
- eventSource.SendCommand(this, EventProviderType.None, 0, 0, EventCommand.Update, false, EventLevel.LogAlways, EventKeywords.None, null);
-
-#if FEATURE_PERFTRACING
- if (eventSource.GetType() == typeof(NativeRuntimeEventSource))
- {
- EventPipeEventDispatcher.Instance.SendCommand(this, EventCommand.Update, false, EventLevel.LogAlways, EventKeywords.None);
- }
-#endif // FEATURE_PERFTRACING
- }
-
- /// <summary>
- /// EventSourceIndex is small non-negative integer (suitable for indexing in an array)
- /// identifying EventSource. It is unique per-appdomain. Some EventListeners might find
- /// it useful to store additional information about each eventSource connected to it,
- /// and EventSourceIndex allows this extra information to be efficiently stored in a
- /// (growable) array (eg List(T)).
- /// </summary>
- public static int EventSourceIndex(EventSource eventSource) { return eventSource.m_id; }
-
- /// <summary>
- /// This method is called whenever a new eventSource is 'attached' to the dispatcher.
- /// This can happen for all existing EventSources when the EventListener is created
- /// as well as for any EventSources that come into existence after the EventListener
- /// has been created.
- ///
- /// These 'catch up' events are called during the construction of the EventListener.
- /// Subclasses need to be prepared for that.
- ///
- /// In a multi-threaded environment, it is possible that 'OnEventWritten' callbacks
- /// for a particular eventSource to occur BEFORE the OnEventSourceCreated is issued.
- /// </summary>
- /// <param name="eventSource"></param>
- protected internal virtual void OnEventSourceCreated(EventSource eventSource)
- {
- EventHandler<EventSourceCreatedEventArgs>? callBack = this._EventSourceCreated;
- if (callBack != null)
- {
- EventSourceCreatedEventArgs args = new EventSourceCreatedEventArgs();
- args.EventSource = eventSource;
- callBack(this, args);
- }
- }
-
- /// <summary>
- /// This method is called whenever an event has been written by a EventSource for which
- /// the EventListener has enabled events.
- /// </summary>
- /// <param name="eventData"></param>
- protected internal virtual void OnEventWritten(EventWrittenEventArgs eventData)
- {
- this.EventWritten?.Invoke(this, eventData);
- }
-
-#region private
- /// <summary>
- /// This routine adds newEventSource to the global list of eventSources, it also assigns the
- /// ID to the eventSource (which is simply the ordinal in the global list).
- ///
- /// EventSources currently do not pro-actively remove themselves from this list. Instead
- /// when eventSources's are GCed, the weak handle in this list naturally gets nulled, and
- /// we will reuse the slot. Today this list never shrinks (but we do reuse entries
- /// that are in the list). This seems OK since the expectation is that EventSources
- /// tend to live for the lifetime of the appdomain anyway (they tend to be used in
- /// global variables).
- /// </summary>
- /// <param name="newEventSource"></param>
- internal static void AddEventSource(EventSource newEventSource)
- {
- lock (EventListenersLock)
- {
- s_EventSources ??= new List<WeakReference<EventSource>>(2);
-
- if (!s_EventSourceShutdownRegistered)
- {
- s_EventSourceShutdownRegistered = true;
-#if ES_BUILD_STANDALONE
- AppDomain.CurrentDomain.ProcessExit += DisposeOnShutdown;
- AppDomain.CurrentDomain.DomainUnload += DisposeOnShutdown;
-#else
- AppContext.ProcessExit += DisposeOnShutdown;
-#endif
- }
-
- // Periodically search the list for existing entries to reuse, this avoids
- // unbounded memory use if we keep recycling eventSources (an unlikely thing).
- int newIndex = -1;
- if (s_EventSources.Count % 64 == 63) // on every block of 64, fill up the block before continuing
- {
- int i = s_EventSources.Count; // Work from the top down.
- while (0 < i)
- {
- --i;
- WeakReference<EventSource> weakRef = s_EventSources[i];
- if (!weakRef.TryGetTarget(out _))
- {
- newIndex = i;
- weakRef.SetTarget(newEventSource);
- break;
- }
- }
- }
- if (newIndex < 0)
- {
- newIndex = s_EventSources.Count;
- s_EventSources.Add(new WeakReference<EventSource>(newEventSource));
- }
- newEventSource.m_id = newIndex;
-
-#if DEBUG
- // Disable validation of EventSource/EventListener connections in case a call to EventSource.AddListener
- // causes a recursive call into this method.
- bool previousValue = s_ConnectingEventSourcesAndListener;
- s_ConnectingEventSourcesAndListener = true;
- try
- {
-#endif
- // Add every existing dispatcher to the new EventSource
- for (EventListener? listener = s_Listeners; listener != null; listener = listener.m_Next)
- newEventSource.AddListener(listener);
-#if DEBUG
- }
- finally
- {
- s_ConnectingEventSourcesAndListener = previousValue;
- }
-#endif
-
- Validate();
- }
- }
-
- // Whenver we have async callbacks from native code, there is an ugly issue where
- // during .NET shutdown native code could be calling the callback, but the CLR
- // has already prohibited callbacks to managed code in the appdomain, causing the CLR
- // to throw a COMPLUS_BOOT_EXCEPTION. The guideline we give is that you must unregister
- // such callbacks on process shutdown or appdomain so that unmanaged code will never
- // do this. This is what this callback is for.
- // See bug 724140 for more
- private static void DisposeOnShutdown(object? sender, EventArgs e)
- {
- lock (EventListenersLock)
- {
- Debug.Assert(s_EventSources != null);
- foreach (WeakReference<EventSource> esRef in s_EventSources)
- {
- if (esRef.TryGetTarget(out EventSource? es))
- es.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Helper used in code:Dispose that removes any references to 'listenerToRemove' in any of the
- /// eventSources in the appdomain.
- ///
- /// The EventListenersLock must be held before calling this routine.
- /// </summary>
- private static void RemoveReferencesToListenerInEventSources(EventListener listenerToRemove)
- {
-#if !ES_BUILD_STANDALONE
- Debug.Assert(Monitor.IsEntered(EventListener.EventListenersLock));
-#endif
- // Foreach existing EventSource in the appdomain
- Debug.Assert(s_EventSources != null);
- foreach (WeakReference<EventSource> eventSourceRef in s_EventSources)
- {
- if (eventSourceRef.TryGetTarget(out EventSource? eventSource))
- {
- Debug.Assert(eventSource.m_Dispatchers != null);
- // Is the first output dispatcher the dispatcher we are removing?
- if (eventSource.m_Dispatchers.m_Listener == listenerToRemove)
- eventSource.m_Dispatchers = eventSource.m_Dispatchers.m_Next;
- else
- {
- // Remove 'listenerToRemove' from the eventSource.m_Dispatchers linked list.
- EventDispatcher? prev = eventSource.m_Dispatchers;
- while (true)
- {
- EventDispatcher? cur = prev.m_Next;
- if (cur == null)
- {
- Debug.Fail("EventSource did not have a registered EventListener!");
- break;
- }
- if (cur.m_Listener == listenerToRemove)
- {
- prev.m_Next = cur.m_Next; // Remove entry.
- break;
- }
- prev = cur;
- }
- }
- }
- }
-
-#if FEATURE_PERFTRACING
- // Remove the listener from the EventPipe dispatcher.
- EventPipeEventDispatcher.Instance.RemoveEventListener(listenerToRemove);
-#endif // FEATURE_PERFTRACING
- }
-
- /// <summary>
- /// Checks internal consistency of EventSources/Listeners.
- /// </summary>
- [Conditional("DEBUG")]
- internal static void Validate()
- {
-#if DEBUG
- // Don't run validation code if we're in the middle of modifying the connections between EventSources and EventListeners.
- if (s_ConnectingEventSourcesAndListener)
- {
- return;
- }
-#endif
-
- lock (EventListenersLock)
- {
- Debug.Assert(s_EventSources != null);
- // Get all listeners
- Dictionary<EventListener, bool> allListeners = new Dictionary<EventListener, bool>();
- EventListener? cur = s_Listeners;
- while (cur != null)
- {
- allListeners.Add(cur, true);
- cur = cur.m_Next;
- }
-
- // For all eventSources
- int id = -1;
- foreach (WeakReference<EventSource> eventSourceRef in s_EventSources)
- {
- id++;
- if (!eventSourceRef.TryGetTarget(out EventSource? eventSource))
- continue;
- Debug.Assert(eventSource.m_id == id, "Unexpected event source ID.");
-
- // None listeners on eventSources exist in the dispatcher list.
- EventDispatcher? dispatcher = eventSource.m_Dispatchers;
- while (dispatcher != null)
- {
- Debug.Assert(allListeners.ContainsKey(dispatcher.m_Listener), "EventSource has a listener not on the global list.");
- dispatcher = dispatcher.m_Next;
- }
-
- // Every dispatcher is on Dispatcher List of every eventSource.
- foreach (EventListener listener in allListeners.Keys)
- {
- dispatcher = eventSource.m_Dispatchers;
- while (true)
- {
- Debug.Assert(dispatcher != null, "Listener is not on all eventSources.");
- if (dispatcher.m_Listener == listener)
- break;
- dispatcher = dispatcher.m_Next;
- }
- }
- }
- }
- }
-
- /// <summary>
- /// Gets a global lock that is intended to protect the code:s_Listeners linked list and the
- /// code:s_EventSources list. (We happen to use the s_EventSources list as the lock object)
- /// </summary>
- internal static object EventListenersLock
- {
- get
- {
- if (s_EventSources == null)
- Interlocked.CompareExchange(ref s_EventSources, new List<WeakReference<EventSource>>(2), null);
- return s_EventSources;
- }
- }
-
- private void CallBackForExistingEventSources(bool addToListenersList, EventHandler<EventSourceCreatedEventArgs>? callback)
- {
- lock (EventListenersLock)
- {
- Debug.Assert(s_EventSources != null);
-
- // Disallow creating EventListener reentrancy.
- if (s_CreatingListener)
- {
- throw new InvalidOperationException(SR.EventSource_ListenerCreatedInsideCallback);
- }
-
- try
- {
- s_CreatingListener = true;
-
- if (addToListenersList)
- {
- // Add to list of listeners in the system, do this BEFORE firing the 'OnEventSourceCreated' so that
- // Those added sources see this listener.
- this.m_Next = s_Listeners;
- s_Listeners = this;
- }
-
- if (callback != null)
- {
- // Find all existing eventSources call OnEventSourceCreated to 'catchup'
- // Note that we DO have reentrancy here because 'AddListener' calls out to user code (via OnEventSourceCreated callback)
- // We tolerate this by iterating over a copy of the list here. New event sources will take care of adding listeners themselves
- // EventSources are not guaranteed to be added at the end of the s_EventSource list -- We re-use slots when a new source
- // is created.
- WeakReference<EventSource>[] eventSourcesSnapshot = s_EventSources.ToArray();
-
-#if DEBUG
- bool previousValue = s_ConnectingEventSourcesAndListener;
- s_ConnectingEventSourcesAndListener = true;
- try
- {
-#endif
- for (int i = 0; i < eventSourcesSnapshot.Length; i++)
- {
- WeakReference<EventSource> eventSourceRef = eventSourcesSnapshot[i];
- if (eventSourceRef.TryGetTarget(out EventSource? eventSource))
- {
- EventSourceCreatedEventArgs args = new EventSourceCreatedEventArgs();
- args.EventSource = eventSource;
- callback(this, args);
- }
- }
-#if DEBUG
- }
- finally
- {
- s_ConnectingEventSourcesAndListener = previousValue;
- }
-#endif
- }
-
- Validate();
- }
- finally
- {
- s_CreatingListener = false;
- }
- }
- }
-
- // Instance fields
- internal volatile EventListener? m_Next; // These form a linked list in s_Listeners
-
- // static fields
-
- /// <summary>
- /// The list of all listeners in the appdomain. Listeners must be explicitly disposed to remove themselves
- /// from this list. Note that EventSources point to their listener but NOT the reverse.
- /// </summary>
- internal static EventListener? s_Listeners;
- /// <summary>
- /// The list of all active eventSources in the appdomain. Note that eventSources do NOT
- /// remove themselves from this list this is a weak list and the GC that removes them may
- /// not have happened yet. Thus it can contain event sources that are dead (thus you have
- /// to filter those out.
- /// </summary>
- internal static List<WeakReference<EventSource>>? s_EventSources;
-
- /// <summary>
- /// Used to disallow reentrancy.
- /// </summary>
- private static bool s_CreatingListener = false;
-
-#if DEBUG
- /// <summary>
- /// Used to disable validation of EventSource and EventListener connectivity.
- /// This is needed when an EventListener is in the middle of being published to all EventSources
- /// and another EventSource is created as part of the process.
- /// </summary>
- [ThreadStatic]
- private static bool s_ConnectingEventSourcesAndListener;
-#endif
-
- /// <summary>
- /// Used to register AD/Process shutdown callbacks.
- /// </summary>
- private static bool s_EventSourceShutdownRegistered = false;
-#endregion
- }
-
- /// <summary>
- /// Passed to the code:EventSource.OnEventCommand callback
- /// </summary>
- public class EventCommandEventArgs : EventArgs
- {
- /// <summary>
- /// Gets the command for the callback.
- /// </summary>
- public EventCommand Command { get; internal set; }
-
- /// <summary>
- /// Gets the arguments for the callback.
- /// </summary>
- public IDictionary<string, string?>? Arguments { get; internal set; }
-
- /// <summary>
- /// Enables the event that has the specified identifier.
- /// </summary>
- /// <param name="eventId">Event ID of event to be enabled</param>
- /// <returns>true if eventId is in range</returns>
- public bool EnableEvent(int eventId)
- {
- if (Command != EventCommand.Enable && Command != EventCommand.Disable)
- throw new InvalidOperationException();
- return eventSource.EnableEventForDispatcher(dispatcher, eventProviderType, eventId, true);
- }
-
- /// <summary>
- /// Disables the event that have the specified identifier.
- /// </summary>
- /// <param name="eventId">Event ID of event to be disabled</param>
- /// <returns>true if eventId is in range</returns>
- public bool DisableEvent(int eventId)
- {
- if (Command != EventCommand.Enable && Command != EventCommand.Disable)
- throw new InvalidOperationException();
- return eventSource.EnableEventForDispatcher(dispatcher, eventProviderType, eventId, false);
- }
-
-#region private
-
- internal EventCommandEventArgs(EventCommand command, IDictionary<string, string?>? arguments, EventSource eventSource,
- EventListener? listener, EventProviderType eventProviderType, int perEventSourceSessionId, int etwSessionId, bool enable, EventLevel level, EventKeywords matchAnyKeyword)
- {
- this.Command = command;
- this.Arguments = arguments;
- this.eventSource = eventSource;
- this.listener = listener;
- this.eventProviderType = eventProviderType;
- this.perEventSourceSessionId = perEventSourceSessionId;
- this.etwSessionId = etwSessionId;
- this.enable = enable;
- this.level = level;
- this.matchAnyKeyword = matchAnyKeyword;
- }
-
- internal EventSource eventSource;
- internal EventDispatcher? dispatcher;
- internal EventProviderType eventProviderType;
-
- // These are the arguments of sendCommand and are only used for deferring commands until after we are fully initialized.
- internal EventListener? listener;
- internal int perEventSourceSessionId;
- internal int etwSessionId;
- internal bool enable;
- internal EventLevel level;
- internal EventKeywords matchAnyKeyword;
- internal EventCommandEventArgs? nextCommand; // We form a linked list of these deferred commands.
-
-#endregion
- }
-
- /// <summary>
- /// EventSourceCreatedEventArgs is passed to <see cref="EventListener.EventSourceCreated"/>
- /// </summary>
- public class EventSourceCreatedEventArgs : EventArgs
- {
- /// <summary>
- /// The EventSource that is attaching to the listener.
- /// </summary>
- public EventSource? EventSource
- {
- get;
- internal set;
- }
- }
-
- /// <summary>
- /// EventWrittenEventArgs is passed to the user-provided override for
- /// <see cref="EventListener.OnEventWritten"/> when an event is fired.
- /// </summary>
- public class EventWrittenEventArgs : EventArgs
- {
- /// <summary>
- /// The name of the event.
- /// </summary>
- public string? EventName
- {
- get
- {
- if (m_eventName != null || EventId < 0) // TraceLogging convention EventID == -1
- {
- return m_eventName;
- }
- else
- {
- Debug.Assert(m_eventSource.m_eventData != null);
- return m_eventSource.m_eventData[EventId].Name;
- }
- }
- internal set => m_eventName = value;
- }
-
- /// <summary>
- /// Gets the event ID for the event that was written.
- /// </summary>
- public int EventId { get; internal set; }
-
- /// <summary>
- /// Gets the activity ID for the thread on which the event was written.
- /// </summary>
- public Guid ActivityId
- {
- get
- {
- Guid activityId = m_activityId;
- if (activityId == Guid.Empty)
- {
- activityId = EventSource.CurrentThreadActivityId;
- }
-
- return activityId;
- }
- internal set => m_activityId = value;
- }
-
- /// <summary>
- /// Gets the related activity ID if one was specified when the event was written.
- /// </summary>
- public Guid RelatedActivityId
- {
- get;
- internal set;
- }
-
- /// <summary>
- /// Gets the payload for the event.
- /// </summary>
- public ReadOnlyCollection<object?>? Payload { get; internal set; }
-
- /// <summary>
- /// Gets the payload argument names.
- /// </summary>
- public ReadOnlyCollection<string>? PayloadNames
- {
- get
- {
- // For contract based events we create the list lazily.
- // You can have m_payloadNames be null in the TraceLogging case (EventID < 0) so only
- // do the lazy init if you know it is contract based (EventID >= 0)
- if (EventId >= 0 && m_payloadNames == null)
- {
- var names = new List<string>();
- Debug.Assert(m_eventSource.m_eventData != null);
- foreach (ParameterInfo parameter in m_eventSource.m_eventData[EventId].Parameters)
- {
- names.Add(parameter.Name!);
- }
-
- m_payloadNames = new ReadOnlyCollection<string>(names);
- }
-
- return m_payloadNames;
- }
-
- internal set => m_payloadNames = value;
- }
-
- /// <summary>
- /// Gets the event source object.
- /// </summary>
- public EventSource EventSource => m_eventSource;
-
- /// <summary>
- /// Gets the keywords for the event.
- /// </summary>
- public EventKeywords Keywords
- {
- get
- {
- if (EventId < 0) // TraceLogging convention EventID == -1
- return m_keywords;
-
- Debug.Assert(m_eventSource.m_eventData != null);
- return (EventKeywords)m_eventSource.m_eventData[EventId].Descriptor.Keywords;
- }
- }
-
- /// <summary>
- /// Gets the operation code for the event.
- /// </summary>
- public EventOpcode Opcode
- {
- get
- {
- if (EventId <= 0) // TraceLogging convention EventID == -1
- return m_opcode;
-
- Debug.Assert(m_eventSource.m_eventData != null);
- return (EventOpcode)m_eventSource.m_eventData[EventId].Descriptor.Opcode;
- }
- }
-
- /// <summary>
- /// Gets the task for the event.
- /// </summary>
- public EventTask Task
- {
- get
- {
- if (EventId <= 0) // TraceLogging convention EventID == -1
- return EventTask.None;
-
- Debug.Assert(m_eventSource.m_eventData != null);
- return (EventTask)m_eventSource.m_eventData[EventId].Descriptor.Task;
- }
- }
-
- /// <summary>
- /// Any provider/user defined options associated with the event.
- /// </summary>
- public EventTags Tags
- {
- get
- {
- if (EventId <= 0) // TraceLogging convention EventID == -1
- return m_tags;
-
- Debug.Assert(m_eventSource.m_eventData != null);
- return m_eventSource.m_eventData[EventId].Tags;
- }
- }
-
- /// <summary>
- /// Gets the message for the event. If the message has {N} parameters they are NOT substituted.
- /// </summary>
- public string? Message
- {
- get
- {
- if (EventId <= 0) // TraceLogging convention EventID == -1
- {
- return m_message;
- }
- else
- {
- Debug.Assert(m_eventSource.m_eventData != null);
- return m_eventSource.m_eventData[EventId].Message;
- }
- }
- internal set => m_message = value;
- }
-
-#if FEATURE_MANAGED_ETW_CHANNELS
- /// <summary>
- /// Gets the channel for the event.
- /// </summary>
- public EventChannel Channel
- {
- get
- {
- if (EventId <= 0) // TraceLogging convention EventID == -1
- return EventChannel.None;
-
- Debug.Assert(m_eventSource.m_eventData != null);
- return (EventChannel)m_eventSource.m_eventData[EventId].Descriptor.Channel;
- }
- }
-#endif
-
- /// <summary>
- /// Gets the version of the event.
- /// </summary>
- public byte Version
- {
- get
- {
- if (EventId <= 0) // TraceLogging convention EventID == -1
- return 0;
-
- Debug.Assert(m_eventSource.m_eventData != null);
- return m_eventSource.m_eventData[EventId].Descriptor.Version;
- }
- }
-
- /// <summary>
- /// Gets the level for the event.
- /// </summary>
- public EventLevel Level
- {
- get
- {
- if (EventId <= 0) // TraceLogging convention EventID == -1
- return m_level;
-
- Debug.Assert(m_eventSource.m_eventData != null);
- return (EventLevel)m_eventSource.m_eventData[EventId].Descriptor.Level;
- }
- }
-
- /// <summary>
- /// Gets the identifier for the OS thread that wrote the event.
- /// </summary>
- public long OSThreadId
- {
- get
- {
- if (!m_osThreadId.HasValue)
- {
-#if ES_BUILD_STANDALONE
- m_osThreadId = (long)Interop.Kernel32.GetCurrentThreadId();
-#else
- m_osThreadId = (long)Thread.CurrentOSThreadId;
-#endif
- }
-
- return m_osThreadId.Value;
- }
- internal set => m_osThreadId = value;
- }
-
- /// <summary>
- /// Gets a UTC DateTime that specifies when the event was written.
- /// </summary>
- public DateTime TimeStamp
- {
- get;
- internal set;
- }
-
-#region private
- internal EventWrittenEventArgs(EventSource eventSource)
- {
- m_eventSource = eventSource;
- TimeStamp = DateTime.UtcNow;
- }
- private string? m_message;
- private string? m_eventName;
- private readonly EventSource m_eventSource;
- private ReadOnlyCollection<string>? m_payloadNames;
- private Guid m_activityId;
- private long? m_osThreadId;
- internal EventTags m_tags;
- internal EventOpcode m_opcode;
- internal EventLevel m_level;
- internal EventKeywords m_keywords;
-#endregion
- }
-
- /// <summary>
- /// Allows customizing defaults and specifying localization support for the event source class to which it is applied.
- /// </summary>
- [AttributeUsage(AttributeTargets.Class)]
- public sealed class EventSourceAttribute : Attribute
- {
- /// <summary>
- /// Overrides the ETW name of the event source (which defaults to the class name)
- /// </summary>
- public string? Name { get; set; }
-
- /// <summary>
- /// Overrides the default (calculated) Guid of an EventSource type. Explicitly defining a GUID is discouraged,
- /// except when upgrading existing ETW providers to using event sources.
- /// </summary>
- public string? Guid { get; set; }
-
- /// <summary>
- /// <para>
- /// EventSources support localization of events. The names used for events, opcodes, tasks, keywords and maps
- /// can be localized to several languages if desired. This works by creating a ResX style string table
- /// (by simply adding a 'Resource File' to your project). This resource file is given a name e.g.
- /// 'DefaultNameSpace.ResourceFileName' which can be passed to the ResourceManager constructor to read the
- /// resources. This name is the value of the LocalizationResources property.
- /// </para><para>
- /// If LocalizationResources property is non-null, then EventSource will look up the localized strings for events by
- /// using the following resource naming scheme
- /// </para>
- /// <para>* event_EVENTNAME</para>
- /// <para>* task_TASKNAME</para>
- /// <para>* keyword_KEYWORDNAME</para>
- /// <para>* map_MAPNAME</para>
- /// <para>
- /// where the capitalized name is the name of the event, task, keyword, or map value that should be localized.
- /// Note that the localized string for an event corresponds to the Message string, and can have {0} values
- /// which represent the payload values.
- /// </para>
- /// </summary>
- public string? LocalizationResources { get; set; }
- }
-
- /// <summary>
- /// Any instance methods in a class that subclasses <see cref="EventSource"/> and that return void are
- /// assumed by default to be methods that generate an ETW event. Enough information can be deduced from the
- /// name of the method and its signature to generate basic schema information for the event. The
- /// <see cref="EventAttribute"/> class allows you to specify additional event schema information for an event if
- /// desired.
- /// </summary>
- [AttributeUsage(AttributeTargets.Method)]
- public sealed class EventAttribute : Attribute
- {
- /// <summary>Construct an EventAttribute with specified eventId</summary>
- /// <param name="eventId">ID of the ETW event (an integer between 1 and 65535)</param>
- public EventAttribute(int eventId) { this.EventId = eventId; Level = EventLevel.Informational; this.m_opcodeSet = false; }
- /// <summary>Event's ID</summary>
- public int EventId { get; private set; }
- /// <summary>Event's severity level: indicates the severity or verbosity of the event</summary>
- public EventLevel Level { get; set; }
- /// <summary>Event's keywords: allows classification of events by "categories"</summary>
- public EventKeywords Keywords { get; set; }
- /// <summary>Event's operation code: allows defining operations, generally used with Tasks</summary>
- public EventOpcode Opcode
- {
- get => m_opcode;
- set
- {
- this.m_opcode = value;
- this.m_opcodeSet = true;
- }
- }
-
- internal bool IsOpcodeSet => m_opcodeSet;
-
- /// <summary>Event's task: allows logical grouping of events</summary>
- public EventTask Task { get; set; }
-#if FEATURE_MANAGED_ETW_CHANNELS
- /// <summary>Event's channel: defines an event log as an additional destination for the event</summary>
- public EventChannel Channel { get; set; }
-#endif
- /// <summary>Event's version</summary>
- public byte Version { get; set; }
-
- /// <summary>
- /// This can be specified to enable formatting and localization of the event's payload. You can
- /// use standard .NET substitution operators (eg {1}) in the string and they will be replaced
- /// with the 'ToString()' of the corresponding part of the event payload.
- /// </summary>
- public string? Message { get; set; }
-
- /// <summary>
- /// User defined options associated with the event. These do not have meaning to the EventSource but
- /// are passed through to listeners which given them semantics.
- /// </summary>
- public EventTags Tags { get; set; }
-
- /// <summary>
- /// Allows fine control over the Activity IDs generated by start and stop events
- /// </summary>
- public EventActivityOptions ActivityOptions { get; set; }
-
-#region private
- private EventOpcode m_opcode;
- private bool m_opcodeSet;
-#endregion
- }
-
- /// <summary>
- /// By default all instance methods in a class that subclasses code:EventSource that and return
- /// void are assumed to be methods that generate an event. This default can be overridden by specifying
- /// the code:NonEventAttribute
- /// </summary>
- [AttributeUsage(AttributeTargets.Method)]
- public sealed class NonEventAttribute : Attribute
- {
- /// <summary>
- /// Constructs a default NonEventAttribute
- /// </summary>
- public NonEventAttribute() { }
- }
-
- // FUTURE we may want to expose this at some point once we have a partner that can help us validate the design.
-#if FEATURE_MANAGED_ETW_CHANNELS
- /// <summary>
- /// EventChannelAttribute allows customizing channels supported by an EventSource. This attribute must be
- /// applied to an member of type EventChannel defined in a Channels class nested in the EventSource class:
- /// <code>
- /// public static class Channels
- /// {
- /// [Channel(Enabled = true, EventChannelType = EventChannelType.Admin)]
- /// public const EventChannel Admin = (EventChannel)16;
- ///
- /// [Channel(Enabled = false, EventChannelType = EventChannelType.Operational)]
- /// public const EventChannel Operational = (EventChannel)17;
- /// }
- /// </code>
- /// </summary>
- [AttributeUsage(AttributeTargets.Field)]
-#if FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
- public
-#else
- internal
-#endif
- class EventChannelAttribute : Attribute
- {
- /// <summary>
- /// Specified whether the channel is enabled by default
- /// </summary>
- public bool Enabled { get; set; }
-
- /// <summary>
- /// Legal values are in EventChannelType
- /// </summary>
- public EventChannelType EventChannelType { get; set; }
-
-#if FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
- /// <summary>
- /// Specifies the isolation for the channel
- /// </summary>
- public EventChannelIsolation Isolation { get; set; }
-
- /// <summary>
- /// Specifies an SDDL access descriptor that controls access to the log file that backs the channel.
- /// See MSDN (https://docs.microsoft.com/en-us/windows/desktop/WES/eventmanifestschema-channeltype-complextype) for details.
- /// </summary>
- public string? Access { get; set; }
-
- /// <summary>
- /// Allows importing channels defined in external manifests
- /// </summary>
- public string? ImportChannel { get; set; }
-#endif
-
- // TODO: there is a convention that the name is the Provider/Type Should we provide an override?
- // public string Name { get; set; }
- }
-
- /// <summary>
- /// Allowed channel types
- /// </summary>
-#if FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
- public
-#else
- internal
-#endif
- enum EventChannelType
- {
- /// <summary>The admin channel</summary>
- Admin = 1,
- /// <summary>The operational channel</summary>
- Operational,
- /// <summary>The Analytic channel</summary>
- Analytic,
- /// <summary>The debug channel</summary>
- Debug,
- }
-
-#if FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
- /// <summary>
- /// Allowed isolation levels. See MSDN (https://docs.microsoft.com/en-us/windows/desktop/WES/eventmanifestschema-channeltype-complextype)
- /// for the default permissions associated with each level. EventChannelIsolation and Access allows control over the
- /// access permissions for the channel and backing file.
- /// </summary>
- public
- enum EventChannelIsolation
- {
- /// <summary>
- /// This is the default isolation level. All channels that specify Application isolation use the same ETW session
- /// </summary>
- Application = 1,
- /// <summary>
- /// All channels that specify System isolation use the same ETW session
- /// </summary>
- System,
- /// <summary>
- /// Use sparingly! When specifying Custom isolation, a separate ETW session is created for the channel.
- /// Using Custom isolation lets you control the access permissions for the channel and backing file.
- /// Because there are only 64 ETW sessions available, you should limit your use of Custom isolation.
- /// </summary>
- Custom,
- }
-#endif
-#endif
-
- /// <summary>
- /// Describes the pre-defined command (EventCommandEventArgs.Command property) that is passed to the OnEventCommand callback.
- /// </summary>
- public enum EventCommand
- {
- /// <summary>
- /// Update EventSource state
- /// </summary>
- Update = 0,
- /// <summary>
- /// Request EventSource to generate and send its manifest
- /// </summary>
- SendManifest = -1,
- /// <summary>
- /// Enable event
- /// </summary>
- Enable = -2,
- /// <summary>
- /// Disable event
- /// </summary>
- Disable = -3
- }
-
-#region private classes
-
- // holds a bitfield representing a session mask
- /// <summary>
- /// A SessionMask represents a set of (at most MAX) sessions as a bit mask. The perEventSourceSessionId
- /// is the index in the SessionMask of the bit that will be set. These can translate to
- /// EventSource's reserved keywords bits using the provided ToEventKeywords() and
- /// FromEventKeywords() methods.
- /// </summary>
- internal struct SessionMask
- {
- public SessionMask(SessionMask m)
- { m_mask = m.m_mask; }
-
- public SessionMask(uint mask = 0)
- { m_mask = mask & MASK; }
-
- public bool IsEqualOrSupersetOf(SessionMask m)
- {
- return (this.m_mask | m.m_mask) == this.m_mask;
- }
-
- public static SessionMask All => new SessionMask(MASK);
-
- public static SessionMask FromId(int perEventSourceSessionId)
- {
- Debug.Assert(perEventSourceSessionId < MAX);
- return new SessionMask((uint)1 << perEventSourceSessionId);
- }
-
- public ulong ToEventKeywords()
- {
- return (ulong)m_mask << SHIFT_SESSION_TO_KEYWORD;
- }
-
- public static SessionMask FromEventKeywords(ulong m)
- {
- return new SessionMask((uint)(m >> SHIFT_SESSION_TO_KEYWORD));
- }
-
- public bool this[int perEventSourceSessionId]
- {
- get
- {
- Debug.Assert(perEventSourceSessionId < MAX);
- return (m_mask & (1 << perEventSourceSessionId)) != 0;
- }
- set
- {
- Debug.Assert(perEventSourceSessionId < MAX);
- if (value) m_mask |= ((uint)1 << perEventSourceSessionId);
- else m_mask &= ~((uint)1 << perEventSourceSessionId);
- }
- }
-
- public static SessionMask operator |(SessionMask m1, SessionMask m2) =>
- new SessionMask(m1.m_mask | m2.m_mask);
-
- public static SessionMask operator &(SessionMask m1, SessionMask m2) =>
- new SessionMask(m1.m_mask & m2.m_mask);
-
- public static SessionMask operator ^(SessionMask m1, SessionMask m2) =>
- new SessionMask(m1.m_mask ^ m2.m_mask);
-
- public static SessionMask operator ~(SessionMask m) =>
- new SessionMask(MASK & ~(m.m_mask));
-
- public static explicit operator ulong(SessionMask m) => m.m_mask;
-
- public static explicit operator uint(SessionMask m) => m.m_mask;
-
- private uint m_mask;
-
- internal const int SHIFT_SESSION_TO_KEYWORD = 44; // bits 44-47 inclusive are reserved
- internal const uint MASK = 0x0fU; // the mask of 4 reserved bits
- internal const uint MAX = 4; // maximum number of simultaneous ETW sessions supported
- }
-
- /// <summary>
- /// code:EventDispatchers are a simple 'helper' structure that holds the filtering state
- /// (m_EventEnabled) for a particular EventSource X EventListener tuple
- ///
- /// Thus a single EventListener may have many EventDispatchers (one for every EventSource
- /// that EventListener has activate) and a Single EventSource may also have many
- /// event Dispatchers (one for every EventListener that has activated it).
- ///
- /// Logically a particular EventDispatcher belongs to exactly one EventSource and exactly
- /// one EventListener (although EventDispatcher does not 'remember' the EventSource it is
- /// associated with.
- /// </summary>
- internal class EventDispatcher
- {
- internal EventDispatcher(EventDispatcher? next, bool[]? eventEnabled, EventListener listener)
- {
- m_Next = next;
- m_EventEnabled = eventEnabled;
- m_Listener = listener;
- }
-
- // Instance fields
- internal readonly EventListener m_Listener; // The dispatcher this entry is for
- internal bool[]? m_EventEnabled; // For every event in a the eventSource, is it enabled?
-
- // Only guaranteed to exist after a InsureInit()
- internal EventDispatcher? m_Next; // These form a linked list in code:EventSource.m_Dispatchers
- // Of all listeners for that eventSource.
- }
-
- /// <summary>
- /// Flags that can be used with EventSource.GenerateManifest to control how the ETW manifest for the EventSource is
- /// generated.
- /// </summary>
- [Flags]
- public enum EventManifestOptions
- {
- /// <summary>
- /// Only the resources associated with current UI culture are included in the manifest
- /// </summary>
- None = 0x0,
- /// <summary>
- /// Throw exceptions for any inconsistency encountered
- /// </summary>
- Strict = 0x1,
- /// <summary>
- /// Generate a "resources" node under "localization" for every satellite assembly provided
- /// </summary>
- AllCultures = 0x2,
- /// <summary>
- /// Generate the manifest only if the event source needs to be registered on the machine,
- /// otherwise return null (but still perform validation if Strict is specified)
- /// </summary>
- OnlyIfNeededForRegistration = 0x4,
- /// <summary>
- /// When generating the manifest do *not* enforce the rule that the current EventSource class
- /// must be the base class for the user-defined type passed in. This allows validation of .net
- /// event sources using the new validation code
- /// </summary>
- AllowEventSourceOverride = 0x8,
- }
-
- /// <summary>
- /// ManifestBuilder is designed to isolate the details of the message of the event from the
- /// rest of EventSource. This one happens to create XML.
- /// </summary>
- internal class ManifestBuilder
- {
- /// <summary>
- /// Build a manifest for 'providerName' with the given GUID, which will be packaged into 'dllName'.
- /// 'resources, is a resource manager. If specified all messages are localized using that manager.
- /// </summary>
- public ManifestBuilder(string providerName, Guid providerGuid, string? dllName, ResourceManager? resources,
- EventManifestOptions flags)
- {
-#if FEATURE_MANAGED_ETW_CHANNELS
- this.providerName = providerName;
-#endif
- this.flags = flags;
-
- this.resources = resources;
- sb = new StringBuilder();
- events = new StringBuilder();
- templates = new StringBuilder();
- opcodeTab = new Dictionary<int, string>();
- stringTab = new Dictionary<string, string>();
- errors = new List<string>();
- perEventByteArrayArgIndices = new Dictionary<string, List<int>>();
-
- sb.AppendLine("<instrumentationManifest xmlns=\"http://schemas.microsoft.com/win/2004/08/events\">");
- sb.AppendLine(" <instrumentation xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:win=\"http://manifests.microsoft.com/win/2004/08/windows/events\">");
- sb.AppendLine(" <events xmlns=\"http://schemas.microsoft.com/win/2004/08/events\">");
- sb.Append("<provider name=\"").Append(providerName).
- Append("\" guid=\"{").Append(providerGuid.ToString()).Append("}");
- if (dllName != null)
- sb.Append("\" resourceFileName=\"").Append(dllName).Append("\" messageFileName=\"").Append(dllName);
-
- string symbolsName = providerName.Replace("-", "").Replace('.', '_'); // Period and - are illegal replace them.
- sb.Append("\" symbol=\"").Append(symbolsName);
- sb.AppendLine("\">");
- }
-
- public void AddOpcode(string name, int value)
- {
- if ((flags & EventManifestOptions.Strict) != 0)
- {
- if (value <= 10 || value >= 239)
- {
- ManifestError(SR.Format(SR.EventSource_IllegalOpcodeValue, name, value));
- }
-
- if (opcodeTab.TryGetValue(value, out string? prevName) && !name.Equals(prevName, StringComparison.Ordinal))
- {
- ManifestError(SR.Format(SR.EventSource_OpcodeCollision, name, prevName, value));
- }
- }
-
- opcodeTab[value] = name;
- }
-
- public void AddTask(string name, int value)
- {
- if ((flags & EventManifestOptions.Strict) != 0)
- {
- if (value <= 0 || value >= 65535)
- {
- ManifestError(SR.Format(SR.EventSource_IllegalTaskValue, name, value));
- }
-
- if (taskTab != null && taskTab.TryGetValue(value, out string? prevName) && !name.Equals(prevName, StringComparison.Ordinal))
- {
- ManifestError(SR.Format(SR.EventSource_TaskCollision, name, prevName, value));
- }
- }
-
- taskTab ??= new Dictionary<int, string>();
- taskTab[value] = name;
- }
-
- public void AddKeyword(string name, ulong value)
- {
- if ((value & (value - 1)) != 0) // Is it a power of 2?
- {
- ManifestError(SR.Format(SR.EventSource_KeywordNeedPowerOfTwo, "0x" + value.ToString("x", CultureInfo.CurrentCulture), name), true);
- }
- if ((flags & EventManifestOptions.Strict) != 0)
- {
- if (value >= 0x0000100000000000UL && !name.StartsWith("Session", StringComparison.Ordinal))
- {
- ManifestError(SR.Format(SR.EventSource_IllegalKeywordsValue, name, "0x" + value.ToString("x", CultureInfo.CurrentCulture)));
- }
-
- if (keywordTab != null && keywordTab.TryGetValue(value, out string? prevName) && !name.Equals(prevName, StringComparison.Ordinal))
- {
- ManifestError(SR.Format(SR.EventSource_KeywordCollision, name, prevName, "0x" + value.ToString("x", CultureInfo.CurrentCulture)));
- }
- }
-
- keywordTab ??= new Dictionary<ulong, string>();
- keywordTab[value] = name;
- }
-
-#if FEATURE_MANAGED_ETW_CHANNELS
- /// <summary>
- /// Add a channel. channelAttribute can be null
- /// </summary>
- public void AddChannel(string? name, int value, EventChannelAttribute? channelAttribute)
- {
- EventChannel chValue = (EventChannel)value;
- if (value < (int)EventChannel.Admin || value > 255)
- ManifestError(SR.Format(SR.EventSource_EventChannelOutOfRange, name, value));
- else if (chValue >= EventChannel.Admin && chValue <= EventChannel.Debug &&
- channelAttribute != null && EventChannelToChannelType(chValue) != channelAttribute.EventChannelType)
- {
- // we want to ensure developers do not define EventChannels that conflict with the builtin ones,
- // but we want to allow them to override the default ones...
- ManifestError(SR.Format(SR.EventSource_ChannelTypeDoesNotMatchEventChannelValue,
- name, ((EventChannel)value).ToString()));
- }
-
- // TODO: validate there are no conflicting manifest exposed names (generally following the format "provider/type")
-
- ulong kwd = GetChannelKeyword(chValue);
-
- channelTab ??= new Dictionary<int, ChannelInfo>(4);
- channelTab[value] = new ChannelInfo { Name = name, Keywords = kwd, Attribs = channelAttribute };
- }
-
- private static EventChannelType EventChannelToChannelType(EventChannel channel)
- {
-#if !ES_BUILD_STANDALONE
- Debug.Assert(channel >= EventChannel.Admin && channel <= EventChannel.Debug);
-#endif
- return (EventChannelType)((int)channel - (int)EventChannel.Admin + (int)EventChannelType.Admin);
- }
-
- private static EventChannelAttribute GetDefaultChannelAttribute(EventChannel channel)
- {
- EventChannelAttribute attrib = new EventChannelAttribute();
- attrib.EventChannelType = EventChannelToChannelType(channel);
- if (attrib.EventChannelType <= EventChannelType.Operational)
- attrib.Enabled = true;
- return attrib;
- }
-
- public ulong[] GetChannelData()
- {
- if (this.channelTab == null)
- {
- return Array.Empty<ulong>();
- }
-
- // We create an array indexed by the channel id for fast look up.
- // E.g. channelMask[Admin] will give you the bit mask for Admin channel.
- int maxkey = -1;
- foreach (int item in this.channelTab.Keys)
- {
- if (item > maxkey)
- {
- maxkey = item;
- }
- }
-
- ulong[] channelMask = new ulong[maxkey + 1];
- foreach (KeyValuePair<int, ChannelInfo> item in this.channelTab)
- {
- channelMask[item.Key] = item.Value.Keywords;
- }
-
- return channelMask;
- }
-
-#endif
- public void StartEvent(string eventName, EventAttribute eventAttribute)
- {
- Debug.Assert(numParams == 0);
- Debug.Assert(this.eventName == null);
- this.eventName = eventName;
- numParams = 0;
- byteArrArgIndices = null;
-
- events.Append(" <event").
- Append(" value=\"").Append(eventAttribute.EventId).Append("\"").
- Append(" version=\"").Append(eventAttribute.Version).Append("\"").
- Append(" level=\"").Append(GetLevelName(eventAttribute.Level)).Append("\"").
- Append(" symbol=\"").Append(eventName).Append("\"");
-
- // at this point we add to the manifest's stringTab a message that is as-of-yet
- // "untranslated to manifest convention", b/c we don't have the number or position
- // of any byte[] args (which require string format index updates)
- WriteMessageAttrib(events, "event", eventName, eventAttribute.Message);
-
- if (eventAttribute.Keywords != 0)
- events.Append(" keywords=\"").Append(GetKeywords((ulong)eventAttribute.Keywords, eventName)).Append("\"");
- if (eventAttribute.Opcode != 0)
- events.Append(" opcode=\"").Append(GetOpcodeName(eventAttribute.Opcode, eventName)).Append("\"");
- if (eventAttribute.Task != 0)
- events.Append(" task=\"").Append(GetTaskName(eventAttribute.Task, eventName)).Append("\"");
-#if FEATURE_MANAGED_ETW_CHANNELS
- if (eventAttribute.Channel != 0)
- {
- events.Append(" channel=\"").Append(GetChannelName(eventAttribute.Channel, eventName, eventAttribute.Message)).Append("\"");
- }
-#endif
- }
-
- public void AddEventParameter(Type type, string name)
- {
- if (numParams == 0)
- templates.Append(" <template tid=\"").Append(eventName).AppendLine("Args\">");
- if (type == typeof(byte[]))
- {
- // mark this index as "extraneous" (it has no parallel in the managed signature)
- // we use these values in TranslateToManifestConvention()
- byteArrArgIndices ??= new List<int>(4);
- byteArrArgIndices.Add(numParams);
-
- // add an extra field to the template representing the length of the binary blob
- numParams++;
- templates.Append(" <data name=\"").Append(name).AppendLine("Size\" inType=\"win:UInt32\"/>");
- }
- numParams++;
- templates.Append(" <data name=\"").Append(name).Append("\" inType=\"").Append(GetTypeName(type)).Append("\"");
- // TODO: for 'byte*' types it assumes the user provided length is named using the same naming convention
- // as for 'byte[]' args (blob_arg_name + "Size")
- if ((type.IsArray || type.IsPointer) && type.GetElementType() == typeof(byte))
- {
- // add "length" attribute to the "blob" field in the template (referencing the field added above)
- templates.Append(" length=\"").Append(name).Append("Size\"");
- }
- // ETW does not support 64-bit value maps, so we don't specify these as ETW maps
- if (type.IsEnum() && Enum.GetUnderlyingType(type) != typeof(ulong) && Enum.GetUnderlyingType(type) != typeof(long))
- {
- templates.Append(" map=\"").Append(type.Name).Append("\"");
- mapsTab ??= new Dictionary<string, Type>();
- if (!mapsTab.ContainsKey(type.Name))
- mapsTab.Add(type.Name, type); // Remember that we need to dump the type enumeration
- }
-
- templates.AppendLine("/>");
- }
- public void EndEvent()
- {
- Debug.Assert(eventName != null);
-
- if (numParams > 0)
- {
- templates.AppendLine(" </template>");
- events.Append(" template=\"").Append(eventName).Append("Args\"");
- }
- events.AppendLine("/>");
-
- if (byteArrArgIndices != null)
- perEventByteArrayArgIndices[eventName] = byteArrArgIndices;
-
- // at this point we have all the information we need to translate the C# Message
- // to the manifest string we'll put in the stringTab
- if (stringTab.TryGetValue("event_" + eventName, out string? msg))
- {
- msg = TranslateToManifestConvention(msg, eventName);
- stringTab["event_" + eventName] = msg;
- }
-
- eventName = null;
- numParams = 0;
- byteArrArgIndices = null;
- }
-
-#if FEATURE_MANAGED_ETW_CHANNELS
- // Channel keywords are generated one per channel to allow channel based filtering in event viewer. These keywords are autogenerated
- // by mc.exe for compiling a manifest and are based on the order of the channels (fields) in the Channels inner class (when advanced
- // channel support is enabled), or based on the order the predefined channels appear in the EventAttribute properties (for simple
- // support). The manifest generated *MUST* have the channels specified in the same order (that's how our computed keywords are mapped
- // to channels by the OS infrastructure).
- // If channelKeyworkds is present, and has keywords bits in the ValidPredefinedChannelKeywords then it is
- // assumed that the keyword for that channel should be that bit.
- // otherwise we allocate a channel bit for the channel.
- // explicit channel bits are only used by WCF to mimic an existing manifest,
- // so we don't dont do error checking.
- public ulong GetChannelKeyword(EventChannel channel, ulong channelKeyword = 0)
- {
- // strip off any non-channel keywords, since we are only interested in channels here.
- channelKeyword &= ValidPredefinedChannelKeywords;
- channelTab ??= new Dictionary<int, ChannelInfo>(4);
-
- if (channelTab.Count == MaxCountChannels)
- ManifestError(SR.EventSource_MaxChannelExceeded);
-
- ChannelInfo? info;
- if (!channelTab.TryGetValue((int)channel, out info))
- {
- // If we were not given an explicit channel, allocate one.
- if (channelKeyword != 0)
- {
- channelKeyword = nextChannelKeywordBit;
- nextChannelKeywordBit >>= 1;
- }
- }
- else
- {
- channelKeyword = info.Keywords;
- }
-
- return channelKeyword;
- }
-#endif
-
- public byte[] CreateManifest()
- {
- string str = CreateManifestString();
- return Encoding.UTF8.GetBytes(str);
- }
-
- public IList<string> Errors => errors;
-
- /// <summary>
- /// When validating an event source it adds the error to the error collection.
- /// When not validating it throws an exception if runtimeCritical is "true".
- /// Otherwise the error is ignored.
- /// </summary>
- /// <param name="msg"></param>
- /// <param name="runtimeCritical"></param>
- public void ManifestError(string msg, bool runtimeCritical = false)
- {
- if ((flags & EventManifestOptions.Strict) != 0)
- errors.Add(msg);
- else if (runtimeCritical)
- throw new ArgumentException(msg);
- }
-
- private string CreateManifestString()
- {
-#if FEATURE_MANAGED_ETW_CHANNELS
- // Write out the channels
- if (channelTab != null)
- {
- sb.AppendLine(" <channels>");
- var sortedChannels = new List<KeyValuePair<int, ChannelInfo>>();
- foreach (KeyValuePair<int, ChannelInfo> p in channelTab) { sortedChannels.Add(p); }
- sortedChannels.Sort((p1, p2) => -Comparer<ulong>.Default.Compare(p1.Value.Keywords, p2.Value.Keywords));
- foreach (KeyValuePair<int, ChannelInfo> kvpair in sortedChannels)
- {
- int channel = kvpair.Key;
- ChannelInfo channelInfo = kvpair.Value;
-
- string? channelType = null;
- const string ElementName = "channel";
- bool enabled = false;
- string? fullName = null;
-#if FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
- string? isolation = null;
- string? access = null;
-#endif
- if (channelInfo.Attribs != null)
- {
- EventChannelAttribute attribs = channelInfo.Attribs;
- if (Enum.IsDefined(typeof(EventChannelType), attribs.EventChannelType))
- channelType = attribs.EventChannelType.ToString();
- enabled = attribs.Enabled;
-#if FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
- if (attribs.ImportChannel != null)
- {
- fullName = attribs.ImportChannel;
- elementName = "importChannel";
- }
- if (Enum.IsDefined(typeof(EventChannelIsolation), attribs.Isolation))
- isolation = attribs.Isolation.ToString();
- access = attribs.Access;
-#endif
- }
-
- fullName ??= providerName + "/" + channelInfo.Name;
-
- sb.Append(" <").Append(ElementName);
- sb.Append(" chid=\"").Append(channelInfo.Name).Append("\"");
- sb.Append(" name=\"").Append(fullName).Append("\"");
- if (ElementName == "channel") // not applicable to importChannels.
- {
- Debug.Assert(channelInfo.Name != null);
- WriteMessageAttrib(sb, "channel", channelInfo.Name, null);
- sb.Append(" value=\"").Append(channel).Append("\"");
- if (channelType != null)
- sb.Append(" type=\"").Append(channelType).Append("\"");
- sb.Append(" enabled=\"").Append(enabled ? "true" : "false").Append("\"");
-#if FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
- if (access != null)
- sb.Append(" access=\"").Append(access).Append("\"");
- if (isolation != null)
- sb.Append(" isolation=\"").Append(isolation).Append("\"");
-#endif
- }
- sb.AppendLine("/>");
- }
- sb.AppendLine(" </channels>");
- }
-#endif
-
- // Write out the tasks
- if (taskTab != null)
- {
- sb.AppendLine(" <tasks>");
- var sortedTasks = new List<int>(taskTab.Keys);
- sortedTasks.Sort();
- foreach (int task in sortedTasks)
- {
- sb.Append(" <task");
- WriteNameAndMessageAttribs(sb, "task", taskTab[task]);
- sb.Append(" value=\"").Append(task).AppendLine("\"/>");
- }
- sb.AppendLine(" </tasks>");
- }
-
- // Write out the maps
- if (mapsTab != null)
- {
- sb.AppendLine(" <maps>");
- foreach (Type enumType in mapsTab.Values)
- {
- bool isbitmap = EventSource.GetCustomAttributeHelper(enumType, typeof(FlagsAttribute), flags) != null;
- string mapKind = isbitmap ? "bitMap" : "valueMap";
- sb.Append(" <").Append(mapKind).Append(" name=\"").Append(enumType.Name).AppendLine("\">");
-
- // write out each enum value
- FieldInfo[] staticFields = enumType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static);
- bool anyValuesWritten = false;
- foreach (FieldInfo staticField in staticFields)
- {
- object? constantValObj = staticField.GetRawConstantValue();
-
- if (constantValObj != null)
- {
- ulong hexValue;
- if (constantValObj is ulong)
- hexValue = (ulong)constantValObj; // This is the only integer type that can't be represented by a long.
- else
- hexValue = (ulong)Convert.ToInt64(constantValObj); // Handles all integer types except ulong.
-
- // ETW requires all bitmap values to be powers of 2. Skip the ones that are not.
- // TODO: Warn people about the dropping of values.
- if (isbitmap && ((hexValue & (hexValue - 1)) != 0 || hexValue == 0))
- continue;
- sb.Append(" <map value=\"0x").Append(hexValue.ToString("x", CultureInfo.InvariantCulture)).Append("\"");
- WriteMessageAttrib(sb, "map", enumType.Name + "." + staticField.Name, staticField.Name);
- sb.AppendLine("/>");
- anyValuesWritten = true;
- }
- }
-
- // the OS requires that bitmaps and valuemaps have at least one value or it reject the whole manifest.
- // To avoid that put a 'None' entry if there are no other values.
- if (!anyValuesWritten)
- {
- sb.Append(" <map value=\"0x0\"");
- WriteMessageAttrib(sb, "map", enumType.Name + ".None", "None");
- sb.AppendLine("/>");
- }
- sb.Append(" </").Append(mapKind).AppendLine(">");
- }
- sb.AppendLine(" </maps>");
- }
-
- // Write out the opcodes
- sb.AppendLine(" <opcodes>");
- var sortedOpcodes = new List<int>(opcodeTab.Keys);
- sortedOpcodes.Sort();
- foreach (int opcode in sortedOpcodes)
- {
- sb.Append(" <opcode");
- WriteNameAndMessageAttribs(sb, "opcode", opcodeTab[opcode]);
- sb.Append(" value=\"").Append(opcode).AppendLine("\"/>");
- }
- sb.AppendLine(" </opcodes>");
-
- // Write out the keywords
- if (keywordTab != null)
- {
- sb.AppendLine(" <keywords>");
- var sortedKeywords = new List<ulong>(keywordTab.Keys);
- sortedKeywords.Sort();
- foreach (ulong keyword in sortedKeywords)
- {
- sb.Append(" <keyword");
- WriteNameAndMessageAttribs(sb, "keyword", keywordTab[keyword]);
- sb.Append(" mask=\"0x").Append(keyword.ToString("x", CultureInfo.InvariantCulture)).AppendLine("\"/>");
- }
- sb.AppendLine(" </keywords>");
- }
-
- sb.AppendLine(" <events>");
- sb.Append(events);
- sb.AppendLine(" </events>");
-
- sb.AppendLine(" <templates>");
- if (templates.Length > 0)
- {
- sb.Append(templates);
- }
- else
- {
- // Work around a cornercase ETW issue where a manifest with no templates causes
- // ETW events to not get sent to their associated channel.
- sb.AppendLine(" <template tid=\"_empty\"></template>");
- }
- sb.AppendLine(" </templates>");
-
- sb.AppendLine("</provider>");
- sb.AppendLine("</events>");
- sb.AppendLine("</instrumentation>");
-
- // Output the localization information.
- sb.AppendLine("<localization>");
-
- List<CultureInfo> cultures = (resources != null && (flags & EventManifestOptions.AllCultures) != 0) ?
- GetSupportedCultures() :
- new List<CultureInfo>() { CultureInfo.CurrentUICulture };
-
- var sortedStrings = new string[stringTab.Keys.Count];
- stringTab.Keys.CopyTo(sortedStrings, 0);
- Array.Sort<string>(sortedStrings, 0, sortedStrings.Length);
-
- foreach (CultureInfo ci in cultures)
- {
- sb.Append(" <resources culture=\"").Append(ci.Name).AppendLine("\">");
- sb.AppendLine(" <stringTable>");
-
- foreach (string stringKey in sortedStrings)
- {
- string? val = GetLocalizedMessage(stringKey, ci, etwFormat: true);
- sb.Append(" <string id=\"").Append(stringKey).Append("\" value=\"").Append(val).AppendLine("\"/>");
- }
- sb.AppendLine(" </stringTable>");
- sb.AppendLine(" </resources>");
- }
- sb.AppendLine("</localization>");
- sb.AppendLine("</instrumentationManifest>");
- return sb.ToString();
- }
-
-#region private
- private void WriteNameAndMessageAttribs(StringBuilder stringBuilder, string elementName, string name)
- {
- stringBuilder.Append(" name=\"").Append(name).Append("\"");
- WriteMessageAttrib(sb, elementName, name, name);
- }
- private void WriteMessageAttrib(StringBuilder stringBuilder, string elementName, string name, string? value)
- {
- string key = elementName + "_" + name;
- // See if the user wants things localized.
- if (resources != null)
- {
- // resource fallback: strings in the neutral culture will take precedence over inline strings
- string? localizedString = resources.GetString(key, CultureInfo.InvariantCulture);
- if (localizedString != null)
- value = localizedString;
- }
- if (value == null)
- return;
-
- stringBuilder.Append(" message=\"$(string.").Append(key).Append(")\"");
-
- if (stringTab.TryGetValue(key, out string? prevValue) && !prevValue.Equals(value))
- {
- ManifestError(SR.Format(SR.EventSource_DuplicateStringKey, key), true);
- return;
- }
-
- stringTab[key] = value;
- }
- internal string? GetLocalizedMessage(string key, CultureInfo ci, bool etwFormat)
- {
- string? value = null;
- if (resources != null)
- {
- string? localizedString = resources.GetString(key, ci);
- if (localizedString != null)
- {
- value = localizedString;
- if (etwFormat && key.StartsWith("event_", StringComparison.Ordinal))
- {
- string evtName = key.Substring("event_".Length);
- value = TranslateToManifestConvention(value, evtName);
- }
- }
- }
- if (etwFormat && value == null)
- stringTab.TryGetValue(key, out value);
-
- return value;
- }
-
- /// <summary>
- /// There's no API to enumerate all languages an assembly is localized into, so instead
- /// we enumerate through all the "known" cultures and attempt to load a corresponding satellite
- /// assembly
- /// </summary>
- /// <returns></returns>
- private static List<CultureInfo> GetSupportedCultures()
- {
- var cultures = new List<CultureInfo>();
-
- if (!cultures.Contains(CultureInfo.CurrentUICulture))
- cultures.Insert(0, CultureInfo.CurrentUICulture);
- return cultures;
- }
-
- private static string GetLevelName(EventLevel level)
- {
- return (((int)level >= 16) ? "" : "win:") + level.ToString();
- }
-
-#if FEATURE_MANAGED_ETW_CHANNELS
- private string? GetChannelName(EventChannel channel, string eventName, string? eventMessage)
- {
- ChannelInfo? info = null;
- if (channelTab == null || !channelTab.TryGetValue((int)channel, out info))
- {
- if (channel < EventChannel.Admin) // || channel > EventChannel.Debug)
- ManifestError(SR.Format(SR.EventSource_UndefinedChannel, channel, eventName));
-
- // allow channels to be auto-defined. The well known ones get their well known names, and the
- // rest get names Channel<N>. This allows users to modify the Manifest if they want more advanced features.
- channelTab ??= new Dictionary<int, ChannelInfo>(4);
-
- string channelName = channel.ToString(); // For well know channels this is a nice name, otherwise a number
- if (EventChannel.Debug < channel)
- channelName = "Channel" + channelName; // Add a 'Channel' prefix for numbers.
-
- AddChannel(channelName, (int)channel, GetDefaultChannelAttribute(channel));
- if (!channelTab.TryGetValue((int)channel, out info))
- ManifestError(SR.Format(SR.EventSource_UndefinedChannel, channel, eventName));
- }
- // events that specify admin channels *must* have non-null "Message" attributes
- if (resources != null)
- eventMessage ??= resources.GetString("event_" + eventName, CultureInfo.InvariantCulture);
-
- Debug.Assert(info!.Attribs != null);
- if (info.Attribs.EventChannelType == EventChannelType.Admin && eventMessage == null)
- ManifestError(SR.Format(SR.EventSource_EventWithAdminChannelMustHaveMessage, eventName, info.Name));
- return info.Name;
- }
-#endif
- private string GetTaskName(EventTask task, string eventName)
- {
- if (task == EventTask.None)
- return "";
-
- string? ret;
- taskTab ??= new Dictionary<int, string>();
- if (!taskTab.TryGetValue((int)task, out ret))
- ret = taskTab[(int)task] = eventName;
- return ret;
- }
-
- private string? GetOpcodeName(EventOpcode opcode, string eventName)
- {
- switch (opcode)
- {
- case EventOpcode.Info:
- return "win:Info";
- case EventOpcode.Start:
- return "win:Start";
- case EventOpcode.Stop:
- return "win:Stop";
- case EventOpcode.DataCollectionStart:
- return "win:DC_Start";
- case EventOpcode.DataCollectionStop:
- return "win:DC_Stop";
- case EventOpcode.Extension:
- return "win:Extension";
- case EventOpcode.Reply:
- return "win:Reply";
- case EventOpcode.Resume:
- return "win:Resume";
- case EventOpcode.Suspend:
- return "win:Suspend";
- case EventOpcode.Send:
- return "win:Send";
- case EventOpcode.Receive:
- return "win:Receive";
- }
-
- string? ret;
- if (opcodeTab == null || !opcodeTab.TryGetValue((int)opcode, out ret))
- {
- ManifestError(SR.Format(SR.EventSource_UndefinedOpcode, opcode, eventName), true);
- ret = null;
- }
-
- return ret;
- }
-
- private string GetKeywords(ulong keywords, string eventName)
- {
-#if FEATURE_MANAGED_ETW_CHANNELS
- // ignore keywords associate with channels
- // See ValidPredefinedChannelKeywords def for more.
- keywords &= ~ValidPredefinedChannelKeywords;
-#endif
-
- string ret = "";
- for (ulong bit = 1; bit != 0; bit <<= 1)
- {
- if ((keywords & bit) != 0)
- {
- string? keyword = null;
- if ((keywordTab == null || !keywordTab.TryGetValue(bit, out keyword)) &&
- (bit >= (ulong)0x1000000000000))
- {
- // do not report Windows reserved keywords in the manifest (this allows the code
- // to be resilient to potential renaming of these keywords)
- keyword = string.Empty;
- }
- if (keyword == null)
- {
- ManifestError(SR.Format(SR.EventSource_UndefinedKeyword, "0x" + bit.ToString("x", CultureInfo.CurrentCulture), eventName), true);
- keyword = string.Empty;
- }
- if (ret.Length != 0 && keyword.Length != 0)
- ret += " ";
- ret += keyword;
- }
- }
- return ret;
- }
-
- private string GetTypeName(Type type)
- {
- if (type.IsEnum())
- {
- FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
- string typeName = GetTypeName(fields[0].FieldType);
- return typeName.Replace("win:Int", "win:UInt"); // ETW requires enums to be unsigned.
- }
-
- switch (type.GetTypeCode())
- {
- case TypeCode.Boolean:
- return "win:Boolean";
- case TypeCode.Byte:
- return "win:UInt8";
- case TypeCode.Char:
- case TypeCode.UInt16:
- return "win:UInt16";
- case TypeCode.UInt32:
- return "win:UInt32";
- case TypeCode.UInt64:
- return "win:UInt64";
- case TypeCode.SByte:
- return "win:Int8";
- case TypeCode.Int16:
- return "win:Int16";
- case TypeCode.Int32:
- return "win:Int32";
- case TypeCode.Int64:
- return "win:Int64";
- case TypeCode.String:
- return "win:UnicodeString";
- case TypeCode.Single:
- return "win:Float";
- case TypeCode.Double:
- return "win:Double";
- case TypeCode.DateTime:
- return "win:FILETIME";
- default:
- if (type == typeof(Guid))
- return "win:GUID";
- else if (type == typeof(IntPtr))
- return "win:Pointer";
- else if ((type.IsArray || type.IsPointer) && type.GetElementType() == typeof(byte))
- return "win:Binary";
-
- ManifestError(SR.Format(SR.EventSource_UnsupportedEventTypeInManifest, type.Name), true);
- return string.Empty;
- }
- }
-
- private static void UpdateStringBuilder([NotNull] ref StringBuilder? stringBuilder, string eventMessage, int startIndex, int count)
- {
- stringBuilder ??= new StringBuilder();
- stringBuilder.Append(eventMessage, startIndex, count);
- }
-
- private static readonly string[] s_escapes = { "&amp;", "&lt;", "&gt;", "&apos;", "&quot;", "%r", "%n", "%t" };
- // Manifest messages use %N conventions for their message substitutions. Translate from
- // .NET conventions. We can't use RegEx for this (we are in mscorlib), so we do it 'by hand'
- private string TranslateToManifestConvention(string eventMessage, string evtName)
- {
- StringBuilder? stringBuilder = null; // We lazily create this
- int writtenSoFar = 0;
- int chIdx = -1;
- for (int i = 0; ;)
- {
- if (i >= eventMessage.Length)
- {
- if (stringBuilder == null)
- return eventMessage;
- UpdateStringBuilder(ref stringBuilder, eventMessage, writtenSoFar, i - writtenSoFar);
- return stringBuilder.ToString();
- }
-
- if (eventMessage[i] == '%')
- {
- // handle format message escaping character '%' by escaping it
- UpdateStringBuilder(ref stringBuilder, eventMessage, writtenSoFar, i - writtenSoFar);
- stringBuilder.Append("%%");
- i++;
- writtenSoFar = i;
- }
- else if (i < eventMessage.Length - 1 &&
- (eventMessage[i] == '{' && eventMessage[i + 1] == '{' || eventMessage[i] == '}' && eventMessage[i + 1] == '}'))
- {
- // handle C# escaped '{" and '}'
- UpdateStringBuilder(ref stringBuilder, eventMessage, writtenSoFar, i - writtenSoFar);
- stringBuilder.Append(eventMessage[i]);
- i++; i++;
- writtenSoFar = i;
- }
- else if (eventMessage[i] == '{')
- {
- int leftBracket = i;
- i++;
- int argNum = 0;
- while (i < eventMessage.Length && char.IsDigit(eventMessage[i]))
- {
- argNum = argNum * 10 + eventMessage[i] - '0';
- i++;
- }
- if (i < eventMessage.Length && eventMessage[i] == '}')
- {
- i++;
- UpdateStringBuilder(ref stringBuilder, eventMessage, writtenSoFar, leftBracket - writtenSoFar);
- int manIndex = TranslateIndexToManifestConvention(argNum, evtName);
- stringBuilder.Append('%').Append(manIndex);
- // An '!' after the insert specifier {n} will be interpreted as a literal.
- // We'll escape it so that mc.exe does not attempt to consider it the
- // beginning of a format string.
- if (i < eventMessage.Length && eventMessage[i] == '!')
- {
- i++;
- stringBuilder.Append("%!");
- }
- writtenSoFar = i;
- }
- else
- {
- ManifestError(SR.Format(SR.EventSource_UnsupportedMessageProperty, evtName, eventMessage));
- }
- }
- else if ((chIdx = "&<>'\"\r\n\t".IndexOf(eventMessage[i])) >= 0)
- {
- UpdateStringBuilder(ref stringBuilder, eventMessage, writtenSoFar, i - writtenSoFar);
- i++;
- stringBuilder.Append(s_escapes[chIdx]);
- writtenSoFar = i;
- }
- else
- i++;
- }
- }
-
- private int TranslateIndexToManifestConvention(int idx, string evtName)
- {
- List<int>? byteArrArgIndices;
- if (perEventByteArrayArgIndices.TryGetValue(evtName, out byteArrArgIndices))
- {
- foreach (int byArrIdx in byteArrArgIndices)
- {
- if (idx >= byArrIdx)
- ++idx;
- else
- break;
- }
- }
- return idx + 1;
- }
-
-#if FEATURE_MANAGED_ETW_CHANNELS
- private class ChannelInfo
- {
- public string? Name;
- public ulong Keywords;
- public EventChannelAttribute? Attribs;
- }
-#endif
-
- private readonly Dictionary<int, string> opcodeTab;
- private Dictionary<int, string>? taskTab;
-#if FEATURE_MANAGED_ETW_CHANNELS
- private Dictionary<int, ChannelInfo>? channelTab;
-#endif
- private Dictionary<ulong, string>? keywordTab;
- private Dictionary<string, Type>? mapsTab;
- private readonly Dictionary<string, string> stringTab; // Maps unlocalized strings to localized ones
-
-#if FEATURE_MANAGED_ETW_CHANNELS
- // WCF used EventSource to mimic a existing ETW manifest. To support this
- // in just their case, we allowed them to specify the keywords associated
- // with their channels explicitly. ValidPredefinedChannelKeywords is
- // this set of channel keywords that we allow to be explicitly set. You
- // can ignore these bits otherwise.
- internal const ulong ValidPredefinedChannelKeywords = 0xF000000000000000;
- private ulong nextChannelKeywordBit = 0x8000000000000000; // available Keyword bit to be used for next channel definition, grows down
- private const int MaxCountChannels = 8; // a manifest can defined at most 8 ETW channels
-#endif
-
- private readonly StringBuilder sb; // Holds the provider information.
- private readonly StringBuilder events; // Holds the events.
- private readonly StringBuilder templates;
-
-#if FEATURE_MANAGED_ETW_CHANNELS
- private readonly string providerName;
-#endif
- private readonly ResourceManager? resources; // Look up localized strings here.
- private readonly EventManifestOptions flags;
- private readonly IList<string> errors; // list of currently encountered errors
- private readonly Dictionary<string, List<int>> perEventByteArrayArgIndices; // "event_name" -> List_of_Indices_of_Byte[]_Arg
-
- // State we track between StartEvent and EndEvent.
- private string? eventName; // Name of the event currently being processed.
- private int numParams; // keeps track of the number of args the event has.
- private List<int>? byteArrArgIndices; // keeps track of the index of each byte[] argument
-#endregion
- }
-
- /// <summary>
- /// Used to send the m_rawManifest into the event dispatcher as a series of events.
- /// </summary>
- internal struct ManifestEnvelope
- {
- public const int MaxChunkSize = 0xFF00;
- public enum ManifestFormats : byte
- {
- SimpleXmlFormat = 1, // simply dump the XML manifest as UTF8
- }
-
-#if FEATURE_MANAGED_ETW
- public ManifestFormats Format;
- public byte MajorVersion;
- public byte MinorVersion;
- public byte Magic;
- public ushort TotalChunks;
- public ushort ChunkNumber;
-#endif
- }
-
-#endregion
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSourceException.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSourceException.cs
deleted file mode 100644
index 2a8515ad615..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSourceException.cs
+++ /dev/null
@@ -1,52 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using Environment = Microsoft.Diagnostics.Tracing.Internal.Environment;
-#endif
-using System.Runtime.Serialization;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Exception that is thrown when an error occurs during EventSource operation.
- /// </summary>
-#if !ES_BUILD_PCL
- [Serializable]
-#endif
- public class EventSourceException : Exception
- {
- /// <summary>
- /// Initializes a new instance of the EventSourceException class.
- /// </summary>
- public EventSourceException() :
- base(SR.EventSource_ListenerWriteFailure) { }
-
- /// <summary>
- /// Initializes a new instance of the EventSourceException class with a specified error message.
- /// </summary>
- public EventSourceException(string? message) : base(message) { }
-
- /// <summary>
- /// Initializes a new instance of the EventSourceException class with a specified error message
- /// and a reference to the inner exception that is the cause of this exception.
- /// </summary>
- public EventSourceException(string? message, Exception? innerException) : base(message, innerException) { }
-
-#if !ES_BUILD_PCL
- /// <summary>
- /// Initializes a new instance of the EventSourceException class with serialized data.
- /// </summary>
- protected EventSourceException(SerializationInfo info, StreamingContext context) : base(info, context) { }
-#endif
-
- internal EventSourceException(Exception? innerException) :
- base(SR.EventSource_ListenerWriteFailure, innerException) { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/FrameworkEventSource.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/FrameworkEventSource.cs
deleted file mode 100644
index 321ae819f50..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/FrameworkEventSource.cs
+++ /dev/null
@@ -1,161 +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 Internal.Runtime.CompilerServices;
-
-namespace System.Diagnostics.Tracing
-{
- [EventSource(Guid = "8E9F5090-2D75-4d03-8A81-E5AFBF85DAF1", Name = "System.Diagnostics.Eventing.FrameworkEventSource")]
- internal sealed class FrameworkEventSource : EventSource
- {
- public static readonly FrameworkEventSource Log = new FrameworkEventSource();
-
- // Keyword definitions. These represent logical groups of events that can be turned on and off independently
- // Often each task has a keyword, but where tasks are determined by subsystem, keywords are determined by
- // usefulness to end users to filter. Generally users don't mind extra events if they are not high volume
- // so grouping low volume events together in a single keywords is OK (users can post-filter by task if desired)
- public static class Keywords
- {
- public const EventKeywords ThreadPool = (EventKeywords)0x0002;
- public const EventKeywords ThreadTransfer = (EventKeywords)0x0010;
- }
-
- /// <summary>ETW tasks that have start/stop events.</summary>
- public static class Tasks // this name is important for EventSource
- {
- /// <summary>Send / Receive - begin transfer/end transfer</summary>
- public const EventTask ThreadTransfer = (EventTask)3;
- }
-
- // The FrameworkEventSource GUID is {8E9F5090-2D75-4d03-8A81-E5AFBF85DAF1}
- private FrameworkEventSource() : base(new Guid(0x8e9f5090, 0x2d75, 0x4d03, 0x8a, 0x81, 0xe5, 0xaf, 0xbf, 0x85, 0xda, 0xf1), "System.Diagnostics.Eventing.FrameworkEventSource") { }
-
- // optimized for common signatures (used by the ThreadTransferSend/Receive events)
- [NonEvent]
- private unsafe void WriteEvent(int eventId, long arg1, int arg2, string? arg3, bool arg4, int arg5, int arg6)
- {
- if (IsEnabled())
- {
- arg3 ??= "";
- fixed (char* string3Bytes = arg3)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[6];
- descrs[0].DataPointer = (IntPtr)(&arg1);
- descrs[0].Size = 8;
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)(&arg2);
- descrs[1].Size = 4;
- descrs[1].Reserved = 0;
- descrs[2].DataPointer = (IntPtr)string3Bytes;
- descrs[2].Size = ((arg3.Length + 1) * 2);
- descrs[2].Reserved = 0;
- descrs[3].DataPointer = (IntPtr)(&arg4);
- descrs[3].Size = 4;
- descrs[3].Reserved = 0;
- descrs[4].DataPointer = (IntPtr)(&arg5);
- descrs[4].Size = 4;
- descrs[4].Reserved = 0;
- descrs[5].DataPointer = (IntPtr)(&arg6);
- descrs[5].Size = 4;
- descrs[5].Reserved = 0;
- WriteEventCore(eventId, 6, descrs);
- }
- }
- }
-
- // optimized for common signatures (used by the ThreadTransferSend/Receive events)
- [NonEvent]
- private unsafe void WriteEvent(int eventId, long arg1, int arg2, string? arg3)
- {
- if (IsEnabled())
- {
- arg3 ??= "";
- fixed (char* string3Bytes = arg3)
- {
- EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
- descrs[0].DataPointer = (IntPtr)(&arg1);
- descrs[0].Size = 8;
- descrs[0].Reserved = 0;
- descrs[1].DataPointer = (IntPtr)(&arg2);
- descrs[1].Size = 4;
- descrs[1].Reserved = 0;
- descrs[2].DataPointer = (IntPtr)string3Bytes;
- descrs[2].Size = ((arg3.Length + 1) * 2);
- descrs[2].Reserved = 0;
- WriteEventCore(eventId, 3, descrs);
- }
- }
- }
-
- [Event(30, Level = EventLevel.Verbose, Keywords = Keywords.ThreadPool | Keywords.ThreadTransfer)]
- public void ThreadPoolEnqueueWork(long workID)
- {
- WriteEvent(30, workID);
- }
-
- [NonEvent]
- public unsafe void ThreadPoolEnqueueWorkObject(object workID)
- {
- // convert the Object Id to a long
- ThreadPoolEnqueueWork((long)*((void**)Unsafe.AsPointer(ref workID)));
- }
-
- [Event(31, Level = EventLevel.Verbose, Keywords = Keywords.ThreadPool | Keywords.ThreadTransfer)]
- public void ThreadPoolDequeueWork(long workID)
- {
- WriteEvent(31, workID);
- }
-
- [NonEvent]
- public unsafe void ThreadPoolDequeueWorkObject(object workID)
- {
- // convert the Object Id to a long
- ThreadPoolDequeueWork((long)*((void**)Unsafe.AsPointer(ref workID)));
- }
-
- // id - represents a correlation ID that allows correlation of two activities, one stamped by
- // ThreadTransferSend, the other by ThreadTransferReceive
- // kind - identifies the transfer: values below 64 are reserved for the runtime. Currently used values:
- // 1 - managed Timers ("roaming" ID)
- // 2 - managed async IO operations (FileStream, PipeStream, a.o.)
- // 3 - WinRT dispatch operations
- // info - any additional information user code might consider interesting
- // intInfo1/2 - any additional integer information user code might consider interesting
- [Event(150, Level = EventLevel.Informational, Keywords = Keywords.ThreadTransfer, Task = Tasks.ThreadTransfer, Opcode = EventOpcode.Send)]
- public void ThreadTransferSend(long id, int kind, string info, bool multiDequeues, int intInfo1, int intInfo2)
- {
- WriteEvent(150, id, kind, info, multiDequeues, intInfo1, intInfo2);
- }
-
- // id - is a managed object. it gets translated to the object's address. ETW listeners must
- // keep track of GC movements in order to correlate the value passed to XyzSend with the
- // (possibly changed) value passed to XyzReceive
- [NonEvent]
- public unsafe void ThreadTransferSendObj(object id, int kind, string info, bool multiDequeues, int intInfo1, int intInfo2)
- {
- ThreadTransferSend((long)*((void**)Unsafe.AsPointer(ref id)), kind, info, multiDequeues, intInfo1, intInfo2);
- }
-
- // id - represents a correlation ID that allows correlation of two activities, one stamped by
- // ThreadTransferSend, the other by ThreadTransferReceive
- // kind - identifies the transfer: values below 64 are reserved for the runtime. Currently used values:
- // 1 - managed Timers ("roaming" ID)
- // 2 - managed async IO operations (FileStream, PipeStream, a.o.)
- // 3 - WinRT dispatch operations
- // info - any additional information user code might consider interesting
- [Event(151, Level = EventLevel.Informational, Keywords = Keywords.ThreadTransfer, Task = Tasks.ThreadTransfer, Opcode = EventOpcode.Receive)]
- public void ThreadTransferReceive(long id, int kind, string? info)
- {
- WriteEvent(151, id, kind, info);
- }
- // id - is a managed object. it gets translated to the object's address. ETW listeners must
- // keep track of GC movements in order to correlate the value passed to XyzSend with the
- // (possibly changed) value passed to XyzReceive
- [NonEvent]
- public unsafe void ThreadTransferReceiveObj(object id, int kind, string? info)
- {
- ThreadTransferReceive((long)*((void**)Unsafe.AsPointer(ref id)), kind, info);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IEventProvider.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IEventProvider.cs
deleted file mode 100644
index 2ceb92f99c0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IEventProvider.cs
+++ /dev/null
@@ -1,44 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- // Represents the interface between EventProvider and an external logging mechanism.
- internal interface IEventProvider
- {
- // Register an event provider.
- unsafe uint EventRegister(
- EventSource eventSource,
- Interop.Advapi32.EtwEnableCallback enableCallback,
- void* callbackContext,
- ref long registrationHandle);
-
- // Unregister an event provider.
- uint EventUnregister(long registrationHandle);
-
- // Write an event.
- unsafe EventProvider.WriteEventErrorCode EventWriteTransfer(
- long registrationHandle,
- in EventDescriptor eventDescriptor,
- IntPtr eventHandle,
- Guid* activityId,
- Guid* relatedActivityId,
- int userDataCount,
- EventProvider.EventData* userData);
-
- // Get or set the per-thread activity ID.
- int EventActivityIdControl(Interop.Advapi32.ActivityControl ControlCode, ref Guid ActivityId);
-
- // Define an EventPipeEvent handle.
- unsafe IntPtr DefineEventHandle(uint eventID, string eventName, long keywords, uint eventVersion, uint level, byte* pMetadata, uint metadataLength);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingEventCounter.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingEventCounter.cs
deleted file mode 100644
index 895ebe59fb2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingEventCounter.cs
+++ /dev/null
@@ -1,94 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// IncrementingEventCounter is a variant of EventCounter for variables that are ever-increasing.
- /// Ex) # of exceptions in the runtime.
- /// It does not calculate statistics like mean, standard deviation, etc. because it only accumulates
- /// the counter value.
- /// </summary>
- public partial class IncrementingEventCounter : DiagnosticCounter
- {
- /// <summary>
- /// Initializes a new instance of the <see cref="IncrementingEventCounter"/> class.
- /// IncrementingEventCounter live as long as the EventSource that they are attached to unless they are
- /// explicitly Disposed.
- /// </summary>
- /// <param name="name">The name.</param>
- /// <param name="eventSource">The event source.</param>
- public IncrementingEventCounter(string name, EventSource eventSource) : base(name, eventSource)
- {
- Publish();
- }
-
- /// <summary>
- /// Writes 'value' to the stream of values tracked by the counter. This updates the sum and other statistics that will
- /// be logged on the next timer interval.
- /// </summary>
- /// <param name="increment">The value to increment by.</param>
- public void Increment(double increment = 1)
- {
- lock (this)
- {
- _increment += increment;
- }
- }
-
- public TimeSpan DisplayRateTimeScale { get; set; }
- private double _increment;
- private double _prevIncrement;
-
- public override string ToString() => $"IncrementingEventCounter '{Name}' Increment {_increment}";
-
- internal override void WritePayload(float intervalSec, int pollingIntervalMillisec)
- {
- lock (this) // Lock the counter
- {
- IncrementingCounterPayload payload = new IncrementingCounterPayload();
- payload.Name = Name;
- payload.IntervalSec = intervalSec;
- payload.DisplayName = DisplayName ?? "";
- payload.DisplayRateTimeScale = (DisplayRateTimeScale == TimeSpan.Zero) ? "" : DisplayRateTimeScale.ToString("c");
- payload.Series = $"Interval={pollingIntervalMillisec}"; // TODO: This may need to change when we support multi-session
- payload.CounterType = "Sum";
- payload.Metadata = GetMetadataString();
- payload.Increment = _increment - _prevIncrement;
- payload.DisplayUnits = DisplayUnits ?? "";
- _prevIncrement = _increment;
- EventSource.Write("EventCounters", new EventSourceOptions() { Level = EventLevel.LogAlways }, new IncrementingEventCounterPayloadType(payload));
- }
- }
-
- // Updates the value.
- internal void UpdateMetric()
- {
- lock (this)
- {
- _prevIncrement = _increment;
- }
- }
- }
-
-
- /// <summary>
- /// This is the payload that is sent in the with EventSource.Write
- /// </summary>
- [EventData]
- internal class IncrementingEventCounterPayloadType
- {
- public IncrementingEventCounterPayloadType(IncrementingCounterPayload payload) { Payload = payload; }
- public IncrementingCounterPayload Payload { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingPollingCounter.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingPollingCounter.cs
deleted file mode 100644
index 0cdbac7e6a0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingPollingCounter.cs
+++ /dev/null
@@ -1,96 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// IncrementingPollingCounter is a variant of EventCounter for variables that are ever-increasing.
- /// Ex) # of exceptions in the runtime.
- /// It does not calculate statistics like mean, standard deviation, etc. because it only accumulates
- /// the counter value.
- /// Unlike IncrementingEventCounter, this takes in a polling callback that it can call to update
- /// its own metric periodically.
- /// </summary>
- public partial class IncrementingPollingCounter : DiagnosticCounter
- {
- /// <summary>
- /// Initializes a new instance of the <see cref="IncrementingPollingCounter"/> class.
- /// IncrementingPollingCounter live as long as the EventSource that they are attached to unless they are
- /// explicitly Disposed.
- /// </summary>
- /// <param name="name">The name.</param>
- /// <param name="eventSource">The event source.</param>
- public IncrementingPollingCounter(string name, EventSource eventSource, Func<double> totalValueProvider) : base(name, eventSource)
- {
- if (totalValueProvider == null)
- throw new ArgumentNullException(nameof(totalValueProvider));
-
- _totalValueProvider = totalValueProvider;
- Publish();
- }
-
- public override string ToString() => $"IncrementingPollingCounter '{Name}' Increment {_increment}";
-
- public TimeSpan DisplayRateTimeScale { get; set; }
- private double _increment;
- private double _prevIncrement;
- private readonly Func<double> _totalValueProvider;
-
- /// <summary>
- /// Calls "_totalValueProvider" to enqueue the counter value to the queue.
- /// </summary>
- internal void UpdateMetric()
- {
- try
- {
- lock (this)
- {
- _prevIncrement = _increment;
- _increment = _totalValueProvider();
- }
- }
- catch (Exception ex)
- {
- ReportOutOfBandMessage($"ERROR: Exception during EventCounter {Name} getMetricFunction callback: " + ex.Message);
- }
- }
-
- internal override void WritePayload(float intervalSec, int pollingIntervalMillisec)
- {
- UpdateMetric();
- lock (this) // Lock the counter
- {
- IncrementingCounterPayload payload = new IncrementingCounterPayload();
- payload.Name = Name;
- payload.DisplayName = DisplayName ?? "";
- payload.DisplayRateTimeScale = (DisplayRateTimeScale == TimeSpan.Zero) ? "" : DisplayRateTimeScale.ToString("c");
- payload.IntervalSec = intervalSec;
- payload.Series = $"Interval={pollingIntervalMillisec}"; // TODO: This may need to change when we support multi-session
- payload.CounterType = "Sum";
- payload.Metadata = GetMetadataString();
- payload.Increment = _increment - _prevIncrement;
- payload.DisplayUnits = DisplayUnits ?? "";
- EventSource.Write("EventCounters", new EventSourceOptions() { Level = EventLevel.LogAlways }, new IncrementingPollingCounterPayloadType(payload));
- }
- }
- }
-
- /// <summary>
- /// This is the payload that is sent in the with EventSource.Write
- /// </summary>
- [EventData]
- internal class IncrementingPollingCounterPayloadType
- {
- public IncrementingPollingCounterPayloadType(IncrementingCounterPayload payload) { Payload = payload; }
- public IncrementingCounterPayload Payload { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/PollingCounter.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/PollingCounter.cs
deleted file mode 100644
index 3dd3d832ea9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/PollingCounter.cs
+++ /dev/null
@@ -1,86 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// PollingCounter is a variant of EventCounter - it collects and calculates similar statistics
- /// as EventCounter. PollingCounter differs from EventCounter in that it takes in a callback
- /// function to collect metrics on its own rather than the user having to call WriteMetric()
- /// every time.
- /// </summary>
- public partial class PollingCounter : DiagnosticCounter
- {
- /// <summary>
- /// Initializes a new instance of the <see cref="PollingCounter"/> class.
- /// PollingCounter live as long as the EventSource that they are attached to unless they are
- /// explicitly Disposed.
- /// </summary>
- /// <param name="name">The name.</param>
- /// <param name="eventSource">The event source.</param>
- public PollingCounter(string name, EventSource eventSource, Func<double> metricProvider) : base(name, eventSource)
- {
- if (metricProvider == null)
- throw new ArgumentNullException(nameof(metricProvider));
-
- _metricProvider = metricProvider;
- Publish();
- }
-
- public override string ToString() => $"PollingCounter '{Name}' Count 1 Mean {_lastVal.ToString("n3")}";
-
- private readonly Func<double> _metricProvider;
- private double _lastVal;
-
- internal override void WritePayload(float intervalSec, int pollingIntervalMillisec)
- {
- lock (this)
- {
- double value = 0;
- try
- {
- value = _metricProvider();
- }
- catch (Exception ex)
- {
- ReportOutOfBandMessage($"ERROR: Exception during EventCounter {Name} metricProvider callback: " + ex.Message);
- }
-
- CounterPayload payload = new CounterPayload();
- payload.Name = Name;
- payload.DisplayName = DisplayName ?? "";
- payload.Count = 1; // NOTE: These dumb-looking statistics is intentional
- payload.IntervalSec = intervalSec;
- payload.Series = $"Interval={pollingIntervalMillisec}"; // TODO: This may need to change when we support multi-session
- payload.CounterType = "Mean";
- payload.Mean = value;
- payload.Max = value;
- payload.Min = value;
- payload.Metadata = GetMetadataString();
- payload.StandardDeviation = 0;
- payload.DisplayUnits = DisplayUnits ?? "";
- _lastVal = value;
- EventSource.Write("EventCounters", new EventSourceOptions() { Level = EventLevel.LogAlways }, new PollingPayloadType(payload));
- }
- }
- }
-
- /// <summary>
- /// This is the payload that is sent in the with EventSource.Write
- /// </summary>
- [EventData]
- internal class PollingPayloadType
- {
- public PollingPayloadType(CounterPayload payload) { Payload = payload; }
- public CounterPayload Payload { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/StubEnvironment.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/StubEnvironment.cs
deleted file mode 100644
index 236e0cbbc40..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/StubEnvironment.cs
+++ /dev/null
@@ -1,376 +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 System;
-#if ES_BUILD_PCL || ES_BUILD_PN
-using System.Collections.Generic;
-#endif
-using System.Reflection;
-#if ES_BUILD_STANDALONE
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Security;
-#endif
-#if ES_BUILD_AGAINST_DOTNET_V35
-using Microsoft.Internal;
-#endif
-using Microsoft.Reflection;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing.Internal
-#else
-namespace System.Diagnostics.Tracing.Internal
-#endif
-{
- internal static class Environment
- {
- public static readonly string NewLine = System.Environment.NewLine;
-
- public static int TickCount => System.Environment.TickCount;
-
- public static string GetResourceString(string key, params object?[] args)
- {
- string? fmt = rm.GetString(key);
- if (fmt != null)
- return string.Format(fmt, args);
-
- string sargs = string.Join(", ", args);
-
- return key + " (" + sargs + ")";
- }
-
- public static string GetRuntimeResourceString(string key, params object?[] args)
- {
- return GetResourceString(key, args);
- }
-
- private static readonly System.Resources.ResourceManager rm = new System.Resources.ResourceManager("Microsoft.Diagnostics.Tracing.Messages", typeof(Environment).Assembly());
- }
-
-#if ES_BUILD_STANDALONE
- internal static class BitOperations
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static uint RotateLeft(uint value, int offset)
- => (value << offset) | (value >> (32 - offset));
-
- public static int PopCount(uint value)
- {
- const uint c1 = 0x_55555555u;
- const uint c2 = 0x_33333333u;
- const uint c3 = 0x_0F0F0F0Fu;
- const uint c4 = 0x_01010101u;
-
- value = value - ((value >> 1) & c1);
- value = (value & c2) + ((value >> 2) & c2);
- value = (((value + (value >> 4)) & c3) * c4) >> 24;
-
- return (int)value;
- }
-
- public static int TrailingZeroCount(uint value)
- {
- if (value == 0)
- return 32;
-
- int count = 0;
- while ((value & 1) == 0)
- {
- value >>= 1;
- count++;
- }
- return count;
- }
- }
-#endif
-}
-
-#if ES_BUILD_AGAINST_DOTNET_V35
-
-namespace Microsoft.Internal
-{
- using System.Text;
-
- internal static class Tuple
- {
- public static Tuple<T1> Create<T1>(T1 item1)
- {
- return new Tuple<T1>(item1);
- }
-
- public static Tuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2)
- {
- return new Tuple<T1, T2>(item1, item2);
- }
- }
-
- [Serializable]
- internal class Tuple<T1>
- {
- private readonly T1 m_Item1;
-
- public T1 Item1 { get { return m_Item1; } }
-
- public Tuple(T1 item1)
- {
- m_Item1 = item1;
- }
-
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append("(");
- sb.Append(m_Item1);
- sb.Append(")");
- return sb.ToString();
- }
-
- int Size
- {
- get
- {
- return 1;
- }
- }
- }
-
- [Serializable]
- public class Tuple<T1, T2>
- {
- private readonly T1 m_Item1;
- private readonly T2 m_Item2;
-
- public T1 Item1 { get { return m_Item1; } }
- public T2 Item2 { get { return m_Item2; } }
-
- public Tuple(T1 item1, T2 item2)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- }
-
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append("(");
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(")");
- return sb.ToString();
- }
-
- int Size
- {
- get
- {
- return 2;
- }
- }
- }
-}
-
-#endif
-
-namespace Microsoft.Reflection
-{
-#if ES_BUILD_PCL
- [Flags]
- public enum BindingFlags
- {
- DeclaredOnly = 0x02, // Only look at the members declared on the Type
- Instance = 0x04, // Include Instance members in search
- Static = 0x08, // Include Static members in search
- Public = 0x10, // Include Public members in search
- NonPublic = 0x20, // Include Non-Public members in search
- }
-
- public enum TypeCode {
- Empty = 0, // Null reference
- Object = 1, // Instance that isn't a value
- DBNull = 2, // Database null value
- Boolean = 3, // Boolean
- Char = 4, // Unicode character
- SByte = 5, // Signed 8-bit integer
- Byte = 6, // Unsigned 8-bit integer
- Int16 = 7, // Signed 16-bit integer
- UInt16 = 8, // Unsigned 16-bit integer
- Int32 = 9, // Signed 32-bit integer
- UInt32 = 10, // Unsigned 32-bit integer
- Int64 = 11, // Signed 64-bit integer
- UInt64 = 12, // Unsigned 64-bit integer
- Single = 13, // IEEE 32-bit float
- Double = 14, // IEEE 64-bit double
- Decimal = 15, // Decimal
- DateTime = 16, // DateTime
- String = 18, // Unicode character string
- }
-#endif
- internal static class ReflectionExtensions
- {
-#if (!ES_BUILD_PCL && !ES_BUILD_PN)
-
- //
- // Type extension methods
- //
- public static bool IsEnum(this Type type) { return type.IsEnum; }
- public static bool IsAbstract(this Type type) { return type.IsAbstract; }
- public static bool IsSealed(this Type type) { return type.IsSealed; }
- public static bool IsValueType(this Type type) { return type.IsValueType; }
- public static bool IsGenericType(this Type type) { return type.IsGenericType; }
- public static Type? BaseType(this Type type) { return type.BaseType; }
- public static Assembly Assembly(this Type type) { return type.Assembly; }
- public static TypeCode GetTypeCode(this Type type) { return Type.GetTypeCode(type); }
-
- public static bool ReflectionOnly(this Assembly assm) { return assm.ReflectionOnly; }
-
-#else
-
- //
- // Type extension methods
- //
- public static bool IsEnum(this Type type) { return type.GetTypeInfo().IsEnum; }
- public static bool IsAbstract(this Type type) { return type.GetTypeInfo().IsAbstract; }
- public static bool IsSealed(this Type type) { return type.GetTypeInfo().IsSealed; }
- public static bool IsValueType(this Type type) { return type.GetTypeInfo().IsValueType; }
- public static bool IsGenericType(this Type type) { return type.IsConstructedGenericType; }
- public static Type? BaseType(this Type type) { return type.GetTypeInfo().BaseType; }
- public static Assembly Assembly(this Type type) { return type.GetTypeInfo().Assembly; }
- public static IEnumerable<PropertyInfo> GetProperties(this Type type)
- {
-#if ES_BUILD_PN
- return type.GetProperties();
-#else
- return type.GetRuntimeProperties();
-#endif
- }
- public static MethodInfo? GetGetMethod(this PropertyInfo propInfo) { return propInfo.GetMethod; }
- public static Type[] GetGenericArguments(this Type type) { return type.GenericTypeArguments; }
-
- public static MethodInfo[] GetMethods(this Type type, BindingFlags flags)
- {
- // Minimal implementation to cover only the cases we need
- System.Diagnostics.Debug.Assert((flags & BindingFlags.DeclaredOnly) != 0);
- System.Diagnostics.Debug.Assert((flags & ~(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Static|BindingFlags.Public|BindingFlags.NonPublic)) == 0);
- Func<MethodInfo, bool> visFilter;
- Func<MethodInfo, bool> instFilter;
- switch (flags & (BindingFlags.Public | BindingFlags.NonPublic))
- {
- case 0: visFilter = mi => false; break;
- case BindingFlags.Public: visFilter = mi => mi.IsPublic; break;
- case BindingFlags.NonPublic: visFilter = mi => !mi.IsPublic; break;
- default: visFilter = mi => true; break;
- }
- switch (flags & (BindingFlags.Instance | BindingFlags.Static))
- {
- case 0: instFilter = mi => false; break;
- case BindingFlags.Instance: instFilter = mi => !mi.IsStatic; break;
- case BindingFlags.Static: instFilter = mi => mi.IsStatic; break;
- default: instFilter = mi => true; break;
- }
- List<MethodInfo> methodInfos = new List<MethodInfo>();
- foreach (var declaredMethod in type.GetTypeInfo().DeclaredMethods)
- {
- if (visFilter(declaredMethod) && instFilter(declaredMethod))
- methodInfos.Add(declaredMethod);
- }
- return methodInfos.ToArray();
- }
- public static FieldInfo[] GetFields(this Type type, BindingFlags flags)
- {
- // Minimal implementation to cover only the cases we need
- System.Diagnostics.Debug.Assert((flags & BindingFlags.DeclaredOnly) != 0);
- System.Diagnostics.Debug.Assert((flags & ~(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) == 0);
- Func<FieldInfo, bool> visFilter;
- Func<FieldInfo, bool> instFilter;
- switch (flags & (BindingFlags.Public | BindingFlags.NonPublic))
- {
- case 0: visFilter = fi => false; break;
- case BindingFlags.Public: visFilter = fi => fi.IsPublic; break;
- case BindingFlags.NonPublic: visFilter = fi => !fi.IsPublic; break;
- default: visFilter = fi => true; break;
- }
- switch (flags & (BindingFlags.Instance | BindingFlags.Static))
- {
- case 0: instFilter = fi => false; break;
- case BindingFlags.Instance: instFilter = fi => !fi.IsStatic; break;
- case BindingFlags.Static: instFilter = fi => fi.IsStatic; break;
- default: instFilter = fi => true; break;
- }
- List<FieldInfo> fieldInfos = new List<FieldInfo>();
- foreach (var declaredField in type.GetTypeInfo().DeclaredFields)
- {
- if (visFilter(declaredField) && instFilter(declaredField))
- fieldInfos.Add(declaredField);
- }
- return fieldInfos.ToArray();
- }
- public static Type? GetNestedType(this Type type, string nestedTypeName)
- {
- TypeInfo? ti = null;
- foreach (var nt in type.GetTypeInfo().DeclaredNestedTypes)
- {
- if (nt.Name == nestedTypeName)
- {
- ti = nt;
- break;
- }
- }
- return ti == null ? null : ti.AsType();
- }
- public static TypeCode GetTypeCode(this Type type)
- {
- if (type == typeof(bool)) return TypeCode.Boolean;
- else if (type == typeof(byte)) return TypeCode.Byte;
- else if (type == typeof(char)) return TypeCode.Char;
- else if (type == typeof(ushort)) return TypeCode.UInt16;
- else if (type == typeof(uint)) return TypeCode.UInt32;
- else if (type == typeof(ulong)) return TypeCode.UInt64;
- else if (type == typeof(sbyte)) return TypeCode.SByte;
- else if (type == typeof(short)) return TypeCode.Int16;
- else if (type == typeof(int)) return TypeCode.Int32;
- else if (type == typeof(long)) return TypeCode.Int64;
- else if (type == typeof(string)) return TypeCode.String;
- else if (type == typeof(float)) return TypeCode.Single;
- else if (type == typeof(double)) return TypeCode.Double;
- else if (type == typeof(DateTime)) return TypeCode.DateTime;
- else if (type == (typeof(decimal))) return TypeCode.Decimal;
- else return TypeCode.Object;
- }
-
- //
- // FieldInfo extension methods
- //
- public static object? GetRawConstantValue(this FieldInfo fi)
- { return fi.GetValue(null); }
-
- //
- // Assembly extension methods
- //
- public static bool ReflectionOnly(this Assembly assm)
- {
- // In PCL we can't load in reflection-only context
- return false;
- }
-
-#endif
- }
-}
-
-#if ES_BUILD_STANDALONE
-internal static partial class Interop
-{
- [SuppressUnmanagedCodeSecurityAttribute]
- internal static partial class Kernel32
- {
- [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
- internal static extern int GetCurrentThreadId();
-
- [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
- internal static extern uint GetCurrentProcessId();
- }
-
- internal static uint GetCurrentProcessId() => Kernel32.GetCurrentProcessId();
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ArrayTypeInfo.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ArrayTypeInfo.cs
deleted file mode 100644
index b9f4864089b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ArrayTypeInfo.cs
+++ /dev/null
@@ -1,66 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- internal sealed class ArrayTypeInfo : TraceLoggingTypeInfo
- {
- private readonly TraceLoggingTypeInfo elementInfo;
-
- public ArrayTypeInfo(Type type, TraceLoggingTypeInfo elementInfo)
- : base(type)
- {
- this.elementInfo = elementInfo;
- }
-
- public override void WriteMetadata(
- TraceLoggingMetadataCollector collector,
- string? name,
- EventFieldFormat format)
- {
- collector.BeginBufferedArray();
- this.elementInfo.WriteMetadata(collector, name, format);
- collector.EndBufferedArray();
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- int bookmark = collector.BeginBufferedArray();
-
- int count = 0;
- Array? array = (Array?)value.ReferenceValue;
- if (array != null)
- {
- count = array.Length;
- for (int i = 0; i < array.Length; i++)
- {
- this.elementInfo.WriteData(collector, elementInfo.PropertyValueFactory(array.GetValue(i)));
- }
- }
-
- collector.EndBufferedArray(bookmark, count);
- }
-
- public override object? GetData(object? value)
- {
- Debug.Assert(value != null, "null accepted only for some overrides");
- var array = (Array)value;
- var serializedArray = new object?[array.Length];
- for (int i = 0; i < array.Length; i++)
- {
- serializedArray[i] = this.elementInfo.GetData(array.GetValue(i));
- }
- return serializedArray;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs
deleted file mode 100644
index f87d6070050..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs
+++ /dev/null
@@ -1,129 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-using System.Threading;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: A very simple lock-free add-only dictionary.
- /// Warning: this is a copy-by-value type. Copying performs a snapshot.
- /// Accessing a readonly field always makes a copy of the field, so the
- /// GetOrAdd method will not work as expected if called on a readonly field.
- /// </summary>
- /// <typeparam name="KeyType">
- /// The type of the key, used for TryGet.
- /// </typeparam>
- /// <typeparam name="ItemType">
- /// The type of the item, used for GetOrAdd.
- /// </typeparam>
- internal struct ConcurrentSet<KeyType, ItemType>
- where ItemType : ConcurrentSetItem<KeyType, ItemType>
- {
- private ItemType[]? items;
-
- public ItemType? TryGet(KeyType key)
- {
- ItemType? item;
- ItemType[]? oldItems = this.items;
-
- if (oldItems != null)
- {
- int lo = 0;
- int hi = oldItems.Length;
- do
- {
- int i = (lo + hi) / 2;
- item = oldItems[i];
-
- int cmp = item.Compare(key);
- if (cmp == 0)
- {
- goto Done;
- }
- else if (cmp < 0)
- {
- lo = i + 1;
- }
- else
- {
- hi = i;
- }
- }
- while (lo != hi);
- }
-
- item = null;
-
- Done:
-
- return item;
- }
-
- public ItemType GetOrAdd(ItemType newItem)
- {
- ItemType item;
- ItemType[]? oldItems = this.items;
- ItemType[] newItems;
-
- Retry:
-
- if (oldItems == null)
- {
- newItems = new ItemType[] { newItem };
- }
- else
- {
- int lo = 0;
- int hi = oldItems.Length;
- do
- {
- int i = (lo + hi) / 2;
- item = oldItems[i];
-
- int cmp = item.Compare(newItem);
- if (cmp == 0)
- {
- goto Done;
- }
- else if (cmp < 0)
- {
- lo = i + 1;
- }
- else
- {
- hi = i;
- }
- }
- while (lo != hi);
-
- int oldLength = oldItems.Length;
- newItems = new ItemType[oldLength + 1];
- Array.Copy(oldItems, newItems, lo);
- newItems[lo] = newItem;
- Array.Copy(oldItems, lo, newItems, lo + 1, oldLength - lo);
- }
-
- newItems = Interlocked.CompareExchange(ref this.items, newItems, oldItems)!;
- if (oldItems != newItems)
- {
- oldItems = newItems;
- goto Retry;
- }
-
- item = newItem;
-
- Done:
-
- return item;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ConcurrentSetItem.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ConcurrentSetItem.cs
deleted file mode 100644
index 7ef078f9090..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ConcurrentSetItem.cs
+++ /dev/null
@@ -1,23 +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.
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: Abstract base class that must be inherited by items in a
- /// ConcurrentSet.
- /// </summary>
- /// <typeparam name="KeyType">Type of the set's key.</typeparam>
- /// <typeparam name="ItemType">Type of the derived class.</typeparam>
- internal abstract class ConcurrentSetItem<KeyType, ItemType>
- where ItemType : ConcurrentSetItem<KeyType, ItemType>
- {
- public abstract int Compare(ItemType other);
- public abstract int Compare(KeyType key);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/DataCollector.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/DataCollector.cs
deleted file mode 100644
index d6886b8b105..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/DataCollector.cs
+++ /dev/null
@@ -1,368 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-using Environment = Microsoft.Diagnostics.Tracing.Internal.Environment;
-#endif
-using System.Runtime.InteropServices;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: This is the implementation of the DataCollector
- /// functionality. To enable safe access to the DataCollector from
- /// untrusted code, there is one thread-local instance of this structure
- /// per thread. The instance must be Enabled before any data is written to
- /// it. The instance must be Finished before the data is passed to
- /// EventWrite. The instance must be Disabled before the arrays referenced
- /// by the pointers are freed or unpinned.
- /// </summary>
- internal unsafe struct DataCollector
- {
- [ThreadStatic]
- internal static DataCollector ThreadInstance;
-
- private byte* scratchEnd;
- private EventSource.EventData* datasEnd;
- private GCHandle* pinsEnd;
- private EventSource.EventData* datasStart;
- private byte* scratch;
- private EventSource.EventData* datas;
- private GCHandle* pins;
- private byte[]? buffer;
- private int bufferPos;
- private int bufferNesting; // We may merge many fields int a single blob. If we are doing this we increment this.
- private bool writingScalars;
-
- internal void Enable(
- byte* scratch,
- int scratchSize,
- EventSource.EventData* datas,
- int dataCount,
- GCHandle* pins,
- int pinCount)
- {
- this.datasStart = datas;
- this.scratchEnd = scratch + scratchSize;
- this.datasEnd = datas + dataCount;
- this.pinsEnd = pins + pinCount;
- this.scratch = scratch;
- this.datas = datas;
- this.pins = pins;
- this.writingScalars = false;
- }
-
- internal void Disable()
- {
- this = default;
- }
-
- /// <summary>
- /// Completes the list of scalars. Finish must be called before the data
- /// descriptor array is passed to EventWrite.
- /// </summary>
- /// <returns>
- /// A pointer to the next unused data descriptor, or datasEnd if they were
- /// all used. (Descriptors may be unused if a string or array was null.)
- /// </returns>
- internal EventSource.EventData* Finish()
- {
- this.ScalarsEnd();
- return this.datas;
- }
-
- internal void AddScalar(void* value, int size)
- {
- var pb = (byte*)value;
- if (this.bufferNesting == 0)
- {
- byte* scratchOld = this.scratch;
- byte* scratchNew = scratchOld + size;
- if (this.scratchEnd < scratchNew)
- {
- throw new IndexOutOfRangeException(SR.EventSource_AddScalarOutOfRange);
- }
-
- this.ScalarsBegin();
- this.scratch = scratchNew;
-
- for (int i = 0; i != size; i++)
- {
- scratchOld[i] = pb[i];
- }
- }
- else
- {
- int oldPos = this.bufferPos;
- this.bufferPos = checked(this.bufferPos + size);
- this.EnsureBuffer();
- Debug.Assert(buffer != null);
-
- for (int i = 0; i != size; i++, oldPos++)
- {
- this.buffer[oldPos] = pb[i];
- }
- }
- }
-
- internal void AddBinary(string? value, int size)
- {
- if (size > ushort.MaxValue)
- {
- size = ushort.MaxValue - 1;
- }
-
- if (this.bufferNesting != 0)
- {
- this.EnsureBuffer(size + 2);
- }
-
- this.AddScalar(&size, 2);
-
- if (size != 0)
- {
- if (this.bufferNesting == 0)
- {
- this.ScalarsEnd();
- this.PinArray(value, size);
- }
- else
- {
- int oldPos = this.bufferPos;
- this.bufferPos = checked(this.bufferPos + size);
- this.EnsureBuffer();
- Debug.Assert(buffer != null);
-
- fixed (void* p = value)
- {
- Marshal.Copy((IntPtr)p, buffer, oldPos, size);
- }
- }
- }
- }
-
- internal void AddNullTerminatedString(string? value)
- {
- // Treat null strings as empty strings.
- if (value == null)
- {
- value = string.Empty;
- }
-
- // Calculate the size of the string including the trailing NULL char.
- // Don't use value.Length here because string allows for embedded NULL characters.
- int nullCharIndex = value.IndexOf((char)0);
- if (nullCharIndex < 0)
- {
- nullCharIndex = value.Length;
- }
- int size = (nullCharIndex + 1) * 2;
-
- if (this.bufferNesting != 0)
- {
- this.EnsureBuffer(size);
- }
-
- if (this.bufferNesting == 0)
- {
- this.ScalarsEnd();
- this.PinArray(value, size);
- }
- else
- {
- int oldPos = this.bufferPos;
- this.bufferPos = checked(this.bufferPos + size);
- this.EnsureBuffer();
- Debug.Assert(buffer != null);
-
- fixed (void* p = value)
- {
- Marshal.Copy((IntPtr)p, buffer, oldPos, size);
- }
- }
- }
-
- internal void AddBinary(Array value, int size)
- {
- this.AddArray(value, size, 1);
- }
-
- internal void AddArray(Array? value, int length, int itemSize)
- {
- if (length > ushort.MaxValue)
- {
- length = ushort.MaxValue;
- }
-
- int size = length * itemSize;
- if (this.bufferNesting != 0)
- {
- this.EnsureBuffer(size + 2);
- }
-
- this.AddScalar(&length, 2);
-
- if (length != 0)
- {
- if (this.bufferNesting == 0)
- {
- this.ScalarsEnd();
- this.PinArray(value, size);
- }
- else
- {
- int oldPos = this.bufferPos;
- this.bufferPos = checked(this.bufferPos + size);
- this.EnsureBuffer();
- Debug.Assert(value != null && buffer != null);
- Buffer.BlockCopy(value, 0, this.buffer, oldPos, size);
- }
- }
- }
-
- /// <summary>
- /// Marks the start of a non-blittable array or enumerable.
- /// </summary>
- /// <returns>Bookmark to be passed to EndBufferedArray.</returns>
- internal int BeginBufferedArray()
- {
- this.BeginBuffered();
- this.bufferPos += 2; // Reserve space for the array length (filled in by EndEnumerable)
- return this.bufferPos;
- }
-
- /// <summary>
- /// Marks the end of a non-blittable array or enumerable.
- /// </summary>
- /// <param name="bookmark">The value returned by BeginBufferedArray.</param>
- /// <param name="count">The number of items in the array.</param>
- internal void EndBufferedArray(int bookmark, int count)
- {
- this.EnsureBuffer();
- Debug.Assert(buffer != null);
- this.buffer[bookmark - 2] = unchecked((byte)count);
- this.buffer[bookmark - 1] = unchecked((byte)(count >> 8));
- this.EndBuffered();
- }
-
- /// <summary>
- /// Marks the start of dynamically-buffered data.
- /// </summary>
- internal void BeginBuffered()
- {
- this.ScalarsEnd();
- this.bufferNesting++;
- }
-
- /// <summary>
- /// Marks the end of dynamically-buffered data.
- /// </summary>
- internal void EndBuffered()
- {
- this.bufferNesting--;
-
- if (this.bufferNesting == 0)
- {
- /*
- TODO (perf): consider coalescing adjacent buffered regions into a
- single buffer, similar to what we're already doing for adjacent
- scalars. In addition, if a type contains a buffered region adjacent
- to a blittable array, and the blittable array is small, it would be
- more efficient to buffer the array instead of pinning it.
- */
-
- this.EnsureBuffer();
- Debug.Assert(buffer != null);
- this.PinArray(this.buffer, this.bufferPos);
- this.buffer = null;
- this.bufferPos = 0;
- }
- }
-
- private void EnsureBuffer()
- {
- int required = this.bufferPos;
- if (this.buffer == null || this.buffer.Length < required)
- {
- this.GrowBuffer(required);
- }
- }
-
- private void EnsureBuffer(int additionalSize)
- {
- int required = this.bufferPos + additionalSize;
- if (this.buffer == null || this.buffer.Length < required)
- {
- this.GrowBuffer(required);
- }
- }
-
- private void GrowBuffer(int required)
- {
- int newSize = this.buffer == null ? 64 : this.buffer.Length;
-
- do
- {
- newSize *= 2;
- }
- while (newSize < required);
-
- Array.Resize(ref this.buffer, newSize);
- }
-
- private void PinArray(object? value, int size)
- {
- GCHandle* pinsTemp = this.pins;
- if (this.pinsEnd <= pinsTemp)
- {
- throw new IndexOutOfRangeException(SR.EventSource_PinArrayOutOfRange);
- }
-
- EventSource.EventData* datasTemp = this.datas;
- if (this.datasEnd <= datasTemp)
- {
- throw new IndexOutOfRangeException(SR.EventSource_DataDescriptorsOutOfRange);
- }
-
- this.pins = pinsTemp + 1;
- this.datas = datasTemp + 1;
-
- *pinsTemp = GCHandle.Alloc(value, GCHandleType.Pinned);
- datasTemp->DataPointer = pinsTemp->AddrOfPinnedObject();
- datasTemp->m_Size = size;
- }
-
- private void ScalarsBegin()
- {
- if (!this.writingScalars)
- {
- EventSource.EventData* datasTemp = this.datas;
- if (this.datasEnd <= datasTemp)
- {
- throw new IndexOutOfRangeException(SR.EventSource_DataDescriptorsOutOfRange);
- }
-
- datasTemp->DataPointer = (IntPtr)this.scratch;
- this.writingScalars = true;
- }
- }
-
- private void ScalarsEnd()
- {
- if (this.writingScalars)
- {
- EventSource.EventData* datasTemp = this.datas;
- datasTemp->m_Size = checked((int)(this.scratch - (byte*)datasTemp->m_Ptr));
- this.datas = datasTemp + 1;
- this.writingScalars = false;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EmptyStruct.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EmptyStruct.cs
deleted file mode 100644
index bc7fb8c3462..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EmptyStruct.cs
+++ /dev/null
@@ -1,17 +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.
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: Empty struct indicating no payload data.
- /// </summary>
- internal struct EmptyStruct
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EnumHelper.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EnumHelper.cs
deleted file mode 100644
index 33c085dcd17..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EnumHelper.cs
+++ /dev/null
@@ -1,31 +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.
-
-#if EVENTSOURCE_GENERICS
-?using System;
-using System.Reflection;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Provides support for casting enums to their underlying type
- /// from within generic context.
- /// </summary>
- /// <typeparam name="UnderlyingType">
- /// The underlying type of the enum.
- /// </typeparam>
- internal static class EnumHelper<UnderlyingType>
- {
- public static UnderlyingType Cast<ValueType>(ValueType value)
- {
- return (UnderlyingType)(object)value;
- }
- }
-
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EnumerableTypeInfo.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EnumerableTypeInfo.cs
deleted file mode 100644
index 92a1a823f94..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EnumerableTypeInfo.cs
+++ /dev/null
@@ -1,68 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-using System.Collections;
-using System.Collections.Generic;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- internal sealed class EnumerableTypeInfo : TraceLoggingTypeInfo
- {
- private readonly TraceLoggingTypeInfo elementInfo;
-
- public EnumerableTypeInfo(Type type, TraceLoggingTypeInfo elementInfo)
- : base(type)
- {
- this.elementInfo = elementInfo;
- }
-
- public override void WriteMetadata(
- TraceLoggingMetadataCollector collector,
- string? name,
- EventFieldFormat format)
- {
- collector.BeginBufferedArray();
- this.elementInfo.WriteMetadata(collector, name, format);
- collector.EndBufferedArray();
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- int bookmark = collector.BeginBufferedArray();
-
- int count = 0;
- IEnumerable? enumerable = (IEnumerable?)value.ReferenceValue;
- if (enumerable != null)
- {
- foreach (object? element in enumerable)
- {
- this.elementInfo.WriteData(collector, elementInfo.PropertyValueFactory(element));
- count++;
- }
- }
-
- collector.EndBufferedArray(bookmark, count);
- }
-
- public override object? GetData(object? value)
- {
- Debug.Assert(value != null, "null accepted only for some overrides");
- var iterType = (IEnumerable)value;
- List<object?> serializedEnumerable = new List<object?>();
- foreach (object? element in iterType)
- {
- serializedEnumerable.Add(elementInfo.GetData(element));
- }
- return serializedEnumerable.ToArray();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventDataAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventDataAttribute.cs
deleted file mode 100644
index cd88c81c3dc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventDataAttribute.cs
+++ /dev/null
@@ -1,148 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Used when authoring types that will be passed to EventSource.Write.
- /// EventSource.Write&lt;T> only works when T is either an anonymous type
- /// or a type with an [EventData] attribute. In addition, the properties
- /// of T must be supported property types. Supported property types include
- /// simple built-in types (int, string, Guid, DateTime, DateTimeOffset,
- /// KeyValuePair, etc.), anonymous types that only contain supported types,
- /// types with an [EventData] attribute, arrays of the above, and IEnumerable
- /// of the above.
- /// </summary>
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
- public class EventDataAttribute
- : Attribute
- {
- private EventLevel level = (EventLevel)(-1);
- private EventOpcode opcode = (EventOpcode)(-1);
-
- /// <summary>
- /// Gets or sets the name to use if this type is used for an
- /// implicitly-named event or an implicitly-named property.
- ///
- /// Example 1:
- ///
- /// EventSource.Write(null, new T()); // implicitly-named event
- ///
- /// The name of the event will be determined as follows:
- ///
- /// if (T has an EventData attribute and attribute.Name != null)
- /// eventName = attribute.Name;
- /// else
- /// eventName = typeof(T).Name;
- ///
- /// Example 2:
- ///
- /// EventSource.Write(name, new { _1 = new T() }); // implicitly-named field
- ///
- /// The name of the field will be determined as follows:
- ///
- /// if (T has an EventData attribute and attribute.Name != null)
- /// fieldName = attribute.Name;
- /// else
- /// fieldName = typeof(T).Name;
- /// </summary>
- public string? Name
- {
- get;
- set;
- }
-
- /// <summary>
- /// Gets or sets the level to use for the event.
- /// Invalid levels (outside the range 0..255) are treated as unset.
- /// Note that the Level attribute can bubble-up, i.e. if a type contains
- /// a sub-object (a field or property), and the sub-object's type has a
- /// TraceLoggingEvent attribute, the Level from the sub-object's attribute
- /// can affect the event's level.
- ///
- /// Example: for EventSource.Write(name, options, data), the level of the
- /// event will be determined as follows:
- ///
- /// if (options.Level has been set)
- /// eventLevel = options.Level;
- /// else if (data.GetType() has a TraceLoggingEvent attribute and attribute.Level has been set)
- /// eventLevel = attribute.Level;
- /// else if (a field/property contained in data has a TraceLoggingEvent attribute and attribute.Level has been set)
- /// eventLevel = attribute.Level;
- /// else
- /// eventLevel = EventLevel.LogAlways;
- /// </summary>
- internal EventLevel Level
- {
- get => this.level;
- set => this.level = value;
- }
-
- /// <summary>
- /// Gets or sets the opcode to use for the event.
- /// Invalid opcodes (outside the range 0..255) are treated as unset.
- /// Note that the Opcode attribute can bubble-up, i.e. if a type contains
- /// a sub-object (a field or property), and the sub-object's type has a
- /// TraceLoggingEvent attribute, the Opcode from the sub-object's attribute
- /// can affect the event's opcode.
- ///
- /// Example: for EventSource.Write(name, options, data), the opcode of the
- /// event will be determined as follows:
- ///
- /// if (options.Opcode has been set)
- /// eventOpcode = options.Opcode;
- /// else if (data.GetType() has a TraceLoggingEvent attribute and attribute.Opcode has been set)
- /// eventOpcode = attribute.Opcode;
- /// else if (a field/property contained in data has a TraceLoggingEvent attribute and attribute.Opcode has been set)
- /// eventOpcode = attribute.Opcode;
- /// else
- /// eventOpcode = EventOpcode.Info;
- /// </summary>
- internal EventOpcode Opcode
- {
- get => this.opcode;
- set => this.opcode = value;
- }
-
- /// <summary>
- /// Gets or sets the keywords to use for the event.
- /// Note that the Keywords attribute can bubble-up, i.e. if a type contains
- /// a sub-object (a field or property), and the sub-object's type has a
- /// TraceLoggingEvent attribute, the Keywords from the sub-object's attribute
- /// can affect the event's keywords.
- ///
- /// Example: for EventSource.Write(name, options, data), the keywords of the
- /// event will be determined as follows:
- ///
- /// eventKeywords = options.Keywords;
- /// if (data.GetType() has a TraceLoggingEvent attribute)
- /// eventKeywords |= attribute.Keywords;
- /// if (a field/property contained in data has a TraceLoggingEvent attribute)
- /// eventKeywords |= attribute.Keywords;
- /// </summary>
- internal EventKeywords Keywords
- {
- get;
- set;
- }
-
- /// <summary>
- /// Gets or sets the flags for an event. These flags are ignored by ETW,
- /// but can have meaning to the event consumer.
- /// </summary>
- internal EventTags Tags
- {
- get;
- set;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventFieldAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventFieldAttribute.cs
deleted file mode 100644
index cad4a9a0683..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventFieldAttribute.cs
+++ /dev/null
@@ -1,78 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Tags are flags that are not interpreted by EventSource but are passed along
- /// to the EventListener. The EventListener determines the semantics of the flags.
- /// </summary>
- [Flags]
- public enum EventFieldTags
- {
- /// <summary>
- /// No special traits are added to the field.
- /// </summary>
- None = 0,
-
- /* Bits below 0x10000 are available for any use by the provider. */
- /* Bits at or above 0x10000 are reserved for definition by Microsoft. */
- }
-
- /// <summary>
- /// TraceLogging: used when authoring types that will be passed to EventSource.Write.
- /// Controls how a field or property is handled when it is written as a
- /// field in a TraceLogging event. Apply this attribute to a field or
- /// property if the default handling is not correct. (Apply the
- /// TraceLoggingIgnore attribute if the property should not be
- /// included as a field in the event.)
- /// The default for Name is null, which means that the name of the
- /// underlying field or property will be used as the event field's name.
- /// The default for PiiTag is 0, which means that the event field does not
- /// contain personally-identifiable information.
- /// </summary>
- [AttributeUsage(AttributeTargets.Property)]
- public class EventFieldAttribute
- : Attribute
- {
- /// <summary>
- /// User defined options for the field. These are not interpreted by the EventSource
- /// but are available to the Listener. See EventFieldSettings for details
- /// </summary>
- public EventFieldTags Tags
- {
- get;
- set;
- }
-
- /// <summary>
- /// Gets or sets the name to use for the field. This defaults to null.
- /// If null, the name of the corresponding property will be used
- /// as the event field's name.
- /// TODO REMOVE
- /// </summary>
- internal string? Name
- {
- get;
- set;
- }
-
- /// <summary>
- /// Gets or sets a field formatting hint.
- /// </summary>
- public EventFieldFormat Format
- {
- get;
- set;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventFieldFormat.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventFieldFormat.cs
deleted file mode 100644
index 20672e68aa9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventFieldFormat.cs
+++ /dev/null
@@ -1,130 +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.
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Provides a hint that may be used by an event listener when formatting
- /// an event field for display. Note that the event listener may ignore the
- /// hint if it does not recognize a particular combination of type and format.
- /// Similar to TDH_OUTTYPE.
- /// </summary>
- public enum EventFieldFormat
- {
- /// <summary>
- /// Field receives default formatting based on the field's underlying type.
- /// </summary>
- Default = 0,
-#if false
- /// <summary>
- /// Field should not be displayed.
- /// </summary>
- NoPrint = 1,
-#endif
- /// <summary>
- /// Field should be formatted as character or string data.
- /// Typically applied to 8-bit or 16-bit integers.
- /// This is the default format for String and Char types.
- /// </summary>
- String = 2,
-
- /// <summary>
- /// Field should be formatted as boolean data. Typically applied to 8-bit
- /// or 32-bit integers. This is the default format for the Boolean type.
- /// </summary>
- Boolean = 3,
-
- /// <summary>
- /// Field should be formatted as hexadecimal data. Typically applied to
- /// integer types.
- /// </summary>
- Hexadecimal = 4,
-
-#if false
- /// <summary>
- /// Field should be formatted as a process identifier. Typically applied to
- /// 32-bit integer types.
- /// </summary>
- ProcessId = 5,
-
- /// <summary>
- /// Field should be formatted as a thread identifier. Typically applied to
- /// 32-bit integer types.
- /// </summary>
- ThreadId = 6,
-
- /// <summary>
- /// Field should be formatted as an Internet port. Typically applied to 16-bit integer
- /// types.
- /// </summary>
- Port = 7,
- /// <summary>
- /// Field should be formatted as an Internet Protocol v4 address. Typically applied to
- /// 32-bit integer types.
- /// </summary>
- Ipv4Address = 8,
-
- /// <summary>
- /// Field should be formatted as an Internet Protocol v6 address. Typically applied to
- /// byte[] types.
- /// </summary>
- Ipv6Address = 9,
- /// <summary>
- /// Field should be formatted as a SOCKADDR. Typically applied to byte[] types.
- /// </summary>
- SocketAddress = 10,
-#endif
- /// <summary>
- /// Field should be formatted as XML string data. Typically applied to
- /// strings or arrays of 8-bit or 16-bit integers.
- /// </summary>
- Xml = 11,
-
- /// <summary>
- /// Field should be formatted as JSON string data. Typically applied to
- /// strings or arrays of 8-bit or 16-bit integers.
- /// </summary>
- Json = 12,
-#if false
- /// <summary>
- /// Field should be formatted as a Win32 error code. Typically applied to
- /// 32-bit integer types.
- /// </summary>
- Win32Error = 13,
-
- /// <summary>
- /// Field should be formatted as an NTSTATUS code. Typically applied to
- /// 32-bit integer types.
- /// </summary>
- NTStatus = 14,
-#endif
- /// <summary>
- /// Field should be formatted as an HRESULT code. Typically applied to
- /// 32-bit integer types.
- /// </summary>
- HResult = 15,
-#if false
- /// <summary>
- /// Field should be formatted as a FILETIME. Typically applied to 64-bit
- /// integer types. This is the default format for DateTime types.
- /// </summary>
- FileTime = 16,
- /// <summary>
- /// When applied to a numeric type, indicates that the type should be formatted
- /// as a signed integer. This is the default format for signed integer types.
- /// </summary>
- Signed = 17,
-
- /// <summary>
- /// When applied to a numeric type, indicates that the type should be formatted
- /// as an unsigned integer. This is the default format for unsigned integer types.
- /// </summary>
- Unsigned = 18,
-#endif
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventIgnoreAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventIgnoreAttribute.cs
deleted file mode 100644
index 81411ebe2d3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventIgnoreAttribute.cs
+++ /dev/null
@@ -1,27 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Used when authoring types that will be passed to EventSource.Write.
- /// By default, EventSource.Write will write all of an object's public
- /// properties to the event payload. Apply [EventIgnore] to a public
- /// property to prevent EventSource.Write from including the property in
- /// the event.
- /// </summary>
- [AttributeUsage(AttributeTargets.Property)]
- public class EventIgnoreAttribute
- : Attribute
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventPayload.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventPayload.cs
deleted file mode 100644
index b177a7526d3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventPayload.cs
+++ /dev/null
@@ -1,150 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// EventPayload class holds the list of parameters and their corresponding values for user defined types passed to
- /// EventSource APIs.
- /// Preserving the order of the elements as they were found inside user defined types is the most important characteristic of this class.
- /// </summary>
- internal class EventPayload : IDictionary<string, object?>
- {
- internal EventPayload(List<string> payloadNames, List<object?> payloadValues)
- {
- Debug.Assert(payloadNames.Count == payloadValues.Count);
-
- m_names = payloadNames;
- m_values = payloadValues;
- }
-
- public ICollection<string> Keys => m_names;
- public ICollection<object?> Values => m_values;
-
- public object? this[string key]
- {
- get
- {
- if (key == null)
- throw new System.ArgumentNullException(nameof(key));
-
- int position = 0;
- foreach (string name in m_names)
- {
- if (name == key)
- {
- return m_values[position];
- }
- position++;
- }
-
- throw new System.Collections.Generic.KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key));
- }
- set => throw new System.NotSupportedException();
- }
-
- public void Add(string key, object? value)
- {
- throw new System.NotSupportedException();
- }
-
- public void Add(KeyValuePair<string, object?> payloadEntry)
- {
- throw new System.NotSupportedException();
- }
-
- public void Clear()
- {
- throw new System.NotSupportedException();
- }
-
- public bool Contains(KeyValuePair<string, object?> entry)
- {
- return ContainsKey(entry.Key);
- }
-
- public bool ContainsKey(string key)
- {
- if (key == null)
- throw new System.ArgumentNullException(nameof(key));
-
- foreach (string item in m_names)
- {
- if (item == key)
- return true;
- }
- return false;
- }
-
- public int Count => m_names.Count;
-
- public bool IsReadOnly => true;
-
- public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
- {
- for (int i = 0; i < Keys.Count; i++)
- {
- yield return new KeyValuePair<string, object?>(this.m_names[i], this.m_values[i]);
- }
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- var instance = this as IEnumerable<KeyValuePair<string, object?>>;
- return instance.GetEnumerator();
- }
-
- public void CopyTo(KeyValuePair<string, object?>[] payloadEntries, int count)
- {
- throw new System.NotSupportedException();
- }
-
- public bool Remove(string key)
- {
- throw new System.NotSupportedException();
- }
-
- public bool Remove(KeyValuePair<string, object?> entry)
- {
- throw new System.NotSupportedException();
- }
-
- public bool TryGetValue(string key, [MaybeNullWhen(false)] out object? value)
- {
- if (key == null)
- throw new System.ArgumentNullException(nameof(key));
-
- int position = 0;
- foreach (string name in m_names)
- {
- if (name == key)
- {
- value = m_values[position];
- return true;
- }
- position++;
- }
-
- value = default;
- return false;
- }
-
-#region private
- private readonly List<string> m_names;
- private readonly List<object?> m_values;
-#endregion
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventSourceActivity.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventSourceActivity.cs
deleted file mode 100644
index 25c8563346a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventSourceActivity.cs
+++ /dev/null
@@ -1,314 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Provides support for EventSource activities by marking the start and
- /// end of a particular operation.
- /// </summary>
- internal sealed class EventSourceActivity
- : IDisposable
- {
- /// <summary>
- /// Initializes a new instance of the EventSourceActivity class that
- /// is attached to the specified event source. The new activity will
- /// not be attached to any related (parent) activity.
- /// The activity is created in the Initialized state.
- /// </summary>
- /// <param name="eventSource">
- /// The event source to which the activity information is written.
- /// </param>
- public EventSourceActivity(EventSource eventSource)
- {
- if (eventSource == null)
- throw new ArgumentNullException(nameof(eventSource));
-
- this.eventSource = eventSource;
- }
-
- /// <summary>
- /// You can make an activity out of just an EventSource.
- /// </summary>
- public static implicit operator EventSourceActivity(EventSource eventSource) =>
- new EventSourceActivity(eventSource);
-
- /* Properties */
- /// <summary>
- /// Gets the event source to which this activity writes events.
- /// </summary>
- public EventSource EventSource => this.eventSource;
-
- /// <summary>
- /// Gets this activity's unique identifier, or the default Guid if the
- /// event source was disabled when the activity was initialized.
- /// </summary>
- public Guid Id => this.activityId;
-
-#if false // don't expose RelatedActivityId unless there is a need.
- /// <summary>
- /// Gets the unique identifier of this activity's related (parent)
- /// activity.
- /// </summary>
- public Guid RelatedId
- {
- get { return this.relatedActivityId; }
- }
-#endif
-
- /// <summary>
- /// Writes a Start event with the specified name and data. If the start event is not active (because the provider
- /// is not on or keyword-level indicates the event is off, then the returned activity is simply the 'this' pointer
- /// and it is effectively like start did not get called.
- ///
- /// A new activityID GUID is generated and the returned
- /// EventSourceActivity remembers this activity and will mark every event (including the start stop and any writes)
- /// with this activityID. In addition the Start activity will log a 'relatedActivityID' that was the activity
- /// ID before the start event. This way event processors can form a linked list of all the activities that
- /// caused this one (directly or indirectly).
- /// </summary>
- /// <param name="eventName">
- /// The name to use for the event. It is strongly suggested that this name end in 'Start' (e.g. DownloadStart).
- /// If you do this, then the Stop() method will automatically replace the 'Start' suffix with a 'Stop' suffix.
- /// </param>
- /// <param name="options">Allow options (keywords, level) to be set for the write associated with this start
- /// These will also be used for the stop event.</param>
- /// <param name="data">The data to include in the event.</param>
- public EventSourceActivity Start<T>(string? eventName, EventSourceOptions options, T data)
- {
- return this.Start(eventName, ref options, ref data);
- }
- /// <summary>
- /// Shortcut version see Start(string eventName, EventSourceOptions options, T data) Options is empty (no keywords
- /// and level==Info) Data payload is empty.
- /// </summary>
- public EventSourceActivity Start(string? eventName)
- {
- EventSourceOptions options = default;
- EmptyStruct data = default;
- return this.Start(eventName, ref options, ref data);
- }
- /// <summary>
- /// Shortcut version see Start(string eventName, EventSourceOptions options, T data). Data payload is empty.
- /// </summary>
- public EventSourceActivity Start(string? eventName, EventSourceOptions options)
- {
- EmptyStruct data = default;
- return this.Start(eventName, ref options, ref data);
- }
- /// <summary>
- /// Shortcut version see Start(string eventName, EventSourceOptions options, T data) Options is empty (no keywords
- /// and level==Info)
- /// </summary>
- public EventSourceActivity Start<T>(string? eventName, T data)
- {
- EventSourceOptions options = default;
- return this.Start(eventName, ref options, ref data);
- }
-
- /// <summary>
- /// Writes a Stop event with the specified data, and sets the activity
- /// to the Stopped state. The name is determined by the eventName used in Start.
- /// If that Start event name is suffixed with 'Start' that is removed, and regardless
- /// 'Stop' is appended to the result to form the Stop event name.
- /// May only be called when the activity is in the Started state.
- /// </summary>
- /// <param name="data">The data to include in the event.</param>
- public void Stop<T>(T data)
- {
- this.Stop(null, ref data);
- }
- /// <summary>
- /// Used if you wish to use the non-default stop name (which is the start name with Start replace with 'Stop')
- /// This can be useful to indicate unusual ways of stopping (but it is still STRONGLY recommended that
- /// you start with the same prefix used for the start event and you end with the 'Stop' suffix.
- /// </summary>
- public void Stop<T>(string? eventName)
- {
- EmptyStruct data = default;
- this.Stop(eventName, ref data);
- }
- /// <summary>
- /// Used if you wish to use the non-default stop name (which is the start name with Start replace with 'Stop')
- /// This can be useful to indicate unusual ways of stopping (but it is still STRONGLY recommended that
- /// you start with the same prefix used for the start event and you end with the 'Stop' suffix.
- /// </summary>
- public void Stop<T>(string? eventName, T data)
- {
- this.Stop(eventName, ref data);
- }
-
- /// <summary>
- /// Writes an event associated with this activity to the eventSource associated with this activity.
- /// May only be called when the activity is in the Started state.
- /// </summary>
- /// <param name="eventName">
- /// The name to use for the event. If null, the name is determined from
- /// data's type.
- /// </param>
- /// <param name="options">
- /// The options to use for the event.
- /// </param>
- /// <param name="data">The data to include in the event.</param>
- public void Write<T>(string? eventName, EventSourceOptions options, T data)
- {
- this.Write(this.eventSource, eventName, ref options, ref data);
- }
- /// <summary>
- /// Writes an event associated with this activity.
- /// May only be called when the activity is in the Started state.
- /// </summary>
- /// <param name="eventName">
- /// The name to use for the event. If null, the name is determined from
- /// data's type.
- /// </param>
- /// <param name="data">The data to include in the event.</param>
- public void Write<T>(string? eventName, T data)
- {
- EventSourceOptions options = default;
- this.Write(this.eventSource, eventName, ref options, ref data);
- }
- /// <summary>
- /// Writes a trivial event associated with this activity.
- /// May only be called when the activity is in the Started state.
- /// </summary>
- /// <param name="eventName">
- /// The name to use for the event. Must not be null.
- /// </param>
- /// <param name="options">
- /// The options to use for the event.
- /// </param>
- public void Write(string? eventName, EventSourceOptions options)
- {
- EmptyStruct data = default;
- this.Write(this.eventSource, eventName, ref options, ref data);
- }
- /// <summary>
- /// Writes a trivial event associated with this activity.
- /// May only be called when the activity is in the Started state.
- /// </summary>
- /// <param name="eventName">
- /// The name to use for the event. Must not be null.
- /// </param>
- public void Write(string? eventName)
- {
- EventSourceOptions options = default;
- EmptyStruct data = default;
- this.Write(this.eventSource, eventName, ref options, ref data);
- }
- /// <summary>
- /// Writes an event to a arbitrary eventSource stamped with the activity ID of this activity.
- /// </summary>
- public void Write<T>(EventSource source, string? eventName, EventSourceOptions options, T data)
- {
- this.Write(source, eventName, ref options, ref data);
- }
-
- /// <summary>
- /// Releases any unmanaged resources associated with this object.
- /// If the activity is in the Started state, calls Stop().
- /// </summary>
- public void Dispose()
- {
- if (this.state == State.Started)
- {
- EmptyStruct data = default;
- this.Stop(null, ref data);
- }
- }
-
-#region private
- private EventSourceActivity Start<T>(string? eventName, ref EventSourceOptions options, ref T data)
- {
- if (this.state != State.Started)
- throw new InvalidOperationException();
-
- // If the source is not on at all, then we don't need to do anything and we can simply return ourselves.
- if (!this.eventSource.IsEnabled())
- return this;
-
- var newActivity = new EventSourceActivity(eventSource);
- if (!this.eventSource.IsEnabled(options.Level, options.Keywords))
- {
- // newActivity.relatedActivityId = this.Id;
- Guid relatedActivityId = this.Id;
- newActivity.activityId = Guid.NewGuid();
- newActivity.startStopOptions = options;
- newActivity.eventName = eventName;
- newActivity.startStopOptions.Opcode = EventOpcode.Start;
- this.eventSource.Write(eventName, ref newActivity.startStopOptions, ref newActivity.activityId, ref relatedActivityId, ref data);
- }
- else
- {
- // If we are not active, we don't set the eventName, which basically also turns off the Stop event as well.
- newActivity.activityId = this.Id;
- }
-
- return newActivity;
- }
-
- private void Write<T>(EventSource eventSource, string? eventName, ref EventSourceOptions options, ref T data)
- {
- if (this.state != State.Started)
- throw new InvalidOperationException(); // Write after stop.
- if (eventName == null)
- throw new ArgumentNullException();
-
- eventSource.Write(eventName, ref options, ref this.activityId, ref s_empty, ref data);
- }
-
- private void Stop<T>(string? eventName, ref T data)
- {
- if (this.state != State.Started)
- throw new InvalidOperationException();
-
- // If start was not fired, then stop isn't as well.
- if (!StartEventWasFired)
- return;
-
- Debug.Assert(this.eventName != null);
-
- this.state = State.Stopped;
- if (eventName == null)
- {
- eventName = this.eventName;
- if (eventName.EndsWith("Start"))
- eventName = eventName.Substring(0, eventName.Length - 5);
- eventName += "Stop";
- }
- this.startStopOptions.Opcode = EventOpcode.Stop;
- this.eventSource.Write(eventName, ref this.startStopOptions, ref this.activityId, ref s_empty, ref data);
- }
-
- private enum State
- {
- Started,
- Stopped
- }
-
- /// <summary>
- /// If eventName is non-null then we logged a start event
- /// </summary>
- private bool StartEventWasFired => eventName != null;
-
- private readonly EventSource eventSource;
- private EventSourceOptions startStopOptions;
- internal Guid activityId;
- // internal Guid relatedActivityId;
- private State state;
- private string? eventName;
-
- internal static Guid s_empty;
-#endregion
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs
deleted file mode 100644
index c6b675a420a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/EventSourceOptions.cs
+++ /dev/null
@@ -1,107 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Used when calling EventSource.Write.
- /// Optional overrides for event settings such as Level, Keywords, or Opcode.
- /// If overrides are not provided for a setting, default values will be used.
- /// </summary>
- public struct EventSourceOptions
- {
- internal EventKeywords keywords;
- internal EventTags tags;
- internal EventActivityOptions activityOptions;
- internal byte level;
- internal byte opcode;
- internal byte valuesSet;
-
- internal const byte keywordsSet = 0x1;
- internal const byte tagsSet = 0x2;
- internal const byte levelSet = 0x4;
- internal const byte opcodeSet = 0x8;
- internal const byte activityOptionsSet = 0x10;
-
- /// <summary>
- /// Gets or sets the level to use for the specified event. If this property
- /// is unset, the event's level will be 5 (Verbose).
- /// </summary>
- public EventLevel Level
- {
- get => (EventLevel)this.level;
- set
- {
- this.level = checked((byte)value);
- this.valuesSet |= levelSet;
- }
- }
-
- /// <summary>
- /// Gets or sets the opcode to use for the specified event. If this property
- /// is unset, the event's opcode will 0 (Info).
- /// </summary>
- public EventOpcode Opcode
- {
- get => (EventOpcode)this.opcode;
- set
- {
- this.opcode = checked((byte)value);
- this.valuesSet |= opcodeSet;
- }
- }
-
- internal bool IsOpcodeSet => (this.valuesSet & opcodeSet) != 0;
-
- /// <summary>
- /// Gets or sets the keywords to use for the specified event. If this
- /// property is unset, the event's keywords will be 0.
- /// </summary>
- public EventKeywords Keywords
- {
- get => this.keywords;
- set
- {
- this.keywords = value;
- this.valuesSet |= keywordsSet;
- }
- }
-
- /// <summary>
- /// Gets or sets the tags to use for the specified event. If this property is
- /// unset, the event's tags will be 0.
- /// </summary>
- public EventTags Tags
- {
- get => this.tags;
- set
- {
- this.tags = value;
- this.valuesSet |= tagsSet;
- }
- }
-
- /// <summary>
- /// Gets or sets the activity options for this specified events. If this property is
- /// unset, the event's activity options will be 0.
- /// </summary>
- public EventActivityOptions ActivityOptions
- {
- get => this.activityOptions;
- set
- {
- this.activityOptions = value;
- this.valuesSet |= activityOptionsSet;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs
deleted file mode 100644
index c42e84afdc7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs
+++ /dev/null
@@ -1,230 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-using System.Text;
-
-#if ES_BUILD_STANDALONE
-using Environment = Microsoft.Diagnostics.Tracing.Internal.Environment;
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: Contains the information needed to generate tracelogging
- /// metadata for an event field.
- /// </summary>
- internal class FieldMetadata
- {
- /// <summary>
- /// Name of the field
- /// </summary>
- private readonly string name;
-
- /// <summary>
- /// The number of bytes in the UTF8 Encoding of 'name' INCLUDING a null terminator.
- /// </summary>
- private readonly int nameSize;
- private readonly EventFieldTags tags;
- private readonly byte[]? custom;
-
- /// <summary>
- /// ETW supports fixed sized arrays. If inType has the InTypeFixedCountFlag then this is the
- /// statically known count for the array. It is also used to encode the number of bytes of
- /// custom meta-data if InTypeCustomCountFlag set.
- /// </summary>
- private readonly ushort fixedCount;
-
- private byte inType;
- private byte outType;
-
- /// <summary>
- /// Scalar or variable-length array.
- /// </summary>
- public FieldMetadata(
- string name,
- TraceLoggingDataType type,
- EventFieldTags tags,
- bool variableCount)
- : this(
- name,
- type,
- tags,
- variableCount ? Statics.InTypeVariableCountFlag : (byte)0,
- 0,
- null)
- {
- }
-
- /// <summary>
- /// Fixed-length array.
- /// </summary>
- public FieldMetadata(
- string name,
- TraceLoggingDataType type,
- EventFieldTags tags,
- ushort fixedCount)
- : this(
- name,
- type,
- tags,
- Statics.InTypeFixedCountFlag,
- fixedCount,
- null)
- {
- }
-
- /// <summary>
- /// Custom serializer
- /// </summary>
- public FieldMetadata(
- string name,
- TraceLoggingDataType type,
- EventFieldTags tags,
- byte[]? custom)
- : this(
- name,
- type,
- tags,
- Statics.InTypeCustomCountFlag,
- checked((ushort)(custom == null ? 0 : custom.Length)),
- custom)
- {
- }
-
- private FieldMetadata(
- string name,
- TraceLoggingDataType dataType,
- EventFieldTags tags,
- byte countFlags,
- ushort fixedCount = 0,
- byte[]? custom = null)
- {
- if (name == null)
- {
- throw new ArgumentNullException(
- nameof(name),
- "This usually means that the object passed to Write is of a type that"
- + " does not support being used as the top-level object in an event,"
- + " e.g. a primitive or built-in type.");
- }
-
- Statics.CheckName(name);
- int coreType = (int)dataType & Statics.InTypeMask;
- this.name = name;
- this.nameSize = Encoding.UTF8.GetByteCount(this.name) + 1;
- this.inType = (byte)(coreType | countFlags);
- this.outType = (byte)(((int)dataType >> 8) & Statics.OutTypeMask);
- this.tags = tags;
- this.fixedCount = fixedCount;
- this.custom = custom;
-
- if (countFlags != 0)
- {
- if (coreType == (int)TraceLoggingDataType.Nil)
- {
- throw new NotSupportedException(SR.EventSource_NotSupportedArrayOfNil);
- }
- if (coreType == (int)TraceLoggingDataType.Binary)
- {
- throw new NotSupportedException(SR.EventSource_NotSupportedArrayOfBinary);
- }
- if (coreType == (int)TraceLoggingDataType.Utf16String ||
- coreType == (int)TraceLoggingDataType.MbcsString)
- {
- throw new NotSupportedException(SR.EventSource_NotSupportedArrayOfNullTerminatedString);
- }
- }
-
- if (((int)this.tags & 0xfffffff) != 0)
- {
- this.outType |= Statics.OutTypeChainFlag;
- }
-
- if (this.outType != 0)
- {
- this.inType |= Statics.InTypeChainFlag;
- }
- }
-
- public void IncrementStructFieldCount()
- {
- this.inType |= Statics.InTypeChainFlag;
- this.outType++;
- if ((this.outType & Statics.OutTypeMask) == 0)
- {
- throw new NotSupportedException(SR.EventSource_TooManyFields);
- }
- }
-
- /// <summary>
- /// This is the main routine for FieldMetaData. Basically it will serialize the data in
- /// this structure as TraceLogging style meta-data into the array 'metaArray' starting at
- /// 'pos' (pos is updated to reflect the bytes written).
- ///
- /// Note that 'metaData' can be null, in which case it only updates 'pos'. This is useful
- /// for a 'two pass' approach where you figure out how big to make the array, and then you
- /// fill it in.
- /// </summary>
- public void Encode(ref int pos, byte[]? metadata)
- {
- // Write out the null terminated UTF8 encoded name
- if (metadata != null)
- {
- Encoding.UTF8.GetBytes(this.name, 0, this.name.Length, metadata, pos);
- }
- pos += this.nameSize;
-
- // Write 1 byte for inType
- if (metadata != null)
- {
- metadata[pos] = this.inType;
- }
- pos++;
-
- // If InTypeChainFlag set, then write out the outType
- if (0 != (this.inType & Statics.InTypeChainFlag))
- {
- if (metadata != null)
- {
- metadata[pos] = this.outType;
- }
- pos++;
-
- // If OutTypeChainFlag set, then write out tags
- if (0 != (this.outType & Statics.OutTypeChainFlag))
- {
- Statics.EncodeTags((int)this.tags, ref pos, metadata);
- }
- }
-
- // If InTypeFixedCountFlag set, write out the fixedCount (2 bytes little endian)
- if (0 != (this.inType & Statics.InTypeFixedCountFlag))
- {
- if (metadata != null)
- {
- metadata[pos + 0] = unchecked((byte)this.fixedCount);
- metadata[pos + 1] = (byte)(this.fixedCount >> 8);
- }
- pos += 2;
-
- // If InTypeCustomCountFlag set, write out the blob of custom meta-data.
- if (Statics.InTypeCustomCountFlag == (this.inType & Statics.InTypeCountMask) &&
- this.fixedCount != 0)
- {
- if (metadata != null)
- {
- Debug.Assert(custom != null);
- Buffer.BlockCopy(custom, 0, metadata, pos, this.fixedCount);
- }
- pos += this.fixedCount;
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/InvokeTypeInfo.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/InvokeTypeInfo.cs
deleted file mode 100644
index 3c5cf2541c1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/InvokeTypeInfo.cs
+++ /dev/null
@@ -1,95 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-using System.Collections.Generic;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: An implementation of TraceLoggingTypeInfo that works
- /// for arbitrary types. It writes all public instance properties of
- /// the type.
- /// </summary>
- internal sealed class InvokeTypeInfo : TraceLoggingTypeInfo
- {
- internal readonly PropertyAnalysis[]? properties;
-
- public InvokeTypeInfo(
- Type type,
- TypeAnalysis typeAnalysis)
- : base(
- type,
- typeAnalysis.name!,
- typeAnalysis.level,
- typeAnalysis.opcode,
- typeAnalysis.keywords,
- typeAnalysis.tags)
- {
- if (typeAnalysis.properties.Length != 0)
- this.properties = typeAnalysis.properties;
- }
-
- public override void WriteMetadata(
- TraceLoggingMetadataCollector collector,
- string? name,
- EventFieldFormat format)
- {
- TraceLoggingMetadataCollector groupCollector = collector.AddGroup(name);
- if (this.properties != null)
- {
- foreach (PropertyAnalysis property in this.properties)
- {
- EventFieldFormat propertyFormat = EventFieldFormat.Default;
- EventFieldAttribute? propertyAttribute = property.fieldAttribute;
- if (propertyAttribute != null)
- {
- groupCollector.Tags = propertyAttribute.Tags;
- propertyFormat = propertyAttribute.Format;
- }
-
- property.typeInfo.WriteMetadata(
- groupCollector,
- property.name,
- propertyFormat);
- }
- }
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- if (this.properties != null)
- {
- foreach (PropertyAnalysis property in this.properties)
- {
- property.typeInfo.WriteData(collector, property.getter(value));
- }
- }
- }
-
- public override object? GetData(object? value)
- {
- if (this.properties != null)
- {
- var membersNames = new List<string>();
- var membersValues = new List<object?>();
- for (int i = 0; i < this.properties.Length; i++)
- {
- object? propertyValue = properties[i].propertyInfo.GetValue(value);
- membersNames.Add(properties[i].name);
- membersValues.Add(properties[i].typeInfo.GetData(propertyValue));
- }
- return new EventPayload(membersNames, membersValues);
- }
-
- return null;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs
deleted file mode 100644
index 17bf2eb2aed..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/NameInfo.cs
+++ /dev/null
@@ -1,126 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-using System.Collections.Generic;
-using System.Threading;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: Stores the metadata and event identifier corresponding
- /// to a tracelogging event type+name+tags combination.
- /// </summary>
- internal sealed class NameInfo
- : ConcurrentSetItem<KeyValuePair<string, EventTags>, NameInfo>
- {
- /// <summary>
- /// Insure that eventIds strictly less than 'eventId' will not be
- /// used by the SelfDescribing events.
- /// </summary>
- internal static void ReserveEventIDsBelow(int eventId)
- {
- while (true)
- {
- int snapshot = lastIdentity;
- int newIdentity = (lastIdentity & ~0xFFFFFF) + eventId;
- newIdentity = Math.Max(newIdentity, snapshot); // Should be redundant. as we only create descriptors once.
- if (Interlocked.CompareExchange(ref lastIdentity, newIdentity, snapshot) == snapshot)
- break;
- }
- }
-
- private static int lastIdentity = Statics.TraceLoggingChannel << 24;
- internal readonly string name;
- internal readonly EventTags tags;
- internal readonly int identity;
- internal readonly byte[] nameMetadata;
-
- public NameInfo(string name, EventTags tags, int typeMetadataSize)
- {
- this.name = name;
- this.tags = tags & Statics.EventTagsMask;
- this.identity = Interlocked.Increment(ref lastIdentity);
-
- int tagsPos = 0;
- Statics.EncodeTags((int)this.tags, ref tagsPos, null);
-
- this.nameMetadata = Statics.MetadataForString(name, tagsPos, 0, typeMetadataSize);
-
- tagsPos = 2;
- Statics.EncodeTags((int)this.tags, ref tagsPos, this.nameMetadata);
- }
-
- public override int Compare(NameInfo other)
- {
- return this.Compare(other.name, other.tags);
- }
-
- public override int Compare(KeyValuePair<string, EventTags> key)
- {
- return this.Compare(key.Key, key.Value & Statics.EventTagsMask);
- }
-
- private int Compare(string otherName, EventTags otherTags)
- {
- int result = StringComparer.Ordinal.Compare(this.name, otherName);
- if (result == 0 && this.tags != otherTags)
- {
- result = this.tags < otherTags ? -1 : 1;
- }
- return result;
- }
-
-#if FEATURE_PERFTRACING
- public IntPtr GetOrCreateEventHandle(EventProvider provider, TraceLoggingEventHandleTable eventHandleTable, EventDescriptor descriptor, TraceLoggingEventTypes eventTypes)
- {
- IntPtr eventHandle;
- if ((eventHandle = eventHandleTable[descriptor.EventId]) == IntPtr.Zero)
- {
- lock (eventHandleTable)
- {
- if ((eventHandle = eventHandleTable[descriptor.EventId]) == IntPtr.Zero)
- {
- byte[]? metadataBlob = EventPipeMetadataGenerator.Instance.GenerateEventMetadata(
- descriptor.EventId,
- name,
- (EventKeywords)descriptor.Keywords,
- (EventLevel)descriptor.Level,
- descriptor.Version,
- eventTypes);
- uint metadataLength = (metadataBlob != null) ? (uint)metadataBlob.Length : 0;
-
- unsafe
- {
- fixed (byte* pMetadataBlob = metadataBlob)
- {
- // Define the event.
- eventHandle = provider.m_eventProvider.DefineEventHandle(
- (uint)descriptor.EventId,
- name,
- descriptor.Keywords,
- descriptor.Version,
- descriptor.Level,
- pMetadataBlob,
- metadataLength);
- }
- }
-
- // Cache the event handle.
- eventHandleTable.SetEventHandle(descriptor.EventId, eventHandle);
- }
- }
- }
-
- return eventHandle;
- }
-#endif
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyAnalysis.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyAnalysis.cs
deleted file mode 100644
index e7c2c08b275..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyAnalysis.cs
+++ /dev/null
@@ -1,41 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-using System.Reflection;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: stores the per-property information obtained by
- /// reflecting over a type.
- /// </summary>
- internal sealed class PropertyAnalysis
- {
- internal readonly string name;
- internal readonly PropertyInfo propertyInfo;
- internal readonly Func<PropertyValue, PropertyValue> getter;
- internal readonly TraceLoggingTypeInfo typeInfo;
- internal readonly EventFieldAttribute? fieldAttribute;
-
- public PropertyAnalysis(
- string name,
- PropertyInfo propertyInfo,
- TraceLoggingTypeInfo typeInfo,
- EventFieldAttribute? fieldAttribute)
- {
- this.name = name;
- this.propertyInfo = propertyInfo;
- this.getter = PropertyValue.GetPropertyGetter(propertyInfo);
- this.typeInfo = typeInfo;
- this.fieldAttribute = fieldAttribute;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs
deleted file mode 100644
index 645aab27244..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs
+++ /dev/null
@@ -1,272 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Holds property values of any type. For common value types, we have inline storage so that we don't need
- /// to box the values. For all other types, we store the value in a single object reference field.
- ///
- /// To get the value of a property quickly, use a delegate produced by <see cref="PropertyValue.GetPropertyGetter(PropertyInfo)"/>.
- /// </summary>
-#if ES_BUILD_PN
- [CLSCompliant(false)]
- public
-#else
- internal
-#endif
- readonly unsafe struct PropertyValue
- {
- /// <summary>
- /// Union of well-known value types, to avoid boxing those types.
- /// </summary>
- [StructLayout(LayoutKind.Explicit)]
- public struct Scalar
- {
- [FieldOffset(0)]
- public bool AsBoolean;
- [FieldOffset(0)]
- public byte AsByte;
- [FieldOffset(0)]
- public sbyte AsSByte;
- [FieldOffset(0)]
- public char AsChar;
- [FieldOffset(0)]
- public short AsInt16;
- [FieldOffset(0)]
- public ushort AsUInt16;
- [FieldOffset(0)]
- public int AsInt32;
- [FieldOffset(0)]
- public uint AsUInt32;
- [FieldOffset(0)]
- public long AsInt64;
- [FieldOffset(0)]
- public ulong AsUInt64;
- [FieldOffset(0)]
- public IntPtr AsIntPtr;
- [FieldOffset(0)]
- public UIntPtr AsUIntPtr;
- [FieldOffset(0)]
- public float AsSingle;
- [FieldOffset(0)]
- public double AsDouble;
- [FieldOffset(0)]
- public Guid AsGuid;
- [FieldOffset(0)]
- public DateTime AsDateTime;
- [FieldOffset(0)]
- public DateTimeOffset AsDateTimeOffset;
- [FieldOffset(0)]
- public TimeSpan AsTimeSpan;
- [FieldOffset(0)]
- public decimal AsDecimal;
- }
-
- // Anything not covered by the Scalar union gets stored in this reference.
- private readonly object? _reference;
- private readonly Scalar _scalar;
- private readonly int _scalarLength;
-
- private PropertyValue(object? value)
- {
- _reference = value;
- _scalar = default;
- _scalarLength = 0;
- }
-
- private PropertyValue(Scalar scalar, int scalarLength)
- {
- _reference = null;
- _scalar = scalar;
- _scalarLength = scalarLength;
- }
-
- private PropertyValue(bool value) : this(new Scalar() { AsBoolean = value }, sizeof(bool)) { }
- private PropertyValue(byte value) : this(new Scalar() { AsByte = value }, sizeof(byte)) { }
- private PropertyValue(sbyte value) : this(new Scalar() { AsSByte = value }, sizeof(sbyte)) { }
- private PropertyValue(char value) : this(new Scalar() { AsChar = value }, sizeof(char)) { }
- private PropertyValue(short value) : this(new Scalar() { AsInt16 = value }, sizeof(short)) { }
- private PropertyValue(ushort value) : this(new Scalar() { AsUInt16 = value }, sizeof(ushort)) { }
- private PropertyValue(int value) : this(new Scalar() { AsInt32 = value }, sizeof(int)) { }
- private PropertyValue(uint value) : this(new Scalar() { AsUInt32 = value }, sizeof(uint)) { }
- private PropertyValue(long value) : this(new Scalar() { AsInt64 = value }, sizeof(long)) { }
- private PropertyValue(ulong value) : this(new Scalar() { AsUInt64 = value }, sizeof(ulong)) { }
- private PropertyValue(IntPtr value) : this(new Scalar() { AsIntPtr = value }, sizeof(IntPtr)) { }
- private PropertyValue(UIntPtr value) : this(new Scalar() { AsUIntPtr = value }, sizeof(UIntPtr)) { }
- private PropertyValue(float value) : this(new Scalar() { AsSingle = value }, sizeof(float)) { }
- private PropertyValue(double value) : this(new Scalar() { AsDouble = value }, sizeof(double)) { }
- private PropertyValue(Guid value) : this(new Scalar() { AsGuid = value }, sizeof(Guid)) { }
- private PropertyValue(DateTime value) : this(new Scalar() { AsDateTime = value }, sizeof(DateTime)) { }
- private PropertyValue(DateTimeOffset value) : this(new Scalar() { AsDateTimeOffset = value }, sizeof(DateTimeOffset)) { }
- private PropertyValue(TimeSpan value) : this(new Scalar() { AsTimeSpan = value }, sizeof(TimeSpan)) { }
- private PropertyValue(decimal value) : this(new Scalar() { AsDecimal = value }, sizeof(decimal)) { }
-
- public static Func<object?, PropertyValue> GetFactory(Type type)
- {
- if (type == typeof(bool)) return value => new PropertyValue((bool)value!);
- if (type == typeof(byte)) return value => new PropertyValue((byte)value!);
- if (type == typeof(sbyte)) return value => new PropertyValue((sbyte)value!);
- if (type == typeof(char)) return value => new PropertyValue((char)value!);
- if (type == typeof(short)) return value => new PropertyValue((short)value!);
- if (type == typeof(ushort)) return value => new PropertyValue((ushort)value!);
- if (type == typeof(int)) return value => new PropertyValue((int)value!);
- if (type == typeof(uint)) return value => new PropertyValue((uint)value!);
- if (type == typeof(long)) return value => new PropertyValue((long)value!);
- if (type == typeof(ulong)) return value => new PropertyValue((ulong)value!);
- if (type == typeof(IntPtr)) return value => new PropertyValue((IntPtr)value!);
- if (type == typeof(UIntPtr)) return value => new PropertyValue((UIntPtr)value!);
- if (type == typeof(float)) return value => new PropertyValue((float)value!);
- if (type == typeof(double)) return value => new PropertyValue((double)value!);
- if (type == typeof(Guid)) return value => new PropertyValue((Guid)value!);
- if (type == typeof(DateTime)) return value => new PropertyValue((DateTime)value!);
- if (type == typeof(DateTimeOffset)) return value => new PropertyValue((DateTimeOffset)value!);
- if (type == typeof(TimeSpan)) return value => new PropertyValue((TimeSpan)value!);
- if (type == typeof(decimal)) return value => new PropertyValue((decimal)value!);
-
- return value => new PropertyValue(value);
- }
-
- public object? ReferenceValue
- {
- get
- {
- Debug.Assert(_scalarLength == 0, "This ReflectedValue refers to an unboxed value type, not a reference type or boxed value type.");
- return _reference;
- }
- }
-
- public Scalar ScalarValue
- {
- get
- {
- Debug.Assert(_scalarLength > 0, "This ReflectedValue refers to a reference type or boxed value type, not an unboxed value type");
- return _scalar;
- }
- }
-
- public int ScalarLength
- {
- get
- {
- Debug.Assert(_scalarLength > 0, "This ReflectedValue refers to a reference type or boxed value type, not an unboxed value type");
- return _scalarLength;
- }
- }
-
- /// <summary>
- /// Gets a delegate that gets the value of a given property.
- /// </summary>
- public static Func<PropertyValue, PropertyValue> GetPropertyGetter(PropertyInfo property)
- {
- if (property.DeclaringType!.GetTypeInfo().IsValueType)
- return GetBoxedValueTypePropertyGetter(property);
- else
- return GetReferenceTypePropertyGetter(property);
- }
-
- /// <summary>
- /// Gets a delegate that gets the value of a property of a value type. We unfortunately cannot avoid boxing the value type,
- /// without making this generic over the value type. That would result in a large number of generic instantiations, and furthermore
- /// does not work correctly on .NET Native (we cannot express the needed instantiations in an rd.xml file). We expect that user-defined
- /// value types will be rare, and in any case the boxing only happens for events that are actually enabled.
- /// </summary>
- private static Func<PropertyValue, PropertyValue> GetBoxedValueTypePropertyGetter(PropertyInfo property)
- {
- Type type = property.PropertyType;
-
- if (type.GetTypeInfo().IsEnum)
- type = Enum.GetUnderlyingType(type);
-
- Func<object?, PropertyValue> factory = GetFactory(type);
-
- return container => factory(property.GetValue(container.ReferenceValue));
- }
-
- /// <summary>
- /// For properties of reference types, we use a generic helper class to get the value. This enables us to use MethodInfo.CreateDelegate
- /// to build a fast getter. We can get away with this on .NET Native, because we really only need one runtime instantiation of the
- /// generic type, since it's only instantiated over reference types (and thus all instances are shared).
- /// </summary>
- /// <param name="property"></param>
- /// <returns></returns>
- private static Func<PropertyValue, PropertyValue> GetReferenceTypePropertyGetter(PropertyInfo property)
- {
- var helper = (TypeHelper)Activator.CreateInstance(typeof(ReferenceTypeHelper<>).MakeGenericType(property.DeclaringType!))!;
- return helper.GetPropertyGetter(property);
- }
-
-#if ES_BUILD_PN
- public
-#else
- private
-#endif
- abstract class TypeHelper
- {
- public abstract Func<PropertyValue, PropertyValue> GetPropertyGetter(PropertyInfo property);
-
- protected Delegate GetGetMethod(PropertyInfo property, Type propertyType)
- {
- return property.GetMethod!.CreateDelegate(typeof(Func<,>).MakeGenericType(property.DeclaringType!, propertyType));
- }
- }
-
-#if ES_BUILD_PN
- public
-#else
- private
-#endif
- sealed class ReferenceTypeHelper<TContainer> : TypeHelper where TContainer : class?
- {
- public override Func<PropertyValue, PropertyValue> GetPropertyGetter(PropertyInfo property)
- {
- Type type = property.PropertyType;
-
- if (!Statics.IsValueType(type))
- {
- var getter = (Func<TContainer, object?>)GetGetMethod(property, type);
- return container => new PropertyValue(getter((TContainer)container.ReferenceValue!));
- }
- else
- {
- if (type.GetTypeInfo().IsEnum)
- type = Enum.GetUnderlyingType(type);
-
- if (type == typeof(bool)) { var f = (Func<TContainer, bool>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(byte)) { var f = (Func<TContainer, byte>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(sbyte)) { var f = (Func<TContainer, sbyte>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(char)) { var f = (Func<TContainer, char>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(short)) { var f = (Func<TContainer, short>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(ushort)) { var f = (Func<TContainer, ushort>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(int)) { var f = (Func<TContainer, int>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(uint)) { var f = (Func<TContainer, uint>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(long)) { var f = (Func<TContainer, long>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(ulong)) { var f = (Func<TContainer, ulong>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(IntPtr)) { var f = (Func<TContainer, IntPtr>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(UIntPtr)) { var f = (Func<TContainer, UIntPtr>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(float)) { var f = (Func<TContainer, float>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(double)) { var f = (Func<TContainer, double>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(Guid)) { var f = (Func<TContainer, Guid>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(DateTime)) { var f = (Func<TContainer, DateTime>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(DateTimeOffset)) { var f = (Func<TContainer, DateTimeOffset>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(TimeSpan)) { var f = (Func<TContainer, TimeSpan>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
- if (type == typeof(decimal)) { var f = (Func<TContainer, decimal>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
-
- return container => new PropertyValue(property.GetValue(container.ReferenceValue));
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs
deleted file mode 100644
index c85ec92febf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/SimpleEventTypes.cs
+++ /dev/null
@@ -1,40 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-using System.Threading;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: Contains the metadata needed to emit an event, optimized
- /// for events with one top-level compile-time-typed payload object.
- /// </summary>
- /// <typeparam name="T">
- /// Type of the top-level payload object. Should be EmptyStruct if the
- /// event has no payload.
- /// </typeparam>
- internal static class SimpleEventTypes<T>
- {
- private static TraceLoggingEventTypes? instance;
-
- public static TraceLoggingEventTypes Instance => instance ?? InitInstance();
-
- private static TraceLoggingEventTypes InitInstance()
- {
- var info = TraceLoggingTypeInfo.GetInstance(typeof(T), null);
- var newInstance = new TraceLoggingEventTypes(info.Name, info.Tags, new TraceLoggingTypeInfo[] { info });
- Interlocked.CompareExchange(ref instance, newInstance, null);
- Debug.Assert(instance != null);
- return instance;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs
deleted file mode 100644
index 0525413ccd9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs
+++ /dev/null
@@ -1,299 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-#endif
-using System.Collections.Generic;
-using System.Reflection;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: Type handler for empty or unsupported types.
- /// </summary>
- internal sealed class NullTypeInfo : TraceLoggingTypeInfo
- {
- public NullTypeInfo() : base(typeof(EmptyStruct)) { }
-
- public override void WriteMetadata(
- TraceLoggingMetadataCollector collector,
- string? name,
- EventFieldFormat format)
- {
- collector.AddGroup(name);
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- return;
- }
-
- public override object? GetData(object? value)
- {
- return null;
- }
- }
-
- /// <summary>
- /// Type handler for simple scalar types.
- /// </summary>
- internal sealed class ScalarTypeInfo : TraceLoggingTypeInfo
- {
- private readonly Func<EventFieldFormat, TraceLoggingDataType, TraceLoggingDataType> formatFunc;
- private readonly TraceLoggingDataType nativeFormat;
-
- private ScalarTypeInfo(
- Type type,
- Func<EventFieldFormat, TraceLoggingDataType, TraceLoggingDataType> formatFunc,
- TraceLoggingDataType nativeFormat)
- : base(type)
- {
- this.formatFunc = formatFunc;
- this.nativeFormat = nativeFormat;
- }
-
- public override void WriteMetadata(TraceLoggingMetadataCollector collector, string? name, EventFieldFormat format)
- {
- collector.AddScalar(name!, formatFunc(format, nativeFormat));
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- collector.AddScalar(value);
- }
-
- public static TraceLoggingTypeInfo Boolean() { return new ScalarTypeInfo(typeof(bool), Statics.Format8, TraceLoggingDataType.Boolean8); }
- public static TraceLoggingTypeInfo Byte() { return new ScalarTypeInfo(typeof(byte), Statics.Format8, TraceLoggingDataType.UInt8); }
- public static TraceLoggingTypeInfo SByte() { return new ScalarTypeInfo(typeof(sbyte), Statics.Format8, TraceLoggingDataType.Int8); }
- public static TraceLoggingTypeInfo Char() { return new ScalarTypeInfo(typeof(char), Statics.Format16, TraceLoggingDataType.Char16); }
- public static TraceLoggingTypeInfo Int16() { return new ScalarTypeInfo(typeof(short), Statics.Format16, TraceLoggingDataType.Int16); }
- public static TraceLoggingTypeInfo UInt16() { return new ScalarTypeInfo(typeof(ushort), Statics.Format16, TraceLoggingDataType.UInt16); }
- public static TraceLoggingTypeInfo Int32() { return new ScalarTypeInfo(typeof(int), Statics.Format32, TraceLoggingDataType.Int32); }
- public static TraceLoggingTypeInfo UInt32() { return new ScalarTypeInfo(typeof(uint), Statics.Format32, TraceLoggingDataType.UInt32); }
- public static TraceLoggingTypeInfo Int64() { return new ScalarTypeInfo(typeof(long), Statics.Format64, TraceLoggingDataType.Int64); }
- public static TraceLoggingTypeInfo UInt64() { return new ScalarTypeInfo(typeof(ulong), Statics.Format64, TraceLoggingDataType.UInt64); }
- public static TraceLoggingTypeInfo IntPtr() { return new ScalarTypeInfo(typeof(IntPtr), Statics.FormatPtr, Statics.IntPtrType); }
- public static TraceLoggingTypeInfo UIntPtr() { return new ScalarTypeInfo(typeof(UIntPtr), Statics.FormatPtr, Statics.UIntPtrType); }
- public static TraceLoggingTypeInfo Single() { return new ScalarTypeInfo(typeof(float), Statics.Format32, TraceLoggingDataType.Float); }
- public static TraceLoggingTypeInfo Double() { return new ScalarTypeInfo(typeof(double), Statics.Format64, TraceLoggingDataType.Double); }
- public static TraceLoggingTypeInfo Guid() { return new ScalarTypeInfo(typeof(Guid), (f, t) => Statics.MakeDataType(TraceLoggingDataType.Guid, f), TraceLoggingDataType.Guid); }
- }
-
-
- /// <summary>
- /// Type handler for arrays of scalars
- /// </summary>
- internal sealed class ScalarArrayTypeInfo : TraceLoggingTypeInfo
- {
- private readonly Func<EventFieldFormat, TraceLoggingDataType, TraceLoggingDataType> formatFunc;
- private readonly TraceLoggingDataType nativeFormat;
- private readonly int elementSize;
-
- private ScalarArrayTypeInfo(
- Type type,
- Func<EventFieldFormat, TraceLoggingDataType, TraceLoggingDataType> formatFunc,
- TraceLoggingDataType nativeFormat,
- int elementSize)
- : base(type)
- {
- this.formatFunc = formatFunc;
- this.nativeFormat = nativeFormat;
- this.elementSize = elementSize;
- }
-
- public override void WriteMetadata(TraceLoggingMetadataCollector collector, string? name, EventFieldFormat format)
- {
- collector.AddArray(name!, formatFunc(format, nativeFormat));
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- collector.AddArray(value, elementSize);
- }
-
- public static TraceLoggingTypeInfo Boolean() { return new ScalarArrayTypeInfo(typeof(bool[]), Statics.Format8, TraceLoggingDataType.Boolean8, sizeof(bool)); }
- public static TraceLoggingTypeInfo Byte() { return new ScalarArrayTypeInfo(typeof(byte[]), Statics.Format8, TraceLoggingDataType.UInt8, sizeof(byte)); }
- public static TraceLoggingTypeInfo SByte() { return new ScalarArrayTypeInfo(typeof(sbyte[]), Statics.Format8, TraceLoggingDataType.Int8, sizeof(sbyte)); }
- public static TraceLoggingTypeInfo Char() { return new ScalarArrayTypeInfo(typeof(char[]), Statics.Format16, TraceLoggingDataType.Char16, sizeof(char)); }
- public static TraceLoggingTypeInfo Int16() { return new ScalarArrayTypeInfo(typeof(short[]), Statics.Format16, TraceLoggingDataType.Int16, sizeof(short)); }
- public static TraceLoggingTypeInfo UInt16() { return new ScalarArrayTypeInfo(typeof(ushort[]), Statics.Format16, TraceLoggingDataType.UInt16, sizeof(ushort)); }
- public static TraceLoggingTypeInfo Int32() { return new ScalarArrayTypeInfo(typeof(int[]), Statics.Format32, TraceLoggingDataType.Int32, sizeof(int)); }
- public static TraceLoggingTypeInfo UInt32() { return new ScalarArrayTypeInfo(typeof(uint[]), Statics.Format32, TraceLoggingDataType.UInt32, sizeof(uint)); }
- public static TraceLoggingTypeInfo Int64() { return new ScalarArrayTypeInfo(typeof(long[]), Statics.Format64, TraceLoggingDataType.Int64, sizeof(long)); }
- public static TraceLoggingTypeInfo UInt64() { return new ScalarArrayTypeInfo(typeof(ulong[]), Statics.Format64, TraceLoggingDataType.UInt64, sizeof(ulong)); }
- public static TraceLoggingTypeInfo IntPtr() { return new ScalarArrayTypeInfo(typeof(IntPtr[]), Statics.FormatPtr, Statics.IntPtrType, System.IntPtr.Size); }
- public static TraceLoggingTypeInfo UIntPtr() { return new ScalarArrayTypeInfo(typeof(UIntPtr[]), Statics.FormatPtr, Statics.UIntPtrType, System.IntPtr.Size); }
- public static TraceLoggingTypeInfo Single() { return new ScalarArrayTypeInfo(typeof(float[]), Statics.Format32, TraceLoggingDataType.Float, sizeof(float)); }
- public static TraceLoggingTypeInfo Double() { return new ScalarArrayTypeInfo(typeof(double[]), Statics.Format64, TraceLoggingDataType.Double, sizeof(double)); }
- public static unsafe TraceLoggingTypeInfo Guid() { return new ScalarArrayTypeInfo(typeof(Guid), (f, t) => Statics.MakeDataType(TraceLoggingDataType.Guid, f), TraceLoggingDataType.Guid, sizeof(Guid)); }
- }
-
- /// <summary>
- /// TraceLogging: Type handler for String.
- /// </summary>
- internal sealed class StringTypeInfo : TraceLoggingTypeInfo
- {
- public StringTypeInfo() : base(typeof(string)) { }
-
- public override void WriteMetadata(
- TraceLoggingMetadataCollector collector,
- string? name,
- EventFieldFormat format)
- {
- collector.AddNullTerminatedString(name!, Statics.MakeDataType(TraceLoggingDataType.Utf16String, format));
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- collector.AddNullTerminatedString((string?)value.ReferenceValue);
- }
-
- public override object GetData(object? value)
- {
- if (value == null)
- {
- return "";
- }
-
- return value;
- }
- }
-
- /// <summary>
- /// TraceLogging: Type handler for DateTime.
- /// </summary>
- internal sealed class DateTimeTypeInfo : TraceLoggingTypeInfo
- {
- public DateTimeTypeInfo() : base(typeof(DateTime)) { }
-
- public override void WriteMetadata(
- TraceLoggingMetadataCollector collector,
- string? name,
- EventFieldFormat format)
- {
- collector.AddScalar(name!, Statics.MakeDataType(TraceLoggingDataType.FileTime, format));
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- DateTime dateTime = value.ScalarValue.AsDateTime;
- const long UTCMinTicks = 504911232000000000;
- long dateTimeTicks = 0;
- // We cannot translate dates sooner than 1/1/1601 in UTC.
- // To avoid getting an ArgumentOutOfRangeException we compare with 1/1/1601 DateTime ticks
- if (dateTime.Ticks > UTCMinTicks)
- dateTimeTicks = dateTime.ToFileTimeUtc();
- collector.AddScalar(dateTimeTicks);
- }
- }
-
- /// <summary>
- /// TraceLogging: Type handler for DateTimeOffset.
- /// </summary>
- internal sealed class DateTimeOffsetTypeInfo : TraceLoggingTypeInfo
- {
- public DateTimeOffsetTypeInfo() : base(typeof(DateTimeOffset)) { }
-
- public override void WriteMetadata(TraceLoggingMetadataCollector collector, string? name, EventFieldFormat format)
- {
- TraceLoggingMetadataCollector group = collector.AddGroup(name);
- group.AddScalar("Ticks", Statics.MakeDataType(TraceLoggingDataType.FileTime, format));
- group.AddScalar("Offset", TraceLoggingDataType.Int64);
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- DateTimeOffset dateTimeOffset = value.ScalarValue.AsDateTimeOffset;
- long ticks = dateTimeOffset.Ticks;
- collector.AddScalar(ticks < 504911232000000000 ? 0 : ticks - 504911232000000000);
- collector.AddScalar(dateTimeOffset.Offset.Ticks);
- }
- }
-
- /// <summary>
- /// TraceLogging: Type handler for TimeSpan.
- /// </summary>
- internal sealed class TimeSpanTypeInfo : TraceLoggingTypeInfo
- {
- public TimeSpanTypeInfo() : base(typeof(TimeSpan)) { }
-
- public override void WriteMetadata(
- TraceLoggingMetadataCollector collector,
- string? name,
- EventFieldFormat format)
- {
- collector.AddScalar(name!, Statics.MakeDataType(TraceLoggingDataType.Int64, format));
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- collector.AddScalar(value.ScalarValue.AsTimeSpan.Ticks);
- }
- }
-
- /// <summary>
- /// TraceLogging: Type handler for decimal. (Note: not full-fidelity, exposed as Double.)
- /// </summary>
- internal sealed class DecimalTypeInfo : TraceLoggingTypeInfo
- {
- public DecimalTypeInfo() : base(typeof(decimal)) { }
-
- public override void WriteMetadata(
- TraceLoggingMetadataCollector collector,
- string? name,
- EventFieldFormat format)
- {
- collector.AddScalar(name!, Statics.MakeDataType(TraceLoggingDataType.Double, format));
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- collector.AddScalar((double)value.ScalarValue.AsDecimal);
- }
- }
-
- /// <summary>
- /// TraceLogging: Type handler for Nullable.
- /// </summary>
- internal sealed class NullableTypeInfo : TraceLoggingTypeInfo
- {
- private readonly TraceLoggingTypeInfo valueInfo;
- private readonly Func<PropertyValue, PropertyValue> valueGetter;
-
- public NullableTypeInfo(Type type, List<Type> recursionCheck)
- : base(type)
- {
- Type[] typeArgs = type.GenericTypeArguments;
- Debug.Assert(typeArgs.Length == 1);
- this.valueInfo = TraceLoggingTypeInfo.GetInstance(typeArgs[0], recursionCheck);
- this.valueGetter = PropertyValue.GetPropertyGetter(type.GetTypeInfo().GetDeclaredProperty("Value")!);
- }
-
- public override void WriteMetadata(
- TraceLoggingMetadataCollector collector,
- string? name,
- EventFieldFormat format)
- {
- TraceLoggingMetadataCollector group = collector.AddGroup(name);
- group.AddScalar("HasValue", TraceLoggingDataType.Boolean8);
- this.valueInfo.WriteMetadata(group, "Value", format);
- }
-
- public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
- {
- // It's not currently possible to get the HasValue property of a nullable type through reflection when the
- // value is null. Instead, we simply check that the nullable is not null.
- bool hasValue = value.ReferenceValue != null;
- collector.AddScalar(hasValue);
- PropertyValue val = hasValue ? valueGetter(value) : valueInfo.PropertyValueFactory(Activator.CreateInstance(valueInfo.DataType));
- this.valueInfo.WriteData(collector, val);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/Statics.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/Statics.cs
deleted file mode 100644
index 6d4dd919981..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/Statics.cs
+++ /dev/null
@@ -1,693 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using Environment = Microsoft.Diagnostics.Tracing.Internal.Environment;
-#endif
-using System.Collections.Generic;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Text;
-using Microsoft.Reflection;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: Constants and utility functions.
- /// </summary>
- internal static class Statics
- {
- #region Constants
-
- public const byte DefaultLevel = 5;
- public const byte TraceLoggingChannel = 0xb;
- public const byte InTypeMask = 31;
- public const byte InTypeFixedCountFlag = 32;
- public const byte InTypeVariableCountFlag = 64;
- public const byte InTypeCustomCountFlag = 96;
- public const byte InTypeCountMask = 96;
- public const byte InTypeChainFlag = 128;
- public const byte OutTypeMask = 127;
- public const byte OutTypeChainFlag = 128;
- public const EventTags EventTagsMask = (EventTags)0xfffffff;
-
- public static readonly TraceLoggingDataType IntPtrType = IntPtr.Size == 8
- ? TraceLoggingDataType.Int64
- : TraceLoggingDataType.Int32;
- public static readonly TraceLoggingDataType UIntPtrType = IntPtr.Size == 8
- ? TraceLoggingDataType.UInt64
- : TraceLoggingDataType.UInt32;
- public static readonly TraceLoggingDataType HexIntPtrType = IntPtr.Size == 8
- ? TraceLoggingDataType.HexInt64
- : TraceLoggingDataType.HexInt32;
-
- #endregion
-
- #region Metadata helpers
-
- /// <summary>
- /// A complete metadata chunk can be expressed as:
- /// length16 + prefix + null-terminated-utf8-name + suffix + additionalData.
- /// We assume that excludedData will be provided by some other means,
- /// but that its size is known. This function returns a blob containing
- /// length16 + prefix + name + suffix, with prefix and suffix initialized
- /// to 0's. The length16 value is initialized to the length of the returned
- /// blob plus additionalSize, so that the concatenation of the returned blob
- /// plus a blob of size additionalSize constitutes a valid metadata blob.
- /// </summary>
- /// <param name="name">
- /// The name to include in the blob.
- /// </param>
- /// <param name="prefixSize">
- /// Amount of space to reserve before name. For provider or field blobs, this
- /// should be 0. For event blobs, this is used for the tags field and will vary
- /// from 1 to 4, depending on how large the tags field needs to be.
- /// </param>
- /// <param name="suffixSize">
- /// Amount of space to reserve after name. For example, a provider blob with no
- /// traits would reserve 0 extra bytes, but a provider blob with a single GroupId
- /// field would reserve 19 extra bytes.
- /// </param>
- /// <param name="additionalSize">
- /// Amount of additional data in another blob. This value will be counted in the
- /// blob's length field, but will not be included in the returned byte[] object.
- /// The complete blob would then be the concatenation of the returned byte[] object
- /// with another byte[] object of length additionalSize.
- /// </param>
- /// <returns>
- /// A byte[] object with the length and name fields set, with room reserved for
- /// prefix and suffix. If additionalSize was 0, the byte[] object is a complete
- /// blob. Otherwise, another byte[] of size additionalSize must be concatenated
- /// with this one to form a complete blob.
- /// </returns>
- public static byte[] MetadataForString(
- string name,
- int prefixSize,
- int suffixSize,
- int additionalSize)
- {
- Statics.CheckName(name);
- int metadataSize = Encoding.UTF8.GetByteCount(name) + 3 + prefixSize + suffixSize;
- var metadata = new byte[metadataSize];
- ushort totalSize = checked((ushort)(metadataSize + additionalSize));
- metadata[0] = unchecked((byte)totalSize);
- metadata[1] = unchecked((byte)(totalSize >> 8));
- Encoding.UTF8.GetBytes(name, 0, name.Length, metadata, 2 + prefixSize);
- return metadata;
- }
-
- /// <summary>
- /// Serialize the low 28 bits of the tags value into the metadata stream,
- /// starting at the index given by pos. Updates pos. Writes 1 to 4 bytes,
- /// depending on the value of the tags variable. Usable for event tags and
- /// field tags.
- ///
- /// Note that 'metadata' can be null, in which case it only updates 'pos'.
- /// This is useful for a two pass approach where you figure out how big to
- /// make the array, and then you fill it in.
- /// </summary>
- public static void EncodeTags(int tags, ref int pos, byte[]? metadata)
- {
- // We transmit the low 28 bits of tags, high bits first, 7 bits at a time.
- int tagsLeft = tags & 0xfffffff;
- bool more;
- do
- {
- byte current = (byte)((tagsLeft >> 21) & 0x7f);
- more = (tagsLeft & 0x1fffff) != 0;
- current |= (byte)(more ? 0x80 : 0x00);
- tagsLeft <<= 7;
-
- if (metadata != null)
- {
- metadata[pos] = current;
- }
- pos++;
- }
- while (more);
- }
-
- public static byte Combine(
- int settingValue,
- byte defaultValue)
- {
- unchecked
- {
- return (byte)settingValue == settingValue
- ? (byte)settingValue
- : defaultValue;
- }
- }
-
- public static byte Combine(
- int settingValue1,
- int settingValue2,
- byte defaultValue)
- {
- unchecked
- {
- return (byte)settingValue1 == settingValue1
- ? (byte)settingValue1
- : (byte)settingValue2 == settingValue2
- ? (byte)settingValue2
- : defaultValue;
- }
- }
-
- public static int Combine(
- int settingValue1,
- int settingValue2)
- {
- unchecked
- {
- return (byte)settingValue1 == settingValue1
- ? settingValue1
- : settingValue2;
- }
- }
-
- public static void CheckName(string? name)
- {
- if (name != null && 0 <= name.IndexOf('\0'))
- {
- throw new ArgumentOutOfRangeException(nameof(name));
- }
- }
-
- public static bool ShouldOverrideFieldName(string fieldName)
- {
- return fieldName.Length <= 2 && fieldName[0] == '_';
- }
-
- public static TraceLoggingDataType MakeDataType(
- TraceLoggingDataType baseType,
- EventFieldFormat format)
- {
- return (TraceLoggingDataType)(((int)baseType & 0x1f) | ((int)format << 8));
- }
-
- /// <summary>
- /// Adjusts the native type based on format.
- /// - If format is default, return native.
- /// - If format is recognized, return the canonical type for that format.
- /// - Otherwise remove existing format from native and apply the requested format.
- /// </summary>
- public static TraceLoggingDataType Format8(
- EventFieldFormat format,
- TraceLoggingDataType native)
- {
- return format switch
- {
- EventFieldFormat.Default => native,
- EventFieldFormat.String => TraceLoggingDataType.Char8,
- EventFieldFormat.Boolean => TraceLoggingDataType.Boolean8,
- EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt8,
-#if false
- EventSourceFieldFormat.Signed => TraceLoggingDataType.Int8,
- EventSourceFieldFormat.Unsigned => TraceLoggingDataType.UInt8,
-#endif
- _ => MakeDataType(native, format),
- };
- }
-
- /// <summary>
- /// Adjusts the native type based on format.
- /// - If format is default, return native.
- /// - If format is recognized, return the canonical type for that format.
- /// - Otherwise remove existing format from native and apply the requested format.
- /// </summary>
- public static TraceLoggingDataType Format16(
- EventFieldFormat format,
- TraceLoggingDataType native)
- {
- return format switch
- {
- EventFieldFormat.Default => native,
- EventFieldFormat.String => TraceLoggingDataType.Char16,
- EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt16,
-#if false
- EventSourceFieldFormat.Port => TraceLoggingDataType.Port,
- EventSourceFieldFormat.Signed => TraceLoggingDataType.Int16,
- EventSourceFieldFormat.Unsigned => TraceLoggingDataType.UInt16,
-#endif
- _ => MakeDataType(native, format),
- };
- }
-
- /// <summary>
- /// Adjusts the native type based on format.
- /// - If format is default, return native.
- /// - If format is recognized, return the canonical type for that format.
- /// - Otherwise remove existing format from native and apply the requested format.
- /// </summary>
- public static TraceLoggingDataType Format32(
- EventFieldFormat format,
- TraceLoggingDataType native)
- {
- return format switch
- {
- EventFieldFormat.Default => native,
- EventFieldFormat.Boolean => TraceLoggingDataType.Boolean32,
- EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt32,
-#if false
- EventSourceFieldFormat.Ipv4Address => TraceLoggingDataType.Ipv4Address,
- EventSourceFieldFormat.ProcessId => TraceLoggingDataType.ProcessId,
- EventSourceFieldFormat.ThreadId => TraceLoggingDataType.ThreadId,
- EventSourceFieldFormat.Win32Error => TraceLoggingDataType.Win32Error,
- EventSourceFieldFormat.NTStatus => TraceLoggingDataType.NTStatus,
-#endif
- EventFieldFormat.HResult => TraceLoggingDataType.HResult,
-#if false
- case EventSourceFieldFormat.Signed:
- return TraceLoggingDataType.Int32;
- case EventSourceFieldFormat.Unsigned:
- return TraceLoggingDataType.UInt32;
-#endif
- _ => MakeDataType(native, format),
- };
- }
-
- /// <summary>
- /// Adjusts the native type based on format.
- /// - If format is default, return native.
- /// - If format is recognized, return the canonical type for that format.
- /// - Otherwise remove existing format from native and apply the requested format.
- /// </summary>
- public static TraceLoggingDataType Format64(
- EventFieldFormat format,
- TraceLoggingDataType native)
- {
- return format switch
- {
- EventFieldFormat.Default => native,
- EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt64,
-#if false
- EventSourceFieldFormat.FileTime => TraceLoggingDataType.FileTime,
- EventSourceFieldFormat.Signed => TraceLoggingDataType.Int64,
- EventSourceFieldFormat.Unsigned => TraceLoggingDataType.UInt64,
-#endif
- _ => MakeDataType(native, format),
- };
- }
-
- /// <summary>
- /// Adjusts the native type based on format.
- /// - If format is default, return native.
- /// - If format is recognized, return the canonical type for that format.
- /// - Otherwise remove existing format from native and apply the requested format.
- /// </summary>
- public static TraceLoggingDataType FormatPtr(
- EventFieldFormat format,
- TraceLoggingDataType native)
- {
- return format switch
- {
- EventFieldFormat.Default => native,
- EventFieldFormat.Hexadecimal => HexIntPtrType,
-#if false
- EventSourceFieldFormat.Signed => IntPtrType,
- EventSourceFieldFormat.Unsigned => UIntPtrType,
-#endif
- _ => MakeDataType(native, format),
- };
- }
-
- #endregion
-
- #region Reflection helpers
-
- /*
- All TraceLogging use of reflection APIs should go through wrappers here.
- This helps with portability, and it also makes it easier to audit what
- kinds of reflection operations are being done.
- */
-
- public static object? CreateInstance(Type type, params object?[]? parameters)
- {
- return Activator.CreateInstance(type, parameters);
- }
-
- public static bool IsValueType(Type type)
- {
- bool result = type.IsValueType();
- return result;
- }
-
- public static bool IsEnum(Type type)
- {
- bool result = type.IsEnum();
- return result;
- }
-
- public static IEnumerable<PropertyInfo> GetProperties(Type type)
- {
- IEnumerable<PropertyInfo> result = type.GetProperties();
- return result;
- }
-
- public static MethodInfo? GetGetMethod(PropertyInfo propInfo)
- {
- MethodInfo? result = propInfo.GetGetMethod();
- return result;
- }
-
- public static MethodInfo? GetDeclaredStaticMethod(Type declaringType, string name)
- {
- MethodInfo? result;
-#if (ES_BUILD_PCL || ES_BUILD_PN)
- result = declaringType.GetTypeInfo().GetDeclaredMethod(name);
-#else
- result = declaringType.GetMethod(
- name,
- BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.NonPublic);
-#endif
- return result;
- }
-
- public static bool HasCustomAttribute(
- PropertyInfo propInfo,
- Type attributeType)
- {
- bool result;
-#if (ES_BUILD_PCL || ES_BUILD_PN)
- result = propInfo.IsDefined(attributeType);
-#else
- object[] attributes = propInfo.GetCustomAttributes(
- attributeType,
- false);
- result = attributes.Length != 0;
-#endif
- return result;
- }
-
- public static AttributeType? GetCustomAttribute<AttributeType>(PropertyInfo propInfo)
- where AttributeType : Attribute
- {
- AttributeType? result = null;
-#if (ES_BUILD_PCL || ES_BUILD_PN)
- foreach (var attrib in propInfo.GetCustomAttributes<AttributeType>(false))
- {
- result = attrib;
- break;
- }
-#else
- object[] attributes = propInfo.GetCustomAttributes(typeof(AttributeType), false);
- if (attributes.Length != 0)
- {
- result = (AttributeType)attributes[0];
- }
-#endif
- return result;
- }
-
- public static AttributeType? GetCustomAttribute<AttributeType>(Type type)
- where AttributeType : Attribute
- {
- AttributeType? result = null;
-#if (ES_BUILD_PCL || ES_BUILD_PN)
- foreach (var attrib in type.GetTypeInfo().GetCustomAttributes<AttributeType>(false))
- {
- result = attrib;
- break;
- }
-#else
- object[] attributes = type.GetCustomAttributes(typeof(AttributeType), false);
- if (attributes.Length != 0)
- {
- result = (AttributeType)attributes[0];
- }
-#endif
- return result;
- }
-
- public static Type[] GetGenericArguments(Type type)
- {
- return type.GetGenericArguments();
- }
-
- public static Type? FindEnumerableElementType(Type type)
- {
- Type? elementType = null;
-
- if (IsGenericMatch(type, typeof(IEnumerable<>)))
- {
- elementType = GetGenericArguments(type)[0];
- }
- else
- {
-#if (ES_BUILD_PCL || ES_BUILD_PN)
- IEnumerable<Type> ifaceTypes = type.GetTypeInfo().ImplementedInterfaces;
-#else
- Type[] ifaceTypes = type.FindInterfaces(IsGenericMatch, typeof(IEnumerable<>));
-#endif
-
- foreach (Type ifaceType in ifaceTypes)
- {
-#if (ES_BUILD_PCL || ES_BUILD_PN)
- if (!IsGenericMatch(ifaceType, typeof(IEnumerable<>)))
- {
- continue;
- }
-#endif
-
- if (elementType != null)
- {
- // ambiguous match. report no match at all.
- elementType = null;
- break;
- }
-
- elementType = GetGenericArguments(ifaceType)[0];
- }
- }
-
- return elementType;
- }
-
- public static bool IsGenericMatch(Type type, object? openType)
- {
- return type.IsGenericType() && type.GetGenericTypeDefinition() == (Type?)openType;
- }
-
- public static Delegate CreateDelegate(Type delegateType, MethodInfo methodInfo)
- {
- Delegate result;
-#if (ES_BUILD_PCL || ES_BUILD_PN)
- result = methodInfo.CreateDelegate(
- delegateType);
-#else
- result = Delegate.CreateDelegate(
- delegateType,
- methodInfo);
-#endif
- return result;
- }
-
- public static TraceLoggingTypeInfo CreateDefaultTypeInfo(
- Type dataType,
- List<Type> recursionCheck)
- {
- TraceLoggingTypeInfo result;
-
- if (recursionCheck.Contains(dataType))
- {
- throw new NotSupportedException(SR.EventSource_RecursiveTypeDefinition);
- }
-
- recursionCheck.Add(dataType);
-
- EventDataAttribute? eventAttrib = Statics.GetCustomAttribute<EventDataAttribute>(dataType);
- if (eventAttrib != null ||
- Statics.GetCustomAttribute<CompilerGeneratedAttribute>(dataType) != null ||
- IsGenericMatch(dataType, typeof(KeyValuePair<,>)))
- {
- var analysis = new TypeAnalysis(dataType, eventAttrib, recursionCheck);
- result = new InvokeTypeInfo(dataType, analysis);
- }
- else if (dataType.IsArray)
- {
- Type elementType = dataType.GetElementType()!;
- if (elementType == typeof(bool))
- {
- result = ScalarArrayTypeInfo.Boolean();
- }
- else if (elementType == typeof(byte))
- {
- result = ScalarArrayTypeInfo.Byte();
- }
- else if (elementType == typeof(sbyte))
- {
- result = ScalarArrayTypeInfo.SByte();
- }
- else if (elementType == typeof(short))
- {
- result = ScalarArrayTypeInfo.Int16();
- }
- else if (elementType == typeof(ushort))
- {
- result = ScalarArrayTypeInfo.UInt16();
- }
- else if (elementType == typeof(int))
- {
- result = ScalarArrayTypeInfo.Int32();
- }
- else if (elementType == typeof(uint))
- {
- result = ScalarArrayTypeInfo.UInt32();
- }
- else if (elementType == typeof(long))
- {
- result = ScalarArrayTypeInfo.Int64();
- }
- else if (elementType == typeof(ulong))
- {
- result = ScalarArrayTypeInfo.UInt64();
- }
- else if (elementType == typeof(char))
- {
- result = ScalarArrayTypeInfo.Char();
- }
- else if (elementType == typeof(double))
- {
- result = ScalarArrayTypeInfo.Double();
- }
- else if (elementType == typeof(float))
- {
- result = ScalarArrayTypeInfo.Single();
- }
- else if (elementType == typeof(IntPtr))
- {
- result = ScalarArrayTypeInfo.IntPtr();
- }
- else if (elementType == typeof(UIntPtr))
- {
- result = ScalarArrayTypeInfo.UIntPtr();
- }
- else if (elementType == typeof(Guid))
- {
- result = ScalarArrayTypeInfo.Guid();
- }
- else
- {
- result = new ArrayTypeInfo(dataType, TraceLoggingTypeInfo.GetInstance(elementType, recursionCheck));
- }
- }
- else
- {
- if (Statics.IsEnum(dataType))
- dataType = Enum.GetUnderlyingType(dataType);
-
- if (dataType == typeof(string))
- {
- result = new StringTypeInfo();
- }
- else if (dataType == typeof(bool))
- {
- result = ScalarTypeInfo.Boolean();
- }
- else if (dataType == typeof(byte))
- {
- result = ScalarTypeInfo.Byte();
- }
- else if (dataType == typeof(sbyte))
- {
- result = ScalarTypeInfo.SByte();
- }
- else if (dataType == typeof(short))
- {
- result = ScalarTypeInfo.Int16();
- }
- else if (dataType == typeof(ushort))
- {
- result = ScalarTypeInfo.UInt16();
- }
- else if (dataType == typeof(int))
- {
- result = ScalarTypeInfo.Int32();
- }
- else if (dataType == typeof(uint))
- {
- result = ScalarTypeInfo.UInt32();
- }
- else if (dataType == typeof(long))
- {
- result = ScalarTypeInfo.Int64();
- }
- else if (dataType == typeof(ulong))
- {
- result = ScalarTypeInfo.UInt64();
- }
- else if (dataType == typeof(char))
- {
- result = ScalarTypeInfo.Char();
- }
- else if (dataType == typeof(double))
- {
- result = ScalarTypeInfo.Double();
- }
- else if (dataType == typeof(float))
- {
- result = ScalarTypeInfo.Single();
- }
- else if (dataType == typeof(DateTime))
- {
- result = new DateTimeTypeInfo();
- }
- else if (dataType == typeof(decimal))
- {
- result = new DecimalTypeInfo();
- }
- else if (dataType == typeof(IntPtr))
- {
- result = ScalarTypeInfo.IntPtr();
- }
- else if (dataType == typeof(UIntPtr))
- {
- result = ScalarTypeInfo.UIntPtr();
- }
- else if (dataType == typeof(Guid))
- {
- result = ScalarTypeInfo.Guid();
- }
- else if (dataType == typeof(TimeSpan))
- {
- result = new TimeSpanTypeInfo();
- }
- else if (dataType == typeof(DateTimeOffset))
- {
- result = new DateTimeOffsetTypeInfo();
- }
- else if (dataType == typeof(EmptyStruct))
- {
- result = new NullTypeInfo();
- }
- else if (IsGenericMatch(dataType, typeof(Nullable<>)))
- {
- result = new NullableTypeInfo(dataType, recursionCheck);
- }
- else
- {
- Type? elementType = FindEnumerableElementType(dataType);
- if (elementType != null)
- {
- result = new EnumerableTypeInfo(dataType, TraceLoggingTypeInfo.GetInstance(elementType, recursionCheck));
- }
- else
- {
- throw new ArgumentException(SR.Format(SR.EventSource_NonCompliantTypeError, dataType.Name));
- }
- }
- }
-
- return result;
- }
-
- #endregion
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingDataCollector.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingDataCollector.cs
deleted file mode 100644
index a5b7621b647..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingDataCollector.cs
+++ /dev/null
@@ -1,125 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: Used when implementing a custom TraceLoggingTypeInfo.
- /// The instance of this type is provided to the TypeInfo.WriteData method.
- /// All operations are forwarded to the current thread's DataCollector.
- /// Note that this abstraction would allow us to expose the custom
- /// serialization system to partially-trusted code. If we end up not
- /// making custom serialization public, or if we only expose it to
- /// full-trust code, this abstraction is unnecessary (though it probably
- /// doesn't hurt anything).
- /// </summary>
- internal unsafe class TraceLoggingDataCollector
- {
- internal static readonly TraceLoggingDataCollector Instance = new TraceLoggingDataCollector();
-
- private TraceLoggingDataCollector()
- {
- return;
- }
-
- /// <summary>
- /// Marks the start of a non-blittable array or enumerable.
- /// </summary>
- /// <returns>Bookmark to be passed to EndBufferedArray.</returns>
- public int BeginBufferedArray()
- {
- return DataCollector.ThreadInstance.BeginBufferedArray();
- }
-
- /// <summary>
- /// Marks the end of a non-blittable array or enumerable.
- /// </summary>
- /// <param name="bookmark">The value returned by BeginBufferedArray.</param>
- /// <param name="count">The number of items in the array.</param>
- public void EndBufferedArray(int bookmark, int count)
- {
- DataCollector.ThreadInstance.EndBufferedArray(bookmark, count);
- }
-
- /// <summary>
- /// Adds the start of a group to the event.
- /// This has no effect on the event payload, but is provided to allow
- /// WriteMetadata and WriteData implementations to have similar
- /// sequences of calls, allowing for easier verification of correctness.
- /// </summary>
- public TraceLoggingDataCollector AddGroup()
- {
- return this;
- }
-
- public void AddScalar(PropertyValue value)
- {
- PropertyValue.Scalar scalar = value.ScalarValue;
- DataCollector.ThreadInstance.AddScalar(&scalar, value.ScalarLength);
- }
-
- /// <summary>
- /// Adds an Int64 value to the event payload.
- /// </summary>
- /// <param name="value">Value to be added.</param>
- public void AddScalar(long value)
- {
- DataCollector.ThreadInstance.AddScalar(&value, sizeof(long));
- }
-
- /// <summary>
- /// Adds a Double value to the event payload.
- /// </summary>
- /// <param name="value">Value to be added.</param>
- public void AddScalar(double value)
- {
- DataCollector.ThreadInstance.AddScalar(&value, sizeof(double));
- }
-
- /// <summary>
- /// Adds a Boolean value to the event payload.
- /// </summary>
- /// <param name="value">Value to be added.</param>
- public void AddScalar(bool value)
- {
- DataCollector.ThreadInstance.AddScalar(&value, sizeof(bool));
- }
-
- /// <summary>
- /// Adds a null-terminated String value to the event payload.
- /// </summary>
- /// <param name="value">
- /// Value to be added. A null value is treated as a zero-length string.
- /// </param>
- public void AddNullTerminatedString(string? value)
- {
- DataCollector.ThreadInstance.AddNullTerminatedString(value);
- }
-
- /// <summary>
- /// Adds a counted String value to the event payload.
- /// </summary>
- /// <param name="value">
- /// Value to be added. A null value is treated as a zero-length string.
- /// </param>
- public void AddBinary(string? value)
- {
- DataCollector.ThreadInstance.AddBinary(value, value == null ? 0 : value.Length * 2);
- }
-
- public void AddArray(PropertyValue value, int elementSize)
- {
- Array? array = (Array?)value.ReferenceValue;
- DataCollector.ThreadInstance.AddArray(array, array == null ? 0 : array.Length, elementSize);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingDataType.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingDataType.cs
deleted file mode 100644
index a71bf635756..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingDataType.cs
+++ /dev/null
@@ -1,351 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: Used when implementing a custom TraceLoggingTypeInfo.
- /// These are passed to metadataCollector.Add to specify the low-level
- /// type of a field in the event payload. Note that a "formatted"
- /// TraceLoggingDataType consists of a core TraceLoggingDataType value
- /// (a TraceLoggingDataType with a value less than 32) plus an OutType.
- /// Any combination of TraceLoggingDataType + OutType is valid, but not
- /// all are useful. In particular, combinations not explicitly listed
- /// below are unlikely to be recognized by decoders, and will typically
- /// be decoded as the corresponding core type (i.e. the decoder will
- /// mask off any unrecognized OutType value).
- /// </summary>
- internal enum TraceLoggingDataType
- {
- /// <summary>
- /// Core type.
- /// Data type with no value (0-length payload).
- /// NOTE: arrays of Nil are illegal.
- /// NOTE: a fixed-length array of Nil is interpreted by the decoder as
- /// a struct (obsolete but retained for backwards-compatibility).
- /// </summary>
- Nil = 0,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes null-terminated Char16 string.
- /// Decoding treats as UTF-16LE string.
- /// </summary>
- Utf16String = 1,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes null-terminated Char8 string.
- /// Decoding treats as MBCS string.
- /// </summary>
- MbcsString = 2,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 8-bit value.
- /// Decoding treats as signed integer.
- /// </summary>
- Int8 = 3,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 8-bit value.
- /// Decoding treats as unsigned integer.
- /// </summary>
- UInt8 = 4,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 16-bit value.
- /// Decoding treats as signed integer.
- /// </summary>
- Int16 = 5,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 16-bit value.
- /// Decoding treats as unsigned integer.
- /// </summary>
- UInt16 = 6,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 32-bit value.
- /// Decoding treats as signed integer.
- /// </summary>
- Int32 = 7,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 32-bit value.
- /// Decoding treats as unsigned integer.
- /// </summary>
- UInt32 = 8,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 64-bit value.
- /// Decoding treats as signed integer.
- /// </summary>
- Int64 = 9,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 64-bit value.
- /// Decoding treats as unsigned integer.
- /// </summary>
- UInt64 = 10,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 32-bit value.
- /// Decoding treats as Float.
- /// </summary>
- Float = 11,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 64-bit value.
- /// Decoding treats as Double.
- /// </summary>
- Double = 12,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 32-bit value.
- /// Decoding treats as Boolean.
- /// </summary>
- Boolean32 = 13,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 16-bit bytecount followed by binary data.
- /// Decoding treats as binary data.
- /// </summary>
- Binary = 14,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 16-byte value.
- /// Decoding treats as GUID.
- /// </summary>
- Guid = 15,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 64-bit value.
- /// Decoding treats as FILETIME.
- /// </summary>
- FileTime = 17,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 16-byte value.
- /// Decoding treats as SYSTEMTIME.
- /// </summary>
- SystemTime = 18,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 32-bit value.
- /// Decoding treats as hexadecimal unsigned integer.
- /// </summary>
- HexInt32 = 20,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 64-bit value.
- /// Decoding treats as hexadecimal unsigned integer.
- /// </summary>
- HexInt64 = 21,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 16-bit bytecount followed by Char16 data.
- /// Decoding treats as UTF-16LE string.
- /// </summary>
- CountedUtf16String = 22,
-
- /// <summary>
- /// Core type.
- /// Encoding assumes 16-bit bytecount followed by Char8 data.
- /// Decoding treats as MBCS string.
- /// </summary>
- CountedMbcsString = 23,
-
- /// <summary>
- /// Core type.
- /// Special case: Struct indicates that this field plus the
- /// subsequent N logical fields are to be considered as one logical
- /// field (i.e. a nested structure). The OutType is used to encode N.
- /// The maximum value for N is 127. This field has no payload by
- /// itself, but logically contains the payload of the following N
- /// fields. It is legal to have an array of Struct.
- /// </summary>
- Struct = 24,
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 16-bit value.
- /// Decoding treats as UTF-16LE character.
- /// </summary>
- Char16 = UInt16 + (EventFieldFormat.String << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 8-bit value.
- /// Decoding treats as character.
- /// </summary>
- Char8 = UInt8 + (EventFieldFormat.String << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 8-bit value.
- /// Decoding treats as Boolean.
- /// </summary>
- Boolean8 = UInt8 + (EventFieldFormat.Boolean << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 8-bit value.
- /// Decoding treats as hexadecimal unsigned integer.
- /// </summary>
- HexInt8 = UInt8 + (EventFieldFormat.Hexadecimal << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 16-bit value.
- /// Decoding treats as hexadecimal unsigned integer.
- /// </summary>
- HexInt16 = UInt16 + (EventFieldFormat.Hexadecimal << 8),
-
-#if false
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 32-bit value.
- /// Decoding treats as process identifier.
- /// </summary>
- ProcessId = UInt32 + (EventSourceFieldFormat.ProcessId << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 32-bit value.
- /// Decoding treats as thread identifier.
- /// </summary>
- ThreadId = UInt32 + (EventSourceFieldFormat.ThreadId << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 16-bit value.
- /// Decoding treats as IP port.
- /// </summary>
- Port = UInt16 + (EventSourceFieldFormat.Port << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 32-bit value.
- /// Decoding treats as IPv4 address.
- /// </summary>
- Ipv4Address = UInt32 + (EventSourceFieldFormat.Ipv4Address << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 16-bit bytecount followed by binary data.
- /// Decoding treats as IPv6 address.
- /// </summary>
- Ipv6Address = Binary + (EventSourceFieldFormat.Ipv6Address << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 16-bit bytecount followed by binary data.
- /// Decoding treats as SOCKADDR.
- /// </summary>
- SocketAddress = Binary + (EventSourceFieldFormat.SocketAddress << 8),
-#endif
- /// <summary>
- /// Formatted type.
- /// Encoding assumes null-terminated Char16 string.
- /// Decoding treats as UTF-16LE XML string.
- /// </summary>
- Utf16Xml = Utf16String + (EventFieldFormat.Xml << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes null-terminated Char8 string.
- /// Decoding treats as MBCS XML string.
- /// </summary>
- MbcsXml = MbcsString + (EventFieldFormat.Xml << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 16-bit bytecount followed by Char16 data.
- /// Decoding treats as UTF-16LE XML.
- /// </summary>
- CountedUtf16Xml = CountedUtf16String + (EventFieldFormat.Xml << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 16-bit bytecount followed by Char8 data.
- /// Decoding treats as MBCS XML.
- /// </summary>
- CountedMbcsXml = CountedMbcsString + (EventFieldFormat.Xml << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes null-terminated Char16 string.
- /// Decoding treats as UTF-16LE JSON string.
- /// </summary>
- Utf16Json = Utf16String + (EventFieldFormat.Json << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes null-terminated Char8 string.
- /// Decoding treats as MBCS JSON string.
- /// </summary>
- MbcsJson = MbcsString + (EventFieldFormat.Json << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 16-bit bytecount followed by Char16 data.
- /// Decoding treats as UTF-16LE JSON.
- /// </summary>
- CountedUtf16Json = CountedUtf16String + (EventFieldFormat.Json << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 16-bit bytecount followed by Char8 data.
- /// Decoding treats as MBCS JSON.
- /// </summary>
- CountedMbcsJson = CountedMbcsString + (EventFieldFormat.Json << 8),
-#if false
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 32-bit value.
- /// Decoding treats as Win32 error.
- /// </summary>
- Win32Error = UInt32 + (EventSourceFieldFormat.Win32Error << 8),
-
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 32-bit value.
- /// Decoding treats as NTSTATUS.
- /// </summary>
- NTStatus = UInt32 + (EventSourceFieldFormat.NTStatus << 8),
-#endif
- /// <summary>
- /// Formatted type.
- /// Encoding assumes 32-bit value.
- /// Decoding treats as HRESULT.
- /// </summary>
- HResult = Int32 + (EventFieldFormat.HResult << 8)
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs
deleted file mode 100644
index 3302018a214..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs
+++ /dev/null
@@ -1,890 +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.
-
-// This program uses code hyperlinks available as part of the HyperAddin Visual Studio plug-in.
-// It is available from http://www.codeplex.com/hyperAddin
-
-#if PLATFORM_WINDOWS
-#define FEATURE_MANAGED_ETW
-#endif // PLATFORM_WINDOWS
-
-#if ES_BUILD_STANDALONE
-#define FEATURE_MANAGED_ETW_CHANNELS
-// #define FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
-#endif
-
-#if ES_BUILD_STANDALONE
-using System;
-using System.Diagnostics;
-using Environment = Microsoft.Diagnostics.Tracing.Internal.Environment;
-using EventDescriptor = Microsoft.Diagnostics.Tracing.EventDescriptor;
-#endif
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Runtime.InteropServices;
-using System.Text;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- public partial class EventSource
- {
-#if FEATURE_MANAGED_ETW
- private byte[] providerMetadata = null!;
-#endif
-
-#if FEATURE_PERFTRACING
- private readonly TraceLoggingEventHandleTable m_eventHandleTable = new TraceLoggingEventHandleTable();
-#endif
-
- /// <summary>
- /// Construct an EventSource with a given name for non-contract based events (e.g. those using the Write() API).
- /// </summary>
- /// <param name="eventSourceName">
- /// The name of the event source. Must not be null.
- /// </param>
- public EventSource(
- string eventSourceName)
- : this(eventSourceName, EventSourceSettings.EtwSelfDescribingEventFormat)
- { }
-
- /// <summary>
- /// Construct an EventSource with a given name for non-contract based events (e.g. those using the Write() API).
- /// </summary>
- /// <param name="eventSourceName">
- /// The name of the event source. Must not be null.
- /// </param>
- /// <param name="config">
- /// Configuration options for the EventSource as a whole.
- /// </param>
- public EventSource(
- string eventSourceName,
- EventSourceSettings config)
- : this(eventSourceName, config, null) { }
-
- /// <summary>
- /// Construct an EventSource with a given name for non-contract based events (e.g. those using the Write() API).
- ///
- /// Also specify a list of key-value pairs called traits (you must pass an even number of strings).
- /// The first string is the key and the second is the value. These are not interpreted by EventSource
- /// itself but may be interpreted the listeners. Can be fetched with GetTrait(string).
- /// </summary>
- /// <param name="eventSourceName">
- /// The name of the event source. Must not be null.
- /// </param>
- /// <param name="config">
- /// Configuration options for the EventSource as a whole.
- /// </param>
- /// <param name="traits">A collection of key-value strings (must be an even number).</param>
- public EventSource(
- string eventSourceName,
- EventSourceSettings config,
- params string[]? traits)
- : this(
- eventSourceName == null ? default : GenerateGuidFromName(eventSourceName.ToUpperInvariant()),
- eventSourceName!,
- config, traits)
- {
- if (eventSourceName == null)
- {
- throw new ArgumentNullException(nameof(eventSourceName));
- }
- }
-
- /// <summary>
- /// Writes an event with no fields and default options.
- /// (Native API: EventWriteTransfer)
- /// </summary>
- /// <param name="eventName">The name of the event.</param>
- public unsafe void Write(string? eventName)
- {
- if (!this.IsEnabled())
- {
- return;
- }
-
- EventSourceOptions options = default;
- this.WriteImpl(eventName, ref options, null, null, null, SimpleEventTypes<EmptyStruct>.Instance);
- }
-
- /// <summary>
- /// Writes an event with no fields.
- /// (Native API: EventWriteTransfer)
- /// </summary>
- /// <param name="eventName">The name of the event.</param>
- /// <param name="options">
- /// Options for the event, such as the level, keywords, and opcode. Unset
- /// options will be set to default values.
- /// </param>
- public unsafe void Write(string? eventName, EventSourceOptions options)
- {
- if (!this.IsEnabled())
- {
- return;
- }
-
- this.WriteImpl(eventName, ref options, null, null, null, SimpleEventTypes<EmptyStruct>.Instance);
- }
-
- /// <summary>
- /// Writes an event.
- /// (Native API: EventWriteTransfer)
- /// </summary>
- /// <typeparam name="T">
- /// The type that defines the event and its payload. This must be an
- /// anonymous type or a type with an [EventData] attribute.
- /// </typeparam>
- /// <param name="eventName">
- /// The name for the event. If null, the event name is automatically
- /// determined based on T, either from the Name property of T's EventData
- /// attribute or from typeof(T).Name.
- /// </param>
- /// <param name="data">
- /// The object containing the event payload data. The type T must be
- /// an anonymous type or a type with an [EventData] attribute. The
- /// public instance properties of data will be written recursively to
- /// create the fields of the event.
- /// </param>
- public unsafe void Write<T>(
- string? eventName,
- T data)
- {
- if (!this.IsEnabled())
- {
- return;
- }
-
- EventSourceOptions options = default;
- this.WriteImpl(eventName, ref options, data, null, null, SimpleEventTypes<T>.Instance);
- }
-
- /// <summary>
- /// Writes an event.
- /// (Native API: EventWriteTransfer)
- /// </summary>
- /// <typeparam name="T">
- /// The type that defines the event and its payload. This must be an
- /// anonymous type or a type with an [EventData] attribute.
- /// </typeparam>
- /// <param name="eventName">
- /// The name for the event. If null, the event name is automatically
- /// determined based on T, either from the Name property of T's EventData
- /// attribute or from typeof(T).Name.
- /// </param>
- /// <param name="options">
- /// Options for the event, such as the level, keywords, and opcode. Unset
- /// options will be set to default values.
- /// </param>
- /// <param name="data">
- /// The object containing the event payload data. The type T must be
- /// an anonymous type or a type with an [EventData] attribute. The
- /// public instance properties of data will be written recursively to
- /// create the fields of the event.
- /// </param>
- public unsafe void Write<T>(
- string? eventName,
- EventSourceOptions options,
- T data)
- {
- if (!this.IsEnabled())
- {
- return;
- }
-
- this.WriteImpl(eventName, ref options, data, null, null, SimpleEventTypes<T>.Instance);
- }
-
- /// <summary>
- /// Writes an event.
- /// This overload is for use with extension methods that wish to efficiently
- /// forward the options or data parameter without performing an extra copy.
- /// (Native API: EventWriteTransfer)
- /// </summary>
- /// <typeparam name="T">
- /// The type that defines the event and its payload. This must be an
- /// anonymous type or a type with an [EventData] attribute.
- /// </typeparam>
- /// <param name="eventName">
- /// The name for the event. If null, the event name is automatically
- /// determined based on T, either from the Name property of T's EventData
- /// attribute or from typeof(T).Name.
- /// </param>
- /// <param name="options">
- /// Options for the event, such as the level, keywords, and opcode. Unset
- /// options will be set to default values.
- /// </param>
- /// <param name="data">
- /// The object containing the event payload data. The type T must be
- /// an anonymous type or a type with an [EventData] attribute. The
- /// public instance properties of data will be written recursively to
- /// create the fields of the event.
- /// </param>
- public unsafe void Write<T>(
- string? eventName,
- ref EventSourceOptions options,
- ref T data)
- {
- if (!this.IsEnabled())
- {
- return;
- }
-
- this.WriteImpl(eventName, ref options, data, null, null, SimpleEventTypes<T>.Instance);
- }
-
- /// <summary>
- /// Writes an event.
- /// This overload is meant for clients that need to manipuate the activityId
- /// and related ActivityId for the event.
- /// </summary>
- /// <typeparam name="T">
- /// The type that defines the event and its payload. This must be an
- /// anonymous type or a type with an [EventData] attribute.
- /// </typeparam>
- /// <param name="eventName">
- /// The name for the event. If null, the event name is automatically
- /// determined based on T, either from the Name property of T's EventData
- /// attribute or from typeof(T).Name.
- /// </param>
- /// <param name="options">
- /// Options for the event, such as the level, keywords, and opcode. Unset
- /// options will be set to default values.
- /// </param>
- /// <param name="activityId">
- /// The GUID of the activity associated with this event.
- /// </param>
- /// <param name="relatedActivityId">
- /// The GUID of another activity that is related to this activity, or Guid.Empty
- /// if there is no related activity. Most commonly, the Start operation of a
- /// new activity specifies a parent activity as its related activity.
- /// </param>
- /// <param name="data">
- /// The object containing the event payload data. The type T must be
- /// an anonymous type or a type with an [EventData] attribute. The
- /// public instance properties of data will be written recursively to
- /// create the fields of the event.
- /// </param>
- public unsafe void Write<T>(
- string? eventName,
- ref EventSourceOptions options,
- ref Guid activityId,
- ref Guid relatedActivityId,
- ref T data)
- {
- if (!this.IsEnabled())
- {
- return;
- }
-
- fixed (Guid* pActivity = &activityId, pRelated = &relatedActivityId)
- {
- this.WriteImpl(
- eventName,
- ref options,
- data,
- pActivity,
- relatedActivityId == Guid.Empty ? null : pRelated,
- SimpleEventTypes<T>.Instance);
- }
- }
-
- /// <summary>
- /// Writes an extended event, where the values of the event are the
- /// combined properties of any number of values. This method is
- /// intended for use in advanced logging scenarios that support a
- /// dynamic set of event context providers.
- /// This method does a quick check on whether this event is enabled.
- /// </summary>
- /// <param name="eventName">
- /// The name for the event. If null, the name from eventTypes is used.
- /// (Note that providing the event name via the name parameter is slightly
- /// less efficient than using the name from eventTypes.)
- /// </param>
- /// <param name="options">
- /// Optional overrides for the event, such as the level, keyword, opcode,
- /// activityId, and relatedActivityId. Any settings not specified by options
- /// are obtained from eventTypes.
- /// </param>
- /// <param name="eventTypes">
- /// Information about the event and the types of the values in the event.
- /// Must not be null. Note that the eventTypes object should be created once and
- /// saved. It should not be recreated for each event.
- /// </param>
- /// <param name="activityID">
- /// A pointer to the activity ID GUID to log
- /// </param>
- /// <param name="childActivityID">
- /// A pointer to the child activity ID to log (can be null) </param>
- /// <param name="values">
- /// The values to include in the event. Must not be null. The number and types of
- /// the values must match the number and types of the fields described by the
- /// eventTypes parameter.
- /// </param>
- private unsafe void WriteMultiMerge(
- string? eventName,
- ref EventSourceOptions options,
- TraceLoggingEventTypes eventTypes,
- Guid* activityID,
- Guid* childActivityID,
- params object?[] values)
- {
- if (!this.IsEnabled())
- {
- return;
- }
- byte level = (options.valuesSet & EventSourceOptions.levelSet) != 0
- ? options.level
- : eventTypes.level;
- EventKeywords keywords = (options.valuesSet & EventSourceOptions.keywordsSet) != 0
- ? options.keywords
- : eventTypes.keywords;
-
- if (this.IsEnabled((EventLevel)level, keywords))
- {
- WriteMultiMergeInner(eventName, ref options, eventTypes, activityID, childActivityID, values);
- }
- }
-
- /// <summary>
- /// Writes an extended event, where the values of the event are the
- /// combined properties of any number of values. This method is
- /// intended for use in advanced logging scenarios that support a
- /// dynamic set of event context providers.
- /// Attention: This API does not check whether the event is enabled or not.
- /// Please use WriteMultiMerge to avoid spending CPU cycles for events that are
- /// not enabled.
- /// </summary>
- /// <param name="eventName">
- /// The name for the event. If null, the name from eventTypes is used.
- /// (Note that providing the event name via the name parameter is slightly
- /// less efficient than using the name from eventTypes.)
- /// </param>
- /// <param name="options">
- /// Optional overrides for the event, such as the level, keyword, opcode,
- /// activityId, and relatedActivityId. Any settings not specified by options
- /// are obtained from eventTypes.
- /// </param>
- /// <param name="eventTypes">
- /// Information about the event and the types of the values in the event.
- /// Must not be null. Note that the eventTypes object should be created once and
- /// saved. It should not be recreated for each event.
- /// </param>
- /// <param name="activityID">
- /// A pointer to the activity ID GUID to log
- /// </param>
- /// <param name="childActivityID">
- /// A pointer to the child activity ID to log (can be null)
- /// </param>
- /// <param name="values">
- /// The values to include in the event. Must not be null. The number and types of
- /// the values must match the number and types of the fields described by the
- /// eventTypes parameter.
- /// </param>
- private unsafe void WriteMultiMergeInner(
- string? eventName,
- ref EventSourceOptions options,
- TraceLoggingEventTypes eventTypes,
- Guid* activityID,
- Guid* childActivityID,
- params object?[] values)
- {
-#if FEATURE_MANAGED_ETW
- int identity = 0;
- byte level = (options.valuesSet & EventSourceOptions.levelSet) != 0
- ? options.level
- : eventTypes.level;
- byte opcode = (options.valuesSet & EventSourceOptions.opcodeSet) != 0
- ? options.opcode
- : eventTypes.opcode;
- EventTags tags = (options.valuesSet & EventSourceOptions.tagsSet) != 0
- ? options.tags
- : eventTypes.Tags;
- EventKeywords keywords = (options.valuesSet & EventSourceOptions.keywordsSet) != 0
- ? options.keywords
- : eventTypes.keywords;
-
- NameInfo nameInfo = eventTypes.GetNameInfo(eventName ?? eventTypes.Name, tags);
- if (nameInfo == null)
- {
- return;
- }
- identity = nameInfo.identity;
- EventDescriptor descriptor = new EventDescriptor(identity, level, opcode, (long)keywords);
-
-#if FEATURE_PERFTRACING
- IntPtr eventHandle = nameInfo.GetOrCreateEventHandle(m_eventPipeProvider, m_eventHandleTable, descriptor, eventTypes);
- Debug.Assert(eventHandle != IntPtr.Zero);
-#else
- IntPtr eventHandle = IntPtr.Zero;
-#endif
-
- int pinCount = eventTypes.pinCount;
- byte* scratch = stackalloc byte[eventTypes.scratchSize];
- EventData* descriptors = stackalloc EventData[eventTypes.dataCount + 3];
- for (int i = 0; i < eventTypes.dataCount + 3; i++)
- descriptors[i] = default;
-
- GCHandle* pins = stackalloc GCHandle[pinCount];
- for (int i = 0; i < pinCount; i++)
- pins[i] = default;
-
- fixed (byte*
- pMetadata0 = this.providerMetadata,
- pMetadata1 = nameInfo.nameMetadata,
- pMetadata2 = eventTypes.typeMetadata)
- {
- descriptors[0].SetMetadata(pMetadata0, this.providerMetadata.Length, 2);
- descriptors[1].SetMetadata(pMetadata1, nameInfo.nameMetadata.Length, 1);
- descriptors[2].SetMetadata(pMetadata2, eventTypes.typeMetadata.Length, 1);
-
-#if (!ES_BUILD_PCL && !ES_BUILD_PN)
- System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
-#endif
- try
- {
- DataCollector.ThreadInstance.Enable(
- scratch,
- eventTypes.scratchSize,
- descriptors + 3,
- eventTypes.dataCount,
- pins,
- pinCount);
-
- for (int i = 0; i < eventTypes.typeInfos.Length; i++)
- {
- TraceLoggingTypeInfo info = eventTypes.typeInfos[i];
- info.WriteData(TraceLoggingDataCollector.Instance, info.PropertyValueFactory(values[i]));
- }
-
- this.WriteEventRaw(
- eventName,
- ref descriptor,
- eventHandle,
- activityID,
- childActivityID,
- (int)(DataCollector.ThreadInstance.Finish() - descriptors),
- (IntPtr)descriptors);
- }
- finally
- {
- WriteCleanup(pins, pinCount);
- }
- }
-#endif // FEATURE_MANAGED_ETW
- }
-
- /// <summary>
- /// Writes an extended event, where the values of the event have already
- /// been serialized in "data".
- /// </summary>
- /// <param name="eventName">
- /// The name for the event. If null, the name from eventTypes is used.
- /// (Note that providing the event name via the name parameter is slightly
- /// less efficient than using the name from eventTypes.)
- /// </param>
- /// <param name="options">
- /// Optional overrides for the event, such as the level, keyword, opcode,
- /// activityId, and relatedActivityId. Any settings not specified by options
- /// are obtained from eventTypes.
- /// </param>
- /// <param name="eventTypes">
- /// Information about the event and the types of the values in the event.
- /// Must not be null. Note that the eventTypes object should be created once and
- /// saved. It should not be recreated for each event.
- /// </param>
- /// <param name="activityID">
- /// A pointer to the activity ID GUID to log
- /// </param>
- /// <param name="childActivityID">
- /// A pointer to the child activity ID to log (can be null)
- /// </param>
- /// <param name="data">
- /// The previously serialized values to include in the event. Must not be null.
- /// The number and types of the values must match the number and types of the
- /// fields described by the eventTypes parameter.
- /// </param>
- internal unsafe void WriteMultiMerge(
- string? eventName,
- ref EventSourceOptions options,
- TraceLoggingEventTypes eventTypes,
- Guid* activityID,
- Guid* childActivityID,
- EventData* data)
- {
-#if FEATURE_MANAGED_ETW
- if (!this.IsEnabled())
- {
- return;
- }
-
- fixed (EventSourceOptions* pOptions = &options)
- {
- EventDescriptor descriptor;
- NameInfo? nameInfo = this.UpdateDescriptor(eventName, eventTypes, ref options, out descriptor);
- if (nameInfo == null)
- {
- return;
- }
-
-#if FEATURE_PERFTRACING
- IntPtr eventHandle = nameInfo.GetOrCreateEventHandle(m_eventPipeProvider, m_eventHandleTable, descriptor, eventTypes);
- Debug.Assert(eventHandle != IntPtr.Zero);
-#else
- IntPtr eventHandle = IntPtr.Zero;
-#endif
-
- // We make a descriptor for each EventData, and because we morph strings to counted strings
- // we may have 2 for each arg, so we allocate enough for this.
- int descriptorsLength = eventTypes.dataCount + eventTypes.typeInfos.Length * 2 + 3;
- EventData* descriptors = stackalloc EventData[descriptorsLength];
- for (int i = 0; i < descriptorsLength; i++)
- descriptors[i] = default;
-
- fixed (byte*
- pMetadata0 = this.providerMetadata,
- pMetadata1 = nameInfo.nameMetadata,
- pMetadata2 = eventTypes.typeMetadata)
- {
- descriptors[0].SetMetadata(pMetadata0, this.providerMetadata.Length, 2);
- descriptors[1].SetMetadata(pMetadata1, nameInfo.nameMetadata.Length, 1);
- descriptors[2].SetMetadata(pMetadata2, eventTypes.typeMetadata.Length, 1);
- int numDescrs = 3;
-
- for (int i = 0; i < eventTypes.typeInfos.Length; i++)
- {
- descriptors[numDescrs].m_Ptr = data[i].m_Ptr;
- descriptors[numDescrs].m_Size = data[i].m_Size;
-
- // old conventions for bool is 4 bytes, but meta-data assumes 1.
- if (data[i].m_Size == 4 && eventTypes.typeInfos[i].DataType == typeof(bool))
- descriptors[numDescrs].m_Size = 1;
-
- numDescrs++;
- }
-
- this.WriteEventRaw(
- eventName,
- ref descriptor,
- eventHandle,
- activityID,
- childActivityID,
- numDescrs,
- (IntPtr)descriptors);
- }
- }
-#endif // FEATURE_MANAGED_ETW
- }
-
- private unsafe void WriteImpl(
- string? eventName,
- ref EventSourceOptions options,
- object? data,
- Guid* pActivityId,
- Guid* pRelatedActivityId,
- TraceLoggingEventTypes eventTypes)
- {
- try
- {
- fixed (EventSourceOptions* pOptions = &options)
- {
- EventDescriptor descriptor;
- options.Opcode = options.IsOpcodeSet ? options.Opcode : GetOpcodeWithDefault(options.Opcode, eventName);
- NameInfo? nameInfo = this.UpdateDescriptor(eventName, eventTypes, ref options, out descriptor);
- if (nameInfo == null)
- {
- return;
- }
-
-#if FEATURE_PERFTRACING
- IntPtr eventHandle = nameInfo.GetOrCreateEventHandle(m_eventPipeProvider, m_eventHandleTable, descriptor, eventTypes);
- Debug.Assert(eventHandle != IntPtr.Zero);
-#else
- IntPtr eventHandle = IntPtr.Zero;
-#endif
-
-#if FEATURE_MANAGED_ETW
- int pinCount = eventTypes.pinCount;
- byte* scratch = stackalloc byte[eventTypes.scratchSize];
- EventData* descriptors = stackalloc EventData[eventTypes.dataCount + 3];
- for (int i = 0; i < eventTypes.dataCount + 3; i++)
- descriptors[i] = default;
-
- GCHandle* pins = stackalloc GCHandle[pinCount];
- for (int i = 0; i < pinCount; i++)
- pins[i] = default;
-
- fixed (byte*
- pMetadata0 = this.providerMetadata,
- pMetadata1 = nameInfo.nameMetadata,
- pMetadata2 = eventTypes.typeMetadata)
- {
- descriptors[0].SetMetadata(pMetadata0, this.providerMetadata.Length, 2);
- descriptors[1].SetMetadata(pMetadata1, nameInfo.nameMetadata.Length, 1);
- descriptors[2].SetMetadata(pMetadata2, eventTypes.typeMetadata.Length, 1);
-#endif // FEATURE_MANAGED_ETW
-
-#if (!ES_BUILD_PCL && !ES_BUILD_PN)
- System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
-#endif
- EventOpcode opcode = (EventOpcode)descriptor.Opcode;
-
- Guid activityId = Guid.Empty;
- Guid relatedActivityId = Guid.Empty;
- if (pActivityId == null && pRelatedActivityId == null &&
- ((options.ActivityOptions & EventActivityOptions.Disable) == 0))
- {
- if (opcode == EventOpcode.Start)
- {
- Debug.Assert(eventName != null, "GetOpcodeWithDefault should not returned Start when eventName is null");
- m_activityTracker.OnStart(m_name, eventName, 0, ref activityId, ref relatedActivityId, options.ActivityOptions);
- }
- else if (opcode == EventOpcode.Stop)
- {
- Debug.Assert(eventName != null, "GetOpcodeWithDefault should not returned Stop when eventName is null");
- m_activityTracker.OnStop(m_name, eventName, 0, ref activityId);
- }
- if (activityId != Guid.Empty)
- pActivityId = &activityId;
- if (relatedActivityId != Guid.Empty)
- pRelatedActivityId = &relatedActivityId;
- }
-
- try
- {
-#if FEATURE_MANAGED_ETW
- DataCollector.ThreadInstance.Enable(
- scratch,
- eventTypes.scratchSize,
- descriptors + 3,
- eventTypes.dataCount,
- pins,
- pinCount);
-
- TraceLoggingTypeInfo info = eventTypes.typeInfos[0];
- info.WriteData(TraceLoggingDataCollector.Instance, info.PropertyValueFactory(data));
-
- this.WriteEventRaw(
- eventName,
- ref descriptor,
- eventHandle,
- pActivityId,
- pRelatedActivityId,
- (int)(DataCollector.ThreadInstance.Finish() - descriptors),
- (IntPtr)descriptors);
-#endif // FEATURE_MANAGED_ETW
-
- // TODO enable filtering for listeners.
- if (m_Dispatchers != null)
- {
- var eventData = (EventPayload?)(eventTypes.typeInfos[0].GetData(data));
- WriteToAllListeners(eventName, ref descriptor, nameInfo.tags, pActivityId, pRelatedActivityId, eventData);
- }
- }
- catch (Exception ex)
- {
- if (ex is EventSourceException)
- throw;
- else
- ThrowEventSourceException(eventName, ex);
- }
-#if FEATURE_MANAGED_ETW
- finally
- {
- WriteCleanup(pins, pinCount);
- }
- }
-#endif // FEATURE_MANAGED_ETW
- }
- }
- catch (Exception ex)
- {
- if (ex is EventSourceException)
- throw;
- else
- ThrowEventSourceException(eventName, ex);
- }
- }
-
- private unsafe void WriteToAllListeners(string? eventName, ref EventDescriptor eventDescriptor, EventTags tags, Guid* pActivityId, Guid* pChildActivityId, EventPayload? payload)
- {
- EventWrittenEventArgs eventCallbackArgs = new EventWrittenEventArgs(this);
- eventCallbackArgs.EventName = eventName;
- eventCallbackArgs.m_level = (EventLevel)eventDescriptor.Level;
- eventCallbackArgs.m_keywords = (EventKeywords)eventDescriptor.Keywords;
- eventCallbackArgs.m_opcode = (EventOpcode)eventDescriptor.Opcode;
- eventCallbackArgs.m_tags = tags;
-
- // Self described events do not have an id attached. We mark it internally with -1.
- eventCallbackArgs.EventId = -1;
- if (pActivityId != null)
- eventCallbackArgs.ActivityId = *pActivityId;
- if (pChildActivityId != null)
- eventCallbackArgs.RelatedActivityId = *pChildActivityId;
-
- if (payload != null)
- {
- eventCallbackArgs.Payload = new ReadOnlyCollection<object?>((IList<object?>)payload.Values);
- eventCallbackArgs.PayloadNames = new ReadOnlyCollection<string>((IList<string>)payload.Keys);
- }
-
- DispatchToAllListeners(-1, eventCallbackArgs);
- }
-
-#if (!ES_BUILD_PCL && !ES_BUILD_PN)
- [System.Runtime.ConstrainedExecution.ReliabilityContract(
- System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState,
- System.Runtime.ConstrainedExecution.Cer.Success)]
-#endif
- [NonEvent]
- private static unsafe void WriteCleanup(GCHandle* pPins, int cPins)
- {
- DataCollector.ThreadInstance.Disable();
-
- for (int i = 0; i < cPins; i++)
- {
- if (pPins[i].IsAllocated)
- {
- pPins[i].Free();
- }
- }
- }
-
- private void InitializeProviderMetadata()
- {
-#if FEATURE_MANAGED_ETW
- if (m_traits != null)
- {
- List<byte> traitMetaData = new List<byte>(100);
- for (int i = 0; i < m_traits.Length - 1; i += 2)
- {
- if (m_traits[i].StartsWith("ETW_", StringComparison.Ordinal))
- {
- string etwTrait = m_traits[i].Substring(4);
- byte traitNum;
- if (!byte.TryParse(etwTrait, out traitNum))
- {
- if (etwTrait == "GROUP")
- {
- traitNum = 1;
- }
- else
- {
- throw new ArgumentException(SR.Format(SR.EventSource_UnknownEtwTrait, etwTrait), "traits");
- }
- }
- string value = m_traits[i + 1];
- int lenPos = traitMetaData.Count;
- traitMetaData.Add(0); // Emit size (to be filled in later)
- traitMetaData.Add(0);
- traitMetaData.Add(traitNum); // Emit Trait number
- int valueLen = AddValueToMetaData(traitMetaData, value) + 3; // Emit the value bytes +3 accounts for 3 bytes we emited above.
- traitMetaData[lenPos] = unchecked((byte)valueLen); // Fill in size
- traitMetaData[lenPos + 1] = unchecked((byte)(valueLen >> 8));
- }
- }
- providerMetadata = Statics.MetadataForString(this.Name, 0, traitMetaData.Count, 0);
- int startPos = providerMetadata.Length - traitMetaData.Count;
- foreach (byte b in traitMetaData)
- providerMetadata[startPos++] = b;
- }
- else
- providerMetadata = Statics.MetadataForString(this.Name, 0, 0, 0);
-#endif //FEATURE_MANAGED_ETW
- }
-
- private static int AddValueToMetaData(List<byte> metaData, string value)
- {
- if (value.Length == 0)
- return 0;
-
- int startPos = metaData.Count;
- char firstChar = value[0];
-
- if (firstChar == '@')
- metaData.AddRange(Encoding.UTF8.GetBytes(value.Substring(1)));
- else if (firstChar == '{')
- metaData.AddRange(new Guid(value).ToByteArray());
- else if (firstChar == '#')
- {
- for (int i = 1; i < value.Length; i++)
- {
- if (value[i] != ' ') // Skip spaces between bytes.
- {
- if (!(i + 1 < value.Length))
- {
- throw new ArgumentException(SR.EventSource_EvenHexDigits, "traits");
- }
- metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
- i++;
- }
- }
- }
- else if ('A' <= firstChar || ' ' == firstChar) // Is it alphabetic or space (excludes digits and most punctuation).
- {
- metaData.AddRange(Encoding.UTF8.GetBytes(value));
- }
- else
- {
- throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), "traits");
- }
-
- return metaData.Count - startPos;
- }
-
- /// <summary>
- /// Returns a value 0-15 if 'c' is a hexadecimal digit. If it throws an argument exception.
- /// </summary>
- private static int HexDigit(char c)
- {
- if ('0' <= c && c <= '9')
- {
- return c - '0';
- }
- if ('a' <= c)
- {
- c = unchecked((char)(c - ('a' - 'A'))); // Convert to lower case
- }
- if ('A' <= c && c <= 'F')
- {
- return c - 'A' + 10;
- }
-
- throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), "traits");
- }
-
- private NameInfo? UpdateDescriptor(
- string? name,
- TraceLoggingEventTypes eventInfo,
- ref EventSourceOptions options,
- out EventDescriptor descriptor)
- {
- NameInfo? nameInfo = null;
- int identity = 0;
- byte level = (options.valuesSet & EventSourceOptions.levelSet) != 0
- ? options.level
- : eventInfo.level;
- byte opcode = (options.valuesSet & EventSourceOptions.opcodeSet) != 0
- ? options.opcode
- : eventInfo.opcode;
- EventTags tags = (options.valuesSet & EventSourceOptions.tagsSet) != 0
- ? options.tags
- : eventInfo.Tags;
- EventKeywords keywords = (options.valuesSet & EventSourceOptions.keywordsSet) != 0
- ? options.keywords
- : eventInfo.keywords;
-
- if (this.IsEnabled((EventLevel)level, keywords))
- {
- nameInfo = eventInfo.GetNameInfo(name ?? eventInfo.Name, tags);
- identity = nameInfo.identity;
- }
-
- descriptor = new EventDescriptor(identity, level, opcode, (long)keywords);
- return nameInfo;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTraits.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTraits.cs
deleted file mode 100644
index e25ae7fdc23..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTraits.cs
+++ /dev/null
@@ -1,30 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// Tags are flags that are not interpreted by EventSource but are passed along
- /// to the EventListener. The EventListener determines the semantics of the flags.
- /// </summary>
- [Flags]
- public enum EventTags
- {
- /// <summary>
- /// No special traits are added to the event.
- /// </summary>
- None = 0,
-
- /* Bits below 0x10000 are available for any use by the provider. */
- /* Bits at or above 0x10000 are reserved for definition by Microsoft. */
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs
deleted file mode 100644
index 0bd29d645ce..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventTypes.cs
+++ /dev/null
@@ -1,243 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-using System.Collections.Generic;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: Used when calling EventSource.WriteMultiMerge.
- /// Stores the type information to use when writing the event fields.
- /// </summary>
- public class TraceLoggingEventTypes
- {
- internal readonly TraceLoggingTypeInfo[] typeInfos;
-#if FEATURE_PERFTRACING
- internal readonly string[]? paramNames;
-#endif
- internal readonly string name;
- internal readonly EventTags tags;
- internal readonly byte level;
- internal readonly byte opcode;
- internal readonly EventKeywords keywords;
- internal readonly byte[] typeMetadata;
- internal readonly int scratchSize;
- internal readonly int dataCount;
- internal readonly int pinCount;
- private ConcurrentSet<KeyValuePair<string, EventTags>, NameInfo> nameInfos;
-
- /// <summary>
- /// Initializes a new instance of TraceLoggingEventTypes corresponding
- /// to the name, flags, and types provided. Always uses the default
- /// TypeInfo for each Type.
- /// </summary>
- /// <param name="name">
- /// The name to use when the name parameter passed to
- /// EventSource.Write is null. This value must not be null.
- /// </param>
- /// <param name="tags">
- /// Tags to add to the event if the tags are not set via options.
- /// </param>
- /// <param name="types">
- /// The types of the fields in the event. This value must not be null.
- /// </param>
- internal TraceLoggingEventTypes(
- string name,
- EventTags tags,
- params Type[] types)
- : this(tags, name, MakeArray(types))
- {
- }
-
- /// <summary>
- /// Returns a new instance of TraceLoggingEventInfo corresponding to the name,
- /// flags, and typeInfos provided.
- /// </summary>
- /// <param name="name">
- /// The name to use when the name parameter passed to
- /// EventSource.Write is null. This value must not be null.
- /// </param>
- /// <param name="tags">
- /// Tags to add to the event if the tags are not set via options.
- /// </param>
- /// <param name="typeInfos">
- /// The types of the fields in the event. This value must not be null.
- /// </param>
- /// <returns>
- /// An instance of TraceLoggingEventInfo with DefaultName set to the specified name
- /// and with the specified typeInfos.
- /// </returns>
- internal TraceLoggingEventTypes(
- string name,
- EventTags tags,
- params TraceLoggingTypeInfo[] typeInfos)
- : this(tags, name, MakeArray(typeInfos))
- {
- }
-
- internal TraceLoggingEventTypes(
- string name,
- EventTags tags,
- System.Reflection.ParameterInfo[] paramInfos)
- {
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- this.typeInfos = MakeArray(paramInfos);
-#if FEATURE_PERFTRACING
- this.paramNames = MakeParamNameArray(paramInfos);
-#endif
- this.name = name;
- this.tags = tags;
- this.level = Statics.DefaultLevel;
-
- var collector = new TraceLoggingMetadataCollector();
- for (int i = 0; i < typeInfos.Length; ++i)
- {
- TraceLoggingTypeInfo typeInfo = typeInfos[i];
- this.level = Statics.Combine((int)typeInfo.Level, this.level);
- this.opcode = Statics.Combine((int)typeInfo.Opcode, this.opcode);
- this.keywords |= typeInfo.Keywords;
- string? paramName = paramInfos[i].Name;
- if (Statics.ShouldOverrideFieldName(paramName!))
- {
- paramName = typeInfo.Name;
- }
- typeInfo.WriteMetadata(collector, paramName, EventFieldFormat.Default);
- }
-
- this.typeMetadata = collector.GetMetadata();
- this.scratchSize = collector.ScratchSize;
- this.dataCount = collector.DataCount;
- this.pinCount = collector.PinCount;
- }
-
- private TraceLoggingEventTypes(
- EventTags tags,
- string defaultName,
- TraceLoggingTypeInfo[] typeInfos)
- {
- if (defaultName == null)
- {
- throw new ArgumentNullException(nameof(defaultName));
- }
-
- this.typeInfos = typeInfos;
- this.name = defaultName;
- this.tags = tags;
- this.level = Statics.DefaultLevel;
-
- var collector = new TraceLoggingMetadataCollector();
- foreach (TraceLoggingTypeInfo typeInfo in typeInfos)
- {
- this.level = Statics.Combine((int)typeInfo.Level, this.level);
- this.opcode = Statics.Combine((int)typeInfo.Opcode, this.opcode);
- this.keywords |= typeInfo.Keywords;
- typeInfo.WriteMetadata(collector, null, EventFieldFormat.Default);
- }
-
- this.typeMetadata = collector.GetMetadata();
- this.scratchSize = collector.ScratchSize;
- this.dataCount = collector.DataCount;
- this.pinCount = collector.PinCount;
- }
-
- /// <summary>
- /// Gets the default name that will be used for events with this descriptor.
- /// </summary>
- internal string Name => this.name;
-
- /// <summary>
- /// Gets the default level that will be used for events with this descriptor.
- /// </summary>
- internal EventLevel Level => (EventLevel)this.level;
-
- /// <summary>
- /// Gets the default opcode that will be used for events with this descriptor.
- /// </summary>
- internal EventOpcode Opcode => (EventOpcode)this.opcode;
-
- /// <summary>
- /// Gets the default set of keywords that will added to events with this descriptor.
- /// </summary>
- internal EventKeywords Keywords => (EventKeywords)this.keywords;
-
- /// <summary>
- /// Gets the default tags that will be added events with this descriptor.
- /// </summary>
- internal EventTags Tags => this.tags;
-
- internal NameInfo GetNameInfo(string name, EventTags tags) =>
- this.nameInfos.TryGet(new KeyValuePair<string, EventTags>(name, tags)) ??
- this.nameInfos.GetOrAdd(new NameInfo(name, tags, this.typeMetadata.Length));
-
- private TraceLoggingTypeInfo[] MakeArray(System.Reflection.ParameterInfo[] paramInfos)
- {
- if (paramInfos == null)
- {
- throw new ArgumentNullException(nameof(paramInfos));
- }
-
- var recursionCheck = new List<Type>(paramInfos.Length);
- var result = new TraceLoggingTypeInfo[paramInfos.Length];
- for (int i = 0; i < paramInfos.Length; ++i)
- {
- result[i] = TraceLoggingTypeInfo.GetInstance(paramInfos[i].ParameterType, recursionCheck);
- }
-
- return result;
- }
-
- private static TraceLoggingTypeInfo[] MakeArray(Type[] types)
- {
- if (types == null)
- {
- throw new ArgumentNullException(nameof(types));
- }
-
- var recursionCheck = new List<Type>(types.Length);
- var result = new TraceLoggingTypeInfo[types.Length];
- for (int i = 0; i < types.Length; i++)
- {
- result[i] = TraceLoggingTypeInfo.GetInstance(types[i], recursionCheck);
- }
-
- return result;
- }
-
- private static TraceLoggingTypeInfo[] MakeArray(
- TraceLoggingTypeInfo[] typeInfos)
- {
- if (typeInfos == null)
- {
- throw new ArgumentNullException(nameof(typeInfos));
- }
-
- return (TraceLoggingTypeInfo[])typeInfos.Clone();
- }
-
-#if FEATURE_PERFTRACING
- private static string[] MakeParamNameArray(
- System.Reflection.ParameterInfo[] paramInfos)
- {
- string[] paramNames = new string[paramInfos.Length];
- for (int i = 0; i < paramNames.Length; i++)
- {
- paramNames[i] = paramInfos[i].Name!;
- }
-
- return paramNames;
- }
-#endif
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingMetadataCollector.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingMetadataCollector.cs
deleted file mode 100644
index 4ab1d054932..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingMetadataCollector.cs
+++ /dev/null
@@ -1,381 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-using Environment = Microsoft.Diagnostics.Tracing.Internal.Environment;
-#endif
-using System.Collections.Generic;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: used when implementing a custom TraceLoggingTypeInfo.
- /// An instance of this type is provided to the TypeInfo.WriteMetadata method.
- /// </summary>
- internal class TraceLoggingMetadataCollector
- {
- private readonly Impl impl;
- private readonly FieldMetadata? currentGroup;
- private int bufferedArrayFieldCount = int.MinValue;
-
- /// <summary>
- /// Creates a root-level collector.
- /// </summary>
- internal TraceLoggingMetadataCollector()
- {
- this.impl = new Impl();
- }
-
- /// <summary>
- /// Creates a collector for a group.
- /// </summary>
- /// <param name="other">Parent collector</param>
- /// <param name="group">The field that starts the group</param>
- private TraceLoggingMetadataCollector(
- TraceLoggingMetadataCollector other,
- FieldMetadata group)
- {
- this.impl = other.impl;
- this.currentGroup = group;
- }
-
- /// <summary>
- /// The field tags to be used for the next field.
- /// This will be reset to None each time a field is written.
- /// </summary>
- internal EventFieldTags Tags
- {
- get;
- set;
- }
-
- internal int ScratchSize => this.impl.scratchSize;
-
- internal int DataCount => this.impl.dataCount;
-
- internal int PinCount => this.impl.pinCount;
-
- private bool BeginningBufferedArray => this.bufferedArrayFieldCount == 0;
-
- /// <summary>
- /// Call this method to add a group to the event and to return
- /// a new metadata collector that can be used to add fields to the
- /// group. After all of the fields in the group have been written,
- /// switch back to the original metadata collector to add fields
- /// outside of the group.
- /// Special-case: if name is null, no group is created, and AddGroup
- /// returns the original metadata collector. This is useful when
- /// adding the top-level group for an event.
- /// Note: do not use the original metadata collector while the group's
- /// metadata collector is in use, and do not use the group's metadata
- /// collector after switching back to the original.
- /// </summary>
- /// <param name="name">
- /// The name of the group. If name is null, the call to AddGroup is a
- /// no-op (collector.AddGroup(null) returns collector).
- /// </param>
- /// <returns>
- /// A new metadata collector that can be used to add fields to the group.
- /// </returns>
- public TraceLoggingMetadataCollector AddGroup(string? name)
- {
- TraceLoggingMetadataCollector result = this;
-
- if (name != null || // Normal.
- this.BeginningBufferedArray) // Error, FieldMetadata's constructor will throw the appropriate exception.
- {
- var newGroup = new FieldMetadata(
- name!,
- TraceLoggingDataType.Struct,
- this.Tags,
- this.BeginningBufferedArray);
- this.AddField(newGroup);
- result = new TraceLoggingMetadataCollector(this, newGroup);
- }
-
- return result;
- }
-
- /// <summary>
- /// Adds a scalar field to an event.
- /// </summary>
- /// <param name="name">
- /// The name to use for the added field. This value must not be null.
- /// </param>
- /// <param name="type">
- /// The type code for the added field. This must be a fixed-size type
- /// (e.g. string types are not supported).
- /// </param>
- public void AddScalar(string name, TraceLoggingDataType type)
- {
- int size;
- switch ((TraceLoggingDataType)((int)type & Statics.InTypeMask))
- {
- case TraceLoggingDataType.Int8:
- case TraceLoggingDataType.UInt8:
- case TraceLoggingDataType.Char8:
- size = 1;
- break;
- case TraceLoggingDataType.Int16:
- case TraceLoggingDataType.UInt16:
- case TraceLoggingDataType.Char16:
- size = 2;
- break;
- case TraceLoggingDataType.Int32:
- case TraceLoggingDataType.UInt32:
- case TraceLoggingDataType.HexInt32:
- case TraceLoggingDataType.Float:
- case TraceLoggingDataType.Boolean32:
- size = 4;
- break;
- case TraceLoggingDataType.Int64:
- case TraceLoggingDataType.UInt64:
- case TraceLoggingDataType.HexInt64:
- case TraceLoggingDataType.Double:
- case TraceLoggingDataType.FileTime:
- size = 8;
- break;
- case TraceLoggingDataType.Guid:
- case TraceLoggingDataType.SystemTime:
- size = 16;
- break;
- default:
- throw new ArgumentOutOfRangeException(nameof(type));
- }
-
- this.impl.AddScalar(size);
- this.AddField(new FieldMetadata(name, type, this.Tags, this.BeginningBufferedArray));
- }
-
- /// <summary>
- /// Adds a binary-format field to an event.
- /// Compatible with core types: Binary, CountedUtf16String, CountedMbcsString.
- /// Compatible with dataCollector methods: AddBinary(string), AddArray(Any8bitType[]).
- /// </summary>
- /// <param name="name">
- /// The name to use for the added field. This value must not be null.
- /// </param>
- /// <param name="type">
- /// The type code for the added field. This must be a Binary or CountedString type.
- /// </param>
- public void AddBinary(string name, TraceLoggingDataType type)
- {
- switch ((TraceLoggingDataType)((int)type & Statics.InTypeMask))
- {
- case TraceLoggingDataType.Binary:
- case TraceLoggingDataType.CountedMbcsString:
- case TraceLoggingDataType.CountedUtf16String:
- break;
- default:
- throw new ArgumentOutOfRangeException(nameof(type));
- }
-
- this.impl.AddScalar(2);
- this.impl.AddNonscalar();
- this.AddField(new FieldMetadata(name, type, this.Tags, this.BeginningBufferedArray));
- }
-
- /// <summary>
- /// Adds a null-terminated string field to an event.
- /// Compatible with core types: Utf16String, MbcsString.
- /// Compatible with dataCollector method: AddNullTerminatedString(string).
- /// </summary>
- /// <param name="name">
- /// The name to use for the added field. This value must not be null.
- /// </param>
- /// <param name="type">
- /// The type code for the added field. This must be a null-terminated string type.
- /// </param>
- public void AddNullTerminatedString(string name, TraceLoggingDataType type)
- {
- switch ((TraceLoggingDataType)((int)type & Statics.InTypeMask))
- {
- case TraceLoggingDataType.Utf16String:
- break;
- default:
- throw new ArgumentOutOfRangeException(nameof(type));
- }
-
- this.impl.AddNonscalar();
- this.AddField(new FieldMetadata(name, type, this.Tags, this.BeginningBufferedArray));
- }
-
- /// <summary>
- /// Adds an array field to an event.
- /// </summary>
- /// <param name="name">
- /// The name to use for the added field. This value must not be null.
- /// </param>
- /// <param name="type">
- /// The type code for the added field. This must be a fixed-size type.
- /// </param>
- public void AddArray(string name, TraceLoggingDataType type)
- {
- switch ((TraceLoggingDataType)((int)type & Statics.InTypeMask))
- {
- case TraceLoggingDataType.Int8:
- case TraceLoggingDataType.UInt8:
- case TraceLoggingDataType.Int16:
- case TraceLoggingDataType.UInt16:
- case TraceLoggingDataType.Int32:
- case TraceLoggingDataType.UInt32:
- case TraceLoggingDataType.Int64:
- case TraceLoggingDataType.UInt64:
- case TraceLoggingDataType.Float:
- case TraceLoggingDataType.Double:
- case TraceLoggingDataType.Boolean32:
- case TraceLoggingDataType.Guid:
- case TraceLoggingDataType.FileTime:
- case TraceLoggingDataType.HexInt32:
- case TraceLoggingDataType.HexInt64:
- case TraceLoggingDataType.Char16:
- case TraceLoggingDataType.Char8:
- break;
- default:
- throw new ArgumentOutOfRangeException(nameof(type));
- }
-
- if (this.BeginningBufferedArray)
- {
- throw new NotSupportedException(SR.EventSource_NotSupportedNestedArraysEnums);
- }
-
- this.impl.AddScalar(2);
- this.impl.AddNonscalar();
- this.AddField(new FieldMetadata(name, type, this.Tags, true));
- }
-
- public void BeginBufferedArray()
- {
- if (this.bufferedArrayFieldCount >= 0)
- {
- throw new NotSupportedException(SR.EventSource_NotSupportedNestedArraysEnums);
- }
-
- this.bufferedArrayFieldCount = 0;
- this.impl.BeginBuffered();
- }
-
- public void EndBufferedArray()
- {
- if (this.bufferedArrayFieldCount != 1)
- {
- throw new InvalidOperationException(SR.EventSource_IncorrentlyAuthoredTypeInfo);
- }
-
- this.bufferedArrayFieldCount = int.MinValue;
- this.impl.EndBuffered();
- }
-
- /// <summary>
- /// Adds a custom-serialized field to an event.
- /// </summary>
- /// <param name="name">
- /// The name to use for the added field. This value must not be null.
- /// </param>
- /// <param name="type">The encoding type for the field.</param>
- /// <param name="metadata">Additional information needed to decode the field, if any.</param>
- public void AddCustom(string name, TraceLoggingDataType type, byte[] metadata)
- {
- if (this.BeginningBufferedArray)
- {
- throw new NotSupportedException(SR.EventSource_NotSupportedCustomSerializedData);
- }
-
- this.impl.AddScalar(2);
- this.impl.AddNonscalar();
- this.AddField(new FieldMetadata(
- name,
- type,
- this.Tags,
- metadata));
- }
-
- internal byte[] GetMetadata()
- {
- int size = this.impl.Encode(null);
- var metadata = new byte[size];
- this.impl.Encode(metadata);
- return metadata;
- }
-
- private void AddField(FieldMetadata fieldMetadata)
- {
- this.Tags = EventFieldTags.None;
- this.bufferedArrayFieldCount++;
- this.impl.fields.Add(fieldMetadata);
-
- if (this.currentGroup != null)
- {
- this.currentGroup.IncrementStructFieldCount();
- }
- }
-
- private class Impl
- {
- internal readonly List<FieldMetadata> fields = new List<FieldMetadata>();
- internal short scratchSize;
- internal sbyte dataCount;
- internal sbyte pinCount;
- private int bufferNesting;
- private bool scalar;
-
- public void AddScalar(int size)
- {
- if (this.bufferNesting == 0)
- {
- if (!this.scalar)
- {
- this.dataCount = checked((sbyte)(this.dataCount + 1));
- }
-
- this.scalar = true;
- this.scratchSize = checked((short)(this.scratchSize + size));
- }
- }
-
- public void AddNonscalar()
- {
- if (this.bufferNesting == 0)
- {
- this.scalar = false;
- this.pinCount = checked((sbyte)(this.pinCount + 1));
- this.dataCount = checked((sbyte)(this.dataCount + 1));
- }
- }
-
- public void BeginBuffered()
- {
- if (this.bufferNesting == 0)
- {
- this.AddNonscalar();
- }
-
- this.bufferNesting++;
- }
-
- public void EndBuffered()
- {
- this.bufferNesting--;
- }
-
- public int Encode(byte[]? metadata)
- {
- int size = 0;
-
- foreach (FieldMetadata field in this.fields)
- {
- field.Encode(ref size, metadata);
- }
-
- return size;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs
deleted file mode 100644
index a5de12342d1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingTypeInfo.cs
+++ /dev/null
@@ -1,179 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-using System.Collections.Generic;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: used when implementing a custom TraceLoggingTypeInfo.
- /// Non-generic base class for TraceLoggingTypeInfo&lt;DataType>. Do not derive
- /// from this class. Instead, derive from TraceLoggingTypeInfo&lt;DataType>.
- /// </summary>
- internal abstract class TraceLoggingTypeInfo
- {
- private readonly string name;
- private readonly EventKeywords keywords;
- private readonly EventLevel level = (EventLevel)(-1);
- private readonly EventOpcode opcode = (EventOpcode)(-1);
- private readonly EventTags tags;
- private readonly Type dataType;
- private readonly Func<object?, PropertyValue> propertyValueFactory;
-
- internal TraceLoggingTypeInfo(Type dataType)
- {
- if (dataType == null)
- {
- throw new ArgumentNullException(nameof(dataType));
- }
-
- this.name = dataType.Name;
- this.dataType = dataType;
- this.propertyValueFactory = PropertyValue.GetFactory(dataType);
- }
-
- internal TraceLoggingTypeInfo(
- Type dataType,
- string name,
- EventLevel level,
- EventOpcode opcode,
- EventKeywords keywords,
- EventTags tags)
- {
- if (dataType == null)
- {
- throw new ArgumentNullException(nameof(dataType));
- }
-
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- Statics.CheckName(name);
-
- this.name = name;
- this.keywords = keywords;
- this.level = level;
- this.opcode = opcode;
- this.tags = tags;
- this.dataType = dataType;
- this.propertyValueFactory = PropertyValue.GetFactory(dataType);
- }
-
- /// <summary>
- /// Gets the name to use for the event if this type is the top-level type,
- /// or the name to use for an implicitly-named field.
- /// Never null.
- /// </summary>
- public string Name => this.name;
-
- /// <summary>
- /// Gets the event level associated with this type. Any value in the range 0..255
- /// is an associated event level. Any value outside the range 0..255 is invalid and
- /// indicates that this type has no associated event level.
- /// </summary>
- public EventLevel Level => this.level;
-
- /// <summary>
- /// Gets the event opcode associated with this type. Any value in the range 0..255
- /// is an associated event opcode. Any value outside the range 0..255 is invalid and
- /// indicates that this type has no associated event opcode.
- /// </summary>
- public EventOpcode Opcode => this.opcode;
-
- /// <summary>
- /// Gets the keyword(s) associated with this type.
- /// </summary>
- public EventKeywords Keywords => this.keywords;
-
- /// <summary>
- /// Gets the event tags associated with this type.
- /// </summary>
- public EventTags Tags => this.tags;
-
- internal Type DataType => this.dataType;
-
- internal Func<object?, PropertyValue> PropertyValueFactory => this.propertyValueFactory;
-
- /// <summary>
- /// When overridden by a derived class, writes the metadata (schema) for
- /// this type. Note that the sequence of operations in WriteMetadata should be
- /// essentially identical to the sequence of operations in
- /// WriteData/WriteObjectData. Otherwise, the metadata and data will not match,
- /// which may cause trouble when decoding the event.
- /// </summary>
- /// <param name="collector">
- /// The object that collects metadata for this object's type. Metadata is written
- /// by calling methods on the collector object. Note that if the type contains
- /// sub-objects, the implementation of this method may need to call the
- /// WriteMetadata method for the type of the sub-object, e.g. by calling
- /// TraceLoggingTypeInfo&lt;SubType&gt;.Instance.WriteMetadata(...).
- /// </param>
- /// <param name="name">
- /// The name of the property that contains an object of this type, or null if this
- /// object is being written as a top-level object of an event. Typical usage
- /// is to pass this value to collector.AddGroup.
- /// </param>
- /// <param name="format">
- /// The format attribute for the field that contains an object of this type.
- /// </param>
- public abstract void WriteMetadata(
- TraceLoggingMetadataCollector collector,
- string? name,
- EventFieldFormat format);
-
- /// <summary>
- /// Refer to TraceLoggingTypeInfo.WriteObjectData for information about this
- /// method.
- /// </summary>
- /// <param name="collector">
- /// Refer to TraceLoggingTypeInfo.WriteObjectData for information about this
- /// method.
- /// </param>
- /// <param name="value">
- /// Refer to TraceLoggingTypeInfo.WriteObjectData for information about this
- /// method.
- /// </param>
- public abstract void WriteData(
- TraceLoggingDataCollector collector,
- PropertyValue value);
-
- /// <summary>
- /// Fetches the event parameter data for internal serialization.
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public virtual object? GetData(object? value)
- {
- return value;
- }
-
- [ThreadStatic] // per-thread cache to avoid synchronization
- private static Dictionary<Type, TraceLoggingTypeInfo>? threadCache;
-
- public static TraceLoggingTypeInfo GetInstance(Type type, List<Type>? recursionCheck)
- {
- Dictionary<Type, TraceLoggingTypeInfo> cache = threadCache ??= new Dictionary<Type, TraceLoggingTypeInfo>();
-
- TraceLoggingTypeInfo? instance;
- if (!cache.TryGetValue(type, out instance))
- {
- recursionCheck ??= new List<Type>();
- int recursionCheckCount = recursionCheck.Count;
- instance = Statics.CreateDefaultTypeInfo(type, recursionCheck);
- cache[type] = instance;
- recursionCheck.RemoveRange(recursionCheckCount, recursionCheck.Count - recursionCheckCount);
- }
- return instance;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs
deleted file mode 100644
index 571298623bd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/TypeAnalysis.cs
+++ /dev/null
@@ -1,104 +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.
-
-#if ES_BUILD_STANDALONE
-using System;
-#endif
-using System.Collections.Generic;
-using System.Reflection;
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// TraceLogging: stores the per-type information obtained by reflecting over a type.
- /// </summary>
- internal sealed class TypeAnalysis
- {
- internal readonly PropertyAnalysis[] properties;
- internal readonly string? name;
- internal readonly EventKeywords keywords;
- internal readonly EventLevel level = (EventLevel)(-1);
- internal readonly EventOpcode opcode = (EventOpcode)(-1);
- internal readonly EventTags tags;
-
- public TypeAnalysis(
- Type dataType,
- EventDataAttribute? eventAttrib,
- List<Type> recursionCheck)
- {
- IEnumerable<PropertyInfo> propertyInfos = Statics.GetProperties(dataType);
- var propertyList = new List<PropertyAnalysis>();
-
- foreach (PropertyInfo propertyInfo in propertyInfos)
- {
- if (Statics.HasCustomAttribute(propertyInfo, typeof(EventIgnoreAttribute)))
- {
- continue;
- }
-
- if (!propertyInfo.CanRead ||
- propertyInfo.GetIndexParameters().Length != 0)
- {
- continue;
- }
-
- MethodInfo? getterInfo = Statics.GetGetMethod(propertyInfo);
- if (getterInfo == null)
- {
- continue;
- }
-
- if (getterInfo.IsStatic || !getterInfo.IsPublic)
- {
- continue;
- }
-
- Type propertyType = propertyInfo.PropertyType;
- var propertyTypeInfo = TraceLoggingTypeInfo.GetInstance(propertyType, recursionCheck);
- EventFieldAttribute? fieldAttribute = Statics.GetCustomAttribute<EventFieldAttribute>(propertyInfo);
-
- string propertyName =
- fieldAttribute != null && fieldAttribute.Name != null
- ? fieldAttribute.Name
- : Statics.ShouldOverrideFieldName(propertyInfo.Name)
- ? propertyTypeInfo.Name
- : propertyInfo.Name;
- propertyList.Add(new PropertyAnalysis(
- propertyName,
- propertyInfo,
- propertyTypeInfo,
- fieldAttribute));
- }
-
- this.properties = propertyList.ToArray();
-
- foreach (PropertyAnalysis property in this.properties)
- {
- TraceLoggingTypeInfo typeInfo = property.typeInfo;
- this.level = (EventLevel)Statics.Combine((int)typeInfo.Level, (int)this.level);
- this.opcode = (EventOpcode)Statics.Combine((int)typeInfo.Opcode, (int)this.opcode);
- this.keywords |= typeInfo.Keywords;
- this.tags |= typeInfo.Tags;
- }
-
- if (eventAttrib != null)
- {
- this.level = (EventLevel)Statics.Combine((int)eventAttrib.Level, (int)this.level);
- this.opcode = (EventOpcode)Statics.Combine((int)eventAttrib.Opcode, (int)this.opcode);
- this.keywords |= eventAttrib.Keywords;
- this.tags |= eventAttrib.Tags;
- this.name = eventAttrib.Name;
- }
-
- if (this.name == null)
- {
- this.name = dataType.Name;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/Winmeta.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/Winmeta.cs
deleted file mode 100644
index 03d86f8efab..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/Winmeta.cs
+++ /dev/null
@@ -1,185 +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.
-
-/*============================================================
-**
-**
-** Purpose:
-** Contains eventing constants defined by the Windows
-** environment.
-**
-============================================================*/
-
-#if ES_BUILD_STANDALONE
-#define FEATURE_MANAGED_ETW_CHANNELS
-using System;
-#endif
-
-#if ES_BUILD_STANDALONE
-namespace Microsoft.Diagnostics.Tracing
-#else
-namespace System.Diagnostics.Tracing
-#endif
-{
- /// <summary>
- /// WindowsEventLevel. Custom values must be in the range from 16 through 255
- /// </summary>
- public enum EventLevel
- {
- /// <summary>
- /// Log always
- /// </summary>
- LogAlways = 0,
- /// <summary>
- /// Only critical errors
- /// </summary>
- Critical,
- /// <summary>
- /// All errors, including previous levels
- /// </summary>
- Error,
- /// <summary>
- /// All warnings, including previous levels
- /// </summary>
- Warning,
- /// <summary>
- /// All informational events, including previous levels
- /// </summary>
- Informational,
- /// <summary>
- /// All events, including previous levels
- /// </summary>
- Verbose
- }
- /// <summary>
- /// WindowsEventTask. Custom values must be in the range from 1 through 65534
- /// </summary>
- public enum EventTask
- {
- /// <summary>
- /// Undefined task
- /// </summary>
- None = 0
- }
- /// <summary>
- /// EventOpcode. Custom values must be in the range from 11 through 239
- /// </summary>
- public enum EventOpcode
- {
- /// <summary>
- /// An informational event
- /// </summary>
- Info = 0,
- /// <summary>
- /// An activity start event
- /// </summary>
- Start,
- /// <summary>
- /// An activity end event
- /// </summary>
- Stop,
- /// <summary>
- /// A trace collection start event
- /// </summary>
- DataCollectionStart,
- /// <summary>
- /// A trace collection end event
- /// </summary>
- DataCollectionStop,
- /// <summary>
- /// An extensional event
- /// </summary>
- Extension,
- /// <summary>
- /// A reply event
- /// </summary>
- Reply,
- /// <summary>
- /// An event representing the activity resuming from the suspension
- /// </summary>
- Resume,
- /// <summary>
- /// An event representing the activity is suspended, pending another activity's completion
- /// </summary>
- Suspend,
- /// <summary>
- /// An event representing the activity is transferred to another component, and can continue to work
- /// </summary>
- Send,
- /// <summary>
- /// An event representing receiving an activity transfer from another component
- /// </summary>
- Receive = 240
- }
-
- // Added for CLR V4
- /// <summary>
- /// EventChannel. Custom values must be in the range from 16 through 255. Currently only predefined values allowed.
- /// </summary>
- public enum EventChannel : byte
- {
- /// <summary>
- /// No channel
- /// </summary>
- None = 0,
- // Channels 1 - 15 are reserved...
- /// <summary>The admin channel</summary>
- Admin = 16,
- /// <summary>The operational channel</summary>
- Operational = 17,
- /// <summary>The analytic channel</summary>
- Analytic = 18,
- /// <summary>The debug channel</summary>
- Debug = 19,
- }
-
- /// <summary>
- /// EventOpcode
- /// </summary>
- [Flags]
- public enum EventKeywords : long
- {
- /// <summary>
- /// No events.
- /// </summary>
- None = 0x0,
- /// <summary>
- /// All Events
- /// </summary>
- All = ~0,
- /// <summary>
- /// Telemetry events
- /// </summary>
- MicrosoftTelemetry = 0x02000000000000,
- /// <summary>
- /// WDI context events
- /// </summary>
- WdiContext = 0x02000000000000,
- /// <summary>
- /// WDI diagnostic events
- /// </summary>
- WdiDiagnostic = 0x04000000000000,
- /// <summary>
- /// SQM events
- /// </summary>
- Sqm = 0x08000000000000,
- /// <summary>
- /// Failed security audits
- /// </summary>
- AuditFailure = 0x10000000000000,
- /// <summary>
- /// Successful security audits
- /// </summary>
- AuditSuccess = 0x20000000000000,
- /// <summary>
- /// Transfer events where the related Activity ID is a computed value and not a GUID
- /// N.B. The correct value for this field is 0x40000000000000.
- /// </summary>
- CorrelationHint = 0x10000000000000,
- /// <summary>
- /// Events raised using classic eventlog API
- /// </summary>
- EventLogClassic = 0x80000000000000
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DivideByZeroException.cs b/netcore/System.Private.CoreLib/shared/System/DivideByZeroException.cs
deleted file mode 100644
index 8c079fb6046..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DivideByZeroException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class for bad arithmetic conditions!
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class DivideByZeroException : ArithmeticException
- {
- public DivideByZeroException()
- : base(SR.Arg_DivideByZero)
- {
- HResult = HResults.COR_E_DIVIDEBYZERO;
- }
-
- public DivideByZeroException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_DIVIDEBYZERO;
- }
-
- public DivideByZeroException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_DIVIDEBYZERO;
- }
-
- protected DivideByZeroException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DllNotFoundException.cs b/netcore/System.Private.CoreLib/shared/System/DllNotFoundException.cs
deleted file mode 100644
index b9c3e05afaa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DllNotFoundException.cs
+++ /dev/null
@@ -1,45 +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.
-
-/*=============================================================================
-**
-** Class: DllNotFoundException
-**
-**
-** Purpose: The exception class for some failed P/Invoke calls.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class DllNotFoundException : TypeLoadException
- {
- public DllNotFoundException()
- : base(SR.Arg_DllNotFoundException)
- {
- HResult = HResults.COR_E_DLLNOTFOUND;
- }
-
- public DllNotFoundException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_DLLNOTFOUND;
- }
-
- public DllNotFoundException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_DLLNOTFOUND;
- }
-
- protected DllNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Double.cs b/netcore/System.Private.CoreLib/shared/System/Double.cs
deleted file mode 100644
index fedbed02de3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Double.cs
+++ /dev/null
@@ -1,448 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: A representation of an IEEE double precision
-** floating point number.
-**
-**
-===========================================================*/
-
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- [Serializable]
- [StructLayout(LayoutKind.Sequential)]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct Double : IComparable, IConvertible, IFormattable, IComparable<double>, IEquatable<double>, ISpanFormattable
- {
- private readonly double m_value; // Do not rename (binary serialization)
-
- //
- // Public Constants
- //
- public const double MinValue = -1.7976931348623157E+308;
- public const double MaxValue = 1.7976931348623157E+308;
-
- // Note Epsilon should be a double whose hex representation is 0x1
- // on little endian machines.
- public const double Epsilon = 4.9406564584124654E-324;
- public const double NegativeInfinity = (double)-1.0 / (double)(0.0);
- public const double PositiveInfinity = (double)1.0 / (double)(0.0);
- public const double NaN = (double)0.0 / (double)0.0;
-
- // We use this explicit definition to avoid the confusion between 0.0 and -0.0.
- internal const double NegativeZero = -0.0;
-
- //
- // Constants for manipulating the private bit-representation
- //
-
- internal const ulong SignMask = 0x8000_0000_0000_0000;
- internal const int SignShift = 63;
- internal const int ShiftedSignMask = (int)(SignMask >> SignShift);
-
- internal const ulong ExponentMask = 0x7FF0_0000_0000_0000;
- internal const int ExponentShift = 52;
- internal const int ShiftedExponentMask = (int)(ExponentMask >> ExponentShift);
-
- internal const ulong SignificandMask = 0x000F_FFFF_FFFF_FFFF;
-
- internal const byte MinSign = 0;
- internal const byte MaxSign = 1;
-
- internal const ushort MinExponent = 0x0000;
- internal const ushort MaxExponent = 0x07FF;
-
- internal const ulong MinSignificand = 0x0000_0000_0000_0000;
- internal const ulong MaxSignificand = 0x000F_FFFF_FFFF_FFFF;
-
- /// <summary>Determines whether the specified value is finite (zero, subnormal, or normal).</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe bool IsFinite(double d)
- {
- long bits = BitConverter.DoubleToInt64Bits(d);
- return (bits & 0x7FFFFFFFFFFFFFFF) < 0x7FF0000000000000;
- }
-
- /// <summary>Determines whether the specified value is infinite.</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe bool IsInfinity(double d)
- {
- long bits = BitConverter.DoubleToInt64Bits(d);
- return (bits & 0x7FFFFFFFFFFFFFFF) == 0x7FF0000000000000;
- }
-
- /// <summary>Determines whether the specified value is NaN.</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe bool IsNaN(double d)
- {
- // A NaN will never equal itself so this is an
- // easy and efficient way to check for NaN.
-
- #pragma warning disable CS1718
- return d != d;
- #pragma warning restore CS1718
- }
-
- /// <summary>Determines whether the specified value is negative.</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe bool IsNegative(double d)
- {
- return BitConverter.DoubleToInt64Bits(d) < 0;
- }
-
- /// <summary>Determines whether the specified value is negative infinity.</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsNegativeInfinity(double d)
- {
- return d == double.NegativeInfinity;
- }
-
- /// <summary>Determines whether the specified value is normal.</summary>
- [NonVersionable]
- // This is probably not worth inlining, it has branches and should be rarely called
- public static unsafe bool IsNormal(double d)
- {
- long bits = BitConverter.DoubleToInt64Bits(d);
- bits &= 0x7FFFFFFFFFFFFFFF;
- return (bits < 0x7FF0000000000000) && (bits != 0) && ((bits & 0x7FF0000000000000) != 0);
- }
-
- /// <summary>Determines whether the specified value is positive infinity.</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsPositiveInfinity(double d)
- {
- return d == double.PositiveInfinity;
- }
-
- /// <summary>Determines whether the specified value is subnormal.</summary>
- [NonVersionable]
- // This is probably not worth inlining, it has branches and should be rarely called
- public static unsafe bool IsSubnormal(double d)
- {
- long bits = BitConverter.DoubleToInt64Bits(d);
- bits &= 0x7FFFFFFFFFFFFFFF;
- return (bits < 0x7FF0000000000000) && (bits != 0) && ((bits & 0x7FF0000000000000) == 0);
- }
-
- internal static int ExtractExponentFromBits(ulong bits)
- {
- return (int)(bits >> ExponentShift) & ShiftedExponentMask;
- }
-
- internal static ulong ExtractSignificandFromBits(ulong bits)
- {
- return bits & SignificandMask;
- }
-
- // Compares this object to another object, returning an instance of System.Relation.
- // Null is considered less than any instance.
- //
- // If object is not of type Double, this method throws an ArgumentException.
- //
- // Returns a value less than zero if this object
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
-
- if (value is double d)
- {
- if (m_value < d) return -1;
- if (m_value > d) return 1;
- if (m_value == d) return 0;
-
- // At least one of the values is NaN.
- if (IsNaN(m_value))
- return IsNaN(d) ? 0 : -1;
- else
- return 1;
- }
-
- throw new ArgumentException(SR.Arg_MustBeDouble);
- }
-
- public int CompareTo(double value)
- {
- if (m_value < value) return -1;
- if (m_value > value) return 1;
- if (m_value == value) return 0;
-
- // At least one of the values is NaN.
- if (IsNaN(m_value))
- return IsNaN(value) ? 0 : -1;
- else
- return 1;
- }
-
- // True if obj is another Double with the same value as the current instance. This is
- // a method of object equality, that only returns true if obj is also a double.
- public override bool Equals(object? obj)
- {
- if (!(obj is double))
- {
- return false;
- }
- double temp = ((double)obj).m_value;
- // This code below is written this way for performance reasons i.e the != and == check is intentional.
- if (temp == m_value)
- {
- return true;
- }
- return IsNaN(temp) && IsNaN(m_value);
- }
-
- [NonVersionable]
- public static bool operator ==(double left, double right) => left == right;
-
- [NonVersionable]
- public static bool operator !=(double left, double right) => left != right;
-
- [NonVersionable]
- public static bool operator <(double left, double right) => left < right;
-
- [NonVersionable]
- public static bool operator >(double left, double right) => left > right;
-
- [NonVersionable]
- public static bool operator <=(double left, double right) => left <= right;
-
- [NonVersionable]
- public static bool operator >=(double left, double right) => left >= right;
-
- public bool Equals(double obj)
- {
- if (obj == m_value)
- {
- return true;
- }
- return IsNaN(obj) && IsNaN(m_value);
- }
-
- // The hashcode for a double is the absolute value of the integer representation
- // of that double.
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // 64-bit constants make the IL unusually large that makes the inliner to reject the method
- public override int GetHashCode()
- {
- long bits = Unsafe.As<double, long>(ref Unsafe.AsRef(in m_value));
-
- // Optimized check for IsNan() || IsZero()
- if (((bits - 1) & 0x7FFFFFFFFFFFFFFF) >= 0x7FF0000000000000)
- {
- // Ensure that all NaNs and both zeros have the same hash code
- bits &= 0x7FF0000000000000;
- }
-
- return unchecked((int)bits) ^ ((int)(bits >> 32));
- }
-
- public override string ToString()
- {
- return Number.FormatDouble(m_value, null, NumberFormatInfo.CurrentInfo);
- }
-
- public string ToString(string? format)
- {
- return Number.FormatDouble(m_value, format, NumberFormatInfo.CurrentInfo);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return Number.FormatDouble(m_value, null, NumberFormatInfo.GetInstance(provider));
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- return Number.FormatDouble(m_value, format, NumberFormatInfo.GetInstance(provider));
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
- {
- return Number.TryFormatDouble(m_value, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten);
- }
-
- public static double Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseDouble(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo);
- }
-
- public static double Parse(string s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseDouble(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- public static double Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseDouble(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.GetInstance(provider));
- }
-
- public static double Parse(string s, NumberStyles style, IFormatProvider? provider)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseDouble(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- // Parses a double from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- //
- // This method will not throw an OverflowException, but will return
- // PositiveInfinity or NegativeInfinity for a number that is too
- // large or too small.
-
- public static double Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Float | NumberStyles.AllowThousands, IFormatProvider? provider = null)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- return Number.ParseDouble(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- public static bool TryParse(string? s, out double result)
- {
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, out double result)
- {
- return TryParse(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, out result);
- }
-
- public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out double result)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
-
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out double result)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- private static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info, out double result)
- {
- return Number.TryParseDouble(s, style, info, out result);
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.Double;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Double", "Char"));
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return m_value;
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Double", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/DuplicateWaitObjectException.cs b/netcore/System.Private.CoreLib/shared/System/DuplicateWaitObjectException.cs
deleted file mode 100644
index bcca7101931..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/DuplicateWaitObjectException.cs
+++ /dev/null
@@ -1,54 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class for duplicate objects in WaitAll/WaitAny.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- // The DuplicateWaitObjectException is thrown when an object
- // appears more than once in the list of objects to WaitAll or WaitAny.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class DuplicateWaitObjectException : ArgumentException
- {
- // Creates a new DuplicateWaitObjectException with its message
- // string set to a default message.
- public DuplicateWaitObjectException()
- : base(SR.Arg_DuplicateWaitObjectException)
- {
- HResult = HResults.COR_E_DUPLICATEWAITOBJECT;
- }
-
- public DuplicateWaitObjectException(string? parameterName)
- : base(SR.Arg_DuplicateWaitObjectException, parameterName)
- {
- HResult = HResults.COR_E_DUPLICATEWAITOBJECT;
- }
-
- public DuplicateWaitObjectException(string? parameterName, string? message)
- : base(message, parameterName)
- {
- HResult = HResults.COR_E_DUPLICATEWAITOBJECT;
- }
-
- public DuplicateWaitObjectException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_DUPLICATEWAITOBJECT;
- }
-
- protected DuplicateWaitObjectException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Empty.cs b/netcore/System.Private.CoreLib/shared/System/Empty.cs
deleted file mode 100644
index 186b92078e8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Empty.cs
+++ /dev/null
@@ -1,25 +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.
-
-namespace System
-{
-#if CORERT
- public // Needs to be public so that Reflection.Core can see it.
-#else
- internal
-#endif
- sealed class Empty
- {
- private Empty()
- {
- }
-
- public static readonly Empty Value = new Empty();
-
- public override string ToString()
- {
- return string.Empty;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/EntryPointNotFoundException.cs b/netcore/System.Private.CoreLib/shared/System/EntryPointNotFoundException.cs
deleted file mode 100644
index 719d28243c8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/EntryPointNotFoundException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: The exception class for some failed P/Invoke calls.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class EntryPointNotFoundException : TypeLoadException
- {
- public EntryPointNotFoundException()
- : base(SR.Arg_EntryPointNotFoundException)
- {
- HResult = HResults.COR_E_ENTRYPOINTNOTFOUND;
- }
-
- public EntryPointNotFoundException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_ENTRYPOINTNOTFOUND;
- }
-
- public EntryPointNotFoundException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_ENTRYPOINTNOTFOUND;
- }
-
- protected EntryPointNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Enum.cs b/netcore/System.Private.CoreLib/shared/System/Enum.cs
deleted file mode 100644
index 410901d4205..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Enum.cs
+++ /dev/null
@@ -1,1147 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using Internal.Runtime.CompilerServices;
-
-#if CORERT
-using CorElementType = System.Runtime.RuntimeImports.RhCorElementType;
-using RuntimeType = System.Type;
-using EnumInfo = Internal.Runtime.Augments.EnumInfo;
-#endif
-
-// The code below includes partial support for float/double and
-// pointer sized enums.
-//
-// The type loader does not prohibit such enums, and older versions of
-// the ECMA spec include them as possible enum types.
-//
-// However there are many things broken throughout the stack for
-// float/double/intptr/uintptr enums. There was a conscious decision
-// made to not fix the whole stack to work well for them because of
-// the right behavior is often unclear, and it is hard to test and
-// very low value because of such enums cannot be expressed in C#.
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public abstract partial class Enum : ValueType, IComparable, IFormattable, IConvertible
- {
- #region Private Constants
- private const char EnumSeparatorChar = ',';
- #endregion
-
- #region Private Static Methods
-
- private string ValueToString()
- {
- ref byte data = ref this.GetRawData();
- return (InternalGetCorElementType()) switch
- {
- CorElementType.ELEMENT_TYPE_I1 => Unsafe.As<byte, sbyte>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_U1 => data.ToString(),
- CorElementType.ELEMENT_TYPE_BOOLEAN => Unsafe.As<byte, bool>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_I2 => Unsafe.As<byte, short>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_U2 => Unsafe.As<byte, ushort>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_CHAR => Unsafe.As<byte, char>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_I4 => Unsafe.As<byte, int>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_U4 => Unsafe.As<byte, uint>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_R4 => Unsafe.As<byte, float>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_I8 => Unsafe.As<byte, long>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_U8 => Unsafe.As<byte, ulong>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_R8 => Unsafe.As<byte, double>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_I => Unsafe.As<byte, IntPtr>(ref data).ToString(),
- CorElementType.ELEMENT_TYPE_U => Unsafe.As<byte, UIntPtr>(ref data).ToString(),
- _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
- };
- }
-
- private string ValueToHexString()
- {
- ref byte data = ref this.GetRawData();
- switch (InternalGetCorElementType())
- {
- case CorElementType.ELEMENT_TYPE_I1:
- case CorElementType.ELEMENT_TYPE_U1:
- return data.ToString("X2", null);
- case CorElementType.ELEMENT_TYPE_BOOLEAN:
- return Convert.ToByte(Unsafe.As<byte, bool>(ref data)).ToString("X2", null);
- case CorElementType.ELEMENT_TYPE_I2:
- case CorElementType.ELEMENT_TYPE_U2:
- case CorElementType.ELEMENT_TYPE_CHAR:
- return Unsafe.As<byte, ushort>(ref data).ToString("X4", null);
- case CorElementType.ELEMENT_TYPE_I4:
- case CorElementType.ELEMENT_TYPE_U4:
- return Unsafe.As<byte, uint>(ref data).ToString("X8", null);
- case CorElementType.ELEMENT_TYPE_I8:
- case CorElementType.ELEMENT_TYPE_U8:
- return Unsafe.As<byte, ulong>(ref data).ToString("X16", null);
- default:
- throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
- }
- }
-
- private static string ValueToHexString(object value)
- {
- return (Convert.GetTypeCode(value)) switch
- {
- TypeCode.SByte => ((byte)(sbyte)value).ToString("X2", null),
- TypeCode.Byte => ((byte)value).ToString("X2", null),
- TypeCode.Boolean => Convert.ToByte((bool)value).ToString("X2", null), // direct cast from bool to byte is not allowed
- TypeCode.Int16 => ((ushort)(short)value).ToString("X4", null),
- TypeCode.UInt16 => ((ushort)value).ToString("X4", null),
- TypeCode.Char => ((ushort)(char)value).ToString("X4", null),
- TypeCode.UInt32 => ((uint)value).ToString("X8", null),
- TypeCode.Int32 => ((uint)(int)value).ToString("X8", null),
- TypeCode.UInt64 => ((ulong)value).ToString("X16", null),
- TypeCode.Int64 => ((ulong)(long)value).ToString("X16", null),
- _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
- };
- }
-
- internal static string? GetEnumName(RuntimeType enumType, ulong ulValue)
- {
- return GetEnumName(GetEnumInfo(enumType), ulValue);
- }
-
- private static string? GetEnumName(EnumInfo enumInfo, ulong ulValue)
- {
- int index = Array.BinarySearch(enumInfo.Values, ulValue);
- if (index >= 0)
- {
- return enumInfo.Names[index];
- }
-
- return null; // return null so the caller knows to .ToString() the input
- }
-
- private static string? InternalFormat(RuntimeType enumType, ulong value)
- {
- EnumInfo enumInfo = GetEnumInfo(enumType);
-
- if (!enumInfo.HasFlagsAttribute)
- {
- return GetEnumName(enumInfo, value);
- }
- else // These are flags OR'ed together (We treat everything as unsigned types)
- {
- return InternalFlagsFormat(enumType, enumInfo, value);
- }
- }
-
- private static string? InternalFlagsFormat(RuntimeType enumType, ulong result)
- {
- return InternalFlagsFormat(enumType, GetEnumInfo(enumType), result);
- }
-
- private static string? InternalFlagsFormat(RuntimeType enumType, EnumInfo enumInfo, ulong resultValue)
- {
- Debug.Assert(enumType != null);
-
- string[] names = enumInfo.Names;
- ulong[] values = enumInfo.Values;
- Debug.Assert(names.Length == values.Length);
-
- // Values are sorted, so if the incoming value is 0, we can check to see whether
- // the first entry matches it, in which case we can return its name; otherwise,
- // we can just return "0".
- if (resultValue == 0)
- {
- return values.Length > 0 && values[0] == 0 ?
- names[0] :
- "0";
- }
-
- // With a ulong result value, regardless of the enum's base type, the maximum
- // possible number of consistent name/values we could have is 64, since every
- // value is made up of one or more bits, and when we see values and incorporate
- // their names, we effectively switch off those bits.
- Span<int> foundItems = stackalloc int[64];
-
- // Walk from largest to smallest. It's common to have a flags enum with a single
- // value that matches a single entry, in which case we can just return the existing
- // name string.
- int index = values.Length - 1;
- while (index >= 0)
- {
- if (values[index] == resultValue)
- {
- return names[index];
- }
-
- if (values[index] < resultValue)
- {
- break;
- }
-
- index--;
- }
-
- // Now look for multiple matches, storing the indices of the values
- // into our span.
- int resultLength = 0, foundItemsCount = 0;
- while (index >= 0)
- {
- ulong currentValue = values[index];
- if (index == 0 && currentValue == 0)
- {
- break;
- }
-
- if ((resultValue & currentValue) == currentValue)
- {
- resultValue -= currentValue;
- foundItems[foundItemsCount++] = index;
- resultLength = checked(resultLength + names[index].Length);
- }
-
- index--;
- }
-
- // If we exhausted looking through all the values and we still have
- // a non-zero result, we couldn't match the result to only named values.
- // In that case, we return null and let the call site just generate
- // a string for the integral value.
- if (resultValue != 0)
- {
- return null;
- }
-
- // We know what strings to concatenate. Do so.
-
- Debug.Assert(foundItemsCount > 0);
- const int SeparatorStringLength = 2; // ", "
- string result = string.FastAllocateString(checked(resultLength + (SeparatorStringLength * (foundItemsCount - 1))));
-
- Span<char> resultSpan = new Span<char>(ref result.GetRawStringData(), result.Length);
- string name = names[foundItems[--foundItemsCount]];
- name.AsSpan().CopyTo(resultSpan);
- resultSpan = resultSpan.Slice(name.Length);
- while (--foundItemsCount >= 0)
- {
- resultSpan[0] = EnumSeparatorChar;
- resultSpan[1] = ' ';
- resultSpan = resultSpan.Slice(2);
-
- name = names[foundItems[foundItemsCount]];
- name.AsSpan().CopyTo(resultSpan);
- resultSpan = resultSpan.Slice(name.Length);
- }
- Debug.Assert(resultSpan.IsEmpty);
-
- return result;
- }
-
- internal static ulong ToUInt64(object value)
- {
- // Helper function to silently convert the value to UInt64 from the other base types for enum without throwing an exception.
- // This is need since the Convert functions do overflow checks.
- TypeCode typeCode = Convert.GetTypeCode(value);
- ulong result = typeCode switch
- {
- TypeCode.SByte => (ulong)(sbyte)value,
- TypeCode.Byte => (byte)value,
- TypeCode.Boolean => Convert.ToByte((bool)value), // direct cast from bool to byte is not allowed
- TypeCode.Int16 => (ulong)(short)value,
- TypeCode.UInt16 => (ushort)value,
- TypeCode.Char => (ushort)(char)value,
- TypeCode.UInt32 => (uint)value,
- TypeCode.Int32 => (ulong)(int)value,
- TypeCode.UInt64 => (ulong)value,
- TypeCode.Int64 => (ulong)(long)value,
- _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
- };
- return result;
- }
-
- #endregion
-
- #region Public Static Methods
- public static object Parse(Type enumType, string value) =>
- Parse(enumType, value, ignoreCase: false);
-
- public static object Parse(Type enumType, string value, bool ignoreCase)
- {
- bool success = TryParse(enumType, value, ignoreCase, throwOnFailure: true, out object? result);
- Debug.Assert(success);
- return result!;
- }
-
- public static TEnum Parse<TEnum>(string value) where TEnum : struct =>
- Parse<TEnum>(value, ignoreCase: false);
-
- public static TEnum Parse<TEnum>(string value, bool ignoreCase) where TEnum : struct
- {
- bool success = TryParse<TEnum>(value, ignoreCase, throwOnFailure: true, out TEnum result);
- Debug.Assert(success);
- return result;
- }
-
- public static bool TryParse(Type enumType, string? value, out object? result) =>
- TryParse(enumType, value, ignoreCase: false, out result);
-
- public static bool TryParse(Type enumType, string? value, bool ignoreCase, out object? result) =>
- TryParse(enumType, value, ignoreCase, throwOnFailure: false, out result);
-
- private static bool TryParse(Type enumType, string? value, bool ignoreCase, bool throwOnFailure, out object? result)
- {
- // Validation on the enum type itself. Failures here are considered non-parsing failures
- // and thus always throw rather than returning false.
- RuntimeType rt = ValidateRuntimeType(enumType);
-
- ReadOnlySpan<char> valueSpan = value.AsSpan().TrimStart();
- if (valueSpan.Length == 0)
- {
- if (throwOnFailure)
- {
- throw value == null ?
- new ArgumentNullException(nameof(value)) :
- new ArgumentException(SR.Arg_MustContainEnumInfo, nameof(value));
- }
- result = null;
- return false;
- }
-
- int intResult;
- uint uintResult;
- bool parsed;
-
- switch (Type.GetTypeCode(rt))
- {
- case TypeCode.SByte:
- parsed = TryParseInt32Enum(rt, value, valueSpan, sbyte.MinValue, sbyte.MaxValue, ignoreCase, throwOnFailure, TypeCode.SByte, out intResult);
- result = parsed ? InternalBoxEnum(rt, intResult) : null;
- return parsed;
-
- case TypeCode.Int16:
- parsed = TryParseInt32Enum(rt, value, valueSpan, short.MinValue, short.MaxValue, ignoreCase, throwOnFailure, TypeCode.Int16, out intResult);
- result = parsed ? InternalBoxEnum(rt, intResult) : null;
- return parsed;
-
- case TypeCode.Int32:
- parsed = TryParseInt32Enum(rt, value, valueSpan, int.MinValue, int.MaxValue, ignoreCase, throwOnFailure, TypeCode.Int32, out intResult);
- result = parsed ? InternalBoxEnum(rt, intResult) : null;
- return parsed;
-
- case TypeCode.Byte:
- parsed = TryParseUInt32Enum(rt, value, valueSpan, byte.MaxValue, ignoreCase, throwOnFailure, TypeCode.Byte, out uintResult);
- result = parsed ? InternalBoxEnum(rt, uintResult) : null;
- return parsed;
-
- case TypeCode.UInt16:
- parsed = TryParseUInt32Enum(rt, value, valueSpan, ushort.MaxValue, ignoreCase, throwOnFailure, TypeCode.UInt16, out uintResult);
- result = parsed ? InternalBoxEnum(rt, uintResult) : null;
- return parsed;
-
- case TypeCode.UInt32:
- parsed = TryParseUInt32Enum(rt, value, valueSpan, uint.MaxValue, ignoreCase, throwOnFailure, TypeCode.UInt32, out uintResult);
- result = parsed ? InternalBoxEnum(rt, uintResult) : null;
- return parsed;
-
- case TypeCode.Int64:
- parsed = TryParseInt64Enum(rt, value, valueSpan, ignoreCase, throwOnFailure, out long longResult);
- result = parsed ? InternalBoxEnum(rt, longResult) : null;
- return parsed;
-
- case TypeCode.UInt64:
- parsed = TryParseUInt64Enum(rt, value, valueSpan, ignoreCase, throwOnFailure, out ulong ulongResult);
- result = parsed ? InternalBoxEnum(rt, (long)ulongResult) : null;
- return parsed;
-
- default:
- return TryParseRareEnum(rt, value, valueSpan, ignoreCase, throwOnFailure, out result);
- }
- }
-
- public static bool TryParse<TEnum>(string? value, out TEnum result) where TEnum : struct =>
- TryParse<TEnum>(value, ignoreCase: false, out result);
-
- public static bool TryParse<TEnum>(string? value, bool ignoreCase, out TEnum result) where TEnum : struct =>
- TryParse<TEnum>(value, ignoreCase, throwOnFailure: false, out result);
-
- private static bool TryParse<TEnum>(string? value, bool ignoreCase, bool throwOnFailure, out TEnum result) where TEnum : struct
- {
- // Validation on the enum type itself. Failures here are considered non-parsing failures
- // and thus always throw rather than returning false.
- if (!typeof(TEnum).IsEnum)
- {
- throw new ArgumentException(SR.Arg_MustBeEnum, nameof(TEnum));
- }
-
- ReadOnlySpan<char> valueSpan = value.AsSpan().TrimStart();
- if (valueSpan.Length == 0)
- {
- if (throwOnFailure)
- {
- throw value == null ?
- new ArgumentNullException(nameof(value)) :
- new ArgumentException(SR.Arg_MustContainEnumInfo, nameof(value));
- }
- result = default;
- return false;
- }
-
- int intResult;
- uint uintResult;
- bool parsed;
- RuntimeType rt = (RuntimeType)typeof(TEnum);
-
- switch (Type.GetTypeCode(typeof(TEnum)))
- {
- case TypeCode.SByte:
- parsed = TryParseInt32Enum(rt, value, valueSpan, sbyte.MinValue, sbyte.MaxValue, ignoreCase, throwOnFailure, TypeCode.SByte, out intResult);
- sbyte sbyteResult = (sbyte)intResult;
- result = Unsafe.As<sbyte, TEnum>(ref sbyteResult);
- return parsed;
-
- case TypeCode.Int16:
- parsed = TryParseInt32Enum(rt, value, valueSpan, short.MinValue, short.MaxValue, ignoreCase, throwOnFailure, TypeCode.Int16, out intResult);
- short shortResult = (short)intResult;
- result = Unsafe.As<short, TEnum>(ref shortResult);
- return parsed;
-
- case TypeCode.Int32:
- parsed = TryParseInt32Enum(rt, value, valueSpan, int.MinValue, int.MaxValue, ignoreCase, throwOnFailure, TypeCode.Int32, out intResult);
- result = Unsafe.As<int, TEnum>(ref intResult);
- return parsed;
-
- case TypeCode.Byte:
- parsed = TryParseUInt32Enum(rt, value, valueSpan, byte.MaxValue, ignoreCase, throwOnFailure, TypeCode.Byte, out uintResult);
- byte byteResult = (byte)uintResult;
- result = Unsafe.As<byte, TEnum>(ref byteResult);
- return parsed;
-
- case TypeCode.UInt16:
- parsed = TryParseUInt32Enum(rt, value, valueSpan, ushort.MaxValue, ignoreCase, throwOnFailure, TypeCode.UInt16, out uintResult);
- ushort ushortResult = (ushort)uintResult;
- result = Unsafe.As<ushort, TEnum>(ref ushortResult);
- return parsed;
-
- case TypeCode.UInt32:
- parsed = TryParseUInt32Enum(rt, value, valueSpan, uint.MaxValue, ignoreCase, throwOnFailure, TypeCode.UInt32, out uintResult);
- result = Unsafe.As<uint, TEnum>(ref uintResult);
- return parsed;
-
- case TypeCode.Int64:
- parsed = TryParseInt64Enum(rt, value, valueSpan, ignoreCase, throwOnFailure, out long longResult);
- result = Unsafe.As<long, TEnum>(ref longResult);
- return parsed;
-
- case TypeCode.UInt64:
- parsed = TryParseUInt64Enum(rt, value, valueSpan, ignoreCase, throwOnFailure, out ulong ulongResult);
- result = Unsafe.As<ulong, TEnum>(ref ulongResult);
- return parsed;
-
- default:
- parsed = TryParseRareEnum(rt, value, valueSpan, ignoreCase, throwOnFailure, out object? objectResult);
- result = parsed ? (TEnum)objectResult! : default;
- return parsed;
- }
- }
-
- /// <summary>Tries to parse the value of an enum with known underlying types that fit in an Int32 (Int32, Int16, and SByte).</summary>
- private static bool TryParseInt32Enum(
- RuntimeType enumType, string? originalValueString, ReadOnlySpan<char> value, int minInclusive, int maxInclusive, bool ignoreCase, bool throwOnFailure, TypeCode type, out int result)
- {
- Debug.Assert(
- enumType.GetEnumUnderlyingType() == typeof(sbyte) ||
- enumType.GetEnumUnderlyingType() == typeof(short) ||
- enumType.GetEnumUnderlyingType() == typeof(int));
-
- Number.ParsingStatus status = default;
- if (StartsNumber(value[0]))
- {
- status = Number.TryParseInt32IntegerStyle(value, NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture.NumberFormat, out result);
- if (status == Number.ParsingStatus.OK)
- {
- if ((uint)(result - minInclusive) <= (uint)(maxInclusive - minInclusive))
- {
- return true;
- }
-
- status = Number.ParsingStatus.Overflow;
- }
- }
-
- if (status == Number.ParsingStatus.Overflow)
- {
- if (throwOnFailure)
- {
- Number.ThrowOverflowException(type);
- }
- }
- else if (TryParseByName(enumType, originalValueString, value, ignoreCase, throwOnFailure, out ulong ulongResult))
- {
- result = (int)ulongResult;
- Debug.Assert(result >= minInclusive && result <= maxInclusive);
- return true;
- }
-
- result = 0;
- return false;
- }
-
- /// <summary>Tries to parse the value of an enum with known underlying types that fit in a UInt32 (UInt32, UInt16, and Byte).</summary>
- private static bool TryParseUInt32Enum(RuntimeType enumType, string? originalValueString, ReadOnlySpan<char> value, uint maxInclusive, bool ignoreCase, bool throwOnFailure, TypeCode type, out uint result)
- {
- Debug.Assert(
- enumType.GetEnumUnderlyingType() == typeof(byte) ||
- enumType.GetEnumUnderlyingType() == typeof(ushort) ||
- enumType.GetEnumUnderlyingType() == typeof(uint));
-
- Number.ParsingStatus status = default;
- if (StartsNumber(value[0]))
- {
- status = Number.TryParseUInt32IntegerStyle(value, NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture.NumberFormat, out result);
- if (status == Number.ParsingStatus.OK)
- {
- if (result <= maxInclusive)
- {
- return true;
- }
-
- status = Number.ParsingStatus.Overflow;
- }
- }
-
- if (status == Number.ParsingStatus.Overflow)
- {
- if (throwOnFailure)
- {
- Number.ThrowOverflowException(type);
- }
- }
- else if (TryParseByName(enumType, originalValueString, value, ignoreCase, throwOnFailure, out ulong ulongResult))
- {
- result = (uint)ulongResult;
- Debug.Assert(result <= maxInclusive);
- return true;
- }
-
- result = 0;
- return false;
- }
-
- /// <summary>Tries to parse the value of an enum with Int64 as the underlying type.</summary>
- private static bool TryParseInt64Enum(RuntimeType enumType, string? originalValueString, ReadOnlySpan<char> value, bool ignoreCase, bool throwOnFailure, out long result)
- {
- Debug.Assert(enumType.GetEnumUnderlyingType() == typeof(long));
-
- Number.ParsingStatus status = default;
- if (StartsNumber(value[0]))
- {
- status = Number.TryParseInt64IntegerStyle(value, NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture.NumberFormat, out result);
- if (status == Number.ParsingStatus.OK)
- {
- return true;
- }
- }
-
- if (status == Number.ParsingStatus.Overflow)
- {
- if (throwOnFailure)
- {
- Number.ThrowOverflowException(TypeCode.Int64);
- }
- }
- else if (TryParseByName(enumType, originalValueString, value, ignoreCase, throwOnFailure, out ulong ulongResult))
- {
- result = (long)ulongResult;
- return true;
- }
-
- result = 0;
- return false;
- }
-
- /// <summary>Tries to parse the value of an enum with UInt64 as the underlying type.</summary>
- private static bool TryParseUInt64Enum(RuntimeType enumType, string? originalValueString, ReadOnlySpan<char> value, bool ignoreCase, bool throwOnFailure, out ulong result)
- {
- Debug.Assert(enumType.GetEnumUnderlyingType() == typeof(ulong));
-
- Number.ParsingStatus status = default;
- if (StartsNumber(value[0]))
- {
- status = Number.TryParseUInt64IntegerStyle(value, NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture.NumberFormat, out result);
- if (status == Number.ParsingStatus.OK)
- {
- return true;
- }
- }
-
- if (status == Number.ParsingStatus.Overflow)
- {
- if (throwOnFailure)
- {
- Number.ThrowOverflowException(TypeCode.UInt64);
- }
- }
- else if (TryParseByName(enumType, originalValueString, value, ignoreCase, throwOnFailure, out result))
- {
- return true;
- }
-
- result = 0;
- return false;
- }
-
- /// <summary>Tries to parse the value of an enum with an underlying type that can't be expressed in C# (e.g. char, bool, double, etc.)</summary>
- private static bool TryParseRareEnum(RuntimeType enumType, string? originalValueString, ReadOnlySpan<char> value, bool ignoreCase, bool throwOnFailure, [NotNullWhen(true)] out object? result)
- {
- Debug.Assert(
- enumType.GetEnumUnderlyingType() != typeof(sbyte) &&
- enumType.GetEnumUnderlyingType() != typeof(byte) &&
- enumType.GetEnumUnderlyingType() != typeof(short) &&
- enumType.GetEnumUnderlyingType() != typeof(ushort) &&
- enumType.GetEnumUnderlyingType() != typeof(int) &&
- enumType.GetEnumUnderlyingType() != typeof(uint) &&
- enumType.GetEnumUnderlyingType() != typeof(long) &&
- enumType.GetEnumUnderlyingType() != typeof(ulong),
- "Should only be used when parsing enums with rare underlying types, those that can't be expressed in C#.");
-
- if (StartsNumber(value[0]))
- {
- Type underlyingType = GetUnderlyingType(enumType);
- try
- {
- result = ToObject(enumType, Convert.ChangeType(value.ToString(), underlyingType, CultureInfo.InvariantCulture)!);
- return true;
- }
- catch (FormatException)
- {
- // We need to Parse this as a String instead. There are cases
- // when you tlbimp enums that can have values of the form "3D".
- }
- catch when (!throwOnFailure)
- {
- result = null;
- return false;
- }
- }
-
- if (TryParseByName(enumType, originalValueString, value, ignoreCase, throwOnFailure, out ulong ulongResult))
- {
- try
- {
- result = ToObject(enumType, ulongResult);
- return true;
- }
- catch when (!throwOnFailure) { }
- }
-
- result = null;
- return false;
- }
-
- private static bool TryParseByName(RuntimeType enumType, string? originalValueString, ReadOnlySpan<char> value, bool ignoreCase, bool throwOnFailure, out ulong result)
- {
- // Find the field. Let's assume that these are always static classes because the class is an enum.
- EnumInfo enumInfo = GetEnumInfo(enumType);
- string[] enumNames = enumInfo.Names;
- ulong[] enumValues = enumInfo.Values;
-
- bool parsed = true;
- ulong localResult = 0;
- while (value.Length > 0)
- {
- // Find the next separator.
- ReadOnlySpan<char> subvalue;
- int endIndex = value.IndexOf(EnumSeparatorChar);
- if (endIndex == -1)
- {
- // No next separator; use the remainder as the next value.
- subvalue = value.Trim();
- value = default;
- }
- else if (endIndex != value.Length - 1)
- {
- // Found a separator before the last char.
- subvalue = value.Slice(0, endIndex).Trim();
- value = value.Slice(endIndex + 1);
- }
- else
- {
- // Last char was a separator, which is invalid.
- parsed = false;
- break;
- }
-
- // Try to match this substring against each enum name
- bool success = false;
- if (ignoreCase)
- {
- for (int i = 0; i < enumNames.Length; i++)
- {
- if (subvalue.EqualsOrdinalIgnoreCase(enumNames[i]))
- {
- localResult |= enumValues[i];
- success = true;
- break;
- }
- }
- }
- else
- {
- for (int i = 0; i < enumNames.Length; i++)
- {
- if (subvalue.EqualsOrdinal(enumNames[i]))
- {
- localResult |= enumValues[i];
- success = true;
- break;
- }
- }
- }
-
- if (!success)
- {
- parsed = false;
- break;
- }
- }
-
- if (parsed)
- {
- result = localResult;
- return true;
- }
-
- if (throwOnFailure)
- {
- throw new ArgumentException(SR.Format(SR.Arg_EnumValueNotFound, originalValueString));
- }
-
- result = 0;
- return false;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool StartsNumber(char c) => char.IsInRange(c, '0', '9') || c == '-' || c == '+';
-
- public static object ToObject(Type enumType, object value)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- // Delegate rest of error checking to the other functions
- TypeCode typeCode = Convert.GetTypeCode(value);
-
- return typeCode switch
- {
- TypeCode.Int32 => ToObject(enumType, (int)value),
- TypeCode.SByte => ToObject(enumType, (sbyte)value),
- TypeCode.Int16 => ToObject(enumType, (short)value),
- TypeCode.Int64 => ToObject(enumType, (long)value),
- TypeCode.UInt32 => ToObject(enumType, (uint)value),
- TypeCode.Byte => ToObject(enumType, (byte)value),
- TypeCode.UInt16 => ToObject(enumType, (ushort)value),
- TypeCode.UInt64 => ToObject(enumType, (ulong)value),
- TypeCode.Char => ToObject(enumType, (char)value),
- TypeCode.Boolean => ToObject(enumType, (bool)value),
- _ => throw new ArgumentException(SR.Arg_MustBeEnumBaseTypeOrEnum, nameof(value)),
- };
- }
-
- public static string Format(Type enumType, object value, string format)
- {
- RuntimeType rtType = ValidateRuntimeType(enumType);
-
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- if (format == null)
- throw new ArgumentNullException(nameof(format));
-
- // If the value is an Enum then we need to extract the underlying value from it
- Type valueType = value.GetType();
- if (valueType.IsEnum)
- {
- if (!valueType.IsEquivalentTo(enumType))
- throw new ArgumentException(SR.Format(SR.Arg_EnumAndObjectMustBeSameType, valueType, enumType));
-
- if (format.Length != 1)
- {
- // all acceptable format string are of length 1
- throw new FormatException(SR.Format_InvalidEnumFormatSpecification);
- }
- return ((Enum)value).ToString(format);
- }
-
- // The value must be of the same type as the Underlying type of the Enum
- Type underlyingType = GetUnderlyingType(enumType);
- if (valueType != underlyingType)
- {
- throw new ArgumentException(SR.Format(SR.Arg_EnumFormatUnderlyingTypeAndObjectMustBeSameType, valueType, underlyingType));
- }
-
- if (format.Length == 1)
- {
- switch (format[0])
- {
- case 'G':
- case 'g':
- return GetEnumName(rtType, ToUInt64(value)) ?? value.ToString()!;
-
- case 'D':
- case 'd':
- return value.ToString()!;
-
- case 'X':
- case 'x':
- return ValueToHexString(value);
-
- case 'F':
- case 'f':
- return InternalFlagsFormat(rtType, ToUInt64(value)) ?? value.ToString()!;
- }
- }
-
- throw new FormatException(SR.Format_InvalidEnumFormatSpecification);
- }
- #endregion
-
- #region Private Methods
- internal object GetValue()
- {
- ref byte data = ref this.GetRawData();
- return (InternalGetCorElementType()) switch
- {
- CorElementType.ELEMENT_TYPE_I1 => Unsafe.As<byte, sbyte>(ref data),
- CorElementType.ELEMENT_TYPE_U1 => data,
- CorElementType.ELEMENT_TYPE_BOOLEAN => Unsafe.As<byte, bool>(ref data),
- CorElementType.ELEMENT_TYPE_I2 => Unsafe.As<byte, short>(ref data),
- CorElementType.ELEMENT_TYPE_U2 => Unsafe.As<byte, ushort>(ref data),
- CorElementType.ELEMENT_TYPE_CHAR => Unsafe.As<byte, char>(ref data),
- CorElementType.ELEMENT_TYPE_I4 => Unsafe.As<byte, int>(ref data),
- CorElementType.ELEMENT_TYPE_U4 => Unsafe.As<byte, uint>(ref data),
- CorElementType.ELEMENT_TYPE_R4 => Unsafe.As<byte, float>(ref data),
- CorElementType.ELEMENT_TYPE_I8 => Unsafe.As<byte, long>(ref data),
- CorElementType.ELEMENT_TYPE_U8 => Unsafe.As<byte, ulong>(ref data),
- CorElementType.ELEMENT_TYPE_R8 => Unsafe.As<byte, double>(ref data),
- CorElementType.ELEMENT_TYPE_I => Unsafe.As<byte, IntPtr>(ref data),
- CorElementType.ELEMENT_TYPE_U => Unsafe.As<byte, UIntPtr>(ref data),
- _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
- };
- }
-
- private ulong ToUInt64()
- {
- ref byte data = ref this.GetRawData();
- switch (InternalGetCorElementType())
- {
- case CorElementType.ELEMENT_TYPE_I1:
- return (ulong)Unsafe.As<byte, sbyte>(ref data);
- case CorElementType.ELEMENT_TYPE_U1:
- return data;
- case CorElementType.ELEMENT_TYPE_BOOLEAN:
- return Convert.ToUInt64(Unsafe.As<byte, bool>(ref data), CultureInfo.InvariantCulture);
- case CorElementType.ELEMENT_TYPE_I2:
- return (ulong)Unsafe.As<byte, short>(ref data);
- case CorElementType.ELEMENT_TYPE_U2:
- case CorElementType.ELEMENT_TYPE_CHAR:
- return Unsafe.As<byte, ushort>(ref data);
- case CorElementType.ELEMENT_TYPE_I4:
- return (ulong)Unsafe.As<byte, int>(ref data);
- case CorElementType.ELEMENT_TYPE_U4:
- case CorElementType.ELEMENT_TYPE_R4:
- return Unsafe.As<byte, uint>(ref data);
- case CorElementType.ELEMENT_TYPE_I8:
- return (ulong)Unsafe.As<byte, long>(ref data);
- case CorElementType.ELEMENT_TYPE_U8:
- case CorElementType.ELEMENT_TYPE_R8:
- return Unsafe.As<byte, ulong>(ref data);
- case CorElementType.ELEMENT_TYPE_I:
- return (ulong)Unsafe.As<byte, IntPtr>(ref data);
- case CorElementType.ELEMENT_TYPE_U:
- return (ulong)Unsafe.As<byte, UIntPtr>(ref data);
- default:
- throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
- }
- }
-
- #endregion
-
- #region Object Overrides
-
- public override int GetHashCode()
- {
- // CONTRACT with the runtime: GetHashCode of enum types is implemented as GetHashCode of the underlying type.
- // The runtime can bypass calls to Enum::GetHashCode and call the underlying type's GetHashCode directly
- // to avoid boxing the enum.
- ref byte data = ref this.GetRawData();
- return (InternalGetCorElementType()) switch
- {
- CorElementType.ELEMENT_TYPE_I1 => Unsafe.As<byte, sbyte>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_U1 => data.GetHashCode(),
- CorElementType.ELEMENT_TYPE_BOOLEAN => Unsafe.As<byte, bool>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_I2 => Unsafe.As<byte, short>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_U2 => Unsafe.As<byte, ushort>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_CHAR => Unsafe.As<byte, char>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_I4 => Unsafe.As<byte, int>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_U4 => Unsafe.As<byte, uint>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_R4 => Unsafe.As<byte, float>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_I8 => Unsafe.As<byte, long>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_U8 => Unsafe.As<byte, ulong>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_R8 => Unsafe.As<byte, double>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_I => Unsafe.As<byte, IntPtr>(ref data).GetHashCode(),
- CorElementType.ELEMENT_TYPE_U => Unsafe.As<byte, UIntPtr>(ref data).GetHashCode(),
- _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
- };
- }
-
- public override string ToString()
- {
- // Returns the value in a human readable format. For PASCAL style enums who's value maps directly the name of the field is returned.
- // For PASCAL style enums who's values do not map directly the decimal value of the field is returned.
- // For BitFlags (indicated by the Flags custom attribute): If for each bit that is set in the value there is a corresponding constant
- // (a pure power of 2), then the OR string (ie "Red, Yellow") is returned. Otherwise, if the value is zero or if you can't create a string that consists of
- // pure powers of 2 OR-ed together, you return a hex value
-
- // Try to see if its one of the enum values, then we return a String back else the value
- return InternalFormat((RuntimeType)GetType(), ToUInt64()) ?? ValueToString();
- }
-
- public int CompareTo(object? target)
- {
- if (target == this)
- return 0;
-
- if (target == null)
- return 1; // all values are greater than null
-
- if (GetType() != target.GetType())
- throw new ArgumentException(SR.Format(SR.Arg_EnumAndObjectMustBeSameType, target.GetType(), GetType()));
-
- ref byte pThisValue = ref this.GetRawData();
- ref byte pTargetValue = ref target.GetRawData();
-
- switch (InternalGetCorElementType())
- {
- case CorElementType.ELEMENT_TYPE_I1:
- return Unsafe.As<byte, sbyte>(ref pThisValue).CompareTo(Unsafe.As<byte, sbyte>(ref pTargetValue));
- case CorElementType.ELEMENT_TYPE_U1:
- case CorElementType.ELEMENT_TYPE_BOOLEAN:
- return pThisValue.CompareTo(pTargetValue);
- case CorElementType.ELEMENT_TYPE_I2:
- return Unsafe.As<byte, short>(ref pThisValue).CompareTo(Unsafe.As<byte, short>(ref pTargetValue));
- case CorElementType.ELEMENT_TYPE_U2:
- case CorElementType.ELEMENT_TYPE_CHAR:
- return Unsafe.As<byte, ushort>(ref pThisValue).CompareTo(Unsafe.As<byte, ushort>(ref pTargetValue));
- case CorElementType.ELEMENT_TYPE_I4:
-#if !BIT64
- case CorElementType.ELEMENT_TYPE_I:
-#endif
- return Unsafe.As<byte, int>(ref pThisValue).CompareTo(Unsafe.As<byte, int>(ref pTargetValue));
- case CorElementType.ELEMENT_TYPE_U4:
-#if !BIT64
- case CorElementType.ELEMENT_TYPE_U:
-#endif
- return Unsafe.As<byte, uint>(ref pThisValue).CompareTo(Unsafe.As<byte, uint>(ref pTargetValue));
- case CorElementType.ELEMENT_TYPE_I8:
-#if BIT64
- case CorElementType.ELEMENT_TYPE_I:
-#endif
- return Unsafe.As<byte, long>(ref pThisValue).CompareTo(Unsafe.As<byte, long>(ref pTargetValue));
- case CorElementType.ELEMENT_TYPE_U8:
-#if BIT64
- case CorElementType.ELEMENT_TYPE_U:
-#endif
- return Unsafe.As<byte, ulong>(ref pThisValue).CompareTo(Unsafe.As<byte, ulong>(ref pTargetValue));
- case CorElementType.ELEMENT_TYPE_R4:
- return Unsafe.As<byte, float>(ref pThisValue).CompareTo(Unsafe.As<byte, float>(ref pTargetValue));
- case CorElementType.ELEMENT_TYPE_R8:
- return Unsafe.As<byte, double>(ref pThisValue).CompareTo(Unsafe.As<byte, double>(ref pTargetValue));
- default:
- throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
- }
- }
- #endregion
-
- #region IFormattable
- [Obsolete("The provider argument is not used. Please use ToString(String).")]
- public string ToString(string? format, IFormatProvider? provider)
- {
- return ToString(format);
- }
- #endregion
-
- #region Public Methods
- public string ToString(string? format)
- {
- if (string.IsNullOrEmpty(format))
- {
- return ToString();
- }
-
- if (format.Length == 1)
- {
- switch (format[0])
- {
- case 'G':
- case 'g':
- return ToString();
-
- case 'D':
- case 'd':
- return ValueToString();
-
- case 'X':
- case 'x':
- return ValueToHexString();
-
- case 'F':
- case 'f':
- return InternalFlagsFormat((RuntimeType)GetType(), ToUInt64()) ?? ValueToString();
- }
- }
-
- throw new FormatException(SR.Format_InvalidEnumFormatSpecification);
- }
-
- [Obsolete("The provider argument is not used. Please use ToString().")]
- public string ToString(IFormatProvider? provider)
- {
- return ToString();
- }
-
- #endregion
-
- #region IConvertible
- public TypeCode GetTypeCode()
- {
- return (InternalGetCorElementType()) switch
- {
- CorElementType.ELEMENT_TYPE_I1 => TypeCode.SByte,
- CorElementType.ELEMENT_TYPE_U1 => TypeCode.Byte,
- CorElementType.ELEMENT_TYPE_BOOLEAN => TypeCode.Boolean,
- CorElementType.ELEMENT_TYPE_I2 => TypeCode.Int16,
- CorElementType.ELEMENT_TYPE_U2 => TypeCode.UInt16,
- CorElementType.ELEMENT_TYPE_CHAR => TypeCode.Char,
- CorElementType.ELEMENT_TYPE_I4 => TypeCode.Int32,
- CorElementType.ELEMENT_TYPE_U4 => TypeCode.UInt32,
- CorElementType.ELEMENT_TYPE_I8 => TypeCode.Int64,
- CorElementType.ELEMENT_TYPE_U8 => TypeCode.UInt64,
- _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
- };
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(GetValue(), CultureInfo.CurrentCulture);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- return Convert.ToChar(GetValue(), CultureInfo.CurrentCulture);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(GetValue(), CultureInfo.CurrentCulture);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(GetValue(), CultureInfo.CurrentCulture);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(GetValue(), CultureInfo.CurrentCulture);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(GetValue(), CultureInfo.CurrentCulture);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(GetValue(), CultureInfo.CurrentCulture);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(GetValue(), CultureInfo.CurrentCulture);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(GetValue(), CultureInfo.CurrentCulture);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(GetValue(), CultureInfo.CurrentCulture);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(GetValue(), CultureInfo.CurrentCulture);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(GetValue(), CultureInfo.CurrentCulture);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(GetValue(), CultureInfo.CurrentCulture);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Enum", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- #endregion
-
- #region ToObject
- [CLSCompliant(false)]
- public static object ToObject(Type enumType, sbyte value) =>
- InternalBoxEnum(ValidateRuntimeType(enumType), value);
-
- public static object ToObject(Type enumType, short value) =>
- InternalBoxEnum(ValidateRuntimeType(enumType), value);
-
- public static object ToObject(Type enumType, int value) =>
- InternalBoxEnum(ValidateRuntimeType(enumType), value);
-
- public static object ToObject(Type enumType, byte value) =>
- InternalBoxEnum(ValidateRuntimeType(enumType), value);
-
- [CLSCompliant(false)]
- public static object ToObject(Type enumType, ushort value) =>
- InternalBoxEnum(ValidateRuntimeType(enumType), value);
-
- [CLSCompliant(false)]
- public static object ToObject(Type enumType, uint value) =>
- InternalBoxEnum(ValidateRuntimeType(enumType), value);
-
- public static object ToObject(Type enumType, long value) =>
- InternalBoxEnum(ValidateRuntimeType(enumType), value);
-
- [CLSCompliant(false)]
- public static object ToObject(Type enumType, ulong value) =>
- InternalBoxEnum(ValidateRuntimeType(enumType), unchecked((long)value));
-
- private static object ToObject(Type enumType, char value) =>
- InternalBoxEnum(ValidateRuntimeType(enumType), value);
-
- private static object ToObject(Type enumType, bool value) =>
- InternalBoxEnum(ValidateRuntimeType(enumType), value ? 1 : 0);
-
- #endregion
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Environment.NoRegistry.cs b/netcore/System.Private.CoreLib/shared/System/Environment.NoRegistry.cs
deleted file mode 100644
index 6e699b1f386..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Environment.NoRegistry.cs
+++ /dev/null
@@ -1,21 +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 System.Diagnostics;
-using System.Collections;
-using Microsoft.Win32;
-
-namespace System
-{
- public static partial class Environment
- {
- // Systems without the Windows registry pretend that it's always empty.
-
- private static string? GetEnvironmentVariableFromRegistry(string variable, bool fromMachine) => null;
-
- private static void SetEnvironmentVariableFromRegistry(string variable, string? value, bool fromMachine) { }
-
- private static IDictionary GetEnvironmentVariablesFromRegistry(bool fromMachine) => new Hashtable();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Environment.SpecialFolder.cs b/netcore/System.Private.CoreLib/shared/System/Environment.SpecialFolder.cs
deleted file mode 100644
index a5a4d2abfde..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Environment.SpecialFolder.cs
+++ /dev/null
@@ -1,115 +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.
-
-namespace System
-{
- public static partial class Environment
- {
- public enum SpecialFolder
- {
- ApplicationData = SpecialFolderValues.CSIDL_APPDATA,
- CommonApplicationData = SpecialFolderValues.CSIDL_COMMON_APPDATA,
- LocalApplicationData = SpecialFolderValues.CSIDL_LOCAL_APPDATA,
- Cookies = SpecialFolderValues.CSIDL_COOKIES,
- Desktop = SpecialFolderValues.CSIDL_DESKTOP,
- Favorites = SpecialFolderValues.CSIDL_FAVORITES,
- History = SpecialFolderValues.CSIDL_HISTORY,
- InternetCache = SpecialFolderValues.CSIDL_INTERNET_CACHE,
- Programs = SpecialFolderValues.CSIDL_PROGRAMS,
- MyComputer = SpecialFolderValues.CSIDL_DRIVES,
- MyMusic = SpecialFolderValues.CSIDL_MYMUSIC,
- MyPictures = SpecialFolderValues.CSIDL_MYPICTURES,
- MyVideos = SpecialFolderValues.CSIDL_MYVIDEO,
- Recent = SpecialFolderValues.CSIDL_RECENT,
- SendTo = SpecialFolderValues.CSIDL_SENDTO,
- StartMenu = SpecialFolderValues.CSIDL_STARTMENU,
- Startup = SpecialFolderValues.CSIDL_STARTUP,
- System = SpecialFolderValues.CSIDL_SYSTEM,
- Templates = SpecialFolderValues.CSIDL_TEMPLATES,
- DesktopDirectory = SpecialFolderValues.CSIDL_DESKTOPDIRECTORY,
- Personal = SpecialFolderValues.CSIDL_PERSONAL,
- MyDocuments = SpecialFolderValues.CSIDL_PERSONAL,
- ProgramFiles = SpecialFolderValues.CSIDL_PROGRAM_FILES,
- CommonProgramFiles = SpecialFolderValues.CSIDL_PROGRAM_FILES_COMMON,
- AdminTools = SpecialFolderValues.CSIDL_ADMINTOOLS,
- CDBurning = SpecialFolderValues.CSIDL_CDBURN_AREA,
- CommonAdminTools = SpecialFolderValues.CSIDL_COMMON_ADMINTOOLS,
- CommonDocuments = SpecialFolderValues.CSIDL_COMMON_DOCUMENTS,
- CommonMusic = SpecialFolderValues.CSIDL_COMMON_MUSIC,
- CommonOemLinks = SpecialFolderValues.CSIDL_COMMON_OEM_LINKS,
- CommonPictures = SpecialFolderValues.CSIDL_COMMON_PICTURES,
- CommonStartMenu = SpecialFolderValues.CSIDL_COMMON_STARTMENU,
- CommonPrograms = SpecialFolderValues.CSIDL_COMMON_PROGRAMS,
- CommonStartup = SpecialFolderValues.CSIDL_COMMON_STARTUP,
- CommonDesktopDirectory = SpecialFolderValues.CSIDL_COMMON_DESKTOPDIRECTORY,
- CommonTemplates = SpecialFolderValues.CSIDL_COMMON_TEMPLATES,
- CommonVideos = SpecialFolderValues.CSIDL_COMMON_VIDEO,
- Fonts = SpecialFolderValues.CSIDL_FONTS,
- NetworkShortcuts = SpecialFolderValues.CSIDL_NETHOOD,
- PrinterShortcuts = SpecialFolderValues.CSIDL_PRINTHOOD,
- UserProfile = SpecialFolderValues.CSIDL_PROFILE,
- CommonProgramFilesX86 = SpecialFolderValues.CSIDL_PROGRAM_FILES_COMMONX86,
- ProgramFilesX86 = SpecialFolderValues.CSIDL_PROGRAM_FILESX86,
- Resources = SpecialFolderValues.CSIDL_RESOURCES,
- LocalizedResources = SpecialFolderValues.CSIDL_RESOURCES_LOCALIZED,
- SystemX86 = SpecialFolderValues.CSIDL_SYSTEMX86,
- Windows = SpecialFolderValues.CSIDL_WINDOWS,
- }
-
- // These values are specific to Windows and are known to SHGetFolderPath, however they are
- // also the values used in the SpecialFolder enum. As such, we keep them as constants
- // with their Win32 names, but keep them here rather than in Interop.Kernel32 as they're
- // used on all platforms.
- private static class SpecialFolderValues
- {
- internal const int CSIDL_APPDATA = 0x001a;
- internal const int CSIDL_COMMON_APPDATA = 0x0023;
- internal const int CSIDL_LOCAL_APPDATA = 0x001c;
- internal const int CSIDL_COOKIES = 0x0021;
- internal const int CSIDL_FAVORITES = 0x0006;
- internal const int CSIDL_HISTORY = 0x0022;
- internal const int CSIDL_INTERNET_CACHE = 0x0020;
- internal const int CSIDL_PROGRAMS = 0x0002;
- internal const int CSIDL_RECENT = 0x0008;
- internal const int CSIDL_SENDTO = 0x0009;
- internal const int CSIDL_STARTMENU = 0x000b;
- internal const int CSIDL_STARTUP = 0x0007;
- internal const int CSIDL_SYSTEM = 0x0025;
- internal const int CSIDL_TEMPLATES = 0x0015;
- internal const int CSIDL_DESKTOPDIRECTORY = 0x0010;
- internal const int CSIDL_PERSONAL = 0x0005;
- internal const int CSIDL_PROGRAM_FILES = 0x0026;
- internal const int CSIDL_PROGRAM_FILES_COMMON = 0x002b;
- internal const int CSIDL_DESKTOP = 0x0000;
- internal const int CSIDL_DRIVES = 0x0011;
- internal const int CSIDL_MYMUSIC = 0x000d;
- internal const int CSIDL_MYPICTURES = 0x0027;
-
- internal const int CSIDL_ADMINTOOLS = 0x0030; // <user name>\Start Menu\Programs\Administrative Tools
- internal const int CSIDL_CDBURN_AREA = 0x003b; // USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
- internal const int CSIDL_COMMON_ADMINTOOLS = 0x002f; // All Users\Start Menu\Programs\Administrative Tools
- internal const int CSIDL_COMMON_DOCUMENTS = 0x002e; // All Users\Documents
- internal const int CSIDL_COMMON_MUSIC = 0x0035; // All Users\My Music
- internal const int CSIDL_COMMON_OEM_LINKS = 0x003a; // Links to All Users OEM specific apps
- internal const int CSIDL_COMMON_PICTURES = 0x0036; // All Users\My Pictures
- internal const int CSIDL_COMMON_STARTMENU = 0x0016; // All Users\Start Menu
- internal const int CSIDL_COMMON_PROGRAMS = 0X0017; // All Users\Start Menu\Programs
- internal const int CSIDL_COMMON_STARTUP = 0x0018; // All Users\Startup
- internal const int CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019; // All Users\Desktop
- internal const int CSIDL_COMMON_TEMPLATES = 0x002d; // All Users\Templates
- internal const int CSIDL_COMMON_VIDEO = 0x0037; // All Users\My Video
- internal const int CSIDL_FONTS = 0x0014; // windows\fonts
- internal const int CSIDL_MYVIDEO = 0x000e; // "My Videos" folder
- internal const int CSIDL_NETHOOD = 0x0013; // %APPDATA%\Microsoft\Windows\Network Shortcuts
- internal const int CSIDL_PRINTHOOD = 0x001b; // %APPDATA%\Microsoft\Windows\Printer Shortcuts
- internal const int CSIDL_PROFILE = 0x0028; // %USERPROFILE% (%SystemDrive%\Users\%USERNAME%)
- internal const int CSIDL_PROGRAM_FILES_COMMONX86 = 0x002c; // x86 Program Files\Common on RISC
- internal const int CSIDL_PROGRAM_FILESX86 = 0x002a; // x86 C:\Program Files on RISC
- internal const int CSIDL_RESOURCES = 0x0038; // %windir%\Resources
- internal const int CSIDL_RESOURCES_LOCALIZED = 0x0039; // %windir%\resources\0409 (code page)
- internal const int CSIDL_SYSTEMX86 = 0x0029; // %windir%\system32
- internal const int CSIDL_WINDOWS = 0x0024; // GetWindowsDirectory()
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Environment.SpecialFolderOption.cs b/netcore/System.Private.CoreLib/shared/System/Environment.SpecialFolderOption.cs
deleted file mode 100644
index cd0e5714ef0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Environment.SpecialFolderOption.cs
+++ /dev/null
@@ -1,33 +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.
-
-namespace System
-{
- public static partial class Environment
- {
- public enum SpecialFolderOption
- {
- None = 0,
- Create = SpecialFolderOptionValues.CSIDL_FLAG_CREATE,
- DoNotVerify = SpecialFolderOptionValues.CSIDL_FLAG_DONT_VERIFY,
- }
-
- // These values are specific to Windows and are known to SHGetFolderPath, however they are
- // also the values used in the SpecialFolderOption enum. As such, we keep them as constants
- // with their Win32 names, but keep them here rather than in Interop.Kernel32 as they're
- // used on all platforms.
- private static class SpecialFolderOptionValues
- {
- /// <summary>
- /// Force folder creation in SHGetFolderPath. Equivalent of KF_FLAG_CREATE (0x00008000).
- /// </summary>
- internal const int CSIDL_FLAG_CREATE = 0x8000;
-
- /// <summary>
- /// Return an unverified folder path. Equivalent of KF_FLAG_DONT_VERIFY (0x00004000).
- /// </summary>
- internal const int CSIDL_FLAG_DONT_VERIFY = 0x4000;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Environment.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Environment.Unix.cs
deleted file mode 100644
index d733feb5316..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Environment.Unix.cs
+++ /dev/null
@@ -1,466 +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 System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Reflection;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading;
-
-namespace System
-{
- public static partial class Environment
- {
- private static Func<string, object>? s_directoryCreateDirectory;
-
- private static string CurrentDirectoryCore
- {
- get => Interop.Sys.GetCwd();
- set => Interop.CheckIo(Interop.Sys.ChDir(value), value, isDirectory: true);
- }
-
- private static string ExpandEnvironmentVariablesCore(string name)
- {
- var result = new ValueStringBuilder(stackalloc char[128]);
-
- int lastPos = 0, pos;
- while (lastPos < name.Length && (pos = name.IndexOf('%', lastPos + 1)) >= 0)
- {
- if (name[lastPos] == '%')
- {
- string key = name.Substring(lastPos + 1, pos - lastPos - 1);
- string? value = GetEnvironmentVariable(key);
- if (value != null)
- {
- result.Append(value);
- lastPos = pos + 1;
- continue;
- }
- }
- result.Append(name.AsSpan(lastPos, pos - lastPos));
- lastPos = pos;
- }
- result.Append(name.AsSpan(lastPos));
-
- return result.ToString();
- }
-
- private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
- {
- // Get the path for the SpecialFolder
- string path = GetFolderPathCoreWithoutValidation(folder);
- Debug.Assert(path != null);
-
- // If we didn't get one, or if we got one but we're not supposed to verify it,
- // or if we're supposed to verify it and it passes verification, return the path.
- if (path.Length == 0 ||
- option == SpecialFolderOption.DoNotVerify ||
- Interop.Sys.Access(path, Interop.Sys.AccessMode.R_OK) == 0)
- {
- return path;
- }
-
- // Failed verification. If None, then we're supposed to return an empty string.
- // If Create, we're supposed to create it and then return the path.
- if (option == SpecialFolderOption.None)
- {
- return string.Empty;
- }
- else
- {
- Debug.Assert(option == SpecialFolderOption.Create);
-
- // TODO #11151: Replace with Directory.CreateDirectory once we have access to System.IO.FileSystem here.
- Func<string, object> createDirectory = LazyInitializer.EnsureInitialized(ref s_directoryCreateDirectory, () =>
- {
- Type dirType = Type.GetType("System.IO.Directory, System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: true)!;
- MethodInfo mi = dirType.GetTypeInfo().GetDeclaredMethod("CreateDirectory")!;
- return (Func<string, object>)mi.CreateDelegate(typeof(Func<string, object>));
- });
- createDirectory(path);
-
- return path;
- }
- }
-
- private static string GetFolderPathCoreWithoutValidation(SpecialFolder folder)
- {
- // First handle any paths that involve only static paths, avoiding the overheads of getting user-local paths.
- // https://www.freedesktop.org/software/systemd/man/file-hierarchy.html
- switch (folder)
- {
- case SpecialFolder.CommonApplicationData: return "/usr/share";
- case SpecialFolder.CommonTemplates: return "/usr/share/templates";
-#if PLATFORM_OSX
- case SpecialFolder.ProgramFiles: return "/Applications";
- case SpecialFolder.System: return "/System";
-#endif
- }
-
- // All other paths are based on the XDG Base Directory Specification:
- // https://specifications.freedesktop.org/basedir-spec/latest/
- string? home = null;
- try
- {
- home = PersistedFiles.GetHomeDirectory();
- }
- catch (Exception exc)
- {
- Debug.Fail($"Unable to get home directory: {exc}");
- }
-
- // Fall back to '/' when we can't determine the home directory.
- // This location isn't writable by non-root users which provides some safeguard
- // that the application doesn't write data which is meant to be private.
- if (string.IsNullOrEmpty(home))
- {
- home = "/";
- }
-
- // TODO: Consider caching (or precomputing and caching) all subsequent results.
- // This would significantly improve performance for repeated access, at the expense
- // of not being responsive to changes in the underlying environment variables,
- // configuration files, etc.
-
- switch (folder)
- {
- case SpecialFolder.UserProfile:
- case SpecialFolder.MyDocuments: // same value as Personal
- return home;
- case SpecialFolder.ApplicationData:
- return GetXdgConfig(home);
- case SpecialFolder.LocalApplicationData:
- // "$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored."
- // "If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used."
- string? data = GetEnvironmentVariable("XDG_DATA_HOME");
- if (string.IsNullOrEmpty(data) || data[0] != '/')
- {
- data = Path.Combine(home, ".local", "share");
- }
- return data;
-
- case SpecialFolder.Desktop:
- case SpecialFolder.DesktopDirectory:
- return ReadXdgDirectory(home, "XDG_DESKTOP_DIR", "Desktop");
- case SpecialFolder.Templates:
- return ReadXdgDirectory(home, "XDG_TEMPLATES_DIR", "Templates");
- case SpecialFolder.MyVideos:
- return ReadXdgDirectory(home, "XDG_VIDEOS_DIR", "Videos");
-
-#if PLATFORM_OSX
- case SpecialFolder.MyMusic:
- return Path.Combine(home, "Music");
- case SpecialFolder.MyPictures:
- return Path.Combine(home, "Pictures");
- case SpecialFolder.Fonts:
- return Path.Combine(home, "Library", "Fonts");
- case SpecialFolder.Favorites:
- return Path.Combine(home, "Library", "Favorites");
- case SpecialFolder.InternetCache:
- return Path.Combine(home, "Library", "Caches");
-#else
- case SpecialFolder.MyMusic:
- return ReadXdgDirectory(home, "XDG_MUSIC_DIR", "Music");
- case SpecialFolder.MyPictures:
- return ReadXdgDirectory(home, "XDG_PICTURES_DIR", "Pictures");
- case SpecialFolder.Fonts:
- return Path.Combine(home, ".fonts");
-#endif
- }
-
- // No known path for the SpecialFolder
- return string.Empty;
- }
-
- private static string GetXdgConfig(string home)
- {
- // "$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored."
- // "If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used."
- string? config = GetEnvironmentVariable("XDG_CONFIG_HOME");
- if (string.IsNullOrEmpty(config) || config[0] != '/')
- {
- config = Path.Combine(home, ".config");
- }
- return config;
- }
-
- private static string ReadXdgDirectory(string homeDir, string key, string fallback)
- {
- Debug.Assert(!string.IsNullOrEmpty(homeDir), $"Expected non-empty homeDir");
- Debug.Assert(!string.IsNullOrEmpty(key), $"Expected non-empty key");
- Debug.Assert(!string.IsNullOrEmpty(fallback), $"Expected non-empty fallback");
-
- string? envPath = GetEnvironmentVariable(key);
- if (!string.IsNullOrEmpty(envPath) && envPath[0] == '/')
- {
- return envPath;
- }
-
- // Use the user-dirs.dirs file to look up the right config.
- // Note that the docs also highlight a list of directories in which to look for this file:
- // "$XDG_CONFIG_DIRS defines the preference-ordered set of base directories to search for configuration files in addition
- // to the $XDG_CONFIG_HOME base directory. The directories in $XDG_CONFIG_DIRS should be separated with a colon ':'. If
- // $XDG_CONFIG_DIRS is either not set or empty, a value equal to / etc / xdg should be used."
- // For simplicity, we don't currently do that. We can add it if/when necessary.
-
- string userDirsPath = Path.Combine(GetXdgConfig(homeDir), "user-dirs.dirs");
- if (Interop.Sys.Access(userDirsPath, Interop.Sys.AccessMode.R_OK) == 0)
- {
- try
- {
- using (var reader = new StreamReader(userDirsPath))
- {
- string? line;
- while ((line = reader.ReadLine()) != null)
- {
- // Example lines:
- // XDG_DESKTOP_DIR="$HOME/Desktop"
- // XDG_PICTURES_DIR = "/absolute/path"
-
- // Skip past whitespace at beginning of line
- int pos = 0;
- SkipWhitespace(line, ref pos);
- if (pos >= line.Length) continue;
-
- // Skip past requested key name
- if (string.CompareOrdinal(line, pos, key, 0, key.Length) != 0) continue;
- pos += key.Length;
-
- // Skip past whitespace and past '='
- SkipWhitespace(line, ref pos);
- if (pos >= line.Length - 4 || line[pos] != '=') continue; // 4 for ="" and at least one char between quotes
- pos++; // skip past '='
-
- // Skip past whitespace and past first quote
- SkipWhitespace(line, ref pos);
- if (pos >= line.Length - 3 || line[pos] != '"') continue; // 3 for "" and at least one char between quotes
- pos++; // skip past opening '"'
-
- // Skip past relative prefix if one exists
- bool relativeToHome = false;
- const string RelativeToHomePrefix = "$HOME/";
- if (string.CompareOrdinal(line, pos, RelativeToHomePrefix, 0, RelativeToHomePrefix.Length) == 0)
- {
- relativeToHome = true;
- pos += RelativeToHomePrefix.Length;
- }
- else if (line[pos] != '/') // if not relative to home, must be absolute path
- {
- continue;
- }
-
- // Find end of path
- int endPos = line.IndexOf('"', pos);
- if (endPos <= pos) continue;
-
- // Got we need. Now extract it.
- string path = line.Substring(pos, endPos - pos);
- return relativeToHome ?
- Path.Combine(homeDir, path) :
- path;
- }
- }
- }
- catch (Exception exc)
- {
- // assembly not found, file not found, errors reading file, etc. Just eat everything.
- Debug.Fail($"Failed reading {userDirsPath}: {exc}");
- }
- }
-
- return Path.Combine(homeDir, fallback);
- }
-
- private static void SkipWhitespace(string line, ref int pos)
- {
- while (pos < line.Length && char.IsWhiteSpace(line[pos])) pos++;
- }
-
- public static string[] GetLogicalDrives() => Interop.Sys.GetAllMountPoints();
-
- private static bool Is64BitOperatingSystemWhen32BitProcess => false;
-
- public static string MachineName
- {
- get
- {
- string hostName = Interop.Sys.GetHostName();
- int dotPos = hostName.IndexOf('.');
- return dotPos == -1 ? hostName : hostName.Substring(0, dotPos);
- }
- }
-
- internal const string NewLineConst = "\n";
-
- private static OperatingSystem GetOSVersion() => GetOperatingSystem(Interop.Sys.GetUnixRelease());
-
- // Tests exercise this method for corner cases via private reflection
- private static OperatingSystem GetOperatingSystem(string release)
- {
- int major = 0, minor = 0, build = 0, revision = 0;
-
- // Parse the uname's utsname.release for the first four numbers found.
- // This isn't perfect, but Version already doesn't map exactly to all possible release
- // formats, e.g. 2.6.19-1.2895.fc6
- if (release != null)
- {
- int i = 0;
- major = FindAndParseNextNumber(release, ref i);
- minor = FindAndParseNextNumber(release, ref i);
- build = FindAndParseNextNumber(release, ref i);
- revision = FindAndParseNextNumber(release, ref i);
- }
-
- // For compatibility reasons with Mono, PlatformID.Unix is returned on MacOSX. PlatformID.MacOSX
- // is hidden from the editor and shouldn't be used.
- return new OperatingSystem(PlatformID.Unix, new Version(major, minor, build, revision));
- }
-
- private static int FindAndParseNextNumber(string text, ref int pos)
- {
- // Move to the beginning of the number
- for (; pos < text.Length; pos++)
- {
- char c = text[pos];
- if ('0' <= c && c <= '9')
- {
- break;
- }
- }
-
- // Parse the number;
- int num = 0;
- for (; pos < text.Length; pos++)
- {
- char c = text[pos];
- if ('0' > c || c > '9')
- break;
-
- try
- {
- num = checked((num * 10) + (c - '0'));
- }
- // Integer overflow can occur for example with:
- // Linux nelknet 4.15.0-24201807041620-generic
- // To form a valid Version, num must be positive.
- catch (OverflowException)
- {
- return int.MaxValue;
- }
- }
-
- return num;
- }
-
- public static string SystemDirectory => GetFolderPathCore(SpecialFolder.System, SpecialFolderOption.None);
-
- public static int SystemPageSize => CheckedSysConf(Interop.Sys.SysConfName._SC_PAGESIZE);
-
- public static unsafe string UserName
- {
- get
- {
- // First try with a buffer that should suffice for 99% of cases.
- string? username;
- const int BufLen = Interop.Sys.Passwd.InitialBufferSize;
- byte* stackBuf = stackalloc byte[BufLen];
- if (TryGetUserNameFromPasswd(stackBuf, BufLen, out username))
- {
- return username ?? string.Empty;
- }
-
- // Fallback to heap allocations if necessary, growing the buffer until
- // we succeed. TryGetUserNameFromPasswd will throw if there's an unexpected error.
- int lastBufLen = BufLen;
- while (true)
- {
- lastBufLen *= 2;
- byte[] heapBuf = new byte[lastBufLen];
- fixed (byte* buf = &heapBuf[0])
- {
- if (TryGetUserNameFromPasswd(buf, heapBuf.Length, out username))
- {
- return username ?? string.Empty;
- }
- }
- }
-
- }
- }
-
- private static unsafe bool TryGetUserNameFromPasswd(byte* buf, int bufLen, out string? username)
- {
- // Call getpwuid_r to get the passwd struct
- Interop.Sys.Passwd passwd;
- int error = Interop.Sys.GetPwUidR(Interop.Sys.GetEUid(), out passwd, buf, bufLen);
-
- // If the call succeeds, give back the user name retrieved
- if (error == 0)
- {
- Debug.Assert(passwd.Name != null);
- username = Marshal.PtrToStringAnsi((IntPtr)passwd.Name);
- return true;
- }
-
- // If the current user's entry could not be found, give back null,
- // but still return true (false indicates the buffer was too small).
- if (error == -1)
- {
- username = null;
- return true;
- }
-
- var errorInfo = new Interop.ErrorInfo(error);
-
- // If the call failed because the buffer was too small, return false to
- // indicate the caller should try again with a larger buffer.
- if (errorInfo.Error == Interop.Error.ERANGE)
- {
- username = null;
- return false;
- }
-
- // Otherwise, fail.
- throw new IOException(errorInfo.GetErrorMessage(), errorInfo.RawErrno);
- }
-
- public static string UserDomainName => MachineName;
-
- /// <summary>Invoke <see cref="Interop.Sys.SysConf"/>, throwing if it fails.</summary>
- private static int CheckedSysConf(Interop.Sys.SysConfName name)
- {
- long result = Interop.Sys.SysConf(name);
- if (result == -1)
- {
- Interop.ErrorInfo errno = Interop.Sys.GetLastErrorInfo();
- throw errno.Error == Interop.Error.EINVAL ?
- new ArgumentOutOfRangeException(nameof(name), name, errno.GetErrorMessage()) :
- Interop.GetIOException(errno);
- }
- return (int)result;
- }
-
- public static long WorkingSet
- {
- get
- {
- Type? processType = Type.GetType("System.Diagnostics.Process, System.Diagnostics.Process, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: false);
- if (processType?.GetMethod("GetCurrentProcess")?.Invoke(null, BindingFlags.DoNotWrapExceptions, null, null, null) is IDisposable currentProcess)
- {
- using (currentProcess)
- {
- object? result = processType!.GetMethod("get_WorkingSet64")?.Invoke(currentProcess, BindingFlags.DoNotWrapExceptions, null, null, null);
- if (result is long) return (long)result;
- }
- }
-
- // Could not get the current working set.
- return 0;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Environment.Variables.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Environment.Variables.Windows.cs
deleted file mode 100644
index 4847698d618..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Environment.Variables.Windows.cs
+++ /dev/null
@@ -1,166 +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 System.Buffers;
-using System.Collections;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System
-{
- public static partial class Environment
- {
- private static string? GetEnvironmentVariableCore(string variable)
- {
- Span<char> buffer = stackalloc char[128]; // a somewhat reasonable default size
- int requiredSize = Interop.Kernel32.GetEnvironmentVariable(variable, buffer);
-
- if (requiredSize == 0 && Marshal.GetLastWin32Error() == Interop.Errors.ERROR_ENVVAR_NOT_FOUND)
- {
- return null;
- }
-
- if (requiredSize <= buffer.Length)
- {
- return new string(buffer.Slice(0, requiredSize));
- }
-
- char[] chars = ArrayPool<char>.Shared.Rent(requiredSize);
- try
- {
- buffer = chars;
- requiredSize = Interop.Kernel32.GetEnvironmentVariable(variable, buffer);
- if ((requiredSize == 0 && Marshal.GetLastWin32Error() == Interop.Errors.ERROR_ENVVAR_NOT_FOUND) ||
- requiredSize > buffer.Length)
- {
- return null;
- }
-
- return new string(buffer.Slice(0, requiredSize));
- }
- finally
- {
- ArrayPool<char>.Shared.Return(chars);
- }
- }
-
- private static void SetEnvironmentVariableCore(string variable, string? value)
- {
- if (!Interop.Kernel32.SetEnvironmentVariable(variable, value))
- {
- int errorCode = Marshal.GetLastWin32Error();
- switch (errorCode)
- {
- case Interop.Errors.ERROR_ENVVAR_NOT_FOUND:
- // Allow user to try to clear a environment variable
- return;
-
- case Interop.Errors.ERROR_FILENAME_EXCED_RANGE:
- // The error message from Win32 is "The filename or extension is too long",
- // which is not accurate.
- throw new ArgumentException(SR.Argument_LongEnvVarValue);
-
- case Interop.Errors.ERROR_NOT_ENOUGH_MEMORY:
- case Interop.Errors.ERROR_NO_SYSTEM_RESOURCES:
- throw new OutOfMemoryException(Interop.Kernel32.GetMessage(errorCode));
-
- default:
- throw new ArgumentException(Interop.Kernel32.GetMessage(errorCode));
- }
- }
- }
-
- public static unsafe IDictionary GetEnvironmentVariables()
- {
- char* pStrings = Interop.Kernel32.GetEnvironmentStrings();
- if (pStrings == null)
- {
- throw new OutOfMemoryException();
- }
-
- try
- {
- // Format for GetEnvironmentStrings is:
- // [=HiddenVar=value\0]* [Variable=value\0]* \0
- // See the description of Environment Blocks in MSDN's
- // CreateProcess page (null-terminated array of null-terminated strings).
-
- // Search for terminating \0\0 (two unicode \0's).
- char* p = pStrings;
- while (!(*p == '\0' && *(p + 1) == '\0'))
- {
- p++;
- }
- Span<char> block = new Span<char>(pStrings, (int)(p - pStrings + 1));
-
- // Format for GetEnvironmentStrings is:
- // (=HiddenVar=value\0 | Variable=value\0)* \0
- // See the description of Environment Blocks in MSDN's
- // CreateProcess page (null-terminated array of null-terminated strings).
- // Note the =HiddenVar's aren't always at the beginning.
-
- // Copy strings out, parsing into pairs and inserting into the table.
- // The first few environment variable entries start with an '='.
- // The current working directory of every drive (except for those drives
- // you haven't cd'ed into in your DOS window) are stored in the
- // environment block (as =C:=pwd) and the program's exit code is
- // as well (=ExitCode=00000000).
-
- var results = new Hashtable();
- for (int i = 0; i < block.Length; i++)
- {
- int startKey = i;
-
- // Skip to key. On some old OS, the environment block can be corrupted.
- // Some will not have '=', so we need to check for '\0'.
- while (block[i] != '=' && block[i] != '\0')
- {
- i++;
- }
-
- if (block[i] == '\0')
- {
- continue;
- }
-
- // Skip over environment variables starting with '='
- if (i - startKey == 0)
- {
- while (block[i] != 0)
- {
- i++;
- }
-
- continue;
- }
-
- string key = new string(block.Slice(startKey, i - startKey));
- i++; // skip over '='
-
- int startValue = i;
- while (block[i] != 0)
- {
- i++; // Read to end of this entry
- }
-
- string value = new string(block.Slice(startValue, i - startValue)); // skip over 0 handled by for loop's i++
- try
- {
- results.Add(key, value);
- }
- catch (ArgumentException)
- {
- // Throw and catch intentionally to provide non-fatal notification about corrupted environment block
- }
- }
- return results;
- }
- finally
- {
- bool success = Interop.Kernel32.FreeEnvironmentStrings(pStrings);
- Debug.Assert(success);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Environment.Win32.cs b/netcore/System.Private.CoreLib/shared/System/Environment.Win32.cs
deleted file mode 100644
index 8f453c5a8a4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Environment.Win32.cs
+++ /dev/null
@@ -1,455 +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 System.Collections;
-using System.Diagnostics;
-using System.IO;
-using System.Reflection;
-using System.Runtime.InteropServices;
-using System.Text;
-using Internal.Win32;
-
-namespace System
-{
- public static partial class Environment
- {
- internal static bool IsWindows8OrAbove => WindowsVersion.IsWindows8OrAbove;
-
- private static string? GetEnvironmentVariableFromRegistry(string variable, bool fromMachine)
- {
- Debug.Assert(variable != null);
-
-#if FEATURE_APPX
- if (ApplicationModel.IsUap)
- return null; // Systems without the Windows registry pretend that it's always empty.
-#endif
-
- using (RegistryKey? environmentKey = OpenEnvironmentKeyIfExists(fromMachine, writable: false))
- {
- return environmentKey?.GetValue(variable) as string;
- }
- }
-
- private static void SetEnvironmentVariableFromRegistry(string variable, string? value, bool fromMachine)
- {
- Debug.Assert(variable != null);
-
-#if FEATURE_APPX
- if (ApplicationModel.IsUap)
- return; // Systems without the Windows registry pretend that it's always empty.
-#endif
-
- const int MaxUserEnvVariableLength = 255; // User-wide env vars stored in the registry have names limited to 255 chars
- if (!fromMachine && variable.Length >= MaxUserEnvVariableLength)
- {
- throw new ArgumentException(SR.Argument_LongEnvVarValue, nameof(variable));
- }
-
- using (RegistryKey? environmentKey = OpenEnvironmentKeyIfExists(fromMachine, writable: true))
- {
- if (environmentKey != null)
- {
- if (value == null)
- {
- environmentKey.DeleteValue(variable, throwOnMissingValue: false);
- }
- else
- {
- environmentKey.SetValue(variable, value);
- }
- }
- }
-
- // send a WM_SETTINGCHANGE message to all windows
- IntPtr r = Interop.User32.SendMessageTimeout(new IntPtr(Interop.User32.HWND_BROADCAST), Interop.User32.WM_SETTINGCHANGE, IntPtr.Zero, "Environment", 0, 1000, IntPtr.Zero);
- Debug.Assert(r != IntPtr.Zero, "SetEnvironmentVariable failed: " + Marshal.GetLastWin32Error());
- }
-
- private static IDictionary GetEnvironmentVariablesFromRegistry(bool fromMachine)
- {
- var results = new Hashtable();
-#if FEATURE_APPX
- if (ApplicationModel.IsUap) // Systems without the Windows registry pretend that it's always empty.
- return results;
-#endif
-
- using (RegistryKey? environmentKey = OpenEnvironmentKeyIfExists(fromMachine, writable: false))
- {
- if (environmentKey != null)
- {
- foreach (string name in environmentKey.GetValueNames())
- {
- string? value = environmentKey.GetValue(name, "").ToString();
- try
- {
- results.Add(name, value);
- }
- catch (ArgumentException)
- {
- // Throw and catch intentionally to provide non-fatal notification about corrupted environment block
- }
- }
- }
- }
-
- return results;
- }
-
- private static RegistryKey? OpenEnvironmentKeyIfExists(bool fromMachine, bool writable)
- {
- RegistryKey baseKey;
- string keyName;
-
- if (fromMachine)
- {
- baseKey = Registry.LocalMachine;
- keyName = @"System\CurrentControlSet\Control\Session Manager\Environment";
- }
- else
- {
- baseKey = Registry.CurrentUser;
- keyName = "Environment";
- }
-
- return baseKey.OpenSubKey(keyName, writable: writable);
- }
-
- public static string UserName
- {
- get
- {
-#if FEATURE_APPX
- if (ApplicationModel.IsUap)
- return "Windows User";
-#endif
-
- // 40 should be enough as we're asking for the SAM compatible name (DOMAIN\User).
- // The max length should be 15 (domain) + 1 (separator) + 20 (name) + null. If for
- // some reason it isn't, we'll grow the buffer.
-
- // https://support.microsoft.com/en-us/help/909264/naming-conventions-in-active-directory-for-computers-domains-sites-and
- // https://msdn.microsoft.com/en-us/library/ms679635.aspx
-
- var builder = new ValueStringBuilder(stackalloc char[40]);
- GetUserName(ref builder);
-
- ReadOnlySpan<char> name = builder.AsSpan();
- int index = name.IndexOf('\\');
- if (index != -1)
- {
- // In the form of DOMAIN\User, cut off DOMAIN\
- name = name.Slice(index + 1);
- }
-
- string result = name.ToString();
- builder.Dispose();
- return result;
- }
- }
-
- private static void GetUserName(ref ValueStringBuilder builder)
- {
- uint size = 0;
- while (Interop.Secur32.GetUserNameExW(Interop.Secur32.NameSamCompatible, ref builder.GetPinnableReference(), ref size) == Interop.BOOLEAN.FALSE)
- {
- if (Marshal.GetLastWin32Error() == Interop.Errors.ERROR_MORE_DATA)
- {
- builder.EnsureCapacity(checked((int)size));
- }
- else
- {
- builder.Length = 0;
- return;
- }
- }
-
- builder.Length = (int)size;
- }
-
- public static string UserDomainName
- {
- get
- {
-#if FEATURE_APPX
- if (ApplicationModel.IsUap)
- return "Windows Domain";
-#endif
-
- // See the comment in UserName
- var builder = new ValueStringBuilder(stackalloc char[40]);
- GetUserName(ref builder);
-
- ReadOnlySpan<char> name = builder.AsSpan();
- int index = name.IndexOf('\\');
- if (index != -1)
- {
- // In the form of DOMAIN\User, cut off \User and return
- builder.Length = index;
- return builder.ToString();
- }
-
- // In theory we should never get use out of LookupAccountNameW as the above API should
- // always return what we need. Can't find any clues in the historical sources, however.
-
- // Domain names aren't typically long.
- // https://support.microsoft.com/en-us/help/909264/naming-conventions-in-active-directory-for-computers-domains-sites-and
- var domainBuilder = new ValueStringBuilder(stackalloc char[64]);
- uint length = (uint)domainBuilder.Capacity;
-
- // This API will fail to return the domain name without a buffer for the SID.
- // SIDs are never over 68 bytes long.
- Span<byte> sid = stackalloc byte[68];
- uint sidLength = 68;
-
- while (!Interop.Advapi32.LookupAccountNameW(null, ref builder.GetPinnableReference(), ref MemoryMarshal.GetReference(sid),
- ref sidLength, ref domainBuilder.GetPinnableReference(), ref length, out _))
- {
- int error = Marshal.GetLastWin32Error();
-
- // The docs don't call this out clearly, but experimenting shows that the error returned is the following.
- if (error != Interop.Errors.ERROR_INSUFFICIENT_BUFFER)
- {
- throw new InvalidOperationException(Win32Marshal.GetMessage(error));
- }
-
- domainBuilder.EnsureCapacity((int)length);
- }
-
- builder.Dispose();
- domainBuilder.Length = (int)length;
- return domainBuilder.ToString();
- }
- }
-
- private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
- {
-#if FEATURE_APPX
- if (ApplicationModel.IsUap)
- return WinRTFolderPaths.GetFolderPath(folder, option);
-#endif
-
- // We're using SHGetKnownFolderPath instead of SHGetFolderPath as SHGetFolderPath is
- // capped at MAX_PATH.
- //
- // Because we validate both of the input enums we shouldn't have to care about CSIDL and flag
- // definitions we haven't mapped. If we remove or loosen the checks we'd have to account
- // for mapping here (this includes tweaking as SHGetFolderPath would do).
- //
- // The only SpecialFolderOption defines we have are equivalent to KnownFolderFlags.
-
- string folderGuid;
-
- switch (folder)
- {
- case SpecialFolder.ApplicationData:
- folderGuid = Interop.Shell32.KnownFolders.RoamingAppData;
- break;
- case SpecialFolder.CommonApplicationData:
- folderGuid = Interop.Shell32.KnownFolders.ProgramData;
- break;
- case SpecialFolder.LocalApplicationData:
- folderGuid = Interop.Shell32.KnownFolders.LocalAppData;
- break;
- case SpecialFolder.Cookies:
- folderGuid = Interop.Shell32.KnownFolders.Cookies;
- break;
- case SpecialFolder.Desktop:
- folderGuid = Interop.Shell32.KnownFolders.Desktop;
- break;
- case SpecialFolder.Favorites:
- folderGuid = Interop.Shell32.KnownFolders.Favorites;
- break;
- case SpecialFolder.History:
- folderGuid = Interop.Shell32.KnownFolders.History;
- break;
- case SpecialFolder.InternetCache:
- folderGuid = Interop.Shell32.KnownFolders.InternetCache;
- break;
- case SpecialFolder.Programs:
- folderGuid = Interop.Shell32.KnownFolders.Programs;
- break;
- case SpecialFolder.MyComputer:
- folderGuid = Interop.Shell32.KnownFolders.ComputerFolder;
- break;
- case SpecialFolder.MyMusic:
- folderGuid = Interop.Shell32.KnownFolders.Music;
- break;
- case SpecialFolder.MyPictures:
- folderGuid = Interop.Shell32.KnownFolders.Pictures;
- break;
- case SpecialFolder.MyVideos:
- folderGuid = Interop.Shell32.KnownFolders.Videos;
- break;
- case SpecialFolder.Recent:
- folderGuid = Interop.Shell32.KnownFolders.Recent;
- break;
- case SpecialFolder.SendTo:
- folderGuid = Interop.Shell32.KnownFolders.SendTo;
- break;
- case SpecialFolder.StartMenu:
- folderGuid = Interop.Shell32.KnownFolders.StartMenu;
- break;
- case SpecialFolder.Startup:
- folderGuid = Interop.Shell32.KnownFolders.Startup;
- break;
- case SpecialFolder.System:
- folderGuid = Interop.Shell32.KnownFolders.System;
- break;
- case SpecialFolder.Templates:
- folderGuid = Interop.Shell32.KnownFolders.Templates;
- break;
- case SpecialFolder.DesktopDirectory:
- folderGuid = Interop.Shell32.KnownFolders.Desktop;
- break;
- case SpecialFolder.Personal:
- // Same as Personal
- // case SpecialFolder.MyDocuments:
- folderGuid = Interop.Shell32.KnownFolders.Documents;
- break;
- case SpecialFolder.ProgramFiles:
- folderGuid = Interop.Shell32.KnownFolders.ProgramFiles;
- break;
- case SpecialFolder.CommonProgramFiles:
- folderGuid = Interop.Shell32.KnownFolders.ProgramFilesCommon;
- break;
- case SpecialFolder.AdminTools:
- folderGuid = Interop.Shell32.KnownFolders.AdminTools;
- break;
- case SpecialFolder.CDBurning:
- folderGuid = Interop.Shell32.KnownFolders.CDBurning;
- break;
- case SpecialFolder.CommonAdminTools:
- folderGuid = Interop.Shell32.KnownFolders.CommonAdminTools;
- break;
- case SpecialFolder.CommonDocuments:
- folderGuid = Interop.Shell32.KnownFolders.PublicDocuments;
- break;
- case SpecialFolder.CommonMusic:
- folderGuid = Interop.Shell32.KnownFolders.PublicMusic;
- break;
- case SpecialFolder.CommonOemLinks:
- folderGuid = Interop.Shell32.KnownFolders.CommonOEMLinks;
- break;
- case SpecialFolder.CommonPictures:
- folderGuid = Interop.Shell32.KnownFolders.PublicPictures;
- break;
- case SpecialFolder.CommonStartMenu:
- folderGuid = Interop.Shell32.KnownFolders.CommonStartMenu;
- break;
- case SpecialFolder.CommonPrograms:
- folderGuid = Interop.Shell32.KnownFolders.CommonPrograms;
- break;
- case SpecialFolder.CommonStartup:
- folderGuid = Interop.Shell32.KnownFolders.CommonStartup;
- break;
- case SpecialFolder.CommonDesktopDirectory:
- folderGuid = Interop.Shell32.KnownFolders.PublicDesktop;
- break;
- case SpecialFolder.CommonTemplates:
- folderGuid = Interop.Shell32.KnownFolders.CommonTemplates;
- break;
- case SpecialFolder.CommonVideos:
- folderGuid = Interop.Shell32.KnownFolders.PublicVideos;
- break;
- case SpecialFolder.Fonts:
- folderGuid = Interop.Shell32.KnownFolders.Fonts;
- break;
- case SpecialFolder.NetworkShortcuts:
- folderGuid = Interop.Shell32.KnownFolders.NetHood;
- break;
- case SpecialFolder.PrinterShortcuts:
- folderGuid = Interop.Shell32.KnownFolders.PrintersFolder;
- break;
- case SpecialFolder.UserProfile:
- folderGuid = Interop.Shell32.KnownFolders.Profile;
- break;
- case SpecialFolder.CommonProgramFilesX86:
- folderGuid = Interop.Shell32.KnownFolders.ProgramFilesCommonX86;
- break;
- case SpecialFolder.ProgramFilesX86:
- folderGuid = Interop.Shell32.KnownFolders.ProgramFilesX86;
- break;
- case SpecialFolder.Resources:
- folderGuid = Interop.Shell32.KnownFolders.ResourceDir;
- break;
- case SpecialFolder.LocalizedResources:
- folderGuid = Interop.Shell32.KnownFolders.LocalizedResourcesDir;
- break;
- case SpecialFolder.SystemX86:
- folderGuid = Interop.Shell32.KnownFolders.SystemX86;
- break;
- case SpecialFolder.Windows:
- folderGuid = Interop.Shell32.KnownFolders.Windows;
- break;
- default:
- return string.Empty;
- }
-
- return GetKnownFolderPath(folderGuid, option);
- }
-
- private static string GetKnownFolderPath(string folderGuid, SpecialFolderOption option)
- {
- Guid folderId = new Guid(folderGuid);
-
- int hr = Interop.Shell32.SHGetKnownFolderPath(folderId, (uint)option, IntPtr.Zero, out string path);
- if (hr != 0) // Not S_OK
- {
- return string.Empty;
- }
-
- return path;
- }
-
-#if FEATURE_APPX
- private static class WinRTFolderPaths
- {
- private static Func<SpecialFolder, SpecialFolderOption, string>? s_winRTFolderPathsGetFolderPath;
-
- public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
- {
- if (s_winRTFolderPathsGetFolderPath == null)
- {
- Type? winRtFolderPathsType = Type.GetType("System.WinRTFolderPaths, System.Runtime.WindowsRuntime, Version=4.0.14.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", throwOnError: false);
- MethodInfo? getFolderPathsMethod = winRtFolderPathsType?.GetMethod("GetFolderPath", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(SpecialFolder), typeof(SpecialFolderOption) }, null);
- var d = (Func<SpecialFolder, SpecialFolderOption, string>?)getFolderPathsMethod?.CreateDelegate(typeof(Func<SpecialFolder, SpecialFolderOption, string>));
- s_winRTFolderPathsGetFolderPath = d ?? delegate { return string.Empty; };
- }
-
- return s_winRTFolderPathsGetFolderPath(folder, option);
- }
- }
-#endif
-
- // Seperate type so a .cctor is not created for Enviroment which then would be triggered during startup
- private static class WindowsVersion
- {
- // Cache the value in static readonly that can be optimized out by the JIT
- internal static readonly bool IsWindows8OrAbove = GetIsWindows8OrAbove();
-
- private static bool GetIsWindows8OrAbove()
- {
- ulong conditionMask = Interop.Kernel32.VerSetConditionMask(0, Interop.Kernel32.VER_MAJORVERSION, Interop.Kernel32.VER_GREATER_EQUAL);
- conditionMask = Interop.Kernel32.VerSetConditionMask(conditionMask, Interop.Kernel32.VER_MINORVERSION, Interop.Kernel32.VER_GREATER_EQUAL);
- conditionMask = Interop.Kernel32.VerSetConditionMask(conditionMask, Interop.Kernel32.VER_SERVICEPACKMAJOR, Interop.Kernel32.VER_GREATER_EQUAL);
- conditionMask = Interop.Kernel32.VerSetConditionMask(conditionMask, Interop.Kernel32.VER_SERVICEPACKMINOR, Interop.Kernel32.VER_GREATER_EQUAL);
-
- // Windows 8 version is 6.2
- Interop.Kernel32.OSVERSIONINFOEX version = default;
- unsafe
- {
- version.dwOSVersionInfoSize = sizeof(Interop.Kernel32.OSVERSIONINFOEX);
- }
- version.dwMajorVersion = 6;
- version.dwMinorVersion = 2;
- version.wServicePackMajor = 0;
- version.wServicePackMinor = 0;
-
- return Interop.Kernel32.VerifyVersionInfoW(ref version,
- Interop.Kernel32.VER_MAJORVERSION | Interop.Kernel32.VER_MINORVERSION | Interop.Kernel32.VER_SERVICEPACKMAJOR | Interop.Kernel32.VER_SERVICEPACKMINOR,
- conditionMask);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Environment.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Environment.Windows.cs
deleted file mode 100644
index 17a49080d66..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Environment.Windows.cs
+++ /dev/null
@@ -1,140 +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 System.IO;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System
-{
- public static partial class Environment
- {
- private static string CurrentDirectoryCore
- {
- get
- {
- var builder = new ValueStringBuilder(stackalloc char[Interop.Kernel32.MAX_PATH]);
-
- uint length;
- while ((length = Interop.Kernel32.GetCurrentDirectory((uint)builder.Capacity, ref builder.GetPinnableReference())) > builder.Capacity)
- {
- builder.EnsureCapacity((int)length);
- }
-
- if (length == 0)
- throw Win32Marshal.GetExceptionForLastWin32Error();
-
- builder.Length = (int)length;
-
- // If we have a tilde in the path, make an attempt to expand 8.3 filenames
- if (builder.AsSpan().Contains('~'))
- {
- string result = PathHelper.TryExpandShortFileName(ref builder, null);
- builder.Dispose();
- return result;
- }
-
- return builder.ToString();
- }
- set
- {
- if (!Interop.Kernel32.SetCurrentDirectory(value))
- {
- int errorCode = Marshal.GetLastWin32Error();
- throw Win32Marshal.GetExceptionForWin32Error(
- errorCode == Interop.Errors.ERROR_FILE_NOT_FOUND ? Interop.Errors.ERROR_PATH_NOT_FOUND : errorCode,
- value);
- }
- }
- }
-
- public static string[] GetLogicalDrives() => DriveInfoInternal.GetLogicalDrives();
-
- internal const string NewLineConst = "\r\n";
-
- public static int SystemPageSize
- {
- get
- {
- Interop.Kernel32.GetSystemInfo(out Interop.Kernel32.SYSTEM_INFO info);
- return info.dwPageSize;
- }
- }
-
- private static string ExpandEnvironmentVariablesCore(string name)
- {
- var builder = new ValueStringBuilder(stackalloc char[128]);
-
- uint length;
- while ((length = Interop.Kernel32.ExpandEnvironmentStrings(name, ref builder.GetPinnableReference(), (uint)builder.Capacity)) > builder.Capacity)
- {
- builder.EnsureCapacity((int)length);
- }
-
- if (length == 0)
- Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
-
- // length includes the null terminator
- builder.Length = (int)length - 1;
- return builder.ToString();
- }
-
- private static bool Is64BitOperatingSystemWhen32BitProcess =>
- Interop.Kernel32.IsWow64Process(Interop.Kernel32.GetCurrentProcess(), out bool isWow64) && isWow64;
-
- public static string MachineName =>
- Interop.Kernel32.GetComputerName() ??
- throw new InvalidOperationException(SR.InvalidOperation_ComputerName);
-
- private static unsafe OperatingSystem GetOSVersion()
- {
- var version = new Interop.Kernel32.OSVERSIONINFOEX { dwOSVersionInfoSize = sizeof(Interop.Kernel32.OSVERSIONINFOEX) };
- if (!Interop.Kernel32.GetVersionExW(ref version))
- {
- throw new InvalidOperationException(SR.InvalidOperation_GetVersion);
- }
-
- return new OperatingSystem(
- PlatformID.Win32NT,
- new Version(version.dwMajorVersion, version.dwMinorVersion, version.dwBuildNumber, (version.wServicePackMajor << 16) | version.wServicePackMinor),
- Marshal.PtrToStringUni((IntPtr)version.szCSDVersion));
- }
-
- public static string SystemDirectory
- {
- get
- {
- // Normally this will be C:\Windows\System32
- var builder = new ValueStringBuilder(stackalloc char[32]);
-
- uint length;
- while ((length = Interop.Kernel32.GetSystemDirectoryW(ref builder.GetPinnableReference(), (uint)builder.Capacity)) > builder.Capacity)
- {
- builder.EnsureCapacity((int)length);
- }
-
- if (length == 0)
- throw Win32Marshal.GetExceptionForLastWin32Error();
-
- builder.Length = (int)length;
- return builder.ToString();
- }
- }
-
- public static unsafe long WorkingSet
- {
- get
- {
- Interop.Kernel32.PROCESS_MEMORY_COUNTERS memoryCounters = default;
- memoryCounters.cb = (uint)(sizeof(Interop.Kernel32.PROCESS_MEMORY_COUNTERS));
-
- if (!Interop.Kernel32.GetProcessMemoryInfo(Interop.Kernel32.GetCurrentProcess(), ref memoryCounters, memoryCounters.cb))
- {
- return 0;
- }
- return (long)memoryCounters.WorkingSetSize;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Environment.cs b/netcore/System.Private.CoreLib/shared/System/Environment.cs
deleted file mode 100644
index 1454f1d56e4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Environment.cs
+++ /dev/null
@@ -1,198 +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 System.Collections;
-using System.Diagnostics;
-using System.Reflection;
-using System.Threading;
-
-namespace System
-{
- public static partial class Environment
- {
- public static int ProcessorCount { get; } = GetProcessorCount();
-
- /// <summary>
- /// Gets whether the current machine has only a single processor.
- /// </summary>
- internal static bool IsSingleProcessor => ProcessorCount == 1;
-
- // Unconditionally return false since .NET Core does not support object finalization during shutdown.
- public static bool HasShutdownStarted => false;
-
- public static string? GetEnvironmentVariable(string variable)
- {
- if (variable == null)
- throw new ArgumentNullException(nameof(variable));
-
- return GetEnvironmentVariableCore(variable);
- }
-
- public static string? GetEnvironmentVariable(string variable, EnvironmentVariableTarget target)
- {
- if (target == EnvironmentVariableTarget.Process)
- return GetEnvironmentVariable(variable);
-
- if (variable == null)
- throw new ArgumentNullException(nameof(variable));
-
- bool fromMachine = ValidateAndConvertRegistryTarget(target);
- return GetEnvironmentVariableFromRegistry(variable, fromMachine);
- }
-
- public static IDictionary GetEnvironmentVariables(EnvironmentVariableTarget target)
- {
- if (target == EnvironmentVariableTarget.Process)
- return GetEnvironmentVariables();
-
- bool fromMachine = ValidateAndConvertRegistryTarget(target);
- return GetEnvironmentVariablesFromRegistry(fromMachine);
- }
-
- public static void SetEnvironmentVariable(string variable, string? value)
- {
- ValidateVariableAndValue(variable, ref value);
- SetEnvironmentVariableCore(variable, value);
- }
-
- public static void SetEnvironmentVariable(string variable, string? value, EnvironmentVariableTarget target)
- {
- if (target == EnvironmentVariableTarget.Process)
- {
- SetEnvironmentVariable(variable, value);
- return;
- }
-
- ValidateVariableAndValue(variable, ref value);
-
- bool fromMachine = ValidateAndConvertRegistryTarget(target);
- SetEnvironmentVariableFromRegistry(variable, value, fromMachine: fromMachine);
- }
-
- public static string CommandLine => PasteArguments.Paste(GetCommandLineArgs(), pasteFirstArgumentUsingArgV0Rules: true);
-
- public static string CurrentDirectory
- {
- get => CurrentDirectoryCore;
- set
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- if (value.Length == 0)
- throw new ArgumentException(SR.Argument_PathEmpty, nameof(value));
-
- CurrentDirectoryCore = value;
- }
- }
-
- public static string ExpandEnvironmentVariables(string name)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- if (name.Length == 0)
- return name;
-
- return ExpandEnvironmentVariablesCore(name);
- }
-
- private static string[]? s_commandLineArgs;
-
- internal static void SetCommandLineArgs(string[] cmdLineArgs) // invoked from VM
- {
- s_commandLineArgs = cmdLineArgs;
- }
-
- public static string GetFolderPath(SpecialFolder folder) => GetFolderPath(folder, SpecialFolderOption.None);
-
- public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
- {
- if (!Enum.IsDefined(typeof(SpecialFolder), folder))
- throw new ArgumentOutOfRangeException(nameof(folder), folder, SR.Format(SR.Arg_EnumIllegalVal, folder));
-
- if (option != SpecialFolderOption.None && !Enum.IsDefined(typeof(SpecialFolderOption), option))
- throw new ArgumentOutOfRangeException(nameof(option), option, SR.Format(SR.Arg_EnumIllegalVal, option));
-
- return GetFolderPathCore(folder, option);
- }
-
- public static bool Is64BitProcess => IntPtr.Size == 8;
-
- public static bool Is64BitOperatingSystem => Is64BitProcess || Is64BitOperatingSystemWhen32BitProcess;
-
- public static string NewLine => NewLineConst;
-
- private static OperatingSystem? s_osVersion;
-
- public static OperatingSystem OSVersion
- {
- get
- {
- if (s_osVersion == null)
- {
- Interlocked.CompareExchange(ref s_osVersion, GetOSVersion(), null);
- }
- return s_osVersion;
- }
- }
-
- public static bool UserInteractive => true;
-
- public static Version Version
- {
- get
- {
- // FX_PRODUCT_VERSION is expected to be set by the host
- // Use AssemblyInformationalVersionAttribute as fallback if the exact product version is not specified by the host
- string? versionString = (string?)AppContext.GetData("FX_PRODUCT_VERSION") ??
- typeof(object).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
-
- ReadOnlySpan<char> versionSpan = versionString.AsSpan();
-
- // Strip optional suffixes
- int separatorIndex = versionSpan.IndexOfAny("-+ ");
- if (separatorIndex != -1)
- versionSpan = versionSpan.Slice(0, separatorIndex);
-
- // Return zeros rather then failing if the version string fails to parse
- return Version.TryParse(versionSpan, out Version? version) ? version : new Version();
- }
- }
-
- private static bool ValidateAndConvertRegistryTarget(EnvironmentVariableTarget target)
- {
- Debug.Assert(target != EnvironmentVariableTarget.Process);
-
- if (target == EnvironmentVariableTarget.Machine)
- return true;
-
- if (target == EnvironmentVariableTarget.User)
- return false;
-
- throw new ArgumentOutOfRangeException(nameof(target), target, SR.Format(SR.Arg_EnumIllegalVal, target));
- }
-
- private static void ValidateVariableAndValue(string variable, ref string? value)
- {
- if (variable == null)
- throw new ArgumentNullException(nameof(variable));
-
- if (variable.Length == 0)
- throw new ArgumentException(SR.Argument_StringZeroLength, nameof(variable));
-
- if (variable[0] == '\0')
- throw new ArgumentException(SR.Argument_StringFirstCharIsZero, nameof(variable));
-
- if (variable.Contains('='))
- throw new ArgumentException(SR.Argument_IllegalEnvVarName, nameof(variable));
-
- if (string.IsNullOrEmpty(value) || value[0] == '\0')
- {
- // Explicitly null out value if it's empty
- value = null;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/EnvironmentVariableTarget.cs b/netcore/System.Private.CoreLib/shared/System/EnvironmentVariableTarget.cs
deleted file mode 100644
index 42b93215697..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/EnvironmentVariableTarget.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System
-{
- public enum EnvironmentVariableTarget
- {
- Process = 0,
- User = 1,
- Machine = 2,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/EventArgs.cs b/netcore/System.Private.CoreLib/shared/System/EventArgs.cs
deleted file mode 100644
index 0a47428bb5e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/EventArgs.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System
-{
- // The base class for all event classes.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class EventArgs
- {
- public static readonly EventArgs Empty = new EventArgs();
-
- public EventArgs()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/EventHandler.cs b/netcore/System.Private.CoreLib/shared/System/EventHandler.cs
deleted file mode 100644
index 05f53338ebb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/EventHandler.cs
+++ /dev/null
@@ -1,10 +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.
-
-namespace System
-{
- public delegate void EventHandler(object? sender, EventArgs e);
-
- public delegate void EventHandler<TEventArgs>(object? sender, TEventArgs e); // Removed TEventArgs constraint post-.NET 4
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Exception.cs b/netcore/System.Private.CoreLib/shared/System/Exception.cs
deleted file mode 100644
index 2e46fbda4fb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Exception.cs
+++ /dev/null
@@ -1,202 +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 System.Collections;
-using System.Diagnostics;
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public partial class Exception : ISerializable
- {
- private protected const string InnerExceptionPrefix = " ---> ";
-
- public Exception()
- {
- _HResult = HResults.COR_E_EXCEPTION;
- }
-
- public Exception(string? message)
- : this()
- {
- _message = message;
- }
-
- // Creates a new Exception. All derived classes should
- // provide this constructor.
- // Note: the stack trace is not started until the exception
- // is thrown
- //
- public Exception(string? message, Exception? innerException)
- : this()
- {
- _message = message;
- _innerException = innerException;
- }
-
- protected Exception(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- throw new ArgumentNullException(nameof(info));
-
- _message = info.GetString("Message"); // Do not rename (binary serialization)
- _data = (IDictionary?)(info.GetValueNoThrow("Data", typeof(IDictionary))); // Do not rename (binary serialization)
- _innerException = (Exception?)(info.GetValue("InnerException", typeof(Exception))); // Do not rename (binary serialization)
- _helpURL = info.GetString("HelpURL"); // Do not rename (binary serialization)
- _stackTraceString = info.GetString("StackTraceString"); // Do not rename (binary serialization)
- _HResult = info.GetInt32("HResult"); // Do not rename (binary serialization)
- _source = info.GetString("Source"); // Do not rename (binary serialization)
-
- RestoreRemoteStackTrace(info, context);
- }
-
- public virtual string Message => _message ?? SR.Format(SR.Exception_WasThrown, GetClassName());
-
- public virtual IDictionary Data => _data ??= CreateDataContainer();
-
- private string GetClassName() => GetType().ToString();
-
- // Retrieves the lowest exception (inner most) for the given Exception.
- // This will traverse exceptions using the innerException property.
- public virtual Exception GetBaseException()
- {
- Exception? inner = InnerException;
- Exception back = this;
-
- while (inner != null)
- {
- back = inner;
- inner = inner.InnerException;
- }
-
- return back;
- }
-
- public Exception? InnerException => _innerException;
-
- // Sets the help link for this exception.
- // This should be in a URL/URN form, such as:
- // "file:///C:/Applications/Bazzal/help.html#ErrorNum42"
- public virtual string? HelpLink
- {
- get => _helpURL;
- set => _helpURL = value;
- }
-
- public virtual string? Source
- {
- get => _source ??= CreateSourceName();
- set => _source = value;
- }
-
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- if (_source == null)
- {
- _source = Source; // Set the Source information correctly before serialization
- }
-
- info.AddValue("ClassName", GetClassName(), typeof(string)); // Do not rename (binary serialization)
- info.AddValue("Message", _message, typeof(string)); // Do not rename (binary serialization)
- info.AddValue("Data", _data, typeof(IDictionary)); // Do not rename (binary serialization)
- info.AddValue("InnerException", _innerException, typeof(Exception)); // Do not rename (binary serialization)
- info.AddValue("HelpURL", _helpURL, typeof(string)); // Do not rename (binary serialization)
- info.AddValue("StackTraceString", SerializationStackTraceString, typeof(string)); // Do not rename (binary serialization)
- info.AddValue("RemoteStackTraceString", SerializationRemoteStackTraceString, typeof(string)); // Do not rename (binary serialization)
- info.AddValue("RemoteStackIndex", 0, typeof(int)); // Do not rename (binary serialization)
- info.AddValue("ExceptionMethod", null, typeof(string)); // Do not rename (binary serialization)
- info.AddValue("HResult", _HResult); // Do not rename (binary serialization)
- info.AddValue("Source", _source, typeof(string)); // Do not rename (binary serialization)
- info.AddValue("WatsonBuckets", SerializationWatsonBuckets, typeof(byte[])); // Do not rename (binary serialization)
- }
-
- public override string ToString()
- {
- string className = GetClassName();
- string? message = Message;
- string innerExceptionString = _innerException?.ToString() ?? "";
- string endOfInnerExceptionResource = SR.Exception_EndOfInnerExceptionStack;
- string? stackTrace = StackTrace;
-
- // Calculate result string length
- int length = className.Length;
- checked
- {
- if (!string.IsNullOrEmpty(message))
- {
- length += 2 + message.Length;
- }
- if (_innerException != null)
- {
- length += Environment.NewLineConst.Length + InnerExceptionPrefix.Length + innerExceptionString.Length + Environment.NewLineConst.Length + 3 + endOfInnerExceptionResource.Length;
- }
- if (stackTrace != null)
- {
- length += Environment.NewLineConst.Length + stackTrace.Length;
- }
- }
-
- // Create the string
- string result = string.FastAllocateString(length);
- Span<char> resultSpan = new Span<char>(ref result.GetRawStringData(), result.Length);
-
- // Fill it in
- Write(className, ref resultSpan);
- if (!string.IsNullOrEmpty(message))
- {
- Write(": ", ref resultSpan);
- Write(message, ref resultSpan);
- }
- if (_innerException != null)
- {
- Write(Environment.NewLineConst, ref resultSpan);
- Write(InnerExceptionPrefix, ref resultSpan);
- Write(innerExceptionString, ref resultSpan);
- Write(Environment.NewLineConst, ref resultSpan);
- Write(" ", ref resultSpan);
- Write(endOfInnerExceptionResource, ref resultSpan);
- }
- if (stackTrace != null)
- {
- Write(Environment.NewLineConst, ref resultSpan);
- Write(stackTrace, ref resultSpan);
- }
- Debug.Assert(resultSpan.Length == 0);
-
- // Return it
- return result;
-
- static void Write(string source, ref Span<char> dest)
- {
- source.AsSpan().CopyTo(dest);
- dest = dest.Slice(source.Length);
- }
- }
-
- protected event EventHandler<SafeSerializationEventArgs>? SerializeObjectState
- {
- add { throw new PlatformNotSupportedException(SR.PlatformNotSupported_SecureBinarySerialization); }
- remove { throw new PlatformNotSupportedException(SR.PlatformNotSupported_SecureBinarySerialization); }
- }
-
- public int HResult
- {
- get => _HResult;
- set => _HResult = value;
- }
-
- // this method is required so Object.GetType is not made virtual by the compiler
- // _Exception.GetType()
- public new Type GetType() => base.GetType();
-
- partial void RestoreRemoteStackTrace(SerializationInfo info, StreamingContext context);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ExecutionEngineException.cs b/netcore/System.Private.CoreLib/shared/System/ExecutionEngineException.cs
deleted file mode 100644
index 681f82b0f50..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ExecutionEngineException.cs
+++ /dev/null
@@ -1,49 +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.
-
-//
-//
-/*=============================================================================
-**
-**
-**
-** Purpose: The exception class for misc execution engine exceptions.
-** Currently, its only used as a placeholder type when the EE
-** does a FailFast.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Obsolete("This type previously indicated an unspecified fatal error in the runtime. The runtime no longer raises this exception so this type is obsolete.")]
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class ExecutionEngineException : SystemException
- {
- public ExecutionEngineException()
- : base(SR.Arg_ExecutionEngineException)
- {
- HResult = HResults.COR_E_EXECUTIONENGINE;
- }
-
- public ExecutionEngineException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_EXECUTIONENGINE;
- }
-
- public ExecutionEngineException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_EXECUTIONENGINE;
- }
-
- private ExecutionEngineException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/FieldAccessException.cs b/netcore/System.Private.CoreLib/shared/System/FieldAccessException.cs
deleted file mode 100644
index 20b4bd95164..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/FieldAccessException.cs
+++ /dev/null
@@ -1,42 +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.
-
-/*=============================================================================
-**
-**
-** Purpose: The exception class for class loading failures.
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class FieldAccessException : MemberAccessException
- {
- public FieldAccessException()
- : base(SR.Arg_FieldAccessException)
- {
- HResult = HResults.COR_E_FIELDACCESS;
- }
-
- public FieldAccessException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_FIELDACCESS;
- }
-
- public FieldAccessException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_FIELDACCESS;
- }
-
- protected FieldAccessException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/FlagsAttribute.cs b/netcore/System.Private.CoreLib/shared/System/FlagsAttribute.cs
deleted file mode 100644
index 4f3ab36bfd5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/FlagsAttribute.cs
+++ /dev/null
@@ -1,21 +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.
-
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-
-namespace System
-{
- // Custom attribute to indicate that the enum
- // should be treated as a bitfield (or set of flags).
- // An IDE may use this information to provide a richer
- // development experience.
- [AttributeUsage(AttributeTargets.Enum, Inherited = false)]
- public class FlagsAttribute : Attribute
- {
- public FlagsAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/FormatException.cs b/netcore/System.Private.CoreLib/shared/System/FormatException.cs
deleted file mode 100644
index ea33a973a1f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/FormatException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Exception to designate an illegal argument to FormatMessage.
-**
-**
-===========================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class FormatException : SystemException
- {
- public FormatException()
- : base(SR.Arg_FormatException)
- {
- HResult = HResults.COR_E_FORMAT;
- }
-
- public FormatException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_FORMAT;
- }
-
- public FormatException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_FORMAT;
- }
-
- protected FormatException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/FormattableString.cs b/netcore/System.Private.CoreLib/shared/System/FormattableString.cs
deleted file mode 100644
index 73b1981cd71..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/FormattableString.cs
+++ /dev/null
@@ -1,104 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: implementation of the FormattableString
-** class.
-**
-===========================================================*/
-
-namespace System
-{
- /// <summary>
- /// A composite format string along with the arguments to be formatted. An instance of this
- /// type may result from the use of the C# or VB language primitive "interpolated string".
- /// </summary>
- public abstract class FormattableString : IFormattable
- {
- /// <summary>
- /// The composite format string.
- /// </summary>
- public abstract string Format { get; }
-
- /// <summary>
- /// Returns an object array that contains zero or more objects to format. Clients should not
- /// mutate the contents of the array.
- /// </summary>
- public abstract object?[] GetArguments();
-
- /// <summary>
- /// The number of arguments to be formatted.
- /// </summary>
- public abstract int ArgumentCount { get; }
-
- /// <summary>
- /// Returns one argument to be formatted from argument position <paramref name="index"/>.
- /// </summary>
- public abstract object? GetArgument(int index);
-
- /// <summary>
- /// Format to a string using the given culture.
- /// </summary>
- public abstract string ToString(IFormatProvider? formatProvider);
-
- string IFormattable.ToString(string? ignored, IFormatProvider? formatProvider)
- {
- return ToString(formatProvider);
- }
-
- /// <summary>
- /// Format the given object in the invariant culture. This static method may be
- /// imported in C# by
- /// <code>
- /// using static System.FormattableString;
- /// </code>.
- /// Within the scope
- /// of that import directive an interpolated string may be formatted in the
- /// invariant culture by writing, for example,
- /// <code>
- /// Invariant($"{{ lat = {latitude}; lon = {longitude} }}")
- /// </code>
- /// </summary>
- public static string Invariant(FormattableString formattable)
- {
- if (formattable == null)
- {
- throw new ArgumentNullException(nameof(formattable));
- }
-
- return formattable.ToString(Globalization.CultureInfo.InvariantCulture);
- }
-
- /// <summary>
- /// Format the given object in the current culture. This static method may be
- /// imported in C# by
- /// <code>
- /// using static System.FormattableString;
- /// </code>.
- /// Within the scope
- /// of that import directive an interpolated string may be formatted in the
- /// current culture by writing, for example,
- /// <code>
- /// CurrentCulture($"{{ lat = {latitude}; lon = {longitude} }}")
- /// </code>
- /// </summary>
- public static string CurrentCulture(FormattableString formattable)
- {
- if (formattable == null)
- {
- throw new ArgumentNullException(nameof(formattable));
- }
-
- return formattable.ToString(Globalization.CultureInfo.CurrentCulture);
- }
-
- public override string ToString()
- {
- return ToString(Globalization.CultureInfo.CurrentCulture);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/GCMemoryInfo.cs b/netcore/System.Private.CoreLib/shared/System/GCMemoryInfo.cs
deleted file mode 100644
index 850f1256eb1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/GCMemoryInfo.cs
+++ /dev/null
@@ -1,61 +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.
-
-namespace System
-{
- public readonly struct GCMemoryInfo
- {
- /// <summary>
- /// High memory load threshold when the last GC occured
- /// </summary>
- public long HighMemoryLoadThresholdBytes { get; }
-
- /// <summary>
- /// Memory load when the last GC ocurred
- /// </summary>
- public long MemoryLoadBytes { get; }
-
- /// <summary>
- /// Total available memory for the GC to use when the last GC ocurred.
- ///
- /// If the environment variable COMPlus_GCHeapHardLimit is set,
- /// or "Server.GC.HeapHardLimit" is in runtimeconfig.json, this will come from that.
- /// If the program is run in a container, this will be an implementation-defined fraction of the container's size.
- /// Else, this is the physical memory on the machine that was available for the GC to use when the last GC occurred.
- /// </summary>
- public long TotalAvailableMemoryBytes { get; }
-
- /// <summary>
- /// The total heap size when the last GC ocurred
- /// </summary>
- public long HeapSizeBytes { get; }
-
- /// <summary>
- /// The total fragmentation when the last GC ocurred
- ///
- /// Let's take the example below:
- /// | OBJ_A | OBJ_B | OBJ_C | OBJ_D | OBJ_E |
- ///
- /// Let's say OBJ_B, OBJ_C and and OBJ_E are garbage and get collected, but the heap does not get compacted, the resulting heap will look like the following:
- /// | OBJ_A | F | OBJ_D |
- ///
- /// The memory between OBJ_A and OBJ_D marked `F` is considered part of the FragmentedBytes, and will be used to allocate new objects. The memory after OBJ_D will not be
- /// considered part of the FragmentedBytes, and will also be used to allocate new objects
- /// </summary>
- public long FragmentedBytes { get; }
-
- internal GCMemoryInfo(long highMemoryLoadThresholdBytes,
- long memoryLoadBytes,
- long totalAvailableMemoryBytes,
- long heapSizeBytes,
- long fragmentedBytes)
- {
- HighMemoryLoadThresholdBytes = highMemoryLoadThresholdBytes;
- MemoryLoadBytes = memoryLoadBytes;
- TotalAvailableMemoryBytes = totalAvailableMemoryBytes;
- HeapSizeBytes = heapSizeBytes;
- FragmentedBytes = fragmentedBytes;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Gen2GcCallback.cs b/netcore/System.Private.CoreLib/shared/System/Gen2GcCallback.cs
deleted file mode 100644
index 1926f6f80ad..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Gen2GcCallback.cs
+++ /dev/null
@@ -1,113 +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 System.Diagnostics;
-using System.Runtime.ConstrainedExecution;
-using System.Runtime.InteropServices;
-
-namespace System
-{
- /// <summary>
- /// Schedules a callback roughly every gen 2 GC (you may see a Gen 0 an Gen 1 but only once)
- /// (We can fix this by capturing the Gen 2 count at startup and testing, but I mostly don't care)
- /// </summary>
- internal sealed class Gen2GcCallback : CriticalFinalizerObject
- {
- private readonly Func<bool>? _callback0;
- private readonly Func<object, bool>? _callback1;
- private GCHandle _weakTargetObj;
-
- private Gen2GcCallback(Func<bool> callback)
- {
- _callback0 = callback;
- }
-
- private Gen2GcCallback(Func<object, bool> callback, object targetObj)
- {
- _callback1 = callback;
- _weakTargetObj = GCHandle.Alloc(targetObj, GCHandleType.Weak);
- }
-
- /// <summary>
- /// Schedule 'callback' to be called in the next GC. If the callback returns true it is
- /// rescheduled for the next Gen 2 GC. Otherwise the callbacks stop.
- /// </summary>
- public static void Register(Func<bool> callback)
- {
- // Create a unreachable object that remembers the callback function and target object.
- new Gen2GcCallback(callback);
- }
-
- /// <summary>
- /// Schedule 'callback' to be called in the next GC. If the callback returns true it is
- /// rescheduled for the next Gen 2 GC. Otherwise the callbacks stop.
- ///
- /// NOTE: This callback will be kept alive until either the callback function returns false,
- /// or the target object dies.
- /// </summary>
- public static void Register(Func<object, bool> callback, object targetObj)
- {
- // Create a unreachable object that remembers the callback function and target object.
- new Gen2GcCallback(callback, targetObj);
- }
-
- ~Gen2GcCallback()
- {
- if (_weakTargetObj.IsAllocated)
- {
- // Check to see if the target object is still alive.
- object? targetObj = _weakTargetObj.Target;
- if (targetObj == null)
- {
- // The target object is dead, so this callback object is no longer needed.
- _weakTargetObj.Free();
- return;
- }
-
- // Execute the callback method.
- try
- {
- Debug.Assert(_callback1 != null);
- if (!_callback1(targetObj))
- {
- // If the callback returns false, this callback object is no longer needed.
- return;
- }
- }
- catch
- {
- // Ensure that we still get a chance to resurrect this object, even if the callback throws an exception.
-#if DEBUG
- // Except in DEBUG, as we really shouldn't be hitting any exceptions here.
- throw;
-#endif
- }
- }
- else
- {
- // Execute the callback method.
- try
- {
- Debug.Assert(_callback0 != null);
- if (!_callback0())
- {
- // If the callback returns false, this callback object is no longer needed.
- return;
- }
- }
- catch
- {
- // Ensure that we still get a chance to resurrect this object, even if the callback throws an exception.
-#if DEBUG
- // Except in DEBUG, as we really shouldn't be hitting any exceptions here.
- throw;
-#endif
- }
- }
-
- // Resurrect ourselves by re-registering for finalization.
- GC.ReRegisterForFinalize(this);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/BidiCategory.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/BidiCategory.cs
deleted file mode 100644
index abe69508932..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/BidiCategory.cs
+++ /dev/null
@@ -1,33 +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.
-
-namespace System.Globalization
-{
- internal enum BidiCategory
- {
- LeftToRight = 0,
- LeftToRightEmbedding = 1,
- LeftToRightOverride = 2,
- RightToLeft = 3,
- RightToLeftArabic = 4,
- RightToLeftEmbedding = 5,
- RightToLeftOverride = 6,
- PopDirectionalFormat = 7,
- EuropeanNumber = 8,
- EuropeanNumberSeparator = 9,
- EuropeanNumberTerminator = 10,
- ArabicNumber = 11,
- CommonNumberSeparator = 12,
- NonSpacingMark = 13,
- BoundaryNeutral = 14,
- ParagraphSeparator = 15,
- SegmentSeparator = 16,
- Whitespace = 17,
- OtherNeutrals = 18,
- LeftToRightIsolate = 19,
- RightToLeftIsolate = 20,
- FirstStrongIsolate = 21,
- PopDirectionIsolate = 22,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/Calendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/Calendar.cs
deleted file mode 100644
index 7d86971a879..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/Calendar.cs
+++ /dev/null
@@ -1,732 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- // This abstract class represents a calendar. A calendar reckons time in
- // divisions such as weeks, months and years. The number, length and start of
- // the divisions vary in each calendar.
- //
- // Any instant in time can be represented as an n-tuple of numeric values using
- // a particular calendar. For example, the next vernal equinox occurs at (0.0, 0
- // , 46, 8, 20, 3, 1999) in the Gregorian calendar. An implementation of
- // Calendar can map any DateTime value to such an n-tuple and vice versa. The
- // DateTimeFormat class can map between such n-tuples and a textual
- // representation such as "8:46 AM March 20th 1999 AD".
- //
- // Most calendars identify a year which begins the current era. There may be any
- // number of previous eras. The Calendar class identifies the eras as enumerated
- // integers where the current era (CurrentEra) has the value zero.
- //
- // For consistency, the first unit in each interval, e.g. the first month, is
- // assigned the value one.
- // The calculation of hour/minute/second is moved to Calendar from GregorianCalendar,
- // since most of the calendars (or all?) have the same way of calcuating hour/minute/second.
-
- public abstract class Calendar : ICloneable
- {
- // Number of 100ns (10E-7 second) ticks per time unit
- internal const long TicksPerMillisecond = 10000;
- internal const long TicksPerSecond = TicksPerMillisecond * 1000;
- internal const long TicksPerMinute = TicksPerSecond * 60;
- internal const long TicksPerHour = TicksPerMinute * 60;
- internal const long TicksPerDay = TicksPerHour * 24;
-
- // Number of milliseconds per time unit
- internal const int MillisPerSecond = 1000;
- internal const int MillisPerMinute = MillisPerSecond * 60;
- internal const int MillisPerHour = MillisPerMinute * 60;
- internal const int MillisPerDay = MillisPerHour * 24;
-
- // Number of days in a non-leap year
- internal const int DaysPerYear = 365;
- // Number of days in 4 years
- internal const int DaysPer4Years = DaysPerYear * 4 + 1;
- // Number of days in 100 years
- internal const int DaysPer100Years = DaysPer4Years * 25 - 1;
- // Number of days in 400 years
- internal const int DaysPer400Years = DaysPer100Years * 4 + 1;
-
- // Number of days from 1/1/0001 to 1/1/10000
- internal const int DaysTo10000 = DaysPer400Years * 25 - 366;
-
- internal const long MaxMillis = (long)DaysTo10000 * MillisPerDay;
-
- private int _currentEraValue = -1;
-
- private bool _isReadOnly = false;
-
- public virtual DateTime MinSupportedDateTime => DateTime.MinValue;
-
- public virtual DateTime MaxSupportedDateTime => DateTime.MaxValue;
-
- public virtual CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.Unknown;
-
- protected Calendar()
- {
- }
-
- internal virtual CalendarId ID => CalendarId.UNINITIALIZED_VALUE;
-
- // Return the Base calendar ID for calendars that didn't have defined data in calendarData
- internal virtual CalendarId BaseCalendarID => ID;
-
- public bool IsReadOnly => _isReadOnly;
-
- public virtual object Clone()
- {
- object o = MemberwiseClone();
- ((Calendar)o).SetReadOnlyState(false);
- return o;
- }
-
- public static Calendar ReadOnly(Calendar calendar)
- {
- if (calendar == null)
- {
- throw new ArgumentNullException(nameof(calendar));
- }
- if (calendar.IsReadOnly)
- {
- return calendar;
- }
-
- Calendar clonedCalendar = (Calendar)(calendar.MemberwiseClone());
- clonedCalendar.SetReadOnlyState(true);
- return clonedCalendar;
- }
-
- internal void VerifyWritable()
- {
- if (_isReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- }
-
- internal void SetReadOnlyState(bool readOnly)
- {
- _isReadOnly = readOnly;
- }
-
- /// <summary>
- /// This is used to convert CurrentEra(0) to an appropriate era value.
- /// </summary>
- internal virtual int CurrentEraValue
- {
- get
- {
- // The following code assumes that the current era value can not be -1.
- if (_currentEraValue == -1)
- {
- Debug.Assert(BaseCalendarID != CalendarId.UNINITIALIZED_VALUE, "[Calendar.CurrentEraValue] Expected a real calendar ID");
- _currentEraValue = CalendarData.GetCalendarData(BaseCalendarID).iCurrentEra;
- }
-
- return _currentEraValue;
- }
- }
-
- public const int CurrentEra = 0;
-
- internal int _twoDigitYearMax = -1;
-
- internal static void CheckAddResult(long ticks, DateTime minValue, DateTime maxValue)
- {
- if (ticks < minValue.Ticks || ticks > maxValue.Ticks)
- {
- throw new ArgumentException(SR.Format(SR.Argument_ResultCalendarRange, minValue, maxValue));
- }
- }
-
- internal DateTime Add(DateTime time, double value, int scale)
- {
- // From ECMA CLI spec, Partition III, section 3.27:
- //
- // If overflow occurs converting a floating-point type to an integer, or if the floating-point value
- // being converted to an integer is a NaN, the value returned is unspecified.
- //
- // Based upon this, this method should be performing the comparison against the double
- // before attempting a cast. Otherwise, the result is undefined.
- double tempMillis = (value * scale + (value >= 0 ? 0.5 : -0.5));
- if (!((tempMillis > -(double)MaxMillis) && (tempMillis < (double)MaxMillis)))
- {
- throw new ArgumentOutOfRangeException(nameof(value), value, SR.ArgumentOutOfRange_AddValue);
- }
-
- long millis = (long)tempMillis;
- long ticks = time.Ticks + millis * TicksPerMillisecond;
- CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
- return new DateTime(ticks);
- }
-
- /// <summary>
- /// Returns the DateTime resulting from adding the given number of
- /// milliseconds to the specified DateTime. The result is computed by rounding
- /// the number of milliseconds given by value to the nearest integer,
- /// and adding that interval to the specified DateTime. The value
- /// argument is permitted to be negative.
- /// </summary>
- public virtual DateTime AddMilliseconds(DateTime time, double milliseconds)
- {
- return Add(time, milliseconds, 1);
- }
-
- /// <summary>
- /// Returns the DateTime resulting from adding a fractional number of
- /// days to the specified DateTime. The result is computed by rounding the
- /// fractional number of days given by value to the nearest
- /// millisecond, and adding that interval to the specified DateTime. The
- /// value argument is permitted to be negative.
- /// </summary>
- public virtual DateTime AddDays(DateTime time, int days)
- {
- return Add(time, days, MillisPerDay);
- }
-
- /// <summary>
- /// Returns the DateTime resulting from adding a fractional number of
- /// hours to the specified DateTime. The result is computed by rounding the
- /// fractional number of hours given by value to the nearest
- /// millisecond, and adding that interval to the specified DateTime. The
- /// value argument is permitted to be negative.
- /// </summary>
- public virtual DateTime AddHours(DateTime time, int hours)
- {
- return Add(time, hours, MillisPerHour);
- }
-
- /// <summary>
- /// Returns the DateTime resulting from adding a fractional number of
- /// minutes to the specified DateTime. The result is computed by rounding the
- /// fractional number of minutes given by value to the nearest
- /// millisecond, and adding that interval to the specified DateTime. The
- /// value argument is permitted to be negative.
- /// </summary>
- public virtual DateTime AddMinutes(DateTime time, int minutes)
- {
- return Add(time, minutes, MillisPerMinute);
- }
-
- /// <summary>
- /// Returns the DateTime resulting from adding the given number of
- /// months to the specified DateTime. The result is computed by incrementing
- /// (or decrementing) the year and month parts of the specified DateTime by
- /// value months, and, if required, adjusting the day part of the
- /// resulting date downwards to the last day of the resulting month in the
- /// resulting year. The time-of-day part of the result is the same as the
- /// time-of-day part of the specified DateTime.
- ///
- /// In more precise terms, considering the specified DateTime to be of the
- /// form y / m / d + t, where y is the
- /// year, m is the month, d is the day, and t is the
- /// time-of-day, the result is y1 / m1 / d1 + t,
- /// where y1 and m1 are computed by adding value months
- /// to y and m, and d1 is the largest value less than
- /// or equal to d that denotes a valid day in month m1 of year
- /// y1.
- /// </summary>
- public abstract DateTime AddMonths(DateTime time, int months);
-
- /// <summary>
- /// Returns the DateTime resulting from adding a number of
- /// seconds to the specified DateTime. The result is computed by rounding the
- /// fractional number of seconds given by value to the nearest
- /// millisecond, and adding that interval to the specified DateTime. The
- /// value argument is permitted to be negative.
- /// </summary>
- public virtual DateTime AddSeconds(DateTime time, int seconds)
- {
- return Add(time, seconds, MillisPerSecond);
- }
-
- // Returns the DateTime resulting from adding a number of
- // weeks to the specified DateTime. The
- // value argument is permitted to be negative.
- public virtual DateTime AddWeeks(DateTime time, int weeks)
- {
- return AddDays(time, weeks * 7);
- }
-
- /// <summary>
- /// Returns the DateTime resulting from adding the given number of
- /// years to the specified DateTime. The result is computed by incrementing
- /// (or decrementing) the year part of the specified DateTime by value
- /// years. If the month and day of the specified DateTime is 2/29, and if the
- /// resulting year is not a leap year, the month and day of the resulting
- /// DateTime becomes 2/28. Otherwise, the month, day, and time-of-day
- /// parts of the result are the same as those of the specified DateTime.
- /// </summary>
- public abstract DateTime AddYears(DateTime time, int years);
-
- /// <summary>
- /// Returns the day-of-month part of the specified DateTime. The returned
- /// value is an integer between 1 and 31.
- /// </summary>
- public abstract int GetDayOfMonth(DateTime time);
-
- /// <summary>
- /// Returns the day-of-week part of the specified DateTime. The returned value
- /// is an integer between 0 and 6, where 0 indicates Sunday, 1 indicates
- /// Monday, 2 indicates Tuesday, 3 indicates Wednesday, 4 indicates
- /// Thursday, 5 indicates Friday, and 6 indicates Saturday.
- /// </summary>
- public abstract DayOfWeek GetDayOfWeek(DateTime time);
-
- /// <summary>
- /// Returns the day-of-year part of the specified DateTime. The returned value
- /// is an integer between 1 and 366.
- /// </summary>
- public abstract int GetDayOfYear(DateTime time);
-
- /// <summary>
- /// Returns the number of days in the month given by the year and
- /// month arguments.
- /// </summary>
- public virtual int GetDaysInMonth(int year, int month)
- {
- return GetDaysInMonth(year, month, CurrentEra);
- }
-
- /// <summary>
- /// Returns the number of days in the month given by the year and
- /// month arguments for the specified era.
- /// </summary>
- public abstract int GetDaysInMonth(int year, int month, int era);
-
- /// <summary>
- /// Returns the number of days in the year given by the year argument
- /// for the current era.
- /// </summary>
- public virtual int GetDaysInYear(int year)
- {
- return GetDaysInYear(year, CurrentEra);
- }
-
- /// <summary>
- /// Returns the number of days in the year given by the year argument
- /// for the current era.
- /// </summary>
- public abstract int GetDaysInYear(int year, int era);
-
- /// <summary>
- /// Returns the era for the specified DateTime value.
- /// </summary>
- public abstract int GetEra(DateTime time);
-
- /// <summary>
- /// Get the list of era values.
- /// </summary>
- /// <returns>The int array of the era names supported in this calendar or null if era is not used.</returns>
- public abstract int[] Eras { get; }
-
- // Returns the hour part of the specified DateTime. The returned value is an
- // integer between 0 and 23.
- public virtual int GetHour(DateTime time)
- {
- return (int)((time.Ticks / TicksPerHour) % 24);
- }
-
- // Returns the millisecond part of the specified DateTime. The returned value
- // is an integer between 0 and 999.
- public virtual double GetMilliseconds(DateTime time)
- {
- return (double)((time.Ticks / TicksPerMillisecond) % 1000);
- }
-
- // Returns the minute part of the specified DateTime. The returned value is
- // an integer between 0 and 59.
- public virtual int GetMinute(DateTime time)
- {
- return (int)((time.Ticks / TicksPerMinute) % 60);
- }
-
- // Returns the month part of the specified DateTime. The returned value is an
- // integer between 1 and 12.
- public abstract int GetMonth(DateTime time);
-
- // Returns the number of months in the specified year in the current era.
- public virtual int GetMonthsInYear(int year)
- {
- return GetMonthsInYear(year, CurrentEra);
- }
-
- // Returns the number of months in the specified year and era.
- public abstract int GetMonthsInYear(int year, int era);
-
- // Returns the second part of the specified DateTime. The returned value is
- // an integer between 0 and 59.
- public virtual int GetSecond(DateTime time)
- {
- return (int)((time.Ticks / TicksPerSecond) % 60);
- }
-
- /// <summary>
- /// Get the week of year using the FirstDay rule.
- /// </summary>
- /// <remarks>
- /// The CalendarWeekRule.FirstDay rule: Week 1 begins on the first day of the year.
- /// Assume f is the specifed firstDayOfWeek,
- /// and n is the day of week for January 1 of the specified year.
- /// Assign offset = n - f;
- /// Case 1: offset = 0
- /// E.g.
- /// f=1
- /// weekday 0 1 2 3 4 5 6 0 1
- /// date 1/1
- /// week# 1 2
- /// then week of year = (GetDayOfYear(time) - 1) / 7 + 1
- ///
- /// Case 2: offset &lt; 0
- /// e.g.
- /// n=1 f=3
- /// weekday 0 1 2 3 4 5 6 0
- /// date 1/1
- /// week# 1 2
- /// This means that the first week actually starts 5 days before 1/1.
- /// So week of year = (GetDayOfYear(time) + (7 + offset) - 1) / 7 + 1
- /// Case 3: offset > 0
- /// e.g.
- /// f=0 n=2
- /// weekday 0 1 2 3 4 5 6 0 1 2
- /// date 1/1
- /// week# 1 2
- /// This means that the first week actually starts 2 days before 1/1.
- /// So Week of year = (GetDayOfYear(time) + offset - 1) / 7 + 1
- /// </remarks>
- internal int GetFirstDayWeekOfYear(DateTime time, int firstDayOfWeek)
- {
- int dayOfYear = GetDayOfYear(time) - 1; // Make the day of year to be 0-based, so that 1/1 is day 0.
- // Calculate the day of week for the first day of the year.
- // dayOfWeek - (dayOfYear % 7) is the day of week for the first day of this year. Note that
- // this value can be less than 0. It's fine since we are making it positive again in calculating offset.
- int dayForJan1 = (int)GetDayOfWeek(time) - (dayOfYear % 7);
- int offset = (dayForJan1 - firstDayOfWeek + 14) % 7;
- Debug.Assert(offset >= 0, "Calendar.GetFirstDayWeekOfYear(): offset >= 0");
- return (dayOfYear + offset) / 7 + 1;
- }
-
- private int GetWeekOfYearFullDays(DateTime time, int firstDayOfWeek, int fullDays)
- {
- int dayForJan1;
- int offset;
- int day;
-
- int dayOfYear = GetDayOfYear(time) - 1; // Make the day of year to be 0-based, so that 1/1 is day 0.
-
- // Calculate the number of days between the first day of year (1/1) and the first day of the week.
- // This value will be a positive value from 0 ~ 6. We call this value as "offset".
- //
- // If offset is 0, it means that the 1/1 is the start of the first week.
- // Assume the first day of the week is Monday, it will look like this:
- // Sun Mon Tue Wed Thu Fri Sat
- // 12/31 1/1 1/2 1/3 1/4 1/5 1/6
- // +--> First week starts here.
- //
- // If offset is 1, it means that the first day of the week is 1 day ahead of 1/1.
- // Assume the first day of the week is Monday, it will look like this:
- // Sun Mon Tue Wed Thu Fri Sat
- // 1/1 1/2 1/3 1/4 1/5 1/6 1/7
- // +--> First week starts here.
- //
- // If offset is 2, it means that the first day of the week is 2 days ahead of 1/1.
- // Assume the first day of the week is Monday, it will look like this:
- // Sat Sun Mon Tue Wed Thu Fri Sat
- // 1/1 1/2 1/3 1/4 1/5 1/6 1/7 1/8
- // +--> First week starts here.
-
- // Day of week is 0-based.
- // Get the day of week for 1/1. This can be derived from the day of week of the target day.
- // Note that we can get a negative value. It's ok since we are going to make it a positive value when calculating the offset.
- dayForJan1 = (int)GetDayOfWeek(time) - (dayOfYear % 7);
-
- // Now, calculate the offset. Subtract the first day of week from the dayForJan1. And make it a positive value.
- offset = (firstDayOfWeek - dayForJan1 + 14) % 7;
- if (offset != 0 && offset >= fullDays)
- {
- // If the offset is greater than the value of fullDays, it means that
- // the first week of the year starts on the week where Jan/1 falls on.
- offset -= 7;
- }
-
- // Calculate the day of year for specified time by taking offset into account.
- day = dayOfYear - offset;
- if (day >= 0)
- {
- // If the day of year value is greater than zero, get the week of year.
- return day / 7 + 1;
- }
-
- // Otherwise, the specified time falls on the week of previous year.
- // Call this method again by passing the last day of previous year.
- // the last day of the previous year may "underflow" to no longer be a valid date time for
- // this calendar if we just subtract so we need the subclass to provide us with
- // that information
- if (time <= MinSupportedDateTime.AddDays(dayOfYear))
- {
- return GetWeekOfYearOfMinSupportedDateTime(firstDayOfWeek, fullDays);
- }
-
- return GetWeekOfYearFullDays(time.AddDays(-(dayOfYear + 1)), firstDayOfWeek, fullDays);
- }
-
- private int GetWeekOfYearOfMinSupportedDateTime(int firstDayOfWeek, int minimumDaysInFirstWeek)
- {
- int dayOfYear = GetDayOfYear(MinSupportedDateTime) - 1; // Make the day of year to be 0-based, so that 1/1 is day 0.
- int dayOfWeekOfFirstOfYear = (int)GetDayOfWeek(MinSupportedDateTime) - dayOfYear % 7;
-
- // Calculate the offset (how many days from the start of the year to the start of the week)
- int offset = (firstDayOfWeek + 7 - dayOfWeekOfFirstOfYear) % 7;
- if (offset == 0 || offset >= minimumDaysInFirstWeek)
- {
- // First of year falls in the first week of the year
- return 1;
- }
-
- int daysInYearBeforeMinSupportedYear = DaysInYearBeforeMinSupportedYear - 1; // Make the day of year to be 0-based, so that 1/1 is day 0.
- int dayOfWeekOfFirstOfPreviousYear = dayOfWeekOfFirstOfYear - 1 - (daysInYearBeforeMinSupportedYear % 7);
-
- // starting from first day of the year, how many days do you have to go forward
- // before getting to the first day of the week?
- int daysInInitialPartialWeek = (firstDayOfWeek - dayOfWeekOfFirstOfPreviousYear + 14) % 7;
- int day = daysInYearBeforeMinSupportedYear - daysInInitialPartialWeek;
- if (daysInInitialPartialWeek >= minimumDaysInFirstWeek)
- {
- // If the offset is greater than the minimum Days in the first week, it means that
- // First of year is part of the first week of the year even though it is only a partial week
- // add another week
- day += 7;
- }
-
- return day / 7 + 1;
- }
-
- protected virtual int DaysInYearBeforeMinSupportedYear => 365;
-
- /// <summary>
- /// Returns the week of year for the specified DateTime. The returned value is an
- /// integer between 1 and 53.
- /// </summary>
- public virtual int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
- {
- if (firstDayOfWeek < DayOfWeek.Sunday || firstDayOfWeek > DayOfWeek.Saturday)
- {
- throw new ArgumentOutOfRangeException(
- nameof(firstDayOfWeek),
- firstDayOfWeek,
- SR.Format(SR.ArgumentOutOfRange_Range, DayOfWeek.Sunday, DayOfWeek.Saturday));
- }
-
- return rule switch
- {
- CalendarWeekRule.FirstDay => GetFirstDayWeekOfYear(time, (int)firstDayOfWeek),
- CalendarWeekRule.FirstFullWeek => GetWeekOfYearFullDays(time, (int)firstDayOfWeek, 7),
- CalendarWeekRule.FirstFourDayWeek => GetWeekOfYearFullDays(time, (int)firstDayOfWeek, 4),
- _ => throw new ArgumentOutOfRangeException(
- nameof(rule),
- rule,
- SR.Format(SR.ArgumentOutOfRange_Range, CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek)),
- };
- }
-
- /// <summary>
- /// Returns the year part of the specified DateTime. The returned value is an
- /// integer between 1 and 9999.
- /// </summary>
- public abstract int GetYear(DateTime time);
-
- /// <summary>
- /// Checks whether a given day in the current era is a leap day.
- /// This method returns true if the date is a leap day, or false if not.
- /// </summary>
- public virtual bool IsLeapDay(int year, int month, int day)
- {
- return IsLeapDay(year, month, day, CurrentEra);
- }
-
- /// <summary>
- /// Checks whether a given day in the specified era is a leap day.
- /// This method returns true if the date is a leap day, or false if not.
- /// </summary>
- public abstract bool IsLeapDay(int year, int month, int day, int era);
-
- /// <summary>
- /// Checks whether a given month in the current era is a leap month.
- /// This method returns true if month is a leap month, or false if not.
- /// </summary>
- public virtual bool IsLeapMonth(int year, int month)
- {
- return IsLeapMonth(year, month, CurrentEra);
- }
-
- /// <summary>
- /// Checks whether a given month in the specified era is a leap month. This method returns true if
- /// month is a leap month, or false if not.
- /// </summary>
- public abstract bool IsLeapMonth(int year, int month, int era);
-
- /// <summary>
- /// Returns the leap month in a calendar year of the current era.
- /// This method returns 0 if this calendar does not have leap month,
- /// or this year is not a leap year.
- /// </summary>
- public virtual int GetLeapMonth(int year)
- {
- return GetLeapMonth(year, CurrentEra);
- }
-
- /// <summary>
- /// Returns the leap month in a calendar year of the specified era.
- /// This method returns 0 if this calendar does not have leap month,
- /// or this year is not a leap year.
- /// </summary>
- public virtual int GetLeapMonth(int year, int era)
- {
- if (!IsLeapYear(year, era))
- {
- return 0;
- }
-
- int monthsCount = GetMonthsInYear(year, era);
- for (int month = 1; month <= monthsCount; month++)
- {
- if (IsLeapMonth(year, month, era))
- {
- return month;
- }
- }
-
- return 0;
- }
-
- /// <summary>
- /// Checks whether a given year in the current era is a leap year.
- /// This method returns true if year is a leap year, or false if not.
- /// </summary>
- public virtual bool IsLeapYear(int year)
- {
- return IsLeapYear(year, CurrentEra);
- }
-
- /// <summary>
- /// Checks whether a given year in the specified era is a leap year.
- /// This method returns true if year is a leap year, or false if not.
- /// </summary>
- public abstract bool IsLeapYear(int year, int era);
-
- /// <summary>
- /// Returns the date and time converted to a DateTime value.
- /// Throws an exception if the n-tuple is invalid.
- /// </summary>
- public virtual DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
- {
- return ToDateTime(year, month, day, hour, minute, second, millisecond, CurrentEra);
- }
-
- /// <summary>
- /// Returns the date and time converted to a DateTime value.
- /// Throws an exception if the n-tuple is invalid.
- /// </summary>
- public abstract DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era);
-
- internal virtual bool TryToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era, out DateTime result)
- {
- result = DateTime.MinValue;
- try
- {
- result = ToDateTime(year, month, day, hour, minute, second, millisecond, era);
- return true;
- }
- catch (ArgumentException)
- {
- return false;
- }
- }
-
- internal virtual bool IsValidYear(int year, int era)
- {
- return year >= GetYear(MinSupportedDateTime) && year <= GetYear(MaxSupportedDateTime);
- }
-
- internal virtual bool IsValidMonth(int year, int month, int era)
- {
- return IsValidYear(year, era) && month >= 1 && month <= GetMonthsInYear(year, era);
- }
-
- internal virtual bool IsValidDay(int year, int month, int day, int era)
- {
- return IsValidMonth(year, month, era) && day >= 1 && day <= GetDaysInMonth(year, month, era);
- }
-
- /// <summary>
- /// Returns and assigns the maximum value to represent a two digit year.
- /// This value is the upper boundary of a 100 year range that allows a
- /// two digit year to be properly translated to a four digit year.
- /// For example, if 2029 is the upper boundary, then a two digit value of
- /// 30 should be interpreted as 1930 while a two digit value of 29 should
- /// be interpreted as 2029. In this example, the 100 year range would be
- /// from 1930-2029. See ToFourDigitYear().
- /// </summary>
- public virtual int TwoDigitYearMax
- {
- get => _twoDigitYearMax;
- set
- {
- VerifyWritable();
- _twoDigitYearMax = value;
- }
- }
-
- /// <summary>
- /// Converts the year value to the appropriate century by using the
- /// TwoDigitYearMax property. For example, if the TwoDigitYearMax value is 2029,
- /// then a two digit value of 30 will get converted to 1930 while a two digit
- /// value of 29 will get converted to 2029.
- /// </summary>
- public virtual int ToFourDigitYear(int year)
- {
- if (year < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (year < 100)
- {
- return (TwoDigitYearMax / 100 - (year > TwoDigitYearMax % 100 ? 1 : 0)) * 100 + year;
- }
-
- // If the year value is above 100, just return the year value. Don't have to do
- // the TwoDigitYearMax comparison.
- return year;
- }
-
- /// <summary>
- /// Return the tick count corresponding to the given hour, minute, second.
- /// Will check the if the parameters are valid.
- /// </summary>
- internal static long TimeToTicks(int hour, int minute, int second, int millisecond)
- {
- if (hour < 0 || hour >= 24 || minute < 0 || minute >= 60 || second < 0 || second >= 60)
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond);
- }
- if (millisecond < 0 || millisecond >= MillisPerSecond)
- {
- throw new ArgumentOutOfRangeException(
- nameof(millisecond),
- millisecond,
- SR.Format(SR.ArgumentOutOfRange_Range, 0, MillisPerSecond - 1));
- }
-
- return InternalGlobalizationHelper.TimeToTicks(hour, minute, second) + millisecond * TicksPerMillisecond;
- }
-
- internal static int GetSystemTwoDigitYearSetting(CalendarId CalID, int defaultYearValue)
- {
- int twoDigitYearMax = CalendarData.GetTwoDigitYearMax(CalID);
- return twoDigitYearMax >= 0 ? twoDigitYearMax : defaultYearValue;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarAlgorithmType.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarAlgorithmType.cs
deleted file mode 100644
index 4ddc307abfa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarAlgorithmType.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Globalization
-{
- public enum CalendarAlgorithmType
- {
- Unknown = 0, // This is the default value to return in the Calendar base class.
- SolarCalendar = 1, // Solar-base calendar, such as GregorianCalendar, jaoaneseCalendar, JulianCalendar, etc.
- // Solar calendars are based on the solar year and seasons.
- LunarCalendar = 2, // Lunar-based calendar, such as Hijri and UmAlQuraCalendar.
- // Lunar calendars are based on the path of the moon. The seasons are not accurately represented.
- LunisolarCalendar = 3 // Lunisolar-based calendar which use leap month rule, such as HebrewCalendar and Asian Lunisolar calendars.
- // Lunisolar calendars are based on the cycle of the moon, but consider the seasons as a secondary consideration,
- // so they align with the seasons as well as lunar events.
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.Unix.cs
deleted file mode 100644
index d8ed0072f37..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.Unix.cs
+++ /dev/null
@@ -1,460 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Security;
-using System.Text;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Globalization
-{
- // needs to be kept in sync with CalendarDataType in System.Globalization.Native
- internal enum CalendarDataType
- {
- Uninitialized = 0,
- NativeName = 1,
- MonthDay = 2,
- ShortDates = 3,
- LongDates = 4,
- YearMonths = 5,
- DayNames = 6,
- AbbrevDayNames = 7,
- MonthNames = 8,
- AbbrevMonthNames = 9,
- SuperShortDayNames = 10,
- MonthGenitiveNames = 11,
- AbbrevMonthGenitiveNames = 12,
- EraNames = 13,
- AbbrevEraNames = 14,
- }
-
- internal partial class CalendarData
- {
- private bool LoadCalendarDataFromSystem(string localeName, CalendarId calendarId)
- {
- bool result = true;
-
- // these can return null but are later replaced with String.Empty or other non-nullable value
- result &= GetCalendarInfo(localeName, calendarId, CalendarDataType.NativeName, out this.sNativeName!);
- result &= GetCalendarInfo(localeName, calendarId, CalendarDataType.MonthDay, out this.sMonthDay!);
-
- if (this.sMonthDay != null)
- {
- this.sMonthDay = NormalizeDatePattern(this.sMonthDay);
- }
-
- result &= EnumDatePatterns(localeName, calendarId, CalendarDataType.ShortDates, out this.saShortDates!);
- result &= EnumDatePatterns(localeName, calendarId, CalendarDataType.LongDates, out this.saLongDates!);
- result &= EnumDatePatterns(localeName, calendarId, CalendarDataType.YearMonths, out this.saYearMonths!);
- result &= EnumCalendarInfo(localeName, calendarId, CalendarDataType.DayNames, out this.saDayNames!);
- result &= EnumCalendarInfo(localeName, calendarId, CalendarDataType.AbbrevDayNames, out this.saAbbrevDayNames!);
- result &= EnumCalendarInfo(localeName, calendarId, CalendarDataType.SuperShortDayNames, out this.saSuperShortDayNames!);
-
- string? leapHebrewMonthName = null;
- result &= EnumMonthNames(localeName, calendarId, CalendarDataType.MonthNames, out this.saMonthNames!, ref leapHebrewMonthName);
- if (leapHebrewMonthName != null)
- {
- Debug.Assert(this.saMonthNames != null);
-
- // In Hebrew calendar, get the leap month name Adar II and override the non-leap month 7
- Debug.Assert(calendarId == CalendarId.HEBREW && saMonthNames.Length == 13);
- saLeapYearMonthNames = (string[]) saMonthNames.Clone();
- saLeapYearMonthNames[6] = leapHebrewMonthName;
-
- // The returned data from ICU has 6th month name as 'Adar I' and 7th month name as 'Adar'
- // We need to adjust that in the list used with non-leap year to have 6th month as 'Adar' and 7th month as 'Adar II'
- // note that when formatting non-leap year dates, 7th month shouldn't get used at all.
- saMonthNames[5] = saMonthNames[6];
- saMonthNames[6] = leapHebrewMonthName;
-
- }
- result &= EnumMonthNames(localeName, calendarId, CalendarDataType.AbbrevMonthNames, out this.saAbbrevMonthNames!, ref leapHebrewMonthName);
- result &= EnumMonthNames(localeName, calendarId, CalendarDataType.MonthGenitiveNames, out this.saMonthGenitiveNames!, ref leapHebrewMonthName);
- result &= EnumMonthNames(localeName, calendarId, CalendarDataType.AbbrevMonthGenitiveNames, out this.saAbbrevMonthGenitiveNames!, ref leapHebrewMonthName);
-
- result &= EnumEraNames(localeName, calendarId, CalendarDataType.EraNames, out this.saEraNames!);
- result &= EnumEraNames(localeName, calendarId, CalendarDataType.AbbrevEraNames, out this.saAbbrevEraNames!);
-
- return result;
- }
-
- internal static int GetTwoDigitYearMax(CalendarId calendarId)
- {
- // There is no user override for this value on Linux or in ICU.
- // So just return -1 to use the hard-coded defaults.
- return -1;
- }
-
- // Call native side to figure out which calendars are allowed
- internal static int GetCalendars(string localeName, bool useUserOverride, CalendarId[] calendars)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- // NOTE: there are no 'user overrides' on Linux
- int count = Interop.Globalization.GetCalendars(localeName, calendars, calendars.Length);
-
- // ensure there is at least 1 calendar returned
- if (count == 0 && calendars.Length > 0)
- {
- calendars[0] = CalendarId.GREGORIAN;
- count = 1;
- }
-
- return count;
- }
-
- private static bool SystemSupportsTaiwaneseCalendar()
- {
- return true;
- }
-
- // PAL Layer ends here
-
- private static unsafe bool GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType dataType, out string? calendarString)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- return Interop.CallStringMethod(
- (buffer, locale, id, type) =>
- {
- fixed (char* bufferPtr = buffer)
- {
- return Interop.Globalization.GetCalendarInfo(locale, id, type, bufferPtr, buffer.Length);
- }
- },
- localeName,
- calendarId,
- dataType,
- out calendarString);
- }
-
- private static bool EnumDatePatterns(string localeName, CalendarId calendarId, CalendarDataType dataType, out string[]? datePatterns)
- {
- datePatterns = null;
-
- EnumCalendarsData callbackContext = default;
- callbackContext.Results = new List<string>();
- callbackContext.DisallowDuplicates = true;
- bool result = EnumCalendarInfo(localeName, calendarId, dataType, ref callbackContext);
- if (result)
- {
- List<string> datePatternsList = callbackContext.Results;
-
- for (int i = 0; i < datePatternsList.Count; i++)
- {
- datePatternsList[i] = NormalizeDatePattern(datePatternsList[i]);
- }
-
- if (dataType == CalendarDataType.ShortDates)
- FixDefaultShortDatePattern(datePatternsList);
-
- datePatterns = datePatternsList.ToArray();
- }
-
- return result;
- }
-
- // FixDefaultShortDatePattern will convert the default short date pattern from using 'yy' to using 'yyyy'
- // And will ensure the original pattern still exist in the list.
- // doing that will have the short date pattern format the year as 4-digit number and not just 2-digit number.
- // Example: June 5, 2018 will be formatted to something like 6/5/2018 instead of 6/5/18 fro en-US culture.
- private static void FixDefaultShortDatePattern(List<string> shortDatePatterns)
- {
- if (shortDatePatterns.Count == 0)
- return;
-
- string s = shortDatePatterns[0];
-
- // We are not expecting any pattern have length more than 100.
- // We have to do this check to prevent stack overflow as we allocate the buffer on the stack.
- if (s.Length > 100)
- return;
-
- Span<char> modifiedPattern = stackalloc char[s.Length + 2];
- int index = 0;
-
- while (index < s.Length)
- {
- if (s[index] == '\'')
- {
- do
- {
- modifiedPattern[index] = s[index];
- index++;
- } while (index < s.Length && s[index] != '\'');
-
- if (index >= s.Length)
- return;
- }
- else if (s[index] == 'y')
- {
- modifiedPattern[index] = 'y';
- break;
- }
-
- modifiedPattern[index] = s[index];
- index++;
- }
-
- if (index >= s.Length - 1 || s[index + 1] != 'y')
- {
- // not a 'yy' pattern
- return;
- }
-
- if (index + 2 < s.Length && s[index + 2] == 'y')
- {
- // we have 'yyy' then nothing to do
- return;
- }
-
- // we are sure now we have 'yy' pattern
-
- Debug.Assert(index + 3 < modifiedPattern.Length);
-
- modifiedPattern[index + 1] = 'y'; // second y
- modifiedPattern[index + 2] = 'y'; // third y
- modifiedPattern[index + 3] = 'y'; // fourth y
-
- index += 2;
-
- // Now, copy the rest of the pattern to the destination buffer
- while (index < s.Length)
- {
- modifiedPattern[index + 2] = s[index];
- index++;
- }
-
- shortDatePatterns[0] = modifiedPattern.ToString();
-
- for (int i = 1; i < shortDatePatterns.Count; i++)
- {
- if (shortDatePatterns[i] == shortDatePatterns[0])
- {
- // Found match in the list to the new constructed pattern, then replace it with the original modified pattern
- shortDatePatterns[i] = s;
- return;
- }
- }
-
- // if we come here means the newly constructed pattern not found on the list, then add the original pattern
- shortDatePatterns.Add(s);
- }
-
- /// <summary>
- /// The ICU date format characters are not exactly the same as the .NET date format characters.
- /// NormalizeDatePattern will take in an ICU date pattern and return the equivalent .NET date pattern.
- /// </summary>
- /// <remarks>
- /// see Date Field Symbol Table in http://userguide.icu-project.org/formatparse/datetime
- /// and https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
- /// </remarks>
- private static string NormalizeDatePattern(string input)
- {
- StringBuilder destination = StringBuilderCache.Acquire(input.Length);
-
- int index = 0;
- while (index < input.Length)
- {
- switch (input[index])
- {
- case '\'':
- // single quotes escape characters, like 'de' in es-SP
- // so read verbatim until the next single quote
- destination.Append(input[index++]);
- while (index < input.Length)
- {
- char current = input[index++];
- destination.Append(current);
- if (current == '\'')
- {
- break;
- }
- }
- break;
- case 'E':
- case 'e':
- case 'c':
- // 'E' in ICU is the day of the week, which maps to 3 or 4 'd's in .NET
- // 'e' in ICU is the local day of the week, which has no representation in .NET, but
- // maps closest to 3 or 4 'd's in .NET
- // 'c' in ICU is the stand-alone day of the week, which has no representation in .NET, but
- // maps closest to 3 or 4 'd's in .NET
- NormalizeDayOfWeek(input, destination, ref index);
- break;
- case 'L':
- case 'M':
- // 'L' in ICU is the stand-alone name of the month,
- // which maps closest to 'M' in .NET since it doesn't support stand-alone month names in patterns
- // 'M' in both ICU and .NET is the month,
- // but ICU supports 5 'M's, which is the super short month name
- int occurrences = CountOccurrences(input, input[index], ref index);
- if (occurrences > 4)
- {
- // 5 'L's or 'M's in ICU is the super short name, which maps closest to MMM in .NET
- occurrences = 3;
- }
- destination.Append('M', occurrences);
- break;
- case 'G':
- // 'G' in ICU is the era, which maps to 'g' in .NET
- occurrences = CountOccurrences(input, 'G', ref index);
-
- // it doesn't matter how many 'G's, since .NET only supports 'g' or 'gg', and they
- // have the same meaning
- destination.Append('g');
- break;
- case 'y':
- // a single 'y' in ICU is the year with no padding or trimming.
- // a single 'y' in .NET is the year with 1 or 2 digits
- // so convert any single 'y' to 'yyyy'
- occurrences = CountOccurrences(input, 'y', ref index);
- if (occurrences == 1)
- {
- occurrences = 4;
- }
- destination.Append('y', occurrences);
- break;
- default:
- const string unsupportedDateFieldSymbols = "YuUrQqwWDFg";
- Debug.Assert(!unsupportedDateFieldSymbols.Contains(input[index]),
- $"Encountered an unexpected date field symbol '{input[index]}' from ICU which has no known corresponding .NET equivalent.");
-
- destination.Append(input[index++]);
- break;
- }
- }
-
- return StringBuilderCache.GetStringAndRelease(destination);
- }
-
- private static void NormalizeDayOfWeek(string input, StringBuilder destination, ref int index)
- {
- char dayChar = input[index];
- int occurrences = CountOccurrences(input, dayChar, ref index);
- occurrences = Math.Max(occurrences, 3);
- if (occurrences > 4)
- {
- // 5 and 6 E/e/c characters in ICU is the super short names, which maps closest to ddd in .NET
- occurrences = 3;
- }
-
- destination.Append('d', occurrences);
- }
-
- private static int CountOccurrences(string input, char value, ref int index)
- {
- int startIndex = index;
- while (index < input.Length && input[index] == value)
- {
- index++;
- }
-
- return index - startIndex;
- }
-
- private static bool EnumMonthNames(string localeName, CalendarId calendarId, CalendarDataType dataType, out string[]? monthNames, ref string? leapHebrewMonthName)
- {
- monthNames = null;
-
- EnumCalendarsData callbackContext = default;
- callbackContext.Results = new List<string>();
- bool result = EnumCalendarInfo(localeName, calendarId, dataType, ref callbackContext);
- if (result)
- {
- // the month-name arrays are expected to have 13 elements. If ICU only returns 12, add an
- // extra empty string to fill the array.
- if (callbackContext.Results.Count == 12)
- {
- callbackContext.Results.Add(string.Empty);
- }
-
- if (callbackContext.Results.Count > 13)
- {
- Debug.Assert(calendarId == CalendarId.HEBREW && callbackContext.Results.Count == 14);
-
- if (calendarId == CalendarId.HEBREW)
- {
- leapHebrewMonthName = callbackContext.Results[13];
- }
- callbackContext.Results.RemoveRange(13, callbackContext.Results.Count - 13);
- }
-
- monthNames = callbackContext.Results.ToArray();
- }
-
- return result;
- }
-
- private static bool EnumEraNames(string localeName, CalendarId calendarId, CalendarDataType dataType, out string[]? eraNames)
- {
- bool result = EnumCalendarInfo(localeName, calendarId, dataType, out eraNames);
-
- // .NET expects that only the Japanese calendars have more than 1 era.
- // So for other calendars, only return the latest era.
- if (calendarId != CalendarId.JAPAN && calendarId != CalendarId.JAPANESELUNISOLAR && eraNames?.Length > 0)
- {
- string[] latestEraName = new string[] { eraNames![eraNames.Length - 1] };
- eraNames = latestEraName;
- }
-
- return result;
- }
-
- internal static bool EnumCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType dataType, out string[]? calendarData)
- {
- calendarData = null;
-
- EnumCalendarsData callbackContext = default;
- callbackContext.Results = new List<string>();
- bool result = EnumCalendarInfo(localeName, calendarId, dataType, ref callbackContext);
- if (result)
- {
- calendarData = callbackContext.Results.ToArray();
- }
-
- return result;
- }
-
- private static unsafe bool EnumCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType dataType, ref EnumCalendarsData callbackContext)
- {
- return Interop.Globalization.EnumCalendarInfo(EnumCalendarInfoCallback, localeName, calendarId, dataType, (IntPtr)Unsafe.AsPointer(ref callbackContext));
- }
-
- private static unsafe void EnumCalendarInfoCallback(string calendarString, IntPtr context)
- {
- try
- {
- ref EnumCalendarsData callbackContext = ref Unsafe.As<byte, EnumCalendarsData>(ref *(byte*)context);
-
- if (callbackContext.DisallowDuplicates)
- {
- foreach (string existingResult in callbackContext.Results)
- {
- if (string.Equals(calendarString, existingResult, StringComparison.Ordinal))
- {
- // the value is already in the results, so don't add it again
- return;
- }
- }
- }
-
- callbackContext.Results.Add(calendarString);
- }
- catch (Exception e)
- {
- Debug.Fail(e.ToString());
- // we ignore the managed exceptions here because EnumCalendarInfoCallback will get called from the native code.
- // If we don't ignore the exception here that can cause the runtime to fail fast.
- }
- }
-
- private struct EnumCalendarsData
- {
- public List<string> Results;
- public bool DisallowDuplicates;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.Windows.cs
deleted file mode 100644
index 8031df90e0e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.Windows.cs
+++ /dev/null
@@ -1,448 +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 System.Diagnostics;
-using System.Collections.Generic;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Globalization
-{
- internal partial class CalendarData
- {
- private bool LoadCalendarDataFromSystem(string localeName, CalendarId calendarId)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- bool ret = true;
-
- uint useOverrides = this.bUseUserOverrides ? 0 : CAL_NOUSEROVERRIDE;
-
- //
- // Windows doesn't support some calendars right now, so remap those.
- //
- switch (calendarId)
- {
- case CalendarId.JAPANESELUNISOLAR: // Data looks like Japanese
- calendarId = CalendarId.JAPAN;
- break;
- case CalendarId.JULIAN: // Data looks like gregorian US
- case CalendarId.CHINESELUNISOLAR: // Algorithmic, so actual data is irrelevent
- case CalendarId.SAKA: // reserved to match Office but not implemented in our code, so data is irrelevent
- case CalendarId.LUNAR_ETO_CHN: // reserved to match Office but not implemented in our code, so data is irrelevent
- case CalendarId.LUNAR_ETO_KOR: // reserved to match Office but not implemented in our code, so data is irrelevent
- case CalendarId.LUNAR_ETO_ROKUYOU: // reserved to match Office but not implemented in our code, so data is irrelevent
- case CalendarId.KOREANLUNISOLAR: // Algorithmic, so actual data is irrelevent
- case CalendarId.TAIWANLUNISOLAR: // Algorithmic, so actual data is irrelevent
- calendarId = CalendarId.GREGORIAN_US;
- break;
- }
-
- //
- // Special handling for some special calendar due to OS limitation.
- // This includes calendar like Taiwan calendar, UmAlQura calendar, etc.
- //
- CheckSpecialCalendar(ref calendarId, ref localeName);
-
- // Numbers
- ret &= CallGetCalendarInfoEx(localeName, calendarId, CAL_ITWODIGITYEARMAX | useOverrides, out this.iTwoDigitYearMax);
-
- // Strings
- ret &= CallGetCalendarInfoEx(localeName, calendarId, CAL_SCALNAME, out this.sNativeName);
- ret &= CallGetCalendarInfoEx(localeName, calendarId, CAL_SMONTHDAY | useOverrides, out this.sMonthDay);
-
- // String Arrays
- // Formats
- ret &= CallEnumCalendarInfo(localeName, calendarId, CAL_SSHORTDATE, LOCALE_SSHORTDATE | useOverrides, out this.saShortDates!);
- ret &= CallEnumCalendarInfo(localeName, calendarId, CAL_SLONGDATE, LOCALE_SLONGDATE | useOverrides, out this.saLongDates!);
-
- // Get the YearMonth pattern.
- ret &= CallEnumCalendarInfo(localeName, calendarId, CAL_SYEARMONTH, LOCALE_SYEARMONTH, out this.saYearMonths!);
-
- // Day & Month Names
- // These are all single calType entries, 1 per day, so we have to make 7 or 13 calls to collect all the names
-
- // Day
- // Note that we're off-by-one since managed starts on sunday and windows starts on monday
- ret &= GetCalendarDayInfo(localeName, calendarId, CAL_SDAYNAME7, out this.saDayNames);
- ret &= GetCalendarDayInfo(localeName, calendarId, CAL_SABBREVDAYNAME7, out this.saAbbrevDayNames);
-
- // Month names
- ret &= GetCalendarMonthInfo(localeName, calendarId, CAL_SMONTHNAME1, out this.saMonthNames);
- ret &= GetCalendarMonthInfo(localeName, calendarId, CAL_SABBREVMONTHNAME1, out this.saAbbrevMonthNames);
-
- //
- // The following LCTYPE are not supported in some platforms. If the call fails,
- // don't return a failure.
- //
- GetCalendarDayInfo(localeName, calendarId, CAL_SSHORTESTDAYNAME7, out this.saSuperShortDayNames);
-
- // Gregorian may have genitive month names
- if (calendarId == CalendarId.GREGORIAN)
- {
- GetCalendarMonthInfo(localeName, calendarId, CAL_SMONTHNAME1 | CAL_RETURN_GENITIVE_NAMES, out this.saMonthGenitiveNames);
- GetCalendarMonthInfo(localeName, calendarId, CAL_SABBREVMONTHNAME1 | CAL_RETURN_GENITIVE_NAMES, out this.saAbbrevMonthGenitiveNames);
- }
-
- // Calendar Parts Names
- // This doesn't get always get localized names for gregorian (not available in windows < 7)
- // so: eg: coreclr on win < 7 won't get these
- CallEnumCalendarInfo(localeName, calendarId, CAL_SERASTRING, 0, out this.saEraNames!);
- CallEnumCalendarInfo(localeName, calendarId, CAL_SABBREVERASTRING, 0, out this.saAbbrevEraNames!);
-
- //
- // Calendar Era Info
- // Note that calendar era data (offsets, etc) is hard coded for each calendar since this
- // data is implementation specific and not dynamic (except perhaps Japanese)
- //
-
- // Clean up the escaping of the formats
- this.saShortDates = CultureData.ReescapeWin32Strings(this.saShortDates)!;
- this.saLongDates = CultureData.ReescapeWin32Strings(this.saLongDates)!;
- this.saYearMonths = CultureData.ReescapeWin32Strings(this.saYearMonths)!;
- this.sMonthDay = CultureData.ReescapeWin32String(this.sMonthDay)!;
-
- return ret;
- }
-
- // Get native two digit year max
- internal static int GetTwoDigitYearMax(CalendarId calendarId) =>
- GlobalizationMode.Invariant ? Invariant.iTwoDigitYearMax :
- CallGetCalendarInfoEx(null, calendarId, CAL_ITWODIGITYEARMAX, out int twoDigitYearMax) ? twoDigitYearMax :
- -1;
-
- // Call native side to figure out which calendars are allowed
- internal static int GetCalendars(string localeName, bool useUserOverride, CalendarId[] calendars)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- EnumCalendarsData data = default;
- data.userOverride = 0;
- data.calendars = new List<int>();
-
- // First call GetLocaleInfo if necessary
- if (useUserOverride)
- {
- // They want user overrides, see if the user calendar matches the input calendar
- int userCalendar = CultureData.GetLocaleInfoExInt(localeName, LOCALE_ICALENDARTYPE);
-
- // If we got a default, then use it as the first calendar
- if (userCalendar != 0)
- {
- data.userOverride = userCalendar;
- data.calendars.Add(userCalendar);
- }
- }
-
- unsafe
- {
- Interop.Kernel32.EnumCalendarInfoExEx(EnumCalendarsCallback, localeName, ENUM_ALL_CALENDARS, null, CAL_ICALINTVALUE, Unsafe.AsPointer(ref data));
- }
-
- // Copy to the output array
- for (int i = 0; i < Math.Min(calendars.Length, data.calendars.Count); i++)
- calendars[i] = (CalendarId)data.calendars[i];
-
- // Now we have a list of data, return the count
- return data.calendars.Count;
- }
-
- private static bool SystemSupportsTaiwaneseCalendar()
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- // Taiwanese calendar get listed as one of the optional zh-TW calendars only when having zh-TW UI
- return CallGetCalendarInfoEx("zh-TW", CalendarId.TAIWAN, CAL_SCALNAME, out string _);
- }
-
- // PAL Layer ends here
-
- private const uint CAL_RETURN_NUMBER = 0x20000000;
- private const uint CAL_RETURN_GENITIVE_NAMES = 0x10000000;
- private const uint CAL_NOUSEROVERRIDE = 0x80000000;
- private const uint CAL_SCALNAME = 0x00000002;
- private const uint CAL_SMONTHDAY = 0x00000038;
- private const uint CAL_SSHORTDATE = 0x00000005;
- private const uint CAL_SLONGDATE = 0x00000006;
- private const uint CAL_SYEARMONTH = 0x0000002f;
- private const uint CAL_SDAYNAME7 = 0x0000000d;
- private const uint CAL_SABBREVDAYNAME7 = 0x00000014;
- private const uint CAL_SMONTHNAME1 = 0x00000015;
- private const uint CAL_SABBREVMONTHNAME1 = 0x00000022;
- private const uint CAL_SSHORTESTDAYNAME7 = 0x00000037;
- private const uint CAL_SERASTRING = 0x00000004;
- private const uint CAL_SABBREVERASTRING = 0x00000039;
- private const uint CAL_ICALINTVALUE = 0x00000001;
- private const uint CAL_ITWODIGITYEARMAX = 0x00000030;
-
- private const uint ENUM_ALL_CALENDARS = 0xffffffff;
-
- private const uint LOCALE_SSHORTDATE = 0x0000001F;
- private const uint LOCALE_SLONGDATE = 0x00000020;
- private const uint LOCALE_SYEARMONTH = 0x00001006;
- private const uint LOCALE_ICALENDARTYPE = 0x00001009;
-
- ////////////////////////////////////////////////////////////////////////
- //
- // For calendars like Gregorain US/Taiwan/UmAlQura, they are not available
- // in all OS or all localized versions of OS.
- // If OS does not support these calendars, we will fallback by using the
- // appropriate fallback calendar and locale combination to retrieve data from OS.
- //
- // Parameters:
- // __deref_inout pCalendarInt:
- // Pointer to the calendar ID. This will be updated to new fallback calendar ID if needed.
- // __in_out pLocaleNameStackBuffer
- // Pointer to the StackSString object which holds the locale name to be checked.
- // This will be updated to new fallback locale name if needed.
- //
- ////////////////////////////////////////////////////////////////////////
- private static void CheckSpecialCalendar(ref CalendarId calendar, ref string localeName)
- {
- // Gregorian-US isn't always available in the OS, however it is the same for all locales
- switch (calendar)
- {
- case CalendarId.GREGORIAN_US:
- // See if this works
- if (!CallGetCalendarInfoEx(localeName, calendar, CAL_SCALNAME, out string _))
- {
- // Failed, set it to a locale (fa-IR) that's alway has Gregorian US available in the OS
- localeName = "fa-IR";
- }
- // See if that works
- if (!CallGetCalendarInfoEx(localeName, calendar, CAL_SCALNAME, out string _))
- {
- // Failed again, just use en-US with the gregorian calendar
- localeName = "en-US";
- calendar = CalendarId.GREGORIAN;
- }
- break;
- case CalendarId.TAIWAN:
- // Taiwan calendar data is not always in all language version of OS due to Geopolical reasons.
- // It is only available in zh-TW localized versions of Windows.
- // Let's check if OS supports it. If not, fallback to Greogrian localized for Taiwan calendar.
- if (!SystemSupportsTaiwaneseCalendar())
- {
- calendar = CalendarId.GREGORIAN;
- }
- break;
- }
- }
-
- private static bool CallGetCalendarInfoEx(string? localeName, CalendarId calendar, uint calType, out int data)
- {
- return Interop.Kernel32.GetCalendarInfoEx(localeName, (uint)calendar, IntPtr.Zero, calType | CAL_RETURN_NUMBER, IntPtr.Zero, 0, out data) != 0;
- }
-
- private static unsafe bool CallGetCalendarInfoEx(string localeName, CalendarId calendar, uint calType, out string data)
- {
- const int BUFFER_LENGTH = 80;
-
- // The maximum size for values returned from GetCalendarInfoEx is 80 characters.
- char* buffer = stackalloc char[BUFFER_LENGTH];
-
- int ret = Interop.Kernel32.GetCalendarInfoEx(localeName, (uint)calendar, IntPtr.Zero, calType, (IntPtr)buffer, BUFFER_LENGTH, IntPtr.Zero);
- if (ret > 0)
- {
- if (buffer[ret - 1] == '\0')
- {
- ret--; // don't include the null termination in the string
- }
- data = new string(buffer, 0, ret);
- return true;
- }
- data = "";
- return false;
- }
-
- // Context for EnumCalendarInfoExEx callback.
- private struct EnumData
- {
- public string? userOverride;
- public List<string>? strings;
- }
-
- // EnumCalendarInfoExEx callback itself.
- // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
- private static unsafe Interop.BOOL EnumCalendarInfoCallback(char* lpCalendarInfoString, uint calendar, IntPtr pReserved, void* lParam)
- {
- ref EnumData context = ref Unsafe.As<byte, EnumData>(ref *(byte*)lParam);
- try
- {
- string calendarInfo = new string(lpCalendarInfoString);
-
- // If we had a user override, check to make sure this differs
- if (context.userOverride != calendarInfo)
- {
- Debug.Assert(context.strings != null);
- context.strings.Add(calendarInfo);
- }
-
- return Interop.BOOL.TRUE;
- }
- catch (Exception)
- {
- return Interop.BOOL.FALSE;
- }
- }
-
- private static unsafe bool CallEnumCalendarInfo(string localeName, CalendarId calendar, uint calType, uint lcType, out string[]? data)
- {
- EnumData context = default;
- context.userOverride = null;
- context.strings = new List<string>();
- // First call GetLocaleInfo if necessary
- if ((lcType != 0) && ((lcType & CAL_NOUSEROVERRIDE) == 0) &&
- // Get user locale, see if it matches localeName.
- // Note that they should match exactly, including letter case
- GetUserDefaultLocaleName() == localeName)
- {
- // They want user overrides, see if the user calendar matches the input calendar
- CalendarId userCalendar = (CalendarId)CultureData.GetLocaleInfoExInt(localeName, LOCALE_ICALENDARTYPE);
-
- // If the calendars were the same, see if the locales were the same
- if (userCalendar == calendar)
- {
- // They matched, get the user override since locale & calendar match
- string? res = CultureData.GetLocaleInfoEx(localeName, lcType);
-
- // if it succeeded remember the override for the later callers
- if (res != null)
- {
- // Remember this was the override (so we can look for duplicates later in the enum function)
- context.userOverride = res;
-
- // Add to the result strings.
- context.strings.Add(res);
- }
- }
- }
-
- // Now call the enumeration API. Work is done by our callback function
- Interop.Kernel32.EnumCalendarInfoExEx(EnumCalendarInfoCallback, localeName, (uint)calendar, null, calType, Unsafe.AsPointer(ref context));
-
- // Now we have a list of data, fail if we didn't find anything.
- Debug.Assert(context.strings != null);
- if (context.strings.Count == 0)
- {
- data = null;
- return false;
- }
-
- string[] output = context.strings.ToArray();
-
- if (calType == CAL_SABBREVERASTRING || calType == CAL_SERASTRING)
- {
- // Eras are enumerated backwards. (oldest era name first, but
- // Japanese calendar has newest era first in array, and is only
- // calendar with multiple eras)
- Array.Reverse(output, 0, output.Length);
- }
-
- data = output;
-
- return true;
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Get the native day names
- //
- // NOTE: There's a disparity between .NET & windows day orders, the input day should
- // start with Sunday
- //
- // Parameters:
- // OUT pOutputStrings The output string[] value.
- //
- ////////////////////////////////////////////////////////////////////////
- private static bool GetCalendarDayInfo(string localeName, CalendarId calendar, uint calType, out string[] outputStrings)
- {
- bool result = true;
-
- //
- // We'll need a new array of 7 items
- //
- string[] results = new string[7];
-
- // Get each one of them
- for (int i = 0; i < 7; i++, calType++)
- {
- result &= CallGetCalendarInfoEx(localeName, calendar, calType, out results[i]);
-
- // On the first iteration we need to go from CAL_SDAYNAME7 to CAL_SDAYNAME1, so subtract 7 before the ++ happens
- // This is because the framework starts on sunday and windows starts on monday when counting days
- if (i == 0)
- calType -= 7;
- }
-
- outputStrings = results;
-
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Get the native month names
- //
- // Parameters:
- // OUT pOutputStrings The output string[] value.
- //
- ////////////////////////////////////////////////////////////////////////
- private static bool GetCalendarMonthInfo(string localeName, CalendarId calendar, uint calType, out string[] outputStrings)
- {
- //
- // We'll need a new array of 13 items
- //
- string[] results = new string[13];
-
- // Get each one of them
- for (int i = 0; i < 13; i++, calType++)
- {
- if (!CallGetCalendarInfoEx(localeName, calendar, calType, out results[i]))
- results[i] = "";
- }
-
- outputStrings = results;
-
- return true;
- }
-
- //
- // struct to help our calendar data enumaration callback
- //
- private struct EnumCalendarsData
- {
- public int userOverride; // user override value (if found)
- public List<int> calendars; // list of calendars found so far
- }
-
- // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
- private static unsafe Interop.BOOL EnumCalendarsCallback(char* lpCalendarInfoString, uint calendar, IntPtr reserved, void* lParam)
- {
- ref EnumCalendarsData context = ref Unsafe.As<byte, EnumCalendarsData>(ref *(byte*)lParam);
- try
- {
- // If we had a user override, check to make sure this differs
- if (context.userOverride != calendar)
- context.calendars.Add((int)calendar);
-
- return Interop.BOOL.TRUE;
- }
- catch (Exception)
- {
- return Interop.BOOL.FALSE;
- }
- }
-
- private static unsafe string GetUserDefaultLocaleName()
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- int result;
- char* localeName = stackalloc char[Interop.Kernel32.LOCALE_NAME_MAX_LENGTH];
- result = CultureData.GetLocaleInfoEx(Interop.Kernel32.LOCALE_NAME_USER_DEFAULT, Interop.Kernel32.LOCALE_SNAME, localeName, Interop.Kernel32.LOCALE_NAME_MAX_LENGTH);
-
- return result <= 0 ? "" : new string(localeName, 0, result - 1); // exclude the null termination
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.cs
deleted file mode 100644
index 997cfb406e4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarData.cs
+++ /dev/null
@@ -1,380 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- // List of calendar data
- // Note the we cache overrides.
- // Note that localized names (resource names) aren't available from here.
- //
- // NOTE: Calendars depend on the locale name that creates it. Only a few
- // properties are available without locales using CalendarData.GetCalendar(CalendarData)
- //
- internal partial class CalendarData
- {
- // Max calendars
- internal const int MAX_CALENDARS = 23;
-
- // Identity
- internal string sNativeName = null!; // Calendar Name for the locale
-
- // Formats
- internal string[] saShortDates = null!; // Short Data format, default first
- internal string[] saYearMonths = null!; // Year/Month Data format, default first
- internal string[] saLongDates = null!; // Long Data format, default first
- internal string sMonthDay = null!; // Month/Day format
-
- // Calendar Parts Names
- internal string[] saEraNames = null!; // Names of Eras
- internal string[] saAbbrevEraNames = null!; // Abbreviated Era Names
- internal string[] saAbbrevEnglishEraNames = null!; // Abbreviated Era Names in English
- internal string[] saDayNames = null!; // Day Names, null to use locale data, starts on Sunday
- internal string[] saAbbrevDayNames = null!; // Abbrev Day Names, null to use locale data, starts on Sunday
- internal string[] saSuperShortDayNames = null!; // Super short Day of week names
- internal string[] saMonthNames = null!; // Month Names (13)
- internal string[] saAbbrevMonthNames = null!; // Abbrev Month Names (13)
- internal string[] saMonthGenitiveNames = null!; // Genitive Month Names (13)
- internal string[] saAbbrevMonthGenitiveNames = null!; // Genitive Abbrev Month Names (13)
- internal string[] saLeapYearMonthNames = null!; // Multiple strings for the month names in a leap year.
-
- // Integers at end to make marshaller happier
- internal int iTwoDigitYearMax = 2029; // Max 2 digit year (for Y2K bug data entry)
- internal int iCurrentEra = 0; // current era # (usually 1)
-
- // Use overrides?
- internal bool bUseUserOverrides; // True if we want user overrides.
-
- // Static invariant for the invariant locale
- internal static readonly CalendarData Invariant = CreateInvariant();
-
- // Private constructor
- private CalendarData()
- {
- }
-
- // Invariant factory
- private static CalendarData CreateInvariant()
- {
- // Set our default/gregorian US calendar data
- // Calendar IDs are 1-based, arrays are 0 based.
- CalendarData invariant = new CalendarData();
-
- // Set default data for calendar
- // Note that we don't load resources since this IS NOT supposed to change (by definition)
- invariant.sNativeName = "Gregorian Calendar"; // Calendar Name
-
- // Year
- invariant.iTwoDigitYearMax = 2029; // Max 2 digit year (for Y2K bug data entry)
- invariant.iCurrentEra = 1; // Current era #
-
- // Formats
- invariant.saShortDates = new string[] { "MM/dd/yyyy", "yyyy-MM-dd" }; // short date format
- invariant.saLongDates = new string[] { "dddd, dd MMMM yyyy" }; // long date format
- invariant.saYearMonths = new string[] { "yyyy MMMM" }; // year month format
- invariant.sMonthDay = "MMMM dd"; // Month day pattern
-
- // Calendar Parts Names
- invariant.saEraNames = new string[] { "A.D." }; // Era names
- invariant.saAbbrevEraNames = new string[] { "AD" }; // Abbreviated Era names
- invariant.saAbbrevEnglishEraNames = new string[] { "AD" }; // Abbreviated era names in English
- invariant.saDayNames = new string[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; // day names
- invariant.saAbbrevDayNames = new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; // abbreviated day names
- invariant.saSuperShortDayNames = new string[] { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" }; // The super short day names
- invariant.saMonthNames = new string[] { "January", "February", "March", "April", "May", "June",
- "July", "August", "September", "October", "November", "December", string.Empty }; // month names
- invariant.saAbbrevMonthNames = new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", string.Empty }; // abbreviated month names
- invariant.saMonthGenitiveNames = invariant.saMonthNames; // Genitive month names (same as month names for invariant)
- invariant.saAbbrevMonthGenitiveNames = invariant.saAbbrevMonthNames; // Abbreviated genitive month names (same as abbrev month names for invariant)
- invariant.saLeapYearMonthNames = invariant.saMonthNames; // leap year month names are unused in Gregorian English (invariant)
-
- invariant.bUseUserOverrides = false;
-
- return invariant;
- }
-
- //
- // Get a bunch of data for a calendar
- //
- internal CalendarData(string localeName, CalendarId calendarId, bool bUseUserOverrides)
- {
- this.bUseUserOverrides = bUseUserOverrides;
-
- Debug.Assert(!GlobalizationMode.Invariant);
-
- if (!LoadCalendarDataFromSystem(localeName, calendarId))
- {
- // LoadCalendarDataFromSystem sometimes can fail on Linux if the installed ICU package is missing some resources.
- // The ICU package can miss some resources in some cases like if someone compile and build the ICU package manually or ICU has a regression.
-
- // Something failed, try invariant for missing parts
- // This is really not good, but we don't want the callers to crash.
- this.sNativeName ??= string.Empty; // Calendar Name for the locale.
-
- // Formats
- this.saShortDates ??= Invariant.saShortDates; // Short Data format, default first
- this.saYearMonths ??= Invariant.saYearMonths; // Year/Month Data format, default first
- this.saLongDates ??= Invariant.saLongDates; // Long Data format, default first
- this.sMonthDay ??= Invariant.sMonthDay; // Month/Day format
-
- // Calendar Parts Names
- this.saEraNames ??= Invariant.saEraNames; // Names of Eras
- this.saAbbrevEraNames ??= Invariant.saAbbrevEraNames; // Abbreviated Era Names
- this.saAbbrevEnglishEraNames ??= Invariant.saAbbrevEnglishEraNames; // Abbreviated Era Names in English
- this.saDayNames ??= Invariant.saDayNames; // Day Names, null to use locale data, starts on Sunday
- this.saAbbrevDayNames ??= Invariant.saAbbrevDayNames; // Abbrev Day Names, null to use locale data, starts on Sunday
- this.saSuperShortDayNames ??= Invariant.saSuperShortDayNames; // Super short Day of week names
- this.saMonthNames ??= Invariant.saMonthNames; // Month Names (13)
- this.saAbbrevMonthNames ??= Invariant.saAbbrevMonthNames; // Abbrev Month Names (13)
- // Genitive and Leap names can follow the fallback below
- }
-
- if (calendarId == CalendarId.TAIWAN)
- {
- if (SystemSupportsTaiwaneseCalendar())
- {
- // We got the month/day names from the OS (same as gregorian), but the native name is wrong
- this.sNativeName = "\x4e2d\x83ef\x6c11\x570b\x66c6";
- }
- else
- {
- this.sNativeName = string.Empty;
- }
- }
-
- // Check for null genitive names (in case unmanaged side skips it for non-gregorian calendars, etc)
- if (this.saMonthGenitiveNames == null || this.saMonthGenitiveNames.Length == 0 || string.IsNullOrEmpty(this.saMonthGenitiveNames[0]))
- this.saMonthGenitiveNames = this.saMonthNames; // Genitive month names (same as month names for invariant)
- if (this.saAbbrevMonthGenitiveNames == null || this.saAbbrevMonthGenitiveNames.Length == 0 || string.IsNullOrEmpty(this.saAbbrevMonthGenitiveNames[0]))
- this.saAbbrevMonthGenitiveNames = this.saAbbrevMonthNames; // Abbreviated genitive month names (same as abbrev month names for invariant)
- if (this.saLeapYearMonthNames == null || this.saLeapYearMonthNames.Length == 0 || string.IsNullOrEmpty(this.saLeapYearMonthNames[0]))
- this.saLeapYearMonthNames = this.saMonthNames;
-
- InitializeEraNames(localeName, calendarId);
-
- InitializeAbbreviatedEraNames(localeName, calendarId);
-
- // Abbreviated English Era Names are only used for the Japanese calendar.
- if (calendarId == CalendarId.JAPAN)
- {
- this.saAbbrevEnglishEraNames = JapaneseCalendar.EnglishEraNames();
- }
- else
- {
- // For all others just use the an empty string (doesn't matter we'll never ask for it for other calendars)
- this.saAbbrevEnglishEraNames = new string[] { "" };
- }
-
- // Japanese is the only thing with > 1 era. Its current era # is how many ever
- // eras are in the array. (And the others all have 1 string in the array)
- this.iCurrentEra = this.saEraNames.Length;
- }
-
- private void InitializeEraNames(string localeName, CalendarId calendarId)
- {
- // Note that the saEraNames only include "A.D." We don't have localized names for other calendars available from windows
- switch (calendarId)
- {
- // For Localized Gregorian we really expect the data from the OS.
- case CalendarId.GREGORIAN:
- // Fallback for CoreCLR < Win7 or culture.dll missing
- if (this.saEraNames == null || this.saEraNames.Length == 0 || string.IsNullOrEmpty(this.saEraNames[0]))
- {
- this.saEraNames = new string[] { "A.D." };
- }
- break;
-
- // The rest of the calendars have constant data, so we'll just use that
- case CalendarId.GREGORIAN_US:
- case CalendarId.JULIAN:
- this.saEraNames = new string[] { "A.D." };
- break;
- case CalendarId.HEBREW:
- this.saEraNames = new string[] { "C.E." };
- break;
- case CalendarId.HIJRI:
- case CalendarId.UMALQURA:
- if (localeName == "dv-MV")
- {
- // Special case for Divehi
- this.saEraNames = new string[] { "\x0780\x07a8\x0796\x07b0\x0783\x07a9" };
- }
- else
- {
- this.saEraNames = new string[] { "\x0628\x0639\x062F \x0627\x0644\x0647\x062C\x0631\x0629" };
- }
- break;
- case CalendarId.GREGORIAN_ARABIC:
- case CalendarId.GREGORIAN_XLIT_ENGLISH:
- case CalendarId.GREGORIAN_XLIT_FRENCH:
- // These are all the same:
- this.saEraNames = new string[] { "\x0645" };
- break;
-
- case CalendarId.GREGORIAN_ME_FRENCH:
- this.saEraNames = new string[] { "ap. J.-C." };
- break;
-
- case CalendarId.TAIWAN:
- if (SystemSupportsTaiwaneseCalendar())
- {
- this.saEraNames = new string[] { "\x4e2d\x83ef\x6c11\x570b" };
- }
- else
- {
- this.saEraNames = new string[] { string.Empty };
- }
- break;
-
- case CalendarId.KOREA:
- this.saEraNames = new string[] { "\xb2e8\xae30" };
- break;
-
- case CalendarId.THAI:
- this.saEraNames = new string[] { "\x0e1e\x002e\x0e28\x002e" };
- break;
-
- case CalendarId.JAPAN:
- case CalendarId.JAPANESELUNISOLAR:
- this.saEraNames = JapaneseCalendar.EraNames();
- break;
-
- case CalendarId.PERSIAN:
- if (this.saEraNames == null || this.saEraNames.Length == 0 || string.IsNullOrEmpty(this.saEraNames[0]))
- {
- this.saEraNames = new string[] { "\x0647\x002e\x0634" };
- }
- break;
-
- default:
- // Most calendars are just "A.D."
- this.saEraNames = Invariant.saEraNames;
- break;
- }
- }
-
- private void InitializeAbbreviatedEraNames(string localeName, CalendarId calendarId)
- {
- // Note that the saAbbrevEraNames only include "AD" We don't have localized names for other calendars available from windows
- switch (calendarId)
- {
- // For Localized Gregorian we really expect the data from the OS.
- case CalendarId.GREGORIAN:
- // Fallback for CoreCLR < Win7 or culture.dll missing
- if (this.saAbbrevEraNames == null || this.saAbbrevEraNames.Length == 0 || string.IsNullOrEmpty(this.saAbbrevEraNames[0]))
- {
- this.saAbbrevEraNames = new string[] { "AD" };
- }
- break;
-
- // The rest of the calendars have constant data, so we'll just use that
- case CalendarId.GREGORIAN_US:
- case CalendarId.JULIAN:
- this.saAbbrevEraNames = new string[] { "AD" };
- break;
- case CalendarId.JAPAN:
- case CalendarId.JAPANESELUNISOLAR:
- this.saAbbrevEraNames = JapaneseCalendar.AbbrevEraNames();
- break;
- case CalendarId.HIJRI:
- case CalendarId.UMALQURA:
- if (localeName == "dv-MV")
- {
- // Special case for Divehi
- this.saAbbrevEraNames = new string[] { "\x0780\x002e" };
- }
- else
- {
- this.saAbbrevEraNames = new string[] { "\x0647\x0640" };
- }
- break;
- case CalendarId.TAIWAN:
- // Get era name and abbreviate it
- this.saAbbrevEraNames = new string[1];
- if (this.saEraNames[0].Length == 4)
- {
- this.saAbbrevEraNames[0] = this.saEraNames[0].Substring(2, 2);
- }
- else
- {
- this.saAbbrevEraNames[0] = this.saEraNames[0];
- }
- break;
-
- case CalendarId.PERSIAN:
- if (this.saAbbrevEraNames == null || this.saAbbrevEraNames.Length == 0 || string.IsNullOrEmpty(this.saAbbrevEraNames[0]))
- {
- this.saAbbrevEraNames = this.saEraNames;
- }
- break;
-
- default:
- // Most calendars just use the full name
- this.saAbbrevEraNames = this.saEraNames;
- break;
- }
- }
-
- internal static CalendarData GetCalendarData(CalendarId calendarId)
- {
- //
- // Get a calendar.
- // Unfortunately we depend on the locale in the OS, so we need a locale
- // no matter what. So just get the appropriate calendar from the
- // appropriate locale here
- //
-
- // Get a culture name
- // TODO: Note that this doesn't handle the new calendars (lunisolar, etc)
- string culture = CalendarIdToCultureName(calendarId);
-
- // Return our calendar
- return CultureInfo.GetCultureInfo(culture)._cultureData.GetCalendar(calendarId);
- }
-
- private static string CalendarIdToCultureName(CalendarId calendarId)
- {
- switch (calendarId)
- {
- case CalendarId.GREGORIAN_US:
- return "fa-IR"; // "fa-IR" Iran
-
- case CalendarId.JAPAN:
- return "ja-JP"; // "ja-JP" Japan
-
- case CalendarId.TAIWAN:
- return "zh-TW"; // zh-TW Taiwan
-
- case CalendarId.KOREA:
- return "ko-KR"; // "ko-KR" Korea
-
- case CalendarId.HIJRI:
- case CalendarId.GREGORIAN_ARABIC:
- case CalendarId.UMALQURA:
- return "ar-SA"; // "ar-SA" Saudi Arabia
-
- case CalendarId.THAI:
- return "th-TH"; // "th-TH" Thailand
-
- case CalendarId.HEBREW:
- return "he-IL"; // "he-IL" Israel
-
- case CalendarId.GREGORIAN_ME_FRENCH:
- return "ar-DZ"; // "ar-DZ" Algeria
-
- case CalendarId.GREGORIAN_XLIT_ENGLISH:
- case CalendarId.GREGORIAN_XLIT_FRENCH:
- return "ar-IQ"; // "ar-IQ"; Iraq
-
- default:
- // Default to gregorian en-US
- break;
- }
-
- return "en-US";
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarWeekRule.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarWeekRule.cs
deleted file mode 100644
index 13567afba1a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendarWeekRule.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System.Globalization
-{
- public enum CalendarWeekRule
- {
- FirstDay = 0, // Week 1 begins on the first day of the year
-
- FirstFullWeek = 1, // Week 1 begins on first FirstDayOfWeek not before the first day of the year
-
- FirstFourDayWeek = 2 // Week 1 begins on first FirstDayOfWeek such that FirstDayOfWeek+3 is not before the first day of the year
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendricalCalculationsHelper.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CalendricalCalculationsHelper.cs
deleted file mode 100644
index 99caf6ba1d1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CalendricalCalculationsHelper.cs
+++ /dev/null
@@ -1,412 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- internal static class CalendricalCalculationsHelper
- {
- private const double FullCircleOfArc = 360.0; // 360.0;
- private const int HalfCircleOfArc = 180;
- private const double TwelveHours = 0.5; // half a day
- private const double Noon2000Jan01 = 730120.5;
- internal const double MeanTropicalYearInDays = 365.242189;
- private const double MeanSpeedOfSun = MeanTropicalYearInDays / FullCircleOfArc;
- private const double LongitudeSpring = 0.0;
- private const double TwoDegreesAfterSpring = 2.0;
- private const int SecondsPerDay = 24 * 60 * 60; // 24 hours * 60 minutes * 60 seconds
-
- private const int DaysInUniformLengthCentury = 36525;
- private const int SecondsPerMinute = 60;
- private const int MinutesPerDegree = 60;
-
- private static readonly long s_startOf1810 = GetNumberOfDays(new DateTime(1810, 1, 1));
- private static readonly long s_startOf1900Century = GetNumberOfDays(new DateTime(1900, 1, 1));
-
- private static readonly double[] s_coefficients1900to1987 = new double[] { -0.00002, 0.000297, 0.025184, -0.181133, 0.553040, -0.861938, 0.677066, -0.212591 };
- private static readonly double[] s_coefficients1800to1899 = new double[] { -0.000009, 0.003844, 0.083563, 0.865736, 4.867575, 15.845535, 31.332267, 38.291999, 28.316289, 11.636204, 2.043794 };
- private static readonly double[] s_coefficients1700to1799 = new double[] { 8.118780842, -0.005092142, 0.003336121, -0.0000266484 };
- private static readonly double[] s_coefficients1620to1699 = new double[] { 196.58333, -4.0675, 0.0219167 };
- private static readonly double[] s_lambdaCoefficients = new double[] { 280.46645, 36000.76983, 0.0003032 };
- private static readonly double[] s_anomalyCoefficients = new double[] { 357.52910, 35999.05030, -0.0001559, -0.00000048 };
- private static readonly double[] s_eccentricityCoefficients = new double[] { 0.016708617, -0.000042037, -0.0000001236 };
- private static readonly double[] s_coefficients = new double[] { Angle(23, 26, 21.448), Angle(0, 0, -46.8150), Angle(0, 0, -0.00059), Angle(0, 0, 0.001813) };
- private static readonly double[] s_coefficientsA = new double[] { 124.90, -1934.134, 0.002063 };
- private static readonly double[] s_coefficientsB = new double[] { 201.11, 72001.5377, 0.00057 };
-
- private static double RadiansFromDegrees(double degree)
- {
- return degree * Math.PI / 180;
- }
-
- private static double SinOfDegree(double degree)
- {
- return Math.Sin(RadiansFromDegrees(degree));
- }
-
- private static double CosOfDegree(double degree)
- {
- return Math.Cos(RadiansFromDegrees(degree));
- }
- private static double TanOfDegree(double degree)
- {
- return Math.Tan(RadiansFromDegrees(degree));
- }
-
- public static double Angle(int degrees, int minutes, double seconds)
- {
- return ((seconds / SecondsPerMinute + minutes) / MinutesPerDegree) + degrees;
- }
-
- private static double Obliquity(double julianCenturies)
- {
- return PolynomialSum(s_coefficients, julianCenturies);
- }
-
- internal static long GetNumberOfDays(DateTime date)
- {
- return date.Ticks / GregorianCalendar.TicksPerDay;
- }
-
- private static int GetGregorianYear(double numberOfDays)
- {
- return new DateTime(Math.Min((long)(Math.Floor(numberOfDays) * GregorianCalendar.TicksPerDay), DateTime.MaxValue.Ticks)).Year;
- }
-
- private enum CorrectionAlgorithm
- {
- Default,
- Year1988to2019,
- Year1900to1987,
- Year1800to1899,
- Year1700to1799,
- Year1620to1699
- }
-
- private struct EphemerisCorrectionAlgorithmMap
- {
- public EphemerisCorrectionAlgorithmMap(int year, CorrectionAlgorithm algorithm)
- {
- _lowestYear = year;
- _algorithm = algorithm;
- }
-
- internal int _lowestYear;
- internal CorrectionAlgorithm _algorithm;
- }
-
- private static readonly EphemerisCorrectionAlgorithmMap[] s_ephemerisCorrectionTable = new EphemerisCorrectionAlgorithmMap[]
- {
- // lowest year that starts algorithm, algorithm to use
- new EphemerisCorrectionAlgorithmMap(2020, CorrectionAlgorithm.Default),
- new EphemerisCorrectionAlgorithmMap(1988, CorrectionAlgorithm.Year1988to2019),
- new EphemerisCorrectionAlgorithmMap(1900, CorrectionAlgorithm.Year1900to1987),
- new EphemerisCorrectionAlgorithmMap(1800, CorrectionAlgorithm.Year1800to1899),
- new EphemerisCorrectionAlgorithmMap(1700, CorrectionAlgorithm.Year1700to1799),
- new EphemerisCorrectionAlgorithmMap(1620, CorrectionAlgorithm.Year1620to1699),
- new EphemerisCorrectionAlgorithmMap(int.MinValue, CorrectionAlgorithm.Default) // default must be last
- };
-
- private static double Reminder(double divisor, double dividend)
- {
- double whole = Math.Floor(divisor / dividend);
- return divisor - (dividend * whole);
- }
-
- private static double NormalizeLongitude(double longitude)
- {
- longitude = Reminder(longitude, FullCircleOfArc);
- if (longitude < 0)
- {
- longitude += FullCircleOfArc;
- }
- return longitude;
- }
-
- public static double AsDayFraction(double longitude)
- {
- return longitude / FullCircleOfArc;
- }
-
- private static double PolynomialSum(double[] coefficients, double indeterminate)
- {
- double sum = coefficients[0];
- double indeterminateRaised = 1;
- for (int i = 1; i < coefficients.Length; i++)
- {
- indeterminateRaised *= indeterminate;
- sum += (coefficients[i] * indeterminateRaised);
- }
-
- return sum;
- }
-
- private static double CenturiesFrom1900(int gregorianYear)
- {
- long july1stOfYear = GetNumberOfDays(new DateTime(gregorianYear, 7, 1));
- return (double)(july1stOfYear - s_startOf1900Century) / DaysInUniformLengthCentury;
- }
-
- // the following formulas defines a polynomial function which gives us the amount that the earth is slowing down for specific year ranges
- private static double DefaultEphemerisCorrection(int gregorianYear)
- {
- Debug.Assert(gregorianYear < 1620 || 2020 <= gregorianYear);
- long january1stOfYear = GetNumberOfDays(new DateTime(gregorianYear, 1, 1));
- double daysSinceStartOf1810 = january1stOfYear - s_startOf1810;
- double x = TwelveHours + daysSinceStartOf1810;
- return ((Math.Pow(x, 2) / 41048480) - 15) / SecondsPerDay;
- }
-
- private static double EphemerisCorrection1988to2019(int gregorianYear)
- {
- Debug.Assert(1988 <= gregorianYear && gregorianYear <= 2019);
- return (double)(gregorianYear - 1933) / SecondsPerDay;
- }
-
- private static double EphemerisCorrection1900to1987(int gregorianYear)
- {
- Debug.Assert(1900 <= gregorianYear && gregorianYear <= 1987);
- double centuriesFrom1900 = CenturiesFrom1900(gregorianYear);
- return PolynomialSum(s_coefficients1900to1987, centuriesFrom1900);
- }
-
- private static double EphemerisCorrection1800to1899(int gregorianYear)
- {
- Debug.Assert(1800 <= gregorianYear && gregorianYear <= 1899);
- double centuriesFrom1900 = CenturiesFrom1900(gregorianYear);
- return PolynomialSum(s_coefficients1800to1899, centuriesFrom1900);
- }
-
- private static double EphemerisCorrection1700to1799(int gregorianYear)
- {
- Debug.Assert(1700 <= gregorianYear && gregorianYear <= 1799);
- double yearsSince1700 = gregorianYear - 1700;
- return PolynomialSum(s_coefficients1700to1799, yearsSince1700) / SecondsPerDay;
- }
-
- private static double EphemerisCorrection1620to1699(int gregorianYear)
- {
- Debug.Assert(1620 <= gregorianYear && gregorianYear <= 1699);
- double yearsSince1600 = gregorianYear - 1600;
- return PolynomialSum(s_coefficients1620to1699, yearsSince1600) / SecondsPerDay;
- }
-
- // ephemeris-correction: correction to account for the slowing down of the rotation of the earth
- private static double EphemerisCorrection(double time)
- {
- int year = GetGregorianYear(time);
- foreach (EphemerisCorrectionAlgorithmMap map in s_ephemerisCorrectionTable)
- {
- if (map._lowestYear <= year)
- {
- switch (map._algorithm)
- {
- case CorrectionAlgorithm.Default: return DefaultEphemerisCorrection(year);
- case CorrectionAlgorithm.Year1988to2019: return EphemerisCorrection1988to2019(year);
- case CorrectionAlgorithm.Year1900to1987: return EphemerisCorrection1900to1987(year);
- case CorrectionAlgorithm.Year1800to1899: return EphemerisCorrection1800to1899(year);
- case CorrectionAlgorithm.Year1700to1799: return EphemerisCorrection1700to1799(year);
- case CorrectionAlgorithm.Year1620to1699: return EphemerisCorrection1620to1699(year);
- }
-
- break; // break the loop and assert eventually
- }
- }
-
- Debug.Fail("Not expected to come here");
- return DefaultEphemerisCorrection(year);
- }
-
- public static double JulianCenturies(double moment)
- {
- double dynamicalMoment = moment + EphemerisCorrection(moment);
- return (dynamicalMoment - Noon2000Jan01) / DaysInUniformLengthCentury;
- }
-
- private static bool IsNegative(double value)
- {
- return Math.Sign(value) == -1;
- }
-
- private static double CopySign(double value, double sign)
- {
- return (IsNegative(value) == IsNegative(sign)) ? value : -value;
- }
-
- // equation-of-time; approximate the difference between apparent solar time and mean solar time
- // formal definition is EOT = GHA - GMHA
- // GHA is the Greenwich Hour Angle of the apparent (actual) Sun
- // GMHA is the Greenwich Mean Hour Angle of the mean (fictitious) Sun
- // http://www.esrl.noaa.gov/gmd/grad/solcalc/
- // http://en.wikipedia.org/wiki/Equation_of_time
- private static double EquationOfTime(double time)
- {
- double julianCenturies = JulianCenturies(time);
- double lambda = PolynomialSum(s_lambdaCoefficients, julianCenturies);
- double anomaly = PolynomialSum(s_anomalyCoefficients, julianCenturies);
- double eccentricity = PolynomialSum(s_eccentricityCoefficients, julianCenturies);
-
- double epsilon = Obliquity(julianCenturies);
- double tanHalfEpsilon = TanOfDegree(epsilon / 2);
- double y = tanHalfEpsilon * tanHalfEpsilon;
-
- double dividend = ((y * SinOfDegree(2 * lambda))
- - (2 * eccentricity * SinOfDegree(anomaly))
- + (4 * eccentricity * y * SinOfDegree(anomaly) * CosOfDegree(2 * lambda))
- - (0.5 * Math.Pow(y, 2) * SinOfDegree(4 * lambda))
- - (1.25 * Math.Pow(eccentricity, 2) * SinOfDegree(2 * anomaly)));
- const double Divisor = 2 * Math.PI;
- double equation = dividend / Divisor;
-
- // approximation of equation of time is not valid for dates that are many millennia in the past or future
- // thus limited to a half day
- return CopySign(Math.Min(Math.Abs(equation), TwelveHours), equation);
- }
-
- private static double AsLocalTime(double apparentMidday, double longitude)
- {
- // slightly inaccurate since equation of time takes mean time not apparent time as its argument, but the difference is negligible
- double universalTime = apparentMidday - AsDayFraction(longitude);
- return apparentMidday - EquationOfTime(universalTime);
- }
-
- // midday
- public static double Midday(double date, double longitude)
- {
- return AsLocalTime(date + TwelveHours, longitude) - AsDayFraction(longitude);
- }
-
- private static double InitLongitude(double longitude)
- {
- return NormalizeLongitude(longitude + HalfCircleOfArc) - HalfCircleOfArc;
- }
-
- // midday-in-tehran
- public static double MiddayAtPersianObservationSite(double date)
- {
- return Midday(date, InitLongitude(52.5)); // 52.5 degrees east - longitude of UTC+3:30 which defines Iranian Standard Time
- }
-
- private static double PeriodicTerm(double julianCenturies, int x, double y, double z)
- {
- return x * SinOfDegree(y + z * julianCenturies);
- }
-
- private static double SumLongSequenceOfPeriodicTerms(double julianCenturies)
- {
- double sum = 0.0;
- sum += PeriodicTerm(julianCenturies, 403406, 270.54861, 0.9287892);
- sum += PeriodicTerm(julianCenturies, 195207, 340.19128, 35999.1376958);
- sum += PeriodicTerm(julianCenturies, 119433, 63.91854, 35999.4089666);
- sum += PeriodicTerm(julianCenturies, 112392, 331.2622, 35998.7287385);
- sum += PeriodicTerm(julianCenturies, 3891, 317.843, 71998.20261);
- sum += PeriodicTerm(julianCenturies, 2819, 86.631, 71998.4403);
- sum += PeriodicTerm(julianCenturies, 1721, 240.052, 36000.35726);
- sum += PeriodicTerm(julianCenturies, 660, 310.26, 71997.4812);
- sum += PeriodicTerm(julianCenturies, 350, 247.23, 32964.4678);
- sum += PeriodicTerm(julianCenturies, 334, 260.87, -19.441);
- sum += PeriodicTerm(julianCenturies, 314, 297.82, 445267.1117);
- sum += PeriodicTerm(julianCenturies, 268, 343.14, 45036.884);
- sum += PeriodicTerm(julianCenturies, 242, 166.79, 3.1008);
- sum += PeriodicTerm(julianCenturies, 234, 81.53, 22518.4434);
- sum += PeriodicTerm(julianCenturies, 158, 3.5, -19.9739);
- sum += PeriodicTerm(julianCenturies, 132, 132.75, 65928.9345);
- sum += PeriodicTerm(julianCenturies, 129, 182.95, 9038.0293);
- sum += PeriodicTerm(julianCenturies, 114, 162.03, 3034.7684);
- sum += PeriodicTerm(julianCenturies, 99, 29.8, 33718.148);
- sum += PeriodicTerm(julianCenturies, 93, 266.4, 3034.448);
- sum += PeriodicTerm(julianCenturies, 86, 249.2, -2280.773);
- sum += PeriodicTerm(julianCenturies, 78, 157.6, 29929.992);
- sum += PeriodicTerm(julianCenturies, 72, 257.8, 31556.493);
- sum += PeriodicTerm(julianCenturies, 68, 185.1, 149.588);
- sum += PeriodicTerm(julianCenturies, 64, 69.9, 9037.75);
- sum += PeriodicTerm(julianCenturies, 46, 8.0, 107997.405);
- sum += PeriodicTerm(julianCenturies, 38, 197.1, -4444.176);
- sum += PeriodicTerm(julianCenturies, 37, 250.4, 151.771);
- sum += PeriodicTerm(julianCenturies, 32, 65.3, 67555.316);
- sum += PeriodicTerm(julianCenturies, 29, 162.7, 31556.08);
- sum += PeriodicTerm(julianCenturies, 28, 341.5, -4561.54);
- sum += PeriodicTerm(julianCenturies, 27, 291.6, 107996.706);
- sum += PeriodicTerm(julianCenturies, 27, 98.5, 1221.655);
- sum += PeriodicTerm(julianCenturies, 25, 146.7, 62894.167);
- sum += PeriodicTerm(julianCenturies, 24, 110.0, 31437.369);
- sum += PeriodicTerm(julianCenturies, 21, 5.2, 14578.298);
- sum += PeriodicTerm(julianCenturies, 21, 342.6, -31931.757);
- sum += PeriodicTerm(julianCenturies, 20, 230.9, 34777.243);
- sum += PeriodicTerm(julianCenturies, 18, 256.1, 1221.999);
- sum += PeriodicTerm(julianCenturies, 17, 45.3, 62894.511);
- sum += PeriodicTerm(julianCenturies, 14, 242.9, -4442.039);
- sum += PeriodicTerm(julianCenturies, 13, 115.2, 107997.909);
- sum += PeriodicTerm(julianCenturies, 13, 151.8, 119.066);
- sum += PeriodicTerm(julianCenturies, 13, 285.3, 16859.071);
- sum += PeriodicTerm(julianCenturies, 12, 53.3, -4.578);
- sum += PeriodicTerm(julianCenturies, 10, 126.6, 26895.292);
- sum += PeriodicTerm(julianCenturies, 10, 205.7, -39.127);
- sum += PeriodicTerm(julianCenturies, 10, 85.9, 12297.536);
- sum += PeriodicTerm(julianCenturies, 10, 146.1, 90073.778);
- return sum;
- }
-
- private static double Aberration(double julianCenturies)
- {
- return (0.0000974 * CosOfDegree(177.63 + (35999.01848 * julianCenturies))) - 0.005575;
- }
-
- private static double Nutation(double julianCenturies)
- {
- double a = PolynomialSum(s_coefficientsA, julianCenturies);
- double b = PolynomialSum(s_coefficientsB, julianCenturies);
- return (-0.004778 * SinOfDegree(a)) - (0.0003667 * SinOfDegree(b));
- }
-
- public static double Compute(double time)
- {
- double julianCenturies = JulianCenturies(time);
- double lambda = 282.7771834
- + (36000.76953744 * julianCenturies)
- + (0.000005729577951308232 * SumLongSequenceOfPeriodicTerms(julianCenturies));
-
- double longitude = lambda + Aberration(julianCenturies) + Nutation(julianCenturies);
- return InitLongitude(longitude);
- }
-
- public static double AsSeason(double longitude)
- {
- return (longitude < 0) ? (longitude + FullCircleOfArc) : longitude;
- }
-
- private static double EstimatePrior(double longitude, double time)
- {
- double timeSunLastAtLongitude = time - (MeanSpeedOfSun * AsSeason(InitLongitude(Compute(time) - longitude)));
- double longitudeErrorDelta = InitLongitude(Compute(timeSunLastAtLongitude) - longitude);
- return Math.Min(time, timeSunLastAtLongitude - (MeanSpeedOfSun * longitudeErrorDelta));
- }
-
- // persian-new-year-on-or-before
- // number of days is the absolute date. The absolute date is the number of days from January 1st, 1 A.D.
- // 1/1/0001 is absolute date 1.
- internal static long PersianNewYearOnOrBefore(long numberOfDays)
- {
- double date = (double)numberOfDays;
-
- double approx = EstimatePrior(LongitudeSpring, MiddayAtPersianObservationSite(date));
- long lowerBoundNewYearDay = (long)Math.Floor(approx) - 1;
- long upperBoundNewYearDay = lowerBoundNewYearDay + 3; // estimate is generally within a day of the actual occurrence (at the limits, the error expands, since the calculations rely on the mean tropical year which changes...)
- long day = lowerBoundNewYearDay;
- for (; day != upperBoundNewYearDay; ++day)
- {
- double midday = MiddayAtPersianObservationSite((double)day);
- double l = Compute(midday);
- if ((LongitudeSpring <= l) && (l <= TwoDegreesAfterSpring))
- {
- break;
- }
- }
- Debug.Assert(day != upperBoundNewYearDay);
-
- return day - 1;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CharUnicodeInfo.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CharUnicodeInfo.cs
deleted file mode 100644
index 59ccd9e30da..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CharUnicodeInfo.cs
+++ /dev/null
@@ -1,321 +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 System.Buffers.Binary;
-using System.Diagnostics;
-using System.Text;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Globalization
-{
- /// <summary>
- /// This class implements a set of methods for retrieving character type
- /// information. Character type information is independent of culture
- /// and region.
- /// </summary>
- public static partial class CharUnicodeInfo
- {
- internal const char HIGH_SURROGATE_START = '\ud800';
- internal const char HIGH_SURROGATE_END = '\udbff';
- internal const char LOW_SURROGATE_START = '\udc00';
- internal const char LOW_SURROGATE_END = '\udfff';
- internal const int HIGH_SURROGATE_RANGE = 0x3FF;
-
- internal const int UNICODE_CATEGORY_OFFSET = 0;
- internal const int BIDI_CATEGORY_OFFSET = 1;
-
- // The starting codepoint for Unicode plane 1. Plane 1 contains 0x010000 ~ 0x01ffff.
- internal const int UNICODE_PLANE01_START = 0x10000;
-
- /// <summary>
- /// Convert the BMP character or surrogate pointed by index to a UTF32 value.
- /// This is similar to char.ConvertToUTF32, but the difference is that
- /// it does not throw exceptions when invalid surrogate characters are passed in.
- ///
- /// WARNING: since it doesn't throw an exception it CAN return a value
- /// in the surrogate range D800-DFFF, which are not legal unicode values.
- /// </summary>
- internal static int InternalConvertToUtf32(string s, int index)
- {
- Debug.Assert(s != null, "s != null");
- Debug.Assert(index >= 0 && index < s.Length, "index < s.Length");
- if (index < s.Length - 1)
- {
- int temp1 = (int)s[index] - HIGH_SURROGATE_START;
- if ((uint)temp1 <= HIGH_SURROGATE_RANGE)
- {
- int temp2 = (int)s[index + 1] - LOW_SURROGATE_START;
- if ((uint)temp2 <= HIGH_SURROGATE_RANGE)
- {
- // Convert the surrogate to UTF32 and get the result.
- return (temp1 * 0x400) + temp2 + UNICODE_PLANE01_START;
- }
- }
- }
- return (int)s[index];
- }
-
- internal static int InternalConvertToUtf32(StringBuilder s, int index)
- {
- Debug.Assert(s != null, "s != null");
- Debug.Assert(index >= 0 && index < s.Length, "index < s.Length");
-
- int c = (int)s[index];
- if (index < s.Length - 1)
- {
- int temp1 = c - HIGH_SURROGATE_START;
- if ((uint)temp1 <= HIGH_SURROGATE_RANGE)
- {
- int temp2 = (int)s[index + 1] - LOW_SURROGATE_START;
- if ((uint)temp2 <= HIGH_SURROGATE_RANGE)
- {
- // Convert the surrogate to UTF32 and get the result.
- return (temp1 * 0x400) + temp2 + UNICODE_PLANE01_START;
- }
- }
- }
- return c;
- }
-
- /// <summary>
- /// Convert a character or a surrogate pair starting at index of string s
- /// to UTF32 value.
- /// WARNING: since it doesn't throw an exception it CAN return a value
- /// in the surrogate range D800-DFFF, which are not legal unicode values.
- /// </summary>
- internal static int InternalConvertToUtf32(string s, int index, out int charLength)
- {
- Debug.Assert(s != null, "s != null");
- Debug.Assert(s.Length > 0, "s.Length > 0");
- Debug.Assert(index >= 0 && index < s.Length, "index >= 0 && index < s.Length");
- charLength = 1;
- if (index < s.Length - 1)
- {
- int temp1 = (int)s[index] - HIGH_SURROGATE_START;
- if ((uint)temp1 <= HIGH_SURROGATE_RANGE)
- {
- int temp2 = (int)s[index + 1] - LOW_SURROGATE_START;
- if ((uint)temp2 <= HIGH_SURROGATE_RANGE)
- {
- // Convert the surrogate to UTF32 and get the result.
- charLength++;
- return (temp1 * 0x400) + temp2 + UNICODE_PLANE01_START;
- }
- }
- }
- return (int)s[index];
- }
-
- /// <summary>
- /// This is called by the public char and string, index versions
- /// Note that for ch in the range D800-DFFF we just treat it as any
- /// other non-numeric character
- /// </summary>
- internal static double InternalGetNumericValue(int ch)
- {
- Debug.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
- // Get the level 2 item from the highest 12 bit (8 - 19) of ch.
- int index = ch >> 8;
- if ((uint)index < (uint)NumericLevel1Index.Length)
- {
- index = NumericLevel1Index[index];
- // Get the level 2 offset from the 4 - 7 bit of ch. This provides the base offset of the level 3 table.
- // Note that & has the lower precedence than addition, so don't forget the parathesis.
- index = NumericLevel2Index[(index << 4) + ((ch >> 4) & 0x000f)];
- index = NumericLevel3Index[(index << 4) + (ch & 0x000f)];
- ref byte value = ref Unsafe.AsRef(in NumericValues[index * 8]);
-
- if (BitConverter.IsLittleEndian)
- {
- return Unsafe.ReadUnaligned<double>(ref value);
- }
-
- return BitConverter.Int64BitsToDouble(BinaryPrimitives.ReverseEndianness(Unsafe.ReadUnaligned<long>(ref value)));
- }
- return -1;
- }
-
- internal static byte InternalGetDigitValues(int ch, int offset)
- {
- Debug.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
- // Get the level 2 item from the highest 12 bit (8 - 19) of ch.
- int index = ch >> 8;
- if ((uint)index < (uint)NumericLevel1Index.Length)
- {
- index = NumericLevel1Index[index];
- // Get the level 2 offset from the 4 - 7 bit of ch. This provides the base offset of the level 3 table.
- // Note that & has the lower precedence than addition, so don't forget the parathesis.
- index = NumericLevel2Index[(index << 4) + ((ch >> 4) & 0x000f)];
- index = NumericLevel3Index[(index << 4) + (ch & 0x000f)];
- return DigitValues[index * 2 + offset];
- }
- return 0xff;
- }
-
- /// <summary>
- /// Returns the numeric value associated with the character c.
- /// If the character is a fraction, the return value will not be an
- /// integer. If the character does not have a numeric value, the return
- /// value is -1.
- /// </summary>
- public static double GetNumericValue(char ch)
- {
- return InternalGetNumericValue(ch);
- }
-
- public static double GetNumericValue(string s, int index)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
- if (index < 0 || index >= s.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
-
- return InternalGetNumericValue(InternalConvertToUtf32(s, index));
- }
-
- public static int GetDecimalDigitValue(char ch)
- {
- return (sbyte)InternalGetDigitValues(ch, 0);
- }
-
- public static int GetDecimalDigitValue(string s, int index)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
- if (index < 0 || index >= s.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
-
- return (sbyte)InternalGetDigitValues(InternalConvertToUtf32(s, index), 0);
- }
-
- public static int GetDigitValue(char ch)
- {
- return (sbyte)InternalGetDigitValues(ch, 1);
- }
-
- public static int GetDigitValue(string s, int index)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
- if (index < 0 || index >= s.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
-
- return (sbyte)InternalGetDigitValues(InternalConvertToUtf32(s, index), 1);
- }
-
- public static UnicodeCategory GetUnicodeCategory(char ch)
- {
- return GetUnicodeCategory((int)ch);
- }
-
- public static UnicodeCategory GetUnicodeCategory(string s, int index)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
-
- return InternalGetUnicodeCategory(s, index);
- }
-
- public static UnicodeCategory GetUnicodeCategory(int codePoint)
- {
- return (UnicodeCategory)InternalGetCategoryValue(codePoint, UNICODE_CATEGORY_OFFSET);
- }
-
- /// <summary>
- /// Returns the Unicode Category property for the character c.
- /// Note that this API will return values for D800-DF00 surrogate halves.
- /// </summary>
- internal static byte InternalGetCategoryValue(int ch, int offset)
- {
- Debug.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
- // Get the level 2 item from the highest 11 bits of ch.
- int index = CategoryLevel1Index[ch >> 9];
- // Get the level 2 WORD offset from the next 5 bits of ch. This provides the base offset of the level 3 table.
- // Note that & has the lower precedence than addition, so don't forget the parathesis.
- index = Unsafe.ReadUnaligned<ushort>(ref Unsafe.AsRef(in CategoryLevel2Index[(index << 6) + ((ch >> 3) & 0b111110)]));
- if (!BitConverter.IsLittleEndian)
- {
- index = BinaryPrimitives.ReverseEndianness((ushort)index);
- }
-
- // Get the result from the 0 -3 bit of ch.
- index = CategoryLevel3Index[(index << 4) + (ch & 0x000f)];
- return CategoriesValue[index * 2 + offset];
- }
-
- /// <summary>
- /// Returns the Unicode Category property for the character c.
- /// </summary>
- internal static UnicodeCategory InternalGetUnicodeCategory(string value, int index)
- {
- Debug.Assert(value != null, "value can not be null");
- Debug.Assert(index < value.Length, "index < value.Length");
-
- return GetUnicodeCategory(InternalConvertToUtf32(value, index));
- }
-
- internal static BidiCategory GetBidiCategory(string s, int index)
- {
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
- if (((uint)index) >= ((uint)s.Length))
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
-
- return (BidiCategory)InternalGetCategoryValue(InternalConvertToUtf32(s, index), BIDI_CATEGORY_OFFSET);
- }
-
- internal static BidiCategory GetBidiCategory(StringBuilder s, int index)
- {
- Debug.Assert(s != null, "s can not be null");
- Debug.Assert(index >= 0 && index < s.Length, "invalid index");
-
- return (BidiCategory)InternalGetCategoryValue(InternalConvertToUtf32(s, index), BIDI_CATEGORY_OFFSET);
- }
-
- /// <summary>
- /// Get the Unicode category of the character starting at index. If the character is in BMP, charLength will return 1.
- /// If the character is a valid surrogate pair, charLength will return 2.
- /// </summary>
- internal static UnicodeCategory InternalGetUnicodeCategory(string str, int index, out int charLength)
- {
- Debug.Assert(str != null, "str can not be null");
- Debug.Assert(str.Length > 0, "str.Length > 0");
- Debug.Assert(index >= 0 && index < str.Length, "index >= 0 && index < str.Length");
-
- return GetUnicodeCategory(InternalConvertToUtf32(str, index, out charLength));
- }
-
- internal static bool IsCombiningCategory(UnicodeCategory uc)
- {
- Debug.Assert(uc >= 0, "uc >= 0");
- return
- uc == UnicodeCategory.NonSpacingMark ||
- uc == UnicodeCategory.SpacingCombiningMark ||
- uc == UnicodeCategory.EnclosingMark
- ;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CharUnicodeInfoData.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CharUnicodeInfoData.cs
deleted file mode 100644
index 522c33004a4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CharUnicodeInfoData.cs
+++ /dev/null
@@ -1,1576 +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.
-
-namespace System.Globalization
-{
- public static partial class CharUnicodeInfo
- {
- // THE FOLLOWING DATA IS AUTO GENERATED BY GenUnicodeProp program UNDER THE TOOLS FOLDER
- // PLEASE DON'T MODIFY BY HAND
-
-
- // 11:5:4 index table of the Unicode category data.
- private static ReadOnlySpan<byte> CategoryLevel1Index => new byte[2176]
- {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1b, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1c,
- 0x1d, 0x1a, 0x1e, 0x1f, 0x20, 0x21, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x22, 0x23, 0x23, 0x23, 0x23,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x25, 0x26, 0x27, 0x28,
- 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
- 0x1a, 0x39, 0x3a, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x1a, 0x1a, 0x3c, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x1a, 0x3d, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x1a, 0x3e, 0x3b, 0x3f, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x40, 0x1a, 0x41, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x42, 0x43, 0x3b, 0x3b, 0x3b, 0x3b, 0x44, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x3b, 0x3b,
- 0x4b, 0x3b, 0x3b, 0x3b, 0x4c, 0x3b, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x3b, 0x3b,
- 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x55, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x56, 0x57, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x58, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a,
- 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x59, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x1a, 0x5a, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x5b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x5c,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x5c
- };
-
- private static ReadOnlySpan<byte> CategoryLevel2Index => new byte[5952]
- {
- 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00,
- 0x08, 0x00, 0x09, 0x00, 0x0a, 0x00, 0x0b, 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x0e, 0x00, 0x0f, 0x00,
- 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x11, 0x00, 0x12, 0x00, 0x10, 0x00, 0x10, 0x00, 0x13, 0x00,
- 0x14, 0x00, 0x15, 0x00, 0x16, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x00, 0x10, 0x00, 0x1a, 0x00,
- 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x1b, 0x00, 0x1c, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00,
- 0x0e, 0x00, 0x1d, 0x00, 0x0e, 0x00, 0x1e, 0x00, 0x1f, 0x00, 0x20, 0x00, 0x21, 0x00, 0x22, 0x00,
- 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x24, 0x00,
- 0x25, 0x00, 0x26, 0x00, 0x27, 0x00, 0x0e, 0x00, 0x28, 0x00, 0x29, 0x00, 0x10, 0x00, 0x2a, 0x00,
- 0x0c, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x10, 0x00, 0x10, 0x00,
- 0x2b, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x2c, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00,
- 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x2d, 0x00, 0x0c, 0x00, 0x2e, 0x00, 0x0e, 0x00, 0x0e, 0x00,
- 0x2f, 0x00, 0x30, 0x00, 0x23, 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x34, 0x00, 0x35, 0x00,
- 0x36, 0x00, 0x37, 0x00, 0x38, 0x00, 0x38, 0x00, 0x39, 0x00, 0x23, 0x00, 0x3a, 0x00, 0x3b, 0x00,
- 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x3c, 0x00, 0x3d, 0x00, 0x3e, 0x00,
- 0x3f, 0x00, 0x40, 0x00, 0x38, 0x00, 0x23, 0x00, 0x41, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00,
- 0x38, 0x00, 0x38, 0x00, 0x42, 0x00, 0x43, 0x00, 0x44, 0x00, 0x33, 0x00, 0x45, 0x00, 0x46, 0x00,
- 0x33, 0x00, 0x47, 0x00, 0x48, 0x00, 0x49, 0x00, 0x33, 0x00, 0x4a, 0x00, 0x4b, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x38, 0x00, 0x4d, 0x00, 0x4c, 0x00, 0x4e, 0x00, 0x4f, 0x00, 0x23, 0x00,
- 0x50, 0x00, 0x51, 0x00, 0x51, 0x00, 0x52, 0x00, 0x53, 0x00, 0x54, 0x00, 0x55, 0x00, 0x56, 0x00,
- 0x57, 0x00, 0x58, 0x00, 0x59, 0x00, 0x5a, 0x00, 0x5b, 0x00, 0x5c, 0x00, 0x5d, 0x00, 0x5e, 0x00,
- 0x5f, 0x00, 0x58, 0x00, 0x59, 0x00, 0x60, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00, 0x64, 0x00,
- 0x65, 0x00, 0x66, 0x00, 0x59, 0x00, 0x67, 0x00, 0x68, 0x00, 0x69, 0x00, 0x5d, 0x00, 0x6a, 0x00,
- 0x6b, 0x00, 0x58, 0x00, 0x59, 0x00, 0x6c, 0x00, 0x6d, 0x00, 0x6e, 0x00, 0x5d, 0x00, 0x6f, 0x00,
- 0x70, 0x00, 0x71, 0x00, 0x72, 0x00, 0x73, 0x00, 0x74, 0x00, 0x75, 0x00, 0x63, 0x00, 0x76, 0x00,
- 0x77, 0x00, 0x78, 0x00, 0x59, 0x00, 0x79, 0x00, 0x7a, 0x00, 0x7b, 0x00, 0x5d, 0x00, 0x7c, 0x00,
- 0x7d, 0x00, 0x78, 0x00, 0x59, 0x00, 0x7e, 0x00, 0x7f, 0x00, 0x80, 0x00, 0x5d, 0x00, 0x81, 0x00,
- 0x82, 0x00, 0x78, 0x00, 0x51, 0x00, 0x83, 0x00, 0x84, 0x00, 0x85, 0x00, 0x5d, 0x00, 0x86, 0x00,
- 0x87, 0x00, 0x88, 0x00, 0x51, 0x00, 0x89, 0x00, 0x8a, 0x00, 0x8b, 0x00, 0x63, 0x00, 0x8c, 0x00,
- 0x8d, 0x00, 0x51, 0x00, 0x51, 0x00, 0x8e, 0x00, 0x8f, 0x00, 0x90, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x91, 0x00, 0x92, 0x00, 0x93, 0x00, 0x94, 0x00, 0x95, 0x00, 0x96, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x97, 0x00, 0x98, 0x00, 0x99, 0x00, 0x9a, 0x00, 0x9b, 0x00, 0x51, 0x00, 0x9c, 0x00, 0x9d, 0x00,
- 0x9e, 0x00, 0x9f, 0x00, 0x23, 0x00, 0xa0, 0x00, 0xa1, 0x00, 0xa2, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0xa3, 0x00, 0xa4, 0x00, 0xa5, 0x00, 0xa6, 0x00, 0xa7, 0x00, 0xa8, 0x00,
- 0xa9, 0x00, 0xaa, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0xab, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0xac, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xad, 0x00, 0xae, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0xad, 0x00, 0x51, 0x00, 0x51, 0x00, 0xaf, 0x00, 0xb0, 0x00, 0xb1, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0xb0, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xb2, 0x00, 0xb3, 0x00, 0xb4, 0x00,
- 0x51, 0x00, 0xb5, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0xb6, 0x00,
- 0xb7, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xb8, 0x00, 0x51, 0x00,
- 0xb9, 0x00, 0xba, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xbb, 0x00, 0xbc, 0x00,
- 0xbd, 0x00, 0xbe, 0x00, 0x51, 0x00, 0xbf, 0x00, 0x51, 0x00, 0xc0, 0x00, 0xbd, 0x00, 0xc1, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xc2, 0x00, 0xc3, 0x00, 0xc4, 0x00, 0xc5, 0x00, 0xc6, 0x00,
- 0xc7, 0x00, 0xc5, 0x00, 0x51, 0x00, 0x51, 0x00, 0xc8, 0x00, 0x51, 0x00, 0x51, 0x00, 0xc9, 0x00,
- 0xca, 0x00, 0x51, 0x00, 0xcb, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xcc, 0x00,
- 0x51, 0x00, 0xcd, 0x00, 0xce, 0x00, 0xcf, 0x00, 0xd0, 0x00, 0x51, 0x00, 0xd1, 0x00, 0xd2, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0xd3, 0x00, 0x51, 0x00, 0xd4, 0x00, 0xd5, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0x51, 0x00, 0xd7, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xd8, 0x00, 0xd9, 0x00, 0xda, 0x00,
- 0xc5, 0x00, 0xc5, 0x00, 0xdb, 0x00, 0xdc, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0xdd, 0x00, 0x51, 0x00, 0x51, 0x00, 0xde, 0x00, 0xdf, 0x00, 0xa5, 0x00, 0xe0, 0x00, 0xe1, 0x00,
- 0xe2, 0x00, 0x51, 0x00, 0xe3, 0x00, 0xe4, 0x00, 0x51, 0x00, 0x51, 0x00, 0xe5, 0x00, 0xe6, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0xe7, 0x00, 0xe8, 0x00, 0xe9, 0x00, 0xe4, 0x00, 0x51, 0x00, 0xea, 0x00,
- 0xeb, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0xec, 0x00, 0xed, 0x00, 0xee, 0x00, 0xef, 0x00, 0xf0, 0x00,
- 0x0e, 0x00, 0x0e, 0x00, 0xf1, 0x00, 0xf2, 0x00, 0xf2, 0x00, 0xf2, 0x00, 0xf3, 0x00, 0xf4, 0x00,
- 0x0e, 0x00, 0xf5, 0x00, 0xf2, 0x00, 0xf2, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0xf6, 0x00,
- 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00,
- 0x10, 0x00, 0xf7, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00,
- 0xf8, 0x00, 0xf9, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf9, 0x00, 0xfa, 0x00, 0xf8, 0x00, 0xfb, 0x00,
- 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfd, 0x00, 0xfe, 0x00, 0xff, 0x00, 0x00, 0x01, 0x01, 0x01,
- 0x02, 0x01, 0x03, 0x01, 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x07, 0x01, 0x08, 0x01, 0x09, 0x01,
- 0x0a, 0x01, 0x0b, 0x01, 0x0c, 0x01, 0x0c, 0x01, 0x4c, 0x00, 0x0d, 0x01, 0x0e, 0x01, 0x0f, 0x01,
- 0x10, 0x01, 0x11, 0x01, 0x12, 0x01, 0x13, 0x01, 0x14, 0x01, 0x15, 0x01, 0x16, 0x01, 0x16, 0x01,
- 0x17, 0x01, 0x18, 0x01, 0x19, 0x01, 0xd6, 0x00, 0x1a, 0x01, 0x1b, 0x01, 0xd6, 0x00, 0x1c, 0x01,
- 0x1d, 0x01, 0x1e, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01,
- 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01,
- 0x1f, 0x01, 0xd6, 0x00, 0x20, 0x01, 0x21, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x23, 0x01,
- 0xd6, 0x00, 0x24, 0x01, 0x1d, 0x01, 0x25, 0x01, 0xd6, 0x00, 0x26, 0x01, 0x27, 0x01, 0xd6, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0x28, 0x01, 0x4c, 0x00, 0x29, 0x01, 0x4c, 0x00, 0x15, 0x01, 0x15, 0x01,
- 0x2a, 0x01, 0x2b, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x2c, 0x01, 0x15, 0x01,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x2d, 0x01, 0x2e, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0x2f, 0x01,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x30, 0x01, 0xd6, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0x31, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x32, 0x01, 0x33, 0x01,
- 0x15, 0x01, 0x34, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0x35, 0x01, 0x1d, 0x01, 0x36, 0x01, 0x1d, 0x01,
- 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01,
- 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01,
- 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01,
- 0x37, 0x01, 0x38, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x39, 0x01, 0x1d, 0x01, 0x3a, 0x01,
- 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01,
- 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01, 0x1d, 0x01,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x1d, 0x01, 0x3b, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0x3c, 0x01,
- 0xd6, 0x00, 0x3d, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0x3e, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0x3f, 0x01,
- 0x0c, 0x00, 0x0c, 0x00, 0x40, 0x01, 0x0e, 0x00, 0x0e, 0x00, 0x41, 0x01, 0x42, 0x01, 0x43, 0x01,
- 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x44, 0x01, 0x45, 0x01,
- 0x0e, 0x00, 0x0e, 0x00, 0x46, 0x01, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x47, 0x01, 0x48, 0x01,
- 0x51, 0x00, 0x49, 0x01, 0x4a, 0x01, 0x4a, 0x01, 0x4a, 0x01, 0x4a, 0x01, 0x23, 0x00, 0x23, 0x00,
- 0x4b, 0x01, 0x4c, 0x01, 0x4d, 0x01, 0x4e, 0x01, 0x4f, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0xd6, 0x00, 0x50, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x51, 0x01,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x52, 0x01, 0x4c, 0x00, 0x53, 0x01,
- 0x54, 0x01, 0x55, 0x01, 0x56, 0x01, 0x57, 0x01, 0x8d, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x58, 0x01, 0xb7, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x59, 0x01,
- 0x5a, 0x01, 0x51, 0x00, 0x51, 0x00, 0x8d, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0xcd, 0x00, 0x5b, 0x01, 0x51, 0x00, 0x5c, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0x51, 0x01, 0x51, 0x00,
- 0x22, 0x01, 0x5d, 0x01, 0x5e, 0x01, 0x22, 0x01, 0x5f, 0x01, 0x60, 0x01, 0x22, 0x01, 0x61, 0x01,
- 0x5e, 0x01, 0x22, 0x01, 0x22, 0x01, 0x62, 0x01, 0x63, 0x01, 0x22, 0x01, 0x22, 0x01, 0x64, 0x01,
- 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x65, 0x01,
- 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x66, 0x01, 0x22, 0x01, 0x67, 0x01,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xcc, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x68, 0x01, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x9c, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x28, 0x01, 0x51, 0x00, 0x51, 0x00, 0xea, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x69, 0x01, 0x51, 0x00, 0x6a, 0x01, 0x4c, 0x00, 0x10, 0x00, 0x10, 0x00, 0x6b, 0x01, 0x6c, 0x01,
- 0x10, 0x00, 0x6d, 0x01, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x6e, 0x01, 0x6f, 0x01,
- 0x22, 0x00, 0x70, 0x01, 0x71, 0x01, 0x72, 0x01, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x73, 0x01,
- 0x74, 0x01, 0x75, 0x01, 0x76, 0x01, 0x77, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x78, 0x01,
- 0x79, 0x01, 0x51, 0x00, 0x7a, 0x01, 0x7b, 0x01, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x7c, 0x01,
- 0x7d, 0x01, 0x51, 0x00, 0x51, 0x00, 0x7e, 0x01, 0x7f, 0x01, 0xc5, 0x00, 0x23, 0x00, 0x80, 0x01,
- 0xe4, 0x00, 0x51, 0x00, 0x81, 0x01, 0x51, 0x00, 0x82, 0x01, 0x83, 0x01, 0x51, 0x00, 0x9c, 0x00,
- 0x50, 0x00, 0x51, 0x00, 0x51, 0x00, 0x84, 0x01, 0x85, 0x01, 0x86, 0x01, 0x87, 0x01, 0x88, 0x01,
- 0x51, 0x00, 0x51, 0x00, 0x89, 0x01, 0x8a, 0x01, 0x8b, 0x01, 0x8c, 0x01, 0x51, 0x00, 0x8d, 0x01,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x8e, 0x01, 0x8f, 0x01, 0x90, 0x01, 0x91, 0x01, 0x92, 0x01,
- 0x93, 0x01, 0x94, 0x01, 0x4a, 0x01, 0x0e, 0x00, 0x0e, 0x00, 0x95, 0x01, 0x96, 0x01, 0x0e, 0x00,
- 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x51, 0x00, 0x51, 0x00, 0x97, 0x01, 0xc5, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x98, 0x01, 0x51, 0x00, 0x99, 0x01, 0x51, 0x00, 0x51, 0x00, 0xd3, 0x00,
- 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01,
- 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01,
- 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01,
- 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01, 0x9a, 0x01,
- 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01,
- 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01,
- 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01,
- 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01,
- 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01,
- 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xd1, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xd4, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x9c, 0x01, 0x9d, 0x01, 0x9e, 0x01, 0x9f, 0x01, 0xa0, 0x01, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00,
- 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0xa1, 0x01, 0xa2, 0x01, 0xa3, 0x01, 0x38, 0x00, 0x38, 0x00,
- 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00,
- 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00,
- 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0xa4, 0x01, 0x4c, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00,
- 0x38, 0x00, 0xa5, 0x01, 0x38, 0x00, 0x38, 0x00, 0xa6, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0xa7, 0x01,
- 0x23, 0x00, 0xa8, 0x01, 0x23, 0x00, 0xa9, 0x01, 0xaa, 0x01, 0xab, 0x01, 0xac, 0x01, 0xad, 0x01,
- 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0xae, 0x01,
- 0xaf, 0x01, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0xb0, 0x01, 0xb1, 0x01, 0xb2, 0x01,
- 0x51, 0x00, 0xb3, 0x01, 0x51, 0x00, 0xcd, 0x00, 0xb4, 0x01, 0xb5, 0x01, 0xb6, 0x01, 0xb7, 0x01,
- 0xb8, 0x01, 0x51, 0x00, 0xb1, 0x00, 0xb9, 0x01, 0xd1, 0x00, 0xd1, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x5c, 0x01,
- 0xba, 0x01, 0xbb, 0x01, 0xbb, 0x01, 0xbc, 0x01, 0xbd, 0x01, 0xbd, 0x01, 0xbd, 0x01, 0xbe, 0x01,
- 0xbf, 0x01, 0x53, 0x01, 0xc0, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0x22, 0x01, 0x22, 0x01, 0xc1, 0x01,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x9c, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x69, 0x00, 0xc2, 0x01, 0xc3, 0x01,
- 0x51, 0x00, 0x51, 0x00, 0xc4, 0x01, 0x51, 0x00, 0xc5, 0x01, 0x51, 0x00, 0x51, 0x00, 0xc6, 0x01,
- 0x51, 0x00, 0xc7, 0x01, 0x51, 0x00, 0x51, 0x00, 0xc8, 0x01, 0xc9, 0x01, 0x4c, 0x00, 0x4c, 0x00,
- 0x0c, 0x00, 0x0c, 0x00, 0xca, 0x01, 0x0e, 0x00, 0x0e, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0xd1, 0x00, 0xc5, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0xcb, 0x01, 0x0e, 0x00, 0xcc, 0x01,
- 0x51, 0x00, 0x51, 0x00, 0xcd, 0x01, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xce, 0x01, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x49, 0x01, 0x51, 0x00, 0xcc, 0x00, 0xcd, 0x01, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0xcf, 0x01, 0x33, 0x00, 0x33, 0x00, 0xd0, 0x01, 0x33, 0x00, 0xd1, 0x01, 0x33, 0x00, 0xd2, 0x01,
- 0x33, 0x00, 0xd3, 0x01, 0xd4, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x33, 0x00, 0xd5, 0x01,
- 0x33, 0x00, 0xd6, 0x01, 0x33, 0x00, 0xd7, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0xd8, 0x01, 0xd9, 0x01, 0xda, 0x01, 0xd9, 0x01, 0xd9, 0x01,
- 0xdb, 0x01, 0xdc, 0x01, 0x33, 0x00, 0xdd, 0x01, 0xde, 0x01, 0xdf, 0x01, 0x33, 0x00, 0xe0, 0x01,
- 0x33, 0x00, 0xe1, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0xe2, 0x01, 0x33, 0x00, 0xe3, 0x01, 0xe4, 0x01,
- 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0xe5, 0x01, 0x33, 0x00, 0xe6, 0x01, 0x33, 0x00, 0xe7, 0x01,
- 0x33, 0x00, 0xe8, 0x01, 0xe9, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0xea, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0xeb, 0x01, 0xeb, 0x01, 0xeb, 0x01, 0xec, 0x01, 0xed, 0x01, 0xed, 0x01, 0xed, 0x01, 0xee, 0x01,
- 0x38, 0x00, 0x38, 0x00, 0xef, 0x01, 0xf0, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0xf1, 0x01, 0xf2, 0x01,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x33, 0x00, 0xe1, 0x01, 0xf3, 0x01, 0x38, 0x00, 0x42, 0x00, 0xf4, 0x01, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0xf5, 0x01, 0x51, 0x00, 0x51, 0x00, 0xf6, 0x01, 0xf7, 0x01, 0xf8, 0x01, 0xf9, 0x01, 0xfa, 0x01,
- 0xe2, 0x00, 0x51, 0x00, 0x51, 0x00, 0xfb, 0x01, 0xfc, 0x01, 0x51, 0x00, 0xc9, 0x00, 0xc5, 0x00,
- 0xfd, 0x01, 0x51, 0x00, 0xfe, 0x01, 0xff, 0x01, 0x00, 0x02, 0x51, 0x00, 0x51, 0x00, 0x01, 0x02,
- 0xe2, 0x00, 0x51, 0x00, 0x51, 0x00, 0x02, 0x02, 0x03, 0x02, 0x04, 0x02, 0x05, 0x02, 0x06, 0x02,
- 0x51, 0x00, 0x66, 0x00, 0x07, 0x02, 0x08, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x09, 0x02, 0x0a, 0x02, 0x0b, 0x02, 0x51, 0x00, 0x51, 0x00, 0x0c, 0x02, 0x0d, 0x02, 0xc5, 0x00,
- 0x0e, 0x02, 0x58, 0x00, 0x59, 0x00, 0x0f, 0x02, 0x10, 0x02, 0x11, 0x02, 0x12, 0x02, 0x13, 0x02,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x14, 0x02, 0x15, 0x02, 0x16, 0x02, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x17, 0x02, 0x18, 0x02, 0xc5, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x19, 0x02, 0x1a, 0x02, 0x1b, 0x02, 0x1c, 0x02, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x1d, 0x02, 0x1e, 0x02, 0xc5, 0x00, 0x1f, 0x02, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x20, 0x02, 0x21, 0x02, 0xc5, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0xb2, 0x00, 0x22, 0x02, 0x23, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x07, 0x02, 0x24, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x99, 0x00, 0x25, 0x02,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x26, 0x02, 0x51, 0x00, 0x51, 0x00, 0x27, 0x02, 0x28, 0x02, 0x29, 0x02, 0x51, 0x00, 0x51, 0x00,
- 0x2a, 0x02, 0x2b, 0x02, 0x2c, 0x02, 0x4c, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xc9, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x59, 0x00, 0x51, 0x00, 0x19, 0x02, 0x2d, 0x02, 0x2e, 0x02, 0x99, 0x00, 0xb4, 0x00, 0x2f, 0x02,
- 0x51, 0x00, 0x30, 0x02, 0x31, 0x02, 0x32, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x33, 0x02, 0x51, 0x00, 0x51, 0x00, 0x34, 0x02, 0x35, 0x02, 0xc5, 0x00, 0x36, 0x02, 0x51, 0x00,
- 0x37, 0x02, 0x38, 0x02, 0xc5, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x51, 0x00, 0x39, 0x02,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0xd4, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x16, 0x01, 0x3a, 0x02, 0x3b, 0x02,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x98, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0xcd, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x49, 0x01, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xc9, 0x00, 0x51, 0x00, 0xcd, 0x00, 0x86, 0x01, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x51, 0x00, 0xd1, 0x00, 0x3c, 0x02,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x3d, 0x02, 0x3e, 0x02, 0x3f, 0x02, 0x40, 0x02, 0x41, 0x02,
- 0x51, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0e, 0x00, 0x0e, 0x00,
- 0xbb, 0x01, 0x42, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xd2, 0x00, 0x43, 0x02, 0x44, 0x02, 0x45, 0x02,
- 0xfa, 0x01, 0x46, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x47, 0x02, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x48, 0x02,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x49, 0x02,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0xcd, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xd3, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x5c, 0x01, 0x9c, 0x00,
- 0xc9, 0x00, 0x4a, 0x02, 0x4b, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01,
- 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x4c, 0x02,
- 0x22, 0x01, 0x22, 0x01, 0x4d, 0x02, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x4e, 0x02, 0x4f, 0x02,
- 0x50, 0x02, 0x22, 0x01, 0x51, 0x02, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x52, 0x02, 0x4c, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x53, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0xbb, 0x01, 0x54, 0x02,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x28, 0x01, 0xbb, 0x01, 0x55, 0x02,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x0c, 0x00, 0x56, 0x02, 0x0e, 0x00, 0x57, 0x02, 0x58, 0x02, 0x59, 0x02, 0xf8, 0x00, 0x0c, 0x00,
- 0x5a, 0x02, 0x5b, 0x02, 0x5c, 0x02, 0x5d, 0x02, 0x5e, 0x02, 0x0c, 0x00, 0x56, 0x02, 0x0e, 0x00,
- 0x5f, 0x02, 0x60, 0x02, 0x0e, 0x00, 0x61, 0x02, 0x62, 0x02, 0x63, 0x02, 0x64, 0x02, 0x0c, 0x00,
- 0x65, 0x02, 0x0e, 0x00, 0x0c, 0x00, 0x56, 0x02, 0x0e, 0x00, 0x57, 0x02, 0x58, 0x02, 0x0e, 0x00,
- 0xf8, 0x00, 0x0c, 0x00, 0x5a, 0x02, 0x64, 0x02, 0x0c, 0x00, 0x65, 0x02, 0x0e, 0x00, 0x0c, 0x00,
- 0x56, 0x02, 0x0e, 0x00, 0x66, 0x02, 0x0c, 0x00, 0x67, 0x02, 0x68, 0x02, 0x69, 0x02, 0x6a, 0x02,
- 0x0e, 0x00, 0x6b, 0x02, 0x0c, 0x00, 0x6c, 0x02, 0x6d, 0x02, 0x6e, 0x02, 0x6f, 0x02, 0x0e, 0x00,
- 0x70, 0x02, 0x0c, 0x00, 0x71, 0x02, 0x0e, 0x00, 0x72, 0x02, 0x73, 0x02, 0x73, 0x02, 0x73, 0x02,
- 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01,
- 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01,
- 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01,
- 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01,
- 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x74, 0x02, 0x23, 0x00, 0x23, 0x00, 0x75, 0x02, 0x76, 0x02,
- 0x77, 0x02, 0x78, 0x02, 0x30, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x79, 0x02, 0x7a, 0x02, 0x7b, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0x33, 0x00,
- 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0x7c, 0x02, 0x7d, 0x02, 0x4c, 0x00, 0x4c, 0x00,
- 0xeb, 0x01, 0xeb, 0x01, 0x7e, 0x02, 0xed, 0x01, 0x7f, 0x02, 0x80, 0x02, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x81, 0x02,
- 0x82, 0x02, 0x82, 0x02, 0x83, 0x02, 0x84, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x85, 0x02, 0x38, 0x00, 0x86, 0x02, 0x87, 0x02, 0x88, 0x02, 0x89, 0x02, 0x8a, 0x02, 0x8b, 0x02,
- 0x8c, 0x02, 0x8d, 0x02, 0x8e, 0x02, 0x8d, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x8f, 0x02,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0x53, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0xd6, 0x00, 0x51, 0x01, 0x3f, 0x01, 0x90, 0x02, 0x90, 0x02, 0x90, 0x02, 0xd6, 0x00, 0x52, 0x01,
- 0x91, 0x02, 0x22, 0x01, 0x67, 0x01, 0x22, 0x01, 0x22, 0x01, 0x22, 0x01, 0x92, 0x02, 0x22, 0x01,
- 0x22, 0x01, 0x22, 0x01, 0x93, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x94, 0x02, 0x22, 0x01,
- 0x95, 0x02, 0x22, 0x01, 0x22, 0x01, 0x96, 0x02, 0x52, 0x02, 0x97, 0x02, 0x52, 0x01, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x98, 0x02,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x99, 0x02, 0x9a, 0x02, 0xb5, 0x00,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x51, 0x01,
- 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x9b, 0x02, 0x4c, 0x00, 0x4c, 0x00,
- 0x53, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x9c, 0x02, 0xb5, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0x9c, 0x02, 0xd6, 0x00, 0x9d, 0x02, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x53, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0x3f, 0x01, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00, 0x9e, 0x02,
- 0xd6, 0x00, 0xd6, 0x00, 0x9f, 0x02, 0xb5, 0x00, 0x9f, 0x02, 0xd6, 0x00, 0xd6, 0x00, 0xd6, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x9d, 0x02, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x49, 0x01, 0x4c, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0xd2, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0xd1, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x48, 0x02, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00,
- 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x51, 0x00, 0x69, 0x00, 0x4c, 0x00,
- 0x51, 0x00, 0xd1, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0xa0, 0x02, 0x4c, 0x00, 0xa1, 0x02, 0xa1, 0x02, 0xa1, 0x02, 0xa1, 0x02, 0xa1, 0x02, 0xa1, 0x02,
- 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00, 0x4c, 0x00,
- 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00,
- 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x23, 0x00, 0x4c, 0x00,
- 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01,
- 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01,
- 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01,
- 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0x9b, 0x01, 0xa2, 0x02
- };
-
- private static ReadOnlySpan<byte> CategoryLevel3Index => new byte[10800]
- {
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x03, 0x02, 0x04, 0x03, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x02,
- 0x05, 0x06, 0x06, 0x07, 0x08, 0x07, 0x06, 0x06, 0x09, 0x0a, 0x06, 0x0b, 0x0c, 0x0d, 0x0c, 0x0c,
- 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0c, 0x06, 0x0f, 0x0f, 0x0f, 0x06,
- 0x06, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x09, 0x06, 0x0a, 0x11, 0x12,
- 0x11, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x09, 0x0f, 0x0a, 0x0f, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x14, 0x06, 0x08, 0x08, 0x08, 0x08, 0x15, 0x06, 0x11, 0x15, 0x16, 0x17, 0x0f, 0x18, 0x15, 0x11,
- 0x19, 0x1a, 0x1b, 0x1b, 0x11, 0x13, 0x06, 0x06, 0x11, 0x1b, 0x16, 0x1c, 0x1d, 0x1d, 0x1d, 0x06,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x0f, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13,
- 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10,
- 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13,
- 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x13,
- 0x13, 0x10, 0x10, 0x13, 0x10, 0x13, 0x10, 0x10, 0x13, 0x10, 0x10, 0x10, 0x13, 0x13, 0x10, 0x10,
- 0x10, 0x10, 0x13, 0x10, 0x10, 0x13, 0x10, 0x10, 0x10, 0x13, 0x13, 0x13, 0x10, 0x10, 0x13, 0x10,
- 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x10, 0x13, 0x10, 0x13, 0x13, 0x10, 0x13, 0x10, 0x10,
- 0x13, 0x10, 0x10, 0x10, 0x13, 0x10, 0x13, 0x10, 0x10, 0x13, 0x13, 0x16, 0x10, 0x13, 0x13, 0x13,
- 0x16, 0x16, 0x16, 0x16, 0x10, 0x1e, 0x13, 0x10, 0x1e, 0x13, 0x10, 0x1e, 0x13, 0x10, 0x13, 0x10,
- 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x13, 0x10, 0x13,
- 0x13, 0x10, 0x1e, 0x13, 0x10, 0x13, 0x10, 0x10, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13,
- 0x10, 0x13, 0x10, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10, 0x10, 0x13, 0x10, 0x10, 0x13,
- 0x13, 0x10, 0x13, 0x10, 0x10, 0x10, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x16, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x20, 0x20, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
- 0x1f, 0x1f, 0x11, 0x11, 0x11, 0x11, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x1f, 0x1f, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
- 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x20, 0x11, 0x1f, 0x11,
- 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x10, 0x13, 0x10, 0x13, 0x20, 0x11, 0x10, 0x13, 0x00, 0x00, 0x1f, 0x13, 0x13, 0x13, 0x06, 0x10,
- 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x10, 0x06, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,
- 0x13, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10,
- 0x13, 0x13, 0x10, 0x10, 0x10, 0x13, 0x13, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x10, 0x13, 0x0f, 0x10, 0x13, 0x10, 0x10, 0x13, 0x13, 0x10, 0x10, 0x10,
- 0x10, 0x13, 0x22, 0x21, 0x21, 0x21, 0x21, 0x21, 0x23, 0x23, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13,
- 0x10, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x13,
- 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x24, 0x25, 0x00, 0x00, 0x15, 0x15, 0x08,
- 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x26, 0x21,
- 0x27, 0x21, 0x21, 0x27, 0x21, 0x21, 0x27, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x28,
- 0x28, 0x28, 0x28, 0x27, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x0f, 0x0f, 0x2a, 0x07, 0x07, 0x2b, 0x0c, 0x2c, 0x15, 0x15,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x2c, 0x2d, 0x00, 0x2c, 0x2c,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
- 0x2f, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x07, 0x31, 0x31, 0x2c, 0x2e, 0x2e,
- 0x21, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2c, 0x2e, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x29, 0x15, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x2f, 0x2f, 0x21, 0x21, 0x15, 0x21, 0x21, 0x21, 0x21, 0x2e, 0x2e,
- 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x2e, 0x2e, 0x2e, 0x32, 0x32, 0x2e,
- 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x00, 0x2d,
- 0x2e, 0x21, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x2e, 0x2e, 0x2e,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x34, 0x34, 0x15, 0x06, 0x06, 0x06, 0x34, 0x00, 0x00, 0x21, 0x35, 0x35,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x21, 0x21, 0x21, 0x21, 0x34, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x34, 0x21, 0x21, 0x21, 0x34, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00,
- 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x00,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x21, 0x21, 0x21, 0x00, 0x00, 0x27, 0x00,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x29, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x36, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x36, 0x21, 0x16, 0x36, 0x36,
- 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x36, 0x36, 0x36, 0x21, 0x36, 0x36,
- 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x21, 0x21, 0x24, 0x24, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37,
- 0x24, 0x1f, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x21, 0x36, 0x36, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x16,
- 0x16, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x00, 0x16, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x21, 0x16, 0x36, 0x36,
- 0x36, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x36, 0x36, 0x21, 0x16, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x00, 0x16,
- 0x16, 0x16, 0x21, 0x21, 0x00, 0x00, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37,
- 0x16, 0x16, 0x08, 0x08, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x22, 0x08, 0x16, 0x24, 0x21, 0x00,
- 0x00, 0x21, 0x21, 0x36, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x16,
- 0x16, 0x00, 0x16, 0x16, 0x00, 0x16, 0x16, 0x00, 0x16, 0x16, 0x00, 0x00, 0x21, 0x00, 0x36, 0x36,
- 0x36, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x21, 0x21, 0x00, 0x00, 0x21, 0x21, 0x21, 0x00, 0x00,
- 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37,
- 0x21, 0x21, 0x16, 0x16, 0x16, 0x21, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x21, 0x21, 0x36, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16,
- 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x00, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x21, 0x16, 0x36, 0x36,
- 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x21, 0x21, 0x36, 0x00, 0x36, 0x36, 0x21, 0x00, 0x00,
- 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x24, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x00, 0x21, 0x36, 0x36, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x16,
- 0x16, 0x00, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x21, 0x16, 0x36, 0x21,
- 0x36, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x36, 0x36, 0x21, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x36, 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x00, 0x16,
- 0x22, 0x16, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x21, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x16, 0x16,
- 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x16, 0x16, 0x00, 0x16, 0x00, 0x16, 0x16,
- 0x00, 0x00, 0x00, 0x16, 0x16, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36,
- 0x21, 0x36, 0x36, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x00, 0x36, 0x36, 0x36, 0x21, 0x00, 0x00,
- 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x38, 0x38, 0x38, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x08, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x21, 0x36, 0x36, 0x36, 0x21, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16,
- 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x16, 0x21, 0x21,
- 0x21, 0x36, 0x36, 0x36, 0x36, 0x00, 0x21, 0x21, 0x21, 0x00, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x21, 0x00, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x22,
- 0x16, 0x21, 0x36, 0x36, 0x24, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x21, 0x16, 0x36, 0x39,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x39, 0x36, 0x36, 0x00, 0x36, 0x36, 0x21, 0x21, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00,
- 0x00, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x21, 0x21, 0x36, 0x36, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x16, 0x36, 0x36,
- 0x36, 0x21, 0x21, 0x21, 0x21, 0x00, 0x36, 0x36, 0x36, 0x00, 0x36, 0x36, 0x36, 0x21, 0x16, 0x22,
- 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16, 0x36, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x16,
- 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x22, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x00, 0x00, 0x36, 0x36, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x36,
- 0x36, 0x36, 0x21, 0x21, 0x21, 0x00, 0x21, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x00, 0x00, 0x36, 0x36, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x21, 0x16, 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x08,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x1f, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x24,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x16, 0x16, 0x00, 0x16, 0x00, 0x00, 0x16, 0x16, 0x00, 0x16, 0x00, 0x00, 0x16, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x00, 0x16, 0x16, 0x16, 0x00, 0x16, 0x00, 0x16, 0x00, 0x00, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16,
- 0x16, 0x21, 0x16, 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x21, 0x21, 0x16, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x1f, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x22, 0x22, 0x22, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x22, 0x24, 0x22, 0x22, 0x22, 0x21, 0x21, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38,
- 0x38, 0x38, 0x38, 0x38, 0x22, 0x21, 0x22, 0x21, 0x22, 0x21, 0x09, 0x0a, 0x09, 0x0a, 0x36, 0x36,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00,
- 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x24, 0x21, 0x21, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x21, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00, 0x22, 0x22,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x22, 0x22, 0x22, 0x22, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x36, 0x36, 0x21, 0x21, 0x21,
- 0x21, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x21, 0x21, 0x36, 0x36, 0x21, 0x21, 0x16,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x36, 0x36, 0x21, 0x21, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21,
- 0x21, 0x16, 0x36, 0x36, 0x36, 0x16, 0x16, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x16, 0x16,
- 0x16, 0x21, 0x21, 0x21, 0x21, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x21, 0x36, 0x36, 0x21, 0x21, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x21, 0x16, 0x36,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x36, 0x36, 0x36, 0x21, 0x22, 0x22,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x24, 0x1f, 0x13, 0x13, 0x13,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00,
- 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00,
- 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x21, 0x21, 0x21,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38,
- 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00,
- 0x25, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x24, 0x24, 0x16,
- 0x05, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x09, 0x0a, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x24, 0x24, 0x24, 0x3a, 0x3a,
- 0x3a, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16,
- 0x16, 0x16, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x21, 0x21, 0x21, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x00, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x21, 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x24, 0x24, 0x24, 0x1f, 0x24, 0x24, 0x24, 0x08, 0x16, 0x21, 0x00, 0x00,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x25, 0x06, 0x06, 0x06, 0x06, 0x21, 0x21, 0x21, 0x18, 0x00,
- 0x16, 0x16, 0x16, 0x1f, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00,
- 0x21, 0x21, 0x21, 0x36, 0x36, 0x36, 0x36, 0x21, 0x21, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00,
- 0x36, 0x36, 0x21, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00,
- 0x15, 0x00, 0x00, 0x00, 0x06, 0x06, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x38, 0x00, 0x00, 0x00, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x36, 0x36, 0x21, 0x00, 0x00, 0x24, 0x24,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x36, 0x21, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00,
- 0x21, 0x36, 0x21, 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x21,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x1f, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x23, 0x00,
- 0x21, 0x21, 0x21, 0x21, 0x36, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x21, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x21, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x21, 0x36, 0x36, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00,
- 0x24, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00,
- 0x21, 0x21, 0x36, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x36, 0x21, 0x21, 0x21, 0x21, 0x36, 0x36, 0x21, 0x21, 0x36, 0x21, 0x21, 0x21, 0x16, 0x16,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x36, 0x21, 0x21, 0x36, 0x36, 0x36, 0x21, 0x36, 0x21,
- 0x21, 0x21, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x24, 0x24,
- 0x16, 0x16, 0x16, 0x16, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x36, 0x36, 0x21, 0x21, 0x00, 0x00, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x24, 0x24,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x21, 0x21, 0x21, 0x24, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x16, 0x16, 0x16, 0x16, 0x21, 0x16, 0x16,
- 0x16, 0x16, 0x36, 0x36, 0x21, 0x16, 0x16, 0x36, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x1f, 0x1f, 0x1f, 0x1f,
- 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
- 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x1f, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x13, 0x13, 0x10, 0x10, 0x10, 0x10, 0x1e, 0x11, 0x13, 0x11,
- 0x11, 0x11, 0x13, 0x13, 0x13, 0x00, 0x13, 0x13, 0x10, 0x10, 0x10, 0x10, 0x1e, 0x11, 0x11, 0x11,
- 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x13, 0x13, 0x10, 0x10, 0x10, 0x10, 0x00, 0x11, 0x11, 0x11,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10, 0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11,
- 0x00, 0x00, 0x13, 0x13, 0x13, 0x00, 0x13, 0x13, 0x10, 0x10, 0x10, 0x10, 0x1e, 0x11, 0x11, 0x00,
- 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x18, 0x18, 0x18, 0x3b, 0x3c,
- 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x06, 0x06, 0x17, 0x1c, 0x09, 0x17, 0x17, 0x1c, 0x09, 0x17,
- 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x14,
- 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06, 0x06, 0x17, 0x1c, 0x06, 0x06, 0x06, 0x06, 0x12,
- 0x12, 0x06, 0x06, 0x06, 0x44, 0x09, 0x0a, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
- 0x06, 0x06, 0x0f, 0x06, 0x12, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x45, 0x46, 0x47, 0x48, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x1b, 0x1f, 0x00, 0x00, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x0b, 0x0b, 0x0f, 0x09, 0x0a, 0x1f,
- 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x0b, 0x0b, 0x0f, 0x09, 0x0a, 0x00,
- 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00,
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x23, 0x23, 0x23,
- 0x23, 0x21, 0x23, 0x23, 0x23, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x15, 0x15, 0x10, 0x15, 0x15, 0x15, 0x15, 0x10, 0x15, 0x15, 0x13, 0x10, 0x10, 0x10, 0x13, 0x13,
- 0x10, 0x10, 0x10, 0x13, 0x15, 0x10, 0x15, 0x15, 0x0f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x10, 0x15, 0x10, 0x15, 0x10, 0x15, 0x10, 0x10, 0x10, 0x10, 0x19, 0x13,
- 0x10, 0x10, 0x10, 0x10, 0x13, 0x16, 0x16, 0x16, 0x16, 0x13, 0x15, 0x15, 0x13, 0x13, 0x10, 0x10,
- 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x10, 0x13, 0x13, 0x13, 0x13, 0x15, 0x0f, 0x15, 0x15, 0x13, 0x22,
- 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
- 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
- 0x3a, 0x3a, 0x3a, 0x10, 0x13, 0x3a, 0x3a, 0x3a, 0x3a, 0x1d, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00,
- 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x15, 0x15, 0x15, 0x15, 0x15, 0x0f, 0x0f, 0x15, 0x15, 0x15, 0x15,
- 0x0f, 0x15, 0x15, 0x0f, 0x15, 0x15, 0x0f, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x0f, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x0f, 0x0f,
- 0x15, 0x15, 0x0f, 0x15, 0x0f, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x0f, 0x0f, 0x0b, 0x1a, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x09, 0x0a, 0x09, 0x0a, 0x15, 0x15, 0x15, 0x15,
- 0x0f, 0x0f, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x09, 0x0a, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x15, 0x0f, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x22, 0x15, 0x15, 0x15, 0x15, 0x15, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x0f, 0x0f, 0x0f, 0x0f, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x0f, 0x0f, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b,
- 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x22, 0x22, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x0f, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x0f, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x0f,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x22, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a,
- 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
- 0x1d, 0x1d, 0x1d, 0x1d, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x09, 0x0a, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a,
- 0x0f, 0x0f, 0x0f, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09,
- 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x09, 0x0a, 0x09, 0x0a, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x09, 0x0a, 0x0f, 0x0f,
- 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x15, 0x15, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00,
- 0x10, 0x13, 0x10, 0x10, 0x10, 0x13, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x10, 0x10,
- 0x10, 0x13, 0x10, 0x13, 0x13, 0x10, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x1f, 0x1f, 0x10, 0x10,
- 0x10, 0x13, 0x10, 0x13, 0x13, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x10, 0x13, 0x10, 0x13, 0x21,
- 0x21, 0x21, 0x10, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x1d, 0x06, 0x06,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
- 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00,
- 0x06, 0x06, 0x17, 0x1c, 0x17, 0x1c, 0x06, 0x06, 0x06, 0x17, 0x1c, 0x06, 0x17, 0x1c, 0x06, 0x06,
- 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x25, 0x06, 0x06, 0x25, 0x06, 0x17, 0x1c, 0x06, 0x06,
- 0x17, 0x1c, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x06, 0x06, 0x06, 0x06, 0x06, 0x20,
- 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x25, 0x25, 0x06, 0x06, 0x06, 0x06,
- 0x25, 0x06, 0x09, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00,
- 0x05, 0x06, 0x06, 0x06, 0x15, 0x1f, 0x16, 0x3a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a,
- 0x09, 0x0a, 0x15, 0x15, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x25, 0x09, 0x0a, 0x0a,
- 0x15, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x21, 0x21, 0x21, 0x21, 0x36, 0x36,
- 0x25, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x15, 0x15, 0x3a, 0x3a, 0x3a, 0x1f, 0x16, 0x06, 0x15, 0x15,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x21, 0x21, 0x11, 0x11, 0x1f, 0x1f, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x06, 0x1f, 0x1f, 0x1f, 0x16,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x22, 0x22, 0x38, 0x38, 0x38, 0x38, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x15, 0x15, 0x00,
- 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38,
- 0x15, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x15, 0x15, 0x15, 0x22,
- 0x22, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x15, 0x15, 0x15, 0x15,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x15, 0x15, 0x15, 0x15, 0x22, 0x22, 0x22, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x15, 0x15,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x15,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x1f, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x1f, 0x06, 0x06, 0x06,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00,
- 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x16, 0x21,
- 0x23, 0x23, 0x23, 0x06, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x06, 0x20,
- 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x1f, 0x1f, 0x21, 0x21,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
- 0x21, 0x21, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x11, 0x11, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13,
- 0x13, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13,
- 0x1f, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x10, 0x13,
- 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x20, 0x49, 0x49, 0x10, 0x13, 0x10, 0x13, 0x16,
- 0x10, 0x13, 0x10, 0x13, 0x13, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13,
- 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x10, 0x10, 0x10, 0x10, 0x10, 0x13,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x13, 0x10, 0x13, 0x10, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x1f, 0x1f, 0x13, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x21, 0x16, 0x16, 0x16, 0x21, 0x16, 0x16, 0x16, 0x16, 0x21, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x36, 0x36, 0x21, 0x21, 0x36, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00,
- 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x22, 0x22, 0x08, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x36, 0x36, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24,
- 0x21, 0x21, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x24, 0x24, 0x24, 0x16, 0x24, 0x16, 0x16, 0x21,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x24, 0x24,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24,
- 0x16, 0x16, 0x16, 0x21, 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x36, 0x36, 0x21, 0x36, 0x36, 0x36,
- 0x36, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x1f,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x1f, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36,
- 0x36, 0x21, 0x21, 0x36, 0x36, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x21, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x36, 0x00, 0x00,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x00, 0x00, 0x24, 0x24, 0x24, 0x24,
- 0x1f, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x22, 0x22, 0x22, 0x16, 0x36, 0x21, 0x36, 0x16, 0x16,
- 0x21, 0x16, 0x21, 0x21, 0x21, 0x16, 0x16, 0x21, 0x21, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21,
- 0x16, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x1f, 0x24, 0x24,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x36, 0x21, 0x21, 0x36, 0x36,
- 0x24, 0x24, 0x16, 0x1f, 0x1f, 0x36, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00,
- 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x49, 0x1f, 0x1f, 0x1f, 0x1f,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x36, 0x36, 0x21, 0x36, 0x36, 0x21, 0x36, 0x36, 0x24, 0x36, 0x21, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a,
- 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x21, 0x28,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x0b, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x28, 0x00,
- 0x28, 0x28, 0x00, 0x28, 0x28, 0x00, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
- 0x2e, 0x2e, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,
- 0x4c, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x0a, 0x09,
- 0x00, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2b, 0x15, 0x00, 0x00,
- 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x09, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x06, 0x25, 0x25, 0x12, 0x12, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x09,
- 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x06, 0x06, 0x09, 0x0a, 0x06, 0x06, 0x06, 0x06, 0x12, 0x12, 0x12,
- 0x0c, 0x06, 0x0c, 0x00, 0x06, 0x0c, 0x06, 0x06, 0x25, 0x09, 0x0a, 0x09, 0x0a, 0x09, 0x0a, 0x07,
- 0x06, 0x06, 0x0b, 0x0d, 0x0f, 0x0f, 0x0f, 0x00, 0x06, 0x08, 0x07, 0x06, 0x00, 0x00, 0x00, 0x00,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x00, 0x18,
- 0x00, 0x06, 0x06, 0x07, 0x08, 0x07, 0x06, 0x06, 0x09, 0x0a, 0x06, 0x0b, 0x0c, 0x0d, 0x0c, 0x0c,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x09, 0x0f, 0x0a, 0x0f, 0x09,
- 0x0a, 0x06, 0x09, 0x0a, 0x06, 0x06, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x1f, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x1f, 0x1f,
- 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00,
- 0x08, 0x08, 0x0f, 0x11, 0x15, 0x08, 0x08, 0x00, 0x15, 0x0f, 0x0f, 0x0f, 0x0f, 0x15, 0x15, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x4d, 0x4d, 0x15, 0x15, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16, 0x00, 0x16,
- 0x24, 0x06, 0x24, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38,
- 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38,
- 0x38, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
- 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e,
- 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x1d, 0x1d, 0x1d, 0x1d, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x1d, 0x1d, 0x15, 0x22, 0x22, 0x00,
- 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x21, 0x00, 0x00,
- 0x21, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b,
- 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00, 0x00, 0x00, 0x00,
- 0x38, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16,
- 0x16, 0x3a, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x24,
- 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x24, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x28, 0x00, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x28, 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x28,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x27, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x50, 0x50, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x28, 0x28, 0x28, 0x00, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x00, 0x00, 0x00, 0x06,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x4f, 0x28, 0x28,
- 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x00, 0x00, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x28, 0x21, 0x21, 0x21, 0x00, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x21, 0x21, 0x21,
- 0x28, 0x28, 0x28, 0x28, 0x00, 0x28, 0x28, 0x28, 0x00, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x21,
- 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4f, 0x4f, 0x27,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4f, 0x4f, 0x4f,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x50, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27, 0x27, 0x27, 0x27, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51,
- 0x51, 0x51, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52,
- 0x52, 0x52, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53,
- 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0x00,
- 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x21, 0x54, 0x54, 0x54, 0x54, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x36, 0x21, 0x36, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00,
- 0x00, 0x00, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
- 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21,
- 0x36, 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x36, 0x36, 0x21, 0x21, 0x24, 0x24, 0x3b, 0x24, 0x24,
- 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00,
- 0x21, 0x21, 0x21, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37,
- 0x24, 0x24, 0x24, 0x24, 0x16, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x21, 0x24, 0x24, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x36, 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36,
- 0x36, 0x16, 0x16, 0x16, 0x16, 0x24, 0x24, 0x24, 0x24, 0x21, 0x21, 0x21, 0x21, 0x24, 0x00, 0x00,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x16, 0x24, 0x16, 0x24, 0x24, 0x24,
- 0x00, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38,
- 0x38, 0x38, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x36, 0x36, 0x36, 0x21,
- 0x21, 0x21, 0x36, 0x36, 0x21, 0x36, 0x21, 0x21, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x21, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21,
- 0x36, 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x21, 0x21, 0x36, 0x36, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x16,
- 0x16, 0x00, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x21, 0x21, 0x16, 0x36, 0x36,
- 0x21, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x36, 0x36, 0x36, 0x00, 0x00,
- 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x36, 0x36, 0x00, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x36, 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x36, 0x36, 0x21, 0x21, 0x21, 0x36, 0x21, 0x16, 0x16, 0x16, 0x16, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x00, 0x24, 0x00, 0x24, 0x21, 0x00,
- 0x36, 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x21, 0x36, 0x36, 0x36, 0x36, 0x21,
- 0x21, 0x36, 0x21, 0x21, 0x16, 0x16, 0x24, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x36,
- 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x21, 0x21, 0x36, 0x21,
- 0x21, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x00, 0x00,
- 0x36, 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x36, 0x21, 0x36, 0x21,
- 0x21, 0x24, 0x24, 0x24, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21, 0x36, 0x21, 0x36, 0x36,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x36, 0x36, 0x21, 0x21, 0x21, 0x21, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x38, 0x38, 0x24, 0x24, 0x24, 0x22,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x21, 0x21, 0x24, 0x00, 0x00, 0x00, 0x00,
- 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16,
- 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x39, 0x39, 0x21, 0x21, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x16, 0x21, 0x21, 0x21, 0x21, 0x24,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x36, 0x21, 0x21, 0x21, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x16, 0x16, 0x16, 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x21, 0x21, 0x24, 0x24, 0x24, 0x16, 0x24, 0x24,
- 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x36, 0x39,
- 0x16, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x24, 0x24, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x00, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x36, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x36, 0x21, 0x21, 0x36, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x21, 0x00, 0x21, 0x21, 0x00, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x16, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x16, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00,
- 0x21, 0x21, 0x00, 0x36, 0x36, 0x21, 0x36, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x21, 0x21, 0x36, 0x36, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x00,
- 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x24, 0x24, 0x24, 0x24, 0x24, 0x22, 0x22, 0x22, 0x22,
- 0x1f, 0x1f, 0x1f, 0x1f, 0x24, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x00, 0x38, 0x38, 0x38, 0x38, 0x38,
- 0x38, 0x38, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x16, 0x16,
- 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00,
- 0x21, 0x21, 0x21, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
- 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x22, 0x21, 0x21, 0x24,
- 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x36, 0x36, 0x21, 0x21, 0x21, 0x22, 0x22, 0x22, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x22, 0x22, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x22, 0x22, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x21, 0x21, 0x21, 0x21, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x15, 0x15, 0x21, 0x21, 0x21, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x38, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x10, 0x10, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10, 0x00, 0x10, 0x10,
- 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x13, 0x13, 0x13, 0x13, 0x00, 0x13, 0x00, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x00, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x00, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x55, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x0f, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x55, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x0f, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x55, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x0f,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x55,
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x0f, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x55, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
- 0x13, 0x13, 0x13, 0x0f, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x10, 0x13, 0x00, 0x00, 0x0e, 0x0e,
- 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x22, 0x22, 0x22, 0x22, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x22, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x21, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x22, 0x21, 0x22, 0x22, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21,
- 0x21, 0x21, 0x00, 0x21, 0x21, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f,
- 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x51, 0x51, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52,
- 0x52, 0x52, 0x52, 0x52, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, 0x00, 0x27, 0x27,
- 0x00, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54,
- 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54,
- 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x54, 0x32, 0x54, 0x54, 0x54,
- 0x2b, 0x54, 0x54, 0x54, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
- 0x00, 0x2e, 0x2e, 0x00, 0x2e, 0x00, 0x00, 0x2e, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
- 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x2e, 0x00, 0x2e, 0x00, 0x2e, 0x2e, 0x2e,
- 0x00, 0x2e, 0x2e, 0x00, 0x2e, 0x00, 0x00, 0x2e, 0x00, 0x2e, 0x00, 0x2e, 0x00, 0x2e, 0x00, 0x2e,
- 0x00, 0x2e, 0x2e, 0x00, 0x2e, 0x00, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x2e, 0x2e, 0x2e,
- 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x00,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
- 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x00, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
- 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
- 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1d, 0x1d, 0x00, 0x00, 0x00,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
- 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
- 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x11, 0x11, 0x11, 0x11, 0x11,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00,
- 0x15, 0x00, 0x00, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x15, 0x00, 0x15, 0x15, 0x15, 0x15,
- 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x00, 0x00
- };
-
- private static ReadOnlySpan<byte> CategoriesValue => new byte[172]
- {
- 0x1d, 0x00, 0x0e, 0x0e, 0x0e, 0x10, 0x0e, 0x0f, 0x0e, 0x11, 0x0b, 0x11, 0x18, 0x12, 0x18, 0x0a,
- 0x1a, 0x0a, 0x14, 0x12, 0x15, 0x12, 0x19, 0x09, 0x18, 0x0c, 0x13, 0x09, 0x08, 0x08, 0x19, 0x12,
- 0x00, 0x00, 0x1b, 0x12, 0x12, 0x12, 0x01, 0x00, 0x0b, 0x0c, 0x1c, 0x12, 0x04, 0x00, 0x16, 0x12,
- 0x0f, 0x0e, 0x1c, 0x0a, 0x19, 0x0a, 0x0a, 0x08, 0x17, 0x12, 0x0a, 0x12, 0x02, 0x00, 0x03, 0x00,
- 0x03, 0x12, 0x05, 0x0d, 0x1c, 0x00, 0x07, 0x0d, 0x18, 0x00, 0x13, 0x12, 0x13, 0x03, 0x18, 0x03,
- 0x04, 0x03, 0x0f, 0x0b, 0x19, 0x04, 0x1a, 0x04, 0x18, 0x04, 0x0f, 0x04, 0x04, 0x04, 0x03, 0x04,
- 0x08, 0x0b, 0x18, 0x0b, 0x1c, 0x04, 0x08, 0x03, 0x03, 0x03, 0x1a, 0x03, 0x06, 0x00, 0x08, 0x00,
- 0x0a, 0x00, 0x05, 0x00, 0x09, 0x00, 0x0f, 0x00, 0x0f, 0x03, 0x0c, 0x11, 0x0d, 0x0f, 0x0f, 0x01,
- 0x0f, 0x05, 0x0f, 0x07, 0x0f, 0x02, 0x0f, 0x06, 0x19, 0x0c, 0x0f, 0x13, 0x0f, 0x14, 0x0f, 0x15,
- 0x0f, 0x16, 0x1b, 0x00, 0x10, 0x00, 0x11, 0x00, 0x1b, 0x04, 0x0f, 0x12, 0x09, 0x12, 0x0a, 0x03,
- 0x1c, 0x03, 0x00, 0x03, 0x01, 0x03, 0x0a, 0x0b, 0x0a, 0x04, 0x19, 0x00
- };
-
- // 12:4:4 index table of the Unicode numeric data.
- private static ReadOnlySpan<byte> NumericLevel1Index => new byte[761]
- {
- 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x03, 0x01, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
- 0x0b, 0x01, 0x01, 0x0c, 0x01, 0x01, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x01, 0x01, 0x01,
- 0x14, 0x15, 0x01, 0x01, 0x16, 0x01, 0x01, 0x17, 0x01, 0x01, 0x01, 0x01, 0x18, 0x01, 0x01, 0x01,
- 0x19, 0x1a, 0x1b, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1c, 0x01, 0x1d, 0x1e, 0x1f, 0x20, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x21, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0f,
- 0x01, 0x22, 0x23, 0x24, 0x25, 0x01, 0x01, 0x01, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
- 0x2e, 0x2f, 0x20, 0x01, 0x09, 0x01, 0x30, 0x31, 0x32, 0x01, 0x01, 0x01, 0x33, 0x34, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x35, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x36, 0x37, 0x01, 0x01, 0x38, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x39, 0x3a, 0x01, 0x01, 0x01, 0x3b, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x3c, 0x1f, 0x01, 0x01, 0x3d, 0x01, 0x01, 0x01,
- 0x01, 0x3e, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x3f
- };
-
- private static ReadOnlySpan<byte> NumericLevel2Index => new byte[1024]
- {
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x03, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
- 0x00, 0x00, 0x0a, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x0f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10,
- 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x15, 0x15, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x18, 0x19, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x1c,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x1e, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
- 0x21, 0x00, 0x22, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x25, 0x00, 0x26, 0x27, 0x00, 0x00, 0x25, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x00,
- 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x2c, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x2e, 0x00, 0x2f,
- 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x3a,
- 0x00, 0x00, 0x3b, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x3f, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x41,
- 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x44, 0x45, 0x46, 0x47,
- 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x49, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x4b, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x50, 0x51, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x39, 0x55,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x58,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x66,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x69, 0x6a, 0x6b,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x6c, 0x6d, 0x6e, 0x6f, 0x00, 0x00, 0x00, 0x00,
- 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
- };
-
- private static ReadOnlySpan<byte> NumericLevel3Index => new byte[1824]
- {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x0e, 0x0f, 0x10, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
- 0x00, 0x00, 0x00, 0x00, 0x11, 0x12, 0x13, 0x0e, 0x10, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x15, 0x16, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x19, 0x1a, 0x1b, 0x19, 0x1a, 0x1b, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x00,
- 0x15, 0x16, 0x17, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0f, 0x23, 0x24, 0x25, 0x26, 0x27,
- 0x28, 0x29, 0x2a, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e, 0x2f,
- 0x30, 0x31, 0x15, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x16, 0x3a, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x3c,
- 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x18, 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x44, 0x00, 0x00, 0x00, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x44, 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x45, 0x46, 0x20, 0x47, 0x48, 0x22, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x12, 0x4e, 0x4f, 0x50, 0x19,
- 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x15, 0x51, 0x52, 0x35, 0x16, 0x53, 0x17,
- 0x17, 0x54, 0x3a, 0x00, 0x00, 0x40, 0x35, 0x55, 0x56, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x15, 0x51, 0x52, 0x57, 0x58, 0x59, 0x14,
- 0x3b, 0x3c, 0x3d, 0x32, 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x15, 0x51, 0x52,
- 0x57, 0x58, 0x59, 0x14, 0x3b, 0x3c, 0x3d, 0x32, 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
- 0x31, 0x15, 0x51, 0x52, 0x57, 0x58, 0x59, 0x14, 0x3b, 0x3c, 0x3d, 0x32, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x51, 0x52, 0x57, 0x58, 0x59,
- 0x14, 0x3b, 0x3c, 0x3d, 0x32, 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x15, 0x44,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x15,
- 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x15, 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e,
- 0x2f, 0x30, 0x31, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x19, 0x1a, 0x1b, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
- 0x00, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x33, 0x63, 0x64, 0x65, 0x66, 0x67,
- 0x00, 0x68, 0x69, 0x6a, 0x6b, 0x34, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x35,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x18,
- 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,
- 0x15, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x16, 0x75, 0x76, 0x77, 0x53, 0x78, 0x79,
- 0x7a, 0x7b, 0x17, 0x7c, 0x7d, 0x7e, 0x54, 0x7f, 0x80, 0x81, 0x82, 0x3a, 0x83, 0x84, 0x85, 0x55,
- 0x86, 0x87, 0x88, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x0e, 0x0f, 0x19, 0x3f, 0x35, 0x53, 0x54, 0x55, 0x3f, 0x15, 0x35, 0x16, 0x53, 0x17, 0x54, 0x3f,
- 0x15, 0x35, 0x16, 0x53, 0x17, 0x3a, 0x55, 0x15, 0x19, 0x19, 0x19, 0x1a, 0x1a, 0x1a, 0x1a, 0x3f,
- 0x15, 0x15, 0x15, 0x15, 0x15, 0x33, 0x35, 0x35, 0x35, 0x35, 0x16, 0x76, 0x53, 0x53, 0x53, 0x53,
- 0x53, 0x17, 0x54, 0x3f, 0x35, 0x0f, 0x0f, 0x48, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x15, 0x32, 0x33, 0x34, 0x35, 0x36,
- 0x37, 0x38, 0x39, 0x16, 0x75, 0x76, 0x77, 0x53, 0x78, 0x79, 0x7a, 0x7b, 0x00, 0x00, 0x00, 0x00,
- 0x19, 0x3f, 0x15, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x19, 0x1a, 0x15, 0x32, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x1a, 0x1b, 0x15, 0x32, 0x16, 0x17, 0x3a,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x15, 0x32,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x1a, 0x1b, 0x3e, 0x3e, 0x3f, 0x15, 0x32, 0x16,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x3f, 0x15, 0x32, 0x16,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x15, 0x32, 0x16, 0x1a, 0x1b, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x0f, 0x00, 0x00,
- 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x15, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
- 0x00, 0x00, 0x16, 0x75, 0x76, 0x77, 0x53, 0x78, 0x79, 0x7a, 0x7b, 0x17, 0x7c, 0x7d, 0x7e, 0x54,
- 0x7f, 0x80, 0x81, 0x82, 0x3a, 0x83, 0x84, 0x85, 0x55, 0x86, 0x87, 0x88, 0x89, 0x56, 0x8b, 0x8c,
- 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c,
- 0x0d, 0x0b, 0x0c, 0x2c, 0x15, 0x32, 0x16, 0x17, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x35, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x15, 0x32,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x1a, 0x1b, 0x3e, 0x15, 0x32, 0x16, 0x17,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x1a, 0x1b, 0x3e, 0x15, 0x32, 0x16,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x3f, 0x15, 0x35, 0x16, 0x17,
- 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x15, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
- 0x38, 0x39, 0x16, 0x75, 0x76, 0x77, 0x53, 0x78, 0x79, 0x7a, 0x7b, 0x0f, 0x0e, 0x47, 0x48, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x1a, 0x1b,
- 0x3e, 0x3f, 0x15, 0x32, 0x33, 0x16, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x19, 0x15, 0x32, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x15, 0x32, 0x33, 0x34, 0x35,
- 0x36, 0x37, 0x38, 0x39, 0x16, 0x17, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
- 0x37, 0x38, 0x39, 0x16, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x15, 0x32, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x15, 0x32, 0x33, 0x34, 0x35, 0x36,
- 0x37, 0x38, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40,
- 0x41, 0x42, 0x43, 0x15, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x16, 0x00, 0x00, 0x00,
- 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x3e,
- 0x3f, 0x40, 0x41, 0x42, 0x43, 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x19, 0x1a,
- 0x1b, 0x3e, 0x3f, 0x1a, 0x1b, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x19, 0x1a, 0x1b, 0x1b,
- 0x3e, 0x3f, 0x9d, 0x9e, 0x19, 0x1a, 0x1b, 0x1b, 0x3e, 0x3f, 0x1b, 0x1b, 0x3e, 0x3e, 0x3e, 0x3e,
- 0x40, 0x41, 0x41, 0x41, 0x42, 0x42, 0x43, 0x43, 0x43, 0x43, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x19,
- 0x1a, 0x1b, 0x3e, 0x3e, 0x3f, 0x3f, 0x1a, 0x1b, 0x19, 0x1a, 0x47, 0x48, 0x4d, 0x47, 0x48, 0x12,
- 0x0e, 0x4c, 0x0e, 0x0e, 0x0f, 0x47, 0x48, 0x34, 0x35, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x00,
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x00, 0x15, 0x16, 0x3a, 0x9f, 0xa0,
- 0xa1, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x18, 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x15, 0x51, 0x52, 0x57, 0x58, 0x59,
- 0x14, 0x3b, 0x3c, 0x3d, 0x19, 0x1a, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x14, 0x3b, 0x3c, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x38, 0x39, 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x19, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
- 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x09, 0x0a, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x01, 0x02, 0x03, 0x04,
- 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
- 0x37, 0x38, 0x39, 0x16, 0x75, 0x76, 0x77, 0x53, 0x78, 0x79, 0x7a, 0x7b, 0x17, 0x7c, 0x7d, 0x7e,
- 0x54, 0x7f, 0x80, 0x81, 0x82, 0x3a, 0x83, 0x84, 0x85, 0x55, 0x86, 0x87, 0x88, 0x89, 0x56, 0x8b,
- 0x56, 0xa3, 0xa4, 0x19, 0x1a, 0x1b, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x00, 0x0e, 0x0f, 0x10,
- 0x00, 0x19, 0x1a, 0x3a, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x44, 0x44, 0x0d, 0x0b, 0x0c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x18, 0x18, 0x00, 0x00, 0x00,
- 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
- };
-
- // Every item contains the value for numeric value.
- private static ReadOnlySpan<byte> NumericValues => new byte[1320]
- {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xbf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x3f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x3f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x8f, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40,
- 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0x79, 0x3f, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x3f,
- 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0xa3, 0x3f, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xa9, 0x3f,
- 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xb9, 0x3f, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0xc3, 0x3f,
- 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xc9, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xbf,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x51, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x56, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0xc3, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92, 0x24, 0x49, 0x92, 0x24, 0x49, 0xc2, 0x3f,
- 0x1c, 0xc7, 0x71, 0x1c, 0xc7, 0x71, 0xbc, 0x3f, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xd5, 0x3f,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xe5, 0x3f, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xd9, 0x3f,
- 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0xe3, 0x3f, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xe9, 0x3f,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xc5, 0x3f, 0xab, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xea, 0x3f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x3f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7f, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0xb3, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6a, 0xe8, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x6a, 0xf8, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x41, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x42, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x43, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x44, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x45, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x46, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x47, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x48, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x72, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x82, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x85, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x8c, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x9f, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xa7, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xaf, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xb7, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0xbb, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xbf, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0xc1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0xd3, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0xdd, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0xe3, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0xed, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xf1, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0xf3, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf9, 0xf5, 0x40,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xed, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6a, 0x08, 0x41,
- 0x00, 0x00, 0x00, 0x00, 0x80, 0x4f, 0x12, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6a, 0x18, 0x41,
- 0x00, 0x00, 0x00, 0x00, 0x80, 0x84, 0x1e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x80, 0x4f, 0x22, 0x41,
- 0x00, 0x00, 0x00, 0x00, 0xc0, 0x5c, 0x25, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6a, 0x28, 0x41,
- 0x00, 0x00, 0x00, 0x00, 0x40, 0x77, 0x2b, 0x41, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xb5, 0x3f,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xc5, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x3f,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xd5, 0x3f, 0xab, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xda, 0x3f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f, 0xab, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xe2, 0x3f,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xe5, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0x3f,
- 0xab, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xea, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5e, 0x0a, 0x41,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x5e, 0x1a, 0x41, 0x00, 0x00, 0x00, 0x00, 0x80, 0x84, 0x2e, 0x41,
- 0x00, 0x00, 0x00, 0x00, 0x84, 0xd7, 0x97, 0x41, 0x00, 0x00, 0x00, 0x20, 0x5f, 0xa0, 0x02, 0x42,
- 0x00, 0x00, 0x00, 0xa2, 0x94, 0x1a, 0x6d, 0x42, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x12, 0x63, 0x41,
- 0x00, 0x00, 0x00, 0x00, 0xd0, 0x12, 0x73, 0x41
- };
-
- private static ReadOnlySpan<byte> DigitValues => new byte[330]
- {
- 0xff, 0xff, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06,
- 0x07, 0x07, 0x08, 0x08, 0x09, 0x09, 0xff, 0x02, 0xff, 0x03, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x04, 0xff, 0x05, 0xff, 0x06, 0xff, 0x07,
- 0xff, 0x08, 0xff, 0x09, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
- };
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/ChineseLunisolarCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/ChineseLunisolarCalendar.cs
deleted file mode 100644
index 01c6133d404..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/ChineseLunisolarCalendar.cs
+++ /dev/null
@@ -1,302 +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.
-
-namespace System.Globalization
-{
- /// <remarks>
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 1901/02/19 2101/01/28
- /// ChineseLunisolar 1901/01/01 2100/12/29
- /// </remarks>
-
- public class ChineseLunisolarCalendar : EastAsianLunisolarCalendar
- {
- public const int ChineseEra = 1;
-
- private const int MinLunisolarYear = 1901;
- private const int MaxLunisolarYear = 2100;
-
- private static readonly DateTime s_minDate = new DateTime(1901, 2, 19);
- private static readonly DateTime s_maxDate = new DateTime((new DateTime(2101, 1, 28, 23, 59, 59, 999)).Ticks + 9999);
-
- public override DateTime MinSupportedDateTime => s_minDate;
-
- public override DateTime MaxSupportedDateTime => s_maxDate;
-
- protected override int DaysInYearBeforeMinSupportedYear =>
- // 1900: 1-29 2-30 3-29 4-29 5-30 6-29 7-30 8-30 Leap8-29 9-30 10-30 11-29 12-30 from Calendrical Tabulations [1]
- // [1] Reingold, Edward M, and Nachum Dershowitz. Calendrical Tabulations, 1900 - 2200.Cambridge: Cambridge Univ. Press, 2002.Print.
- 384;
-
- // Data for years 1901-1905 and 1907-2100 matches output of Calendrical Calculations [2] and published calendar tables [3].
- // For 1906, month 4 of the Chinese year starts on 24 Apr 1906 and has 29 days. This is historially accurate
- // but different to the values in [1] and output from [2]. This is due to a change in the astronomical methods used
- // by the Chinese to calculate the calendar from 1913 onwards (see warnings in [1]).
- // [2] Reingold, Edward M, and Nachum Dershowitz. Calendrical Calculations: The Ultimate Edition. Cambridge [etc.: Cambridge University Press, 2018. Print.
- // [3] Wang, Jianmin. Xin Bian Wan Nian Li: (1840-2050) Chong Bian Ben. Beijing: Ke xue pu ji chu ban she, 1990. Print.
- private static readonly int[,] s_yinfo =
- {
-/*Y LM Lmon Lday DaysPerMonth D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 D12 D13 #Days
-1901 */ { 00, 02, 19, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1902 */ { 00, 02, 08, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1903 */ { 05, 01, 29, 0b0101001001101000 }, /* 29 30 29 30 29 29 30 29 29 30 30 29 30 383
-1904 */ { 00, 02, 16, 0b1101001001100000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 354
-1905 */ { 00, 02, 04, 0b1101100101010000 }, /* 30 30 29 30 30 29 29 30 29 30 29 30 355
-1906 */ { 04, 01, 25, 0b0110101010101000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 30 384
-1907 */ { 00, 02, 13, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1908 */ { 00, 02, 02, 0b1001101011010000 }, /* 30 29 29 30 30 29 30 29 30 30 29 30 355
-1909 */ { 02, 01, 22, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1910 */ { 00, 02, 10, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1911 */ { 06, 01, 30, 0b1010010011011000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 30 384
-1912 */ { 00, 02, 18, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1913 */ { 00, 02, 06, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-1914 */ { 05, 01, 26, 0b1101010100101000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 30 384
-1915 */ { 00, 02, 14, 0b1011010101000000 }, /* 30 29 30 30 29 30 29 30 29 30 29 29 354
-1916 */ { 00, 02, 03, 0b1101011010100000 }, /* 30 30 29 30 29 30 30 29 30 29 30 29 355
-1917 */ { 02, 01, 23, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 29 384
-1918 */ { 00, 02, 11, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1919 */ { 07, 02, 01, 0b0100100110111000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 30 384
-1920 */ { 00, 02, 20, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1921 */ { 00, 02, 08, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1922 */ { 05, 01, 28, 0b1011001001011000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384
-1923 */ { 00, 02, 16, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 354
-1924 */ { 00, 02, 05, 0b0110110101000000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 354
-1925 */ { 04, 01, 24, 0b1010110110101000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 30 385
-1926 */ { 00, 02, 13, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1927 */ { 00, 02, 02, 0b1001010101110000 }, /* 30 29 29 30 29 30 29 30 29 30 30 30 355
-1928 */ { 02, 01, 23, 0b0100100101111000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 30 384
-1929 */ { 00, 02, 10, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1930 */ { 06, 01, 30, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 29 383
-1931 */ { 00, 02, 17, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1932 */ { 00, 02, 06, 0b1110101001010000 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 355
-1933 */ { 05, 01, 26, 0b0110110101001000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 30 384
-1934 */ { 00, 02, 14, 0b0101101011010000 }, /* 29 30 29 30 30 29 30 29 30 30 29 30 355
-1935 */ { 00, 02, 04, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1936 */ { 03, 01, 24, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 29 384
-1937 */ { 00, 02, 11, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1938 */ { 07, 01, 31, 0b1100100101101000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 30 384
-1939 */ { 00, 02, 19, 0b1100100101010000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 354
-1940 */ { 00, 02, 08, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1941 */ { 06, 01, 27, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 29 384
-1942 */ { 00, 02, 15, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1943 */ { 00, 02, 05, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1944 */ { 04, 01, 25, 0b1010101011011000 }, /* 30 29 30 29 30 29 30 29 30 30 29 30 30 385
-1945 */ { 00, 02, 13, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-1946 */ { 00, 02, 02, 0b1001001011010000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 354
-1947 */ { 02, 01, 22, 0b1100100101011000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 30 384
-1948 */ { 00, 02, 10, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1949 */ { 07, 01, 29, 0b1011010010101000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 30 384
-1950 */ { 00, 02, 17, 0b0110110010100000 }, /* 29 30 30 29 30 30 29 29 30 29 30 29 354
-1951 */ { 00, 02, 06, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1952 */ { 05, 01, 27, 0b0101010110101000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 30 384
-1953 */ { 00, 02, 14, 0b0100110110100000 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 354
-1954 */ { 00, 02, 03, 0b1010010110110000 }, /* 30 29 30 29 29 30 29 30 30 29 30 30 355
-1955 */ { 03, 01, 24, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-1956 */ { 00, 02, 12, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1957 */ { 08, 01, 31, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 29 383
-1958 */ { 00, 02, 18, 0b1110100101010000 }, /* 30 30 30 29 30 29 29 30 29 30 29 30 355
-1959 */ { 00, 02, 08, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1960 */ { 06, 01, 28, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-1961 */ { 00, 02, 15, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1962 */ { 00, 02, 05, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-1963 */ { 04, 01, 25, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-1964 */ { 00, 02, 13, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1965 */ { 00, 02, 02, 0b0101001001100000 }, /* 29 30 29 30 29 29 30 29 29 30 30 29 353
-1966 */ { 03, 01, 21, 0b1110100100110000 }, /* 30 30 30 29 30 29 29 30 29 29 30 30 29 384
-1967 */ { 00, 02, 09, 0b1101100101010000 }, /* 30 30 29 30 30 29 29 30 29 30 29 30 355
-1968 */ { 07, 01, 30, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-1969 */ { 00, 02, 17, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1970 */ { 00, 02, 06, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355
-1971 */ { 05, 01, 27, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1972 */ { 00, 02, 15, 0b0100101011010000 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 354
-1973 */ { 00, 02, 03, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1974 */ { 04, 01, 23, 0b1101001001101000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384
-1975 */ { 00, 02, 11, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-1976 */ { 08, 01, 31, 0b1101010100101000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 30 384
-1977 */ { 00, 02, 18, 0b1011010101000000 }, /* 30 29 30 30 29 30 29 30 29 30 29 29 354
-1978 */ { 00, 02, 07, 0b1011011010100000 }, /* 30 29 30 30 29 30 30 29 30 29 30 29 355
-1979 */ { 06, 01, 28, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 29 384
-1980 */ { 00, 02, 16, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1981 */ { 00, 02, 05, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1982 */ { 04, 01, 25, 0b1010010010111000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384
-1983 */ { 00, 02, 13, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1984 */ { 10, 02, 02, 0b1011001001011000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384
-1985 */ { 00, 02, 20, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 354
-1986 */ { 00, 02, 09, 0b0110110101000000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 354
-1987 */ { 06, 01, 29, 0b1010110110100000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 29 384
-1988 */ { 00, 02, 17, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-1989 */ { 00, 02, 06, 0b1001010101110000 }, /* 30 29 29 30 29 30 29 30 29 30 30 30 355
-1990 */ { 05, 01, 27, 0b0100100101111000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 30 384
-1991 */ { 00, 02, 15, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1992 */ { 00, 02, 04, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-1993 */ { 03, 01, 23, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383
-1994 */ { 00, 02, 10, 0b1110101001010000 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 355
-1995 */ { 08, 01, 31, 0b0110101100101000 }, /* 29 30 30 29 30 29 30 30 29 29 30 29 30 384
-1996 */ { 00, 02, 19, 0b0101101011000000 }, /* 29 30 29 30 30 29 30 29 30 30 29 29 354
-1997 */ { 00, 02, 07, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-1998 */ { 05, 01, 28, 0b1001001101101000 }, /* 30 29 29 30 29 29 30 30 29 30 30 29 30 384
-1999 */ { 00, 02, 16, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-2000 */ { 00, 02, 05, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-2001 */ { 04, 01, 24, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-2002 */ { 00, 02, 12, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-2003 */ { 00, 02, 01, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 355
-2004 */ { 02, 01, 22, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-2005 */ { 00, 02, 09, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-2006 */ { 07, 01, 29, 0b1010101011011000 }, /* 30 29 30 29 30 29 30 29 30 30 29 30 30 385
-2007 */ { 00, 02, 18, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-2008 */ { 00, 02, 07, 0b1001001011010000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 354
-2009 */ { 05, 01, 26, 0b1100100101011000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 30 384
-2010 */ { 00, 02, 14, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-2011 */ { 00, 02, 03, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-2012 */ { 04, 01, 23, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-2013 */ { 00, 02, 10, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-2014 */ { 09, 01, 31, 0b0101010110101000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 30 384
-2015 */ { 00, 02, 19, 0b0100101110100000 }, /* 29 30 29 29 30 29 30 30 30 29 30 29 354
-2016 */ { 00, 02, 08, 0b1010010110110000 }, /* 30 29 30 29 29 30 29 30 30 29 30 30 355
-2017 */ { 06, 01, 28, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-2018 */ { 00, 02, 16, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-2019 */ { 00, 02, 05, 0b1010100100110000 }, /* 30 29 30 29 30 29 29 30 29 29 30 30 354
-2020 */ { 04, 01, 25, 0b0111010010101000 }, /* 29 30 30 30 29 30 29 29 30 29 30 29 30 384
-2021 */ { 00, 02, 12, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-2022 */ { 00, 02, 01, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-2023 */ { 02, 01, 22, 0b0100110110101000 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 30 384
-2024 */ { 00, 02, 10, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-2025 */ { 06, 01, 29, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-2026 */ { 00, 02, 17, 0b1010010011100000 }, /* 30 29 30 29 29 30 29 29 30 30 30 29 354
-2027 */ { 00, 02, 06, 0b1101001001100000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 354
-2028 */ { 05, 01, 26, 0b1110100100110000 }, /* 30 30 30 29 30 29 29 30 29 29 30 30 29 384
-2029 */ { 00, 02, 13, 0b1101010100110000 }, /* 30 30 29 30 29 30 29 30 29 29 30 30 355
-2030 */ { 00, 02, 03, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-2031 */ { 03, 01, 23, 0b0110101101010000 }, /* 29 30 30 29 30 29 30 30 29 30 29 30 29 384
-2032 */ { 00, 02, 11, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355
-2033 */ { 11, 01, 31, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-2034 */ { 00, 02, 19, 0b0100101011010000 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 354
-2035 */ { 00, 02, 08, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-2036 */ { 06, 01, 28, 0b1101001001011000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 30 384
-2037 */ { 00, 02, 15, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-2038 */ { 00, 02, 04, 0b1101010100100000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 354
-2039 */ { 05, 01, 24, 0b1101101010100000 }, /* 30 30 29 30 30 29 30 29 30 29 30 29 29 384
-2040 */ { 00, 02, 12, 0b1011010110100000 }, /* 30 29 30 30 29 30 29 30 30 29 30 29 355
-2041 */ { 00, 02, 01, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-2042 */ { 02, 01, 22, 0b0100101011011000 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 30 384
-2043 */ { 00, 02, 10, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-2044 */ { 07, 01, 30, 0b1010010010111000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384
-2045 */ { 00, 02, 17, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-2046 */ { 00, 02, 06, 0b1010101001010000 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 354
-2047 */ { 05, 01, 26, 0b1011010100101000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 30 384
-2048 */ { 00, 02, 14, 0b0110110100100000 }, /* 29 30 30 29 30 30 29 30 29 29 30 29 354
-2049 */ { 00, 02, 02, 0b1010110110100000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 355
-2050 */ { 03, 01, 23, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 29 384
-2051 */ { 00, 02, 11, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 355
-2052 */ { 08, 02, 01, 0b0100100101111000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 30 384
-2053 */ { 00, 02, 19, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-2054 */ { 00, 02, 08, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-2055 */ { 06, 01, 28, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383
-2056 */ { 00, 02, 15, 0b1110101001010000 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 355
-2057 */ { 00, 02, 04, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-2058 */ { 04, 01, 24, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 29 384
-2059 */ { 00, 02, 12, 0b1010101011100000 }, /* 30 29 30 29 30 29 30 29 30 30 30 29 355
-2060 */ { 00, 02, 02, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-2061 */ { 03, 01, 21, 0b1100100101110000 }, /* 30 30 29 29 30 29 29 30 29 30 30 30 29 384
-2062 */ { 00, 02, 09, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-2063 */ { 07, 01, 29, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-2064 */ { 00, 02, 17, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-2065 */ { 00, 02, 05, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 355
-2066 */ { 05, 01, 26, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-2067 */ { 00, 02, 14, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-2068 */ { 00, 02, 03, 0b1010011011010000 }, /* 30 29 30 29 29 30 30 29 30 30 29 30 355
-2069 */ { 04, 01, 23, 0b0101001011101000 }, /* 29 30 29 30 29 29 30 29 30 30 30 29 30 384
-2070 */ { 00, 02, 11, 0b0101001011010000 }, /* 29 30 29 30 29 29 30 29 30 30 29 30 354
-2071 */ { 08, 01, 31, 0b1010100101011000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 30 384
-2072 */ { 00, 02, 19, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-2073 */ { 00, 02, 07, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-2074 */ { 06, 01, 27, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-2075 */ { 00, 02, 15, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-2076 */ { 00, 02, 05, 0b0101010110100000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 354
-2077 */ { 04, 01, 24, 0b1010010111010000 }, /* 30 29 30 29 29 30 29 30 30 30 29 30 29 384
-2078 */ { 00, 02, 12, 0b1010010110110000 }, /* 30 29 30 29 29 30 29 30 30 29 30 30 355
-2079 */ { 00, 02, 02, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-2080 */ { 03, 01, 22, 0b1010100100111000 }, /* 30 29 30 29 30 29 29 30 29 29 30 30 30 384
-2081 */ { 00, 02, 09, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 354
-2082 */ { 07, 01, 29, 0b0111001010011000 }, /* 29 30 30 30 29 29 30 29 30 29 29 30 30 384
-2083 */ { 00, 02, 17, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-2084 */ { 00, 02, 06, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-2085 */ { 05, 01, 26, 0b0100110110101000 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 30 384
-2086 */ { 00, 02, 14, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-2087 */ { 00, 02, 03, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-2088 */ { 04, 01, 24, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 29 383
-2089 */ { 00, 02, 10, 0b1101000101100000 }, /* 30 30 29 30 29 29 29 30 29 30 30 29 354
-2090 */ { 08, 01, 30, 0b1110100100110000 }, /* 30 30 30 29 30 29 29 30 29 29 30 30 29 384
-2091 */ { 00, 02, 18, 0b1101010100100000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 354
-2092 */ { 00, 02, 07, 0b1101101010100000 }, /* 30 30 29 30 30 29 30 29 30 29 30 29 355
-2093 */ { 06, 01, 27, 0b0110101101010000 }, /* 29 30 30 29 30 29 30 30 29 30 29 30 29 384
-2094 */ { 00, 02, 15, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-2095 */ { 00, 02, 05, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-2096 */ { 04, 01, 25, 0b1010010011101000 }, /* 30 29 30 29 29 30 29 29 30 30 30 29 30 384
-2097 */ { 00, 02, 12, 0b1010001011010000 }, /* 30 29 30 29 29 29 30 29 30 30 29 30 354
-2098 */ { 00, 02, 01, 0b1101000101010000 }, /* 30 30 29 30 29 29 29 30 29 30 29 30 354
-2099 */ { 02, 01, 21, 0b1101100100101000 }, /* 30 30 29 30 30 29 29 30 29 29 30 29 30 384
-2100 */ { 00, 02, 09, 0b1101010100100000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 354
- */ };
-
- internal override int MinCalendarYear => MinLunisolarYear;
-
- internal override int MaxCalendarYear => MaxLunisolarYear;
-
- internal override DateTime MinDate => s_minDate;
-
- internal override DateTime MaxDate => s_maxDate;
-
- internal override EraInfo[]? CalEraInfo => null;
-
- internal override int GetYearInfo(int lunarYear, int index)
- {
- if (lunarYear < MinLunisolarYear || lunarYear > MaxLunisolarYear)
- {
- throw new ArgumentOutOfRangeException("year", lunarYear, SR.Format(SR.ArgumentOutOfRange_Range, MinLunisolarYear, MaxLunisolarYear));
- }
-
- return s_yinfo[lunarYear - MinLunisolarYear, index];
- }
-
- internal override int GetYear(int year, DateTime time)
- {
- return year;
- }
-
- internal override int GetGregorianYear(int year, int era)
- {
- if (era != CurrentEra && era != ChineseEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- if (year < MinLunisolarYear || year > MaxLunisolarYear)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.Format(SR.ArgumentOutOfRange_Range, MinLunisolarYear, MaxLunisolarYear));
- }
-
- return year;
- }
-
- public ChineseLunisolarCalendar()
- {
- }
-
- public override int GetEra(DateTime time)
- {
- CheckTicksRange(time.Ticks);
- return ChineseEra;
- }
-
- internal override CalendarId ID => CalendarId.CHINESELUNISOLAR;
-
- internal override CalendarId BaseCalendarID =>
- // Use CAL_GREGORIAN just to get CurrentEraValue as 1 since we do not have data under the ID CAL_ChineseLunisolar yet
- CalendarId.GREGORIAN;
-
- public override int[] Eras => new int[] { ChineseEra };
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Invariant.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Invariant.cs
deleted file mode 100644
index 92a962b5273..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Invariant.cs
+++ /dev/null
@@ -1,249 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Globalization
-{
- public partial class CompareInfo
- {
- internal static unsafe int InvariantIndexOf(string source, string value, int startIndex, int count, bool ignoreCase)
- {
- Debug.Assert(source != null);
- Debug.Assert(value != null);
- Debug.Assert(startIndex >= 0 && startIndex < source.Length);
-
- fixed (char* pSource = source) fixed (char* pValue = value)
- {
- char* pSrc = &pSource[startIndex];
- int index = InvariantFindString(pSrc, count, pValue, value.Length, ignoreCase, fromBeginning: true);
- if (index >= 0)
- {
- return index + startIndex;
- }
- return -1;
- }
- }
-
- internal static unsafe int InvariantIndexOf(ReadOnlySpan<char> source, ReadOnlySpan<char> value, bool ignoreCase, bool fromBeginning = true)
- {
- Debug.Assert(source.Length != 0);
- Debug.Assert(value.Length != 0);
-
- fixed (char* pSource = &MemoryMarshal.GetReference(source))
- fixed (char* pValue = &MemoryMarshal.GetReference(value))
- {
- return InvariantFindString(pSource, source.Length, pValue, value.Length, ignoreCase, fromBeginning);
- }
- }
-
- internal static unsafe int InvariantLastIndexOf(string source, string value, int startIndex, int count, bool ignoreCase)
- {
- Debug.Assert(source != null);
- Debug.Assert(value != null);
- Debug.Assert(startIndex >= 0 && startIndex < source.Length);
-
- fixed (char* pSource = source) fixed (char* pValue = value)
- {
- char* pSrc = &pSource[startIndex - count + 1];
- int index = InvariantFindString(pSrc, count, pValue, value.Length, ignoreCase, fromBeginning: false);
- if (index >= 0)
- {
- return index + startIndex - count + 1;
- }
- return -1;
- }
- }
-
- private static unsafe int InvariantFindString(char* source, int sourceCount, char* value, int valueCount, bool ignoreCase, bool fromBeginning)
- {
- int ctrSource = 0; // index value into source
- int ctrValue = 0; // index value into value
- char sourceChar; // Character for case lookup in source
- char valueChar; // Character for case lookup in value
- int lastSourceStart;
-
- Debug.Assert(source != null);
- Debug.Assert(value != null);
- Debug.Assert(sourceCount >= 0);
- Debug.Assert(valueCount >= 0);
-
- if (valueCount == 0)
- {
- return fromBeginning ? 0 : sourceCount - 1;
- }
-
- if (sourceCount < valueCount)
- {
- return -1;
- }
-
- if (fromBeginning)
- {
- lastSourceStart = sourceCount - valueCount;
- if (ignoreCase)
- {
- char firstValueChar = InvariantToUpper(value[0]);
- for (ctrSource = 0; ctrSource <= lastSourceStart; ctrSource++)
- {
- sourceChar = InvariantToUpper(source[ctrSource]);
- if (sourceChar != firstValueChar)
- {
- continue;
- }
-
- for (ctrValue = 1; ctrValue < valueCount; ctrValue++)
- {
- sourceChar = InvariantToUpper(source[ctrSource + ctrValue]);
- valueChar = InvariantToUpper(value[ctrValue]);
-
- if (sourceChar != valueChar)
- {
- break;
- }
- }
-
- if (ctrValue == valueCount)
- {
- return ctrSource;
- }
- }
- }
- else
- {
- char firstValueChar = value[0];
- for (ctrSource = 0; ctrSource <= lastSourceStart; ctrSource++)
- {
- sourceChar = source[ctrSource];
- if (sourceChar != firstValueChar)
- {
- continue;
- }
-
- for (ctrValue = 1; ctrValue < valueCount; ctrValue++)
- {
- sourceChar = source[ctrSource + ctrValue];
- valueChar = value[ctrValue];
-
- if (sourceChar != valueChar)
- {
- break;
- }
- }
-
- if (ctrValue == valueCount)
- {
- return ctrSource;
- }
- }
- }
- }
- else
- {
- lastSourceStart = sourceCount - valueCount;
- if (ignoreCase)
- {
- char firstValueChar = InvariantToUpper(value[0]);
- for (ctrSource = lastSourceStart; ctrSource >= 0; ctrSource--)
- {
- sourceChar = InvariantToUpper(source[ctrSource]);
- if (sourceChar != firstValueChar)
- {
- continue;
- }
- for (ctrValue = 1; ctrValue < valueCount; ctrValue++)
- {
- sourceChar = InvariantToUpper(source[ctrSource + ctrValue]);
- valueChar = InvariantToUpper(value[ctrValue]);
-
- if (sourceChar != valueChar)
- {
- break;
- }
- }
-
- if (ctrValue == valueCount)
- {
- return ctrSource;
- }
- }
- }
- else
- {
- char firstValueChar = value[0];
- for (ctrSource = lastSourceStart; ctrSource >= 0; ctrSource--)
- {
- sourceChar = source[ctrSource];
- if (sourceChar != firstValueChar)
- {
- continue;
- }
-
- for (ctrValue = 1; ctrValue < valueCount; ctrValue++)
- {
- sourceChar = source[ctrSource + ctrValue];
- valueChar = value[ctrValue];
-
- if (sourceChar != valueChar)
- {
- break;
- }
- }
-
- if (ctrValue == valueCount)
- {
- return ctrSource;
- }
- }
- }
- }
-
- return -1;
- }
-
- private static char InvariantToUpper(char c)
- {
- return (uint)(c - 'a') <= (uint)('z' - 'a') ? (char)(c - 0x20) : c;
- }
-
- private unsafe SortKey InvariantCreateSortKey(string source, CompareOptions options)
- {
- if (source == null) { throw new ArgumentNullException(nameof(source)); }
-
- if ((options & ValidSortkeyCtorMaskOffFlags) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
-
- byte[] keyData;
- if (source.Length == 0)
- {
- keyData = Array.Empty<byte>();
- }
- else
- {
- // In the invariant mode, all string comparisons are done as ordinal so when generating the sort keys we generate it according to this fact
- keyData = new byte[source.Length * sizeof(char)];
-
- fixed (char* pChar = source) fixed (byte* pByte = keyData)
- {
- if ((options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0)
- {
- short* pShort = (short*)pByte;
- for (int i = 0; i < source.Length; i++)
- {
- pShort[i] = (short)InvariantToUpper(source[i]);
- }
- }
- else
- {
- Buffer.MemoryCopy(pChar, pByte, keyData.Length, keyData.Length);
- }
- }
- }
- return new SortKey(Name, source, options, keyData);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs
deleted file mode 100644
index f77c3913cae..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs
+++ /dev/null
@@ -1,1148 +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 System.Buffers;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Security;
-using System.Threading;
-
-using Internal.Runtime.CompilerServices;
-
-namespace System.Globalization
-{
- public partial class CompareInfo
- {
- [NonSerialized]
- private IntPtr _sortHandle;
-
- [NonSerialized]
- private bool _isAsciiEqualityOrdinal;
-
- private void InitSort(CultureInfo culture)
- {
- _sortName = culture.SortName;
-
- if (GlobalizationMode.Invariant)
- {
- _isAsciiEqualityOrdinal = true;
- }
- else
- {
- // Inline the following condition to avoid potential implementation cycles within globalization
- //
- // _isAsciiEqualityOrdinal = _sortName == "" || _sortName == "en" || _sortName.StartsWith("en-", StringComparison.Ordinal);
- //
- _isAsciiEqualityOrdinal = _sortName.Length == 0 ||
- (_sortName.Length >= 2 && _sortName[0] == 'e' && _sortName[1] == 'n' && (_sortName.Length == 2 || _sortName[2] == '-'));
-
- _sortHandle = SortHandleCache.GetCachedSortHandle(_sortName);
- }
- }
-
- internal static unsafe int IndexOfOrdinalCore(string source, string value, int startIndex, int count, bool ignoreCase)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(source != null);
- Debug.Assert(value != null);
-
- if (value.Length == 0)
- {
- return startIndex;
- }
-
- if (count < value.Length)
- {
- return -1;
- }
-
- if (ignoreCase)
- {
- fixed (char* pSource = source)
- {
- int index = Interop.Globalization.IndexOfOrdinalIgnoreCase(value, value.Length, pSource + startIndex, count, findLast: false);
- return index != -1 ?
- startIndex + index :
- -1;
- }
- }
-
- int endIndex = startIndex + (count - value.Length);
- for (int i = startIndex; i <= endIndex; i++)
- {
- int valueIndex, sourceIndex;
-
- for (valueIndex = 0, sourceIndex = i;
- valueIndex < value.Length && source[sourceIndex] == value[valueIndex];
- valueIndex++, sourceIndex++) ;
-
- if (valueIndex == value.Length)
- {
- return i;
- }
- }
-
- return -1;
- }
-
- internal static unsafe int IndexOfOrdinalCore(ReadOnlySpan<char> source, ReadOnlySpan<char> value, bool ignoreCase, bool fromBeginning)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(source.Length != 0);
- Debug.Assert(value.Length != 0);
-
- if (source.Length < value.Length)
- {
- return -1;
- }
-
- if (ignoreCase)
- {
- fixed (char* pSource = &MemoryMarshal.GetReference(source))
- fixed (char* pValue = &MemoryMarshal.GetReference(value))
- {
- return Interop.Globalization.IndexOfOrdinalIgnoreCase(pValue, value.Length, pSource, source.Length, findLast: !fromBeginning);
- }
- }
-
- int startIndex, endIndex, jump;
- if (fromBeginning)
- {
- // Left to right, from zero to last possible index in the source string.
- // Incrementing by one after each iteration. Stop condition is last possible index plus 1.
- startIndex = 0;
- endIndex = source.Length - value.Length + 1;
- jump = 1;
- }
- else
- {
- // Right to left, from first possible index in the source string to zero.
- // Decrementing by one after each iteration. Stop condition is last possible index minus 1.
- startIndex = source.Length - value.Length;
- endIndex = -1;
- jump = -1;
- }
-
- for (int i = startIndex; i != endIndex; i += jump)
- {
- int valueIndex, sourceIndex;
-
- for (valueIndex = 0, sourceIndex = i;
- valueIndex < value.Length && source[sourceIndex] == value[valueIndex];
- valueIndex++, sourceIndex++)
- ;
-
- if (valueIndex == value.Length)
- {
- return i;
- }
- }
-
- return -1;
- }
-
- internal static unsafe int LastIndexOfOrdinalCore(string source, string value, int startIndex, int count, bool ignoreCase)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(source != null);
- Debug.Assert(value != null);
-
- if (value.Length == 0)
- {
- return startIndex;
- }
-
- if (count < value.Length)
- {
- return -1;
- }
-
- // startIndex is the index into source where we start search backwards from.
- // leftStartIndex is the index into source of the start of the string that is
- // count characters away from startIndex.
- int leftStartIndex = startIndex - count + 1;
-
- if (ignoreCase)
- {
- fixed (char* pSource = source)
- {
- int lastIndex = Interop.Globalization.IndexOfOrdinalIgnoreCase(value, value.Length, pSource + leftStartIndex, count, findLast: true);
- return lastIndex != -1 ?
- leftStartIndex + lastIndex :
- -1;
- }
- }
-
- for (int i = startIndex - value.Length + 1; i >= leftStartIndex; i--)
- {
- int valueIndex, sourceIndex;
-
- for (valueIndex = 0, sourceIndex = i;
- valueIndex < value.Length && source[sourceIndex] == value[valueIndex];
- valueIndex++, sourceIndex++) ;
-
- if (valueIndex == value.Length) {
- return i;
- }
- }
-
- return -1;
- }
-
- private static unsafe int CompareStringOrdinalIgnoreCase(ref char string1, int count1, ref char string2, int count2)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- fixed (char* char1 = &string1)
- fixed (char* char2 = &string2)
- {
- return Interop.Globalization.CompareStringOrdinalIgnoreCase(char1, count1, char2, count2);
- }
- }
-
- // TODO https://github.com/dotnet/coreclr/issues/13827:
- // This method shouldn't be necessary, as we should be able to just use the overload
- // that takes two spans. But due to this issue, that's adding significant overhead.
- private unsafe int CompareString(ReadOnlySpan<char> string1, string string2, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(string2 != null);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- fixed (char* pString1 = &MemoryMarshal.GetReference(string1))
- fixed (char* pString2 = &string2.GetRawStringData())
- {
- return Interop.Globalization.CompareString(_sortHandle, pString1, string1.Length, pString2, string2.Length, options);
- }
- }
-
- private unsafe int CompareString(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- fixed (char* pString1 = &MemoryMarshal.GetReference(string1))
- fixed (char* pString2 = &MemoryMarshal.GetReference(string2))
- {
- return Interop.Globalization.CompareString(_sortHandle, pString1, string1.Length, pString2, string2.Length, options);
- }
- }
-
- internal unsafe int IndexOfCore(string source, string target, int startIndex, int count, CompareOptions options, int* matchLengthPtr)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!string.IsNullOrEmpty(source));
- Debug.Assert(target != null);
- Debug.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
- Debug.Assert((options & CompareOptions.Ordinal) == 0);
-
- int index;
-
- if (_isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions(options))
- {
- if ((options & CompareOptions.IgnoreCase) != 0)
- index = IndexOfOrdinalIgnoreCaseHelper(source.AsSpan(startIndex, count), target.AsSpan(), options, matchLengthPtr, fromBeginning: true);
- else
- index = IndexOfOrdinalHelper(source.AsSpan(startIndex, count), target.AsSpan(), options, matchLengthPtr, fromBeginning: true);
- }
- else
- {
- fixed (char* pSource = source)
- fixed (char* pTarget = target)
- {
- index = Interop.Globalization.IndexOf(_sortHandle, pTarget, target.Length, pSource + startIndex, count, options, matchLengthPtr);
- }
- }
-
- return index != -1 ? index + startIndex : -1;
- }
-
- // For now, this method is only called from Span APIs with either options == CompareOptions.None or CompareOptions.IgnoreCase
- internal unsafe int IndexOfCore(ReadOnlySpan<char> source, ReadOnlySpan<char> target, CompareOptions options, int* matchLengthPtr, bool fromBeginning)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(source.Length != 0);
- Debug.Assert(target.Length != 0);
-
- if (_isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions(options))
- {
- if ((options & CompareOptions.IgnoreCase) != 0)
- return IndexOfOrdinalIgnoreCaseHelper(source, target, options, matchLengthPtr, fromBeginning);
- else
- return IndexOfOrdinalHelper(source, target, options, matchLengthPtr, fromBeginning);
- }
- else
- {
- fixed (char* pSource = &MemoryMarshal.GetReference(source))
- fixed (char* pTarget = &MemoryMarshal.GetReference(target))
- {
- if (fromBeginning)
- return Interop.Globalization.IndexOf(_sortHandle, pTarget, target.Length, pSource, source.Length, options, matchLengthPtr);
- else
- return Interop.Globalization.LastIndexOf(_sortHandle, pTarget, target.Length, pSource, source.Length, options);
- }
- }
- }
-
- /// <summary>
- /// Duplicate of IndexOfOrdinalHelper that also handles ignore case. Can't converge both methods
- /// as the JIT wouldn't be able to optimize the ignoreCase path away.
- /// </summary>
- /// <returns></returns>
- private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> target, CompareOptions options, int* matchLengthPtr, bool fromBeginning)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!target.IsEmpty);
- Debug.Assert(_isAsciiEqualityOrdinal);
-
- fixed (char* ap = &MemoryMarshal.GetReference(source))
- fixed (char* bp = &MemoryMarshal.GetReference(target))
- {
- char* a = ap;
- char* b = bp;
-
- for (int j = 0; j < target.Length; j++)
- {
- char targetChar = *(b + j);
- if (targetChar >= 0x80 || HighCharTable[targetChar])
- goto InteropCall;
- }
-
- if (target.Length > source.Length)
- {
- for (int k = 0; k < source.Length; k++)
- {
- char targetChar = *(a + k);
- if (targetChar >= 0x80 || HighCharTable[targetChar])
- goto InteropCall;
- }
- return -1;
- }
-
- int startIndex, endIndex, jump;
- if (fromBeginning)
- {
- // Left to right, from zero to last possible index in the source string.
- // Incrementing by one after each iteration. Stop condition is last possible index plus 1.
- startIndex = 0;
- endIndex = source.Length - target.Length + 1;
- jump = 1;
- }
- else
- {
- // Right to left, from first possible index in the source string to zero.
- // Decrementing by one after each iteration. Stop condition is last possible index minus 1.
- startIndex = source.Length - target.Length;
- endIndex = -1;
- jump = -1;
- }
-
- for (int i = startIndex; i != endIndex; i += jump)
- {
- int targetIndex = 0;
- int sourceIndex = i;
-
- for (; targetIndex < target.Length; targetIndex++, sourceIndex++)
- {
- char valueChar = *(a + sourceIndex);
- char targetChar = *(b + targetIndex);
-
- if (valueChar >= 0x80 || HighCharTable[valueChar])
- goto InteropCall;
-
- if (valueChar == targetChar)
- {
- continue;
- }
-
- // uppercase both chars - notice that we need just one compare per char
- if ((uint)(valueChar - 'a') <= ('z' - 'a'))
- valueChar = (char)(valueChar - 0x20);
- if ((uint)(targetChar - 'a') <= ('z' - 'a'))
- targetChar = (char)(targetChar - 0x20);
-
- if (valueChar == targetChar)
- {
- continue;
- }
-
- // The match may be affected by special character. Verify that the following character is regular ASCII.
- if (sourceIndex < source.Length - 1 && *(a + sourceIndex + 1) >= 0x80)
- goto InteropCall;
- goto Next;
- }
-
- // The match may be affected by special character. Verify that the following character is regular ASCII.
- if (sourceIndex < source.Length && *(a + sourceIndex) >= 0x80)
- goto InteropCall;
- if (matchLengthPtr != null)
- *matchLengthPtr = target.Length;
- return i;
-
- Next: ;
- }
-
- return -1;
-
- InteropCall:
- if (fromBeginning)
- return Interop.Globalization.IndexOf(_sortHandle, b, target.Length, a, source.Length, options, matchLengthPtr);
- else
- return Interop.Globalization.LastIndexOf(_sortHandle, b, target.Length, a, source.Length, options);
- }
- }
-
- private unsafe int IndexOfOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> target, CompareOptions options, int* matchLengthPtr, bool fromBeginning)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!target.IsEmpty);
- Debug.Assert(_isAsciiEqualityOrdinal);
-
- fixed (char* ap = &MemoryMarshal.GetReference(source))
- fixed (char* bp = &MemoryMarshal.GetReference(target))
- {
- char* a = ap;
- char* b = bp;
-
- for (int j = 0; j < target.Length; j++)
- {
- char targetChar = *(b + j);
- if (targetChar >= 0x80 || HighCharTable[targetChar])
- goto InteropCall;
- }
-
- if (target.Length > source.Length)
- {
- for (int k = 0; k < source.Length; k++)
- {
- char targetChar = *(a + k);
- if (targetChar >= 0x80 || HighCharTable[targetChar])
- goto InteropCall;
- }
- return -1;
- }
-
- int startIndex, endIndex, jump;
- if (fromBeginning)
- {
- // Left to right, from zero to last possible index in the source string.
- // Incrementing by one after each iteration. Stop condition is last possible index plus 1.
- startIndex = 0;
- endIndex = source.Length - target.Length + 1;
- jump = 1;
- }
- else
- {
- // Right to left, from first possible index in the source string to zero.
- // Decrementing by one after each iteration. Stop condition is last possible index minus 1.
- startIndex = source.Length - target.Length;
- endIndex = -1;
- jump = -1;
- }
-
- for (int i = startIndex; i != endIndex; i += jump)
- {
- int targetIndex = 0;
- int sourceIndex = i;
-
- for (; targetIndex < target.Length; targetIndex++, sourceIndex++)
- {
- char valueChar = *(a + sourceIndex);
- char targetChar = *(b + targetIndex);
-
- if (valueChar >= 0x80 || HighCharTable[valueChar])
- goto InteropCall;
-
- if (valueChar == targetChar)
- {
- continue;
- }
-
- // The match may be affected by special character. Verify that the following character is regular ASCII.
- if (sourceIndex < source.Length - 1 && *(a + sourceIndex + 1) >= 0x80)
- goto InteropCall;
- goto Next;
- }
-
- // The match may be affected by special character. Verify that the following character is regular ASCII.
- if (sourceIndex < source.Length && *(a + sourceIndex) >= 0x80)
- goto InteropCall;
- if (matchLengthPtr != null)
- *matchLengthPtr = target.Length;
- return i;
-
- Next: ;
- }
-
- return -1;
-
- InteropCall:
- if (fromBeginning)
- return Interop.Globalization.IndexOf(_sortHandle, b, target.Length, a, source.Length, options, matchLengthPtr);
- else
- return Interop.Globalization.LastIndexOf(_sortHandle, b, target.Length, a, source.Length, options);
- }
- }
-
- private unsafe int LastIndexOfCore(string source, string target, int startIndex, int count, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!string.IsNullOrEmpty(source));
- Debug.Assert(target != null);
- Debug.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
-
- if (target.Length == 0)
- {
- return startIndex;
- }
-
- if (options == CompareOptions.Ordinal)
- {
- return LastIndexOfOrdinalCore(source, target, startIndex, count, ignoreCase: false);
- }
-
- // startIndex is the index into source where we start search backwards from. leftStartIndex is the index into source
- // of the start of the string that is count characters away from startIndex.
- int leftStartIndex = (startIndex - count + 1);
-
- int lastIndex;
-
- if (_isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions(options))
- {
- if ((options & CompareOptions.IgnoreCase) != 0)
- lastIndex = IndexOfOrdinalIgnoreCaseHelper(source.AsSpan(leftStartIndex, count), target.AsSpan(), options, matchLengthPtr: null, fromBeginning: false);
- else
- lastIndex = IndexOfOrdinalHelper(source.AsSpan(leftStartIndex, count), target.AsSpan(), options, matchLengthPtr: null, fromBeginning: false);
- }
- else
- {
- fixed (char* pSource = source)
- fixed (char* pTarget = target)
- {
- lastIndex = Interop.Globalization.LastIndexOf(_sortHandle, pTarget, target.Length, pSource + (startIndex - count + 1), count, options);
- }
- }
-
- return lastIndex != -1 ? lastIndex + leftStartIndex : -1;
- }
-
- private unsafe bool StartsWith(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!prefix.IsEmpty);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- if (_isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions(options))
- {
- if ((options & CompareOptions.IgnoreCase) != 0)
- return StartsWithOrdinalIgnoreCaseHelper(source, prefix, options);
- else
- return StartsWithOrdinalHelper(source, prefix, options);
- }
- else
- {
- fixed (char* pSource = &MemoryMarshal.GetReference(source))
- fixed (char* pPrefix = &MemoryMarshal.GetReference(prefix))
- {
- return Interop.Globalization.StartsWith(_sortHandle, pPrefix, prefix.Length, pSource, source.Length, options);
- }
- }
- }
-
- private unsafe bool StartsWithOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!prefix.IsEmpty);
- Debug.Assert(_isAsciiEqualityOrdinal);
-
- int length = Math.Min(source.Length, prefix.Length);
-
- fixed (char* ap = &MemoryMarshal.GetReference(source))
- fixed (char* bp = &MemoryMarshal.GetReference(prefix))
- {
- char* a = ap;
- char* b = bp;
-
- while (length != 0)
- {
- int charA = *a;
- int charB = *b;
-
- if (charA >= 0x80 || charB >= 0x80 || HighCharTable[charA] || HighCharTable[charB])
- goto InteropCall;
-
- if (charA == charB)
- {
- a++; b++;
- length--;
- continue;
- }
-
- // uppercase both chars - notice that we need just one compare per char
- if ((uint)(charA - 'a') <= (uint)('z' - 'a')) charA -= 0x20;
- if ((uint)(charB - 'a') <= (uint)('z' - 'a')) charB -= 0x20;
-
- if (charA == charB)
- {
- a++; b++;
- length--;
- continue;
- }
-
- // The match may be affected by special character. Verify that the following character is regular ASCII.
- if (a < ap + source.Length - 1 && *(a + 1) >= 0x80)
- goto InteropCall;
- if (b < bp + prefix.Length - 1 && *(b + 1) >= 0x80)
- goto InteropCall;
- return false;
- }
-
- // The match may be affected by special character. Verify that the following character is regular ASCII.
-
- if (source.Length < prefix.Length)
- {
- if (*b >= 0x80)
- goto InteropCall;
- return false;
- }
-
- if (source.Length > prefix.Length)
- {
- if (*a >= 0x80)
- goto InteropCall;
- }
- return true;
-
- InteropCall:
- return Interop.Globalization.StartsWith(_sortHandle, bp, prefix.Length, ap, source.Length, options);
- }
- }
-
- private unsafe bool StartsWithOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!prefix.IsEmpty);
- Debug.Assert(_isAsciiEqualityOrdinal);
-
- int length = Math.Min(source.Length, prefix.Length);
-
- fixed (char* ap = &MemoryMarshal.GetReference(source))
- fixed (char* bp = &MemoryMarshal.GetReference(prefix))
- {
- char* a = ap;
- char* b = bp;
-
- while (length != 0)
- {
- int charA = *a;
- int charB = *b;
-
- if (charA >= 0x80 || charB >= 0x80 || HighCharTable[charA] || HighCharTable[charB])
- goto InteropCall;
-
- if (charA == charB)
- {
- a++; b++;
- length--;
- continue;
- }
-
- // The match may be affected by special character. Verify that the following character is regular ASCII.
- if (a < ap + source.Length - 1 && *(a + 1) >= 0x80)
- goto InteropCall;
- if (b < bp + prefix.Length - 1 && *(b + 1) >= 0x80)
- goto InteropCall;
- return false;
- }
-
- // The match may be affected by special character. Verify that the following character is regular ASCII.
-
- if (source.Length < prefix.Length)
- {
- if (*b >= 0x80)
- goto InteropCall;
- return false;
- }
-
- if (source.Length > prefix.Length)
- {
- if (*a >= 0x80)
- goto InteropCall;
- }
- return true;
-
- InteropCall:
- return Interop.Globalization.StartsWith(_sortHandle, bp, prefix.Length, ap, source.Length, options);
- }
- }
-
- private unsafe bool EndsWith(ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!suffix.IsEmpty);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- if (_isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions(options))
- {
- if ((options & CompareOptions.IgnoreCase) != 0)
- return EndsWithOrdinalIgnoreCaseHelper(source, suffix, options);
- else
- return EndsWithOrdinalHelper(source, suffix, options);
- }
- else
- {
- fixed (char* pSource = &MemoryMarshal.GetReference(source))
- fixed (char* pSuffix = &MemoryMarshal.GetReference(suffix))
- {
- return Interop.Globalization.EndsWith(_sortHandle, pSuffix, suffix.Length, pSource, source.Length, options);
- }
- }
- }
-
- private unsafe bool EndsWithOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!suffix.IsEmpty);
- Debug.Assert(_isAsciiEqualityOrdinal);
-
- int length = Math.Min(source.Length, suffix.Length);
-
- fixed (char* ap = &MemoryMarshal.GetReference(source))
- fixed (char* bp = &MemoryMarshal.GetReference(suffix))
- {
- char* a = ap + source.Length - 1;
- char* b = bp + suffix.Length - 1;
-
- while (length != 0)
- {
- int charA = *a;
- int charB = *b;
-
- if (charA >= 0x80 || charB >= 0x80 || HighCharTable[charA] || HighCharTable[charB])
- goto InteropCall;
-
- if (charA == charB)
- {
- a--; b--;
- length--;
- continue;
- }
-
- // uppercase both chars - notice that we need just one compare per char
- if ((uint)(charA - 'a') <= (uint)('z' - 'a')) charA -= 0x20;
- if ((uint)(charB - 'a') <= (uint)('z' - 'a')) charB -= 0x20;
-
- if (charA == charB)
- {
- a--; b--;
- length--;
- continue;
- }
-
- return false;
- }
-
- return (source.Length >= suffix.Length);
-
- InteropCall:
- return Interop.Globalization.EndsWith(_sortHandle, bp, suffix.Length, ap, source.Length, options);
- }
- }
-
- private unsafe bool EndsWithOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!suffix.IsEmpty);
- Debug.Assert(_isAsciiEqualityOrdinal);
-
- int length = Math.Min(source.Length, suffix.Length);
-
- fixed (char* ap = &MemoryMarshal.GetReference(source))
- fixed (char* bp = &MemoryMarshal.GetReference(suffix))
- {
- char* a = ap + source.Length - 1;
- char* b = bp + suffix.Length - 1;
-
- while (length != 0)
- {
- int charA = *a;
- int charB = *b;
-
- if (charA >= 0x80 || charB >= 0x80 || HighCharTable[charA] || HighCharTable[charB])
- goto InteropCall;
-
- if (charA == charB)
- {
- a--; b--;
- length--;
- continue;
- }
-
- return false;
- }
-
- return (source.Length >= suffix.Length);
-
- InteropCall:
- return Interop.Globalization.EndsWith(_sortHandle, bp, suffix.Length, ap, source.Length, options);
- }
- }
-
- private unsafe SortKey CreateSortKey(string source, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- if (source==null) { throw new ArgumentNullException(nameof(source)); }
-
- if ((options & ValidSortkeyCtorMaskOffFlags) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
-
- byte [] keyData;
- if (source.Length == 0)
- {
- keyData = Array.Empty<byte>();
- }
- else
- {
- fixed (char* pSource = source)
- {
- int sortKeyLength = Interop.Globalization.GetSortKey(_sortHandle, pSource, source.Length, null, 0, options);
- keyData = new byte[sortKeyLength];
-
- fixed (byte* pSortKey = keyData)
- {
- if (Interop.Globalization.GetSortKey(_sortHandle, pSource, source.Length, pSortKey, sortKeyLength, options) != sortKeyLength)
- {
- throw new ArgumentException(SR.Arg_ExternalException);
- }
- }
- }
- }
-
- return new SortKey(Name, source, options, keyData);
- }
-
- private static unsafe bool IsSortable(char *text, int length)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- int index = 0;
- UnicodeCategory uc;
-
- while (index < length)
- {
- if (char.IsHighSurrogate(text[index]))
- {
- if (index == length - 1 || !char.IsLowSurrogate(text[index+1]))
- return false; // unpaired surrogate
-
- uc = CharUnicodeInfo.GetUnicodeCategory(char.ConvertToUtf32(text[index], text[index+1]));
- if (uc == UnicodeCategory.PrivateUse || uc == UnicodeCategory.OtherNotAssigned)
- return false;
-
- index += 2;
- continue;
- }
-
- if (char.IsLowSurrogate(text[index]))
- {
- return false; // unpaired surrogate
- }
-
- uc = CharUnicodeInfo.GetUnicodeCategory(text[index]);
- if (uc == UnicodeCategory.PrivateUse || uc == UnicodeCategory.OtherNotAssigned)
- {
- return false;
- }
-
- index++;
- }
-
- return true;
- }
-
- // -----------------------------
- // ---- PAL layer ends here ----
- // -----------------------------
-
- internal unsafe int GetHashCodeOfStringCore(ReadOnlySpan<char> source, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- if (source.Length == 0)
- {
- return 0;
- }
-
- // according to ICU User Guide the performance of ucol_getSortKey is worse when it is called with null output buffer
- // the solution is to try to fill the sort key in a temporary buffer of size equal 4 x string length
- // 1MB is the biggest array that can be rented from ArrayPool.Shared without memory allocation
- int sortKeyLength = (source.Length > 1024 * 1024 / 4) ? 0 : 4 * source.Length;
-
- byte[]? borrowedArray = null;
- Span<byte> sortKey = sortKeyLength <= 1024
- ? stackalloc byte[1024]
- : (borrowedArray = ArrayPool<byte>.Shared.Rent(sortKeyLength));
-
- fixed (char* pSource = &MemoryMarshal.GetReference(source))
- {
- fixed (byte* pSortKey = &MemoryMarshal.GetReference(sortKey))
- {
- sortKeyLength = Interop.Globalization.GetSortKey(_sortHandle, pSource, source.Length, pSortKey, sortKey.Length, options);
- }
-
- if (sortKeyLength > sortKey.Length) // slow path for big strings
- {
- if (borrowedArray != null)
- {
- ArrayPool<byte>.Shared.Return(borrowedArray);
- }
-
- sortKey = (borrowedArray = ArrayPool<byte>.Shared.Rent(sortKeyLength));
-
- fixed (byte* pSortKey = &MemoryMarshal.GetReference(sortKey))
- {
- sortKeyLength = Interop.Globalization.GetSortKey(_sortHandle, pSource, source.Length, pSortKey, sortKey.Length, options);
- }
- }
- }
-
- if (sortKeyLength == 0 || sortKeyLength > sortKey.Length) // internal error (0) or a bug (2nd call failed) in ucol_getSortKey
- {
- throw new ArgumentException(SR.Arg_ExternalException);
- }
-
- int hash = Marvin.ComputeHash32(sortKey.Slice(0, sortKeyLength), Marvin.DefaultSeed);
-
- if (borrowedArray != null)
- {
- ArrayPool<byte>.Shared.Return(borrowedArray);
- }
-
- return hash;
- }
-
- private static CompareOptions GetOrdinalCompareOptions(CompareOptions options)
- {
- if ((options & CompareOptions.IgnoreCase) != 0)
- {
- return CompareOptions.OrdinalIgnoreCase;
- }
- else
- {
- return CompareOptions.Ordinal;
- }
- }
-
- private static bool CanUseAsciiOrdinalForOptions(CompareOptions options)
- {
- // Unlike the other Ignore options, IgnoreSymbols impacts ASCII characters (e.g. ').
- return (options & CompareOptions.IgnoreSymbols) == 0;
- }
-
- private SortVersion GetSortVersion()
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- int sortVersion = Interop.Globalization.GetSortVersion(_sortHandle);
- return new SortVersion(sortVersion, LCID, new Guid(sortVersion, 0, 0, 0, 0, 0, 0,
- (byte) (LCID >> 24),
- (byte) ((LCID & 0x00FF0000) >> 16),
- (byte) ((LCID & 0x0000FF00) >> 8),
- (byte) (LCID & 0xFF)));
- }
-
- private static class SortHandleCache
- {
- // in most scenarios there is a limited number of cultures with limited number of sort options
- // so caching the sort handles and not freeing them is OK, see https://github.com/dotnet/coreclr/pull/25117 for more
- private static readonly Dictionary<string, IntPtr> s_sortNameToSortHandleCache = new Dictionary<string, IntPtr>();
-
- internal static IntPtr GetCachedSortHandle(string sortName)
- {
- lock (s_sortNameToSortHandleCache)
- {
- if (!s_sortNameToSortHandleCache.TryGetValue(sortName, out IntPtr result))
- {
- Interop.Globalization.ResultCode resultCode = Interop.Globalization.GetSortHandle(sortName, out result);
-
- if (resultCode == Interop.Globalization.ResultCode.OutOfMemory)
- throw new OutOfMemoryException();
- else if (resultCode != Interop.Globalization.ResultCode.Success)
- throw new ExternalException(SR.Arg_ExternalException);
-
- try
- {
- s_sortNameToSortHandleCache.Add(sortName, result);
- }
- catch
- {
- Interop.Globalization.CloseSortHandle(result);
-
- throw;
- }
- }
-
- return result;
- }
- }
- }
-
- private static ReadOnlySpan<bool> HighCharTable => new bool[0x80]
- {
- true, /* 0x0, 0x0 */
- true, /* 0x1, .*/
- true, /* 0x2, .*/
- true, /* 0x3, .*/
- true, /* 0x4, .*/
- true, /* 0x5, .*/
- true, /* 0x6, .*/
- true, /* 0x7, .*/
- true, /* 0x8, .*/
- false, /* 0x9, */
- true, /* 0xA, */
- false, /* 0xB, .*/
- false, /* 0xC, .*/
- true, /* 0xD, */
- true, /* 0xE, .*/
- true, /* 0xF, .*/
- true, /* 0x10, .*/
- true, /* 0x11, .*/
- true, /* 0x12, .*/
- true, /* 0x13, .*/
- true, /* 0x14, .*/
- true, /* 0x15, .*/
- true, /* 0x16, .*/
- true, /* 0x17, .*/
- true, /* 0x18, .*/
- true, /* 0x19, .*/
- true, /* 0x1A, */
- true, /* 0x1B, .*/
- true, /* 0x1C, .*/
- true, /* 0x1D, .*/
- true, /* 0x1E, .*/
- true, /* 0x1F, .*/
- false, /*0x20, */
- false, /*0x21, !*/
- false, /*0x22, "*/
- false, /*0x23, #*/
- false, /*0x24, $*/
- false, /*0x25, %*/
- false, /*0x26, &*/
- true, /*0x27, '*/
- false, /*0x28, (*/
- false, /*0x29, )*/
- false, /*0x2A **/
- false, /*0x2B, +*/
- false, /*0x2C, ,*/
- true, /*0x2D, -*/
- false, /*0x2E, .*/
- false, /*0x2F, /*/
- false, /*0x30, 0*/
- false, /*0x31, 1*/
- false, /*0x32, 2*/
- false, /*0x33, 3*/
- false, /*0x34, 4*/
- false, /*0x35, 5*/
- false, /*0x36, 6*/
- false, /*0x37, 7*/
- false, /*0x38, 8*/
- false, /*0x39, 9*/
- false, /*0x3A, :*/
- false, /*0x3B, ;*/
- false, /*0x3C, <*/
- false, /*0x3D, =*/
- false, /*0x3E, >*/
- false, /*0x3F, ?*/
- false, /*0x40, @*/
- false, /*0x41, A*/
- false, /*0x42, B*/
- false, /*0x43, C*/
- false, /*0x44, D*/
- false, /*0x45, E*/
- false, /*0x46, F*/
- false, /*0x47, G*/
- false, /*0x48, H*/
- false, /*0x49, I*/
- false, /*0x4A, J*/
- false, /*0x4B, K*/
- false, /*0x4C, L*/
- false, /*0x4D, M*/
- false, /*0x4E, N*/
- false, /*0x4F, O*/
- false, /*0x50, P*/
- false, /*0x51, Q*/
- false, /*0x52, R*/
- false, /*0x53, S*/
- false, /*0x54, T*/
- false, /*0x55, U*/
- false, /*0x56, V*/
- false, /*0x57, W*/
- false, /*0x58, X*/
- false, /*0x59, Y*/
- false, /*0x5A, Z*/
- false, /*0x5B, [*/
- false, /*0x5C, \*/
- false, /*0x5D, ]*/
- false, /*0x5E, ^*/
- false, /*0x5F, _*/
- false, /*0x60, `*/
- false, /*0x61, a*/
- false, /*0x62, b*/
- false, /*0x63, c*/
- false, /*0x64, d*/
- false, /*0x65, e*/
- false, /*0x66, f*/
- false, /*0x67, g*/
- false, /*0x68, h*/
- false, /*0x69, i*/
- false, /*0x6A, j*/
- false, /*0x6B, k*/
- false, /*0x6C, l*/
- false, /*0x6D, m*/
- false, /*0x6E, n*/
- false, /*0x6F, o*/
- false, /*0x70, p*/
- false, /*0x71, q*/
- false, /*0x72, r*/
- false, /*0x73, s*/
- false, /*0x74, t*/
- false, /*0x75, u*/
- false, /*0x76, v*/
- false, /*0x77, w*/
- false, /*0x78, x*/
- false, /*0x79, y*/
- false, /*0x7A, z*/
- false, /*0x7B, {*/
- false, /*0x7C, |*/
- false, /*0x7D, }*/
- false, /*0x7E, ~*/
- true, /*0x7F, */
- };
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Windows.cs
deleted file mode 100644
index 595f64221b1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Windows.cs
+++ /dev/null
@@ -1,606 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Globalization
-{
- public partial class CompareInfo
- {
- internal static unsafe IntPtr GetSortHandle(string cultureName)
- {
- if (GlobalizationMode.Invariant)
- {
- return IntPtr.Zero;
- }
-
- IntPtr handle;
- int ret = Interop.Kernel32.LCMapStringEx(cultureName, Interop.Kernel32.LCMAP_SORTHANDLE, null, 0, &handle, IntPtr.Size, null, null, IntPtr.Zero);
- if (ret > 0)
- {
- // Even if we can get the sort handle, it is not guaranteed to work when Windows compatibility shim is applied
- // e.g. Windows 7 compatibility mode. We need to ensure it is working before using it.
- // otherwise the whole framework app will not start.
- int hashValue = 0;
- char a = 'a';
- ret = Interop.Kernel32.LCMapStringEx(null, Interop.Kernel32.LCMAP_HASH, &a, 1, &hashValue, sizeof(int), null, null, handle);
- if (ret > 1)
- {
- return handle;
- }
- }
-
- return IntPtr.Zero;
- }
-
- private void InitSort(CultureInfo culture)
- {
- _sortName = culture.SortName;
- _sortHandle = GetSortHandle(_sortName);
- }
-
- private static unsafe int FindStringOrdinal(
- uint dwFindStringOrdinalFlags,
- string stringSource,
- int offset,
- int cchSource,
- string value,
- int cchValue,
- bool bIgnoreCase)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(stringSource != null);
- Debug.Assert(value != null);
-
- fixed (char* pSource = stringSource)
- fixed (char* pValue = value)
- {
- int ret = Interop.Kernel32.FindStringOrdinal(
- dwFindStringOrdinalFlags,
- pSource + offset,
- cchSource,
- pValue,
- cchValue,
- bIgnoreCase ? 1 : 0);
- return ret < 0 ? ret : ret + offset;
- }
- }
-
- private static unsafe int FindStringOrdinal(
- uint dwFindStringOrdinalFlags,
- ReadOnlySpan<char> source,
- ReadOnlySpan<char> value,
- bool bIgnoreCase)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!value.IsEmpty);
-
- fixed (char* pSource = &MemoryMarshal.GetReference(source))
- fixed (char* pValue = &MemoryMarshal.GetReference(value))
- {
- int ret = Interop.Kernel32.FindStringOrdinal(
- dwFindStringOrdinalFlags,
- pSource,
- source.Length,
- pValue,
- value.Length,
- bIgnoreCase ? 1 : 0);
- return ret;
- }
- }
-
- internal static int IndexOfOrdinalCore(string source, string value, int startIndex, int count, bool ignoreCase)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(source != null);
- Debug.Assert(value != null);
-
- return FindStringOrdinal(FIND_FROMSTART, source, startIndex, count, value, value.Length, ignoreCase);
- }
-
- internal static int IndexOfOrdinalCore(ReadOnlySpan<char> source, ReadOnlySpan<char> value, bool ignoreCase, bool fromBeginning)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(source.Length != 0);
- Debug.Assert(value.Length != 0);
-
- uint positionFlag = fromBeginning ? (uint)FIND_FROMSTART : FIND_FROMEND;
- return FindStringOrdinal(positionFlag, source, value, ignoreCase);
- }
-
- internal static int LastIndexOfOrdinalCore(string source, string value, int startIndex, int count, bool ignoreCase)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(source != null);
- Debug.Assert(value != null);
-
- return FindStringOrdinal(FIND_FROMEND, source, startIndex - count + 1, count, value, value.Length, ignoreCase);
- }
-
- private unsafe int GetHashCodeOfStringCore(ReadOnlySpan<char> source, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- if (source.Length == 0)
- {
- return 0;
- }
-
- uint flags = LCMAP_SORTKEY | (uint)GetNativeCompareFlags(options);
-
- fixed (char* pSource = source)
- {
- int sortKeyLength = Interop.Kernel32.LCMapStringEx(_sortHandle != IntPtr.Zero ? null : _sortName,
- flags,
- pSource, source.Length /* in chars */,
- null, 0,
- null, null, _sortHandle);
- if (sortKeyLength == 0)
- {
- throw new ArgumentException(SR.Arg_ExternalException);
- }
-
- // Note in calls to LCMapStringEx below, the input buffer is specified in wchars (and wchar count),
- // but the output buffer is specified in bytes (and byte count). This is because when generating
- // sort keys, LCMapStringEx treats the output buffer as containing opaque binary data.
- // See https://docs.microsoft.com/en-us/windows/desktop/api/winnls/nf-winnls-lcmapstringex.
-
- byte[]? borrowedArr = null;
- Span<byte> span = sortKeyLength <= 512 ?
- stackalloc byte[512] :
- (borrowedArr = ArrayPool<byte>.Shared.Rent(sortKeyLength));
-
- fixed (byte* pSortKey = &MemoryMarshal.GetReference(span))
- {
- if (Interop.Kernel32.LCMapStringEx(_sortHandle != IntPtr.Zero ? null : _sortName,
- flags,
- pSource, source.Length /* in chars */,
- pSortKey, sortKeyLength,
- null, null, _sortHandle) != sortKeyLength)
- {
- throw new ArgumentException(SR.Arg_ExternalException);
- }
- }
-
- int hash = Marvin.ComputeHash32(span.Slice(0, sortKeyLength), Marvin.DefaultSeed);
-
- // Return the borrowed array if necessary.
- if (borrowedArr != null)
- {
- ArrayPool<byte>.Shared.Return(borrowedArr);
- }
-
- return hash;
- }
- }
-
- private static unsafe int CompareStringOrdinalIgnoreCase(ref char string1, int count1, ref char string2, int count2)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- fixed (char* char1 = &string1)
- fixed (char* char2 = &string2)
- {
- // Use the OS to compare and then convert the result to expected value by subtracting 2
- return Interop.Kernel32.CompareStringOrdinal(char1, count1, char2, count2, true) - 2;
- }
- }
-
- // TODO https://github.com/dotnet/coreclr/issues/13827:
- // This method shouldn't be necessary, as we should be able to just use the overload
- // that takes two spans. But due to this issue, that's adding significant overhead.
- private unsafe int CompareString(ReadOnlySpan<char> string1, string string2, CompareOptions options)
- {
- Debug.Assert(string2 != null);
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- string? localeName = _sortHandle != IntPtr.Zero ? null : _sortName;
-
- fixed (char* pLocaleName = localeName)
- fixed (char* pString1 = &MemoryMarshal.GetReference(string1))
- fixed (char* pString2 = &string2.GetRawStringData())
- {
- Debug.Assert(pString1 != null);
- int result = Interop.Kernel32.CompareStringEx(
- pLocaleName,
- (uint)GetNativeCompareFlags(options),
- pString1,
- string1.Length,
- pString2,
- string2.Length,
- null,
- null,
- _sortHandle);
-
- if (result == 0)
- {
- throw new ArgumentException(SR.Arg_ExternalException);
- }
-
- // Map CompareStringEx return value to -1, 0, 1.
- return result - 2;
- }
- }
-
- private unsafe int CompareString(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- string? localeName = _sortHandle != IntPtr.Zero ? null : _sortName;
-
- fixed (char* pLocaleName = localeName)
- fixed (char* pString1 = &MemoryMarshal.GetReference(string1))
- fixed (char* pString2 = &MemoryMarshal.GetReference(string2))
- {
- Debug.Assert(pString1 != null);
- Debug.Assert(pString2 != null);
- int result = Interop.Kernel32.CompareStringEx(
- pLocaleName,
- (uint)GetNativeCompareFlags(options),
- pString1,
- string1.Length,
- pString2,
- string2.Length,
- null,
- null,
- _sortHandle);
-
- if (result == 0)
- {
- throw new ArgumentException(SR.Arg_ExternalException);
- }
-
- // Map CompareStringEx return value to -1, 0, 1.
- return result - 2;
- }
- }
-
- private unsafe int FindString(
- uint dwFindNLSStringFlags,
- ReadOnlySpan<char> lpStringSource,
- ReadOnlySpan<char> lpStringValue,
- int* pcchFound)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(!lpStringSource.IsEmpty);
- Debug.Assert(!lpStringValue.IsEmpty);
-
- string? localeName = _sortHandle != IntPtr.Zero ? null : _sortName;
-
- fixed (char* pLocaleName = localeName)
- fixed (char* pSource = &MemoryMarshal.GetReference(lpStringSource))
- fixed (char* pValue = &MemoryMarshal.GetReference(lpStringValue))
- {
- return Interop.Kernel32.FindNLSStringEx(
- pLocaleName,
- dwFindNLSStringFlags,
- pSource,
- lpStringSource.Length,
- pValue,
- lpStringValue.Length,
- pcchFound,
- null,
- null,
- _sortHandle);
- }
- }
-
- private unsafe int FindString(
- uint dwFindNLSStringFlags,
- string lpStringSource,
- int startSource,
- int cchSource,
- string lpStringValue,
- int startValue,
- int cchValue,
- int* pcchFound)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(lpStringSource != null);
- Debug.Assert(lpStringValue != null);
-
- string? localeName = _sortHandle != IntPtr.Zero ? null : _sortName;
-
- fixed (char* pLocaleName = localeName)
- fixed (char* pSource = lpStringSource)
- fixed (char* pValue = lpStringValue)
- {
- char* pS = pSource + startSource;
- char* pV = pValue + startValue;
-
- return Interop.Kernel32.FindNLSStringEx(
- pLocaleName,
- dwFindNLSStringFlags,
- pS,
- cchSource,
- pV,
- cchValue,
- pcchFound,
- null,
- null,
- _sortHandle);
- }
- }
-
- internal unsafe int IndexOfCore(string source, string target, int startIndex, int count, CompareOptions options, int* matchLengthPtr)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(source != null);
- Debug.Assert(target != null);
- Debug.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
- Debug.Assert((options & CompareOptions.Ordinal) == 0);
-
- int retValue = FindString(FIND_FROMSTART | (uint)GetNativeCompareFlags(options), source, startIndex, count,
- target, 0, target.Length, matchLengthPtr);
- if (retValue >= 0)
- {
- return retValue + startIndex;
- }
-
- return -1;
- }
-
- internal unsafe int IndexOfCore(ReadOnlySpan<char> source, ReadOnlySpan<char> target, CompareOptions options, int* matchLengthPtr, bool fromBeginning)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(source.Length != 0);
- Debug.Assert(target.Length != 0);
- Debug.Assert(options == CompareOptions.None || options == CompareOptions.IgnoreCase);
-
- uint positionFlag = fromBeginning ? (uint)FIND_FROMSTART : FIND_FROMEND;
- return FindString(positionFlag | (uint)GetNativeCompareFlags(options), source, target, matchLengthPtr);
- }
-
- private unsafe int LastIndexOfCore(string source, string target, int startIndex, int count, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!string.IsNullOrEmpty(source));
- Debug.Assert(target != null);
- Debug.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
-
- if (target.Length == 0)
- return startIndex;
-
- if ((options & CompareOptions.Ordinal) != 0)
- {
- return FastLastIndexOfString(source, target, startIndex, count, target.Length);
- }
- else
- {
- int retValue = FindString(FIND_FROMEND | (uint)GetNativeCompareFlags(options), source, startIndex - count + 1,
- count, target, 0, target.Length, null);
-
- if (retValue >= 0)
- {
- return retValue + startIndex - (count - 1);
- }
- }
-
- return -1;
- }
-
- private unsafe bool StartsWith(string source, string prefix, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!string.IsNullOrEmpty(source));
- Debug.Assert(!string.IsNullOrEmpty(prefix));
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- return FindString(FIND_STARTSWITH | (uint)GetNativeCompareFlags(options), source, 0, source.Length,
- prefix, 0, prefix.Length, null) >= 0;
- }
-
- private unsafe bool StartsWith(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!prefix.IsEmpty);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- return FindString(FIND_STARTSWITH | (uint)GetNativeCompareFlags(options), source, prefix, null) >= 0;
- }
-
- private unsafe bool EndsWith(string source, string suffix, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!string.IsNullOrEmpty(source));
- Debug.Assert(!string.IsNullOrEmpty(suffix));
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- return FindString(FIND_ENDSWITH | (uint)GetNativeCompareFlags(options), source, 0, source.Length,
- suffix, 0, suffix.Length, null) >= 0;
- }
-
- private unsafe bool EndsWith(ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!suffix.IsEmpty);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- return FindString(FIND_ENDSWITH | (uint)GetNativeCompareFlags(options), source, suffix, null) >= 0;
- }
-
- // PAL ends here
- [NonSerialized]
- private IntPtr _sortHandle;
-
- private const uint LCMAP_SORTKEY = 0x00000400;
-
- private const int FIND_STARTSWITH = 0x00100000;
- private const int FIND_ENDSWITH = 0x00200000;
- private const int FIND_FROMSTART = 0x00400000;
- private const int FIND_FROMEND = 0x00800000;
-
- // TODO: Instead of this method could we just have upstack code call LastIndexOfOrdinal with ignoreCase = false?
- private static unsafe int FastLastIndexOfString(string source, string target, int startIndex, int sourceCount, int targetCount)
- {
- int retValue = -1;
-
- int sourceStartIndex = startIndex - sourceCount + 1;
-
- fixed (char* pSource = source, spTarget = target)
- {
- char* spSubSource = pSource + sourceStartIndex;
-
- int endPattern = sourceCount - targetCount;
- if (endPattern < 0)
- return -1;
-
- Debug.Assert(target.Length >= 1);
- char patternChar0 = spTarget[0];
- for (int ctrSrc = endPattern; ctrSrc >= 0; ctrSrc--)
- {
- if (spSubSource[ctrSrc] != patternChar0)
- continue;
-
- int ctrPat;
- for (ctrPat = 1; ctrPat < targetCount; ctrPat++)
- {
- if (spSubSource[ctrSrc + ctrPat] != spTarget[ctrPat])
- break;
- }
- if (ctrPat == targetCount)
- {
- retValue = ctrSrc;
- break;
- }
- }
-
- if (retValue >= 0)
- {
- retValue += startIndex - sourceCount + 1;
- }
- }
-
- return retValue;
- }
-
- private unsafe SortKey CreateSortKey(string source, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- if (source == null) { throw new ArgumentNullException(nameof(source)); }
-
- if ((options & ValidSortkeyCtorMaskOffFlags) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
-
- byte[] keyData;
- if (source.Length == 0)
- {
- keyData = Array.Empty<byte>();
- }
- else
- {
- uint flags = LCMAP_SORTKEY | (uint)GetNativeCompareFlags(options);
-
- fixed (char* pSource = source)
- {
- int sortKeyLength = Interop.Kernel32.LCMapStringEx(_sortHandle != IntPtr.Zero ? null : _sortName,
- flags,
- pSource, source.Length,
- null, 0,
- null, null, _sortHandle);
- if (sortKeyLength == 0)
- {
- throw new ArgumentException(SR.Arg_ExternalException);
- }
-
- keyData = new byte[sortKeyLength];
-
- fixed (byte* pBytes = keyData)
- {
- if (Interop.Kernel32.LCMapStringEx(_sortHandle != IntPtr.Zero ? null : _sortName,
- flags,
- pSource, source.Length,
- pBytes, keyData.Length,
- null, null, _sortHandle) != sortKeyLength)
- {
- throw new ArgumentException(SR.Arg_ExternalException);
- }
- }
- }
- }
-
- return new SortKey(Name, source, options, keyData);
- }
-
- private static unsafe bool IsSortable(char* text, int length)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(text != null);
-
- return Interop.Kernel32.IsNLSDefinedString(Interop.Kernel32.COMPARE_STRING, 0, IntPtr.Zero, text, length);
- }
-
- private const int COMPARE_OPTIONS_ORDINAL = 0x40000000; // Ordinal
- private const int NORM_IGNORECASE = 0x00000001; // Ignores case. (use LINGUISTIC_IGNORECASE instead)
- private const int NORM_IGNOREKANATYPE = 0x00010000; // Does not differentiate between Hiragana and Katakana characters. Corresponding Hiragana and Katakana will compare as equal.
- private const int NORM_IGNORENONSPACE = 0x00000002; // Ignores nonspacing. This flag also removes Japanese accent characters. (use LINGUISTIC_IGNOREDIACRITIC instead)
- private const int NORM_IGNORESYMBOLS = 0x00000004; // Ignores symbols.
- private const int NORM_IGNOREWIDTH = 0x00020000; // Does not differentiate between a single-byte character and the same character as a double-byte character.
- private const int NORM_LINGUISTIC_CASING = 0x08000000; // use linguistic rules for casing
- private const int SORT_STRINGSORT = 0x00001000; // Treats punctuation the same as symbols.
-
- private static int GetNativeCompareFlags(CompareOptions options)
- {
- // Use "linguistic casing" by default (load the culture's casing exception tables)
- int nativeCompareFlags = NORM_LINGUISTIC_CASING;
-
- if ((options & CompareOptions.IgnoreCase) != 0) { nativeCompareFlags |= NORM_IGNORECASE; }
- if ((options & CompareOptions.IgnoreKanaType) != 0) { nativeCompareFlags |= NORM_IGNOREKANATYPE; }
- if ((options & CompareOptions.IgnoreNonSpace) != 0) { nativeCompareFlags |= NORM_IGNORENONSPACE; }
- if ((options & CompareOptions.IgnoreSymbols) != 0) { nativeCompareFlags |= NORM_IGNORESYMBOLS; }
- if ((options & CompareOptions.IgnoreWidth) != 0) { nativeCompareFlags |= NORM_IGNOREWIDTH; }
- if ((options & CompareOptions.StringSort) != 0) { nativeCompareFlags |= SORT_STRINGSORT; }
-
- // TODO: Can we try for GetNativeCompareFlags to never
- // take Ordinal or OrdinalIgnoreCase. This value is not part of Win32, we just handle it special
- // in some places.
- // Suffix & Prefix shouldn't use this, make sure to turn off the NORM_LINGUISTIC_CASING flag
- if (options == CompareOptions.Ordinal) { nativeCompareFlags = COMPARE_OPTIONS_ORDINAL; }
-
- Debug.Assert(((options & ~(CompareOptions.IgnoreCase |
- CompareOptions.IgnoreKanaType |
- CompareOptions.IgnoreNonSpace |
- CompareOptions.IgnoreSymbols |
- CompareOptions.IgnoreWidth |
- CompareOptions.StringSort)) == 0) ||
- (options == CompareOptions.Ordinal), "[CompareInfo.GetNativeCompareFlags]Expected all flags to be handled");
-
- return nativeCompareFlags;
- }
-
- private unsafe SortVersion GetSortVersion()
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Interop.Kernel32.NlsVersionInfoEx nlsVersion = default;
- nlsVersion.dwNLSVersionInfoSize = sizeof(Interop.Kernel32.NlsVersionInfoEx);
- Interop.Kernel32.GetNLSVersionEx(Interop.Kernel32.COMPARE_STRING, _sortName, &nlsVersion);
- return new SortVersion(
- nlsVersion.dwNLSVersion,
- nlsVersion.dwEffectiveId == 0 ? LCID : nlsVersion.dwEffectiveId,
- nlsVersion.guidCustomVersion);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs
deleted file mode 100644
index 3b8350f34ea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs
+++ /dev/null
@@ -1,1503 +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 System.Diagnostics;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Serialization;
-using System.Text.Unicode;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Globalization
-{
- /// <summary>
- /// This class implements a set of methods for comparing strings.
- /// </summary>
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public partial class CompareInfo : IDeserializationCallback
- {
- // Mask used to check if IndexOf()/LastIndexOf()/IsPrefix()/IsPostfix() has the right flags.
- private const CompareOptions ValidIndexMaskOffFlags =
- ~(CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace |
- CompareOptions.IgnoreWidth | CompareOptions.IgnoreKanaType);
-
- // Mask used to check if Compare() has the right flags.
- private const CompareOptions ValidCompareMaskOffFlags =
- ~(CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace |
- CompareOptions.IgnoreWidth | CompareOptions.IgnoreKanaType | CompareOptions.StringSort);
-
- // Mask used to check if GetHashCodeOfString() has the right flags.
- private const CompareOptions ValidHashCodeOfStringMaskOffFlags =
- ~(CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace |
- CompareOptions.IgnoreWidth | CompareOptions.IgnoreKanaType);
-
- // Mask used to check if we have the right flags.
- private const CompareOptions ValidSortkeyCtorMaskOffFlags =
- ~(CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace |
- CompareOptions.IgnoreWidth | CompareOptions.IgnoreKanaType | CompareOptions.StringSort);
-
- // Cache the invariant CompareInfo
- internal static readonly CompareInfo Invariant = CultureInfo.InvariantCulture.CompareInfo;
-
- // CompareInfos have an interesting identity. They are attached to the locale that created them,
- // ie: en-US would have an en-US sort. For haw-US (custom), then we serialize it as haw-US.
- // The interesting part is that since haw-US doesn't have its own sort, it has to point at another
- // locale, which is what SCOMPAREINFO does.
- [OptionalField(VersionAdded = 2)]
- private string m_name; // The name used to construct this CompareInfo. Do not rename (binary serialization)
-
- [NonSerialized]
- private string _sortName = null!; // The name that defines our behavior
-
- [OptionalField(VersionAdded = 3)]
- private SortVersion? m_SortVersion; // Do not rename (binary serialization)
-
- private int culture; // Do not rename (binary serialization). The fields sole purpose is to support Desktop serialization.
-
- internal CompareInfo(CultureInfo culture)
- {
- m_name = culture._name;
- InitSort(culture);
- }
-
- /// <summary>
- /// Get the CompareInfo constructed from the data table in the specified
- /// assembly for the specified culture.
- /// Warning: The assembly versioning mechanism is dead!
- /// </summary>
- public static CompareInfo GetCompareInfo(int culture, Assembly assembly)
- {
- // Parameter checking.
- if (assembly == null)
- {
- throw new ArgumentNullException(nameof(assembly));
- }
- if (assembly != typeof(object).Module.Assembly)
- {
- throw new ArgumentException(SR.Argument_OnlyMscorlib, nameof(assembly));
- }
-
- return GetCompareInfo(culture);
- }
-
- /// <summary>
- /// Get the CompareInfo constructed from the data table in the specified
- /// assembly for the specified culture.
- /// The purpose of this method is to provide version for CompareInfo tables.
- /// </summary>
- public static CompareInfo GetCompareInfo(string name, Assembly assembly)
- {
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
- if (assembly == null)
- {
- throw new ArgumentNullException(nameof(assembly));
- }
- if (assembly != typeof(object).Module.Assembly)
- {
- throw new ArgumentException(SR.Argument_OnlyMscorlib, nameof(assembly));
- }
-
- return GetCompareInfo(name);
- }
-
- /// <summary>
- /// Get the CompareInfo for the specified culture.
- /// This method is provided for ease of integration with NLS-based software.
- /// </summary>
- public static CompareInfo GetCompareInfo(int culture)
- {
- if (CultureData.IsCustomCultureId(culture))
- {
- throw new ArgumentException(SR.Argument_CustomCultureCannotBePassedByNumber, nameof(culture));
- }
-
- return CultureInfo.GetCultureInfo(culture).CompareInfo;
- }
-
- /// <summary>
- /// Get the CompareInfo for the specified culture.
- /// </summary>
- public static CompareInfo GetCompareInfo(string name)
- {
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- return CultureInfo.GetCultureInfo(name).CompareInfo;
- }
-
- public static unsafe bool IsSortable(char ch)
- {
- if (GlobalizationMode.Invariant)
- {
- return true;
- }
-
- char* pChar = &ch;
- return IsSortable(pChar, 1);
- }
-
- public static unsafe bool IsSortable(string text)
- {
- if (text == null)
- {
- throw new ArgumentNullException(nameof(text));
- }
-
- if (text.Length == 0)
- {
- return false;
- }
-
- if (GlobalizationMode.Invariant)
- {
- return true;
- }
-
- fixed (char* pChar = text)
- {
- return IsSortable(pChar, text.Length);
- }
- }
-
- [OnDeserializing]
- private void OnDeserializing(StreamingContext ctx)
- {
- // this becomes null for a brief moment before deserialization
- // after serialization is finished it is never null.
- m_name = null!;
- }
-
- void IDeserializationCallback.OnDeserialization(object? sender)
- {
- OnDeserialized();
- }
-
- [OnDeserialized]
- private void OnDeserialized(StreamingContext ctx)
- {
- OnDeserialized();
- }
-
- private void OnDeserialized()
- {
- // If we didn't have a name, use the LCID
- if (m_name == null)
- {
- // From whidbey, didn't have a name
- m_name = CultureInfo.GetCultureInfo(culture)._name;
- }
- else
- {
- InitSort(CultureInfo.GetCultureInfo(m_name));
- }
- }
-
- [OnSerializing]
- private void OnSerializing(StreamingContext ctx)
- {
- // This is merely for serialization compatibility with Whidbey/Orcas, it can go away when we don't want that compat any more.
- culture = CultureInfo.GetCultureInfo(Name).LCID; // This is the lcid of the constructing culture (still have to dereference to get target sort)
- Debug.Assert(m_name != null, "CompareInfo.OnSerializing - expected m_name to be set already");
- }
-
- /// <summary>
- /// Returns the name of the culture (well actually, of the sort).
- /// Very important for providing a non-LCID way of identifying
- /// what the sort is.
- ///
- /// Note that this name isn't dereferenced in case the CompareInfo is a different locale
- /// which is consistent with the behaviors of earlier versions. (so if you ask for a sort
- /// and the locale's changed behavior, then you'll get changed behavior, which is like
- /// what happens for a version update)
- /// </summary>
- public virtual string Name
- {
- get
- {
- Debug.Assert(m_name != null, "CompareInfo.Name Expected _name to be set");
- if (m_name == "zh-CHT" || m_name == "zh-CHS")
- {
- return m_name;
- }
-
- return _sortName;
- }
- }
-
- /// <summary>
- /// Compares the two strings with the given options. Returns 0 if the
- /// two strings are equal, a number less than 0 if string1 is less
- /// than string2, and a number greater than 0 if string1 is greater
- /// than string2.
- /// </summary>
- public virtual int Compare(string? string1, string? string2)
- {
- return Compare(string1, string2, CompareOptions.None);
- }
-
- public virtual int Compare(string? string1, string? string2, CompareOptions options)
- {
- if (options == CompareOptions.OrdinalIgnoreCase)
- {
- return string.Compare(string1, string2, StringComparison.OrdinalIgnoreCase);
- }
-
- // Verify the options before we do any real comparison.
- if ((options & CompareOptions.Ordinal) != 0)
- {
- if (options != CompareOptions.Ordinal)
- {
- throw new ArgumentException(SR.Argument_CompareOptionOrdinal, nameof(options));
- }
-
- return string.CompareOrdinal(string1, string2);
- }
-
- if ((options & ValidCompareMaskOffFlags) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
-
- // Our paradigm is that null sorts less than any other string and
- // that two nulls sort as equal.
- if (string1 == null)
- {
- if (string2 == null)
- {
- return 0;
- }
- return -1; // null < non-null
- }
- if (string2 == null)
- {
- return 1; // non-null > null
- }
-
- if (GlobalizationMode.Invariant)
- {
- if ((options & CompareOptions.IgnoreCase) != 0)
- {
- return CompareOrdinalIgnoreCase(string1, string2);
- }
-
- return string.CompareOrdinal(string1, string2);
- }
-
- return CompareString(string1.AsSpan(), string2.AsSpan(), options);
- }
-
- // TODO https://github.com/dotnet/coreclr/issues/13827:
- // This method shouldn't be necessary, as we should be able to just use the overload
- // that takes two spans. But due to this issue, that's adding significant overhead.
- internal int Compare(ReadOnlySpan<char> string1, string? string2, CompareOptions options)
- {
- if (options == CompareOptions.OrdinalIgnoreCase)
- {
- return CompareOrdinalIgnoreCase(string1, string2.AsSpan());
- }
-
- // Verify the options before we do any real comparison.
- if ((options & CompareOptions.Ordinal) != 0)
- {
- if (options != CompareOptions.Ordinal)
- {
- throw new ArgumentException(SR.Argument_CompareOptionOrdinal, nameof(options));
- }
-
- return string.CompareOrdinal(string1, string2.AsSpan());
- }
-
- if ((options & ValidCompareMaskOffFlags) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
-
- // null sorts less than any other string.
- if (string2 == null)
- {
- return 1;
- }
-
- if (GlobalizationMode.Invariant)
- {
- return (options & CompareOptions.IgnoreCase) != 0 ?
- CompareOrdinalIgnoreCase(string1, string2.AsSpan()) :
- string.CompareOrdinal(string1, string2.AsSpan());
- }
-
- return CompareString(string1, string2, options);
- }
-
- internal int CompareOptionNone(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2)
- {
- // Check for empty span or span from a null string
- if (string1.Length == 0 || string2.Length == 0)
- {
- return string1.Length - string2.Length;
- }
-
- return GlobalizationMode.Invariant ?
- string.CompareOrdinal(string1, string2) :
- CompareString(string1, string2, CompareOptions.None);
- }
-
- internal int CompareOptionIgnoreCase(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2)
- {
- // Check for empty span or span from a null string
- if (string1.Length == 0 || string2.Length == 0)
- {
- return string1.Length - string2.Length;
- }
-
- return GlobalizationMode.Invariant ?
- CompareOrdinalIgnoreCase(string1, string2) :
- CompareString(string1, string2, CompareOptions.IgnoreCase);
- }
-
- /// <summary>
- /// Compares the specified regions of the two strings with the given
- /// options.
- /// Returns 0 if the two strings are equal, a number less than 0 if
- /// string1 is less than string2, and a number greater than 0 if
- /// string1 is greater than string2.
- /// </summary>
- public virtual int Compare(string? string1, int offset1, int length1, string? string2, int offset2, int length2)
- {
- return Compare(string1, offset1, length1, string2, offset2, length2, 0);
- }
-
- public virtual int Compare(string? string1, int offset1, string? string2, int offset2, CompareOptions options)
- {
- return Compare(string1, offset1, string1 == null ? 0 : string1.Length - offset1,
- string2, offset2, string2 == null ? 0 : string2.Length - offset2, options);
- }
-
- public virtual int Compare(string? string1, int offset1, string? string2, int offset2)
- {
- return Compare(string1, offset1, string2, offset2, 0);
- }
-
- public virtual int Compare(string? string1, int offset1, int length1, string? string2, int offset2, int length2, CompareOptions options)
- {
- if (options == CompareOptions.OrdinalIgnoreCase)
- {
- int result = string.Compare(string1, offset1, string2, offset2, length1 < length2 ? length1 : length2, StringComparison.OrdinalIgnoreCase);
- if ((length1 != length2) && result == 0)
- {
- return length1 > length2 ? 1 : -1;
- }
-
- return result;
- }
-
- if (length1 < 0 || length2 < 0)
- {
- throw new ArgumentOutOfRangeException((length1 < 0) ? nameof(length1) : nameof(length2), SR.ArgumentOutOfRange_NeedPosNum);
- }
- if (offset1 < 0 || offset2 < 0)
- {
- throw new ArgumentOutOfRangeException((offset1 < 0) ? nameof(offset1) : nameof(offset2), SR.ArgumentOutOfRange_NeedPosNum);
- }
- if (offset1 > (string1 == null ? 0 : string1.Length) - length1)
- {
- throw new ArgumentOutOfRangeException(nameof(string1), SR.ArgumentOutOfRange_OffsetLength);
- }
- if (offset2 > (string2 == null ? 0 : string2.Length) - length2)
- {
- throw new ArgumentOutOfRangeException(nameof(string2), SR.ArgumentOutOfRange_OffsetLength);
- }
- if ((options & CompareOptions.Ordinal) != 0)
- {
- if (options != CompareOptions.Ordinal)
- {
- throw new ArgumentException(SR.Argument_CompareOptionOrdinal,
- nameof(options));
- }
- }
- else if ((options & ValidCompareMaskOffFlags) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
-
- if (string1 == null)
- {
- if (string2 == null)
- {
- return 0;
- }
- return -1;
- }
- if (string2 == null)
- {
- return 1;
- }
-
- ReadOnlySpan<char> span1 = string1.AsSpan(offset1, length1);
- ReadOnlySpan<char> span2 = string2.AsSpan(offset2, length2);
-
- if (options == CompareOptions.Ordinal)
- {
- return string.CompareOrdinal(span1, span2);
- }
-
- if (GlobalizationMode.Invariant)
- {
- if ((options & CompareOptions.IgnoreCase) != 0)
- {
- return CompareOrdinalIgnoreCase(span1, span2);
- }
-
- return string.CompareOrdinal(span1, span2);
- }
-
- return CompareString(span1, span2, options);
- }
-
- /// <summary>
- /// CompareOrdinalIgnoreCase compare two string ordinally with ignoring the case.
- /// it assumes the strings are Ascii string till we hit non Ascii character in strA or strB and then we continue the comparison by
- /// calling the OS.
- /// </summary>
- internal static int CompareOrdinalIgnoreCase(string strA, int indexA, int lengthA, string strB, int indexB, int lengthB)
- {
- Debug.Assert(indexA + lengthA <= strA.Length);
- Debug.Assert(indexB + lengthB <= strB.Length);
- return CompareOrdinalIgnoreCase(
- ref Unsafe.Add(ref strA.GetRawStringData(), indexA),
- lengthA,
- ref Unsafe.Add(ref strB.GetRawStringData(), indexB),
- lengthB);
- }
-
- internal static int CompareOrdinalIgnoreCase(ReadOnlySpan<char> strA, ReadOnlySpan<char> strB)
- {
- return CompareOrdinalIgnoreCase(ref MemoryMarshal.GetReference(strA), strA.Length, ref MemoryMarshal.GetReference(strB), strB.Length);
- }
-
- internal static int CompareOrdinalIgnoreCase(string strA, string strB)
- {
- return CompareOrdinalIgnoreCase(ref strA.GetRawStringData(), strA.Length, ref strB.GetRawStringData(), strB.Length);
- }
-
- internal static int CompareOrdinalIgnoreCase(ref char strA, int lengthA, ref char strB, int lengthB)
- {
- int length = Math.Min(lengthA, lengthB);
- int range = length;
-
- ref char charA = ref strA;
- ref char charB = ref strB;
-
- // in InvariantMode we support all range and not only the ascii characters.
- char maxChar = (GlobalizationMode.Invariant ? (char)0xFFFF : (char)0x7F);
-
- while (length != 0 && charA <= maxChar && charB <= maxChar)
- {
- // Ordinal equals or lowercase equals if the result ends up in the a-z range
- if (charA == charB ||
- ((charA | 0x20) == (charB | 0x20) &&
- (uint)((charA | 0x20) - 'a') <= (uint)('z' - 'a')))
- {
- length--;
- charA = ref Unsafe.Add(ref charA, 1);
- charB = ref Unsafe.Add(ref charB, 1);
- }
- else
- {
- int currentA = charA;
- int currentB = charB;
-
- // Uppercase both chars if needed
- if ((uint)(charA - 'a') <= 'z' - 'a')
- {
- currentA -= 0x20;
- }
- if ((uint)(charB - 'a') <= 'z' - 'a')
- {
- currentB -= 0x20;
- }
-
- // Return the (case-insensitive) difference between them.
- return currentA - currentB;
- }
- }
-
- if (length == 0)
- {
- return lengthA - lengthB;
- }
-
- Debug.Assert(!GlobalizationMode.Invariant);
-
- range -= length;
-
- return CompareStringOrdinalIgnoreCase(ref charA, lengthA - range, ref charB, lengthB - range);
- }
-
- internal static bool EqualsOrdinalIgnoreCase(ref char charA, ref char charB, int length)
- {
- IntPtr byteOffset = IntPtr.Zero;
-
-#if BIT64
- // Read 4 chars (64 bits) at a time from each string
- while ((uint)length >= 4)
- {
- ulong valueA = Unsafe.ReadUnaligned<ulong>(ref Unsafe.As<char, byte>(ref Unsafe.AddByteOffset(ref charA, byteOffset)));
- ulong valueB = Unsafe.ReadUnaligned<ulong>(ref Unsafe.As<char, byte>(ref Unsafe.AddByteOffset(ref charB, byteOffset)));
-
- // A 32-bit test - even with the bit-twiddling here - is more efficient than a 64-bit test.
- ulong temp = valueA | valueB;
- if (!Utf16Utility.AllCharsInUInt32AreAscii((uint)temp | (uint)(temp >> 32)))
- {
- goto NonAscii; // one of the inputs contains non-ASCII data
- }
-
- // Generally, the caller has likely performed a first-pass check that the input strings
- // are likely equal. Consider a dictionary which computes the hash code of its key before
- // performing a proper deep equality check of the string contents. We want to optimize for
- // the case where the equality check is likely to succeed, which means that we want to avoid
- // branching within this loop unless we're about to exit the loop, either due to failure or
- // due to us running out of input data.
-
- if (!Utf16Utility.UInt64OrdinalIgnoreCaseAscii(valueA, valueB))
- {
- return false;
- }
-
- byteOffset += 8;
- length -= 4;
- }
-#endif
-
- // Read 2 chars (32 bits) at a time from each string
-#if BIT64
- if ((uint)length >= 2)
-#else
- while ((uint)length >= 2)
-#endif
- {
- uint valueA = Unsafe.ReadUnaligned<uint>(ref Unsafe.As<char, byte>(ref Unsafe.AddByteOffset(ref charA, byteOffset)));
- uint valueB = Unsafe.ReadUnaligned<uint>(ref Unsafe.As<char, byte>(ref Unsafe.AddByteOffset(ref charB, byteOffset)));
-
- if (!Utf16Utility.AllCharsInUInt32AreAscii(valueA | valueB))
- {
- goto NonAscii; // one of the inputs contains non-ASCII data
- }
-
- // Generally, the caller has likely performed a first-pass check that the input strings
- // are likely equal. Consider a dictionary which computes the hash code of its key before
- // performing a proper deep equality check of the string contents. We want to optimize for
- // the case where the equality check is likely to succeed, which means that we want to avoid
- // branching within this loop unless we're about to exit the loop, either due to failure or
- // due to us running out of input data.
-
- if (!Utf16Utility.UInt32OrdinalIgnoreCaseAscii(valueA, valueB))
- {
- return false;
- }
-
- byteOffset += 4;
- length -= 2;
- }
-
- if (length != 0)
- {
- Debug.Assert(length == 1);
-
- uint valueA = Unsafe.AddByteOffset(ref charA, byteOffset);
- uint valueB = Unsafe.AddByteOffset(ref charB, byteOffset);
-
- if ((valueA | valueB) > 0x7Fu)
- {
- goto NonAscii; // one of the inputs contains non-ASCII data
- }
-
- if (valueA == valueB)
- {
- return true; // exact match
- }
-
- valueA |= 0x20u;
- if ((uint)(valueA - 'a') > (uint)('z' - 'a'))
- {
- return false; // not exact match, and first input isn't in [A-Za-z]
- }
-
- // The ternary operator below seems redundant but helps RyuJIT generate more optimal code.
- // See https://github.com/dotnet/coreclr/issues/914.
- return (valueA == (valueB | 0x20u)) ? true : false;
- }
-
- Debug.Assert(length == 0);
- return true;
-
- NonAscii:
- // The non-ASCII case is factored out into its own helper method so that the JIT
- // doesn't need to emit a complex prolog for its caller (this method).
- return EqualsOrdinalIgnoreCaseNonAscii(ref Unsafe.AddByteOffset(ref charA, byteOffset), ref Unsafe.AddByteOffset(ref charB, byteOffset), length);
- }
-
- private static bool EqualsOrdinalIgnoreCaseNonAscii(ref char charA, ref char charB, int length)
- {
- if (!GlobalizationMode.Invariant)
- {
- return CompareStringOrdinalIgnoreCase(ref charA, length, ref charB, length) == 0;
- }
- else
- {
- // If we don't have localization tables to consult, we'll still perform a case-insensitive
- // check for ASCII characters, but if we see anything outside the ASCII range we'll immediately
- // fail if it doesn't have true bitwise equality.
-
- IntPtr byteOffset = IntPtr.Zero;
- while (length != 0)
- {
- // Ordinal equals or lowercase equals if the result ends up in the a-z range
- uint valueA = Unsafe.AddByteOffset(ref charA, byteOffset);
- uint valueB = Unsafe.AddByteOffset(ref charB, byteOffset);
-
- if (valueA == valueB ||
- ((valueA | 0x20) == (valueB | 0x20) &&
- (uint)((valueA | 0x20) - 'a') <= (uint)('z' - 'a')))
- {
- byteOffset += 2;
- length--;
- }
- else
- {
- return false;
- }
- }
-
- return true;
- }
- }
-
- /// <summary>
- /// Determines whether prefix is a prefix of string. If prefix equals
- /// string.Empty, true is returned.
- /// </summary>
- public virtual bool IsPrefix(string source, string prefix, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
- if (prefix == null)
- {
- throw new ArgumentNullException(nameof(prefix));
- }
-
- if (prefix.Length == 0)
- {
- return true;
- }
- if (source.Length == 0)
- {
- return false;
- }
-
- if (options == CompareOptions.OrdinalIgnoreCase)
- {
- return source.StartsWith(prefix, StringComparison.OrdinalIgnoreCase);
- }
-
- if (options == CompareOptions.Ordinal)
- {
- return source.StartsWith(prefix, StringComparison.Ordinal);
- }
-
- if ((options & ValidIndexMaskOffFlags) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
-
- if (GlobalizationMode.Invariant)
- {
- return source.StartsWith(prefix, (options & CompareOptions.IgnoreCase) != 0 ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
- }
-
- return StartsWith(source, prefix, options);
- }
-
- internal bool IsPrefix(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, CompareOptions options)
- {
- Debug.Assert(prefix.Length != 0);
- Debug.Assert(source.Length != 0);
- Debug.Assert((options & ValidIndexMaskOffFlags) == 0);
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- return StartsWith(source, prefix, options);
- }
-
- public virtual bool IsPrefix(string source, string prefix)
- {
- return IsPrefix(source, prefix, 0);
- }
-
- /// <summary>
- /// Determines whether suffix is a suffix of string. If suffix equals
- /// string.Empty, true is returned.
- /// </summary>
- public virtual bool IsSuffix(string source, string suffix, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
- if (suffix == null)
- {
- throw new ArgumentNullException(nameof(suffix));
- }
-
- if (suffix.Length == 0)
- {
- return true;
- }
- if (source.Length == 0)
- {
- return false;
- }
-
- if (options == CompareOptions.OrdinalIgnoreCase)
- {
- return source.EndsWith(suffix, StringComparison.OrdinalIgnoreCase);
- }
-
- if (options == CompareOptions.Ordinal)
- {
- return source.EndsWith(suffix, StringComparison.Ordinal);
- }
-
- if ((options & ValidIndexMaskOffFlags) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
-
- if (GlobalizationMode.Invariant)
- {
- return source.EndsWith(suffix, (options & CompareOptions.IgnoreCase) != 0 ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
- }
-
- return EndsWith(source, suffix, options);
- }
-
- internal bool IsSuffix(ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, CompareOptions options)
- {
- Debug.Assert(suffix.Length != 0);
- Debug.Assert(source.Length != 0);
- Debug.Assert((options & ValidIndexMaskOffFlags) == 0);
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
-
- return EndsWith(source, suffix, options);
- }
-
- public virtual bool IsSuffix(string source, string suffix)
- {
- return IsSuffix(source, suffix, 0);
- }
-
- /// <summary>
- /// Returns the first index where value is found in string. The
- /// search starts from startIndex and ends at endIndex. Returns -1 if
- /// the specified value is not found. If value equals string.Empty,
- /// startIndex is returned. Throws IndexOutOfRange if startIndex or
- /// endIndex is less than zero or greater than the length of string.
- /// Throws ArgumentException if value is null.
- /// </summary>
- public virtual int IndexOf(string source, char value)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- return IndexOf(source, value, 0, source.Length, CompareOptions.None);
- }
-
- public virtual int IndexOf(string source, string value)
- {
- if (source == null)
- throw new ArgumentNullException(nameof(source));
-
- return IndexOf(source, value, 0, source.Length, CompareOptions.None);
- }
-
- public virtual int IndexOf(string source, char value, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- return IndexOf(source, value, 0, source.Length, options);
- }
-
- public virtual int IndexOf(string source, string value, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- return IndexOf(source, value, 0, source.Length, options);
- }
-
- public virtual int IndexOf(string source, char value, int startIndex)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- return IndexOf(source, value, startIndex, source.Length - startIndex, CompareOptions.None);
- }
-
- public virtual int IndexOf(string source, string value, int startIndex)
- {
- if (source == null)
- throw new ArgumentNullException(nameof(source));
-
- return IndexOf(source, value, startIndex, source.Length - startIndex, CompareOptions.None);
- }
-
- public virtual int IndexOf(string source, char value, int startIndex, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- return IndexOf(source, value, startIndex, source.Length - startIndex, options);
- }
-
- public virtual int IndexOf(string source, string value, int startIndex, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- return IndexOf(source, value, startIndex, source.Length - startIndex, options);
- }
-
- public virtual int IndexOf(string source, char value, int startIndex, int count)
- {
- return IndexOf(source, value, startIndex, count, CompareOptions.None);
- }
-
- public virtual int IndexOf(string source, string value, int startIndex, int count)
- {
- return IndexOf(source, value, startIndex, count, CompareOptions.None);
- }
-
- public virtual unsafe int IndexOf(string source, char value, int startIndex, int count, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
- if (startIndex < 0 || startIndex > source.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
- if (count < 0 || startIndex > source.Length - count)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
- }
-
- if (source.Length == 0)
- {
- return -1;
- }
-
- // Validate CompareOptions
- // Ordinal can't be selected with other flags
- if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal && options != CompareOptions.OrdinalIgnoreCase))
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
-
- return IndexOf(source, char.ToString(value), startIndex, count, options, null);
- }
-
- public virtual unsafe int IndexOf(string source, string value, int startIndex, int count, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if (startIndex > source.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
-
- // In Everett we used to return -1 for empty string even if startIndex is negative number so we keeping same behavior here.
- // We return 0 if both source and value are empty strings for Everett compatibility too.
- if (source.Length == 0)
- {
- if (value.Length == 0)
- {
- return 0;
- }
- return -1;
- }
-
- if (startIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
-
- if (count < 0 || startIndex > source.Length - count)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
- }
-
- // Validate CompareOptions
- // Ordinal can't be selected with other flags
- if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal && options != CompareOptions.OrdinalIgnoreCase))
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
-
- return IndexOf(source, value, startIndex, count, options, null);
- }
-
- internal int IndexOfOrdinalIgnoreCase(ReadOnlySpan<char> source, ReadOnlySpan<char> value)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!value.IsEmpty);
-
- return IndexOfOrdinalCore(source, value, ignoreCase: true, fromBeginning: true);
- }
-
- internal int LastIndexOfOrdinal(ReadOnlySpan<char> source, ReadOnlySpan<char> value, bool ignoreCase)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!value.IsEmpty);
- return IndexOfOrdinalCore(source, value, ignoreCase, fromBeginning: false);
- }
-
- internal unsafe int IndexOf(ReadOnlySpan<char> source, ReadOnlySpan<char> value, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!value.IsEmpty);
- return IndexOfCore(source, value, options, null, fromBeginning: true);
- }
-
- internal unsafe int LastIndexOf(ReadOnlySpan<char> source, ReadOnlySpan<char> value, CompareOptions options)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(!source.IsEmpty);
- Debug.Assert(!value.IsEmpty);
- return IndexOfCore(source, value, options, null, fromBeginning: false);
- }
-
- /// <summary>
- /// The following IndexOf overload is mainly used by String.Replace. This overload assumes the parameters are already validated
- /// and the caller is passing a valid matchLengthPtr pointer.
- /// </summary>
- internal unsafe int IndexOf(string source, string value, int startIndex, int count, CompareOptions options, int* matchLengthPtr, bool fromBeginning = true)
- {
- Debug.Assert(source != null);
- Debug.Assert(value != null);
- Debug.Assert(startIndex >= 0);
-
- if (matchLengthPtr != null)
- {
- *matchLengthPtr = 0;
- }
-
- if (value.Length == 0)
- {
- return startIndex;
- }
-
- if (startIndex >= source.Length)
- {
- return -1;
- }
-
- if (options == CompareOptions.OrdinalIgnoreCase)
- {
- int res;
- if (fromBeginning)
- {
- res = IndexOfOrdinal(source, value, startIndex, count, ignoreCase: true);
- }
- else
- {
- res = LastIndexOfOrdinal(source, value, startIndex, count, ignoreCase: true);
- }
-
- if (res >= 0 && matchLengthPtr != null)
- {
- *matchLengthPtr = value.Length;
- }
- return res;
- }
-
- if (GlobalizationMode.Invariant)
- {
- bool ignoreCase = (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0;
- int res;
-
- if (fromBeginning)
- {
- res = IndexOfOrdinal(source, value, startIndex, count, ignoreCase);
- }
- else
- {
- res = LastIndexOfOrdinal(source, value, startIndex, count, ignoreCase);
- }
-
- if (res >= 0 && matchLengthPtr != null)
- {
- *matchLengthPtr = value.Length;
- }
- return res;
- }
-
- if (options == CompareOptions.Ordinal)
- {
- int retValue;
-
- if (fromBeginning)
- {
- retValue = SpanHelpers.IndexOf(
- ref Unsafe.Add(ref source.GetRawStringData(), startIndex),
- count,
- ref value.GetRawStringData(),
- value.Length);
- }
- else
- {
- retValue = SpanHelpers.LastIndexOf(
- ref Unsafe.Add(ref source.GetRawStringData(), startIndex),
- count,
- ref value.GetRawStringData(),
- value.Length);
- }
-
- if (retValue >= 0)
- {
- retValue += startIndex;
- if (matchLengthPtr != null)
- {
- *matchLengthPtr = value.Length;
- }
- }
-
- return retValue;
- }
- else
- {
- if (fromBeginning)
- {
- // Call the string-based overload, as it special-cases IsFastSort as a perf optimization.
- return IndexOfCore(source, value, startIndex, count, options, matchLengthPtr);
- }
- else
- {
- return IndexOfCore(source.AsSpan(startIndex, count), value, options, matchLengthPtr, fromBeginning: false);
- }
- }
- }
-
- internal static int IndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase)
- {
- if (!ignoreCase)
- {
- int result = SpanHelpers.IndexOf(
- ref Unsafe.Add(ref source.GetRawStringData(), startIndex),
- count,
- ref value.GetRawStringData(),
- value.Length);
-
- return (result >= 0 ? startIndex : 0) + result;
- }
-
- if (GlobalizationMode.Invariant)
- {
- return InvariantIndexOf(source, value, startIndex, count, ignoreCase);
- }
-
- return IndexOfOrdinalCore(source, value, startIndex, count, ignoreCase);
- }
-
- /// <summary>
- /// Returns the last index where value is found in string. The
- /// search starts from startIndex and ends at endIndex. Returns -1 if
- /// the specified value is not found. If value equals string.Empty,
- /// endIndex is returned. Throws IndexOutOfRange if startIndex or
- /// endIndex is less than zero or greater than the length of string.
- /// Throws ArgumentException if value is null.
- /// </summary>
- public virtual int LastIndexOf(string source, char value)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- // Can't start at negative index, so make sure we check for the length == 0 case.
- return LastIndexOf(source, value, source.Length - 1, source.Length, CompareOptions.None);
- }
-
- public virtual int LastIndexOf(string source, string value)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- // Can't start at negative index, so make sure we check for the length == 0 case.
- return LastIndexOf(source, value, source.Length - 1,
- source.Length, CompareOptions.None);
- }
-
- public virtual int LastIndexOf(string source, char value, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- // Can't start at negative index, so make sure we check for the length == 0 case.
- return LastIndexOf(source, value, source.Length - 1, source.Length, options);
- }
-
- public virtual int LastIndexOf(string source, string value, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- // Can't start at negative index, so make sure we check for the length == 0 case.
- return LastIndexOf(source, value, source.Length - 1, source.Length, options);
- }
-
- public virtual int LastIndexOf(string source, char value, int startIndex)
- {
- return LastIndexOf(source, value, startIndex, startIndex + 1, CompareOptions.None);
- }
-
- public virtual int LastIndexOf(string source, string value, int startIndex)
- {
- return LastIndexOf(source, value, startIndex, startIndex + 1, CompareOptions.None);
- }
-
- public virtual int LastIndexOf(string source, char value, int startIndex, CompareOptions options)
- {
- return LastIndexOf(source, value, startIndex, startIndex + 1, options);
- }
-
- public virtual int LastIndexOf(string source, string value, int startIndex, CompareOptions options)
- {
- return LastIndexOf(source, value, startIndex, startIndex + 1, options);
- }
-
- public virtual int LastIndexOf(string source, char value, int startIndex, int count)
- {
- return LastIndexOf(source, value, startIndex, count, CompareOptions.None);
- }
-
- public virtual int LastIndexOf(string source, string value, int startIndex, int count)
- {
- return LastIndexOf(source, value, startIndex, count, CompareOptions.None);
- }
-
- public virtual int LastIndexOf(string source, char value, int startIndex, int count, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
- // Validate CompareOptions
- // Ordinal can't be selected with other flags
- if ((options & ValidIndexMaskOffFlags) != 0 &&
- (options != CompareOptions.Ordinal) &&
- (options != CompareOptions.OrdinalIgnoreCase))
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
-
- // Special case for 0 length input strings
- if (source.Length == 0 && (startIndex == -1 || startIndex == 0))
- {
- return -1;
- }
-
- // Make sure we're not out of range
- if (startIndex < 0 || startIndex > source.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
-
- // Make sure that we allow startIndex == source.Length
- if (startIndex == source.Length)
- {
- startIndex--;
- if (count > 0)
- {
- count--;
- }
- }
-
- // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
- if (count < 0 || startIndex - count + 1 < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
- }
-
- if (options == CompareOptions.OrdinalIgnoreCase)
- {
- return source.LastIndexOf(value.ToString(), startIndex, count, StringComparison.OrdinalIgnoreCase);
- }
-
- if (GlobalizationMode.Invariant)
- {
- return InvariantLastIndexOf(source, char.ToString(value), startIndex, count, (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0);
- }
-
- return LastIndexOfCore(source, value.ToString(), startIndex, count, options);
- }
-
- public virtual int LastIndexOf(string source, string value, int startIndex, int count, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- // Validate CompareOptions
- // Ordinal can't be selected with other flags
- if ((options & ValidIndexMaskOffFlags) != 0 &&
- (options != CompareOptions.Ordinal) &&
- (options != CompareOptions.OrdinalIgnoreCase))
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
-
- // Special case for 0 length input strings
- if (source.Length == 0 && (startIndex == -1 || startIndex == 0))
- {
- return (value.Length == 0) ? 0 : -1;
- }
-
- // Make sure we're not out of range
- if (startIndex < 0 || startIndex > source.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
-
- // Make sure that we allow startIndex == source.Length
- if (startIndex == source.Length)
- {
- startIndex--;
- if (count > 0)
- {
- count--;
- }
-
- // If we are looking for nothing, just return 0
- if (value.Length == 0 && count >= 0 && startIndex - count + 1 >= 0)
- {
- return startIndex;
- }
- }
-
- // 2nd half of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
- if (count < 0 || startIndex - count + 1 < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
- }
-
- if (options == CompareOptions.OrdinalIgnoreCase)
- {
- return LastIndexOfOrdinal(source, value, startIndex, count, ignoreCase: true);
- }
-
- if (GlobalizationMode.Invariant)
- return InvariantLastIndexOf(source, value, startIndex, count, (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0);
-
- return LastIndexOfCore(source, value, startIndex, count, options);
- }
-
- internal static int LastIndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase)
- {
- if (GlobalizationMode.Invariant)
- {
- return InvariantLastIndexOf(source, value, startIndex, count, ignoreCase);
- }
-
- return LastIndexOfOrdinalCore(source, value, startIndex, count, ignoreCase);
- }
-
- /// <summary>
- /// Gets the SortKey for the given string with the given options.
- /// </summary>
- public virtual SortKey GetSortKey(string source, CompareOptions options)
- {
- if (GlobalizationMode.Invariant)
- {
- return InvariantCreateSortKey(source, options);
- }
-
- return CreateSortKey(source, options);
- }
-
- public virtual SortKey GetSortKey(string source)
- {
- if (GlobalizationMode.Invariant)
- {
- return InvariantCreateSortKey(source, CompareOptions.None);
- }
-
- return CreateSortKey(source, CompareOptions.None);
- }
-
- public override bool Equals(object? value)
- {
- return value is CompareInfo otherCompareInfo
- && Name == otherCompareInfo.Name;
- }
-
- public override int GetHashCode() => Name.GetHashCode();
-
- /// <summary>
- /// This internal method allows a method that allows the equivalent of creating a Sortkey for a
- /// string from CompareInfo, and generate a hashcode value from it. It is not very convenient
- /// to use this method as is and it creates an unnecessary Sortkey object that will be GC'ed.
- ///
- /// The hash code is guaranteed to be the same for string A and B where A.Equals(B) is true and both
- /// the CompareInfo and the CompareOptions are the same. If two different CompareInfo objects
- /// treat the string the same way, this implementation will treat them differently (the same way that
- /// Sortkey does at the moment).
- ///
- /// This method will never be made public itself, but public consumers of it could be created, e.g.:
- ///
- /// string.GetHashCode(CultureInfo)
- /// string.GetHashCode(CompareInfo)
- /// string.GetHashCode(CultureInfo, CompareOptions)
- /// string.GetHashCode(CompareInfo, CompareOptions)
- /// etc.
- ///
- /// (the methods above that take a CultureInfo would use CultureInfo.CompareInfo)
- /// </summary>
- internal int GetHashCodeOfString(string source, CompareOptions options)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
- if ((options & ValidHashCodeOfStringMaskOffFlags) == 0)
- {
- // No unsupported flags are set - continue on with the regular logic
- if (GlobalizationMode.Invariant)
- {
- return ((options & CompareOptions.IgnoreCase) != 0) ? source.GetHashCodeOrdinalIgnoreCase() : source.GetHashCode();
- }
-
- return GetHashCodeOfStringCore(source, options);
- }
- else if (options == CompareOptions.Ordinal)
- {
- // We allow Ordinal in isolation
- return source.GetHashCode();
- }
- else if (options == CompareOptions.OrdinalIgnoreCase)
- {
- // We allow OrdinalIgnoreCase in isolation
- return source.GetHashCodeOrdinalIgnoreCase();
- }
- else
- {
- // Unsupported combination of flags specified
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
- }
-
- public virtual int GetHashCode(string source, CompareOptions options)
- {
- // virtual method delegates to non-virtual method
- return GetHashCodeOfString(source, options);
- }
-
- public int GetHashCode(ReadOnlySpan<char> source, CompareOptions options)
- {
- if ((options & ValidHashCodeOfStringMaskOffFlags) == 0)
- {
- // No unsupported flags are set - continue on with the regular logic
- if (GlobalizationMode.Invariant)
- {
- return ((options & CompareOptions.IgnoreCase) != 0) ? string.GetHashCodeOrdinalIgnoreCase(source) : string.GetHashCode(source);
- }
-
- return GetHashCodeOfStringCore(source, options);
- }
- else if (options == CompareOptions.Ordinal)
- {
- // We allow Ordinal in isolation
- return string.GetHashCode(source);
- }
- else if (options == CompareOptions.OrdinalIgnoreCase)
- {
- // We allow OrdinalIgnoreCase in isolation
- return string.GetHashCodeOrdinalIgnoreCase(source);
- }
- else
- {
- // Unsupported combination of flags specified
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
- }
-
- public override string ToString() => "CompareInfo - " + Name;
-
- public SortVersion Version
- {
- get
- {
- if (m_SortVersion == null)
- {
- if (GlobalizationMode.Invariant)
- {
- m_SortVersion = new SortVersion(0, CultureInfo.LOCALE_INVARIANT, new Guid(0, 0, 0, 0, 0, 0, 0,
- (byte)(CultureInfo.LOCALE_INVARIANT >> 24),
- (byte)((CultureInfo.LOCALE_INVARIANT & 0x00FF0000) >> 16),
- (byte)((CultureInfo.LOCALE_INVARIANT & 0x0000FF00) >> 8),
- (byte)(CultureInfo.LOCALE_INVARIANT & 0xFF)));
- }
- else
- {
- m_SortVersion = GetSortVersion();
- }
- }
-
- return m_SortVersion;
- }
- }
-
- public int LCID => CultureInfo.GetCultureInfo(Name).LCID;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CompareOptions.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CompareOptions.cs
deleted file mode 100644
index 366ece403c0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CompareOptions.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Globalization
-{
- [Flags]
- public enum CompareOptions
- {
- None = 0x00000000,
- IgnoreCase = 0x00000001,
- IgnoreNonSpace = 0x00000002,
- IgnoreSymbols = 0x00000004,
- IgnoreKanaType = 0x00000008,
- IgnoreWidth = 0x00000010,
- OrdinalIgnoreCase = 0x10000000, // This flag can not be used with other flags.
- StringSort = 0x20000000,
- Ordinal = 0x40000000, // This flag can not be used with other flags.
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Unix.cs
deleted file mode 100644
index cbd42e62fd6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Unix.cs
+++ /dev/null
@@ -1,421 +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 System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Security;
-using System.Text;
-
-namespace System.Globalization
-{
- internal partial class CultureData
- {
- // ICU constants
- private const int ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY = 100; // max size of keyword or value
- private const int ICU_ULOC_FULLNAME_CAPACITY = 157; // max size of locale name
- private const string ICU_COLLATION_KEYWORD = "@collation=";
-
- /// <summary>
- /// This method uses the sRealName field (which is initialized by the constructor before this is called) to
- /// initialize the rest of the state of CultureData based on the underlying OS globalization library.
- /// </summary>
- private unsafe bool InitCultureData()
- {
- Debug.Assert(_sRealName != null);
-
- Debug.Assert(!GlobalizationMode.Invariant);
-
- string realNameBuffer = _sRealName;
-
- // Basic validation
- if (realNameBuffer.Contains('@'))
- {
- return false; // don't allow ICU variants to come in directly
- }
-
- // Replace _ (alternate sort) with @collation= for ICU
- ReadOnlySpan<char> alternateSortName = default;
- int index = realNameBuffer.IndexOf('_');
- if (index > 0)
- {
- if (index >= (realNameBuffer.Length - 1) // must have characters after _
- || realNameBuffer.IndexOf('_', index + 1) >= 0) // only one _ allowed
- {
- return false; // fail
- }
- alternateSortName = realNameBuffer.AsSpan(index + 1);
- realNameBuffer = string.Concat(realNameBuffer.AsSpan(0, index), ICU_COLLATION_KEYWORD, alternateSortName);
- }
-
- // Get the locale name from ICU
- if (!GetLocaleName(realNameBuffer, out _sWindowsName))
- {
- return false; // fail
- }
-
- // Replace the ICU collation keyword with an _
- Debug.Assert(_sWindowsName != null);
- index = _sWindowsName.IndexOf(ICU_COLLATION_KEYWORD, StringComparison.Ordinal);
- if (index >= 0)
- {
- _sName = string.Concat(_sWindowsName.AsSpan(0, index), "_", alternateSortName);
- }
- else
- {
- _sName = _sWindowsName;
- }
- _sRealName = _sName;
-
- _iLanguage = LCID;
- if (_iLanguage == 0)
- {
- _iLanguage = CultureInfo.LOCALE_CUSTOM_UNSPECIFIED;
- }
-
- _bNeutral = TwoLetterISOCountryName.Length == 0;
-
- _sSpecificCulture = _bNeutral ? LocaleData.GetSpecificCultureName(_sRealName) : _sRealName;
-
- // Remove the sort from sName unless custom culture
- if (index > 0 && !_bNeutral && !IsCustomCultureId(_iLanguage))
- {
- _sName = _sWindowsName.Substring(0, index);
- }
- return true;
- }
-
- internal static unsafe bool GetLocaleName(string localeName, out string? windowsName)
- {
- // Get the locale name from ICU
- char* buffer = stackalloc char[ICU_ULOC_FULLNAME_CAPACITY];
- if (!Interop.Globalization.GetLocaleName(localeName, buffer, ICU_ULOC_FULLNAME_CAPACITY))
- {
- windowsName = null;
- return false; // fail
- }
-
- // Success - use the locale name returned which may be different than realNameBuffer (casing)
- windowsName = new string(buffer); // the name passed to subsequent ICU calls
- return true;
- }
-
- internal static unsafe bool GetDefaultLocaleName(out string? windowsName)
- {
- // Get the default (system) locale name from ICU
- char* buffer = stackalloc char[ICU_ULOC_FULLNAME_CAPACITY];
- if (!Interop.Globalization.GetDefaultLocaleName(buffer, ICU_ULOC_FULLNAME_CAPACITY))
- {
- windowsName = null;
- return false; // fail
- }
-
- // Success - use the locale name returned which may be different than realNameBuffer (casing)
- windowsName = new string(buffer); // the name passed to subsequent ICU calls
- return true;
- }
-
- private string GetLocaleInfo(LocaleStringData type)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfo] Expected _sWindowsName to be populated already");
- return GetLocaleInfo(_sWindowsName, type);
- }
-
- // For LOCALE_SPARENT we need the option of using the "real" name (forcing neutral names) instead of the
- // "windows" name, which can be specific for downlevel (< windows 7) os's.
- private unsafe string GetLocaleInfo(string localeName, LocaleStringData type)
- {
- Debug.Assert(localeName != null, "[CultureData.GetLocaleInfo] Expected localeName to be not be null");
-
- switch (type)
- {
- case LocaleStringData.NegativeInfinitySymbol:
- // not an equivalent in ICU; prefix the PositiveInfinitySymbol with NegativeSign
- return GetLocaleInfo(localeName, LocaleStringData.NegativeSign) +
- GetLocaleInfo(localeName, LocaleStringData.PositiveInfinitySymbol);
- }
-
- char* buffer = stackalloc char[ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY];
- bool result = Interop.Globalization.GetLocaleInfoString(localeName, (uint)type, buffer, ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY);
- if (!result)
- {
- // Failed, just use empty string
- Debug.Fail("[CultureData.GetLocaleInfo(LocaleStringData)] Failed");
- return string.Empty;
- }
-
- return new string(buffer);
- }
-
- private int GetLocaleInfo(LocaleNumberData type)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- Debug.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfo(LocaleNumberData)] Expected _sWindowsName to be populated already");
-
- switch (type)
- {
- case LocaleNumberData.CalendarType:
- // returning 0 will cause the first supported calendar to be returned, which is the preferred calendar
- return 0;
- }
-
-
- int value = 0;
- bool result = Interop.Globalization.GetLocaleInfoInt(_sWindowsName, (uint)type, ref value);
- if (!result)
- {
- // Failed, just use 0
- Debug.Fail("[CultureData.GetLocaleInfo(LocaleNumberData)] failed");
- }
-
- return value;
- }
-
- private int[] GetLocaleInfo(LocaleGroupingData type)
- {
- Debug.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfo(LocaleGroupingData)] Expected _sWindowsName to be populated already");
-
- int primaryGroupingSize = 0;
- int secondaryGroupingSize = 0;
- bool result = Interop.Globalization.GetLocaleInfoGroupingSizes(_sWindowsName, (uint)type, ref primaryGroupingSize, ref secondaryGroupingSize);
- if (!result)
- {
- Debug.Fail("[CultureData.GetLocaleInfo(LocaleGroupingData type)] failed");
- }
-
- if (secondaryGroupingSize == 0)
- {
- return new int[] { primaryGroupingSize };
- }
-
- return new int[] { primaryGroupingSize, secondaryGroupingSize };
- }
-
- private string GetTimeFormatString() => GetTimeFormatString(shortFormat: false);
-
- private unsafe string GetTimeFormatString(bool shortFormat)
- {
- Debug.Assert(_sWindowsName != null, "[CultureData.GetTimeFormatString(bool shortFormat)] Expected _sWindowsName to be populated already");
-
- char* buffer = stackalloc char[ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY];
-
- bool result = Interop.Globalization.GetLocaleTimeFormat(_sWindowsName, shortFormat, buffer, ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY);
- if (!result)
- {
- // Failed, just use empty string
- Debug.Fail("[CultureData.GetTimeFormatString(bool shortFormat)] Failed");
- return string.Empty;
- }
-
- var span = new ReadOnlySpan<char>(buffer, ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY);
- return ConvertIcuTimeFormatString(span.Slice(0, span.IndexOf('\0')));
- }
-
- private int GetFirstDayOfWeek() => GetLocaleInfo(LocaleNumberData.FirstDayOfWeek);
-
- private string[] GetTimeFormats()
- {
- string format = GetTimeFormatString(false);
- return new string[] { format };
- }
-
- private string[] GetShortTimeFormats()
- {
- string format = GetTimeFormatString(true);
- return new string[] { format };
- }
-
- private static CultureData? GetCultureDataFromRegionName(string? regionName)
- {
- // no support to lookup by region name, other than the hard-coded list in CultureData
- return null;
- }
-
- private static string GetLanguageDisplayName(string cultureName)
- {
- return new CultureInfo(cultureName)._cultureData.GetLocaleInfo(cultureName, LocaleStringData.LocalizedDisplayName);
- }
-
- private static string? GetRegionDisplayName()
- {
- // use the fallback which is to return NativeName
- return null;
- }
-
- private static string ConvertIcuTimeFormatString(ReadOnlySpan<char> icuFormatString)
- {
- Debug.Assert(icuFormatString.Length < ICU_ULOC_FULLNAME_CAPACITY);
- Span<char> result = stackalloc char[ICU_ULOC_FULLNAME_CAPACITY];
-
- bool amPmAdded = false;
- int resultPos = 0;
-
- for (int i = 0; i < icuFormatString.Length; i++)
- {
- switch (icuFormatString[i])
- {
- case '\'':
- result[resultPos++] = icuFormatString[i++];
- while (i < icuFormatString.Length)
- {
- char current = icuFormatString[i++];
- result[resultPos++] = current;
- if (current == '\'')
- {
- break;
- }
- }
- break;
-
- case ':':
- case '.':
- case 'H':
- case 'h':
- case 'm':
- case 's':
- result[resultPos++] = icuFormatString[i];
- break;
-
- case ' ':
- case '\u00A0':
- // Convert nonbreaking spaces into regular spaces
- result[resultPos++] = ' ';
- break;
-
- case 'a': // AM/PM
- if (!amPmAdded)
- {
- amPmAdded = true;
- result[resultPos++] = 't';
- result[resultPos++] = 't';
- }
- break;
-
- }
- }
-
- return result.Slice(0, resultPos).ToString();
- }
-
- private static string? LCIDToLocaleName(int culture)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- return LocaleData.LCIDToLocaleName(culture);
- }
-
- private static int LocaleNameToLCID(string cultureName)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- int lcid = LocaleData.GetLocaleDataNumericPart(cultureName, LocaleDataParts.Lcid);
- return lcid == -1 ? CultureInfo.LOCALE_CUSTOM_UNSPECIFIED : lcid;
- }
-
- private static int GetAnsiCodePage(string cultureName)
- {
- int ansiCodePage = LocaleData.GetLocaleDataNumericPart(cultureName, LocaleDataParts.AnsiCodePage);
- return ansiCodePage == -1 ? CultureData.Invariant.ANSICodePage : ansiCodePage;
- }
-
- private static int GetOemCodePage(string cultureName)
- {
- int oemCodePage = LocaleData.GetLocaleDataNumericPart(cultureName, LocaleDataParts.OemCodePage);
- return oemCodePage == -1 ? CultureData.Invariant.OEMCodePage : oemCodePage;
- }
-
- private static int GetMacCodePage(string cultureName)
- {
- int macCodePage = LocaleData.GetLocaleDataNumericPart(cultureName, LocaleDataParts.MacCodePage);
- return macCodePage == -1 ? CultureData.Invariant.MacCodePage : macCodePage;
- }
-
- private static int GetEbcdicCodePage(string cultureName)
- {
- int ebcdicCodePage = LocaleData.GetLocaleDataNumericPart(cultureName, LocaleDataParts.EbcdicCodePage);
- return ebcdicCodePage == -1 ? CultureData.Invariant.EBCDICCodePage : ebcdicCodePage;
- }
-
- private static int GetGeoId(string cultureName)
- {
- int geoId = LocaleData.GetLocaleDataNumericPart(cultureName, LocaleDataParts.GeoId);
- return geoId == -1 ? CultureData.Invariant.GeoId : geoId;
- }
-
- private static int GetDigitSubstitution(string cultureName)
- {
- int digitSubstitution = LocaleData.GetLocaleDataNumericPart(cultureName, LocaleDataParts.DigitSubstitution);
- return digitSubstitution == -1 ? (int) DigitShapes.None : digitSubstitution;
- }
-
- private static string GetThreeLetterWindowsLanguageName(string cultureName)
- {
- return LocaleData.GetThreeLetterWindowsLanguageName(cultureName) ?? "ZZZ" /* default lang name */;
- }
-
- private static CultureInfo[] EnumCultures(CultureTypes types)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- if ((types & (CultureTypes.NeutralCultures | CultureTypes.SpecificCultures)) == 0)
- {
- return Array.Empty<CultureInfo>();
- }
-
- int bufferLength = Interop.Globalization.GetLocales(null, 0);
- if (bufferLength <= 0)
- {
- return Array.Empty<CultureInfo>();
- }
-
- char [] chars = new char[bufferLength];
-
- bufferLength = Interop.Globalization.GetLocales(chars, bufferLength);
- if (bufferLength <= 0)
- {
- return Array.Empty<CultureInfo>();
- }
-
- bool enumNeutrals = (types & CultureTypes.NeutralCultures) != 0;
- bool enumSpecificss = (types & CultureTypes.SpecificCultures) != 0;
-
- List<CultureInfo> list = new List<CultureInfo>();
- if (enumNeutrals)
- {
- list.Add(CultureInfo.InvariantCulture);
- }
-
- int index = 0;
- while (index < bufferLength)
- {
- int length = (int) chars[index++];
- if (index + length <= bufferLength)
- {
- CultureInfo ci = CultureInfo.GetCultureInfo(new string(chars, index, length));
- if ((enumNeutrals && ci.IsNeutralCulture) || (enumSpecificss && !ci.IsNeutralCulture))
- {
- list.Add(ci);
- }
- }
-
- index += length;
- }
-
- return list.ToArray();
- }
-
- private static string GetConsoleFallbackName(string cultureName)
- {
- return LocaleData.GetConsoleUICulture(cultureName);
- }
-
- internal bool IsWin32Installed => false;
-
- internal bool IsReplacementCulture => false;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs
deleted file mode 100644
index b8ae4083724..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs
+++ /dev/null
@@ -1,718 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Text;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Globalization
-{
- internal partial class CultureData
- {
- /// <summary>
- /// Check with the OS to see if this is a valid culture.
- /// If so we populate a limited number of fields. If its not valid we return false.
- ///
- /// The fields we populate:
- ///
- /// sWindowsName -- The name that windows thinks this culture is, ie:
- /// en-US if you pass in en-US
- /// de-DE_phoneb if you pass in de-DE_phoneb
- /// fj-FJ if you pass in fj (neutral, on a pre-Windows 7 machine)
- /// fj if you pass in fj (neutral, post-Windows 7 machine)
- ///
- /// sRealName -- The name you used to construct the culture, in pretty form
- /// en-US if you pass in EN-us
- /// en if you pass in en
- /// de-DE_phoneb if you pass in de-DE_phoneb
- ///
- /// sSpecificCulture -- The specific culture for this culture
- /// en-US for en-US
- /// en-US for en
- /// de-DE_phoneb for alt sort
- /// fj-FJ for fj (neutral)
- ///
- /// sName -- The IETF name of this culture (ie: no sort info, could be neutral)
- /// en-US if you pass in en-US
- /// en if you pass in en
- /// de-DE if you pass in de-DE_phoneb
- ///
- /// bNeutral -- TRUE if it is a neutral locale
- ///
- /// For a neutral we just populate the neutral name, but we leave the windows name pointing to the
- /// windows locale that's going to provide data for us.
- /// </summary>
- private unsafe bool InitCultureData()
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- int result;
- string realNameBuffer = _sRealName;
- char* pBuffer = stackalloc char[Interop.Kernel32.LOCALE_NAME_MAX_LENGTH];
-
- result = GetLocaleInfoEx(realNameBuffer, Interop.Kernel32.LOCALE_SNAME, pBuffer, Interop.Kernel32.LOCALE_NAME_MAX_LENGTH);
-
- // Did it fail?
- if (result == 0)
- {
- return false;
- }
-
- // It worked, note that the name is the locale name, so use that (even for neutrals)
- // We need to clean up our "real" name, which should look like the windows name right now
- // so overwrite the input with the cleaned up name
- _sRealName = new string(pBuffer, 0, result - 1);
- realNameBuffer = _sRealName;
-
- // Check for neutrality, don't expect to fail
- // (buffer has our name in it, so we don't have to do the gc. stuff)
-
- result = GetLocaleInfoEx(realNameBuffer, Interop.Kernel32.LOCALE_INEUTRAL | Interop.Kernel32.LOCALE_RETURN_NUMBER, pBuffer, sizeof(int) / sizeof(char));
- if (result == 0)
- {
- return false;
- }
-
- // Remember our neutrality
- _bNeutral = *((uint*)pBuffer) != 0;
-
- // Note: Parents will be set dynamically
-
- // Start by assuming the windows name will be the same as the specific name since windows knows
- // about specifics on all versions. Only for downlevel Neutral locales does this have to change.
- _sWindowsName = realNameBuffer;
-
- // Neutrals and non-neutrals are slightly different
- if (_bNeutral)
- {
- // Neutral Locale
-
- // IETF name looks like neutral name
- _sName = realNameBuffer;
-
- // Specific locale name is whatever ResolveLocaleName (win7+) returns.
- // (Buffer has our name in it, and we can recycle that because windows resolves it before writing to the buffer)
- result = Interop.Kernel32.ResolveLocaleName(realNameBuffer, pBuffer, Interop.Kernel32.LOCALE_NAME_MAX_LENGTH);
-
- // 0 is failure, 1 is invariant (""), which we expect
- if (result < 1)
- {
- return false;
- }
- // We found a locale name, so use it.
- // In vista this should look like a sort name (de-DE_phoneb) or a specific culture (en-US) and be in the "pretty" form
- _sSpecificCulture = new string(pBuffer, 0, result - 1);
- }
- else
- {
- // Specific Locale
-
- // Specific culture's the same as the locale name since we know its not neutral
- // On mac we'll use this as well, even for neutrals. There's no obvious specific
- // culture to use and this isn't exposed, but behaviorally this is correct on mac.
- // Note that specifics include the sort name (de-DE_phoneb)
- _sSpecificCulture = realNameBuffer;
-
- _sName = realNameBuffer;
-
- // We need the IETF name (sname)
- // If we aren't an alt sort locale then this is the same as the windows name.
- // If we are an alt sort locale then this is the same as the part before the _ in the windows name
- // This is for like de-DE_phoneb and es-ES_tradnl that hsouldn't have the _ part
-
- result = GetLocaleInfoEx(realNameBuffer, Interop.Kernel32.LOCALE_ILANGUAGE | Interop.Kernel32.LOCALE_RETURN_NUMBER, pBuffer, sizeof(int) / sizeof(char));
- if (result == 0)
- {
- return false;
- }
-
- _iLanguage = *((int*)pBuffer);
-
- if (!IsCustomCultureId(_iLanguage))
- {
- // not custom locale
- int index = realNameBuffer.IndexOf('_');
- if (index > 0 && index < realNameBuffer.Length)
- {
- _sName = realNameBuffer.Substring(0, index);
- }
- }
- }
-
- // It succeeded.
- return true;
- }
-
- // Wrappers around the GetLocaleInfoEx APIs which handle marshalling the returned
- // data as either and Int or string.
- internal static unsafe string? GetLocaleInfoEx(string localeName, uint field)
- {
- // REVIEW: Determine the maximum size for the buffer
- const int BUFFER_SIZE = 530;
-
- char* pBuffer = stackalloc char[BUFFER_SIZE];
- int resultCode = GetLocaleInfoEx(localeName, field, pBuffer, BUFFER_SIZE);
- if (resultCode > 0)
- {
- return new string(pBuffer);
- }
-
- return null;
- }
-
- internal static unsafe int GetLocaleInfoExInt(string localeName, uint field)
- {
- field |= Interop.Kernel32.LOCALE_RETURN_NUMBER;
- int value = 0;
- GetLocaleInfoEx(localeName, field, (char*)&value, sizeof(int));
- return value;
- }
-
- internal static unsafe int GetLocaleInfoEx(string lpLocaleName, uint lcType, char* lpLCData, int cchData)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- return Interop.Kernel32.GetLocaleInfoEx(lpLocaleName, lcType, lpLCData, cchData);
- }
-
- private string GetLocaleInfo(LocaleStringData type)
- {
- Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfo] Expected _sWindowsName to be populated by already");
- return GetLocaleInfo(_sWindowsName, type);
- }
-
- // For LOCALE_SPARENT we need the option of using the "real" name (forcing neutral names) instead of the
- // "windows" name, which can be specific for downlevel (< windows 7) os's.
- private string GetLocaleInfo(string localeName, LocaleStringData type)
- {
- uint lctype = (uint)type;
-
- return GetLocaleInfoFromLCType(localeName, lctype, UseUserOverride);
- }
-
- private int GetLocaleInfo(LocaleNumberData type)
- {
- uint lctype = (uint)type;
-
- // Fix lctype if we don't want overrides
- if (!UseUserOverride)
- {
- lctype |= Interop.Kernel32.LOCALE_NOUSEROVERRIDE;
- }
-
- // Ask OS for data, note that we presume it returns success, so we have to know that
- // sWindowsName is valid before calling.
- Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
- return GetLocaleInfoExInt(_sWindowsName, lctype);
- }
-
- private int[] GetLocaleInfo(LocaleGroupingData type)
- {
- Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
- return ConvertWin32GroupString(GetLocaleInfoFromLCType(_sWindowsName, (uint)type, UseUserOverride));
- }
-
- private string? GetTimeFormatString()
- {
- Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
- return ReescapeWin32String(GetLocaleInfoFromLCType(_sWindowsName, Interop.Kernel32.LOCALE_STIMEFORMAT, UseUserOverride));
- }
-
- private int GetFirstDayOfWeek()
- {
- Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
-
- int result = GetLocaleInfoExInt(_sWindowsName, Interop.Kernel32.LOCALE_IFIRSTDAYOFWEEK | (!UseUserOverride ? Interop.Kernel32.LOCALE_NOUSEROVERRIDE : 0));
-
- // Win32 and .NET disagree on the numbering for days of the week, so we have to convert.
- return ConvertFirstDayOfWeekMonToSun(result);
- }
-
- private string[]? GetTimeFormats()
- {
- // Note that this gets overrides for us all the time
- Debug.Assert(_sWindowsName != null, "[CultureData.DoEnumTimeFormats] Expected _sWindowsName to be populated by already");
- string[]? result = ReescapeWin32Strings(nativeEnumTimeFormats(_sWindowsName, 0, UseUserOverride));
-
- return result;
- }
-
- private string[]? GetShortTimeFormats()
- {
- // Note that this gets overrides for us all the time
- Debug.Assert(_sWindowsName != null, "[CultureData.DoEnumShortTimeFormats] Expected _sWindowsName to be populated by already");
- string[]? result = ReescapeWin32Strings(nativeEnumTimeFormats(_sWindowsName, Interop.Kernel32.TIME_NOSECONDS, UseUserOverride));
-
- return result;
- }
-
- // Enumerate all system cultures and then try to find out which culture has
- // region name match the requested region name
- private static CultureData? GetCultureDataFromRegionName(string regionName)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(regionName != null);
-
- EnumLocaleData context;
- context.cultureName = null;
- context.regionName = regionName;
-
- unsafe
- {
- Interop.Kernel32.EnumSystemLocalesEx(EnumSystemLocalesProc, Interop.Kernel32.LOCALE_SPECIFICDATA | Interop.Kernel32.LOCALE_SUPPLEMENTAL, Unsafe.AsPointer(ref context), IntPtr.Zero);
- }
-
- if (context.cultureName != null)
- {
- // we got a matched culture
- return GetCultureData(context.cultureName, true);
- }
-
- return null;
- }
-
- private string GetLanguageDisplayName(string cultureName)
- {
- // Usually the UI culture shouldn't be different than what we got from WinRT except
- // if DefaultThreadCurrentUICulture was set
- CultureInfo? ci;
-
- if (CultureInfo.DefaultThreadCurrentUICulture != null &&
- ((ci = CultureInfo.GetUserDefaultCulture()) != null) &&
- !CultureInfo.DefaultThreadCurrentUICulture.Name.Equals(ci.Name))
- {
- return NativeName;
- }
- else
- {
- return GetLocaleInfo(cultureName, LocaleStringData.LocalizedDisplayName);
- }
- }
-
- private string GetRegionDisplayName()
- {
- // If the current UI culture matching the OS UI language, we'll get the display name from the OS.
- // otherwise, we use the native name as we don't carry resources for the region display names anyway.
- if (CultureInfo.CurrentUICulture.Name.Equals(CultureInfo.UserDefaultUICulture.Name))
- {
- return GetLocaleInfo(LocaleStringData.LocalizedCountryName);
- }
-
- return NativeCountryName;
- }
-
- // PAL methods end here.
-
- private static string GetLocaleInfoFromLCType(string localeName, uint lctype, bool useUserOveride)
- {
- Debug.Assert(localeName != null, "[CultureData.GetLocaleInfoFromLCType] Expected localeName to be not be null");
-
- // Fix lctype if we don't want overrides
- if (!useUserOveride)
- {
- lctype |= Interop.Kernel32.LOCALE_NOUSEROVERRIDE;
- }
-
- // Ask OS for data
- // Failed? Just use empty string
- return GetLocaleInfoEx(localeName, lctype) ?? string.Empty;
- }
-
- /// <summary>
- /// Reescape a Win32 style quote string as a NLS+ style quoted string
- ///
- /// This is also the escaping style used by custom culture data files
- ///
- /// NLS+ uses \ to escape the next character, whether in a quoted string or
- /// not, so we always have to change \ to \\.
- ///
- /// NLS+ uses \' to escape a quote inside a quoted string so we have to change
- /// '' to \' (if inside a quoted string)
- ///
- /// We don't build the stringbuilder unless we find something to change
- /// </summary>
- [return: NotNullIfNotNull("str")]
- internal static string? ReescapeWin32String(string? str)
- {
- // If we don't have data, then don't try anything
- if (str == null)
- {
- return null;
- }
-
- StringBuilder? result = null;
-
- bool inQuote = false;
- for (int i = 0; i < str.Length; i++)
- {
- // Look for quote
- if (str[i] == '\'')
- {
- // Already in quote?
- if (inQuote)
- {
- // See another single quote. Is this '' of 'fred''s' or '''', or is it an ending quote?
- if (i + 1 < str.Length && str[i + 1] == '\'')
- {
- // Found another ', so we have ''. Need to add \' instead.
- // 1st make sure we have our stringbuilder
- result ??= new StringBuilder(str, 0, i, str.Length * 2);
-
- // Append a \' and keep going (so we don't turn off quote mode)
- result.Append("\\'");
- i++;
- continue;
- }
-
- // Turning off quote mode, fall through to add it
- inQuote = false;
- }
- else
- {
- // Found beginning quote, fall through to add it
- inQuote = true;
- }
- }
- // Is there a single \ character?
- else if (str[i] == '\\')
- {
- // Found a \, need to change it to \\
- // 1st make sure we have our stringbuilder
- result ??= new StringBuilder(str, 0, i, str.Length * 2);
-
- // Append our \\ to the string & continue
- result.Append("\\\\");
- continue;
- }
-
- // If we have a builder we need to add our character
- result?.Append(str[i]);
- }
-
- // Unchanged string? , just return input string
- if (result == null)
- return str;
-
- // String changed, need to use the builder
- return result.ToString();
- }
-
- [return: NotNullIfNotNull("array")]
- internal static string[]? ReescapeWin32Strings(string[]? array)
- {
- if (array != null)
- {
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = ReescapeWin32String(array[i]);
- }
- }
-
- return array;
- }
-
- // If we get a group from windows, then its in 3;0 format with the 0 backwards
- // of how NLS+ uses it (ie: if the string has a 0, then the int[] shouldn't and vice versa)
- // EXCEPT in the case where the list only contains 0 in which NLS and NLS+ have the same meaning.
- private static int[] ConvertWin32GroupString(string win32Str)
- {
- // None of these cases make any sense
- if (string.IsNullOrEmpty(win32Str))
- {
- return new int[] { 3 };
- }
-
- if (win32Str[0] == '0')
- {
- return new int[] { 0 };
- }
-
- // Since its in n;n;n;n;n format, we can always get the length quickly
- int[] values;
- if (win32Str[^1] == '0')
- {
- // Trailing 0 gets dropped. 1;0 -> 1
- values = new int[win32Str.Length / 2];
- }
- else
- {
- // Need extra space for trailing zero 1 -> 1;0
- values = new int[(win32Str.Length / 2) + 2];
- values[^1] = 0;
- }
-
- int i;
- int j;
- for (i = 0, j = 0; i < win32Str.Length && j < values.Length; i += 2, j++)
- {
- // Note that this # shouldn't ever be zero, 'cause 0 is only at end
- // But we'll test because its registry that could be anything
- if (win32Str[i] < '1' || win32Str[i] > '9')
- return new int[] { 3 };
-
- values[j] = (int)(win32Str[i] - '0');
- }
-
- return values;
- }
-
- private static int ConvertFirstDayOfWeekMonToSun(int iTemp)
- {
- // Convert Mon-Sun to Sun-Sat format
- iTemp++;
- if (iTemp > 6)
- {
- // Wrap Sunday and convert invalid data to Sunday
- iTemp = 0;
- }
- return iTemp;
- }
-
- // Context for EnumCalendarInfoExEx callback.
- private struct EnumLocaleData
- {
- public string regionName;
- public string? cultureName;
- }
-
- // EnumSystemLocaleEx callback.
- // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
- private static unsafe Interop.BOOL EnumSystemLocalesProc(char* lpLocaleString, uint flags, void* contextHandle)
- {
- ref EnumLocaleData context = ref Unsafe.As<byte, EnumLocaleData>(ref *(byte*)contextHandle);
- try
- {
- string cultureName = new string(lpLocaleString);
- string? regionName = GetLocaleInfoEx(cultureName, Interop.Kernel32.LOCALE_SISO3166CTRYNAME);
- if (regionName != null && regionName.Equals(context.regionName, StringComparison.OrdinalIgnoreCase))
- {
- context.cultureName = cultureName;
- return Interop.BOOL.FALSE; // we found a match, then stop the enumeration
- }
-
- return Interop.BOOL.TRUE;
- }
- catch (Exception)
- {
- return Interop.BOOL.FALSE;
- }
- }
-
- // EnumSystemLocaleEx callback.
- // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
- private static unsafe Interop.BOOL EnumAllSystemLocalesProc(char* lpLocaleString, uint flags, void* contextHandle)
- {
- ref EnumData context = ref Unsafe.As<byte, EnumData>(ref *(byte*)contextHandle);
- try
- {
- context.strings.Add(new string(lpLocaleString));
- return Interop.BOOL.TRUE;
- }
- catch (Exception)
- {
- return Interop.BOOL.FALSE;
- }
- }
-
- // Context for EnumTimeFormatsEx callback.
- private struct EnumData
- {
- public List<string> strings;
- }
-
- // EnumTimeFormatsEx callback itself.
- // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
- private static unsafe Interop.BOOL EnumTimeCallback(char* lpTimeFormatString, void* lParam)
- {
- ref EnumData context = ref Unsafe.As<byte, EnumData>(ref *(byte*)lParam);
- try
- {
- context.strings.Add(new string(lpTimeFormatString));
- return Interop.BOOL.TRUE;
- }
- catch (Exception)
- {
- return Interop.BOOL.FALSE;
- }
- }
-
- private static unsafe string[]? nativeEnumTimeFormats(string localeName, uint dwFlags, bool useUserOverride)
- {
- EnumData data = default;
- data.strings = new List<string>();
-
- // Now call the enumeration API. Work is done by our callback function
- Interop.Kernel32.EnumTimeFormatsEx(EnumTimeCallback, localeName, (uint)dwFlags, Unsafe.AsPointer(ref data));
-
- if (data.strings.Count > 0)
- {
- // Now we need to allocate our stringarray and populate it
- string[] results = data.strings.ToArray();
-
- if (!useUserOverride && data.strings.Count > 1)
- {
- // Since there is no "NoUserOverride" aware EnumTimeFormatsEx, we always get an override
- // The override is the first entry if it is overriden.
- // We can check if we have overrides by checking the GetLocaleInfo with no override
- // If we do have an override, we don't know if it is a user defined override or if the
- // user has just selected one of the predefined formats so we can't just remove it
- // but we can move it down.
- uint lcType = (dwFlags == Interop.Kernel32.TIME_NOSECONDS) ? Interop.Kernel32.LOCALE_SSHORTTIME : Interop.Kernel32.LOCALE_STIMEFORMAT;
- string timeFormatNoUserOverride = GetLocaleInfoFromLCType(localeName, lcType, useUserOverride);
- if (timeFormatNoUserOverride != "")
- {
- string firstTimeFormat = results[0];
- if (timeFormatNoUserOverride != firstTimeFormat)
- {
- results[0] = results[1];
- results[1] = firstTimeFormat;
- }
- }
- }
-
- return results;
- }
-
- return null;
- }
-
- private static int LocaleNameToLCID(string cultureName)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- return Interop.Kernel32.LocaleNameToLCID(cultureName, Interop.Kernel32.LOCALE_ALLOW_NEUTRAL_NAMES);
- }
-
- private static unsafe string? LCIDToLocaleName(int culture)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- char* pBuffer = stackalloc char[Interop.Kernel32.LOCALE_NAME_MAX_LENGTH + 1]; // +1 for the null termination
- int length = Interop.Kernel32.LCIDToLocaleName(culture, pBuffer, Interop.Kernel32.LOCALE_NAME_MAX_LENGTH + 1, Interop.Kernel32.LOCALE_ALLOW_NEUTRAL_NAMES);
-
- if (length > 0)
- {
- return new string(pBuffer);
- }
-
- return null;
- }
-
- private int GetAnsiCodePage(string cultureName)
- {
- return GetLocaleInfo(LocaleNumberData.AnsiCodePage);
- }
-
- private int GetOemCodePage(string cultureName)
- {
- return GetLocaleInfo(LocaleNumberData.OemCodePage);
- }
-
- private int GetMacCodePage(string cultureName)
- {
- return GetLocaleInfo(LocaleNumberData.MacCodePage);
- }
-
- private int GetEbcdicCodePage(string cultureName)
- {
- return GetLocaleInfo(LocaleNumberData.EbcdicCodePage);
- }
-
- private int GetGeoId(string cultureName)
- {
- return GetLocaleInfo(LocaleNumberData.GeoId);
- }
-
- private int GetDigitSubstitution(string cultureName)
- {
- return GetLocaleInfo(LocaleNumberData.DigitSubstitution);
- }
-
- private string GetThreeLetterWindowsLanguageName(string cultureName)
- {
- return GetLocaleInfo(cultureName, LocaleStringData.AbbreviatedWindowsLanguageName);
- }
-
- private static CultureInfo[] EnumCultures(CultureTypes types)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- uint flags = 0;
-
-#pragma warning disable 618
- if ((types & (CultureTypes.FrameworkCultures | CultureTypes.InstalledWin32Cultures | CultureTypes.ReplacementCultures)) != 0)
- {
- flags |= Interop.Kernel32.LOCALE_NEUTRALDATA | Interop.Kernel32.LOCALE_SPECIFICDATA;
- }
-#pragma warning restore 618
-
- if ((types & CultureTypes.NeutralCultures) != 0)
- {
- flags |= Interop.Kernel32.LOCALE_NEUTRALDATA;
- }
-
- if ((types & CultureTypes.SpecificCultures) != 0)
- {
- flags |= Interop.Kernel32.LOCALE_SPECIFICDATA;
- }
-
- if ((types & CultureTypes.UserCustomCulture) != 0)
- {
- flags |= Interop.Kernel32.LOCALE_SUPPLEMENTAL;
- }
-
- if ((types & CultureTypes.ReplacementCultures) != 0)
- {
- flags |= Interop.Kernel32.LOCALE_SUPPLEMENTAL;
- }
-
- EnumData context = default;
- context.strings = new List<string>();
-
- unsafe
- {
- Interop.Kernel32.EnumSystemLocalesEx(EnumAllSystemLocalesProc, flags, Unsafe.AsPointer(ref context), IntPtr.Zero);
- }
-
- CultureInfo[] cultures = new CultureInfo[context.strings.Count];
- for (int i = 0; i < cultures.Length; i++)
- {
- cultures[i] = new CultureInfo(context.strings[i]);
- }
-
- return cultures;
- }
-
- private string GetConsoleFallbackName(string cultureName)
- {
- return GetLocaleInfo(cultureName, LocaleStringData.ConsoleFallbackName);
- }
-
- internal bool IsWin32Installed => true;
-
- internal bool IsReplacementCulture
- {
- get
- {
- EnumData context = default;
- context.strings = new List<string>();
-
- unsafe
- {
- Interop.Kernel32.EnumSystemLocalesEx(EnumAllSystemLocalesProc, Interop.Kernel32.LOCALE_REPLACEMENT, Unsafe.AsPointer(ref context), IntPtr.Zero);
- }
-
- for (int i = 0; i < context.strings.Count; i++)
- {
- if (string.Equals(context.strings[i], _sWindowsName, StringComparison.OrdinalIgnoreCase))
- return true;
- }
-
- return false;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.cs
deleted file mode 100644
index cad208b1974..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.cs
+++ /dev/null
@@ -1,2252 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Text;
-
-namespace System.Globalization
-{
- /// <summary>
- /// List of culture data
- /// Note the we cache overrides.
- /// Note that localized names (resource names) aren't available from here.
- /// </summary>
- /// <remarks>
- /// Our names are a tad confusing.
- ///
- /// sWindowsName -- The name that windows thinks this culture is, ie:
- /// en-US if you pass in en-US
- /// de-DE_phoneb if you pass in de-DE_phoneb
- /// fj-FJ if you pass in fj (neutral, on a pre-Windows 7 machine)
- /// fj if you pass in fj (neutral, post-Windows 7 machine)
- ///
- /// sRealName -- The name you used to construct the culture, in pretty form
- /// en-US if you pass in EN-us
- /// en if you pass in en
- /// de-DE_phoneb if you pass in de-DE_phoneb
- ///
- /// sSpecificCulture -- The specific culture for this culture
- /// en-US for en-US
- /// en-US for en
- /// de-DE_phoneb for alt sort
- /// fj-FJ for fj (neutral)
- ///
- /// sName -- The IETF name of this culture (ie: no sort info, could be neutral)
- /// en-US if you pass in en-US
- /// en if you pass in en
- /// de-DE if you pass in de-DE_phoneb
- /// </remarks>
- internal partial class CultureData
- {
- private const int LocaleNameMaxLength = 85;
- private const int undef = -1;
-
- // Override flag
- private string _sRealName = null!; // Name you passed in (ie: en-US, en, or de-DE_phoneb). Initialized by helper called during initialization.
- private string? _sWindowsName; // Name OS thinks the object is (ie: de-DE_phoneb, or en-US (even if en was passed in))
-
- // Identity
- private string? _sName; // locale name (ie: en-us, NO sort info, but could be neutral)
- private string? _sParent; // Parent name (which may be a custom locale/culture)
- private string? _sLocalizedDisplayName; // Localized pretty name for this locale
- private string? _sEnglishDisplayName; // English pretty name for this locale
- private string? _sNativeDisplayName; // Native pretty name for this locale
- private string? _sSpecificCulture; // The culture name to be used in CultureInfo.CreateSpecificCulture(), en-US form if neutral, sort name if sort
-
- // Language
- private string? _sISO639Language; // ISO 639 Language Name
- private string? _sISO639Language2; // ISO 639 Language Name
- private string? _sLocalizedLanguage; // Localized name for this language
- private string? _sEnglishLanguage; // English name for this language
- private string? _sNativeLanguage; // Native name of this language
- private string? _sAbbrevLang; // abbreviated language name (Windows Language Name) ex: ENU
- private string? _sConsoleFallbackName; // The culture name for the console fallback UI culture
- private int _iInputLanguageHandle = undef; // input language handle
-
- // Region
- private string? _sRegionName; // (RegionInfo)
- private string? _sLocalizedCountry; // localized country name
- private string? _sEnglishCountry; // english country name (RegionInfo)
- private string? _sNativeCountry; // native country name
- private string? _sISO3166CountryName; // ISO 3166 (RegionInfo), ie: US
- private string? _sISO3166CountryName2; // 3 char ISO 3166 country name 2 2(RegionInfo) ex: USA (ISO)
- private int _iGeoId = undef; // GeoId
-
- // Numbers
- private string? _sPositiveSign; // (user can override) positive sign
- private string? _sNegativeSign; // (user can override) negative sign
- // (nfi populates these 5, don't have to be = undef)
- private int _iDigits; // (user can override) number of fractional digits
- private int _iNegativeNumber; // (user can override) negative number format
- private int[]? _waGrouping; // (user can override) grouping of digits
- private string? _sDecimalSeparator; // (user can override) decimal separator
- private string? _sThousandSeparator; // (user can override) thousands separator
- private string? _sNaN; // Not a Number
- private string? _sPositiveInfinity; // + Infinity
- private string? _sNegativeInfinity; // - Infinity
-
- // Percent
- private int _iNegativePercent = undef; // Negative Percent (0-3)
- private int _iPositivePercent = undef; // Positive Percent (0-11)
- private string? _sPercent; // Percent (%) symbol
- private string? _sPerMille; // PerMille symbol
-
- // Currency
- private string? _sCurrency; // (user can override) local monetary symbol
- private string? _sIntlMonetarySymbol; // international monetary symbol (RegionInfo)
- private string? _sEnglishCurrency; // English name for this currency
- private string? _sNativeCurrency; // Native name for this currency
- // (nfi populates these 4, don't have to be = undef)
- private int _iCurrencyDigits; // (user can override) # local monetary fractional digits
- private int _iCurrency; // (user can override) positive currency format
- private int _iNegativeCurrency; // (user can override) negative currency format
- private int[]? _waMonetaryGrouping; // (user can override) monetary grouping of digits
- private string? _sMonetaryDecimal; // (user can override) monetary decimal separator
- private string? _sMonetaryThousand; // (user can override) monetary thousands separator
-
- // Misc
- private int _iMeasure = undef; // (user can override) system of measurement 0=metric, 1=US (RegionInfo)
- private string? _sListSeparator; // (user can override) list separator
-
- // Time
- private string? _sAM1159; // (user can override) AM designator
- private string? _sPM2359; // (user can override) PM designator
- private string? _sTimeSeparator;
- private volatile string[]? _saLongTimes; // (user can override) time format
- private volatile string[]? _saShortTimes; // short time format
- private volatile string[]? _saDurationFormats; // time duration format
-
- // Calendar specific data
- private int _iFirstDayOfWeek = undef; // (user can override) first day of week (gregorian really)
- private int _iFirstWeekOfYear = undef; // (user can override) first week of year (gregorian really)
- private volatile CalendarId[]? _waCalendars; // all available calendar type(s). The first one is the default calendar
-
- // Store for specific data about each calendar
- private CalendarData?[]? _calendars; // Store for specific calendar data
-
- // Text information
- private int _iReadingLayout = undef; // Reading layout data
- // 0 - Left to right (eg en-US)
- // 1 - Right to left (eg arabic locales)
- // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
- // 3 - Vertical top to bottom with columns proceeding to the right
-
- // CoreCLR depends on this even though its not exposed publicly.
-
- private int _iDefaultAnsiCodePage = undef; // default ansi code page ID (ACP)
- private int _iDefaultOemCodePage = undef; // default oem code page ID (OCP or OEM)
- private int _iDefaultMacCodePage = undef; // default macintosh code page
- private int _iDefaultEbcdicCodePage = undef; // default EBCDIC code page
-
- private int _iLanguage; // locale ID (0409) - NO sort information
- private bool _bUseOverrides; // use user overrides?
- private bool _bNeutral; // Flags for the culture (ie: neutral or not right now)
-
- /// <summary>
- /// Region Name to Culture Name mapping table
- /// </summary>
- /// <remarks>
- /// Using a property so we avoid creating the dictionary until we need it
- /// </remarks>
- private static Dictionary<string, string> RegionNames =>
- s_regionNames ??=
- new Dictionary<string, string>(211 /* prime */)
- {
- { "029", "en-029" },
- { "AE", "ar-AE" },
- { "AF", "prs-AF" },
- { "AL", "sq-AL" },
- { "AM", "hy-AM" },
- { "AR", "es-AR" },
- { "AT", "de-AT" },
- { "AU", "en-AU" },
- { "AZ", "az-Cyrl-AZ" },
- { "BA", "bs-Latn-BA" },
- { "BD", "bn-BD" },
- { "BE", "nl-BE" },
- { "BG", "bg-BG" },
- { "BH", "ar-BH" },
- { "BN", "ms-BN" },
- { "BO", "es-BO" },
- { "BR", "pt-BR" },
- { "BY", "be-BY" },
- { "BZ", "en-BZ" },
- { "CA", "en-CA" },
- { "CH", "it-CH" },
- { "CL", "es-CL" },
- { "CN", "zh-CN" },
- { "CO", "es-CO" },
- { "CR", "es-CR" },
- { "CS", "sr-Cyrl-CS" },
- { "CZ", "cs-CZ" },
- { "DE", "de-DE" },
- { "DK", "da-DK" },
- { "DO", "es-DO" },
- { "DZ", "ar-DZ" },
- { "EC", "es-EC" },
- { "EE", "et-EE" },
- { "EG", "ar-EG" },
- { "ES", "es-ES" },
- { "ET", "am-ET" },
- { "FI", "fi-FI" },
- { "FO", "fo-FO" },
- { "FR", "fr-FR" },
- { "GB", "en-GB" },
- { "GE", "ka-GE" },
- { "GL", "kl-GL" },
- { "GR", "el-GR" },
- { "GT", "es-GT" },
- { "HK", "zh-HK" },
- { "HN", "es-HN" },
- { "HR", "hr-HR" },
- { "HU", "hu-HU" },
- { "ID", "id-ID" },
- { "IE", "en-IE" },
- { "IL", "he-IL" },
- { "IN", "hi-IN" },
- { "IQ", "ar-IQ" },
- { "IR", "fa-IR" },
- { "IS", "is-IS" },
- { "IT", "it-IT" },
- { "IV", "" },
- { "JM", "en-JM" },
- { "JO", "ar-JO" },
- { "JP", "ja-JP" },
- { "KE", "sw-KE" },
- { "KG", "ky-KG" },
- { "KH", "km-KH" },
- { "KR", "ko-KR" },
- { "KW", "ar-KW" },
- { "KZ", "kk-KZ" },
- { "LA", "lo-LA" },
- { "LB", "ar-LB" },
- { "LI", "de-LI" },
- { "LK", "si-LK" },
- { "LT", "lt-LT" },
- { "LU", "lb-LU" },
- { "LV", "lv-LV" },
- { "LY", "ar-LY" },
- { "MA", "ar-MA" },
- { "MC", "fr-MC" },
- { "ME", "sr-Latn-ME" },
- { "MK", "mk-MK" },
- { "MN", "mn-MN" },
- { "MO", "zh-MO" },
- { "MT", "mt-MT" },
- { "MV", "dv-MV" },
- { "MX", "es-MX" },
- { "MY", "ms-MY" },
- { "NG", "ig-NG" },
- { "NI", "es-NI" },
- { "NL", "nl-NL" },
- { "NO", "nn-NO" },
- { "NP", "ne-NP" },
- { "NZ", "en-NZ" },
- { "OM", "ar-OM" },
- { "PA", "es-PA" },
- { "PE", "es-PE" },
- { "PH", "en-PH" },
- { "PK", "ur-PK" },
- { "PL", "pl-PL" },
- { "PR", "es-PR" },
- { "PT", "pt-PT" },
- { "PY", "es-PY" },
- { "QA", "ar-QA" },
- { "RO", "ro-RO" },
- { "RS", "sr-Latn-RS" },
- { "RU", "ru-RU" },
- { "RW", "rw-RW" },
- { "SA", "ar-SA" },
- { "SE", "sv-SE" },
- { "SG", "zh-SG" },
- { "SI", "sl-SI" },
- { "SK", "sk-SK" },
- { "SN", "wo-SN" },
- { "SV", "es-SV" },
- { "SY", "ar-SY" },
- { "TH", "th-TH" },
- { "TJ", "tg-Cyrl-TJ" },
- { "TM", "tk-TM" },
- { "TN", "ar-TN" },
- { "TR", "tr-TR" },
- { "TT", "en-TT" },
- { "TW", "zh-TW" },
- { "UA", "uk-UA" },
- { "US", "en-US" },
- { "UY", "es-UY" },
- { "UZ", "uz-Cyrl-UZ" },
- { "VE", "es-VE" },
- { "VN", "vi-VN" },
- { "YE", "ar-YE" },
- { "ZA", "af-ZA" },
- { "ZW", "en-ZW" }
- };
-
- // Cache of regions we've already looked up
- private static volatile Dictionary<string, CultureData>? s_cachedRegions;
- private static volatile Dictionary<string, string>? s_regionNames;
-
- internal static CultureData? GetCultureDataForRegion(string? cultureName, bool useUserOverride)
- {
- // First do a shortcut for Invariant
- if (string.IsNullOrEmpty(cultureName))
- {
- return CultureData.Invariant;
- }
-
- // First check if GetCultureData() can find it (ie: its a real culture)
- CultureData? retVal = GetCultureData(cultureName, useUserOverride);
- if (retVal != null && !retVal.IsNeutralCulture)
- {
- return retVal;
- }
-
- // Not a specific culture, perhaps it's region-only name
- // (Remember this isn't a core clr path where that's not supported)
-
- // If it was neutral remember that so that RegionInfo() can throw the right exception
- CultureData? neutral = retVal;
-
- // Try the hash table next
- string hashName = AnsiToLower(useUserOverride ? cultureName : cultureName + '*');
- Dictionary<string, CultureData>? tempHashTable = s_cachedRegions;
-
- if (tempHashTable == null)
- {
- // No table yet, make a new one
- tempHashTable = new Dictionary<string, CultureData>();
- }
- else
- {
- // Check the hash table
- lock (s_lock)
- {
- tempHashTable.TryGetValue(hashName, out retVal);
- }
- if (retVal != null)
- {
- return retVal;
- }
- }
-
- // Not found in the hash table, look it up the hard way
-
- // If not a valid mapping from the registry we'll have to try the hard coded table
- if (retVal == null || retVal.IsNeutralCulture)
- {
- // Not a valid mapping, try the hard coded table
- string? name;
- if (RegionNames.TryGetValue(cultureName, out name))
- {
- // Make sure we can get culture data for it
- retVal = GetCultureData(name, useUserOverride);
- }
- }
-
- // If not found in the hard coded table we'll have to find a culture that works for us
- if (!GlobalizationMode.Invariant && (retVal == null || retVal.IsNeutralCulture))
- {
- retVal = GetCultureDataFromRegionName(cultureName);
- }
-
- // If we found one we can use, then cache it for next time
- if (retVal != null && !retVal.IsNeutralCulture)
- {
- // first add it to the cache
- lock (s_lock)
- {
- tempHashTable[hashName] = retVal;
- }
-
- // Copy the hashtable to the corresponding member variables. This will potentially overwrite
- // new tables simultaneously created by a new thread, but maximizes thread safety.
- s_cachedRegions = tempHashTable;
- }
- else
- {
- // Unable to find a matching culture/region, return null or neutral
- // (regionInfo throws a more specific exception on neutrals)
- retVal = neutral;
- }
-
- // Return the found culture to use, null, or the neutral culture.
- return retVal;
- }
-
- // Clear our internal caches
- internal static void ClearCachedData()
- {
- s_cachedCultures = null;
- s_cachedRegions = null;
- }
-
- internal static CultureInfo[] GetCultures(CultureTypes types)
- {
- // Disable warning 618: System.Globalization.CultureTypes.FrameworkCultures' is obsolete
-#pragma warning disable 618
- // Validate flags
- if ((int)types <= 0 || ((int)types & (int)~(CultureTypes.NeutralCultures | CultureTypes.SpecificCultures |
- CultureTypes.InstalledWin32Cultures | CultureTypes.UserCustomCulture |
- CultureTypes.ReplacementCultures | CultureTypes.WindowsOnlyCultures |
- CultureTypes.FrameworkCultures)) != 0)
- {
- throw new ArgumentOutOfRangeException(nameof(types),
- SR.Format(SR.ArgumentOutOfRange_Range, CultureTypes.NeutralCultures, CultureTypes.FrameworkCultures));
- }
-
- // We have deprecated CultureTypes.FrameworkCultures.
- // When this enum is used, we will enumerate Whidbey framework cultures (for compatibility).
-
- // We have deprecated CultureTypes.WindowsOnlyCultures.
- // When this enum is used, we will return an empty array for this enum.
- if ((types & CultureTypes.WindowsOnlyCultures) != 0)
- {
- // Remove the enum as it is an no-op.
- types &= (~CultureTypes.WindowsOnlyCultures);
- }
-
- if (GlobalizationMode.Invariant)
- {
- // in invariant mode we always return invariant culture only from the enumeration
- return new CultureInfo[] { new CultureInfo("") };
- }
-
-#pragma warning restore 618
- return EnumCultures(types);
- }
-
- private static CultureData CreateCultureWithInvariantData()
- {
- // Make a new culturedata
- CultureData invariant = new CultureData();
-
- // Basics
- // Note that we override the resources since this IS NOT supposed to change (by definition)
- invariant._bUseOverrides = false;
- invariant._sRealName = ""; // Name you passed in (ie: en-US, en, or de-DE_phoneb)
- invariant._sWindowsName = ""; // Name OS thinks the object is (ie: de-DE_phoneb, or en-US (even if en was passed in))
-
- // Identity
- invariant._sName = ""; // locale name (ie: en-us)
- invariant._sParent = ""; // Parent name (which may be a custom locale/culture)
- invariant._bNeutral = false; // Flags for the culture (ie: neutral or not right now)
- invariant._sEnglishDisplayName = "Invariant Language (Invariant Country)"; // English pretty name for this locale
- invariant._sNativeDisplayName = "Invariant Language (Invariant Country)"; // Native pretty name for this locale
- invariant._sSpecificCulture = ""; // The culture name to be used in CultureInfo.CreateSpecificCulture()
-
- // Language
- invariant._sISO639Language = "iv"; // ISO 639 Language Name
- invariant._sISO639Language2 = "ivl"; // 3 char ISO 639 lang name 2
- invariant._sLocalizedLanguage = "Invariant Language"; // Display name for this Language
- invariant._sEnglishLanguage = "Invariant Language"; // English name for this language
- invariant._sNativeLanguage = "Invariant Language"; // Native name of this language
- invariant._sAbbrevLang = "IVL"; // abbreviated language name (Windows Language Name)
- invariant._sConsoleFallbackName = ""; // The culture name for the console fallback UI culture
- invariant._iInputLanguageHandle = 0x07F; // input language handle
-
- // Region
- invariant._sRegionName = "IV"; // (RegionInfo)
- invariant._sEnglishCountry = "Invariant Country"; // english country name (RegionInfo)
- invariant._sNativeCountry = "Invariant Country"; // native country name (Windows Only)
- invariant._sISO3166CountryName = "IV"; // (RegionInfo), ie: US
- invariant._sISO3166CountryName2 = "ivc"; // 3 char ISO 3166 country name 2 2(RegionInfo)
- invariant._iGeoId = 244; // GeoId (Windows Only)
-
- // Numbers
- invariant._sPositiveSign = "+"; // positive sign
- invariant._sNegativeSign = "-"; // negative sign
- invariant._iDigits = 2; // number of fractional digits
- invariant._iNegativeNumber = 1; // negative number format
- invariant._waGrouping = new int[] { 3 }; // grouping of digits
- invariant._sDecimalSeparator = "."; // decimal separator
- invariant._sThousandSeparator = ","; // thousands separator
- invariant._sNaN = "NaN"; // Not a Number
- invariant._sPositiveInfinity = "Infinity"; // + Infinity
- invariant._sNegativeInfinity = "-Infinity"; // - Infinity
-
- // Percent
- invariant._iNegativePercent = 0; // Negative Percent (0-3)
- invariant._iPositivePercent = 0; // Positive Percent (0-11)
- invariant._sPercent = "%"; // Percent (%) symbol
- invariant._sPerMille = "\x2030"; // PerMille symbol
-
- // Currency
- invariant._sCurrency = "\x00a4"; // local monetary symbol: for international monetary symbol
- invariant._sIntlMonetarySymbol = "XDR"; // international monetary symbol (RegionInfo)
- invariant._sEnglishCurrency = "International Monetary Fund"; // English name for this currency (Windows Only)
- invariant._sNativeCurrency = "International Monetary Fund"; // Native name for this currency (Windows Only)
- invariant._iCurrencyDigits = 2; // # local monetary fractional digits
- invariant._iCurrency = 0; // positive currency format
- invariant._iNegativeCurrency = 0; // negative currency format
- invariant._waMonetaryGrouping = new int[] { 3 }; // monetary grouping of digits
- invariant._sMonetaryDecimal = "."; // monetary decimal separator
- invariant._sMonetaryThousand = ","; // monetary thousands separator
-
- // Misc
- invariant._iMeasure = 0; // system of measurement 0=metric, 1=US (RegionInfo)
- invariant._sListSeparator = ","; // list separator
-
- // Time
- invariant._sTimeSeparator = ":";
- invariant._sAM1159 = "AM"; // AM designator
- invariant._sPM2359 = "PM"; // PM designator
- invariant._saLongTimes = new string[] { "HH:mm:ss" }; // time format
- invariant._saShortTimes = new string[] { "HH:mm", "hh:mm tt", "H:mm", "h:mm tt" }; // short time format
- invariant._saDurationFormats = new string[] { "HH:mm:ss" }; // time duration format
-
- // Calendar specific data
- invariant._iFirstDayOfWeek = 0; // first day of week
- invariant._iFirstWeekOfYear = 0; // first week of year
- invariant._waCalendars = new CalendarId[] { CalendarId.GREGORIAN }; // all available calendar type(s). The first one is the default calendar
-
- // Store for specific data about each calendar
- invariant._calendars = new CalendarData[CalendarData.MAX_CALENDARS];
- invariant._calendars[0] = CalendarData.Invariant;
-
- // Text information
- invariant._iReadingLayout = 0;
-
- // These are desktop only, not coreclr
-
- invariant._iLanguage = CultureInfo.LOCALE_INVARIANT; // locale ID (0409) - NO sort information
- invariant._iDefaultAnsiCodePage = 1252; // default ansi code page ID (ACP)
- invariant._iDefaultOemCodePage = 437; // default oem code page ID (OCP or OEM)
- invariant._iDefaultMacCodePage = 10000; // default macintosh code page
- invariant._iDefaultEbcdicCodePage = 037; // default EBCDIC code page
-
- if (GlobalizationMode.Invariant)
- {
- invariant._sLocalizedDisplayName = invariant._sNativeDisplayName;
- invariant._sLocalizedCountry = invariant._sNativeCountry;
- }
-
- return invariant;
- }
-
- /// <summary>
- /// Build our invariant information
- /// We need an invariant instance, which we build hard-coded
- /// </summary>
- internal static CultureData Invariant => s_Invariant ??= CreateCultureWithInvariantData();
- private static volatile CultureData? s_Invariant;
-
- // Cache of cultures we've already looked up
- private static volatile Dictionary<string, CultureData>? s_cachedCultures;
- private static readonly object s_lock = new object();
-
- internal static CultureData? GetCultureData(string? cultureName, bool useUserOverride)
- {
- // First do a shortcut for Invariant
- if (string.IsNullOrEmpty(cultureName))
- {
- return CultureData.Invariant;
- }
-
- // Try the hash table first
- string hashName = AnsiToLower(useUserOverride ? cultureName : cultureName + '*');
- Dictionary<string, CultureData>? tempHashTable = s_cachedCultures;
- if (tempHashTable == null)
- {
- // No table yet, make a new one
- tempHashTable = new Dictionary<string, CultureData>();
- }
- else
- {
- // Check the hash table
- bool ret;
- CultureData? retVal;
- lock (s_lock)
- {
- ret = tempHashTable.TryGetValue(hashName, out retVal);
- }
- if (ret && retVal != null)
- {
- return retVal;
- }
- }
-
- // Not found in the hash table, need to see if we can build one that works for us
- CultureData? culture = CreateCultureData(cultureName, useUserOverride);
- if (culture == null)
- {
- return null;
- }
-
- // Found one, add it to the cache
- lock (s_lock)
- {
- tempHashTable[hashName] = culture;
- }
-
- // Copy the hashtable to the corresponding member variables. This will potentially overwrite
- // new tables simultaneously created by a new thread, but maximizes thread safety.
- s_cachedCultures = tempHashTable;
-
- return culture;
- }
-
- private static string NormalizeCultureName(string name, out bool isNeutralName)
- {
- isNeutralName = true;
- int i = 0;
-
- if (name.Length > LocaleNameMaxLength)
- {
- // Theoretically we shouldn't hit this exception.
- throw new ArgumentException(SR.Format(SR.Argument_InvalidId, nameof(name)));
- }
-
- Span<char> normalizedName = stackalloc char[name.Length];
-
- bool changed = false;
-
- while (i < name.Length && name[i] != '-' && name[i] != '_')
- {
- if (name[i] >= 'A' && name[i] <= 'Z')
- {
- // lowercase characters before '-'
- normalizedName[i] = (char)(((int)name[i]) + 0x20);
- changed = true;
- }
- else
- {
- normalizedName[i] = name[i];
- }
- i++;
- }
-
- if (i < name.Length)
- {
- // this is not perfect to detect the non neutral cultures but it is good enough when we are running in invariant mode
- isNeutralName = false;
- }
-
- while (i < name.Length)
- {
- if (name[i] >= 'a' && name[i] <= 'z')
- {
- normalizedName[i] = (char)(((int)name[i]) - 0x20);
- changed = true;
- }
- else
- {
- normalizedName[i] = name[i];
- }
- i++;
- }
-
- if (changed)
- {
- return new string(normalizedName);
- }
-
- return name;
- }
-
- private static CultureData? CreateCultureData(string cultureName, bool useUserOverride)
- {
- if (GlobalizationMode.Invariant)
- {
- if (cultureName.Length > LocaleNameMaxLength || !CultureInfo.VerifyCultureName(cultureName, false))
- {
- return null;
- }
- CultureData cd = CreateCultureWithInvariantData();
- cd._bUseOverrides = useUserOverride;
- cd._sName = NormalizeCultureName(cultureName, out cd._bNeutral);
- cd._sRealName = cd._sName;
- cd._sWindowsName = cd._sName;
- cd._iLanguage = CultureInfo.LOCALE_CUSTOM_UNSPECIFIED;
-
- return cd;
- }
-
- if (cultureName.Length == 1 && (cultureName[0] == 'C' || cultureName[0] == 'c'))
- {
- // Always map the "C" locale to Invariant to avoid mapping it to en_US_POSIX on Linux because POSIX
- // locale collation doesn't support case insensitive comparisons.
- // We do the same mapping on Windows for the sake of consistency.
- return CultureData.Invariant;
- }
-
- CultureData culture = new CultureData();
- culture._bUseOverrides = useUserOverride;
- culture._sRealName = cultureName;
-
- // Ask native code if that one's real
- if (!culture.InitCultureData() && !culture.InitCompatibilityCultureData())
- {
- return null;
- }
-
- return culture;
- }
-
- private bool InitCompatibilityCultureData()
- {
- // for compatibility handle the deprecated ids: zh-chs, zh-cht
- string cultureName = _sRealName!;
-
- string fallbackCultureName;
- string realCultureName;
- switch (AnsiToLower(cultureName))
- {
- case "zh-chs":
- fallbackCultureName = "zh-Hans";
- realCultureName = "zh-CHS";
- break;
- case "zh-cht":
- fallbackCultureName = "zh-Hant";
- realCultureName = "zh-CHT";
- break;
- default:
- return false;
- }
-
- _sRealName = fallbackCultureName;
- if (!InitCultureData())
- {
- return false;
- }
-
- // fixup our data
- _sName = realCultureName; // the name that goes back to the user
- _sParent = fallbackCultureName;
-
- return true;
- }
-
- /// We'd rather people use the named version since this doesn't allow custom locales
- internal static CultureData GetCultureData(int culture, bool bUseUserOverride)
- {
- string? localeName = null;
- CultureData? retVal = null;
-
- if (culture == CultureInfo.LOCALE_INVARIANT)
- {
- return Invariant;
- }
-
- if (GlobalizationMode.Invariant)
- {
- // LCID is not supported in the InvariantMode
- throw new CultureNotFoundException(nameof(culture), culture, SR.Argument_CultureNotSupported);
- }
-
- // Convert the lcid to a name, then use that
- // Note that this will return neutral names (unlike Vista native API)
- localeName = LCIDToLocaleName(culture);
-
- if (!string.IsNullOrEmpty(localeName))
- {
- // Valid name, use it
- retVal = GetCultureData(localeName, bUseUserOverride);
- }
-
- // If not successful, throw
- if (retVal == null)
- {
- throw new CultureNotFoundException(nameof(culture), culture, SR.Argument_CultureNotSupported);
- }
-
- // Return the one we found
- return retVal;
- }
-
- /// <summary>
- /// The real name used to construct the locale (ie: de-DE_phoneb)
- /// </summary>
- internal string CultureName
- {
- get
- {
- Debug.Assert(_sRealName != null, "[CultureData.CultureName] Expected _sRealName to be populated by already");
- // since windows doesn't know about zh-CHS and zh-CHT,
- // we leave sRealName == zh-Hanx but we still need to
- // pretend that it was zh-CHX.
- switch (_sName)
- {
- case "zh-CHS":
- case "zh-CHT":
- return _sName;
- }
- return _sRealName;
- }
- }
-
- /// <summary>
- /// Are overrides enabled?
- /// </summary>
- internal bool UseUserOverride => _bUseOverrides;
-
- /// <summary>
- /// locale name (ie: de-DE, NO sort information)
- /// </summary>
- internal string Name => _sName ?? string.Empty;
-
- // Parent name (which may be a custom locale/culture)
- // Ask using the real name, so that we get parents of neutrals
- internal string ParentName => _sParent ??= GetLocaleInfo(_sRealName!, LocaleStringData.ParentName);
-
- // Localized pretty name for this locale (ie: Inglis (estados Unitos))
- internal string DisplayName
- {
- get
- {
- string? localizedDisplayName = _sLocalizedDisplayName;
- if (localizedDisplayName == null)
- {
- if (IsSupplementalCustomCulture)
- {
- if (IsNeutralCulture)
- {
- localizedDisplayName = NativeLanguageName;
- }
- else
- {
- localizedDisplayName = NativeName;
- }
- }
- else
- {
- try
- {
- const string ZH_CHT = "zh-CHT";
- const string ZH_CHS = "zh-CHS";
-
- if (Name.Equals(ZH_CHT, StringComparison.OrdinalIgnoreCase))
- {
- localizedDisplayName = GetLanguageDisplayName("zh-Hant");
- }
- else if (Name.Equals(ZH_CHS, StringComparison.OrdinalIgnoreCase))
- {
- localizedDisplayName = GetLanguageDisplayName("zh-Hans");
- }
- else
- {
- localizedDisplayName = GetLanguageDisplayName(Name);
- }
- }
- catch
- {
- // do nothing
- }
- }
-
- // If it hasn't been found (Windows 8 and up), fallback to the system
- if (string.IsNullOrEmpty(localizedDisplayName))
- {
- // If its neutral use the language name
- if (IsNeutralCulture)
- {
- localizedDisplayName = LocalizedLanguageName;
- }
- else
- {
- // Usually the UI culture shouldn't be different than what we got from WinRT except
- // if DefaultThreadCurrentUICulture was set
- CultureInfo ci;
-
- if (CultureInfo.DefaultThreadCurrentUICulture != null &&
- ((ci = CultureInfo.GetUserDefaultCulture()) != null) &&
- !CultureInfo.DefaultThreadCurrentUICulture.Name.Equals(ci.Name))
- {
- localizedDisplayName = NativeName;
- }
- else
- {
- localizedDisplayName = GetLocaleInfo(LocaleStringData.LocalizedDisplayName);
- }
- }
- }
-
- _sLocalizedDisplayName = localizedDisplayName;
- }
-
- return localizedDisplayName;
- }
- }
-
- /// <summary>
- /// English pretty name for this locale (ie: English (United States))
- /// </summary>
- internal string EnglishName
- {
- get
- {
- string? englishDisplayName = _sEnglishDisplayName;
- if (englishDisplayName == null)
- {
- // If its neutral use the language name
- if (IsNeutralCulture)
- {
- englishDisplayName = EnglishLanguageName;
- // differentiate the legacy display names
- switch (_sName)
- {
- case "zh-CHS":
- case "zh-CHT":
- englishDisplayName += " Legacy";
- break;
- }
- }
- else
- {
- englishDisplayName = GetLocaleInfo(LocaleStringData.EnglishDisplayName);
-
- // if it isn't found build one:
- if (string.IsNullOrEmpty(englishDisplayName))
- {
- // Our existing names mostly look like:
- // "English" + "United States" -> "English (United States)"
- // "Azeri (Latin)" + "Azerbaijan" -> "Azeri (Latin, Azerbaijan)"
- if (EnglishLanguageName[^1] == ')')
- {
- // "Azeri (Latin)" + "Azerbaijan" -> "Azeri (Latin, Azerbaijan)"
- englishDisplayName = string.Concat(
- EnglishLanguageName.AsSpan(0, _sEnglishLanguage!.Length - 1),
- ", ",
- EnglishCountryName,
- ")");
- }
- else
- {
- // "English" + "United States" -> "English (United States)"
- englishDisplayName = EnglishLanguageName + " (" + EnglishCountryName + ")";
- }
- }
- }
-
- _sEnglishDisplayName = englishDisplayName;
- }
-
- return englishDisplayName;
- }
- }
-
- /// <summary>
- /// Native pretty name for this locale (ie: Deutsch (Deutschland))
- /// </summary>
- internal string NativeName
- {
- get
- {
- string? nativeDisplayName = _sNativeDisplayName;
- if (nativeDisplayName == null)
- {
- // If its neutral use the language name
- if (IsNeutralCulture)
- {
- nativeDisplayName = NativeLanguageName;
- // differentiate the legacy display names
- switch (_sName)
- {
- case "zh-CHS":
- nativeDisplayName += " \u65E7\u7248";
- break;
- case "zh-CHT":
- nativeDisplayName += " \u820A\u7248";
- break;
- }
- }
- else
- {
- nativeDisplayName = GetLocaleInfo(LocaleStringData.NativeDisplayName);
-
- // if it isn't found build one:
- if (string.IsNullOrEmpty(nativeDisplayName))
- {
- // These should primarily be "Deutsch (Deutschland)" type names
- nativeDisplayName = NativeLanguageName + " (" + NativeCountryName + ")";
- }
- }
-
- _sNativeDisplayName = nativeDisplayName;
- }
-
- return nativeDisplayName;
- }
- }
-
- /// <summary>
- /// The culture name to be used in CultureInfo.CreateSpecificCulture()
- /// </summary>
- internal string SpecificCultureName
- {
- get
- {
- // This got populated during the culture initialization
- Debug.Assert(_sSpecificCulture != null, "[CultureData.SpecificCultureName] Expected this.sSpecificCulture to be populated by culture data initialization already");
- return _sSpecificCulture;
- }
- }
-
- /// <summary>
- /// iso 639 language name, ie: en
- /// </summary>
- internal string TwoLetterISOLanguageName => _sISO639Language ??= GetLocaleInfo(LocaleStringData.Iso639LanguageTwoLetterName);
-
- /// <summary>
- /// iso 639 language name, ie: eng
- /// </summary>
- internal string ThreeLetterISOLanguageName => _sISO639Language2 ??= GetLocaleInfo(LocaleStringData.Iso639LanguageThreeLetterName);
-
- /// <summary>
- /// abbreviated windows language name (ie: enu) (non-standard, avoid this)
- /// </summary>
- internal string ThreeLetterWindowsLanguageName => _sAbbrevLang ??= GetThreeLetterWindowsLanguageName(_sRealName!);
-
- /// <summary>
- /// Localized name for this language (Windows Only) ie: Inglis
- /// This is only valid for Windows 8 and higher neutrals:
- /// </summary>
- private string LocalizedLanguageName
- {
- get
- {
- if (_sLocalizedLanguage == null)
- {
- // Usually the UI culture shouldn't be different than what we got from WinRT except
- // if DefaultThreadCurrentUICulture was set
- CultureInfo ci;
-
- if (CultureInfo.DefaultThreadCurrentUICulture != null &&
- ((ci = CultureInfo.GetUserDefaultCulture()) != null) &&
- !CultureInfo.DefaultThreadCurrentUICulture!.Name.Equals(ci.Name))
- {
- _sLocalizedLanguage = NativeLanguageName;
- }
- else
- {
- _sLocalizedLanguage = GetLocaleInfo(LocaleStringData.LocalizedLanguageName);
- }
- }
-
- return _sLocalizedLanguage;
- }
- }
-
- /// <summary>
- /// English name for this language (Windows Only) ie: German
- /// </summary>
- private string EnglishLanguageName => _sEnglishLanguage ??= GetLocaleInfo(LocaleStringData.EnglishLanguageName);
-
- /// <summary>
- /// Native name of this language (Windows Only) ie: Deutsch
- /// </summary>
- private string NativeLanguageName => _sNativeLanguage ??= GetLocaleInfo(LocaleStringData.NativeLanguageName);
-
- /// <summary>
- /// region name (eg US)
- /// </summary>
- internal string RegionName => _sRegionName ??= GetLocaleInfo(LocaleStringData.Iso3166CountryName);
-
- internal int GeoId
- {
- get
- {
- if (_iGeoId == undef)
- {
- _iGeoId = GetGeoId(_sRealName!);
- }
- return _iGeoId;
- }
- }
-
- /// <summary>
- /// localized name for the country
- /// </summary>
- internal string LocalizedCountryName
- {
- get
- {
- string? localizedCountry = _sLocalizedCountry;
- if (localizedCountry == null)
- {
- try
- {
- localizedCountry = GetRegionDisplayName();
- }
- catch
- {
- // do nothing. we'll fallback
- }
-
- localizedCountry ??= NativeCountryName;
- _sLocalizedCountry = localizedCountry;
- }
-
- return localizedCountry;
- }
- }
-
- /// <summary>
- /// english country name (RegionInfo) ie: Germany
- /// </summary>
- internal string EnglishCountryName => _sEnglishCountry ??= GetLocaleInfo(LocaleStringData.EnglishCountryName);
-
- /// <summary>
- /// native country name (RegionInfo) ie: Deutschland
- /// </summary>
- internal string NativeCountryName => _sNativeCountry ??= GetLocaleInfo(LocaleStringData.NativeCountryName);
-
- /// <summary>
- /// ISO 3166 Country Name
- /// </summary>
- internal string TwoLetterISOCountryName => _sISO3166CountryName ??= GetLocaleInfo(LocaleStringData.Iso3166CountryName);
-
- /// <summary>
- /// 3 letter ISO 3166 country code
- /// </summary>
- internal string ThreeLetterISOCountryName => _sISO3166CountryName2 ??= GetLocaleInfo(LocaleStringData.Iso3166CountryName2);
-
- internal int KeyboardLayoutId
- {
- get
- {
- if (_iInputLanguageHandle == undef)
- {
- if (IsSupplementalCustomCulture)
- {
- _iInputLanguageHandle = 0x0409;
- }
- else
- {
- // Input Language is same as LCID for built-in cultures
- _iInputLanguageHandle = LCID;
- }
- }
- return _iInputLanguageHandle;
- }
- }
-
- /// <summary>
- /// Console fallback name (ie: locale to use for console apps for unicode-only locales)
- /// </summary>
- internal string SCONSOLEFALLBACKNAME => _sConsoleFallbackName ??= GetConsoleFallbackName(_sRealName!);
-
- /// <summary>
- /// (user can override) grouping of digits
- /// </summary>
- internal int[] NumberGroupSizes => _waGrouping ??= GetLocaleInfo(LocaleGroupingData.Digit);
-
- /// <summary>
- /// Not a Number
- /// </summary>
- private string NaNSymbol => _sNaN ??= GetLocaleInfo(LocaleStringData.NaNSymbol);
-
- /// <summary>
- /// + Infinity
- /// </summary>
- private string PositiveInfinitySymbol => _sPositiveInfinity ??= GetLocaleInfo(LocaleStringData.PositiveInfinitySymbol);
-
- /// <summary>
- /// - Infinity
- /// </summary>
- private string NegativeInfinitySymbol => _sNegativeInfinity ??= GetLocaleInfo(LocaleStringData.NegativeInfinitySymbol);
-
- /// <summary>
- /// Negative Percent (0-3)
- /// </summary>
- private int PercentNegativePattern
- {
- get
- {
- if (_iNegativePercent == undef)
- {
- // Note that <= Windows Vista this is synthesized by native code
- _iNegativePercent = GetLocaleInfo(LocaleNumberData.NegativePercentFormat);
- }
- return _iNegativePercent;
- }
- }
-
- /// <summary>
- /// Positive Percent (0-11)
- /// </summary>
- private int PercentPositivePattern
- {
- get
- {
- if (_iPositivePercent == undef)
- {
- // Note that <= Windows Vista this is synthesized by native code
- _iPositivePercent = GetLocaleInfo(LocaleNumberData.PositivePercentFormat);
- }
- return _iPositivePercent;
- }
- }
-
- /// <summary>
- /// Percent (%) symbol
- /// </summary>
- private string PercentSymbol => _sPercent ??= GetLocaleInfo(LocaleStringData.PercentSymbol);
-
- /// <summary>
- /// PerMille symbol
- /// </summary>
- private string PerMilleSymbol => _sPerMille ??= GetLocaleInfo(LocaleStringData.PerMilleSymbol);
-
- /// <summary>
- /// (user can override) local monetary symbol, eg: $
- /// </summary>
- internal string CurrencySymbol => _sCurrency ??= GetLocaleInfo(LocaleStringData.MonetarySymbol);
-
- /// <summary>
- /// international monetary symbol (RegionInfo), eg: USD
- /// </summary>
- internal string ISOCurrencySymbol => _sIntlMonetarySymbol ??= GetLocaleInfo(LocaleStringData.Iso4217MonetarySymbol);
-
- /// <summary>
- /// English name for this currency (RegionInfo), eg: US Dollar
- /// </summary>
- internal string CurrencyEnglishName => _sEnglishCurrency ??= GetLocaleInfo(LocaleStringData.CurrencyEnglishName);
-
- /// <summary>
- /// Native name for this currency (RegionInfo), eg: Schweiz Frank
- /// </summary>
- internal string CurrencyNativeName => _sNativeCurrency ??= GetLocaleInfo(LocaleStringData.CurrencyNativeName);
-
- /// <summary>
- /// (user can override) monetary grouping of digits
- /// </summary>
- internal int[] CurrencyGroupSizes => _waMonetaryGrouping ??= GetLocaleInfo(LocaleGroupingData.Monetary);
-
- /// <summary>
- /// (user can override) system of measurement 0=metric, 1=US (RegionInfo)
- /// </summary>
- internal int MeasurementSystem
- {
- get
- {
- if (_iMeasure == undef)
- {
- _iMeasure = GetLocaleInfo(LocaleNumberData.MeasurementSystem);
- }
- return _iMeasure;
- }
- }
-
- /// <summary>
- /// (user can override) list Separator
- /// </summary>
- internal string ListSeparator => _sListSeparator ??= GetLocaleInfo(LocaleStringData.ListSeparator);
-
- /// <summary>
- /// (user can override) AM designator
- /// </summary>
- internal string AMDesignator => _sAM1159 ??= GetLocaleInfo(LocaleStringData.AMDesignator);
-
- /// <summary>
- /// (user can override) PM designator
- /// </summary>
- internal string PMDesignator => _sPM2359 ??= GetLocaleInfo(LocaleStringData.PMDesignator);
-
- /// <summary>
- /// (user can override) time format
- /// </summary>
- internal string[] LongTimes
- {
- get
- {
- if (_saLongTimes == null)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- string[]? longTimes = GetTimeFormats();
- if (longTimes == null || longTimes.Length == 0)
- {
- _saLongTimes = Invariant._saLongTimes!;
- }
- else
- {
- _saLongTimes = longTimes;
- }
- }
- return _saLongTimes;
- }
- }
-
- /// <summary>
- /// short time format
- /// Short times (derived from long times format)
- /// </summary>
- internal string[] ShortTimes
- {
- get
- {
- if (_saShortTimes == null)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- // Try to get the short times from the OS/culture.dll
- string[]? shortTimes = GetShortTimeFormats();
-
- if (shortTimes == null || shortTimes.Length == 0)
- {
- //
- // If we couldn't find short times, then compute them from long times
- // (eg: CORECLR on < Win7 OS & fallback for missing culture.dll)
- //
- shortTimes = DeriveShortTimesFromLong();
- }
-
- // Found short times, use them
- _saShortTimes = shortTimes;
- }
- return _saShortTimes;
- }
- }
-
- private string[] DeriveShortTimesFromLong()
- {
- // Our logic is to look for h,H,m,s,t. If we find an s, then we check the string
- // between it and the previous marker, if any. If its a short, unescaped separator,
- // then we don't retain that part.
- // We then check after the ss and remove anything before the next h,H,m,t...
- string[] longTimes = LongTimes;
- string[] shortTimes = new string[longTimes.Length];
-
- for (int i = 0; i < longTimes.Length; i++)
- {
- shortTimes[i] = StripSecondsFromPattern(longTimes[i]);
- }
- return shortTimes;
- }
-
- private static string StripSecondsFromPattern(string time)
- {
- bool bEscape = false;
- int iLastToken = -1;
-
- // Find the seconds
- for (int j = 0; j < time.Length; j++)
- {
- // Change escape mode?
- if (time[j] == '\'')
- {
- // Continue
- bEscape = !bEscape;
- continue;
- }
-
- // See if there was a single \
- if (time[j] == '\\')
- {
- // Skip next char
- j++;
- continue;
- }
-
- if (bEscape)
- {
- continue;
- }
-
- switch (time[j])
- {
- // Check for seconds
- case 's':
- // Found seconds, see if there was something unescaped and short between
- // the last marker and the seconds. Windows says separator can be a
- // maximum of three characters (without null)
- // If 1st or last characters were ', then ignore it
- if ((j - iLastToken) <= 4 && (j - iLastToken) > 1 &&
- (time[iLastToken + 1] != '\'') &&
- (time[j - 1] != '\''))
- {
- // There was something there we want to remember
- if (iLastToken >= 0)
- {
- j = iLastToken + 1;
- }
- }
-
- bool containsSpace;
- int endIndex = GetIndexOfNextTokenAfterSeconds(time, j, out containsSpace);
-
- string sep;
-
- if (containsSpace)
- {
- sep = " ";
- }
- else
- {
- sep = "";
- }
-
- time = string.Concat(time.AsSpan(0, j), sep, time.AsSpan(endIndex));
- break;
- case 'm':
- case 'H':
- case 'h':
- iLastToken = j;
- break;
- }
- }
- return time;
- }
-
- private static int GetIndexOfNextTokenAfterSeconds(string time, int index, out bool containsSpace)
- {
- bool shouldEscape = false;
- containsSpace = false;
- for (; index < time.Length; index++)
- {
- switch (time[index])
- {
- case '\'':
- shouldEscape = !shouldEscape;
- continue;
- case '\\':
- index++;
- if (time[index] == ' ')
- {
- containsSpace = true;
- }
- continue;
- case ' ':
- containsSpace = true;
- break;
- case 't':
- case 'm':
- case 'H':
- case 'h':
- if (shouldEscape)
- {
- continue;
- }
- return index;
- }
- }
- containsSpace = false;
- return index;
- }
-
- // (user can override) first day of week
- internal int FirstDayOfWeek
- {
- get
- {
- if (_iFirstDayOfWeek == undef)
- {
- _iFirstDayOfWeek = GetFirstDayOfWeek();
- }
- return _iFirstDayOfWeek;
- }
- }
-
- // (user can override) first week of year
- internal int CalendarWeekRule
- {
- get
- {
- if (_iFirstWeekOfYear == undef)
- {
- _iFirstWeekOfYear = GetLocaleInfo(LocaleNumberData.FirstWeekOfYear);
- }
- return _iFirstWeekOfYear;
- }
- }
-
- /// <summary>
- /// (user can override default only) short date format
- /// </summary>
- internal string[] ShortDates(CalendarId calendarId)
- {
- return GetCalendar(calendarId).saShortDates;
- }
-
- /// <summary>
- /// (user can override default only) long date format
- /// </summary>
- internal string[] LongDates(CalendarId calendarId)
- {
- return GetCalendar(calendarId).saLongDates;
- }
-
- /// <summary>
- /// (user can override) date year/month format.
- /// </summary>
- internal string[] YearMonths(CalendarId calendarId)
- {
- return GetCalendar(calendarId).saYearMonths;
- }
-
- internal string[] DayNames(CalendarId calendarId)
- {
- return GetCalendar(calendarId).saDayNames;
- }
-
- internal string[] AbbreviatedDayNames(CalendarId calendarId)
- {
- return GetCalendar(calendarId).saAbbrevDayNames;
- }
-
- internal string[] SuperShortDayNames(CalendarId calendarId)
- {
- return GetCalendar(calendarId).saSuperShortDayNames;
- }
-
- internal string[] MonthNames(CalendarId calendarId)
- {
- return GetCalendar(calendarId).saMonthNames;
- }
-
- internal string[] GenitiveMonthNames(CalendarId calendarId)
- {
- return GetCalendar(calendarId).saMonthGenitiveNames;
- }
-
- internal string[] AbbreviatedMonthNames(CalendarId calendarId)
- {
- return GetCalendar(calendarId).saAbbrevMonthNames;
- }
-
- internal string[] AbbreviatedGenitiveMonthNames(CalendarId calendarId)
- {
- return GetCalendar(calendarId).saAbbrevMonthGenitiveNames;
- }
-
- /// <remarks>>
- /// Note: This only applies to Hebrew, and it basically adds a "1" to the 6th month name
- /// the non-leap names skip the 7th name in the normal month name array
- /// </remarks>
- internal string[] LeapYearMonthNames(CalendarId calendarId)
- {
- return GetCalendar(calendarId).saLeapYearMonthNames;
- }
-
- internal string MonthDay(CalendarId calendarId)
- {
- return GetCalendar(calendarId).sMonthDay;
- }
-
- /// <summary>
- /// All available calendar type(s). The first one is the default calendar.
- /// </summary>
- internal CalendarId[] CalendarIds
- {
- get
- {
- if (_waCalendars == null)
- {
- // We pass in an array of ints, and native side fills it up with count calendars.
- // We then have to copy that list to a new array of the right size.
- // Default calendar should be first
- CalendarId[] calendars = new CalendarId[23];
- Debug.Assert(_sWindowsName != null, "[CultureData.CalendarIds] Expected _sWindowsName to be populated by already");
- int count = CalendarData.GetCalendars(_sWindowsName, _bUseOverrides, calendars);
-
- // See if we had a calendar to add.
- if (count == 0)
- {
- // Failed for some reason, just grab Gregorian from Invariant
- _waCalendars = Invariant._waCalendars!;
- }
- else
- {
- // The OS may not return calendar 4 for zh-TW, but we've always allowed it.
- // TODO: Is this hack necessary long-term?
- if (_sWindowsName == "zh-TW")
- {
- bool found = false;
-
- // Do we need to insert calendar 4?
- for (int i = 0; i < count; i++)
- {
- // Stop if we found calendar four
- if (calendars[i] == CalendarId.TAIWAN)
- {
- found = true;
- break;
- }
- }
-
- // If not found then insert it
- if (!found)
- {
- // Insert it as the 2nd calendar
- count++;
- // Copy them from the 2nd position to the end, -1 for skipping 1st, -1 for one being added.
- Array.Copy(calendars, 1, calendars, 2, 23 - 1 - 1);
- calendars[1] = CalendarId.TAIWAN;
- }
- }
-
- // It worked, remember the list
- CalendarId[] temp = new CalendarId[count];
- Array.Copy(calendars, temp, count);
-
- // Want 1st calendar to be default
- // Prior to Vista the enumeration didn't have default calendar first
- if (temp.Length > 1)
- {
- CalendarId i = (CalendarId)GetLocaleInfo(LocaleNumberData.CalendarType);
- if (temp[1] == i)
- {
- temp[1] = temp[0];
- temp[0] = i;
- }
- }
-
- _waCalendars = temp;
- }
- }
-
- return _waCalendars;
- }
- }
-
- /// <summary>
- /// Native calendar names. Index of optional calendar - 1, empty if
- /// no optional calendar at that number
- /// </summary>
- internal string CalendarName(CalendarId calendarId)
- {
- return GetCalendar(calendarId).sNativeName;
- }
-
- internal CalendarData GetCalendar(CalendarId calendarId)
- {
- Debug.Assert(calendarId > 0 && calendarId <= CalendarId.LAST_CALENDAR,
- "[CultureData.GetCalendar] Expect calendarId to be in a valid range");
-
- // arrays are 0 based, calendarIds are 1 based
- int calendarIndex = (int)calendarId - 1;
-
- // Have to have calendars
- _calendars ??= new CalendarData[CalendarData.MAX_CALENDARS];
-
- // we need the following local variable to avoid returning null
- // when another thread creates a new array of CalendarData (above)
- // right after we insert the newly created CalendarData (below)
- CalendarData? calendarData = _calendars[calendarIndex];
- // Make sure that calendar has data
- if (calendarData == null)
- {
- Debug.Assert(_sWindowsName != null, "[CultureData.GetCalendar] Expected _sWindowsName to be populated by already");
- calendarData = new CalendarData(_sWindowsName, calendarId, UseUserOverride);
- _calendars[calendarIndex] = calendarData;
- }
-
- return calendarData;
- }
-
- internal bool IsRightToLeft =>
- // Returns one of the following 4 reading layout values:
- // 0 - Left to right (eg en-US)
- // 1 - Right to left (eg arabic locales)
- // 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
- // 3 - Vertical top to bottom with columns proceeding to the right
- ReadingLayout == 1;
-
- /// <summary>
- /// Returns one of the following 4 reading layout values:
- /// 0 - Left to right (eg en-US)
- /// 1 - Right to left (eg arabic locales)
- /// 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
- /// 3 - Vertical top to bottom with columns proceeding to the right
- /// </summary>
- private int ReadingLayout
- {
- get
- {
- if (_iReadingLayout == undef)
- {
- Debug.Assert(_sRealName != null, "[CultureData.IsRightToLeft] Expected _sRealName to be populated by already");
- _iReadingLayout = GetLocaleInfo(LocaleNumberData.ReadingLayout);
- }
-
- return _iReadingLayout;
- }
- }
-
- /// <summary>
- /// // Text info name to use for text information
- /// The TextInfo name never includes that alternate sort and is always specific
- /// For customs, it uses the SortLocale (since the textinfo is not exposed in Win7)
- /// en -> en-US
- /// en-US -> en-US
- /// fj (custom neutral) -> en-US (assuming that en-US is the sort locale for fj)
- /// fj_FJ (custom specific) -> en-US (assuming that en-US is the sort locale for fj-FJ)
- /// es-ES_tradnl -> es-ES
- /// </summary>
- internal string TextInfoName
- {
- get
- {
- // Note: Custom cultures might point at another culture's textinfo, however windows knows how
- // to redirect it to the desired textinfo culture, so this is OK.
- Debug.Assert(_sRealName != null, "[CultureData.TextInfoName] Expected _sRealName to be populated by already");
- return _sRealName;
- }
- }
-
- /// <summary>
- /// Compare info name (including sorting key) to use if custom
- /// </summary>
- internal string SortName
- {
- get
- {
- Debug.Assert(_sRealName != null, "[CultureData.SortName] Expected _sRealName to be populated by already");
- return _sRealName;
- }
- }
-
- internal bool IsSupplementalCustomCulture => IsCustomCultureId(LCID);
-
- /// <summary>
- /// Default ansi code page ID (ACP)
- /// </summary>
- internal int ANSICodePage
- {
- get
- {
- if (_iDefaultAnsiCodePage == undef)
- {
- _iDefaultAnsiCodePage = GetAnsiCodePage(_sRealName!);
- }
- return _iDefaultAnsiCodePage;
- }
- }
-
- /// <summary>
- /// Default oem code page ID (OCP or OEM).
- /// </summary>
- internal int OEMCodePage
- {
- get
- {
- if (_iDefaultOemCodePage == undef)
- {
- _iDefaultOemCodePage = GetOemCodePage(_sRealName!);
- }
- return _iDefaultOemCodePage;
- }
- }
-
- /// <summary>
- /// Default macintosh code page.
- /// </summary>
- internal int MacCodePage
- {
- get
- {
- if (_iDefaultMacCodePage == undef)
- {
- _iDefaultMacCodePage = GetMacCodePage(_sRealName!);
- }
- return _iDefaultMacCodePage;
- }
- }
-
- /// <summary>
- /// Default EBCDIC code page.
- /// </summary>
- internal int EBCDICCodePage
- {
- get
- {
- if (_iDefaultEbcdicCodePage == undef)
- {
- _iDefaultEbcdicCodePage = GetEbcdicCodePage(_sRealName!);
- }
- return _iDefaultEbcdicCodePage;
- }
- }
-
- internal int LCID
- {
- get
- {
- if (_iLanguage == 0)
- {
- Debug.Assert(_sRealName != null, "[CultureData.LCID] Expected this.sRealName to be populated already");
- _iLanguage = LocaleNameToLCID(_sRealName);
- }
- return _iLanguage;
- }
- }
-
- internal bool IsNeutralCulture =>
- // InitCultureData told us if we're neutral or not
- _bNeutral;
-
- internal bool IsInvariantCulture => string.IsNullOrEmpty(Name);
-
- /// <summary>
- /// Get an instance of our default calendar
- /// </summary>
- internal Calendar DefaultCalendar
- {
- get
- {
- if (GlobalizationMode.Invariant)
- {
- return CultureInfo.GetCalendarInstance(CalendarIds[0]);
- }
-
- CalendarId defaultCalId = (CalendarId)GetLocaleInfo(LocaleNumberData.CalendarType);
-
- if (defaultCalId == 0)
- {
- defaultCalId = CalendarIds[0];
- }
-
- return CultureInfo.GetCalendarInstance(defaultCalId);
- }
- }
-
- /// <summary>
- /// All of our era names
- /// </summary>
- internal string[] EraNames(CalendarId calendarId)
- {
- Debug.Assert(calendarId > 0, "[CultureData.saEraNames] Expected Calendar.ID > 0");
- return GetCalendar(calendarId).saEraNames;
- }
-
- internal string[] AbbrevEraNames(CalendarId calendarId)
- {
- Debug.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
- return GetCalendar(calendarId).saAbbrevEraNames;
- }
-
- internal string[] AbbreviatedEnglishEraNames(CalendarId calendarId)
- {
- Debug.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
- return GetCalendar(calendarId).saAbbrevEnglishEraNames;
- }
-
- /// <summary>
- /// Time separator (derived from time format)
- /// </summary>
- internal string TimeSeparator
- {
- get
- {
- if (_sTimeSeparator == null)
- {
- string? longTimeFormat = GetTimeFormatString();
- if (string.IsNullOrEmpty(longTimeFormat))
- {
- longTimeFormat = LongTimes[0];
- }
-
- // Compute STIME from time format
- _sTimeSeparator = GetTimeSeparator(longTimeFormat);
- }
- return _sTimeSeparator;
- }
- }
-
- /// <summary>
- /// Date separator (derived from short date format)
- /// </summary>
- internal string DateSeparator(CalendarId calendarId)
- {
- if (calendarId == CalendarId.JAPAN && !LocalAppContextSwitches.EnforceLegacyJapaneseDateParsing)
- {
- // The date separator is derived from the default short date pattern. So far this pattern is using
- // '/' as date separator when using the Japanese calendar which make the formatting and parsing work fine.
- // changing the default pattern is likely will happen in the near future which can easily break formatting
- // and parsing.
- // We are forcing here the date separator to '/' to ensure the parsing is not going to break when changing
- // the default short date pattern. The application still can override this in the code by DateTimeFormatInfo.DateSeparartor.
- return "/";
- }
-
- return GetDateSeparator(ShortDates(calendarId)[0]);
- }
-
- /// <summary>
- /// Unescape a NLS style quote string
- ///
- /// This removes single quotes:
- /// 'fred' -> fred
- /// 'fred -> fred
- /// fred' -> fred
- /// fred's -> freds
- ///
- /// This removes the first \ of escaped characters:
- /// fred\'s -> fred's
- /// a\\b -> a\b
- /// a\b -> ab
- ///
- /// We don't build the stringbuilder unless we find a ' or a \. If we find a ' or a \, we
- /// always build a stringbuilder because we need to remove the ' or \.
- /// </summary>
- private static string UnescapeNlsString(string str, int start, int end)
- {
- Debug.Assert(str != null);
- Debug.Assert(start >= 0);
- Debug.Assert(end >= 0);
- StringBuilder? result = null;
-
- for (int i = start; i < str.Length && i <= end; i++)
- {
- switch (str[i])
- {
- case '\'':
- result ??= new StringBuilder(str, start, i - start, str.Length);
- break;
- case '\\':
- result ??= new StringBuilder(str, start, i - start, str.Length);
- ++i;
- if (i < str.Length)
- {
- result.Append(str[i]);
- }
- break;
- default:
- result?.Append(str[i]);
- break;
- }
- }
-
- if (result == null)
- {
- return str.Substring(start, end - start + 1);
- }
-
- return result.ToString();
- }
-
- /// <summary>
- /// Time format separator (ie: : in 12:39:00)
- /// We calculate this from the provided time format
- /// </summary>
- private static string GetTimeSeparator(string format)
- {
- // Find the time separator so that we can pretend we know TimeSeparator.
- return GetSeparator(format, "Hhms");
- }
-
- /// <summary>
- /// Date format separator (ie: / in 9/1/03)
- /// We calculate this from the provided short date
- /// </summary>
- private static string GetDateSeparator(string format)
- {
- // Find the date separator so that we can pretend we know DateSeparator.
- return GetSeparator(format, "dyM");
- }
-
- private static string GetSeparator(string format, string timeParts)
- {
- int index = IndexOfTimePart(format, 0, timeParts);
-
- if (index != -1)
- {
- // Found a time part, find out when it changes
- char cTimePart = format[index];
-
- do
- {
- index++;
- } while (index < format.Length && format[index] == cTimePart);
-
- int separatorStart = index;
-
- // Now we need to find the end of the separator
- if (separatorStart < format.Length)
- {
- int separatorEnd = IndexOfTimePart(format, separatorStart, timeParts);
- if (separatorEnd != -1)
- {
- // From [separatorStart, count) is our string, except we need to unescape
- return UnescapeNlsString(format, separatorStart, separatorEnd - 1);
- }
- }
- }
-
- return string.Empty;
- }
-
- private static int IndexOfTimePart(string format, int startIndex, string timeParts)
- {
- Debug.Assert(startIndex >= 0, "startIndex cannot be negative");
- Debug.Assert(timeParts.IndexOfAny(new char[] { '\'', '\\' }) == -1, "timeParts cannot include quote characters");
- bool inQuote = false;
- for (int i = startIndex; i < format.Length; ++i)
- {
- // See if we have a time Part
- if (!inQuote && timeParts.Contains(format[i]))
- {
- return i;
- }
- switch (format[i])
- {
- case '\\':
- if (i + 1 < format.Length)
- {
- ++i;
- switch (format[i])
- {
- case '\'':
- case '\\':
- break;
- default:
- --i; // backup since we will move over this next
- break;
- }
- }
- break;
- case '\'':
- inQuote = !inQuote;
- break;
- }
- }
-
- return -1;
- }
-
- internal static bool IsCustomCultureId(int cultureId)
- {
- return cultureId == CultureInfo.LOCALE_CUSTOM_DEFAULT || cultureId == CultureInfo.LOCALE_CUSTOM_UNSPECIFIED;
- }
-
- internal void GetNFIValues(NumberFormatInfo nfi)
- {
- if (GlobalizationMode.Invariant || IsInvariantCulture)
- {
- nfi._positiveSign = _sPositiveSign!;
- nfi._negativeSign = _sNegativeSign!;
-
- nfi._numberGroupSeparator = _sThousandSeparator!;
- nfi._numberDecimalSeparator = _sDecimalSeparator!;
- nfi._numberDecimalDigits = _iDigits;
- nfi._numberNegativePattern = _iNegativeNumber;
-
- nfi._currencySymbol = _sCurrency!;
- nfi._currencyGroupSeparator = _sMonetaryThousand!;
- nfi._currencyDecimalSeparator = _sMonetaryDecimal!;
- nfi._currencyDecimalDigits = _iCurrencyDigits;
- nfi._currencyNegativePattern = _iNegativeCurrency;
- nfi._currencyPositivePattern = _iCurrency;
- }
- else
- {
- Debug.Assert(_sWindowsName != null, "[CultureData.GetNFIValues] Expected _sWindowsName to be populated by already");
- // String values
- nfi._positiveSign = GetLocaleInfo(LocaleStringData.PositiveSign);
- nfi._negativeSign = GetLocaleInfo(LocaleStringData.NegativeSign);
-
- nfi._numberDecimalSeparator = GetLocaleInfo(LocaleStringData.DecimalSeparator);
- nfi._numberGroupSeparator = GetLocaleInfo(LocaleStringData.ThousandSeparator);
- nfi._currencyGroupSeparator = GetLocaleInfo(LocaleStringData.MonetaryThousandSeparator);
- nfi._currencyDecimalSeparator = GetLocaleInfo(LocaleStringData.MonetaryDecimalSeparator);
- nfi._currencySymbol = GetLocaleInfo(LocaleStringData.MonetarySymbol);
-
- // Numeric values
- nfi._numberDecimalDigits = GetLocaleInfo(LocaleNumberData.FractionalDigitsCount);
- nfi._currencyDecimalDigits = GetLocaleInfo(LocaleNumberData.MonetaryFractionalDigitsCount);
- nfi._currencyPositivePattern = GetLocaleInfo(LocaleNumberData.PositiveMonetaryNumberFormat);
- nfi._currencyNegativePattern = GetLocaleInfo(LocaleNumberData.NegativeMonetaryNumberFormat);
- nfi._numberNegativePattern = GetLocaleInfo(LocaleNumberData.NegativeNumberFormat);
-
- // LOCALE_SNATIVEDIGITS (array of 10 single character strings).
- string digits = GetLocaleInfo(LocaleStringData.Digits);
- nfi._nativeDigits = new string[10];
- for (int i = 0; i < nfi._nativeDigits.Length; i++)
- {
- nfi._nativeDigits[i] = char.ToString(digits[i]);
- }
-
- Debug.Assert(_sRealName != null);
- nfi._digitSubstitution = GetDigitSubstitution(_sRealName);
- }
-
- // Gather additional data
- nfi._numberGroupSizes = NumberGroupSizes;
- nfi._currencyGroupSizes = CurrencyGroupSizes;
-
- // prefer the cached value since these do not have user overrides
- nfi._percentNegativePattern = PercentNegativePattern;
- nfi._percentPositivePattern = PercentPositivePattern;
- nfi._percentSymbol = PercentSymbol;
- nfi._perMilleSymbol = PerMilleSymbol;
-
- nfi._negativeInfinitySymbol = NegativeInfinitySymbol;
- nfi._positiveInfinitySymbol = PositiveInfinitySymbol;
- nfi._nanSymbol = NaNSymbol;
-
- // We don't have percent values, so use the number values
- nfi._percentDecimalDigits = nfi._numberDecimalDigits;
- nfi._percentDecimalSeparator = nfi._numberDecimalSeparator;
- nfi._percentGroupSizes = nfi._numberGroupSizes;
- nfi._percentGroupSeparator = nfi._numberGroupSeparator;
-
- // Clean up a few odd values
-
- // Windows usually returns an empty positive sign, but we like it to be "+"
- if (string.IsNullOrEmpty(nfi._positiveSign))
- {
- nfi._positiveSign = "+";
- }
-
- // Special case for Italian. The currency decimal separator in the control panel is the empty string. When the user
- // specifies C4 as the currency format, this results in the number apparently getting multiplied by 10000 because the
- // decimal point doesn't show up. We'll just hack this here because our default currency format will never use nfi.
- if (string.IsNullOrEmpty(nfi._currencyDecimalSeparator))
- {
- nfi._currencyDecimalSeparator = nfi._numberDecimalSeparator;
- }
- }
-
- /// <remarks>
- /// This is ONLY used for caching names and shouldn't be used for anything else
- /// </remarks>
- internal static string AnsiToLower(string testString) => TextInfo.ToLowerAsciiInvariant(testString);
-
- /// <remarks>
- /// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation
- /// takes a dependency on this fact, in order to prevent having to construct a mapping from internal values to LCTypes.
- /// </remarks>
- private enum LocaleStringData : uint
- {
- /// <summary>localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME)</summary>
- LocalizedDisplayName = 0x00000002,
- /// <summary>Display name (language + country usually) in English, eg "German (Germany)" (corresponds to LOCALE_SENGLISHDISPLAYNAME)</summary>
- EnglishDisplayName = 0x00000072,
- /// <summary>Display name in native locale language, eg "Deutsch (Deutschland) (corresponds to LOCALE_SNATIVEDISPLAYNAME)</summary>
- NativeDisplayName = 0x00000073,
- /// <summary>Language Display Name for a language, eg "German" in UI language (corresponds to LOCALE_SLOCALIZEDLANGUAGENAME)</summary>
- LocalizedLanguageName = 0x0000006f,
- /// <summary>English name of language, eg "German" (corresponds to LOCALE_SENGLISHLANGUAGENAME)</summary>
- EnglishLanguageName = 0x00001001,
- /// <summary>native name of language, eg "Deutsch" (corresponds to LOCALE_SNATIVELANGUAGENAME)</summary>
- NativeLanguageName = 0x00000004,
- /// <summary>localized name of country, eg "Germany" in UI language (corresponds to LOCALE_SLOCALIZEDCOUNTRYNAME)</summary>
- LocalizedCountryName = 0x00000006,
- /// <summary>English name of country, eg "Germany" (corresponds to LOCALE_SENGLISHCOUNTRYNAME)</summary>
- EnglishCountryName = 0x00001002,
- /// <summary>native name of country, eg "Deutschland" (corresponds to LOCALE_SNATIVECOUNTRYNAME)</summary>
- NativeCountryName = 0x00000008,
- /// <summary>abbreviated language name (corresponds to LOCALE_SABBREVLANGNAME)</summary>
- AbbreviatedWindowsLanguageName = 0x00000003,
- /// <summary>list item separator (corresponds to LOCALE_SLIST)</summary>
- ListSeparator = 0x0000000C,
- /// <summary>decimal separator (corresponds to LOCALE_SDECIMAL)</summary>
- DecimalSeparator = 0x0000000E,
- /// <summary>thousand separator (corresponds to LOCALE_STHOUSAND)</summary>
- ThousandSeparator = 0x0000000F,
- /// <summary>digit grouping (corresponds to LOCALE_SGROUPING)</summary>
- Digits = 0x00000013,
- /// <summary>local monetary symbol (corresponds to LOCALE_SCURRENCY)</summary>
- MonetarySymbol = 0x00000014,
- /// <summary>English currency name (corresponds to LOCALE_SENGCURRNAME)</summary>
- CurrencyEnglishName = 0x00001007,
- /// <summary>Native currency name (corresponds to LOCALE_SNATIVECURRNAME)</summary>
- CurrencyNativeName = 0x00001008,
- /// <summary>uintl monetary symbol (corresponds to LOCALE_SINTLSYMBOL)</summary>
- Iso4217MonetarySymbol = 0x00000015,
- /// <summary>monetary decimal separator (corresponds to LOCALE_SMONDECIMALSEP)</summary>
- MonetaryDecimalSeparator = 0x00000016,
- /// <summary>monetary thousand separator (corresponds to LOCALE_SMONTHOUSANDSEP)</summary>
- MonetaryThousandSeparator = 0x00000017,
- /// <summary>AM designator (corresponds to LOCALE_S1159)</summary>
- AMDesignator = 0x00000028,
- /// <summary>PM designator (corresponds to LOCALE_S2359)</summary>
- PMDesignator = 0x00000029,
- /// <summary>positive sign (corresponds to LOCALE_SPOSITIVESIGN)</summary>
- PositiveSign = 0x00000050,
- /// <summary>negative sign (corresponds to LOCALE_SNEGATIVESIGN)</summary>
- NegativeSign = 0x00000051,
- /// <summary>ISO abbreviated language name (corresponds to LOCALE_SISO639LANGNAME)</summary>
- Iso639LanguageTwoLetterName = 0x00000059,
- /// <summary>ISO abbreviated country name (corresponds to LOCALE_SISO639LANGNAME2)</summary>
- Iso639LanguageThreeLetterName = 0x00000067,
- /// <summary>ISO abbreviated language name (corresponds to LOCALE_SISO639LANGNAME)</summary>
- Iso639LanguageName = 0x00000059,
- /// <summary>ISO abbreviated country name (corresponds to LOCALE_SISO3166CTRYNAME)</summary>
- Iso3166CountryName = 0x0000005A,
- /// <summary>3 letter ISO country code (corresponds to LOCALE_SISO3166CTRYNAME2)</summary>
- Iso3166CountryName2 = 0x00000068, // 3 character ISO country name
- /// <summary>Not a Number (corresponds to LOCALE_SNAN)</summary>
- NaNSymbol = 0x00000069,
- /// <summary>+ Infinity (corresponds to LOCALE_SPOSINFINITY)</summary>
- PositiveInfinitySymbol = 0x0000006a,
- /// <summary>- Infinity (corresponds to LOCALE_SNEGINFINITY)</summary>
- NegativeInfinitySymbol = 0x0000006b,
- /// <summary>Fallback name for resources (corresponds to LOCALE_SPARENT)</summary>
- ParentName = 0x0000006d,
- /// <summary>Fallback name for within the console (corresponds to LOCALE_SCONSOLEFALLBACKNAME)</summary>
- ConsoleFallbackName = 0x0000006e,
- /// <summary>Returns the percent symbol (corresponds to LOCALE_SPERCENT)</summary>
- PercentSymbol = 0x00000076,
- /// <summary>Returns the permille (U+2030) symbol (corresponds to LOCALE_SPERMILLE)</summary>
- PerMilleSymbol = 0x00000077
- }
-
- /// <remarks>
- /// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation
- /// takes a dependency on this fact, in order to prevent having to construct a mapping from internal values to LCTypes.
- /// </remarks>
- private enum LocaleGroupingData : uint
- {
- /// <summary>digit grouping (corresponds to LOCALE_SGROUPING)</summary>
- Digit = 0x00000010,
- /// <summary>monetary grouping (corresponds to LOCALE_SMONGROUPING)</summary>
- Monetary = 0x00000018,
- }
-
- /// <remarks>
- /// The numeric values of the enum members match their Win32 counterparts. The CultureData Win32 PAL implementation
- /// takes a dependency on this fact, in order to prevent having to construct a mapping from internal values to LCTypes.
- /// </remarks>
- private enum LocaleNumberData : uint
- {
- /// <summary>language id (corresponds to LOCALE_ILANGUAGE)</summary>
- LanguageId = 0x00000001,
- /// <summary>geographical location id, (corresponds to LOCALE_IGEOID)</summary>
- GeoId = 0x0000005B,
- /// <summary>0 = context, 1 = none, 2 = national (corresponds to LOCALE_IDIGITSUBSTITUTION)</summary>
- DigitSubstitution = 0x00001014,
- /// <summary>0 = metric, 1 = US (corresponds to LOCALE_IMEASURE)</summary>
- MeasurementSystem = 0x0000000D,
- /// <summary>number of fractional digits (corresponds to LOCALE_IDIGITS)</summary>
- FractionalDigitsCount = 0x00000011,
- /// <summary>negative number mode (corresponds to LOCALE_INEGNUMBER)</summary>
- NegativeNumberFormat = 0x00001010,
- /// <summary># local monetary digits (corresponds to LOCALE_ICURRDIGITS)</summary>
- MonetaryFractionalDigitsCount = 0x00000019,
- /// <summary>positive currency mode (corresponds to LOCALE_ICURRENCY)</summary>
- PositiveMonetaryNumberFormat = 0x0000001B,
- /// <summary>negative currency mode (corresponds to LOCALE_INEGCURR)</summary>
- NegativeMonetaryNumberFormat = 0x0000001C,
- /// <summary>type of calendar specifier (corresponds to LOCALE_ICALENDARTYPE)</summary>
- CalendarType = 0x00001009,
- /// <summary>first day of week specifier (corresponds to LOCALE_IFIRSTDAYOFWEEK)</summary>
- FirstDayOfWeek = 0x0000100C,
- /// <summary>first week of year specifier (corresponds to LOCALE_IFIRSTWEEKOFYEAR)</summary>
- FirstWeekOfYear = 0x0000100D,
- /// <summary>
- /// Returns one of the following 4 reading layout values:
- /// 0 - Left to right (eg en-US)
- /// 1 - Right to left (eg arabic locales)
- /// 2 - Vertical top to bottom with columns to the left and also left to right (ja-JP locales)
- /// 3 - Vertical top to bottom with columns proceeding to the right
- /// (corresponds to LOCALE_IREADINGLAYOUT)
- /// </summary>
- ReadingLayout = 0x00000070,
- /// <summary>Returns 0-11 for the negative percent format (corresponds to LOCALE_INEGATIVEPERCENT)</summary>
- NegativePercentFormat = 0x00000074,
- /// <summary>Returns 0-3 for the positive percent format (corresponds to LOCALE_IPOSITIVEPERCENT)</summary>
- PositivePercentFormat = 0x00000075,
- /// <summary>default ansi code page (corresponds to LOCALE_IDEFAULTCODEPAGE)</summary>
- OemCodePage = 0x0000000B,
- /// <summary>default ansi code page (corresponds to LOCALE_IDEFAULTANSICODEPAGE)</summary>
- AnsiCodePage = 0x00001004,
- /// <summary>default mac code page (corresponds to LOCALE_IDEFAULTMACCODEPAGE)</summary>
- MacCodePage = 0x00001011,
- /// <summary>default ebcdic code page (corresponds to LOCALE_IDEFAULTEBCDICCODEPAGE)</summary>
- EbcdicCodePage = 0x00001012,
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Unix.cs
deleted file mode 100644
index 2a16ab6111f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Unix.cs
+++ /dev/null
@@ -1,36 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- public partial class CultureInfo : IFormatProvider
- {
- internal static CultureInfo GetUserDefaultCulture()
- {
- if (GlobalizationMode.Invariant)
- return CultureInfo.InvariantCulture;
-
- CultureInfo cultureInfo;
- string? localeName;
- if (CultureData.GetDefaultLocaleName(out localeName))
- {
- Debug.Assert(localeName != null);
- cultureInfo = GetCultureByName(localeName);
- }
- else
- {
- cultureInfo = CultureInfo.InvariantCulture;
- }
-
- return cultureInfo;
- }
-
- private static CultureInfo GetUserDefaultUICulture()
- {
- return InitializeUserDefaultCulture();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Windows.cs
deleted file mode 100644
index 1a8e8e81cb5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.Windows.cs
+++ /dev/null
@@ -1,59 +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.
-
-namespace System.Globalization
-{
- public partial class CultureInfo : IFormatProvider
- {
- internal static CultureInfo GetUserDefaultCulture()
- {
- if (GlobalizationMode.Invariant)
- return CultureInfo.InvariantCulture;
-
- string? strDefault = CultureData.GetLocaleInfoEx(Interop.Kernel32.LOCALE_NAME_USER_DEFAULT, Interop.Kernel32.LOCALE_SNAME);
- if (strDefault == null)
- {
- strDefault = CultureData.GetLocaleInfoEx(Interop.Kernel32.LOCALE_NAME_SYSTEM_DEFAULT, Interop.Kernel32.LOCALE_SNAME);
-
- if (strDefault == null)
- {
- // If system default doesn't work, use invariant
- return CultureInfo.InvariantCulture;
- }
- }
-
- return GetCultureByName(strDefault);
- }
-
- private static unsafe CultureInfo GetUserDefaultUICulture()
- {
- if (GlobalizationMode.Invariant)
- return CultureInfo.InvariantCulture;
-
- const uint MUI_LANGUAGE_NAME = 0x8; // Use ISO language (culture) name convention
- uint langCount = 0;
- uint bufLen = 0;
-
- if (Interop.Kernel32.GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &langCount, null, &bufLen) != Interop.BOOL.FALSE)
- {
- char[] languages = new char[bufLen];
- fixed (char* pLanguages = languages)
- {
- if (Interop.Kernel32.GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &langCount, pLanguages, &bufLen) != Interop.BOOL.FALSE)
- {
- int index = 0;
- while (languages[index] != (char)0 && index < languages.Length)
- {
- index++;
- }
-
- return GetCultureByName(new string(languages, 0, index));
- }
- }
- }
-
- return InitializeUserDefaultCulture();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.cs
deleted file mode 100644
index bc276e2bae0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureInfo.cs
+++ /dev/null
@@ -1,1166 +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.
-
-////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-// Purpose: This class represents the software preferences of a particular
-// culture or community. It includes information such as the
-// language, writing system, and a calendar used by the culture
-// as well as methods for common operations such as printing
-// dates and sorting strings.
-//
-//
-//
-// !!!! NOTE WHEN CHANGING THIS CLASS !!!!
-//
-// If adding or removing members to this class, please update CultureInfoBaseObject
-// in ndp/clr/src/vm/object.h. Note, the "actual" layout of the class may be
-// different than the order in which members are declared. For instance, all
-// reference types will come first in the class before value types (like ints, bools, etc)
-// regardless of the order in which they are declared. The best way to see the
-// actual order of the class is to do a !dumpobj on an instance of the managed
-// object inside of the debugger.
-//
-////////////////////////////////////////////////////////////////////////////
-
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Threading;
-
-namespace System.Globalization
-{
- /// <summary>
- /// This class represents the software preferences of a particular culture
- /// or community. It includes information such as the language, writing
- /// system and a calendar used by the culture as well as methods for
- /// common operations such as printing dates and sorting strings.
- /// </summary>
- /// <remarks>
- /// !!!! NOTE WHEN CHANGING THIS CLASS !!!!
- /// If adding or removing members to this class, please update
- /// CultureInfoBaseObject in ndp/clr/src/vm/object.h. Note, the "actual"
- /// layout of the class may be different than the order in which members
- /// are declared. For instance, all reference types will come first in the
- /// class before value types (like ints, bools, etc) regardless of the
- /// order in which they are declared. The best way to see the actual
- /// order of the class is to do a !dumpobj on an instance of the managed
- /// object inside of the debugger.
- /// </remarks>
- public partial class CultureInfo : IFormatProvider, ICloneable
- {
- // We use an RFC4646 type string to construct CultureInfo.
- // This string is stored in _name and is authoritative.
- // We use the _cultureData to get the data for our object
-
- private bool _isReadOnly;
- private CompareInfo? _compareInfo;
- private TextInfo? _textInfo;
- internal NumberFormatInfo? _numInfo;
- internal DateTimeFormatInfo? _dateTimeInfo;
- private Calendar? _calendar;
- //
- // The CultureData instance that we are going to read data from.
- // For supported culture, this will be the CultureData instance that read data from mscorlib assembly.
- // For customized culture, this will be the CultureData instance that read data from user customized culture binary file.
- //
- internal CultureData _cultureData;
-
- internal bool _isInherited;
-
- private CultureInfo? _consoleFallbackCulture;
-
- // Names are confusing. Here are 3 names we have:
- //
- // new CultureInfo() _name _nonSortName _sortName
- // en-US en-US en-US en-US
- // de-de_phoneb de-DE_phoneb de-DE de-DE_phoneb
- // fj-fj (custom) fj-FJ fj-FJ en-US (if specified sort is en-US)
- // en en
- //
- // Note that in Silverlight we ask the OS for the text and sort behavior, so the
- // textinfo and compareinfo names are the same as the name
-
- // This has a de-DE, de-DE_phoneb or fj-FJ style name
- internal string _name;
-
- // This will hold the non sorting name to be returned from CultureInfo.Name property.
- // This has a de-DE style name even for de-DE_phoneb type cultures
- private string? _nonSortName;
-
- // This will hold the sorting name to be returned from CultureInfo.SortName property.
- // This might be completely unrelated to the culture name if a custom culture. Ie en-US for fj-FJ.
- // Otherwise its the sort name, ie: de-DE or de-DE_phoneb
- private string? _sortName;
-
- // Get the current user default culture. This one is almost always used, so we create it by default.
- private static volatile CultureInfo? s_userDefaultCulture;
-
- // The culture used in the user interface. This is mostly used to load correct localized resources.
- private static volatile CultureInfo? s_userDefaultUICulture;
-
- // WARNING: We allow diagnostic tools to directly inspect these three members (s_InvariantCultureInfo, s_DefaultThreadCurrentUICulture and s_DefaultThreadCurrentCulture)
- // 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.
-
- // The Invariant culture;
- private static readonly CultureInfo s_InvariantCultureInfo = new CultureInfo(CultureData.Invariant, isReadOnly: true);
-
- // These are defaults that we use if a thread has not opted into having an explicit culture
- private static volatile CultureInfo? s_DefaultThreadCurrentUICulture;
- private static volatile CultureInfo? s_DefaultThreadCurrentCulture;
-
- [ThreadStatic]
- private static CultureInfo? s_currentThreadCulture;
- [ThreadStatic]
- private static CultureInfo? s_currentThreadUICulture;
-
- private static AsyncLocal<CultureInfo>? s_asyncLocalCurrentCulture;
- private static AsyncLocal<CultureInfo>? s_asyncLocalCurrentUICulture;
-
- private static void AsyncLocalSetCurrentCulture(AsyncLocalValueChangedArgs<CultureInfo> args)
- {
- s_currentThreadCulture = args.CurrentValue;
- }
-
- private static void AsyncLocalSetCurrentUICulture(AsyncLocalValueChangedArgs<CultureInfo> args)
- {
- s_currentThreadUICulture = args.CurrentValue;
- }
-
- private static volatile Dictionary<string, CultureInfo>? s_cachedCulturesByName;
- private static volatile Dictionary<int, CultureInfo>? s_cachedCulturesByLcid;
-
- // The parent culture.
- private CultureInfo? _parent;
-
- // LOCALE constants of interest to us internally and privately for LCID functions
- // (ie: avoid using these and use names if possible)
- internal const int LOCALE_NEUTRAL = 0x0000;
- private const int LOCALE_USER_DEFAULT = 0x0400;
- private const int LOCALE_SYSTEM_DEFAULT = 0x0800;
- internal const int LOCALE_CUSTOM_UNSPECIFIED = 0x1000;
- internal const int LOCALE_CUSTOM_DEFAULT = 0x0c00;
- internal const int LOCALE_INVARIANT = 0x007F;
-
- private static CultureInfo InitializeUserDefaultCulture()
- {
- Interlocked.CompareExchange(ref s_userDefaultCulture, GetUserDefaultCulture(), null);
- return s_userDefaultCulture!;
- }
-
- private static CultureInfo InitializeUserDefaultUICulture()
- {
- Interlocked.CompareExchange(ref s_userDefaultUICulture, GetUserDefaultUICulture(), null);
- return s_userDefaultUICulture!;
- }
-
- public CultureInfo(string name) : this(name, true)
- {
- }
-
- public CultureInfo(string name, bool useUserOverride)
- {
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- // Get our data providing record
- CultureData? cultureData = CultureData.GetCultureData(name, useUserOverride);
-
- if (cultureData == null)
- {
- throw new CultureNotFoundException(nameof(name), name, SR.Argument_CultureNotSupported);
- }
-
- _cultureData = cultureData;
- _name = _cultureData.CultureName;
- _isInherited = GetType() != typeof(CultureInfo);
- }
-
- private CultureInfo(CultureData cultureData, bool isReadOnly = false)
- {
- Debug.Assert(cultureData != null);
- _cultureData = cultureData;
- _name = cultureData.CultureName;
- _isInherited = false;
- _isReadOnly = isReadOnly;
- }
-
- private static CultureInfo? CreateCultureInfoNoThrow(string name, bool useUserOverride)
- {
- Debug.Assert(name != null);
- CultureData? cultureData = CultureData.GetCultureData(name, useUserOverride);
- if (cultureData == null)
- {
- return null;
- }
-
- return new CultureInfo(cultureData);
- }
-
- public CultureInfo(int culture) : this(culture, true)
- {
- }
-
- public CultureInfo(int culture, bool useUserOverride)
- {
- // We don't check for other invalid LCIDS here...
- if (culture < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(culture), SR.ArgumentOutOfRange_NeedPosNum);
- }
-
- switch (culture)
- {
- case LOCALE_CUSTOM_DEFAULT:
- case LOCALE_SYSTEM_DEFAULT:
- case LOCALE_NEUTRAL:
- case LOCALE_USER_DEFAULT:
- case LOCALE_CUSTOM_UNSPECIFIED:
- // Can't support unknown custom cultures and we do not support neutral or
- // non-custom user locales.
- throw new CultureNotFoundException(nameof(culture), culture, SR.Argument_CultureNotSupported);
- default:
- // Now see if this LCID is supported in the system default CultureData table.
- _cultureData = CultureData.GetCultureData(culture, useUserOverride);
- break;
- }
- _isInherited = GetType() != typeof(CultureInfo);
- _name = _cultureData.CultureName;
- }
-
- /// <summary>
- /// Constructor called by SQL Server's special munged culture - creates a culture with
- /// a TextInfo and CompareInfo that come from a supplied alternate source. This object
- /// is ALWAYS read-only.
- /// Note that we really cannot use an LCID version of this override as the cached
- /// name we create for it has to include both names, and the logic for this is in
- /// the GetCultureInfo override *only*.
- /// </summary>
- internal CultureInfo(string cultureName, string textAndCompareCultureName)
- {
- if (cultureName == null)
- {
- throw new ArgumentNullException(nameof(cultureName), SR.ArgumentNull_String);
- }
-
- CultureData? cultureData = CultureData.GetCultureData(cultureName, false) ??
- throw new CultureNotFoundException(nameof(cultureName), cultureName, SR.Argument_CultureNotSupported);
-
- _cultureData = cultureData;
-
- _name = _cultureData.CultureName;
-
- CultureInfo altCulture = GetCultureInfo(textAndCompareCultureName);
- _compareInfo = altCulture.CompareInfo;
- _textInfo = altCulture.TextInfo;
- }
-
- /// <summary>
- /// We do this to try to return the system UI language and the default user languages
- /// This method will fallback if this fails (like Invariant)
- /// </summary>
- private static CultureInfo GetCultureByName(string name)
- {
- try
- {
- return new CultureInfo(name)
- {
- _isReadOnly = true
- };
- }
- catch (ArgumentException)
- {
- return InvariantCulture;
- }
- }
-
- /// <summary>
- /// Return a specific culture. A tad irrelevent now since we always
- /// return valid data for neutral locales.
- ///
- /// Note that there's interesting behavior that tries to find a
- /// smaller name, ala RFC4647, if we can't find a bigger name.
- /// That doesn't help with things like "zh" though, so the approach
- /// is of questionable value
- /// </summary>
- public static CultureInfo CreateSpecificCulture(string name)
- {
- CultureInfo? culture;
-
- try
- {
- culture = new CultureInfo(name);
- }
- catch (ArgumentException)
- {
- // When CultureInfo throws this exception, it may be because someone passed the form
- // like "az-az" because it came out of an http accept lang. We should try a little
- // parsing to perhaps fall back to "az" here and use *it* to create the neutral.
- culture = null;
- for (int idx = 0; idx < name.Length; idx++)
- {
- if ('-' == name[idx])
- {
- try
- {
- culture = new CultureInfo(name.Substring(0, idx));
- break;
- }
- catch (ArgumentException)
- {
- // throw the original exception so the name in the string will be right
- throw;
- }
- }
- }
-
- if (culture == null)
- {
- // nothing to save here; throw the original exception
- throw;
- }
- }
-
- // In the most common case, they've given us a specific culture, so we'll just return that.
- if (!culture.IsNeutralCulture)
- {
- return culture;
- }
-
- return new CultureInfo(culture._cultureData.SpecificCultureName);
- }
-
- internal static bool VerifyCultureName(string cultureName, bool throwException)
- {
- // This function is used by ResourceManager.GetResourceFileName().
- // ResourceManager searches for resource using CultureInfo.Name,
- // so we should check against CultureInfo.Name.
- for (int i = 0; i < cultureName.Length; i++)
- {
- char c = cultureName[i];
- // TODO: Names can only be RFC4646 names (ie: a-zA-Z0-9) while this allows any unicode letter/digit
- if (char.IsLetterOrDigit(c) || c == '-' || c == '_')
- {
- continue;
- }
- if (throwException)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidResourceCultureName, cultureName));
- }
- return false;
- }
- return true;
- }
-
- internal static bool VerifyCultureName(CultureInfo culture, bool throwException)
- {
- // If we have an instance of one of our CultureInfos, the user can't have changed the
- // name and we know that all names are valid in files.
- if (!culture._isInherited)
- {
- return true;
- }
-
- return VerifyCultureName(culture.Name, throwException);
- }
-
- /// <summary>
- /// This instance provides methods based on the current user settings.
- /// These settings are volatile and may change over the lifetime of the
- /// thread.
- /// </summary>
- /// <remarks>
- /// We use the following order to return CurrentCulture and CurrentUICulture
- /// o Use WinRT to return the current user profile language
- /// o use current thread culture if the user already set one using CurrentCulture/CurrentUICulture
- /// o use thread culture if the user already set one using DefaultThreadCurrentCulture
- /// or DefaultThreadCurrentUICulture
- /// o Use NLS default user culture
- /// o Use NLS default system culture
- /// o Use Invariant culture
- /// </remarks>
- public static CultureInfo CurrentCulture
- {
- get
- {
- return s_currentThreadCulture ??
- s_DefaultThreadCurrentCulture ??
- s_userDefaultCulture ??
- InitializeUserDefaultCulture();
- }
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- if (s_asyncLocalCurrentCulture == null)
- {
- Interlocked.CompareExchange(ref s_asyncLocalCurrentCulture, new AsyncLocal<CultureInfo>(AsyncLocalSetCurrentCulture), null);
- }
- s_asyncLocalCurrentCulture!.Value = value;
- }
- }
-
- public static CultureInfo CurrentUICulture
- {
- get
- {
- return s_currentThreadUICulture ??
- s_DefaultThreadCurrentUICulture ??
- UserDefaultUICulture;
- }
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- CultureInfo.VerifyCultureName(value, true);
-
- if (s_asyncLocalCurrentUICulture == null)
- {
- Interlocked.CompareExchange(ref s_asyncLocalCurrentUICulture, new AsyncLocal<CultureInfo>(AsyncLocalSetCurrentUICulture), null);
- }
-
- // this one will set s_currentThreadUICulture too
- s_asyncLocalCurrentUICulture!.Value = value;
- }
- }
-
- internal static CultureInfo UserDefaultUICulture => s_userDefaultUICulture ?? InitializeUserDefaultUICulture();
-
- public static CultureInfo InstalledUICulture => s_userDefaultCulture ?? InitializeUserDefaultCulture();
-
- public static CultureInfo? DefaultThreadCurrentCulture
- {
- get => s_DefaultThreadCurrentCulture;
- set =>
- // If you add pre-conditions to this method, check to see if you also need to
- // add them to Thread.CurrentCulture.set.
- s_DefaultThreadCurrentCulture = value;
- }
-
- public static CultureInfo? DefaultThreadCurrentUICulture
- {
- get => s_DefaultThreadCurrentUICulture;
- set
- {
- // If they're trying to use a Culture with a name that we can't use in resource lookup,
- // don't even let them set it on the thread.
-
- // If you add more pre-conditions to this method, check to see if you also need to
- // add them to Thread.CurrentUICulture.set.
-
- if (value != null)
- {
- CultureInfo.VerifyCultureName(value, true);
- }
-
- s_DefaultThreadCurrentUICulture = value;
- }
- }
-
- /// <summary>
- /// This instance provides methods, for example for casing and sorting,
- /// that are independent of the system and current user settings. It
- /// should be used only by processes such as some system services that
- /// require such invariant results (eg. file systems). In general,
- /// the results are not linguistically correct and do not match any
- /// culture info.
- /// </summary>
- public static CultureInfo InvariantCulture
- {
- get
- {
- Debug.Assert(s_InvariantCultureInfo != null);
- return s_InvariantCultureInfo;
- }
- }
-
- /// <summary>
- /// Return the parent CultureInfo for the current instance.
- /// </summary>
- public virtual CultureInfo Parent
- {
- get
- {
- if (_parent == null)
- {
- CultureInfo culture;
- string parentName = _cultureData.ParentName;
-
- if (string.IsNullOrEmpty(parentName))
- {
- culture = InvariantCulture;
- }
- else
- {
- culture = CreateCultureInfoNoThrow(parentName, _cultureData.UseUserOverride) ??
- // For whatever reason our IPARENT or SPARENT wasn't correct, so use invariant
- // We can't allow ourselves to fail. In case of custom cultures the parent of the
- // current custom culture isn't installed.
- InvariantCulture;
- }
-
- Interlocked.CompareExchange<CultureInfo?>(ref _parent, culture, null);
- }
- return _parent!;
- }
- }
-
- public virtual int LCID => _cultureData.LCID;
-
- public virtual int KeyboardLayoutId => _cultureData.KeyboardLayoutId;
-
- public static CultureInfo[] GetCultures(CultureTypes types)
- {
- // internally we treat UserCustomCultures as Supplementals but v2
- // treats as Supplementals and Replacements
- if ((types & CultureTypes.UserCustomCulture) == CultureTypes.UserCustomCulture)
- {
- types |= CultureTypes.ReplacementCultures;
- }
- return CultureData.GetCultures(types);
- }
-
- /// <summary>
- /// Returns the full name of the CultureInfo. The name is in format like
- /// "en-US" This version does NOT include sort information in the name.
- /// </summary>
- public virtual string Name => _nonSortName ??= (_cultureData.Name ?? string.Empty);
-
- /// <summary>
- /// This one has the sort information (ie: de-DE_phoneb)
- /// </summary>
- internal string SortName => _sortName ??= _cultureData.SortName;
-
- public string IetfLanguageTag =>
- // special case the compatibility cultures
- Name switch
- {
- "zh-CHT" => "zh-Hant",
- "zh-CHS" => "zh-Hans",
- _ => Name,
- };
-
- /// <summary>
- /// Returns the full name of the CultureInfo in the localized language.
- /// For example, if the localized language of the runtime is Spanish and the CultureInfo is
- /// US English, "Ingles (Estados Unidos)" will be returned.
- /// </summary>
- public virtual string DisplayName
- {
- get
- {
- Debug.Assert(_name != null, "[CultureInfo.DisplayName] Always expect _name to be set");
- return _cultureData.DisplayName;
- }
- }
-
- /// <summary>
- /// Returns the full name of the CultureInfo in the native language.
- /// For example, if the CultureInfo is US English, "English
- /// (United States)" will be returned.
- /// </summary>
- public virtual string NativeName => _cultureData.NativeName;
-
- /// <summary>
- /// Returns the full name of the CultureInfo in English.
- /// For example, if the CultureInfo is US English, "English
- /// (United States)" will be returned.
- /// </summary>
- public virtual string EnglishName => _cultureData.EnglishName;
-
- /// <summary>
- /// ie: en
- /// </summary>
- public virtual string TwoLetterISOLanguageName => _cultureData.TwoLetterISOLanguageName;
-
- /// <summary>
- /// ie: eng
- /// </summary>
- public virtual string ThreeLetterISOLanguageName => _cultureData.ThreeLetterISOLanguageName;
-
- /// <summary>
- /// Returns the 3 letter windows language name for the current instance. eg: "ENU"
- /// The ISO names are much preferred
- /// </summary>
- public virtual string ThreeLetterWindowsLanguageName => _cultureData.ThreeLetterWindowsLanguageName;
-
- /// <summary>
- /// Gets the CompareInfo for this culture.
- /// </summary>
- public virtual CompareInfo CompareInfo => _compareInfo ??=
- // Since CompareInfo's don't have any overrideable properties, get the CompareInfo from
- // the Non-Overridden CultureInfo so that we only create one CompareInfo per culture
- (UseUserOverride ? GetCultureInfo(_name).CompareInfo : new CompareInfo(this));
-
- /// <summary>
- /// Gets the TextInfo for this culture.
- /// </summary>
- public virtual TextInfo TextInfo
- {
- get
- {
- if (_textInfo == null)
- {
- // Make a new textInfo
- TextInfo tempTextInfo = new TextInfo(_cultureData);
- tempTextInfo.SetReadOnlyState(_isReadOnly);
- _textInfo = tempTextInfo;
- }
- return _textInfo;
- }
- }
-
- public override bool Equals(object? value)
- {
- if (object.ReferenceEquals(this, value))
- {
- return true;
- }
-
- if (value is CultureInfo that)
- {
- // using CompareInfo to verify the data passed through the constructor
- // CultureInfo(String cultureName, String textAndCompareCultureName)
- return Name.Equals(that.Name) && CompareInfo.Equals(that.CompareInfo);
- }
-
- return false;
- }
-
- public override int GetHashCode()
- {
- return Name.GetHashCode() + CompareInfo.GetHashCode();
- }
-
- /// <summary>
- /// Implements object.ToString(). Returns the name of the CultureInfo,
- /// eg. "de-DE_phoneb", "en-US", or "fj-FJ".
- /// </summary>
- public override string ToString() => _name;
-
- public virtual object? GetFormat(Type? formatType)
- {
- if (formatType == typeof(NumberFormatInfo))
- {
- return NumberFormat;
- }
- if (formatType == typeof(DateTimeFormatInfo))
- {
- return DateTimeFormat;
- }
-
- return null;
- }
-
- public virtual bool IsNeutralCulture => _cultureData.IsNeutralCulture;
-
- public CultureTypes CultureTypes
- {
- get
- {
- CultureTypes types = _cultureData.IsNeutralCulture ?
- CultureTypes.NeutralCultures :
- CultureTypes.SpecificCultures;
-
- if (_cultureData.IsWin32Installed)
- {
- types |= CultureTypes.InstalledWin32Cultures;
- }
-
- if (_cultureData.IsSupplementalCustomCulture)
- {
- types |= CultureTypes.UserCustomCulture;
- }
-
- if (_cultureData.IsReplacementCulture)
- {
- types |= CultureTypes.ReplacementCultures;
- }
-
- return types;
- }
- }
-
- public virtual NumberFormatInfo NumberFormat
- {
- get
- {
- if (_numInfo == null)
- {
- NumberFormatInfo temp = new NumberFormatInfo(_cultureData);
- temp._isReadOnly = _isReadOnly;
- Interlocked.CompareExchange(ref _numInfo, temp, null);
- }
- return _numInfo!;
- }
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- _numInfo = value;
- }
- }
-
- /// <summary>
- /// Create a DateTimeFormatInfo, and fill in the properties according to
- /// the CultureID.
- /// </summary>
- public virtual DateTimeFormatInfo DateTimeFormat
- {
- get
- {
- if (_dateTimeInfo == null)
- {
- // Change the calendar of DTFI to the specified calendar of this CultureInfo.
- DateTimeFormatInfo temp = new DateTimeFormatInfo(_cultureData, this.Calendar);
- temp._isReadOnly = _isReadOnly;
- Interlocked.CompareExchange(ref _dateTimeInfo, temp, null);
- }
- return _dateTimeInfo!;
- }
-
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- _dateTimeInfo = value;
- }
- }
-
- public void ClearCachedData()
- {
- // reset the default culture values
- s_userDefaultCulture = GetUserDefaultCulture();
- s_userDefaultUICulture = GetUserDefaultUICulture();
-
- RegionInfo.s_currentRegionInfo = null;
-#pragma warning disable 0618 // disable the obsolete warning
- TimeZone.ResetTimeZone();
-#pragma warning restore 0618
- TimeZoneInfo.ClearCachedData();
- s_cachedCulturesByLcid = null;
- s_cachedCulturesByName = null;
-
- CultureData.ClearCachedData();
- }
-
- /// <summary>
- /// Map a Win32 CALID to an instance of supported calendar.
- /// </summary>
- /// <remarks>
- /// Shouldn't throw exception since the calType value is from our data
- /// table or from Win32 registry.
- /// If we are in trouble (like getting a weird value from Win32
- /// registry), just return the GregorianCalendar.
- /// </remarks>
- internal static Calendar GetCalendarInstance(CalendarId calType)
- {
- if (calType == CalendarId.GREGORIAN)
- {
- return new GregorianCalendar();
- }
-
- return GetCalendarInstanceRare(calType);
- }
-
- /// <summary>
- /// This function exists as a shortcut to prevent us from loading all of the non-gregorian
- /// calendars unless they're required.
- /// </summary>
- internal static Calendar GetCalendarInstanceRare(CalendarId calType)
- {
- Debug.Assert(calType != CalendarId.GREGORIAN, "calType!=CalendarId.GREGORIAN");
-
- switch (calType)
- {
- case CalendarId.GREGORIAN_US: // Gregorian (U.S.) calendar
- case CalendarId.GREGORIAN_ME_FRENCH: // Gregorian Middle East French calendar
- case CalendarId.GREGORIAN_ARABIC: // Gregorian Arabic calendar
- case CalendarId.GREGORIAN_XLIT_ENGLISH: // Gregorian Transliterated English calendar
- case CalendarId.GREGORIAN_XLIT_FRENCH: // Gregorian Transliterated French calendar
- return new GregorianCalendar((GregorianCalendarTypes)calType);
- case CalendarId.TAIWAN: // Taiwan Era calendar
- return new TaiwanCalendar();
- case CalendarId.JAPAN: // Japanese Emperor Era calendar
- return new JapaneseCalendar();
- case CalendarId.KOREA: // Korean Tangun Era calendar
- return new KoreanCalendar();
- case CalendarId.THAI: // Thai calendar
- return new ThaiBuddhistCalendar();
- case CalendarId.HIJRI: // Hijri (Arabic Lunar) calendar
- return new HijriCalendar();
- case CalendarId.HEBREW: // Hebrew (Lunar) calendar
- return new HebrewCalendar();
- case CalendarId.UMALQURA:
- return new UmAlQuraCalendar();
- case CalendarId.PERSIAN:
- return new PersianCalendar();
- }
- return new GregorianCalendar();
- }
-
- /// <summary>
- /// Return/set the default calendar used by this culture.
- /// This value can be overridden by regional option if this is a current culture.
- /// </summary>
- public virtual Calendar Calendar
- {
- get
- {
- if (_calendar == null)
- {
- Debug.Assert(_cultureData.CalendarIds.Length > 0, "_cultureData.CalendarIds.Length > 0");
- // Get the default calendar for this culture. Note that the value can be
- // from registry if this is a user default culture.
- Calendar newObj = _cultureData.DefaultCalendar;
-
- Interlocked.MemoryBarrier();
- newObj.SetReadOnlyState(_isReadOnly);
- _calendar = newObj;
- }
- return _calendar;
- }
- }
-
- /// <summary>
- /// Return an array of the optional calendar for this culture.
- /// </summary>
- public virtual Calendar[] OptionalCalendars
- {
- get
- {
- // This property always returns a new copy of the calendar array.
- CalendarId[] calID = _cultureData.CalendarIds;
- Calendar[] cals = new Calendar[calID.Length];
- for (int i = 0; i < cals.Length; i++)
- {
- cals[i] = GetCalendarInstance(calID[i]);
- }
- return cals;
- }
- }
-
- public bool UseUserOverride => _cultureData.UseUserOverride;
-
- public CultureInfo GetConsoleFallbackUICulture()
- {
- CultureInfo? temp = _consoleFallbackCulture;
- if (temp == null)
- {
- temp = CreateSpecificCulture(_cultureData.SCONSOLEFALLBACKNAME);
- temp._isReadOnly = true;
- _consoleFallbackCulture = temp;
- }
- return temp;
- }
-
- public virtual object Clone()
- {
- CultureInfo ci = (CultureInfo)MemberwiseClone();
- ci._isReadOnly = false;
-
- // If this is exactly our type, we can make certain optimizations so that we don't allocate NumberFormatInfo or DTFI unless
- // they've already been allocated. If this is a derived type, we'll take a more generic codepath.
- if (!_isInherited)
- {
- if (_dateTimeInfo != null)
- {
- ci._dateTimeInfo = (DateTimeFormatInfo)_dateTimeInfo.Clone();
- }
- if (_numInfo != null)
- {
- ci._numInfo = (NumberFormatInfo)_numInfo.Clone();
- }
- }
- else
- {
- ci.DateTimeFormat = (DateTimeFormatInfo)this.DateTimeFormat.Clone();
- ci.NumberFormat = (NumberFormatInfo)this.NumberFormat.Clone();
- }
-
- if (_textInfo != null)
- {
- ci._textInfo = (TextInfo)_textInfo.Clone();
- }
-
- if (_dateTimeInfo != null && _dateTimeInfo.Calendar == _calendar)
- {
- // Usually when we access CultureInfo.DateTimeFormat first time, we create the DateTimeFormatInfo object
- // using CultureInfo.Calendar. i.e. CultureInfo.DateTimeInfo.Calendar == CultureInfo.calendar.
- // When cloning CultureInfo, if we know it's still the case that CultureInfo.DateTimeInfo.Calendar == CultureInfo.calendar
- // then we can keep the same behavior for the cloned object and no need to create another calendar object.
- ci._calendar = ci.DateTimeFormat.Calendar;
- }
- else if (_calendar != null)
- {
- ci._calendar = (Calendar)_calendar.Clone();
- }
-
- return ci;
- }
-
- public static CultureInfo ReadOnly(CultureInfo ci)
- {
- if (ci == null)
- {
- throw new ArgumentNullException(nameof(ci));
- }
-
- if (ci.IsReadOnly)
- {
- return ci;
- }
- CultureInfo newInfo = (CultureInfo)(ci.MemberwiseClone());
-
- if (!ci.IsNeutralCulture)
- {
- // If this is exactly our type, we can make certain optimizations so that we don't allocate NumberFormatInfo or DTFI unless
- // they've already been allocated. If this is a derived type, we'll take a more generic codepath.
- if (!ci._isInherited)
- {
- if (ci._dateTimeInfo != null)
- {
- newInfo._dateTimeInfo = DateTimeFormatInfo.ReadOnly(ci._dateTimeInfo);
- }
- if (ci._numInfo != null)
- {
- newInfo._numInfo = NumberFormatInfo.ReadOnly(ci._numInfo);
- }
- }
- else
- {
- newInfo.DateTimeFormat = DateTimeFormatInfo.ReadOnly(ci.DateTimeFormat);
- newInfo.NumberFormat = NumberFormatInfo.ReadOnly(ci.NumberFormat);
- }
- }
-
- if (ci._textInfo != null)
- {
- newInfo._textInfo = TextInfo.ReadOnly(ci._textInfo);
- }
-
- if (ci._calendar != null)
- {
- newInfo._calendar = Calendar.ReadOnly(ci._calendar);
- }
-
- // Don't set the read-only flag too early.
- // We should set the read-only flag here. Otherwise, info.DateTimeFormat will not be able to set.
- newInfo._isReadOnly = true;
-
- return newInfo;
- }
-
- public bool IsReadOnly => _isReadOnly;
-
- private void VerifyWritable()
- {
- if (_isReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- }
-
- /// <summary>
- /// For resource lookup, we consider a culture the invariant culture by name equality.
- /// We perform this check frequently during resource lookup, so adding a property for
- /// improved readability.
- /// </summary>
- internal bool HasInvariantCultureName => Name == InvariantCulture.Name;
-
- /// <summary>
- /// Gets a cached copy of the specified culture from an internal
- /// hashtable (or creates it if not found). (LCID version)
- /// </summary>
- public static CultureInfo GetCultureInfo(int culture)
- {
- if (culture <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(culture), SR.ArgumentOutOfRange_NeedPosNum);
- }
-
- Dictionary<int, CultureInfo> lcidTable = CachedCulturesByLcid;
- CultureInfo? result;
-
- lock (lcidTable)
- {
- if (lcidTable.TryGetValue(culture, out result))
- {
- return result;
- }
- }
-
- try
- {
- result = new CultureInfo(culture, useUserOverride: false) { _isReadOnly = true };
- }
- catch (ArgumentException)
- {
- throw new CultureNotFoundException(nameof(culture), culture, SR.Argument_CultureNotSupported);
- }
-
- lock (lcidTable)
- {
- lcidTable[culture] = result;
- }
-
- return result;
- }
-
- /// <summary>
- /// Gets a cached copy of the specified culture from an internal
- /// hashtable (or creates it if not found). (Named version)
- /// </summary>
- public static CultureInfo GetCultureInfo(string name)
- {
- // Make sure we have a valid, non-zero length string as name
- if (name is null)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- name = CultureData.AnsiToLower(name);
- Dictionary<string, CultureInfo> nameTable = CachedCulturesByName;
- CultureInfo? result;
-
- lock (nameTable)
- {
- if (nameTable.TryGetValue(name, out result))
- {
- return result;
- }
- }
-
- result = CreateCultureInfoNoThrow(name, useUserOverride: false) ??
- throw new CultureNotFoundException(nameof(name), name, SR.Argument_CultureNotSupported);
- result._isReadOnly = true;
-
- // Remember our name as constructed. Do NOT use alternate sort name versions because
- // we have internal state representing the sort (so someone would get the wrong cached version).
- name = CultureData.AnsiToLower(result._name);
-
- lock (nameTable)
- {
- nameTable[name] = result;
- }
-
- return result;
- }
-
- /// <summary>
- /// Gets a cached copy of the specified culture from an internal
- /// hashtable (or creates it if not found).
- /// </summary>
- public static CultureInfo GetCultureInfo(string name, string altName)
- {
- if (name is null)
- {
- throw new ArgumentNullException(nameof(name));
- }
- if (altName is null)
- {
- throw new ArgumentNullException(nameof(altName));
- }
-
- name = CultureData.AnsiToLower(name);
- altName = CultureData.AnsiToLower(altName);
- string nameAndAltName = name + "\xfffd" + altName;
- Dictionary<string, CultureInfo> nameTable = CachedCulturesByName;
- CultureInfo? result;
-
- lock (nameTable)
- {
- if (nameTable.TryGetValue(nameAndAltName, out result))
- {
- return result;
- }
- }
-
- try
- {
- result = new CultureInfo(name, altName) { _isReadOnly = true };
- result.TextInfo.SetReadOnlyState(readOnly: true); // TextInfo object is already created; we need to set it as read only.
- }
- catch (ArgumentException)
- {
- throw new CultureNotFoundException("name/altName", SR.Format(SR.Argument_OneOfCulturesNotSupported, name, altName));
- }
-
- lock (nameTable)
- {
- nameTable[nameAndAltName] = result;
- }
-
- return result;
- }
-
- private static Dictionary<string, CultureInfo> CachedCulturesByName
- {
- get
- {
- Dictionary<string, CultureInfo>? cache = s_cachedCulturesByName;
- if (cache is null)
- {
- cache = new Dictionary<string, CultureInfo>();
- cache = Interlocked.CompareExchange(ref s_cachedCulturesByName, cache, null) ?? cache;
- }
-
- return cache;
- }
- }
-
- private static Dictionary<int, CultureInfo> CachedCulturesByLcid
- {
- get
- {
- Dictionary<int, CultureInfo>? cache = s_cachedCulturesByLcid;
- if (cache is null)
- {
- cache = new Dictionary<int, CultureInfo>();
- cache = Interlocked.CompareExchange(ref s_cachedCulturesByLcid, cache, null) ?? cache;
- }
-
- return cache;
- }
- }
-
- public static CultureInfo GetCultureInfoByIetfLanguageTag(string name)
- {
- // Disallow old zh-CHT/zh-CHS names
- if (name == "zh-CHT" || name == "zh-CHS")
- {
- throw new CultureNotFoundException(nameof(name), SR.Format(SR.Argument_CultureIetfNotSupported, name));
- }
-
- CultureInfo ci = GetCultureInfo(name);
-
- // Disallow alt sorts and es-es_TS
- if (ci.LCID > 0xffff || ci.LCID == 0x040a)
- {
- throw new CultureNotFoundException(nameof(name), SR.Format(SR.Argument_CultureIetfNotSupported, name));
- }
-
- return ci;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureNotFoundException.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureNotFoundException.cs
deleted file mode 100644
index 5869b6ae51d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureNotFoundException.cs
+++ /dev/null
@@ -1,104 +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 System.Runtime.Serialization;
-
-namespace System.Globalization
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class CultureNotFoundException : ArgumentException
- {
- private readonly string? _invalidCultureName; // unrecognized culture name
- private readonly int? _invalidCultureId; // unrecognized culture Lcid
-
- public CultureNotFoundException()
- : base(DefaultMessage)
- {
- }
-
- public CultureNotFoundException(string? message)
- : base(message)
- {
- }
-
- public CultureNotFoundException(string? paramName, string? message)
- : base(message, paramName)
- {
- }
-
- public CultureNotFoundException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- }
-
- public CultureNotFoundException(string? paramName, string? invalidCultureName, string? message)
- : base(message, paramName)
- {
- _invalidCultureName = invalidCultureName;
- }
-
- public CultureNotFoundException(string? message, string? invalidCultureName, Exception? innerException)
- : base(message, innerException)
- {
- _invalidCultureName = invalidCultureName;
- }
-
- public CultureNotFoundException(string? message, int invalidCultureId, Exception? innerException)
- : base(message, innerException)
- {
- _invalidCultureId = invalidCultureId;
- }
-
- public CultureNotFoundException(string? paramName, int invalidCultureId, string? message)
- : base(message, paramName)
- {
- _invalidCultureId = invalidCultureId;
- }
-
- protected CultureNotFoundException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- _invalidCultureId = (int?)info.GetValue("InvalidCultureId", typeof(int?));
- _invalidCultureName = (string?)info.GetValue("InvalidCultureName", typeof(string));
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("InvalidCultureId", _invalidCultureId, typeof(int?));
- info.AddValue("InvalidCultureName", _invalidCultureName, typeof(string));
- }
-
- public virtual int? InvalidCultureId => _invalidCultureId;
-
- public virtual string? InvalidCultureName => _invalidCultureName;
-
- private static string DefaultMessage => SR.Argument_CultureNotSupported;
-
- private string? FormattedInvalidCultureId =>
- InvalidCultureId != null ?
- string.Format(CultureInfo.InvariantCulture, "{0} (0x{0:x4})", (int)InvalidCultureId) :
- InvalidCultureName;
-
- public override string Message
- {
- get
- {
- string s = base.Message;
- if (_invalidCultureId != null || _invalidCultureName != null)
- {
- string valueMessage = SR.Format(SR.Argument_CultureInvalidIdentifier, FormattedInvalidCultureId);
- if (s == null)
- {
- return valueMessage;
- }
-
- return s + Environment.NewLineConst + valueMessage;
- }
- return s;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureTypes.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureTypes.cs
deleted file mode 100644
index f780b1ce57c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureTypes.cs
+++ /dev/null
@@ -1,27 +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.
-
-// The enumeration constants used in CultureInfo.GetCultures().
-// On Linux platforms, the only enum values used there is NeutralCultures and SpecificCultures
-// the rest are obsolete or not valid on Linux
-
-namespace System.Globalization
-{
- [Flags]
- public enum CultureTypes
- {
- NeutralCultures = 0x0001, // Neutral cultures are cultures like "en", "de", "zh", etc, for enumeration this includes ALL neutrals regardless of other flags
- SpecificCultures = 0x0002, // Non-netural cultuers. Examples are "en-us", "zh-tw", etc., for enumeration this includes ALL specifics regardless of other flags
- InstalledWin32Cultures = 0x0004, // Win32 installed cultures in the system and exists in the framework too., this is effectively all cultures
-
- AllCultures = NeutralCultures | SpecificCultures | InstalledWin32Cultures,
-
- UserCustomCulture = 0x0008, // User defined custom culture
- ReplacementCultures = 0x0010, // User defined replacement custom culture.
- [Obsolete("This value has been deprecated. Please use other values in CultureTypes.")]
- WindowsOnlyCultures = 0x0020, // this will always return empty list.
- [Obsolete("This value has been deprecated. Please use other values in CultureTypes.")]
- FrameworkCultures = 0x0040, // will return only the v2 cultures marked as Framework culture.
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs
deleted file mode 100644
index 8f8944bba2f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs
+++ /dev/null
@@ -1,1380 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.Text;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- /*
- Customized format patterns:
- P.S. Format in the table below is the internal number format used to display the pattern.
-
- Patterns Format Description Example
- ========= ========== ===================================== ========
- "h" "0" hour (12-hour clock)w/o leading zero 3
- "hh" "00" hour (12-hour clock)with leading zero 03
- "hh*" "00" hour (12-hour clock)with leading zero 03
-
- "H" "0" hour (24-hour clock)w/o leading zero 8
- "HH" "00" hour (24-hour clock)with leading zero 08
- "HH*" "00" hour (24-hour clock) 08
-
- "m" "0" minute w/o leading zero
- "mm" "00" minute with leading zero
- "mm*" "00" minute with leading zero
-
- "s" "0" second w/o leading zero
- "ss" "00" second with leading zero
- "ss*" "00" second with leading zero
-
- "f" "0" second fraction (1 digit)
- "ff" "00" second fraction (2 digit)
- "fff" "000" second fraction (3 digit)
- "ffff" "0000" second fraction (4 digit)
- "fffff" "00000" second fraction (5 digit)
- "ffffff" "000000" second fraction (6 digit)
- "fffffff" "0000000" second fraction (7 digit)
-
- "F" "0" second fraction (up to 1 digit)
- "FF" "00" second fraction (up to 2 digit)
- "FFF" "000" second fraction (up to 3 digit)
- "FFFF" "0000" second fraction (up to 4 digit)
- "FFFFF" "00000" second fraction (up to 5 digit)
- "FFFFFF" "000000" second fraction (up to 6 digit)
- "FFFFFFF" "0000000" second fraction (up to 7 digit)
-
- "t" first character of AM/PM designator A
- "tt" AM/PM designator AM
- "tt*" AM/PM designator PM
-
- "d" "0" day w/o leading zero 1
- "dd" "00" day with leading zero 01
- "ddd" short weekday name (abbreviation) Mon
- "dddd" full weekday name Monday
- "dddd*" full weekday name Monday
-
-
- "M" "0" month w/o leading zero 2
- "MM" "00" month with leading zero 02
- "MMM" short month name (abbreviation) Feb
- "MMMM" full month name Febuary
- "MMMM*" full month name Febuary
-
- "y" "0" two digit year (year % 100) w/o leading zero 0
- "yy" "00" two digit year (year % 100) with leading zero 00
- "yyy" "D3" year 2000
- "yyyy" "D4" year 2000
- "yyyyy" "D5" year 2000
- ...
-
- "z" "+0;-0" timezone offset w/o leading zero -8
- "zz" "+00;-00" timezone offset with leading zero -08
- "zzz" "+00;-00" for hour offset, "00" for minute offset full timezone offset -07:30
- "zzz*" "+00;-00" for hour offset, "00" for minute offset full timezone offset -08:00
-
- "K" -Local "zzz", e.g. -08:00
- -Utc "'Z'", representing UTC
- -Unspecified ""
- -DateTimeOffset "zzzzz" e.g -07:30:15
-
- "g*" the current era name A.D.
-
- ":" time separator : -- DEPRECATED - Insert separator directly into pattern (eg: "H.mm.ss")
- "/" date separator /-- DEPRECATED - Insert separator directly into pattern (eg: "M-dd-yyyy")
- "'" quoted string 'ABC' will insert ABC into the formatted string.
- '"' quoted string "ABC" will insert ABC into the formatted string.
- "%" used to quote a single pattern characters E.g.The format character "%y" is to print two digit year.
- "\" escaped character E.g. '\d' insert the character 'd' into the format string.
- other characters insert the character into the format string.
-
- Pre-defined format characters:
- (U) to indicate Universal time is used.
- (G) to indicate Gregorian calendar is used.
-
- Format Description Real format Example
- ========= ================================= ====================== =======================
- "d" short date culture-specific 10/31/1999
- "D" long data culture-specific Sunday, October 31, 1999
- "f" full date (long date + short time) culture-specific Sunday, October 31, 1999 2:00 AM
- "F" full date (long date + long time) culture-specific Sunday, October 31, 1999 2:00:00 AM
- "g" general date (short date + short time) culture-specific 10/31/1999 2:00 AM
- "G" general date (short date + long time) culture-specific 10/31/1999 2:00:00 AM
- "m"/"M" Month/Day date culture-specific October 31
-(G) "o"/"O" Round Trip XML "yyyy-MM-ddTHH:mm:ss.fffffffK" 1999-10-31 02:00:00.0000000Z
-(G) "r"/"R" RFC 1123 date, "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'" Sun, 31 Oct 1999 10:00:00 GMT
-(G) "s" Sortable format, based on ISO 8601. "yyyy-MM-dd'T'HH:mm:ss" 1999-10-31T02:00:00
- ('T' for local time)
- "t" short time culture-specific 2:00 AM
- "T" long time culture-specific 2:00:00 AM
-(G) "u" Universal time with sortable format, "yyyy'-'MM'-'dd HH':'mm':'ss'Z'" 1999-10-31 10:00:00Z
- based on ISO 8601.
-(U) "U" Universal time with full culture-specific Sunday, October 31, 1999 10:00:00 AM
- (long date + long time) format
- "y"/"Y" Year/Month day culture-specific October, 1999
-
- */
-
- // This class contains only static members and does not require the serializable attribute.
- internal static
- class DateTimeFormat
- {
- internal const int MaxSecondsFractionDigits = 7;
- internal static readonly TimeSpan NullOffset = TimeSpan.MinValue;
-
- internal static char[] allStandardFormats =
- {
- 'd', 'D', 'f', 'F', 'g', 'G',
- 'm', 'M', 'o', 'O', 'r', 'R',
- 's', 't', 'T', 'u', 'U', 'y', 'Y',
- };
-
- internal const string RoundtripFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK";
- internal const string RoundtripDateTimeUnfixed = "yyyy'-'MM'-'ddTHH':'mm':'ss zzz";
-
- private const int DEFAULT_ALL_DATETIMES_SIZE = 132;
-
- internal static readonly DateTimeFormatInfo InvariantFormatInfo = CultureInfo.InvariantCulture.DateTimeFormat;
- internal static readonly string[] InvariantAbbreviatedMonthNames = InvariantFormatInfo.AbbreviatedMonthNames;
- internal static readonly string[] InvariantAbbreviatedDayNames = InvariantFormatInfo.AbbreviatedDayNames;
- internal const string Gmt = "GMT";
-
- internal static string[] fixedNumberFormats = new string[] {
- "0",
- "00",
- "000",
- "0000",
- "00000",
- "000000",
- "0000000",
- };
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Format the positive integer value to a string and prefix with assigned
- // length of leading zero.
- //
- // Parameters:
- // value: The value to format
- // len: The maximum length for leading zero.
- // If the digits of the value is greater than len, no leading zero is added.
- //
- // Notes:
- // The function can format to int.MaxValue.
- //
- ////////////////////////////////////////////////////////////////////////////
- internal static void FormatDigits(StringBuilder outputBuffer, int value, int len)
- {
- Debug.Assert(value >= 0, "DateTimeFormat.FormatDigits(): value >= 0");
- FormatDigits(outputBuffer, value, len, false);
- }
-
- internal static unsafe void FormatDigits(StringBuilder outputBuffer, int value, int len, bool overrideLengthLimit)
- {
- Debug.Assert(value >= 0, "DateTimeFormat.FormatDigits(): value >= 0");
-
- // Limit the use of this function to be two-digits, so that we have the same behavior
- // as RTM bits.
- if (!overrideLengthLimit && len > 2)
- {
- len = 2;
- }
-
- char* buffer = stackalloc char[16];
- char* p = buffer + 16;
- int n = value;
- do
- {
- *--p = (char)(n % 10 + '0');
- n /= 10;
- } while ((n != 0) && (p > buffer));
-
- int digits = (int)(buffer + 16 - p);
-
- // If the repeat count is greater than 0, we're trying
- // to emulate the "00" format, so we have to prepend
- // a zero if the string only has one character.
- while ((digits < len) && (p > buffer))
- {
- *--p = '0';
- digits++;
- }
- outputBuffer.Append(p, digits);
- }
-
- private static void HebrewFormatDigits(StringBuilder outputBuffer, int digits)
- {
- HebrewNumber.Append(outputBuffer, digits);
- }
-
- internal static int ParseRepeatPattern(ReadOnlySpan<char> format, int pos, char patternChar)
- {
- int len = format.Length;
- int index = pos + 1;
- while ((index < len) && (format[index] == patternChar))
- {
- index++;
- }
- return index - pos;
- }
-
- private static string FormatDayOfWeek(int dayOfWeek, int repeat, DateTimeFormatInfo dtfi)
- {
- Debug.Assert(dayOfWeek >= 0 && dayOfWeek <= 6, "dayOfWeek >= 0 && dayOfWeek <= 6");
- if (repeat == 3)
- {
- return dtfi.GetAbbreviatedDayName((DayOfWeek)dayOfWeek);
- }
- // Call dtfi.GetDayName() here, instead of accessing DayNames property, because we don't
- // want a clone of DayNames, which will hurt perf.
- return dtfi.GetDayName((DayOfWeek)dayOfWeek);
- }
-
- private static string FormatMonth(int month, int repeatCount, DateTimeFormatInfo dtfi)
- {
- Debug.Assert(month >= 1 && month <= 12, "month >=1 && month <= 12");
- if (repeatCount == 3)
- {
- return dtfi.GetAbbreviatedMonthName(month);
- }
- // Call GetMonthName() here, instead of accessing MonthNames property, because we don't
- // want a clone of MonthNames, which will hurt perf.
- return dtfi.GetMonthName(month);
- }
-
- //
- // FormatHebrewMonthName
- //
- // Action: Return the Hebrew month name for the specified DateTime.
- // Returns: The month name string for the specified DateTime.
- // Arguments:
- // time the time to format
- // month The month is the value of HebrewCalendar.GetMonth(time).
- // repeat Return abbreviated month name if repeat=3, or full month name if repeat=4
- // dtfi The DateTimeFormatInfo which uses the Hebrew calendars as its calendar.
- // Exceptions: None.
- //
-
- /* Note:
- If DTFI is using Hebrew calendar, GetMonthName()/GetAbbreviatedMonthName() will return month names like this:
- 1 Hebrew 1st Month
- 2 Hebrew 2nd Month
- .. ...
- 6 Hebrew 6th Month
- 7 Hebrew 6th Month II (used only in a leap year)
- 8 Hebrew 7th Month
- 9 Hebrew 8th Month
- 10 Hebrew 9th Month
- 11 Hebrew 10th Month
- 12 Hebrew 11th Month
- 13 Hebrew 12th Month
-
- Therefore, if we are in a regular year, we have to increment the month name if month is greater or equal to 7.
- */
- private static string FormatHebrewMonthName(DateTime time, int month, int repeatCount, DateTimeFormatInfo dtfi)
- {
- Debug.Assert(repeatCount != 3 || repeatCount != 4, "repeateCount should be 3 or 4");
- if (dtfi.Calendar.IsLeapYear(dtfi.Calendar.GetYear(time)))
- {
- // This month is in a leap year
- return dtfi.InternalGetMonthName(month, MonthNameStyles.LeapYear, repeatCount == 3);
- }
- // This is in a regular year.
- if (month >= 7)
- {
- month++;
- }
- if (repeatCount == 3)
- {
- return dtfi.GetAbbreviatedMonthName(month);
- }
- return dtfi.GetMonthName(month);
- }
-
- //
- // The pos should point to a quote character. This method will
- // append to the result StringBuilder the string enclosed by the quote character.
- //
- internal static int ParseQuoteString(ReadOnlySpan<char> format, int pos, StringBuilder result)
- {
- //
- // NOTE : pos will be the index of the quote character in the 'format' string.
- //
- int formatLen = format.Length;
- int beginPos = pos;
- char quoteChar = format[pos++]; // Get the character used to quote the following string.
-
- bool foundQuote = false;
- while (pos < formatLen)
- {
- char ch = format[pos++];
- if (ch == quoteChar)
- {
- foundQuote = true;
- break;
- }
- else if (ch == '\\')
- {
- // The following are used to support escaped character.
- // Escaped character is also supported in the quoted string.
- // Therefore, someone can use a format like "'minute:' mm\"" to display:
- // minute: 45"
- // because the second double quote is escaped.
- if (pos < formatLen)
- {
- result.Append(format[pos++]);
- }
- else
- {
- //
- // This means that '\' is at the end of the formatting string.
- //
- throw new FormatException(SR.Format_InvalidString);
- }
- }
- else
- {
- result.Append(ch);
- }
- }
-
- if (!foundQuote)
- {
- // Here we can't find the matching quote.
- throw new FormatException(SR.Format(SR.Format_BadQuote, quoteChar));
- }
-
- //
- // Return the character count including the begin/end quote characters and enclosed string.
- //
- return pos - beginPos;
- }
-
- //
- // Get the next character at the index of 'pos' in the 'format' string.
- // Return value of -1 means 'pos' is already at the end of the 'format' string.
- // Otherwise, return value is the int value of the next character.
- //
- internal static int ParseNextChar(ReadOnlySpan<char> format, int pos)
- {
- if (pos >= format.Length - 1)
- {
- return -1;
- }
- return (int)format[pos + 1];
- }
-
- //
- // IsUseGenitiveForm
- //
- // Actions: Check the format to see if we should use genitive month in the formatting.
- // Starting at the position (index) in the (format) string, look back and look ahead to
- // see if there is "d" or "dd". In the case like "d MMMM" or "MMMM dd", we can use
- // genitive form. Genitive form is not used if there is more than two "d".
- // Arguments:
- // format The format string to be scanned.
- // index Where we should start the scanning. This is generally where "M" starts.
- // tokenLen The len of the current pattern character. This indicates how many "M" that we have.
- // patternToMatch The pattern that we want to search. This generally uses "d"
- //
- private static bool IsUseGenitiveForm(ReadOnlySpan<char> format, int index, int tokenLen, char patternToMatch)
- {
- int i;
- int repeat = 0;
- //
- // Look back to see if we can find "d" or "ddd"
- //
-
- // Find first "d".
- for (i = index - 1; i >= 0 && format[i] != patternToMatch; i--) { /*Do nothing here */ }
-
- if (i >= 0)
- {
- // Find a "d", so look back to see how many "d" that we can find.
- while (--i >= 0 && format[i] == patternToMatch)
- {
- repeat++;
- }
- //
- // repeat == 0 means that we have one (patternToMatch)
- // repeat == 1 means that we have two (patternToMatch)
- //
- if (repeat <= 1)
- {
- return true;
- }
- // Note that we can't just stop here. We may find "ddd" while looking back, and we have to look
- // ahead to see if there is "d" or "dd".
- }
-
- //
- // If we can't find "d" or "dd" by looking back, try look ahead.
- //
-
- // Find first "d"
- for (i = index + tokenLen; i < format.Length && format[i] != patternToMatch; i++) { /* Do nothing here */ }
-
- if (i < format.Length)
- {
- repeat = 0;
- // Find a "d", so contine the walk to see how may "d" that we can find.
- while (++i < format.Length && format[i] == patternToMatch)
- {
- repeat++;
- }
- //
- // repeat == 0 means that we have one (patternToMatch)
- // repeat == 1 means that we have two (patternToMatch)
- //
- if (repeat <= 1)
- {
- return true;
- }
- }
- return false;
- }
-
- //
- // FormatCustomized
- //
- // Actions: Format the DateTime instance using the specified format.
- //
- private static StringBuilder FormatCustomized(
- DateTime dateTime, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, TimeSpan offset, StringBuilder? result)
- {
- Calendar cal = dtfi.Calendar;
-
- bool resultBuilderIsPooled = false;
- if (result == null)
- {
- resultBuilderIsPooled = true;
- result = StringBuilderCache.Acquire();
- }
-
- // This is a flag to indicate if we are formatting the dates using Hebrew calendar.
- bool isHebrewCalendar = (cal.ID == CalendarId.HEBREW);
- bool isJapaneseCalendar = (cal.ID == CalendarId.JAPAN);
- // This is a flag to indicate if we are formatting hour/minute/second only.
- bool bTimeOnly = true;
-
- int i = 0;
- int tokenLen, hour12;
-
- while (i < format.Length)
- {
- char ch = format[i];
- int nextChar;
- switch (ch)
- {
- case 'g':
- tokenLen = ParseRepeatPattern(format, i, ch);
- result.Append(dtfi.GetEraName(cal.GetEra(dateTime)));
- break;
- case 'h':
- tokenLen = ParseRepeatPattern(format, i, ch);
- hour12 = dateTime.Hour % 12;
- if (hour12 == 0)
- {
- hour12 = 12;
- }
- FormatDigits(result, hour12, tokenLen);
- break;
- case 'H':
- tokenLen = ParseRepeatPattern(format, i, ch);
- FormatDigits(result, dateTime.Hour, tokenLen);
- break;
- case 'm':
- tokenLen = ParseRepeatPattern(format, i, ch);
- FormatDigits(result, dateTime.Minute, tokenLen);
- break;
- case 's':
- tokenLen = ParseRepeatPattern(format, i, ch);
- FormatDigits(result, dateTime.Second, tokenLen);
- break;
- case 'f':
- case 'F':
- tokenLen = ParseRepeatPattern(format, i, ch);
- if (tokenLen <= MaxSecondsFractionDigits)
- {
- long fraction = (dateTime.Ticks % Calendar.TicksPerSecond);
- fraction /= (long)Math.Pow(10, 7 - tokenLen);
- if (ch == 'f')
- {
- result.AppendSpanFormattable((int)fraction, fixedNumberFormats[tokenLen - 1], CultureInfo.InvariantCulture);
- }
- else
- {
- int effectiveDigits = tokenLen;
- while (effectiveDigits > 0)
- {
- if (fraction % 10 == 0)
- {
- fraction /= 10;
- effectiveDigits--;
- }
- else
- {
- break;
- }
- }
- if (effectiveDigits > 0)
- {
- result.AppendSpanFormattable((int)fraction, fixedNumberFormats[effectiveDigits - 1], CultureInfo.InvariantCulture);
- }
- else
- {
- // No fraction to emit, so see if we should remove decimal also.
- if (result.Length > 0 && result[result.Length - 1] == '.')
- {
- result.Remove(result.Length - 1, 1);
- }
- }
- }
- }
- else
- {
- if (resultBuilderIsPooled)
- {
- StringBuilderCache.Release(result);
- }
- throw new FormatException(SR.Format_InvalidString);
- }
- break;
- case 't':
- tokenLen = ParseRepeatPattern(format, i, ch);
- if (tokenLen == 1)
- {
- if (dateTime.Hour < 12)
- {
- if (dtfi.AMDesignator.Length >= 1)
- {
- result.Append(dtfi.AMDesignator[0]);
- }
- }
- else
- {
- if (dtfi.PMDesignator.Length >= 1)
- {
- result.Append(dtfi.PMDesignator[0]);
- }
- }
- }
- else
- {
- result.Append(dateTime.Hour < 12 ? dtfi.AMDesignator : dtfi.PMDesignator);
- }
- break;
- case 'd':
- //
- // tokenLen == 1 : Day of month as digits with no leading zero.
- // tokenLen == 2 : Day of month as digits with leading zero for single-digit months.
- // tokenLen == 3 : Day of week as a three-letter abbreviation.
- // tokenLen >= 4 : Day of week as its full name.
- //
- tokenLen = ParseRepeatPattern(format, i, ch);
- if (tokenLen <= 2)
- {
- int day = cal.GetDayOfMonth(dateTime);
- if (isHebrewCalendar)
- {
- // For Hebrew calendar, we need to convert numbers to Hebrew text for yyyy, MM, and dd values.
- HebrewFormatDigits(result, day);
- }
- else
- {
- FormatDigits(result, day, tokenLen);
- }
- }
- else
- {
- int dayOfWeek = (int)cal.GetDayOfWeek(dateTime);
- result.Append(FormatDayOfWeek(dayOfWeek, tokenLen, dtfi));
- }
- bTimeOnly = false;
- break;
- case 'M':
- //
- // tokenLen == 1 : Month as digits with no leading zero.
- // tokenLen == 2 : Month as digits with leading zero for single-digit months.
- // tokenLen == 3 : Month as a three-letter abbreviation.
- // tokenLen >= 4 : Month as its full name.
- //
- tokenLen = ParseRepeatPattern(format, i, ch);
- int month = cal.GetMonth(dateTime);
- if (tokenLen <= 2)
- {
- if (isHebrewCalendar)
- {
- // For Hebrew calendar, we need to convert numbers to Hebrew text for yyyy, MM, and dd values.
- HebrewFormatDigits(result, month);
- }
- else
- {
- FormatDigits(result, month, tokenLen);
- }
- }
- else
- {
- if (isHebrewCalendar)
- {
- result.Append(FormatHebrewMonthName(dateTime, month, tokenLen, dtfi));
- }
- else
- {
- if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0)
- {
- result.Append(
- dtfi.InternalGetMonthName(
- month,
- IsUseGenitiveForm(format, i, tokenLen, 'd') ? MonthNameStyles.Genitive : MonthNameStyles.Regular,
- tokenLen == 3));
- }
- else
- {
- result.Append(FormatMonth(month, tokenLen, dtfi));
- }
- }
- }
- bTimeOnly = false;
- break;
- case 'y':
- // Notes about OS behavior:
- // y: Always print (year % 100). No leading zero.
- // yy: Always print (year % 100) with leading zero.
- // yyy/yyyy/yyyyy/... : Print year value. No leading zero.
-
- int year = cal.GetYear(dateTime);
- tokenLen = ParseRepeatPattern(format, i, ch);
- if (isJapaneseCalendar &&
- !LocalAppContextSwitches.FormatJapaneseFirstYearAsANumber &&
- year == 1 &&
- ((i + tokenLen < format.Length && format[i + tokenLen] == DateTimeFormatInfoScanner.CJKYearSuff[0]) ||
- (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);
- }
- else if (cal.ID == CalendarId.HEBREW)
- {
- HebrewFormatDigits(result, year);
- }
- else
- {
- if (tokenLen <= 2)
- {
- FormatDigits(result, year % 100, tokenLen);
- }
- else if (tokenLen <= 16) // FormatDigits has an implicit 16-digit limit
- {
- FormatDigits(result, year, tokenLen, overrideLengthLimit: true);
- }
- else
- {
- result.Append(year.ToString("D" + tokenLen.ToString(), CultureInfo.InvariantCulture));
- }
- }
- bTimeOnly = false;
- break;
- case 'z':
- tokenLen = ParseRepeatPattern(format, i, ch);
- FormatCustomizedTimeZone(dateTime, offset, tokenLen, bTimeOnly, result);
- break;
- case 'K':
- tokenLen = 1;
- FormatCustomizedRoundripTimeZone(dateTime, offset, result);
- break;
- case ':':
- result.Append(dtfi.TimeSeparator);
- tokenLen = 1;
- break;
- case '/':
- result.Append(dtfi.DateSeparator);
- tokenLen = 1;
- break;
- case '\'':
- case '\"':
- tokenLen = ParseQuoteString(format, i, result);
- break;
- case '%':
- // Optional format character.
- // For example, format string "%d" will print day of month
- // without leading zero. Most of the cases, "%" can be ignored.
- nextChar = ParseNextChar(format, i);
- // nextChar will be -1 if we have already reached the end of the format string.
- // Besides, we will not allow "%%" to appear in the pattern.
- if (nextChar >= 0 && nextChar != '%')
- {
- char nextCharChar = (char)nextChar;
- StringBuilder origStringBuilder = FormatCustomized(dateTime, MemoryMarshal.CreateReadOnlySpan<char>(ref nextCharChar, 1), dtfi, offset, result);
- Debug.Assert(ReferenceEquals(origStringBuilder, result));
- tokenLen = 2;
- }
- else
- {
- //
- // This means that '%' is at the end of the format string or
- // "%%" appears in the format string.
- //
- if (resultBuilderIsPooled)
- {
- StringBuilderCache.Release(result);
- }
- throw new FormatException(SR.Format_InvalidString);
- }
- break;
- case '\\':
- // Escaped character. Can be used to insert a character into the format string.
- // For exmple, "\d" will insert the character 'd' into the string.
- //
- // NOTENOTE : we can remove this format character if we enforce the enforced quote
- // character rule.
- // That is, we ask everyone to use single quote or double quote to insert characters,
- // then we can remove this character.
- //
- nextChar = ParseNextChar(format, i);
- if (nextChar >= 0)
- {
- result.Append((char)nextChar);
- tokenLen = 2;
- }
- else
- {
- //
- // This means that '\' is at the end of the formatting string.
- //
- if (resultBuilderIsPooled)
- {
- StringBuilderCache.Release(result);
- }
- throw new FormatException(SR.Format_InvalidString);
- }
- break;
- default:
- // NOTENOTE : we can remove this rule if we enforce the enforced quote
- // character rule.
- // That is, if we ask everyone to use single quote or double quote to insert characters,
- // then we can remove this default block.
- result.Append(ch);
- tokenLen = 1;
- break;
- }
- i += tokenLen;
- }
- return result;
- }
-
- // output the 'z' family of formats, which output a the offset from UTC, e.g. "-07:30"
- private static void FormatCustomizedTimeZone(DateTime dateTime, TimeSpan offset, int tokenLen, bool timeOnly, StringBuilder result)
- {
- // See if the instance already has an offset
- bool dateTimeFormat = (offset == NullOffset);
- if (dateTimeFormat)
- {
- // No offset. The instance is a DateTime and the output should be the local time zone
-
- if (timeOnly && dateTime.Ticks < Calendar.TicksPerDay)
- {
- // For time only format and a time only input, the time offset on 0001/01/01 is less
- // accurate than the system's current offset because of daylight saving time.
- offset = TimeZoneInfo.GetLocalUtcOffset(DateTime.Now, TimeZoneInfoOptions.NoThrowOnInvalidTime);
- }
- else if (dateTime.Kind == DateTimeKind.Utc)
- {
- offset = TimeSpan.Zero;
- }
- else
- {
- offset = TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
- }
- }
- if (offset >= TimeSpan.Zero)
- {
- result.Append('+');
- }
- else
- {
- result.Append('-');
- // get a positive offset, so that you don't need a separate code path for the negative numbers.
- offset = offset.Negate();
- }
-
- if (tokenLen <= 1)
- {
- // 'z' format e.g "-7"
- result.AppendFormat(CultureInfo.InvariantCulture, "{0:0}", offset.Hours);
- }
- else
- {
- // 'zz' or longer format e.g "-07"
- result.AppendFormat(CultureInfo.InvariantCulture, "{0:00}", offset.Hours);
- if (tokenLen >= 3)
- {
- // 'zzz*' or longer format e.g "-07:30"
- result.AppendFormat(CultureInfo.InvariantCulture, ":{0:00}", offset.Minutes);
- }
- }
- }
-
- // output the 'K' format, which is for round-tripping the data
- private static void FormatCustomizedRoundripTimeZone(DateTime dateTime, TimeSpan offset, StringBuilder result)
- {
- // The objective of this format is to round trip the data in the type
- // For DateTime it should round-trip the Kind value and preserve the time zone.
- // DateTimeOffset instance, it should do so by using the internal time zone.
-
- if (offset == NullOffset)
- {
- // source is a date time, so behavior depends on the kind.
- switch (dateTime.Kind)
- {
- case DateTimeKind.Local:
- // This should output the local offset, e.g. "-07:30"
- offset = TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
- // fall through to shared time zone output code
- break;
- case DateTimeKind.Utc:
- // The 'Z' constant is a marker for a UTC date
- result.Append("Z");
- return;
- default:
- // If the kind is unspecified, we output nothing here
- return;
- }
- }
- if (offset >= TimeSpan.Zero)
- {
- result.Append('+');
- }
- else
- {
- result.Append('-');
- // get a positive offset, so that you don't need a separate code path for the negative numbers.
- offset = offset.Negate();
- }
-
- Append2DigitNumber(result, offset.Hours);
- result.Append(':');
- Append2DigitNumber(result, offset.Minutes);
- }
-
- private static void Append2DigitNumber(StringBuilder result, int val)
- {
- result.Append((char)('0' + (val / 10)));
- result.Append((char)('0' + (val % 10)));
- }
-
- internal static string GetRealFormat(ReadOnlySpan<char> format, DateTimeFormatInfo dtfi)
- {
- string realFormat;
-
- switch (format[0])
- {
- case 'd': // Short Date
- realFormat = dtfi.ShortDatePattern;
- break;
- case 'D': // Long Date
- realFormat = dtfi.LongDatePattern;
- break;
- case 'f': // Full (long date + short time)
- realFormat = dtfi.LongDatePattern + " " + dtfi.ShortTimePattern;
- break;
- case 'F': // Full (long date + long time)
- realFormat = dtfi.FullDateTimePattern;
- break;
- case 'g': // General (short date + short time)
- realFormat = dtfi.GeneralShortTimePattern;
- break;
- case 'G': // General (short date + long time)
- realFormat = dtfi.GeneralLongTimePattern;
- break;
- case 'm':
- case 'M': // Month/Day Date
- realFormat = dtfi.MonthDayPattern;
- break;
- case 'o':
- case 'O':
- realFormat = RoundtripFormat;
- break;
- case 'r':
- case 'R': // RFC 1123 Standard
- realFormat = dtfi.RFC1123Pattern;
- break;
- case 's': // Sortable without Time Zone Info
- realFormat = dtfi.SortableDateTimePattern;
- break;
- case 't': // Short Time
- realFormat = dtfi.ShortTimePattern;
- break;
- case 'T': // Long Time
- realFormat = dtfi.LongTimePattern;
- break;
- case 'u': // Universal with Sortable format
- realFormat = dtfi.UniversalSortableDateTimePattern;
- break;
- case 'U': // Universal with Full (long date + long time) format
- realFormat = dtfi.FullDateTimePattern;
- break;
- case 'y':
- case 'Y': // Year/Month Date
- realFormat = dtfi.YearMonthPattern;
- break;
- default:
- throw new FormatException(SR.Format_InvalidString);
- }
- return realFormat;
- }
-
- // Expand a pre-defined format string (like "D" for long date) to the real format that
- // we are going to use in the date time parsing.
- // This method also convert the dateTime if necessary (e.g. when the format is in Universal time),
- // and change dtfi if necessary (e.g. when the format should use invariant culture).
- //
- private static string ExpandPredefinedFormat(ReadOnlySpan<char> format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, ref TimeSpan offset)
- {
- switch (format[0])
- {
- case 'o':
- case 'O': // Round trip format
- dtfi = DateTimeFormatInfo.InvariantInfo;
- break;
- case 'r':
- case 'R': // RFC 1123 Standard
- case 'u': // Universal time in sortable format.
- if (offset != NullOffset)
- {
- // Convert to UTC invariants mean this will be in range
- dateTime -= offset;
- }
- dtfi = DateTimeFormatInfo.InvariantInfo;
- break;
- case 's': // Sortable without Time Zone Info
- dtfi = DateTimeFormatInfo.InvariantInfo;
- break;
- case 'U': // Universal time in culture dependent format.
- if (offset != NullOffset)
- {
- // This format is not supported by DateTimeOffset
- throw new FormatException(SR.Format_InvalidString);
- }
- // Universal time is always in Greogrian calendar.
- //
- // Change the Calendar to be Gregorian Calendar.
- //
- dtfi = (DateTimeFormatInfo)dtfi.Clone();
- if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
- {
- dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
- }
- dateTime = dateTime.ToUniversalTime();
- break;
- }
- return GetRealFormat(format, dtfi);
- }
-
- internal static string Format(DateTime dateTime, string? format, IFormatProvider? provider)
- {
- return Format(dateTime, format, provider, NullOffset);
- }
-
- internal static string Format(DateTime dateTime, string? format, IFormatProvider? provider, TimeSpan offset)
- {
- if (format != null && format.Length == 1)
- {
- // Optimize for these standard formats that are not affected by culture.
- switch (format[0])
- {
- // Round trip format
- case 'o':
- case 'O':
- const int MinFormatOLength = 27, MaxFormatOLength = 33;
- Span<char> span = stackalloc char[MaxFormatOLength];
- TryFormatO(dateTime, offset, span, out int ochars);
- Debug.Assert(ochars >= MinFormatOLength && ochars <= MaxFormatOLength);
- return span.Slice(0, ochars).ToString();
-
- // RFC1123
- case 'r':
- case 'R':
- const int FormatRLength = 29;
- string str = string.FastAllocateString(FormatRLength);
- TryFormatR(dateTime, offset, new Span<char>(ref str.GetRawStringData(), str.Length), out int rchars);
- Debug.Assert(rchars == str.Length);
- return str;
- }
- }
-
- DateTimeFormatInfo dtfi = DateTimeFormatInfo.GetInstance(provider);
- return StringBuilderCache.GetStringAndRelease(FormatStringBuilder(dateTime, format, dtfi, offset));
- }
-
- internal static bool TryFormat(DateTime dateTime, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
- TryFormat(dateTime, destination, out charsWritten, format, provider, NullOffset);
-
- internal static bool TryFormat(DateTime dateTime, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider, TimeSpan offset)
- {
- if (format.Length == 1)
- {
- // Optimize for these standard formats that are not affected by culture.
- switch (format[0])
- {
- // Round trip format
- case 'o':
- case 'O':
- return TryFormatO(dateTime, offset, destination, out charsWritten);
-
- // RFC1123
- case 'r':
- case 'R':
- return TryFormatR(dateTime, offset, destination, out charsWritten);
- }
- }
-
- DateTimeFormatInfo dtfi = DateTimeFormatInfo.GetInstance(provider);
- StringBuilder sb = FormatStringBuilder(dateTime, format, dtfi, offset);
-
- bool success = sb.Length <= destination.Length;
- if (success)
- {
- sb.CopyTo(0, destination, sb.Length);
- charsWritten = sb.Length;
- }
- else
- {
- charsWritten = 0;
- }
-
- StringBuilderCache.Release(sb);
- return success;
- }
-
- private static StringBuilder FormatStringBuilder(DateTime dateTime, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, TimeSpan offset)
- {
- Debug.Assert(dtfi != null);
- if (format.Length == 0)
- {
- bool timeOnlySpecialCase = false;
- if (dateTime.Ticks < Calendar.TicksPerDay)
- {
- // If the time is less than 1 day, consider it as time of day.
- // Just print out the short time format.
- //
- // This is a workaround for VB, since they use ticks less then one day to be
- // time of day. In cultures which use calendar other than Gregorian calendar, these
- // alternative calendar may not support ticks less than a day.
- // For example, Japanese calendar only supports date after 1868/9/8.
- // This will pose a problem when people in VB get the time of day, and use it
- // to call ToString(), which will use the general format (short date + long time).
- // Since Japanese calendar does not support Gregorian year 0001, an exception will be
- // thrown when we try to get the Japanese year for Gregorian year 0001.
- // Therefore, the workaround allows them to call ToString() for time of day from a DateTime by
- // formatting as ISO 8601 format.
- switch (dtfi.Calendar.ID)
- {
- case CalendarId.JAPAN:
- case CalendarId.TAIWAN:
- case CalendarId.HIJRI:
- case CalendarId.HEBREW:
- case CalendarId.JULIAN:
- case CalendarId.UMALQURA:
- case CalendarId.PERSIAN:
- timeOnlySpecialCase = true;
- dtfi = DateTimeFormatInfo.InvariantInfo;
- break;
- }
- }
- if (offset == NullOffset)
- {
- // Default DateTime.ToString case.
- format = timeOnlySpecialCase ? "s" : "G";
- }
- else
- {
- // Default DateTimeOffset.ToString case.
- format = timeOnlySpecialCase ? RoundtripDateTimeUnfixed : dtfi.DateTimeOffsetPattern;
- }
- }
-
- if (format.Length == 1)
- {
- format = ExpandPredefinedFormat(format, ref dateTime, ref dtfi, ref offset);
- }
-
- return FormatCustomized(dateTime, format, dtfi, offset, result: null);
- }
-
- // Roundtrippable format. One of
- // 012345678901234567890123456789012
- // ---------------------------------
- // 2017-06-12T05:30:45.7680000-07:00
- // 2017-06-12T05:30:45.7680000Z (Z is short for "+00:00" but also distinguishes DateTimeKind.Utc from DateTimeKind.Local)
- // 2017-06-12T05:30:45.7680000 (interpreted as local time wrt to current time zone)
- private static bool TryFormatO(DateTime dateTime, TimeSpan offset, Span<char> destination, out int charsWritten)
- {
- const int MinimumBytesNeeded = 27;
-
- int charsRequired = MinimumBytesNeeded;
- DateTimeKind kind = DateTimeKind.Local;
-
- if (offset == NullOffset)
- {
- kind = dateTime.Kind;
- if (kind == DateTimeKind.Local)
- {
- offset = TimeZoneInfo.Local.GetUtcOffset(dateTime);
- charsRequired += 6;
- }
- else if (kind == DateTimeKind.Utc)
- {
- charsRequired++;
- }
- }
- else
- {
- charsRequired += 6;
- }
-
- if (destination.Length < charsRequired)
- {
- charsWritten = 0;
- return false;
- }
- charsWritten = charsRequired;
-
- // Hoist most of the bounds checks on destination.
- { _ = destination[MinimumBytesNeeded - 1]; }
-
- WriteFourDecimalDigits((uint)dateTime.Year, destination, 0);
- destination[4] = '-';
- WriteTwoDecimalDigits((uint)dateTime.Month, destination, 5);
- destination[7] = '-';
- WriteTwoDecimalDigits((uint)dateTime.Day, destination, 8);
- destination[10] = 'T';
- WriteTwoDecimalDigits((uint)dateTime.Hour, destination, 11);
- destination[13] = ':';
- WriteTwoDecimalDigits((uint)dateTime.Minute, destination, 14);
- destination[16] = ':';
- WriteTwoDecimalDigits((uint)dateTime.Second, destination, 17);
- destination[19] = '.';
- WriteDigits((uint)((ulong)dateTime.Ticks % (ulong)TimeSpan.TicksPerSecond), destination.Slice(20, 7));
-
- if (kind == DateTimeKind.Local)
- {
- char sign;
- if (offset < default(TimeSpan) /* a "const" version of TimeSpan.Zero */)
- {
- sign = '-';
- offset = TimeSpan.FromTicks(-offset.Ticks);
- }
- else
- {
- sign = '+';
- }
-
- // Writing the value backward allows the JIT to optimize by
- // performing a single bounds check against buffer.
- WriteTwoDecimalDigits((uint)offset.Minutes, destination, 31);
- destination[30] = ':';
- WriteTwoDecimalDigits((uint)offset.Hours, destination, 28);
- destination[27] = sign;
- }
- else if (kind == DateTimeKind.Utc)
- {
- destination[27] = 'Z';
- }
-
- return true;
- }
-
- // Rfc1123
- // 01234567890123456789012345678
- // -----------------------------
- // Tue, 03 Jan 2017 08:08:05 GMT
- private static bool TryFormatR(DateTime dateTime, TimeSpan offset, Span<char> destination, out int charsWritten)
- {
- // Writing the check in this fashion elides all bounds checks on 'destination'
- // for the remainder of the method.
- if (28 >= (uint)destination.Length)
- {
- charsWritten = 0;
- return false;
- }
-
- if (offset != NullOffset)
- {
- // Convert to UTC invariants.
- dateTime -= offset;
- }
-
- dateTime.GetDatePart(out int year, out int month, out int day);
-
- string dayAbbrev = InvariantAbbreviatedDayNames[(int)dateTime.DayOfWeek];
- Debug.Assert(dayAbbrev.Length == 3);
-
- string monthAbbrev = InvariantAbbreviatedMonthNames[month - 1];
- Debug.Assert(monthAbbrev.Length == 3);
-
- destination[0] = dayAbbrev[0];
- destination[1] = dayAbbrev[1];
- destination[2] = dayAbbrev[2];
- destination[3] = ',';
- destination[4] = ' ';
- WriteTwoDecimalDigits((uint)day, destination, 5);
- destination[7] = ' ';
- destination[8] = monthAbbrev[0];
- destination[9] = monthAbbrev[1];
- destination[10] = monthAbbrev[2];
- destination[11] = ' ';
- WriteFourDecimalDigits((uint)year, destination, 12);
- destination[16] = ' ';
- WriteTwoDecimalDigits((uint)dateTime.Hour, destination, 17);
- destination[19] = ':';
- WriteTwoDecimalDigits((uint)dateTime.Minute, destination, 20);
- destination[22] = ':';
- WriteTwoDecimalDigits((uint)dateTime.Second, destination, 23);
- destination[25] = ' ';
- destination[26] = 'G';
- destination[27] = 'M';
- destination[28] = 'T';
-
- charsWritten = 29;
- return true;
- }
-
- /// <summary>
- /// Writes a value [ 00 .. 99 ] to the buffer starting at the specified offset.
- /// This method performs best when the starting index is a constant literal.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void WriteTwoDecimalDigits(uint value, Span<char> destination, int offset)
- {
- Debug.Assert(value <= 99);
-
- uint temp = '0' + value;
- value /= 10;
- destination[offset + 1] = (char)(temp - (value * 10));
- destination[offset] = (char)('0' + value);
- }
-
- /// <summary>
- /// Writes a value [ 0000 .. 9999 ] to the buffer starting at the specified offset.
- /// This method performs best when the starting index is a constant literal.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void WriteFourDecimalDigits(uint value, Span<char> buffer, int startingIndex = 0)
- {
- Debug.Assert(value <= 9999);
-
- uint temp = '0' + value;
- value /= 10;
- buffer[startingIndex + 3] = (char)(temp - (value * 10));
-
- temp = '0' + value;
- value /= 10;
- buffer[startingIndex + 2] = (char)(temp - (value * 10));
-
- temp = '0' + value;
- value /= 10;
- buffer[startingIndex + 1] = (char)(temp - (value * 10));
-
- buffer[startingIndex] = (char)('0' + value);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void WriteDigits(ulong value, Span<char> buffer)
- {
- // We can mutate the 'value' parameter since it's a copy-by-value local.
- // It'll be used to represent the value left over after each division by 10.
-
- for (int i = buffer.Length - 1; i >= 1; i--)
- {
- ulong temp = '0' + value;
- value /= 10;
- buffer[i] = (char)(temp - (value * 10));
- }
-
- Debug.Assert(value < 10);
- buffer[0] = (char)('0' + value);
- }
-
- internal static string[] GetAllDateTimes(DateTime dateTime, char format, DateTimeFormatInfo dtfi)
- {
- Debug.Assert(dtfi != null);
- string[] allFormats;
- string[] results;
-
- switch (format)
- {
- case 'd':
- case 'D':
- case 'f':
- case 'F':
- case 'g':
- case 'G':
- case 'm':
- case 'M':
- case 't':
- case 'T':
- case 'y':
- case 'Y':
- allFormats = dtfi.GetAllDateTimePatterns(format);
- results = new string[allFormats.Length];
- for (int i = 0; i < allFormats.Length; i++)
- {
- results[i] = Format(dateTime, allFormats[i], dtfi);
- }
- break;
- case 'U':
- DateTime universalTime = dateTime.ToUniversalTime();
- allFormats = dtfi.GetAllDateTimePatterns(format);
- results = new string[allFormats.Length];
- for (int i = 0; i < allFormats.Length; i++)
- {
- results[i] = Format(universalTime, allFormats[i], dtfi);
- }
- break;
- //
- // The following ones are special cases because these patterns are read-only in
- // DateTimeFormatInfo.
- //
- case 'r':
- case 'R':
- case 'o':
- case 'O':
- case 's':
- case 'u':
- results = new string[] { Format(dateTime, char.ToString(format), dtfi) };
- break;
- default:
- throw new FormatException(SR.Format_InvalidString);
- }
- return results;
- }
-
- internal static string[] GetAllDateTimes(DateTime dateTime, DateTimeFormatInfo dtfi)
- {
- List<string> results = new List<string>(DEFAULT_ALL_DATETIMES_SIZE);
-
- for (int i = 0; i < allStandardFormats.Length; i++)
- {
- string[] strings = GetAllDateTimes(dateTime, allStandardFormats[i], dtfi);
- for (int j = 0; j < strings.Length; j++)
- {
- results.Add(strings[j]);
- }
- }
-
- return results.ToArray();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfo.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfo.cs
deleted file mode 100644
index 2989153d62f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfo.cs
+++ /dev/null
@@ -1,2604 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Globalization
-{
- /// <summary>
- /// Flags used to indicate different styles of month names.
- /// This is an internal flag used by internalGetMonthName().
- /// Use flag here in case that we need to provide a combination of these styles
- /// (such as month name of a leap year in genitive form. Not likely for now,
- /// but would like to keep the option open).
- /// </summary>
-
- [Flags]
- internal enum MonthNameStyles
- {
- Regular = 0x00000000,
- Genitive = 0x00000001,
- LeapYear = 0x00000002,
- }
-
- /// <summary>
- /// Flags used to indicate special rule used in parsing/formatting
- /// for a specific DateTimeFormatInfo instance.
- /// This is an internal flag.
- ///
- /// This flag is different from MonthNameStyles because this flag
- /// can be expanded to accommodate parsing behaviors like CJK month names
- /// or alternative month names, etc.
- /// </summary>
- [Flags]
- internal enum DateTimeFormatFlags
- {
- None = 0x00000000,
- UseGenitiveMonth = 0x00000001,
- UseLeapYearMonth = 0x00000002,
- UseSpacesInMonthNames = 0x00000004, // Has spaces or non-breaking space in the month names.
- UseHebrewRule = 0x00000008, // Format/Parse using the Hebrew calendar rule.
- UseSpacesInDayNames = 0x00000010, // Has spaces or non-breaking space in the day names.
- UseDigitPrefixInTokens = 0x00000020, // Has token starting with numbers.
-
- NotInitialized = -1,
- }
-
- public sealed class DateTimeFormatInfo : IFormatProvider, ICloneable
- {
- // cache for the invariant culture.
- // invariantInfo is constant irrespective of your current culture.
- private static volatile DateTimeFormatInfo? s_invariantInfo;
-
- // an index which points to a record in Culture Data Table.
- private readonly CultureData _cultureData;
-
- // The culture name used to create this DTFI.
- private string? _name = null;
-
- // The language name of the culture used to create this DTFI.
- private string? _langName = null;
-
- // CompareInfo usually used by the parser.
- private CompareInfo? _compareInfo = null;
-
- // Culture matches current DTFI. mainly used for string comparisons during parsing.
- private CultureInfo? _cultureInfo = null;
-
- private string? amDesignator = null;
- private string? pmDesignator = null;
-
- private string? dateSeparator = null; // derived from short date (whidbey expects, arrowhead doesn't)
-
- private string? generalShortTimePattern = null; // short date + short time (whidbey expects, arrowhead doesn't)
-
- private string? generalLongTimePattern = null; // short date + long time (whidbey expects, arrowhead doesn't)
-
- private string? timeSeparator = null; // derived from long time (whidbey expects, arrowhead doesn't)
- private string? monthDayPattern = null;
- private string? dateTimeOffsetPattern = null;
-
- private const string rfc1123Pattern = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'";
-
- // The sortable pattern is based on ISO 8601.
- private const string sortableDateTimePattern = "yyyy'-'MM'-'dd'T'HH':'mm':'ss";
- private const string universalSortableDateTimePattern = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'";
-
- private Calendar calendar = null!; // initialized in helper called by ctors
-
- private int firstDayOfWeek = -1;
- private int calendarWeekRule = -1;
-
- private string? fullDateTimePattern = null; // long date + long time (whidbey expects, arrowhead doesn't)
-
- private string[]? abbreviatedDayNames = null;
-
- private string[]? m_superShortDayNames = null;
-
- private string[]? dayNames = null;
- private string[]? abbreviatedMonthNames = null;
- private string[]? monthNames = null;
-
- // Cache the genitive month names that we retrieve from the data table.
-
- private string[]? genitiveMonthNames = null;
-
- // Cache the abbreviated genitive month names that we retrieve from the data table.
-
- private string[]? m_genitiveAbbreviatedMonthNames = null;
-
- // Cache the month names of a leap year that we retrieve from the data table.
- private string[]? leapYearMonthNames = null;
-
- // For our "patterns" arrays we have 2 variables, a string and a string[]
- //
- // The string[] contains the list of patterns, EXCEPT the default may not be included.
- // The string contains the default pattern.
- // When we initially construct our string[], we set the string to string[0]
-
- // The "default" Date/time patterns
- private string? longDatePattern = null;
- private string? shortDatePattern = null;
- private string? yearMonthPattern = null;
- private string? longTimePattern = null;
- private string? shortTimePattern = null;
-
- private string[]? allYearMonthPatterns = null;
-
- private string[]? allShortDatePatterns = null;
- private string[]? allLongDatePatterns = null;
- private string[]? allShortTimePatterns = null;
- private string[]? allLongTimePatterns = null;
-
- // Cache the era names for this DateTimeFormatInfo instance.
- private string[]? m_eraNames = null;
- private string[]? m_abbrevEraNames = null;
- private string[]? m_abbrevEnglishEraNames = null;
-
- private CalendarId[]? optionalCalendars = null;
-
- private const int DEFAULT_ALL_DATETIMES_SIZE = 132;
-
- // CultureInfo updates this
- internal bool _isReadOnly = false;
-
- // This flag gives hints about if formatting/parsing should perform special code path for things like
- // genitive form or leap year month names.
-
- private DateTimeFormatFlags formatFlags = DateTimeFormatFlags.NotInitialized;
-
- private string CultureName => _name ??= _cultureData.CultureName;
-
- private CultureInfo Culture => _cultureInfo ??= CultureInfo.GetCultureInfo(CultureName);
-
- private string LanguageName => _langName ??= _cultureData.TwoLetterISOLanguageName;
-
- /// <summary>
- /// Create an array of string which contains the abbreviated day names.
- /// </summary>
- private string[] InternalGetAbbreviatedDayOfWeekNames() => abbreviatedDayNames ?? InternalGetAbbreviatedDayOfWeekNamesCore();
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private string[] InternalGetAbbreviatedDayOfWeekNamesCore()
- {
- // Get the abbreviated day names for our current calendar
- abbreviatedDayNames = _cultureData.AbbreviatedDayNames(Calendar.ID);
- Debug.Assert(abbreviatedDayNames.Length == 7, "[DateTimeFormatInfo.GetAbbreviatedDayOfWeekNames] Expected 7 day names in a week");
- return abbreviatedDayNames;
- }
-
- /// <summary>
- /// Returns the string array of the one-letter day of week names.
- /// </summary>
- private string[] InternalGetSuperShortDayNames() => m_superShortDayNames ?? InternalGetSuperShortDayNamesCore();
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private string[] InternalGetSuperShortDayNamesCore()
- {
- // Get the super short day names for our current calendar
- m_superShortDayNames = _cultureData.SuperShortDayNames(Calendar.ID);
- Debug.Assert(m_superShortDayNames.Length == 7, "[DateTimeFormatInfo.InternalGetSuperShortDayNames] Expected 7 day names in a week");
- return m_superShortDayNames;
- }
-
- /// <summary>
- /// Create an array of string which contains the day names.
- /// </summary>
- private string[] InternalGetDayOfWeekNames() => dayNames ?? InternalGetDayOfWeekNamesCore();
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private string[] InternalGetDayOfWeekNamesCore()
- {
- // Get the day names for our current calendar
- dayNames = _cultureData.DayNames(Calendar.ID);
- Debug.Assert(dayNames.Length == 7, "[DateTimeFormatInfo.GetDayOfWeekNames] Expected 7 day names in a week");
- return dayNames;
- }
-
- /// <summary>
- /// Create an array of string which contains the abbreviated month names.
- /// </summary>
- private string[] InternalGetAbbreviatedMonthNames() => abbreviatedMonthNames ?? InternalGetAbbreviatedMonthNamesCore();
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private string[] InternalGetAbbreviatedMonthNamesCore()
- {
- // Get the month names for our current calendar
- abbreviatedMonthNames = _cultureData.AbbreviatedMonthNames(Calendar.ID);
- Debug.Assert(abbreviatedMonthNames.Length == 12 || abbreviatedMonthNames.Length == 13,
- "[DateTimeFormatInfo.GetAbbreviatedMonthNames] Expected 12 or 13 month names in a year");
- return abbreviatedMonthNames;
- }
-
- /// <summary>
- /// Create an array of string which contains the month names.
- /// </summary>
- private string[] InternalGetMonthNames() => monthNames ?? internalGetMonthNamesCore();
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private string[] internalGetMonthNamesCore()
- {
- // Get the month names for our current calendar
- monthNames = _cultureData.MonthNames(Calendar.ID);
- Debug.Assert(monthNames.Length == 12 || monthNames.Length == 13,
- "[DateTimeFormatInfo.GetMonthNames] Expected 12 or 13 month names in a year");
- return monthNames;
- }
-
- // Invariant DateTimeFormatInfo doesn't have user-overriden values
- // Default calendar is gregorian
- public DateTimeFormatInfo()
- : this(CultureInfo.InvariantCulture._cultureData, GregorianCalendar.GetDefaultInstance())
- {
- }
-
- internal DateTimeFormatInfo(CultureData cultureData, Calendar cal)
- {
- Debug.Assert(cultureData != null);
- Debug.Assert(cal != null);
-
- // Remember our culture
- _cultureData = cultureData;
-
- Calendar = cal;
- }
-
- private void InitializeOverridableProperties(CultureData cultureData, CalendarId calendarId)
- {
- Debug.Assert(cultureData != null);
- Debug.Assert(calendarId != CalendarId.UNINITIALIZED_VALUE, "[DateTimeFormatInfo.Populate] Expected initalized calendarId");
-
- if (firstDayOfWeek == -1)
- {
- firstDayOfWeek = cultureData.FirstDayOfWeek;
- }
- if (calendarWeekRule == -1)
- {
- calendarWeekRule = cultureData.CalendarWeekRule;
- }
-
- if (amDesignator == null)
- {
- amDesignator = cultureData.AMDesignator;
- }
- if (pmDesignator == null)
- {
- pmDesignator = cultureData.PMDesignator;
- }
- if (timeSeparator == null)
- {
- timeSeparator = cultureData.TimeSeparator;
- }
- if (dateSeparator == null)
- {
- dateSeparator = cultureData.DateSeparator(calendarId);
- }
-
- allLongTimePatterns = _cultureData.LongTimes;
- Debug.Assert(allLongTimePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some long time patterns");
-
- allShortTimePatterns = _cultureData.ShortTimes;
- Debug.Assert(allShortTimePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some short time patterns");
-
- allLongDatePatterns = cultureData.LongDates(calendarId);
- Debug.Assert(allLongDatePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some long date patterns");
-
- allShortDatePatterns = cultureData.ShortDates(calendarId);
- Debug.Assert(allShortDatePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some short date patterns");
-
- allYearMonthPatterns = cultureData.YearMonths(calendarId);
- Debug.Assert(allYearMonthPatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some year month patterns");
- }
-
- /// <summary>
- /// Returns a default DateTimeFormatInfo that will be universally
- /// supported and constant irrespective of the current culture.
- /// </summary>
- public static DateTimeFormatInfo InvariantInfo
- {
- get
- {
- if (s_invariantInfo == null)
- {
- DateTimeFormatInfo info = new DateTimeFormatInfo();
- info.Calendar.SetReadOnlyState(true);
- info._isReadOnly = true;
- s_invariantInfo = info;
- }
- return s_invariantInfo;
- }
- }
-
- /// <summary>
- /// Returns the current culture's DateTimeFormatInfo.
- /// </summary>
- public static DateTimeFormatInfo CurrentInfo
- {
- get
- {
- System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CurrentCulture;
- if (!culture._isInherited)
- {
- DateTimeFormatInfo? info = culture._dateTimeInfo;
- if (info != null)
- {
- return info;
- }
- }
- return (DateTimeFormatInfo)culture.GetFormat(typeof(DateTimeFormatInfo))!;
- }
- }
-
- public static DateTimeFormatInfo GetInstance(IFormatProvider? provider) =>
- provider == null ? CurrentInfo :
- provider is CultureInfo cultureProvider && !cultureProvider._isInherited ? cultureProvider.DateTimeFormat :
- provider is DateTimeFormatInfo info ? info :
- provider.GetFormat(typeof(DateTimeFormatInfo)) is DateTimeFormatInfo info2 ? info2 :
- CurrentInfo; // Couldn't get anything, just use currentInfo as fallback
-
- public object? GetFormat(Type? formatType)
- {
- return formatType == typeof(DateTimeFormatInfo) ? this : null;
- }
-
- public object Clone()
- {
- DateTimeFormatInfo n = (DateTimeFormatInfo)MemberwiseClone();
- // We can use the data member calendar in the setter, instead of the property Calendar,
- // since the cloned copy should have the same state as the original copy.
- n.calendar = (Calendar)Calendar.Clone();
- n._isReadOnly = false;
- return n;
- }
-
- public string AMDesignator
- {
- get
- {
- if (amDesignator == null)
- {
- amDesignator = _cultureData.AMDesignator;
- }
-
- Debug.Assert(amDesignator != null, "DateTimeFormatInfo.AMDesignator, amDesignator != null");
- return amDesignator;
- }
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- ClearTokenHashTable();
- amDesignator = value;
- }
- }
-
- public Calendar Calendar
- {
- get
- {
- Debug.Assert(calendar != null, "DateTimeFormatInfo.Calendar: calendar != null");
- return calendar;
- }
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- if (value == calendar)
- {
- return;
- }
-
- for (int i = 0; i < OptionalCalendars.Length; i++)
- {
- if (OptionalCalendars[i] == value.ID)
- {
- // We can use this one, so do so.
- // Clean related properties if we already had a calendar set
- if (calendar != null)
- {
- // clean related properties which are affected by the calendar setting,
- // so that they will be refreshed when they are accessed next time.
- // These properites are in the order as appearing in calendar.xml.
- m_eraNames = null;
- m_abbrevEraNames = null;
- m_abbrevEnglishEraNames = null;
-
- monthDayPattern = null;
-
- dayNames = null;
- abbreviatedDayNames = null;
- m_superShortDayNames = null;
- monthNames = null;
- abbreviatedMonthNames = null;
- genitiveMonthNames = null;
- m_genitiveAbbreviatedMonthNames = null;
- leapYearMonthNames = null;
- formatFlags = DateTimeFormatFlags.NotInitialized;
-
- allShortDatePatterns = null;
- allLongDatePatterns = null;
- allYearMonthPatterns = null;
- dateTimeOffsetPattern = null;
-
- // The defaults need reset as well:
- longDatePattern = null;
- shortDatePattern = null;
- yearMonthPattern = null;
-
- // These properies are not in the OS data, but they are dependent on the values like shortDatePattern.
- fullDateTimePattern = null; // Long date + long time
- generalShortTimePattern = null; // short date + short time
- generalLongTimePattern = null; // short date + long time
-
- // Derived item that changes
- dateSeparator = null;
-
- // We don't need to do these because they are not changed by changing calendar
- // amDesignator
- // pmDesignator
- // timeSeparator
- // longTimePattern
- // firstDayOfWeek
- // calendarWeekRule
-
- // remember to reload tokens
- ClearTokenHashTable();
- }
-
- // Remember the new calendar
- calendar = value;
- InitializeOverridableProperties(_cultureData, calendar.ID);
-
- // We succeeded, return
- return;
- }
- }
-
- // The assigned calendar is not a valid calendar for this culture, throw
- throw new ArgumentOutOfRangeException(nameof(value), value, SR.Argument_InvalidCalendar);
- }
- }
-
- private CalendarId[] OptionalCalendars => optionalCalendars ??= _cultureData.CalendarIds;
-
- /// <summary>
- /// Get the era value by parsing the name of the era.
- /// </summary>
- public int GetEra(string eraName)
- {
- if (eraName == null)
- {
- throw new ArgumentNullException(nameof(eraName));
- }
-
- // The Era Name and Abbreviated Era Name
- // for Taiwan Calendar on non-Taiwan SKU returns empty string (which
- // would be matched below) but we don't want the empty string to give
- // us an Era number
- // confer 85900 DTFI.GetEra("") should fail on all cultures
- if (eraName.Length == 0)
- {
- return -1;
- }
-
- // The following is based on the assumption that the era value is starting from 1, and has a
- // serial values.
- // If that ever changes, the code has to be changed.
-
- // The calls to String.Compare should use the current culture for the string comparisons, but the
- // invariant culture when comparing against the english names.
- for (int i = 0; i < EraNames.Length; i++)
- {
- // Compare the era name in a case-insensitive way for the appropriate culture.
- if (m_eraNames![i].Length > 0)
- {
- if (Culture.CompareInfo.Compare(eraName, m_eraNames[i], CompareOptions.IgnoreCase) == 0)
- {
- return i + 1;
- }
- }
- }
- for (int i = 0; i < AbbreviatedEraNames.Length; i++)
- {
- // Compare the abbreviated era name in a case-insensitive way for the appropriate culture.
- if (Culture.CompareInfo.Compare(eraName, m_abbrevEraNames![i], CompareOptions.IgnoreCase) == 0)
- {
- return i + 1;
- }
- }
- for (int i = 0; i < AbbreviatedEnglishEraNames.Length; i++)
- {
- // this comparison should use the InvariantCulture. The English name could have linguistically
- // interesting characters.
- if (CompareInfo.Invariant.Compare(eraName, m_abbrevEnglishEraNames![i], CompareOptions.IgnoreCase) == 0)
- {
- return i + 1;
- }
- }
- return -1;
- }
-
- internal string[] EraNames => m_eraNames ??= _cultureData.EraNames(Calendar.ID);
-
- /// <summary>
- /// Get the name of the era for the specified era value.
- /// Era names are 1 indexed
- /// </summary>
- public string GetEraName(int era)
- {
- if (era == Calendar.CurrentEra)
- {
- era = Calendar.CurrentEraValue;
- }
-
- // The following is based on the assumption that the era value is starting from 1, and has a
- // serial values.
- // If that ever changes, the code has to be changed.
- if ((--era) < EraNames.Length && (era >= 0))
- {
- return m_eraNames![era];
- }
-
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
-
- internal string[] AbbreviatedEraNames => m_abbrevEraNames ??= _cultureData.AbbrevEraNames(Calendar.ID);
-
- /// <remarks>
- /// Era names are 1 indexed
- /// </remarks>
- public string GetAbbreviatedEraName(int era)
- {
- if (AbbreviatedEraNames.Length == 0)
- {
- // If abbreviation era name is not used in this culture,
- // return the full era name.
- return GetEraName(era);
- }
-
- if (era == Calendar.CurrentEra)
- {
- era = Calendar.CurrentEraValue;
- }
-
- if ((--era) < m_abbrevEraNames!.Length && (era >= 0))
- {
- return m_abbrevEraNames[era];
- }
-
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
-
- internal string[] AbbreviatedEnglishEraNames
- {
- get
- {
- if (m_abbrevEnglishEraNames == null)
- {
- Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.AbbreviatedEnglishEraNames] Expected Calendar.ID > 0");
- m_abbrevEnglishEraNames = _cultureData.AbbreviatedEnglishEraNames(Calendar.ID);
- }
- return m_abbrevEnglishEraNames;
- }
- }
-
- /// <remarks>
- /// Note that cultureData derives this from the short date format (unless someone's set this previously)
- /// Note that this property is quite undesirable.
- /// </remarks>
- public string DateSeparator
- {
- get
- {
- if (dateSeparator == null)
- {
- dateSeparator = _cultureData.DateSeparator(Calendar.ID);
- }
- Debug.Assert(dateSeparator != null, "DateTimeFormatInfo.DateSeparator, dateSeparator != null");
- return dateSeparator;
- }
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- ClearTokenHashTable();
- dateSeparator = value;
- }
- }
-
- public DayOfWeek FirstDayOfWeek
- {
- get
- {
- if (firstDayOfWeek == -1)
- {
- firstDayOfWeek = _cultureData.FirstDayOfWeek;
- }
- Debug.Assert(firstDayOfWeek != -1, "DateTimeFormatInfo.FirstDayOfWeek, firstDayOfWeek != -1");
-
- return (DayOfWeek)firstDayOfWeek;
- }
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
-
- if (value < DayOfWeek.Sunday || value > DayOfWeek.Saturday)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, DayOfWeek.Sunday, DayOfWeek.Saturday));
- }
-
- firstDayOfWeek = (int)value;
- }
- }
-
- public CalendarWeekRule CalendarWeekRule
- {
- get
- {
- if (calendarWeekRule == -1)
- {
- calendarWeekRule = _cultureData.CalendarWeekRule;
- }
-
- Debug.Assert(calendarWeekRule != -1, "DateTimeFormatInfo.CalendarWeekRule, calendarWeekRule != -1");
- return (CalendarWeekRule)calendarWeekRule;
- }
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value < CalendarWeekRule.FirstDay || value > CalendarWeekRule.FirstFourDayWeek)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek));
- }
-
- calendarWeekRule = (int)value;
- }
- }
-
- public string FullDateTimePattern
- {
- get => fullDateTimePattern ??= LongDatePattern + " " + LongTimePattern;
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- fullDateTimePattern = value;
- }
- }
-
- /// <summary>
- /// For our "patterns" arrays we have 2 variables, a string and a string[]
- /// The string[] contains the list of patterns, EXCEPT the default may not be included.
- /// The string contains the default pattern.
- /// When we initially construct our string[], we set the string to string[0]
- /// </summary>
- public string LongDatePattern
- {
- get => longDatePattern ??= UnclonedLongDatePatterns[0]; // initialize from the 1st array value if not set
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- // Remember the new string
- longDatePattern = value;
-
- // Clear the token hash table
- ClearTokenHashTable();
-
- // Clean up cached values that will be affected by this property.
- fullDateTimePattern = null;
- }
- }
-
- /// <summary>
- /// For our "patterns" arrays we have 2 variables, a string and a string[]
- ///
- /// The string[] contains the list of patterns, EXCEPT the default may not be included.
- /// The string contains the default pattern.
- /// When we initially construct our string[], we set the string to string[0]
- /// </summary>
- public string LongTimePattern
- {
- get => longTimePattern ??= UnclonedLongTimePatterns[0]; // initialize from the 1st array value if not set
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- // Remember the new string
- longTimePattern = value;
-
- // Clear the token hash table
- ClearTokenHashTable();
-
- // Clean up cached values that will be affected by this property.
- fullDateTimePattern = null; // Full date = long date + long Time
- generalLongTimePattern = null; // General long date = short date + long Time
- dateTimeOffsetPattern = null;
- }
- }
-
- /// <remarks>
- /// Just to be confusing there's only 1 month day pattern, not a whole list
- /// </remarks>
- public string MonthDayPattern
- {
- get
- {
- if (monthDayPattern == null)
- {
- Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.MonthDayPattern] Expected calID > 0");
- monthDayPattern = _cultureData.MonthDay(Calendar.ID);
- }
-
- Debug.Assert(monthDayPattern != null, "DateTimeFormatInfo.MonthDayPattern, monthDayPattern != null");
- return monthDayPattern;
- }
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- monthDayPattern = value;
- }
- }
-
- public string PMDesignator
- {
- get
- {
- if (pmDesignator == null)
- {
- pmDesignator = _cultureData.PMDesignator;
- }
-
- Debug.Assert(pmDesignator != null, "DateTimeFormatInfo.PMDesignator, pmDesignator != null");
- return pmDesignator;
- }
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- ClearTokenHashTable();
- pmDesignator = value;
- }
- }
-
- public string RFC1123Pattern => rfc1123Pattern;
-
- /// <summary>
- /// For our "patterns" arrays we have 2 variables, a string and a string[]
- ///
- /// The string[] contains the list of patterns, EXCEPT the default may not be included.
- /// The string contains the default pattern.
- /// When we initially construct our string[], we set the string to string[0]
- /// </summary>
- public string ShortDatePattern
- {
- get
- {
- return shortDatePattern ??= UnclonedShortDatePatterns[0]; // initialize from the 1st array value if not set
- }
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- // Remember the new string
- shortDatePattern = value;
-
- // Clear the token hash table, note that even short dates could require this
- ClearTokenHashTable();
-
- // Clean up cached values that will be affected by this property.
- generalLongTimePattern = null; // General long time = short date + long time
- generalShortTimePattern = null; // General short time = short date + short Time
- dateTimeOffsetPattern = null;
- }
- }
-
- /// <summary>
- /// For our "patterns" arrays we have 2 variables, a string and a string[]
- ///
- /// The string[] contains the list of patterns, EXCEPT the default may not be included.
- /// The string contains the default pattern.
- /// When we initially construct our string[], we set the string to string[0]
- /// </summary>
- public string ShortTimePattern
- {
- get => shortTimePattern ??= UnclonedShortTimePatterns[0]; // initialize from the 1st array value if not set
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- // Remember the new string
- shortTimePattern = value;
-
- // Clear the token hash table, note that even short times could require this
- ClearTokenHashTable();
-
- // Clean up cached values that will be affected by this property.
- generalShortTimePattern = null; // General short date = short date + short time.
- }
- }
-
- public string SortableDateTimePattern => sortableDateTimePattern;
-
- /// <summary>
- /// Return the pattern for 'g' general format: shortDate + short time
- /// This is used by DateTimeFormat.cs to get the pattern for 'g'.
- /// We put this internal property here so that we can avoid doing the
- /// concatation every time somebody asks for the general format.
- /// </summary>
- internal string GeneralShortTimePattern => generalShortTimePattern ??= ShortDatePattern + " " + ShortTimePattern;
-
- /// <summary>
- /// Return the pattern for 'g' general format: shortDate + Long time.
- /// We put this internal property here so that we can avoid doing the
- /// concatation every time somebody asks for the general format.
- /// </summary>
- internal string GeneralLongTimePattern => generalLongTimePattern ??= ShortDatePattern + " " + LongTimePattern;
-
- /// Return the default pattern DateTimeOffset : shortDate + long time + time zone offset.
- /// This is used by DateTimeFormat.cs to get the pattern for short Date + long time + time zone offset
- /// We put this internal property here so that we can avoid doing the
- /// concatation every time somebody uses this form.
- internal string DateTimeOffsetPattern
- {
- get
- {
- if (dateTimeOffsetPattern == null)
- {
- /* LongTimePattern might contain a "z" as part of the format string in which case we don't want to append a time zone offset */
-
- bool foundZ = false;
- bool inQuote = false;
- char quote = '\'';
- for (int i = 0; !foundZ && i < LongTimePattern.Length; i++)
- {
- switch (LongTimePattern[i])
- {
- case 'z':
- /* if we aren't in a quote, we've found a z */
- foundZ = !inQuote;
- /* we'll fall out of the loop now because the test includes !foundZ */
- break;
- case '\'':
- case '\"':
- if (inQuote && (quote == LongTimePattern[i]))
- {
- /* we were in a quote and found a matching exit quote, so we are outside a quote now */
- inQuote = false;
- }
- else if (!inQuote)
- {
- quote = LongTimePattern[i];
- inQuote = true;
- }
- else
- {
- /* we were in a quote and saw the other type of quote character, so we are still in a quote */
- }
- break;
- case '%':
- case '\\':
- i++; /* skip next character that is escaped by this backslash */
- break;
- default:
- break;
- }
- }
-
- dateTimeOffsetPattern = foundZ ?
- ShortDatePattern + " " + LongTimePattern :
- ShortDatePattern + " " + LongTimePattern + " zzz";
- }
- return dateTimeOffsetPattern;
- }
- }
-
- /// <remarks>
- /// Note that cultureData derives this from the long time format (unless someone's set this previously)
- /// Note that this property is quite undesirable.
- /// </remarks>
- public string TimeSeparator
- {
- get
- {
- if (timeSeparator == null)
- {
- timeSeparator = _cultureData.TimeSeparator;
- }
- Debug.Assert(timeSeparator != null, "DateTimeFormatInfo.TimeSeparator, timeSeparator != null");
- return timeSeparator;
- }
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- ClearTokenHashTable();
- timeSeparator = value;
- }
- }
-
- public string UniversalSortableDateTimePattern => universalSortableDateTimePattern;
-
- /// <summary>
- /// For our "patterns" arrays we have 2 variables, a string and a string[]
- ///
- /// The string[] contains the list of patterns, EXCEPT the default may not be included.
- /// The string contains the default pattern.
- /// When we initially construct our string[], we set the string to string[0]
- /// </summary>
- public string YearMonthPattern
- {
- get => yearMonthPattern ??= UnclonedYearMonthPatterns[0]; // initialize from the 1st array value if not set
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- // Remember the new string
- yearMonthPattern = value;
-
- // Clear the token hash table, note that even short times could require this
- ClearTokenHashTable();
- }
- }
-
- /// <summary>
- /// Check if a string array contains a null value, and throw ArgumentNullException with parameter name "value"
- /// </summary>
- private static void CheckNullValue(string[] values, int length)
- {
- Debug.Assert(values != null, "value != null");
- Debug.Assert(values.Length >= length);
- for (int i = 0; i < length; i++)
- {
- if (values[i] == null)
- {
- throw new ArgumentNullException("value", SR.ArgumentNull_ArrayValue);
- }
- }
- }
-
- public string[] AbbreviatedDayNames
- {
- get => (string[])InternalGetAbbreviatedDayOfWeekNames().Clone();
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if (value.Length != 7)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 7), nameof(value));
- }
-
- CheckNullValue(value, value.Length);
- ClearTokenHashTable();
-
- abbreviatedDayNames = value;
- }
- }
-
- /// <summary>
- /// Returns the string array of the one-letter day of week names.
- /// </summary>
- public string[] ShortestDayNames
- {
- get => (string[])InternalGetSuperShortDayNames().Clone();
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if (value.Length != 7)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 7), nameof(value));
- }
-
- CheckNullValue(value, value.Length);
- m_superShortDayNames = value;
- }
- }
-
- public string[] DayNames
- {
- get => (string[])InternalGetDayOfWeekNames().Clone();
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if (value.Length != 7)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 7), nameof(value));
- }
-
- CheckNullValue(value, value.Length);
- ClearTokenHashTable();
-
- dayNames = value;
- }
- }
-
- public string[] AbbreviatedMonthNames
- {
- get => (string[])InternalGetAbbreviatedMonthNames().Clone();
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if (value.Length != 13)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 13), nameof(value));
- }
-
- CheckNullValue(value, value.Length - 1);
- ClearTokenHashTable();
- abbreviatedMonthNames = value;
- }
- }
-
- public string[] MonthNames
- {
- get => (string[])InternalGetMonthNames().Clone();
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if (value.Length != 13)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 13), nameof(value));
- }
-
- CheckNullValue(value, value.Length - 1);
- monthNames = value;
- ClearTokenHashTable();
- }
- }
-
- internal bool HasSpacesInMonthNames => (FormatFlags & DateTimeFormatFlags.UseSpacesInMonthNames) != 0;
-
- internal bool HasSpacesInDayNames => (FormatFlags & DateTimeFormatFlags.UseSpacesInDayNames) != 0;
-
- /// <summary>
- /// Return the month name using the specified MonthNameStyles in either abbreviated form
- /// or full form.
- /// </summary>
- internal string InternalGetMonthName(int month, MonthNameStyles style, bool abbreviated)
- {
- string[] monthNamesArray = style switch
- {
- MonthNameStyles.Genitive => InternalGetGenitiveMonthNames(abbreviated),
- MonthNameStyles.LeapYear => InternalGetLeapYearMonthNames(),
- _ => (abbreviated ? InternalGetAbbreviatedMonthNames() : InternalGetMonthNames()),
- };
-
- // The month range is from 1 ~ m_monthNames.Length
- // (actually is 13 right now for all cases)
- if ((month < 1) || (month > monthNamesArray.Length))
- {
- throw new ArgumentOutOfRangeException(
- nameof(month),
- month,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, monthNamesArray.Length));
- }
-
- return monthNamesArray[month - 1];
- }
-
- /// <summary>
- /// Retrieve the array which contains the month names in genitive form.
- /// If this culture does not use the genitive form, the normal month name is returned.
- /// </summary>
- private string[] InternalGetGenitiveMonthNames(bool abbreviated)
- {
- if (abbreviated)
- {
- if (m_genitiveAbbreviatedMonthNames == null)
- {
- m_genitiveAbbreviatedMonthNames = _cultureData.AbbreviatedGenitiveMonthNames(Calendar.ID);
- Debug.Assert(m_genitiveAbbreviatedMonthNames.Length == 13,
- "[DateTimeFormatInfo.GetGenitiveMonthNames] Expected 13 abbreviated genitive month names in a year");
- }
-
- return m_genitiveAbbreviatedMonthNames;
- }
-
- if (genitiveMonthNames == null)
- {
- genitiveMonthNames = _cultureData.GenitiveMonthNames(Calendar.ID);
- Debug.Assert(genitiveMonthNames.Length == 13,
- "[DateTimeFormatInfo.GetGenitiveMonthNames] Expected 13 genitive month names in a year");
- }
-
- return genitiveMonthNames;
- }
-
- /// <summary>
- /// Retrieve the month names used in a leap year.
- /// If this culture does not have different month names in a leap year,
- /// the normal month name is returned.
- /// </summary>
- internal string[] InternalGetLeapYearMonthNames()
- {
- if (leapYearMonthNames == null)
- {
- Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.InternalGetLeapYearMonthNames] Expected Calendar.ID > 0");
- leapYearMonthNames = _cultureData.LeapYearMonthNames(Calendar.ID);
- Debug.Assert(leapYearMonthNames.Length == 13,
- "[DateTimeFormatInfo.InternalGetLeapYearMonthNames] Expepcted 13 leap year month names");
- }
-
- return leapYearMonthNames;
- }
-
- public string GetAbbreviatedDayName(DayOfWeek dayofweek)
- {
- if (dayofweek < DayOfWeek.Sunday || dayofweek > DayOfWeek.Saturday)
- {
- throw new ArgumentOutOfRangeException(
- nameof(dayofweek),
- dayofweek,
- SR.Format(SR.ArgumentOutOfRange_Range, DayOfWeek.Sunday, DayOfWeek.Saturday));
- }
-
- // Don't call the public property AbbreviatedDayNames here since a clone is needed in that
- // property, so it will be slower. Instead, use GetAbbreviatedDayOfWeekNames() directly.
- return InternalGetAbbreviatedDayOfWeekNames()[(int)dayofweek];
- }
-
- /// <summary>
- /// Returns the super short day of week names for the specified day of week.
- /// </summary>
- public string GetShortestDayName(DayOfWeek dayOfWeek)
- {
- if (dayOfWeek < DayOfWeek.Sunday || dayOfWeek > DayOfWeek.Saturday)
- {
- throw new ArgumentOutOfRangeException(
- nameof(dayOfWeek),
- dayOfWeek,
- SR.Format(SR.ArgumentOutOfRange_Range, DayOfWeek.Sunday, DayOfWeek.Saturday));
- }
-
- // Don't call the public property SuperShortDayNames here since a clone is needed in that
- // property, so it will be slower. Instead, use internalGetSuperShortDayNames() directly.
- return InternalGetSuperShortDayNames()[(int)dayOfWeek];
- }
-
- /// <summary>
- /// Get all possible combination of inputs
- /// </summary>
- private static string[] GetCombinedPatterns(string[] patterns1, string[] patterns2, string connectString)
- {
- Debug.Assert(patterns1 != null);
- Debug.Assert(patterns2 != null);
-
- // Get array size
- string[] result = new string[patterns1.Length * patterns2.Length];
-
- // Counter of actual results
- int k = 0;
- for (int i = 0; i < patterns1.Length; i++)
- {
- for (int j = 0; j < patterns2.Length; j++)
- {
- // Can't combine if null or empty
- result[k++] = patterns1[i] + connectString + patterns2[j];
- }
- }
-
- // Return the combinations
- return result;
- }
-
- public string[] GetAllDateTimePatterns()
- {
- List<string> results = new List<string>(DEFAULT_ALL_DATETIMES_SIZE);
-
- for (int i = 0; i < DateTimeFormat.allStandardFormats.Length; i++)
- {
- string[] strings = GetAllDateTimePatterns(DateTimeFormat.allStandardFormats[i]);
- for (int j = 0; j < strings.Length; j++)
- {
- results.Add(strings[j]);
- }
- }
- return results.ToArray();
- }
-
- public string[] GetAllDateTimePatterns(char format)
- {
- string[] result;
-
- switch (format)
- {
- case 'd':
- result = AllShortDatePatterns;
- break;
- case 'D':
- result = AllLongDatePatterns;
- break;
- case 'f':
- result = GetCombinedPatterns(AllLongDatePatterns, AllShortTimePatterns, " ");
- break;
- case 'F':
- case 'U':
- result = GetCombinedPatterns(AllLongDatePatterns, AllLongTimePatterns, " ");
- break;
- case 'g':
- result = GetCombinedPatterns(AllShortDatePatterns, AllShortTimePatterns, " ");
- break;
- case 'G':
- result = GetCombinedPatterns(AllShortDatePatterns, AllLongTimePatterns, " ");
- break;
- case 'm':
- case 'M':
- result = new string[] { MonthDayPattern };
- break;
- case 'o':
- case 'O':
- result = new string[] { RoundtripFormat };
- break;
- case 'r':
- case 'R':
- result = new string[] { rfc1123Pattern };
- break;
- case 's':
- result = new string[] { sortableDateTimePattern };
- break;
- case 't':
- result = AllShortTimePatterns;
- break;
- case 'T':
- result = AllLongTimePatterns;
- break;
- case 'u':
- result = new string[] { UniversalSortableDateTimePattern };
- break;
- case 'y':
- case 'Y':
- result = AllYearMonthPatterns;
- break;
- default:
- throw new ArgumentException(SR.Format(SR.Format_BadFormatSpecifier, format), nameof(format));
- }
- return result;
- }
-
- public string GetDayName(DayOfWeek dayofweek)
- {
- if ((int)dayofweek < 0 || (int)dayofweek > 6)
- {
- throw new ArgumentOutOfRangeException(
- nameof(dayofweek),
- dayofweek,
- SR.Format(SR.ArgumentOutOfRange_Range, DayOfWeek.Sunday, DayOfWeek.Saturday));
- }
-
- // Use the internal one so that we don't clone the array unnecessarily
- return InternalGetDayOfWeekNames()[(int)dayofweek];
- }
-
- public string GetAbbreviatedMonthName(int month)
- {
- if (month < 1 || month > 13)
- {
- throw new ArgumentOutOfRangeException(
- nameof(month),
- month,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, 13));
- }
-
- // Use the internal one so we don't clone the array unnecessarily
- return InternalGetAbbreviatedMonthNames()[month - 1];
- }
-
- public string GetMonthName(int month)
- {
- if (month < 1 || month > 13)
- {
- throw new ArgumentOutOfRangeException(
- nameof(month),
- month,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, 13));
- }
-
- // Use the internal one so we don't clone the array unnecessarily
- return InternalGetMonthNames()[month - 1];
- }
-
- /// <summary>
- /// For our "patterns" arrays we have 2 variables, a string and a string[]
- ///
- /// The string[] contains the list of patterns, EXCEPT the default may not be included.
- /// The string contains the default pattern.
- /// When we initially construct our string[], we set the string to string[0]
- ///
- /// The resulting [] can get returned to the calling app, so clone it.
- /// </summary>
- private static string[] GetMergedPatterns(string[] patterns, string defaultPattern)
- {
- Debug.Assert(patterns != null && patterns.Length > 0,
- "[DateTimeFormatInfo.GetMergedPatterns]Expected array of at least one pattern");
- Debug.Assert(defaultPattern != null,
- "[DateTimeFormatInfo.GetMergedPatterns]Expected non null default string");
-
- // If the default happens to be the first in the list just return (a cloned) copy
- if (defaultPattern == patterns[0])
- {
- return (string[])patterns.Clone();
- }
-
- // We either need a bigger list, or the pattern from the list.
- int i;
- for (i = 0; i < patterns.Length; i++)
- {
- // Stop if we found it
- if (defaultPattern == patterns[i])
- break;
- }
-
- // Either way we're going to need a new array
- string[] newPatterns;
-
- // Did we find it
- if (i < patterns.Length)
- {
- // Found it, output will be same size
- newPatterns = (string[])patterns.Clone();
-
- // Have to move [0] item to [i] so we can re-write default at [0]
- // (remember defaultPattern == [i] so this is OK)
- newPatterns[i] = newPatterns[0];
- }
- else
- {
- // Not found, make room for it
- newPatterns = new string[patterns.Length + 1];
-
- // Copy existing array
- Array.Copy(patterns, 0, newPatterns, 1, patterns.Length);
- }
-
- // Remember the default
- newPatterns[0] = defaultPattern;
-
- // Return the reconstructed list
- return newPatterns;
- }
-
- // Needed by DateTimeFormatInfo and DateTimeFormat
- internal const string RoundtripFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK";
- internal const string RoundtripDateTimeUnfixed = "yyyy'-'MM'-'ddTHH':'mm':'ss zzz";
-
- /// <summary>
- /// Default string isn't necessarily in our string array, so get the
- /// merged patterns of both
- /// </summary>
- private string[] AllYearMonthPatterns => GetMergedPatterns(UnclonedYearMonthPatterns, YearMonthPattern);
-
- private string[] AllShortDatePatterns => GetMergedPatterns(UnclonedShortDatePatterns, ShortDatePattern);
-
- private string[] AllShortTimePatterns => GetMergedPatterns(UnclonedShortTimePatterns, ShortTimePattern);
-
- private string[] AllLongDatePatterns => GetMergedPatterns(UnclonedLongDatePatterns, LongDatePattern);
-
- private string[] AllLongTimePatterns => GetMergedPatterns(UnclonedLongTimePatterns, LongTimePattern);
-
- /// <remarks>
- /// Clone this string array if you want to return it to user.
- /// Otherwise, you are returning a writable cache copy.
- /// This won't include default, call AllYearMonthPatterns
- /// </remarks>
- private string[] UnclonedYearMonthPatterns
- {
- get
- {
- if (allYearMonthPatterns == null)
- {
- Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.UnclonedYearMonthPatterns] Expected Calendar.ID > 0");
- allYearMonthPatterns = _cultureData.YearMonths(Calendar.ID);
- Debug.Assert(allYearMonthPatterns.Length > 0,
- "[DateTimeFormatInfo.UnclonedYearMonthPatterns] Expected some year month patterns");
- }
-
- return allYearMonthPatterns;
- }
- }
-
- /// <remarks>
- /// Clone this string array if you want to return it to user.
- /// Otherwise, you are returning a writable cache copy.
- /// This won't include default, call AllShortDatePatterns
- /// </remarks>
- private string[] UnclonedShortDatePatterns
- {
- get
- {
- if (allShortDatePatterns == null)
- {
- Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.UnclonedShortDatePatterns] Expected Calendar.ID > 0");
- allShortDatePatterns = _cultureData.ShortDates(Calendar.ID);
- Debug.Assert(allShortDatePatterns.Length > 0,
- "[DateTimeFormatInfo.UnclonedShortDatePatterns] Expected some short date patterns");
- }
-
- return allShortDatePatterns;
- }
- }
-
- /// <remarks>
- /// Clone this string array if you want to return it to user.
- /// Otherwise, you are returning a writable cache copy.
- /// This won't include default, call AllLongDatePatterns
- /// </remarks>
- private string[] UnclonedLongDatePatterns
- {
- get
- {
- if (allLongDatePatterns == null)
- {
- Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.UnclonedLongDatePatterns] Expected Calendar.ID > 0");
- allLongDatePatterns = _cultureData.LongDates(Calendar.ID);
- Debug.Assert(allLongDatePatterns.Length > 0,
- "[DateTimeFormatInfo.UnclonedLongDatePatterns] Expected some long date patterns");
- }
-
- return allLongDatePatterns;
- }
- }
-
- /// <remarks>
- /// Clone this string array if you want to return it to user.
- /// Otherwise, you are returning a writable cache copy.
- /// This won't include default, call AllShortTimePatterns
- /// </remarks>
- private string[] UnclonedShortTimePatterns
- {
- get
- {
- if (allShortTimePatterns == null)
- {
- allShortTimePatterns = _cultureData.ShortTimes;
- Debug.Assert(allShortTimePatterns.Length > 0,
- "[DateTimeFormatInfo.UnclonedShortTimePatterns] Expected some short time patterns");
- }
-
- return allShortTimePatterns;
- }
- }
-
- /// <remarks>
- /// Clone this string array if you want to return it to user.
- /// Otherwise, you are returning a writable cache copy.
- /// This won't include default, call AllLongTimePatterns
- /// </remarks>
- private string[] UnclonedLongTimePatterns
- {
- get
- {
- if (allLongTimePatterns == null)
- {
- allLongTimePatterns = _cultureData.LongTimes;
- Debug.Assert(allLongTimePatterns.Length > 0,
- "[DateTimeFormatInfo.UnclonedLongTimePatterns] Expected some long time patterns");
- }
-
- return allLongTimePatterns;
- }
- }
-
- public static DateTimeFormatInfo ReadOnly(DateTimeFormatInfo dtfi)
- {
- if (dtfi == null)
- {
- throw new ArgumentNullException(nameof(dtfi));
- }
-
- if (dtfi.IsReadOnly)
- {
- return dtfi;
- }
-
- DateTimeFormatInfo newInfo = (DateTimeFormatInfo)(dtfi.MemberwiseClone());
- // We can use the data member calendar in the setter, instead of the property Calendar,
- // since the cloned copy should have the same state as the original copy.
- newInfo.calendar = Calendar.ReadOnly(dtfi.Calendar);
- newInfo._isReadOnly = true;
- return newInfo;
- }
-
- public bool IsReadOnly => _isReadOnly;
-
- /// <summary>
- /// Return the native name for the calendar in DTFI.Calendar. The native name is referred to
- /// the culture used to create the DTFI. E.g. in the following example, the native language is Japanese.
- /// DateTimeFormatInfo dtfi = new CultureInfo("ja-JP", false).DateTimeFormat.Calendar = new JapaneseCalendar();
- /// String nativeName = dtfi.NativeCalendarName; // Get the Japanese name for the Japanese calendar.
- /// DateTimeFormatInfo dtfi = new CultureInfo("ja-JP", false).DateTimeFormat.Calendar = new GregorianCalendar(GregorianCalendarTypes.Localized);
- /// String nativeName = dtfi.NativeCalendarName; // Get the Japanese name for the Gregorian calendar.
- /// </summary>
- public string NativeCalendarName => _cultureData.CalendarName(Calendar.ID);
-
- /// <summary>
- /// Used by custom cultures and others to set the list of available formats. Note that none of them are
- /// explicitly used unless someone calls GetAllDateTimePatterns and subsequently uses one of the items
- /// from the list.
- ///
- /// Most of the format characters that can be used in GetAllDateTimePatterns are
- /// not really needed since they are one of the following:
- ///
- /// r/R/s/u locale-independent constants -- cannot be changed!
- /// m/M/y/Y fields with a single string in them -- that can be set through props directly
- /// f/F/g/G/U derived fields based on combinations of various of the below formats
- ///
- /// NOTE: No special validation is done here beyond what is done when the actual respective fields
- /// are used (what would be the point of disallowing here what we allow in the appropriate property?)
- ///
- /// WARNING: If more validation is ever done in one place, it should be done in the other.
- /// </summary>
- public void SetAllDateTimePatterns(string[] patterns, char format)
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (patterns == null)
- {
- throw new ArgumentNullException(nameof(patterns));
- }
-
- if (patterns.Length == 0)
- {
- throw new ArgumentException(SR.Arg_ArrayZeroError, nameof(patterns));
- }
-
- for (int i = 0; i < patterns.Length; i++)
- {
- if (patterns[i] == null)
- {
- throw new ArgumentNullException("patterns[" + i + "]", SR.ArgumentNull_ArrayValue);
- }
- }
-
- // Remember the patterns, and use the 1st as default
- switch (format)
- {
- case 'd':
- allShortDatePatterns = patterns;
- shortDatePattern = allShortDatePatterns[0];
- break;
-
- case 'D':
- allLongDatePatterns = patterns;
- longDatePattern = allLongDatePatterns[0];
- break;
-
- case 't':
- allShortTimePatterns = patterns;
- shortTimePattern = allShortTimePatterns[0];
- break;
-
- case 'T':
- allLongTimePatterns = patterns;
- longTimePattern = allLongTimePatterns[0];
- break;
-
- case 'y':
- case 'Y':
- allYearMonthPatterns = patterns;
- yearMonthPattern = allYearMonthPatterns[0];
- break;
-
- default:
- throw new ArgumentException(SR.Format(SR.Format_BadFormatSpecifier, format), nameof(format));
- }
-
- // Clear the token hash table, note that even short dates could require this
- ClearTokenHashTable();
- }
-
- public string[] AbbreviatedMonthGenitiveNames
- {
- get => (string[])InternalGetGenitiveMonthNames(true).Clone();
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if (value.Length != 13)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 13), nameof(value));
- }
-
- CheckNullValue(value, value.Length - 1);
- ClearTokenHashTable();
- m_genitiveAbbreviatedMonthNames = value;
- }
- }
-
- public string[] MonthGenitiveNames
- {
- get => (string[])InternalGetGenitiveMonthNames(false).Clone();
- set
- {
- if (IsReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if (value.Length != 13)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 13), nameof(value));
- }
-
- CheckNullValue(value, value.Length - 1);
- genitiveMonthNames = value;
- ClearTokenHashTable();
- }
- }
-
- // Decimal separator used by positive TimeSpan pattern
- private string? _decimalSeparator;
- internal string DecimalSeparator =>
- _decimalSeparator ??=
- new NumberFormatInfo(_cultureData.UseUserOverride ? CultureData.GetCultureData(_cultureData.CultureName, false) : _cultureData).NumberDecimalSeparator;
-
- // Positive TimeSpan Pattern
- private string? _fullTimeSpanPositivePattern;
- internal string FullTimeSpanPositivePattern =>
- _fullTimeSpanPositivePattern ??= "d':'h':'mm':'ss'" + DecimalSeparator + "'FFFFFFF";
-
- // Negative TimeSpan Pattern
- private string? _fullTimeSpanNegativePattern;
- internal string FullTimeSpanNegativePattern =>
- _fullTimeSpanNegativePattern ??= "'-'" + FullTimeSpanPositivePattern;
-
- // Get suitable CompareInfo from current DTFI object.
- internal CompareInfo CompareInfo =>
- // We use the regular GetCompareInfo here to make sure the created CompareInfo object is stored in the
- // CompareInfo cache. otherwise we would just create CompareInfo using _cultureData.
- _compareInfo ??= CompareInfo.GetCompareInfo(_cultureData.SortName);
-
- internal const DateTimeStyles InvalidDateTimeStyles = ~(DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite
- | DateTimeStyles.AllowInnerWhite | DateTimeStyles.NoCurrentDateDefault
- | DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeLocal
- | DateTimeStyles.AssumeUniversal | DateTimeStyles.RoundtripKind);
-
- internal static void ValidateStyles(DateTimeStyles style, string parameterName)
- {
- if ((style & InvalidDateTimeStyles) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidDateTimeStyles, parameterName);
- }
- if (((style & (DateTimeStyles.AssumeLocal)) != 0) && ((style & (DateTimeStyles.AssumeUniversal)) != 0))
- {
- throw new ArgumentException(SR.Argument_ConflictingDateTimeStyles, parameterName);
- }
- if (((style & DateTimeStyles.RoundtripKind) != 0)
- && ((style & (DateTimeStyles.AssumeLocal | DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal)) != 0))
- {
- throw new ArgumentException(SR.Argument_ConflictingDateTimeRoundtripStyles, parameterName);
- }
- }
-
- /// <summary>
- /// Return the internal flag used in formatting and parsing.
- /// The flag can be used to indicate things like if genitive forms is used in
- /// this DTFi, or if leap year gets different month names.
- /// </summary>
- internal DateTimeFormatFlags FormatFlags => formatFlags != DateTimeFormatFlags.NotInitialized ? formatFlags : InitializeFormatFlags();
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private DateTimeFormatFlags InitializeFormatFlags()
- {
- // Build the format flags from the data in this DTFI
- formatFlags =
- (DateTimeFormatFlags)DateTimeFormatInfoScanner.GetFormatFlagGenitiveMonth(
- MonthNames, InternalGetGenitiveMonthNames(false), AbbreviatedMonthNames, InternalGetGenitiveMonthNames(true)) |
- (DateTimeFormatFlags)DateTimeFormatInfoScanner.GetFormatFlagUseSpaceInMonthNames(
- MonthNames, InternalGetGenitiveMonthNames(false), AbbreviatedMonthNames, InternalGetGenitiveMonthNames(true)) |
- (DateTimeFormatFlags)DateTimeFormatInfoScanner.GetFormatFlagUseSpaceInDayNames(DayNames, AbbreviatedDayNames) |
- (DateTimeFormatFlags)DateTimeFormatInfoScanner.GetFormatFlagUseHebrewCalendar((int)Calendar.ID);
- return formatFlags;
- }
-
- internal bool HasForceTwoDigitYears
- {
- get
- {
- switch (calendar.ID)
- {
- // Handle Japanese and Taiwan cases.
- // If is y/yy, do not get (year % 100). "y" will print
- // year without leading zero. "yy" will print year with two-digit in leading zero.
- // If pattern is yyy/yyyy/..., print year value with two-digit in leading zero.
- // So year 5 is "05", and year 125 is "125".
- // The reason for not doing (year % 100) is for Taiwan calendar.
- // If year 125, then output 125 and not 25.
- // Note: OS uses "yyyy" for Taiwan calendar by default.
- case (CalendarId.JAPAN):
- case (CalendarId.TAIWAN):
- return true;
- }
- return false;
- }
- }
-
- /// <summary>
- /// Returns whether the YearMonthAdjustment function has any fix-up work to do for this culture/calendar.
- /// </summary>
- internal bool HasYearMonthAdjustment => (FormatFlags & DateTimeFormatFlags.UseHebrewRule) != 0;
-
- /// <summary>
- /// This is a callback that the parser can make back into the DTFI to let it fiddle with special
- /// cases associated with that culture or calendar. Currently this only has special cases for
- /// the Hebrew calendar, but this could be extended to other cultures.
- ///
- /// The return value is whether the year and month are actually valid for this calendar.
- /// </summary>
- internal bool YearMonthAdjustment(ref int year, ref int month, bool parsedMonthName)
- {
- if ((FormatFlags & DateTimeFormatFlags.UseHebrewRule) != 0)
- {
- // Special rules to fix up the Hebrew year/month
-
- // When formatting, we only format up to the hundred digit of the Hebrew year, although Hebrew year is now over 5000.
- // E.g. if the year is 5763, we only format as 763.
- if (year < 1000)
- {
- year += 5000;
- }
-
- // Because we need to calculate leap year, we should fall out now for an invalid year.
- if (year < Calendar.GetYear(Calendar.MinSupportedDateTime) || year > Calendar.GetYear(Calendar.MaxSupportedDateTime))
- {
- return false;
- }
-
- // To handle leap months, the set of month names in the symbol table does not always correspond to the numbers.
- // For non-leap years, month 7 (Adar Bet) is not present, so we need to make using this month invalid and
- // shuffle the other months down.
- if (parsedMonthName)
- {
- if (!Calendar.IsLeapYear(year))
- {
- if (month >= 8)
- {
- month--;
- }
- else if (month == 7)
- {
- return false;
- }
- }
- }
- }
- return true;
- }
-
- // DateTimeFormatInfo tokenizer. This is used by DateTime.Parse() to break input string into tokens.
- private TokenHashValue[]? _dtfiTokenHash;
-
- private const int TOKEN_HASH_SIZE = 199;
- private const int SECOND_PRIME = 197;
- private const string dateSeparatorOrTimeZoneOffset = "-";
- private const string invariantDateSeparator = "/";
- private const string invariantTimeSeparator = ":";
-
- // Common Ignorable Symbols
- internal const string IgnorablePeriod = ".";
- internal const string IgnorableComma = ",";
-
- // Year/Month/Day suffixes
- internal const string CJKYearSuff = "\u5e74";
- internal const string CJKMonthSuff = "\u6708";
- internal const string CJKDaySuff = "\u65e5";
-
- internal const string KoreanYearSuff = "\ub144";
- internal const string KoreanMonthSuff = "\uc6d4";
- internal const string KoreanDaySuff = "\uc77c";
-
- internal const string KoreanHourSuff = "\uc2dc";
- internal const string KoreanMinuteSuff = "\ubd84";
- internal const string KoreanSecondSuff = "\ucd08";
-
- internal const string CJKHourSuff = "\u6642";
- internal const string ChineseHourSuff = "\u65f6";
-
- internal const string CJKMinuteSuff = "\u5206";
- internal const string CJKSecondSuff = "\u79d2";
-
- internal const string JapaneseEraStart = "\u5143";
-
- internal const string LocalTimeMark = "T";
-
- internal const string GMTName = "GMT";
- internal const string ZuluName = "Z";
-
- internal const string KoreanLangName = "ko";
- internal const string JapaneseLangName = "ja";
- internal const string EnglishLangName = "en";
-
- private static volatile DateTimeFormatInfo? s_jajpDTFI;
- private static volatile DateTimeFormatInfo? s_zhtwDTFI;
-
- /// <summary>
- /// Create a Japanese DTFI which uses JapaneseCalendar. This is used to parse
- /// date string with Japanese era name correctly even when the supplied DTFI
- /// does not use Japanese calendar.
- /// The created instance is stored in global s_jajpDTFI.
- /// </summary>
- internal static DateTimeFormatInfo GetJapaneseCalendarDTFI()
- {
- DateTimeFormatInfo? temp = s_jajpDTFI;
- if (temp == null)
- {
- temp = new CultureInfo("ja-JP", false).DateTimeFormat;
- temp.Calendar = JapaneseCalendar.GetDefaultInstance();
- s_jajpDTFI = temp;
- }
- return temp;
- }
-
- /// <summary>
- /// Create a Taiwan DTFI which uses TaiwanCalendar. This is used to parse
- /// date string with era name correctly even when the supplied DTFI
- /// does not use Taiwan calendar.
- /// The created instance is stored in global s_zhtwDTFI.
- /// </summary>
- internal static DateTimeFormatInfo GetTaiwanCalendarDTFI()
- {
- DateTimeFormatInfo? temp = s_zhtwDTFI;
- if (temp == null)
- {
- temp = new CultureInfo("zh-TW", false).DateTimeFormat;
- temp.Calendar = TaiwanCalendar.GetDefaultInstance();
- s_zhtwDTFI = temp;
- }
- return temp;
- }
-
- /// <summary>
- /// DTFI properties should call this when the setter are called.
- /// </summary>
- private void ClearTokenHashTable()
- {
- _dtfiTokenHash = null;
- formatFlags = DateTimeFormatFlags.NotInitialized;
- }
-
- internal TokenHashValue[] CreateTokenHashTable()
- {
- TokenHashValue[]? temp = _dtfiTokenHash;
- if (temp == null)
- {
- temp = new TokenHashValue[TOKEN_HASH_SIZE];
-
- bool koreanLanguage = LanguageName.Equals(KoreanLangName);
-
- string sep = TimeSeparator.Trim();
- if (IgnorableComma != sep) InsertHash(temp, IgnorableComma, TokenType.IgnorableSymbol, 0);
- if (IgnorablePeriod != sep) InsertHash(temp, IgnorablePeriod, TokenType.IgnorableSymbol, 0);
-
- if (KoreanHourSuff != sep && CJKHourSuff != sep && ChineseHourSuff != sep)
- {
- //
- // On the Macintosh, the default TimeSeparator is identical to the KoreanHourSuff, CJKHourSuff, or ChineseHourSuff for some cultures like
- // ja-JP and ko-KR. In these cases having the same symbol inserted into the hash table with multiple TokenTypes causes undesirable
- // DateTime.Parse behavior. For instance, the DateTimeFormatInfo.Tokenize() method might return SEP_DateOrOffset for KoreanHourSuff
- // instead of SEP_HourSuff.
- //
- InsertHash(temp, TimeSeparator, TokenType.SEP_Time, 0);
- }
-
- InsertHash(temp, AMDesignator, TokenType.SEP_Am | TokenType.Am, 0);
- InsertHash(temp, PMDesignator, TokenType.SEP_Pm | TokenType.Pm, 1);
-
- if (LanguageName.Equals("sq"))
- {
- // Albanian allows time formats like "12:00.PD"
- InsertHash(temp, IgnorablePeriod + AMDesignator, TokenType.SEP_Am | TokenType.Am, 0);
- InsertHash(temp, IgnorablePeriod + PMDesignator, TokenType.SEP_Pm | TokenType.Pm, 1);
- }
-
- // CJK suffix
- InsertHash(temp, CJKYearSuff, TokenType.SEP_YearSuff, 0);
- InsertHash(temp, KoreanYearSuff, TokenType.SEP_YearSuff, 0);
- InsertHash(temp, CJKMonthSuff, TokenType.SEP_MonthSuff, 0);
- InsertHash(temp, KoreanMonthSuff, TokenType.SEP_MonthSuff, 0);
- InsertHash(temp, CJKDaySuff, TokenType.SEP_DaySuff, 0);
- InsertHash(temp, KoreanDaySuff, TokenType.SEP_DaySuff, 0);
-
- InsertHash(temp, CJKHourSuff, TokenType.SEP_HourSuff, 0);
- InsertHash(temp, ChineseHourSuff, TokenType.SEP_HourSuff, 0);
- InsertHash(temp, CJKMinuteSuff, TokenType.SEP_MinuteSuff, 0);
- InsertHash(temp, CJKSecondSuff, TokenType.SEP_SecondSuff, 0);
-
- if (!LocalAppContextSwitches.EnforceLegacyJapaneseDateParsing && Calendar.ID == CalendarId.JAPAN)
- {
- // We need to support parsing the dates has the start of era symbol which means it is year 1 in the era.
- // The start of era symbol has to be followed by the year symbol suffix, otherwise it would be invalid date.
- InsertHash(temp, JapaneseEraStart, TokenType.YearNumberToken, 1);
- InsertHash(temp, "(", TokenType.IgnorableSymbol, 0);
- InsertHash(temp, ")", TokenType.IgnorableSymbol, 0);
- }
-
- // TODO: This ignores other custom cultures that might want to do something similar
- if (koreanLanguage)
- {
- // Korean suffix
- InsertHash(temp, KoreanHourSuff, TokenType.SEP_HourSuff, 0);
- InsertHash(temp, KoreanMinuteSuff, TokenType.SEP_MinuteSuff, 0);
- InsertHash(temp, KoreanSecondSuff, TokenType.SEP_SecondSuff, 0);
- }
-
- if (LanguageName.Equals("ky"))
- {
- // For some cultures, the date separator works more like a comma, being allowed before or after any date part
- InsertHash(temp, dateSeparatorOrTimeZoneOffset, TokenType.IgnorableSymbol, 0);
- }
- else
- {
- InsertHash(temp, dateSeparatorOrTimeZoneOffset, TokenType.SEP_DateOrOffset, 0);
- }
-
- // We need to rescan the date words since we're always synthetic
- DateTimeFormatInfoScanner scanner = new DateTimeFormatInfoScanner();
- string[]? dateWords = scanner.GetDateWordsOfDTFI(this);
-
- // Ensure the formatflags is initialized.
- _ = FormatFlags;
-
- // For some cultures, the date separator works more like a comma, being allowed before or after any date part.
- // In these cultures, we do not use normal date separator since we disallow date separator after a date terminal state.
- // This is determined in DateTimeFormatInfoScanner. Use this flag to determine if we should treat date separator as ignorable symbol.
- bool useDateSepAsIgnorableSymbol = false;
-
- if (dateWords != null)
- {
- // There are DateWords. It could be a real date word (such as "de"), or a monthPostfix.
- // The monthPostfix starts with '\xfffe' (MonthPostfixChar), followed by the real monthPostfix.
- for (int i = 0; i < dateWords.Length; i++)
- {
- switch (dateWords[i][0])
- {
- // This is a month postfix
- case DateTimeFormatInfoScanner.MonthPostfixChar:
- // Get the real month postfix.
- ReadOnlySpan<char> monthPostfix = dateWords[i].AsSpan(1);
- // Add the month name + postfix into the token.
- AddMonthNames(temp, monthPostfix);
- break;
- case DateTimeFormatInfoScanner.IgnorableSymbolChar:
- string symbol = dateWords[i].Substring(1);
- InsertHash(temp, symbol, TokenType.IgnorableSymbol, 0);
- if (DateSeparator.Trim(null).Equals(symbol))
- {
- // The date separator is the same as the ignorable symbol.
- useDateSepAsIgnorableSymbol = true;
- }
- break;
- default:
- InsertHash(temp, dateWords[i], TokenType.DateWordToken, 0);
- // TODO: This ignores similar custom cultures
- if (LanguageName.Equals("eu"))
- {
- // Basque has date words with leading dots
- InsertHash(temp, IgnorablePeriod + dateWords[i], TokenType.DateWordToken, 0);
- }
- break;
- }
- }
- }
-
- if (!useDateSepAsIgnorableSymbol)
- {
- // Use the normal date separator.
- InsertHash(temp, DateSeparator, TokenType.SEP_Date, 0);
- }
- // Add the regular month names.
- AddMonthNames(temp);
-
- // Add the abbreviated month names.
- for (int i = 1; i <= 13; i++)
- {
- InsertHash(temp, GetAbbreviatedMonthName(i), TokenType.MonthToken, i);
- }
-
- if ((FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0)
- {
- string [] genitiveMonthNames = InternalGetGenitiveMonthNames(abbreviated: false);
- string [] abbreviatedGenitiveMonthNames = InternalGetGenitiveMonthNames(abbreviated: true);
-
- for (int i = 1; i <= 13; i++)
- {
- InsertHash(temp, genitiveMonthNames[i - 1], TokenType.MonthToken, i);
- InsertHash(temp, abbreviatedGenitiveMonthNames[i - 1], TokenType.MonthToken, i);
- }
- }
-
- if ((FormatFlags & DateTimeFormatFlags.UseLeapYearMonth) != 0)
- {
- for (int i = 1; i <= 13; i++)
- {
- string str = InternalGetMonthName(i, MonthNameStyles.LeapYear, false);
- InsertHash(temp, str, TokenType.MonthToken, i);
- }
- }
-
- for (int i = 0; i < 7; i++)
- {
- // We have to call public methods here to work with inherited DTFI.
- string str = GetDayName((DayOfWeek)i);
- InsertHash(temp, str, TokenType.DayOfWeekToken, i);
-
- str = GetAbbreviatedDayName((DayOfWeek)i);
- InsertHash(temp, str, TokenType.DayOfWeekToken, i);
- }
-
- int[] eras = calendar.Eras;
- for (int i = 1; i <= eras.Length; i++)
- {
- InsertHash(temp, GetEraName(i), TokenType.EraToken, i);
- InsertHash(temp, GetAbbreviatedEraName(i), TokenType.EraToken, i);
- }
-
- if (LanguageName.Equals(JapaneseLangName))
- {
- // Japanese allows day of week forms like: "(Tue)"
- for (int i = 0; i < 7; i++)
- {
- string specialDayOfWeek = "(" + GetAbbreviatedDayName((DayOfWeek)i) + ")";
- InsertHash(temp, specialDayOfWeek, TokenType.DayOfWeekToken, i);
- }
- if (Calendar.GetType() != typeof(JapaneseCalendar))
- {
- // Special case for Japanese. If this is a Japanese DTFI, and the calendar is not Japanese calendar,
- // we will check Japanese Era name as well when the calendar is Gregorian.
- DateTimeFormatInfo jaDtfi = GetJapaneseCalendarDTFI();
- for (int i = 1; i <= jaDtfi.Calendar.Eras.Length; i++)
- {
- InsertHash(temp, jaDtfi.GetEraName(i), TokenType.JapaneseEraToken, i);
- InsertHash(temp, jaDtfi.GetAbbreviatedEraName(i), TokenType.JapaneseEraToken, i);
- // m_abbrevEnglishEraNames[0] contains the name for era 1, so the token value is i+1.
- InsertHash(temp, jaDtfi.AbbreviatedEnglishEraNames[i - 1], TokenType.JapaneseEraToken, i);
- }
- }
- }
- // TODO: This prohibits similar custom cultures, but we hard coded the name
- else if (CultureName.Equals("zh-TW"))
- {
- DateTimeFormatInfo twDtfi = GetTaiwanCalendarDTFI();
- for (int i = 1; i <= twDtfi.Calendar.Eras.Length; i++)
- {
- if (twDtfi.GetEraName(i).Length > 0)
- {
- InsertHash(temp, twDtfi.GetEraName(i), TokenType.TEraToken, i);
- }
- }
- }
-
- InsertHash(temp, InvariantInfo.AMDesignator, TokenType.SEP_Am | TokenType.Am, 0);
- InsertHash(temp, InvariantInfo.PMDesignator, TokenType.SEP_Pm | TokenType.Pm, 1);
-
- // Add invariant month names and day names.
- for (int i = 1; i <= 12; i++)
- {
- // We have to call public methods here to work with inherited DTFI.
- // Insert the month name first, so that they are at the front of abbreviated
- // month names.
- string str = InvariantInfo.GetMonthName(i);
- InsertHash(temp, str, TokenType.MonthToken, i);
- str = InvariantInfo.GetAbbreviatedMonthName(i);
- InsertHash(temp, str, TokenType.MonthToken, i);
- }
-
- for (int i = 0; i < 7; i++)
- {
- // We have to call public methods here to work with inherited DTFI.
- string str = InvariantInfo.GetDayName((DayOfWeek)i);
- InsertHash(temp, str, TokenType.DayOfWeekToken, i);
-
- str = InvariantInfo.GetAbbreviatedDayName((DayOfWeek)i);
- InsertHash(temp, str, TokenType.DayOfWeekToken, i);
- }
-
- for (int i = 0; i < AbbreviatedEnglishEraNames.Length; i++)
- {
- // m_abbrevEnglishEraNames[0] contains the name for era 1, so the token value is i+1.
- InsertHash(temp, AbbreviatedEnglishEraNames[i], TokenType.EraToken, i + 1);
- }
-
- InsertHash(temp, LocalTimeMark, TokenType.SEP_LocalTimeMark, 0);
- InsertHash(temp, GMTName, TokenType.TimeZoneToken, 0);
- InsertHash(temp, ZuluName, TokenType.TimeZoneToken, 0);
-
- InsertHash(temp, invariantDateSeparator, TokenType.SEP_Date, 0);
- InsertHash(temp, invariantTimeSeparator, TokenType.SEP_Time, 0);
-
- _dtfiTokenHash = temp;
- }
- return temp;
- }
-
- private void AddMonthNames(TokenHashValue[] temp, ReadOnlySpan<char> monthPostfix = default)
- {
- for (int i = 1; i <= 13; i++)
- {
- // We have to call public methods here to work with inherited DTFI.
- // Insert the month name first, so that they are at the front of abbreviated
- // month names.
- string str = GetMonthName(i);
- if (str.Length > 0)
- {
- if (!monthPostfix.IsEmpty)
- {
- // Insert the month name with the postfix first, so it can be matched first.
- InsertHash(temp, string.Concat(str, monthPostfix), TokenType.MonthToken, i);
- }
- else
- {
- InsertHash(temp, str, TokenType.MonthToken, i);
- }
- }
- str = GetAbbreviatedMonthName(i);
- InsertHash(temp, str, TokenType.MonthToken, i);
- }
- }
-
- /// <summary>
- /// Try to parse the current word to see if it is a Hebrew number.
- /// Tokens will be updated accordingly.
- /// This is called by the Lexer of DateTime.Parse().
- ///
- /// Unlike most of the functions in this class, the return value indicates
- /// whether or not it started to parse. The badFormat parameter indicates
- /// if parsing began, but the format was bad.
- /// </summary>
- private static bool TryParseHebrewNumber(
- ref __DTString str,
- out bool badFormat,
- out int number)
- {
- number = -1;
- badFormat = false;
-
- int i = str.Index;
- if (!HebrewNumber.IsDigit(str.Value[i]))
- {
- // If the current character is not a Hebrew digit, just return false.
- // There is no chance that we can parse a valid Hebrew number from here.
- return false;
- }
- // The current character is a Hebrew digit. Try to parse this word as a Hebrew number.
- HebrewNumberParsingContext context = new HebrewNumberParsingContext(0);
- HebrewNumberParsingState state;
-
- do
- {
- state = HebrewNumber.ParseByChar(str.Value[i++], ref context);
- switch (state)
- {
- case HebrewNumberParsingState.InvalidHebrewNumber: // Not a valid Hebrew number.
- case HebrewNumberParsingState.NotHebrewDigit: // The current character is not a Hebrew digit character.
- // Break out so that we don't continue to try parse this as a Hebrew number.
- return false;
- }
- } while (i < str.Value.Length && (state != HebrewNumberParsingState.FoundEndOfHebrewNumber));
-
- // When we are here, we are either at the end of the string, or we find a valid Hebrew number.
- Debug.Assert(state == HebrewNumberParsingState.ContinueParsing || state == HebrewNumberParsingState.FoundEndOfHebrewNumber,
- "Invalid returned state from HebrewNumber.ParseByChar()");
-
- if (state != HebrewNumberParsingState.FoundEndOfHebrewNumber)
- {
- // We reach end of the string but we can't find a terminal state in parsing Hebrew number.
- return false;
- }
-
- // We have found a valid Hebrew number. Update the index.
- str.Advance(i - str.Index);
-
- // Get the final Hebrew number value from the HebrewNumberParsingContext.
- number = context.result;
-
- return true;
- }
-
- private static bool IsHebrewChar(char ch)
- {
- return ch >= '\x0590' && ch <= '\x05ff';
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private bool IsAllowedJapaneseTokenFollowedByNonSpaceLetter(string tokenString, char nextCh)
- {
- // Allow the parser to recognize the case when having some date part followed by JapaneseEraStart "\u5143"
- // without spaces in between. e.g. Era name followed by \u5143 in the date formats ggy.
- // Also, allow recognizing the year suffix symbol "\u5e74" followed the JapaneseEraStart "\u5143"
- if (!LocalAppContextSwitches.EnforceLegacyJapaneseDateParsing && Calendar.ID == CalendarId.JAPAN &&
- (
- // something like ggy, era followed by year and the year is specified using the JapaneseEraStart "\u5143"
- nextCh == JapaneseEraStart[0] ||
- // JapaneseEraStart followed by year suffix "\u5143"
- (tokenString == JapaneseEraStart && nextCh == CJKYearSuff[0])
- ))
- {
- return true;
- }
- return false;
- }
-
- internal bool Tokenize(TokenType TokenMask, out TokenType tokenType, out int tokenValue,
- ref __DTString str)
- {
- tokenType = TokenType.UnknownToken;
- tokenValue = 0;
-
- TokenHashValue value;
- Debug.Assert(str.Index < str.Value.Length, "DateTimeFormatInfo.Tokenize(): start < value.Length");
-
- char ch = str.m_current;
- bool isLetter = char.IsLetter(ch);
- if (isLetter)
- {
- ch = Culture.TextInfo.ToLower(ch);
- if (IsHebrewChar(ch) && TokenMask == TokenType.RegularTokenMask)
- {
- bool badFormat;
- if (TryParseHebrewNumber(ref str, out badFormat, out tokenValue))
- {
- if (badFormat)
- {
- tokenType = TokenType.UnknownToken;
- return false;
- }
- // This is a Hebrew number.
- // Do nothing here. TryParseHebrewNumber() will update token accordingly.
- tokenType = TokenType.HebrewNumber;
- return true;
- }
- }
- }
-
- int hashcode = ch % TOKEN_HASH_SIZE;
- int hashProbe = 1 + ch % SECOND_PRIME;
- int remaining = str.Length - str.Index;
- int i = 0;
-
- TokenHashValue[] hashTable = _dtfiTokenHash ?? CreateTokenHashTable();
- do
- {
- value = hashTable[hashcode];
- if (value == null)
- {
- // Not found.
- break;
- }
- // Check this value has the right category (regular token or separator token) that we are looking for.
- if (((int)value.tokenType & (int)TokenMask) > 0 && value.tokenString.Length <= remaining)
- {
- bool compareStrings = true;
- if (isLetter)
- {
- // If this token starts with a letter, make sure that we won't allow partial match. So you can't tokenize "MarchWed" separately.
- // Also an optimization to avoid string comparison
- int nextCharIndex = str.Index + value.tokenString.Length;
- if (nextCharIndex > str.Length)
- {
- compareStrings = false;
- }
- else if (nextCharIndex < str.Length)
- {
- // Check word boundary. The next character should NOT be a letter.
- char nextCh = str.Value[nextCharIndex];
- compareStrings = !char.IsLetter(nextCh) || IsAllowedJapaneseTokenFollowedByNonSpaceLetter(value.tokenString, nextCh);
- }
- }
-
- if (compareStrings &&
- ((value.tokenString.Length == 1 && str.Value[str.Index] == value.tokenString[0]) ||
- Culture.CompareInfo.Compare(str.Value.Slice(str.Index, value.tokenString.Length), value.tokenString, CompareOptions.IgnoreCase) == 0))
- {
- tokenType = value.tokenType & TokenMask;
- tokenValue = value.tokenValue;
- str.Advance(value.tokenString.Length);
- return true;
- }
- else if ((value.tokenType == TokenType.MonthToken && HasSpacesInMonthNames) ||
- (value.tokenType == TokenType.DayOfWeekToken && HasSpacesInDayNames))
- {
- // For month or day token, we will match the names which have spaces.
- int matchStrLen = 0;
- if (str.MatchSpecifiedWords(value.tokenString, true, ref matchStrLen))
- {
- tokenType = value.tokenType & TokenMask;
- tokenValue = value.tokenValue;
- str.Advance(matchStrLen);
- return true;
- }
- }
- }
- i++;
- hashcode += hashProbe;
- if (hashcode >= TOKEN_HASH_SIZE) hashcode -= TOKEN_HASH_SIZE;
- } while (i < TOKEN_HASH_SIZE);
-
- return false;
- }
-
- private void InsertAtCurrentHashNode(TokenHashValue[] hashTable, string str, char ch, TokenType tokenType, int tokenValue, int pos, int hashcode, int hashProbe)
- {
- // Remember the current slot.
- TokenHashValue previousNode = hashTable[hashcode];
-
- // Insert the new node into the current slot.
- hashTable[hashcode] = new TokenHashValue(str, tokenType, tokenValue);
-
- while (++pos < TOKEN_HASH_SIZE)
- {
- hashcode += hashProbe;
- if (hashcode >= TOKEN_HASH_SIZE) hashcode -= TOKEN_HASH_SIZE;
- // Remember this slot
- TokenHashValue temp = hashTable[hashcode];
-
- if (temp != null && Culture.TextInfo.ToLower(temp.tokenString[0]) != ch)
- {
- continue;
- }
- // Put the previous slot into this slot.
- hashTable[hashcode] = previousNode;
- if (temp == null)
- {
- // Done
- return;
- }
- previousNode = temp;
- }
- Debug.Fail("The hashtable is full. This should not happen.");
- }
-
- private void InsertHash(TokenHashValue[] hashTable, string str, TokenType tokenType, int tokenValue)
- {
- // The month of the 13th month is allowed to be null, so make sure that we ignore null value here.
- if (string.IsNullOrEmpty(str))
- {
- return;
- }
-
- TokenHashValue value;
- int i = 0;
- // If there is whitespace characters in the beginning and end of the string, trim them since whitespaces are skipped by
- // DateTime.Parse().
- if (char.IsWhiteSpace(str[0]) || char.IsWhiteSpace(str[^1]))
- {
- str = str.Trim(null); // Trim white space characters.
- // Could have space for separators
- if (str.Length == 0)
- {
- return;
- }
- }
-
- char ch = Culture.TextInfo.ToLower(str[0]);
- int hashcode = ch % TOKEN_HASH_SIZE;
- int hashProbe = 1 + ch % SECOND_PRIME;
- do
- {
- value = hashTable[hashcode];
- if (value == null)
- {
- hashTable[hashcode] = new TokenHashValue(str, tokenType, tokenValue);
- return;
- }
- else
- {
- // Collision happens. Find another slot.
- if (str.Length >= value.tokenString.Length)
- {
- // If there are two tokens with the same prefix, we have to make sure that the longer token should be at the front of
- // the shorter ones.
- if (CompareStringIgnoreCaseOptimized(str, 0, value.tokenString.Length, value.tokenString, 0, value.tokenString.Length))
- {
- if (str.Length > value.tokenString.Length)
- {
- // The str to be inserted has the same prefix as the current token, and str is longer.
- // Insert str into this node, and shift every node behind it.
- InsertAtCurrentHashNode(hashTable, str, ch, tokenType, tokenValue, i, hashcode, hashProbe);
- return;
- }
- else
- {
- // Same token. If they have different types (regular token vs separator token). Add them.
- // If we have the same regular token or separator token in the hash already, do NOT update the hash.
- // Therefore, the order of inserting token is significant here regarding what tokenType will be kept in the hash.
-
- // Check the current value of RegularToken (stored in the lower 8-bit of tokenType) , and insert the tokenType into the hash ONLY when we don't have a RegularToken yet.
- // Also check the current value of SeparatorToken (stored in the upper 8-bit of token), and insert the tokenType into the hash ONLY when we don't have the SeparatorToken yet.
-
- int nTokenType = (int)tokenType;
- int nCurrentTokenTypeInHash = (int)value.tokenType;
-
- // The folowing is the fix for the issue of throwing FormatException when "mar" is passed in string of the short date format dd/MMM/yyyy for es-MX
- if (((nCurrentTokenTypeInHash & (int)TokenType.RegularTokenMask) == 0) && ((nTokenType & (int)TokenType.RegularTokenMask) != 0) ||
- ((nCurrentTokenTypeInHash & (int)TokenType.SeparatorTokenMask) == 0) && ((nTokenType & (int)TokenType.SeparatorTokenMask) != 0))
- {
- value.tokenType |= tokenType;
- if (tokenValue != 0)
- {
- value.tokenValue = tokenValue;
- }
- }
- // The token to be inserted is already in the table. Skip it.
- return;
- }
- }
- }
- }
- i++;
- hashcode += hashProbe;
- if (hashcode >= TOKEN_HASH_SIZE) hashcode -= TOKEN_HASH_SIZE;
- } while (i < TOKEN_HASH_SIZE);
- Debug.Fail("The hashtable is full. This should not happen.");
- }
-
- private bool CompareStringIgnoreCaseOptimized(string string1, int offset1, int length1, string string2, int offset2, int length2)
- {
- // Optimize for one character cases which are common due to date and time separators (/ and :)
- if (length1 == 1 && length2 == 1 && string1[offset1] == string2[offset2])
- {
- return true;
- }
-
- return Culture.CompareInfo.Compare(string1, offset1, length1, string2, offset2, length2, CompareOptions.IgnoreCase) == 0;
- }
-
- internal class TokenHashValue
- {
- internal string tokenString;
- internal TokenType tokenType;
- internal int tokenValue;
-
- internal TokenHashValue(string tokenString, TokenType tokenType, int tokenValue)
- {
- this.tokenString = tokenString;
- this.tokenType = tokenType;
- this.tokenValue = tokenValue;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs
deleted file mode 100644
index 1ecdc35eac9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs
+++ /dev/null
@@ -1,712 +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.
-
-////////////////////////////////////////////////////////////////////////////
-//
-// DateTimeFormatInfoScanner
-//
-// Scan a specified DateTimeFormatInfo to search for data used in DateTime.Parse()
-//
-// The data includes:
-//
-// DateWords: such as "de" used in es-ES (Spanish) LongDatePattern.
-// Postfix: such as "ta" used in fi-FI after the month name.
-//
-// This class is shared among mscorlib.dll and sysglobl.dll.
-// Use conditional CULTURE_AND_REGIONINFO_BUILDER_ONLY to differentiate between
-// methods for mscorlib.dll and sysglobl.dll.
-//
-////////////////////////////////////////////////////////////////////////////
-
-using System.Collections.Generic;
-using System.Text;
-
-namespace System.Globalization
-{
- // from LocaleEx.txt header
- // IFORMATFLAGS
- internal enum FORMATFLAGS
- {
- None = 0x00000000,
- UseGenitiveMonth = 0x00000001,
- UseLeapYearMonth = 0x00000002,
- UseSpacesInMonthNames = 0x00000004,
- UseHebrewParsing = 0x00000008,
- UseSpacesInDayNames = 0x00000010, // Has spaces or non-breaking space in the day names.
- UseDigitPrefixInTokens = 0x00000020, // Has token starting with numbers.
- }
-
- internal enum CalendarId : ushort
- {
- UNINITIALIZED_VALUE = 0,
- GREGORIAN = 1, // Gregorian (localized) calendar
- GREGORIAN_US = 2, // Gregorian (U.S.) calendar
- JAPAN = 3, // Japanese Emperor Era calendar
- /* SSS_WARNINGS_OFF */
- TAIWAN = 4, // Taiwan Era calendar /* SSS_WARNINGS_ON */
- KOREA = 5, // Korean Tangun Era calendar
- HIJRI = 6, // Hijri (Arabic Lunar) calendar
- THAI = 7, // Thai calendar
- HEBREW = 8, // Hebrew (Lunar) calendar
- GREGORIAN_ME_FRENCH = 9, // Gregorian Middle East French calendar
- GREGORIAN_ARABIC = 10, // Gregorian Arabic calendar
- GREGORIAN_XLIT_ENGLISH = 11, // Gregorian Transliterated English calendar
- GREGORIAN_XLIT_FRENCH = 12,
- // Note that all calendars after this point are MANAGED ONLY for now.
- JULIAN = 13,
- JAPANESELUNISOLAR = 14,
- CHINESELUNISOLAR = 15,
- SAKA = 16, // reserved to match Office but not implemented in our code
- LUNAR_ETO_CHN = 17, // reserved to match Office but not implemented in our code
- LUNAR_ETO_KOR = 18, // reserved to match Office but not implemented in our code
- LUNAR_ETO_ROKUYOU = 19, // reserved to match Office but not implemented in our code
- KOREANLUNISOLAR = 20,
- TAIWANLUNISOLAR = 21,
- PERSIAN = 22,
- UMALQURA = 23,
- LAST_CALENDAR = 23 // Last calendar ID
- }
-
- internal class DateTimeFormatInfoScanner
- {
- // Special prefix-like flag char in DateWord array.
-
- // Use char in PUA area since we won't be using them in real data.
- // The char used to tell a read date word or a month postfix. A month postfix
- // is "ta" in the long date pattern like "d. MMMM'ta 'yyyy" for fi-FI.
- // In this case, it will be stored as "\xfffeta" in the date word array.
- internal const char MonthPostfixChar = '\xe000';
-
- // Add ignorable symbol in a DateWord array.
-
- // hu-HU has:
- // shrot date pattern: yyyy. MM. dd.;yyyy-MM-dd;yy-MM-dd
- // long date pattern: yyyy. MMMM d.
- // Here, "." is the date separator (derived from short date pattern). However,
- // "." also appear at the end of long date pattern. In this case, we just
- // "." as ignorable symbol so that the DateTime.Parse() state machine will not
- // treat the additional date separator at the end of y,m,d pattern as an error
- // condition.
- internal const char IgnorableSymbolChar = '\xe001';
-
- // Known CJK suffix
- internal const string CJKYearSuff = "\u5e74";
- internal const string CJKMonthSuff = "\u6708";
- internal const string CJKDaySuff = "\u65e5";
-
- internal const string KoreanYearSuff = "\ub144";
- internal const string KoreanMonthSuff = "\uc6d4";
- internal const string KoreanDaySuff = "\uc77c";
-
- internal const string KoreanHourSuff = "\uc2dc";
- internal const string KoreanMinuteSuff = "\ubd84";
- internal const string KoreanSecondSuff = "\ucd08";
-
- internal const string CJKHourSuff = "\u6642";
- internal const string ChineseHourSuff = "\u65f6";
-
- internal const string CJKMinuteSuff = "\u5206";
- internal const string CJKSecondSuff = "\u79d2";
-
- // The collection fo date words & postfix.
- internal List<string> m_dateWords = new List<string>();
- // Hashtable for the known words.
- private static volatile Dictionary<string, string>? s_knownWords;
-
- private static Dictionary<string, string> KnownWords =>
- s_knownWords ??=
- new Dictionary<string, string>(16)
- {
- // Add known words into the hash table.
-
- // Skip these special symbols.
- { "/", string.Empty },
- { "-", string.Empty },
- { ".", string.Empty },
-
- // Skip known CJK suffixes.
- { CJKYearSuff, string.Empty },
- { CJKMonthSuff, string.Empty },
- { CJKDaySuff, string.Empty },
- { KoreanYearSuff, string.Empty },
- { KoreanMonthSuff, string.Empty },
- { KoreanDaySuff, string.Empty },
- { KoreanHourSuff, string.Empty },
- { KoreanMinuteSuff, string.Empty },
- { KoreanSecondSuff, string.Empty },
- { CJKHourSuff, string.Empty },
- { ChineseHourSuff, string.Empty },
- { CJKMinuteSuff, string.Empty },
- { CJKSecondSuff, string.Empty }
- };
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Parameters:
- // pattern: The pattern to be scanned.
- // currentIndex: the current index to start the scan.
- //
- // Returns:
- // Return the index with the first character that is a letter, which will
- // be the start of a date word.
- // Note that the index can be pattern.Length if we reach the end of the string.
- //
- ////////////////////////////////////////////////////////////////////////////
- internal static int SkipWhiteSpacesAndNonLetter(string pattern, int currentIndex)
- {
- while (currentIndex < pattern.Length)
- {
- char ch = pattern[currentIndex];
- if (ch == '\\')
- {
- // Escaped character. Look ahead one character.
- currentIndex++;
- if (currentIndex < pattern.Length)
- {
- ch = pattern[currentIndex];
- if (ch == '\'')
- {
- // Skip the leading single quote. We will
- // stop at the first letter.
- continue;
- }
- // Fall thru to check if this is a letter.
- }
- else
- {
- // End of string
- break;
- }
- }
- if (char.IsLetter(ch) || ch == '\'' || ch == '.')
- {
- break;
- }
- // Skip the current char since it is not a letter.
- currentIndex++;
- }
- return currentIndex;
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // A helper to add the found date word or month postfix into ArrayList for date words.
- //
- // Parameters:
- // formatPostfix: What kind of postfix this is.
- // Possible values:
- // null: This is a regular date word
- // "MMMM": month postfix
- // word: The date word or postfix to be added.
- //
- ////////////////////////////////////////////////////////////////////////////
- internal void AddDateWordOrPostfix(string? formatPostfix, string str)
- {
- if (str.Length > 0)
- {
- // Some cultures use . like an abbreviation
- if (str.Equals("."))
- {
- AddIgnorableSymbols(".");
- return;
- }
-
- if (!KnownWords.TryGetValue(str, out _))
- {
- m_dateWords ??= new List<string>();
-
- if (formatPostfix == "MMMM")
- {
- // Add the word into the ArrayList as "\xfffe" + real month postfix.
- string temp = MonthPostfixChar + str;
- if (!m_dateWords.Contains(temp))
- {
- m_dateWords.Add(temp);
- }
- }
- else
- {
- if (!m_dateWords.Contains(str))
- {
- m_dateWords.Add(str);
- }
- if (str[^1] == '.')
- {
- // Old version ignore the trailing dot in the date words. Support this as well.
- string strWithoutDot = str[0..^1];
- if (!m_dateWords.Contains(strWithoutDot))
- {
- m_dateWords.Add(strWithoutDot);
- }
- }
- }
- }
- }
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Scan the pattern from the specified index and add the date word/postfix
- // when appropriate.
- //
- // Parameters:
- // pattern: The pattern to be scanned.
- // index: The starting index to be scanned.
- // formatPostfix: The kind of postfix to be scanned.
- // Possible values:
- // null: This is a regular date word
- // "MMMM": month postfix
- //
- //
- ////////////////////////////////////////////////////////////////////////////
- internal int AddDateWords(string pattern, int index, string? formatPostfix)
- {
- // Skip any whitespaces so we will start from a letter.
- int newIndex = SkipWhiteSpacesAndNonLetter(pattern, index);
- if (newIndex != index && formatPostfix != null)
- {
- // There are whitespaces. This will not be a postfix.
- formatPostfix = null;
- }
- index = newIndex;
-
- // This is the first char added into dateWord.
- // Skip all non-letter character. We will add the first letter into DateWord.
- StringBuilder dateWord = new StringBuilder();
- // We assume that date words should start with a letter.
- // Skip anything until we see a letter.
-
- while (index < pattern.Length)
- {
- char ch = pattern[index];
- if (ch == '\'')
- {
- // We have seen the end of quote. Add the word if we do not see it before,
- // and break the while loop.
- AddDateWordOrPostfix(formatPostfix, dateWord.ToString());
- index++;
- break;
- }
- else if (ch == '\\')
- {
- //
- // Escaped character. Look ahead one character
- //
-
- // Skip escaped backslash.
- index++;
- if (index < pattern.Length)
- {
- dateWord.Append(pattern[index]);
- index++;
- }
- }
- else if (char.IsWhiteSpace(ch))
- {
- // Found a whitespace. We have to add the current date word/postfix.
- AddDateWordOrPostfix(formatPostfix, dateWord.ToString());
- if (formatPostfix != null)
- {
- // Done with postfix. The rest will be regular date word.
- formatPostfix = null;
- }
- // Reset the dateWord.
- dateWord.Length = 0;
- index++;
- }
- else
- {
- dateWord.Append(ch);
- index++;
- }
- }
- return index;
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // A simple helper to find the repeat count for a specified char.
- //
- ////////////////////////////////////////////////////////////////////////////
- internal static int ScanRepeatChar(string pattern, char ch, int index, out int count)
- {
- count = 1;
- while (++index < pattern.Length && pattern[index] == ch)
- {
- count++;
- }
- // Return the updated position.
- return index;
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Add the text that is a date separator but is treated like ignorable symbol.
- // E.g.
- // hu-HU has:
- // short date pattern: yyyy. MM. dd.;yyyy-MM-dd;yy-MM-dd
- // long date pattern: yyyy. MMMM d.
- // Here, "." is the date separator (derived from short date pattern). However,
- // "." also appear at the end of long date pattern. In this case, we just
- // "." as ignorable symbol so that the DateTime.Parse() state machine will not
- // treat the additional date separator at the end of y,m,d pattern as an error
- // condition.
- //
- ////////////////////////////////////////////////////////////////////////////
-
- internal void AddIgnorableSymbols(string? text)
- {
- if (m_dateWords == null)
- {
- // Create the date word array.
- m_dateWords = new List<string>();
- }
- // Add the ignorable symbol into the ArrayList.
- string temp = IgnorableSymbolChar + text;
- if (!m_dateWords.Contains(temp))
- {
- m_dateWords.Add(temp);
- }
- }
-
- //
- // Flag used to trace the date patterns (yy/yyyyy/M/MM/MMM/MMM/d/dd) that we have seen.
- //
- private enum FoundDatePattern
- {
- None = 0x0000,
- FoundYearPatternFlag = 0x0001,
- FoundMonthPatternFlag = 0x0002,
- FoundDayPatternFlag = 0x0004,
- FoundYMDPatternFlag = 0x0007, // FoundYearPatternFlag | FoundMonthPatternFlag | FoundDayPatternFlag;
- }
-
- // Check if we have found all of the year/month/day pattern.
- private FoundDatePattern _ymdFlags = FoundDatePattern.None;
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Given a date format pattern, scan for date word or postfix.
- //
- // A date word should be always put in a single quoted string. And it will
- // start from a letter, so whitespace and symbols will be ignored before
- // the first letter.
- //
- // Examples of date word:
- // 'de' in es-SP: dddd, dd' de 'MMMM' de 'yyyy
- // "\x0443." in bg-BG: dd.M.yyyy '\x0433.'
- //
- // Example of postfix:
- // month postfix:
- // "ta" in fi-FI: d. MMMM'ta 'yyyy
- // Currently, only month postfix is supported.
- //
- // Usage:
- // Always call this with Framework-style pattern, instead of Windows style pattern.
- // Windows style pattern uses '' for single quote, while .NET uses \'
- //
- ////////////////////////////////////////////////////////////////////////////
- internal void ScanDateWord(string pattern)
- {
- // Check if we have found all of the year/month/day pattern.
- _ymdFlags = FoundDatePattern.None;
-
- int i = 0;
- while (i < pattern.Length)
- {
- char ch = pattern[i];
- int chCount;
-
- switch (ch)
- {
- case '\'':
- // Find a beginning quote. Search until the end quote.
- i = AddDateWords(pattern, i + 1, null);
- break;
- case 'M':
- i = ScanRepeatChar(pattern, 'M', i, out chCount);
- if (chCount >= 4)
- {
- if (i < pattern.Length && pattern[i] == '\'')
- {
- i = AddDateWords(pattern, i + 1, "MMMM");
- }
- }
- _ymdFlags |= FoundDatePattern.FoundMonthPatternFlag;
- break;
- case 'y':
- i = ScanRepeatChar(pattern, 'y', i, out chCount);
- _ymdFlags |= FoundDatePattern.FoundYearPatternFlag;
- break;
- case 'd':
- i = ScanRepeatChar(pattern, 'd', i, out chCount);
- if (chCount <= 2)
- {
- // Only count "d" & "dd".
- // ddd, dddd are day names. Do not count them.
- _ymdFlags |= FoundDatePattern.FoundDayPatternFlag;
- }
- break;
- case '\\':
- // Found a escaped char not in a quoted string. Skip the current backslash
- // and its next character.
- i += 2;
- break;
- case '.':
- if (_ymdFlags == FoundDatePattern.FoundYMDPatternFlag)
- {
- // If we find a dot immediately after the we have seen all of the y, m, d pattern.
- // treat it as a ignroable symbol. Check for comments in AddIgnorableSymbols for
- // more details.
- AddIgnorableSymbols(".");
- _ymdFlags = FoundDatePattern.None;
- }
- i++;
- break;
- default:
- if (_ymdFlags == FoundDatePattern.FoundYMDPatternFlag && !char.IsWhiteSpace(ch))
- {
- // We are not seeing "." after YMD. Clear the flag.
- _ymdFlags = FoundDatePattern.None;
- }
- // We are not in quote. Skip the current character.
- i++;
- break;
- }
- }
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Given a DTFI, get all of the date words from date patterns and time patterns.
- //
- ////////////////////////////////////////////////////////////////////////////
-
- internal string[]? GetDateWordsOfDTFI(DateTimeFormatInfo dtfi)
- {
- // Enumarate all LongDatePatterns, and get the DateWords and scan for month postfix.
- string[] datePatterns = dtfi.GetAllDateTimePatterns('D');
- int i;
-
- // Scan the long date patterns
- for (i = 0; i < datePatterns.Length; i++)
- {
- ScanDateWord(datePatterns[i]);
- }
-
- // Scan the short date patterns
- datePatterns = dtfi.GetAllDateTimePatterns('d');
- for (i = 0; i < datePatterns.Length; i++)
- {
- ScanDateWord(datePatterns[i]);
- }
- // Scan the YearMonth patterns.
- datePatterns = dtfi.GetAllDateTimePatterns('y');
- for (i = 0; i < datePatterns.Length; i++)
- {
- ScanDateWord(datePatterns[i]);
- }
-
- // Scan the month/day pattern
- ScanDateWord(dtfi.MonthDayPattern);
-
- // Scan the long time patterns.
- datePatterns = dtfi.GetAllDateTimePatterns('T');
- for (i = 0; i < datePatterns.Length; i++)
- {
- ScanDateWord(datePatterns[i]);
- }
-
- // Scan the short time patterns.
- datePatterns = dtfi.GetAllDateTimePatterns('t');
- for (i = 0; i < datePatterns.Length; i++)
- {
- ScanDateWord(datePatterns[i]);
- }
-
- string[]? result = null;
- if (m_dateWords != null && m_dateWords.Count > 0)
- {
- result = new string[m_dateWords.Count];
- for (i = 0; i < m_dateWords.Count; i++)
- {
- result[i] = m_dateWords[i];
- }
- }
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Scan the month names to see if genitive month names are used, and return
- // the format flag.
- //
- ////////////////////////////////////////////////////////////////////////////
- internal static FORMATFLAGS GetFormatFlagGenitiveMonth(string[] monthNames, string[] genitveMonthNames, string[] abbrevMonthNames, string[] genetiveAbbrevMonthNames)
- {
- // If we have different names in regular and genitive month names, use genitive month flag.
- return (!EqualStringArrays(monthNames, genitveMonthNames) || !EqualStringArrays(abbrevMonthNames, genetiveAbbrevMonthNames))
- ? FORMATFLAGS.UseGenitiveMonth : 0;
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Scan the month names to see if spaces are used or start with a digit, and return the format flag
- //
- ////////////////////////////////////////////////////////////////////////////
- internal static FORMATFLAGS GetFormatFlagUseSpaceInMonthNames(string[] monthNames, string[] genitveMonthNames, string[] abbrevMonthNames, string[] genetiveAbbrevMonthNames)
- {
- FORMATFLAGS formatFlags = 0;
- formatFlags |= (ArrayElementsBeginWithDigit(monthNames) ||
- ArrayElementsBeginWithDigit(genitveMonthNames) ||
- ArrayElementsBeginWithDigit(abbrevMonthNames) ||
- ArrayElementsBeginWithDigit(genetiveAbbrevMonthNames)
- ? FORMATFLAGS.UseDigitPrefixInTokens : 0);
-
- formatFlags |= (ArrayElementsHaveSpace(monthNames) ||
- ArrayElementsHaveSpace(genitveMonthNames) ||
- ArrayElementsHaveSpace(abbrevMonthNames) ||
- ArrayElementsHaveSpace(genetiveAbbrevMonthNames)
- ? FORMATFLAGS.UseSpacesInMonthNames : 0);
- return formatFlags;
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Scan the day names and set the correct format flag.
- //
- ////////////////////////////////////////////////////////////////////////////
- internal static FORMATFLAGS GetFormatFlagUseSpaceInDayNames(string[] dayNames, string[] abbrevDayNames)
- {
- return (ArrayElementsHaveSpace(dayNames) ||
- ArrayElementsHaveSpace(abbrevDayNames))
- ? FORMATFLAGS.UseSpacesInDayNames : 0;
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Check the calendar to see if it is HebrewCalendar and set the Hebrew format flag if necessary.
- //
- ////////////////////////////////////////////////////////////////////////////
- internal static FORMATFLAGS GetFormatFlagUseHebrewCalendar(int calID)
- {
- return calID == (int)CalendarId.HEBREW ?
- FORMATFLAGS.UseHebrewParsing | FORMATFLAGS.UseLeapYearMonth : 0;
- }
-
- //-----------------------------------------------------------------------------
- // EqualStringArrays
- // compares two string arrays and return true if all elements of the first
- // array equals to all elements of the second array.
- // otherwise it returns false.
- //-----------------------------------------------------------------------------
-
- private static bool EqualStringArrays(string[] array1, string[] array2)
- {
- // Shortcut if they're the same array
- if (array1 == array2)
- {
- return true;
- }
-
- // This is effectively impossible
- if (array1.Length != array2.Length)
- {
- return false;
- }
-
- // Check each string
- for (int i = 0; i < array1.Length; i++)
- {
- if (array1[i] != array2[i])
- {
- return false;
- }
- }
-
- return true;
- }
-
- //-----------------------------------------------------------------------------
- // ArrayElementsHaveSpace
- // It checks all input array elements if any of them has space character
- // returns true if found space character in one of the array elements.
- // otherwise returns false.
- //-----------------------------------------------------------------------------
-
- private static bool ArrayElementsHaveSpace(string[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- // it is faster to check for space character manually instead of calling IndexOf
- // so we don't have to go to native code side.
- for (int j = 0; j < array[i].Length; j++)
- {
- if (char.IsWhiteSpace(array[i][j]))
- {
- return true;
- }
- }
- }
-
- return false;
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Check if any element of the array start with a digit.
- //
- ////////////////////////////////////////////////////////////////////////////
- private static bool ArrayElementsBeginWithDigit(string[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- // it is faster to check for space character manually instead of calling IndexOf
- // so we don't have to go to native code side.
- if (array[i].Length > 0 &&
- array[i][0] >= '0' && array[i][0] <= '9')
- {
- int index = 1;
- while (index < array[i].Length && array[i][index] >= '0' && array[i][index] <= '9')
- {
- // Skip other digits.
- index++;
- }
- if (index == array[i].Length)
- {
- return false;
- }
-
- if (index == array[i].Length - 1)
- {
- // Skip known CJK month suffix.
- // CJK uses month name like "1\x6708", since \x6708 is a known month suffix,
- // we don't need the UseDigitPrefixInTokens since it is slower.
- switch (array[i][index])
- {
- case '\x6708': // CJKMonthSuff
- case '\xc6d4': // KoreanMonthSuff
- return false;
- }
- }
-
- if (index == array[i].Length - 4)
- {
- // Skip known CJK month suffix.
- // Starting with Windows 8, the CJK months for some cultures looks like: "1' \x6708'"
- // instead of just "1\x6708"
- if (array[i][index] == '\'' && array[i][index + 1] == ' ' &&
- array[i][index + 2] == '\x6708' && array[i][index + 3] == '\'')
- {
- return false;
- }
- }
- return true;
- }
- }
-
- return false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs
deleted file mode 100644
index 50002e6e04e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs
+++ /dev/null
@@ -1,6106 +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 System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System
-{
- internal static class DateTimeParse
- {
- internal const int MaxDateTimeNumberDigits = 8;
-
- internal delegate bool MatchNumberDelegate(ref __DTString str, int digitLen, out int result);
-
- internal static MatchNumberDelegate m_hebrewNumberParser = new MatchNumberDelegate(DateTimeParse.MatchHebrewDigits);
-
- internal static DateTime ParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, DateTimeStyles style)
- {
- DateTimeResult result = default; // The buffer to store the parsing result.
- result.Init(s);
- if (TryParseExact(s, format, dtfi, style, ref result))
- {
- return result.parsedDate;
- }
- else
- {
- throw GetDateTimeParseException(ref result);
- }
- }
-
- internal static DateTime ParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, DateTimeStyles style, out TimeSpan offset)
- {
- DateTimeResult result = default; // The buffer to store the parsing result.
- result.Init(s);
- result.flags |= ParseFlags.CaptureOffset;
- if (TryParseExact(s, format, dtfi, style, ref result))
- {
- offset = result.timeZoneOffset;
- return result.parsedDate;
- }
- else
- {
- throw GetDateTimeParseException(ref result);
- }
- }
-
- internal static bool TryParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result)
- {
- DateTimeResult resultData = default; // The buffer to store the parsing result.
- resultData.Init(s);
-
- if (TryParseExact(s, format, dtfi, style, ref resultData))
- {
- result = resultData.parsedDate;
- return true;
- }
-
- result = DateTime.MinValue;
- return false;
- }
-
- internal static bool TryParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result, out TimeSpan offset)
- {
- DateTimeResult resultData = default; // The buffer to store the parsing result.
- resultData.Init(s);
- resultData.flags |= ParseFlags.CaptureOffset;
-
- if (TryParseExact(s, format, dtfi, style, ref resultData))
- {
- result = resultData.parsedDate;
- offset = resultData.timeZoneOffset;
- return true;
- }
-
- result = DateTime.MinValue;
- offset = TimeSpan.Zero;
- return false;
- }
-
- internal static bool TryParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, DateTimeStyles style, ref DateTimeResult result)
- {
- if (s.Length == 0)
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDateTime));
- return false;
- }
-
- if (format.Length == 0)
- {
- result.SetBadFormatSpecifierFailure();
- return false;
- }
-
- Debug.Assert(dtfi != null, "dtfi == null");
-
- return DoStrictParse(s, format, style, dtfi, ref result);
- }
-
- internal static DateTime ParseExactMultiple(ReadOnlySpan<char> s, string[] formats,
- DateTimeFormatInfo dtfi, DateTimeStyles style)
- {
- DateTimeResult result = default; // The buffer to store the parsing result.
- result.Init(s);
- if (TryParseExactMultiple(s, formats, dtfi, style, ref result))
- {
- return result.parsedDate;
- }
- else
- {
- throw GetDateTimeParseException(ref result);
- }
- }
-
- internal static DateTime ParseExactMultiple(ReadOnlySpan<char> s, string[] formats,
- DateTimeFormatInfo dtfi, DateTimeStyles style, out TimeSpan offset)
- {
- DateTimeResult result = default; // The buffer to store the parsing result.
- result.Init(s);
- result.flags |= ParseFlags.CaptureOffset;
- if (TryParseExactMultiple(s, formats, dtfi, style, ref result))
- {
- offset = result.timeZoneOffset;
- return result.parsedDate;
- }
- else
- {
- throw GetDateTimeParseException(ref result);
- }
- }
-
- internal static bool TryParseExactMultiple(ReadOnlySpan<char> s, string?[]? formats,
- DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result, out TimeSpan offset)
- {
- DateTimeResult resultData = default; // The buffer to store the parsing result.
- resultData.Init(s);
- resultData.flags |= ParseFlags.CaptureOffset;
-
- if (TryParseExactMultiple(s, formats, dtfi, style, ref resultData))
- {
- result = resultData.parsedDate;
- offset = resultData.timeZoneOffset;
- return true;
- }
-
- result = DateTime.MinValue;
- offset = TimeSpan.Zero;
- return false;
- }
-
- internal static bool TryParseExactMultiple(ReadOnlySpan<char> s, string?[]? formats,
- DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result)
- {
- DateTimeResult resultData = default; // The buffer to store the parsing result.
- resultData.Init(s);
-
- if (TryParseExactMultiple(s, formats, dtfi, style, ref resultData))
- {
- result = resultData.parsedDate;
- return true;
- }
-
- result = DateTime.MinValue;
- return false;
- }
-
- internal static bool TryParseExactMultiple(ReadOnlySpan<char> s, string?[]? formats,
- DateTimeFormatInfo dtfi, DateTimeStyles style, ref DateTimeResult result)
- {
- if (formats == null)
- {
- result.SetFailure(ParseFailureKind.ArgumentNull, nameof(SR.ArgumentNull_String), null, nameof(formats));
- return false;
- }
-
- if (s.Length == 0)
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDateTime));
- return false;
- }
-
- if (formats.Length == 0)
- {
- result.SetFailure(ParseFailureKind.Format, nameof(SR.Format_NoFormatSpecifier));
- return false;
- }
-
- Debug.Assert(dtfi != null, "dtfi == null");
-
- //
- // Do a loop through the provided formats and see if we can parse successfully in
- // one of the formats.
- //
- for (int i = 0; i < formats.Length; i++)
- {
- if (formats[i] == null || formats[i]!.Length == 0) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- {
- result.SetBadFormatSpecifierFailure();
- return false;
- }
- // Create a new result each time to ensure the runs are independent. Carry through
- // flags from the caller and return the result.
- DateTimeResult innerResult = default; // The buffer to store the parsing result.
- innerResult.Init(s);
- innerResult.flags = result.flags;
- if (TryParseExact(s, formats[i], dtfi, style, ref innerResult))
- {
- result.parsedDate = innerResult.parsedDate;
- result.timeZoneOffset = innerResult.timeZoneOffset;
- return true;
- }
- }
- result.SetBadDateTimeFailure();
- return false;
- }
-
- ////////////////////////////////////////////////////////////////////////////
- // Date Token Types
- //
- // Following is the set of tokens that can be generated from a date
- // string. Notice that the legal set of trailing separators have been
- // folded in with the date number, and month name tokens. This set
- // of tokens is chosen to reduce the number of date parse states.
- //
- ////////////////////////////////////////////////////////////////////////////
-
- internal enum DTT : int
- {
- End = 0, // '\0'
- NumEnd = 1, // Num[ ]*[\0]
- NumAmpm = 2, // Num[ ]+AmPm
- NumSpace = 3, // Num[ ]+^[Dsep|Tsep|'0\']
- NumDatesep = 4, // Num[ ]*Dsep
- NumTimesep = 5, // Num[ ]*Tsep
- MonthEnd = 6, // Month[ ]*'\0'
- MonthSpace = 7, // Month[ ]+^[Dsep|Tsep|'\0']
- MonthDatesep = 8, // Month[ ]*Dsep
- NumDatesuff = 9, // Month[ ]*DSuff
- NumTimesuff = 10, // Month[ ]*TSuff
- DayOfWeek = 11, // Day of week name
- YearSpace = 12, // Year+^[Dsep|Tsep|'0\']
- YearDateSep = 13, // Year+Dsep
- YearEnd = 14, // Year+['\0']
- TimeZone = 15, // timezone name
- Era = 16, // era name
- NumUTCTimeMark = 17, // Num + 'Z'
- // When you add a new token which will be in the
- // state table, add it after NumLocalTimeMark.
- Unk = 18, // unknown
- NumLocalTimeMark = 19, // Num + 'T'
- Max = 20, // marker
- }
-
- internal enum TM
- {
- NotSet = -1,
- AM = 0,
- PM = 1,
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // DateTime parsing state enumeration (DS.*)
- //
- ////////////////////////////////////////////////////////////////////////////
-
- internal enum DS
- {
- BEGIN = 0,
- N = 1, // have one number
- NN = 2, // have two numbers
-
- // The following are known to be part of a date
-
- D_Nd = 3, // date string: have number followed by date separator
- D_NN = 4, // date string: have two numbers
- D_NNd = 5, // date string: have two numbers followed by date separator
-
- D_M = 6, // date string: have a month
- D_MN = 7, // date string: have a month and a number
- D_NM = 8, // date string: have a number and a month
- D_MNd = 9, // date string: have a month and number followed by date separator
- D_NDS = 10, // date string: have one number followed a date suffix.
-
- D_Y = 11, // date string: have a year.
- D_YN = 12, // date string: have a year and a number
- D_YNd = 13, // date string: have a year and a number and a date separator
- D_YM = 14, // date string: have a year and a month
- D_YMd = 15, // date string: have a year and a month and a date separator
- D_S = 16, // have numbers followed by a date suffix.
- T_S = 17, // have numbers followed by a time suffix.
-
- // The following are known to be part of a time
-
- T_Nt = 18, // have num followed by time separator
- T_NNt = 19, // have two numbers followed by time separator
-
- ERROR = 20,
-
- // The following are terminal states. These all have an action
- // associated with them; and transition back to BEGIN.
-
- DX_NN = 21, // day from two numbers
- DX_NNN = 22, // day from three numbers
- DX_MN = 23, // day from month and one number
- DX_NM = 24, // day from month and one number
- DX_MNN = 25, // day from month and two numbers
- DX_DS = 26, // a set of date suffixed numbers.
- DX_DSN = 27, // day from date suffixes and one number.
- DX_NDS = 28, // day from one number and date suffixes .
- DX_NNDS = 29, // day from one number and date suffixes .
-
- DX_YNN = 30, // date string: have a year and two number
- DX_YMN = 31, // date string: have a year, a month, and a number.
- DX_YN = 32, // date string: have a year and one number
- DX_YM = 33, // date string: have a year, a month.
- TX_N = 34, // time from one number (must have ampm)
- TX_NN = 35, // time from two numbers
- TX_NNN = 36, // time from three numbers
- TX_TS = 37, // a set of time suffixed numbers.
- DX_NNY = 38,
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // NOTE: The following state machine table is dependent on the order of the
- // DS and DTT enumerations.
- //
- // For each non terminal state, the following table defines the next state
- // for each given date token type.
- //
- ////////////////////////////////////////////////////////////////////////////
-
- // End NumEnd NumAmPm NumSpace NumDaySep NumTimesep MonthEnd MonthSpace MonthDSep NumDateSuff NumTimeSuff DayOfWeek YearSpace YearDateSep YearEnd TimeZone Era UTCTimeMark
- private static readonly DS[][] dateParsingStates = {
-// DS.BEGIN // DS.BEGIN
-new DS[] { DS.BEGIN, DS.ERROR, DS.TX_N, DS.N, DS.D_Nd, DS.T_Nt, DS.ERROR, DS.D_M, DS.D_M, DS.D_S, DS.T_S, DS.BEGIN, DS.D_Y, DS.D_Y, DS.ERROR, DS.BEGIN, DS.BEGIN, DS.ERROR },
-
-// DS.N // DS.N
-new DS[] { DS.ERROR, DS.DX_NN, DS.ERROR, DS.NN, DS.D_NNd, DS.ERROR, DS.DX_NM, DS.D_NM, DS.D_MNd, DS.D_NDS, DS.ERROR, DS.N, DS.D_YN, DS.D_YNd, DS.DX_YN, DS.N, DS.N, DS.ERROR },
-
-// DS.NN // DS.NN
-new DS[] { DS.DX_NN, DS.DX_NNN, DS.TX_N, DS.DX_NNN, DS.ERROR, DS.T_Nt, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.ERROR, DS.T_S, DS.NN, DS.DX_NNY, DS.ERROR, DS.DX_NNY, DS.NN, DS.NN, DS.ERROR },
-
-// DS.D_Nd // DS.D_Nd
-new DS[] { DS.ERROR, DS.DX_NN, DS.ERROR, DS.D_NN, DS.D_NNd, DS.ERROR, DS.DX_NM, DS.D_MN, DS.D_MNd, DS.ERROR, DS.ERROR, DS.D_Nd, DS.D_YN, DS.D_YNd, DS.DX_YN, DS.ERROR, DS.D_Nd, DS.ERROR },
-
-// DS.D_NN // DS.D_NN
-new DS[] { DS.DX_NN, DS.DX_NNN, DS.TX_N, DS.DX_NNN, DS.ERROR, DS.T_Nt, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.DX_DS, DS.T_S, DS.D_NN, DS.DX_NNY, DS.ERROR, DS.DX_NNY, DS.ERROR, DS.D_NN, DS.ERROR },
-
-// DS.D_NNd // DS.D_NNd
-new DS[] { DS.ERROR, DS.DX_NNN, DS.DX_NNN, DS.DX_NNN, DS.ERROR, DS.ERROR, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.DX_DS, DS.ERROR, DS.D_NNd, DS.DX_NNY, DS.ERROR, DS.DX_NNY, DS.ERROR, DS.D_NNd, DS.ERROR },
-
-// DS.D_M // DS.D_M
-new DS[] { DS.ERROR, DS.DX_MN, DS.ERROR, DS.D_MN, DS.D_MNd, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_M, DS.D_YM, DS.D_YMd, DS.DX_YM, DS.ERROR, DS.D_M, DS.ERROR },
-
-// DS.D_MN // DS.D_MN
-new DS[] { DS.DX_MN, DS.DX_MNN, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.DX_DS, DS.T_S, DS.D_MN, DS.DX_YMN, DS.ERROR, DS.DX_YMN, DS.ERROR, DS.D_MN, DS.ERROR },
-
-// DS.D_NM // DS.D_NM
-new DS[] { DS.DX_NM, DS.DX_MNN, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.DX_DS, DS.T_S, DS.D_NM, DS.DX_YMN, DS.ERROR, DS.DX_YMN, DS.ERROR, DS.D_NM, DS.ERROR },
-
-// DS.D_MNd // DS.D_MNd
-new DS[] { DS.ERROR, DS.DX_MNN, DS.ERROR, DS.DX_MNN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_MNd, DS.DX_YMN, DS.ERROR, DS.DX_YMN, DS.ERROR, DS.D_MNd, DS.ERROR },
-
-// DS.D_NDS, // DS.D_NDS,
-new DS[] { DS.DX_NDS, DS.DX_NNDS, DS.DX_NNDS, DS.DX_NNDS, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_NDS, DS.T_S, DS.D_NDS, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_NDS, DS.ERROR },
-
-// DS.D_Y // DS.D_Y
-new DS[] { DS.ERROR, DS.DX_YN, DS.ERROR, DS.D_YN, DS.D_YNd, DS.ERROR, DS.DX_YM, DS.D_YM, DS.D_YMd, DS.D_YM, DS.ERROR, DS.D_Y, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_Y, DS.ERROR },
-
-// DS.D_YN // DS.D_YN
-new DS[] { DS.DX_YN, DS.DX_YNN, DS.DX_YNN, DS.DX_YNN, DS.ERROR, DS.ERROR, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR },
-
-// DS.D_YNd // DS.D_YNd
-new DS[] { DS.ERROR, DS.DX_YNN, DS.DX_YNN, DS.DX_YNN, DS.ERROR, DS.ERROR, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR },
-
-// DS.D_YM // DS.D_YM
-new DS[] { DS.DX_YM, DS.DX_YMN, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR },
-
-// DS.D_YMd // DS.D_YMd
-new DS[] { DS.ERROR, DS.DX_YMN, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR },
-
-// DS.D_S // DS.D_S
-new DS[] { DS.DX_DS, DS.DX_DSN, DS.TX_N, DS.T_Nt, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_S, DS.T_S, DS.D_S, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_S, DS.ERROR },
-
-// DS.T_S // DS.T_S
-new DS[] { DS.TX_TS, DS.TX_TS, DS.TX_TS, DS.T_Nt, DS.D_Nd, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_S, DS.T_S, DS.T_S, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_S, DS.T_S, DS.ERROR },
-
-// DS.T_Nt // DS.T_Nt
-new DS[] { DS.ERROR, DS.TX_NN, DS.TX_NN, DS.TX_NN, DS.ERROR, DS.T_NNt, DS.DX_NM, DS.D_NM, DS.ERROR, DS.ERROR, DS.T_S, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_Nt, DS.T_Nt, DS.TX_NN },
-
-// DS.T_NNt // DS.T_NNt
-new DS[] { DS.ERROR, DS.TX_NNN, DS.TX_NNN, DS.TX_NNN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_S, DS.T_NNt, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_NNt, DS.T_NNt, DS.TX_NNN },
-};
- // End NumEnd NumAmPm NumSpace NumDaySep NumTimesep MonthEnd MonthSpace MonthDSep NumDateSuff NumTimeSuff DayOfWeek YearSpace YearDateSep YearEnd TimeZone Era UTCMark
-
- internal const string GMTName = "GMT";
- internal const string ZuluName = "Z";
-
- //
- // Search from the index of str at str.Index to see if the target string exists in the str.
- //
- private static bool MatchWord(ref __DTString str, string target)
- {
- if (target.Length > (str.Value.Length - str.Index))
- {
- return false;
- }
-
- if (str.CompareInfo.Compare(str.Value.Slice(str.Index, target.Length), target, CompareOptions.IgnoreCase) != 0)
- {
- return false;
- }
-
- int nextCharIndex = str.Index + target.Length;
-
- if (nextCharIndex < str.Value.Length)
- {
- char nextCh = str.Value[nextCharIndex];
- if (char.IsLetter(nextCh))
- {
- return false;
- }
- }
- str.Index = nextCharIndex;
- if (str.Index < str.Length)
- {
- str.m_current = str.Value[str.Index];
- }
-
- return true;
- }
-
- //
- // Check the word at the current index to see if it matches GMT name or Zulu name.
- //
- private static bool GetTimeZoneName(ref __DTString str)
- {
- if (MatchWord(ref str, GMTName))
- {
- return true;
- }
-
- if (MatchWord(ref str, ZuluName))
- {
- return true;
- }
-
- return false;
- }
-
- internal static bool IsDigit(char ch) => (uint)(ch - '0') <= 9;
-
- /*=================================ParseFraction==========================
- **Action: Starting at the str.Index, which should be a decimal symbol.
- ** if the current character is a digit, parse the remaining
- ** numbers as fraction. For example, if the sub-string starting at str.Index is "123", then
- ** the method will return 0.123
- **Returns: The fraction number.
- **Arguments:
- ** str the parsing string
- **Exceptions:
- ============================================================================*/
-
- private static bool ParseFraction(ref __DTString str, out double result)
- {
- result = 0;
- double decimalBase = 0.1;
- int digits = 0;
- char ch;
- while (str.GetNext()
- && IsDigit(ch = str.m_current))
- {
- result += (ch - '0') * decimalBase;
- decimalBase *= 0.1;
- digits++;
- }
- return digits > 0;
- }
-
- /*=================================ParseTimeZone==========================
- **Action: Parse the timezone offset in the following format:
- ** "+8", "+08", "+0800", "+0800"
- ** This method is used by DateTime.Parse().
- **Returns: The TimeZone offset.
- **Arguments:
- ** str the parsing string
- **Exceptions:
- ** FormatException if invalid timezone format is found.
- ============================================================================*/
-
- private static bool ParseTimeZone(ref __DTString str, ref TimeSpan result)
- {
- // The hour/minute offset for timezone.
- int hourOffset;
- int minuteOffset = 0;
-
- // Consume the +/- character that has already been read
- DTSubString sub = str.GetSubString();
- if (sub.length != 1)
- {
- return false;
- }
- char offsetChar = sub[0];
- if (offsetChar != '+' && offsetChar != '-')
- {
- return false;
- }
- str.ConsumeSubString(sub);
-
- sub = str.GetSubString();
- if (sub.type != DTSubStringType.Number)
- {
- return false;
- }
- int value = sub.value;
- int length = sub.length;
- if (length == 1 || length == 2)
- {
- // Parsing "+8" or "+08"
- hourOffset = value;
- str.ConsumeSubString(sub);
- // See if we have minutes
- sub = str.GetSubString();
- if (sub.length == 1 && sub[0] == ':')
- {
- // Parsing "+8:00" or "+08:00"
- str.ConsumeSubString(sub);
- sub = str.GetSubString();
- if (sub.type != DTSubStringType.Number || sub.length < 1 || sub.length > 2)
- {
- return false;
- }
- minuteOffset = sub.value;
- str.ConsumeSubString(sub);
- }
- }
- else if (length == 3 || length == 4)
- {
- // Parsing "+800" or "+0800"
- hourOffset = value / 100;
- minuteOffset = value % 100;
- str.ConsumeSubString(sub);
- }
- else
- {
- // Wrong number of digits
- return false;
- }
- Debug.Assert(hourOffset >= 0 && hourOffset <= 99, "hourOffset >= 0 && hourOffset <= 99");
- Debug.Assert(minuteOffset >= 0 && minuteOffset <= 99, "minuteOffset >= 0 && minuteOffset <= 99");
- if (minuteOffset < 0 || minuteOffset >= 60)
- {
- return false;
- }
-
- result = new TimeSpan(hourOffset, minuteOffset, 0);
- if (offsetChar == '-')
- {
- result = result.Negate();
- }
- return true;
- }
-
- // This is the helper function to handle timezone in string in the format like +/-0800
- private static bool HandleTimeZone(ref __DTString str, ref DateTimeResult result)
- {
- if (str.Index < str.Length - 1)
- {
- char nextCh = str.Value[str.Index];
- // Skip whitespace, but don't update the index unless we find a time zone marker
- int whitespaceCount = 0;
- while (char.IsWhiteSpace(nextCh) && str.Index + whitespaceCount < str.Length - 1)
- {
- whitespaceCount++;
- nextCh = str.Value[str.Index + whitespaceCount];
- }
- if (nextCh == '+' || nextCh == '-')
- {
- str.Index += whitespaceCount;
- if ((result.flags & ParseFlags.TimeZoneUsed) != 0)
- {
- // Should not have two timezone offsets.
- result.SetBadDateTimeFailure();
- return false;
- }
- result.flags |= ParseFlags.TimeZoneUsed;
- if (!ParseTimeZone(ref str, ref result.timeZoneOffset))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- }
- return true;
- }
-
- //
- // This is the lexer. Check the character at the current index, and put the found token in dtok and
- // some raw date/time information in raw.
- //
- private static bool Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref DateTimeRawInfo raw, ref DateTimeResult result, ref DateTimeFormatInfo dtfi, DateTimeStyles styles)
- {
- TokenType tokenType;
- int tokenValue;
- int indexBeforeSeparator;
- char charBeforeSeparator;
-
- TokenType sep;
- dtok.dtt = DTT.Unk; // Assume the token is unkown.
-
- str.GetRegularToken(out tokenType, out tokenValue, dtfi);
-
-#if _LOGGING
- if (_tracingEnabled)
- {
- Trace($"Lex({Hex(str.Value)})\tpos:{str.Index}({Hex(str.m_current)}), {tokenType}, DS.{dps}");
- }
-#endif // _LOGGING
-
- // Look at the regular token.
- switch (tokenType)
- {
- case TokenType.NumberToken:
- case TokenType.YearNumberToken:
- if (raw.numCount == 3 || tokenValue == -1)
- {
- result.SetBadDateTimeFailure();
- LexTraceExit("0010", dps);
- return false;
- }
- //
- // This is a digit.
- //
- // If the previous parsing state is DS.T_NNt (like 12:01), and we got another number,
- // so we will have a terminal state DS.TX_NNN (like 12:01:02).
- // If the previous parsing state is DS.T_Nt (like 12:), and we got another number,
- // so we will have a terminal state DS.TX_NN (like 12:01).
- //
- // Look ahead to see if the following character is a decimal point or timezone offset.
- // This enables us to parse time in the forms of:
- // "11:22:33.1234" or "11:22:33-08".
- if (dps == DS.T_NNt)
- {
- if (str.Index < str.Length - 1)
- {
- char nextCh = str.Value[str.Index];
- if (nextCh == '.')
- {
- // While ParseFraction can fail, it just means that there were no digits after
- // the dot. In this case ParseFraction just removes the dot. This is actually
- // valid for cultures like Albanian, that join the time marker to the time with
- // with a dot: e.g. "9:03.MD"
- ParseFraction(ref str, out raw.fraction);
- }
- }
- }
- if (dps == DS.T_NNt || dps == DS.T_Nt)
- {
- if (str.Index < str.Length - 1)
- {
- if (!HandleTimeZone(ref str, ref result))
- {
- LexTraceExit("0020 (value like \"12:01\" or \"12:\" followed by a non-TZ number", dps);
- return false;
- }
- }
- }
-
- dtok.num = tokenValue;
- if (tokenType == TokenType.YearNumberToken)
- {
- if (raw.year == -1)
- {
- raw.year = tokenValue;
- //
- // If we have number which has 3 or more digits (like "001" or "0001"),
- // we assume this number is a year. Save the current raw.numCount in
- // raw.year.
- //
- switch (sep = str.GetSeparatorToken(dtfi, out indexBeforeSeparator, out charBeforeSeparator))
- {
- case TokenType.SEP_End:
- dtok.dtt = DTT.YearEnd;
- break;
- case TokenType.SEP_Am:
- case TokenType.SEP_Pm:
- if (raw.timeMark == TM.NotSet)
- {
- raw.timeMark = (sep == TokenType.SEP_Am ? TM.AM : TM.PM);
- dtok.dtt = DTT.YearSpace;
- }
- else
- {
- result.SetBadDateTimeFailure();
- LexTraceExit("0030 (TM.AM/TM.PM Happened more than 1x)", dps);
- }
- break;
- case TokenType.SEP_Space:
- dtok.dtt = DTT.YearSpace;
- break;
- case TokenType.SEP_Date:
- dtok.dtt = DTT.YearDateSep;
- break;
- case TokenType.SEP_Time:
- if (!raw.hasSameDateAndTimeSeparators)
- {
- result.SetBadDateTimeFailure();
- LexTraceExit("0040 (Invalid separator after number)", dps);
- return false;
- }
-
- // we have the date and time separators are same and getting a year number, then change the token to YearDateSep as
- // we are sure we are not parsing time.
- dtok.dtt = DTT.YearDateSep;
- break;
- case TokenType.SEP_DateOrOffset:
- // The separator is either a date separator or the start of a time zone offset. If the token will complete the date then
- // process just the number and roll back the index so that the outer loop can attempt to parse the time zone offset.
- if ((dateParsingStates[(int)dps][(int)DTT.YearDateSep] == DS.ERROR)
- && (dateParsingStates[(int)dps][(int)DTT.YearSpace] > DS.ERROR))
- {
- str.Index = indexBeforeSeparator;
- str.m_current = charBeforeSeparator;
- dtok.dtt = DTT.YearSpace;
- }
- else
- {
- dtok.dtt = DTT.YearDateSep;
- }
- break;
- case TokenType.SEP_YearSuff:
- case TokenType.SEP_MonthSuff:
- case TokenType.SEP_DaySuff:
- dtok.dtt = DTT.NumDatesuff;
- dtok.suffix = sep;
- break;
- case TokenType.SEP_HourSuff:
- case TokenType.SEP_MinuteSuff:
- case TokenType.SEP_SecondSuff:
- dtok.dtt = DTT.NumTimesuff;
- dtok.suffix = sep;
- break;
- default:
- // Invalid separator after number number.
- result.SetBadDateTimeFailure();
- LexTraceExit("0040 (Invalid separator after number)", dps);
- return false;
- }
- //
- // Found the token already. Return now.
- //
- LexTraceExit("0050 (success)", dps);
- return true;
- }
- result.SetBadDateTimeFailure();
- LexTraceExit("0060", dps);
- return false;
- }
- switch (sep = str.GetSeparatorToken(dtfi, out indexBeforeSeparator, out charBeforeSeparator))
- {
- //
- // Note here we check if the numCount is less than three.
- // When we have more than three numbers, it will be caught as error in the state machine.
- //
- case TokenType.SEP_End:
- dtok.dtt = DTT.NumEnd;
- raw.AddNumber(dtok.num);
- break;
- case TokenType.SEP_Am:
- case TokenType.SEP_Pm:
- if (raw.timeMark == TM.NotSet)
- {
- raw.timeMark = (sep == TokenType.SEP_Am ? TM.AM : TM.PM);
- dtok.dtt = DTT.NumAmpm;
- // Fix AM/PM parsing case, e.g. "1/10 5 AM"
- if (dps == DS.D_NN)
- {
- if (!ProcessTerminalState(DS.DX_NN, ref str, ref result, ref styles, ref raw, dtfi))
- {
- return false;
- }
- }
-
- raw.AddNumber(dtok.num);
- }
- else
- {
- result.SetBadDateTimeFailure();
- break;
- }
- if (dps == DS.T_NNt || dps == DS.T_Nt)
- {
- if (!HandleTimeZone(ref str, ref result))
- {
- LexTraceExit("0070 (HandleTimeZone returned false)", dps);
- return false;
- }
- }
- break;
- case TokenType.SEP_Space:
- dtok.dtt = DTT.NumSpace;
- raw.AddNumber(dtok.num);
- break;
- case TokenType.SEP_Date:
- dtok.dtt = DTT.NumDatesep;
- raw.AddNumber(dtok.num);
- break;
- case TokenType.SEP_DateOrOffset:
- // The separator is either a date separator or the start of a time zone offset. If the token will complete the date then
- // process just the number and roll back the index so that the outer loop can attempt to parse the time zone offset.
- if ((dateParsingStates[(int)dps][(int)DTT.NumDatesep] == DS.ERROR)
- && (dateParsingStates[(int)dps][(int)DTT.NumSpace] > DS.ERROR))
- {
- str.Index = indexBeforeSeparator;
- str.m_current = charBeforeSeparator;
- dtok.dtt = DTT.NumSpace;
- }
- else
- {
- dtok.dtt = DTT.NumDatesep;
- }
- raw.AddNumber(dtok.num);
- break;
- case TokenType.SEP_Time:
- if (raw.hasSameDateAndTimeSeparators &&
- (dps == DS.D_Y || dps == DS.D_YN || dps == DS.D_YNd || dps == DS.D_YM || dps == DS.D_YMd))
- {
- // we are parsing a date and we have the time separator same as date separator, so we mark the token as date separator
- dtok.dtt = DTT.NumDatesep;
- raw.AddNumber(dtok.num);
- break;
- }
- dtok.dtt = DTT.NumTimesep;
- raw.AddNumber(dtok.num);
- break;
- case TokenType.SEP_YearSuff:
- try
- {
- dtok.num = dtfi.Calendar.ToFourDigitYear(tokenValue);
- }
- catch (ArgumentOutOfRangeException)
- {
- result.SetBadDateTimeFailure();
- LexTraceExit("0075 (Calendar.ToFourDigitYear failed)", dps);
- return false;
- }
- dtok.dtt = DTT.NumDatesuff;
- dtok.suffix = sep;
- break;
- case TokenType.SEP_MonthSuff:
- case TokenType.SEP_DaySuff:
- dtok.dtt = DTT.NumDatesuff;
- dtok.suffix = sep;
- break;
- case TokenType.SEP_HourSuff:
- case TokenType.SEP_MinuteSuff:
- case TokenType.SEP_SecondSuff:
- dtok.dtt = DTT.NumTimesuff;
- dtok.suffix = sep;
- break;
- case TokenType.SEP_LocalTimeMark:
- dtok.dtt = DTT.NumLocalTimeMark;
- raw.AddNumber(dtok.num);
- break;
- default:
- // Invalid separator after number number.
- result.SetBadDateTimeFailure();
- LexTraceExit("0080", dps);
- return false;
- }
- break;
- case TokenType.HebrewNumber:
- if (tokenValue >= 100)
- {
- // This is a year number
- if (raw.year == -1)
- {
- raw.year = tokenValue;
- //
- // If we have number which has 3 or more digits (like "001" or "0001"),
- // we assume this number is a year. Save the current raw.numCount in
- // raw.year.
- //
- switch (sep = str.GetSeparatorToken(dtfi, out indexBeforeSeparator, out charBeforeSeparator))
- {
- case TokenType.SEP_End:
- dtok.dtt = DTT.YearEnd;
- break;
- case TokenType.SEP_Space:
- dtok.dtt = DTT.YearSpace;
- break;
- case TokenType.SEP_DateOrOffset:
- // The separator is either a date separator or the start of a time zone offset. If the token will complete the date then
- // process just the number and roll back the index so that the outer loop can attempt to parse the time zone offset.
- if (dateParsingStates[(int)dps][(int)DTT.YearSpace] > DS.ERROR)
- {
- str.Index = indexBeforeSeparator;
- str.m_current = charBeforeSeparator;
- dtok.dtt = DTT.YearSpace;
- break;
- }
- goto default;
- default:
- // Invalid separator after number number.
- result.SetBadDateTimeFailure();
- LexTraceExit("0090", dps);
- return false;
- }
- }
- else
- {
- // Invalid separator after number number.
- result.SetBadDateTimeFailure();
- LexTraceExit("0100", dps);
- return false;
- }
- }
- else
- {
- // This is a day number
- dtok.num = tokenValue;
- raw.AddNumber(dtok.num);
-
- switch (sep = str.GetSeparatorToken(dtfi, out indexBeforeSeparator, out charBeforeSeparator))
- {
- //
- // Note here we check if the numCount is less than three.
- // When we have more than three numbers, it will be caught as error in the state machine.
- //
- case TokenType.SEP_End:
- dtok.dtt = DTT.NumEnd;
- break;
- case TokenType.SEP_Space:
- case TokenType.SEP_Date:
- dtok.dtt = DTT.NumDatesep;
- break;
- case TokenType.SEP_DateOrOffset:
- // The separator is either a date separator or the start of a time zone offset. If the token will complete the date then
- // process just the number and roll back the index so that the outer loop can attempt to parse the time zone offset.
- if ((dateParsingStates[(int)dps][(int)DTT.NumDatesep] == DS.ERROR)
- && (dateParsingStates[(int)dps][(int)DTT.NumSpace] > DS.ERROR))
- {
- str.Index = indexBeforeSeparator;
- str.m_current = charBeforeSeparator;
- dtok.dtt = DTT.NumSpace;
- }
- else
- {
- dtok.dtt = DTT.NumDatesep;
- }
- break;
- default:
- // Invalid separator after number number.
- result.SetBadDateTimeFailure();
- LexTraceExit("0110", dps);
- return false;
- }
- }
- break;
- case TokenType.DayOfWeekToken:
- if (raw.dayOfWeek == -1)
- {
- //
- // This is a day of week name.
- //
- raw.dayOfWeek = tokenValue;
- dtok.dtt = DTT.DayOfWeek;
- }
- else
- {
- result.SetBadDateTimeFailure();
- LexTraceExit("0120 (DayOfWeek seen more than 1x)", dps);
- return false;
- }
- break;
- case TokenType.MonthToken:
- if (raw.month == -1)
- {
- //
- // This is a month name
- //
- switch (sep = str.GetSeparatorToken(dtfi, out indexBeforeSeparator, out charBeforeSeparator))
- {
- case TokenType.SEP_End:
- dtok.dtt = DTT.MonthEnd;
- break;
- case TokenType.SEP_Space:
- dtok.dtt = DTT.MonthSpace;
- break;
- case TokenType.SEP_Date:
- dtok.dtt = DTT.MonthDatesep;
- break;
- case TokenType.SEP_Time:
- if (!raw.hasSameDateAndTimeSeparators)
- {
- result.SetBadDateTimeFailure();
- LexTraceExit("0130 (Invalid separator after month name)", dps);
- return false;
- }
-
- // we have the date and time separators are same and getting a Month name, then change the token to MonthDatesep as
- // we are sure we are not parsing time.
- dtok.dtt = DTT.MonthDatesep;
- break;
- case TokenType.SEP_DateOrOffset:
- // The separator is either a date separator or the start of a time zone offset. If the token will complete the date then
- // process just the number and roll back the index so that the outer loop can attempt to parse the time zone offset.
- if ((dateParsingStates[(int)dps][(int)DTT.MonthDatesep] == DS.ERROR)
- && (dateParsingStates[(int)dps][(int)DTT.MonthSpace] > DS.ERROR))
- {
- str.Index = indexBeforeSeparator;
- str.m_current = charBeforeSeparator;
- dtok.dtt = DTT.MonthSpace;
- }
- else
- {
- dtok.dtt = DTT.MonthDatesep;
- }
- break;
- default:
- // Invalid separator after month name
- result.SetBadDateTimeFailure();
- LexTraceExit("0130 (Invalid separator after month name)", dps);
- return false;
- }
- raw.month = tokenValue;
- }
- else
- {
- result.SetBadDateTimeFailure();
- LexTraceExit("0140 (MonthToken seen more than 1x)", dps);
- return false;
- }
- break;
- case TokenType.EraToken:
- if (result.era != -1)
- {
- result.era = tokenValue;
- dtok.dtt = DTT.Era;
- }
- else
- {
- result.SetBadDateTimeFailure();
- LexTraceExit("0150 (EraToken seen when result.era already set)", dps);
- return false;
- }
- break;
- case TokenType.JapaneseEraToken:
- // Special case for Japanese. We allow Japanese era name to be used even if the calendar is not Japanese Calendar.
- result.calendar = JapaneseCalendar.GetDefaultInstance();
- dtfi = DateTimeFormatInfo.GetJapaneseCalendarDTFI();
- if (result.era != -1)
- {
- result.era = tokenValue;
- dtok.dtt = DTT.Era;
- }
- else
- {
- result.SetBadDateTimeFailure();
- LexTraceExit("0160 (JapaneseEraToken seen when result.era already set)", dps);
- return false;
- }
- break;
- case TokenType.TEraToken:
- result.calendar = TaiwanCalendar.GetDefaultInstance();
- dtfi = DateTimeFormatInfo.GetTaiwanCalendarDTFI();
- if (result.era != -1)
- {
- result.era = tokenValue;
- dtok.dtt = DTT.Era;
- }
- else
- {
- result.SetBadDateTimeFailure();
- LexTraceExit("0170 (TEraToken seen when result.era already set)", dps);
- return false;
- }
- break;
- case TokenType.TimeZoneToken:
- //
- // This is a timezone designator
- //
- // NOTENOTE : for now, we only support "GMT" and "Z" (for Zulu time).
- //
- if ((result.flags & ParseFlags.TimeZoneUsed) != 0)
- {
- // Should not have two timezone offsets.
- result.SetBadDateTimeFailure();
- LexTraceExit("0180 (seen GMT or Z more than 1x)", dps);
- return false;
- }
- dtok.dtt = DTT.TimeZone;
- result.flags |= ParseFlags.TimeZoneUsed;
- result.timeZoneOffset = new TimeSpan(0);
- result.flags |= ParseFlags.TimeZoneUtc;
- break;
- case TokenType.EndOfString:
- dtok.dtt = DTT.End;
- break;
- case TokenType.DateWordToken:
- case TokenType.IgnorableSymbol:
- // Date words and ignorable symbols can just be skipped over
- break;
- case TokenType.Am:
- case TokenType.Pm:
- if (raw.timeMark == TM.NotSet)
- {
- raw.timeMark = (TM)tokenValue;
- }
- else
- {
- result.SetBadDateTimeFailure();
- LexTraceExit("0190 (AM/PM timeMark already set)", dps);
- return false;
- }
- break;
- case TokenType.UnknownToken:
- if (char.IsLetter(str.m_current))
- {
- result.SetFailure(ParseFailureKind.FormatWithOriginalDateTimeAndParameter, nameof(SR.Format_UnknownDateTimeWord), str.Index);
- LexTraceExit("0200", dps);
- return false;
- }
-
- if ((str.m_current == '-' || str.m_current == '+') && ((result.flags & ParseFlags.TimeZoneUsed) == 0))
- {
- int originalIndex = str.Index;
- if (ParseTimeZone(ref str, ref result.timeZoneOffset))
- {
- result.flags |= ParseFlags.TimeZoneUsed;
- LexTraceExit("0220 (success)", dps);
- return true;
- }
- else
- {
- // Time zone parse attempt failed. Fall through to punctuation handling.
- str.Index = originalIndex;
- }
- }
-
- // Visual Basic implements string to date conversions on top of DateTime.Parse:
- // CDate("#10/10/95#")
- //
- if (VerifyValidPunctuation(ref str))
- {
- LexTraceExit("0230 (success)", dps);
- return true;
- }
-
- result.SetBadDateTimeFailure();
- LexTraceExit("0240", dps);
- return false;
- }
-
- LexTraceExit("0250 (success)", dps);
- return true;
- }
-
- private static bool VerifyValidPunctuation(ref __DTString str)
- {
- // Compatability Behavior. Allow trailing nulls and surrounding hashes
- char ch = str.Value[str.Index];
- if (ch == '#')
- {
- bool foundStart = false;
- bool foundEnd = false;
- for (int i = 0; i < str.Length; i++)
- {
- ch = str.Value[i];
- if (ch == '#')
- {
- if (foundStart)
- {
- if (foundEnd)
- {
- // Having more than two hashes is invalid
- return false;
- }
- else
- {
- foundEnd = true;
- }
- }
- else
- {
- foundStart = true;
- }
- }
- else if (ch == '\0')
- {
- // Allow nulls only at the end
- if (!foundEnd)
- {
- return false;
- }
- }
- else if (!char.IsWhiteSpace(ch))
- {
- // Anything other than whitespace outside hashes is invalid
- if (!foundStart || foundEnd)
- {
- return false;
- }
- }
- }
- if (!foundEnd)
- {
- // The has was un-paired
- return false;
- }
- // Valid Hash usage: eat the hash and continue.
- str.GetNext();
- return true;
- }
- else if (ch == '\0')
- {
- for (int i = str.Index; i < str.Length; i++)
- {
- if (str.Value[i] != '\0')
- {
- // Nulls are only valid if they are the only trailing character
- return false;
- }
- }
- // Move to the end of the string
- str.Index = str.Length;
- return true;
- }
- return false;
- }
-
- private const int ORDER_YMD = 0; // The order of date is Year/Month/Day.
- private const int ORDER_MDY = 1; // The order of date is Month/Day/Year.
- private const int ORDER_DMY = 2; // The order of date is Day/Month/Year.
- private const int ORDER_YDM = 3; // The order of date is Year/Day/Month
- private const int ORDER_YM = 4; // Year/Month order.
- private const int ORDER_MY = 5; // Month/Year order.
- private const int ORDER_MD = 6; // Month/Day order.
- private const int ORDER_DM = 7; // Day/Month order.
-
- //
- // Decide the year/month/day order from the datePattern.
- //
- // Return 0 for YMD, 1 for MDY, 2 for DMY, otherwise -1.
- //
- private static bool GetYearMonthDayOrder(string datePattern, out int order)
- {
- int yearOrder = -1;
- int monthOrder = -1;
- int dayOrder = -1;
- int orderCount = 0;
-
- bool inQuote = false;
-
- for (int i = 0; i < datePattern.Length && orderCount < 3; i++)
- {
- char ch = datePattern[i];
- if (ch == '\\' || ch == '%')
- {
- i++;
- continue; // Skip next character that is escaped by this backslash
- }
-
- if (ch == '\'' || ch == '"')
- {
- inQuote = !inQuote;
- }
-
- if (!inQuote)
- {
- if (ch == 'y')
- {
- yearOrder = orderCount++;
-
- //
- // Skip all year pattern charaters.
- //
- for (; i + 1 < datePattern.Length && datePattern[i + 1] == 'y'; i++)
- {
- // Do nothing here.
- }
- }
- else if (ch == 'M')
- {
- monthOrder = orderCount++;
- //
- // Skip all month pattern characters.
- //
- for (; i + 1 < datePattern.Length && datePattern[i + 1] == 'M'; i++)
- {
- // Do nothing here.
- }
- }
- else if (ch == 'd')
- {
- int patternCount = 1;
- //
- // Skip all day pattern characters.
- //
- for (; i + 1 < datePattern.Length && datePattern[i + 1] == 'd'; i++)
- {
- patternCount++;
- }
- //
- // Make sure this is not "ddd" or "dddd", which means day of week.
- //
- if (patternCount <= 2)
- {
- dayOrder = orderCount++;
- }
- }
- }
- }
-
- if (yearOrder == 0 && monthOrder == 1 && dayOrder == 2)
- {
- order = ORDER_YMD;
- return true;
- }
- if (monthOrder == 0 && dayOrder == 1 && yearOrder == 2)
- {
- order = ORDER_MDY;
- return true;
- }
- if (dayOrder == 0 && monthOrder == 1 && yearOrder == 2)
- {
- order = ORDER_DMY;
- return true;
- }
- if (yearOrder == 0 && dayOrder == 1 && monthOrder == 2)
- {
- order = ORDER_YDM;
- return true;
- }
- order = -1;
- return false;
- }
-
- //
- // Decide the year/month order from the pattern.
- //
- // Return 0 for YM, 1 for MY, otherwise -1.
- //
- private static bool GetYearMonthOrder(string pattern, out int order)
- {
- int yearOrder = -1;
- int monthOrder = -1;
- int orderCount = 0;
-
- bool inQuote = false;
- for (int i = 0; i < pattern.Length && orderCount < 2; i++)
- {
- char ch = pattern[i];
- if (ch == '\\' || ch == '%')
- {
- i++;
- continue; // Skip next character that is escaped by this backslash
- }
-
- if (ch == '\'' || ch == '"')
- {
- inQuote = !inQuote;
- }
-
- if (!inQuote)
- {
- if (ch == 'y')
- {
- yearOrder = orderCount++;
-
- //
- // Skip all year pattern charaters.
- //
- for (; i + 1 < pattern.Length && pattern[i + 1] == 'y'; i++)
- {
- }
- }
- else if (ch == 'M')
- {
- monthOrder = orderCount++;
- //
- // Skip all month pattern characters.
- //
- for (; i + 1 < pattern.Length && pattern[i + 1] == 'M'; i++)
- {
- }
- }
- }
- }
-
- if (yearOrder == 0 && monthOrder == 1)
- {
- order = ORDER_YM;
- return true;
- }
- if (monthOrder == 0 && yearOrder == 1)
- {
- order = ORDER_MY;
- return true;
- }
- order = -1;
- return false;
- }
-
- //
- // Decide the month/day order from the pattern.
- //
- // Return 0 for MD, 1 for DM, otherwise -1.
- //
- private static bool GetMonthDayOrder(string pattern, out int order)
- {
- int monthOrder = -1;
- int dayOrder = -1;
- int orderCount = 0;
-
- bool inQuote = false;
- for (int i = 0; i < pattern.Length && orderCount < 2; i++)
- {
- char ch = pattern[i];
- if (ch == '\\' || ch == '%')
- {
- i++;
- continue; // Skip next character that is escaped by this backslash
- }
-
- if (ch == '\'' || ch == '"')
- {
- inQuote = !inQuote;
- }
-
- if (!inQuote)
- {
- if (ch == 'd')
- {
- int patternCount = 1;
- //
- // Skip all day pattern charaters.
- //
- for (; i + 1 < pattern.Length && pattern[i + 1] == 'd'; i++)
- {
- patternCount++;
- }
-
- //
- // Make sure this is not "ddd" or "dddd", which means day of week.
- //
- if (patternCount <= 2)
- {
- dayOrder = orderCount++;
- }
- }
- else if (ch == 'M')
- {
- monthOrder = orderCount++;
- //
- // Skip all month pattern characters.
- //
- for (; i + 1 < pattern.Length && pattern[i + 1] == 'M'; i++)
- {
- }
- }
- }
- }
-
- if (monthOrder == 0 && dayOrder == 1)
- {
- order = ORDER_MD;
- return true;
- }
- if (dayOrder == 0 && monthOrder == 1)
- {
- order = ORDER_DM;
- return true;
- }
- order = -1;
- return false;
- }
-
- //
- // Adjust the two-digit year if necessary.
- //
- private static bool TryAdjustYear(ref DateTimeResult result, int year, out int adjustedYear)
- {
- if (year < 100)
- {
- try
- {
- // the Calendar classes need some real work. Many of the calendars that throw
- // don't implement a fast/non-allocating (and non-throwing) IsValid{Year|Day|Month} method.
- // we are making a targeted try/catch fix in the in-place release but will revisit this code
- // in the next side-by-side release.
- year = result.calendar.ToFourDigitYear(year);
- }
- catch (ArgumentOutOfRangeException)
- {
- adjustedYear = -1;
- return false;
- }
- }
- adjustedYear = year;
- return true;
- }
-
- private static bool SetDateYMD(ref DateTimeResult result, int year, int month, int day)
- {
- // Note, longer term these checks should be done at the end of the parse. This current
- // way of checking creates order dependence with parsing the era name.
- if (result.calendar.IsValidDay(year, month, day, result.era))
- {
- result.SetDate(year, month, day); // YMD
- return true;
- }
- return false;
- }
-
- private static bool SetDateMDY(ref DateTimeResult result, int month, int day, int year)
- {
- return SetDateYMD(ref result, year, month, day);
- }
-
- private static bool SetDateDMY(ref DateTimeResult result, int day, int month, int year)
- {
- return SetDateYMD(ref result, year, month, day);
- }
-
- private static bool SetDateYDM(ref DateTimeResult result, int year, int day, int month)
- {
- return SetDateYMD(ref result, year, month, day);
- }
-
- private static void GetDefaultYear(ref DateTimeResult result, ref DateTimeStyles styles)
- {
- result.Year = result.calendar.GetYear(GetDateTimeNow(ref result, ref styles));
- result.flags |= ParseFlags.YearDefault;
- }
-
- // Processing teriminal case: DS.DX_NN
- private static bool GetDayOfNN(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
- {
- if ((result.flags & ParseFlags.HaveDate) != 0)
- {
- // Multiple dates in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
-
- int n1 = raw.GetNumber(0);
- int n2 = raw.GetNumber(1);
-
- GetDefaultYear(ref result, ref styles);
-
- int order;
- if (!GetMonthDayOrder(dtfi.MonthDayPattern, out order))
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDatePattern), dtfi.MonthDayPattern);
- return false;
- }
-
- if (order == ORDER_MD)
- {
- if (SetDateYMD(ref result, result.Year, n1, n2)) // MD
- {
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- }
- else
- {
- // ORDER_DM
- if (SetDateYMD(ref result, result.Year, n2, n1)) // DM
- {
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- }
- result.SetBadDateTimeFailure();
- return false;
- }
-
- // Processing teriminal case: DS.DX_NNN
- private static bool GetDayOfNNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
- {
- if ((result.flags & ParseFlags.HaveDate) != 0)
- {
- // Multiple dates in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
-
- int n1 = raw.GetNumber(0);
- int n2 = raw.GetNumber(1);
- int n3 = raw.GetNumber(2);
-
- int order;
- if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, out order))
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDatePattern), dtfi.ShortDatePattern);
- return false;
- }
- int year;
-
- if (order == ORDER_YMD)
- {
- if (TryAdjustYear(ref result, n1, out year) && SetDateYMD(ref result, year, n2, n3)) // YMD
- {
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- }
- else if (order == ORDER_MDY)
- {
- if (TryAdjustYear(ref result, n3, out year) && SetDateMDY(ref result, n1, n2, year)) // MDY
- {
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- }
- else if (order == ORDER_DMY)
- {
- if (TryAdjustYear(ref result, n3, out year) && SetDateDMY(ref result, n1, n2, year)) // DMY
- {
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- }
- else if (order == ORDER_YDM)
- {
- if (TryAdjustYear(ref result, n1, out year) && SetDateYDM(ref result, year, n2, n3)) // YDM
- {
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- }
- result.SetBadDateTimeFailure();
- return false;
- }
-
- private static bool GetDayOfMN(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
- {
- if ((result.flags & ParseFlags.HaveDate) != 0)
- {
- // Multiple dates in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
-
- // The interpretation is based on the MonthDayPattern and YearMonthPattern
- //
- // MonthDayPattern YearMonthPattern Interpretation
- // --------------- ---------------- ---------------
- // MMMM dd MMMM yyyy Day
- // MMMM dd yyyy MMMM Day
- // dd MMMM MMMM yyyy Year
- // dd MMMM yyyy MMMM Day
- //
- // In the first and last cases, it could be either or neither, but a day is a better default interpretation
- // than a 2 digit year.
-
- int monthDayOrder;
- if (!GetMonthDayOrder(dtfi.MonthDayPattern, out monthDayOrder))
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDatePattern), dtfi.MonthDayPattern);
- return false;
- }
- if (monthDayOrder == ORDER_DM)
- {
- int yearMonthOrder;
- if (!GetYearMonthOrder(dtfi.YearMonthPattern, out yearMonthOrder))
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDatePattern), dtfi.YearMonthPattern);
- return false;
- }
- if (yearMonthOrder == ORDER_MY)
- {
- int year;
- if (!TryAdjustYear(ref result, raw.GetNumber(0), out year) || !SetDateYMD(ref result, year, raw.month, 1))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- return true;
- }
- }
-
- GetDefaultYear(ref result, ref styles);
- if (!SetDateYMD(ref result, result.Year, raw.month, raw.GetNumber(0)))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- return true;
- }
-
- ////////////////////////////////////////////////////////////////////////
- // Actions:
- // Deal with the terminal state for Hebrew Month/Day pattern
- //
- ////////////////////////////////////////////////////////////////////////
-
- private static bool GetHebrewDayOfNM(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
- {
- int monthDayOrder;
- if (!GetMonthDayOrder(dtfi.MonthDayPattern, out monthDayOrder))
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDatePattern), dtfi.MonthDayPattern);
- return false;
- }
- result.Month = raw.month;
- if (monthDayOrder == ORDER_DM || monthDayOrder == ORDER_MD)
- {
- if (result.calendar.IsValidDay(result.Year, result.Month, raw.GetNumber(0), result.era))
- {
- result.Day = raw.GetNumber(0);
- return true;
- }
- }
- result.SetBadDateTimeFailure();
- return false;
- }
-
- private static bool GetDayOfNM(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
- {
- if ((result.flags & ParseFlags.HaveDate) != 0)
- {
- // Multiple dates in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
-
- // The interpretation is based on the MonthDayPattern and YearMonthPattern
- //
- // MonthDayPattern YearMonthPattern Interpretation
- // --------------- ---------------- ---------------
- // MMMM dd MMMM yyyy Day
- // MMMM dd yyyy MMMM Year
- // dd MMMM MMMM yyyy Day
- // dd MMMM yyyy MMMM Day
- //
- // In the first and last cases, it could be either or neither, but a day is a better default interpretation
- // than a 2 digit year.
-
- int monthDayOrder;
- if (!GetMonthDayOrder(dtfi.MonthDayPattern, out monthDayOrder))
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDatePattern), dtfi.MonthDayPattern);
- return false;
- }
- if (monthDayOrder == ORDER_MD)
- {
- int yearMonthOrder;
- if (!GetYearMonthOrder(dtfi.YearMonthPattern, out yearMonthOrder))
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDatePattern), dtfi.YearMonthPattern);
- return false;
- }
- if (yearMonthOrder == ORDER_YM)
- {
- int year;
- if (!TryAdjustYear(ref result, raw.GetNumber(0), out year) || !SetDateYMD(ref result, year, raw.month, 1))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- return true;
- }
- }
-
- GetDefaultYear(ref result, ref styles);
- if (!SetDateYMD(ref result, result.Year, raw.month, raw.GetNumber(0)))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- return true;
- }
-
- private static bool GetDayOfMNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
- {
- if ((result.flags & ParseFlags.HaveDate) != 0)
- {
- // Multiple dates in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
-
- int n1 = raw.GetNumber(0);
- int n2 = raw.GetNumber(1);
-
- int order;
- if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, out order))
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDatePattern), dtfi.ShortDatePattern);
- return false;
- }
- int year;
-
- if (order == ORDER_MDY)
- {
- if (TryAdjustYear(ref result, n2, out year) && result.calendar.IsValidDay(year, raw.month, n1, result.era))
- {
- result.SetDate(year, raw.month, n1); // MDY
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- else if (TryAdjustYear(ref result, n1, out year) && result.calendar.IsValidDay(year, raw.month, n2, result.era))
- {
- result.SetDate(year, raw.month, n2); // YMD
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- }
- else if (order == ORDER_YMD)
- {
- if (TryAdjustYear(ref result, n1, out year) && result.calendar.IsValidDay(year, raw.month, n2, result.era))
- {
- result.SetDate(year, raw.month, n2); // YMD
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- else if (TryAdjustYear(ref result, n2, out year) && result.calendar.IsValidDay(year, raw.month, n1, result.era))
- {
- result.SetDate(year, raw.month, n1); // DMY
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- }
- else if (order == ORDER_DMY)
- {
- if (TryAdjustYear(ref result, n2, out year) && result.calendar.IsValidDay(year, raw.month, n1, result.era))
- {
- result.SetDate(year, raw.month, n1); // DMY
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- else if (TryAdjustYear(ref result, n1, out year) && result.calendar.IsValidDay(year, raw.month, n2, result.era))
- {
- result.SetDate(year, raw.month, n2); // YMD
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- }
-
- result.SetBadDateTimeFailure();
- return false;
- }
-
- private static bool GetDayOfYNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
- {
- if ((result.flags & ParseFlags.HaveDate) != 0)
- {
- // Multiple dates in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
-
- int n1 = raw.GetNumber(0);
- int n2 = raw.GetNumber(1);
- string pattern = dtfi.ShortDatePattern;
-
- // For compatibility, don't throw if we can't determine the order, but default to YMD instead
- int order;
- if (GetYearMonthDayOrder(pattern, out order) && order == ORDER_YDM)
- {
- if (SetDateYMD(ref result, raw.year, n2, n1))
- {
- result.flags |= ParseFlags.HaveDate;
- return true; // Year + DM
- }
- }
- else
- {
- if (SetDateYMD(ref result, raw.year, n1, n2))
- {
- result.flags |= ParseFlags.HaveDate;
- return true; // Year + MD
- }
- }
- result.SetBadDateTimeFailure();
- return false;
- }
-
- private static bool GetDayOfNNY(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
- {
- if ((result.flags & ParseFlags.HaveDate) != 0)
- {
- // Multiple dates in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
-
- int n1 = raw.GetNumber(0);
- int n2 = raw.GetNumber(1);
-
- int order;
- if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, out order))
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDatePattern), dtfi.ShortDatePattern);
- return false;
- }
-
- if (order == ORDER_MDY || order == ORDER_YMD)
- {
- if (SetDateYMD(ref result, raw.year, n1, n2))
- {
- result.flags |= ParseFlags.HaveDate;
- return true; // MD + Year
- }
- }
- else
- {
- if (SetDateYMD(ref result, raw.year, n2, n1))
- {
- result.flags |= ParseFlags.HaveDate;
- return true; // DM + Year
- }
- }
- result.SetBadDateTimeFailure();
- return false;
- }
-
- private static bool GetDayOfYMN(ref DateTimeResult result, ref DateTimeRawInfo raw)
- {
- if ((result.flags & ParseFlags.HaveDate) != 0)
- {
- // Multiple dates in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
-
- if (SetDateYMD(ref result, raw.year, raw.month, raw.GetNumber(0)))
- {
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- result.SetBadDateTimeFailure();
- return false;
- }
-
- private static bool GetDayOfYN(ref DateTimeResult result, ref DateTimeRawInfo raw)
- {
- if ((result.flags & ParseFlags.HaveDate) != 0)
- {
- // Multiple dates in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
-
- if (SetDateYMD(ref result, raw.year, raw.GetNumber(0), 1))
- {
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- result.SetBadDateTimeFailure();
- return false;
- }
-
- private static bool GetDayOfYM(ref DateTimeResult result, ref DateTimeRawInfo raw)
- {
- if ((result.flags & ParseFlags.HaveDate) != 0)
- {
- // Multiple dates in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
-
- if (SetDateYMD(ref result, raw.year, raw.month, 1))
- {
- result.flags |= ParseFlags.HaveDate;
- return true;
- }
- result.SetBadDateTimeFailure();
- return false;
- }
-
- private static void AdjustTimeMark(DateTimeFormatInfo dtfi, ref DateTimeRawInfo raw)
- {
- // Specail case for culture which uses AM as empty string.
- // E.g. af-ZA (0x0436)
- // S1159 \x0000
- // S2359 nm
- // In this case, if we are parsing a string like "2005/09/14 12:23", we will assume this is in AM.
-
- if (raw.timeMark == TM.NotSet)
- {
- if (dtfi.AMDesignator != null && dtfi.PMDesignator != null)
- {
- if (dtfi.AMDesignator.Length == 0 && dtfi.PMDesignator.Length != 0)
- {
- raw.timeMark = TM.AM;
- }
- if (dtfi.PMDesignator.Length == 0 && dtfi.AMDesignator.Length != 0)
- {
- raw.timeMark = TM.PM;
- }
- }
- }
- }
-
- //
- // Adjust hour according to the time mark.
- //
- private static bool AdjustHour(ref int hour, TM timeMark)
- {
- if (timeMark != TM.NotSet)
- {
- if (timeMark == TM.AM)
- {
- if (hour < 0 || hour > 12)
- {
- return false;
- }
- hour = (hour == 12) ? 0 : hour;
- }
- else
- {
- if (hour < 0 || hour > 23)
- {
- return false;
- }
- if (hour < 12)
- {
- hour += 12;
- }
- }
- }
- return true;
- }
-
- private static bool GetTimeOfN(ref DateTimeResult result, ref DateTimeRawInfo raw)
- {
- if ((result.flags & ParseFlags.HaveTime) != 0)
- {
- // Multiple times in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
- //
- // In this case, we need a time mark. Check if so.
- //
- if (raw.timeMark == TM.NotSet)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- result.Hour = raw.GetNumber(0);
- result.flags |= ParseFlags.HaveTime;
- return true;
- }
-
- private static bool GetTimeOfNN(ref DateTimeResult result, ref DateTimeRawInfo raw)
- {
- Debug.Assert(raw.numCount >= 2, "raw.numCount >= 2");
- if ((result.flags & ParseFlags.HaveTime) != 0)
- {
- // Multiple times in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
-
- result.Hour = raw.GetNumber(0);
- result.Minute = raw.GetNumber(1);
- result.flags |= ParseFlags.HaveTime;
- return true;
- }
-
- private static bool GetTimeOfNNN(ref DateTimeResult result, ref DateTimeRawInfo raw)
- {
- if ((result.flags & ParseFlags.HaveTime) != 0)
- {
- // Multiple times in the input string
- result.SetBadDateTimeFailure();
- return false;
- }
- Debug.Assert(raw.numCount >= 3, "raw.numCount >= 3");
- result.Hour = raw.GetNumber(0);
- result.Minute = raw.GetNumber(1);
- result.Second = raw.GetNumber(2);
- result.flags |= ParseFlags.HaveTime;
- return true;
- }
-
- //
- // Processing terminal state: A Date suffix followed by one number.
- //
- private static bool GetDateOfDSN(ref DateTimeResult result, ref DateTimeRawInfo raw)
- {
- if (raw.numCount != 1 || result.Day != -1)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- result.Day = raw.GetNumber(0);
- return true;
- }
-
- private static bool GetDateOfNDS(ref DateTimeResult result, ref DateTimeRawInfo raw)
- {
- if (result.Month == -1)
- {
- // Should have a month suffix
- result.SetBadDateTimeFailure();
- return false;
- }
- if (result.Year != -1)
- {
- // Already has a year suffix
- result.SetBadDateTimeFailure();
- return false;
- }
- if (!TryAdjustYear(ref result, raw.GetNumber(0), out result.Year))
- {
- // the year value is out of range
- result.SetBadDateTimeFailure();
- return false;
- }
- result.Day = 1;
- return true;
- }
-
- private static bool GetDateOfNNDS(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
- {
- // For partial CJK Dates, the only valid formats are with a specified year, followed by two numbers, which
- // will be the Month and Day, and with a specified Month, when the numbers are either the year and day or
- // day and year, depending on the short date pattern.
-
- if ((result.flags & ParseFlags.HaveYear) != 0)
- {
- if (((result.flags & ParseFlags.HaveMonth) == 0) && ((result.flags & ParseFlags.HaveDay) == 0))
- {
- if (TryAdjustYear(ref result, raw.year, out result.Year) && SetDateYMD(ref result, result.Year, raw.GetNumber(0), raw.GetNumber(1)))
- {
- return true;
- }
- }
- }
- else if ((result.flags & ParseFlags.HaveMonth) != 0)
- {
- if (((result.flags & ParseFlags.HaveYear) == 0) && ((result.flags & ParseFlags.HaveDay) == 0))
- {
- int order;
- if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, out order))
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDatePattern), dtfi.ShortDatePattern);
- return false;
- }
- int year;
- if (order == ORDER_YMD)
- {
- if (TryAdjustYear(ref result, raw.GetNumber(0), out year) && SetDateYMD(ref result, year, result.Month, raw.GetNumber(1)))
- {
- return true;
- }
- }
- else
- {
- if (TryAdjustYear(ref result, raw.GetNumber(1), out year) && SetDateYMD(ref result, year, result.Month, raw.GetNumber(0)))
- {
- return true;
- }
- }
- }
- }
- result.SetBadDateTimeFailure();
- return false;
- }
-
- //
- // A date suffix is found, use this method to put the number into the result.
- //
- private static bool ProcessDateTimeSuffix(ref DateTimeResult result, ref DateTimeRawInfo raw, ref DateTimeToken dtok)
- {
- switch (dtok.suffix)
- {
- case TokenType.SEP_YearSuff:
- if ((result.flags & ParseFlags.HaveYear) != 0)
- {
- return false;
- }
- result.flags |= ParseFlags.HaveYear;
- result.Year = raw.year = dtok.num;
- break;
- case TokenType.SEP_MonthSuff:
- if ((result.flags & ParseFlags.HaveMonth) != 0)
- {
- return false;
- }
- result.flags |= ParseFlags.HaveMonth;
- result.Month = raw.month = dtok.num;
- break;
- case TokenType.SEP_DaySuff:
- if ((result.flags & ParseFlags.HaveDay) != 0)
- {
- return false;
- }
- result.flags |= ParseFlags.HaveDay;
- result.Day = dtok.num;
- break;
- case TokenType.SEP_HourSuff:
- if ((result.flags & ParseFlags.HaveHour) != 0)
- {
- return false;
- }
- result.flags |= ParseFlags.HaveHour;
- result.Hour = dtok.num;
- break;
- case TokenType.SEP_MinuteSuff:
- if ((result.flags & ParseFlags.HaveMinute) != 0)
- {
- return false;
- }
- result.flags |= ParseFlags.HaveMinute;
- result.Minute = dtok.num;
- break;
- case TokenType.SEP_SecondSuff:
- if ((result.flags & ParseFlags.HaveSecond) != 0)
- {
- return false;
- }
- result.flags |= ParseFlags.HaveSecond;
- result.Second = dtok.num;
- break;
- }
- return true;
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Actions:
- // This is used by DateTime.Parse().
- // Process the terminal state for the Hebrew calendar parsing.
- //
- ////////////////////////////////////////////////////////////////////////
-
- internal static bool ProcessHebrewTerminalState(DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
- {
- // The following are accepted terminal state for Hebrew date.
- switch (dps)
- {
- case DS.DX_MNN:
- // Deal with the default long/short date format when the year number is ambigous (i.e. year < 100).
- raw.year = raw.GetNumber(1);
- if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true))
- {
- result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, nameof(SR.Format_BadDateTimeCalendar));
- return false;
- }
- if (!GetDayOfMNN(ref result, ref raw, dtfi))
- {
- return false;
- }
- break;
- case DS.DX_YMN:
- // Deal with the default long/short date format when the year number is NOT ambigous (i.e. year >= 100).
- if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true))
- {
- result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, nameof(SR.Format_BadDateTimeCalendar));
- return false;
- }
- if (!GetDayOfYMN(ref result, ref raw))
- {
- return false;
- }
- break;
- case DS.DX_NNY:
- // When formatting, we only format up to the hundred digit of the Hebrew year, although Hebrew year is now over 5000.
- // E.g. if the year is 5763, we only format as 763. so we do the reverse when parsing.
- if (raw.year < 1000)
- {
- raw.year += 5000;
- }
- if (!GetDayOfNNY(ref result, ref raw, dtfi))
- {
- return false;
- }
- if (!dtfi.YearMonthAdjustment(ref result.Year, ref raw.month, true))
- {
- result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, nameof(SR.Format_BadDateTimeCalendar));
- return false;
- }
- break;
- case DS.DX_NM:
- case DS.DX_MN:
- // Deal with Month/Day pattern.
- GetDefaultYear(ref result, ref styles);
- if (!dtfi.YearMonthAdjustment(ref result.Year, ref raw.month, true))
- {
- result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, nameof(SR.Format_BadDateTimeCalendar));
- return false;
- }
- if (!GetHebrewDayOfNM(ref result, ref raw, dtfi))
- {
- return false;
- }
- break;
- case DS.DX_YM:
- // Deal with Year/Month pattern.
- if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true))
- {
- result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, nameof(SR.Format_BadDateTimeCalendar));
- return false;
- }
- if (!GetDayOfYM(ref result, ref raw))
- {
- return false;
- }
- break;
- case DS.TX_N:
- // Deal hour + AM/PM
- if (!GetTimeOfN(ref result, ref raw))
- {
- return false;
- }
- break;
- case DS.TX_NN:
- if (!GetTimeOfNN(ref result, ref raw))
- {
- return false;
- }
- break;
- case DS.TX_NNN:
- if (!GetTimeOfNNN(ref result, ref raw))
- {
- return false;
- }
- break;
- default:
- result.SetBadDateTimeFailure();
- return false;
- }
- if (dps > DS.ERROR)
- {
- //
- // We have reached a terminal state. Reset the raw num count.
- //
- raw.numCount = 0;
- }
- return true;
- }
-
- //
- // A terminal state has been reached, call the appropriate function to fill in the parsing result.
- // Return true if the state is a terminal state.
- //
- internal static bool ProcessTerminalState(DS dps, ref __DTString str, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
- {
- bool passed = true;
- switch (dps)
- {
- case DS.DX_NN:
- passed = GetDayOfNN(ref result, ref styles, ref raw, dtfi);
- break;
- case DS.DX_NNN:
- passed = GetDayOfNNN(ref result, ref raw, dtfi);
- break;
- case DS.DX_MN:
- passed = GetDayOfMN(ref result, ref styles, ref raw, dtfi);
- break;
- case DS.DX_NM:
- passed = GetDayOfNM(ref result, ref styles, ref raw, dtfi);
- break;
- case DS.DX_MNN:
- passed = GetDayOfMNN(ref result, ref raw, dtfi);
- break;
- case DS.DX_DS:
- // The result has got the correct value. No need to process.
- passed = true;
- break;
- case DS.DX_YNN:
- passed = GetDayOfYNN(ref result, ref raw, dtfi);
- break;
- case DS.DX_NNY:
- passed = GetDayOfNNY(ref result, ref raw, dtfi);
- break;
- case DS.DX_YMN:
- passed = GetDayOfYMN(ref result, ref raw);
- break;
- case DS.DX_YN:
- passed = GetDayOfYN(ref result, ref raw);
- break;
- case DS.DX_YM:
- passed = GetDayOfYM(ref result, ref raw);
- break;
- case DS.TX_N:
- passed = GetTimeOfN(ref result, ref raw);
- break;
- case DS.TX_NN:
- passed = GetTimeOfNN(ref result, ref raw);
- break;
- case DS.TX_NNN:
- passed = GetTimeOfNNN(ref result, ref raw);
- break;
- case DS.TX_TS:
- // The result has got the correct value. Nothing to do.
- passed = true;
- break;
- case DS.DX_DSN:
- passed = GetDateOfDSN(ref result, ref raw);
- break;
- case DS.DX_NDS:
- passed = GetDateOfNDS(ref result, ref raw);
- break;
- case DS.DX_NNDS:
- passed = GetDateOfNNDS(ref result, ref raw, dtfi);
- break;
- }
-
- PTSTraceExit(dps, passed);
- if (!passed)
- {
- return false;
- }
-
- if (dps > DS.ERROR)
- {
- //
- // We have reached a terminal state. Reset the raw num count.
- //
- raw.numCount = 0;
- }
- return true;
- }
-
- internal static DateTime Parse(ReadOnlySpan<char> s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
- {
- DateTimeResult result = default; // The buffer to store the parsing result.
- result.Init(s);
- if (TryParse(s, dtfi, styles, ref result))
- {
- return result.parsedDate;
- }
- else
- {
- throw GetDateTimeParseException(ref result);
- }
- }
-
- internal static DateTime Parse(ReadOnlySpan<char> s, DateTimeFormatInfo dtfi, DateTimeStyles styles, out TimeSpan offset)
- {
- DateTimeResult result = default; // The buffer to store the parsing result.
- result.Init(s);
- result.flags |= ParseFlags.CaptureOffset;
- if (TryParse(s, dtfi, styles, ref result))
- {
- offset = result.timeZoneOffset;
- return result.parsedDate;
- }
- else
- {
- throw GetDateTimeParseException(ref result);
- }
- }
-
- internal static bool TryParse(ReadOnlySpan<char> s, DateTimeFormatInfo dtfi, DateTimeStyles styles, out DateTime result)
- {
- DateTimeResult resultData = default; // The buffer to store the parsing result.
- resultData.Init(s);
-
- if (TryParse(s, dtfi, styles, ref resultData))
- {
- result = resultData.parsedDate;
- return true;
- }
-
- result = DateTime.MinValue;
- return false;
- }
-
- internal static bool TryParse(ReadOnlySpan<char> s, DateTimeFormatInfo dtfi, DateTimeStyles styles, out DateTime result, out TimeSpan offset)
- {
- DateTimeResult parseResult = default; // The buffer to store the parsing result.
- parseResult.Init(s);
- parseResult.flags |= ParseFlags.CaptureOffset;
-
- if (TryParse(s, dtfi, styles, ref parseResult))
- {
- result = parseResult.parsedDate;
- offset = parseResult.timeZoneOffset;
- return true;
- }
-
- result = DateTime.MinValue;
- offset = TimeSpan.Zero;
- return false;
- }
-
- //
- // This is the real method to do the parsing work.
- //
- internal static bool TryParse(ReadOnlySpan<char> s, DateTimeFormatInfo dtfi, DateTimeStyles styles, ref DateTimeResult result)
- {
- if (s.Length == 0)
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadDateTime));
- return false;
- }
-
- Debug.Assert(dtfi != null, "dtfi == null");
-
-#if _LOGGING
- DTFITrace(dtfi);
-#endif
-
- DateTime time;
- //
- // First try the predefined format.
- //
-
- DS dps = DS.BEGIN; // Date Parsing State.
- bool reachTerminalState = false;
-
- DateTimeToken dtok = default; // The buffer to store the parsing token.
- dtok.suffix = TokenType.SEP_Unk;
- DateTimeRawInfo raw = default; // The buffer to store temporary parsing information.
- unsafe
- {
- int* numberPointer = stackalloc int[3];
- raw.Init(numberPointer);
- }
- raw.hasSameDateAndTimeSeparators = dtfi.DateSeparator.Equals(dtfi.TimeSeparator, StringComparison.Ordinal);
-
- result.calendar = dtfi.Calendar;
- result.era = Calendar.CurrentEra;
-
- //
- // The string to be parsed. Use a __DTString wrapper so that we can trace the index which
- // indicates the begining of next token.
- //
- __DTString str = new __DTString(s, dtfi);
-
- str.GetNext();
-
- //
- // The following loop will break out when we reach the end of the str.
- //
- do
- {
- //
- // Call the lexer to get the next token.
- //
- // If we find a era in Lex(), the era value will be in raw.era.
- if (!Lex(dps, ref str, ref dtok, ref raw, ref result, ref dtfi, styles))
- {
- TPTraceExit("0000", dps);
- return false;
- }
-
- //
- // If the token is not unknown, process it.
- // Otherwise, just discard it.
- //
- if (dtok.dtt != DTT.Unk)
- {
- //
- // Check if we got any CJK Date/Time suffix.
- // Since the Date/Time suffix tells us the number belongs to year/month/day/hour/minute/second,
- // store the number in the appropriate field in the result.
- //
- if (dtok.suffix != TokenType.SEP_Unk)
- {
- if (!ProcessDateTimeSuffix(ref result, ref raw, ref dtok))
- {
- result.SetBadDateTimeFailure();
- TPTraceExit("0010", dps);
- return false;
- }
-
- dtok.suffix = TokenType.SEP_Unk; // Reset suffix to SEP_Unk;
- }
-
- if (dtok.dtt == DTT.NumLocalTimeMark)
- {
- if (dps == DS.D_YNd || dps == DS.D_YN)
- {
- // Consider this as ISO 8601 format:
- // "yyyy-MM-dd'T'HH:mm:ss" 1999-10-31T02:00:00
- TPTraceExit("0020", dps);
- return ParseISO8601(ref raw, ref str, styles, ref result);
- }
- else
- {
- result.SetBadDateTimeFailure();
- TPTraceExit("0030", dps);
- return false;
- }
- }
-
- if (raw.hasSameDateAndTimeSeparators)
- {
- if (dtok.dtt == DTT.YearEnd || dtok.dtt == DTT.YearSpace || dtok.dtt == DTT.YearDateSep)
- {
- // When time and date separators are same and we are hitting a year number while the first parsed part of the string was recognized
- // as part of time (and not a date) DS.T_Nt, DS.T_NNt then change the state to be a date so we try to parse it as a date instead
- if (dps == DS.T_Nt)
- {
- dps = DS.D_Nd;
- }
- if (dps == DS.T_NNt)
- {
- dps = DS.D_NNd;
- }
- }
-
- bool atEnd = str.AtEnd();
- if (dateParsingStates[(int)dps][(int)dtok.dtt] == DS.ERROR || atEnd)
- {
- switch (dtok.dtt)
- {
- // we have the case of Serbia have dates in forms 'd.M.yyyy.' so we can expect '.' after the date parts.
- // changing the token to end with space instead of Date Separator will avoid failing the parsing.
-
- case DTT.YearDateSep: dtok.dtt = atEnd ? DTT.YearEnd : DTT.YearSpace; break;
- case DTT.NumDatesep: dtok.dtt = atEnd ? DTT.NumEnd : DTT.NumSpace; break;
- case DTT.NumTimesep: dtok.dtt = atEnd ? DTT.NumEnd : DTT.NumSpace; break;
- case DTT.MonthDatesep: dtok.dtt = atEnd ? DTT.MonthEnd : DTT.MonthSpace; break;
- }
- }
- }
-
- //
- // Advance to the next state, and continue
- //
- dps = dateParsingStates[(int)dps][(int)dtok.dtt];
-
- if (dps == DS.ERROR)
- {
- result.SetBadDateTimeFailure();
- TPTraceExit("0040 (invalid state transition)", dps);
- return false;
- }
- else if (dps > DS.ERROR)
- {
- if ((dtfi.FormatFlags & DateTimeFormatFlags.UseHebrewRule) != 0)
- {
- if (!ProcessHebrewTerminalState(dps, ref result, ref styles, ref raw, dtfi))
- {
- TPTraceExit("0050 (ProcessHebrewTerminalState)", dps);
- return false;
- }
- }
- else
- {
- if (!ProcessTerminalState(dps, ref str, ref result, ref styles, ref raw, dtfi))
- {
- TPTraceExit("0060 (ProcessTerminalState)", dps);
- return false;
- }
- }
- reachTerminalState = true;
-
- //
- // If we have reached a terminal state, start over from DS.BEGIN again.
- // For example, when we parsed "1999-12-23 13:30", we will reach a terminal state at "1999-12-23",
- // and we start over so we can continue to parse "12:30".
- //
- dps = DS.BEGIN;
- }
- }
- } while (dtok.dtt != DTT.End && dtok.dtt != DTT.NumEnd && dtok.dtt != DTT.MonthEnd);
-
- if (!reachTerminalState)
- {
- result.SetBadDateTimeFailure();
- TPTraceExit("0070 (did not reach terminal state)", dps);
- return false;
- }
-
- AdjustTimeMark(dtfi, ref raw);
- if (!AdjustHour(ref result.Hour, raw.timeMark))
- {
- result.SetBadDateTimeFailure();
- TPTraceExit("0080 (AdjustHour)", dps);
- return false;
- }
-
- // Check if the parsed string only contains hour/minute/second values.
- bool bTimeOnly = (result.Year == -1 && result.Month == -1 && result.Day == -1);
-
- //
- // Check if any year/month/day is missing in the parsing string.
- // If yes, get the default value from today's date.
- //
- if (!CheckDefaultDateTime(ref result, ref result.calendar, styles))
- {
- TPTraceExit("0090 (failed to fill in missing year/month/day defaults)", dps);
- return false;
- }
-
- if (!result.calendar.TryToDateTime(result.Year, result.Month, result.Day,
- result.Hour, result.Minute, result.Second, 0, result.era, out time))
- {
- result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, nameof(SR.Format_BadDateTimeCalendar));
- TPTraceExit("0100 (result.calendar.TryToDateTime)", dps);
- return false;
- }
-
- if (raw.fraction > 0)
- {
- if (!time.TryAddTicks((long)Math.Round(raw.fraction * Calendar.TicksPerSecond), out time))
- {
- result.SetBadDateTimeFailure();
- TPTraceExit("0100 (time.TryAddTicks)", dps);
- return false;
- }
- }
-
- //
- // We have to check day of week before we adjust to the time zone.
- // Otherwise, the value of day of week may change after adjusting to the time zone.
- //
- if (raw.dayOfWeek != -1)
- {
- //
- // Check if day of week is correct.
- //
- if (raw.dayOfWeek != (int)result.calendar.GetDayOfWeek(time))
- {
- result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, nameof(SR.Format_BadDayOfWeek));
- TPTraceExit("0110 (dayOfWeek check)", dps);
- return false;
- }
- }
-
- result.parsedDate = time;
-
- if (!DetermineTimeZoneAdjustments(ref result, styles, bTimeOnly))
- {
- TPTraceExit("0120 (DetermineTimeZoneAdjustments)", dps);
- return false;
- }
- TPTraceExit("0130 (success)", dps);
- return true;
- }
-
- // Handles time zone adjustments and sets DateTimeKind values as required by the styles
- private static bool DetermineTimeZoneAdjustments(ref DateTimeResult result, DateTimeStyles styles, bool bTimeOnly)
- {
- if ((result.flags & ParseFlags.CaptureOffset) != 0)
- {
- // This is a DateTimeOffset parse, so the offset will actually be captured directly, and
- // no adjustment is required in most cases
- return DateTimeOffsetTimeZonePostProcessing(ref result, styles);
- }
- else
- {
- long offsetTicks = result.timeZoneOffset.Ticks;
-
- // the DateTime offset must be within +- 14:00 hours.
- if (offsetTicks < DateTimeOffset.MinOffset || offsetTicks > DateTimeOffset.MaxOffset)
- {
- result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, nameof(SR.Format_OffsetOutOfRange));
- return false;
- }
- }
-
- // The flags AssumeUniveral and AssumeLocal only apply when the input does not have a time zone
- if ((result.flags & ParseFlags.TimeZoneUsed) == 0)
- {
- // If AssumeLocal or AssumeLocal is used, there will always be a kind specified. As in the
- // case when a time zone is present, it will default to being local unless AdjustToUniversal
- // is present. These comparisons determine whether setting the kind is sufficient, or if a
- // time zone adjustment is required. For consistentcy with the rest of parsing, it is desirable
- // to fall through to the Adjust methods below, so that there is consist handling of boundary
- // cases like wrapping around on time-only dates and temporarily allowing an adjusted date
- // to exceed DateTime.MaxValue
- if ((styles & DateTimeStyles.AssumeLocal) != 0)
- {
- if ((styles & DateTimeStyles.AdjustToUniversal) != 0)
- {
- result.flags |= ParseFlags.TimeZoneUsed;
- result.timeZoneOffset = TimeZoneInfo.GetLocalUtcOffset(result.parsedDate, TimeZoneInfoOptions.NoThrowOnInvalidTime);
- }
- else
- {
- result.parsedDate = DateTime.SpecifyKind(result.parsedDate, DateTimeKind.Local);
- return true;
- }
- }
- else if ((styles & DateTimeStyles.AssumeUniversal) != 0)
- {
- if ((styles & DateTimeStyles.AdjustToUniversal) != 0)
- {
- result.parsedDate = DateTime.SpecifyKind(result.parsedDate, DateTimeKind.Utc);
- return true;
- }
- else
- {
- result.flags |= ParseFlags.TimeZoneUsed;
- result.timeZoneOffset = TimeSpan.Zero;
- }
- }
- else
- {
- // No time zone and no Assume flags, so DateTimeKind.Unspecified is fine
- Debug.Assert(result.parsedDate.Kind == DateTimeKind.Unspecified, "result.parsedDate.Kind == DateTimeKind.Unspecified");
- return true;
- }
- }
-
- if (((styles & DateTimeStyles.RoundtripKind) != 0) && ((result.flags & ParseFlags.TimeZoneUtc) != 0))
- {
- result.parsedDate = DateTime.SpecifyKind(result.parsedDate, DateTimeKind.Utc);
- return true;
- }
-
- if ((styles & DateTimeStyles.AdjustToUniversal) != 0)
- {
- return AdjustTimeZoneToUniversal(ref result);
- }
- return AdjustTimeZoneToLocal(ref result, bTimeOnly);
- }
-
- // Apply validation and adjustments specific to DateTimeOffset
- private static bool DateTimeOffsetTimeZonePostProcessing(ref DateTimeResult result, DateTimeStyles styles)
- {
- // For DateTimeOffset, default to the Utc or Local offset when an offset was not specified by
- // the input string.
- if ((result.flags & ParseFlags.TimeZoneUsed) == 0)
- {
- if ((styles & DateTimeStyles.AssumeUniversal) != 0)
- {
- // AssumeUniversal causes the offset to default to zero (0)
- result.timeZoneOffset = TimeSpan.Zero;
- }
- else
- {
- // AssumeLocal causes the offset to default to Local. This flag is on by default for DateTimeOffset.
- result.timeZoneOffset = TimeZoneInfo.GetLocalUtcOffset(result.parsedDate, TimeZoneInfoOptions.NoThrowOnInvalidTime);
- }
- }
-
- long offsetTicks = result.timeZoneOffset.Ticks;
-
- // there should be no overflow, because the offset can be no more than -+100 hours and the date already
- // fits within a DateTime.
- long utcTicks = result.parsedDate.Ticks - offsetTicks;
-
- // For DateTimeOffset, both the parsed time and the corresponding UTC value must be within the boundaries
- // of a DateTime instance.
- if (utcTicks < DateTime.MinTicks || utcTicks > DateTime.MaxTicks)
- {
- result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, nameof(SR.Format_UTCOutOfRange));
- return false;
- }
-
- // the offset must be within +- 14:00 hours.
- if (offsetTicks < DateTimeOffset.MinOffset || offsetTicks > DateTimeOffset.MaxOffset)
- {
- result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, nameof(SR.Format_OffsetOutOfRange));
- return false;
- }
-
- // DateTimeOffset should still honor the AdjustToUniversal flag for consistency with DateTime. It means you
- // want to return an adjusted UTC value, so store the utcTicks in the DateTime and set the offset to zero
- if ((styles & DateTimeStyles.AdjustToUniversal) != 0)
- {
- if (((result.flags & ParseFlags.TimeZoneUsed) == 0) && ((styles & DateTimeStyles.AssumeUniversal) == 0))
- {
- // Handle the special case where the timeZoneOffset was defaulted to Local
- bool toUtcResult = AdjustTimeZoneToUniversal(ref result);
- result.timeZoneOffset = TimeSpan.Zero;
- return toUtcResult;
- }
-
- // The constructor should always succeed because of the range check earlier in the function
- // Although it is UTC, internally DateTimeOffset does not use this flag
- result.parsedDate = new DateTime(utcTicks, DateTimeKind.Utc);
- result.timeZoneOffset = TimeSpan.Zero;
- }
-
- return true;
- }
-
- //
- // Adjust the specified time to universal time based on the supplied timezone.
- // E.g. when parsing "2001/06/08 14:00-07:00",
- // the time is 2001/06/08 14:00, and timeZoneOffset = -07:00.
- // The result will be "2001/06/08 21:00"
- //
- private static bool AdjustTimeZoneToUniversal(ref DateTimeResult result)
- {
- long resultTicks = result.parsedDate.Ticks;
- resultTicks -= result.timeZoneOffset.Ticks;
- if (resultTicks < 0)
- {
- resultTicks += Calendar.TicksPerDay;
- }
-
- if (resultTicks < DateTime.MinTicks || resultTicks > DateTime.MaxTicks)
- {
- result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, nameof(SR.Format_DateOutOfRange));
- return false;
- }
- result.parsedDate = new DateTime(resultTicks, DateTimeKind.Utc);
- return true;
- }
-
- //
- // Adjust the specified time to universal time based on the supplied timezone,
- // and then convert to local time.
- // E.g. when parsing "2001/06/08 14:00-04:00", and local timezone is GMT-7.
- // the time is 2001/06/08 14:00, and timeZoneOffset = -05:00.
- // The result will be "2001/06/08 11:00"
- //
- private static bool AdjustTimeZoneToLocal(ref DateTimeResult result, bool bTimeOnly)
- {
- long resultTicks = result.parsedDate.Ticks;
- // Convert to local ticks
- TimeZoneInfo tz = TimeZoneInfo.Local;
- bool isAmbiguousLocalDst = false;
- if (resultTicks < Calendar.TicksPerDay)
- {
- //
- // This is time of day.
- //
-
- // Adjust timezone.
- resultTicks -= result.timeZoneOffset.Ticks;
- // If the time is time of day, use the current timezone offset.
- resultTicks += tz.GetUtcOffset(bTimeOnly ? DateTime.Now : result.parsedDate, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks;
-
- if (resultTicks < 0)
- {
- resultTicks += Calendar.TicksPerDay;
- }
- }
- else
- {
- // Adjust timezone to GMT.
- resultTicks -= result.timeZoneOffset.Ticks;
- if (resultTicks < DateTime.MinTicks || resultTicks > DateTime.MaxTicks)
- {
- // If the result ticks is greater than DateTime.MaxValue, we can not create a DateTime from this ticks.
- // In this case, keep using the old code.
- resultTicks += tz.GetUtcOffset(result.parsedDate, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks;
- }
- else
- {
- // Convert the GMT time to local time.
- DateTime utcDt = new DateTime(resultTicks, DateTimeKind.Utc);
- bool isDaylightSavings = false;
- resultTicks += TimeZoneInfo.GetUtcOffsetFromUtc(utcDt, TimeZoneInfo.Local, out isDaylightSavings, out isAmbiguousLocalDst).Ticks;
- }
- }
- if (resultTicks < DateTime.MinTicks || resultTicks > DateTime.MaxTicks)
- {
- result.parsedDate = DateTime.MinValue;
- result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, nameof(SR.Format_DateOutOfRange));
- return false;
- }
- result.parsedDate = new DateTime(resultTicks, DateTimeKind.Local, isAmbiguousLocalDst);
- return true;
- }
-
- //
- // Parse the ISO8601 format string found during Parse();
- //
- //
- private static bool ParseISO8601(ref DateTimeRawInfo raw, ref __DTString str, DateTimeStyles styles, ref DateTimeResult result)
- {
- if (raw.year < 0 || raw.GetNumber(0) < 0 || raw.GetNumber(1) < 0)
- {
- }
- str.Index--;
- int hour, minute;
- int second = 0;
- double partSecond = 0;
-
- str.SkipWhiteSpaces();
- if (!ParseDigits(ref str, 2, out hour))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- str.SkipWhiteSpaces();
- if (!str.Match(':'))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- str.SkipWhiteSpaces();
- if (!ParseDigits(ref str, 2, out minute))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- str.SkipWhiteSpaces();
- if (str.Match(':'))
- {
- str.SkipWhiteSpaces();
- if (!ParseDigits(ref str, 2, out second))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- if (str.Match('.'))
- {
- if (!ParseFraction(ref str, out partSecond))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- str.Index--;
- }
- str.SkipWhiteSpaces();
- }
- if (str.GetNext())
- {
- char ch = str.GetChar();
- if (ch == '+' || ch == '-')
- {
- result.flags |= ParseFlags.TimeZoneUsed;
- if (!ParseTimeZone(ref str, ref result.timeZoneOffset))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- else if (ch == 'Z' || ch == 'z')
- {
- result.flags |= ParseFlags.TimeZoneUsed;
- result.timeZoneOffset = TimeSpan.Zero;
- result.flags |= ParseFlags.TimeZoneUtc;
- }
- else
- {
- str.Index--;
- }
- str.SkipWhiteSpaces();
- if (str.Match('#'))
- {
- if (!VerifyValidPunctuation(ref str))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- str.SkipWhiteSpaces();
- }
- if (str.Match('\0'))
- {
- if (!VerifyValidPunctuation(ref str))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- if (str.GetNext())
- {
- // If this is true, there were non-white space characters remaining in the DateTime
- result.SetBadDateTimeFailure();
- return false;
- }
- }
-
- DateTime time;
- Calendar calendar = GregorianCalendar.GetDefaultInstance();
- if (!calendar.TryToDateTime(raw.year, raw.GetNumber(0), raw.GetNumber(1),
- hour, minute, second, 0, result.era, out time))
- {
- result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, nameof(SR.Format_BadDateTimeCalendar));
- return false;
- }
-
- if (!time.TryAddTicks((long)Math.Round(partSecond * Calendar.TicksPerSecond), out time))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- result.parsedDate = time;
- return DetermineTimeZoneAdjustments(ref result, styles, false);
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Actions:
- // Parse the current word as a Hebrew number.
- // This is used by DateTime.ParseExact().
- //
- ////////////////////////////////////////////////////////////////////////
-
- internal static bool MatchHebrewDigits(ref __DTString str, int digitLen, out int number)
- {
- number = 0;
-
- // Create a context object so that we can parse the Hebrew number text character by character.
- HebrewNumberParsingContext context = new HebrewNumberParsingContext(0);
-
- // Set this to ContinueParsing so that we will run the following while loop in the first time.
- HebrewNumberParsingState state = HebrewNumberParsingState.ContinueParsing;
-
- while (state == HebrewNumberParsingState.ContinueParsing && str.GetNext())
- {
- state = HebrewNumber.ParseByChar(str.GetChar(), ref context);
- }
-
- if (state == HebrewNumberParsingState.FoundEndOfHebrewNumber)
- {
- // If we have reached a terminal state, update the result and returns.
- number = context.result;
- return true;
- }
-
- // If we run out of the character before reaching FoundEndOfHebrewNumber, or
- // the state is InvalidHebrewNumber or ContinueParsing, we fail to match a Hebrew number.
- // Return an error.
- return false;
- }
-
- /*=================================ParseDigits==================================
- **Action: Parse the number string in __DTString that are formatted using
- ** the following patterns:
- ** "0", "00", and "000..0"
- **Returns: the integer value
- **Arguments: str: a __DTString. The parsing will start from the
- ** next character after str.Index.
- **Exceptions: FormatException if error in parsing number.
- ==============================================================================*/
-
- internal static bool ParseDigits(ref __DTString str, int digitLen, out int result)
- {
- if (digitLen == 1)
- {
- // 1 really means 1 or 2 for this call
- return ParseDigits(ref str, 1, 2, out result);
- }
- else
- {
- return ParseDigits(ref str, digitLen, digitLen, out result);
- }
- }
-
- internal static bool ParseDigits(ref __DTString str, int minDigitLen, int maxDigitLen, out int result)
- {
- Debug.Assert(minDigitLen > 0, "minDigitLen > 0");
- Debug.Assert(maxDigitLen < 9, "maxDigitLen < 9");
- Debug.Assert(minDigitLen <= maxDigitLen, "minDigitLen <= maxDigitLen");
- int localResult = 0;
- int startingIndex = str.Index;
- int tokenLength = 0;
- while (tokenLength < maxDigitLen)
- {
- if (!str.GetNextDigit())
- {
- str.Index--;
- break;
- }
- localResult = localResult * 10 + str.GetDigit();
- tokenLength++;
- }
- result = localResult;
- if (tokenLength < minDigitLen)
- {
- str.Index = startingIndex;
- return false;
- }
- return true;
- }
-
- /*=================================ParseFractionExact==================================
- **Action: Parse the number string in __DTString that are formatted using
- ** the following patterns:
- ** "0", "00", and "000..0"
- **Returns: the fraction value
- **Arguments: str: a __DTString. The parsing will start from the
- ** next character after str.Index.
- **Exceptions: FormatException if error in parsing number.
- ==============================================================================*/
-
- private static bool ParseFractionExact(ref __DTString str, int maxDigitLen, ref double result)
- {
- if (!str.GetNextDigit())
- {
- str.Index--;
- return false;
- }
- result = str.GetDigit();
-
- int digitLen = 1;
- for (; digitLen < maxDigitLen; digitLen++)
- {
- if (!str.GetNextDigit())
- {
- str.Index--;
- break;
- }
- result = result * 10 + str.GetDigit();
- }
-
- result /= TimeSpanParse.Pow10(digitLen);
- return digitLen == maxDigitLen;
- }
-
- /*=================================ParseSign==================================
- **Action: Parse a positive or a negative sign.
- **Returns: true if postive sign. flase if negative sign.
- **Arguments: str: a __DTString. The parsing will start from the
- ** next character after str.Index.
- **Exceptions: FormatException if end of string is encountered or a sign
- ** symbol is not found.
- ==============================================================================*/
-
- private static bool ParseSign(ref __DTString str, ref bool result)
- {
- if (!str.GetNext())
- {
- // A sign symbol ('+' or '-') is expected. However, end of string is encountered.
- return false;
- }
- char ch = str.GetChar();
- if (ch == '+')
- {
- result = true;
- return true;
- }
- else if (ch == '-')
- {
- result = false;
- return true;
- }
- // A sign symbol ('+' or '-') is expected.
- return false;
- }
-
- /*=================================ParseTimeZoneOffset==================================
- **Action: Parse the string formatted using "z", "zz", "zzz" in DateTime.Format().
- **Returns: the TimeSpan for the parsed timezone offset.
- **Arguments: str: a __DTString. The parsing will start from the
- ** next character after str.Index.
- ** len: the repeated number of the "z"
- **Exceptions: FormatException if errors in parsing.
- ==============================================================================*/
-
- private static bool ParseTimeZoneOffset(ref __DTString str, int len, ref TimeSpan result)
- {
- bool isPositive = true;
- int hourOffset;
- int minuteOffset = 0;
-
- switch (len)
- {
- case 1:
- case 2:
- if (!ParseSign(ref str, ref isPositive))
- {
- return false;
- }
- if (!ParseDigits(ref str, len, out hourOffset))
- {
- return false;
- }
- break;
- default:
- if (!ParseSign(ref str, ref isPositive))
- {
- return false;
- }
-
- // Parsing 1 digit will actually parse 1 or 2.
- if (!ParseDigits(ref str, 1, out hourOffset))
- {
- return false;
- }
- // ':' is optional.
- if (str.Match(":"))
- {
- // Found ':'
- if (!ParseDigits(ref str, 2, out minuteOffset))
- {
- return false;
- }
- }
- else
- {
- // Since we can not match ':', put the char back.
- str.Index--;
- if (!ParseDigits(ref str, 2, out minuteOffset))
- {
- return false;
- }
- }
- break;
- }
- if (minuteOffset < 0 || minuteOffset >= 60)
- {
- return false;
- }
-
- result = (new TimeSpan(hourOffset, minuteOffset, 0));
- if (!isPositive)
- {
- result = result.Negate();
- }
- return true;
- }
-
- /*=================================MatchAbbreviatedMonthName==================================
- **Action: Parse the abbreviated month name from string starting at str.Index.
- **Returns: A value from 1 to 12 for the first month to the twelfth month.
- **Arguments: str: a __DTString. The parsing will start from the
- ** next character after str.Index.
- **Exceptions: FormatException if an abbreviated month name can not be found.
- ==============================================================================*/
-
- private static bool MatchAbbreviatedMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
- {
- int maxMatchStrLen = 0;
- result = -1;
- if (str.GetNext())
- {
- //
- // Scan the month names (note that some calendars has 13 months) and find
- // the matching month name which has the max string length.
- // We need to do this because some cultures (e.g. "cs-CZ") which have
- // abbreviated month names with the same prefix.
- //
- int monthsInYear = (dtfi.GetMonthName(13).Length == 0 ? 12 : 13);
- for (int i = 1; i <= monthsInYear; i++)
- {
- string searchStr = dtfi.GetAbbreviatedMonthName(i);
- int matchStrLen = searchStr.Length;
- if (dtfi.HasSpacesInMonthNames
- ? str.MatchSpecifiedWords(searchStr, false, ref matchStrLen)
- : str.MatchSpecifiedWord(searchStr))
- {
- if (matchStrLen > maxMatchStrLen)
- {
- maxMatchStrLen = matchStrLen;
- result = i;
- }
- }
- }
-
- // Search genitive form.
- if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0)
- {
- int tempResult = str.MatchLongestWords(dtfi.AbbreviatedMonthGenitiveNames, ref maxMatchStrLen);
-
- // We found a longer match in the genitive month name. Use this as the result.
- // tempResult + 1 should be the month value.
- if (tempResult >= 0)
- {
- result = tempResult + 1;
- }
- }
-
- // Search leap year form.
- if ((dtfi.FormatFlags & DateTimeFormatFlags.UseLeapYearMonth) != 0)
- {
- int tempResult = str.MatchLongestWords(dtfi.InternalGetLeapYearMonthNames(), ref maxMatchStrLen);
- // We found a longer match in the leap year month name. Use this as the result.
- // The result from MatchLongestWords is 0 ~ length of word array.
- // So we increment the result by one to become the month value.
- if (tempResult >= 0)
- {
- result = tempResult + 1;
- }
- }
- }
- if (result > 0)
- {
- str.Index += (maxMatchStrLen - 1);
- return true;
- }
- return false;
- }
-
- /*=================================MatchMonthName==================================
- **Action: Parse the month name from string starting at str.Index.
- **Returns: A value from 1 to 12 indicating the first month to the twelfth month.
- **Arguments: str: a __DTString. The parsing will start from the
- ** next character after str.Index.
- **Exceptions: FormatException if a month name can not be found.
- ==============================================================================*/
-
- private static bool MatchMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
- {
- int maxMatchStrLen = 0;
- result = -1;
- if (str.GetNext())
- {
- //
- // Scan the month names (note that some calendars has 13 months) and find
- // the matching month name which has the max string length.
- // We need to do this because some cultures (e.g. "vi-VN") which have
- // month names with the same prefix.
- //
- int monthsInYear = (dtfi.GetMonthName(13).Length == 0 ? 12 : 13);
- for (int i = 1; i <= monthsInYear; i++)
- {
- string searchStr = dtfi.GetMonthName(i);
- int matchStrLen = searchStr.Length;
- if (dtfi.HasSpacesInMonthNames
- ? str.MatchSpecifiedWords(searchStr, false, ref matchStrLen)
- : str.MatchSpecifiedWord(searchStr))
- {
- if (matchStrLen > maxMatchStrLen)
- {
- maxMatchStrLen = matchStrLen;
- result = i;
- }
- }
- }
-
- // Search genitive form.
- if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0)
- {
- int tempResult = str.MatchLongestWords(dtfi.MonthGenitiveNames, ref maxMatchStrLen);
- // We found a longer match in the genitive month name. Use this as the result.
- // The result from MatchLongestWords is 0 ~ length of word array.
- // So we increment the result by one to become the month value.
- if (tempResult >= 0)
- {
- result = tempResult + 1;
- }
- }
-
- // Search leap year form.
- if ((dtfi.FormatFlags & DateTimeFormatFlags.UseLeapYearMonth) != 0)
- {
- int tempResult = str.MatchLongestWords(dtfi.InternalGetLeapYearMonthNames(), ref maxMatchStrLen);
- // We found a longer match in the leap year month name. Use this as the result.
- // The result from MatchLongestWords is 0 ~ length of word array.
- // So we increment the result by one to become the month value.
- if (tempResult >= 0)
- {
- result = tempResult + 1;
- }
- }
- }
-
- if (result > 0)
- {
- str.Index += (maxMatchStrLen - 1);
- return true;
- }
- return false;
- }
-
- /*=================================MatchAbbreviatedDayName==================================
- **Action: Parse the abbreviated day of week name from string starting at str.Index.
- **Returns: A value from 0 to 6 indicating Sunday to Saturday.
- **Arguments: str: a __DTString. The parsing will start from the
- ** next character after str.Index.
- **Exceptions: FormatException if a abbreviated day of week name can not be found.
- ==============================================================================*/
-
- private static bool MatchAbbreviatedDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
- {
- int maxMatchStrLen = 0;
- result = -1;
- if (str.GetNext())
- {
- for (DayOfWeek i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++)
- {
- string searchStr = dtfi.GetAbbreviatedDayName(i);
- int matchStrLen = searchStr.Length;
- if (dtfi.HasSpacesInDayNames
- ? str.MatchSpecifiedWords(searchStr, false, ref matchStrLen)
- : str.MatchSpecifiedWord(searchStr))
- {
- if (matchStrLen > maxMatchStrLen)
- {
- maxMatchStrLen = matchStrLen;
- result = (int)i;
- }
- }
- }
- }
- if (result >= 0)
- {
- str.Index += maxMatchStrLen - 1;
- return true;
- }
- return false;
- }
-
- /*=================================MatchDayName==================================
- **Action: Parse the day of week name from string starting at str.Index.
- **Returns: A value from 0 to 6 indicating Sunday to Saturday.
- **Arguments: str: a __DTString. The parsing will start from the
- ** next character after str.Index.
- **Exceptions: FormatException if a day of week name can not be found.
- ==============================================================================*/
-
- private static bool MatchDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
- {
- // Turkish (tr-TR) got day names with the same prefix.
- int maxMatchStrLen = 0;
- result = -1;
- if (str.GetNext())
- {
- for (DayOfWeek i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++)
- {
- string searchStr = dtfi.GetDayName(i);
- int matchStrLen = searchStr.Length;
- if (dtfi.HasSpacesInDayNames
- ? str.MatchSpecifiedWords(searchStr, false, ref matchStrLen)
- : str.MatchSpecifiedWord(searchStr))
- {
- if (matchStrLen > maxMatchStrLen)
- {
- maxMatchStrLen = matchStrLen;
- result = (int)i;
- }
- }
- }
- }
- if (result >= 0)
- {
- str.Index += maxMatchStrLen - 1;
- return true;
- }
- return false;
- }
-
- /*=================================MatchEraName==================================
- **Action: Parse era name from string starting at str.Index.
- **Returns: An era value.
- **Arguments: str: a __DTString. The parsing will start from the
- ** next character after str.Index.
- **Exceptions: FormatException if an era name can not be found.
- ==============================================================================*/
-
- private static bool MatchEraName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
- {
- if (str.GetNext())
- {
- int[] eras = dtfi.Calendar.Eras;
-
- if (eras != null)
- {
- for (int i = 0; i < eras.Length; i++)
- {
- string searchStr = dtfi.GetEraName(eras[i]);
- if (str.MatchSpecifiedWord(searchStr))
- {
- str.Index += (searchStr.Length - 1);
- result = eras[i];
- return true;
- }
- searchStr = dtfi.GetAbbreviatedEraName(eras[i]);
- if (str.MatchSpecifiedWord(searchStr))
- {
- str.Index += (searchStr.Length - 1);
- result = eras[i];
- return true;
- }
- }
- }
- }
- return false;
- }
-
- /*=================================MatchTimeMark==================================
- **Action: Parse the time mark (AM/PM) from string starting at str.Index.
- **Returns: TM_AM or TM_PM.
- **Arguments: str: a __DTString. The parsing will start from the
- ** next character after str.Index.
- **Exceptions: FormatException if a time mark can not be found.
- ==============================================================================*/
-
- private static bool MatchTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result)
- {
- result = TM.NotSet;
- // In some cultures have empty strings in AM/PM mark. E.g. af-ZA (0x0436), the AM mark is "", and PM mark is "nm".
- if (dtfi.AMDesignator.Length == 0)
- {
- result = TM.AM;
- }
- if (dtfi.PMDesignator.Length == 0)
- {
- result = TM.PM;
- }
-
- if (str.GetNext())
- {
- string searchStr = dtfi.AMDesignator;
- if (searchStr.Length > 0)
- {
- if (str.MatchSpecifiedWord(searchStr))
- {
- // Found an AM timemark with length > 0.
- str.Index += (searchStr.Length - 1);
- result = TM.AM;
- return true;
- }
- }
- searchStr = dtfi.PMDesignator;
- if (searchStr.Length > 0)
- {
- if (str.MatchSpecifiedWord(searchStr))
- {
- // Found a PM timemark with length > 0.
- str.Index += (searchStr.Length - 1);
- result = TM.PM;
- return true;
- }
- }
- str.Index--; // Undo the GetNext call.
- }
- if (result != TM.NotSet)
- {
- // If one of the AM/PM marks is empty string, return the result.
- return true;
- }
- return false;
- }
-
- /*=================================MatchAbbreviatedTimeMark==================================
- **Action: Parse the abbreviated time mark (AM/PM) from string starting at str.Index.
- **Returns: TM_AM or TM_PM.
- **Arguments: str: a __DTString. The parsing will start from the
- ** next character after str.Index.
- **Exceptions: FormatException if a abbreviated time mark can not be found.
- ==============================================================================*/
-
- private static bool MatchAbbreviatedTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result)
- {
- // NOTENOTE : the assumption here is that abbreviated time mark is the first
- // character of the AM/PM designator. If this invariant changes, we have to
- // change the code below.
- if (str.GetNext())
- {
- string amDesignator = dtfi.AMDesignator;
- if (amDesignator.Length > 0 && str.GetChar() == amDesignator[0])
- {
- result = TM.AM;
- return true;
- }
-
- string pmDesignator = dtfi.PMDesignator;
- if (pmDesignator.Length > 0 && str.GetChar() == pmDesignator[0])
- {
- result = TM.PM;
- return true;
- }
- }
- return false;
- }
-
- /*=================================CheckNewValue==================================
- **Action: Check if currentValue is initialized. If not, return the newValue.
- ** If yes, check if the current value is equal to newValue. Return false
- ** if they are not equal. This is used to check the case like "d" and "dd" are both
- ** used to format a string.
- **Returns: the correct value for currentValue.
- **Arguments:
- **Exceptions:
- ==============================================================================*/
-
- private static bool CheckNewValue(ref int currentValue, int newValue, char patternChar, ref DateTimeResult result)
- {
- if (currentValue == -1)
- {
- currentValue = newValue;
- return true;
- }
- else
- {
- if (newValue != currentValue)
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_RepeatDateTimePattern), patternChar);
- return false;
- }
- }
- return true;
- }
-
- private static DateTime GetDateTimeNow(ref DateTimeResult result, ref DateTimeStyles styles)
- {
- if ((result.flags & ParseFlags.CaptureOffset) != 0)
- {
- if ((result.flags & ParseFlags.TimeZoneUsed) != 0)
- {
- // use the supplied offset to calculate 'Now'
- return new DateTime(DateTime.UtcNow.Ticks + result.timeZoneOffset.Ticks, DateTimeKind.Unspecified);
- }
- else if ((styles & DateTimeStyles.AssumeUniversal) != 0)
- {
- // assume the offset is Utc
- return DateTime.UtcNow;
- }
- }
-
- // assume the offset is Local
- return DateTime.Now;
- }
-
- private static bool CheckDefaultDateTime(ref DateTimeResult result, ref Calendar cal, DateTimeStyles styles)
- {
- if ((result.flags & ParseFlags.CaptureOffset) != 0)
- {
- // DateTimeOffset.Parse should allow dates without a year, but only if there is also no time zone marker;
- // e.g. "May 1 5pm" is OK, but "May 1 5pm -08:30" is not. This is somewhat pragmatic, since we would
- // have to rearchitect parsing completely to allow this one case to correctly handle things like leap
- // years and leap months. Is an extremely corner case, and DateTime is basically incorrect in that
- // case today.
- //
- // values like "11:00Z" or "11:00 -3:00" are also acceptable
- //
- // if ((month or day is set) and (year is not set and time zone is set))
- //
- if (((result.Month != -1) || (result.Day != -1))
- && ((result.Year == -1 || ((result.flags & ParseFlags.YearDefault) != 0)) && (result.flags & ParseFlags.TimeZoneUsed) != 0))
- {
- result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, nameof(SR.Format_MissingIncompleteDate));
- return false;
- }
- }
-
- if ((result.Year == -1) || (result.Month == -1) || (result.Day == -1))
- {
- /*
- The following table describes the behaviors of getting the default value
- when a certain year/month/day values are missing.
-
- An "X" means that the value exists. And "--" means that value is missing.
-
- Year Month Day => ResultYear ResultMonth ResultDay Note
-
- X X X Parsed year Parsed month Parsed day
- X X -- Parsed Year Parsed month First day If we have year and month, assume the first day of that month.
- X -- X Parsed year First month Parsed day If the month is missing, assume first month of that year.
- X -- -- Parsed year First month First day If we have only the year, assume the first day of that year.
-
- -- X X CurrentYear Parsed month Parsed day If the year is missing, assume the current year.
- -- X -- CurrentYear Parsed month First day If we have only a month value, assume the current year and current day.
- -- -- X CurrentYear First month Parsed day If we have only a day value, assume current year and first month.
- -- -- -- CurrentYear Current month Current day So this means that if the date string only contains time, you will get current date.
-
- */
-
- DateTime now = GetDateTimeNow(ref result, ref styles);
- if (result.Month == -1 && result.Day == -1)
- {
- if (result.Year == -1)
- {
- if ((styles & DateTimeStyles.NoCurrentDateDefault) != 0)
- {
- // If there is no year/month/day values, and NoCurrentDateDefault flag is used,
- // set the year/month/day value to the beginning year/month/day of DateTime().
- // Note we should be using Gregorian for the year/month/day.
- cal = GregorianCalendar.GetDefaultInstance();
- result.Year = result.Month = result.Day = 1;
- }
- else
- {
- // Year/Month/Day are all missing.
- result.Year = cal.GetYear(now);
- result.Month = cal.GetMonth(now);
- result.Day = cal.GetDayOfMonth(now);
- }
- }
- else
- {
- // Month/Day are both missing.
- result.Month = 1;
- result.Day = 1;
- }
- }
- else
- {
- if (result.Year == -1)
- {
- result.Year = cal.GetYear(now);
- }
- if (result.Month == -1)
- {
- result.Month = 1;
- }
- if (result.Day == -1)
- {
- result.Day = 1;
- }
- }
- }
- // Set Hour/Minute/Second to zero if these value are not in str.
- if (result.Hour == -1) result.Hour = 0;
- if (result.Minute == -1) result.Minute = 0;
- if (result.Second == -1) result.Second = 0;
- if (result.era == -1) result.era = Calendar.CurrentEra;
- return true;
- }
-
- // Expand a pre-defined format string (like "D" for long date) to the real format that
- // we are going to use in the date time parsing.
- // This method also set the dtfi according/parseInfo to some special pre-defined
- // formats.
- //
- private static string ExpandPredefinedFormat(ReadOnlySpan<char> format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result)
- {
- //
- // Check the format to see if we need to override the dtfi to be InvariantInfo,
- // and see if we need to set up the userUniversalTime flag.
- //
- switch (format[0])
- {
- case 's': // Sortable format (in local time)
- case 'o':
- case 'O': // Round Trip Format
- ConfigureFormatOS(ref dtfi, ref parseInfo);
- break;
- case 'r':
- case 'R': // RFC 1123 Standard. (in Universal time)
- ConfigureFormatR(ref dtfi, ref parseInfo, ref result);
- break;
- case 'u': // Universal time format in sortable format.
- parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
- dtfi = DateTimeFormatInfo.InvariantInfo;
-
- if ((result.flags & ParseFlags.CaptureOffset) != 0)
- {
- result.flags |= ParseFlags.UtcSortPattern;
- }
- break;
- case 'U': // Universal time format with culture-dependent format.
- parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
- result.flags |= ParseFlags.TimeZoneUsed;
- result.timeZoneOffset = new TimeSpan(0);
- result.flags |= ParseFlags.TimeZoneUtc;
- if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
- {
- dtfi = (DateTimeFormatInfo)dtfi.Clone();
- dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
- }
- break;
- }
-
- //
- // Expand the pre-defined format character to the real format from DateTimeFormatInfo.
- //
- return DateTimeFormat.GetRealFormat(format, dtfi);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool ParseJapaneseEraStart(ref __DTString str, DateTimeFormatInfo dtfi)
- {
- // ParseJapaneseEraStart will be called when parsing the year number. We can have dates which not listing
- // the year as a number and listing it as JapaneseEraStart symbol (which means year 1).
- // This will be legitimate date to recognize.
- if (LocalAppContextSwitches.EnforceLegacyJapaneseDateParsing || dtfi.Calendar.ID != CalendarId.JAPAN || !str.GetNext())
- return false;
-
- if (str.m_current != DateTimeFormatInfo.JapaneseEraStart[0])
- {
- str.Index--;
- return false;
- }
-
- return true;
- }
-
- private static void ConfigureFormatR(ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result)
- {
- parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
- dtfi = DateTimeFormatInfo.InvariantInfo;
- if ((result.flags & ParseFlags.CaptureOffset) != 0)
- {
- result.flags |= ParseFlags.Rfc1123Pattern;
- }
- }
-
- private static void ConfigureFormatOS(ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo)
- {
- parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
- dtfi = DateTimeFormatInfo.InvariantInfo;
- }
-
- // Given a specified format character, parse and update the parsing result.
- //
- private static bool ParseByFormat(
- ref __DTString str,
- ref __DTString format,
- ref ParsingInfo parseInfo,
- DateTimeFormatInfo dtfi,
- ref DateTimeResult result)
- {
- int tokenLen = 0;
- int tempYear = 0, tempMonth = 0, tempDay = 0, tempDayOfWeek = 0, tempHour = 0, tempMinute = 0, tempSecond = 0;
- double tempFraction = 0;
- TM tempTimeMark = 0;
-
- char ch = format.GetChar();
-
- switch (ch)
- {
- case 'y':
- tokenLen = format.GetRepeatCount();
- bool parseResult;
- if (ParseJapaneseEraStart(ref str, dtfi))
- {
- tempYear = 1;
- parseResult = true;
- }
- else if (dtfi.HasForceTwoDigitYears)
- {
- parseResult = ParseDigits(ref str, 1, 4, out tempYear);
- }
- else
- {
- if (tokenLen <= 2)
- {
- parseInfo.fUseTwoDigitYear = true;
- }
- parseResult = ParseDigits(ref str, tokenLen, out tempYear);
- }
- if (!parseResult && parseInfo.fCustomNumberParser)
- {
- parseResult = parseInfo.parseNumberDelegate(ref str, tokenLen, out tempYear);
- }
- if (!parseResult)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- if (!CheckNewValue(ref result.Year, tempYear, ch, ref result))
- {
- return false;
- }
- break;
- case 'M':
- tokenLen = format.GetRepeatCount();
- if (tokenLen <= 2)
- {
- if (!ParseDigits(ref str, tokenLen, out tempMonth))
- {
- if (!parseInfo.fCustomNumberParser ||
- !parseInfo.parseNumberDelegate(ref str, tokenLen, out tempMonth))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- }
- else
- {
- if (tokenLen == 3)
- {
- if (!MatchAbbreviatedMonthName(ref str, dtfi, ref tempMonth))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- else
- {
- if (!MatchMonthName(ref str, dtfi, ref tempMonth))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- result.flags |= ParseFlags.ParsedMonthName;
- }
- if (!CheckNewValue(ref result.Month, tempMonth, ch, ref result))
- {
- return false;
- }
- break;
- case 'd':
- // Day & Day of week
- tokenLen = format.GetRepeatCount();
- if (tokenLen <= 2)
- {
- // "d" & "dd"
-
- if (!ParseDigits(ref str, tokenLen, out tempDay))
- {
- if (!parseInfo.fCustomNumberParser ||
- !parseInfo.parseNumberDelegate(ref str, tokenLen, out tempDay))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- if (!CheckNewValue(ref result.Day, tempDay, ch, ref result))
- {
- return false;
- }
- }
- else
- {
- if (tokenLen == 3)
- {
- // "ddd"
- if (!MatchAbbreviatedDayName(ref str, dtfi, ref tempDayOfWeek))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- else
- {
- // "dddd*"
- if (!MatchDayName(ref str, dtfi, ref tempDayOfWeek))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- if (!CheckNewValue(ref parseInfo.dayOfWeek, tempDayOfWeek, ch, ref result))
- {
- return false;
- }
- }
- break;
- case 'g':
- tokenLen = format.GetRepeatCount();
- // Put the era value in result.era.
- if (!MatchEraName(ref str, dtfi, ref result.era))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- break;
- case 'h':
- parseInfo.fUseHour12 = true;
- tokenLen = format.GetRepeatCount();
- if (!ParseDigits(ref str, tokenLen < 2 ? 1 : 2, out tempHour))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- if (!CheckNewValue(ref result.Hour, tempHour, ch, ref result))
- {
- return false;
- }
- break;
- case 'H':
- tokenLen = format.GetRepeatCount();
- if (!ParseDigits(ref str, tokenLen < 2 ? 1 : 2, out tempHour))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- if (!CheckNewValue(ref result.Hour, tempHour, ch, ref result))
- {
- return false;
- }
- break;
- case 'm':
- tokenLen = format.GetRepeatCount();
- if (!ParseDigits(ref str, tokenLen < 2 ? 1 : 2, out tempMinute))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- if (!CheckNewValue(ref result.Minute, tempMinute, ch, ref result))
- {
- return false;
- }
- break;
- case 's':
- tokenLen = format.GetRepeatCount();
- if (!ParseDigits(ref str, tokenLen < 2 ? 1 : 2, out tempSecond))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- if (!CheckNewValue(ref result.Second, tempSecond, ch, ref result))
- {
- return false;
- }
- break;
- case 'f':
- case 'F':
- tokenLen = format.GetRepeatCount();
- if (tokenLen <= DateTimeFormat.MaxSecondsFractionDigits)
- {
- if (!ParseFractionExact(ref str, tokenLen, ref tempFraction))
- {
- if (ch == 'f')
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- if (result.fraction < 0)
- {
- result.fraction = tempFraction;
- }
- else
- {
- if (tempFraction != result.fraction)
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_RepeatDateTimePattern), ch);
- return false;
- }
- }
- }
- else
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- break;
- case 't':
- // AM/PM designator
- tokenLen = format.GetRepeatCount();
- if (tokenLen == 1)
- {
- if (!MatchAbbreviatedTimeMark(ref str, dtfi, ref tempTimeMark))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- else
- {
- if (!MatchTimeMark(ref str, dtfi, ref tempTimeMark))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
-
- if (parseInfo.timeMark == TM.NotSet)
- {
- parseInfo.timeMark = tempTimeMark;
- }
- else
- {
- if (parseInfo.timeMark != tempTimeMark)
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_RepeatDateTimePattern), ch);
- return false;
- }
- }
- break;
- case 'z':
- // timezone offset
- tokenLen = format.GetRepeatCount();
- {
- TimeSpan tempTimeZoneOffset = new TimeSpan(0);
- if (!ParseTimeZoneOffset(ref str, tokenLen, ref tempTimeZoneOffset))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && tempTimeZoneOffset != result.timeZoneOffset)
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_RepeatDateTimePattern), 'z');
- return false;
- }
- result.timeZoneOffset = tempTimeZoneOffset;
- result.flags |= ParseFlags.TimeZoneUsed;
- }
- break;
- case 'Z':
- if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && result.timeZoneOffset != TimeSpan.Zero)
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_RepeatDateTimePattern), 'Z');
- return false;
- }
-
- result.flags |= ParseFlags.TimeZoneUsed;
- result.timeZoneOffset = new TimeSpan(0);
- result.flags |= ParseFlags.TimeZoneUtc;
-
- // The updating of the indexes is to reflect that ParseExact MatchXXX methods assume that
- // they need to increment the index and Parse GetXXX do not. Since we are calling a Parse
- // method from inside ParseExact we need to adjust this. Long term, we should try to
- // eliminate this discrepancy.
- str.Index++;
- if (!GetTimeZoneName(ref str))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- str.Index--;
- break;
- case 'K':
- // This should parse either as a blank, the 'Z' character or a local offset like "-07:00"
- if (str.Match('Z'))
- {
- if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && result.timeZoneOffset != TimeSpan.Zero)
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_RepeatDateTimePattern), 'K');
- return false;
- }
-
- result.flags |= ParseFlags.TimeZoneUsed;
- result.timeZoneOffset = new TimeSpan(0);
- result.flags |= ParseFlags.TimeZoneUtc;
- }
- else if (str.Match('+') || str.Match('-'))
- {
- str.Index--; // Put the character back for the parser
- TimeSpan tempTimeZoneOffset = new TimeSpan(0);
- if (!ParseTimeZoneOffset(ref str, 3, ref tempTimeZoneOffset))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && tempTimeZoneOffset != result.timeZoneOffset)
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_RepeatDateTimePattern), 'K');
- return false;
- }
- result.timeZoneOffset = tempTimeZoneOffset;
- result.flags |= ParseFlags.TimeZoneUsed;
- }
- // Otherwise it is unspecified and we consume no characters
- break;
- case ':':
- // We match the separator in time pattern with the character in the time string if both equal to ':' or the date separator is matching the characters in the date string
- // We have to exclude the case when the time separator is more than one character and starts with ':' something like "::" for instance.
- if (((dtfi.TimeSeparator.Length > 1 && dtfi.TimeSeparator[0] == ':') || !str.Match(':')) &&
- !str.Match(dtfi.TimeSeparator))
- {
- // A time separator is expected.
- result.SetBadDateTimeFailure();
- return false;
- }
- break;
- case '/':
- // We match the separator in date pattern with the character in the date string if both equal to '/' or the date separator is matching the characters in the date string
- // We have to exclude the case when the date separator is more than one character and starts with '/' something like "//" for instance.
- if (((dtfi.DateSeparator.Length > 1 && dtfi.DateSeparator[0] == '/') || !str.Match('/')) &&
- !str.Match(dtfi.DateSeparator))
- {
- // A date separator is expected.
- result.SetBadDateTimeFailure();
- return false;
- }
- break;
- case '\"':
- case '\'':
- StringBuilder enquotedString = StringBuilderCache.Acquire();
- // Use ParseQuoteString so that we can handle escape characters within the quoted string.
- if (!TryParseQuoteString(format.Value, format.Index, enquotedString, out tokenLen))
- {
- result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadQuote), ch);
- StringBuilderCache.Release(enquotedString);
- return false;
- }
- format.Index += tokenLen - 1;
-
- // Some cultures uses space in the quoted string. E.g. Spanish has long date format as:
- // "dddd, dd' de 'MMMM' de 'yyyy". When inner spaces flag is set, we should skip whitespaces if there is space
- // in the quoted string.
- string quotedStr = StringBuilderCache.GetStringAndRelease(enquotedString);
-
- for (int i = 0; i < quotedStr.Length; i++)
- {
- if (quotedStr[i] == ' ' && parseInfo.fAllowInnerWhite)
- {
- str.SkipWhiteSpaces();
- }
- else if (!str.Match(quotedStr[i]))
- {
- // Can not find the matching quoted string.
- result.SetBadDateTimeFailure();
- return false;
- }
- }
-
- // The "r" and "u" formats incorrectly quoted 'GMT' and 'Z', respectively. We cannot
- // correct this mistake for DateTime.ParseExact for compatibility reasons, but we can
- // fix it for DateTimeOffset.ParseExact as DateTimeOffset has not been publically released
- // with this issue.
- if ((result.flags & ParseFlags.CaptureOffset) != 0)
- {
- if (((result.flags & ParseFlags.Rfc1123Pattern) != 0 && quotedStr == GMTName) ||
- ((result.flags & ParseFlags.UtcSortPattern) != 0 && quotedStr == ZuluName))
- {
- result.flags |= ParseFlags.TimeZoneUsed;
- result.timeZoneOffset = TimeSpan.Zero;
- }
- }
-
- break;
- case '%':
- // Skip this so we can get to the next pattern character.
- // Used in case like "%d", "%y"
-
- // Make sure the next character is not a '%' again.
- if (format.Index >= format.Value.Length - 1 || format.Value[format.Index + 1] == '%')
- {
- result.SetBadFormatSpecifierFailure(format.Value);
- return false;
- }
- break;
- case '\\':
- // Escape character. For example, "\d".
- // Get the next character in format, and see if we can
- // find a match in str.
- if (format.GetNext())
- {
- if (!str.Match(format.GetChar()))
- {
- // Can not find a match for the escaped character.
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- else
- {
- result.SetBadFormatSpecifierFailure(format.Value);
- return false;
- }
- break;
- case '.':
- if (!str.Match(ch))
- {
- if (format.GetNext())
- {
- // If we encounter the pattern ".F", and the dot is not present, it is an optional
- // second fraction and we can skip this format.
- if (format.Match('F'))
- {
- format.GetRepeatCount();
- break;
- }
- }
- result.SetBadDateTimeFailure();
- return false;
- }
- break;
- default:
- if (ch == ' ')
- {
- if (parseInfo.fAllowInnerWhite)
- {
- // Skip whitespaces if AllowInnerWhite.
- // Do nothing here.
- }
- else
- {
- if (!str.Match(ch))
- {
- // If the space does not match, and trailing space is allowed, we do
- // one more step to see if the next format character can lead to
- // successful parsing.
- // This is used to deal with special case that a empty string can match
- // a specific pattern.
- // The example here is af-ZA, which has a time format like "hh:mm:ss tt". However,
- // its AM symbol is "" (empty string). If fAllowTrailingWhite is used, and time is in
- // the AM, we will trim the whitespaces at the end, which will lead to a failure
- // when we are trying to match the space before "tt".
- if (parseInfo.fAllowTrailingWhite)
- {
- if (format.GetNext())
- {
- if (ParseByFormat(ref str, ref format, ref parseInfo, dtfi, ref result))
- {
- return true;
- }
- }
- }
- result.SetBadDateTimeFailure();
- return false;
- }
- // Found a macth.
- }
- }
- else
- {
- if (format.MatchSpecifiedWord(GMTName))
- {
- format.Index += (GMTName.Length - 1);
- // Found GMT string in format. This means the DateTime string
- // is in GMT timezone.
- result.flags |= ParseFlags.TimeZoneUsed;
- result.timeZoneOffset = TimeSpan.Zero;
- if (!str.Match(GMTName))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- else if (!str.Match(ch))
- {
- // ch is expected.
- result.SetBadDateTimeFailure();
- return false;
- }
- }
- break;
- } // switch
- return true;
- }
-
- //
- // The pos should point to a quote character. This method will
- // get the string enclosed by the quote character.
- //
- internal static bool TryParseQuoteString(ReadOnlySpan<char> format, int pos, StringBuilder result, out int returnValue)
- {
- //
- // NOTE : pos will be the index of the quote character in the 'format' string.
- //
- returnValue = 0;
- int formatLen = format.Length;
- int beginPos = pos;
- char quoteChar = format[pos++]; // Get the character used to quote the following string.
-
- bool foundQuote = false;
- while (pos < formatLen)
- {
- char ch = format[pos++];
- if (ch == quoteChar)
- {
- foundQuote = true;
- break;
- }
- else if (ch == '\\')
- {
- // The following are used to support escaped character.
- // Escaped character is also supported in the quoted string.
- // Therefore, someone can use a format like "'minute:' mm\"" to display:
- // minute: 45"
- // because the second double quote is escaped.
- if (pos < formatLen)
- {
- result.Append(format[pos++]);
- }
- else
- {
- //
- // This means that '\' is at the end of the formatting string.
- //
- return false;
- }
- }
- else
- {
- result.Append(ch);
- }
- }
-
- if (!foundQuote)
- {
- // Here we can't find the matching quote.
- return false;
- }
-
- //
- // Return the character count including the begin/end quote characters and enclosed string.
- //
- returnValue = (pos - beginPos);
- return true;
- }
-
- /*=================================DoStrictParse==================================
- **Action: Do DateTime parsing using the format in formatParam.
- **Returns: The parsed DateTime.
- **Arguments:
- **Exceptions:
- **
- **Notes:
- ** When the following general formats are used, InvariantInfo is used in dtfi:
- ** 'r', 'R', 's'.
- ** When the following general formats are used, the time is assumed to be in Universal time.
- **
- **Limitations:
- ** Only GregorianCalendar is supported for now.
- ** Only support GMT timezone.
- ==============================================================================*/
-
- private static bool DoStrictParse(
- ReadOnlySpan<char> s,
- ReadOnlySpan<char> formatParam,
- DateTimeStyles styles,
- DateTimeFormatInfo dtfi,
- ref DateTimeResult result)
- {
- ParsingInfo parseInfo = default;
- parseInfo.Init();
-
- parseInfo.calendar = dtfi.Calendar;
- parseInfo.fAllowInnerWhite = ((styles & DateTimeStyles.AllowInnerWhite) != 0);
- parseInfo.fAllowTrailingWhite = ((styles & DateTimeStyles.AllowTrailingWhite) != 0);
-
- if (formatParam.Length == 1)
- {
- char formatParamChar = formatParam[0];
-
- // Fast-paths for common and important formats/configurations.
- if (styles == DateTimeStyles.None)
- {
- switch (formatParamChar)
- {
- case 'R':
- case 'r':
- ConfigureFormatR(ref dtfi, ref parseInfo, ref result);
- return ParseFormatR(s, ref parseInfo, ref result);
-
- case 'O':
- case 'o':
- ConfigureFormatOS(ref dtfi, ref parseInfo);
- return ParseFormatO(s, ref result);
- }
- }
-
- if (((result.flags & ParseFlags.CaptureOffset) != 0) && formatParamChar == 'U')
- {
- // The 'U' format is not allowed for DateTimeOffset
- result.SetBadFormatSpecifierFailure(formatParam);
- return false;
- }
-
- formatParam = ExpandPredefinedFormat(formatParam, ref dtfi, ref parseInfo, ref result);
- }
-
- bool bTimeOnly = false;
- result.calendar = parseInfo.calendar;
-
- if (parseInfo.calendar.ID == CalendarId.HEBREW)
- {
- parseInfo.parseNumberDelegate = m_hebrewNumberParser;
- parseInfo.fCustomNumberParser = true;
- }
-
- // Reset these values to negative one so that we could throw exception
- // if we have parsed every item twice.
- result.Hour = result.Minute = result.Second = -1;
-
- __DTString format = new __DTString(formatParam, dtfi, false);
- __DTString str = new __DTString(s, dtfi, false);
-
- if (parseInfo.fAllowTrailingWhite)
- {
- // Trim trailing spaces if AllowTrailingWhite.
- format.TrimTail();
- format.RemoveTrailingInQuoteSpaces();
- str.TrimTail();
- }
-
- if ((styles & DateTimeStyles.AllowLeadingWhite) != 0)
- {
- format.SkipWhiteSpaces();
- format.RemoveLeadingInQuoteSpaces();
- str.SkipWhiteSpaces();
- }
-
- //
- // Scan every character in format and match the pattern in str.
- //
- while (format.GetNext())
- {
- // We trim inner spaces here, so that we will not eat trailing spaces when
- // AllowTrailingWhite is not used.
- if (parseInfo.fAllowInnerWhite)
- {
- str.SkipWhiteSpaces();
- }
- if (!ParseByFormat(ref str, ref format, ref parseInfo, dtfi, ref result))
- {
- return false;
- }
- }
-
- if (str.Index < str.Value.Length - 1)
- {
- // There are still remaining character in str.
- result.SetBadDateTimeFailure();
- return false;
- }
-
- if (parseInfo.fUseTwoDigitYear && ((dtfi.FormatFlags & DateTimeFormatFlags.UseHebrewRule) == 0))
- {
- // A two digit year value is expected. Check if the parsed year value is valid.
- if (result.Year >= 100)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- try
- {
- result.Year = parseInfo.calendar.ToFourDigitYear(result.Year);
- }
- catch (ArgumentOutOfRangeException)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
-
- if (parseInfo.fUseHour12)
- {
- if (parseInfo.timeMark == TM.NotSet)
- {
- // hh is used, but no AM/PM designator is specified.
- // Assume the time is AM.
- // Don't throw exceptions in here becasue it is very confusing for the caller.
- // I always got confused myself when I use "hh:mm:ss" to parse a time string,
- // and ParseExact() throws on me (because I didn't use the 24-hour clock 'HH').
- parseInfo.timeMark = TM.AM;
- }
- if (result.Hour > 12)
- {
- // AM/PM is used, but the value for HH is too big.
- result.SetBadDateTimeFailure();
- return false;
- }
- if (parseInfo.timeMark == TM.AM)
- {
- if (result.Hour == 12)
- {
- result.Hour = 0;
- }
- }
- else
- {
- result.Hour = (result.Hour == 12) ? 12 : result.Hour + 12;
- }
- }
- else
- {
- // Military (24-hour time) mode
- //
- // AM cannot be set with a 24-hour time like 17:15.
- // PM cannot be set with a 24-hour time like 03:15.
- if ((parseInfo.timeMark == TM.AM && result.Hour >= 12)
- || (parseInfo.timeMark == TM.PM && result.Hour < 12))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
-
- // Check if the parsed string only contains hour/minute/second values.
- bTimeOnly = (result.Year == -1 && result.Month == -1 && result.Day == -1);
- if (!CheckDefaultDateTime(ref result, ref parseInfo.calendar, styles))
- {
- return false;
- }
-
- if (!bTimeOnly && dtfi.HasYearMonthAdjustment)
- {
- if (!dtfi.YearMonthAdjustment(ref result.Year, ref result.Month, (result.flags & ParseFlags.ParsedMonthName) != 0))
- {
- result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, nameof(SR.Format_BadDateTimeCalendar));
- return false;
- }
- }
- if (!parseInfo.calendar.TryToDateTime(result.Year, result.Month, result.Day,
- result.Hour, result.Minute, result.Second, 0, result.era, out result.parsedDate))
- {
- result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, nameof(SR.Format_BadDateTimeCalendar));
- return false;
- }
- if (result.fraction > 0)
- {
- if (!result.parsedDate.TryAddTicks((long)Math.Round(result.fraction * Calendar.TicksPerSecond), out result.parsedDate))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- }
-
- //
- // We have to check day of week before we adjust to the time zone.
- // It is because the value of day of week may change after adjusting
- // to the time zone.
- //
- if (parseInfo.dayOfWeek != -1)
- {
- //
- // Check if day of week is correct.
- //
- if (parseInfo.dayOfWeek != (int)parseInfo.calendar.GetDayOfWeek(result.parsedDate))
- {
- result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, nameof(SR.Format_BadDayOfWeek));
- return false;
- }
- }
-
- return DetermineTimeZoneAdjustments(ref result, styles, bTimeOnly);
- }
-
- private static bool ParseFormatR(ReadOnlySpan<char> source, ref ParsingInfo parseInfo, ref DateTimeResult result)
- {
- // Example:
- // Tue, 03 Jan 2017 08:08:05 GMT
-
- // The format is exactly 29 characters.
- if ((uint)source.Length != 29)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- // Parse the three-letter day of week. Any casing is valid.
- DayOfWeek dayOfWeek;
- {
- uint dow0 = source[0], dow1 = source[1], dow2 = source[2], comma = source[3];
-
- if ((dow0 | dow1 | dow2 | comma) > 0x7F)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- uint dowString = (dow0 << 24) | (dow1 << 16) | (dow2 << 8) | comma | 0x20202000;
- switch (dowString)
- {
- case 0x73756E2c /* 'sun,' */: dayOfWeek = DayOfWeek.Sunday; break;
- case 0x6d6f6e2c /* 'mon,' */: dayOfWeek = DayOfWeek.Monday; break;
- case 0x7475652c /* 'tue,' */: dayOfWeek = DayOfWeek.Tuesday; break;
- case 0x7765642c /* 'wed,' */: dayOfWeek = DayOfWeek.Wednesday; break;
- case 0x7468752c /* 'thu,' */: dayOfWeek = DayOfWeek.Thursday; break;
- case 0x6672692c /* 'fri,' */: dayOfWeek = DayOfWeek.Friday; break;
- case 0x7361742c /* 'sat,' */: dayOfWeek = DayOfWeek.Saturday; break;
- default:
- result.SetBadDateTimeFailure();
- return false;
- }
- }
-
- if (source[4] != ' ')
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- // Parse the two digit day.
- int day;
- {
- uint digit1 = (uint)(source[5] - '0'), digit2 = (uint)(source[6] - '0');
-
- if (digit1 > 9 || digit2 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- day = (int)(digit1 * 10 + digit2);
- }
-
- if (source[7] != ' ')
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- // Parse the three letter month (followed by a space). Any casing is valid.
- int month;
- {
- uint m0 = source[8], m1 = source[9], m2 = source[10], space = source[11];
-
- if ((m0 | m1 | m2 | space) > 0x7F)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- switch ((m0 << 24) | (m1 << 16) | (m2 << 8) | space | 0x20202000)
- {
- case 0x6a616e20: /* 'jan ' */ month = 1; break;
- case 0x66656220: /* 'feb ' */ month = 2; break;
- case 0x6d617220: /* 'mar ' */ month = 3; break;
- case 0x61707220: /* 'apr ' */ month = 4; break;
- case 0x6d617920: /* 'may ' */ month = 5; break;
- case 0x6a756e20: /* 'jun ' */ month = 6; break;
- case 0x6a756c20: /* 'jul ' */ month = 7; break;
- case 0x61756720: /* 'aug ' */ month = 8; break;
- case 0x73657020: /* 'sep ' */ month = 9; break;
- case 0x6f637420: /* 'oct ' */ month = 10; break;
- case 0x6e6f7620: /* 'nov ' */ month = 11; break;
- case 0x64656320: /* 'dec ' */ month = 12; break;
- default:
- result.SetBadDateTimeFailure();
- return false;
- }
- }
-
- // Parse the four-digit year.
- int year;
- {
- uint y1 = (uint)(source[12] - '0'), y2 = (uint)(source[13] - '0'), y3 = (uint)(source[14] - '0'), y4 = (uint)(source[15] - '0');
-
- if (y1 > 9 || y2 > 9 || y3 > 9 || y4 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- year = (int)(y1 * 1000 + y2 * 100 + y3 * 10 + y4);
- }
-
- if (source[16] != ' ')
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- // Parse the two digit hour.
- int hour;
- {
- uint h1 = (uint)(source[17] - '0'), h2 = (uint)(source[18] - '0');
-
- if (h1 > 9 || h2 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- hour = (int)(h1 * 10 + h2);
- }
-
- if (source[19] != ':')
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- // Parse the two-digit minute.
- int minute;
- {
- uint m1 = (uint)(source[20] - '0');
- uint m2 = (uint)(source[21] - '0');
-
- if (m1 > 9 || m2 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- minute = (int)(m1 * 10 + m2);
- }
-
- if (source[22] != ':')
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- // Parse the two-digit second.
- int second;
- {
- uint s1 = (uint)(source[23] - '0'), s2 = (uint)(source[24] - '0');
-
- if (s1 > 9 || s2 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- second = (int)(s1 * 10 + s2);
- }
-
- // Parse " GMT". It must be upper case.
- if (source[25] != ' ' || source[26] != 'G' || source[27] != 'M' || source[28] != 'T')
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- // Validate that the parsed date is valid according to the calendar.
- if (!parseInfo.calendar.TryToDateTime(year, month, day, hour, minute, second, 0, 0, out result.parsedDate))
- {
- result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, nameof(SR.Format_BadDateTimeCalendar));
- return false;
- }
-
- // And validate that the parsed day of week matches what the calendar said it should be.
- if (dayOfWeek != result.parsedDate.DayOfWeek)
- {
- result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, nameof(SR.Format_BadDayOfWeek));
- return false;
- }
-
- return true;
- }
-
- private static bool ParseFormatO(ReadOnlySpan<char> source, ref DateTimeResult result)
- {
- // Examples:
- // 2017-06-12T05:30:45.7680000 (interpreted as local time wrt to current time zone)
- // 2017-06-12T05:30:45.7680000Z (Z is short for "+00:00" but also distinguishes DateTimeKind.Utc from DateTimeKind.Local)
- // 2017-06-12T05:30:45.7680000-7:00 (special-case of one-digit offset hour)
- // 2017-06-12T05:30:45.7680000-07:00
-
- if ((uint)source.Length < 27 ||
- source[4] != '-' ||
- source[7] != '-' ||
- source[10] != 'T' ||
- source[13] != ':' ||
- source[16] != ':' ||
- source[19] != '.')
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- int year;
- {
- uint y1 = (uint)(source[0] - '0'), y2 = (uint)(source[1] - '0'), y3 = (uint)(source[2] - '0'), y4 = (uint)(source[3] - '0');
-
- if (y1 > 9 || y2 > 9 || y3 > 9 || y4 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- year = (int)(y1 * 1000 + y2 * 100 + y3 * 10 + y4);
- }
-
- int month;
- {
- uint m1 = (uint)(source[5] - '0'), m2 = (uint)(source[6] - '0');
-
- if (m1 > 9 || m2 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- month = (int)(m1 * 10 + m2);
- }
-
- int day;
- {
- uint d1 = (uint)(source[8] - '0'), d2 = (uint)(source[9] - '0');
-
- if (d1 > 9 || d2 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- day = (int)(d1 * 10 + d2);
- }
-
- int hour;
- {
- uint h1 = (uint)(source[11] - '0'), h2 = (uint)(source[12] - '0');
-
- if (h1 > 9 || h2 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- hour = (int)(h1 * 10 + h2);
- }
-
- int minute;
- {
- uint m1 = (uint)(source[14] - '0'), m2 = (uint)(source[15] - '0');
-
- if (m1 > 9 || m2 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- minute = (int)(m1 * 10 + m2);
- }
-
- int second;
- {
- uint s1 = (uint)(source[17] - '0'), s2 = (uint)(source[18] - '0');
-
- if (s1 > 9 || s2 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- second = (int)(s1 * 10 + s2);
- }
-
- double fraction;
- {
- uint f1 = (uint)(source[20] - '0');
- uint f2 = (uint)(source[21] - '0');
- uint f3 = (uint)(source[22] - '0');
- uint f4 = (uint)(source[23] - '0');
- uint f5 = (uint)(source[24] - '0');
- uint f6 = (uint)(source[25] - '0');
- uint f7 = (uint)(source[26] - '0');
-
- if (f1 > 9 || f2 > 9 || f3 > 9 || f4 > 9 || f5 > 9 || f6 > 9 || f7 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- fraction = (f1 * 1000000 + f2 * 100000 + f3 * 10000 + f4 * 1000 + f5 * 100 + f6 * 10 + f7) / 10000000.0;
- }
-
- if (!DateTime.TryCreate(year, month, day, hour, minute, second, 0, out DateTime dateTime))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- if (!dateTime.TryAddTicks((long)Math.Round(fraction * Calendar.TicksPerSecond), out result.parsedDate))
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- if ((uint)source.Length > 27)
- {
- char offsetChar = source[27];
- switch (offsetChar)
- {
- case 'Z':
- if (source.Length != 28)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
- result.flags |= ParseFlags.TimeZoneUsed | ParseFlags.TimeZoneUtc;
- break;
-
- case '+':
- case '-':
- int offsetHours, colonIndex;
-
- if ((uint)source.Length == 33)
- {
- uint oh1 = (uint)(source[28] - '0'), oh2 = (uint)(source[29] - '0');
-
- if (oh1 > 9 || oh2 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- offsetHours = (int)(oh1 * 10 + oh2);
- colonIndex = 30;
- }
- else if ((uint)source.Length == 32) // special-case allowed for compat: only one offset hour digit
- {
- offsetHours = source[28] - '0';
-
- if ((uint)offsetHours > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- colonIndex = 29;
- }
- else
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- if (source[colonIndex] != ':')
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- int offsetMinutes;
- {
- uint om1 = (uint)(source[colonIndex + 1] - '0'), om2 = (uint)(source[colonIndex + 2] - '0');
-
- if (om1 > 9 || om2 > 9)
- {
- result.SetBadDateTimeFailure();
- return false;
- }
-
- offsetMinutes = (int)(om1 * 10 + om2);
- }
-
- result.flags |= ParseFlags.TimeZoneUsed;
- result.timeZoneOffset = new TimeSpan(offsetHours, offsetMinutes, 0);
- if (offsetChar == '-')
- {
- result.timeZoneOffset = result.timeZoneOffset.Negate();
- }
- break;
-
- default:
- result.SetBadDateTimeFailure();
- return false;
- }
- }
-
- return DetermineTimeZoneAdjustments(ref result, DateTimeStyles.None, bTimeOnly: false);
- }
-
- private static Exception GetDateTimeParseException(ref DateTimeResult result)
- {
- switch (result.failure)
- {
- case ParseFailureKind.ArgumentNull:
- return new ArgumentNullException(result.failureArgumentName, SR.GetResourceString(result.failureMessageID));
- case ParseFailureKind.Format:
- return new FormatException(SR.GetResourceString(result.failureMessageID));
- case ParseFailureKind.FormatWithParameter:
- return new FormatException(SR.Format(SR.GetResourceString(result.failureMessageID)!, result.failureMessageFormatArgument));
- case ParseFailureKind.FormatBadDateTimeCalendar:
- return new FormatException(SR.Format(SR.GetResourceString(result.failureMessageID)!, new string(result.originalDateTimeString), result.calendar));
- case ParseFailureKind.FormatWithOriginalDateTime:
- return new FormatException(SR.Format(SR.GetResourceString(result.failureMessageID)!, new string(result.originalDateTimeString)));
- case ParseFailureKind.FormatWithFormatSpecifier:
- return new FormatException(SR.Format(SR.GetResourceString(result.failureMessageID)!, new string(result.failedFormatSpecifier)));
- case ParseFailureKind.FormatWithOriginalDateTimeAndParameter:
- return new FormatException(SR.Format(SR.GetResourceString(result.failureMessageID)!, new string(result.originalDateTimeString), result.failureMessageFormatArgument));
- default:
- Debug.Fail("Unknown DateTimeParseFailure: " + result.failure.ToString());
- return null!;
- }
- }
-
- [Conditional("_LOGGING")]
- private static void LexTraceExit(string message, DS dps)
- {
-#if _LOGGING
- if (!_tracingEnabled)
- return;
- Trace($"Lex return {message}, DS.{dps}");
-#endif // _LOGGING
- }
- [Conditional("_LOGGING")]
- private static void PTSTraceExit(DS dps, bool passed)
- {
-#if _LOGGING
- if (!_tracingEnabled)
- return;
- Trace($"ProcessTerminalState {(passed ? "passed" : "failed")} @ DS.{dps}");
-#endif // _LOGGING
- }
- [Conditional("_LOGGING")]
- private static void TPTraceExit(string message, DS dps)
- {
-#if _LOGGING
- if (!_tracingEnabled)
- return;
- Trace($"TryParse return {message}, DS.{dps}");
-#endif // _LOGGING
- }
- [Conditional("_LOGGING")]
- private static void DTFITrace(DateTimeFormatInfo dtfi)
- {
-#if _LOGGING
- if (!_tracingEnabled)
- return;
-
- Trace("DateTimeFormatInfo Properties");
- Trace($" NativeCalendarName {Hex(dtfi.NativeCalendarName)}");
- Trace($" AMDesignator {Hex(dtfi.AMDesignator)}");
- Trace($" PMDesignator {Hex(dtfi.PMDesignator)}");
- Trace($" TimeSeparator {Hex(dtfi.TimeSeparator)}");
- Trace($" AbbrvDayNames {Hex(dtfi.AbbreviatedDayNames)}");
- Trace($" ShortestDayNames {Hex(dtfi.ShortestDayNames)}");
- Trace($" DayNames {Hex(dtfi.DayNames)}");
- Trace($" AbbrvMonthNames {Hex(dtfi.AbbreviatedMonthNames)}");
- Trace($" MonthNames {Hex(dtfi.MonthNames)}");
- Trace($" AbbrvMonthGenNames {Hex(dtfi.AbbreviatedMonthGenitiveNames)}");
- Trace($" MonthGenNames {Hex(dtfi.MonthGenitiveNames)}");
-#endif // _LOGGING
- }
-#if _LOGGING
- // return a string in the form: "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
- private static string Hex(string[] strs)
- {
- if (strs == null || strs.Length == 0)
- return string.Empty;
- if (strs.Length == 1)
- return Hex(strs[0]);
-
- int curLineLength = 0;
- const int MaxLineLength = 55;
- const int NewLinePadding = 20;
-
- // invariant: strs.Length >= 2
- StringBuilder buffer = new StringBuilder();
- buffer.Append(Hex(strs[0]));
- curLineLength = buffer.Length;
- string s;
-
- for (int i = 1; i < strs.Length - 1; i++)
- {
- s = Hex(strs[i]);
-
- if (s.Length > MaxLineLength || (curLineLength + s.Length + 2) > MaxLineLength)
- {
- buffer.Append(',');
- buffer.Append(Environment.NewLineConst);
- buffer.Append(' ', NewLinePadding);
- curLineLength = 0;
- }
- else
- {
- buffer.Append(", ");
- curLineLength += 2;
- }
- buffer.Append(s);
- curLineLength += s.Length;
- }
-
- buffer.Append(',');
- s = Hex(strs[strs.Length - 1]);
- if (s.Length > MaxLineLength || (curLineLength + s.Length + 6) > MaxLineLength)
- {
- buffer.Append(Environment.NewLineConst);
- buffer.Append(' ', NewLinePadding);
- }
- else
- {
- buffer.Append(' ');
- }
- buffer.Append(s);
- return buffer.ToString();
- }
- // return a string in the form: "Sun"
- private static string Hex(string str) => Hex((ReadOnlySpan<char>)str);
- private static string Hex(ReadOnlySpan<char> str)
- {
- StringBuilder buffer = new StringBuilder();
- buffer.Append("\"");
- for (int i = 0; i < str.Length; i++)
- {
- if (str[i] <= '\x007f')
- buffer.Append(str[i]);
- else
- buffer.Append("\\u").Append(((int)str[i]).ToString("x4", CultureInfo.InvariantCulture));
- }
- buffer.Append("\"");
- return buffer.ToString();
- }
- // return an unicode escaped string form of char c
- private static string Hex(char c)
- {
- if (c <= '\x007f')
- return c.ToString(CultureInfo.InvariantCulture);
- else
- return "\\u" + ((int)c).ToString("x4", CultureInfo.InvariantCulture);
- }
-
- private static void Trace(string s)
- {
- // Internal.Console.WriteLine(s);
- }
-
- // for testing; do not make this readonly
- private static bool _tracingEnabled = false;
-#endif // _LOGGING
- }
-
- //
- // This is a string parsing helper which wraps a String object.
- // It has a Index property which tracks
- // the current parsing pointer of the string.
- //
- internal ref struct __DTString
- {
- //
- // Value property: stores the real string to be parsed.
- //
- internal ReadOnlySpan<char> Value;
-
- //
- // Index property: points to the character that we are currently parsing.
- //
- internal int Index;
-
- // The length of Value string.
- internal int Length => Value.Length;
-
- // The current character to be looked at.
- internal char m_current;
-
- private readonly CompareInfo m_info;
- // Flag to indicate if we encouter an digit, we should check for token or not.
- // In some cultures, such as mn-MN, it uses "\x0031\x00a0\x0434\x04af\x0433\x044d\x044d\x0440\x00a0\x0441\x0430\x0440" in month names.
- private readonly bool m_checkDigitToken;
-
- internal __DTString(ReadOnlySpan<char> str, DateTimeFormatInfo dtfi, bool checkDigitToken) : this(str, dtfi)
- {
- m_checkDigitToken = checkDigitToken;
- }
-
- internal __DTString(ReadOnlySpan<char> str, DateTimeFormatInfo dtfi)
- {
- Debug.Assert(dtfi != null, "Expected non-null DateTimeFormatInfo");
-
- Index = -1;
- Value = str;
-
- m_current = '\0';
- m_info = dtfi.CompareInfo;
- m_checkDigitToken = ((dtfi.FormatFlags & DateTimeFormatFlags.UseDigitPrefixInTokens) != 0);
- }
-
- internal CompareInfo CompareInfo => m_info;
-
- //
- // Advance the Index.
- // Return true if Index is NOT at the end of the string.
- //
- // Typical usage:
- // while (str.GetNext())
- // {
- // char ch = str.GetChar()
- // }
- internal bool GetNext()
- {
- Index++;
- if (Index < Length)
- {
- m_current = Value[Index];
- return true;
- }
- return false;
- }
-
- internal bool AtEnd()
- {
- return Index < Length ? false : true;
- }
-
- internal bool Advance(int count)
- {
- Debug.Assert(Index + count <= Length, "__DTString::Advance: Index + count <= len");
- Index += count;
- if (Index < Length)
- {
- m_current = Value[Index];
- return true;
- }
- return false;
- }
-
- // Used by DateTime.Parse() to get the next token.
- internal void GetRegularToken(out TokenType tokenType, out int tokenValue, DateTimeFormatInfo dtfi)
- {
- tokenValue = 0;
- if (Index >= Length)
- {
- tokenType = TokenType.EndOfString;
- return;
- }
-
- Start:
- if (DateTimeParse.IsDigit(m_current))
- {
- // This is a digit.
- tokenValue = m_current - '0';
- int value;
- int start = Index;
-
- //
- // Collect other digits.
- //
- while (++Index < Length)
- {
- m_current = Value[Index];
- value = m_current - '0';
- if (value >= 0 && value <= 9)
- {
- tokenValue = tokenValue * 10 + value;
- }
- else
- {
- break;
- }
- }
- if (Index - start > DateTimeParse.MaxDateTimeNumberDigits)
- {
- tokenType = TokenType.NumberToken;
- tokenValue = -1;
- }
- else if (Index - start < 3)
- {
- tokenType = TokenType.NumberToken;
- }
- else
- {
- // If there are more than 3 digits, assume that it's a year value.
- tokenType = TokenType.YearNumberToken;
- }
- if (m_checkDigitToken)
- {
- int save = Index;
- char saveCh = m_current;
- // Re-scan using the staring Index to see if this is a token.
- Index = start; // To include the first digit.
- m_current = Value[Index];
- TokenType tempType;
- int tempValue;
- // This DTFI has tokens starting with digits.
- // E.g. mn-MN has month name like "\x0031\x00a0\x0434\x04af\x0433\x044d\x044d\x0440\x00a0\x0441\x0430\x0440"
- if (dtfi.Tokenize(TokenType.RegularTokenMask, out tempType, out tempValue, ref this))
- {
- tokenType = tempType;
- tokenValue = tempValue;
- // This is a token, so the Index has been advanced propertly in DTFI.Tokenizer().
- }
- else
- {
- // Use the number token value.
- // Restore the index.
- Index = save;
- m_current = saveCh;
- }
- }
- }
- else if (char.IsWhiteSpace(m_current))
- {
- // Just skip to the next character.
- while (++Index < Length)
- {
- m_current = Value[Index];
- if (!char.IsWhiteSpace(m_current))
- {
- goto Start;
- }
- }
- // We have reached the end of string.
- tokenType = TokenType.EndOfString;
- }
- else
- {
- dtfi.Tokenize(TokenType.RegularTokenMask, out tokenType, out tokenValue, ref this);
- }
- }
-
- internal TokenType GetSeparatorToken(DateTimeFormatInfo dtfi, out int indexBeforeSeparator, out char charBeforeSeparator)
- {
- indexBeforeSeparator = Index;
- charBeforeSeparator = m_current;
- TokenType tokenType;
- if (!SkipWhiteSpaceCurrent())
- {
- // Reach the end of the string.
- return TokenType.SEP_End;
- }
- if (!DateTimeParse.IsDigit(m_current))
- {
- // Not a digit. Tokenize it.
- bool found = dtfi.Tokenize(TokenType.SeparatorTokenMask, out tokenType, out _, ref this);
- if (!found)
- {
- tokenType = TokenType.SEP_Space;
- }
- }
- else
- {
- // Do nothing here. If we see a number, it will not be a separator. There is no need wasting time trying to find the
- // separator token.
- tokenType = TokenType.SEP_Space;
- }
- return tokenType;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal bool MatchSpecifiedWord(string target) =>
- Index + target.Length <= Length &&
- m_info.Compare(Value.Slice(Index, target.Length), target, CompareOptions.IgnoreCase) == 0;
-
- private static readonly char[] WhiteSpaceChecks = new char[] { ' ', '\u00A0' };
-
- internal bool MatchSpecifiedWords(string target, bool checkWordBoundary, ref int matchLength)
- {
- int valueRemaining = Value.Length - Index;
- matchLength = target.Length;
-
- if (matchLength > valueRemaining || m_info.Compare(Value.Slice(Index, matchLength), target, CompareOptions.IgnoreCase) != 0)
- {
- // Check word by word
- int targetPosition = 0; // Where we are in the target string
- int thisPosition = Index; // Where we are in this string
- int wsIndex = target.IndexOfAny(WhiteSpaceChecks, targetPosition);
- if (wsIndex == -1)
- {
- return false;
- }
- do
- {
- int segmentLength = wsIndex - targetPosition;
- if (thisPosition >= Value.Length - segmentLength)
- { // Subtraction to prevent overflow.
- return false;
- }
- if (segmentLength == 0)
- {
- // If segmentLength == 0, it means that we have leading space in the target string.
- // In that case, skip the leading spaces in the target and this string.
- matchLength--;
- }
- else
- {
- // Make sure we also have whitespace in the input string
- if (!char.IsWhiteSpace(Value[thisPosition + segmentLength]))
- {
- return false;
- }
- if (m_info.CompareOptionIgnoreCase(Value.Slice(thisPosition, segmentLength), target.AsSpan(targetPosition, segmentLength)) != 0)
- {
- return false;
- }
- // Advance the input string
- thisPosition = thisPosition + segmentLength + 1;
- }
- // Advance our target string
- targetPosition = wsIndex + 1;
-
- // Skip past multiple whitespace
- while (thisPosition < Value.Length && char.IsWhiteSpace(Value[thisPosition]))
- {
- thisPosition++;
- matchLength++;
- }
- } while ((wsIndex = target.IndexOfAny(WhiteSpaceChecks, targetPosition)) >= 0);
- // now check the last segment;
- if (targetPosition < target.Length)
- {
- int segmentLength = target.Length - targetPosition;
- if (thisPosition > Value.Length - segmentLength)
- {
- return false;
- }
- if (m_info.CompareOptionIgnoreCase(Value.Slice(thisPosition, segmentLength), target.AsSpan(targetPosition, segmentLength)) != 0)
- {
- return false;
- }
- }
- }
-
- if (checkWordBoundary)
- {
- int nextCharIndex = Index + matchLength;
- if (nextCharIndex < Value.Length)
- {
- if (char.IsLetter(Value[nextCharIndex]))
- {
- return false;
- }
- }
- }
- return true;
- }
-
- //
- // Check to see if the string starting from Index is a prefix of
- // str.
- // If a match is found, true value is returned and Index is updated to the next character to be parsed.
- // Otherwise, Index is unchanged.
- //
- internal bool Match(string str)
- {
- if (++Index >= Length)
- {
- return false;
- }
-
- if (str.Length > (Value.Length - Index))
- {
- return false;
- }
-
- if (m_info.Compare(Value.Slice(Index, str.Length), str, CompareOptions.Ordinal) == 0)
- {
- // Update the Index to the end of the matching string.
- // So the following GetNext()/Match() opeartion will get
- // the next character to be parsed.
- Index += (str.Length - 1);
- return true;
- }
- return false;
- }
-
- internal bool Match(char ch)
- {
- if (++Index >= Length)
- {
- return false;
- }
- if (Value[Index] == ch)
- {
- m_current = ch;
- return true;
- }
- Index--;
- return false;
- }
-
- //
- // Actions: From the current position, try matching the longest word in the specified string array.
- // E.g. words[] = {"AB", "ABC", "ABCD"}, if the current position points to a substring like "ABC DEF",
- // MatchLongestWords(words, ref MaxMatchStrLen) will return 1 (the index), and maxMatchLen will be 3.
- // Returns:
- // The index that contains the longest word to match
- // Arguments:
- // words The string array that contains words to search.
- // maxMatchStrLen [in/out] the initialized maximum length. This parameter can be used to
- // find the longest match in two string arrays.
- //
- internal int MatchLongestWords(string[] words, ref int maxMatchStrLen)
- {
- int result = -1;
- for (int i = 0; i < words.Length; i++)
- {
- string word = words[i];
- int matchLength = word.Length;
- if (MatchSpecifiedWords(word, false, ref matchLength))
- {
- if (matchLength > maxMatchStrLen)
- {
- maxMatchStrLen = matchLength;
- result = i;
- }
- }
- }
-
- return result;
- }
-
- //
- // Get the number of repeat character after the current character.
- // For a string "hh:mm:ss" at Index of 3. GetRepeatCount() = 2, and Index
- // will point to the second ':'.
- //
- internal int GetRepeatCount()
- {
- char repeatChar = Value[Index];
- int pos = Index + 1;
- while ((pos < Length) && (Value[pos] == repeatChar))
- {
- pos++;
- }
- int repeatCount = (pos - Index);
- // Update the Index to the end of the repeated characters.
- // So the following GetNext() opeartion will get
- // the next character to be parsed.
- Index = pos - 1;
- return repeatCount;
- }
-
- // Return false when end of string is encountered or a non-digit character is found.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal bool GetNextDigit() =>
- ++Index < Length &&
- DateTimeParse.IsDigit(Value[Index]);
-
- //
- // Get the current character.
- //
- internal char GetChar()
- {
- Debug.Assert(Index >= 0 && Index < Length, "Index >= 0 && Index < len");
- return Value[Index];
- }
-
- //
- // Convert the current character to a digit, and return it.
- //
- internal int GetDigit()
- {
- Debug.Assert(Index >= 0 && Index < Length, "Index >= 0 && Index < len");
- Debug.Assert(DateTimeParse.IsDigit(Value[Index]), "IsDigit(Value[Index])");
- return Value[Index] - '0';
- }
-
- //
- // Eat White Space ahead of the current position
- //
- // Return false if end of string is encountered.
- //
- internal void SkipWhiteSpaces()
- {
- // Look ahead to see if the next character
- // is a whitespace.
- while (Index + 1 < Length)
- {
- char ch = Value[Index + 1];
- if (!char.IsWhiteSpace(ch))
- {
- return;
- }
- Index++;
- }
- return;
- }
-
- //
- // Skip white spaces from the current position
- //
- // Return false if end of string is encountered.
- //
- internal bool SkipWhiteSpaceCurrent()
- {
- if (Index >= Length)
- {
- return false;
- }
-
- if (!char.IsWhiteSpace(m_current))
- {
- return true;
- }
-
- while (++Index < Length)
- {
- m_current = Value[Index];
- if (!char.IsWhiteSpace(m_current))
- {
- return true;
- }
- // Nothing here.
- }
- return false;
- }
-
- internal void TrimTail()
- {
- int i = Length - 1;
- while (i >= 0 && char.IsWhiteSpace(Value[i]))
- {
- i--;
- }
- Value = Value.Slice(0, i + 1);
- }
-
- // Trim the trailing spaces within a quoted string.
- // Call this after TrimTail() is done.
- internal void RemoveTrailingInQuoteSpaces()
- {
- int i = Length - 1;
- if (i <= 1)
- {
- return;
- }
- char ch = Value[i];
- // Check if the last character is a quote.
- if (ch == '\'' || ch == '\"')
- {
- if (char.IsWhiteSpace(Value[i - 1]))
- {
- i--;
- while (i >= 1 && char.IsWhiteSpace(Value[i - 1]))
- {
- i--;
- }
- Span<char> result = new char[i + 1];
- result[i] = ch;
- Value.Slice(0, i).CopyTo(result);
- Value = result;
- }
- }
- }
-
- // Trim the leading spaces within a quoted string.
- // Call this after the leading spaces before quoted string are trimmed.
- internal void RemoveLeadingInQuoteSpaces()
- {
- if (Length <= 2)
- {
- return;
- }
- int i = 0;
- char ch = Value[i];
- // Check if the last character is a quote.
- if (ch == '\'' || ch == '\"')
- {
- while ((i + 1) < Length && char.IsWhiteSpace(Value[i + 1]))
- {
- i++;
- }
- if (i != 0)
- {
- Span<char> result = new char[Value.Length - i];
- result[0] = ch;
- Value.Slice(i + 1).CopyTo(result.Slice(1));
- Value = result;
- }
- }
- }
-
- internal DTSubString GetSubString()
- {
- DTSubString sub = default;
- sub.index = Index;
- sub.s = Value;
- while (Index + sub.length < Length)
- {
- DTSubStringType currentType;
- char ch = Value[Index + sub.length];
- if (ch >= '0' && ch <= '9')
- {
- currentType = DTSubStringType.Number;
- }
- else
- {
- currentType = DTSubStringType.Other;
- }
-
- if (sub.length == 0)
- {
- sub.type = currentType;
- }
- else
- {
- if (sub.type != currentType)
- {
- break;
- }
- }
- sub.length++;
- if (currentType == DTSubStringType.Number)
- {
- // Incorporate the number into the value
- // Limit the digits to prevent overflow
- if (sub.length > DateTimeParse.MaxDateTimeNumberDigits)
- {
- sub.type = DTSubStringType.Invalid;
- return sub;
- }
- int number = ch - '0';
- Debug.Assert(number >= 0 && number <= 9, "number >= 0 && number <= 9");
- sub.value = sub.value * 10 + number;
- }
- else
- {
- // For non numbers, just return this length 1 token. This should be expanded
- // to more types of thing if this parsing approach is used for things other
- // than numbers and single characters
- break;
- }
- }
- if (sub.length == 0)
- {
- sub.type = DTSubStringType.End;
- return sub;
- }
-
- return sub;
- }
-
- internal void ConsumeSubString(DTSubString sub)
- {
- Debug.Assert(sub.index == Index, "sub.index == Index");
- Debug.Assert(sub.index + sub.length <= Length, "sub.index + sub.length <= len");
- Index = sub.index + sub.length;
- if (Index < Length)
- {
- m_current = Value[Index];
- }
- }
- }
-
- internal enum DTSubStringType
- {
- Unknown = 0,
- Invalid = 1,
- Number = 2,
- End = 3,
- Other = 4,
- }
-
- internal ref struct DTSubString
- {
- internal ReadOnlySpan<char> s;
- internal int index;
- internal int length;
- internal DTSubStringType type;
- internal int value;
-
- internal char this[int relativeIndex] => s[index + relativeIndex];
- }
-
- //
- // The buffer to store the parsing token.
- //
- internal
- struct DateTimeToken
- {
- internal DateTimeParse.DTT dtt; // Store the token
- internal TokenType suffix; // Store the CJK Year/Month/Day suffix (if any)
- internal int num; // Store the number that we are parsing (if any)
- }
-
- //
- // The buffer to store temporary parsing information.
- //
- internal unsafe struct DateTimeRawInfo
- {
- private int* num;
- internal int numCount;
- internal int month;
- internal int year;
- internal int dayOfWeek;
- internal int era;
- internal DateTimeParse.TM timeMark;
- internal double fraction;
- internal bool hasSameDateAndTimeSeparators;
-
- internal void Init(int* numberBuffer)
- {
- month = -1;
- year = -1;
- dayOfWeek = -1;
- era = -1;
- timeMark = DateTimeParse.TM.NotSet;
- fraction = -1;
- num = numberBuffer;
- }
-
- internal void AddNumber(int value)
- {
- num[numCount++] = value;
- }
-
- internal int GetNumber(int index)
- {
- return num[index];
- }
- }
-
- internal enum ParseFailureKind
- {
- None = 0,
- ArgumentNull = 1,
- Format = 2,
- FormatWithParameter = 3,
- FormatWithOriginalDateTime = 4,
- FormatWithFormatSpecifier = 5,
- FormatWithOriginalDateTimeAndParameter = 6,
- FormatBadDateTimeCalendar = 7, // FormatException when ArgumentOutOfRange is thrown by a Calendar.TryToDateTime().
- }
-
- [Flags]
- internal enum ParseFlags
- {
- HaveYear = 0x00000001,
- HaveMonth = 0x00000002,
- HaveDay = 0x00000004,
- HaveHour = 0x00000008,
- HaveMinute = 0x00000010,
- HaveSecond = 0x00000020,
- HaveTime = 0x00000040,
- HaveDate = 0x00000080,
- TimeZoneUsed = 0x00000100,
- TimeZoneUtc = 0x00000200,
- ParsedMonthName = 0x00000400,
- CaptureOffset = 0x00000800,
- YearDefault = 0x00001000,
- Rfc1123Pattern = 0x00002000,
- UtcSortPattern = 0x00004000,
- }
-
- //
- // This will store the result of the parsing. And it will be eventually
- // used to construct a DateTime instance.
- //
- internal ref struct DateTimeResult
- {
- internal int Year;
- internal int Month;
- internal int Day;
- //
- // Set time default to 00:00:00.
- //
- internal int Hour;
- internal int Minute;
- internal int Second;
- internal double fraction;
-
- internal int era;
-
- internal ParseFlags flags;
-
- internal TimeSpan timeZoneOffset;
-
- internal Calendar calendar;
-
- internal DateTime parsedDate;
-
- internal ParseFailureKind failure;
- internal string failureMessageID;
- internal object? failureMessageFormatArgument;
- internal string failureArgumentName;
- internal ReadOnlySpan<char> originalDateTimeString;
- internal ReadOnlySpan<char> failedFormatSpecifier;
-
- internal void Init(ReadOnlySpan<char> originalDateTimeString)
- {
- this.originalDateTimeString = originalDateTimeString;
- Year = -1;
- Month = -1;
- Day = -1;
- fraction = -1;
- era = -1;
- }
-
- internal void SetDate(int year, int month, int day)
- {
- Year = year;
- Month = month;
- Day = day;
- }
-
- internal void SetBadFormatSpecifierFailure()
- {
- SetBadFormatSpecifierFailure(ReadOnlySpan<char>.Empty);
- }
-
- internal void SetBadFormatSpecifierFailure(ReadOnlySpan<char> failedFormatSpecifier)
- {
- this.failure = ParseFailureKind.FormatWithFormatSpecifier;
- this.failureMessageID = nameof(SR.Format_BadFormatSpecifier);
- this.failedFormatSpecifier = failedFormatSpecifier;
- }
-
- internal void SetBadDateTimeFailure()
- {
- this.failure = ParseFailureKind.FormatWithOriginalDateTime;
- this.failureMessageID = nameof(SR.Format_BadDateTime);
- this.failureMessageFormatArgument = null;
- }
-
- internal void SetFailure(ParseFailureKind failure, string failureMessageID)
- {
- this.failure = failure;
- this.failureMessageID = failureMessageID;
- this.failureMessageFormatArgument = null;
- }
-
- internal void SetFailure(ParseFailureKind failure, string failureMessageID, object? failureMessageFormatArgument)
- {
- this.failure = failure;
- this.failureMessageID = failureMessageID;
- this.failureMessageFormatArgument = failureMessageFormatArgument;
- }
-
- internal void SetFailure(ParseFailureKind failure, string failureMessageID, object? failureMessageFormatArgument, string failureArgumentName)
- {
- this.failure = failure;
- this.failureMessageID = failureMessageID;
- this.failureMessageFormatArgument = failureMessageFormatArgument;
- this.failureArgumentName = failureArgumentName;
- }
- }
-
- // This is the helper data structure used in ParseExact().
- internal struct ParsingInfo
- {
- internal Calendar calendar;
- internal int dayOfWeek;
- internal DateTimeParse.TM timeMark;
-
- internal bool fUseHour12;
- internal bool fUseTwoDigitYear;
- internal bool fAllowInnerWhite;
- internal bool fAllowTrailingWhite;
- internal bool fCustomNumberParser;
- internal DateTimeParse.MatchNumberDelegate parseNumberDelegate;
-
- internal void Init()
- {
- dayOfWeek = -1;
- timeMark = DateTimeParse.TM.NotSet;
- }
- }
-
- //
- // The type of token that will be returned by DateTimeFormatInfo.Tokenize().
- //
- internal enum TokenType
- {
- // The valid token should start from 1.
-
- // Regular tokens. The range is from 0x00 ~ 0xff.
- NumberToken = 1, // The number. E.g. "12"
- YearNumberToken = 2, // The number which is considered as year number, which has 3 or more digits. E.g. "2003"
- Am = 3, // AM timemark. E.g. "AM"
- Pm = 4, // PM timemark. E.g. "PM"
- MonthToken = 5, // A word (or words) that represents a month name. E.g. "March"
- EndOfString = 6, // End of string
- DayOfWeekToken = 7, // A word (or words) that represents a day of week name. E.g. "Monday" or "Mon"
- TimeZoneToken = 8, // A word that represents a timezone name. E.g. "GMT"
- EraToken = 9, // A word that represents a era name. E.g. "A.D."
- DateWordToken = 10, // A word that can appear in a DateTime string, but serves no parsing semantics. E.g. "de" in Spanish culture.
- UnknownToken = 11, // An unknown word, which signals an error in parsing.
- HebrewNumber = 12, // A number that is composed of Hebrew text. Hebrew calendar uses Hebrew digits for year values, month values, and day values.
- JapaneseEraToken = 13, // Era name for JapaneseCalendar
- TEraToken = 14, // Era name for TaiwanCalendar
- IgnorableSymbol = 15, // A separator like "," that is equivalent to whitespace
-
- // Separator tokens.
- SEP_Unk = 0x100, // Unknown separator.
- SEP_End = 0x200, // The end of the parsing string.
- SEP_Space = 0x300, // Whitespace (including comma).
- SEP_Am = 0x400, // AM timemark. E.g. "AM"
- SEP_Pm = 0x500, // PM timemark. E.g. "PM"
- SEP_Date = 0x600, // date separator. E.g. "/"
- SEP_Time = 0x700, // time separator. E.g. ":"
- SEP_YearSuff = 0x800, // Chinese/Japanese/Korean year suffix.
- SEP_MonthSuff = 0x900, // Chinese/Japanese/Korean month suffix.
- SEP_DaySuff = 0xa00, // Chinese/Japanese/Korean day suffix.
- SEP_HourSuff = 0xb00, // Chinese/Japanese/Korean hour suffix.
- SEP_MinuteSuff = 0xc00, // Chinese/Japanese/Korean minute suffix.
- SEP_SecondSuff = 0xd00, // Chinese/Japanese/Korean second suffix.
- SEP_LocalTimeMark = 0xe00, // 'T', used in ISO 8601 format.
- SEP_DateOrOffset = 0xf00, // '-' which could be a date separator or start of a time zone offset
-
- RegularTokenMask = 0x00ff,
- SeparatorTokenMask = 0xff00,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeStyles.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeStyles.cs
deleted file mode 100644
index 94a1eeb71f4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/DateTimeStyles.cs
+++ /dev/null
@@ -1,49 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Contains valid formats for DateTime recognized by
-** the DateTime class' parsing code.
-**
-**
-===========================================================*/
-
-namespace System.Globalization
-{
- [Flags]
- public enum DateTimeStyles
- {
- // Bit flag indicating that leading whitespace is allowed. Character values
- // 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, and 0x0020 are considered to be
- // whitespace.
-
-
- None = 0x00000000,
-
- AllowLeadingWhite = 0x00000001,
-
- AllowTrailingWhite = 0x00000002, // Bitflag indicating trailing whitespace is allowed.
-
- AllowInnerWhite = 0x00000004,
-
- AllowWhiteSpaces = AllowLeadingWhite | AllowInnerWhite | AllowTrailingWhite,
- // When parsing a date/time string, if all year/month/day are missing, set the default date
- // to 0001/1/1, instead of the current year/month/day.
-
- NoCurrentDateDefault = 0x00000008,
- // When parsing a date/time string, if a timezone specifier ("GMT","Z","+xxxx", "-xxxx" exists), we will
- // adjust the parsed time based to GMT.
-
- AdjustToUniversal = 0x00000010,
-
- AssumeLocal = 0x00000020,
-
- AssumeUniversal = 0x00000040,
- // Attempt to preserve whether the input is unspecified, local or UTC
- RoundtripKind = 0x00000080,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/DaylightTime.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/DaylightTime.cs
deleted file mode 100644
index 72a572c97de..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/DaylightTime.cs
+++ /dev/null
@@ -1,45 +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.
-
-namespace System.Globalization
-{
- // This class represents a starting/ending time for a period of daylight saving time.
- public class DaylightTime
- {
- private readonly DateTime _start;
- private readonly DateTime _end;
- private readonly TimeSpan _delta;
-
- public DaylightTime(DateTime start, DateTime end, TimeSpan delta)
- {
- _start = start;
- _end = end;
- _delta = delta;
- }
-
- // The start date of a daylight saving period.
- public DateTime Start => _start;
-
- // The end date of a daylight saving period.
- public DateTime End => _end;
-
- // Delta to stardard offset in ticks.
- public TimeSpan Delta => _delta;
- }
-
- // Value type version of DaylightTime
- internal readonly struct DaylightTimeStruct
- {
- public DaylightTimeStruct(DateTime start, DateTime end, TimeSpan delta)
- {
- Start = start;
- End = end;
- Delta = delta;
- }
-
- public readonly DateTime Start;
- public readonly DateTime End;
- public readonly TimeSpan Delta;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/DigitShapes.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/DigitShapes.cs
deleted file mode 100644
index 27ff391ca72..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/DigitShapes.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Globalization
-{
- public enum DigitShapes : int
- {
- Context = 0x0000, // The shape depends on the previous text in the same output.
- None = 0x0001, // Gives full Unicode compatibility.
- NativeNational = 0x0002 // National shapes
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/EastAsianLunisolarCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/EastAsianLunisolarCalendar.cs
deleted file mode 100644
index 113fec1a7d6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/EastAsianLunisolarCalendar.cs
+++ /dev/null
@@ -1,692 +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.
-
-namespace System.Globalization
-{
- public abstract class EastAsianLunisolarCalendar : Calendar
- {
- private const int LeapMonth = 0;
- private const int Jan1Month = 1;
- private const int Jan1Date = 2;
- private const int nDaysPerMonth = 3;
-
- // # of days so far in the solar year
- private static readonly int[] s_daysToMonth365 = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
-
- private static readonly int[] s_daysToMonth366 = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 };
-
- public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.LunisolarCalendar;
-
- /// <summary>
- /// Return the year number in the 60-year cycle.
- /// </summary>
- public virtual int GetSexagenaryYear(DateTime time)
- {
- CheckTicksRange(time.Ticks);
-
- TimeToLunar(time, out int year, out _, out _);
- return ((year - 4) % 60) + 1;
- }
-
- /// <summary>
- /// Return the celestial year from the 60-year cycle.
- /// The returned value is from 1 ~ 10.
- /// </summary>
- public int GetCelestialStem(int sexagenaryYear)
- {
- if (sexagenaryYear < 1 || sexagenaryYear > 60)
- {
- throw new ArgumentOutOfRangeException(
- nameof(sexagenaryYear),
- sexagenaryYear,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, 60));
- }
-
- return ((sexagenaryYear - 1) % 10) + 1;
- }
-
- /// <summary>
- /// Return the Terrestial Branch from the 60-year cycle.
- /// The returned value is from 1 ~ 12.
- /// </summary>
- public int GetTerrestrialBranch(int sexagenaryYear)
- {
- if (sexagenaryYear < 1 || sexagenaryYear > 60)
- {
- throw new ArgumentOutOfRangeException(
- nameof(sexagenaryYear),
- sexagenaryYear,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, 60));
- }
-
- return ((sexagenaryYear - 1) % 12) + 1;
- }
-
- internal abstract int GetYearInfo(int LunarYear, int Index);
- internal abstract int GetYear(int year, DateTime time);
- internal abstract int GetGregorianYear(int year, int era);
-
- internal abstract int MinCalendarYear { get; }
- internal abstract int MaxCalendarYear { get; }
- internal abstract EraInfo[]? CalEraInfo { get; }
- internal abstract DateTime MinDate { get; }
- internal abstract DateTime MaxDate { get; }
-
- internal const int MaxCalendarMonth = 13;
- internal const int MaxCalendarDay = 30;
-
- internal int MinEraCalendarYear(int era)
- {
- EraInfo[]? eraInfo = CalEraInfo;
- if (eraInfo == null)
- {
- return MinCalendarYear;
- }
-
- if (era == Calendar.CurrentEra)
- {
- era = CurrentEraValue;
- }
-
- // Era has to be in the supported range otherwise we will throw exception in CheckEraRange()
- if (era == GetEra(MinDate))
- {
- return GetYear(MinCalendarYear, MinDate);
- }
-
- for (int i = 0; i < eraInfo.Length; i++)
- {
- if (era == eraInfo[i].era)
- {
- return eraInfo[i].minEraYear;
- }
- }
-
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
-
- internal int MaxEraCalendarYear(int era)
- {
- EraInfo[]? eraInfo = CalEraInfo;
- if (eraInfo == null)
- {
- return MaxCalendarYear;
- }
-
- if (era == Calendar.CurrentEra)
- {
- era = CurrentEraValue;
- }
-
- // Era has to be in the supported range otherwise we will throw exception in CheckEraRange()
- if (era == GetEra(MaxDate))
- {
- return GetYear(MaxCalendarYear, MaxDate);
- }
-
- for (int i = 0; i < eraInfo.Length; i++)
- {
- if (era == eraInfo[i].era)
- {
- return eraInfo[i].maxEraYear;
- }
- }
-
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
-
- internal EastAsianLunisolarCalendar()
- {
- }
-
- internal void CheckTicksRange(long ticks)
- {
- if (ticks < MinSupportedDateTime.Ticks || ticks > MaxSupportedDateTime.Ticks)
- {
- throw new ArgumentOutOfRangeException(
- "time",
- ticks,
- SR.Format(CultureInfo.InvariantCulture, SR.ArgumentOutOfRange_CalendarRange,
- MinSupportedDateTime, MaxSupportedDateTime));
- }
- }
-
- internal void CheckEraRange(int era)
- {
- if (era == Calendar.CurrentEra)
- {
- era = CurrentEraValue;
- }
-
- if (era < GetEra(MinDate) || era > GetEra(MaxDate))
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- }
-
- internal int CheckYearRange(int year, int era)
- {
- CheckEraRange(era);
- year = GetGregorianYear(year, era);
-
- if (year < MinCalendarYear || year > MaxCalendarYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, MinEraCalendarYear(era), MaxEraCalendarYear(era)));
- }
- return year;
- }
-
- internal int CheckYearMonthRange(int year, int month, int era)
- {
- year = CheckYearRange(year, era);
-
- if (month == 13)
- {
- // Reject if there is no leap month this year
- if (GetYearInfo(year, LeapMonth) == 0)
- {
- throw new ArgumentOutOfRangeException(nameof(month), month, SR.ArgumentOutOfRange_Month);
- }
- }
-
- if (month < 1 || month > 13)
- {
- throw new ArgumentOutOfRangeException(nameof(month), month, SR.ArgumentOutOfRange_Month);
- }
-
- return year;
- }
-
- internal int InternalGetDaysInMonth(int year, int month)
- {
- int mask = 0x8000;
-
- // convert the lunar day into a lunar month/date
- mask >>= (month - 1);
- if ((GetYearInfo(year, nDaysPerMonth) & mask) == 0)
- {
- return 29;
- }
-
- return 30;
- }
-
- /// <summary>
- /// Returns the number of days in the month given by the year and
- /// month arguments.
- /// </summary>
- public override int GetDaysInMonth(int year, int month, int era)
- {
- year = CheckYearMonthRange(year, month, era);
- return InternalGetDaysInMonth(year, month);
- }
-
- private static bool GregorianIsLeapYear(int y)
- {
- if ((y % 4) != 0)
- {
- return false;
- }
- if ((y % 100) != 0)
- {
- return true;
- }
-
- return (y % 400) == 0;
- }
-
- /// <summary>
- /// Returns the date and time converted to a DateTime value.
- /// Throws an exception if the n-tuple is invalid.
- /// </summary>
- public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- year = CheckYearMonthRange(year, month, era);
- int daysInMonth = InternalGetDaysInMonth(year, month);
- if (day < 1 || day > daysInMonth)
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- day,
- SR.Format(SR.ArgumentOutOfRange_Day, daysInMonth, month));
- }
-
- if (!LunarToGregorian(year, month, day, out int gy, out int gm, out int gd))
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay);
- }
-
- return new DateTime(gy, gm, gd, hour, minute, second, millisecond);
- }
-
- /// <summary>
- /// Calculates lunar calendar info for the given gregorian year, month, date.
- /// The input date should be validated before calling this method.
- /// </summary>
- private void GregorianToLunar(int solarYear, int solarMonth, int solarDate, out int lunarYear, out int lunarMonth, out int lunarDate)
- {
- bool isLeapYear = GregorianIsLeapYear(solarYear);
- int jan1Month;
- int jan1Date;
-
- // Calculate the day number in the solar year.
- int solarDay = isLeapYear ? s_daysToMonth366[solarMonth - 1] : s_daysToMonth365[solarMonth - 1];
- solarDay += solarDate;
-
- // Calculate the day number in the lunar year.
- int lunarDay = solarDay;
- lunarYear = solarYear;
- if (lunarYear == (MaxCalendarYear + 1))
- {
- lunarYear--;
- lunarDay += (GregorianIsLeapYear(lunarYear) ? 366 : 365);
- jan1Month = GetYearInfo(lunarYear, Jan1Month);
- jan1Date = GetYearInfo(lunarYear, Jan1Date);
- }
- else
- {
- jan1Month = GetYearInfo(lunarYear, Jan1Month);
- jan1Date = GetYearInfo(lunarYear, Jan1Date);
-
- // check if this solar date is actually part of the previous
- // lunar year
- if ((solarMonth < jan1Month) ||
- (solarMonth == jan1Month && solarDate < jan1Date))
- {
- // the corresponding lunar day is actually part of the previous
- // lunar year
- lunarYear--;
-
- // add a solar year to the lunar day #
- lunarDay += (GregorianIsLeapYear(lunarYear) ? 366 : 365);
-
- // update the new start of year
- jan1Month = GetYearInfo(lunarYear, Jan1Month);
- jan1Date = GetYearInfo(lunarYear, Jan1Date);
- }
- }
-
- // convert solar day into lunar day.
- // subtract off the beginning part of the solar year which is not
- // part of the lunar year. since this part is always in Jan or Feb,
- // we don't need to handle Leap Year (LY only affects March
- // and later).
- lunarDay -= s_daysToMonth365[jan1Month - 1];
- lunarDay -= (jan1Date - 1);
-
- // convert the lunar day into a lunar month/date
- int mask = 0x8000;
- int yearInfo = GetYearInfo(lunarYear, nDaysPerMonth);
- int days = ((yearInfo & mask) != 0) ? 30 : 29;
- lunarMonth = 1;
- while (lunarDay > days)
- {
- lunarDay -= days;
- lunarMonth++;
- mask >>= 1;
- days = ((yearInfo & mask) != 0) ? 30 : 29;
- }
- lunarDate = lunarDay;
- }
-
- /// <summary>
- /// Convert from Lunar to Gregorian
- /// </summary>
- /// <remarks>
- /// Highly inefficient, but it works based on the forward conversion
- /// </remarks>
- private bool LunarToGregorian(int lunarYear, int lunarMonth, int lunarDate, out int solarYear, out int solarMonth, out int solarDay)
- {
- if (lunarDate < 1 || lunarDate > 30)
- {
- solarYear = 0;
- solarMonth = 0;
- solarDay = 0;
- return false;
- }
-
- int numLunarDays = lunarDate - 1;
-
- // Add previous months days to form the total num of days from the first of the month.
- for (int i = 1; i < lunarMonth; i++)
- {
- numLunarDays += InternalGetDaysInMonth(lunarYear, i);
- }
-
- // Get Gregorian First of year
- int jan1Month = GetYearInfo(lunarYear, Jan1Month);
- int jan1Date = GetYearInfo(lunarYear, Jan1Date);
-
- // calc the solar day of year of 1 Lunar day
- bool isLeapYear = GregorianIsLeapYear(lunarYear);
- int[] days = isLeapYear ? s_daysToMonth366 : s_daysToMonth365;
-
- solarDay = jan1Date;
-
- if (jan1Month > 1)
- {
- solarDay += days[jan1Month - 1];
- }
-
- // Add the actual lunar day to get the solar day we want
- solarDay += numLunarDays;
-
- if (solarDay > (365 + (isLeapYear ? 1 : 0)))
- {
- solarYear = lunarYear + 1;
- solarDay -= (365 + (isLeapYear ? 1 : 0));
- }
- else
- {
- solarYear = lunarYear;
- }
-
- for (solarMonth = 1; solarMonth < 12; solarMonth++)
- {
- if (days[solarMonth] >= solarDay)
- {
- break;
- }
- }
-
- solarDay -= days[solarMonth - 1];
- return true;
- }
-
- private DateTime LunarToTime(DateTime time, int year, int month, int day)
- {
- LunarToGregorian(year, month, day, out int gy, out int gm, out int gd);
- return GregorianCalendar.GetDefaultInstance().ToDateTime(gy, gm, gd, time.Hour, time.Minute, time.Second, time.Millisecond);
- }
-
- private void TimeToLunar(DateTime time, out int year, out int month, out int day)
- {
- Calendar gregorianCalendar = GregorianCalendar.GetDefaultInstance();
- int gy = gregorianCalendar.GetYear(time);
- int gm = gregorianCalendar.GetMonth(time);
- int gd = gregorianCalendar.GetDayOfMonth(time);
-
- GregorianToLunar(gy, gm, gd, out year, out month, out day);
- }
-
- /// <summary>
- /// Returns the DateTime resulting from adding the given number of
- /// months to the specified DateTime. The result is computed by incrementing
- /// (or decrementing) the year and month parts of the specified DateTime by
- /// value months, and, if required, adjusting the day part of the
- /// resulting date downwards to the last day of the resulting month in the
- /// resulting year. The time-of-day part of the result is the same as the
- /// time-of-day part of the specified DateTime.
- /// </summary>
- public override DateTime AddMonths(DateTime time, int months)
- {
- if (months < -120000 || months > 120000)
- {
- throw new ArgumentOutOfRangeException(
- nameof(months),
- months,
- SR.Format(SR.ArgumentOutOfRange_Range, -120000, 120000));
- }
-
- CheckTicksRange(time.Ticks);
- TimeToLunar(time, out int y, out int m, out int d);
-
- int i = m + months;
- if (i > 0)
- {
- int monthsInYear = InternalIsLeapYear(y) ? 13 : 12;
-
- while (i - monthsInYear > 0)
- {
- i -= monthsInYear;
- y++;
- monthsInYear = InternalIsLeapYear(y) ? 13 : 12;
- }
- m = i;
- }
- else
- {
- int monthsInYear;
- while (i <= 0)
- {
- monthsInYear = InternalIsLeapYear(y - 1) ? 13 : 12;
- i += monthsInYear;
- y--;
- }
- m = i;
- }
-
- int days = InternalGetDaysInMonth(y, m);
- if (d > days)
- {
- d = days;
- }
- DateTime dt = LunarToTime(time, y, m, d);
-
- CheckAddResult(dt.Ticks, MinSupportedDateTime, MaxSupportedDateTime);
- return dt;
- }
-
- public override DateTime AddYears(DateTime time, int years)
- {
- CheckTicksRange(time.Ticks);
- TimeToLunar(time, out int y, out int m, out int d);
-
- y += years;
-
- if (m == 13 && !InternalIsLeapYear(y))
- {
- m = 12;
- d = InternalGetDaysInMonth(y, m);
- }
- int daysInMonths = InternalGetDaysInMonth(y, m);
- if (d > daysInMonths)
- {
- d = daysInMonths;
- }
-
- DateTime dt = LunarToTime(time, y, m, d);
- CheckAddResult(dt.Ticks, MinSupportedDateTime, MaxSupportedDateTime);
- return dt;
- }
-
- /// <summary>
- /// Returns the day-of-year part of the specified DateTime. The returned value
- /// is an integer between 1 and [354|355 |383|384].
- /// </summary>
- public override int GetDayOfYear(DateTime time)
- {
- CheckTicksRange(time.Ticks);
- TimeToLunar(time, out int y, out int m, out int d);
-
- for (int i = 1; i < m; i++)
- {
- d += InternalGetDaysInMonth(y, i);
- }
- return d;
- }
-
- /// <summary>
- /// Returns the day-of-month part of the specified DateTime. The returned
- /// value is an integer between 1 and 29 or 30.
- /// </summary>
- public override int GetDayOfMonth(DateTime time)
- {
- CheckTicksRange(time.Ticks);
-
- TimeToLunar(time, out _, out _, out int d);
-
- return d;
- }
-
- /// <summary>
- /// Returns the number of days in the year given by the year argument for the current era.
- /// </summary>
- public override int GetDaysInYear(int year, int era)
- {
- year = CheckYearRange(year, era);
-
- int days = 0;
- int monthsInYear = InternalIsLeapYear(year) ? 13 : 12;
-
- while (monthsInYear != 0)
- {
- days += InternalGetDaysInMonth(year, monthsInYear--);
- }
-
- return days;
- }
-
- /// <summary>
- /// Returns the month part of the specified DateTime.
- /// The returned value is an integer between 1 and 13.
- /// </summary>
- public override int GetMonth(DateTime time)
- {
- CheckTicksRange(time.Ticks);
-
- TimeToLunar(time, out _, out int m, out _);
-
- return m;
- }
-
- /// <summary>
- /// Returns the year part of the specified DateTime.
- /// The returned value is an integer between 1 and MaxCalendarYear.
- /// </summary>
- public override int GetYear(DateTime time)
- {
- CheckTicksRange(time.Ticks);
-
- TimeToLunar(time, out int y, out _, out _);
-
- return GetYear(y, time);
- }
-
- /// <summary>
- /// Returns the day-of-week part of the specified DateTime. The returned value
- /// is an integer between 0 and 6, where 0 indicates Sunday, 1 indicates
- /// Monday, 2 indicates Tuesday, 3 indicates Wednesday, 4 indicates
- /// Thursday, 5 indicates Friday, and 6 indicates Saturday.
- /// </summary>
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
- CheckTicksRange(time.Ticks);
- return (DayOfWeek)((int)(time.Ticks / Calendar.TicksPerDay + 1) % 7);
- }
-
- /// <summary>
- /// Returns the number of months in the specified year and era.
- /// </summary>
- public override int GetMonthsInYear(int year, int era)
- {
- year = CheckYearRange(year, era);
- return InternalIsLeapYear(year) ? 13 : 12;
- }
-
- /// <summary>
- /// Checks whether a given day in the specified era is a leap day.
- /// This method returns true if the date is a leap day, or false if not.
- /// </summary>
- public override bool IsLeapDay(int year, int month, int day, int era)
- {
- year = CheckYearMonthRange(year, month, era);
- int daysInMonth = InternalGetDaysInMonth(year, month);
-
- if (day < 1 || day > daysInMonth)
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- day,
- SR.Format(SR.ArgumentOutOfRange_Day, daysInMonth, month));
- }
-
- int m = GetYearInfo(year, LeapMonth);
- return (m != 0) && (month == (m + 1));
- }
-
- /// <summary>
- /// Checks whether a given month in the specified era is a leap month.
- /// This method returns true if month is a leap month, or false if not.
- /// </summary>
- public override bool IsLeapMonth(int year, int month, int era)
- {
- year = CheckYearMonthRange(year, month, era);
- int m = GetYearInfo(year, LeapMonth);
- return (m != 0) && (month == (m + 1));
- }
-
- /// <summary>
- /// Returns the leap month in a calendar year of the specified era. This method returns 0
- /// if this year is not a leap year.
- /// </summary>
- public override int GetLeapMonth(int year, int era)
- {
- year = CheckYearRange(year, era);
- int month = GetYearInfo(year, LeapMonth);
- return month > 0 ? month + 1 : 0;
- }
-
- internal bool InternalIsLeapYear(int year)
- {
- return GetYearInfo(year, LeapMonth) != 0;
- }
-
- /// <summary>
- /// Checks whether a given year in the specified era is a leap year.
- /// This method returns true if year is a leap year, or false if not.
- /// </summary>
- public override bool IsLeapYear(int year, int era)
- {
- year = CheckYearRange(year, era);
- return InternalIsLeapYear(year);
- }
-
- private const int DefaultGregorianTwoDigitYearMax = 2029;
-
- public override int TwoDigitYearMax
- {
- get
- {
- if (_twoDigitYearMax == -1)
- {
- _twoDigitYearMax = GetSystemTwoDigitYearSetting(BaseCalendarID, GetYear(new DateTime(DefaultGregorianTwoDigitYearMax, 1, 1)));
- }
-
- return _twoDigitYearMax;
- }
- set
- {
- VerifyWritable();
- if (value < 99 || value > MaxCalendarYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 99, MaxCalendarYear));
- }
-
- _twoDigitYearMax = value;
- }
- }
-
- public override int ToFourDigitYear(int year)
- {
- if (year < 0)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- year = base.ToFourDigitYear(year);
- CheckYearRange(year, CurrentEra);
- return year;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/GlobalizationExtensions.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/GlobalizationExtensions.cs
deleted file mode 100644
index 2e61b5394ab..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/GlobalizationExtensions.cs
+++ /dev/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.
-
-namespace System.Globalization
-{
- public static class GlobalizationExtensions
- {
- public static StringComparer GetStringComparer(this CompareInfo compareInfo, CompareOptions options)
- {
- if (compareInfo == null)
- {
- throw new ArgumentNullException(nameof(compareInfo));
- }
-
- if (options == CompareOptions.Ordinal)
- {
- return StringComparer.Ordinal;
- }
-
- if (options == CompareOptions.OrdinalIgnoreCase)
- {
- return StringComparer.OrdinalIgnoreCase;
- }
-
- return new CultureAwareComparer(compareInfo, options);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs
deleted file mode 100644
index 6767b9a26a2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs
+++ /dev/null
@@ -1,488 +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.
-
-namespace System.Globalization
-{
- /// <remarks>
- /// This calendar recognizes two era values:
- /// 0 CurrentEra (AD)
- /// 1 BeforeCurrentEra (BC)
- /// </remarks>
- public class GregorianCalendar : Calendar
- {
- public const int ADEra = 1;
-
- // This is the min Gregorian year can be represented by the DateTime class.
- // The limitation is derived from the DateTime class.
- internal const int MinYear = 1;
-
- // This is the max Gregorian year can be represented by the DateTime class.
- // The limitation is derived from the DateTime class.
- internal const int MaxYear = 9999;
-
- private GregorianCalendarTypes _type;
-
- private static readonly int[] DaysToMonth365 = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
-
- private static readonly int[] DaysToMonth366 = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
-
- private static volatile Calendar? s_defaultInstance;
-
- public override DateTime MinSupportedDateTime => DateTime.MinValue;
-
- public override DateTime MaxSupportedDateTime => DateTime.MaxValue;
-
- public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.SolarCalendar;
-
- /// <summary>
- /// Internal method to provide a default intance of GregorianCalendar.
- /// Used by NLS+ implementation
- /// </summary>
- internal static Calendar GetDefaultInstance() => s_defaultInstance ??= new GregorianCalendar();
-
- public GregorianCalendar() : this(GregorianCalendarTypes.Localized)
- {
- }
-
- public GregorianCalendar(GregorianCalendarTypes type)
- {
- if (type < GregorianCalendarTypes.Localized || type > GregorianCalendarTypes.TransliteratedFrench)
- {
- throw new ArgumentOutOfRangeException(
- nameof(type),
- type,
- SR.Format(SR.ArgumentOutOfRange_Range, GregorianCalendarTypes.Localized, GregorianCalendarTypes.TransliteratedFrench));
- }
-
- _type = type;
- }
-
- public virtual GregorianCalendarTypes CalendarType
- {
- get => _type;
- set
- {
- VerifyWritable();
- if (value < GregorianCalendarTypes.Localized || value > GregorianCalendarTypes.TransliteratedFrench)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, GregorianCalendarTypes.Localized, GregorianCalendarTypes.TransliteratedFrench));
- }
-
- _type = value;
- }
- }
-
- internal override CalendarId ID =>
- // By returning different ID for different variations of GregorianCalendar,
- // we can support the Transliterated Gregorian calendar.
- // DateTimeFormatInfo will use this ID to get formatting information about
- // the calendar.
- (CalendarId)_type;
-
- /// <summary>
- /// Gets the absolute date for the given Gregorian date. The absolute date means
- /// the number of days from January 1st, 1 A.D.
- /// </summary>
- /// <remarks>
- /// This is an internal method used by DateToTicks() and the calculations of Hijri and Hebrew calendars.
- /// Number of Days in Prior Years (both common and leap years) +
- /// Number of Days in Prior Months of Current Year +
- /// Number of Days in Current Month
- /// </remarks>
- internal static long GetAbsoluteDate(int year, int month, int day)
- {
- if (year >= 1 && year <= MaxYear && month >= 1 && month <= 12)
- {
- int[] days = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? DaysToMonth366 : DaysToMonth365;
- if (day >= 1 && (day <= days[month] - days[month - 1]))
- {
- int y = year - 1;
- return y * 365 + y / 4 - y / 100 + y / 400 + days[month - 1] + day - 1;
- }
- }
-
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay);
- }
-
- /// <summary>
- /// Returns the tick count corresponding to the given year, month, and day.
- /// Will check the if the parameters are valid.
- /// </summary>
- internal virtual long DateToTicks(int year, int month, int day)
- {
- return GetAbsoluteDate(year, month, day) * TicksPerDay;
- }
-
- /// <summary>
- /// Returns the DateTime resulting from adding the given number of
- /// months to the specified DateTime. The result is computed by incrementing
- /// (or decrementing) the year and month parts of the specified DateTime by
- /// value months, and, if required, adjusting the day part of the
- /// resulting date downwards to the last day of the resulting month in the
- /// resulting year. The time-of-day part of the result is the same as the
- /// time-of-day part of the specified DateTime.
- ///
- /// In more precise terms, considering the specified DateTime to be of the
- /// form y / m / d + t, where y is the
- /// year, m is the month, d is the day, and t is the
- /// time-of-day, the result is y1 / m1 / d1 + t,
- /// where y1 and m1 are computed by adding value months
- /// to y and m, and d1 is the largest value less than
- /// or equal to d that denotes a valid day in month m1 of year
- /// y1.
- /// </summary>
- public override DateTime AddMonths(DateTime time, int months)
- {
- if (months < -120000 || months > 120000)
- {
- throw new ArgumentOutOfRangeException(
- nameof(months),
- months,
- SR.Format(SR.ArgumentOutOfRange_Range, -120000, 120000));
- }
-
- time.GetDatePart(out int y, out int m, out int d);
- int i = m - 1 + months;
- if (i >= 0)
- {
- m = i % 12 + 1;
- y += i / 12;
- }
- else
- {
- m = 12 + (i + 1) % 12;
- y += (i - 11) / 12;
- }
-
- int[] daysArray = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) ? DaysToMonth366 : DaysToMonth365;
- int days = (daysArray[m] - daysArray[m - 1]);
-
- if (d > days)
- {
- d = days;
- }
- long ticks = DateToTicks(y, m, d) + time.Ticks % TicksPerDay;
- Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
-
- return new DateTime(ticks);
- }
-
- /// <summary>
- /// Returns the DateTime resulting from adding the given number of
- /// years to the specified DateTime. The result is computed by incrementing
- /// (or decrementing) the year part of the specified DateTime by value
- /// years. If the month and day of the specified DateTime is 2/29, and if the
- /// resulting year is not a leap year, the month and day of the resulting
- /// DateTime becomes 2/28. Otherwise, the month, day, and time-of-day
- /// parts of the result are the same as those of the specified DateTime.
- /// </summary>
- public override DateTime AddYears(DateTime time, int years)
- {
- return AddMonths(time, years * 12);
- }
-
- /// <summary>
- /// Returns the day-of-month part of the specified DateTime. The returned
- /// value is an integer between 1 and 31.
- /// </summary>
- public override int GetDayOfMonth(DateTime time) => time.Day;
-
- /// <summary>
- /// Returns the day-of-week part of the specified DateTime. The returned value
- /// is an integer between 0 and 6, where 0 indicates Sunday, 1 indicates
- /// Monday, 2 indicates Tuesday, 3 indicates Wednesday, 4 indicates
- /// Thursday, 5 indicates Friday, and 6 indicates Saturday.
- /// </summary>
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
- return (DayOfWeek)((int)(time.Ticks / TicksPerDay + 1) % 7);
- }
-
- /// <summary>
- /// Returns the day-of-year part of the specified DateTime. The returned value
- /// is an integer between 1 and 366.
- /// </summary>
- public override int GetDayOfYear(DateTime time) => time.DayOfYear;
-
- /// <summary>
- /// Returns the number of days in the month given by the year and
- /// month arguments.
- /// </summary>
- public override int GetDaysInMonth(int year, int month, int era)
- {
- if (era != CurrentEra && era != ADEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
-
- if (year < 1 || year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxYear));
- }
- if (month < 1 || month > 12)
- {
- throw new ArgumentOutOfRangeException(nameof(month), month, SR.ArgumentOutOfRange_Month);
- }
-
- int[] days = ((year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? DaysToMonth366 : DaysToMonth365);
- return days[month] - days[month - 1];
- }
-
- /// <summary>
- /// Returns the number of days in the year given by the year argument for
- /// the current era.
- /// </summary>
- public override int GetDaysInYear(int year, int era)
- {
- if (era != CurrentEra && era != ADEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
-
- if (year < 1 || year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxYear));
- }
-
- return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 366 : 365;
- }
-
- public override int GetEra(DateTime time) => ADEra;
-
- public override int[] Eras => new int[] { ADEra };
-
- /// <summary>
- /// Returns the month part of the specified DateTime.
- /// The returned value is an integer between 1 and 12.
- /// </summary>
- public override int GetMonth(DateTime time) => time.Month;
-
- /// <summary>
- /// Returns the number of months in the specified year and era.
- /// </summary>
- public override int GetMonthsInYear(int year, int era)
- {
- if (era != CurrentEra && era != ADEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- if (year < 1 || year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxYear));
- }
-
- return 12;
- }
-
- /// <summary>
- /// Returns the year part of the specified DateTime. The returned value is an
- /// integer between 1 and 9999.
- /// </summary>
- public override int GetYear(DateTime time) => time.Year;
-
- internal override bool IsValidYear(int year, int era) => year >= 1 && year <= MaxYear;
-
- internal override bool IsValidDay(int year, int month, int day, int era)
- {
- if ((era != CurrentEra && era != ADEra) ||
- year < 1 || year > MaxYear ||
- month < 1 || month > 12 ||
- day < 1)
- {
- return false;
- }
-
- int[] days = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? DaysToMonth366 : DaysToMonth365;
- return day <= (days[month] - days[month - 1]);
- }
-
- /// <summary>
- /// Checks whether a given day in the specified era is a leap day. This method returns true if
- /// the date is a leap day, or false if not.
- /// </summary>
- public override bool IsLeapDay(int year, int month, int day, int era)
- {
- if (month < 1 || month > 12)
- {
- throw new ArgumentOutOfRangeException(
- nameof(month),
- month,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, 12));
- }
-
- if (era != CurrentEra && era != ADEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- if (year < 1 || year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxYear));
- }
- if (day < 1 || day > GetDaysInMonth(year, month))
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- day,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, GetDaysInMonth(year, month)));
- }
-
- return IsLeapYear(year) && month == 2 && day == 29;
- }
-
- /// <summary>
- /// Returns the leap month in a calendar year of the specified era.
- /// This method returns 0 if this calendar does not have leap month, or
- /// this year is not a leap year.
- /// </summary>
- public override int GetLeapMonth(int year, int era)
- {
- if (era != CurrentEra && era != ADEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- if (year < 1 || year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxYear));
- }
-
- return 0;
- }
-
- /// <summary>
- /// Checks whether a given month in the specified era is a leap month.
- /// This method returns true if month is a leap month, or false if not.
- /// </summary>
- public override bool IsLeapMonth(int year, int month, int era)
- {
- if (era != CurrentEra && era != ADEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- if (year < 1 || year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxYear));
- }
- if (month < 1 || month > 12)
- {
- throw new ArgumentOutOfRangeException(
- nameof(month),
- month,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, 12));
- }
-
- return false;
- }
-
- /// <summary>
- /// Checks whether a given year in the specified era is a leap year. This method returns true if
- /// year is a leap year, or false if not.
- /// </summary>
- public override bool IsLeapYear(int year, int era)
- {
- if (era != CurrentEra && era != ADEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- if (year < 1 || year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxYear));
- }
-
- return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
- }
-
- /// <summary>
- /// Returns the date and time converted to a DateTime value.
- /// Throws an exception if the n-tuple is invalid.
- /// </summary>
- public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- if (era != CurrentEra && era != ADEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
-
- return new DateTime(year, month, day, hour, minute, second, millisecond);
- }
-
- internal override bool TryToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era, out DateTime result)
- {
- if (era != CurrentEra && era != ADEra)
- {
- result = DateTime.MinValue;
- return false;
- }
-
- return DateTime.TryCreate(year, month, day, hour, minute, second, millisecond, out result);
- }
-
- private const int DefaultTwoDigitYearMax = 2029;
-
- public override int TwoDigitYearMax
- {
- get
- {
- if (_twoDigitYearMax == -1)
- {
- _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultTwoDigitYearMax);
- }
-
- return _twoDigitYearMax;
- }
- set
- {
- VerifyWritable();
- if (value < 99 || value > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 99, MaxYear));
- }
- _twoDigitYearMax = value;
- }
- }
-
- public override int ToFourDigitYear(int year)
- {
- if (year < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxYear));
- }
-
- return base.ToFourDigitYear(year);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendarHelper.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendarHelper.cs
deleted file mode 100644
index 589a8b662f0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendarHelper.cs
+++ /dev/null
@@ -1,660 +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.
-
-namespace System.Globalization
-{
- // Gregorian Calendars use Era Info
- internal class EraInfo
- {
- internal int era; // The value of the era.
- internal long ticks; // The time in ticks when the era starts
- internal int yearOffset; // The offset to Gregorian year when the era starts.
- // Gregorian Year = Era Year + yearOffset
- // Era Year = Gregorian Year - yearOffset
- internal int minEraYear; // Min year value in this era. Generally, this value is 1, but this may
- // be affected by the DateTime.MinValue;
- internal int maxEraYear; // Max year value in this era. (== the year length of the era + 1)
-
- internal string? eraName; // The era name
- internal string? abbrevEraName; // Abbreviated Era Name
- internal string? englishEraName; // English era name
-
- internal EraInfo(int era, int startYear, int startMonth, int startDay, int yearOffset, int minEraYear, int maxEraYear)
- {
- this.era = era;
- this.yearOffset = yearOffset;
- this.minEraYear = minEraYear;
- this.maxEraYear = maxEraYear;
- this.ticks = new DateTime(startYear, startMonth, startDay).Ticks;
- }
-
- internal EraInfo(int era, int startYear, int startMonth, int startDay, int yearOffset, int minEraYear, int maxEraYear,
- string eraName, string abbrevEraName, string englishEraName)
- {
- this.era = era;
- this.yearOffset = yearOffset;
- this.minEraYear = minEraYear;
- this.maxEraYear = maxEraYear;
- this.ticks = new DateTime(startYear, startMonth, startDay).Ticks;
- this.eraName = eraName;
- this.abbrevEraName = abbrevEraName;
- this.englishEraName = englishEraName;
- }
- }
-
- // This calendar recognizes two era values:
- // 0 CurrentEra (AD)
- // 1 BeforeCurrentEra (BC)
- internal class GregorianCalendarHelper
- {
- // 1 tick = 100ns = 10E-7 second
- // Number of ticks per time unit
- internal const long TicksPerMillisecond = 10000;
- internal const long TicksPerSecond = TicksPerMillisecond * 1000;
- internal const long TicksPerMinute = TicksPerSecond * 60;
- internal const long TicksPerHour = TicksPerMinute * 60;
- internal const long TicksPerDay = TicksPerHour * 24;
-
- // Number of milliseconds per time unit
- internal const int MillisPerSecond = 1000;
- internal const int MillisPerMinute = MillisPerSecond * 60;
- internal const int MillisPerHour = MillisPerMinute * 60;
- internal const int MillisPerDay = MillisPerHour * 24;
-
- // Number of days in a non-leap year
- internal const int DaysPerYear = 365;
- // Number of days in 4 years
- internal const int DaysPer4Years = DaysPerYear * 4 + 1;
- // Number of days in 100 years
- internal const int DaysPer100Years = DaysPer4Years * 25 - 1;
- // Number of days in 400 years
- internal const int DaysPer400Years = DaysPer100Years * 4 + 1;
-
- // Number of days from 1/1/0001 to 1/1/10000
- internal const int DaysTo10000 = DaysPer400Years * 25 - 366;
-
- internal const long MaxMillis = (long)DaysTo10000 * MillisPerDay;
-
- internal const int DatePartYear = 0;
- internal const int DatePartDayOfYear = 1;
- internal const int DatePartMonth = 2;
- internal const int DatePartDay = 3;
-
- //
- // This is the max Gregorian year can be represented by DateTime class. The limitation
- // is derived from DateTime class.
- //
- internal int MaxYear => m_maxYear;
-
- internal static readonly int[] DaysToMonth365 =
- {
- 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
- };
-
- internal static readonly int[] DaysToMonth366 =
- {
- 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366
- };
-
- internal int m_maxYear;
- internal int m_minYear;
- internal Calendar m_Cal;
-
- internal EraInfo[] m_EraInfo;
- internal int[]? m_eras = null;
-
- // Construct an instance of gregorian calendar.
- internal GregorianCalendarHelper(Calendar cal, EraInfo[] eraInfo)
- {
- m_Cal = cal;
- m_EraInfo = eraInfo;
- m_maxYear = m_EraInfo[0].maxEraYear;
- m_minYear = m_EraInfo[0].minEraYear;
- }
-
- // EraInfo.yearOffset: The offset to Gregorian year when the era starts. Gregorian Year = Era Year + yearOffset
- // Era Year = Gregorian Year - yearOffset
- // EraInfo.minEraYear: Min year value in this era. Generally, this value is 1, but this may be affected by the DateTime.MinValue;
- // EraInfo.maxEraYear: Max year value in this era. (== the year length of the era + 1)
- private int GetYearOffset(int year, int era, bool throwOnError)
- {
- if (year < 0)
- {
- if (throwOnError)
- {
- throw new ArgumentOutOfRangeException(nameof(year), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- return -1;
- }
-
- if (era == Calendar.CurrentEra)
- {
- era = m_Cal.CurrentEraValue;
- }
-
- for (int i = 0; i < m_EraInfo.Length; i++)
- {
- if (era == m_EraInfo[i].era)
- {
- if (year >= m_EraInfo[i].minEraYear)
- {
- if (year <= m_EraInfo[i].maxEraYear)
- {
- return m_EraInfo[i].yearOffset;
- }
- else if (!LocalAppContextSwitches.EnforceJapaneseEraYearRanges)
- {
- // If we got the year number exceeding the era max year number, this still possible be valid as the date can be created before
- // introducing new eras after the era we are checking. we'll loop on the eras after the era we have and ensure the year
- // can exist in one of these eras. otherwise, we'll throw.
- // Note, we always return the offset associated with the requested era.
- //
- // Here is some example:
- // if we are getting the era number 4 (Heisei) and getting the year number 32. if the era 4 has year range from 1 to 31
- // then year 32 exceeded the range of era 4 and we'll try to find out if the years difference (32 - 31 = 1) would lay in
- // the subsequent eras (e.g era 5 and up)
-
- int remainingYears = year - m_EraInfo[i].maxEraYear;
-
- for (int j = i - 1; j >= 0; j--)
- {
- if (remainingYears <= m_EraInfo[j].maxEraYear)
- {
- return m_EraInfo[i].yearOffset;
- }
- remainingYears -= m_EraInfo[j].maxEraYear;
- }
- }
- }
-
- if (throwOnError)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- SR.Format(
- SR.ArgumentOutOfRange_Range,
- m_EraInfo[i].minEraYear,
- m_EraInfo[i].maxEraYear));
- }
-
- break; // no need to iterate more on eras.
- }
- }
-
- if (throwOnError)
- {
- throw new ArgumentOutOfRangeException(nameof(era), SR.ArgumentOutOfRange_InvalidEraValue);
- }
- return -1;
- }
-
- /*=================================GetGregorianYear==========================
- **Action: Get the Gregorian year value for the specified year in an era.
- **Returns: The Gregorian year value.
- **Arguments:
- ** year the year value in Japanese calendar
- ** era the Japanese emperor era value.
- **Exceptions:
- ** ArgumentOutOfRangeException if year value is invalid or era value is invalid.
- ============================================================================*/
-
- internal int GetGregorianYear(int year, int era)
- {
- return GetYearOffset(year, era, throwOnError: true) + year;
- }
-
- internal bool IsValidYear(int year, int era)
- {
- return GetYearOffset(year, era, throwOnError: false) >= 0;
- }
-
- // Returns a given date part of this DateTime. This method is used
- // to compute the year, day-of-year, month, or day part.
- internal virtual int GetDatePart(long ticks, int part)
- {
- CheckTicksRange(ticks);
- // n = number of days since 1/1/0001
- int n = (int)(ticks / TicksPerDay);
- // y400 = number of whole 400-year periods since 1/1/0001
- int y400 = n / DaysPer400Years;
- // n = day number within 400-year period
- n -= y400 * DaysPer400Years;
- // y100 = number of whole 100-year periods within 400-year period
- int y100 = n / DaysPer100Years;
- // Last 100-year period has an extra day, so decrement result if 4
- if (y100 == 4) y100 = 3;
- // n = day number within 100-year period
- n -= y100 * DaysPer100Years;
- // y4 = number of whole 4-year periods within 100-year period
- int y4 = n / DaysPer4Years;
- // n = day number within 4-year period
- n -= y4 * DaysPer4Years;
- // y1 = number of whole years within 4-year period
- int y1 = n / DaysPerYear;
- // Last year has an extra day, so decrement result if 4
- if (y1 == 4) y1 = 3;
- // If year was requested, compute and return it
- if (part == DatePartYear)
- {
- return y400 * 400 + y100 * 100 + y4 * 4 + y1 + 1;
- }
- // n = day number within year
- n -= y1 * DaysPerYear;
- // If day-of-year was requested, return it
- if (part == DatePartDayOfYear)
- {
- return n + 1;
- }
- // Leap year calculation looks different from IsLeapYear since y1, y4,
- // and y100 are relative to year 1, not year 0
- bool leapYear = (y1 == 3 && (y4 != 24 || y100 == 3));
- int[] days = leapYear ? DaysToMonth366 : DaysToMonth365;
- // All months have less than 32 days, so n >> 5 is a good conservative
- // estimate for the month
- int m = (n >> 5) + 1;
- // m = 1-based month number
- while (n >= days[m]) m++;
- // If month was requested, return it
- if (part == DatePartMonth) return m;
- // Return 1-based day-of-month
- return n - days[m - 1] + 1;
- }
-
- /*=================================GetAbsoluteDate==========================
- **Action: Gets the absolute date for the given Gregorian date. The absolute date means
- ** the number of days from January 1st, 1 A.D.
- **Returns: the absolute date
- **Arguments:
- ** year the Gregorian year
- ** month the Gregorian month
- ** day the day
- **Exceptions:
- ** ArgumentOutOfRangException if year, month, day value is valid.
- **Note:
- ** This is an internal method used by DateToTicks() and the calculations of Hijri and Hebrew calendars.
- ** Number of Days in Prior Years (both common and leap years) +
- ** Number of Days in Prior Months of Current Year +
- ** Number of Days in Current Month
- **
- ============================================================================*/
-
- internal static long GetAbsoluteDate(int year, int month, int day)
- {
- if (year >= 1 && year <= 9999 && month >= 1 && month <= 12)
- {
- int[] days = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? DaysToMonth366 : DaysToMonth365;
- if (day >= 1 && (day <= days[month] - days[month - 1]))
- {
- int y = year - 1;
- int absoluteDate = y * 365 + y / 4 - y / 100 + y / 400 + days[month - 1] + day - 1;
- return absoluteDate;
- }
- }
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay);
- }
-
- // Returns the tick count corresponding to the given year, month, and day.
- // Will check the if the parameters are valid.
- internal static long DateToTicks(int year, int month, int day)
- {
- return GetAbsoluteDate(year, month, day) * TicksPerDay;
- }
-
- // Return the tick count corresponding to the given hour, minute, second.
- // Will check the if the parameters are valid.
- internal static long TimeToTicks(int hour, int minute, int second, int millisecond)
- {
- // TimeSpan.TimeToTicks is a family access function which does no error checking, so
- // we need to put some error checking out here.
- if (hour >= 0 && hour < 24 && minute >= 0 && minute < 60 && second >= 0 && second < 60)
- {
- if (millisecond < 0 || millisecond >= MillisPerSecond)
- {
- throw new ArgumentOutOfRangeException(
- nameof(millisecond),
- SR.Format(
- SR.ArgumentOutOfRange_Range,
- 0,
- MillisPerSecond - 1));
- }
- return InternalGlobalizationHelper.TimeToTicks(hour, minute, second) + millisecond * TicksPerMillisecond;
- }
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond);
- }
-
- internal void CheckTicksRange(long ticks)
- {
- if (ticks < m_Cal.MinSupportedDateTime.Ticks || ticks > m_Cal.MaxSupportedDateTime.Ticks)
- {
- throw new ArgumentOutOfRangeException(
- "time",
- SR.Format(
- CultureInfo.InvariantCulture,
- SR.ArgumentOutOfRange_CalendarRange,
- m_Cal.MinSupportedDateTime,
- m_Cal.MaxSupportedDateTime));
- }
- }
-
- // Returns the DateTime resulting from adding the given number of
- // months to the specified DateTime. The result is computed by incrementing
- // (or decrementing) the year and month parts of the specified DateTime by
- // value months, and, if required, adjusting the day part of the
- // resulting date downwards to the last day of the resulting month in the
- // resulting year. The time-of-day part of the result is the same as the
- // time-of-day part of the specified DateTime.
- //
- // In more precise terms, considering the specified DateTime to be of the
- // form y / m / d + t, where y is the
- // year, m is the month, d is the day, and t is the
- // time-of-day, the result is y1 / m1 / d1 + t,
- // where y1 and m1 are computed by adding value months
- // to y and m, and d1 is the largest value less than
- // or equal to d that denotes a valid day in month m1 of year
- // y1.
- //
- public DateTime AddMonths(DateTime time, int months)
- {
- if (months < -120000 || months > 120000)
- {
- throw new ArgumentOutOfRangeException(
- nameof(months),
- SR.Format(
- SR.ArgumentOutOfRange_Range,
- -120000,
- 120000));
- }
- CheckTicksRange(time.Ticks);
-
- int y = GetDatePart(time.Ticks, DatePartYear);
- int m = GetDatePart(time.Ticks, DatePartMonth);
- int d = GetDatePart(time.Ticks, DatePartDay);
- int i = m - 1 + months;
- if (i >= 0)
- {
- m = i % 12 + 1;
- y += i / 12;
- }
- else
- {
- m = 12 + (i + 1) % 12;
- y += (i - 11) / 12;
- }
- int[] daysArray = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) ? DaysToMonth366 : DaysToMonth365;
- int days = (daysArray[m] - daysArray[m - 1]);
-
- if (d > days)
- {
- d = days;
- }
- long ticks = DateToTicks(y, m, d) + (time.Ticks % TicksPerDay);
- Calendar.CheckAddResult(ticks, m_Cal.MinSupportedDateTime, m_Cal.MaxSupportedDateTime);
- return new DateTime(ticks);
- }
-
- // Returns the DateTime resulting from adding the given number of
- // years to the specified DateTime. The result is computed by incrementing
- // (or decrementing) the year part of the specified DateTime by value
- // years. If the month and day of the specified DateTime is 2/29, and if the
- // resulting year is not a leap year, the month and day of the resulting
- // DateTime becomes 2/28. Otherwise, the month, day, and time-of-day
- // parts of the result are the same as those of the specified DateTime.
- //
- public DateTime AddYears(DateTime time, int years)
- {
- return AddMonths(time, years * 12);
- }
-
- // Returns the day-of-month part of the specified DateTime. The returned
- // value is an integer between 1 and 31.
- //
- public int GetDayOfMonth(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartDay);
- }
-
- // Returns the day-of-week part of the specified DateTime. The returned value
- // is an integer between 0 and 6, where 0 indicates Sunday, 1 indicates
- // Monday, 2 indicates Tuesday, 3 indicates Wednesday, 4 indicates
- // Thursday, 5 indicates Friday, and 6 indicates Saturday.
- //
- public DayOfWeek GetDayOfWeek(DateTime time)
- {
- CheckTicksRange(time.Ticks);
- return (DayOfWeek)((time.Ticks / TicksPerDay + 1) % 7);
- }
-
- // Returns the day-of-year part of the specified DateTime. The returned value
- // is an integer between 1 and 366.
- //
- public int GetDayOfYear(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartDayOfYear);
- }
-
- // Returns the number of days in the month given by the year and
- // month arguments.
- //
- public int GetDaysInMonth(int year, int month, int era)
- {
- //
- // Convert year/era value to Gregorain year value.
- //
- year = GetGregorianYear(year, era);
- if (month < 1 || month > 12)
- {
- throw new ArgumentOutOfRangeException(nameof(month), SR.ArgumentOutOfRange_Month);
- }
- int[] days = ((year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? DaysToMonth366 : DaysToMonth365);
- return days[month] - days[month - 1];
- }
-
- // Returns the number of days in the year given by the year argument for the current era.
- //
-
- public int GetDaysInYear(int year, int era)
- {
- //
- // Convert year/era value to Gregorain year value.
- //
- year = GetGregorianYear(year, era);
- return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 366 : 365;
- }
-
- // Returns the era for the specified DateTime value.
- public int GetEra(DateTime time)
- {
- long ticks = time.Ticks;
- // The assumption here is that m_EraInfo is listed in reverse order.
- for (int i = 0; i < m_EraInfo.Length; i++)
- {
- if (ticks >= m_EraInfo[i].ticks)
- {
- return m_EraInfo[i].era;
- }
- }
- throw new ArgumentOutOfRangeException(nameof(time), SR.ArgumentOutOfRange_Era);
- }
-
- public int[] Eras
- {
- get
- {
- if (m_eras == null)
- {
- m_eras = new int[m_EraInfo.Length];
- for (int i = 0; i < m_EraInfo.Length; i++)
- {
- m_eras[i] = m_EraInfo[i].era;
- }
- }
- return (int[])m_eras.Clone();
- }
- }
-
- // Returns the month part of the specified DateTime. The returned value is an
- // integer between 1 and 12.
- //
- public int GetMonth(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartMonth);
- }
-
- // Returns the number of months in the specified year and era.
- // Always return 12.
- public int GetMonthsInYear(int year, int era)
- {
- ValidateYearInEra(year, era);
- return 12;
- }
-
- // Returns the year part of the specified DateTime. The returned value is an
- // integer between 1 and 9999.
- //
- public int GetYear(DateTime time)
- {
- long ticks = time.Ticks;
- int year = GetDatePart(ticks, DatePartYear);
- for (int i = 0; i < m_EraInfo.Length; i++)
- {
- if (ticks >= m_EraInfo[i].ticks)
- {
- return year - m_EraInfo[i].yearOffset;
- }
- }
- throw new ArgumentException(SR.Argument_NoEra);
- }
-
- // Returns the year that match the specified Gregorian year. The returned value is an
- // integer between 1 and 9999.
- //
- public int GetYear(int year, DateTime time)
- {
- long ticks = time.Ticks;
- for (int i = 0; i < m_EraInfo.Length; i++)
- {
- // while calculating dates with JapaneseLuniSolarCalendar, we can run into cases right after the start of the era
- // and still belong to the month which is started in previous era. Calculating equivalent calendar date will cause
- // using the new era info which will have the year offset equal to the year we are calculating year = m_EraInfo[i].yearOffset
- // which will end up with zero as calendar year.
- // We should use the previous era info instead to get the right year number. Example of such date is Feb 2nd 1989
- if (ticks >= m_EraInfo[i].ticks && year > m_EraInfo[i].yearOffset)
- {
- return year - m_EraInfo[i].yearOffset;
- }
- }
- throw new ArgumentException(SR.Argument_NoEra);
- }
-
- // Checks whether a given day in the specified era is a leap day. This method returns true if
- // the date is a leap day, or false if not.
- //
- public bool IsLeapDay(int year, int month, int day, int era)
- {
- // year/month/era checking is done in GetDaysInMonth()
- if (day < 1 || day > GetDaysInMonth(year, month, era))
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- SR.Format(
- SR.ArgumentOutOfRange_Range,
- 1,
- GetDaysInMonth(year, month, era)));
- }
-
- if (!IsLeapYear(year, era))
- {
- return false;
- }
-
- if (month == 2 && day == 29)
- {
- return true;
- }
-
- return false;
- }
-
- // Giving the calendar year and era, ValidateYearInEra will validate the existence of the input year in the input era.
- // This method will throw if the year or the era is invalid.
- public void ValidateYearInEra(int year, int era) => GetYearOffset(year, era, throwOnError: true);
-
- // Returns the leap month in a calendar year of the specified era.
- // This method always returns 0 as all calendars using this method don't have leap months.
- public int GetLeapMonth(int year, int era)
- {
- ValidateYearInEra(year, era);
- return 0;
- }
-
- // Checks whether a given month in the specified era is a leap month.
- // This method always returns false as all calendars using this method don't have leap months.
- public bool IsLeapMonth(int year, int month, int era)
- {
- ValidateYearInEra(year, era);
- if (month < 1 || month > 12)
- {
- throw new ArgumentOutOfRangeException(
- nameof(month),
- SR.Format(
- SR.ArgumentOutOfRange_Range,
- 1,
- 12));
- }
- return false;
- }
-
- // Checks whether a given year in the specified era is a leap year. This method returns true if
- // year is a leap year, or false if not.
- //
- public bool IsLeapYear(int year, int era)
- {
- year = GetGregorianYear(year, era);
- return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
- }
-
- // Returns the date and time converted to a DateTime value. Throws an exception if the n-tuple is invalid.
- //
- public DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- year = GetGregorianYear(year, era);
- long ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second, millisecond);
- CheckTicksRange(ticks);
- return new DateTime(ticks);
- }
-
- public virtual int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
- {
- CheckTicksRange(time.Ticks);
- // Use GregorianCalendar to get around the problem that the implmentation in Calendar.GetWeekOfYear()
- // can call GetYear() that exceeds the supported range of the Gregorian-based calendars.
- return GregorianCalendar.GetDefaultInstance().GetWeekOfYear(time, rule, firstDayOfWeek);
- }
-
- public int ToFourDigitYear(int year, int twoDigitYearMax)
- {
- if (year < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year),
- SR.ArgumentOutOfRange_NeedPosNum);
- }
-
- if (year < 100)
- {
- int y = year % 100;
- return (twoDigitYearMax / 100 - (y > twoDigitYearMax % 100 ? 1 : 0)) * 100 + y;
- }
-
- if (year < m_minYear || year > m_maxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- SR.Format(SR.ArgumentOutOfRange_Range, m_minYear, m_maxYear));
- }
- // If the year value is above 100, just return the year value. Don't have to do
- // the TwoDigitYearMax comparison.
- return year;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendarTypes.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendarTypes.cs
deleted file mode 100644
index 46f13b00e06..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/GregorianCalendarTypes.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Globalization
-{
- // Note: The values of the members of this enum must match the coresponding values
- // in the CalendarId enum (since we cast between GregorianCalendarTypes and CalendarId).
- public enum GregorianCalendarTypes
- {
- Localized = CalendarId.GREGORIAN,
- USEnglish = CalendarId.GREGORIAN_US,
- MiddleEastFrench = CalendarId.GREGORIAN_ME_FRENCH,
- Arabic = CalendarId.GREGORIAN_ARABIC,
- TransliteratedEnglish = CalendarId.GREGORIAN_XLIT_ENGLISH,
- TransliteratedFrench = CalendarId.GREGORIAN_XLIT_FRENCH,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/HebrewCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/HebrewCalendar.cs
deleted file mode 100644
index 477c1ed8d93..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/HebrewCalendar.cs
+++ /dev/null
@@ -1,904 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- /// <remarks>
- /// Rules for the Hebrew calendar:
- /// - The Hebrew calendar is both a Lunar (months) and Solar (years)
- /// calendar, but allows for a week of seven days.
- /// - Days begin at sunset.
- /// - Leap Years occur in the 3, 6, 8, 11, 14, 17, &amp; 19th years of a
- /// 19-year cycle. Year = leap iff ((7y+1) mod 19 &lt; 7).
- /// - There are 12 months in a common year and 13 months in a leap year.
- /// - In a common year, the 6th month, Adar, has 29 days. In a leap
- /// year, the 6th month, Adar I, has 30 days and the leap month,
- /// Adar II, has 29 days.
- /// - Common years have 353-355 days. Leap years have 383-385 days.
- /// - The Hebrew new year (Rosh HaShanah) begins on the 1st of Tishri,
- /// the 7th month in the list below.
- /// - The new year may not begin on Sunday, Wednesday, or Friday.
- /// - If the new year would fall on a Tuesday and the conjunction of
- /// the following year were at midday or later, the new year is
- /// delayed until Thursday.
- /// - If the new year would fall on a Monday after a leap year, the
- /// new year is delayed until Tuesday.
- /// - The length of the 8th and 9th months vary from year to year,
- /// depending on the overall length of the year.
- /// - The length of a year is determined by the dates of the new
- /// years (Tishri 1) preceding and following the year in question.
- /// - The 2th month is long (30 days) if the year has 355 or 385 days.
- /// - The 3th month is short (29 days) if the year has 353 or 383 days.
- /// - The Hebrew months are:
- /// 1. Tishri (30 days)
- /// 2. Heshvan (29 or 30 days)
- /// 3. Kislev (29 or 30 days)
- /// 4. Teveth (29 days)
- /// 5. Shevat (30 days)
- /// 6. Adar I (30 days)
- /// 7. Adar {II} (29 days, this only exists if that year is a leap year)
- /// 8. Nisan (30 days)
- /// 9. Iyyar (29 days)
- /// 10. Sivan (30 days)
- /// 11. Tammuz (29 days)
- /// 12. Av (30 days)
- /// 13. Elul (29 days)
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 1583/01/01 2239/09/29
- /// Hebrew 5343/04/07 5999/13/29
- ///
- /// Includes CHebrew implemetation;i.e All the code necessary for converting
- /// Gregorian to Hebrew Lunar from 1583 to 2239.
- /// </remarks>
- public class HebrewCalendar : Calendar
- {
- public static readonly int HebrewEra = 1;
-
- private const int DatePartYear = 0;
- private const int DatePartMonth = 2;
- private const int DatePartDay = 3;
-
- // Hebrew Translation Table.
- //
- // This table is used to get the following Hebrew calendar information for a
- // given Gregorian year:
- // 1. The day of the Hebrew month corresponding to Gregorian January 1st
- // for a given Gregorian year.
- // 2. The month of the Hebrew month corresponding to Gregorian January 1st
- // for a given Gregorian year.
- // The information is not directly in the table. Instead, the info is decoded
- // by special values (numbers above 29 and below 1).
- // 3. The type of the Hebrew year for a given Gregorian year.
- //
- // More notes:
- // This table includes 2 numbers for each year.
- // The offset into the table determines the year. (offset 0 is Gregorian year 1500)
- // 1st number determines the day of the Hebrew month coresponeds to January 1st.
- // 2nd number determines the type of the Hebrew year. (the type determines how
- // many days are there in the year.)
- //
- // normal years : 1 = 353 days 2 = 354 days 3 = 355 days.
- // Leap years : 4 = 383 5 384 6 = 385 days.
- //
- // A 99 means the year is not supported for translation.
- // for convenience the table was defined for 750 year,
- // but only 640 years are supported. (from 1583 to 2239)
- // the years before 1582 (starting of Georgian calendar)
- // and after 2239, are filled with 99.
- //
- // Greogrian January 1st falls usually in Tevet (4th month). Tevet has always 29 days.
- // That's why, there no nead to specify the lunar month in the table.
- // There are exceptions, these are coded by giving numbers above 29 and below 1.
- // Actual decoding is takenig place whenever fetching information from the table.
- // The function for decoding is in GetLunarMonthDay().
- //
- // Example:
- // The data for 2000 - 2005 A.D. is:
- // 23,6,6,1,17,2,27,6,7,3, // 2000 - 2004
- //
- // For year 2000, we know it has a Hebrew year type 6, which means it has 385 days.
- // And 1/1/2000 A.D. is Hebrew year 5760, 23rd day of 4th month.
- //
- // Jewish Era in use today is dated from the supposed year of the
- // Creation with its beginning in 3761 B.C.
- //
- // The Hebrew year of Gregorian 1st year AD.
- // 0001/01/01 AD is Hebrew 3760/01/01
- private const int HebrewYearOf1AD = 3760;
-
- private const int FirstGregorianTableYear = 1583; // == Hebrew Year 5343
- private const int LastGregorianTableYear = 2239; // == Hebrew Year 5999
-
- private const int TableSize = (LastGregorianTableYear - FirstGregorianTableYear);
-
- private const int MinHebrewYear = HebrewYearOf1AD + FirstGregorianTableYear; // == 5343
- private const int MaxHebrewYear = HebrewYearOf1AD + LastGregorianTableYear; // == 5999
-
- private static ReadOnlySpan<byte> HebrewTable => new byte[] // rely on C# compiler optimization to reference static data
- {
- 7, 3, 17, 3, // 1583-1584 (Hebrew year: 5343 - 5344)
- 0, 4, 11, 2, 21, 6, 1, 3, 13, 2, // 1585-1589
- 25, 4, 5, 3, 16, 2, 27, 6, 9, 1, // 1590-1594
- 20, 2, 0, 6, 11, 3, 23, 4, 4, 2, // 1595-1599
- 14, 3, 27, 4, 8, 2, 18, 3, 28, 6, // 1600
- 11, 1, 22, 5, 2, 3, 12, 3, 25, 4, // 1605
- 6, 2, 16, 3, 26, 6, 8, 2, 20, 1, // 1610
- 0, 6, 11, 2, 24, 4, 4, 3, 15, 2, // 1615
- 25, 6, 8, 1, 19, 2, 29, 6, 9, 3, // 1620
- 22, 4, 3, 2, 13, 3, 25, 4, 6, 3, // 1625
- 17, 2, 27, 6, 7, 3, 19, 2, 31, 4, // 1630
- 11, 3, 23, 4, 5, 2, 15, 3, 25, 6, // 1635
- 6, 2, 19, 1, 29, 6, 10, 2, 22, 4, // 1640
- 3, 3, 14, 2, 24, 6, 6, 1, 17, 3, // 1645
- 28, 5, 8, 3, 20, 1, 32, 5, 12, 3, // 1650
- 22, 6, 4, 1, 16, 2, 26, 6, 6, 3, // 1655
- 17, 2, 0, 4, 10, 3, 22, 4, 3, 2, // 1660
- 14, 3, 24, 6, 5, 2, 17, 1, 28, 6, // 1665
- 9, 2, 19, 3, 31, 4, 13, 2, 23, 6, // 1670
- 3, 3, 15, 1, 27, 5, 7, 3, 17, 3, // 1675
- 29, 4, 11, 2, 21, 6, 3, 1, 14, 2, // 1680
- 25, 6, 5, 3, 16, 2, 28, 4, 9, 3, // 1685
- 20, 2, 0, 6, 12, 1, 23, 6, 4, 2, // 1690
- 14, 3, 26, 4, 8, 2, 18, 3, 0, 4, // 1695
- 10, 3, 21, 5, 1, 3, 13, 1, 24, 5, // 1700
- 5, 3, 15, 3, 27, 4, 8, 2, 19, 3, // 1705
- 29, 6, 10, 2, 22, 4, 3, 3, 14, 2, // 1710
- 26, 4, 6, 3, 18, 2, 28, 6, 10, 1, // 1715
- 20, 6, 2, 2, 12, 3, 24, 4, 5, 2, // 1720
- 16, 3, 28, 4, 8, 3, 19, 2, 0, 6, // 1725
- 12, 1, 23, 5, 3, 3, 14, 3, 26, 4, // 1730
- 7, 2, 17, 3, 28, 6, 9, 2, 21, 4, // 1735
- 1, 3, 13, 2, 25, 4, 5, 3, 16, 2, // 1740
- 27, 6, 9, 1, 19, 3, 0, 5, 11, 3, // 1745
- 23, 4, 4, 2, 14, 3, 25, 6, 7, 1, // 1750
- 18, 2, 28, 6, 9, 3, 21, 4, 2, 2, // 1755
- 12, 3, 25, 4, 6, 2, 16, 3, 26, 6, // 1760
- 8, 2, 20, 1, 0, 6, 11, 2, 22, 6, // 1765
- 4, 1, 15, 2, 25, 6, 6, 3, 18, 1, // 1770
- 29, 5, 9, 3, 22, 4, 2, 3, 13, 2, // 1775
- 23, 6, 4, 3, 15, 2, 27, 4, 7, 3, // 1780
- 19, 2, 31, 4, 11, 3, 21, 6, 3, 2, // 1785
- 15, 1, 25, 6, 6, 2, 17, 3, 29, 4, // 1790
- 10, 2, 20, 6, 3, 1, 13, 3, 24, 5, // 1795
- 4, 3, 16, 1, 27, 5, 7, 3, 17, 3, // 1800
- 0, 4, 11, 2, 21, 6, 1, 3, 13, 2, // 1805
- 25, 4, 5, 3, 16, 2, 29, 4, 9, 3, // 1810
- 19, 6, 30, 2, 13, 1, 23, 6, 4, 2, // 1815
- 14, 3, 27, 4, 8, 2, 18, 3, 0, 4, // 1820
- 11, 3, 22, 5, 2, 3, 14, 1, 26, 5, // 1825
- 6, 3, 16, 3, 28, 4, 10, 2, 20, 6, // 1830
- 30, 3, 11, 2, 24, 4, 4, 3, 15, 2, // 1835
- 25, 6, 8, 1, 19, 2, 29, 6, 9, 3, // 1840
- 22, 4, 3, 2, 13, 3, 25, 4, 7, 2, // 1845
- 17, 3, 27, 6, 9, 1, 21, 5, 1, 3, // 1850
- 11, 3, 23, 4, 5, 2, 15, 3, 25, 6, // 1855
- 6, 2, 19, 1, 29, 6, 10, 2, 22, 4, // 1860
- 3, 3, 14, 2, 24, 6, 6, 1, 18, 2, // 1865
- 28, 6, 8, 3, 20, 4, 2, 2, 12, 3, // 1870
- 24, 4, 4, 3, 16, 2, 26, 6, 6, 3, // 1875
- 17, 2, 0, 4, 10, 3, 22, 4, 3, 2, // 1880
- 14, 3, 24, 6, 5, 2, 17, 1, 28, 6, // 1885
- 9, 2, 21, 4, 1, 3, 13, 2, 23, 6, // 1890
- 5, 1, 15, 3, 27, 5, 7, 3, 19, 1, // 1895
- 0, 5, 10, 3, 22, 4, 2, 3, 13, 2, // 1900
- 24, 6, 4, 3, 15, 2, 27, 4, 8, 3, // 1905
- 20, 4, 1, 2, 11, 3, 22, 6, 3, 2, // 1910
- 15, 1, 25, 6, 7, 2, 17, 3, 29, 4, // 1915
- 10, 2, 21, 6, 1, 3, 13, 1, 24, 5, // 1920
- 5, 3, 15, 3, 27, 4, 8, 2, 19, 6, // 1925
- 1, 1, 12, 2, 22, 6, 3, 3, 14, 2, // 1930
- 26, 4, 6, 3, 18, 2, 28, 6, 10, 1, // 1935
- 20, 6, 2, 2, 12, 3, 24, 4, 5, 2, // 1940
- 16, 3, 28, 4, 9, 2, 19, 6, 30, 3, // 1945
- 12, 1, 23, 5, 3, 3, 14, 3, 26, 4, // 1950
- 7, 2, 17, 3, 28, 6, 9, 2, 21, 4, // 1955
- 1, 3, 13, 2, 25, 4, 5, 3, 16, 2, // 1960
- 27, 6, 9, 1, 19, 6, 30, 2, 11, 3, // 1965
- 23, 4, 4, 2, 14, 3, 27, 4, 7, 3, // 1970
- 18, 2, 28, 6, 11, 1, 22, 5, 2, 3, // 1975
- 12, 3, 25, 4, 6, 2, 16, 3, 26, 6, // 1980
- 8, 2, 20, 4, 30, 3, 11, 2, 24, 4, // 1985
- 4, 3, 15, 2, 25, 6, 8, 1, 18, 3, // 1990
- 29, 5, 9, 3, 22, 4, 3, 2, 13, 3, // 1995
- 23, 6, 6, 1, 17, 2, 27, 6, 7, 3, // 2000 - 2004
- 20, 4, 1, 2, 11, 3, 23, 4, 5, 2, // 2005 - 2009
- 15, 3, 25, 6, 6, 2, 19, 1, 29, 6, // 2010
- 10, 2, 20, 6, 3, 1, 14, 2, 24, 6, // 2015
- 4, 3, 17, 1, 28, 5, 8, 3, 20, 4, // 2020
- 1, 3, 12, 2, 22, 6, 2, 3, 14, 2, // 2025
- 26, 4, 6, 3, 17, 2, 0, 4, 10, 3, // 2030
- 20, 6, 1, 2, 14, 1, 24, 6, 5, 2, // 2035
- 15, 3, 28, 4, 9, 2, 19, 6, 1, 1, // 2040
- 12, 3, 23, 5, 3, 3, 15, 1, 27, 5, // 2045
- 7, 3, 17, 3, 29, 4, 11, 2, 21, 6, // 2050
- 1, 3, 12, 2, 25, 4, 5, 3, 16, 2, // 2055
- 28, 4, 9, 3, 19, 6, 30, 2, 12, 1, // 2060
- 23, 6, 4, 2, 14, 3, 26, 4, 8, 2, // 2065
- 18, 3, 0, 4, 10, 3, 22, 5, 2, 3, // 2070
- 14, 1, 25, 5, 6, 3, 16, 3, 28, 4, // 2075
- 9, 2, 20, 6, 30, 3, 11, 2, 23, 4, // 2080
- 4, 3, 15, 2, 27, 4, 7, 3, 19, 2, // 2085
- 29, 6, 11, 1, 21, 6, 3, 2, 13, 3, // 2090
- 25, 4, 6, 2, 17, 3, 27, 6, 9, 1, // 2095
- 20, 5, 30, 3, 10, 3, 22, 4, 3, 2, // 2100
- 14, 3, 24, 6, 5, 2, 17, 1, 28, 6, // 2105
- 9, 2, 21, 4, 1, 3, 13, 2, 23, 6, // 2110
- 5, 1, 16, 2, 27, 6, 7, 3, 19, 4, // 2115
- 30, 2, 11, 3, 23, 4, 3, 3, 14, 2, // 2120
- 25, 6, 5, 3, 16, 2, 28, 4, 9, 3, // 2125
- 21, 4, 2, 2, 12, 3, 23, 6, 4, 2, // 2130
- 16, 1, 26, 6, 8, 2, 20, 4, 30, 3, // 2135
- 11, 2, 22, 6, 4, 1, 14, 3, 25, 5, // 2140
- 6, 3, 18, 1, 29, 5, 9, 3, 22, 4, // 2145
- 2, 3, 13, 2, 23, 6, 4, 3, 15, 2, // 2150
- 27, 4, 7, 3, 20, 4, 1, 2, 11, 3, // 2155
- 21, 6, 3, 2, 15, 1, 25, 6, 6, 2, // 2160
- 17, 3, 29, 4, 10, 2, 20, 6, 3, 1, // 2165
- 13, 3, 24, 5, 4, 3, 17, 1, 28, 5, // 2170
- 8, 3, 18, 6, 1, 1, 12, 2, 22, 6, // 2175
- 2, 3, 14, 2, 26, 4, 6, 3, 17, 2, // 2180
- 28, 6, 10, 1, 20, 6, 1, 2, 12, 3, // 2185
- 24, 4, 5, 2, 15, 3, 28, 4, 9, 2, // 2190
- 19, 6, 33, 3, 12, 1, 23, 5, 3, 3, // 2195
- 13, 3, 25, 4, 6, 2, 16, 3, 26, 6, // 2200
- 8, 2, 20, 4, 30, 3, 11, 2, 24, 4, // 2205
- 4, 3, 15, 2, 25, 6, 8, 1, 18, 6, // 2210
- 33, 2, 9, 3, 22, 4, 3, 2, 13, 3, // 2215
- 25, 4, 6, 3, 17, 2, 27, 6, 9, 1, // 2220
- 21, 5, 1, 3, 11, 3, 23, 4, 5, 2, // 2225
- 15, 3, 25, 6, 6, 2, 19, 4, 33, 3, // 2230
- 10, 2, 22, 4, 3, 3, 14, 2, 24, 6, // 2235
- 6, 1 // 2240 (Hebrew year: 6000)
- };
-
- private const int MaxMonthPlusOne = 14;
-
- // The lunar calendar has 6 different variations of month lengths
- // within a year.
- private static ReadOnlySpan<byte> LunarMonthLen => new byte[] // rely on C# compiler optimization to reference static data
- {
- 0, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0,
- 0, 30, 29, 29, 29, 30, 29, 30, 29, 30, 29, 30, 29, 0, // 3 common year variations
- 0, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 0,
- 0, 30, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 0,
- 0, 30, 29, 29, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, // 3 leap year variations
- 0, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29,
- 0, 30, 30, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29
- };
-
- private static readonly DateTime s_calendarMinValue = new DateTime(1583, 1, 1);
-
- // Gregorian 2239/9/29 = Hebrew 5999/13/29 (last day in Hebrew year 5999).
- // We can only format/parse Hebrew numbers up to 999, so we limit the max range to Hebrew year 5999.
- private static readonly DateTime s_calendarMaxValue = new DateTime((new DateTime(2239, 9, 29, 23, 59, 59, 999)).Ticks + 9999);
-
- public override DateTime MinSupportedDateTime => s_calendarMinValue;
-
- public override DateTime MaxSupportedDateTime => s_calendarMaxValue;
-
- public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.LunisolarCalendar;
-
- public HebrewCalendar()
- {
- }
-
- internal override CalendarId ID => CalendarId.HEBREW;
-
- private static void CheckHebrewYearValue(int y, int era, string varName)
- {
- CheckEraRange(era);
- if (y > MaxHebrewYear || y < MinHebrewYear)
- {
- throw new ArgumentOutOfRangeException(
- varName,
- y,
- SR.Format(SR.ArgumentOutOfRange_Range, MinHebrewYear, MaxHebrewYear));
- }
- }
-
- /// <summary>
- /// Check if the Hebrew month value is valid.
- /// </summary>
- /// <remarks>
- /// Call CheckHebrewYearValue() before calling this to verify the year value is supported.
- /// </remarks>
- private void CheckHebrewMonthValue(int year, int month, int era)
- {
- int monthsInYear = GetMonthsInYear(year, era);
- if (month < 1 || month > monthsInYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(month),
- month,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, monthsInYear));
- }
- }
-
- /// <summary>
- /// Check if the Hebrew day value is valid.
- /// </summary>
- /// <remarks>
- /// Call CheckHebrewYearValue()/CheckHebrewMonthValue() before calling this to verify the year/month values are valid.
- /// </remarks>
- private void CheckHebrewDayValue(int year, int month, int day, int era)
- {
- int daysInMonth = GetDaysInMonth(year, month, era);
- if (day < 1 || day > daysInMonth)
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- day,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, daysInMonth));
- }
- }
-
- private static void CheckEraRange(int era)
- {
- if (era != CurrentEra && era != HebrewEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- }
-
- private static void CheckTicksRange(long ticks)
- {
- if (ticks < s_calendarMinValue.Ticks || ticks > s_calendarMaxValue.Ticks)
- {
- throw new ArgumentOutOfRangeException(
- "time",
- ticks,
- // Print out the date in Gregorian using InvariantCulture since the DateTime is based on GreograinCalendar.
- SR.Format(
- CultureInfo.InvariantCulture,
- SR.ArgumentOutOfRange_CalendarRange,
- s_calendarMinValue,
- s_calendarMaxValue));
- }
- }
-
- private static int GetResult(DateBuffer result, int part)
- {
- return part switch
- {
- DatePartYear => result.year,
- DatePartMonth => result.month,
- DatePartDay => result.day,
- _ => throw new InvalidOperationException(SR.InvalidOperation_DateTimeParsing),
- };
- }
-
- /// <summary>
- /// Using the Hebrew table (HebrewTable) to get the Hebrew month/day value for Gregorian January 1st
- /// in a given Gregorian year.
- /// Greogrian January 1st falls usually in Tevet (4th month). Tevet has always 29 days.
- /// That's why, there no nead to specify the lunar month in the table. There are exceptions, and these
- /// are coded by giving numbers above 29 and below 1.
- /// Actual decoding is takenig place in the switch statement below.
- /// </summary>
- /// <returns>
- /// The Hebrew year type. The value is from 1 to 6.
- /// normal years : 1 = 353 days 2 = 354 days 3 = 355 days.
- /// Leap years : 4 = 383 5 384 6 = 385 days.
- /// </returns>
- internal static int GetLunarMonthDay(int gregorianYear, DateBuffer lunarDate)
- {
- // Get the offset into the LunarMonthLen array and the lunar day
- // for January 1st.
- int index = gregorianYear - FirstGregorianTableYear;
- if (index < 0 || index > TableSize)
- {
- throw new ArgumentOutOfRangeException(nameof(gregorianYear));
- }
-
- index *= 2;
- lunarDate.day = HebrewTable[index];
-
- // Get the type of the year. The value is from 1 to 6
- int lunarYearType = HebrewTable[index + 1];
-
- // Get the Lunar Month.
- switch (lunarDate.day)
- {
- case 0: // 1/1 is on Shvat 1
- lunarDate.month = 5;
- lunarDate.day = 1;
- break;
- case 30: // 1/1 is on Kislev 30
- lunarDate.month = 3;
- break;
- case 31: // 1/1 is on Shvat 2
- lunarDate.month = 5;
- lunarDate.day = 2;
- break;
- case 32: // 1/1 is on Shvat 3
- lunarDate.month = 5;
- lunarDate.day = 3;
- break;
- case 33: // 1/1 is on Kislev 29
- lunarDate.month = 3;
- lunarDate.day = 29;
- break;
- default: // 1/1 is on Tevet (This is the general case)
- lunarDate.month = 4;
- break;
- }
-
- return lunarYearType;
- }
-
- /// <summary>
- /// Returns a given date part of this DateTime. This method is used
- /// to compute the year, day-of-year, month, or day part.
- /// </summary>
- internal virtual int GetDatePart(long ticks, int part)
- {
- // The Gregorian year, month, day value for ticks.
- int gregorianYear, gregorianMonth, gregorianDay;
- int hebrewYearType; // lunar year type
- long AbsoluteDate; // absolute date - absolute date 1/1/1600
-
- // Make sure we have a valid Gregorian date that will fit into our
- // Hebrew conversion limits.
- CheckTicksRange(ticks);
-
- DateTime time = new DateTime(ticks);
-
- // Save the Gregorian date values.
- time.GetDatePart(out gregorianYear, out gregorianMonth, out gregorianDay);
-
- DateBuffer lunarDate = new DateBuffer(); // lunar month and day for Jan 1
-
- // From the table looking-up value of HebrewTable[index] (stored in lunarDate.day), we get the
- // lunar month and lunar day where the Gregorian date 1/1 falls.
- lunarDate.year = gregorianYear + HebrewYearOf1AD;
- hebrewYearType = GetLunarMonthDay(gregorianYear, lunarDate);
-
- // This is the buffer used to store the result Hebrew date.
- DateBuffer result = new DateBuffer();
-
- // Store the values for the start of the new year - 1/1.
- result.year = lunarDate.year;
- result.month = lunarDate.month;
- result.day = lunarDate.day;
-
- // Get the absolute date from 1/1/1600.
- AbsoluteDate = GregorianCalendar.GetAbsoluteDate(gregorianYear, gregorianMonth, gregorianDay);
-
- // If the requested date was 1/1, then we're done.
- if ((gregorianMonth == 1) && (gregorianDay == 1))
- {
- return GetResult(result, part);
- }
-
- // Calculate the number of days between 1/1 and the requested date.
- long numDays = AbsoluteDate - GregorianCalendar.GetAbsoluteDate(gregorianYear, 1, 1);
-
- // If the requested date is within the current lunar month, then
- // we're done.
- if ((numDays + (long)lunarDate.day) <= (long)(LunarMonthLen[hebrewYearType * MaxMonthPlusOne + lunarDate.month]))
- {
- result.day += (int)numDays;
- return GetResult(result, part);
- }
-
- // Adjust for the current partial month.
- result.month++;
- result.day = 1;
-
- // Adjust the Lunar Month and Year (if necessary) based on the number
- // of days between 1/1 and the requested date.
- // Assumes Jan 1 can never translate to the last Lunar month, which
- // is true.
- numDays -= (long)(LunarMonthLen[hebrewYearType * MaxMonthPlusOne + lunarDate.month] - lunarDate.day);
- Debug.Assert(numDays >= 1, "NumDays >= 1");
-
- // If NumDays is 1, then we are done. Otherwise, find the correct Hebrew month
- // and day.
- if (numDays > 1)
- {
- // See if we're on the correct Lunar month.
- while (numDays > (long)(LunarMonthLen[hebrewYearType * MaxMonthPlusOne + result.month]))
- {
- // Adjust the number of days and move to the next month.
- numDays -= (long)(LunarMonthLen[hebrewYearType * MaxMonthPlusOne + result.month++]);
-
- // See if we need to adjust the Year.
- // Must handle both 12 and 13 month years.
- if ((result.month > 13) || (LunarMonthLen[hebrewYearType * MaxMonthPlusOne + result.month] == 0))
- {
- // Adjust the Year.
- result.year++;
- hebrewYearType = HebrewTable[(gregorianYear + 1 - FirstGregorianTableYear) * 2 + 1];
-
- // Adjust the Month.
- result.month = 1;
- }
- }
-
- // Found the right Lunar month.
- result.day += (int)(numDays - 1);
- }
-
- return GetResult(result, part);
- }
-
- public override DateTime AddMonths(DateTime time, int months)
- {
- try
- {
- int y = GetDatePart(time.Ticks, DatePartYear);
- int m = GetDatePart(time.Ticks, DatePartMonth);
- int d = GetDatePart(time.Ticks, DatePartDay);
-
- int monthsInYear;
- int i;
- if (months >= 0)
- {
- i = m + months;
- while (i > (monthsInYear = GetMonthsInYear(y, CurrentEra)))
- {
- y++;
- i -= monthsInYear;
- }
- }
- else
- {
- if ((i = m + months) <= 0)
- {
- months = -months;
- months -= m;
- y--;
-
- while (months > (monthsInYear = GetMonthsInYear(y, CurrentEra)))
- {
- y--;
- months -= monthsInYear;
- }
- monthsInYear = GetMonthsInYear(y, CurrentEra);
- i = monthsInYear - months;
- }
- }
-
- int days = GetDaysInMonth(y, i);
- if (d > days)
- {
- d = days;
- }
-
- return new DateTime(ToDateTime(y, i, d, 0, 0, 0, 0).Ticks + (time.Ticks % TicksPerDay));
- }
- // We expect ArgumentException and ArgumentOutOfRangeException (which is subclass of ArgumentException)
- // If exception is thrown in the calls above, we are out of the supported range of this calendar.
- catch (ArgumentException)
- {
- throw new ArgumentOutOfRangeException(nameof(months), months, SR.ArgumentOutOfRange_AddValue);
- }
- }
-
- public override DateTime AddYears(DateTime time, int years)
- {
- int y = GetDatePart(time.Ticks, DatePartYear);
- int m = GetDatePart(time.Ticks, DatePartMonth);
- int d = GetDatePart(time.Ticks, DatePartDay);
-
- y += years;
- CheckHebrewYearValue(y, Calendar.CurrentEra, nameof(years));
-
- int months = GetMonthsInYear(y, CurrentEra);
- if (m > months)
- {
- m = months;
- }
-
- int days = GetDaysInMonth(y, m);
- if (d > days)
- {
- d = days;
- }
-
- long ticks = ToDateTime(y, m, d, 0, 0, 0, 0).Ticks + (time.Ticks % TicksPerDay);
- Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
- return new DateTime(ticks);
- }
-
- public override int GetDayOfMonth(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartDay);
- }
-
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
- // If we calculate back, the Hebrew day of week for Gregorian 0001/1/1 is Monday (1).
- // Therfore, the fomula is:
- return (DayOfWeek)((int)(time.Ticks / TicksPerDay + 1) % 7);
- }
-
- internal static int GetHebrewYearType(int year, int era)
- {
- CheckHebrewYearValue(year, era, nameof(year));
- // The HebrewTable is indexed by Gregorian year and starts from FirstGregorianYear.
- // So we need to convert year (Hebrew year value) to Gregorian Year below.
- return HebrewTable[(year - HebrewYearOf1AD - FirstGregorianTableYear) * 2 + 1];
- }
-
- public override int GetDayOfYear(DateTime time)
- {
- // Get Hebrew year value of the specified time.
- int year = GetYear(time);
- DateTime beginOfYearDate;
- if (year == 5343)
- {
- // Gregorian 1583/01/01 corresponds to Hebrew 5343/04/07 (MinSupportedDateTime)
- // To figure out the Gregorian date associated with Hebrew 5343/01/01, we need to
- // count the days from 5343/01/01 to 5343/04/07 and subtract that from Gregorian
- // 1583/01/01.
- // 1. Tishri (30 days)
- // 2. Heshvan (30 days since 5343 has 355 days)
- // 3. Kislev (30 days since 5343 has 355 days)
- // 96 days to get from 5343/01/01 to 5343/04/07
- // Gregorian 1583/01/01 - 96 days = 1582/9/27
-
- // the beginning of Hebrew year 5343 corresponds to Gregorian September 27, 1582.
- beginOfYearDate = new DateTime(1582, 9, 27);
- }
- else
- {
- // following line will fail when year is 5343 (first supported year)
- beginOfYearDate = ToDateTime(year, 1, 1, 0, 0, 0, 0, CurrentEra);
- }
-
- return (int)((time.Ticks - beginOfYearDate.Ticks) / TicksPerDay) + 1;
- }
-
- public override int GetDaysInMonth(int year, int month, int era)
- {
- CheckEraRange(era);
- int hebrewYearType = GetHebrewYearType(year, era);
- CheckHebrewMonthValue(year, month, era);
-
- Debug.Assert(hebrewYearType >= 1 && hebrewYearType <= 6,
- "hebrewYearType should be from 1 to 6, but now hebrewYearType = " + hebrewYearType + " for hebrew year " + year);
- int monthDays = LunarMonthLen[hebrewYearType * MaxMonthPlusOne + month];
- if (monthDays == 0)
- {
- throw new ArgumentOutOfRangeException(nameof(month), month, SR.ArgumentOutOfRange_Month);
- }
-
- return monthDays;
- }
-
- public override int GetDaysInYear(int year, int era)
- {
- CheckEraRange(era);
- // normal years : 1 = 353 days 2 = 354 days 3 = 355 days.
- // Leap years : 4 = 383 5 384 6 = 385 days.
-
- // LunarYearType is from 1 to 6
- int LunarYearType = GetHebrewYearType(year, era);
- if (LunarYearType < 4)
- {
- // common year: LunarYearType = 1, 2, 3
- return 352 + LunarYearType;
- }
-
- return 382 + (LunarYearType - 3);
- }
-
- public override int GetEra(DateTime time) => HebrewEra;
-
- public override int[] Eras => new int[] { HebrewEra };
-
- public override int GetMonth(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartMonth);
- }
-
- public override int GetMonthsInYear(int year, int era)
- {
- return IsLeapYear(year, era) ? 13 : 12;
- }
-
- public override int GetYear(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartYear);
- }
-
- public override bool IsLeapDay(int year, int month, int day, int era)
- {
- if (IsLeapMonth(year, month, era))
- {
- // Every day in a leap month is a leap day.
- CheckHebrewDayValue(year, month, day, era);
- return true;
- }
- else if (IsLeapYear(year, Calendar.CurrentEra))
- {
- // There is an additional day in the 6th month in the leap year (the extra day is the 30th day in the 6th month),
- // so we should return true for 6/30 if that's in a leap year.
- if (month == 6 && day == 30)
- {
- return true;
- }
- }
-
- CheckHebrewDayValue(year, month, day, era);
- return false;
- }
-
- public override int GetLeapMonth(int year, int era)
- {
- // Year/era values are checked in IsLeapYear().
- if (IsLeapYear(year, era))
- {
- // The 7th month in a leap year is a leap month.
- return 7;
- }
- return 0;
- }
-
- public override bool IsLeapMonth(int year, int month, int era)
- {
- // Year/era values are checked in IsLeapYear().
- bool isLeapYear = IsLeapYear(year, era);
- CheckHebrewMonthValue(year, month, era);
-
- // The 7th month in a leap year is a leap month.
- return isLeapYear && month == 7;
- }
-
- public override bool IsLeapYear(int year, int era)
- {
- CheckHebrewYearValue(year, era, nameof(year));
- return ((7 * (long)year + 1) % 19) < 7;
- }
-
- /// <summary>
- /// (month1, day1) - (month2, day2)
- /// </summary>
- private static int GetDayDifference(int lunarYearType, int month1, int day1, int month2, int day2)
- {
- if (month1 == month2)
- {
- return day1 - day2;
- }
-
- // Make sure that (month1, day1) < (month2, day2)
- bool swap = (month1 > month2);
- if (swap)
- {
- // (month1, day1) < (month2, day2). Swap the values.
- // The result will be a negative number.
- int tempMonth, tempDay;
- tempMonth = month1; tempDay = day1;
- month1 = month2; day1 = day2;
- month2 = tempMonth; day2 = tempDay;
- }
-
- // Get the number of days from (month1,day1) to (month1, end of month1)
- int days = LunarMonthLen[lunarYearType * MaxMonthPlusOne + month1] - day1;
-
- // Move to next month.
- month1++;
-
- // Add up the days.
- while (month1 < month2)
- {
- days += LunarMonthLen[lunarYearType * MaxMonthPlusOne + month1++];
- }
- days += day2;
-
- return swap ? days : -days;
- }
-
- /// <summary>
- /// Convert Hebrew date to Gregorian date.
- /// The algorithm is like this:
- /// The hebrew year has an offset to the Gregorian year, so we can guess the Gregorian year for
- /// the specified Hebrew year. That is, GreogrianYear = HebrewYear - FirstHebrewYearOf1AD.
- ///
- /// From the Gregorian year and HebrewTable, we can get the Hebrew month/day value
- /// of the Gregorian date January 1st. Let's call this month/day value [hebrewDateForJan1]
- ///
- /// If the requested Hebrew month/day is less than [hebrewDateForJan1], we know the result
- /// Gregorian date falls in previous year. So we decrease the Gregorian year value, and
- /// retrieve the Hebrew month/day value of the Gregorian date january 1st again.
- ///
- /// Now, we get the answer of the Gregorian year.
- ///
- /// The next step is to get the number of days between the requested Hebrew month/day
- /// and [hebrewDateForJan1]. When we get that, we can create the DateTime by adding/subtracting
- /// the ticks value of the number of days.
- /// </summary>
- private static DateTime HebrewToGregorian(int hebrewYear, int hebrewMonth, int hebrewDay, int hour, int minute, int second, int millisecond)
- {
- // Get the rough Gregorian year for the specified hebrewYear.
- int gregorianYear = hebrewYear - HebrewYearOf1AD;
-
- DateBuffer hebrewDateOfJan1 = new DateBuffer(); // year value is unused.
- int lunarYearType = GetLunarMonthDay(gregorianYear, hebrewDateOfJan1);
-
- if ((hebrewMonth == hebrewDateOfJan1.month) && (hebrewDay == hebrewDateOfJan1.day))
- {
- return new DateTime(gregorianYear, 1, 1, hour, minute, second, millisecond);
- }
-
- int days = GetDayDifference(lunarYearType, hebrewMonth, hebrewDay, hebrewDateOfJan1.month, hebrewDateOfJan1.day);
-
- DateTime gregorianNewYear = new DateTime(gregorianYear, 1, 1);
- return new DateTime(gregorianNewYear.Ticks + days * TicksPerDay + TimeToTicks(hour, minute, second, millisecond));
- }
-
- public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- CheckHebrewYearValue(year, era, nameof(year));
- CheckHebrewMonthValue(year, month, era);
- CheckHebrewDayValue(year, month, day, era);
- DateTime dt = HebrewToGregorian(year, month, day, hour, minute, second, millisecond);
- CheckTicksRange(dt.Ticks);
- return dt;
- }
-
- private const int DefaultTwoDigitYearMax = 5790;
-
- public override int TwoDigitYearMax
- {
- get
- {
- if (_twoDigitYearMax == -1)
- {
- _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultTwoDigitYearMax);
- }
-
- return _twoDigitYearMax;
- }
- set
- {
- VerifyWritable();
- if (value == 99)
- {
- // Do nothing here. Year 99 is allowed so that TwoDitYearMax is disabled.
- }
- else
- {
- CheckHebrewYearValue(value, HebrewEra, nameof(value));
- }
-
- _twoDigitYearMax = value;
- }
- }
-
- public override int ToFourDigitYear(int year)
- {
- if (year < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (year < 100)
- {
- return base.ToFourDigitYear(year);
- }
-
- if (year > MaxHebrewYear || year < MinHebrewYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, MinHebrewYear, MaxHebrewYear));
- }
- return year;
- }
-
- internal class DateBuffer
- {
- internal int year;
- internal int month;
- internal int day;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/HebrewNumber.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/HebrewNumber.cs
deleted file mode 100644
index 41cf1d2bf49..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/HebrewNumber.cs
+++ /dev/null
@@ -1,447 +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 System.Text;
-using System.Diagnostics;
-
-namespace System.Globalization
-{
- ////////////////////////////////////////////////////////////////////////////
- //
- // Used in HebrewNumber.ParseByChar to maintain the context information (
- // the state in the state machine and current Hebrew number values, etc.)
- // when parsing Hebrew number character by character.
- //
- ////////////////////////////////////////////////////////////////////////////
-
- internal struct HebrewNumberParsingContext
- {
- // The current state of the state machine for parsing Hebrew numbers.
- internal HebrewNumber.HS state;
- // The current value of the Hebrew number.
- // The final value is determined when state is FoundEndOfHebrewNumber.
- internal int result;
-
- public HebrewNumberParsingContext(int result)
- {
- // Set the start state of the state machine for parsing Hebrew numbers.
- state = HebrewNumber.HS.Start;
- this.result = result;
- }
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Please see ParseByChar() for comments about different states defined here.
- //
- ////////////////////////////////////////////////////////////////////////////
-
- internal enum HebrewNumberParsingState
- {
- InvalidHebrewNumber,
- NotHebrewDigit,
- FoundEndOfHebrewNumber,
- ContinueParsing,
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // class HebrewNumber
- //
- // Provides static methods for formatting integer values into
- // Hebrew text and parsing Hebrew number text.
- //
- // Limitations:
- // Parse can only handle value 1 ~ 999.
- // Append() can only handle 1 ~ 999. If value is greater than 5000,
- // 5000 will be subtracted from the value.
- //
- ////////////////////////////////////////////////////////////////////////////
-
- internal static class HebrewNumber
- {
- ////////////////////////////////////////////////////////////////////////////
- //
- // Append
- //
- // Converts the given number to Hebrew letters according to the numeric
- // value of each Hebrew letter, appending to the supplied StringBuilder.
- // Basically, this converts the lunar year and the lunar month to letters.
- //
- // The character of a year is described by three letters of the Hebrew
- // alphabet, the first and third giving, respectively, the days of the
- // weeks on which the New Year occurs and Passover begins, while the
- // second is the initial of the Hebrew word for defective, normal, or
- // complete.
- //
- // Defective Year : Both Heshvan and Kislev are defective (353 or 383 days)
- // Normal Year : Heshvan is defective, Kislev is full (354 or 384 days)
- // Complete Year : Both Heshvan and Kislev are full (355 or 385 days)
- //
- ////////////////////////////////////////////////////////////////////////////
-
- internal static void Append(StringBuilder outputBuffer, int Number)
- {
- Debug.Assert(outputBuffer != null);
- int outputBufferStartingLength = outputBuffer.Length;
-
- char cTens = '\x0';
- char cUnits; // tens and units chars
- int Hundreds, Tens; // hundreds and tens values
-
- //
- // Adjust the number if greater than 5000.
- //
- if (Number > 5000)
- {
- Number -= 5000;
- }
-
- Debug.Assert(Number > 0 && Number <= 999, "Number is out of range.");
-
- //
- // Get the Hundreds.
- //
- Hundreds = Number / 100;
-
- if (Hundreds > 0)
- {
- Number -= Hundreds * 100;
- // \x05e7 = 100
- // \x05e8 = 200
- // \x05e9 = 300
- // \x05ea = 400
- // If the number is greater than 400, use the multiples of 400.
- for (int i = 0; i < (Hundreds / 4); i++)
- {
- outputBuffer.Append('\x05ea');
- }
-
- int remains = Hundreds % 4;
- if (remains > 0)
- {
- outputBuffer.Append((char)((int)'\x05e6' + remains));
- }
- }
-
- //
- // Get the Tens.
- //
- Tens = Number / 10;
- Number %= 10;
-
- switch (Tens)
- {
- case (0):
- cTens = '\x0';
- break;
- case (1):
- cTens = '\x05d9'; // Hebrew Letter Yod
- break;
- case (2):
- cTens = '\x05db'; // Hebrew Letter Kaf
- break;
- case (3):
- cTens = '\x05dc'; // Hebrew Letter Lamed
- break;
- case (4):
- cTens = '\x05de'; // Hebrew Letter Mem
- break;
- case (5):
- cTens = '\x05e0'; // Hebrew Letter Nun
- break;
- case (6):
- cTens = '\x05e1'; // Hebrew Letter Samekh
- break;
- case (7):
- cTens = '\x05e2'; // Hebrew Letter Ayin
- break;
- case (8):
- cTens = '\x05e4'; // Hebrew Letter Pe
- break;
- case (9):
- cTens = '\x05e6'; // Hebrew Letter Tsadi
- break;
- }
-
- //
- // Get the Units.
- //
- cUnits = (char)(Number > 0 ? ((int)'\x05d0' + Number - 1) : 0);
-
- if ((cUnits == '\x05d4') && // Hebrew Letter He (5)
- (cTens == '\x05d9'))
- { // Hebrew Letter Yod (10)
- cUnits = '\x05d5'; // Hebrew Letter Vav (6)
- cTens = '\x05d8'; // Hebrew Letter Tet (9)
- }
-
- if ((cUnits == '\x05d5') && // Hebrew Letter Vav (6)
- (cTens == '\x05d9'))
- { // Hebrew Letter Yod (10)
- cUnits = '\x05d6'; // Hebrew Letter Zayin (7)
- cTens = '\x05d8'; // Hebrew Letter Tet (9)
- }
-
- //
- // Copy the appropriate info to the given buffer.
- //
-
- if (cTens != '\x0')
- {
- outputBuffer.Append(cTens);
- }
-
- if (cUnits != '\x0')
- {
- outputBuffer.Append(cUnits);
- }
-
- if (outputBuffer.Length - outputBufferStartingLength > 1)
- {
- outputBuffer.Insert(outputBuffer.Length - 1, '"');
- }
- else
- {
- outputBuffer.Append('\'');
- }
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Token used to tokenize a Hebrew word into tokens so that we can use in the
- // state machine.
- //
- ////////////////////////////////////////////////////////////////////////////
-
- private enum HebrewToken : short
- {
- Invalid = -1,
- Digit400 = 0,
- Digit200_300 = 1,
- Digit100 = 2,
- Digit10 = 3, // 10 ~ 90
- Digit1 = 4, // 1, 2, 3, 4, 5, 8,
- Digit6_7 = 5,
- Digit7 = 6,
- Digit9 = 7,
- SingleQuote = 8,
- DoubleQuote = 9,
- }
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // This class is used to map a token into its Hebrew digit value.
- //
- ////////////////////////////////////////////////////////////////////////////
-
- private struct HebrewValue
- {
- internal HebrewToken token;
- internal short value;
- internal HebrewValue(HebrewToken token, short value)
- {
- this.token = token;
- this.value = value;
- }
- }
-
- //
- // Map a Hebrew character from U+05D0 ~ U+05EA to its digit value.
- // The value is -1 if the Hebrew character does not have a associated value.
- //
- private static readonly HebrewValue[] s_hebrewValues = {
- new HebrewValue(HebrewToken.Digit1, 1), // '\x05d0
- new HebrewValue(HebrewToken.Digit1, 2), // '\x05d1
- new HebrewValue(HebrewToken.Digit1, 3), // '\x05d2
- new HebrewValue(HebrewToken.Digit1, 4), // '\x05d3
- new HebrewValue(HebrewToken.Digit1, 5), // '\x05d4
- new HebrewValue(HebrewToken.Digit6_7, 6), // '\x05d5
- new HebrewValue(HebrewToken.Digit6_7, 7), // '\x05d6
- new HebrewValue(HebrewToken.Digit1, 8), // '\x05d7
- new HebrewValue(HebrewToken.Digit9, 9), // '\x05d8
- new HebrewValue(HebrewToken.Digit10, 10), // '\x05d9; // Hebrew Letter Yod
- new HebrewValue(HebrewToken.Invalid, -1), // '\x05da;
- new HebrewValue(HebrewToken.Digit10, 20), // '\x05db; // Hebrew Letter Kaf
- new HebrewValue(HebrewToken.Digit10, 30), // '\x05dc; // Hebrew Letter Lamed
- new HebrewValue(HebrewToken.Invalid, -1), // '\x05dd;
- new HebrewValue(HebrewToken.Digit10, 40), // '\x05de; // Hebrew Letter Mem
- new HebrewValue(HebrewToken.Invalid, -1), // '\x05df;
- new HebrewValue(HebrewToken.Digit10, 50), // '\x05e0; // Hebrew Letter Nun
- new HebrewValue(HebrewToken.Digit10, 60), // '\x05e1; // Hebrew Letter Samekh
- new HebrewValue(HebrewToken.Digit10, 70), // '\x05e2; // Hebrew Letter Ayin
- new HebrewValue(HebrewToken.Invalid, -1), // '\x05e3;
- new HebrewValue(HebrewToken.Digit10, 80), // '\x05e4; // Hebrew Letter Pe
- new HebrewValue(HebrewToken.Invalid, -1), // '\x05e5;
- new HebrewValue(HebrewToken.Digit10, 90), // '\x05e6; // Hebrew Letter Tsadi
- new HebrewValue(HebrewToken.Digit100, 100), // '\x05e7;
- new HebrewValue(HebrewToken.Digit200_300, 200), // '\x05e8;
- new HebrewValue(HebrewToken.Digit200_300, 300), // '\x05e9;
- new HebrewValue(HebrewToken.Digit400, 400), // '\x05ea;
- };
-
- private const int minHebrewNumberCh = 0x05d0;
- private static readonly char s_maxHebrewNumberCh = (char)(minHebrewNumberCh + s_hebrewValues.Length - 1);
-
- ////////////////////////////////////////////////////////////////////////////
- //
- // Hebrew number parsing State
- // The current state and the next token will lead to the next state in the state machine.
- // DQ = Double Quote
- //
- ////////////////////////////////////////////////////////////////////////////
-
- internal enum HS : sbyte
- {
- _err = -1, // an error state
- Start = 0,
- S400 = 1, // a Hebrew digit 400
- S400_400 = 2, // Two Hebrew digit 400
- S400_X00 = 3, // Two Hebrew digit 400 and followed by 100
- S400_X0 = 4, // Hebrew digit 400 and followed by 10 ~ 90
- X00_DQ = 5, // A hundred number and followed by a double quote.
- S400_X00_X0 = 6,
- X0_DQ = 7, // A two-digit number and followed by a double quote.
- X = 8, // A single digit Hebrew number.
- X0 = 9, // A two-digit Hebrew number
- X00 = 10, // A three-digit Hebrew number
- S400_DQ = 11, // A Hebrew digit 400 and followed by a double quote.
- S400_400_DQ = 12,
- S400_400_100 = 13,
- S9 = 14, // Hebrew digit 9
- X00_S9 = 15, // A hundered number and followed by a digit 9
- S9_DQ = 16, // Hebrew digit 9 and followed by a double quote
- END = 100, // A terminial state is reached.
- }
-
- //
- // The state machine for Hebrew number pasing.
- //
- private static readonly HS[] s_numberPasingState =
- {
- // 400 300/200 100 90~10 8~1 6, 7, 9, ' "
- /* 0 */
- HS.S400, HS.X00, HS.X00, HS.X0, HS.X, HS.X, HS.X, HS.S9, HS._err, HS._err,
- /* 1: S400 */
- HS.S400_400, HS.S400_X00, HS.S400_X00, HS.S400_X0, HS._err, HS._err, HS._err, HS.X00_S9, HS.END, HS.S400_DQ,
- /* 2: S400_400 */
- HS._err, HS._err, HS.S400_400_100, HS.S400_X0, HS._err, HS._err, HS._err, HS.X00_S9, HS._err, HS.S400_400_DQ,
- /* 3: S400_X00 */
- HS._err, HS._err, HS._err, HS.S400_X00_X0, HS._err, HS._err, HS._err, HS.X00_S9, HS._err, HS.X00_DQ,
- /* 4: S400_X0 */
- HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS.X0_DQ,
- /* 5: X00_DQ */
- HS._err, HS._err, HS._err, HS.END, HS.END, HS.END, HS.END, HS.END, HS._err, HS._err,
- /* 6: S400_X00_X0 */
- HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS.X0_DQ,
- /* 7: X0_DQ */
- HS._err, HS._err, HS._err, HS._err, HS.END, HS.END, HS.END, HS.END, HS._err, HS._err,
- /* 8: X */
- HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS.END, HS._err,
- /* 9: X0 */
- HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS.END, HS.X0_DQ,
- /* 10: X00 */
- HS._err, HS._err, HS._err, HS.S400_X0, HS._err, HS._err, HS._err, HS.X00_S9, HS.END, HS.X00_DQ,
- /* 11: S400_DQ */
- HS.END, HS.END, HS.END, HS.END, HS.END, HS.END, HS.END, HS.END, HS._err, HS._err,
- /* 12: S400_400_DQ*/
- HS._err, HS._err, HS.END, HS.END, HS.END, HS.END, HS.END, HS.END, HS._err, HS._err,
- /* 13: S400_400_100*/
- HS._err, HS._err, HS._err, HS.S400_X00_X0, HS._err, HS._err, HS._err, HS.X00_S9, HS._err, HS.X00_DQ,
- /* 14: S9 */
- HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS.END, HS.S9_DQ,
- /* 15: X00_S9 */
- HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS.S9_DQ,
- /* 16: S9_DQ */
- HS._err, HS._err, HS._err, HS._err, HS._err, HS.END, HS.END, HS._err, HS._err, HS._err
- };
-
- // Count of valid HebrewToken, column count in the NumberPasingState array
- private const int HebrewTokenCount = 10;
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Actions:
- // Parse the Hebrew number by passing one character at a time.
- // The state between characters are maintained at HebrewNumberPasingContext.
- // Returns:
- // Return a enum of HebrewNumberParsingState.
- // NotHebrewDigit: The specified ch is not a valid Hebrew digit.
- // InvalidHebrewNumber: After parsing the specified ch, it will lead into
- // an invalid Hebrew number text.
- // FoundEndOfHebrewNumber: A terminal state is reached. This means that
- // we find a valid Hebrew number text after the specified ch is parsed.
- // ContinueParsing: The specified ch is a valid Hebrew digit, and
- // it will lead into a valid state in the state machine, we should
- // continue to parse incoming characters.
- //
- ////////////////////////////////////////////////////////////////////////
-
- internal static HebrewNumberParsingState ParseByChar(char ch, ref HebrewNumberParsingContext context)
- {
- Debug.Assert(s_numberPasingState.Length == HebrewTokenCount * ((int)HS.S9_DQ + 1));
-
- HebrewToken token;
- if (ch == '\'')
- {
- token = HebrewToken.SingleQuote;
- }
- else if (ch == '\"')
- {
- token = HebrewToken.DoubleQuote;
- }
- else
- {
- int index = (int)ch - minHebrewNumberCh;
- if (index >= 0 && index < s_hebrewValues.Length)
- {
- token = s_hebrewValues[index].token;
- if (token == HebrewToken.Invalid)
- {
- return HebrewNumberParsingState.NotHebrewDigit;
- }
- context.result += s_hebrewValues[index].value;
- }
- else
- {
- // Not in valid Hebrew digit range.
- return HebrewNumberParsingState.NotHebrewDigit;
- }
- }
- context.state = s_numberPasingState[(int)context.state * (int)HebrewTokenCount + (int)token];
- if (context.state == HS._err)
- {
- // Invalid Hebrew state. This indicates an incorrect Hebrew number.
- return HebrewNumberParsingState.InvalidHebrewNumber;
- }
- if (context.state == HS.END)
- {
- // Reach a terminal state.
- return HebrewNumberParsingState.FoundEndOfHebrewNumber;
- }
- // We should continue to parse.
- return HebrewNumberParsingState.ContinueParsing;
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Actions:
- // Check if the ch is a valid Hebrew number digit.
- // This function will return true if the specified char is a legal Hebrew
- // digit character, single quote, or double quote.
- // Returns:
- // true if the specified character is a valid Hebrew number character.
- //
- ////////////////////////////////////////////////////////////////////////
-
- internal static bool IsDigit(char ch)
- {
- if (ch >= minHebrewNumberCh && ch <= s_maxHebrewNumberCh)
- {
- return s_hebrewValues[ch - minHebrewNumberCh].value >= 0;
- }
- return ch == '\'' || ch == '\"';
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.Unix.cs
deleted file mode 100644
index a6e8f73d3e4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.Unix.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System.Globalization
-{
- public partial class HijriCalendar : Calendar
- {
- private static int GetHijriDateAdjustment()
- {
- // this setting is not supported on Unix, so always return 0
- return 0;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.Win32.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.Win32.cs
deleted file mode 100644
index d8f69fb5bb3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.Win32.cs
+++ /dev/null
@@ -1,83 +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 Internal.Win32;
-
-namespace System.Globalization
-{
- public partial class HijriCalendar : Calendar
- {
- private int GetHijriDateAdjustment()
- {
- if (_hijriAdvance == int.MinValue)
- {
- // Never been set before. Use the system value from registry.
- _hijriAdvance = GetAdvanceHijriDate();
- }
- return _hijriAdvance;
- }
-
- private const string InternationalRegKey = "Control Panel\\International";
- private const string HijriAdvanceRegKeyEntry = "AddHijriDate";
-
- /*=================================GetAdvanceHijriDate==========================
- **Action: Gets the AddHijriDate value from the registry.
- **Returns:
- **Arguments: None.
- **Exceptions:
- **Note:
- ** The HijriCalendar has a user-overidable calculation. That is, use can set a value from the control
- ** panel, so that the calculation of the Hijri Calendar can move ahead or backwards from -2 to +2 days.
- **
- ** The valid string values in the registry are:
- ** "AddHijriDate-2" => Add -2 days to the current calculated Hijri date.
- ** "AddHijriDate" => Add -1 day to the current calculated Hijri date.
- ** "" => Add 0 day to the current calculated Hijri date.
- ** "AddHijriDate+1" => Add +1 days to the current calculated Hijri date.
- ** "AddHijriDate+2" => Add +2 days to the current calculated Hijri date.
- ============================================================================*/
- private static int GetAdvanceHijriDate()
- {
- using (RegistryKey? key = Registry.CurrentUser.OpenSubKey(InternationalRegKey))
- {
- // Abort if we didn't find anything
- if (key == null)
- {
- return 0;
- }
-
- object? value = key.GetValue(HijriAdvanceRegKeyEntry);
- if (value == null)
- {
- return 0;
- }
-
- int hijriAdvance = 0;
- string? str = value.ToString();
- if (string.Compare(str, 0, HijriAdvanceRegKeyEntry, 0, HijriAdvanceRegKeyEntry.Length, StringComparison.OrdinalIgnoreCase) == 0)
- {
- if (str!.Length == HijriAdvanceRegKeyEntry.Length)
- hijriAdvance = -1;
- else
- {
- try
- {
- int advance = int.Parse(str.AsSpan(HijriAdvanceRegKeyEntry.Length), provider: CultureInfo.InvariantCulture);
- if ((advance >= MinAdvancedHijri) && (advance <= MaxAdvancedHijri))
- {
- hijriAdvance = advance;
- }
- }
- // If we got garbage from registry just ignore it.
- // hijriAdvance = 0 because of declaraction assignment up above.
- catch (ArgumentException) { }
- catch (FormatException) { }
- catch (OverflowException) { }
- }
- }
- return hijriAdvance;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.cs
deleted file mode 100644
index 4a4c667a5d5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/HijriCalendar.cs
+++ /dev/null
@@ -1,473 +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.
-
-namespace System.Globalization
-{
- /// <remarks>
- /// Rules for the Hijri calendar:
- /// - The Hijri calendar is a strictly Lunar calendar.
- /// - Days begin at sunset.
- /// - Islamic Year 1 (Muharram 1, 1 A.H.) is equivalent to absolute date
- /// 227015 (Friday, July 16, 622 C.E. - Julian).
- /// - Leap Years occur in the 2, 5, 7, 10, 13, 16, 18, 21, 24, 26, &amp; 29th
- /// years of a 30-year cycle. Year = leap iff ((11y+14) mod 30 &lt; 11).
- /// - There are 12 months which contain alternately 30 and 29 days.
- /// - The 12th month, Dhu al-Hijjah, contains 30 days instead of 29 days
- /// in a leap year.
- /// - Common years have 354 days. Leap years have 355 days.
- /// - There are 10,631 days in a 30-year cycle.
- /// - The Islamic months are:
- /// 1. Muharram (30 days) 7. Rajab (30 days)
- /// 2. Safar (29 days) 8. Sha'ban (29 days)
- /// 3. Rabi I (30 days) 9. Ramadan (30 days)
- /// 4. Rabi II (29 days) 10. Shawwal (29 days)
- /// 5. Jumada I (30 days) 11. Dhu al-Qada (30 days)
- /// 6. Jumada II (29 days) 12. Dhu al-Hijjah (29 days) {30}
- ///
- /// NOTENOTE
- /// The calculation of the HijriCalendar is based on the absolute date. And the
- /// absolute date means the number of days from January 1st, 1 A.D.
- /// Therefore, we do not support the days before the January 1st, 1 A.D.
- ///
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 0622/07/18 9999/12/31
- /// Hijri 0001/01/01 9666/04/03
- /// </remarks>
-
- public partial class HijriCalendar : Calendar
- {
- public static readonly int HijriEra = 1;
-
- private const int DatePartYear = 0;
- private const int DatePartDayOfYear = 1;
- private const int DatePartMonth = 2;
- private const int DatePartDay = 3;
-
- private const int MinAdvancedHijri = -2;
- private const int MaxAdvancedHijri = 2;
-
- private static readonly int[] s_hijriMonthDays = { 0, 30, 59, 89, 118, 148, 177, 207, 236, 266, 295, 325, 355 };
-
- private int _hijriAdvance = int.MinValue;
-
- // DateTime.MaxValue = Hijri calendar (year:9666, month: 4, day: 3).
- private const int MaxCalendarYear = 9666;
- private const int MaxCalendarMonth = 4;
-
- // Hijri calendar (year: 1, month: 1, day:1 ) = Gregorian (year: 622, month: 7, day: 18)
- // This is the minimal Gregorian date that we support in the HijriCalendar.
- private static readonly DateTime s_calendarMinValue = new DateTime(622, 7, 18);
- private static readonly DateTime s_calendarMaxValue = DateTime.MaxValue;
-
- public override DateTime MinSupportedDateTime => s_calendarMinValue;
-
- public override DateTime MaxSupportedDateTime => s_calendarMaxValue;
-
- public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.LunarCalendar;
-
- public HijriCalendar()
- {
- }
-
- internal override CalendarId ID => CalendarId.HIJRI;
-
- protected override int DaysInYearBeforeMinSupportedYear =>
- // the year before the 1st year of the cycle would have been the 30th year
- // of the previous cycle which is not a leap year. Common years have 354 days.
- 354;
-
- private long GetAbsoluteDateHijri(int y, int m, int d)
- {
- return (long)(DaysUpToHijriYear(y) + s_hijriMonthDays[m - 1] + d - 1 - HijriAdjustment);
- }
-
- private long DaysUpToHijriYear(int HijriYear)
- {
- // Compute the number of years up to the current 30 year cycle.
- int numYear30 = ((HijriYear - 1) / 30) * 30;
-
- // Compute the number of years left. This is the number of years
- // into the 30 year cycle for the given year.
- int numYearsLeft = HijriYear - numYear30 - 1;
-
- // Compute the number of absolute days up to the given year.
- long numDays = ((numYear30 * 10631L) / 30L) + 227013L;
- while (numYearsLeft > 0)
- {
- // Common year is 354 days, and leap year is 355 days.
- numDays += 354 + (IsLeapYear(numYearsLeft, CurrentEra) ? 1 : 0);
- numYearsLeft--;
- }
-
- return numDays;
- }
-
- public int HijriAdjustment
- {
- get
- {
- if (_hijriAdvance == int.MinValue)
- {
- // Never been set before. Use the system value from registry.
- _hijriAdvance = GetHijriDateAdjustment();
- }
-
- return _hijriAdvance;
- }
-
- set
- {
- if (value < MinAdvancedHijri || value > MaxAdvancedHijri)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Bounds_Lower_Upper, MinAdvancedHijri, MaxAdvancedHijri));
- }
-
- VerifyWritable();
- _hijriAdvance = value;
- }
- }
-
- internal static void CheckTicksRange(long ticks)
- {
- if (ticks < s_calendarMinValue.Ticks || ticks > s_calendarMaxValue.Ticks)
- {
- throw new ArgumentOutOfRangeException(
- "time",
- ticks,
- SR.Format(
- CultureInfo.InvariantCulture,
- SR.ArgumentOutOfRange_CalendarRange,
- s_calendarMinValue,
- s_calendarMaxValue));
- }
- }
-
- internal static void CheckEraRange(int era)
- {
- if (era != CurrentEra && era != HijriEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- }
-
- internal static void CheckYearRange(int year, int era)
- {
- CheckEraRange(era);
- if (year < 1 || year > MaxCalendarYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxCalendarYear));
- }
- }
-
- internal static void CheckYearMonthRange(int year, int month, int era)
- {
- CheckYearRange(year, era);
- if (year == MaxCalendarYear)
- {
- if (month > MaxCalendarMonth)
- {
- throw new ArgumentOutOfRangeException(
- nameof(month),
- month,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxCalendarMonth));
- }
- }
-
- if (month < 1 || month > 12)
- {
- throw new ArgumentOutOfRangeException(nameof(month), month, SR.ArgumentOutOfRange_Month);
- }
- }
-
- /// <summary>
- /// First, we get the absolute date (the number of days from January 1st, 1 A.C) for the given ticks.
- /// Use the formula (((AbsoluteDate - 227013) * 30) / 10631) + 1, we can a rough value for the Hijri year.
- /// In order to get the exact Hijri year, we compare the exact absolute date for HijriYear and (HijriYear + 1).
- /// From here, we can get the correct Hijri year.
- /// </summary>
- internal virtual int GetDatePart(long ticks, int part)
- {
- CheckTicksRange(ticks);
-
- // Get the absolute date. The absolute date is the number of days from January 1st, 1 A.D.
- // 1/1/0001 is absolute date 1.
- long numDays = ticks / GregorianCalendar.TicksPerDay + 1;
-
- // See how much we need to backup or advance
- numDays += HijriAdjustment;
-
- // Calculate the appromixate Hijri Year from this magic formula.
- int hijriYear = (int)(((numDays - 227013) * 30) / 10631) + 1;
-
- long daysToHijriYear = DaysUpToHijriYear(hijriYear); // The absolute date for HijriYear
- long daysOfHijriYear = GetDaysInYear(hijriYear, CurrentEra); // The number of days for (HijriYear+1) year.
-
- if (numDays < daysToHijriYear)
- {
- daysToHijriYear -= daysOfHijriYear;
- hijriYear--;
- }
- else if (numDays == daysToHijriYear)
- {
- hijriYear--;
- daysToHijriYear -= GetDaysInYear(hijriYear, CurrentEra);
- }
- else
- {
- if (numDays > daysToHijriYear + daysOfHijriYear)
- {
- daysToHijriYear += daysOfHijriYear;
- hijriYear++;
- }
- }
- if (part == DatePartYear)
- {
- return hijriYear;
- }
-
- // Calculate the Hijri Month.
- int hijriMonth = 1;
- numDays -= daysToHijriYear;
-
- if (part == DatePartDayOfYear)
- {
- return (int)numDays;
- }
-
- while ((hijriMonth <= 12) && (numDays > s_hijriMonthDays[hijriMonth - 1]))
- {
- hijriMonth++;
- }
- hijriMonth--;
-
- if (part == DatePartMonth)
- {
- return hijriMonth;
- }
-
- // Calculate the Hijri Day.
- int hijriDay = (int)(numDays - s_hijriMonthDays[hijriMonth - 1]);
-
- if (part == DatePartDay)
- {
- return hijriDay;
- }
-
- // Incorrect part value.
- throw new InvalidOperationException(SR.InvalidOperation_DateTimeParsing);
- }
-
- public override DateTime AddMonths(DateTime time, int months)
- {
- if (months < -120000 || months > 120000)
- {
- throw new ArgumentOutOfRangeException(
- nameof(months),
- months,
- SR.Format(SR.ArgumentOutOfRange_Range, -120000, 120000));
- }
-
- // Get the date in Hijri calendar.
- int y = GetDatePart(time.Ticks, DatePartYear);
- int m = GetDatePart(time.Ticks, DatePartMonth);
- int d = GetDatePart(time.Ticks, DatePartDay);
- int i = m - 1 + months;
- if (i >= 0)
- {
- m = i % 12 + 1;
- y += i / 12;
- }
- else
- {
- m = 12 + (i + 1) % 12;
- y += (i - 11) / 12;
- }
-
- int days = GetDaysInMonth(y, m);
- if (d > days)
- {
- d = days;
- }
-
- long ticks = GetAbsoluteDateHijri(y, m, d) * TicksPerDay + (time.Ticks % TicksPerDay);
- Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
- return new DateTime(ticks);
- }
-
- public override DateTime AddYears(DateTime time, int years)
- {
- return AddMonths(time, years * 12);
- }
-
- public override int GetDayOfMonth(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartDay);
- }
-
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
- return (DayOfWeek)((int)(time.Ticks / TicksPerDay + 1) % 7);
- }
-
- public override int GetDayOfYear(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartDayOfYear);
- }
-
- public override int GetDaysInMonth(int year, int month, int era)
- {
- CheckYearMonthRange(year, month, era);
- if (month == 12)
- {
- // For the 12th month, leap year has 30 days, and common year has 29 days.
- return IsLeapYear(year, CurrentEra) ? 30 : 29;
- }
-
- // Other months contain 30 and 29 days alternatively. The 1st month has 30 days.
- return ((month % 2) == 1) ? 30 : 29;
- }
-
- public override int GetDaysInYear(int year, int era)
- {
- CheckYearRange(year, era);
- // Common years have 354 days. Leap years have 355 days.
- return IsLeapYear(year, CurrentEra) ? 355 : 354;
- }
-
- public override int GetEra(DateTime time)
- {
- CheckTicksRange(time.Ticks);
- return HijriEra;
- }
-
- public override int[] Eras => new int[] { HijriEra };
-
- public override int GetMonth(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartMonth);
- }
-
- public override int GetMonthsInYear(int year, int era)
- {
- CheckYearRange(year, era);
- return 12;
- }
-
- public override int GetYear(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartYear);
- }
-
- public override bool IsLeapDay(int year, int month, int day, int era)
- {
- // The year/month/era value checking is done in GetDaysInMonth().
- int daysInMonth = GetDaysInMonth(year, month, era);
- if (day < 1 || day > daysInMonth)
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- day,
- SR.Format(SR.ArgumentOutOfRange_Day, daysInMonth, month));
- }
-
- return IsLeapYear(year, era) && month == 12 && day == 30;
- }
-
- public override int GetLeapMonth(int year, int era)
- {
- CheckYearRange(year, era);
- return 0;
- }
-
- public override bool IsLeapMonth(int year, int month, int era)
- {
- CheckYearMonthRange(year, month, era);
- return false;
- }
-
- public override bool IsLeapYear(int year, int era)
- {
- CheckYearRange(year, era);
- return (((year * 11) + 14) % 30) < 11;
- }
-
- public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- // The year/month/era checking is done in GetDaysInMonth().
- int daysInMonth = GetDaysInMonth(year, month, era);
- if (day < 1 || day > daysInMonth)
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- day,
- SR.Format(SR.ArgumentOutOfRange_Day, daysInMonth, month));
- }
-
- long lDate = GetAbsoluteDateHijri(year, month, day);
- if (lDate < 0)
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay);
- }
-
- return new DateTime(lDate * GregorianCalendar.TicksPerDay + TimeToTicks(hour, minute, second, millisecond));
- }
-
- private const int DefaultTwoDigitYearMax = 1451;
-
- public override int TwoDigitYearMax
- {
- get
- {
- if (_twoDigitYearMax == -1)
- {
- _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultTwoDigitYearMax);
- }
-
- return _twoDigitYearMax;
- }
- set
- {
- VerifyWritable();
- if (value < 99 || value > MaxCalendarYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 99, MaxCalendarYear));
- }
-
- _twoDigitYearMax = value;
- }
- }
-
- public override int ToFourDigitYear(int year)
- {
- if (year < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (year < 100)
- {
- return base.ToFourDigitYear(year);
- }
-
- if (year > MaxCalendarYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxCalendarYear));
- }
- return year;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/ISOWeek.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/ISOWeek.cs
deleted file mode 100644
index 1c0a909abbc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/ISOWeek.cs
+++ /dev/null
@@ -1,162 +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 static System.Globalization.GregorianCalendar;
-
-namespace System.Globalization
-{
- public static class ISOWeek
- {
- private const int WeeksInLongYear = 53;
- private const int WeeksInShortYear = 52;
-
- private const int MinWeek = 1;
- private const int MaxWeek = WeeksInLongYear;
-
- public static int GetWeekOfYear(DateTime date)
- {
- int week = GetWeekNumber(date);
-
- if (week < MinWeek)
- {
- // If the week number obtained equals 0, it means that the
- // given date belongs to the preceding (week-based) year.
- return GetWeeksInYear(date.Year - 1);
- }
-
- if (week > GetWeeksInYear(date.Year))
- {
- // If a week number of 53 is obtained, one must check that
- // the date is not actually in week 1 of the following year.
- return MinWeek;
- }
-
- return week;
- }
-
- public static int GetYear(DateTime date)
- {
- int week = GetWeekNumber(date);
-
- if (week < MinWeek)
- {
- // If the week number obtained equals 0, it means that the
- // given date belongs to the preceding (week-based) year.
- return date.Year - 1;
- }
-
- if (week > GetWeeksInYear(date.Year))
- {
- // If a week number of 53 is obtained, one must check that
- // the date is not actually in week 1 of the following year.
- return date.Year + 1;
- }
-
- return date.Year;
- }
-
- // The year parameter represents an ISO week-numbering year (also called ISO year informally).
- // Each week's year is the Gregorian year in which the Thursday falls.
- // The first week of the year, hence, always contains 4 January.
- // ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.
- public static DateTime GetYearStart(int year)
- {
- return ToDateTime(year, MinWeek, DayOfWeek.Monday);
- }
-
- // The year parameter represents an ISO week-numbering year (also called ISO year informally).
- // Each week's year is the Gregorian year in which the Thursday falls.
- // The first week of the year, hence, always contains 4 January.
- // ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.
- public static DateTime GetYearEnd(int year)
- {
- return ToDateTime(year, GetWeeksInYear(year), DayOfWeek.Sunday);
- }
-
- // From https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year:
- //
- // The long years, with 53 weeks in them, can be described by any of the following equivalent definitions:
- //
- // - Any year starting on Thursday and any leap year starting on Wednesday.
- // - Any year ending on Thursday and any leap year ending on Friday.
- // - Years in which 1 January and 31 December (in common years) or either (in leap years) are Thursdays.
- //
- // All other week-numbering years are short years and have 52 weeks.
- public static int GetWeeksInYear(int year)
- {
- if (year < MinYear || year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(nameof(year), SR.ArgumentOutOfRange_Year);
- }
-
- static int P(int y) => (y + (y / 4) - (y / 100) + (y / 400)) % 7;
-
- if (P(year) == 4 || P(year - 1) == 3)
- {
- return WeeksInLongYear;
- }
-
- return WeeksInShortYear;
- }
-
- // From https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year,_week_number_and_weekday:
- //
- // This method requires that one know the weekday of 4 January of the year in question.
- // Add 3 to the number of this weekday, giving a correction to be used for dates within this year.
- //
- // Multiply the week number by 7, then add the weekday. From this sum subtract the correction for the year.
- // The result is the ordinal date, which can be converted into a calendar date.
- //
- // If the ordinal date thus obtained is zero or negative, the date belongs to the previous calendar year.
- // If greater than the number of days in the year, to the following year.
- public static DateTime ToDateTime(int year, int week, DayOfWeek dayOfWeek)
- {
- if (year < MinYear || year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(nameof(year), SR.ArgumentOutOfRange_Year);
- }
-
- if (week < MinWeek || week > MaxWeek)
- {
- throw new ArgumentOutOfRangeException(nameof(week), SR.ArgumentOutOfRange_Week_ISO);
- }
-
- // We allow 7 for convenience in cases where a user already has a valid ISO
- // day of week value for Sunday. This means that both 0 and 7 will map to Sunday.
- // The GetWeekday method will normalize this into the 1-7 range required by ISO.
- if ((int)dayOfWeek < 0 || (int)dayOfWeek > 7)
- {
- throw new ArgumentOutOfRangeException(nameof(dayOfWeek), SR.ArgumentOutOfRange_DayOfWeek);
- }
-
- var jan4 = new DateTime(year, month: 1, day: 4);
-
- int correction = GetWeekday(jan4.DayOfWeek) + 3;
-
- int ordinal = (week * 7) + GetWeekday(dayOfWeek) - correction;
-
- return new DateTime(year, month: 1, day: 1).AddDays(ordinal - 1);
- }
-
- // From https://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_of_a_given_date:
- //
- // Using ISO weekday numbers (running from 1 for Monday to 7 for Sunday),
- // subtract the weekday from the ordinal date, then add 10. Divide the result by 7.
- // Ignore the remainder; the quotient equals the week number.
- //
- // If the week number thus obtained equals 0, it means that the given date belongs to the preceding (week-based) year.
- // If a week number of 53 is obtained, one must check that the date is not actually in week 1 of the following year.
- private static int GetWeekNumber(DateTime date)
- {
- return (date.DayOfYear - GetWeekday(date.DayOfWeek) + 10) / 7;
- }
-
- // Day of week in ISO is represented by an integer from 1 through 7, beginning with Monday and ending with Sunday.
- // This matches the underlying values of the DayOfWeek enum, except for Sunday, which needs to be converted.
- private static int GetWeekday(DayOfWeek dayOfWeek)
- {
- return dayOfWeek == DayOfWeek.Sunday ? 7 : (int)dayOfWeek;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.Unix.cs
deleted file mode 100644
index 4c6ee2c4041..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.Unix.cs
+++ /dev/null
@@ -1,145 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- public sealed partial class IdnMapping
- {
- private unsafe string GetAsciiCore(string unicodeString, char* unicode, int count)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(unicodeString != null && unicodeString.Length >= count);
-
- uint flags = Flags;
- CheckInvalidIdnCharacters(unicode, count, flags, nameof(unicode));
-
- const int StackallocThreshold = 512;
- // Each unicode character is represented by up to 3 ASCII chars
- // and the whole string is prefixed by "xn--" (length 4)
- int estimatedLength = (int)Math.Min(count * 3L + 4, StackallocThreshold);
- int actualLength;
- if (estimatedLength < StackallocThreshold)
- {
- char* outputStack = stackalloc char[estimatedLength];
- actualLength = Interop.Globalization.ToAscii(flags, unicode, count, outputStack, estimatedLength);
- if (actualLength > 0 && actualLength <= estimatedLength)
- {
- return GetStringForOutput(unicodeString, unicode, count, outputStack, actualLength);
- }
- }
- else
- {
- actualLength = Interop.Globalization.ToAscii(flags, unicode, count, null, 0);
- }
- if (actualLength == 0)
- {
- throw new ArgumentException(SR.Argument_IdnIllegalName, nameof(unicode));
- }
-
- char[] outputHeap = new char[actualLength];
- fixed (char* pOutputHeap = &outputHeap[0])
- {
- actualLength = Interop.Globalization.ToAscii(flags, unicode, count, pOutputHeap, actualLength);
- if (actualLength == 0 || actualLength > outputHeap.Length)
- {
- throw new ArgumentException(SR.Argument_IdnIllegalName, nameof(unicode));
- }
- return GetStringForOutput(unicodeString, unicode, count, pOutputHeap, actualLength);
- }
- }
-
- private unsafe string GetUnicodeCore(string asciiString, char* ascii, int count)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(asciiString != null && asciiString.Length >= count);
-
- uint flags = Flags;
- CheckInvalidIdnCharacters(ascii, count, flags, nameof(ascii));
-
- const int StackAllocThreshold = 512;
- if (count < StackAllocThreshold)
- {
- char* output = stackalloc char[count];
- return GetUnicodeCore(asciiString, ascii, count, flags, output, count, reattempt: true);
- }
- else
- {
- char[] output = new char[count];
- fixed (char* pOutput = &output[0])
- {
- return GetUnicodeCore(asciiString, ascii, count, flags, pOutput, count, reattempt: true);
- }
- }
- }
-
- private unsafe string GetUnicodeCore(string asciiString, char* ascii, int count, uint flags, char* output, int outputLength, bool reattempt)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(asciiString != null && asciiString.Length >= count);
-
- int realLen = Interop.Globalization.ToUnicode(flags, ascii, count, output, outputLength);
-
- if (realLen == 0)
- {
- throw new ArgumentException(SR.Argument_IdnIllegalName, nameof(ascii));
- }
- else if (realLen <= outputLength)
- {
- return GetStringForOutput(asciiString, ascii, count, output, realLen);
- }
- else if (reattempt)
- {
- char[] newOutput = new char[realLen];
- fixed (char* pNewOutput = newOutput)
- {
- return GetUnicodeCore(asciiString, ascii, count, flags, pNewOutput, realLen, reattempt: false);
- }
- }
-
- throw new ArgumentException(SR.Argument_IdnIllegalName, nameof(ascii));
- }
-
- // -----------------------------
- // ---- PAL layer ends here ----
- // -----------------------------
-
- private uint Flags
- {
- get
- {
- int flags =
- (AllowUnassigned ? Interop.Globalization.AllowUnassigned : 0) |
- (UseStd3AsciiRules ? Interop.Globalization.UseStd3AsciiRules : 0);
- return (uint)flags;
- }
- }
-
- /// <summary>
- /// ICU doesn't check for invalid characters unless the STD3 rules option
- /// is enabled.
- ///
- /// To match Windows behavior, we walk the string ourselves looking for these
- /// bad characters so we can continue to throw ArgumentException in these cases.
- /// </summary>
- private static unsafe void CheckInvalidIdnCharacters(char* s, int count, uint flags, string paramName)
- {
- if ((flags & Interop.Globalization.UseStd3AsciiRules) == 0)
- {
- for (int i = 0; i < count; i++)
- {
- char c = s[i];
-
- // These characters are prohibited regardless of the UseStd3AsciiRules property.
- // See https://msdn.microsoft.com/en-us/library/system.globalization.idnmapping.usestd3asciirules(v=vs.110).aspx
- if (c <= 0x1F || c == 0x7F)
- {
- throw new ArgumentException(SR.Argument_IdnIllegalName, paramName);
- }
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.Windows.cs
deleted file mode 100644
index 6a97c04ebf6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.Windows.cs
+++ /dev/null
@@ -1,129 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.InteropServices;
-
-namespace System.Globalization
-{
- public sealed partial class IdnMapping
- {
- private unsafe string GetAsciiCore(string unicodeString, char* unicode, int count)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(unicodeString != null && unicodeString.Length >= count);
-
- uint flags = Flags;
-
- // Determine the required length
- int length = Interop.Normaliz.IdnToAscii(flags, unicode, count, null, 0);
- if (length == 0)
- {
- ThrowForZeroLength(unicode: true);
- }
-
- // Do the conversion
- const int StackAllocThreshold = 512; // arbitrary limit to switch from stack to heap allocation
- if (length < StackAllocThreshold)
- {
- char* output = stackalloc char[length];
- return GetAsciiCore(unicodeString, unicode, count, flags, output, length);
- }
- else
- {
- char[] output = new char[length];
- fixed (char* pOutput = &output[0])
- {
- return GetAsciiCore(unicodeString, unicode, count, flags, pOutput, length);
- }
- }
- }
-
- private unsafe string GetAsciiCore(string unicodeString, char* unicode, int count, uint flags, char* output, int outputLength)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(unicodeString != null && unicodeString.Length >= count);
-
- int length = Interop.Normaliz.IdnToAscii(flags, unicode, count, output, outputLength);
- if (length == 0)
- {
- ThrowForZeroLength(unicode: true);
- }
- Debug.Assert(length == outputLength);
- return GetStringForOutput(unicodeString, unicode, count, output, length);
- }
-
- private unsafe string GetUnicodeCore(string asciiString, char* ascii, int count)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(asciiString != null && asciiString.Length >= count);
-
- uint flags = Flags;
-
- // Determine the required length
- int length = Interop.Normaliz.IdnToUnicode(flags, ascii, count, null, 0);
- if (length == 0)
- {
- ThrowForZeroLength(unicode: false);
- }
-
- // Do the conversion
- const int StackAllocThreshold = 512; // arbitrary limit to switch from stack to heap allocation
- if (length < StackAllocThreshold)
- {
- char* output = stackalloc char[length];
- return GetUnicodeCore(asciiString, ascii, count, flags, output, length);
- }
- else
- {
- char[] output = new char[length];
- fixed (char* pOutput = &output[0])
- {
- return GetUnicodeCore(asciiString, ascii, count, flags, pOutput, length);
- }
- }
- }
-
- private unsafe string GetUnicodeCore(string asciiString, char* ascii, int count, uint flags, char* output, int outputLength)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(asciiString != null && asciiString.Length >= count);
-
- int length = Interop.Normaliz.IdnToUnicode(flags, ascii, count, output, outputLength);
- if (length == 0)
- {
- ThrowForZeroLength(unicode: false);
- }
- Debug.Assert(length == outputLength);
- return GetStringForOutput(asciiString, ascii, count, output, length);
- }
-
- // -----------------------------
- // ---- PAL layer ends here ----
- // -----------------------------
-
- private uint Flags
- {
- get
- {
- int flags =
- (AllowUnassigned ? Interop.Normaliz.IDN_ALLOW_UNASSIGNED : 0) |
- (UseStd3AsciiRules ? Interop.Normaliz.IDN_USE_STD3_ASCII_RULES : 0);
- return (uint)flags;
- }
- }
-
- [DoesNotReturn]
- private static void ThrowForZeroLength(bool unicode)
- {
- int lastError = Marshal.GetLastWin32Error();
-
- throw new ArgumentException(
- lastError == Interop.Errors.ERROR_INVALID_NAME ? SR.Argument_IdnIllegalName :
- (unicode ? SR.Argument_InvalidCharSequenceNoIndex : SR.Argument_IdnBadPunycode),
- unicode ? "unicode" : "ascii");
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.cs
deleted file mode 100644
index 2035932a82e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/IdnMapping.cs
+++ /dev/null
@@ -1,871 +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.
-
-// This file contains the IDN functions and implementation.
-//
-// This allows encoding of non-ASCII domain names in a "punycode" form,
-// for example:
-//
-// \u5B89\u5BA4\u5948\u7F8E\u6075-with-SUPER-MONKEYS
-//
-// is encoded as:
-//
-// xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n
-//
-// Additional options are provided to allow unassigned IDN characters and
-// to validate according to the Std3ASCII Rules (like DNS names).
-//
-// There are also rules regarding bidirectionality of text and the length
-// of segments.
-//
-// For additional rules see also:
-// RFC 3490 - Internationalizing Domain Names in Applications (IDNA)
-// RFC 3491 - Nameprep: A Stringprep Profile for Internationalized Domain Names (IDN)
-// RFC 3492 - Punycode: A Bootstring encoding of Unicode for Internationalized Domain Names in Applications (IDNA)
-
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System.Globalization
-{
- // IdnMapping class used to map names to Punycode
- public sealed partial class IdnMapping
- {
- private bool _allowUnassigned;
- private bool _useStd3AsciiRules;
-
- public IdnMapping()
- {
- }
-
- public bool AllowUnassigned
- {
- get => _allowUnassigned;
- set => _allowUnassigned = value;
- }
-
- public bool UseStd3AsciiRules
- {
- get => _useStd3AsciiRules;
- set => _useStd3AsciiRules = value;
- }
-
- // Gets ASCII (Punycode) version of the string
- public string GetAscii(string unicode) =>
- GetAscii(unicode, 0);
-
- public string GetAscii(string unicode, int index)
- {
- if (unicode == null)
- throw new ArgumentNullException(nameof(unicode));
- return GetAscii(unicode, index, unicode.Length - index);
- }
-
- public string GetAscii(string unicode, int index, int count)
- {
- if (unicode == null)
- throw new ArgumentNullException(nameof(unicode));
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException((index < 0) ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (index > unicode.Length)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- if (index > unicode.Length - count)
- throw new ArgumentOutOfRangeException(nameof(unicode), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (count == 0)
- {
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(unicode));
- }
- if (unicode[index + count - 1] == 0)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidCharSequence, index + count - 1), nameof(unicode));
- }
-
- if (GlobalizationMode.Invariant)
- {
- return GetAsciiInvariant(unicode, index, count);
- }
-
- unsafe
- {
- fixed (char* pUnicode = unicode)
- {
- return GetAsciiCore(unicode, pUnicode + index, count);
- }
- }
- }
-
- // Gets Unicode version of the string. Normalized and limited to IDNA characters.
- public string GetUnicode(string ascii) =>
- GetUnicode(ascii, 0);
-
- public string GetUnicode(string ascii, int index)
- {
- if (ascii == null)
- throw new ArgumentNullException(nameof(ascii));
- return GetUnicode(ascii, index, ascii.Length - index);
- }
-
- public string GetUnicode(string ascii, int index, int count)
- {
- if (ascii == null)
- throw new ArgumentNullException(nameof(ascii));
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException((index < 0) ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (index > ascii.Length)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- if (index > ascii.Length - count)
- throw new ArgumentOutOfRangeException(nameof(ascii), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // This is a case (i.e. explicitly null-terminated input) where behavior in .NET and Win32 intentionally differ.
- // The .NET APIs should (and did in v4.0 and earlier) throw an ArgumentException on input that includes a terminating null.
- // The Win32 APIs fail on an embedded null, but not on a terminating null.
- if (count > 0 && ascii[index + count - 1] == (char)0)
- throw new ArgumentException(SR.Argument_IdnBadPunycode, nameof(ascii));
-
- if (GlobalizationMode.Invariant)
- {
- return GetUnicodeInvariant(ascii, index, count);
- }
-
- unsafe
- {
- fixed (char* pAscii = ascii)
- {
- return GetUnicodeCore(ascii, pAscii + index, count);
- }
- }
- }
-
- public override bool Equals(object? obj) =>
- obj is IdnMapping that &&
- _allowUnassigned == that._allowUnassigned &&
- _useStd3AsciiRules == that._useStd3AsciiRules;
-
- public override int GetHashCode() =>
- (_allowUnassigned ? 100 : 200) + (_useStd3AsciiRules ? 1000 : 2000);
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe string GetStringForOutput(string originalString, char* input, int inputLength, char* output, int outputLength) =>
- originalString.Length == inputLength && new ReadOnlySpan<char>(input, inputLength).SequenceEqual(new ReadOnlySpan<char>(output, outputLength)) ?
- originalString :
- new string(output, 0, outputLength);
-
- //
- // Invariant implementation
- //
-
- private const char c_delimiter = '-';
- private const string c_strAcePrefix = "xn--";
- private const int c_labelLimit = 63; // Not including dots
- private const int c_defaultNameLimit = 255; // Including dots
- private const int c_initialN = 0x80;
- private const int c_maxint = 0x7ffffff;
- private const int c_initialBias = 72;
- private const int c_punycodeBase = 36;
- private const int c_tmin = 1;
- private const int c_tmax = 26;
- private const int c_skew = 38;
- private const int c_damp = 700;
-
- // Legal "dot" separators (i.e: . in www.microsoft.com)
- private static readonly char[] s_dotSeparators = { '.', '\u3002', '\uFF0E', '\uFF61' };
-
- private string GetAsciiInvariant(string unicode, int index, int count)
- {
- if (index > 0 || count < unicode.Length)
- {
- unicode = unicode.Substring(index, count);
- }
-
- // Check for ASCII only string, which will be unchanged
- if (ValidateStd3AndAscii(unicode, UseStd3AsciiRules, true))
- {
- return unicode;
- }
-
- // Cannot be null terminated (normalization won't help us with this one, and
- // may have returned false before checking the whole string above)
- Debug.Assert(count >= 1, "[IdnMapping.GetAscii] Expected 0 length strings to fail before now.");
- if (unicode[^1] <= 0x1f)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidCharSequence, unicode.Length - 1), nameof(unicode));
- }
-
- // May need to check Std3 rules again for non-ascii
- if (UseStd3AsciiRules)
- {
- ValidateStd3AndAscii(unicode, true, false);
- }
-
- // Go ahead and encode it
- return PunycodeEncode(unicode);
- }
-
- // See if we're only ASCII
- private static bool ValidateStd3AndAscii(string unicode, bool bUseStd3, bool bCheckAscii)
- {
- // If its empty, then its too small
- if (unicode.Length == 0)
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(unicode));
-
- int iLastDot = -1;
-
- // Loop the whole string
- for (int i = 0; i < unicode.Length; i++)
- {
- // Aren't allowing control chars (or 7f, but idn tables catch that, they don't catch \0 at end though)
- if (unicode[i] <= 0x1f)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidCharSequence, i), nameof(unicode));
- }
-
- // If its Unicode or a control character, return false (non-ascii)
- if (bCheckAscii && unicode[i] >= 0x7f)
- return false;
-
- // Check for dots
- if (IsDot(unicode[i]))
- {
- // Can't have 2 dots in a row
- if (i == iLastDot + 1)
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(unicode));
-
- // If its too far between dots then fail
- if (i - iLastDot > c_labelLimit + 1)
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(unicode));
-
- // If validating Std3, then char before dot can't be - char
- if (bUseStd3 && i > 0)
- ValidateStd3(unicode[i - 1], true);
-
- // Remember where the last dot is
- iLastDot = i;
- continue;
- }
-
- // If necessary, make sure its a valid std3 character
- if (bUseStd3)
- {
- ValidateStd3(unicode[i], i == iLastDot + 1);
- }
- }
-
- // If we never had a dot, then we need to be shorter than the label limit
- if (iLastDot == -1 && unicode.Length > c_labelLimit)
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(unicode));
-
- // Need to validate entire string length, 1 shorter if last char wasn't a dot
- if (unicode.Length > c_defaultNameLimit - (IsDot(unicode[^1]) ? 0 : 1))
- throw new ArgumentException(SR.Format(SR.Argument_IdnBadNameSize,
- c_defaultNameLimit - (IsDot(unicode[^1]) ? 0 : 1)), nameof(unicode));
-
- // If last char wasn't a dot we need to check for trailing -
- if (bUseStd3 && !IsDot(unicode[^1]))
- ValidateStd3(unicode[^1], true);
-
- return true;
- }
-
- /* PunycodeEncode() converts Unicode to Punycode. The input */
- /* is represented as an array of Unicode code points (not code */
- /* units; surrogate pairs are not allowed), and the output */
- /* will be represented as an array of ASCII code points. The */
- /* output string is *not* null-terminated; it will contain */
- /* zeros if and only if the input contains zeros. (Of course */
- /* the caller can leave room for a terminator and add one if */
- /* needed.) The input_length is the number of code points in */
- /* the input. The output_length is an in/out argument: the */
- /* caller passes in the maximum number of code points that it */
-
- /* can receive, and on successful return it will contain the */
- /* number of code points actually output. The case_flags array */
- /* holds input_length boolean values, where nonzero suggests that */
- /* the corresponding Unicode character be forced to uppercase */
- /* after being decoded (if possible), and zero suggests that */
- /* it be forced to lowercase (if possible). ASCII code points */
- /* are encoded literally, except that ASCII letters are forced */
- /* to uppercase or lowercase according to the corresponding */
- /* uppercase flags. If case_flags is a null pointer then ASCII */
- /* letters are left as they are, and other code points are */
- /* treated as if their uppercase flags were zero. The return */
- /* value can be any of the punycode_status values defined above */
- /* except punycode_bad_input; if not punycode_success, then */
- /* output_size and output might contain garbage. */
- private static string PunycodeEncode(string unicode)
- {
- // 0 length strings aren't allowed
- if (unicode.Length == 0)
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(unicode));
-
- StringBuilder output = new StringBuilder(unicode.Length);
- int iNextDot = 0;
- int iAfterLastDot = 0;
- int iOutputAfterLastDot = 0;
-
- // Find the next dot
- while (iNextDot < unicode.Length)
- {
- // Find end of this segment
- iNextDot = unicode.IndexOfAny(s_dotSeparators, iAfterLastDot);
- Debug.Assert(iNextDot <= unicode.Length, "[IdnMapping.punycode_encode]IndexOfAny is broken");
- if (iNextDot < 0)
- iNextDot = unicode.Length;
-
- // Only allowed to have empty . section at end (www.microsoft.com.)
- if (iNextDot == iAfterLastDot)
- {
- // Only allowed to have empty sections as trailing .
- if (iNextDot != unicode.Length)
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(unicode));
- // Last dot, stop
- break;
- }
-
- // We'll need an Ace prefix
- output.Append(c_strAcePrefix);
-
- // Everything resets every segment.
- bool bRightToLeft = false;
-
- // Check for RTL. If right-to-left, then 1st & last chars must be RTL
- BidiCategory eBidi = CharUnicodeInfo.GetBidiCategory(unicode, iAfterLastDot);
- if (eBidi == BidiCategory.RightToLeft || eBidi == BidiCategory.RightToLeftArabic)
- {
- // It has to be right to left.
- bRightToLeft = true;
-
- // Check last char
- int iTest = iNextDot - 1;
- if (char.IsLowSurrogate(unicode, iTest))
- {
- iTest--;
- }
-
- eBidi = CharUnicodeInfo.GetBidiCategory(unicode, iTest);
- if (eBidi != BidiCategory.RightToLeft && eBidi != BidiCategory.RightToLeftArabic)
- {
- // Oops, last wasn't RTL, last should be RTL if first is RTL
- throw new ArgumentException(SR.Argument_IdnBadBidi, nameof(unicode));
- }
- }
-
- // Handle the basic code points
- int basicCount;
- int numProcessed = 0; // Num code points that have been processed so far (this segment)
- for (basicCount = iAfterLastDot; basicCount < iNextDot; basicCount++)
- {
- // Can't be lonely surrogate because it would've thrown in normalization
- Debug.Assert(!char.IsLowSurrogate(unicode, basicCount), "[IdnMapping.punycode_encode]Unexpected low surrogate");
-
- // Double check our bidi rules
- BidiCategory testBidi = CharUnicodeInfo.GetBidiCategory(unicode, basicCount);
-
- // If we're RTL, we can't have LTR chars
- if (bRightToLeft && testBidi == BidiCategory.LeftToRight)
- {
- // Oops, throw error
- throw new ArgumentException(SR.Argument_IdnBadBidi, nameof(unicode));
- }
-
- // If we're not RTL we can't have RTL chars
- if (!bRightToLeft && (testBidi == BidiCategory.RightToLeft || testBidi == BidiCategory.RightToLeftArabic))
- {
- // Oops, throw error
- throw new ArgumentException(SR.Argument_IdnBadBidi, nameof(unicode));
- }
-
- // If its basic then add it
- if (Basic(unicode[basicCount]))
- {
- output.Append(EncodeBasic(unicode[basicCount]));
- numProcessed++;
- }
- // If its a surrogate, skip the next since our bidi category tester doesn't handle it.
- else if (char.IsSurrogatePair(unicode, basicCount))
- basicCount++;
- }
-
- int numBasicCodePoints = numProcessed; // number of basic code points
-
- // Stop if we ONLY had basic code points
- if (numBasicCodePoints == iNextDot - iAfterLastDot)
- {
- // Get rid of xn-- and this segments done
- output.Remove(iOutputAfterLastDot, c_strAcePrefix.Length);
- }
- else
- {
- // If it has some non-basic code points the input cannot start with xn--
- if (unicode.Length - iAfterLastDot >= c_strAcePrefix.Length &&
- unicode.Substring(iAfterLastDot, c_strAcePrefix.Length).Equals(
- c_strAcePrefix, StringComparison.OrdinalIgnoreCase))
- throw new ArgumentException(SR.Argument_IdnBadPunycode, nameof(unicode));
-
- // Need to do ACE encoding
- int numSurrogatePairs = 0; // number of surrogate pairs so far
-
- // Add a delimiter (-) if we had any basic code points (between basic and encoded pieces)
- if (numBasicCodePoints > 0)
- {
- output.Append(c_delimiter);
- }
-
- // Initialize the state
- int n = c_initialN;
- int delta = 0;
- int bias = c_initialBias;
-
- // Main loop
- while (numProcessed < (iNextDot - iAfterLastDot))
- {
- /* All non-basic code points < n have been */
- /* handled already. Find the next larger one: */
- int j;
- int m;
- int test = 0;
- for (m = c_maxint, j = iAfterLastDot;
- j < iNextDot;
- j += IsSupplementary(test) ? 2 : 1)
- {
- test = char.ConvertToUtf32(unicode, j);
- if (test >= n && test < m) m = test;
- }
-
- /* Increase delta enough to advance the decoder's */
- /* <n,i> state to <m,0>, but guard against overflow: */
- delta += (int)((m - n) * ((numProcessed - numSurrogatePairs) + 1));
- Debug.Assert(delta > 0, "[IdnMapping.cs]1 punycode_encode - delta overflowed int");
- n = m;
-
- for (j = iAfterLastDot; j < iNextDot; j += IsSupplementary(test) ? 2 : 1)
- {
- // Make sure we're aware of surrogates
- test = char.ConvertToUtf32(unicode, j);
-
- // Adjust for character position (only the chars in our string already, some
- // haven't been processed.
-
- if (test < n)
- {
- delta++;
- Debug.Assert(delta > 0, "[IdnMapping.cs]2 punycode_encode - delta overflowed int");
- }
-
- if (test == n)
- {
- // Represent delta as a generalized variable-length integer:
- int q, k;
- for (q = delta, k = c_punycodeBase; ; k += c_punycodeBase)
- {
- int t = k <= bias ? c_tmin : k >= bias + c_tmax ? c_tmax : k - bias;
- if (q < t) break;
- Debug.Assert(c_punycodeBase != t, "[IdnMapping.punycode_encode]Expected c_punycodeBase (36) to be != t");
- output.Append(EncodeDigit(t + (q - t) % (c_punycodeBase - t)));
- q = (q - t) / (c_punycodeBase - t);
- }
-
- output.Append(EncodeDigit(q));
- bias = Adapt(delta, (numProcessed - numSurrogatePairs) + 1, numProcessed == numBasicCodePoints);
- delta = 0;
- numProcessed++;
-
- if (IsSupplementary(m))
- {
- numProcessed++;
- numSurrogatePairs++;
- }
- }
- }
- ++delta;
- ++n;
- Debug.Assert(delta > 0, "[IdnMapping.cs]3 punycode_encode - delta overflowed int");
- }
- }
-
- // Make sure its not too big
- if (output.Length - iOutputAfterLastDot > c_labelLimit)
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(unicode));
-
- // Done with this segment, add dot if necessary
- if (iNextDot != unicode.Length)
- output.Append('.');
-
- iAfterLastDot = iNextDot + 1;
- iOutputAfterLastDot = output.Length;
- }
-
- // Throw if we're too long
- if (output.Length > c_defaultNameLimit - (IsDot(unicode[^1]) ? 0 : 1))
- throw new ArgumentException(SR.Format(SR.Argument_IdnBadNameSize,
- c_defaultNameLimit - (IsDot(unicode[^1]) ? 0 : 1)), nameof(unicode));
- // Return our output string
- return output.ToString();
- }
-
- // Is it a dot?
- // are we U+002E (., full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), or
- // U+FF61 (halfwidth ideographic full stop).
- // Note: IDNA Normalization gets rid of dots now, but testing for last dot is before normalization
- private static bool IsDot(char c) =>
- c == '.' || c == '\u3002' || c == '\uFF0E' || c == '\uFF61';
-
- private static bool IsSupplementary(int cTest) =>
- cTest >= 0x10000;
-
- private static bool Basic(uint cp) =>
- // Is it in ASCII range?
- cp < 0x80;
-
- // Validate Std3 rules for a character
- private static void ValidateStd3(char c, bool bNextToDot)
- {
- // Check for illegal characters
- if (c <= ',' || c == '/' || (c >= ':' && c <= '@') || // Lots of characters not allowed
- (c >= '[' && c <= '`') || (c >= '{' && c <= (char)0x7F) ||
- (c == '-' && bNextToDot))
- throw new ArgumentException(SR.Format(SR.Argument_IdnBadStd3, c), nameof(c));
- }
-
- private string GetUnicodeInvariant(string ascii, int index, int count)
- {
- if (index > 0 || count < ascii.Length)
- {
- // We're only using part of the string
- ascii = ascii.Substring(index, count);
- }
- // Convert Punycode to Unicode
- string strUnicode = PunycodeDecode(ascii);
-
- // Output name MUST obey IDNA rules & round trip (casing differences are allowed)
- if (!ascii.Equals(GetAscii(strUnicode), StringComparison.OrdinalIgnoreCase))
- throw new ArgumentException(SR.Argument_IdnIllegalName, nameof(ascii));
-
- return strUnicode;
- }
-
- /* PunycodeDecode() converts Punycode to Unicode. The input is */
- /* represented as an array of ASCII code points, and the output */
- /* will be represented as an array of Unicode code points. The */
- /* input_length is the number of code points in the input. The */
- /* output_length is an in/out argument: the caller passes in */
- /* the maximum number of code points that it can receive, and */
- /* on successful return it will contain the actual number of */
- /* code points output. The case_flags array needs room for at */
- /* least output_length values, or it can be a null pointer if the */
- /* case information is not needed. A nonzero flag suggests that */
- /* the corresponding Unicode character be forced to uppercase */
- /* by the caller (if possible), while zero suggests that it be */
- /* forced to lowercase (if possible). ASCII code points are */
- /* output already in the proper case, but their flags will be set */
- /* appropriately so that applying the flags would be harmless. */
- /* The return value can be any of the punycode_status values */
- /* defined above; if not punycode_success, then output_length, */
- /* output, and case_flags might contain garbage. On success, the */
- /* decoder will never need to write an output_length greater than */
- /* input_length, because of how the encoding is defined. */
-
- private static string PunycodeDecode(string ascii)
- {
- // 0 length strings aren't allowed
- if (ascii.Length == 0)
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(ascii));
-
- // Throw if we're too long
- if (ascii.Length > c_defaultNameLimit - (IsDot(ascii[^1]) ? 0 : 1))
- throw new ArgumentException(SR.Format(SR.Argument_IdnBadNameSize,
- c_defaultNameLimit - (IsDot(ascii[^1]) ? 0 : 1)), nameof(ascii));
-
- // output stringbuilder
- StringBuilder output = new StringBuilder(ascii.Length);
-
- // Dot searching
- int iNextDot = 0;
- int iAfterLastDot = 0;
- int iOutputAfterLastDot = 0;
-
- while (iNextDot < ascii.Length)
- {
- // Find end of this segment
- iNextDot = ascii.IndexOf('.', iAfterLastDot);
- if (iNextDot < 0 || iNextDot > ascii.Length)
- iNextDot = ascii.Length;
-
- // Only allowed to have empty . section at end (www.microsoft.com.)
- if (iNextDot == iAfterLastDot)
- {
- // Only allowed to have empty sections as trailing .
- if (iNextDot != ascii.Length)
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(ascii));
-
- // Last dot, stop
- break;
- }
-
- // In either case it can't be bigger than segment size
- if (iNextDot - iAfterLastDot > c_labelLimit)
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(ascii));
-
- // See if this section's ASCII or ACE
- if (ascii.Length < c_strAcePrefix.Length + iAfterLastDot ||
- string.Compare(ascii, iAfterLastDot, c_strAcePrefix, 0, c_strAcePrefix.Length, StringComparison.OrdinalIgnoreCase) != 0)
- {
- // Its ASCII, copy it
- output.Append(ascii, iAfterLastDot, iNextDot - iAfterLastDot);
- }
- else
- {
- // Not ASCII, bump up iAfterLastDot to be after ACE Prefix
- iAfterLastDot += c_strAcePrefix.Length;
-
- // Get number of basic code points (where delimiter is)
- // numBasicCodePoints < 0 if there're no basic code points
- int iTemp = ascii.LastIndexOf(c_delimiter, iNextDot - 1);
-
- // Trailing - not allowed
- if (iTemp == iNextDot - 1)
- throw new ArgumentException(SR.Argument_IdnBadPunycode, nameof(ascii));
-
- int numBasicCodePoints;
- if (iTemp <= iAfterLastDot)
- numBasicCodePoints = 0;
- else
- {
- numBasicCodePoints = iTemp - iAfterLastDot;
-
- // Copy all the basic code points, making sure they're all in the allowed range,
- // and losing the casing for all of them.
- for (int copyAscii = iAfterLastDot; copyAscii < iAfterLastDot + numBasicCodePoints; copyAscii++)
- {
- // Make sure we don't allow unicode in the ascii part
- if (ascii[copyAscii] > 0x7f)
- throw new ArgumentException(SR.Argument_IdnBadPunycode, nameof(ascii));
-
- // When appending make sure they get lower cased
- output.Append((char)(ascii[copyAscii] >= 'A' && ascii[copyAscii] <= 'Z' ? ascii[copyAscii] - 'A' + 'a' : ascii[copyAscii]));
- }
- }
-
- // Get ready for main loop. Start at beginning if we didn't have any
- // basic code points, otherwise start after the -.
- // asciiIndex will be next character to read from ascii
- int asciiIndex = iAfterLastDot + (numBasicCodePoints > 0 ? numBasicCodePoints + 1 : 0);
-
- // initialize our state
- int n = c_initialN;
- int bias = c_initialBias;
- int i = 0;
-
- int w, k;
-
- // no Supplementary characters yet
- int numSurrogatePairs = 0;
-
- // Main loop, read rest of ascii
- while (asciiIndex < iNextDot)
- {
- /* Decode a generalized variable-length integer into delta, */
- /* which gets added to i. The overflow checking is easier */
- /* if we increase i as we go, then subtract off its starting */
- /* value at the end to obtain delta. */
- int oldi = i;
-
- for (w = 1, k = c_punycodeBase; ; k += c_punycodeBase)
- {
- // Check to make sure we aren't overrunning our ascii string
- if (asciiIndex >= iNextDot)
- throw new ArgumentException(SR.Argument_IdnBadPunycode, nameof(ascii));
-
- // decode the digit from the next char
- int digit = DecodeDigit(ascii[asciiIndex++]);
-
- Debug.Assert(w > 0, "[IdnMapping.punycode_decode]Expected w > 0");
- if (digit > (c_maxint - i) / w)
- throw new ArgumentException(SR.Argument_IdnBadPunycode, nameof(ascii));
-
- i += (int)(digit * w);
- int t = k <= bias ? c_tmin : k >= bias + c_tmax ? c_tmax : k - bias;
- if (digit < t)
- break;
- Debug.Assert(c_punycodeBase != t, "[IdnMapping.punycode_decode]Expected t != c_punycodeBase (36)");
- if (w > c_maxint / (c_punycodeBase - t))
- throw new ArgumentException(SR.Argument_IdnBadPunycode, nameof(ascii));
- w *= (c_punycodeBase - t);
- }
-
- bias = Adapt(i - oldi, (output.Length - iOutputAfterLastDot - numSurrogatePairs) + 1, oldi == 0);
-
- /* i was supposed to wrap around from output.Length to 0, */
- /* incrementing n each time, so we'll fix that now: */
- Debug.Assert((output.Length - iOutputAfterLastDot - numSurrogatePairs) + 1 > 0,
- "[IdnMapping.punycode_decode]Expected to have added > 0 characters this segment");
- if (i / ((output.Length - iOutputAfterLastDot - numSurrogatePairs) + 1) > c_maxint - n)
- throw new ArgumentException(SR.Argument_IdnBadPunycode, nameof(ascii));
- n += (int)(i / (output.Length - iOutputAfterLastDot - numSurrogatePairs + 1));
- i %= (output.Length - iOutputAfterLastDot - numSurrogatePairs + 1);
-
- // Make sure n is legal
- if (n < 0 || n > 0x10ffff || (n >= 0xD800 && n <= 0xDFFF))
- throw new ArgumentException(SR.Argument_IdnBadPunycode, nameof(ascii));
-
- // insert n at position i of the output: Really tricky if we have surrogates
- int iUseInsertLocation;
- string strTemp = char.ConvertFromUtf32(n);
-
- // If we have supplimentary characters
- if (numSurrogatePairs > 0)
- {
- // Hard way, we have supplimentary characters
- int iCount;
- for (iCount = i, iUseInsertLocation = iOutputAfterLastDot; iCount > 0; iCount--, iUseInsertLocation++)
- {
- // If its a surrogate, we have to go one more
- if (iUseInsertLocation >= output.Length)
- throw new ArgumentException(SR.Argument_IdnBadPunycode, nameof(ascii));
- if (char.IsSurrogate(output[iUseInsertLocation]))
- iUseInsertLocation++;
- }
- }
- else
- {
- // No Supplementary chars yet, just add i
- iUseInsertLocation = iOutputAfterLastDot + i;
- }
-
- // Insert it
- output.Insert(iUseInsertLocation, strTemp);
-
- // If it was a surrogate increment our counter
- if (IsSupplementary(n))
- numSurrogatePairs++;
-
- // Index gets updated
- i++;
- }
-
- // Do BIDI testing
- bool bRightToLeft = false;
-
- // Check for RTL. If right-to-left, then 1st & last chars must be RTL
- BidiCategory eBidi = CharUnicodeInfo.GetBidiCategory(output, iOutputAfterLastDot);
- if (eBidi == BidiCategory.RightToLeft || eBidi == BidiCategory.RightToLeftArabic)
- {
- // It has to be right to left.
- bRightToLeft = true;
- }
-
- // Check the rest of them to make sure RTL/LTR is consistent
- for (int iTest = iOutputAfterLastDot; iTest < output.Length; iTest++)
- {
- // This might happen if we run into a pair
- if (char.IsLowSurrogate(output[iTest]))
- continue;
-
- // Check to see if its LTR
- eBidi = CharUnicodeInfo.GetBidiCategory(output, iTest);
- if ((bRightToLeft && eBidi == BidiCategory.LeftToRight) ||
- (!bRightToLeft && (eBidi == BidiCategory.RightToLeft || eBidi == BidiCategory.RightToLeftArabic)))
- throw new ArgumentException(SR.Argument_IdnBadBidi, nameof(ascii));
- }
-
- // Its also a requirement that the last one be RTL if 1st is RTL
- if (bRightToLeft && eBidi != BidiCategory.RightToLeft && eBidi != BidiCategory.RightToLeftArabic)
- {
- // Oops, last wasn't RTL, last should be RTL if first is RTL
- throw new ArgumentException(SR.Argument_IdnBadBidi, nameof(ascii));
- }
- }
-
- // See if this label was too long
- if (iNextDot - iAfterLastDot > c_labelLimit)
- throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(ascii));
-
- // Done with this segment, add dot if necessary
- if (iNextDot != ascii.Length)
- output.Append('.');
-
- iAfterLastDot = iNextDot + 1;
- iOutputAfterLastDot = output.Length;
- }
-
- // Throw if we're too long
- if (output.Length > c_defaultNameLimit - (IsDot(output[output.Length - 1]) ? 0 : 1))
- throw new ArgumentException(SR.Format(SR.Argument_IdnBadNameSize, c_defaultNameLimit - (IsDot(output[output.Length - 1]) ? 0 : 1)), nameof(ascii));
-
- // Return our output string
- return output.ToString();
- }
-
- // DecodeDigit(cp) returns the numeric value of a basic code */
- // point (for use in representing integers) in the range 0 to */
- // c_punycodeBase-1, or <0 if cp is does not represent a value. */
-
- private static int DecodeDigit(char cp)
- {
- if (cp >= '0' && cp <= '9')
- return cp - '0' + 26;
-
- // Two flavors for case differences
- if (cp >= 'a' && cp <= 'z')
- return cp - 'a';
-
- if (cp >= 'A' && cp <= 'Z')
- return cp - 'A';
-
- // Expected 0-9, A-Z or a-z, everything else is illegal
- throw new ArgumentException(SR.Argument_IdnBadPunycode, nameof(cp));
- }
-
- private static int Adapt(int delta, int numpoints, bool firsttime)
- {
- uint k;
-
- delta = firsttime ? delta / c_damp : delta / 2;
- Debug.Assert(numpoints != 0, "[IdnMapping.adapt]Expected non-zero numpoints.");
- delta += delta / numpoints;
-
- for (k = 0; delta > ((c_punycodeBase - c_tmin) * c_tmax) / 2; k += c_punycodeBase)
- {
- delta /= c_punycodeBase - c_tmin;
- }
-
- Debug.Assert(delta + c_skew != 0, "[IdnMapping.adapt]Expected non-zero delta+skew.");
- return (int)(k + (c_punycodeBase - c_tmin + 1) * delta / (delta + c_skew));
- }
-
- /* EncodeBasic(bcp,flag) forces a basic code point to lowercase */
- /* if flag is false, uppercase if flag is true, and returns */
- /* the resulting code point. The code point is unchanged if it */
- /* is caseless. The behavior is undefined if bcp is not a basic */
- /* code point. */
-
- private static char EncodeBasic(char bcp)
- {
- if (HasUpperCaseFlag(bcp))
- bcp += (char)('a' - 'A');
-
- return bcp;
- }
-
- // Return whether a punycode code point is flagged as being upper case.
- private static bool HasUpperCaseFlag(char punychar) =>
- punychar >= 'A' && punychar <= 'Z';
-
- /* EncodeDigit(d,flag) returns the basic code point whose value */
- /* (when used for representing integers) is d, which needs to be in */
- /* the range 0 to punycodeBase-1. The lowercase form is used unless flag is */
- /* true, in which case the uppercase form is used. */
-
- private static char EncodeDigit(int d)
- {
- Debug.Assert(d >= 0 && d < c_punycodeBase, "[IdnMapping.encode_digit]Expected 0 <= d < punycodeBase");
- // 26-35 map to ASCII 0-9
- if (d > 25) return (char)(d - 26 + '0');
-
- // 0-25 map to a-z or A-Z
- return (char)(d + 'a');
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/InternalGlobalizationHelper.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/InternalGlobalizationHelper.cs
deleted file mode 100644
index c49b34accd7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/InternalGlobalizationHelper.cs
+++ /dev/null
@@ -1,48 +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.
-
-namespace System.Globalization
-{
- internal static class InternalGlobalizationHelper
- {
- // Copied from the TimeSpan to be used inside the globalization code and avoid internal dependency on TimeSpan class
- internal static long TimeToTicks(int hour, int minute, int second)
- {
- // totalSeconds is bounded by 2^31 * 2^12 + 2^31 * 2^8 + 2^31,
- // which is less than 2^44, meaning we won't overflow totalSeconds.
- long totalSeconds = (long)hour * 3600 + (long)minute * 60 + (long)second;
- if (totalSeconds > MaxSeconds || totalSeconds < MinSeconds)
- throw new ArgumentOutOfRangeException(null, SR.Overflow_TimeSpanTooLong);
- return totalSeconds * TicksPerSecond;
- }
-
-
- //
- // Define needed constants so globalization code can be independant from any other types
- //
-
- internal const long TicksPerMillisecond = 10000;
- internal const long TicksPerTenthSecond = TicksPerMillisecond * 100;
- internal const long TicksPerSecond = TicksPerMillisecond * 1000; // 10,000,000
- internal const long MaxSeconds = long.MaxValue / TicksPerSecond;
- internal const long MinSeconds = long.MinValue / TicksPerSecond;
- private const int DaysPerYear = 365;
- private const int DaysPer4Years = DaysPerYear * 4 + 1; // 1461
- private const int DaysPer100Years = DaysPer4Years * 25 - 1; // 36524
- private const int DaysPer400Years = DaysPer100Years * 4 + 1; // 146097
- private const int DaysTo10000 = DaysPer400Years * 25 - 366; // 3652059
- private const long TicksPerMinute = TicksPerSecond * 60;
- private const long TicksPerHour = TicksPerMinute * 60;
- private const long TicksPerDay = TicksPerHour * 24;
- internal const long MaxTicks = DaysTo10000 * TicksPerDay - 1;
- internal const long MinTicks = 0;
- internal const long MaxMilliSeconds = long.MaxValue / TicksPerMillisecond;
- internal const long MinMilliSeconds = long.MinValue / TicksPerMillisecond;
-
- internal const int StringBuilderDefaultCapacity = 16;
-
- internal const long MaxOffset = TimeSpan.TicksPerHour * 14;
- internal const long MinOffset = -MaxOffset;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Unix.cs
deleted file mode 100644
index 0bbebba7742..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Unix.cs
+++ /dev/null
@@ -1,96 +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 System.Collections.Generic;
-using System.Diagnostics;
-
-namespace System.Globalization
-{
- public partial class JapaneseCalendar : Calendar
- {
- private static EraInfo[]? GetJapaneseEras()
- {
- if (GlobalizationMode.Invariant)
- {
- return null;
- }
-
- string[]? eraNames;
- if (!CalendarData.EnumCalendarInfo("ja-JP", CalendarId.JAPAN, CalendarDataType.EraNames, out eraNames))
- {
- return null;
- }
-
- string[]? abbrevEnglishEraNames;
- if (!CalendarData.EnumCalendarInfo("en", CalendarId.JAPAN, CalendarDataType.AbbrevEraNames, out abbrevEnglishEraNames))
- {
- return null;
- }
-
- List<EraInfo> eras = new List<EraInfo>();
- int lastMaxYear = GregorianCalendar.MaxYear;
-
- int latestEra = Interop.Globalization.GetLatestJapaneseEra();
- for (int i = latestEra; i >= 0; i--)
- {
- DateTime dt;
- if (!GetJapaneseEraStartDate(i, out dt))
- {
- return null;
- }
-
- if (dt < s_calendarMinValue)
- {
- // only populate the Eras that are valid JapaneseCalendar date times
- break;
- }
-
- eras.Add(new EraInfo(i, dt.Year, dt.Month, dt.Day, dt.Year - 1, 1, lastMaxYear - dt.Year + 1,
- eraNames![i], GetAbbreviatedEraName(eraNames, i), abbrevEnglishEraNames![i]));
-
- lastMaxYear = dt.Year;
- }
-
- // remap the Era numbers, now that we know how many there will be
- for (int i = 0; i < eras.Count; i++)
- {
- eras[i].era = eras.Count - i;
- }
-
- return eras.ToArray();
- }
-
- // PAL Layer ends here
-
- private static string GetAbbreviatedEraName(string[] eraNames, int eraIndex)
- {
- // This matches the behavior on Win32 - only returning the first character of the era name.
- // See Calendar.EraAsString(Int32) - https://msdn.microsoft.com/en-us/library/windows/apps/br206751.aspx
- return eraNames[eraIndex].Substring(0, 1);
- }
-
- private static bool GetJapaneseEraStartDate(int era, out DateTime dateTime)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- dateTime = default(DateTime);
-
- int startYear;
- int startMonth;
- int startDay;
- bool result = Interop.Globalization.GetJapaneseEraStartDate(
- era,
- out startYear,
- out startMonth,
- out startDay);
-
- if (result)
- {
- dateTime = new DateTime(startYear, startMonth, startDay);
- }
-
- return result;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Win32.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Win32.cs
deleted file mode 100644
index e70dc510804..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.Win32.cs
+++ /dev/null
@@ -1,198 +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 Internal.Win32;
-
-namespace System.Globalization
-{
- public partial class JapaneseCalendar : Calendar
- {
- private const string JapaneseErasHive = @"System\CurrentControlSet\Control\Nls\Calendars\Japanese\Eras";
-
- // We know about 5 built-in eras, however users may add additional era(s) from the
- // registry, by adding values to HKLM\SYSTEM\CurrentControlSet\Control\Nls\Calendars\Japanese\Eras
- //
- // Registry values look like:
- // yyyy.mm.dd=era_abbrev_english_englishabbrev
- //
- // Where yyyy.mm.dd is the registry value name, and also the date of the era start.
- // yyyy, mm, and dd are the year, month & day the era begins (4, 2 & 2 digits long)
- // era is the Japanese Era name
- // abbrev is the Abbreviated Japanese Era Name
- // english is the English name for the Era (unused)
- // englishabbrev is the Abbreviated English name for the era.
- // . is a delimiter, but the value of . doesn't matter.
- // '_' marks the space between the japanese era name, japanese abbreviated era name
- // english name, and abbreviated english names.
- private static EraInfo[]? GetJapaneseEras()
- {
- // Look in the registry key and see if we can find any ranges
- int iFoundEras = 0;
- EraInfo[]? registryEraRanges = null;
-
- try
- {
- // Need to access registry
- using (RegistryKey? key = Registry.LocalMachine.OpenSubKey(JapaneseErasHive))
- {
- // Abort if we didn't find anything
- if (key == null) return null;
-
- // Look up the values in our reg key
- string[] valueNames = key.GetValueNames();
- if (valueNames != null && valueNames.Length > 0)
- {
- registryEraRanges = new EraInfo[valueNames.Length];
-
- // Loop through the registry and read in all the values
- for (int i = 0; i < valueNames.Length; i++)
- {
- // See if the era is a valid date
- EraInfo? era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i])?.ToString());
-
- // continue if not valid
- if (era == null) continue;
-
- // Remember we found one.
- registryEraRanges[iFoundEras] = era;
- iFoundEras++;
- }
- }
- }
- }
- catch (System.Security.SecurityException)
- {
- // If we weren't allowed to read, then just ignore the error
- return null;
- }
- catch (System.IO.IOException)
- {
- // If key is being deleted just ignore the error
- return null;
- }
- catch (System.UnauthorizedAccessException)
- {
- // Registry access rights permissions, just ignore the error
- return null;
- }
-
- //
- // If we didn't have valid eras, then fail
- // should have at least 5 eras
- //
- if (iFoundEras < 5) return null;
-
- //
- // Now we have eras, clean them up.
- //
- // Clean up array length
- Array.Resize(ref registryEraRanges, iFoundEras);
-
- // Sort them
- Array.Sort(registryEraRanges, CompareEraRanges);
-
- // Clean up era information
- for (int i = 0; i < registryEraRanges.Length; i++)
- {
- // eras count backwards from length to 1 (and are 1 based indexes into string arrays)
- registryEraRanges[i].era = registryEraRanges.Length - i;
-
- // update max era year
- if (i == 0)
- {
- // First range is 'til the end of the calendar
- registryEraRanges[0].maxEraYear = GregorianCalendar.MaxYear - registryEraRanges[0].yearOffset;
- }
- else
- {
- // Rest are until the next era (remember most recent era is first in array)
- registryEraRanges[i].maxEraYear = registryEraRanges[i - 1].yearOffset + 1 - registryEraRanges[i].yearOffset;
- }
- }
-
- // Return our ranges
- return registryEraRanges;
- }
-
- //
- // Compare two era ranges, eg just the ticks
- // Remember the era array is supposed to be in reverse chronological order
- //
- private static int CompareEraRanges(EraInfo a, EraInfo b)
- {
- return b.ticks.CompareTo(a.ticks);
- }
-
- //
- // GetEraFromValue
- //
- // Parse the registry value name/data pair into an era
- //
- // Registry values look like:
- // yyyy.mm.dd=era_abbrev_english_englishabbrev
- //
- // Where yyyy.mm.dd is the registry value name, and also the date of the era start.
- // yyyy, mm, and dd are the year, month & day the era begins (4, 2 & 2 digits long)
- // era is the Japanese Era name
- // abbrev is the Abbreviated Japanese Era Name
- // english is the English name for the Era (unused)
- // englishabbrev is the Abbreviated English name for the era.
- // . is a delimiter, but the value of . doesn't matter.
- // '_' marks the space between the japanese era name, japanese abbreviated era name
- // english name, and abbreviated english names.
- private static EraInfo? GetEraFromValue(string? value, string? data)
- {
- // Need inputs
- if (value == null || data == null) return null;
-
- //
- // Get Date
- //
- // Need exactly 10 characters in name for date
- // yyyy.mm.dd although the . can be any character
- if (value.Length != 10) return null;
-
- int year;
- int month;
- int day;
-
- ReadOnlySpan<char> valueSpan = value.AsSpan();
- if (!int.TryParse(valueSpan.Slice(0, 4), NumberStyles.None, NumberFormatInfo.InvariantInfo, out year) ||
- !int.TryParse(valueSpan.Slice(5, 2), NumberStyles.None, NumberFormatInfo.InvariantInfo, out month) ||
- !int.TryParse(valueSpan.Slice(8, 2), NumberStyles.None, NumberFormatInfo.InvariantInfo, out day))
- {
- // Couldn't convert integer, fail
- return null;
- }
-
- //
- // Get Strings
- //
- // Needs to be a certain length e_a_E_A at least (7 chars, exactly 4 groups)
- string[] names = data.Split('_');
-
- // Should have exactly 4 parts
- // 0 - Era Name
- // 1 - Abbreviated Era Name
- // 2 - English Era Name
- // 3 - Abbreviated English Era Name
- if (names.Length != 4) return null;
-
- // Each part should have data in it
- if (names[0].Length == 0 ||
- names[1].Length == 0 ||
- names[2].Length == 0 ||
- names[3].Length == 0)
- return null;
-
- //
- // Now we have an era we can build
- // Note that the era # and max era year need cleaned up after sorting
- // Don't use the full English Era Name (names[2])
- //
- return new EraInfo(0, year, month, day, year - 1, 1, 0,
- names[0], names[1], names[3]);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.cs
deleted file mode 100644
index eae8fa0bc87..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseCalendar.cs
+++ /dev/null
@@ -1,294 +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.
-
-namespace System.Globalization
-{
- /// <summary>
- /// JapaneseCalendar is based on Gregorian calendar. The month and day values are the same as
- /// Gregorian calendar. However, the year value is an offset to the Gregorian
- /// year based on the era.
- ///
- /// This system is adopted by Emperor Meiji in 1868. The year value is counted based on the reign of an emperor,
- /// and the era begins on the day an emperor ascends the throne and continues until his death or his abdication.
- /// The era changes at 12:00AM.
- ///
- /// For example, the current era is Reiwa. It started on 2019/5/1 A.D. Therefore, Gregorian year 2019 is also Reiwa 1st.
- /// 2019/5/1 A.D. is also Reiwa 1st 5/1.
- ///
- /// Any date in the year during which era is changed can be reckoned in either era. For example,
- /// 2019/1/1 can be 1/1 Reiwa 1st year or 1/1 Heisei 31st year.
- ///
- /// Note:
- /// The DateTime can be represented by the JapaneseCalendar are limited to two factors:
- /// 1. The min value and max value of DateTime class.
- /// 2. The available era information.
- /// </summary>
- /// <remarks>
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 1868/09/08 9999/12/31
- /// Japanese Meiji 01/01 Reiwa 7981/12/31
- /// </remarks>
- public partial class JapaneseCalendar : Calendar
- {
- private static readonly DateTime s_calendarMinValue = new DateTime(1868, 9, 8);
-
- public override DateTime MinSupportedDateTime => s_calendarMinValue;
-
- public override DateTime MaxSupportedDateTime => DateTime.MaxValue;
-
- public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.SolarCalendar;
-
- // Using a field initializer rather than a static constructor so that the whole class can be lazy
- // init.
- private static volatile EraInfo[]? s_japaneseEraInfo;
-
- // m_EraInfo must be listed in reverse chronological order. The most recent era
- // should be the first element.
- // That is, m_EraInfo[0] contains the most recent era.
- //
- // We know about 4 built-in eras, however users may add additional era(s) from the
- // registry, by adding values to HKLM\SYSTEM\CurrentControlSet\Control\Nls\Calendars\Japanese\Eras
- // we don't read the registry and instead we call WinRT to get the needed informatio
- //
- // Registry values look like:
- // yyyy.mm.dd=era_abbrev_english_englishabbrev
- //
- // Where yyyy.mm.dd is the registry value name, and also the date of the era start.
- // yyyy, mm, and dd are the year, month & day the era begins (4, 2 & 2 digits long)
- // era is the Japanese Era name
- // abbrev is the Abbreviated Japanese Era Name
- // english is the English name for the Era (unused)
- // englishabbrev is the Abbreviated English name for the era.
- // . is a delimiter, but the value of . doesn't matter.
- // '_' marks the space between the japanese era name, japanese abbreviated era name
- // english name, and abbreviated english names.
- internal static EraInfo[] GetEraInfo()
- {
- // See if we need to build it
- return s_japaneseEraInfo ??
- (s_japaneseEraInfo = GetJapaneseEras()) ??
- // See if we have to use the built-in eras
- (s_japaneseEraInfo = new EraInfo[]
- {
- new EraInfo(5, 2019, 5, 1, 2018, 1, GregorianCalendar.MaxYear - 2018, "\x4ee4\x548c", "\x4ee4", "R"),
- new EraInfo(4, 1989, 1, 8, 1988, 1, 2019 - 1988, "\x5e73\x6210", "\x5e73", "H"),
- new EraInfo(3, 1926, 12, 25, 1925, 1, 1989 - 1925, "\x662d\x548c", "\x662d", "S"),
- new EraInfo(2, 1912, 7, 30, 1911, 1, 1926 - 1911, "\x5927\x6b63", "\x5927", "T"),
- new EraInfo(1, 1868, 1, 1, 1867, 1, 1912 - 1867, "\x660e\x6cbb", "\x660e", "M")
- });
- }
-
- internal static volatile Calendar? s_defaultInstance;
- internal GregorianCalendarHelper _helper;
-
- internal static Calendar GetDefaultInstance() => s_defaultInstance ??= new JapaneseCalendar();
-
- public JapaneseCalendar()
- {
- try
- {
- new CultureInfo("ja-JP");
- }
- catch (ArgumentException e)
- {
- throw new TypeInitializationException(this.GetType().ToString(), e);
- }
-
- _helper = new GregorianCalendarHelper(this, GetEraInfo());
- }
-
- internal override CalendarId ID => CalendarId.JAPAN;
-
- public override DateTime AddMonths(DateTime time, int months)
- {
- return _helper.AddMonths(time, months);
- }
-
- public override DateTime AddYears(DateTime time, int years)
- {
- return _helper.AddYears(time, years);
- }
-
- public override int GetDaysInMonth(int year, int month, int era)
- {
- return _helper.GetDaysInMonth(year, month, era);
- }
-
- public override int GetDaysInYear(int year, int era)
- {
- return _helper.GetDaysInYear(year, era);
- }
-
- public override int GetDayOfMonth(DateTime time)
- {
- return _helper.GetDayOfMonth(time);
- }
-
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
- return _helper.GetDayOfWeek(time);
- }
-
- public override int GetDayOfYear(DateTime time)
- {
- return _helper.GetDayOfYear(time);
- }
-
- public override int GetMonthsInYear(int year, int era)
- {
- return _helper.GetMonthsInYear(year, era);
- }
-
- public override int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
- {
- return _helper.GetWeekOfYear(time, rule, firstDayOfWeek);
- }
-
- public override int GetEra(DateTime time)
- {
- return _helper.GetEra(time);
- }
-
- public override int GetMonth(DateTime time)
- {
- return _helper.GetMonth(time);
- }
-
- public override int GetYear(DateTime time)
- {
- return _helper.GetYear(time);
- }
-
- public override bool IsLeapDay(int year, int month, int day, int era)
- {
- return _helper.IsLeapDay(year, month, day, era);
- }
-
- public override bool IsLeapYear(int year, int era)
- {
- return _helper.IsLeapYear(year, era);
- }
-
- public override int GetLeapMonth(int year, int era)
- {
- return _helper.GetLeapMonth(year, era);
- }
-
- public override bool IsLeapMonth(int year, int month, int era)
- {
- return _helper.IsLeapMonth(year, month, era);
- }
-
-
- public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- return _helper.ToDateTime(year, month, day, hour, minute, second, millisecond, era);
- }
-
- /// <summary>
- /// For Japanese calendar, four digit year is not used. Few emperors will live for more than one hundred years.
- /// Therefore, for any two digit number, we just return the original number.
- /// </summary>
- public override int ToFourDigitYear(int year)
- {
- if (year <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.ArgumentOutOfRange_NeedPosNum);
- }
- if (year > _helper.MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, _helper.MaxYear));
- }
-
- return year;
- }
-
-
- public override int[] Eras => _helper.Eras;
-
- /// <summary>
- /// Return the various era strings
- /// Note: The arrays are backwards of the eras
- /// </summary>
- internal static string[] EraNames()
- {
- EraInfo[] eras = GetEraInfo();
- string[] eraNames = new string[eras.Length];
-
- for (int i = 0; i < eras.Length; i++)
- {
- // Strings are in chronological order, eras are backwards order.
- eraNames[i] = eras[eras.Length - i - 1].eraName!;
- }
-
- return eraNames;
- }
-
- internal static string[] AbbrevEraNames()
- {
- EraInfo[] eras = GetEraInfo();
- string[] erasAbbrev = new string[eras.Length];
-
- for (int i = 0; i < eras.Length; i++)
- {
- // Strings are in chronological order, eras are backwards order.
- erasAbbrev[i] = eras[eras.Length - i - 1].abbrevEraName!;
- }
-
- return erasAbbrev;
- }
-
- internal static string[] EnglishEraNames()
- {
- EraInfo[] eras = GetEraInfo();
- string[] erasEnglish = new string[eras.Length];
-
- for (int i = 0; i < eras.Length; i++)
- {
- // Strings are in chronological order, eras are backwards order.
- erasEnglish[i] = eras[eras.Length - i - 1].englishEraName!;
- }
-
- return erasEnglish;
- }
-
- private const int DefaultTwoDigitYearMax = 99;
-
- internal override bool IsValidYear(int year, int era)
- {
- return _helper.IsValidYear(year, era);
- }
-
- public override int TwoDigitYearMax
- {
- get
- {
- if (_twoDigitYearMax == -1)
- {
- _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultTwoDigitYearMax);
- }
-
- return _twoDigitYearMax;
- }
- set
- {
- VerifyWritable();
- if (value < 99 || value > _helper.MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 99, _helper.MaxYear));
- }
-
- _twoDigitYearMax = value;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseLunisolarCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseLunisolarCalendar.cs
deleted file mode 100644
index 67162a8c541..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/JapaneseLunisolarCalendar.cs
+++ /dev/null
@@ -1,216 +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.
-
-namespace System.Globalization
-{
- /// <remarks>
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 1960/01/28 2050/01/22
- /// JapaneseLunisolar 1960/01/01 2049/12/29
- /// </remarks>
- public class JapaneseLunisolarCalendar : EastAsianLunisolarCalendar
- {
- public const int JapaneseEra = 1;
-
- private readonly GregorianCalendarHelper _helper;
-
- private const int MinLunisolarYear = 1960;
- private const int MaxLunisolarYear = 2049;
-
- private static readonly DateTime s_minDate = new DateTime(1960, 1, 28);
- private static readonly DateTime s_maxDate = new DateTime((new DateTime(2050, 1, 22, 23, 59, 59, 999)).Ticks + 9999);
-
- public override DateTime MinSupportedDateTime => s_minDate;
-
- public override DateTime MaxSupportedDateTime => s_maxDate;
-
- protected override int DaysInYearBeforeMinSupportedYear =>
- // 1959 from ChineseLunisolarCalendar
- 354;
-
- // Data for years 1960-2049 matches output of Calendrical Calculations [1] and published calendar tables [2].
- // [1] Reingold, Edward M, and Nachum Dershowitz. Calendrical Calculations: The Ultimate Edition. Cambridge [etc.: Cambridge University Press, 2018. Print.
- // [2] Nishizawa, Yūsō. Rekijitsu Taikan: Meiji Kaireki 1873-Nen-2100-Nen Shinkyūreki, Kanshi Kyūsei Rokuyō Taishō. Tōkyō: Shin Jinbutsu Ōraisha, 1994. Print.
- private static readonly int[,] s_yinfo =
- {
-/*Y LM Lmon Lday DaysPerMonth D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 D12 D13 #Days
-1960 */ { 06, 01, 28, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-1961 */ { 00, 02, 15, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1962 */ { 00, 02, 05, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-1963 */ { 04, 01, 25, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-1964 */ { 00, 02, 13, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1965 */ { 00, 02, 02, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 354
-1966 */ { 03, 01, 22, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 29 383
-1967 */ { 00, 02, 09, 0b1101100101010000 }, /* 30 30 29 30 30 29 29 30 29 30 29 30 355
-1968 */ { 07, 01, 30, 0b0110101010101000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 30 384
-1969 */ { 00, 02, 17, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1970 */ { 00, 02, 06, 0b1001101011010000 }, /* 30 29 29 30 30 29 30 29 30 30 29 30 355
-1971 */ { 05, 01, 27, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1972 */ { 00, 02, 15, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1973 */ { 00, 02, 03, 0b1010010011100000 }, /* 30 29 30 29 29 30 29 29 30 30 30 29 354
-1974 */ { 04, 01, 23, 0b1101001001101000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384
-1975 */ { 00, 02, 11, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-1976 */ { 08, 01, 31, 0b1101010101001000 }, /* 30 30 29 30 29 30 29 30 29 30 29 29 30 384
-1977 */ { 00, 02, 18, 0b1011010101000000 }, /* 30 29 30 30 29 30 29 30 29 30 29 29 354
-1978 */ { 00, 02, 07, 0b1101011010100000 }, /* 30 30 29 30 29 30 30 29 30 29 30 29 355
-1979 */ { 06, 01, 28, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 29 384
-1980 */ { 00, 02, 16, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1981 */ { 00, 02, 05, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1982 */ { 04, 01, 25, 0b1010010011011000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 30 384
-1983 */ { 00, 02, 13, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1984 */ { 10, 02, 02, 0b1011001001011000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384
-1985 */ { 00, 02, 20, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 354
-1986 */ { 00, 02, 09, 0b0110110101000000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 354
-1987 */ { 06, 01, 29, 0b1011010110101000 }, /* 30 29 30 30 29 30 29 30 30 29 30 29 30 385
-1988 */ { 00, 02, 18, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1989 */ { 00, 02, 06, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1990 */ { 05, 01, 27, 0b0100100110111000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 30 384
-1991 */ { 00, 02, 15, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1992 */ { 00, 02, 04, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-1993 */ { 03, 01, 23, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383
-1994 */ { 00, 02, 10, 0b1110101001010000 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 355
-1995 */ { 08, 01, 31, 0b0110110101001000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 30 384
-1996 */ { 00, 02, 19, 0b0101101011010000 }, /* 29 30 29 30 30 29 30 29 30 30 29 30 355
-1997 */ { 00, 02, 08, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1998 */ { 05, 01, 28, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 29 384
-1999 */ { 00, 02, 16, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-2000 */ { 00, 02, 05, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-2001 */ { 04, 01, 24, 0b1110010010101000 }, /* 30 30 30 29 29 30 29 29 30 29 30 29 30 384
-2002 */ { 00, 02, 12, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-2003 */ { 00, 02, 01, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 355
-2004 */ { 02, 01, 22, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-2005 */ { 00, 02, 09, 0b0101011011000000 }, /* 29 30 29 30 29 30 30 29 30 30 29 29 354
-2006 */ { 07, 01, 29, 0b1010101011011000 }, /* 30 29 30 29 30 29 30 29 30 30 29 30 30 385
-2007 */ { 00, 02, 18, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-2008 */ { 00, 02, 07, 0b1001001011010000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 354
-2009 */ { 05, 01, 26, 0b1100100101011000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 30 384
-2010 */ { 00, 02, 14, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-2011 */ { 00, 02, 03, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-2012 */ { 03, 01, 23, 0b1011101001010000 }, /* 30 29 30 30 30 29 30 29 29 30 29 30 29 384
-2013 */ { 00, 02, 10, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-2014 */ { 09, 01, 31, 0b0101010110101000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 30 384
-2015 */ { 00, 02, 19, 0b0100101110100000 }, /* 29 30 29 29 30 29 30 30 30 29 30 29 354
-2016 */ { 00, 02, 08, 0b1010010110110000 }, /* 30 29 30 29 29 30 29 30 30 29 30 30 355
-2017 */ { 05, 01, 28, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-2018 */ { 00, 02, 16, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-2019 */ { 00, 02, 05, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-2020 */ { 04, 01, 25, 0b1011010010101000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 30 384
-2021 */ { 00, 02, 12, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-2022 */ { 00, 02, 01, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-2023 */ { 02, 01, 22, 0b0101010110101000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 30 384
-2024 */ { 00, 02, 10, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-2025 */ { 06, 01, 29, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-2026 */ { 00, 02, 17, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-2027 */ { 00, 02, 07, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 354
-2028 */ { 05, 01, 27, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 29 383
-2029 */ { 00, 02, 13, 0b1101100100110000 }, /* 30 30 29 30 30 29 29 30 29 29 30 30 355
-2030 */ { 00, 02, 03, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-2031 */ { 03, 01, 23, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 29 384
-2032 */ { 00, 02, 11, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355
-2033 */ { 11, 01, 31, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-2034 */ { 00, 02, 19, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-2035 */ { 00, 02, 08, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-2036 */ { 06, 01, 28, 0b1101001001101000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384
-2037 */ { 00, 02, 15, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-2038 */ { 00, 02, 04, 0b1101010100100000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 354
-2039 */ { 05, 01, 24, 0b1101101010100000 }, /* 30 30 29 30 30 29 30 29 30 29 30 29 29 384
-2040 */ { 00, 02, 12, 0b1011011010100000 }, /* 30 29 30 30 29 30 30 29 30 29 30 29 355
-2041 */ { 00, 02, 01, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355
-2042 */ { 02, 01, 22, 0b0100101011011000 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 30 384
-2043 */ { 00, 02, 10, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-2044 */ { 07, 01, 30, 0b1010010010111000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384
-2045 */ { 00, 02, 17, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-2046 */ { 00, 02, 06, 0b1011001001010000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 354
-2047 */ { 05, 01, 26, 0b1011010100101000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 30 384
-2048 */ { 00, 02, 14, 0b0110110101000000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 354
-2049 */ { 00, 02, 02, 0b1010110110100000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 355
- */ };
-
- internal override int MinCalendarYear => MinLunisolarYear;
-
- internal override int MaxCalendarYear => MaxLunisolarYear;
-
- internal override DateTime MinDate => s_minDate;
-
- internal override DateTime MaxDate => s_maxDate;
-
- internal override EraInfo[]? CalEraInfo => JapaneseCalendar.GetEraInfo();
-
- internal override int GetYearInfo(int lunarYear, int index)
- {
- if (lunarYear < MinLunisolarYear || lunarYear > MaxLunisolarYear)
- {
- throw new ArgumentOutOfRangeException(
- "year",
- lunarYear,
- SR.Format(SR.ArgumentOutOfRange_Range, MinLunisolarYear, MaxLunisolarYear));
- }
-
- return s_yinfo[lunarYear - MinLunisolarYear, index];
- }
-
- internal override int GetYear(int year, DateTime time)
- {
- return _helper.GetYear(year, time);
- }
-
- internal override int GetGregorianYear(int year, int era)
- {
- return _helper.GetGregorianYear(year, era);
- }
-
- /// <summary>
- /// Trim off the eras that are before our date range
- /// </summary>
- private static EraInfo[] TrimEras(EraInfo[] baseEras)
- {
- EraInfo[] newEras = new EraInfo[baseEras.Length];
- int newIndex = 0;
-
- // Eras have most recent first, so start with that
- for (int i = 0; i < baseEras.Length; i++)
- {
- // If this one's minimum year is bigger than our maximum year
- // then we can't use it.
- if (baseEras[i].yearOffset + baseEras[i].minEraYear >= MaxLunisolarYear)
- {
- // skip this one.
- continue;
- }
-
- // If this one's maximum era is less than our minimum era
- // then we've gotten too low in the era #s, so we're done
- if (baseEras[i].yearOffset + baseEras[i].maxEraYear < MinLunisolarYear)
- {
- break;
- }
-
- // Wasn't too large or too small, can use this one
- newEras[newIndex] = baseEras[i];
- newIndex++;
- }
-
- // If we didn't copy any then something was wrong, just return base
- if (newIndex == 0) return baseEras;
-
- Array.Resize(ref newEras!, newIndex);
- return newEras;
- }
-
- public JapaneseLunisolarCalendar()
- {
- _helper = new GregorianCalendarHelper(this, TrimEras(JapaneseCalendar.GetEraInfo()));
- }
-
- public override int GetEra(DateTime time) => _helper.GetEra(time);
-
- internal override CalendarId BaseCalendarID => CalendarId.JAPAN;
-
- internal override CalendarId ID => CalendarId.JAPANESELUNISOLAR;
-
- public override int[] Eras => _helper.Eras;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/JulianCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/JulianCalendar.cs
deleted file mode 100644
index fca11fe43c8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/JulianCalendar.cs
+++ /dev/null
@@ -1,371 +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.
-
-namespace System.Globalization
-{
- /// <summary>
- /// This class implements the Julian calendar. In 48 B.C. Julius Caesar
- /// ordered a calendar reform, and this calendar is called Julian calendar.
- /// It consisted of a solar year of twelve months and of 365 days with an
- /// extra day every fourth year.
- /// </summary>
- /// <remarks>
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 0001/01/01 9999/12/31
- /// Julia 0001/01/03 9999/10/19
- /// </remarks>
- public class JulianCalendar : Calendar
- {
- public static readonly int JulianEra = 1;
-
- private const int DatePartYear = 0;
- private const int DatePartDayOfYear = 1;
- private const int DatePartMonth = 2;
- private const int DatePartDay = 3;
-
- // Number of days in a non-leap year
- private const int JulianDaysPerYear = 365;
-
- // Number of days in 4 years
- private const int JulianDaysPer4Years = JulianDaysPerYear * 4 + 1;
-
- private static readonly int[] s_daysToMonth365 =
- {
- 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
- };
-
- private static readonly int[] s_daysToMonth366 =
- {
- 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366
- };
-
- // Gregorian Calendar 9999/12/31 = Julian Calendar 9999/10/19
- // keep it as variable field for serialization compat.
- internal int MaxYear = 9999;
-
- public override DateTime MinSupportedDateTime => DateTime.MinValue;
-
- public override DateTime MaxSupportedDateTime => DateTime.MaxValue;
-
- public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.SolarCalendar;
-
- public JulianCalendar()
- {
- // There is no system setting of TwoDigitYear max, so set the value here.
- _twoDigitYearMax = 2029;
- }
-
- internal override CalendarId ID => CalendarId.JULIAN;
-
- internal static void CheckEraRange(int era)
- {
- if (era != CurrentEra && era != JulianEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- }
-
- internal void CheckYearEraRange(int year, int era)
- {
- CheckEraRange(era);
- if (year <= 0 || year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxYear));
- }
- }
-
- internal static void CheckMonthRange(int month)
- {
- if (month < 1 || month > 12)
- {
- throw new ArgumentOutOfRangeException(nameof(month), month, SR.ArgumentOutOfRange_Month);
- }
- }
-
- /// <summary>
- /// Check for if the day value is valid.
- /// </summary>
- /// <remarks>
- /// Before calling this method, call CheckYearEraRange()/CheckMonthRange() to make
- /// sure year/month values are correct.
- /// </remarks>
- internal static void CheckDayRange(int year, int month, int day)
- {
- if (year == 1 && month == 1)
- {
- // The minimum supported Julia date is Julian 0001/01/03.
- if (day < 3)
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay);
- }
- }
-
- bool isLeapYear = (year % 4) == 0;
- int[] days = isLeapYear ? s_daysToMonth366 : s_daysToMonth365;
- int monthDays = days[month] - days[month - 1];
- if (day < 1 || day > monthDays)
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- day,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, monthDays));
- }
- }
-
- /// <summary>
- /// Returns a given date part of this DateTime. This method is used
- /// to compute the year, day-of-year, month, or day part.
- /// </summary>
- internal static int GetDatePart(long ticks, int part)
- {
- // Gregorian 1/1/0001 is Julian 1/3/0001. Remember DateTime(0) is refered to Gregorian 1/1/0001.
- // The following line convert Gregorian ticks to Julian ticks.
- long julianTicks = ticks + TicksPerDay * 2;
- // n = number of days since 1/1/0001
- int n = (int)(julianTicks / TicksPerDay);
- // y4 = number of whole 4-year periods within 100-year period
- int y4 = n / JulianDaysPer4Years;
- // n = day number within 4-year period
- n -= y4 * JulianDaysPer4Years;
- // y1 = number of whole years within 4-year period
- int y1 = n / JulianDaysPerYear;
- // Last year has an extra day, so decrement result if 4
- if (y1 == 4) y1 = 3;
- // If year was requested, compute and return it
- if (part == DatePartYear)
- {
- return y4 * 4 + y1 + 1;
- }
-
- // n = day number within year
- n -= y1 * JulianDaysPerYear;
- // If day-of-year was requested, return it
- if (part == DatePartDayOfYear)
- {
- return n + 1;
- }
-
- // Leap year calculation looks different from IsLeapYear since y1, y4,
- // and y100 are relative to year 1, not year 0
- bool leapYear = (y1 == 3);
- int[] days = leapYear ? s_daysToMonth366 : s_daysToMonth365;
- // All months have less than 32 days, so n >> 5 is a good conservative
- // estimate for the month
- int m = (n >> 5) + 1;
- // m = 1-based month number
- while (n >= days[m])
- {
- m++;
- }
-
- // If month was requested, return it
- if (part == DatePartMonth)
- {
- return m;
- }
-
- // Return 1-based day-of-month
- return n - days[m - 1] + 1;
- }
-
- /// <summary>
- /// Returns the tick count corresponding to the given year, month, and day.
- /// </summary>
- internal static long DateToTicks(int year, int month, int day)
- {
- int[] days = (year % 4 == 0) ? s_daysToMonth366 : s_daysToMonth365;
- int y = year - 1;
- int n = y * 365 + y / 4 + days[month - 1] + day - 1;
- // Gregorian 1/1/0001 is Julian 1/3/0001. n * TicksPerDay is the ticks in JulianCalendar.
- // Therefore, we subtract two days in the following to convert the ticks in JulianCalendar
- // to ticks in Gregorian calendar.
- return (n - 2) * TicksPerDay;
- }
-
- public override DateTime AddMonths(DateTime time, int months)
- {
- if (months < -120000 || months > 120000)
- {
- throw new ArgumentOutOfRangeException(
- nameof(months),
- months,
- SR.Format(SR.ArgumentOutOfRange_Range, -120000, 120000));
- }
-
- int y = GetDatePart(time.Ticks, DatePartYear);
- int m = GetDatePart(time.Ticks, DatePartMonth);
- int d = GetDatePart(time.Ticks, DatePartDay);
- int i = m - 1 + months;
- if (i >= 0)
- {
- m = i % 12 + 1;
- y += i / 12;
- }
- else
- {
- m = 12 + (i + 1) % 12;
- y += (i - 11) / 12;
- }
-
- int[] daysArray = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) ? s_daysToMonth366 : s_daysToMonth365;
- int days = daysArray[m] - daysArray[m - 1];
- if (d > days)
- {
- d = days;
- }
-
- long ticks = DateToTicks(y, m, d) + time.Ticks % TicksPerDay;
- Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
- return new DateTime(ticks);
- }
-
- public override DateTime AddYears(DateTime time, int years)
- {
- return AddMonths(time, years * 12);
- }
-
- public override int GetDayOfMonth(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartDay);
- }
-
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
- return (DayOfWeek)((int)(time.Ticks / TicksPerDay + 1) % 7);
- }
-
- public override int GetDayOfYear(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartDayOfYear);
- }
-
- public override int GetDaysInMonth(int year, int month, int era)
- {
- CheckYearEraRange(year, era);
- CheckMonthRange(month);
- int[] days = (year % 4 == 0) ? s_daysToMonth366 : s_daysToMonth365;
- return days[month] - days[month - 1];
- }
-
- public override int GetDaysInYear(int year, int era)
- {
- // Year/Era range is done in IsLeapYear().
- return IsLeapYear(year, era) ? 366 : 365;
- }
-
- public override int GetEra(DateTime time) => JulianEra;
-
- public override int GetMonth(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartMonth);
- }
-
- public override int[] Eras => new int[] { JulianEra };
-
- public override int GetMonthsInYear(int year, int era)
- {
- CheckYearEraRange(year, era);
- return 12;
- }
-
- public override int GetYear(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartYear);
- }
-
- public override bool IsLeapDay(int year, int month, int day, int era)
- {
- CheckMonthRange(month);
- // Year/Era range check is done in IsLeapYear().
- if (IsLeapYear(year, era))
- {
- CheckDayRange(year, month, day);
- return month == 2 && day == 29;
- }
-
- CheckDayRange(year, month, day);
- return false;
- }
-
- public override int GetLeapMonth(int year, int era)
- {
- CheckYearEraRange(year, era);
- return 0;
- }
-
- public override bool IsLeapMonth(int year, int month, int era)
- {
- CheckYearEraRange(year, era);
- CheckMonthRange(month);
- return false;
- }
-
- public override bool IsLeapYear(int year, int era)
- {
- CheckYearEraRange(year, era);
- return year % 4 == 0;
- }
-
- public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- CheckYearEraRange(year, era);
- CheckMonthRange(month);
- CheckDayRange(year, month, day);
- if (millisecond < 0 || millisecond >= MillisPerSecond)
- {
- throw new ArgumentOutOfRangeException(
- nameof(millisecond),
- millisecond,
- SR.Format(SR.ArgumentOutOfRange_Range, 0, MillisPerSecond - 1));
- }
-
- if (hour < 0 || hour >= 24 || minute < 0 || minute >= 60 || second < 0 || second >= 60)
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond);
- }
-
- return new DateTime(DateToTicks(year, month, day) + (new TimeSpan(0, hour, minute, second, millisecond)).Ticks);
- }
-
- public override int TwoDigitYearMax
- {
- get => _twoDigitYearMax;
- set
- {
- VerifyWritable();
- if (value < 99 || value > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 99, MaxYear));
- }
-
- _twoDigitYearMax = value;
- }
- }
-
- public override int ToFourDigitYear(int year)
- {
- if (year < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (year > MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Bounds_Lower_Upper, 1, MaxYear));
- }
-
- return base.ToFourDigitYear(year);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/KoreanCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/KoreanCalendar.cs
deleted file mode 100644
index d9ded694d88..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/KoreanCalendar.cs
+++ /dev/null
@@ -1,187 +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.
-
-namespace System.Globalization
-{
- /// <summary>
- /// Korean calendar is based on the Gregorian calendar. And the year is an offset to Gregorian calendar.
- /// That is,
- /// Korean year = Gregorian year + 2333. So 2000/01/01 A.D. is Korean 4333/01/01
- ///
- /// 0001/1/1 A.D. is Korean year 2334.
- /// </summary>
- /// <remarks>
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 0001/01/01 9999/12/31
- /// Korean 2334/01/01 12332/12/31
- /// </remarks>
- public class KoreanCalendar : Calendar
- {
- public const int KoreanEra = 1;
-
- // Since
- // Gregorian Year = Era Year + yearOffset
- // Gregorian Year 1 is Korean year 2334, so that
- // 1 = 2334 + yearOffset
- // So yearOffset = -2333
- // Gregorian year 2001 is Korean year 4334.
- private static readonly EraInfo[] s_koreanEraInfo = new EraInfo[]
- {
- new EraInfo(1, 1, 1, 1, -2333, 2334, GregorianCalendar.MaxYear + 2333) // era #, start year/month/day, yearOffset, minEraYear
- };
-
- private readonly GregorianCalendarHelper _helper;
-
- public override DateTime MinSupportedDateTime => DateTime.MinValue;
-
- public override DateTime MaxSupportedDateTime => DateTime.MaxValue;
-
- public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.SolarCalendar;
-
- public KoreanCalendar()
- {
- try
- {
- new CultureInfo("ko-KR");
- }
- catch (ArgumentException e)
- {
- throw new TypeInitializationException(GetType().ToString(), e);
- }
-
- _helper = new GregorianCalendarHelper(this, s_koreanEraInfo);
- }
-
- internal override CalendarId ID => CalendarId.KOREA;
-
-
- public override DateTime AddMonths(DateTime time, int months)
- {
- return _helper.AddMonths(time, months);
- }
-
- public override DateTime AddYears(DateTime time, int years)
- {
- return _helper.AddYears(time, years);
- }
-
- public override int GetDaysInMonth(int year, int month, int era)
- {
- return _helper.GetDaysInMonth(year, month, era);
- }
-
- public override int GetDaysInYear(int year, int era)
- {
- return _helper.GetDaysInYear(year, era);
- }
-
- public override int GetDayOfMonth(DateTime time)
- {
- return _helper.GetDayOfMonth(time);
- }
-
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
- return _helper.GetDayOfWeek(time);
- }
-
- public override int GetDayOfYear(DateTime time)
- {
- return _helper.GetDayOfYear(time);
- }
-
- public override int GetMonthsInYear(int year, int era)
- {
- return _helper.GetMonthsInYear(year, era);
- }
-
- public override int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
- {
- return _helper.GetWeekOfYear(time, rule, firstDayOfWeek);
- }
-
- public override int GetEra(DateTime time)
- {
- return _helper.GetEra(time);
- }
-
- public override int GetMonth(DateTime time)
- {
- return _helper.GetMonth(time);
- }
-
- public override int GetYear(DateTime time)
- {
- return _helper.GetYear(time);
- }
-
- public override bool IsLeapDay(int year, int month, int day, int era)
- {
- return _helper.IsLeapDay(year, month, day, era);
- }
-
- public override bool IsLeapYear(int year, int era)
- {
- return _helper.IsLeapYear(year, era);
- }
-
- public override int GetLeapMonth(int year, int era)
- {
- return _helper.GetLeapMonth(year, era);
- }
-
- public override bool IsLeapMonth(int year, int month, int era)
- {
- return _helper.IsLeapMonth(year, month, era);
- }
-
- public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- return _helper.ToDateTime(year, month, day, hour, minute, second, millisecond, era);
- }
-
- public override int[] Eras => _helper.Eras;
-
- private const int DefaultTwoDigitYearMax = 4362;
-
-
- public override int TwoDigitYearMax
- {
- get
- {
- if (_twoDigitYearMax == -1)
- {
- _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultTwoDigitYearMax);
- }
-
- return _twoDigitYearMax;
- }
- set
- {
- VerifyWritable();
- if (value < 99 || value > _helper.MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 99, _helper.MaxYear));
- }
-
- _twoDigitYearMax = value;
- }
- }
-
- public override int ToFourDigitYear(int year)
- {
- if (year < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return _helper.ToFourDigitYear(year, TwoDigitYearMax);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/KoreanLunisolarCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/KoreanLunisolarCalendar.cs
deleted file mode 100644
index 1d632cdc4fa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/KoreanLunisolarCalendar.cs
+++ /dev/null
@@ -1,1235 +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.
-
-namespace System.Globalization
-{
- /// <remarks>
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 918/02/19 2051/02/10
- /// KoreanLunisolar 918/01/01 2050/13/29
- /// </remarks>
- public class KoreanLunisolarCalendar : EastAsianLunisolarCalendar
- {
- public const int GregorianEra = 1;
-
- private const int MinLunisolarYear = 918;
- private const int MaxLunisolarYear = 2050;
-
- private static readonly DateTime s_minDate = new DateTime(918, 2, 19);
- private static readonly DateTime s_maxDate = new DateTime((new DateTime(2051, 2, 10, 23, 59, 59, 999)).Ticks + 9999);
-
- public override DateTime MinSupportedDateTime => s_minDate;
-
- public override DateTime MaxSupportedDateTime => s_maxDate;
-
- protected override int DaysInYearBeforeMinSupportedYear =>
- // 917 -- From http://emr.cs.iit.edu/home/reingold/calendar-book/Calendrica.html
- // using ChineseLunisolar
- 384;
-
- // Data for years 1391-2050 matches that available from
- // Korea Astronomy and Space Science Institute (KASI)
- // https://astro.kasi.re.kr:444/life/pageView/5
- private static readonly int[,] s_yinfo =
- {
-/*Y LM Lmon Lday DaysPerMonth D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 D12 D13 #Days
-0918 */ { 00, 02, 19, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 355
-0919 */ { 00, 02, 09, 0b0100010111010000 }, /* 29 30 29 29 29 30 29 30 30 30 29 30 354
-0920 */ { 06, 01, 29, 0b1010001011011000 }, /* 30 29 30 29 29 29 30 29 30 30 29 30 30 384
-0921 */ { 00, 02, 16, 0b1010001010110000 }, /* 30 29 30 29 29 29 30 29 30 29 30 30 354
-0922 */ { 00, 02, 05, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-0923 */ { 04, 01, 25, 0b1011010010101000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 30 384
-0924 */ { 00, 02, 13, 0b0110110100100000 }, /* 29 30 30 29 30 30 29 30 29 29 30 29 354
-0925 */ { 12, 02, 01, 0b1010110101100000 }, /* 30 29 30 29 30 30 29 30 29 30 30 29 29 384
-0926 */ { 00, 02, 20, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-0927 */ { 00, 02, 10, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 355
-0928 */ { 08, 01, 31, 0b0100010110111000 }, /* 29 30 29 29 29 30 29 30 30 29 30 30 30 384
-0929 */ { 00, 02, 18, 0b0100010101110000 }, /* 29 30 29 29 29 30 29 30 29 30 30 30 354
-0930 */ { 00, 02, 07, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-0931 */ { 05, 01, 27, 0b0110100101010000 }, /* 29 30 30 29 30 29 29 30 29 30 29 30 29 383
-0932 */ { 00, 02, 14, 0b1110100101010000 }, /* 30 30 30 29 30 29 29 30 29 30 29 30 355
-0933 */ { 00, 02, 03, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-0934 */ { 01, 01, 23, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-0935 */ { 00, 02, 11, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-0936 */ { 11, 02, 01, 0b0101001101100000 }, /* 29 30 29 30 29 29 30 30 29 30 30 29 29 383
-0937 */ { 00, 02, 18, 0b1100101011000000 }, /* 30 30 29 29 30 29 30 29 30 30 29 29 354
-0938 */ { 00, 02, 07, 0b1110010101100000 }, /* 30 30 30 29 29 30 29 30 29 30 30 29 355
-0939 */ { 07, 01, 28, 0b1101001010101000 }, /* 30 30 29 30 29 29 30 29 30 29 30 29 30 384
-0940 */ { 00, 02, 16, 0b1101001010100000 }, /* 30 30 29 30 29 29 30 29 30 29 30 29 354
-0941 */ { 00, 02, 04, 0b1101100101010000 }, /* 30 30 29 30 30 29 29 30 29 30 29 30 355
-0942 */ { 03, 01, 25, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-0943 */ { 00, 02, 13, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-0944 */ { 12, 02, 02, 0b1010011011010000 }, /* 30 29 30 29 29 30 30 29 30 30 29 30 29 384
-0945 */ { 00, 02, 20, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 355
-0946 */ { 00, 02, 10, 0b0100101011010000 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 354
-0947 */ { 07, 01, 30, 0b1010010011011000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 30 384
-0948 */ { 00, 02, 18, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-0949 */ { 00, 02, 06, 0b1011001001100000 }, /* 30 29 30 30 29 29 30 29 29 30 30 29 354
-0950 */ { 05, 01, 26, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-0951 */ { 00, 02, 14, 0b1011001101110000 }, /* 30 29 30 30 29 29 30 30 29 30 30 30 356
-0953 */ { 00, 01, 05, 0b1010101011010000 }, /* 30 29 30 29 30 29 30 29 30 30 29 30 355
-0953 */ { 01, 01, 23, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 29 384
-0954 */ { 00, 02, 11, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-0955 */ { 09, 02, 01, 0b0100101010111000 }, /* 29 30 29 29 30 29 30 29 30 29 30 30 30 384
-0956 */ { 00, 02, 20, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-0957 */ { 00, 02, 08, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-0958 */ { 07, 01, 28, 0b1010101010011000 }, /* 30 29 30 29 30 29 30 29 30 29 29 30 30 384
-0959 */ { 00, 02, 16, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-0960 */ { 00, 02, 05, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-0961 */ { 03, 01, 25, 0b0100110110101000 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 30 384
-0962 */ { 00, 02, 13, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-0963 */ { 12, 02, 02, 0b1001010101110000 }, /* 30 29 29 30 29 30 29 30 29 30 30 30 29 384
-0964 */ { 00, 02, 21, 0b1010001101110000 }, /* 30 29 30 29 29 29 30 30 29 30 30 30 355
-0965 */ { 00, 02, 10, 0b0101000101110000 }, /* 29 30 29 30 29 29 29 30 29 30 30 30 354
-0966 */ { 08, 01, 30, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 29 383
-0967 */ { 00, 02, 17, 0b1101010010110000 }, /* 30 30 29 30 29 30 29 29 30 29 30 30 355
-0968 */ { 00, 02, 07, 0b0101101010010000 }, /* 29 30 29 30 30 29 30 29 30 29 29 30 354
-0969 */ { 05, 01, 26, 0b0110101101010000 }, /* 29 30 30 29 30 29 30 30 29 30 29 30 29 384
-0970 */ { 00, 02, 14, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-0971 */ { 00, 02, 04, 0b0010101011100000 }, /* 29 29 30 29 30 29 30 29 30 30 30 29 354
-0972 */ { 02, 01, 24, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 29 384
-0973 */ { 00, 02, 11, 0b1010001011100000 }, /* 30 29 30 29 29 29 30 29 30 30 30 29 354
-0974 */ { 10, 01, 31, 0b1100100101101000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 30 384
-0975 */ { 00, 02, 19, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-0976 */ { 00, 02, 08, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-0977 */ { 07, 01, 27, 0b1101101010010000 }, /* 30 30 29 30 30 29 30 29 30 29 29 30 29 384
-0978 */ { 00, 02, 15, 0b1011010110100000 }, /* 30 29 30 30 29 30 29 30 30 29 30 29 355
-0979 */ { 00, 02, 05, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-0980 */ { 03, 01, 26, 0b0010101011011000 }, /* 29 29 30 29 30 29 30 29 30 30 29 30 30 384
-0981 */ { 00, 02, 13, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-0982 */ { 12, 02, 02, 0b1001001011011000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 30 384
-0983 */ { 00, 02, 21, 0b1001001010110000 }, /* 30 29 29 30 29 29 30 29 30 29 30 30 354
-0984 */ { 00, 02, 10, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-0985 */ { 09, 01, 29, 0b1011010010101000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 30 384
-0986 */ { 00, 02, 17, 0b1010110010100000 }, /* 30 29 30 29 30 30 29 29 30 29 30 29 354
-0987 */ { 00, 02, 06, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-0988 */ { 05, 01, 27, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 29 384
-0989 */ { 00, 02, 14, 0b0100101110110000 }, /* 29 30 29 29 30 29 30 30 30 29 30 30 355
-0990 */ { 00, 02, 04, 0b0010010110110000 }, /* 29 29 30 29 29 30 29 30 30 29 30 30 354
-0991 */ { 02, 01, 24, 0b1001001010111000 }, /* 30 29 29 30 29 29 30 29 30 29 30 30 30 384
-0992 */ { 00, 02, 12, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-0993 */ { 10, 01, 31, 0b0110100101011000 }, /* 29 30 30 29 30 29 29 30 29 30 29 30 30 384
-0994 */ { 00, 02, 19, 0b0101100101010000 }, /* 29 30 29 30 30 29 29 30 29 30 29 30 354
-0995 */ { 00, 02, 08, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-0996 */ { 07, 01, 28, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 29 384
-0997 */ { 00, 02, 15, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-0998 */ { 00, 02, 05, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-0999 */ { 03, 01, 25, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-1000 */ { 00, 02, 13, 0b0010010101110000 }, /* 29 29 30 29 29 30 29 30 29 30 30 30 354
-1001 */ { 12, 02, 03, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 29 383
-1002 */ { 00, 02, 21, 0b1101001010100000 }, /* 30 30 29 30 29 29 30 29 30 29 30 29 354
-1003 */ { 00, 02, 10, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 355
-1004 */ { 09, 01, 31, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-1005 */ { 00, 02, 18, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1006 */ { 00, 02, 07, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355
-1007 */ { 05, 01, 28, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1008 */ { 00, 02, 16, 0b0100101011010000 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 354
-1009 */ { 00, 02, 04, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1010 */ { 02, 01, 24, 0b1101001001101000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384
-1011 */ { 00, 02, 12, 0b1011001001100000 }, /* 30 29 30 30 29 29 30 29 29 30 30 29 354
-1012 */ { 10, 02, 01, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-1013 */ { 00, 02, 19, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-1014 */ { 00, 02, 09, 0b0011010110100000 }, /* 29 29 30 30 29 30 29 30 30 29 30 29 354
-1015 */ { 06, 01, 29, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 29 384
-1016 */ { 00, 02, 17, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1017 */ { 00, 02, 06, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1018 */ { 04, 01, 26, 0b1010010011011000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 30 384
-1019 */ { 00, 02, 14, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1020 */ { 12, 02, 03, 0b1010101001011000 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 30 384
-1021 */ { 00, 02, 21, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1022 */ { 00, 02, 10, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-1023 */ { 09, 01, 31, 0b0010110110101000 }, /* 29 29 30 29 30 30 29 30 30 29 30 29 30 384
-1024 */ { 00, 02, 19, 0b0010101101010000 }, /* 29 29 30 29 30 29 30 30 29 30 29 30 354
-1025 */ { 00, 02, 07, 0b1001010101110000 }, /* 30 29 29 30 29 30 29 30 29 30 30 30 355
-1026 */ { 05, 01, 28, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 29 383
-1027 */ { 00, 02, 15, 0b1100100101110000 }, /* 30 30 29 29 30 29 29 30 29 30 30 30 355
-1028 */ { 00, 02, 05, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-1029 */ { 02, 01, 24, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383
-1030 */ { 00, 02, 11, 0b1101101010010000 }, /* 30 30 29 30 30 29 30 29 30 29 29 30 355
-1031 */ { 10, 02, 01, 0b0110101101010000 }, /* 29 30 30 29 30 29 30 30 29 30 29 30 29 384
-1032 */ { 00, 02, 20, 0b0110011011010000 }, /* 29 30 30 29 29 30 30 29 30 30 29 30 355
-1033 */ { 00, 02, 09, 0b0010011011100000 }, /* 29 29 30 29 29 30 30 29 30 30 30 29 354
-1034 */ { 06, 01, 29, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 29 384
-1035 */ { 00, 02, 17, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1036 */ { 00, 02, 06, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-1037 */ { 04, 01, 25, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1038 */ { 00, 02, 13, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1039 */ { 12, 02, 02, 0b1101011010010000 }, /* 30 30 29 30 29 30 30 29 30 29 29 30 29 384
-1040 */ { 00, 02, 21, 0b1011010110000000 }, /* 30 29 30 30 29 30 29 30 30 29 29 29 354
-1041 */ { 00, 02, 09, 0b1101011010110000 }, /* 30 30 29 30 29 30 30 29 30 29 30 30 356
-1042 */ { 09, 01, 31, 0b0010011011011000 }, /* 29 29 30 29 29 30 30 29 30 30 29 30 30 384
-1043 */ { 00, 02, 19, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-1044 */ { 00, 02, 08, 0b1001001010110000 }, /* 30 29 29 30 29 29 30 29 30 29 30 30 354
-1045 */ { 05, 01, 27, 0b1010100101011000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 30 384
-1046 */ { 00, 02, 15, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1047 */ { 00, 02, 04, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-1048 */ { 01, 01, 24, 0b1011010101011000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 30 385
-1049 */ { 00, 02, 12, 0b0010110101010000 }, /* 29 29 30 29 30 30 29 30 29 30 29 30 354
-1050 */ { 11, 02, 01, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 29 384
-1051 */ { 00, 02, 20, 0b0100101110110000 }, /* 29 30 29 29 30 29 30 30 30 29 30 30 355
-1052 */ { 00, 02, 10, 0b0010010110110000 }, /* 29 29 30 29 29 30 29 30 30 29 30 30 354
-1053 */ { 07, 01, 29, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-1054 */ { 00, 02, 17, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1055 */ { 00, 02, 06, 0b0110100101010000 }, /* 29 30 30 29 30 29 29 30 29 30 29 30 354
-1056 */ { 03, 01, 26, 0b0110101010101000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 30 384
-1057 */ { 00, 02, 13, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1058 */ { 12, 02, 02, 0b1010101101011000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 30 385
-1059 */ { 00, 02, 22, 0b0010011101010000 }, /* 29 29 30 29 29 30 30 30 29 30 29 30 354
-1060 */ { 00, 02, 11, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-1061 */ { 08, 01, 30, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-1062 */ { 00, 02, 18, 0b1010010101100000 }, /* 30 29 30 29 29 30 29 30 29 30 30 29 354
-1063 */ { 00, 02, 07, 0b1101001001100000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 354
-1064 */ { 05, 01, 27, 0b1110100100110000 }, /* 30 30 30 29 30 29 29 30 29 29 30 30 29 384
-1065 */ { 00, 02, 14, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 355
-1066 */ { 00, 02, 04, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1067 */ { 01, 01, 24, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 29 384
-1068 */ { 00, 02, 12, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355
-1069 */ { 11, 02, 01, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1070 */ { 00, 02, 20, 0b0100100111010000 }, /* 29 30 29 29 30 29 29 30 30 30 29 30 354
-1071 */ { 00, 02, 09, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1072 */ { 07, 01, 29, 0b1101001001101000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384
-1073 */ { 00, 02, 16, 0b1010101001100000 }, /* 30 29 30 29 30 29 30 29 29 30 30 29 354
-1074 */ { 00, 02, 05, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1075 */ { 04, 01, 26, 0b0101011010101000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 30 384
-1076 */ { 00, 02, 14, 0b0011010110100000 }, /* 29 29 30 30 29 30 29 30 30 29 30 29 354
-1077 */ { 00, 02, 02, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 355
-1078 */ { 01, 01, 23, 0b0100101110011000 }, /* 29 30 29 29 30 29 30 30 30 29 29 30 30 384
-1079 */ { 00, 02, 11, 0b0100010110110000 }, /* 29 30 29 29 29 30 29 30 30 29 30 30 354
-1080 */ { 09, 01, 31, 0b1010010010111000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384
-1081 */ { 00, 02, 18, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-1082 */ { 00, 02, 07, 0b1010101001010000 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 354
-1083 */ { 06, 01, 27, 0b1011010101001000 }, /* 30 29 30 30 29 30 29 30 29 30 29 29 30 384
-1084 */ { 00, 02, 15, 0b0110101101010000 }, /* 29 30 30 29 30 29 30 30 29 30 29 30 355
-1085 */ { 00, 02, 04, 0b0010110110100000 }, /* 29 29 30 29 30 30 29 30 30 29 30 29 354
-1086 */ { 02, 01, 24, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 29 384
-1087 */ { 00, 02, 12, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 355
-1088 */ { 12, 02, 02, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 29 383
-1089 */ { 00, 02, 19, 0b1100100101110000 }, /* 30 30 29 29 30 29 29 30 29 30 30 30 355
-1090 */ { 00, 02, 09, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-1091 */ { 08, 01, 29, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383
-1092 */ { 00, 02, 16, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 355
-1093 */ { 00, 02, 05, 0b0101101101000000 }, /* 29 30 29 30 30 29 30 30 29 30 29 29 354
-1094 */ { 04, 01, 25, 0b1010101101101000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 30 385
-1095 */ { 00, 02, 14, 0b0010101011100000 }, /* 29 29 30 29 30 29 30 29 30 30 30 29 354
-1096 */ { 00, 02, 03, 0b1110011000010000 }, /* 30 30 30 29 29 30 30 29 29 29 29 30 354
-1097 */ { 02, 01, 22, 0b1100100101110000 }, /* 30 30 29 29 30 29 29 30 29 30 30 30 29 384
-1098 */ { 00, 02, 10, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-1099 */ { 09, 01, 30, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1100 */ { 00, 02, 18, 0b0101010010100000 }, /* 29 30 29 30 29 30 29 29 30 29 30 29 353
-1101 */ { 00, 02, 07, 0b1101011001010000 }, /* 30 30 29 30 29 30 30 29 29 30 29 30 355
-1102 */ { 06, 01, 28, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-1103 */ { 00, 02, 16, 0b0101010111010000 }, /* 29 30 29 30 29 30 29 30 30 30 29 30 355
-1104 */ { 00, 02, 06, 0b0010011011010000 }, /* 29 29 30 29 29 30 30 29 30 30 29 30 354
-1105 */ { 02, 01, 25, 0b1001001011101000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 30 384
-1106 */ { 00, 02, 13, 0b1001001010110000 }, /* 30 29 29 30 29 29 30 29 30 29 30 30 354
-1107 */ { 10, 02, 02, 0b1010100101011000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 30 384
-1108 */ { 00, 02, 21, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1109 */ { 00, 02, 09, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-1110 */ { 08, 01, 29, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-1111 */ { 00, 02, 17, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-1112 */ { 00, 02, 07, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 355
-1113 */ { 04, 01, 27, 0b0010010110111000 }, /* 29 29 30 29 29 30 29 30 30 29 30 30 30 384
-1114 */ { 00, 02, 15, 0b0100010101110000 }, /* 29 30 29 29 29 30 29 30 29 30 30 30 354
-1115 */ { 00, 02, 04, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1116 */ { 01, 01, 24, 0b1010100101011000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 30 384
-1117 */ { 00, 02, 11, 0b0110100101010000 }, /* 29 30 30 29 30 29 29 30 29 30 29 30 354
-1118 */ { 09, 01, 31, 0b0111001010101000 }, /* 29 30 30 30 29 29 30 29 30 29 30 29 30 384
-1119 */ { 00, 02, 19, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1120 */ { 00, 02, 08, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1121 */ { 05, 01, 28, 0b0100101101101000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 30 384
-1122 */ { 00, 02, 16, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-1123 */ { 00, 02, 05, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1124 */ { 03, 01, 26, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 29 383
-1125 */ { 00, 02, 12, 0b1101001001100000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 354
-1126 */ { 11, 02, 01, 0b1110100100110000 }, /* 30 30 30 29 30 29 29 30 29 29 30 30 29 384
-1127 */ { 00, 02, 20, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 355
-1128 */ { 00, 02, 10, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1129 */ { 08, 01, 29, 0b1001101110010000 }, /* 30 29 29 30 30 29 30 30 30 29 29 30 29 384
-1130 */ { 00, 02, 17, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355
-1131 */ { 00, 02, 07, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1132 */ { 04, 01, 27, 0b1010010011101000 }, /* 30 29 30 29 29 30 29 29 30 30 30 29 30 384
-1133 */ { 00, 02, 14, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1134 */ { 00, 02, 03, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-1135 */ { 02, 01, 23, 0b1101100100101000 }, /* 30 30 29 30 30 29 29 30 29 29 30 29 30 384
-1136 */ { 00, 02, 11, 0b1011010101000000 }, /* 30 29 30 30 29 30 29 30 29 30 29 29 354
-1137 */ { 10, 01, 30, 0b1101011010101000 }, /* 30 30 29 30 29 30 30 29 30 29 30 29 30 385
-1138 */ { 00, 02, 19, 0b0010110110100000 }, /* 29 29 30 29 30 30 29 30 30 29 30 29 354
-1139 */ { 00, 02, 08, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 355
-1140 */ { 06, 01, 29, 0b0100101011011000 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 30 384
-1141 */ { 00, 02, 16, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1142 */ { 00, 02, 05, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1143 */ { 04, 01, 25, 0b1011001001011000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384
-1144 */ { 00, 02, 13, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 354
-1145 */ { 11, 02, 01, 0b1011010100101000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 30 384
-1146 */ { 00, 02, 20, 0b0110101101000000 }, /* 29 30 30 29 30 29 30 30 29 30 29 29 354
-1147 */ { 00, 02, 09, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-1148 */ { 08, 01, 30, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 29 384
-1149 */ { 00, 02, 17, 0b1001100101110000 }, /* 30 29 29 30 30 29 29 30 29 30 30 30 355
-1150 */ { 00, 02, 07, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1151 */ { 04, 01, 27, 0b0110010010111000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 30 384
-1152 */ { 00, 02, 15, 0b0101010010110000 }, /* 29 30 29 30 29 30 29 29 30 29 30 30 354
-1153 */ { 12, 02, 03, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383
-1154 */ { 00, 02, 21, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 355
-1155 */ { 00, 02, 11, 0b0101101011000000 }, /* 29 30 29 30 30 29 30 29 30 30 29 29 354
-1156 */ { 10, 01, 31, 0b1010101101101000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 30 385
-1157 */ { 00, 02, 19, 0b0010011011100000 }, /* 29 29 30 29 29 30 30 29 30 30 30 29 354
-1158 */ { 00, 02, 08, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1159 */ { 06, 01, 28, 0b1100100101110000 }, /* 30 30 29 29 30 29 29 30 29 30 30 30 29 384
-1160 */ { 00, 02, 16, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-1161 */ { 00, 02, 04, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1162 */ { 02, 01, 24, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 29 384
-1163 */ { 00, 02, 12, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 355
-1164 */ { 11, 02, 02, 0b0101011010101000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 30 384
-1165 */ { 00, 02, 20, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 355
-1166 */ { 00, 02, 10, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-1167 */ { 07, 01, 30, 0b1001001011101000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 30 384
-1168 */ { 00, 02, 18, 0b1001001001110000 }, /* 30 29 29 30 29 29 30 29 29 30 30 30 354
-1169 */ { 00, 02, 06, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1170 */ { 05, 01, 26, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1171 */ { 00, 02, 14, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-1172 */ { 00, 02, 03, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1173 */ { 01, 01, 23, 0b0101011010101000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 30 384
-1174 */ { 00, 02, 11, 0b0100110110110000 }, /* 29 30 29 29 30 30 29 30 30 29 30 30 355
-1175 */ { 09, 02, 01, 0b0010010110110000 }, /* 29 29 30 29 29 30 29 30 30 29 30 30 29 383
-1176 */ { 00, 02, 19, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1177 */ { 00, 02, 08, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1178 */ { 06, 01, 28, 0b1010100101011000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 30 384
-1179 */ { 00, 02, 16, 0b0110100101010000 }, /* 29 30 30 29 30 29 29 30 29 30 29 30 354
-1180 */ { 00, 02, 05, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1181 */ { 03, 01, 24, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-1182 */ { 00, 02, 12, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1183 */ { 11, 02, 02, 0b0100101101101000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 30 384
-1184 */ { 00, 02, 21, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1185 */ { 00, 02, 09, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1186 */ { 07, 01, 30, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 29 383
-1187 */ { 00, 02, 17, 0b1101000010010000 }, /* 30 30 29 30 29 29 29 29 30 29 29 30 353
-1188 */ { 00, 01, 08, 0b0111010010011000 }, /* 29 30 30 30 29 30 29 29 30 29 29 30 354
-1189 */ { 05, 01, 26, 0b0110101010101000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 30 384
-1190 */ { 00, 02, 14, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1191 */ { 00, 02, 03, 0b1001101101010000 }, /* 30 29 29 30 30 29 30 30 29 30 29 30 355
-1192 */ { 02, 01, 24, 0b0100101101101000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 30 384
-1193 */ { 00, 02, 11, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1194 */ { 10, 01, 31, 0b1010010011101000 }, /* 30 29 30 29 29 30 29 29 30 30 30 29 30 384
-1195 */ { 00, 02, 19, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1196 */ { 00, 02, 08, 0b1101001001100000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 354
-1197 */ { 06, 01, 27, 0b1101010100101000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 30 384
-1198 */ { 00, 02, 15, 0b1011010100100000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 354
-1199 */ { 00, 02, 04, 0b1101011010100000 }, /* 30 30 29 30 29 30 30 29 30 29 30 29 355
-1200 */ { 02, 01, 25, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 29 384
-1201 */ { 00, 02, 12, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 355
-1202 */ { 12, 02, 02, 0b0100100111011000 }, /* 29 30 29 29 30 29 29 30 30 30 29 30 30 384
-1203 */ { 00, 02, 21, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1204 */ { 00, 02, 10, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1205 */ { 08, 01, 29, 0b1010101001011000 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 30 384
-1206 */ { 00, 02, 17, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 354
-1207 */ { 00, 02, 06, 0b1011010101000000 }, /* 30 29 30 30 29 30 29 30 29 30 29 29 354
-1208 */ { 04, 01, 26, 0b1011010110100000 }, /* 30 29 30 30 29 30 29 30 30 29 30 29 29 384
-1209 */ { 00, 02, 13, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-1210 */ { 00, 02, 03, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1211 */ { 02, 01, 24, 0b0100100110111000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 30 384
-1212 */ { 00, 02, 12, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1213 */ { 09, 01, 31, 0b0110010010111000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 30 384
-1214 */ { 00, 02, 19, 0b0101010010110000 }, /* 29 30 29 30 29 30 29 29 30 29 30 30 354
-1215 */ { 00, 02, 08, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 354
-1216 */ { 07, 01, 28, 0b0110110100101000 }, /* 29 30 30 29 30 30 29 30 29 29 30 29 30 384
-1217 */ { 00, 02, 15, 0b0101101011000000 }, /* 29 30 29 30 30 29 30 29 30 30 29 29 354
-1218 */ { 00, 02, 04, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-1219 */ { 03, 01, 25, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 29 384
-1220 */ { 00, 02, 13, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1221 */ { 12, 02, 01, 0b1100100101110000 }, /* 30 30 29 29 30 29 29 30 29 30 30 30 29 384
-1222 */ { 00, 02, 20, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-1223 */ { 00, 02, 09, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1224 */ { 08, 01, 29, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 29 384
-1225 */ { 00, 02, 16, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1226 */ { 00, 02, 06, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1227 */ { 05, 01, 26, 0b1010101011011000 }, /* 30 29 30 29 30 29 30 29 30 30 29 30 30 385
-1228 */ { 00, 02, 15, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-1229 */ { 00, 02, 03, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1230 */ { 02, 01, 23, 0b1100100101011000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 30 384
-1231 */ { 00, 02, 11, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1232 */ { 09, 01, 31, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1233 */ { 00, 02, 18, 0b1011001010100000 }, /* 30 29 30 30 29 29 30 29 30 29 30 29 354
-1234 */ { 00, 02, 07, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1235 */ { 07, 01, 28, 0b0101011010101000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 30 384
-1236 */ { 00, 02, 16, 0b0100110110100000 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 354
-1237 */ { 00, 02, 04, 0b1010010110110000 }, /* 30 29 30 29 29 30 29 30 30 29 30 30 355
-1238 */ { 04, 01, 25, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-1239 */ { 00, 02, 13, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1240 */ { 12, 02, 02, 0b1010100100111000 }, /* 30 29 30 29 30 29 29 30 29 29 30 30 30 384
-1241 */ { 00, 02, 20, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 354
-1242 */ { 00, 02, 09, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1243 */ { 08, 01, 29, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-1244 */ { 00, 02, 17, 0b1010111001010000 }, /* 30 29 30 29 30 30 30 29 29 30 29 30 355
-1245 */ { 00, 02, 06, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-1246 */ { 04, 01, 26, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-1247 */ { 00, 02, 14, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1248 */ { 00, 02, 04, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 354
-1249 */ { 02, 01, 23, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 29 383
-1250 */ { 00, 02, 10, 0b1110010100110000 }, /* 30 30 30 29 29 30 29 30 29 29 30 30 355
-1251 */ { 10, 01, 31, 0b0110110010011000 }, /* 29 30 30 29 30 30 29 29 30 29 29 30 30 384
-1252 */ { 00, 02, 19, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1253 */ { 00, 02, 07, 0b0101101011010000 }, /* 29 30 29 30 30 29 30 29 30 30 29 30 355
-1254 */ { 06, 01, 28, 0b0100101101101000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 30 384
-1255 */ { 00, 02, 16, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1256 */ { 00, 02, 05, 0b1010010011100000 }, /* 30 29 30 29 29 30 29 29 30 30 30 29 354
-1257 */ { 04, 01, 24, 0b1101001001101000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384
-1258 */ { 00, 02, 12, 0b1101001001100000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 354
-1259 */ { 11, 02, 01, 0b1101010100101000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 30 384
-1260 */ { 00, 02, 20, 0b1011010100100000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 354
-1261 */ { 00, 02, 08, 0b1011011010100000 }, /* 30 29 30 30 29 30 30 29 30 29 30 29 355
-1262 */ { 09, 01, 29, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 29 384
-1263 */ { 00, 02, 17, 0b0101010101110000 }, /* 29 30 29 30 29 30 29 30 29 30 30 30 355
-1264 */ { 00, 02, 07, 0b0100100111010000 }, /* 29 30 29 29 30 29 29 30 30 30 29 30 354
-1265 */ { 05, 01, 26, 0b1010010011011000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 30 384
-1266 */ { 00, 02, 14, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1267 */ { 00, 02, 03, 0b1010101001010000 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 354
-1268 */ { 01, 01, 23, 0b1011010100101000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 30 384
-1269 */ { 00, 02, 10, 0b1011010100100000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 354
-1270 */ { 11, 01, 30, 0b1011010111000000 }, /* 30 29 30 30 29 30 29 30 30 30 29 29 29 384
-1271 */ { 00, 02, 18, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-1272 */ { 00, 02, 08, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1273 */ { 06, 01, 28, 0b0100100110111000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 30 384
-1274 */ { 00, 02, 16, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1275 */ { 00, 02, 05, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-1276 */ { 03, 01, 25, 0b0110101001011000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 30 384
-1277 */ { 00, 02, 12, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 354
-1278 */ { 11, 02, 01, 0b0110101100101000 }, /* 29 30 30 29 30 29 30 30 29 29 30 29 30 384
-1279 */ { 00, 02, 20, 0b0101101011000000 }, /* 29 30 29 30 30 29 30 29 30 30 29 29 354
-1280 */ { 00, 02, 09, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-1281 */ { 08, 01, 29, 0b0010101011101000 }, /* 29 29 30 29 30 29 30 29 30 30 30 29 30 384
-1282 */ { 00, 02, 17, 0b0100100111100000 }, /* 29 30 29 29 30 29 29 30 30 30 30 29 354
-1283 */ { 00, 02, 06, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1284 */ { 05, 01, 26, 0b1101001001011000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 30 384
-1285 */ { 00, 02, 13, 0b1011001001010000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 354
-1286 */ { 00, 02, 02, 0b1011010100100000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 354
-1287 */ { 02, 01, 22, 0b1111001010010000 }, /* 30 30 30 30 29 29 30 29 30 29 29 30 29 384
-1288 */ { 00, 02, 10, 0b1011010110100000 }, /* 30 29 30 30 29 30 29 30 30 29 30 29 355
-1289 */ { 10, 01, 30, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 29 384
-1290 */ { 00, 02, 18, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1291 */ { 00, 02, 08, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1292 */ { 06, 01, 28, 0b1010010010111000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384
-1293 */ { 00, 02, 15, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1294 */ { 00, 02, 04, 0b1010101001010000 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 354
-1295 */ { 04, 01, 24, 0b1011010100101000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 30 384
-1296 */ { 00, 02, 12, 0b0110110101000000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 354
-1297 */ { 12, 01, 31, 0b1010110101100000 }, /* 30 29 30 29 30 30 29 30 29 30 30 29 29 384
-1298 */ { 00, 02, 19, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-1299 */ { 00, 02, 09, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 355
-1300 */ { 08, 01, 30, 0b0000100101111000 }, /* 29 29 29 29 30 29 29 30 29 30 30 30 30 383
-1301 */ { 00, 02, 18, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1302 */ { 00, 02, 07, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-1303 */ { 05, 01, 27, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383
-1304 */ { 00, 02, 14, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 355
-1305 */ { 00, 02, 03, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1306 */ { 01, 01, 23, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 29 384
-1307 */ { 00, 02, 11, 0b1010011011100000 }, /* 30 29 30 29 29 30 30 29 30 30 30 29 355
-1308 */ { 11, 02, 01, 0b1001001011101000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 30 384
-1309 */ { 00, 02, 19, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1310 */ { 00, 02, 08, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-1311 */ { 07, 01, 28, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1312 */ { 00, 02, 16, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1313 */ { 00, 02, 04, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 355
-1314 */ { 03, 01, 25, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-1315 */ { 00, 02, 13, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1316 */ { 00, 02, 02, 0b1010011011010000 }, /* 30 29 30 29 29 30 30 29 30 30 29 30 355
-1317 */ { 01, 01, 22, 0b1001001011101000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 30 384
-1318 */ { 00, 02, 10, 0b1001001010110000 }, /* 30 29 29 30 29 29 30 29 30 29 30 30 354
-1319 */ { 08, 01, 30, 0b1010010101011000 }, /* 30 29 30 29 29 30 29 30 29 30 29 30 30 384
-1320 */ { 00, 02, 18, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1321 */ { 00, 02, 06, 0b1011001010100000 }, /* 30 29 30 30 29 29 30 29 30 29 30 29 354
-1322 */ { 05, 01, 26, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-1323 */ { 00, 02, 14, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-1324 */ { 00, 02, 04, 0b0100110110100000 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 354
-1325 */ { 01, 01, 23, 0b1010010111010000 }, /* 30 29 30 29 29 30 29 30 30 30 29 30 29 384
-1326 */ { 00, 02, 11, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1327 */ { 09, 02, 01, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-1328 */ { 00, 02, 20, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 354
-1329 */ { 00, 02, 08, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 354
-1330 */ { 07, 01, 28, 0b0110101010011000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 30 384
-1331 */ { 00, 02, 16, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1332 */ { 00, 02, 05, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1333 */ { 03, 01, 25, 0b0100101110101000 }, /* 29 30 29 29 30 29 30 30 30 29 30 29 30 384
-1334 */ { 00, 02, 13, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-1335 */ { 12, 02, 02, 0b1010011001110000 }, /* 30 29 30 29 29 30 30 29 29 30 30 30 29 384
-1336 */ { 00, 02, 21, 0b1010001011100000 }, /* 30 29 30 29 29 29 30 29 30 30 30 29 354
-1337 */ { 00, 02, 09, 0b1101000101100000 }, /* 30 30 29 30 29 29 29 30 29 30 30 29 354
-1338 */ { 08, 01, 29, 0b1110100100110000 }, /* 30 30 30 29 30 29 29 30 29 29 30 30 29 384
-1339 */ { 00, 02, 17, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1340 */ { 00, 02, 06, 0b1101101010100000 }, /* 30 30 29 30 30 29 30 29 30 29 30 29 355
-1341 */ { 05, 01, 26, 0b0101101101010000 }, /* 29 30 29 30 30 29 30 30 29 30 29 30 29 384
-1342 */ { 00, 02, 14, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-1343 */ { 00, 02, 04, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1344 */ { 02, 01, 24, 0b1010001011101000 }, /* 30 29 30 29 29 29 30 29 30 30 30 29 30 384
-1345 */ { 00, 02, 11, 0b1010001011010000 }, /* 30 29 30 29 29 29 30 29 30 30 29 30 354
-1346 */ { 10, 01, 31, 0b1101000101011000 }, /* 30 30 29 30 29 29 29 30 29 30 29 30 30 384
-1347 */ { 00, 02, 19, 0b1010101001010000 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 354
-1348 */ { 00, 02, 08, 0b1011010100100000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 354
-1349 */ { 07, 01, 27, 0b1101011010100000 }, /* 30 30 29 30 29 30 30 29 30 29 30 29 29 384
-1350 */ { 00, 02, 15, 0b1010110110100000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 355
-1351 */ { 00, 02, 05, 0b0101010111010000 }, /* 29 30 29 30 29 30 29 30 30 30 29 30 355
-1352 */ { 03, 01, 26, 0b0100100111011000 }, /* 29 30 29 29 30 29 29 30 30 30 29 30 30 384
-1353 */ { 00, 02, 13, 0b0100010110110000 }, /* 29 30 29 29 29 30 29 30 30 29 30 30 354
-1354 */ { 00, 02, 02, 0b1010001010110000 }, /* 30 29 30 29 29 29 30 29 30 29 30 30 354
-1355 */ { 01, 01, 22, 0b1101000101011000 }, /* 30 30 29 30 29 29 29 30 29 30 29 30 30 384
-1356 */ { 00, 02, 10, 0b1010101001010000 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 354
-1357 */ { 09, 01, 29, 0b1011010100101000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 30 384
-1358 */ { 00, 02, 17, 0b0110101100100000 }, /* 29 30 30 29 30 29 30 30 29 29 30 29 354
-1359 */ { 00, 02, 06, 0b1010110101100000 }, /* 30 29 30 29 30 30 29 30 29 30 30 29 355
-1360 */ { 05, 01, 27, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 29 384
-1361 */ { 00, 02, 14, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 355
-1362 */ { 00, 02, 04, 0b0100010101110000 }, /* 29 30 29 29 29 30 29 30 29 30 30 30 354
-1363 */ { 03, 01, 24, 0b1010001010111000 }, /* 30 29 30 29 29 29 30 29 30 29 30 30 30 384
-1364 */ { 00, 02, 12, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1365 */ { 10, 01, 31, 0b1010101001010000 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 29 383
-1366 */ { 00, 02, 18, 0b1101100101010000 }, /* 30 30 29 30 30 29 29 30 29 30 29 30 355
-1367 */ { 00, 02, 08, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1368 */ { 07, 01, 28, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 29 384
-1369 */ { 00, 02, 15, 0b1010011011100000 }, /* 30 29 30 29 29 30 30 29 30 30 30 29 355
-1370 */ { 00, 02, 05, 0b0101001011100000 }, /* 29 30 29 30 29 29 30 29 30 30 30 29 354
-1371 */ { 03, 01, 25, 0b1100010101110000 }, /* 30 30 29 29 29 30 29 30 29 30 30 30 29 384
-1372 */ { 00, 02, 13, 0b1010010101100000 }, /* 30 29 30 29 29 30 29 30 29 30 30 29 354
-1373 */ { 11, 02, 01, 0b1101001010101000 }, /* 30 30 29 30 29 29 30 29 30 29 30 29 30 384
-1374 */ { 00, 02, 20, 0b1101001010100000 }, /* 30 30 29 30 29 29 30 29 30 29 30 29 354
-1375 */ { 00, 02, 09, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 355
-1376 */ { 09, 01, 30, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-1377 */ { 00, 02, 17, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1378 */ { 00, 02, 06, 0b1010011011010000 }, /* 30 29 30 29 29 30 30 29 30 30 29 30 355
-1379 */ { 05, 01, 27, 0b0101001011101000 }, /* 29 30 29 30 29 29 30 29 30 30 30 29 30 384
-1380 */ { 00, 02, 15, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1381 */ { 00, 02, 03, 0b1010100011010000 }, /* 30 29 30 29 30 29 29 29 30 30 29 30 354
-1382 */ { 02, 01, 23, 0b1101001010101000 }, /* 30 30 29 30 29 29 30 29 30 29 30 29 30 384
-1383 */ { 00, 02, 11, 0b1011001010100000 }, /* 30 29 30 30 29 29 30 29 30 29 30 29 354
-1384 */ { 10, 01, 31, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-1385 */ { 00, 02, 18, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-1386 */ { 00, 02, 08, 0b0100110110100000 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 354
-1387 */ { 06, 01, 28, 0b1010010111010000 }, /* 30 29 30 29 29 30 29 30 30 30 29 30 29 384
-1388 */ { 00, 02, 16, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1389 */ { 00, 02, 05, 0b0101000110110000 }, /* 29 30 29 30 29 29 29 30 30 29 30 30 354
-1390 */ { 04, 01, 25, 0b1010100010111000 }, /* 30 29 30 29 30 29 29 29 30 29 30 30 30 384
-1391 */ { 00, 02, 13, 0b0110010100110000 }, /* 29 30 30 29 29 30 29 30 29 29 30 30 354
-1392 */ { 12, 02, 02, 0b0110101010011000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 30 384
-1393 */ { 00, 02, 20, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1394 */ { 00, 02, 09, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1395 */ { 09, 01, 30, 0b0010101110101000 }, /* 29 29 30 29 30 29 30 30 30 29 30 29 30 384
-1396 */ { 00, 02, 18, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1397 */ { 00, 02, 06, 0b1100001101110000 }, /* 30 30 29 29 29 29 30 30 29 30 30 30 355
-1398 */ { 05, 01, 27, 0b0101000101110000 }, /* 29 30 29 30 29 29 29 30 29 30 30 30 29 383
-1399 */ { 00, 02, 14, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-1400 */ { 00, 02, 03, 0b1110010010110000 }, /* 30 30 30 29 29 30 29 29 30 29 30 30 355
-1401 */ { 03, 01, 24, 0b0110101010010000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 29 383
-1402 */ { 00, 02, 11, 0b1101101010100000 }, /* 30 30 29 30 30 29 30 29 30 29 30 29 355
-1403 */ { 11, 02, 01, 0b0101101101010000 }, /* 29 30 29 30 30 29 30 30 29 30 29 30 29 384
-1404 */ { 00, 02, 20, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-1405 */ { 00, 02, 09, 0b0010101011100000 }, /* 29 29 30 29 30 29 30 29 30 30 30 29 354
-1406 */ { 07, 01, 29, 0b1010001011101000 }, /* 30 29 30 29 29 29 30 29 30 30 30 29 30 384
-1407 */ { 00, 02, 17, 0b1010001011010000 }, /* 30 29 30 29 29 29 30 29 30 30 29 30 354
-1408 */ { 00, 02, 06, 0b1101000101010000 }, /* 30 30 29 30 29 29 29 30 29 30 29 30 354
-1409 */ { 04, 01, 25, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1410 */ { 00, 02, 13, 0b1011010100100000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 354
-1411 */ { 12, 02, 02, 0b1011011010010000 }, /* 30 29 30 30 29 30 30 29 30 29 29 30 29 384
-1412 */ { 00, 02, 21, 0b1010110110100000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 355
-1413 */ { 00, 02, 10, 0b0101010111010000 }, /* 29 30 29 30 29 30 29 30 30 30 29 30 355
-1414 */ { 09, 01, 31, 0b0010010111011000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 30 384
-1415 */ { 00, 02, 19, 0b0100010110110000 }, /* 29 30 29 29 29 30 29 30 30 29 30 30 354
-1416 */ { 00, 02, 08, 0b1010001010110000 }, /* 30 29 30 29 29 29 30 29 30 29 30 30 354
-1417 */ { 05, 01, 27, 0b1010100101011000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 30 384
-1418 */ { 00, 02, 15, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1419 */ { 00, 02, 04, 0b1011010100100000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 354
-1420 */ { 01, 01, 24, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-1421 */ { 00, 02, 11, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-1422 */ { 12, 02, 01, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 29 384
-1423 */ { 00, 02, 20, 0b0100101101110000 }, /* 29 30 29 29 30 29 30 30 29 30 30 30 355
-1424 */ { 00, 02, 10, 0b0100010101110000 }, /* 29 30 29 29 29 30 29 30 29 30 30 30 354
-1425 */ { 07, 01, 29, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-1426 */ { 00, 02, 17, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1427 */ { 00, 02, 06, 0b0110100101010000 }, /* 29 30 30 29 30 29 29 30 29 30 29 30 354
-1428 */ { 04, 01, 26, 0b0110110010101000 }, /* 29 30 30 29 30 30 29 29 30 29 30 29 30 384
-1429 */ { 00, 02, 13, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1430 */ { 12, 02, 02, 0b1001101101010000 }, /* 30 29 29 30 30 29 30 30 29 30 29 30 29 384
-1431 */ { 00, 02, 21, 0b1010011011100000 }, /* 30 29 30 29 29 30 30 29 30 30 30 29 355
-1432 */ { 00, 02, 11, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1433 */ { 08, 01, 30, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-1434 */ { 00, 02, 18, 0b1010010101100000 }, /* 30 29 30 29 29 30 29 30 29 30 30 29 354
-1435 */ { 00, 02, 07, 0b1101001010100000 }, /* 30 30 29 30 29 29 30 29 30 29 30 29 354
-1436 */ { 06, 01, 27, 0b1110100101010000 }, /* 30 30 30 29 30 29 29 30 29 30 29 30 29 384
-1437 */ { 00, 02, 14, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 355
-1438 */ { 00, 02, 04, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1439 */ { 02, 01, 24, 0b1010101011010000 }, /* 30 29 30 29 30 29 30 29 30 30 29 30 29 384
-1440 */ { 00, 02, 12, 0b1001010111100000 }, /* 30 29 29 30 29 30 29 30 30 30 30 29 355
-1441 */ { 11, 02, 01, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1442 */ { 00, 02, 20, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1443 */ { 00, 02, 09, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1444 */ { 07, 01, 29, 0b1101001001110000 }, /* 30 30 29 30 29 29 30 29 29 30 30 30 29 384
-1445 */ { 00, 02, 16, 0b1011001010100000 }, /* 30 29 30 30 29 29 30 29 30 29 30 29 354
-1446 */ { 00, 02, 05, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1447 */ { 04, 01, 26, 0b0101011010101000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 30 384
-1448 */ { 00, 02, 14, 0b0010110110100000 }, /* 29 29 30 29 30 30 29 30 30 29 30 29 354
-1449 */ { 00, 02, 02, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1450 */ { 01, 01, 23, 0b0100101010111000 }, /* 29 30 29 29 30 29 30 29 30 29 30 30 30 384
-1451 */ { 00, 02, 11, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1452 */ { 09, 01, 31, 0b1010010010111000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384
-1453 */ { 00, 02, 18, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-1454 */ { 00, 02, 07, 0b0110101010010000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 354
-1455 */ { 06, 01, 27, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-1456 */ { 00, 02, 15, 0b0110101101010000 }, /* 29 30 30 29 30 29 30 30 29 30 29 30 355
-1457 */ { 00, 02, 04, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1458 */ { 02, 01, 24, 0b1001010101110000 }, /* 30 29 29 30 29 30 29 30 29 30 30 30 29 384
-1459 */ { 00, 02, 12, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 355
-1460 */ { 11, 02, 02, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 29 383
-1461 */ { 00, 02, 19, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-1462 */ { 00, 02, 08, 0b1110010010110000 }, /* 30 30 30 29 29 30 29 29 30 29 30 30 355
-1463 */ { 07, 01, 29, 0b0110101010010000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 29 383
-1464 */ { 00, 02, 16, 0b1101101010100000 }, /* 30 30 29 30 30 29 30 29 30 29 30 29 355
-1465 */ { 00, 02, 05, 0b0101101011010000 }, /* 29 30 29 30 30 29 30 29 30 30 29 30 355
-1466 */ { 03, 01, 26, 0b0010101101101000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 30 384
-1467 */ { 00, 02, 14, 0b0010011011100000 }, /* 29 29 30 29 29 30 30 29 30 30 30 29 354
-1468 */ { 00, 02, 03, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1469 */ { 02, 01, 22, 0b1100100101101000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 30 384
-1470 */ { 00, 02, 10, 0b1100100101010000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 354
-1471 */ { 09, 01, 30, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1472 */ { 00, 02, 18, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-1473 */ { 00, 02, 06, 0b1011011010010000 }, /* 30 29 30 30 29 30 30 29 30 29 29 30 355
-1474 */ { 06, 01, 27, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 29 384
-1475 */ { 00, 02, 15, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 355
-1476 */ { 00, 02, 05, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-1477 */ { 02, 01, 24, 0b1001001011011000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 30 384
-1478 */ { 00, 02, 12, 0b1001001010110000 }, /* 30 29 29 30 29 29 30 29 30 29 30 30 354
-1479 */ { 10, 02, 01, 0b1010100101011000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 30 384
-1480 */ { 00, 02, 20, 0b0110100101010000 }, /* 29 30 30 29 30 29 29 30 29 30 29 30 354
-1481 */ { 00, 02, 08, 0b0111010010100000 }, /* 29 30 30 30 29 30 29 29 30 29 30 29 354
-1482 */ { 08, 01, 28, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-1483 */ { 00, 02, 16, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 355
-1484 */ { 00, 02, 06, 0b0101001110110000 }, /* 29 30 29 30 29 29 30 30 30 29 30 30 355
-1485 */ { 04, 01, 26, 0b0010010110111000 }, /* 29 29 30 29 29 30 29 30 30 29 30 30 30 384
-1486 */ { 00, 02, 14, 0b0010010101110000 }, /* 29 29 30 29 29 30 29 30 29 30 30 30 354
-1487 */ { 00, 02, 03, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1488 */ { 01, 01, 23, 0b1010100101011000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 30 384
-1489 */ { 00, 02, 10, 0b0110100101010000 }, /* 29 30 30 29 30 29 29 30 29 30 29 30 354
-1490 */ { 09, 01, 30, 0b0110101010101000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 30 384
-1491 */ { 00, 02, 18, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1492 */ { 00, 02, 07, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1493 */ { 05, 01, 27, 0b0100101101101000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 30 384
-1494 */ { 00, 02, 15, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1495 */ { 00, 02, 04, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1496 */ { 03, 01, 25, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 29 383
-1497 */ { 00, 02, 11, 0b1101001010100000 }, /* 30 30 29 30 29 29 30 29 30 29 30 29 354
-1498 */ { 11, 01, 31, 0b1101100101010000 }, /* 30 30 29 30 30 29 29 30 29 30 29 30 29 384
-1499 */ { 00, 02, 19, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1500 */ { 00, 02, 09, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1501 */ { 07, 01, 29, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 29 384
-1502 */ { 00, 02, 17, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 355
-1503 */ { 00, 02, 07, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1504 */ { 04, 01, 27, 0b1010010011011000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 30 384
-1505 */ { 00, 02, 14, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1506 */ { 00, 02, 03, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-1507 */ { 01, 01, 23, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 29 384
-1508 */ { 00, 02, 11, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1509 */ { 09, 01, 31, 0b0101011010101000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 30 384
-1510 */ { 00, 02, 19, 0b0010110110100000 }, /* 29 29 30 29 30 30 29 30 30 29 30 29 354
-1511 */ { 00, 02, 08, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1512 */ { 05, 01, 29, 0b0100100110111000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 30 384
-1513 */ { 00, 02, 16, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1514 */ { 00, 02, 05, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1515 */ { 04, 01, 25, 0b1011001001011000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384
-1516 */ { 00, 02, 13, 0b0110101010010000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 354
-1517 */ { 12, 02, 01, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-1518 */ { 00, 02, 20, 0b0101101101010000 }, /* 29 30 29 30 30 29 30 30 29 30 29 30 355
-1519 */ { 00, 02, 10, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1520 */ { 08, 01, 30, 0b1001010101110000 }, /* 30 29 29 30 29 30 29 30 29 30 30 30 29 384
-1521 */ { 00, 02, 17, 0b1001001011110000 }, /* 30 29 29 30 29 29 30 29 30 30 30 30 355
-1522 */ { 00, 02, 07, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1523 */ { 04, 01, 27, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 29 383
-1524 */ { 00, 02, 14, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1525 */ { 12, 02, 02, 0b1110101001010000 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 29 384
-1526 */ { 00, 02, 21, 0b1101011010010000 }, /* 30 30 29 30 29 30 30 29 30 29 29 30 355
-1527 */ { 00, 02, 11, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-1528 */ { 10, 02, 01, 0b0010101101101000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 30 384
-1529 */ { 00, 02, 19, 0b0010011011100000 }, /* 29 29 30 29 29 30 30 29 30 30 30 29 354
-1530 */ { 00, 02, 08, 0b0101001011100000 }, /* 29 30 29 30 29 29 30 29 30 30 30 29 354
-1531 */ { 06, 01, 28, 0b1100100101101000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 30 384
-1532 */ { 00, 02, 16, 0b1100100101010000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 354
-1533 */ { 00, 02, 04, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1534 */ { 02, 01, 24, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 29 384
-1535 */ { 00, 02, 12, 0b1011010110010000 }, /* 30 29 30 30 29 30 29 30 30 29 29 30 355
-1536 */ { 12, 02, 02, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 29 384
-1537 */ { 00, 02, 20, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 355
-1538 */ { 00, 02, 10, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-1539 */ { 07, 01, 30, 0b1001001011011000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 30 384
-1540 */ { 00, 02, 18, 0b1001001010110000 }, /* 30 29 29 30 29 29 30 29 30 29 30 30 354
-1541 */ { 00, 02, 06, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1542 */ { 05, 01, 26, 0b1011010010101000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 30 384
-1543 */ { 00, 02, 14, 0b0110110010100000 }, /* 29 30 30 29 30 30 29 29 30 29 30 29 354
-1544 */ { 00, 02, 03, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-1545 */ { 01, 01, 23, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 29 384
-1546 */ { 00, 02, 11, 0b0100101110110000 }, /* 29 30 29 29 30 29 30 30 30 29 30 30 355
-1547 */ { 09, 02, 01, 0b0010010110111000 }, /* 29 29 30 29 29 30 29 30 30 29 30 30 30 384
-1548 */ { 00, 02, 20, 0b0010010101110000 }, /* 29 29 30 29 29 30 29 30 29 30 30 30 354
-1549 */ { 00, 02, 08, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1550 */ { 06, 01, 28, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 29 383
-1551 */ { 00, 02, 15, 0b1110100101010000 }, /* 30 30 30 29 30 29 29 30 29 30 29 30 355
-1552 */ { 00, 02, 05, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1553 */ { 03, 01, 24, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-1554 */ { 00, 02, 12, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1555 */ { 11, 02, 02, 0b0100101101101000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 30 384
-1556 */ { 00, 02, 21, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1557 */ { 00, 02, 09, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1558 */ { 07, 01, 30, 0b0101001001101000 }, /* 29 30 29 30 29 29 30 29 29 30 30 29 30 383
-1559 */ { 00, 02, 17, 0b1101001001100000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 354
-1560 */ { 00, 02, 06, 0b1101100101010000 }, /* 30 30 29 30 30 29 29 30 29 30 29 30 355
-1561 */ { 05, 01, 26, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-1562 */ { 00, 02, 14, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1563 */ { 00, 02, 03, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355
-1564 */ { 02, 01, 24, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1565 */ { 00, 02, 11, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1566 */ { 10, 01, 31, 0b1010010011011000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 30 384
-1567 */ { 00, 02, 19, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1568 */ { 00, 02, 08, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-1569 */ { 06, 01, 27, 0b1101010101001000 }, /* 30 30 29 30 29 30 29 30 29 30 29 29 30 384
-1570 */ { 00, 02, 15, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1571 */ { 00, 02, 05, 0b0011010110100000 }, /* 29 29 30 30 29 30 29 30 30 29 30 29 354
-1572 */ { 02, 01, 25, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 29 384
-1573 */ { 00, 02, 12, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1574 */ { 12, 02, 02, 0b0100100110111000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 30 384
-1575 */ { 00, 02, 21, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1576 */ { 00, 02, 10, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1577 */ { 08, 01, 29, 0b1011001001011000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384
-1578 */ { 00, 02, 17, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 354
-1579 */ { 00, 02, 06, 0b0110110101000000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 354
-1580 */ { 04, 01, 26, 0b1010110110101000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 30 385
-1581 */ { 00, 02, 14, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1582 */ { 00, 02, 03, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 355
-1583 */ { 02, 01, 24, 0b0100100101111000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 30 384
-1584 */ { 00, 02, 12, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1585 */ { 09, 01, 31, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 29 383
-1586 */ { 00, 02, 18, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1587 */ { 00, 02, 07, 0b1110101001010000 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 355
-1588 */ { 06, 01, 28, 0b0110101101001000 }, /* 29 30 30 29 30 29 30 30 29 30 29 29 30 384
-1589 */ { 00, 02, 15, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-1590 */ { 00, 02, 05, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1591 */ { 03, 01, 25, 0b1001001011110000 }, /* 30 29 29 30 29 29 30 29 30 30 30 30 29 384
-1592 */ { 00, 02, 13, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1593 */ { 11, 02, 01, 0b1100100101101000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 30 384
-1594 */ { 00, 02, 20, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1595 */ { 00, 02, 09, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1596 */ { 08, 01, 29, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 29 384
-1597 */ { 00, 02, 16, 0b1011010011010000 }, /* 30 29 30 30 29 30 29 29 30 30 29 30 355
-1598 */ { 00, 02, 06, 0b0101011010110000 }, /* 29 30 29 30 29 30 30 29 30 29 30 30 355
-1599 */ { 04, 01, 27, 0b0010011011011000 }, /* 29 29 30 29 29 30 30 29 30 30 29 30 30 384
-1600 */ { 00, 02, 15, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-1601 */ { 00, 02, 03, 0b1001001011010000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 354
-1602 */ { 02, 01, 23, 0b1100100110011000 }, /* 30 30 29 29 30 29 29 30 30 29 29 30 30 384
-1603 */ { 00, 02, 11, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1604 */ { 09, 01, 31, 0b1011010010101000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 30 384
-1605 */ { 00, 02, 18, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1606 */ { 00, 02, 07, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-1607 */ { 06, 01, 28, 0b0101010110101000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 30 384
-1608 */ { 00, 02, 16, 0b0100101110110000 }, /* 29 30 29 29 30 29 30 30 30 29 30 30 355
-1609 */ { 00, 02, 05, 0b0010010110110000 }, /* 29 29 30 29 29 30 29 30 30 29 30 30 354
-1610 */ { 03, 01, 25, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-1611 */ { 00, 02, 13, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1612 */ { 11, 02, 02, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 29 383
-1613 */ { 00, 02, 19, 0b1110100101010000 }, /* 30 30 30 29 30 29 29 30 29 30 29 30 355
-1614 */ { 00, 02, 09, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1615 */ { 08, 01, 29, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-1616 */ { 00, 02, 17, 0b1001101101010000 }, /* 30 29 29 30 30 29 30 30 29 30 29 30 355
-1617 */ { 00, 02, 06, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-1618 */ { 04, 01, 26, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-1619 */ { 00, 02, 14, 0b1010010011110000 }, /* 30 29 30 29 29 30 29 29 30 30 30 30 355
-1620 */ { 00, 02, 04, 0b0101001001100000 }, /* 29 30 29 30 29 29 30 29 29 30 30 29 353
-1621 */ { 02, 01, 22, 0b1110100100110000 }, /* 30 30 30 29 30 29 29 30 29 29 30 30 29 384
-1622 */ { 00, 02, 10, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 355
-1623 */ { 10, 01, 31, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-1624 */ { 00, 02, 19, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1625 */ { 00, 02, 07, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355
-1626 */ { 06, 01, 28, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1627 */ { 00, 02, 16, 0b0100100111100000 }, /* 29 30 29 29 30 29 29 30 30 30 30 29 354
-1628 */ { 00, 02, 05, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1629 */ { 04, 01, 24, 0b1101001001101000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384
-1630 */ { 00, 02, 12, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-1631 */ { 11, 02, 01, 0b1101010100101000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 30 384
-1632 */ { 00, 02, 20, 0b1011010101000000 }, /* 30 29 30 30 29 30 29 30 29 30 29 29 354
-1633 */ { 00, 02, 08, 0b1011010110100000 }, /* 30 29 30 30 29 30 29 30 30 29 30 29 355
-1634 */ { 08, 01, 29, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 29 384
-1635 */ { 00, 02, 17, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1636 */ { 00, 02, 07, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1637 */ { 04, 01, 26, 0b1010010010111000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384
-1638 */ { 00, 02, 14, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1639 */ { 00, 02, 03, 0b1010101001010000 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 354
-1640 */ { 01, 01, 23, 0b1011010100101000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 30 384
-1641 */ { 00, 02, 10, 0b0110110101000000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 354
-1642 */ { 11, 01, 30, 0b1010110110101000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 30 385
-1643 */ { 00, 02, 19, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1644 */ { 00, 02, 08, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 355
-1645 */ { 06, 01, 28, 0b0100100101111000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 30 384
-1646 */ { 00, 02, 16, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1647 */ { 00, 02, 05, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-1648 */ { 03, 01, 25, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383
-1649 */ { 00, 02, 11, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 355
-1650 */ { 11, 02, 01, 0b0110101101001000 }, /* 29 30 30 29 30 29 30 30 29 30 29 29 30 384
-1651 */ { 00, 02, 20, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-1652 */ { 00, 02, 10, 0b0010101110100000 }, /* 29 29 30 29 30 29 30 30 30 29 30 29 354
-1653 */ { 07, 01, 29, 0b1001001011110000 }, /* 30 29 29 30 29 29 30 29 30 30 30 30 29 384
-1654 */ { 00, 02, 17, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1655 */ { 00, 02, 06, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-1656 */ { 05, 01, 26, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1657 */ { 00, 02, 13, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1658 */ { 00, 02, 02, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 355
-1659 */ { 03, 01, 23, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-1660 */ { 00, 02, 11, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1661 */ { 07, 01, 30, 0b1010011011010000 }, /* 30 29 30 29 29 30 30 29 30 30 29 30 29 384
-1662 */ { 00, 02, 18, 0b1010010111010000 }, /* 30 29 30 29 29 30 29 30 30 30 29 30 355
-1663 */ { 00, 02, 08, 0b1001001011010000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 354
-1664 */ { 06, 01, 28, 0b1010100101011000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 30 384
-1665 */ { 00, 02, 15, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1666 */ { 00, 02, 04, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-1667 */ { 04, 01, 24, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-1668 */ { 00, 02, 12, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-1669 */ { 00, 02, 01, 0b0101010110100000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 354
-1670 */ { 02, 01, 21, 0b1010010111010000 }, /* 30 29 30 29 29 30 29 30 30 30 29 30 29 384
-1671 */ { 00, 02, 09, 0b1010010110110000 }, /* 30 29 30 29 29 30 29 30 30 29 30 30 355
-1672 */ { 07, 01, 30, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-1673 */ { 00, 02, 17, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1674 */ { 00, 02, 06, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 354
-1675 */ { 05, 01, 26, 0b0111010010101000 }, /* 29 30 30 30 29 30 29 29 30 29 30 29 30 384
-1676 */ { 00, 02, 14, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1677 */ { 00, 02, 02, 0b1010110110010000 }, /* 30 29 30 29 30 30 29 30 30 29 29 30 355
-1678 */ { 03, 01, 23, 0b0100110110101000 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 30 384
-1679 */ { 00, 02, 11, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-1680 */ { 08, 01, 31, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-1681 */ { 00, 02, 18, 0b1010010011100000 }, /* 30 29 30 29 29 30 29 29 30 30 30 29 354
-1682 */ { 00, 02, 07, 0b1101001001100000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 354
-1683 */ { 06, 01, 27, 0b1110100100110000 }, /* 30 30 30 29 30 29 29 30 29 29 30 30 29 384
-1684 */ { 00, 02, 15, 0b1101010100100000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 354
-1685 */ { 00, 02, 03, 0b1101101010100000 }, /* 30 30 29 30 30 29 30 29 30 29 30 29 355
-1686 */ { 04, 01, 24, 0b0110101101010000 }, /* 29 30 30 29 30 29 30 30 29 30 29 30 29 384
-1687 */ { 00, 02, 12, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-1688 */ { 00, 02, 02, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1689 */ { 03, 01, 21, 0b1010010011101000 }, /* 30 29 30 29 29 30 29 29 30 30 30 29 30 384
-1690 */ { 00, 02, 09, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1691 */ { 07, 01, 29, 0b1101001001011000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 30 384
-1692 */ { 00, 02, 17, 0b1011001001010000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 354
-1693 */ { 00, 02, 05, 0b1101010100100000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 354
-1694 */ { 05, 01, 25, 0b1101011010100000 }, /* 30 30 29 30 29 30 30 29 30 29 30 29 29 384
-1695 */ { 00, 02, 13, 0b1011010110100000 }, /* 30 29 30 30 29 30 29 30 30 29 30 29 355
-1696 */ { 00, 02, 03, 0b0101010111010000 }, /* 29 30 29 30 29 30 29 30 30 30 29 30 355
-1697 */ { 03, 01, 23, 0b0100101011011000 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 30 384
-1698 */ { 00, 02, 11, 0b0100100111010000 }, /* 29 30 29 29 30 29 29 30 30 30 29 30 354
-1699 */ { 07, 01, 31, 0b1010010010111000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384
-1700 */ { 00, 02, 19, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1701 */ { 00, 02, 08, 0b1010101001010000 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 354
-1702 */ { 06, 01, 28, 0b1011010100101000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 30 384
-1703 */ { 00, 02, 16, 0b0110110100100000 }, /* 29 30 30 29 30 30 29 30 29 29 30 29 354
-1704 */ { 00, 02, 05, 0b1010110110100000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 355
-1705 */ { 04, 01, 25, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 29 384
-1706 */ { 00, 02, 13, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 355
-1707 */ { 00, 02, 03, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1708 */ { 03, 01, 23, 0b0110010010111000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 30 384
-1709 */ { 00, 02, 10, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1710 */ { 07, 01, 30, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383
-1711 */ { 00, 02, 17, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 355
-1712 */ { 00, 02, 07, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1713 */ { 05, 01, 26, 0b1010101101100000 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 29 384
-1714 */ { 00, 02, 14, 0b1010101011100000 }, /* 30 29 30 29 30 29 30 29 30 30 30 29 355
-1715 */ { 00, 02, 04, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1716 */ { 03, 01, 24, 0b1100100101110000 }, /* 30 30 29 29 30 29 29 30 29 30 30 30 29 384
-1717 */ { 00, 02, 11, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-1718 */ { 08, 01, 31, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1719 */ { 00, 02, 19, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1720 */ { 00, 02, 08, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 355
-1721 */ { 06, 01, 28, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-1722 */ { 00, 02, 16, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1723 */ { 00, 02, 05, 0b1010011011010000 }, /* 30 29 30 29 29 30 30 29 30 30 29 30 355
-1724 */ { 04, 01, 26, 0b0101001011101000 }, /* 29 30 29 30 29 29 30 29 30 30 30 29 30 384
-1725 */ { 00, 02, 13, 0b0101001011010000 }, /* 29 30 29 30 29 29 30 29 30 30 29 30 354
-1726 */ { 00, 02, 02, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1727 */ { 03, 01, 22, 0b1110010010101000 }, /* 30 30 30 29 29 30 29 29 30 29 30 29 30 384
-1728 */ { 00, 02, 10, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-1729 */ { 07, 01, 29, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-1730 */ { 00, 02, 17, 0b1001110101010000 }, /* 30 29 29 30 30 30 29 30 29 30 29 30 355
-1731 */ { 00, 02, 07, 0b0101010110100000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 354
-1732 */ { 05, 01, 27, 0b1010010111010000 }, /* 30 29 30 29 29 30 29 30 30 30 29 30 29 384
-1733 */ { 00, 02, 14, 0b1010010110110000 }, /* 30 29 30 29 29 30 29 30 30 29 30 30 355
-1734 */ { 00, 02, 04, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1735 */ { 04, 01, 24, 0b1010100010111000 }, /* 30 29 30 29 30 29 29 29 30 29 30 30 30 384
-1736 */ { 00, 02, 12, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 354
-1737 */ { 09, 01, 31, 0b0110101010011000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 30 384
-1738 */ { 00, 02, 19, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1739 */ { 00, 02, 08, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1740 */ { 06, 01, 29, 0b0100110110101000 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 30 384
-1741 */ { 00, 02, 16, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-1742 */ { 00, 02, 05, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1743 */ { 04, 01, 26, 0b0101000101110000 }, /* 29 30 29 30 29 29 29 30 29 30 30 30 29 383
-1744 */ { 00, 02, 13, 0b1101000101100000 }, /* 30 30 29 30 29 29 29 30 29 30 30 29 354
-1745 */ { 00, 02, 01, 0b1110100100110000 }, /* 30 30 30 29 30 29 29 30 29 29 30 30 355
-1746 */ { 03, 01, 22, 0b0110101010010000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 29 383
-1747 */ { 00, 02, 09, 0b1101101010100000 }, /* 30 30 29 30 30 29 30 29 30 29 30 29 355
-1748 */ { 07, 01, 30, 0b0101101101010000 }, /* 29 30 29 30 30 29 30 30 29 30 29 30 29 384
-1749 */ { 00, 02, 17, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-1750 */ { 00, 02, 07, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1751 */ { 05, 01, 27, 0b1010010011011000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 30 384
-1752 */ { 00, 02, 15, 0b1010001011010000 }, /* 30 29 30 29 29 29 30 29 30 30 29 30 354
-1753 */ { 00, 02, 03, 0b1101000101010000 }, /* 30 30 29 30 29 29 29 30 29 30 29 30 354
-1754 */ { 04, 01, 23, 0b1101010100101000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 30 384
-1755 */ { 00, 02, 11, 0b1011010100100000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 354
-1756 */ { 09, 01, 31, 0b1101011010010000 }, /* 30 30 29 30 29 30 30 29 30 29 29 30 29 384
-1757 */ { 00, 02, 18, 0b1010110110100000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 355
-1758 */ { 00, 02, 08, 0b0101010111010000 }, /* 29 30 29 30 29 30 29 30 30 30 29 30 355
-1759 */ { 06, 01, 29, 0b0010101011011000 }, /* 29 29 30 29 30 29 30 29 30 30 29 30 30 384
-1760 */ { 00, 02, 17, 0b0100010110110000 }, /* 29 30 29 29 29 30 29 30 30 29 30 30 354
-1761 */ { 00, 02, 05, 0b1010001010110000 }, /* 30 29 30 29 29 29 30 29 30 29 30 30 354
-1762 */ { 05, 01, 25, 0b1011000101011000 }, /* 30 29 30 30 29 29 29 30 29 30 29 30 30 384
-1763 */ { 00, 02, 13, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1764 */ { 00, 02, 02, 0b1011010100100000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 354
-1765 */ { 02, 01, 21, 0b1011010110010000 }, /* 30 29 30 30 29 30 29 30 30 29 29 30 29 384
-1766 */ { 00, 02, 09, 0b1010110101100000 }, /* 30 29 30 29 30 30 29 30 29 30 30 29 355
-1767 */ { 07, 01, 30, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 29 384
-1768 */ { 00, 02, 18, 0b0101001101110000 }, /* 29 30 29 30 29 29 30 30 29 30 30 30 355
-1769 */ { 00, 02, 07, 0b0100010101110000 }, /* 29 30 29 29 29 30 29 30 29 30 30 30 354
-1770 */ { 05, 01, 27, 0b0110001010111000 }, /* 29 30 30 29 29 29 30 29 30 29 30 30 30 384
-1771 */ { 00, 02, 15, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1772 */ { 00, 02, 04, 0b0110100101010000 }, /* 29 30 30 29 30 29 29 30 29 30 29 30 354
-1773 */ { 03, 01, 23, 0b0110110010101000 }, /* 29 30 30 29 30 30 29 29 30 29 30 29 30 384
-1774 */ { 00, 02, 11, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1775 */ { 10, 01, 31, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 29 384
-1776 */ { 00, 02, 19, 0b1010011011010000 }, /* 30 29 30 29 29 30 30 29 30 30 29 30 355
-1777 */ { 00, 02, 08, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1778 */ { 06, 01, 28, 0b1001010101110000 }, /* 30 29 29 30 29 30 29 30 29 30 30 30 29 384
-1779 */ { 00, 02, 16, 0b1010010101100000 }, /* 30 29 30 29 29 30 29 30 29 30 30 29 354
-1780 */ { 00, 02, 05, 0b1101001010100000 }, /* 30 30 29 30 29 29 30 29 30 29 30 29 354
-1781 */ { 05, 01, 24, 0b1110100101010000 }, /* 30 30 30 29 30 29 29 30 29 30 29 30 29 384
-1782 */ { 00, 02, 12, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 355
-1783 */ { 00, 02, 02, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1784 */ { 03, 01, 22, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 29 384
-1785 */ { 00, 02, 09, 0b1010011011010000 }, /* 30 29 30 29 29 30 30 29 30 30 29 30 355
-1786 */ { 07, 01, 30, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1787 */ { 00, 02, 18, 0b0100101010110000 }, /* 29 30 29 29 30 29 30 29 30 29 30 30 354
-1788 */ { 00, 02, 07, 0b1010100011010000 }, /* 30 29 30 29 30 29 29 29 30 30 29 30 354
-1789 */ { 05, 01, 26, 0b1101001010101000 }, /* 30 30 29 30 29 29 30 29 30 29 30 29 30 384
-1790 */ { 00, 02, 14, 0b1011001010100000 }, /* 30 29 30 30 29 29 30 29 30 29 30 29 354
-1791 */ { 00, 02, 03, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1792 */ { 04, 01, 24, 0b0101011010101000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 30 384
-1793 */ { 00, 02, 11, 0b0100110110100000 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 354
-1794 */ { 00, 01, 31, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 355
-1795 */ { 02, 01, 21, 0b0100101010111000 }, /* 29 30 29 29 30 29 30 29 30 29 30 30 30 384
-1796 */ { 00, 02, 09, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1797 */ { 06, 01, 28, 0b1010100010111000 }, /* 30 29 30 29 30 29 29 29 30 29 30 30 30 384
-1798 */ { 00, 02, 16, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-1799 */ { 00, 02, 05, 0b0110101010010000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 354
-1800 */ { 04, 01, 25, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-1801 */ { 00, 02, 13, 0b0110101101010000 }, /* 29 30 30 29 30 29 30 30 29 30 29 30 355
-1802 */ { 00, 02, 03, 0b0010101110100000 }, /* 29 29 30 29 30 29 30 30 30 29 30 29 354
-1803 */ { 02, 01, 23, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 29 384
-1804 */ { 00, 02, 11, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 355
-1805 */ { 06, 01, 31, 0b0101000101110000 }, /* 29 30 29 30 29 29 29 30 29 30 30 30 29 383
-1806 */ { 00, 02, 18, 0b1101000101100000 }, /* 30 30 29 30 29 29 29 30 29 30 30 29 354
-1807 */ { 00, 02, 07, 0b1110010010110000 }, /* 30 30 30 29 29 30 29 29 30 29 30 30 355
-1808 */ { 05, 01, 28, 0b0110101010010000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 29 383
-1809 */ { 00, 02, 14, 0b1101101010010000 }, /* 30 30 29 30 30 29 30 29 30 29 29 30 355
-1810 */ { 00, 02, 04, 0b0101101101010000 }, /* 29 30 29 30 30 29 30 30 29 30 29 30 355
-1811 */ { 03, 01, 25, 0b0010101101101000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 30 384
-1812 */ { 00, 02, 13, 0b0010101011100000 }, /* 29 29 30 29 30 29 30 29 30 30 30 29 354
-1813 */ { 00, 02, 01, 0b1010001011100000 }, /* 30 29 30 29 29 29 30 29 30 30 30 29 354
-1814 */ { 02, 01, 21, 0b1101000101101000 }, /* 30 30 29 30 29 29 29 30 29 30 30 29 30 384
-1815 */ { 00, 02, 09, 0b1100100101010000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 354
-1816 */ { 06, 01, 29, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1817 */ { 00, 02, 16, 0b1011010100100000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 354
-1818 */ { 00, 02, 05, 0b1011011010010000 }, /* 30 29 30 30 29 30 30 29 30 29 29 30 355
-1819 */ { 04, 01, 26, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 29 384
-1820 */ { 00, 02, 14, 0b0101010111010000 }, /* 29 30 29 30 29 30 29 30 30 30 29 30 355
-1821 */ { 00, 02, 03, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-1822 */ { 03, 01, 23, 0b1010001011011000 }, /* 30 29 30 29 29 29 30 29 30 30 29 30 30 384
-1823 */ { 00, 02, 11, 0b1010001010110000 }, /* 30 29 30 29 29 29 30 29 30 29 30 30 354
-1824 */ { 07, 01, 31, 0b1010100101011000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 30 384
-1825 */ { 00, 02, 18, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1826 */ { 00, 02, 07, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-1827 */ { 05, 01, 27, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-1828 */ { 00, 02, 15, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-1829 */ { 00, 02, 04, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 355
-1830 */ { 04, 01, 25, 0b0010010110111000 }, /* 29 29 30 29 29 30 29 30 30 29 30 30 30 384
-1831 */ { 00, 02, 13, 0b0010010101110000 }, /* 29 29 30 29 29 30 29 30 29 30 30 30 354
-1832 */ { 09, 02, 02, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-1833 */ { 00, 02, 20, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1834 */ { 00, 02, 09, 0b0110100101010000 }, /* 29 30 30 29 30 29 29 30 29 30 29 30 354
-1835 */ { 06, 01, 29, 0b0110110010101000 }, /* 29 30 30 29 30 30 29 29 30 29 30 29 30 384
-1836 */ { 00, 02, 17, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1837 */ { 00, 02, 05, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1838 */ { 04, 01, 26, 0b0101001101101000 }, /* 29 30 29 30 29 29 30 30 29 30 30 29 30 384
-1839 */ { 00, 02, 14, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1840 */ { 00, 02, 03, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1841 */ { 03, 01, 23, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 29 383
-1842 */ { 00, 02, 10, 0b1101001010100000 }, /* 30 30 29 30 29 29 30 29 30 29 30 29 354
-1843 */ { 07, 01, 30, 0b1110100101010000 }, /* 30 30 30 29 30 29 29 30 29 30 29 30 29 384
-1844 */ { 00, 02, 18, 0b1101010101010000 }, /* 30 30 29 30 29 30 29 30 29 30 29 30 355
-1845 */ { 00, 02, 07, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-1846 */ { 05, 01, 27, 0b1010101011010000 }, /* 30 29 30 29 30 29 30 29 30 30 29 30 29 384
-1847 */ { 00, 02, 15, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 355
-1848 */ { 00, 02, 05, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1849 */ { 04, 01, 24, 0b1010010101011000 }, /* 30 29 30 29 29 30 29 30 29 30 29 30 30 384
-1850 */ { 00, 02, 12, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1851 */ { 08, 02, 01, 0b1101001001011000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 30 384
-1852 */ { 00, 02, 20, 0b1011001010010000 }, /* 30 29 30 30 29 29 30 29 30 29 29 30 354
-1853 */ { 00, 02, 08, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1854 */ { 07, 01, 29, 0b0101011010101000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 30 384
-1855 */ { 00, 02, 17, 0b0010110110100000 }, /* 29 29 30 29 30 30 29 30 30 29 30 29 354
-1856 */ { 00, 02, 06, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 355
-1857 */ { 05, 01, 26, 0b0100101010111000 }, /* 29 30 29 29 30 29 30 29 30 29 30 30 30 384
-1858 */ { 00, 02, 14, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1859 */ { 00, 02, 03, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1860 */ { 03, 01, 23, 0b1011001001011000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384
-1861 */ { 00, 02, 10, 0b0110101010010000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 354
-1862 */ { 08, 01, 30, 0b1010110101001000 }, /* 30 29 30 29 30 30 29 30 29 30 29 29 30 384
-1863 */ { 00, 02, 18, 0b0110101101010000 }, /* 29 30 30 29 30 29 30 30 29 30 29 30 355
-1864 */ { 00, 02, 08, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1865 */ { 05, 01, 27, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 29 384
-1866 */ { 00, 02, 15, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 355
-1867 */ { 00, 02, 05, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1868 */ { 04, 01, 25, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 29 383
-1869 */ { 00, 02, 11, 0b1110010010100000 }, /* 30 30 30 29 29 30 29 29 30 29 30 29 354
-1870 */ { 10, 01, 31, 0b1110101001010000 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 29 384
-1871 */ { 00, 02, 19, 0b1101101010010000 }, /* 30 30 29 30 30 29 30 29 30 29 29 30 355
-1872 */ { 00, 02, 09, 0b0101101011010000 }, /* 29 30 29 30 30 29 30 29 30 30 29 30 355
-1873 */ { 06, 01, 29, 0b0010101101101000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 30 384
-1874 */ { 00, 02, 17, 0b0010101011100000 }, /* 29 29 30 29 30 29 30 29 30 30 30 29 354
-1875 */ { 00, 02, 06, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1876 */ { 05, 01, 26, 0b1100100101101000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 30 384
-1877 */ { 00, 02, 13, 0b1100100101010000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 354
-1878 */ { 00, 02, 02, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1879 */ { 03, 01, 22, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 29 384
-1880 */ { 00, 02, 10, 0b1011011010010000 }, /* 30 29 30 30 29 30 30 29 30 29 29 30 355
-1881 */ { 07, 01, 30, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 29 384
-1882 */ { 00, 02, 18, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 355
-1883 */ { 00, 02, 08, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-1884 */ { 05, 01, 28, 0b1001001011011000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 30 384
-1885 */ { 00, 02, 15, 0b1001001010110000 }, /* 30 29 29 30 29 29 30 29 30 29 30 30 354
-1886 */ { 00, 02, 04, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1887 */ { 04, 01, 24, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1888 */ { 00, 02, 12, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-1889 */ { 00, 01, 31, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1890 */ { 02, 01, 21, 0b0101011010101000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 30 384
-1891 */ { 00, 02, 09, 0b0101010110110000 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 355
-1892 */ { 06, 01, 30, 0b0010010110111000 }, /* 29 29 30 29 29 30 29 30 30 29 30 30 30 384
-1893 */ { 00, 02, 17, 0b0010010101110000 }, /* 29 29 30 29 29 30 29 30 29 30 30 30 354
-1894 */ { 00, 02, 06, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1895 */ { 05, 01, 26, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 29 383
-1896 */ { 00, 02, 13, 0b1110100101010000 }, /* 30 30 30 29 30 29 29 30 29 30 29 30 355
-1897 */ { 00, 02, 02, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1898 */ { 03, 01, 22, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-1899 */ { 00, 02, 10, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1900 */ { 08, 01, 31, 0b0100101101101000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 30 384
-1901 */ { 00, 02, 19, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1902 */ { 00, 02, 08, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1903 */ { 05, 01, 29, 0b0101001001101000 }, /* 29 30 29 30 29 29 30 29 29 30 30 29 30 383
-1904 */ { 00, 02, 16, 0b1101001001100000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 354
-1905 */ { 00, 02, 04, 0b1101100101010000 }, /* 30 30 29 30 30 29 29 30 29 30 29 30 355
-1906 */ { 04, 01, 25, 0b0110101010101000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 30 384
-1907 */ { 00, 02, 13, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1908 */ { 00, 02, 02, 0b1001101011010000 }, /* 30 29 29 30 30 29 30 29 30 30 29 30 355
-1909 */ { 02, 01, 22, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1910 */ { 00, 02, 10, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1911 */ { 06, 01, 30, 0b1010010011011000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 30 384
-1912 */ { 00, 02, 18, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-1913 */ { 00, 02, 06, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-1914 */ { 05, 01, 26, 0b1101100101001000 }, /* 30 30 29 30 30 29 29 30 29 30 29 29 30 384
-1915 */ { 00, 02, 14, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1916 */ { 00, 02, 04, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1917 */ { 02, 01, 23, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 29 384
-1918 */ { 00, 02, 11, 0b1001010111010000 }, /* 30 29 29 30 29 30 29 30 30 30 29 30 355
-1919 */ { 07, 02, 01, 0b0100101011011000 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 30 384
-1920 */ { 00, 02, 20, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1921 */ { 00, 02, 08, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1922 */ { 05, 01, 28, 0b1011001001011000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384
-1923 */ { 00, 02, 16, 0b0110101010010000 }, /* 29 30 30 29 30 29 30 29 30 29 29 30 354
-1924 */ { 00, 02, 05, 0b1010110101000000 }, /* 30 29 30 29 30 30 29 30 29 30 29 29 354
-1925 */ { 04, 01, 24, 0b1011010110101000 }, /* 30 29 30 30 29 30 29 30 30 29 30 29 30 385
-1926 */ { 00, 02, 13, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1927 */ { 00, 02, 02, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1928 */ { 02, 01, 23, 0b0100100110111000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 30 384
-1929 */ { 00, 02, 10, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1930 */ { 06, 01, 30, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 29 383
-1931 */ { 00, 02, 17, 0b1110010010100000 }, /* 30 30 30 29 29 30 29 29 30 29 30 29 354
-1932 */ { 00, 02, 06, 0b1110101001010000 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 355
-1933 */ { 05, 01, 26, 0b0110110101001000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 30 384
-1934 */ { 00, 02, 14, 0b0101101101010000 }, /* 29 30 29 30 30 29 30 30 29 30 29 30 355
-1935 */ { 00, 02, 04, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1936 */ { 03, 01, 24, 0b1001010101110000 }, /* 30 29 29 30 29 30 29 30 29 30 30 30 29 384
-1937 */ { 00, 02, 11, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-1938 */ { 07, 01, 31, 0b1100100101101000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 30 384
-1939 */ { 00, 02, 19, 0b1100100101010000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 354
-1940 */ { 00, 02, 08, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-1941 */ { 06, 01, 27, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 29 384
-1942 */ { 00, 02, 15, 0b1011011010010000 }, /* 30 29 30 30 29 30 30 29 30 29 29 30 355
-1943 */ { 00, 02, 05, 0b0101011011010000 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 355
-1944 */ { 04, 01, 26, 0b0010101011011000 }, /* 29 29 30 29 30 29 30 29 30 30 29 30 30 384
-1945 */ { 00, 02, 13, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-1946 */ { 00, 02, 02, 0b1001001011010000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 354
-1947 */ { 02, 01, 22, 0b1100100101011000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 30 384
-1948 */ { 00, 02, 10, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-1949 */ { 07, 01, 29, 0b1101010010101000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-1950 */ { 00, 02, 17, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-1951 */ { 00, 02, 06, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-1952 */ { 05, 01, 27, 0b0101011010101000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 30 384
-1953 */ { 00, 02, 14, 0b0100110110110000 }, /* 29 30 29 29 30 30 29 30 30 29 30 30 355
-1954 */ { 00, 02, 04, 0b0010010110110000 }, /* 29 29 30 29 29 30 29 30 30 29 30 30 354
-1955 */ { 03, 01, 24, 0b1001001010111000 }, /* 30 29 29 30 29 29 30 29 30 29 30 30 30 384
-1956 */ { 00, 02, 12, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-1957 */ { 08, 01, 31, 0b1010100101011000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 30 384
-1958 */ { 00, 02, 19, 0b0110100101010000 }, /* 29 30 30 29 30 29 29 30 29 30 29 30 354
-1959 */ { 00, 02, 08, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-1960 */ { 06, 01, 28, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-1961 */ { 00, 02, 15, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355
-1962 */ { 00, 02, 05, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-1963 */ { 04, 01, 25, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-1964 */ { 00, 02, 13, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-1965 */ { 00, 02, 02, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 354
-1966 */ { 03, 01, 22, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 29 383
-1967 */ { 00, 02, 09, 0b1101100101010000 }, /* 30 30 29 30 30 29 29 30 29 30 29 30 355
-1968 */ { 07, 01, 30, 0b0110101010101000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 30 384
-1969 */ { 00, 02, 17, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354
-1970 */ { 00, 02, 06, 0b1001101011010000 }, /* 30 29 29 30 30 29 30 29 30 30 29 30 355
-1971 */ { 05, 01, 27, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1972 */ { 00, 02, 15, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-1973 */ { 00, 02, 03, 0b1010010011100000 }, /* 30 29 30 29 29 30 29 29 30 30 30 29 354
-1974 */ { 04, 01, 23, 0b1101001001101000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384
-1975 */ { 00, 02, 11, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-1976 */ { 08, 01, 31, 0b1101010101001000 }, /* 30 30 29 30 29 30 29 30 29 30 29 29 30 384
-1977 */ { 00, 02, 18, 0b1011010101000000 }, /* 30 29 30 30 29 30 29 30 29 30 29 29 354
-1978 */ { 00, 02, 07, 0b1101011010100000 }, /* 30 30 29 30 29 30 30 29 30 29 30 29 355
-1979 */ { 06, 01, 28, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 29 384
-1980 */ { 00, 02, 16, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1981 */ { 00, 02, 05, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-1982 */ { 04, 01, 25, 0b1010010011011000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 30 384
-1983 */ { 00, 02, 13, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-1984 */ { 10, 02, 02, 0b1011001001011000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384
-1985 */ { 00, 02, 20, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 354
-1986 */ { 00, 02, 09, 0b0110110101000000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 354
-1987 */ { 06, 01, 29, 0b1011010110101000 }, /* 30 29 30 30 29 30 29 30 30 29 30 29 30 385
-1988 */ { 00, 02, 18, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1989 */ { 00, 02, 06, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355
-1990 */ { 05, 01, 27, 0b0100100110111000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 30 384
-1991 */ { 00, 02, 15, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354
-1992 */ { 00, 02, 04, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354
-1993 */ { 03, 01, 23, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383
-1994 */ { 00, 02, 10, 0b1110101001010000 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 355
-1995 */ { 08, 01, 31, 0b0110110101001000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 30 384
-1996 */ { 00, 02, 19, 0b0101101011010000 }, /* 29 30 29 30 30 29 30 29 30 30 29 30 355
-1997 */ { 00, 02, 08, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354
-1998 */ { 05, 01, 28, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 29 384
-1999 */ { 00, 02, 16, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354
-2000 */ { 00, 02, 05, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354
-2001 */ { 04, 01, 24, 0b1110010010101000 }, /* 30 30 30 29 29 30 29 29 30 29 30 29 30 384
-2002 */ { 00, 02, 12, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354
-2003 */ { 00, 02, 01, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 355
-2004 */ { 02, 01, 22, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-2005 */ { 00, 02, 09, 0b0101011011000000 }, /* 29 30 29 30 29 30 30 29 30 30 29 29 354
-2006 */ { 07, 01, 29, 0b1010101011011000 }, /* 30 29 30 29 30 29 30 29 30 30 29 30 30 385
-2007 */ { 00, 02, 18, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354
-2008 */ { 00, 02, 07, 0b1001001011010000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 354
-2009 */ { 05, 01, 26, 0b1100100101011000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 30 384
-2010 */ { 00, 02, 14, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-2011 */ { 00, 02, 03, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354
-2012 */ { 03, 01, 23, 0b1011101001010000 }, /* 30 29 30 30 30 29 30 29 29 30 29 30 29 384
-2013 */ { 00, 02, 10, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355
-2014 */ { 09, 01, 31, 0b0101010110101000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 30 384
-2015 */ { 00, 02, 19, 0b0100101110100000 }, /* 29 30 29 29 30 29 30 30 30 29 30 29 354
-2016 */ { 00, 02, 08, 0b1010010110110000 }, /* 30 29 30 29 29 30 29 30 30 29 30 30 355
-2017 */ { 05, 01, 28, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-2018 */ { 00, 02, 16, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354
-2019 */ { 00, 02, 05, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354
-2020 */ { 04, 01, 25, 0b1011010010101000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 30 384
-2021 */ { 00, 02, 12, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354
-2022 */ { 00, 02, 01, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355
-2023 */ { 02, 01, 22, 0b0101010110101000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 30 384
-2024 */ { 00, 02, 10, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354
-2025 */ { 06, 01, 29, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-2026 */ { 00, 02, 17, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355
-2027 */ { 00, 02, 07, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 354
-2028 */ { 05, 01, 27, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 29 383
-2029 */ { 00, 02, 13, 0b1101100100110000 }, /* 30 30 29 30 30 29 29 30 29 29 30 30 355
-2030 */ { 00, 02, 03, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354
-2031 */ { 03, 01, 23, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 29 384
-2032 */ { 00, 02, 11, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355
-2033 */ { 11, 01, 31, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-2034 */ { 00, 02, 19, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354
-2035 */ { 00, 02, 08, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354
-2036 */ { 06, 01, 28, 0b1101001001101000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384
-2037 */ { 00, 02, 15, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354
-2038 */ { 00, 02, 04, 0b1101010100100000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 354
-2039 */ { 05, 01, 24, 0b1101101010100000 }, /* 30 30 29 30 30 29 30 29 30 29 30 29 29 384
-2040 */ { 00, 02, 12, 0b1011011010100000 }, /* 30 29 30 30 29 30 30 29 30 29 30 29 355
-2041 */ { 00, 02, 01, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355
-2042 */ { 02, 01, 22, 0b0100101011011000 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 30 384
-2043 */ { 00, 02, 10, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354
-2044 */ { 07, 01, 30, 0b1010010010111000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384
-2045 */ { 00, 02, 17, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354
-2046 */ { 00, 02, 06, 0b1011001001010000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 354
-2047 */ { 05, 01, 26, 0b1011010100101000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 30 384
-2048 */ { 00, 02, 14, 0b0110110101000000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 354
-2049 */ { 00, 02, 02, 0b1010110110100000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 355
-2050 */ { 03, 01, 23, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 29 384
- */ };
-
- internal override int MinCalendarYear => MinLunisolarYear;
-
- internal override int MaxCalendarYear => MaxLunisolarYear;
-
- internal override DateTime MinDate => s_minDate;
-
- internal override DateTime MaxDate => s_maxDate;
-
- internal override EraInfo[]? CalEraInfo => null;
-
- internal override int GetYearInfo(int lunarYear, int index)
- {
- if (lunarYear < MinLunisolarYear || lunarYear > MaxLunisolarYear)
- {
- throw new ArgumentOutOfRangeException(
- "year",
- lunarYear,
- SR.Format(SR.ArgumentOutOfRange_Range, MinLunisolarYear, MaxLunisolarYear));
- }
-
- return s_yinfo[lunarYear - MinLunisolarYear, index];
- }
-
- internal override int GetYear(int year, DateTime time)
- {
- return year;
- }
-
- internal override int GetGregorianYear(int year, int era)
- {
- if (era != CurrentEra && era != GregorianEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- if (year < MinLunisolarYear || year > MaxLunisolarYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, MinLunisolarYear, MaxLunisolarYear));
- }
-
- return year;
- }
-
- public KoreanLunisolarCalendar()
- {
- }
-
- public override int GetEra(DateTime time)
- {
- CheckTicksRange(time.Ticks);
- return GregorianEra;
- }
-
- internal override CalendarId BaseCalendarID => CalendarId.KOREA;
-
- internal override CalendarId ID => CalendarId.KOREANLUNISOLAR;
-
- public override int[] Eras => new int[] { GregorianEra };
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/LocaleData.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/LocaleData.Unix.cs
deleted file mode 100644
index 2af5eb9c250..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/LocaleData.Unix.cs
+++ /dev/null
@@ -1,4573 +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 System.Diagnostics;
-
-#pragma warning disable SA1001
-
-// This file contains the handling of Windows OS specific culture features.
-
-namespace System.Globalization
-{
- internal enum LocaleDataParts
- {
- Lcid = 0,
- AnsiCodePage = 1,
- OemCodePage = 2,
- MacCodePage = 3,
- EbcdicCodePage = 4,
- GeoId = 5,
- DigitSubstitution = 6,
- SpecificLocaleIndex = 7,
- ConsoleLocaleIndex = 8
- }
-
- internal static class LocaleData
- {
- // this is done rather than using a large readonly array of strings to avoid
- // generating a large amount of code in the static constructor.
- // Using indices from s_localeNamesIndices, we binary search this string when mapping
- // an culture name to Lcid. Note that these names are all lowercase and are
- // sorted alphabetically (ordinal).
- private const string c_localeNames =
- // culture name Lcid
- "aa" + // 01000 - 0
- "aa-dj" + // 01000 - 2
- "aa-er" + // 01000 - 7
- "aa-et" + // 01000 - 12
- "af" + // 00036 - 17
- "af-na" + // 01000 - 19
- "af-za" + // 00436 - 24
- "agq" + // 01000 - 29
- "agq-cm" + // 01000 - 32
- "ak" + // 01000 - 38
- "ak-gh" + // 01000 - 40
- "am" + // 0005e - 45
- "am-et" + // 0045e - 47
- "ar" + // 00001 - 52
- "ar-001" + // 01000 - 54
- "ar-ae" + // 03801 - 60
- "ar-bh" + // 03c01 - 65
- "ar-dj" + // 01000 - 70
- "ar-dz" + // 01401 - 75
- "ar-eg" + // 00c01 - 80
- "ar-er" + // 01000 - 85
- "ar-il" + // 01000 - 90
- "ar-iq" + // 00801 - 95
- "ar-jo" + // 02c01 - 100
- "ar-km" + // 01000 - 105
- "ar-kw" + // 03401 - 110
- "ar-lb" + // 03001 - 115
- "ar-ly" + // 01001 - 120
- "ar-ma" + // 01801 - 125
- "ar-mr" + // 01000 - 130
- "ar-om" + // 02001 - 135
- "ar-ps" + // 01000 - 140
- "ar-qa" + // 04001 - 145
- "ar-sa" + // 00401 - 150
- "ar-sd" + // 01000 - 155
- "ar-so" + // 01000 - 160
- "ar-ss" + // 01000 - 165
- "ar-sy" + // 02801 - 170
- "ar-td" + // 01000 - 175
- "ar-tn" + // 01c01 - 180
- "ar-ye" + // 02401 - 185
- "arn" + // 0007a - 190
- "arn-cl" + // 0047a - 193
- "as" + // 0004d - 199
- "as-in" + // 0044d - 201
- "asa" + // 01000 - 206
- "asa-tz" + // 01000 - 209
- "ast" + // 01000 - 215
- "ast-es" + // 01000 - 218
- "az" + // 0002c - 224
- "az-cyrl" + // 0742c - 226
- "az-cyrl-az" + // 0082c - 233
- "az-latn" + // 0782c - 243
- "az-latn-az" + // 0042c - 250
- "ba" + // 0006d - 260
- "ba-ru" + // 0046d - 262
- "bas" + // 01000 - 267
- "bas-cm" + // 01000 - 270
- "be" + // 00023 - 276
- "be-by" + // 00423 - 278
- "bem" + // 01000 - 283
- "bem-zm" + // 01000 - 286
- "bez" + // 01000 - 292
- "bez-tz" + // 01000 - 295
- "bg" + // 00002 - 301
- "bg-bg" + // 00402 - 303
- "bin" + // 00066 - 308
- "bin-ng" + // 00466 - 311
- "bm" + // 01000 - 317
- "bm-latn" + // 01000 - 319
- "bm-latn-ml" + // 01000 - 326
- "bn" + // 00045 - 336
- "bn-bd" + // 00845 - 338
- "bn-in" + // 00445 - 343
- "bo" + // 00051 - 348
- "bo-cn" + // 00451 - 350
- "bo-in" + // 01000 - 355
- "br" + // 0007e - 360
- "br-fr" + // 0047e - 362
- "brx" + // 01000 - 367
- "brx-in" + // 01000 - 370
- "bs" + // 0781a - 376
- "bs-cyrl" + // 0641a - 378
- "bs-cyrl-ba" + // 0201a - 385
- "bs-latn" + // 0681a - 395
- "bs-latn-ba" + // 0141a - 402
- "byn" + // 01000 - 412
- "byn-er" + // 01000 - 415
- "ca" + // 00003 - 421
- "ca-ad" + // 01000 - 423
- "ca-es" + // 00403 - 428
- "ca-es-valencia" + // 00803 - 433
- "ca-fr" + // 01000 - 447
- "ca-it" + // 01000 - 452
- "ce" + // 01000 - 457
- "ce-ru" + // 01000 - 459
- "cgg" + // 01000 - 464
- "cgg-ug" + // 01000 - 467
- "chr" + // 0005c - 473
- "chr-cher" + // 07c5c - 476
- "chr-cher-us" + // 0045c - 484
- "co" + // 00083 - 495
- "co-fr" + // 00483 - 497
- "cs" + // 00005 - 502
- "cs-cz" + // 00405 - 504
- "cu" + // 01000 - 509
- "cu-ru" + // 01000 - 511
- "cy" + // 00052 - 516
- "cy-gb" + // 00452 - 518
- "da" + // 00006 - 523
- "da-dk" + // 00406 - 525
- "da-gl" + // 01000 - 530
- "dav" + // 01000 - 535
- "dav-ke" + // 01000 - 538
- "de" + // 00007 - 544
- "de-at" + // 00c07 - 546
- "de-be" + // 01000 - 551
- "de-ch" + // 00807 - 556
- "de-de" + // 00407 - 561
- "de-de_phoneb" + // 10407 - 566
- "de-it" + // 01000 - 578
- "de-li" + // 01407 - 583
- "de-lu" + // 01007 - 588
- "dje" + // 01000 - 593
- "dje-ne" + // 01000 - 596
- "dsb" + // 07c2e - 602
- "dsb-de" + // 0082e - 605
- "dua" + // 01000 - 611
- "dua-cm" + // 01000 - 614
- "dv" + // 00065 - 620
- "dv-mv" + // 00465 - 622
- "dyo" + // 01000 - 627
- "dyo-sn" + // 01000 - 630
- "dz" + // 01000 - 636
- "dz-bt" + // 00c51 - 638
- "ebu" + // 01000 - 643
- "ebu-ke" + // 01000 - 646
- "ee" + // 01000 - 652
- "ee-gh" + // 01000 - 654
- "ee-tg" + // 01000 - 659
- "el" + // 00008 - 664
- "el-cy" + // 01000 - 666
- "el-gr" + // 00408 - 671
- "en" + // 00009 - 676
- "en-001" + // 01000 - 678
- "en-029" + // 02409 - 684
- "en-150" + // 01000 - 690
- "en-ag" + // 01000 - 696
- "en-ai" + // 01000 - 701
- "en-as" + // 01000 - 706
- "en-at" + // 01000 - 711
- "en-au" + // 00c09 - 716
- "en-bb" + // 01000 - 721
- "en-be" + // 01000 - 726
- "en-bi" + // 01000 - 731
- "en-bm" + // 01000 - 736
- "en-bs" + // 01000 - 741
- "en-bw" + // 01000 - 746
- "en-bz" + // 02809 - 751
- "en-ca" + // 01009 - 756
- "en-cc" + // 01000 - 761
- "en-ch" + // 01000 - 766
- "en-ck" + // 01000 - 771
- "en-cm" + // 01000 - 776
- "en-cx" + // 01000 - 781
- "en-cy" + // 01000 - 786
- "en-de" + // 01000 - 791
- "en-dk" + // 01000 - 796
- "en-dm" + // 01000 - 801
- "en-er" + // 01000 - 806
- "en-fi" + // 01000 - 811
- "en-fj" + // 01000 - 816
- "en-fk" + // 01000 - 821
- "en-fm" + // 01000 - 826
- "en-gb" + // 00809 - 831
- "en-gd" + // 01000 - 836
- "en-gg" + // 01000 - 841
- "en-gh" + // 01000 - 846
- "en-gi" + // 01000 - 851
- "en-gm" + // 01000 - 856
- "en-gu" + // 01000 - 861
- "en-gy" + // 01000 - 866
- "en-hk" + // 03c09 - 871
- "en-id" + // 03809 - 876
- "en-ie" + // 01809 - 881
- "en-il" + // 01000 - 886
- "en-im" + // 01000 - 891
- "en-in" + // 04009 - 896
- "en-io" + // 01000 - 901
- "en-je" + // 01000 - 906
- "en-jm" + // 02009 - 911
- "en-ke" + // 01000 - 916
- "en-ki" + // 01000 - 921
- "en-kn" + // 01000 - 926
- "en-ky" + // 01000 - 931
- "en-lc" + // 01000 - 936
- "en-lr" + // 01000 - 941
- "en-ls" + // 01000 - 946
- "en-mg" + // 01000 - 951
- "en-mh" + // 01000 - 956
- "en-mo" + // 01000 - 961
- "en-mp" + // 01000 - 966
- "en-ms" + // 01000 - 971
- "en-mt" + // 01000 - 976
- "en-mu" + // 01000 - 981
- "en-mw" + // 01000 - 986
- "en-my" + // 04409 - 991
- "en-na" + // 01000 - 996
- "en-nf" + // 01000 - 1001
- "en-ng" + // 01000 - 1006
- "en-nl" + // 01000 - 1011
- "en-nr" + // 01000 - 1016
- "en-nu" + // 01000 - 1021
- "en-nz" + // 01409 - 1026
- "en-pg" + // 01000 - 1031
- "en-ph" + // 03409 - 1036
- "en-pk" + // 01000 - 1041
- "en-pn" + // 01000 - 1046
- "en-pr" + // 01000 - 1051
- "en-pw" + // 01000 - 1056
- "en-rw" + // 01000 - 1061
- "en-sb" + // 01000 - 1066
- "en-sc" + // 01000 - 1071
- "en-sd" + // 01000 - 1076
- "en-se" + // 01000 - 1081
- "en-sg" + // 04809 - 1086
- "en-sh" + // 01000 - 1091
- "en-si" + // 01000 - 1096
- "en-sl" + // 01000 - 1101
- "en-ss" + // 01000 - 1106
- "en-sx" + // 01000 - 1111
- "en-sz" + // 01000 - 1116
- "en-tc" + // 01000 - 1121
- "en-tk" + // 01000 - 1126
- "en-to" + // 01000 - 1131
- "en-tt" + // 02c09 - 1136
- "en-tv" + // 01000 - 1141
- "en-tz" + // 01000 - 1146
- "en-ug" + // 01000 - 1151
- "en-um" + // 01000 - 1156
- "en-us" + // 00409 - 1161
- "en-vc" + // 01000 - 1166
- "en-vg" + // 01000 - 1171
- "en-vi" + // 01000 - 1176
- "en-vu" + // 01000 - 1181
- "en-ws" + // 01000 - 1186
- "en-za" + // 01c09 - 1191
- "en-zm" + // 01000 - 1196
- "en-zw" + // 03009 - 1201
- "eo" + // 01000 - 1206
- "eo-001" + // 01000 - 1208
- "es" + // 0000a - 1214
- "es-419" + // 0580a - 1216
- "es-ar" + // 02c0a - 1222
- "es-bo" + // 0400a - 1227
- "es-br" + // 01000 - 1232
- "es-cl" + // 0340a - 1237
- "es-co" + // 0240a - 1242
- "es-cr" + // 0140a - 1247
- "es-cu" + // 05c0a - 1252
- "es-do" + // 01c0a - 1257
- "es-ec" + // 0300a - 1262
- "es-es" + // 00c0a - 1267
- "es-es_tradnl" + // 0040a - 1272
- "es-gq" + // 01000 - 1284
- "es-gt" + // 0100a - 1289
- "es-hn" + // 0480a - 1294
- "es-mx" + // 0080a - 1299
- "es-ni" + // 04c0a - 1304
- "es-pa" + // 0180a - 1309
- "es-pe" + // 0280a - 1314
- "es-ph" + // 01000 - 1319
- "es-pr" + // 0500a - 1324
- "es-py" + // 03c0a - 1329
- "es-sv" + // 0440a - 1334
- "es-us" + // 0540a - 1339
- "es-uy" + // 0380a - 1344
- "es-ve" + // 0200a - 1349
- "et" + // 00025 - 1354
- "et-ee" + // 00425 - 1356
- "eu" + // 0002d - 1361
- "eu-es" + // 0042d - 1363
- "ewo" + // 01000 - 1368
- "ewo-cm" + // 01000 - 1371
- "fa" + // 00029 - 1377
- "fa-ir" + // 00429 - 1379
- "ff" + // 00067 - 1384
- "ff-cm" + // 01000 - 1386
- "ff-gn" + // 01000 - 1391
- "ff-latn" + // 07c67 - 1396
- "ff-latn-sn" + // 00867 - 1403
- "ff-mr" + // 01000 - 1413
- "ff-ng" + // 00467 - 1418
- "fi" + // 0000b - 1423
- "fi-fi" + // 0040b - 1425
- "fil" + // 00064 - 1430
- "fil-ph" + // 00464 - 1433
- "fo" + // 00038 - 1439
- "fo-dk" + // 01000 - 1441
- "fo-fo" + // 00438 - 1446
- "fr" + // 0000c - 1451
- "fr-029" + // 01c0c - 1453
- "fr-be" + // 0080c - 1459
- "fr-bf" + // 01000 - 1464
- "fr-bi" + // 01000 - 1469
- "fr-bj" + // 01000 - 1474
- "fr-bl" + // 01000 - 1479
- "fr-ca" + // 00c0c - 1484
- "fr-cd" + // 0240c - 1489
- "fr-cf" + // 01000 - 1494
- "fr-cg" + // 01000 - 1499
- "fr-ch" + // 0100c - 1504
- "fr-ci" + // 0300c - 1509
- "fr-cm" + // 02c0c - 1514
- "fr-dj" + // 01000 - 1519
- "fr-dz" + // 01000 - 1524
- "fr-fr" + // 0040c - 1529
- "fr-ga" + // 01000 - 1534
- "fr-gf" + // 01000 - 1539
- "fr-gn" + // 01000 - 1544
- "fr-gp" + // 01000 - 1549
- "fr-gq" + // 01000 - 1554
- "fr-ht" + // 03c0c - 1559
- "fr-km" + // 01000 - 1564
- "fr-lu" + // 0140c - 1569
- "fr-ma" + // 0380c - 1574
- "fr-mc" + // 0180c - 1579
- "fr-mf" + // 01000 - 1584
- "fr-mg" + // 01000 - 1589
- "fr-ml" + // 0340c - 1594
- "fr-mq" + // 01000 - 1599
- "fr-mr" + // 01000 - 1604
- "fr-mu" + // 01000 - 1609
- "fr-nc" + // 01000 - 1614
- "fr-ne" + // 01000 - 1619
- "fr-pf" + // 01000 - 1624
- "fr-pm" + // 01000 - 1629
- "fr-re" + // 0200c - 1634
- "fr-rw" + // 01000 - 1639
- "fr-sc" + // 01000 - 1644
- "fr-sn" + // 0280c - 1649
- "fr-sy" + // 01000 - 1654
- "fr-td" + // 01000 - 1659
- "fr-tg" + // 01000 - 1664
- "fr-tn" + // 01000 - 1669
- "fr-vu" + // 01000 - 1674
- "fr-wf" + // 01000 - 1679
- "fr-yt" + // 01000 - 1684
- "fur" + // 01000 - 1689
- "fur-it" + // 01000 - 1692
- "fy" + // 00062 - 1698
- "fy-nl" + // 00462 - 1700
- "ga" + // 0003c - 1705
- "ga-ie" + // 0083c - 1707
- "gd" + // 00091 - 1712
- "gd-gb" + // 00491 - 1714
- "gl" + // 00056 - 1719
- "gl-es" + // 00456 - 1721
- "gn" + // 00074 - 1726
- "gn-py" + // 00474 - 1728
- "gsw" + // 00084 - 1733
- "gsw-ch" + // 01000 - 1736
- "gsw-fr" + // 00484 - 1742
- "gsw-li" + // 01000 - 1748
- "gu" + // 00047 - 1754
- "gu-in" + // 00447 - 1756
- "guz" + // 01000 - 1761
- "guz-ke" + // 01000 - 1764
- "gv" + // 01000 - 1770
- "gv-im" + // 01000 - 1772
- "ha" + // 00068 - 1777
- "ha-latn" + // 07c68 - 1779
- "ha-latn-gh" + // 01000 - 1786
- "ha-latn-ne" + // 01000 - 1796
- "ha-latn-ng" + // 00468 - 1806
- "haw" + // 00075 - 1816
- "haw-us" + // 00475 - 1819
- "he" + // 0000d - 1825
- "he-il" + // 0040d - 1827
- "hi" + // 00039 - 1832
- "hi-in" + // 00439 - 1834
- "hr" + // 0001a - 1839
- "hr-ba" + // 0101a - 1841
- "hr-hr" + // 0041a - 1846
- "hsb" + // 0002e - 1851
- "hsb-de" + // 0042e - 1854
- "hu" + // 0000e - 1860
- "hu-hu" + // 0040e - 1862
- "hu-hu_technl" + // 1040e - 1867
- "hy" + // 0002b - 1879
- "hy-am" + // 0042b - 1881
- "ia" + // 01000 - 1886
- "ia-001" + // 01000 - 1888
- "ia-fr" + // 01000 - 1894
- "ibb" + // 00069 - 1899
- "ibb-ng" + // 00469 - 1902
- "id" + // 00021 - 1908
- "id-id" + // 00421 - 1910
- "ig" + // 00070 - 1915
- "ig-ng" + // 00470 - 1917
- "ii" + // 00078 - 1922
- "ii-cn" + // 00478 - 1924
- "is" + // 0000f - 1929
- "is-is" + // 0040f - 1931
- "it" + // 00010 - 1936
- "it-ch" + // 00810 - 1938
- "it-it" + // 00410 - 1943
- "it-sm" + // 01000 - 1948
- "iu" + // 0005d - 1953
- "iu-cans" + // 0785d - 1955
- "iu-cans-ca" + // 0045d - 1962
- "iu-latn" + // 07c5d - 1972
- "iu-latn-ca" + // 0085d - 1979
- "ja" + // 00011 - 1989
- "ja-jp" + // 00411 - 1991
- "ja-jp_radstr" + // 40411 - 1996
- "jgo" + // 01000 - 2008
- "jgo-cm" + // 01000 - 2011
- "jmc" + // 01000 - 2017
- "jmc-tz" + // 01000 - 2020
- "jv" + // 01000 - 2026
- "jv-java" + // 01000 - 2028
- "jv-java-id" + // 01000 - 2035
- "jv-latn" + // 01000 - 2045
- "jv-latn-id" + // 01000 - 2052
- "ka" + // 00037 - 2062
- "ka-ge" + // 00437 - 2064
- "ka-ge_modern" + // 10437 - 2069
- "kab" + // 01000 - 2081
- "kab-dz" + // 01000 - 2084
- "kam" + // 01000 - 2090
- "kam-ke" + // 01000 - 2093
- "kde" + // 01000 - 2099
- "kde-tz" + // 01000 - 2102
- "kea" + // 01000 - 2108
- "kea-cv" + // 01000 - 2111
- "khq" + // 01000 - 2117
- "khq-ml" + // 01000 - 2120
- "ki" + // 01000 - 2126
- "ki-ke" + // 01000 - 2128
- "kk" + // 0003f - 2133
- "kk-kz" + // 0043f - 2135
- "kkj" + // 01000 - 2140
- "kkj-cm" + // 01000 - 2143
- "kl" + // 0006f - 2149
- "kl-gl" + // 0046f - 2151
- "kln" + // 01000 - 2156
- "kln-ke" + // 01000 - 2159
- "km" + // 00053 - 2165
- "km-kh" + // 00453 - 2167
- "kn" + // 0004b - 2172
- "kn-in" + // 0044b - 2174
- "ko" + // 00012 - 2179
- "ko-kp" + // 01000 - 2181
- "ko-kr" + // 00412 - 2186
- "kok" + // 00057 - 2191
- "kok-in" + // 00457 - 2194
- "kr" + // 00071 - 2200
- "kr-ng" + // 00471 - 2202
- "ks" + // 00060 - 2207
- "ks-arab" + // 00460 - 2209
- "ks-arab-in" + // 01000 - 2216
- "ks-deva" + // 01000 - 2226
- "ks-deva-in" + // 00860 - 2233
- "ksb" + // 01000 - 2243
- "ksb-tz" + // 01000 - 2246
- "ksf" + // 01000 - 2252
- "ksf-cm" + // 01000 - 2255
- "ksh" + // 01000 - 2261
- "ksh-de" + // 01000 - 2264
- "ku" + // 00092 - 2270
- "ku-arab" + // 07c92 - 2272
- "ku-arab-iq" + // 00492 - 2279
- "ku-arab-ir" + // 01000 - 2289
- "kw" + // 01000 - 2299
- "kw-gb" + // 01000 - 2301
- "ky" + // 00040 - 2306
- "ky-kg" + // 00440 - 2308
- "la" + // 00076 - 2313
- "la-001" + // 00476 - 2315
- "lag" + // 01000 - 2321
- "lag-tz" + // 01000 - 2324
- "lb" + // 0006e - 2330
- "lb-lu" + // 0046e - 2332
- "lg" + // 01000 - 2337
- "lg-ug" + // 01000 - 2339
- "lkt" + // 01000 - 2344
- "lkt-us" + // 01000 - 2347
- "ln" + // 01000 - 2353
- "ln-ao" + // 01000 - 2355
- "ln-cd" + // 01000 - 2360
- "ln-cf" + // 01000 - 2365
- "ln-cg" + // 01000 - 2370
- "lo" + // 00054 - 2375
- "lo-la" + // 00454 - 2377
- "lrc" + // 01000 - 2382
- "lrc-iq" + // 01000 - 2385
- "lrc-ir" + // 01000 - 2391
- "lt" + // 00027 - 2397
- "lt-lt" + // 00427 - 2399
- "lu" + // 01000 - 2404
- "lu-cd" + // 01000 - 2406
- "luo" + // 01000 - 2411
- "luo-ke" + // 01000 - 2414
- "luy" + // 01000 - 2420
- "luy-ke" + // 01000 - 2423
- "lv" + // 00026 - 2429
- "lv-lv" + // 00426 - 2431
- "mas" + // 01000 - 2436
- "mas-ke" + // 01000 - 2439
- "mas-tz" + // 01000 - 2445
- "mer" + // 01000 - 2451
- "mer-ke" + // 01000 - 2454
- "mfe" + // 01000 - 2460
- "mfe-mu" + // 01000 - 2463
- "mg" + // 01000 - 2469
- "mg-mg" + // 01000 - 2471
- "mgh" + // 01000 - 2476
- "mgh-mz" + // 01000 - 2479
- "mgo" + // 01000 - 2485
- "mgo-cm" + // 01000 - 2488
- "mi" + // 00081 - 2494
- "mi-nz" + // 00481 - 2496
- "mk" + // 0002f - 2501
- "mk-mk" + // 0042f - 2503
- "ml" + // 0004c - 2508
- "ml-in" + // 0044c - 2510
- "mn" + // 00050 - 2515
- "mn-cyrl" + // 07850 - 2517
- "mn-mn" + // 00450 - 2524
- "mn-mong" + // 07c50 - 2529
- "mn-mong-cn" + // 00850 - 2536
- "mn-mong-mn" + // 00c50 - 2546
- "mni" + // 00058 - 2556
- "mni-in" + // 00458 - 2559
- "moh" + // 0007c - 2565
- "moh-ca" + // 0047c - 2568
- "mr" + // 0004e - 2574
- "mr-in" + // 0044e - 2576
- "ms" + // 0003e - 2581
- "ms-bn" + // 0083e - 2583
- "ms-my" + // 0043e - 2588
- "ms-sg" + // 01000 - 2593
- "mt" + // 0003a - 2598
- "mt-mt" + // 0043a - 2600
- "mua" + // 01000 - 2605
- "mua-cm" + // 01000 - 2608
- "my" + // 00055 - 2614
- "my-mm" + // 00455 - 2616
- "mzn" + // 01000 - 2621
- "mzn-ir" + // 01000 - 2624
- "naq" + // 01000 - 2630
- "naq-na" + // 01000 - 2633
- "nb" + // 07c14 - 2639
- "nb-no" + // 00414 - 2641
- "nb-sj" + // 01000 - 2646
- "nd" + // 01000 - 2651
- "nd-zw" + // 01000 - 2653
- "nds" + // 01000 - 2658
- "nds-de" + // 01000 - 2661
- "nds-nl" + // 01000 - 2667
- "ne" + // 00061 - 2673
- "ne-in" + // 00861 - 2675
- "ne-np" + // 00461 - 2680
- "nl" + // 00013 - 2685
- "nl-aw" + // 01000 - 2687
- "nl-be" + // 00813 - 2692
- "nl-bq" + // 01000 - 2697
- "nl-cw" + // 01000 - 2702
- "nl-nl" + // 00413 - 2707
- "nl-sr" + // 01000 - 2712
- "nl-sx" + // 01000 - 2717
- "nmg" + // 01000 - 2722
- "nmg-cm" + // 01000 - 2725
- "nn" + // 07814 - 2731
- "nn-no" + // 00814 - 2733
- "nnh" + // 01000 - 2738
- "nnh-cm" + // 01000 - 2741
- "no" + // 00014 - 2747
- "nqo" + // 01000 - 2749
- "nqo-gn" + // 01000 - 2752
- "nr" + // 01000 - 2758
- "nr-za" + // 01000 - 2760
- "nso" + // 0006c - 2765
- "nso-za" + // 0046c - 2768
- "nus" + // 01000 - 2774
- "nus-ss" + // 01000 - 2777
- "nyn" + // 01000 - 2783
- "nyn-ug" + // 01000 - 2786
- "oc" + // 00082 - 2792
- "oc-fr" + // 00482 - 2794
- "om" + // 00072 - 2799
- "om-et" + // 00472 - 2801
- "om-ke" + // 01000 - 2806
- "or" + // 00048 - 2811
- "or-in" + // 00448 - 2813
- "os" + // 01000 - 2818
- "os-ge" + // 01000 - 2820
- "os-ru" + // 01000 - 2825
- "pa" + // 00046 - 2830
- "pa-arab" + // 07c46 - 2832
- "pa-arab-pk" + // 00846 - 2839
- "pa-in" + // 00446 - 2849
- "pap" + // 00079 - 2854
- "pap-029" + // 00479 - 2857
- "pl" + // 00015 - 2864
- "pl-pl" + // 00415 - 2866
- "prg" + // 01000 - 2871
- "prg-001" + // 01000 - 2874
- "prs" + // 0008c - 2881
- "prs-af" + // 0048c - 2884
- "ps" + // 00063 - 2890
- "ps-af" + // 00463 - 2892
- "pt" + // 00016 - 2897
- "pt-ao" + // 01000 - 2899
- "pt-br" + // 00416 - 2904
- "pt-ch" + // 01000 - 2909
- "pt-cv" + // 01000 - 2914
- "pt-gq" + // 01000 - 2919
- "pt-gw" + // 01000 - 2924
- "pt-lu" + // 01000 - 2929
- "pt-mo" + // 01000 - 2934
- "pt-mz" + // 01000 - 2939
- "pt-pt" + // 00816 - 2944
- "pt-st" + // 01000 - 2949
- "pt-tl" + // 01000 - 2954
- "qps-latn-x-sh" + // 00901 - 2959
- "qps-ploc" + // 00501 - 2972
- "qps-ploca" + // 005fe - 2980
- "qps-plocm" + // 009ff - 2989
- "quc" + // 00086 - 2998
- "quc-latn" + // 07c86 - 3001
- "quc-latn-gt" + // 00486 - 3009
- "quz" + // 0006b - 3020
- "quz-bo" + // 0046b - 3023
- "quz-ec" + // 0086b - 3029
- "quz-pe" + // 00c6b - 3035
- "rm" + // 00017 - 3041
- "rm-ch" + // 00417 - 3043
- "rn" + // 01000 - 3048
- "rn-bi" + // 01000 - 3050
- "ro" + // 00018 - 3055
- "ro-md" + // 00818 - 3057
- "ro-ro" + // 00418 - 3062
- "rof" + // 01000 - 3067
- "rof-tz" + // 01000 - 3070
- "ru" + // 00019 - 3076
- "ru-by" + // 01000 - 3078
- "ru-kg" + // 01000 - 3083
- "ru-kz" + // 01000 - 3088
- "ru-md" + // 00819 - 3093
- "ru-ru" + // 00419 - 3098
- "ru-ua" + // 01000 - 3103
- "rw" + // 00087 - 3108
- "rw-rw" + // 00487 - 3110
- "rwk" + // 01000 - 3115
- "rwk-tz" + // 01000 - 3118
- "sa" + // 0004f - 3124
- "sa-in" + // 0044f - 3126
- "sah" + // 00085 - 3131
- "sah-ru" + // 00485 - 3134
- "saq" + // 01000 - 3140
- "saq-ke" + // 01000 - 3143
- "sbp" + // 01000 - 3149
- "sbp-tz" + // 01000 - 3152
- "sd" + // 00059 - 3158
- "sd-arab" + // 07c59 - 3160
- "sd-arab-pk" + // 00859 - 3167
- "sd-deva" + // 01000 - 3177
- "sd-deva-in" + // 00459 - 3184
- "se" + // 0003b - 3194
- "se-fi" + // 00c3b - 3196
- "se-no" + // 0043b - 3201
- "se-se" + // 0083b - 3206
- "seh" + // 01000 - 3211
- "seh-mz" + // 01000 - 3214
- "ses" + // 01000 - 3220
- "ses-ml" + // 01000 - 3223
- "sg" + // 01000 - 3229
- "sg-cf" + // 01000 - 3231
- "shi" + // 01000 - 3236
- "shi-latn" + // 01000 - 3239
- "shi-latn-ma" + // 01000 - 3247
- "shi-tfng" + // 01000 - 3258
- "shi-tfng-ma" + // 01000 - 3266
- "si" + // 0005b - 3277
- "si-lk" + // 0045b - 3279
- "sk" + // 0001b - 3284
- "sk-sk" + // 0041b - 3286
- "sl" + // 00024 - 3291
- "sl-si" + // 00424 - 3293
- "sma" + // 0783b - 3298
- "sma-no" + // 0183b - 3301
- "sma-se" + // 01c3b - 3307
- "smj" + // 07c3b - 3313
- "smj-no" + // 0103b - 3316
- "smj-se" + // 0143b - 3322
- "smn" + // 0703b - 3328
- "smn-fi" + // 0243b - 3331
- "sms" + // 0743b - 3337
- "sms-fi" + // 0203b - 3340
- "sn" + // 01000 - 3346
- "sn-latn" + // 01000 - 3348
- "sn-latn-zw" + // 01000 - 3355
- "so" + // 00077 - 3365
- "so-dj" + // 01000 - 3367
- "so-et" + // 01000 - 3372
- "so-ke" + // 01000 - 3377
- "so-so" + // 00477 - 3382
- "sq" + // 0001c - 3387
- "sq-al" + // 0041c - 3389
- "sq-mk" + // 01000 - 3394
- "sq-xk" + // 01000 - 3399
- "sr" + // 07c1a - 3404
- "sr-cyrl" + // 06c1a - 3406
- "sr-cyrl-ba" + // 01c1a - 3413
- "sr-cyrl-cs" + // 00c1a - 3423
- "sr-cyrl-me" + // 0301a - 3433
- "sr-cyrl-rs" + // 0281a - 3443
- "sr-cyrl-xk" + // 01000 - 3453
- "sr-latn" + // 0701a - 3463
- "sr-latn-ba" + // 0181a - 3470
- "sr-latn-cs" + // 0081a - 3480
- "sr-latn-me" + // 02c1a - 3490
- "sr-latn-rs" + // 0241a - 3500
- "sr-latn-xk" + // 01000 - 3510
- "ss" + // 01000 - 3520
- "ss-sz" + // 01000 - 3522
- "ss-za" + // 01000 - 3527
- "ssy" + // 01000 - 3532
- "ssy-er" + // 01000 - 3535
- "st" + // 00030 - 3541
- "st-ls" + // 01000 - 3543
- "st-za" + // 00430 - 3548
- "sv" + // 0001d - 3553
- "sv-ax" + // 01000 - 3555
- "sv-fi" + // 0081d - 3560
- "sv-se" + // 0041d - 3565
- "sw" + // 00041 - 3570
- "sw-cd" + // 01000 - 3572
- "sw-ke" + // 00441 - 3577
- "sw-tz" + // 01000 - 3582
- "sw-ug" + // 01000 - 3587
- "swc" + // 01000 - 3592
- "swc-cd" + // 01000 - 3595
- "syr" + // 0005a - 3601
- "syr-sy" + // 0045a - 3604
- "ta" + // 00049 - 3610
- "ta-in" + // 00449 - 3612
- "ta-lk" + // 00849 - 3617
- "ta-my" + // 01000 - 3622
- "ta-sg" + // 01000 - 3627
- "te" + // 0004a - 3632
- "te-in" + // 0044a - 3634
- "teo" + // 01000 - 3639
- "teo-ke" + // 01000 - 3642
- "teo-ug" + // 01000 - 3648
- "tg" + // 00028 - 3654
- "tg-cyrl" + // 07c28 - 3656
- "tg-cyrl-tj" + // 00428 - 3663
- "th" + // 0001e - 3673
- "th-th" + // 0041e - 3675
- "ti" + // 00073 - 3680
- "ti-er" + // 00873 - 3682
- "ti-et" + // 00473 - 3687
- "tig" + // 01000 - 3692
- "tig-er" + // 01000 - 3695
- "tk" + // 00042 - 3701
- "tk-tm" + // 00442 - 3703
- "tn" + // 00032 - 3708
- "tn-bw" + // 00832 - 3710
- "tn-za" + // 00432 - 3715
- "to" + // 01000 - 3720
- "to-to" + // 01000 - 3722
- "tr" + // 0001f - 3727
- "tr-cy" + // 01000 - 3729
- "tr-tr" + // 0041f - 3734
- "ts" + // 00031 - 3739
- "ts-za" + // 00431 - 3741
- "tt" + // 00044 - 3746
- "tt-ru" + // 00444 - 3748
- "twq" + // 01000 - 3753
- "twq-ne" + // 01000 - 3756
- "tzm" + // 0005f - 3762
- "tzm-arab" + // 01000 - 3765
- "tzm-arab-ma" + // 0045f - 3773
- "tzm-latn" + // 07c5f - 3784
- "tzm-latn-dz" + // 0085f - 3792
- "tzm-latn-ma" + // 01000 - 3803
- "tzm-tfng" + // 0785f - 3814
- "tzm-tfng-ma" + // 0105f - 3822
- "ug" + // 00080 - 3833
- "ug-cn" + // 00480 - 3835
- "uk" + // 00022 - 3840
- "uk-ua" + // 00422 - 3842
- "ur" + // 00020 - 3847
- "ur-in" + // 00820 - 3849
- "ur-pk" + // 00420 - 3854
- "uz" + // 00043 - 3859
- "uz-arab" + // 01000 - 3861
- "uz-arab-af" + // 01000 - 3868
- "uz-cyrl" + // 07843 - 3878
- "uz-cyrl-uz" + // 00843 - 3885
- "uz-latn" + // 07c43 - 3895
- "uz-latn-uz" + // 00443 - 3902
- "vai" + // 01000 - 3912
- "vai-latn" + // 01000 - 3915
- "vai-latn-lr" + // 01000 - 3923
- "vai-vaii" + // 01000 - 3934
- "vai-vaii-lr" + // 01000 - 3942
- "ve" + // 00033 - 3953
- "ve-za" + // 00433 - 3955
- "vi" + // 0002a - 3960
- "vi-vn" + // 0042a - 3962
- "vo" + // 01000 - 3967
- "vo-001" + // 01000 - 3969
- "vun" + // 01000 - 3975
- "vun-tz" + // 01000 - 3978
- "wae" + // 01000 - 3984
- "wae-ch" + // 01000 - 3987
- "wal" + // 01000 - 3993
- "wal-et" + // 01000 - 3996
- "wo" + // 00088 - 4002
- "wo-sn" + // 00488 - 4004
- "x-iv_mathan" + // 1007f - 4009
- "xh" + // 00034 - 4020
- "xh-za" + // 00434 - 4022
- "xog" + // 01000 - 4027
- "xog-ug" + // 01000 - 4030
- "yav" + // 01000 - 4036
- "yav-cm" + // 01000 - 4039
- "yi" + // 0003d - 4045
- "yi-001" + // 0043d - 4047
- "yo" + // 0006a - 4053
- "yo-bj" + // 01000 - 4055
- "yo-ng" + // 0046a - 4060
- "yue" + // 01000 - 4065
- "yue-hk" + // 01000 - 4068
- "zgh" + // 01000 - 4074
- "zgh-tfng" + // 01000 - 4077
- "zgh-tfng-ma" + // 01000 - 4085
- "zh" + // 07804 - 4096
- "zh-chs" + // 00004 - 4098
- "zh-cht" + // 07c04 - 4104
- "zh-cn" + // 00804 - 4110
- "zh-cn_phoneb" + // 50804 - 4115
- "zh-cn_stroke" + // 20804 - 4127
- "zh-hans" + // 00004 - 4139
- "zh-hans-hk" + // 01000 - 4146
- "zh-hans-mo" + // 01000 - 4156
- "zh-hant" + // 07c04 - 4166
- "zh-hk" + // 00c04 - 4173
- "zh-hk_radstr" + // 40c04 - 4178
- "zh-mo" + // 01404 - 4190
- "zh-mo_radstr" + // 41404 - 4195
- "zh-mo_stroke" + // 21404 - 4207
- "zh-sg" + // 01004 - 4219
- "zh-sg_phoneb" + // 51004 - 4224
- "zh-sg_stroke" + // 21004 - 4236
- "zh-tw" + // 00404 - 4248
- "zh-tw_pronun" + // 30404 - 4253
- "zh-tw_radstr" + // 40404 - 4265
- "zu" + // 00035 - 4277
- "zu-za"; // 00435 - 4279
-
- // c_threeLetterWindowsLanguageName is string containing 3-letter Windows language names
- // every 3-characters entry is matching locale name entry in c_localeNames
-
- private const string c_threeLetterWindowsLanguageName =
- "ZZZ" + // aa
- "ZZZ" + // aa-dj
- "ZZZ" + // aa-er
- "ZZZ" + // aa-et
- "AFK" + // af
- "ZZZ" + // af-na
- "AFK" + // af-za
- "ZZZ" + // agq
- "ZZZ" + // agq-cm
- "ZZZ" + // ak
- "ZZZ" + // ak-gh
- "AMH" + // am
- "AMH" + // am-et
- "ARA" + // ar
- "ZZZ" + // ar-001
- "ARU" + // ar-ae
- "ARH" + // ar-bh
- "ZZZ" + // ar-dj
- "ARG" + // ar-dz
- "ARE" + // ar-eg
- "ZZZ" + // ar-er
- "ZZZ" + // ar-il
- "ARI" + // ar-iq
- "ARJ" + // ar-jo
- "ZZZ" + // ar-km
- "ARK" + // ar-kw
- "ARB" + // ar-lb
- "ARL" + // ar-ly
- "ARM" + // ar-ma
- "ZZZ" + // ar-mr
- "ARO" + // ar-om
- "ZZZ" + // ar-ps
- "ARQ" + // ar-qa
- "ARA" + // ar-sa
- "ZZZ" + // ar-sd
- "ZZZ" + // ar-so
- "ZZZ" + // ar-ss
- "ARS" + // ar-sy
- "ZZZ" + // ar-td
- "ART" + // ar-tn
- "ARY" + // ar-ye
- "MPD" + // arn
- "MPD" + // arn-cl
- "ASM" + // as
- "ASM" + // as-in
- "ZZZ" + // asa
- "ZZZ" + // asa-tz
- "ZZZ" + // ast
- "ZZZ" + // ast-es
- "AZE" + // az
- "AZC" + // az-cyrl
- "AZC" + // az-cyrl-az
- "AZE" + // az-latn
- "AZE" + // az-latn-az
- "BAS" + // ba
- "BAS" + // ba-ru
- "ZZZ" + // bas
- "ZZZ" + // bas-cm
- "BEL" + // be
- "BEL" + // be-by
- "ZZZ" + // bem
- "ZZZ" + // bem-zm
- "ZZZ" + // bez
- "ZZZ" + // bez-tz
- "BGR" + // bg
- "BGR" + // bg-bg
- "ZZZ" + // bin
- "ZZZ" + // bin-ng
- "ZZZ" + // bm
- "ZZZ" + // bm-latn
- "ZZZ" + // bm-latn-ml
- "BNB" + // bn
- "BNB" + // bn-bd
- "BNG" + // bn-in
- "BOB" + // bo
- "BOB" + // bo-cn
- "ZZZ" + // bo-in
- "BRE" + // br
- "BRE" + // br-fr
- "ZZZ" + // brx
- "ZZZ" + // brx-in
- "BSB" + // bs
- "BSC" + // bs-cyrl
- "BSC" + // bs-cyrl-ba
- "BSB" + // bs-latn
- "BSB" + // bs-latn-ba
- "ZZZ" + // byn
- "ZZZ" + // byn-er
- "CAT" + // ca
- "ZZZ" + // ca-ad
- "CAT" + // ca-es
- "VAL" + // ca-es-valencia
- "ZZZ" + // ca-fr
- "ZZZ" + // ca-it
- "ZZZ" + // ce
- "ZZZ" + // ce-ru
- "ZZZ" + // cgg
- "ZZZ" + // cgg-ug
- "CRE" + // chr
- "CRE" + // chr-cher
- "CRE" + // chr-cher-us
- "COS" + // co
- "COS" + // co-fr
- "CSY" + // cs
- "CSY" + // cs-cz
- "ZZZ" + // cu
- "ZZZ" + // cu-ru
- "CYM" + // cy
- "CYM" + // cy-gb
- "DAN" + // da
- "DAN" + // da-dk
- "ZZZ" + // da-gl
- "ZZZ" + // dav
- "ZZZ" + // dav-ke
- "DEU" + // de
- "DEA" + // de-at
- "ZZZ" + // de-be
- "DES" + // de-ch
- "DEU" + // de-de
- "DEU" + // de-de_phoneb
- "ZZZ" + // de-it
- "DEC" + // de-li
- "DEL" + // de-lu
- "ZZZ" + // dje
- "ZZZ" + // dje-ne
- "DSB" + // dsb
- "DSB" + // dsb-de
- "ZZZ" + // dua
- "ZZZ" + // dua-cm
- "DIV" + // dv
- "DIV" + // dv-mv
- "ZZZ" + // dyo
- "ZZZ" + // dyo-sn
- "ZZZ" + // dz
- "ZZZ" + // dz-bt
- "ZZZ" + // ebu
- "ZZZ" + // ebu-ke
- "ZZZ" + // ee
- "ZZZ" + // ee-gh
- "ZZZ" + // ee-tg
- "ELL" + // el
- "ZZZ" + // el-cy
- "ELL" + // el-gr
- "ENU" + // en
- "ZZZ" + // en-001
- "ENB" + // en-029
- "ZZZ" + // en-150
- "ZZZ" + // en-ag
- "ZZZ" + // en-ai
- "ZZZ" + // en-as
- "ZZZ" + // en-at
- "ENA" + // en-au
- "ZZZ" + // en-bb
- "ZZZ" + // en-be
- "ZZZ" + // en-bi
- "ZZZ" + // en-bm
- "ZZZ" + // en-bs
- "ZZZ" + // en-bw
- "ENL" + // en-bz
- "ENC" + // en-ca
- "ZZZ" + // en-cc
- "ZZZ" + // en-ch
- "ZZZ" + // en-ck
- "ZZZ" + // en-cm
- "ZZZ" + // en-cx
- "ZZZ" + // en-cy
- "ZZZ" + // en-de
- "ZZZ" + // en-dk
- "ZZZ" + // en-dm
- "ZZZ" + // en-er
- "ZZZ" + // en-fi
- "ZZZ" + // en-fj
- "ZZZ" + // en-fk
- "ZZZ" + // en-fm
- "ENG" + // en-gb
- "ZZZ" + // en-gd
- "ZZZ" + // en-gg
- "ZZZ" + // en-gh
- "ZZZ" + // en-gi
- "ZZZ" + // en-gm
- "ZZZ" + // en-gu
- "ZZZ" + // en-gy
- "ENH" + // en-hk
- "ZZZ" + // en-id
- "ENI" + // en-ie
- "ZZZ" + // en-il
- "ZZZ" + // en-im
- "ENN" + // en-in
- "ZZZ" + // en-io
- "ZZZ" + // en-je
- "ENJ" + // en-jm
- "ZZZ" + // en-ke
- "ZZZ" + // en-ki
- "ZZZ" + // en-kn
- "ZZZ" + // en-ky
- "ZZZ" + // en-lc
- "ZZZ" + // en-lr
- "ZZZ" + // en-ls
- "ZZZ" + // en-mg
- "ZZZ" + // en-mh
- "ZZZ" + // en-mo
- "ZZZ" + // en-mp
- "ZZZ" + // en-ms
- "ZZZ" + // en-mt
- "ZZZ" + // en-mu
- "ZZZ" + // en-mw
- "ENM" + // en-my
- "ZZZ" + // en-na
- "ZZZ" + // en-nf
- "ZZZ" + // en-ng
- "ZZZ" + // en-nl
- "ZZZ" + // en-nr
- "ZZZ" + // en-nu
- "ENZ" + // en-nz
- "ZZZ" + // en-pg
- "ENP" + // en-ph
- "ZZZ" + // en-pk
- "ZZZ" + // en-pn
- "ZZZ" + // en-pr
- "ZZZ" + // en-pw
- "ZZZ" + // en-rw
- "ZZZ" + // en-sb
- "ZZZ" + // en-sc
- "ZZZ" + // en-sd
- "ZZZ" + // en-se
- "ENE" + // en-sg
- "ZZZ" + // en-sh
- "ZZZ" + // en-si
- "ZZZ" + // en-sl
- "ZZZ" + // en-ss
- "ZZZ" + // en-sx
- "ZZZ" + // en-sz
- "ZZZ" + // en-tc
- "ZZZ" + // en-tk
- "ZZZ" + // en-to
- "ENT" + // en-tt
- "ZZZ" + // en-tv
- "ZZZ" + // en-tz
- "ZZZ" + // en-ug
- "ZZZ" + // en-um
- "ENU" + // en-us
- "ZZZ" + // en-vc
- "ZZZ" + // en-vg
- "ZZZ" + // en-vi
- "ZZZ" + // en-vu
- "ZZZ" + // en-ws
- "ENS" + // en-za
- "ZZZ" + // en-zm
- "ENW" + // en-zw
- "ZZZ" + // eo
- "ZZZ" + // eo-001
- "ESN" + // es
- "ESJ" + // es-419
- "ESS" + // es-ar
- "ESB" + // es-bo
- "ZZZ" + // es-br
- "ESL" + // es-cl
- "ESO" + // es-co
- "ESC" + // es-cr
- "ESK" + // es-cu
- "ESD" + // es-do
- "ESF" + // es-ec
- "ESN" + // es-es
- "ESP" + // es-es_tradnl
- "ZZZ" + // es-gq
- "ESG" + // es-gt
- "ESH" + // es-hn
- "ESM" + // es-mx
- "ESI" + // es-ni
- "ESA" + // es-pa
- "ESR" + // es-pe
- "ZZZ" + // es-ph
- "ESU" + // es-pr
- "ESZ" + // es-py
- "ESE" + // es-sv
- "EST" + // es-us
- "ESY" + // es-uy
- "ESV" + // es-ve
- "ETI" + // et
- "ETI" + // et-ee
- "EUQ" + // eu
- "EUQ" + // eu-es
- "ZZZ" + // ewo
- "ZZZ" + // ewo-cm
- "FAR" + // fa
- "FAR" + // fa-ir
- "FUL" + // ff
- "ZZZ" + // ff-cm
- "ZZZ" + // ff-gn
- "FUL" + // ff-latn
- "FUL" + // ff-latn-sn
- "ZZZ" + // ff-mr
- "ZZZ" + // ff-ng
- "FIN" + // fi
- "FIN" + // fi-fi
- "FPO" + // fil
- "FPO" + // fil-ph
- "FOS" + // fo
- "ZZZ" + // fo-dk
- "FOS" + // fo-fo
- "FRA" + // fr
- "ZZZ" + // fr-029
- "FRB" + // fr-be
- "ZZZ" + // fr-bf
- "ZZZ" + // fr-bi
- "ZZZ" + // fr-bj
- "ZZZ" + // fr-bl
- "FRC" + // fr-ca
- "FRD" + // fr-cd
- "ZZZ" + // fr-cf
- "ZZZ" + // fr-cg
- "FRS" + // fr-ch
- "FRI" + // fr-ci
- "FRE" + // fr-cm
- "ZZZ" + // fr-dj
- "ZZZ" + // fr-dz
- "FRA" + // fr-fr
- "ZZZ" + // fr-ga
- "ZZZ" + // fr-gf
- "ZZZ" + // fr-gn
- "ZZZ" + // fr-gp
- "ZZZ" + // fr-gq
- "FRH" + // fr-ht
- "ZZZ" + // fr-km
- "FRL" + // fr-lu
- "FRO" + // fr-ma
- "FRM" + // fr-mc
- "ZZZ" + // fr-mf
- "ZZZ" + // fr-mg
- "FRF" + // fr-ml
- "ZZZ" + // fr-mq
- "ZZZ" + // fr-mr
- "ZZZ" + // fr-mu
- "ZZZ" + // fr-nc
- "ZZZ" + // fr-ne
- "ZZZ" + // fr-pf
- "ZZZ" + // fr-pm
- "FRR" + // fr-re
- "ZZZ" + // fr-rw
- "ZZZ" + // fr-sc
- "FRN" + // fr-sn
- "ZZZ" + // fr-sy
- "ZZZ" + // fr-td
- "ZZZ" + // fr-tg
- "ZZZ" + // fr-tn
- "ZZZ" + // fr-vu
- "ZZZ" + // fr-wf
- "ZZZ" + // fr-yt
- "ZZZ" + // fur
- "ZZZ" + // fur-it
- "FYN" + // fy
- "FYN" + // fy-nl
- "IRE" + // ga
- "IRE" + // ga-ie
- "GLA" + // gd
- "GLA" + // gd-gb
- "GLC" + // gl
- "GLC" + // gl-es
- "GRN" + // gn
- "GRN" + // gn-py
- "ZZZ" + // gsw
- "ZZZ" + // gsw-ch
- "GSW" + // gsw-fr
- "ZZZ" + // gsw-li
- "GUJ" + // gu
- "GUJ" + // gu-in
- "ZZZ" + // guz
- "ZZZ" + // guz-ke
- "ZZZ" + // gv
- "ZZZ" + // gv-im
- "HAU" + // ha
- "HAU" + // ha-latn
- "ZZZ" + // ha-latn-gh
- "ZZZ" + // ha-latn-ne
- "HAU" + // ha-latn-ng
- "HAW" + // haw
- "HAW" + // haw-us
- "HEB" + // he
- "HEB" + // he-il
- "HIN" + // hi
- "HIN" + // hi-in
- "HRV" + // hr
- "HRB" + // hr-ba
- "HRV" + // hr-hr
- "HSB" + // hsb
- "HSB" + // hsb-de
- "HUN" + // hu
- "HUN" + // hu-hu
- "HUN" + // hu-hu_technl
- "HYE" + // hy
- "HYE" + // hy-am
- "ZZZ" + // ia
- "ZZZ" + // ia-001
- "ZZZ" + // ia-fr
- "ZZZ" + // ibb
- "ZZZ" + // ibb-ng
- "IND" + // id
- "IND" + // id-id
- "IBO" + // ig
- "IBO" + // ig-ng
- "III" + // ii
- "III" + // ii-cn
- "ISL" + // is
- "ISL" + // is-is
- "ITA" + // it
- "ITS" + // it-ch
- "ITA" + // it-it
- "ZZZ" + // it-sm
- "IUK" + // iu
- "IUS" + // iu-cans
- "IUS" + // iu-cans-ca
- "IUK" + // iu-latn
- "IUK" + // iu-latn-ca
- "JPN" + // ja
- "JPN" + // ja-jp
- "JPN" + // ja-jp_radstr
- "ZZZ" + // jgo
- "ZZZ" + // jgo-cm
- "ZZZ" + // jmc
- "ZZZ" + // jmc-tz
- "JAV" + // jv
- "ZZZ" + // jv-java
- "ZZZ" + // jv-java-id
- "JAV" + // jv-latn
- "JAV" + // jv-latn-id
- "KAT" + // ka
- "KAT" + // ka-ge
- "KAT" + // ka-ge_modern
- "ZZZ" + // kab
- "ZZZ" + // kab-dz
- "ZZZ" + // kam
- "ZZZ" + // kam-ke
- "ZZZ" + // kde
- "ZZZ" + // kde-tz
- "ZZZ" + // kea
- "ZZZ" + // kea-cv
- "ZZZ" + // khq
- "ZZZ" + // khq-ml
- "ZZZ" + // ki
- "ZZZ" + // ki-ke
- "KKZ" + // kk
- "KKZ" + // kk-kz
- "ZZZ" + // kkj
- "ZZZ" + // kkj-cm
- "KAL" + // kl
- "KAL" + // kl-gl
- "ZZZ" + // kln
- "ZZZ" + // kln-ke
- "KHM" + // km
- "KHM" + // km-kh
- "KDI" + // kn
- "KDI" + // kn-in
- "KOR" + // ko
- "ZZZ" + // ko-kp
- "KOR" + // ko-kr
- "KNK" + // kok
- "KNK" + // kok-in
- "ZZZ" + // kr
- "ZZZ" + // kr-ng
- "ZZZ" + // ks
- "ZZZ" + // ks-arab
- "ZZZ" + // ks-arab-in
- "ZZZ" + // ks-deva
- "ZZZ" + // ks-deva-in
- "ZZZ" + // ksb
- "ZZZ" + // ksb-tz
- "ZZZ" + // ksf
- "ZZZ" + // ksf-cm
- "ZZZ" + // ksh
- "ZZZ" + // ksh-de
- "KUR" + // ku
- "KUR" + // ku-arab
- "KUR" + // ku-arab-iq
- "ZZZ" + // ku-arab-ir
- "ZZZ" + // kw
- "ZZZ" + // kw-gb
- "KYR" + // ky
- "KYR" + // ky-kg
- "ZZZ" + // la
- "ZZZ" + // la-001
- "ZZZ" + // lag
- "ZZZ" + // lag-tz
- "LBX" + // lb
- "LBX" + // lb-lu
- "ZZZ" + // lg
- "ZZZ" + // lg-ug
- "ZZZ" + // lkt
- "ZZZ" + // lkt-us
- "ZZZ" + // ln
- "ZZZ" + // ln-ao
- "ZZZ" + // ln-cd
- "ZZZ" + // ln-cf
- "ZZZ" + // ln-cg
- "LAO" + // lo
- "LAO" + // lo-la
- "ZZZ" + // lrc
- "ZZZ" + // lrc-iq
- "ZZZ" + // lrc-ir
- "LTH" + // lt
- "LTH" + // lt-lt
- "ZZZ" + // lu
- "ZZZ" + // lu-cd
- "ZZZ" + // luo
- "ZZZ" + // luo-ke
- "ZZZ" + // luy
- "ZZZ" + // luy-ke
- "LVI" + // lv
- "LVI" + // lv-lv
- "ZZZ" + // mas
- "ZZZ" + // mas-ke
- "ZZZ" + // mas-tz
- "ZZZ" + // mer
- "ZZZ" + // mer-ke
- "ZZZ" + // mfe
- "ZZZ" + // mfe-mu
- "MLG" + // mg
- "MLG" + // mg-mg
- "ZZZ" + // mgh
- "ZZZ" + // mgh-mz
- "ZZZ" + // mgo
- "ZZZ" + // mgo-cm
- "MRI" + // mi
- "MRI" + // mi-nz
- "MKI" + // mk
- "MKI" + // mk-mk
- "MYM" + // ml
- "MYM" + // ml-in
- "MNN" + // mn
- "MNN" + // mn-cyrl
- "MNN" + // mn-mn
- "MNG" + // mn-mong
- "MNG" + // mn-mong-cn
- "MNM" + // mn-mong-mn
- "ZZZ" + // mni
- "ZZZ" + // mni-in
- "MWK" + // moh
- "MWK" + // moh-ca
- "MAR" + // mr
- "MAR" + // mr-in
- "MSL" + // ms
- "MSB" + // ms-bn
- "MSL" + // ms-my
- "ZZZ" + // ms-sg
- "MLT" + // mt
- "MLT" + // mt-mt
- "ZZZ" + // mua
- "ZZZ" + // mua-cm
- "MYA" + // my
- "MYA" + // my-mm
- "ZZZ" + // mzn
- "ZZZ" + // mzn-ir
- "ZZZ" + // naq
- "ZZZ" + // naq-na
- "NOR" + // nb
- "NOR" + // nb-no
- "ZZZ" + // nb-sj
- "ZZZ" + // nd
- "ZZZ" + // nd-zw
- "ZZZ" + // nds
- "ZZZ" + // nds-de
- "ZZZ" + // nds-nl
- "NEP" + // ne
- "NEI" + // ne-in
- "NEP" + // ne-np
- "NLD" + // nl
- "ZZZ" + // nl-aw
- "NLB" + // nl-be
- "ZZZ" + // nl-bq
- "ZZZ" + // nl-cw
- "NLD" + // nl-nl
- "ZZZ" + // nl-sr
- "ZZZ" + // nl-sx
- "ZZZ" + // nmg
- "ZZZ" + // nmg-cm
- "NON" + // nn
- "NON" + // nn-no
- "ZZZ" + // nnh
- "ZZZ" + // nnh-cm
- "NOR" + // no
- "NQO" + // nqo
- "NQO" + // nqo-gn
- "ZZZ" + // nr
- "ZZZ" + // nr-za
- "NSO" + // nso
- "NSO" + // nso-za
- "ZZZ" + // nus
- "ZZZ" + // nus-ss
- "ZZZ" + // nyn
- "ZZZ" + // nyn-ug
- "OCI" + // oc
- "OCI" + // oc-fr
- "ORM" + // om
- "ORM" + // om-et
- "ZZZ" + // om-ke
- "ORI" + // or
- "ORI" + // or-in
- "ZZZ" + // os
- "ZZZ" + // os-ge
- "ZZZ" + // os-ru
- "PAN" + // pa
- "PAP" + // pa-arab
- "PAP" + // pa-arab-pk
- "PAN" + // pa-in
- "ZZZ" + // pap
- "ZZZ" + // pap-029
- "PLK" + // pl
- "PLK" + // pl-pl
- "ZZZ" + // prg
- "ZZZ" + // prg-001
- "PRS" + // prs
- "PRS" + // prs-af
- "PAS" + // ps
- "PAS" + // ps-af
- "PTB" + // pt
- "PTA" + // pt-ao
- "PTB" + // pt-br
- "ZZZ" + // pt-ch
- "ZZZ" + // pt-cv
- "ZZZ" + // pt-gq
- "ZZZ" + // pt-gw
- "ZZZ" + // pt-lu
- "ZZZ" + // pt-mo
- "ZZZ" + // pt-mz
- "PTG" + // pt-pt
- "ZZZ" + // pt-st
- "ZZZ" + // pt-tl
- "ENJ" + // qps-latn-x-sh
- "ENU" + // qps-ploc
- "JPN" + // qps-ploca
- "ARA" + // qps-plocm
- "QUT" + // quc
- "QUT" + // quc-latn
- "QUT" + // quc-latn-gt
- "QUB" + // quz
- "QUB" + // quz-bo
- "QUE" + // quz-ec
- "QUP" + // quz-pe
- "RMC" + // rm
- "RMC" + // rm-ch
- "ZZZ" + // rn
- "ZZZ" + // rn-bi
- "ROM" + // ro
- "ROD" + // ro-md
- "ROM" + // ro-ro
- "ZZZ" + // rof
- "ZZZ" + // rof-tz
- "RUS" + // ru
- "ZZZ" + // ru-by
- "ZZZ" + // ru-kg
- "ZZZ" + // ru-kz
- "RUM" + // ru-md
- "RUS" + // ru-ru
- "ZZZ" + // ru-ua
- "KIN" + // rw
- "KIN" + // rw-rw
- "ZZZ" + // rwk
- "ZZZ" + // rwk-tz
- "SAN" + // sa
- "SAN" + // sa-in
- "SAH" + // sah
- "SAH" + // sah-ru
- "ZZZ" + // saq
- "ZZZ" + // saq-ke
- "ZZZ" + // sbp
- "ZZZ" + // sbp-tz
- "SIP" + // sd
- "SIP" + // sd-arab
- "SIP" + // sd-arab-pk
- "ZZZ" + // sd-deva
- "ZZZ" + // sd-deva-in
- "SME" + // se
- "SMG" + // se-fi
- "SME" + // se-no
- "SMF" + // se-se
- "ZZZ" + // seh
- "ZZZ" + // seh-mz
- "ZZZ" + // ses
- "ZZZ" + // ses-ml
- "ZZZ" + // sg
- "ZZZ" + // sg-cf
- "ZZZ" + // shi
- "ZZZ" + // shi-latn
- "ZZZ" + // shi-latn-ma
- "ZZZ" + // shi-tfng
- "ZZZ" + // shi-tfng-ma
- "SIN" + // si
- "SIN" + // si-lk
- "SKY" + // sk
- "SKY" + // sk-sk
- "SLV" + // sl
- "SLV" + // sl-si
- "SMB" + // sma
- "SMA" + // sma-no
- "SMB" + // sma-se
- "SMK" + // smj
- "SMJ" + // smj-no
- "SMK" + // smj-se
- "SMN" + // smn
- "SMN" + // smn-fi
- "SMS" + // sms
- "SMS" + // sms-fi
- "SNA" + // sn
- "SNA" + // sn-latn
- "SNA" + // sn-latn-zw
- "SOM" + // so
- "ZZZ" + // so-dj
- "ZZZ" + // so-et
- "ZZZ" + // so-ke
- "SOM" + // so-so
- "SQI" + // sq
- "SQI" + // sq-al
- "ZZZ" + // sq-mk
- "ZZZ" + // sq-xk
- "SRM" + // sr
- "SRO" + // sr-cyrl
- "SRN" + // sr-cyrl-ba
- "SRB" + // sr-cyrl-cs
- "SRQ" + // sr-cyrl-me
- "SRO" + // sr-cyrl-rs
- "ZZZ" + // sr-cyrl-xk
- "SRM" + // sr-latn
- "SRS" + // sr-latn-ba
- "SRL" + // sr-latn-cs
- "SRP" + // sr-latn-me
- "SRM" + // sr-latn-rs
- "ZZZ" + // sr-latn-xk
- "ZZZ" + // ss
- "ZZZ" + // ss-sz
- "ZZZ" + // ss-za
- "ZZZ" + // ssy
- "ZZZ" + // ssy-er
- "SOT" + // st
- "ZZZ" + // st-ls
- "SOT" + // st-za
- "SVE" + // sv
- "ZZZ" + // sv-ax
- "SVF" + // sv-fi
- "SVE" + // sv-se
- "SWK" + // sw
- "ZZZ" + // sw-cd
- "SWK" + // sw-ke
- "ZZZ" + // sw-tz
- "ZZZ" + // sw-ug
- "ZZZ" + // swc
- "ZZZ" + // swc-cd
- "SYR" + // syr
- "SYR" + // syr-sy
- "TAI" + // ta
- "TAI" + // ta-in
- "TAM" + // ta-lk
- "ZZZ" + // ta-my
- "ZZZ" + // ta-sg
- "TEL" + // te
- "TEL" + // te-in
- "ZZZ" + // teo
- "ZZZ" + // teo-ke
- "ZZZ" + // teo-ug
- "TAJ" + // tg
- "TAJ" + // tg-cyrl
- "TAJ" + // tg-cyrl-tj
- "THA" + // th
- "THA" + // th-th
- "TIR" + // ti
- "TIR" + // ti-er
- "TIE" + // ti-et
- "ZZZ" + // tig
- "ZZZ" + // tig-er
- "TUK" + // tk
- "TUK" + // tk-tm
- "TSN" + // tn
- "TSB" + // tn-bw
- "TSN" + // tn-za
- "ZZZ" + // to
- "ZZZ" + // to-to
- "TRK" + // tr
- "ZZZ" + // tr-cy
- "TRK" + // tr-tr
- "TSO" + // ts
- "TSO" + // ts-za
- "TTT" + // tt
- "TTT" + // tt-ru
- "ZZZ" + // twq
- "ZZZ" + // twq-ne
- "TZA" + // tzm
- "ZZZ" + // tzm-arab
- "ZZZ" + // tzm-arab-ma
- "TZA" + // tzm-latn
- "TZA" + // tzm-latn-dz
- "ZZZ" + // tzm-latn-ma
- "TZM" + // tzm-tfng
- "TZM" + // tzm-tfng-ma
- "UIG" + // ug
- "UIG" + // ug-cn
- "UKR" + // uk
- "UKR" + // uk-ua
- "URD" + // ur
- "URI" + // ur-in
- "URD" + // ur-pk
- "UZB" + // uz
- "ZZZ" + // uz-arab
- "ZZZ" + // uz-arab-af
- "UZC" + // uz-cyrl
- "UZC" + // uz-cyrl-uz
- "UZB" + // uz-latn
- "UZB" + // uz-latn-uz
- "ZZZ" + // vai
- "ZZZ" + // vai-latn
- "ZZZ" + // vai-latn-lr
- "ZZZ" + // vai-vaii
- "ZZZ" + // vai-vaii-lr
- "ZZZ" + // ve
- "ZZZ" + // ve-za
- "VIT" + // vi
- "VIT" + // vi-vn
- "ZZZ" + // vo
- "ZZZ" + // vo-001
- "ZZZ" + // vun
- "ZZZ" + // vun-tz
- "ZZZ" + // wae
- "ZZZ" + // wae-ch
- "ZZZ" + // wal
- "ZZZ" + // wal-et
- "WOL" + // wo
- "WOL" + // wo-sn
- "IVL" + // x-iv_mathan
- "XHO" + // xh
- "XHO" + // xh-za
- "ZZZ" + // xog
- "ZZZ" + // xog-ug
- "ZZZ" + // yav
- "ZZZ" + // yav-cm
- "ZZZ" + // yi
- "ZZZ" + // yi-001
- "YOR" + // yo
- "ZZZ" + // yo-bj
- "YOR" + // yo-ng
- "ZZZ" + // yue
- "ZZZ" + // yue-hk
- "ZHG" + // zgh
- "ZHG" + // zgh-tfng
- "ZHG" + // zgh-tfng-ma
- "CHS" + // zh
- "CHS" + // zh-chs
- "CHT" + // zh-cht
- "CHS" + // zh-cn
- "CHS" + // zh-cn_phoneb
- "CHS" + // zh-cn_stroke
- "CHS" + // zh-hans
- "ZZZ" + // zh-hans-hk
- "ZZZ" + // zh-hans-mo
- "ZHH" + // zh-hant
- "ZHH" + // zh-hk
- "ZHH" + // zh-hk_radstr
- "ZHM" + // zh-mo
- "ZHM" + // zh-mo_radstr
- "ZHM" + // zh-mo_stroke
- "ZHI" + // zh-sg
- "ZHI" + // zh-sg_phoneb
- "ZHI" + // zh-sg_stroke
- "CHT" + // zh-tw
- "CHT" + // zh-tw_pronun
- "CHT" + // zh-tw_radstr
- "ZUL" + // zu
- "ZUL"; // zu-za
-
- // s_localeNamesIndices contains the start index of every culture name in the string
- // s_localeNames. We infer the length of each string by looking at the start index
- // of the next string.
- private static readonly int[] s_localeNamesIndices = new int[]
- {
- // c_localeNames index, // index to this array - culture name
- 0 , // 0 - aa
- 2 , // 1 - aa-dj
- 7 , // 2 - aa-er
- 12 , // 3 - aa-et
- 17 , // 4 - af
- 19 , // 5 - af-na
- 24 , // 6 - af-za
- 29 , // 7 - agq
- 32 , // 8 - agq-cm
- 38 , // 9 - ak
- 40 , // 10 - ak-gh
- 45 , // 11 - am
- 47 , // 12 - am-et
- 52 , // 13 - ar
- 54 , // 14 - ar-001
- 60 , // 15 - ar-ae
- 65 , // 16 - ar-bh
- 70 , // 17 - ar-dj
- 75 , // 18 - ar-dz
- 80 , // 19 - ar-eg
- 85 , // 20 - ar-er
- 90 , // 21 - ar-il
- 95 , // 22 - ar-iq
- 100 , // 23 - ar-jo
- 105 , // 24 - ar-km
- 110 , // 25 - ar-kw
- 115 , // 26 - ar-lb
- 120 , // 27 - ar-ly
- 125 , // 28 - ar-ma
- 130 , // 29 - ar-mr
- 135 , // 30 - ar-om
- 140 , // 31 - ar-ps
- 145 , // 32 - ar-qa
- 150 , // 33 - ar-sa
- 155 , // 34 - ar-sd
- 160 , // 35 - ar-so
- 165 , // 36 - ar-ss
- 170 , // 37 - ar-sy
- 175 , // 38 - ar-td
- 180 , // 39 - ar-tn
- 185 , // 40 - ar-ye
- 190 , // 41 - arn
- 193 , // 42 - arn-cl
- 199 , // 43 - as
- 201 , // 44 - as-in
- 206 , // 45 - asa
- 209 , // 46 - asa-tz
- 215 , // 47 - ast
- 218 , // 48 - ast-es
- 224 , // 49 - az
- 226 , // 50 - az-cyrl
- 233 , // 51 - az-cyrl-az
- 243 , // 52 - az-latn
- 250 , // 53 - az-latn-az
- 260 , // 54 - ba
- 262 , // 55 - ba-ru
- 267 , // 56 - bas
- 270 , // 57 - bas-cm
- 276 , // 58 - be
- 278 , // 59 - be-by
- 283 , // 60 - bem
- 286 , // 61 - bem-zm
- 292 , // 62 - bez
- 295 , // 63 - bez-tz
- 301 , // 64 - bg
- 303 , // 65 - bg-bg
- 308 , // 66 - bin
- 311 , // 67 - bin-ng
- 317 , // 68 - bm
- 319 , // 69 - bm-latn
- 326 , // 70 - bm-latn-ml
- 336 , // 71 - bn
- 338 , // 72 - bn-bd
- 343 , // 73 - bn-in
- 348 , // 74 - bo
- 350 , // 75 - bo-cn
- 355 , // 76 - bo-in
- 360 , // 77 - br
- 362 , // 78 - br-fr
- 367 , // 79 - brx
- 370 , // 80 - brx-in
- 376 , // 81 - bs
- 378 , // 82 - bs-cyrl
- 385 , // 83 - bs-cyrl-ba
- 395 , // 84 - bs-latn
- 402 , // 85 - bs-latn-ba
- 412 , // 86 - byn
- 415 , // 87 - byn-er
- 421 , // 88 - ca
- 423 , // 89 - ca-ad
- 428 , // 90 - ca-es
- 433 , // 91 - ca-es-valencia
- 447 , // 92 - ca-fr
- 452 , // 93 - ca-it
- 457 , // 94 - ce
- 459 , // 95 - ce-ru
- 464 , // 96 - cgg
- 467 , // 97 - cgg-ug
- 473 , // 98 - chr
- 476 , // 99 - chr-cher
- 484 , // 100 - chr-cher-us
- 495 , // 101 - co
- 497 , // 102 - co-fr
- 502 , // 103 - cs
- 504 , // 104 - cs-cz
- 509 , // 105 - cu
- 511 , // 106 - cu-ru
- 516 , // 107 - cy
- 518 , // 108 - cy-gb
- 523 , // 109 - da
- 525 , // 110 - da-dk
- 530 , // 111 - da-gl
- 535 , // 112 - dav
- 538 , // 113 - dav-ke
- 544 , // 114 - de
- 546 , // 115 - de-at
- 551 , // 116 - de-be
- 556 , // 117 - de-ch
- 561 , // 118 - de-de
- 566 , // 119 - de-de_phoneb
- 578 , // 120 - de-it
- 583 , // 121 - de-li
- 588 , // 122 - de-lu
- 593 , // 123 - dje
- 596 , // 124 - dje-ne
- 602 , // 125 - dsb
- 605 , // 126 - dsb-de
- 611 , // 127 - dua
- 614 , // 128 - dua-cm
- 620 , // 129 - dv
- 622 , // 130 - dv-mv
- 627 , // 131 - dyo
- 630 , // 132 - dyo-sn
- 636 , // 133 - dz
- 638 , // 134 - dz-bt
- 643 , // 135 - ebu
- 646 , // 136 - ebu-ke
- 652 , // 137 - ee
- 654 , // 138 - ee-gh
- 659 , // 139 - ee-tg
- 664 , // 140 - el
- 666 , // 141 - el-cy
- 671 , // 142 - el-gr
- 676 , // 143 - en
- 678 , // 144 - en-001
- 684 , // 145 - en-029
- 690 , // 146 - en-150
- 696 , // 147 - en-ag
- 701 , // 148 - en-ai
- 706 , // 149 - en-as
- 711 , // 150 - en-at
- 716 , // 151 - en-au
- 721 , // 152 - en-bb
- 726 , // 153 - en-be
- 731 , // 154 - en-bi
- 736 , // 155 - en-bm
- 741 , // 156 - en-bs
- 746 , // 157 - en-bw
- 751 , // 158 - en-bz
- 756 , // 159 - en-ca
- 761 , // 160 - en-cc
- 766 , // 161 - en-ch
- 771 , // 162 - en-ck
- 776 , // 163 - en-cm
- 781 , // 164 - en-cx
- 786 , // 165 - en-cy
- 791 , // 166 - en-de
- 796 , // 167 - en-dk
- 801 , // 168 - en-dm
- 806 , // 169 - en-er
- 811 , // 170 - en-fi
- 816 , // 171 - en-fj
- 821 , // 172 - en-fk
- 826 , // 173 - en-fm
- 831 , // 174 - en-gb
- 836 , // 175 - en-gd
- 841 , // 176 - en-gg
- 846 , // 177 - en-gh
- 851 , // 178 - en-gi
- 856 , // 179 - en-gm
- 861 , // 180 - en-gu
- 866 , // 181 - en-gy
- 871 , // 182 - en-hk
- 876 , // 183 - en-id
- 881 , // 184 - en-ie
- 886 , // 185 - en-il
- 891 , // 186 - en-im
- 896 , // 187 - en-in
- 901 , // 188 - en-io
- 906 , // 189 - en-je
- 911 , // 190 - en-jm
- 916 , // 191 - en-ke
- 921 , // 192 - en-ki
- 926 , // 193 - en-kn
- 931 , // 194 - en-ky
- 936 , // 195 - en-lc
- 941 , // 196 - en-lr
- 946 , // 197 - en-ls
- 951 , // 198 - en-mg
- 956 , // 199 - en-mh
- 961 , // 200 - en-mo
- 966 , // 201 - en-mp
- 971 , // 202 - en-ms
- 976 , // 203 - en-mt
- 981 , // 204 - en-mu
- 986 , // 205 - en-mw
- 991 , // 206 - en-my
- 996 , // 207 - en-na
- 1001, // 208 - en-nf
- 1006, // 209 - en-ng
- 1011, // 210 - en-nl
- 1016, // 211 - en-nr
- 1021, // 212 - en-nu
- 1026, // 213 - en-nz
- 1031, // 214 - en-pg
- 1036, // 215 - en-ph
- 1041, // 216 - en-pk
- 1046, // 217 - en-pn
- 1051, // 218 - en-pr
- 1056, // 219 - en-pw
- 1061, // 220 - en-rw
- 1066, // 221 - en-sb
- 1071, // 222 - en-sc
- 1076, // 223 - en-sd
- 1081, // 224 - en-se
- 1086, // 225 - en-sg
- 1091, // 226 - en-sh
- 1096, // 227 - en-si
- 1101, // 228 - en-sl
- 1106, // 229 - en-ss
- 1111, // 230 - en-sx
- 1116, // 231 - en-sz
- 1121, // 232 - en-tc
- 1126, // 233 - en-tk
- 1131, // 234 - en-to
- 1136, // 235 - en-tt
- 1141, // 236 - en-tv
- 1146, // 237 - en-tz
- 1151, // 238 - en-ug
- 1156, // 239 - en-um
- 1161, // 240 - en-us
- 1166, // 241 - en-vc
- 1171, // 242 - en-vg
- 1176, // 243 - en-vi
- 1181, // 244 - en-vu
- 1186, // 245 - en-ws
- 1191, // 246 - en-za
- 1196, // 247 - en-zm
- 1201, // 248 - en-zw
- 1206, // 249 - eo
- 1208, // 250 - eo-001
- 1214, // 251 - es
- 1216, // 252 - es-419
- 1222, // 253 - es-ar
- 1227, // 254 - es-bo
- 1232, // 255 - es-br
- 1237, // 256 - es-cl
- 1242, // 257 - es-co
- 1247, // 258 - es-cr
- 1252, // 259 - es-cu
- 1257, // 260 - es-do
- 1262, // 261 - es-ec
- 1267, // 262 - es-es
- 1272, // 263 - es-es_tradnl
- 1284, // 264 - es-gq
- 1289, // 265 - es-gt
- 1294, // 266 - es-hn
- 1299, // 267 - es-mx
- 1304, // 268 - es-ni
- 1309, // 269 - es-pa
- 1314, // 270 - es-pe
- 1319, // 271 - es-ph
- 1324, // 272 - es-pr
- 1329, // 273 - es-py
- 1334, // 274 - es-sv
- 1339, // 275 - es-us
- 1344, // 276 - es-uy
- 1349, // 277 - es-ve
- 1354, // 278 - et
- 1356, // 279 - et-ee
- 1361, // 280 - eu
- 1363, // 281 - eu-es
- 1368, // 282 - ewo
- 1371, // 283 - ewo-cm
- 1377, // 284 - fa
- 1379, // 285 - fa-ir
- 1384, // 286 - ff
- 1386, // 287 - ff-cm
- 1391, // 288 - ff-gn
- 1396, // 289 - ff-latn
- 1403, // 290 - ff-latn-sn
- 1413, // 291 - ff-mr
- 1418, // 292 - ff-ng
- 1423, // 293 - fi
- 1425, // 294 - fi-fi
- 1430, // 295 - fil
- 1433, // 296 - fil-ph
- 1439, // 297 - fo
- 1441, // 298 - fo-dk
- 1446, // 299 - fo-fo
- 1451, // 300 - fr
- 1453, // 301 - fr-029
- 1459, // 302 - fr-be
- 1464, // 303 - fr-bf
- 1469, // 304 - fr-bi
- 1474, // 305 - fr-bj
- 1479, // 306 - fr-bl
- 1484, // 307 - fr-ca
- 1489, // 308 - fr-cd
- 1494, // 309 - fr-cf
- 1499, // 310 - fr-cg
- 1504, // 311 - fr-ch
- 1509, // 312 - fr-ci
- 1514, // 313 - fr-cm
- 1519, // 314 - fr-dj
- 1524, // 315 - fr-dz
- 1529, // 316 - fr-fr
- 1534, // 317 - fr-ga
- 1539, // 318 - fr-gf
- 1544, // 319 - fr-gn
- 1549, // 320 - fr-gp
- 1554, // 321 - fr-gq
- 1559, // 322 - fr-ht
- 1564, // 323 - fr-km
- 1569, // 324 - fr-lu
- 1574, // 325 - fr-ma
- 1579, // 326 - fr-mc
- 1584, // 327 - fr-mf
- 1589, // 328 - fr-mg
- 1594, // 329 - fr-ml
- 1599, // 330 - fr-mq
- 1604, // 331 - fr-mr
- 1609, // 332 - fr-mu
- 1614, // 333 - fr-nc
- 1619, // 334 - fr-ne
- 1624, // 335 - fr-pf
- 1629, // 336 - fr-pm
- 1634, // 337 - fr-re
- 1639, // 338 - fr-rw
- 1644, // 339 - fr-sc
- 1649, // 340 - fr-sn
- 1654, // 341 - fr-sy
- 1659, // 342 - fr-td
- 1664, // 343 - fr-tg
- 1669, // 344 - fr-tn
- 1674, // 345 - fr-vu
- 1679, // 346 - fr-wf
- 1684, // 347 - fr-yt
- 1689, // 348 - fur
- 1692, // 349 - fur-it
- 1698, // 350 - fy
- 1700, // 351 - fy-nl
- 1705, // 352 - ga
- 1707, // 353 - ga-ie
- 1712, // 354 - gd
- 1714, // 355 - gd-gb
- 1719, // 356 - gl
- 1721, // 357 - gl-es
- 1726, // 358 - gn
- 1728, // 359 - gn-py
- 1733, // 360 - gsw
- 1736, // 361 - gsw-ch
- 1742, // 362 - gsw-fr
- 1748, // 363 - gsw-li
- 1754, // 364 - gu
- 1756, // 365 - gu-in
- 1761, // 366 - guz
- 1764, // 367 - guz-ke
- 1770, // 368 - gv
- 1772, // 369 - gv-im
- 1777, // 370 - ha
- 1779, // 371 - ha-latn
- 1786, // 372 - ha-latn-gh
- 1796, // 373 - ha-latn-ne
- 1806, // 374 - ha-latn-ng
- 1816, // 375 - haw
- 1819, // 376 - haw-us
- 1825, // 377 - he
- 1827, // 378 - he-il
- 1832, // 379 - hi
- 1834, // 380 - hi-in
- 1839, // 381 - hr
- 1841, // 382 - hr-ba
- 1846, // 383 - hr-hr
- 1851, // 384 - hsb
- 1854, // 385 - hsb-de
- 1860, // 386 - hu
- 1862, // 387 - hu-hu
- 1867, // 388 - hu-hu_technl
- 1879, // 389 - hy
- 1881, // 390 - hy-am
- 1886, // 391 - ia
- 1888, // 392 - ia-001
- 1894, // 393 - ia-fr
- 1899, // 394 - ibb
- 1902, // 395 - ibb-ng
- 1908, // 396 - id
- 1910, // 397 - id-id
- 1915, // 398 - ig
- 1917, // 399 - ig-ng
- 1922, // 400 - ii
- 1924, // 401 - ii-cn
- 1929, // 402 - is
- 1931, // 403 - is-is
- 1936, // 404 - it
- 1938, // 405 - it-ch
- 1943, // 406 - it-it
- 1948, // 407 - it-sm
- 1953, // 408 - iu
- 1955, // 409 - iu-cans
- 1962, // 410 - iu-cans-ca
- 1972, // 411 - iu-latn
- 1979, // 412 - iu-latn-ca
- 1989, // 413 - ja
- 1991, // 414 - ja-jp
- 1996, // 415 - ja-jp_radstr
- 2008, // 416 - jgo
- 2011, // 417 - jgo-cm
- 2017, // 418 - jmc
- 2020, // 419 - jmc-tz
- 2026, // 420 - jv
- 2028, // 421 - jv-java
- 2035, // 422 - jv-java-id
- 2045, // 423 - jv-latn
- 2052, // 424 - jv-latn-id
- 2062, // 425 - ka
- 2064, // 426 - ka-ge
- 2069, // 427 - ka-ge_modern
- 2081, // 428 - kab
- 2084, // 429 - kab-dz
- 2090, // 430 - kam
- 2093, // 431 - kam-ke
- 2099, // 432 - kde
- 2102, // 433 - kde-tz
- 2108, // 434 - kea
- 2111, // 435 - kea-cv
- 2117, // 436 - khq
- 2120, // 437 - khq-ml
- 2126, // 438 - ki
- 2128, // 439 - ki-ke
- 2133, // 440 - kk
- 2135, // 441 - kk-kz
- 2140, // 442 - kkj
- 2143, // 443 - kkj-cm
- 2149, // 444 - kl
- 2151, // 445 - kl-gl
- 2156, // 446 - kln
- 2159, // 447 - kln-ke
- 2165, // 448 - km
- 2167, // 449 - km-kh
- 2172, // 450 - kn
- 2174, // 451 - kn-in
- 2179, // 452 - ko
- 2181, // 453 - ko-kp
- 2186, // 454 - ko-kr
- 2191, // 455 - kok
- 2194, // 456 - kok-in
- 2200, // 457 - kr
- 2202, // 458 - kr-ng
- 2207, // 459 - ks
- 2209, // 460 - ks-arab
- 2216, // 461 - ks-arab-in
- 2226, // 462 - ks-deva
- 2233, // 463 - ks-deva-in
- 2243, // 464 - ksb
- 2246, // 465 - ksb-tz
- 2252, // 466 - ksf
- 2255, // 467 - ksf-cm
- 2261, // 468 - ksh
- 2264, // 469 - ksh-de
- 2270, // 470 - ku
- 2272, // 471 - ku-arab
- 2279, // 472 - ku-arab-iq
- 2289, // 473 - ku-arab-ir
- 2299, // 474 - kw
- 2301, // 475 - kw-gb
- 2306, // 476 - ky
- 2308, // 477 - ky-kg
- 2313, // 478 - la
- 2315, // 479 - la-001
- 2321, // 480 - lag
- 2324, // 481 - lag-tz
- 2330, // 482 - lb
- 2332, // 483 - lb-lu
- 2337, // 484 - lg
- 2339, // 485 - lg-ug
- 2344, // 486 - lkt
- 2347, // 487 - lkt-us
- 2353, // 488 - ln
- 2355, // 489 - ln-ao
- 2360, // 490 - ln-cd
- 2365, // 491 - ln-cf
- 2370, // 492 - ln-cg
- 2375, // 493 - lo
- 2377, // 494 - lo-la
- 2382, // 495 - lrc
- 2385, // 496 - lrc-iq
- 2391, // 497 - lrc-ir
- 2397, // 498 - lt
- 2399, // 499 - lt-lt
- 2404, // 500 - lu
- 2406, // 501 - lu-cd
- 2411, // 502 - luo
- 2414, // 503 - luo-ke
- 2420, // 504 - luy
- 2423, // 505 - luy-ke
- 2429, // 506 - lv
- 2431, // 507 - lv-lv
- 2436, // 508 - mas
- 2439, // 509 - mas-ke
- 2445, // 510 - mas-tz
- 2451, // 511 - mer
- 2454, // 512 - mer-ke
- 2460, // 513 - mfe
- 2463, // 514 - mfe-mu
- 2469, // 515 - mg
- 2471, // 516 - mg-mg
- 2476, // 517 - mgh
- 2479, // 518 - mgh-mz
- 2485, // 519 - mgo
- 2488, // 520 - mgo-cm
- 2494, // 521 - mi
- 2496, // 522 - mi-nz
- 2501, // 523 - mk
- 2503, // 524 - mk-mk
- 2508, // 525 - ml
- 2510, // 526 - ml-in
- 2515, // 527 - mn
- 2517, // 528 - mn-cyrl
- 2524, // 529 - mn-mn
- 2529, // 530 - mn-mong
- 2536, // 531 - mn-mong-cn
- 2546, // 532 - mn-mong-mn
- 2556, // 533 - mni
- 2559, // 534 - mni-in
- 2565, // 535 - moh
- 2568, // 536 - moh-ca
- 2574, // 537 - mr
- 2576, // 538 - mr-in
- 2581, // 539 - ms
- 2583, // 540 - ms-bn
- 2588, // 541 - ms-my
- 2593, // 542 - ms-sg
- 2598, // 543 - mt
- 2600, // 544 - mt-mt
- 2605, // 545 - mua
- 2608, // 546 - mua-cm
- 2614, // 547 - my
- 2616, // 548 - my-mm
- 2621, // 549 - mzn
- 2624, // 550 - mzn-ir
- 2630, // 551 - naq
- 2633, // 552 - naq-na
- 2639, // 553 - nb
- 2641, // 554 - nb-no
- 2646, // 555 - nb-sj
- 2651, // 556 - nd
- 2653, // 557 - nd-zw
- 2658, // 558 - nds
- 2661, // 559 - nds-de
- 2667, // 560 - nds-nl
- 2673, // 561 - ne
- 2675, // 562 - ne-in
- 2680, // 563 - ne-np
- 2685, // 564 - nl
- 2687, // 565 - nl-aw
- 2692, // 566 - nl-be
- 2697, // 567 - nl-bq
- 2702, // 568 - nl-cw
- 2707, // 569 - nl-nl
- 2712, // 570 - nl-sr
- 2717, // 571 - nl-sx
- 2722, // 572 - nmg
- 2725, // 573 - nmg-cm
- 2731, // 574 - nn
- 2733, // 575 - nn-no
- 2738, // 576 - nnh
- 2741, // 577 - nnh-cm
- 2747, // 578 - no
- 2749, // 579 - nqo
- 2752, // 580 - nqo-gn
- 2758, // 581 - nr
- 2760, // 582 - nr-za
- 2765, // 583 - nso
- 2768, // 584 - nso-za
- 2774, // 585 - nus
- 2777, // 586 - nus-ss
- 2783, // 587 - nyn
- 2786, // 588 - nyn-ug
- 2792, // 589 - oc
- 2794, // 590 - oc-fr
- 2799, // 591 - om
- 2801, // 592 - om-et
- 2806, // 593 - om-ke
- 2811, // 594 - or
- 2813, // 595 - or-in
- 2818, // 596 - os
- 2820, // 597 - os-ge
- 2825, // 598 - os-ru
- 2830, // 599 - pa
- 2832, // 600 - pa-arab
- 2839, // 601 - pa-arab-pk
- 2849, // 602 - pa-in
- 2854, // 603 - pap
- 2857, // 604 - pap-029
- 2864, // 605 - pl
- 2866, // 606 - pl-pl
- 2871, // 607 - prg
- 2874, // 608 - prg-001
- 2881, // 609 - prs
- 2884, // 610 - prs-af
- 2890, // 611 - ps
- 2892, // 612 - ps-af
- 2897, // 613 - pt
- 2899, // 614 - pt-ao
- 2904, // 615 - pt-br
- 2909, // 616 - pt-ch
- 2914, // 617 - pt-cv
- 2919, // 618 - pt-gq
- 2924, // 619 - pt-gw
- 2929, // 620 - pt-lu
- 2934, // 621 - pt-mo
- 2939, // 622 - pt-mz
- 2944, // 623 - pt-pt
- 2949, // 624 - pt-st
- 2954, // 625 - pt-tl
- 2959, // 626 - qps-latn-x-sh
- 2972, // 627 - qps-ploc
- 2980, // 628 - qps-ploca
- 2989, // 629 - qps-plocm
- 2998, // 630 - quc
- 3001, // 631 - quc-latn
- 3009, // 632 - quc-latn-gt
- 3020, // 633 - quz
- 3023, // 634 - quz-bo
- 3029, // 635 - quz-ec
- 3035, // 636 - quz-pe
- 3041, // 637 - rm
- 3043, // 638 - rm-ch
- 3048, // 639 - rn
- 3050, // 640 - rn-bi
- 3055, // 641 - ro
- 3057, // 642 - ro-md
- 3062, // 643 - ro-ro
- 3067, // 644 - rof
- 3070, // 645 - rof-tz
- 3076, // 646 - ru
- 3078, // 647 - ru-by
- 3083, // 648 - ru-kg
- 3088, // 649 - ru-kz
- 3093, // 650 - ru-md
- 3098, // 651 - ru-ru
- 3103, // 652 - ru-ua
- 3108, // 653 - rw
- 3110, // 654 - rw-rw
- 3115, // 655 - rwk
- 3118, // 656 - rwk-tz
- 3124, // 657 - sa
- 3126, // 658 - sa-in
- 3131, // 659 - sah
- 3134, // 660 - sah-ru
- 3140, // 661 - saq
- 3143, // 662 - saq-ke
- 3149, // 663 - sbp
- 3152, // 664 - sbp-tz
- 3158, // 665 - sd
- 3160, // 666 - sd-arab
- 3167, // 667 - sd-arab-pk
- 3177, // 668 - sd-deva
- 3184, // 669 - sd-deva-in
- 3194, // 670 - se
- 3196, // 671 - se-fi
- 3201, // 672 - se-no
- 3206, // 673 - se-se
- 3211, // 674 - seh
- 3214, // 675 - seh-mz
- 3220, // 676 - ses
- 3223, // 677 - ses-ml
- 3229, // 678 - sg
- 3231, // 679 - sg-cf
- 3236, // 680 - shi
- 3239, // 681 - shi-latn
- 3247, // 682 - shi-latn-ma
- 3258, // 683 - shi-tfng
- 3266, // 684 - shi-tfng-ma
- 3277, // 685 - si
- 3279, // 686 - si-lk
- 3284, // 687 - sk
- 3286, // 688 - sk-sk
- 3291, // 689 - sl
- 3293, // 690 - sl-si
- 3298, // 691 - sma
- 3301, // 692 - sma-no
- 3307, // 693 - sma-se
- 3313, // 694 - smj
- 3316, // 695 - smj-no
- 3322, // 696 - smj-se
- 3328, // 697 - smn
- 3331, // 698 - smn-fi
- 3337, // 699 - sms
- 3340, // 700 - sms-fi
- 3346, // 701 - sn
- 3348, // 702 - sn-latn
- 3355, // 703 - sn-latn-zw
- 3365, // 704 - so
- 3367, // 705 - so-dj
- 3372, // 706 - so-et
- 3377, // 707 - so-ke
- 3382, // 708 - so-so
- 3387, // 709 - sq
- 3389, // 710 - sq-al
- 3394, // 711 - sq-mk
- 3399, // 712 - sq-xk
- 3404, // 713 - sr
- 3406, // 714 - sr-cyrl
- 3413, // 715 - sr-cyrl-ba
- 3423, // 716 - sr-cyrl-cs
- 3433, // 717 - sr-cyrl-me
- 3443, // 718 - sr-cyrl-rs
- 3453, // 719 - sr-cyrl-xk
- 3463, // 720 - sr-latn
- 3470, // 721 - sr-latn-ba
- 3480, // 722 - sr-latn-cs
- 3490, // 723 - sr-latn-me
- 3500, // 724 - sr-latn-rs
- 3510, // 725 - sr-latn-xk
- 3520, // 726 - ss
- 3522, // 727 - ss-sz
- 3527, // 728 - ss-za
- 3532, // 729 - ssy
- 3535, // 730 - ssy-er
- 3541, // 731 - st
- 3543, // 732 - st-ls
- 3548, // 733 - st-za
- 3553, // 734 - sv
- 3555, // 735 - sv-ax
- 3560, // 736 - sv-fi
- 3565, // 737 - sv-se
- 3570, // 738 - sw
- 3572, // 739 - sw-cd
- 3577, // 740 - sw-ke
- 3582, // 741 - sw-tz
- 3587, // 742 - sw-ug
- 3592, // 743 - swc
- 3595, // 744 - swc-cd
- 3601, // 745 - syr
- 3604, // 746 - syr-sy
- 3610, // 747 - ta
- 3612, // 748 - ta-in
- 3617, // 749 - ta-lk
- 3622, // 750 - ta-my
- 3627, // 751 - ta-sg
- 3632, // 752 - te
- 3634, // 753 - te-in
- 3639, // 754 - teo
- 3642, // 755 - teo-ke
- 3648, // 756 - teo-ug
- 3654, // 757 - tg
- 3656, // 758 - tg-cyrl
- 3663, // 759 - tg-cyrl-tj
- 3673, // 760 - th
- 3675, // 761 - th-th
- 3680, // 762 - ti
- 3682, // 763 - ti-er
- 3687, // 764 - ti-et
- 3692, // 765 - tig
- 3695, // 766 - tig-er
- 3701, // 767 - tk
- 3703, // 768 - tk-tm
- 3708, // 769 - tn
- 3710, // 770 - tn-bw
- 3715, // 771 - tn-za
- 3720, // 772 - to
- 3722, // 773 - to-to
- 3727, // 774 - tr
- 3729, // 775 - tr-cy
- 3734, // 776 - tr-tr
- 3739, // 777 - ts
- 3741, // 778 - ts-za
- 3746, // 779 - tt
- 3748, // 780 - tt-ru
- 3753, // 781 - twq
- 3756, // 782 - twq-ne
- 3762, // 783 - tzm
- 3765, // 784 - tzm-arab
- 3773, // 785 - tzm-arab-ma
- 3784, // 786 - tzm-latn
- 3792, // 787 - tzm-latn-dz
- 3803, // 788 - tzm-latn-ma
- 3814, // 789 - tzm-tfng
- 3822, // 790 - tzm-tfng-ma
- 3833, // 791 - ug
- 3835, // 792 - ug-cn
- 3840, // 793 - uk
- 3842, // 794 - uk-ua
- 3847, // 795 - ur
- 3849, // 796 - ur-in
- 3854, // 797 - ur-pk
- 3859, // 798 - uz
- 3861, // 799 - uz-arab
- 3868, // 800 - uz-arab-af
- 3878, // 801 - uz-cyrl
- 3885, // 802 - uz-cyrl-uz
- 3895, // 803 - uz-latn
- 3902, // 804 - uz-latn-uz
- 3912, // 805 - vai
- 3915, // 806 - vai-latn
- 3923, // 807 - vai-latn-lr
- 3934, // 808 - vai-vaii
- 3942, // 809 - vai-vaii-lr
- 3953, // 810 - ve
- 3955, // 811 - ve-za
- 3960, // 812 - vi
- 3962, // 813 - vi-vn
- 3967, // 814 - vo
- 3969, // 815 - vo-001
- 3975, // 816 - vun
- 3978, // 817 - vun-tz
- 3984, // 818 - wae
- 3987, // 819 - wae-ch
- 3993, // 820 - wal
- 3996, // 821 - wal-et
- 4002, // 822 - wo
- 4004, // 823 - wo-sn
- 4009, // 824 - x-iv_mathan
- 4020, // 825 - xh
- 4022, // 826 - xh-za
- 4027, // 827 - xog
- 4030, // 828 - xog-ug
- 4036, // 829 - yav
- 4039, // 830 - yav-cm
- 4045, // 831 - yi
- 4047, // 832 - yi-001
- 4053, // 833 - yo
- 4055, // 834 - yo-bj
- 4060, // 835 - yo-ng
- 4065, // 836 - yue
- 4068, // 837 - yue-hk
- 4074, // 838 - zgh
- 4077, // 839 - zgh-tfng
- 4085, // 840 - zgh-tfng-ma
- 4096, // 841 - zh
- 4098, // 842 - zh-chs
- 4104, // 843 - zh-cht
- 4110, // 844 - zh-cn
- 4115, // 845 - zh-cn_phoneb
- 4127, // 846 - zh-cn_stroke
- 4139, // 847 - zh-hans
- 4146, // 848 - zh-hans-hk
- 4156, // 849 - zh-hans-mo
- 4166, // 850 - zh-hant
- 4173, // 851 - zh-hk
- 4178, // 852 - zh-hk_radstr
- 4190, // 853 - zh-mo
- 4195, // 854 - zh-mo_radstr
- 4207, // 855 - zh-mo_stroke
- 4219, // 856 - zh-sg
- 4224, // 857 - zh-sg_phoneb
- 4236, // 858 - zh-sg_stroke
- 4248, // 859 - zh-tw
- 4253, // 860 - zh-tw_pronun
- 4265, // 861 - zh-tw_radstr
- 4277, // 862 - zu
- 4279, // 863 - zu-za
- 4284
- };
-
- private const int NUMERIC_LOCALE_DATA_COUNT_PER_ROW = 9;
- // s_nameIndexToNumericData is mapping from index in s_localeNamesIndices to locale data.
- // each row in the table will have the following data:
- // Lcid, Ansi codepage, Oem codepage, MAC codepage, EBCDIC codepage, Geo Id, Digit Substitution, specific locale index, Console locale index
- private static readonly int[] s_nameIndexToNumericData = new int[]
- {
- // Lcid, Ansi CP, Oem CP, MAC CP, EBCDIC CP, Geo Id, digit substitution, Specific culture index, keyboard Id, Console locale index // index - locale name
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x49 , 1 , 3 , 240 , // 0 - aa
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x3e , 1 , 1 , 240 , // 1 - aa-dj
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x47 , 1 , 2 , 240 , // 2 - aa-er
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x49 , 1 , 3 , 240 , // 3 - aa-et
- 0x36 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd1 , 1 , 6 , 6 , // 4 - af
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xfe , 1 , 5 , 240 , // 5 - af-na
- 0x436 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd1 , 1 , 6 , 6 , // 6 - af-za
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 8 , 240 , // 7 - agq
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 8 , 240 , // 8 - agq-cm
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x59 , 1 , 10 , 240 , // 9 - ak
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x59 , 1 , 10 , 240 , // 10 - ak-gh
- 0x5e , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x49 , 1 , 12 , 143 , // 11 - am
- 0x45e , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x49 , 1 , 12 , 143 , // 12 - am-et
- 0x1 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xcd , 0 , 33 , 143 , // 13 - ar
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x989e, 0 , 14 , 240 , // 14 - ar-001
- 0x3801 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xe0 , 0 , 15 , 143 , // 15 - ar-ae
- 0x3c01 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x11 , 0 , 16 , 143 , // 16 - ar-bh
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x3e , 0 , 17 , 240 , // 17 - ar-dj
- 0x1401 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x4 , 1 , 18 , 300 , // 18 - ar-dz
- 0xc01 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x43 , 0 , 19 , 143 , // 19 - ar-eg
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x47 , 0 , 20 , 240 , // 20 - ar-er
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x75 , 0 , 21 , 240 , // 21 - ar-il
- 0x801 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x79 , 0 , 22 , 143 , // 22 - ar-iq
- 0x2c01 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x7e , 0 , 23 , 143 , // 23 - ar-jo
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x32 , 0 , 24 , 240 , // 24 - ar-km
- 0x3401 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x88 , 0 , 25 , 143 , // 25 - ar-kw
- 0x3001 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x8b , 0 , 26 , 143 , // 26 - ar-lb
- 0x1001 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x94 , 1 , 27 , 143 , // 27 - ar-ly
- 0x1801 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x9f , 1 , 28 , 300 , // 28 - ar-ma
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xa2 , 0 , 29 , 240 , // 29 - ar-mr
- 0x2001 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xa4 , 0 , 30 , 143 , // 30 - ar-om
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xb8 , 0 , 31 , 240 , // 31 - ar-ps
- 0x4001 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xc5 , 0 , 32 , 143 , // 32 - ar-qa
- 0x401 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xcd , 0 , 33 , 143 , // 33 - ar-sa
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xdb , 0 , 34 , 240 , // 34 - ar-sd
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xd8 , 0 , 35 , 240 , // 35 - ar-so
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x114 , 0 , 36 , 240 , // 36 - ar-ss
- 0x2801 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xde , 0 , 37 , 143 , // 37 - ar-sy
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x29 , 0 , 38 , 240 , // 38 - ar-td
- 0x1c01 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xea , 1 , 39 , 300 , // 39 - ar-tn
- 0x2401 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x105 , 0 , 40 , 143 , // 40 - ar-ye
- 0x7a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x2e , 1 , 42 , 42 , // 41 - arn
- 0x47a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x2e , 1 , 42 , 42 , // 42 - arn-cl
- 0x4d , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 44 , 143 , // 43 - as
- 0x44d , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 44 , 143 , // 44 - as-in
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 46 , 240 , // 45 - asa
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 46 , 240 , // 46 - asa-tz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd9 , 1 , 48 , 240 , // 47 - ast
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd9 , 1 , 48 , 240 , // 48 - ast-es
- 0x2c , 0x4e6 , 0x359 , 0x2761, 0x51a9, 0x5 , 1 , 53 , 53 , // 49 - az
- 0x742c , 0x4e3 , 0x362 , 0x2717, 0x5190, 0x5 , 1 , 51 , 51 , // 50 - az-cyrl
- 0x82c , 0x4e3 , 0x362 , 0x2717, 0x5190, 0x5 , 1 , 51 , 51 , // 51 - az-cyrl-az
- 0x782c , 0x4e6 , 0x359 , 0x2761, 0x51a9, 0x5 , 1 , 53 , 53 , // 52 - az-latn
- 0x42c , 0x4e6 , 0x359 , 0x2761, 0x51a9, 0x5 , 1 , 53 , 53 , // 53 - az-latn-az
- 0x6d , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xcb , 1 , 55 , 55 , // 54 - ba
- 0x46d , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xcb , 1 , 55 , 55 , // 55 - ba-ru
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 57 , 240 , // 56 - bas
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 57 , 240 , // 57 - bas-cm
- 0x23 , 0x4e3 , 0x362 , 0x2717, 0x1f4 , 0x1d , 1 , 59 , 59 , // 58 - be
- 0x423 , 0x4e3 , 0x362 , 0x2717, 0x1f4 , 0x1d , 1 , 59 , 59 , // 59 - be-by
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x107 , 1 , 61 , 240 , // 60 - bem
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x107 , 1 , 61 , 240 , // 61 - bem-zm
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 63 , 240 , // 62 - bez
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 63 , 240 , // 63 - bez-tz
- 0x2 , 0x4e3 , 0x362 , 0x2717, 0x5221, 0x23 , 1 , 65 , 65 , // 64 - bg
- 0x402 , 0x4e3 , 0x362 , 0x2717, 0x5221, 0x23 , 1 , 65 , 65 , // 65 - bg-bg
- 0x66 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xaf , 1 , 67 , 240 , // 66 - bin
- 0x466 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xaf , 1 , 67 , 240 , // 67 - bin-ng
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9d , 1 , 70 , 240 , // 68 - bm
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9d , 1 , 70 , 240 , // 69 - bm-latn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9d , 1 , 70 , 240 , // 70 - bm-latn-ml
- 0x45 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x17 , 1 , 72 , 143 , // 71 - bn
- 0x845 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x17 , 1 , 72 , 143 , // 72 - bn-bd
- 0x445 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 73 , 143 , // 73 - bn-in
- 0x51 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2d , 1 , 75 , 143 , // 74 - bo
- 0x451 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2d , 1 , 75 , 143 , // 75 - bo-cn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 76 , 240 , // 76 - bo-in
- 0x7e , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x54 , 1 , 78 , 78 , // 77 - br
- 0x47e , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x54 , 1 , 78 , 78 , // 78 - br-fr
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 80 , 240 , // 79 - brx
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 80 , 240 , // 80 - brx-in
- 0x781a , 0x4e2 , 0x354 , 0x2762, 0x366 , 0x19 , 1 , 85 , 85 , // 81 - bs
- 0x641a , 0x4e3 , 0x357 , 0x2762, 0x366 , 0x19 , 1 , 83 , 83 , // 82 - bs-cyrl
- 0x201a , 0x4e3 , 0x357 , 0x2762, 0x366 , 0x19 , 1 , 83 , 83 , // 83 - bs-cyrl-ba
- 0x681a , 0x4e2 , 0x354 , 0x2762, 0x366 , 0x19 , 1 , 85 , 85 , // 84 - bs-latn
- 0x141a , 0x4e2 , 0x354 , 0x2762, 0x366 , 0x19 , 1 , 85 , 85 , // 85 - bs-latn-ba
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x47 , 1 , 87 , 240 , // 86 - byn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x47 , 1 , 87 , 240 , // 87 - byn-er
- 0x3 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd9 , 1 , 90 , 90 , // 88 - ca
- 0x1000 , 0x4e4 , 0x352 , 0x2 , 0x1f4 , 0x8 , 1 , 89 , 240 , // 89 - ca-ad
- 0x403 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd9 , 1 , 90 , 90 , // 90 - ca-es
- 0x803 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd9 , 1 , 91 , 90 , // 91 - ca-es-valencia
- 0x1000 , 0x4e4 , 0x352 , 0x2 , 0x1f4 , 0x54 , 1 , 92 , 240 , // 92 - ca-fr
- 0x1000 , 0x4e4 , 0x352 , 0x2 , 0x1f4 , 0x76 , 1 , 93 , 240 , // 93 - ca-it
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xcb , 1 , 95 , 240 , // 94 - ce
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xcb , 1 , 95 , 240 , // 95 - ce-ru
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf0 , 1 , 97 , 240 , // 96 - cgg
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf0 , 1 , 97 , 240 , // 97 - cgg-ug
- 0x5c , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf4 , 1 , 100 , 240 , // 98 - chr
- 0x7c5c , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf4 , 1 , 100 , 240 , // 99 - chr-cher
- 0x45c , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf4 , 1 , 100 , 240 , // 100 - chr-cher-us
- 0x83 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x54 , 1 , 102 , 102 , // 101 - co
- 0x483 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x54 , 1 , 102 , 102 , // 102 - co-fr
- 0x5 , 0x4e2 , 0x354 , 0x272d, 0x1f4 , 0x4b , 1 , 104 , 104 , // 103 - cs
- 0x405 , 0x4e2 , 0x354 , 0x272d, 0x1f4 , 0x4b , 1 , 104 , 104 , // 104 - cs-cz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xcb , 1 , 106 , 240 , // 105 - cu
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xcb , 1 , 106 , 240 , // 106 - cu-ru
- 0x52 , 0x4e4 , 0x352 , 0x2710, 0x4f3d, 0xf2 , 1 , 108 , 108 , // 107 - cy
- 0x452 , 0x4e4 , 0x352 , 0x2710, 0x4f3d, 0xf2 , 1 , 108 , 108 , // 108 - cy-gb
- 0x6 , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0x3d , 1 , 110 , 110 , // 109 - da
- 0x406 , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0x3d , 1 , 110 , 110 , // 110 - da-dk
- 0x1000 , 0x4e4 , 0x352 , 0x2 , 0x1f4 , 0x5d , 1 , 111 , 240 , // 111 - da-gl
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 113 , 240 , // 112 - dav
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 113 , 240 , // 113 - dav-ke
- 0x7 , 0x4e4 , 0x352 , 0x2710, 0x4f31, 0x5e , 1 , 118 , 118 , // 114 - de
- 0xc07 , 0x4e4 , 0x352 , 0x2710, 0x4f31, 0xe , 1 , 115 , 115 , // 115 - de-at
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f31, 0x15 , 1 , 116 , 240 , // 116 - de-be
- 0x807 , 0x4e4 , 0x352 , 0x2710, 0x4f31, 0xdf , 1 , 117 , 117 , // 117 - de-ch
- 0x407 , 0x4e4 , 0x352 , 0x2710, 0x4f31, 0x5e , 1 , 118 , 118 , // 118 - de-de
- 0x10407, 0x4e4 , 0x352 , 0x2710, 0x4f31, 0x5e , 1 , 118 , 118 , // 119 - de-de_phoneb
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x76 , 1 , 120 , 240 , // 120 - de-it
- 0x1407 , 0x4e4 , 0x352 , 0x2710, 0x4f31, 0x91 , 1 , 121 , 121 , // 121 - de-li
- 0x1007 , 0x4e4 , 0x352 , 0x2710, 0x4f31, 0x93 , 1 , 122 , 122 , // 122 - de-lu
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xad , 1 , 124 , 240 , // 123 - dje
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xad , 1 , 124 , 240 , // 124 - dje-ne
- 0x7c2e , 0x4e4 , 0x352 , 0x2710, 0x366 , 0x5e , 1 , 126 , 126 , // 125 - dsb
- 0x82e , 0x4e4 , 0x352 , 0x2710, 0x366 , 0x5e , 1 , 126 , 126 , // 126 - dsb-de
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 128 , 240 , // 127 - dua
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 128 , 240 , // 128 - dua-cm
- 0x65 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xa5 , 1 , 130 , 143 , // 129 - dv
- 0x465 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xa5 , 1 , 130 , 143 , // 130 - dv-mv
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd2 , 1 , 132 , 240 , // 131 - dyo
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd2 , 1 , 132 , 240 , // 132 - dyo-sn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x22 , 2 , 134 , 240 , // 133 - dz
- 0xc51 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x22 , 2 , 134 , 240 , // 134 - dz-bt
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 136 , 240 , // 135 - ebu
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 136 , 240 , // 136 - ebu-ke
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x59 , 1 , 138 , 240 , // 137 - ee
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x59 , 1 , 138 , 240 , // 138 - ee-gh
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xe8 , 1 , 139 , 240 , // 139 - ee-tg
- 0x8 , 0x4e5 , 0x2e1 , 0x2716, 0x4f31, 0x62 , 1 , 142 , 142 , // 140 - el
- 0x1000 , 0x4e5 , 0x2e1 , 0x2716, 0x4f31, 0x3b , 1 , 141 , 240 , // 141 - el-cy
- 0x408 , 0x4e5 , 0x2e1 , 0x2716, 0x4f31, 0x62 , 1 , 142 , 142 , // 142 - el-gr
- 0x9 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xf4 , 1 , 240 , 240 , // 143 - en
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x989e, 1 , 144 , 240 , // 144 - en-001
- 0x2409 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x993248, 1 , 145 , 145 , // 145 - en-029
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x292d, 1 , 146 , 240 , // 146 - en-150
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x2 , 1 , 147 , 240 , // 147 - en-ag
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x12c , 1 , 148 , 240 , // 148 - en-ai
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xa , 1 , 149 , 240 , // 149 - en-as
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xe , 1 , 150 , 240 , // 150 - en-at
- 0xc09 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xc , 1 , 151 , 151 , // 151 - en-au
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x12 , 1 , 152 , 240 , // 152 - en-bb
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x15 , 1 , 153 , 240 , // 153 - en-be
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x26 , 1 , 154 , 240 , // 154 - en-bi
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x14 , 1 , 155 , 240 , // 155 - en-bm
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x16 , 1 , 156 , 240 , // 156 - en-bs
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x13 , 1 , 157 , 240 , // 157 - en-bw
- 0x2809 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x18 , 1 , 158 , 158 , // 158 - en-bz
- 0x1009 , 0x4e4 , 0x352 , 0x2710, 0x25 , 0x27 , 1 , 159 , 159 , // 159 - en-ca
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x137 , 1 , 160 , 240 , // 160 - en-cc
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xdf , 1 , 161 , 240 , // 161 - en-ch
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x138 , 1 , 162 , 240 , // 162 - en-ck
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x31 , 1 , 163 , 240 , // 163 - en-cm
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x135 , 1 , 164 , 240 , // 164 - en-cx
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x3b , 1 , 165 , 240 , // 165 - en-cy
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x5e , 1 , 166 , 240 , // 166 - en-de
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x3d , 1 , 167 , 240 , // 167 - en-dk
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x3f , 1 , 168 , 240 , // 168 - en-dm
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x47 , 1 , 169 , 240 , // 169 - en-er
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x4d , 1 , 170 , 240 , // 170 - en-fi
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x4e , 1 , 171 , 240 , // 171 - en-fj
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x13b , 1 , 172 , 240 , // 172 - en-fk
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x50 , 1 , 173 , 240 , // 173 - en-fm
- 0x809 , 0x4e4 , 0x352 , 0x2710, 0x4f3d, 0xf2 , 1 , 174 , 174 , // 174 - en-gb
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x5b , 1 , 175 , 240 , // 175 - en-gd
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x144 , 1 , 176 , 240 , // 176 - en-gg
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x59 , 1 , 177 , 240 , // 177 - en-gh
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x5a , 1 , 178 , 240 , // 178 - en-gi
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x56 , 1 , 179 , 240 , // 179 - en-gm
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x142 , 1 , 180 , 240 , // 180 - en-gu
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x65 , 1 , 181 , 240 , // 181 - en-gy
- 0x3c09 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x68 , 1 , 182 , 240 , // 182 - en-hk
- 0x3809 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x6f , 1 , 183 , 240 , // 183 - en-id
- 0x1809 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x44 , 1 , 184 , 184 , // 184 - en-ie
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x75 , 1 , 185 , 240 , // 185 - en-il
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x3b16, 1 , 186 , 240 , // 186 - en-im
- 0x4009 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0x71 , 1 , 187 , 187 , // 187 - en-in
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x72 , 1 , 188 , 240 , // 188 - en-io
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x148 , 1 , 189 , 240 , // 189 - en-je
- 0x2009 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x7c , 1 , 190 , 190 , // 190 - en-jm
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x81 , 1 , 191 , 240 , // 191 - en-ke
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x85 , 1 , 192 , 240 , // 192 - en-ki
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xcf , 1 , 193 , 240 , // 193 - en-kn
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x133 , 1 , 194 , 240 , // 194 - en-ky
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xda , 1 , 195 , 240 , // 195 - en-lc
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x8e , 1 , 196 , 240 , // 196 - en-lr
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x92 , 1 , 197 , 240 , // 197 - en-ls
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x95 , 1 , 198 , 240 , // 198 - en-mg
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xc7 , 1 , 199 , 240 , // 199 - en-mh
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x97 , 1 , 200 , 240 , // 200 - en-mo
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x151 , 1 , 201 , 240 , // 201 - en-mp
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x14c , 1 , 202 , 240 , // 202 - en-ms
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xa3 , 1 , 203 , 240 , // 203 - en-mt
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xa0 , 1 , 204 , 240 , // 204 - en-mu
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x9c , 1 , 205 , 240 , // 205 - en-mw
- 0x4409 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xa7 , 1 , 206 , 206 , // 206 - en-my
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xfe , 1 , 207 , 240 , // 207 - en-na
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x150 , 1 , 208 , 240 , // 208 - en-nf
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xaf , 1 , 209 , 240 , // 209 - en-ng
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xb0 , 1 , 210 , 240 , // 210 - en-nl
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xb4 , 1 , 211 , 240 , // 211 - en-nr
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x14f , 1 , 212 , 240 , // 212 - en-nu
- 0x1409 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xb7 , 1 , 213 , 213 , // 213 - en-nz
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xc2 , 1 , 214 , 240 , // 214 - en-pg
- 0x3409 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0xc9 , 1 , 215 , 215 , // 215 - en-ph
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xbe , 1 , 216 , 240 , // 216 - en-pk
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x153 , 1 , 217 , 240 , // 217 - en-pn
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xca , 1 , 218 , 240 , // 218 - en-pr
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xc3 , 1 , 219 , 240 , // 219 - en-pw
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xcc , 1 , 220 , 240 , // 220 - en-rw
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x1e , 1 , 221 , 240 , // 221 - en-sb
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd0 , 1 , 222 , 240 , // 222 - en-sc
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xdb , 1 , 223 , 240 , // 223 - en-sd
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xdd , 1 , 224 , 240 , // 224 - en-se
- 0x4809 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xd7 , 1 , 225 , 225 , // 225 - en-sg
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x157 , 1 , 226 , 240 , // 226 - en-sh
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd4 , 1 , 227 , 240 , // 227 - en-si
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd5 , 1 , 228 , 240 , // 228 - en-sl
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x114 , 1 , 229 , 240 , // 229 - en-ss
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x78f7, 1 , 230 , 240 , // 230 - en-sx
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x104 , 1 , 231 , 240 , // 231 - en-sz
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x15d , 1 , 232 , 240 , // 232 - en-tc
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x15b , 1 , 233 , 240 , // 233 - en-tk
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xe7 , 1 , 234 , 240 , // 234 - en-to
- 0x2c09 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xe1 , 1 , 235 , 235 , // 235 - en-tt
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xec , 1 , 236 , 240 , // 236 - en-tv
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xef , 1 , 237 , 240 , // 237 - en-tz
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xf0 , 1 , 238 , 240 , // 238 - en-ug
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x9a55d40, 1 , 239 , 240 , // 239 - en-um
- 0x409 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xf4 , 1 , 240 , 240 , // 240 - en-us
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xf8 , 1 , 241 , 240 , // 241 - en-vc
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x15f , 1 , 242 , 240 , // 242 - en-vg
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xfc , 1 , 243 , 240 , // 243 - en-vi
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xae , 1 , 244 , 240 , // 244 - en-vu
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x103 , 1 , 245 , 240 , // 245 - en-ws
- 0x1c09 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0xd1 , 1 , 246 , 246 , // 246 - en-za
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x107 , 1 , 247 , 240 , // 247 - en-zm
- 0x3009 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0x108 , 1 , 248 , 248 , // 248 - en-zw
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x989e, 1 , 250 , 240 , // 249 - eo
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x989e, 1 , 250 , 240 , // 250 - eo-001
- 0xa , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xd9 , 1 , 262 , 262 , // 251 - es
- 0x580a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x9a55d41, 1 , 252 , 240 , // 252 - es-419
- 0x2c0a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xb , 1 , 253 , 253 , // 253 - es-ar
- 0x400a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x1a , 1 , 254 , 254 , // 254 - es-bo
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x20 , 1 , 255 , 240 , // 255 - es-br
- 0x340a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x2e , 1 , 256 , 256 , // 256 - es-cl
- 0x240a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x33 , 1 , 257 , 257 , // 257 - es-co
- 0x140a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x36 , 1 , 258 , 258 , // 258 - es-cr
- 0x5c0a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x38 , 1 , 259 , 240 , // 259 - es-cu
- 0x1c0a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x41 , 1 , 260 , 260 , // 260 - es-do
- 0x300a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x42 , 1 , 261 , 261 , // 261 - es-ec
- 0xc0a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xd9 , 1 , 262 , 262 , // 262 - es-es
- 0x40a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xd9 , 1 , 263 , 263 , // 263 - es-es_tradnl
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x45 , 1 , 264 , 240 , // 264 - es-gq
- 0x100a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x63 , 1 , 265 , 265 , // 265 - es-gt
- 0x480a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x6a , 1 , 266 , 266 , // 266 - es-hn
- 0x80a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xa6 , 1 , 267 , 267 , // 267 - es-mx
- 0x4c0a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xb6 , 1 , 268 , 268 , // 268 - es-ni
- 0x180a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xc0 , 1 , 269 , 269 , // 269 - es-pa
- 0x280a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xbb , 1 , 270 , 270 , // 270 - es-pe
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xc9 , 1 , 271 , 240 , // 271 - es-ph
- 0x500a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xca , 1 , 272 , 272 , // 272 - es-pr
- 0x3c0a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xb9 , 1 , 273 , 273 , // 273 - es-py
- 0x440a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x48 , 1 , 274 , 274 , // 274 - es-sv
- 0x540a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xf4 , 1 , 275 , 275 , // 275 - es-us
- 0x380a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xf6 , 1 , 276 , 276 , // 276 - es-uy
- 0x200a , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xf9 , 1 , 277 , 277 , // 277 - es-ve
- 0x25 , 0x4e9 , 0x307 , 0x272d, 0x1f4 , 0x46 , 1 , 279 , 279 , // 278 - et
- 0x425 , 0x4e9 , 0x307 , 0x272d, 0x1f4 , 0x46 , 1 , 279 , 279 , // 279 - et-ee
- 0x2d , 0x4e4 , 0x352 , 0x2 , 0x1f4 , 0xd9 , 1 , 281 , 240 , // 280 - eu
- 0x42d , 0x4e4 , 0x352 , 0x2 , 0x1f4 , 0xd9 , 1 , 281 , 240 , // 281 - eu-es
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 283 , 240 , // 282 - ewo
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 283 , 240 , // 283 - ewo-cm
- 0x29 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x74 , 0 , 285 , 143 , // 284 - fa
- 0x429 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x74 , 0 , 285 , 143 , // 285 - fa-ir
- 0x67 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xd2 , 1 , 290 , 290 , // 286 - ff
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x31 , 1 , 287 , 240 , // 287 - ff-cm
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x64 , 1 , 288 , 240 , // 288 - ff-gn
- 0x7c67 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xd2 , 1 , 290 , 290 , // 289 - ff-latn
- 0x867 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xd2 , 1 , 290 , 290 , // 290 - ff-latn-sn
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xa2 , 1 , 291 , 240 , // 291 - ff-mr
- 0x467 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xaf , 1 , 292 , 240 , // 292 - ff-ng
- 0xb , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0x4d , 1 , 294 , 294 , // 293 - fi
- 0x40b , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0x4d , 1 , 294 , 294 , // 294 - fi-fi
- 0x64 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0xc9 , 1 , 296 , 296 , // 295 - fil
- 0x464 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0xc9 , 1 , 296 , 296 , // 296 - fil-ph
- 0x38 , 0x4e4 , 0x352 , 0x275f, 0x4f35, 0x51 , 1 , 299 , 299 , // 297 - fo
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x3d , 1 , 298 , 240 , // 298 - fo-dk
- 0x438 , 0x4e4 , 0x352 , 0x275f, 0x4f35, 0x51 , 1 , 299 , 299 , // 299 - fo-fo
- 0xc , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x54 , 1 , 316 , 316 , // 300 - fr
- 0x1c0c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x993248, 1 , 301 , 316 , // 301 - fr-029
- 0x80c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x15 , 1 , 302 , 302 , // 302 - fr-be
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xf5 , 1 , 303 , 240 , // 303 - fr-bf
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x26 , 1 , 304 , 240 , // 304 - fr-bi
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x1c , 1 , 305 , 240 , // 305 - fr-bj
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x9a55c4f, 1 , 306 , 240 , // 306 - fr-bl
- 0xc0c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x27 , 1 , 307 , 307 , // 307 - fr-ca
- 0x240c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x2c , 1 , 308 , 240 , // 308 - fr-cd
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x37 , 1 , 309 , 240 , // 309 - fr-cf
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x2b , 1 , 310 , 240 , // 310 - fr-cg
- 0x100c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xdf , 1 , 311 , 311 , // 311 - fr-ch
- 0x300c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x77 , 1 , 312 , 240 , // 312 - fr-ci
- 0x2c0c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x31 , 1 , 313 , 240 , // 313 - fr-cm
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x3e , 1 , 314 , 240 , // 314 - fr-dj
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x4 , 1 , 315 , 240 , // 315 - fr-dz
- 0x40c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x54 , 1 , 316 , 316 , // 316 - fr-fr
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x57 , 1 , 317 , 240 , // 317 - fr-ga
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x13d , 1 , 318 , 240 , // 318 - fr-gf
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x64 , 1 , 319 , 240 , // 319 - fr-gn
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x141 , 1 , 320 , 240 , // 320 - fr-gp
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x45 , 1 , 321 , 240 , // 321 - fr-gq
- 0x3c0c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x67 , 1 , 322 , 240 , // 322 - fr-ht
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x32 , 1 , 323 , 240 , // 323 - fr-km
- 0x140c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x93 , 1 , 324 , 324 , // 324 - fr-lu
- 0x380c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x9f , 1 , 325 , 240 , // 325 - fr-ma
- 0x180c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x9e , 1 , 326 , 326 , // 326 - fr-mc
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x7bda, 1 , 327 , 240 , // 327 - fr-mf
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x95 , 1 , 328 , 240 , // 328 - fr-mg
- 0x340c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x9d , 1 , 329 , 240 , // 329 - fr-ml
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x14a , 1 , 330 , 240 , // 330 - fr-mq
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xa2 , 1 , 331 , 240 , // 331 - fr-mr
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xa0 , 1 , 332 , 240 , // 332 - fr-mu
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x14e , 1 , 333 , 240 , // 333 - fr-nc
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xad , 1 , 334 , 240 , // 334 - fr-ne
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x13e , 1 , 335 , 240 , // 335 - fr-pf
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xce , 1 , 336 , 240 , // 336 - fr-pm
- 0x200c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xc6 , 1 , 337 , 240 , // 337 - fr-re
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xcc , 1 , 338 , 240 , // 338 - fr-rw
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xd0 , 1 , 339 , 240 , // 339 - fr-sc
- 0x280c , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xd2 , 1 , 340 , 240 , // 340 - fr-sn
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xde , 1 , 341 , 240 , // 341 - fr-sy
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x29 , 1 , 342 , 240 , // 342 - fr-td
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xe8 , 1 , 343 , 240 , // 343 - fr-tg
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xea , 1 , 344 , 240 , // 344 - fr-tn
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xae , 1 , 345 , 240 , // 345 - fr-vu
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x160 , 1 , 346 , 240 , // 346 - fr-wf
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x14b , 1 , 347 , 240 , // 347 - fr-yt
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x76 , 1 , 349 , 240 , // 348 - fur
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x76 , 1 , 349 , 240 , // 349 - fur-it
- 0x62 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xb0 , 1 , 351 , 351 , // 350 - fy
- 0x462 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xb0 , 1 , 351 , 351 , // 351 - fy-nl
- 0x3c , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x44 , 1 , 353 , 353 , // 352 - ga
- 0x83c , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x44 , 1 , 353 , 353 , // 353 - ga-ie
- 0x91 , 0x4e4 , 0x352 , 0x2710, 0x4f3d, 0xf2 , 1 , 355 , 355 , // 354 - gd
- 0x491 , 0x4e4 , 0x352 , 0x2710, 0x4f3d, 0xf2 , 1 , 355 , 355 , // 355 - gd-gb
- 0x56 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd9 , 1 , 357 , 357 , // 356 - gl
- 0x456 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd9 , 1 , 357 , 357 , // 357 - gl-es
- 0x74 , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xb9 , 1 , 359 , 359 , // 358 - gn
- 0x474 , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xb9 , 1 , 359 , 359 , // 359 - gn-py
- 0x84 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xdf , 1 , 361 , 240 , // 360 - gsw
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xdf , 1 , 361 , 240 , // 361 - gsw-ch
- 0x484 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x54 , 1 , 362 , 362 , // 362 - gsw-fr
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x91 , 1 , 363 , 240 , // 363 - gsw-li
- 0x47 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 365 , 143 , // 364 - gu
- 0x447 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 365 , 143 , // 365 - gu-in
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 367 , 240 , // 366 - guz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 367 , 240 , // 367 - guz-ke
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x3b16, 1 , 369 , 240 , // 368 - gv
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x3b16, 1 , 369 , 240 , // 369 - gv-im
- 0x68 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xaf , 1 , 374 , 374 , // 370 - ha
- 0x7c68 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xaf , 1 , 374 , 374 , // 371 - ha-latn
- 0x1000 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0x59 , 1 , 372 , 240 , // 372 - ha-latn-gh
- 0x1000 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0xad , 1 , 373 , 240 , // 373 - ha-latn-ne
- 0x468 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xaf , 1 , 374 , 374 , // 374 - ha-latn-ng
- 0x75 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xf4 , 1 , 376 , 376 , // 375 - haw
- 0x475 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xf4 , 1 , 376 , 376 , // 376 - haw-us
- 0xd , 0x4e7 , 0x35e , 0x2715, 0x1f4 , 0x75 , 1 , 378 , 143 , // 377 - he
- 0x40d , 0x4e7 , 0x35e , 0x2715, 0x1f4 , 0x75 , 1 , 378 , 143 , // 378 - he-il
- 0x39 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 380 , 143 , // 379 - hi
- 0x439 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 380 , 143 , // 380 - hi-in
- 0x1a , 0x4e2 , 0x354 , 0x2762, 0x1f4 , 0x6c , 1 , 383 , 383 , // 381 - hr
- 0x101a , 0x4e2 , 0x354 , 0x2762, 0x366 , 0x19 , 1 , 382 , 382 , // 382 - hr-ba
- 0x41a , 0x4e2 , 0x354 , 0x2762, 0x1f4 , 0x6c , 1 , 383 , 383 , // 383 - hr-hr
- 0x2e , 0x4e4 , 0x352 , 0x2710, 0x366 , 0x5e , 1 , 385 , 385 , // 384 - hsb
- 0x42e , 0x4e4 , 0x352 , 0x2710, 0x366 , 0x5e , 1 , 385 , 385 , // 385 - hsb-de
- 0xe , 0x4e2 , 0x354 , 0x272d, 0x1f4 , 0x6d , 1 , 387 , 387 , // 386 - hu
- 0x40e , 0x4e2 , 0x354 , 0x272d, 0x1f4 , 0x6d , 1 , 387 , 387 , // 387 - hu-hu
- 0x1040e, 0x4e2 , 0x354 , 0x272d, 0x1f4 , 0x6d , 1 , 387 , 387 , // 388 - hu-hu_technl
- 0x2b , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x7 , 1 , 390 , 390 , // 389 - hy
- 0x42b , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x7 , 1 , 390 , 390 , // 390 - hy-am
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x54 , 1 , 393 , 240 , // 391 - ia
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x989e, 1 , 392 , 240 , // 392 - ia-001
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x54 , 1 , 393 , 240 , // 393 - ia-fr
- 0x69 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xaf , 1 , 395 , 240 , // 394 - ibb
- 0x469 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xaf , 1 , 395 , 240 , // 395 - ibb-ng
- 0x21 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x6f , 1 , 397 , 397 , // 396 - id
- 0x421 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x6f , 1 , 397 , 397 , // 397 - id-id
- 0x70 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xaf , 1 , 399 , 399 , // 398 - ig
- 0x470 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xaf , 1 , 399 , 399 , // 399 - ig-ng
- 0x78 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2d , 1 , 401 , 143 , // 400 - ii
- 0x478 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2d , 1 , 401 , 143 , // 401 - ii-cn
- 0xf , 0x4e4 , 0x352 , 0x275f, 0x5187, 0x6e , 1 , 403 , 403 , // 402 - is
- 0x40f , 0x4e4 , 0x352 , 0x275f, 0x5187, 0x6e , 1 , 403 , 403 , // 403 - is-is
- 0x10 , 0x4e4 , 0x352 , 0x2710, 0x4f38, 0x76 , 1 , 406 , 406 , // 404 - it
- 0x810 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xdf , 1 , 405 , 405 , // 405 - it-ch
- 0x410 , 0x4e4 , 0x352 , 0x2710, 0x4f38, 0x76 , 1 , 406 , 406 , // 406 - it-it
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f38, 0xd6 , 1 , 407 , 240 , // 407 - it-sm
- 0x5d , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0x27 , 1 , 412 , 412 , // 408 - iu
- 0x785d , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x27 , 1 , 410 , 143 , // 409 - iu-cans
- 0x45d , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x27 , 1 , 410 , 143 , // 410 - iu-cans-ca
- 0x7c5d , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0x27 , 1 , 412 , 412 , // 411 - iu-latn
- 0x85d , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0x27 , 1 , 412 , 412 , // 412 - iu-latn-ca
- 0x11 , 0x3a4 , 0x3a4 , 0x2711, 0x4f42, 0x7a , 1 , 414 , 414 , // 413 - ja
- 0x411 , 0x3a4 , 0x3a4 , 0x2711, 0x4f42, 0x7a , 1 , 414 , 414 , // 414 - ja-jp
- 0x40411, 0x3a4 , 0x3a4 , 0x2711, 0x4f42, 0x7a , 1 , 414 , 414 , // 415 - ja-jp_radstr
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 417 , 240 , // 416 - jgo
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 417 , 240 , // 417 - jgo-cm
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 419 , 240 , // 418 - jmc
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 419 , 240 , // 419 - jmc-tz
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x6f , 1 , 424 , 424 , // 420 - jv
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x6f , 1 , 422 , 424 , // 421 - jv-java
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x6f , 1 , 422 , 424 , // 422 - jv-java-id
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x6f , 1 , 424 , 424 , // 423 - jv-latn
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x6f , 1 , 424 , 424 , // 424 - jv-latn-id
- 0x37 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x58 , 1 , 426 , 426 , // 425 - ka
- 0x437 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x58 , 1 , 426 , 426 , // 426 - ka-ge
- 0x10437, 0x0 , 0x1 , 0x2 , 0x1f4 , 0x58 , 1 , 426 , 426 , // 427 - ka-ge_modern
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x4 , 1 , 429 , 240 , // 428 - kab
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x4 , 1 , 429 , 240 , // 429 - kab-dz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 431 , 240 , // 430 - kam
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 431 , 240 , // 431 - kam-ke
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 433 , 240 , // 432 - kde
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 433 , 240 , // 433 - kde-tz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x39 , 1 , 435 , 240 , // 434 - kea
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x39 , 1 , 435 , 240 , // 435 - kea-cv
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9d , 1 , 437 , 240 , // 436 - khq
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9d , 1 , 437 , 240 , // 437 - khq-ml
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 439 , 240 , // 438 - ki
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 439 , 240 , // 439 - ki-ke
- 0x3f , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x89 , 1 , 441 , 441 , // 440 - kk
- 0x43f , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x89 , 1 , 441 , 441 , // 441 - kk-kz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 443 , 240 , // 442 - kkj
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 443 , 240 , // 443 - kkj-cm
- 0x6f , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0x5d , 1 , 445 , 445 , // 444 - kl
- 0x46f , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0x5d , 1 , 445 , 445 , // 445 - kl-gl
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 447 , 240 , // 446 - kln
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 447 , 240 , // 447 - kln-ke
- 0x53 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x28 , 2 , 449 , 143 , // 448 - km
- 0x453 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x28 , 2 , 449 , 143 , // 449 - km-kh
- 0x4b , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 451 , 143 , // 450 - kn
- 0x44b , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 451 , 143 , // 451 - kn-in
- 0x12 , 0x3b5 , 0x3b5 , 0x2713, 0x5161, 0x86 , 1 , 454 , 454 , // 452 - ko
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x83 , 1 , 453 , 240 , // 453 - ko-kp
- 0x412 , 0x3b5 , 0x3b5 , 0x2713, 0x5161, 0x86 , 1 , 454 , 454 , // 454 - ko-kr
- 0x57 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 456 , 143 , // 455 - kok
- 0x457 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 456 , 143 , // 456 - kok-in
- 0x71 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xaf , 1 , 458 , 240 , // 457 - kr
- 0x471 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xaf , 1 , 458 , 240 , // 458 - kr-ng
- 0x60 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 2 , 461 , 240 , // 459 - ks
- 0x460 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 2 , 461 , 240 , // 460 - ks-arab
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 2 , 461 , 240 , // 461 - ks-arab-in
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 463 , 187 , // 462 - ks-deva
- 0x860 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 463 , 187 , // 463 - ks-deva-in
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 465 , 240 , // 464 - ksb
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 465 , 240 , // 465 - ksb-tz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 467 , 240 , // 466 - ksf
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 467 , 240 , // 467 - ksf-cm
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x5e , 1 , 469 , 240 , // 468 - ksh
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x5e , 1 , 469 , 240 , // 469 - ksh-de
- 0x92 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x79 , 0 , 472 , 143 , // 470 - ku
- 0x7c92 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x79 , 0 , 472 , 143 , // 471 - ku-arab
- 0x492 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x79 , 0 , 472 , 143 , // 472 - ku-arab-iq
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x74 , 0 , 473 , 240 , // 473 - ku-arab-ir
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf2 , 1 , 475 , 240 , // 474 - kw
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf2 , 1 , 475 , 240 , // 475 - kw-gb
- 0x40 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0x82 , 1 , 477 , 477 , // 476 - ky
- 0x440 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0x82 , 1 , 477 , 477 , // 477 - ky-kg
- 0x76 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0x989e, 1 , 479 , 143 , // 478 - la
- 0x476 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0x989e, 1 , 479 , 143 , // 479 - la-001
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 481 , 240 , // 480 - lag
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 481 , 240 , // 481 - lag-tz
- 0x6e , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x93 , 1 , 483 , 483 , // 482 - lb
- 0x46e , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x93 , 1 , 483 , 483 , // 483 - lb-lu
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf0 , 1 , 485 , 240 , // 484 - lg
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf0 , 1 , 485 , 240 , // 485 - lg-ug
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf4 , 1 , 487 , 240 , // 486 - lkt
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf4 , 1 , 487 , 240 , // 487 - lkt-us
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2c , 1 , 490 , 240 , // 488 - ln
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9 , 1 , 489 , 240 , // 489 - ln-ao
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2c , 1 , 490 , 240 , // 490 - ln-cd
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x37 , 1 , 491 , 240 , // 491 - ln-cf
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2b , 1 , 492 , 240 , // 492 - ln-cg
- 0x54 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x8a , 1 , 494 , 143 , // 493 - lo
- 0x454 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x8a , 1 , 494 , 143 , // 494 - lo-la
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x74 , 2 , 497 , 240 , // 495 - lrc
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x79 , 2 , 496 , 240 , // 496 - lrc-iq
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x74 , 2 , 497 , 240 , // 497 - lrc-ir
- 0x27 , 0x4e9 , 0x307 , 0x272d, 0x1f4 , 0x8d , 1 , 499 , 499 , // 498 - lt
- 0x427 , 0x4e9 , 0x307 , 0x272d, 0x1f4 , 0x8d , 1 , 499 , 499 , // 499 - lt-lt
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2c , 1 , 501 , 240 , // 500 - lu
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2c , 1 , 501 , 240 , // 501 - lu-cd
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 503 , 240 , // 502 - luo
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 503 , 240 , // 503 - luo-ke
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 505 , 240 , // 504 - luy
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 505 , 240 , // 505 - luy-ke
- 0x26 , 0x4e9 , 0x307 , 0x272d, 0x1f4 , 0x8c , 1 , 507 , 507 , // 506 - lv
- 0x426 , 0x4e9 , 0x307 , 0x272d, 0x1f4 , 0x8c , 1 , 507 , 507 , // 507 - lv-lv
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 509 , 240 , // 508 - mas
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 509 , 240 , // 509 - mas-ke
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 510 , 240 , // 510 - mas-tz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 512 , 240 , // 511 - mer
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 512 , 240 , // 512 - mer-ke
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xa0 , 1 , 514 , 240 , // 513 - mfe
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xa0 , 1 , 514 , 240 , // 514 - mfe-mu
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x95 , 1 , 516 , 240 , // 515 - mg
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x95 , 1 , 516 , 240 , // 516 - mg-mg
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xa8 , 1 , 518 , 240 , // 517 - mgh
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xa8 , 1 , 518 , 240 , // 518 - mgh-mz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 520 , 240 , // 519 - mgo
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 520 , 240 , // 520 - mgo-cm
- 0x81 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xb7 , 1 , 522 , 522 , // 521 - mi
- 0x481 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xb7 , 1 , 522 , 522 , // 522 - mi-nz
- 0x2f , 0x4e3 , 0x362 , 0x2717, 0x1f4 , 0x4ca2, 1 , 524 , 524 , // 523 - mk
- 0x42f , 0x4e3 , 0x362 , 0x2717, 0x1f4 , 0x4ca2, 1 , 524 , 524 , // 524 - mk-mk
- 0x4c , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 526 , 143 , // 525 - ml
- 0x44c , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 526 , 143 , // 526 - ml-in
- 0x50 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0x9a , 1 , 529 , 529 , // 527 - mn
- 0x7850 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0x9a , 1 , 529 , 529 , // 528 - mn-cyrl
- 0x450 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0x9a , 1 , 529 , 529 , // 529 - mn-mn
- 0x7c50 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2d , 1 , 531 , 531 , // 530 - mn-mong
- 0x850 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2d , 1 , 531 , 531 , // 531 - mn-mong-cn
- 0xc50 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9a , 1 , 532 , 532 , // 532 - mn-mong-mn
- 0x58 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 534 , 187 , // 533 - mni
- 0x458 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 534 , 187 , // 534 - mni-in
- 0x7c , 0x4e4 , 0x352 , 0x2710, 0x25 , 0x27 , 1 , 536 , 240 , // 535 - moh
- 0x47c , 0x4e4 , 0x352 , 0x2710, 0x25 , 0x27 , 1 , 536 , 240 , // 536 - moh-ca
- 0x4e , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 538 , 143 , // 537 - mr
- 0x44e , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 538 , 143 , // 538 - mr-in
- 0x3e , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xa7 , 1 , 541 , 541 , // 539 - ms
- 0x83e , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x25 , 1 , 540 , 540 , // 540 - ms-bn
- 0x43e , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xa7 , 1 , 541 , 541 , // 541 - ms-my
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd7 , 1 , 542 , 240 , // 542 - ms-sg
- 0x3a , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xa3 , 1 , 544 , 544 , // 543 - mt
- 0x43a , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xa3 , 1 , 544 , 544 , // 544 - mt-mt
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 546 , 240 , // 545 - mua
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 546 , 240 , // 546 - mua-cm
- 0x55 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x1b , 2 , 548 , 240 , // 547 - my
- 0x455 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x1b , 2 , 548 , 240 , // 548 - my-mm
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x74 , 2 , 550 , 240 , // 549 - mzn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x74 , 2 , 550 , 240 , // 550 - mzn-ir
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xfe , 1 , 552 , 240 , // 551 - naq
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xfe , 1 , 552 , 240 , // 552 - naq-na
- 0x7c14 , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0xb1 , 1 , 554 , 554 , // 553 - nb
- 0x414 , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0xb1 , 1 , 554 , 554 , // 554 - nb-no
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0xdc , 1 , 555 , 240 , // 555 - nb-sj
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x108 , 1 , 557 , 240 , // 556 - nd
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x108 , 1 , 557 , 240 , // 557 - nd-zw
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x5e , 1 , 559 , 240 , // 558 - nds
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x5e , 1 , 559 , 240 , // 559 - nds-de
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xb0 , 1 , 560 , 240 , // 560 - nds-nl
- 0x61 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xb2 , 1 , 563 , 143 , // 561 - ne
- 0x861 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 2 , 562 , 240 , // 562 - ne-in
- 0x461 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xb2 , 1 , 563 , 143 , // 563 - ne-np
- 0x13 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xb0 , 1 , 569 , 569 , // 564 - nl
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x12e , 1 , 565 , 240 , // 565 - nl-aw
- 0x813 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x15 , 1 , 566 , 566 , // 566 - nl-be
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x9a55d42, 1 , 567 , 240 , // 567 - nl-bq
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x111 , 1 , 568 , 240 , // 568 - nl-cw
- 0x413 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xb0 , 1 , 569 , 569 , // 569 - nl-nl
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xb5 , 1 , 570 , 240 , // 570 - nl-sr
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x78f7, 1 , 571 , 240 , // 571 - nl-sx
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 573 , 240 , // 572 - nmg
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 573 , 240 , // 573 - nmg-cm
- 0x7814 , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0xb1 , 1 , 575 , 575 , // 574 - nn
- 0x814 , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0xb1 , 1 , 575 , 575 , // 575 - nn-no
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 577 , 240 , // 576 - nnh
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 577 , 240 , // 577 - nnh-cm
- 0x14 , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0xb1 , 1 , 554 , 554 , // 578 - no
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x64 , 2 , 580 , 143 , // 579 - nqo
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x64 , 2 , 580 , 143 , // 580 - nqo-gn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd1 , 1 , 582 , 240 , // 581 - nr
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd1 , 1 , 582 , 240 , // 582 - nr-za
- 0x6c , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd1 , 1 , 584 , 584 , // 583 - nso
- 0x46c , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd1 , 1 , 584 , 584 , // 584 - nso-za
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x114 , 1 , 586 , 240 , // 585 - nus
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x114 , 1 , 586 , 240 , // 586 - nus-ss
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf0 , 1 , 588 , 240 , // 587 - nyn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf0 , 1 , 588 , 240 , // 588 - nyn-ug
- 0x82 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x54 , 1 , 590 , 590 , // 589 - oc
- 0x482 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x54 , 1 , 590 , 590 , // 590 - oc-fr
- 0x72 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x49 , 1 , 592 , 240 , // 591 - om
- 0x472 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x49 , 1 , 592 , 240 , // 592 - om-et
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 593 , 240 , // 593 - om-ke
- 0x48 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 595 , 143 , // 594 - or
- 0x448 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 595 , 143 , // 595 - or-in
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x58 , 1 , 597 , 240 , // 596 - os
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x58 , 1 , 597 , 240 , // 597 - os-ge
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xcb , 1 , 598 , 240 , // 598 - os-ru
- 0x46 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 602 , 143 , // 599 - pa
- 0x7c46 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xbe , 2 , 601 , 143 , // 600 - pa-arab
- 0x846 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xbe , 2 , 601 , 143 , // 601 - pa-arab-pk
- 0x446 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 602 , 143 , // 602 - pa-in
- 0x79 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x993248, 1 , 604 , 145 , // 603 - pap
- 0x479 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x993248, 1 , 604 , 145 , // 604 - pap-029
- 0x15 , 0x4e2 , 0x354 , 0x272d, 0x5190, 0xbf , 1 , 606 , 606 , // 605 - pl
- 0x415 , 0x4e2 , 0x354 , 0x272d, 0x5190, 0xbf , 1 , 606 , 606 , // 606 - pl-pl
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x989e, 1 , 608 , 240 , // 607 - prg
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x989e, 1 , 608 , 240 , // 608 - prg-001
- 0x8c , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x3 , 2 , 610 , 143 , // 609 - prs
- 0x48c , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x3 , 2 , 610 , 143 , // 610 - prs-af
- 0x63 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x3 , 2 , 612 , 143 , // 611 - ps
- 0x463 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x3 , 2 , 612 , 143 , // 612 - ps-af
- 0x16 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x20 , 1 , 615 , 615 , // 613 - pt
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x9 , 1 , 614 , 240 , // 614 - pt-ao
- 0x416 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x20 , 1 , 615 , 615 , // 615 - pt-br
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xdf , 1 , 616 , 240 , // 616 - pt-ch
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x39 , 1 , 617 , 240 , // 617 - pt-cv
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x45 , 1 , 618 , 240 , // 618 - pt-gq
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xc4 , 1 , 619 , 240 , // 619 - pt-gw
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x93 , 1 , 620 , 240 , // 620 - pt-lu
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x97 , 1 , 621 , 240 , // 621 - pt-mo
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xa8 , 1 , 622 , 240 , // 622 - pt-mz
- 0x816 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xc1 , 1 , 623 , 623 , // 623 - pt-pt
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xe9 , 1 , 624 , 240 , // 624 - pt-st
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x6f60e7, 1 , 625 , 240 , // 625 - pt-tl
- 0x901 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x7c , 1 , 626 , 190 , // 626 - qps-latn-x-sh
- 0x501 , 0x4e2 , 0x354 , 0x272d, 0x5190, 0xf4 , 1 , 627 , 627 , // 627 - qps-ploc
- 0x5fe , 0x3a4 , 0x3a4 , 0x2711, 0x4f42, 0x7a , 1 , 628 , 628 , // 628 - qps-ploca
- 0x9ff , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xcd , 0 , 629 , 143 , // 629 - qps-plocm
- 0x86 , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x63 , 1 , 632 , 632 , // 630 - quc
- 0x7c86 , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x63 , 1 , 632 , 632 , // 631 - quc-latn
- 0x486 , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x63 , 1 , 632 , 632 , // 632 - quc-latn-gt
- 0x6b , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x1a , 1 , 634 , 634 , // 633 - quz
- 0x46b , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x1a , 1 , 634 , 634 , // 634 - quz-bo
- 0x86b , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0x42 , 1 , 635 , 635 , // 635 - quz-ec
- 0xc6b , 0x4e4 , 0x352 , 0x2710, 0x4f3c, 0xbb , 1 , 636 , 636 , // 636 - quz-pe
- 0x17 , 0x4e4 , 0x352 , 0x2710, 0x4f31, 0xdf , 1 , 638 , 638 , // 637 - rm
- 0x417 , 0x4e4 , 0x352 , 0x2710, 0x4f31, 0xdf , 1 , 638 , 638 , // 638 - rm-ch
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x26 , 1 , 640 , 240 , // 639 - rn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x26 , 1 , 640 , 240 , // 640 - rn-bi
- 0x18 , 0x4e2 , 0x354 , 0x272d, 0x5190, 0xc8 , 1 , 643 , 643 , // 641 - ro
- 0x818 , 0x4e2 , 0x354 , 0x2 , 0x1f4 , 0x98 , 1 , 642 , 240 , // 642 - ro-md
- 0x418 , 0x4e2 , 0x354 , 0x272d, 0x5190, 0xc8 , 1 , 643 , 643 , // 643 - ro-ro
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 645 , 240 , // 644 - rof
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 645 , 240 , // 645 - rof-tz
- 0x19 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xcb , 1 , 651 , 651 , // 646 - ru
- 0x1000 , 0x4e3 , 0x362 , 0x2 , 0x1f4 , 0x1d , 1 , 647 , 240 , // 647 - ru-by
- 0x1000 , 0x4e3 , 0x362 , 0x2 , 0x1f4 , 0x82 , 1 , 648 , 240 , // 648 - ru-kg
- 0x1000 , 0x4e3 , 0x362 , 0x2 , 0x1f4 , 0x89 , 1 , 649 , 240 , // 649 - ru-kz
- 0x819 , 0x4e3 , 0x362 , 0x2 , 0x1f4 , 0x98 , 1 , 650 , 240 , // 650 - ru-md
- 0x419 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xcb , 1 , 651 , 651 , // 651 - ru-ru
- 0x1000 , 0x4e3 , 0x362 , 0x2 , 0x1f4 , 0xf1 , 1 , 652 , 240 , // 652 - ru-ua
- 0x87 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xcc , 1 , 654 , 654 , // 653 - rw
- 0x487 , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xcc , 1 , 654 , 654 , // 654 - rw-rw
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 656 , 240 , // 655 - rwk
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 656 , 240 , // 656 - rwk-tz
- 0x4f , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 658 , 143 , // 657 - sa
- 0x44f , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 658 , 143 , // 658 - sa-in
- 0x85 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xcb , 1 , 660 , 660 , // 659 - sah
- 0x485 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xcb , 1 , 660 , 660 , // 660 - sah-ru
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 662 , 240 , // 661 - saq
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 662 , 240 , // 662 - saq-ke
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 664 , 240 , // 663 - sbp
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 664 , 240 , // 664 - sbp-tz
- 0x59 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xbe , 2 , 667 , 143 , // 665 - sd
- 0x7c59 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xbe , 2 , 667 , 143 , // 666 - sd-arab
- 0x859 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xbe , 2 , 667 , 143 , // 667 - sd-arab-pk
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 669 , 187 , // 668 - sd-deva
- 0x459 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 669 , 187 , // 669 - sd-deva-in
- 0x3b , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0xb1 , 1 , 672 , 672 , // 670 - se
- 0xc3b , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0x4d , 1 , 671 , 671 , // 671 - se-fi
- 0x43b , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0xb1 , 1 , 672 , 672 , // 672 - se-no
- 0x83b , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0xdd , 1 , 673 , 673 , // 673 - se-se
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xa8 , 1 , 675 , 240 , // 674 - seh
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xa8 , 1 , 675 , 240 , // 675 - seh-mz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9d , 1 , 677 , 240 , // 676 - ses
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9d , 1 , 677 , 240 , // 677 - ses-ml
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x37 , 1 , 679 , 240 , // 678 - sg
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x37 , 1 , 679 , 240 , // 679 - sg-cf
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9f , 1 , 684 , 240 , // 680 - shi
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9f , 1 , 682 , 240 , // 681 - shi-latn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9f , 1 , 682 , 240 , // 682 - shi-latn-ma
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9f , 1 , 684 , 240 , // 683 - shi-tfng
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9f , 1 , 684 , 240 , // 684 - shi-tfng-ma
- 0x5b , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2a , 1 , 686 , 143 , // 685 - si
- 0x45b , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2a , 1 , 686 , 143 , // 686 - si-lk
- 0x1b , 0x4e2 , 0x354 , 0x272d, 0x5190, 0x8f , 1 , 688 , 688 , // 687 - sk
- 0x41b , 0x4e2 , 0x354 , 0x272d, 0x5190, 0x8f , 1 , 688 , 688 , // 688 - sk-sk
- 0x24 , 0x4e2 , 0x354 , 0x272d, 0x5190, 0xd4 , 1 , 690 , 690 , // 689 - sl
- 0x424 , 0x4e2 , 0x354 , 0x272d, 0x5190, 0xd4 , 1 , 690 , 690 , // 690 - sl-si
- 0x783b , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0xdd , 1 , 693 , 693 , // 691 - sma
- 0x183b , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0xb1 , 1 , 692 , 692 , // 692 - sma-no
- 0x1c3b , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0xdd , 1 , 693 , 693 , // 693 - sma-se
- 0x7c3b , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0xdd , 1 , 696 , 696 , // 694 - smj
- 0x103b , 0x4e4 , 0x352 , 0x2710, 0x4f35, 0xb1 , 1 , 695 , 695 , // 695 - smj-no
- 0x143b , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0xdd , 1 , 696 , 696 , // 696 - smj-se
- 0x703b , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0x4d , 1 , 698 , 698 , // 697 - smn
- 0x243b , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0x4d , 1 , 698 , 698 , // 698 - smn-fi
- 0x743b , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0x4d , 1 , 700 , 700 , // 699 - sms
- 0x203b , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0x4d , 1 , 700 , 700 , // 700 - sms-fi
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x108 , 1 , 703 , 240 , // 701 - sn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x108 , 1 , 703 , 240 , // 702 - sn-latn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x108 , 1 , 703 , 240 , // 703 - sn-latn-zw
- 0x77 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd8 , 1 , 708 , 240 , // 704 - so
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x3e , 1 , 705 , 240 , // 705 - so-dj
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x49 , 1 , 706 , 240 , // 706 - so-et
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 707 , 240 , // 707 - so-ke
- 0x477 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd8 , 1 , 708 , 240 , // 708 - so-so
- 0x1c , 0x4e2 , 0x354 , 0x272d, 0x5190, 0x6 , 1 , 710 , 710 , // 709 - sq
- 0x41c , 0x4e2 , 0x354 , 0x272d, 0x5190, 0x6 , 1 , 710 , 710 , // 710 - sq-al
- 0x1000 , 0x4e2 , 0x354 , 0x272d, 0x5190, 0x4ca2, 1 , 711 , 240 , // 711 - sq-mk
- 0x1000 , 0x4e2 , 0x354 , 0x272d, 0x5190, 0x974941, 1 , 712 , 240 , // 712 - sq-xk
- 0x7c1a , 0x4e2 , 0x354 , 0x272d, 0x1f4 , 0x10f , 1 , 724 , 724 , // 713 - sr
- 0x6c1a , 0x4e3 , 0x357 , 0x2717, 0x5221, 0x10f , 1 , 718 , 718 , // 714 - sr-cyrl
- 0x1c1a , 0x4e3 , 0x357 , 0x2717, 0x5221, 0x19 , 1 , 715 , 715 , // 715 - sr-cyrl-ba
- 0xc1a , 0x4e3 , 0x357 , 0x2717, 0x5221, 0x10d , 1 , 716 , 716 , // 716 - sr-cyrl-cs
- 0x301a , 0x4e3 , 0x357 , 0x2717, 0x5221, 0x10e , 1 , 717 , 717 , // 717 - sr-cyrl-me
- 0x281a , 0x4e3 , 0x357 , 0x2717, 0x5221, 0x10f , 1 , 718 , 718 , // 718 - sr-cyrl-rs
- 0x1000 , 0x4e3 , 0x357 , 0x2717, 0x5221, 0x974941, 1 , 719 , 240 , // 719 - sr-cyrl-xk
- 0x701a , 0x4e2 , 0x354 , 0x272d, 0x1f4 , 0x10f , 1 , 724 , 724 , // 720 - sr-latn
- 0x181a , 0x4e2 , 0x354 , 0x2762, 0x366 , 0x19 , 1 , 721 , 721 , // 721 - sr-latn-ba
- 0x81a , 0x4e2 , 0x354 , 0x272d, 0x1f4 , 0x10d , 1 , 722 , 722 , // 722 - sr-latn-cs
- 0x2c1a , 0x4e2 , 0x354 , 0x272d, 0x1f4 , 0x10e , 1 , 723 , 723 , // 723 - sr-latn-me
- 0x241a , 0x4e2 , 0x354 , 0x272d, 0x1f4 , 0x10f , 1 , 724 , 724 , // 724 - sr-latn-rs
- 0x1000 , 0x4e2 , 0x354 , 0x272d, 0x1f4 , 0x974941, 1 , 725 , 240 , // 725 - sr-latn-xk
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd1 , 1 , 728 , 240 , // 726 - ss
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x104 , 1 , 727 , 240 , // 727 - ss-sz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd1 , 1 , 728 , 240 , // 728 - ss-za
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x47 , 1 , 730 , 240 , // 729 - ssy
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x47 , 1 , 730 , 240 , // 730 - ssy-er
- 0x30 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd1 , 1 , 733 , 240 , // 731 - st
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x92 , 1 , 732 , 240 , // 732 - st-ls
- 0x430 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd1 , 1 , 733 , 240 , // 733 - st-za
- 0x1d , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0xdd , 1 , 737 , 737 , // 734 - sv
- 0x1000 , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0x9906f5, 1 , 735 , 240 , // 735 - sv-ax
- 0x81d , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0x4d , 1 , 736 , 736 , // 736 - sv-fi
- 0x41d , 0x4e4 , 0x352 , 0x2710, 0x4f36, 0xdd , 1 , 737 , 737 , // 737 - sv-se
- 0x41 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0x81 , 1 , 740 , 740 , // 738 - sw
- 0x1000 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0x2c , 1 , 739 , 740 , // 739 - sw-cd
- 0x441 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0x81 , 1 , 740 , 740 , // 740 - sw-ke
- 0x1000 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0xef , 1 , 741 , 240 , // 741 - sw-tz
- 0x1000 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0xf0 , 1 , 742 , 240 , // 742 - sw-ug
- 0x1000 , 0x0 , 0x1 , 0x0 , 0x1f4 , 0x2c , 1 , 744 , 240 , // 743 - swc
- 0x1000 , 0x0 , 0x1 , 0x0 , 0x1f4 , 0x2c , 1 , 744 , 240 , // 744 - swc-cd
- 0x5a , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xde , 1 , 746 , 143 , // 745 - syr
- 0x45a , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xde , 1 , 746 , 143 , // 746 - syr-sy
- 0x49 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 748 , 143 , // 747 - ta
- 0x449 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 748 , 143 , // 748 - ta-in
- 0x849 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x2a , 1 , 749 , 143 , // 749 - ta-lk
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xa7 , 1 , 750 , 240 , // 750 - ta-my
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd7 , 1 , 751 , 240 , // 751 - ta-sg
- 0x4a , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 753 , 143 , // 752 - te
- 0x44a , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x71 , 1 , 753 , 143 , // 753 - te-in
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf0 , 1 , 756 , 240 , // 754 - teo
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x81 , 1 , 755 , 240 , // 755 - teo-ke
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf0 , 1 , 756 , 240 , // 756 - teo-ug
- 0x28 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xe4 , 1 , 759 , 759 , // 757 - tg
- 0x7c28 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xe4 , 1 , 759 , 759 , // 758 - tg-cyrl
- 0x428 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xe4 , 1 , 759 , 759 , // 759 - tg-cyrl-tj
- 0x1e , 0x36a , 0x36a , 0x2725, 0x5166, 0xe3 , 1 , 761 , 143 , // 760 - th
- 0x41e , 0x36a , 0x36a , 0x2725, 0x5166, 0xe3 , 1 , 761 , 143 , // 761 - th-th
- 0x73 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x47 , 1 , 763 , 143 , // 762 - ti
- 0x873 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x47 , 1 , 763 , 143 , // 763 - ti-er
- 0x473 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x49 , 1 , 764 , 143 , // 764 - ti-et
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x47 , 1 , 766 , 240 , // 765 - tig
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x47 , 1 , 766 , 240 , // 766 - tig-er
- 0x42 , 0x4e2 , 0x354 , 0x272d, 0x5190, 0xee , 1 , 768 , 768 , // 767 - tk
- 0x442 , 0x4e2 , 0x354 , 0x272d, 0x5190, 0xee , 1 , 768 , 768 , // 768 - tk-tm
- 0x32 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd1 , 1 , 771 , 771 , // 769 - tn
- 0x832 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0x13 , 1 , 770 , 770 , // 770 - tn-bw
- 0x432 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd1 , 1 , 771 , 771 , // 771 - tn-za
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xe7 , 1 , 773 , 240 , // 772 - to
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xe7 , 1 , 773 , 240 , // 773 - to-to
- 0x1f , 0x4e6 , 0x359 , 0x2761, 0x51a9, 0xeb , 1 , 776 , 776 , // 774 - tr
- 0x1000 , 0x4e6 , 0x359 , 0x2761, 0x51a9, 0x3b , 1 , 775 , 240 , // 775 - tr-cy
- 0x41f , 0x4e6 , 0x359 , 0x2761, 0x51a9, 0xeb , 1 , 776 , 776 , // 776 - tr-tr
- 0x31 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd1 , 1 , 778 , 240 , // 777 - ts
- 0x431 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd1 , 1 , 778 , 240 , // 778 - ts-za
- 0x44 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xcb , 1 , 780 , 780 , // 779 - tt
- 0x444 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xcb , 1 , 780 , 780 , // 780 - tt-ru
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xad , 1 , 782 , 240 , // 781 - twq
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xad , 1 , 782 , 240 , // 782 - twq-ne
- 0x5f , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x4 , 1 , 787 , 787 , // 783 - tzm
- 0x1000 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x9f , 1 , 785 , 240 , // 784 - tzm-arab
- 0x45f , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x9f , 1 , 785 , 240 , // 785 - tzm-arab-ma
- 0x7c5f , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x4 , 1 , 787 , 787 , // 786 - tzm-latn
- 0x85f , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0x4 , 1 , 787 , 787 , // 787 - tzm-latn-dz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9f , 1 , 788 , 240 , // 788 - tzm-latn-ma
- 0x785f , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9f , 1 , 790 , 316 , // 789 - tzm-tfng
- 0x105f , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9f , 1 , 790 , 316 , // 790 - tzm-tfng-ma
- 0x80 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x2d , 1 , 792 , 143 , // 791 - ug
- 0x480 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0x2d , 1 , 792 , 143 , // 792 - ug-cn
- 0x22 , 0x4e3 , 0x362 , 0x2721, 0x1f4 , 0xf1 , 1 , 794 , 794 , // 793 - uk
- 0x422 , 0x4e3 , 0x362 , 0x2721, 0x1f4 , 0xf1 , 1 , 794 , 794 , // 794 - uk-ua
- 0x20 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xbe , 1 , 797 , 143 , // 795 - ur
- 0x820 , 0x4e8 , 0x2d0 , 0x2 , 0x1f4 , 0x71 , 2 , 796 , 240 , // 796 - ur-in
- 0x420 , 0x4e8 , 0x2d0 , 0x2714, 0x4fc4, 0xbe , 1 , 797 , 143 , // 797 - ur-pk
- 0x43 , 0x4e6 , 0x359 , 0x272d, 0x1f4 , 0xf7 , 1 , 804 , 804 , // 798 - uz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x3 , 2 , 800 , 240 , // 799 - uz-arab
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x3 , 2 , 800 , 240 , // 800 - uz-arab-af
- 0x7843 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xf7 , 1 , 802 , 802 , // 801 - uz-cyrl
- 0x843 , 0x4e3 , 0x362 , 0x2717, 0x5190, 0xf7 , 1 , 802 , 802 , // 802 - uz-cyrl-uz
- 0x7c43 , 0x4e6 , 0x359 , 0x272d, 0x1f4 , 0xf7 , 1 , 804 , 804 , // 803 - uz-latn
- 0x443 , 0x4e6 , 0x359 , 0x272d, 0x1f4 , 0xf7 , 1 , 804 , 804 , // 804 - uz-latn-uz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x8e , 1 , 809 , 240 , // 805 - vai
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x8e , 1 , 807 , 240 , // 806 - vai-latn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x8e , 1 , 807 , 240 , // 807 - vai-latn-lr
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x8e , 1 , 809 , 240 , // 808 - vai-vaii
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x8e , 1 , 809 , 240 , // 809 - vai-vaii-lr
- 0x33 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd1 , 1 , 811 , 240 , // 810 - ve
- 0x433 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xd1 , 1 , 811 , 240 , // 811 - ve-za
- 0x2a , 0x4ea , 0x4ea , 0x2710, 0x1f4 , 0xfb , 1 , 813 , 143 , // 812 - vi
- 0x42a , 0x4ea , 0x4ea , 0x2710, 0x1f4 , 0xfb , 1 , 813 , 143 , // 813 - vi-vn
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x989e, 1 , 815 , 240 , // 814 - vo
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x989e, 1 , 815 , 240 , // 815 - vo-001
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 817 , 240 , // 816 - vun
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xef , 1 , 817 , 240 , // 817 - vun-tz
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xdf , 1 , 819 , 240 , // 818 - wae
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xdf , 1 , 819 , 240 , // 819 - wae-ch
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x49 , 1 , 821 , 240 , // 820 - wal
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x49 , 1 , 821 , 240 , // 821 - wal-et
- 0x88 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xd2 , 1 , 823 , 823 , // 822 - wo
- 0x488 , 0x4e4 , 0x352 , 0x2710, 0x4f49, 0xd2 , 1 , 823 , 823 , // 823 - wo-sn
- 0x1007f, 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xf4 , 1 , -1 , -1 , // 824 - x-iv_mathan
- 0x34 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd1 , 1 , 826 , 826 , // 825 - xh
- 0x434 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd1 , 1 , 826 , 826 , // 826 - xh-za
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf0 , 1 , 828 , 240 , // 827 - xog
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0xf0 , 1 , 828 , 240 , // 828 - xog-ug
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 830 , 240 , // 829 - yav
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x31 , 1 , 830 , 240 , // 830 - yav-cm
- 0x3d , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x989e, 1 , 832 , 240 , // 831 - yi
- 0x43d , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x989e, 1 , 832 , 240 , // 832 - yi-001
- 0x6a , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xaf , 1 , 835 , 835 , // 833 - yo
- 0x1000 , 0x4e4 , 0x1b5 , 0x2710, 0x1f4 , 0x1c , 1 , 834 , 240 , // 834 - yo-bj
- 0x46a , 0x4e4 , 0x1b5 , 0x2710, 0x25 , 0xaf , 1 , 835 , 835 , // 835 - yo-ng
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x68 , 1 , 837 , 240 , // 836 - yue
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x68 , 1 , 837 , 240 , // 837 - yue-hk
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9f , 1 , 840 , 316 , // 838 - zgh
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9f , 1 , 840 , 316 , // 839 - zgh-tfng
- 0x1000 , 0x0 , 0x1 , 0x2 , 0x1f4 , 0x9f , 1 , 840 , 316 , // 840 - zgh-tfng-ma
- 0x7804 , 0x3a8 , 0x3a8 , 0x2718, 0x1f4 , 0x2d , 1 , 844 , 844 , // 841 - zh
- 0x4 , 0x3a8 , 0x3a8 , 0x0 , 0x1f4 , 0x2d , 1 , 844 , 844 , // 842 - zh-chs
- 0x7c04 , 0x3b6 , 0x3b6 , 0x0 , 0x1f4 , 0x68 , 1 , 851 , 851 , // 843 - zh-cht
- 0x804 , 0x3a8 , 0x3a8 , 0x2718, 0x1f4 , 0x2d , 1 , 844 , 844 , // 844 - zh-cn
- 0x50804, 0x3a8 , 0x3a8 , 0x2718, 0x1f4 , 0x2d , 1 , 844 , 844 , // 845 - zh-cn_phoneb
- 0x20804, 0x3a8 , 0x3a8 , 0x2718, 0x1f4 , 0x2d , 1 , 844 , 844 , // 846 - zh-cn_stroke
- 0x4 , 0x3a8 , 0x3a8 , 0x2718, 0x1f4 , 0x2d , 1 , 844 , 844 , // 847 - zh-hans
- 0x1000 , 0x3a8 , 0x3a8 , 0x2718, 0x1f4 , 0x68 , 1 , 848 , 240 , // 848 - zh-hans-hk
- 0x1000 , 0x3a8 , 0x3a8 , 0x2718, 0x1f4 , 0x97 , 1 , 849 , 240 , // 849 - zh-hans-mo
- 0x7c04 , 0x3b6 , 0x3b6 , 0x2712, 0x1f4 , 0x68 , 1 , 851 , 851 , // 850 - zh-hant
- 0xc04 , 0x3b6 , 0x3b6 , 0x2712, 0x1f4 , 0x68 , 1 , 851 , 851 , // 851 - zh-hk
- 0x40c04, 0x3b6 , 0x3b6 , 0x2712, 0x1f4 , 0x68 , 1 , 851 , 851 , // 852 - zh-hk_radstr
- 0x1404 , 0x3b6 , 0x3b6 , 0x2712, 0x1f4 , 0x97 , 1 , 853 , 853 , // 853 - zh-mo
- 0x41404, 0x3b6 , 0x3b6 , 0x2712, 0x1f4 , 0x97 , 1 , 853 , 853 , // 854 - zh-mo_radstr
- 0x21404, 0x3b6 , 0x3b6 , 0x2712, 0x1f4 , 0x97 , 1 , 853 , 853 , // 855 - zh-mo_stroke
- 0x1004 , 0x3a8 , 0x3a8 , 0x2718, 0x1f4 , 0xd7 , 1 , 856 , 856 , // 856 - zh-sg
- 0x51004, 0x3a8 , 0x3a8 , 0x2718, 0x1f4 , 0xd7 , 1 , 856 , 856 , // 857 - zh-sg_phoneb
- 0x21004, 0x3a8 , 0x3a8 , 0x2718, 0x1f4 , 0xd7 , 1 , 856 , 856 , // 858 - zh-sg_stroke
- 0x404 , 0x3b6 , 0x3b6 , 0x2712, 0x1f4 , 0xed , 1 , 859 , 859 , // 859 - zh-tw
- 0x30404, 0x3b6 , 0x3b6 , 0x2712, 0x1f4 , 0xed , 1 , 859 , 859 , // 860 - zh-tw_pronun
- 0x40404, 0x3b6 , 0x3b6 , 0x2712, 0x1f4 , 0xed , 1 , 859 , 859 , // 861 - zh-tw_radstr
- 0x35 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd1 , 1 , 863 , 863 , // 862 - zu
- 0x435 , 0x4e4 , 0x352 , 0x2710, 0x1f4 , 0xd1 , 1 , 863 , 863 , // 863 - zu-za
- };
-
- // s_lcids list all supported lcids. used to binary search and we use the index of the matched lcid to
- // get the index in s_localeNamesIndices using s_lcidToCultureNameIndices
- private static readonly int[] s_lcids = new int[]
- {
- // Lcid , index - index in c_localeNames
- 0x1 , // 0 - 52
- 0x2 , // 1 - 301
- 0x3 , // 2 - 421
- 0x4 , // 3 - 4139
- 0x5 , // 4 - 502
- 0x6 , // 5 - 523
- 0x7 , // 6 - 544
- 0x8 , // 7 - 664
- 0x9 , // 8 - 676
- 0xa , // 9 - 1214
- 0xb , // 10 - 1423
- 0xc , // 11 - 1451
- 0xd , // 12 - 1825
- 0xe , // 13 - 1860
- 0xf , // 14 - 1929
- 0x10 , // 15 - 1936
- 0x11 , // 16 - 1989
- 0x12 , // 17 - 2179
- 0x13 , // 18 - 2685
- 0x14 , // 19 - 2747
- 0x15 , // 20 - 2864
- 0x16 , // 21 - 2897
- 0x17 , // 22 - 3041
- 0x18 , // 23 - 3055
- 0x19 , // 24 - 3076
- 0x1a , // 25 - 1839
- 0x1b , // 26 - 3284
- 0x1c , // 27 - 3387
- 0x1d , // 28 - 3553
- 0x1e , // 29 - 3673
- 0x1f , // 30 - 3727
- 0x20 , // 31 - 3847
- 0x21 , // 32 - 1908
- 0x22 , // 33 - 3840
- 0x23 , // 34 - 276
- 0x24 , // 35 - 3291
- 0x25 , // 36 - 1354
- 0x26 , // 37 - 2429
- 0x27 , // 38 - 2397
- 0x28 , // 39 - 3654
- 0x29 , // 40 - 1377
- 0x2a , // 41 - 3960
- 0x2b , // 42 - 1879
- 0x2c , // 43 - 224
- 0x2d , // 44 - 1361
- 0x2e , // 45 - 1851
- 0x2f , // 46 - 2501
- 0x30 , // 47 - 3541
- 0x31 , // 48 - 3739
- 0x32 , // 49 - 3708
- 0x33 , // 50 - 3953
- 0x34 , // 51 - 4020
- 0x35 , // 52 - 4277
- 0x36 , // 53 - 17
- 0x37 , // 54 - 2062
- 0x38 , // 55 - 1439
- 0x39 , // 56 - 1832
- 0x3a , // 57 - 2598
- 0x3b , // 58 - 3194
- 0x3c , // 59 - 1705
- 0x3d , // 60 - 4045
- 0x3e , // 61 - 2581
- 0x3f , // 62 - 2133
- 0x40 , // 63 - 2306
- 0x41 , // 64 - 3570
- 0x42 , // 65 - 3701
- 0x43 , // 66 - 3859
- 0x44 , // 67 - 3746
- 0x45 , // 68 - 336
- 0x46 , // 69 - 2830
- 0x47 , // 70 - 1754
- 0x48 , // 71 - 2811
- 0x49 , // 72 - 3610
- 0x4a , // 73 - 3632
- 0x4b , // 74 - 2172
- 0x4c , // 75 - 2508
- 0x4d , // 76 - 199
- 0x4e , // 77 - 2574
- 0x4f , // 78 - 3124
- 0x50 , // 79 - 2515
- 0x51 , // 80 - 348
- 0x52 , // 81 - 516
- 0x53 , // 82 - 2165
- 0x54 , // 83 - 2375
- 0x55 , // 84 - 2614
- 0x56 , // 85 - 1719
- 0x57 , // 86 - 2191
- 0x58 , // 87 - 2556
- 0x59 , // 88 - 3158
- 0x5a , // 89 - 3601
- 0x5b , // 90 - 3277
- 0x5c , // 91 - 473
- 0x5d , // 92 - 1953
- 0x5e , // 93 - 45
- 0x5f , // 94 - 3762
- 0x60 , // 95 - 2207
- 0x61 , // 96 - 2673
- 0x62 , // 97 - 1698
- 0x63 , // 98 - 2890
- 0x64 , // 99 - 1430
- 0x65 , // 100 - 620
- 0x66 , // 101 - 308
- 0x67 , // 102 - 1384
- 0x68 , // 103 - 1777
- 0x69 , // 104 - 1899
- 0x6a , // 105 - 4053
- 0x6b , // 106 - 3020
- 0x6c , // 107 - 2765
- 0x6d , // 108 - 260
- 0x6e , // 109 - 2330
- 0x6f , // 110 - 2149
- 0x70 , // 111 - 1915
- 0x71 , // 112 - 2200
- 0x72 , // 113 - 2799
- 0x73 , // 114 - 3680
- 0x74 , // 115 - 1726
- 0x75 , // 116 - 1816
- 0x76 , // 117 - 2313
- 0x77 , // 118 - 3365
- 0x78 , // 119 - 1922
- 0x79 , // 120 - 2854
- 0x7a , // 121 - 190
- 0x7c , // 122 - 2565
- 0x7e , // 123 - 360
- 0x80 , // 124 - 3833
- 0x81 , // 125 - 2494
- 0x82 , // 126 - 2792
- 0x83 , // 127 - 495
- 0x84 , // 128 - 1733
- 0x85 , // 129 - 3131
- 0x86 , // 130 - 2998
- 0x87 , // 131 - 3108
- 0x88 , // 132 - 4002
- 0x8c , // 133 - 2881
- 0x91 , // 134 - 1712
- 0x92 , // 135 - 2270
- 0x401 , // 136 - 150
- 0x402 , // 137 - 303
- 0x403 , // 138 - 428
- 0x404 , // 139 - 4248
- 0x405 , // 140 - 504
- 0x406 , // 141 - 525
- 0x407 , // 142 - 561
- 0x408 , // 143 - 671
- 0x409 , // 144 - 1161
- 0x40a , // 145 - 1272
- 0x40b , // 146 - 1425
- 0x40c , // 147 - 1529
- 0x40d , // 148 - 1827
- 0x40e , // 149 - 1862
- 0x40f , // 150 - 1931
- 0x410 , // 151 - 1943
- 0x411 , // 152 - 1991
- 0x412 , // 153 - 2186
- 0x413 , // 154 - 2707
- 0x414 , // 155 - 2641
- 0x415 , // 156 - 2866
- 0x416 , // 157 - 2904
- 0x417 , // 158 - 3043
- 0x418 , // 159 - 3062
- 0x419 , // 160 - 3098
- 0x41a , // 161 - 1846
- 0x41b , // 162 - 3286
- 0x41c , // 163 - 3389
- 0x41d , // 164 - 3565
- 0x41e , // 165 - 3675
- 0x41f , // 166 - 3734
- 0x420 , // 167 - 3854
- 0x421 , // 168 - 1910
- 0x422 , // 169 - 3842
- 0x423 , // 170 - 278
- 0x424 , // 171 - 3293
- 0x425 , // 172 - 1356
- 0x426 , // 173 - 2431
- 0x427 , // 174 - 2399
- 0x428 , // 175 - 3663
- 0x429 , // 176 - 1379
- 0x42a , // 177 - 3962
- 0x42b , // 178 - 1881
- 0x42c , // 179 - 250
- 0x42d , // 180 - 1363
- 0x42e , // 181 - 1854
- 0x42f , // 182 - 2503
- 0x430 , // 183 - 3548
- 0x431 , // 184 - 3741
- 0x432 , // 185 - 3715
- 0x433 , // 186 - 3955
- 0x434 , // 187 - 4022
- 0x435 , // 188 - 4279
- 0x436 , // 189 - 24
- 0x437 , // 190 - 2064
- 0x438 , // 191 - 1446
- 0x439 , // 192 - 1834
- 0x43a , // 193 - 2600
- 0x43b , // 194 - 3201
- 0x43d , // 195 - 4047
- 0x43e , // 196 - 2588
- 0x43f , // 197 - 2135
- 0x440 , // 198 - 2308
- 0x441 , // 199 - 3577
- 0x442 , // 200 - 3703
- 0x443 , // 201 - 3902
- 0x444 , // 202 - 3748
- 0x445 , // 203 - 343
- 0x446 , // 204 - 2849
- 0x447 , // 205 - 1756
- 0x448 , // 206 - 2813
- 0x449 , // 207 - 3612
- 0x44a , // 208 - 3634
- 0x44b , // 209 - 2174
- 0x44c , // 210 - 2510
- 0x44d , // 211 - 201
- 0x44e , // 212 - 2576
- 0x44f , // 213 - 3126
- 0x450 , // 214 - 2524
- 0x451 , // 215 - 350
- 0x452 , // 216 - 518
- 0x453 , // 217 - 2167
- 0x454 , // 218 - 2377
- 0x455 , // 219 - 2616
- 0x456 , // 220 - 1721
- 0x457 , // 221 - 2194
- 0x458 , // 222 - 2559
- 0x459 , // 223 - 3184
- 0x45a , // 224 - 3604
- 0x45b , // 225 - 3279
- 0x45c , // 226 - 484
- 0x45d , // 227 - 1962
- 0x45e , // 228 - 47
- 0x45f , // 229 - 3773
- 0x460 , // 230 - 2209
- 0x461 , // 231 - 2680
- 0x462 , // 232 - 1700
- 0x463 , // 233 - 2892
- 0x464 , // 234 - 1433
- 0x465 , // 235 - 622
- 0x466 , // 236 - 311
- 0x467 , // 237 - 1418
- 0x468 , // 238 - 1806
- 0x469 , // 239 - 1902
- 0x46a , // 240 - 4060
- 0x46b , // 241 - 3023
- 0x46c , // 242 - 2768
- 0x46d , // 243 - 262
- 0x46e , // 244 - 2332
- 0x46f , // 245 - 2151
- 0x470 , // 246 - 1917
- 0x471 , // 247 - 2202
- 0x472 , // 248 - 2801
- 0x473 , // 249 - 3687
- 0x474 , // 250 - 1728
- 0x475 , // 251 - 1819
- 0x476 , // 252 - 2315
- 0x477 , // 253 - 3382
- 0x478 , // 254 - 1924
- 0x479 , // 255 - 2857
- 0x47a , // 256 - 193
- 0x47c , // 257 - 2568
- 0x47e , // 258 - 362
- 0x480 , // 259 - 3835
- 0x481 , // 260 - 2496
- 0x482 , // 261 - 2794
- 0x483 , // 262 - 497
- 0x484 , // 263 - 1742
- 0x485 , // 264 - 3134
- 0x486 , // 265 - 3009
- 0x487 , // 266 - 3110
- 0x488 , // 267 - 4004
- 0x48c , // 268 - 2884
- 0x491 , // 269 - 1714
- 0x492 , // 270 - 2279
- 0x501 , // 271 - 2972
- 0x5fe , // 272 - 2980
- 0x801 , // 273 - 95
- 0x803 , // 274 - 433
- 0x804 , // 275 - 4110
- 0x807 , // 276 - 556
- 0x809 , // 277 - 831
- 0x80a , // 278 - 1299
- 0x80c , // 279 - 1459
- 0x810 , // 280 - 1938
- 0x813 , // 281 - 2692
- 0x814 , // 282 - 2733
- 0x816 , // 283 - 2944
- 0x818 , // 284 - 3057
- 0x819 , // 285 - 3093
- 0x81a , // 286 - 3480
- 0x81d , // 287 - 3560
- 0x820 , // 288 - 3849
- 0x82c , // 289 - 233
- 0x82e , // 290 - 605
- 0x832 , // 291 - 3710
- 0x83b , // 292 - 3206
- 0x83c , // 293 - 1707
- 0x83e , // 294 - 2583
- 0x843 , // 295 - 3885
- 0x845 , // 296 - 338
- 0x846 , // 297 - 2839
- 0x849 , // 298 - 3617
- 0x850 , // 299 - 2536
- 0x859 , // 300 - 3167
- 0x85d , // 301 - 1979
- 0x85f , // 302 - 3792
- 0x860 , // 303 - 2233
- 0x861 , // 304 - 2675
- 0x867 , // 305 - 1403
- 0x86b , // 306 - 3029
- 0x873 , // 307 - 3682
- 0x901 , // 308 - 2959
- 0x9ff , // 309 - 2989
- 0xc01 , // 310 - 80
- 0xc04 , // 311 - 4173
- 0xc07 , // 312 - 546
- 0xc09 , // 313 - 716
- 0xc0a , // 314 - 1267
- 0xc0c , // 315 - 1484
- 0xc1a , // 316 - 3423
- 0xc3b , // 317 - 3196
- 0xc50 , // 318 - 2546
- 0xc51 , // 319 - 638
- 0xc6b , // 320 - 3035
- 0x1001 , // 321 - 120
- 0x1004 , // 322 - 4219
- 0x1007 , // 323 - 588
- 0x1009 , // 324 - 756
- 0x100a , // 325 - 1289
- 0x100c , // 326 - 1504
- 0x101a , // 327 - 1841
- 0x103b , // 328 - 3316
- 0x105f , // 329 - 3822
- 0x1401 , // 330 - 75
- 0x1404 , // 331 - 4190
- 0x1407 , // 332 - 583
- 0x1409 , // 333 - 1026
- 0x140a , // 334 - 1247
- 0x140c , // 335 - 1569
- 0x141a , // 336 - 402
- 0x143b , // 337 - 3322
- 0x1801 , // 338 - 125
- 0x1809 , // 339 - 881
- 0x180a , // 340 - 1309
- 0x180c , // 341 - 1579
- 0x181a , // 342 - 3470
- 0x183b , // 343 - 3301
- 0x1c01 , // 344 - 180
- 0x1c09 , // 345 - 1191
- 0x1c0a , // 346 - 1257
- 0x1c0c , // 347 - 1453
- 0x1c1a , // 348 - 3413
- 0x1c3b , // 349 - 3307
- 0x2001 , // 350 - 135
- 0x2009 , // 351 - 911
- 0x200a , // 352 - 1349
- 0x200c , // 353 - 1634
- 0x201a , // 354 - 385
- 0x203b , // 355 - 3340
- 0x2401 , // 356 - 185
- 0x2409 , // 357 - 684
- 0x240a , // 358 - 1242
- 0x240c , // 359 - 1489
- 0x241a , // 360 - 3500
- 0x243b , // 361 - 3331
- 0x2801 , // 362 - 170
- 0x2809 , // 363 - 751
- 0x280a , // 364 - 1314
- 0x280c , // 365 - 1649
- 0x281a , // 366 - 3443
- 0x2c01 , // 367 - 100
- 0x2c09 , // 368 - 1136
- 0x2c0a , // 369 - 1222
- 0x2c0c , // 370 - 1514
- 0x2c1a , // 371 - 3490
- 0x3001 , // 372 - 115
- 0x3009 , // 373 - 1201
- 0x300a , // 374 - 1262
- 0x300c , // 375 - 1509
- 0x301a , // 376 - 3433
- 0x3401 , // 377 - 110
- 0x3409 , // 378 - 1036
- 0x340a , // 379 - 1237
- 0x340c , // 380 - 1594
- 0x3801 , // 381 - 60
- 0x3809 , // 382 - 876
- 0x380a , // 383 - 1344
- 0x380c , // 384 - 1574
- 0x3c01 , // 385 - 65
- 0x3c09 , // 386 - 871
- 0x3c0a , // 387 - 1329
- 0x3c0c , // 388 - 1559
- 0x4001 , // 389 - 145
- 0x4009 , // 390 - 896
- 0x400a , // 391 - 1227
- 0x4409 , // 392 - 991
- 0x440a , // 393 - 1334
- 0x4809 , // 394 - 1086
- 0x480a , // 395 - 1294
- 0x4c0a , // 396 - 1304
- 0x500a , // 397 - 1324
- 0x540a , // 398 - 1339
- 0x580a , // 399 - 1216
- 0x5c0a , // 400 - 1252
- 0x641a , // 401 - 378
- 0x681a , // 402 - 395
- 0x6c1a , // 403 - 3406
- 0x701a , // 404 - 3463
- 0x703b , // 405 - 3328
- 0x742c , // 406 - 226
- 0x743b , // 407 - 3337
- 0x7804 , // 408 - 4096
- 0x7814 , // 409 - 2731
- 0x781a , // 410 - 376
- 0x782c , // 411 - 243
- 0x783b , // 412 - 3298
- 0x7843 , // 413 - 3878
- 0x7850 , // 414 - 2517
- 0x785d , // 415 - 1955
- 0x785f , // 416 - 3814
- 0x7c04 , // 417 - 4166
- 0x7c14 , // 418 - 2639
- 0x7c1a , // 419 - 3404
- 0x7c28 , // 420 - 3656
- 0x7c2e , // 421 - 602
- 0x7c3b , // 422 - 3313
- 0x7c43 , // 423 - 3895
- 0x7c46 , // 424 - 2832
- 0x7c50 , // 425 - 2529
- 0x7c59 , // 426 - 3160
- 0x7c5c , // 427 - 476
- 0x7c5d , // 428 - 1972
- 0x7c5f , // 429 - 3784
- 0x7c67 , // 430 - 1396
- 0x7c68 , // 431 - 1779
- 0x7c86 , // 432 - 3001
- 0x7c92 , // 433 - 2272
- 0x1007f, // 434 - 4009
- 0x10407, // 435 - 566
- 0x1040e, // 436 - 1867
- 0x10437, // 437 - 2069
- 0x20804, // 438 - 4127
- 0x21004, // 439 - 4236
- 0x21404, // 440 - 4207
- 0x30404, // 441 - 4253
- 0x40404, // 442 - 4265
- 0x40411, // 443 - 1996
- 0x40c04, // 444 - 4178
- 0x41404, // 445 - 4195
- 0x50804, // 446 - 4115
- 0x51004 // 447 - 4224
- };
- // each element in s_lcidToCultureNameIndices is index to s_localeNamesIndices
- private static readonly int[] s_lcidToCultureNameIndices = new int[]
- {
- // Index to s_localeNamesIndices, index to this array - lcid - index to the c_localeNames
- 13 , // 0 - 1 - 52
- 64 , // 1 - 2 - 301
- 88 , // 2 - 3 - 421
- 847 , // 3 - 4 - 4139
- 103 , // 4 - 5 - 502
- 109 , // 5 - 6 - 523
- 114 , // 6 - 7 - 544
- 140 , // 7 - 8 - 664
- 143 , // 8 - 9 - 676
- 251 , // 9 - a - 1214
- 293 , // 10 - b - 1423
- 300 , // 11 - c - 1451
- 377 , // 12 - d - 1825
- 386 , // 13 - e - 1860
- 402 , // 14 - f - 1929
- 404 , // 15 - 10 - 1936
- 413 , // 16 - 11 - 1989
- 452 , // 17 - 12 - 2179
- 564 , // 18 - 13 - 2685
- 578 , // 19 - 14 - 2747
- 605 , // 20 - 15 - 2864
- 613 , // 21 - 16 - 2897
- 637 , // 22 - 17 - 3041
- 641 , // 23 - 18 - 3055
- 646 , // 24 - 19 - 3076
- 381 , // 25 - 1a - 1839
- 687 , // 26 - 1b - 3284
- 709 , // 27 - 1c - 3387
- 734 , // 28 - 1d - 3553
- 760 , // 29 - 1e - 3673
- 774 , // 30 - 1f - 3727
- 795 , // 31 - 20 - 3847
- 396 , // 32 - 21 - 1908
- 793 , // 33 - 22 - 3840
- 58 , // 34 - 23 - 276
- 689 , // 35 - 24 - 3291
- 278 , // 36 - 25 - 1354
- 506 , // 37 - 26 - 2429
- 498 , // 38 - 27 - 2397
- 757 , // 39 - 28 - 3654
- 284 , // 40 - 29 - 1377
- 812 , // 41 - 2a - 3960
- 389 , // 42 - 2b - 1879
- 49 , // 43 - 2c - 224
- 280 , // 44 - 2d - 1361
- 384 , // 45 - 2e - 1851
- 523 , // 46 - 2f - 2501
- 731 , // 47 - 30 - 3541
- 777 , // 48 - 31 - 3739
- 769 , // 49 - 32 - 3708
- 810 , // 50 - 33 - 3953
- 825 , // 51 - 34 - 4020
- 862 , // 52 - 35 - 4277
- 4 , // 53 - 36 - 17
- 425 , // 54 - 37 - 2062
- 297 , // 55 - 38 - 1439
- 379 , // 56 - 39 - 1832
- 543 , // 57 - 3a - 2598
- 670 , // 58 - 3b - 3194
- 352 , // 59 - 3c - 1705
- 831 , // 60 - 3d - 4045
- 539 , // 61 - 3e - 2581
- 440 , // 62 - 3f - 2133
- 476 , // 63 - 40 - 2306
- 738 , // 64 - 41 - 3570
- 767 , // 65 - 42 - 3701
- 798 , // 66 - 43 - 3859
- 779 , // 67 - 44 - 3746
- 71 , // 68 - 45 - 336
- 599 , // 69 - 46 - 2830
- 364 , // 70 - 47 - 1754
- 594 , // 71 - 48 - 2811
- 747 , // 72 - 49 - 3610
- 752 , // 73 - 4a - 3632
- 450 , // 74 - 4b - 2172
- 525 , // 75 - 4c - 2508
- 43 , // 76 - 4d - 199
- 537 , // 77 - 4e - 2574
- 657 , // 78 - 4f - 3124
- 527 , // 79 - 50 - 2515
- 74 , // 80 - 51 - 348
- 107 , // 81 - 52 - 516
- 448 , // 82 - 53 - 2165
- 493 , // 83 - 54 - 2375
- 547 , // 84 - 55 - 2614
- 356 , // 85 - 56 - 1719
- 455 , // 86 - 57 - 2191
- 533 , // 87 - 58 - 2556
- 665 , // 88 - 59 - 3158
- 745 , // 89 - 5a - 3601
- 685 , // 90 - 5b - 3277
- 98 , // 91 - 5c - 473
- 408 , // 92 - 5d - 1953
- 11 , // 93 - 5e - 45
- 783 , // 94 - 5f - 3762
- 459 , // 95 - 60 - 2207
- 561 , // 96 - 61 - 2673
- 350 , // 97 - 62 - 1698
- 611 , // 98 - 63 - 2890
- 295 , // 99 - 64 - 1430
- 129 , // 100 - 65 - 620
- 66 , // 101 - 66 - 308
- 286 , // 102 - 67 - 1384
- 370 , // 103 - 68 - 1777
- 394 , // 104 - 69 - 1899
- 833 , // 105 - 6a - 4053
- 633 , // 106 - 6b - 3020
- 583 , // 107 - 6c - 2765
- 54 , // 108 - 6d - 260
- 482 , // 109 - 6e - 2330
- 444 , // 110 - 6f - 2149
- 398 , // 111 - 70 - 1915
- 457 , // 112 - 71 - 2200
- 591 , // 113 - 72 - 2799
- 762 , // 114 - 73 - 3680
- 358 , // 115 - 74 - 1726
- 375 , // 116 - 75 - 1816
- 478 , // 117 - 76 - 2313
- 704 , // 118 - 77 - 3365
- 400 , // 119 - 78 - 1922
- 603 , // 120 - 79 - 2854
- 41 , // 121 - 7a - 190
- 535 , // 122 - 7c - 2565
- 77 , // 123 - 7e - 360
- 791 , // 124 - 80 - 3833
- 521 , // 125 - 81 - 2494
- 589 , // 126 - 82 - 2792
- 101 , // 127 - 83 - 495
- 360 , // 128 - 84 - 1733
- 659 , // 129 - 85 - 3131
- 630 , // 130 - 86 - 2998
- 653 , // 131 - 87 - 3108
- 822 , // 132 - 88 - 4002
- 609 , // 133 - 8c - 2881
- 354 , // 134 - 91 - 1712
- 470 , // 135 - 92 - 2270
- 33 , // 136 - 401 - 150
- 65 , // 137 - 402 - 303
- 90 , // 138 - 403 - 428
- 859 , // 139 - 404 - 4248
- 104 , // 140 - 405 - 504
- 110 , // 141 - 406 - 525
- 118 , // 142 - 407 - 561
- 142 , // 143 - 408 - 671
- 240 , // 144 - 409 - 1161
- 263 , // 145 - 40a - 1272
- 294 , // 146 - 40b - 1425
- 316 , // 147 - 40c - 1529
- 378 , // 148 - 40d - 1827
- 387 , // 149 - 40e - 1862
- 403 , // 150 - 40f - 1931
- 406 , // 151 - 410 - 1943
- 414 , // 152 - 411 - 1991
- 454 , // 153 - 412 - 2186
- 569 , // 154 - 413 - 2707
- 554 , // 155 - 414 - 2641
- 606 , // 156 - 415 - 2866
- 615 , // 157 - 416 - 2904
- 638 , // 158 - 417 - 3043
- 643 , // 159 - 418 - 3062
- 651 , // 160 - 419 - 3098
- 383 , // 161 - 41a - 1846
- 688 , // 162 - 41b - 3286
- 710 , // 163 - 41c - 3389
- 737 , // 164 - 41d - 3565
- 761 , // 165 - 41e - 3675
- 776 , // 166 - 41f - 3734
- 797 , // 167 - 420 - 3854
- 397 , // 168 - 421 - 1910
- 794 , // 169 - 422 - 3842
- 59 , // 170 - 423 - 278
- 690 , // 171 - 424 - 3293
- 279 , // 172 - 425 - 1356
- 507 , // 173 - 426 - 2431
- 499 , // 174 - 427 - 2399
- 759 , // 175 - 428 - 3663
- 285 , // 176 - 429 - 1379
- 813 , // 177 - 42a - 3962
- 390 , // 178 - 42b - 1881
- 53 , // 179 - 42c - 250
- 281 , // 180 - 42d - 1363
- 385 , // 181 - 42e - 1854
- 524 , // 182 - 42f - 2503
- 733 , // 183 - 430 - 3548
- 778 , // 184 - 431 - 3741
- 771 , // 185 - 432 - 3715
- 811 , // 186 - 433 - 3955
- 826 , // 187 - 434 - 4022
- 863 , // 188 - 435 - 4279
- 6 , // 189 - 436 - 24
- 426 , // 190 - 437 - 2064
- 299 , // 191 - 438 - 1446
- 380 , // 192 - 439 - 1834
- 544 , // 193 - 43a - 2600
- 672 , // 194 - 43b - 3201
- 832 , // 195 - 43d - 4047
- 541 , // 196 - 43e - 2588
- 441 , // 197 - 43f - 2135
- 477 , // 198 - 440 - 2308
- 740 , // 199 - 441 - 3577
- 768 , // 200 - 442 - 3703
- 804 , // 201 - 443 - 3902
- 780 , // 202 - 444 - 3748
- 73 , // 203 - 445 - 343
- 602 , // 204 - 446 - 2849
- 365 , // 205 - 447 - 1756
- 595 , // 206 - 448 - 2813
- 748 , // 207 - 449 - 3612
- 753 , // 208 - 44a - 3634
- 451 , // 209 - 44b - 2174
- 526 , // 210 - 44c - 2510
- 44 , // 211 - 44d - 201
- 538 , // 212 - 44e - 2576
- 658 , // 213 - 44f - 3126
- 529 , // 214 - 450 - 2524
- 75 , // 215 - 451 - 350
- 108 , // 216 - 452 - 518
- 449 , // 217 - 453 - 2167
- 494 , // 218 - 454 - 2377
- 548 , // 219 - 455 - 2616
- 357 , // 220 - 456 - 1721
- 456 , // 221 - 457 - 2194
- 534 , // 222 - 458 - 2559
- 669 , // 223 - 459 - 3184
- 746 , // 224 - 45a - 3604
- 686 , // 225 - 45b - 3279
- 100 , // 226 - 45c - 484
- 410 , // 227 - 45d - 1962
- 12 , // 228 - 45e - 47
- 785 , // 229 - 45f - 3773
- 460 , // 230 - 460 - 2209
- 563 , // 231 - 461 - 2680
- 351 , // 232 - 462 - 1700
- 612 , // 233 - 463 - 2892
- 296 , // 234 - 464 - 1433
- 130 , // 235 - 465 - 622
- 67 , // 236 - 466 - 311
- 292 , // 237 - 467 - 1418
- 374 , // 238 - 468 - 1806
- 395 , // 239 - 469 - 1902
- 835 , // 240 - 46a - 4060
- 634 , // 241 - 46b - 3023
- 584 , // 242 - 46c - 2768
- 55 , // 243 - 46d - 262
- 483 , // 244 - 46e - 2332
- 445 , // 245 - 46f - 2151
- 399 , // 246 - 470 - 1917
- 458 , // 247 - 471 - 2202
- 592 , // 248 - 472 - 2801
- 764 , // 249 - 473 - 3687
- 359 , // 250 - 474 - 1728
- 376 , // 251 - 475 - 1819
- 479 , // 252 - 476 - 2315
- 708 , // 253 - 477 - 3382
- 401 , // 254 - 478 - 1924
- 604 , // 255 - 479 - 2857
- 42 , // 256 - 47a - 193
- 536 , // 257 - 47c - 2568
- 78 , // 258 - 47e - 362
- 792 , // 259 - 480 - 3835
- 522 , // 260 - 481 - 2496
- 590 , // 261 - 482 - 2794
- 102 , // 262 - 483 - 497
- 362 , // 263 - 484 - 1742
- 660 , // 264 - 485 - 3134
- 632 , // 265 - 486 - 3009
- 654 , // 266 - 487 - 3110
- 823 , // 267 - 488 - 4004
- 610 , // 268 - 48c - 2884
- 355 , // 269 - 491 - 1714
- 472 , // 270 - 492 - 2279
- 627 , // 271 - 501 - 2972
- 628 , // 272 - 5fe - 2980
- 22 , // 273 - 801 - 95
- 91 , // 274 - 803 - 433
- 844 , // 275 - 804 - 4110
- 117 , // 276 - 807 - 556
- 174 , // 277 - 809 - 831
- 267 , // 278 - 80a - 1299
- 302 , // 279 - 80c - 1459
- 405 , // 280 - 810 - 1938
- 566 , // 281 - 813 - 2692
- 575 , // 282 - 814 - 2733
- 623 , // 283 - 816 - 2944
- 642 , // 284 - 818 - 3057
- 650 , // 285 - 819 - 3093
- 722 , // 286 - 81a - 3480
- 736 , // 287 - 81d - 3560
- 796 , // 288 - 820 - 3849
- 51 , // 289 - 82c - 233
- 126 , // 290 - 82e - 605
- 770 , // 291 - 832 - 3710
- 673 , // 292 - 83b - 3206
- 353 , // 293 - 83c - 1707
- 540 , // 294 - 83e - 2583
- 802 , // 295 - 843 - 3885
- 72 , // 296 - 845 - 338
- 601 , // 297 - 846 - 2839
- 749 , // 298 - 849 - 3617
- 531 , // 299 - 850 - 2536
- 667 , // 300 - 859 - 3167
- 412 , // 301 - 85d - 1979
- 787 , // 302 - 85f - 3792
- 463 , // 303 - 860 - 2233
- 562 , // 304 - 861 - 2675
- 290 , // 305 - 867 - 1403
- 635 , // 306 - 86b - 3029
- 763 , // 307 - 873 - 3682
- 626 , // 308 - 901 - 2959
- 629 , // 309 - 9ff - 2989
- 19 , // 310 - c01 - 80
- 851 , // 311 - c04 - 4173
- 115 , // 312 - c07 - 546
- 151 , // 313 - c09 - 716
- 262 , // 314 - c0a - 1267
- 307 , // 315 - c0c - 1484
- 716 , // 316 - c1a - 3423
- 671 , // 317 - c3b - 3196
- 532 , // 318 - c50 - 2546
- 134 , // 319 - c51 - 638
- 636 , // 320 - c6b - 3035
- 27 , // 321 - 1001 - 120
- 856 , // 322 - 1004 - 4219
- 122 , // 323 - 1007 - 588
- 159 , // 324 - 1009 - 756
- 265 , // 325 - 100a - 1289
- 311 , // 326 - 100c - 1504
- 382 , // 327 - 101a - 1841
- 695 , // 328 - 103b - 3316
- 790 , // 329 - 105f - 3822
- 18 , // 330 - 1401 - 75
- 853 , // 331 - 1404 - 4190
- 121 , // 332 - 1407 - 583
- 213 , // 333 - 1409 - 1026
- 258 , // 334 - 140a - 1247
- 324 , // 335 - 140c - 1569
- 85 , // 336 - 141a - 402
- 696 , // 337 - 143b - 3322
- 28 , // 338 - 1801 - 125
- 184 , // 339 - 1809 - 881
- 269 , // 340 - 180a - 1309
- 326 , // 341 - 180c - 1579
- 721 , // 342 - 181a - 3470
- 692 , // 343 - 183b - 3301
- 39 , // 344 - 1c01 - 180
- 246 , // 345 - 1c09 - 1191
- 260 , // 346 - 1c0a - 1257
- 301 , // 347 - 1c0c - 1453
- 715 , // 348 - 1c1a - 3413
- 693 , // 349 - 1c3b - 3307
- 30 , // 350 - 2001 - 135
- 190 , // 351 - 2009 - 911
- 277 , // 352 - 200a - 1349
- 337 , // 353 - 200c - 1634
- 83 , // 354 - 201a - 385
- 700 , // 355 - 203b - 3340
- 40 , // 356 - 2401 - 185
- 145 , // 357 - 2409 - 684
- 257 , // 358 - 240a - 1242
- 308 , // 359 - 240c - 1489
- 724 , // 360 - 241a - 3500
- 698 , // 361 - 243b - 3331
- 37 , // 362 - 2801 - 170
- 158 , // 363 - 2809 - 751
- 270 , // 364 - 280a - 1314
- 340 , // 365 - 280c - 1649
- 718 , // 366 - 281a - 3443
- 23 , // 367 - 2c01 - 100
- 235 , // 368 - 2c09 - 1136
- 253 , // 369 - 2c0a - 1222
- 313 , // 370 - 2c0c - 1514
- 723 , // 371 - 2c1a - 3490
- 26 , // 372 - 3001 - 115
- 248 , // 373 - 3009 - 1201
- 261 , // 374 - 300a - 1262
- 312 , // 375 - 300c - 1509
- 717 , // 376 - 301a - 3433
- 25 , // 377 - 3401 - 110
- 215 , // 378 - 3409 - 1036
- 256 , // 379 - 340a - 1237
- 329 , // 380 - 340c - 1594
- 15 , // 381 - 3801 - 60
- 183 , // 382 - 3809 - 876
- 276 , // 383 - 380a - 1344
- 325 , // 384 - 380c - 1574
- 16 , // 385 - 3c01 - 65
- 182 , // 386 - 3c09 - 871
- 273 , // 387 - 3c0a - 1329
- 322 , // 388 - 3c0c - 1559
- 32 , // 389 - 4001 - 145
- 187 , // 390 - 4009 - 896
- 254 , // 391 - 400a - 1227
- 206 , // 392 - 4409 - 991
- 274 , // 393 - 440a - 1334
- 225 , // 394 - 4809 - 1086
- 266 , // 395 - 480a - 1294
- 268 , // 396 - 4c0a - 1304
- 272 , // 397 - 500a - 1324
- 275 , // 398 - 540a - 1339
- 252 , // 399 - 580a - 1216
- 259 , // 400 - 5c0a - 1252
- 82 , // 401 - 641a - 378
- 84 , // 402 - 681a - 395
- 714 , // 403 - 6c1a - 3406
- 720 , // 404 - 701a - 3463
- 697 , // 405 - 703b - 3328
- 50 , // 406 - 742c - 226
- 699 , // 407 - 743b - 3337
- 841 , // 408 - 7804 - 4096
- 574 , // 409 - 7814 - 2731
- 81 , // 410 - 781a - 376
- 52 , // 411 - 782c - 243
- 691 , // 412 - 783b - 3298
- 801 , // 413 - 7843 - 3878
- 528 , // 414 - 7850 - 2517
- 409 , // 415 - 785d - 1955
- 789 , // 416 - 785f - 3814
- 850 , // 417 - 7c04 - 4166
- 553 , // 418 - 7c14 - 2639
- 713 , // 419 - 7c1a - 3404
- 758 , // 420 - 7c28 - 3656
- 125 , // 421 - 7c2e - 602
- 694 , // 422 - 7c3b - 3313
- 803 , // 423 - 7c43 - 3895
- 600 , // 424 - 7c46 - 2832
- 530 , // 425 - 7c50 - 2529
- 666 , // 426 - 7c59 - 3160
- 99 , // 427 - 7c5c - 476
- 411 , // 428 - 7c5d - 1972
- 786 , // 429 - 7c5f - 3784
- 289 , // 430 - 7c67 - 1396
- 371 , // 431 - 7c68 - 1779
- 631 , // 432 - 7c86 - 3001
- 471 , // 433 - 7c92 - 2272
- 824 , // 434 - 1007f - 4009
- 119 , // 435 - 10407 - 566
- 388 , // 436 - 1040e - 1867
- 427 , // 437 - 10437 - 2069
- 846 , // 438 - 20804 - 4127
- 858 , // 439 - 21004 - 4236
- 855 , // 440 - 21404 - 4207
- 860 , // 441 - 30404 - 4253
- 861 , // 442 - 40404 - 4265
- 415 , // 443 - 40411 - 1996
- 852 , // 444 - 40c04 - 4178
- 854 , // 445 - 41404 - 4195
- 845 , // 446 - 50804 - 4115
- 857 // 447 - 51004 - 4224
- };
-
- internal static string? LCIDToLocaleName(int culture)
- {
- int left = 0;
- int right = s_lcids.Length - 1;
- int index;
-
- Debug.Assert(s_lcids.Length == s_lcidToCultureNameIndices.Length);
-
- while (left <= right)
- {
- index = (right + left) / 2;
-
- if (culture == s_lcids[index])
- {
- int indexToLocaleNamesIndices = s_lcidToCultureNameIndices[index];
- Debug.Assert(indexToLocaleNamesIndices < s_localeNamesIndices.Length - 1);
-
- return c_localeNames.Substring(s_localeNamesIndices[indexToLocaleNamesIndices],
- s_localeNamesIndices[indexToLocaleNamesIndices + 1] -
- s_localeNamesIndices[indexToLocaleNamesIndices]);
- }
- else if (culture < s_lcids[index])
- {
- right = index - 1;
- }
- else
- {
- left = index + 1;
- }
- }
-
- return null;
- }
-
- internal static int GetLocaleDataNumericPart(string cultureName, LocaleDataParts part)
- {
- int index = SearchCultureName(cultureName);
- if (index < 0)
- {
- return -1;
- }
-
- Debug.Assert((s_localeNamesIndices.Length-1 == (s_nameIndexToNumericData.Length/NUMERIC_LOCALE_DATA_COUNT_PER_ROW)) &&
- index < s_localeNamesIndices.Length);
-
- return s_nameIndexToNumericData[index * NUMERIC_LOCALE_DATA_COUNT_PER_ROW + (int) part];
- }
-
- internal static string? GetThreeLetterWindowsLanguageName(string cultureName)
- {
- int index = SearchCultureName(cultureName);
- if (index < 0)
- {
- return null;
- }
-
- Debug.Assert(s_localeNamesIndices.Length-1 == (c_threeLetterWindowsLanguageName.Length / 3));
- return c_threeLetterWindowsLanguageName.Substring(index * 3, 3);
- }
-
- internal static string GetLocaleDataMappedCulture(string cultureName, LocaleDataParts part)
- {
- int indexToIndicesTable = GetLocaleDataNumericPart(cultureName, part);
- if (indexToIndicesTable < 0)
- {
- return ""; // fallback to invariant
- }
-
- Debug.Assert(indexToIndicesTable < s_localeNamesIndices.Length-1);
-
- return c_localeNames.Substring(s_localeNamesIndices[indexToIndicesTable],
- s_localeNamesIndices[indexToIndicesTable+1] - s_localeNamesIndices[indexToIndicesTable]);
- }
-
- internal static string GetSpecificCultureName(string cultureName)
- {
- return GetLocaleDataMappedCulture(cultureName, LocaleDataParts.SpecificLocaleIndex);
- }
-
- internal static string GetConsoleUICulture(string cultureName)
- {
- return GetLocaleDataMappedCulture(cultureName, LocaleDataParts.ConsoleLocaleIndex);
- }
-
- // SearchCultureName will binary search c_localeNames using s_localeNamesIndices.
- // return index in s_localeNamesIndices, or -1 if it fail finding any match
- private static int SearchCultureName(string name)
- {
- int left = 0;
- int right = s_localeNamesIndices.Length - 2;
- int index;
- int result;
-
- Debug.Assert(s_localeNamesIndices[s_localeNamesIndices.Length - 1] == c_localeNames.Length);
-
- name = CultureData.AnsiToLower(name);
-
- // Binary search the array until we have only a couple of elements left and then
- // just walk those elements.
- while ((right - left) > 3)
- {
- index = ((right - left) / 2) + left;
-
- Debug.Assert(index < s_localeNamesIndices.Length - 1);
- result = CompareOrdinal(name, c_localeNames, s_localeNamesIndices[index], s_localeNamesIndices[index + 1] - s_localeNamesIndices[index]);
- if (result == 0)
- {
- return index;
- }
- else if (result < 0)
- {
- right = index;
- }
- else
- {
- left = index;
- }
- }
-
- // Walk the remaining elements (it'll be 3 or fewer).
- for (; left <= right; left++)
- {
- Debug.Assert(left < s_localeNamesIndices.Length - 1);
- if (CompareOrdinal(name, c_localeNames, s_localeNamesIndices[left], s_localeNamesIndices[left + 1] - s_localeNamesIndices[left]) == 0)
- {
- return (left);
- }
- }
-
- // couldn't find culture name
- return -1;
- }
-
- // optimized to avoid parameters checking
- private static int CompareOrdinal(string s1, string s2, int index, int length)
- {
- int count = s1.Length;
- if (count > length)
- count = length;
-
- int i = 0;
- while (i < count && s1[i] == s2[index + i])
- i++;
-
- if (i < count)
- return (int)(s1[i] - s2[index + i]);
-
- return s1.Length - length;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/Normalization.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/Normalization.Unix.cs
deleted file mode 100644
index 37c9024c33d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/Normalization.Unix.cs
+++ /dev/null
@@ -1,134 +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 System.Diagnostics;
-using System.Text;
-
-namespace System.Globalization
-{
- internal static partial class Normalization
- {
- internal static bool IsNormalized(string strInput, NormalizationForm normalizationForm)
- {
- if (GlobalizationMode.Invariant)
- {
- // In Invariant mode we assume all characters are normalized.
- // This is because we don't support any linguistic operation on the strings
- return true;
- }
-
- ValidateArguments(strInput, normalizationForm);
-
- int ret = Interop.Globalization.IsNormalized(normalizationForm, strInput, strInput.Length);
-
- if (ret == -1)
- {
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
- }
-
- return ret == 1;
- }
-
- internal static string Normalize(string strInput, NormalizationForm normalizationForm)
- {
- if (GlobalizationMode.Invariant)
- {
- // In Invariant mode we assume all characters are normalized.
- // This is because we don't support any linguistic operation on the strings
- return strInput;
- }
-
- ValidateArguments(strInput, normalizationForm);
-
- char[] buf = new char[strInput.Length];
-
- for (int attempts = 2; attempts > 0; attempts--)
- {
- int realLen = Interop.Globalization.NormalizeString(normalizationForm, strInput, strInput.Length, buf, buf.Length);
-
- if (realLen == -1)
- {
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
- }
-
- if (realLen <= buf.Length)
- {
- return new string(buf, 0, realLen);
- }
-
- buf = new char[realLen];
- }
-
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
- }
-
- // -----------------------------
- // ---- PAL layer ends here ----
- // -----------------------------
-
- private static void ValidateArguments(string strInput, NormalizationForm normalizationForm)
- {
- Debug.Assert(strInput != null);
-
- if (normalizationForm != NormalizationForm.FormC && normalizationForm != NormalizationForm.FormD &&
- normalizationForm != NormalizationForm.FormKC && normalizationForm != NormalizationForm.FormKD)
- {
- throw new ArgumentException(SR.Argument_InvalidNormalizationForm, nameof(normalizationForm));
- }
-
- if (HasInvalidUnicodeSequence(strInput))
- {
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
- }
- }
-
- /// <summary>
- /// ICU does not signal an error during normalization if the input string has invalid unicode,
- /// unlike Windows (which uses the ERROR_NO_UNICODE_TRANSLATION error value to signal an error).
- ///
- /// We walk the string ourselves looking for these bad sequences so we can continue to throw
- /// ArgumentException in these cases.
- /// </summary>
- private static bool HasInvalidUnicodeSequence(string s)
- {
- for (int i = 0; i < s.Length; i++)
- {
- char c = s[i];
-
- if (c < '\ud800')
- {
- continue;
- }
-
- if (c == '\uFFFE')
- {
- return true;
- }
-
- // If we see low surrogate before a high one, the string is invalid.
- if (char.IsLowSurrogate(c))
- {
- return true;
- }
-
- if (char.IsHighSurrogate(c))
- {
- if (i + 1 >= s.Length || !char.IsLowSurrogate(s[i + 1]))
- {
- // A high surrogate at the end of the string or a high surrogate
- // not followed by a low surrogate
- return true;
- }
- else
- {
- i++; // consume the low surrogate.
- continue;
- }
- }
- }
-
- return false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/Normalization.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/Normalization.Windows.cs
deleted file mode 100644
index e96789d1695..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/Normalization.Windows.cs
+++ /dev/null
@@ -1,148 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System.Globalization
-{
- internal static partial class Normalization
- {
- internal static bool IsNormalized(string strInput, NormalizationForm normalizationForm)
- {
- if (GlobalizationMode.Invariant)
- {
- // In Invariant mode we assume all characters are normalized.
- // This is because we don't support any linguistic operation on the strings
- return true;
- }
-
- Debug.Assert(strInput != null);
-
- // The only way to know if IsNormalizedString failed is through checking the Win32 last error
- // IsNormalizedString pinvoke has SetLastError attribute property which will set the last error
- // to 0 (ERROR_SUCCESS) before executing the calls.
- bool result = Interop.Normaliz.IsNormalizedString((int)normalizationForm, strInput, strInput.Length);
-
- int lastError = Marshal.GetLastWin32Error();
- switch (lastError)
- {
- case Interop.Errors.ERROR_SUCCESS:
- break;
-
- case Interop.Errors.ERROR_INVALID_PARAMETER:
- case Interop.Errors.ERROR_NO_UNICODE_TRANSLATION:
- if (normalizationForm != NormalizationForm.FormC &&
- normalizationForm != NormalizationForm.FormD &&
- normalizationForm != NormalizationForm.FormKC &&
- normalizationForm != NormalizationForm.FormKD)
- {
- throw new ArgumentException(SR.Argument_InvalidNormalizationForm, nameof(normalizationForm));
- }
-
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
-
- case Interop.Errors.ERROR_NOT_ENOUGH_MEMORY:
- throw new OutOfMemoryException();
-
- default:
- throw new InvalidOperationException(SR.Format(SR.UnknownError_Num, lastError));
- }
-
- return result;
- }
-
- internal static string Normalize(string strInput, NormalizationForm normalizationForm)
- {
- if (GlobalizationMode.Invariant)
- {
- // In Invariant mode we assume all characters are normalized.
- // This is because we don't support any linguistic operation on the strings
- return strInput;
- }
-
- Debug.Assert(strInput != null);
-
- // we depend on Win32 last error when calling NormalizeString
- // NormalizeString pinvoke has SetLastError attribute property which will set the last error
- // to 0 (ERROR_SUCCESS) before executing the calls.
-
- // Guess our buffer size first
- int iLength = Interop.Normaliz.NormalizeString((int)normalizationForm, strInput, strInput.Length, null, 0);
-
- int lastError = Marshal.GetLastWin32Error();
- // Could have an error (actually it'd be quite hard to have an error here)
- if ((lastError != Interop.Errors.ERROR_SUCCESS) || iLength < 0)
- {
- if (lastError == Interop.Errors.ERROR_INVALID_PARAMETER)
- {
- if (normalizationForm != NormalizationForm.FormC &&
- normalizationForm != NormalizationForm.FormD &&
- normalizationForm != NormalizationForm.FormKC &&
- normalizationForm != NormalizationForm.FormKD)
- {
- throw new ArgumentException(SR.Argument_InvalidNormalizationForm, nameof(normalizationForm));
- }
-
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
- }
-
- // We shouldn't really be able to get here..., guessing length is
- // a trivial math function...
- // Can't really be Out of Memory, but just in case:
- if (lastError == Interop.Errors.ERROR_NOT_ENOUGH_MEMORY)
- throw new OutOfMemoryException();
-
- // Who knows what happened? Not us!
- throw new InvalidOperationException(SR.Format(SR.UnknownError_Num, lastError));
- }
-
- // Don't break for empty strings (only possible for D & KD and not really possible at that)
- if (iLength == 0) return string.Empty;
-
- // Someplace to stick our buffer
- char[] cBuffer;
-
- while (true)
- {
- // (re)allocation buffer and normalize string
- cBuffer = new char[iLength];
-
- // NormalizeString pinvoke has SetLastError attribute property which will set the last error
- // to 0 (ERROR_SUCCESS) before executing the calls.
- iLength = Interop.Normaliz.NormalizeString((int)normalizationForm, strInput, strInput.Length, cBuffer, cBuffer.Length);
- lastError = Marshal.GetLastWin32Error();
-
- if (lastError == Interop.Errors.ERROR_SUCCESS)
- break;
-
- // Could have an error (actually it'd be quite hard to have an error here)
- switch (lastError)
- {
- // Do appropriate stuff for the individual errors:
- case Interop.Errors.ERROR_INSUFFICIENT_BUFFER:
- iLength = Math.Abs(iLength);
- Debug.Assert(iLength > cBuffer.Length, "Buffer overflow should have iLength > cBuffer.Length");
- continue;
-
- case Interop.Errors.ERROR_INVALID_PARAMETER:
- case Interop.Errors.ERROR_NO_UNICODE_TRANSLATION:
- // Illegal code point or order found. Ie: FFFE or D800 D800, etc.
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
-
- case Interop.Errors.ERROR_NOT_ENOUGH_MEMORY:
- throw new OutOfMemoryException();
-
- default:
- // We shouldn't get here...
- throw new InvalidOperationException(SR.Format(SR.UnknownError_Num, lastError));
- }
- }
-
- // Copy our buffer into our new string, which will be the appropriate size
- return new string(cBuffer, 0, iLength);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/NumberFormatInfo.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/NumberFormatInfo.cs
deleted file mode 100644
index d5fa16edcdc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/NumberFormatInfo.cs
+++ /dev/null
@@ -1,750 +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.
-
-namespace System.Globalization
-{
- /// <remarks>
- /// Property Default Description
- /// PositiveSign '+' Character used to indicate positive values.
- /// NegativeSign '-' Character used to indicate negative values.
- /// NumberDecimalSeparator '.' The character used as the decimal separator.
- /// NumberGroupSeparator ',' The character used to separate groups of
- /// digits to the left of the decimal point.
- /// NumberDecimalDigits 2 The default number of decimal places.
- /// NumberGroupSizes 3 The number of digits in each group to the
- /// left of the decimal point.
- /// NaNSymbol "NaN" The string used to represent NaN values.
- /// PositiveInfinitySymbol"Infinity" The string used to represent positive
- /// infinities.
- /// NegativeInfinitySymbol"-Infinity" The string used to represent negative
- /// infinities.
- ///
- /// Property Default Description
- /// CurrencyDecimalSeparator '.' The character used as the decimal
- /// separator.
- /// CurrencyGroupSeparator ',' The character used to separate groups
- /// of digits to the left of the decimal
- /// point.
- /// CurrencyDecimalDigits 2 The default number of decimal places.
- /// CurrencyGroupSizes 3 The number of digits in each group to
- /// the left of the decimal point.
- /// CurrencyPositivePattern 0 The format of positive values.
- /// CurrencyNegativePattern 0 The format of negative values.
- /// CurrencySymbol "$" String used as local monetary symbol.
- /// </remarks>
- public sealed class NumberFormatInfo : IFormatProvider, ICloneable
- {
- private static volatile NumberFormatInfo? s_invariantInfo;
-
- internal int[] _numberGroupSizes = new int[] { 3 };
- internal int[] _currencyGroupSizes = new int[] { 3 };
- internal int[] _percentGroupSizes = new int[] { 3 };
- internal string _positiveSign = "+";
- internal string _negativeSign = "-";
- internal string _numberDecimalSeparator = ".";
- internal string _numberGroupSeparator = ",";
- internal string _currencyGroupSeparator = ",";
- internal string _currencyDecimalSeparator = ".";
- internal string _currencySymbol = "\x00a4"; // U+00a4 is the symbol for International Monetary Fund.
- internal string _nanSymbol = "NaN";
- internal string _positiveInfinitySymbol = "Infinity";
- internal string _negativeInfinitySymbol = "-Infinity";
- internal string _percentDecimalSeparator = ".";
- internal string _percentGroupSeparator = ",";
- internal string _percentSymbol = "%";
- internal string _perMilleSymbol = "\u2030";
-
- internal string[] _nativeDigits = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
-
- internal int _numberDecimalDigits = 2;
- internal int _currencyDecimalDigits = 2;
- internal int _currencyPositivePattern = 0;
- internal int _currencyNegativePattern = 0;
- internal int _numberNegativePattern = 1;
- internal int _percentPositivePattern = 0;
- internal int _percentNegativePattern = 0;
- internal int _percentDecimalDigits = 2;
-
- internal int _digitSubstitution = (int)DigitShapes.None;
-
- internal bool _isReadOnly = false;
-
- private bool _hasInvariantNumberSigns = true;
-
- public NumberFormatInfo()
- {
- }
-
- private static void VerifyDecimalSeparator(string decSep, string propertyName)
- {
- if (decSep == null)
- {
- throw new ArgumentNullException(propertyName);
- }
-
- if (decSep.Length == 0)
- {
- throw new ArgumentException(SR.Argument_EmptyDecString, propertyName);
- }
- }
-
- private static void VerifyGroupSeparator(string groupSep, string propertyName)
- {
- if (groupSep == null)
- {
- throw new ArgumentNullException(propertyName);
- }
- }
-
- private static void VerifyNativeDigits(string[] nativeDig, string propertyName)
- {
- if (nativeDig == null)
- {
- throw new ArgumentNullException(propertyName, SR.ArgumentNull_Array);
- }
-
- if (nativeDig.Length != 10)
- {
- throw new ArgumentException(SR.Argument_InvalidNativeDigitCount, propertyName);
- }
-
- for (int i = 0; i < nativeDig.Length; i++)
- {
- if (nativeDig[i] == null)
- {
- throw new ArgumentNullException(propertyName, SR.ArgumentNull_ArrayValue);
- }
-
- if (nativeDig[i].Length != 1)
- {
- if (nativeDig[i].Length != 2)
- {
- // Not 1 or 2 UTF-16 code points
- throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName);
- }
- else if (!char.IsSurrogatePair(nativeDig[i][0], nativeDig[i][1]))
- {
- // 2 UTF-6 code points, but not a surrogate pair
- throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName);
- }
- }
-
- if (CharUnicodeInfo.GetDecimalDigitValue(nativeDig[i], 0) != i &&
- CharUnicodeInfo.GetUnicodeCategory(nativeDig[i], 0) != UnicodeCategory.PrivateUse)
- {
- // Not the appropriate digit according to the Unicode data properties
- // (Digit 0 must be a 0, etc.).
- throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName);
- }
- }
- }
-
- private static void VerifyDigitSubstitution(DigitShapes digitSub, string propertyName)
- {
- switch (digitSub)
- {
- case DigitShapes.Context:
- case DigitShapes.None:
- case DigitShapes.NativeNational:
- // Success.
- break;
-
- default:
- throw new ArgumentException(SR.Argument_InvalidDigitSubstitution, propertyName);
- }
- }
-
- internal bool HasInvariantNumberSigns => _hasInvariantNumberSigns;
-
- private void UpdateHasInvariantNumberSigns()
- {
- _hasInvariantNumberSigns = _positiveSign == "+" && _negativeSign == "-";
- }
-
- internal NumberFormatInfo(CultureData? cultureData)
- {
- if (cultureData != null)
- {
- // We directly use fields here since these data is coming from data table or Win32, so we
- // don't need to verify their values (except for invalid parsing situations).
- cultureData.GetNFIValues(this);
-
- UpdateHasInvariantNumberSigns();
- }
- }
-
- private void VerifyWritable()
- {
- if (_isReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- }
-
- /// <summary>
- /// Returns a default NumberFormatInfo that will be universally
- /// supported and constant irrespective of the current culture.
- /// Used by FromString methods.
- /// </summary>
- public static NumberFormatInfo InvariantInfo => s_invariantInfo ??=
- // Lazy create the invariant info. This cannot be done in a .cctor because exceptions can
- // be thrown out of a .cctor stack that will need this.
- new NumberFormatInfo { _isReadOnly = true };
-
- public static NumberFormatInfo GetInstance(IFormatProvider? formatProvider)
- {
- return formatProvider == null ?
- CurrentInfo : // Fast path for a null provider
- GetProviderNonNull(formatProvider);
-
- static NumberFormatInfo GetProviderNonNull(IFormatProvider provider)
- {
- // Fast path for a regular CultureInfo
- if (provider is CultureInfo cultureProvider && !cultureProvider._isInherited)
- {
- return cultureProvider._numInfo ?? cultureProvider.NumberFormat;
- }
-
- return
- provider as NumberFormatInfo ?? // Fast path for an NFI
- provider.GetFormat(typeof(NumberFormatInfo)) as NumberFormatInfo ??
- CurrentInfo;
- }
- }
-
- public object Clone()
- {
- NumberFormatInfo n = (NumberFormatInfo)MemberwiseClone();
- n._isReadOnly = false;
- return n;
- }
-
- public int CurrencyDecimalDigits
- {
- get => _currencyDecimalDigits;
- set
- {
- if (value < 0 || value > 99)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 0, 99));
- }
-
- VerifyWritable();
- _currencyDecimalDigits = value;
- }
- }
-
- public string CurrencyDecimalSeparator
- {
- get => _currencyDecimalSeparator;
- set
- {
- VerifyWritable();
- VerifyDecimalSeparator(value, nameof(value));
- _currencyDecimalSeparator = value;
- }
- }
-
- public bool IsReadOnly => _isReadOnly;
-
- /// <summary>
- /// Check the values of the groupSize array.
- /// Every element in the groupSize array should be between 1 and 9
- /// except the last element could be zero.
- /// </summary>
- internal static void CheckGroupSize(string propName, int[] groupSize)
- {
- for (int i = 0; i < groupSize.Length; i++)
- {
- if (groupSize[i] < 1)
- {
- if (i == groupSize.Length - 1 && groupSize[i] == 0)
- {
- return;
- }
-
- throw new ArgumentException(SR.Argument_InvalidGroupSize, propName);
- }
- else if (groupSize[i] > 9)
- {
- throw new ArgumentException(SR.Argument_InvalidGroupSize, propName);
- }
- }
- }
-
- public int[] CurrencyGroupSizes
- {
- get => (int[])_currencyGroupSizes.Clone();
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
-
- int[] inputSizes = (int[])value.Clone();
- CheckGroupSize(nameof(value), inputSizes);
- _currencyGroupSizes = inputSizes;
- }
- }
-
- public int[] NumberGroupSizes
- {
- get => (int[])_numberGroupSizes.Clone();
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
-
- int[] inputSizes = (int[])value.Clone();
- CheckGroupSize(nameof(value), inputSizes);
- _numberGroupSizes = inputSizes;
- }
- }
-
- public int[] PercentGroupSizes
- {
- get => (int[])_percentGroupSizes.Clone();
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- int[] inputSizes = (int[])value.Clone();
- CheckGroupSize(nameof(value), inputSizes);
- _percentGroupSizes = inputSizes;
- }
- }
-
- public string CurrencyGroupSeparator
- {
- get => _currencyGroupSeparator;
- set
- {
- VerifyWritable();
- VerifyGroupSeparator(value, nameof(value));
- _currencyGroupSeparator = value;
- }
- }
-
- public string CurrencySymbol
- {
- get => _currencySymbol;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- _currencySymbol = value;
- }
- }
-
- /// <summary>
- /// Returns the current culture's NumberFormatInfo. Used by Parse methods.
- /// </summary>
-
- public static NumberFormatInfo CurrentInfo
- {
- get
- {
- System.Globalization.CultureInfo culture = CultureInfo.CurrentCulture;
- if (!culture._isInherited)
- {
- NumberFormatInfo? info = culture._numInfo;
- if (info != null)
- {
- return info;
- }
- }
- // returns non-nullable when passed typeof(NumberFormatInfo)
- return (NumberFormatInfo)culture.GetFormat(typeof(NumberFormatInfo))!;
- }
- }
-
- public string NaNSymbol
- {
- get => _nanSymbol;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- _nanSymbol = value;
- }
- }
-
- public int CurrencyNegativePattern
- {
- get => _currencyNegativePattern;
- set
- {
- if (value < 0 || value > 15)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 0, 15));
- }
-
- VerifyWritable();
- _currencyNegativePattern = value;
- }
- }
-
- public int NumberNegativePattern
- {
- get => _numberNegativePattern;
- set
- {
- // NOTENOTE: the range of value should correspond to negNumberFormats[] in vm\COMNumber.cpp.
- if (value < 0 || value > 4)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 0, 4));
- }
-
- VerifyWritable();
- _numberNegativePattern = value;
- }
- }
-
- public int PercentPositivePattern
- {
- get => _percentPositivePattern;
- set
- {
- // NOTENOTE: the range of value should correspond to posPercentFormats[] in vm\COMNumber.cpp.
- if (value < 0 || value > 3)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 0, 3));
- }
-
- VerifyWritable();
- _percentPositivePattern = value;
- }
- }
-
- public int PercentNegativePattern
- {
- get => _percentNegativePattern;
- set
- {
- // NOTENOTE: the range of value should correspond to posPercentFormats[] in vm\COMNumber.cpp.
- if (value < 0 || value > 11)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 0, 11));
- }
-
- VerifyWritable();
- _percentNegativePattern = value;
- }
- }
-
- public string NegativeInfinitySymbol
- {
- get => _negativeInfinitySymbol;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- _negativeInfinitySymbol = value;
- }
- }
-
- public string NegativeSign
- {
- get => _negativeSign;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- _negativeSign = value;
- UpdateHasInvariantNumberSigns();
- }
- }
-
- public int NumberDecimalDigits
- {
- get => _numberDecimalDigits;
- set
- {
- if (value < 0 || value > 99)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 0, 99));
- }
-
- VerifyWritable();
- _numberDecimalDigits = value;
- }
- }
-
- public string NumberDecimalSeparator
- {
- get => _numberDecimalSeparator;
- set
- {
- VerifyWritable();
- VerifyDecimalSeparator(value, nameof(value));
- _numberDecimalSeparator = value;
- }
- }
-
- public string NumberGroupSeparator
- {
- get => _numberGroupSeparator;
- set
- {
- VerifyWritable();
- VerifyGroupSeparator(value, nameof(value));
- _numberGroupSeparator = value;
- }
- }
-
- public int CurrencyPositivePattern
- {
- get => _currencyPositivePattern;
- set
- {
- if (value < 0 || value > 3)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 0, 3));
- }
-
- VerifyWritable();
- _currencyPositivePattern = value;
- }
- }
-
- public string PositiveInfinitySymbol
- {
- get => _positiveInfinitySymbol;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- _positiveInfinitySymbol = value;
- }
- }
-
- public string PositiveSign
- {
- get => _positiveSign;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- _positiveSign = value;
- UpdateHasInvariantNumberSigns();
- }
- }
-
- public int PercentDecimalDigits
- {
- get => _percentDecimalDigits;
- set
- {
- if (value < 0 || value > 99)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 0, 99));
- }
-
- VerifyWritable();
- _percentDecimalDigits = value;
- }
- }
-
- public string PercentDecimalSeparator
- {
- get => _percentDecimalSeparator;
- set
- {
- VerifyWritable();
- VerifyDecimalSeparator(value, nameof(value));
- _percentDecimalSeparator = value;
- }
- }
-
- public string PercentGroupSeparator
- {
- get => _percentGroupSeparator;
- set
- {
- VerifyWritable();
- VerifyGroupSeparator(value, nameof(value));
- _percentGroupSeparator = value;
- }
- }
-
- public string PercentSymbol
- {
- get => _percentSymbol;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- _percentSymbol = value;
- }
- }
-
- public string PerMilleSymbol
- {
- get => _perMilleSymbol;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- _perMilleSymbol = value;
- }
- }
-
- public string[] NativeDigits
- {
- get => (string[])_nativeDigits.Clone();
- set
- {
- VerifyWritable();
- VerifyNativeDigits(value, nameof(value));
- _nativeDigits = value;
- }
- }
-
- public DigitShapes DigitSubstitution
- {
- get => (DigitShapes)_digitSubstitution;
- set
- {
- VerifyWritable();
- VerifyDigitSubstitution(value, nameof(value));
- _digitSubstitution = (int)value;
- }
- }
-
- public object? GetFormat(Type? formatType)
- {
- return formatType == typeof(NumberFormatInfo) ? this : null;
- }
-
- public static NumberFormatInfo ReadOnly(NumberFormatInfo nfi)
- {
- if (nfi == null)
- {
- throw new ArgumentNullException(nameof(nfi));
- }
-
- if (nfi.IsReadOnly)
- {
- return nfi;
- }
-
- NumberFormatInfo info = (NumberFormatInfo)(nfi.MemberwiseClone());
- info._isReadOnly = true;
- return info;
- }
-
- // private const NumberStyles InvalidNumberStyles = unchecked((NumberStyles) 0xFFFFFC00);
- private const NumberStyles InvalidNumberStyles = ~(NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite
- | NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingSign
- | NumberStyles.AllowParentheses | NumberStyles.AllowDecimalPoint
- | NumberStyles.AllowThousands | NumberStyles.AllowExponent
- | NumberStyles.AllowCurrencySymbol | NumberStyles.AllowHexSpecifier);
-
- internal static void ValidateParseStyleInteger(NumberStyles style)
- {
- // Check for undefined flags or invalid hex number flags
- if ((style & (InvalidNumberStyles | NumberStyles.AllowHexSpecifier)) != 0
- && (style & ~NumberStyles.HexNumber) != 0)
- {
- throwInvalid(style);
-
- void throwInvalid(NumberStyles value)
- {
- if ((value & InvalidNumberStyles) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidNumberStyles, nameof(style));
- }
-
- throw new ArgumentException(SR.Arg_InvalidHexStyle);
- }
- }
- }
-
- internal static void ValidateParseStyleFloatingPoint(NumberStyles style)
- {
- // Check for undefined flags or hex number
- if ((style & (InvalidNumberStyles | NumberStyles.AllowHexSpecifier)) != 0)
- {
- throwInvalid(style);
-
- void throwInvalid(NumberStyles value)
- {
- if ((value & InvalidNumberStyles) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidNumberStyles, nameof(style));
- }
-
- throw new ArgumentException(SR.Arg_HexStyleNotSupported);
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/NumberStyles.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/NumberStyles.cs
deleted file mode 100644
index cf5a081016a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/NumberStyles.cs
+++ /dev/null
@@ -1,70 +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.
-
-namespace System.Globalization
-{
- /// <summary>
- /// Contains valid formats for Numbers recognized by the Number
- /// class' parsing code.
- /// </summary>
- [Flags]
- public enum NumberStyles
- {
- None = 0x00000000,
-
- /// <summary>
- /// Bit flag indicating that leading whitespace is allowed. Character values
- /// 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, and 0x0020 are considered to be
- /// whitespace.
- /// </summary>
- AllowLeadingWhite = 0x00000001,
-
- /// <summary>
- /// Bitflag indicating trailing whitespace is allowed.
- /// </summary>
- AllowTrailingWhite = 0x00000002,
-
- /// <summary>
- /// Can the number start with a sign char specified by
- /// NumberFormatInfo.PositiveSign and NumberFormatInfo.NegativeSign
- /// </summary>
- AllowLeadingSign = 0x00000004,
-
- /// <summary>
- /// Allow the number to end with a sign char
- /// </summary>
- AllowTrailingSign = 0x00000008,
-
- /// <summary>
- /// Allow the number to be enclosed in parens
- /// </summary>
- AllowParentheses = 0x00000010,
-
- AllowDecimalPoint = 0x00000020,
-
- AllowThousands = 0x00000040,
-
- AllowExponent = 0x00000080,
-
- AllowCurrencySymbol = 0x00000100,
-
- AllowHexSpecifier = 0x00000200,
-
- Integer = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign,
-
- HexNumber = AllowLeadingWhite | AllowTrailingWhite | AllowHexSpecifier,
-
- Number = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign | AllowTrailingSign |
- AllowDecimalPoint | AllowThousands,
-
- Float = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign |
- AllowDecimalPoint | AllowExponent,
-
- Currency = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign | AllowTrailingSign |
- AllowParentheses | AllowDecimalPoint | AllowThousands | AllowCurrencySymbol,
-
- Any = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign | AllowTrailingSign |
- AllowParentheses | AllowDecimalPoint | AllowThousands | AllowCurrencySymbol | AllowExponent,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/PersianCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/PersianCalendar.cs
deleted file mode 100644
index 40268efb18d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/PersianCalendar.cs
+++ /dev/null
@@ -1,418 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- /// <summary>
- /// Modern Persian calendar is a solar observation based calendar. Each new year begins on the day when the vernal equinox occurs before noon.
- /// The epoch is the date of the vernal equinox prior to the epoch of the Islamic calendar (March 19, 622 Julian or March 22, 622 Gregorian)
- /// There is no Persian year 0. Ordinary years have 365 days. Leap years have 366 days with the last month (Esfand) gaining the extra day.
- /// </summary>
- /// <remarks>
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 0622/03/22 9999/12/31
- /// Persian 0001/01/01 9378/10/13
- /// </remarks>
- public class PersianCalendar : Calendar
- {
- public static readonly int PersianEra = 1;
-
- private static readonly long s_persianEpoch = new DateTime(622, 3, 22).Ticks / GregorianCalendar.TicksPerDay;
- private const int ApproximateHalfYear = 180;
-
- private const int DatePartYear = 0;
- private const int DatePartDayOfYear = 1;
- private const int DatePartMonth = 2;
- private const int DatePartDay = 3;
- private const int MonthsPerYear = 12;
-
- private static readonly int[] s_daysToMonth = { 0, 31, 62, 93, 124, 155, 186, 216, 246, 276, 306, 336, 366 };
-
- private const int MaxCalendarYear = 9378;
- private const int MaxCalendarMonth = 10;
- private const int MaxCalendarDay = 13;
-
- // Persian calendar (year: 1, month: 1, day:1 ) = Gregorian (year: 622, month: 3, day: 22)
- // This is the minimal Gregorian date that we support in the PersianCalendar.
- private static readonly DateTime s_minDate = new DateTime(622, 3, 22);
- private static readonly DateTime s_maxDate = DateTime.MaxValue;
-
- public override DateTime MinSupportedDateTime => s_minDate;
-
- public override DateTime MaxSupportedDateTime => s_maxDate;
-
- public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.SolarCalendar;
-
- public PersianCalendar()
- {
- }
-
- internal override CalendarId BaseCalendarID => CalendarId.GREGORIAN;
-
- internal override CalendarId ID => CalendarId.PERSIAN;
-
- private long GetAbsoluteDatePersian(int year, int month, int day)
- {
- if (year < 1 || year > MaxCalendarYear || month < 1 || month > 12)
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay);
- }
-
- // day is one based, make 0 based since this will be the number of days we add to beginning of year below
- int ordinalDay = DaysInPreviousMonths(month) + day - 1;
- int approximateDaysFromEpochForYearStart = (int)(CalendricalCalculationsHelper.MeanTropicalYearInDays * (year - 1));
- long yearStart = CalendricalCalculationsHelper.PersianNewYearOnOrBefore(s_persianEpoch + approximateDaysFromEpochForYearStart + ApproximateHalfYear);
- yearStart += ordinalDay;
- return yearStart;
- }
-
- internal static void CheckTicksRange(long ticks)
- {
- if (ticks < s_minDate.Ticks || ticks > s_maxDate.Ticks)
- {
- throw new ArgumentOutOfRangeException(
- "time",
- ticks,
- SR.Format(SR.ArgumentOutOfRange_CalendarRange, s_minDate, s_maxDate));
- }
- }
-
- internal static void CheckEraRange(int era)
- {
- if (era != CurrentEra && era != PersianEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- }
-
- internal static void CheckYearRange(int year, int era)
- {
- CheckEraRange(era);
- if (year < 1 || year > MaxCalendarYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxCalendarYear));
- }
- }
-
- internal static void CheckYearMonthRange(int year, int month, int era)
- {
- CheckYearRange(year, era);
- if (year == MaxCalendarYear)
- {
- if (month > MaxCalendarMonth)
- {
- throw new ArgumentOutOfRangeException(
- nameof(month),
- month,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxCalendarMonth));
- }
- }
-
- if (month < 1 || month > 12)
- {
- throw new ArgumentOutOfRangeException(nameof(month), month, SR.ArgumentOutOfRange_Month);
- }
- }
-
- private static int MonthFromOrdinalDay(int ordinalDay)
- {
- Debug.Assert(ordinalDay <= 366);
- int index = 0;
- while (ordinalDay > s_daysToMonth[index])
- {
- index++;
- }
-
- return index;
- }
-
- private static int DaysInPreviousMonths(int month)
- {
- Debug.Assert(1 <= month && month <= 12);
- // months are one based but for calculations use 0 based
- --month;
- return s_daysToMonth[month];
- }
-
- internal int GetDatePart(long ticks, int part)
- {
- CheckTicksRange(ticks);
-
- // Get the absolute date. The absolute date is the number of days from January 1st, 1 A.D.
- // 1/1/0001 is absolute date 1.
- long numDays = ticks / GregorianCalendar.TicksPerDay + 1;
-
- // Calculate the appromixate Persian Year.
- long yearStart = CalendricalCalculationsHelper.PersianNewYearOnOrBefore(numDays);
- int y = (int)(Math.Floor(((yearStart - s_persianEpoch) / CalendricalCalculationsHelper.MeanTropicalYearInDays) + 0.5)) + 1;
- Debug.Assert(y >= 1);
-
- if (part == DatePartYear)
- {
- return y;
- }
-
- // Calculate the Persian Month.
- int ordinalDay = (int)(numDays - CalendricalCalculationsHelper.GetNumberOfDays(this.ToDateTime(y, 1, 1, 0, 0, 0, 0, 1)));
- if (part == DatePartDayOfYear)
- {
- return ordinalDay;
- }
-
- int m = MonthFromOrdinalDay(ordinalDay);
- Debug.Assert(ordinalDay >= 1);
- Debug.Assert(m >= 1 && m <= 12);
- if (part == DatePartMonth)
- {
- return m;
- }
-
- int d = ordinalDay - DaysInPreviousMonths(m);
- Debug.Assert(1 <= d);
- Debug.Assert(d <= 31);
-
- // Calculate the Persian Day.
- if (part == DatePartDay)
- {
- return d;
- }
-
- // Incorrect part value.
- throw new InvalidOperationException(SR.InvalidOperation_DateTimeParsing);
- }
-
- public override DateTime AddMonths(DateTime time, int months)
- {
- if (months < -120000 || months > 120000)
- {
- throw new ArgumentOutOfRangeException(
- nameof(months),
- months,
- SR.Format(SR.ArgumentOutOfRange_Range, -120000, 120000));
- }
-
- // Get the date in Persian calendar.
- int y = GetDatePart(time.Ticks, DatePartYear);
- int m = GetDatePart(time.Ticks, DatePartMonth);
- int d = GetDatePart(time.Ticks, DatePartDay);
- int i = m - 1 + months;
- if (i >= 0)
- {
- m = i % 12 + 1;
- y += i / 12;
- }
- else
- {
- m = 12 + (i + 1) % 12;
- y += (i - 11) / 12;
- }
- int days = GetDaysInMonth(y, m);
- if (d > days)
- {
- d = days;
- }
-
- long ticks = GetAbsoluteDatePersian(y, m, d) * TicksPerDay + time.Ticks % TicksPerDay;
- Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
- return new DateTime(ticks);
- }
-
- public override DateTime AddYears(DateTime time, int years)
- {
- return AddMonths(time, years * 12);
- }
-
- public override int GetDayOfMonth(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartDay);
- }
-
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
- return (DayOfWeek)((int)(time.Ticks / TicksPerDay + 1) % 7);
- }
-
- public override int GetDayOfYear(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartDayOfYear);
- }
-
- public override int GetDaysInMonth(int year, int month, int era)
- {
- CheckYearMonthRange(year, month, era);
-
- if ((month == MaxCalendarMonth) && (year == MaxCalendarYear))
- {
- return MaxCalendarDay;
- }
-
- int daysInMonth = s_daysToMonth[month] - s_daysToMonth[month - 1];
- if ((month == MonthsPerYear) && !IsLeapYear(year))
- {
- Debug.Assert(daysInMonth == 30);
- --daysInMonth;
- }
-
- return daysInMonth;
- }
-
- public override int GetDaysInYear(int year, int era)
- {
- CheckYearRange(year, era);
- if (year == MaxCalendarYear)
- {
- return s_daysToMonth[MaxCalendarMonth - 1] + MaxCalendarDay;
- }
-
- return IsLeapYear(year, CurrentEra) ? 366 : 365;
- }
-
- public override int GetEra(DateTime time)
- {
- CheckTicksRange(time.Ticks);
- return PersianEra;
- }
-
- public override int[] Eras => new int[] { PersianEra };
-
- public override int GetMonth(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartMonth);
- }
-
- public override int GetMonthsInYear(int year, int era)
- {
- CheckYearRange(year, era);
- if (year == MaxCalendarYear)
- {
- return MaxCalendarMonth;
- }
-
- return 12;
- }
-
- public override int GetYear(DateTime time)
- {
- return GetDatePart(time.Ticks, DatePartYear);
- }
-
- public override bool IsLeapDay(int year, int month, int day, int era)
- {
- // The year/month/era value checking is done in GetDaysInMonth().
- int daysInMonth = GetDaysInMonth(year, month, era);
- if (day < 1 || day > daysInMonth)
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- day,
- SR.Format(SR.ArgumentOutOfRange_Day, daysInMonth, month));
- }
-
- return IsLeapYear(year, era) && month == 12 && day == 30;
- }
-
- public override int GetLeapMonth(int year, int era)
- {
- CheckYearRange(year, era);
- return 0;
- }
-
- public override bool IsLeapMonth(int year, int month, int era)
- {
- CheckYearMonthRange(year, month, era);
- return false;
- }
-
- public override bool IsLeapYear(int year, int era)
- {
- CheckYearRange(year, era);
-
- if (year == MaxCalendarYear)
- {
- return false;
- }
-
- return (GetAbsoluteDatePersian(year + 1, 1, 1) - GetAbsoluteDatePersian(year, 1, 1)) == 366;
- }
-
- public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- // The year/month/era checking is done in GetDaysInMonth().
- int daysInMonth = GetDaysInMonth(year, month, era);
- if (day < 1 || day > daysInMonth)
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- day,
- SR.Format(SR.ArgumentOutOfRange_Day, daysInMonth, month));
- }
-
- long lDate = GetAbsoluteDatePersian(year, month, day);
-
- if (lDate < 0)
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay);
- }
-
- return new DateTime(lDate * GregorianCalendar.TicksPerDay + TimeToTicks(hour, minute, second, millisecond));
- }
-
- private const int DefaultTwoDigitYearMax = 1410;
-
- public override int TwoDigitYearMax
- {
- get
- {
- if (_twoDigitYearMax == -1)
- {
- _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultTwoDigitYearMax);
- }
-
- return _twoDigitYearMax;
- }
- set
- {
- VerifyWritable();
- if (value < 99 || value > MaxCalendarYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 99, MaxCalendarYear));
- }
-
- _twoDigitYearMax = value;
- }
- }
-
- public override int ToFourDigitYear(int year)
- {
- if (year < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (year < 100)
- {
- return base.ToFourDigitYear(year);
- }
-
- if (year > MaxCalendarYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, MaxCalendarYear));
- }
-
- return year;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/RegionInfo.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/RegionInfo.cs
deleted file mode 100644
index ccaa806adb6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/RegionInfo.cs
+++ /dev/null
@@ -1,198 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- /// <summary>
- /// This class represents settings specified by de jure or de facto
- /// standards for a particular country/region. In contrast to
- /// CultureInfo, the RegionInfo does not represent preferences of the
- /// user and does not depend on the user's language or culture.
- /// </summary>
- public class RegionInfo
- {
- // Name of this region (ie: es-US): serialized, the field used for deserialization
- private string _name;
-
- // The CultureData instance that we are going to read data from.
- private readonly CultureData _cultureData;
-
- // The RegionInfo for our current region
- internal static volatile RegionInfo? s_currentRegionInfo;
-
- public RegionInfo(string name)
- {
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- // The InvariantCulture has no matching region
- if (name.Length == 0)
- {
- throw new ArgumentException(SR.Argument_NoRegionInvariantCulture, nameof(name));
- }
-
- // For CoreCLR we only want the region names that are full culture names
- _cultureData = CultureData.GetCultureDataForRegion(name, true) ??
- throw new ArgumentException(SR.Format(SR.Argument_InvalidCultureName, name), nameof(name));
-
- // Not supposed to be neutral
- if (_cultureData.IsNeutralCulture)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidNeutralRegionName, name), nameof(name));
- }
-
- _name = _cultureData.RegionName;
- }
-
- public RegionInfo(int culture)
- {
- // The InvariantCulture has no matching region
- if (culture == CultureInfo.LOCALE_INVARIANT)
- {
- throw new ArgumentException(SR.Argument_NoRegionInvariantCulture);
- }
-
- if (culture == CultureInfo.LOCALE_NEUTRAL)
- {
- // Not supposed to be neutral
- throw new ArgumentException(SR.Format(SR.Argument_CultureIsNeutral, culture), nameof(culture));
- }
-
- if (culture == CultureInfo.LOCALE_CUSTOM_DEFAULT)
- {
- // Not supposed to be neutral
- throw new ArgumentException(SR.Format(SR.Argument_CustomCultureCannotBePassedByNumber, culture), nameof(culture));
- }
-
- _cultureData = CultureData.GetCultureData(culture, true);
- _name = _cultureData.RegionName;
-
- if (_cultureData.IsNeutralCulture)
- {
- // Not supposed to be neutral
- throw new ArgumentException(SR.Format(SR.Argument_CultureIsNeutral, culture), nameof(culture));
- }
- }
-
- internal RegionInfo(CultureData cultureData)
- {
- _cultureData = cultureData;
- _name = _cultureData.RegionName;
- }
-
- /// <summary>
- /// This instance provides methods based on the current user settings.
- /// These settings are volatile and may change over the lifetime of the
- /// </summary>
- public static RegionInfo CurrentRegion
- {
- get
- {
- RegionInfo? temp = s_currentRegionInfo;
- if (temp == null)
- {
- temp = new RegionInfo(CultureInfo.CurrentCulture._cultureData);
-
- // Need full name for custom cultures
- temp._name = temp._cultureData.RegionName;
- s_currentRegionInfo = temp;
- }
- return temp;
- }
- }
-
- /// <summary>
- /// Returns the name of the region (ie: en-US)
- /// </summary>
- public virtual string Name
- {
- get
- {
- Debug.Assert(_name != null, "Expected RegionInfo._name to be populated already");
- return _name;
- }
- }
-
- /// <summary>
- /// Returns the name of the region in English. (ie: United States)
- /// </summary>
- public virtual string EnglishName => _cultureData.EnglishCountryName;
-
- /// <summary>
- /// Returns the display name (localized) of the region. (ie: United States
- /// if the current UI language is en-US)
- /// </summary>
- public virtual string DisplayName => _cultureData.LocalizedCountryName;
-
- /// <summary>
- /// Returns the native name of the region. (ie: Deutschland)
- /// WARNING: You need a full locale name for this to make sense.
- /// </summary>
- public virtual string NativeName => _cultureData.NativeCountryName;
-
- /// <summary>
- /// Returns the two letter ISO region name (ie: US)
- /// </summary>
- public virtual string TwoLetterISORegionName => _cultureData.TwoLetterISOCountryName;
-
- /// <summary>
- /// Returns the three letter ISO region name (ie: USA)
- /// </summary>
- public virtual string ThreeLetterISORegionName => _cultureData.ThreeLetterISOCountryName;
-
- /// <summary>
- /// Returns the three letter windows region name (ie: USA)
- /// </summary>
- public virtual string ThreeLetterWindowsRegionName => ThreeLetterISORegionName;
-
-
- /// <summary>
- /// Returns true if this region uses the metric measurement system
- /// </summary>
- public virtual bool IsMetric => _cultureData.MeasurementSystem == 0;
-
- public virtual int GeoId => _cultureData.GeoId;
-
- /// <summary>
- /// English name for this region's currency, ie: Swiss Franc
- /// </summary>
- public virtual string CurrencyEnglishName => _cultureData.CurrencyEnglishName;
-
- /// <summary>
- /// Native name for this region's currency, ie: Schweizer Franken
- /// WARNING: You need a full locale name for this to make sense.
- /// </summary>
- public virtual string CurrencyNativeName => _cultureData.CurrencyNativeName;
-
- /// <summary>
- /// Currency Symbol for this locale, ie: Fr. or $
- /// </summary>
- public virtual string CurrencySymbol => _cultureData.CurrencySymbol;
-
- /// <summary>
- /// ISO Currency Symbol for this locale, ie: CHF
- /// </summary>
- public virtual string ISOCurrencySymbol => _cultureData.ISOCurrencySymbol;
-
- /// <summary>
- /// Implements Object.Equals(). Returns a boolean indicating whether
- /// or not object refers to the same RegionInfo as the current instance.
- /// RegionInfos are considered equal if and only if they have the same name
- /// (ie: en-US)
- /// </summary>
- public override bool Equals(object? value)
- {
- return value is RegionInfo otherRegion
- && Name.Equals(otherRegion.Name);
- }
-
- public override int GetHashCode() => Name.GetHashCode();
-
- public override string ToString() => Name;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/SortKey.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/SortKey.cs
deleted file mode 100644
index b69cf9f5513..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/SortKey.cs
+++ /dev/null
@@ -1,110 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- /// <summary>
- /// This class implements a set of methods for retrieving
- /// </summary>
- public partial class SortKey
- {
- private readonly string _localeName;
- private readonly CompareOptions _options;
- private readonly string _string;
- private readonly byte[] _keyData;
-
- /// <summary>
- /// The following constructor is designed to be called from CompareInfo to get the
- /// the sort key of specific string for synthetic culture
- /// </summary>
- internal SortKey(string localeName, string str, CompareOptions options, byte[] keyData)
- {
- _keyData = keyData;
- _localeName = localeName;
- _options = options;
- _string = str;
- }
-
- /// <summary>
- /// Returns the original string used to create the current instance
- /// of SortKey.
- /// </summary>
- public virtual string OriginalString => _string;
-
- /// <summary>
- /// Returns a byte array representing the current instance of the
- /// sort key.
- /// </summary>
- public virtual byte[] KeyData => (byte[])_keyData.Clone();
-
- /// <summary>
- /// Compares the two sort keys. Returns 0 if the two sort keys are
- /// equal, a number less than 0 if sortkey1 is less than sortkey2,
- /// and a number greater than 0 if sortkey1 is greater than sortkey2.
- /// </summary>
- public static int Compare(SortKey sortkey1, SortKey sortkey2)
- {
- if (sortkey1 == null)
- {
- throw new ArgumentNullException(nameof(sortkey1));
- }
- if (sortkey2 == null)
- {
- throw new ArgumentNullException(nameof(sortkey2));
- }
-
- byte[] key1Data = sortkey1._keyData;
- byte[] key2Data = sortkey2._keyData;
-
- Debug.Assert(key1Data != null, "key1Data != null");
- Debug.Assert(key2Data != null, "key2Data != null");
-
- if (key1Data.Length == 0)
- {
- if (key2Data.Length == 0)
- {
- return 0;
- }
-
- return -1;
- }
- if (key2Data.Length == 0)
- {
- return 1;
- }
-
- int compLen = (key1Data.Length < key2Data.Length) ? key1Data.Length : key2Data.Length;
- for (int i = 0; i < compLen; i++)
- {
- if (key1Data[i] > key2Data[i])
- {
- return 1;
- }
- if (key1Data[i] < key2Data[i])
- {
- return -1;
- }
- }
-
- return 0;
- }
-
- public override bool Equals(object? value)
- {
- return value is SortKey otherSortKey && Compare(this, otherSortKey) == 0;
- }
-
- public override int GetHashCode()
- {
- return CompareInfo.GetCompareInfo(_localeName).GetHashCodeOfString(_string, _options);
- }
-
- public override string ToString()
- {
- return "SortKey - " + _localeName + ", " + _options + ", " + _string;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/SortVersion.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/SortVersion.cs
deleted file mode 100644
index 2cac2389d9f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/SortVersion.cs
+++ /dev/null
@@ -1,83 +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 System.Runtime.CompilerServices;
-
-namespace System.Globalization
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class SortVersion :
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- IEquatable<SortVersion>
-#nullable restore
- {
- private readonly int m_NlsVersion; // Do not rename (binary serialization)
- private Guid m_SortId; // Do not rename (binary serialization)
-
- public int FullVersion => m_NlsVersion;
-
- public Guid SortId => m_SortId;
-
- public SortVersion(int fullVersion, Guid sortId)
- {
- m_SortId = sortId;
- m_NlsVersion = fullVersion;
- }
-
- internal SortVersion(int nlsVersion, int effectiveId, Guid customVersion)
- {
- m_NlsVersion = nlsVersion;
-
- if (customVersion == Guid.Empty)
- {
- byte b1 = (byte)(effectiveId >> 24);
- byte b2 = (byte)((effectiveId & 0x00FF0000) >> 16);
- byte b3 = (byte)((effectiveId & 0x0000FF00) >> 8);
- byte b4 = (byte)(effectiveId & 0xFF);
- customVersion = new Guid(0, 0, 0, 0, 0, 0, 0, b1, b2, b3, b4);
- }
-
- m_SortId = customVersion;
- }
-
- public override bool Equals(object? obj)
- {
- return obj is SortVersion otherVersion && Equals(otherVersion);
- }
-
- public bool Equals(SortVersion? other)
- {
- if (other == null)
- {
- return false;
- }
-
- return m_NlsVersion == other.m_NlsVersion && m_SortId == other.m_SortId;
- }
-
- public override int GetHashCode()
- {
- return m_NlsVersion * 7 | m_SortId.GetHashCode();
- }
-
- // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(SortVersion? left, SortVersion? right)
- {
- // Test "right" first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (right is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (left is null) ? true : false;
- }
-
- return right.Equals(left);
- }
-
- public static bool operator !=(SortVersion? left, SortVersion? right) =>
- !(left == right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/StringInfo.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/StringInfo.cs
deleted file mode 100644
index f82d3f618c1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/StringInfo.cs
+++ /dev/null
@@ -1,296 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- /// <summary>
- /// This class defines behaviors specific to a writing system.
- /// A writing system is the collection of scripts and orthographic rules
- /// required to represent a language as text.
- /// </summary>
- public class StringInfo
- {
- private string _str = null!; // initialized in helper called by ctors
-
- private int[]? _indexes;
-
- public StringInfo() : this(string.Empty)
- {
- }
-
- public StringInfo(string value)
- {
- this.String = value;
- }
-
- public override bool Equals(object? value)
- {
- return value is StringInfo otherStringInfo
- && _str.Equals(otherStringInfo._str);
- }
-
- public override int GetHashCode() => _str.GetHashCode();
-
- /// <summary>
- /// Our zero-based array of index values into the string. Initialize if
- /// our private array is not yet, in fact, initialized.
- /// </summary>
- private int[]? Indexes
- {
- get
- {
- if (_indexes == null && String.Length > 0)
- {
- _indexes = StringInfo.ParseCombiningCharacters(String);
- }
-
- return _indexes;
- }
- }
-
- public string String
- {
- get => _str;
- set
- {
- _str = value ?? throw new ArgumentNullException(nameof(value));
- _indexes = null;
- }
- }
-
- public int LengthInTextElements => Indexes?.Length ?? 0;
-
- public string SubstringByTextElements(int startingTextElement)
- {
- // If the string is empty, no sense going further.
- if (Indexes == null)
- {
- if (startingTextElement < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startingTextElement), startingTextElement, SR.ArgumentOutOfRange_NeedPosNum);
- }
- else
- {
- throw new ArgumentOutOfRangeException(nameof(startingTextElement), startingTextElement, SR.Arg_ArgumentOutOfRangeException);
- }
- }
-
- return SubstringByTextElements(startingTextElement, Indexes.Length - startingTextElement);
- }
-
- public string SubstringByTextElements(int startingTextElement, int lengthInTextElements)
- {
- if (startingTextElement < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startingTextElement), startingTextElement, SR.ArgumentOutOfRange_NeedPosNum);
- }
- if (String.Length == 0 || startingTextElement >= Indexes!.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(startingTextElement), startingTextElement, SR.Arg_ArgumentOutOfRangeException);
- }
- if (lengthInTextElements < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(lengthInTextElements), lengthInTextElements, SR.ArgumentOutOfRange_NeedPosNum);
- }
- if (startingTextElement > Indexes.Length - lengthInTextElements)
- {
- throw new ArgumentOutOfRangeException(nameof(lengthInTextElements), lengthInTextElements, SR.Arg_ArgumentOutOfRangeException);
- }
-
- int start = Indexes[startingTextElement];
-
- if (startingTextElement + lengthInTextElements == Indexes.Length)
- {
- // We are at the last text element in the string and because of that
- // must handle the call differently.
- return String.Substring(start);
- }
- else
- {
- return String[start..Indexes[lengthInTextElements + startingTextElement]];
- }
- }
-
- public static string GetNextTextElement(string str) => GetNextTextElement(str, 0);
-
- /// <summary>
- /// Get the code point count of the current text element.
- ///
- /// A combining class is defined as:
- /// A character/surrogate that has the following Unicode category:
- /// * NonSpacingMark (e.g. U+0300 COMBINING GRAVE ACCENT)
- /// * SpacingCombiningMark (e.g. U+ 0903 DEVANGARI SIGN VISARGA)
- /// * EnclosingMark (e.g. U+20DD COMBINING ENCLOSING CIRCLE)
- ///
- /// In the context of GetNextTextElement() and ParseCombiningCharacters(), a text element is defined as:
- /// 1. If a character/surrogate is in the following category, it is a text element.
- /// It can NOT further combine with characters in the combinging class to form a text element.
- /// * one of the Unicode category in the combinging class
- /// * UnicodeCategory.Format
- /// * UnicodeCateogry.Control
- /// * UnicodeCategory.OtherNotAssigned
- /// 2. Otherwise, the character/surrogate can be combined with characters in the combinging class to form a text element.
- /// </summary>
- /// <returns>The length of the current text element</returns>
- internal static int GetCurrentTextElementLen(string str, int index, int len, ref UnicodeCategory ucCurrent, ref int currentCharCount)
- {
- Debug.Assert(index >= 0 && len >= 0, "StringInfo.GetCurrentTextElementLen() : index = " + index + ", len = " + len);
- Debug.Assert(index < len, "StringInfo.GetCurrentTextElementLen() : index = " + index + ", len = " + len);
- if (index + currentCharCount == len)
- {
- // This is the last character/surrogate in the string.
- return currentCharCount;
- }
-
- // Call an internal GetUnicodeCategory, which will tell us both the unicode category, and also tell us if it is a surrogate pair or not.
- int nextCharCount;
- UnicodeCategory ucNext = CharUnicodeInfo.InternalGetUnicodeCategory(str, index + currentCharCount, out nextCharCount);
- if (CharUnicodeInfo.IsCombiningCategory(ucNext))
- {
- // The next element is a combining class.
- // Check if the current text element to see if it is a valid base category (i.e. it should not be a combining category,
- // not a format character, and not a control character).
- if (CharUnicodeInfo.IsCombiningCategory(ucCurrent)
- || (ucCurrent == UnicodeCategory.Format)
- || (ucCurrent == UnicodeCategory.Control)
- || (ucCurrent == UnicodeCategory.OtherNotAssigned)
- || (ucCurrent == UnicodeCategory.Surrogate)) // An unpair high surrogate or low surrogate
- {
- // Will fall thru and return the currentCharCount
- }
- else
- {
- // Remember the current index.
- int startIndex = index;
-
- // We have a valid base characters, and we have a character (or surrogate) that is combining.
- // Check if there are more combining characters to follow.
- // Check if the next character is a nonspacing character.
- index += currentCharCount + nextCharCount;
-
- while (index < len)
- {
- ucNext = CharUnicodeInfo.InternalGetUnicodeCategory(str, index, out nextCharCount);
- if (!CharUnicodeInfo.IsCombiningCategory(ucNext))
- {
- ucCurrent = ucNext;
- currentCharCount = nextCharCount;
- break;
- }
- index += nextCharCount;
- }
-
- return index - startIndex;
- }
- }
-
- // The return value will be the currentCharCount.
- int ret = currentCharCount;
- ucCurrent = ucNext;
- // Update currentCharCount.
- currentCharCount = nextCharCount;
- return ret;
- }
-
- /// <summary>
- /// Returns the str containing the next text element in str starting at
- /// index index. If index is not supplied, then it will start at the beginning
- /// of str. It recognizes a base character plus one or more combining
- /// characters or a properly formed surrogate pair as a text element.
- /// See also the ParseCombiningCharacters() and the ParseSurrogates() methods.
- /// </summary>
- public static string GetNextTextElement(string str, int index)
- {
- if (str == null)
- {
- throw new ArgumentNullException(nameof(str));
- }
-
- int len = str.Length;
- if (index < 0 || index >= len)
- {
- if (index == len)
- {
- return string.Empty;
- }
-
- throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index);
- }
-
- int charLen;
- UnicodeCategory uc = CharUnicodeInfo.InternalGetUnicodeCategory(str, index, out charLen);
- return str.Substring(index, GetCurrentTextElementLen(str, index, len, ref uc, ref charLen));
- }
-
- public static TextElementEnumerator GetTextElementEnumerator(string str)
- {
- return GetTextElementEnumerator(str, 0);
- }
-
- public static TextElementEnumerator GetTextElementEnumerator(string str, int index)
- {
- if (str == null)
- {
- throw new ArgumentNullException(nameof(str));
- }
-
- int len = str.Length;
- if (index < 0 || index > len)
- {
- throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index);
- }
-
- return new TextElementEnumerator(str, index, len);
- }
-
- /// <summary>
- /// Returns the indices of each base character or properly formed surrogate
- /// pair within the str. It recognizes a base character plus one or more
- /// combining characters or a properly formed surrogate pair as a text
- /// element and returns the index of the base character or high surrogate.
- /// Each index is the beginning of a text element within a str. The length
- /// of each element is easily computed as the difference between successive
- /// indices. The length of the array will always be less than or equal to
- /// the length of the str. For example, given the str
- /// \u4f00\u302a\ud800\udc00\u4f01, this method would return the indices:
- /// 0, 2, 4.
- /// </summary>
- public static int[] ParseCombiningCharacters(string str)
- {
- if (str == null)
- {
- throw new ArgumentNullException(nameof(str));
- }
-
- int len = str.Length;
- int[] result = new int[len];
- if (len == 0)
- {
- return result;
- }
-
- int resultCount = 0;
-
- int i = 0;
- int currentCharLen;
- UnicodeCategory currentCategory = CharUnicodeInfo.InternalGetUnicodeCategory(str, 0, out currentCharLen);
-
- while (i < len)
- {
- result[resultCount++] = i;
- i += GetCurrentTextElementLen(str, i, len, ref currentCategory, ref currentCharLen);
- }
-
- if (resultCount < len)
- {
- int[] returnArray = new int[resultCount];
- Array.Copy(result, returnArray, resultCount);
- return returnArray;
- }
- return result;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanCalendar.cs
deleted file mode 100644
index 03003826dfa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanCalendar.cs
+++ /dev/null
@@ -1,198 +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.
-
-namespace System.Globalization
-{
- /// <summary>
- /// Taiwan calendar is based on the Gregorian calendar. And the year is an offset to Gregorian calendar.
- /// That is,
- /// Taiwan year = Gregorian year - 1911. So 1912/01/01 A.D. is Taiwan 1/01/01
- /// </summary>
- /// <remarks>
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 1912/01/01 9999/12/31
- /// Taiwan 01/01/01 8088/12/31
- /// </remarks>
- public class TaiwanCalendar : Calendar
- {
- // Since
- // Gregorian Year = Era Year + yearOffset
- // When Gregorian Year 1912 is year 1, so that
- // 1912 = 1 + yearOffset
- // So yearOffset = 1911
- private static readonly EraInfo[] s_taiwanEraInfo = new EraInfo[]
- {
- new EraInfo(1, 1912, 1, 1, 1911, 1, GregorianCalendar.MaxYear - 1911) // era #, start year/month/day, yearOffset, minEraYear
- };
-
- private static volatile Calendar? s_defaultInstance;
-
- private readonly GregorianCalendarHelper _helper;
-
- internal static Calendar GetDefaultInstance() => s_defaultInstance ??= new TaiwanCalendar();
-
- private static readonly DateTime s_calendarMinValue = new DateTime(1912, 1, 1);
-
- public override DateTime MinSupportedDateTime => s_calendarMinValue;
-
- public override DateTime MaxSupportedDateTime => DateTime.MaxValue;
-
- public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.SolarCalendar;
-
- public TaiwanCalendar()
- {
- try
- {
- new CultureInfo("zh-TW");
- }
- catch (ArgumentException e)
- {
- throw new TypeInitializationException(GetType().ToString(), e);
- }
-
- _helper = new GregorianCalendarHelper(this, s_taiwanEraInfo);
- }
-
- internal override CalendarId ID => CalendarId.TAIWAN;
-
- public override DateTime AddMonths(DateTime time, int months)
- {
- return _helper.AddMonths(time, months);
- }
-
- public override DateTime AddYears(DateTime time, int years)
- {
- return _helper.AddYears(time, years);
- }
-
- public override int GetDaysInMonth(int year, int month, int era)
- {
- return _helper.GetDaysInMonth(year, month, era);
- }
-
- public override int GetDaysInYear(int year, int era)
- {
- return _helper.GetDaysInYear(year, era);
- }
-
- public override int GetDayOfMonth(DateTime time)
- {
- return _helper.GetDayOfMonth(time);
- }
-
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
- return _helper.GetDayOfWeek(time);
- }
-
- public override int GetDayOfYear(DateTime time)
- {
- return _helper.GetDayOfYear(time);
- }
-
- public override int GetMonthsInYear(int year, int era)
- {
- return _helper.GetMonthsInYear(year, era);
- }
-
- public override int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
- {
- return _helper.GetWeekOfYear(time, rule, firstDayOfWeek);
- }
-
- public override int GetEra(DateTime time)
- {
- return _helper.GetEra(time);
- }
-
- public override int GetMonth(DateTime time)
- {
- return _helper.GetMonth(time);
- }
-
- public override int GetYear(DateTime time)
- {
- return _helper.GetYear(time);
- }
-
- public override bool IsLeapDay(int year, int month, int day, int era)
- {
- return _helper.IsLeapDay(year, month, day, era);
- }
-
- public override bool IsLeapYear(int year, int era)
- {
- return _helper.IsLeapYear(year, era);
- }
-
- public override int GetLeapMonth(int year, int era)
- {
- return _helper.GetLeapMonth(year, era);
- }
-
- public override bool IsLeapMonth(int year, int month, int era)
- {
- return _helper.IsLeapMonth(year, month, era);
- }
-
- public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- return _helper.ToDateTime(year, month, day, hour, minute, second, millisecond, era);
- }
-
- public override int[] Eras => _helper.Eras;
-
- private const int DefaultTwoDigitYearMax = 99;
-
- public override int TwoDigitYearMax
- {
- get
- {
- if (_twoDigitYearMax == -1)
- {
- _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultTwoDigitYearMax);
- }
-
- return _twoDigitYearMax;
- }
- set
- {
- VerifyWritable();
- if (value < 99 || value > _helper.MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 99, _helper.MaxYear));
- }
-
- _twoDigitYearMax = value;
- }
- }
-
- /// <summary>
- /// For Taiwan calendar, four digit year is not used.
- /// Therefore, for any two digit number, we just return the original number.
- /// </summary>
-
- public override int ToFourDigitYear(int year)
- {
- if (year <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.ArgumentOutOfRange_NeedPosNum);
- }
- if (year > _helper.MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, 1, _helper.MaxYear));
- }
-
- return year;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanLunisolarCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanLunisolarCalendar.cs
deleted file mode 100644
index cecbf6a7ed4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/TaiwanLunisolarCalendar.cs
+++ /dev/null
@@ -1,234 +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.
-
-namespace System.Globalization
-{
- /// <remarks>
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 1912/02/18 2051/02/10
- /// TaiwanLunisolar 1912/01/01 2050/13/29
- /// </remarks>
- public class TaiwanLunisolarCalendar : EastAsianLunisolarCalendar
- {
- // Since
- // Gregorian Year = Era Year + yearOffset
- // When Gregorian Year 1912 is year 1, so that
- // 1912 = 1 + yearOffset
- // So yearOffset = 1911
- private static readonly EraInfo[] s_taiwanLunisolarEraInfo = new EraInfo[]
- {
- new EraInfo(1, 1912, 1, 1, 1911, 1, GregorianCalendar.MaxYear - 1911) // era #, start year/month/day, yearOffset, minEraYear
- };
-
- private readonly GregorianCalendarHelper _helper;
-
- private const int MinLunisolarYear = 1912;
- private const int MaxLunisolarYear = 2050;
-
- private static readonly DateTime s_minDate = new DateTime(1912, 2, 18);
- private static readonly DateTime s_maxDate = new DateTime((new DateTime(2051, 2, 10, 23, 59, 59, 999)).Ticks + 9999);
-
- public override DateTime MinSupportedDateTime => s_minDate;
-
- public override DateTime MaxSupportedDateTime => s_maxDate;
-
- protected override int DaysInYearBeforeMinSupportedYear =>
- // 1911 from ChineseLunisolarCalendar
- 384;
-
- private static readonly int[,] s_yinfo =
- {
- /*Y LM Lmon Lday DaysPerMonth D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 D12 D13 #Days
- 1912 */
- { 0, 2, 18, 42192 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 0 354
-1913 */ { 0, 2, 6, 53840 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 0 354
-1914 */ { 5, 1, 26, 54568 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 30 384
-1915 */ { 0, 2, 14, 46400 }, /* 30 29 30 30 29 30 29 30 29 30 29 29 0 354
-1916 */ { 0, 2, 3, 54944 }, /* 30 30 29 30 29 30 30 29 30 29 30 29 0 355
-1917 */ { 2, 1, 23, 38608 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 29 384
-1918 */ { 0, 2, 11, 38320 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 0 355
-1919 */ { 7, 2, 1, 18872 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 30 384
-1920 */ { 0, 2, 20, 18800 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 0 354
-1921 */ { 0, 2, 8, 42160 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 0 354
-1922 */ { 5, 1, 28, 45656 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384
-1923 */ { 0, 2, 16, 27216 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 0 354
-1924 */ { 0, 2, 5, 27968 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 0 354
-1925 */ { 4, 1, 24, 44456 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 30 385
-1926 */ { 0, 2, 13, 11104 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 0 354
-1927 */ { 0, 2, 2, 38256 }, /* 30 29 29 30 29 30 29 30 29 30 30 30 0 355
-1928 */ { 2, 1, 23, 18808 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 30 384
-1929 */ { 0, 2, 10, 18800 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 0 354
-1930 */ { 6, 1, 30, 25776 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 29 383
-1931 */ { 0, 2, 17, 54432 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 0 354
-1932 */ { 0, 2, 6, 59984 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 0 355
-1933 */ { 5, 1, 26, 27976 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 30 384
-1934 */ { 0, 2, 14, 23248 }, /* 29 30 29 30 30 29 30 29 30 30 29 30 0 355
-1935 */ { 0, 2, 4, 11104 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 0 354
-1936 */ { 3, 1, 24, 37744 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 29 384
-1937 */ { 0, 2, 11, 37600 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 0 354
-1938 */ { 7, 1, 31, 51560 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 30 384
-1939 */ { 0, 2, 19, 51536 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 0 354
-1940 */ { 0, 2, 8, 54432 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 0 354
-1941 */ { 6, 1, 27, 55888 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 29 384
-1942 */ { 0, 2, 15, 46416 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 0 355
-1943 */ { 0, 2, 5, 22176 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 0 354
-1944 */ { 4, 1, 25, 43736 }, /* 30 29 30 29 30 29 30 29 30 30 29 30 30 385
-1945 */ { 0, 2, 13, 9680 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 0 354
-1946 */ { 0, 2, 2, 37584 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 0 354
-1947 */ { 2, 1, 22, 51544 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 30 384
-1948 */ { 0, 2, 10, 43344 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 0 354
-1949 */ { 7, 1, 29, 46248 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 30 384
-1950 */ { 0, 2, 17, 27808 }, /* 29 30 30 29 30 30 29 29 30 29 30 29 0 354
-1951 */ { 0, 2, 6, 46416 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 0 355
-1952 */ { 5, 1, 27, 21928 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 30 384
-1953 */ { 0, 2, 14, 19872 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 0 354
-1954 */ { 0, 2, 3, 42416 }, /* 30 29 30 29 29 30 29 30 30 29 30 30 0 355
-1955 */ { 3, 1, 24, 21176 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-1956 */ { 0, 2, 12, 21168 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 0 354
-1957 */ { 8, 1, 31, 43344 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 29 383
-1958 */ { 0, 2, 18, 59728 }, /* 30 30 30 29 30 29 29 30 29 30 29 30 0 355
-1959 */ { 0, 2, 8, 27296 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 0 354
-1960 */ { 6, 1, 28, 44368 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384
-1961 */ { 0, 2, 15, 43856 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 0 355
-1962 */ { 0, 2, 5, 19296 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 0 354
-1963 */ { 4, 1, 25, 42352 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-1964 */ { 0, 2, 13, 42352 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 0 355
-1965 */ { 0, 2, 2, 21088 }, /* 29 30 29 30 29 29 30 29 29 30 30 29 0 353
-1966 */ { 3, 1, 21, 59696 }, /* 30 30 30 29 30 29 29 30 29 29 30 30 29 384
-1967 */ { 0, 2, 9, 55632 }, /* 30 30 29 30 30 29 29 30 29 30 29 30 0 355
-1968 */ { 7, 1, 30, 23208 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-1969 */ { 0, 2, 17, 22176 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 0 354
-1970 */ { 0, 2, 6, 38608 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 0 355
-1971 */ { 5, 1, 27, 19176 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-1972 */ { 0, 2, 15, 19152 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 0 354
-1973 */ { 0, 2, 3, 42192 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 0 354
-1974 */ { 4, 1, 23, 53864 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384
-1975 */ { 0, 2, 11, 53840 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 0 354
-1976 */ { 8, 1, 31, 54568 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 30 384
-1977 */ { 0, 2, 18, 46400 }, /* 30 29 30 30 29 30 29 30 29 30 29 29 0 354
-1978 */ { 0, 2, 7, 46752 }, /* 30 29 30 30 29 30 30 29 30 29 30 29 0 355
-1979 */ { 6, 1, 28, 38608 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 29 384
-1980 */ { 0, 2, 16, 38320 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 0 355
-1981 */ { 0, 2, 5, 18864 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 0 354
-1982 */ { 4, 1, 25, 42168 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384
-1983 */ { 0, 2, 13, 42160 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 0 354
-1984 */ { 10, 2, 2, 45656 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384
-1985 */ { 0, 2, 20, 27216 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 0 354
-1986 */ { 0, 2, 9, 27968 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 0 354
-1987 */ { 6, 1, 29, 44448 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 29 384
-1988 */ { 0, 2, 17, 43872 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 0 355
-1989 */ { 0, 2, 6, 38256 }, /* 30 29 29 30 29 30 29 30 29 30 30 30 0 355
-1990 */ { 5, 1, 27, 18808 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 30 384
-1991 */ { 0, 2, 15, 18800 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 0 354
-1992 */ { 0, 2, 4, 25776 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 0 354
-1993 */ { 3, 1, 23, 27216 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383
-1994 */ { 0, 2, 10, 59984 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 0 355
-1995 */ { 8, 1, 31, 27432 }, /* 29 30 30 29 30 29 30 30 29 29 30 29 30 384
-1996 */ { 0, 2, 19, 23232 }, /* 29 30 29 30 30 29 30 29 30 30 29 29 0 354
-1997 */ { 0, 2, 7, 43872 }, /* 30 29 30 29 30 29 30 30 29 30 30 29 0 355
-1998 */ { 5, 1, 28, 37736 }, /* 30 29 29 30 29 29 30 30 29 30 30 29 30 384
-1999 */ { 0, 2, 16, 37600 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 0 354
-2000 */ { 0, 2, 5, 51552 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 0 354
-2001 */ { 4, 1, 24, 54440 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 30 384
-2002 */ { 0, 2, 12, 54432 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 0 354
-2003 */ { 0, 2, 1, 55888 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 0 355
-2004 */ { 2, 1, 22, 23208 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384
-2005 */ { 0, 2, 9, 22176 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 0 354
-2006 */ { 7, 1, 29, 43736 }, /* 30 29 30 29 30 29 30 29 30 30 29 30 30 385
-2007 */ { 0, 2, 18, 9680 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 0 354
-2008 */ { 0, 2, 7, 37584 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 0 354
-2009 */ { 5, 1, 26, 51544 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 30 384
-2010 */ { 0, 2, 14, 43344 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 0 354
-2011 */ { 0, 2, 3, 46240 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 0 354
-2012 */ { 4, 1, 23, 46416 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 29 384
-2013 */ { 0, 2, 10, 44368 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 0 355
-2014 */ { 9, 1, 31, 21928 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 30 384
-2015 */ { 0, 2, 19, 19360 }, /* 29 30 29 29 30 29 30 30 30 29 30 29 0 354
-2016 */ { 0, 2, 8, 42416 }, /* 30 29 30 29 29 30 29 30 30 29 30 30 0 355
-2017 */ { 6, 1, 28, 21176 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384
-2018 */ { 0, 2, 16, 21168 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 0 354
-2019 */ { 0, 2, 5, 43312 }, /* 30 29 30 29 30 29 29 30 29 29 30 30 0 354
-2020 */ { 4, 1, 25, 29864 }, /* 29 30 30 30 29 30 29 29 30 29 30 29 30 384
-2021 */ { 0, 2, 12, 27296 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 0 354
-2022 */ { 0, 2, 1, 44368 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 0 355
-2023 */ { 2, 1, 22, 19880 }, /* 29 30 29 29 30 30 29 30 30 29 30 29 30 384
-2024 */ { 0, 2, 10, 19296 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 0 354
-2025 */ { 6, 1, 29, 42352 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384
-2026 */ { 0, 2, 17, 42208 }, /* 30 29 30 29 29 30 29 29 30 30 30 29 0 354
-2027 */ { 0, 2, 6, 53856 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 0 354
-2028 */ { 5, 1, 26, 59696 }, /* 30 30 30 29 30 29 29 30 29 29 30 30 29 384
-2029 */ { 0, 2, 13, 54576 }, /* 30 30 29 30 29 30 29 30 29 29 30 30 0 355
-2030 */ { 0, 2, 3, 23200 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 0 354
-2031 */ { 3, 1, 23, 27472 }, /* 29 30 30 29 30 29 30 30 29 30 29 30 29 384
-2032 */ { 0, 2, 11, 38608 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 0 355
-2033 */ { 11, 1, 31, 19176 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384
-2034 */ { 0, 2, 19, 19152 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 0 354
-2035 */ { 0, 2, 8, 42192 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 0 354
-2036 */ { 6, 1, 28, 53848 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 30 384
-2037 */ { 0, 2, 15, 53840 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 0 354
-2038 */ { 0, 2, 4, 54560 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 0 354
-2039 */ { 5, 1, 24, 55968 }, /* 30 30 29 30 30 29 30 29 30 29 30 29 29 384
-2040 */ { 0, 2, 12, 46496 }, /* 30 29 30 30 29 30 29 30 30 29 30 29 0 355
-2041 */ { 0, 2, 1, 22224 }, /* 29 30 29 30 29 30 30 29 30 30 29 30 0 355
-2042 */ { 2, 1, 22, 19160 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 30 384
-2043 */ { 0, 2, 10, 18864 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 0 354
-2044 */ { 7, 1, 30, 42168 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384
-2045 */ { 0, 2, 17, 42160 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 0 354
-2046 */ { 0, 2, 6, 43600 }, /* 30 29 30 29 30 29 30 29 29 30 29 30 0 354
-2047 */ { 5, 1, 26, 46376 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 30 384
-2048 */ { 0, 2, 14, 27936 }, /* 29 30 30 29 30 30 29 30 29 29 30 29 0 354
-2049 */ { 0, 2, 2, 44448 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 0 355
-2050 */ { 3, 1, 23, 21936 }, /* 29 30 29 30 29 30 29 30 30 29 30 30 29 384
- */ };
-
-
- internal override int MinCalendarYear => MinLunisolarYear;
-
- internal override int MaxCalendarYear => MaxLunisolarYear;
-
- internal override DateTime MinDate => s_minDate;
-
- internal override DateTime MaxDate => s_maxDate;
-
- internal override EraInfo[]? CalEraInfo => s_taiwanLunisolarEraInfo;
-
- internal override int GetYearInfo(int lunarYear, int index)
- {
- if ((lunarYear < MinLunisolarYear) || (lunarYear > MaxLunisolarYear))
- {
- throw new ArgumentOutOfRangeException(
- "year",
- lunarYear,
- SR.Format(SR.ArgumentOutOfRange_Range, MinLunisolarYear, MaxLunisolarYear));
- }
-
- return s_yinfo[lunarYear - MinLunisolarYear, index];
- }
-
- internal override int GetYear(int year, DateTime time)
- {
- return _helper.GetYear(year, time);
- }
-
- internal override int GetGregorianYear(int year, int era)
- {
- return _helper.GetGregorianYear(year, era);
- }
-
- public TaiwanLunisolarCalendar()
- {
- _helper = new GregorianCalendarHelper(this, s_taiwanLunisolarEraInfo);
- }
-
- public override int GetEra(DateTime time) => _helper.GetEra(time);
-
- internal override CalendarId BaseCalendarID => CalendarId.TAIWAN;
-
- internal override CalendarId ID => CalendarId.TAIWANLUNISOLAR;
-
- public override int[] Eras => _helper.Eras;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/TextElementEnumerator.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/TextElementEnumerator.cs
deleted file mode 100644
index 7ee564a9347..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/TextElementEnumerator.cs
+++ /dev/null
@@ -1,92 +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 System.Collections;
-using System.Diagnostics;
-
-namespace System.Globalization
-{
- public class TextElementEnumerator : IEnumerator
- {
- private readonly string _str;
- private int _index;
- private readonly int _startIndex;
-
- // This is the length of the total string, counting from the beginning of string.
- private readonly int _strLen;
-
- // The current text element lenght after MoveNext() is called.
- private int _currTextElementLen;
-
- private UnicodeCategory _uc;
-
- // The next abstract char to look at after MoveNext() is called.
- // It could be 1 or 2, depending on if it is a surrogate or not.
- private int _charLen;
-
- internal TextElementEnumerator(string str, int startIndex, int strLen)
- {
- Debug.Assert(str != null, "TextElementEnumerator(): str != null");
- Debug.Assert(startIndex >= 0 && strLen >= 0, "TextElementEnumerator(): startIndex >= 0 && strLen >= 0");
- Debug.Assert(strLen >= startIndex, "TextElementEnumerator(): strLen >= startIndex");
- _str = str;
- _startIndex = startIndex;
- _strLen = strLen;
- Reset();
- }
-
- public bool MoveNext()
- {
- if (_index >= _strLen)
- {
- // Make the _index to be greater than _strLen so that we can throw exception if GetTextElement() is called.
- _index = _strLen + 1;
- return false;
- }
-
- _currTextElementLen = StringInfo.GetCurrentTextElementLen(_str, _index, _strLen, ref _uc, ref _charLen);
- _index += _currTextElementLen;
- return true;
- }
-
- public object Current => GetTextElement();
-
- public string GetTextElement()
- {
- if (_index == _startIndex)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted);
- }
- if (_index > _strLen)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumEnded);
- }
-
- return _str.Substring(_index - _currTextElementLen, _currTextElementLen);
- }
-
- public int ElementIndex
- {
- get
- {
- if (_index == _startIndex)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted);
- }
-
- return _index - _currTextElementLen;
- }
- }
-
- public void Reset()
- {
- _index = _startIndex;
- if (_index < _strLen)
- {
- // If we have more than 1 character, get the category of the current char.
- _uc = CharUnicodeInfo.InternalGetUnicodeCategory(_str, _index, out _charLen);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.Unix.cs
deleted file mode 100644
index 02e7c5f50b9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.Unix.cs
+++ /dev/null
@@ -1,57 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Security;
-using System.Text;
-
-namespace System.Globalization
-{
- public partial class TextInfo
- {
- private Tristate _needsTurkishCasing = Tristate.NotInitialized;
-
- private void FinishInitialization() { }
-
- // -----------------------------
- // ---- PAL layer ends here ----
- // -----------------------------
-
- private static bool NeedsTurkishCasing(string localeName)
- {
- Debug.Assert(localeName != null);
-
- return CultureInfo.GetCultureInfo(localeName).CompareInfo.Compare("\u0131", "I", CompareOptions.IgnoreCase) == 0;
- }
-
- private bool IsInvariant { get { return _cultureName.Length == 0; } }
-
- internal unsafe void ChangeCase(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- if (IsInvariant)
- {
- Interop.Globalization.ChangeCaseInvariant(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper);
- }
- else
- {
- if (_needsTurkishCasing == Tristate.NotInitialized)
- {
- _needsTurkishCasing = NeedsTurkishCasing(_textInfoName) ? Tristate.True : Tristate.False;
- }
- if (_needsTurkishCasing == Tristate.True)
- {
- Interop.Globalization.ChangeCaseTurkish(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper);
- }
- else
- {
- Interop.Globalization.ChangeCase(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper);
- }
- }
- }
-
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.Windows.cs
deleted file mode 100644
index 948644769da..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.Windows.cs
+++ /dev/null
@@ -1,55 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- public partial class TextInfo
- {
- private unsafe void FinishInitialization()
- {
- _sortHandle = CompareInfo.GetSortHandle(_textInfoName);
- }
-
- private unsafe void ChangeCase(char* pSource, int pSourceLen, char* pResult, int pResultLen, bool toUpper)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(pSource != null);
- Debug.Assert(pResult != null);
- Debug.Assert(pSourceLen >= 0);
- Debug.Assert(pResultLen >= 0);
- Debug.Assert(pSourceLen <= pResultLen);
-
- // Check for Invariant to avoid A/V in LCMapStringEx
- uint linguisticCasing = IsInvariantLocale(_textInfoName) ? 0 : LCMAP_LINGUISTIC_CASING;
-
- int ret = Interop.Kernel32.LCMapStringEx(_sortHandle != IntPtr.Zero ? null : _textInfoName,
- linguisticCasing | (toUpper ? LCMAP_UPPERCASE : LCMAP_LOWERCASE),
- pSource,
- pSourceLen,
- pResult,
- pSourceLen,
- null,
- null,
- _sortHandle);
- if (ret == 0)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
-
- Debug.Assert(ret == pSourceLen, "Expected getting the same length of the original string");
- }
-
- // PAL Ends here
-
- private IntPtr _sortHandle;
-
- private const uint LCMAP_LINGUISTIC_CASING = 0x01000000;
- private const uint LCMAP_LOWERCASE = 0x00000100;
- private const uint LCMAP_UPPERCASE = 0x00000200;
-
- private static bool IsInvariantLocale(string localeName) => localeName == "";
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs
deleted file mode 100644
index d1f6b8d343b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs
+++ /dev/null
@@ -1,870 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Serialization;
-using System.Text;
-using System.Text.Unicode;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else // BIT64
-using nuint = System.UInt32;
-#endif // BIT64
-
-namespace System.Globalization
-{
- /// <summary>
- /// This Class defines behaviors specific to a writing system.
- /// A writing system is the collection of scripts and orthographic rules
- /// required to represent a language as text.
- /// </summary>
- public partial class TextInfo : ICloneable, IDeserializationCallback
- {
- private enum Tristate : byte
- {
- NotInitialized = 0,
- False = 1,
- True = 2
- }
-
- private string? _listSeparator;
- private bool _isReadOnly = false;
-
- private readonly string _cultureName;
- private readonly CultureData _cultureData;
-
- // // Name of the text info we're using (ie: _cultureData.TextInfoName)
- private readonly string _textInfoName;
-
- private Tristate _isAsciiCasingSameAsInvariant = Tristate.NotInitialized;
-
- // Invariant text info
- internal static TextInfo Invariant => s_invariant ??= new TextInfo(CultureData.Invariant);
-
- private static volatile TextInfo? s_invariant;
-
- internal TextInfo(CultureData cultureData)
- {
- // This is our primary data source, we don't need most of the rest of this
- _cultureData = cultureData;
- _cultureName = _cultureData.CultureName;
- _textInfoName = _cultureData.TextInfoName;
-
- FinishInitialization();
- }
-
- void IDeserializationCallback.OnDeserialization(object? sender)
- {
- throw new PlatformNotSupportedException();
- }
-
- public virtual int ANSICodePage => _cultureData.ANSICodePage;
-
- public virtual int OEMCodePage => _cultureData.OEMCodePage;
-
- public virtual int MacCodePage => _cultureData.MacCodePage;
-
- public virtual int EBCDICCodePage => _cultureData.EBCDICCodePage;
-
- // Just use the LCID from our text info name
- public int LCID => CultureInfo.GetCultureInfo(_textInfoName).LCID;
-
- public string CultureName => _textInfoName;
-
- public bool IsReadOnly => _isReadOnly;
-
- public virtual object Clone()
- {
- object o = MemberwiseClone();
- ((TextInfo)o).SetReadOnlyState(false);
- return o;
- }
-
- /// <summary>
- /// Create a cloned readonly instance or return the input one if it is
- /// readonly.
- /// </summary>
- public static TextInfo ReadOnly(TextInfo textInfo)
- {
- if (textInfo == null)
- {
- throw new ArgumentNullException(nameof(textInfo));
- }
-
- if (textInfo.IsReadOnly)
- {
- return textInfo;
- }
-
- TextInfo clonedTextInfo = (TextInfo)(textInfo.MemberwiseClone());
- clonedTextInfo.SetReadOnlyState(true);
- return clonedTextInfo;
- }
-
- private void VerifyWritable()
- {
- if (_isReadOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- }
-
- internal void SetReadOnlyState(bool readOnly)
- {
- _isReadOnly = readOnly;
- }
-
- /// <summary>
- /// Returns the string used to separate items in a list.
- /// </summary>
- public virtual string ListSeparator
- {
- get => _listSeparator ??= _cultureData.ListSeparator;
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- VerifyWritable();
- _listSeparator = value;
- }
- }
-
- /// <summary>
- /// Converts the character or string to lower case. Certain locales
- /// have different casing semantics from the file systems in Win32.
- /// </summary>
- public virtual char ToLower(char c)
- {
- if (GlobalizationMode.Invariant || (IsAscii(c) && IsAsciiCasingSameAsInvariant))
- {
- return ToLowerAsciiInvariant(c);
- }
-
- return ChangeCase(c, toUpper: false);
- }
-
- public virtual string ToLower(string str)
- {
- if (str == null)
- {
- throw new ArgumentNullException(nameof(str));
- }
-
- if (GlobalizationMode.Invariant)
- {
- return ToLowerAsciiInvariant(str);
- }
-
- return ChangeCaseCommon<ToLowerConversion>(str);
- }
-
- private unsafe char ChangeCase(char c, bool toUpper)
- {
- Debug.Assert(!GlobalizationMode.Invariant);
-
- char dst = default;
- ChangeCase(&c, 1, &dst, 1, toUpper);
- return dst;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal void ChangeCaseToLower(ReadOnlySpan<char> source, Span<char> destination)
- {
- Debug.Assert(destination.Length >= source.Length);
- ChangeCaseCommon<ToLowerConversion>(ref MemoryMarshal.GetReference(source), ref MemoryMarshal.GetReference(destination), source.Length);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal void ChangeCaseToUpper(ReadOnlySpan<char> source, Span<char> destination)
- {
- Debug.Assert(destination.Length >= source.Length);
- ChangeCaseCommon<ToUpperConversion>(ref MemoryMarshal.GetReference(source), ref MemoryMarshal.GetReference(destination), source.Length);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private void ChangeCaseCommon<TConversion>(ReadOnlySpan<char> source, Span<char> destination) where TConversion : struct
- {
- Debug.Assert(destination.Length >= source.Length);
- ChangeCaseCommon<TConversion>(ref MemoryMarshal.GetReference(source), ref MemoryMarshal.GetReference(destination), source.Length);
- }
-
- private unsafe void ChangeCaseCommon<TConversion>(ref char source, ref char destination, int charCount) where TConversion : struct
- {
- Debug.Assert(typeof(TConversion) == typeof(ToUpperConversion) || typeof(TConversion) == typeof(ToLowerConversion));
- bool toUpper = typeof(TConversion) == typeof(ToUpperConversion); // JIT will treat this as a constant in release builds
-
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(charCount >= 0);
-
- if (charCount == 0)
- {
- goto Return;
- }
-
- fixed (char* pSource = &source)
- fixed (char* pDestination = &destination)
- {
- nuint currIdx = 0; // in chars
-
- if (IsAsciiCasingSameAsInvariant)
- {
- // Read 4 chars (two 32-bit integers) at a time
-
- if (charCount >= 4)
- {
- nuint lastIndexWhereCanReadFourChars = (uint)charCount - 4;
- do
- {
- // This is a mostly branchless case change routine. Generally speaking, we assume that the majority
- // of input is ASCII, so the 'if' checks below should normally evaluate to false. However, within
- // the ASCII data, we expect that characters of either case might be about equally distributed, so
- // we want the case change operation itself to be branchless. This gives optimal performance in the
- // common case. We also expect that developers aren't passing very long (16+ character) strings into
- // this method, so we won't bother vectorizing until data shows us that it's worthwhile to do so.
-
- uint tempValue = Unsafe.ReadUnaligned<uint>(pSource + currIdx);
- if (!Utf16Utility.AllCharsInUInt32AreAscii(tempValue))
- {
- goto NonAscii;
- }
- tempValue = (toUpper) ? Utf16Utility.ConvertAllAsciiCharsInUInt32ToUppercase(tempValue) : Utf16Utility.ConvertAllAsciiCharsInUInt32ToLowercase(tempValue);
- Unsafe.WriteUnaligned<uint>(pDestination + currIdx, tempValue);
-
- tempValue = Unsafe.ReadUnaligned<uint>(pSource + currIdx + 2);
- if (!Utf16Utility.AllCharsInUInt32AreAscii(tempValue))
- {
- goto NonAsciiSkipTwoChars;
- }
- tempValue = (toUpper) ? Utf16Utility.ConvertAllAsciiCharsInUInt32ToUppercase(tempValue) : Utf16Utility.ConvertAllAsciiCharsInUInt32ToLowercase(tempValue);
- Unsafe.WriteUnaligned<uint>(pDestination + currIdx + 2, tempValue);
- currIdx += 4;
- } while (currIdx <= lastIndexWhereCanReadFourChars);
-
- // At this point, there are fewer than 4 characters remaining to convert.
- Debug.Assert((uint)charCount - currIdx < 4);
- }
-
- // If there are 2 or 3 characters left to convert, we'll convert 2 of them now.
- if ((charCount & 2) != 0)
- {
- uint tempValue = Unsafe.ReadUnaligned<uint>(pSource + currIdx);
- if (!Utf16Utility.AllCharsInUInt32AreAscii(tempValue))
- {
- goto NonAscii;
- }
- tempValue = (toUpper) ? Utf16Utility.ConvertAllAsciiCharsInUInt32ToUppercase(tempValue) : Utf16Utility.ConvertAllAsciiCharsInUInt32ToLowercase(tempValue);
- Unsafe.WriteUnaligned<uint>(pDestination + currIdx, tempValue);
- currIdx += 2;
- }
-
- // If there's a single character left to convert, do it now.
- if ((charCount & 1) != 0)
- {
- uint tempValue = pSource[currIdx];
- if (tempValue > 0x7Fu)
- {
- goto NonAscii;
- }
- tempValue = (toUpper) ? Utf16Utility.ConvertAllAsciiCharsInUInt32ToUppercase(tempValue) : Utf16Utility.ConvertAllAsciiCharsInUInt32ToLowercase(tempValue);
- pDestination[currIdx] = (char)tempValue;
- }
-
- // And we're finished!
-
- goto Return;
-
- // If we reached this point, we found non-ASCII data.
- // Fall back down the p/invoke code path.
-
- NonAsciiSkipTwoChars:
- currIdx += 2;
-
- NonAscii:
- Debug.Assert(currIdx < (uint)charCount, "We somehow read past the end of the buffer.");
- charCount -= (int)currIdx;
- }
-
- // We encountered non-ASCII data and therefore can't perform invariant case conversion; or the requested culture
- // has a case conversion that's different from the invariant culture, even for ASCII data (e.g., tr-TR converts
- // 'i' (U+0069) to Latin Capital Letter I With Dot Above (U+0130)).
-
- ChangeCase(pSource + currIdx, charCount, pDestination + currIdx, charCount, toUpper);
- }
-
- Return:
- return;
- }
-
- private unsafe string ChangeCaseCommon<TConversion>(string source) where TConversion : struct
- {
- Debug.Assert(typeof(TConversion) == typeof(ToUpperConversion) || typeof(TConversion) == typeof(ToLowerConversion));
- bool toUpper = typeof(TConversion) == typeof(ToUpperConversion); // JIT will treat this as a constant in release builds
-
- Debug.Assert(!GlobalizationMode.Invariant);
- Debug.Assert(source != null);
-
- // If the string is empty, we're done.
- if (source.Length == 0)
- {
- return string.Empty;
- }
-
- fixed (char* pSource = source)
- {
- nuint currIdx = 0; // in chars
-
- // If this culture's casing for ASCII is the same as invariant, try to take
- // a fast path that'll work in managed code and ASCII rather than calling out
- // to the OS for culture-aware casing.
- if (IsAsciiCasingSameAsInvariant)
- {
- // Read 2 chars (one 32-bit integer) at a time
-
- if (source.Length >= 2)
- {
- nuint lastIndexWhereCanReadTwoChars = (uint)source.Length - 2;
- do
- {
- // See the comments in ChangeCaseCommon<TConversion>(ROS<char>, Span<char>) for a full explanation of the below code.
-
- uint tempValue = Unsafe.ReadUnaligned<uint>(pSource + currIdx);
- if (!Utf16Utility.AllCharsInUInt32AreAscii(tempValue))
- {
- goto NotAscii;
- }
- if ((toUpper) ? Utf16Utility.UInt32ContainsAnyLowercaseAsciiChar(tempValue) : Utf16Utility.UInt32ContainsAnyUppercaseAsciiChar(tempValue))
- {
- goto AsciiMustChangeCase;
- }
-
- currIdx += 2;
- } while (currIdx <= lastIndexWhereCanReadTwoChars);
- }
-
- // If there's a single character left to convert, do it now.
- if ((source.Length & 1) != 0)
- {
- uint tempValue = pSource[currIdx];
- if (tempValue > 0x7Fu)
- {
- goto NotAscii;
- }
- if ((toUpper) ? ((tempValue - 'a') <= (uint)('z' - 'a')) : ((tempValue - 'A') <= (uint)('Z' - 'A')))
- {
- goto AsciiMustChangeCase;
- }
- }
-
- // We got through all characters without finding anything that needed to change - done!
- return source;
-
- AsciiMustChangeCase:
- {
- // We reached ASCII data that requires a case change.
- // This will necessarily allocate a new string, but let's try to stay within the managed (non-localization tables)
- // conversion code path if we can.
-
- string result = string.FastAllocateString(source.Length); // changing case uses simple folding: doesn't change UTF-16 code unit count
-
- // copy existing known-good data into the result
- Span<char> resultSpan = new Span<char>(ref result.GetRawStringData(), result.Length);
- source.AsSpan(0, (int)currIdx).CopyTo(resultSpan);
-
- // and re-run the fast span-based logic over the remainder of the data
- ChangeCaseCommon<TConversion>(source.AsSpan((int)currIdx), resultSpan.Slice((int)currIdx));
- return result;
- }
- }
-
- NotAscii:
- {
- // We reached non-ASCII data *or* the requested culture doesn't map ASCII data the same way as the invariant culture.
- // In either case we need to fall back to the localization tables.
-
- string result = string.FastAllocateString(source.Length); // changing case uses simple folding: doesn't change UTF-16 code unit count
-
- if (currIdx > 0)
- {
- // copy existing known-good data into the result
- Span<char> resultSpan = new Span<char>(ref result.GetRawStringData(), result.Length);
- source.AsSpan(0, (int)currIdx).CopyTo(resultSpan);
- }
-
- // and run the culture-aware logic over the remainder of the data
- fixed (char* pResult = result)
- {
- ChangeCase(pSource + currIdx, source.Length - (int)currIdx, pResult + currIdx, result.Length - (int)currIdx, toUpper);
- }
- return result;
- }
- }
- }
-
- internal static unsafe string ToLowerAsciiInvariant(string s)
- {
- if (s.Length == 0)
- {
- return string.Empty;
- }
-
- fixed (char* pSource = s)
- {
- int i = 0;
- while (i < s.Length)
- {
- if ((uint)(pSource[i] - 'A') <= (uint)('Z' - 'A'))
- {
- break;
- }
- i++;
- }
-
- if (i >= s.Length)
- {
- return s;
- }
-
- string result = string.FastAllocateString(s.Length);
- fixed (char* pResult = result)
- {
- for (int j = 0; j < i; j++)
- {
- pResult[j] = pSource[j];
- }
-
- pResult[i] = (char)(pSource[i] | 0x20);
- i++;
-
- while (i < s.Length)
- {
- pResult[i] = ToLowerAsciiInvariant(pSource[i]);
- i++;
- }
- }
-
- return result;
- }
- }
-
- internal static void ToLowerAsciiInvariant(ReadOnlySpan<char> source, Span<char> destination)
- {
- Debug.Assert(destination.Length >= source.Length);
-
- for (int i = 0; i < source.Length; i++)
- {
- destination[i] = ToLowerAsciiInvariant(source[i]);
- }
- }
-
- private static unsafe string ToUpperAsciiInvariant(string s)
- {
- if (s.Length == 0)
- {
- return string.Empty;
- }
-
- fixed (char* pSource = s)
- {
- int i = 0;
- while (i < s.Length)
- {
- if ((uint)(pSource[i] - 'a') <= (uint)('z' - 'a'))
- {
- break;
- }
- i++;
- }
-
- if (i >= s.Length)
- {
- return s;
- }
-
- string result = string.FastAllocateString(s.Length);
- fixed (char* pResult = result)
- {
- for (int j = 0; j < i; j++)
- {
- pResult[j] = pSource[j];
- }
-
- pResult[i] = (char)(pSource[i] & ~0x20);
- i++;
-
- while (i < s.Length)
- {
- pResult[i] = ToUpperAsciiInvariant(pSource[i]);
- i++;
- }
- }
-
- return result;
- }
- }
-
- internal static void ToUpperAsciiInvariant(ReadOnlySpan<char> source, Span<char> destination)
- {
- Debug.Assert(destination.Length >= source.Length);
-
- for (int i = 0; i < source.Length; i++)
- {
- destination[i] = ToUpperAsciiInvariant(source[i]);
- }
- }
-
- private static char ToLowerAsciiInvariant(char c)
- {
- if ((uint)(c - 'A') <= (uint)('Z' - 'A'))
- {
- c = (char)(c | 0x20);
- }
- return c;
- }
-
- /// <summary>
- /// Converts the character or string to upper case. Certain locales
- /// have different casing semantics from the file systems in Win32.
- /// </summary>
- public virtual char ToUpper(char c)
- {
- if (GlobalizationMode.Invariant || (IsAscii(c) && IsAsciiCasingSameAsInvariant))
- {
- return ToUpperAsciiInvariant(c);
- }
-
- return ChangeCase(c, toUpper: true);
- }
-
- public virtual string ToUpper(string str)
- {
- if (str == null)
- {
- throw new ArgumentNullException(nameof(str));
- }
-
- if (GlobalizationMode.Invariant)
- {
- return ToUpperAsciiInvariant(str);
- }
-
- return ChangeCaseCommon<ToUpperConversion>(str);
- }
-
- internal static char ToUpperAsciiInvariant(char c)
- {
- if ((uint)(c - 'a') <= (uint)('z' - 'a'))
- {
- c = (char)(c & ~0x20);
- }
- return c;
- }
-
- private static bool IsAscii(char c) => c < 0x80;
-
- private bool IsAsciiCasingSameAsInvariant
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- if (_isAsciiCasingSameAsInvariant == Tristate.NotInitialized)
- {
- PopulateIsAsciiCasingSameAsInvariant();
- }
-
- Debug.Assert(_isAsciiCasingSameAsInvariant == Tristate.True || _isAsciiCasingSameAsInvariant == Tristate.False);
- return _isAsciiCasingSameAsInvariant == Tristate.True;
- }
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private void PopulateIsAsciiCasingSameAsInvariant()
- {
- bool compareResult = CultureInfo.GetCultureInfo(_textInfoName).CompareInfo.Compare("abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", CompareOptions.IgnoreCase) == 0;
- _isAsciiCasingSameAsInvariant = (compareResult) ? Tristate.True : Tristate.False;
- }
-
- /// <summary>
- /// Returns true if the dominant direction of text and UI such as the
- /// relative position of buttons and scroll bars
- /// </summary>
- public bool IsRightToLeft => _cultureData.IsRightToLeft;
-
- public override bool Equals(object? obj)
- {
- return obj is TextInfo otherTextInfo
- && CultureName.Equals(otherTextInfo.CultureName);
- }
-
- public override int GetHashCode() => CultureName.GetHashCode();
-
- public override string ToString()
- {
- return "TextInfo - " + _cultureData.CultureName;
- }
-
- /// <summary>
- /// Titlecasing refers to a casing practice wherein the first letter of a word is an uppercase letter
- /// and the rest of the letters are lowercase. The choice of which words to titlecase in headings
- /// and titles is dependent on language and local conventions. For example, "The Merry Wives of Windor"
- /// is the appropriate titlecasing of that play's name in English, with the word "of" not titlecased.
- /// In German, however, the title is "Die lustigen Weiber von Windsor," and both "lustigen" and "von"
- /// are not titlecased. In French even fewer words are titlecased: "Les joyeuses commeres de Windsor."
- ///
- /// Moreover, the determination of what actually constitutes a word is language dependent, and this can
- /// influence which letter or letters of a "word" are uppercased when titlecasing strings. For example
- /// "l'arbre" is considered two words in French, whereas "can't" is considered one word in English.
- /// </summary>
- public unsafe string ToTitleCase(string str)
- {
- if (str == null)
- {
- throw new ArgumentNullException(nameof(str));
- }
-
- if (str.Length == 0)
- {
- return str;
- }
-
- StringBuilder result = new StringBuilder();
- string? lowercaseData = null;
- // Store if the current culture is Dutch (special case)
- bool isDutchCulture = CultureName.StartsWith("nl-", StringComparison.OrdinalIgnoreCase);
-
- for (int i = 0; i < str.Length; i++)
- {
- int charLen;
- UnicodeCategory charType = CharUnicodeInfo.InternalGetUnicodeCategory(str, i, out charLen);
- if (char.CheckLetter(charType))
- {
- // Special case to check for Dutch specific titlecasing with "IJ" characters
- // at the beginning of a word
- if (isDutchCulture && i < str.Length - 1 && (str[i] == 'i' || str[i] == 'I') && (str[i + 1] == 'j' || str[i + 1] == 'J'))
- {
- result.Append("IJ");
- i += 2;
- }
- else
- {
- // Do the titlecasing for the first character of the word.
- i = AddTitlecaseLetter(ref result, ref str, i, charLen) + 1;
- }
-
- // Convert the characters until the end of the this word
- // to lowercase.
- int lowercaseStart = i;
-
- // Use hasLowerCase flag to prevent from lowercasing acronyms (like "URT", "USA", etc)
- // This is in line with Word 2000 behavior of titlecasing.
- bool hasLowerCase = (charType == UnicodeCategory.LowercaseLetter);
-
- // Use a loop to find all of the other letters following this letter.
- while (i < str.Length)
- {
- charType = CharUnicodeInfo.InternalGetUnicodeCategory(str, i, out charLen);
- if (IsLetterCategory(charType))
- {
- if (charType == UnicodeCategory.LowercaseLetter)
- {
- hasLowerCase = true;
- }
- i += charLen;
- }
- else if (str[i] == '\'')
- {
- i++;
- if (hasLowerCase)
- {
- if (lowercaseData == null)
- {
- lowercaseData = ToLower(str);
- }
- result.Append(lowercaseData, lowercaseStart, i - lowercaseStart);
- }
- else
- {
- result.Append(str, lowercaseStart, i - lowercaseStart);
- }
- lowercaseStart = i;
- hasLowerCase = true;
- }
- else if (!IsWordSeparator(charType))
- {
- // This category is considered to be part of the word.
- // This is any category that is marked as false in wordSeprator array.
- i += charLen;
- }
- else
- {
- // A word separator. Break out of the loop.
- break;
- }
- }
-
- int count = i - lowercaseStart;
-
- if (count > 0)
- {
- if (hasLowerCase)
- {
- if (lowercaseData == null)
- {
- lowercaseData = ToLower(str);
- }
- result.Append(lowercaseData, lowercaseStart, count);
- }
- else
- {
- result.Append(str, lowercaseStart, count);
- }
- }
-
- if (i < str.Length)
- {
- // not a letter, just append it
- i = AddNonLetter(ref result, ref str, i, charLen);
- }
- }
- else
- {
- // not a letter, just append it
- i = AddNonLetter(ref result, ref str, i, charLen);
- }
- }
- return result.ToString();
- }
-
- private static int AddNonLetter(ref StringBuilder result, ref string input, int inputIndex, int charLen)
- {
- Debug.Assert(charLen == 1 || charLen == 2, "[TextInfo.AddNonLetter] CharUnicodeInfo.InternalGetUnicodeCategory returned an unexpected charLen!");
- if (charLen == 2)
- {
- // Surrogate pair
- result.Append(input[inputIndex++]);
- result.Append(input[inputIndex]);
- }
- else
- {
- result.Append(input[inputIndex]);
- }
- return inputIndex;
- }
-
- private int AddTitlecaseLetter(ref StringBuilder result, ref string input, int inputIndex, int charLen)
- {
- Debug.Assert(charLen == 1 || charLen == 2, "[TextInfo.AddTitlecaseLetter] CharUnicodeInfo.InternalGetUnicodeCategory returned an unexpected charLen!");
-
- if (charLen == 2)
- {
- // for surrogate pairs do a ToUpper operation on the substring
- ReadOnlySpan<char> src = input.AsSpan(inputIndex, 2);
- if (GlobalizationMode.Invariant)
- {
- result.Append(src); // surrogate pair in invariant mode, so changing case is a nop
- }
- else
- {
- Span<char> dst = stackalloc char[2];
- ChangeCaseToUpper(src, dst);
- result.Append(dst);
- }
- inputIndex++;
- }
- else
- {
- switch (input[inputIndex])
- {
- // For AppCompat, the Titlecase Case Mapping data from NDP 2.0 is used below.
- case (char)0x01C4: // DZ with Caron -> Dz with Caron
- case (char)0x01C5: // Dz with Caron -> Dz with Caron
- case (char)0x01C6: // dz with Caron -> Dz with Caron
- result.Append((char)0x01C5);
- break;
- case (char)0x01C7: // LJ -> Lj
- case (char)0x01C8: // Lj -> Lj
- case (char)0x01C9: // lj -> Lj
- result.Append((char)0x01C8);
- break;
- case (char)0x01CA: // NJ -> Nj
- case (char)0x01CB: // Nj -> Nj
- case (char)0x01CC: // nj -> Nj
- result.Append((char)0x01CB);
- break;
- case (char)0x01F1: // DZ -> Dz
- case (char)0x01F2: // Dz -> Dz
- case (char)0x01F3: // dz -> Dz
- result.Append((char)0x01F2);
- break;
- default:
- result.Append(ToUpper(input[inputIndex]));
- break;
- }
- }
- return inputIndex;
- }
-
- // Used in ToTitleCase():
- // When we find a starting letter, the following array decides if a category should be
- // considered as word seprator or not.
- private const int c_wordSeparatorMask =
- /* false */ (0 << 0) | // UppercaseLetter = 0,
- /* false */ (0 << 1) | // LowercaseLetter = 1,
- /* false */ (0 << 2) | // TitlecaseLetter = 2,
- /* false */ (0 << 3) | // ModifierLetter = 3,
- /* false */ (0 << 4) | // OtherLetter = 4,
- /* false */ (0 << 5) | // NonSpacingMark = 5,
- /* false */ (0 << 6) | // SpacingCombiningMark = 6,
- /* false */ (0 << 7) | // EnclosingMark = 7,
- /* false */ (0 << 8) | // DecimalDigitNumber = 8,
- /* false */ (0 << 9) | // LetterNumber = 9,
- /* false */ (0 << 10) | // OtherNumber = 10,
- /* true */ (1 << 11) | // SpaceSeparator = 11,
- /* true */ (1 << 12) | // LineSeparator = 12,
- /* true */ (1 << 13) | // ParagraphSeparator = 13,
- /* true */ (1 << 14) | // Control = 14,
- /* true */ (1 << 15) | // Format = 15,
- /* false */ (0 << 16) | // Surrogate = 16,
- /* false */ (0 << 17) | // PrivateUse = 17,
- /* true */ (1 << 18) | // ConnectorPunctuation = 18,
- /* true */ (1 << 19) | // DashPunctuation = 19,
- /* true */ (1 << 20) | // OpenPunctuation = 20,
- /* true */ (1 << 21) | // ClosePunctuation = 21,
- /* true */ (1 << 22) | // InitialQuotePunctuation = 22,
- /* true */ (1 << 23) | // FinalQuotePunctuation = 23,
- /* true */ (1 << 24) | // OtherPunctuation = 24,
- /* true */ (1 << 25) | // MathSymbol = 25,
- /* true */ (1 << 26) | // CurrencySymbol = 26,
- /* true */ (1 << 27) | // ModifierSymbol = 27,
- /* true */ (1 << 28) | // OtherSymbol = 28,
- /* false */ (0 << 29); // OtherNotAssigned = 29;
-
- private static bool IsWordSeparator(UnicodeCategory category)
- {
- return (c_wordSeparatorMask & (1 << (int)category)) != 0;
- }
-
- private static bool IsLetterCategory(UnicodeCategory uc)
- {
- return uc == UnicodeCategory.UppercaseLetter
- || uc == UnicodeCategory.LowercaseLetter
- || uc == UnicodeCategory.TitlecaseLetter
- || uc == UnicodeCategory.ModifierLetter
- || uc == UnicodeCategory.OtherLetter;
- }
-
- // A dummy struct that is used for 'ToUpper' in generic parameters
- private readonly struct ToUpperConversion { }
-
- // A dummy struct that is used for 'ToLower' in generic parameters
- private readonly struct ToLowerConversion { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/ThaiBuddhistCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/ThaiBuddhistCalendar.cs
deleted file mode 100644
index 96ecea765de..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/ThaiBuddhistCalendar.cs
+++ /dev/null
@@ -1,168 +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.
-
-namespace System.Globalization
-{
- /// <summary>
- /// ThaiBuddhistCalendar is based on Gregorian calendar.
- /// Its year value has an offset to the Gregorain calendar.
- /// </summary>
- /// <remarks>
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 0001/01/01 9999/12/31
- /// Thai 0544/01/01 10542/12/31
- /// </remarks>
- public class ThaiBuddhistCalendar : Calendar
- {
- private static readonly EraInfo[] s_thaiBuddhistEraInfo = new EraInfo[]
- {
- new EraInfo(1, 1, 1, 1, -543, 544, GregorianCalendar.MaxYear + 543) // era #, start year/month/day, yearOffset, minEraYear
- };
-
- public const int ThaiBuddhistEra = 1;
-
- private readonly GregorianCalendarHelper _helper;
-
- public override DateTime MinSupportedDateTime => DateTime.MinValue;
-
- public override DateTime MaxSupportedDateTime => DateTime.MaxValue;
-
- public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.SolarCalendar;
-
- public ThaiBuddhistCalendar()
- {
- _helper = new GregorianCalendarHelper(this, s_thaiBuddhistEraInfo);
- }
-
- internal override CalendarId ID => CalendarId.THAI;
-
- public override DateTime AddMonths(DateTime time, int months)
- {
- return _helper.AddMonths(time, months);
- }
-
- public override DateTime AddYears(DateTime time, int years)
- {
- return _helper.AddYears(time, years);
- }
-
- public override int GetDaysInMonth(int year, int month, int era)
- {
- return _helper.GetDaysInMonth(year, month, era);
- }
-
- public override int GetDaysInYear(int year, int era)
- {
- return _helper.GetDaysInYear(year, era);
- }
-
- public override int GetDayOfMonth(DateTime time)
- {
- return _helper.GetDayOfMonth(time);
- }
-
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
- return _helper.GetDayOfWeek(time);
- }
-
- public override int GetDayOfYear(DateTime time)
- {
- return _helper.GetDayOfYear(time);
- }
-
- public override int GetMonthsInYear(int year, int era)
- {
- return _helper.GetMonthsInYear(year, era);
- }
-
- public override int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
- {
- return _helper.GetWeekOfYear(time, rule, firstDayOfWeek);
- }
-
- public override int GetEra(DateTime time)
- {
- return _helper.GetEra(time);
- }
-
- public override int GetMonth(DateTime time)
- {
- return _helper.GetMonth(time);
- }
-
- public override int GetYear(DateTime time)
- {
- return _helper.GetYear(time);
- }
-
- public override bool IsLeapDay(int year, int month, int day, int era)
- {
- return _helper.IsLeapDay(year, month, day, era);
- }
-
- public override bool IsLeapYear(int year, int era)
- {
- return _helper.IsLeapYear(year, era);
- }
-
- public override int GetLeapMonth(int year, int era)
- {
- return _helper.GetLeapMonth(year, era);
- }
-
- public override bool IsLeapMonth(int year, int month, int era)
- {
- return _helper.IsLeapMonth(year, month, era);
- }
-
- public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- return _helper.ToDateTime(year, month, day, hour, minute, second, millisecond, era);
- }
-
- public override int[] Eras => _helper.Eras;
-
- private const int DefaultTwoDigitYearMax = 2572;
-
-
- public override int TwoDigitYearMax
- {
- get
- {
- if (_twoDigitYearMax == -1)
- {
- _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultTwoDigitYearMax);
- }
-
- return _twoDigitYearMax;
- }
- set
- {
- VerifyWritable();
- if (value < 99 || value > _helper.MaxYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, 99, _helper.MaxYear));
- }
-
- _twoDigitYearMax = value;
- }
- }
-
- public override int ToFourDigitYear(int year)
- {
- if (year < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return _helper.ToFourDigitYear(year, TwoDigitYearMax);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanFormat.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanFormat.cs
deleted file mode 100644
index 08ffc3269aa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanFormat.cs
+++ /dev/null
@@ -1,658 +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 System.Buffers.Text;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System.Globalization
-{
- internal static class TimeSpanFormat
- {
- internal static readonly FormatLiterals PositiveInvariantFormatLiterals = TimeSpanFormat.FormatLiterals.InitInvariant(isNegative: false);
- internal static readonly FormatLiterals NegativeInvariantFormatLiterals = TimeSpanFormat.FormatLiterals.InitInvariant(isNegative: true);
-
- /// <summary>Main method called from TimeSpan.ToString.</summary>
- internal static string Format(TimeSpan value, string? format, IFormatProvider? formatProvider)
- {
- if (string.IsNullOrEmpty(format))
- {
- return FormatC(value); // formatProvider ignored, as "c" is invariant
- }
-
- if (format.Length == 1)
- {
- char c = format[0];
-
- if (c == 'c' || (c | 0x20) == 't') // special-case to optimize the default TimeSpan format
- {
- return FormatC(value); // formatProvider ignored, as "c" is invariant
- }
-
- if ((c | 0x20) == 'g') // special-case to optimize the remaining 'g'/'G' standard formats
- {
- return FormatG(value, DateTimeFormatInfo.GetInstance(formatProvider), c == 'G' ? StandardFormat.G : StandardFormat.g);
- }
-
- throw new FormatException(SR.Format_InvalidString);
- }
-
- return StringBuilderCache.GetStringAndRelease(FormatCustomized(value, format, DateTimeFormatInfo.GetInstance(formatProvider), result: null));
- }
-
- /// <summary>Main method called from TimeSpan.TryFormat.</summary>
- internal static bool TryFormat(TimeSpan value, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? formatProvider)
- {
- if (format.Length == 0)
- {
- return TryFormatStandard(value, StandardFormat.C, null, destination, out charsWritten);
- }
-
- if (format.Length == 1)
- {
- char c = format[0];
- if (c == 'c' || ((c | 0x20) == 't'))
- {
- return TryFormatStandard(value, StandardFormat.C, null, destination, out charsWritten);
- }
- else
- {
- StandardFormat sf =
- c == 'g' ? StandardFormat.g :
- c == 'G' ? StandardFormat.G :
- throw new FormatException(SR.Format_InvalidString);
- return TryFormatStandard(value, sf, DateTimeFormatInfo.GetInstance(formatProvider).DecimalSeparator, destination, out charsWritten);
- }
- }
-
- StringBuilder sb = FormatCustomized(value, format, DateTimeFormatInfo.GetInstance(formatProvider), result: null);
-
- if (sb.Length <= destination.Length)
- {
- sb.CopyTo(0, destination, sb.Length);
- charsWritten = sb.Length;
- StringBuilderCache.Release(sb);
- return true;
- }
-
- charsWritten = 0;
- StringBuilderCache.Release(sb);
- return false;
- }
-
- internal static string FormatC(TimeSpan value)
- {
- Span<char> destination = stackalloc char[26]; // large enough for any "c" TimeSpan
- TryFormatStandard(value, StandardFormat.C, null, destination, out int charsWritten);
- return new string(destination.Slice(0, charsWritten));
- }
-
- private static string FormatG(TimeSpan value, DateTimeFormatInfo dtfi, StandardFormat format)
- {
- string decimalSeparator = dtfi.DecimalSeparator;
- int maxLength = 25 + decimalSeparator.Length; // large enough for any "g"/"G" TimeSpan
- Span<char> destination = maxLength < 128 ?
- stackalloc char[maxLength] :
- new char[maxLength]; // the chances of needing this case are almost 0, as DecimalSeparator.Length will basically always == 1
- TryFormatStandard(value, format, decimalSeparator, destination, out int charsWritten);
- return new string(destination.Slice(0, charsWritten));
- }
-
- private enum StandardFormat { C, G, g }
-
- private static bool TryFormatStandard(TimeSpan value, StandardFormat format, string? decimalSeparator, Span<char> destination, out int charsWritten)
- {
- Debug.Assert(format == StandardFormat.C || format == StandardFormat.G || format == StandardFormat.g);
-
- // First, calculate how large an output buffer is needed to hold the entire output.
- int requiredOutputLength = 8; // start with "hh:mm:ss" and adjust as necessary
-
- uint fraction;
- ulong totalSecondsRemaining;
- {
- // Turn this into a non-negative TimeSpan if possible.
- long ticks = value.Ticks;
- if (ticks < 0)
- {
- requiredOutputLength = 9; // requiredOutputLength + 1 for the leading '-' sign
- ticks = -ticks;
- if (ticks < 0)
- {
- Debug.Assert(ticks == long.MinValue /* -9223372036854775808 */);
-
- // We computed these ahead of time; they're straight from the decimal representation of Int64.MinValue.
- fraction = 4775808;
- totalSecondsRemaining = 922337203685;
- goto AfterComputeFraction;
- }
- }
-
- totalSecondsRemaining = Math.DivRem((ulong)ticks, TimeSpan.TicksPerSecond, out ulong fraction64);
- fraction = (uint)fraction64;
- }
-
- AfterComputeFraction:
- // Only write out the fraction if it's non-zero, and in that
- // case write out the entire fraction (all digits).
- Debug.Assert(fraction < 10_000_000);
- int fractionDigits = 0;
- switch (format)
- {
- case StandardFormat.C:
- // "c": Write out a fraction only if it's non-zero, and write out all 7 digits of it.
- if (fraction != 0)
- {
- fractionDigits = DateTimeFormat.MaxSecondsFractionDigits;
- requiredOutputLength += fractionDigits + 1; // digits plus leading decimal separator
- }
- break;
-
- case StandardFormat.G:
- // "G": Write out a fraction regardless of whether it's 0, and write out all 7 digits of it.
- fractionDigits = DateTimeFormat.MaxSecondsFractionDigits;
- requiredOutputLength += fractionDigits + 1; // digits plus leading decimal separator
- break;
-
- default:
- // "g": Write out a fraction only if it's non-zero, and write out only the most significant digits.
- Debug.Assert(format == StandardFormat.g);
- if (fraction != 0)
- {
- fractionDigits = DateTimeFormat.MaxSecondsFractionDigits - FormattingHelpers.CountDecimalTrailingZeros(fraction, out fraction);
- requiredOutputLength += fractionDigits + 1; // digits plus leading decimal separator
- }
- break;
- }
-
- ulong totalMinutesRemaining = 0, seconds = 0;
- if (totalSecondsRemaining > 0)
- {
- // Only compute minutes if the TimeSpan has an absolute value of >= 1 minute.
- totalMinutesRemaining = Math.DivRem(totalSecondsRemaining, 60 /* seconds per minute */, out seconds);
- Debug.Assert(seconds < 60);
- }
-
- ulong totalHoursRemaining = 0, minutes = 0;
- if (totalMinutesRemaining > 0)
- {
- // Only compute hours if the TimeSpan has an absolute value of >= 1 hour.
- totalHoursRemaining = Math.DivRem(totalMinutesRemaining, 60 /* minutes per hour */, out minutes);
- Debug.Assert(minutes < 60);
- }
-
- // At this point, we can switch over to 32-bit DivRem since the data has shrunk far enough.
- Debug.Assert(totalHoursRemaining <= uint.MaxValue);
-
- uint days = 0, hours = 0;
- if (totalHoursRemaining > 0)
- {
- // Only compute days if the TimeSpan has an absolute value of >= 1 day.
- days = Math.DivRem((uint)totalHoursRemaining, 24 /* hours per day */, out hours);
- Debug.Assert(hours < 24);
- }
-
- int hourDigits = 2;
- if (format == StandardFormat.g && hours < 10)
- {
- // "g": Only writing a one-digit hour, rather than expected two-digit hour
- hourDigits = 1;
- requiredOutputLength--;
- }
-
- int dayDigits = 0;
- if (days > 0)
- {
- dayDigits = FormattingHelpers.CountDigits(days);
- Debug.Assert(dayDigits <= 8);
- requiredOutputLength += dayDigits + 1; // for the leading "d."
- }
- else if (format == StandardFormat.G)
- {
- // "G": has a leading "0:" if days is 0
- requiredOutputLength += 2;
- dayDigits = 1;
- }
-
- if (destination.Length < requiredOutputLength)
- {
- charsWritten = 0;
- return false;
- }
-
- // Write leading '-' if necessary
- int idx = 0;
- if (value.Ticks < 0)
- {
- destination[idx++] = '-';
- }
-
- // Write day and separator, if necessary
- if (dayDigits != 0)
- {
- WriteDigits(days, destination.Slice(idx, dayDigits));
- idx += dayDigits;
- destination[idx++] = format == StandardFormat.C ? '.' : ':';
- }
-
- // Write "[h]h:mm:ss
- Debug.Assert(hourDigits == 1 || hourDigits == 2);
- if (hourDigits == 2)
- {
- WriteTwoDigits(hours, destination.Slice(idx));
- idx += 2;
- }
- else
- {
- destination[idx++] = (char)('0' + hours);
- }
- destination[idx++] = ':';
- WriteTwoDigits((uint)minutes, destination.Slice(idx));
- idx += 2;
- destination[idx++] = ':';
- WriteTwoDigits((uint)seconds, destination.Slice(idx));
- idx += 2;
-
- // Write fraction and separator, if necessary
- if (fractionDigits != 0)
- {
- Debug.Assert(format == StandardFormat.C || decimalSeparator != null);
- if (format == StandardFormat.C)
- {
- destination[idx++] = '.';
- }
- else if (decimalSeparator!.Length == 1)
- {
- destination[idx++] = decimalSeparator[0];
- }
- else
- {
- decimalSeparator.AsSpan().CopyTo(destination);
- idx += decimalSeparator.Length;
- }
- WriteDigits(fraction, destination.Slice(idx, fractionDigits));
- idx += fractionDigits;
- }
-
- Debug.Assert(idx == requiredOutputLength);
- charsWritten = requiredOutputLength;
- return true;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void WriteTwoDigits(uint value, Span<char> buffer)
- {
- Debug.Assert(buffer.Length >= 2);
- uint temp = '0' + value;
- value /= 10;
- buffer[1] = (char)(temp - (value * 10));
- buffer[0] = (char)('0' + value);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void WriteDigits(uint value, Span<char> buffer)
- {
- Debug.Assert(buffer.Length > 0);
-
- for (int i = buffer.Length - 1; i >= 1; i--)
- {
- uint temp = '0' + value;
- value /= 10;
- buffer[i] = (char)(temp - (value * 10));
- }
-
- Debug.Assert(value < 10);
- buffer[0] = (char)('0' + value);
- }
-
- /// <summary>Format the TimeSpan instance using the specified format.</summary>
- private static StringBuilder FormatCustomized(TimeSpan value, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, StringBuilder? result = null)
- {
- Debug.Assert(dtfi != null);
-
- bool resultBuilderIsPooled = false;
- if (result == null)
- {
- result = StringBuilderCache.Acquire(InternalGlobalizationHelper.StringBuilderDefaultCapacity);
- resultBuilderIsPooled = true;
- }
-
- int day = (int)(value.Ticks / TimeSpan.TicksPerDay);
- long time = value.Ticks % TimeSpan.TicksPerDay;
-
- if (value.Ticks < 0)
- {
- day = -day;
- time = -time;
- }
- int hours = (int)(time / TimeSpan.TicksPerHour % 24);
- int minutes = (int)(time / TimeSpan.TicksPerMinute % 60);
- int seconds = (int)(time / TimeSpan.TicksPerSecond % 60);
- int fraction = (int)(time % TimeSpan.TicksPerSecond);
-
- long tmp = 0;
- int i = 0;
- int tokenLen;
-
- while (i < format.Length)
- {
- char ch = format[i];
- int nextChar;
- switch (ch)
- {
- case 'h':
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > 2)
- {
- goto default; // to release the builder and throw
- }
- DateTimeFormat.FormatDigits(result, hours, tokenLen);
- break;
- case 'm':
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > 2)
- {
- goto default; // to release the builder and throw
- }
- DateTimeFormat.FormatDigits(result, minutes, tokenLen);
- break;
- case 's':
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > 2)
- {
- goto default; // to release the builder and throw
- }
- DateTimeFormat.FormatDigits(result, seconds, tokenLen);
- break;
- case 'f':
- //
- // The fraction of a second in single-digit precision. The remaining digits are truncated.
- //
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > DateTimeFormat.MaxSecondsFractionDigits)
- {
- goto default; // to release the builder and throw
- }
-
- tmp = fraction;
- tmp /= TimeSpanParse.Pow10(DateTimeFormat.MaxSecondsFractionDigits - tokenLen);
- result.AppendSpanFormattable(tmp, DateTimeFormat.fixedNumberFormats[tokenLen - 1], CultureInfo.InvariantCulture);
- break;
- case 'F':
- //
- // Displays the most significant digit of the seconds fraction. Nothing is displayed if the digit is zero.
- //
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > DateTimeFormat.MaxSecondsFractionDigits)
- {
- goto default; // to release the builder and throw
- }
-
- tmp = fraction;
- tmp /= TimeSpanParse.Pow10(DateTimeFormat.MaxSecondsFractionDigits - tokenLen);
- int effectiveDigits = tokenLen;
- while (effectiveDigits > 0)
- {
- if (tmp % 10 == 0)
- {
- tmp /= 10;
- effectiveDigits--;
- }
- else
- {
- break;
- }
- }
- if (effectiveDigits > 0)
- {
- result.AppendSpanFormattable(tmp, DateTimeFormat.fixedNumberFormats[effectiveDigits - 1], CultureInfo.InvariantCulture);
- }
- break;
- case 'd':
- //
- // tokenLen == 1 : Day as digits with no leading zero.
- // tokenLen == 2+: Day as digits with leading zero for single-digit days.
- //
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > 8)
- {
- goto default; // to release the builder and throw
- }
-
- DateTimeFormat.FormatDigits(result, day, tokenLen, true);
- break;
- case '\'':
- case '\"':
- tokenLen = DateTimeFormat.ParseQuoteString(format, i, result);
- break;
- case '%':
- // Optional format character.
- // For example, format string "%d" will print day
- // Most of the cases, "%" can be ignored.
- nextChar = DateTimeFormat.ParseNextChar(format, i);
- // nextChar will be -1 if we already reach the end of the format string.
- // Besides, we will not allow "%%" appear in the pattern.
- if (nextChar >= 0 && nextChar != (int)'%')
- {
- char nextCharChar = (char)nextChar;
- StringBuilder origStringBuilder = FormatCustomized(value, MemoryMarshal.CreateReadOnlySpan<char>(ref nextCharChar, 1), dtfi, result);
- Debug.Assert(ReferenceEquals(origStringBuilder, result));
- tokenLen = 2;
- }
- else
- {
- //
- // This means that '%' is at the end of the format string or
- // "%%" appears in the format string.
- //
- goto default; // to release the builder and throw
- }
- break;
- case '\\':
- // Escaped character. Can be used to insert character into the format string.
- // For example, "\d" will insert the character 'd' into the string.
- //
- nextChar = DateTimeFormat.ParseNextChar(format, i);
- if (nextChar >= 0)
- {
- result.Append((char)nextChar);
- tokenLen = 2;
- }
- else
- {
- //
- // This means that '\' is at the end of the formatting string.
- //
- goto default; // to release the builder and throw
- }
- break;
- default:
- // Invalid format string
- if (resultBuilderIsPooled)
- {
- StringBuilderCache.Release(result);
- }
- throw new FormatException(SR.Format_InvalidString);
- }
- i += tokenLen;
- }
- return result;
- }
-
- internal struct FormatLiterals
- {
- internal string AppCompatLiteral;
- internal int dd;
- internal int hh;
- internal int mm;
- internal int ss;
- internal int ff;
-
- private string[] _literals;
-
- internal string Start => _literals[0];
- internal string DayHourSep => _literals[1];
- internal string HourMinuteSep => _literals[2];
- internal string MinuteSecondSep => _literals[3];
- internal string SecondFractionSep => _literals[4];
- internal string End => _literals[5];
-
- /* factory method for static invariant FormatLiterals */
- internal static FormatLiterals InitInvariant(bool isNegative)
- {
- FormatLiterals x = default;
- x._literals = new string[6];
- x._literals[0] = isNegative ? "-" : string.Empty;
- x._literals[1] = ".";
- x._literals[2] = ":";
- x._literals[3] = ":";
- x._literals[4] = ".";
- x._literals[5] = string.Empty;
- x.AppCompatLiteral = ":."; // MinuteSecondSep+SecondFractionSep;
- x.dd = 2;
- x.hh = 2;
- x.mm = 2;
- x.ss = 2;
- x.ff = DateTimeFormat.MaxSecondsFractionDigits;
- return x;
- }
-
- // For the "v1" TimeSpan localized patterns, the data is simply literal field separators with
- // the constants guaranteed to include DHMSF ordered greatest to least significant.
- // Once the data becomes more complex than this we will need to write a proper tokenizer for
- // parsing and formatting
- internal void Init(ReadOnlySpan<char> format, bool useInvariantFieldLengths)
- {
- dd = hh = mm = ss = ff = 0;
- _literals = new string[6];
- for (int i = 0; i < _literals.Length; i++)
- {
- _literals[i] = string.Empty;
- }
-
- StringBuilder sb = StringBuilderCache.Acquire(InternalGlobalizationHelper.StringBuilderDefaultCapacity);
- bool inQuote = false;
- char quote = '\'';
- int field = 0;
-
- for (int i = 0; i < format.Length; i++)
- {
- switch (format[i])
- {
- case '\'':
- case '\"':
- if (inQuote && (quote == format[i]))
- {
- /* we were in a quote and found a matching exit quote, so we are outside a quote now */
- if (field >= 0 && field <= 5)
- {
- _literals[field] = sb.ToString();
- sb.Length = 0;
- inQuote = false;
- }
- else
- {
- Debug.Fail($"Unexpected field value: {field}");
- return; // how did we get here?
- }
- }
- else if (!inQuote)
- {
- /* we are at the start of a new quote block */
- quote = format[i];
- inQuote = true;
- }
- else
- {
- /* we were in a quote and saw the other type of quote character, so we are still in a quote */
- }
- break;
- case '%':
- Debug.Fail("Unexpected special token '%', Bug in DateTimeFormatInfo.FullTimeSpan[Positive|Negative]Pattern");
- goto default;
- case '\\':
- if (!inQuote)
- {
- i++; /* skip next character that is escaped by this backslash or percent sign */
- break;
- }
- goto default;
- case 'd':
- if (!inQuote)
- {
- Debug.Assert((field == 0 && sb.Length == 0) || field == 1, "field == 0 || field == 1, Bug in DateTimeFormatInfo.FullTimeSpan[Positive|Negative]Pattern");
- field = 1; // DayHourSep
- dd++;
- }
- break;
- case 'h':
- if (!inQuote)
- {
- Debug.Assert((field == 1 && sb.Length == 0) || field == 2, "field == 1 || field == 2, Bug in DateTimeFormatInfo.FullTimeSpan[Positive|Negative]Pattern");
- field = 2; // HourMinuteSep
- hh++;
- }
- break;
- case 'm':
- if (!inQuote)
- {
- Debug.Assert((field == 2 && sb.Length == 0) || field == 3, "field == 2 || field == 3, Bug in DateTimeFormatInfo.FullTimeSpan[Positive|Negative]Pattern");
- field = 3; // MinuteSecondSep
- mm++;
- }
- break;
- case 's':
- if (!inQuote)
- {
- Debug.Assert((field == 3 && sb.Length == 0) || field == 4, "field == 3 || field == 4, Bug in DateTimeFormatInfo.FullTimeSpan[Positive|Negative]Pattern");
- field = 4; // SecondFractionSep
- ss++;
- }
- break;
- case 'f':
- case 'F':
- if (!inQuote)
- {
- Debug.Assert((field == 4 && sb.Length == 0) || field == 5, "field == 4 || field == 5, Bug in DateTimeFormatInfo.FullTimeSpan[Positive|Negative]Pattern");
- field = 5; // End
- ff++;
- }
- break;
- default:
- sb.Append(format[i]);
- break;
- }
- }
-
- Debug.Assert(field == 5);
- AppCompatLiteral = MinuteSecondSep + SecondFractionSep;
-
- Debug.Assert(0 < dd && dd < 3, "0 < dd && dd < 3, Bug in System.Globalization.DateTimeFormatInfo.FullTimeSpan[Positive|Negative]Pattern");
- Debug.Assert(0 < hh && hh < 3, "0 < hh && hh < 3, Bug in System.Globalization.DateTimeFormatInfo.FullTimeSpan[Positive|Negative]Pattern");
- Debug.Assert(0 < mm && mm < 3, "0 < mm && mm < 3, Bug in System.Globalization.DateTimeFormatInfo.FullTimeSpan[Positive|Negative]Pattern");
- Debug.Assert(0 < ss && ss < 3, "0 < ss && ss < 3, Bug in System.Globalization.DateTimeFormatInfo.FullTimeSpan[Positive|Negative]Pattern");
- Debug.Assert(0 < ff && ff < 8, "0 < ff && ff < 8, Bug in System.Globalization.DateTimeFormatInfo.FullTimeSpan[Positive|Negative]Pattern");
-
- if (useInvariantFieldLengths)
- {
- dd = 2;
- hh = 2;
- mm = 2;
- ss = 2;
- ff = DateTimeFormat.MaxSecondsFractionDigits;
- }
- else
- {
- if (dd < 1 || dd > 2) dd = 2; // The DTFI property has a problem. let's try to make the best of the situation.
- if (hh < 1 || hh > 2) hh = 2;
- if (mm < 1 || mm > 2) mm = 2;
- if (ss < 1 || ss > 2) ss = 2;
- if (ff < 1 || ff > 7) ff = 7;
- }
- StringBuilderCache.Release(sb);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs
deleted file mode 100644
index 0a2df773409..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs
+++ /dev/null
@@ -1,1705 +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.
-
-////////////////////////////////////////////////////////////////////////////
-//
-// Purpose: Used by TimeSpan to parse a time interval string.
-//
-// Standard Format:
-// -=-=-=-=-=-=-=-
-// "c": Constant format. [-][d'.']hh':'mm':'ss['.'fffffff]
-// Not culture sensitive. Default format (and null/empty format string) map to this format.
-//
-// "g": General format, short: [-][d':']h':'mm':'ss'.'FFFFFFF
-// Only print what's needed. Localized (if you want Invariant, pass in Invariant).
-// The fractional seconds separator is localized, equal to the culture's DecimalSeparator.
-//
-// "G": General format, long: [-]d':'hh':'mm':'ss'.'fffffff
-// Always print days and 7 fractional digits. Localized (if you want Invariant, pass in Invariant).
-// The fractional seconds separator is localized, equal to the culture's DecimalSeparator.
-//
-// * "TryParseTimeSpan" is the main method for Parse/TryParse
-//
-// - TimeSpanTokenizer.GetNextToken() is used to split the input string into number and literal tokens.
-// - TimeSpanRawInfo.ProcessToken() adds the next token into the parsing intermediary state structure
-// - ProcessTerminalState() uses the fully initialized TimeSpanRawInfo to find a legal parse match.
-// The terminal states are attempted as follows:
-// foreach (+InvariantPattern, -InvariantPattern, +LocalizedPattern, -LocalizedPattern) try
-// 1 number => d
-// 2 numbers => h:m
-// 3 numbers => h:m:s | d.h:m | h:m:.f
-// 4 numbers => h:m:s.f | d.h:m:s | d.h:m:.f
-// 5 numbers => d.h:m:s.f
-//
-// Custom Format:
-// -=-=-=-=-=-=-=
-//
-// * "TryParseExactTimeSpan" is the main method for ParseExact/TryParseExact methods
-// * "TryParseExactMultipleTimeSpan" is the main method for ParseExact/TryparseExact
-// methods that take a string[] of formats
-//
-// - For single-letter formats "TryParseTimeSpan" is called (see above)
-// - For multi-letter formats "TryParseByFormat" is called
-// - TryParseByFormat uses helper methods (ParseExactLiteral, ParseExactDigits, etc)
-// which drive the underlying TimeSpanTokenizer. However, unlike standard formatting which
-// operates on whole-tokens, ParseExact operates at the character-level. As such,
-// TimeSpanTokenizer.NextChar and TimeSpanTokenizer.BackOne() are called directly.
-//
-////////////////////////////////////////////////////////////////////////////
-
-using System.Diagnostics;
-using System.Text;
-
-namespace System.Globalization
-{
- internal static class TimeSpanParse
- {
- private const int MaxFractionDigits = 7;
- private const int MaxDays = 10675199;
- private const int MaxHours = 23;
- private const int MaxMinutes = 59;
- private const int MaxSeconds = 59;
- private const int MaxFraction = 9999999;
-
- [Flags]
- private enum TimeSpanStandardStyles : byte
- {
- // Standard Format Styles
- None = 0x00000000,
- Invariant = 0x00000001, // Allow Invariant Culture
- Localized = 0x00000002, // Allow Localized Culture
- RequireFull = 0x00000004, // Require the input to be in DHMSF format
- Any = Invariant | Localized,
- }
-
- // TimeSpan Token Types
- private enum TTT : byte
- {
- None = 0, // None of the TimeSpanToken fields are set
- End = 1, // '\0'
- Num = 2, // Number
- Sep = 3, // literal
- NumOverflow = 4, // Number that overflowed
- }
-
- private ref struct TimeSpanToken
- {
- internal TTT _ttt;
- internal int _num; // Store the number that we are parsing (if any)
- internal int _zeroes; // Store the number of leading zeroes (if any)
- internal ReadOnlySpan<char> _sep; // Store the literal that we are parsing (if any)
-
- public TimeSpanToken(TTT type) : this(type, 0, 0, default) { }
-
- public TimeSpanToken(int number) : this(TTT.Num, number, 0, default) { }
-
- public TimeSpanToken(int number, int leadingZeroes) : this(TTT.Num, number, leadingZeroes, default) { }
-
- public TimeSpanToken(TTT type, int number, int leadingZeroes, ReadOnlySpan<char> separator)
- {
- _ttt = type;
- _num = number;
- _zeroes = leadingZeroes;
- _sep = separator;
- }
-
- public bool NormalizeAndValidateFraction()
- {
- Debug.Assert(_ttt == TTT.Num);
- Debug.Assert(_num > -1);
-
- if (_num == 0)
- return true;
-
- if (_zeroes == 0 && _num > MaxFraction)
- return false;
-
- int totalDigitsCount = ((int)Math.Floor(Math.Log10(_num))) + 1 + _zeroes;
-
- if (totalDigitsCount == MaxFractionDigits)
- {
- // Already normalized. no more action needed
- // .9999999 normalize to 9,999,999 ticks
- // .0000001 normalize to 1 ticks
- return true;
- }
-
- if (totalDigitsCount < MaxFractionDigits)
- {
- // normalize the fraction to the 7-digits
- // .999999 normalize to 9,999,990 ticks
- // .99999 normalize to 9,999,900 ticks
- // .000001 normalize to 10 ticks
- // .1 normalize to 1,000,000 ticks
-
- _num *= (int)Pow10(MaxFractionDigits - totalDigitsCount);
- return true;
- }
-
- // totalDigitsCount is greater then MaxFractionDigits, we'll need to do the rounding to 7-digits length
- // .00000001 normalized to 0 ticks
- // .00000005 normalized to 1 ticks
- // .09999999 normalize to 1,000,000 ticks
- // .099999999 normalize to 1,000,000 ticks
-
- Debug.Assert(_zeroes > 0); // Already validated that in the condition _zeroes == 0 && _num > MaxFraction
- _num = (int)Math.Round((double)_num / Pow10(totalDigitsCount - MaxFractionDigits), MidpointRounding.AwayFromZero);
- Debug.Assert(_num < MaxFraction);
-
- return true;
- }
- }
-
- private ref struct TimeSpanTokenizer
- {
- private readonly ReadOnlySpan<char> _value;
- private int _pos;
-
- internal TimeSpanTokenizer(ReadOnlySpan<char> input) : this(input, 0) { }
-
- internal TimeSpanTokenizer(ReadOnlySpan<char> input, int startPosition)
- {
- _value = input;
- _pos = startPosition;
- }
-
- /// <summary>Returns the next token in the input string</summary>
- /// <remarks>Used by the parsing routines that operate on standard-formats.</remarks>
- internal TimeSpanToken GetNextToken()
- {
- // Get the position of the next character to be processed. If there is no
- // next character, we're at the end.
- int pos = _pos;
- Debug.Assert(pos > -1);
- if (pos >= _value.Length)
- {
- return new TimeSpanToken(TTT.End);
- }
-
- // Now retrieve that character. If it's a digit, we're processing a number.
- int num = _value[pos] - '0';
- if ((uint)num <= 9)
- {
- int zeroes = 0;
- if (num == 0)
- {
- // Read all leading zeroes.
- zeroes = 1;
- while (true)
- {
- int digit;
- if (++_pos >= _value.Length || (uint)(digit = _value[_pos] - '0') > 9)
- {
- return new TimeSpanToken(TTT.Num, 0, zeroes, default);
- }
-
- if (digit == 0)
- {
- zeroes++;
- continue;
- }
-
- num = digit;
- break;
- }
- }
-
- // Continue to read as long as we're reading digits.
- while (++_pos < _value.Length)
- {
- int digit = _value[_pos] - '0';
- if ((uint)digit > 9)
- {
- break;
- }
-
- num = num * 10 + digit;
- if ((num & 0xF0000000) != 0) // Max limit we can support 268435455 which is FFFFFFF
- {
- return new TimeSpanToken(TTT.NumOverflow);
- }
- }
-
- return new TimeSpanToken(TTT.Num, num, zeroes, default);
- }
-
- // Otherwise, we're processing a separator, and we've already processed the first
- // character of it. Continue processing characters as long as they're not digits.
- int length = 1;
- while (true)
- {
- if (++_pos >= _value.Length || (uint)(_value[_pos] - '0') <= 9)
- {
- break;
- }
- length++;
- }
-
- // Return the separator.
- return new TimeSpanToken(TTT.Sep, 0, 0, _value.Slice(pos, length));
- }
-
- internal bool EOL => _pos >= (_value.Length - 1);
-
- internal void BackOne()
- {
- if (_pos > 0) --_pos;
- }
-
- internal char NextChar
- {
- get
- {
- int pos = ++_pos;
- return (uint)pos < (uint)_value.Length ?
- _value[pos] :
- (char)0;
- }
- }
- }
-
- /// <summary>Stores intermediary parsing state for the standard formats.</summary>
- private ref struct TimeSpanRawInfo
- {
- internal TimeSpanFormat.FormatLiterals PositiveLocalized
- {
- get
- {
- if (!_posLocInit)
- {
- _posLoc = default;
- _posLoc.Init(_fullPosPattern, false);
- _posLocInit = true;
- }
- return _posLoc;
- }
- }
-
- internal TimeSpanFormat.FormatLiterals NegativeLocalized
- {
- get
- {
- if (!_negLocInit)
- {
- _negLoc = default;
- _negLoc.Init(_fullNegPattern, false);
- _negLocInit = true;
- }
- return _negLoc;
- }
- }
-
- internal bool FullAppCompatMatch(TimeSpanFormat.FormatLiterals pattern) =>
- _sepCount == 5
- && _numCount == 4
- && _literals0.EqualsOrdinal(pattern.Start)
- && _literals1.EqualsOrdinal(pattern.DayHourSep)
- && _literals2.EqualsOrdinal(pattern.HourMinuteSep)
- && _literals3.EqualsOrdinal(pattern.AppCompatLiteral)
- && _literals4.EqualsOrdinal(pattern.End);
-
- internal bool PartialAppCompatMatch(TimeSpanFormat.FormatLiterals pattern) =>
- _sepCount == 4
- && _numCount == 3
- && _literals0.EqualsOrdinal(pattern.Start)
- && _literals1.EqualsOrdinal(pattern.HourMinuteSep)
- && _literals2.EqualsOrdinal(pattern.AppCompatLiteral)
- && _literals3.EqualsOrdinal(pattern.End);
-
- /// <summary>DHMSF (all values matched)</summary>
- internal bool FullMatch(TimeSpanFormat.FormatLiterals pattern) =>
- _sepCount == MaxLiteralTokens
- && _numCount == MaxNumericTokens
- && _literals0.EqualsOrdinal(pattern.Start)
- && _literals1.EqualsOrdinal(pattern.DayHourSep)
- && _literals2.EqualsOrdinal(pattern.HourMinuteSep)
- && _literals3.EqualsOrdinal(pattern.MinuteSecondSep)
- && _literals4.EqualsOrdinal(pattern.SecondFractionSep)
- && _literals5.EqualsOrdinal(pattern.End);
-
- /// <summary>D (no hours, minutes, seconds, or fractions)</summary>
- internal bool FullDMatch(TimeSpanFormat.FormatLiterals pattern) =>
- _sepCount == 2
- && _numCount == 1
- && _literals0.EqualsOrdinal(pattern.Start)
- && _literals1.EqualsOrdinal(pattern.End);
-
- /// <summary>HM (no days, seconds, or fractions)</summary>
- internal bool FullHMMatch(TimeSpanFormat.FormatLiterals pattern) =>
- _sepCount == 3
- && _numCount == 2
- && _literals0.EqualsOrdinal(pattern.Start)
- && _literals1.EqualsOrdinal(pattern.HourMinuteSep)
- && _literals2.EqualsOrdinal(pattern.End);
-
- /// <summary>DHM (no seconds or fraction)</summary>
- internal bool FullDHMMatch(TimeSpanFormat.FormatLiterals pattern) =>
- _sepCount == 4
- && _numCount == 3
- && _literals0.EqualsOrdinal(pattern.Start)
- && _literals1.EqualsOrdinal(pattern.DayHourSep)
- && _literals2.EqualsOrdinal(pattern.HourMinuteSep)
- && _literals3.EqualsOrdinal(pattern.End);
-
- /// <summary>HMS (no days or fraction)</summary>
- internal bool FullHMSMatch(TimeSpanFormat.FormatLiterals pattern) =>
- _sepCount == 4
- && _numCount == 3
- && _literals0.EqualsOrdinal(pattern.Start)
- && _literals1.EqualsOrdinal(pattern.HourMinuteSep)
- && _literals2.EqualsOrdinal(pattern.MinuteSecondSep)
- && _literals3.EqualsOrdinal(pattern.End);
-
- /// <summary>DHMS (no fraction)</summary>
- internal bool FullDHMSMatch(TimeSpanFormat.FormatLiterals pattern) =>
- _sepCount == 5
- && _numCount == 4
- && _literals0.EqualsOrdinal(pattern.Start)
- && _literals1.EqualsOrdinal(pattern.DayHourSep)
- && _literals2.EqualsOrdinal(pattern.HourMinuteSep)
- && _literals3.EqualsOrdinal(pattern.MinuteSecondSep)
- && _literals4.EqualsOrdinal(pattern.End);
-
- /// <summary>HMSF (no days)</summary>
- internal bool FullHMSFMatch(TimeSpanFormat.FormatLiterals pattern) =>
- _sepCount == 5
- && _numCount == 4
- && _literals0.EqualsOrdinal(pattern.Start)
- && _literals1.EqualsOrdinal(pattern.HourMinuteSep)
- && _literals2.EqualsOrdinal(pattern.MinuteSecondSep)
- && _literals3.EqualsOrdinal(pattern.SecondFractionSep)
- && _literals4.EqualsOrdinal(pattern.End);
-
- internal TTT _lastSeenTTT;
- internal int _tokenCount;
- internal int _sepCount;
- internal int _numCount;
-
- private TimeSpanFormat.FormatLiterals _posLoc;
- private TimeSpanFormat.FormatLiterals _negLoc;
- private bool _posLocInit;
- private bool _negLocInit;
- private string _fullPosPattern;
- private string _fullNegPattern;
-
- private const int MaxTokens = 11;
- private const int MaxLiteralTokens = 6;
- private const int MaxNumericTokens = 5;
-
- internal TimeSpanToken _numbers0, _numbers1, _numbers2, _numbers3, _numbers4; // MaxNumbericTokens = 5
- internal ReadOnlySpan<char> _literals0, _literals1, _literals2, _literals3, _literals4, _literals5; // MaxLiteralTokens=6
-
- internal void Init(DateTimeFormatInfo dtfi)
- {
- Debug.Assert(dtfi != null);
-
- _lastSeenTTT = TTT.None;
- _tokenCount = 0;
- _sepCount = 0;
- _numCount = 0;
-
- _fullPosPattern = dtfi.FullTimeSpanPositivePattern;
- _fullNegPattern = dtfi.FullTimeSpanNegativePattern;
- _posLocInit = false;
- _negLocInit = false;
- }
-
- internal bool ProcessToken(ref TimeSpanToken tok, ref TimeSpanResult result)
- {
- switch (tok._ttt)
- {
- case TTT.Num:
- if ((_tokenCount == 0 && !AddSep(default, ref result)) || !AddNum(tok, ref result))
- {
- return false;
- }
- break;
-
- case TTT.Sep:
- if (!AddSep(tok._sep, ref result))
- {
- return false;
- }
- break;
-
- case TTT.NumOverflow:
- return result.SetOverflowFailure();
-
- default:
- // Some unknown token or a repeat token type in the input
- return result.SetBadTimeSpanFailure();
- }
-
- _lastSeenTTT = tok._ttt;
- Debug.Assert(_tokenCount == (_sepCount + _numCount), "tokenCount == (SepCount + NumCount)");
- return true;
- }
-
- private bool AddSep(ReadOnlySpan<char> sep, ref TimeSpanResult result)
- {
- if (_sepCount >= MaxLiteralTokens || _tokenCount >= MaxTokens)
- {
- return result.SetBadTimeSpanFailure();
- }
-
- switch (_sepCount++)
- {
- case 0: _literals0 = sep; break;
- case 1: _literals1 = sep; break;
- case 2: _literals2 = sep; break;
- case 3: _literals3 = sep; break;
- case 4: _literals4 = sep; break;
- default: _literals5 = sep; break;
- }
-
- _tokenCount++;
- return true;
- }
- private bool AddNum(TimeSpanToken num, ref TimeSpanResult result)
- {
- if (_numCount >= MaxNumericTokens || _tokenCount >= MaxTokens)
- {
- return result.SetBadTimeSpanFailure();
- }
-
- switch (_numCount++)
- {
- case 0: _numbers0 = num; break;
- case 1: _numbers1 = num; break;
- case 2: _numbers2 = num; break;
- case 3: _numbers3 = num; break;
- default: _numbers4 = num; break;
- }
-
- _tokenCount++;
- return true;
- }
- }
-
- /// <summary>Store the result of the parsing.</summary>
- private ref struct TimeSpanResult
- {
- internal TimeSpan parsedTimeSpan;
- private readonly bool _throwOnFailure;
- private readonly ReadOnlySpan<char> _originalTimeSpanString;
-
- internal TimeSpanResult(bool throwOnFailure, ReadOnlySpan<char> originalTimeSpanString)
- {
- parsedTimeSpan = default;
- _throwOnFailure = throwOnFailure;
- _originalTimeSpanString = originalTimeSpanString;
- }
-
- internal bool SetNoFormatSpecifierFailure()
- {
- if (!_throwOnFailure)
- {
- return false;
- }
-
- throw new FormatException(SR.Format_NoFormatSpecifier);
- }
-
- internal bool SetBadQuoteFailure(char failingCharacter)
- {
- if (!_throwOnFailure)
- {
- return false;
- }
-
- throw new FormatException(SR.Format(SR.Format_BadQuote, failingCharacter));
- }
-
- internal bool SetInvalidStringFailure()
- {
- if (!_throwOnFailure)
- {
- return false;
- }
-
- throw new FormatException(SR.Format_InvalidString);
- }
-
- internal bool SetArgumentNullFailure(string argumentName)
- {
- if (!_throwOnFailure)
- {
- return false;
- }
-
- Debug.Assert(argumentName != null);
- throw new ArgumentNullException(argumentName, SR.ArgumentNull_String);
- }
-
- internal bool SetOverflowFailure()
- {
- if (!_throwOnFailure)
- {
- return false;
- }
-
- throw new OverflowException(SR.Format(SR.Overflow_TimeSpanElementTooLarge, new string(_originalTimeSpanString)));
- }
-
- internal bool SetBadTimeSpanFailure()
- {
- if (!_throwOnFailure)
- {
- return false;
- }
-
- throw new FormatException(SR.Format(SR.Format_BadTimeSpan, new string(_originalTimeSpanString)));
- }
-
- internal bool SetBadFormatSpecifierFailure(char? formatSpecifierCharacter = null)
- {
- if (!_throwOnFailure)
- {
- return false;
- }
-
- throw new FormatException(SR.Format(SR.Format_BadFormatSpecifier, formatSpecifierCharacter));
- }
- }
-
- internal static long Pow10(int pow)
- {
- return pow switch
- {
- 0 => 1,
- 1 => 10,
- 2 => 100,
- 3 => 1000,
- 4 => 10000,
- 5 => 100000,
- 6 => 1000000,
- 7 => 10000000,
- _ => (long)Math.Pow(10, pow),
- };
- }
-
- private static bool TryTimeToTicks(bool positive, TimeSpanToken days, TimeSpanToken hours, TimeSpanToken minutes, TimeSpanToken seconds, TimeSpanToken fraction, out long result)
- {
- if (days._num > MaxDays ||
- hours._num > MaxHours ||
- minutes._num > MaxMinutes ||
- seconds._num > MaxSeconds ||
- !fraction.NormalizeAndValidateFraction())
- {
- result = 0;
- return false;
- }
-
- long ticks = ((long)days._num * 3600 * 24 + (long)hours._num * 3600 + (long)minutes._num * 60 + seconds._num) * 1000;
- if (ticks > InternalGlobalizationHelper.MaxMilliSeconds || ticks < InternalGlobalizationHelper.MinMilliSeconds)
- {
- result = 0;
- return false;
- }
-
- result = ticks * TimeSpan.TicksPerMillisecond + fraction._num;
- if (positive && result < 0)
- {
- result = 0;
- return false;
- }
-
- return true;
- }
-
- internal static TimeSpan Parse(ReadOnlySpan<char> input, IFormatProvider? formatProvider)
- {
- var parseResult = new TimeSpanResult(throwOnFailure: true, originalTimeSpanString: input);
- bool success = TryParseTimeSpan(input, TimeSpanStandardStyles.Any, formatProvider, ref parseResult);
- Debug.Assert(success, "Should have thrown on failure");
- return parseResult.parsedTimeSpan;
- }
-
- internal static bool TryParse(ReadOnlySpan<char> input, IFormatProvider? formatProvider, out TimeSpan result)
- {
- var parseResult = new TimeSpanResult(throwOnFailure: false, originalTimeSpanString: input);
-
- if (TryParseTimeSpan(input, TimeSpanStandardStyles.Any, formatProvider, ref parseResult))
- {
- result = parseResult.parsedTimeSpan;
- return true;
- }
-
- result = default;
- return false;
- }
-
- internal static TimeSpan ParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, TimeSpanStyles styles)
- {
- var parseResult = new TimeSpanResult(throwOnFailure: true, originalTimeSpanString: input);
- bool success = TryParseExactTimeSpan(input, format, formatProvider, styles, ref parseResult);
- Debug.Assert(success, "Should have thrown on failure");
- return parseResult.parsedTimeSpan;
- }
-
- internal static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result)
- {
- var parseResult = new TimeSpanResult(throwOnFailure: false, originalTimeSpanString: input);
-
- if (TryParseExactTimeSpan(input, format, formatProvider, styles, ref parseResult))
- {
- result = parseResult.parsedTimeSpan;
- return true;
- }
-
- result = default;
- return false;
- }
-
- internal static TimeSpan ParseExactMultiple(ReadOnlySpan<char> input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles)
- {
- var parseResult = new TimeSpanResult(throwOnFailure: true, originalTimeSpanString: input);
- bool success = TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref parseResult);
- Debug.Assert(success, "Should have thrown on failure");
- return parseResult.parsedTimeSpan;
- }
-
- internal static bool TryParseExactMultiple(ReadOnlySpan<char> input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result)
- {
- var parseResult = new TimeSpanResult(throwOnFailure: false, originalTimeSpanString: input);
-
- if (TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref parseResult))
- {
- result = parseResult.parsedTimeSpan;
- return true;
- }
-
- result = default;
- return false;
- }
-
- /// <summary>Common private Parse method called by both Parse and TryParse.</summary>
- private static bool TryParseTimeSpan(ReadOnlySpan<char> input, TimeSpanStandardStyles style, IFormatProvider? formatProvider, ref TimeSpanResult result)
- {
- input = input.Trim();
- if (input.IsEmpty)
- {
- return result.SetBadTimeSpanFailure();
- }
-
- var tokenizer = new TimeSpanTokenizer(input);
-
- TimeSpanRawInfo raw = default;
- raw.Init(DateTimeFormatInfo.GetInstance(formatProvider));
-
- TimeSpanToken tok = tokenizer.GetNextToken();
-
- // The following loop will break out when we reach the end of the str or
- // when we can determine that the input is invalid.
- while (tok._ttt != TTT.End)
- {
- if (!raw.ProcessToken(ref tok, ref result))
- {
- return result.SetBadTimeSpanFailure();
- }
- tok = tokenizer.GetNextToken();
- }
- Debug.Assert(tokenizer.EOL);
-
- if (!ProcessTerminalState(ref raw, style, ref result))
- {
- return result.SetBadTimeSpanFailure();
- }
-
- return true;
- }
-
- /// <summary>
- /// Validate the terminal state of a standard format parse.
- /// Sets result.parsedTimeSpan on success.
- /// Calculates the resultant TimeSpan from the TimeSpanRawInfo.
- /// </summary>
- /// <remarks>
- /// try => +InvariantPattern, -InvariantPattern, +LocalizedPattern, -LocalizedPattern
- /// 1) Verify Start matches
- /// 2) Verify End matches
- /// 3) 1 number => d
- /// 2 numbers => h:m
- /// 3 numbers => h:m:s | d.h:m | h:m:.f
- /// 4 numbers => h:m:s.f | d.h:m:s | d.h:m:.f
- /// 5 numbers => d.h:m:s.f
- /// </remarks>
- private static bool ProcessTerminalState(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result)
- {
- if (raw._lastSeenTTT == TTT.Num)
- {
- TimeSpanToken tok = default;
- tok._ttt = TTT.Sep;
- if (!raw.ProcessToken(ref tok, ref result))
- {
- return result.SetBadTimeSpanFailure();
- }
- }
-
- return raw._numCount switch
- {
- 1 => ProcessTerminal_D(ref raw, style, ref result),
- 2 => ProcessTerminal_HM(ref raw, style, ref result),
- 3 => ProcessTerminal_HM_S_D(ref raw, style, ref result),
- 4 => ProcessTerminal_HMS_F_D(ref raw, style, ref result),
- 5 => ProcessTerminal_DHMSF(ref raw, style, ref result),
- _ => result.SetBadTimeSpanFailure(),
- };
- }
-
- /// <summary>Validate the 5-number "Days.Hours:Minutes:Seconds.Fraction" terminal case.</summary>
- private static bool ProcessTerminal_DHMSF(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result)
- {
- if (raw._sepCount != 6)
- {
- return result.SetBadTimeSpanFailure();
- }
- Debug.Assert(raw._numCount == 5);
-
- bool inv = (style & TimeSpanStandardStyles.Invariant) != 0;
- bool loc = (style & TimeSpanStandardStyles.Localized) != 0;
- bool positive = false;
- bool match = false;
-
- if (inv)
- {
- if (raw.FullMatch(TimeSpanFormat.PositiveInvariantFormatLiterals))
- {
- match = true;
- positive = true;
- }
- if (!match && raw.FullMatch(TimeSpanFormat.NegativeInvariantFormatLiterals))
- {
- match = true;
- positive = false;
- }
- }
-
- if (loc)
- {
- if (!match && raw.FullMatch(raw.PositiveLocalized))
- {
- match = true;
- positive = true;
- }
- if (!match && raw.FullMatch(raw.NegativeLocalized))
- {
- match = true;
- positive = false;
- }
- }
-
- if (match)
- {
- long ticks;
-
- if (!TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, raw._numbers3, raw._numbers4, out ticks))
- {
- return result.SetOverflowFailure();
- }
-
- if (!positive)
- {
- ticks = -ticks;
- if (ticks > 0)
- {
- return result.SetOverflowFailure();
- }
- }
-
- result.parsedTimeSpan = new TimeSpan(ticks);
- return true;
- }
-
- return result.SetBadTimeSpanFailure();
- }
-
-
- /// <summary>
- /// Validate the ambiguous 4-number "Hours:Minutes:Seconds.Fraction", "Days.Hours:Minutes:Seconds",
- /// or "Days.Hours:Minutes:.Fraction" terminal case.
- /// </summary>
- private static bool ProcessTerminal_HMS_F_D(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result)
- {
- if (raw._sepCount != 5 || (style & TimeSpanStandardStyles.RequireFull) != 0)
- {
- return result.SetBadTimeSpanFailure();
- }
- Debug.Assert(raw._numCount == 4);
-
- bool inv = ((style & TimeSpanStandardStyles.Invariant) != 0);
- bool loc = ((style & TimeSpanStandardStyles.Localized) != 0);
-
- long ticks = 0;
- bool positive = false, match = false, overflow = false;
- var zero = new TimeSpanToken(0);
-
- if (inv)
- {
- if (raw.FullHMSFMatch(TimeSpanFormat.PositiveInvariantFormatLiterals))
- {
- positive = true;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, raw._numbers2, raw._numbers3, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullDHMSMatch(TimeSpanFormat.PositiveInvariantFormatLiterals))
- {
- positive = true;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, raw._numbers3, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullAppCompatMatch(TimeSpanFormat.PositiveInvariantFormatLiterals))
- {
- positive = true;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, zero, raw._numbers3, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullHMSFMatch(TimeSpanFormat.NegativeInvariantFormatLiterals))
- {
- positive = false;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, raw._numbers2, raw._numbers3, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullDHMSMatch(TimeSpanFormat.NegativeInvariantFormatLiterals))
- {
- positive = false;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, raw._numbers3, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullAppCompatMatch(TimeSpanFormat.NegativeInvariantFormatLiterals))
- {
- positive = false;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, zero, raw._numbers3, out ticks);
- overflow = overflow || !match;
- }
- }
-
- if (loc)
- {
- if (!match && raw.FullHMSFMatch(raw.PositiveLocalized))
- {
- positive = true;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, raw._numbers2, raw._numbers3, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullDHMSMatch(raw.PositiveLocalized))
- {
- positive = true;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, raw._numbers3, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullAppCompatMatch(raw.PositiveLocalized))
- {
- positive = true;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, zero, raw._numbers3, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullHMSFMatch(raw.NegativeLocalized))
- {
- positive = false;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, raw._numbers2, raw._numbers3, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullDHMSMatch(raw.NegativeLocalized))
- {
- positive = false;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, raw._numbers3, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullAppCompatMatch(raw.NegativeLocalized))
- {
- positive = false;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, zero, raw._numbers3, out ticks);
- overflow = overflow || !match;
- }
- }
-
- if (match)
- {
- if (!positive)
- {
- ticks = -ticks;
- if (ticks > 0)
- {
- return result.SetOverflowFailure();
- }
- }
-
- result.parsedTimeSpan = new TimeSpan(ticks);
- return true;
- }
-
- return overflow ?
- result.SetOverflowFailure() : // we found at least one literal pattern match but the numbers just didn't fit
- result.SetBadTimeSpanFailure(); // we couldn't find a thing
- }
-
- /// <summary>Validate the ambiguous 3-number "Hours:Minutes:Seconds", "Days.Hours:Minutes", or "Hours:Minutes:.Fraction" terminal case.</summary>
- private static bool ProcessTerminal_HM_S_D(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result)
- {
- if (raw._sepCount != 4 || (style & TimeSpanStandardStyles.RequireFull) != 0)
- {
- return result.SetBadTimeSpanFailure();
- }
- Debug.Assert(raw._numCount == 3);
-
- bool inv = ((style & TimeSpanStandardStyles.Invariant) != 0);
- bool loc = ((style & TimeSpanStandardStyles.Localized) != 0);
-
- bool positive = false, match = false, overflow = false;
- var zero = new TimeSpanToken(0);
- long ticks = 0;
-
- if (inv)
- {
- if (raw.FullHMSMatch(TimeSpanFormat.PositiveInvariantFormatLiterals))
- {
- positive = true;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, raw._numbers2, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullDHMMatch(TimeSpanFormat.PositiveInvariantFormatLiterals))
- {
- positive = true;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, zero, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.PartialAppCompatMatch(TimeSpanFormat.PositiveInvariantFormatLiterals))
- {
- positive = true;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, zero, raw._numbers2, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullHMSMatch(TimeSpanFormat.NegativeInvariantFormatLiterals))
- {
- positive = false;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, raw._numbers2, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullDHMMatch(TimeSpanFormat.NegativeInvariantFormatLiterals))
- {
- positive = false;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, zero, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.PartialAppCompatMatch(TimeSpanFormat.NegativeInvariantFormatLiterals))
- {
- positive = false;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, zero, raw._numbers2, out ticks);
- overflow = overflow || !match;
- }
- }
-
- if (loc)
- {
- if (!match && raw.FullHMSMatch(raw.PositiveLocalized))
- {
- positive = true;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, raw._numbers2, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullDHMMatch(raw.PositiveLocalized))
- {
- positive = true;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, zero, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.PartialAppCompatMatch(raw.PositiveLocalized))
- {
- positive = true;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, zero, raw._numbers2, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullHMSMatch(raw.NegativeLocalized))
- {
- positive = false;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, raw._numbers2, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.FullDHMMatch(raw.NegativeLocalized))
- {
- positive = false;
- match = TryTimeToTicks(positive, raw._numbers0, raw._numbers1, raw._numbers2, zero, zero, out ticks);
- overflow = overflow || !match;
- }
-
- if (!match && raw.PartialAppCompatMatch(raw.NegativeLocalized))
- {
- positive = false;
- match = TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, zero, raw._numbers2, out ticks);
- overflow = overflow || !match;
- }
- }
-
- if (match)
- {
- if (!positive)
- {
- ticks = -ticks;
- if (ticks > 0)
- {
- return result.SetOverflowFailure();
- }
- }
-
- result.parsedTimeSpan = new TimeSpan(ticks);
- return true;
- }
-
- return overflow ?
- result.SetOverflowFailure() : // we found at least one literal pattern match but the numbers just didn't fit
- result.SetBadTimeSpanFailure(); // we couldn't find a thing
- }
-
- /// <summary>Validate the 2-number "Hours:Minutes" terminal case.</summary>
- private static bool ProcessTerminal_HM(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result)
- {
- if (raw._sepCount != 3 || (style & TimeSpanStandardStyles.RequireFull) != 0)
- {
- return result.SetBadTimeSpanFailure();
- }
- Debug.Assert(raw._numCount == 2);
-
- bool inv = ((style & TimeSpanStandardStyles.Invariant) != 0);
- bool loc = ((style & TimeSpanStandardStyles.Localized) != 0);
-
- bool positive = false, match = false;
-
- if (inv)
- {
- if (raw.FullHMMatch(TimeSpanFormat.PositiveInvariantFormatLiterals))
- {
- match = true;
- positive = true;
- }
-
- if (!match && raw.FullHMMatch(TimeSpanFormat.NegativeInvariantFormatLiterals))
- {
- match = true;
- positive = false;
- }
- }
-
- if (loc)
- {
- if (!match && raw.FullHMMatch(raw.PositiveLocalized))
- {
- match = true;
- positive = true;
- }
-
- if (!match && raw.FullHMMatch(raw.NegativeLocalized))
- {
- match = true;
- positive = false;
- }
- }
-
- if (match)
- {
- long ticks;
- var zero = new TimeSpanToken(0);
-
- if (!TryTimeToTicks(positive, zero, raw._numbers0, raw._numbers1, zero, zero, out ticks))
- {
- return result.SetOverflowFailure();
- }
-
- if (!positive)
- {
- ticks = -ticks;
- if (ticks > 0)
- {
- return result.SetOverflowFailure();
- }
- }
-
- result.parsedTimeSpan = new TimeSpan(ticks);
- return true;
- }
-
- return result.SetBadTimeSpanFailure();
- }
-
- /// <summary>Validate the 1-number "Days" terminal case.</summary>
- private static bool ProcessTerminal_D(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result)
- {
- if (raw._sepCount != 2 || (style & TimeSpanStandardStyles.RequireFull) != 0)
- {
- return result.SetBadTimeSpanFailure();
- }
- Debug.Assert(raw._numCount == 1);
-
- bool inv = ((style & TimeSpanStandardStyles.Invariant) != 0);
- bool loc = ((style & TimeSpanStandardStyles.Localized) != 0);
-
- bool positive = false, match = false;
-
- if (inv)
- {
- if (raw.FullDMatch(TimeSpanFormat.PositiveInvariantFormatLiterals))
- {
- match = true;
- positive = true;
- }
-
- if (!match && raw.FullDMatch(TimeSpanFormat.NegativeInvariantFormatLiterals))
- {
- match = true;
- positive = false;
- }
- }
-
- if (loc)
- {
- if (!match && raw.FullDMatch(raw.PositiveLocalized))
- {
- match = true;
- positive = true;
- }
-
- if (!match && raw.FullDMatch(raw.NegativeLocalized))
- {
- match = true;
- positive = false;
- }
- }
-
- if (match)
- {
- long ticks;
- var zero = new TimeSpanToken(0);
-
- if (!TryTimeToTicks(positive, raw._numbers0, zero, zero, zero, zero, out ticks))
- {
- return result.SetOverflowFailure();
- }
-
- if (!positive)
- {
- ticks = -ticks;
- if (ticks > 0)
- {
- return result.SetOverflowFailure();
- }
- }
-
- result.parsedTimeSpan = new TimeSpan(ticks);
- return true;
- }
-
- return result.SetBadTimeSpanFailure();
- }
-
- /// <summary>Common private ParseExact method called by both ParseExact and TryParseExact.</summary>
- private static bool TryParseExactTimeSpan(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, TimeSpanStyles styles, ref TimeSpanResult result)
- {
- if (format.Length == 0)
- {
- return result.SetBadFormatSpecifierFailure();
- }
-
- if (format.Length == 1)
- {
- switch (format[0])
- {
- case 'c':
- case 't':
- case 'T':
- return TryParseTimeSpanConstant(input, ref result); // fast path for legacy style TimeSpan formats.
-
- case 'g':
- return TryParseTimeSpan(input, TimeSpanStandardStyles.Localized, formatProvider, ref result);
-
- case 'G':
- return TryParseTimeSpan(input, TimeSpanStandardStyles.Localized | TimeSpanStandardStyles.RequireFull, formatProvider, ref result);
-
- default:
- return result.SetBadFormatSpecifierFailure(format[0]);
- }
- }
-
- return TryParseByFormat(input, format, styles, ref result);
- }
-
- /// <summary>Parse the TimeSpan instance using the specified format. Used by TryParseExactTimeSpan.</summary>
- private static bool TryParseByFormat(ReadOnlySpan<char> input, ReadOnlySpan<char> format, TimeSpanStyles styles, ref TimeSpanResult result)
- {
- bool seenDD = false; // already processed days?
- bool seenHH = false; // already processed hours?
- bool seenMM = false; // already processed minutes?
- bool seenSS = false; // already processed seconds?
- bool seenFF = false; // already processed fraction?
-
- int dd = 0; // parsed days
- int hh = 0; // parsed hours
- int mm = 0; // parsed minutes
- int ss = 0; // parsed seconds
- int leadingZeroes = 0; // number of leading zeroes in the parsed fraction
- int ff = 0; // parsed fraction
- int i = 0; // format string position
- int tokenLen; // length of current format token, used to update index 'i'
-
- var tokenizer = new TimeSpanTokenizer(input, -1);
-
- while (i < format.Length)
- {
- char ch = format[i];
- int nextFormatChar;
- switch (ch)
- {
- case 'h':
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > 2 || seenHH || !ParseExactDigits(ref tokenizer, tokenLen, out hh))
- {
- return result.SetInvalidStringFailure();
- }
- seenHH = true;
- break;
-
- case 'm':
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > 2 || seenMM || !ParseExactDigits(ref tokenizer, tokenLen, out mm))
- {
- return result.SetInvalidStringFailure();
- }
- seenMM = true;
- break;
-
- case 's':
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > 2 || seenSS || !ParseExactDigits(ref tokenizer, tokenLen, out ss))
- {
- return result.SetInvalidStringFailure();
- }
- seenSS = true;
- break;
-
- case 'f':
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > DateTimeFormat.MaxSecondsFractionDigits || seenFF || !ParseExactDigits(ref tokenizer, tokenLen, tokenLen, out leadingZeroes, out ff))
- {
- return result.SetInvalidStringFailure();
- }
- seenFF = true;
- break;
-
- case 'F':
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > DateTimeFormat.MaxSecondsFractionDigits || seenFF)
- {
- return result.SetInvalidStringFailure();
- }
- ParseExactDigits(ref tokenizer, tokenLen, tokenLen, out leadingZeroes, out ff);
- seenFF = true;
- break;
-
- case 'd':
- tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
- if (tokenLen > 8 || seenDD || !ParseExactDigits(ref tokenizer, (tokenLen < 2) ? 1 : tokenLen, (tokenLen < 2) ? 8 : tokenLen, out _, out dd))
- {
- return result.SetInvalidStringFailure();
- }
- seenDD = true;
- break;
-
- case '\'':
- case '\"':
- StringBuilder enquotedString = StringBuilderCache.Acquire();
- if (!DateTimeParse.TryParseQuoteString(format, i, enquotedString, out tokenLen))
- {
- StringBuilderCache.Release(enquotedString);
- return result.SetBadQuoteFailure(ch);
- }
- if (!ParseExactLiteral(ref tokenizer, enquotedString))
- {
- StringBuilderCache.Release(enquotedString);
- return result.SetInvalidStringFailure();
- }
- StringBuilderCache.Release(enquotedString);
- break;
-
- case '%':
- // Optional format character.
- // For example, format string "%d" will print day
- // Most of the cases, "%" can be ignored.
- nextFormatChar = DateTimeFormat.ParseNextChar(format, i);
-
- // nextFormatChar will be -1 if we already reach the end of the format string.
- // Besides, we will not allow "%%" appear in the pattern.
- if (nextFormatChar >= 0 && nextFormatChar != '%')
- {
- tokenLen = 1; // skip the '%' and process the format character
- break;
- }
- else
- {
- // This means that '%' is at the end of the format string or
- // "%%" appears in the format string.
- return result.SetInvalidStringFailure();
- }
-
- case '\\':
- // Escaped character. Can be used to insert character into the format string.
- // For example, "\d" will insert the character 'd' into the string.
- //
- nextFormatChar = DateTimeFormat.ParseNextChar(format, i);
- if (nextFormatChar >= 0 && tokenizer.NextChar == (char)nextFormatChar)
- {
- tokenLen = 2;
- }
- else
- {
- // This means that '\' is at the end of the format string or the literal match failed.
- return result.SetInvalidStringFailure();
- }
- break;
-
- default:
- return result.SetInvalidStringFailure();
- }
-
- i += tokenLen;
- }
-
-
- if (!tokenizer.EOL)
- {
- // the custom format didn't consume the entire input
- return result.SetBadTimeSpanFailure();
- }
-
- bool positive = (styles & TimeSpanStyles.AssumeNegative) == 0;
- if (TryTimeToTicks(positive, new TimeSpanToken(dd),
- new TimeSpanToken(hh),
- new TimeSpanToken(mm),
- new TimeSpanToken(ss),
- new TimeSpanToken(ff, leadingZeroes),
- out long ticks))
- {
- if (!positive)
- {
- ticks = -ticks;
- }
-
- result.parsedTimeSpan = new TimeSpan(ticks);
- return true;
- }
- else
- {
- return result.SetOverflowFailure();
- }
- }
-
- private static bool ParseExactDigits(ref TimeSpanTokenizer tokenizer, int minDigitLength, out int result)
- {
- int maxDigitLength = (minDigitLength == 1) ? 2 : minDigitLength;
- return ParseExactDigits(ref tokenizer, minDigitLength, maxDigitLength, out _, out result);
- }
-
- private static bool ParseExactDigits(ref TimeSpanTokenizer tokenizer, int minDigitLength, int maxDigitLength, out int zeroes, out int result)
- {
- int tmpResult = 0, tmpZeroes = 0;
-
- int tokenLength = 0;
- while (tokenLength < maxDigitLength)
- {
- char ch = tokenizer.NextChar;
- if (ch < '0' || ch > '9')
- {
- tokenizer.BackOne();
- break;
- }
-
- tmpResult = tmpResult * 10 + (ch - '0');
- if (tmpResult == 0) tmpZeroes++;
- tokenLength++;
- }
-
- zeroes = tmpZeroes;
- result = tmpResult;
- return tokenLength >= minDigitLength;
- }
-
- private static bool ParseExactLiteral(ref TimeSpanTokenizer tokenizer, StringBuilder enquotedString)
- {
- for (int i = 0; i < enquotedString.Length; i++)
- {
- if (enquotedString[i] != tokenizer.NextChar)
- {
- return false;
- }
- }
-
- return true;
- }
-
- /// <summary>
- /// Parses the "c" (constant) format. This code is 100% identical to the non-globalized v1.0-v3.5 TimeSpan.Parse() routine
- /// and exists for performance/appcompat with legacy callers who cannot move onto the globalized Parse overloads.
- /// </summary>
- private static bool TryParseTimeSpanConstant(ReadOnlySpan<char> input, ref TimeSpanResult result) =>
- default(StringParser).TryParse(input, ref result);
-
- private ref struct StringParser
- {
- private ReadOnlySpan<char> _str;
- private char _ch;
- private int _pos;
- private int _len;
-
- internal void NextChar()
- {
- if (_pos < _len)
- {
- _pos++;
- }
-
- _ch = _pos < _len ?
- _str[_pos] :
- (char)0;
- }
-
- internal char NextNonDigit()
- {
- int i = _pos;
- while (i < _len)
- {
- char ch = _str[i];
- if (ch < '0' || ch > '9') return ch;
- i++;
- }
-
- return (char)0;
- }
-
- internal bool TryParse(ReadOnlySpan<char> input, ref TimeSpanResult result)
- {
- result.parsedTimeSpan = default;
-
- _str = input;
- _len = input.Length;
- _pos = -1;
- NextChar();
- SkipBlanks();
-
- bool negative = false;
- if (_ch == '-')
- {
- negative = true;
- NextChar();
- }
-
- long time;
- if (NextNonDigit() == ':')
- {
- if (!ParseTime(out time, ref result))
- {
- return false;
- }
- }
- else
- {
- int days;
- if (!ParseInt((int)(0x7FFFFFFFFFFFFFFFL / TimeSpan.TicksPerDay), out days, ref result))
- {
- return false;
- }
-
- time = days * TimeSpan.TicksPerDay;
-
- if (_ch == '.')
- {
- NextChar();
- long remainingTime;
- if (!ParseTime(out remainingTime, ref result))
- {
- return false;
- }
- time += remainingTime;
- }
- }
-
- if (negative)
- {
- time = -time;
- // Allow -0 as well
- if (time > 0)
- {
- return result.SetOverflowFailure();
- }
- }
- else
- {
- if (time < 0)
- {
- return result.SetOverflowFailure();
- }
- }
-
- SkipBlanks();
-
- if (_pos < _len)
- {
- return result.SetBadTimeSpanFailure();
- }
-
- result.parsedTimeSpan = new TimeSpan(time);
- return true;
- }
-
- internal bool ParseInt(int max, out int i, ref TimeSpanResult result)
- {
- i = 0;
- int p = _pos;
- while (_ch >= '0' && _ch <= '9')
- {
- if ((i & 0xF0000000) != 0)
- {
- return result.SetOverflowFailure();
- }
-
- i = i * 10 + _ch - '0';
- if (i < 0)
- {
- return result.SetOverflowFailure();
- }
-
- NextChar();
- }
-
- if (p == _pos)
- {
- return result.SetBadTimeSpanFailure();
- }
-
- if (i > max)
- {
- return result.SetOverflowFailure();
- }
-
- return true;
- }
-
- internal bool ParseTime(out long time, ref TimeSpanResult result)
- {
- time = 0;
- int unit;
-
- if (!ParseInt(23, out unit, ref result))
- {
- return false;
- }
-
- time = unit * TimeSpan.TicksPerHour;
- if (_ch != ':')
- {
- return result.SetBadTimeSpanFailure();
- }
-
- NextChar();
-
- if (!ParseInt(59, out unit, ref result))
- {
- return false;
- }
-
- time += unit * TimeSpan.TicksPerMinute;
-
- if (_ch == ':')
- {
- NextChar();
-
- // allow seconds with the leading zero
- if (_ch != '.')
- {
- if (!ParseInt(59, out unit, ref result))
- {
- return false;
- }
- time += unit * TimeSpan.TicksPerSecond;
- }
-
- if (_ch == '.')
- {
- NextChar();
- int f = (int)TimeSpan.TicksPerSecond;
- while (f > 1 && _ch >= '0' && _ch <= '9')
- {
- f /= 10;
- time += (_ch - '0') * f;
- NextChar();
- }
- }
- }
-
- return true;
- }
-
- internal void SkipBlanks()
- {
- while (_ch == ' ' || _ch == '\t') NextChar();
- }
- }
-
- /// <summary>Common private ParseExactMultiple method called by both ParseExactMultiple and TryParseExactMultiple.</summary>
- private static bool TryParseExactMultipleTimeSpan(ReadOnlySpan<char> input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles, ref TimeSpanResult result)
- {
- if (formats == null)
- {
- return result.SetArgumentNullFailure(nameof(formats));
- }
-
- if (input.Length == 0)
- {
- return result.SetBadTimeSpanFailure();
- }
-
- if (formats.Length == 0)
- {
- return result.SetNoFormatSpecifierFailure();
- }
-
- // Do a loop through the provided formats and see if we can parse succesfully in
- // one of the formats.
- for (int i = 0; i < formats.Length; i++)
- {
- if (formats[i] == null || formats[i].Length == 0)
- {
- return result.SetBadFormatSpecifierFailure();
- }
-
- // Create a new non-throwing result each time to ensure the runs are independent.
- TimeSpanResult innerResult = new TimeSpanResult(throwOnFailure: false, originalTimeSpanString: input);
-
- if (TryParseExactTimeSpan(input, formats[i], formatProvider, styles, ref innerResult))
- {
- result.parsedTimeSpan = innerResult.parsedTimeSpan;
- return true;
- }
- }
-
- return result.SetBadTimeSpanFailure();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanStyles.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanStyles.cs
deleted file mode 100644
index 68a47bcbe60..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/TimeSpanStyles.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Globalization
-{
- [Flags]
- public enum TimeSpanStyles
- {
- None = 0x00000000,
- AssumeNegative = 0x00000001,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/UmAlQuraCalendar.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/UmAlQuraCalendar.cs
deleted file mode 100644
index ae5820841e4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/UmAlQuraCalendar.cs
+++ /dev/null
@@ -1,653 +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 System.Diagnostics;
-
-namespace System.Globalization
-{
- /// <remarks>
- /// Calendar support range:
- /// Calendar Minimum Maximum
- /// ========== ========== ==========
- /// Gregorian 1900/04/30 2077/05/13
- /// UmAlQura 1318/01/01 1500/12/30
- /// </remarks>
- public partial class UmAlQuraCalendar : Calendar
- {
- private const int MinCalendarYear = 1318;
- private const int MaxCalendarYear = 1500;
-
- private struct DateMapping
- {
- internal DateMapping(int MonthsLengthFlags, int GYear, int GMonth, int GDay)
- {
- HijriMonthsLengthFlags = MonthsLengthFlags;
- GregorianDate = new DateTime(GYear, GMonth, GDay);
- }
-
- internal int HijriMonthsLengthFlags;
- internal DateTime GregorianDate;
- }
-
- private static readonly DateMapping[] s_hijriYearInfo = InitDateMapping();
-
- private static DateMapping[] InitDateMapping()
- {
- short[] rawData = new short[]
- {
- // These data are taken from Tables/Excel/UmAlQura.xls please make sure that the two places are in sync
- /* DaysPerM GY GM GD D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 D12
- 1318*/0x02EA, 1900, 4, 30, /* 0 1 0 1 0 1 1 1 0 1 0 0 4/30/1900
- 1319*/0x06E9, 1901, 4, 19, /* 1 0 0 1 0 1 1 1 0 1 1 0 4/19/1901
- 1320*/0x0ED2, 1902, 4, 9, /* 0 1 0 0 1 0 1 1 0 1 1 1 4/9/1902
- 1321*/0x0EA4, 1903, 3, 30, /* 0 0 1 0 0 1 0 1 0 1 1 1 3/30/1903
- 1322*/0x0D4A, 1904, 3, 18, /* 0 1 0 1 0 0 1 0 1 0 1 1 3/18/1904
- 1323*/0x0A96, 1905, 3, 7, /* 0 1 1 0 1 0 0 1 0 1 0 1 3/7/1905
- 1324*/0x0536, 1906, 2, 24, /* 0 1 1 0 1 1 0 0 1 0 1 0 2/24/1906
- 1325*/0x0AB5, 1907, 2, 13, /* 1 0 1 0 1 1 0 1 0 1 0 1 2/13/1907
- 1326*/0x0DAA, 1908, 2, 3, /* 0 1 0 1 0 1 0 1 1 0 1 1 2/3/1908
- 1327*/0x0BA4, 1909, 1, 23, /* 0 0 1 0 0 1 0 1 1 1 0 1 1/23/1909
- 1328*/0x0B49, 1910, 1, 12, /* 1 0 0 1 0 0 1 0 1 1 0 1 1/12/1910
- 1329*/0x0A93, 1911, 1, 1, /* 1 1 0 0 1 0 0 1 0 1 0 1 1/1/1911
- 1330*/0x052B, 1911, 12, 21, /* 1 1 0 1 0 1 0 0 1 0 1 0 12/21/1911
- 1331*/0x0A57, 1912, 12, 9, /* 1 1 1 0 1 0 1 0 0 1 0 1 12/9/1912
- 1332*/0x04B6, 1913, 11, 29, /* 0 1 1 0 1 1 0 1 0 0 1 0 11/29/1913
- 1333*/0x0AB5, 1914, 11, 18, /* 1 0 1 0 1 1 0 1 0 1 0 1 11/18/1914
- 1334*/0x05AA, 1915, 11, 8, /* 0 1 0 1 0 1 0 1 1 0 1 0 11/8/1915
- 1335*/0x0D55, 1916, 10, 27, /* 1 0 1 0 1 0 1 0 1 0 1 1 10/27/1916
- 1336*/0x0D2A, 1917, 10, 17, /* 0 1 0 1 0 1 0 0 1 0 1 1 10/17/1917
- 1337*/0x0A56, 1918, 10, 6, /* 0 1 1 0 1 0 1 0 0 1 0 1 10/6/1918
- 1338*/0x04AE, 1919, 9, 25, /* 0 1 1 1 0 1 0 1 0 0 1 0 9/25/1919
- 1339*/0x095D, 1920, 9, 13, /* 1 0 1 1 1 0 1 0 1 0 0 1 9/13/1920
- 1340*/0x02EC, 1921, 9, 3, /* 0 0 1 1 0 1 1 1 0 1 0 0 9/3/1921
- 1341*/0x06D5, 1922, 8, 23, /* 1 0 1 0 1 0 1 1 0 1 1 0 8/23/1922
- 1342*/0x06AA, 1923, 8, 13, /* 0 1 0 1 0 1 0 1 0 1 1 0 8/13/1923
- 1343*/0x0555, 1924, 8, 1, /* 1 0 1 0 1 0 1 0 1 0 1 0 8/1/1924
- 1344*/0x04AB, 1925, 7, 21, /* 1 1 0 1 0 1 0 1 0 0 1 0 7/21/1925
- 1345*/0x095B, 1926, 7, 10, /* 1 1 0 1 1 0 1 0 1 0 0 1 7/10/1926
- 1346*/0x02BA, 1927, 6, 30, /* 0 1 0 1 1 1 0 1 0 1 0 0 6/30/1927
- 1347*/0x0575, 1928, 6, 18, /* 1 0 1 0 1 1 1 0 1 0 1 0 6/18/1928
- 1348*/0x0BB2, 1929, 6, 8, /* 0 1 0 0 1 1 0 1 1 1 0 1 6/8/1929
- 1349*/0x0764, 1930, 5, 29, /* 0 0 1 0 0 1 1 0 1 1 1 0 5/29/1930
- 1350*/0x0749, 1931, 5, 18, /* 1 0 0 1 0 0 1 0 1 1 1 0 5/18/1931
- 1351*/0x0655, 1932, 5, 6, /* 1 0 1 0 1 0 1 0 0 1 1 0 5/6/1932
- 1352*/0x02AB, 1933, 4, 25, /* 1 1 0 1 0 1 0 1 0 1 0 0 4/25/1933
- 1353*/0x055B, 1934, 4, 14, /* 1 1 0 1 1 0 1 0 1 0 1 0 4/14/1934
- 1354*/0x0ADA, 1935, 4, 4, /* 0 1 0 1 1 0 1 1 0 1 0 1 4/4/1935
- 1355*/0x06D4, 1936, 3, 24, /* 0 0 1 0 1 0 1 1 0 1 1 0 3/24/1936
- 1356*/0x0EC9, 1937, 3, 13, /* 1 0 0 1 0 0 1 1 0 1 1 1 3/13/1937
- 1357*/0x0D92, 1938, 3, 3, /* 0 1 0 0 1 0 0 1 1 0 1 1 3/3/1938
- 1358*/0x0D25, 1939, 2, 20, /* 1 0 1 0 0 1 0 0 1 0 1 1 2/20/1939
- 1359*/0x0A4D, 1940, 2, 9, /* 1 0 1 1 0 0 1 0 0 1 0 1 2/9/1940
- 1360*/0x02AD, 1941, 1, 28, /* 1 0 1 1 0 1 0 1 0 1 0 0 1/28/1941
- 1361*/0x056D, 1942, 1, 17, /* 1 0 1 1 0 1 1 0 1 0 1 0 1/17/1942
- 1362*/0x0B6A, 1943, 1, 7, /* 0 1 0 1 0 1 1 0 1 1 0 1 1/7/1943
- 1363*/0x0B52, 1943, 12, 28, /* 0 1 0 0 1 0 1 0 1 1 0 1 12/28/1943
- 1364*/0x0AA5, 1944, 12, 16, /* 1 0 1 0 0 1 0 1 0 1 0 1 12/16/1944
- 1365*/0x0A4B, 1945, 12, 5, /* 1 1 0 1 0 0 1 0 0 1 0 1 12/5/1945
- 1366*/0x0497, 1946, 11, 24, /* 1 1 1 0 1 0 0 1 0 0 1 0 11/24/1946
- 1367*/0x0937, 1947, 11, 13, /* 1 1 1 0 1 1 0 0 1 0 0 1 11/13/1947
- 1368*/0x02B6, 1948, 11, 2, /* 0 1 1 0 1 1 0 1 0 1 0 0 11/2/1948
- 1369*/0x0575, 1949, 10, 22, /* 1 0 1 0 1 1 1 0 1 0 1 0 10/22/1949
- 1370*/0x0D6A, 1950, 10, 12, /* 0 1 0 1 0 1 1 0 1 0 1 1 10/12/1950
- 1371*/0x0D52, 1951, 10, 2, /* 0 1 0 0 1 0 1 0 1 0 1 1 10/2/1951
- 1372*/0x0A96, 1952, 9, 20, /* 0 1 1 0 1 0 0 1 0 1 0 1 9/20/1952
- 1373*/0x092D, 1953, 9, 9, /* 1 0 1 1 0 1 0 0 1 0 0 1 9/9/1953
- 1374*/0x025D, 1954, 8, 29, /* 1 0 1 1 1 0 1 0 0 1 0 0 8/29/1954
- 1375*/0x04DD, 1955, 8, 18, /* 1 0 1 1 1 0 1 1 0 0 1 0 8/18/1955
- 1376*/0x0ADA, 1956, 8, 7, /* 0 1 0 1 1 0 1 1 0 1 0 1 8/7/1956
- 1377*/0x05D4, 1957, 7, 28, /* 0 0 1 0 1 0 1 1 1 0 1 0 7/28/1957
- 1378*/0x0DA9, 1958, 7, 17, /* 1 0 0 1 0 1 0 1 1 0 1 1 7/17/1958
- 1379*/0x0D52, 1959, 7, 7, /* 0 1 0 0 1 0 1 0 1 0 1 1 7/7/1959
- 1380*/0x0AAA, 1960, 6, 25, /* 0 1 0 1 0 1 0 1 0 1 0 1 6/25/1960
- 1381*/0x04D6, 1961, 6, 14, /* 0 1 1 0 1 0 1 1 0 0 1 0 6/14/1961
- 1382*/0x09B6, 1962, 6, 3, /* 0 1 1 0 1 1 0 1 1 0 0 1 6/3/1962
- 1383*/0x0374, 1963, 5, 24, /* 0 0 1 0 1 1 1 0 1 1 0 0 5/24/1963
- 1384*/0x0769, 1964, 5, 12, /* 1 0 0 1 0 1 1 0 1 1 1 0 5/12/1964
- 1385*/0x0752, 1965, 5, 2, /* 0 1 0 0 1 0 1 0 1 1 1 0 5/2/1965
- 1386*/0x06A5, 1966, 4, 21, /* 1 0 1 0 0 1 0 1 0 1 1 0 4/21/1966
- 1387*/0x054B, 1967, 4, 10, /* 1 1 0 1 0 0 1 0 1 0 1 0 4/10/1967
- 1388*/0x0AAB, 1968, 3, 29, /* 1 1 0 1 0 1 0 1 0 1 0 1 3/29/1968
- 1389*/0x055A, 1969, 3, 19, /* 0 1 0 1 1 0 1 0 1 0 1 0 3/19/1969
- 1390*/0x0AD5, 1970, 3, 8, /* 1 0 1 0 1 0 1 1 0 1 0 1 3/8/1970
- 1391*/0x0DD2, 1971, 2, 26, /* 0 1 0 0 1 0 1 1 1 0 1 1 2/26/1971
- 1392*/0x0DA4, 1972, 2, 16, /* 0 0 1 0 0 1 0 1 1 0 1 1 2/16/1972
- 1393*/0x0D49, 1973, 2, 4, /* 1 0 0 1 0 0 1 0 1 0 1 1 2/4/1973
- 1394*/0x0A95, 1974, 1, 24, /* 1 0 1 0 1 0 0 1 0 1 0 1 1/24/1974
- 1395*/0x052D, 1975, 1, 13, /* 1 0 1 1 0 1 0 0 1 0 1 0 1/13/1975
- 1396*/0x0A5D, 1976, 1, 2, /* 1 0 1 1 1 0 1 0 0 1 0 1 1/2/1976
- 1397*/0x055A, 1976, 12, 22, /* 0 1 0 1 1 0 1 0 1 0 1 0 12/22/1976
- 1398*/0x0AD5, 1977, 12, 11, /* 1 0 1 0 1 0 1 1 0 1 0 1 12/11/1977
- 1399*/0x06AA, 1978, 12, 1, /* 0 1 0 1 0 1 0 1 0 1 1 0 12/1/1978
- 1400*/0x0695, 1979, 11, 20, /* 1 0 1 0 1 0 0 1 0 1 1 0 11/20/1979
- 1401*/0x052B, 1980, 11, 8, /* 1 1 0 1 0 1 0 0 1 0 1 0 11/8/1980
- 1402*/0x0A57, 1981, 10, 28, /* 1 1 1 0 1 0 1 0 0 1 0 1 10/28/1981
- 1403*/0x04AE, 1982, 10, 18, /* 0 1 1 1 0 1 0 1 0 0 1 0 10/18/1982
- 1404*/0x0976, 1983, 10, 7, /* 0 1 1 0 1 1 1 0 1 0 0 1 10/7/1983
- 1405*/0x056C, 1984, 9, 26, /* 0 0 1 1 0 1 1 0 1 0 1 0 9/26/1984
- 1406*/0x0B55, 1985, 9, 15, /* 1 0 1 0 1 0 1 0 1 1 0 1 9/15/1985
- 1407*/0x0AAA, 1986, 9, 5, /* 0 1 0 1 0 1 0 1 0 1 0 1 9/5/1986
- 1408*/0x0A55, 1987, 8, 25, /* 1 0 1 0 1 0 1 0 0 1 0 1 8/25/1987
- 1409*/0x04AD, 1988, 8, 13, /* 1 0 1 1 0 1 0 1 0 0 1 0 8/13/1988
- 1410*/0x095D, 1989, 8, 2, /* 1 0 1 1 1 0 1 0 1 0 0 1 8/2/1989
- 1411*/0x02DA, 1990, 7, 23, /* 0 1 0 1 1 0 1 1 0 1 0 0 7/23/1990
- 1412*/0x05D9, 1991, 7, 12, /* 1 0 0 1 1 0 1 1 1 0 1 0 7/12/1991
- 1413*/0x0DB2, 1992, 7, 1, /* 0 1 0 0 1 1 0 1 1 0 1 1 7/1/1992
- 1414*/0x0BA4, 1993, 6, 21, /* 0 0 1 0 0 1 0 1 1 1 0 1 6/21/1993
- 1415*/0x0B4A, 1994, 6, 10, /* 0 1 0 1 0 0 1 0 1 1 0 1 6/10/1994
- 1416*/0x0A55, 1995, 5, 30, /* 1 0 1 0 1 0 1 0 0 1 0 1 5/30/1995
- 1417*/0x02B5, 1996, 5, 18, /* 1 0 1 0 1 1 0 1 0 1 0 0 5/18/1996
- 1418*/0x0575, 1997, 5, 7, /* 1 0 1 0 1 1 1 0 1 0 1 0 5/7/1997
- 1419*/0x0B6A, 1998, 4, 27, /* 0 1 0 1 0 1 1 0 1 1 0 1 4/27/1998
- 1420*/0x0BD2, 1999, 4, 17, /* 0 1 0 0 1 0 1 1 1 1 0 1 4/17/1999
- 1421*/0x0BC4, 2000, 4, 6, /* 0 0 1 0 0 0 1 1 1 1 0 1 4/6/2000
- 1422*/0x0B89, 2001, 3, 26, /* 1 0 0 1 0 0 0 1 1 1 0 1 3/26/2001
- 1423*/0x0A95, 2002, 3, 15, /* 1 0 1 0 1 0 0 1 0 1 0 1 3/15/2002
- 1424*/0x052D, 2003, 3, 4, /* 1 0 1 1 0 1 0 0 1 0 1 0 3/4/2003
- 1425*/0x05AD, 2004, 2, 21, /* 1 0 1 1 0 1 0 1 1 0 1 0 2/21/2004
- 1426*/0x0B6A, 2005, 2, 10, /* 0 1 0 1 0 1 1 0 1 1 0 1 2/10/2005
- 1427*/0x06D4, 2006, 1, 31, /* 0 0 1 0 1 0 1 1 0 1 1 0 1/31/2006
- 1428*/0x0DC9, 2007, 1, 20, /* 1 0 0 1 0 0 1 1 1 0 1 1 1/20/2007
- 1429*/0x0D92, 2008, 1, 10, /* 0 1 0 0 1 0 0 1 1 0 1 1 1/10/2008
- 1430*/0x0AA6, 2008, 12, 29, /* 0 1 1 0 0 1 0 1 0 1 0 1 12/29/2008
- 1431*/0x0956, 2009, 12, 18, /* 0 1 1 0 1 0 1 0 1 0 0 1 12/18/2009
- 1432*/0x02AE, 2010, 12, 7, /* 0 1 1 1 0 1 0 1 0 1 0 0 12/7/2010
- 1433*/0x056D, 2011, 11, 26, /* 1 0 1 1 0 1 1 0 1 0 1 0 11/26/2011
- 1434*/0x036A, 2012, 11, 15, /* 0 1 0 1 0 1 1 0 1 1 0 0 11/15/2012
- 1435*/0x0B55, 2013, 11, 4, /* 1 0 1 0 1 0 1 0 1 1 0 1 11/4/2013
- 1436*/0x0AAA, 2014, 10, 25, /* 0 1 0 1 0 1 0 1 0 1 0 1 10/25/2014
- 1437*/0x094D, 2015, 10, 14, /* 1 0 1 1 0 0 1 0 1 0 0 1 10/14/2015
- 1438*/0x049D, 2016, 10, 2, /* 1 0 1 1 1 0 0 1 0 0 1 0 10/2/2016
- 1439*/0x095D, 2017, 9, 21, /* 1 0 1 1 1 0 1 0 1 0 0 1 9/21/2017
- 1440*/0x02BA, 2018, 9, 11, /* 0 1 0 1 1 1 0 1 0 1 0 0 9/11/2018
- 1441*/0x05B5, 2019, 8, 31, /* 1 0 1 0 1 1 0 1 1 0 1 0 8/31/2019
- 1442*/0x05AA, 2020, 8, 20, /* 0 1 0 1 0 1 0 1 1 0 1 0 8/20/2020
- 1443*/0x0D55, 2021, 8, 9, /* 1 0 1 0 1 0 1 0 1 0 1 1 8/9/2021
- 1444*/0x0A9A, 2022, 7, 30, /* 0 1 0 1 1 0 0 1 0 1 0 1 7/30/2022
- 1445*/0x092E, 2023, 7, 19, /* 0 1 1 1 0 1 0 0 1 0 0 1 7/19/2023
- 1446*/0x026E, 2024, 7, 7, /* 0 1 1 1 0 1 1 0 0 1 0 0 7/7/2024
- 1447*/0x055D, 2025, 6, 26, /* 1 0 1 1 1 0 1 0 1 0 1 0 6/26/2025
- 1448*/0x0ADA, 2026, 6, 16, /* 0 1 0 1 1 0 1 1 0 1 0 1 6/16/2026
- 1449*/0x06D4, 2027, 6, 6, /* 0 0 1 0 1 0 1 1 0 1 1 0 6/6/2027
- 1450*/0x06A5, 2028, 5, 25, /* 1 0 1 0 0 1 0 1 0 1 1 0 5/25/2028
- 1451*/0x054B, 2029, 5, 14, /* 1 1 0 1 0 0 1 0 1 0 1 0 5/14/2029
- 1452*/0x0A97, 2030, 5, 3, /* 1 1 1 0 1 0 0 1 0 1 0 1 5/3/2030
- 1453*/0x054E, 2031, 4, 23, /* 0 1 1 1 0 0 1 0 1 0 1 0 4/23/2031
- 1454*/0x0AAE, 2032, 4, 11, /* 0 1 1 1 0 1 0 1 0 1 0 1 4/11/2032
- 1455*/0x05AC, 2033, 4, 1, /* 0 0 1 1 0 1 0 1 1 0 1 0 4/1/2033
- 1456*/0x0BA9, 2034, 3, 21, /* 1 0 0 1 0 1 0 1 1 1 0 1 3/21/2034
- 1457*/0x0D92, 2035, 3, 11, /* 0 1 0 0 1 0 0 1 1 0 1 1 3/11/2035
- 1458*/0x0B25, 2036, 2, 28, /* 1 0 1 0 0 1 0 0 1 1 0 1 2/28/2036
- 1459*/0x064B, 2037, 2, 16, /* 1 1 0 1 0 0 1 0 0 1 1 0 2/16/2037
- 1460*/0x0CAB, 2038, 2, 5, /* 1 1 0 1 0 1 0 1 0 0 1 1 2/5/2038
- 1461*/0x055A, 2039, 1, 26, /* 0 1 0 1 1 0 1 0 1 0 1 0 1/26/2039
- 1462*/0x0B55, 2040, 1, 15, /* 1 0 1 0 1 0 1 0 1 1 0 1 1/15/2040
- 1463*/0x06D2, 2041, 1, 4, /* 0 1 0 0 1 0 1 1 0 1 1 0 1/4/2041
- 1464*/0x0EA5, 2041, 12, 24, /* 1 0 1 0 0 1 0 1 0 1 1 1 12/24/2041
- 1465*/0x0E4A, 2042, 12, 14, /* 0 1 0 1 0 0 1 0 0 1 1 1 12/14/2042
- 1466*/0x0A95, 2043, 12, 3, /* 1 0 1 0 1 0 0 1 0 1 0 1 12/3/2043
- 1467*/0x052D, 2044, 11, 21, /* 1 0 1 1 0 1 0 0 1 0 1 0 11/21/2044
- 1468*/0x0AAD, 2045, 11, 10, /* 1 0 1 1 0 1 0 1 0 1 0 1 11/10/2045
- 1469*/0x036C, 2046, 10, 31, /* 0 0 1 1 0 1 1 0 1 1 0 0 10/31/2046
- 1470*/0x0759, 2047, 10, 20, /* 1 0 0 1 1 0 1 0 1 1 1 0 10/20/2047
- 1471*/0x06D2, 2048, 10, 9, /* 0 1 0 0 1 0 1 1 0 1 1 0 10/9/2048
- 1472*/0x0695, 2049, 9, 28, /* 1 0 1 0 1 0 0 1 0 1 1 0 9/28/2049
- 1473*/0x052D, 2050, 9, 17, /* 1 0 1 1 0 1 0 0 1 0 1 0 9/17/2050
- 1474*/0x0A5B, 2051, 9, 6, /* 1 1 0 1 1 0 1 0 0 1 0 1 9/6/2051
- 1475*/0x04BA, 2052, 8, 26, /* 0 1 0 1 1 1 0 1 0 0 1 0 8/26/2052
- 1476*/0x09BA, 2053, 8, 15, /* 0 1 0 1 1 1 0 1 1 0 0 1 8/15/2053
- 1477*/0x03B4, 2054, 8, 5, /* 0 0 1 0 1 1 0 1 1 1 0 0 8/5/2054
- 1478*/0x0B69, 2055, 7, 25, /* 1 0 0 1 0 1 1 0 1 1 0 1 7/25/2055
- 1479*/0x0B52, 2056, 7, 14, /* 0 1 0 0 1 0 1 0 1 1 0 1 7/14/2056
- 1480*/0x0AA6, 2057, 7, 3, /* 0 1 1 0 0 1 0 1 0 1 0 1 7/3/2057
- 1481*/0x04B6, 2058, 6, 22, /* 0 1 1 0 1 1 0 1 0 0 1 0 6/22/2058
- 1482*/0x096D, 2059, 6, 11, /* 1 0 1 1 0 1 1 0 1 0 0 1 6/11/2059
- 1483*/0x02EC, 2060, 5, 31, /* 0 0 1 1 0 1 1 1 0 1 0 0 5/31/2060
- 1484*/0x06D9, 2061, 5, 20, /* 1 0 0 1 1 0 1 1 0 1 1 0 5/20/2061
- 1485*/0x0EB2, 2062, 5, 10, /* 0 1 0 0 1 1 0 1 0 1 1 1 5/10/2062
- 1486*/0x0D54, 2063, 4, 30, /* 0 0 1 0 1 0 1 0 1 0 1 1 4/30/2063
- 1487*/0x0D2A, 2064, 4, 18, /* 0 1 0 1 0 1 0 0 1 0 1 1 4/18/2064
- 1488*/0x0A56, 2065, 4, 7, /* 0 1 1 0 1 0 1 0 0 1 0 1 4/7/2065
- 1489*/0x04AE, 2066, 3, 27, /* 0 1 1 1 0 1 0 1 0 0 1 0 3/27/2066
- 1490*/0x096D, 2067, 3, 16, /* 1 0 1 1 0 1 1 0 1 0 0 1 3/16/2067
- 1491*/0x0D6A, 2068, 3, 5, /* 0 1 0 1 0 1 1 0 1 0 1 1 3/5/2068
- 1492*/0x0B54, 2069, 2, 23, /* 0 0 1 0 1 0 1 0 1 1 0 1 2/23/2069
- 1493*/0x0B29, 2070, 2, 12, /* 1 0 0 1 0 1 0 0 1 1 0 1 2/12/2070
- 1494*/0x0A93, 2071, 2, 1, /* 1 1 0 0 1 0 0 1 0 1 0 1 2/1/2071
- 1495*/0x052B, 2072, 1, 21, /* 1 1 0 1 0 1 0 0 1 0 1 0 1/21/2072
- 1496*/0x0A57, 2073, 1, 9, /* 1 1 1 0 1 0 1 0 0 1 0 1 1/9/2073
- 1497*/0x0536, 2073, 12, 30, /* 0 1 1 0 1 1 0 0 1 0 1 0 12/30/2073
- 1498*/0x0AB5, 2074, 12, 19, /* 1 0 1 0 1 1 0 1 0 1 0 1 12/19/2074
- 1499*/0x06AA, 2075, 12, 9, /* 0 1 0 1 0 1 0 1 0 1 1 0 12/9/2075
- 1500*/0x0E93, 2076, 11, 27, /* 1 1 0 0 1 0 0 1 0 1 1 1 11/27/2076
- 1501*/ 0, 2077, 11, 17, /* 0 0 0 0 0 0 0 0 0 0 0 0 11/17/2077
- */ };
- // Direct inline initialization of DateMapping array would produce a lot of code bloat.
-
- // We take advantage of C# compiler compiles inline initialization of primitive type array into very compact code.
- // So we start with raw data stored in primitive type array, and initialize the DateMapping out of it
-
- DateMapping[] mapping = new DateMapping[rawData.Length / 4];
- for (int i = 0; i < mapping.Length; i++)
- mapping[i] = new DateMapping(rawData[i * 4], rawData[i * 4 + 1], rawData[i * 4 + 2], rawData[i * 4 + 3]);
- return mapping;
- }
-
- public const int UmAlQuraEra = 1;
-
- private const int DatePartYear = 0;
- private const int DatePartDayOfYear = 1;
- private const int DatePartMonth = 2;
- private const int DatePartDay = 3;
-
- private static readonly DateTime s_minDate = new DateTime(1900, 4, 30);
- private static readonly DateTime s_maxDate = new DateTime((new DateTime(2077, 11, 16, 23, 59, 59, 999)).Ticks + 9999);
-
- public override DateTime MinSupportedDateTime => s_minDate;
-
- public override DateTime MaxSupportedDateTime => s_maxDate;
-
- public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.LunarCalendar;
-
- public UmAlQuraCalendar()
- {
- }
-
- internal override CalendarId BaseCalendarID => CalendarId.HIJRI;
-
- internal override CalendarId ID => CalendarId.UMALQURA;
-
- protected override int DaysInYearBeforeMinSupportedYear =>
- // HijriCalendar has same number of days as UmAlQuraCalendar for any given year
- // HijriCalendar says year 1317 has 355 days.
- 355;
-
- private static void ConvertHijriToGregorian(int HijriYear, int HijriMonth, int HijriDay, out int yg, out int mg, out int dg)
- {
- Debug.Assert((HijriYear >= MinCalendarYear) && (HijriYear <= MaxCalendarYear), "Hijri year is out of range.");
- Debug.Assert(HijriMonth >= 1, "Hijri month is out of range.");
- Debug.Assert(HijriDay >= 1, "Hijri day is out of range.");
- int nDays = HijriDay - 1;
-
- int index = HijriYear - MinCalendarYear;
- DateTime dt = s_hijriYearInfo[index].GregorianDate;
- int b = s_hijriYearInfo[index].HijriMonthsLengthFlags;
-
- for (int m = 1; m < HijriMonth; m++)
- {
- // Add the months lengths before mh
- nDays = nDays + 29 + (b & 1);
- b >>= 1;
- }
-
- dt = dt.AddDays(nDays);
- dt.GetDatePart(out yg, out mg, out dg);
- }
-
- private static long GetAbsoluteDateUmAlQura(int year, int month, int day)
- {
- ConvertHijriToGregorian(year, month, day, out int yg, out int mg, out int dg);
- return GregorianCalendar.GetAbsoluteDate(yg, mg, dg);
- }
-
- internal static void CheckTicksRange(long ticks)
- {
- if (ticks < s_minDate.Ticks || ticks > s_maxDate.Ticks)
- {
- throw new ArgumentOutOfRangeException(
- "time",
- ticks,
- SR.Format(
- CultureInfo.InvariantCulture,
- SR.ArgumentOutOfRange_CalendarRange,
- s_minDate,
- s_maxDate));
- }
- }
-
- internal static void CheckEraRange(int era)
- {
- if (era != CurrentEra && era != UmAlQuraEra)
- {
- throw new ArgumentOutOfRangeException(nameof(era), era, SR.ArgumentOutOfRange_InvalidEraValue);
- }
- }
-
- internal static void CheckYearRange(int year, int era)
- {
- CheckEraRange(era);
- if (year < MinCalendarYear || year > MaxCalendarYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, MinCalendarYear, MaxCalendarYear));
- }
- }
-
- internal static void CheckYearMonthRange(int year, int month, int era)
- {
- CheckYearRange(year, era);
- if (month < 1 || month > 12)
- {
- throw new ArgumentOutOfRangeException(nameof(month), month, SR.ArgumentOutOfRange_Month);
- }
- }
-
- private static void ConvertGregorianToHijri(DateTime time, out int HijriYear, out int HijriMonth, out int HijriDay)
- {
- Debug.Assert((time.Ticks >= s_minDate.Ticks) && (time.Ticks <= s_maxDate.Ticks), "Gregorian date is out of range.");
-
- // Find the index where we should start our search by quessing the Hijri year that we will be in HijriYearInfo.
- // A Hijri year is 354 or 355 days. Use 355 days so that we will search from a lower index.
-
- int index = (int)((time.Ticks - s_minDate.Ticks) / Calendar.TicksPerDay) / 355;
- do
- {
- } while (time.CompareTo(s_hijriYearInfo[++index].GregorianDate) > 0); // while greater
-
- if (time.CompareTo(s_hijriYearInfo[index].GregorianDate) != 0)
- {
- index--;
- }
-
- TimeSpan ts = time.Subtract(s_hijriYearInfo[index].GregorianDate);
- int yh1 = index + MinCalendarYear;
- int mh1 = 1;
- int dh1 = 1;
- double nDays = ts.TotalDays;
- int b = s_hijriYearInfo[index].HijriMonthsLengthFlags;
- int daysPerThisMonth = 29 + (b & 1);
-
- while (nDays >= daysPerThisMonth)
- {
- nDays -= daysPerThisMonth;
- b >>= 1;
- daysPerThisMonth = 29 + (b & 1);
- mh1++;
- }
- dh1 += (int)nDays;
-
- HijriDay = dh1;
- HijriMonth = mh1;
- HijriYear = yh1;
- }
-
- /// <summary>
- /// First, we get the absolute date (the number of days from January 1st, 1 A.C) for the given ticks.
- /// Use the formula (((AbsoluteDate - 226894) * 33) / (33 * 365 + 8)) + 1, we can a rough value for the UmAlQura year.
- /// In order to get the exact UmAlQura year, we compare the exact absolute date for UmAlQuraYear and (UmAlQuraYear + 1).
- /// From here, we can get the correct UmAlQura year.
- /// </summary>
- private int GetDatePart(DateTime time, int part)
- {
- long ticks = time.Ticks;
- CheckTicksRange(ticks);
-
- ConvertGregorianToHijri(time, out int UmAlQuraYear, out int UmAlQuraMonth, out int UmAlQuraDay);
-
- if (part == DatePartYear)
- {
- return UmAlQuraYear;
- }
- if (part == DatePartMonth)
- {
- return UmAlQuraMonth;
- }
- if (part == DatePartDay)
- {
- return UmAlQuraDay;
- }
- if (part == DatePartDayOfYear)
- {
- return (int)(GetAbsoluteDateUmAlQura(UmAlQuraYear, UmAlQuraMonth, UmAlQuraDay) - GetAbsoluteDateUmAlQura(UmAlQuraYear, 1, 1) + 1);
- }
-
- // Incorrect part value.
- throw new InvalidOperationException(SR.InvalidOperation_DateTimeParsing);
- }
-
- public override DateTime AddMonths(DateTime time, int months)
- {
- if (months < -120000 || months > 120000)
- {
- throw new ArgumentOutOfRangeException(
- nameof(months),
- months,
- SR.Format(SR.ArgumentOutOfRange_Range, -120000, 120000));
- }
-
- // Get the date in UmAlQura calendar.
- int y = GetDatePart(time, DatePartYear);
- int m = GetDatePart(time, DatePartMonth);
- int d = GetDatePart(time, DatePartDay);
- int i = m - 1 + months;
-
- if (i >= 0)
- {
- m = i % 12 + 1;
- y += i / 12;
- }
- else
- {
- m = 12 + (i + 1) % 12;
- y += (i - 11) / 12;
- }
-
- if (d > 29)
- {
- int days = GetDaysInMonth(y, m);
- if (d > days)
- {
- d = days;
- }
- }
-
- CheckYearRange(y, UmAlQuraEra);
- DateTime dt = new DateTime(GetAbsoluteDateUmAlQura(y, m, d) * TicksPerDay + time.Ticks % TicksPerDay);
- Calendar.CheckAddResult(dt.Ticks, MinSupportedDateTime, MaxSupportedDateTime);
- return dt;
- }
-
- public override DateTime AddYears(DateTime time, int years)
- {
- return AddMonths(time, years * 12);
- }
-
- public override int GetDayOfMonth(DateTime time)
- {
- return GetDatePart(time, DatePartDay);
- }
-
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
- return (DayOfWeek)((int)(time.Ticks / TicksPerDay + 1) % 7);
- }
-
- public override int GetDayOfYear(DateTime time)
- {
- return GetDatePart(time, DatePartDayOfYear);
- }
-
- public override int GetDaysInMonth(int year, int month, int era)
- {
- CheckYearMonthRange(year, month, era);
-
- if ((s_hijriYearInfo[year - MinCalendarYear].HijriMonthsLengthFlags & (1 << month - 1)) == 0)
- {
- return 29;
- }
- else
- {
- return 30;
- }
- }
-
- internal static int RealGetDaysInYear(int year)
- {
- int days = 0;
-
- Debug.Assert((year >= MinCalendarYear) && (year <= MaxCalendarYear), "Hijri year is out of range.");
-
- int b = s_hijriYearInfo[year - MinCalendarYear].HijriMonthsLengthFlags;
-
- for (int m = 1; m <= 12; m++)
- {
- days = days + 29 + (b & 1); /* Add the months lengths before mh */
- b >>= 1;
- }
-
- Debug.Assert((days == 354) || (days == 355), "Hijri year has to be 354 or 355 days.");
- return days;
- }
-
- public override int GetDaysInYear(int year, int era)
- {
- CheckYearRange(year, era);
- return RealGetDaysInYear(year);
- }
-
- public override int GetEra(DateTime time)
- {
- CheckTicksRange(time.Ticks);
- return UmAlQuraEra;
- }
-
- public override int[] Eras => new int[] { UmAlQuraEra };
-
- public override int GetMonth(DateTime time)
- {
- return GetDatePart(time, DatePartMonth);
- }
-
- public override int GetMonthsInYear(int year, int era)
- {
- CheckYearRange(year, era);
- return 12;
- }
-
- public override int GetYear(DateTime time)
- {
- return GetDatePart(time, DatePartYear);
- }
-
- public override bool IsLeapDay(int year, int month, int day, int era)
- {
- if (day >= 1 && day <= 29)
- {
- CheckYearMonthRange(year, month, era);
- return false;
- }
-
- // The year/month/era value checking is done in GetDaysInMonth().
- int daysInMonth = GetDaysInMonth(year, month, era);
- if (day < 1 || day > daysInMonth)
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- day,
- SR.Format(SR.ArgumentOutOfRange_Day, daysInMonth, month));
- }
- return false;
- }
-
- public override int GetLeapMonth(int year, int era)
- {
- CheckYearRange(year, era);
- return 0;
- }
-
- public override bool IsLeapMonth(int year, int month, int era)
- {
- CheckYearMonthRange(year, month, era);
- return false;
- }
-
- public override bool IsLeapYear(int year, int era)
- {
- CheckYearRange(year, era);
- return RealGetDaysInYear(year) == 355;
- }
-
- public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
- {
- if (day >= 1 && day <= 29)
- {
- CheckYearMonthRange(year, month, era);
- goto DayInRang;
- }
-
- // The year/month/era value checking is done in GetDaysInMonth().
- int daysInMonth = GetDaysInMonth(year, month, era);
-
- if (day < 1 || day > daysInMonth)
- {
- throw new ArgumentOutOfRangeException(
- nameof(day),
- day,
- SR.Format(SR.ArgumentOutOfRange_Day, daysInMonth, month));
- }
- DayInRang:
- long lDate = GetAbsoluteDateUmAlQura(year, month, day);
- if (lDate < 0)
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay);
- }
-
- return new DateTime(lDate * GregorianCalendar.TicksPerDay + TimeToTicks(hour, minute, second, millisecond));
- }
-
- private const int DefaultTwoDigitYearMax = 1451;
-
- public override int TwoDigitYearMax
- {
- get
- {
- if (_twoDigitYearMax == -1)
- {
- _twoDigitYearMax = GetSystemTwoDigitYearSetting(ID, DefaultTwoDigitYearMax);
- }
-
- return _twoDigitYearMax;
- }
- set
- {
- if (value != 99 && (value < MinCalendarYear || value > MaxCalendarYear))
- {
- throw new ArgumentOutOfRangeException(
- nameof(value),
- value,
- SR.Format(SR.ArgumentOutOfRange_Range, MinCalendarYear, MaxCalendarYear));
- }
-
- VerifyWritable();
- // We allow year 99 to be set so that one can make ToFourDigitYearMax a no-op by setting TwoDigitYearMax to 99.
- _twoDigitYearMax = value;
- }
- }
-
- public override int ToFourDigitYear(int year)
- {
- if (year < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(year), year, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (year < 100)
- {
- return base.ToFourDigitYear(year);
- }
-
- if (year < MinCalendarYear || year > MaxCalendarYear)
- {
- throw new ArgumentOutOfRangeException(
- nameof(year),
- year,
- SR.Format(SR.ArgumentOutOfRange_Range, MinCalendarYear, MaxCalendarYear));
- }
-
- return year;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Globalization/UnicodeCategory.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/UnicodeCategory.cs
deleted file mode 100644
index f0ae1fdfd9d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Globalization/UnicodeCategory.cs
+++ /dev/null
@@ -1,40 +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.
-
-namespace System.Globalization
-{
- public enum UnicodeCategory
- {
- UppercaseLetter = 0,
- LowercaseLetter = 1,
- TitlecaseLetter = 2,
- ModifierLetter = 3,
- OtherLetter = 4,
- NonSpacingMark = 5,
- SpacingCombiningMark = 6,
- EnclosingMark = 7,
- DecimalDigitNumber = 8,
- LetterNumber = 9,
- OtherNumber = 10,
- SpaceSeparator = 11,
- LineSeparator = 12,
- ParagraphSeparator = 13,
- Control = 14,
- Format = 15,
- Surrogate = 16,
- PrivateUse = 17,
- ConnectorPunctuation = 18,
- DashPunctuation = 19,
- OpenPunctuation = 20,
- ClosePunctuation = 21,
- InitialQuotePunctuation = 22,
- FinalQuotePunctuation = 23,
- OtherPunctuation = 24,
- MathSymbol = 25,
- CurrencySymbol = 26,
- ModifierSymbol = 27,
- OtherSymbol = 28,
- OtherNotAssigned = 29,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Guid.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Guid.Unix.cs
deleted file mode 100644
index 5a1364d032d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Guid.Unix.cs
+++ /dev/null
@@ -1,37 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System
-{
- public partial struct Guid
- {
- // This will create a new random guid based on the https://www.ietf.org/rfc/rfc4122.txt
- public static unsafe Guid NewGuid()
- {
- Guid g;
- Interop.GetRandomBytes((byte*)&g, sizeof(Guid));
-
- const ushort VersionMask = 0xF000;
- const ushort RandomGuidVersion = 0x4000;
-
- const byte ClockSeqHiAndReservedMask = 0xC0;
- const byte ClockSeqHiAndReservedValue = 0x80;
-
- // Modify bits indicating the type of the GUID
-
- unchecked
- {
- // time_hi_and_version
- g._c = (short)((g._c & ~VersionMask) | RandomGuidVersion);
- // clock_seq_hi_and_reserved
- g._d = (byte)((g._d & ~ClockSeqHiAndReservedMask) | ClockSeqHiAndReservedValue);
- }
-
- return g;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Guid.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Guid.Windows.cs
deleted file mode 100644
index 5947cea4618..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Guid.Windows.cs
+++ /dev/null
@@ -1,28 +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.
-
-namespace System
-{
- public partial struct Guid
- {
- public static Guid NewGuid()
- {
- // CoCreateGuid should never return Guid.Empty, since it attempts to maintain some
- // uniqueness guarantees.
-
- Guid g;
- int hr = Interop.Ole32.CoCreateGuid(out g);
- // We don't expect that this will ever throw an error, none are even documented, and so we don't want to pull
- // in the HR to ComException mappings into the core library just for this so we will try a generic exception if
- // we ever hit this condition.
- if (hr != 0)
- {
- Exception ex = new Exception();
- ex.HResult = hr;
- throw ex;
- }
- return g;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Guid.cs b/netcore/System.Private.CoreLib/shared/System/Guid.cs
deleted file mode 100644
index 65370c0556e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Guid.cs
+++ /dev/null
@@ -1,1175 +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 System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- // Represents a Globally Unique Identifier.
- [StructLayout(LayoutKind.Sequential)]
- [Serializable]
- [NonVersionable] // This only applies to field layout
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public partial struct Guid : IFormattable, IComparable, IComparable<Guid>, IEquatable<Guid>, ISpanFormattable
- {
- public static readonly Guid Empty = default;
-
- private int _a; // Do not rename (binary serialization)
- private short _b; // Do not rename (binary serialization)
- private short _c; // Do not rename (binary serialization)
- private byte _d; // Do not rename (binary serialization)
- private byte _e; // Do not rename (binary serialization)
- private byte _f; // Do not rename (binary serialization)
- private byte _g; // Do not rename (binary serialization)
- private byte _h; // Do not rename (binary serialization)
- private byte _i; // Do not rename (binary serialization)
- private byte _j; // Do not rename (binary serialization)
- private byte _k; // Do not rename (binary serialization)
-
- // Creates a new guid from an array of bytes.
- public Guid(byte[] b) :
- this(new ReadOnlySpan<byte>(b ?? throw new ArgumentNullException(nameof(b))))
- {
- }
-
- // Creates a new guid from a read-only span.
- public Guid(ReadOnlySpan<byte> b)
- {
- if ((uint)b.Length != 16)
- {
- throw new ArgumentException(SR.Format(SR.Arg_GuidArrayCtor, "16"), nameof(b));
- }
-
- if (BitConverter.IsLittleEndian)
- {
- this = MemoryMarshal.Read<Guid>(b);
- return;
- }
-
- // slower path for BigEndian:
- _k = b[15]; // hoist bounds checks
- _a = b[3] << 24 | b[2] << 16 | b[1] << 8 | b[0];
- _b = (short)(b[5] << 8 | b[4]);
- _c = (short)(b[7] << 8 | b[6]);
- _d = b[8];
- _e = b[9];
- _f = b[10];
- _g = b[11];
- _h = b[12];
- _i = b[13];
- _j = b[14];
- }
-
- [CLSCompliant(false)]
- public Guid(uint a, ushort b, ushort c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k)
- {
- _a = (int)a;
- _b = (short)b;
- _c = (short)c;
- _d = d;
- _e = e;
- _f = f;
- _g = g;
- _h = h;
- _i = i;
- _j = j;
- _k = k;
- }
-
- // Creates a new GUID initialized to the value represented by the arguments.
- public Guid(int a, short b, short c, byte[] d)
- {
- if (d == null)
- {
- throw new ArgumentNullException(nameof(d));
- }
- if (d.Length != 8)
- {
- throw new ArgumentException(SR.Format(SR.Arg_GuidArrayCtor, "8"), nameof(d));
- }
-
- _a = a;
- _b = b;
- _c = c;
- _k = d[7]; // hoist bounds checks
- _d = d[0];
- _e = d[1];
- _f = d[2];
- _g = d[3];
- _h = d[4];
- _i = d[5];
- _j = d[6];
- }
-
- // Creates a new GUID initialized to the value represented by the
- // arguments. The bytes are specified like this to avoid endianness issues.
- public Guid(int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k)
- {
- _a = a;
- _b = b;
- _c = c;
- _d = d;
- _e = e;
- _f = f;
- _g = g;
- _h = h;
- _i = i;
- _j = j;
- _k = k;
- }
-
- private enum GuidParseThrowStyle : byte
- {
- None = 0,
- All = 1,
- AllButOverflow = 2
- }
-
- // This will store the result of the parsing. And it will eventually be used to construct a Guid instance.
- private struct GuidResult
- {
- private readonly GuidParseThrowStyle _throwStyle;
- internal Guid _parsedGuid;
-
- internal GuidResult(GuidParseThrowStyle canThrow) : this()
- {
- _throwStyle = canThrow;
- }
-
- internal void SetFailure(bool overflow, string failureMessageID)
- {
- if (_throwStyle == GuidParseThrowStyle.None)
- {
- return;
- }
-
- if (overflow)
- {
- if (_throwStyle == GuidParseThrowStyle.All)
- {
- throw new OverflowException(SR.GetResourceString(failureMessageID));
- }
-
- throw new FormatException(SR.Format_GuidUnrecognized);
- }
-
- throw new FormatException(SR.GetResourceString(failureMessageID));
- }
- }
-
- // Creates a new guid based on the value in the string. The value is made up
- // of hex digits speared by the dash ("-"). The string may begin and end with
- // brackets ("{", "}").
- //
- // The string must be of the form dddddddd-dddd-dddd-dddd-dddddddddddd. where
- // d is a hex digit. (That is 8 hex digits, followed by 4, then 4, then 4,
- // then 12) such as: "CA761232-ED42-11CE-BACD-00AA0057B223"
- public Guid(string g)
- {
- if (g == null)
- {
- throw new ArgumentNullException(nameof(g));
- }
-
- var result = new GuidResult(GuidParseThrowStyle.All);
- bool success = TryParseGuid(g, ref result);
- Debug.Assert(success, "GuidParseThrowStyle.All means throw on all failures");
-
- this = result._parsedGuid;
- }
-
- public static Guid Parse(string input) =>
- Parse(input != null ? (ReadOnlySpan<char>)input : throw new ArgumentNullException(nameof(input)));
-
- public static Guid Parse(ReadOnlySpan<char> input)
- {
- var result = new GuidResult(GuidParseThrowStyle.AllButOverflow);
- bool success = TryParseGuid(input, ref result);
- Debug.Assert(success, "GuidParseThrowStyle.AllButOverflow means throw on all failures");
-
- return result._parsedGuid;
- }
-
- public static bool TryParse(string? input, out Guid result)
- {
- if (input == null)
- {
- result = default;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)input, out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> input, out Guid result)
- {
- var parseResult = new GuidResult(GuidParseThrowStyle.None);
- if (TryParseGuid(input, ref parseResult))
- {
- result = parseResult._parsedGuid;
- return true;
- }
- else
- {
- result = default;
- return false;
- }
- }
-
- public static Guid ParseExact(string input, string format) =>
- ParseExact(
- input != null ? (ReadOnlySpan<char>)input : throw new ArgumentNullException(nameof(input)),
- format != null ? (ReadOnlySpan<char>)format : throw new ArgumentNullException(nameof(format)));
-
- public static Guid ParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format)
- {
- if (format.Length != 1)
- {
- // all acceptable format strings are of length 1
- throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
- }
-
- input = input.Trim();
-
- var result = new GuidResult(GuidParseThrowStyle.AllButOverflow);
- bool success = ((char)(format[0] | 0x20)) switch
- {
- 'd' => TryParseExactD(input, ref result),
- 'n' => TryParseExactN(input, ref result),
- 'b' => TryParseExactB(input, ref result),
- 'p' => TryParseExactP(input, ref result),
- 'x' => TryParseExactX(input, ref result),
- _ => throw new FormatException(SR.Format_InvalidGuidFormatSpecification),
- };
- Debug.Assert(success, "GuidParseThrowStyle.AllButOverflow means throw on all failures");
- return result._parsedGuid;
- }
-
- public static bool TryParseExact(string? input, string? format, out Guid result)
- {
- if (input == null)
- {
- result = default;
- return false;
- }
-
- return TryParseExact((ReadOnlySpan<char>)input, format, out result);
- }
-
- public static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, out Guid result)
- {
- if (format.Length != 1)
- {
- result = default;
- return false;
- }
-
- input = input.Trim();
-
- var parseResult = new GuidResult(GuidParseThrowStyle.None);
- bool success = false;
- switch ((char)(format[0] | 0x20))
- {
- case 'd':
- success = TryParseExactD(input, ref parseResult);
- break;
-
- case 'n':
- success = TryParseExactN(input, ref parseResult);
- break;
-
- case 'b':
- success = TryParseExactB(input, ref parseResult);
- break;
-
- case 'p':
- success = TryParseExactP(input, ref parseResult);
- break;
-
- case 'x':
- success = TryParseExactX(input, ref parseResult);
- break;
- }
-
- if (success)
- {
- result = parseResult._parsedGuid;
- return true;
- }
- else
- {
- result = default;
- return false;
- }
- }
-
- private static bool TryParseGuid(ReadOnlySpan<char> guidString, ref GuidResult result)
- {
- guidString = guidString.Trim(); // Remove whitespace from beginning and end
-
- if (guidString.Length == 0)
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidUnrecognized));
- return false;
- }
-
- return (guidString[0]) switch
- {
- '(' => TryParseExactP(guidString, ref result),
- '{' => guidString.Contains('-') ?
- TryParseExactB(guidString, ref result) :
- TryParseExactX(guidString, ref result),
- _ => guidString.Contains('-') ?
- TryParseExactD(guidString, ref result) :
- TryParseExactN(guidString, ref result),
- };
- }
-
- // Two helpers used for parsing components:
- // - uint.TryParse(..., NumberStyles.AllowHexSpecifier, ...)
- // Used when we expect the entire provided span to be filled with and only with hex digits and no overflow is possible
- // - TryParseHex
- // Used when the component may have an optional '+' and "0x" prefix, when it may overflow, etc.
-
- private static bool TryParseExactB(ReadOnlySpan<char> guidString, ref GuidResult result)
- {
- // e.g. "{d85b1407-351d-4694-9392-03acc5870eb1}"
-
- if ((uint)guidString.Length != 38 || guidString[0] != '{' || guidString[37] != '}')
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidInvLen));
- return false;
- }
-
- return TryParseExactD(guidString.Slice(1, 36), ref result);
- }
-
- private static bool TryParseExactD(ReadOnlySpan<char> guidString, ref GuidResult result)
- {
- // e.g. "d85b1407-351d-4694-9392-03acc5870eb1"
-
- // Compat notes due to the previous implementation's implementation details.
- // - Components may begin with "0x" or "0x+", but the expected length of each component
- // needs to include those prefixes, e.g. a four digit component could be "1234" or
- // "0x34" or "+0x4" or "+234", but not "0x1234" nor "+1234" nor "+0x1234".
- // - "0X" is valid instead of "0x"
-
- if ((uint)guidString.Length != 36)
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidInvLen));
- return false;
- }
-
- if (guidString[8] != '-' || guidString[13] != '-' || guidString[18] != '-' || guidString[23] != '-')
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidDashes));
- return false;
- }
-
- ref Guid g = ref result._parsedGuid;
-
- uint uintTmp;
- if (TryParseHex(guidString.Slice(0, 8), out Unsafe.As<int, uint>(ref g._a)) && // _a
- TryParseHex(guidString.Slice(9, 4), out uintTmp)) // _b
- {
- g._b = (short)uintTmp;
-
- if (TryParseHex(guidString.Slice(14, 4), out uintTmp)) // _c
- {
- g._c = (short)uintTmp;
-
- if (TryParseHex(guidString.Slice(19, 4), out uintTmp)) // _d, _e
- {
- g._d = (byte)(uintTmp >> 8);
- g._e = (byte)uintTmp;
-
- if (TryParseHex(guidString.Slice(24, 4), out uintTmp)) // _f, _g
- {
- g._f = (byte)(uintTmp >> 8);
- g._g = (byte)uintTmp;
-
- if (uint.TryParse(guidString.Slice(28, 8), NumberStyles.AllowHexSpecifier, null, out uintTmp)) // _h, _i, _j, _k
- {
- g._h = (byte)(uintTmp >> 24);
- g._i = (byte)(uintTmp >> 16);
- g._j = (byte)(uintTmp >> 8);
- g._k = (byte)uintTmp;
-
- return true;
- }
- }
- }
- }
- }
-
- result.SetFailure(overflow: false, nameof(SR.Format_GuidInvalidChar));
- return false;
- }
-
- private static bool TryParseExactN(ReadOnlySpan<char> guidString, ref GuidResult result)
- {
- // e.g. "d85b1407351d4694939203acc5870eb1"
-
- if ((uint)guidString.Length != 32)
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidInvLen));
- return false;
- }
-
- ref Guid g = ref result._parsedGuid;
-
- uint uintTmp;
- if (uint.TryParse(guidString.Slice(0, 8), NumberStyles.AllowHexSpecifier, null, out Unsafe.As<int, uint>(ref g._a)) && // _a
- uint.TryParse(guidString.Slice(8, 8), NumberStyles.AllowHexSpecifier, null, out uintTmp)) // _b, _c
- {
- g._b = (short)(uintTmp >> 16);
- g._c = (short)uintTmp;
-
- if (uint.TryParse(guidString.Slice(16, 8), NumberStyles.AllowHexSpecifier, null, out uintTmp)) // _d, _e, _f, _g
- {
- g._d = (byte)(uintTmp >> 24);
- g._e = (byte)(uintTmp >> 16);
- g._f = (byte)(uintTmp >> 8);
- g._g = (byte)uintTmp;
-
- if (uint.TryParse(guidString.Slice(24, 8), NumberStyles.AllowHexSpecifier, null, out uintTmp)) // _h, _i, _j, _k
- {
- g._h = (byte)(uintTmp >> 24);
- g._i = (byte)(uintTmp >> 16);
- g._j = (byte)(uintTmp >> 8);
- g._k = (byte)uintTmp;
-
- return true;
- }
- }
- }
-
- result.SetFailure(overflow: false, nameof(SR.Format_GuidInvalidChar));
- return false;
- }
-
- private static bool TryParseExactP(ReadOnlySpan<char> guidString, ref GuidResult result)
- {
- // e.g. "(d85b1407-351d-4694-9392-03acc5870eb1)"
-
- if ((uint)guidString.Length != 38 || guidString[0] != '(' || guidString[37] != ')')
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidInvLen));
- return false;
- }
-
- return TryParseExactD(guidString.Slice(1, 36), ref result);
- }
-
- private static bool TryParseExactX(ReadOnlySpan<char> guidString, ref GuidResult result)
- {
- // e.g. "{0xd85b1407,0x351d,0x4694,{0x93,0x92,0x03,0xac,0xc5,0x87,0x0e,0xb1}}"
-
- // Compat notes due to the previous implementation's implementation details.
- // - Each component need not be the full expected number of digits.
- // - Each component may contain any number of leading 0s
- // - The "short" components are parsed as 32-bits and only considered to overflow if they'd overflow 32 bits.
- // - The "byte" components are parsed as 32-bits and are considered to overflow if they'd overflow 8 bits,
- // but for the Guid ctor, whether they overflow 8 bits or 32 bits results in differing exceptions.
- // - Components may begin with "0x", "0x+", even "0x+0x".
- // - "0X" is valid instead of "0x"
-
- // Eat all of the whitespace. Unlike the other forms, X allows for any amount of whitespace
- // anywhere, not just at the beginning and end.
- guidString = EatAllWhitespace(guidString);
-
- // Check for leading '{'
- if ((uint)guidString.Length == 0 || guidString[0] != '{')
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidBrace));
- return false;
- }
-
- // Check for '0x'
- if (!IsHexPrefix(guidString, 1))
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidHexPrefix));
- return false;
- }
-
- // Find the end of this hex number (since it is not fixed length)
- int numStart = 3;
- int numLen = guidString.Slice(numStart).IndexOf(',');
- if (numLen <= 0)
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidComma));
- return false;
- }
-
- bool overflow = false;
- if (!TryParseHex(guidString.Slice(numStart, numLen), out Unsafe.As<int, uint>(ref result._parsedGuid._a), ref overflow) || overflow)
- {
- result.SetFailure(overflow, overflow ? nameof(SR.Overflow_UInt32) : nameof(SR.Format_GuidInvalidChar));
- return false;
- }
-
- // Check for '0x'
- if (!IsHexPrefix(guidString, numStart + numLen + 1))
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidHexPrefix));
- return false;
- }
- // +3 to get by ',0x'
- numStart = numStart + numLen + 3;
- numLen = guidString.Slice(numStart).IndexOf(',');
- if (numLen <= 0)
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidComma));
- return false;
- }
-
- // Read in the number
- if (!TryParseHex(guidString.Slice(numStart, numLen), out result._parsedGuid._b, ref overflow) || overflow)
- {
- result.SetFailure(overflow, overflow ? nameof(SR.Overflow_UInt32) : nameof(SR.Format_GuidInvalidChar));
- return false;
- }
-
- // Check for '0x'
- if (!IsHexPrefix(guidString, numStart + numLen + 1))
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidHexPrefix));
- return false;
- }
- // +3 to get by ',0x'
- numStart = numStart + numLen + 3;
- numLen = guidString.Slice(numStart).IndexOf(',');
- if (numLen <= 0)
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidComma));
- return false;
- }
-
- // Read in the number
- if (!TryParseHex(guidString.Slice(numStart, numLen), out result._parsedGuid._c, ref overflow) || overflow)
- {
- result.SetFailure(overflow, overflow ? nameof(SR.Overflow_UInt32) : nameof(SR.Format_GuidInvalidChar));
- return false;
- }
-
- // Check for '{'
- if ((uint)guidString.Length <= (uint)(numStart + numLen + 1) || guidString[numStart + numLen + 1] != '{')
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidBrace));
- return false;
- }
-
- // Prepare for loop
- numLen++;
- for (int i = 0; i < 8; i++)
- {
- // Check for '0x'
- if (!IsHexPrefix(guidString, numStart + numLen + 1))
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidHexPrefix));
- return false;
- }
-
- // +3 to get by ',0x' or '{0x' for first case
- numStart = numStart + numLen + 3;
-
- // Calculate number length
- if (i < 7) // first 7 cases
- {
- numLen = guidString.Slice(numStart).IndexOf(',');
- if (numLen <= 0)
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidComma));
- return false;
- }
- }
- else // last case ends with '}', not ','
- {
- numLen = guidString.Slice(numStart).IndexOf('}');
- if (numLen <= 0)
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidBraceAfterLastNumber));
- return false;
- }
- }
-
- // Read in the number
- uint byteVal;
- if (!TryParseHex(guidString.Slice(numStart, numLen), out byteVal, ref overflow) || overflow || byteVal > byte.MaxValue)
- {
- // The previous implementation had some odd inconsistencies, which are carried forward here.
- // The byte values in the X format are treated as integers with regards to overflow, so
- // a "byte" value like 0xddd in Guid's ctor results in a FormatException but 0xddddddddd results
- // in OverflowException.
- result.SetFailure(overflow,
- overflow ? nameof(SR.Overflow_UInt32) :
- byteVal > byte.MaxValue ? nameof(SR.Overflow_Byte) :
- nameof(SR.Format_GuidInvalidChar));
- return false;
- }
- Unsafe.Add(ref result._parsedGuid._d, i) = (byte)byteVal;
- }
-
- // Check for last '}'
- if (numStart + numLen + 1 >= guidString.Length || guidString[numStart + numLen + 1] != '}')
- {
- result.SetFailure(overflow: false, nameof(SR.Format_GuidEndBrace));
- return false;
- }
-
- // Check if we have extra characters at the end
- if (numStart + numLen + 1 != guidString.Length - 1)
- {
- result.SetFailure(overflow: false, nameof(SR.Format_ExtraJunkAtEnd));
- return false;
- }
-
- return true;
- }
-
- private static bool TryParseHex(ReadOnlySpan<char> guidString, out short result, ref bool overflow)
- {
- uint tmp;
- bool success = TryParseHex(guidString, out tmp, ref overflow);
- result = (short)tmp;
- return success;
- }
-
- private static bool TryParseHex(ReadOnlySpan<char> guidString, out uint result)
- {
- bool overflowIgnored = false;
- return TryParseHex(guidString, out result, ref overflowIgnored);
- }
-
- private static bool TryParseHex(ReadOnlySpan<char> guidString, out uint result, ref bool overflow)
- {
- if ((uint)guidString.Length > 0)
- {
- if (guidString[0] == '+')
- {
- guidString = guidString.Slice(1);
- }
-
- if ((uint)guidString.Length > 1 && guidString[0] == '0' && (guidString[1] | 0x20) == 'x')
- {
- guidString = guidString.Slice(2);
- }
- }
-
- // Skip past leading 0s.
- int i = 0;
- for (; i < guidString.Length && guidString[i] == '0'; i++) ;
-
- int processedDigits = 0;
- ReadOnlySpan<byte> charToHexLookup = Number.CharToHexLookup;
- uint tmp = 0;
- for (; i < guidString.Length; i++)
- {
- int numValue;
- char c = guidString[i];
- if (c >= (uint)charToHexLookup.Length || (numValue = charToHexLookup[c]) == 0xFF)
- {
- if (processedDigits > 8) overflow = true;
- result = 0;
- return false;
- }
- tmp = (tmp * 16) + (uint)numValue;
- processedDigits++;
- }
-
- if (processedDigits > 8) overflow = true;
- result = tmp;
- return true;
- }
-
- private static ReadOnlySpan<char> EatAllWhitespace(ReadOnlySpan<char> str)
- {
- // Find the first whitespace character. If there is none, just return the input.
- int i;
- for (i = 0; i < str.Length && !char.IsWhiteSpace(str[i]); i++) ;
- if (i == str.Length)
- {
- return str;
- }
-
- // There was at least one whitespace. Copy over everything prior to it to a new array.
- var chArr = new char[str.Length];
- int newLength = 0;
- if (i > 0)
- {
- newLength = i;
- str.Slice(0, i).CopyTo(chArr);
- }
-
- // Loop through the remaining chars, copying over non-whitespace.
- for (; i < str.Length; i++)
- {
- char c = str[i];
- if (!char.IsWhiteSpace(c))
- {
- chArr[newLength++] = c;
- }
- }
-
- // Return the string with the whitespace removed.
- return new ReadOnlySpan<char>(chArr, 0, newLength);
- }
-
- private static bool IsHexPrefix(ReadOnlySpan<char> str, int i) =>
- i + 1 < str.Length &&
- str[i] == '0' &&
- (str[i + 1] | 0x20) == 'x';
-
- // Returns an unsigned byte array containing the GUID.
- public byte[] ToByteArray()
- {
- var g = new byte[16];
- if (BitConverter.IsLittleEndian)
- {
- MemoryMarshal.TryWrite<Guid>(g, ref this);
- }
- else
- {
- TryWriteBytes(g);
- }
- return g;
- }
-
- // Returns whether bytes are sucessfully written to given span.
- public bool TryWriteBytes(Span<byte> destination)
- {
- if (BitConverter.IsLittleEndian)
- {
- return MemoryMarshal.TryWrite(destination, ref this);
- }
-
- // slower path for BigEndian
- if (destination.Length < 16)
- return false;
-
- destination[15] = _k; // hoist bounds checks
- destination[0] = (byte)(_a);
- destination[1] = (byte)(_a >> 8);
- destination[2] = (byte)(_a >> 16);
- destination[3] = (byte)(_a >> 24);
- destination[4] = (byte)(_b);
- destination[5] = (byte)(_b >> 8);
- destination[6] = (byte)(_c);
- destination[7] = (byte)(_c >> 8);
- destination[8] = _d;
- destination[9] = _e;
- destination[10] = _f;
- destination[11] = _g;
- destination[12] = _h;
- destination[13] = _i;
- destination[14] = _j;
- return true;
- }
-
- // Returns the guid in "registry" format.
- public override string ToString() => ToString("D", null);
-
- public override int GetHashCode()
- {
- // Simply XOR all the bits of the GUID 32 bits at a time.
- return _a ^ Unsafe.Add(ref _a, 1) ^ Unsafe.Add(ref _a, 2) ^ Unsafe.Add(ref _a, 3);
- }
-
- // Returns true if and only if the guid represented
- // by o is the same as this instance.
- public override bool Equals(object? o)
- {
- Guid g;
- // Check that o is a Guid first
- if (o == null || !(o is Guid))
- return false;
- else g = (Guid)o;
-
- // Now compare each of the elements
- return g._a == _a &&
- Unsafe.Add(ref g._a, 1) == Unsafe.Add(ref _a, 1) &&
- Unsafe.Add(ref g._a, 2) == Unsafe.Add(ref _a, 2) &&
- Unsafe.Add(ref g._a, 3) == Unsafe.Add(ref _a, 3);
- }
-
- public bool Equals(Guid g)
- {
- // Now compare each of the elements
- return g._a == _a &&
- Unsafe.Add(ref g._a, 1) == Unsafe.Add(ref _a, 1) &&
- Unsafe.Add(ref g._a, 2) == Unsafe.Add(ref _a, 2) &&
- Unsafe.Add(ref g._a, 3) == Unsafe.Add(ref _a, 3);
- }
-
- private int GetResult(uint me, uint them) => me < them ? -1 : 1;
-
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
- if (!(value is Guid))
- {
- throw new ArgumentException(SR.Arg_MustBeGuid, nameof(value));
- }
- Guid g = (Guid)value;
-
- if (g._a != _a)
- {
- return GetResult((uint)_a, (uint)g._a);
- }
-
- if (g._b != _b)
- {
- return GetResult((uint)_b, (uint)g._b);
- }
-
- if (g._c != _c)
- {
- return GetResult((uint)_c, (uint)g._c);
- }
-
- if (g._d != _d)
- {
- return GetResult(_d, g._d);
- }
-
- if (g._e != _e)
- {
- return GetResult(_e, g._e);
- }
-
- if (g._f != _f)
- {
- return GetResult(_f, g._f);
- }
-
- if (g._g != _g)
- {
- return GetResult(_g, g._g);
- }
-
- if (g._h != _h)
- {
- return GetResult(_h, g._h);
- }
-
- if (g._i != _i)
- {
- return GetResult(_i, g._i);
- }
-
- if (g._j != _j)
- {
- return GetResult(_j, g._j);
- }
-
- if (g._k != _k)
- {
- return GetResult(_k, g._k);
- }
-
- return 0;
- }
-
- public int CompareTo(Guid value)
- {
- if (value._a != _a)
- {
- return GetResult((uint)_a, (uint)value._a);
- }
-
- if (value._b != _b)
- {
- return GetResult((uint)_b, (uint)value._b);
- }
-
- if (value._c != _c)
- {
- return GetResult((uint)_c, (uint)value._c);
- }
-
- if (value._d != _d)
- {
- return GetResult(_d, value._d);
- }
-
- if (value._e != _e)
- {
- return GetResult(_e, value._e);
- }
-
- if (value._f != _f)
- {
- return GetResult(_f, value._f);
- }
-
- if (value._g != _g)
- {
- return GetResult(_g, value._g);
- }
-
- if (value._h != _h)
- {
- return GetResult(_h, value._h);
- }
-
- if (value._i != _i)
- {
- return GetResult(_i, value._i);
- }
-
- if (value._j != _j)
- {
- return GetResult(_j, value._j);
- }
-
- if (value._k != _k)
- {
- return GetResult(_k, value._k);
- }
-
- return 0;
- }
-
- public static bool operator ==(Guid a, Guid b) =>
- a._a == b._a &&
- Unsafe.Add(ref a._a, 1) == Unsafe.Add(ref b._a, 1) &&
- Unsafe.Add(ref a._a, 2) == Unsafe.Add(ref b._a, 2) &&
- Unsafe.Add(ref a._a, 3) == Unsafe.Add(ref b._a, 3);
-
- public static bool operator !=(Guid a, Guid b) =>
- // Now compare each of the elements
- a._a != b._a ||
- Unsafe.Add(ref a._a, 1) != Unsafe.Add(ref b._a, 1) ||
- Unsafe.Add(ref a._a, 2) != Unsafe.Add(ref b._a, 2) ||
- Unsafe.Add(ref a._a, 3) != Unsafe.Add(ref b._a, 3);
-
- public string ToString(string? format)
- {
- return ToString(format, null);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static char HexToChar(int a)
- {
- a &= 0xf;
- return (char)((a > 9) ? a - 10 + 0x61 : a + 0x30);
- }
-
- private static unsafe int HexsToChars(char* guidChars, int a, int b)
- {
- guidChars[0] = HexToChar(a >> 4);
- guidChars[1] = HexToChar(a);
-
- guidChars[2] = HexToChar(b >> 4);
- guidChars[3] = HexToChar(b);
-
- return 4;
- }
-
- private static unsafe int HexsToCharsHexOutput(char* guidChars, int a, int b)
- {
- guidChars[0] = '0';
- guidChars[1] = 'x';
-
- guidChars[2] = HexToChar(a >> 4);
- guidChars[3] = HexToChar(a);
-
- guidChars[4] = ',';
- guidChars[5] = '0';
- guidChars[6] = 'x';
-
- guidChars[7] = HexToChar(b >> 4);
- guidChars[8] = HexToChar(b);
-
- return 9;
- }
-
- // IFormattable interface
- // We currently ignore provider
- public string ToString(string? format, IFormatProvider? provider)
- {
- if (string.IsNullOrEmpty(format))
- {
- format = "D";
- }
-
- // all acceptable format strings are of length 1
- if (format.Length != 1)
- {
- throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
- }
-
- int guidSize;
- switch (format[0])
- {
- case 'D':
- case 'd':
- guidSize = 36;
- break;
- case 'N':
- case 'n':
- guidSize = 32;
- break;
- case 'B':
- case 'b':
- case 'P':
- case 'p':
- guidSize = 38;
- break;
- case 'X':
- case 'x':
- guidSize = 68;
- break;
- default:
- throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
- }
-
- string guidString = string.FastAllocateString(guidSize);
-
- int bytesWritten;
- bool result = TryFormat(new Span<char>(ref guidString.GetRawStringData(), guidString.Length), out bytesWritten, format);
- Debug.Assert(result && bytesWritten == guidString.Length, "Formatting guid should have succeeded.");
-
- return guidString;
- }
-
- // Returns whether the guid is successfully formatted as a span.
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default)
- {
- if (format.Length == 0)
- {
- format = "D";
- }
- // all acceptable format strings are of length 1
- if (format.Length != 1)
- {
- throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
- }
-
- bool dash = true;
- bool hex = false;
- int braces = 0;
-
- int guidSize;
-
- switch (format[0])
- {
- case 'D':
- case 'd':
- guidSize = 36;
- break;
- case 'N':
- case 'n':
- dash = false;
- guidSize = 32;
- break;
- case 'B':
- case 'b':
- braces = '{' + ('}' << 16);
- guidSize = 38;
- break;
- case 'P':
- case 'p':
- braces = '(' + (')' << 16);
- guidSize = 38;
- break;
- case 'X':
- case 'x':
- braces = '{' + ('}' << 16);
- dash = false;
- hex = true;
- guidSize = 68;
- break;
- default:
- throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
- }
-
- if (destination.Length < guidSize)
- {
- charsWritten = 0;
- return false;
- }
-
- unsafe
- {
- fixed (char* guidChars = &MemoryMarshal.GetReference(destination))
- {
- char* p = guidChars;
-
- if (braces != 0)
- *p++ = (char)braces;
-
- if (hex)
- {
- // {0xdddddddd,0xdddd,0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}}
- *p++ = '0';
- *p++ = 'x';
- p += HexsToChars(p, _a >> 24, _a >> 16);
- p += HexsToChars(p, _a >> 8, _a);
- *p++ = ',';
- *p++ = '0';
- *p++ = 'x';
- p += HexsToChars(p, _b >> 8, _b);
- *p++ = ',';
- *p++ = '0';
- *p++ = 'x';
- p += HexsToChars(p, _c >> 8, _c);
- *p++ = ',';
- *p++ = '{';
- p += HexsToCharsHexOutput(p, _d, _e);
- *p++ = ',';
- p += HexsToCharsHexOutput(p, _f, _g);
- *p++ = ',';
- p += HexsToCharsHexOutput(p, _h, _i);
- *p++ = ',';
- p += HexsToCharsHexOutput(p, _j, _k);
- *p++ = '}';
- }
- else
- {
- // [{|(]dddddddd[-]dddd[-]dddd[-]dddd[-]dddddddddddd[}|)]
- p += HexsToChars(p, _a >> 24, _a >> 16);
- p += HexsToChars(p, _a >> 8, _a);
- if (dash)
- *p++ = '-';
- p += HexsToChars(p, _b >> 8, _b);
- if (dash)
- *p++ = '-';
- p += HexsToChars(p, _c >> 8, _c);
- if (dash)
- *p++ = '-';
- p += HexsToChars(p, _d, _e);
- if (dash)
- *p++ = '-';
- p += HexsToChars(p, _f, _g);
- p += HexsToChars(p, _h, _i);
- p += HexsToChars(p, _j, _k);
- }
-
- if (braces != 0)
- *p++ = (char)(braces >> 16);
-
- Debug.Assert(p - guidChars == guidSize);
- }
- }
-
- charsWritten = guidSize;
- return true;
- }
-
- bool ISpanFormattable.TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
- {
- // Like with the IFormattable implementation, provider is ignored.
- return TryFormat(destination, out charsWritten, format);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/HResults.cs b/netcore/System.Private.CoreLib/shared/System/HResults.cs
deleted file mode 100644
index eb12058f8b6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/HResults.cs
+++ /dev/null
@@ -1,128 +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.
-
-// =============================================================================
-//
-//
-// Purpose: Define HResult constants. Every exception has one of these.
-//
-//
-// ===========================================================================*/
-// Note: FACILITY_URT is defined as 0x13 (0x8013xxxx). Within that
-// range, 0x1yyy is for Runtime errors (used for Security, Metadata, etc).
-// In that subrange, 0x15zz and 0x16zz have been allocated for classlib-type
-// HResults. Also note that some of our HResults have to map to certain
-// COM HR's, etc.
-
-// Reflection will use 0x1600 -> 0x161f. IO will use 0x1620 -> 0x163f.
-// Security will use 0x1640 -> 0x165f
-
-namespace System
-{
- internal static partial class HResults
- {
- internal const int S_OK = unchecked((int)0x00000000);
- internal const int S_FALSE = unchecked((int)0x1);
- internal const int COR_E_ABANDONEDMUTEX = unchecked((int)0x8013152D);
- internal const int COR_E_AMBIGUOUSIMPLEMENTATION = unchecked((int)0x8013106A);
- internal const int COR_E_AMBIGUOUSMATCH = unchecked((int)0x8000211D);
- internal const int COR_E_APPLICATION = unchecked((int)0x80131600);
- internal const int COR_E_ARGUMENT = unchecked((int)0x80070057);
- internal const int COR_E_ARGUMENTOUTOFRANGE = unchecked((int)0x80131502);
- internal const int COR_E_ARITHMETIC = unchecked((int)0x80070216);
- internal const int COR_E_ARRAYTYPEMISMATCH = unchecked((int)0x80131503);
- internal const int COR_E_BADEXEFORMAT = unchecked((int)0x800700C1);
- internal const int COR_E_BADIMAGEFORMAT = unchecked((int)0x8007000B);
- internal const int COR_E_CANNOTUNLOADAPPDOMAIN = unchecked((int)0x80131015);
- internal const int COR_E_CODECONTRACTFAILED = unchecked((int)0x80131542);
- internal const int COR_E_COMEMULATE = unchecked((int)0x80131535);
- internal const int COR_E_CONTEXTMARSHAL = unchecked((int)0x80131504);
- internal const int COR_E_CUSTOMATTRIBUTEFORMAT = unchecked((int)0x80131605);
- internal const int COR_E_DATAMISALIGNED = unchecked((int)0x80131541);
- internal const int COR_E_DIRECTORYNOTFOUND = unchecked((int)0x80070003);
- internal const int COR_E_DIVIDEBYZERO = unchecked((int)0x80020012); // DISP_E_DIVBYZERO
- internal const int COR_E_DLLNOTFOUND = unchecked((int)0x80131524);
- internal const int COR_E_DUPLICATEWAITOBJECT = unchecked((int)0x80131529);
- internal const int COR_E_ENDOFSTREAM = unchecked((int)0x80070026); // OS defined
- internal const int COR_E_ENTRYPOINTNOTFOUND = unchecked((int)0x80131523);
- internal const int COR_E_EXCEPTION = unchecked((int)0x80131500);
- internal const int COR_E_EXECUTIONENGINE = unchecked((int)0x80131506);
- internal const int COR_E_FIELDACCESS = unchecked((int)0x80131507);
- internal const int COR_E_FILELOAD = unchecked((int)0x80131621);
- internal const int COR_E_FILENOTFOUND = unchecked((int)0x80070002);
- internal const int COR_E_FORMAT = unchecked((int)0x80131537);
- internal const int COR_E_HOSTPROTECTION = unchecked((int)0x80131640);
- internal const int COR_E_INDEXOUTOFRANGE = unchecked((int)0x80131508);
- internal const int COR_E_INSUFFICIENTEXECUTIONSTACK = unchecked((int)0x80131578);
- internal const int COR_E_INSUFFICIENTMEMORY = unchecked((int)0x8013153D);
- internal const int COR_E_INVALIDCAST = unchecked((int)0x80004002);
- internal const int COR_E_INVALIDCOMOBJECT = unchecked((int)0x80131527);
- internal const int COR_E_INVALIDFILTERCRITERIA = unchecked((int)0x80131601);
- internal const int COR_E_INVALIDOLEVARIANTTYPE = unchecked((int)0x80131531);
- internal const int COR_E_INVALIDOPERATION = unchecked((int)0x80131509);
- internal const int COR_E_INVALIDPROGRAM = unchecked((int)0x8013153A);
- internal const int COR_E_IO = unchecked((int)0x80131620);
- internal const int COR_E_KEYNOTFOUND = unchecked((int)0x80131577);
- internal const int COR_E_MARSHALDIRECTIVE = unchecked((int)0x80131535);
- internal const int COR_E_MEMBERACCESS = unchecked((int)0x8013151A);
- internal const int COR_E_METHODACCESS = unchecked((int)0x80131510);
- internal const int COR_E_MISSINGFIELD = unchecked((int)0x80131511);
- internal const int COR_E_MISSINGMANIFESTRESOURCE = unchecked((int)0x80131532);
- internal const int COR_E_MISSINGMEMBER = unchecked((int)0x80131512);
- internal const int COR_E_MISSINGMETHOD = unchecked((int)0x80131513);
- internal const int COR_E_MISSINGSATELLITEASSEMBLY = unchecked((int)0x80131536);
- internal const int COR_E_MULTICASTNOTSUPPORTED = unchecked((int)0x80131514);
- internal const int COR_E_NOTFINITENUMBER = unchecked((int)0x80131528);
- internal const int COR_E_NOTSUPPORTED = unchecked((int)0x80131515);
- internal const int COR_E_NULLREFERENCE = unchecked((int)0x80004003);
- internal const int COR_E_OBJECTDISPOSED = unchecked((int)0x80131622);
- internal const int COR_E_OPERATIONCANCELED = unchecked((int)0x8013153B);
- internal const int COR_E_OUTOFMEMORY = unchecked((int)0x8007000E);
- internal const int COR_E_OVERFLOW = unchecked((int)0x80131516);
- internal const int COR_E_PATHTOOLONG = unchecked((int)0x800700CE);
- internal const int COR_E_PLATFORMNOTSUPPORTED = unchecked((int)0x80131539);
- internal const int COR_E_RANK = unchecked((int)0x80131517);
- internal const int COR_E_REFLECTIONTYPELOAD = unchecked((int)0x80131602);
- internal const int COR_E_RUNTIMEWRAPPED = unchecked((int)0x8013153E);
- internal const int COR_E_SAFEARRAYRANKMISMATCH = unchecked((int)0x80131538);
- internal const int COR_E_SAFEARRAYTYPEMISMATCH = unchecked((int)0x80131533);
- internal const int COR_E_SAFEHANDLEMISSINGATTRIBUTE = unchecked((int)0x80131623);
- internal const int COR_E_SECURITY = unchecked((int)0x8013150A);
- internal const int COR_E_SEMAPHOREFULL = unchecked((int)0x8013152B);
- internal const int COR_E_SERIALIZATION = unchecked((int)0x8013150C);
- internal const int COR_E_STACKOVERFLOW = unchecked((int)0x800703E9);
- internal const int COR_E_SYNCHRONIZATIONLOCK = unchecked((int)0x80131518);
- internal const int COR_E_SYSTEM = unchecked((int)0x80131501);
- internal const int COR_E_TARGET = unchecked((int)0x80131603);
- internal const int COR_E_TARGETINVOCATION = unchecked((int)0x80131604);
- internal const int COR_E_TARGETPARAMCOUNT = unchecked((int)0x8002000E);
- internal const int COR_E_THREADABORTED = unchecked((int)0x80131530);
- internal const int COR_E_THREADINTERRUPTED = unchecked((int)0x80131519);
- internal const int COR_E_THREADSTART = unchecked((int)0x80131525);
- internal const int COR_E_THREADSTATE = unchecked((int)0x80131520);
- internal const int COR_E_THREADSTOP = unchecked((int)0x80131521);
- internal const int COR_E_TIMEOUT = unchecked((int)0x80131505);
- internal const int COR_E_TYPEACCESS = unchecked((int)0x80131543);
- internal const int COR_E_TYPEINITIALIZATION = unchecked((int)0x80131534);
- internal const int COR_E_TYPELOAD = unchecked((int)0x80131522);
- internal const int COR_E_TYPEUNLOADED = unchecked((int)0x80131013);
- internal const int COR_E_UNAUTHORIZEDACCESS = unchecked((int)0x80070005);
- internal const int COR_E_UNSUPPORTEDFORMAT = unchecked((int)0x80131523);
- internal const int COR_E_VERIFICATION = unchecked((int)0x8013150D);
- internal const int COR_E_WAITHANDLECANNOTBEOPENED = unchecked((int)0x8013152C);
- internal const int DISP_E_OVERFLOW = unchecked((int)0x8002000A);
- internal const int E_BOUNDS = unchecked((int)0x8000000B);
- internal const int E_CHANGED_STATE = unchecked((int)0x8000000C);
- internal const int E_FAIL = unchecked((int)0x80004005);
- internal const int E_HANDLE = unchecked((int)0x80070006);
- internal const int E_INVALIDARG = unchecked((int)0x80070057);
- internal const int E_NOTIMPL = unchecked((int)0x80004001);
- internal const int E_POINTER = unchecked((int)0x80004003);
- internal const int ERROR_MRM_MAP_NOT_FOUND = unchecked((int)0x80073B1F);
- internal const int RO_E_CLOSED = unchecked((int)0x80000013);
- internal const int TYPE_E_TYPEMISMATCH = unchecked((int)0x80028CA0);
- internal const int CO_E_NOTINITIALIZED = unchecked((int)0x800401F0);
- internal const int RPC_E_CHANGED_MODE = unchecked((int)0x80010106);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/HashCode.cs b/netcore/System.Private.CoreLib/shared/System/HashCode.cs
deleted file mode 100644
index 0ff94adf17b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/HashCode.cs
+++ /dev/null
@@ -1,423 +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.
-
-/*
-
-The xxHash32 implementation is based on the code published by Yann Collet:
-https://raw.githubusercontent.com/Cyan4973/xxHash/5c174cfa4e45a42f94082dc0d4539b39696afea1/xxhash.c
-
- xxHash - Fast Hash algorithm
- Copyright (C) 2012-2016, Yann Collet
-
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following disclaimer
- in the documentation and/or other materials provided with the
- distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- You can contact the author at :
- - xxHash homepage: http://www.xxhash.com
- - xxHash source repository : https://github.com/Cyan4973/xxHash
-
-*/
-
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- // xxHash32 is used for the hash code.
- // https://github.com/Cyan4973/xxHash
-
- public struct HashCode
- {
- private static readonly uint s_seed = GenerateGlobalSeed();
-
- private const uint Prime1 = 2654435761U;
- private const uint Prime2 = 2246822519U;
- private const uint Prime3 = 3266489917U;
- private const uint Prime4 = 668265263U;
- private const uint Prime5 = 374761393U;
-
- private uint _v1, _v2, _v3, _v4;
- private uint _queue1, _queue2, _queue3;
- private uint _length;
-
- private static unsafe uint GenerateGlobalSeed()
- {
- uint result;
- Interop.GetRandomBytes((byte*)&result, sizeof(uint));
- return result;
- }
-
- public static int Combine<T1>(T1 value1)
- {
- // Provide a way of diffusing bits from something with a limited
- // input hash space. For example, many enums only have a few
- // possible hashes, only using the bottom few bits of the code. Some
- // collections are built on the assumption that hashes are spread
- // over a larger space, so diffusing the bits may help the
- // collection work more efficiently.
-
- uint hc1 = (uint)(value1?.GetHashCode() ?? 0);
-
- uint hash = MixEmptyState();
- hash += 4;
-
- hash = QueueRound(hash, hc1);
-
- hash = MixFinal(hash);
- return (int)hash;
- }
-
- public static int Combine<T1, T2>(T1 value1, T2 value2)
- {
- uint hc1 = (uint)(value1?.GetHashCode() ?? 0);
- uint hc2 = (uint)(value2?.GetHashCode() ?? 0);
-
- uint hash = MixEmptyState();
- hash += 8;
-
- hash = QueueRound(hash, hc1);
- hash = QueueRound(hash, hc2);
-
- hash = MixFinal(hash);
- return (int)hash;
- }
-
- public static int Combine<T1, T2, T3>(T1 value1, T2 value2, T3 value3)
- {
- uint hc1 = (uint)(value1?.GetHashCode() ?? 0);
- uint hc2 = (uint)(value2?.GetHashCode() ?? 0);
- uint hc3 = (uint)(value3?.GetHashCode() ?? 0);
-
- uint hash = MixEmptyState();
- hash += 12;
-
- hash = QueueRound(hash, hc1);
- hash = QueueRound(hash, hc2);
- hash = QueueRound(hash, hc3);
-
- hash = MixFinal(hash);
- return (int)hash;
- }
-
- public static int Combine<T1, T2, T3, T4>(T1 value1, T2 value2, T3 value3, T4 value4)
- {
- uint hc1 = (uint)(value1?.GetHashCode() ?? 0);
- uint hc2 = (uint)(value2?.GetHashCode() ?? 0);
- uint hc3 = (uint)(value3?.GetHashCode() ?? 0);
- uint hc4 = (uint)(value4?.GetHashCode() ?? 0);
-
- Initialize(out uint v1, out uint v2, out uint v3, out uint v4);
-
- v1 = Round(v1, hc1);
- v2 = Round(v2, hc2);
- v3 = Round(v3, hc3);
- v4 = Round(v4, hc4);
-
- uint hash = MixState(v1, v2, v3, v4);
- hash += 16;
-
- hash = MixFinal(hash);
- return (int)hash;
- }
-
- public static int Combine<T1, T2, T3, T4, T5>(T1 value1, T2 value2, T3 value3, T4 value4, T5 value5)
- {
- uint hc1 = (uint)(value1?.GetHashCode() ?? 0);
- uint hc2 = (uint)(value2?.GetHashCode() ?? 0);
- uint hc3 = (uint)(value3?.GetHashCode() ?? 0);
- uint hc4 = (uint)(value4?.GetHashCode() ?? 0);
- uint hc5 = (uint)(value5?.GetHashCode() ?? 0);
-
- Initialize(out uint v1, out uint v2, out uint v3, out uint v4);
-
- v1 = Round(v1, hc1);
- v2 = Round(v2, hc2);
- v3 = Round(v3, hc3);
- v4 = Round(v4, hc4);
-
- uint hash = MixState(v1, v2, v3, v4);
- hash += 20;
-
- hash = QueueRound(hash, hc5);
-
- hash = MixFinal(hash);
- return (int)hash;
- }
-
- public static int Combine<T1, T2, T3, T4, T5, T6>(T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6)
- {
- uint hc1 = (uint)(value1?.GetHashCode() ?? 0);
- uint hc2 = (uint)(value2?.GetHashCode() ?? 0);
- uint hc3 = (uint)(value3?.GetHashCode() ?? 0);
- uint hc4 = (uint)(value4?.GetHashCode() ?? 0);
- uint hc5 = (uint)(value5?.GetHashCode() ?? 0);
- uint hc6 = (uint)(value6?.GetHashCode() ?? 0);
-
- Initialize(out uint v1, out uint v2, out uint v3, out uint v4);
-
- v1 = Round(v1, hc1);
- v2 = Round(v2, hc2);
- v3 = Round(v3, hc3);
- v4 = Round(v4, hc4);
-
- uint hash = MixState(v1, v2, v3, v4);
- hash += 24;
-
- hash = QueueRound(hash, hc5);
- hash = QueueRound(hash, hc6);
-
- hash = MixFinal(hash);
- return (int)hash;
- }
-
- public static int Combine<T1, T2, T3, T4, T5, T6, T7>(T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7)
- {
- uint hc1 = (uint)(value1?.GetHashCode() ?? 0);
- uint hc2 = (uint)(value2?.GetHashCode() ?? 0);
- uint hc3 = (uint)(value3?.GetHashCode() ?? 0);
- uint hc4 = (uint)(value4?.GetHashCode() ?? 0);
- uint hc5 = (uint)(value5?.GetHashCode() ?? 0);
- uint hc6 = (uint)(value6?.GetHashCode() ?? 0);
- uint hc7 = (uint)(value7?.GetHashCode() ?? 0);
-
- Initialize(out uint v1, out uint v2, out uint v3, out uint v4);
-
- v1 = Round(v1, hc1);
- v2 = Round(v2, hc2);
- v3 = Round(v3, hc3);
- v4 = Round(v4, hc4);
-
- uint hash = MixState(v1, v2, v3, v4);
- hash += 28;
-
- hash = QueueRound(hash, hc5);
- hash = QueueRound(hash, hc6);
- hash = QueueRound(hash, hc7);
-
- hash = MixFinal(hash);
- return (int)hash;
- }
-
- public static int Combine<T1, T2, T3, T4, T5, T6, T7, T8>(T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8)
- {
- uint hc1 = (uint)(value1?.GetHashCode() ?? 0);
- uint hc2 = (uint)(value2?.GetHashCode() ?? 0);
- uint hc3 = (uint)(value3?.GetHashCode() ?? 0);
- uint hc4 = (uint)(value4?.GetHashCode() ?? 0);
- uint hc5 = (uint)(value5?.GetHashCode() ?? 0);
- uint hc6 = (uint)(value6?.GetHashCode() ?? 0);
- uint hc7 = (uint)(value7?.GetHashCode() ?? 0);
- uint hc8 = (uint)(value8?.GetHashCode() ?? 0);
-
- Initialize(out uint v1, out uint v2, out uint v3, out uint v4);
-
- v1 = Round(v1, hc1);
- v2 = Round(v2, hc2);
- v3 = Round(v3, hc3);
- v4 = Round(v4, hc4);
-
- v1 = Round(v1, hc5);
- v2 = Round(v2, hc6);
- v3 = Round(v3, hc7);
- v4 = Round(v4, hc8);
-
- uint hash = MixState(v1, v2, v3, v4);
- hash += 32;
-
- hash = MixFinal(hash);
- return (int)hash;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void Initialize(out uint v1, out uint v2, out uint v3, out uint v4)
- {
- v1 = s_seed + Prime1 + Prime2;
- v2 = s_seed + Prime2;
- v3 = s_seed;
- v4 = s_seed - Prime1;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint Round(uint hash, uint input)
- {
- return BitOperations.RotateLeft(hash + input * Prime2, 13) * Prime1;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint QueueRound(uint hash, uint queuedValue)
- {
- return BitOperations.RotateLeft(hash + queuedValue * Prime3, 17) * Prime4;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint MixState(uint v1, uint v2, uint v3, uint v4)
- {
- return BitOperations.RotateLeft(v1, 1) + BitOperations.RotateLeft(v2, 7) + BitOperations.RotateLeft(v3, 12) + BitOperations.RotateLeft(v4, 18);
- }
-
- private static uint MixEmptyState()
- {
- return s_seed + Prime5;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint MixFinal(uint hash)
- {
- hash ^= hash >> 15;
- hash *= Prime2;
- hash ^= hash >> 13;
- hash *= Prime3;
- hash ^= hash >> 16;
- return hash;
- }
-
- public void Add<T>(T value)
- {
- Add(value?.GetHashCode() ?? 0);
- }
-
- public void Add<T>(T value, IEqualityComparer<T>? comparer)
- {
- Add(comparer != null ? comparer.GetHashCode(value) : (value?.GetHashCode() ?? 0));
- }
-
- private void Add(int value)
- {
- // The original xxHash works as follows:
- // 0. Initialize immediately. We can't do this in a struct (no
- // default ctor).
- // 1. Accumulate blocks of length 16 (4 uints) into 4 accumulators.
- // 2. Accumulate remaining blocks of length 4 (1 uint) into the
- // hash.
- // 3. Accumulate remaining blocks of length 1 into the hash.
-
- // There is no need for #3 as this type only accepts ints. _queue1,
- // _queue2 and _queue3 are basically a buffer so that when
- // ToHashCode is called we can execute #2 correctly.
-
- // We need to initialize the xxHash32 state (_v1 to _v4) lazily (see
- // #0) nd the last place that can be done if you look at the
- // original code is just before the first block of 16 bytes is mixed
- // in. The xxHash32 state is never used for streams containing fewer
- // than 16 bytes.
-
- // To see what's really going on here, have a look at the Combine
- // methods.
-
- uint val = (uint)value;
-
- // Storing the value of _length locally shaves of quite a few bytes
- // in the resulting machine code.
- uint previousLength = _length++;
- uint position = previousLength % 4;
-
- // Switch can't be inlined.
-
- if (position == 0)
- _queue1 = val;
- else if (position == 1)
- _queue2 = val;
- else if (position == 2)
- _queue3 = val;
- else // position == 3
- {
- if (previousLength == 3)
- Initialize(out _v1, out _v2, out _v3, out _v4);
-
- _v1 = Round(_v1, _queue1);
- _v2 = Round(_v2, _queue2);
- _v3 = Round(_v3, _queue3);
- _v4 = Round(_v4, val);
- }
- }
-
- public int ToHashCode()
- {
- // Storing the value of _length locally shaves of quite a few bytes
- // in the resulting machine code.
- uint length = _length;
-
- // position refers to the *next* queue position in this method, so
- // position == 1 means that _queue1 is populated; _queue2 would have
- // been populated on the next call to Add.
- uint position = length % 4;
-
- // If the length is less than 4, _v1 to _v4 don't contain anything
- // yet. xxHash32 treats this differently.
-
- uint hash = length < 4 ? MixEmptyState() : MixState(_v1, _v2, _v3, _v4);
-
- // _length is incremented once per Add(Int32) and is therefore 4
- // times too small (xxHash length is in bytes, not ints).
-
- hash += length * 4;
-
- // Mix what remains in the queue
-
- // Switch can't be inlined right now, so use as few branches as
- // possible by manually excluding impossible scenarios (position > 1
- // is always false if position is not > 0).
- if (position > 0)
- {
- hash = QueueRound(hash, _queue1);
- if (position > 1)
- {
- hash = QueueRound(hash, _queue2);
- if (position > 2)
- hash = QueueRound(hash, _queue3);
- }
- }
-
- hash = MixFinal(hash);
- return (int)hash;
- }
-
-#pragma warning disable 0809
- // Obsolete member 'memberA' overrides non-obsolete member 'memberB'.
- // Disallowing GetHashCode and Equals is by design
-
- // * We decided to not override GetHashCode() to produce the hash code
- // as this would be weird, both naming-wise as well as from a
- // behavioral standpoint (GetHashCode() should return the object's
- // hash code, not the one being computed).
-
- // * Even though ToHashCode() can be called safely multiple times on
- // this implementation, it is not part of the contract. If the
- // implementation has to change in the future we don't want to worry
- // about people who might have incorrectly used this type.
-
- [Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes. Use ToHashCode to retrieve the computed hash code.", error: true)]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override int GetHashCode() => throw new NotSupportedException(SR.HashCode_HashCodeNotSupported);
-
- [Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes.", error: true)]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override bool Equals(object? obj) => throw new NotSupportedException(SR.HashCode_EqualityNotSupported);
-#pragma warning restore 0809
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IAsyncDisposable.cs b/netcore/System.Private.CoreLib/shared/System/IAsyncDisposable.cs
deleted file mode 100644
index c29f549df29..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IAsyncDisposable.cs
+++ /dev/null
@@ -1,18 +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 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();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IAsyncResult.cs b/netcore/System.Private.CoreLib/shared/System/IAsyncResult.cs
deleted file mode 100644
index 1caa724c8fd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IAsyncResult.cs
+++ /dev/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.
-
-/*============================================================
-**
-** Interface: IAsyncResult
-**
-** Purpose: Interface to encapsulate the results of an async
-** operation
-**
-===========================================================*/
-
-using System.Threading;
-
-namespace System
-{
- public interface IAsyncResult
- {
- bool IsCompleted { get; }
-
- WaitHandle AsyncWaitHandle { get; }
-
-
- object? AsyncState { get; }
-
- bool CompletedSynchronously { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ICloneable.cs b/netcore/System.Private.CoreLib/shared/System/ICloneable.cs
deleted file mode 100644
index 9f123e45c84..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ICloneable.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System
-{
- public interface ICloneable
- {
- object Clone();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IComparable.cs b/netcore/System.Private.CoreLib/shared/System/IComparable.cs
deleted file mode 100644
index 6bde8b01355..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IComparable.cs
+++ /dev/null
@@ -1,39 +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 System.Diagnostics.CodeAnalysis;
-
-namespace System
-{
- // The IComparable interface is implemented by classes that support an
- // ordering of instances of the class. The ordering represented by
- // IComparable can be used to sort arrays and collections of objects
- // that implement the interface.
- //
- public interface IComparable
- {
- // Interface does not need to be marked with the serializable attribute
- // Compares this object to another object, returning an integer that
- // indicates the relationship. An implementation of this method must return
- // a value less than zero if this is less than object, zero
- // if this is equal to object, or a value greater than zero
- // if this is greater than object.
- //
- int CompareTo(object? obj);
- }
-
- // Generic version of IComparable.
-
- public interface IComparable<in T>
- {
- // Interface does not need to be marked with the serializable attribute
- // Compares this object to another object, returning an integer that
- // indicates the relationship. An implementation of this method must return
- // a value less than zero if this is less than object, zero
- // if this is equal to object, or a value greater than zero
- // if this is greater than object.
- //
- int CompareTo([AllowNull] T other);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IConvertible.cs b/netcore/System.Private.CoreLib/shared/System/IConvertible.cs
deleted file mode 100644
index 745d979185d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IConvertible.cs
+++ /dev/null
@@ -1,62 +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.
-
-namespace System
-{
- // The IConvertible interface represents an object that contains a value. This
- // interface is implemented by the following types in the System namespace:
- // Boolean, Char, SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64,
- // Single, Double, Decimal, DateTime, and String. The interface may
- // be implemented by other types that are to be considered values. For example,
- // a library of nullable database types could implement IConvertible.
- //
- // Note: The interface was originally proposed as IValue.
- //
- // The implementations of IConvertible provided by the System.XXX value classes
- // simply forward to the appropriate Value.ToXXX(YYY) methods (a description of
- // the Value class follows below). In cases where a Value.ToXXX(YYY) method
- // does not exist (because the particular conversion is not supported), the
- // IConvertible implementation should simply throw an InvalidCastException.
-
- [CLSCompliant(false)]
- public interface IConvertible
- {
- // Returns the type code of this object. An implementation of this method
- // must not return TypeCode.Empty (which represents a null reference) or
- // TypeCode.Object (which represents an object that doesn't implement the
- // IConvertible interface). An implementation of this method should return
- // TypeCode.DBNull if the value of this object is a database null. For
- // example, a nullable integer type should return TypeCode.DBNull if the
- // value of the object is the database null. Otherwise, an implementation
- // of this method should return the TypeCode that best describes the
- // internal representation of the object.
-
- TypeCode GetTypeCode();
-
- // The ToXXX methods convert the value of the underlying object to the
- // given type. If a particular conversion is not supported, the
- // implementation must throw an InvalidCastException. If the value of the
- // underlying object is not within the range of the target type, the
- // implementation must throw an OverflowException. The
- // IFormatProvider? will be used to get a NumberFormatInfo or similar
- // appropriate service object, and may safely be null.
-
- bool ToBoolean(IFormatProvider? provider);
- char ToChar(IFormatProvider? provider);
- sbyte ToSByte(IFormatProvider? provider);
- byte ToByte(IFormatProvider? provider);
- short ToInt16(IFormatProvider? provider);
- ushort ToUInt16(IFormatProvider? provider);
- int ToInt32(IFormatProvider? provider);
- uint ToUInt32(IFormatProvider? provider);
- long ToInt64(IFormatProvider? provider);
- ulong ToUInt64(IFormatProvider? provider);
- float ToSingle(IFormatProvider? provider);
- double ToDouble(IFormatProvider? provider);
- decimal ToDecimal(IFormatProvider? provider);
- DateTime ToDateTime(IFormatProvider? provider);
- string ToString(IFormatProvider? provider);
- object ToType(Type conversionType, IFormatProvider? provider);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ICustomFormatter.cs b/netcore/System.Private.CoreLib/shared/System/ICustomFormatter.cs
deleted file mode 100644
index 6911e8c5608..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ICustomFormatter.cs
+++ /dev/null
@@ -1,21 +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.
-
-/*============================================================
-**
-** Interface: ICustomFormatter
-**
-**
-** Purpose: Marks a class as providing special formatting
-**
-**
-===========================================================*/
-
-namespace System
-{
- public interface ICustomFormatter
- {
- string Format(string? format, object? arg, IFormatProvider? formatProvider);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IDisposable.cs b/netcore/System.Private.CoreLib/shared/System/IDisposable.cs
deleted file mode 100644
index 4930b3c8ed6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IDisposable.cs
+++ /dev/null
@@ -1,60 +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.
-
-/*============================================================
-**
-** Interface: IDisposable
-**
-**
-** Purpose: Interface for assisting with deterministic finalization.
-**
-**
-===========================================================*/
-
-namespace System
-{
- // IDisposable is an attempt at helping to solve problems with deterministic
- // finalization. The GC of course doesn't leave any way to deterministically
- // know when a finalizer will run. This forces classes that hold onto OS
- // resources or some sort of important state (such as a FileStream or a
- // network connection) to provide a Close or Dispose method so users can
- // run clean up code deterministically. We have formalized this into an
- // interface with one method. Classes may privately implement IDisposable and
- // provide a Close method instead, if that name is by far the expected name
- // for objects in that domain (ie, you don't Dispose of a FileStream, you Close
- // it).
- //
- // This interface could be theoretically used as a marker by a compiler to
- // ensure a disposable object has been cleaned up along all code paths if it's
- // been allocated in that method, though in practice any compiler that
- // draconian may tick off any number of people. Perhaps an external tool (like
- // like Purify or BoundsChecker) could do this. Instead, C# has added a using
- // clause, which will generate a try/finally statement where the resource
- // passed into the using clause will always have it's Dispose method called.
- // Syntax is using(FileStream fs = ...) { .. };
- //
- // Dispose should meet the following conditions:
- // 1) Be safely callable multiple times
- // 2) Release any resources associated with the instance
- // 3) Call the base class's Dispose method, if necessary
- // 4) Suppress finalization of this class to help the GC by reducing the
- // number of objects on the finalization queue.
- // 5) Dispose shouldn't generally throw exceptions, except for very serious
- // errors that are particularly unexpected. (ie, OutOfMemoryException)
- // Ideally, nothing should go wrong with your object by calling Dispose.
- //
- // If possible, a class should define a finalizer that calls Dispose.
- // However, in many situations, this is impractical. For instance, take the
- // classic example of a Stream and a StreamWriter (which has an internal
- // buffer of data to write to the Stream). If both objects are collected
- // before Close or Dispose has been called on either, then the GC may run the
- // finalizer for the Stream first, before the StreamWriter. At that point, any
- // data buffered by the StreamWriter cannot be written to the Stream. In this
- // case, it doesn't make much sense to provide a finalizer on the StreamWriter
- // since you cannot solve this problem correctly.
- public interface IDisposable
- {
- void Dispose();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IEquatable.cs b/netcore/System.Private.CoreLib/shared/System/IEquatable.cs
deleted file mode 100644
index 4a64ea37ee1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IEquatable.cs
+++ /dev/null
@@ -1,13 +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 System.Diagnostics.CodeAnalysis;
-
-namespace System
-{
- public interface IEquatable<T> // invariant due to questionable semantics around equality and inheritance
- {
- bool Equals([AllowNull] T other);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IFormatProvider.cs b/netcore/System.Private.CoreLib/shared/System/IFormatProvider.cs
deleted file mode 100644
index f1e767f5437..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IFormatProvider.cs
+++ /dev/null
@@ -1,21 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Notes a class which knows how to return formatting information
-**
-**
-============================================================*/
-
-namespace System
-{
- public interface IFormatProvider
- {
- // Interface does not need to be marked with the serializable attribute
- object? GetFormat(Type? formatType);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IFormattable.cs b/netcore/System.Private.CoreLib/shared/System/IFormattable.cs
deleted file mode 100644
index bb5aeae97aa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IFormattable.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System
-{
- public interface IFormattable
- {
- string ToString(string? format, IFormatProvider? formatProvider);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/BinaryReader.cs b/netcore/System.Private.CoreLib/shared/System/IO/BinaryReader.cs
deleted file mode 100644
index cf8e4954593..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/BinaryReader.cs
+++ /dev/null
@@ -1,611 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: Wraps a stream and provides convenient read functionality
-** for strings and primitive types.
-**
-**
-============================================================*/
-
-using System.Buffers.Binary;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System.IO
-{
- public class BinaryReader : IDisposable
- {
- private const int MaxCharBytesSize = 128;
-
- private readonly Stream _stream;
- private readonly byte[] _buffer;
- private readonly Decoder _decoder;
- private byte[]? _charBytes;
- private char[]? _charBuffer;
- private readonly int _maxCharsSize; // From MaxCharBytesSize & Encoding
-
- // Performance optimization for Read() w/ Unicode. Speeds us up by ~40%
- private readonly bool _2BytesPerChar;
- private readonly bool _isMemoryStream; // "do we sit on MemoryStream?" for Read/ReadInt32 perf
- private readonly bool _leaveOpen;
- private bool _disposed;
-
- public BinaryReader(Stream input) : this(input, Encoding.UTF8, false)
- {
- }
-
- public BinaryReader(Stream input, Encoding encoding) : this(input, encoding, false)
- {
- }
-
- public BinaryReader(Stream input, Encoding encoding, bool leaveOpen)
- {
- if (input == null)
- {
- throw new ArgumentNullException(nameof(input));
- }
- if (encoding == null)
- {
- throw new ArgumentNullException(nameof(encoding));
- }
- if (!input.CanRead)
- {
- throw new ArgumentException(SR.Argument_StreamNotReadable);
- }
-
- _stream = input;
- _decoder = encoding.GetDecoder();
- _maxCharsSize = encoding.GetMaxCharCount(MaxCharBytesSize);
- int minBufferSize = encoding.GetMaxByteCount(1); // max bytes per one char
- if (minBufferSize < 16)
- {
- minBufferSize = 16;
- }
-
- _buffer = new byte[minBufferSize];
- // _charBuffer and _charBytes will be left null.
-
- // For Encodings that always use 2 bytes per char (or more),
- // special case them here to make Read() & Peek() faster.
- _2BytesPerChar = encoding is UnicodeEncoding;
- // check if BinaryReader is based on MemoryStream, and keep this for it's life
- // we cannot use "as" operator, since derived classes are not allowed
- _isMemoryStream = (_stream.GetType() == typeof(MemoryStream));
- _leaveOpen = leaveOpen;
-
- Debug.Assert(_decoder != null, "[BinaryReader.ctor]_decoder!=null");
- }
-
- public virtual Stream BaseStream => _stream;
-
- protected virtual void Dispose(bool disposing)
- {
- if (!_disposed)
- {
- if (disposing && !_leaveOpen)
- {
- _stream.Close();
- }
- _disposed = true;
- }
- }
-
- public void Dispose()
- {
- Dispose(true);
- }
-
- /// <remarks>
- /// Override Dispose(bool) instead of Close(). This API exists for compatibility purposes.
- /// </remarks>
- public virtual void Close()
- {
- Dispose(true);
- }
-
- private void ThrowIfDisposed()
- {
- if (_disposed)
- {
- throw Error.GetFileNotOpen();
- }
- }
-
- public virtual int PeekChar()
- {
- ThrowIfDisposed();
-
- if (!_stream.CanSeek)
- {
- return -1;
- }
-
- long origPos = _stream.Position;
- int ch = Read();
- _stream.Position = origPos;
- return ch;
- }
-
- public virtual int Read()
- {
- ThrowIfDisposed();
-
- int charsRead = 0;
- int numBytes;
- long posSav = 0;
-
- if (_stream.CanSeek)
- {
- posSav = _stream.Position;
- }
-
- _charBytes ??= new byte[MaxCharBytesSize];
-
- Span<char> singleChar = stackalloc char[1];
-
- while (charsRead == 0)
- {
- // We really want to know what the minimum number of bytes per char
- // is for our encoding. Otherwise for UnicodeEncoding we'd have to
- // do ~1+log(n) reads to read n characters.
- // Assume 1 byte can be 1 char unless _2BytesPerChar is true.
- numBytes = _2BytesPerChar ? 2 : 1;
-
- int r = _stream.ReadByte();
- _charBytes[0] = (byte)r;
- if (r == -1)
- {
- numBytes = 0;
- }
- if (numBytes == 2)
- {
- r = _stream.ReadByte();
- _charBytes[1] = (byte)r;
- if (r == -1)
- {
- numBytes = 1;
- }
- }
-
- if (numBytes == 0)
- {
- return -1;
- }
-
- Debug.Assert(numBytes == 1 || numBytes == 2, "BinaryReader::ReadOneChar assumes it's reading one or 2 bytes only.");
-
- try
- {
- charsRead = _decoder.GetChars(new ReadOnlySpan<byte>(_charBytes, 0, numBytes), singleChar, flush: false);
- }
- catch
- {
- // Handle surrogate char
-
- if (_stream.CanSeek)
- {
- _stream.Seek(posSav - _stream.Position, SeekOrigin.Current);
- }
- // else - we can't do much here
-
- throw;
- }
-
- Debug.Assert(charsRead < 2, "BinaryReader::ReadOneChar - assuming we only got 0 or 1 char, not 2!");
- }
- Debug.Assert(charsRead > 0);
- return singleChar[0];
- }
-
- public virtual byte ReadByte() => InternalReadByte();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // Inlined to avoid some method call overhead with InternalRead.
- private byte InternalReadByte()
- {
- ThrowIfDisposed();
-
- int b = _stream.ReadByte();
- if (b == -1)
- {
- throw Error.GetEndOfFile();
- }
-
- return (byte)b;
- }
-
- [CLSCompliant(false)]
- public virtual sbyte ReadSByte() => (sbyte)InternalReadByte();
- public virtual bool ReadBoolean() => InternalReadByte() != 0;
-
- public virtual char ReadChar()
- {
- int value = Read();
- if (value == -1)
- {
- throw Error.GetEndOfFile();
- }
- return (char)value;
- }
-
- public virtual short ReadInt16() => BinaryPrimitives.ReadInt16LittleEndian(InternalRead(2));
-
- [CLSCompliant(false)]
- public virtual ushort ReadUInt16() => BinaryPrimitives.ReadUInt16LittleEndian(InternalRead(2));
-
- public virtual int ReadInt32() => BinaryPrimitives.ReadInt32LittleEndian(InternalRead(4));
- [CLSCompliant(false)]
- public virtual uint ReadUInt32() => BinaryPrimitives.ReadUInt32LittleEndian(InternalRead(4));
- public virtual long ReadInt64() => BinaryPrimitives.ReadInt64LittleEndian(InternalRead(8));
- [CLSCompliant(false)]
- public virtual ulong ReadUInt64() => BinaryPrimitives.ReadUInt64LittleEndian(InternalRead(8));
- public virtual unsafe float ReadSingle() => BitConverter.Int32BitsToSingle(BinaryPrimitives.ReadInt32LittleEndian(InternalRead(4)));
- public virtual unsafe double ReadDouble() => BitConverter.Int64BitsToDouble(BinaryPrimitives.ReadInt64LittleEndian(InternalRead(8)));
-
- public virtual decimal ReadDecimal()
- {
- ReadOnlySpan<byte> span = InternalRead(16);
- try
- {
- return decimal.ToDecimal(span);
- }
- catch (ArgumentException e)
- {
- // ReadDecimal cannot leak out ArgumentException
- throw new IOException(SR.Arg_DecBitCtor, e);
- }
- }
-
- public virtual string ReadString()
- {
- ThrowIfDisposed();
-
- int currPos = 0;
- int n;
- int stringLength;
- int readLength;
- int charsRead;
-
- // Length of the string in bytes, not chars
- stringLength = Read7BitEncodedInt();
- if (stringLength < 0)
- {
- throw new IOException(SR.Format(SR.IO_InvalidStringLen_Len, stringLength));
- }
-
- if (stringLength == 0)
- {
- return string.Empty;
- }
-
- _charBytes ??= new byte[MaxCharBytesSize];
- _charBuffer ??= new char[_maxCharsSize];
-
- StringBuilder? sb = null;
- do
- {
- readLength = ((stringLength - currPos) > MaxCharBytesSize) ? MaxCharBytesSize : (stringLength - currPos);
-
- n = _stream.Read(_charBytes, 0, readLength);
- if (n == 0)
- {
- throw Error.GetEndOfFile();
- }
-
- charsRead = _decoder.GetChars(_charBytes, 0, n, _charBuffer, 0);
-
- if (currPos == 0 && n == stringLength)
- {
- return new string(_charBuffer, 0, charsRead);
- }
-
- sb ??= StringBuilderCache.Acquire(stringLength); // Actual string length in chars may be smaller.
- sb.Append(_charBuffer, 0, charsRead);
- currPos += n;
- } while (currPos < stringLength);
-
- return StringBuilderCache.GetStringAndRelease(sb);
- }
-
- public virtual int Read(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
- ThrowIfDisposed();
-
- return InternalReadChars(new Span<char>(buffer, index, count));
- }
-
- public virtual int Read(Span<char> buffer)
- {
- ThrowIfDisposed();
- return InternalReadChars(buffer);
- }
-
- private int InternalReadChars(Span<char> buffer)
- {
- Debug.Assert(!_disposed);
-
- int totalCharsRead = 0;
-
- while (!buffer.IsEmpty)
- {
- int numBytes = buffer.Length;
-
- // We really want to know what the minimum number of bytes per char
- // is for our encoding. Otherwise for UnicodeEncoding we'd have to
- // do ~1+log(n) reads to read n characters.
- if (_2BytesPerChar)
- {
- numBytes <<= 1;
- }
-
- // We do not want to read even a single byte more than necessary.
- //
- // Subtract pending bytes that the decoder may be holding onto. This assumes that each
- // decoded char corresponds to one or more bytes. Note that custom encodings or encodings with
- // a custom replacement sequence may violate this assumption.
- if (numBytes > 1)
- {
- DecoderNLS? decoder = _decoder as DecoderNLS;
- // For internal decoders, we can check whether the decoder has any pending state.
- // For custom decoders, assume that the decoder has pending state.
- if (decoder == null || decoder.HasState)
- {
- numBytes--;
-
- // The worst case is charsRemaining = 2 and UTF32Decoder holding onto 3 pending bytes. We need to read just
- // one byte in this case.
- if (_2BytesPerChar && numBytes > 2)
- numBytes -= 2;
- }
- }
-
- ReadOnlySpan<byte> byteBuffer;
- if (_isMemoryStream)
- {
- Debug.Assert(_stream is MemoryStream);
- MemoryStream mStream = (MemoryStream)_stream;
-
- int position = mStream.InternalGetPosition();
- numBytes = mStream.InternalEmulateRead(numBytes);
- byteBuffer = new ReadOnlySpan<byte>(mStream.InternalGetBuffer(), position, numBytes);
- }
- else
- {
- _charBytes ??= new byte[MaxCharBytesSize];
-
- if (numBytes > MaxCharBytesSize)
- {
- numBytes = MaxCharBytesSize;
- }
-
- numBytes = _stream.Read(_charBytes, 0, numBytes);
- byteBuffer = new ReadOnlySpan<byte>(_charBytes, 0, numBytes);
- }
-
- if (byteBuffer.IsEmpty)
- {
- break;
- }
-
- int charsRead = _decoder.GetChars(byteBuffer, buffer, flush: false);
- buffer = buffer.Slice(charsRead);
-
- totalCharsRead += charsRead;
- }
-
- // we may have read fewer than the number of characters requested if end of stream reached
- // or if the encoding makes the char count too big for the buffer (e.g. fallback sequence)
- return totalCharsRead;
- }
-
- public virtual char[] ReadChars(int count)
- {
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- ThrowIfDisposed();
-
- if (count == 0)
- {
- return Array.Empty<char>();
- }
-
- char[] chars = new char[count];
- int n = InternalReadChars(new Span<char>(chars));
- if (n != count)
- {
- char[] copy = new char[n];
- Buffer.BlockCopy(chars, 0, copy, 0, 2 * n); // sizeof(char)
- chars = copy;
- }
-
- return chars;
- }
-
- public virtual int Read(byte[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
- ThrowIfDisposed();
-
- return _stream.Read(buffer, index, count);
- }
-
- public virtual int Read(Span<byte> buffer)
- {
- ThrowIfDisposed();
- return _stream.Read(buffer);
- }
-
- public virtual byte[] ReadBytes(int count)
- {
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- ThrowIfDisposed();
-
- if (count == 0)
- {
- return Array.Empty<byte>();
- }
-
- byte[] result = new byte[count];
- int numRead = 0;
- do
- {
- int n = _stream.Read(result, numRead, count);
- if (n == 0)
- {
- break;
- }
-
- numRead += n;
- count -= n;
- } while (count > 0);
-
- if (numRead != result.Length)
- {
- // Trim array. This should happen on EOF & possibly net streams.
- byte[] copy = new byte[numRead];
- Buffer.BlockCopy(result, 0, copy, 0, numRead);
- result = copy;
- }
-
- return result;
- }
-
- private ReadOnlySpan<byte> InternalRead(int numBytes)
- {
- Debug.Assert(numBytes >= 2 && numBytes <= 16, "value of 1 should use ReadByte. value > 16 requires to change the minimal _buffer size");
-
- if (_isMemoryStream)
- {
- // read directly from MemoryStream buffer
- Debug.Assert(_stream is MemoryStream);
- return ((MemoryStream)_stream).InternalReadSpan(numBytes);
- }
- else
- {
- ThrowIfDisposed();
-
- int bytesRead = 0;
- do
- {
- int n = _stream.Read(_buffer, bytesRead, numBytes - bytesRead);
- if (n == 0)
- {
- throw Error.GetEndOfFile();
- }
- bytesRead += n;
- } while (bytesRead < numBytes);
-
- return _buffer;
- }
- }
-
- // FillBuffer is not performing well when reading from MemoryStreams as it is using the public Stream interface.
- // We introduced new function InternalRead which can work directly on the MemoryStream internal buffer or using the public Stream
- // interface when working with all other streams. This function is not needed anymore but we decided not to delete it for compatibility
- // reasons. More about the subject in: https://github.com/dotnet/coreclr/pull/22102
- protected virtual void FillBuffer(int numBytes)
- {
- if (numBytes < 0 || numBytes > _buffer.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(numBytes), SR.ArgumentOutOfRange_BinaryReaderFillBuffer);
- }
-
- int bytesRead = 0;
- int n = 0;
-
- ThrowIfDisposed();
-
- // Need to find a good threshold for calling ReadByte() repeatedly
- // vs. calling Read(byte[], int, int) for both buffered & unbuffered
- // streams.
- if (numBytes == 1)
- {
- n = _stream.ReadByte();
- if (n == -1)
- {
- throw Error.GetEndOfFile();
- }
-
- _buffer[0] = (byte)n;
- return;
- }
-
- do
- {
- n = _stream.Read(_buffer, bytesRead, numBytes - bytesRead);
- if (n == 0)
- {
- throw Error.GetEndOfFile();
- }
- bytesRead += n;
- } while (bytesRead < numBytes);
- }
-
- protected internal int Read7BitEncodedInt()
- {
- // Read out an Int32 7 bits at a time. The high bit
- // of the byte when on means to continue reading more bytes.
- int count = 0;
- int shift = 0;
- byte b;
- do
- {
- // Check for a corrupted stream. Read a max of 5 bytes.
- // In a future version, add a DataFormatException.
- if (shift == 5 * 7) // 5 bytes max per Int32, shift += 7
- {
- throw new FormatException(SR.Format_Bad7BitInt32);
- }
-
- // ReadByte handles end of stream cases for us.
- b = ReadByte();
- count |= (b & 0x7F) << shift;
- shift += 7;
- } while ((b & 0x80) != 0);
- return count;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/BinaryWriter.cs b/netcore/System.Private.CoreLib/shared/System/IO/BinaryWriter.cs
deleted file mode 100644
index fde451656a5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/BinaryWriter.cs
+++ /dev/null
@@ -1,469 +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 System.Text;
-using System.Diagnostics;
-using System.Buffers;
-using System.Threading.Tasks;
-
-namespace System.IO
-{
- // This abstract base class represents a writer that can write
- // primitives to an arbitrary stream. A subclass can override methods to
- // give unique encodings.
- //
- public class BinaryWriter : IDisposable, IAsyncDisposable
- {
- public static readonly BinaryWriter Null = new BinaryWriter();
-
- protected Stream OutStream;
- private readonly byte[] _buffer; // temp space for writing primitives to.
- private readonly Encoding _encoding;
- private readonly Encoder _encoder;
-
- private readonly bool _leaveOpen;
-
- // Perf optimization stuff
- private byte[]? _largeByteBuffer; // temp space for writing chars.
- private int _maxChars; // max # of chars we can put in _largeByteBuffer
- // Size should be around the max number of chars/string * Encoding's max bytes/char
- private const int LargeByteBufferSize = 256;
-
- // Protected default constructor that sets the output stream
- // to a null stream (a bit bucket).
- protected BinaryWriter()
- {
- OutStream = Stream.Null;
- _buffer = new byte[16];
- _encoding = EncodingCache.UTF8NoBOM;
- _encoder = _encoding.GetEncoder();
- }
-
- public BinaryWriter(Stream output) : this(output, EncodingCache.UTF8NoBOM, false)
- {
- }
-
- public BinaryWriter(Stream output, Encoding encoding) : this(output, encoding, false)
- {
- }
-
- public BinaryWriter(Stream output, Encoding encoding, bool leaveOpen)
- {
- if (output == null)
- throw new ArgumentNullException(nameof(output));
- if (encoding == null)
- throw new ArgumentNullException(nameof(encoding));
- if (!output.CanWrite)
- throw new ArgumentException(SR.Argument_StreamNotWritable);
-
- OutStream = output;
- _buffer = new byte[16];
- _encoding = encoding;
- _encoder = _encoding.GetEncoder();
- _leaveOpen = leaveOpen;
- }
-
- // Closes this writer and releases any system resources associated with the
- // writer. Following a call to Close, any operations on the writer
- // may raise exceptions.
- public virtual void Close()
- {
- Dispose(true);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (_leaveOpen)
- OutStream.Flush();
- else
- OutStream.Close();
- }
- }
-
- public void Dispose()
- {
- Dispose(true);
- }
-
- public virtual ValueTask DisposeAsync()
- {
- try
- {
- if (GetType() == typeof(BinaryWriter))
- {
- if (_leaveOpen)
- {
- return new ValueTask(OutStream.FlushAsync());
- }
-
- OutStream.Close();
- }
- else
- {
- // Since this is a derived BinaryWriter, delegate to whatever logic
- // the derived implementation already has in Dispose.
- Dispose();
- }
-
- return default;
- }
- catch (Exception exc)
- {
- return new ValueTask(Task.FromException(exc));
- }
- }
-
- // Returns the stream associated with the writer. It flushes all pending
- // writes before returning. All subclasses should override Flush to
- // ensure that all buffered data is sent to the stream.
- public virtual Stream BaseStream
- {
- get
- {
- Flush();
- return OutStream;
- }
- }
-
- // Clears all buffers for this writer and causes any buffered data to be
- // written to the underlying device.
- public virtual void Flush()
- {
- OutStream.Flush();
- }
-
- public virtual long Seek(int offset, SeekOrigin origin)
- {
- return OutStream.Seek(offset, origin);
- }
-
- // Writes a boolean to this stream. A single byte is written to the stream
- // with the value 0 representing false or the value 1 representing true.
- //
- public virtual void Write(bool value)
- {
- _buffer[0] = (byte)(value ? 1 : 0);
- OutStream.Write(_buffer, 0, 1);
- }
-
- // Writes a byte to this stream. The current position of the stream is
- // advanced by one.
- //
- public virtual void Write(byte value)
- {
- OutStream.WriteByte(value);
- }
-
- // Writes a signed byte to this stream. The current position of the stream
- // is advanced by one.
- //
- [CLSCompliant(false)]
- public virtual void Write(sbyte value)
- {
- OutStream.WriteByte((byte)value);
- }
-
- // Writes a byte array to this stream.
- //
- // This default implementation calls the Write(Object, int, int)
- // method to write the byte array.
- //
- public virtual void Write(byte[] buffer)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer));
- OutStream.Write(buffer, 0, buffer.Length);
- }
-
- // Writes a section of a byte array to this stream.
- //
- // This default implementation calls the Write(Object, int, int)
- // method to write the byte array.
- //
- public virtual void Write(byte[] buffer, int index, int count)
- {
- OutStream.Write(buffer, index, count);
- }
-
-
- // Writes a character to this stream. The current position of the stream is
- // advanced by two.
- // Note this method cannot handle surrogates properly in UTF-8.
- //
- public virtual unsafe void Write(char ch)
- {
- if (char.IsSurrogate(ch))
- throw new ArgumentException(SR.Arg_SurrogatesNotAllowedAsSingleChar);
-
- Debug.Assert(_encoding.GetMaxByteCount(1) <= 16, "_encoding.GetMaxByteCount(1) <= 16)");
- int numBytes = 0;
- fixed (byte* pBytes = &_buffer[0])
- {
- numBytes = _encoder.GetBytes(&ch, 1, pBytes, _buffer.Length, flush: true);
- }
- OutStream.Write(_buffer, 0, numBytes);
- }
-
- // Writes a character array to this stream.
- //
- // This default implementation calls the Write(Object, int, int)
- // method to write the character array.
- //
- public virtual void Write(char[] chars)
- {
- if (chars == null)
- throw new ArgumentNullException(nameof(chars));
-
- byte[] bytes = _encoding.GetBytes(chars, 0, chars.Length);
- OutStream.Write(bytes, 0, bytes.Length);
- }
-
- // Writes a section of a character array to this stream.
- //
- // This default implementation calls the Write(Object, int, int)
- // method to write the character array.
- //
- public virtual void Write(char[] chars, int index, int count)
- {
- byte[] bytes = _encoding.GetBytes(chars, index, count);
- OutStream.Write(bytes, 0, bytes.Length);
- }
-
-
- // Writes a double to this stream. The current position of the stream is
- // advanced by eight.
- //
- public virtual unsafe void Write(double value)
- {
- ulong TmpValue = *(ulong*)&value;
- _buffer[0] = (byte)TmpValue;
- _buffer[1] = (byte)(TmpValue >> 8);
- _buffer[2] = (byte)(TmpValue >> 16);
- _buffer[3] = (byte)(TmpValue >> 24);
- _buffer[4] = (byte)(TmpValue >> 32);
- _buffer[5] = (byte)(TmpValue >> 40);
- _buffer[6] = (byte)(TmpValue >> 48);
- _buffer[7] = (byte)(TmpValue >> 56);
- OutStream.Write(_buffer, 0, 8);
- }
-
- public virtual void Write(decimal value)
- {
- decimal.GetBytes(value, _buffer);
- OutStream.Write(_buffer, 0, 16);
- }
-
- // Writes a two-byte signed integer to this stream. The current position of
- // the stream is advanced by two.
- //
- public virtual void Write(short value)
- {
- _buffer[0] = (byte)value;
- _buffer[1] = (byte)(value >> 8);
- OutStream.Write(_buffer, 0, 2);
- }
-
- // Writes a two-byte unsigned integer to this stream. The current position
- // of the stream is advanced by two.
- //
- [CLSCompliant(false)]
- public virtual void Write(ushort value)
- {
- _buffer[0] = (byte)value;
- _buffer[1] = (byte)(value >> 8);
- OutStream.Write(_buffer, 0, 2);
- }
-
- // Writes a four-byte signed integer to this stream. The current position
- // of the stream is advanced by four.
- //
- public virtual void Write(int value)
- {
- _buffer[0] = (byte)value;
- _buffer[1] = (byte)(value >> 8);
- _buffer[2] = (byte)(value >> 16);
- _buffer[3] = (byte)(value >> 24);
- OutStream.Write(_buffer, 0, 4);
- }
-
- // Writes a four-byte unsigned integer to this stream. The current position
- // of the stream is advanced by four.
- //
- [CLSCompliant(false)]
- public virtual void Write(uint value)
- {
- _buffer[0] = (byte)value;
- _buffer[1] = (byte)(value >> 8);
- _buffer[2] = (byte)(value >> 16);
- _buffer[3] = (byte)(value >> 24);
- OutStream.Write(_buffer, 0, 4);
- }
-
- // Writes an eight-byte signed integer to this stream. The current position
- // of the stream is advanced by eight.
- //
- public virtual void Write(long value)
- {
- _buffer[0] = (byte)value;
- _buffer[1] = (byte)(value >> 8);
- _buffer[2] = (byte)(value >> 16);
- _buffer[3] = (byte)(value >> 24);
- _buffer[4] = (byte)(value >> 32);
- _buffer[5] = (byte)(value >> 40);
- _buffer[6] = (byte)(value >> 48);
- _buffer[7] = (byte)(value >> 56);
- OutStream.Write(_buffer, 0, 8);
- }
-
- // Writes an eight-byte unsigned integer to this stream. The current
- // position of the stream is advanced by eight.
- //
- [CLSCompliant(false)]
- public virtual void Write(ulong value)
- {
- _buffer[0] = (byte)value;
- _buffer[1] = (byte)(value >> 8);
- _buffer[2] = (byte)(value >> 16);
- _buffer[3] = (byte)(value >> 24);
- _buffer[4] = (byte)(value >> 32);
- _buffer[5] = (byte)(value >> 40);
- _buffer[6] = (byte)(value >> 48);
- _buffer[7] = (byte)(value >> 56);
- OutStream.Write(_buffer, 0, 8);
- }
-
- // Writes a float to this stream. The current position of the stream is
- // advanced by four.
- //
- public virtual unsafe void Write(float value)
- {
- uint TmpValue = *(uint*)&value;
- _buffer[0] = (byte)TmpValue;
- _buffer[1] = (byte)(TmpValue >> 8);
- _buffer[2] = (byte)(TmpValue >> 16);
- _buffer[3] = (byte)(TmpValue >> 24);
- OutStream.Write(_buffer, 0, 4);
- }
-
-
- // Writes a length-prefixed string to this stream in the BinaryWriter's
- // current Encoding. This method first writes the length of the string as
- // a four-byte unsigned integer, and then writes that many characters
- // to the stream.
- //
- public virtual unsafe void Write(string value)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- int len = _encoding.GetByteCount(value);
- Write7BitEncodedInt(len);
-
- if (_largeByteBuffer == null)
- {
- _largeByteBuffer = new byte[LargeByteBufferSize];
- _maxChars = _largeByteBuffer.Length / _encoding.GetMaxByteCount(1);
- }
-
- if (len <= _largeByteBuffer.Length)
- {
- _encoding.GetBytes(value, 0, value.Length, _largeByteBuffer, 0);
- OutStream.Write(_largeByteBuffer, 0, len);
- }
- else
- {
- // Aggressively try to not allocate memory in this loop for
- // runtime performance reasons. Use an Encoder to write out
- // the string correctly (handling surrogates crossing buffer
- // boundaries properly).
- int charStart = 0;
- int numLeft = value.Length;
-#if DEBUG
- int totalBytes = 0;
-#endif
- while (numLeft > 0)
- {
- // Figure out how many chars to process this round.
- int charCount = (numLeft > _maxChars) ? _maxChars : numLeft;
- int byteLen;
-
- checked
- {
- if (charStart < 0 || charCount < 0 || charStart > value.Length - charCount)
- {
- throw new ArgumentOutOfRangeException(nameof(charCount));
- }
- fixed (char* pChars = value)
- {
- fixed (byte* pBytes = &_largeByteBuffer[0])
- {
- byteLen = _encoder.GetBytes(pChars + charStart, charCount, pBytes, _largeByteBuffer.Length, charCount == numLeft);
- }
- }
- }
-#if DEBUG
- totalBytes += byteLen;
- Debug.Assert(totalBytes <= len && byteLen <= _largeByteBuffer.Length, "BinaryWriter::Write(String) - More bytes encoded than expected!");
-#endif
- OutStream.Write(_largeByteBuffer, 0, byteLen);
- charStart += charCount;
- numLeft -= charCount;
- }
-#if DEBUG
- Debug.Assert(totalBytes == len, "BinaryWriter::Write(String) - Didn't write out all the bytes!");
-#endif
- }
- }
-
- public virtual void Write(ReadOnlySpan<byte> buffer)
- {
- if (GetType() == typeof(BinaryWriter))
- {
- OutStream.Write(buffer);
- }
- else
- {
- byte[] array = ArrayPool<byte>.Shared.Rent(buffer.Length);
- try
- {
- buffer.CopyTo(array);
- Write(array, 0, buffer.Length);
- }
- finally
- {
- ArrayPool<byte>.Shared.Return(array);
- }
- }
- }
-
- public virtual void Write(ReadOnlySpan<char> chars)
- {
- byte[] bytes = ArrayPool<byte>.Shared.Rent(_encoding.GetMaxByteCount(chars.Length));
- try
- {
- int bytesWritten = _encoding.GetBytes(chars, bytes);
- Write(bytes, 0, bytesWritten);
- }
- finally
- {
- ArrayPool<byte>.Shared.Return(bytes);
- }
- }
-
- protected void Write7BitEncodedInt(int value)
- {
- // Write out an int 7 bits at a time. The high bit of the byte,
- // when on, tells reader to continue reading more bytes.
- uint v = (uint)value; // support negative numbers
- while (v >= 0x80)
- {
- Write((byte)(v | 0x80));
- v >>= 7;
- }
- Write((byte)v);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/DirectoryNotFoundException.cs b/netcore/System.Private.CoreLib/shared/System/IO/DirectoryNotFoundException.cs
deleted file mode 100644
index 2b0f5026919..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/DirectoryNotFoundException.cs
+++ /dev/null
@@ -1,42 +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 System.Runtime.Serialization;
-
-namespace System.IO
-{
- /*
- * Thrown when trying to access a directory that doesn't exist on disk.
- * From COM Interop, this exception is thrown for 2 HRESULTS:
- * the Win32 errorcode-as-HRESULT ERROR_PATH_NOT_FOUND (0x80070003)
- * and STG_E_PATHNOTFOUND (0x80030003).
- */
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class DirectoryNotFoundException : IOException
- {
- public DirectoryNotFoundException()
- : base(SR.Arg_DirectoryNotFoundException)
- {
- HResult = HResults.COR_E_DIRECTORYNOTFOUND;
- }
-
- public DirectoryNotFoundException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_DIRECTORYNOTFOUND;
- }
-
- public DirectoryNotFoundException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_DIRECTORYNOTFOUND;
- }
-
- protected DirectoryNotFoundException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/DisableMediaInsertionPrompt.cs b/netcore/System.Private.CoreLib/shared/System/IO/DisableMediaInsertionPrompt.cs
deleted file mode 100644
index d14043c8304..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/DisableMediaInsertionPrompt.cs
+++ /dev/null
@@ -1,41 +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.
-
-#if MS_IO_REDIST
-using System;
-
-namespace Microsoft.IO
-#else
-namespace System.IO
-#endif
-{
- /// <summary>
- /// Simple wrapper to safely disable the normal media insertion prompt for
- /// removable media (floppies, cds, memory cards, etc.)
- /// </summary>
- /// <remarks>
- /// Note that removable media file systems lazily load. After starting the OS
- /// they won't be loaded until you have media in the drive- and as such the
- /// prompt won't happen. You have to have had media in at least once to get
- /// the file system to load and then have removed it.
- /// </remarks>
- internal struct DisableMediaInsertionPrompt : IDisposable
- {
- private bool _disableSuccess;
- private uint _oldMode;
-
- public static DisableMediaInsertionPrompt Create()
- {
- DisableMediaInsertionPrompt prompt = default;
- prompt._disableSuccess = Interop.Kernel32.SetThreadErrorMode(Interop.Kernel32.SEM_FAILCRITICALERRORS, out prompt._oldMode);
- return prompt;
- }
-
- public void Dispose()
- {
- if (_disableSuccess)
- Interop.Kernel32.SetThreadErrorMode(_oldMode, out _);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/DriveInfoInternal.Unix.cs b/netcore/System.Private.CoreLib/shared/System/IO/DriveInfoInternal.Unix.cs
deleted file mode 100644
index 78ef95704fe..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/DriveInfoInternal.Unix.cs
+++ /dev/null
@@ -1,15 +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 System.Diagnostics;
-using System.Text;
-
-namespace System.IO
-{
- /// <summary>Contains internal volume helpers that are shared between many projects.</summary>
- internal static partial class DriveInfoInternal
- {
- internal static string[] GetLogicalDrives() => Interop.Sys.GetAllMountPoints();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/DriveInfoInternal.Windows.cs b/netcore/System.Private.CoreLib/shared/System/IO/DriveInfoInternal.Windows.cs
deleted file mode 100644
index c811a876920..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/DriveInfoInternal.Windows.cs
+++ /dev/null
@@ -1,87 +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.
-
-#nullable enable
-using System.Diagnostics;
-
-namespace System.IO
-{
- /// <summary>Contains internal volume helpers that are shared between many projects.</summary>
- internal static partial class DriveInfoInternal
- {
- public static string[] GetLogicalDrives()
- {
- int drives = Interop.Kernel32.GetLogicalDrives();
- if (drives == 0)
- {
- throw Win32Marshal.GetExceptionForLastWin32Error();
- }
-
- // GetLogicalDrives returns a bitmask starting from
- // position 0 "A" indicating whether a drive is present.
- // Loop over each bit, creating a string for each one
- // that is set.
-
- uint d = (uint)drives;
- int count = 0;
- while (d != 0)
- {
- if (((int)d & 1) != 0) count++;
- d >>= 1;
- }
-
- string[] result = new string[count];
- Span<char> root = stackalloc char[] { 'A', ':', '\\' };
- d = (uint)drives;
- count = 0;
- while (d != 0)
- {
- if (((int)d & 1) != 0)
- {
- result[count++] = root.ToString();
- }
- d >>= 1;
- root[0]++;
- }
- return result;
- }
-
- public static string NormalizeDriveName(string driveName)
- {
- Debug.Assert(driveName != null);
-
- string? name;
-
- if (driveName.Length == 1)
- {
- name = driveName + ":\\";
- }
- else
- {
- name = Path.GetPathRoot(driveName);
- // Disallow null or empty drive letters and UNC paths
- if (string.IsNullOrEmpty(name) || name.StartsWith("\\\\", StringComparison.Ordinal))
- {
- throw new ArgumentException(SR.Arg_MustBeDriveLetterOrRootDir, nameof(driveName));
- }
- }
- // We want to normalize to have a trailing backslash so we don't have two equivalent forms and
- // because some Win32 API don't work without it.
- if (name.Length == 2 && name[1] == ':')
- {
- name += "\\";
- }
-
- // Now verify that the drive letter could be a real drive name.
- // On Windows this means it's between A and Z, ignoring case.
- char letter = driveName[0];
- if (!((letter >= 'A' && letter <= 'Z') || (letter >= 'a' && letter <= 'z')))
- {
- throw new ArgumentException(SR.Arg_MustBeDriveLetterOrRootDir, nameof(driveName));
- }
-
- return name;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/EncodingCache.cs b/netcore/System.Private.CoreLib/shared/System/IO/EncodingCache.cs
deleted file mode 100644
index 53379bc77f3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/EncodingCache.cs
+++ /dev/null
@@ -1,13 +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 System.Text;
-
-namespace System.IO
-{
- internal static class EncodingCache
- {
- internal static readonly Encoding UTF8NoBOM = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/EndOfStreamException.cs b/netcore/System.Private.CoreLib/shared/System/IO/EndOfStreamException.cs
deleted file mode 100644
index c965b6a1c20..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/EndOfStreamException.cs
+++ /dev/null
@@ -1,36 +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 System.Runtime.Serialization;
-
-namespace System.IO
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class EndOfStreamException : IOException
- {
- public EndOfStreamException()
- : base(SR.Arg_EndOfStreamException)
- {
- HResult = HResults.COR_E_ENDOFSTREAM;
- }
-
- public EndOfStreamException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_ENDOFSTREAM;
- }
-
- public EndOfStreamException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_ENDOFSTREAM;
- }
-
- protected EndOfStreamException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/Error.cs b/netcore/System.Private.CoreLib/shared/System/IO/Error.cs
deleted file mode 100644
index fd39f166cf9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/Error.cs
+++ /dev/null
@@ -1,42 +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.
-
-namespace System.IO
-{
- /// <summary>
- /// Provides centralized methods for creating exceptions for System.IO.FileSystem.
- /// </summary>
- internal static class Error
- {
- internal static Exception GetStreamIsClosed()
- {
- return new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
- }
-
- internal static Exception GetEndOfFile()
- {
- return new EndOfStreamException(SR.IO_EOF_ReadBeyondEOF);
- }
-
- internal static Exception GetFileNotOpen()
- {
- return new ObjectDisposedException(null, SR.ObjectDisposed_FileClosed);
- }
-
- internal static Exception GetReadNotSupported()
- {
- return new NotSupportedException(SR.NotSupported_UnreadableStream);
- }
-
- internal static Exception GetSeekNotSupported()
- {
- return new NotSupportedException(SR.NotSupported_UnseekableStream);
- }
-
- internal static Exception GetWriteNotSupported()
- {
- return new NotSupportedException(SR.NotSupported_UnwritableStream);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileAccess.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileAccess.cs
deleted file mode 100644
index c0b75374522..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileAccess.cs
+++ /dev/null
@@ -1,26 +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.
-
-namespace System.IO
-{
- // Contains constants for specifying the access you want for a file.
- // You can have Read, Write or ReadWrite access.
- //
- [Flags]
- public enum FileAccess
- {
- // Specifies read access to the file. Data can be read from the file and
- // the file pointer can be moved. Combine with WRITE for read-write access.
- Read = 1,
-
- // Specifies write access to the file. Data can be written to the file and
- // the file pointer can be moved. Combine with READ for read-write access.
- Write = 2,
-
- // Specifies read and write access to the file. Data can be written to the
- // file and the file pointer can be moved. Data can also be read from the
- // file.
- ReadWrite = 3,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileLoadException.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileLoadException.cs
deleted file mode 100644
index f7ef7c4c050..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileLoadException.cs
+++ /dev/null
@@ -1,85 +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 System.Runtime.Serialization;
-
-namespace System.IO
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public partial class FileLoadException : IOException
- {
- public FileLoadException()
- : base(SR.IO_FileLoad)
- {
- HResult = HResults.COR_E_FILELOAD;
- }
-
- public FileLoadException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_FILELOAD;
- }
-
- public FileLoadException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_FILELOAD;
- }
-
- public FileLoadException(string? message, string? fileName) : base(message)
- {
- HResult = HResults.COR_E_FILELOAD;
- FileName = fileName;
- }
-
- public FileLoadException(string? message, string? fileName, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_FILELOAD;
- FileName = fileName;
- }
-
- public override string Message => _message ??= FormatFileLoadExceptionMessage(FileName, HResult);
-
- public string? FileName { get; }
- public string? FusionLog { get; }
-
- public override string ToString()
- {
- string s = GetType().ToString() + ": " + Message;
-
- if (!string.IsNullOrEmpty(FileName))
- s += Environment.NewLineConst + SR.Format(SR.IO_FileName_Name, FileName);
-
- if (InnerException != null)
- s += Environment.NewLineConst + InnerExceptionPrefix + InnerException.ToString();
-
- if (StackTrace != null)
- s += Environment.NewLineConst + StackTrace;
-
- if (FusionLog != null)
- {
- s ??= " ";
- s += Environment.NewLineConst + Environment.NewLineConst + FusionLog;
- }
-
- return s;
- }
-
- protected FileLoadException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- FileName = info.GetString("FileLoad_FileName");
- FusionLog = info.GetString("FileLoad_FusionLog");
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("FileLoad_FileName", FileName, typeof(string));
- info.AddValue("FileLoad_FusionLog", FusionLog, typeof(string));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileMode.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileMode.cs
deleted file mode 100644
index 83f48229958..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileMode.cs
+++ /dev/null
@@ -1,38 +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.
-
-namespace System.IO
-{
- // Contains constants for specifying how the OS should open a file.
- // These will control whether you overwrite a file, open an existing
- // file, or some combination thereof.
- //
- // To append to a file, use Append (which maps to OpenOrCreate then we seek
- // to the end of the file). To truncate a file or create it if it doesn't
- // exist, use Create.
- //
- public enum FileMode
- {
- // Creates a new file. An exception is raised if the file already exists.
- CreateNew = 1,
-
- // Creates a new file. If the file already exists, it is overwritten.
- Create = 2,
-
- // Opens an existing file. An exception is raised if the file does not exist.
- Open = 3,
-
- // Opens the file if it exists. Otherwise, creates a new file.
- OpenOrCreate = 4,
-
- // Opens an existing file. Once opened, the file is truncated so that its
- // size is zero bytes. The calling process must open the file with at least
- // WRITE access. An exception is raised if the file does not exist.
- Truncate = 5,
-
- // Opens the file if it exists and seeks to the end. Otherwise,
- // creates a new file.
- Append = 6,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs
deleted file mode 100644
index 48c513b7f37..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileNotFoundException.cs
+++ /dev/null
@@ -1,107 +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 System.Diagnostics;
-using System.Runtime.Serialization;
-
-namespace System.IO
-{
- // Thrown when trying to access a file that doesn't exist on disk.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public partial class FileNotFoundException : IOException
- {
- public FileNotFoundException()
- : base(SR.IO_FileNotFound)
- {
- HResult = HResults.COR_E_FILENOTFOUND;
- }
-
- public FileNotFoundException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_FILENOTFOUND;
- }
-
- public FileNotFoundException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_FILENOTFOUND;
- }
-
- public FileNotFoundException(string? message, string? fileName)
- : base(message)
- {
- HResult = HResults.COR_E_FILENOTFOUND;
- FileName = fileName;
- }
-
- public FileNotFoundException(string? message, string? fileName, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_FILENOTFOUND;
- FileName = fileName;
- }
-
- public override string Message
- {
- get
- {
- SetMessageField();
- Debug.Assert(_message != null, "_message was null after calling SetMessageField");
- return _message;
- }
- }
-
- private void SetMessageField()
- {
- if (_message == null)
- {
- if ((FileName == null) &&
- (HResult == System.HResults.COR_E_EXCEPTION))
- _message = SR.IO_FileNotFound;
- else if (FileName != null)
- _message = FileLoadException.FormatFileLoadExceptionMessage(FileName, HResult);
- }
- }
-
- public string? FileName { get; }
- public string? FusionLog { get; }
-
- public override string ToString()
- {
- string s = GetType().ToString() + ": " + Message;
-
- if (!string.IsNullOrEmpty(FileName))
- s += Environment.NewLineConst + SR.Format(SR.IO_FileName_Name, FileName);
-
- if (InnerException != null)
- s += Environment.NewLineConst + InnerExceptionPrefix + InnerException.ToString();
-
- if (StackTrace != null)
- s += Environment.NewLineConst + StackTrace;
-
- if (FusionLog != null)
- {
- s ??= " ";
- s += Environment.NewLineConst + Environment.NewLineConst + FusionLog;
- }
- return s;
- }
-
- protected FileNotFoundException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- FileName = info.GetString("FileNotFound_FileName");
- FusionLog = info.GetString("FileNotFound_FusionLog");
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("FileNotFound_FileName", FileName, typeof(string));
- info.AddValue("FileNotFound_FusionLog", FusionLog, typeof(string));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileOptions.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileOptions.cs
deleted file mode 100644
index eed14c86b05..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileOptions.cs
+++ /dev/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.
-
-namespace System.IO
-{
- // Maps to FILE_FLAG_DELETE_ON_CLOSE and similar values from winbase.h.
- // We didn't expose a number of these values because we didn't believe
- // a number of them made sense in managed code, at least not yet.
- [Flags]
- public enum FileOptions
- {
- // NOTE: any change to FileOptions enum needs to be
- // matched in the FileStream ctor for error validation
- None = 0,
- WriteThrough = unchecked((int)0x80000000),
- Asynchronous = unchecked((int)0x40000000), // FILE_FLAG_OVERLAPPED
- // NoBuffering = 0x20000000,
- RandomAccess = 0x10000000,
- DeleteOnClose = 0x04000000,
- SequentialScan = 0x08000000,
- // AllowPosix = 0x01000000, // FILE_FLAG_POSIX_SEMANTICS
- // BackupOrRestore,
- // DisallowReparsePoint = 0x00200000, // FILE_FLAG_OPEN_REPARSE_POINT
- // NoRemoteRecall = 0x00100000, // FILE_FLAG_OPEN_NO_RECALL
- // FirstPipeInstance = 0x00080000, // FILE_FLAG_FIRST_PIPE_INSTANCE
- Encrypted = 0x00004000, // FILE_ATTRIBUTE_ENCRYPTED
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileShare.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileShare.cs
deleted file mode 100644
index 24742a71b3f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileShare.cs
+++ /dev/null
@@ -1,43 +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.
-
-namespace System.IO
-{
- // Contains constants for controlling file sharing options while
- // opening files. You can specify what access other processes trying
- // to open the same file concurrently can have.
- //
- // Note these values currently match the values for FILE_SHARE_READ,
- // FILE_SHARE_WRITE, and FILE_SHARE_DELETE in winnt.h
- //
- [Flags]
- public enum FileShare
- {
- // No sharing. Any request to open the file (by this process or another
- // process) will fail until the file is closed.
- None = 0,
-
- // Allows subsequent opening of the file for reading. If this flag is not
- // specified, any request to open the file for reading (by this process or
- // another process) will fail until the file is closed.
- Read = 1,
-
- // Allows subsequent opening of the file for writing. If this flag is not
- // specified, any request to open the file for writing (by this process or
- // another process) will fail until the file is closed.
- Write = 2,
-
- // Allows subsequent opening of the file for writing or reading. If this flag
- // is not specified, any request to open the file for writing or reading (by
- // this process or another process) will fail until the file is closed.
- ReadWrite = 3,
-
- // Open the file, but allow someone else to delete the file.
- Delete = 4,
-
- // Whether the file handle should be inheritable by child processes.
- // Note this is not directly supported like this by Win32.
- Inheritable = 0x10,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Linux.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Linux.cs
deleted file mode 100644
index 873c4eb5599..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Linux.cs
+++ /dev/null
@@ -1,30 +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.Diagnostics;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.IO
-{
- public partial class FileStream : Stream
- {
- /// <summary>Prevents other processes from reading from or writing to the FileStream.</summary>
- /// <param name="position">The beginning of the range to lock.</param>
- /// <param name="length">The range to be locked.</param>
- private void LockInternal(long position, long length)
- {
- CheckFileCall(Interop.Sys.LockFileRegion(_fileHandle, position, length, Interop.Sys.LockType.F_WRLCK));
- }
-
- /// <summary>Allows access by other processes to all or part of a file that was previously locked.</summary>
- /// <param name="position">The beginning of the range to unlock.</param>
- /// <param name="length">The range to be unlocked.</param>
- private void UnlockInternal(long position, long length)
- {
- CheckFileCall(Interop.Sys.LockFileRegion(_fileHandle, position, length, Interop.Sys.LockType.F_UNLCK));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.OSX.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileStream.OSX.cs
deleted file mode 100644
index f29e9223373..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.OSX.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.IO
-{
- public partial class FileStream : Stream
- {
- private void LockInternal(long position, long length)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_OSXFileLocking);
- }
-
- private void UnlockInternal(long position, long length)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_OSXFileLocking);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs
deleted file mode 100644
index c1f0fcfb57f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs
+++ /dev/null
@@ -1,852 +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.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.IO
-{
- /// <summary>Provides an implementation of a file stream for Unix files.</summary>
- public partial class FileStream : Stream
- {
- /// <summary>File mode.</summary>
- private FileMode _mode;
-
- /// <summary>Advanced options requested when opening the file.</summary>
- private FileOptions _options;
-
- /// <summary>If the file was opened with FileMode.Append, the length of the file when opened; otherwise, -1.</summary>
- private long _appendStart = -1;
-
- /// <summary>
- /// Extra state used by the file stream when _useAsyncIO is true. This includes
- /// the semaphore used to serialize all operation, the buffer/offset/count provided by the
- /// caller for ReadAsync/WriteAsync operations, and the last successful task returned
- /// synchronously from ReadAsync which can be reused if the count matches the next request.
- /// Only initialized when <see cref="_useAsyncIO"/> is true.
- /// </summary>
- private AsyncState? _asyncState;
-
- /// <summary>Lazily-initialized value for whether the file supports seeking.</summary>
- private bool? _canSeek;
-
- private SafeFileHandle OpenHandle(FileMode mode, FileShare share, FileOptions options)
- {
- // FileStream performs most of the general argument validation. We can assume here that the arguments
- // are all checked and consistent (e.g. non-null-or-empty path; valid enums in mode, access, share, and options; etc.)
- // Store the arguments
- _mode = mode;
- _options = options;
-
- if (_useAsyncIO)
- _asyncState = new AsyncState();
-
- // Translate the arguments into arguments for an open call.
- Interop.Sys.OpenFlags openFlags = PreOpenConfigurationFromOptions(mode, _access, share, options);
-
- // If the file gets created a new, we'll select the permissions for it. Most Unix utilities by default use 666 (read and
- // write for all), so we do the same (even though this doesn't match Windows, where by default it's possible to write out
- // a file and then execute it). No matter what we choose, it'll be subject to the umask applied by the system, such that the
- // actual permissions will typically be less than what we select here.
- const Interop.Sys.Permissions OpenPermissions =
- Interop.Sys.Permissions.S_IRUSR | Interop.Sys.Permissions.S_IWUSR |
- Interop.Sys.Permissions.S_IRGRP | Interop.Sys.Permissions.S_IWGRP |
- Interop.Sys.Permissions.S_IROTH | Interop.Sys.Permissions.S_IWOTH;
-
- // Open the file and store the safe handle.
- return SafeFileHandle.Open(_path!, openFlags, (int)OpenPermissions);
- }
-
- private static bool GetDefaultIsAsync(SafeFileHandle handle) => handle.IsAsync ?? DefaultIsAsync;
-
- /// <summary>Initializes a stream for reading or writing a Unix file.</summary>
- /// <param name="mode">How the file should be opened.</param>
- /// <param name="share">What other access to the file should be allowed. This is currently ignored.</param>
- private void Init(FileMode mode, FileShare share, string originalPath)
- {
- _fileHandle.IsAsync = _useAsyncIO;
-
- // Lock the file if requested via FileShare. This is only advisory locking. FileShare.None implies an exclusive
- // lock on the file and all other modes use a shared lock. While this is not as granular as Windows, not mandatory,
- // and not atomic with file opening, it's better than nothing.
- Interop.Sys.LockOperations lockOperation = (share == FileShare.None) ? Interop.Sys.LockOperations.LOCK_EX : Interop.Sys.LockOperations.LOCK_SH;
- if (Interop.Sys.FLock(_fileHandle, lockOperation | Interop.Sys.LockOperations.LOCK_NB) < 0)
- {
- // The only error we care about is EWOULDBLOCK, which indicates that the file is currently locked by someone
- // else and we would block trying to access it. Other errors, such as ENOTSUP (locking isn't supported) or
- // EACCES (the file system doesn't allow us to lock), will only hamper FileStream's usage without providing value,
- // given again that this is only advisory / best-effort.
- Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
- if (errorInfo.Error == Interop.Error.EWOULDBLOCK)
- {
- throw Interop.GetExceptionForIoErrno(errorInfo, _path, isDirectory: false);
- }
- }
-
- // These provide hints around how the file will be accessed. Specifying both RandomAccess
- // and Sequential together doesn't make sense as they are two competing options on the same spectrum,
- // so if both are specified, we prefer RandomAccess (behavior on Windows is unspecified if both are provided).
- Interop.Sys.FileAdvice fadv =
- (_options & FileOptions.RandomAccess) != 0 ? Interop.Sys.FileAdvice.POSIX_FADV_RANDOM :
- (_options & FileOptions.SequentialScan) != 0 ? Interop.Sys.FileAdvice.POSIX_FADV_SEQUENTIAL :
- 0;
- if (fadv != 0)
- {
- CheckFileCall(Interop.Sys.PosixFAdvise(_fileHandle, 0, 0, fadv),
- ignoreNotSupported: true); // just a hint.
- }
-
- if (_mode == FileMode.Append)
- {
- // Jump to the end of the file if opened as Append.
- _appendStart = SeekCore(_fileHandle, 0, SeekOrigin.End);
- }
- else if (mode == FileMode.Create || mode == FileMode.Truncate)
- {
- // Truncate the file now if the file mode requires it. This ensures that the file only will be truncated
- // if opened successfully.
- if (Interop.Sys.FTruncate(_fileHandle, 0) < 0)
- {
- Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
- if (errorInfo.Error != Interop.Error.EBADF && errorInfo.Error != Interop.Error.EINVAL)
- {
- // We know the file descriptor is valid and we know the size argument to FTruncate is correct,
- // so if EBADF or EINVAL is returned, it means we're dealing with a special file that can't be
- // truncated. Ignore the error in such cases; in all others, throw.
- throw Interop.GetExceptionForIoErrno(errorInfo, _path, isDirectory: false);
- }
- }
- }
- }
-
- /// <summary>Initializes a stream from an already open file handle (file descriptor).</summary>
- private void InitFromHandle(SafeFileHandle handle, FileAccess access, bool useAsyncIO)
- {
- if (useAsyncIO)
- _asyncState = new AsyncState();
-
- if (CanSeekCore(handle)) // use non-virtual CanSeekCore rather than CanSeek to avoid making virtual call during ctor
- SeekCore(handle, 0, SeekOrigin.Current);
- }
-
- /// <summary>Translates the FileMode, FileAccess, and FileOptions values into flags to be passed when opening the file.</summary>
- /// <param name="mode">The FileMode provided to the stream's constructor.</param>
- /// <param name="access">The FileAccess provided to the stream's constructor</param>
- /// <param name="share">The FileShare provided to the stream's constructor</param>
- /// <param name="options">The FileOptions provided to the stream's constructor</param>
- /// <returns>The flags value to be passed to the open system call.</returns>
- private static Interop.Sys.OpenFlags PreOpenConfigurationFromOptions(FileMode mode, FileAccess access, FileShare share, FileOptions options)
- {
- // Translate FileMode. Most of the values map cleanly to one or more options for open.
- Interop.Sys.OpenFlags flags = default(Interop.Sys.OpenFlags);
- switch (mode)
- {
- default:
- case FileMode.Open: // Open maps to the default behavior for open(...). No flags needed.
- case FileMode.Truncate: // We truncate the file after getting the lock
- break;
-
- case FileMode.Append: // Append is the same as OpenOrCreate, except that we'll also separately jump to the end later
- case FileMode.OpenOrCreate:
- case FileMode.Create: // We truncate the file after getting the lock
- flags |= Interop.Sys.OpenFlags.O_CREAT;
- break;
-
- case FileMode.CreateNew:
- flags |= (Interop.Sys.OpenFlags.O_CREAT | Interop.Sys.OpenFlags.O_EXCL);
- break;
- }
-
- // Translate FileAccess. All possible values map cleanly to corresponding values for open.
- switch (access)
- {
- case FileAccess.Read:
- flags |= Interop.Sys.OpenFlags.O_RDONLY;
- break;
-
- case FileAccess.ReadWrite:
- flags |= Interop.Sys.OpenFlags.O_RDWR;
- break;
-
- case FileAccess.Write:
- flags |= Interop.Sys.OpenFlags.O_WRONLY;
- break;
- }
-
- // Handle Inheritable, other FileShare flags are handled by Init
- if ((share & FileShare.Inheritable) == 0)
- {
- flags |= Interop.Sys.OpenFlags.O_CLOEXEC;
- }
-
- // Translate some FileOptions; some just aren't supported, and others will be handled after calling open.
- // - Asynchronous: Handled in ctor, setting _useAsync and SafeFileHandle.IsAsync to true
- // - DeleteOnClose: Doesn't have a Unix equivalent, but we approximate it in Dispose
- // - Encrypted: No equivalent on Unix and is ignored
- // - RandomAccess: Implemented after open if posix_fadvise is available
- // - SequentialScan: Implemented after open if posix_fadvise is available
- // - WriteThrough: Handled here
- if ((options & FileOptions.WriteThrough) != 0)
- {
- flags |= Interop.Sys.OpenFlags.O_SYNC;
- }
-
- return flags;
- }
-
- /// <summary>Gets a value indicating whether the current stream supports seeking.</summary>
- public override bool CanSeek => CanSeekCore(_fileHandle);
-
- /// <summary>Gets a value indicating whether the current stream supports seeking.</summary>
- /// <remarks>
- /// Separated out of CanSeek to enable making non-virtual call to this logic.
- /// We also pass in the file handle to allow the constructor to use this before it stashes the handle.
- /// </remarks>
- private bool CanSeekCore(SafeFileHandle fileHandle)
- {
- if (fileHandle.IsClosed)
- {
- return false;
- }
-
- if (!_canSeek.HasValue)
- {
- // Lazily-initialize whether we're able to seek, tested by seeking to our current location.
- _canSeek = Interop.Sys.LSeek(fileHandle, 0, Interop.Sys.SeekWhence.SEEK_CUR) >= 0;
- }
-
- return _canSeek.GetValueOrDefault();
- }
-
- private long GetLengthInternal()
- {
- // Get the length of the file as reported by the OS
- Interop.Sys.FileStatus status;
- CheckFileCall(Interop.Sys.FStat(_fileHandle, out status));
- long length = status.Size;
-
- // But we may have buffered some data to be written that puts our length
- // beyond what the OS is aware of. Update accordingly.
- if (_writePos > 0 && _filePosition + _writePos > length)
- {
- length = _writePos + _filePosition;
- }
-
- return length;
- }
-
- /// <summary>Releases the unmanaged resources used by the stream.</summary>
- /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
- protected override void Dispose(bool disposing)
- {
- try
- {
- if (_fileHandle != null && !_fileHandle.IsClosed)
- {
- // Flush any remaining data in the file
- try
- {
- FlushWriteBuffer();
- }
- catch (Exception e) when (IsIoRelatedException(e) && !disposing)
- {
- // On finalization, ignore failures from trying to flush the write buffer,
- // e.g. if this stream is wrapping a pipe and the pipe is now broken.
- }
-
- // If DeleteOnClose was requested when constructed, delete the file now.
- // (Unix doesn't directly support DeleteOnClose, so we mimic it here.)
- if (_path != null && (_options & FileOptions.DeleteOnClose) != 0)
- {
- // Since we still have the file open, this will end up deleting
- // it (assuming we're the only link to it) once it's closed, but the
- // name will be removed immediately.
- Interop.Sys.Unlink(_path); // ignore errors; it's valid that the path may no longer exist
- }
- }
- }
- finally
- {
- if (_fileHandle != null && !_fileHandle.IsClosed)
- {
- _fileHandle.Dispose();
- }
- base.Dispose(disposing);
- }
- }
-
- public override ValueTask DisposeAsync()
- {
- // On Unix, we don't have any special support for async I/O, simply queueing writes
- // rather than doing them synchronously. As such, if we're "using async I/O" and we
- // have something to flush, queue the call to Dispose, so that we end up queueing whatever
- // write work happens to flush the buffer. Otherwise, just delegate to the base implementation,
- // which will synchronously invoke Dispose. We don't need to factor in the current type
- // as we're using the virtual Dispose either way, and therefore factoring in whatever
- // override may already exist on a derived type.
- if (_useAsyncIO && _writePos > 0)
- {
- return new ValueTask(Task.Factory.StartNew(s => ((FileStream)s!).Dispose(), this,
- CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default));
- }
-
- return base.DisposeAsync();
- }
-
- /// <summary>Flushes the OS buffer. This does not flush the internal read/write buffer.</summary>
- private void FlushOSBuffer()
- {
- if (Interop.Sys.FSync(_fileHandle) < 0)
- {
- Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
- switch (errorInfo.Error)
- {
- case Interop.Error.EROFS:
- case Interop.Error.EINVAL:
- case Interop.Error.ENOTSUP:
- // Ignore failures due to the FileStream being bound to a special file that
- // doesn't support synchronization. In such cases there's nothing to flush.
- break;
- default:
- throw Interop.GetExceptionForIoErrno(errorInfo, _path, isDirectory: false);
- }
- }
- }
-
- private void FlushWriteBufferForWriteByte()
- {
- _asyncState?.Wait();
- try { FlushWriteBuffer(); }
- finally { _asyncState?.Release(); }
- }
-
- /// <summary>Writes any data in the write buffer to the underlying stream and resets the buffer.</summary>
- private void FlushWriteBuffer()
- {
- AssertBufferInvariants();
- if (_writePos > 0)
- {
- WriteNative(new ReadOnlySpan<byte>(GetBuffer(), 0, _writePos));
- _writePos = 0;
- }
- }
-
- /// <summary>Asynchronously clears all buffers for this stream, causing any buffered data to be written to the underlying device.</summary>
- /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
- /// <returns>A task that represents the asynchronous flush operation.</returns>
- private Task FlushAsyncInternal(CancellationToken cancellationToken)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
- if (_fileHandle.IsClosed)
- {
- throw Error.GetFileNotOpen();
- }
-
- // As with Win32FileStream, flush the buffers synchronously to avoid race conditions.
- try
- {
- FlushInternalBuffer();
- }
- catch (Exception e)
- {
- return Task.FromException(e);
- }
-
- // We then separately flush to disk asynchronously. This is only
- // necessary if we support writing; otherwise, we're done.
- if (CanWrite)
- {
- return Task.Factory.StartNew(
- state => ((FileStream)state!).FlushOSBuffer(),
- this,
- cancellationToken,
- TaskCreationOptions.DenyChildAttach,
- TaskScheduler.Default);
- }
- else
- {
- return Task.CompletedTask;
- }
- }
-
- /// <summary>Sets the length of this stream to the given value.</summary>
- /// <param name="value">The new length of the stream.</param>
- private void SetLengthInternal(long value)
- {
- FlushInternalBuffer();
-
- if (_appendStart != -1 && value < _appendStart)
- {
- throw new IOException(SR.IO_SetLengthAppendTruncate);
- }
-
- long origPos = _filePosition;
-
- VerifyOSHandlePosition();
-
- if (_filePosition != value)
- {
- SeekCore(_fileHandle, value, SeekOrigin.Begin);
- }
-
- CheckFileCall(Interop.Sys.FTruncate(_fileHandle, value));
-
- // Return file pointer to where it was before setting length
- if (origPos != value)
- {
- if (origPos < value)
- {
- SeekCore(_fileHandle, origPos, SeekOrigin.Begin);
- }
- else
- {
- SeekCore(_fileHandle, 0, SeekOrigin.End);
- }
- }
- }
-
- /// <summary>Reads a block of bytes from the stream and writes the data in a given buffer.</summary>
- private int ReadSpan(Span<byte> destination)
- {
- PrepareForReading();
-
- // Are there any bytes available in the read buffer? If yes,
- // we can just return from the buffer. If the buffer is empty
- // or has no more available data in it, we can either refill it
- // (and then read from the buffer into the user's buffer) or
- // we can just go directly into the user's buffer, if they asked
- // for more data than we'd otherwise buffer.
- int numBytesAvailable = _readLength - _readPos;
- bool readFromOS = false;
- if (numBytesAvailable == 0)
- {
- // If we're not able to seek, then we're not able to rewind the stream (i.e. flushing
- // a read buffer), in which case we don't want to use a read buffer. Similarly, if
- // the user has asked for more data than we can buffer, we also want to skip the buffer.
- if (!CanSeek || (destination.Length >= _bufferLength))
- {
- // Read directly into the user's buffer
- _readPos = _readLength = 0;
- return ReadNative(destination);
- }
- else
- {
- // Read into our buffer.
- _readLength = numBytesAvailable = ReadNative(GetBuffer());
- _readPos = 0;
- if (numBytesAvailable == 0)
- {
- return 0;
- }
-
- // Note that we did an OS read as part of this Read, so that later
- // we don't try to do one again if what's in the buffer doesn't
- // meet the user's request.
- readFromOS = true;
- }
- }
-
- // Now that we know there's data in the buffer, read from it into the user's buffer.
- Debug.Assert(numBytesAvailable > 0, "Data must be in the buffer to be here");
- int bytesRead = Math.Min(numBytesAvailable, destination.Length);
- new Span<byte>(GetBuffer(), _readPos, bytesRead).CopyTo(destination);
- _readPos += bytesRead;
-
- // We may not have had enough data in the buffer to completely satisfy the user's request.
- // While Read doesn't require that we return as much data as the user requested (any amount
- // up to the requested count is fine), FileStream on Windows tries to do so by doing a
- // subsequent read from the file if we tried to satisfy the request with what was in the
- // buffer but the buffer contained less than the requested count. To be consistent with that
- // behavior, we do the same thing here on Unix. Note that we may still get less the requested
- // amount, as the OS may give us back fewer than we request, either due to reaching the end of
- // file, or due to its own whims.
- if (!readFromOS && bytesRead < destination.Length)
- {
- Debug.Assert(_readPos == _readLength, "bytesToRead should only be < destination.Length if numBytesAvailable < destination.Length");
- _readPos = _readLength = 0; // no data left in the read buffer
- bytesRead += ReadNative(destination.Slice(bytesRead));
- }
-
- return bytesRead;
- }
-
- /// <summary>Unbuffered, reads a block of bytes from the file handle into the given buffer.</summary>
- /// <param name="buffer">The buffer into which data from the file is read.</param>
- /// <returns>
- /// The total number of bytes read into the buffer. This might be less than the number of bytes requested
- /// if that number of bytes are not currently available, or zero if the end of the stream is reached.
- /// </returns>
- private unsafe int ReadNative(Span<byte> buffer)
- {
- FlushWriteBuffer(); // we're about to read; dump the write buffer
-
- VerifyOSHandlePosition();
-
- int bytesRead;
- fixed (byte* bufPtr = &MemoryMarshal.GetReference(buffer))
- {
- bytesRead = CheckFileCall(Interop.Sys.Read(_fileHandle, bufPtr, buffer.Length));
- Debug.Assert(bytesRead <= buffer.Length);
- }
- _filePosition += bytesRead;
- return bytesRead;
- }
-
- /// <summary>
- /// Asynchronously reads a sequence of bytes from the current stream and advances
- /// the position within the stream by the number of bytes read.
- /// </summary>
- /// <param name="destination">The buffer to write the data into.</param>
- /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
- /// <param name="synchronousResult">If the operation completes synchronously, the number of bytes read.</param>
- /// <returns>A task that represents the asynchronous read operation.</returns>
- private Task<int>? ReadAsyncInternal(Memory<byte> destination, CancellationToken cancellationToken, out int synchronousResult)
- {
- Debug.Assert(_useAsyncIO);
- Debug.Assert(_asyncState != null);
-
- if (!CanRead) // match Windows behavior; this gets thrown synchronously
- {
- throw Error.GetReadNotSupported();
- }
-
- // Serialize operations using the semaphore.
- Task waitTask = _asyncState.WaitAsync();
-
- // If we got ownership immediately, and if there's enough data in our buffer
- // to satisfy the full request of the caller, hand back the buffered data.
- // While it would be a legal implementation of the Read contract, we don't
- // hand back here less than the amount requested so as to match the behavior
- // in ReadCore that will make a native call to try to fulfill the remainder
- // of the request.
- if (waitTask.Status == TaskStatus.RanToCompletion)
- {
- int numBytesAvailable = _readLength - _readPos;
- if (numBytesAvailable >= destination.Length)
- {
- try
- {
- PrepareForReading();
-
- new Span<byte>(GetBuffer(), _readPos, destination.Length).CopyTo(destination.Span);
- _readPos += destination.Length;
-
- synchronousResult = destination.Length;
- return null;
- }
- catch (Exception exc)
- {
- synchronousResult = 0;
- return Task.FromException<int>(exc);
- }
- finally
- {
- _asyncState.Release();
- }
- }
- }
-
- // Otherwise, issue the whole request asynchronously.
- synchronousResult = 0;
- _asyncState.Memory = destination;
- return waitTask.ContinueWith((t, s) =>
- {
- // The options available on Unix for writing asynchronously to an arbitrary file
- // handle typically amount to just using another thread to do the synchronous write,
- // which is exactly what this implementation does. This does mean there are subtle
- // differences in certain FileStream behaviors between Windows and Unix when multiple
- // asynchronous operations are issued against the stream to execute concurrently; on
- // Unix the operations will be serialized due to the usage of a semaphore, but the
- // position /length information won't be updated until after the write has completed,
- // whereas on Windows it may happen before the write has completed.
-
- Debug.Assert(t.Status == TaskStatus.RanToCompletion);
- var thisRef = (FileStream)s!;
- Debug.Assert(thisRef._asyncState != null);
- try
- {
- Memory<byte> memory = thisRef._asyncState.Memory;
- thisRef._asyncState.Memory = default(Memory<byte>);
- return thisRef.ReadSpan(memory.Span);
- }
- finally { thisRef._asyncState.Release(); }
- }, this, CancellationToken.None, TaskContinuationOptions.DenyChildAttach, TaskScheduler.Default);
- }
-
- /// <summary>Reads from the file handle into the buffer, overwriting anything in it.</summary>
- private int FillReadBufferForReadByte()
- {
- _asyncState?.Wait();
- try { return ReadNative(_buffer); }
- finally { _asyncState?.Release(); }
- }
-
- /// <summary>Writes a block of bytes to the file stream.</summary>
- /// <param name="source">The buffer containing data to write to the stream.</param>
- private void WriteSpan(ReadOnlySpan<byte> source)
- {
- PrepareForWriting();
-
- // If no data is being written, nothing more to do.
- if (source.Length == 0)
- {
- return;
- }
-
- // If there's already data in our write buffer, then we need to go through
- // our buffer to ensure data isn't corrupted.
- if (_writePos > 0)
- {
- // If there's space remaining in the buffer, then copy as much as
- // we can from the user's buffer into ours.
- int spaceRemaining = _bufferLength - _writePos;
- if (spaceRemaining >= source.Length)
- {
- source.CopyTo(GetBuffer().AsSpan(_writePos));
- _writePos += source.Length;
- return;
- }
- else if (spaceRemaining > 0)
- {
- source.Slice(0, spaceRemaining).CopyTo(GetBuffer().AsSpan(_writePos));
- _writePos += spaceRemaining;
- source = source.Slice(spaceRemaining);
- }
-
- // At this point, the buffer is full, so flush it out.
- FlushWriteBuffer();
- }
-
- // Our buffer is now empty. If using the buffer would slow things down (because
- // the user's looking to write more data than we can store in the buffer),
- // skip the buffer. Otherwise, put the remaining data into the buffer.
- Debug.Assert(_writePos == 0);
- if (source.Length >= _bufferLength)
- {
- WriteNative(source);
- }
- else
- {
- source.CopyTo(new Span<byte>(GetBuffer()));
- _writePos = source.Length;
- }
- }
-
- /// <summary>Unbuffered, writes a block of bytes to the file stream.</summary>
- /// <param name="source">The buffer containing data to write to the stream.</param>
- private unsafe void WriteNative(ReadOnlySpan<byte> source)
- {
- VerifyOSHandlePosition();
-
- fixed (byte* bufPtr = &MemoryMarshal.GetReference(source))
- {
- int offset = 0;
- int count = source.Length;
- while (count > 0)
- {
- int bytesWritten = CheckFileCall(Interop.Sys.Write(_fileHandle, bufPtr + offset, count));
- _filePosition += bytesWritten;
- offset += bytesWritten;
- count -= bytesWritten;
- }
- }
- }
-
- /// <summary>
- /// Asynchronously writes a sequence of bytes to the current stream, advances
- /// the current position within this stream by the number of bytes written, and
- /// monitors cancellation requests.
- /// </summary>
- /// <param name="source">The buffer to write data from.</param>
- /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
- /// <returns>A task that represents the asynchronous write operation.</returns>
- private ValueTask WriteAsyncInternal(ReadOnlyMemory<byte> source, CancellationToken cancellationToken)
- {
- Debug.Assert(_useAsyncIO);
- Debug.Assert(_asyncState != null);
-
- if (cancellationToken.IsCancellationRequested)
- return new ValueTask(Task.FromCanceled(cancellationToken));
-
- if (_fileHandle.IsClosed)
- throw Error.GetFileNotOpen();
-
- if (!CanWrite) // match Windows behavior; this gets thrown synchronously
- {
- throw Error.GetWriteNotSupported();
- }
-
- // Serialize operations using the semaphore.
- Task waitTask = _asyncState.WaitAsync();
-
- // If we got ownership immediately, and if there's enough space in our buffer
- // to buffer the entire write request, then do so and we're done.
- if (waitTask.Status == TaskStatus.RanToCompletion)
- {
- int spaceRemaining = _bufferLength - _writePos;
- if (spaceRemaining >= source.Length)
- {
- try
- {
- PrepareForWriting();
-
- source.Span.CopyTo(new Span<byte>(GetBuffer(), _writePos, source.Length));
- _writePos += source.Length;
-
- return default;
- }
- catch (Exception exc)
- {
- return new ValueTask(Task.FromException(exc));
- }
- finally
- {
- _asyncState.Release();
- }
- }
- }
-
- // Otherwise, issue the whole request asynchronously.
- _asyncState.ReadOnlyMemory = source;
- return new ValueTask(waitTask.ContinueWith((t, s) =>
- {
- // The options available on Unix for writing asynchronously to an arbitrary file
- // handle typically amount to just using another thread to do the synchronous write,
- // which is exactly what this implementation does. This does mean there are subtle
- // differences in certain FileStream behaviors between Windows and Unix when multiple
- // asynchronous operations are issued against the stream to execute concurrently; on
- // Unix the operations will be serialized due to the usage of a semaphore, but the
- // position/length information won't be updated until after the write has completed,
- // whereas on Windows it may happen before the write has completed.
-
- Debug.Assert(t.Status == TaskStatus.RanToCompletion);
- var thisRef = (FileStream)s!;
- Debug.Assert(thisRef._asyncState != null);
- try
- {
- ReadOnlyMemory<byte> readOnlyMemory = thisRef._asyncState.ReadOnlyMemory;
- thisRef._asyncState.ReadOnlyMemory = default(ReadOnlyMemory<byte>);
- thisRef.WriteSpan(readOnlyMemory.Span);
- }
- finally { thisRef._asyncState.Release(); }
- }, this, CancellationToken.None, TaskContinuationOptions.DenyChildAttach, TaskScheduler.Default));
- }
-
- public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) =>
- // Windows version overrides this method, so the Unix version does as well, but it doesn't
- // currently have any special optimizations to be done and so just calls to the base.
- base.CopyToAsync(destination, bufferSize, cancellationToken);
-
- /// <summary>Sets the current position of this stream to the given value.</summary>
- /// <param name="offset">The point relative to origin from which to begin seeking. </param>
- /// <param name="origin">
- /// Specifies the beginning, the end, or the current position as a reference
- /// point for offset, using a value of type SeekOrigin.
- /// </param>
- /// <returns>The new position in the stream.</returns>
- public override long Seek(long offset, SeekOrigin origin)
- {
- if (origin < SeekOrigin.Begin || origin > SeekOrigin.End)
- {
- throw new ArgumentException(SR.Argument_InvalidSeekOrigin, nameof(origin));
- }
- if (_fileHandle.IsClosed)
- {
- throw Error.GetFileNotOpen();
- }
- if (!CanSeek)
- {
- throw Error.GetSeekNotSupported();
- }
-
- VerifyOSHandlePosition();
-
- // Flush our write/read buffer. FlushWrite will output any write buffer we have and reset _bufferWritePos.
- // We don't call FlushRead, as that will do an unnecessary seek to rewind the read buffer, and since we're
- // about to seek and update our position, we can simply update the offset as necessary and reset our read
- // position and length to 0. (In the future, for some simple cases we could potentially add an optimization
- // here to just move data around in the buffer for short jumps, to avoid re-reading the data from disk.)
- FlushWriteBuffer();
- if (origin == SeekOrigin.Current)
- {
- offset -= (_readLength - _readPos);
- }
- _readPos = _readLength = 0;
-
- // Keep track of where we were, in case we're in append mode and need to verify
- long oldPos = 0;
- if (_appendStart >= 0)
- {
- oldPos = SeekCore(_fileHandle, 0, SeekOrigin.Current);
- }
-
- // Jump to the new location
- long pos = SeekCore(_fileHandle, offset, origin);
-
- // Prevent users from overwriting data in a file that was opened in append mode.
- if (_appendStart != -1 && pos < _appendStart)
- {
- SeekCore(_fileHandle, oldPos, SeekOrigin.Begin);
- throw new IOException(SR.IO_SeekAppendOverwrite);
- }
-
- // Return the new position
- return pos;
- }
-
- /// <summary>Sets the current position of this stream to the given value.</summary>
- /// <param name="offset">The point relative to origin from which to begin seeking. </param>
- /// <param name="origin">
- /// Specifies the beginning, the end, or the current position as a reference
- /// point for offset, using a value of type SeekOrigin.
- /// </param>
- /// <returns>The new position in the stream.</returns>
- private long SeekCore(SafeFileHandle fileHandle, long offset, SeekOrigin origin)
- {
- Debug.Assert(!fileHandle.IsClosed && (GetType() != typeof(FileStream) || CanSeekCore(fileHandle))); // verify that we can seek, but only if CanSeek won't be a virtual call (which could happen in the ctor)
- Debug.Assert(origin >= SeekOrigin.Begin && origin <= SeekOrigin.End);
-
- long pos = CheckFileCall(Interop.Sys.LSeek(fileHandle, offset, (Interop.Sys.SeekWhence)(int)origin)); // SeekOrigin values are the same as Interop.libc.SeekWhence values
- _filePosition = pos;
- return pos;
- }
-
- private long CheckFileCall(long result, bool ignoreNotSupported = false)
- {
- if (result < 0)
- {
- Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
- if (!(ignoreNotSupported && errorInfo.Error == Interop.Error.ENOTSUP))
- {
- throw Interop.GetExceptionForIoErrno(errorInfo, _path, isDirectory: false);
- }
- }
-
- return result;
- }
-
- private int CheckFileCall(int result, bool ignoreNotSupported = false)
- {
- CheckFileCall((long)result, ignoreNotSupported);
-
- return result;
- }
-
- /// <summary>State used when the stream is in async mode.</summary>
- private sealed class AsyncState : SemaphoreSlim
- {
- internal ReadOnlyMemory<byte> ReadOnlyMemory;
- internal Memory<byte> Memory;
-
- /// <summary>Initialize the AsyncState.</summary>
- internal AsyncState() : base(initialCount: 1, maxCount: 1) { }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Win32.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Win32.cs
deleted file mode 100644
index 310d5d2d1fb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Win32.cs
+++ /dev/null
@@ -1,107 +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 System.Diagnostics;
-using Microsoft.Win32.SafeHandles;
-
-namespace System.IO
-{
- public partial class FileStream : Stream
- {
- private SafeFileHandle OpenHandle(FileMode mode, FileShare share, FileOptions options)
- {
- return CreateFileOpenHandle(mode, share, options);
- }
-
- private unsafe SafeFileHandle CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
- {
- Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(share);
-
- int fAccess =
- ((_access & FileAccess.Read) == FileAccess.Read ? GENERIC_READ : 0) |
- ((_access & FileAccess.Write) == FileAccess.Write ? GENERIC_WRITE : 0);
-
- // Our Inheritable bit was stolen from Windows, but should be set in
- // the security attributes class. Don't leave this bit set.
- share &= ~FileShare.Inheritable;
-
- // Must use a valid Win32 constant here...
- if (mode == FileMode.Append)
- mode = FileMode.OpenOrCreate;
-
- int flagsAndAttributes = (int)options;
-
- // For mitigating local elevation of privilege attack through named pipes
- // make sure we always call CreateFile with SECURITY_ANONYMOUS so that the
- // named pipe server can't impersonate a high privileged client security context
- // (note that this is the effective default on CreateFile2)
- flagsAndAttributes |= (Interop.Kernel32.SecurityOptions.SECURITY_SQOS_PRESENT | Interop.Kernel32.SecurityOptions.SECURITY_ANONYMOUS);
-
- using (DisableMediaInsertionPrompt.Create())
- {
- Debug.Assert(_path != null);
- return ValidateFileHandle(
- Interop.Kernel32.CreateFile(_path, fAccess, share, ref secAttrs, mode, flagsAndAttributes, IntPtr.Zero));
- }
- }
-
- private static bool GetDefaultIsAsync(SafeFileHandle handle)
- {
- return handle.IsAsync ?? !IsHandleSynchronous(handle, ignoreInvalid: true) ?? DefaultIsAsync;
- }
-
- private static unsafe bool? IsHandleSynchronous(SafeFileHandle fileHandle, bool ignoreInvalid)
- {
- if (fileHandle.IsInvalid)
- return null;
-
- uint fileMode;
-
-
- int status = Interop.NtDll.NtQueryInformationFile(
- FileHandle: fileHandle,
- IoStatusBlock: out _,
- FileInformation: &fileMode,
- Length: sizeof(uint),
- FileInformationClass: Interop.NtDll.FileModeInformation);
-
- switch (status)
- {
- case 0:
- // We were successful
- break;
- case Interop.NtDll.STATUS_INVALID_HANDLE:
- if (!ignoreInvalid)
- {
- throw Win32Marshal.GetExceptionForWin32Error(Interop.Errors.ERROR_INVALID_HANDLE);
- }
- else
- {
- return null;
- }
- default:
- // Something else is preventing access
- Debug.Fail("Unable to get the file mode information, status was" + status.ToString());
- return null;
- }
-
- // If either of these two flags are set, the file handle is synchronous (not overlapped)
- return (fileMode & (Interop.NtDll.FILE_SYNCHRONOUS_IO_ALERT | Interop.NtDll.FILE_SYNCHRONOUS_IO_NONALERT)) > 0;
- }
-
- private static void VerifyHandleIsSync(SafeFileHandle handle, int fileType, FileAccess access)
- {
- // As we can accurately check the handle type when we have access to NtQueryInformationFile we don't need to skip for
- // any particular file handle type.
-
- // If the handle was passed in without an explicit async setting, we already looked it up in GetDefaultIsAsync
- if (!handle.IsAsync.HasValue)
- return;
-
- // If we can't check the handle, just assume it is ok.
- if (!(IsHandleSynchronous(handle, ignoreInvalid: false) ?? true))
- throw new ArgumentException(SR.Arg_HandleNotSync, nameof(handle));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs
deleted file mode 100644
index cc6da307f6a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs
+++ /dev/null
@@ -1,1627 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Threading.Tasks;
-using Microsoft.Win32.SafeHandles;
-using System.Runtime.CompilerServices;
-
-/*
- * Win32FileStream supports different modes of accessing the disk - async mode
- * and sync mode. They are two completely different codepaths in the
- * sync & async methods (i.e. Read/Write vs. ReadAsync/WriteAsync). File
- * handles in NT can be opened in only sync or overlapped (async) mode,
- * and we have to deal with this pain. Stream has implementations of
- * the sync methods in terms of the async ones, so we'll
- * call through to our base class to get those methods when necessary.
- *
- * Also buffering is added into Win32FileStream as well. Folded in the
- * code from BufferedStream, so all the comments about it being mostly
- * aggressive (and the possible perf improvement) apply to Win32FileStream as
- * well. Also added some buffering to the async code paths.
- *
- * Class Invariants:
- * The class has one buffer, shared for reading & writing. It can only be
- * used for one or the other at any point in time - not both. The following
- * should be true:
- * 0 <= _readPos <= _readLen < _bufferSize
- * 0 <= _writePos < _bufferSize
- * _readPos == _readLen && _readPos > 0 implies the read buffer is valid,
- * but we're at the end of the buffer.
- * _readPos == _readLen == 0 means the read buffer contains garbage.
- * Either _writePos can be greater than 0, or _readLen & _readPos can be
- * greater than zero, but neither can be greater than zero at the same time.
- *
- */
-
-namespace System.IO
-{
- public partial class FileStream : Stream
- {
- private bool _canSeek;
- private bool _isPipe; // Whether to disable async buffering code.
- private long _appendStart; // When appending, prevent overwriting file.
-
- private static readonly unsafe IOCompletionCallback s_ioCallback = FileStreamCompletionSource.IOCallback;
-
- private Task _activeBufferOperation = Task.CompletedTask; // tracks in-progress async ops using the buffer
- private PreAllocatedOverlapped? _preallocatedOverlapped; // optimization for async ops to avoid per-op allocations
- private FileStreamCompletionSource? _currentOverlappedOwner; // async op currently using the preallocated overlapped
-
- private void Init(FileMode mode, FileShare share, string originalPath)
- {
- if (!PathInternal.IsExtended(originalPath))
- {
- // To help avoid stumbling into opening COM/LPT ports by accident, we will block on non file handles unless
- // we were explicitly passed a path that has \\?\. GetFullPath() will turn paths like C:\foo\con.txt into
- // \\.\CON, so we'll only allow the \\?\ syntax.
-
- int fileType = Interop.Kernel32.GetFileType(_fileHandle);
- if (fileType != Interop.Kernel32.FileTypes.FILE_TYPE_DISK)
- {
- int errorCode = fileType == Interop.Kernel32.FileTypes.FILE_TYPE_UNKNOWN
- ? Marshal.GetLastWin32Error()
- : Interop.Errors.ERROR_SUCCESS;
-
- _fileHandle.Dispose();
-
- if (errorCode != Interop.Errors.ERROR_SUCCESS)
- {
- throw Win32Marshal.GetExceptionForWin32Error(errorCode);
- }
- throw new NotSupportedException(SR.NotSupported_FileStreamOnNonFiles);
- }
- }
-
- // This is necessary for async IO using IO Completion ports via our
- // managed Threadpool API's. This (theoretically) calls the OS's
- // BindIoCompletionCallback method, and passes in a stub for the
- // LPOVERLAPPED_COMPLETION_ROUTINE. This stub looks at the Overlapped
- // struct for this request and gets a delegate to a managed callback
- // from there, which it then calls on a threadpool thread. (We allocate
- // our native OVERLAPPED structs 2 pointers too large and store EE state
- // & GC handles there, one to an IAsyncResult, the other to a delegate.)
- if (_useAsyncIO)
- {
- try
- {
- _fileHandle.ThreadPoolBinding = ThreadPoolBoundHandle.BindHandle(_fileHandle);
- }
- catch (ArgumentException ex)
- {
- throw new IOException(SR.IO_BindHandleFailed, ex);
- }
- finally
- {
- if (_fileHandle.ThreadPoolBinding == null)
- {
- // We should close the handle so that the handle is not open until SafeFileHandle GC
- Debug.Assert(!_exposedHandle, "Are we closing handle that we exposed/not own, how?");
- _fileHandle.Dispose();
- }
- }
- }
-
- _canSeek = true;
-
- // For Append mode...
- if (mode == FileMode.Append)
- {
- _appendStart = SeekCore(_fileHandle, 0, SeekOrigin.End);
- }
- else
- {
- _appendStart = -1;
- }
- }
-
- private void InitFromHandle(SafeFileHandle handle, FileAccess access, bool useAsyncIO)
- {
-#if DEBUG
- bool hadBinding = handle.ThreadPoolBinding != null;
-
- try
- {
-#endif
- InitFromHandleImpl(handle, access, useAsyncIO);
-#if DEBUG
- }
- catch
- {
- Debug.Assert(hadBinding || handle.ThreadPoolBinding == null, "We should never error out with a ThreadPoolBinding we've added");
- throw;
- }
-#endif
- }
-
- private void InitFromHandleImpl(SafeFileHandle handle, FileAccess access, bool useAsyncIO)
- {
- int handleType = Interop.Kernel32.GetFileType(handle);
- Debug.Assert(handleType == Interop.Kernel32.FileTypes.FILE_TYPE_DISK || handleType == Interop.Kernel32.FileTypes.FILE_TYPE_PIPE || handleType == Interop.Kernel32.FileTypes.FILE_TYPE_CHAR, "FileStream was passed an unknown file type!");
-
- _canSeek = handleType == Interop.Kernel32.FileTypes.FILE_TYPE_DISK;
- _isPipe = handleType == Interop.Kernel32.FileTypes.FILE_TYPE_PIPE;
-
- // This is necessary for async IO using IO Completion ports via our
- // managed Threadpool API's. This calls the OS's
- // BindIoCompletionCallback method, and passes in a stub for the
- // LPOVERLAPPED_COMPLETION_ROUTINE. This stub looks at the Overlapped
- // struct for this request and gets a delegate to a managed callback
- // from there, which it then calls on a threadpool thread. (We allocate
- // our native OVERLAPPED structs 2 pointers too large and store EE
- // state & a handle to a delegate there.)
- //
- // If, however, we've already bound this file handle to our completion port,
- // don't try to bind it again because it will fail. A handle can only be
- // bound to a single completion port at a time.
- if (useAsyncIO && !(handle.IsAsync ?? false))
- {
- try
- {
- handle.ThreadPoolBinding = ThreadPoolBoundHandle.BindHandle(handle);
- }
- catch (Exception ex)
- {
- // If you passed in a synchronous handle and told us to use
- // it asynchronously, throw here.
- throw new ArgumentException(SR.Arg_HandleNotAsync, nameof(handle), ex);
- }
- }
- else if (!useAsyncIO)
- {
- VerifyHandleIsSync(handle, handleType, access);
- }
-
- if (_canSeek)
- SeekCore(handle, 0, SeekOrigin.Current);
- else
- _filePosition = 0;
- }
-
- private static unsafe Interop.Kernel32.SECURITY_ATTRIBUTES GetSecAttrs(FileShare share)
- {
- Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = default;
- if ((share & FileShare.Inheritable) != 0)
- {
- secAttrs = new Interop.Kernel32.SECURITY_ATTRIBUTES
- {
- nLength = (uint)sizeof(Interop.Kernel32.SECURITY_ATTRIBUTES),
- bInheritHandle = Interop.BOOL.TRUE
- };
- }
- return secAttrs;
- }
-
- private bool HasActiveBufferOperation => !_activeBufferOperation.IsCompleted;
-
- public override bool CanSeek => _canSeek;
-
- private unsafe long GetLengthInternal()
- {
- Interop.Kernel32.FILE_STANDARD_INFO info;
-
- if (!Interop.Kernel32.GetFileInformationByHandleEx(_fileHandle, Interop.Kernel32.FILE_INFO_BY_HANDLE_CLASS.FileStandardInfo, out info, (uint)sizeof(Interop.Kernel32.FILE_STANDARD_INFO)))
- throw Win32Marshal.GetExceptionForLastWin32Error(_path);
- long len = info.EndOfFile;
-
- // If we're writing near the end of the file, we must include our
- // internal buffer in our Length calculation. Don't flush because
- // we use the length of the file in our async write method.
- if (_writePos > 0 && _filePosition + _writePos > len)
- len = _writePos + _filePosition;
-
- return len;
- }
-
- protected override void Dispose(bool disposing)
- {
- // Nothing will be done differently based on whether we are
- // disposing vs. finalizing. This is taking advantage of the
- // weak ordering between normal finalizable objects & critical
- // finalizable objects, which I included in the SafeHandle
- // design for Win32FileStream, which would often "just work" when
- // finalized.
- try
- {
- if (_fileHandle != null && !_fileHandle.IsClosed && _writePos > 0)
- {
- // Flush data to disk iff we were writing. After
- // thinking about this, we also don't need to flush
- // our read position, regardless of whether the handle
- // was exposed to the user. They probably would NOT
- // want us to do this.
- try
- {
- FlushWriteBuffer(!disposing);
- }
- catch (Exception e) when (IsIoRelatedException(e) && !disposing)
- {
- // On finalization, ignore failures from trying to flush the write buffer,
- // e.g. if this stream is wrapping a pipe and the pipe is now broken.
- }
- }
- }
- finally
- {
- if (_fileHandle != null && !_fileHandle.IsClosed)
- {
- _fileHandle.ThreadPoolBinding?.Dispose();
- _fileHandle.Dispose();
- }
-
- _preallocatedOverlapped?.Dispose();
- _canSeek = false;
-
- // Don't set the buffer to null, to avoid a NullReferenceException
- // when users have a race condition in their code (i.e. they call
- // Close when calling another method on Stream like Read).
- }
- }
-
- public override ValueTask DisposeAsync() =>
- GetType() == typeof(FileStream) ?
- DisposeAsyncCore() :
- base.DisposeAsync();
-
- private async ValueTask DisposeAsyncCore()
- {
- // Same logic as in Dispose(), except with async counterparts.
- // TODO: https://github.com/dotnet/corefx/issues/32837: FlushAsync does synchronous work.
- try
- {
- if (_fileHandle != null && !_fileHandle.IsClosed && _writePos > 0)
- {
- await FlushAsyncInternal(default).ConfigureAwait(false);
- }
- }
- finally
- {
- if (_fileHandle != null && !_fileHandle.IsClosed)
- {
- _fileHandle.ThreadPoolBinding?.Dispose();
- _fileHandle.Dispose();
- }
-
- _preallocatedOverlapped?.Dispose();
- _canSeek = false;
- GC.SuppressFinalize(this); // the handle is closed; nothing further for the finalizer to do
- }
- }
-
- private void FlushOSBuffer()
- {
- if (!Interop.Kernel32.FlushFileBuffers(_fileHandle))
- {
- throw Win32Marshal.GetExceptionForLastWin32Error(_path);
- }
- }
-
- // Returns a task that flushes the internal write buffer
- private Task FlushWriteAsync(CancellationToken cancellationToken)
- {
- Debug.Assert(_useAsyncIO);
- Debug.Assert(_readPos == 0 && _readLength == 0, "FileStream: Read buffer must be empty in FlushWriteAsync!");
-
- // If the buffer is already flushed, don't spin up the OS write
- if (_writePos == 0) return Task.CompletedTask;
-
- Task flushTask = WriteAsyncInternalCore(new ReadOnlyMemory<byte>(GetBuffer(), 0, _writePos), cancellationToken);
- _writePos = 0;
-
- // Update the active buffer operation
- _activeBufferOperation = HasActiveBufferOperation ?
- Task.WhenAll(_activeBufferOperation, flushTask) :
- flushTask;
-
- return flushTask;
- }
-
- private void FlushWriteBufferForWriteByte() => FlushWriteBuffer();
-
- // Writes are buffered. Anytime the buffer fills up
- // (_writePos + delta > _bufferSize) or the buffer switches to reading
- // and there is left over data (_writePos > 0), this function must be called.
- private void FlushWriteBuffer(bool calledFromFinalizer = false)
- {
- if (_writePos == 0) return;
- Debug.Assert(_readPos == 0 && _readLength == 0, "FileStream: Read buffer must be empty in FlushWrite!");
-
- if (_useAsyncIO)
- {
- Task writeTask = FlushWriteAsync(CancellationToken.None);
- // With our Whidbey async IO & overlapped support for AD unloads,
- // we don't strictly need to block here to release resources
- // since that support takes care of the pinning & freeing the
- // overlapped struct. We need to do this when called from
- // Close so that the handle is closed when Close returns, but
- // we don't need to call EndWrite from the finalizer.
- // Additionally, if we do call EndWrite, we block forever
- // because AD unloads prevent us from running the managed
- // callback from the IO completion port. Blocking here when
- // called from the finalizer during AD unload is clearly wrong,
- // but we can't use any sort of test for whether the AD is
- // unloading because if we weren't unloading, an AD unload
- // could happen on a separate thread before we call EndWrite.
- if (!calledFromFinalizer)
- {
- writeTask.GetAwaiter().GetResult();
- }
- }
- else
- {
- WriteCore(new ReadOnlySpan<byte>(GetBuffer(), 0, _writePos));
- }
-
- _writePos = 0;
- }
-
- private void SetLengthInternal(long value)
- {
- // Handle buffering updates.
- if (_writePos > 0)
- {
- FlushWriteBuffer();
- }
- else if (_readPos < _readLength)
- {
- FlushReadBuffer();
- }
- _readPos = 0;
- _readLength = 0;
-
- if (_appendStart != -1 && value < _appendStart)
- throw new IOException(SR.IO_SetLengthAppendTruncate);
- SetLengthCore(value);
- }
-
- // We absolutely need this method broken out so that WriteInternalCoreAsync can call
- // a method without having to go through buffering code that might call FlushWrite.
- private void SetLengthCore(long value)
- {
- Debug.Assert(value >= 0, "value >= 0");
- long origPos = _filePosition;
-
- VerifyOSHandlePosition();
- if (_filePosition != value)
- SeekCore(_fileHandle, value, SeekOrigin.Begin);
- if (!Interop.Kernel32.SetEndOfFile(_fileHandle))
- {
- int errorCode = Marshal.GetLastWin32Error();
- if (errorCode == Interop.Errors.ERROR_INVALID_PARAMETER)
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_FileLengthTooBig);
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, _path);
- }
- // Return file pointer to where it was before setting length
- if (origPos != value)
- {
- if (origPos < value)
- SeekCore(_fileHandle, origPos, SeekOrigin.Begin);
- else
- SeekCore(_fileHandle, 0, SeekOrigin.End);
- }
- }
-
- // Instance method to help code external to this MarshalByRefObject avoid
- // accessing its fields by ref. This avoids a compiler warning.
- private FileStreamCompletionSource? CompareExchangeCurrentOverlappedOwner(FileStreamCompletionSource? newSource, FileStreamCompletionSource? existingSource) =>
- Interlocked.CompareExchange(ref _currentOverlappedOwner, newSource, existingSource);
-
- private int ReadSpan(Span<byte> destination)
- {
- Debug.Assert(!_useAsyncIO, "Must only be used when in synchronous mode");
- Debug.Assert((_readPos == 0 && _readLength == 0 && _writePos >= 0) || (_writePos == 0 && _readPos <= _readLength),
- "We're either reading or writing, but not both.");
-
- bool isBlocked = false;
- int n = _readLength - _readPos;
- // if the read buffer is empty, read into either user's array or our
- // buffer, depending on number of bytes user asked for and buffer size.
- if (n == 0)
- {
- if (!CanRead) throw Error.GetReadNotSupported();
- if (_writePos > 0) FlushWriteBuffer();
- if (!CanSeek || (destination.Length >= _bufferLength))
- {
- n = ReadNative(destination);
- // Throw away read buffer.
- _readPos = 0;
- _readLength = 0;
- return n;
- }
- n = ReadNative(GetBuffer());
- if (n == 0) return 0;
- isBlocked = n < _bufferLength;
- _readPos = 0;
- _readLength = n;
- }
- // Now copy min of count or numBytesAvailable (i.e. near EOF) to array.
- if (n > destination.Length) n = destination.Length;
- new ReadOnlySpan<byte>(GetBuffer(), _readPos, n).CopyTo(destination);
- _readPos += n;
-
- // We may have read less than the number of bytes the user asked
- // for, but that is part of the Stream contract. Reading again for
- // more data may cause us to block if we're using a device with
- // no clear end of file, such as a serial port or pipe. If we
- // blocked here & this code was used with redirected pipes for a
- // process's standard output, this can lead to deadlocks involving
- // two processes. But leave this here for files to avoid what would
- // probably be a breaking change. --
-
- // If we are reading from a device with no clear EOF like a
- // serial port or a pipe, this will cause us to block incorrectly.
- if (!_isPipe)
- {
- // If we hit the end of the buffer and didn't have enough bytes, we must
- // read some more from the underlying stream. However, if we got
- // fewer bytes from the underlying stream than we asked for (i.e. we're
- // probably blocked), don't ask for more bytes.
- if (n < destination.Length && !isBlocked)
- {
- Debug.Assert(_readPos == _readLength, "Read buffer should be empty!");
- int moreBytesRead = ReadNative(destination.Slice(n));
- n += moreBytesRead;
- // We've just made our buffer inconsistent with our position
- // pointer. We must throw away the read buffer.
- _readPos = 0;
- _readLength = 0;
- }
- }
-
- return n;
- }
-
- [Conditional("DEBUG")]
- private void AssertCanRead()
- {
- Debug.Assert(!_fileHandle.IsClosed, "!_fileHandle.IsClosed");
- Debug.Assert(CanRead, "CanRead");
- }
-
- /// <summary>Reads from the file handle into the buffer, overwriting anything in it.</summary>
- private int FillReadBufferForReadByte() =>
- _useAsyncIO ?
- ReadNativeAsync(new Memory<byte>(_buffer), 0, CancellationToken.None).GetAwaiter().GetResult() :
- ReadNative(_buffer);
-
- private unsafe int ReadNative(Span<byte> buffer)
- {
- Debug.Assert(!_useAsyncIO, $"{nameof(ReadNative)} doesn't work on asynchronous file streams.");
- AssertCanRead();
-
- // Make sure we are reading from the right spot
- VerifyOSHandlePosition();
-
- int r = ReadFileNative(_fileHandle, buffer, null, out int errorCode);
-
- if (r == -1)
- {
- // For pipes, ERROR_BROKEN_PIPE is the normal end of the pipe.
- if (errorCode == ERROR_BROKEN_PIPE)
- {
- r = 0;
- }
- else
- {
- if (errorCode == ERROR_INVALID_PARAMETER)
- throw new ArgumentException(SR.Arg_HandleNotSync, "_fileHandle");
-
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, _path);
- }
- }
- Debug.Assert(r >= 0, "FileStream's ReadNative is likely broken.");
- _filePosition += r;
-
- return r;
- }
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- if (origin < SeekOrigin.Begin || origin > SeekOrigin.End)
- throw new ArgumentException(SR.Argument_InvalidSeekOrigin, nameof(origin));
- if (_fileHandle.IsClosed) throw Error.GetFileNotOpen();
- if (!CanSeek) throw Error.GetSeekNotSupported();
-
- Debug.Assert((_readPos == 0 && _readLength == 0 && _writePos >= 0) || (_writePos == 0 && _readPos <= _readLength), "We're either reading or writing, but not both.");
-
- // If we've got bytes in our buffer to write, write them out.
- // If we've read in and consumed some bytes, we'll have to adjust
- // our seek positions ONLY IF we're seeking relative to the current
- // position in the stream. This simulates doing a seek to the new
- // position, then a read for the number of bytes we have in our buffer.
- if (_writePos > 0)
- {
- FlushWriteBuffer();
- }
- else if (origin == SeekOrigin.Current)
- {
- // Don't call FlushRead here, which would have caused an infinite
- // loop. Simply adjust the seek origin. This isn't necessary
- // if we're seeking relative to the beginning or end of the stream.
- offset -= (_readLength - _readPos);
- }
- _readPos = _readLength = 0;
-
- // Verify that internal position is in sync with the handle
- VerifyOSHandlePosition();
-
- long oldPos = _filePosition + (_readPos - _readLength);
- long pos = SeekCore(_fileHandle, offset, origin);
-
- // Prevent users from overwriting data in a file that was opened in
- // append mode.
- if (_appendStart != -1 && pos < _appendStart)
- {
- SeekCore(_fileHandle, oldPos, SeekOrigin.Begin);
- throw new IOException(SR.IO_SeekAppendOverwrite);
- }
-
- // We now must update the read buffer. We can in some cases simply
- // update _readPos within the buffer, copy around the buffer so our
- // Position property is still correct, and avoid having to do more
- // reads from the disk. Otherwise, discard the buffer's contents.
- if (_readLength > 0)
- {
- // We can optimize the following condition:
- // oldPos - _readPos <= pos < oldPos + _readLen - _readPos
- if (oldPos == pos)
- {
- if (_readPos > 0)
- {
- Buffer.BlockCopy(GetBuffer(), _readPos, GetBuffer(), 0, _readLength - _readPos);
- _readLength -= _readPos;
- _readPos = 0;
- }
- // If we still have buffered data, we must update the stream's
- // position so our Position property is correct.
- if (_readLength > 0)
- SeekCore(_fileHandle, _readLength, SeekOrigin.Current);
- }
- else if (oldPos - _readPos < pos && pos < oldPos + _readLength - _readPos)
- {
- int diff = (int)(pos - oldPos);
- Buffer.BlockCopy(GetBuffer(), _readPos + diff, GetBuffer(), 0, _readLength - (_readPos + diff));
- _readLength -= (_readPos + diff);
- _readPos = 0;
- if (_readLength > 0)
- SeekCore(_fileHandle, _readLength, SeekOrigin.Current);
- }
- else
- {
- // Lose the read buffer.
- _readPos = 0;
- _readLength = 0;
- }
- Debug.Assert(_readLength >= 0 && _readPos <= _readLength, "_readLen should be nonnegative, and _readPos should be less than or equal _readLen");
- Debug.Assert(pos == Position, "Seek optimization: pos != Position! Buffer math was mangled.");
- }
- return pos;
- }
-
- // This doesn't do argument checking. Necessary for SetLength, which must
- // set the file pointer beyond the end of the file. This will update the
- // internal position
- private long SeekCore(SafeFileHandle fileHandle, long offset, SeekOrigin origin, bool closeInvalidHandle = false)
- {
- Debug.Assert(!fileHandle.IsClosed && _canSeek, "!fileHandle.IsClosed && _canSeek");
- Debug.Assert(origin >= SeekOrigin.Begin && origin <= SeekOrigin.End, "origin >= SeekOrigin.Begin && origin <= SeekOrigin.End");
-
- if (!Interop.Kernel32.SetFilePointerEx(fileHandle, offset, out long ret, (uint)origin))
- {
- if (closeInvalidHandle)
- {
- throw Win32Marshal.GetExceptionForWin32Error(GetLastWin32ErrorAndDisposeHandleIfInvalid(), _path);
- }
- else
- {
- throw Win32Marshal.GetExceptionForLastWin32Error(_path);
- }
- }
-
- _filePosition = ret;
- return ret;
- }
-
- partial void OnBufferAllocated()
- {
- Debug.Assert(_buffer != null);
- Debug.Assert(_preallocatedOverlapped == null);
-
- if (_useAsyncIO)
- _preallocatedOverlapped = new PreAllocatedOverlapped(s_ioCallback, this, _buffer);
- }
-
- private void WriteSpan(ReadOnlySpan<byte> source)
- {
- Debug.Assert(!_useAsyncIO, "Must only be used when in synchronous mode");
-
- if (_writePos == 0)
- {
- // Ensure we can write to the stream, and ready buffer for writing.
- if (!CanWrite) throw Error.GetWriteNotSupported();
- if (_readPos < _readLength) FlushReadBuffer();
- _readPos = 0;
- _readLength = 0;
- }
-
- // If our buffer has data in it, copy data from the user's array into
- // the buffer, and if we can fit it all there, return. Otherwise, write
- // the buffer to disk and copy any remaining data into our buffer.
- // The assumption here is memcpy is cheaper than disk (or net) IO.
- // (10 milliseconds to disk vs. ~20-30 microseconds for a 4K memcpy)
- // So the extra copying will reduce the total number of writes, in
- // non-pathological cases (i.e. write 1 byte, then write for the buffer
- // size repeatedly)
- if (_writePos > 0)
- {
- int numBytes = _bufferLength - _writePos; // space left in buffer
- if (numBytes > 0)
- {
- if (numBytes >= source.Length)
- {
- source.CopyTo(GetBuffer().AsSpan(_writePos));
- _writePos += source.Length;
- return;
- }
- else
- {
- source.Slice(0, numBytes).CopyTo(GetBuffer().AsSpan(_writePos));
- _writePos += numBytes;
- source = source.Slice(numBytes);
- }
- }
- // Reset our buffer. We essentially want to call FlushWrite
- // without calling Flush on the underlying Stream.
-
- WriteCore(new ReadOnlySpan<byte>(GetBuffer(), 0, _writePos));
- _writePos = 0;
- }
-
- // If the buffer would slow writes down, avoid buffer completely.
- if (source.Length >= _bufferLength)
- {
- Debug.Assert(_writePos == 0, "FileStream cannot have buffered data to write here! Your stream will be corrupted.");
- WriteCore(source);
- return;
- }
- else if (source.Length == 0)
- {
- return; // Don't allocate a buffer then call memcpy for 0 bytes.
- }
-
- // Copy remaining bytes into buffer, to write at a later date.
- source.CopyTo(GetBuffer().AsSpan(_writePos));
- _writePos = source.Length;
- return;
- }
-
- private unsafe void WriteCore(ReadOnlySpan<byte> source)
- {
- Debug.Assert(!_useAsyncIO);
- Debug.Assert(!_fileHandle.IsClosed, "!_handle.IsClosed");
- Debug.Assert(CanWrite, "_parent.CanWrite");
- Debug.Assert(_readPos == _readLength, "_readPos == _readLen");
-
- // Make sure we are writing to the position that we think we are
- VerifyOSHandlePosition();
-
- int errorCode = 0;
- int r = WriteFileNative(_fileHandle, source, null, out errorCode);
-
- if (r == -1)
- {
- // For pipes, ERROR_NO_DATA is not an error, but the pipe is closing.
- if (errorCode == ERROR_NO_DATA)
- {
- r = 0;
- }
- else
- {
- // ERROR_INVALID_PARAMETER may be returned for writes
- // where the position is too large or for synchronous writes
- // to a handle opened asynchronously.
- if (errorCode == ERROR_INVALID_PARAMETER)
- throw new IOException(SR.IO_FileTooLongOrHandleNotSync);
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, _path);
- }
- }
- Debug.Assert(r >= 0, "FileStream's WriteCore is likely broken.");
- _filePosition += r;
- return;
- }
-
- private Task<int>? ReadAsyncInternal(Memory<byte> destination, CancellationToken cancellationToken, out int synchronousResult)
- {
- Debug.Assert(_useAsyncIO);
- if (!CanRead) throw Error.GetReadNotSupported();
-
- Debug.Assert((_readPos == 0 && _readLength == 0 && _writePos >= 0) || (_writePos == 0 && _readPos <= _readLength), "We're either reading or writing, but not both.");
-
- if (_isPipe)
- {
- // Pipes are tricky, at least when you have 2 different pipes
- // that you want to use simultaneously. When redirecting stdout
- // & stderr with the Process class, it's easy to deadlock your
- // parent & child processes when doing writes 4K at a time. The
- // OS appears to use a 4K buffer internally. If you write to a
- // pipe that is full, you will block until someone read from
- // that pipe. If you try reading from an empty pipe and
- // Win32FileStream's ReadAsync blocks waiting for data to fill it's
- // internal buffer, you will be blocked. In a case where a child
- // process writes to stdout & stderr while a parent process tries
- // reading from both, you can easily get into a deadlock here.
- // To avoid this deadlock, don't buffer when doing async IO on
- // pipes. But don't completely ignore buffered data either.
- if (_readPos < _readLength)
- {
- int n = Math.Min(_readLength - _readPos, destination.Length);
- new Span<byte>(GetBuffer(), _readPos, n).CopyTo(destination.Span);
- _readPos += n;
- synchronousResult = n;
- return null;
- }
- else
- {
- Debug.Assert(_writePos == 0, "Win32FileStream must not have buffered write data here! Pipes should be unidirectional.");
- synchronousResult = 0;
- return ReadNativeAsync(destination, 0, cancellationToken);
- }
- }
-
- Debug.Assert(!_isPipe, "Should not be a pipe.");
-
- // Handle buffering.
- if (_writePos > 0) FlushWriteBuffer();
- if (_readPos == _readLength)
- {
- // I can't see how to handle buffering of async requests when
- // filling the buffer asynchronously, without a lot of complexity.
- // The problems I see are issuing an async read, we do an async
- // read to fill the buffer, then someone issues another read
- // (either synchronously or asynchronously) before the first one
- // returns. This would involve some sort of complex buffer locking
- // that we probably don't want to get into, at least not in V1.
- // If we did a sync read to fill the buffer, we could avoid the
- // problem, and any async read less than 64K gets turned into a
- // synchronous read by NT anyways... --
-
- if (destination.Length < _bufferLength)
- {
- Task<int> readTask = ReadNativeAsync(new Memory<byte>(GetBuffer()), 0, cancellationToken);
- _readLength = readTask.GetAwaiter().GetResult();
- int n = Math.Min(_readLength, destination.Length);
- new Span<byte>(GetBuffer(), 0, n).CopyTo(destination.Span);
- _readPos = n;
-
- synchronousResult = n;
- return null;
- }
- else
- {
- // Here we're making our position pointer inconsistent
- // with our read buffer. Throw away the read buffer's contents.
- _readPos = 0;
- _readLength = 0;
- synchronousResult = 0;
- return ReadNativeAsync(destination, 0, cancellationToken);
- }
- }
- else
- {
- int n = Math.Min(_readLength - _readPos, destination.Length);
- new Span<byte>(GetBuffer(), _readPos, n).CopyTo(destination.Span);
- _readPos += n;
-
- if (n == destination.Length)
- {
- // Return a completed task
- synchronousResult = n;
- return null;
- }
- else
- {
- // For streams with no clear EOF like serial ports or pipes
- // we cannot read more data without causing an app to block
- // incorrectly. Pipes don't go down this path
- // though. This code needs to be fixed.
- // Throw away read buffer.
- _readPos = 0;
- _readLength = 0;
- synchronousResult = 0;
- return ReadNativeAsync(destination.Slice(n), n, cancellationToken);
- }
- }
- }
-
- private unsafe Task<int> ReadNativeAsync(Memory<byte> destination, int numBufferedBytesRead, CancellationToken cancellationToken)
- {
- AssertCanRead();
- Debug.Assert(_useAsyncIO, "ReadNativeAsync doesn't work on synchronous file streams!");
-
- // Create and store async stream class library specific data in the async result
- FileStreamCompletionSource completionSource = FileStreamCompletionSource.Create(this, numBufferedBytesRead, destination);
- NativeOverlapped* intOverlapped = completionSource.Overlapped;
-
- // Calculate position in the file we should be at after the read is done
- if (CanSeek)
- {
- long len = Length;
-
- // Make sure we are reading from the position that we think we are
- VerifyOSHandlePosition();
-
- if (_filePosition + destination.Length > len)
- {
- if (_filePosition <= len)
- {
- destination = destination.Slice(0, (int)(len - _filePosition));
- }
- else
- {
- destination = default;
- }
- }
-
- // Now set the position to read from in the NativeOverlapped struct
- // For pipes, we should leave the offset fields set to 0.
- intOverlapped->OffsetLow = unchecked((int)_filePosition);
- intOverlapped->OffsetHigh = (int)(_filePosition >> 32);
-
- // When using overlapped IO, the OS is not supposed to
- // touch the file pointer location at all. We will adjust it
- // ourselves. This isn't threadsafe.
-
- // WriteFile should not update the file pointer when writing
- // in overlapped mode, according to MSDN. But it does update
- // the file pointer when writing to a UNC path!
- // So changed the code below to seek to an absolute
- // location, not a relative one. ReadFile seems consistent though.
- SeekCore(_fileHandle, destination.Length, SeekOrigin.Current);
- }
-
- // queue an async ReadFile operation and pass in a packed overlapped
- int errorCode = 0;
- int r = ReadFileNative(_fileHandle, destination.Span, intOverlapped, out errorCode);
-
- // ReadFile, the OS version, will return 0 on failure. But
- // my ReadFileNative wrapper returns -1. My wrapper will return
- // the following:
- // On error, r==-1.
- // On async requests that are still pending, r==-1 w/ errorCode==ERROR_IO_PENDING
- // on async requests that completed sequentially, r==0
- // You will NEVER RELIABLY be able to get the number of bytes
- // read back from this call when using overlapped structures! You must
- // not pass in a non-null lpNumBytesRead to ReadFile when using
- // overlapped structures! This is by design NT behavior.
- if (r == -1)
- {
- // For pipes, when they hit EOF, they will come here.
- if (errorCode == ERROR_BROKEN_PIPE)
- {
- // Not an error, but EOF. AsyncFSCallback will NOT be
- // called. Call the user callback here.
-
- // We clear the overlapped status bit for this special case.
- // Failure to do so looks like we are freeing a pending overlapped later.
- intOverlapped->InternalLow = IntPtr.Zero;
- completionSource.SetCompletedSynchronously(0);
- }
- else if (errorCode != ERROR_IO_PENDING)
- {
- if (!_fileHandle.IsClosed && CanSeek) // Update Position - It could be anywhere.
- {
- SeekCore(_fileHandle, 0, SeekOrigin.Current);
- }
-
- completionSource.ReleaseNativeResource();
-
- if (errorCode == ERROR_HANDLE_EOF)
- {
- throw Error.GetEndOfFile();
- }
- else
- {
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, _path);
- }
- }
- else if (cancellationToken.CanBeCanceled) // ERROR_IO_PENDING
- {
- // Only once the IO is pending do we register for cancellation
- completionSource.RegisterForCancellation(cancellationToken);
- }
- }
- else
- {
- // Due to a workaround for a race condition in NT's ReadFile &
- // WriteFile routines, we will always be returning 0 from ReadFileNative
- // when we do async IO instead of the number of bytes read,
- // irregardless of whether the operation completed
- // synchronously or asynchronously. We absolutely must not
- // set asyncResult._numBytes here, since will never have correct
- // results.
- }
-
- return completionSource.Task;
- }
-
- private ValueTask WriteAsyncInternal(ReadOnlyMemory<byte> source, CancellationToken cancellationToken)
- {
- Debug.Assert(_useAsyncIO);
- Debug.Assert((_readPos == 0 && _readLength == 0 && _writePos >= 0) || (_writePos == 0 && _readPos <= _readLength), "We're either reading or writing, but not both.");
- Debug.Assert(!_isPipe || (_readPos == 0 && _readLength == 0), "Win32FileStream must not have buffered data here! Pipes should be unidirectional.");
-
- if (!CanWrite) throw Error.GetWriteNotSupported();
-
- bool writeDataStoredInBuffer = false;
- if (!_isPipe) // avoid async buffering with pipes, as doing so can lead to deadlocks (see comments in ReadInternalAsyncCore)
- {
- // Ensure the buffer is clear for writing
- if (_writePos == 0)
- {
- if (_readPos < _readLength)
- {
- FlushReadBuffer();
- }
- _readPos = 0;
- _readLength = 0;
- }
-
- // Determine how much space remains in the buffer
- int remainingBuffer = _bufferLength - _writePos;
- Debug.Assert(remainingBuffer >= 0);
-
- // Simple/common case:
- // - The write is smaller than our buffer, such that it's worth considering buffering it.
- // - There's no active flush operation, such that we don't have to worry about the existing buffer being in use.
- // - And the data we're trying to write fits in the buffer, meaning it wasn't already filled by previous writes.
- // In that case, just store it in the buffer.
- if (source.Length < _bufferLength && !HasActiveBufferOperation && source.Length <= remainingBuffer)
- {
- source.Span.CopyTo(new Span<byte>(GetBuffer(), _writePos, source.Length));
- _writePos += source.Length;
- writeDataStoredInBuffer = true;
-
- // There is one special-but-common case, common because devs often use
- // byte[] sizes that are powers of 2 and thus fit nicely into our buffer, which is
- // also a power of 2. If after our write the buffer still has remaining space,
- // then we're done and can return a completed task now. But if we filled the buffer
- // completely, we want to do the asynchronous flush/write as part of this operation
- // rather than waiting until the next write that fills the buffer.
- if (source.Length != remainingBuffer)
- return default;
-
- Debug.Assert(_writePos == _bufferLength);
- }
- }
-
- // At this point, at least one of the following is true:
- // 1. There was an active flush operation (it could have completed by now, though).
- // 2. The data doesn't fit in the remaining buffer (or it's a pipe and we chose not to try).
- // 3. We wrote all of the data to the buffer, filling it.
- //
- // If there's an active operation, we can't touch the current buffer because it's in use.
- // That gives us a choice: we can either allocate a new buffer, or we can skip the buffer
- // entirely (even if the data would otherwise fit in it). For now, for simplicity, we do
- // the latter; it could also have performance wins due to OS-level optimizations, and we could
- // potentially add support for PreAllocatedOverlapped due to having a single buffer. (We can
- // switch to allocating a new buffer, potentially experimenting with buffer pooling, should
- // performance data suggest it's appropriate.)
- //
- // If the data doesn't fit in the remaining buffer, it could be because it's so large
- // it's greater than the entire buffer size, in which case we'd always skip the buffer,
- // or it could be because there's more data than just the space remaining. For the latter
- // case, we need to issue an asynchronous write to flush that data, which then turns this into
- // the first case above with an active operation.
- //
- // If we already stored the data, then we have nothing additional to write beyond what
- // we need to flush.
- //
- // In any of these cases, we have the same outcome:
- // - If there's data in the buffer, flush it by writing it out asynchronously.
- // - Then, if there's any data to be written, issue a write for it concurrently.
- // We return a Task that represents one or both.
-
- // Flush the buffer asynchronously if there's anything to flush
- Task? flushTask = null;
- if (_writePos > 0)
- {
- flushTask = FlushWriteAsync(cancellationToken);
-
- // If we already copied all of the data into the buffer,
- // simply return the flush task here. Same goes for if the task has
- // already completed and was unsuccessful.
- if (writeDataStoredInBuffer ||
- flushTask.IsFaulted ||
- flushTask.IsCanceled)
- {
- return new ValueTask(flushTask);
- }
- }
-
- Debug.Assert(!writeDataStoredInBuffer);
- Debug.Assert(_writePos == 0);
-
- // Finally, issue the write asynchronously, and return a Task that logically
- // represents the write operation, including any flushing done.
- Task writeTask = WriteAsyncInternalCore(source, cancellationToken);
- return new ValueTask(
- (flushTask == null || flushTask.Status == TaskStatus.RanToCompletion) ? writeTask :
- (writeTask.Status == TaskStatus.RanToCompletion) ? flushTask :
- Task.WhenAll(flushTask, writeTask));
- }
-
- private unsafe Task WriteAsyncInternalCore(ReadOnlyMemory<byte> source, CancellationToken cancellationToken)
- {
- Debug.Assert(!_fileHandle.IsClosed, "!_handle.IsClosed");
- Debug.Assert(CanWrite, "_parent.CanWrite");
- Debug.Assert(_readPos == _readLength, "_readPos == _readLen");
- Debug.Assert(_useAsyncIO, "WriteInternalCoreAsync doesn't work on synchronous file streams!");
-
- // Create and store async stream class library specific data in the async result
- FileStreamCompletionSource completionSource = FileStreamCompletionSource.Create(this, 0, source);
- NativeOverlapped* intOverlapped = completionSource.Overlapped;
-
- if (CanSeek)
- {
- // Make sure we set the length of the file appropriately.
- long len = Length;
-
- // Make sure we are writing to the position that we think we are
- VerifyOSHandlePosition();
-
- if (_filePosition + source.Length > len)
- {
- SetLengthCore(_filePosition + source.Length);
- }
-
- // Now set the position to read from in the NativeOverlapped struct
- // For pipes, we should leave the offset fields set to 0.
- intOverlapped->OffsetLow = (int)_filePosition;
- intOverlapped->OffsetHigh = (int)(_filePosition >> 32);
-
- // When using overlapped IO, the OS is not supposed to
- // touch the file pointer location at all. We will adjust it
- // ourselves. This isn't threadsafe.
- SeekCore(_fileHandle, source.Length, SeekOrigin.Current);
- }
-
- int errorCode = 0;
- // queue an async WriteFile operation and pass in a packed overlapped
- int r = WriteFileNative(_fileHandle, source.Span, intOverlapped, out errorCode);
-
- // WriteFile, the OS version, will return 0 on failure. But
- // my WriteFileNative wrapper returns -1. My wrapper will return
- // the following:
- // On error, r==-1.
- // On async requests that are still pending, r==-1 w/ errorCode==ERROR_IO_PENDING
- // On async requests that completed sequentially, r==0
- // You will NEVER RELIABLY be able to get the number of bytes
- // written back from this call when using overlapped IO! You must
- // not pass in a non-null lpNumBytesWritten to WriteFile when using
- // overlapped structures! This is ByDesign NT behavior.
- if (r == -1)
- {
- // For pipes, when they are closed on the other side, they will come here.
- if (errorCode == ERROR_NO_DATA)
- {
- // Not an error, but EOF. AsyncFSCallback will NOT be called.
- // Completing TCS and return cached task allowing the GC to collect TCS.
- completionSource.SetCompletedSynchronously(0);
- return Task.CompletedTask;
- }
- else if (errorCode != ERROR_IO_PENDING)
- {
- if (!_fileHandle.IsClosed && CanSeek) // Update Position - It could be anywhere.
- {
- SeekCore(_fileHandle, 0, SeekOrigin.Current);
- }
-
- completionSource.ReleaseNativeResource();
-
- if (errorCode == ERROR_HANDLE_EOF)
- {
- throw Error.GetEndOfFile();
- }
- else
- {
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, _path);
- }
- }
- else if (cancellationToken.CanBeCanceled) // ERROR_IO_PENDING
- {
- // Only once the IO is pending do we register for cancellation
- completionSource.RegisterForCancellation(cancellationToken);
- }
- }
- else
- {
- // Due to a workaround for a race condition in NT's ReadFile &
- // WriteFile routines, we will always be returning 0 from WriteFileNative
- // when we do async IO instead of the number of bytes written,
- // irregardless of whether the operation completed
- // synchronously or asynchronously. We absolutely must not
- // set asyncResult._numBytes here, since will never have correct
- // results.
- }
-
- return completionSource.Task;
- }
-
- // Windows API definitions, from winbase.h and others
-
- internal const int GENERIC_READ = unchecked((int)0x80000000);
- private const int GENERIC_WRITE = 0x40000000;
-
- // Error codes (not HRESULTS), from winerror.h
- internal const int ERROR_BROKEN_PIPE = 109;
- internal const int ERROR_NO_DATA = 232;
- private const int ERROR_HANDLE_EOF = 38;
- private const int ERROR_INVALID_PARAMETER = 87;
- private const int ERROR_IO_PENDING = 997;
-
- // __ConsoleStream also uses this code.
- private unsafe int ReadFileNative(SafeFileHandle handle, Span<byte> bytes, NativeOverlapped* overlapped, out int errorCode)
- {
- Debug.Assert(handle != null, "handle != null");
- Debug.Assert((_useAsyncIO && overlapped != null) || (!_useAsyncIO && overlapped == null), "Async IO and overlapped parameters inconsistent in call to ReadFileNative.");
-
- int r;
- int numBytesRead = 0;
-
- fixed (byte* p = &MemoryMarshal.GetReference(bytes))
- {
- r = _useAsyncIO ?
- Interop.Kernel32.ReadFile(handle, p, bytes.Length, IntPtr.Zero, overlapped) :
- Interop.Kernel32.ReadFile(handle, p, bytes.Length, out numBytesRead, IntPtr.Zero);
- }
-
- if (r == 0)
- {
- errorCode = GetLastWin32ErrorAndDisposeHandleIfInvalid();
- return -1;
- }
- else
- {
- errorCode = 0;
- return numBytesRead;
- }
- }
-
- private unsafe int WriteFileNative(SafeFileHandle handle, ReadOnlySpan<byte> buffer, NativeOverlapped* overlapped, out int errorCode)
- {
- Debug.Assert(handle != null, "handle != null");
- Debug.Assert((_useAsyncIO && overlapped != null) || (!_useAsyncIO && overlapped == null), "Async IO and overlapped parameters inconsistent in call to WriteFileNative.");
-
- int numBytesWritten = 0;
- int r;
-
- fixed (byte* p = &MemoryMarshal.GetReference(buffer))
- {
- r = _useAsyncIO ?
- Interop.Kernel32.WriteFile(handle, p, buffer.Length, IntPtr.Zero, overlapped) :
- Interop.Kernel32.WriteFile(handle, p, buffer.Length, out numBytesWritten, IntPtr.Zero);
- }
-
- if (r == 0)
- {
- errorCode = GetLastWin32ErrorAndDisposeHandleIfInvalid();
- return -1;
- }
- else
- {
- errorCode = 0;
- return numBytesWritten;
- }
- }
-
- private int GetLastWin32ErrorAndDisposeHandleIfInvalid()
- {
- int errorCode = Marshal.GetLastWin32Error();
-
- // If ERROR_INVALID_HANDLE is returned, it doesn't suffice to set
- // the handle as invalid; the handle must also be closed.
- //
- // Marking the handle as invalid but not closing the handle
- // resulted in exceptions during finalization and locked column
- // values (due to invalid but unclosed handle) in SQL Win32FileStream
- // scenarios.
- //
- // A more mainstream scenario involves accessing a file on a
- // network share. ERROR_INVALID_HANDLE may occur because the network
- // connection was dropped and the server closed the handle. However,
- // the client side handle is still open and even valid for certain
- // operations.
- //
- // Note that _parent.Dispose doesn't throw so we don't need to special case.
- // SetHandleAsInvalid only sets _closed field to true (without
- // actually closing handle) so we don't need to call that as well.
- if (errorCode == Interop.Errors.ERROR_INVALID_HANDLE)
- {
- _fileHandle.Dispose();
- }
-
- return errorCode;
- }
-
- public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
- {
- // If we're in sync mode, just use the shared CopyToAsync implementation that does
- // typical read/write looping. We also need to take this path if this is a derived
- // instance from FileStream, as a derived type could have overridden ReadAsync, in which
- // case our custom CopyToAsync implementation isn't necessarily correct.
- if (!_useAsyncIO || GetType() != typeof(FileStream))
- {
- return base.CopyToAsync(destination, bufferSize, cancellationToken);
- }
-
- StreamHelpers.ValidateCopyToArgs(this, destination, bufferSize);
-
- // Bail early for cancellation if cancellation has been requested
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled<int>(cancellationToken);
- }
-
- // Fail if the file was closed
- if (_fileHandle.IsClosed)
- {
- throw Error.GetFileNotOpen();
- }
-
- // Do the async copy, with differing implementations based on whether the FileStream was opened as async or sync
- Debug.Assert((_readPos == 0 && _readLength == 0 && _writePos >= 0) || (_writePos == 0 && _readPos <= _readLength), "We're either reading or writing, but not both.");
- return AsyncModeCopyToAsync(destination, bufferSize, cancellationToken);
- }
-
- private async Task AsyncModeCopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
- {
- Debug.Assert(_useAsyncIO, "This implementation is for async mode only");
- Debug.Assert(!_fileHandle.IsClosed, "!_handle.IsClosed");
- Debug.Assert(CanRead, "_parent.CanRead");
-
- // Make sure any pending writes have been flushed before we do a read.
- if (_writePos > 0)
- {
- await FlushWriteAsync(cancellationToken).ConfigureAwait(false);
- }
-
- // Typically CopyToAsync would be invoked as the only "read" on the stream, but it's possible some reading is
- // done and then the CopyToAsync is issued. For that case, see if we have any data available in the buffer.
- if (GetBuffer() != null)
- {
- int bufferedBytes = _readLength - _readPos;
- if (bufferedBytes > 0)
- {
- await destination.WriteAsync(new ReadOnlyMemory<byte>(GetBuffer(), _readPos, bufferedBytes), cancellationToken).ConfigureAwait(false);
- _readPos = _readLength = 0;
- }
- }
-
- // For efficiency, we avoid creating a new task and associated state for each asynchronous read.
- // Instead, we create a single reusable awaitable object that will be triggered when an await completes
- // and reset before going again.
- var readAwaitable = new AsyncCopyToAwaitable(this);
-
- // Make sure we are reading from the position that we think we are.
- // Only set the position in the awaitable if we can seek (e.g. not for pipes).
- bool canSeek = CanSeek;
- if (canSeek)
- {
- VerifyOSHandlePosition();
- readAwaitable._position = _filePosition;
- }
-
- // Get the buffer to use for the copy operation, as the base CopyToAsync does. We don't try to use
- // _buffer here, even if it's not null, as concurrent operations are allowed, and another operation may
- // actually be using the buffer already. Plus, it'll be rare for _buffer to be non-null, as typically
- // CopyToAsync is used as the only operation performed on the stream, and the buffer is lazily initialized.
- // Further, typically the CopyToAsync buffer size will be larger than that used by the FileStream, such that
- // we'd likely be unable to use it anyway. Instead, we rent the buffer from a pool.
- byte[] copyBuffer = ArrayPool<byte>.Shared.Rent(bufferSize);
-
- // Allocate an Overlapped we can use repeatedly for all operations
- var awaitableOverlapped = new PreAllocatedOverlapped(AsyncCopyToAwaitable.s_callback, readAwaitable, copyBuffer);
- var cancellationReg = default(CancellationTokenRegistration);
- try
- {
- // Register for cancellation. We do this once for the whole copy operation, and just try to cancel
- // whatever read operation may currently be in progress, if there is one. It's possible the cancellation
- // request could come in between operations, in which case we flag that with explicit calls to ThrowIfCancellationRequested
- // in the read/write copy loop.
- if (cancellationToken.CanBeCanceled)
- {
- cancellationReg = cancellationToken.UnsafeRegister(s =>
- {
- Debug.Assert(s is AsyncCopyToAwaitable);
- var innerAwaitable = (AsyncCopyToAwaitable)s;
- unsafe
- {
- lock (innerAwaitable.CancellationLock) // synchronize with cleanup of the overlapped
- {
- if (innerAwaitable._nativeOverlapped != null)
- {
- // Try to cancel the I/O. We ignore the return value, as cancellation is opportunistic and we
- // don't want to fail the operation because we couldn't cancel it.
- Interop.Kernel32.CancelIoEx(innerAwaitable._fileStream._fileHandle, innerAwaitable._nativeOverlapped);
- }
- }
- }
- }, readAwaitable);
- }
-
- // Repeatedly read from this FileStream and write the results to the destination stream.
- while (true)
- {
- cancellationToken.ThrowIfCancellationRequested();
- readAwaitable.ResetForNextOperation();
-
- try
- {
- bool synchronousSuccess;
- int errorCode;
- unsafe
- {
- // Allocate a native overlapped for our reusable overlapped, and set position to read based on the next
- // desired address stored in the awaitable. (This position may be 0, if either we're at the beginning or
- // if the stream isn't seekable.)
- readAwaitable._nativeOverlapped = _fileHandle.ThreadPoolBinding!.AllocateNativeOverlapped(awaitableOverlapped);
- if (canSeek)
- {
- readAwaitable._nativeOverlapped->OffsetLow = unchecked((int)readAwaitable._position);
- readAwaitable._nativeOverlapped->OffsetHigh = (int)(readAwaitable._position >> 32);
- }
-
- // Kick off the read.
- synchronousSuccess = ReadFileNative(_fileHandle, copyBuffer, readAwaitable._nativeOverlapped, out errorCode) >= 0;
- }
-
- // If the operation did not synchronously succeed, it either failed or initiated the asynchronous operation.
- if (!synchronousSuccess)
- {
- switch (errorCode)
- {
- case ERROR_IO_PENDING:
- // Async operation in progress.
- break;
- case ERROR_BROKEN_PIPE:
- case ERROR_HANDLE_EOF:
- // We're at or past the end of the file, and the overlapped callback
- // won't be raised in these cases. Mark it as completed so that the await
- // below will see it as such.
- readAwaitable.MarkCompleted();
- break;
- default:
- // Everything else is an error (and there won't be a callback).
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, _path);
- }
- }
-
- // Wait for the async operation (which may or may not have already completed), then throw if it failed.
- await readAwaitable;
- switch (readAwaitable._errorCode)
- {
- case 0: // success
- break;
- case ERROR_BROKEN_PIPE: // logically success with 0 bytes read (write end of pipe closed)
- case ERROR_HANDLE_EOF: // logically success with 0 bytes read (read at end of file)
- Debug.Assert(readAwaitable._numBytes == 0, $"Expected 0 bytes read, got {readAwaitable._numBytes}");
- break;
- case Interop.Errors.ERROR_OPERATION_ABORTED: // canceled
- throw new OperationCanceledException(cancellationToken.IsCancellationRequested ? cancellationToken : new CancellationToken(true));
- default: // error
- throw Win32Marshal.GetExceptionForWin32Error((int)readAwaitable._errorCode, _path);
- }
-
- // Successful operation. If we got zero bytes, we're done: exit the read/write loop.
- int numBytesRead = (int)readAwaitable._numBytes;
- if (numBytesRead == 0)
- {
- break;
- }
-
- // Otherwise, update the read position for next time accordingly.
- if (canSeek)
- {
- readAwaitable._position += numBytesRead;
- }
- }
- finally
- {
- // Free the resources for this read operation
- unsafe
- {
- NativeOverlapped* overlapped;
- lock (readAwaitable.CancellationLock) // just an Exchange, but we need this to be synchronized with cancellation, so using the same lock
- {
- overlapped = readAwaitable._nativeOverlapped;
- readAwaitable._nativeOverlapped = null;
- }
- if (overlapped != null)
- {
- _fileHandle.ThreadPoolBinding!.FreeNativeOverlapped(overlapped);
- }
- }
- }
-
- // Write out the read data.
- await destination.WriteAsync(new ReadOnlyMemory<byte>(copyBuffer, 0, (int)readAwaitable._numBytes), cancellationToken).ConfigureAwait(false);
- }
- }
- finally
- {
- // Cleanup from the whole copy operation
- cancellationReg.Dispose();
- awaitableOverlapped.Dispose();
-
- ArrayPool<byte>.Shared.Return(copyBuffer);
-
- // Make sure the stream's current position reflects where we ended up
- if (!_fileHandle.IsClosed && CanSeek)
- {
- SeekCore(_fileHandle, 0, SeekOrigin.End);
- }
- }
- }
-
- /// <summary>Used by CopyToAsync to enable awaiting the result of an overlapped I/O operation with minimal overhead.</summary>
- private sealed unsafe class AsyncCopyToAwaitable : ICriticalNotifyCompletion
- {
- /// <summary>Sentinel object used to indicate that the I/O operation has completed before being awaited.</summary>
- private static readonly Action s_sentinel = () => { };
- /// <summary>Cached delegate to IOCallback.</summary>
- internal static readonly IOCompletionCallback s_callback = IOCallback;
-
- /// <summary>The FileStream that owns this instance.</summary>
- internal readonly FileStream _fileStream;
-
- /// <summary>Tracked position representing the next location from which to read.</summary>
- internal long _position;
- /// <summary>The current native overlapped pointer. This changes for each operation.</summary>
- internal NativeOverlapped* _nativeOverlapped;
- /// <summary>
- /// null if the operation is still in progress,
- /// s_sentinel if the I/O operation completed before the await,
- /// s_callback if it completed after the await yielded.
- /// </summary>
- internal Action? _continuation;
- /// <summary>Last error code from completed operation.</summary>
- internal uint _errorCode;
- /// <summary>Last number of read bytes from completed operation.</summary>
- internal uint _numBytes;
-
- /// <summary>Lock object used to protect cancellation-related access to _nativeOverlapped.</summary>
- internal object CancellationLock => this;
-
- /// <summary>Initialize the awaitable.</summary>
- internal AsyncCopyToAwaitable(FileStream fileStream)
- {
- _fileStream = fileStream;
- }
-
- /// <summary>Reset state to prepare for the next read operation.</summary>
- internal void ResetForNextOperation()
- {
- Debug.Assert(_position >= 0, $"Expected non-negative position, got {_position}");
- _continuation = null;
- _errorCode = 0;
- _numBytes = 0;
- }
-
- /// <summary>Overlapped callback: store the results, then invoke the continuation delegate.</summary>
- internal static void IOCallback(uint errorCode, uint numBytes, NativeOverlapped* pOVERLAP)
- {
- var awaitable = (AsyncCopyToAwaitable?)ThreadPoolBoundHandle.GetNativeOverlappedState(pOVERLAP);
- Debug.Assert(awaitable != null);
-
- Debug.Assert(!ReferenceEquals(awaitable._continuation, s_sentinel), "Sentinel must not have already been set as the continuation");
- awaitable._errorCode = errorCode;
- awaitable._numBytes = numBytes;
-
- (awaitable._continuation ?? Interlocked.CompareExchange(ref awaitable._continuation, s_sentinel, null))?.Invoke();
- }
-
- /// <summary>
- /// Called when it's known that the I/O callback for an operation will not be invoked but we'll
- /// still be awaiting the awaitable.
- /// </summary>
- internal void MarkCompleted()
- {
- Debug.Assert(_continuation == null, "Expected null continuation");
- _continuation = s_sentinel;
- }
-
- public AsyncCopyToAwaitable GetAwaiter() => this;
- public bool IsCompleted => ReferenceEquals(_continuation, s_sentinel);
- public void GetResult() { }
- public void OnCompleted(Action continuation) => UnsafeOnCompleted(continuation);
- public void UnsafeOnCompleted(Action continuation)
- {
- if (ReferenceEquals(_continuation, s_sentinel) ||
- Interlocked.CompareExchange(ref _continuation, continuation, null) != null)
- {
- Debug.Assert(ReferenceEquals(_continuation, s_sentinel), $"Expected continuation set to s_sentinel, got ${_continuation}");
- Task.Run(continuation);
- }
- }
- }
-
- private Task FlushAsyncInternal(CancellationToken cancellationToken)
- {
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled(cancellationToken);
-
- if (_fileHandle.IsClosed)
- throw Error.GetFileNotOpen();
-
- // TODO: https://github.com/dotnet/corefx/issues/32837 (stop doing this synchronous work!!).
- // The always synchronous data transfer between the OS and the internal buffer is intentional
- // because this is needed to allow concurrent async IO requests. Concurrent data transfer
- // between the OS and the internal buffer will result in race conditions. Since FlushWrite and
- // FlushRead modify internal state of the stream and transfer data between the OS and the
- // internal buffer, they cannot be truly async. We will, however, flush the OS file buffers
- // asynchronously because it doesn't modify any internal state of the stream and is potentially
- // a long running process.
- try
- {
- FlushInternalBuffer();
- }
- catch (Exception e)
- {
- return Task.FromException(e);
- }
-
- return Task.CompletedTask;
- }
-
- private void LockInternal(long position, long length)
- {
- int positionLow = unchecked((int)(position));
- int positionHigh = unchecked((int)(position >> 32));
- int lengthLow = unchecked((int)(length));
- int lengthHigh = unchecked((int)(length >> 32));
-
- if (!Interop.Kernel32.LockFile(_fileHandle, positionLow, positionHigh, lengthLow, lengthHigh))
- {
- throw Win32Marshal.GetExceptionForLastWin32Error(_path);
- }
- }
-
- private void UnlockInternal(long position, long length)
- {
- int positionLow = unchecked((int)(position));
- int positionHigh = unchecked((int)(position >> 32));
- int lengthLow = unchecked((int)(length));
- int lengthHigh = unchecked((int)(length >> 32));
-
- if (!Interop.Kernel32.UnlockFile(_fileHandle, positionLow, positionHigh, lengthLow, lengthHigh))
- {
- throw Win32Marshal.GetExceptionForLastWin32Error(_path);
- }
- }
-
- private SafeFileHandle ValidateFileHandle(SafeFileHandle fileHandle)
- {
- if (fileHandle.IsInvalid)
- {
- // Return a meaningful exception with the full path.
-
- // NT5 oddity - when trying to open "C:\" as a Win32FileStream,
- // we usually get ERROR_PATH_NOT_FOUND from the OS. We should
- // probably be consistent w/ every other directory.
- int errorCode = Marshal.GetLastWin32Error();
-
- if (errorCode == Interop.Errors.ERROR_PATH_NOT_FOUND && _path!.Length == PathInternal.GetRootLength(_path))
- errorCode = Interop.Errors.ERROR_ACCESS_DENIED;
-
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, _path);
- }
-
- fileHandle.IsAsync = _useAsyncIO;
- return fileHandle;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileStream.cs
deleted file mode 100644
index 05b97e1bcc6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileStream.cs
+++ /dev/null
@@ -1,915 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.Serialization;
-using System.Threading;
-using System.Threading.Tasks;
-using Microsoft.Win32.SafeHandles;
-
-namespace System.IO
-{
- public partial class FileStream : Stream
- {
- private const FileShare DefaultShare = FileShare.Read;
- private const bool DefaultIsAsync = false;
- internal const int DefaultBufferSize = 4096;
-
- private byte[]? _buffer;
- private int _bufferLength;
- private readonly SafeFileHandle _fileHandle; // only ever null if ctor throws
-
- /// <summary>Whether the file is opened for reading, writing, or both.</summary>
- private readonly FileAccess _access;
-
- /// <summary>The path to the opened file.</summary>
- private readonly string? _path;
-
- /// <summary>The next available byte to be read from the _buffer.</summary>
- private int _readPos;
-
- /// <summary>The number of valid bytes in _buffer.</summary>
- private int _readLength;
-
- /// <summary>The next location in which a write should occur to the buffer.</summary>
- private int _writePos;
-
- /// <summary>
- /// Whether asynchronous read/write/flush operations should be performed using async I/O.
- /// On Windows FileOptions.Asynchronous controls how the file handle is configured,
- /// and then as a result how operations are issued against that file handle. On Unix,
- /// there isn't any distinction around how file descriptors are created for async vs
- /// sync, but we still differentiate how the operations are issued in order to provide
- /// similar behavioral semantics and performance characteristics as on Windows. On
- /// Windows, if non-async, async read/write requests just delegate to the base stream,
- /// and no attempt is made to synchronize between sync and async operations on the stream;
- /// if async, then async read/write requests are implemented specially, and sync read/write
- /// requests are coordinated with async ones by implementing the sync ones over the async
- /// ones. On Unix, we do something similar. If non-async, async read/write requests just
- /// delegate to the base stream, and no attempt is made to synchronize. If async, we use
- /// a semaphore to coordinate both sync and async operations.
- /// </summary>
- private readonly bool _useAsyncIO;
-
- /// <summary>cached task for read ops that complete synchronously</summary>
- private Task<int>? _lastSynchronouslyCompletedTask = null;
-
- /// <summary>
- /// Currently cached position in the stream. This should always mirror the underlying file's actual position,
- /// and should only ever be out of sync if another stream with access to this same file manipulates it, at which
- /// point we attempt to error out.
- /// </summary>
- private long _filePosition;
-
- /// <summary>Whether the file stream's handle has been exposed.</summary>
- private bool _exposedHandle;
-
- /// <summary>Caches whether Serialization Guard has been disabled for file writes</summary>
- private static int s_cachedSerializationSwitch = 0;
-
- [Obsolete("This constructor has been deprecated. Please use new FileStream(SafeFileHandle handle, FileAccess access) instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- public FileStream(IntPtr handle, FileAccess access)
- : this(handle, access, true, DefaultBufferSize, false)
- {
- }
-
- [Obsolete("This constructor has been deprecated. Please use new FileStream(SafeFileHandle handle, FileAccess access) instead, and optionally make a new SafeFileHandle with ownsHandle=false if needed. https://go.microsoft.com/fwlink/?linkid=14202")]
- public FileStream(IntPtr handle, FileAccess access, bool ownsHandle)
- : this(handle, access, ownsHandle, DefaultBufferSize, false)
- {
- }
-
- [Obsolete("This constructor has been deprecated. Please use new FileStream(SafeFileHandle handle, FileAccess access, int bufferSize) instead, and optionally make a new SafeFileHandle with ownsHandle=false if needed. https://go.microsoft.com/fwlink/?linkid=14202")]
- public FileStream(IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize)
- : this(handle, access, ownsHandle, bufferSize, false)
- {
- }
-
- [Obsolete("This constructor has been deprecated. Please use new FileStream(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync) instead, and optionally make a new SafeFileHandle with ownsHandle=false if needed. https://go.microsoft.com/fwlink/?linkid=14202")]
- public FileStream(IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync)
- {
- SafeFileHandle safeHandle = new SafeFileHandle(handle, ownsHandle: ownsHandle);
- try
- {
- ValidateAndInitFromHandle(safeHandle, access, bufferSize, isAsync);
- }
- catch
- {
- // We don't want to take ownership of closing passed in handles
- // *unless* the constructor completes successfully.
- GC.SuppressFinalize(safeHandle);
-
- // This would also prevent Close from being called, but is unnecessary
- // as we've removed the object from the finalizer queue.
- //
- // safeHandle.SetHandleAsInvalid();
- throw;
- }
-
- // Note: Cleaner to set the following fields in ValidateAndInitFromHandle,
- // but we can't as they're readonly.
- _access = access;
- _useAsyncIO = isAsync;
-
- // As the handle was passed in, we must set the handle field at the very end to
- // avoid the finalizer closing the handle when we throw errors.
- _fileHandle = safeHandle;
- }
-
- public FileStream(SafeFileHandle handle, FileAccess access)
- : this(handle, access, DefaultBufferSize)
- {
- }
-
- public FileStream(SafeFileHandle handle, FileAccess access, int bufferSize)
- : this(handle, access, bufferSize, GetDefaultIsAsync(handle))
- {
- }
-
- private void ValidateAndInitFromHandle(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync)
- {
- if (handle.IsInvalid)
- throw new ArgumentException(SR.Arg_InvalidHandle, nameof(handle));
-
- if (access < FileAccess.Read || access > FileAccess.ReadWrite)
- throw new ArgumentOutOfRangeException(nameof(access), SR.ArgumentOutOfRange_Enum);
- if (bufferSize <= 0)
- throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
-
- if (handle.IsClosed)
- throw new ObjectDisposedException(SR.ObjectDisposed_FileClosed);
- if (handle.IsAsync.HasValue && isAsync != handle.IsAsync.GetValueOrDefault())
- throw new ArgumentException(SR.Arg_HandleNotAsync, nameof(handle));
-
- _exposedHandle = true;
- _bufferLength = bufferSize;
-
- InitFromHandle(handle, access, isAsync);
- }
-
- public FileStream(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync)
- {
- ValidateAndInitFromHandle(handle, access, bufferSize, isAsync);
-
- // Note: Cleaner to set the following fields in ValidateAndInitFromHandle,
- // but we can't as they're readonly.
- _access = access;
- _useAsyncIO = isAsync;
-
- // As the handle was passed in, we must set the handle field at the very end to
- // avoid the finalizer closing the handle when we throw errors.
- _fileHandle = handle;
- }
-
- public FileStream(string path, FileMode mode) :
- this(path, mode, mode == FileMode.Append ? FileAccess.Write : FileAccess.ReadWrite, DefaultShare, DefaultBufferSize, DefaultIsAsync)
- { }
-
- public FileStream(string path, FileMode mode, FileAccess access) :
- this(path, mode, access, DefaultShare, DefaultBufferSize, DefaultIsAsync)
- { }
-
- public FileStream(string path, FileMode mode, FileAccess access, FileShare share) :
- this(path, mode, access, share, DefaultBufferSize, DefaultIsAsync)
- { }
-
- public FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize) :
- this(path, mode, access, share, bufferSize, DefaultIsAsync)
- { }
-
- public FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync) :
- this(path, mode, access, share, bufferSize, useAsync ? FileOptions.Asynchronous : FileOptions.None)
- { }
-
- public FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options)
- {
- if (path == null)
- throw new ArgumentNullException(nameof(path), SR.ArgumentNull_Path);
- if (path.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyPath, nameof(path));
-
- // don't include inheritable in our bounds check for share
- FileShare tempshare = share & ~FileShare.Inheritable;
- string? badArg = null;
-
- if (mode < FileMode.CreateNew || mode > FileMode.Append)
- badArg = nameof(mode);
- else if (access < FileAccess.Read || access > FileAccess.ReadWrite)
- badArg = nameof(access);
- else if (tempshare < FileShare.None || tempshare > (FileShare.ReadWrite | FileShare.Delete))
- badArg = nameof(share);
-
- if (badArg != null)
- throw new ArgumentOutOfRangeException(badArg, SR.ArgumentOutOfRange_Enum);
-
- // NOTE: any change to FileOptions enum needs to be matched here in the error validation
- if (options != FileOptions.None && (options & ~(FileOptions.WriteThrough | FileOptions.Asynchronous | FileOptions.RandomAccess | FileOptions.DeleteOnClose | FileOptions.SequentialScan | FileOptions.Encrypted | (FileOptions)0x20000000 /* NoBuffering */)) != 0)
- throw new ArgumentOutOfRangeException(nameof(options), SR.ArgumentOutOfRange_Enum);
-
- if (bufferSize <= 0)
- throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
-
- // Write access validation
- if ((access & FileAccess.Write) == 0)
- {
- if (mode == FileMode.Truncate || mode == FileMode.CreateNew || mode == FileMode.Create || mode == FileMode.Append)
- {
- // No write access, mode and access disagree but flag access since mode comes first
- throw new ArgumentException(SR.Format(SR.Argument_InvalidFileModeAndAccessCombo, mode, access), nameof(access));
- }
- }
-
- if ((access & FileAccess.Read) != 0 && mode == FileMode.Append)
- throw new ArgumentException(SR.Argument_InvalidAppendMode, nameof(access));
-
- string fullPath = Path.GetFullPath(path);
-
- _path = fullPath;
- _access = access;
- _bufferLength = bufferSize;
-
- if ((options & FileOptions.Asynchronous) != 0)
- _useAsyncIO = true;
-
- if ((access & FileAccess.Write) == FileAccess.Write)
- {
- SerializationInfo.ThrowIfDeserializationInProgress("AllowFileWrites", ref s_cachedSerializationSwitch);
- }
-
- _fileHandle = OpenHandle(mode, share, options);
-
- try
- {
- Init(mode, share, path);
- }
- catch
- {
- // If anything goes wrong while setting up the stream, make sure we deterministically dispose
- // of the opened handle.
- _fileHandle.Dispose();
- _fileHandle = null!;
- throw;
- }
- }
-
- [Obsolete("This property has been deprecated. Please use FileStream's SafeFileHandle property instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- public virtual IntPtr Handle => SafeFileHandle.DangerousGetHandle();
-
- public virtual void Lock(long position, long length)
- {
- if (position < 0 || length < 0)
- {
- throw new ArgumentOutOfRangeException(position < 0 ? nameof(position) : nameof(length), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (_fileHandle.IsClosed)
- {
- throw Error.GetFileNotOpen();
- }
-
- LockInternal(position, length);
- }
-
- public virtual void Unlock(long position, long length)
- {
- if (position < 0 || length < 0)
- {
- throw new ArgumentOutOfRangeException(position < 0 ? nameof(position) : nameof(length), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (_fileHandle.IsClosed)
- {
- throw Error.GetFileNotOpen();
- }
-
- UnlockInternal(position, length);
- }
-
- public override Task FlushAsync(CancellationToken cancellationToken)
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Flush() which a subclass might have overridden. To be safe
- // we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Flush) when we are not sure.
- if (GetType() != typeof(FileStream))
- return base.FlushAsync(cancellationToken);
-
- return FlushAsyncInternal(cancellationToken);
- }
-
- public override int Read(byte[] array, int offset, int count)
- {
- ValidateReadWriteArgs(array, offset, count);
- return _useAsyncIO ?
- ReadAsyncTask(array, offset, count, CancellationToken.None).GetAwaiter().GetResult() :
- ReadSpan(new Span<byte>(array, offset, count));
- }
-
- public override int Read(Span<byte> buffer)
- {
- if (GetType() == typeof(FileStream) && !_useAsyncIO)
- {
- if (_fileHandle.IsClosed)
- {
- throw Error.GetFileNotOpen();
- }
- return ReadSpan(buffer);
- }
- else
- {
- // This type is derived from FileStream and/or the stream is in async mode. If this is a
- // derived type, it may have overridden Read(byte[], int, int) prior to this Read(Span<byte>)
- // overload being introduced. In that case, this Read(Span<byte>) overload should use the behavior
- // of Read(byte[],int,int) overload. Or if the stream is in async mode, we can't call the
- // synchronous ReadSpan, so we similarly call the base Read, which will turn delegate to
- // Read(byte[],int,int), which will do the right thing if we're in async mode.
- return base.Read(buffer);
- }
- }
-
- public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - offset < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen /*, no good single parameter name to pass*/);
-
- if (GetType() != typeof(FileStream))
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Read() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Read/ReadAsync) when we are not sure.
- return base.ReadAsync(buffer, offset, count, cancellationToken);
- }
-
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled<int>(cancellationToken);
-
- if (IsClosed)
- throw Error.GetFileNotOpen();
-
- if (!_useAsyncIO)
- {
- // If we weren't opened for asynchronous I/O, we still call to the base implementation so that
- // Read is invoked asynchronously. But we can do so using the base Stream's internal helper
- // that bypasses delegating to BeginRead, since we already know this is FileStream rather
- // than something derived from it and what our BeginRead implementation is going to do.
- return (Task<int>)base.BeginReadInternal(buffer, offset, count, null, null, serializeAsynchronously: true, apm: false);
- }
-
- return ReadAsyncTask(buffer, offset, count, cancellationToken);
- }
-
- public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
- {
- if (GetType() != typeof(FileStream))
- {
- // If this isn't a concrete FileStream, a derived type may have overridden ReadAsync(byte[],...),
- // which was introduced first, so delegate to the base which will delegate to that.
- return base.ReadAsync(buffer, cancellationToken);
- }
-
- if (cancellationToken.IsCancellationRequested)
- {
- return new ValueTask<int>(Task.FromCanceled<int>(cancellationToken));
- }
-
- if (IsClosed)
- {
- throw Error.GetFileNotOpen();
- }
-
- if (!_useAsyncIO)
- {
- // If we weren't opened for asynchronous I/O, we still call to the base implementation so that
- // Read is invoked asynchronously. But if we have a byte[], we can do so using the base Stream's
- // internal helper that bypasses delegating to BeginRead, since we already know this is FileStream
- // rather than something derived from it and what our BeginRead implementation is going to do.
- return MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> segment) ?
- new ValueTask<int>((Task<int>)base.BeginReadInternal(segment.Array!, segment.Offset, segment.Count, null, null, serializeAsynchronously: true, apm: false)) :
- base.ReadAsync(buffer, cancellationToken);
- }
-
- Task<int>? t = ReadAsyncInternal(buffer, cancellationToken, out int synchronousResult);
- return t != null ?
- new ValueTask<int>(t) :
- new ValueTask<int>(synchronousResult);
- }
-
- private Task<int> ReadAsyncTask(byte[] array, int offset, int count, CancellationToken cancellationToken)
- {
- Task<int>? t = ReadAsyncInternal(new Memory<byte>(array, offset, count), cancellationToken, out int synchronousResult);
-
- if (t == null)
- {
- t = _lastSynchronouslyCompletedTask;
- Debug.Assert(t == null || t.IsCompletedSuccessfully, "Cached task should have completed successfully");
-
- if (t == null || t.Result != synchronousResult)
- {
- _lastSynchronouslyCompletedTask = t = Task.FromResult(synchronousResult);
- }
- }
-
- return t;
- }
-
- public override void Write(byte[] array, int offset, int count)
- {
- ValidateReadWriteArgs(array, offset, count);
- if (_useAsyncIO)
- {
- WriteAsyncInternal(new ReadOnlyMemory<byte>(array, offset, count), CancellationToken.None).GetAwaiter().GetResult();
- }
- else
- {
- WriteSpan(new ReadOnlySpan<byte>(array, offset, count));
- }
- }
-
- public override void Write(ReadOnlySpan<byte> buffer)
- {
- if (GetType() == typeof(FileStream) && !_useAsyncIO)
- {
- if (_fileHandle.IsClosed)
- {
- throw Error.GetFileNotOpen();
- }
- WriteSpan(buffer);
- }
- else
- {
- // This type is derived from FileStream and/or the stream is in async mode. If this is a
- // derived type, it may have overridden Write(byte[], int, int) prior to this Write(ReadOnlySpan<byte>)
- // overload being introduced. In that case, this Write(ReadOnlySpan<byte>) overload should use the behavior
- // of Write(byte[],int,int) overload. Or if the stream is in async mode, we can't call the
- // synchronous WriteSpan, so we similarly call the base Write, which will turn delegate to
- // Write(byte[],int,int), which will do the right thing if we're in async mode.
- base.Write(buffer);
- }
- }
-
- public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - offset < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen /*, no good single parameter name to pass*/);
-
- if (GetType() != typeof(FileStream))
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Write() or WriteAsync() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Write/WriteAsync) when we are not sure.
- return base.WriteAsync(buffer, offset, count, cancellationToken);
- }
-
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled(cancellationToken);
-
- if (IsClosed)
- throw Error.GetFileNotOpen();
-
- if (!_useAsyncIO)
- {
- // If we weren't opened for asynchronous I/O, we still call to the base implementation so that
- // Write is invoked asynchronously. But we can do so using the base Stream's internal helper
- // that bypasses delegating to BeginWrite, since we already know this is FileStream rather
- // than something derived from it and what our BeginWrite implementation is going to do.
- return (Task)base.BeginWriteInternal(buffer, offset, count, null, null, serializeAsynchronously: true, apm: false);
- }
-
- return WriteAsyncInternal(new ReadOnlyMemory<byte>(buffer, offset, count), cancellationToken).AsTask();
- }
-
- public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
- {
- if (GetType() != typeof(FileStream))
- {
- // If this isn't a concrete FileStream, a derived type may have overridden WriteAsync(byte[],...),
- // which was introduced first, so delegate to the base which will delegate to that.
- return base.WriteAsync(buffer, cancellationToken);
- }
-
- if (cancellationToken.IsCancellationRequested)
- {
- return new ValueTask(Task.FromCanceled<int>(cancellationToken));
- }
-
- if (IsClosed)
- {
- throw Error.GetFileNotOpen();
- }
-
- if (!_useAsyncIO)
- {
- // If we weren't opened for asynchronous I/O, we still call to the base implementation so that
- // Write is invoked asynchronously. But if we have a byte[], we can do so using the base Stream's
- // internal helper that bypasses delegating to BeginWrite, since we already know this is FileStream
- // rather than something derived from it and what our BeginWrite implementation is going to do.
- return MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> segment) ?
- new ValueTask((Task)BeginWriteInternal(segment.Array!, segment.Offset, segment.Count, null, null, serializeAsynchronously: true, apm: false)) :
- base.WriteAsync(buffer, cancellationToken);
- }
-
- return WriteAsyncInternal(buffer, cancellationToken);
- }
-
- /// <summary>
- /// Clears buffers for this stream and causes any buffered data to be written to the file.
- /// </summary>
- public override void Flush()
- {
- // Make sure that we call through the public virtual API
- Flush(flushToDisk: false);
- }
-
- /// <summary>
- /// Clears buffers for this stream, and if <param name="flushToDisk"/> is true,
- /// causes any buffered data to be written to the file.
- /// </summary>
- public virtual void Flush(bool flushToDisk)
- {
- if (IsClosed) throw Error.GetFileNotOpen();
-
- FlushInternalBuffer();
-
- if (flushToDisk && CanWrite)
- {
- FlushOSBuffer();
- }
- }
-
- /// <summary>Gets a value indicating whether the current stream supports reading.</summary>
- public override bool CanRead => !_fileHandle.IsClosed && (_access & FileAccess.Read) != 0;
-
- /// <summary>Gets a value indicating whether the current stream supports writing.</summary>
- public override bool CanWrite => !_fileHandle.IsClosed && (_access & FileAccess.Write) != 0;
-
- /// <summary>Validates arguments to Read and Write and throws resulting exceptions.</summary>
- /// <param name="array">The buffer to read from or write to.</param>
- /// <param name="offset">The zero-based offset into the array.</param>
- /// <param name="count">The maximum number of bytes to read or write.</param>
- private void ValidateReadWriteArgs(byte[] array, int offset, int count)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array), SR.ArgumentNull_Buffer);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - offset < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen /*, no good single parameter name to pass*/);
- if (_fileHandle.IsClosed)
- throw Error.GetFileNotOpen();
- }
-
- /// <summary>Sets the length of this stream to the given value.</summary>
- /// <param name="value">The new length of the stream.</param>
- public override void SetLength(long value)
- {
- if (value < 0)
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_fileHandle.IsClosed)
- throw Error.GetFileNotOpen();
- if (!CanSeek)
- throw Error.GetSeekNotSupported();
- if (!CanWrite)
- throw Error.GetWriteNotSupported();
-
- SetLengthInternal(value);
- }
-
- public virtual SafeFileHandle SafeFileHandle
- {
- get
- {
- Flush();
- _exposedHandle = true;
- return _fileHandle;
- }
- }
-
- /// <summary>Gets the path that was passed to the constructor.</summary>
- public virtual string Name => _path ?? SR.IO_UnknownFileName;
-
- /// <summary>Gets a value indicating whether the stream was opened for I/O to be performed synchronously or asynchronously.</summary>
- public virtual bool IsAsync => _useAsyncIO;
-
- /// <summary>Gets the length of the stream in bytes.</summary>
- public override long Length
- {
- get
- {
- if (_fileHandle.IsClosed) throw Error.GetFileNotOpen();
- if (!CanSeek) throw Error.GetSeekNotSupported();
- return GetLengthInternal();
- }
- }
-
- /// <summary>
- /// Verify that the actual position of the OS's handle equals what we expect it to.
- /// This will fail if someone else moved the UnixFileStream's handle or if
- /// our position updating code is incorrect.
- /// </summary>
- private void VerifyOSHandlePosition()
- {
- bool verifyPosition = _exposedHandle; // in release, only verify if we've given out the handle such that someone else could be manipulating it
-#if DEBUG
- verifyPosition = true; // in debug, always make sure our position matches what the OS says it should be
-#endif
- if (verifyPosition && CanSeek)
- {
- long oldPos = _filePosition; // SeekCore will override the current _position, so save it now
- long curPos = SeekCore(_fileHandle, 0, SeekOrigin.Current);
- if (oldPos != curPos)
- {
- // For reads, this is non-fatal but we still could have returned corrupted
- // data in some cases, so discard the internal buffer. For writes,
- // this is a problem; discard the buffer and error out.
- _readPos = _readLength = 0;
- if (_writePos > 0)
- {
- _writePos = 0;
- throw new IOException(SR.IO_FileStreamHandlePosition);
- }
- }
- }
- }
-
- /// <summary>Verifies that state relating to the read/write buffer is consistent.</summary>
- [Conditional("DEBUG")]
- private void AssertBufferInvariants()
- {
- // Read buffer values must be in range: 0 <= _bufferReadPos <= _bufferReadLength <= _bufferLength
- Debug.Assert(0 <= _readPos && _readPos <= _readLength && _readLength <= _bufferLength);
-
- // Write buffer values must be in range: 0 <= _bufferWritePos <= _bufferLength
- Debug.Assert(0 <= _writePos && _writePos <= _bufferLength);
-
- // Read buffering and write buffering can't both be active
- Debug.Assert((_readPos == 0 && _readLength == 0) || _writePos == 0);
- }
-
- /// <summary>Validates that we're ready to read from the stream.</summary>
- private void PrepareForReading()
- {
- if (_fileHandle.IsClosed)
- throw Error.GetFileNotOpen();
- if (_readLength == 0 && !CanRead)
- throw Error.GetReadNotSupported();
-
- AssertBufferInvariants();
- }
-
- /// <summary>Gets or sets the position within the current stream</summary>
- public override long Position
- {
- get
- {
- if (_fileHandle.IsClosed)
- throw Error.GetFileNotOpen();
-
- if (!CanSeek)
- throw Error.GetSeekNotSupported();
-
- AssertBufferInvariants();
- VerifyOSHandlePosition();
-
- // We may have read data into our buffer from the handle, such that the handle position
- // is artificially further along than the consumer's view of the stream's position.
- // Thus, when reading, our position is really starting from the handle position negatively
- // offset by the number of bytes in the buffer and positively offset by the number of
- // bytes into that buffer we've read. When writing, both the read length and position
- // must be zero, and our position is just the handle position offset positive by how many
- // bytes we've written into the buffer.
- return (_filePosition - _readLength) + _readPos + _writePos;
- }
- set
- {
- if (value < 0)
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- Seek(value, SeekOrigin.Begin);
- }
- }
-
- internal virtual bool IsClosed => _fileHandle.IsClosed;
-
- private static bool IsIoRelatedException(Exception e) =>
- // These all derive from IOException
- // DirectoryNotFoundException
- // DriveNotFoundException
- // EndOfStreamException
- // FileLoadException
- // FileNotFoundException
- // PathTooLongException
- // PipeException
- e is IOException ||
- // Note that SecurityException is only thrown on runtimes that support CAS
- // e is SecurityException ||
- e is UnauthorizedAccessException ||
- e is NotSupportedException ||
- (e is ArgumentException && !(e is ArgumentNullException));
-
- /// <summary>
- /// Gets the array used for buffering reading and writing.
- /// If the array hasn't been allocated, this will lazily allocate it.
- /// </summary>
- /// <returns>The buffer.</returns>
- private byte[] GetBuffer()
- {
- Debug.Assert(_buffer == null || _buffer.Length == _bufferLength);
- if (_buffer == null)
- {
- _buffer = new byte[_bufferLength];
- OnBufferAllocated();
- }
-
- return _buffer;
- }
-
- partial void OnBufferAllocated();
-
- /// <summary>
- /// Flushes the internal read/write buffer for this stream. If write data has been buffered,
- /// that data is written out to the underlying file. Or if data has been buffered for
- /// reading from the stream, the data is dumped and our position in the underlying file
- /// is rewound as necessary. This does not flush the OS buffer.
- /// </summary>
- private void FlushInternalBuffer()
- {
- AssertBufferInvariants();
- if (_writePos > 0)
- {
- FlushWriteBuffer();
- }
- else if (_readPos < _readLength && CanSeek)
- {
- FlushReadBuffer();
- }
- }
-
- /// <summary>Dumps any read data in the buffer and rewinds our position in the stream, accordingly, as necessary.</summary>
- private void FlushReadBuffer()
- {
- // Reading is done by blocks from the file, but someone could read
- // 1 byte from the buffer then write. At that point, the OS's file
- // pointer is out of sync with the stream's position. All write
- // functions should call this function to preserve the position in the file.
-
- AssertBufferInvariants();
- Debug.Assert(_writePos == 0, "FileStream: Write buffer must be empty in FlushReadBuffer!");
-
- int rewind = _readPos - _readLength;
- if (rewind != 0)
- {
- Debug.Assert(CanSeek, "FileStream will lose buffered read data now.");
- SeekCore(_fileHandle, rewind, SeekOrigin.Current);
- }
- _readPos = _readLength = 0;
- }
-
- /// <summary>
- /// Reads a byte from the file stream. Returns the byte cast to an int
- /// or -1 if reading from the end of the stream.
- /// </summary>
- public override int ReadByte()
- {
- PrepareForReading();
-
- byte[] buffer = GetBuffer();
- if (_readPos == _readLength)
- {
- FlushWriteBuffer();
- _readLength = FillReadBufferForReadByte();
- _readPos = 0;
- if (_readLength == 0)
- {
- return -1;
- }
- }
-
- return buffer[_readPos++];
- }
-
- /// <summary>
- /// Writes a byte to the current position in the stream and advances the position
- /// within the stream by one byte.
- /// </summary>
- /// <param name="value">The byte to write to the stream.</param>
- public override void WriteByte(byte value)
- {
- PrepareForWriting();
-
- // Flush the write buffer if it's full
- if (_writePos == _bufferLength)
- FlushWriteBufferForWriteByte();
-
- // We now have space in the buffer. Store the byte.
- GetBuffer()[_writePos++] = value;
- }
-
- /// <summary>
- /// Validates that we're ready to write to the stream,
- /// including flushing a read buffer if necessary.
- /// </summary>
- private void PrepareForWriting()
- {
- if (_fileHandle.IsClosed)
- throw Error.GetFileNotOpen();
-
- // Make sure we're good to write. We only need to do this if there's nothing already
- // in our write buffer, since if there is something in the buffer, we've already done
- // this checking and flushing.
- if (_writePos == 0)
- {
- if (!CanWrite) throw Error.GetWriteNotSupported();
- FlushReadBuffer();
- Debug.Assert(_bufferLength > 0, "_bufferSize > 0");
- }
- }
-
- ~FileStream()
- {
- // Preserved for compatibility since FileStream has defined a
- // finalizer in past releases and derived classes may depend
- // on Dispose(false) call.
- Dispose(false);
- }
-
- public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback callback, object? state)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (numBytes < 0)
- throw new ArgumentOutOfRangeException(nameof(numBytes), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - offset < numBytes)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- if (IsClosed) throw new ObjectDisposedException(SR.ObjectDisposed_FileClosed);
- if (!CanRead) throw new NotSupportedException(SR.NotSupported_UnreadableStream);
-
- if (!IsAsync)
- return base.BeginRead(array, offset, numBytes, callback, state);
- else
- return TaskToApm.Begin(ReadAsyncTask(array, offset, numBytes, CancellationToken.None), callback, state);
- }
-
- public override IAsyncResult BeginWrite(byte[] array, int offset, int numBytes, AsyncCallback callback, object? state)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (numBytes < 0)
- throw new ArgumentOutOfRangeException(nameof(numBytes), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - offset < numBytes)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- if (IsClosed) throw new ObjectDisposedException(SR.ObjectDisposed_FileClosed);
- if (!CanWrite) throw new NotSupportedException(SR.NotSupported_UnwritableStream);
-
- if (!IsAsync)
- return base.BeginWrite(array, offset, numBytes, callback, state);
- else
- return TaskToApm.Begin(WriteAsyncInternal(new ReadOnlyMemory<byte>(array, offset, numBytes), CancellationToken.None).AsTask(), callback, state);
- }
-
- public override int EndRead(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- throw new ArgumentNullException(nameof(asyncResult));
-
- if (!IsAsync)
- return base.EndRead(asyncResult);
- else
- return TaskToApm.End<int>(asyncResult);
- }
-
- public override void EndWrite(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- throw new ArgumentNullException(nameof(asyncResult));
-
- if (!IsAsync)
- base.EndWrite(asyncResult);
- else
- TaskToApm.End(asyncResult);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs b/netcore/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs
deleted file mode 100644
index 7345afec3f1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs
+++ /dev/null
@@ -1,259 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.ExceptionServices;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.IO
-{
- public partial class FileStream : Stream
- {
- // This is an internal object extending TaskCompletionSource with fields
- // for all of the relevant data necessary to complete the IO operation.
- // This is used by IOCallback and all of the async methods.
- private unsafe class FileStreamCompletionSource : TaskCompletionSource<int>
- {
- private const long NoResult = 0;
- private const long ResultSuccess = (long)1 << 32;
- private const long ResultError = (long)2 << 32;
- private const long RegisteringCancellation = (long)4 << 32;
- private const long CompletedCallback = (long)8 << 32;
- private const ulong ResultMask = ((ulong)uint.MaxValue) << 32;
-
- private static Action<object?>? s_cancelCallback;
-
- private readonly FileStream _stream;
- private readonly int _numBufferedBytes;
- private CancellationTokenRegistration _cancellationRegistration;
-#if DEBUG
- private bool _cancellationHasBeenRegistered;
-#endif
- private NativeOverlapped* _overlapped; // Overlapped class responsible for operations in progress when an appdomain unload occurs
- private long _result; // Using long since this needs to be used in Interlocked APIs
-
- // Using RunContinuationsAsynchronously for compat reasons (old API used Task.Factory.StartNew for continuations)
- protected FileStreamCompletionSource(FileStream stream, int numBufferedBytes, byte[]? bytes)
- : base(TaskCreationOptions.RunContinuationsAsynchronously)
- {
- _numBufferedBytes = numBufferedBytes;
- _stream = stream;
- _result = NoResult;
-
- // Create the native overlapped. We try to use the preallocated overlapped if possible: it's possible if the byte
- // buffer is null (there's nothing to pin) or the same one that's associated with the preallocated overlapped (and
- // thus is already pinned) and if no one else is currently using the preallocated overlapped. This is the fast-path
- // for cases where the user-provided buffer is smaller than the FileStream's buffer (such that the FileStream's
- // buffer is used) and where operations on the FileStream are not being performed concurrently.
- Debug.Assert(bytes == null || ReferenceEquals(bytes, _stream._buffer));
-
- // The _preallocatedOverlapped is null if the internal buffer was never created, so we check for
- // a non-null bytes before using the stream's _preallocatedOverlapped
- _overlapped = bytes != null && _stream.CompareExchangeCurrentOverlappedOwner(this, null) == null ?
- _stream._fileHandle.ThreadPoolBinding!.AllocateNativeOverlapped(_stream._preallocatedOverlapped!) : // allocated when buffer was created, and buffer is non-null
- _stream._fileHandle.ThreadPoolBinding!.AllocateNativeOverlapped(s_ioCallback, this, bytes);
- Debug.Assert(_overlapped != null, "AllocateNativeOverlapped returned null");
- }
-
- internal NativeOverlapped* Overlapped => _overlapped;
-
- public void SetCompletedSynchronously(int numBytes)
- {
- ReleaseNativeResource();
- TrySetResult(numBytes + _numBufferedBytes);
- }
-
- public void RegisterForCancellation(CancellationToken cancellationToken)
- {
-#if DEBUG
- Debug.Assert(cancellationToken.CanBeCanceled);
- Debug.Assert(!_cancellationHasBeenRegistered, "Cannot register for cancellation twice");
- _cancellationHasBeenRegistered = true;
-#endif
-
- // Quick check to make sure the IO hasn't completed
- if (_overlapped != null)
- {
- Action<object?>? cancelCallback = s_cancelCallback ??= Cancel;
-
- // Register the cancellation only if the IO hasn't completed
- long packedResult = Interlocked.CompareExchange(ref _result, RegisteringCancellation, NoResult);
- if (packedResult == NoResult)
- {
- _cancellationRegistration = cancellationToken.UnsafeRegister(cancelCallback, this);
-
- // Switch the result, just in case IO completed while we were setting the registration
- packedResult = Interlocked.Exchange(ref _result, NoResult);
- }
- else if (packedResult != CompletedCallback)
- {
- // Failed to set the result, IO is in the process of completing
- // Attempt to take the packed result
- packedResult = Interlocked.Exchange(ref _result, NoResult);
- }
-
- // If we have a callback that needs to be completed
- if ((packedResult != NoResult) && (packedResult != CompletedCallback) && (packedResult != RegisteringCancellation))
- {
- CompleteCallback((ulong)packedResult);
- }
- }
- }
-
- internal virtual void ReleaseNativeResource()
- {
- // Ensure that cancellation has been completed and cleaned up.
- _cancellationRegistration.Dispose();
-
- // Free the overlapped.
- // NOTE: The cancellation must *NOT* be running at this point, or it may observe freed memory
- // (this is why we disposed the registration above).
- if (_overlapped != null)
- {
- _stream._fileHandle.ThreadPoolBinding!.FreeNativeOverlapped(_overlapped);
- _overlapped = null;
- }
-
- // Ensure we're no longer set as the current completion source (we may not have been to begin with).
- // Only one operation at a time is eligible to use the preallocated overlapped,
- _stream.CompareExchangeCurrentOverlappedOwner(null, this);
- }
-
- // When doing IO asynchronously (i.e. _isAsync==true), this callback is
- // called by a free thread in the threadpool when the IO operation
- // completes.
- internal static void IOCallback(uint errorCode, uint numBytes, NativeOverlapped* pOverlapped)
- {
- // Extract the completion source from the overlapped. The state in the overlapped
- // will either be a FileStream (in the case where the preallocated overlapped was used),
- // in which case the operation being completed is its _currentOverlappedOwner, or it'll
- // be directly the FileStreamCompletionSource that's completing (in the case where the preallocated
- // overlapped was already in use by another operation).
- object? state = ThreadPoolBoundHandle.GetNativeOverlappedState(pOverlapped);
- Debug.Assert(state is FileStream || state is FileStreamCompletionSource);
- FileStreamCompletionSource completionSource = state is FileStream fs ?
- fs._currentOverlappedOwner! : // must be owned
- (FileStreamCompletionSource)state!;
- Debug.Assert(completionSource != null);
- Debug.Assert(completionSource._overlapped == pOverlapped, "Overlaps don't match");
-
- // Handle reading from & writing to closed pipes. While I'm not sure
- // this is entirely necessary anymore, maybe it's possible for
- // an async read on a pipe to be issued and then the pipe is closed,
- // returning this error. This may very well be necessary.
- ulong packedResult;
- if (errorCode != 0 && errorCode != ERROR_BROKEN_PIPE && errorCode != ERROR_NO_DATA)
- {
- packedResult = ((ulong)ResultError | errorCode);
- }
- else
- {
- packedResult = ((ulong)ResultSuccess | numBytes);
- }
-
- // Stow the result so that other threads can observe it
- // And, if no other thread is registering cancellation, continue
- if (NoResult == Interlocked.Exchange(ref completionSource._result, (long)packedResult))
- {
- // Successfully set the state, attempt to take back the callback
- if (Interlocked.Exchange(ref completionSource._result, CompletedCallback) != NoResult)
- {
- // Successfully got the callback, finish the callback
- completionSource.CompleteCallback(packedResult);
- }
- // else: Some other thread stole the result, so now it is responsible to finish the callback
- }
- // else: Some other thread is registering a cancellation, so it *must* finish the callback
- }
-
- private void CompleteCallback(ulong packedResult)
- {
- // Free up the native resource and cancellation registration
- CancellationToken cancellationToken = _cancellationRegistration.Token; // access before disposing registration
- ReleaseNativeResource();
-
- // Unpack the result and send it to the user
- long result = (long)(packedResult & ResultMask);
- if (result == ResultError)
- {
- int errorCode = unchecked((int)(packedResult & uint.MaxValue));
- if (errorCode == Interop.Errors.ERROR_OPERATION_ABORTED)
- {
- TrySetCanceled(cancellationToken.IsCancellationRequested ? cancellationToken : new CancellationToken(true));
- }
- else
- {
- Exception e = Win32Marshal.GetExceptionForWin32Error(errorCode);
- e.SetCurrentStackTrace();
- TrySetException(e);
- }
- }
- else
- {
- Debug.Assert(result == ResultSuccess, "Unknown result");
- TrySetResult((int)(packedResult & uint.MaxValue) + _numBufferedBytes);
- }
- }
-
- private static void Cancel(object? state)
- {
- // WARNING: This may potentially be called under a lock (during cancellation registration)
-
- Debug.Assert(state is FileStreamCompletionSource, "Unknown state passed to cancellation");
- FileStreamCompletionSource completionSource = (FileStreamCompletionSource)state;
- Debug.Assert(completionSource._overlapped != null && !completionSource.Task.IsCompleted, "IO should not have completed yet");
-
- // If the handle is still valid, attempt to cancel the IO
- if (!completionSource._stream._fileHandle.IsInvalid &&
- !Interop.Kernel32.CancelIoEx(completionSource._stream._fileHandle, completionSource._overlapped))
- {
- int errorCode = Marshal.GetLastWin32Error();
-
- // ERROR_NOT_FOUND is returned if CancelIoEx cannot find the request to cancel.
- // This probably means that the IO operation has completed.
- if (errorCode != Interop.Errors.ERROR_NOT_FOUND)
- {
- throw Win32Marshal.GetExceptionForWin32Error(errorCode);
- }
- }
- }
-
- public static FileStreamCompletionSource Create(FileStream stream, int numBufferedBytesRead, ReadOnlyMemory<byte> memory)
- {
- // If the memory passed in is the stream's internal buffer, we can use the base FileStreamCompletionSource,
- // which has a PreAllocatedOverlapped with the memory already pinned. Otherwise, we use the derived
- // MemoryFileStreamCompletionSource, which Retains the memory, which will result in less pinning in the case
- // where the underlying memory is backed by pre-pinned buffers.
- return MemoryMarshal.TryGetArray(memory, out ArraySegment<byte> buffer) && ReferenceEquals(buffer.Array, stream._buffer) ?
- new FileStreamCompletionSource(stream, numBufferedBytesRead, buffer.Array) :
- new MemoryFileStreamCompletionSource(stream, numBufferedBytesRead, memory);
- }
- }
-
- /// <summary>
- /// Extends <see cref="FileStreamCompletionSource"/> with to support disposing of a
- /// <see cref="MemoryHandle"/> when the operation has completed. This should only be used
- /// when memory doesn't wrap a byte[].
- /// </summary>
- private sealed class MemoryFileStreamCompletionSource : FileStreamCompletionSource
- {
- private MemoryHandle _handle; // mutable struct; do not make this readonly
-
- internal MemoryFileStreamCompletionSource(FileStream stream, int numBufferedBytes, ReadOnlyMemory<byte> memory) :
- base(stream, numBufferedBytes, bytes: null) // this type handles the pinning, so null is passed for bytes
- {
- _handle = memory.Pin();
- }
-
- internal override void ReleaseNativeResource()
- {
- _handle.Dispose();
- base.ReleaseNativeResource();
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/IOException.cs b/netcore/System.Private.CoreLib/shared/System/IO/IOException.cs
deleted file mode 100644
index a22cc3bc48f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/IOException.cs
+++ /dev/null
@@ -1,41 +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 System.Runtime.Serialization;
-
-namespace System.IO
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class IOException : SystemException
- {
- public IOException()
- : base(SR.Arg_IOException)
- {
- HResult = HResults.COR_E_IO;
- }
-
- public IOException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_IO;
- }
-
- public IOException(string? message, int hresult)
- : base(message)
- {
- HResult = hresult;
- }
-
- public IOException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_IO;
- }
-
- protected IOException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/MemoryStream.cs b/netcore/System.Private.CoreLib/shared/System/IO/MemoryStream.cs
deleted file mode 100644
index b8ff126e895..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/MemoryStream.cs
+++ /dev/null
@@ -1,868 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.IO
-{
- // A MemoryStream represents a Stream in memory (ie, it has no backing store).
- // This stream may reduce the need for temporary buffers and files in
- // an application.
- //
- // There are two ways to create a MemoryStream. You can initialize one
- // from an unsigned byte array, or you can create an empty one. Empty
- // memory streams are resizable, while ones created with a byte array provide
- // a stream "view" of the data.
- public class MemoryStream : Stream
- {
- private byte[] _buffer; // Either allocated internally or externally.
- private readonly int _origin; // For user-provided arrays, start at this origin
- private int _position; // read/write head.
- private int _length; // Number of bytes within the memory stream
- private int _capacity; // length of usable portion of buffer for stream
- // Note that _capacity == _buffer.Length for non-user-provided byte[]'s
-
- private bool _expandable; // User-provided buffers aren't expandable.
- private bool _writable; // Can user write to this stream?
- private readonly bool _exposable; // Whether the array can be returned to the user.
- private bool _isOpen; // Is this stream open or closed?
-
- private Task<int>? _lastReadTask; // The last successful task returned from ReadAsync
-
- private const int MemStreamMaxLength = int.MaxValue;
-
- public MemoryStream()
- : this(0)
- {
- }
-
- public MemoryStream(int capacity)
- {
- if (capacity < 0)
- throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_NegativeCapacity);
-
- _buffer = capacity != 0 ? new byte[capacity] : Array.Empty<byte>();
- _capacity = capacity;
- _expandable = true;
- _writable = true;
- _exposable = true;
- _origin = 0; // Must be 0 for byte[]'s created by MemoryStream
- _isOpen = true;
- }
-
- public MemoryStream(byte[] buffer)
- : this(buffer, true)
- {
- }
-
- public MemoryStream(byte[] buffer, bool writable)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
-
- _buffer = buffer;
- _length = _capacity = buffer.Length;
- _writable = writable;
- _exposable = false;
- _origin = 0;
- _isOpen = true;
- }
-
- public MemoryStream(byte[] buffer, int index, int count)
- : this(buffer, index, count, true, false)
- {
- }
-
- public MemoryStream(byte[] buffer, int index, int count, bool writable)
- : this(buffer, index, count, writable, false)
- {
- }
-
- public MemoryStream(byte[] buffer, int index, int count, bool writable, bool publiclyVisible)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- _buffer = buffer;
- _origin = _position = index;
- _length = _capacity = index + count;
- _writable = writable;
- _exposable = publiclyVisible; // Can TryGetBuffer/GetBuffer return the array?
- _expandable = false;
- _isOpen = true;
- }
-
- public override bool CanRead => _isOpen;
-
- public override bool CanSeek => _isOpen;
-
- public override bool CanWrite => _writable;
-
- private void EnsureNotClosed()
- {
- if (!_isOpen)
- throw Error.GetStreamIsClosed();
- }
-
- private void EnsureWriteable()
- {
- if (!CanWrite)
- throw Error.GetWriteNotSupported();
- }
-
- protected override void Dispose(bool disposing)
- {
- try
- {
- if (disposing)
- {
- _isOpen = false;
- _writable = false;
- _expandable = false;
- // Don't set buffer to null - allow TryGetBuffer, GetBuffer & ToArray to work.
- _lastReadTask = null;
- }
- }
- finally
- {
- // Call base.Close() to cleanup async IO resources
- base.Dispose(disposing);
- }
- }
-
- // returns a bool saying whether we allocated a new array.
- private bool EnsureCapacity(int value)
- {
- // Check for overflow
- if (value < 0)
- throw new IOException(SR.IO_StreamTooLong);
-
- if (value > _capacity)
- {
- int newCapacity = Math.Max(value, 256);
-
- // We are ok with this overflowing since the next statement will deal
- // with the cases where _capacity*2 overflows.
- if (newCapacity < _capacity * 2)
- {
- newCapacity = _capacity * 2;
- }
-
- // We want to expand the array up to Array.MaxByteArrayLength
- // And we want to give the user the value that they asked for
- if ((uint)(_capacity * 2) > Array.MaxByteArrayLength)
- {
- newCapacity = Math.Max(value, Array.MaxByteArrayLength);
- }
-
- Capacity = newCapacity;
- return true;
- }
- return false;
- }
-
- public override void Flush()
- {
- }
-
- public override Task FlushAsync(CancellationToken cancellationToken)
- {
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled(cancellationToken);
-
- try
- {
- Flush();
- return Task.CompletedTask;
- }
- catch (Exception ex)
- {
- return Task.FromException(ex);
- }
- }
-
- public virtual byte[] GetBuffer()
- {
- if (!_exposable)
- throw new UnauthorizedAccessException(SR.UnauthorizedAccess_MemStreamBuffer);
- return _buffer;
- }
-
- public virtual bool TryGetBuffer(out ArraySegment<byte> buffer)
- {
- if (!_exposable)
- {
- buffer = default;
- return false;
- }
-
- buffer = new ArraySegment<byte>(_buffer, offset: _origin, count: _length - _origin);
- return true;
- }
-
- // -------------- PERF: Internal functions for fast direct access of MemoryStream buffer (cf. BinaryReader for usage) ---------------
-
- // PERF: Internal sibling of GetBuffer, always returns a buffer (cf. GetBuffer())
- internal byte[] InternalGetBuffer()
- {
- return _buffer;
- }
-
- // PERF: True cursor position, we don't need _origin for direct access
- internal int InternalGetPosition()
- {
- return _position;
- }
-
- // PERF: Expose internal buffer for BinaryReader instead of going via the regular Stream interface which requires to copy the data out
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal ReadOnlySpan<byte> InternalReadSpan(int count)
- {
- EnsureNotClosed();
-
- int origPos = _position;
- int newPos = origPos + count;
-
- if ((uint)newPos > (uint)_length)
- {
- _position = _length;
- throw Error.GetEndOfFile();
- }
-
- var span = new ReadOnlySpan<byte>(_buffer, origPos, count);
- _position = newPos;
- return span;
- }
-
- // PERF: Get actual length of bytes available for read; do sanity checks; shift position - i.e. everything except actual copying bytes
- internal int InternalEmulateRead(int count)
- {
- EnsureNotClosed();
-
- int n = _length - _position;
- if (n > count)
- n = count;
- if (n < 0)
- n = 0;
-
- Debug.Assert(_position + n >= 0, "_position + n >= 0"); // len is less than 2^31 -1.
- _position += n;
- return n;
- }
-
- // Gets & sets the capacity (number of bytes allocated) for this stream.
- // The capacity cannot be set to a value less than the current length
- // of the stream.
- //
- public virtual int Capacity
- {
- get
- {
- EnsureNotClosed();
- return _capacity - _origin;
- }
- set
- {
- // Only update the capacity if the MS is expandable and the value is different than the current capacity.
- // Special behavior if the MS isn't expandable: we don't throw if value is the same as the current capacity
- if (value < Length)
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_SmallCapacity);
-
- EnsureNotClosed();
-
- if (!_expandable && (value != Capacity))
- throw new NotSupportedException(SR.NotSupported_MemStreamNotExpandable);
-
- // MemoryStream has this invariant: _origin > 0 => !expandable (see ctors)
- if (_expandable && value != _capacity)
- {
- if (value > 0)
- {
- byte[] newBuffer = new byte[value];
- if (_length > 0)
- {
- Buffer.BlockCopy(_buffer, 0, newBuffer, 0, _length);
- }
- _buffer = newBuffer;
- }
- else
- {
- _buffer = Array.Empty<byte>();
- }
- _capacity = value;
- }
- }
- }
-
- public override long Length
- {
- get
- {
- EnsureNotClosed();
- return _length - _origin;
- }
- }
-
- public override long Position
- {
- get
- {
- EnsureNotClosed();
- return _position - _origin;
- }
- set
- {
- if (value < 0)
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- EnsureNotClosed();
-
- if (value > MemStreamMaxLength)
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_StreamLength);
- _position = _origin + (int)value;
- }
- }
-
- public override int Read(byte[] buffer, int offset, int count)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - offset < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- EnsureNotClosed();
-
- int n = _length - _position;
- if (n > count)
- n = count;
- if (n <= 0)
- return 0;
-
- Debug.Assert(_position + n >= 0, "_position + n >= 0"); // len is less than 2^31 -1.
-
- if (n <= 8)
- {
- int byteCount = n;
- while (--byteCount >= 0)
- buffer[offset + byteCount] = _buffer[_position + byteCount];
- }
- else
- Buffer.BlockCopy(_buffer, _position, buffer, offset, n);
- _position += n;
-
- return n;
- }
-
- public override int Read(Span<byte> buffer)
- {
- if (GetType() != typeof(MemoryStream))
- {
- // MemoryStream is not sealed, and a derived type may have overridden Read(byte[], int, int) prior
- // to this Read(Span<byte>) overload being introduced. In that case, this Read(Span<byte>) overload
- // should use the behavior of Read(byte[],int,int) overload.
- return base.Read(buffer);
- }
-
- EnsureNotClosed();
-
- int n = Math.Min(_length - _position, buffer.Length);
- if (n <= 0)
- return 0;
-
- // TODO https://github.com/dotnet/coreclr/issues/15076:
- // Read(byte[], int, int) has an n <= 8 optimization, presumably based
- // on benchmarking. Determine if/where such a cut-off is here and add
- // an equivalent optimization if necessary.
- new Span<byte>(_buffer, _position, n).CopyTo(buffer);
-
- _position += n;
- return n;
- }
-
- public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - offset < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- // If cancellation was requested, bail early
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled<int>(cancellationToken);
-
- try
- {
- int n = Read(buffer, offset, count);
- Task<int>? t = _lastReadTask;
- Debug.Assert(t == null || t.Status == TaskStatus.RanToCompletion,
- "Expected that a stored last task completed successfully");
- return (t != null && t.Result == n) ? t : (_lastReadTask = Task.FromResult<int>(n));
- }
- catch (OperationCanceledException oce)
- {
- return Task.FromCanceled<int>(oce);
- }
- catch (Exception exception)
- {
- return Task.FromException<int>(exception);
- }
- }
-
- public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return new ValueTask<int>(Task.FromCanceled<int>(cancellationToken));
- }
-
- try
- {
- // ReadAsync(Memory<byte>,...) needs to delegate to an existing virtual to do the work, in case an existing derived type
- // has changed or augmented the logic associated with reads. If the Memory wraps an array, we could delegate to
- // ReadAsync(byte[], ...), but that would defeat part of the purpose, as ReadAsync(byte[], ...) often needs to allocate
- // a Task<int> for the return value, so we want to delegate to one of the synchronous methods. We could always
- // delegate to the Read(Span<byte>) method, and that's the most efficient solution when dealing with a concrete
- // MemoryStream, but if we're dealing with a type derived from MemoryStream, Read(Span<byte>) will end up delegating
- // to Read(byte[], ...), which requires it to get a byte[] from ArrayPool and copy the data. So, we special-case the
- // very common case of the Memory<byte> wrapping an array: if it does, we delegate to Read(byte[], ...) with it,
- // as that will be efficient in both cases, and we fall back to Read(Span<byte>) if the Memory<byte> wrapped something
- // else; if this is a concrete MemoryStream, that'll be efficient, and only in the case where the Memory<byte> wrapped
- // something other than an array and this is a MemoryStream-derived type that doesn't override Read(Span<byte>) will
- // it then fall back to doing the ArrayPool/copy behavior.
- return new ValueTask<int>(
- MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> destinationArray) ?
- Read(destinationArray.Array!, destinationArray.Offset, destinationArray.Count) :
- Read(buffer.Span));
- }
- catch (OperationCanceledException oce)
- {
- return new ValueTask<int>(Task.FromCanceled<int>(oce));
- }
- catch (Exception exception)
- {
- return new ValueTask<int>(Task.FromException<int>(exception));
- }
- }
-
- public override int ReadByte()
- {
- EnsureNotClosed();
-
- if (_position >= _length)
- return -1;
-
- return _buffer[_position++];
- }
-
- public override void CopyTo(Stream destination, int bufferSize)
- {
- // Since we did not originally override this method, validate the arguments
- // the same way Stream does for back-compat.
- StreamHelpers.ValidateCopyToArgs(this, destination, bufferSize);
-
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Read() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Read) when we are not sure.
- if (GetType() != typeof(MemoryStream))
- {
- base.CopyTo(destination, bufferSize);
- return;
- }
-
- int originalPosition = _position;
-
- // Seek to the end of the MemoryStream.
- int remaining = InternalEmulateRead(_length - originalPosition);
-
- // If we were already at or past the end, there's no copying to do so just quit.
- if (remaining > 0)
- {
- // Call Write() on the other Stream, using our internal buffer and avoiding any
- // intermediary allocations.
- destination.Write(_buffer, originalPosition, remaining);
- }
- }
-
- public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
- {
- // This implementation offers better performance compared to the base class version.
-
- StreamHelpers.ValidateCopyToArgs(this, destination, bufferSize);
-
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to ReadAsync() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into ReadAsync) when we are not sure.
- if (GetType() != typeof(MemoryStream))
- return base.CopyToAsync(destination, bufferSize, cancellationToken);
-
- // If canceled - return fast:
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled(cancellationToken);
-
- // Avoid copying data from this buffer into a temp buffer:
- // (require that InternalEmulateRead does not throw,
- // otherwise it needs to be wrapped into try-catch-Task.FromException like memStrDest.Write below)
-
- int pos = _position;
- int n = InternalEmulateRead(_length - _position);
-
- // If we were already at or past the end, there's no copying to do so just quit.
- if (n == 0)
- return Task.CompletedTask;
-
- // If destination is not a memory stream, write there asynchronously:
- if (!(destination is MemoryStream memStrDest))
- return destination.WriteAsync(_buffer, pos, n, cancellationToken);
-
- try
- {
- // If destination is a MemoryStream, CopyTo synchronously:
- memStrDest.Write(_buffer, pos, n);
- return Task.CompletedTask;
- }
- catch (Exception ex)
- {
- return Task.FromException(ex);
- }
- }
-
- public override void CopyTo(ReadOnlySpanAction<byte, object?> callback, object? state, int bufferSize)
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Read() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Read) when we are not sure.
- if (GetType() != typeof(MemoryStream))
- {
- base.CopyTo(callback, state, bufferSize);
- return;
- }
-
- StreamHelpers.ValidateCopyToArgs(this, callback, bufferSize);
-
- // Retrieve a span until the end of the MemoryStream.
- ReadOnlySpan<byte> span = new ReadOnlySpan<byte>(_buffer, _position, _length - _position);
- _position = _length;
-
- // Invoke the callback, using our internal span and avoiding any
- // intermediary allocations.
- callback(span, state);
- }
-
- public override Task CopyToAsync(Func<ReadOnlyMemory<byte>, object?, CancellationToken, ValueTask> callback, object? state, int bufferSize, CancellationToken cancellationToken)
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to ReadAsync() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into ReadAsync) when we are not sure.
- if (GetType() != typeof(MemoryStream))
- return base.CopyToAsync(callback, state, bufferSize, cancellationToken);
-
- StreamHelpers.ValidateCopyToArgs(this, callback, bufferSize);
-
- // If canceled - return fast:
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled(cancellationToken);
-
- // Avoid copying data from this buffer into a temp buffer
- ReadOnlyMemory<byte> memory = new ReadOnlyMemory<byte>(_buffer, _position, _length - _position);
- _position = _length;
-
- return callback(memory, state, cancellationToken).AsTask();
- }
-
- public override long Seek(long offset, SeekOrigin loc)
- {
- EnsureNotClosed();
-
- if (offset > MemStreamMaxLength)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_StreamLength);
-
- switch (loc)
- {
- case SeekOrigin.Begin:
- {
- int tempPosition = unchecked(_origin + (int)offset);
- if (offset < 0 || tempPosition < _origin)
- throw new IOException(SR.IO_SeekBeforeBegin);
- _position = tempPosition;
- break;
- }
- case SeekOrigin.Current:
- {
- int tempPosition = unchecked(_position + (int)offset);
- if (unchecked(_position + offset) < _origin || tempPosition < _origin)
- throw new IOException(SR.IO_SeekBeforeBegin);
- _position = tempPosition;
- break;
- }
- case SeekOrigin.End:
- {
- int tempPosition = unchecked(_length + (int)offset);
- if (unchecked(_length + offset) < _origin || tempPosition < _origin)
- throw new IOException(SR.IO_SeekBeforeBegin);
- _position = tempPosition;
- break;
- }
- default:
- throw new ArgumentException(SR.Argument_InvalidSeekOrigin);
- }
-
- Debug.Assert(_position >= 0, "_position >= 0");
- return _position;
- }
-
- // Sets the length of the stream to a given value. The new
- // value must be nonnegative and less than the space remaining in
- // the array, int.MaxValue - origin
- // Origin is 0 in all cases other than a MemoryStream created on
- // top of an existing array and a specific starting offset was passed
- // into the MemoryStream constructor. The upper bounds prevents any
- // situations where a stream may be created on top of an array then
- // the stream is made longer than the maximum possible length of the
- // array (int.MaxValue).
- //
- public override void SetLength(long value)
- {
- if (value < 0 || value > int.MaxValue)
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_StreamLength);
-
- EnsureWriteable();
-
- // Origin wasn't publicly exposed above.
- Debug.Assert(MemStreamMaxLength == int.MaxValue); // Check parameter validation logic in this method if this fails.
- if (value > (int.MaxValue - _origin))
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_StreamLength);
-
- int newLength = _origin + (int)value;
- bool allocatedNewArray = EnsureCapacity(newLength);
- if (!allocatedNewArray && newLength > _length)
- Array.Clear(_buffer, _length, newLength - _length);
- _length = newLength;
- if (_position > newLength)
- _position = newLength;
- }
-
- public virtual byte[] ToArray()
- {
- int count = _length - _origin;
- if (count == 0)
- return Array.Empty<byte>();
- byte[] copy = new byte[count];
- Buffer.BlockCopy(_buffer, _origin, copy, 0, count);
- return copy;
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - offset < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- EnsureNotClosed();
- EnsureWriteable();
-
- int i = _position + count;
- // Check for overflow
- if (i < 0)
- throw new IOException(SR.IO_StreamTooLong);
-
- if (i > _length)
- {
- bool mustZero = _position > _length;
- if (i > _capacity)
- {
- bool allocatedNewArray = EnsureCapacity(i);
- if (allocatedNewArray)
- {
- mustZero = false;
- }
- }
- if (mustZero)
- {
- Array.Clear(_buffer, _length, i - _length);
- }
- _length = i;
- }
- if ((count <= 8) && (buffer != _buffer))
- {
- int byteCount = count;
- while (--byteCount >= 0)
- {
- _buffer[_position + byteCount] = buffer[offset + byteCount];
- }
- }
- else
- {
- Buffer.BlockCopy(buffer, offset, _buffer, _position, count);
- }
- _position = i;
- }
-
- public override void Write(ReadOnlySpan<byte> buffer)
- {
- if (GetType() != typeof(MemoryStream))
- {
- // MemoryStream is not sealed, and a derived type may have overridden Write(byte[], int, int) prior
- // to this Write(Span<byte>) overload being introduced. In that case, this Write(Span<byte>) overload
- // should use the behavior of Write(byte[],int,int) overload.
- base.Write(buffer);
- return;
- }
-
- EnsureNotClosed();
- EnsureWriteable();
-
- // Check for overflow
- int i = _position + buffer.Length;
- if (i < 0)
- throw new IOException(SR.IO_StreamTooLong);
-
- if (i > _length)
- {
- bool mustZero = _position > _length;
- if (i > _capacity)
- {
- bool allocatedNewArray = EnsureCapacity(i);
- if (allocatedNewArray)
- {
- mustZero = false;
- }
- }
- if (mustZero)
- {
- Array.Clear(_buffer, _length, i - _length);
- }
- _length = i;
- }
-
- buffer.CopyTo(new Span<byte>(_buffer, _position, buffer.Length));
- _position = i;
- }
-
- public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - offset < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- // If cancellation is already requested, bail early
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled(cancellationToken);
-
- try
- {
- Write(buffer, offset, count);
- return Task.CompletedTask;
- }
- catch (OperationCanceledException oce)
- {
- return Task.FromCanceled(oce);
- }
- catch (Exception exception)
- {
- return Task.FromException(exception);
- }
- }
-
- public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return new ValueTask(Task.FromCanceled(cancellationToken));
- }
-
- try
- {
- // See corresponding comment in ReadAsync for why we don't just always use Write(ReadOnlySpan<byte>).
- // Unlike ReadAsync, we could delegate to WriteAsync(byte[], ...) here, but we don't for consistency.
- if (MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> sourceArray))
- {
- Write(sourceArray.Array!, sourceArray.Offset, sourceArray.Count);
- }
- else
- {
- Write(buffer.Span);
- }
- return default;
- }
- catch (OperationCanceledException oce)
- {
- return new ValueTask(Task.FromCanceled(oce));
- }
- catch (Exception exception)
- {
- return new ValueTask(Task.FromException(exception));
- }
- }
-
- public override void WriteByte(byte value)
- {
- EnsureNotClosed();
- EnsureWriteable();
-
- if (_position >= _length)
- {
- int newLength = _position + 1;
- bool mustZero = _position > _length;
- if (newLength >= _capacity)
- {
- bool allocatedNewArray = EnsureCapacity(newLength);
- if (allocatedNewArray)
- {
- mustZero = false;
- }
- }
- if (mustZero)
- {
- Array.Clear(_buffer, _length, _position - _length);
- }
- _length = newLength;
- }
- _buffer[_position++] = value;
- }
-
- // Writes this MemoryStream to another stream.
- public virtual void WriteTo(Stream stream)
- {
- if (stream == null)
- throw new ArgumentNullException(nameof(stream), SR.ArgumentNull_Stream);
-
- EnsureNotClosed();
-
- stream.Write(_buffer, _origin, _length - _origin);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/Path.Unix.cs b/netcore/System.Private.CoreLib/shared/System/IO/Path.Unix.cs
deleted file mode 100644
index 487c880c8e0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/Path.Unix.cs
+++ /dev/null
@@ -1,147 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System.IO
-{
- public static partial class Path
- {
- public static char[] GetInvalidFileNameChars() => new char[] { '\0', '/' };
-
- public static char[] GetInvalidPathChars() => new char[] { '\0' };
-
- // Expands the given path to a fully qualified path.
- public static string GetFullPath(string path)
- {
- if (path == null)
- throw new ArgumentNullException(nameof(path));
-
- if (path.Length == 0)
- throw new ArgumentException(SR.Arg_PathEmpty, nameof(path));
-
- if (path.Contains('\0'))
- throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path));
-
- // Expand with current directory if necessary
- if (!IsPathRooted(path))
- {
- path = Combine(Interop.Sys.GetCwd(), path);
- }
-
- // We would ideally use realpath to do this, but it resolves symlinks, requires that the file actually exist,
- // and turns it into a full path, which we only want if fullCheck is true.
- string collapsedString = PathInternal.RemoveRelativeSegments(path, PathInternal.GetRootLength(path));
-
- Debug.Assert(collapsedString.Length < path.Length || collapsedString.ToString() == path,
- "Either we've removed characters, or the string should be unmodified from the input path.");
-
- string result = collapsedString.Length == 0 ? PathInternal.DirectorySeparatorCharAsString : collapsedString;
-
- return result;
- }
-
- public static string GetFullPath(string path, string basePath)
- {
- if (path == null)
- throw new ArgumentNullException(nameof(path));
-
- if (basePath == null)
- throw new ArgumentNullException(nameof(basePath));
-
- if (!IsPathFullyQualified(basePath))
- throw new ArgumentException(SR.Arg_BasePathNotFullyQualified, nameof(basePath));
-
- if (basePath.Contains('\0') || path.Contains('\0'))
- throw new ArgumentException(SR.Argument_InvalidPathChars);
-
- if (IsPathFullyQualified(path))
- return GetFullPath(path);
-
- return GetFullPath(CombineInternal(basePath, path));
- }
-
- private static string RemoveLongPathPrefix(string path)
- {
- return path; // nop. There's nothing special about "long" paths on Unix.
- }
-
- public static string GetTempPath()
- {
- const string TempEnvVar = "TMPDIR";
- const string DefaultTempPath = "/tmp/";
-
- // Get the temp path from the TMPDIR environment variable.
- // If it's not set, just return the default path.
- // If it is, return it, ensuring it ends with a slash.
- string? path = Environment.GetEnvironmentVariable(TempEnvVar);
- return
- string.IsNullOrEmpty(path) ? DefaultTempPath :
- PathInternal.IsDirectorySeparator(path[path.Length - 1]) ? path :
- path + PathInternal.DirectorySeparatorChar;
- }
-
- public static string GetTempFileName()
- {
- const string Suffix = ".tmp";
- const int SuffixByteLength = 4;
-
- // mkstemps takes a char* and overwrites the XXXXXX with six characters
- // that'll result in a unique file name.
- string template = GetTempPath() + "tmpXXXXXX" + Suffix + "\0";
- byte[] name = Encoding.UTF8.GetBytes(template);
-
- // Create, open, and close the temp file.
- IntPtr fd = Interop.CheckIo(Interop.Sys.MksTemps(name, SuffixByteLength));
- Interop.Sys.Close(fd); // ignore any errors from close; nothing to do if cleanup isn't possible
-
- // 'name' is now the name of the file
- Debug.Assert(name[name.Length - 1] == '\0');
- return Encoding.UTF8.GetString(name, 0, name.Length - 1); // trim off the trailing '\0'
- }
-
- public static bool IsPathRooted(string? path)
- {
- if (path == null)
- return false;
-
- return IsPathRooted(path.AsSpan());
- }
-
- public static bool IsPathRooted(ReadOnlySpan<char> path)
- {
- return path.Length > 0 && path[0] == PathInternal.DirectorySeparatorChar;
- }
-
- /// <summary>
- /// Returns the path root or null if path is empty or null.
- /// </summary>
- public static string? GetPathRoot(string? path)
- {
- if (PathInternal.IsEffectivelyEmpty(path)) return null;
-
- return IsPathRooted(path) ? PathInternal.DirectorySeparatorCharAsString : string.Empty;
- }
-
- public static ReadOnlySpan<char> GetPathRoot(ReadOnlySpan<char> path)
- {
- return PathInternal.IsEffectivelyEmpty(path) && IsPathRooted(path) ? PathInternal.DirectorySeparatorCharAsString.AsSpan() : ReadOnlySpan<char>.Empty;
- }
-
- /// <summary>Gets whether the system is case-sensitive.</summary>
- internal static bool IsCaseSensitive
- {
- get
- {
- #if PLATFORM_OSX
- return false;
- #else
- return true;
- #endif
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/Path.Windows.cs b/netcore/System.Private.CoreLib/shared/System/IO/Path.Windows.cs
deleted file mode 100644
index 1e2bf76b3b0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/Path.Windows.cs
+++ /dev/null
@@ -1,286 +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.
-
-#nullable enable
-using System.Diagnostics;
-using System.Text;
-
-#if MS_IO_REDIST
-using System;
-using System.IO;
-
-namespace Microsoft.IO
-#else
-namespace System.IO
-#endif
-{
- public static partial class Path
- {
- public static char[] GetInvalidFileNameChars() => new char[]
- {
- '\"', '<', '>', '|', '\0',
- (char)1, (char)2, (char)3, (char)4, (char)5, (char)6, (char)7, (char)8, (char)9, (char)10,
- (char)11, (char)12, (char)13, (char)14, (char)15, (char)16, (char)17, (char)18, (char)19, (char)20,
- (char)21, (char)22, (char)23, (char)24, (char)25, (char)26, (char)27, (char)28, (char)29, (char)30,
- (char)31, ':', '*', '?', '\\', '/'
- };
-
- public static char[] GetInvalidPathChars() => new char[]
- {
- '|', '\0',
- (char)1, (char)2, (char)3, (char)4, (char)5, (char)6, (char)7, (char)8, (char)9, (char)10,
- (char)11, (char)12, (char)13, (char)14, (char)15, (char)16, (char)17, (char)18, (char)19, (char)20,
- (char)21, (char)22, (char)23, (char)24, (char)25, (char)26, (char)27, (char)28, (char)29, (char)30,
- (char)31
- };
-
- // Expands the given path to a fully qualified path.
- public static string GetFullPath(string path)
- {
- if (path == null)
- throw new ArgumentNullException(nameof(path));
-
- // If the path would normalize to string empty, we'll consider it empty
- if (PathInternal.IsEffectivelyEmpty(path.AsSpan()))
- throw new ArgumentException(SR.Arg_PathEmpty, nameof(path));
-
- // Embedded null characters are the only invalid character case we trully care about.
- // This is because the nulls will signal the end of the string to Win32 and therefore have
- // unpredictable results.
- if (path.Contains('\0'))
- throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path));
-
- if (PathInternal.IsExtended(path.AsSpan()))
- {
- // \\?\ paths are considered normalized by definition. Windows doesn't normalize \\?\
- // paths and neither should we. Even if we wanted to GetFullPathName does not work
- // properly with device paths. If one wants to pass a \\?\ path through normalization
- // one can chop off the prefix, pass it to GetFullPath and add it again.
- return path;
- }
-
- return PathHelper.Normalize(path);
- }
-
- public static string GetFullPath(string path, string basePath)
- {
- if (path == null)
- throw new ArgumentNullException(nameof(path));
-
- if (basePath == null)
- throw new ArgumentNullException(nameof(basePath));
-
- if (!IsPathFullyQualified(basePath))
- throw new ArgumentException(SR.Arg_BasePathNotFullyQualified, nameof(basePath));
-
- if (basePath.Contains('\0') || path.Contains('\0'))
- throw new ArgumentException(SR.Argument_InvalidPathChars);
-
- if (IsPathFullyQualified(path))
- return GetFullPath(path);
-
- if (PathInternal.IsEffectivelyEmpty(path.AsSpan()))
- return basePath;
-
- int length = path.Length;
- string? combinedPath = null;
-
- if (length >= 1 && PathInternal.IsDirectorySeparator(path[0]))
- {
- // Path is current drive rooted i.e. starts with \:
- // "\Foo" and "C:\Bar" => "C:\Foo"
- // "\Foo" and "\\?\C:\Bar" => "\\?\C:\Foo"
- combinedPath = Join(GetPathRoot(basePath.AsSpan()), path.AsSpan(1)); // Cut the separator to ensure we don't end up with two separators when joining with the root.
- }
- else if (length >= 2 && PathInternal.IsValidDriveChar(path[0]) && path[1] == PathInternal.VolumeSeparatorChar)
- {
- // Drive relative paths
- Debug.Assert(length == 2 || !PathInternal.IsDirectorySeparator(path[2]));
-
- if (GetVolumeName(path.AsSpan()).EqualsOrdinal(GetVolumeName(basePath.AsSpan())))
- {
- // Matching root
- // "C:Foo" and "C:\Bar" => "C:\Bar\Foo"
- // "C:Foo" and "\\?\C:\Bar" => "\\?\C:\Bar\Foo"
- combinedPath = Join(basePath.AsSpan(), path.AsSpan(2));
- }
- else
- {
- // No matching root, root to specified drive
- // "D:Foo" and "C:\Bar" => "D:Foo"
- // "D:Foo" and "\\?\C:\Bar" => "\\?\D:\Foo"
- combinedPath = !PathInternal.IsDevice(basePath.AsSpan())
- ? path.Insert(2, @"\")
- : length == 2
- ? JoinInternal(basePath.AsSpan(0, 4), path.AsSpan(), @"\".AsSpan())
- : JoinInternal(basePath.AsSpan(0, 4), path.AsSpan(0, 2), @"\".AsSpan(), path.AsSpan(2));
- }
- }
- else
- {
- // "Simple" relative path
- // "Foo" and "C:\Bar" => "C:\Bar\Foo"
- // "Foo" and "\\?\C:\Bar" => "\\?\C:\Bar\Foo"
- combinedPath = JoinInternal(basePath.AsSpan(), path.AsSpan());
- }
-
- // Device paths are normalized by definition, so passing something of this format (i.e. \\?\C:\.\tmp, \\.\C:\foo)
- // to Windows APIs won't do anything by design. Additionally, GetFullPathName() in Windows doesn't root
- // them properly. As such we need to manually remove segments and not use GetFullPath().
-
- return PathInternal.IsDevice(combinedPath.AsSpan())
- ? PathInternal.RemoveRelativeSegments(combinedPath, PathInternal.GetRootLength(combinedPath.AsSpan()))
- : GetFullPath(combinedPath);
- }
-
- public static string GetTempPath()
- {
- var builder = new ValueStringBuilder(stackalloc char[PathInternal.MaxShortPath]);
-
- GetTempPath(ref builder);
-
- string path = PathHelper.Normalize(ref builder);
- builder.Dispose();
- return path;
- }
-
- private static void GetTempPath(ref ValueStringBuilder builder)
- {
- uint result;
- while ((result = Interop.Kernel32.GetTempPathW(builder.Capacity, ref builder.GetPinnableReference())) > builder.Capacity)
- {
- // Reported size is greater than the buffer size. Increase the capacity.
- builder.EnsureCapacity(checked((int)result));
- }
-
- if (result == 0)
- throw Win32Marshal.GetExceptionForLastWin32Error();
-
- builder.Length = (int)result;
- }
-
- // Returns a unique temporary file name, and creates a 0-byte file by that
- // name on disk.
- public static string GetTempFileName()
- {
- var tempPathBuilder = new ValueStringBuilder(stackalloc char[PathInternal.MaxShortPath]);
-
- GetTempPath(ref tempPathBuilder);
-
- var builder = new ValueStringBuilder(stackalloc char[PathInternal.MaxShortPath]);
-
- uint result = Interop.Kernel32.GetTempFileNameW(
- ref tempPathBuilder.GetPinnableReference(), "tmp", 0, ref builder.GetPinnableReference());
-
- tempPathBuilder.Dispose();
-
- if (result == 0)
- throw Win32Marshal.GetExceptionForLastWin32Error();
-
- builder.Length = builder.RawChars.IndexOf('\0');
-
- string path = PathHelper.Normalize(ref builder);
- builder.Dispose();
- return path;
- }
-
- // Tests if the given path contains a root. A path is considered rooted
- // if it starts with a backslash ("\") or a valid drive letter and a colon (":").
- public static bool IsPathRooted(string? path)
- {
- return path != null && IsPathRooted(path.AsSpan());
- }
-
- public static bool IsPathRooted(ReadOnlySpan<char> path)
- {
- int length = path.Length;
- return (length >= 1 && PathInternal.IsDirectorySeparator(path[0]))
- || (length >= 2 && PathInternal.IsValidDriveChar(path[0]) && path[1] == PathInternal.VolumeSeparatorChar);
- }
-
- // Returns the root portion of the given path. The resulting string
- // consists of those rightmost characters of the path that constitute the
- // root of the path. Possible patterns for the resulting string are: An
- // empty string (a relative path on the current drive), "\" (an absolute
- // path on the current drive), "X:" (a relative path on a given drive,
- // where X is the drive letter), "X:\" (an absolute path on a given drive),
- // and "\\server\share" (a UNC path for a given server and share name).
- // The resulting string is null if path is null. If the path is empty or
- // only contains whitespace characters an ArgumentException gets thrown.
- public static string? GetPathRoot(string? path)
- {
- if (PathInternal.IsEffectivelyEmpty(path.AsSpan()))
- return null;
-
- ReadOnlySpan<char> result = GetPathRoot(path.AsSpan());
- if (path!.Length == result.Length)
- return PathInternal.NormalizeDirectorySeparators(path);
-
- return PathInternal.NormalizeDirectorySeparators(result.ToString());
- }
-
- /// <remarks>
- /// Unlike the string overload, this method will not normalize directory separators.
- /// </remarks>
- public static ReadOnlySpan<char> GetPathRoot(ReadOnlySpan<char> path)
- {
- if (PathInternal.IsEffectivelyEmpty(path))
- return ReadOnlySpan<char>.Empty;
-
- int pathRoot = PathInternal.GetRootLength(path);
- return pathRoot <= 0 ? ReadOnlySpan<char>.Empty : path.Slice(0, pathRoot);
- }
-
- /// <summary>Gets whether the system is case-sensitive.</summary>
- internal static bool IsCaseSensitive => false;
-
- /// <summary>
- /// Returns the volume name for dos, UNC and device paths.
- /// </summary>
- internal static ReadOnlySpan<char> GetVolumeName(ReadOnlySpan<char> path)
- {
- // 3 cases: UNC ("\\server\share"), Device ("\\?\C:\"), or Dos ("C:\")
- ReadOnlySpan<char> root = GetPathRoot(path);
- if (root.Length == 0)
- return root;
-
- // Cut from "\\?\UNC\Server\Share" to "Server\Share"
- // Cut from "\\Server\Share" to "Server\Share"
- int startOffset = GetUncRootLength(path);
- if (startOffset == -1)
- {
- if (PathInternal.IsDevice(path))
- {
- startOffset = 4; // Cut from "\\?\C:\" to "C:"
- }
- else
- {
- startOffset = 0; // e.g. "C:"
- }
- }
-
- ReadOnlySpan<char> pathToTrim = root.Slice(startOffset);
- return Path.EndsInDirectorySeparator(pathToTrim) ? pathToTrim.Slice(0, pathToTrim.Length - 1) : pathToTrim;
- }
-
- /// <summary>
- /// Returns offset as -1 if the path is not in Unc format, otherwise returns the root length.
- /// </summary>
- /// <param name="path"></param>
- /// <returns></returns>
- internal static int GetUncRootLength(ReadOnlySpan<char> path)
- {
- bool isDevice = PathInternal.IsDevice(path);
-
- if (!isDevice && path.Slice(0, 2).EqualsOrdinal(@"\\".AsSpan()))
- return 2;
- else if (isDevice && path.Length >= 8
- && (path.Slice(0, 8).EqualsOrdinal(PathInternal.UncExtendedPathPrefix.AsSpan())
- || path.Slice(5, 4).EqualsOrdinal(@"UNC\".AsSpan())))
- return 8;
-
- return -1;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/Path.cs b/netcore/System.Private.CoreLib/shared/System/IO/Path.cs
deleted file mode 100644
index b0cdad93bc7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/Path.cs
+++ /dev/null
@@ -1,930 +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.
-
-#nullable enable
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.InteropServices;
-using System.Text;
-
-#if MS_IO_REDIST
-using System;
-using System.IO;
-
-namespace Microsoft.IO
-#else
-namespace System.IO
-#endif
-{
- // Provides methods for processing file system strings in a cross-platform manner.
- // Most of the methods don't do a complete parsing (such as examining a UNC hostname),
- // but they will handle most string operations.
- public static partial class Path
- {
- // Public static readonly variant of the separators. The Path implementation itself is using
- // internal const variant of the separators for better performance.
- public static readonly char DirectorySeparatorChar = PathInternal.DirectorySeparatorChar;
- public static readonly char AltDirectorySeparatorChar = PathInternal.AltDirectorySeparatorChar;
- public static readonly char VolumeSeparatorChar = PathInternal.VolumeSeparatorChar;
- public static readonly char PathSeparator = PathInternal.PathSeparator;
-
- // For generating random file names
- // 8 random bytes provides 12 chars in our encoding for the 8.3 name.
- private const int KeyLength = 8;
-
- [Obsolete("Please use GetInvalidPathChars or GetInvalidFileNameChars instead.")]
- public static readonly char[] InvalidPathChars = GetInvalidPathChars();
-
- // Changes the extension of a file path. The path parameter
- // specifies a file path, and the extension parameter
- // specifies a file extension (with a leading period, such as
- // ".exe" or ".cs").
- //
- // The function returns a file path with the same root, directory, and base
- // name parts as path, but with the file extension changed to
- // the specified extension. If path is null, the function
- // returns null. If path does not contain a file extension,
- // the new file extension is appended to the path. If extension
- // is null, any existing extension is removed from path.
- [return: NotNullIfNotNull("path")]
- public static string? ChangeExtension(string? path, string? extension)
- {
- if (path == null)
- return null;
-
- int subLength = path.Length;
- if (subLength == 0)
- return string.Empty;
-
- for (int i = path.Length - 1; i >= 0; i--)
- {
- char ch = path[i];
-
- if (ch == '.')
- {
- subLength = i;
- break;
- }
-
- if (PathInternal.IsDirectorySeparator(ch))
- {
- break;
- }
- }
-
- if (extension == null)
- {
- return path.Substring(0, subLength);
- }
-
- ReadOnlySpan<char> subpath = path.AsSpan(0, subLength);
-#if MS_IO_REDIST
- return extension.Length != 0 && extension[0] == '.' ?
- StringExtensions.Concat(subpath, extension.AsSpan()) :
- StringExtensions.Concat(subpath, ".".AsSpan(), extension.AsSpan());
-#else
- return extension.StartsWith('.') ?
- string.Concat(subpath, extension) :
- string.Concat(subpath, ".", extension);
-#endif
- }
-
- /// <summary>
- /// Returns the directory portion of a file path. This method effectively
- /// removes the last segment of the given file path, i.e. it returns a
- /// string consisting of all characters up to but not including the last
- /// backslash ("\") in the file path. The returned value is null if the
- /// specified path is null, empty, or a root (such as "\", "C:", or
- /// "\\server\share").
- /// </summary>
- /// <remarks>
- /// Directory separators are normalized in the returned string.
- /// </remarks>
- public static string? GetDirectoryName(string? path)
- {
- if (path == null || PathInternal.IsEffectivelyEmpty(path.AsSpan()))
- return null;
-
- int end = GetDirectoryNameOffset(path.AsSpan());
- return end >= 0 ? PathInternal.NormalizeDirectorySeparators(path.Substring(0, end)) : null;
- }
-
- /// <summary>
- /// Returns the directory portion of a file path. The returned value is empty
- /// if the specified path is null, empty, or a root (such as "\", "C:", or
- /// "\\server\share").
- /// </summary>
- /// <remarks>
- /// Unlike the string overload, this method will not normalize directory separators.
- /// </remarks>
- public static ReadOnlySpan<char> GetDirectoryName(ReadOnlySpan<char> path)
- {
- if (PathInternal.IsEffectivelyEmpty(path))
- return ReadOnlySpan<char>.Empty;
-
- int end = GetDirectoryNameOffset(path);
- return end >= 0 ? path.Slice(0, end) : ReadOnlySpan<char>.Empty;
- }
-
- private static int GetDirectoryNameOffset(ReadOnlySpan<char> path)
- {
- int rootLength = PathInternal.GetRootLength(path);
- int end = path.Length;
- if (end <= rootLength)
- return -1;
-
- while (end > rootLength && !PathInternal.IsDirectorySeparator(path[--end])) ;
-
- // Trim off any remaining separators (to deal with C:\foo\\bar)
- while (end > rootLength && PathInternal.IsDirectorySeparator(path[end - 1]))
- end--;
-
- return end;
- }
-
- /// <summary>
- /// Returns the extension of the given path. The returned value includes the period (".") character of the
- /// extension except when you have a terminal period when you get string.Empty, such as ".exe" or ".cpp".
- /// The returned value is null if the given path is null or empty if the given path does not include an
- /// extension.
- /// </summary>
- [return: NotNullIfNotNull("path")]
- public static string? GetExtension(string? path)
- {
- if (path == null)
- return null;
-
- return GetExtension(path.AsSpan()).ToString();
- }
-
- /// <summary>
- /// Returns the extension of the given path.
- /// </summary>
- /// <remarks>
- /// The returned value is an empty ReadOnlySpan if the given path does not include an extension.
- /// </remarks>
- public static ReadOnlySpan<char> GetExtension(ReadOnlySpan<char> path)
- {
- int length = path.Length;
-
- for (int i = length - 1; i >= 0; i--)
- {
- char ch = path[i];
- if (ch == '.')
- {
- if (i != length - 1)
- return path.Slice(i, length - i);
- else
- return ReadOnlySpan<char>.Empty;
- }
- if (PathInternal.IsDirectorySeparator(ch))
- break;
- }
- return ReadOnlySpan<char>.Empty;
- }
-
- /// <summary>
- /// Returns the name and extension parts of the given path. The resulting string contains
- /// the characters of path that follow the last separator in path. The resulting string is
- /// null if path is null.
- /// </summary>
- [return: NotNullIfNotNull("path")]
- public static string? GetFileName(string? path)
- {
- if (path == null)
- return null;
-
- ReadOnlySpan<char> result = GetFileName(path.AsSpan());
- if (path.Length == result.Length)
- return path;
-
- return result.ToString();
- }
-
- /// <summary>
- /// The returned ReadOnlySpan contains the characters of the path that follows the last separator in path.
- /// </summary>
- public static ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
- {
- int root = GetPathRoot(path).Length;
-
- // We don't want to cut off "C:\file.txt:stream" (i.e. should be "file.txt:stream")
- // but we *do* want "C:Foo" => "Foo". This necessitates checking for the root.
-
- for (int i = path.Length; --i >= 0;)
- {
- if (i < root || PathInternal.IsDirectorySeparator(path[i]))
- return path.Slice(i + 1, path.Length - i - 1);
- }
-
- return path;
- }
-
- [return: NotNullIfNotNull("path")]
- public static string? GetFileNameWithoutExtension(string? path)
- {
- if (path == null)
- return null;
-
- ReadOnlySpan<char> result = GetFileNameWithoutExtension(path.AsSpan());
- if (path.Length == result.Length)
- return path;
-
- return result.ToString();
- }
-
- /// <summary>
- /// Returns the characters between the last separator and last (.) in the path.
- /// </summary>
- public static ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path)
- {
- ReadOnlySpan<char> fileName = GetFileName(path);
- int lastPeriod = fileName.LastIndexOf('.');
- return lastPeriod == -1 ?
- fileName : // No extension was found
- fileName.Slice(0, lastPeriod);
- }
-
- /// <summary>
- /// Returns a cryptographically strong random 8.3 string that can be
- /// used as either a folder name or a file name.
- /// </summary>
- public static unsafe string GetRandomFileName()
- {
- byte* pKey = stackalloc byte[KeyLength];
- Interop.GetRandomBytes(pKey, KeyLength);
-
-#if MS_IO_REDIST
- return StringExtensions.Create(
-#else
- return string.Create(
-#endif
- 12, (IntPtr)pKey, (span, key) => // 12 == 8 + 1 (for period) + 3
- Populate83FileNameFromRandomBytes((byte*)key, KeyLength, span));
- }
-
- /// <summary>
- /// Returns true if the path is fixed to a specific drive or UNC path. This method does no
- /// validation of the path (URIs will be returned as relative as a result).
- /// Returns false if the path specified is relative to the current drive or working directory.
- /// </summary>
- /// <remarks>
- /// Handles paths that use the alternate directory separator. It is a frequent mistake to
- /// assume that rooted paths <see cref="Path.IsPathRooted(string)"/> are not relative. This isn't the case.
- /// "C:a" is drive relative- meaning that it will be resolved against the current directory
- /// for C: (rooted, but relative). "C:\a" is rooted and not relative (the current directory
- /// will not be used to modify the path).
- /// </remarks>
- /// <exception cref="ArgumentNullException">
- /// Thrown if <paramref name="path"/> is null.
- /// </exception>
- public static bool IsPathFullyQualified(string path)
- {
- if (path == null)
- throw new ArgumentNullException(nameof(path));
-
- return IsPathFullyQualified(path.AsSpan());
- }
-
- public static bool IsPathFullyQualified(ReadOnlySpan<char> path)
- {
- return !PathInternal.IsPartiallyQualified(path);
- }
-
- /// <summary>
- /// Tests if a path's file name includes a file extension. A trailing period
- /// is not considered an extension.
- /// </summary>
- public static bool HasExtension(string? path)
- {
- if (path != null)
- {
- return HasExtension(path.AsSpan());
- }
- return false;
- }
-
- public static bool HasExtension(ReadOnlySpan<char> path)
- {
- for (int i = path.Length - 1; i >= 0; i--)
- {
- char ch = path[i];
- if (ch == '.')
- {
- return i != path.Length - 1;
- }
- if (PathInternal.IsDirectorySeparator(ch))
- break;
- }
- return false;
- }
-
- public static string Combine(string path1, string path2)
- {
- if (path1 == null || path2 == null)
- throw new ArgumentNullException((path1 == null) ? nameof(path1) : nameof(path2));
-
- return CombineInternal(path1, path2);
- }
-
- public static string Combine(string path1, string path2, string path3)
- {
- if (path1 == null || path2 == null || path3 == null)
- throw new ArgumentNullException((path1 == null) ? nameof(path1) : (path2 == null) ? nameof(path2) : nameof(path3));
-
- return CombineInternal(path1, path2, path3);
- }
-
- public static string Combine(string path1, string path2, string path3, string path4)
- {
- if (path1 == null || path2 == null || path3 == null || path4 == null)
- throw new ArgumentNullException((path1 == null) ? nameof(path1) : (path2 == null) ? nameof(path2) : (path3 == null) ? nameof(path3) : nameof(path4));
-
- return CombineInternal(path1, path2, path3, path4);
- }
-
- public static string Combine(params string[] paths)
- {
- if (paths == null)
- {
- throw new ArgumentNullException(nameof(paths));
- }
-
- int maxSize = 0;
- int firstComponent = 0;
-
- // We have two passes, the first calculates how large a buffer to allocate and does some precondition
- // checks on the paths passed in. The second actually does the combination.
-
- for (int i = 0; i < paths.Length; i++)
- {
- if (paths[i] == null)
- {
- throw new ArgumentNullException(nameof(paths));
- }
-
- if (paths[i].Length == 0)
- {
- continue;
- }
-
- if (IsPathRooted(paths[i]))
- {
- firstComponent = i;
- maxSize = paths[i].Length;
- }
- else
- {
- maxSize += paths[i].Length;
- }
-
- char ch = paths[i][paths[i].Length - 1];
- if (!PathInternal.IsDirectorySeparator(ch))
- maxSize++;
- }
-
- var builder = new ValueStringBuilder(stackalloc char[260]); // MaxShortPath on Windows
- builder.EnsureCapacity(maxSize);
-
- for (int i = firstComponent; i < paths.Length; i++)
- {
- if (paths[i].Length == 0)
- {
- continue;
- }
-
- if (builder.Length == 0)
- {
- builder.Append(paths[i]);
- }
- else
- {
- char ch = builder[builder.Length - 1];
- if (!PathInternal.IsDirectorySeparator(ch))
- {
- builder.Append(PathInternal.DirectorySeparatorChar);
- }
-
- builder.Append(paths[i]);
- }
- }
-
- return builder.ToString();
- }
-
- // Unlike Combine(), Join() methods do not consider rooting. They simply combine paths, ensuring that there
- // is a directory separator between them.
-
- public static string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2)
- {
- if (path1.Length == 0)
- return path2.ToString();
- if (path2.Length == 0)
- return path1.ToString();
-
- return JoinInternal(path1, path2);
- }
-
- public static string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3)
- {
- if (path1.Length == 0)
- return Join(path2, path3);
-
- if (path2.Length == 0)
- return Join(path1, path3);
-
- if (path3.Length == 0)
- return Join(path1, path2);
-
- return JoinInternal(path1, path2, path3);
- }
-
- public static string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3, ReadOnlySpan<char> path4)
- {
- if (path1.Length == 0)
- return Join(path2, path3, path4);
-
- if (path2.Length == 0)
- return Join(path1, path3, path4);
-
- if (path3.Length == 0)
- return Join(path1, path2, path4);
-
- if (path4.Length == 0)
- return Join(path1, path2, path3);
-
- return JoinInternal(path1, path2, path3, path4);
- }
-
- public static string Join(string? path1, string? path2)
- {
- return Join(path1.AsSpan(), path2.AsSpan());
- }
-
- public static string Join(string? path1, string? path2, string? path3)
- {
- return Join(path1.AsSpan(), path2.AsSpan(), path3.AsSpan());
- }
-
- public static string Join(string? path1, string? path2, string? path3, string? path4)
- {
- return Join(path1.AsSpan(), path2.AsSpan(), path3.AsSpan(), path4.AsSpan());
- }
-
- public static string Join(params string?[] paths)
- {
- if (paths == null)
- {
- throw new ArgumentNullException(nameof(paths));
- }
-
- if (paths.Length == 0)
- {
- return string.Empty;
- }
-
- int maxSize = 0;
- foreach (string? path in paths)
- {
- maxSize += path?.Length ?? 0;
- }
- maxSize += paths.Length - 1;
-
- var builder = new ValueStringBuilder(stackalloc char[260]); // MaxShortPath on Windows
- builder.EnsureCapacity(maxSize);
-
- for (int i = 0; i < paths.Length; i++)
- {
- string? path = paths[i];
- if (string.IsNullOrEmpty(path))
- {
- continue;
- }
-
- if (builder.Length == 0)
- {
- builder.Append(path);
- }
- else
- {
- if (!PathInternal.IsDirectorySeparator(builder[builder.Length - 1]) && !PathInternal.IsDirectorySeparator(path[0]))
- {
- builder.Append(PathInternal.DirectorySeparatorChar);
- }
-
- builder.Append(path);
- }
- }
-
- return builder.ToString();
- }
-
- public static bool TryJoin(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, Span<char> destination, out int charsWritten)
- {
- charsWritten = 0;
- if (path1.Length == 0 && path2.Length == 0)
- return true;
-
- if (path1.Length == 0 || path2.Length == 0)
- {
- ref ReadOnlySpan<char> pathToUse = ref path1.Length == 0 ? ref path2 : ref path1;
- if (destination.Length < pathToUse.Length)
- {
- return false;
- }
-
- pathToUse.CopyTo(destination);
- charsWritten = pathToUse.Length;
- return true;
- }
-
- bool needsSeparator = !(EndsInDirectorySeparator(path1) || PathInternal.StartsWithDirectorySeparator(path2));
- int charsNeeded = path1.Length + path2.Length + (needsSeparator ? 1 : 0);
- if (destination.Length < charsNeeded)
- return false;
-
- path1.CopyTo(destination);
- if (needsSeparator)
- destination[path1.Length] = DirectorySeparatorChar;
-
- path2.CopyTo(destination.Slice(path1.Length + (needsSeparator ? 1 : 0)));
-
- charsWritten = charsNeeded;
- return true;
- }
-
- public static bool TryJoin(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3, Span<char> destination, out int charsWritten)
- {
- charsWritten = 0;
- if (path1.Length == 0 && path2.Length == 0 && path3.Length == 0)
- return true;
-
- if (path1.Length == 0)
- return TryJoin(path2, path3, destination, out charsWritten);
- if (path2.Length == 0)
- return TryJoin(path1, path3, destination, out charsWritten);
- if (path3.Length == 0)
- return TryJoin(path1, path2, destination, out charsWritten);
-
- int neededSeparators = EndsInDirectorySeparator(path1) || PathInternal.StartsWithDirectorySeparator(path2) ? 0 : 1;
- bool needsSecondSeparator = !(EndsInDirectorySeparator(path2) || PathInternal.StartsWithDirectorySeparator(path3));
- if (needsSecondSeparator)
- neededSeparators++;
-
- int charsNeeded = path1.Length + path2.Length + path3.Length + neededSeparators;
- if (destination.Length < charsNeeded)
- return false;
-
- bool result = TryJoin(path1, path2, destination, out charsWritten);
- Debug.Assert(result, "should never fail joining first two paths");
-
- if (needsSecondSeparator)
- destination[charsWritten++] = DirectorySeparatorChar;
-
- path3.CopyTo(destination.Slice(charsWritten));
- charsWritten += path3.Length;
-
- return true;
- }
-
- private static string CombineInternal(string first, string second)
- {
- if (string.IsNullOrEmpty(first))
- return second;
-
- if (string.IsNullOrEmpty(second))
- return first;
-
- if (IsPathRooted(second.AsSpan()))
- return second;
-
- return JoinInternal(first.AsSpan(), second.AsSpan());
- }
-
- private static string CombineInternal(string first, string second, string third)
- {
- if (string.IsNullOrEmpty(first))
- return CombineInternal(second, third);
- if (string.IsNullOrEmpty(second))
- return CombineInternal(first, third);
- if (string.IsNullOrEmpty(third))
- return CombineInternal(first, second);
-
- if (IsPathRooted(third.AsSpan()))
- return third;
- if (IsPathRooted(second.AsSpan()))
- return CombineInternal(second, third);
-
- return JoinInternal(first.AsSpan(), second.AsSpan(), third.AsSpan());
- }
-
- private static string CombineInternal(string first, string second, string third, string fourth)
- {
- if (string.IsNullOrEmpty(first))
- return CombineInternal(second, third, fourth);
- if (string.IsNullOrEmpty(second))
- return CombineInternal(first, third, fourth);
- if (string.IsNullOrEmpty(third))
- return CombineInternal(first, second, fourth);
- if (string.IsNullOrEmpty(fourth))
- return CombineInternal(first, second, third);
-
- if (IsPathRooted(fourth.AsSpan()))
- return fourth;
- if (IsPathRooted(third.AsSpan()))
- return CombineInternal(third, fourth);
- if (IsPathRooted(second.AsSpan()))
- return CombineInternal(second, third, fourth);
-
- return JoinInternal(first.AsSpan(), second.AsSpan(), third.AsSpan(), fourth.AsSpan());
- }
-
- private static unsafe string JoinInternal(ReadOnlySpan<char> first, ReadOnlySpan<char> second)
- {
- Debug.Assert(first.Length > 0 && second.Length > 0, "should have dealt with empty paths");
-
- bool hasSeparator = PathInternal.IsDirectorySeparator(first[first.Length - 1])
- || PathInternal.IsDirectorySeparator(second[0]);
-
- fixed (char* f = &MemoryMarshal.GetReference(first), s = &MemoryMarshal.GetReference(second))
- {
-#if MS_IO_REDIST
- return StringExtensions.Create(
-#else
- return string.Create(
-#endif
- first.Length + second.Length + (hasSeparator ? 0 : 1),
- (First: (IntPtr)f, FirstLength: first.Length, Second: (IntPtr)s, SecondLength: second.Length, HasSeparator: hasSeparator),
- (destination, state) =>
- {
- new Span<char>((char*)state.First, state.FirstLength).CopyTo(destination);
- if (!state.HasSeparator)
- destination[state.FirstLength] = PathInternal.DirectorySeparatorChar;
- new Span<char>((char*)state.Second, state.SecondLength).CopyTo(destination.Slice(state.FirstLength + (state.HasSeparator ? 0 : 1)));
- });
- }
- }
-
- private static unsafe string JoinInternal(ReadOnlySpan<char> first, ReadOnlySpan<char> second, ReadOnlySpan<char> third)
- {
- Debug.Assert(first.Length > 0 && second.Length > 0 && third.Length > 0, "should have dealt with empty paths");
-
- bool firstHasSeparator = PathInternal.IsDirectorySeparator(first[first.Length - 1])
- || PathInternal.IsDirectorySeparator(second[0]);
- bool thirdHasSeparator = PathInternal.IsDirectorySeparator(second[second.Length - 1])
- || PathInternal.IsDirectorySeparator(third[0]);
-
- fixed (char* f = &MemoryMarshal.GetReference(first), s = &MemoryMarshal.GetReference(second), t = &MemoryMarshal.GetReference(third))
- {
-#if MS_IO_REDIST
- return StringExtensions.Create(
-#else
- return string.Create(
-#endif
- first.Length + second.Length + third.Length + (firstHasSeparator ? 0 : 1) + (thirdHasSeparator ? 0 : 1),
- (First: (IntPtr)f, FirstLength: first.Length, Second: (IntPtr)s, SecondLength: second.Length,
- Third: (IntPtr)t, ThirdLength: third.Length, FirstHasSeparator: firstHasSeparator, ThirdHasSeparator: thirdHasSeparator),
- (destination, state) =>
- {
- new Span<char>((char*)state.First, state.FirstLength).CopyTo(destination);
- if (!state.FirstHasSeparator)
- destination[state.FirstLength] = PathInternal.DirectorySeparatorChar;
- new Span<char>((char*)state.Second, state.SecondLength).CopyTo(destination.Slice(state.FirstLength + (state.FirstHasSeparator ? 0 : 1)));
- if (!state.ThirdHasSeparator)
- destination[destination.Length - state.ThirdLength - 1] = PathInternal.DirectorySeparatorChar;
- new Span<char>((char*)state.Third, state.ThirdLength).CopyTo(destination.Slice(destination.Length - state.ThirdLength));
- });
- }
- }
-
- private static unsafe string JoinInternal(ReadOnlySpan<char> first, ReadOnlySpan<char> second, ReadOnlySpan<char> third, ReadOnlySpan<char> fourth)
- {
- Debug.Assert(first.Length > 0 && second.Length > 0 && third.Length > 0 && fourth.Length > 0, "should have dealt with empty paths");
-
- bool firstHasSeparator = PathInternal.IsDirectorySeparator(first[first.Length - 1])
- || PathInternal.IsDirectorySeparator(second[0]);
- bool thirdHasSeparator = PathInternal.IsDirectorySeparator(second[second.Length - 1])
- || PathInternal.IsDirectorySeparator(third[0]);
- bool fourthHasSeparator = PathInternal.IsDirectorySeparator(third[third.Length - 1])
- || PathInternal.IsDirectorySeparator(fourth[0]);
-
- fixed (char* f = &MemoryMarshal.GetReference(first), s = &MemoryMarshal.GetReference(second), t = &MemoryMarshal.GetReference(third), u = &MemoryMarshal.GetReference(fourth))
- {
-#if MS_IO_REDIST
- return StringExtensions.Create(
-#else
- return string.Create(
-#endif
- first.Length + second.Length + third.Length + fourth.Length + (firstHasSeparator ? 0 : 1) + (thirdHasSeparator ? 0 : 1) + (fourthHasSeparator ? 0 : 1),
- (First: (IntPtr)f, FirstLength: first.Length, Second: (IntPtr)s, SecondLength: second.Length,
- Third: (IntPtr)t, ThirdLength: third.Length, Fourth: (IntPtr)u, FourthLength: fourth.Length,
- FirstHasSeparator: firstHasSeparator, ThirdHasSeparator: thirdHasSeparator, FourthHasSeparator: fourthHasSeparator),
- (destination, state) =>
- {
- new Span<char>((char*)state.First, state.FirstLength).CopyTo(destination);
- if (!state.FirstHasSeparator)
- destination[state.FirstLength] = PathInternal.DirectorySeparatorChar;
- new Span<char>((char*)state.Second, state.SecondLength).CopyTo(destination.Slice(state.FirstLength + (state.FirstHasSeparator ? 0 : 1)));
- if (!state.ThirdHasSeparator)
- destination[state.FirstLength + state.SecondLength + (state.FirstHasSeparator ? 0 : 1)] = PathInternal.DirectorySeparatorChar;
- new Span<char>((char*)state.Third, state.ThirdLength).CopyTo(destination.Slice(state.FirstLength + state.SecondLength + (state.FirstHasSeparator ? 0 : 1) + (state.ThirdHasSeparator ? 0 : 1)));
- if (!state.FourthHasSeparator)
- destination[destination.Length - state.FourthLength - 1] = PathInternal.DirectorySeparatorChar;
- new Span<char>((char*)state.Fourth, state.FourthLength).CopyTo(destination.Slice(destination.Length - state.FourthLength));
- });
- }
- }
-
- private static ReadOnlySpan<byte> Base32Char => new byte[32] { // uses C# compiler's optimization for static byte[] data
- (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', (byte)'h',
- (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', (byte)'o', (byte)'p',
- (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', (byte)'v', (byte)'w', (byte)'x',
- (byte)'y', (byte)'z', (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5' };
-
- private static unsafe void Populate83FileNameFromRandomBytes(byte* bytes, int byteCount, Span<char> chars)
- {
- // This method requires bytes of length 8 and chars of length 12.
- Debug.Assert(bytes != null);
- Debug.Assert(byteCount == 8, $"Unexpected {nameof(byteCount)}");
- Debug.Assert(chars.Length == 12, $"Unexpected {nameof(chars)}.Length");
-
- byte b0 = bytes[0];
- byte b1 = bytes[1];
- byte b2 = bytes[2];
- byte b3 = bytes[3];
- byte b4 = bytes[4];
-
- // write to chars[11] first in order to eliminate redundant bounds checks
- chars[11] = (char)Base32Char[bytes[7] & 0x1F];
-
- // Consume the 5 Least significant bits of the first 5 bytes
- chars[0] = (char)Base32Char[b0 & 0x1F];
- chars[1] = (char)Base32Char[b1 & 0x1F];
- chars[2] = (char)Base32Char[b2 & 0x1F];
- chars[3] = (char)Base32Char[b3 & 0x1F];
- chars[4] = (char)Base32Char[b4 & 0x1F];
-
- // Consume 3 MSB of b0, b1, MSB bits 6, 7 of b3, b4
- chars[5] = (char)Base32Char[
- ((b0 & 0xE0) >> 5) |
- ((b3 & 0x60) >> 2)];
-
- chars[6] = (char)Base32Char[
- ((b1 & 0xE0) >> 5) |
- ((b4 & 0x60) >> 2)];
-
- // Consume 3 MSB bits of b2, 1 MSB bit of b3, b4
- b2 >>= 5;
-
- Debug.Assert((b2 & 0xF8) == 0, "Unexpected set bits");
-
- if ((b3 & 0x80) != 0)
- b2 |= 0x08;
- if ((b4 & 0x80) != 0)
- b2 |= 0x10;
-
- chars[7] = (char)Base32Char[b2];
-
- // Set the file extension separator
- chars[8] = '.';
-
- // Consume the 5 Least significant bits of the remaining 3 bytes
- chars[9] = (char)Base32Char[bytes[5] & 0x1F];
- chars[10] = (char)Base32Char[bytes[6] & 0x1F];
- }
-
- /// <summary>
- /// Create a relative path from one path to another. Paths will be resolved before calculating the difference.
- /// Default path comparison for the active platform will be used (OrdinalIgnoreCase for Windows or Mac, Ordinal for Unix).
- /// </summary>
- /// <param name="relativeTo">The source path the output should be relative to. This path is always considered to be a directory.</param>
- /// <param name="path">The destination path.</param>
- /// <returns>The relative path or <paramref name="path"/> if the paths don't share the same root.</returns>
- /// <exception cref="ArgumentNullException">Thrown if <paramref name="relativeTo"/> or <paramref name="path"/> is <c>null</c> or an empty string.</exception>
- public static string GetRelativePath(string relativeTo, string path)
- {
- return GetRelativePath(relativeTo, path, StringComparison);
- }
-
- private static string GetRelativePath(string relativeTo, string path, StringComparison comparisonType)
- {
- if (relativeTo == null)
- throw new ArgumentNullException(nameof(relativeTo));
-
- if (PathInternal.IsEffectivelyEmpty(relativeTo.AsSpan()))
- throw new ArgumentException(SR.Arg_PathEmpty, nameof(relativeTo));
-
- if (path == null)
- throw new ArgumentNullException(nameof(path));
-
- if (PathInternal.IsEffectivelyEmpty(path.AsSpan()))
- throw new ArgumentException(SR.Arg_PathEmpty, nameof(path));
-
- Debug.Assert(comparisonType == StringComparison.Ordinal || comparisonType == StringComparison.OrdinalIgnoreCase);
-
- relativeTo = GetFullPath(relativeTo);
- path = GetFullPath(path);
-
- // Need to check if the roots are different- if they are we need to return the "to" path.
- if (!PathInternal.AreRootsEqual(relativeTo, path, comparisonType))
- return path;
-
- int commonLength = PathInternal.GetCommonPathLength(relativeTo, path, ignoreCase: comparisonType == StringComparison.OrdinalIgnoreCase);
-
- // If there is nothing in common they can't share the same root, return the "to" path as is.
- if (commonLength == 0)
- return path;
-
- // Trailing separators aren't significant for comparison
- int relativeToLength = relativeTo.Length;
- if (EndsInDirectorySeparator(relativeTo.AsSpan()))
- relativeToLength--;
-
- bool pathEndsInSeparator = EndsInDirectorySeparator(path.AsSpan());
- int pathLength = path.Length;
- if (pathEndsInSeparator)
- pathLength--;
-
- // If we have effectively the same path, return "."
- if (relativeToLength == pathLength && commonLength >= relativeToLength) return ".";
-
- // We have the same root, we need to calculate the difference now using the
- // common Length and Segment count past the length.
- //
- // Some examples:
- //
- // C:\Foo C:\Bar L3, S1 -> ..\Bar
- // C:\Foo C:\Foo\Bar L6, S0 -> Bar
- // C:\Foo\Bar C:\Bar\Bar L3, S2 -> ..\..\Bar\Bar
- // C:\Foo\Foo C:\Foo\Bar L7, S1 -> ..\Bar
-
- var sb = new ValueStringBuilder(stackalloc char[260]);
- sb.EnsureCapacity(Math.Max(relativeTo.Length, path.Length));
-
- // Add parent segments for segments past the common on the "from" path
- if (commonLength < relativeToLength)
- {
- sb.Append("..");
-
- for (int i = commonLength + 1; i < relativeToLength; i++)
- {
- if (PathInternal.IsDirectorySeparator(relativeTo[i]))
- {
- sb.Append(DirectorySeparatorChar);
- sb.Append("..");
- }
- }
- }
- else if (PathInternal.IsDirectorySeparator(path[commonLength]))
- {
- // No parent segments and we need to eat the initial separator
- // (C:\Foo C:\Foo\Bar case)
- commonLength++;
- }
-
- // Now add the rest of the "to" path, adding back the trailing separator
- int differenceLength = pathLength - commonLength;
- if (pathEndsInSeparator)
- differenceLength++;
-
- if (differenceLength > 0)
- {
- if (sb.Length > 0)
- {
- sb.Append(DirectorySeparatorChar);
- }
-
- sb.Append(path.AsSpan(commonLength, differenceLength));
- }
-
- return sb.ToString();
- }
-
- /// <summary>Returns a comparison that can be used to compare file and directory names for equality.</summary>
- internal static StringComparison StringComparison =>
- IsCaseSensitive ?
- StringComparison.Ordinal :
- StringComparison.OrdinalIgnoreCase;
-
- /// <summary>
- /// Trims one trailing directory separator beyond the root of the path.
- /// </summary>
- public static string TrimEndingDirectorySeparator(string path) => PathInternal.TrimEndingDirectorySeparator(path);
-
- /// <summary>
- /// Trims one trailing directory separator beyond the root of the path.
- /// </summary>
- public static ReadOnlySpan<char> TrimEndingDirectorySeparator(ReadOnlySpan<char> path) => PathInternal.TrimEndingDirectorySeparator(path);
-
- /// <summary>
- /// Returns true if the path ends in a directory separator.
- /// </summary>
- public static bool EndsInDirectorySeparator(ReadOnlySpan<char> path) => PathInternal.EndsInDirectorySeparator(path);
-
- /// <summary>
- /// Returns true if the path ends in a directory separator.
- /// </summary>
- public static bool EndsInDirectorySeparator(string path) => PathInternal.EndsInDirectorySeparator(path);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/PathHelper.Windows.cs b/netcore/System.Private.CoreLib/shared/System/IO/PathHelper.Windows.cs
deleted file mode 100644
index abf5c346148..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/PathHelper.Windows.cs
+++ /dev/null
@@ -1,251 +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.
-
-#nullable enable
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System.IO
-{
- /// <summary>
- /// Wrapper to help with path normalization.
- /// </summary>
- internal static class PathHelper
- {
- /// <summary>
- /// Normalize the given path.
- /// </summary>
- /// <remarks>
- /// Normalizes via Win32 GetFullPathName().
- /// </remarks>
- /// <param name="path">Path to normalize</param>
- /// <exception cref="PathTooLongException">Thrown if we have a string that is too large to fit into a UNICODE_STRING.</exception>
- /// <exception cref="IOException">Thrown if the path is empty.</exception>
- /// <returns>Normalized path</returns>
- internal static string Normalize(string path)
- {
- var builder = new ValueStringBuilder(stackalloc char[PathInternal.MaxShortPath]);
-
- // Get the full path
- GetFullPathName(path.AsSpan(), ref builder);
-
- // If we have the exact same string we were passed in, don't allocate another string.
- // TryExpandShortName does this input identity check.
- string result = builder.AsSpan().IndexOf('~') >= 0
- ? TryExpandShortFileName(ref builder, originalPath: path)
- : builder.AsSpan().Equals(path.AsSpan(), StringComparison.Ordinal) ? path : builder.ToString();
-
- // Clear the buffer
- builder.Dispose();
- return result;
- }
-
- /// <summary>
- /// Normalize the given path.
- /// </summary>
- /// <remarks>
- /// Exceptions are the same as the string overload.
- /// </remarks>
- internal static string Normalize(ref ValueStringBuilder path)
- {
- var builder = new ValueStringBuilder(stackalloc char[PathInternal.MaxShortPath]);
-
- // Get the full path
- GetFullPathName(path.AsSpan(terminate: true), ref builder);
-
- string result = builder.AsSpan().IndexOf('~') >= 0
- ? TryExpandShortFileName(ref builder, originalPath: null)
- : builder.ToString();
-
- // Clear the buffer
- builder.Dispose();
- return result;
- }
-
- /// <summary>
- /// Calls GetFullPathName on the given path.
- /// </summary>
- /// <param name="path">The path name. MUST be null terminated after the span.</param>
- /// <param name="builder">Builder that will store the result.</param>
- private static void GetFullPathName(ReadOnlySpan<char> path, ref ValueStringBuilder builder)
- {
- // If the string starts with an extended prefix we would need to remove it from the path before we call GetFullPathName as
- // it doesn't root extended paths correctly. We don't currently resolve extended paths, so we'll just assert here.
- Debug.Assert(PathInternal.IsPartiallyQualified(path) || !PathInternal.IsExtended(path));
-
- uint result;
- while ((result = Interop.Kernel32.GetFullPathNameW(ref MemoryMarshal.GetReference(path), (uint)builder.Capacity, ref builder.GetPinnableReference(), IntPtr.Zero)) > builder.Capacity)
- {
- // Reported size is greater than the buffer size. Increase the capacity.
- builder.EnsureCapacity(checked((int)result));
- }
-
- if (result == 0)
- {
- // Failure, get the error and throw
- int errorCode = Marshal.GetLastWin32Error();
- if (errorCode == 0)
- errorCode = Interop.Errors.ERROR_BAD_PATHNAME;
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, path.ToString());
- }
-
- builder.Length = (int)result;
- }
-
- internal static int PrependDevicePathChars(ref ValueStringBuilder content, bool isDosUnc, ref ValueStringBuilder buffer)
- {
- int length = content.Length;
-
- length += isDosUnc
- ? PathInternal.UncExtendedPrefixLength - PathInternal.UncPrefixLength
- : PathInternal.DevicePrefixLength;
-
- buffer.EnsureCapacity(length + 1);
- buffer.Length = 0;
-
- if (isDosUnc)
- {
- // Is a \\Server\Share, put \\?\UNC\ in the front
- buffer.Append(PathInternal.UncExtendedPathPrefix);
-
- // Copy Server\Share\... over to the buffer
- buffer.Append(content.AsSpan(PathInternal.UncPrefixLength));
-
- // Return the prefix difference
- return PathInternal.UncExtendedPrefixLength - PathInternal.UncPrefixLength;
- }
- else
- {
- // Not an UNC, put the \\?\ prefix in front, then the original string
- buffer.Append(PathInternal.ExtendedPathPrefix);
- buffer.Append(content.AsSpan());
- return PathInternal.DevicePrefixLength;
- }
- }
-
- internal static string TryExpandShortFileName(ref ValueStringBuilder outputBuilder, string? originalPath)
- {
- // We guarantee we'll expand short names for paths that only partially exist. As such, we need to find the part of the path that actually does exist. To
- // avoid allocating a lot we'll create only one input array and modify the contents with embedded nulls.
-
- Debug.Assert(!PathInternal.IsPartiallyQualified(outputBuilder.AsSpan()), "should have resolved by now");
-
- // We'll have one of a few cases by now (the normalized path will have already:
- //
- // 1. Dos path (C:\)
- // 2. Dos UNC (\\Server\Share)
- // 3. Dos device path (\\.\C:\, \\?\C:\)
- //
- // We want to put the extended syntax on the front if it doesn't already have it (for long path support and speed), which may mean switching from \\.\.
- //
- // Note that we will never get \??\ here as GetFullPathName() does not recognize \??\ and will return it as C:\??\ (or whatever the current drive is).
-
- int rootLength = PathInternal.GetRootLength(outputBuilder.AsSpan());
- bool isDevice = PathInternal.IsDevice(outputBuilder.AsSpan());
-
- // As this is a corner case we're not going to add a stackalloc here to keep the stack pressure down.
- ValueStringBuilder inputBuilder = default;
-
- bool isDosUnc = false;
- int rootDifference = 0;
- bool wasDotDevice = false;
-
- // Add the extended prefix before expanding to allow growth over MAX_PATH
- if (isDevice)
- {
- // We have one of the following (\\?\ or \\.\)
- inputBuilder.Append(outputBuilder.AsSpan());
-
- if (outputBuilder[2] == '.')
- {
- wasDotDevice = true;
- inputBuilder[2] = '?';
- }
- }
- else
- {
- isDosUnc = !PathInternal.IsDevice(outputBuilder.AsSpan()) && outputBuilder.Length > 1 && outputBuilder[0] == '\\' && outputBuilder[1] == '\\';
- rootDifference = PrependDevicePathChars(ref outputBuilder, isDosUnc, ref inputBuilder);
- }
-
- rootLength += rootDifference;
- int inputLength = inputBuilder.Length;
-
- bool success = false;
- int foundIndex = inputBuilder.Length - 1;
-
- while (!success)
- {
- uint result = Interop.Kernel32.GetLongPathNameW(
- ref inputBuilder.GetPinnableReference(terminate: true), ref outputBuilder.GetPinnableReference(), (uint)outputBuilder.Capacity);
-
- // Replace any temporary null we added
- if (inputBuilder[foundIndex] == '\0') inputBuilder[foundIndex] = '\\';
-
- if (result == 0)
- {
- // Look to see if we couldn't find the file
- int error = Marshal.GetLastWin32Error();
- if (error != Interop.Errors.ERROR_FILE_NOT_FOUND && error != Interop.Errors.ERROR_PATH_NOT_FOUND)
- {
- // Some other failure, give up
- break;
- }
-
- // We couldn't find the path at the given index, start looking further back in the string.
- foundIndex--;
-
- for (; foundIndex > rootLength && inputBuilder[foundIndex] != '\\'; foundIndex--) ;
- if (foundIndex == rootLength)
- {
- // Can't trim the path back any further
- break;
- }
- else
- {
- // Temporarily set a null in the string to get Windows to look further up the path
- inputBuilder[foundIndex] = '\0';
- }
- }
- else if (result > outputBuilder.Capacity)
- {
- // Not enough space. The result count for this API does not include the null terminator.
- outputBuilder.EnsureCapacity(checked((int)result));
- }
- else
- {
- // Found the path
- success = true;
- outputBuilder.Length = checked((int)result);
- if (foundIndex < inputLength - 1)
- {
- // It was a partial find, put the non-existent part of the path back
- outputBuilder.Append(inputBuilder.AsSpan(foundIndex, inputBuilder.Length - foundIndex));
- }
- }
- }
-
- // If we were able to expand the path, use it, otherwise use the original full path result
- ref ValueStringBuilder builderToUse = ref (success ? ref outputBuilder : ref inputBuilder);
-
- // Switch back from \\?\ to \\.\ if necessary
- if (wasDotDevice)
- builderToUse[2] = '.';
-
- // Change from \\?\UNC\ to \\?\UN\\ if needed
- if (isDosUnc)
- builderToUse[PathInternal.UncExtendedPrefixLength - PathInternal.UncPrefixLength] = '\\';
-
- // Strip out any added characters at the front of the string
- ReadOnlySpan<char> output = builderToUse.AsSpan(rootDifference);
-
- string returnValue = ((originalPath != null) && output.Equals(originalPath.AsSpan(), StringComparison.Ordinal))
- ? originalPath : output.ToString();
-
- inputBuilder.Dispose();
- return returnValue;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.Unix.cs b/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.Unix.cs
deleted file mode 100644
index f9a018ae5e3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.Unix.cs
+++ /dev/null
@@ -1,98 +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.
-
-#nullable enable
-using System.Diagnostics;
-using System.Text;
-using System.Runtime.InteropServices;
-
-namespace System.IO
-{
- /// <summary>Contains internal path helpers that are shared between many projects.</summary>
- internal static partial class PathInternal
- {
- internal const char DirectorySeparatorChar = '/';
- internal const char AltDirectorySeparatorChar = '/';
- internal const char VolumeSeparatorChar = '/';
- internal const char PathSeparator = ':';
- internal const string DirectorySeparatorCharAsString = "/";
- internal const string ParentDirectoryPrefix = @"../";
-
- internal static int GetRootLength(ReadOnlySpan<char> path)
- {
- return path.Length > 0 && IsDirectorySeparator(path[0]) ? 1 : 0;
- }
-
- internal static bool IsDirectorySeparator(char c)
- {
- // The alternate directory separator char is the same as the directory separator,
- // so we only need to check one.
- Debug.Assert(DirectorySeparatorChar == AltDirectorySeparatorChar);
- return c == DirectorySeparatorChar;
- }
-
- /// <summary>
- /// Normalize separators in the given path. Compresses forward slash runs.
- /// </summary>
- internal static string NormalizeDirectorySeparators(string path)
- {
- if (string.IsNullOrEmpty(path))
- return path;
-
- // Make a pass to see if we need to normalize so we can potentially skip allocating
- bool normalized = true;
-
- for (int i = 0; i < path.Length; i++)
- {
- if (IsDirectorySeparator(path[i])
- && (i + 1 < path.Length && IsDirectorySeparator(path[i + 1])))
- {
- normalized = false;
- break;
- }
- }
-
- if (normalized)
- return path;
-
- StringBuilder builder = new StringBuilder(path.Length);
-
- for (int i = 0; i < path.Length; i++)
- {
- char current = path[i];
-
- // Skip if we have another separator following
- if (IsDirectorySeparator(current)
- && (i + 1 < path.Length && IsDirectorySeparator(path[i + 1])))
- continue;
-
- builder.Append(current);
- }
-
- return builder.ToString();
- }
-
- internal static bool IsPartiallyQualified(ReadOnlySpan<char> path)
- {
- // This is much simpler than Windows where paths can be rooted, but not fully qualified (such as Drive Relative)
- // As long as the path is rooted in Unix it doesn't use the current directory and therefore is fully qualified.
- return !Path.IsPathRooted(path);
- }
-
- /// <summary>
- /// Returns true if the path is effectively empty for the current OS.
- /// For unix, this is empty or null. For Windows, this is empty, null, or
- /// just spaces ((char)32).
- /// </summary>
- internal static bool IsEffectivelyEmpty(string? path)
- {
- return string.IsNullOrEmpty(path);
- }
-
- internal static bool IsEffectivelyEmpty(ReadOnlySpan<char> path)
- {
- return path.IsEmpty;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs b/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs
deleted file mode 100644
index 300d1265579..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs
+++ /dev/null
@@ -1,414 +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.
-
-#nullable enable
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System.IO
-{
- /// <summary>Contains internal path helpers that are shared between many projects.</summary>
- internal static partial class PathInternal
- {
- // All paths in Win32 ultimately end up becoming a path to a File object in the Windows object manager. Passed in paths get mapped through
- // DosDevice symbolic links in the object tree to actual File objects under \Devices. To illustrate, this is what happens with a typical
- // path "Foo" passed as a filename to any Win32 API:
- //
- // 1. "Foo" is recognized as a relative path and is appended to the current directory (say, "C:\" in our example)
- // 2. "C:\Foo" is prepended with the DosDevice namespace "\??\"
- // 3. CreateFile tries to create an object handle to the requested file "\??\C:\Foo"
- // 4. The Object Manager recognizes the DosDevices prefix and looks
- // a. First in the current session DosDevices ("\Sessions\1\DosDevices\" for example, mapped network drives go here)
- // b. If not found in the session, it looks in the Global DosDevices ("\GLOBAL??\")
- // 5. "C:" is found in DosDevices (in our case "\GLOBAL??\C:", which is a symbolic link to "\Device\HarddiskVolume6")
- // 6. The full path is now "\Device\HarddiskVolume6\Foo", "\Device\HarddiskVolume6" is a File object and parsing is handed off
- // to the registered parsing method for Files
- // 7. The registered open method for File objects is invoked to create the file handle which is then returned
- //
- // There are multiple ways to directly specify a DosDevices path. The final format of "\??\" is one way. It can also be specified
- // as "\\.\" (the most commonly documented way) and "\\?\". If the question mark syntax is used the path will skip normalization
- // (essentially GetFullPathName()) and path length checks.
-
- // Windows Kernel-Mode Object Manager
- // https://msdn.microsoft.com/en-us/library/windows/hardware/ff565763.aspx
- // https://channel9.msdn.com/Shows/Going+Deep/Windows-NT-Object-Manager
- //
- // Introduction to MS-DOS Device Names
- // https://msdn.microsoft.com/en-us/library/windows/hardware/ff548088.aspx
- //
- // Local and Global MS-DOS Device Names
- // https://msdn.microsoft.com/en-us/library/windows/hardware/ff554302.aspx
-
- internal const char DirectorySeparatorChar = '\\';
- internal const char AltDirectorySeparatorChar = '/';
- internal const char VolumeSeparatorChar = ':';
- internal const char PathSeparator = ';';
-
- internal const string DirectorySeparatorCharAsString = "\\";
-
- internal const string ExtendedPathPrefix = @"\\?\";
- internal const string UncPathPrefix = @"\\";
- internal const string UncExtendedPrefixToInsert = @"?\UNC\";
- internal const string UncExtendedPathPrefix = @"\\?\UNC\";
- internal const string DevicePathPrefix = @"\\.\";
- internal const string ParentDirectoryPrefix = @"..\";
-
- internal const int MaxShortPath = 260;
- internal const int MaxShortDirectoryPath = 248;
- // \\?\, \\.\, \??\
- internal const int DevicePrefixLength = 4;
- // \\
- internal const int UncPrefixLength = 2;
- // \\?\UNC\, \\.\UNC\
- internal const int UncExtendedPrefixLength = 8;
-
- /// <summary>
- /// Returns true if the given character is a valid drive letter
- /// </summary>
- internal static bool IsValidDriveChar(char value)
- {
- return (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z');
- }
-
- internal static bool EndsWithPeriodOrSpace(string? path)
- {
- if (string.IsNullOrEmpty(path))
- return false;
-
- char c = path[path.Length - 1];
- return c == ' ' || c == '.';
- }
-
- /// <summary>
- /// Adds the extended path prefix (\\?\) if not already a device path, IF the path is not relative,
- /// AND the path is more than 259 characters. (> MAX_PATH + null). This will also insert the extended
- /// prefix if the path ends with a period or a space. Trailing periods and spaces are normally eaten
- /// away from paths during normalization, but if we see such a path at this point it should be
- /// normalized and has retained the final characters. (Typically from one of the *Info classes)
- /// </summary>
- [return: NotNullIfNotNull("path")]
- internal static string? EnsureExtendedPrefixIfNeeded(string? path)
- {
- if (path != null && (path.Length >= MaxShortPath || EndsWithPeriodOrSpace(path)))
- {
- return EnsureExtendedPrefix(path);
- }
- else
- {
- return path;
- }
- }
-
- /// <summary>
- /// Adds the extended path prefix (\\?\) if not relative or already a device path.
- /// </summary>
- internal static string EnsureExtendedPrefix(string path)
- {
- // Putting the extended prefix on the path changes the processing of the path. It won't get normalized, which
- // means adding to relative paths will prevent them from getting the appropriate current directory inserted.
-
- // If it already has some variant of a device path (\??\, \\?\, \\.\, //./, etc.) we don't need to change it
- // as it is either correct or we will be changing the behavior. When/if Windows supports long paths implicitly
- // in the future we wouldn't want normalization to come back and break existing code.
-
- // In any case, all internal usages should be hitting normalize path (Path.GetFullPath) before they hit this
- // shimming method. (Or making a change that doesn't impact normalization, such as adding a filename to a
- // normalized base path.)
- if (IsPartiallyQualified(path.AsSpan()) || IsDevice(path.AsSpan()))
- return path;
-
- // Given \\server\share in longpath becomes \\?\UNC\server\share
- if (path.StartsWith(UncPathPrefix, StringComparison.OrdinalIgnoreCase))
- return path.Insert(2, UncExtendedPrefixToInsert);
-
- return ExtendedPathPrefix + path;
- }
-
- /// <summary>
- /// Returns true if the path uses any of the DOS device path syntaxes. ("\\.\", "\\?\", or "\??\")
- /// </summary>
- internal static bool IsDevice(ReadOnlySpan<char> path)
- {
- // If the path begins with any two separators is will be recognized and normalized and prepped with
- // "\??\" for internal usage correctly. "\??\" is recognized and handled, "/??/" is not.
- return IsExtended(path)
- ||
- (
- path.Length >= DevicePrefixLength
- && IsDirectorySeparator(path[0])
- && IsDirectorySeparator(path[1])
- && (path[2] == '.' || path[2] == '?')
- && IsDirectorySeparator(path[3])
- );
- }
-
- /// <summary>
- /// Returns true if the path is a device UNC (\\?\UNC\, \\.\UNC\)
- /// </summary>
- internal static bool IsDeviceUNC(ReadOnlySpan<char> path)
- {
- return path.Length >= UncExtendedPrefixLength
- && IsDevice(path)
- && IsDirectorySeparator(path[7])
- && path[4] == 'U'
- && path[5] == 'N'
- && path[6] == 'C';
- }
-
- /// <summary>
- /// Returns true if the path uses the canonical form of extended syntax ("\\?\" or "\??\"). If the
- /// path matches exactly (cannot use alternate directory separators) Windows will skip normalization
- /// and path length checks.
- /// </summary>
- internal static bool IsExtended(ReadOnlySpan<char> path)
- {
- // While paths like "//?/C:/" will work, they're treated the same as "\\.\" paths.
- // Skipping of normalization will *only* occur if back slashes ('\') are used.
- return path.Length >= DevicePrefixLength
- && path[0] == '\\'
- && (path[1] == '\\' || path[1] == '?')
- && path[2] == '?'
- && path[3] == '\\';
- }
-
- /// <summary>
- /// Check for known wildcard characters. '*' and '?' are the most common ones.
- /// </summary>
- internal static bool HasWildCardCharacters(ReadOnlySpan<char> path)
- {
- // Question mark is part of dos device syntax so we have to skip if we are
- int startIndex = IsDevice(path) ? ExtendedPathPrefix.Length : 0;
-
- // [MS - FSA] 2.1.4.4 Algorithm for Determining if a FileName Is in an Expression
- // https://msdn.microsoft.com/en-us/library/ff469270.aspx
- for (int i = startIndex; i < path.Length; i++)
- {
- char c = path[i];
- if (c <= '?') // fast path for common case - '?' is highest wildcard character
- {
- if (c == '\"' || c == '<' || c == '>' || c == '*' || c == '?')
- return true;
- }
- }
-
- return false;
- }
-
- /// <summary>
- /// Gets the length of the root of the path (drive, share, etc.).
- /// </summary>
- internal static int GetRootLength(ReadOnlySpan<char> path)
- {
- int pathLength = path.Length;
- int i = 0;
-
- bool deviceSyntax = IsDevice(path);
- bool deviceUnc = deviceSyntax && IsDeviceUNC(path);
-
- if ((!deviceSyntax || deviceUnc) && pathLength > 0 && IsDirectorySeparator(path[0]))
- {
- // UNC or simple rooted path (e.g. "\foo", NOT "\\?\C:\foo")
- if (deviceUnc || (pathLength > 1 && IsDirectorySeparator(path[1])))
- {
- // UNC (\\?\UNC\ or \\), scan past server\share
-
- // Start past the prefix ("\\" or "\\?\UNC\")
- i = deviceUnc ? UncExtendedPrefixLength : UncPrefixLength;
-
- // Skip two separators at most
- int n = 2;
- while (i < pathLength && (!IsDirectorySeparator(path[i]) || --n > 0))
- i++;
- }
- else
- {
- // Current drive rooted (e.g. "\foo")
- i = 1;
- }
- }
- else if (deviceSyntax)
- {
- // Device path (e.g. "\\?\.", "\\.\")
- // Skip any characters following the prefix that aren't a separator
- i = DevicePrefixLength;
- while (i < pathLength && !IsDirectorySeparator(path[i]))
- i++;
-
- // If there is another separator take it, as long as we have had at least one
- // non-separator after the prefix (e.g. don't take "\\?\\", but take "\\?\a\")
- if (i < pathLength && i > DevicePrefixLength && IsDirectorySeparator(path[i]))
- i++;
- }
- else if (pathLength >= 2
- && path[1] == VolumeSeparatorChar
- && IsValidDriveChar(path[0]))
- {
- // Valid drive specified path ("C:", "D:", etc.)
- i = 2;
-
- // If the colon is followed by a directory separator, move past it (e.g "C:\")
- if (pathLength > 2 && IsDirectorySeparator(path[2]))
- i++;
- }
-
- return i;
- }
-
- /// <summary>
- /// Returns true if the path specified is relative to the current drive or working directory.
- /// Returns false if the path is fixed to a specific drive or UNC path. This method does no
- /// validation of the path (URIs will be returned as relative as a result).
- /// </summary>
- /// <remarks>
- /// Handles paths that use the alternate directory separator. It is a frequent mistake to
- /// assume that rooted paths (Path.IsPathRooted) are not relative. This isn't the case.
- /// "C:a" is drive relative- meaning that it will be resolved against the current directory
- /// for C: (rooted, but relative). "C:\a" is rooted and not relative (the current directory
- /// will not be used to modify the path).
- /// </remarks>
- internal static bool IsPartiallyQualified(ReadOnlySpan<char> path)
- {
- if (path.Length < 2)
- {
- // It isn't fixed, it must be relative. There is no way to specify a fixed
- // path with one character (or less).
- return true;
- }
-
- if (IsDirectorySeparator(path[0]))
- {
- // There is no valid way to specify a relative path with two initial slashes or
- // \? as ? isn't valid for drive relative paths and \??\ is equivalent to \\?\
- return !(path[1] == '?' || IsDirectorySeparator(path[1]));
- }
-
- // The only way to specify a fixed path that doesn't begin with two slashes
- // is the drive, colon, slash format- i.e. C:\
- return !((path.Length >= 3)
- && (path[1] == VolumeSeparatorChar)
- && IsDirectorySeparator(path[2])
- // To match old behavior we'll check the drive character for validity as the path is technically
- // not qualified if you don't have a valid drive. "=:\" is the "=" file's default data stream.
- && IsValidDriveChar(path[0]));
- }
-
- /// <summary>
- /// True if the given character is a directory separator.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool IsDirectorySeparator(char c)
- {
- return c == DirectorySeparatorChar || c == AltDirectorySeparatorChar;
- }
-
- /// <summary>
- /// Normalize separators in the given path. Converts forward slashes into back slashes and compresses slash runs, keeping initial 2 if present.
- /// Also trims initial whitespace in front of "rooted" paths (see PathStartSkip).
- ///
- /// This effectively replicates the behavior of the legacy NormalizePath when it was called with fullCheck=false and expandShortpaths=false.
- /// The current NormalizePath gets directory separator normalization from Win32's GetFullPathName(), which will resolve relative paths and as
- /// such can't be used here (and is overkill for our uses).
- ///
- /// Like the current NormalizePath this will not try and analyze periods/spaces within directory segments.
- /// </summary>
- /// <remarks>
- /// The only callers that used to use Path.Normalize(fullCheck=false) were Path.GetDirectoryName() and Path.GetPathRoot(). Both usages do
- /// not need trimming of trailing whitespace here.
- ///
- /// GetPathRoot() could technically skip normalizing separators after the second segment- consider as a future optimization.
- ///
- /// For legacy desktop behavior with ExpandShortPaths:
- /// - It has no impact on GetPathRoot() so doesn't need consideration.
- /// - It could impact GetDirectoryName(), but only if the path isn't relative (C:\ or \\Server\Share).
- ///
- /// In the case of GetDirectoryName() the ExpandShortPaths behavior was undocumented and provided inconsistent results if the path was
- /// fixed/relative. For example: "C:\PROGRA~1\A.TXT" would return "C:\Program Files" while ".\PROGRA~1\A.TXT" would return ".\PROGRA~1". If you
- /// ultimately call GetFullPath() this doesn't matter, but if you don't or have any intermediate string handling could easily be tripped up by
- /// this undocumented behavior.
- ///
- /// We won't match this old behavior because:
- ///
- /// 1. It was undocumented
- /// 2. It was costly (extremely so if it actually contained '~')
- /// 3. Doesn't play nice with string logic
- /// 4. Isn't a cross-plat friendly concept/behavior
- /// </remarks>
- internal static string NormalizeDirectorySeparators(string path)
- {
- if (string.IsNullOrEmpty(path))
- return path;
-
- char current;
-
- // Make a pass to see if we need to normalize so we can potentially skip allocating
- bool normalized = true;
-
- for (int i = 0; i < path.Length; i++)
- {
- current = path[i];
- if (IsDirectorySeparator(current)
- && (current != DirectorySeparatorChar
- // Check for sequential separators past the first position (we need to keep initial two for UNC/extended)
- || (i > 0 && i + 1 < path.Length && IsDirectorySeparator(path[i + 1]))))
- {
- normalized = false;
- break;
- }
- }
-
- if (normalized)
- return path;
-
- var builder = new ValueStringBuilder(stackalloc char[MaxShortPath]);
-
- int start = 0;
- if (IsDirectorySeparator(path[start]))
- {
- start++;
- builder.Append(DirectorySeparatorChar);
- }
-
- for (int i = start; i < path.Length; i++)
- {
- current = path[i];
-
- // If we have a separator
- if (IsDirectorySeparator(current))
- {
- // If the next is a separator, skip adding this
- if (i + 1 < path.Length && IsDirectorySeparator(path[i + 1]))
- {
- continue;
- }
-
- // Ensure it is the primary separator
- current = DirectorySeparatorChar;
- }
-
- builder.Append(current);
- }
-
- return builder.ToString();
- }
-
- /// <summary>
- /// Returns true if the path is effectively empty for the current OS.
- /// For unix, this is empty or null. For Windows, this is empty, null, or
- /// just spaces ((char)32).
- /// </summary>
- internal static bool IsEffectivelyEmpty(ReadOnlySpan<char> path)
- {
- if (path.IsEmpty)
- return true;
-
- foreach (char c in path)
- {
- if (c != ' ')
- return false;
- }
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.cs b/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.cs
deleted file mode 100644
index dfea93658d3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/PathInternal.cs
+++ /dev/null
@@ -1,248 +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 System.Diagnostics;
-using System.Text;
-
-namespace System.IO
-{
- /// <summary>Contains internal path helpers that are shared between many projects.</summary>
- internal static partial class PathInternal
- {
- /// <summary>
- /// Returns true if the path starts in a directory separator.
- /// </summary>
- internal static bool StartsWithDirectorySeparator(ReadOnlySpan<char> path) => path.Length > 0 && IsDirectorySeparator(path[0]);
-
-#if MS_IO_REDIST
- internal static string EnsureTrailingSeparator(string path)
- => EndsInDirectorySeparator(path) ? path : path + DirectorySeparatorCharAsString;
-#else
- internal static string EnsureTrailingSeparator(string path)
- => EndsInDirectorySeparator(path.AsSpan()) ? path : path + DirectorySeparatorCharAsString;
-#endif
-
- internal static bool IsRoot(ReadOnlySpan<char> path)
- => path.Length == GetRootLength(path);
-
- /// <summary>
- /// Get the common path length from the start of the string.
- /// </summary>
- internal static int GetCommonPathLength(string first, string second, bool ignoreCase)
- {
- int commonChars = EqualStartingCharacterCount(first, second, ignoreCase: ignoreCase);
-
- // If nothing matches
- if (commonChars == 0)
- return commonChars;
-
- // Or we're a full string and equal length or match to a separator
- if (commonChars == first.Length
- && (commonChars == second.Length || IsDirectorySeparator(second[commonChars])))
- return commonChars;
-
- if (commonChars == second.Length && IsDirectorySeparator(first[commonChars]))
- return commonChars;
-
- // It's possible we matched somewhere in the middle of a segment e.g. C:\Foodie and C:\Foobar.
- while (commonChars > 0 && !IsDirectorySeparator(first[commonChars - 1]))
- commonChars--;
-
- return commonChars;
- }
-
- /// <summary>
- /// Gets the count of common characters from the left optionally ignoring case
- /// </summary>
- internal static unsafe int EqualStartingCharacterCount(string first, string second, bool ignoreCase)
- {
- if (string.IsNullOrEmpty(first) || string.IsNullOrEmpty(second)) return 0;
-
- int commonChars = 0;
-
- fixed (char* f = first)
- fixed (char* s = second)
- {
- char* l = f;
- char* r = s;
- char* leftEnd = l + first.Length;
- char* rightEnd = r + second.Length;
-
- while (l != leftEnd && r != rightEnd
- && (*l == *r || (ignoreCase && char.ToUpperInvariant(*l) == char.ToUpperInvariant(*r))))
- {
- commonChars++;
- l++;
- r++;
- }
- }
-
- return commonChars;
- }
-
- /// <summary>
- /// Returns true if the two paths have the same root
- /// </summary>
- internal static bool AreRootsEqual(string first, string second, StringComparison comparisonType)
- {
- int firstRootLength = GetRootLength(first.AsSpan());
- int secondRootLength = GetRootLength(second.AsSpan());
-
- return firstRootLength == secondRootLength
- && string.Compare(
- strA: first,
- indexA: 0,
- strB: second,
- indexB: 0,
- length: firstRootLength,
- comparisonType: comparisonType) == 0;
- }
-
- /// <summary>
- /// Try to remove relative segments from the given path (without combining with a root).
- /// </summary>
- /// <param name="path">Input path</param>
- /// <param name="rootLength">The length of the root of the given path</param>
- internal static string RemoveRelativeSegments(string path, int rootLength)
- {
- var sb = new ValueStringBuilder(stackalloc char[260 /* PathInternal.MaxShortPath */]);
-
- if (RemoveRelativeSegments(path.AsSpan(), rootLength, ref sb))
- {
- path = sb.ToString();
- }
-
- sb.Dispose();
- return path;
- }
-
- /// <summary>
- /// Try to remove relative segments from the given path (without combining with a root).
- /// </summary>
- /// <param name="path">Input path</param>
- /// <param name="rootLength">The length of the root of the given path</param>
- /// <param name="sb">String builder that will store the result</param>
- /// <returns>"true" if the path was modified</returns>
- internal static bool RemoveRelativeSegments(ReadOnlySpan<char> path, int rootLength, ref ValueStringBuilder sb)
- {
- Debug.Assert(rootLength > 0);
- bool flippedSeparator = false;
-
- int skip = rootLength;
- // We treat "\.." , "\." and "\\" as a relative segment. We want to collapse the first separator past the root presuming
- // the root actually ends in a separator. Otherwise the first segment for RemoveRelativeSegments
- // in cases like "\\?\C:\.\" and "\\?\C:\..\", the first segment after the root will be ".\" and "..\" which is not considered as a relative segment and hence not be removed.
- if (PathInternal.IsDirectorySeparator(path[skip - 1]))
- skip--;
-
- // Remove "//", "/./", and "/../" from the path by copying each character to the output,
- // except the ones we're removing, such that the builder contains the normalized path
- // at the end.
- if (skip > 0)
- {
- sb.Append(path.Slice(0, skip));
- }
-
- for (int i = skip; i < path.Length; i++)
- {
- char c = path[i];
-
- if (PathInternal.IsDirectorySeparator(c) && i + 1 < path.Length)
- {
- // Skip this character if it's a directory separator and if the next character is, too,
- // e.g. "parent//child" => "parent/child"
- if (PathInternal.IsDirectorySeparator(path[i + 1]))
- {
- continue;
- }
-
- // Skip this character and the next if it's referring to the current directory,
- // e.g. "parent/./child" => "parent/child"
- if ((i + 2 == path.Length || PathInternal.IsDirectorySeparator(path[i + 2])) &&
- path[i + 1] == '.')
- {
- i++;
- continue;
- }
-
- // Skip this character and the next two if it's referring to the parent directory,
- // e.g. "parent/child/../grandchild" => "parent/grandchild"
- if (i + 2 < path.Length &&
- (i + 3 == path.Length || PathInternal.IsDirectorySeparator(path[i + 3])) &&
- path[i + 1] == '.' && path[i + 2] == '.')
- {
- // Unwind back to the last slash (and if there isn't one, clear out everything).
- int s;
- for (s = sb.Length - 1; s >= skip; s--)
- {
- if (PathInternal.IsDirectorySeparator(sb[s]))
- {
- sb.Length = (i + 3 >= path.Length && s == skip) ? s + 1 : s; // to avoid removing the complete "\tmp\" segment in cases like \\?\C:\tmp\..\, C:\tmp\..
- break;
- }
- }
- if (s < skip)
- {
- sb.Length = skip;
- }
-
- i += 2;
- continue;
- }
- }
-
- // Normalize the directory separator if needed
- if (c != PathInternal.DirectorySeparatorChar && c == PathInternal.AltDirectorySeparatorChar)
- {
- c = PathInternal.DirectorySeparatorChar;
- flippedSeparator = true;
- }
-
- sb.Append(c);
- }
-
- // If we haven't changed the source path, return the original
- if (!flippedSeparator && sb.Length == path.Length)
- {
- return false;
- }
-
- // We may have eaten the trailing separator from the root when we started and not replaced it
- if (skip != rootLength && sb.Length < rootLength)
- {
- sb.Append(path[rootLength - 1]);
- }
-
- return true;
- }
-
- /// <summary>
- /// Trims one trailing directory separator beyond the root of the path.
- /// </summary>
- internal static string TrimEndingDirectorySeparator(string path) =>
- EndsInDirectorySeparator(path) && !IsRoot(path.AsSpan()) ?
- path.Substring(0, path.Length - 1) :
- path;
-
- /// <summary>
- /// Returns true if the path ends in a directory separator.
- /// </summary>
- internal static bool EndsInDirectorySeparator(string path) =>
- !string.IsNullOrEmpty(path) && IsDirectorySeparator(path[path.Length - 1]);
-
- /// <summary>
- /// Trims one trailing directory separator beyond the root of the path.
- /// </summary>
- internal static ReadOnlySpan<char> TrimEndingDirectorySeparator(ReadOnlySpan<char> path) =>
- EndsInDirectorySeparator(path) && !IsRoot(path) ?
- path.Slice(0, path.Length - 1) :
- path;
-
- /// <summary>
- /// Returns true if the path ends in a directory separator.
- /// </summary>
- internal static bool EndsInDirectorySeparator(ReadOnlySpan<char> path) =>
- path.Length > 0 && IsDirectorySeparator(path[path.Length - 1]);
- }
-} \ No newline at end of file
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/PathTooLongException.cs b/netcore/System.Private.CoreLib/shared/System/IO/PathTooLongException.cs
deleted file mode 100644
index 3a69930a911..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/PathTooLongException.cs
+++ /dev/null
@@ -1,36 +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 System.Runtime.Serialization;
-
-namespace System.IO
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class PathTooLongException : IOException
- {
- public PathTooLongException()
- : base(SR.IO_PathTooLong)
- {
- HResult = HResults.COR_E_PATHTOOLONG;
- }
-
- public PathTooLongException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_PATHTOOLONG;
- }
-
- public PathTooLongException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_PATHTOOLONG;
- }
-
- protected PathTooLongException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/PersistedFiles.Names.Unix.cs b/netcore/System.Private.CoreLib/shared/System/IO/PersistedFiles.Names.Unix.cs
deleted file mode 100644
index 8984f1aee32..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/PersistedFiles.Names.Unix.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.IO
-{
- internal static partial class PersistedFiles
- {
- // Temporary data, /tmp/.dotnet/corefx
- // User-persisted data, ~/.dotnet/corefx/
- // System-persisted data, /etc/dotnet/corefx/
-
- internal const string TopLevelDirectory = "dotnet";
- internal const string TopLevelHiddenDirectory = "." + TopLevelDirectory;
- internal const string SecondLevelDirectory = "corefx";
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/PersistedFiles.Unix.cs b/netcore/System.Private.CoreLib/shared/System/IO/PersistedFiles.Unix.cs
deleted file mode 100644
index a610614f276..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/PersistedFiles.Unix.cs
+++ /dev/null
@@ -1,164 +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.
-
-#nullable enable
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.IO
-{
- internal static partial class PersistedFiles
- {
- private static string? s_userProductDirectory;
-
- /// <summary>
- /// Get the location of where to persist information for a particular aspect of the framework,
- /// such as "cryptography".
- /// </summary>
- /// <param name="featureName">The directory name for the feature</param>
- /// <returns>A path within the user's home directory for persisting data for the feature</returns>
- internal static string GetUserFeatureDirectory(string featureName)
- {
- if (s_userProductDirectory == null)
- {
- EnsureUserDirectories();
- }
-
- return Path.Combine(s_userProductDirectory!, featureName);
- }
-
- /// <summary>
- /// Get the location of where to persist information for a particular aspect of a feature of
- /// the framework, such as "x509stores" within "cryptography".
- /// </summary>
- /// <param name="featureName">The directory name for the feature</param>
- /// <param name="subFeatureName">The directory name for the sub-feature</param>
- /// <returns>A path within the user's home directory for persisting data for the sub-feature</returns>
- internal static string GetUserFeatureDirectory(string featureName, string subFeatureName)
- {
- if (s_userProductDirectory == null)
- {
- EnsureUserDirectories();
- }
-
- return Path.Combine(s_userProductDirectory!, featureName, subFeatureName);
- }
-
- /// <summary>
- /// Get the location of where to persist information for a particular aspect of the framework,
- /// with a lot of hierarchy, such as ["cryptography", "x509stores", "my"]
- /// </summary>
- /// <param name="featurePathParts">A non-empty set of directories to use for the storage hierarchy</param>
- /// <returns>A path within the user's home directory for persisting data for the feature</returns>
- internal static string GetUserFeatureDirectory(params string[] featurePathParts)
- {
- Debug.Assert(featurePathParts != null);
- Debug.Assert(featurePathParts.Length > 0);
-
- if (s_userProductDirectory == null)
- {
- EnsureUserDirectories();
- }
-
- return Path.Combine(s_userProductDirectory!, Path.Combine(featurePathParts));
- }
-
- private static void EnsureUserDirectories()
- {
- string? userHomeDirectory = GetHomeDirectory();
-
- if (string.IsNullOrEmpty(userHomeDirectory))
- {
- throw new InvalidOperationException(SR.PersistedFiles_NoHomeDirectory);
- }
-
- s_userProductDirectory = Path.Combine(
- userHomeDirectory,
- TopLevelHiddenDirectory,
- SecondLevelDirectory);
- }
-
- /// <summary>Gets the current user's home directory.</summary>
- /// <returns>The path to the home directory, or null if it could not be determined.</returns>
- internal static string? GetHomeDirectory()
- {
- // First try to get the user's home directory from the HOME environment variable.
- // This should work in most cases.
- string? userHomeDirectory = Environment.GetEnvironmentVariable("HOME");
- if (!string.IsNullOrEmpty(userHomeDirectory))
- return userHomeDirectory;
-
- // In initialization conditions, however, the "HOME" environment variable may
- // not yet be set. For such cases, consult with the password entry.
- unsafe
- {
- // First try with a buffer that should suffice for 99% of cases.
- // Note that, theoretically, userHomeDirectory may be null in the success case
- // if we simply couldn't find a home directory for the current user.
- // In that case, we pass back the null value and let the caller decide
- // what to do.
- const int BufLen = Interop.Sys.Passwd.InitialBufferSize;
- byte* stackBuf = stackalloc byte[BufLen];
- if (TryGetHomeDirectoryFromPasswd(stackBuf, BufLen, out userHomeDirectory))
- return userHomeDirectory;
-
- // Fallback to heap allocations if necessary, growing the buffer until
- // we succeed. TryGetHomeDirectory will throw if there's an unexpected error.
- int lastBufLen = BufLen;
- while (true)
- {
- lastBufLen *= 2;
- byte[] heapBuf = new byte[lastBufLen];
- fixed (byte* buf = &heapBuf[0])
- {
- if (TryGetHomeDirectoryFromPasswd(buf, heapBuf.Length, out userHomeDirectory))
- return userHomeDirectory;
- }
- }
- }
- }
-
- /// <summary>Wrapper for getpwuid_r.</summary>
- /// <param name="buf">The scratch buffer to pass into getpwuid_r.</param>
- /// <param name="bufLen">The length of <paramref name="buf"/>.</param>
- /// <param name="path">The resulting path; null if the user didn't have an entry.</param>
- /// <returns>true if the call was successful (path may still be null); false is a larger buffer is needed.</returns>
- private static unsafe bool TryGetHomeDirectoryFromPasswd(byte* buf, int bufLen, out string? path)
- {
- // Call getpwuid_r to get the passwd struct
- Interop.Sys.Passwd passwd;
- int error = Interop.Sys.GetPwUidR(Interop.Sys.GetEUid(), out passwd, buf, bufLen);
-
- // If the call succeeds, give back the home directory path retrieved
- if (error == 0)
- {
- Debug.Assert(passwd.HomeDirectory != null);
- path = Marshal.PtrToStringAnsi((IntPtr)passwd.HomeDirectory);
- return true;
- }
-
- // If the current user's entry could not be found, give back null
- // path, but still return true as false indicates the buffer was
- // too small.
- if (error == -1)
- {
- path = null;
- return true;
- }
-
- var errorInfo = new Interop.ErrorInfo(error);
-
- // If the call failed because the buffer was too small, return false to
- // indicate the caller should try again with a larger buffer.
- if (errorInfo.Error == Interop.Error.ERANGE)
- {
- path = null;
- return false;
- }
-
- // Otherwise, fail.
- throw new IOException(errorInfo.GetErrorMessage(), errorInfo.RawErrno);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/PinnedBufferMemoryStream.cs b/netcore/System.Private.CoreLib/shared/System/IO/PinnedBufferMemoryStream.cs
deleted file mode 100644
index 9c002974786..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/PinnedBufferMemoryStream.cs
+++ /dev/null
@@ -1,61 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: Pins a byte[], exposing it as an unmanaged memory
-** stream. Used in ResourceReader for corner cases.
-**
-**
-===========================================================*/
-
-using System.Runtime.InteropServices;
-using System.Diagnostics;
-
-namespace System.IO
-{
- internal sealed unsafe class PinnedBufferMemoryStream : UnmanagedMemoryStream
- {
- private readonly byte[] _array;
- private GCHandle _pinningHandle;
-
- internal PinnedBufferMemoryStream(byte[] array)
- {
- Debug.Assert(array != null, "Array can't be null");
-
- _array = array;
- _pinningHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
- // Now the byte[] is pinned for the lifetime of this instance.
- // But I also need to get a pointer to that block of memory...
- int len = array.Length;
- fixed (byte* ptr = &MemoryMarshal.GetReference((Span<byte>)array))
- Initialize(ptr, len, len, FileAccess.Read);
- }
-
-#if !NETSTANDARD2_0
- public override int Read(Span<byte> buffer) => ReadCore(buffer);
-
- public override void Write(ReadOnlySpan<byte> buffer) => WriteCore(buffer);
-#endif
-
- ~PinnedBufferMemoryStream()
- {
- Dispose(false);
- }
-
- protected override void Dispose(bool disposing)
- {
- if (_pinningHandle.IsAllocated)
- {
- _pinningHandle.Free();
- }
-
- base.Dispose(disposing);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/SeekOrigin.cs b/netcore/System.Private.CoreLib/shared/System/IO/SeekOrigin.cs
deleted file mode 100644
index 3798a0ce702..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/SeekOrigin.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.IO
-{
- // Provides seek reference points. To seek to the end of a stream,
- // call stream.Seek(0, SeekOrigin.End).
- public enum SeekOrigin
- {
- // These constants match Win32's FILE_BEGIN, FILE_CURRENT, and FILE_END
- Begin = 0,
- Current = 1,
- End = 2,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/Stream.cs b/netcore/System.Private.CoreLib/shared/System/IO/Stream.cs
deleted file mode 100644
index cf05e669ba3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/Stream.cs
+++ /dev/null
@@ -1,1400 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: Abstract base class for all Streams. Provides
-** default implementations of asynchronous reads & writes, in
-** terms of the synchronous reads & writes (and vice versa).
-**
-**
-===========================================================*/
-
-using System.Buffers;
-using System.Diagnostics;
-using System.Runtime.ExceptionServices;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.IO
-{
- public abstract partial class Stream : MarshalByRefObject, IDisposable, IAsyncDisposable
- {
- public static readonly Stream Null = new NullStream();
-
- // We pick a value that is the largest multiple of 4096 that is still smaller than the large object heap threshold (85K).
- // The CopyTo/CopyToAsync buffer is short-lived and is likely to be collected at Gen0, and it offers a significant
- // improvement in Copy performance.
- private const int DefaultCopyBufferSize = 81920;
-
- // To implement Async IO operations on streams that don't support async IO
-
- private ReadWriteTask? _activeReadWriteTask;
- private SemaphoreSlim? _asyncActiveSemaphore;
-
- internal SemaphoreSlim EnsureAsyncActiveSemaphoreInitialized()
- {
- // Lazily-initialize _asyncActiveSemaphore. As we're never accessing the SemaphoreSlim's
- // WaitHandle, we don't need to worry about Disposing it.
- return LazyInitializer.EnsureInitialized(ref _asyncActiveSemaphore, () => new SemaphoreSlim(1, 1));
- }
-
- public abstract bool CanRead
- {
- get;
- }
-
- // If CanSeek is false, Position, Seek, Length, and SetLength should throw.
- public abstract bool CanSeek
- {
- get;
- }
-
- public virtual bool CanTimeout => false;
-
- public abstract bool CanWrite
- {
- get;
- }
-
- public abstract long Length
- {
- get;
- }
-
- public abstract long Position
- {
- get;
- set;
- }
-
- public virtual int ReadTimeout
- {
- get => throw new InvalidOperationException(SR.InvalidOperation_TimeoutsNotSupported);
- set => throw new InvalidOperationException(SR.InvalidOperation_TimeoutsNotSupported);
- }
-
- public virtual int WriteTimeout
- {
- get => throw new InvalidOperationException(SR.InvalidOperation_TimeoutsNotSupported);
- set => throw new InvalidOperationException(SR.InvalidOperation_TimeoutsNotSupported);
- }
-
- public Task CopyToAsync(Stream destination)
- {
- int bufferSize = GetCopyBufferSize();
-
- return CopyToAsync(destination, bufferSize);
- }
-
- public Task CopyToAsync(Stream destination, int bufferSize)
- {
- return CopyToAsync(destination, bufferSize, CancellationToken.None);
- }
-
- public Task CopyToAsync(Stream destination, CancellationToken cancellationToken)
- {
- int bufferSize = GetCopyBufferSize();
-
- return CopyToAsync(destination, bufferSize, cancellationToken);
- }
-
- public virtual Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
- {
- StreamHelpers.ValidateCopyToArgs(this, destination, bufferSize);
-
- return CopyToAsyncInternal(destination, bufferSize, cancellationToken);
- }
-
- private async Task CopyToAsyncInternal(Stream destination, int bufferSize, CancellationToken cancellationToken)
- {
- byte[] buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
- try
- {
- while (true)
- {
- int bytesRead = await ReadAsync(new Memory<byte>(buffer), cancellationToken).ConfigureAwait(false);
- if (bytesRead == 0) break;
- await destination.WriteAsync(new ReadOnlyMemory<byte>(buffer, 0, bytesRead), cancellationToken).ConfigureAwait(false);
- }
- }
- finally
- {
- ArrayPool<byte>.Shared.Return(buffer);
- }
- }
-
- // Reads the bytes from the current stream and writes the bytes to
- // the destination stream until all bytes are read, starting at
- // the current position.
- public void CopyTo(Stream destination)
- {
- int bufferSize = GetCopyBufferSize();
-
- CopyTo(destination, bufferSize);
- }
-
- public virtual void CopyTo(Stream destination, int bufferSize)
- {
- StreamHelpers.ValidateCopyToArgs(this, destination, bufferSize);
-
- byte[] buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
- try
- {
- int read;
- while ((read = Read(buffer, 0, buffer.Length)) != 0)
- {
- destination.Write(buffer, 0, read);
- }
- }
- finally
- {
- ArrayPool<byte>.Shared.Return(buffer);
- }
- }
-
- private int GetCopyBufferSize()
- {
- int bufferSize = DefaultCopyBufferSize;
-
- if (CanSeek)
- {
- long length = Length;
- long position = Position;
- if (length <= position) // Handles negative overflows
- {
- // There are no bytes left in the stream to copy.
- // However, because CopyTo{Async} is virtual, we need to
- // ensure that any override is still invoked to provide its
- // own validation, so we use the smallest legal buffer size here.
- bufferSize = 1;
- }
- else
- {
- long remaining = length - position;
- if (remaining > 0)
- {
- // In the case of a positive overflow, stick to the default size
- bufferSize = (int)Math.Min(bufferSize, remaining);
- }
- }
- }
-
- return bufferSize;
- }
-
- public virtual void CopyTo(ReadOnlySpanAction<byte, object?> callback, object? state, int bufferSize)
- {
- if (callback == null) throw new ArgumentNullException(nameof(callback));
-
- CopyTo(new WriteCallbackStream(callback, state), bufferSize);
- }
-
- public virtual Task CopyToAsync(Func<ReadOnlyMemory<byte>, object?, CancellationToken, ValueTask> callback, object? state, int bufferSize, CancellationToken cancellationToken)
- {
- if (callback == null) throw new ArgumentNullException(nameof(callback));
-
- return CopyToAsync(new WriteCallbackStream(callback, state), bufferSize, cancellationToken);
- }
-
- private sealed class WriteCallbackStream : Stream
- {
- private readonly ReadOnlySpanAction<byte, object?>? _action;
- private readonly Func<ReadOnlyMemory<byte>, object?, CancellationToken, ValueTask>? _func;
- private readonly object? _state;
-
- public WriteCallbackStream(ReadOnlySpanAction<byte, object?> action, object? state)
- {
- _action = action;
- _state = state;
- }
-
- public WriteCallbackStream(Func<ReadOnlyMemory<byte>, object?, CancellationToken, ValueTask> func, object? state)
- {
- _func = func;
- _state = state;
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- Write(new ReadOnlySpan<byte>(buffer, offset, count));
- }
-
- public override void Write(ReadOnlySpan<byte> span)
- {
- if (_action != null)
- {
- _action(span, _state);
- return;
- }
-
- // In case a poorly implemented CopyToAsync(Stream, ...) method decides to call
- // the destination stream's Write rather than WriteAsync, we make it work, but this
- // does not need to be efficient.
- Debug.Assert(_func != null);
- _func(span.ToArray(), _state, CancellationToken.None).AsTask().GetAwaiter().GetResult();
-
- }
-
- public override Task WriteAsync(byte[] buffer, int offset, int length, CancellationToken cancellationToken)
- {
- return WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, length), cancellationToken).AsTask();
- }
-
- public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
- {
- if (_func != null)
- {
- return _func(buffer, _state, cancellationToken);
- }
-
- // In case a poorly implemented CopyTo(Stream, ...) method decides to call
- // the destination stream's WriteAsync rather than Write, we make it work,
- // but this does not need to be efficient.
- Debug.Assert(_action != null);
- try
- {
- cancellationToken.ThrowIfCancellationRequested();
- _action(buffer.Span, _state);
- return default;
- }
- catch (Exception e)
- {
- return new ValueTask(Task.FromException(e));
- }
- }
-
- public override bool CanRead => false;
- public override bool CanSeek => false;
- public override bool CanWrite => true;
- public override void Flush() { }
- public override Task FlushAsync(CancellationToken token) => Task.CompletedTask;
- public override long Length => throw new NotSupportedException();
- public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }
- public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException();
- public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
- public override void SetLength(long value) => throw new NotSupportedException();
- }
-
- // Stream used to require that all cleanup logic went into Close(),
- // which was thought up before we invented IDisposable. However, we
- // need to follow the IDisposable pattern so that users can write
- // sensible subclasses without needing to inspect all their base
- // classes, and without worrying about version brittleness, from a
- // base class switching to the Dispose pattern. We're moving
- // Stream to the Dispose(bool) pattern - that's where all subclasses
- // should put their cleanup now.
- public virtual void Close()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- public void Dispose()
- {
- Close();
- }
-
- protected virtual void Dispose(bool disposing)
- {
- // Note: Never change this to call other virtual methods on Stream
- // like Write, since the state on subclasses has already been
- // torn down. This is the last code to run on cleanup for a stream.
- }
-
- public virtual ValueTask DisposeAsync()
- {
- try
- {
- Dispose();
- return default;
- }
- catch (Exception exc)
- {
- return new ValueTask(Task.FromException(exc));
- }
- }
-
- public abstract void Flush();
-
- public Task FlushAsync()
- {
- return FlushAsync(CancellationToken.None);
- }
-
- public virtual Task FlushAsync(CancellationToken cancellationToken)
- {
- return Task.Factory.StartNew(state => ((Stream)state!).Flush(), this,
- cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
- }
-
- [Obsolete("CreateWaitHandle will be removed eventually. Please use \"new ManualResetEvent(false)\" instead.")]
- protected virtual WaitHandle CreateWaitHandle()
- {
- return new ManualResetEvent(false);
- }
-
- public virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
- {
- return BeginReadInternal(buffer, offset, count, callback, state, serializeAsynchronously: false, apm: true);
- }
-
- internal IAsyncResult BeginReadInternal(
- byte[] buffer, int offset, int count, AsyncCallback? callback, object? state,
- bool serializeAsynchronously, bool apm)
- {
- if (!CanRead) throw Error.GetReadNotSupported();
-
- // To avoid a race with a stream's position pointer & generating race conditions
- // with internal buffer indexes in our own streams that
- // don't natively support async IO operations when there are multiple
- // async requests outstanding, we will block the application's main
- // thread if it does a second IO request until the first one completes.
- SemaphoreSlim semaphore = EnsureAsyncActiveSemaphoreInitialized();
- Task? semaphoreTask = null;
- if (serializeAsynchronously)
- {
- semaphoreTask = semaphore.WaitAsync();
- }
- else
- {
- semaphore.Wait();
- }
-
- // Create the task to asynchronously do a Read. This task serves both
- // as the asynchronous work item and as the IAsyncResult returned to the user.
- var asyncResult = new ReadWriteTask(true /*isRead*/, apm, delegate
- {
- // The ReadWriteTask stores all of the parameters to pass to Read.
- // As we're currently inside of it, we can get the current task
- // and grab the parameters from it.
- var thisTask = Task.InternalCurrent as ReadWriteTask;
- Debug.Assert(thisTask != null && thisTask._stream != null && thisTask._buffer != null,
- "Inside ReadWriteTask, InternalCurrent should be the ReadWriteTask, and stream and buffer should be set");
-
- try
- {
- // Do the Read and return the number of bytes read
- return thisTask._stream.Read(thisTask._buffer, thisTask._offset, thisTask._count);
- }
- finally
- {
- // If this implementation is part of Begin/EndXx, then the EndXx method will handle
- // finishing the async operation. However, if this is part of XxAsync, then there won't
- // be an end method, and this task is responsible for cleaning up.
- if (!thisTask._apm)
- {
- thisTask._stream.FinishTrackingAsyncOperation();
- }
-
- thisTask.ClearBeginState(); // just to help alleviate some memory pressure
- }
- }, state, this, buffer, offset, count, callback);
-
- // Schedule it
- if (semaphoreTask != null)
- RunReadWriteTaskWhenReady(semaphoreTask, asyncResult);
- else
- RunReadWriteTask(asyncResult);
-
-
- return asyncResult; // return it
- }
-
- public virtual int EndRead(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- throw new ArgumentNullException(nameof(asyncResult));
-
- ReadWriteTask? readTask = _activeReadWriteTask;
-
- if (readTask == null)
- {
- throw new ArgumentException(SR.InvalidOperation_WrongAsyncResultOrEndReadCalledMultiple);
- }
- else if (readTask != asyncResult)
- {
- throw new InvalidOperationException(SR.InvalidOperation_WrongAsyncResultOrEndReadCalledMultiple);
- }
- else if (!readTask._isRead)
- {
- throw new ArgumentException(SR.InvalidOperation_WrongAsyncResultOrEndReadCalledMultiple);
- }
-
- try
- {
- return readTask.GetAwaiter().GetResult(); // block until completion, then get result / propagate any exception
- }
- finally
- {
- FinishTrackingAsyncOperation();
- }
- }
-
- public Task<int> ReadAsync(byte[] buffer, int offset, int count)
- {
- return ReadAsync(buffer, offset, count, CancellationToken.None);
- }
-
- public virtual Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- // If cancellation was requested, bail early with an already completed task.
- // Otherwise, return a task that represents the Begin/End methods.
- return cancellationToken.IsCancellationRequested
- ? Task.FromCanceled<int>(cancellationToken)
- : BeginEndReadAsync(buffer, offset, count);
- }
-
- public virtual ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
- {
- if (MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> array))
- {
- return new ValueTask<int>(ReadAsync(array.Array!, array.Offset, array.Count, cancellationToken));
- }
- else
- {
- byte[] sharedBuffer = ArrayPool<byte>.Shared.Rent(buffer.Length);
- return FinishReadAsync(ReadAsync(sharedBuffer, 0, buffer.Length, cancellationToken), sharedBuffer, buffer);
-
- static async ValueTask<int> FinishReadAsync(Task<int> readTask, byte[] localBuffer, Memory<byte> localDestination)
- {
- try
- {
- int result = await readTask.ConfigureAwait(false);
- new Span<byte>(localBuffer, 0, result).CopyTo(localDestination.Span);
- return result;
- }
- finally
- {
- ArrayPool<byte>.Shared.Return(localBuffer);
- }
- }
- }
- }
-
- private Task<int> BeginEndReadAsync(byte[] buffer, int offset, int count)
- {
- if (!HasOverriddenBeginEndRead())
- {
- // If the Stream does not override Begin/EndRead, then we can take an optimized path
- // that skips an extra layer of tasks / IAsyncResults.
- return (Task<int>)BeginReadInternal(buffer, offset, count, null, null, serializeAsynchronously: true, apm: false);
- }
-
- // Otherwise, we need to wrap calls to Begin/EndWrite to ensure we use the derived type's functionality.
- return TaskFactory<int>.FromAsyncTrim(
- this, new ReadWriteParameters { Buffer = buffer, Offset = offset, Count = count },
- (stream, args, callback, state) => stream.BeginRead(args.Buffer, args.Offset, args.Count, callback, state), // cached by compiler
- (stream, asyncResult) => stream.EndRead(asyncResult)); // cached by compiler
- }
-
- private struct ReadWriteParameters // struct for arguments to Read and Write calls
- {
- internal byte[] Buffer;
- internal int Offset;
- internal int Count;
- }
-
-
-
- public virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
- {
- return BeginWriteInternal(buffer, offset, count, callback, state, serializeAsynchronously: false, apm: true);
- }
-
- internal IAsyncResult BeginWriteInternal(
- byte[] buffer, int offset, int count, AsyncCallback? callback, object? state,
- bool serializeAsynchronously, bool apm)
- {
- if (!CanWrite) throw Error.GetWriteNotSupported();
-
- // To avoid a race condition with a stream's position pointer & generating conditions
- // with internal buffer indexes in our own streams that
- // don't natively support async IO operations when there are multiple
- // async requests outstanding, we will block the application's main
- // thread if it does a second IO request until the first one completes.
- SemaphoreSlim semaphore = EnsureAsyncActiveSemaphoreInitialized();
- Task? semaphoreTask = null;
- if (serializeAsynchronously)
- {
- semaphoreTask = semaphore.WaitAsync(); // kick off the asynchronous wait, but don't block
- }
- else
- {
- semaphore.Wait(); // synchronously wait here
- }
-
- // Create the task to asynchronously do a Write. This task serves both
- // as the asynchronous work item and as the IAsyncResult returned to the user.
- var asyncResult = new ReadWriteTask(false /*isRead*/, apm, delegate
- {
- // The ReadWriteTask stores all of the parameters to pass to Write.
- // As we're currently inside of it, we can get the current task
- // and grab the parameters from it.
- var thisTask = Task.InternalCurrent as ReadWriteTask;
- Debug.Assert(thisTask != null && thisTask._stream != null && thisTask._buffer != null,
- "Inside ReadWriteTask, InternalCurrent should be the ReadWriteTask, and stream and buffer should be set");
-
- try
- {
- // Do the Write
- thisTask._stream.Write(thisTask._buffer, thisTask._offset, thisTask._count);
- return 0; // not used, but signature requires a value be returned
- }
- finally
- {
- // If this implementation is part of Begin/EndXx, then the EndXx method will handle
- // finishing the async operation. However, if this is part of XxAsync, then there won't
- // be an end method, and this task is responsible for cleaning up.
- if (!thisTask._apm)
- {
- thisTask._stream.FinishTrackingAsyncOperation();
- }
-
- thisTask.ClearBeginState(); // just to help alleviate some memory pressure
- }
- }, state, this, buffer, offset, count, callback);
-
- // Schedule it
- if (semaphoreTask != null)
- RunReadWriteTaskWhenReady(semaphoreTask, asyncResult);
- else
- RunReadWriteTask(asyncResult);
-
- return asyncResult; // return it
- }
-
- private void RunReadWriteTaskWhenReady(Task asyncWaiter, ReadWriteTask readWriteTask)
- {
- Debug.Assert(readWriteTask != null);
- Debug.Assert(asyncWaiter != null);
-
- // If the wait has already completed, run the task.
- if (asyncWaiter.IsCompleted)
- {
- Debug.Assert(asyncWaiter.IsCompletedSuccessfully, "The semaphore wait should always complete successfully.");
- RunReadWriteTask(readWriteTask);
- }
- else // Otherwise, wait for our turn, and then run the task.
- {
- asyncWaiter.ContinueWith((t, state) =>
- {
- Debug.Assert(t.IsCompletedSuccessfully, "The semaphore wait should always complete successfully.");
- var rwt = (ReadWriteTask)state!;
- Debug.Assert(rwt._stream != null);
- rwt._stream.RunReadWriteTask(rwt); // RunReadWriteTask(readWriteTask);
- }, readWriteTask, default, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
- }
- }
-
- private void RunReadWriteTask(ReadWriteTask readWriteTask)
- {
- Debug.Assert(readWriteTask != null);
- Debug.Assert(_activeReadWriteTask == null, "Expected no other readers or writers");
-
- // Schedule the task. ScheduleAndStart must happen after the write to _activeReadWriteTask to avoid a race.
- // Internally, we're able to directly call ScheduleAndStart rather than Start, avoiding
- // two interlocked operations. However, if ReadWriteTask is ever changed to use
- // a cancellation token, this should be changed to use Start.
- _activeReadWriteTask = readWriteTask; // store the task so that EndXx can validate it's given the right one
- readWriteTask.m_taskScheduler = TaskScheduler.Default;
- readWriteTask.ScheduleAndStart(needsProtection: false);
- }
-
- private void FinishTrackingAsyncOperation()
- {
- _activeReadWriteTask = null;
- Debug.Assert(_asyncActiveSemaphore != null, "Must have been initialized in order to get here.");
- _asyncActiveSemaphore.Release();
- }
-
- public virtual void EndWrite(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- throw new ArgumentNullException(nameof(asyncResult));
-
- ReadWriteTask? writeTask = _activeReadWriteTask;
- if (writeTask == null)
- {
- throw new ArgumentException(SR.InvalidOperation_WrongAsyncResultOrEndWriteCalledMultiple);
- }
- else if (writeTask != asyncResult)
- {
- throw new InvalidOperationException(SR.InvalidOperation_WrongAsyncResultOrEndWriteCalledMultiple);
- }
- else if (writeTask._isRead)
- {
- throw new ArgumentException(SR.InvalidOperation_WrongAsyncResultOrEndWriteCalledMultiple);
- }
-
- try
- {
- writeTask.GetAwaiter().GetResult(); // block until completion, then propagate any exceptions
- Debug.Assert(writeTask.Status == TaskStatus.RanToCompletion);
- }
- finally
- {
- FinishTrackingAsyncOperation();
- }
- }
-
- // Task used by BeginRead / BeginWrite to do Read / Write asynchronously.
- // A single instance of this task serves four purposes:
- // 1. The work item scheduled to run the Read / Write operation
- // 2. The state holding the arguments to be passed to Read / Write
- // 3. The IAsyncResult returned from BeginRead / BeginWrite
- // 4. The completion action that runs to invoke the user-provided callback.
- // This last item is a bit tricky. Before the AsyncCallback is invoked, the
- // IAsyncResult must have completed, so we can't just invoke the handler
- // from within the task, since it is the IAsyncResult, and thus it's not
- // yet completed. Instead, we use AddCompletionAction to install this
- // task as its own completion handler. That saves the need to allocate
- // a separate completion handler, it guarantees that the task will
- // have completed by the time the handler is invoked, and it allows
- // the handler to be invoked synchronously upon the completion of the
- // task. This all enables BeginRead / BeginWrite to be implemented
- // with a single allocation.
- private sealed class ReadWriteTask : Task<int>, ITaskCompletionAction
- {
- internal readonly bool _isRead;
- internal readonly bool _apm; // true if this is from Begin/EndXx; false if it's from XxAsync
- internal Stream? _stream;
- internal byte[]? _buffer;
- internal readonly int _offset;
- internal readonly int _count;
- private AsyncCallback? _callback;
- private ExecutionContext? _context;
-
- internal void ClearBeginState() // Used to allow the args to Read/Write to be made available for GC
- {
- _stream = null;
- _buffer = null;
- }
-
- public ReadWriteTask(
- bool isRead,
- bool apm,
- Func<object?, int> function, object? state,
- Stream stream, byte[] buffer, int offset, int count, AsyncCallback? callback) :
- base(function, state, CancellationToken.None, TaskCreationOptions.DenyChildAttach)
- {
- Debug.Assert(function != null);
- Debug.Assert(stream != null);
- Debug.Assert(buffer != null);
-
- // Store the arguments
- _isRead = isRead;
- _apm = apm;
- _stream = stream;
- _buffer = buffer;
- _offset = offset;
- _count = count;
-
- // If a callback was provided, we need to:
- // - Store the user-provided handler
- // - Capture an ExecutionContext under which to invoke the handler
- // - Add this task as its own completion handler so that the Invoke method
- // will run the callback when this task completes.
- if (callback != null)
- {
- _callback = callback;
- _context = ExecutionContext.Capture();
- base.AddCompletionAction(this);
- }
- }
-
- private static void InvokeAsyncCallback(object? completedTask)
- {
- Debug.Assert(completedTask is ReadWriteTask);
- var rwc = (ReadWriteTask)completedTask;
- AsyncCallback? callback = rwc._callback;
- Debug.Assert(callback != null);
- rwc._callback = null;
- callback(rwc);
- }
-
- private static ContextCallback? s_invokeAsyncCallback;
-
- void ITaskCompletionAction.Invoke(Task completingTask)
- {
- // Get the ExecutionContext. If there is none, just run the callback
- // directly, passing in the completed task as the IAsyncResult.
- // If there is one, process it with ExecutionContext.Run.
- ExecutionContext? context = _context;
- if (context == null)
- {
- AsyncCallback? callback = _callback;
- Debug.Assert(callback != null);
- _callback = null;
- callback(completingTask);
- }
- else
- {
- _context = null;
-
- ContextCallback? invokeAsyncCallback = s_invokeAsyncCallback ??= InvokeAsyncCallback;
-
- ExecutionContext.RunInternal(context, invokeAsyncCallback, this);
- }
- }
-
- bool ITaskCompletionAction.InvokeMayRunArbitraryCode => true;
- }
-
- public Task WriteAsync(byte[] buffer, int offset, int count)
- {
- return WriteAsync(buffer, offset, count, CancellationToken.None);
- }
-
- public virtual Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- // If cancellation was requested, bail early with an already completed task.
- // Otherwise, return a task that represents the Begin/End methods.
- return cancellationToken.IsCancellationRequested
- ? Task.FromCanceled(cancellationToken)
- : BeginEndWriteAsync(buffer, offset, count);
- }
-
- public virtual ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
- {
- if (MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> array))
- {
- return new ValueTask(WriteAsync(array.Array!, array.Offset, array.Count, cancellationToken));
- }
- else
- {
- byte[] sharedBuffer = ArrayPool<byte>.Shared.Rent(buffer.Length);
- buffer.Span.CopyTo(sharedBuffer);
- return new ValueTask(FinishWriteAsync(WriteAsync(sharedBuffer, 0, buffer.Length, cancellationToken), sharedBuffer));
- }
- }
-
- private async Task FinishWriteAsync(Task writeTask, byte[] localBuffer)
- {
- try
- {
- await writeTask.ConfigureAwait(false);
- }
- finally
- {
- ArrayPool<byte>.Shared.Return(localBuffer);
- }
- }
-
- private Task BeginEndWriteAsync(byte[] buffer, int offset, int count)
- {
- if (!HasOverriddenBeginEndWrite())
- {
- // If the Stream does not override Begin/EndWrite, then we can take an optimized path
- // that skips an extra layer of tasks / IAsyncResults.
- return (Task)BeginWriteInternal(buffer, offset, count, null, null, serializeAsynchronously: true, apm: false);
- }
-
- // Otherwise, we need to wrap calls to Begin/EndWrite to ensure we use the derived type's functionality.
- return TaskFactory<VoidTaskResult>.FromAsyncTrim(
- this, new ReadWriteParameters { Buffer = buffer, Offset = offset, Count = count },
- (stream, args, callback, state) => stream.BeginWrite(args.Buffer, args.Offset, args.Count, callback, state), // cached by compiler
- (stream, asyncResult) => // cached by compiler
- {
- stream.EndWrite(asyncResult);
- return default;
- });
- }
-
- public abstract long Seek(long offset, SeekOrigin origin);
-
- public abstract void SetLength(long value);
-
- public abstract int Read(byte[] buffer, int offset, int count);
-
- public virtual int Read(Span<byte> buffer)
- {
- byte[] sharedBuffer = ArrayPool<byte>.Shared.Rent(buffer.Length);
- try
- {
- int numRead = Read(sharedBuffer, 0, buffer.Length);
- if ((uint)numRead > (uint)buffer.Length)
- {
- throw new IOException(SR.IO_StreamTooLong);
- }
- new Span<byte>(sharedBuffer, 0, numRead).CopyTo(buffer);
- return numRead;
- }
- finally { ArrayPool<byte>.Shared.Return(sharedBuffer); }
- }
-
- // Reads one byte from the stream by calling Read(byte[], int, int).
- // Will return an unsigned byte cast to an int or -1 on end of stream.
- // This implementation does not perform well because it allocates a new
- // byte[] each time you call it, and should be overridden by any
- // subclass that maintains an internal buffer. Then, it can help perf
- // significantly for people who are reading one byte at a time.
- public virtual int ReadByte()
- {
- byte[] oneByteArray = new byte[1];
- int r = Read(oneByteArray, 0, 1);
- if (r == 0)
- return -1;
- return oneByteArray[0];
- }
-
- public abstract void Write(byte[] buffer, int offset, int count);
-
- public virtual void Write(ReadOnlySpan<byte> buffer)
- {
- byte[] sharedBuffer = ArrayPool<byte>.Shared.Rent(buffer.Length);
- try
- {
- buffer.CopyTo(sharedBuffer);
- Write(sharedBuffer, 0, buffer.Length);
- }
- finally { ArrayPool<byte>.Shared.Return(sharedBuffer); }
- }
-
- // Writes one byte from the stream by calling Write(byte[], int, int).
- // This implementation does not perform well because it allocates a new
- // byte[] each time you call it, and should be overridden by any
- // subclass that maintains an internal buffer. Then, it can help perf
- // significantly for people who are writing one byte at a time.
- public virtual void WriteByte(byte value)
- {
- byte[] oneByteArray = new byte[1];
- oneByteArray[0] = value;
- Write(oneByteArray, 0, 1);
- }
-
- public static Stream Synchronized(Stream stream)
- {
- if (stream == null)
- throw new ArgumentNullException(nameof(stream));
- if (stream is SyncStream)
- return stream;
-
- return new SyncStream(stream);
- }
-
- [Obsolete("Do not call or override this method.")]
- protected virtual void ObjectInvariant()
- {
- }
-
- internal IAsyncResult BlockingBeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
- {
- // To avoid a race with a stream's position pointer & generating conditions
- // with internal buffer indexes in our own streams that
- // don't natively support async IO operations when there are multiple
- // async requests outstanding, we will block the application's main
- // thread and do the IO synchronously.
- // This can't perform well - use a different approach.
- SynchronousAsyncResult asyncResult;
- try
- {
- int numRead = Read(buffer, offset, count);
- asyncResult = new SynchronousAsyncResult(numRead, state);
- }
- catch (IOException ex)
- {
- asyncResult = new SynchronousAsyncResult(ex, state, isWrite: false);
- }
-
- callback?.Invoke(asyncResult);
-
- return asyncResult;
- }
-
- internal static int BlockingEndRead(IAsyncResult asyncResult)
- {
- return SynchronousAsyncResult.EndRead(asyncResult);
- }
-
- internal IAsyncResult BlockingBeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
- {
- // To avoid a race condition with a stream's position pointer & generating conditions
- // with internal buffer indexes in our own streams that
- // don't natively support async IO operations when there are multiple
- // async requests outstanding, we will block the application's main
- // thread and do the IO synchronously.
- // This can't perform well - use a different approach.
- SynchronousAsyncResult asyncResult;
- try
- {
- Write(buffer, offset, count);
- asyncResult = new SynchronousAsyncResult(state);
- }
- catch (IOException ex)
- {
- asyncResult = new SynchronousAsyncResult(ex, state, isWrite: true);
- }
-
- callback?.Invoke(asyncResult);
-
- return asyncResult;
- }
-
- internal static void BlockingEndWrite(IAsyncResult asyncResult)
- {
- SynchronousAsyncResult.EndWrite(asyncResult);
- }
-
- private sealed class NullStream : Stream
- {
- private static readonly Task<int> s_zeroTask = Task.FromResult(0);
-
- internal NullStream() { }
-
- public override bool CanRead => true;
-
- public override bool CanWrite => true;
-
- public override bool CanSeek => true;
-
- public override long Length => 0;
-
- public override long Position
- {
- get => 0;
- set { }
- }
-
- public override void CopyTo(Stream destination, int bufferSize)
- {
- StreamHelpers.ValidateCopyToArgs(this, destination, bufferSize);
-
- // After we validate arguments this is a nop.
- }
-
- public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
- {
- // Validate arguments here for compat, since previously this method
- // was inherited from Stream (which did check its arguments).
- StreamHelpers.ValidateCopyToArgs(this, destination, bufferSize);
-
- return cancellationToken.IsCancellationRequested ?
- Task.FromCanceled(cancellationToken) :
- Task.CompletedTask;
- }
-
- public override void CopyTo(ReadOnlySpanAction<byte, object?> callback, object? state, int bufferSize)
- {
- StreamHelpers.ValidateCopyToArgs(this, callback, bufferSize);
-
- // After we validate arguments this is a nop.
- }
-
- public override Task CopyToAsync(Func<ReadOnlyMemory<byte>, object?, CancellationToken, ValueTask> callback, object? state, int bufferSize, CancellationToken cancellationToken)
- {
- StreamHelpers.ValidateCopyToArgs(this, callback, bufferSize);
-
- return cancellationToken.IsCancellationRequested ?
- Task.FromCanceled(cancellationToken) :
- Task.CompletedTask;
- }
-
- protected override void Dispose(bool disposing)
- {
- // Do nothing - we don't want NullStream singleton (static) to be closable
- }
-
- public override void Flush()
- {
- }
-
- public override Task FlushAsync(CancellationToken cancellationToken)
- {
- return cancellationToken.IsCancellationRequested ?
- Task.FromCanceled(cancellationToken) :
- Task.CompletedTask;
- }
-
- public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
- {
- if (!CanRead) throw Error.GetReadNotSupported();
-
- return BlockingBeginRead(buffer, offset, count, callback, state);
- }
-
- public override int EndRead(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- throw new ArgumentNullException(nameof(asyncResult));
-
- return BlockingEndRead(asyncResult);
- }
-
- public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
- {
- if (!CanWrite) throw Error.GetWriteNotSupported();
-
- return BlockingBeginWrite(buffer, offset, count, callback, state);
- }
-
- public override void EndWrite(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- throw new ArgumentNullException(nameof(asyncResult));
-
- BlockingEndWrite(asyncResult);
- }
-
- public override int Read(byte[] buffer, int offset, int count)
- {
- return 0;
- }
-
- public override int Read(Span<byte> buffer)
- {
- return 0;
- }
-
- public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- return s_zeroTask;
- }
-
- public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
- {
- return new ValueTask<int>(0);
- }
-
- public override int ReadByte()
- {
- return -1;
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- }
-
- public override void Write(ReadOnlySpan<byte> buffer)
- {
- }
-
- public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- return cancellationToken.IsCancellationRequested ?
- Task.FromCanceled(cancellationToken) :
- Task.CompletedTask;
- }
-
- public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
- {
- return cancellationToken.IsCancellationRequested ?
- new ValueTask(Task.FromCanceled(cancellationToken)) :
- default;
- }
-
- public override void WriteByte(byte value)
- {
- }
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- return 0;
- }
-
- public override void SetLength(long length)
- {
- }
- }
-
-
- /// <summary>Used as the IAsyncResult object when using asynchronous IO methods on the base Stream class.</summary>
- private sealed class SynchronousAsyncResult : IAsyncResult
- {
- private readonly object? _stateObject;
- private readonly bool _isWrite;
- private ManualResetEvent? _waitHandle;
- private readonly ExceptionDispatchInfo? _exceptionInfo;
-
- private bool _endXxxCalled;
- private readonly int _bytesRead;
-
- internal SynchronousAsyncResult(int bytesRead, object? asyncStateObject)
- {
- _bytesRead = bytesRead;
- _stateObject = asyncStateObject;
- }
-
- internal SynchronousAsyncResult(object? asyncStateObject)
- {
- _stateObject = asyncStateObject;
- _isWrite = true;
- }
-
- internal SynchronousAsyncResult(Exception ex, object? asyncStateObject, bool isWrite)
- {
- _exceptionInfo = ExceptionDispatchInfo.Capture(ex);
- _stateObject = asyncStateObject;
- _isWrite = isWrite;
- }
-
- public bool IsCompleted => true;
-
- public WaitHandle AsyncWaitHandle =>
- LazyInitializer.EnsureInitialized(ref _waitHandle, () => new ManualResetEvent(true));
-
- public object? AsyncState => _stateObject;
-
- public bool CompletedSynchronously => true;
-
- internal void ThrowIfError()
- {
- if (_exceptionInfo != null)
- _exceptionInfo.Throw();
- }
-
- internal static int EndRead(IAsyncResult asyncResult)
- {
- if (!(asyncResult is SynchronousAsyncResult ar) || ar._isWrite)
- throw new ArgumentException(SR.Arg_WrongAsyncResult);
-
- if (ar._endXxxCalled)
- throw new ArgumentException(SR.InvalidOperation_EndReadCalledMultiple);
-
- ar._endXxxCalled = true;
-
- ar.ThrowIfError();
- return ar._bytesRead;
- }
-
- internal static void EndWrite(IAsyncResult asyncResult)
- {
- if (!(asyncResult is SynchronousAsyncResult ar) || !ar._isWrite)
- throw new ArgumentException(SR.Arg_WrongAsyncResult);
-
- if (ar._endXxxCalled)
- throw new ArgumentException(SR.InvalidOperation_EndWriteCalledMultiple);
-
- ar._endXxxCalled = true;
-
- ar.ThrowIfError();
- }
- } // class SynchronousAsyncResult
-
-
- // SyncStream is a wrapper around a stream that takes
- // a lock for every operation making it thread safe.
- private sealed class SyncStream : Stream, IDisposable
- {
- private readonly Stream _stream;
-
- internal SyncStream(Stream stream)
- {
- if (stream == null)
- throw new ArgumentNullException(nameof(stream));
- _stream = stream;
- }
-
- public override bool CanRead => _stream.CanRead;
-
- public override bool CanWrite => _stream.CanWrite;
-
- public override bool CanSeek => _stream.CanSeek;
-
- public override bool CanTimeout => _stream.CanTimeout;
-
- public override long Length
- {
- get
- {
- lock (_stream)
- {
- return _stream.Length;
- }
- }
- }
-
- public override long Position
- {
- get
- {
- lock (_stream)
- {
- return _stream.Position;
- }
- }
- set
- {
- lock (_stream)
- {
- _stream.Position = value;
- }
- }
- }
-
- public override int ReadTimeout
- {
- get => _stream.ReadTimeout;
- set => _stream.ReadTimeout = value;
- }
-
- public override int WriteTimeout
- {
- get => _stream.WriteTimeout;
- set => _stream.WriteTimeout = value;
- }
-
- // In the off chance that some wrapped stream has different
- // semantics for Close vs. Dispose, let's preserve that.
- public override void Close()
- {
- lock (_stream)
- {
- try
- {
- _stream.Close();
- }
- finally
- {
- base.Dispose(true);
- }
- }
- }
-
- protected override void Dispose(bool disposing)
- {
- lock (_stream)
- {
- try
- {
- // Explicitly pick up a potentially methodimpl'ed Dispose
- if (disposing)
- ((IDisposable)_stream).Dispose();
- }
- finally
- {
- base.Dispose(disposing);
- }
- }
- }
-
- public override ValueTask DisposeAsync()
- {
- lock (_stream)
- return _stream.DisposeAsync();
- }
-
- public override void Flush()
- {
- lock (_stream)
- _stream.Flush();
- }
-
- public override int Read(byte[] bytes, int offset, int count)
- {
- lock (_stream)
- return _stream.Read(bytes, offset, count);
- }
-
- public override int Read(Span<byte> buffer)
- {
- lock (_stream)
- return _stream.Read(buffer);
- }
-
- public override int ReadByte()
- {
- lock (_stream)
- return _stream.ReadByte();
- }
-
- public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
- {
-#if CORERT
- throw new NotImplementedException(); // TODO: https://github.com/dotnet/corert/issues/3251
-#else
- bool overridesBeginRead = _stream.HasOverriddenBeginEndRead();
-
- lock (_stream)
- {
- // If the Stream does have its own BeginRead implementation, then we must use that override.
- // If it doesn't, then we'll use the base implementation, but we'll make sure that the logic
- // which ensures only one asynchronous operation does so with an asynchronous wait rather
- // than a synchronous wait. A synchronous wait will result in a deadlock condition, because
- // the EndXx method for the outstanding async operation won't be able to acquire the lock on
- // _stream due to this call blocked while holding the lock.
- return overridesBeginRead ?
- _stream.BeginRead(buffer, offset, count, callback, state) :
- _stream.BeginReadInternal(buffer, offset, count, callback, state, serializeAsynchronously: true, apm: true);
- }
-#endif
- }
-
- public override int EndRead(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- throw new ArgumentNullException(nameof(asyncResult));
-
- lock (_stream)
- return _stream.EndRead(asyncResult);
- }
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- lock (_stream)
- return _stream.Seek(offset, origin);
- }
-
- public override void SetLength(long length)
- {
- lock (_stream)
- _stream.SetLength(length);
- }
-
- public override void Write(byte[] bytes, int offset, int count)
- {
- lock (_stream)
- _stream.Write(bytes, offset, count);
- }
-
- public override void Write(ReadOnlySpan<byte> buffer)
- {
- lock (_stream)
- _stream.Write(buffer);
- }
-
- public override void WriteByte(byte b)
- {
- lock (_stream)
- _stream.WriteByte(b);
- }
-
- public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object? state)
- {
-#if CORERT
- throw new NotImplementedException(); // TODO: https://github.com/dotnet/corert/issues/3251
-#else
- bool overridesBeginWrite = _stream.HasOverriddenBeginEndWrite();
-
- lock (_stream)
- {
- // If the Stream does have its own BeginWrite implementation, then we must use that override.
- // If it doesn't, then we'll use the base implementation, but we'll make sure that the logic
- // which ensures only one asynchronous operation does so with an asynchronous wait rather
- // than a synchronous wait. A synchronous wait will result in a deadlock condition, because
- // the EndXx method for the outstanding async operation won't be able to acquire the lock on
- // _stream due to this call blocked while holding the lock.
- return overridesBeginWrite ?
- _stream.BeginWrite(buffer, offset, count, callback, state) :
- _stream.BeginWriteInternal(buffer, offset, count, callback, state, serializeAsynchronously: true, apm: true);
- }
-#endif
- }
-
- public override void EndWrite(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- throw new ArgumentNullException(nameof(asyncResult));
-
- lock (_stream)
- _stream.EndWrite(asyncResult);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/StreamHelpers.CopyValidation.cs b/netcore/System.Private.CoreLib/shared/System/IO/StreamHelpers.CopyValidation.cs
deleted file mode 100644
index 1d120e5a077..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/StreamHelpers.CopyValidation.cs
+++ /dev/null
@@ -1,70 +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 System.Buffers;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.IO
-{
- /// <summary>Provides methods to help in the implementation of Stream-derived types.</summary>
- internal static partial class StreamHelpers
- {
- /// <summary>Validate the arguments to CopyTo, as would Stream.CopyTo.</summary>
- public static void ValidateCopyToArgs(Stream source, Stream destination, int bufferSize)
- {
- if (destination == null)
- {
- throw new ArgumentNullException(nameof(destination));
- }
-
- if (bufferSize <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, SR.ArgumentOutOfRange_NeedPosNum);
- }
-
- bool sourceCanRead = source.CanRead;
- if (!sourceCanRead && !source.CanWrite)
- {
- throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
- }
-
- bool destinationCanWrite = destination.CanWrite;
- if (!destinationCanWrite && !destination.CanRead)
- {
- throw new ObjectDisposedException(nameof(destination), SR.ObjectDisposed_StreamClosed);
- }
-
- if (!sourceCanRead)
- {
- throw new NotSupportedException(SR.NotSupported_UnreadableStream);
- }
-
- if (!destinationCanWrite)
- {
- throw new NotSupportedException(SR.NotSupported_UnwritableStream);
- }
- }
-
- public static void ValidateCopyToArgs(Stream source, Delegate callback, int bufferSize)
- {
- if (callback == null)
- {
- throw new ArgumentNullException(nameof(callback));
- }
-
- if (bufferSize <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, SR.ArgumentOutOfRange_NeedPosNum);
- }
-
- if (!source.CanRead)
- {
- throw source.CanWrite ? (Exception)
- new NotSupportedException(SR.NotSupported_UnreadableStream) :
- new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/StreamReader.cs b/netcore/System.Private.CoreLib/shared/System/IO/StreamReader.cs
deleted file mode 100644
index 5ce2d117a99..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/StreamReader.cs
+++ /dev/null
@@ -1,1347 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.IO
-{
- // This class implements a TextReader for reading characters to a Stream.
- // This is designed for character input in a particular Encoding,
- // whereas the Stream class is designed for byte input and output.
- public class StreamReader : TextReader
- {
- // StreamReader.Null is threadsafe.
- public static new readonly StreamReader Null = new NullStreamReader();
-
- // Using a 1K byte buffer and a 4K FileStream buffer works out pretty well
- // perf-wise. On even a 40 MB text file, any perf loss by using a 4K
- // buffer is negated by the win of allocating a smaller byte[], which
- // saves construction time. This does break adaptive buffering,
- // but this is slightly faster.
- private const int DefaultBufferSize = 1024; // Byte buffer size
- private const int DefaultFileStreamBufferSize = 4096;
- private const int MinBufferSize = 128;
-
- private readonly Stream _stream;
- private Encoding _encoding = null!; // only null in NullStreamReader where this is never used
- private Decoder _decoder = null!; // only null in NullStreamReader where this is never used
- private readonly byte[] _byteBuffer = null!; // only null in NullStreamReader where this is never used
- private char[] _charBuffer = null!; // only null in NullStreamReader where this is never used
- private int _charPos;
- private int _charLen;
- // Record the number of valid bytes in the byteBuffer, for a few checks.
- private int _byteLen;
- // This is used only for preamble detection
- private int _bytePos;
-
- // This is the maximum number of chars we can get from one call to
- // ReadBuffer. Used so ReadBuffer can tell when to copy data into
- // a user's char[] directly, instead of our internal char[].
- private int _maxCharsPerBuffer;
-
- /// <summary>True if the writer has been disposed; otherwise, false.</summary>
- private bool _disposed;
-
- // We will support looking for byte order marks in the stream and trying
- // to decide what the encoding might be from the byte order marks, IF they
- // exist. But that's all we'll do.
- private bool _detectEncoding;
-
- // Whether we must still check for the encoding's given preamble at the
- // beginning of this file.
- private bool _checkPreamble;
-
- // Whether the stream is most likely not going to give us back as much
- // data as we want the next time we call it. We must do the computation
- // before we do any byte order mark handling and save the result. Note
- // that we need this to allow users to handle streams used for an
- // interactive protocol, where they block waiting for the remote end
- // to send a response, like logging in on a Unix machine.
- private bool _isBlocked;
-
- // The intent of this field is to leave open the underlying stream when
- // disposing of this StreamReader. A name like _leaveOpen is better,
- // but this type is serializable, and this field's name was _closable.
- private readonly bool _closable; // Whether to close the underlying stream.
-
- // We don't guarantee thread safety on StreamReader, but we should at
- // least prevent users from trying to read anything while an Async
- // read from the same thread is in progress.
- private Task _asyncReadTask = Task.CompletedTask;
-
- private void CheckAsyncTaskInProgress()
- {
- // We are not locking the access to _asyncReadTask because this is not meant to guarantee thread safety.
- // We are simply trying to deter calling any Read APIs while an async Read from the same thread is in progress.
- if (!_asyncReadTask.IsCompleted)
- {
- ThrowAsyncIOInProgress();
- }
- }
-
- [DoesNotReturn]
- private static void ThrowAsyncIOInProgress() =>
- throw new InvalidOperationException(SR.InvalidOperation_AsyncIOInProgress);
-
- // StreamReader by default will ignore illegal UTF8 characters. We don't want to
- // throw here because we want to be able to read ill-formed data without choking.
- // The high level goal is to be tolerant of encoding errors when we read and very strict
- // when we write. Hence, default StreamWriter encoding will throw on error.
-
- private StreamReader()
- {
- Debug.Assert(this is NullStreamReader);
- _stream = Stream.Null;
- _closable = true;
- }
-
- public StreamReader(Stream stream)
- : this(stream, true)
- {
- }
-
- public StreamReader(Stream stream, bool detectEncodingFromByteOrderMarks)
- : this(stream, Encoding.UTF8, detectEncodingFromByteOrderMarks, DefaultBufferSize, false)
- {
- }
-
- public StreamReader(Stream stream, Encoding encoding)
- : this(stream, encoding, true, DefaultBufferSize, false)
- {
- }
-
- public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks)
- : this(stream, encoding, detectEncodingFromByteOrderMarks, DefaultBufferSize, false)
- {
- }
-
- // Creates a new StreamReader for the given stream. The
- // character encoding is set by encoding and the buffer size,
- // in number of 16-bit characters, is set by bufferSize.
- //
- // Note that detectEncodingFromByteOrderMarks is a very
- // loose attempt at detecting the encoding by looking at the first
- // 3 bytes of the stream. It will recognize UTF-8, little endian
- // unicode, and big endian unicode text, but that's it. If neither
- // of those three match, it will use the Encoding you provided.
- //
- public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize)
- : this(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize, false)
- {
- }
-
- public StreamReader(Stream stream, Encoding? encoding = null, bool detectEncodingFromByteOrderMarks = true, int bufferSize = -1, bool leaveOpen = false)
- {
- if (stream == null)
- {
- throw new ArgumentNullException(nameof(stream));
- }
- if (encoding == null)
- {
- encoding = Encoding.UTF8;
- }
- if (!stream.CanRead)
- {
- throw new ArgumentException(SR.Argument_StreamNotReadable);
- }
- if (bufferSize == -1)
- {
- bufferSize = DefaultBufferSize;
- }
- else if (bufferSize <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
- }
-
- _stream = stream;
- _encoding = encoding;
- _decoder = encoding.GetDecoder();
- if (bufferSize < MinBufferSize)
- {
- bufferSize = MinBufferSize;
- }
-
- _byteBuffer = new byte[bufferSize];
- _maxCharsPerBuffer = encoding.GetMaxCharCount(bufferSize);
- _charBuffer = new char[_maxCharsPerBuffer];
- _byteLen = 0;
- _bytePos = 0;
- _detectEncoding = detectEncodingFromByteOrderMarks;
- _checkPreamble = encoding.Preamble.Length > 0;
- _isBlocked = false;
- _closable = !leaveOpen;
- }
-
- public StreamReader(string path)
- : this(path, true)
- {
- }
-
- public StreamReader(string path, bool detectEncodingFromByteOrderMarks)
- : this(path, Encoding.UTF8, detectEncodingFromByteOrderMarks, DefaultBufferSize)
- {
- }
-
- public StreamReader(string path, Encoding encoding)
- : this(path, encoding, true, DefaultBufferSize)
- {
- }
-
- public StreamReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks)
- : this(path, encoding, detectEncodingFromByteOrderMarks, DefaultBufferSize)
- {
- }
-
- public StreamReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) :
- this(ValidateArgsAndOpenPath(path, encoding, bufferSize), encoding, detectEncodingFromByteOrderMarks, bufferSize, leaveOpen: false)
- {
- }
-
- private static Stream ValidateArgsAndOpenPath(string path, Encoding encoding, int bufferSize)
- {
- if (path == null)
- throw new ArgumentNullException(nameof(path));
- if (encoding == null)
- throw new ArgumentNullException(nameof(encoding));
- if (path.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyPath);
- if (bufferSize <= 0)
- throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
-
- return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, DefaultFileStreamBufferSize, FileOptions.SequentialScan);
- }
-
- public override void Close()
- {
- Dispose(true);
- }
-
- protected override void Dispose(bool disposing)
- {
- if (_disposed)
- {
- return;
- }
- _disposed = true;
-
- // Dispose of our resources if this StreamReader is closable.
- if (_closable)
- {
- try
- {
- // Note that Stream.Close() can potentially throw here. So we need to
- // ensure cleaning up internal resources, inside the finally block.
- if (disposing)
- {
- _stream.Close();
- }
- }
- finally
- {
- _charPos = 0;
- _charLen = 0;
- base.Dispose(disposing);
- }
- }
- }
-
- public virtual Encoding CurrentEncoding => _encoding;
-
- public virtual Stream BaseStream => _stream;
-
- // DiscardBufferedData tells StreamReader to throw away its internal
- // buffer contents. This is useful if the user needs to seek on the
- // underlying stream to a known location then wants the StreamReader
- // to start reading from this new point. This method should be called
- // very sparingly, if ever, since it can lead to very poor performance.
- // However, it may be the only way of handling some scenarios where
- // users need to re-read the contents of a StreamReader a second time.
- public void DiscardBufferedData()
- {
- CheckAsyncTaskInProgress();
-
- _byteLen = 0;
- _charLen = 0;
- _charPos = 0;
- // in general we'd like to have an invariant that encoding isn't null. However,
- // for startup improvements for NullStreamReader, we want to delay load encoding.
- if (_encoding != null)
- {
- _decoder = _encoding.GetDecoder();
- }
- _isBlocked = false;
- }
-
- public bool EndOfStream
- {
- get
- {
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- if (_charPos < _charLen)
- {
- return false;
- }
-
- // This may block on pipes!
- int numRead = ReadBuffer();
- return numRead == 0;
- }
- }
-
- public override int Peek()
- {
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- if (_charPos == _charLen)
- {
- if (_isBlocked || ReadBuffer() == 0)
- {
- return -1;
- }
- }
- return _charBuffer[_charPos];
- }
-
- public override int Read()
- {
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- if (_charPos == _charLen)
- {
- if (ReadBuffer() == 0)
- {
- return -1;
- }
- }
- int result = _charBuffer[_charPos];
- _charPos++;
- return result;
- }
-
- public override int Read(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0 || count < 0)
- {
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
-
- return ReadSpan(new Span<char>(buffer, index, count));
- }
-
- public override int Read(Span<char> buffer) =>
- GetType() == typeof(StreamReader) ? ReadSpan(buffer) :
- base.Read(buffer); // Defer to Read(char[], ...) if a derived type may have previously overridden it
-
- private int ReadSpan(Span<char> buffer)
- {
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- int charsRead = 0;
- // As a perf optimization, if we had exactly one buffer's worth of
- // data read in, let's try writing directly to the user's buffer.
- bool readToUserBuffer = false;
- int count = buffer.Length;
- while (count > 0)
- {
- int n = _charLen - _charPos;
- if (n == 0)
- {
- n = ReadBuffer(buffer.Slice(charsRead), out readToUserBuffer);
- }
- if (n == 0)
- {
- break; // We're at EOF
- }
- if (n > count)
- {
- n = count;
- }
- if (!readToUserBuffer)
- {
- new Span<char>(_charBuffer, _charPos, n).CopyTo(buffer.Slice(charsRead));
- _charPos += n;
- }
-
- charsRead += n;
- count -= n;
- // This function shouldn't block for an indefinite amount of time,
- // or reading from a network stream won't work right. If we got
- // fewer bytes than we requested, then we want to break right here.
- if (_isBlocked)
- {
- break;
- }
- }
-
- return charsRead;
- }
-
- public override string ReadToEnd()
- {
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- // Call ReadBuffer, then pull data out of charBuffer.
- StringBuilder sb = new StringBuilder(_charLen - _charPos);
- do
- {
- sb.Append(_charBuffer, _charPos, _charLen - _charPos);
- _charPos = _charLen; // Note we consumed these characters
- ReadBuffer();
- } while (_charLen > 0);
- return sb.ToString();
- }
-
- public override int ReadBlock(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0 || count < 0)
- {
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- return base.ReadBlock(buffer, index, count);
- }
-
- public override int ReadBlock(Span<char> buffer)
- {
- if (GetType() != typeof(StreamReader))
- {
- // Defer to Read(char[], ...) if a derived type may have previously overridden it.
- return base.ReadBlock(buffer);
- }
-
- int i, n = 0;
- do
- {
- i = ReadSpan(buffer.Slice(n));
- n += i;
- } while (i > 0 && n < buffer.Length);
- return n;
- }
-
- // Trims n bytes from the front of the buffer.
- private void CompressBuffer(int n)
- {
- Debug.Assert(_byteLen >= n, "CompressBuffer was called with a number of bytes greater than the current buffer length. Are two threads using this StreamReader at the same time?");
- Buffer.BlockCopy(_byteBuffer, n, _byteBuffer, 0, _byteLen - n);
- _byteLen -= n;
- }
-
- private void DetectEncoding()
- {
- if (_byteLen < 2)
- {
- return;
- }
- _detectEncoding = false;
- bool changedEncoding = false;
- if (_byteBuffer[0] == 0xFE && _byteBuffer[1] == 0xFF)
- {
- // Big Endian Unicode
-
- _encoding = Encoding.BigEndianUnicode;
- CompressBuffer(2);
- changedEncoding = true;
- }
- else if (_byteBuffer[0] == 0xFF && _byteBuffer[1] == 0xFE)
- {
- // Little Endian Unicode, or possibly little endian UTF32
- if (_byteLen < 4 || _byteBuffer[2] != 0 || _byteBuffer[3] != 0)
- {
- _encoding = Encoding.Unicode;
- CompressBuffer(2);
- changedEncoding = true;
- }
- else
- {
- _encoding = Encoding.UTF32;
- CompressBuffer(4);
- changedEncoding = true;
- }
- }
- else if (_byteLen >= 3 && _byteBuffer[0] == 0xEF && _byteBuffer[1] == 0xBB && _byteBuffer[2] == 0xBF)
- {
- // UTF-8
- _encoding = Encoding.UTF8;
- CompressBuffer(3);
- changedEncoding = true;
- }
- else if (_byteLen >= 4 && _byteBuffer[0] == 0 && _byteBuffer[1] == 0 &&
- _byteBuffer[2] == 0xFE && _byteBuffer[3] == 0xFF)
- {
- // Big Endian UTF32
- _encoding = new UTF32Encoding(bigEndian: true, byteOrderMark: true);
- CompressBuffer(4);
- changedEncoding = true;
- }
- else if (_byteLen == 2)
- {
- _detectEncoding = true;
- }
- // Note: in the future, if we change this algorithm significantly,
- // we can support checking for the preamble of the given encoding.
-
- if (changedEncoding)
- {
- _decoder = _encoding.GetDecoder();
- int newMaxCharsPerBuffer = _encoding.GetMaxCharCount(_byteBuffer.Length);
- if (newMaxCharsPerBuffer > _maxCharsPerBuffer)
- {
- _charBuffer = new char[newMaxCharsPerBuffer];
- }
- _maxCharsPerBuffer = newMaxCharsPerBuffer;
- }
- }
-
- // Trims the preamble bytes from the byteBuffer. This routine can be called multiple times
- // and we will buffer the bytes read until the preamble is matched or we determine that
- // there is no match. If there is no match, every byte read previously will be available
- // for further consumption. If there is a match, we will compress the buffer for the
- // leading preamble bytes
- private bool IsPreamble()
- {
- if (!_checkPreamble)
- {
- return _checkPreamble;
- }
-
- ReadOnlySpan<byte> preamble = _encoding.Preamble;
-
- Debug.Assert(_bytePos <= preamble.Length, "_compressPreamble was called with the current bytePos greater than the preamble buffer length. Are two threads using this StreamReader at the same time?");
- int len = (_byteLen >= (preamble.Length)) ? (preamble.Length - _bytePos) : (_byteLen - _bytePos);
-
- for (int i = 0; i < len; i++, _bytePos++)
- {
- if (_byteBuffer[_bytePos] != preamble[_bytePos])
- {
- _bytePos = 0;
- _checkPreamble = false;
- break;
- }
- }
-
- Debug.Assert(_bytePos <= preamble.Length, "possible bug in _compressPreamble. Are two threads using this StreamReader at the same time?");
-
- if (_checkPreamble)
- {
- if (_bytePos == preamble.Length)
- {
- // We have a match
- CompressBuffer(preamble.Length);
- _bytePos = 0;
- _checkPreamble = false;
- _detectEncoding = false;
- }
- }
-
- return _checkPreamble;
- }
-
- internal virtual int ReadBuffer()
- {
- _charLen = 0;
- _charPos = 0;
-
- if (!_checkPreamble)
- {
- _byteLen = 0;
- }
-
- do
- {
- if (_checkPreamble)
- {
- Debug.Assert(_bytePos <= _encoding.Preamble.Length, "possible bug in _compressPreamble. Are two threads using this StreamReader at the same time?");
- int len = _stream.Read(_byteBuffer, _bytePos, _byteBuffer.Length - _bytePos);
- Debug.Assert(len >= 0, "Stream.Read returned a negative number! This is a bug in your stream class.");
-
- if (len == 0)
- {
- // EOF but we might have buffered bytes from previous
- // attempt to detect preamble that needs to be decoded now
- if (_byteLen > 0)
- {
- _charLen += _decoder.GetChars(_byteBuffer, 0, _byteLen, _charBuffer, _charLen);
- // Need to zero out the byteLen after we consume these bytes so that we don't keep infinitely hitting this code path
- _bytePos = _byteLen = 0;
- }
-
- return _charLen;
- }
-
- _byteLen += len;
- }
- else
- {
- Debug.Assert(_bytePos == 0, "bytePos can be non zero only when we are trying to _checkPreamble. Are two threads using this StreamReader at the same time?");
- _byteLen = _stream.Read(_byteBuffer, 0, _byteBuffer.Length);
- Debug.Assert(_byteLen >= 0, "Stream.Read returned a negative number! This is a bug in your stream class.");
-
- if (_byteLen == 0) // We're at EOF
- {
- return _charLen;
- }
- }
-
- // _isBlocked == whether we read fewer bytes than we asked for.
- // Note we must check it here because CompressBuffer or
- // DetectEncoding will change byteLen.
- _isBlocked = (_byteLen < _byteBuffer.Length);
-
- // Check for preamble before detect encoding. This is not to override the
- // user supplied Encoding for the one we implicitly detect. The user could
- // customize the encoding which we will loose, such as ThrowOnError on UTF8
- if (IsPreamble())
- {
- continue;
- }
-
- // If we're supposed to detect the encoding and haven't done so yet,
- // do it. Note this may need to be called more than once.
- if (_detectEncoding && _byteLen >= 2)
- {
- DetectEncoding();
- }
-
- _charLen += _decoder.GetChars(_byteBuffer, 0, _byteLen, _charBuffer, _charLen);
- } while (_charLen == 0);
- return _charLen;
- }
-
-
- // This version has a perf optimization to decode data DIRECTLY into the
- // user's buffer, bypassing StreamReader's own buffer.
- // This gives a > 20% perf improvement for our encodings across the board,
- // but only when asking for at least the number of characters that one
- // buffer's worth of bytes could produce.
- // This optimization, if run, will break SwitchEncoding, so we must not do
- // this on the first call to ReadBuffer.
- private int ReadBuffer(Span<char> userBuffer, out bool readToUserBuffer)
- {
- _charLen = 0;
- _charPos = 0;
-
- if (!_checkPreamble)
- {
- _byteLen = 0;
- }
-
- int charsRead = 0;
-
- // As a perf optimization, we can decode characters DIRECTLY into a
- // user's char[]. We absolutely must not write more characters
- // into the user's buffer than they asked for. Calculating
- // encoding.GetMaxCharCount(byteLen) each time is potentially very
- // expensive - instead, cache the number of chars a full buffer's
- // worth of data may produce. Yes, this makes the perf optimization
- // less aggressive, in that all reads that asked for fewer than AND
- // returned fewer than _maxCharsPerBuffer chars won't get the user
- // buffer optimization. This affects reads where the end of the
- // Stream comes in the middle somewhere, and when you ask for
- // fewer chars than your buffer could produce.
- readToUserBuffer = userBuffer.Length >= _maxCharsPerBuffer;
-
- do
- {
- Debug.Assert(charsRead == 0);
-
- if (_checkPreamble)
- {
- Debug.Assert(_bytePos <= _encoding.Preamble.Length, "possible bug in _compressPreamble. Are two threads using this StreamReader at the same time?");
- int len = _stream.Read(_byteBuffer, _bytePos, _byteBuffer.Length - _bytePos);
- Debug.Assert(len >= 0, "Stream.Read returned a negative number! This is a bug in your stream class.");
-
- if (len == 0)
- {
- // EOF but we might have buffered bytes from previous
- // attempt to detect preamble that needs to be decoded now
- if (_byteLen > 0)
- {
- if (readToUserBuffer)
- {
- charsRead = _decoder.GetChars(new ReadOnlySpan<byte>(_byteBuffer, 0, _byteLen), userBuffer.Slice(charsRead), flush: false);
- _charLen = 0; // StreamReader's buffer is empty.
- }
- else
- {
- charsRead = _decoder.GetChars(_byteBuffer, 0, _byteLen, _charBuffer, charsRead);
- _charLen += charsRead; // Number of chars in StreamReader's buffer.
- }
- }
-
- return charsRead;
- }
-
- _byteLen += len;
- }
- else
- {
- Debug.Assert(_bytePos == 0, "bytePos can be non zero only when we are trying to _checkPreamble. Are two threads using this StreamReader at the same time?");
-
- _byteLen = _stream.Read(_byteBuffer, 0, _byteBuffer.Length);
-
- Debug.Assert(_byteLen >= 0, "Stream.Read returned a negative number! This is a bug in your stream class.");
-
- if (_byteLen == 0) // EOF
- {
- break;
- }
- }
-
- // _isBlocked == whether we read fewer bytes than we asked for.
- // Note we must check it here because CompressBuffer or
- // DetectEncoding will change byteLen.
- _isBlocked = (_byteLen < _byteBuffer.Length);
-
- // Check for preamble before detect encoding. This is not to override the
- // user supplied Encoding for the one we implicitly detect. The user could
- // customize the encoding which we will loose, such as ThrowOnError on UTF8
- // Note: we don't need to recompute readToUserBuffer optimization as IsPreamble
- // doesn't change the encoding or affect _maxCharsPerBuffer
- if (IsPreamble())
- {
- continue;
- }
-
- // On the first call to ReadBuffer, if we're supposed to detect the encoding, do it.
- if (_detectEncoding && _byteLen >= 2)
- {
- DetectEncoding();
- // DetectEncoding changes some buffer state. Recompute this.
- readToUserBuffer = userBuffer.Length >= _maxCharsPerBuffer;
- }
-
- _charPos = 0;
- if (readToUserBuffer)
- {
- charsRead += _decoder.GetChars(new ReadOnlySpan<byte>(_byteBuffer, 0, _byteLen), userBuffer.Slice(charsRead), flush: false);
- _charLen = 0; // StreamReader's buffer is empty.
- }
- else
- {
- charsRead = _decoder.GetChars(_byteBuffer, 0, _byteLen, _charBuffer, charsRead);
- _charLen += charsRead; // Number of chars in StreamReader's buffer.
- }
- } while (charsRead == 0);
-
- _isBlocked &= charsRead < userBuffer.Length;
-
- return charsRead;
- }
-
-
- // Reads a line. A line is defined as a sequence of characters followed by
- // a carriage return ('\r'), a line feed ('\n'), or a carriage return
- // immediately followed by a line feed. The resulting string does not
- // contain the terminating carriage return and/or line feed. The returned
- // value is null if the end of the input stream has been reached.
- //
- public override string? ReadLine()
- {
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- if (_charPos == _charLen)
- {
- if (ReadBuffer() == 0)
- {
- return null;
- }
- }
-
- StringBuilder? sb = null;
- do
- {
- int i = _charPos;
- do
- {
- char ch = _charBuffer[i];
- // Note the following common line feed chars:
- // \n - UNIX \r\n - DOS \r - Mac
- if (ch == '\r' || ch == '\n')
- {
- string s;
- if (sb != null)
- {
- sb.Append(_charBuffer, _charPos, i - _charPos);
- s = sb.ToString();
- }
- else
- {
- s = new string(_charBuffer, _charPos, i - _charPos);
- }
- _charPos = i + 1;
- if (ch == '\r' && (_charPos < _charLen || ReadBuffer() > 0))
- {
- if (_charBuffer[_charPos] == '\n')
- {
- _charPos++;
- }
- }
- return s;
- }
- i++;
- } while (i < _charLen);
-
- i = _charLen - _charPos;
- sb ??= new StringBuilder(i + 80);
- sb.Append(_charBuffer, _charPos, i);
- } while (ReadBuffer() > 0);
- return sb.ToString();
- }
-
- public override Task<string?> ReadLineAsync()
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Read() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Read) when we are not sure.
- if (GetType() != typeof(StreamReader))
- {
- return base.ReadLineAsync();
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task<string?> task = ReadLineAsyncInternal();
- _asyncReadTask = task;
-
- return task;
- }
-
- private async Task<string?> ReadLineAsyncInternal()
- {
- if (_charPos == _charLen && (await ReadBufferAsync(CancellationToken.None).ConfigureAwait(false)) == 0)
- {
- return null;
- }
-
- StringBuilder? sb = null;
-
- do
- {
- char[] tmpCharBuffer = _charBuffer;
- int tmpCharLen = _charLen;
- int tmpCharPos = _charPos;
- int i = tmpCharPos;
-
- do
- {
- char ch = tmpCharBuffer[i];
-
- // Note the following common line feed chars:
- // \n - UNIX \r\n - DOS \r - Mac
- if (ch == '\r' || ch == '\n')
- {
- string s;
-
- if (sb != null)
- {
- sb.Append(tmpCharBuffer, tmpCharPos, i - tmpCharPos);
- s = sb.ToString();
- }
- else
- {
- s = new string(tmpCharBuffer, tmpCharPos, i - tmpCharPos);
- }
-
- _charPos = tmpCharPos = i + 1;
-
- if (ch == '\r' && (tmpCharPos < tmpCharLen || (await ReadBufferAsync(CancellationToken.None).ConfigureAwait(false)) > 0))
- {
- tmpCharPos = _charPos;
- if (_charBuffer[tmpCharPos] == '\n')
- {
- _charPos = ++tmpCharPos;
- }
- }
-
- return s;
- }
-
- i++;
- } while (i < tmpCharLen);
-
- i = tmpCharLen - tmpCharPos;
- sb ??= new StringBuilder(i + 80);
- sb.Append(tmpCharBuffer, tmpCharPos, i);
- } while (await ReadBufferAsync(CancellationToken.None).ConfigureAwait(false) > 0);
-
- return sb.ToString();
- }
-
- public override Task<string> ReadToEndAsync()
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Read() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Read) when we are not sure.
- if (GetType() != typeof(StreamReader))
- {
- return base.ReadToEndAsync();
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task<string> task = ReadToEndAsyncInternal();
- _asyncReadTask = task;
-
- return task;
- }
-
- private async Task<string> ReadToEndAsyncInternal()
- {
- // Call ReadBuffer, then pull data out of charBuffer.
- StringBuilder sb = new StringBuilder(_charLen - _charPos);
- do
- {
- int tmpCharPos = _charPos;
- sb.Append(_charBuffer, tmpCharPos, _charLen - tmpCharPos);
- _charPos = _charLen; // We consumed these characters
- await ReadBufferAsync(CancellationToken.None).ConfigureAwait(false);
- } while (_charLen > 0);
-
- return sb.ToString();
- }
-
- public override Task<int> ReadAsync(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0 || count < 0)
- {
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
-
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Read() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Read) when we are not sure.
- if (GetType() != typeof(StreamReader))
- {
- return base.ReadAsync(buffer, index, count);
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task<int> task = ReadAsyncInternal(new Memory<char>(buffer, index, count), CancellationToken.None).AsTask();
- _asyncReadTask = task;
-
- return task;
- }
-
- public override ValueTask<int> ReadAsync(Memory<char> buffer, CancellationToken cancellationToken = default)
- {
- if (GetType() != typeof(StreamReader))
- {
- // Ensure we use existing overrides if a class already overrode existing overloads.
- return base.ReadAsync(buffer, cancellationToken);
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- if (cancellationToken.IsCancellationRequested)
- {
- return new ValueTask<int>(Task.FromCanceled<int>(cancellationToken));
- }
-
- return ReadAsyncInternal(buffer, cancellationToken);
- }
-
- internal override async ValueTask<int> ReadAsyncInternal(Memory<char> buffer, CancellationToken cancellationToken)
- {
- if (_charPos == _charLen && (await ReadBufferAsync(cancellationToken).ConfigureAwait(false)) == 0)
- {
- return 0;
- }
-
- int charsRead = 0;
-
- // As a perf optimization, if we had exactly one buffer's worth of
- // data read in, let's try writing directly to the user's buffer.
- bool readToUserBuffer = false;
-
- byte[] tmpByteBuffer = _byteBuffer;
- Stream tmpStream = _stream;
-
- int count = buffer.Length;
- while (count > 0)
- {
- // n is the characters available in _charBuffer
- int n = _charLen - _charPos;
-
- // charBuffer is empty, let's read from the stream
- if (n == 0)
- {
- _charLen = 0;
- _charPos = 0;
-
- if (!_checkPreamble)
- {
- _byteLen = 0;
- }
-
- readToUserBuffer = count >= _maxCharsPerBuffer;
-
- // We loop here so that we read in enough bytes to yield at least 1 char.
- // We break out of the loop if the stream is blocked (EOF is reached).
- do
- {
- Debug.Assert(n == 0);
-
- if (_checkPreamble)
- {
- Debug.Assert(_bytePos <= _encoding.Preamble.Length, "possible bug in _compressPreamble. Are two threads using this StreamReader at the same time?");
- int tmpBytePos = _bytePos;
- int len = await tmpStream.ReadAsync(new Memory<byte>(tmpByteBuffer, tmpBytePos, tmpByteBuffer.Length - tmpBytePos), cancellationToken).ConfigureAwait(false);
- Debug.Assert(len >= 0, "Stream.Read returned a negative number! This is a bug in your stream class.");
-
- if (len == 0)
- {
- // EOF but we might have buffered bytes from previous
- // attempts to detect preamble that needs to be decoded now
- if (_byteLen > 0)
- {
- if (readToUserBuffer)
- {
- n = _decoder.GetChars(new ReadOnlySpan<byte>(tmpByteBuffer, 0, _byteLen), buffer.Span.Slice(charsRead), flush: false);
- _charLen = 0; // StreamReader's buffer is empty.
- }
- else
- {
- n = _decoder.GetChars(tmpByteBuffer, 0, _byteLen, _charBuffer, 0);
- _charLen += n; // Number of chars in StreamReader's buffer.
- }
- }
-
- // How can part of the preamble yield any chars?
- Debug.Assert(n == 0);
-
- _isBlocked = true;
- break;
- }
- else
- {
- _byteLen += len;
- }
- }
- else
- {
- Debug.Assert(_bytePos == 0, "_bytePos can be non zero only when we are trying to _checkPreamble. Are two threads using this StreamReader at the same time?");
-
- _byteLen = await tmpStream.ReadAsync(new Memory<byte>(tmpByteBuffer), cancellationToken).ConfigureAwait(false);
-
- Debug.Assert(_byteLen >= 0, "Stream.Read returned a negative number! This is a bug in your stream class.");
-
- if (_byteLen == 0) // EOF
- {
- _isBlocked = true;
- break;
- }
- }
-
- // _isBlocked == whether we read fewer bytes than we asked for.
- // Note we must check it here because CompressBuffer or
- // DetectEncoding will change _byteLen.
- _isBlocked = (_byteLen < tmpByteBuffer.Length);
-
- // Check for preamble before detect encoding. This is not to override the
- // user supplied Encoding for the one we implicitly detect. The user could
- // customize the encoding which we will loose, such as ThrowOnError on UTF8
- // Note: we don't need to recompute readToUserBuffer optimization as IsPreamble
- // doesn't change the encoding or affect _maxCharsPerBuffer
- if (IsPreamble())
- {
- continue;
- }
-
- // On the first call to ReadBuffer, if we're supposed to detect the encoding, do it.
- if (_detectEncoding && _byteLen >= 2)
- {
- DetectEncoding();
- // DetectEncoding changes some buffer state. Recompute this.
- readToUserBuffer = count >= _maxCharsPerBuffer;
- }
-
- Debug.Assert(n == 0);
-
- _charPos = 0;
- if (readToUserBuffer)
- {
- n += _decoder.GetChars(new ReadOnlySpan<byte>(tmpByteBuffer, 0, _byteLen), buffer.Span.Slice(charsRead), flush: false);
-
- // Why did the bytes yield no chars?
- Debug.Assert(n > 0);
-
- _charLen = 0; // StreamReader's buffer is empty.
- }
- else
- {
- n = _decoder.GetChars(tmpByteBuffer, 0, _byteLen, _charBuffer, 0);
-
- // Why did the bytes yield no chars?
- Debug.Assert(n > 0);
-
- _charLen += n; // Number of chars in StreamReader's buffer.
- }
- } while (n == 0);
-
- if (n == 0)
- {
- break; // We're at EOF
- }
- } // if (n == 0)
-
- // Got more chars in charBuffer than the user requested
- if (n > count)
- {
- n = count;
- }
-
- if (!readToUserBuffer)
- {
- new Span<char>(_charBuffer, _charPos, n).CopyTo(buffer.Span.Slice(charsRead));
- _charPos += n;
- }
-
- charsRead += n;
- count -= n;
-
- // This function shouldn't block for an indefinite amount of time,
- // or reading from a network stream won't work right. If we got
- // fewer bytes than we requested, then we want to break right here.
- if (_isBlocked)
- {
- break;
- }
- } // while (count > 0)
-
- return charsRead;
- }
-
- public override Task<int> ReadBlockAsync(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0 || count < 0)
- {
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
-
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Read() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Read) when we are not sure.
- if (GetType() != typeof(StreamReader))
- {
- return base.ReadBlockAsync(buffer, index, count);
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task<int> task = base.ReadBlockAsync(buffer, index, count);
- _asyncReadTask = task;
-
- return task;
- }
-
- public override ValueTask<int> ReadBlockAsync(Memory<char> buffer, CancellationToken cancellationToken = default)
- {
- if (GetType() != typeof(StreamReader))
- {
- // If a derived type may have overridden ReadBlockAsync(char[], ...) before this overload
- // was introduced, defer to it.
- return base.ReadBlockAsync(buffer, cancellationToken);
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- if (cancellationToken.IsCancellationRequested)
- {
- return new ValueTask<int>(Task.FromCanceled<int>(cancellationToken));
- }
-
- ValueTask<int> vt = ReadBlockAsyncInternal(buffer, cancellationToken);
- if (vt.IsCompletedSuccessfully)
- {
- return vt;
- }
-
- Task<int> t = vt.AsTask();
- _asyncReadTask = t;
- return new ValueTask<int>(t);
- }
-
- private async ValueTask<int> ReadBufferAsync(CancellationToken cancellationToken)
- {
- _charLen = 0;
- _charPos = 0;
- byte[] tmpByteBuffer = _byteBuffer;
- Stream tmpStream = _stream;
-
- if (!_checkPreamble)
- {
- _byteLen = 0;
- }
- do
- {
- if (_checkPreamble)
- {
- Debug.Assert(_bytePos <= _encoding.Preamble.Length, "possible bug in _compressPreamble. Are two threads using this StreamReader at the same time?");
- int tmpBytePos = _bytePos;
- int len = await tmpStream.ReadAsync(new Memory<byte>(tmpByteBuffer, tmpBytePos, tmpByteBuffer.Length - tmpBytePos), cancellationToken).ConfigureAwait(false);
- Debug.Assert(len >= 0, "Stream.Read returned a negative number! This is a bug in your stream class.");
-
- if (len == 0)
- {
- // EOF but we might have buffered bytes from previous
- // attempt to detect preamble that needs to be decoded now
- if (_byteLen > 0)
- {
- _charLen += _decoder.GetChars(tmpByteBuffer, 0, _byteLen, _charBuffer, _charLen);
- // Need to zero out the _byteLen after we consume these bytes so that we don't keep infinitely hitting this code path
- _bytePos = 0; _byteLen = 0;
- }
-
- return _charLen;
- }
-
- _byteLen += len;
- }
- else
- {
- Debug.Assert(_bytePos == 0, "_bytePos can be non zero only when we are trying to _checkPreamble. Are two threads using this StreamReader at the same time?");
- _byteLen = await tmpStream.ReadAsync(new Memory<byte>(tmpByteBuffer), cancellationToken).ConfigureAwait(false);
- Debug.Assert(_byteLen >= 0, "Stream.Read returned a negative number! Bug in stream class.");
-
- if (_byteLen == 0) // We're at EOF
- {
- return _charLen;
- }
- }
-
- // _isBlocked == whether we read fewer bytes than we asked for.
- // Note we must check it here because CompressBuffer or
- // DetectEncoding will change _byteLen.
- _isBlocked = (_byteLen < tmpByteBuffer.Length);
-
- // Check for preamble before detect encoding. This is not to override the
- // user supplied Encoding for the one we implicitly detect. The user could
- // customize the encoding which we will loose, such as ThrowOnError on UTF8
- if (IsPreamble())
- {
- continue;
- }
-
- // If we're supposed to detect the encoding and haven't done so yet,
- // do it. Note this may need to be called more than once.
- if (_detectEncoding && _byteLen >= 2)
- {
- DetectEncoding();
- }
-
- _charLen += _decoder.GetChars(tmpByteBuffer, 0, _byteLen, _charBuffer, _charLen);
- } while (_charLen == 0);
-
- return _charLen;
- }
-
- private void ThrowIfDisposed()
- {
- if (_disposed)
- {
- ThrowObjectDisposedException();
- }
-
- void ThrowObjectDisposedException() => throw new ObjectDisposedException(GetType().Name, SR.ObjectDisposed_ReaderClosed);
- }
-
- // No data, class doesn't need to be serializable.
- // Note this class is threadsafe.
- private sealed class NullStreamReader : StreamReader
- {
- public override Encoding CurrentEncoding => Encoding.Unicode;
-
- protected override void Dispose(bool disposing)
- {
- // Do nothing - this is essentially unclosable.
- }
-
- public override int Peek()
- {
- return -1;
- }
-
- public override int Read()
- {
- return -1;
- }
-
- public override int Read(char[] buffer, int index, int count)
- {
- return 0;
- }
-
- public override string? ReadLine()
- {
- return null;
- }
-
- public override string ReadToEnd()
- {
- return string.Empty;
- }
-
- internal override int ReadBuffer()
- {
- return 0;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/StreamWriter.cs b/netcore/System.Private.CoreLib/shared/System/IO/StreamWriter.cs
deleted file mode 100644
index 3987457bbfe..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/StreamWriter.cs
+++ /dev/null
@@ -1,1078 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.IO
-{
- // This class implements a TextWriter for writing characters to a Stream.
- // This is designed for character output in a particular Encoding,
- // whereas the Stream class is designed for byte input and output.
- public class StreamWriter : TextWriter
- {
- // For UTF-8, the values of 1K for the default buffer size and 4K for the
- // file stream buffer size are reasonable & give very reasonable
- // performance for in terms of construction time for the StreamWriter and
- // 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.
- private const int DefaultBufferSize = 1024; // char[]
- private const int DefaultFileStreamBufferSize = 4096;
- private const int MinBufferSize = 128;
-
- // Bit bucket - Null has no backing store. Non closable.
- public static new readonly StreamWriter Null = new StreamWriter(Stream.Null, UTF8NoBOM, MinBufferSize, leaveOpen: true);
-
- private readonly Stream _stream;
- private readonly Encoding _encoding;
- private readonly Encoder _encoder;
- private readonly byte[] _byteBuffer;
- private readonly char[] _charBuffer;
- private int _charPos;
- private int _charLen;
- private bool _autoFlush;
- private bool _haveWrittenPreamble;
- private readonly bool _closable;
- private bool _disposed;
-
- // We don't guarantee thread safety on StreamWriter, but we should at
- // least prevent users from trying to write anything while an Async
- // write from the same thread is in progress.
- private Task _asyncWriteTask = Task.CompletedTask;
-
- private void CheckAsyncTaskInProgress()
- {
- // We are not locking the access to _asyncWriteTask because this is not meant to guarantee thread safety.
- // We are simply trying to deter calling any Write APIs while an async Write from the same thread is in progress.
- if (!_asyncWriteTask.IsCompleted)
- {
- ThrowAsyncIOInProgress();
- }
- }
-
- [DoesNotReturn]
- private static void ThrowAsyncIOInProgress() =>
- throw new InvalidOperationException(SR.InvalidOperation_AsyncIOInProgress);
-
- // The high level goal is to be tolerant of encoding errors when we read and very strict
- // when we write. Hence, default StreamWriter encoding will throw on encoding error.
- // Note: when StreamWriter throws on invalid encoding chars (for ex, high surrogate character
- // D800-DBFF without a following low surrogate character DC00-DFFF), it will cause the
- // internal StreamWriter's state to be irrecoverable as it would have buffered the
- // illegal chars and any subsequent call to Flush() would hit the encoding error again.
- // 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!
- private static Encoding UTF8NoBOM => EncodingCache.UTF8NoBOM;
-
- public StreamWriter(Stream stream)
- : this(stream, UTF8NoBOM, DefaultBufferSize, false)
- {
- }
-
- public StreamWriter(Stream stream, Encoding encoding)
- : this(stream, encoding, DefaultBufferSize, false)
- {
- }
-
- // Creates a new StreamWriter for the given stream. The
- // character encoding is set by encoding and the buffer size,
- // in number of 16-bit characters, is set by bufferSize.
- //
- public StreamWriter(Stream stream, Encoding encoding, int bufferSize)
- : this(stream, encoding, bufferSize, false)
- {
- }
-
- public StreamWriter(Stream stream, Encoding? encoding = null, int bufferSize = -1, bool leaveOpen = false)
- : base(null) // Ask for CurrentCulture all the time
- {
- if (stream == null)
- {
- throw new ArgumentNullException(nameof(stream));
- }
- if (encoding == null)
- {
- encoding = UTF8NoBOM;
- }
- if (!stream.CanWrite)
- {
- throw new ArgumentException(SR.Argument_StreamNotWritable);
- }
- if (bufferSize == -1)
- {
- bufferSize = DefaultBufferSize;
- }
- else if (bufferSize <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
- }
-
- _stream = stream;
- _encoding = encoding;
- _encoder = _encoding.GetEncoder();
- if (bufferSize < MinBufferSize)
- {
- bufferSize = MinBufferSize;
- }
-
- _charBuffer = new char[bufferSize];
- _byteBuffer = new byte[_encoding.GetMaxByteCount(bufferSize)];
- _charLen = bufferSize;
- // If we're appending to a Stream that already has data, don't write
- // the preamble.
- if (_stream.CanSeek && _stream.Position > 0)
- {
- _haveWrittenPreamble = true;
- }
-
- _closable = !leaveOpen;
- }
-
- public StreamWriter(string path)
- : this(path, false, UTF8NoBOM, DefaultBufferSize)
- {
- }
-
- public StreamWriter(string path, bool append)
- : this(path, append, UTF8NoBOM, DefaultBufferSize)
- {
- }
-
- public StreamWriter(string path, bool append, Encoding encoding)
- : this(path, append, encoding, DefaultBufferSize)
- {
- }
-
- public StreamWriter(string path, bool append, Encoding encoding, int bufferSize) :
- this(ValidateArgsAndOpenPath(path, append, encoding, bufferSize), encoding, bufferSize, leaveOpen: false)
- {
- }
-
- private static Stream ValidateArgsAndOpenPath(string path, bool append, Encoding encoding, int bufferSize)
- {
- if (path == null)
- throw new ArgumentNullException(nameof(path));
- if (encoding == null)
- throw new ArgumentNullException(nameof(encoding));
- if (path.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyPath);
- if (bufferSize <= 0)
- throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
-
- return new FileStream(path, append ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.Read, DefaultFileStreamBufferSize, FileOptions.SequentialScan);
- }
-
- public override void Close()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected override void Dispose(bool disposing)
- {
- try
- {
- // We need to flush any buffered data if we are being closed/disposed.
- // Also, we never close the handles for stdout & friends. So we can safely
- // write any buffered data to those streams even during finalization, which
- // is generally the right thing to do.
- if (!_disposed && disposing)
- {
- // Note: flush on the underlying stream can throw (ex., low disk space)
- CheckAsyncTaskInProgress();
- Flush(flushStream: true, flushEncoder: true);
- }
- }
- finally
- {
- CloseStreamFromDispose(disposing);
- }
- }
-
- private void CloseStreamFromDispose(bool disposing)
- {
- // Dispose of our resources if this StreamWriter is closable.
- if (_closable && !_disposed)
- {
- 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
- {
- _disposed = true;
- _charLen = 0;
- base.Dispose(disposing);
- }
- }
- }
-
- public override ValueTask DisposeAsync() =>
- GetType() != typeof(StreamWriter) ?
- base.DisposeAsync() :
- DisposeAsyncCore();
-
- private async ValueTask DisposeAsyncCore()
- {
- // Same logic as in Dispose(), but with async flushing.
- Debug.Assert(GetType() == typeof(StreamWriter));
- try
- {
- if (!_disposed)
- {
- await FlushAsync().ConfigureAwait(false);
- }
- }
- finally
- {
- CloseStreamFromDispose(disposing: true);
- }
- GC.SuppressFinalize(this);
- }
-
- public override void Flush()
- {
- CheckAsyncTaskInProgress();
-
- Flush(true, true);
- }
-
- private void Flush(bool flushStream, bool flushEncoder)
- {
- // flushEncoder should be true at the end of the file and if
- // the user explicitly calls Flush (though not if AutoFlush is true).
- // This is required to flush any dangling characters from our UTF-7
- // and UTF-8 encoders.
- ThrowIfDisposed();
-
- // Perf boost for Flush on non-dirty writers.
- if (_charPos == 0 && !flushStream && !flushEncoder)
- {
- return;
- }
-
- if (!_haveWrittenPreamble)
- {
- _haveWrittenPreamble = true;
- ReadOnlySpan<byte> preamble = _encoding.Preamble;
- if (preamble.Length > 0)
- {
- _stream.Write(preamble);
- }
- }
-
- int count = _encoder.GetBytes(_charBuffer, 0, _charPos, _byteBuffer, 0, flushEncoder);
- _charPos = 0;
- if (count > 0)
- {
- _stream.Write(_byteBuffer, 0, count);
- }
- // By definition, calling Flush should flush the stream, but this is
- // only necessary if we passed in true for flushStream. The Web
- // Services guys have some perf tests where flushing needlessly hurts.
- if (flushStream)
- {
- _stream.Flush();
- }
- }
-
- public virtual bool AutoFlush
- {
- get => _autoFlush;
-
- set
- {
- CheckAsyncTaskInProgress();
-
- _autoFlush = value;
- if (value)
- {
- Flush(true, false);
- }
- }
- }
-
- public virtual Stream BaseStream => _stream;
-
- public override Encoding Encoding => _encoding;
-
- public override void Write(char value)
- {
- CheckAsyncTaskInProgress();
-
- if (_charPos == _charLen)
- {
- Flush(false, false);
- }
-
- _charBuffer[_charPos] = value;
- _charPos++;
- if (_autoFlush)
- {
- Flush(true, false);
- }
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)] // prevent WriteSpan from bloating call sites
- public override void Write(char[]? buffer)
- {
- WriteSpan(buffer, appendNewLine: false);
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)] // prevent WriteSpan from bloating call sites
- public override void Write(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
-
- WriteSpan(buffer.AsSpan(index, count), appendNewLine: false);
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)] // prevent WriteSpan from bloating call sites
- public override void Write(ReadOnlySpan<char> buffer)
- {
- if (GetType() == typeof(StreamWriter))
- {
- WriteSpan(buffer, appendNewLine: false);
- }
- else
- {
- // If a derived class may have overridden existing Write behavior,
- // we need to make sure we use it.
- base.Write(buffer);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private unsafe void WriteSpan(ReadOnlySpan<char> buffer, bool appendNewLine)
- {
- CheckAsyncTaskInProgress();
-
- if (buffer.Length <= 4 && // Threshold of 4 chosen based on perf experimentation
- buffer.Length <= _charLen - _charPos)
- {
- // For very short buffers and when we don't need to worry about running out of space
- // in the char buffer, just copy the chars individually.
- for (int i = 0; i < buffer.Length; i++)
- {
- _charBuffer[_charPos++] = buffer[i];
- }
- }
- else
- {
- // For larger buffers or when we may run out of room in the internal char buffer, copy in chunks.
- // Use unsafe code until https://github.com/dotnet/coreclr/issues/13827 is addressed, as spans are
- // resulting in significant overhead (even when the if branch above is taken rather than this
- // else) due to temporaries that need to be cleared. Given the use of unsafe code, we also
- // make local copies of instance state to protect against potential concurrent misuse.
-
- ThrowIfDisposed();
- char[] charBuffer = _charBuffer;
-
- fixed (char* bufferPtr = &MemoryMarshal.GetReference(buffer))
- fixed (char* dstPtr = &charBuffer[0])
- {
- char* srcPtr = bufferPtr;
- int count = buffer.Length;
- int dstPos = _charPos; // use a local copy of _charPos for safety
- while (count > 0)
- {
- if (dstPos == charBuffer.Length)
- {
- Flush(false, false);
- dstPos = 0;
- }
-
- int n = Math.Min(charBuffer.Length - dstPos, count);
- int bytesToCopy = n * sizeof(char);
-
- Buffer.MemoryCopy(srcPtr, dstPtr + dstPos, bytesToCopy, bytesToCopy);
-
- _charPos += n;
- dstPos += n;
- srcPtr += n;
- count -= n;
- }
- }
- }
-
- if (appendNewLine)
- {
- char[] coreNewLine = CoreNewLine;
- for (int i = 0; i < coreNewLine.Length; i++) // Generally 1 (\n) or 2 (\r\n) iterations
- {
- if (_charPos == _charLen)
- {
- Flush(false, false);
- }
-
- _charBuffer[_charPos] = coreNewLine[i];
- _charPos++;
- }
- }
-
- if (_autoFlush)
- {
- Flush(true, false);
- }
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)] // prevent WriteSpan from bloating call sites
- public override void Write(string? value)
- {
- WriteSpan(value, appendNewLine: false);
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)] // prevent WriteSpan from bloating call sites
- public override void WriteLine(string? value)
- {
- CheckAsyncTaskInProgress();
- WriteSpan(value, appendNewLine: true);
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)] // prevent WriteSpan from bloating call sites
- public override void WriteLine(ReadOnlySpan<char> value)
- {
- if (GetType() == typeof(StreamWriter))
- {
- CheckAsyncTaskInProgress();
- WriteSpan(value, appendNewLine: true);
- }
- else
- {
- // If a derived class may have overridden existing WriteLine behavior,
- // we need to make sure we use it.
- base.WriteLine(value);
- }
- }
-
- private void WriteFormatHelper(string format, ParamsArray args, bool appendNewLine)
- {
- StringBuilder sb =
- StringBuilderCache.Acquire((format?.Length ?? 0) + args.Length * 8)
- .AppendFormatHelper(null, format!, args); // AppendFormatHelper will appropriately throw ArgumentNullException for a null format
-
- StringBuilder.ChunkEnumerator chunks = sb.GetChunks();
-
- bool more = chunks.MoveNext();
- while (more)
- {
- ReadOnlySpan<char> current = chunks.Current.Span;
- more = chunks.MoveNext();
-
- // If final chunk, include the newline if needed
- WriteSpan(current, appendNewLine: more ? false : appendNewLine);
- }
-
- StringBuilderCache.Release(sb);
- }
-
- public override void Write(string format, object? arg0)
- {
- if (GetType() == typeof(StreamWriter))
- {
- WriteFormatHelper(format, new ParamsArray(arg0), appendNewLine: false);
- }
- else
- {
- base.Write(format, arg0);
- }
- }
-
- public override void Write(string format, object? arg0, object? arg1)
- {
- if (GetType() == typeof(StreamWriter))
- {
- WriteFormatHelper(format, new ParamsArray(arg0, arg1), appendNewLine: false);
- }
- else
- {
- base.Write(format, arg0, arg1);
- }
- }
-
- public override void Write(string format, object? arg0, object? arg1, object? arg2)
- {
- if (GetType() == typeof(StreamWriter))
- {
- WriteFormatHelper(format, new ParamsArray(arg0, arg1, arg2), appendNewLine: false);
- }
- else
- {
- base.Write(format, arg0, arg1, arg2);
- }
- }
-
- public override void Write(string format, params object?[] arg)
- {
- if (GetType() == typeof(StreamWriter))
- {
- if (arg == null)
- {
- throw new ArgumentNullException((format == null) ? nameof(format) : nameof(arg)); // same as base logic
- }
- WriteFormatHelper(format, new ParamsArray(arg), appendNewLine: false);
- }
- else
- {
- base.Write(format, arg);
- }
- }
-
- public override void WriteLine(string format, object? arg0)
- {
- if (GetType() == typeof(StreamWriter))
- {
- WriteFormatHelper(format, new ParamsArray(arg0), appendNewLine: true);
- }
- else
- {
- base.WriteLine(format, arg0);
- }
- }
-
- public override void WriteLine(string format, object? arg0, object? arg1)
- {
- if (GetType() == typeof(StreamWriter))
- {
- WriteFormatHelper(format, new ParamsArray(arg0, arg1), appendNewLine: true);
- }
- else
- {
- base.WriteLine(format, arg0, arg1);
- }
- }
-
- public override void WriteLine(string format, object? arg0, object? arg1, object? arg2)
- {
- if (GetType() == typeof(StreamWriter))
- {
- WriteFormatHelper(format, new ParamsArray(arg0, arg1, arg2), appendNewLine: true);
- }
- else
- {
- base.WriteLine(format, arg0, arg1, arg2);
- }
- }
-
- public override void WriteLine(string format, params object?[] arg)
- {
- if (GetType() == typeof(StreamWriter))
- {
- if (arg == null)
- {
- throw new ArgumentNullException(nameof(arg));
- }
- WriteFormatHelper(format, new ParamsArray(arg), appendNewLine: true);
- }
- else
- {
- base.WriteLine(format, arg);
- }
- }
-
- public override Task WriteAsync(char value)
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Write() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Write) when we are not sure.
- if (GetType() != typeof(StreamWriter))
- {
- return base.WriteAsync(value);
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task task = WriteAsyncInternal(this, value, _charBuffer, _charPos, _charLen, CoreNewLine, _autoFlush, appendNewLine: false);
- _asyncWriteTask = task;
-
- return task;
- }
-
- // We pass in private instance fields of this MarshalByRefObject-derived type as local params
- // to ensure performant access inside the state machine that corresponds this async method.
- // Fields that are written to must be assigned at the end of the method *and* before instance invocations.
- private static async Task WriteAsyncInternal(StreamWriter _this, char value,
- char[] charBuffer, int charPos, int charLen, char[] coreNewLine,
- bool autoFlush, bool appendNewLine)
- {
- if (charPos == charLen)
- {
- await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);
- Debug.Assert(_this._charPos == 0);
- charPos = 0;
- }
-
- charBuffer[charPos] = value;
- charPos++;
-
- if (appendNewLine)
- {
- for (int i = 0; i < coreNewLine.Length; i++) // Expect 2 iterations, no point calling BlockCopy
- {
- if (charPos == charLen)
- {
- await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);
- Debug.Assert(_this._charPos == 0);
- charPos = 0;
- }
-
- charBuffer[charPos] = coreNewLine[i];
- charPos++;
- }
- }
-
- if (autoFlush)
- {
- await _this.FlushAsyncInternal(true, false, charBuffer, charPos).ConfigureAwait(false);
- Debug.Assert(_this._charPos == 0);
- charPos = 0;
- }
-
- _this._charPos = charPos;
- }
-
- public override Task WriteAsync(string? value)
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Write() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Write) when we are not sure.
- if (GetType() != typeof(StreamWriter))
- {
- return base.WriteAsync(value);
- }
-
- if (value != null)
- {
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task task = WriteAsyncInternal(this, value, _charBuffer, _charPos, _charLen, CoreNewLine, _autoFlush, appendNewLine: false);
- _asyncWriteTask = task;
-
- return task;
- }
- else
- {
- return Task.CompletedTask;
- }
- }
-
- // We pass in private instance fields of this MarshalByRefObject-derived type as local params
- // to ensure performant access inside the state machine that corresponds this async method.
- // Fields that are written to must be assigned at the end of the method *and* before instance invocations.
- private static async Task WriteAsyncInternal(StreamWriter _this, string value,
- char[] charBuffer, int charPos, int charLen, char[] coreNewLine,
- bool autoFlush, bool appendNewLine)
- {
- Debug.Assert(value != null);
-
- int count = value.Length;
- int index = 0;
-
- while (count > 0)
- {
- if (charPos == charLen)
- {
- await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);
- Debug.Assert(_this._charPos == 0);
- charPos = 0;
- }
-
- int n = charLen - charPos;
- if (n > count)
- {
- n = count;
- }
-
- Debug.Assert(n > 0, "StreamWriter::Write(String) isn't making progress! This is most likely a race condition in user code.");
-
- value.CopyTo(index, charBuffer, charPos, n);
-
- charPos += n;
- index += n;
- count -= n;
- }
-
- if (appendNewLine)
- {
- for (int i = 0; i < coreNewLine.Length; i++) // Expect 2 iterations, no point calling BlockCopy
- {
- if (charPos == charLen)
- {
- await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);
- Debug.Assert(_this._charPos == 0);
- charPos = 0;
- }
-
- charBuffer[charPos] = coreNewLine[i];
- charPos++;
- }
- }
-
- if (autoFlush)
- {
- await _this.FlushAsyncInternal(true, false, charBuffer, charPos).ConfigureAwait(false);
- Debug.Assert(_this._charPos == 0);
- charPos = 0;
- }
-
- _this._charPos = charPos;
- }
-
- public override Task WriteAsync(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
-
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Write() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Write) when we are not sure.
- if (GetType() != typeof(StreamWriter))
- {
- return base.WriteAsync(buffer, index, count);
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task task = WriteAsyncInternal(this, new ReadOnlyMemory<char>(buffer, index, count), _charBuffer, _charPos, _charLen, CoreNewLine, _autoFlush, appendNewLine: false, cancellationToken: default);
- _asyncWriteTask = task;
-
- return task;
- }
-
- public override Task WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default)
- {
- if (GetType() != typeof(StreamWriter))
- {
- // If a derived type may have overridden existing WriteASync(char[], ...) behavior, make sure we use it.
- return base.WriteAsync(buffer, cancellationToken);
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
-
- Task task = WriteAsyncInternal(this, buffer, _charBuffer, _charPos, _charLen, CoreNewLine, _autoFlush, appendNewLine: false, cancellationToken: cancellationToken);
- _asyncWriteTask = task;
- return task;
- }
-
- // We pass in private instance fields of this MarshalByRefObject-derived type as local params
- // to ensure performant access inside the state machine that corresponds this async method.
- // Fields that are written to must be assigned at the end of the method *and* before instance invocations.
- private static async Task WriteAsyncInternal(StreamWriter _this, ReadOnlyMemory<char> source,
- char[] charBuffer, int charPos, int charLen, char[] coreNewLine,
- bool autoFlush, bool appendNewLine, CancellationToken cancellationToken)
- {
- int copied = 0;
- while (copied < source.Length)
- {
- if (charPos == charLen)
- {
- await _this.FlushAsyncInternal(false, false, charBuffer, charPos, cancellationToken).ConfigureAwait(false);
- Debug.Assert(_this._charPos == 0);
- charPos = 0;
- }
-
- int n = Math.Min(charLen - charPos, source.Length - copied);
- Debug.Assert(n > 0, "StreamWriter::Write(char[], int, int) isn't making progress! This is most likely a race condition in user code.");
-
- source.Span.Slice(copied, n).CopyTo(new Span<char>(charBuffer, charPos, n));
- charPos += n;
- copied += n;
- }
-
- if (appendNewLine)
- {
- for (int i = 0; i < coreNewLine.Length; i++) // Expect 2 iterations, no point calling BlockCopy
- {
- if (charPos == charLen)
- {
- await _this.FlushAsyncInternal(false, false, charBuffer, charPos, cancellationToken).ConfigureAwait(false);
- Debug.Assert(_this._charPos == 0);
- charPos = 0;
- }
-
- charBuffer[charPos] = coreNewLine[i];
- charPos++;
- }
- }
-
- if (autoFlush)
- {
- await _this.FlushAsyncInternal(true, false, charBuffer, charPos, cancellationToken).ConfigureAwait(false);
- Debug.Assert(_this._charPos == 0);
- charPos = 0;
- }
-
- _this._charPos = charPos;
- }
-
- public override Task WriteLineAsync()
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Write() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Write) when we are not sure.
- if (GetType() != typeof(StreamWriter))
- {
- return base.WriteLineAsync();
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task task = WriteAsyncInternal(this, ReadOnlyMemory<char>.Empty, _charBuffer, _charPos, _charLen, CoreNewLine, _autoFlush, appendNewLine: true, cancellationToken: default);
- _asyncWriteTask = task;
-
- return task;
- }
-
-
- public override Task WriteLineAsync(char value)
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Write() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Write) when we are not sure.
- if (GetType() != typeof(StreamWriter))
- {
- return base.WriteLineAsync(value);
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task task = WriteAsyncInternal(this, value, _charBuffer, _charPos, _charLen, CoreNewLine, _autoFlush, appendNewLine: true);
- _asyncWriteTask = task;
-
- return task;
- }
-
-
- public override Task WriteLineAsync(string? value)
- {
- if (value == null)
- {
- return WriteLineAsync();
- }
-
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Write() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Write) when we are not sure.
- if (GetType() != typeof(StreamWriter))
- {
- return base.WriteLineAsync(value);
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task task = WriteAsyncInternal(this, value, _charBuffer, _charPos, _charLen, CoreNewLine, _autoFlush, appendNewLine: true);
- _asyncWriteTask = task;
-
- return task;
- }
-
-
- public override Task WriteLineAsync(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
-
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Write() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Write) when we are not sure.
- if (GetType() != typeof(StreamWriter))
- {
- return base.WriteLineAsync(buffer, index, count);
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task task = WriteAsyncInternal(this, new ReadOnlyMemory<char>(buffer, index, count), _charBuffer, _charPos, _charLen, CoreNewLine, _autoFlush, appendNewLine: true, cancellationToken: default);
- _asyncWriteTask = task;
-
- return task;
- }
-
- public override Task WriteLineAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default)
- {
- if (GetType() != typeof(StreamWriter))
- {
- return base.WriteLineAsync(buffer, cancellationToken);
- }
-
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
-
- Task task = WriteAsyncInternal(this, buffer, _charBuffer, _charPos, _charLen, CoreNewLine, _autoFlush, appendNewLine: true, cancellationToken: cancellationToken);
- _asyncWriteTask = task;
-
- return task;
- }
-
-
- public override Task FlushAsync()
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Flush() which a subclass might have overridden. To be safe
- // we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Flush) when we are not sure.
- if (GetType() != typeof(StreamWriter))
- {
- return base.FlushAsync();
- }
-
- // flushEncoder should be true at the end of the file and if
- // the user explicitly calls Flush (though not if AutoFlush is true).
- // This is required to flush any dangling characters from our UTF-7
- // and UTF-8 encoders.
- ThrowIfDisposed();
- CheckAsyncTaskInProgress();
-
- Task task = FlushAsyncInternal(true, true, _charBuffer, _charPos);
- _asyncWriteTask = task;
-
- return task;
- }
-
- private Task FlushAsyncInternal(bool flushStream, bool flushEncoder,
- char[] sCharBuffer, int sCharPos, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
-
- // Perf boost for Flush on non-dirty writers.
- if (sCharPos == 0 && !flushStream && !flushEncoder)
- {
- return Task.CompletedTask;
- }
-
- Task flushTask = FlushAsyncInternal(this, flushStream, flushEncoder, sCharBuffer, sCharPos, _haveWrittenPreamble,
- _encoding, _encoder, _byteBuffer, _stream, cancellationToken);
-
- _charPos = 0;
- return flushTask;
- }
-
-
- // We pass in private instance fields of this MarshalByRefObject-derived type as local params
- // to ensure performant access inside the state machine that corresponds this async method.
- private static async Task FlushAsyncInternal(StreamWriter _this, bool flushStream, bool flushEncoder,
- char[] charBuffer, int charPos, bool haveWrittenPreamble,
- Encoding encoding, Encoder encoder, byte[] byteBuffer, Stream stream, CancellationToken cancellationToken)
- {
- if (!haveWrittenPreamble)
- {
- _this._haveWrittenPreamble = true;
- byte[] preamble = encoding.GetPreamble();
- if (preamble.Length > 0)
- {
- await stream.WriteAsync(new ReadOnlyMemory<byte>(preamble), cancellationToken).ConfigureAwait(false);
- }
- }
-
- int count = encoder.GetBytes(charBuffer, 0, charPos, byteBuffer, 0, flushEncoder);
- if (count > 0)
- {
- await stream.WriteAsync(new ReadOnlyMemory<byte>(byteBuffer, 0, count), cancellationToken).ConfigureAwait(false);
- }
-
- // By definition, calling Flush should flush the stream, but this is
- // only necessary if we passed in true for flushStream. The Web
- // Services guys have some perf tests where flushing needlessly hurts.
- if (flushStream)
- {
- await stream.FlushAsync(cancellationToken).ConfigureAwait(false);
- }
- }
-
- private void ThrowIfDisposed()
- {
- if (_disposed)
- {
- ThrowObjectDisposedException();
- }
-
- void ThrowObjectDisposedException() => throw new ObjectDisposedException(GetType().Name, SR.ObjectDisposed_WriterClosed);
- }
- } // class StreamWriter
-} // namespace
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/TextReader.cs b/netcore/System.Private.CoreLib/shared/System/IO/TextReader.cs
deleted file mode 100644
index 50c4d77e03f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/TextReader.cs
+++ /dev/null
@@ -1,406 +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 System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Buffers;
-
-namespace System.IO
-{
- // This abstract base class represents a reader that can read a sequential
- // stream of characters. This is not intended for reading bytes -
- // there are methods on the Stream class to read bytes.
- // A subclass must minimally implement the Peek() and Read() methods.
- //
- // This class is intended for character input, not bytes.
- // There are methods on the Stream class for reading bytes.
- public abstract partial class TextReader : MarshalByRefObject, IDisposable
- {
- public static readonly TextReader Null = new NullTextReader();
-
- protected TextReader() { }
-
- public virtual void Close()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- }
-
- // Returns the next available character without actually reading it from
- // the input stream. The current position of the TextReader is not changed by
- // this operation. The returned value is -1 if no further characters are
- // available.
- //
- // This default method simply returns -1.
- //
- public virtual int Peek()
- {
- return -1;
- }
-
- // Reads the next character from the input stream. The returned value is
- // -1 if no further characters are available.
- //
- // This default method simply returns -1.
- //
- public virtual int Read()
- {
- return -1;
- }
-
- // Reads a block of characters. This method will read up to
- // count characters from this TextReader into the
- // buffer character array starting at position
- // index. Returns the actual number of characters read.
- //
- public virtual int Read(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
-
- int n;
- for (n = 0; n < count; n++)
- {
- int ch = Read();
- if (ch == -1) break;
- buffer[index + n] = (char)ch;
- }
-
- return n;
- }
-
- // Reads a span of characters. This method will read up to
- // count characters from this TextReader into the
- // span of characters Returns the actual number of characters read.
- //
- public virtual int Read(Span<char> buffer)
- {
- char[] array = ArrayPool<char>.Shared.Rent(buffer.Length);
-
- try
- {
- int numRead = Read(array, 0, buffer.Length);
- if ((uint)numRead > (uint)buffer.Length)
- {
- throw new IOException(SR.IO_InvalidReadLength);
- }
- new Span<char>(array, 0, numRead).CopyTo(buffer);
- return numRead;
- }
- finally
- {
- ArrayPool<char>.Shared.Return(array);
- }
- }
-
- // Reads all characters from the current position to the end of the
- // TextReader, and returns them as one string.
- public virtual string ReadToEnd()
- {
- char[] chars = new char[4096];
- int len;
- StringBuilder sb = new StringBuilder(4096);
- while ((len = Read(chars, 0, chars.Length)) != 0)
- {
- sb.Append(chars, 0, len);
- }
- return sb.ToString();
- }
-
- // Blocking version of read. Returns only when count
- // characters have been read or the end of the file was reached.
- //
- public virtual int ReadBlock(char[] buffer, int index, int count)
- {
- int i, n = 0;
- do
- {
- n += (i = Read(buffer, index + n, count - n));
- } while (i > 0 && n < count);
- return n;
- }
-
- // Blocking version of read for span of characters. Returns only when count
- // characters have been read or the end of the file was reached.
- //
- public virtual int ReadBlock(Span<char> buffer)
- {
- char[] array = ArrayPool<char>.Shared.Rent(buffer.Length);
-
- try
- {
- int numRead = ReadBlock(array, 0, buffer.Length);
- if ((uint)numRead > (uint)buffer.Length)
- {
- throw new IOException(SR.IO_InvalidReadLength);
- }
- new Span<char>(array, 0, numRead).CopyTo(buffer);
- return numRead;
- }
- finally
- {
- ArrayPool<char>.Shared.Return(array);
- }
- }
-
- // Reads a line. A line is defined as a sequence of characters followed by
- // a carriage return ('\r'), a line feed ('\n'), or a carriage return
- // immediately followed by a line feed. The resulting string does not
- // contain the terminating carriage return and/or line feed. The returned
- // value is null if the end of the input stream has been reached.
- //
- public virtual string? ReadLine()
- {
- StringBuilder sb = new StringBuilder();
- while (true)
- {
- int ch = Read();
- if (ch == -1) break;
- if (ch == '\r' || ch == '\n')
- {
- if (ch == '\r' && Peek() == '\n')
- {
- Read();
- }
-
- return sb.ToString();
- }
- sb.Append((char)ch);
- }
- if (sb.Length > 0)
- {
- return sb.ToString();
- }
-
- return null;
- }
-
- #region Task based Async APIs
- public virtual Task<string?> ReadLineAsync() =>
- Task<string?>.Factory.StartNew(state => ((TextReader)state!).ReadLine(), this,
- CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
-
- public virtual async Task<string> ReadToEndAsync()
- {
- var sb = new StringBuilder(4096);
- char[] chars = ArrayPool<char>.Shared.Rent(4096);
- try
- {
- int len;
- while ((len = await ReadAsyncInternal(chars, default).ConfigureAwait(false)) != 0)
- {
- sb.Append(chars, 0, len);
- }
- }
- finally
- {
- ArrayPool<char>.Shared.Return(chars);
- }
- return sb.ToString();
- }
-
- public virtual Task<int> ReadAsync(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0 || count < 0)
- {
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
-
- return ReadAsyncInternal(new Memory<char>(buffer, index, count), default).AsTask();
- }
-
- public virtual ValueTask<int> ReadAsync(Memory<char> buffer, CancellationToken cancellationToken = default) =>
- new ValueTask<int>(MemoryMarshal.TryGetArray(buffer, out ArraySegment<char> array) ?
- ReadAsync(array.Array!, array.Offset, array.Count) :
- Task<int>.Factory.StartNew(state =>
- {
- var t = (Tuple<TextReader, Memory<char>>)state!;
- return t.Item1.Read(t.Item2.Span);
- }, Tuple.Create(this, buffer), cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default));
-
- internal virtual ValueTask<int> ReadAsyncInternal(Memory<char> buffer, CancellationToken cancellationToken)
- {
- var tuple = new Tuple<TextReader, Memory<char>>(this, buffer);
- return new ValueTask<int>(Task<int>.Factory.StartNew(state =>
- {
- var t = (Tuple<TextReader, Memory<char>>)state!;
- return t.Item1.Read(t.Item2.Span);
- },
- tuple, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default));
- }
-
- public virtual Task<int> ReadBlockAsync(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0 || count < 0)
- {
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
-
- return ReadBlockAsyncInternal(new Memory<char>(buffer, index, count), default).AsTask();
- }
-
- public virtual ValueTask<int> ReadBlockAsync(Memory<char> buffer, CancellationToken cancellationToken = default) =>
- new ValueTask<int>(MemoryMarshal.TryGetArray(buffer, out ArraySegment<char> array) ?
- ReadBlockAsync(array.Array!, array.Offset, array.Count) :
- Task<int>.Factory.StartNew(state =>
- {
- var t = (Tuple<TextReader, Memory<char>>)state!;
- return t.Item1.ReadBlock(t.Item2.Span);
- }, Tuple.Create(this, buffer), cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default));
-
- internal async ValueTask<int> ReadBlockAsyncInternal(Memory<char> buffer, CancellationToken cancellationToken)
- {
- int n = 0, i;
- do
- {
- i = await ReadAsyncInternal(buffer.Slice(n), cancellationToken).ConfigureAwait(false);
- n += i;
- } while (i > 0 && n < buffer.Length);
-
- return n;
- }
- #endregion
-
- private sealed class NullTextReader : TextReader
- {
- public NullTextReader() { }
-
- public override int Read(char[] buffer, int index, int count)
- {
- return 0;
- }
-
- public override string? ReadLine()
- {
- return null;
- }
- }
-
- public static TextReader Synchronized(TextReader reader)
- {
- if (reader == null)
- throw new ArgumentNullException(nameof(reader));
-
- return reader is SyncTextReader ? reader : new SyncTextReader(reader);
- }
-
- internal sealed class SyncTextReader : TextReader
- {
- internal readonly TextReader _in;
-
- internal SyncTextReader(TextReader t)
- {
- _in = t;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Close() => _in.Close();
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- protected override void Dispose(bool disposing)
- {
- // Explicitly pick up a potentially methodimpl'ed Dispose
- if (disposing)
- ((IDisposable)_in).Dispose();
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override int Peek() => _in.Peek();
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override int Read() => _in.Read();
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override int Read(char[] buffer, int index, int count) => _in.Read(buffer, index, count);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override int ReadBlock(char[] buffer, int index, int count) => _in.ReadBlock(buffer, index, count);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override string? ReadLine() => _in.ReadLine();
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override string ReadToEnd() => _in.ReadToEnd();
-
- //
- // On SyncTextReader all APIs should run synchronously, even the async ones.
- //
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task<string?> ReadLineAsync() => Task.FromResult(ReadLine());
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task<string> ReadToEndAsync() => Task.FromResult(ReadToEnd());
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task<int> ReadBlockAsync(char[] buffer, int index, int count)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- return Task.FromResult(ReadBlock(buffer, index, count));
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task<int> ReadAsync(char[] buffer, int index, int count)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- return Task.FromResult(Read(buffer, index, count));
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/TextWriter.cs b/netcore/System.Private.CoreLib/shared/System/IO/TextWriter.cs
deleted file mode 100644
index 8263072b14e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/TextWriter.cs
+++ /dev/null
@@ -1,1016 +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 System.Text;
-using System.Threading;
-using System.Globalization;
-using System.Threading.Tasks;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Buffers;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.IO
-{
- // This abstract base class represents a writer that can write a sequential
- // stream of characters. A subclass must minimally implement the
- // Write(char) method.
- //
- // This class is intended for character output, not bytes.
- // There are methods on the Stream class for writing bytes.
- public abstract partial class TextWriter : MarshalByRefObject, IDisposable, IAsyncDisposable
- {
- public static readonly TextWriter Null = new NullTextWriter();
-
- // We don't want to allocate on every TextWriter creation, so cache the char array.
- private static readonly char[] s_coreNewLine = Environment.NewLineConst.ToCharArray();
-
- /// <summary>
- /// This is the 'NewLine' property expressed as a char[].
- /// It is exposed to subclasses as a protected field for read-only
- /// purposes. You should only modify it by using the 'NewLine' property.
- /// In particular you should never modify the elements of the array
- /// as they are shared among many instances of TextWriter.
- /// </summary>
- protected char[] CoreNewLine = s_coreNewLine;
- private string CoreNewLineStr = Environment.NewLineConst;
-
- // Can be null - if so, ask for the Thread's CurrentCulture every time.
- private readonly IFormatProvider? _internalFormatProvider;
-
- protected TextWriter()
- {
- _internalFormatProvider = null; // Ask for CurrentCulture all the time.
- }
-
- protected TextWriter(IFormatProvider? formatProvider)
- {
- _internalFormatProvider = formatProvider;
- }
-
- public virtual IFormatProvider FormatProvider
- {
- get
- {
- if (_internalFormatProvider == null)
- {
- return CultureInfo.CurrentCulture;
- }
- else
- {
- return _internalFormatProvider;
- }
- }
- }
-
- public virtual void Close()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- public virtual ValueTask DisposeAsync()
- {
- try
- {
- Dispose();
- return default;
- }
- catch (Exception exc)
- {
- return new ValueTask(Task.FromException(exc));
- }
- }
-
- // 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
- // functionality.
- public virtual void Flush()
- {
- }
-
- public abstract Encoding Encoding
- {
- get;
- }
-
- /// <summary>
- /// Returns the line terminator string used by this TextWriter. The default line
- /// terminator string is Environment.NewLine, which is platform specific.
- /// On Windows this is a carriage return followed by a line feed ("\r\n").
- /// On OSX and Linux this is a line feed ("\n").
- /// </summary>
- /// <remarks>
- /// The line terminator string is written to the text stream whenever one of the
- /// WriteLine methods are called. In order for text written by
- /// the TextWriter to be readable by a TextReader, only one of the following line
- /// terminator strings should be used: "\r", "\n", or "\r\n".
- /// </remarks>
- [AllowNull]
- public virtual string NewLine
- {
- get => CoreNewLineStr;
- set
- {
- if (value == null)
- {
- value = Environment.NewLineConst;
- }
-
- CoreNewLineStr = value;
- CoreNewLine = value.ToCharArray();
- }
- }
-
- // Writes a character to the text stream. This default method is empty,
- // but descendant classes can override the method to provide the
- // appropriate functionality.
- //
- public virtual void Write(char value)
- {
- }
-
- // Writes a character array to the text stream. This default method calls
- // Write(char) for each of the characters in the character array.
- // If the character array is null, nothing is written.
- //
- public virtual void Write(char[]? buffer)
- {
- if (buffer != null)
- {
- Write(buffer, 0, buffer.Length);
- }
- }
-
- // Writes a range of a character array to the text stream. This method will
- // write count characters of data into this TextWriter from the
- // buffer character array starting at position index.
- //
- public virtual void Write(char[] buffer, int index, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- }
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.Length - index < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
-
- for (int i = 0; i < count; i++) Write(buffer[index + i]);
- }
-
- // Writes a span of characters to the text stream.
- //
- public virtual void Write(ReadOnlySpan<char> buffer)
- {
- char[] array = ArrayPool<char>.Shared.Rent(buffer.Length);
-
- try
- {
- buffer.CopyTo(new Span<char>(array));
- Write(array, 0, buffer.Length);
- }
- finally
- {
- ArrayPool<char>.Shared.Return(array);
- }
- }
-
- // Writes the text representation of a boolean to the text stream. This
- // method outputs either bool.TrueString or bool.FalseString.
- //
- public virtual void Write(bool value)
- {
- Write(value ? "True" : "False");
- }
-
- // Writes the text representation of an integer to the text stream. The
- // text representation of the given value is produced by calling the
- // int.ToString() method.
- //
- public virtual void Write(int value)
- {
- Write(value.ToString(FormatProvider));
- }
-
- // Writes the text representation of an integer to the text stream. The
- // text representation of the given value is produced by calling the
- // uint.ToString() method.
- //
- [CLSCompliant(false)]
- public virtual void Write(uint value)
- {
- Write(value.ToString(FormatProvider));
- }
-
- // Writes the text representation of a long to the text stream. The
- // text representation of the given value is produced by calling the
- // long.ToString() method.
- //
- public virtual void Write(long value)
- {
- Write(value.ToString(FormatProvider));
- }
-
- // Writes the text representation of an unsigned long to the text
- // stream. The text representation of the given value is produced
- // by calling the ulong.ToString() method.
- //
- [CLSCompliant(false)]
- public virtual void Write(ulong value)
- {
- Write(value.ToString(FormatProvider));
- }
-
- // Writes the text representation of a float to the text stream. The
- // text representation of the given value is produced by calling the
- // float.ToString(float) method.
- //
- public virtual void Write(float value)
- {
- Write(value.ToString(FormatProvider));
- }
-
- // Writes the text representation of a double to the text stream. The
- // text representation of the given value is produced by calling the
- // double.ToString(double) method.
- //
- public virtual void Write(double value)
- {
- Write(value.ToString(FormatProvider));
- }
-
- public virtual void Write(decimal value)
- {
- Write(value.ToString(FormatProvider));
- }
-
- // Writes a string to the text stream. If the given string is null, nothing
- // is written to the text stream.
- //
- public virtual void Write(string? value)
- {
- if (value != null)
- {
- Write(value.ToCharArray());
- }
- }
-
- // Writes the text representation of an object to the text stream. If the
- // given object is null, nothing is written to the text stream.
- // Otherwise, the object's ToString method is called to produce the
- // string representation, and the resulting string is then written to the
- // output stream.
- //
- public virtual void Write(object? value)
- {
- if (value != null)
- {
- if (value is IFormattable f)
- {
- Write(f.ToString(null, FormatProvider));
- }
- else
- Write(value.ToString());
- }
- }
-
- /// <summary>
- /// Equivalent to Write(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
- /// </summary>
- /// <param name="value">The string (as a StringBuilder) to write to the stream</param>
- public virtual void Write(StringBuilder? value)
- {
- if (value != null)
- {
- foreach (ReadOnlyMemory<char> chunk in value.GetChunks())
- Write(chunk.Span);
- }
- }
-
- // Writes out a formatted string. Uses the same semantics as
- // string.Format.
- //
- public virtual void Write(string format, object? arg0)
- {
- Write(string.Format(FormatProvider, format, arg0));
- }
-
- // Writes out a formatted string. Uses the same semantics as
- // string.Format.
- //
- public virtual void Write(string format, object? arg0, object? arg1)
- {
- Write(string.Format(FormatProvider, format, arg0, arg1));
- }
-
- // Writes out a formatted string. Uses the same semantics as
- // string.Format.
- //
- public virtual void Write(string format, object? arg0, object? arg1, object? arg2)
- {
- Write(string.Format(FormatProvider, format, arg0, arg1, arg2));
- }
-
- // Writes out a formatted string. Uses the same semantics as
- // string.Format.
- //
- public virtual void Write(string format, params object?[] arg)
- {
- Write(string.Format(FormatProvider, format, arg));
- }
-
- // Writes a line terminator to the text stream. The default line terminator
- // is Environment.NewLine, but this value can be changed by setting the NewLine property.
- //
- public virtual void WriteLine()
- {
- Write(CoreNewLine);
- }
-
- // Writes a character followed by a line terminator to the text stream.
- //
- public virtual void WriteLine(char value)
- {
- Write(value);
- WriteLine();
- }
-
- // Writes an array of characters followed by a line terminator to the text
- // stream.
- //
- public virtual void WriteLine(char[]? buffer)
- {
- Write(buffer);
- WriteLine();
- }
-
- // Writes a range of a character array followed by a line terminator to the
- // text stream.
- //
- public virtual void WriteLine(char[] buffer, int index, int count)
- {
- Write(buffer, index, count);
- WriteLine();
- }
-
- public virtual void WriteLine(ReadOnlySpan<char> buffer)
- {
- char[] array = ArrayPool<char>.Shared.Rent(buffer.Length);
-
- try
- {
- buffer.CopyTo(new Span<char>(array));
- WriteLine(array, 0, buffer.Length);
- }
- finally
- {
- ArrayPool<char>.Shared.Return(array);
- }
- }
-
- // Writes the text representation of a boolean followed by a line
- // terminator to the text stream.
- //
- public virtual void WriteLine(bool value)
- {
- Write(value);
- WriteLine();
- }
-
- // Writes the text representation of an integer followed by a line
- // terminator to the text stream.
- //
- public virtual void WriteLine(int value)
- {
- Write(value);
- WriteLine();
- }
-
- // Writes the text representation of an unsigned integer followed by
- // a line terminator to the text stream.
- //
- [CLSCompliant(false)]
- public virtual void WriteLine(uint value)
- {
- Write(value);
- WriteLine();
- }
-
- // Writes the text representation of a long followed by a line terminator
- // to the text stream.
- //
- public virtual void WriteLine(long value)
- {
- Write(value);
- WriteLine();
- }
-
- // Writes the text representation of an unsigned long followed by
- // a line terminator to the text stream.
- //
- [CLSCompliant(false)]
- public virtual void WriteLine(ulong value)
- {
- Write(value);
- WriteLine();
- }
-
- // Writes the text representation of a float followed by a line terminator
- // to the text stream.
- //
- public virtual void WriteLine(float value)
- {
- Write(value);
- WriteLine();
- }
-
- // Writes the text representation of a double followed by a line terminator
- // to the text stream.
- //
- public virtual void WriteLine(double value)
- {
- Write(value);
- WriteLine();
- }
-
- public virtual void WriteLine(decimal value)
- {
- Write(value);
- WriteLine();
- }
-
- // Writes a string followed by a line terminator to the text stream.
- //
- public virtual void WriteLine(string? value)
- {
- if (value != null)
- {
- Write(value);
- }
- Write(CoreNewLineStr);
- }
-
- /// <summary>
- /// Equivalent to WriteLine(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
- /// </summary>
- public virtual void WriteLine(StringBuilder? value)
- {
- Write(value);
- WriteLine();
- }
-
- // Writes the text representation of an object followed by a line
- // terminator to the text stream.
- //
- public virtual void WriteLine(object? value)
- {
- if (value == null)
- {
- WriteLine();
- }
- else
- {
- // Call WriteLine(value.ToString), not Write(Object), WriteLine().
- // This makes calls to WriteLine(Object) atomic.
- if (value is IFormattable f)
- {
- WriteLine(f.ToString(null, FormatProvider));
- }
- else
- {
- WriteLine(value.ToString());
- }
- }
- }
-
- // Writes out a formatted string and a new line. Uses the same
- // semantics as string.Format.
- //
- public virtual void WriteLine(string format, object? arg0)
- {
- WriteLine(string.Format(FormatProvider, format, arg0));
- }
-
- // Writes out a formatted string and a new line. Uses the same
- // semantics as string.Format.
- //
- public virtual void WriteLine(string format, object? arg0, object? arg1)
- {
- WriteLine(string.Format(FormatProvider, format, arg0, arg1));
- }
-
- // Writes out a formatted string and a new line. Uses the same
- // semantics as string.Format.
- //
- public virtual void WriteLine(string format, object? arg0, object? arg1, object? arg2)
- {
- WriteLine(string.Format(FormatProvider, format, arg0, arg1, arg2));
- }
-
- // Writes out a formatted string and a new line. Uses the same
- // semantics as string.Format.
- //
- public virtual void WriteLine(string format, params object?[] arg)
- {
- WriteLine(string.Format(FormatProvider, format, arg));
- }
-
- #region Task based Async APIs
- public virtual Task WriteAsync(char value)
- {
- var tuple = new Tuple<TextWriter, char>(this, value);
- return Task.Factory.StartNew(state =>
- {
- var t = (Tuple<TextWriter, char>)state!;
- t.Item1.Write(t.Item2);
- },
- tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
- }
-
- public virtual Task WriteAsync(string? value)
- {
- var tuple = new Tuple<TextWriter, string?>(this, value);
- return Task.Factory.StartNew(state =>
- {
- var t = (Tuple<TextWriter, string?>)state!;
- t.Item1.Write(t.Item2);
- },
- tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
- }
-
- /// <summary>
- /// Equivalent to WriteAsync(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
- /// </summary>
- /// <param name="value">The string (as a StringBuilder) to write to the stream</param>
- public virtual Task WriteAsync(StringBuilder? value, CancellationToken cancellationToken = default)
- {
- return
- cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
- value == null ? Task.CompletedTask :
- WriteAsyncCore(value, cancellationToken);
-
- async Task WriteAsyncCore(StringBuilder sb, CancellationToken ct)
- {
- foreach (ReadOnlyMemory<char> chunk in sb.GetChunks())
- {
- await WriteAsync(chunk, ct).ConfigureAwait(false);
- }
- }
- }
-
- public Task WriteAsync(char[]? buffer)
- {
- if (buffer == null)
- {
- return Task.CompletedTask;
- }
-
- return WriteAsync(buffer, 0, buffer.Length);
- }
-
- public virtual Task WriteAsync(char[] buffer, int index, int count)
- {
- var tuple = new Tuple<TextWriter, char[], int, int>(this, buffer, index, count);
- return Task.Factory.StartNew(state =>
- {
- var t = (Tuple<TextWriter, char[], int, int>)state!;
- t.Item1.Write(t.Item2, t.Item3, t.Item4);
- },
- tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
- }
-
- public virtual Task WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default) =>
- cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
- MemoryMarshal.TryGetArray(buffer, out ArraySegment<char> array) ?
- WriteAsync(array.Array!, array.Offset, array.Count) :
- Task.Factory.StartNew(state =>
- {
- var t = (Tuple<TextWriter, ReadOnlyMemory<char>>)state!;
- t.Item1.Write(t.Item2.Span);
- }, Tuple.Create(this, buffer), cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
-
- public virtual Task WriteLineAsync(char value)
- {
- var tuple = new Tuple<TextWriter, char>(this, value);
- return Task.Factory.StartNew(state =>
- {
- var t = (Tuple<TextWriter, char>)state!;
- t.Item1.WriteLine(t.Item2);
- },
- tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
- }
-
- public virtual Task WriteLineAsync(string? value)
- {
- var tuple = new Tuple<TextWriter, string?>(this, value);
- return Task.Factory.StartNew(state =>
- {
- var t = (Tuple<TextWriter, string?>)state!;
- t.Item1.WriteLine(t.Item2);
- },
- tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
- }
-
- /// <summary>
- /// Equivalent to WriteLineAsync(stringBuilder.ToString()) however it uses the
- /// StringBuilder.GetChunks() method to avoid creating the intermediate string
- /// </summary>
- /// <param name="value">The string (as a StringBuilder) to write to the stream</param>
- public virtual Task WriteLineAsync(StringBuilder? value, CancellationToken cancellationToken = default)
- {
- return
- cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
- value == null ? WriteAsync(CoreNewLine, cancellationToken) :
- WriteLineAsyncCore(value, cancellationToken);
-
- async Task WriteLineAsyncCore(StringBuilder sb, CancellationToken ct)
- {
- foreach (ReadOnlyMemory<char> chunk in sb.GetChunks())
- {
- await WriteAsync(chunk, ct).ConfigureAwait(false);
- }
- await WriteAsync(CoreNewLine, ct).ConfigureAwait(false);
- }
- }
-
- public Task WriteLineAsync(char[]? buffer)
- {
- if (buffer == null)
- {
- return WriteLineAsync();
- }
-
- return WriteLineAsync(buffer, 0, buffer.Length);
- }
-
- public virtual Task WriteLineAsync(char[] buffer, int index, int count)
- {
- var tuple = new Tuple<TextWriter, char[], int, int>(this, buffer, index, count);
- return Task.Factory.StartNew(state =>
- {
- var t = (Tuple<TextWriter, char[], int, int>)state!;
- t.Item1.WriteLine(t.Item2, t.Item3, t.Item4);
- },
- tuple, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
- }
-
- public virtual Task WriteLineAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default) =>
- cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
- MemoryMarshal.TryGetArray(buffer, out ArraySegment<char> array) ?
- WriteLineAsync(array.Array!, array.Offset, array.Count) :
- Task.Factory.StartNew(state =>
- {
- var t = (Tuple<TextWriter, ReadOnlyMemory<char>>)state!;
- t.Item1.WriteLine(t.Item2.Span);
- }, Tuple.Create(this, buffer), cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
-
- public virtual Task WriteLineAsync()
- {
- return WriteAsync(CoreNewLine);
- }
-
- public virtual Task FlushAsync()
- {
- return Task.Factory.StartNew(state => ((TextWriter)state!).Flush(), this,
- CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
- }
- #endregion
-
- private sealed class NullTextWriter : TextWriter
- {
- internal NullTextWriter() : base(CultureInfo.InvariantCulture)
- {
- }
-
- public override Encoding Encoding => Encoding.Unicode;
-
- public override void Write(char[] buffer, int index, int count)
- {
- }
-
- public override void Write(string? value)
- {
- }
-
- // Not strictly necessary, but for perf reasons
- public override void WriteLine()
- {
- }
-
- // Not strictly necessary, but for perf reasons
- public override void WriteLine(string? value)
- {
- }
-
- public override void WriteLine(object? value)
- {
- }
-
- public override void Write(char value)
- {
- }
- }
-
- public static TextWriter Synchronized(TextWriter writer)
- {
- if (writer == null)
- throw new ArgumentNullException(nameof(writer));
-
- return writer is SyncTextWriter ? writer : new SyncTextWriter(writer);
- }
-
- internal sealed class SyncTextWriter : TextWriter, IDisposable
- {
- private readonly TextWriter _out;
-
- internal SyncTextWriter(TextWriter t) : base(t.FormatProvider)
- {
- _out = t;
- }
-
- public override Encoding Encoding => _out.Encoding;
-
- public override IFormatProvider FormatProvider => _out.FormatProvider;
-
- [AllowNull]
- public override string NewLine
- {
- [MethodImpl(MethodImplOptions.Synchronized)]
- get => _out.NewLine;
- [MethodImpl(MethodImplOptions.Synchronized)]
- set => _out.NewLine = value;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Close() => _out.Close();
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- protected override void Dispose(bool disposing)
- {
- // Explicitly pick up a potentially methodimpl'ed Dispose
- if (disposing)
- ((IDisposable)_out).Dispose();
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Flush() => _out.Flush();
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(char value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(char[]? buffer) => _out.Write(buffer);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(char[] buffer, int index, int count) => _out.Write(buffer, index, count);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(ReadOnlySpan<char> buffer) => _out.Write(buffer);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(bool value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(int value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(uint value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(long value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(ulong value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(float value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(double value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(decimal value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(string? value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(StringBuilder? value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(object? value) => _out.Write(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(string format, object? arg0) => _out.Write(format, arg0);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(string format, object? arg0, object? arg1) => _out.Write(format, arg0, arg1);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(string format, object? arg0, object? arg1, object? arg2) => _out.Write(format, arg0, arg1, arg2);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void Write(string format, object?[] arg) => _out.Write(format, arg);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine() => _out.WriteLine();
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(char value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(decimal value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(char[]? buffer) => _out.WriteLine(buffer);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(char[] buffer, int index, int count) => _out.WriteLine(buffer, index, count);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(ReadOnlySpan<char> buffer) => _out.WriteLine(buffer);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(bool value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(int value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(uint value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(long value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(ulong value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(float value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(double value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(string? value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(StringBuilder? value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(object? value) => _out.WriteLine(value);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(string format, object? arg0) => _out.WriteLine(format, arg0);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(string format, object? arg0, object? arg1) => _out.WriteLine(format, arg0, arg1);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(string format, object? arg0, object? arg1, object? arg2) => _out.WriteLine(format, arg0, arg1, arg2);
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override void WriteLine(string format, object?[] arg) => _out.WriteLine(format, arg);
-
- //
- // On SyncTextWriter all APIs should run synchronously, even the async ones.
- //
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override ValueTask DisposeAsync()
- {
- Dispose();
- return default;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteAsync(char value)
- {
- Write(value);
- return Task.CompletedTask;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteAsync(string? value)
- {
- Write(value);
- return Task.CompletedTask;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteAsync(StringBuilder? value, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
-
- Write(value);
- return Task.CompletedTask;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteAsync(char[] buffer, int index, int count)
- {
- Write(buffer, index, count);
- return Task.CompletedTask;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
-
- Write(buffer.Span);
- return Task.CompletedTask;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
-
- WriteLine(buffer.Span);
- return Task.CompletedTask;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync(char value)
- {
- WriteLine(value);
- return Task.CompletedTask;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync()
- {
- WriteLine();
- return Task.CompletedTask;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync(string? value)
- {
- WriteLine(value);
- return Task.CompletedTask;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync(StringBuilder? value, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return Task.FromCanceled(cancellationToken);
- }
-
- WriteLine(value);
- return Task.CompletedTask;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task WriteLineAsync(char[] buffer, int index, int count)
- {
- WriteLine(buffer, index, count);
- return Task.CompletedTask;
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- public override Task FlushAsync()
- {
- Flush();
- return Task.CompletedTask;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryAccessor.cs b/netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryAccessor.cs
deleted file mode 100644
index a2c6bd1764f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryAccessor.cs
+++ /dev/null
@@ -1,668 +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.
-
-/*============================================================
-**
-**
-**
-**
-** Purpose: Provides a fast, AV free, cross-language way of
-** accessing unmanaged memory in a random fashion.
-**
-**
-===========================================================*/
-
-using System.Runtime.InteropServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System.IO
-{
- /// Perf notes: ReadXXX, WriteXXX (for basic types) acquire and release the
- /// SafeBuffer pointer rather than relying on generic Read(T) from SafeBuffer because
- /// this gives better throughput; benchmarks showed about 12-15% better.
- public class UnmanagedMemoryAccessor : IDisposable
- {
- private SafeBuffer _buffer = null!; // initialized in helper called by ctor
- private long _offset;
- private long _capacity;
- private FileAccess _access;
- private bool _isOpen;
- private bool _canRead;
- private bool _canWrite;
-
- protected UnmanagedMemoryAccessor()
- {
- _isOpen = false;
- }
-
- public UnmanagedMemoryAccessor(SafeBuffer buffer, long offset, long capacity)
- {
- Initialize(buffer, offset, capacity, FileAccess.Read);
- }
-
- public UnmanagedMemoryAccessor(SafeBuffer buffer, long offset, long capacity, FileAccess access)
- {
- Initialize(buffer, offset, capacity, access);
- }
-
- protected void Initialize(SafeBuffer buffer, long offset, long capacity, FileAccess access)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer));
- }
- if (offset < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (capacity < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.ByteLength < (ulong)(offset + capacity))
- {
- throw new ArgumentException(SR.Argument_OffsetAndCapacityOutOfBounds);
- }
- if (access < FileAccess.Read || access > FileAccess.ReadWrite)
- {
- throw new ArgumentOutOfRangeException(nameof(access));
- }
-
- if (_isOpen)
- {
- throw new InvalidOperationException(SR.InvalidOperation_CalledTwice);
- }
-
- unsafe
- {
- byte* pointer = null;
-
- try
- {
- buffer.AcquirePointer(ref pointer);
- if (((byte*)((long)pointer + offset + capacity)) < pointer)
- {
- throw new ArgumentException(SR.Argument_UnmanagedMemAccessorWrapAround);
- }
- }
- finally
- {
- if (pointer != null)
- {
- buffer.ReleasePointer();
- }
- }
- }
-
- _offset = offset;
- _buffer = buffer;
- _capacity = capacity;
- _access = access;
- _isOpen = true;
- _canRead = (_access & FileAccess.Read) != 0;
- _canWrite = (_access & FileAccess.Write) != 0;
- }
-
- public long Capacity => _capacity;
-
- public bool CanRead => _isOpen && _canRead;
-
- public bool CanWrite => _isOpen && _canWrite;
-
- protected virtual void Dispose(bool disposing)
- {
- _isOpen = false;
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected bool IsOpen => _isOpen;
-
- // ************** Read Methods ****************/
-
- public bool ReadBoolean(long position) => ReadByte(position) != 0;
-
- public byte ReadByte(long position)
- {
- EnsureSafeToRead(position, sizeof(byte));
-
- byte result;
- unsafe
- {
- byte* pointer = null;
-
- try
- {
- _buffer.AcquirePointer(ref pointer);
- result = *((byte*)(pointer + _offset + position));
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- return result;
- }
-
- public char ReadChar(long position) => unchecked((char)ReadInt16(position));
-
- public short ReadInt16(long position)
- {
- EnsureSafeToRead(position, sizeof(short));
-
- short result;
- unsafe
- {
- byte* pointer = null;
-
- try
- {
- _buffer.AcquirePointer(ref pointer);
- result = Unsafe.ReadUnaligned<short>(pointer + _offset + position);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- return result;
- }
-
- public int ReadInt32(long position)
- {
- EnsureSafeToRead(position, sizeof(int));
-
- int result;
- unsafe
- {
- byte* pointer = null;
-
- try
- {
- _buffer.AcquirePointer(ref pointer);
- result = Unsafe.ReadUnaligned<int>(pointer + _offset + position);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- return result;
- }
-
- public long ReadInt64(long position)
- {
- EnsureSafeToRead(position, sizeof(long));
-
- long result;
- unsafe
- {
- byte* pointer = null;
-
- try
- {
- _buffer.AcquirePointer(ref pointer);
- result = Unsafe.ReadUnaligned<long>(pointer + _offset + position);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- return result;
- }
-
- public decimal ReadDecimal(long position)
- {
- const int ScaleMask = 0x00FF0000;
- const int SignMask = unchecked((int)0x80000000);
-
- EnsureSafeToRead(position, sizeof(decimal));
-
- int lo, mid, hi, flags;
-
- unsafe
- {
- byte* pointer = null;
- try
- {
- _buffer.AcquirePointer(ref pointer);
- pointer += (_offset + position);
-
- lo = Unsafe.ReadUnaligned<int>(pointer);
- mid = Unsafe.ReadUnaligned<int>(pointer + 4);
- hi = Unsafe.ReadUnaligned<int>(pointer + 8);
- flags = Unsafe.ReadUnaligned<int>(pointer + 12);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
-
- // Check for invalid Decimal values
- if (!((flags & ~(SignMask | ScaleMask)) == 0 && (flags & ScaleMask) <= (28 << 16)))
- {
- throw new ArgumentException(SR.Arg_BadDecimal); // Throw same Exception type as Decimal(int[]) ctor for compat
- }
-
- bool isNegative = (flags & SignMask) != 0;
- byte scale = (byte)(flags >> 16);
-
- return new decimal(lo, mid, hi, isNegative, scale);
- }
-
- public float ReadSingle(long position) => BitConverter.Int32BitsToSingle(ReadInt32(position));
-
- public double ReadDouble(long position) => BitConverter.Int64BitsToDouble(ReadInt64(position));
-
- [CLSCompliant(false)]
- public sbyte ReadSByte(long position) => unchecked((sbyte)ReadByte(position));
-
- [CLSCompliant(false)]
- public ushort ReadUInt16(long position) => unchecked((ushort)ReadInt16(position));
-
- [CLSCompliant(false)]
- public uint ReadUInt32(long position) => unchecked((uint)ReadInt32(position));
-
- [CLSCompliant(false)]
- public ulong ReadUInt64(long position) => unchecked((ulong)ReadInt64(position));
-
- // Reads a struct of type T from unmanaged memory, into the reference pointed to by ref value.
- // Note: this method is not safe, since it overwrites the contents of a structure, it can be
- // used to modify the private members of a struct.
- // This method is most performant when used with medium to large sized structs
- // (larger than 8 bytes -- though this is number is JIT and architecture dependent). As
- // such, it is best to use the ReadXXX methods for small standard types such as ints, longs,
- // bools, etc.
- public void Read<T>(long position, out T structure) where T : struct
- {
- if (position < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (!_isOpen)
- {
- throw new ObjectDisposedException(nameof(UnmanagedMemoryAccessor), SR.ObjectDisposed_ViewAccessorClosed);
- }
- if (!_canRead)
- {
- throw new NotSupportedException(SR.NotSupported_Reading);
- }
-
- uint sizeOfT = SafeBuffer.SizeOf<T>();
- if (position > _capacity - sizeOfT)
- {
- if (position >= _capacity)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired);
- }
- else
- {
- throw new ArgumentException(SR.Format(SR.Argument_NotEnoughBytesToRead, typeof(T)), nameof(position));
- }
- }
-
- structure = _buffer.Read<T>((ulong)(_offset + position));
- }
-
- // Reads 'count' structs of type T from unmanaged memory, into 'array' starting at 'offset'.
- // Note: this method is not safe, since it overwrites the contents of structures, it can
- // be used to modify the private members of a struct.
- public int ReadArray<T>(long position, T[] array, int offset, int count) where T : struct
- {
- if (array == null)
- {
- throw new ArgumentNullException(nameof(array), SR.ArgumentNull_Buffer);
- }
- if (offset < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (array.Length - offset < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
- if (!_isOpen)
- {
- throw new ObjectDisposedException(nameof(UnmanagedMemoryAccessor), SR.ObjectDisposed_ViewAccessorClosed);
- }
- if (!_canRead)
- {
- throw new NotSupportedException(SR.NotSupported_Reading);
- }
- if (position < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- uint sizeOfT = SafeBuffer.AlignedSizeOf<T>();
-
- // only check position and ask for fewer Ts if count is too big
- if (position >= _capacity)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired);
- }
-
- int n = count;
- long spaceLeft = _capacity - position;
- if (spaceLeft < 0)
- {
- n = 0;
- }
- else
- {
- ulong spaceNeeded = (ulong)(sizeOfT * count);
- if ((ulong)spaceLeft < spaceNeeded)
- {
- n = (int)(spaceLeft / sizeOfT);
- }
- }
-
- _buffer.ReadArray<T>((ulong)(_offset + position), array, offset, n);
-
- return n;
- }
-
- // ************** Write Methods ****************/
-
- public void Write(long position, bool value) => Write(position, (byte)(value ? 1 : 0));
-
- public void Write(long position, byte value)
- {
- EnsureSafeToWrite(position, sizeof(byte));
-
- unsafe
- {
- byte* pointer = null;
-
- try
- {
- _buffer.AcquirePointer(ref pointer);
- *((byte*)(pointer + _offset + position)) = value;
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- }
-
- public void Write(long position, char value) => Write(position, unchecked((short)value));
-
- public void Write(long position, short value)
- {
- EnsureSafeToWrite(position, sizeof(short));
-
- unsafe
- {
- byte* pointer = null;
-
- try
- {
- _buffer.AcquirePointer(ref pointer);
- Unsafe.WriteUnaligned<short>(pointer + _offset + position, value);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- }
-
- public void Write(long position, int value)
- {
- EnsureSafeToWrite(position, sizeof(int));
-
- unsafe
- {
- byte* pointer = null;
-
- try
- {
- _buffer.AcquirePointer(ref pointer);
- Unsafe.WriteUnaligned<int>(pointer + _offset + position, value);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- }
-
- public void Write(long position, long value)
- {
- EnsureSafeToWrite(position, sizeof(long));
-
- unsafe
- {
- byte* pointer = null;
-
- try
- {
- _buffer.AcquirePointer(ref pointer);
- Unsafe.WriteUnaligned<long>(pointer + _offset + position, value);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- }
-
- public void Write(long position, decimal value)
- {
- EnsureSafeToWrite(position, sizeof(decimal));
-
- unsafe
- {
- int* valuePtr = (int*)(&value);
- int flags = *valuePtr;
- int hi = *(valuePtr + 1);
- int lo = *(valuePtr + 2);
- int mid = *(valuePtr + 3);
-
- byte* pointer = null;
- try
- {
- _buffer.AcquirePointer(ref pointer);
- pointer += (_offset + position);
-
- Unsafe.WriteUnaligned<int>(pointer, lo);
- Unsafe.WriteUnaligned<int>(pointer + 4, mid);
- Unsafe.WriteUnaligned<int>(pointer + 8, hi);
- Unsafe.WriteUnaligned<int>(pointer + 12, flags);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- }
-
- public void Write(long position, float value) => Write(position, BitConverter.SingleToInt32Bits(value));
-
- public void Write(long position, double value) => Write(position, BitConverter.DoubleToInt64Bits(value));
-
- [CLSCompliant(false)]
- public void Write(long position, sbyte value) => Write(position, unchecked((byte)value));
-
- [CLSCompliant(false)]
- public void Write(long position, ushort value) => Write(position, unchecked((short)value));
-
- [CLSCompliant(false)]
- public void Write(long position, uint value) => Write(position, unchecked((int)value));
-
- [CLSCompliant(false)]
- public void Write(long position, ulong value) => Write(position, unchecked((long)value));
-
- // Writes the struct pointed to by ref value into unmanaged memory. Note that this method
- // is most performant when used with medium to large sized structs (larger than 8 bytes
- // though this is number is JIT and architecture dependent). As such, it is best to use
- // the WriteX methods for small standard types such as ints, longs, bools, etc.
- public void Write<T>(long position, ref T structure) where T : struct
- {
- if (position < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (!_isOpen)
- {
- throw new ObjectDisposedException(nameof(UnmanagedMemoryAccessor), SR.ObjectDisposed_ViewAccessorClosed);
- }
- if (!_canWrite)
- {
- throw new NotSupportedException(SR.NotSupported_Writing);
- }
-
- uint sizeOfT = SafeBuffer.SizeOf<T>();
- if (position > _capacity - sizeOfT)
- {
- if (position >= _capacity)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired);
- }
- else
- {
- throw new ArgumentException(SR.Format(SR.Argument_NotEnoughBytesToWrite, typeof(T)), nameof(position));
- }
- }
-
- _buffer.Write<T>((ulong)(_offset + position), structure);
- }
-
- // Writes 'count' structs of type T from 'array' (starting at 'offset') into unmanaged memory.
- public void WriteArray<T>(long position, T[] array, int offset, int count) where T : struct
- {
- if (array == null)
- {
- throw new ArgumentNullException(nameof(array), SR.ArgumentNull_Buffer);
- }
- if (offset < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (array.Length - offset < count)
- {
- throw new ArgumentException(SR.Argument_InvalidOffLen);
- }
- if (position < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (position >= Capacity)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired);
- }
-
- if (!_isOpen)
- {
- throw new ObjectDisposedException(nameof(UnmanagedMemoryAccessor), SR.ObjectDisposed_ViewAccessorClosed);
- }
- if (!_canWrite)
- {
- throw new NotSupportedException(SR.NotSupported_Writing);
- }
-
- _buffer.WriteArray<T>((ulong)(_offset + position), array, offset, count);
- }
-
- private void EnsureSafeToRead(long position, int sizeOfType)
- {
- if (!_isOpen)
- {
- throw new ObjectDisposedException(nameof(UnmanagedMemoryAccessor), SR.ObjectDisposed_ViewAccessorClosed);
- }
- if (!_canRead)
- {
- throw new NotSupportedException(SR.NotSupported_Reading);
- }
- if (position < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (position > _capacity - sizeOfType)
- {
- if (position >= _capacity)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired);
- }
- else
- {
- throw new ArgumentException(SR.Argument_NotEnoughBytesToRead, nameof(position));
- }
- }
- }
-
- private void EnsureSafeToWrite(long position, int sizeOfType)
- {
- if (!_isOpen)
- {
- throw new ObjectDisposedException(nameof(UnmanagedMemoryAccessor), SR.ObjectDisposed_ViewAccessorClosed);
- }
- if (!_canWrite)
- {
- throw new NotSupportedException(SR.NotSupported_Writing);
- }
- if (position < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (position > _capacity - sizeOfType)
- {
- if (position >= _capacity)
- {
- throw new ArgumentOutOfRangeException(nameof(position), SR.ArgumentOutOfRange_PositionLessThanCapacityRequired);
- }
- else
- {
- throw new ArgumentException(SR.Argument_NotEnoughBytesToWrite, nameof(position));
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs b/netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs
deleted file mode 100644
index 4dbd34a95a7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs
+++ /dev/null
@@ -1,951 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Threading.Tasks;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System.IO
-{
- /*
- * This class is used to access a contiguous block of memory, likely outside
- * the GC heap (or pinned in place in the GC heap, but a MemoryStream may
- * make more sense in those cases). It's great if you have a pointer and
- * a length for a section of memory mapped in by someone else and you don't
- * want to copy this into the GC heap. UnmanagedMemoryStream assumes these
- * two things:
- *
- * 1) All the memory in the specified block is readable or writable,
- * depending on the values you pass to the constructor.
- * 2) The lifetime of the block of memory is at least as long as the lifetime
- * of the UnmanagedMemoryStream.
- * 3) You clean up the memory when appropriate. The UnmanagedMemoryStream
- * currently will do NOTHING to free this memory.
- * 4) All calls to Write and WriteByte may not be threadsafe currently.
- *
- * It may become necessary to add in some sort of
- * DeallocationMode enum, specifying whether we unmap a section of memory,
- * call free, run a user-provided delegate to free the memory, etc.
- * We'll suggest user write a subclass of UnmanagedMemoryStream that uses
- * a SafeHandle subclass to hold onto the memory.
- *
- */
-
- /// <summary>
- /// Stream over a memory pointer or over a SafeBuffer
- /// </summary>
- public class UnmanagedMemoryStream : Stream
- {
- private SafeBuffer? _buffer;
- private unsafe byte* _mem;
- private long _length;
- private long _capacity;
- private long _position;
- private long _offset;
- private FileAccess _access;
- private bool _isOpen;
- private Task<int>? _lastReadTask; // The last successful task returned from ReadAsync
-
- /// <summary>
- /// Creates a closed stream.
- /// </summary>
- // Needed for subclasses that need to map a file, etc.
- protected UnmanagedMemoryStream()
- {
- unsafe
- {
- _mem = null;
- }
- _isOpen = false;
- }
-
- /// <summary>
- /// Creates a stream over a SafeBuffer.
- /// </summary>
- /// <param name="buffer"></param>
- /// <param name="offset"></param>
- /// <param name="length"></param>
- public UnmanagedMemoryStream(SafeBuffer buffer, long offset, long length)
- {
- Initialize(buffer, offset, length, FileAccess.Read);
- }
-
- /// <summary>
- /// Creates a stream over a SafeBuffer.
- /// </summary>
- public UnmanagedMemoryStream(SafeBuffer buffer, long offset, long length, FileAccess access)
- {
- Initialize(buffer, offset, length, access);
- }
-
- /// <summary>
- /// Subclasses must call this method (or the other overload) to properly initialize all instance fields.
- /// </summary>
- /// <param name="buffer"></param>
- /// <param name="offset"></param>
- /// <param name="length"></param>
- /// <param name="access"></param>
- protected void Initialize(SafeBuffer buffer, long offset, long length, FileAccess access)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer));
- }
- if (offset < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (length < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (buffer.ByteLength < (ulong)(offset + length))
- {
- throw new ArgumentException(SR.Argument_InvalidSafeBufferOffLen);
- }
- if (access < FileAccess.Read || access > FileAccess.ReadWrite)
- {
- throw new ArgumentOutOfRangeException(nameof(access));
- }
-
- if (_isOpen)
- {
- throw new InvalidOperationException(SR.InvalidOperation_CalledTwice);
- }
-
- // check for wraparound
- unsafe
- {
- byte* pointer = null;
- RuntimeHelpers.PrepareConstrainedRegions();
- try
- {
- buffer.AcquirePointer(ref pointer);
- if ((pointer + offset + length) < pointer)
- {
- throw new ArgumentException(SR.ArgumentOutOfRange_UnmanagedMemStreamWrapAround);
- }
- }
- finally
- {
- if (pointer != null)
- {
- buffer.ReleasePointer();
- }
- }
- }
-
- _offset = offset;
- _buffer = buffer;
- _length = length;
- _capacity = length;
- _access = access;
- _isOpen = true;
- }
-
- /// <summary>
- /// Creates a stream over a byte*.
- /// </summary>
- [CLSCompliant(false)]
- public unsafe UnmanagedMemoryStream(byte* pointer, long length)
- {
- Initialize(pointer, length, length, FileAccess.Read);
- }
-
- /// <summary>
- /// Creates a stream over a byte*.
- /// </summary>
- [CLSCompliant(false)]
- public unsafe UnmanagedMemoryStream(byte* pointer, long length, long capacity, FileAccess access)
- {
- Initialize(pointer, length, capacity, access);
- }
-
- /// <summary>
- /// Subclasses must call this method (or the other overload) to properly initialize all instance fields.
- /// </summary>
- [CLSCompliant(false)]
- protected unsafe void Initialize(byte* pointer, long length, long capacity, FileAccess access)
- {
- if (pointer == null)
- throw new ArgumentNullException(nameof(pointer));
- if (length < 0 || capacity < 0)
- throw new ArgumentOutOfRangeException((length < 0) ? nameof(length) : nameof(capacity), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (length > capacity)
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_LengthGreaterThanCapacity);
- // Check for wraparound.
- if (((byte*)((long)pointer + capacity)) < pointer)
- throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_UnmanagedMemStreamWrapAround);
- if (access < FileAccess.Read || access > FileAccess.ReadWrite)
- throw new ArgumentOutOfRangeException(nameof(access), SR.ArgumentOutOfRange_Enum);
- if (_isOpen)
- throw new InvalidOperationException(SR.InvalidOperation_CalledTwice);
-
- _mem = pointer;
- _offset = 0;
- _length = length;
- _capacity = capacity;
- _access = access;
- _isOpen = true;
- }
-
- /// <summary>
- /// Returns true if the stream can be read; otherwise returns false.
- /// </summary>
- public override bool CanRead => _isOpen && (_access & FileAccess.Read) != 0;
-
- /// <summary>
- /// Returns true if the stream can seek; otherwise returns false.
- /// </summary>
- public override bool CanSeek => _isOpen;
-
- /// <summary>
- /// Returns true if the stream can be written to; otherwise returns false.
- /// </summary>
- public override bool CanWrite => _isOpen && (_access & FileAccess.Write) != 0;
-
- /// <summary>
- /// Calls the given callback with a span of the memory stream data
- /// </summary>
- /// <param name="callback">the callback to be called</param>
- /// <param name="state">A user-defined state, passed to the callback</param>
- /// <param name="bufferSize">the maximum size of the memory span</param>
- public override void CopyTo(ReadOnlySpanAction<byte, object?> callback, object? state, int bufferSize)
- {
- // If we have been inherited into a subclass, the following implementation could be incorrect
- // since it does not call through to Read() which a subclass might have overridden.
- // To be safe we will only use this implementation in cases where we know it is safe to do so,
- // and delegate to our base class (which will call into Read) when we are not sure.
- if (GetType() != typeof(UnmanagedMemoryStream))
- {
- base.CopyTo(callback, state, bufferSize);
- return;
- }
-
- if (callback == null) throw new ArgumentNullException(nameof(callback));
-
- EnsureNotClosed();
- EnsureReadable();
-
- // Use a local variable to avoid a race where another thread
- // changes our position after we decide we can read some bytes.
- long pos = Interlocked.Read(ref _position);
- long len = Interlocked.Read(ref _length);
- long n = len - pos;
- if (n <= 0)
- {
- return;
- }
-
- int nInt = (int)n; // Safe because n <= count, which is an Int32
- if (nInt < 0)
- {
- return; // _position could be beyond EOF
- }
-
- unsafe
- {
- if (_buffer != null)
- {
- byte* pointer = null;
-
- RuntimeHelpers.PrepareConstrainedRegions();
- try
- {
- _buffer.AcquirePointer(ref pointer);
- ReadOnlySpan<byte> span = new ReadOnlySpan<byte>(pointer + pos + _offset, nInt);
- Interlocked.Exchange(ref _position, pos + n);
- callback(span, state);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- else
- {
- ReadOnlySpan<byte> span = new ReadOnlySpan<byte>(_mem + pos, nInt);
- Interlocked.Exchange(ref _position, pos + n);
- callback(span, state);
- }
- }
- }
-
- /// <summary>
- /// Closes the stream. The stream's memory needs to be dealt with separately.
- /// </summary>
- /// <param name="disposing"></param>
- protected override void Dispose(bool disposing)
- {
- _isOpen = false;
- unsafe { _mem = null; }
-
- // Stream allocates WaitHandles for async calls. So for correctness
- // call base.Dispose(disposing) for better perf, avoiding waiting
- // for the finalizers to run on those types.
- base.Dispose(disposing);
- }
-
- private void EnsureNotClosed()
- {
- if (!_isOpen)
- throw Error.GetStreamIsClosed();
- }
-
- private void EnsureReadable()
- {
- if (!CanRead)
- throw Error.GetReadNotSupported();
- }
-
- private void EnsureWriteable()
- {
- if (!CanWrite)
- throw Error.GetWriteNotSupported();
- }
-
- /// <summary>
- /// Since it's a memory stream, this method does nothing.
- /// </summary>
- public override void Flush()
- {
- EnsureNotClosed();
- }
-
- /// <summary>
- /// Since it's a memory stream, this method does nothing specific.
- /// </summary>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- public override Task FlushAsync(CancellationToken cancellationToken)
- {
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled(cancellationToken);
-
- try
- {
- Flush();
- return Task.CompletedTask;
- }
- catch (Exception ex)
- {
- return Task.FromException(ex);
- }
- }
-
- /// <summary>
- /// Number of bytes in the stream.
- /// </summary>
- public override long Length
- {
- get
- {
- EnsureNotClosed();
- return Interlocked.Read(ref _length);
- }
- }
-
- /// <summary>
- /// Number of bytes that can be written to the stream.
- /// </summary>
- public long Capacity
- {
- get
- {
- EnsureNotClosed();
- return _capacity;
- }
- }
-
- /// <summary>
- /// ReadByte will read byte at the Position in the stream
- /// </summary>
- public override long Position
- {
- get
- {
- if (!CanSeek) throw Error.GetStreamIsClosed();
- return Interlocked.Read(ref _position);
- }
- set
- {
- if (value < 0) throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (!CanSeek) throw Error.GetStreamIsClosed();
-
- Interlocked.Exchange(ref _position, value);
- }
- }
-
- /// <summary>
- /// Pointer to memory at the current Position in the stream.
- /// </summary>
- [CLSCompliant(false)]
- public unsafe byte* PositionPointer
- {
- get
- {
- if (_buffer != null)
- throw new NotSupportedException(SR.NotSupported_UmsSafeBuffer);
-
- EnsureNotClosed();
-
- // Use a temp to avoid a race
- long pos = Interlocked.Read(ref _position);
- if (pos > _capacity)
- throw new IndexOutOfRangeException(SR.IndexOutOfRange_UMSPosition);
- byte* ptr = _mem + pos;
- return ptr;
- }
- set
- {
- if (_buffer != null)
- throw new NotSupportedException(SR.NotSupported_UmsSafeBuffer);
-
- EnsureNotClosed();
-
- if (value < _mem)
- throw new IOException(SR.IO_SeekBeforeBegin);
- long newPosition = (long)value - (long)_mem;
- if (newPosition < 0)
- throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_UnmanagedMemStreamLength);
-
- Interlocked.Exchange(ref _position, newPosition);
- }
- }
-
- /// <summary>
- /// Reads bytes from stream and puts them into the buffer
- /// </summary>
- /// <param name="buffer">Buffer to read the bytes to.</param>
- /// <param name="offset">Starting index in the buffer.</param>
- /// <param name="count">Maximum number of bytes to read.</param>
- /// <returns>Number of bytes actually read.</returns>
- public override int Read(byte[] buffer, int offset, int count)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - offset < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- return ReadCore(new Span<byte>(buffer, offset, count));
- }
-
- public override int Read(Span<byte> buffer)
- {
- if (GetType() == typeof(UnmanagedMemoryStream))
- {
- return ReadCore(buffer);
- }
- else
- {
- // UnmanagedMemoryStream is not sealed, and a derived type may have overridden Read(byte[], int, int) prior
- // to this Read(Span<byte>) overload being introduced. In that case, this Read(Span<byte>) overload
- // should use the behavior of Read(byte[],int,int) overload.
- return base.Read(buffer);
- }
- }
-
- internal int ReadCore(Span<byte> buffer)
- {
- EnsureNotClosed();
- EnsureReadable();
-
- // Use a local variable to avoid a race where another thread
- // changes our position after we decide we can read some bytes.
- long pos = Interlocked.Read(ref _position);
- long len = Interlocked.Read(ref _length);
- long n = Math.Min(len - pos, buffer.Length);
- if (n <= 0)
- {
- return 0;
- }
-
- int nInt = (int)n; // Safe because n <= count, which is an Int32
- if (nInt < 0)
- {
- return 0; // _position could be beyond EOF
- }
- Debug.Assert(pos + nInt >= 0, "_position + n >= 0"); // len is less than 2^63 -1.
-
- unsafe
- {
- fixed (byte* pBuffer = &MemoryMarshal.GetReference(buffer))
- {
- if (_buffer != null)
- {
- byte* pointer = null;
-
- RuntimeHelpers.PrepareConstrainedRegions();
- try
- {
- _buffer.AcquirePointer(ref pointer);
- Buffer.Memcpy(pBuffer, pointer + pos + _offset, nInt);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- else
- {
- Buffer.Memcpy(pBuffer, _mem + pos, nInt);
- }
- }
- }
- Interlocked.Exchange(ref _position, pos + n);
- return nInt;
- }
-
- /// <summary>
- /// Reads bytes from stream and puts them into the buffer
- /// </summary>
- /// <param name="buffer">Buffer to read the bytes to.</param>
- /// <param name="offset">Starting index in the buffer.</param>
- /// <param name="count">Maximum number of bytes to read.</param>
- /// <param name="cancellationToken">Token that can be used to cancel this operation.</param>
- /// <returns>Task that can be used to access the number of bytes actually read.</returns>
- public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - offset < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled<int>(cancellationToken);
-
- try
- {
- int n = Read(buffer, offset, count);
- Task<int>? t = _lastReadTask;
- return (t != null && t.Result == n) ? t : (_lastReadTask = Task.FromResult<int>(n));
- }
- catch (Exception ex)
- {
- Debug.Assert(!(ex is OperationCanceledException));
- return Task.FromException<int>(ex);
- }
- }
-
- /// <summary>
- /// Reads bytes from stream and puts them into the buffer
- /// </summary>
- /// <param name="buffer">Buffer to read the bytes to.</param>
- /// <param name="cancellationToken">Token that can be used to cancel this operation.</param>
- public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return new ValueTask<int>(Task.FromCanceled<int>(cancellationToken));
- }
-
- try
- {
- // ReadAsync(Memory<byte>,...) needs to delegate to an existing virtual to do the work, in case an existing derived type
- // has changed or augmented the logic associated with reads. If the Memory wraps an array, we could delegate to
- // ReadAsync(byte[], ...), but that would defeat part of the purpose, as ReadAsync(byte[], ...) often needs to allocate
- // a Task<int> for the return value, so we want to delegate to one of the synchronous methods. We could always
- // delegate to the Read(Span<byte>) method, and that's the most efficient solution when dealing with a concrete
- // UnmanagedMemoryStream, but if we're dealing with a type derived from UnmanagedMemoryStream, Read(Span<byte>) will end up delegating
- // to Read(byte[], ...), which requires it to get a byte[] from ArrayPool and copy the data. So, we special-case the
- // very common case of the Memory<byte> wrapping an array: if it does, we delegate to Read(byte[], ...) with it,
- // as that will be efficient in both cases, and we fall back to Read(Span<byte>) if the Memory<byte> wrapped something
- // else; if this is a concrete UnmanagedMemoryStream, that'll be efficient, and only in the case where the Memory<byte> wrapped
- // something other than an array and this is an UnmanagedMemoryStream-derived type that doesn't override Read(Span<byte>) will
- // it then fall back to doing the ArrayPool/copy behavior.
- return new ValueTask<int>(
- MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> destinationArray) ?
- Read(destinationArray.Array!, destinationArray.Offset, destinationArray.Count) :
- Read(buffer.Span));
- }
- catch (Exception ex)
- {
- return new ValueTask<int>(Task.FromException<int>(ex));
- }
- }
-
- /// <summary>
- /// Returns the byte at the stream current Position and advances the Position.
- /// </summary>
- /// <returns></returns>
- public override int ReadByte()
- {
- EnsureNotClosed();
- EnsureReadable();
-
- long pos = Interlocked.Read(ref _position); // Use a local to avoid a race condition
- long len = Interlocked.Read(ref _length);
- if (pos >= len)
- return -1;
- Interlocked.Exchange(ref _position, pos + 1);
- int result;
- if (_buffer != null)
- {
- unsafe
- {
- byte* pointer = null;
- RuntimeHelpers.PrepareConstrainedRegions();
- try
- {
- _buffer.AcquirePointer(ref pointer);
- result = *(pointer + pos + _offset);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- }
- else
- {
- unsafe
- {
- result = _mem[pos];
- }
- }
- return result;
- }
-
- /// <summary>
- /// Advanced the Position to specific location in the stream.
- /// </summary>
- /// <param name="offset">Offset from the loc parameter.</param>
- /// <param name="loc">Origin for the offset parameter.</param>
- /// <returns></returns>
- public override long Seek(long offset, SeekOrigin loc)
- {
- EnsureNotClosed();
-
- switch (loc)
- {
- case SeekOrigin.Begin:
- if (offset < 0)
- throw new IOException(SR.IO_SeekBeforeBegin);
- Interlocked.Exchange(ref _position, offset);
- break;
-
- case SeekOrigin.Current:
- long pos = Interlocked.Read(ref _position);
- if (offset + pos < 0)
- throw new IOException(SR.IO_SeekBeforeBegin);
- Interlocked.Exchange(ref _position, offset + pos);
- break;
-
- case SeekOrigin.End:
- long len = Interlocked.Read(ref _length);
- if (len + offset < 0)
- throw new IOException(SR.IO_SeekBeforeBegin);
- Interlocked.Exchange(ref _position, len + offset);
- break;
-
- default:
- throw new ArgumentException(SR.Argument_InvalidSeekOrigin);
- }
-
- long finalPos = Interlocked.Read(ref _position);
- Debug.Assert(finalPos >= 0, "_position >= 0");
- return finalPos;
- }
-
- /// <summary>
- /// Sets the Length of the stream.
- /// </summary>
- /// <param name="value"></param>
- public override void SetLength(long value)
- {
- if (value < 0)
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_buffer != null)
- throw new NotSupportedException(SR.NotSupported_UmsSafeBuffer);
-
- EnsureNotClosed();
- EnsureWriteable();
-
- if (value > _capacity)
- throw new IOException(SR.IO_FixedCapacity);
-
- long pos = Interlocked.Read(ref _position);
- long len = Interlocked.Read(ref _length);
- if (value > len)
- {
- unsafe
- {
- Buffer.ZeroMemory(_mem + len, (nuint)(value - len));
- }
- }
- Interlocked.Exchange(ref _length, value);
- if (pos > value)
- {
- Interlocked.Exchange(ref _position, value);
- }
- }
-
- /// <summary>
- /// Writes buffer into the stream
- /// </summary>
- /// <param name="buffer">Buffer that will be written.</param>
- /// <param name="offset">Starting index in the buffer.</param>
- /// <param name="count">Number of bytes to write.</param>
- public override void Write(byte[] buffer, int offset, int count)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - offset < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- WriteCore(new ReadOnlySpan<byte>(buffer, offset, count));
- }
-
- public override void Write(ReadOnlySpan<byte> buffer)
- {
- if (GetType() == typeof(UnmanagedMemoryStream))
- {
- WriteCore(buffer);
- }
- else
- {
- // UnmanagedMemoryStream is not sealed, and a derived type may have overridden Write(byte[], int, int) prior
- // to this Write(Span<byte>) overload being introduced. In that case, this Write(Span<byte>) overload
- // should use the behavior of Write(byte[],int,int) overload.
- base.Write(buffer);
- }
- }
-
- internal unsafe void WriteCore(ReadOnlySpan<byte> buffer)
- {
- EnsureNotClosed();
- EnsureWriteable();
-
- long pos = Interlocked.Read(ref _position); // Use a local to avoid a race condition
- long len = Interlocked.Read(ref _length);
- long n = pos + buffer.Length;
- // Check for overflow
- if (n < 0)
- {
- throw new IOException(SR.IO_StreamTooLong);
- }
-
- if (n > _capacity)
- {
- throw new NotSupportedException(SR.IO_FixedCapacity);
- }
-
- if (_buffer == null)
- {
- // Check to see whether we are now expanding the stream and must
- // zero any memory in the middle.
- if (pos > len)
- {
- Buffer.ZeroMemory(_mem + len, (nuint)(pos - len));
- }
-
- // set length after zeroing memory to avoid race condition of accessing unzeroed memory
- if (n > len)
- {
- Interlocked.Exchange(ref _length, n);
- }
- }
-
- fixed (byte* pBuffer = &MemoryMarshal.GetReference(buffer))
- {
- if (_buffer != null)
- {
- long bytesLeft = _capacity - pos;
- if (bytesLeft < buffer.Length)
- {
- throw new ArgumentException(SR.Arg_BufferTooSmall);
- }
-
- byte* pointer = null;
- RuntimeHelpers.PrepareConstrainedRegions();
- try
- {
- _buffer.AcquirePointer(ref pointer);
- Buffer.Memcpy(pointer + pos + _offset, pBuffer, buffer.Length);
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- else
- {
- Buffer.Memcpy(_mem + pos, pBuffer, buffer.Length);
- }
- }
-
- Interlocked.Exchange(ref _position, n);
- return;
- }
-
- /// <summary>
- /// Writes buffer into the stream. The operation completes synchronously.
- /// </summary>
- /// <param name="buffer">Buffer that will be written.</param>
- /// <param name="offset">Starting index in the buffer.</param>
- /// <param name="count">Number of bytes to write.</param>
- /// <param name="cancellationToken">Token that can be used to cancel the operation.</param>
- /// <returns>Task that can be awaited </returns>
- public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- if (buffer == null)
- throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
- if (offset < 0)
- throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (buffer.Length - offset < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled(cancellationToken);
-
- try
- {
- Write(buffer, offset, count);
- return Task.CompletedTask;
- }
- catch (Exception ex)
- {
- Debug.Assert(!(ex is OperationCanceledException));
- return Task.FromException(ex);
- }
- }
-
- /// <summary>
- /// Writes buffer into the stream. The operation completes synchronously.
- /// </summary>
- /// <param name="buffer">Buffer that will be written.</param>
- /// <param name="cancellationToken">Token that can be used to cancel the operation.</param>
- public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- return new ValueTask(Task.FromCanceled(cancellationToken));
- }
-
- try
- {
- // See corresponding comment in ReadAsync for why we don't just always use Write(ReadOnlySpan<byte>).
- // Unlike ReadAsync, we could delegate to WriteAsync(byte[], ...) here, but we don't for consistency.
- if (MemoryMarshal.TryGetArray(buffer, out ArraySegment<byte> sourceArray))
- {
- Write(sourceArray.Array!, sourceArray.Offset, sourceArray.Count);
- }
- else
- {
- Write(buffer.Span);
- }
- return default;
- }
- catch (Exception ex)
- {
- return new ValueTask(Task.FromException(ex));
- }
- }
-
- /// <summary>
- /// Writes a byte to the stream and advances the current Position.
- /// </summary>
- /// <param name="value"></param>
- public override void WriteByte(byte value)
- {
- EnsureNotClosed();
- EnsureWriteable();
-
- long pos = Interlocked.Read(ref _position); // Use a local to avoid a race condition
- long len = Interlocked.Read(ref _length);
- long n = pos + 1;
- if (pos >= len)
- {
- // Check for overflow
- if (n < 0)
- throw new IOException(SR.IO_StreamTooLong);
-
- if (n > _capacity)
- throw new NotSupportedException(SR.IO_FixedCapacity);
-
- // Check to see whether we are now expanding the stream and must
- // zero any memory in the middle.
- // don't do if created from SafeBuffer
- if (_buffer == null)
- {
- if (pos > len)
- {
- unsafe
- {
- Buffer.ZeroMemory(_mem + len, (nuint)(pos - len));
- }
- }
-
- // set length after zeroing memory to avoid race condition of accessing unzeroed memory
- Interlocked.Exchange(ref _length, n);
- }
- }
-
- if (_buffer != null)
- {
- unsafe
- {
- byte* pointer = null;
- RuntimeHelpers.PrepareConstrainedRegions();
- try
- {
- _buffer.AcquirePointer(ref pointer);
- *(pointer + pos + _offset) = value;
- }
- finally
- {
- if (pointer != null)
- {
- _buffer.ReleasePointer();
- }
- }
- }
- }
- else
- {
- unsafe
- {
- _mem[pos] = value;
- }
- }
- Interlocked.Exchange(ref _position, n);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStreamWrapper.cs b/netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStreamWrapper.cs
deleted file mode 100644
index e90c094df74..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStreamWrapper.cs
+++ /dev/null
@@ -1,195 +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.
-
-/*============================================================
-**
-**
-**
-**
-** Purpose: Create a Memorystream over an UnmanagedMemoryStream
-**
-===========================================================*/
-
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.IO
-{
- // Needed for backwards compatibility with V1.x usages of the
- // ResourceManager, where a MemoryStream is now returned as an
- // UnmanagedMemoryStream from ResourceReader.
- internal sealed class UnmanagedMemoryStreamWrapper : MemoryStream
- {
- private readonly UnmanagedMemoryStream _unmanagedStream;
-
- internal UnmanagedMemoryStreamWrapper(UnmanagedMemoryStream stream)
- {
- _unmanagedStream = stream;
- }
-
- public override bool CanRead => _unmanagedStream.CanRead;
-
- public override bool CanSeek => _unmanagedStream.CanSeek;
-
- public override bool CanWrite => _unmanagedStream.CanWrite;
-
- protected override void Dispose(bool disposing)
- {
- try
- {
- if (disposing)
- _unmanagedStream.Dispose();
- }
- finally
- {
- base.Dispose(disposing);
- }
- }
-
- public override void Flush()
- {
- _unmanagedStream.Flush();
- }
-
- public override byte[] GetBuffer()
- {
- throw new UnauthorizedAccessException(SR.UnauthorizedAccess_MemStreamBuffer);
- }
-
- public override bool TryGetBuffer(out ArraySegment<byte> buffer)
- {
- buffer = default;
- return false;
- }
-
- public override int Capacity
- {
- get => (int)_unmanagedStream.Capacity;
- set => throw new IOException(SR.IO_FixedCapacity);
- }
-
- public override long Length => _unmanagedStream.Length;
-
- public override long Position
- {
- get => _unmanagedStream.Position;
- set => _unmanagedStream.Position = value;
- }
-
- public override int Read(byte[] buffer, int offset, int count)
- {
- return _unmanagedStream.Read(buffer, offset, count);
- }
-
- public override int Read(Span<byte> buffer)
- {
- return _unmanagedStream.Read(buffer);
- }
-
- public override int ReadByte()
- {
- return _unmanagedStream.ReadByte();
- }
-
- public override long Seek(long offset, SeekOrigin loc)
- {
- return _unmanagedStream.Seek(offset, loc);
- }
-
- public override unsafe byte[] ToArray()
- {
- byte[] buffer = new byte[_unmanagedStream.Length];
- _unmanagedStream.Read(buffer, 0, (int)_unmanagedStream.Length);
- return buffer;
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- _unmanagedStream.Write(buffer, offset, count);
- }
-
- public override void Write(ReadOnlySpan<byte> buffer)
- {
- _unmanagedStream.Write(buffer);
- }
-
- public override void WriteByte(byte value)
- {
- _unmanagedStream.WriteByte(value);
- }
-
- // Writes this MemoryStream to another stream.
- public override unsafe void WriteTo(Stream stream)
- {
- if (stream == null)
- throw new ArgumentNullException(nameof(stream), SR.ArgumentNull_Stream);
-
- byte[] buffer = ToArray();
-
- stream.Write(buffer, 0, buffer.Length);
- }
-
- public override void SetLength(long value)
- {
- // This was probably meant to call _unmanagedStream.SetLength(value), but it was forgotten in V.4.0.
- // Now this results in a call to the base which touches the underlying array which is never actually used.
- // We cannot fix it due to compat now, but we should fix this at the next SxS release oportunity.
- base.SetLength(value);
- }
-
-
- public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
- {
- // The parameter checks must be in sync with the base version:
- if (destination == null)
- throw new ArgumentNullException(nameof(destination));
-
- if (bufferSize <= 0)
- throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
-
- if (!CanRead && !CanWrite)
- throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
-
- if (!destination.CanRead && !destination.CanWrite)
- throw new ObjectDisposedException(nameof(destination), SR.ObjectDisposed_StreamClosed);
-
- if (!CanRead)
- throw new NotSupportedException(SR.NotSupported_UnreadableStream);
-
- if (!destination.CanWrite)
- throw new NotSupportedException(SR.NotSupported_UnwritableStream);
-
-
- return _unmanagedStream.CopyToAsync(destination, bufferSize, cancellationToken);
- }
-
-
- public override Task FlushAsync(CancellationToken cancellationToken)
- {
- return _unmanagedStream.FlushAsync(cancellationToken);
- }
-
-
- public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- return _unmanagedStream.ReadAsync(buffer, offset, count, cancellationToken);
- }
-
- public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
- {
- return _unmanagedStream.ReadAsync(buffer, cancellationToken);
- }
-
-
- public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- return _unmanagedStream.WriteAsync(buffer, offset, count, cancellationToken);
- }
-
- public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
- {
- return _unmanagedStream.WriteAsync(buffer, cancellationToken);
- }
- } // class UnmanagedMemoryStreamWrapper
-} // namespace
diff --git a/netcore/System.Private.CoreLib/shared/System/IO/Win32Marshal.cs b/netcore/System.Private.CoreLib/shared/System/IO/Win32Marshal.cs
deleted file mode 100644
index 35f7d2eefe9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IO/Win32Marshal.cs
+++ /dev/null
@@ -1,101 +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.
-
-#nullable enable
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.IO
-{
- /// <summary>
- /// Provides static methods for converting from Win32 errors codes to exceptions, HRESULTS and error messages.
- /// </summary>
- internal static class Win32Marshal
- {
- /// <summary>
- /// Converts, resetting it, the last Win32 error into a corresponding <see cref="Exception"/> object, optionally
- /// including the specified path in the error message.
- /// </summary>
- internal static Exception GetExceptionForLastWin32Error(string? path = "")
- => GetExceptionForWin32Error(Marshal.GetLastWin32Error(), path);
-
- /// <summary>
- /// Converts the specified Win32 error into a corresponding <see cref="Exception"/> object, optionally
- /// including the specified path in the error message.
- /// </summary>
- internal static Exception GetExceptionForWin32Error(int errorCode, string? path = "")
- {
- // ERROR_SUCCESS gets thrown when another unexpected interop call was made before checking GetLastWin32Error().
- // Errors have to get retrieved as soon as possible after P/Invoking to avoid this.
- Debug.Assert(errorCode != Interop.Errors.ERROR_SUCCESS);
-
- switch (errorCode)
- {
- case Interop.Errors.ERROR_FILE_NOT_FOUND:
- return new FileNotFoundException(
- string.IsNullOrEmpty(path) ? SR.IO_FileNotFound : SR.Format(SR.IO_FileNotFound_FileName, path), path);
- case Interop.Errors.ERROR_PATH_NOT_FOUND:
- return new DirectoryNotFoundException(
- string.IsNullOrEmpty(path) ? SR.IO_PathNotFound_NoPathName : SR.Format(SR.IO_PathNotFound_Path, path));
- case Interop.Errors.ERROR_ACCESS_DENIED:
- return new UnauthorizedAccessException(
- string.IsNullOrEmpty(path) ? SR.UnauthorizedAccess_IODenied_NoPathName : SR.Format(SR.UnauthorizedAccess_IODenied_Path, path));
- case Interop.Errors.ERROR_ALREADY_EXISTS:
- if (string.IsNullOrEmpty(path))
- goto default;
- return new IOException(SR.Format(SR.IO_AlreadyExists_Name, path), MakeHRFromErrorCode(errorCode));
- case Interop.Errors.ERROR_FILENAME_EXCED_RANGE:
- return new PathTooLongException(
- string.IsNullOrEmpty(path) ? SR.IO_PathTooLong : SR.Format(SR.IO_PathTooLong_Path, path));
- case Interop.Errors.ERROR_SHARING_VIOLATION:
- return new IOException(
- string.IsNullOrEmpty(path) ? SR.IO_SharingViolation_NoFileName : SR.Format(SR.IO_SharingViolation_File, path),
- MakeHRFromErrorCode(errorCode));
- case Interop.Errors.ERROR_FILE_EXISTS:
- if (string.IsNullOrEmpty(path))
- goto default;
- return new IOException(SR.Format(SR.IO_FileExists_Name, path), MakeHRFromErrorCode(errorCode));
- case Interop.Errors.ERROR_OPERATION_ABORTED:
- return new OperationCanceledException();
- case Interop.Errors.ERROR_INVALID_PARAMETER:
- default:
- return new IOException(
- string.IsNullOrEmpty(path) ? GetMessage(errorCode) : $"{GetMessage(errorCode)} : '{path}'",
- MakeHRFromErrorCode(errorCode));
- }
- }
-
- /// <summary>
- /// If not already an HRESULT, returns an HRESULT for the specified Win32 error code.
- /// </summary>
- internal static int MakeHRFromErrorCode(int errorCode)
- {
- // Don't convert it if it is already an HRESULT
- if ((0xFFFF0000 & errorCode) != 0)
- return errorCode;
-
- return unchecked(((int)0x80070000) | errorCode);
- }
-
- /// <summary>
- /// Returns a Win32 error code for the specified HRESULT if it came from FACILITY_WIN32
- /// If not, returns the HRESULT unchanged
- /// </summary>
- internal static int TryMakeWin32ErrorCodeFromHR(int hr)
- {
- if ((0xFFFF0000 & hr) == 0x80070000)
- {
- // Win32 error, Win32Marshal.GetExceptionForWin32Error expects the Win32 format
- hr &= 0x0000FFFF;
- }
-
- return hr;
- }
-
- /// <summary>
- /// Returns a string message for the specified Win32 error code.
- /// </summary>
- internal static string GetMessage(int errorCode) => Interop.Kernel32.GetMessage(errorCode);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IObservable.cs b/netcore/System.Private.CoreLib/shared/System/IObservable.cs
deleted file mode 100644
index aabb0b8fb42..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IObservable.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System
-{
- public interface IObservable<out T>
- {
- IDisposable Subscribe(IObserver<T> observer);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IObserver.cs b/netcore/System.Private.CoreLib/shared/System/IObserver.cs
deleted file mode 100644
index 39e123de8db..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IObserver.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System
-{
- public interface IObserver<in T>
- {
- void OnNext(T value);
- void OnError(Exception error);
- void OnCompleted();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IProgress.cs b/netcore/System.Private.CoreLib/shared/System/IProgress.cs
deleted file mode 100644
index 724c7bdce9a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IProgress.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System
-{
- /// <summary>Defines a provider for progress updates.</summary>
- /// <typeparam name="T">The type of progress update value.</typeparam>
- public interface IProgress<in T>
- {
- /// <summary>Reports a progress update.</summary>
- /// <param name="value">The value of the updated progress.</param>
- void Report(T value);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ISpanFormattable.cs b/netcore/System.Private.CoreLib/shared/System/ISpanFormattable.cs
deleted file mode 100644
index d3744addcbd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ISpanFormattable.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System
-{
- internal interface ISpanFormattable
- {
- bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Index.cs b/netcore/System.Private.CoreLib/shared/System/Index.cs
deleted file mode 100644
index 8f7c12eaac7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Index.cs
+++ /dev/null
@@ -1,150 +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 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 = _value;
- if (IsFromEnd)
- {
- // offset = length - (~value)
- // offset = length + (~(~value) + 1)
- // offset = length + value + 1
-
- offset += length + 1;
- }
- 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));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IndexOutOfRangeException.cs b/netcore/System.Private.CoreLib/shared/System/IndexOutOfRangeException.cs
deleted file mode 100644
index b2ef53865b7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IndexOutOfRangeException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class for invalid array indices.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class IndexOutOfRangeException : SystemException
- {
- public IndexOutOfRangeException()
- : base(SR.Arg_IndexOutOfRangeException)
- {
- HResult = HResults.COR_E_INDEXOUTOFRANGE;
- }
-
- public IndexOutOfRangeException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_INDEXOUTOFRANGE;
- }
-
- public IndexOutOfRangeException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_INDEXOUTOFRANGE;
- }
-
- private IndexOutOfRangeException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/InsufficientExecutionStackException.cs b/netcore/System.Private.CoreLib/shared/System/InsufficientExecutionStackException.cs
deleted file mode 100644
index 998a824ff69..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/InsufficientExecutionStackException.cs
+++ /dev/null
@@ -1,35 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class InsufficientExecutionStackException : SystemException
- {
- public InsufficientExecutionStackException()
- : base(SR.Arg_InsufficientExecutionStackException)
- {
- HResult = HResults.COR_E_INSUFFICIENTEXECUTIONSTACK;
- }
-
- public InsufficientExecutionStackException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_INSUFFICIENTEXECUTIONSTACK;
- }
-
- public InsufficientExecutionStackException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_INSUFFICIENTEXECUTIONSTACK;
- }
-
- private InsufficientExecutionStackException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/InsufficientMemoryException.cs b/netcore/System.Private.CoreLib/shared/System/InsufficientMemoryException.cs
deleted file mode 100644
index 900f626a02c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/InsufficientMemoryException.cs
+++ /dev/null
@@ -1,48 +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 System.Runtime.Serialization;
-
-namespace System
-{
- /// <summary>
- /// Purpose: The exception class for running out of memory
- /// but most likely in a non-fatal way that shouldn't
- /// be affected by escalation policy. Use this for cases
- /// like MemoryFailPoint or a TryAllocate method, where you
- /// expect OOM's with no shared state corruption and you
- /// want to recover from these errors.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class InsufficientMemoryException : OutOfMemoryException
- {
- public InsufficientMemoryException() : base(
-#if CORECLR
- GetMessageFromNativeResources(ExceptionMessageKind.OutOfMemory)
-#else
- SR.Arg_OutOfMemoryException
-#endif
- )
- {
- HResult = HResults.COR_E_INSUFFICIENTMEMORY;
- }
-
- public InsufficientMemoryException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_INSUFFICIENTMEMORY;
- }
-
- public InsufficientMemoryException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_INSUFFICIENTMEMORY;
- }
-
- private InsufficientMemoryException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Int16.cs b/netcore/System.Private.CoreLib/shared/System/Int16.cs
deleted file mode 100644
index ed556eede40..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Int16.cs
+++ /dev/null
@@ -1,289 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- [Serializable]
- [StructLayout(LayoutKind.Sequential)]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct Int16 : IComparable, IConvertible, IFormattable, IComparable<short>, IEquatable<short>, ISpanFormattable
- {
- private readonly short m_value; // Do not rename (binary serialization)
-
- public const short MaxValue = (short)0x7FFF;
- public const short MinValue = unchecked((short)0x8000);
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type Int16, this method throws an ArgumentException.
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
-
- if (value is short)
- {
- return m_value - ((short)value).m_value;
- }
-
- throw new ArgumentException(SR.Arg_MustBeInt16);
- }
-
- public int CompareTo(short value)
- {
- return m_value - value;
- }
-
- public override bool Equals(object? obj)
- {
- if (!(obj is short))
- {
- return false;
- }
- return m_value == ((short)obj).m_value;
- }
-
- [NonVersionable]
- public bool Equals(short obj)
- {
- return m_value == obj;
- }
-
- // Returns a HashCode for the Int16
- public override int GetHashCode()
- {
- return m_value;
- }
-
-
- public override string ToString()
- {
- return Number.FormatInt32(m_value, null, null);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return Number.FormatInt32(m_value, null, provider);
- }
-
- public string ToString(string? format)
- {
- return ToString(format, null);
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- if (m_value < 0 && format != null && format.Length > 0 && (format[0] == 'X' || format[0] == 'x'))
- {
- uint temp = (uint)(m_value & 0x0000FFFF);
- return Number.FormatUInt32(temp, format, provider);
- }
-
- return Number.FormatInt32(m_value, format, provider);
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
- {
- if (m_value < 0 && format.Length > 0 && (format[0] == 'X' || format[0] == 'x'))
- {
- uint temp = (uint)(m_value & 0x0000FFFF);
- return Number.TryFormatUInt32(temp, format, provider, destination, out charsWritten);
- }
- return Number.TryFormatInt32(m_value, format, provider, destination, out charsWritten);
- }
-
- public static short Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- public static short Parse(string s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, style, NumberFormatInfo.CurrentInfo);
- }
-
- public static short Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- public static short Parse(string s, NumberStyles style, IFormatProvider? provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- public static short Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- private static short Parse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info)
- {
- Number.ParsingStatus status = Number.TryParseInt32(s, style, info, out int i);
- if (status != Number.ParsingStatus.OK)
- {
- Number.ThrowOverflowOrFormatException(status, TypeCode.Int16);
- }
-
- // For hex number styles AllowHexSpecifier << 6 == 0x8000 and cancels out MinValue so the check is effectively: (uint)i > ushort.MaxValue
- // For integer styles it's zero and the effective check is (uint)(i - MinValue) > ushort.MaxValue
- if ((uint)(i - MinValue - ((int)(style & NumberStyles.AllowHexSpecifier) << 6)) > ushort.MaxValue)
- {
- Number.ThrowOverflowException(TypeCode.Int16);
- }
- return (short)i;
- }
-
- public static bool TryParse(string? s, out short result)
- {
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, out short result)
- {
- return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out short result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
-
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out short result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- private static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info, out short result)
- {
- // For hex number styles AllowHexSpecifier << 6 == 0x8000 and cancels out MinValue so the check is effectively: (uint)i > ushort.MaxValue
- // For integer styles it's zero and the effective check is (uint)(i - MinValue) > ushort.MaxValue
- if (Number.TryParseInt32(s, style, info, out int i) != Number.ParsingStatus.OK
- || (uint)(i - MinValue - ((int)(style & NumberStyles.AllowHexSpecifier) << 6)) > ushort.MaxValue)
- {
- result = 0;
- return false;
- }
- result = (short)i;
- return true;
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.Int16;
- }
-
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return m_value;
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int16", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Int32.cs b/netcore/System.Private.CoreLib/shared/System/Int32.cs
deleted file mode 100644
index e1707f054fa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Int32.cs
+++ /dev/null
@@ -1,270 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- [Serializable]
- [StructLayout(LayoutKind.Sequential)]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct Int32 : IComparable, IConvertible, IFormattable, IComparable<int>, IEquatable<int>, ISpanFormattable
- {
- private readonly int m_value; // Do not rename (binary serialization)
-
- public const int MaxValue = 0x7fffffff;
- public const int MinValue = unchecked((int)0x80000000);
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns :
- // 0 if the values are equal
- // Negative number if _value is less than value
- // Positive number if _value is more than value
- // null is considered to be less than any instance, hence returns positive number
- // If object is not of type Int32, this method throws an ArgumentException.
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
-
- // NOTE: Cannot use return (_value - value) as this causes a wrap
- // around in cases where _value - value > MaxValue.
- if (value is int i)
- {
- if (m_value < i) return -1;
- if (m_value > i) return 1;
- return 0;
- }
-
- throw new ArgumentException(SR.Arg_MustBeInt32);
- }
-
- public int CompareTo(int value)
- {
- // NOTE: Cannot use return (_value - value) as this causes a wrap
- // around in cases where _value - value > MaxValue.
- if (m_value < value) return -1;
- if (m_value > value) return 1;
- return 0;
- }
-
- public override bool Equals(object? obj)
- {
- if (!(obj is int))
- {
- return false;
- }
- return m_value == ((int)obj).m_value;
- }
-
- [NonVersionable]
- public bool Equals(int obj)
- {
- return m_value == obj;
- }
-
- // The absolute value of the int contained.
- public override int GetHashCode()
- {
- return m_value;
- }
-
- public override string ToString()
- {
- return Number.FormatInt32(m_value, null, null);
- }
-
- public string ToString(string? format)
- {
- return Number.FormatInt32(m_value, format, null);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return Number.FormatInt32(m_value, null, provider);
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- return Number.FormatInt32(m_value, format, provider);
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
- {
- return Number.TryFormatInt32(m_value, format, provider, destination, out charsWritten);
- }
-
- public static int Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- public static int Parse(string s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseInt32(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- // Parses an integer from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- //
- public static int Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- // Parses an integer from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- //
- public static int Parse(string s, NumberStyles style, IFormatProvider? provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseInt32(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- public static int Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseInt32(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- // Parses an integer from a String. Returns false rather
- // than throwing exceptin if input is invalid
- //
- public static bool TryParse(string? s, out int result)
- {
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return Number.TryParseInt32IntegerStyle(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result) == Number.ParsingStatus.OK;
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, out int result)
- {
- return Number.TryParseInt32IntegerStyle(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result) == Number.ParsingStatus.OK;
- }
-
- // Parses an integer from a String in the given style. Returns false rather
- // than throwing exceptin if input is invalid
- //
- public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out int result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
-
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK;
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out int result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK;
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.Int32;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return m_value;
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int32", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Int64.cs b/netcore/System.Private.CoreLib/shared/System/Int64.cs
deleted file mode 100644
index ae513d13047..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Int64.cs
+++ /dev/null
@@ -1,257 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- [Serializable]
- [StructLayout(LayoutKind.Sequential)]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct Int64 : IComparable, IConvertible, IFormattable, IComparable<long>, IEquatable<long>, ISpanFormattable
- {
- private readonly long m_value; // Do not rename (binary serialization)
-
- public const long MaxValue = 0x7fffffffffffffffL;
- public const long MinValue = unchecked((long)0x8000000000000000L);
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type Int64, this method throws an ArgumentException.
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
-
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- if (value is long i)
- {
- if (m_value < i) return -1;
- if (m_value > i) return 1;
- return 0;
- }
-
- throw new ArgumentException(SR.Arg_MustBeInt64);
- }
-
- public int CompareTo(long value)
- {
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- if (m_value < value) return -1;
- if (m_value > value) return 1;
- return 0;
- }
-
- public override bool Equals(object? obj)
- {
- if (!(obj is long))
- {
- return false;
- }
- return m_value == ((long)obj).m_value;
- }
-
- [NonVersionable]
- public bool Equals(long obj)
- {
- return m_value == obj;
- }
-
- // The value of the lower 32 bits XORed with the uppper 32 bits.
- public override int GetHashCode()
- {
- return unchecked((int)((long)m_value)) ^ (int)(m_value >> 32);
- }
-
- public override string ToString()
- {
- return Number.FormatInt64(m_value, null, null);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return Number.FormatInt64(m_value, null, provider);
- }
-
- public string ToString(string? format)
- {
- return Number.FormatInt64(m_value, format, null);
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- return Number.FormatInt64(m_value, format, provider);
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
- {
- return Number.TryFormatInt64(m_value, format, provider, destination, out charsWritten);
- }
-
- public static long Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- public static long Parse(string s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseInt64(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- public static long Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseInt64(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- // Parses a long from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- //
- public static long Parse(string s, NumberStyles style, IFormatProvider? provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseInt64(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- public static long Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseInt64(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- public static bool TryParse(string? s, out long result)
- {
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return Number.TryParseInt64IntegerStyle(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result) == Number.ParsingStatus.OK;
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, out long result)
- {
- return Number.TryParseInt64IntegerStyle(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result) == Number.ParsingStatus.OK;
- }
-
- public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out long result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
-
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return Number.TryParseInt64(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK;
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out long result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.TryParseInt64(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK;
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.Int64;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return m_value;
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int64", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/IntPtr.cs b/netcore/System.Private.CoreLib/shared/System/IntPtr.cs
deleted file mode 100644
index 1d93be7fb15..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/IntPtr.cs
+++ /dev/null
@@ -1,195 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-using System.Runtime.Versioning;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nint = System.Int64;
-#else
-using nint = System.Int32;
-#endif
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- 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 readonly unsafe void* _value; // Do not rename (binary serialization)
-
- [Intrinsic]
- public static readonly IntPtr Zero;
-
- [Intrinsic]
- [NonVersionable]
- public unsafe IntPtr(int value)
- {
- _value = (void*)value;
- }
-
- [Intrinsic]
- [NonVersionable]
- public unsafe IntPtr(long value)
- {
-#if BIT64
- _value = (void*)value;
-#else
- _value = (void*)checked((int)value);
-#endif
- }
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public unsafe IntPtr(void* value)
- {
- _value = value;
- }
-
- private unsafe IntPtr(SerializationInfo info, StreamingContext context)
- {
- long l = info.GetInt64("value");
-
- if (Size == 4 && (l > int.MaxValue || l < int.MinValue))
- throw new ArgumentException(SR.Serialization_InvalidPtrValue);
-
- _value = (void*)l;
- }
-
- unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- throw new ArgumentNullException(nameof(info));
-
- info.AddValue("value", ToInt64());
- }
-
- public override unsafe bool Equals(object? obj) =>
- obj is IntPtr other &&
- _value == other._value;
-
- unsafe bool IEquatable<IntPtr>.Equals(IntPtr other) =>
- _value == other._value;
-
- public override unsafe int GetHashCode()
- {
-#if BIT64
- long l = (long)_value;
- return unchecked((int)l) ^ (int)(l >> 32);
-#else
- return unchecked((int)_value);
-#endif
- }
-
- [Intrinsic]
- [NonVersionable]
- public unsafe int ToInt32()
- {
-#if BIT64
- long l = (long)_value;
- return checked((int)l);
-#else
- return (int)_value;
-#endif
- }
-
- [Intrinsic]
- [NonVersionable]
- public unsafe long ToInt64() =>
- (nint)_value;
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe explicit operator IntPtr(int value) =>
- new IntPtr(value);
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe explicit operator IntPtr(long value) =>
- new IntPtr(value);
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static unsafe explicit operator IntPtr(void* value) =>
- new IntPtr(value);
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static unsafe explicit operator void*(IntPtr value) =>
- value._value;
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe explicit operator int(IntPtr value)
- {
-#if BIT64
- long l = (long)value._value;
- return checked((int)l);
-#else
- return (int)value._value;
-#endif
- }
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe explicit operator long(IntPtr value) =>
- (nint)value._value;
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe bool operator ==(IntPtr value1, IntPtr value2) =>
- value1._value == value2._value;
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe bool operator !=(IntPtr value1, IntPtr value2) =>
- value1._value != value2._value;
-
- [NonVersionable]
- public static IntPtr Add(IntPtr pointer, int offset) =>
- pointer + offset;
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe IntPtr operator +(IntPtr pointer, int offset) =>
- new IntPtr((nint)pointer._value + offset);
-
- [NonVersionable]
- public static IntPtr Subtract(IntPtr pointer, int offset) =>
- pointer - offset;
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe IntPtr operator -(IntPtr pointer, int offset) =>
- new IntPtr((nint)pointer._value - offset);
-
- public static int Size
- {
- [Intrinsic]
- [NonVersionable]
- get => sizeof(nint);
- }
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public unsafe void* ToPointer() => _value;
-
- public override unsafe string ToString() =>
- ((nint)_value).ToString(CultureInfo.InvariantCulture);
-
- public unsafe string ToString(string format) =>
- ((nint)_value).ToString(format, CultureInfo.InvariantCulture);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/InvalidCastException.cs b/netcore/System.Private.CoreLib/shared/System/InvalidCastException.cs
deleted file mode 100644
index c3b22167b1e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/InvalidCastException.cs
+++ /dev/null
@@ -1,47 +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.
-
-/*=============================================================================
-**
-** Purpose: Exception class for invalid cast conditions!
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class InvalidCastException : SystemException
- {
- public InvalidCastException()
- : base(SR.Arg_InvalidCastException)
- {
- HResult = HResults.COR_E_INVALIDCAST;
- }
-
- public InvalidCastException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_INVALIDCAST;
- }
-
- public InvalidCastException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_INVALIDCAST;
- }
-
- public InvalidCastException(string? message, int errorCode)
- : base(message)
- {
- HResult = errorCode;
- }
-
- protected InvalidCastException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/InvalidOperationException.cs b/netcore/System.Private.CoreLib/shared/System/InvalidOperationException.cs
deleted file mode 100644
index ac24a834ef5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/InvalidOperationException.cs
+++ /dev/null
@@ -1,45 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class for denoting an object was in a state that
-** made calling a method illegal.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class InvalidOperationException : SystemException
- {
- public InvalidOperationException()
- : base(SR.Arg_InvalidOperationException)
- {
- HResult = HResults.COR_E_INVALIDOPERATION;
- }
-
- public InvalidOperationException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_INVALIDOPERATION;
- }
-
- public InvalidOperationException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_INVALIDOPERATION;
- }
-
- protected InvalidOperationException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/InvalidProgramException.cs b/netcore/System.Private.CoreLib/shared/System/InvalidProgramException.cs
deleted file mode 100644
index d20391beb02..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/InvalidProgramException.cs
+++ /dev/null
@@ -1,42 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: The exception class for programs with invalid IL or bad metadata.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class InvalidProgramException : SystemException
- {
- public InvalidProgramException()
- : base(SR.InvalidProgram_Default)
- {
- HResult = HResults.COR_E_INVALIDPROGRAM;
- }
-
- public InvalidProgramException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_INVALIDPROGRAM;
- }
-
- public InvalidProgramException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_INVALIDPROGRAM;
- }
-
- private InvalidProgramException(SerializationInfo info, StreamingContext context) : base(info, context) { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/InvalidTimeZoneException.cs b/netcore/System.Private.CoreLib/shared/System/InvalidTimeZoneException.cs
deleted file mode 100644
index 165c25b15a2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/InvalidTimeZoneException.cs
+++ /dev/null
@@ -1,31 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class InvalidTimeZoneException : Exception
- {
- public InvalidTimeZoneException()
- {
- }
-
- public InvalidTimeZoneException(string? message)
- : base(message)
- {
- }
-
- public InvalidTimeZoneException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- }
-
- protected InvalidTimeZoneException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Lazy.cs b/netcore/System.Private.CoreLib/shared/System/Lazy.cs
deleted file mode 100644
index a88b0a9f228..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Lazy.cs
+++ /dev/null
@@ -1,536 +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.
-
-// --------------------------------------------------------------------------------------
-//
-// A class that provides a simple, lightweight implementation of lazy initialization,
-// obviating the need for a developer to implement a custom, thread-safe lazy initialization
-// solution.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.ExceptionServices;
-using System.Threading;
-
-namespace System
-{
- internal enum LazyState
- {
- NoneViaConstructor = 0,
- NoneViaFactory = 1,
- NoneException = 2,
-
- PublicationOnlyViaConstructor = 3,
- PublicationOnlyViaFactory = 4,
- PublicationOnlyWait = 5,
- PublicationOnlyException = 6,
-
- ExecutionAndPublicationViaConstructor = 7,
- ExecutionAndPublicationViaFactory = 8,
- ExecutionAndPublicationException = 9,
- }
-
- /// <summary>
- /// LazyHelper serves multiples purposes
- /// - minimizing code size of Lazy&lt;T&gt; by implementing as much of the code that is not generic
- /// this reduces generic code bloat, making faster class initialization
- /// - contains singleton objects that are used to handle threading primitives for PublicationOnly mode
- /// - allows for instantiation for ExecutionAndPublication so as to create an object for locking on
- /// - holds exception information.
- /// </summary>
- internal class LazyHelper
- {
- internal static readonly LazyHelper NoneViaConstructor = new LazyHelper(LazyState.NoneViaConstructor);
- internal static readonly LazyHelper NoneViaFactory = new LazyHelper(LazyState.NoneViaFactory);
- internal static readonly LazyHelper PublicationOnlyViaConstructor = new LazyHelper(LazyState.PublicationOnlyViaConstructor);
- internal static readonly LazyHelper PublicationOnlyViaFactory = new LazyHelper(LazyState.PublicationOnlyViaFactory);
- internal static readonly LazyHelper PublicationOnlyWaitForOtherThreadToPublish = new LazyHelper(LazyState.PublicationOnlyWait);
-
- internal LazyState State { get; }
-
- private readonly ExceptionDispatchInfo? _exceptionDispatch;
-
- /// <summary>
- /// Constructor that defines the state
- /// </summary>
- internal LazyHelper(LazyState state)
- {
- State = state;
- }
-
- /// <summary>
- /// Constructor used for exceptions
- /// </summary>
- internal LazyHelper(LazyThreadSafetyMode mode, Exception exception)
- {
- switch (mode)
- {
- case LazyThreadSafetyMode.ExecutionAndPublication:
- State = LazyState.ExecutionAndPublicationException;
- break;
-
- case LazyThreadSafetyMode.None:
- State = LazyState.NoneException;
- break;
-
- case LazyThreadSafetyMode.PublicationOnly:
- State = LazyState.PublicationOnlyException;
- break;
-
- default:
- Debug.Fail("internal constructor, this should never occur");
- break;
- }
-
- _exceptionDispatch = ExceptionDispatchInfo.Capture(exception);
- }
-
- [DoesNotReturn]
- internal void ThrowException()
- {
- Debug.Assert(_exceptionDispatch != null, "execution path is invalid");
-
- _exceptionDispatch.Throw();
- }
-
- private LazyThreadSafetyMode GetMode()
- {
- switch (State)
- {
- case LazyState.NoneViaConstructor:
- case LazyState.NoneViaFactory:
- case LazyState.NoneException:
- return LazyThreadSafetyMode.None;
-
- case LazyState.PublicationOnlyViaConstructor:
- case LazyState.PublicationOnlyViaFactory:
- case LazyState.PublicationOnlyWait:
- case LazyState.PublicationOnlyException:
- return LazyThreadSafetyMode.PublicationOnly;
-
- case LazyState.ExecutionAndPublicationViaConstructor:
- case LazyState.ExecutionAndPublicationViaFactory:
- case LazyState.ExecutionAndPublicationException:
- return LazyThreadSafetyMode.ExecutionAndPublication;
-
- default:
- Debug.Fail("Invalid logic; State should always have a valid value");
- return default;
- }
- }
-
- internal static LazyThreadSafetyMode? GetMode(LazyHelper? state)
- {
- if (state == null)
- return null; // we don't know the mode anymore
- return state.GetMode();
- }
-
- internal static bool GetIsValueFaulted(LazyHelper? state) => state?._exceptionDispatch != null;
-
- internal static LazyHelper Create(LazyThreadSafetyMode mode, bool useDefaultConstructor)
- {
- switch (mode)
- {
- case LazyThreadSafetyMode.None:
- return useDefaultConstructor ? NoneViaConstructor : NoneViaFactory;
-
- case LazyThreadSafetyMode.PublicationOnly:
- return useDefaultConstructor ? PublicationOnlyViaConstructor : PublicationOnlyViaFactory;
-
- case LazyThreadSafetyMode.ExecutionAndPublication:
- // we need to create an object for ExecutionAndPublication because we use Monitor-based locking
- LazyState state = useDefaultConstructor ?
- LazyState.ExecutionAndPublicationViaConstructor :
- LazyState.ExecutionAndPublicationViaFactory;
- return new LazyHelper(state);
-
- default:
- throw new ArgumentOutOfRangeException(nameof(mode), SR.Lazy_ctor_ModeInvalid);
- }
- }
-
- internal static T CreateViaDefaultConstructor<T>()
- {
- try
- {
- return Activator.CreateInstance<T>();
- }
- catch (MissingMethodException)
- {
- throw new MissingMemberException(SR.Lazy_CreateValue_NoParameterlessCtorForT);
- }
- }
-
- internal static LazyThreadSafetyMode GetModeFromIsThreadSafe(bool isThreadSafe)
- {
- return isThreadSafe ? LazyThreadSafetyMode.ExecutionAndPublication : LazyThreadSafetyMode.None;
- }
- }
-
- /// <summary>
- /// Provides support for lazy initialization.
- /// </summary>
- /// <typeparam name="T">Specifies the type of element being lazily initialized.</typeparam>
- /// <remarks>
- /// <para>
- /// By default, all public and protected members of <see cref="Lazy{T}"/> are thread-safe and may be used
- /// concurrently from multiple threads. These thread-safety guarantees may be removed optionally and per instance
- /// using parameters to the type's constructors.
- /// </para>
- /// </remarks>
- [DebuggerTypeProxy(typeof(LazyDebugView<>))]
- [DebuggerDisplay("ThreadSafetyMode={Mode}, IsValueCreated={IsValueCreated}, IsValueFaulted={IsValueFaulted}, Value={ValueForDebugDisplay}")]
- public class Lazy<T>
- {
- private static T CreateViaDefaultConstructor() => LazyHelper.CreateViaDefaultConstructor<T>();
-
- // _state, a volatile reference, is set to null after _value has been set
- private volatile LazyHelper? _state;
-
- // we ensure that _factory when finished is set to null to allow garbage collector to clean up
- // any referenced items
- private Func<T>? _factory;
-
- // _value eventually stores the lazily created value. It is valid when _state = null.
- private T _value = default!;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Lazy{T}"/> class that
- /// uses <typeparamref name="T"/>'s default constructor for lazy initialization.
- /// </summary>
- /// <remarks>
- /// An instance created with this constructor may be used concurrently from multiple threads.
- /// </remarks>
- public Lazy()
- : this(null, LazyThreadSafetyMode.ExecutionAndPublication, useDefaultConstructor: true)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Lazy{T}"/> class that
- /// uses a pre-initialized specified value.
- /// </summary>
- /// <remarks>
- /// An instance created with this constructor should be usable by multiple threads
- /// concurrently.
- /// </remarks>
- public Lazy(T value)
- {
- _value = value;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Lazy{T}"/> class that uses a
- /// specified initialization function.
- /// </summary>
- /// <param name="valueFactory">
- /// The <see cref="System.Func{T}"/> invoked to produce the lazily-initialized value when it is
- /// needed.
- /// </param>
- /// <exception cref="System.ArgumentNullException"><paramref name="valueFactory"/> is a null
- /// reference (Nothing in Visual Basic).</exception>
- /// <remarks>
- /// An instance created with this constructor may be used concurrently from multiple threads.
- /// </remarks>
- public Lazy(Func<T> valueFactory)
- : this(valueFactory, LazyThreadSafetyMode.ExecutionAndPublication, useDefaultConstructor: false)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Lazy{T}"/>
- /// class that uses <typeparamref name="T"/>'s default constructor and a specified thread-safety mode.
- /// </summary>
- /// <param name="isThreadSafe">true if this instance should be usable by multiple threads concurrently; false if the instance will only be used by one thread at a time.
- /// </param>
- public Lazy(bool isThreadSafe) :
- this(null, LazyHelper.GetModeFromIsThreadSafe(isThreadSafe), useDefaultConstructor: true)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Lazy{T}"/>
- /// class that uses <typeparamref name="T"/>'s default constructor and a specified thread-safety mode.
- /// </summary>
- /// <param name="mode">The lazy thread-safety mode</param>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="mode"/> mode contains an invalid valuee</exception>
- public Lazy(LazyThreadSafetyMode mode) :
- this(null, mode, useDefaultConstructor: true)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Lazy{T}"/> class
- /// that uses a specified initialization function and a specified thread-safety mode.
- /// </summary>
- /// <param name="valueFactory">
- /// The <see cref="System.Func{T}"/> invoked to produce the lazily-initialized value when it is needed.
- /// </param>
- /// <param name="isThreadSafe">true if this instance should be usable by multiple threads concurrently; false if the instance will only be used by one thread at a time.
- /// </param>
- /// <exception cref="System.ArgumentNullException"><paramref name="valueFactory"/> is
- /// a null reference (Nothing in Visual Basic).</exception>
- public Lazy(Func<T> valueFactory, bool isThreadSafe) :
- this(valueFactory, LazyHelper.GetModeFromIsThreadSafe(isThreadSafe), useDefaultConstructor: false)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Lazy{T}"/> class
- /// that uses a specified initialization function and a specified thread-safety mode.
- /// </summary>
- /// <param name="valueFactory">
- /// The <see cref="System.Func{T}"/> invoked to produce the lazily-initialized value when it is needed.
- /// </param>
- /// <param name="mode">The lazy thread-safety mode.</param>
- /// <exception cref="System.ArgumentNullException"><paramref name="valueFactory"/> is
- /// a null reference (Nothing in Visual Basic).</exception>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="mode"/> mode contains an invalid value.</exception>
- public Lazy(Func<T> valueFactory, LazyThreadSafetyMode mode)
- : this(valueFactory, mode, useDefaultConstructor: false)
- {
- }
-
- private Lazy(Func<T>? valueFactory, LazyThreadSafetyMode mode, bool useDefaultConstructor)
- {
- if (valueFactory == null && !useDefaultConstructor)
- throw new ArgumentNullException(nameof(valueFactory));
-
- _factory = valueFactory;
- _state = LazyHelper.Create(mode, useDefaultConstructor);
- }
-
- private void ViaConstructor()
- {
- _value = CreateViaDefaultConstructor();
- _state = null; // volatile write, must occur after setting _value
- }
-
- private void ViaFactory(LazyThreadSafetyMode mode)
- {
- try
- {
- Func<T>? factory = _factory;
- if (factory == null)
- throw new InvalidOperationException(SR.Lazy_Value_RecursiveCallsToValue);
- _factory = null;
-
- _value = factory();
- _state = null; // volatile write, must occur after setting _value
- }
- catch (Exception exception)
- {
- _state = new LazyHelper(mode, exception);
- throw;
- }
- }
-
- private void ExecutionAndPublication(LazyHelper executionAndPublication, bool useDefaultConstructor)
- {
- lock (executionAndPublication)
- {
- // it's possible for multiple calls to have piled up behind the lock, so we need to check
- // to see if the ExecutionAndPublication object is still the current implementation.
- if (ReferenceEquals(_state, executionAndPublication))
- {
- if (useDefaultConstructor)
- {
- ViaConstructor();
- }
- else
- {
- ViaFactory(LazyThreadSafetyMode.ExecutionAndPublication);
- }
- }
- }
- }
-
- private void PublicationOnly(LazyHelper publicationOnly, T possibleValue)
- {
- LazyHelper? previous = Interlocked.CompareExchange(ref _state, LazyHelper.PublicationOnlyWaitForOtherThreadToPublish, publicationOnly);
- if (previous == publicationOnly)
- {
- _factory = null;
- _value = possibleValue;
- _state = null; // volatile write, must occur after setting _value
- }
- }
-
- private void PublicationOnlyViaConstructor(LazyHelper initializer)
- {
- PublicationOnly(initializer, CreateViaDefaultConstructor());
- }
-
- private void PublicationOnlyViaFactory(LazyHelper initializer)
- {
- Func<T>? factory = _factory;
- if (factory == null)
- {
- PublicationOnlyWaitForOtherThreadToPublish();
- }
- else
- {
- PublicationOnly(initializer, factory());
- }
- }
-
- private void PublicationOnlyWaitForOtherThreadToPublish()
- {
- SpinWait spinWait = default;
- while (!ReferenceEquals(_state, null))
- {
- // We get here when PublicationOnly temporarily sets _state to LazyHelper.PublicationOnlyWaitForOtherThreadToPublish.
- // This temporary state should be quickly followed by _state being set to null.
- spinWait.SpinOnce();
- }
- }
-
- private T CreateValue()
- {
- // we have to create a copy of state here, and use the copy exclusively from here on in
- // so as to ensure thread safety.
- LazyHelper? state = _state;
- if (state != null)
- {
- switch (state.State)
- {
- case LazyState.NoneViaConstructor:
- ViaConstructor();
- break;
-
- case LazyState.NoneViaFactory:
- ViaFactory(LazyThreadSafetyMode.None);
- break;
-
- case LazyState.PublicationOnlyViaConstructor:
- PublicationOnlyViaConstructor(state);
- break;
-
- case LazyState.PublicationOnlyViaFactory:
- PublicationOnlyViaFactory(state);
- break;
-
- case LazyState.PublicationOnlyWait:
- PublicationOnlyWaitForOtherThreadToPublish();
- break;
-
- case LazyState.ExecutionAndPublicationViaConstructor:
- ExecutionAndPublication(state, useDefaultConstructor: true);
- break;
-
- case LazyState.ExecutionAndPublicationViaFactory:
- ExecutionAndPublication(state, useDefaultConstructor: false);
- break;
-
- default:
- state.ThrowException();
- break;
- }
- }
- return Value;
- }
-
- /// <summary>Creates and returns a string representation of this instance.</summary>
- /// <returns>The result of calling <see cref="object.ToString"/> on the <see
- /// cref="Value"/>.</returns>
- /// <exception cref="System.NullReferenceException">
- /// The <see cref="Value"/> is null.
- /// </exception>
- public override string? ToString()
- {
- return IsValueCreated ?
- Value!.ToString() : // Throws NullReferenceException as if caller called ToString on the value itself
- SR.Lazy_ToString_ValueNotCreated;
- }
-
- /// <summary>Gets the value of the Lazy&lt;T&gt; for debugging display purposes.</summary>
- [MaybeNull]
- internal T ValueForDebugDisplay
- {
- get
- {
- if (!IsValueCreated)
- {
- return default!;
- }
- return _value;
- }
- }
-
- /// <summary>
- /// Gets a value indicating whether this instance may be used concurrently from multiple threads.
- /// </summary>
- internal LazyThreadSafetyMode? Mode => LazyHelper.GetMode(_state);
-
- /// <summary>
- /// Gets whether the value creation is faulted or not
- /// </summary>
- internal bool IsValueFaulted => LazyHelper.GetIsValueFaulted(_state);
-
- /// <summary>Gets a value indicating whether the <see cref="System.Lazy{T}"/> has been initialized.
- /// </summary>
- /// <value>true if the <see cref="System.Lazy{T}"/> instance has been initialized;
- /// otherwise, false.</value>
- /// <remarks>
- /// The initialization of a <see cref="System.Lazy{T}"/> instance may result in either
- /// a value being produced or an exception being thrown. If an exception goes unhandled during initialization,
- /// <see cref="IsValueCreated"/> will return false.
- /// </remarks>
- public bool IsValueCreated => _state == null;
-
- /// <summary>Gets the lazily initialized value of the current <see
- /// cref="System.Lazy{T}"/>.</summary>
- /// <value>The lazily initialized value of the current <see
- /// cref="System.Lazy{T}"/>.</value>
- /// <exception cref="System.MissingMemberException">
- /// The <see cref="System.Lazy{T}"/> was initialized to use the default constructor
- /// of the type being lazily initialized, and that type does not have a public, parameterless constructor.
- /// </exception>
- /// <exception cref="System.MemberAccessException">
- /// The <see cref="System.Lazy{T}"/> was initialized to use the default constructor
- /// of the type being lazily initialized, and permissions to access the constructor were missing.
- /// </exception>
- /// <exception cref="System.InvalidOperationException">
- /// The <see cref="System.Lazy{T}"/> was constructed with the <see cref="System.Threading.LazyThreadSafetyMode.ExecutionAndPublication"/> or
- /// <see cref="System.Threading.LazyThreadSafetyMode.None"/> and the initialization function attempted to access <see cref="Value"/> on this instance.
- /// </exception>
- /// <remarks>
- /// If <see cref="IsValueCreated"/> is false, accessing <see cref="Value"/> will force initialization.
- /// Please <see cref="System.Threading.LazyThreadSafetyMode"/> for more information on how <see cref="System.Lazy{T}"/> will behave if an exception is thrown
- /// from initialization delegate.
- /// </remarks>
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public T Value => _state == null ? _value : CreateValue();
- }
-
- /// <summary>A debugger view of the Lazy&lt;T&gt; to surface additional debugging properties and
- /// to ensure that the Lazy&lt;T&gt; does not become initialized if it was not already.</summary>
- internal sealed class LazyDebugView<T>
- {
- // The Lazy object being viewed.
- private readonly Lazy<T> _lazy;
-
- /// <summary>Constructs a new debugger view object for the provided Lazy object.</summary>
- /// <param name="lazy">A Lazy object to browse in the debugger.</param>
- public LazyDebugView(Lazy<T> lazy)
- {
- _lazy = lazy;
- }
-
- /// <summary>Returns whether the Lazy object is initialized or not.</summary>
- public bool IsValueCreated => _lazy.IsValueCreated;
-
- /// <summary>Returns the value of the Lazy object.</summary>
- public T Value => _lazy.ValueForDebugDisplay;
-
- /// <summary>Returns the execution mode of the Lazy object</summary>
- public LazyThreadSafetyMode? Mode => _lazy.Mode;
-
- /// <summary>Returns the execution mode of the Lazy object</summary>
- public bool IsValueFaulted => _lazy.IsValueFaulted;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/LocalAppContextSwitches.Common.cs b/netcore/System.Private.CoreLib/shared/System/LocalAppContextSwitches.Common.cs
deleted file mode 100644
index eb657317e21..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/LocalAppContextSwitches.Common.cs
+++ /dev/null
@@ -1,54 +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 System.Runtime.CompilerServices;
-
-namespace System
-{
- // Helper method for local caching of compatibility quirks. Keep this lean and simple - this file is included into
- // every framework assembly that implements any compatibility quirks.
- internal static partial class LocalAppContextSwitches
- {
- // Returns value of given switch using provided cache.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool GetCachedSwitchValue(string switchName, ref int cachedSwitchValue)
- {
- // The cached switch value has 3 states: 0 - unknown, 1 - true, -1 - false
- if (cachedSwitchValue < 0) return false;
- if (cachedSwitchValue > 0) return true;
-
- return GetCachedSwitchValueInternal(switchName, ref cachedSwitchValue);
- }
-
- private static bool GetCachedSwitchValueInternal(string switchName, ref int cachedSwitchValue)
- {
- bool isSwitchEnabled;
-
- bool hasSwitch = AppContext.TryGetSwitch(switchName, out isSwitchEnabled);
- if (!hasSwitch)
- {
- isSwitchEnabled = GetSwitchDefaultValue(switchName);
- }
-
- AppContext.TryGetSwitch("TestSwitch.LocalAppContext.DisableCaching", out bool disableCaching);
- if (!disableCaching)
- {
- cachedSwitchValue = isSwitchEnabled ? 1 /*true*/ : -1 /*false*/;
- }
-
- return isSwitchEnabled;
- }
-
- // Provides default values for switches if they're not always false by default
- private static bool GetSwitchDefaultValue(string switchName)
- {
- if (switchName == "Switch.System.Runtime.Serialization.SerializationGuard")
- {
- return true;
- }
-
- return false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/LocalAppContextSwitches.cs b/netcore/System.Private.CoreLib/shared/System/LocalAppContextSwitches.cs
deleted file mode 100644
index a8c2b187d15..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/LocalAppContextSwitches.cs
+++ /dev/null
@@ -1,45 +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 System.Runtime.CompilerServices;
-
-namespace System
-{
- internal static partial class LocalAppContextSwitches
- {
- private static int s_enforceJapaneseEraYearRanges;
- public static bool EnforceJapaneseEraYearRanges
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => GetCachedSwitchValue("Switch.System.Globalization.EnforceJapaneseEraYearRanges", ref s_enforceJapaneseEraYearRanges);
- }
-
- private static int s_formatJapaneseFirstYearAsANumber;
- public static bool FormatJapaneseFirstYearAsANumber
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => GetCachedSwitchValue("Switch.System.Globalization.FormatJapaneseFirstYearAsANumber", ref s_formatJapaneseFirstYearAsANumber);
- }
- private static int s_enforceLegacyJapaneseDateParsing;
- public static bool EnforceLegacyJapaneseDateParsing
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => GetCachedSwitchValue("Switch.System.Globalization.EnforceLegacyJapaneseDateParsing", ref s_enforceLegacyJapaneseDateParsing);
- }
-
- private static int s_preserveEventListnerObjectIdentity;
- public static bool PreserveEventListnerObjectIdentity
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => GetCachedSwitchValue("Switch.System.Diagnostics.EventSource.PreserveEventListnerObjectIdentity", ref s_preserveEventListnerObjectIdentity);
- }
-
- private static int s_serializationGuard;
- public static bool SerializationGuard
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => GetCachedSwitchValue("Switch.System.Runtime.Serialization.SerializationGuard", ref s_serializationGuard);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/LocalDataStoreSlot.cs b/netcore/System.Private.CoreLib/shared/System/LocalDataStoreSlot.cs
deleted file mode 100644
index 592b8171d90..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/LocalDataStoreSlot.cs
+++ /dev/null
@@ -1,25 +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 System.Diagnostics.CodeAnalysis;
-using System.Threading;
-
-namespace System
-{
- public sealed class LocalDataStoreSlot
- {
- internal LocalDataStoreSlot(ThreadLocal<object?> data)
- {
- Data = data;
- GC.SuppressFinalize(this);
- }
-
- internal ThreadLocal<object?> Data { get; private set; }
-
- [SuppressMessage("Microsoft.Security", "CA1821", Justification = "Finalizer preserved for compat, it is suppressed by the constructor.")]
- ~LocalDataStoreSlot()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MarshalByRefObject.cs b/netcore/System.Private.CoreLib/shared/System/MarshalByRefObject.cs
deleted file mode 100644
index a083c97c9d7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MarshalByRefObject.cs
+++ /dev/null
@@ -1,33 +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 System.Runtime.InteropServices;
-
-namespace System
-{
- [ClassInterface(ClassInterfaceType.AutoDispatch)]
- [ComVisible(true)]
- public abstract class MarshalByRefObject
- {
- protected MarshalByRefObject()
- {
- }
-
- public object GetLifetimeService()
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_Remoting);
- }
-
- public virtual object InitializeLifetimeService()
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_Remoting);
- }
-
- protected MarshalByRefObject MemberwiseClone(bool cloneIdentity)
- {
- MarshalByRefObject mbr = (MarshalByRefObject)base.MemberwiseClone();
- return mbr;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Marvin.OrdinalIgnoreCase.cs b/netcore/System.Private.CoreLib/shared/System/Marvin.OrdinalIgnoreCase.cs
deleted file mode 100644
index 0f715bb97b5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Marvin.OrdinalIgnoreCase.cs
+++ /dev/null
@@ -1,97 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Text.Unicode;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- internal static partial class Marvin
- {
- /// <summary>
- /// Compute a Marvin OrdinalIgnoreCase hash and collapse it into a 32-bit hash.
- /// n.b. <paramref name="count"/> is specified as char count, not byte count.
- /// </summary>
- public static int ComputeHash32OrdinalIgnoreCase(ref char data, int count, uint p0, uint p1)
- {
- uint ucount = (uint)count; // in chars
- nuint byteOffset = 0; // in bytes
- uint tempValue;
-
- // We operate on 32-bit integers (two chars) at a time.
-
- while (ucount >= 2)
- {
- tempValue = Unsafe.ReadUnaligned<uint>(ref Unsafe.As<char, byte>(ref Unsafe.AddByteOffset(ref data, byteOffset)));
- if (!Utf16Utility.AllCharsInUInt32AreAscii(tempValue))
- {
- goto NotAscii;
- }
- p0 += Utf16Utility.ConvertAllAsciiCharsInUInt32ToUppercase(tempValue);
- Block(ref p0, ref p1);
-
- byteOffset += 4;
- ucount -= 2;
- }
-
- // We have either one char (16 bits) or zero chars left over.
- Debug.Assert(ucount < 2);
-
- if (ucount > 0)
- {
- tempValue = Unsafe.AddByteOffset(ref data, byteOffset);
- if (tempValue > 0x7Fu)
- {
- goto NotAscii;
- }
-
- // addition is written with -0x80u to allow fall-through to next statement rather than jmp past it
- p0 += Utf16Utility.ConvertAllAsciiCharsInUInt32ToUppercase(tempValue) + (0x800000u - 0x80u);
- }
- p0 += 0x80u;
-
- Block(ref p0, ref p1);
- Block(ref p0, ref p1);
-
- return (int)(p1 ^ p0);
-
- NotAscii:
- Debug.Assert(ucount <= int.MaxValue); // this should fit into a signed int
- return ComputeHash32OrdinalIgnoreCaseSlow(ref Unsafe.AddByteOffset(ref data, byteOffset), (int)ucount, p0, p1);
- }
-
- private static int ComputeHash32OrdinalIgnoreCaseSlow(ref char data, int count, uint p0, uint p1)
- {
- Debug.Assert(count > 0);
-
- char[]? borrowedArr = null;
- Span<char> scratch = (uint)count <= 64 ? stackalloc char[64] : (borrowedArr = ArrayPool<char>.Shared.Rent(count));
-
- int charsWritten = new ReadOnlySpan<char>(ref data, count).ToUpperInvariant(scratch);
- Debug.Assert(charsWritten == count); // invariant case conversion should involve simple folding; preserve code unit count
-
- // Slice the array to the size returned by ToUpperInvariant.
- // Multiplication below will not overflow since going from positive Int32 to UInt32.
- int hash = ComputeHash32(ref Unsafe.As<char, byte>(ref MemoryMarshal.GetReference(scratch)), (uint)charsWritten * 2, p0, p1);
-
- // Return the borrowed array if necessary.
- if (borrowedArr != null)
- {
- ArrayPool<char>.Shared.Return(borrowedArr);
- }
-
- return hash;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Marvin.cs b/netcore/System.Private.CoreLib/shared/System/Marvin.cs
deleted file mode 100644
index 67123a77067..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Marvin.cs
+++ /dev/null
@@ -1,256 +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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- internal static partial class Marvin
- {
- /// <summary>
- /// Compute a Marvin hash and collapse it into a 32-bit hash.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int ComputeHash32(ReadOnlySpan<byte> data, ulong seed) => ComputeHash32(ref MemoryMarshal.GetReference(data), (uint)data.Length, (uint)seed, (uint)(seed >> 32));
-
- /// <summary>
- /// Compute a Marvin hash and collapse it into a 32-bit hash.
- /// </summary>
- public static int ComputeHash32(ref byte data, uint count, uint p0, uint p1)
- {
- // Control flow of this method generally flows top-to-bottom, trying to
- // minimize the number of branches taken for large (>= 8 bytes, 4 chars) inputs.
- // If small inputs (< 8 bytes, 4 chars) are given, this jumps to a "small inputs"
- // handler at the end of the method.
-
- if (count < 8)
- {
- // We can't run the main loop, but we might still have 4 or more bytes available to us.
- // If so, jump to the 4 .. 7 bytes logic immediately after the main loop.
-
- if (count >= 4)
- {
- goto Between4And7BytesRemain;
- }
- else
- {
- goto InputTooSmallToEnterMainLoop;
- }
- }
-
- // Main loop - read 8 bytes at a time.
- // The block function is unrolled 2x in this loop.
-
- uint loopCount = count / 8;
- Debug.Assert(loopCount > 0, "Shouldn't reach this code path for small inputs.");
-
- do
- {
- // Most x86 processors have two dispatch ports for reads, so we can read 2x 32-bit
- // values in parallel. We opt for this instead of a single 64-bit read since the
- // typical use case for Marvin32 is computing String hash codes, and the particular
- // layout of String instances means the starting data is never 8-byte aligned when
- // running in a 64-bit process.
-
- p0 += Unsafe.ReadUnaligned<uint>(ref data);
- uint nextUInt32 = Unsafe.ReadUnaligned<uint>(ref Unsafe.AddByteOffset(ref data, 4));
-
- // One block round for each of the 32-bit integers we just read, 2x rounds total.
-
- Block(ref p0, ref p1);
- p0 += nextUInt32;
- Block(ref p0, ref p1);
-
- // Bump the data reference pointer and decrement the loop count.
-
- // Decrementing by 1 every time and comparing against zero allows the JIT to produce
- // better codegen compared to a standard 'for' loop with an incrementing counter.
- // Requires https://github.com/dotnet/coreclr/issues/7566 to be addressed first
- // before we can realize the full benefits of this.
-
- data = ref Unsafe.AddByteOffset(ref data, 8);
- } while (--loopCount > 0);
-
- // n.b. We've not been updating the original 'count' parameter, so its actual value is
- // still the original data length. However, we can still rely on its least significant
- // 3 bits to tell us how much data remains (0 .. 7 bytes) after the loop above is
- // completed.
-
- if ((count & 0b_0100) == 0)
- {
- goto DoFinalPartialRead;
- }
-
- Between4And7BytesRemain:
-
- // If after finishing the main loop we still have 4 or more leftover bytes, or if we had
- // 4 .. 7 bytes to begin with and couldn't enter the loop in the first place, we need to
- // consume 4 bytes immediately and send them through one round of the block function.
-
- Debug.Assert(count >= 4, "Only should've gotten here if the original count was >= 4.");
-
- p0 += Unsafe.ReadUnaligned<uint>(ref data);
- Block(ref p0, ref p1);
-
- DoFinalPartialRead:
-
- // Finally, we have 0 .. 3 bytes leftover. Since we know the original data length was at
- // least 4 bytes (smaller lengths are handled at the end of this routine), we can safely
- // read the 4 bytes at the end of the buffer without reading past the beginning of the
- // original buffer. This necessarily means the data we're about to read will overlap with
- // some data we've already processed, but we can handle that below.
-
- Debug.Assert(count >= 4, "Only should've gotten here if the original count was >= 4.");
-
- // Read the last 4 bytes of the buffer.
-
- uint partialResult = Unsafe.ReadUnaligned<uint>(ref Unsafe.Add(ref Unsafe.AddByteOffset(ref data, (nuint)count & 7), -4));
-
- // The 'partialResult' local above contains any data we have yet to read, plus some number
- // of bytes which we've already read from the buffer. An example of this is given below
- // for little-endian architectures. In this table, AA BB CC are the bytes which we still
- // need to consume, and ## are bytes which we want to throw away since we've already
- // consumed them as part of a previous read.
- //
- // (partialResult contains) (we want it to contain)
- // count mod 4 = 0 -> [ ## ## ## ## | ] -> 0x####_#### -> 0x0000_0080
- // count mod 4 = 1 -> [ ## ## ## ## | AA ] -> 0xAA##_#### -> 0x0000_80AA
- // count mod 4 = 2 -> [ ## ## ## ## | AA BB ] -> 0xBBAA_#### -> 0x0080_BBAA
- // count mod 4 = 3 -> [ ## ## ## ## | AA BB CC ] -> 0xCCBB_AA## -> 0x80CC_BBAA
-
- count = ~count << 3;
-
- if (BitConverter.IsLittleEndian)
- {
- partialResult >>= 8; // make some room for the 0x80 byte
- partialResult |= 0x8000_0000u; // put the 0x80 byte at the beginning
- partialResult >>= (int)count & 0x1F; // shift out all previously consumed bytes
- }
- else
- {
- partialResult <<= 8; // make some room for the 0x80 byte
- partialResult |= 0x80u; // put the 0x80 byte at the end
- partialResult <<= (int)count & 0x1F; // shift out all previously consumed bytes
- }
-
- DoFinalRoundsAndReturn:
-
- // Now that we've computed the final partial result, merge it in and run two rounds of
- // the block function to finish out the Marvin algorithm.
-
- p0 += partialResult;
- Block(ref p0, ref p1);
- Block(ref p0, ref p1);
-
- return (int)(p1 ^ p0);
-
- InputTooSmallToEnterMainLoop:
-
- // We had only 0 .. 3 bytes to begin with, so we can't perform any 32-bit reads.
- // This means that we're going to be building up the final result right away and
- // will only ever run two rounds total of the block function. Let's initialize
- // the partial result to "no data".
-
- if (BitConverter.IsLittleEndian)
- {
- partialResult = 0x80u;
- }
- else
- {
- partialResult = 0x80000000u;
- }
-
- if ((count & 0b_0001) != 0)
- {
- // If the buffer is 1 or 3 bytes in length, let's read a single byte now
- // and merge it into our partial result. This will result in partialResult
- // having one of the two values below, where AA BB CC are the buffer bytes.
- //
- // (little-endian / big-endian)
- // [ AA ] -> 0x0000_80AA / 0xAA80_0000
- // [ AA BB CC ] -> 0x0000_80CC / 0xCC80_0000
-
- partialResult = Unsafe.AddByteOffset(ref data, (nuint)count & 2);
-
- if (BitConverter.IsLittleEndian)
- {
- partialResult |= 0x8000;
- }
- else
- {
- partialResult <<= 24;
- partialResult |= 0x800000u;
- }
- }
-
- if ((count & 0b_0010) != 0)
- {
- // If the buffer is 2 or 3 bytes in length, let's read a single ushort now
- // and merge it into the partial result. This will result in partialResult
- // having one of the two values below, where AA BB CC are the buffer bytes.
- //
- // (little-endian / big-endian)
- // [ AA BB ] -> 0x0080_BBAA / 0xAABB_8000
- // [ AA BB CC ] -> 0x80CC_BBAA / 0xAABB_CC80 (carried over from above)
-
- if (BitConverter.IsLittleEndian)
- {
- partialResult <<= 16;
- partialResult |= (uint)Unsafe.ReadUnaligned<ushort>(ref data);
- }
- else
- {
- partialResult |= (uint)Unsafe.ReadUnaligned<ushort>(ref data);
- partialResult = BitOperations.RotateLeft(partialResult, 16);
- }
- }
-
- // Everything is consumed! Go perform the final rounds and return.
-
- goto DoFinalRoundsAndReturn;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void Block(ref uint rp0, ref uint rp1)
- {
- uint p0 = rp0;
- uint p1 = rp1;
-
- p1 ^= p0;
- p0 = BitOperations.RotateLeft(p0, 20);
-
- p0 += p1;
- p1 = BitOperations.RotateLeft(p1, 9);
-
- p1 ^= p0;
- p0 = BitOperations.RotateLeft(p0, 27);
-
- p0 += p1;
- p1 = BitOperations.RotateLeft(p1, 19);
-
- rp0 = p0;
- rp1 = p1;
- }
-
- public static ulong DefaultSeed { get; } = GenerateSeed();
-
- private static unsafe ulong GenerateSeed()
- {
- ulong seed;
- Interop.GetRandomBytes((byte*)&seed, sizeof(ulong));
- return seed;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Math.cs b/netcore/System.Private.CoreLib/shared/System/Math.cs
deleted file mode 100644
index b418aa4d8cc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Math.cs
+++ /dev/null
@@ -1,1036 +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.
-
-// ===================================================================================================
-// Portions of the code implemented below are based on the 'Berkeley SoftFloat Release 3e' algorithms.
-// ===================================================================================================
-
-/*============================================================
-**
-**
-**
-** Purpose: Some floating-point math operations
-**
-**
-===========================================================*/
-
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- public static partial class Math
- {
- public const double E = 2.7182818284590452354;
-
- public const double PI = 3.14159265358979323846;
-
- private const int maxRoundingDigits = 15;
-
- private const double doubleRoundLimit = 1e16d;
-
- // This table is required for the Round function which can specify the number of digits to round to
- private static readonly double[] roundPower10Double = new double[] {
- 1E0, 1E1, 1E2, 1E3, 1E4, 1E5, 1E6, 1E7, 1E8,
- 1E9, 1E10, 1E11, 1E12, 1E13, 1E14, 1E15
- };
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static short Abs(short value)
- {
- if (value < 0)
- {
- value = (short)-value;
- if (value < 0)
- {
- ThrowAbsOverflow();
- }
- }
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int Abs(int value)
- {
- if (value < 0)
- {
- value = -value;
- if (value < 0)
- {
- ThrowAbsOverflow();
- }
- }
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static long Abs(long value)
- {
- if (value < 0)
- {
- value = -value;
- if (value < 0)
- {
- ThrowAbsOverflow();
- }
- }
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static sbyte Abs(sbyte value)
- {
- if (value < 0)
- {
- value = (sbyte)-value;
- if (value < 0)
- {
- ThrowAbsOverflow();
- }
- }
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static decimal Abs(decimal value)
- {
- return decimal.Abs(value);
- }
-
- [DoesNotReturn]
- [StackTraceHidden]
- private static void ThrowAbsOverflow()
- {
- throw new OverflowException(SR.Overflow_NegateTwosCompNum);
- }
-
- public static long BigMul(int a, int b)
- {
- return ((long)a) * b;
- }
-
- public static double BitDecrement(double x)
- {
- long bits = BitConverter.DoubleToInt64Bits(x);
-
- if (((bits >> 32) & 0x7FF00000) >= 0x7FF00000)
- {
- // NaN returns NaN
- // -Infinity returns -Infinity
- // +Infinity returns double.MaxValue
- return (bits == 0x7FF00000_00000000) ? double.MaxValue : x;
- }
-
- if (bits == 0x00000000_00000000)
- {
- // +0.0 returns -double.Epsilon
- return -double.Epsilon;
- }
-
- // Negative values need to be incremented
- // Positive values need to be decremented
-
- bits += ((bits < 0) ? +1 : -1);
- return BitConverter.Int64BitsToDouble(bits);
- }
-
- public static double BitIncrement(double x)
- {
- long bits = BitConverter.DoubleToInt64Bits(x);
-
- if (((bits >> 32) & 0x7FF00000) >= 0x7FF00000)
- {
- // NaN returns NaN
- // -Infinity returns double.MinValue
- // +Infinity returns +Infinity
- return (bits == unchecked((long)(0xFFF00000_00000000))) ? double.MinValue : x;
- }
-
- if (bits == unchecked((long)(0x80000000_00000000)))
- {
- // -0.0 returns double.Epsilon
- return double.Epsilon;
- }
-
- // Negative values need to be decremented
- // Positive values need to be incremented
-
- bits += ((bits < 0) ? -1 : +1);
- return BitConverter.Int64BitsToDouble(bits);
- }
-
- public static unsafe double CopySign(double x, double y)
- {
- // This method is required to work for all inputs,
- // including NaN, so we operate on the raw bits.
-
- long xbits = BitConverter.DoubleToInt64Bits(x);
- long ybits = BitConverter.DoubleToInt64Bits(y);
-
- // If the sign bits of x and y are not the same,
- // flip the sign bit of x and return the new value;
- // otherwise, just return x
-
- if ((xbits ^ ybits) < 0)
- {
- return BitConverter.Int64BitsToDouble(xbits ^ long.MinValue);
- }
-
- return x;
- }
-
- public static int DivRem(int a, int b, out int result)
- {
- // TODO https://github.com/dotnet/coreclr/issues/3439:
- // Restore to using % and / when the JIT is able to eliminate one of the idivs.
- // In the meantime, a * and - is measurably faster than an extra /.
-
- int div = a / b;
- result = a - (div * b);
- return div;
- }
-
- public static long DivRem(long a, long b, out long result)
- {
- long div = a / b;
- result = a - (div * b);
- return div;
- }
-
- internal static uint DivRem(uint a, uint b, out uint result)
- {
- uint div = a / b;
- result = a - (div * b);
- return div;
- }
-
- internal static ulong DivRem(ulong a, ulong b, out ulong result)
- {
- ulong div = a / b;
- result = a - (div * b);
- return div;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static decimal Ceiling(decimal d)
- {
- return decimal.Ceiling(d);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static byte Clamp(byte value, byte min, byte max)
- {
- if (min > max)
- {
- ThrowMinMaxException(min, max);
- }
-
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
-
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static decimal Clamp(decimal value, decimal min, decimal max)
- {
- if (min > max)
- {
- ThrowMinMaxException(min, max);
- }
-
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
-
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static double Clamp(double value, double min, double max)
- {
- if (min > max)
- {
- ThrowMinMaxException(min, max);
- }
-
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
-
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static short Clamp(short value, short min, short max)
- {
- if (min > max)
- {
- ThrowMinMaxException(min, max);
- }
-
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
-
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int Clamp(int value, int min, int max)
- {
- if (min > max)
- {
- ThrowMinMaxException(min, max);
- }
-
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
-
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static long Clamp(long value, long min, long max)
- {
- if (min > max)
- {
- ThrowMinMaxException(min, max);
- }
-
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
-
- return value;
- }
-
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static sbyte Clamp(sbyte value, sbyte min, sbyte max)
- {
- if (min > max)
- {
- ThrowMinMaxException(min, max);
- }
-
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
-
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Clamp(float value, float min, float max)
- {
- if (min > max)
- {
- ThrowMinMaxException(min, max);
- }
-
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
-
- return value;
- }
-
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ushort Clamp(ushort value, ushort min, ushort max)
- {
- if (min > max)
- {
- ThrowMinMaxException(min, max);
- }
-
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
-
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static uint Clamp(uint value, uint min, uint max)
- {
- if (min > max)
- {
- ThrowMinMaxException(min, max);
- }
-
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
-
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static ulong Clamp(ulong value, ulong min, ulong max)
- {
- if (min > max)
- {
- ThrowMinMaxException(min, max);
- }
-
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
-
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static decimal Floor(decimal d)
- {
- return decimal.Floor(d);
- }
-
- public static double IEEERemainder(double x, double y)
- {
- if (double.IsNaN(x))
- {
- return x; // IEEE 754-2008: NaN payload must be preserved
- }
-
- if (double.IsNaN(y))
- {
- return y; // IEEE 754-2008: NaN payload must be preserved
- }
-
- double regularMod = x % y;
-
- if (double.IsNaN(regularMod))
- {
- return double.NaN;
- }
-
- if ((regularMod == 0) && double.IsNegative(x))
- {
- return double.NegativeZero;
- }
-
- double alternativeResult = (regularMod - (Abs(y) * Sign(x)));
-
- if (Abs(alternativeResult) == Abs(regularMod))
- {
- double divisionResult = x / y;
- double roundedResult = Round(divisionResult);
-
- if (Abs(roundedResult) > Abs(divisionResult))
- {
- return alternativeResult;
- }
- else
- {
- return regularMod;
- }
- }
-
- if (Abs(alternativeResult) < Abs(regularMod))
- {
- return alternativeResult;
- }
- else
- {
- return regularMod;
- }
- }
-
- public static double Log(double a, double newBase)
- {
- if (double.IsNaN(a))
- {
- return a; // IEEE 754-2008: NaN payload must be preserved
- }
-
- if (double.IsNaN(newBase))
- {
- return newBase; // IEEE 754-2008: NaN payload must be preserved
- }
-
- if (newBase == 1)
- {
- return double.NaN;
- }
-
- if ((a != 1) && ((newBase == 0) || double.IsPositiveInfinity(newBase)))
- {
- return double.NaN;
- }
-
- return Log(a) / Log(newBase);
- }
-
- [NonVersionable]
- public static byte Max(byte val1, byte val2)
- {
- return (val1 >= val2) ? val1 : val2;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static decimal Max(decimal val1, decimal val2)
- {
- return decimal.Max(val1, val2);
- }
-
- public static double Max(double val1, double val2)
- {
- // This matches the IEEE 754:2019 `maximum` function
- //
- // It propagates NaN inputs back to the caller and
- // otherwise returns the larger of the inputs. It
- // treats +0 as larger than -0 as per the specification.
-
- if ((val1 > val2) || double.IsNaN(val1))
- {
- return val1;
- }
-
- if (val1 == val2)
- {
- return double.IsNegative(val1) ? val2 : val1;
- }
-
- return val2;
- }
-
- [NonVersionable]
- public static short Max(short val1, short val2)
- {
- return (val1 >= val2) ? val1 : val2;
- }
-
- [NonVersionable]
- public static int Max(int val1, int val2)
- {
- return (val1 >= val2) ? val1 : val2;
- }
-
- [NonVersionable]
- public static long Max(long val1, long val2)
- {
- return (val1 >= val2) ? val1 : val2;
- }
-
- [CLSCompliant(false)]
- [NonVersionable]
- public static sbyte Max(sbyte val1, sbyte val2)
- {
- return (val1 >= val2) ? val1 : val2;
- }
-
- public static float Max(float val1, float val2)
- {
- // This matches the IEEE 754:2019 `maximum` function
- //
- // It propagates NaN inputs back to the caller and
- // otherwise returns the larger of the inputs. It
- // treats +0 as larger than -0 as per the specification.
-
- if ((val1 > val2) || float.IsNaN(val1))
- {
- return val1;
- }
-
- if (val1 == val2)
- {
- return float.IsNegative(val1) ? val2 : val1;
- }
-
- return val2;
- }
-
- [CLSCompliant(false)]
- [NonVersionable]
- public static ushort Max(ushort val1, ushort val2)
- {
- return (val1 >= val2) ? val1 : val2;
- }
-
- [CLSCompliant(false)]
- [NonVersionable]
- public static uint Max(uint val1, uint val2)
- {
- return (val1 >= val2) ? val1 : val2;
- }
-
- [CLSCompliant(false)]
- [NonVersionable]
- public static ulong Max(ulong val1, ulong val2)
- {
- return (val1 >= val2) ? val1 : val2;
- }
-
- public static double MaxMagnitude(double x, double y)
- {
- // This matches the IEEE 754:2019 `maximumMagnitude` function
- //
- // It propagates NaN inputs back to the caller and
- // otherwise returns the input with a larger magnitude.
- // It treats +0 as larger than -0 as per the specification.
-
- double ax = Abs(x);
- double ay = Abs(y);
-
- if ((ax > ay) || double.IsNaN(ax))
- {
- return x;
- }
-
- if (ax == ay)
- {
- return double.IsNegative(x) ? y : x;
- }
-
- return y;
- }
-
- [NonVersionable]
- public static byte Min(byte val1, byte val2)
- {
- return (val1 <= val2) ? val1 : val2;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static decimal Min(decimal val1, decimal val2)
- {
- return decimal.Min(val1, val2);
- }
-
- public static double Min(double val1, double val2)
- {
- // This matches the IEEE 754:2019 `minimum` function
- //
- // It propagates NaN inputs back to the caller and
- // otherwise returns the larger of the inputs. It
- // treats +0 as larger than -0 as per the specification.
-
- if ((val1 < val2) || double.IsNaN(val1))
- {
- return val1;
- }
-
- if (val1 == val2)
- {
- return double.IsNegative(val1) ? val1 : val2;
- }
-
- return val2;
- }
-
- [NonVersionable]
- public static short Min(short val1, short val2)
- {
- return (val1 <= val2) ? val1 : val2;
- }
-
- [NonVersionable]
- public static int Min(int val1, int val2)
- {
- return (val1 <= val2) ? val1 : val2;
- }
-
- [NonVersionable]
- public static long Min(long val1, long val2)
- {
- return (val1 <= val2) ? val1 : val2;
- }
-
- [CLSCompliant(false)]
- [NonVersionable]
- public static sbyte Min(sbyte val1, sbyte val2)
- {
- return (val1 <= val2) ? val1 : val2;
- }
-
- public static float Min(float val1, float val2)
- {
- // This matches the IEEE 754:2019 `minimum` function
- //
- // It propagates NaN inputs back to the caller and
- // otherwise returns the larger of the inputs. It
- // treats +0 as larger than -0 as per the specification.
-
- if ((val1 < val2) || float.IsNaN(val1))
- {
- return val1;
- }
-
- if (val1 == val2)
- {
- return float.IsNegative(val1) ? val1 : val2;
- }
-
- return val2;
- }
-
- [CLSCompliant(false)]
- [NonVersionable]
- public static ushort Min(ushort val1, ushort val2)
- {
- return (val1 <= val2) ? val1 : val2;
- }
-
- [CLSCompliant(false)]
- [NonVersionable]
- public static uint Min(uint val1, uint val2)
- {
- return (val1 <= val2) ? val1 : val2;
- }
-
- [CLSCompliant(false)]
- [NonVersionable]
- public static ulong Min(ulong val1, ulong val2)
- {
- return (val1 <= val2) ? val1 : val2;
- }
-
- public static double MinMagnitude(double x, double y)
- {
- // This matches the IEEE 754:2019 `minimumMagnitude` function
- //
- // It propagates NaN inputs back to the caller and
- // otherwise returns the input with a larger magnitude.
- // It treats +0 as larger than -0 as per the specification.
-
- double ax = Abs(x);
- double ay = Abs(y);
-
- if ((ax < ay) || double.IsNaN(ax))
- {
- return x;
- }
-
- if (ax == ay)
- {
- return double.IsNegative(x) ? x : y;
- }
-
- return y;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static decimal Round(decimal d)
- {
- return decimal.Round(d, 0);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static decimal Round(decimal d, int decimals)
- {
- return decimal.Round(d, decimals);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static decimal Round(decimal d, MidpointRounding mode)
- {
- return decimal.Round(d, 0, mode);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static decimal Round(decimal d, int decimals, MidpointRounding mode)
- {
- return decimal.Round(d, decimals, mode);
- }
-
- [Intrinsic]
- public static double Round(double a)
- {
- // ************************************************************************************
- // IMPORTANT: Do not change this implementation without also updating MathF.Round(float),
- // FloatingPointUtils::round(double), and FloatingPointUtils::round(float)
- // ************************************************************************************
-
- // This is based on the 'Berkeley SoftFloat Release 3e' algorithm
-
- ulong bits = (ulong)BitConverter.DoubleToInt64Bits(a);
- int exponent = double.ExtractExponentFromBits(bits);
-
- if (exponent <= 0x03FE)
- {
- if ((bits << 1) == 0)
- {
- // Exactly +/- zero should return the original value
- return a;
- }
-
- // Any value less than or equal to 0.5 will always round to exactly zero
- // and any value greater than 0.5 will always round to exactly one. However,
- // we need to preserve the original sign for IEEE compliance.
-
- double result = ((exponent == 0x03FE) && (double.ExtractSignificandFromBits(bits) != 0)) ? 1.0 : 0.0;
- return CopySign(result, a);
- }
-
- if (exponent >= 0x0433)
- {
- // Any value greater than or equal to 2^52 cannot have a fractional part,
- // So it will always round to exactly itself.
-
- return a;
- }
-
- // The absolute value should be greater than or equal to 1.0 and less than 2^52
- Debug.Assert((0x03FF <= exponent) && (exponent <= 0x0432));
-
- // Determine the last bit that represents the integral portion of the value
- // and the bits representing the fractional portion
-
- ulong lastBitMask = 1UL << (0x0433 - exponent);
- ulong roundBitsMask = lastBitMask - 1;
-
- // Increment the first fractional bit, which represents the midpoint between
- // two integral values in the current window.
-
- bits += lastBitMask >> 1;
-
- if ((bits & roundBitsMask) == 0)
- {
- // If that overflowed and the rest of the fractional bits are zero
- // then we were exactly x.5 and we want to round to the even result
-
- bits &= ~lastBitMask;
- }
- else
- {
- // Otherwise, we just want to strip the fractional bits off, truncating
- // to the current integer value.
-
- bits &= ~roundBitsMask;
- }
-
- return BitConverter.Int64BitsToDouble((long)bits);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static double Round(double value, int digits)
- {
- return Round(value, digits, MidpointRounding.ToEven);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static double Round(double value, MidpointRounding mode)
- {
- return Round(value, 0, mode);
- }
-
- public static unsafe double Round(double value, int digits, MidpointRounding mode)
- {
- if ((digits < 0) || (digits > maxRoundingDigits))
- {
- throw new ArgumentOutOfRangeException(nameof(digits), SR.ArgumentOutOfRange_RoundingDigits);
- }
-
- if (mode < MidpointRounding.ToEven || mode > MidpointRounding.ToPositiveInfinity)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, nameof(MidpointRounding)), nameof(mode));
- }
-
- if (Abs(value) < doubleRoundLimit)
- {
- double power10 = roundPower10Double[digits];
-
- value *= power10;
-
- switch (mode)
- {
- // Rounds to the nearest value; if the number falls midway,
- // it is rounded to the nearest value with an even least significant digit
- case MidpointRounding.ToEven:
- {
- value = Round(value);
- break;
- }
- // Rounds to the nearest value; if the number falls midway,
- // it is rounded to the nearest value above (for positive numbers) or below (for negative numbers)
- case MidpointRounding.AwayFromZero:
- {
- double fraction = ModF(value, &value);
-
- if (Abs(fraction) >= 0.5)
- {
- value += Sign(fraction);
- }
-
- break;
- }
- // Directed rounding: Round to the nearest value, toward to zero
- case MidpointRounding.ToZero:
- {
- value = Truncate(value);
- break;
- }
- // Directed Rounding: Round down to the next value, toward negative infinity
- case MidpointRounding.ToNegativeInfinity:
- {
- value = Floor(value);
- break;
- }
- // Directed rounding: Round up to the next value, toward positive infinity
- case MidpointRounding.ToPositiveInfinity:
- {
- value = Ceiling(value);
- break;
- }
- default:
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, nameof(MidpointRounding)), nameof(mode));
- }
- }
-
- value /= power10;
- }
-
- return value;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int Sign(decimal value)
- {
- return decimal.Sign(value);
- }
-
- public static int Sign(double value)
- {
- if (value < 0)
- {
- return -1;
- }
- else if (value > 0)
- {
- return 1;
- }
- else if (value == 0)
- {
- return 0;
- }
-
- throw new ArithmeticException(SR.Arithmetic_NaN);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int Sign(short value)
- {
- return Sign((int)value);
- }
-
- public static int Sign(int value)
- {
- return unchecked(value >> 31 | (int)((uint)-value >> 31));
- }
-
- public static int Sign(long value)
- {
- return unchecked((int)(value >> 63 | (long)((ulong)-value >> 63)));
- }
-
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int Sign(sbyte value)
- {
- return Sign((int)value);
- }
-
- public static int Sign(float value)
- {
- if (value < 0)
- {
- return -1;
- }
- else if (value > 0)
- {
- return 1;
- }
- else if (value == 0)
- {
- return 0;
- }
-
- throw new ArithmeticException(SR.Arithmetic_NaN);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static decimal Truncate(decimal d)
- {
- return decimal.Truncate(d);
- }
-
- public static unsafe double Truncate(double d)
- {
- ModF(d, &d);
- return d;
- }
-
- [DoesNotReturn]
- private static void ThrowMinMaxException<T>(T min, T max)
- {
- throw new ArgumentException(SR.Format(SR.Argument_MinMaxValue, min, max));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MathF.cs b/netcore/System.Private.CoreLib/shared/System/MathF.cs
deleted file mode 100644
index 5d7de839590..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MathF.cs
+++ /dev/null
@@ -1,410 +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.
-
-// ===================================================================================================
-// Portions of the code implemented below are based on the 'Berkeley SoftFloat Release 3e' algorithms.
-// ===================================================================================================
-
-/*============================================================
-**
-** Purpose: Some single-precision floating-point math operations
-**
-===========================================================*/
-
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- public static partial class MathF
- {
- public const float E = 2.71828183f;
-
- public const float PI = 3.14159265f;
-
- private const int maxRoundingDigits = 6;
-
- // This table is required for the Round function which can specify the number of digits to round to
- private static readonly float[] roundPower10Single = new float[] {
- 1e0f, 1e1f, 1e2f, 1e3f, 1e4f, 1e5f, 1e6f
- };
-
- private const float singleRoundLimit = 1e8f;
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Abs(float x)
- {
- return Math.Abs(x);
- }
-
- public static float BitDecrement(float x)
- {
- int bits = BitConverter.SingleToInt32Bits(x);
-
- if ((bits & 0x7F800000) >= 0x7F800000)
- {
- // NaN returns NaN
- // -Infinity returns -Infinity
- // +Infinity returns float.MaxValue
- return (bits == 0x7F800000) ? float.MaxValue : x;
- }
-
- if (bits == 0x00000000)
- {
- // +0.0 returns -float.Epsilon
- return -float.Epsilon;
- }
-
- // Negative values need to be incremented
- // Positive values need to be decremented
-
- bits += ((bits < 0) ? +1 : -1);
- return BitConverter.Int32BitsToSingle(bits);
- }
-
- public static float BitIncrement(float x)
- {
- int bits = BitConverter.SingleToInt32Bits(x);
-
- if ((bits & 0x7F800000) >= 0x7F800000)
- {
- // NaN returns NaN
- // -Infinity returns float.MinValue
- // +Infinity returns +Infinity
- return (bits == unchecked((int)(0xFF800000))) ? float.MinValue : x;
- }
-
- if (bits == unchecked((int)(0x80000000)))
- {
- // -0.0 returns float.Epsilon
- return float.Epsilon;
- }
-
- // Negative values need to be decremented
- // Positive values need to be incremented
-
- bits += ((bits < 0) ? -1 : +1);
- return BitConverter.Int32BitsToSingle(bits);
- }
-
- public static unsafe float CopySign(float x, float y)
- {
- // This method is required to work for all inputs,
- // including NaN, so we operate on the raw bits.
-
- int xbits = BitConverter.SingleToInt32Bits(x);
- int ybits = BitConverter.SingleToInt32Bits(y);
-
- // If the sign bits of x and y are not the same,
- // flip the sign bit of x and return the new value;
- // otherwise, just return x
-
- if ((xbits ^ ybits) < 0)
- {
- return BitConverter.Int32BitsToSingle(xbits ^ int.MinValue);
- }
-
- return x;
- }
-
- public static float IEEERemainder(float x, float y)
- {
- if (float.IsNaN(x))
- {
- return x; // IEEE 754-2008: NaN payload must be preserved
- }
-
- if (float.IsNaN(y))
- {
- return y; // IEEE 754-2008: NaN payload must be preserved
- }
-
- float regularMod = x % y;
-
- if (float.IsNaN(regularMod))
- {
- return float.NaN;
- }
-
- if ((regularMod == 0) && float.IsNegative(x))
- {
- return float.NegativeZero;
- }
-
- float alternativeResult = (regularMod - (Abs(y) * Sign(x)));
-
- if (Abs(alternativeResult) == Abs(regularMod))
- {
- float divisionResult = x / y;
- float roundedResult = Round(divisionResult);
-
- if (Abs(roundedResult) > Abs(divisionResult))
- {
- return alternativeResult;
- }
- else
- {
- return regularMod;
- }
- }
-
- if (Abs(alternativeResult) < Abs(regularMod))
- {
- return alternativeResult;
- }
- else
- {
- return regularMod;
- }
- }
-
- public static float Log(float x, float y)
- {
- if (float.IsNaN(x))
- {
- return x; // IEEE 754-2008: NaN payload must be preserved
- }
-
- if (float.IsNaN(y))
- {
- return y; // IEEE 754-2008: NaN payload must be preserved
- }
-
- if (y == 1)
- {
- return float.NaN;
- }
-
- if ((x != 1) && ((y == 0) || float.IsPositiveInfinity(y)))
- {
- return float.NaN;
- }
-
- return Log(x) / Log(y);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Max(float x, float y)
- {
- return Math.Max(x, y);
- }
-
- public static float MaxMagnitude(float x, float y)
- {
- // This matches the IEEE 754:2019 `maximumMagnitude` function
- //
- // It propagates NaN inputs back to the caller and
- // otherwise returns the input with a larger magnitude.
- // It treats +0 as larger than -0 as per the specification.
-
- float ax = Abs(x);
- float ay = Abs(y);
-
- if ((ax > ay) || float.IsNaN(ax))
- {
- return x;
- }
-
- if (ax == ay)
- {
- return float.IsNegative(x) ? y : x;
- }
-
- return y;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Min(float x, float y)
- {
- return Math.Min(x, y);
- }
-
- public static float MinMagnitude(float x, float y)
- {
- // This matches the IEEE 754:2019 `minimumMagnitude` function
- //
- // It propagates NaN inputs back to the caller and
- // otherwise returns the input with a larger magnitude.
- // It treats +0 as larger than -0 as per the specification.
-
- float ax = Abs(x);
- float ay = Abs(y);
-
- if ((ax < ay) || float.IsNaN(ax))
- {
- return x;
- }
-
- if (ax == ay)
- {
- return float.IsNegative(x) ? x : y;
- }
-
- return y;
- }
-
- [Intrinsic]
- public static float Round(float x)
- {
- // ************************************************************************************
- // IMPORTANT: Do not change this implementation without also updating MathF.Round(float),
- // FloatingPointUtils::round(double), and FloatingPointUtils::round(float)
- // ************************************************************************************
-
- // This is based on the 'Berkeley SoftFloat Release 3e' algorithm
-
- uint bits = (uint)BitConverter.SingleToInt32Bits(x);
- int exponent = float.ExtractExponentFromBits(bits);
-
- if (exponent <= 0x7E)
- {
- if ((bits << 1) == 0)
- {
- // Exactly +/- zero should return the original value
- return x;
- }
-
- // Any value less than or equal to 0.5 will always round to exactly zero
- // and any value greater than 0.5 will always round to exactly one. However,
- // we need to preserve the original sign for IEEE compliance.
-
- float result = ((exponent == 0x7E) && (float.ExtractSignificandFromBits(bits) != 0)) ? 1.0f : 0.0f;
- return CopySign(result, x);
- }
-
- if (exponent >= 0x96)
- {
- // Any value greater than or equal to 2^23 cannot have a fractional part,
- // So it will always round to exactly itself.
-
- return x;
- }
-
- // The absolute value should be greater than or equal to 1.0 and less than 2^23
- Debug.Assert((0x7F <= exponent) && (exponent <= 0x95));
-
- // Determine the last bit that represents the integral portion of the value
- // and the bits representing the fractional portion
-
- uint lastBitMask = 1U << (0x96 - exponent);
- uint roundBitsMask = lastBitMask - 1;
-
- // Increment the first fractional bit, which represents the midpoint between
- // two integral values in the current window.
-
- bits += lastBitMask >> 1;
-
- if ((bits & roundBitsMask) == 0)
- {
- // If that overflowed and the rest of the fractional bits are zero
- // then we were exactly x.5 and we want to round to the even result
-
- bits &= ~lastBitMask;
- }
- else
- {
- // Otherwise, we just want to strip the fractional bits off, truncating
- // to the current integer value.
-
- bits &= ~roundBitsMask;
- }
-
- return BitConverter.Int32BitsToSingle((int)bits);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Round(float x, int digits)
- {
- return Round(x, digits, MidpointRounding.ToEven);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Round(float x, MidpointRounding mode)
- {
- return Round(x, 0, mode);
- }
-
- public static unsafe float Round(float x, int digits, MidpointRounding mode)
- {
- if ((digits < 0) || (digits > maxRoundingDigits))
- {
- throw new ArgumentOutOfRangeException(nameof(digits), SR.ArgumentOutOfRange_RoundingDigits);
- }
-
- if (mode < MidpointRounding.ToEven || mode > MidpointRounding.ToPositiveInfinity)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, nameof(MidpointRounding)), nameof(mode));
- }
-
- if (Abs(x) < singleRoundLimit)
- {
- float power10 = roundPower10Single[digits];
-
- x *= power10;
-
- switch (mode)
- {
- // Rounds to the nearest value; if the number falls midway,
- // it is rounded to the nearest value with an even least significant digit
- case MidpointRounding.ToEven:
- {
- x = Round(x);
- break;
- }
- // Rounds to the nearest value; if the number falls midway,
- // it is rounded to the nearest value above (for positive numbers) or below (for negative numbers)
- case MidpointRounding.AwayFromZero:
- {
- float fraction = ModF(x, &x);
-
- if (Abs(fraction) >= 0.5)
- {
- x += Sign(fraction);
- }
-
- break;
- }
- // Directed rounding: Round to the nearest value, toward to zero
- case MidpointRounding.ToZero:
- {
- x = Truncate(x);
- break;
- }
- // Directed Rounding: Round down to the next value, toward negative infinity
- case MidpointRounding.ToNegativeInfinity:
- {
- x = Floor(x);
- break;
- }
- // Directed rounding: Round up to the next value, toward positive infinity
- case MidpointRounding.ToPositiveInfinity:
- {
- x = Ceiling(x);
- break;
- }
- default:
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, nameof(MidpointRounding)), nameof(mode));
- }
- }
-
- x /= power10;
- }
-
- return x;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int Sign(float x)
- {
- return Math.Sign(x);
- }
-
- public static unsafe float Truncate(float x)
- {
- ModF(x, &x);
- return x;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MemberAccessException.cs b/netcore/System.Private.CoreLib/shared/System/MemberAccessException.cs
deleted file mode 100644
index a3ccdbe83dd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MemberAccessException.cs
+++ /dev/null
@@ -1,50 +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.
-
-////////////////////////////////////////////////////////////////////////////////
-// MemberAccessException
-// Thrown when we try accessing a member that we cannot
-// access, due to it being removed, private or something similar.
-////////////////////////////////////////////////////////////////////////////////
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- // The MemberAccessException is thrown when trying to access a class
- // member fails.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class MemberAccessException : SystemException
- {
- // Creates a new MemberAccessException with its message string set to
- // the empty string, its HRESULT set to COR_E_MEMBERACCESS,
- // and its ExceptionInfo reference set to null.
- public MemberAccessException()
- : base(SR.Arg_AccessException)
- {
- HResult = HResults.COR_E_MEMBERACCESS;
- }
-
- // Creates a new MemberAccessException with its message string set to
- // message, its HRESULT set to COR_E_ACCESS,
- // and its ExceptionInfo reference set to null.
- //
- public MemberAccessException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_MEMBERACCESS;
- }
-
- public MemberAccessException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_MEMBERACCESS;
- }
-
- protected MemberAccessException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Memory.cs b/netcore/System.Private.CoreLib/shared/System/Memory.cs
deleted file mode 100644
index bc437644c1f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Memory.cs
+++ /dev/null
@@ -1,517 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-using EditorBrowsableAttribute = System.ComponentModel.EditorBrowsableAttribute;
-using EditorBrowsableState = System.ComponentModel.EditorBrowsableState;
-
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else // BIT64
-using nuint = System.UInt32;
-#endif // BIT64
-
-namespace System
-{
- /// <summary>
- /// Memory represents a contiguous region of arbitrary memory similar to <see cref="Span{T}"/>.
- /// Unlike <see cref="Span{T}"/>, it is not a byref-like type.
- /// </summary>
- [DebuggerTypeProxy(typeof(MemoryDebugView<>))]
- [DebuggerDisplay("{ToString(),raw}")]
- 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.
-
- // The highest order bit of _index is used to discern whether _object is a pre-pinned array.
- // (_index < 0) => _object is a pre-pinned array, so Pin() will not allocate a new GCHandle
- // (else) => Pin() needs to allocate a new GCHandle to pin the object.
- private readonly object? _object;
- private readonly int _index;
- private readonly int _length;
-
- /// <summary>
- /// Creates a new memory over the entirety of the target array.
- /// </summary>
- /// <param name="array">The target array.</param>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Memory(T[]? array)
- {
- if (array == null)
- {
- this = default;
- return; // returns default
- }
- if (default(T)! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- ThrowHelper.ThrowArrayTypeMismatchException();
-
- _object = array;
- _index = 0;
- _length = array.Length;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal Memory(T[]? array, int start)
- {
- if (array == null)
- {
- if (start != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
- this = default;
- return; // returns default
- }
- if (default(T)! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- ThrowHelper.ThrowArrayTypeMismatchException();
- if ((uint)start > (uint)array.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- _object = array;
- _index = start;
- _length = array.Length - start;
- }
-
- /// <summary>
- /// Creates a new memory over the portion of the target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="array">The target array.</param>
- /// <param name="start">The index at which to begin the memory.</param>
- /// <param name="length">The number of items in the memory.</param>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Memory(T[]? array, int start, int length)
- {
- if (array == null)
- {
- if (start != 0 || length != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
- this = default;
- return; // returns default
- }
- if (default(T)! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- ThrowHelper.ThrowArrayTypeMismatchException();
-#if BIT64
- // See comment in Span<T>.Slice for how this works.
- if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)array.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#else
- if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#endif
-
- _object = array;
- _index = start;
- _length = length;
- }
-
- /// <summary>
- /// Creates a new memory from a memory manager that provides specific method implementations beginning
- /// at 0 index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="manager">The memory manager.</param>
- /// <param name="length">The number of items in the memory.</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="length"/> is negative.
- /// </exception>
- /// <remarks>For internal infrastructure only</remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal Memory(MemoryManager<T> manager, int length)
- {
- Debug.Assert(manager != null);
-
- if (length < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- _object = manager;
- _index = 0;
- _length = length;
- }
-
- /// <summary>
- /// Creates a new memory from a memory manager that provides specific method implementations beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="manager">The memory manager.</param>
- /// <param name="start">The index at which to begin the memory.</param>
- /// <param name="length">The number of items in the memory.</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or <paramref name="length"/> is negative.
- /// </exception>
- /// <remarks>For internal infrastructure only</remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal Memory(MemoryManager<T> manager, int start, int length)
- {
- Debug.Assert(manager != null);
-
- if (length < 0 || start < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- _object = manager;
- _index = start;
- _length = length;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal Memory(object? obj, int start, int length)
- {
- // No validation performed in release builds; caller must provide any necessary validation.
-
- // 'obj is T[]' below also handles things like int[] <-> uint[] being convertible
- Debug.Assert((obj == null)
- || (typeof(T) == typeof(char) && obj is string)
-#if FEATURE_UTF8STRING
- || ((typeof(T) == typeof(byte) || typeof(T) == typeof(Char8)) && obj is Utf8String)
-#endif // FEATURE_UTF8STRING
- || (obj is T[])
- || (obj is MemoryManager<T>));
-
- _object = obj;
- _index = start;
- _length = length;
- }
-
- /// <summary>
- /// Defines an implicit conversion of an array to a <see cref="Memory{T}"/>
- /// </summary>
- public static implicit operator Memory<T>(T[]? array) => new Memory<T>(array);
-
- /// <summary>
- /// Defines an implicit conversion of a <see cref="ArraySegment{T}"/> to a <see cref="Memory{T}"/>
- /// </summary>
- public static implicit operator Memory<T>(ArraySegment<T> segment) => new Memory<T>(segment.Array, segment.Offset, segment.Count);
-
- /// <summary>
- /// Defines an implicit conversion of a <see cref="Memory{T}"/> to a <see cref="ReadOnlyMemory{T}"/>
- /// </summary>
- public static implicit operator ReadOnlyMemory<T>(Memory<T> memory) =>
- Unsafe.As<Memory<T>, ReadOnlyMemory<T>>(ref memory);
-
- /// <summary>
- /// Returns an empty <see cref="Memory{T}"/>
- /// </summary>
- public static Memory<T> Empty => default;
-
- /// <summary>
- /// The number of items in the memory.
- /// </summary>
- public int Length => _length;
-
- /// <summary>
- /// Returns true if Length is 0.
- /// </summary>
- public bool IsEmpty => _length == 0;
-
- /// <summary>
- /// For <see cref="Memory{Char}"/>, returns a new instance of string that represents the characters pointed to by the memory.
- /// Otherwise, returns a <see cref="string"/> with the name of the type and the number of elements.
- /// </summary>
- public override string ToString()
- {
- if (typeof(T) == typeof(char))
- {
- return (_object is string str) ? str.Substring(_index, _length) : Span.ToString();
- }
-#if FEATURE_UTF8STRING
- else if (typeof(T) == typeof(Char8))
- {
- // TODO_UTF8STRING: Call into optimized transcoding routine when it's available.
- Span<T> span = Span;
- return Encoding.UTF8.GetString(new ReadOnlySpan<byte>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length));
- }
-#endif // FEATURE_UTF8STRING
- return string.Format("System.Memory<{0}>[{1}]", typeof(T).Name, _length);
- }
-
- /// <summary>
- /// Forms a slice out of the given memory, beginning at 'start'.
- /// </summary>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> index is not in range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Memory<T> Slice(int start)
- {
- if ((uint)start > (uint)_length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
- }
-
- // It is expected for _index + start to be negative if the memory is already pre-pinned.
- return new Memory<T>(_object, _index + start, _length - start);
- }
-
- /// <summary>
- /// Forms a slice out of the given memory, beginning at 'start', of given length
- /// </summary>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <param name="length">The desired length for the slice (exclusive).</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Memory<T> Slice(int start, int length)
- {
-#if BIT64
- // See comment in Span<T>.Slice for how this works.
- if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)_length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#else
- if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#endif
-
- // It is expected for _index + start to be negative if the memory is already pre-pinned.
- return new Memory<T>(_object, _index + start, length);
- }
-
- /// <summary>
- /// Returns a span from the memory.
- /// </summary>
- public unsafe Span<T> Span
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- // This property getter has special support for returning a mutable Span<char> that wraps
- // an immutable String instance. This is obviously a dangerous feature and breaks type safety.
- // However, we need to handle the case where a ReadOnlyMemory<char> was created from a string
- // and then cast to a Memory<T>. Such a cast can only be done with unsafe or marshaling code,
- // in which case that's the dangerous operation performed by the dev, and we're just following
- // suit here to make it work as best as possible.
-
- ref T refToReturn = ref Unsafe.NullRef<T>();
- int lengthOfUnderlyingSpan = 0;
-
- // Copy this field into a local so that it can't change out from under us mid-operation.
-
- object? tmpObject = _object;
- if (tmpObject != null)
- {
- if (typeof(T) == typeof(char) && tmpObject.GetType() == typeof(string))
- {
- // Special-case string since it's the most common for ROM<char>.
-
- refToReturn = ref Unsafe.As<char, T>(ref Unsafe.As<string>(tmpObject).GetRawStringData());
- lengthOfUnderlyingSpan = Unsafe.As<string>(tmpObject).Length;
- }
-#if FEATURE_UTF8STRING
- else if ((typeof(T) == typeof(byte) || typeof(T) == typeof(Char8)) && tmpObject.GetType() == typeof(Utf8String))
- {
- refToReturn = ref Unsafe.As<byte, T>(ref Unsafe.As<Utf8String>(tmpObject).DangerousGetMutableReference());
- lengthOfUnderlyingSpan = Unsafe.As<Utf8String>(tmpObject).Length;
- }
-#endif // FEATURE_UTF8STRING
- else if (RuntimeHelpers.ObjectHasComponentSize(tmpObject))
- {
- // We know the object is not null, it's not a string, and it is variable-length. The only
- // remaining option is for it to be a T[] (or a U[] which is blittable to T[], like int[]
- // and uint[]). Otherwise somebody used private reflection to set this field, and we're not
- // too worried about type safety violations at this point.
-
- // 'tmpObject is T[]' below also handles things like int[] <-> uint[] being convertible
- Debug.Assert(tmpObject is T[]);
-
- refToReturn = ref Unsafe.As<byte, T>(ref Unsafe.As<T[]>(tmpObject).GetRawSzArrayData());
- lengthOfUnderlyingSpan = Unsafe.As<T[]>(tmpObject).Length;
- }
- else
- {
- // We know the object is not null, and it's not variable-length, so it must be a MemoryManager<T>.
- // Otherwise somebody used private reflection to set this field, and we're not too worried about
- // type safety violations at that point. Note that it can't be a MemoryManager<U>, even if U and
- // T are blittable (e.g., MemoryManager<int> to MemoryManager<uint>), since there exists no
- // constructor or other public API which would allow such a conversion.
-
- Debug.Assert(tmpObject is MemoryManager<T>);
- Span<T> memoryManagerSpan = Unsafe.As<MemoryManager<T>>(tmpObject).GetSpan();
- refToReturn = ref MemoryMarshal.GetReference(memoryManagerSpan);
- lengthOfUnderlyingSpan = memoryManagerSpan.Length;
- }
-
- // If the Memory<T> or ReadOnlyMemory<T> instance is torn, this property getter has undefined behavior.
- // We try to detect this condition and throw an exception, but it's possible that a torn struct might
- // appear to us to be valid, and we'll return an undesired span. Such a span is always guaranteed at
- // least to be in-bounds when compared with the original Memory<T> instance, so using the span won't
- // AV the process.
-
- nuint desiredStartIndex = (uint)_index & (uint)ReadOnlyMemory<T>.RemoveFlagsBitMask;
- int desiredLength = _length;
-
-#if BIT64
- // See comment in Span<T>.Slice for how this works.
- if ((ulong)desiredStartIndex + (ulong)(uint)desiredLength > (ulong)(uint)lengthOfUnderlyingSpan)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException();
- }
-#else
- if ((uint)desiredStartIndex > (uint)lengthOfUnderlyingSpan || (uint)desiredLength > (uint)(lengthOfUnderlyingSpan - desiredStartIndex))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException();
- }
-#endif
-
- refToReturn = ref Unsafe.Add(ref refToReturn, (IntPtr)(void*)desiredStartIndex);
- lengthOfUnderlyingSpan = desiredLength;
- }
-
- return new Span<T>(ref refToReturn, lengthOfUnderlyingSpan);
- }
- }
-
- /// <summary>
- /// Copies the contents of the memory into the destination. If the source
- /// and destination overlap, this method behaves as if the original values are in
- /// a temporary location before the destination is overwritten.
- ///
- /// <param name="destination">The Memory to copy items into.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when the destination is shorter than the source.
- /// </exception>
- /// </summary>
- public void CopyTo(Memory<T> destination) => Span.CopyTo(destination.Span);
-
- /// <summary>
- /// Copies the contents of the memory into the destination. If the source
- /// and destination overlap, this method behaves as if the original values are in
- /// a temporary location before the destination is overwritten.
- ///
- /// <returns>If the destination is shorter than the source, this method
- /// return false and no data is written to the destination.</returns>
- /// </summary>
- /// <param name="destination">The span to copy items into.</param>
- public bool TryCopyTo(Memory<T> destination) => Span.TryCopyTo(destination.Span);
-
- /// <summary>
- /// Creates a handle for the memory.
- /// The GC will not move the memory until the returned <see cref="MemoryHandle"/>
- /// is disposed, enabling taking and using the memory's address.
- /// <exception cref="System.ArgumentException">
- /// An instance with nonprimitive (non-blittable) members cannot be pinned.
- /// </exception>
- /// </summary>
- public unsafe MemoryHandle Pin()
- {
- // Just like the Span property getter, we have special support for a mutable Memory<char>
- // that wraps an immutable String instance. This might happen if a caller creates an
- // immutable ROM<char> wrapping a String, then uses Unsafe.As to create a mutable M<char>.
- // This needs to work, however, so that code that uses a single Memory<char> field to store either
- // a readable ReadOnlyMemory<char> or a writable Memory<char> can still be pinned and
- // used for interop purposes.
-
- // It's possible that the below logic could result in an AV if the struct
- // is torn. This is ok since the caller is expecting to use raw pointers,
- // and we're not required to keep this as safe as the other Span-based APIs.
-
- object? tmpObject = _object;
- if (tmpObject != null)
- {
- if (typeof(T) == typeof(char) && tmpObject is string s)
- {
- GCHandle handle = GCHandle.Alloc(tmpObject, GCHandleType.Pinned);
- ref char stringData = ref Unsafe.Add(ref s.GetRawStringData(), _index);
- return new MemoryHandle(Unsafe.AsPointer(ref stringData), handle);
- }
-#if FEATURE_UTF8STRING
- else if ((typeof(T) == typeof(byte) || typeof(T) == typeof(Char8)) && tmpObject is Utf8String utf8String)
- {
- GCHandle handle = GCHandle.Alloc(tmpObject, GCHandleType.Pinned);
- ref byte stringData = ref utf8String.DangerousGetMutableReference(_index);
- return new MemoryHandle(Unsafe.AsPointer(ref stringData), handle);
- }
-#endif // FEATURE_UTF8STRING
- else if (RuntimeHelpers.ObjectHasComponentSize(tmpObject))
- {
- // 'tmpObject is T[]' below also handles things like int[] <-> uint[] being convertible
- Debug.Assert(tmpObject is T[]);
-
- // Array is already pre-pinned
- if (_index < 0)
- {
- void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref Unsafe.As<T[]>(tmpObject).GetRawSzArrayData()), _index & ReadOnlyMemory<T>.RemoveFlagsBitMask);
- return new MemoryHandle(pointer);
- }
- else
- {
- GCHandle handle = GCHandle.Alloc(tmpObject, GCHandleType.Pinned);
- void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref Unsafe.As<T[]>(tmpObject).GetRawSzArrayData()), _index);
- return new MemoryHandle(pointer, handle);
- }
- }
- else
- {
- Debug.Assert(tmpObject is MemoryManager<T>);
- return Unsafe.As<MemoryManager<T>>(tmpObject).Pin(_index);
- }
- }
-
- return default;
- }
-
- /// <summary>
- /// Copies the contents from the memory into a new array. This heap
- /// allocates, so should generally be avoided, however it is sometimes
- /// necessary to bridge the gap with APIs written in terms of arrays.
- /// </summary>
- public T[] ToArray() => Span.ToArray();
-
- /// <summary>
- /// Determines whether the specified object is equal to the current object.
- /// Returns true if the object is Memory or ReadOnlyMemory and if both objects point to the same array and have the same length.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override bool Equals(object? obj)
- {
- if (obj is ReadOnlyMemory<T>)
- {
- return ((ReadOnlyMemory<T>)obj).Equals(this);
- }
- else if (obj is Memory<T> memory)
- {
- return Equals(memory);
- }
- else
- {
- return false;
- }
- }
-
- /// <summary>
- /// Returns true if the memory points to the same array and has the same length. Note that
- /// this does *not* check to see if the *contents* are equal.
- /// </summary>
- public bool Equals(Memory<T> other)
- {
- return
- _object == other._object &&
- _index == other._index &&
- _length == other._length;
- }
-
- /// <summary>
- /// Serves as the default hash function.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override int GetHashCode()
- {
- // We use RuntimeHelpers.GetHashCode instead of Object.GetHashCode because the hash
- // code is based on object identity and referential equality, not deep equality (as common with string).
- return (_object != null) ? HashCode.Combine(RuntimeHelpers.GetHashCode(_object), _index, _length) : 0;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MemoryDebugView.cs b/netcore/System.Private.CoreLib/shared/System/MemoryDebugView.cs
deleted file mode 100644
index 6ab6e5065cf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MemoryDebugView.cs
+++ /dev/null
@@ -1,26 +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 System.Diagnostics;
-
-namespace System
-{
- internal sealed class MemoryDebugView<T>
- {
- private readonly ReadOnlyMemory<T> _memory;
-
- public MemoryDebugView(Memory<T> memory)
- {
- _memory = memory;
- }
-
- public MemoryDebugView(ReadOnlyMemory<T> memory)
- {
- _memory = memory;
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public T[] Items => _memory.ToArray();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Globalization.cs b/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Globalization.cs
deleted file mode 100644
index 5bcdf8295ce..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Globalization.cs
+++ /dev/null
@@ -1,416 +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 System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System
-{
- public static partial class MemoryExtensions
- {
- /// <summary>
- /// Indicates whether the specified span contains only white-space characters.
- /// </summary>
- public static bool IsWhiteSpace(this ReadOnlySpan<char> span)
- {
- for (int i = 0; i < span.Length; i++)
- {
- if (!char.IsWhiteSpace(span[i]))
- return false;
- }
- return true;
- }
-
- /// <summary>
- /// Returns a value indicating whether the specified <paramref name="value"/> occurs within the <paramref name="span"/>.
- /// <param name="span">The source span.</param>
- /// <param name="value">The value to seek within the source span.</param>
- /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param>
- /// </summary>
- public static bool Contains(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
- {
- return IndexOf(span, value, comparisonType) >= 0;
- }
-
- /// <summary>
- /// Determines whether this <paramref name="span"/> and the specified <paramref name="other"/> span have the same characters
- /// when compared using the specified <paramref name="comparisonType"/> option.
- /// <param name="span">The source span.</param>
- /// <param name="other">The value to compare with the source span.</param>
- /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="other"/> are compared.</param>
- /// </summary>
- public static bool Equals(this ReadOnlySpan<char> span, ReadOnlySpan<char> other, StringComparison comparisonType)
- {
- string.CheckStringComparison(comparisonType);
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- return CultureInfo.CurrentCulture.CompareInfo.CompareOptionNone(span, other) == 0;
-
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.CompareOptionIgnoreCase(span, other) == 0;
-
- case StringComparison.InvariantCulture:
- return CompareInfo.Invariant.CompareOptionNone(span, other) == 0;
-
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.CompareOptionIgnoreCase(span, other) == 0;
-
- case StringComparison.Ordinal:
- return EqualsOrdinal(span, other);
-
- case StringComparison.OrdinalIgnoreCase:
- return EqualsOrdinalIgnoreCase(span, other);
- }
-
- Debug.Fail("StringComparison outside range");
- return false;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool EqualsOrdinal(this ReadOnlySpan<char> span, ReadOnlySpan<char> value)
- {
- if (span.Length != value.Length)
- return false;
- if (value.Length == 0) // span.Length == value.Length == 0
- return true;
- return span.SequenceEqual(value);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool EqualsOrdinalIgnoreCase(this ReadOnlySpan<char> span, ReadOnlySpan<char> value)
- {
- if (span.Length != value.Length)
- return false;
- if (value.Length == 0) // span.Length == value.Length == 0
- return true;
- return CompareInfo.EqualsOrdinalIgnoreCase(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(value), span.Length);
- }
-
- /// <summary>
- /// Compares the specified <paramref name="span"/> and <paramref name="other"/> using the specified <paramref name="comparisonType"/>,
- /// and returns an integer that indicates their relative position in the sort order.
- /// <param name="span">The source span.</param>
- /// <param name="other">The value to compare with the source span.</param>
- /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="other"/> are compared.</param>
- /// </summary>
- public static int CompareTo(this ReadOnlySpan<char> span, ReadOnlySpan<char> other, StringComparison comparisonType)
- {
- string.CheckStringComparison(comparisonType);
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- return CultureInfo.CurrentCulture.CompareInfo.CompareOptionNone(span, other);
-
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.CompareOptionIgnoreCase(span, other);
-
- case StringComparison.InvariantCulture:
- return CompareInfo.Invariant.CompareOptionNone(span, other);
-
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.CompareOptionIgnoreCase(span, other);
-
- case StringComparison.Ordinal:
- if (span.Length == 0 || other.Length == 0)
- return span.Length - other.Length;
- return string.CompareOrdinal(span, other);
-
- case StringComparison.OrdinalIgnoreCase:
- return CompareInfo.CompareOrdinalIgnoreCase(span, other);
- }
-
- Debug.Fail("StringComparison outside range");
- return 0;
- }
-
- /// <summary>
- /// Reports the zero-based index of the first occurrence of the specified <paramref name="value"/> in the current <paramref name="span"/>.
- /// <param name="span">The source span.</param>
- /// <param name="value">The value to seek within the source span.</param>
- /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param>
- /// </summary>
- public static int IndexOf(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
- {
- string.CheckStringComparison(comparisonType);
-
- if (value.Length == 0)
- {
- return 0;
- }
-
- if (span.Length == 0)
- {
- return -1;
- }
-
- if (comparisonType == StringComparison.Ordinal)
- {
- return SpanHelpers.IndexOf(
- ref MemoryMarshal.GetReference(span),
- span.Length,
- ref MemoryMarshal.GetReference(value),
- value.Length);
- }
-
- if (GlobalizationMode.Invariant)
- {
- return CompareInfo.InvariantIndexOf(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType) != CompareOptions.None);
- }
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.IndexOf(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.IndexOf(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType));
-
- default:
- Debug.Assert(comparisonType == StringComparison.OrdinalIgnoreCase);
- return CompareInfo.Invariant.IndexOfOrdinalIgnoreCase(span, value);
- }
- }
-
- /// <summary>
- /// Reports the zero-based index of the last occurrence of the specified <paramref name="value"/> in the current <paramref name="span"/>.
- /// <param name="span">The source span.</param>
- /// <param name="value">The value to seek within the source span.</param>
- /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param>
- /// </summary>
- public static int LastIndexOf(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
- {
- string.CheckStringComparison(comparisonType);
-
- if (value.Length == 0)
- {
- return span.Length > 0 ? span.Length - 1 : 0;
- }
-
- if (span.Length == 0)
- {
- return -1;
- }
-
- if (GlobalizationMode.Invariant)
- {
- return CompareInfo.InvariantIndexOf(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType) != CompareOptions.None, fromBeginning: false);
- }
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.LastIndexOf(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.LastIndexOf(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType));
-
- default:
- Debug.Assert(comparisonType == StringComparison.Ordinal || comparisonType == StringComparison.OrdinalIgnoreCase);
- return CompareInfo.Invariant.LastIndexOfOrdinal(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType) != CompareOptions.None);
- }
- }
-
- /// <summary>
- /// Copies the characters from the source span into the destination, converting each character to lowercase,
- /// using the casing rules of the specified culture.
- /// </summary>
- /// <param name="source">The source span.</param>
- /// <param name="destination">The destination span which contains the transformed characters.</param>
- /// <param name="culture">An object that supplies culture-specific casing rules.</param>
- /// <remarks>If <paramref name="culture"/> is null, <see cref="System.Globalization.CultureInfo.CurrentCulture"/> will be used.</remarks>
- /// <returns>The number of characters written into the destination span. If the destination is too small, returns -1.</returns>
- /// <exception cref="InvalidOperationException">The source and destination buffers overlap.</exception>
- public static int ToLower(this ReadOnlySpan<char> source, Span<char> destination, CultureInfo? culture)
- {
- if (source.Overlaps(destination))
- throw new InvalidOperationException(SR.InvalidOperation_SpanOverlappedOperation);
-
- culture ??= CultureInfo.CurrentCulture;
-
- // Assuming that changing case does not affect length
- if (destination.Length < source.Length)
- return -1;
-
- if (GlobalizationMode.Invariant)
- TextInfo.ToLowerAsciiInvariant(source, destination);
- else
- culture.TextInfo.ChangeCaseToLower(source, destination);
- return source.Length;
- }
-
- /// <summary>
- /// Copies the characters from the source span into the destination, converting each character to lowercase,
- /// using the casing rules of the invariant culture.
- /// </summary>
- /// <param name="source">The source span.</param>
- /// <param name="destination">The destination span which contains the transformed characters.</param>
- /// <returns>The number of characters written into the destination span. If the destination is too small, returns -1.</returns>
- /// <exception cref="InvalidOperationException">The source and destination buffers overlap.</exception>
- public static int ToLowerInvariant(this ReadOnlySpan<char> source, Span<char> destination)
- {
- if (source.Overlaps(destination))
- throw new InvalidOperationException(SR.InvalidOperation_SpanOverlappedOperation);
-
- // Assuming that changing case does not affect length
- if (destination.Length < source.Length)
- return -1;
-
- if (GlobalizationMode.Invariant)
- TextInfo.ToLowerAsciiInvariant(source, destination);
- else
- CultureInfo.InvariantCulture.TextInfo.ChangeCaseToLower(source, destination);
- return source.Length;
- }
-
- /// <summary>
- /// Copies the characters from the source span into the destination, converting each character to uppercase,
- /// using the casing rules of the specified culture.
- /// </summary>
- /// <param name="source">The source span.</param>
- /// <param name="destination">The destination span which contains the transformed characters.</param>
- /// <param name="culture">An object that supplies culture-specific casing rules.</param>
- /// <remarks>If <paramref name="culture"/> is null, <see cref="System.Globalization.CultureInfo.CurrentCulture"/> will be used.</remarks>
- /// <returns>The number of characters written into the destination span. If the destination is too small, returns -1.</returns>
- /// <exception cref="InvalidOperationException">The source and destination buffers overlap.</exception>
- public static int ToUpper(this ReadOnlySpan<char> source, Span<char> destination, CultureInfo? culture)
- {
- if (source.Overlaps(destination))
- throw new InvalidOperationException(SR.InvalidOperation_SpanOverlappedOperation);
-
- culture ??= CultureInfo.CurrentCulture;
-
- // Assuming that changing case does not affect length
- if (destination.Length < source.Length)
- return -1;
-
- if (GlobalizationMode.Invariant)
- TextInfo.ToUpperAsciiInvariant(source, destination);
- else
- culture.TextInfo.ChangeCaseToUpper(source, destination);
- return source.Length;
- }
-
- /// <summary>
- /// Copies the characters from the source span into the destination, converting each character to uppercase
- /// using the casing rules of the invariant culture.
- /// </summary>
- /// <param name="source">The source span.</param>
- /// <param name="destination">The destination span which contains the transformed characters.</param>
- /// <returns>The number of characters written into the destination span. If the destination is too small, returns -1.</returns>
- /// <exception cref="InvalidOperationException">The source and destination buffers overlap.</exception>
- public static int ToUpperInvariant(this ReadOnlySpan<char> source, Span<char> destination)
- {
- if (source.Overlaps(destination))
- throw new InvalidOperationException(SR.InvalidOperation_SpanOverlappedOperation);
-
- // Assuming that changing case does not affect length
- if (destination.Length < source.Length)
- return -1;
-
- if (GlobalizationMode.Invariant)
- TextInfo.ToUpperAsciiInvariant(source, destination);
- else
- CultureInfo.InvariantCulture.TextInfo.ChangeCaseToUpper(source, destination);
- return source.Length;
- }
-
- /// <summary>
- /// Determines whether the end of the <paramref name="span"/> matches the specified <paramref name="value"/> when compared using the specified <paramref name="comparisonType"/> option.
- /// </summary>
- /// <param name="span">The source span.</param>
- /// <param name="value">The sequence to compare to the end of the source span.</param>
- /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param>
- public static bool EndsWith(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
- {
- string.CheckStringComparison(comparisonType);
-
- if (value.Length == 0)
- {
- return true;
- }
-
- if (comparisonType >= StringComparison.Ordinal || GlobalizationMode.Invariant)
- {
- if (string.GetCaseCompareOfComparisonCulture(comparisonType) == CompareOptions.None)
- return span.EndsWith(value);
-
- return (span.Length >= value.Length) ? (CompareInfo.CompareOrdinalIgnoreCase(span.Slice(span.Length - value.Length), value) == 0) : false;
- }
-
- if (span.Length == 0)
- {
- return false;
- }
-
- return (comparisonType >= StringComparison.InvariantCulture) ?
- CompareInfo.Invariant.IsSuffix(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType)) :
- CultureInfo.CurrentCulture.CompareInfo.IsSuffix(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType));
- }
-
- /// <summary>
- /// Determines whether the beginning of the <paramref name="span"/> matches the specified <paramref name="value"/> when compared using the specified <paramref name="comparisonType"/> option.
- /// </summary>
- /// <param name="span">The source span.</param>
- /// <param name="value">The sequence to compare to the beginning of the source span.</param>
- /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param>
- public static bool StartsWith(this ReadOnlySpan<char> span, ReadOnlySpan<char> value, StringComparison comparisonType)
- {
- string.CheckStringComparison(comparisonType);
-
- if (value.Length == 0)
- {
- return true;
- }
-
- if (comparisonType >= StringComparison.Ordinal || GlobalizationMode.Invariant)
- {
- if (string.GetCaseCompareOfComparisonCulture(comparisonType) == CompareOptions.None)
- return span.StartsWith(value);
-
- return (span.Length >= value.Length) ? (CompareInfo.CompareOrdinalIgnoreCase(span.Slice(0, value.Length), value) == 0) : false;
- }
-
- if (span.Length == 0)
- {
- return false;
- }
-
- return (comparisonType >= StringComparison.InvariantCulture) ?
- CompareInfo.Invariant.IsPrefix(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType)) :
- CultureInfo.CurrentCulture.CompareInfo.IsPrefix(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType));
- }
-
- /// <summary>
- /// Returns an enumeration of <see cref="Rune"/> from the provided span.
- /// </summary>
- /// <remarks>
- /// Invalid sequences will be represented in the enumeration by <see cref="Rune.ReplacementChar"/>.
- /// </remarks>
- public static SpanRuneEnumerator EnumerateRunes(this ReadOnlySpan<char> span)
- {
- return new SpanRuneEnumerator(span);
- }
-
- /// <summary>
- /// Returns an enumeration of <see cref="Rune"/> from the provided span.
- /// </summary>
- /// <remarks>
- /// Invalid sequences will be represented in the enumeration by <see cref="Rune.ReplacementChar"/>.
- /// </remarks>
- public static SpanRuneEnumerator EnumerateRunes(this Span<char> span)
- {
- return new SpanRuneEnumerator(span);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Trim.cs b/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Trim.cs
deleted file mode 100644
index 236a5e3fa21..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.Trim.cs
+++ /dev/null
@@ -1,921 +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 System.Diagnostics;
-
-namespace System
-{
- public static partial class MemoryExtensions
- {
- /// <summary>
- /// Removes all leading and trailing occurrences of a specified element from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static Memory<T> Trim<T>(this Memory<T> memory, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- ReadOnlySpan<T> span = memory.Span;
- int start = ClampStart(span, trimElement);
- int length = ClampEnd(span, start, trimElement);
- return memory.Slice(start, length);
- }
-
- /// <summary>
- /// Removes all leading occurrences of a specified element from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static Memory<T> TrimStart<T>(this Memory<T> memory, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- => memory.Slice(ClampStart(memory.Span, trimElement));
-
- /// <summary>
- /// Removes all trailing occurrences of a specified element from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static Memory<T> TrimEnd<T>(this Memory<T> memory, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- => memory.Slice(0, ClampEnd(memory.Span, 0, trimElement));
-
- /// <summary>
- /// Removes all leading and trailing occurrences of a specified element from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static ReadOnlyMemory<T> Trim<T>(this ReadOnlyMemory<T> memory, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- ReadOnlySpan<T> span = memory.Span;
- int start = ClampStart(span, trimElement);
- int length = ClampEnd(span, start, trimElement);
- return memory.Slice(start, length);
- }
-
- /// <summary>
- /// Removes all leading occurrences of a specified element from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static ReadOnlyMemory<T> TrimStart<T>(this ReadOnlyMemory<T> memory, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- => memory.Slice(ClampStart(memory.Span, trimElement));
-
- /// <summary>
- /// Removes all trailing occurrences of a specified element from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static ReadOnlyMemory<T> TrimEnd<T>(this ReadOnlyMemory<T> memory, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- => memory.Slice(0, ClampEnd(memory.Span, 0, trimElement));
-
- /// <summary>
- /// Removes all leading and trailing occurrences of a specified element from the span.
- /// </summary>
- /// <param name="span">The source span from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static Span<T> Trim<T>(this Span<T> span, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- int start = ClampStart(span, trimElement);
- int length = ClampEnd(span, start, trimElement);
- return span.Slice(start, length);
- }
-
- /// <summary>
- /// Removes all leading occurrences of a specified element from the span.
- /// </summary>
- /// <param name="span">The source span from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static Span<T> TrimStart<T>(this Span<T> span, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- => span.Slice(ClampStart(span, trimElement));
-
- /// <summary>
- /// Removes all trailing occurrences of a specified element from the span.
- /// </summary>
- /// <param name="span">The source span from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static Span<T> TrimEnd<T>(this Span<T> span, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- => span.Slice(0, ClampEnd(span, 0, trimElement));
-
- /// <summary>
- /// Removes all leading and trailing occurrences of a specified element from the span.
- /// </summary>
- /// <param name="span">The source span from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static ReadOnlySpan<T> Trim<T>(this ReadOnlySpan<T> span, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- int start = ClampStart(span, trimElement);
- int length = ClampEnd(span, start, trimElement);
- return span.Slice(start, length);
- }
-
- /// <summary>
- /// Removes all leading occurrences of a specified element from the span.
- /// </summary>
- /// <param name="span">The source span from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static ReadOnlySpan<T> TrimStart<T>(this ReadOnlySpan<T> span, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- => span.Slice(ClampStart(span, trimElement));
-
- /// <summary>
- /// Removes all trailing occurrences of a specified element from the span.
- /// </summary>
- /// <param name="span">The source span from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- public static ReadOnlySpan<T> TrimEnd<T>(this ReadOnlySpan<T> span, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- => span.Slice(0, ClampEnd(span, 0, trimElement));
-
- /// <summary>
- /// Delimits all leading occurrences of a specified element from the span.
- /// </summary>
- /// <param name="span">The source span from which the element is removed.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- private static int ClampStart<T>(ReadOnlySpan<T> span, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- int start = 0;
-
- if (trimElement != null)
- {
- for (; start < span.Length; start++)
- {
- if (!trimElement.Equals(span[start]))
- {
- break;
- }
- }
- }
- else
- {
- for (; start < span.Length; start++)
- {
- if (span[start] != null)
- {
- break;
- }
- }
- }
-
- return start;
- }
-
- /// <summary>
- /// Delimits all trailing occurrences of a specified element from the span.
- /// </summary>
- /// <param name="span">The source span from which the element is removed.</param>
- /// <param name="start">The start index from which to being searching.</param>
- /// <param name="trimElement">The specified element to look for and remove.</param>
- private static int ClampEnd<T>(ReadOnlySpan<T> span, int start, T trimElement)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- // Initially, start==len==0. If ClampStart trims all, start==len
- Debug.Assert((uint)start <= span.Length);
-
- int end = span.Length - 1;
-
- if (trimElement != null)
- {
- for (; end >= start; end--)
- {
- if (!trimElement.Equals(span[end]))
- {
- break;
- }
- }
- }
- else
- {
- for (; end >= start; end--)
- {
- if (span[end] != null)
- {
- break;
- }
- }
- }
-
- return end - start + 1;
- }
-
- /// <summary>
- /// Removes all leading and trailing occurrences of a set of elements specified
- /// in a readonly span from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the memory is returned unaltered.</remarks>
- public static Memory<T> Trim<T>(this Memory<T> memory, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- ReadOnlySpan<T> span = memory.Span;
- int start = ClampStart(span, trimElements);
- int length = ClampEnd(span, start, trimElements);
- return memory.Slice(start, length);
- }
-
- if (trimElements.Length == 1)
- {
- return Trim(memory, trimElements[0]);
- }
-
- return memory;
- }
-
- /// <summary>
- /// Removes all leading occurrences of a set of elements specified
- /// in a readonly span from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the memory is returned unaltered.</remarks>
- public static Memory<T> TrimStart<T>(this Memory<T> memory, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- return memory.Slice(ClampStart(memory.Span, trimElements));
- }
-
- if (trimElements.Length == 1)
- {
- return TrimStart(memory, trimElements[0]);
- }
-
- return memory;
- }
-
- /// <summary>
- /// Removes all trailing occurrences of a set of elements specified
- /// in a readonly span from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the memory is returned unaltered.</remarks>
- public static Memory<T> TrimEnd<T>(this Memory<T> memory, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- return memory.Slice(0, ClampEnd(memory.Span, 0, trimElements));
- }
-
- if (trimElements.Length == 1)
- {
- return TrimEnd(memory, trimElements[0]);
- }
-
- return memory;
- }
-
- /// <summary>
- /// Removes all leading and trailing occurrences of a set of elements specified
- /// in a readonly span from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the memory is returned unaltered.</remarks>
- public static ReadOnlyMemory<T> Trim<T>(this ReadOnlyMemory<T> memory, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- ReadOnlySpan<T> span = memory.Span;
- int start = ClampStart(span, trimElements);
- int length = ClampEnd(span, start, trimElements);
- return memory.Slice(start, length);
- }
-
- if (trimElements.Length == 1)
- {
- return Trim(memory, trimElements[0]);
- }
-
- return memory;
- }
-
- /// <summary>
- /// Removes all leading occurrences of a set of elements specified
- /// in a readonly span from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the memory is returned unaltered.</remarks>
- public static ReadOnlyMemory<T> TrimStart<T>(this ReadOnlyMemory<T> memory, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- return memory.Slice(ClampStart(memory.Span, trimElements));
- }
-
- if (trimElements.Length == 1)
- {
- return TrimStart(memory, trimElements[0]);
- }
-
- return memory;
- }
-
- /// <summary>
- /// Removes all trailing occurrences of a set of elements specified
- /// in a readonly span from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the memory is returned unaltered.</remarks>
- public static ReadOnlyMemory<T> TrimEnd<T>(this ReadOnlyMemory<T> memory, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- return memory.Slice(0, ClampEnd(memory.Span, 0, trimElements));
- }
-
- if (trimElements.Length == 1)
- {
- return TrimEnd(memory, trimElements[0]);
- }
-
- return memory;
- }
-
- /// <summary>
- /// Removes all leading and trailing occurrences of a set of elements specified
- /// in a readonly span from the span.
- /// </summary>
- /// <param name="span">The source span from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the span is returned unaltered.</remarks>
- public static Span<T> Trim<T>(this Span<T> span, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- int start = ClampStart(span, trimElements);
- int length = ClampEnd(span, start, trimElements);
- return span.Slice(start, length);
- }
-
- if (trimElements.Length == 1)
- {
- return Trim(span, trimElements[0]);
- }
-
- return span;
- }
-
- /// <summary>
- /// Removes all leading occurrences of a set of elements specified
- /// in a readonly span from the span.
- /// </summary>
- /// <param name="span">The source span from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the span is returned unaltered.</remarks>
- public static Span<T> TrimStart<T>(this Span<T> span, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- return span.Slice(ClampStart(span, trimElements));
- }
-
- if (trimElements.Length == 1)
- {
- return TrimStart(span, trimElements[0]);
- }
-
- return span;
- }
-
- /// <summary>
- /// Removes all trailing occurrences of a set of elements specified
- /// in a readonly span from the span.
- /// </summary>
- /// <param name="span">The source span from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the span is returned unaltered.</remarks>
- public static Span<T> TrimEnd<T>(this Span<T> span, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- return span.Slice(0, ClampEnd(span, 0, trimElements));
- }
-
- if (trimElements.Length == 1)
- {
- return TrimEnd(span, trimElements[0]);
- }
-
- return span;
- }
-
- /// <summary>
- /// Removes all leading and trailing occurrences of a set of elements specified
- /// in a readonly span from the span.
- /// </summary>
- /// <param name="span">The source span from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the span is returned unaltered.</remarks>
- public static ReadOnlySpan<T> Trim<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- int start = ClampStart(span, trimElements);
- int length = ClampEnd(span, start, trimElements);
- return span.Slice(start, length);
- }
-
- if (trimElements.Length == 1)
- {
- return Trim(span, trimElements[0]);
- }
-
- return span;
- }
-
- /// <summary>
- /// Removes all leading occurrences of a set of elements specified
- /// in a readonly span from the span.
- /// </summary>
- /// <param name="span">The source span from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the span is returned unaltered.</remarks>
- public static ReadOnlySpan<T> TrimStart<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- return span.Slice(ClampStart(span, trimElements));
- }
-
- if (trimElements.Length == 1)
- {
- return TrimStart(span, trimElements[0]);
- }
-
- return span;
- }
-
- /// <summary>
- /// Removes all trailing occurrences of a set of elements specified
- /// in a readonly span from the span.
- /// </summary>
- /// <param name="span">The source span from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- /// <remarks>If <paramref name="trimElements"/> is empty, the span is returned unaltered.</remarks>
- public static ReadOnlySpan<T> TrimEnd<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (trimElements.Length > 1)
- {
- return span.Slice(0, ClampEnd(span, 0, trimElements));
- }
-
- if (trimElements.Length == 1)
- {
- return TrimEnd(span, trimElements[0]);
- }
-
- return span;
- }
-
- /// <summary>
- /// Delimits all leading occurrences of a set of elements specified
- /// in a readonly span from the span.
- /// </summary>
- /// <param name="span">The source span from which the elements are removed.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- private static int ClampStart<T>(ReadOnlySpan<T> span, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- int start = 0;
- for (; start < span.Length; start++)
- {
- if (!trimElements.Contains(span[start]))
- {
- break;
- }
- }
-
- return start;
- }
-
- /// <summary>
- /// Delimits all trailing occurrences of a set of elements specified
- /// in a readonly span from the span.
- /// </summary>
- /// <param name="span">The source span from which the elements are removed.</param>
- /// <param name="start">The start index from which to being searching.</param>
- /// <param name="trimElements">The span which contains the set of elements to remove.</param>
- private static int ClampEnd<T>(ReadOnlySpan<T> span, int start, ReadOnlySpan<T> trimElements)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- // Initially, start==len==0. If ClampStart trims all, start==len
- Debug.Assert((uint)start <= span.Length);
-
- int end = span.Length - 1;
- for (; end >= start; end--)
- {
- if (!trimElements.Contains(span[end]))
- {
- break;
- }
- }
-
- return end - start + 1;
- }
-
- /// <summary>
- /// Removes all leading and trailing white-space characters from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the characters are removed.</param>
- public static Memory<char> Trim(this Memory<char> memory)
- {
- ReadOnlySpan<char> span = memory.Span;
- int start = ClampStart(span);
- int length = ClampEnd(span, start);
- return memory.Slice(start, length);
- }
-
- /// <summary>
- /// Removes all leading white-space characters from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the characters are removed.</param>
- public static Memory<char> TrimStart(this Memory<char> memory)
- => memory.Slice(ClampStart(memory.Span));
-
- /// <summary>
- /// Removes all trailing white-space characters from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the characters are removed.</param>
- public static Memory<char> TrimEnd(this Memory<char> memory)
- => memory.Slice(0, ClampEnd(memory.Span, 0));
-
- /// <summary>
- /// Removes all leading and trailing white-space characters from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the characters are removed.</param>
- public static ReadOnlyMemory<char> Trim(this ReadOnlyMemory<char> memory)
- {
- ReadOnlySpan<char> span = memory.Span;
- int start = ClampStart(span);
- int length = ClampEnd(span, start);
- return memory.Slice(start, length);
- }
-
- /// <summary>
- /// Removes all leading white-space characters from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the characters are removed.</param>
- public static ReadOnlyMemory<char> TrimStart(this ReadOnlyMemory<char> memory)
- => memory.Slice(ClampStart(memory.Span));
-
- /// <summary>
- /// Removes all trailing white-space characters from the memory.
- /// </summary>
- /// <param name="memory">The source memory from which the characters are removed.</param>
- public static ReadOnlyMemory<char> TrimEnd(this ReadOnlyMemory<char> memory)
- => memory.Slice(0, ClampEnd(memory.Span, 0));
-
- /// <summary>
- /// Removes all leading and trailing white-space characters from the span.
- /// </summary>
- /// <param name="span">The source span from which the characters are removed.</param>
- public static ReadOnlySpan<char> Trim(this ReadOnlySpan<char> span)
- {
- int start = 0;
- for (; start < span.Length; start++)
- {
- if (!char.IsWhiteSpace(span[start]))
- {
- break;
- }
- }
-
- int end = span.Length - 1;
- for (; end > start; end--)
- {
- if (!char.IsWhiteSpace(span[end]))
- {
- break;
- }
- }
-
- return span.Slice(start, end - start + 1);
- }
-
- /// <summary>
- /// Removes all leading white-space characters from the span.
- /// </summary>
- /// <param name="span">The source span from which the characters are removed.</param>
- public static ReadOnlySpan<char> TrimStart(this ReadOnlySpan<char> span)
- {
- int start = 0;
- for (; start < span.Length; start++)
- {
- if (!char.IsWhiteSpace(span[start]))
- {
- break;
- }
- }
-
- return span.Slice(start);
- }
-
- /// <summary>
- /// Removes all trailing white-space characters from the span.
- /// </summary>
- /// <param name="span">The source span from which the characters are removed.</param>
- public static ReadOnlySpan<char> TrimEnd(this ReadOnlySpan<char> span)
- {
- int end = span.Length - 1;
- for (; end >= 0; end--)
- {
- if (!char.IsWhiteSpace(span[end]))
- {
- break;
- }
- }
-
- return span.Slice(0, end + 1);
- }
-
- /// <summary>
- /// Removes all leading and trailing occurrences of a specified character from the span.
- /// </summary>
- /// <param name="span">The source span from which the character is removed.</param>
- /// <param name="trimChar">The specified character to look for and remove.</param>
- public static ReadOnlySpan<char> Trim(this ReadOnlySpan<char> span, char trimChar)
- {
- int start = 0;
- for (; start < span.Length; start++)
- {
- if (span[start] != trimChar)
- {
- break;
- }
- }
-
- int end = span.Length - 1;
- for (; end > start; end--)
- {
- if (span[end] != trimChar)
- {
- break;
- }
- }
-
- return span.Slice(start, end - start + 1);
- }
-
- /// <summary>
- /// Removes all leading occurrences of a specified character from the span.
- /// </summary>
- /// <param name="span">The source span from which the character is removed.</param>
- /// <param name="trimChar">The specified character to look for and remove.</param>
- public static ReadOnlySpan<char> TrimStart(this ReadOnlySpan<char> span, char trimChar)
- {
- int start = 0;
- for (; start < span.Length; start++)
- {
- if (span[start] != trimChar)
- {
- break;
- }
- }
-
- return span.Slice(start);
- }
-
- /// <summary>
- /// Removes all trailing occurrences of a specified character from the span.
- /// </summary>
- /// <param name="span">The source span from which the character is removed.</param>
- /// <param name="trimChar">The specified character to look for and remove.</param>
- public static ReadOnlySpan<char> TrimEnd(this ReadOnlySpan<char> span, char trimChar)
- {
- int end = span.Length - 1;
- for (; end >= 0; end--)
- {
- if (span[end] != trimChar)
- {
- break;
- }
- }
-
- return span.Slice(0, end + 1);
- }
-
- /// <summary>
- /// Removes all leading and trailing occurrences of a set of characters specified
- /// in a readonly span from the span.
- /// </summary>
- /// <param name="span">The source span from which the characters are removed.</param>
- /// <param name="trimChars">The span which contains the set of characters to remove.</param>
- /// <remarks>If <paramref name="trimChars"/> is empty, white-space characters are removed instead.</remarks>
- public static ReadOnlySpan<char> Trim(this ReadOnlySpan<char> span, ReadOnlySpan<char> trimChars)
- => span.TrimStart(trimChars).TrimEnd(trimChars);
-
- /// <summary>
- /// Removes all leading occurrences of a set of characters specified
- /// in a readonly span from the span.
- /// </summary>
- /// <param name="span">The source span from which the characters are removed.</param>
- /// <param name="trimChars">The span which contains the set of characters to remove.</param>
- /// <remarks>If <paramref name="trimChars"/> is empty, white-space characters are removed instead.</remarks>
- public static ReadOnlySpan<char> TrimStart(this ReadOnlySpan<char> span, ReadOnlySpan<char> trimChars)
- {
- if (trimChars.IsEmpty)
- {
- return span.TrimStart();
- }
-
- int start = 0;
- for (; start < span.Length; start++)
- {
- for (int i = 0; i < trimChars.Length; i++)
- {
- if (span[start] == trimChars[i])
- {
- goto Next;
- }
- }
-
- break;
- Next:
- ;
- }
-
- return span.Slice(start);
- }
-
- /// <summary>
- /// Removes all trailing occurrences of a set of characters specified
- /// in a readonly span from the span.
- /// </summary>
- /// <param name="span">The source span from which the characters are removed.</param>
- /// <param name="trimChars">The span which contains the set of characters to remove.</param>
- /// <remarks>If <paramref name="trimChars"/> is empty, white-space characters are removed instead.</remarks>
- public static ReadOnlySpan<char> TrimEnd(this ReadOnlySpan<char> span, ReadOnlySpan<char> trimChars)
- {
- if (trimChars.IsEmpty)
- {
- return span.TrimEnd();
- }
-
- int end = span.Length - 1;
- for (; end >= 0; end--)
- {
- for (int i = 0; i < trimChars.Length; i++)
- {
- if (span[end] == trimChars[i])
- {
- goto Next;
- }
- }
-
- break;
- Next:
- ;
- }
-
- return span.Slice(0, end + 1);
- }
-
- /// <summary>
- /// Removes all leading and trailing white-space characters from the span.
- /// </summary>
- /// <param name="span">The source span from which the characters are removed.</param>
- public static Span<char> Trim(this Span<char> span)
- {
- int start = ClampStart(span);
- int length = ClampEnd(span, start);
- return span.Slice(start, length);
- }
-
- /// <summary>
- /// Removes all leading white-space characters from the span.
- /// </summary>
- /// <param name="span">The source span from which the characters are removed.</param>
- public static Span<char> TrimStart(this Span<char> span)
- => span.Slice(ClampStart(span));
-
- /// <summary>
- /// Removes all trailing white-space characters from the span.
- /// </summary>
- /// <param name="span">The source span from which the characters are removed.</param>
- public static Span<char> TrimEnd(this Span<char> span)
- => span.Slice(0, ClampEnd(span, 0));
-
- /// <summary>
- /// Delimits all leading occurrences of whitespace charecters from the span.
- /// </summary>
- /// <param name="span">The source span from which the characters are removed.</param>
- private static int ClampStart(ReadOnlySpan<char> span)
- {
- int start = 0;
-
- for (; start < span.Length; start++)
- {
- if (!char.IsWhiteSpace(span[start]))
- {
- break;
- }
- }
-
- return start;
- }
-
- /// <summary>
- /// Delimits all trailing occurrences of whitespace charecters from the span.
- /// </summary>
- /// <param name="span">The source span from which the characters are removed.</param>
- /// <param name="start">The start index from which to being searching.</param>
- private static int ClampEnd(ReadOnlySpan<char> span, int start)
- {
- // Initially, start==len==0. If ClampStart trims all, start==len
- Debug.Assert((uint)start <= span.Length);
-
- int end = span.Length - 1;
-
- for (; end >= start; end--)
- {
- if (!char.IsWhiteSpace(span[end]))
- {
- break;
- }
- }
-
- return end - start + 1;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.cs b/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.cs
deleted file mode 100644
index 97da535e586..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MemoryExtensions.cs
+++ /dev/null
@@ -1,2004 +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 System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif // BIT64
-
-namespace System
-{
- /// <summary>
- /// Extension methods for Span{T}, Memory{T}, and friends.
- /// </summary>
- public static partial class MemoryExtensions
- {
- /// <summary>
- /// Creates a new span over the portion of the target array.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> AsSpan<T>(this T[]? array, int start)
- {
- if (array == null)
- {
- if (start != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
- return default;
- }
- if (default(T)! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- ThrowHelper.ThrowArrayTypeMismatchException();
- if ((uint)start > (uint)array.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- return new Span<T>(ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), start), array.Length - start);
- }
-
- /// <summary>
- /// Creates a new span over the portion of the target array.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> AsSpan<T>(this T[]? array, Index startIndex)
- {
- if (array == null)
- {
- if (!startIndex.Equals(Index.Start))
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
-
- return default;
- }
-
- if (default(T)! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- ThrowHelper.ThrowArrayTypeMismatchException();
-
- int actualIndex = startIndex.GetOffset(array.Length);
- if ((uint)actualIndex > (uint)array.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- return new Span<T>(ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), actualIndex), array.Length - actualIndex);
- }
-
- /// <summary>
- /// Creates a new span over the portion of the target array.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> AsSpan<T>(this T[]? array, Range range)
- {
- if (array == null)
- {
- Index startIndex = range.Start;
- Index endIndex = range.End;
-
- if (!startIndex.Equals(Index.Start) || !endIndex.Equals(Index.Start))
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
-
- return default;
- }
-
- if (default(T)! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- ThrowHelper.ThrowArrayTypeMismatchException();
-
- (int start, int length) = range.GetOffsetAndLength(array.Length);
- return new Span<T>(ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), start), length);
- }
-
- /// <summary>
- /// Creates a new readonly span over the portion of the target string.
- /// </summary>
- /// <param name="text">The target string.</param>
- /// <remarks>Returns default when <paramref name="text"/> is null.</remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<char> AsSpan(this string? text)
- {
- if (text == null)
- return default;
-
- return new ReadOnlySpan<char>(ref text.GetRawStringData(), text.Length);
- }
-
- /// <summary>
- /// Creates a new readonly span over the portion of the target string.
- /// </summary>
- /// <param name="text">The target string.</param>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> index is not in range (&lt;0 or &gt;text.Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<char> AsSpan(this string? text, int start)
- {
- if (text == null)
- {
- if (start != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
- return default;
- }
-
- if ((uint)start > (uint)text.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
-
- return new ReadOnlySpan<char>(ref Unsafe.Add(ref text.GetRawStringData(), start), text.Length - start);
- }
-
- /// <summary>
- /// Creates a new readonly span over the portion of the target string.
- /// </summary>
- /// <param name="text">The target string.</param>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <param name="length">The desired length for the slice (exclusive).</param>
- /// <remarks>Returns default when <paramref name="text"/> is null.</remarks>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> index or <paramref name="length"/> is not in range.
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<char> AsSpan(this string? text, int start, int length)
- {
- if (text == null)
- {
- if (start != 0 || length != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
- return default;
- }
-
-#if BIT64
- // See comment in Span<T>.Slice for how this works.
- if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)text.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
-#else
- if ((uint)start > (uint)text.Length || (uint)length > (uint)(text.Length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
-#endif
-
- return new ReadOnlySpan<char>(ref Unsafe.Add(ref text.GetRawStringData(), start), length);
- }
-
- /// <summary>Creates a new <see cref="ReadOnlyMemory{T}"/> over the portion of the target string.</summary>
- /// <param name="text">The target string.</param>
- /// <remarks>Returns default when <paramref name="text"/> is null.</remarks>
- public static ReadOnlyMemory<char> AsMemory(this string? text)
- {
- if (text == null)
- return default;
-
- return new ReadOnlyMemory<char>(text, 0, text.Length);
- }
-
- /// <summary>Creates a new <see cref="ReadOnlyMemory{T}"/> over the portion of the target string.</summary>
- /// <param name="text">The target string.</param>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <remarks>Returns default when <paramref name="text"/> is null.</remarks>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> index is not in range (&lt;0 or &gt;text.Length).
- /// </exception>
- public static ReadOnlyMemory<char> AsMemory(this string? text, int start)
- {
- if (text == null)
- {
- if (start != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
- return default;
- }
-
- if ((uint)start > (uint)text.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
-
- return new ReadOnlyMemory<char>(text, start, text.Length - start);
- }
-
- /// <summary>Creates a new <see cref="ReadOnlyMemory{T}"/> over the portion of the target string.</summary>
- /// <param name="text">The target string.</param>
- /// <param name="startIndex">The index at which to begin this slice.</param>
- public static ReadOnlyMemory<char> AsMemory(this string? text, Index startIndex)
- {
- if (text == null)
- {
- if (!startIndex.Equals(Index.Start))
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text);
-
- return default;
- }
-
- int actualIndex = startIndex.GetOffset(text.Length);
- if ((uint)actualIndex > (uint)text.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- return new ReadOnlyMemory<char>(text, actualIndex, text.Length - actualIndex);
- }
-
- /// <summary>Creates a new <see cref="ReadOnlyMemory{T}"/> over the portion of the target string.</summary>
- /// <param name="text">The target string.</param>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <param name="length">The desired length for the slice (exclusive).</param>
- /// <remarks>Returns default when <paramref name="text"/> is null.</remarks>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> index or <paramref name="length"/> is not in range.
- /// </exception>
- public static ReadOnlyMemory<char> AsMemory(this string? text, int start, int length)
- {
- if (text == null)
- {
- if (start != 0 || length != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
- return default;
- }
-
-#if BIT64
- // See comment in Span<T>.Slice for how this works.
- if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)text.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
-#else
- if ((uint)start > (uint)text.Length || (uint)length > (uint)(text.Length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
-#endif
-
- return new ReadOnlyMemory<char>(text, start, length);
- }
-
- /// <summary>Creates a new <see cref="ReadOnlyMemory{T}"/> over the portion of the target string.</summary>
- /// <param name="text">The target string.</param>
- /// <param name="range">The range used to indicate the start and length of the sliced string.</param>
- public static ReadOnlyMemory<char> AsMemory(this string? text, Range range)
- {
- if (text == null)
- {
- Index startIndex = range.Start;
- Index endIndex = range.End;
-
- if (!startIndex.Equals(Index.Start) || !endIndex.Equals(Index.Start))
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text);
-
- return default;
- }
-
- (int start, int length) = range.GetOffsetAndLength(text.Length);
- return new ReadOnlyMemory<char>(text, start, length);
- }
-
- /// <summary>
- /// Searches for the specified value and returns true if found. If not found, returns false. Values are compared using IEquatable{T}.Equals(T).
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="span">The span to search.</param>
- /// <param name="value">The value to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool Contains<T>(this Span<T> span, T value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.Contains(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value),
- span.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.Contains(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, char>(ref value),
- span.Length);
- }
-
- return SpanHelpers.Contains(ref MemoryMarshal.GetReference(span), value, span.Length);
- }
-
- /// <summary>
- /// Searches for the specified value and returns true if found. If not found, returns false. Values are compared using IEquatable{T}.Equals(T).
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="span">The span to search.</param>
- /// <param name="value">The value to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool Contains<T>(this ReadOnlySpan<T> span, T value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.Contains(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value),
- span.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.Contains(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, char>(ref value),
- span.Length);
- }
-
- return SpanHelpers.Contains(ref MemoryMarshal.GetReference(span), value, span.Length);
- }
-
- /// <summary>
- /// Searches for the specified value and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value">The value to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int IndexOf<T>(this Span<T> span, T value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.IndexOf(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value),
- span.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.IndexOf(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, char>(ref value),
- span.Length);
- }
-
- return SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), value, span.Length);
- }
-
- /// <summary>
- /// Searches for the specified sequence and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value">The sequence to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int IndexOf<T>(this Span<T> span, ReadOnlySpan<T> value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.IndexOf(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)),
- value.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.IndexOf(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(value)),
- value.Length);
- }
-
- return SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length);
- }
-
- /// <summary>
- /// Searches for the specified value and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value">The value to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int LastIndexOf<T>(this Span<T> span, T value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.LastIndexOf(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value),
- span.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.LastIndexOf(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, char>(ref value),
- span.Length);
- }
-
- return SpanHelpers.LastIndexOf<T>(ref MemoryMarshal.GetReference(span), value, span.Length);
- }
-
- /// <summary>
- /// Searches for the specified sequence and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value">The sequence to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int LastIndexOf<T>(this Span<T> span, ReadOnlySpan<T> value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable<T>())
- return SpanHelpers.LastIndexOf(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)),
- value.Length);
-
- return SpanHelpers.LastIndexOf<T>(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length);
- }
-
- /// <summary>
- /// Determines whether two sequences are equal by comparing the elements using IEquatable{T}.Equals(T).
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool SequenceEqual<T>(this Span<T> span, ReadOnlySpan<T> other)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- int length = span.Length;
-
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- nuint size = (nuint)Unsafe.SizeOf<T>();
- return length == other.Length &&
- SpanHelpers.SequenceEqual(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(other)),
- ((nuint)length) * size); // If this multiplication overflows, the Span we got overflows the entire address range. There's no happy outcome for this api in such a case so we choose not to take the overhead of checking.
- }
-
- return length == other.Length && SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other), length);
- }
-
- /// <summary>
- /// Determines the relative order of the sequences being compared by comparing the elements using IComparable{T}.CompareTo(T).
- /// </summary>
- public static int SequenceCompareTo<T>(this Span<T> span, ReadOnlySpan<T> other)
- where T : IComparable<T>
- {
- // Can't use IsBitwiseEquatable<T>() below because that only tells us about
- // equality checks, not about CompareTo checks.
-
- if (typeof(T) == typeof(byte))
- return SpanHelpers.SequenceCompareTo(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(other)),
- other.Length);
-
- if (typeof(T) == typeof(char))
- return SpanHelpers.SequenceCompareTo(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(other)),
- other.Length);
-
- return SpanHelpers.SequenceCompareTo(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(other), other.Length);
- }
-
- /// <summary>
- /// Searches for the specified value and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value">The value to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int IndexOf<T>(this ReadOnlySpan<T> span, T value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.IndexOf(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value),
- span.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.IndexOf(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, char>(ref value),
- span.Length);
- }
-
- return SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), value, span.Length);
- }
-
- /// <summary>
- /// Searches for the specified sequence and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value">The sequence to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int IndexOf<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.IndexOf(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)),
- value.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.IndexOf(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(value)),
- value.Length);
- }
-
- return SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length);
- }
-
- /// <summary>
- /// Searches for the specified value and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value">The value to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int LastIndexOf<T>(this ReadOnlySpan<T> span, T value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.LastIndexOf(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value),
- span.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.LastIndexOf(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, char>(ref value),
- span.Length);
- }
-
- return SpanHelpers.LastIndexOf<T>(ref MemoryMarshal.GetReference(span), value, span.Length);
- }
-
- /// <summary>
- /// Searches for the specified sequence and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value">The sequence to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int LastIndexOf<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable<T>())
- return SpanHelpers.LastIndexOf(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)),
- value.Length);
-
- return SpanHelpers.LastIndexOf<T>(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length);
- }
-
- /// <summary>
- /// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value0">One of the values to search for.</param>
- /// <param name="value1">One of the values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int IndexOfAny<T>(this Span<T> span, T value0, T value1)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value0),
- Unsafe.As<T, byte>(ref value1),
- span.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, char>(ref value0),
- Unsafe.As<T, char>(ref value1),
- span.Length);
- }
-
- return SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length);
- }
-
- /// <summary>
- /// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value0">One of the values to search for.</param>
- /// <param name="value1">One of the values to search for.</param>
- /// <param name="value2">One of the values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int IndexOfAny<T>(this Span<T> span, T value0, T value1, T value2)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value0),
- Unsafe.As<T, byte>(ref value1),
- Unsafe.As<T, byte>(ref value2),
- span.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, char>(ref value0),
- Unsafe.As<T, char>(ref value1),
- Unsafe.As<T, char>(ref value2),
- span.Length);
- }
-
- return SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length);
- }
-
- /// <summary>
- /// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="values">The set of values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int IndexOfAny<T>(this Span<T> span, ReadOnlySpan<T> values)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- {
- ref byte valueRef = ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values));
- if (values.Length == 2)
- {
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- span.Length);
- }
- else if (values.Length == 3)
- {
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- Unsafe.Add(ref valueRef, 2),
- span.Length);
- }
- else
- {
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref valueRef,
- values.Length);
- }
- }
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- {
- ref char valueRef = ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(values));
- if (values.Length == 5)
- {
- // Length 5 is a common length for FileSystemName expression (", <, >, *, ?) and in preference to 2 as it has an explicit overload
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- Unsafe.Add(ref valueRef, 2),
- Unsafe.Add(ref valueRef, 3),
- Unsafe.Add(ref valueRef, 4),
- span.Length);
- }
- else if (values.Length == 2)
- {
- // Length 2 is a common length for simple wildcards (*, ?), directory separators (/, \), quotes (", '), brackets, etc
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- span.Length);
- }
- else if (values.Length == 4)
- {
- // Length 4 before 3 as 3 has an explicit overload
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- Unsafe.Add(ref valueRef, 2),
- Unsafe.Add(ref valueRef, 3),
- span.Length);
- }
- else if (values.Length == 3)
- {
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- Unsafe.Add(ref valueRef, 2),
- span.Length);
- }
- else if (values.Length == 1)
- {
- // Length 1 last, as ctoring a ReadOnlySpan to call this overload for a single value
- // is already throwing away a bunch of performance vs just calling IndexOf
- return SpanHelpers.IndexOf(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- span.Length);
- }
- }
- }
-
- return SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length);
- }
-
- /// <summary>
- /// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value0">One of the values to search for.</param>
- /// <param name="value1">One of the values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int IndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value0),
- Unsafe.As<T, byte>(ref value1),
- span.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, char>(ref value0),
- Unsafe.As<T, char>(ref value1),
- span.Length);
- }
-
- return SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length);
- }
-
- /// <summary>
- /// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value0">One of the values to search for.</param>
- /// <param name="value1">One of the values to search for.</param>
- /// <param name="value2">One of the values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int IndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1, T value2)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value0),
- Unsafe.As<T, byte>(ref value1),
- Unsafe.As<T, byte>(ref value2),
- span.Length);
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, char>(ref value0),
- Unsafe.As<T, char>(ref value1),
- Unsafe.As<T, char>(ref value2),
- span.Length);
- }
-
- return SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length);
- }
-
- /// <summary>
- /// Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="values">The set of values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int IndexOfAny<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> values)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte))
- {
- ref byte valueRef = ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values));
- if (values.Length == 2)
- {
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- span.Length);
- }
- else if (values.Length == 3)
- {
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- Unsafe.Add(ref valueRef, 2),
- span.Length);
- }
- else
- {
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref valueRef,
- values.Length);
- }
- }
-
- if (Unsafe.SizeOf<T>() == sizeof(char))
- {
- ref char valueRef = ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(values));
- if (values.Length == 5)
- {
- // Length 5 is a common length for FileSystemName expression (", <, >, *, ?) and in preference to 2 as it has an explicit overload
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- Unsafe.Add(ref valueRef, 2),
- Unsafe.Add(ref valueRef, 3),
- Unsafe.Add(ref valueRef, 4),
- span.Length);
- }
- else if (values.Length == 2)
- {
- // Length 2 is a common length for simple wildcards (*, ?), directory separators (/, \), quotes (", '), brackets, etc
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- span.Length);
- }
- else if (values.Length == 4)
- {
- // Length 4 before 3 as 3 has an explicit overload
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- Unsafe.Add(ref valueRef, 2),
- Unsafe.Add(ref valueRef, 3),
- span.Length);
- }
- else if (values.Length == 3)
- {
- return SpanHelpers.IndexOfAny(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- Unsafe.Add(ref valueRef, 1),
- Unsafe.Add(ref valueRef, 2),
- span.Length);
- }
- else if (values.Length == 1)
- {
- // Length 1 last, as ctoring a ReadOnlySpan to call this overload for a single value
- // is already throwing away a bunch of performance vs just calling IndexOf
- return SpanHelpers.IndexOf(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- valueRef,
- span.Length);
- }
- }
- }
-
- return SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length);
- }
-
- /// <summary>
- /// Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value0">One of the values to search for.</param>
- /// <param name="value1">One of the values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int LastIndexOfAny<T>(this Span<T> span, T value0, T value1)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable<T>())
- return SpanHelpers.LastIndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value0),
- Unsafe.As<T, byte>(ref value1),
- span.Length);
-
- return SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length);
- }
-
- /// <summary>
- /// Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value0">One of the values to search for.</param>
- /// <param name="value1">One of the values to search for.</param>
- /// <param name="value2">One of the values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int LastIndexOfAny<T>(this Span<T> span, T value0, T value1, T value2)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable<T>())
- return SpanHelpers.LastIndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value0),
- Unsafe.As<T, byte>(ref value1),
- Unsafe.As<T, byte>(ref value2),
- span.Length);
-
- return SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length);
- }
-
- /// <summary>
- /// Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="values">The set of values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int LastIndexOfAny<T>(this Span<T> span, ReadOnlySpan<T> values)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable<T>())
- return SpanHelpers.LastIndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)),
- values.Length);
-
- return SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length);
- }
-
- /// <summary>
- /// Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value0">One of the values to search for.</param>
- /// <param name="value1">One of the values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int LastIndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable<T>())
- return SpanHelpers.LastIndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value0),
- Unsafe.As<T, byte>(ref value1),
- span.Length);
-
- return SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length);
- }
-
- /// <summary>
- /// Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="value0">One of the values to search for.</param>
- /// <param name="value1">One of the values to search for.</param>
- /// <param name="value2">One of the values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int LastIndexOfAny<T>(this ReadOnlySpan<T> span, T value0, T value1, T value2)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable<T>())
- return SpanHelpers.LastIndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- Unsafe.As<T, byte>(ref value0),
- Unsafe.As<T, byte>(ref value1),
- Unsafe.As<T, byte>(ref value2),
- span.Length);
-
- return SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length);
- }
-
- /// <summary>
- /// Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
- /// </summary>
- /// <param name="span">The span to search.</param>
- /// <param name="values">The set of values to search for.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int LastIndexOfAny<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> values)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- if (Unsafe.SizeOf<T>() == sizeof(byte) && RuntimeHelpers.IsBitwiseEquatable<T>())
- return SpanHelpers.LastIndexOfAny(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)),
- values.Length);
-
- return SpanHelpers.LastIndexOfAny<T>(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length);
- }
-
- /// <summary>
- /// Determines whether two sequences are equal by comparing the elements using IEquatable{T}.Equals(T).
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool SequenceEqual<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- int length = span.Length;
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- nuint size = (nuint)Unsafe.SizeOf<T>();
- return length == other.Length &&
- SpanHelpers.SequenceEqual(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(other)),
- ((nuint)length) * size); // If this multiplication overflows, the Span we got overflows the entire address range. There's no happy outcome for this api in such a case so we choose not to take the overhead of checking.
- }
-
- return length == other.Length && SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other), length);
- }
-
- /// <summary>
- /// Determines the relative order of the sequences being compared by comparing the elements using IComparable{T}.CompareTo(T).
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int SequenceCompareTo<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other)
- where T : IComparable<T>
- {
- // Can't use IsBitwiseEquatable<T>() below because that only tells us about
- // equality checks, not about CompareTo checks.
-
- if (typeof(T) == typeof(byte))
- return SpanHelpers.SequenceCompareTo(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(other)),
- other.Length);
-
- if (typeof(T) == typeof(char))
- return SpanHelpers.SequenceCompareTo(
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(span)),
- span.Length,
- ref Unsafe.As<T, char>(ref MemoryMarshal.GetReference(other)),
- other.Length);
-
- return SpanHelpers.SequenceCompareTo(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(other), other.Length);
- }
-
- /// <summary>
- /// Determines whether the specified sequence appears at the start of the span.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool StartsWith<T>(this Span<T> span, ReadOnlySpan<T> value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- int valueLength = value.Length;
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- nuint size = (nuint)Unsafe.SizeOf<T>();
- return valueLength <= span.Length &&
- SpanHelpers.SequenceEqual(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)),
- ((nuint)valueLength) * size); // If this multiplication overflows, the Span we got overflows the entire address range. There's no happy outcome for this api in such a case so we choose not to take the overhead of checking.
- }
-
- return valueLength <= span.Length && SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(value), valueLength);
- }
-
- /// <summary>
- /// Determines whether the specified sequence appears at the start of the span.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool StartsWith<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- int valueLength = value.Length;
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- nuint size = (nuint)Unsafe.SizeOf<T>();
- return valueLength <= span.Length &&
- SpanHelpers.SequenceEqual(
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)),
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)),
- ((nuint)valueLength) * size); // If this multiplication overflows, the Span we got overflows the entire address range. There's no happy outcome for this api in such a case so we choose not to take the overhead of checking.
- }
-
- return valueLength <= span.Length && SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(value), valueLength);
- }
-
- /// <summary>
- /// Determines whether the specified sequence appears at the end of the span.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool EndsWith<T>(this Span<T> span, ReadOnlySpan<T> value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- int spanLength = span.Length;
- int valueLength = value.Length;
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- nuint size = (nuint)Unsafe.SizeOf<T>();
- return valueLength <= spanLength &&
- SpanHelpers.SequenceEqual(
- ref Unsafe.As<T, byte>(ref Unsafe.Add(ref MemoryMarshal.GetReference(span), spanLength - valueLength)),
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)),
- ((nuint)valueLength) * size); // If this multiplication overflows, the Span we got overflows the entire address range. There's no happy outcome for this api in such a case so we choose not to take the overhead of checking.
- }
-
- return valueLength <= spanLength &&
- SpanHelpers.SequenceEqual(
- ref Unsafe.Add(ref MemoryMarshal.GetReference(span), spanLength - valueLength),
- ref MemoryMarshal.GetReference(value),
- valueLength);
- }
-
- /// <summary>
- /// Determines whether the specified sequence appears at the end of the span.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool EndsWith<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> value)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- int spanLength = span.Length;
- int valueLength = value.Length;
- if (RuntimeHelpers.IsBitwiseEquatable<T>())
- {
- nuint size = (nuint)Unsafe.SizeOf<T>();
- return valueLength <= spanLength &&
- SpanHelpers.SequenceEqual(
- ref Unsafe.As<T, byte>(ref Unsafe.Add(ref MemoryMarshal.GetReference(span), spanLength - valueLength)),
- ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(value)),
- ((nuint)valueLength) * size); // If this multiplication overflows, the Span we got overflows the entire address range. There's no happy outcome for this api in such a case so we choose not to take the overhead of checking.
- }
-
- return valueLength <= spanLength &&
- SpanHelpers.SequenceEqual(
- ref Unsafe.Add(ref MemoryMarshal.GetReference(span), spanLength - valueLength),
- ref MemoryMarshal.GetReference(value),
- valueLength);
- }
-
- /// <summary>
- /// Reverses the sequence of the elements in the entire span.
- /// </summary>
- public static void Reverse<T>(this Span<T> span)
- {
- if (span.Length <= 1)
- {
- return;
- }
-
- ref T first = ref MemoryMarshal.GetReference(span);
- ref T last = ref Unsafe.Add(ref Unsafe.Add(ref first, span.Length), -1);
- do
- {
- T temp = first;
- first = last;
- last = temp;
- first = ref Unsafe.Add(ref first, 1);
- last = ref Unsafe.Add(ref last, -1);
- } while (Unsafe.IsAddressLessThan(ref first, ref last));
- }
-
- /// <summary>
- /// Creates a new span over the target array.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> AsSpan<T>(this T[]? array)
- {
- return new Span<T>(array);
- }
-
- /// <summary>
- /// Creates a new Span over the portion of the target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="array">The target array.</param>
- /// <param name="start">The index at which to begin the Span.</param>
- /// <param name="length">The number of items in the Span.</param>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> AsSpan<T>(this T[]? array, int start, int length)
- {
- return new Span<T>(array, start, length);
- }
-
- /// <summary>
- /// Creates a new span over the portion of the target array segment.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> AsSpan<T>(this ArraySegment<T> segment)
- {
- return new Span<T>(segment.Array, segment.Offset, segment.Count);
- }
-
- /// <summary>
- /// Creates a new Span over the portion of the target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="segment">The target array.</param>
- /// <param name="start">The index at which to begin the Span.</param>
- /// <remarks>Returns default when <paramref name="segment"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="segment"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;segment.Count).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> AsSpan<T>(this ArraySegment<T> segment, int start)
- {
- if (((uint)start) > (uint)segment.Count)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
-
- return new Span<T>(segment.Array, segment.Offset + start, segment.Count - start);
- }
-
- /// <summary>
- /// Creates a new Span over the portion of the target array beginning
- /// at 'startIndex' and ending at the end of the segment.
- /// </summary>
- /// <param name="segment">The target array.</param>
- /// <param name="startIndex">The index at which to begin the Span.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> AsSpan<T>(this ArraySegment<T> segment, Index startIndex)
- {
- int actualIndex = startIndex.GetOffset(segment.Count);
- return AsSpan(segment, actualIndex);
- }
-
- /// <summary>
- /// Creates a new Span over the portion of the target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="segment">The target array.</param>
- /// <param name="start">The index at which to begin the Span.</param>
- /// <param name="length">The number of items in the Span.</param>
- /// <remarks>Returns default when <paramref name="segment"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="segment"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;segment.Count).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> AsSpan<T>(this ArraySegment<T> segment, int start, int length)
- {
- if (((uint)start) > (uint)segment.Count)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
- if (((uint)length) > (uint)(segment.Count - start))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
-
- return new Span<T>(segment.Array, segment.Offset + start, length);
- }
-
- /// <summary>
- /// Creates a new Span over the portion of the target array using the range start and end indexes
- /// </summary>
- /// <param name="segment">The target array.</param>
- /// <param name="range">The range which has start and end indexes to use for slicing the array.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> AsSpan<T>(this ArraySegment<T> segment, Range range)
- {
- (int start, int length) = range.GetOffsetAndLength(segment.Count);
- return new Span<T>(segment.Array, segment.Offset + start, length);
- }
-
- /// <summary>
- /// Creates a new memory over the target array.
- /// </summary>
- public static Memory<T> AsMemory<T>(this T[]? array) => new Memory<T>(array);
-
- /// <summary>
- /// Creates a new memory over the portion of the target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="array">The target array.</param>
- /// <param name="start">The index at which to begin the memory.</param>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;array.Length).
- /// </exception>
- public static Memory<T> AsMemory<T>(this T[]? array, int start) => new Memory<T>(array, start);
-
- /// <summary>
- /// Creates a new memory over the portion of the target array starting from
- /// 'startIndex' to the end of the array.
- /// </summary>
- public static Memory<T> AsMemory<T>(this T[]? array, Index startIndex)
- {
- if (array == null)
- {
- if (!startIndex.Equals(Index.Start))
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
-
- return default;
- }
-
- int actualIndex = startIndex.GetOffset(array.Length);
- return new Memory<T>(array, actualIndex);
- }
-
- /// <summary>
- /// Creates a new memory over the portion of the target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="array">The target array.</param>
- /// <param name="start">The index at which to begin the memory.</param>
- /// <param name="length">The number of items in the memory.</param>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;Length).
- /// </exception>
- public static Memory<T> AsMemory<T>(this T[]? array, int start, int length) => new Memory<T>(array, start, length);
-
- /// <summary>
- /// Creates a new memory over the portion of the target array beginning at inclusive start index of the range
- /// and ending at the exclusive end index of the range.
- /// </summary>
- public static Memory<T> AsMemory<T>(this T[]? array, Range range)
- {
- if (array == null)
- {
- Index startIndex = range.Start;
- Index endIndex = range.End;
- if (!startIndex.Equals(Index.Start) || !endIndex.Equals(Index.Start))
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
-
- return default;
- }
-
- (int start, int length) = range.GetOffsetAndLength(array.Length);
- return new Memory<T>(array, start, length);
- }
-
- /// <summary>
- /// Creates a new memory over the portion of the target array.
- /// </summary>
- public static Memory<T> AsMemory<T>(this ArraySegment<T> segment) => new Memory<T>(segment.Array, segment.Offset, segment.Count);
-
- /// <summary>
- /// Creates a new memory over the portion of the target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="segment">The target array.</param>
- /// <param name="start">The index at which to begin the memory.</param>
- /// <remarks>Returns default when <paramref name="segment"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="segment"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;segment.Count).
- /// </exception>
- public static Memory<T> AsMemory<T>(this ArraySegment<T> segment, int start)
- {
- if (((uint)start) > (uint)segment.Count)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
-
- return new Memory<T>(segment.Array, segment.Offset + start, segment.Count - start);
- }
-
- /// <summary>
- /// Creates a new memory over the portion of the target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="segment">The target array.</param>
- /// <param name="start">The index at which to begin the memory.</param>
- /// <param name="length">The number of items in the memory.</param>
- /// <remarks>Returns default when <paramref name="segment"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="segment"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;segment.Count).
- /// </exception>
- public static Memory<T> AsMemory<T>(this ArraySegment<T> segment, int start, int length)
- {
- if (((uint)start) > (uint)segment.Count)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
- if (((uint)length) > (uint)(segment.Count - start))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
-
- return new Memory<T>(segment.Array, segment.Offset + start, length);
- }
-
- /// <summary>
- /// Copies the contents of the array into the span. If the source
- /// and destinations overlap, this method behaves as if the original values in
- /// a temporary location before the destination is overwritten.
- ///
- ///<param name="source">The array to copy items from.</param>
- /// <param name="destination">The span to copy items into.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when the destination Span is shorter than the source array.
- /// </exception>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void CopyTo<T>(this T[]? source, Span<T> destination)
- {
- new ReadOnlySpan<T>(source).CopyTo(destination);
- }
-
- /// <summary>
- /// Copies the contents of the array into the memory. If the source
- /// and destinations overlap, this method behaves as if the original values are in
- /// a temporary location before the destination is overwritten.
- ///
- ///<param name="source">The array to copy items from.</param>
- /// <param name="destination">The memory to copy items into.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when the destination is shorter than the source array.
- /// </exception>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void CopyTo<T>(this T[]? source, Memory<T> destination)
- {
- source.CopyTo(destination.Span);
- }
-
- //
- // Overlaps
- // ========
- //
- // The following methods can be used to determine if two sequences
- // overlap in memory.
- //
- // Two sequences overlap if they have positions in common and neither
- // is empty. Empty sequences do not overlap with any other sequence.
- //
- // If two sequences overlap, the element offset is the number of
- // elements by which the second sequence is offset from the first
- // sequence (i.e., second minus first). An exception is thrown if the
- // number is not a whole number, which can happen when a sequence of a
- // smaller type is cast to a sequence of a larger type with unsafe code
- // or NonPortableCast. If the sequences do not overlap, the offset is
- // meaningless and arbitrarily set to zero.
- //
- // Implementation
- // --------------
- //
- // Implementing this correctly is quite tricky due of two problems:
- //
- // * If the sequences refer to two different objects on the managed
- // heap, the garbage collector can move them freely around or change
- // their relative order in memory.
- //
- // * The distance between two sequences can be greater than
- // int.MaxValue (on a 32-bit system) or long.MaxValue (on a 64-bit
- // system).
- //
- // (For simplicity, the following text assumes a 32-bit system, but
- // everything also applies to a 64-bit system if every 32 is replaced a
- // 64.)
- //
- // The first problem is solved by calculating the distance with exactly
- // one atomic operation. If the garbage collector happens to move the
- // sequences afterwards and the sequences overlapped before, they will
- // still overlap after the move and their distance hasn't changed. If
- // the sequences did not overlap, the distance can change but the
- // sequences still won't overlap.
- //
- // The second problem is solved by making all addresses relative to the
- // start of the first sequence and performing all operations in
- // unsigned integer arithmetic modulo 2^32.
- //
- // Example
- // -------
- //
- // Let's say there are two sequences, x and y. Let
- //
- // ref T xRef = MemoryMarshal.GetReference(x)
- // uint xLength = x.Length * Unsafe.SizeOf<T>()
- // ref T yRef = MemoryMarshal.GetReference(y)
- // uint yLength = y.Length * Unsafe.SizeOf<T>()
- //
- // Visually, the two sequences are located somewhere in the 32-bit
- // address space as follows:
- //
- // [----------------------------------------------) normal address space
- // 0 2^32
- // [------------------) first sequence
- // xRef xRef + xLength
- // [--------------------------) . second sequence
- // yRef . yRef + yLength
- // : . . .
- // : . . .
- // . . .
- // . . .
- // . . .
- // [----------------------------------------------) relative address space
- // 0 . . 2^32
- // [------------------) : first sequence
- // x1 . x2 :
- // -------------) [------------- second sequence
- // y2 y1
- //
- // The idea is to make all addresses relative to xRef: Let x1 be the
- // start address of x in this relative address space, x2 the end
- // address of x, y1 the start address of y, and y2 the end address of
- // y:
- //
- // nuint x1 = 0
- // nuint x2 = xLength
- // nuint y1 = (nuint)Unsafe.ByteOffset(xRef, yRef)
- // nuint y2 = y1 + yLength
- //
- // xRef relative to xRef is 0.
- //
- // x2 is simply x1 + xLength. This cannot overflow.
- //
- // yRef relative to xRef is (yRef - xRef). If (yRef - xRef) is
- // negative, casting it to an unsigned 32-bit integer turns it into
- // (yRef - xRef + 2^32). So, in the example above, y1 moves to the right
- // of x2.
- //
- // y2 is simply y1 + yLength. Note that this can overflow, as in the
- // example above, which must be avoided.
- //
- // The two sequences do *not* overlap if y is entirely in the space
- // right of x in the relative address space. (It can't be left of it!)
- //
- // (y1 >= x2) && (y2 <= 2^32)
- //
- // Inversely, they do overlap if
- //
- // (y1 < x2) || (y2 > 2^32)
- //
- // After substituting x2 and y2 with their respective definition:
- //
- // == (y1 < xLength) || (y1 + yLength > 2^32)
- //
- // Since yLength can't be greater than the size of the address space,
- // the overflow can be avoided as follows:
- //
- // == (y1 < xLength) || (y1 > 2^32 - yLength)
- //
- // However, 2^32 cannot be stored in an unsigned 32-bit integer, so one
- // more change is needed to keep doing everything with unsigned 32-bit
- // integers:
- //
- // == (y1 < xLength) || (y1 > -yLength)
- //
- // Due to modulo arithmetic, this gives exactly same result *except* if
- // yLength is zero, since 2^32 - 0 is 0 and not 2^32. So the case
- // y.IsEmpty must be handled separately first.
- //
-
- /// <summary>
- /// Determines whether two sequences overlap in memory.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool Overlaps<T>(this Span<T> span, ReadOnlySpan<T> other)
- {
- return Overlaps((ReadOnlySpan<T>)span, other);
- }
-
- /// <summary>
- /// Determines whether two sequences overlap in memory and outputs the element offset.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool Overlaps<T>(this Span<T> span, ReadOnlySpan<T> other, out int elementOffset)
- {
- return Overlaps((ReadOnlySpan<T>)span, other, out elementOffset);
- }
-
- /// <summary>
- /// Determines whether two sequences overlap in memory.
- /// </summary>
- public static bool Overlaps<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other)
- {
- if (span.IsEmpty || other.IsEmpty)
- {
- return false;
- }
-
- IntPtr byteOffset = Unsafe.ByteOffset(
- ref MemoryMarshal.GetReference(span),
- ref MemoryMarshal.GetReference(other));
-
- if (Unsafe.SizeOf<IntPtr>() == sizeof(int))
- {
- return (uint)byteOffset < (uint)(span.Length * Unsafe.SizeOf<T>()) ||
- (uint)byteOffset > (uint)-(other.Length * Unsafe.SizeOf<T>());
- }
- else
- {
- return (ulong)byteOffset < (ulong)((long)span.Length * Unsafe.SizeOf<T>()) ||
- (ulong)byteOffset > (ulong)-((long)other.Length * Unsafe.SizeOf<T>());
- }
- }
-
- /// <summary>
- /// Determines whether two sequences overlap in memory and outputs the element offset.
- /// </summary>
- public static bool Overlaps<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other, out int elementOffset)
- {
- if (span.IsEmpty || other.IsEmpty)
- {
- elementOffset = 0;
- return false;
- }
-
- IntPtr byteOffset = Unsafe.ByteOffset(
- ref MemoryMarshal.GetReference(span),
- ref MemoryMarshal.GetReference(other));
-
- if (Unsafe.SizeOf<IntPtr>() == sizeof(int))
- {
- if ((uint)byteOffset < (uint)(span.Length * Unsafe.SizeOf<T>()) ||
- (uint)byteOffset > (uint)-(other.Length * Unsafe.SizeOf<T>()))
- {
- if ((int)byteOffset % Unsafe.SizeOf<T>() != 0)
- ThrowHelper.ThrowArgumentException_OverlapAlignmentMismatch();
-
- elementOffset = (int)byteOffset / Unsafe.SizeOf<T>();
- return true;
- }
- else
- {
- elementOffset = 0;
- return false;
- }
- }
- else
- {
- if ((ulong)byteOffset < (ulong)((long)span.Length * Unsafe.SizeOf<T>()) ||
- (ulong)byteOffset > (ulong)-((long)other.Length * Unsafe.SizeOf<T>()))
- {
- if ((long)byteOffset % Unsafe.SizeOf<T>() != 0)
- ThrowHelper.ThrowArgumentException_OverlapAlignmentMismatch();
-
- elementOffset = (int)((long)byteOffset / Unsafe.SizeOf<T>());
- return true;
- }
- else
- {
- elementOffset = 0;
- return false;
- }
- }
- }
-
- /// <summary>
- /// Searches an entire sorted <see cref="Span{T}"/> for a value
- /// using the specified <see cref="IComparable{T}"/> generic interface.
- /// </summary>
- /// <typeparam name="T">The element type of the span.</typeparam>
- /// <param name="span">The sorted <see cref="Span{T}"/> to search.</param>
- /// <param name="comparable">The <see cref="IComparable{T}"/> to use when comparing.</param>
- /// <returns>
- /// The zero-based index of <paramref name="comparable"/> in the sorted <paramref name="span"/>,
- /// if <paramref name="comparable"/> is found; otherwise, a negative number that is the bitwise complement
- /// of the index of the next element that is larger than <paramref name="comparable"/> or, if there is
- /// no larger element, the bitwise complement of <see cref="Span{T}.Length"/>.
- /// </returns>
- /// <exception cref="System.ArgumentNullException">
- /// <paramref name = "comparable" /> is <see langword="null"/> .
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int BinarySearch<T>(
- this Span<T> span, IComparable<T> comparable)
- {
- return BinarySearch<T, IComparable<T>>(span, comparable);
- }
-
- /// <summary>
- /// Searches an entire sorted <see cref="Span{T}"/> for a value
- /// using the specified <typeparamref name="TComparable"/> generic type.
- /// </summary>
- /// <typeparam name="T">The element type of the span.</typeparam>
- /// <typeparam name="TComparable">The specific type of <see cref="IComparable{T}"/>.</typeparam>
- /// <param name="span">The sorted <see cref="Span{T}"/> to search.</param>
- /// <param name="comparable">The <typeparamref name="TComparable"/> to use when comparing.</param>
- /// <returns>
- /// The zero-based index of <paramref name="comparable"/> in the sorted <paramref name="span"/>,
- /// if <paramref name="comparable"/> is found; otherwise, a negative number that is the bitwise complement
- /// of the index of the next element that is larger than <paramref name="comparable"/> or, if there is
- /// no larger element, the bitwise complement of <see cref="Span{T}.Length"/>.
- /// </returns>
- /// <exception cref="System.ArgumentNullException">
- /// <paramref name = "comparable" /> is <see langword="null"/> .
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int BinarySearch<T, TComparable>(
- this Span<T> span, TComparable comparable)
- where TComparable : IComparable<T>
- {
- return BinarySearch((ReadOnlySpan<T>)span, comparable);
- }
-
- /// <summary>
- /// Searches an entire sorted <see cref="Span{T}"/> for the specified <paramref name="value"/>
- /// using the specified <typeparamref name="TComparer"/> generic type.
- /// </summary>
- /// <typeparam name="T">The element type of the span.</typeparam>
- /// <typeparam name="TComparer">The specific type of <see cref="IComparer{T}"/>.</typeparam>
- /// <param name="span">The sorted <see cref="Span{T}"/> to search.</param>
- /// <param name="value">The object to locate. The value can be null for reference types.</param>
- /// <param name="comparer">The <typeparamref name="TComparer"/> to use when comparing.</param>
- /// /// <returns>
- /// The zero-based index of <paramref name="value"/> in the sorted <paramref name="span"/>,
- /// if <paramref name="value"/> is found; otherwise, a negative number that is the bitwise complement
- /// of the index of the next element that is larger than <paramref name="value"/> or, if there is
- /// no larger element, the bitwise complement of <see cref="Span{T}.Length"/>.
- /// </returns>
- /// <exception cref="System.ArgumentNullException">
- /// <paramref name = "comparer" /> is <see langword="null"/> .
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int BinarySearch<T, TComparer>(
- this Span<T> span, T value, TComparer comparer)
- where TComparer : IComparer<T>
- {
- return BinarySearch((ReadOnlySpan<T>)span, value, comparer);
- }
-
- /// <summary>
- /// Searches an entire sorted <see cref="ReadOnlySpan{T}"/> for a value
- /// using the specified <see cref="IComparable{T}"/> generic interface.
- /// </summary>
- /// <typeparam name="T">The element type of the span.</typeparam>
- /// <param name="span">The sorted <see cref="ReadOnlySpan{T}"/> to search.</param>
- /// <param name="comparable">The <see cref="IComparable{T}"/> to use when comparing.</param>
- /// <returns>
- /// The zero-based index of <paramref name="comparable"/> in the sorted <paramref name="span"/>,
- /// if <paramref name="comparable"/> is found; otherwise, a negative number that is the bitwise complement
- /// of the index of the next element that is larger than <paramref name="comparable"/> or, if there is
- /// no larger element, the bitwise complement of <see cref="ReadOnlySpan{T}.Length"/>.
- /// </returns>
- /// <exception cref="System.ArgumentNullException">
- /// <paramref name = "comparable" /> is <see langword="null"/> .
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int BinarySearch<T>(
- this ReadOnlySpan<T> span, IComparable<T> comparable)
- {
- return BinarySearch<T, IComparable<T>>(span, comparable);
- }
-
- /// <summary>
- /// Searches an entire sorted <see cref="ReadOnlySpan{T}"/> for a value
- /// using the specified <typeparamref name="TComparable"/> generic type.
- /// </summary>
- /// <typeparam name="T">The element type of the span.</typeparam>
- /// <typeparam name="TComparable">The specific type of <see cref="IComparable{T}"/>.</typeparam>
- /// <param name="span">The sorted <see cref="ReadOnlySpan{T}"/> to search.</param>
- /// <param name="comparable">The <typeparamref name="TComparable"/> to use when comparing.</param>
- /// <returns>
- /// The zero-based index of <paramref name="comparable"/> in the sorted <paramref name="span"/>,
- /// if <paramref name="comparable"/> is found; otherwise, a negative number that is the bitwise complement
- /// of the index of the next element that is larger than <paramref name="comparable"/> or, if there is
- /// no larger element, the bitwise complement of <see cref="ReadOnlySpan{T}.Length"/>.
- /// </returns>
- /// <exception cref="System.ArgumentNullException">
- /// <paramref name = "comparable" /> is <see langword="null"/> .
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int BinarySearch<T, TComparable>(
- this ReadOnlySpan<T> span, TComparable comparable)
- where TComparable : IComparable<T>
- {
- return SpanHelpers.BinarySearch(span, comparable);
- }
-
- /// <summary>
- /// Searches an entire sorted <see cref="ReadOnlySpan{T}"/> for the specified <paramref name="value"/>
- /// using the specified <typeparamref name="TComparer"/> generic type.
- /// </summary>
- /// <typeparam name="T">The element type of the span.</typeparam>
- /// <typeparam name="TComparer">The specific type of <see cref="IComparer{T}"/>.</typeparam>
- /// <param name="span">The sorted <see cref="ReadOnlySpan{T}"/> to search.</param>
- /// <param name="value">The object to locate. The value can be null for reference types.</param>
- /// <param name="comparer">The <typeparamref name="TComparer"/> to use when comparing.</param>
- /// /// <returns>
- /// The zero-based index of <paramref name="value"/> in the sorted <paramref name="span"/>,
- /// if <paramref name="value"/> is found; otherwise, a negative number that is the bitwise complement
- /// of the index of the next element that is larger than <paramref name="value"/> or, if there is
- /// no larger element, the bitwise complement of <see cref="ReadOnlySpan{T}.Length"/>.
- /// </returns>
- /// <exception cref="System.ArgumentNullException">
- /// <paramref name = "comparer" /> is <see langword="null"/> .
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int BinarySearch<T, TComparer>(
- this ReadOnlySpan<T> span, T value, TComparer comparer)
- where TComparer : IComparer<T>
- {
- if (comparer == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer);
-
- var comparable = new SpanHelpers.ComparerComparable<T, TComparer>(
- value, comparer);
- return BinarySearch(span, comparable);
- }
-
- /// <summary>
- /// Sorts the elements in the entire <see cref="Span{T}" /> using the <see cref="IComparable{T}" /> implementation
- /// of each element of the <see cref= "Span{T}" />
- /// </summary>
- /// <typeparam name="T">The type of the elements of the span.</typeparam>
- /// <param name="span">The <see cref="Span{T}"/> to sort.</param>
- /// <exception cref="InvalidOperationException">
- /// One or more elements in <paramref name="span"/> do not implement the <see cref="IComparable{T}" /> interface.
- /// </exception>
- public static void Sort<T>(this Span<T> span) =>
- Sort(span, (IComparer<T>?)null);
-
- /// <summary>
- /// Sorts the elements in the entire <see cref="Span{T}" /> using the <typeparamref name="TComparer" />.
- /// </summary>
- /// <typeparam name="T">The type of the elements of the span.</typeparam>
- /// <typeparam name="TComparer">The type of the comparer to use to compare elements.</typeparam>
- /// <param name="span">The <see cref="Span{T}"/> to sort.</param>
- /// <param name="comparer">
- /// The <see cref="IComparer{T}"/> implementation to use when comparing elements, or null to
- /// use the <see cref="IComparable{T}"/> interface implementation of each element.
- /// </param>
- /// <exception cref="InvalidOperationException">
- /// <paramref name="comparer"/> is null, and one or more elements in <paramref name="span"/> do not
- /// implement the <see cref="IComparable{T}" /> interface.
- /// </exception>
- /// <exception cref="ArgumentException">
- /// The implementation of <paramref name="comparer"/> caused an error during the sort.
- /// </exception>
- public static void Sort<T, TComparer>(this Span<T> span, TComparer comparer)
- where TComparer : IComparer<T>?
- {
- if (span.Length > 1)
- {
- ArraySortHelper<T>.Default.Sort(span, comparer); // value-type comparer will be boxed
- }
- }
-
- /// <summary>
- /// Sorts the elements in the entire <see cref="Span{T}" /> using the specified <see cref="Comparison{T}" />.
- /// </summary>
- /// <typeparam name="T">The type of the elements of the span.</typeparam>
- /// <param name="span">The <see cref="Span{T}"/> to sort.</param>
- /// <param name="comparison">The <see cref="Comparison{T}"/> to use when comparing elements.</param>
- /// <exception cref="ArgumentNullException"><paramref name="comparison"/> is null.</exception>
- public static void Sort<T>(this Span<T> span, Comparison<T> comparison)
- {
- if (comparison == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison);
-
- if (span.Length > 1)
- {
- ArraySortHelper<T>.Sort(span, comparison);
- }
- }
-
- /// <summary>
- /// Sorts a pair of spans (one containing the keys and the other containing the corresponding items)
- /// based on the keys in the first <see cref="Span{TKey}" /> using the <see cref="IComparable{T}" />
- /// implementation of each key.
- /// </summary>
- /// <typeparam name="TKey">The type of the elements of the key span.</typeparam>
- /// <typeparam name="TValue">The type of the elements of the items span.</typeparam>
- /// <param name="keys">The span that contains the keys to sort.</param>
- /// <param name="items">The span that contains the items that correspond to the keys in <paramref name="keys"/>.</param>
- /// <exception cref="ArgumentException">
- /// The length of <paramref name="keys"/> isn't equal to the length of <paramref name="items"/>.
- /// </exception>
- /// <exception cref="InvalidOperationException">
- /// One or more elements in <paramref name="keys"/> do not implement the <see cref="IComparable{T}" /> interface.
- /// </exception>
- public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> items) =>
- Sort(keys, items, (IComparer<TKey>?)null);
-
- /// <summary>
- /// Sorts a pair of spans (one containing the keys and the other containing the corresponding items)
- /// based on the keys in the first <see cref="Span{TKey}" /> using the specified comparer.
- /// </summary>
- /// <typeparam name="TKey">The type of the elements of the key span.</typeparam>
- /// <typeparam name="TValue">The type of the elements of the items span.</typeparam>
- /// <typeparam name="TComparer">The type of the comparer to use to compare elements.</typeparam>
- /// <param name="keys">The span that contains the keys to sort.</param>
- /// <param name="items">The span that contains the items that correspond to the keys in <paramref name="keys"/>.</param>
- /// <param name="comparer">
- /// The <see cref="IComparer{T}"/> implementation to use when comparing elements, or null to
- /// use the <see cref="IComparable{T}"/> interface implementation of each element.
- /// </param>
- /// <exception cref="ArgumentException">
- /// The length of <paramref name="keys"/> isn't equal to the length of <paramref name="items"/>.
- /// </exception>
- /// <exception cref="InvalidOperationException">
- /// <paramref name="comparer"/> is null, and one or more elements in <paramref name="keys"/> do not
- /// implement the <see cref="IComparable{T}" /> interface.
- /// </exception>
- public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TValue> items, TComparer comparer)
- where TComparer : IComparer<TKey>?
- {
- if (keys.Length != items.Length)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_SpansMustHaveSameLength);
-
- if (keys.Length > 1)
- {
- ArraySortHelper<TKey, TValue>.Default.Sort(keys, items, comparer); // value-type comparer will be boxed
- }
- }
-
- /// <summary>
- /// Sorts a pair of spans (one containing the keys and the other containing the corresponding items)
- /// based on the keys in the first <see cref="Span{TKey}" /> using the specified comparison.
- /// </summary>
- /// <typeparam name="TKey">The type of the elements of the key span.</typeparam>
- /// <typeparam name="TValue">The type of the elements of the items span.</typeparam>
- /// <param name="keys">The span that contains the keys to sort.</param>
- /// <param name="items">The span that contains the items that correspond to the keys in <paramref name="keys"/>.</param>
- /// <param name="comparison">The <see cref="Comparison{T}"/> to use when comparing elements.</param>
- /// <exception cref="ArgumentNullException"><paramref name="comparison"/> is null.</exception>
- /// <exception cref="ArgumentException">
- /// The length of <paramref name="keys"/> isn't equal to the length of <paramref name="items"/>.
- /// </exception>
- public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> items, Comparison<TKey> comparison)
- {
- if (comparison == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison);
- if (keys.Length != items.Length)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_SpansMustHaveSameLength);
-
- if (keys.Length > 1)
- {
- ArraySortHelper<TKey, TValue>.Default.Sort(keys, items, new ComparisonComparer<TKey>(comparison));
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MethodAccessException.cs b/netcore/System.Private.CoreLib/shared/System/MethodAccessException.cs
deleted file mode 100644
index 5a9445d0cca..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MethodAccessException.cs
+++ /dev/null
@@ -1,42 +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.
-
-/*=============================================================================
-**
-**
-** Purpose: The exception class for class loading failures.
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class MethodAccessException : MemberAccessException
- {
- public MethodAccessException()
- : base(SR.Arg_MethodAccessException)
- {
- HResult = HResults.COR_E_METHODACCESS;
- }
-
- public MethodAccessException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_METHODACCESS;
- }
-
- public MethodAccessException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_METHODACCESS;
- }
-
- protected MethodAccessException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MidpointRounding.cs b/netcore/System.Private.CoreLib/shared/System/MidpointRounding.cs
deleted file mode 100644
index 835dafe7eee..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MidpointRounding.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System
-{
- public enum MidpointRounding
- {
- ToEven = 0,
- AwayFromZero = 1,
- ToZero = 2,
- ToNegativeInfinity = 3,
- ToPositiveInfinity = 4
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MissingFieldException.cs b/netcore/System.Private.CoreLib/shared/System/MissingFieldException.cs
deleted file mode 100644
index 6297177c1e4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MissingFieldException.cs
+++ /dev/null
@@ -1,58 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class MissingFieldException : MissingMemberException, ISerializable
- {
- public MissingFieldException()
- : base(SR.Arg_MissingFieldException)
- {
- HResult = HResults.COR_E_MISSINGFIELD;
- }
-
- public MissingFieldException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_MISSINGFIELD;
- }
-
- public MissingFieldException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_MISSINGFIELD;
- }
-
- public MissingFieldException(string? className, string? fieldName)
- {
- ClassName = className;
- MemberName = fieldName;
- }
-
- protected MissingFieldException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
-
- public override string Message
- {
- get
- {
- if (ClassName == null)
- {
- return base.Message;
- }
- else
- {
- // do any desired fixups to classname here.
- return SR.Format(SR.MissingField_Name, (Signature != null ? FormatSignature(Signature) + " " : "") + ClassName + "." + MemberName);
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MissingMemberException.cs b/netcore/System.Private.CoreLib/shared/System/MissingMemberException.cs
deleted file mode 100644
index 8ba7b53e311..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MissingMemberException.cs
+++ /dev/null
@@ -1,76 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public partial class MissingMemberException : MemberAccessException
- {
- public MissingMemberException()
- : base(SR.Arg_MissingMemberException)
- {
- HResult = HResults.COR_E_MISSINGMEMBER;
- }
-
- public MissingMemberException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_MISSINGMEMBER;
- }
-
- public MissingMemberException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_MISSINGMEMBER;
- }
-
- public MissingMemberException(string? className, string? memberName)
- {
- ClassName = className;
- MemberName = memberName;
- }
-
- protected MissingMemberException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- ClassName = info.GetString("MMClassName");
- MemberName = info.GetString("MMMemberName");
- Signature = (byte[]?)info.GetValue("MMSignature", typeof(byte[]));
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("MMClassName", ClassName, typeof(string));
- info.AddValue("MMMemberName", MemberName, typeof(string));
- info.AddValue("MMSignature", Signature, typeof(byte[]));
- }
-
- public override string Message
- {
- get
- {
- if (ClassName == null)
- {
- return base.Message;
- }
- else
- {
- // do any desired fixups to classname here.
- return SR.Format(SR.MissingMember_Name, ClassName + "." + MemberName + (Signature != null ? " " + FormatSignature(Signature) : string.Empty));
- }
- }
- }
-
- // If ClassName != null, GetMessage will construct on the fly using it
- // and the other variables. This allows customization of the
- // format depending on the language environment.
- protected string? ClassName;
- protected string? MemberName;
- protected byte[]? Signature;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MissingMethodException.cs b/netcore/System.Private.CoreLib/shared/System/MissingMethodException.cs
deleted file mode 100644
index 05436df2f13..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MissingMethodException.cs
+++ /dev/null
@@ -1,57 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: The exception class for class loading failures.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class MissingMethodException : MissingMemberException
- {
- public MissingMethodException()
- : base(SR.Arg_MissingMethodException)
- {
- HResult = HResults.COR_E_MISSINGMETHOD;
- }
-
- public MissingMethodException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_MISSINGMETHOD;
- }
-
- public MissingMethodException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_MISSINGMETHOD;
- }
-
- public MissingMethodException(string? className, string? methodName)
- {
- ClassName = className;
- MemberName = methodName;
- }
-
- protected MissingMethodException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
-
- public override string Message =>
- ClassName == null ?
- base.Message :
- SR.Format(SR.MissingMethod_Name, ClassName + "." + MemberName +
- (Signature != null ? " " + FormatSignature(Signature) : string.Empty));
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/MulticastNotSupportedException.cs b/netcore/System.Private.CoreLib/shared/System/MulticastNotSupportedException.cs
deleted file mode 100644
index 34c7ed5d531..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/MulticastNotSupportedException.cs
+++ /dev/null
@@ -1,40 +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.
-
-////////////////////////////////////////////////////////////////////////////////
-// MulticastNotSupportedException
-// This is thrown when you add multiple callbacks to a non-multicast delegate.
-////////////////////////////////////////////////////////////////////////////////
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class MulticastNotSupportedException : SystemException
- {
- public MulticastNotSupportedException()
- : base(SR.Arg_MulticastNotSupportedException)
- {
- HResult = HResults.COR_E_MULTICASTNOTSUPPORTED;
- }
-
- public MulticastNotSupportedException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_MULTICASTNOTSUPPORTED;
- }
-
- public MulticastNotSupportedException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_MULTICASTNOTSUPPORTED;
- }
-
- private MulticastNotSupportedException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/NonSerializedAttribute.cs b/netcore/System.Private.CoreLib/shared/System/NonSerializedAttribute.cs
deleted file mode 100644
index cabd5a2aa25..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/NonSerializedAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System
-{
- [AttributeUsage(AttributeTargets.Field, Inherited = false)]
- public sealed class NonSerializedAttribute : Attribute
- {
- public NonSerializedAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/NotFiniteNumberException.cs b/netcore/System.Private.CoreLib/shared/System/NotFiniteNumberException.cs
deleted file mode 100644
index f641a1ae3f8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/NotFiniteNumberException.cs
+++ /dev/null
@@ -1,68 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class NotFiniteNumberException : ArithmeticException
- {
- private readonly double _offendingNumber;
-
- public NotFiniteNumberException()
- : base(SR.Arg_NotFiniteNumberException)
- {
- _offendingNumber = 0;
- HResult = HResults.COR_E_NOTFINITENUMBER;
- }
-
- public NotFiniteNumberException(double offendingNumber)
- {
- _offendingNumber = offendingNumber;
- HResult = HResults.COR_E_NOTFINITENUMBER;
- }
-
- public NotFiniteNumberException(string? message)
- : base(message)
- {
- _offendingNumber = 0;
- HResult = HResults.COR_E_NOTFINITENUMBER;
- }
-
- public NotFiniteNumberException(string? message, double offendingNumber)
- : base(message)
- {
- _offendingNumber = offendingNumber;
- HResult = HResults.COR_E_NOTFINITENUMBER;
- }
-
- public NotFiniteNumberException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_NOTFINITENUMBER;
- }
-
- public NotFiniteNumberException(string? message, double offendingNumber, Exception? innerException)
- : base(message, innerException)
- {
- _offendingNumber = offendingNumber;
- HResult = HResults.COR_E_NOTFINITENUMBER;
- }
-
- protected NotFiniteNumberException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- _offendingNumber = info.GetDouble("OffendingNumber"); // Do not rename (binary serialization)
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("OffendingNumber", _offendingNumber, typeof(double)); // Do not rename (binary serialization)
- }
-
- public double OffendingNumber => _offendingNumber;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/NotImplementedException.cs b/netcore/System.Private.CoreLib/shared/System/NotImplementedException.cs
deleted file mode 100644
index 8f443476ff7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/NotImplementedException.cs
+++ /dev/null
@@ -1,43 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception thrown when a requested method or operation is not
-** implemented.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class NotImplementedException : SystemException
- {
- public NotImplementedException()
- : base(SR.Arg_NotImplementedException)
- {
- HResult = HResults.E_NOTIMPL;
- }
- public NotImplementedException(string? message)
- : base(message)
- {
- HResult = HResults.E_NOTIMPL;
- }
- public NotImplementedException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.E_NOTIMPL;
- }
-
- protected NotImplementedException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/NotSupportedException.cs b/netcore/System.Private.CoreLib/shared/System/NotSupportedException.cs
deleted file mode 100644
index 61c186844f3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/NotSupportedException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: For methods that should be implemented on subclasses.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class NotSupportedException : SystemException
- {
- public NotSupportedException()
- : base(SR.Arg_NotSupportedException)
- {
- HResult = HResults.COR_E_NOTSUPPORTED;
- }
-
- public NotSupportedException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_NOTSUPPORTED;
- }
-
- public NotSupportedException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_NOTSUPPORTED;
- }
-
- protected NotSupportedException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/NullReferenceException.cs b/netcore/System.Private.CoreLib/shared/System/NullReferenceException.cs
deleted file mode 100644
index 6b1a0350add..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/NullReferenceException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class for dereferencing a null reference.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class NullReferenceException : SystemException
- {
- public NullReferenceException()
- : base(SR.Arg_NullReferenceException)
- {
- HResult = HResults.COR_E_NULLREFERENCE;
- }
-
- public NullReferenceException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_NULLREFERENCE;
- }
-
- public NullReferenceException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_NULLREFERENCE;
- }
-
- protected NullReferenceException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Nullable.cs b/netcore/System.Private.CoreLib/shared/System/Nullable.cs
deleted file mode 100644
index b3ecf622128..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Nullable.cs
+++ /dev/null
@@ -1,133 +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 System.Collections.Generic;
-using System.Runtime.Versioning;
-
-namespace System
-{
- // Because we have special type system support that says a boxed Nullable<T>
- // can be used where a boxed<T> is use, Nullable<T> can not implement any intefaces
- // at all (since T may not). Do NOT add any interfaces to Nullable!
- //
- [Serializable]
- [NonVersionable] // This only applies to field layout
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public partial struct Nullable<T> where T : struct
- {
- private readonly bool hasValue; // Do not rename (binary serialization)
- internal T value; // Do not rename (binary serialization) or make readonly (can be mutated in ToString, etc.)
-
- [NonVersionable]
- public Nullable(T value)
- {
- this.value = value;
- hasValue = true;
- }
-
- public bool HasValue
- {
- [NonVersionable]
- get => hasValue;
- }
-
- public T Value
- {
- get
- {
- if (!hasValue)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_NoValue();
- }
- return value;
- }
- }
-
- [NonVersionable]
- public T GetValueOrDefault() => value;
-
- [NonVersionable]
- public T GetValueOrDefault(T defaultValue) =>
- hasValue ? value : defaultValue;
-
- public override bool Equals(object? other)
- {
- if (!hasValue) return other == null;
- if (other == null) return false;
- return value.Equals(other);
- }
-
- public override int GetHashCode() => hasValue ? value.GetHashCode() : 0;
-
- public override string? ToString() => hasValue ? value.ToString() : "";
-
- [NonVersionable]
- public static implicit operator Nullable<T>(T value) =>
- new Nullable<T>(value);
-
- [NonVersionable]
- public static explicit operator T(Nullable<T> value) => value!.Value;
- }
-
- public static class Nullable
- {
- public static int Compare<T>(Nullable<T> n1, Nullable<T> n2) where T : struct
- {
- if (n1.HasValue)
- {
- if (n2.HasValue) return Comparer<T>.Default.Compare(n1.value, n2.value);
- return 1;
- }
- if (n2.HasValue) return -1;
- return 0;
- }
-
- public static bool Equals<T>(Nullable<T> n1, Nullable<T> n2) where T : struct
- {
- if (n1.HasValue)
- {
- if (n2.HasValue) return EqualityComparer<T>.Default.Equals(n1.value, n2.value);
- return false;
- }
- if (n2.HasValue) return false;
- return true;
- }
-
- // If the type provided is not a Nullable Type, return null.
- // Otherwise, returns the underlying type of the Nullable type
- public static Type? GetUnderlyingType(Type nullableType)
- {
- if ((object)nullableType == null)
- {
- throw new ArgumentNullException(nameof(nullableType));
- }
-
-#if CORERT
- // This is necessary to handle types without reflection metadata
- if (nullableType.TryGetEEType(out EETypePtr nullableEEType))
- {
- if (nullableEEType.IsGeneric)
- {
- if (nullableEEType.IsNullable)
- {
- return Internal.Reflection.Core.NonPortable.RuntimeTypeUnifier.GetRuntimeTypeForEEType(nullableEEType.NullableType);
- }
- }
- return null;
- }
-#endif
-
- if (nullableType.IsGenericType && !nullableType.IsGenericTypeDefinition)
- {
- // instantiated generic type only
- Type genericType = nullableType.GetGenericTypeDefinition();
- if (object.ReferenceEquals(genericType, typeof(Nullable<>)))
- {
- return nullableType.GetGenericArguments()[0];
- }
- }
- return null;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Number.BigInteger.cs b/netcore/System.Private.CoreLib/shared/System/Number.BigInteger.cs
deleted file mode 100644
index 8c19c990671..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Number.BigInteger.cs
+++ /dev/null
@@ -1,1245 +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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.InteropServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- internal static partial class Number
- {
- [StructLayout(LayoutKind.Sequential, Pack = 1)]
- internal unsafe ref struct BigInteger
- {
- // The longest binary mantissa requires: explicit mantissa bits + abs(min exponent)
- // * Half: 10 + 14 = 24
- // * Single: 23 + 126 = 149
- // * Double: 52 + 1022 = 1074
- // * Quad: 112 + 16382 = 16494
- private const int BitsForLongestBinaryMantissa = 1074;
-
- // The longest digit sequence requires: ceil(log2(pow(10, max significant digits + 1 rounding digit)))
- // * Half: ceil(log2(pow(10, 21 + 1))) = 74
- // * Single: ceil(log2(pow(10, 112 + 1))) = 376
- // * Double: ceil(log2(pow(10, 767 + 1))) = 2552
- // * Quad: ceil(log2(pow(10, 11563 + 1))) = 38415
- private const int BitsForLongestDigitSequence = 2552;
-
- // We require BitsPerBlock additional bits for shift space used during the pre-division preparation
- private const int MaxBits = BitsForLongestBinaryMantissa + BitsForLongestDigitSequence + BitsPerBlock;
-
- private const int BitsPerBlock = sizeof(int) * 8;
- private const int MaxBlockCount = (MaxBits + (BitsPerBlock - 1)) / BitsPerBlock;
-
- private static readonly uint[] s_Pow10UInt32Table = new uint[]
- {
- 1, // 10^0
- 10, // 10^1
- 100, // 10^2
- 1000, // 10^3
- 10000, // 10^4
- 100000, // 10^5
- 1000000, // 10^6
- 10000000, // 10^7
- };
-
- private static readonly int[] s_Pow10BigNumTableIndices = new int[]
- {
- 0, // 10^8
- 2, // 10^16
- 5, // 10^32
- 10, // 10^64
- 18, // 10^128
- 33, // 10^256
- 61, // 10^512
- 116, // 10^1024
- };
-
- private static readonly uint[] s_Pow10BigNumTable = new uint[]
- {
- // 10^8
- 1, // _length
- 100000000, // _blocks
-
- // 10^16
- 2, // _length
- 0x6FC10000, // _blocks
- 0x002386F2,
-
- // 10^32
- 4, // _length
- 0x00000000, // _blocks
- 0x85ACEF81,
- 0x2D6D415B,
- 0x000004EE,
-
- // 10^64
- 7, // _length
- 0x00000000, // _blocks
- 0x00000000,
- 0xBF6A1F01,
- 0x6E38ED64,
- 0xDAA797ED,
- 0xE93FF9F4,
- 0x00184F03,
-
- // 10^128
- 14, // _length
- 0x00000000, // _blocks
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x2E953E01,
- 0x03DF9909,
- 0x0F1538FD,
- 0x2374E42F,
- 0xD3CFF5EC,
- 0xC404DC08,
- 0xBCCDB0DA,
- 0xA6337F19,
- 0xE91F2603,
- 0x0000024E,
-
- // 10^256
- 27, // _length
- 0x00000000, // _blocks
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x982E7C01,
- 0xBED3875B,
- 0xD8D99F72,
- 0x12152F87,
- 0x6BDE50C6,
- 0xCF4A6E70,
- 0xD595D80F,
- 0x26B2716E,
- 0xADC666B0,
- 0x1D153624,
- 0x3C42D35A,
- 0x63FF540E,
- 0xCC5573C0,
- 0x65F9EF17,
- 0x55BC28F2,
- 0x80DCC7F7,
- 0xF46EEDDC,
- 0x5FDCEFCE,
- 0x000553F7,
-
- // 10^512
- 54, // _length
- 0x00000000, // _blocks
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0xFC6CF801,
- 0x77F27267,
- 0x8F9546DC,
- 0x5D96976F,
- 0xB83A8A97,
- 0xC31E1AD9,
- 0x46C40513,
- 0x94E65747,
- 0xC88976C1,
- 0x4475B579,
- 0x28F8733B,
- 0xAA1DA1BF,
- 0x703ED321,
- 0x1E25CFEA,
- 0xB21A2F22,
- 0xBC51FB2E,
- 0x96E14F5D,
- 0xBFA3EDAC,
- 0x329C57AE,
- 0xE7FC7153,
- 0xC3FC0695,
- 0x85A91924,
- 0xF95F635E,
- 0xB2908EE0,
- 0x93ABADE4,
- 0x1366732A,
- 0x9449775C,
- 0x69BE5B0E,
- 0x7343AFAC,
- 0xB099BC81,
- 0x45A71D46,
- 0xA2699748,
- 0x8CB07303,
- 0x8A0B1F13,
- 0x8CAB8A97,
- 0xC1D238D9,
- 0x633415D4,
- 0x0000001C,
-
- // 10^1024
- 107, // _length
- 0x00000000, // _blocks
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x2919F001,
- 0xF55B2B72,
- 0x6E7C215B,
- 0x1EC29F86,
- 0x991C4E87,
- 0x15C51A88,
- 0x140AC535,
- 0x4C7D1E1A,
- 0xCC2CD819,
- 0x0ED1440E,
- 0x896634EE,
- 0x7DE16CFB,
- 0x1E43F61F,
- 0x9FCE837D,
- 0x231D2B9C,
- 0x233E55C7,
- 0x65DC60D7,
- 0xF451218B,
- 0x1C5CD134,
- 0xC9635986,
- 0x922BBB9F,
- 0xA7E89431,
- 0x9F9F2A07,
- 0x62BE695A,
- 0x8E1042C4,
- 0x045B7A74,
- 0x1ABE1DE3,
- 0x8AD822A5,
- 0xBA34C411,
- 0xD814B505,
- 0xBF3FDEB3,
- 0x8FC51A16,
- 0xB1B896BC,
- 0xF56DEEEC,
- 0x31FB6BFD,
- 0xB6F4654B,
- 0x101A3616,
- 0x6B7595FB,
- 0xDC1A47FE,
- 0x80D98089,
- 0x80BDA5A5,
- 0x9A202882,
- 0x31EB0F66,
- 0xFC8F1F90,
- 0x976A3310,
- 0xE26A7B7E,
- 0xDF68368A,
- 0x3CE3A0B8,
- 0x8E4262CE,
- 0x75A351A2,
- 0x6CB0B6C9,
- 0x44597583,
- 0x31B5653F,
- 0xC356E38A,
- 0x35FAABA6,
- 0x0190FBA0,
- 0x9FC4ED52,
- 0x88BC491B,
- 0x1640114A,
- 0x005B8041,
- 0xF4F3235E,
- 0x1E8D4649,
- 0x36A8DE06,
- 0x73C55349,
- 0xA7E6BD2A,
- 0xC1A6970C,
- 0x47187094,
- 0xD2DB49EF,
- 0x926C3F5B,
- 0xAE6209D4,
- 0x2D433949,
- 0x34F4A3C6,
- 0xD4305D94,
- 0xD9D61A05,
- 0x00000325,
-
- // 9 Trailing blocks to ensure MaxBlockCount
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- 0x00000000,
- };
-
- private int _length;
- private fixed uint _blocks[MaxBlockCount];
-
- public BigInteger(uint value)
- {
- _blocks[0] = value;
- _length = (value == 0) ? 0 : 1;
- }
-
- public BigInteger(ulong value)
- {
- uint lower = (uint)(value);
- uint upper = (uint)(value >> 32);
-
- _blocks[0] = lower;
- _blocks[1] = upper;
-
- _length = (upper == 0) ? 1 : 2;
- }
-
- public static void Add(ref BigInteger lhs, ref BigInteger rhs, out BigInteger result)
- {
- // determine which operand has the smaller length
- ref BigInteger large = ref (lhs._length < rhs._length) ? ref rhs : ref lhs;
- ref BigInteger small = ref (lhs._length < rhs._length) ? ref lhs : ref rhs;
-
- int largeLength = large._length;
- int smallLength = small._length;
-
- // The output will be at least as long as the largest input
- result = new BigInteger(0);
- result._length = largeLength;
-
- // Add each block and add carry the overflow to the next block
- ulong carry = 0;
-
- int largeIndex = 0;
- int smallIndex = 0;
- int resultIndex = 0;
-
- while (smallIndex < smallLength)
- {
- ulong sum = carry + large._blocks[largeIndex] + small._blocks[smallIndex];
- carry = sum >> 32;
- result._blocks[resultIndex] = (uint)(sum);
-
- largeIndex++;
- smallIndex++;
- resultIndex++;
- }
-
- // Add the carry to any blocks that only exist in the large operand
- while (largeIndex < largeLength)
- {
- ulong sum = carry + large._blocks[largeIndex];
- carry = sum >> 32;
- result._blocks[resultIndex] = (uint)(sum);
-
- largeIndex++;
- resultIndex++;
- }
-
- // If there's still a carry, append a new block
- if (carry != 0)
- {
- Debug.Assert(carry == 1);
- Debug.Assert((resultIndex == largeLength) && (largeLength < MaxBlockCount));
-
- result._blocks[resultIndex] = 1;
- result._length++;
- }
- }
-
- public static int Compare(ref BigInteger lhs, ref BigInteger rhs)
- {
- Debug.Assert(unchecked((uint)(lhs._length)) <= MaxBlockCount);
- Debug.Assert(unchecked((uint)(rhs._length)) <= MaxBlockCount);
-
- int lhsLength = lhs._length;
- int rhsLength = rhs._length;
-
- int lengthDelta = (lhsLength - rhsLength);
-
- if (lengthDelta != 0)
- {
- return lengthDelta;
- }
-
- if (lhsLength == 0)
- {
- Debug.Assert(rhsLength == 0);
- return 0;
- }
-
- for (int index = (lhsLength - 1); index >= 0; index--)
- {
- long delta = (long)(lhs._blocks[index]) - rhs._blocks[index];
-
- if (delta != 0)
- {
- return delta > 0 ? 1 : -1;
- }
- }
-
- return 0;
- }
-
- public static uint CountSignificantBits(uint value)
- {
- return 32 - (uint)BitOperations.LeadingZeroCount(value);
- }
-
- public static uint CountSignificantBits(ulong value)
- {
- return 64 - (uint)BitOperations.LeadingZeroCount(value);
- }
-
- public static uint CountSignificantBits(ref BigInteger value)
- {
- if (value.IsZero())
- {
- return 0;
- }
-
- // We don't track any unused blocks, so we only need to do a BSR on the
- // last index and add that to the number of bits we skipped.
-
- uint lastIndex = (uint)(value._length - 1);
- return (lastIndex * BitsPerBlock) + CountSignificantBits(value._blocks[lastIndex]);
- }
-
- public static void DivRem(ref BigInteger lhs, ref BigInteger rhs, out BigInteger quo, out BigInteger rem)
- {
- // This is modified from the CoreFX BigIntegerCalculator.DivRem.cs implementation:
- // https://github.com/dotnet/corefx/blob/0bb106232745aedfc0d0c5a84ff2b244bf190317/src/System.Runtime.Numerics/src/System/Numerics/BigIntegerCalculator.DivRem.cs
-
- Debug.Assert(!rhs.IsZero());
-
- quo = new BigInteger(0);
- rem = new BigInteger(0);
-
- if (lhs.IsZero())
- {
- return;
- }
-
- int lhsLength = lhs._length;
- int rhsLength = rhs._length;
-
- if ((lhsLength == 1) && (rhsLength == 1))
- {
- uint quotient = Math.DivRem(lhs._blocks[0], rhs._blocks[0], out uint remainder);
- quo = new BigInteger(quotient);
- rem = new BigInteger(remainder);
- return;
- }
-
- if (rhsLength == 1)
- {
- // We can make the computation much simpler if the rhs is only one block
-
- int quoLength = lhsLength;
-
- ulong rhsValue = rhs._blocks[0];
- ulong carry = 0;
-
- for (int i = quoLength - 1; i >= 0; i--)
- {
- ulong value = (carry << 32) | lhs._blocks[i];
- ulong digit = Math.DivRem(value, rhsValue, out carry);
-
- if ((digit == 0) && (i == (quoLength - 1)))
- {
- quoLength--;
- }
- else
- {
- quo._blocks[i] = (uint)(digit);
- }
- }
-
- quo._length = quoLength;
- rem.SetUInt32((uint)(carry));
-
- return;
- }
- else if (rhsLength > lhsLength)
- {
- // Handle the case where we have no quotient
- rem.SetValue(ref lhs);
- return;
- }
- else
- {
- int quoLength = lhsLength - rhsLength + 1;
- rem.SetValue(ref lhs);
- int remLength = lhsLength;
-
- // Executes the "grammar-school" algorithm for computing q = a / b.
- // Before calculating q_i, we get more bits into the highest bit
- // block of the divisor. Thus, guessing digits of the quotient
- // will be more precise. Additionally we'll get r = a % b.
-
- uint divHi = rhs._blocks[rhsLength - 1];
- uint divLo = rhs._blocks[rhsLength - 2];
-
- // We measure the leading zeros of the divisor
- int shiftLeft = BitOperations.LeadingZeroCount(divHi);
- int shiftRight = 32 - shiftLeft;
-
- // And, we make sure the most significant bit is set
- if (shiftLeft > 0)
- {
- divHi = (divHi << shiftLeft) | (divLo >> shiftRight);
- divLo <<= shiftLeft;
-
- if (rhsLength > 2)
- {
- divLo |= (rhs._blocks[rhsLength - 3] >> shiftRight);
- }
- }
-
- // Then, we divide all of the bits as we would do it using
- // pen and paper: guessing the next digit, subtracting, ...
- for (int i = lhsLength; i >= rhsLength; i--)
- {
- int n = i - rhsLength;
- uint t = i < lhsLength ? rem._blocks[i] : 0;
-
- ulong valHi = ((ulong)(t) << 32) | rem._blocks[i - 1];
- uint valLo = i > 1 ? rem._blocks[i - 2] : 0;
-
- // We shifted the divisor, we shift the dividend too
- if (shiftLeft > 0)
- {
- valHi = (valHi << shiftLeft) | (valLo >> shiftRight);
- valLo <<= shiftLeft;
-
- if (i > 2)
- {
- valLo |= (rem._blocks[i - 3] >> shiftRight);
- }
- }
-
- // First guess for the current digit of the quotient,
- // which naturally must have only 32 bits...
- ulong digit = valHi / divHi;
-
- if (digit > uint.MaxValue)
- {
- digit = uint.MaxValue;
- }
-
- // Our first guess may be a little bit to big
- while (DivideGuessTooBig(digit, valHi, valLo, divHi, divLo))
- {
- digit--;
- }
-
- if (digit > 0)
- {
- // Now it's time to subtract our current quotient
- uint carry = SubtractDivisor(ref rem, n, ref rhs, digit);
-
- if (carry != t)
- {
- Debug.Assert(carry == t + 1);
-
- // Our guess was still exactly one too high
- carry = AddDivisor(ref rem, n, ref rhs);
- digit--;
-
- Debug.Assert(carry == 1);
- }
- }
-
- // We have the digit!
- if (quoLength != 0)
- {
- if ((digit == 0) && (n == (quoLength - 1)))
- {
- quoLength--;
- }
- else
- {
- quo._blocks[n] = (uint)(digit);
- }
- }
-
- if (i < remLength)
- {
- remLength--;
- }
- }
-
- quo._length = quoLength;
-
- // We need to check for the case where remainder is zero
-
- for (int i = remLength - 1; i >= 0; i--)
- {
- if (rem._blocks[i] == 0)
- {
- remLength--;
- }
- }
-
- rem._length = remLength;
- }
- }
-
- public static uint HeuristicDivide(ref BigInteger dividend, ref BigInteger divisor)
- {
- int divisorLength = divisor._length;
-
- if (dividend._length < divisorLength)
- {
- return 0;
- }
-
- // This is an estimated quotient. Its error should be less than 2.
- // Reference inequality:
- // a/b - floor(floor(a)/(floor(b) + 1)) < 2
- int lastIndex = (divisorLength - 1);
- uint quotient = dividend._blocks[lastIndex] / (divisor._blocks[lastIndex] + 1);
-
- if (quotient != 0)
- {
- // Now we use our estimated quotient to update each block of dividend.
- // dividend = dividend - divisor * quotient
- int index = 0;
-
- ulong borrow = 0;
- ulong carry = 0;
-
- do
- {
- ulong product = ((ulong)(divisor._blocks[index]) * quotient) + carry;
- carry = product >> 32;
-
- ulong difference = (ulong)(dividend._blocks[index]) - (uint)(product) - borrow;
- borrow = (difference >> 32) & 1;
-
- dividend._blocks[index] = (uint)(difference);
-
- index++;
- }
- while (index < divisorLength);
-
- // Remove all leading zero blocks from dividend
- while ((divisorLength > 0) && (dividend._blocks[divisorLength - 1] == 0))
- {
- divisorLength--;
- }
-
- dividend._length = divisorLength;
- }
-
- // If the dividend is still larger than the divisor, we overshot our estimate quotient. To correct,
- // we increment the quotient and subtract one more divisor from the dividend (Because we guaranteed the error range).
- if (Compare(ref dividend, ref divisor) >= 0)
- {
- quotient++;
-
- // dividend = dividend - divisor
- int index = 0;
- ulong borrow = 0;
-
- do
- {
- ulong difference = (ulong)(dividend._blocks[index]) - divisor._blocks[index] - borrow;
- borrow = (difference >> 32) & 1;
-
- dividend._blocks[index] = (uint)(difference);
-
- index++;
- }
- while (index < divisorLength);
-
- // Remove all leading zero blocks from dividend
- while ((divisorLength > 0) && (dividend._blocks[divisorLength - 1] == 0))
- {
- divisorLength--;
- }
-
- dividend._length = divisorLength;
- }
-
- return quotient;
- }
-
- public static void Multiply(ref BigInteger lhs, uint value, ref BigInteger result)
- {
- if (lhs.IsZero() || (value == 1))
- {
- result.SetValue(ref lhs);
- return;
- }
-
- if (value == 0)
- {
- result.SetZero();
- return;
- }
-
- int lhsLength = lhs._length;
- int index = 0;
- uint carry = 0;
-
- while (index < lhsLength)
- {
- ulong product = ((ulong)(lhs._blocks[index]) * value) + carry;
- result._blocks[index] = (uint)(product);
- carry = (uint)(product >> 32);
-
- index++;
- }
-
- if (carry != 0)
- {
- Debug.Assert(unchecked((uint)(lhsLength)) + 1 <= MaxBlockCount);
- result._blocks[index] = carry;
- result._length = (lhsLength + 1);
- }
- else
- {
- result._length = lhsLength;
- }
- }
-
- public static void Multiply(ref BigInteger lhs, ref BigInteger rhs, ref BigInteger result)
- {
- if (lhs.IsZero() || rhs.IsOne())
- {
- result.SetValue(ref lhs);
- return;
- }
-
- if (rhs.IsZero())
- {
- result.SetZero();
- return;
- }
-
- ref readonly BigInteger large = ref lhs;
- int largeLength = lhs._length;
-
- ref readonly BigInteger small = ref rhs;
- int smallLength = rhs._length;
-
- if (largeLength < smallLength)
- {
- large = ref rhs;
- largeLength = rhs._length;
-
- small = ref lhs;
- smallLength = lhs._length;
- }
-
- int maxResultLength = smallLength + largeLength;
- Debug.Assert(unchecked((uint)(maxResultLength)) <= MaxBlockCount);
-
- // Zero out result internal blocks.
- Buffer.ZeroMemory((byte*)result.GetBlocksPointer(), (uint)maxResultLength * sizeof(uint));
-
- int smallIndex = 0;
- int resultStartIndex = 0;
-
- while (smallIndex < smallLength)
- {
- // Multiply each block of large BigNum.
- if (small._blocks[smallIndex] != 0)
- {
- int largeIndex = 0;
- int resultIndex = resultStartIndex;
-
- ulong carry = 0;
-
- do
- {
- ulong product = result._blocks[resultIndex] + ((ulong)(small._blocks[smallIndex]) * large._blocks[largeIndex]) + carry;
- carry = product >> 32;
- result._blocks[resultIndex] = (uint)(product);
-
- resultIndex++;
- largeIndex++;
- }
- while (largeIndex < largeLength);
-
- result._blocks[resultIndex] = (uint)(carry);
- }
-
- smallIndex++;
- resultStartIndex++;
- }
-
- if ((maxResultLength > 0) && (result._blocks[maxResultLength - 1] == 0))
- {
- result._length = (maxResultLength - 1);
- }
- else
- {
- result._length = maxResultLength;
- }
- }
-
- public static void Pow2(uint exponent, out BigInteger result)
- {
- uint blocksToShift = DivRem32(exponent, out uint remainingBitsToShift);
- result._length = (int)blocksToShift + 1;
- Debug.Assert(unchecked((uint)result._length) <= MaxBlockCount);
- if (blocksToShift > 0)
- {
- Buffer.ZeroMemory((byte*)result.GetBlocksPointer(), blocksToShift * sizeof(uint));
- }
- result._blocks[blocksToShift] = 1U << (int)(remainingBitsToShift);
- }
-
- public static void Pow10(uint exponent, out BigInteger result)
- {
- // We leverage two arrays - s_Pow10UInt32Table and s_Pow10BigNumTable to speed up the Pow10 calculation.
- //
- // s_Pow10UInt32Table stores the results of 10^0 to 10^7.
- // s_Pow10BigNumTable stores the results of 10^8, 10^16, 10^32, 10^64, 10^128, 10^256, and 10^512
- //
- // For example, let's say exp = 0b111111. We can split the exp to two parts, one is small exp,
- // which 10^smallExp can be represented as uint, another part is 10^bigExp, which must be represented as BigNum.
- // So the result should be 10^smallExp * 10^bigExp.
- //
- // Calculating 10^smallExp is simple, we just lookup the 10^smallExp from s_Pow10UInt32Table.
- // But here's a bad news: although uint can represent 10^9, exp 9's binary representation is 1001.
- // That means 10^(1011), 10^(1101), 10^(1111) all cannot be stored as uint, we cannot easily say something like:
- // "Any bits <= 3 is small exp, any bits > 3 is big exp". So instead of involving 10^8, 10^9 to s_Pow10UInt32Table,
- // consider 10^8 and 10^9 as a bigNum, so they fall into s_Pow10BigNumTable. Now we can have a simple rule:
- // "Any bits <= 3 is small exp, any bits > 3 is big exp".
- //
- // For 0b111111, we first calculate 10^(smallExp), which is 10^(7), now we can shift right 3 bits, prepare to calculate the bigExp part,
- // the exp now becomes 0b000111.
- //
- // Apparently the lowest bit of bigExp should represent 10^8 because we have already shifted 3 bits for smallExp, so s_Pow10BigNumTable[0] = 10^8.
- // Now let's shift exp right 1 bit, the lowest bit should represent 10^(8 * 2) = 10^16, and so on...
- //
- // That's why we just need the values of s_Pow10BigNumTable be power of 2.
- //
- // More details of this implementation can be found at: https://github.com/dotnet/coreclr/pull/12894#discussion_r128890596
-
- // Validate that `s_Pow10BigNumTable` has exactly enough trailing elements to fill a BigInteger (which contains MaxBlockCount + 1 elements)
- // We validate here, since this is the only current consumer of the array
- Debug.Assert((s_Pow10BigNumTableIndices[^1] + MaxBlockCount + 2) == s_Pow10BigNumTable.Length);
-
- BigInteger temp1 = new BigInteger(s_Pow10UInt32Table[exponent & 0x7]);
- ref BigInteger lhs = ref temp1;
-
- BigInteger temp2 = new BigInteger(0);
- ref BigInteger product = ref temp2;
-
- exponent >>= 3;
- uint index = 0;
-
- while (exponent != 0)
- {
- // If the current bit is set, multiply it with the corresponding power of 10
- if ((exponent & 1) != 0)
- {
- // Multiply into the next temporary
- fixed (uint* pBigNumEntry = &s_Pow10BigNumTable[s_Pow10BigNumTableIndices[index]])
- {
- ref BigInteger rhs = ref *(BigInteger*)(pBigNumEntry);
- Multiply(ref lhs, ref rhs, ref product);
- }
-
- // Swap to the next temporary
- ref BigInteger temp = ref product;
- product = ref lhs;
- lhs = ref temp;
- }
-
- // Advance to the next bit
- ++index;
- exponent >>= 1;
- }
-
- result = new BigInteger(0);
- result.SetValue(ref lhs);
- }
-
- private static uint AddDivisor(ref BigInteger lhs, int lhsStartIndex, ref BigInteger rhs)
- {
- int lhsLength = lhs._length;
- int rhsLength = rhs._length;
-
- Debug.Assert(lhsLength >= 0);
- Debug.Assert(rhsLength >= 0);
- Debug.Assert(lhsLength >= rhsLength);
-
- // Repairs the dividend, if the last subtract was too much
-
- ulong carry = 0UL;
-
- for (int i = 0; i < rhsLength; i++)
- {
- ref uint lhsValue = ref lhs._blocks[lhsStartIndex + i];
-
- ulong digit = lhsValue + carry + rhs._blocks[i];
- lhsValue = unchecked((uint)digit);
- carry = digit >> 32;
- }
-
- return (uint)(carry);
- }
-
- private static bool DivideGuessTooBig(ulong q, ulong valHi, uint valLo, uint divHi, uint divLo)
- {
- Debug.Assert(q <= 0xFFFFFFFF);
-
- // We multiply the two most significant limbs of the divisor
- // with the current guess for the quotient. If those are bigger
- // than the three most significant limbs of the current dividend
- // we return true, which means the current guess is still too big.
-
- ulong chkHi = divHi * q;
- ulong chkLo = divLo * q;
-
- chkHi += (chkLo >> 32);
- chkLo &= uint.MaxValue;
-
- if (chkHi < valHi)
- return false;
-
- if (chkHi > valHi)
- return true;
-
- if (chkLo < valLo)
- return false;
-
- if (chkLo > valLo)
- return true;
-
- return false;
- }
-
- private static uint SubtractDivisor(ref BigInteger lhs, int lhsStartIndex, ref BigInteger rhs, ulong q)
- {
- int lhsLength = lhs._length - lhsStartIndex;
- int rhsLength = rhs._length;
-
- Debug.Assert(lhsLength >= 0);
- Debug.Assert(rhsLength >= 0);
- Debug.Assert(lhsLength >= rhsLength);
- Debug.Assert(q <= uint.MaxValue);
-
- // Combines a subtract and a multiply operation, which is naturally
- // more efficient than multiplying and then subtracting...
-
- ulong carry = 0;
-
- for (int i = 0; i < rhsLength; i++)
- {
- carry += rhs._blocks[i] * q;
- uint digit = unchecked((uint)carry);
- carry >>= 32;
-
- ref uint lhsValue = ref lhs._blocks[lhsStartIndex + i];
-
- if (lhsValue < digit)
- {
- carry++;
- }
-
- lhsValue = unchecked(lhsValue - digit);
- }
-
- return (uint)(carry);
- }
-
- public void Add(uint value)
- {
- int length = _length;
- if (length == 0)
- {
- SetUInt32(value);
- return;
- }
-
- _blocks[0] += value;
- if (_blocks[0] >= value)
- {
- // No carry
- return;
- }
-
- for (int index = 1; index < length; index++)
- {
- _blocks[index]++;
- if (_blocks[index] > 0)
- {
- // No carry
- return;
- }
- }
-
- Debug.Assert(unchecked((uint)(length)) + 1 <= MaxBlockCount);
- _blocks[length] = 1;
- _length = length + 1;
- }
-
- public uint GetBlock(uint index)
- {
- Debug.Assert(index < _length);
- return _blocks[index];
- }
-
- public int GetLength()
- {
- return _length;
- }
-
- public bool IsOne()
- {
- return (_length == 1)
- && (_blocks[0] == 1);
- }
-
- public bool IsZero()
- {
- return _length == 0;
- }
-
- public void Multiply(uint value)
- {
- Multiply(ref this, value, ref this);
- }
-
- public void Multiply(ref BigInteger value)
- {
- BigInteger temp = new BigInteger(0);
- temp.SetValue(ref this);
- Multiply(ref temp, ref value, ref this);
- }
-
- public void Multiply10()
- {
- if (IsZero())
- {
- return;
- }
-
- int index = 0;
- int length = _length;
- ulong carry = 0;
-
- while (index < length)
- {
- ulong block = (ulong)(_blocks[index]);
- ulong product = (block << 3) + (block << 1) + carry;
- carry = product >> 32;
- _blocks[index] = (uint)(product);
-
- index++;
- }
-
- if (carry != 0)
- {
- Debug.Assert(unchecked((uint)(_length)) + 1 <= MaxBlockCount);
- _blocks[index] = (uint)carry;
- _length++;
- }
- }
-
- public void MultiplyPow10(uint exponent)
- {
- if (IsZero())
- {
- return;
- }
-
- Pow10(exponent, out BigInteger poweredValue);
-
- if (poweredValue._length == 1)
- {
- Multiply(poweredValue._blocks[0]);
- }
- else
- {
- Multiply(ref poweredValue);
- }
- }
-
- public void SetUInt32(uint value)
- {
- if (value == 0)
- {
- SetZero();
- }
- else
- {
- _blocks[0] = value;
- _length = 1;
- }
- }
-
- public void SetUInt64(ulong value)
- {
- if (value <= uint.MaxValue)
- {
- SetUInt32((uint)(value));
- }
- else
- {
- _blocks[0] = (uint)(value);
- _blocks[1] = (uint)(value >> 32);
-
- _length = 2;
- }
- }
-
- public void SetValue(ref BigInteger rhs)
- {
- int rhsLength = rhs._length;
- Buffer.Memcpy((byte*)GetBlocksPointer(), (byte*)rhs.GetBlocksPointer(), rhsLength * sizeof(uint));
- _length = rhsLength;
- }
-
- public void SetZero()
- {
- _length = 0;
- }
-
- public void ShiftLeft(uint shift)
- {
- // Process blocks high to low so that we can safely process in place
- int length = _length;
-
- if ((length == 0) || (shift == 0))
- {
- return;
- }
-
- uint blocksToShift = DivRem32(shift, out uint remainingBitsToShift);
-
- // Copy blocks from high to low
- int readIndex = (length - 1);
- int writeIndex = readIndex + (int)(blocksToShift);
-
- // Check if the shift is block aligned
- if (remainingBitsToShift == 0)
- {
- Debug.Assert(writeIndex < MaxBlockCount);
-
- while (readIndex >= 0)
- {
- _blocks[writeIndex] = _blocks[readIndex];
- readIndex--;
- writeIndex--;
- }
-
- _length += (int)(blocksToShift);
-
- // Zero the remaining low blocks
- Buffer.ZeroMemory((byte*)GetBlocksPointer(), blocksToShift * sizeof(uint));
- }
- else
- {
- // We need an extra block for the partial shift
- writeIndex++;
- Debug.Assert(writeIndex < MaxBlockCount);
-
- // Set the length to hold the shifted blocks
- _length = writeIndex + 1;
-
- // Output the initial blocks
- uint lowBitsShift = (32 - remainingBitsToShift);
- uint highBits = 0;
- uint block = _blocks[readIndex];
- uint lowBits = block >> (int)(lowBitsShift);
- while (readIndex > 0)
- {
- _blocks[writeIndex] = highBits | lowBits;
- highBits = block << (int)(remainingBitsToShift);
-
- --readIndex;
- --writeIndex;
-
- block = _blocks[readIndex];
- lowBits = block >> (int)lowBitsShift;
- }
-
- // Output the final blocks
- _blocks[writeIndex] = highBits | lowBits;
- _blocks[writeIndex - 1] = block << (int)(remainingBitsToShift);
-
- // Zero the remaining low blocks
- Buffer.ZeroMemory((byte*)GetBlocksPointer(), blocksToShift * sizeof(uint));
-
- // Check if the terminating block has no set bits
- if (_blocks[_length - 1] == 0)
- {
- _length--;
- }
- }
- }
-
- public ulong ToUInt64()
- {
- if (_length > 1)
- {
- return ((ulong)(_blocks[1]) << 32) + _blocks[0];
- }
-
- if (_length > 0)
- {
- return _blocks[0];
- }
-
- return 0;
- }
-
- private uint* GetBlocksPointer()
- {
- // This is safe to do since we are a ref struct
- return (uint*)(Unsafe.AsPointer(ref _blocks[0]));
- }
-
- private static uint DivRem32(uint value, out uint remainder)
- {
- remainder = value & 31;
- return value >> 5;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Number.DiyFp.cs b/netcore/System.Private.CoreLib/shared/System/Number.DiyFp.cs
deleted file mode 100644
index 141690dd632..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Number.DiyFp.cs
+++ /dev/null
@@ -1,157 +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 System.Diagnostics;
-using System.Numerics;
-
-namespace System
-{
- internal static partial class Number
- {
- // This is a port of the `DiyFp` implementation here: https://github.com/google/double-conversion/blob/a711666ddd063eb1e4b181a6cb981d39a1fc8bac/double-conversion/diy-fp.h
- // The backing structure and how it is used is described in more detail here: http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf
-
- // This "Do It Yourself Floating Point" class implements a floating-point number with a ulong significand and an int exponent.
- // Normalized DiyFp numbers will have the most significant bit of the significand set.
- // Multiplication and Subtraction do not normalize their results.
- // DiyFp are not designed to contain special doubles (NaN and Infinity).
- internal readonly ref struct DiyFp
- {
- public const int DoubleImplicitBitIndex = 52;
- public const int SingleImplicitBitIndex = 23;
-
- public const int SignificandSize = 64;
-
- public readonly ulong f;
- public readonly int e;
-
- // Computes the two boundaries of value.
- //
- // The bigger boundary (mPlus) is normalized.
- // The lower boundary has the same exponent as mPlus.
- //
- // Precondition:
- // The value encoded by value must be greater than 0.
- public static DiyFp CreateAndGetBoundaries(double value, out DiyFp mMinus, out DiyFp mPlus)
- {
- var result = new DiyFp(value);
- result.GetBoundaries(DoubleImplicitBitIndex, out mMinus, out mPlus);
- return result;
- }
-
- // Computes the two boundaries of value.
- //
- // The bigger boundary (mPlus) is normalized.
- // The lower boundary has the same exponent as mPlus.
- //
- // Precondition:
- // The value encoded by value must be greater than 0.
- public static DiyFp CreateAndGetBoundaries(float value, out DiyFp mMinus, out DiyFp mPlus)
- {
- var result = new DiyFp(value);
- result.GetBoundaries(SingleImplicitBitIndex, out mMinus, out mPlus);
- return result;
- }
-
- public DiyFp(double value)
- {
- Debug.Assert(double.IsFinite(value));
- Debug.Assert(value > 0.0);
- f = ExtractFractionAndBiasedExponent(value, out e);
- }
-
- public DiyFp(float value)
- {
- Debug.Assert(float.IsFinite(value));
- Debug.Assert(value > 0.0f);
- f = ExtractFractionAndBiasedExponent(value, out e);
- }
-
- public DiyFp(ulong f, int e)
- {
- this.f = f;
- this.e = e;
- }
-
- public DiyFp Multiply(in DiyFp other)
- {
- // Simply "emulates" a 128-bit multiplication
- //
- // However: the resulting number only contains 64-bits. The least
- // signficant 64-bits are only used for rounding the most significant
- // 64-bits.
-
- uint a = (uint)(f >> 32);
- uint b = (uint)(f);
-
- uint c = (uint)(other.f >> 32);
- uint d = (uint)(other.f);
-
- ulong ac = ((ulong)(a) * c);
- ulong bc = ((ulong)(b) * c);
- ulong ad = ((ulong)(a) * d);
- ulong bd = ((ulong)(b) * d);
-
- ulong tmp = (bd >> 32) + (uint)(ad) + (uint)(bc);
-
- // By adding (1UL << 31) to tmp, we round the final result.
- // Halfway cases will be rounded up.
-
- tmp += (1U << 31);
-
- return new DiyFp(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + other.e + SignificandSize);
- }
-
- public DiyFp Normalize()
- {
- // This method is mainly called for normalizing boundaries.
- //
- // We deviate from the reference implementation by just using
- // our LeadingZeroCount function so that we only need to shift
- // and subtract once.
-
- Debug.Assert(f != 0);
- int lzcnt = BitOperations.LeadingZeroCount(f);
- return new DiyFp(f << lzcnt, e - lzcnt);
- }
-
- // The exponents of both numbers must be the same.
- // The significand of 'this' must be bigger than the significand of 'other'.
- // The result will not be normalized.
- public DiyFp Subtract(in DiyFp other)
- {
- Debug.Assert(e == other.e);
- Debug.Assert(f >= other.f);
- return new DiyFp(f - other.f, e);
- }
-
- private void GetBoundaries(int implicitBitIndex, out DiyFp mMinus, out DiyFp mPlus)
- {
- mPlus = new DiyFp((f << 1) + 1, e - 1).Normalize();
-
- // The boundary is closer if the sigificand is of the form:
- // f == 2^p-1
- //
- // Think of v = 1000e10 and v- = 9999e9
- // Then the boundary == (v - v-) / 2 is not just at a distance of 1e9 but at a distance of 1e8.
- // The only exception is for the smallest normal, where the largest denormal is at the same distance as its successor.
- //
- // Note: denormals have the same exponent as the smallest normals.
-
- // We deviate from the reference implementation by just checking if the significand has only the implicit bit set.
- // In this scenario, we know that all the explicit bits are 0 and that the unbiased exponent is non-zero.
- if (f == (1UL << implicitBitIndex))
- {
- mMinus = new DiyFp((f << 2) - 1, e - 2);
- }
- else
- {
- mMinus = new DiyFp((f << 1) - 1, e - 1);
- }
-
- mMinus = new DiyFp(mMinus.f << (mMinus.e - mPlus.e), mPlus.e);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Number.Dragon4.cs b/netcore/System.Private.CoreLib/shared/System/Number.Dragon4.cs
deleted file mode 100644
index d065726e471..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Number.Dragon4.cs
+++ /dev/null
@@ -1,483 +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 System.Diagnostics;
-using System.Numerics;
-
-namespace System
-{
- // This is a port of the `Dragon4` implementation here: http://www.ryanjuckett.com/programming/printing-floating-point-numbers/part-2/
- // The backing algorithm and the proofs behind it are described in more detail here: https://www.cs.indiana.edu/~dyb/pubs/FP-Printing-PLDI96.pdf
- internal static partial class Number
- {
- public static void Dragon4Double(double value, int cutoffNumber, bool isSignificantDigits, ref NumberBuffer number)
- {
- double v = double.IsNegative(value) ? -value : value;
-
- Debug.Assert(v > 0);
- Debug.Assert(double.IsFinite(v));
-
- ulong mantissa = ExtractFractionAndBiasedExponent(value, out int exponent);
-
- uint mantissaHighBitIdx;
- bool hasUnequalMargins = false;
-
- if ((mantissa >> DiyFp.DoubleImplicitBitIndex) != 0)
- {
- mantissaHighBitIdx = DiyFp.DoubleImplicitBitIndex;
- hasUnequalMargins = (mantissa == (1UL << DiyFp.DoubleImplicitBitIndex));
- }
- else
- {
- Debug.Assert(mantissa != 0);
- mantissaHighBitIdx = (uint)BitOperations.Log2(mantissa);
- }
-
- int length = (int)(Dragon4(mantissa, exponent, mantissaHighBitIdx, hasUnequalMargins, cutoffNumber, isSignificantDigits, number.Digits, out int decimalExponent));
-
- number.Scale = decimalExponent + 1;
- number.Digits[length] = (byte)('\0');
- number.DigitsCount = length;
- }
-
- public static unsafe void Dragon4Single(float value, int cutoffNumber, bool isSignificantDigits, ref NumberBuffer number)
- {
- float v = float.IsNegative(value) ? -value : value;
-
- Debug.Assert(v > 0);
- Debug.Assert(float.IsFinite(v));
-
- uint mantissa = ExtractFractionAndBiasedExponent(value, out int exponent);
-
- uint mantissaHighBitIdx;
- bool hasUnequalMargins = false;
-
- if ((mantissa >> DiyFp.SingleImplicitBitIndex) != 0)
- {
- mantissaHighBitIdx = DiyFp.SingleImplicitBitIndex;
- hasUnequalMargins = (mantissa == (1U << DiyFp.SingleImplicitBitIndex));
- }
- else
- {
- Debug.Assert(mantissa != 0);
- mantissaHighBitIdx = (uint)BitOperations.Log2(mantissa);
- }
-
- int length = (int)(Dragon4(mantissa, exponent, mantissaHighBitIdx, hasUnequalMargins, cutoffNumber, isSignificantDigits, number.Digits, out int decimalExponent));
-
- number.Scale = decimalExponent + 1;
- number.Digits[length] = (byte)('\0');
- number.DigitsCount = length;
- }
-
- // This is an implementation of the Dragon4 algorithm to convert a binary number in floating-point format to a decimal number in string format.
- // The function returns the number of digits written to the output buffer and the output is not NUL terminated.
- //
- // The floating point input value is (mantissa * 2^exponent).
- //
- // See the following papers for more information on the algorithm:
- // "How to Print Floating-Point Numbers Accurately"
- // Steele and White
- // http://kurtstephens.com/files/p372-steele.pdf
- // "Printing Floating-Point Numbers Quickly and Accurately"
- // Burger and Dybvig
- // http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72.4656&rep=rep1&type=pdf
- private static unsafe uint Dragon4(ulong mantissa, int exponent, uint mantissaHighBitIdx, bool hasUnequalMargins, int cutoffNumber, bool isSignificantDigits, Span<byte> buffer, out int decimalExponent)
- {
- int curDigit = 0;
-
- Debug.Assert(buffer.Length > 0);
-
- // We deviate from the original algorithm and just assert that the mantissa
- // is not zero. Comparing to zero is fine since the caller should have set
- // the implicit bit of the mantissa, meaning it would only ever be zero if
- // the extracted exponent was also zero. And the assertion is fine since we
- // require that the DoubleToNumber handle zero itself.
- Debug.Assert(mantissa != 0);
-
- // Compute the initial state in integral form such that
- // value = scaledValue / scale
- // marginLow = scaledMarginLow / scale
-
- BigInteger scale; // positive scale applied to value and margin such that they can be represented as whole numbers
- BigInteger scaledValue; // scale * mantissa
- BigInteger scaledMarginLow; // scale * 0.5 * (distance between this floating-point number and its immediate lower value)
-
- // For normalized IEEE floating-point values, each time the exponent is incremented the margin also doubles.
- // That creates a subset of transition numbers where the high margin is twice the size of the low margin.
- BigInteger* pScaledMarginHigh;
- BigInteger optionalMarginHigh;
-
- if (hasUnequalMargins)
- {
- if (exponent > 0) // We have no fractional component
- {
- // 1) Expand the input value by multiplying out the mantissa and exponent.
- // This represents the input value in its whole number representation.
- // 2) Apply an additional scale of 2 such that later comparisons against the margin values are simplified.
- // 3) Set the margin value to the loweset mantissa bit's scale.
-
- // scaledValue = 2 * 2 * mantissa * 2^exponent
- scaledValue = new BigInteger(4 * mantissa);
- scaledValue.ShiftLeft((uint)(exponent));
-
- // scale = 2 * 2 * 1
- scale = new BigInteger(4);
-
- // scaledMarginLow = 2 * 2^(exponent - 1)
- BigInteger.Pow2((uint)(exponent), out scaledMarginLow);
-
- // scaledMarginHigh = 2 * 2 * 2^(exponent + 1)
- BigInteger.Pow2((uint)(exponent + 1), out optionalMarginHigh);
- }
- else // We have a fractional exponent
- {
- // In order to track the mantissa data as an integer, we store it as is with a large scale
-
- // scaledValue = 2 * 2 * mantissa
- scaledValue = new BigInteger(4 * mantissa);
-
- // scale = 2 * 2 * 2^(-exponent)
- BigInteger.Pow2((uint)(-exponent + 2), out scale);
-
- // scaledMarginLow = 2 * 2^(-1)
- scaledMarginLow = new BigInteger(1);
-
- // scaledMarginHigh = 2 * 2 * 2^(-1)
- optionalMarginHigh = new BigInteger(2);
- }
-
- // The high and low margins are different
- pScaledMarginHigh = &optionalMarginHigh;
- }
- else
- {
- if (exponent > 0) // We have no fractional component
- {
- // 1) Expand the input value by multiplying out the mantissa and exponent.
- // This represents the input value in its whole number representation.
- // 2) Apply an additional scale of 2 such that later comparisons against the margin values are simplified.
- // 3) Set the margin value to the lowest mantissa bit's scale.
-
- // scaledValue = 2 * mantissa*2^exponent
- scaledValue = new BigInteger(2 * mantissa);
- scaledValue.ShiftLeft((uint)(exponent));
-
- // scale = 2 * 1
- scale = new BigInteger(2);
-
- // scaledMarginLow = 2 * 2^(exponent-1)
- BigInteger.Pow2((uint)(exponent), out scaledMarginLow);
- }
- else // We have a fractional exponent
- {
- // In order to track the mantissa data as an integer, we store it as is with a large scale
-
- // scaledValue = 2 * mantissa
- scaledValue = new BigInteger(2 * mantissa);
-
- // scale = 2 * 2^(-exponent)
- BigInteger.Pow2((uint)(-exponent + 1), out scale);
-
- // scaledMarginLow = 2 * 2^(-1)
- scaledMarginLow = new BigInteger(1);
- }
-
- // The high and low margins are equal
- pScaledMarginHigh = &scaledMarginLow;
- }
-
- // Compute an estimate for digitExponent that will be correct or undershoot by one.
- //
- // This optimization is based on the paper "Printing Floating-Point Numbers Quickly and Accurately" by Burger and Dybvig http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72.4656&rep=rep1&type=pdf
- //
- // We perform an additional subtraction of 0.69 to increase the frequency of a failed estimate because that lets us take a faster branch in the code.
- // 0.69 is chosen because 0.69 + log10(2) is less than one by a reasonable epsilon that will account for any floating point error.
- //
- // We want to set digitExponent to floor(log10(v)) + 1
- // v = mantissa * 2^exponent
- // log2(v) = log2(mantissa) + exponent;
- // log10(v) = log2(v) * log10(2)
- // floor(log2(v)) = mantissaHighBitIdx + exponent;
- // log10(v) - log10(2) < (mantissaHighBitIdx + exponent) * log10(2) <= log10(v)
- // log10(v) < (mantissaHighBitIdx + exponent) * log10(2) + log10(2) <= log10(v) + log10(2)
- // floor(log10(v)) < ceil((mantissaHighBitIdx + exponent) * log10(2)) <= floor(log10(v)) + 1
- const double Log10V2 = 0.30102999566398119521373889472449;
- int digitExponent = (int)(Math.Ceiling(((int)(mantissaHighBitIdx) + exponent) * Log10V2 - 0.69));
-
- // Divide value by 10^digitExponent.
- if (digitExponent > 0)
- {
- // The exponent is positive creating a division so we multiply up the scale.
- scale.MultiplyPow10((uint)(digitExponent));
- }
- else if (digitExponent < 0)
- {
- // The exponent is negative creating a multiplication so we multiply up the scaledValue, scaledMarginLow and scaledMarginHigh.
-
- BigInteger.Pow10((uint)(-digitExponent), out BigInteger pow10);
-
- scaledValue.Multiply(ref pow10);
- scaledMarginLow.Multiply(ref pow10);
-
- if (pScaledMarginHigh != &scaledMarginLow)
- {
- BigInteger.Multiply(ref scaledMarginLow, 2, ref *pScaledMarginHigh);
- }
- }
-
- // If (value >= 1), our estimate for digitExponent was too low
- if (BigInteger.Compare(ref scaledValue, ref scale) >= 0)
- {
- // The exponent estimate was incorrect.
- // Increment the exponent and don't perform the premultiply needed for the first loop iteration.
- digitExponent++;
- }
- else
- {
- // The exponent estimate was correct.
- // Multiply larger by the output base to prepare for the first loop iteration.
- scaledValue.Multiply10();
- scaledMarginLow.Multiply10();
-
- if (pScaledMarginHigh != &scaledMarginLow)
- {
- BigInteger.Multiply(ref scaledMarginLow, 2, ref *pScaledMarginHigh);
- }
- }
-
- // Compute the cutoff exponent (the exponent of the final digit to print).
- // Default to the maximum size of the output buffer.
- int cutoffExponent = digitExponent - buffer.Length;
-
- if (cutoffNumber != -1)
- {
- int desiredCutoffExponent = 0;
-
- if (isSignificantDigits)
- {
- // We asked for a specific number of significant digits.
- Debug.Assert(cutoffNumber > 0);
- desiredCutoffExponent = digitExponent - cutoffNumber;
- }
- else
- {
- // We asked for a specific number of fractional digits.
- Debug.Assert(cutoffNumber >= 0);
- desiredCutoffExponent = -cutoffNumber;
- }
-
- if (desiredCutoffExponent > cutoffExponent)
- {
- // Only select the new cutoffExponent if it won't overflow the destination buffer.
- cutoffExponent = desiredCutoffExponent;
- }
- }
-
- // Output the exponent of the first digit we will print
- decimalExponent = --digitExponent;
-
- // In preparation for calling BigInteger.HeuristicDivie(), we need to scale up our values such that the highest block of the denominator is greater than or equal to 8.
- // We also need to guarantee that the numerator can never have a length greater than the denominator after each loop iteration.
- // This requires the highest block of the denominator to be less than or equal to 429496729 which is the highest number that can be multiplied by 10 without overflowing to a new block.
-
- Debug.Assert(scale.GetLength() > 0);
- uint hiBlock = scale.GetBlock((uint)(scale.GetLength() - 1));
-
- if ((hiBlock < 8) || (hiBlock > 429496729))
- {
- // Perform a bit shift on all values to get the highest block of the denominator into the range [8,429496729].
- // We are more likely to make accurate quotient estimations in BigInteger.HeuristicDivide() with higher denominator values so we shift the denominator to place the highest bit at index 27 of the highest block.
- // This is safe because (2^28 - 1) = 268435455 which is less than 429496729.
- // This means that all values with a highest bit at index 27 are within range.
- Debug.Assert(hiBlock != 0);
- uint hiBlockLog2 = (uint)BitOperations.Log2(hiBlock);
- Debug.Assert((hiBlockLog2 < 3) || (hiBlockLog2 > 27));
- uint shift = (32 + 27 - hiBlockLog2) % 32;
-
- scale.ShiftLeft(shift);
- scaledValue.ShiftLeft(shift);
- scaledMarginLow.ShiftLeft(shift);
-
- if (pScaledMarginHigh != &scaledMarginLow)
- {
- BigInteger.Multiply(ref scaledMarginLow, 2, ref *pScaledMarginHigh);
- }
- }
-
- // These values are used to inspect why the print loop terminated so we can properly round the final digit.
- bool low; // did the value get within marginLow distance from zero
- bool high; // did the value get within marginHigh distance from one
- uint outputDigit; // current digit being output
-
- if (cutoffNumber == -1)
- {
- Debug.Assert(isSignificantDigits);
- Debug.Assert(digitExponent >= cutoffExponent);
-
- // For the unique cutoff mode, we will try to print until we have reached a level of precision that uniquely distinguishes this value from its neighbors.
- // If we run out of space in the output buffer, we terminate early.
-
- while (true)
- {
- // divide out the scale to extract the digit
- outputDigit = BigInteger.HeuristicDivide(ref scaledValue, ref scale);
- Debug.Assert(outputDigit < 10);
-
- // update the high end of the value
- BigInteger.Add(ref scaledValue, ref *pScaledMarginHigh, out BigInteger scaledValueHigh);
-
- // stop looping if we are far enough away from our neighboring values or if we have reached the cutoff digit
- low = BigInteger.Compare(ref scaledValue, ref scaledMarginLow) < 0;
- high = BigInteger.Compare(ref scaledValueHigh, ref scale) > 0;
-
- if (low || high || (digitExponent == cutoffExponent))
- {
- break;
- }
-
- // store the output digit
- buffer[curDigit] = (byte)('0' + outputDigit);
- curDigit++;
-
- // multiply larger by the output base
- scaledValue.Multiply10();
- scaledMarginLow.Multiply10();
-
- if (pScaledMarginHigh != &scaledMarginLow)
- {
- BigInteger.Multiply(ref scaledMarginLow, 2, ref *pScaledMarginHigh);
- }
-
- digitExponent--;
- }
- }
- else if (digitExponent >= cutoffExponent)
- {
- Debug.Assert((cutoffNumber > 0) || ((cutoffNumber == 0) && !isSignificantDigits));
-
- // For length based cutoff modes, we will try to print until we have exhausted all precision (i.e. all remaining digits are zeros) or until we reach the desired cutoff digit.
- low = false;
- high = false;
-
- while (true)
- {
- // divide out the scale to extract the digit
- outputDigit = BigInteger.HeuristicDivide(ref scaledValue, ref scale);
- Debug.Assert(outputDigit < 10);
-
- if (scaledValue.IsZero() || (digitExponent <= cutoffExponent))
- {
- break;
- }
-
- // store the output digit
- buffer[curDigit] = (byte)('0' + outputDigit);
- curDigit++;
-
- // multiply larger by the output base
- scaledValue.Multiply10();
- digitExponent--;
- }
- }
- else
- {
- // In the scenario where the first significant digit is after the cutoff, we want to treat that
- // first significant digit as the rounding digit. If the first significant would cause the next
- // digit to round, we will increase the decimalExponent by one and set the previous digit to one.
- // This ensures we correctly handle the case where the first significant digit is exactly one after
- // the cutoff, it is a 4, and the subsequent digit would round that to 5 inducing a double rounding
- // bug when NumberToString does its own rounding checks. However, if the first significant digit
- // would not cause the next one to round, we preserve that digit as is.
-
- // divide out the scale to extract the digit
- outputDigit = BigInteger.HeuristicDivide(ref scaledValue, ref scale);
- Debug.Assert((0 < outputDigit) && (outputDigit < 10));
-
- if ((outputDigit > 5) || ((outputDigit == 5) && !scaledValue.IsZero()))
- {
- decimalExponent++;
- outputDigit = 1;
- }
-
- buffer[curDigit] = (byte)('0' + outputDigit);
- curDigit++;
-
- // return the number of digits output
- return (uint)curDigit;
- }
-
- // round off the final digit
- // default to rounding down if value got too close to 0
- bool roundDown = low;
-
- if (low == high) // is it legal to round up and down
- {
- // round to the closest digit by comparing value with 0.5.
- //
- // To do this we need to convert the inequality to large integer values.
- // compare(value, 0.5)
- // compare(scale * value, scale * 0.5)
- // compare(2 * scale * value, scale)
- scaledValue.ShiftLeft(1); // Multiply by 2
- int compare = BigInteger.Compare(ref scaledValue, ref scale);
- roundDown = compare < 0;
-
- // if we are directly in the middle, round towards the even digit (i.e. IEEE rouding rules)
- if (compare == 0)
- {
- roundDown = (outputDigit & 1) == 0;
- }
- }
-
- // print the rounded digit
- if (roundDown)
- {
- buffer[curDigit] = (byte)('0' + outputDigit);
- curDigit++;
- }
- else if (outputDigit == 9) // handle rounding up
- {
- // find the first non-nine prior digit
- while (true)
- {
- // if we are at the first digit
- if (curDigit == 0)
- {
- // output 1 at the next highest exponent
-
- buffer[curDigit] = (byte)('1');
- curDigit++;
- decimalExponent++;
-
- break;
- }
-
- curDigit--;
-
- if (buffer[curDigit] != '9')
- {
- // increment the digit
-
- buffer[curDigit]++;
- curDigit++;
-
- break;
- }
- }
- }
- else
- {
- // values in the range [0,8] can perform a simple round up
- buffer[curDigit] = (byte)('0' + outputDigit + 1);
- curDigit++;
- }
-
- // return the number of digits output
- uint outputLen = (uint)curDigit;
- Debug.Assert(outputLen <= buffer.Length);
- return outputLen;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Number.Formatting.cs b/netcore/System.Private.CoreLib/shared/System/Number.Formatting.cs
deleted file mode 100644
index ee9e67d010e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Number.Formatting.cs
+++ /dev/null
@@ -1,2539 +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 System.Buffers.Text;
-using System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System
-{
- // The Format methods provided by the numeric classes convert
- // the numeric value to a string using the format string given by the
- // format parameter. If the format parameter is null or
- // an empty string, the number is formatted as if the string "G" (general
- // format) was specified. The info parameter specifies the
- // NumberFormatInfo instance to use when formatting the number. If the
- // info parameter is null or omitted, the numeric formatting information
- // is obtained from the current culture. The NumberFormatInfo supplies
- // such information as the characters to use for decimal and thousand
- // separators, and the spelling and placement of currency symbols in monetary
- // values.
- //
- // Format strings fall into two categories: Standard format strings and
- // user-defined format strings. A format string consisting of a single
- // alphabetic character (A-Z or a-z), optionally followed by a sequence of
- // digits (0-9), is a standard format string. All other format strings are
- // used-defined format strings.
- //
- // A standard format string takes the form Axx, where A is an
- // alphabetic character called the format specifier and xx is a
- // sequence of digits called the precision specifier. The format
- // specifier controls the type of formatting applied to the number and the
- // precision specifier controls the number of significant digits or decimal
- // places of the formatting operation. The following table describes the
- // supported standard formats.
- //
- // C c - Currency format. The number is
- // converted to a string that represents a currency amount. The conversion is
- // controlled by the currency format information of the NumberFormatInfo
- // used to format the number. The precision specifier indicates the desired
- // number of decimal places. If the precision specifier is omitted, the default
- // currency precision given by the NumberFormatInfo is used.
- //
- // D d - Decimal format. This format is
- // supported for integral types only. The number is converted to a string of
- // decimal digits, prefixed by a minus sign if the number is negative. The
- // precision specifier indicates the minimum number of digits desired in the
- // resulting string. If required, the number will be left-padded with zeros to
- // produce the number of digits given by the precision specifier.
- //
- // E e Engineering (scientific) format.
- // The number is converted to a string of the form
- // "-d.ddd...E+ddd" or "-d.ddd...e+ddd", where each
- // 'd' indicates a digit (0-9). The string starts with a minus sign if the
- // number is negative, and one digit always precedes the decimal point. The
- // precision specifier indicates the desired number of digits after the decimal
- // point. If the precision specifier is omitted, a default of 6 digits after
- // the decimal point is used. The format specifier indicates whether to prefix
- // the exponent with an 'E' or an 'e'. The exponent is always consists of a
- // plus or minus sign and three digits.
- //
- // F f Fixed point format. The number is
- // converted to a string of the form "-ddd.ddd....", where each
- // 'd' indicates a digit (0-9). The string starts with a minus sign if the
- // number is negative. The precision specifier indicates the desired number of
- // decimal places. If the precision specifier is omitted, the default numeric
- // precision given by the NumberFormatInfo is used.
- //
- // G g - General format. The number is
- // converted to the shortest possible decimal representation using fixed point
- // or scientific format. The precision specifier determines the number of
- // significant digits in the resulting string. If the precision specifier is
- // omitted, the number of significant digits is determined by the type of the
- // number being converted (10 for int, 19 for long, 7 for
- // float, 15 for double, 19 for Currency, and 29 for
- // Decimal). Trailing zeros after the decimal point are removed, and the
- // resulting string contains a decimal point only if required. The resulting
- // string uses fixed point format if the exponent of the number is less than
- // the number of significant digits and greater than or equal to -4. Otherwise,
- // the resulting string uses scientific format, and the case of the format
- // specifier controls whether the exponent is prefixed with an 'E' or an 'e'.
- //
- // N n Number format. The number is
- // converted to a string of the form "-d,ddd,ddd.ddd....", where
- // each 'd' indicates a digit (0-9). The string starts with a minus sign if the
- // number is negative. Thousand separators are inserted between each group of
- // three digits to the left of the decimal point. The precision specifier
- // indicates the desired number of decimal places. If the precision specifier
- // is omitted, the default numeric precision given by the
- // NumberFormatInfo is used.
- //
- // X x - Hexadecimal format. This format is
- // supported for integral types only. The number is converted to a string of
- // hexadecimal digits. The format specifier indicates whether to use upper or
- // lower case characters for the hexadecimal digits above 9 ('X' for 'ABCDEF',
- // and 'x' for 'abcdef'). The precision specifier indicates the minimum number
- // of digits desired in the resulting string. If required, the number will be
- // left-padded with zeros to produce the number of digits given by the
- // precision specifier.
- //
- // Some examples of standard format strings and their results are shown in the
- // table below. (The examples all assume a default NumberFormatInfo.)
- //
- // Value Format Result
- // 12345.6789 C $12,345.68
- // -12345.6789 C ($12,345.68)
- // 12345 D 12345
- // 12345 D8 00012345
- // 12345.6789 E 1.234568E+004
- // 12345.6789 E10 1.2345678900E+004
- // 12345.6789 e4 1.2346e+004
- // 12345.6789 F 12345.68
- // 12345.6789 F0 12346
- // 12345.6789 F6 12345.678900
- // 12345.6789 G 12345.6789
- // 12345.6789 G7 12345.68
- // 123456789 G7 1.234568E8
- // 12345.6789 N 12,345.68
- // 123456789 N4 123,456,789.0000
- // 0x2c45e x 2c45e
- // 0x2c45e X 2C45E
- // 0x2c45e X8 0002C45E
- //
- // Format strings that do not start with an alphabetic character, or that start
- // with an alphabetic character followed by a non-digit, are called
- // user-defined format strings. The following table describes the formatting
- // characters that are supported in user defined format strings.
- //
- //
- // 0 - Digit placeholder. If the value being
- // formatted has a digit in the position where the '0' appears in the format
- // string, then that digit is copied to the output string. Otherwise, a '0' is
- // stored in that position in the output string. The position of the leftmost
- // '0' before the decimal point and the rightmost '0' after the decimal point
- // determines the range of digits that are always present in the output
- // string.
- //
- // # - Digit placeholder. If the value being
- // formatted has a digit in the position where the '#' appears in the format
- // string, then that digit is copied to the output string. Otherwise, nothing
- // is stored in that position in the output string.
- //
- // . - Decimal point. The first '.' character
- // in the format string determines the location of the decimal separator in the
- // formatted value; any additional '.' characters are ignored. The actual
- // character used as a the decimal separator in the output string is given by
- // the NumberFormatInfo used to format the number.
- //
- // , - Thousand separator and number scaling.
- // The ',' character serves two purposes. First, if the format string contains
- // a ',' character between two digit placeholders (0 or #) and to the left of
- // the decimal point if one is present, then the output will have thousand
- // separators inserted between each group of three digits to the left of the
- // decimal separator. The actual character used as a the decimal separator in
- // the output string is given by the NumberFormatInfo used to format the
- // number. Second, if the format string contains one or more ',' characters
- // immediately to the left of the decimal point, or after the last digit
- // placeholder if there is no decimal point, then the number will be divided by
- // 1000 times the number of ',' characters before it is formatted. For example,
- // the format string '0,,' will represent 100 million as just 100. Use of the
- // ',' character to indicate scaling does not also cause the formatted number
- // to have thousand separators. Thus, to scale a number by 1 million and insert
- // thousand separators you would use the format string '#,##0,,'.
- //
- // % - Percentage placeholder. The presence of
- // a '%' character in the format string causes the number to be multiplied by
- // 100 before it is formatted. The '%' character itself is inserted in the
- // output string where it appears in the format string.
- //
- // E+ E- e+ e- - Scientific notation.
- // If any of the strings 'E+', 'E-', 'e+', or 'e-' are present in the format
- // string and are immediately followed by at least one '0' character, then the
- // number is formatted using scientific notation with an 'E' or 'e' inserted
- // between the number and the exponent. The number of '0' characters following
- // the scientific notation indicator determines the minimum number of digits to
- // output for the exponent. The 'E+' and 'e+' formats indicate that a sign
- // character (plus or minus) should always precede the exponent. The 'E-' and
- // 'e-' formats indicate that a sign character should only precede negative
- // exponents.
- //
- // \ - Literal character. A backslash character
- // causes the next character in the format string to be copied to the output
- // string as-is. The backslash itself isn't copied, so to place a backslash
- // character in the output string, use two backslashes (\\) in the format
- // string.
- //
- // 'ABC' "ABC" - Literal string. Characters
- // enclosed in single or double quotation marks are copied to the output string
- // as-is and do not affect formatting.
- //
- // ; - Section separator. The ';' character is
- // used to separate sections for positive, negative, and zero numbers in the
- // format string.
- //
- // Other - All other characters are copied to
- // the output string in the position they appear.
- //
- // For fixed point formats (formats not containing an 'E+', 'E-', 'e+', or
- // 'e-'), the number is rounded to as many decimal places as there are digit
- // placeholders to the right of the decimal point. If the format string does
- // not contain a decimal point, the number is rounded to the nearest
- // integer. If the number has more digits than there are digit placeholders to
- // the left of the decimal point, the extra digits are copied to the output
- // string immediately before the first digit placeholder.
- //
- // For scientific formats, the number is rounded to as many significant digits
- // as there are digit placeholders in the format string.
- //
- // To allow for different formatting of positive, negative, and zero values, a
- // user-defined format string may contain up to three sections separated by
- // semicolons. The results of having one, two, or three sections in the format
- // string are described in the table below.
- //
- // Sections:
- //
- // One - The format string applies to all values.
- //
- // Two - The first section applies to positive values
- // and zeros, and the second section applies to negative values. If the number
- // to be formatted is negative, but becomes zero after rounding according to
- // the format in the second section, then the resulting zero is formatted
- // according to the first section.
- //
- // Three - The first section applies to positive
- // values, the second section applies to negative values, and the third section
- // applies to zeros. The second section may be left empty (by having no
- // characters between the semicolons), in which case the first section applies
- // to all non-zero values. If the number to be formatted is non-zero, but
- // becomes zero after rounding according to the format in the first or second
- // section, then the resulting zero is formatted according to the third
- // section.
- //
- // For both standard and user-defined formatting operations on values of type
- // float and double, if the value being formatted is a NaN (Not
- // a Number) or a positive or negative infinity, then regardless of the format
- // string, the resulting string is given by the NaNSymbol,
- // PositiveInfinitySymbol, or NegativeInfinitySymbol property of
- // the NumberFormatInfo used to format the number.
-
- internal static partial class Number
- {
- internal const int DecimalPrecision = 29; // Decimal.DecCalc also uses this value
-
- // SinglePrecision and DoublePrecision represent the maximum number of digits required
- // to guarantee that any given Single or Double can roundtrip. Some numbers may require
- // less, but none will require more.
- private const int SinglePrecision = 9;
- private const int DoublePrecision = 17;
-
- // SinglePrecisionCustomFormat and DoublePrecisionCustomFormat are used to ensure that
- // custom format strings return the same string as in previous releases when the format
- // would return x digits or less (where x is the value of the corresponding constant).
- // In order to support more digits, we would need to update ParseFormatSpecifier to pre-parse
- // the format and determine exactly how many digits are being requested and whether they
- // represent "significant digits" or "digits after the decimal point".
- private const int SinglePrecisionCustomFormat = 7;
- private const int DoublePrecisionCustomFormat = 15;
-
- private const int DefaultPrecisionExponentialFormat = 6;
-
- private const int MaxUInt32DecDigits = 10;
- private const int CharStackBufferSize = 32;
- private const string PosNumberFormat = "#";
-
- private static readonly string[] s_singleDigitStringCache = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
-
- private static readonly string[] s_posCurrencyFormats =
- {
- "$#", "#$", "$ #", "# $"
- };
-
- private static readonly string[] s_negCurrencyFormats =
- {
- "($#)", "-$#", "$-#", "$#-",
- "(#$)", "-#$", "#-$", "#$-",
- "-# $", "-$ #", "# $-", "$ #-",
- "$ -#", "#- $", "($ #)", "(# $)"
- };
-
- private static readonly string[] s_posPercentFormats =
- {
- "# %", "#%", "%#", "% #"
- };
-
- private static readonly string[] s_negPercentFormats =
- {
- "-# %", "-#%", "-%#",
- "%-#", "%#-",
- "#-%", "#%-",
- "-% #", "# %-", "% #-",
- "% -#", "#- %"
- };
-
- private static readonly string[] s_negNumberFormats =
- {
- "(#)", "-#", "- #", "#-", "# -",
- };
-
- public static unsafe string FormatDecimal(decimal value, ReadOnlySpan<char> format, NumberFormatInfo info)
- {
- char fmt = ParseFormatSpecifier(format, out int digits);
-
- byte* pDigits = stackalloc byte[DecimalNumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Decimal, pDigits, DecimalNumberBufferLength);
-
- DecimalToNumber(ref value, ref number);
-
- char* stackPtr = stackalloc char[CharStackBufferSize];
- ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(stackPtr, CharStackBufferSize));
-
- if (fmt != 0)
- {
- NumberToString(ref sb, ref number, fmt, digits, info);
- }
- else
- {
- NumberToStringFormat(ref sb, ref number, format, info);
- }
-
- return sb.ToString();
- }
-
- public static unsafe bool TryFormatDecimal(decimal value, ReadOnlySpan<char> format, NumberFormatInfo info, Span<char> destination, out int charsWritten)
- {
- char fmt = ParseFormatSpecifier(format, out int digits);
-
- byte* pDigits = stackalloc byte[DecimalNumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Decimal, pDigits, DecimalNumberBufferLength);
-
- DecimalToNumber(ref value, ref number);
-
- char* stackPtr = stackalloc char[CharStackBufferSize];
- ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(stackPtr, CharStackBufferSize));
-
- if (fmt != 0)
- {
- NumberToString(ref sb, ref number, fmt, digits, info);
- }
- else
- {
- NumberToStringFormat(ref sb, ref number, format, info);
- }
-
- return sb.TryCopyTo(destination, out charsWritten);
- }
-
- internal static unsafe void DecimalToNumber(ref decimal d, ref NumberBuffer number)
- {
- byte* buffer = number.GetDigitsPointer();
- number.DigitsCount = DecimalPrecision;
- number.IsNegative = d.IsNegative;
-
- byte* p = buffer + DecimalPrecision;
- while ((d.Mid | d.High) != 0)
- {
- p = UInt32ToDecChars(p, decimal.DecDivMod1E9(ref d), 9);
- }
- p = UInt32ToDecChars(p, d.Low, 0);
-
- int i = (int)((buffer + DecimalPrecision) - p);
-
- number.DigitsCount = i;
- number.Scale = i - d.Scale;
-
- byte* dst = number.GetDigitsPointer();
- while (--i >= 0)
- {
- *dst++ = *p++;
- }
- *dst = (byte)('\0');
-
- number.CheckConsistency();
- }
-
- public static string FormatDouble(double value, string? format, NumberFormatInfo info)
- {
- Span<char> stackBuffer = stackalloc char[CharStackBufferSize];
- var sb = new ValueStringBuilder(stackBuffer);
- return FormatDouble(ref sb, value, format, info) ?? sb.ToString();
- }
-
- public static bool TryFormatDouble(double value, ReadOnlySpan<char> format, NumberFormatInfo info, Span<char> destination, out int charsWritten)
- {
- Span<char> stackBuffer = stackalloc char[CharStackBufferSize];
- var sb = new ValueStringBuilder(stackBuffer);
- string? s = FormatDouble(ref sb, value, format, info);
- return s != null ?
- TryCopyTo(s, destination, out charsWritten) :
- sb.TryCopyTo(destination, out charsWritten);
- }
-
- private static int GetFloatingPointMaxDigitsAndPrecision(char fmt, ref int precision, NumberFormatInfo info, out bool isSignificantDigits)
- {
- if (fmt == 0)
- {
- isSignificantDigits = true;
- return precision;
- }
-
- int maxDigits = precision;
-
- switch (fmt)
- {
- case 'C':
- case 'c':
- {
- // The currency format uses the precision specifier to indicate the number of
- // decimal digits to format. This defaults to NumberFormatInfo.CurrencyDecimalDigits.
-
- if (precision == -1)
- {
- precision = info.CurrencyDecimalDigits;
- }
- isSignificantDigits = false;
-
- break;
- }
-
- case 'E':
- case 'e':
- {
- // The exponential format uses the precision specifier to indicate the number of
- // decimal digits to format. This defaults to 6. However, the exponential format
- // also always formats a single integral digit, so we need to increase the precision
- // specifier and treat it as the number of significant digits to account for this.
-
- if (precision == -1)
- {
- precision = DefaultPrecisionExponentialFormat;
- }
-
- precision++;
- isSignificantDigits = true;
-
- break;
- }
-
- case 'F':
- case 'f':
- case 'N':
- case 'n':
- {
- // The fixed-point and number formats use the precision specifier to indicate the number
- // of decimal digits to format. This defaults to NumberFormatInfo.NumberDecimalDigits.
-
- if (precision == -1)
- {
- precision = info.NumberDecimalDigits;
- }
- isSignificantDigits = false;
-
- break;
- }
-
- case 'G':
- case 'g':
- {
- // The general format uses the precision specifier to indicate the number of significant
- // digits to format. This defaults to the shortest roundtrippable string. Additionally,
- // given that we can't return zero significant digits, we treat 0 as returning the shortest
- // roundtrippable string as well.
-
- if (precision == 0)
- {
- precision = -1;
- }
- isSignificantDigits = true;
-
- break;
- }
-
- case 'P':
- case 'p':
- {
- // The percent format uses the precision specifier to indicate the number of
- // decimal digits to format. This defaults to NumberFormatInfo.PercentDecimalDigits.
- // However, the percent format also always multiplies the number by 100, so we need
- // to increase the precision specifier to ensure we get the appropriate number of digits.
-
- if (precision == -1)
- {
- precision = info.PercentDecimalDigits;
- }
-
- precision += 2;
- isSignificantDigits = false;
-
- break;
- }
-
- case 'R':
- case 'r':
- {
- // The roundtrip format ignores the precision specifier and always returns the shortest
- // roundtrippable string.
-
- precision = -1;
- isSignificantDigits = true;
-
- break;
- }
-
- default:
- {
- throw new FormatException(SR.Argument_BadFormatSpecifier);
- }
- }
-
- return maxDigits;
- }
-
- /// <summary>Formats the specified value according to the specified format and info.</summary>
- /// <returns>
- /// Non-null if an existing string can be returned, in which case the builder will be unmodified.
- /// Null if no existing string was returned, in which case the formatted output is in the builder.
- /// </returns>
- private static unsafe string? FormatDouble(ref ValueStringBuilder sb, double value, ReadOnlySpan<char> format, NumberFormatInfo info)
- {
- if (!double.IsFinite(value))
- {
- if (double.IsNaN(value))
- {
- return info.NaNSymbol;
- }
-
- return double.IsNegative(value) ? info.NegativeInfinitySymbol : info.PositiveInfinitySymbol;
- }
-
- char fmt = ParseFormatSpecifier(format, out int precision);
- byte* pDigits = stackalloc byte[DoubleNumberBufferLength];
-
- if (fmt == '\0')
- {
- // For back-compat we currently specially treat the precision for custom
- // format specifiers. The constant has more details as to why.
- precision = DoublePrecisionCustomFormat;
- }
-
- NumberBuffer number = new NumberBuffer(NumberBufferKind.FloatingPoint, pDigits, DoubleNumberBufferLength);
- number.IsNegative = double.IsNegative(value);
-
- // We need to track the original precision requested since some formats
- // accept values like 0 and others may require additional fixups.
- int nMaxDigits = GetFloatingPointMaxDigitsAndPrecision(fmt, ref precision, info, out bool isSignificantDigits);
-
- if ((value != 0.0) && (!isSignificantDigits || !Grisu3.TryRunDouble(value, precision, ref number)))
- {
- Dragon4Double(value, precision, isSignificantDigits, ref number);
- }
-
- number.CheckConsistency();
-
- // When the number is known to be roundtrippable (either because we requested it be, or
- // because we know we have enough digits to satisfy roundtrippability), we should validate
- // that the number actually roundtrips back to the original result.
-
- Debug.Assert(((precision != -1) && (precision < DoublePrecision)) || (BitConverter.DoubleToInt64Bits(value) == BitConverter.DoubleToInt64Bits(NumberToDouble(ref number))));
-
- if (fmt != 0)
- {
- if (precision == -1)
- {
- Debug.Assert((fmt == 'G') || (fmt == 'g') || (fmt == 'R') || (fmt == 'r'));
-
- // For the roundtrip and general format specifiers, when returning the shortest roundtrippable
- // string, we need to update the maximum number of digits to be the greater of number.DigitsCount
- // or DoublePrecision. This ensures that we continue returning "pretty" strings for values with
- // less digits. One example this fixes is "-60", which would otherwise be formatted as "-6E+01"
- // since DigitsCount would be 1 and the formatter would almost immediately switch to scientific notation.
-
- nMaxDigits = Math.Max(number.DigitsCount, DoublePrecision);
- }
- NumberToString(ref sb, ref number, fmt, nMaxDigits, info);
- }
- else
- {
- Debug.Assert(precision == DoublePrecisionCustomFormat);
- NumberToStringFormat(ref sb, ref number, format, info);
- }
- return null;
- }
-
- public static string FormatSingle(float value, string? format, NumberFormatInfo info)
- {
- Span<char> stackBuffer = stackalloc char[CharStackBufferSize];
- var sb = new ValueStringBuilder(stackBuffer);
- return FormatSingle(ref sb, value, format, info) ?? sb.ToString();
- }
-
- public static bool TryFormatSingle(float value, ReadOnlySpan<char> format, NumberFormatInfo info, Span<char> destination, out int charsWritten)
- {
- Span<char> stackBuffer = stackalloc char[CharStackBufferSize];
- var sb = new ValueStringBuilder(stackBuffer);
- string? s = FormatSingle(ref sb, value, format, info);
- return s != null ?
- TryCopyTo(s, destination, out charsWritten) :
- sb.TryCopyTo(destination, out charsWritten);
- }
-
- /// <summary>Formats the specified value according to the specified format and info.</summary>
- /// <returns>
- /// Non-null if an existing string can be returned, in which case the builder will be unmodified.
- /// Null if no existing string was returned, in which case the formatted output is in the builder.
- /// </returns>
- private static unsafe string? FormatSingle(ref ValueStringBuilder sb, float value, ReadOnlySpan<char> format, NumberFormatInfo info)
- {
- if (!float.IsFinite(value))
- {
- if (float.IsNaN(value))
- {
- return info.NaNSymbol;
- }
-
- return float.IsNegative(value) ? info.NegativeInfinitySymbol : info.PositiveInfinitySymbol;
- }
-
- char fmt = ParseFormatSpecifier(format, out int precision);
- byte* pDigits = stackalloc byte[SingleNumberBufferLength];
-
- if (fmt == '\0')
- {
- // For back-compat we currently specially treat the precision for custom
- // format specifiers. The constant has more details as to why.
- precision = SinglePrecisionCustomFormat;
- }
-
- NumberBuffer number = new NumberBuffer(NumberBufferKind.FloatingPoint, pDigits, SingleNumberBufferLength);
- number.IsNegative = float.IsNegative(value);
-
- // We need to track the original precision requested since some formats
- // accept values like 0 and others may require additional fixups.
- int nMaxDigits = GetFloatingPointMaxDigitsAndPrecision(fmt, ref precision, info, out bool isSignificantDigits);
-
- if ((value != 0.0f) && (!isSignificantDigits || !Grisu3.TryRunSingle(value, precision, ref number)))
- {
- Dragon4Single(value, precision, isSignificantDigits, ref number);
- }
-
- number.CheckConsistency();
-
- // When the number is known to be roundtrippable (either because we requested it be, or
- // because we know we have enough digits to satisfy roundtrippability), we should validate
- // that the number actually roundtrips back to the original result.
-
- Debug.Assert(((precision != -1) && (precision < SinglePrecision)) || (BitConverter.SingleToInt32Bits(value) == BitConverter.SingleToInt32Bits(NumberToSingle(ref number))));
-
- if (fmt != 0)
- {
- if (precision == -1)
- {
- Debug.Assert((fmt == 'G') || (fmt == 'g') || (fmt == 'R') || (fmt == 'r'));
-
- // For the roundtrip and general format specifiers, when returning the shortest roundtrippable
- // string, we need to update the maximum number of digits to be the greater of number.DigitsCount
- // or SinglePrecision. This ensures that we continue returning "pretty" strings for values with
- // less digits. One example this fixes is "-60", which would otherwise be formatted as "-6E+01"
- // since DigitsCount would be 1 and the formatter would almost immediately switch to scientific notation.
-
- nMaxDigits = Math.Max(number.DigitsCount, SinglePrecision);
- }
- NumberToString(ref sb, ref number, fmt, nMaxDigits, info);
- }
- else
- {
- Debug.Assert(precision == SinglePrecisionCustomFormat);
- NumberToStringFormat(ref sb, ref number, format, info);
- }
- return null;
- }
-
- private static bool TryCopyTo(string source, Span<char> destination, out int charsWritten)
- {
- Debug.Assert(source != null);
-
- if (source.AsSpan().TryCopyTo(destination))
- {
- charsWritten = source.Length;
- return true;
- }
-
- charsWritten = 0;
- return false;
- }
-
- public static unsafe string FormatInt32(int value, ReadOnlySpan<char> format, IFormatProvider? provider)
- {
- // Fast path for default format with a non-negative value
- if (value >= 0 && format.Length == 0)
- {
- return UInt32ToDecStr((uint)value, digits: -1);
- }
-
- char fmt = ParseFormatSpecifier(format, out int digits);
- char fmtUpper = (char)(fmt & 0xFFDF); // ensure fmt is upper-cased for purposes of comparison
- if ((fmtUpper == 'G' && digits < 1) || fmtUpper == 'D')
- {
- return value >= 0 ?
- UInt32ToDecStr((uint)value, digits) :
- NegativeInt32ToDecStr(value, digits, NumberFormatInfo.GetInstance(provider).NegativeSign);
- }
- else if (fmtUpper == 'X')
- {
- // The fmt-(X-A+10) hack has the effect of dictating whether we produce uppercase or lowercase
- // hex numbers for a-f. 'X' as the fmt code produces uppercase. 'x' as the format code produces lowercase.
- return Int32ToHexStr(value, (char)(fmt - ('X' - 'A' + 10)), digits);
- }
- else
- {
- NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);
-
- byte* pDigits = stackalloc byte[Int32NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, Int32NumberBufferLength);
-
- Int32ToNumber(value, ref number);
-
- char* stackPtr = stackalloc char[CharStackBufferSize];
- ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(stackPtr, CharStackBufferSize));
-
- if (fmt != 0)
- {
- NumberToString(ref sb, ref number, fmt, digits, info);
- }
- else
- {
- NumberToStringFormat(ref sb, ref number, format, info);
- }
- return sb.ToString();
- }
- }
-
- public static unsafe bool TryFormatInt32(int value, ReadOnlySpan<char> format, IFormatProvider? provider, Span<char> destination, out int charsWritten)
- {
- // Fast path for default format with a non-negative value
- if (value >= 0 && format.Length == 0)
- {
- return TryUInt32ToDecStr((uint)value, digits: -1, destination, out charsWritten);
- }
-
- char fmt = ParseFormatSpecifier(format, out int digits);
- char fmtUpper = (char)(fmt & 0xFFDF); // ensure fmt is upper-cased for purposes of comparison
- if ((fmtUpper == 'G' && digits < 1) || fmtUpper == 'D')
- {
- return value >= 0 ?
- TryUInt32ToDecStr((uint)value, digits, destination, out charsWritten) :
- TryNegativeInt32ToDecStr(value, digits, NumberFormatInfo.GetInstance(provider).NegativeSign, destination, out charsWritten);
- }
- else if (fmtUpper == 'X')
- {
- // The fmt-(X-A+10) hack has the effect of dictating whether we produce uppercase or lowercase
- // hex numbers for a-f. 'X' as the fmt code produces uppercase. 'x' as the format code produces lowercase.
- return TryInt32ToHexStr(value, (char)(fmt - ('X' - 'A' + 10)), digits, destination, out charsWritten);
- }
- else
- {
- NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);
-
- byte* pDigits = stackalloc byte[Int32NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, Int32NumberBufferLength);
-
- Int32ToNumber(value, ref number);
-
- char* stackPtr = stackalloc char[CharStackBufferSize];
- ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(stackPtr, CharStackBufferSize));
-
- if (fmt != 0)
- {
- NumberToString(ref sb, ref number, fmt, digits, info);
- }
- else
- {
- NumberToStringFormat(ref sb, ref number, format, info);
- }
- return sb.TryCopyTo(destination, out charsWritten);
- }
- }
-
- public static unsafe string FormatUInt32(uint value, ReadOnlySpan<char> format, IFormatProvider? provider)
- {
- // Fast path for default format
- if (format.Length == 0)
- {
- return UInt32ToDecStr(value, digits: -1);
- }
-
- char fmt = ParseFormatSpecifier(format, out int digits);
- char fmtUpper = (char)(fmt & 0xFFDF); // ensure fmt is upper-cased for purposes of comparison
- if ((fmtUpper == 'G' && digits < 1) || fmtUpper == 'D')
- {
- return UInt32ToDecStr(value, digits);
- }
- else if (fmtUpper == 'X')
- {
- // The fmt-(X-A+10) hack has the effect of dictating whether we produce uppercase or lowercase
- // hex numbers for a-f. 'X' as the fmt code produces uppercase. 'x' as the format code produces lowercase.
- return Int32ToHexStr((int)value, (char)(fmt - ('X' - 'A' + 10)), digits);
- }
- else
- {
- NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);
-
- byte* pDigits = stackalloc byte[UInt32NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, UInt32NumberBufferLength);
-
- UInt32ToNumber(value, ref number);
-
- char* stackPtr = stackalloc char[CharStackBufferSize];
- ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(stackPtr, CharStackBufferSize));
-
- if (fmt != 0)
- {
- NumberToString(ref sb, ref number, fmt, digits, info);
- }
- else
- {
- NumberToStringFormat(ref sb, ref number, format, info);
- }
- return sb.ToString();
- }
- }
-
- public static unsafe bool TryFormatUInt32(uint value, ReadOnlySpan<char> format, IFormatProvider? provider, Span<char> destination, out int charsWritten)
- {
- // Fast path for default format
- if (format.Length == 0)
- {
- return TryUInt32ToDecStr(value, digits: -1, destination, out charsWritten);
- }
-
- char fmt = ParseFormatSpecifier(format, out int digits);
- char fmtUpper = (char)(fmt & 0xFFDF); // ensure fmt is upper-cased for purposes of comparison
- if ((fmtUpper == 'G' && digits < 1) || fmtUpper == 'D')
- {
- return TryUInt32ToDecStr(value, digits, destination, out charsWritten);
- }
- else if (fmtUpper == 'X')
- {
- // The fmt-(X-A+10) hack has the effect of dictating whether we produce uppercase or lowercase
- // hex numbers for a-f. 'X' as the fmt code produces uppercase. 'x' as the format code produces lowercase.
- return TryInt32ToHexStr((int)value, (char)(fmt - ('X' - 'A' + 10)), digits, destination, out charsWritten);
- }
- else
- {
- NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);
-
- byte* pDigits = stackalloc byte[UInt32NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, UInt32NumberBufferLength);
-
- UInt32ToNumber(value, ref number);
-
- char* stackPtr = stackalloc char[CharStackBufferSize];
- ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(stackPtr, CharStackBufferSize));
-
- if (fmt != 0)
- {
- NumberToString(ref sb, ref number, fmt, digits, info);
- }
- else
- {
- NumberToStringFormat(ref sb, ref number, format, info);
- }
- return sb.TryCopyTo(destination, out charsWritten);
- }
- }
-
- public static unsafe string FormatInt64(long value, ReadOnlySpan<char> format, IFormatProvider? provider)
- {
- // Fast path for default format with a non-negative value
- if (value >= 0 && format.Length == 0)
- {
- return UInt64ToDecStr((ulong)value, digits: -1);
- }
-
- char fmt = ParseFormatSpecifier(format, out int digits);
- char fmtUpper = (char)(fmt & 0xFFDF); // ensure fmt is upper-cased for purposes of comparison
- if ((fmtUpper == 'G' && digits < 1) || fmtUpper == 'D')
- {
- return value >= 0 ?
- UInt64ToDecStr((ulong)value, digits) :
- NegativeInt64ToDecStr(value, digits, NumberFormatInfo.GetInstance(provider).NegativeSign);
- }
- else if (fmtUpper == 'X')
- {
- // The fmt-(X-A+10) hack has the effect of dictating whether we produce uppercase or lowercase
- // hex numbers for a-f. 'X' as the fmt code produces uppercase. 'x' as the format code
- // produces lowercase.
- return Int64ToHexStr(value, (char)(fmt - ('X' - 'A' + 10)), digits);
- }
- else
- {
- NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);
-
- byte* pDigits = stackalloc byte[Int64NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, Int64NumberBufferLength);
-
- Int64ToNumber(value, ref number);
-
- char* stackPtr = stackalloc char[CharStackBufferSize];
- ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(stackPtr, CharStackBufferSize));
-
- if (fmt != 0)
- {
- NumberToString(ref sb, ref number, fmt, digits, info);
- }
- else
- {
- NumberToStringFormat(ref sb, ref number, format, info);
- }
- return sb.ToString();
- }
- }
-
- public static unsafe bool TryFormatInt64(long value, ReadOnlySpan<char> format, IFormatProvider? provider, Span<char> destination, out int charsWritten)
- {
- // Fast path for default format with a non-negative value
- if (value >= 0 && format.Length == 0)
- {
- return TryUInt64ToDecStr((ulong)value, digits: -1, destination, out charsWritten);
- }
-
- char fmt = ParseFormatSpecifier(format, out int digits);
- char fmtUpper = (char)(fmt & 0xFFDF); // ensure fmt is upper-cased for purposes of comparison
- if ((fmtUpper == 'G' && digits < 1) || fmtUpper == 'D')
- {
- return value >= 0 ?
- TryUInt64ToDecStr((ulong)value, digits, destination, out charsWritten) :
- TryNegativeInt64ToDecStr(value, digits, NumberFormatInfo.GetInstance(provider).NegativeSign, destination, out charsWritten);
- }
- else if (fmtUpper == 'X')
- {
- // The fmt-(X-A+10) hack has the effect of dictating whether we produce uppercase or lowercase
- // hex numbers for a-f. 'X' as the fmt code produces uppercase. 'x' as the format code
- // produces lowercase.
- return TryInt64ToHexStr(value, (char)(fmt - ('X' - 'A' + 10)), digits, destination, out charsWritten);
- }
- else
- {
- NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);
-
- byte* pDigits = stackalloc byte[Int64NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, Int64NumberBufferLength);
-
- Int64ToNumber(value, ref number);
-
- char* stackPtr = stackalloc char[CharStackBufferSize];
- ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(stackPtr, CharStackBufferSize));
-
- if (fmt != 0)
- {
- NumberToString(ref sb, ref number, fmt, digits, info);
- }
- else
- {
- NumberToStringFormat(ref sb, ref number, format, info);
- }
- return sb.TryCopyTo(destination, out charsWritten);
- }
- }
-
- public static unsafe string FormatUInt64(ulong value, ReadOnlySpan<char> format, IFormatProvider? provider)
- {
- // Fast path for default format
- if (format.Length == 0)
- {
- return UInt64ToDecStr(value, digits: -1);
- }
-
- char fmt = ParseFormatSpecifier(format, out int digits);
- char fmtUpper = (char)(fmt & 0xFFDF); // ensure fmt is upper-cased for purposes of comparison
- if ((fmtUpper == 'G' && digits < 1) || fmtUpper == 'D')
- {
- return UInt64ToDecStr(value, digits);
- }
- else if (fmtUpper == 'X')
- {
- // The fmt-(X-A+10) hack has the effect of dictating whether we produce uppercase or lowercase
- // hex numbers for a-f. 'X' as the fmt code produces uppercase. 'x' as the format code
- // produces lowercase.
- return Int64ToHexStr((long)value, (char)(fmt - ('X' - 'A' + 10)), digits);
- }
- else
- {
- NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);
-
- byte* pDigits = stackalloc byte[UInt64NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, UInt64NumberBufferLength);
-
- UInt64ToNumber(value, ref number);
-
- char* stackPtr = stackalloc char[CharStackBufferSize];
- ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(stackPtr, CharStackBufferSize));
-
- if (fmt != 0)
- {
- NumberToString(ref sb, ref number, fmt, digits, info);
- }
- else
- {
- NumberToStringFormat(ref sb, ref number, format, info);
- }
- return sb.ToString();
- }
- }
-
- public static unsafe bool TryFormatUInt64(ulong value, ReadOnlySpan<char> format, IFormatProvider? provider, Span<char> destination, out int charsWritten)
- {
- // Fast path for default format
- if (format.Length == 0)
- {
- return TryUInt64ToDecStr(value, digits: -1, destination, out charsWritten);
- }
-
- char fmt = ParseFormatSpecifier(format, out int digits);
- char fmtUpper = (char)(fmt & 0xFFDF); // ensure fmt is upper-cased for purposes of comparison
- if ((fmtUpper == 'G' && digits < 1) || fmtUpper == 'D')
- {
- return TryUInt64ToDecStr(value, digits, destination, out charsWritten);
- }
- else if (fmtUpper == 'X')
- {
- // The fmt-(X-A+10) hack has the effect of dictating whether we produce uppercase or lowercase
- // hex numbers for a-f. 'X' as the fmt code produces uppercase. 'x' as the format code
- // produces lowercase.
- return TryInt64ToHexStr((long)value, (char)(fmt - ('X' - 'A' + 10)), digits, destination, out charsWritten);
- }
- else
- {
- NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);
-
- byte* pDigits = stackalloc byte[UInt64NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, UInt64NumberBufferLength);
-
- UInt64ToNumber(value, ref number);
-
- char* stackPtr = stackalloc char[CharStackBufferSize];
- ValueStringBuilder sb = new ValueStringBuilder(new Span<char>(stackPtr, CharStackBufferSize));
-
- if (fmt != 0)
- {
- NumberToString(ref sb, ref number, fmt, digits, info);
- }
- else
- {
- NumberToStringFormat(ref sb, ref number, format, info);
- }
- return sb.TryCopyTo(destination, out charsWritten);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // called from only one location
- private static unsafe void Int32ToNumber(int value, ref NumberBuffer number)
- {
- number.DigitsCount = Int32Precision;
-
- if (value >= 0)
- {
- number.IsNegative = false;
- }
- else
- {
- number.IsNegative = true;
- value = -value;
- }
-
- byte* buffer = number.GetDigitsPointer();
- byte* p = UInt32ToDecChars(buffer + Int32Precision, (uint)value, 0);
-
- int i = (int)(buffer + Int32Precision - p);
-
- number.DigitsCount = i;
- number.Scale = i;
-
- byte* dst = number.GetDigitsPointer();
- while (--i >= 0)
- *dst++ = *p++;
- *dst = (byte)('\0');
-
- number.CheckConsistency();
- }
-
- private static unsafe string NegativeInt32ToDecStr(int value, int digits, string sNegative)
- {
- Debug.Assert(value < 0);
-
- if (digits < 1)
- digits = 1;
-
- int bufferLength = Math.Max(digits, FormattingHelpers.CountDigits((uint)(-value))) + sNegative.Length;
- string result = string.FastAllocateString(bufferLength);
- fixed (char* buffer = result)
- {
- char* p = UInt32ToDecChars(buffer + bufferLength, (uint)(-value), digits);
- Debug.Assert(p == buffer + sNegative.Length);
-
- for (int i = sNegative.Length - 1; i >= 0; i--)
- {
- *(--p) = sNegative[i];
- }
- Debug.Assert(p == buffer);
- }
- return result;
- }
-
- private static unsafe bool TryNegativeInt32ToDecStr(int value, int digits, string sNegative, Span<char> destination, out int charsWritten)
- {
- Debug.Assert(value < 0);
-
- if (digits < 1)
- digits = 1;
-
- int bufferLength = Math.Max(digits, FormattingHelpers.CountDigits((uint)(-value))) + sNegative.Length;
- if (bufferLength > destination.Length)
- {
- charsWritten = 0;
- return false;
- }
-
- charsWritten = bufferLength;
- fixed (char* buffer = &MemoryMarshal.GetReference(destination))
- {
- char* p = UInt32ToDecChars(buffer + bufferLength, (uint)(-value), digits);
- Debug.Assert(p == buffer + sNegative.Length);
-
- for (int i = sNegative.Length - 1; i >= 0; i--)
- {
- *(--p) = sNegative[i];
- }
- Debug.Assert(p == buffer);
- }
- return true;
- }
-
- private static unsafe string Int32ToHexStr(int value, char hexBase, int digits)
- {
- if (digits < 1)
- digits = 1;
-
- int bufferLength = Math.Max(digits, FormattingHelpers.CountHexDigits((uint)value));
- string result = string.FastAllocateString(bufferLength);
- fixed (char* buffer = result)
- {
- char* p = Int32ToHexChars(buffer + bufferLength, (uint)value, hexBase, digits);
- Debug.Assert(p == buffer);
- }
- return result;
- }
-
- private static unsafe bool TryInt32ToHexStr(int value, char hexBase, int digits, Span<char> destination, out int charsWritten)
- {
- if (digits < 1)
- digits = 1;
-
- int bufferLength = Math.Max(digits, FormattingHelpers.CountHexDigits((uint)value));
- if (bufferLength > destination.Length)
- {
- charsWritten = 0;
- return false;
- }
-
- charsWritten = bufferLength;
- fixed (char* buffer = &MemoryMarshal.GetReference(destination))
- {
- char* p = Int32ToHexChars(buffer + bufferLength, (uint)value, hexBase, digits);
- Debug.Assert(p == buffer);
- }
- return true;
- }
-
- private static unsafe char* Int32ToHexChars(char* buffer, uint value, int hexBase, int digits)
- {
- while (--digits >= 0 || value != 0)
- {
- byte digit = (byte)(value & 0xF);
- *(--buffer) = (char)(digit + (digit < 10 ? (byte)'0' : hexBase));
- value >>= 4;
- }
- return buffer;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // called from only one location
- private static unsafe void UInt32ToNumber(uint value, ref NumberBuffer number)
- {
- number.DigitsCount = UInt32Precision;
- number.IsNegative = false;
-
- byte* buffer = number.GetDigitsPointer();
- byte* p = UInt32ToDecChars(buffer + UInt32Precision, value, 0);
-
- int i = (int)(buffer + UInt32Precision - p);
-
- number.DigitsCount = i;
- number.Scale = i;
-
- byte* dst = number.GetDigitsPointer();
- while (--i >= 0)
- *dst++ = *p++;
- *dst = (byte)('\0');
-
- number.CheckConsistency();
- }
-
- internal static unsafe byte* UInt32ToDecChars(byte* bufferEnd, uint value, int digits)
- {
- while (--digits >= 0 || value != 0)
- {
- value = Math.DivRem(value, 10, out uint remainder);
- *(--bufferEnd) = (byte)(remainder + '0');
- }
- return bufferEnd;
- }
-
- internal static unsafe char* UInt32ToDecChars(char* bufferEnd, uint value, int digits)
- {
- while (--digits >= 0 || value != 0)
- {
- value = Math.DivRem(value, 10, out uint remainder);
- *(--bufferEnd) = (char)(remainder + '0');
- }
- return bufferEnd;
- }
-
- internal static unsafe string UInt32ToDecStr(uint value, int digits)
- {
- int bufferLength = Math.Max(digits, FormattingHelpers.CountDigits(value));
-
- // For single-digit values that are very common, especially 0 and 1, just return cached strings.
- if (bufferLength == 1)
- {
- return s_singleDigitStringCache[value];
- }
-
- string result = string.FastAllocateString(bufferLength);
- fixed (char* buffer = result)
- {
- char* p = buffer + bufferLength;
- if (digits <= 1)
- {
- do
- {
- value = Math.DivRem(value, 10, out uint remainder);
- *(--p) = (char)(remainder + '0');
- }
- while (value != 0);
- }
- else
- {
- p = UInt32ToDecChars(p, value, digits);
- }
- Debug.Assert(p == buffer);
- }
- return result;
- }
-
- private static unsafe bool TryUInt32ToDecStr(uint value, int digits, Span<char> destination, out int charsWritten)
- {
- int bufferLength = Math.Max(digits, FormattingHelpers.CountDigits(value));
- if (bufferLength > destination.Length)
- {
- charsWritten = 0;
- return false;
- }
-
- charsWritten = bufferLength;
- fixed (char* buffer = &MemoryMarshal.GetReference(destination))
- {
- char* p = buffer + bufferLength;
- if (digits <= 1)
- {
- do
- {
- value = Math.DivRem(value, 10, out uint remainder);
- *(--p) = (char)(remainder + '0');
- }
- while (value != 0);
- }
- else
- {
- p = UInt32ToDecChars(p, value, digits);
- }
- Debug.Assert(p == buffer);
- }
- return true;
- }
-
- private static unsafe void Int64ToNumber(long input, ref NumberBuffer number)
- {
- ulong value = (ulong)input;
- number.IsNegative = input < 0;
- number.DigitsCount = Int64Precision;
- if (number.IsNegative)
- {
- value = (ulong)(-input);
- }
-
- byte* buffer = number.GetDigitsPointer();
- byte* p = buffer + Int64Precision;
- while (High32(value) != 0)
- p = UInt32ToDecChars(p, Int64DivMod1E9(ref value), 9);
- p = UInt32ToDecChars(p, Low32(value), 0);
-
- int i = (int)(buffer + Int64Precision - p);
-
- number.DigitsCount = i;
- number.Scale = i;
-
- byte* dst = number.GetDigitsPointer();
- while (--i >= 0)
- *dst++ = *p++;
- *dst = (byte)('\0');
-
- number.CheckConsistency();
- }
-
- private static unsafe string NegativeInt64ToDecStr(long input, int digits, string sNegative)
- {
- Debug.Assert(input < 0);
-
- if (digits < 1)
- {
- digits = 1;
- }
-
- ulong value = (ulong)(-input);
-
- int bufferLength = Math.Max(digits, FormattingHelpers.CountDigits(value)) + sNegative.Length;
- string result = string.FastAllocateString(bufferLength);
- fixed (char* buffer = result)
- {
- char* p = buffer + bufferLength;
- while (High32(value) != 0)
- {
- p = UInt32ToDecChars(p, Int64DivMod1E9(ref value), 9);
- digits -= 9;
- }
- p = UInt32ToDecChars(p, Low32(value), digits);
- Debug.Assert(p == buffer + sNegative.Length);
-
- for (int i = sNegative.Length - 1; i >= 0; i--)
- {
- *(--p) = sNegative[i];
- }
- Debug.Assert(p == buffer);
- }
- return result;
- }
-
- private static unsafe bool TryNegativeInt64ToDecStr(long input, int digits, string sNegative, Span<char> destination, out int charsWritten)
- {
- Debug.Assert(input < 0);
-
- if (digits < 1)
- {
- digits = 1;
- }
-
- ulong value = (ulong)(-input);
-
- int bufferLength = Math.Max(digits, FormattingHelpers.CountDigits((ulong)(-input))) + sNegative.Length;
- if (bufferLength > destination.Length)
- {
- charsWritten = 0;
- return false;
- }
-
- charsWritten = bufferLength;
- fixed (char* buffer = &MemoryMarshal.GetReference(destination))
- {
- char* p = buffer + bufferLength;
- while (High32(value) != 0)
- {
- p = UInt32ToDecChars(p, Int64DivMod1E9(ref value), 9);
- digits -= 9;
- }
- p = UInt32ToDecChars(p, Low32(value), digits);
- Debug.Assert(p == buffer + sNegative.Length);
-
- for (int i = sNegative.Length - 1; i >= 0; i--)
- {
- *(--p) = sNegative[i];
- }
- Debug.Assert(p == buffer);
- }
- return true;
- }
-
- private static unsafe string Int64ToHexStr(long value, char hexBase, int digits)
- {
- int bufferLength = Math.Max(digits, FormattingHelpers.CountHexDigits((ulong)value));
- string result = string.FastAllocateString(bufferLength);
- fixed (char* buffer = result)
- {
- char* p = buffer + bufferLength;
- if (High32((ulong)value) != 0)
- {
- p = Int32ToHexChars(p, Low32((ulong)value), hexBase, 8);
- p = Int32ToHexChars(p, High32((ulong)value), hexBase, digits - 8);
- }
- else
- {
- p = Int32ToHexChars(p, Low32((ulong)value), hexBase, Math.Max(digits, 1));
- }
- Debug.Assert(p == buffer);
- }
- return result;
- }
-
- private static unsafe bool TryInt64ToHexStr(long value, char hexBase, int digits, Span<char> destination, out int charsWritten)
- {
- int bufferLength = Math.Max(digits, FormattingHelpers.CountHexDigits((ulong)value));
- if (bufferLength > destination.Length)
- {
- charsWritten = 0;
- return false;
- }
-
- charsWritten = bufferLength;
- fixed (char* buffer = &MemoryMarshal.GetReference(destination))
- {
- char* p = buffer + bufferLength;
- if (High32((ulong)value) != 0)
- {
- p = Int32ToHexChars(p, Low32((ulong)value), hexBase, 8);
- p = Int32ToHexChars(p, High32((ulong)value), hexBase, digits - 8);
- }
- else
- {
- p = Int32ToHexChars(p, Low32((ulong)value), hexBase, Math.Max(digits, 1));
- }
- Debug.Assert(p == buffer);
- }
- return true;
- }
-
- private static unsafe void UInt64ToNumber(ulong value, ref NumberBuffer number)
- {
- number.DigitsCount = UInt64Precision;
- number.IsNegative = false;
-
- byte* buffer = number.GetDigitsPointer();
- byte* p = buffer + UInt64Precision;
-
- while (High32(value) != 0)
- p = UInt32ToDecChars(p, Int64DivMod1E9(ref value), 9);
- p = UInt32ToDecChars(p, Low32(value), 0);
-
- int i = (int)(buffer + UInt64Precision - p);
-
- number.DigitsCount = i;
- number.Scale = i;
-
- byte* dst = number.GetDigitsPointer();
- while (--i >= 0)
- *dst++ = *p++;
- *dst = (byte)('\0');
-
- number.CheckConsistency();
- }
-
- internal static unsafe string UInt64ToDecStr(ulong value, int digits)
- {
- if (digits < 1)
- digits = 1;
-
- int bufferLength = Math.Max(digits, FormattingHelpers.CountDigits(value));
-
- // For single-digit values that are very common, especially 0 and 1, just return cached strings.
- if (bufferLength == 1)
- {
- return s_singleDigitStringCache[value];
- }
-
- string result = string.FastAllocateString(bufferLength);
- fixed (char* buffer = result)
- {
- char* p = buffer + bufferLength;
- while (High32(value) != 0)
- {
- p = UInt32ToDecChars(p, Int64DivMod1E9(ref value), 9);
- digits -= 9;
- }
- p = UInt32ToDecChars(p, Low32(value), digits);
- Debug.Assert(p == buffer);
- }
- return result;
- }
-
- private static unsafe bool TryUInt64ToDecStr(ulong value, int digits, Span<char> destination, out int charsWritten)
- {
- if (digits < 1)
- digits = 1;
-
- int bufferLength = Math.Max(digits, FormattingHelpers.CountDigits(value));
- if (bufferLength > destination.Length)
- {
- charsWritten = 0;
- return false;
- }
-
- charsWritten = bufferLength;
- fixed (char* buffer = &MemoryMarshal.GetReference(destination))
- {
- char* p = buffer + bufferLength;
- while (High32(value) != 0)
- {
- p = UInt32ToDecChars(p, Int64DivMod1E9(ref value), 9);
- digits -= 9;
- }
- p = UInt32ToDecChars(p, Low32(value), digits);
- Debug.Assert(p == buffer);
- }
- return true;
- }
-
- internal static unsafe char ParseFormatSpecifier(ReadOnlySpan<char> format, out int digits)
- {
- char c = default;
- if (format.Length > 0)
- {
- // If the format begins with a symbol, see if it's a standard format
- // with or without a specified number of digits.
- c = format[0];
- if ((uint)(c - 'A') <= 'Z' - 'A' ||
- (uint)(c - 'a') <= 'z' - 'a')
- {
- // Fast path for sole symbol, e.g. "D"
- if (format.Length == 1)
- {
- digits = -1;
- return c;
- }
-
- if (format.Length == 2)
- {
- // Fast path for symbol and single digit, e.g. "X4"
- int d = format[1] - '0';
- if ((uint)d < 10)
- {
- digits = d;
- return c;
- }
- }
- else if (format.Length == 3)
- {
- // Fast path for symbol and double digit, e.g. "F12"
- int d1 = format[1] - '0', d2 = format[2] - '0';
- if ((uint)d1 < 10 && (uint)d2 < 10)
- {
- digits = d1 * 10 + d2;
- return c;
- }
- }
-
- // Fallback for symbol and any length digits. The digits value must be >= 0 && <= 99,
- // but it can begin with any number of 0s, and thus we may need to check more than two
- // digits. Further, for compat, we need to stop when we hit a null char.
- int n = 0;
- int i = 1;
- while (i < format.Length && (((uint)format[i] - '0') < 10) && n < 10)
- {
- n = (n * 10) + format[i++] - '0';
- }
-
- // If we're at the end of the digits rather than having stopped because we hit something
- // other than a digit or overflowed, return the standard format info.
- if (i == format.Length || format[i] == '\0')
- {
- digits = n;
- return c;
- }
- }
- }
-
- // Default empty format to be "G"; custom format is signified with '\0'.
- digits = -1;
- return format.Length == 0 || c == '\0' ? // For compat, treat '\0' as the end of the specifier, even if the specifier extends beyond it.
- 'G' :
- '\0';
- }
-
- internal static unsafe void NumberToString(ref ValueStringBuilder sb, ref NumberBuffer number, char format, int nMaxDigits, NumberFormatInfo info)
- {
- number.CheckConsistency();
- bool isCorrectlyRounded = (number.Kind == NumberBufferKind.FloatingPoint);
-
- switch (format)
- {
- case 'C':
- case 'c':
- {
- if (nMaxDigits < 0)
- nMaxDigits = info.CurrencyDecimalDigits;
-
- RoundNumber(ref number, number.Scale + nMaxDigits, isCorrectlyRounded); // Don't change this line to use digPos since digCount could have its sign changed.
-
- FormatCurrency(ref sb, ref number, nMaxDigits, info);
-
- break;
- }
-
- case 'F':
- case 'f':
- {
- if (nMaxDigits < 0)
- nMaxDigits = info.NumberDecimalDigits;
-
- RoundNumber(ref number, number.Scale + nMaxDigits, isCorrectlyRounded);
-
- if (number.IsNegative)
- sb.Append(info.NegativeSign);
-
- FormatFixed(ref sb, ref number, nMaxDigits, null, info.NumberDecimalSeparator, null);
-
- break;
- }
-
- case 'N':
- case 'n':
- {
- if (nMaxDigits < 0)
- nMaxDigits = info.NumberDecimalDigits; // Since we are using digits in our calculation
-
- RoundNumber(ref number, number.Scale + nMaxDigits, isCorrectlyRounded);
-
- FormatNumber(ref sb, ref number, nMaxDigits, info);
-
- break;
- }
-
- case 'E':
- case 'e':
- {
- if (nMaxDigits < 0)
- nMaxDigits = DefaultPrecisionExponentialFormat;
- nMaxDigits++;
-
- RoundNumber(ref number, nMaxDigits, isCorrectlyRounded);
-
- if (number.IsNegative)
- sb.Append(info.NegativeSign);
-
- FormatScientific(ref sb, ref number, nMaxDigits, info, format);
-
- break;
- }
-
- case 'G':
- case 'g':
- {
- bool noRounding = false;
- if (nMaxDigits < 1)
- {
- if ((number.Kind == NumberBufferKind.Decimal) && (nMaxDigits == -1))
- {
- noRounding = true; // Turn off rounding for ECMA compliance to output trailing 0's after decimal as significant
-
- if (number.Digits[0] == 0)
- {
- // -0 should be formatted as 0 for decimal. This is normally handled by RoundNumber (which we are skipping)
- goto SkipSign;
- }
-
- goto SkipRounding;
- }
- else
- {
- // This ensures that the PAL code pads out to the correct place even when we use the default precision
- nMaxDigits = number.DigitsCount;
- }
- }
-
- RoundNumber(ref number, nMaxDigits, isCorrectlyRounded);
-
- SkipRounding:
- if (number.IsNegative)
- sb.Append(info.NegativeSign);
-
- SkipSign:
- FormatGeneral(ref sb, ref number, nMaxDigits, info, (char)(format - ('G' - 'E')), noRounding);
-
- break;
- }
-
- case 'P':
- case 'p':
- {
- if (nMaxDigits < 0)
- nMaxDigits = info.PercentDecimalDigits;
- number.Scale += 2;
-
- RoundNumber(ref number, number.Scale + nMaxDigits, isCorrectlyRounded);
-
- FormatPercent(ref sb, ref number, nMaxDigits, info);
-
- break;
- }
-
- case 'R':
- case 'r':
- {
- if (number.Kind != NumberBufferKind.FloatingPoint)
- {
- goto default;
- }
-
- format = (char)(format - ('R' - 'G'));
- Debug.Assert((format == 'G') || (format == 'g'));
- goto case 'G';
- }
-
- default:
- throw new FormatException(SR.Argument_BadFormatSpecifier);
- }
- }
-
- internal static unsafe void NumberToStringFormat(ref ValueStringBuilder sb, ref NumberBuffer number, ReadOnlySpan<char> format, NumberFormatInfo info)
- {
- number.CheckConsistency();
-
- int digitCount;
- int decimalPos;
- int firstDigit;
- int lastDigit;
- int digPos;
- bool scientific;
- int thousandPos;
- int thousandCount = 0;
- bool thousandSeps;
- int scaleAdjust;
- int adjust;
-
- int section;
- int src;
- byte* dig = number.GetDigitsPointer();
- char ch;
-
- section = FindSection(format, dig[0] == 0 ? 2 : number.IsNegative ? 1 : 0);
-
- while (true)
- {
- digitCount = 0;
- decimalPos = -1;
- firstDigit = 0x7FFFFFFF;
- lastDigit = 0;
- scientific = false;
- thousandPos = -1;
- thousandSeps = false;
- scaleAdjust = 0;
- src = section;
-
- fixed (char* pFormat = &MemoryMarshal.GetReference(format))
- {
- while (src < format.Length && (ch = pFormat[src++]) != 0 && ch != ';')
- {
- switch (ch)
- {
- case '#':
- digitCount++;
- break;
- case '0':
- if (firstDigit == 0x7FFFFFFF)
- firstDigit = digitCount;
- digitCount++;
- lastDigit = digitCount;
- break;
- case '.':
- if (decimalPos < 0)
- decimalPos = digitCount;
- break;
- case ',':
- if (digitCount > 0 && decimalPos < 0)
- {
- if (thousandPos >= 0)
- {
- if (thousandPos == digitCount)
- {
- thousandCount++;
- break;
- }
- thousandSeps = true;
- }
- thousandPos = digitCount;
- thousandCount = 1;
- }
- break;
- case '%':
- scaleAdjust += 2;
- break;
- case '\x2030':
- scaleAdjust += 3;
- break;
- case '\'':
- case '"':
- while (src < format.Length && pFormat[src] != 0 && pFormat[src++] != ch)
- ;
- break;
- case '\\':
- if (src < format.Length && pFormat[src] != 0)
- src++;
- break;
- case 'E':
- case 'e':
- if ((src < format.Length && pFormat[src] == '0') ||
- (src + 1 < format.Length && (pFormat[src] == '+' || pFormat[src] == '-') && pFormat[src + 1] == '0'))
- {
- while (++src < format.Length && pFormat[src] == '0')
- ;
- scientific = true;
- }
- break;
- }
- }
- }
-
- if (decimalPos < 0)
- decimalPos = digitCount;
-
- if (thousandPos >= 0)
- {
- if (thousandPos == decimalPos)
- scaleAdjust -= thousandCount * 3;
- else
- thousandSeps = true;
- }
-
- if (dig[0] != 0)
- {
- number.Scale += scaleAdjust;
- int pos = scientific ? digitCount : number.Scale + digitCount - decimalPos;
- RoundNumber(ref number, pos, isCorrectlyRounded: false);
- if (dig[0] == 0)
- {
- src = FindSection(format, 2);
- if (src != section)
- {
- section = src;
- continue;
- }
- }
- }
- else
- {
- if (number.Kind != NumberBufferKind.FloatingPoint)
- {
- // The integer types don't have a concept of -0 and decimal always format -0 as 0
- number.IsNegative = false;
- }
- number.Scale = 0; // Decimals with scale ('0.00') should be rounded.
- }
-
- break;
- }
-
- firstDigit = firstDigit < decimalPos ? decimalPos - firstDigit : 0;
- lastDigit = lastDigit > decimalPos ? decimalPos - lastDigit : 0;
- if (scientific)
- {
- digPos = decimalPos;
- adjust = 0;
- }
- else
- {
- digPos = number.Scale > decimalPos ? number.Scale : decimalPos;
- adjust = number.Scale - decimalPos;
- }
- src = section;
-
- // Adjust can be negative, so we make this an int instead of an unsigned int.
- // Adjust represents the number of characters over the formatting e.g. format string is "0000" and you are trying to
- // format 100000 (6 digits). Means adjust will be 2. On the other hand if you are trying to format 10 adjust will be
- // -2 and we'll need to fixup these digits with 0 padding if we have 0 formatting as in this example.
- Span<int> thousandsSepPos = stackalloc int[4];
- int thousandsSepCtr = -1;
-
- if (thousandSeps)
- {
- // We need to precompute this outside the number formatting loop
- if (info.NumberGroupSeparator.Length > 0)
- {
- // We need this array to figure out where to insert the thousands separator. We would have to traverse the string
- // backwards. PIC formatting always traverses forwards. These indices are precomputed to tell us where to insert
- // the thousands separator so we can get away with traversing forwards. Note we only have to compute up to digPos.
- // The max is not bound since you can have formatting strings of the form "000,000..", and this
- // should handle that case too.
-
- int[] groupDigits = info._numberGroupSizes;
-
- int groupSizeIndex = 0; // Index into the groupDigits array.
- int groupTotalSizeCount = 0;
- int groupSizeLen = groupDigits.Length; // The length of groupDigits array.
- if (groupSizeLen != 0)
- groupTotalSizeCount = groupDigits[groupSizeIndex]; // The current running total of group size.
- int groupSize = groupTotalSizeCount;
-
- int totalDigits = digPos + ((adjust < 0) ? adjust : 0); // Actual number of digits in o/p
- int numDigits = (firstDigit > totalDigits) ? firstDigit : totalDigits;
- while (numDigits > groupTotalSizeCount)
- {
- if (groupSize == 0)
- break;
- ++thousandsSepCtr;
- if (thousandsSepCtr >= thousandsSepPos.Length)
- {
- var newThousandsSepPos = new int[thousandsSepPos.Length * 2];
- thousandsSepPos.CopyTo(newThousandsSepPos);
- thousandsSepPos = newThousandsSepPos;
- }
-
- thousandsSepPos[thousandsSepCtr] = groupTotalSizeCount;
- if (groupSizeIndex < groupSizeLen - 1)
- {
- groupSizeIndex++;
- groupSize = groupDigits[groupSizeIndex];
- }
- groupTotalSizeCount += groupSize;
- }
- }
- }
-
- if (number.IsNegative && (section == 0) && (number.Scale != 0))
- sb.Append(info.NegativeSign);
-
- bool decimalWritten = false;
-
- fixed (char* pFormat = &MemoryMarshal.GetReference(format))
- {
- byte* cur = dig;
-
- while (src < format.Length && (ch = pFormat[src++]) != 0 && ch != ';')
- {
- if (adjust > 0)
- {
- switch (ch)
- {
- case '#':
- case '0':
- case '.':
- while (adjust > 0)
- {
- // digPos will be one greater than thousandsSepPos[thousandsSepCtr] since we are at
- // the character after which the groupSeparator needs to be appended.
- sb.Append(*cur != 0 ? (char)(*cur++) : '0');
- if (thousandSeps && digPos > 1 && thousandsSepCtr >= 0)
- {
- if (digPos == thousandsSepPos[thousandsSepCtr] + 1)
- {
- sb.Append(info.NumberGroupSeparator);
- thousandsSepCtr--;
- }
- }
- digPos--;
- adjust--;
- }
- break;
- }
- }
-
- switch (ch)
- {
- case '#':
- case '0':
- {
- if (adjust < 0)
- {
- adjust++;
- ch = digPos <= firstDigit ? '0' : '\0';
- }
- else
- {
- ch = *cur != 0 ? (char)(*cur++) : digPos > lastDigit ? '0' : '\0';
- }
- if (ch != 0)
- {
- sb.Append(ch);
- if (thousandSeps && digPos > 1 && thousandsSepCtr >= 0)
- {
- if (digPos == thousandsSepPos[thousandsSepCtr] + 1)
- {
- sb.Append(info.NumberGroupSeparator);
- thousandsSepCtr--;
- }
- }
- }
-
- digPos--;
- break;
- }
- case '.':
- {
- if (digPos != 0 || decimalWritten)
- {
- // For compatibility, don't echo repeated decimals
- break;
- }
- // If the format has trailing zeros or the format has a decimal and digits remain
- if (lastDigit < 0 || (decimalPos < digitCount && *cur != 0))
- {
- sb.Append(info.NumberDecimalSeparator);
- decimalWritten = true;
- }
- break;
- }
- case '\x2030':
- sb.Append(info.PerMilleSymbol);
- break;
- case '%':
- sb.Append(info.PercentSymbol);
- break;
- case ',':
- break;
- case '\'':
- case '"':
- while (src < format.Length && pFormat[src] != 0 && pFormat[src] != ch)
- sb.Append(pFormat[src++]);
- if (src < format.Length && pFormat[src] != 0)
- src++;
- break;
- case '\\':
- if (src < format.Length && pFormat[src] != 0)
- sb.Append(pFormat[src++]);
- break;
- case 'E':
- case 'e':
- {
- bool positiveSign = false;
- int i = 0;
- if (scientific)
- {
- if (src < format.Length && pFormat[src] == '0')
- {
- // Handles E0, which should format the same as E-0
- i++;
- }
- else if (src + 1 < format.Length && pFormat[src] == '+' && pFormat[src + 1] == '0')
- {
- // Handles E+0
- positiveSign = true;
- }
- else if (src + 1 < format.Length && pFormat[src] == '-' && pFormat[src + 1] == '0')
- {
- // Handles E-0
- // Do nothing, this is just a place holder s.t. we don't break out of the loop.
- }
- else
- {
- sb.Append(ch);
- break;
- }
-
- while (++src < format.Length && pFormat[src] == '0')
- i++;
- if (i > 10)
- i = 10;
-
- int exp = dig[0] == 0 ? 0 : number.Scale - decimalPos;
- FormatExponent(ref sb, info, exp, ch, i, positiveSign);
- scientific = false;
- }
- else
- {
- sb.Append(ch); // Copy E or e to output
- if (src < format.Length)
- {
- if (pFormat[src] == '+' || pFormat[src] == '-')
- sb.Append(pFormat[src++]);
- while (src < format.Length && pFormat[src] == '0')
- sb.Append(pFormat[src++]);
- }
- }
- break;
- }
- default:
- sb.Append(ch);
- break;
- }
- }
- }
-
- if (number.IsNegative && (section == 0) && (number.Scale == 0) && (sb.Length > 0))
- sb.Insert(0, info.NegativeSign);
- }
-
- private static void FormatCurrency(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info)
- {
- string fmt = number.IsNegative ?
- s_negCurrencyFormats[info.CurrencyNegativePattern] :
- s_posCurrencyFormats[info.CurrencyPositivePattern];
-
- foreach (char ch in fmt)
- {
- switch (ch)
- {
- case '#':
- FormatFixed(ref sb, ref number, nMaxDigits, info._currencyGroupSizes, info.CurrencyDecimalSeparator, info.CurrencyGroupSeparator);
- break;
- case '-':
- sb.Append(info.NegativeSign);
- break;
- case '$':
- sb.Append(info.CurrencySymbol);
- break;
- default:
- sb.Append(ch);
- break;
- }
- }
- }
-
- private static unsafe void FormatFixed(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, int[]? groupDigits, string? sDecimal, string? sGroup)
- {
- int digPos = number.Scale;
- byte* dig = number.GetDigitsPointer();
-
- if (digPos > 0)
- {
- if (groupDigits != null)
- {
- Debug.Assert(sGroup != null, "Must be nulll when groupDigits != null");
- int groupSizeIndex = 0; // Index into the groupDigits array.
- int bufferSize = digPos; // The length of the result buffer string.
- int groupSize = 0; // The current group size.
-
- // Find out the size of the string buffer for the result.
- if (groupDigits.Length != 0) // You can pass in 0 length arrays
- {
- int groupSizeCount = groupDigits[groupSizeIndex]; // The current total of group size.
-
- while (digPos > groupSizeCount)
- {
- groupSize = groupDigits[groupSizeIndex];
- if (groupSize == 0)
- break;
-
- bufferSize += sGroup.Length;
- if (groupSizeIndex < groupDigits.Length - 1)
- groupSizeIndex++;
-
- groupSizeCount += groupDigits[groupSizeIndex];
- if (groupSizeCount < 0 || bufferSize < 0)
- throw new ArgumentOutOfRangeException(); // If we overflow
- }
-
- groupSize = groupSizeCount == 0 ? 0 : groupDigits[0]; // If you passed in an array with one entry as 0, groupSizeCount == 0
- }
-
- groupSizeIndex = 0;
- int digitCount = 0;
- int digLength = number.DigitsCount;
- int digStart = (digPos < digLength) ? digPos : digLength;
- fixed (char* spanPtr = &MemoryMarshal.GetReference(sb.AppendSpan(bufferSize)))
- {
- char* p = spanPtr + bufferSize - 1;
- for (int i = digPos - 1; i >= 0; i--)
- {
- *(p--) = (i < digStart) ? (char)(dig[i]) : '0';
-
- if (groupSize > 0)
- {
- digitCount++;
- if ((digitCount == groupSize) && (i != 0))
- {
- for (int j = sGroup.Length - 1; j >= 0; j--)
- *(p--) = sGroup[j];
-
- if (groupSizeIndex < groupDigits.Length - 1)
- {
- groupSizeIndex++;
- groupSize = groupDigits[groupSizeIndex];
- }
- digitCount = 0;
- }
- }
- }
-
- Debug.Assert(p >= spanPtr - 1, "Underflow");
- dig += digStart;
- }
- }
- else
- {
- do
- {
- sb.Append(*dig != 0 ? (char)(*dig++) : '0');
- }
- while (--digPos > 0);
- }
- }
- else
- {
- sb.Append('0');
- }
-
- if (nMaxDigits > 0)
- {
- Debug.Assert(sDecimal != null);
- sb.Append(sDecimal);
- if ((digPos < 0) && (nMaxDigits > 0))
- {
- int zeroes = Math.Min(-digPos, nMaxDigits);
- sb.Append('0', zeroes);
- digPos += zeroes;
- nMaxDigits -= zeroes;
- }
-
- while (nMaxDigits > 0)
- {
- sb.Append((*dig != 0) ? (char)(*dig++) : '0');
- nMaxDigits--;
- }
- }
- }
-
- private static void FormatNumber(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info)
- {
- string fmt = number.IsNegative ?
- s_negNumberFormats[info.NumberNegativePattern] :
- PosNumberFormat;
-
- foreach (char ch in fmt)
- {
- switch (ch)
- {
- case '#':
- FormatFixed(ref sb, ref number, nMaxDigits, info._numberGroupSizes, info.NumberDecimalSeparator, info.NumberGroupSeparator);
- break;
- case '-':
- sb.Append(info.NegativeSign);
- break;
- default:
- sb.Append(ch);
- break;
- }
- }
- }
-
- private static unsafe void FormatScientific(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info, char expChar)
- {
- byte* dig = number.GetDigitsPointer();
-
- sb.Append((*dig != 0) ? (char)(*dig++) : '0');
-
- if (nMaxDigits != 1) // For E0 we would like to suppress the decimal point
- sb.Append(info.NumberDecimalSeparator);
-
- while (--nMaxDigits > 0)
- sb.Append((*dig != 0) ? (char)(*dig++) : '0');
-
- int e = number.Digits[0] == 0 ? 0 : number.Scale - 1;
- FormatExponent(ref sb, info, e, expChar, 3, true);
- }
-
- private static unsafe void FormatExponent(ref ValueStringBuilder sb, NumberFormatInfo info, int value, char expChar, int minDigits, bool positiveSign)
- {
- sb.Append(expChar);
-
- if (value < 0)
- {
- sb.Append(info.NegativeSign);
- value = -value;
- }
- else
- {
- if (positiveSign)
- sb.Append(info.PositiveSign);
- }
-
- char* digits = stackalloc char[MaxUInt32DecDigits];
- char* p = UInt32ToDecChars(digits + MaxUInt32DecDigits, (uint)value, minDigits);
- sb.Append(p, (int)(digits + MaxUInt32DecDigits - p));
- }
-
- private static unsafe void FormatGeneral(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info, char expChar, bool bSuppressScientific)
- {
- int digPos = number.Scale;
- bool scientific = false;
-
- if (!bSuppressScientific)
- {
- // Don't switch to scientific notation
- if (digPos > nMaxDigits || digPos < -3)
- {
- digPos = 1;
- scientific = true;
- }
- }
-
- byte* dig = number.GetDigitsPointer();
-
- if (digPos > 0)
- {
- do
- {
- sb.Append((*dig != 0) ? (char)(*dig++) : '0');
- } while (--digPos > 0);
- }
- else
- {
- sb.Append('0');
- }
-
- if (*dig != 0 || digPos < 0)
- {
- sb.Append(info.NumberDecimalSeparator);
-
- while (digPos < 0)
- {
- sb.Append('0');
- digPos++;
- }
-
- while (*dig != 0)
- sb.Append((char)(*dig++));
- }
-
- if (scientific)
- FormatExponent(ref sb, info, number.Scale - 1, expChar, 2, true);
- }
-
- private static void FormatPercent(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info)
- {
- string fmt = number.IsNegative ?
- s_negPercentFormats[info.PercentNegativePattern] :
- s_posPercentFormats[info.PercentPositivePattern];
-
- foreach (char ch in fmt)
- {
- switch (ch)
- {
- case '#':
- FormatFixed(ref sb, ref number, nMaxDigits, info._percentGroupSizes, info.PercentDecimalSeparator, info.PercentGroupSeparator);
- break;
- case '-':
- sb.Append(info.NegativeSign);
- break;
- case '%':
- sb.Append(info.PercentSymbol);
- break;
- default:
- sb.Append(ch);
- break;
- }
- }
- }
-
- internal static unsafe void RoundNumber(ref NumberBuffer number, int pos, bool isCorrectlyRounded)
- {
- byte* dig = number.GetDigitsPointer();
-
- int i = 0;
- while (i < pos && dig[i] != '\0')
- i++;
-
- if ((i == pos) && ShouldRoundUp(dig, i, number.Kind, isCorrectlyRounded))
- {
- while (i > 0 && dig[i - 1] == '9')
- i--;
-
- if (i > 0)
- {
- dig[i - 1]++;
- }
- else
- {
- number.Scale++;
- dig[0] = (byte)('1');
- i = 1;
- }
- }
- else
- {
- while (i > 0 && dig[i - 1] == '0')
- i--;
- }
-
- if (i == 0)
- {
- if (number.Kind != NumberBufferKind.FloatingPoint)
- {
- // The integer types don't have a concept of -0 and decimal always format -0 as 0
- number.IsNegative = false;
- }
- number.Scale = 0; // Decimals with scale ('0.00') should be rounded.
- }
-
- dig[i] = (byte)('\0');
- number.DigitsCount = i;
- number.CheckConsistency();
-
- static bool ShouldRoundUp(byte* dig, int i, NumberBufferKind numberKind, bool isCorrectlyRounded)
- {
- // We only want to round up if the digit is greater than or equal to 5 and we are
- // not rounding a floating-point number. If we are rounding a floating-point number
- // we have one of two cases.
- //
- // In the case of a standard numeric-format specifier, the exact and correctly rounded
- // string will have been produced. In this scenario, pos will have pointed to the
- // terminating null for the buffer and so this will return false.
- //
- // However, in the case of a custom numeric-format specifier, we currently fall back
- // to generating Single/DoublePrecisionCustomFormat digits and then rely on this
- // function to round correctly instead. This can unfortunately lead to double-rounding
- // bugs but is the best we have right now due to back-compat concerns.
-
- byte digit = dig[i];
-
- if ((digit == '\0') || isCorrectlyRounded)
- {
- // Fast path for the common case with no rounding
- return false;
- }
-
- // Values greater than or equal to 5 should round up, otherwise we round down. The IEEE
- // 754 spec actually dictates that ties (exactly 5) should round to the nearest even number
- // but that can have undesired behavior for custom numeric format strings. This probably
- // needs further thought for .NET 5 so that we can be spec compliant and so that users
- // can get the desired rounding behavior for their needs.
-
- return digit >= '5';
- }
- }
-
- private static unsafe int FindSection(ReadOnlySpan<char> format, int section)
- {
- int src;
- char ch;
-
- if (section == 0)
- return 0;
-
- fixed (char* pFormat = &MemoryMarshal.GetReference(format))
- {
- src = 0;
- while (true)
- {
- if (src >= format.Length)
- {
- return 0;
- }
-
- switch (ch = pFormat[src++])
- {
- case '\'':
- case '"':
- while (src < format.Length && pFormat[src] != 0 && pFormat[src++] != ch) ;
- break;
- case '\\':
- if (src < format.Length && pFormat[src] != 0)
- src++;
- break;
- case ';':
- if (--section != 0)
- break;
- if (src < format.Length && pFormat[src] != 0 && pFormat[src] != ';')
- return src;
- goto case '\0';
- case '\0':
- return 0;
- }
- }
- }
- }
-
- private static uint Low32(ulong value) => (uint)value;
-
- private static uint High32(ulong value) => (uint)((value & 0xFFFFFFFF00000000) >> 32);
-
- private static uint Int64DivMod1E9(ref ulong value)
- {
- uint rem = (uint)(value % 1000000000);
- value /= 1000000000;
- return rem;
- }
-
- private static ulong ExtractFractionAndBiasedExponent(double value, out int exponent)
- {
- ulong bits = (ulong)(BitConverter.DoubleToInt64Bits(value));
- ulong fraction = (bits & 0xFFFFFFFFFFFFF);
- exponent = ((int)(bits >> 52) & 0x7FF);
-
- if (exponent != 0)
- {
- // For normalized value, according to https://en.wikipedia.org/wiki/Double-precision_floating-point_format
- // value = 1.fraction * 2^(exp - 1023)
- // = (1 + mantissa / 2^52) * 2^(exp - 1023)
- // = (2^52 + mantissa) * 2^(exp - 1023 - 52)
- //
- // So f = (2^52 + mantissa), e = exp - 1075;
-
- fraction |= (1UL << 52);
- exponent -= 1075;
- }
- else
- {
- // For denormalized value, according to https://en.wikipedia.org/wiki/Double-precision_floating-point_format
- // value = 0.fraction * 2^(1 - 1023)
- // = (mantissa / 2^52) * 2^(-1022)
- // = mantissa * 2^(-1022 - 52)
- // = mantissa * 2^(-1074)
- // So f = mantissa, e = -1074
- exponent = -1074;
- }
-
- return fraction;
- }
-
- private static uint ExtractFractionAndBiasedExponent(float value, out int exponent)
- {
- uint bits = (uint)(BitConverter.SingleToInt32Bits(value));
- uint fraction = (bits & 0x7FFFFF);
- exponent = ((int)(bits >> 23) & 0xFF);
-
- if (exponent != 0)
- {
- // For normalized value, according to https://en.wikipedia.org/wiki/Single-precision_floating-point_format
- // value = 1.fraction * 2^(exp - 127)
- // = (1 + mantissa / 2^23) * 2^(exp - 127)
- // = (2^23 + mantissa) * 2^(exp - 127 - 23)
- //
- // So f = (2^23 + mantissa), e = exp - 150;
-
- fraction |= (1U << 23);
- exponent -= 150;
- }
- else
- {
- // For denormalized value, according to https://en.wikipedia.org/wiki/Single-precision_floating-point_format
- // value = 0.fraction * 2^(1 - 127)
- // = (mantissa / 2^23) * 2^(-126)
- // = mantissa * 2^(-126 - 23)
- // = mantissa * 2^(-149)
- // So f = mantissa, e = -149
- exponent = -149;
- }
-
- return fraction;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Number.Grisu3.cs b/netcore/System.Private.CoreLib/shared/System/Number.Grisu3.cs
deleted file mode 100644
index 528e64e0aa7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Number.Grisu3.cs
+++ /dev/null
@@ -1,1054 +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 System.Diagnostics;
-
-namespace System
-{
- internal static partial class Number
- {
- // This is a port of the `Grisu3` implementation here: https://github.com/google/double-conversion/blob/a711666ddd063eb1e4b181a6cb981d39a1fc8bac/double-conversion/fast-dtoa.cc
- // The backing algorithm and the proofs behind it are described in more detail here: http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf
- // ========================================================================================================================================
- //
- // Overview:
- //
- // The general idea behind Grisu3 is to leverage additional bits and cached powers of ten to generate the correct digits.
- // The algorithm is imprecise for some numbers. Fortunately, the algorithm itself can determine this scenario and gives us
- // a result indicating success or failure. We must fallback to a different algorithm for the failing scenario.
- internal static class Grisu3
- {
- private const int CachedPowersDecimalExponentDistance = 8;
- private const int CachedPowersMinDecimalExponent = -348;
- private const int CachedPowersPowerMaxDecimalExponent = 340;
- private const int CachedPowersOffset = -CachedPowersMinDecimalExponent;
-
- // 1 / Log2(10)
- private const double D1Log210 = 0.301029995663981195;
-
- // The minimal and maximal target exponents define the range of w's binary exponent,
- // where w is the result of multiplying the input by a cached power of ten.
- //
- // A different range might be chosen on a different platform, to optimize digit generation,
- // but a smaller range requires more powers of ten to be cached.
- private const int MaximalTargetExponent = -32;
- private const int MinimalTargetExponent = -60;
-
- private static readonly short[] s_CachedPowersBinaryExponent = new short[]
- {
- -1220,
- -1193,
- -1166,
- -1140,
- -1113,
- -1087,
- -1060,
- -1034,
- -1007,
- -980,
- -954,
- -927,
- -901,
- -874,
- -847,
- -821,
- -794,
- -768,
- -741,
- -715,
- -688,
- -661,
- -635,
- -608,
- -582,
- -555,
- -529,
- -502,
- -475,
- -449,
- -422,
- -396,
- -369,
- -343,
- -316,
- -289,
- -263,
- -236,
- -210,
- -183,
- -157,
- -130,
- -103,
- -77,
- -50,
- -24,
- 3,
- 30,
- 56,
- 83,
- 109,
- 136,
- 162,
- 189,
- 216,
- 242,
- 269,
- 295,
- 322,
- 348,
- 375,
- 402,
- 428,
- 455,
- 481,
- 508,
- 534,
- 561,
- 588,
- 614,
- 641,
- 667,
- 694,
- 720,
- 747,
- 774,
- 800,
- 827,
- 853,
- 880,
- 907,
- 933,
- 960,
- 986,
- 1013,
- 1039,
- 1066,
- };
-
- private static readonly short[] s_CachedPowersDecimalExponent = new short[]
- {
- CachedPowersMinDecimalExponent,
- -340,
- -332,
- -324,
- -316,
- -308,
- -300,
- -292,
- -284,
- -276,
- -268,
- -260,
- -252,
- -244,
- -236,
- -228,
- -220,
- -212,
- -204,
- -196,
- -188,
- -180,
- -172,
- -164,
- -156,
- -148,
- -140,
- -132,
- -124,
- -116,
- -108,
- -100,
- -92,
- -84,
- -76,
- -68,
- -60,
- -52,
- -44,
- -36,
- -28,
- -20,
- -12,
- -4,
- 4,
- 12,
- 20,
- 28,
- 36,
- 44,
- 52,
- 60,
- 68,
- 76,
- 84,
- 92,
- 100,
- 108,
- 116,
- 124,
- 132,
- 140,
- 148,
- 156,
- 164,
- 172,
- 180,
- 188,
- 196,
- 204,
- 212,
- 220,
- 228,
- 236,
- 244,
- 252,
- 260,
- 268,
- 276,
- 284,
- 292,
- 300,
- 308,
- 316,
- 324,
- 332,
- CachedPowersPowerMaxDecimalExponent,
- };
-
- private static readonly ulong[] s_CachedPowersSignificand = new ulong[]
- {
- 0xFA8FD5A0081C0288,
- 0xBAAEE17FA23EBF76,
- 0x8B16FB203055AC76,
- 0xCF42894A5DCE35EA,
- 0x9A6BB0AA55653B2D,
- 0xE61ACF033D1A45DF,
- 0xAB70FE17C79AC6CA,
- 0xFF77B1FCBEBCDC4F,
- 0xBE5691EF416BD60C,
- 0x8DD01FAD907FFC3C,
- 0xD3515C2831559A83,
- 0x9D71AC8FADA6C9B5,
- 0xEA9C227723EE8BCB,
- 0xAECC49914078536D,
- 0x823C12795DB6CE57,
- 0xC21094364DFB5637,
- 0x9096EA6F3848984F,
- 0xD77485CB25823AC7,
- 0xA086CFCD97BF97F4,
- 0xEF340A98172AACE5,
- 0xB23867FB2A35B28E,
- 0x84C8D4DFD2C63F3B,
- 0xC5DD44271AD3CDBA,
- 0x936B9FCEBB25C996,
- 0xDBAC6C247D62A584,
- 0xA3AB66580D5FDAF6,
- 0xF3E2F893DEC3F126,
- 0xB5B5ADA8AAFF80B8,
- 0x87625F056C7C4A8B,
- 0xC9BCFF6034C13053,
- 0x964E858C91BA2655,
- 0xDFF9772470297EBD,
- 0xA6DFBD9FB8E5B88F,
- 0xF8A95FCF88747D94,
- 0xB94470938FA89BCF,
- 0x8A08F0F8BF0F156B,
- 0xCDB02555653131B6,
- 0x993FE2C6D07B7FAC,
- 0xE45C10C42A2B3B06,
- 0xAA242499697392D3,
- 0xFD87B5F28300CA0E,
- 0xBCE5086492111AEB,
- 0x8CBCCC096F5088CC,
- 0xD1B71758E219652C,
- 0x9C40000000000000,
- 0xE8D4A51000000000,
- 0xAD78EBC5AC620000,
- 0x813F3978F8940984,
- 0xC097CE7BC90715B3,
- 0x8F7E32CE7BEA5C70,
- 0xD5D238A4ABE98068,
- 0x9F4F2726179A2245,
- 0xED63A231D4C4FB27,
- 0xB0DE65388CC8ADA8,
- 0x83C7088E1AAB65DB,
- 0xC45D1DF942711D9A,
- 0x924D692CA61BE758,
- 0xDA01EE641A708DEA,
- 0xA26DA3999AEF774A,
- 0xF209787BB47D6B85,
- 0xB454E4A179DD1877,
- 0x865B86925B9BC5C2,
- 0xC83553C5C8965D3D,
- 0x952AB45CFA97A0B3,
- 0xDE469FBD99A05FE3,
- 0xA59BC234DB398C25,
- 0xF6C69A72A3989F5C,
- 0xB7DCBF5354E9BECE,
- 0x88FCF317F22241E2,
- 0xCC20CE9BD35C78A5,
- 0x98165AF37B2153DF,
- 0xE2A0B5DC971F303A,
- 0xA8D9D1535CE3B396,
- 0xFB9B7CD9A4A7443C,
- 0xBB764C4CA7A44410,
- 0x8BAB8EEFB6409C1A,
- 0xD01FEF10A657842C,
- 0x9B10A4E5E9913129,
- 0xE7109BFBA19C0C9D,
- 0xAC2820D9623BF429,
- 0x80444B5E7AA7CF85,
- 0xBF21E44003ACDD2D,
- 0x8E679C2F5E44FF8F,
- 0xD433179D9C8CB841,
- 0x9E19DB92B4E31BA9,
- 0xEB96BF6EBADF77D9,
- 0xAF87023B9BF0EE6B,
- };
-
- private static readonly uint[] s_SmallPowersOfTen = new uint[]
- {
- 1, // 10^0
- 10, // 10^1
- 100, // 10^2
- 1000, // 10^3
- 10000, // 10^4
- 100000, // 10^5
- 1000000, // 10^6
- 10000000, // 10^7
- 100000000, // 10^8
- 1000000000, // 10^9
- };
-
- public static bool TryRunDouble(double value, int requestedDigits, ref NumberBuffer number)
- {
- double v = double.IsNegative(value) ? -value : value;
-
- Debug.Assert(v > 0);
- Debug.Assert(double.IsFinite(v));
-
- int length;
- int decimalExponent;
- bool result;
-
- if (requestedDigits == -1)
- {
- DiyFp w = DiyFp.CreateAndGetBoundaries(v, out DiyFp boundaryMinus, out DiyFp boundaryPlus).Normalize();
- result = TryRunShortest(in boundaryMinus, in w, in boundaryPlus, number.Digits, out length, out decimalExponent);
- }
- else
- {
- DiyFp w = new DiyFp(v).Normalize();
- result = TryRunCounted(in w, requestedDigits, number.Digits, out length, out decimalExponent);
- }
-
- if (result)
- {
- Debug.Assert((requestedDigits == -1) || (length == requestedDigits));
-
- number.Scale = length + decimalExponent;
- number.Digits[length] = (byte)('\0');
- number.DigitsCount = length;
- }
-
- return result;
- }
-
- public static bool TryRunSingle(float value, int requestedDigits, ref NumberBuffer number)
- {
- float v = float.IsNegative(value) ? -value : value;
-
- Debug.Assert(v > 0);
- Debug.Assert(float.IsFinite(v));
-
- int length;
- int decimalExponent;
- bool result;
-
- if (requestedDigits == -1)
- {
- DiyFp w = DiyFp.CreateAndGetBoundaries(v, out DiyFp boundaryMinus, out DiyFp boundaryPlus).Normalize();
- result = TryRunShortest(in boundaryMinus, in w, in boundaryPlus, number.Digits, out length, out decimalExponent);
- }
- else
- {
- DiyFp w = new DiyFp(v).Normalize();
- result = TryRunCounted(in w, requestedDigits, number.Digits, out length, out decimalExponent);
- }
-
- if (result)
- {
- Debug.Assert((requestedDigits == -1) || (length == requestedDigits));
-
- number.Scale = length + decimalExponent;
- number.Digits[length] = (byte)('\0');
- number.DigitsCount = length;
- }
-
- return result;
- }
-
- // The counted version of Grisu3 only generates requestedDigits number of digits.
- // This version does not generate the shortest representation, and with enough requested digits 0.1 will at some point print as 0.9999999...
- // Grisu3 is too imprecise for real halfway cases (1.5 will not work) and therefore the rounding strategy for halfway cases is irrelevant.
- private static bool TryRunCounted(in DiyFp w, int requestedDigits, Span<byte> buffer, out int length, out int decimalExponent)
- {
- Debug.Assert(requestedDigits > 0);
-
- int tenMkMinimalBinaryExponent = MinimalTargetExponent - (w.e + DiyFp.SignificandSize);
- int tenMkMaximalBinaryExponent = MaximalTargetExponent - (w.e + DiyFp.SignificandSize);
-
- DiyFp tenMk = GetCachedPowerForBinaryExponentRange(tenMkMinimalBinaryExponent, tenMkMaximalBinaryExponent, out int mk);
-
- Debug.Assert(MinimalTargetExponent <= (w.e + tenMk.e + DiyFp.SignificandSize));
- Debug.Assert(MaximalTargetExponent >= (w.e + tenMk.e + DiyFp.SignificandSize));
-
- // Note that tenMk is only an approximation of 10^-k.
- // A DiyFp only contains a 64-bit significand and tenMk is thus only precise up to 64-bits.
-
- // The DiyFp.Multiply procedure rounds its result and tenMk is approximated too.
- // The variable scaledW (as well as scaledBoundaryMinus/Plus) are now off by a small amount.
- //
- // In fact, scaledW - (w * 10^k) < 1ulp (unit in last place) of scaledW.
- // In other words, let f = scaledW.f and e = scaledW.e, then:
- // (f - 1) * 2^e < (w * 10^k) < (f + 1) * 2^e
-
- DiyFp scaledW = w.Multiply(in tenMk);
-
- // We now have (double)(scaledW * 10^-mk).
- //
- // DigitGenCounted will generate the first requestedDigits of scaledW and return together with a kappa such that:
- // scaledW ~= buffer * 10^kappa.
- //
- // It will not always be exactly the same since DigitGenCounted only produces a limited number of digits.
-
- bool result = TryDigitGenCounted(in scaledW, requestedDigits, buffer, out length, out int kappa);
- decimalExponent = -mk + kappa;
- return result;
- }
-
- // Provides a decimal representation of v.
- // Returns true if it succeeds; otherwise, the result cannot be trusted.
- //
- // There will be length digits inside the buffer (not null-terminated).
- // If the function returns true then:
- // v == (double)(buffer * 10^decimalExponent)
- //
- // The digits in the buffer are the shortest represenation possible (no 0.09999999999999999 instead of 0.1).
- // The shorter representation will even be chosen if the longer one would be closer to v.
- //
- // The last digit will be closest to the actual v.
- // That is, even if several digits might correctly yield 'v' when read again, the closest will be computed.
- private static bool TryRunShortest(in DiyFp boundaryMinus, in DiyFp w, in DiyFp boundaryPlus, Span<byte> buffer, out int length, out int decimalExponent)
- {
- // boundaryMinus and boundaryPlus are the boundaries between v and its closest floating-point neighbors.
- // Any number strictly between boundaryMinus and boundaryPlus will round to v when converted to a double.
- // Grisu3 will never output representations that lie exactly on a boundary.
-
- Debug.Assert(boundaryPlus.e == w.e);
-
- int tenMkMinimalBinaryExponent = MinimalTargetExponent - (w.e + DiyFp.SignificandSize);
- int tenMkMaximalBinaryExponent = MaximalTargetExponent - (w.e + DiyFp.SignificandSize);
-
- DiyFp tenMk = GetCachedPowerForBinaryExponentRange(tenMkMinimalBinaryExponent, tenMkMaximalBinaryExponent, out int mk);
-
- Debug.Assert(MinimalTargetExponent <= (w.e + tenMk.e + DiyFp.SignificandSize));
- Debug.Assert(MaximalTargetExponent >= (w.e + tenMk.e + DiyFp.SignificandSize));
-
- // Note that tenMk is only an approximation of 10^-k.
- // A DiyFp only contains a 64-bit significan and tenMk is thus only precise up to 64-bits.
-
- // The DiyFp.Multiply procedure rounds its result and tenMk is approximated too.
- // The variable scaledW (as well as scaledBoundaryMinus/Plus) are now off by a small amount.
- //
- // In fact, scaledW - (w * 10^k) < 1ulp (unit in last place) of scaledW.
- // In other words, let f = scaledW.f and e = scaledW.e, then:
- // (f - 1) * 2^e < (w * 10^k) < (f + 1) * 2^e
-
- DiyFp scaledW = w.Multiply(in tenMk);
- Debug.Assert(scaledW.e == (boundaryPlus.e + tenMk.e + DiyFp.SignificandSize));
-
- // In theory, it would be possible to avoid some recomputations by computing the difference between w
- // and boundaryMinus/Plus (a power of 2) and to compute scaledBoundaryMinus/Plus by subtracting/adding
- // from scaledW. However, the code becomes much less readable and the speed enhancements are not terrific.
-
- DiyFp scaledBoundaryMinus = boundaryMinus.Multiply(in tenMk);
- DiyFp scaledBoundaryPlus = boundaryPlus.Multiply(in tenMk);
-
- // DigitGen will generate the digits of scaledW. Therefore, we have:
- // v == (double)(scaledW * 10^-mk)
- //
- // Set decimalExponent == -mk and pass it to DigitGen and if scaledW is not an integer than it will be updated.
- // For instance, if scaledW == 1.23 then the buffer will be filled with "123" and the decimalExponent will be decreased by 2.
-
- bool result = TryDigitGenShortest(in scaledBoundaryMinus, in scaledW, in scaledBoundaryPlus, buffer, out length, out int kappa);
- decimalExponent = -mk + kappa;
- return result;
- }
-
- // Returns the biggest power of ten that is less than or equal to the given number.
- // We furthermore receive the maximum number of bits 'number' has.
- //
- // Returns power == 10^(exponent) such that
- // power <= number < power * 10
- // If numberBits == 0, then 0^(0-1) is returned.
- // The number of bits must be <= 32.
- //
- // Preconditions:
- // number < (1 << (numberBits + 1))
- private static uint BiggestPowerTen(uint number, int numberBits, out int exponentPlusOne)
- {
- // Inspired by the method for finding an integer log base 10 from here:
- // http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
-
- Debug.Assert(number < (1U << (numberBits + 1)));
-
- // 1233/4096 is approximately 1/log2(10)
- int exponentGuess = ((numberBits + 1) * 1233) >> 12;
- Debug.Assert((uint)(exponentGuess) < s_SmallPowersOfTen.Length);
-
- uint power = s_SmallPowersOfTen[exponentGuess];
-
- // We don't have any guarantees that 2^numberBits <= number
- if (number < power)
- {
- exponentGuess--;
- power = s_SmallPowersOfTen[exponentGuess];
- }
-
- exponentPlusOne = exponentGuess + 1;
- return power;
- }
-
- // Generates (at most) requestedDigits of input number w.
- //
- // w is a floating-point number (DiyFp), consisting of a significand and an exponent.
- // Its exponent is bounded by MinimalTargetExponent and MaximalTargetExponent, hence:
- // -60 <= w.e <= -32
- //
- // Returns false if it fails, in which case the generated digits in the buffer should not be used.
- //
- // Preconditions:
- // w is correct up to 1 ulp (unit in last place). That is, its error must be strictly less than a unit of its last digit.
- // MinimalTargetExponent <= w.e <= MaximalTargetExponent
- //
- // Postconditions:
- // Returns false if the procedure fails; otherwise:
- // * buffer is not null-terminated, but length contains the number of digits.
- // * The representation in buffer is the most precise representation of requestedDigits digits.
- // * buffer contains at most requestedDigits digits of w. If there are less than requestedDigits digits then some trailing '0's have been removed.
- // * kappa is such that w = buffer * 10^kappa + eps with |eps| < 10^kappa / 2.
- //
- // This procedure takes into account the imprecision of its input numbers.
- // If the precision is not enough to guarantee all the postconditions, then false is returned.
- // This usually happens rarely, but the failure-rate increases with higher requestedDigits
- private static bool TryDigitGenCounted(in DiyFp w, int requestedDigits, Span<byte> buffer, out int length, out int kappa)
- {
- Debug.Assert(MinimalTargetExponent <= w.e);
- Debug.Assert(w.e <= MaximalTargetExponent);
- Debug.Assert(MinimalTargetExponent >= -60);
- Debug.Assert(MaximalTargetExponent <= -32);
-
- // w is assumed to have an error less than 1 unit.
- // Whenever w is scaled we also scale its error.
- ulong wError = 1;
-
- // We cut the input number into two parts: the integral digits and the fractional digits.
- // We don't emit any decimal separator, but adapt kapp instead.
- // For example: instead of writing "1.2", we put "12" into the buffer and increase kappa by 1.
- var one = new DiyFp(1UL << -w.e, w.e);
-
- // Division by one is a shift.
- uint integrals = (uint)(w.f >> -one.e);
-
- // Modulo by one is an and.
- ulong fractionals = w.f & (one.f - 1);
-
- // We deviate from the original algorithm here and do some early checks to determine if we can satisfy requestedDigits.
- // If we determine that we can't, we exit early and avoid most of the heavy lifting that the algorithm otherwise does.
- //
- // When fractionals is zero, we can easily determine if integrals can satisfy requested digits:
- // If requestedDigits >= 11, integrals is not able to exhaust the count by itself since 10^(11 -1) > uint.MaxValue >= integrals.
- // If integrals < 10^(requestedDigits - 1), integrals cannot exhaust the count.
- // Otherwise, integrals might be able to exhaust the count and we need to execute the rest of the code.
- if ((fractionals == 0) && ((requestedDigits >= 11) || (integrals < s_SmallPowersOfTen[requestedDigits - 1])))
- {
- Debug.Assert(buffer[0] == '\0');
- length = 0;
- kappa = 0;
- return false;
- }
-
- uint divisor = BiggestPowerTen(integrals, DiyFp.SignificandSize - (-one.e), out kappa);
- length = 0;
-
- // Loop invariant:
- // buffer = w / 10^kappa (integer division)
- // These invariants hold for the first iteration:
- // kappa has been initialized with the divisor exponent + 1
- // The divisor is the biggest power of ten that is smaller than integrals
- while (kappa > 0)
- {
- uint digit = Math.DivRem(integrals, divisor, out integrals);
- Debug.Assert(digit <= 9);
- buffer[length] = (byte)('0' + digit);
-
- length++;
- requestedDigits--;
- kappa--;
-
- // Note that kappa now equals the exponent of the
- // divisor and that the invariant thus holds again.
- if (requestedDigits == 0)
- {
- break;
- }
-
- divisor /= 10;
- }
-
- if (requestedDigits == 0)
- {
- ulong rest = ((ulong)(integrals) << -one.e) + fractionals;
- return TryRoundWeedCounted(
- buffer,
- length,
- rest,
- tenKappa: ((ulong)(divisor)) << -one.e,
- unit: wError,
- ref kappa
- );
- }
-
- // The integrals have been generated and we are at the point of the decimal separator.
- // In the following loop, we simply multiply the remaining digits by 10 and divide by one.
- // We just need to pay attention to multiply associated data (the unit), too.
- // Note that the multiplication by 10 does not overflow because:
- // w.e >= -60 and thus one.e >= -60
-
- Debug.Assert(one.e >= MinimalTargetExponent);
- Debug.Assert(fractionals < one.f);
- Debug.Assert((ulong.MaxValue / 10) >= one.f);
-
- while ((requestedDigits > 0) && (fractionals > wError))
- {
- fractionals *= 10;
- wError *= 10;
-
- // Integer division by one.
- uint digit = (uint)(fractionals >> -one.e);
- Debug.Assert(digit <= 9);
- buffer[length] = (byte)('0' + digit);
-
- length++;
- requestedDigits--;
- kappa--;
-
- // Modulo by one.
- fractionals &= (one.f - 1);
- }
-
- if (requestedDigits != 0)
- {
- buffer[0] = (byte)('\0');
- length = 0;
- kappa = 0;
- return false;
- }
-
- return TryRoundWeedCounted(
- buffer,
- length,
- rest: fractionals,
- tenKappa: one.f,
- unit: wError,
- ref kappa
- );
- }
-
- // Generates the digits of input number w.
- //
- // w is a floating-point number (DiyFp), consisting of a significand and an exponent.
- // Its exponent is bounded by kMinimalTargetExponent and kMaximalTargetExponent, hence:
- // -60 <= w.e() <= -32.
- //
- // Returns false if it fails, in which case the generated digits in the buffer should not be used.
- //
- // Preconditions:
- // low, w and high are correct up to 1 ulp (unit in the last place). That is, their error must be less than a unit of their last digits.
- // low.e() == w.e() == high.e()
- // low < w < high, and taking into account their error: low~ <= high~
- // kMinimalTargetExponent <= w.e() <= kMaximalTargetExponent
- //
- // Postconditions:
- // Returns false if procedure fails; otherwise:
- // * buffer is not null-terminated, but len contains the number of digits.
- // * buffer contains the shortest possible decimal digit-sequence such that LOW < buffer * 10^kappa < HIGH, where LOW and HIGH are the correct values of low and high (without their error).
- // * If more than one decimal representation gives the minimal number of decimal digits then the one closest to W (where W is the correct value of w) is chosen.
- //
- // This procedure takes into account the imprecision of its input numbers.
- // If the precision is not enough to guarantee all the postconditions then false is returned.
- // This usually happens rarely (~0.5%).
- //
- // Say, for the sake of example, that:
- // w.e() == -48, and w.f() == 0x1234567890abcdef
- //
- // w's value can be computed by w.f() * 2^w.e()
- //
- // We can obtain w's integral digits by simply shifting w.f() by -w.e().
- // -> w's integral part is 0x1234
- // w's fractional part is therefore 0x567890abcdef.
- //
- // Printing w's integral part is easy (simply print 0x1234 in decimal).
- //
- // In order to print its fraction we repeatedly multiply the fraction by 10 and get each digit.
- // For example, the first digit after the point would be computed by
- // (0x567890abcdef * 10) >> 48. -> 3
- //
- // The whole thing becomes slightly more complicated because we want to stop once we have enough digits.
- // That is, once the digits inside the buffer represent 'w' we can stop.
- //
- // Everything inside the interval low - high represents w.
- // However we have to pay attention to low, high and w's imprecision.
- private static bool TryDigitGenShortest(in DiyFp low, in DiyFp w, in DiyFp high, Span<byte> buffer, out int length, out int kappa)
- {
- Debug.Assert(low.e == w.e);
- Debug.Assert(w.e == high.e);
-
- Debug.Assert((low.f + 1) <= (high.f - 1));
-
- Debug.Assert(MinimalTargetExponent <= w.e);
- Debug.Assert(w.e <= MaximalTargetExponent);
-
- // low, w, and high are imprecise, but by less than one ulp (unit in the last place).
- //
- // If we remove (resp. add) 1 ulp from low (resp. high) we are certain that the new numbers
- // are outside of the interval we want the final representation to lie in.
- //
- // Inversely adding (resp. removing) 1 ulp from low (resp. high) would yield numbers that
- // are certain to lie in the interval. We will use this fact later on.
- //
- // We will now start by generating the digits within the uncertain interval.
- // Later, we will weed out representations that lie outside the safe interval and thus might lie outside the correct interval.
-
- ulong unit = 1;
-
- var tooLow = new DiyFp(low.f - unit, low.e);
- var tooHigh = new DiyFp(high.f + unit, high.e);
-
- // tooLow and tooHigh are guaranteed to lie outside the interval we want the generated number in.
-
- DiyFp unsafeInterval = tooHigh.Subtract(in tooLow);
-
- // We now cut the input number into two parts: the integral digits and the fractional digits.
- // We will not write any decimal separator, but adapt kappa instead.
- //
- // Reminder: we are currently computing the digits (Stored inside the buffer) such that:
- // tooLow < buffer * 10^kappa < tooHigh
- //
- // We use tooHigh for the digitGeneration and stop as soon as possible.
- // If we stop early, we effectively round down.
-
- var one = new DiyFp(1UL << -w.e, w.e);
-
- // Division by one is a shift.
- uint integrals = (uint)(tooHigh.f >> -one.e);
-
- // Modulo by one is an and.
- ulong fractionals = tooHigh.f & (one.f - 1);
-
- uint divisor = BiggestPowerTen(integrals, DiyFp.SignificandSize - (-one.e), out kappa);
- length = 0;
-
- // Loop invariant:
- // buffer = tooHigh / 10^kappa (integer division)
- // These invariants hold for the first iteration:
- // kappa has been initialized with the divisor exponent + 1
- // The divisor is the biggest power of ten that is smaller than integrals
- while (kappa > 0)
- {
- uint digit = Math.DivRem(integrals, divisor, out integrals);
- Debug.Assert(digit <= 9);
- buffer[length] = (byte)('0' + digit);
-
- length++;
- kappa--;
-
- // Note that kappa now equals the exponent of the
- // divisor and that the invariant thus holds again.
-
- ulong rest = ((ulong)(integrals) << -one.e) + fractionals;
-
- // Invariant: tooHigh = buffer * 10^kappa + DiyFp(rest, one.e)
- // Reminder: unsafeInterval.e == one.e
-
- if (rest < unsafeInterval.f)
- {
- // Rounding down (by not emitting the remaining digits)
- // yields a number that lies within the unsafe interval
-
- return TryRoundWeedShortest(
- buffer,
- length,
- tooHigh.Subtract(w).f,
- unsafeInterval.f,
- rest,
- tenKappa: ((ulong)(divisor)) << -one.e,
- unit
- );
- }
-
- divisor /= 10;
- }
-
- // The integrals have been generated and we are at the point of the decimal separator.
- // In the following loop, we simply multiply the remaining digits by 10 and divide by one.
- // We just need to pay attention to multiply associated data (the unit), too.
- // Note that the multiplication by 10 does not overflow because:
- // w.e >= -60 and thus one.e >= -60
-
- Debug.Assert(one.e >= MinimalTargetExponent);
- Debug.Assert(fractionals < one.f);
- Debug.Assert((ulong.MaxValue / 10) >= one.f);
-
- while (true)
- {
- fractionals *= 10;
- unit *= 10;
-
- unsafeInterval = new DiyFp(unsafeInterval.f * 10, unsafeInterval.e);
-
- // Integer division by one.
- uint digit = (uint)(fractionals >> -one.e);
- Debug.Assert(digit <= 9);
- buffer[length] = (byte)('0' + digit);
-
- length++;
- kappa--;
-
- // Modulo by one.
- fractionals &= (one.f - 1);
-
- if (fractionals < unsafeInterval.f)
- {
- return TryRoundWeedShortest(
- buffer,
- length,
- tooHigh.Subtract(w).f * unit,
- unsafeInterval.f,
- rest: fractionals,
- tenKappa: one.f,
- unit
- );
- }
- }
- }
-
- // Returns a cached power-of-ten with a binary exponent in the range [minExponent; maxExponent] (boundaries included).
- private static DiyFp GetCachedPowerForBinaryExponentRange(int minExponent, int maxExponent, out int decimalExponent)
- {
- Debug.Assert(s_CachedPowersSignificand.Length == s_CachedPowersBinaryExponent.Length);
- Debug.Assert(s_CachedPowersSignificand.Length == s_CachedPowersDecimalExponent.Length);
-
- double k = Math.Ceiling((minExponent + DiyFp.SignificandSize - 1) * D1Log210);
- int index = ((CachedPowersOffset + (int)(k) - 1) / CachedPowersDecimalExponentDistance) + 1;
-
- Debug.Assert((uint)(index) < s_CachedPowersSignificand.Length);
-
- Debug.Assert(minExponent <= s_CachedPowersBinaryExponent[index]);
- Debug.Assert(s_CachedPowersBinaryExponent[index] <= maxExponent);
-
- decimalExponent = s_CachedPowersDecimalExponent[index];
- return new DiyFp(s_CachedPowersSignificand[index], s_CachedPowersBinaryExponent[index]);
- }
-
- // Rounds the buffer upwards if the result is closer to v by possibly adding 1 to the buffer.
- // If the precision of the calculation is not sufficient to round correctly, return false.
- //
- // The rounding might shift the whole buffer, in which case, the kappy is adjusted.
- // For example "99", kappa = 3 might become "10", kappa = 4.
- //
- // If (2 * rest) > tenKappa then the buffer needs to be round up.
- // rest can have an error of +/- 1 unit.
- // This function accounts for the imprecision and returns false if the rounding direction cannot be unambiguously determined.
- //
- // Preconditions:
- // rest < tenKappa
- private static bool TryRoundWeedCounted(Span<byte> buffer, int length, ulong rest, ulong tenKappa, ulong unit, ref int kappa)
- {
- Debug.Assert(rest < tenKappa);
-
- // The following tests are done in a specific order to avoid overflows.
- // They will work correctly with any ulong values of rest < tenKappa and unit.
- //
- // If the unit is too big, then we don't know which way to round.
- // For example, a unit of 50 means that the real number lies within rest +/- 50.
- // If 10^kappa == 40, then there is no way to tell which way to round.
- //
- // Even if unit is just half the size of 10^kappa we are already completely lost.
- // And after the previous test, we know that the expression will not over/underflow.
- if ((unit >= tenKappa) || ((tenKappa - unit) <= unit))
- {
- return false;
- }
-
- // If 2 * (rest + unit) <= 10^kappa, we can safely round down.
- if (((tenKappa - rest) > rest) && ((tenKappa - (2 * rest)) >= (2 * unit)))
- {
- return true;
- }
-
- // If 2 * (rest - unit) >= 10^kappa, we can safely round up.
- if ((rest > unit) && (tenKappa <= (rest - unit) || ((tenKappa - (rest - unit)) <= (rest - unit))))
- {
- // Increment the last digit recursively until we find a non '9' digit.
- buffer[length - 1]++;
-
- for (int i = (length - 1); i > 0; i--)
- {
- if (buffer[i] != ('0' + 10))
- {
- break;
- }
-
- buffer[i] = (byte)('0');
- buffer[i - 1]++;
- }
-
- // If the first digit is now '0'+10, we had a buffer with all '9's.
- // With the exception of the first digit, all digits are now '0'.
- // Simply switch the first digit to '1' and adjust the kappa.
- // For example, "99" becomes "10" and the power (the kappa) is increased.
- if (buffer[0] == ('0' + 10))
- {
- buffer[0] = (byte)('1');
- kappa++;
- }
-
- return true;
- }
-
- return false;
- }
-
- // Adjusts the last digit of the generated number and screens out generated solutions that may be inaccurate.
- // A solution may be inaccurate if it is outside the safe interval or if we cannot provide that it is closer to the input than a neighboring representation of the same length.
- //
- // Input:
- // buffer containing the digits of tooHigh / 10^kappa
- // the buffer's length
- // distanceTooHighW == (tooHigh - w).f * unit
- // unsafeInterval == (tooHigh - tooLow).f * unit
- // rest = (tooHigh - buffer * 10^kapp).f * unit
- // tenKappa = 10^kappa * unit
- // unit = the common multiplier
- //
- // Output:
- // Returns true if the buffer is guaranteed to contain the closest representable number to the input.
- //
- // Modifies the generated digits in the buffer to approach (round towards) w.
- private static bool TryRoundWeedShortest(Span<byte> buffer, int length, ulong distanceTooHighW, ulong unsafeInterval, ulong rest, ulong tenKappa, ulong unit)
- {
- ulong smallDistance = distanceTooHighW - unit;
- ulong bigDistance = distanceTooHighW + unit;
-
- // Let wLow = tooHigh - bigDistance, and wHigh = tooHigh - smallDistance.
- //
- // Note: wLow < w < wHigh
- //
- // The real w * unit must lie somewhere inside the interval
- // ]w_low; w_high[ (often written as "(w_low; w_high)")
-
- // Basically the buffer currently contains a number in the unsafe interval
- // ]too_low; too_high[ with too_low < w < too_high
- //
- // tooHigh - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // ^v 1 unit ^ ^ ^ ^
- // boundaryHigh --------------------- . . . .
- // ^v 1 unit . . . .
- // - - - - - - - - - - - - - - - - - - - + - - + - - - - - - . .
- // . . ^ . .
- // . bigDistance . . .
- // . . . . rest
- // smallDistance . . . .
- // v . . . .
- // wHigh - - - - - - - - - - - - - - - - - - . . . .
- // ^v 1 unit . . . .
- // w --------------------------------------- . . . .
- // ^v 1 unit v . . .
- // wLow - - - - - - - - - - - - - - - - - - - - - . . .
- // . . v
- // buffer -------------------------------------------------+-------+--------
- // . .
- // safeInterval .
- // v .
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - .
- // ^v 1 unit .
- // boundaryLow ------------------------- unsafeInterval
- // ^v 1 unit v
- // tooLow - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- //
- //
- // Note that the value of buffer could lie anywhere inside the range tooLow to tooHigh.
- //
- // boundaryLow, boundaryHigh and w are approximations of the real boundaries and v (the input number).
- // They are guaranteed to be precise up to one unit.
- // In fact the error is guaranteed to be strictly less than one unit.
- //
- // Anything that lies outside the unsafe interval is guaranteed not to round to v when read again.
- // Anything that lies inside the safe interval is guaranteed to round to v when read again.
- //
- // If the number inside the buffer lies inside the unsafe interval but not inside the safe interval
- // then we simply do not know and bail out (returning false).
- //
- // Similarly we have to take into account the imprecision of 'w' when finding the closest representation of 'w'.
- // If we have two potential representations, and one is closer to both wLow and wHigh, then we know it is closer to the actual value v.
- //
- // By generating the digits of tooHigh we got the largest (closest to tooHigh) buffer that is still in the unsafe interval.
- // In the case where wHigh < buffer < tooHigh we try to decrement the buffer.
- // This way the buffer approaches (rounds towards) w.
- //
- // There are 3 conditions that stop the decrementation process:
- // 1) the buffer is already below wHigh
- // 2) decrementing the buffer would make it leave the unsafe interval
- // 3) decrementing the buffer would yield a number below wHigh and farther away than the current number.
- //
- // In other words:
- // (buffer{-1} < wHigh) && wHigh - buffer{-1} > buffer - wHigh
- //
- // Instead of using the buffer directly we use its distance to tooHigh.
- //
- // Conceptually rest ~= tooHigh - buffer
- //
- // We need to do the following tests in this order to avoid over- and underflows.
-
- Debug.Assert(rest <= unsafeInterval);
-
- while ((rest < smallDistance) && ((unsafeInterval - rest) >= tenKappa) && (((rest + tenKappa) < smallDistance) || ((smallDistance - rest) >= (rest + tenKappa - smallDistance))))
- {
- buffer[length - 1]--;
- rest += tenKappa;
- }
-
- // We have approached w+ as much as possible.
- // We now test if approaching w- would require changing the buffer.
- // If yes, then we have two possible representations close to w, but we cannot decide which one is closer.
- if ((rest < bigDistance) && ((unsafeInterval - rest) >= tenKappa) && (((rest + tenKappa) < bigDistance) || ((bigDistance - rest) > (rest + tenKappa - bigDistance))))
- {
- return false;
- }
-
- // Weeding test.
- //
- // The safe interval is [tooLow + 2 ulp; tooHigh - 2 ulp]
- // Since tooLow = tooHigh - unsafeInterval this is equivalent to
- // [tooHigh - unsafeInterval + 4 ulp; tooHigh - 2 ulp]
- //
- // Conceptually we have: rest ~= tooHigh - buffer
- return ((2 * unit) <= rest) && (rest <= (unsafeInterval - 4 * unit));
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Number.NumberBuffer.cs b/netcore/System.Private.CoreLib/shared/System/Number.NumberBuffer.cs
deleted file mode 100644
index 7218af24076..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Number.NumberBuffer.cs
+++ /dev/null
@@ -1,124 +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 System.Diagnostics;
-using System.Text;
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- internal static partial class Number
- {
- // We need 1 additional byte, per length, for the terminating null
- internal const int DecimalNumberBufferLength = 29 + 1 + 1; // 29 for the longest input + 1 for rounding
- internal const int DoubleNumberBufferLength = 767 + 1 + 1; // 767 for the longest input + 1 for rounding: 4.9406564584124654E-324
- internal const int Int32NumberBufferLength = 10 + 1; // 10 for the longest input: 2,147,483,647
- internal const int Int64NumberBufferLength = 19 + 1; // 19 for the longest input: 9,223,372,036,854,775,807
- internal const int SingleNumberBufferLength = 112 + 1 + 1; // 112 for the longest input + 1 for rounding: 1.40129846E-45
- internal const int UInt32NumberBufferLength = 10 + 1; // 10 for the longest input: 4,294,967,295
- internal const int UInt64NumberBufferLength = 20 + 1; // 20 for the longest input: 18,446,744,073,709,551,615
-
- internal unsafe ref struct NumberBuffer
- {
- public int DigitsCount;
- public int Scale;
- public bool IsNegative;
- public bool HasNonZeroTail;
- public NumberBufferKind Kind;
- public Span<byte> Digits;
-
- public NumberBuffer(NumberBufferKind kind, byte* digits, int digitsLength)
- {
- Debug.Assert(digits != null);
- Debug.Assert(digitsLength > 0);
-
- DigitsCount = 0;
- Scale = 0;
- IsNegative = false;
- HasNonZeroTail = false;
- Kind = kind;
- Digits = new Span<byte>(digits, digitsLength);
-
-#if DEBUG
- Digits.Fill(0xCC);
-#endif
-
- Digits[0] = (byte)('\0');
- CheckConsistency();
- }
-
- [Conditional("DEBUG")]
- public void CheckConsistency()
- {
-#if DEBUG
- Debug.Assert((Kind == NumberBufferKind.Integer) || (Kind == NumberBufferKind.Decimal) || (Kind == NumberBufferKind.FloatingPoint));
- Debug.Assert(Digits[0] != '0', "Leading zeros should never be stored in a Number");
-
- int numDigits;
- for (numDigits = 0; numDigits < Digits.Length; numDigits++)
- {
- byte digit = Digits[numDigits];
-
- if (digit == 0)
- {
- break;
- }
-
- Debug.Assert((digit >= '0') && (digit <= '9'), "Unexpected character found in Number");
- }
-
- Debug.Assert(numDigits == DigitsCount, "Null terminator found in unexpected location in Number");
- Debug.Assert(numDigits < Digits.Length, "Null terminator not found in Number");
-#endif // DEBUG
- }
-
- public byte* GetDigitsPointer()
- {
- // This is safe to do since we are a ref struct
- return (byte*)(Unsafe.AsPointer(ref Digits[0]));
- }
-
- //
- // Code coverage note: This only exists so that Number displays nicely in the VS watch window. So yes, I know it works.
- //
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
-
- sb.Append('[');
- sb.Append('"');
-
- for (int i = 0; i < Digits.Length; i++)
- {
- byte digit = Digits[i];
-
- if (digit == 0)
- {
- break;
- }
-
- sb.Append((char)(digit));
- }
-
- sb.Append('"');
- sb.Append(", Length = ").Append(DigitsCount);
- sb.Append(", Scale = ").Append(Scale);
- sb.Append(", IsNegative = ").Append(IsNegative);
- sb.Append(", HasNonZeroTail = ").Append(HasNonZeroTail);
- sb.Append(", Kind = ").Append(Kind);
- sb.Append(']');
-
- return sb.ToString();
- }
- }
-
- internal enum NumberBufferKind : byte
- {
- Unknown = 0,
- Integer = 1,
- Decimal = 2,
- FloatingPoint = 3,
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Number.NumberToFloatingPointBits.cs b/netcore/System.Private.CoreLib/shared/System/Number.NumberToFloatingPointBits.cs
deleted file mode 100644
index 98ad9f25fcd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Number.NumberToFloatingPointBits.cs
+++ /dev/null
@@ -1,630 +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 System.Diagnostics;
-
-namespace System
-{
- internal unsafe partial class Number
- {
- public readonly struct FloatingPointInfo
- {
- public static readonly FloatingPointInfo Double = new FloatingPointInfo(
- denormalMantissaBits: 52,
- exponentBits: 11,
- maxBinaryExponent: 1023,
- exponentBias: 1023,
- infinityBits: 0x7FF00000_00000000
- );
-
- public static readonly FloatingPointInfo Single = new FloatingPointInfo(
- denormalMantissaBits: 23,
- exponentBits: 8,
- maxBinaryExponent: 127,
- exponentBias: 127,
- infinityBits: 0x7F800000
- );
-
- public ulong ZeroBits { get; }
- public ulong InfinityBits { get; }
-
- public ulong NormalMantissaMask { get; }
- public ulong DenormalMantissaMask { get; }
-
- public int MinBinaryExponent { get; }
- public int MaxBinaryExponent { get; }
-
- public int ExponentBias { get; }
- public int OverflowDecimalExponent { get; }
-
- public ushort NormalMantissaBits { get; }
- public ushort DenormalMantissaBits { get; }
-
- public ushort ExponentBits { get; }
-
- public FloatingPointInfo(ushort denormalMantissaBits, ushort exponentBits, int maxBinaryExponent, int exponentBias, ulong infinityBits)
- {
- ExponentBits = exponentBits;
-
- DenormalMantissaBits = denormalMantissaBits;
- NormalMantissaBits = (ushort)(denormalMantissaBits + 1); // we get an extra (hidden) bit for normal mantissas
-
- OverflowDecimalExponent = (maxBinaryExponent + 2 * NormalMantissaBits) / 3;
- ExponentBias = exponentBias;
-
- MaxBinaryExponent = maxBinaryExponent;
- MinBinaryExponent = 1 - maxBinaryExponent;
-
- DenormalMantissaMask = (1UL << denormalMantissaBits) - 1;
- NormalMantissaMask = (1UL << NormalMantissaBits) - 1;
-
- InfinityBits = infinityBits;
- ZeroBits = 0;
- }
- }
-
- private static readonly float[] s_Pow10SingleTable = new float[]
- {
- 1e0f, // 10^0
- 1e1f, // 10^1
- 1e2f, // 10^2
- 1e3f, // 10^3
- 1e4f, // 10^4
- 1e5f, // 10^5
- 1e6f, // 10^6
- 1e7f, // 10^7
- 1e8f, // 10^8
- 1e9f, // 10^9
- 1e10f, // 10^10
- };
-
- private static readonly double[] s_Pow10DoubleTable = new double[]
- {
- 1e0, // 10^0
- 1e1, // 10^1
- 1e2, // 10^2
- 1e3, // 10^3
- 1e4, // 10^4
- 1e5, // 10^5
- 1e6, // 10^6
- 1e7, // 10^7
- 1e8, // 10^8
- 1e9, // 10^9
- 1e10, // 10^10
- 1e11, // 10^11
- 1e12, // 10^12
- 1e13, // 10^13
- 1e14, // 10^14
- 1e15, // 10^15
- 1e16, // 10^16
- 1e17, // 10^17
- 1e18, // 10^18
- 1e19, // 10^19
- 1e20, // 10^20
- 1e21, // 10^21
- 1e22, // 10^22
- };
-
- private static void AccumulateDecimalDigitsIntoBigInteger(ref NumberBuffer number, uint firstIndex, uint lastIndex, out BigInteger result)
- {
- result = new BigInteger(0);
-
- byte* src = number.GetDigitsPointer() + firstIndex;
- uint remaining = lastIndex - firstIndex;
-
- while (remaining != 0)
- {
- uint count = Math.Min(remaining, 9);
- uint value = DigitsToUInt32(src, (int)(count));
-
- result.MultiplyPow10(count);
- result.Add(value);
-
- src += count;
- remaining -= count;
- }
- }
-
- private static ulong AssembleFloatingPointBits(in FloatingPointInfo info, ulong initialMantissa, int initialExponent, bool hasZeroTail)
- {
- // number of bits by which we must adjust the mantissa to shift it into the
- // correct position, and compute the resulting base two exponent for the
- // normalized mantissa:
- uint initialMantissaBits = BigInteger.CountSignificantBits(initialMantissa);
- int normalMantissaShift = info.NormalMantissaBits - (int)(initialMantissaBits);
- int normalExponent = initialExponent - normalMantissaShift;
-
- ulong mantissa = initialMantissa;
- int exponent = normalExponent;
-
- if (normalExponent > info.MaxBinaryExponent)
- {
- // The exponent is too large to be represented by the floating point
- // type; report the overflow condition:
- return info.InfinityBits;
- }
- else if (normalExponent < info.MinBinaryExponent)
- {
- // The exponent is too small to be represented by the floating point
- // type as a normal value, but it may be representable as a denormal
- // value. Compute the number of bits by which we need to shift the
- // mantissa in order to form a denormal number. (The subtraction of
- // an extra 1 is to account for the hidden bit of the mantissa that
- // is not available for use when representing a denormal.)
- int denormalMantissaShift = normalMantissaShift + normalExponent + info.ExponentBias - 1;
-
- // Denormal values have an exponent of zero, so the debiased exponent is
- // the negation of the exponent bias:
- exponent = -info.ExponentBias;
-
- if (denormalMantissaShift < 0)
- {
- // Use two steps for right shifts: for a shift of N bits, we first
- // shift by N-1 bits, then shift the last bit and use its value to
- // round the mantissa.
- mantissa = RightShiftWithRounding(mantissa, -denormalMantissaShift, hasZeroTail);
-
- // If the mantissa is now zero, we have underflowed:
- if (mantissa == 0)
- {
- return info.ZeroBits;
- }
-
- // When we round the mantissa, the result may be so large that the
- // number becomes a normal value. For example, consider the single
- // precision case where the mantissa is 0x01ffffff and a right shift
- // of 2 is required to shift the value into position. We perform the
- // shift in two steps: we shift by one bit, then we shift again and
- // round using the dropped bit. The initial shift yields 0x00ffffff.
- // The rounding shift then yields 0x007fffff and because the least
- // significant bit was 1, we add 1 to this number to round it. The
- // final result is 0x00800000.
- //
- // 0x00800000 is 24 bits, which is more than the 23 bits available
- // in the mantissa. Thus, we have rounded our denormal number into
- // a normal number.
- //
- // We detect this case here and re-adjust the mantissa and exponent
- // appropriately, to form a normal number:
- if (mantissa > info.DenormalMantissaMask)
- {
- // We add one to the denormal_mantissa_shift to account for the
- // hidden mantissa bit (we subtracted one to account for this bit
- // when we computed the denormal_mantissa_shift above).
- exponent = initialExponent - (denormalMantissaShift + 1) - normalMantissaShift;
- }
- }
- else
- {
- mantissa <<= denormalMantissaShift;
- }
- }
- else
- {
- if (normalMantissaShift < 0)
- {
- // Use two steps for right shifts: for a shift of N bits, we first
- // shift by N-1 bits, then shift the last bit and use its value to
- // round the mantissa.
- mantissa = RightShiftWithRounding(mantissa, -normalMantissaShift, hasZeroTail);
-
- // When we round the mantissa, it may produce a result that is too
- // large. In this case, we divide the mantissa by two and increment
- // the exponent (this does not change the value).
- if (mantissa > info.NormalMantissaMask)
- {
- mantissa >>= 1;
- exponent++;
-
- // The increment of the exponent may have generated a value too
- // large to be represented. In this case, report the overflow:
- if (exponent > info.MaxBinaryExponent)
- {
- return info.InfinityBits;
- }
- }
- }
- else if (normalMantissaShift > 0)
- {
- mantissa <<= normalMantissaShift;
- }
- }
-
- // Unset the hidden bit in the mantissa and assemble the floating point value
- // from the computed components:
- mantissa &= info.DenormalMantissaMask;
-
- Debug.Assert((info.DenormalMantissaMask & (1UL << info.DenormalMantissaBits)) == 0);
- ulong shiftedExponent = ((ulong)(exponent + info.ExponentBias)) << info.DenormalMantissaBits;
- Debug.Assert((shiftedExponent & info.DenormalMantissaMask) == 0);
- Debug.Assert((mantissa & ~info.DenormalMantissaMask) == 0);
- Debug.Assert((shiftedExponent & ~(((1UL << info.ExponentBits) - 1) << info.DenormalMantissaBits)) == 0); // exponent fits in its place
-
- return shiftedExponent | mantissa;
- }
-
- private static ulong ConvertBigIntegerToFloatingPointBits(ref BigInteger value, in FloatingPointInfo info, uint integerBitsOfPrecision, bool hasNonZeroFractionalPart)
- {
- int baseExponent = info.DenormalMantissaBits;
-
- // When we have 64-bits or less of precision, we can just get the mantissa directly
- if (integerBitsOfPrecision <= 64)
- {
- return AssembleFloatingPointBits(in info, value.ToUInt64(), baseExponent, !hasNonZeroFractionalPart);
- }
-
- uint topBlockIndex = Math.DivRem(integerBitsOfPrecision, 32, out uint topBlockBits);
- uint middleBlockIndex = topBlockIndex - 1;
- uint bottomBlockIndex = middleBlockIndex - 1;
-
- ulong mantissa;
- int exponent = baseExponent + ((int)(bottomBlockIndex) * 32);
- bool hasZeroTail = !hasNonZeroFractionalPart;
-
- // When the top 64-bits perfectly span two blocks, we can get those blocks directly
- if (topBlockBits == 0)
- {
- mantissa = ((ulong)(value.GetBlock(middleBlockIndex)) << 32) + value.GetBlock(bottomBlockIndex);
- }
- else
- {
- // Otherwise, we need to read three blocks and combine them into a 64-bit mantissa
-
- int bottomBlockShift = (int)(topBlockBits);
- int topBlockShift = 64 - bottomBlockShift;
- int middleBlockShift = topBlockShift - 32;
-
- exponent += (int)(topBlockBits);
-
- uint bottomBlock = value.GetBlock(bottomBlockIndex);
- uint bottomBits = bottomBlock >> bottomBlockShift;
-
- ulong middleBits = (ulong)(value.GetBlock(middleBlockIndex)) << middleBlockShift;
- ulong topBits = (ulong)(value.GetBlock(topBlockIndex)) << topBlockShift;
-
- mantissa = topBits + middleBits + bottomBits;
-
- uint unusedBottomBlockBitsMask = (1u << (int)(topBlockBits)) - 1;
- hasZeroTail &= (bottomBlock & unusedBottomBlockBitsMask) == 0;
- }
-
- for (uint i = 0; i != bottomBlockIndex; i++)
- {
- hasZeroTail &= (value.GetBlock(i) == 0);
- }
-
- return AssembleFloatingPointBits(in info, mantissa, exponent, hasZeroTail);
- }
-
- // get 32-bit integer from at most 9 digits
- private static uint DigitsToUInt32(byte* p, int count)
- {
- Debug.Assert((1 <= count) && (count <= 9));
-
- byte* end = (p + count);
- uint res = (uint)(p[0] - '0');
-
- for (p++; p < end; p++)
- {
- res = (10 * res) + p[0] - '0';
- }
-
- return res;
- }
-
- // get 64-bit integer from at most 19 digits
- private static ulong DigitsToUInt64(byte* p, int count)
- {
- Debug.Assert((1 <= count) && (count <= 19));
-
- byte* end = (p + count);
- ulong res = (ulong)(p[0] - '0');
-
- for (p++; p < end; p++)
- {
- res = (10 * res) + p[0] - '0';
- }
-
- return res;
- }
-
- private static ulong NumberToFloatingPointBits(ref NumberBuffer number, in FloatingPointInfo info)
- {
- Debug.Assert(number.GetDigitsPointer()[0] != '0');
-
- Debug.Assert(number.Scale <= FloatingPointMaxExponent);
- Debug.Assert(number.Scale >= FloatingPointMinExponent);
-
- Debug.Assert(number.DigitsCount != 0);
-
- // The input is of the form 0.Mantissa x 10^Exponent, where 'Mantissa' are
- // the decimal digits of the mantissa and 'Exponent' is the decimal exponent.
- // We decompose the mantissa into two parts: an integer part and a fractional
- // part. If the exponent is positive, then the integer part consists of the
- // first 'exponent' digits, or all present digits if there are fewer digits.
- // If the exponent is zero or negative, then the integer part is empty. In
- // either case, the remaining digits form the fractional part of the mantissa.
-
- uint totalDigits = (uint)(number.DigitsCount);
- uint positiveExponent = (uint)(Math.Max(0, number.Scale));
-
- uint integerDigitsPresent = Math.Min(positiveExponent, totalDigits);
- uint fractionalDigitsPresent = totalDigits - integerDigitsPresent;
-
- uint fastExponent = (uint)(Math.Abs(number.Scale - integerDigitsPresent - fractionalDigitsPresent));
-
- // When the number of significant digits is less than or equal to 15 and the
- // scale is less than or equal to 22, we can take some shortcuts and just rely
- // on floating-point arithmetic to compute the correct result. This is
- // because each floating-point precision values allows us to exactly represent
- // different whole integers and certain powers of 10, depending on the underlying
- // formats exact range. Additionally, IEEE operations dictate that the result is
- // computed to the infinitely precise result and then rounded, which means that
- // we can rely on it to produce the correct result when both inputs are exact.
-
- byte* src = number.GetDigitsPointer();
-
- if ((info.DenormalMantissaBits == 23) && (totalDigits <= 7) && (fastExponent <= 10))
- {
- // It is only valid to do this optimization for single-precision floating-point
- // values since we can lose some of the mantissa bits and would return the
- // wrong value when upcasting to double.
-
- float result = DigitsToUInt32(src, (int)(totalDigits));
- float scale = s_Pow10SingleTable[fastExponent];
-
- if (fractionalDigitsPresent != 0)
- {
- result /= scale;
- }
- else
- {
- result *= scale;
- }
-
- return (uint)(BitConverter.SingleToInt32Bits(result));
- }
-
- if ((totalDigits <= 15) && (fastExponent <= 22))
- {
- double result = DigitsToUInt64(src, (int)(totalDigits));
- double scale = s_Pow10DoubleTable[fastExponent];
-
- if (fractionalDigitsPresent != 0)
- {
- result /= scale;
- }
- else
- {
- result *= scale;
- }
-
- if (info.DenormalMantissaBits == 52)
- {
- return (ulong)(BitConverter.DoubleToInt64Bits(result));
- }
- else
- {
- Debug.Assert(info.DenormalMantissaBits == 23);
- return (uint)(BitConverter.SingleToInt32Bits((float)(result)));
- }
- }
-
- return NumberToFloatingPointBitsSlow(ref number, in info, positiveExponent, integerDigitsPresent, fractionalDigitsPresent);
- }
-
- private static ulong NumberToFloatingPointBitsSlow(ref NumberBuffer number, in FloatingPointInfo info, uint positiveExponent, uint integerDigitsPresent, uint fractionalDigitsPresent)
- {
- // To generate an N bit mantissa we require N + 1 bits of precision. The
- // extra bit is used to correctly round the mantissa (if there are fewer bits
- // than this available, then that's totally okay; in that case we use what we
- // have and we don't need to round).
- uint requiredBitsOfPrecision = (uint)(info.NormalMantissaBits + 1);
-
- uint totalDigits = (uint)(number.DigitsCount);
- uint integerDigitsMissing = positiveExponent - integerDigitsPresent;
-
- const uint IntegerFirstIndex = 0;
- uint integerLastIndex = integerDigitsPresent;
-
- uint fractionalFirstIndex = integerLastIndex;
- uint fractionalLastIndex = totalDigits;
-
- // First, we accumulate the integer part of the mantissa into a big_integer:
- AccumulateDecimalDigitsIntoBigInteger(ref number, IntegerFirstIndex, integerLastIndex, out BigInteger integerValue);
-
- if (integerDigitsMissing > 0)
- {
- if (integerDigitsMissing > info.OverflowDecimalExponent)
- {
- return info.InfinityBits;
- }
-
- integerValue.MultiplyPow10(integerDigitsMissing);
- }
-
- // At this point, the integer_value contains the value of the integer part
- // of the mantissa. If either [1] this number has more than the required
- // number of bits of precision or [2] the mantissa has no fractional part,
- // then we can assemble the result immediately:
- uint integerBitsOfPrecision = BigInteger.CountSignificantBits(ref integerValue);
-
- if ((integerBitsOfPrecision >= requiredBitsOfPrecision) || (fractionalDigitsPresent == 0))
- {
- return ConvertBigIntegerToFloatingPointBits(
- ref integerValue,
- in info,
- integerBitsOfPrecision,
- fractionalDigitsPresent != 0
- );
- }
-
- // Otherwise, we did not get enough bits of precision from the integer part,
- // and the mantissa has a fractional part. We parse the fractional part of
- // the mantissa to obtain more bits of precision. To do this, we convert
- // the fractional part into an actual fraction N/M, where the numerator N is
- // computed from the digits of the fractional part, and the denominator M is
- // computed as the power of 10 such that N/M is equal to the value of the
- // fractional part of the mantissa.
-
- uint fractionalDenominatorExponent = fractionalDigitsPresent;
-
- if (number.Scale < 0)
- {
- fractionalDenominatorExponent += (uint)(-number.Scale);
- }
-
- if ((integerBitsOfPrecision == 0) && (fractionalDenominatorExponent - (int)(totalDigits)) > info.OverflowDecimalExponent)
- {
- // If there were any digits in the integer part, it is impossible to
- // underflow (because the exponent cannot possibly be small enough),
- // so if we underflow here it is a true underflow and we return zero.
- return info.ZeroBits;
- }
-
- AccumulateDecimalDigitsIntoBigInteger(ref number, fractionalFirstIndex, fractionalLastIndex, out BigInteger fractionalNumerator);
-
- if (fractionalNumerator.IsZero())
- {
- return ConvertBigIntegerToFloatingPointBits(
- ref integerValue,
- in info,
- integerBitsOfPrecision,
- fractionalDigitsPresent != 0
- );
- }
-
- BigInteger.Pow10(fractionalDenominatorExponent, out BigInteger fractionalDenominator);
-
- // Because we are using only the fractional part of the mantissa here, the
- // numerator is guaranteed to be smaller than the denominator. We normalize
- // the fraction such that the most significant bit of the numerator is in
- // the same position as the most significant bit in the denominator. This
- // ensures that when we later shift the numerator N bits to the left, we
- // will produce N bits of precision.
- uint fractionalNumeratorBits = BigInteger.CountSignificantBits(ref fractionalNumerator);
- uint fractionalDenominatorBits = BigInteger.CountSignificantBits(ref fractionalDenominator);
-
- uint fractionalShift = 0;
-
- if (fractionalDenominatorBits > fractionalNumeratorBits)
- {
- fractionalShift = fractionalDenominatorBits - fractionalNumeratorBits;
- }
-
- if (fractionalShift > 0)
- {
- fractionalNumerator.ShiftLeft(fractionalShift);
- }
-
- uint requiredFractionalBitsOfPrecision = requiredBitsOfPrecision - integerBitsOfPrecision;
- uint remainingBitsOfPrecisionRequired = requiredFractionalBitsOfPrecision;
-
- if (integerBitsOfPrecision > 0)
- {
- // If the fractional part of the mantissa provides no bits of precision
- // and cannot affect rounding, we can just take whatever bits we got from
- // the integer part of the mantissa. This is the case for numbers like
- // 5.0000000000000000000001, where the significant digits of the fractional
- // part start so far to the right that they do not affect the floating
- // point representation.
- //
- // If the fractional shift is exactly equal to the number of bits of
- // precision that we require, then no fractional bits will be part of the
- // result, but the result may affect rounding. This is e.g. the case for
- // large, odd integers with a fractional part greater than or equal to .5.
- // Thus, we need to do the division to correctly round the result.
- if (fractionalShift > remainingBitsOfPrecisionRequired)
- {
- return ConvertBigIntegerToFloatingPointBits(
- ref integerValue,
- in info,
- integerBitsOfPrecision,
- fractionalDigitsPresent != 0
- );
- }
-
- remainingBitsOfPrecisionRequired -= fractionalShift;
- }
-
- // If there was no integer part of the mantissa, we will need to compute the
- // exponent from the fractional part. The fractional exponent is the power
- // of two by which we must multiply the fractional part to move it into the
- // range [1.0, 2.0). This will either be the same as the shift we computed
- // earlier, or one greater than that shift:
- uint fractionalExponent = fractionalShift;
-
- if (BigInteger.Compare(ref fractionalNumerator, ref fractionalDenominator) < 0)
- {
- fractionalExponent++;
- }
-
- fractionalNumerator.ShiftLeft(remainingBitsOfPrecisionRequired);
-
- BigInteger.DivRem(ref fractionalNumerator, ref fractionalDenominator, out BigInteger bigFractionalMantissa, out BigInteger fractionalRemainder);
- ulong fractionalMantissa = bigFractionalMantissa.ToUInt64();
- bool hasZeroTail = !number.HasNonZeroTail && fractionalRemainder.IsZero();
-
- // We may have produced more bits of precision than were required. Check,
- // and remove any "extra" bits:
- uint fractionalMantissaBits = BigInteger.CountSignificantBits(fractionalMantissa);
-
- if (fractionalMantissaBits > requiredFractionalBitsOfPrecision)
- {
- int shift = (int)(fractionalMantissaBits - requiredFractionalBitsOfPrecision);
- hasZeroTail = hasZeroTail && (fractionalMantissa & ((1UL << shift) - 1)) == 0;
- fractionalMantissa >>= shift;
- }
-
- // Compose the mantissa from the integer and fractional parts:
- ulong integerMantissa = integerValue.ToUInt64();
- ulong completeMantissa = (integerMantissa << (int)(requiredFractionalBitsOfPrecision)) + fractionalMantissa;
-
- // Compute the final exponent:
- // * If the mantissa had an integer part, then the exponent is one less than
- // the number of bits we obtained from the integer part. (It's one less
- // because we are converting to the form 1.11111, with one 1 to the left
- // of the decimal point.)
- // * If the mantissa had no integer part, then the exponent is the fractional
- // exponent that we computed.
- // Then, in both cases, we subtract an additional one from the exponent, to
- // account for the fact that we've generated an extra bit of precision, for
- // use in rounding.
- int finalExponent = (integerBitsOfPrecision > 0) ? (int)(integerBitsOfPrecision) - 2 : -(int)(fractionalExponent) - 1;
-
- return AssembleFloatingPointBits(in info, completeMantissa, finalExponent, hasZeroTail);
- }
-
- private static ulong RightShiftWithRounding(ulong value, int shift, bool hasZeroTail)
- {
- // If we'd need to shift further than it is possible to shift, the answer
- // is always zero:
- if (shift >= 64)
- {
- return 0;
- }
-
- ulong extraBitsMask = (1UL << (shift - 1)) - 1;
- ulong roundBitMask = (1UL << (shift - 1));
- ulong lsbBitMask = 1UL << shift;
-
- bool lsbBit = (value & lsbBitMask) != 0;
- bool roundBit = (value & roundBitMask) != 0;
- bool hasTailBits = !hasZeroTail || (value & extraBitsMask) != 0;
-
- return (value >> shift) + (ShouldRoundUp(lsbBit, roundBit, hasTailBits) ? 1UL : 0);
- }
-
- private static bool ShouldRoundUp(bool lsbBit, bool roundBit, bool hasTailBits)
- {
- // If there are insignificant set bits, we need to round to the
- // nearest; there are two cases:
- // we round up if either [1] the value is slightly greater than the midpoint
- // between two exactly representable values or [2] the value is exactly the
- // midpoint between two exactly representable values and the greater of the
- // two is even (this is "round-to-even").
- return roundBit && (hasTailBits || lsbBit);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Number.Parsing.cs b/netcore/System.Private.CoreLib/shared/System/Number.Parsing.cs
deleted file mode 100644
index 58eee1f9236..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Number.Parsing.cs
+++ /dev/null
@@ -1,2024 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- // The Parse methods provided by the numeric classes convert a
- // string to a numeric value. The optional style parameter specifies the
- // permitted style of the numeric string. It must be a combination of bit flags
- // from the NumberStyles enumeration. The optional info parameter
- // specifies the NumberFormatInfo instance to use when parsing the
- // string. If the info parameter is null or omitted, the numeric
- // formatting information is obtained from the current culture.
- //
- // Numeric strings produced by the Format methods using the Currency,
- // Decimal, Engineering, Fixed point, General, or Number standard formats
- // (the C, D, E, F, G, and N format specifiers) are guaranteed to be parseable
- // by the Parse methods if the NumberStyles.Any style is
- // specified. Note, however, that the Parse methods do not accept
- // NaNs or Infinities.
-
- internal static partial class Number
- {
- private const int Int32Precision = 10;
- private const int UInt32Precision = Int32Precision;
- private const int Int64Precision = 19;
- private const int UInt64Precision = 20;
-
- private const int DoubleMaxExponent = 309;
- private const int DoubleMinExponent = -324;
-
- private const int FloatingPointMaxExponent = DoubleMaxExponent;
- private const int FloatingPointMinExponent = DoubleMinExponent;
-
- private const int SingleMaxExponent = 39;
- private const int SingleMinExponent = -45;
-
- /// <summary>Map from an ASCII char to its hex value, e.g. arr['b'] == 11. 0xFF means it's not a hex digit.</summary>
- internal static ReadOnlySpan<byte> CharToHexLookup => new byte[]
- {
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 15
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 31
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 47
- 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 63
- 0xFF, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 79
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 95
- 0xFF, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf // 102
- };
-
- private static unsafe bool TryNumberToInt32(ref NumberBuffer number, ref int value)
- {
- number.CheckConsistency();
-
- int i = number.Scale;
- if (i > Int32Precision || i < number.DigitsCount)
- {
- return false;
- }
- byte* p = number.GetDigitsPointer();
- Debug.Assert(p != null);
- int n = 0;
- while (--i >= 0)
- {
- if ((uint)n > (0x7FFFFFFF / 10))
- {
- return false;
- }
- n *= 10;
- if (*p != '\0')
- {
- n += (*p++ - '0');
- }
- }
- if (number.IsNegative)
- {
- n = -n;
- if (n > 0)
- {
- return false;
- }
- }
- else
- {
- if (n < 0)
- {
- return false;
- }
- }
- value = n;
- return true;
- }
-
- private static unsafe bool TryNumberToInt64(ref NumberBuffer number, ref long value)
- {
- number.CheckConsistency();
-
- int i = number.Scale;
- if (i > Int64Precision || i < number.DigitsCount)
- {
- return false;
- }
- byte* p = number.GetDigitsPointer();
- Debug.Assert(p != null);
- long n = 0;
- while (--i >= 0)
- {
- if ((ulong)n > (0x7FFFFFFFFFFFFFFF / 10))
- {
- return false;
- }
- n *= 10;
- if (*p != '\0')
- {
- n += (*p++ - '0');
- }
- }
- if (number.IsNegative)
- {
- n = -n;
- if (n > 0)
- {
- return false;
- }
- }
- else
- {
- if (n < 0)
- {
- return false;
- }
- }
- value = n;
- return true;
- }
-
- private static unsafe bool TryNumberToUInt32(ref NumberBuffer number, ref uint value)
- {
- number.CheckConsistency();
-
- int i = number.Scale;
- if (i > UInt32Precision || i < number.DigitsCount || number.IsNegative)
- {
- return false;
- }
- byte* p = number.GetDigitsPointer();
- Debug.Assert(p != null);
- uint n = 0;
- while (--i >= 0)
- {
- if (n > (0xFFFFFFFF / 10))
- {
- return false;
- }
- n *= 10;
- if (*p != '\0')
- {
- uint newN = n + (uint)(*p++ - '0');
- // Detect an overflow here...
- if (newN < n)
- {
- return false;
- }
- n = newN;
- }
- }
- value = n;
- return true;
- }
-
- private static unsafe bool TryNumberToUInt64(ref NumberBuffer number, ref ulong value)
- {
- number.CheckConsistency();
-
- int i = number.Scale;
- if (i > UInt64Precision || i < number.DigitsCount || number.IsNegative)
- {
- return false;
- }
- byte* p = number.GetDigitsPointer();
- Debug.Assert(p != null);
- ulong n = 0;
- while (--i >= 0)
- {
- if (n > (0xFFFFFFFFFFFFFFFF / 10))
- {
- return false;
- }
- n *= 10;
- if (*p != '\0')
- {
- ulong newN = n + (ulong)(*p++ - '0');
- // Detect an overflow here...
- if (newN < n)
- {
- return false;
- }
- n = newN;
- }
- }
- value = n;
- return true;
- }
-
- internal static int ParseInt32(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info)
- {
- ParsingStatus status = TryParseInt32(value, styles, info, out int result);
- if (status != ParsingStatus.OK)
- {
- ThrowOverflowOrFormatException(status, TypeCode.Int32);
- }
-
- return result;
- }
-
- internal static long ParseInt64(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info)
- {
- ParsingStatus status = TryParseInt64(value, styles, info, out long result);
- if (status != ParsingStatus.OK)
- {
- ThrowOverflowOrFormatException(status, TypeCode.Int64);
- }
-
- return result;
- }
-
- internal static uint ParseUInt32(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info)
- {
- ParsingStatus status = TryParseUInt32(value, styles, info, out uint result);
- if (status != ParsingStatus.OK)
- {
- ThrowOverflowOrFormatException(status, TypeCode.UInt32);
- }
-
- return result;
- }
-
- internal static ulong ParseUInt64(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info)
- {
- ParsingStatus status = TryParseUInt64(value, styles, info, out ulong result);
- if (status != ParsingStatus.OK)
- {
- ThrowOverflowOrFormatException(status, TypeCode.UInt64);
- }
-
- return result;
- }
-
- private static unsafe bool TryParseNumber(ref char* str, char* strEnd, NumberStyles styles, ref NumberBuffer number, NumberFormatInfo info)
- {
- Debug.Assert(str != null);
- Debug.Assert(strEnd != null);
- Debug.Assert(str <= strEnd);
- Debug.Assert((styles & NumberStyles.AllowHexSpecifier) == 0);
-
- const int StateSign = 0x0001;
- const int StateParens = 0x0002;
- const int StateDigits = 0x0004;
- const int StateNonZero = 0x0008;
- const int StateDecimal = 0x0010;
- const int StateCurrency = 0x0020;
-
- Debug.Assert(number.DigitsCount == 0);
- Debug.Assert(number.Scale == 0);
- Debug.Assert(!number.IsNegative);
- Debug.Assert(!number.HasNonZeroTail);
-
- number.CheckConsistency();
-
- string decSep; // decimal separator from NumberFormatInfo.
- string groupSep; // group separator from NumberFormatInfo.
- string? currSymbol = null; // currency symbol from NumberFormatInfo.
-
- bool parsingCurrency = false;
- if ((styles & NumberStyles.AllowCurrencySymbol) != 0)
- {
- currSymbol = info.CurrencySymbol;
-
- // The idea here is to match the currency separators and on failure match the number separators to keep the perf of VB's IsNumeric fast.
- // The values of decSep are setup to use the correct relevant separator (currency in the if part and decimal in the else part).
- decSep = info.CurrencyDecimalSeparator;
- groupSep = info.CurrencyGroupSeparator;
- parsingCurrency = true;
- }
- else
- {
- decSep = info.NumberDecimalSeparator;
- groupSep = info.NumberGroupSeparator;
- }
-
- int state = 0;
- char* p = str;
- char ch = p < strEnd ? *p : '\0';
- char* next;
-
- while (true)
- {
- // Eat whitespace unless we've found a sign which isn't followed by a currency symbol.
- // "-Kr 1231.47" is legal but "- 1231.47" is not.
- if (!IsWhite(ch) || (styles & NumberStyles.AllowLeadingWhite) == 0 || ((state & StateSign) != 0 && ((state & StateCurrency) == 0 && info.NumberNegativePattern != 2)))
- {
- if ((((styles & NumberStyles.AllowLeadingSign) != 0) && (state & StateSign) == 0) && ((next = MatchChars(p, strEnd, info.PositiveSign)) != null || ((next = MatchChars(p, strEnd, info.NegativeSign)) != null && (number.IsNegative = true))))
- {
- state |= StateSign;
- p = next - 1;
- }
- else if (ch == '(' && ((styles & NumberStyles.AllowParentheses) != 0) && ((state & StateSign) == 0))
- {
- state |= StateSign | StateParens;
- number.IsNegative = true;
- }
- else if (currSymbol != null && (next = MatchChars(p, strEnd, currSymbol)) != null)
- {
- state |= StateCurrency;
- currSymbol = null;
- // We already found the currency symbol. There should not be more currency symbols. Set
- // currSymbol to NULL so that we won't search it again in the later code path.
- p = next - 1;
- }
- else
- {
- break;
- }
- }
- ch = ++p < strEnd ? *p : '\0';
- }
-
- int digCount = 0;
- int digEnd = 0;
- int maxDigCount = number.Digits.Length - 1;
-
- while (true)
- {
- if (IsDigit(ch))
- {
- state |= StateDigits;
-
- if (ch != '0' || (state & StateNonZero) != 0)
- {
- if (digCount < maxDigCount)
- {
- number.Digits[digCount++] = (byte)(ch);
- if ((ch != '0') || (number.Kind != NumberBufferKind.Integer))
- {
- digEnd = digCount;
- }
- }
- else if (ch != '0')
- {
- // For decimal and binary floating-point numbers, we only
- // need to store digits up to maxDigCount. However, we still
- // need to keep track of whether any additional digits past
- // maxDigCount were non-zero, as that can impact rounding
- // for an input that falls evenly between two representable
- // results.
-
- number.HasNonZeroTail = true;
- }
-
- if ((state & StateDecimal) == 0)
- {
- number.Scale++;
- }
- state |= StateNonZero;
- }
- else if ((state & StateDecimal) != 0)
- {
- number.Scale--;
- }
- }
- else if (((styles & NumberStyles.AllowDecimalPoint) != 0) && ((state & StateDecimal) == 0) && ((next = MatchChars(p, strEnd, decSep)) != null || (parsingCurrency && (state & StateCurrency) == 0) && (next = MatchChars(p, strEnd, info.NumberDecimalSeparator)) != null))
- {
- state |= StateDecimal;
- p = next - 1;
- }
- else if (((styles & NumberStyles.AllowThousands) != 0) && ((state & StateDigits) != 0) && ((state & StateDecimal) == 0) && ((next = MatchChars(p, strEnd, groupSep)) != null || (parsingCurrency && (state & StateCurrency) == 0) && (next = MatchChars(p, strEnd, info.NumberGroupSeparator)) != null))
- {
- p = next - 1;
- }
- else
- {
- break;
- }
- ch = ++p < strEnd ? *p : '\0';
- }
-
- bool negExp = false;
- number.DigitsCount = digEnd;
- number.Digits[digEnd] = (byte)('\0');
- if ((state & StateDigits) != 0)
- {
- if ((ch == 'E' || ch == 'e') && ((styles & NumberStyles.AllowExponent) != 0))
- {
- char* temp = p;
- ch = ++p < strEnd ? *p : '\0';
- if ((next = MatchChars(p, strEnd, info._positiveSign)) != null)
- {
- ch = (p = next) < strEnd ? *p : '\0';
- }
- else if ((next = MatchChars(p, strEnd, info._negativeSign)) != null)
- {
- ch = (p = next) < strEnd ? *p : '\0';
- negExp = true;
- }
- if (IsDigit(ch))
- {
- int exp = 0;
- do
- {
- exp = exp * 10 + (ch - '0');
- ch = ++p < strEnd ? *p : '\0';
- if (exp > 1000)
- {
- exp = 9999;
- while (IsDigit(ch))
- {
- ch = ++p < strEnd ? *p : '\0';
- }
- }
- } while (IsDigit(ch));
- if (negExp)
- {
- exp = -exp;
- }
- number.Scale += exp;
- }
- else
- {
- p = temp;
- ch = p < strEnd ? *p : '\0';
- }
- }
- while (true)
- {
- if (!IsWhite(ch) || (styles & NumberStyles.AllowTrailingWhite) == 0)
- {
- if ((styles & NumberStyles.AllowTrailingSign) != 0 && ((state & StateSign) == 0) && ((next = MatchChars(p, strEnd, info.PositiveSign)) != null || (((next = MatchChars(p, strEnd, info.NegativeSign)) != null) && (number.IsNegative = true))))
- {
- state |= StateSign;
- p = next - 1;
- }
- else if (ch == ')' && ((state & StateParens) != 0))
- {
- state &= ~StateParens;
- }
- else if (currSymbol != null && (next = MatchChars(p, strEnd, currSymbol)) != null)
- {
- currSymbol = null;
- p = next - 1;
- }
- else
- {
- break;
- }
- }
- ch = ++p < strEnd ? *p : '\0';
- }
- if ((state & StateParens) == 0)
- {
- if ((state & StateNonZero) == 0)
- {
- if (number.Kind != NumberBufferKind.Decimal)
- {
- number.Scale = 0;
- }
- if ((number.Kind == NumberBufferKind.Integer) && (state & StateDecimal) == 0)
- {
- number.IsNegative = false;
- }
- }
- str = p;
- return true;
- }
- }
- str = p;
- return false;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static ParsingStatus TryParseInt32(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out int result)
- {
- if ((styles & ~NumberStyles.Integer) == 0)
- {
- // Optimized path for the common case of anything that's allowed for integer style.
- return TryParseInt32IntegerStyle(value, styles, info, out result);
- }
-
- if ((styles & NumberStyles.AllowHexSpecifier) != 0)
- {
- result = 0;
- return TryParseUInt32HexNumberStyle(value, styles, out Unsafe.As<int, uint>(ref result));
- }
-
- return TryParseInt32Number(value, styles, info, out result);
- }
-
- private static unsafe ParsingStatus TryParseInt32Number(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out int result)
- {
- result = 0;
- byte* pDigits = stackalloc byte[Int32NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, Int32NumberBufferLength);
-
- if (!TryStringToNumber(value, styles, ref number, info))
- {
- return ParsingStatus.Failed;
- }
-
- if (!TryNumberToInt32(ref number, ref result))
- {
- return ParsingStatus.Overflow;
- }
-
- return ParsingStatus.OK;
- }
-
- /// <summary>Parses int limited to styles that make up NumberStyles.Integer.</summary>
- internal static ParsingStatus TryParseInt32IntegerStyle(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out int result)
- {
- Debug.Assert((styles & ~NumberStyles.Integer) == 0, "Only handles subsets of Integer format");
-
- if (value.IsEmpty)
- goto FalseExit;
-
- int index = 0;
- int num = value[0];
-
- // Skip past any whitespace at the beginning.
- if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num))
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- while (IsWhite(num));
- }
-
- // Parse leading sign.
- int sign = 1;
- if ((styles & NumberStyles.AllowLeadingSign) != 0)
- {
- if (info.HasInvariantNumberSigns)
- {
- if (num == '-')
- {
- sign = -1;
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- else if (num == '+')
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- }
- else
- {
- value = value.Slice(index);
- index = 0;
- string positiveSign = info.PositiveSign, negativeSign = info.NegativeSign;
- if (!string.IsNullOrEmpty(positiveSign) && value.StartsWith(positiveSign))
- {
- index += positiveSign.Length;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- else if (!string.IsNullOrEmpty(negativeSign) && value.StartsWith(negativeSign))
- {
- sign = -1;
- index += negativeSign.Length;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- }
- }
-
- bool overflow = false;
- int answer = 0;
-
- if (IsDigit(num))
- {
- // Skip past leading zeros.
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- } while (num == '0');
- if (!IsDigit(num))
- goto HasTrailingChars;
- }
-
- // Parse most digits, up to the potential for overflow, which can't happen until after 9 digits.
- answer = num - '0'; // first digit
- index++;
- for (int i = 0; i < 8; i++) // next 8 digits can't overflow
- {
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- if (!IsDigit(num))
- goto HasTrailingChars;
- index++;
- answer = 10 * answer + num - '0';
- }
-
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- if (!IsDigit(num))
- goto HasTrailingChars;
- index++;
- // Potential overflow now processing the 10th digit.
- overflow = answer > int.MaxValue / 10;
- answer = answer * 10 + num - '0';
- overflow |= (uint)answer > int.MaxValue + (((uint)sign) >> 31);
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
-
- // At this point, we're either overflowing or hitting a formatting error.
- // Format errors take precedence for compatibility.
- num = value[index];
- while (IsDigit(num))
- {
- overflow = true;
- index++;
- if ((uint)index >= (uint)value.Length)
- goto OverflowExit;
- num = value[index];
- }
- goto HasTrailingChars;
- }
- goto FalseExit;
-
- DoneAtEndButPotentialOverflow:
- if (overflow)
- {
- goto OverflowExit;
- }
- DoneAtEnd:
- result = answer * sign;
- ParsingStatus status = ParsingStatus.OK;
- Exit:
- return status;
-
- FalseExit: // parsing failed
- result = 0;
- status = ParsingStatus.Failed;
- goto Exit;
- OverflowExit:
- result = 0;
- status = ParsingStatus.Overflow;
- goto Exit;
-
- HasTrailingChars: // we've successfully parsed, but there are still remaining characters in the span
- // Skip past trailing whitespace, then past trailing zeros, and if anything else remains, fail.
- if (IsWhite(num))
- {
- if ((styles & NumberStyles.AllowTrailingWhite) == 0)
- goto FalseExit;
- for (index++; index < value.Length; index++)
- {
- if (!IsWhite(value[index]))
- break;
- }
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
- }
-
- if (!TrailingZeros(value, index))
- goto FalseExit;
-
- goto DoneAtEndButPotentialOverflow;
- }
-
- /// <summary>Parses long inputs limited to styles that make up NumberStyles.Integer.</summary>
- internal static ParsingStatus TryParseInt64IntegerStyle(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out long result)
- {
- Debug.Assert((styles & ~NumberStyles.Integer) == 0, "Only handles subsets of Integer format");
-
- if (value.IsEmpty)
- goto FalseExit;
-
- int index = 0;
- int num = value[0];
-
- // Skip past any whitespace at the beginning.
- if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num))
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- while (IsWhite(num));
- }
-
- // Parse leading sign.
- int sign = 1;
- if ((styles & NumberStyles.AllowLeadingSign) != 0)
- {
- if (info.HasInvariantNumberSigns)
- {
- if (num == '-')
- {
- sign = -1;
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- else if (num == '+')
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- }
- else
- {
- value = value.Slice(index);
- index = 0;
- string positiveSign = info.PositiveSign, negativeSign = info.NegativeSign;
- if (!string.IsNullOrEmpty(positiveSign) && value.StartsWith(positiveSign))
- {
- index += positiveSign.Length;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- else if (!string.IsNullOrEmpty(negativeSign) && value.StartsWith(negativeSign))
- {
- sign = -1;
- index += negativeSign.Length;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- }
- }
-
- bool overflow = false;
- long answer = 0;
-
- if (IsDigit(num))
- {
- // Skip past leading zeros.
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- } while (num == '0');
- if (!IsDigit(num))
- goto HasTrailingChars;
- }
-
- // Parse most digits, up to the potential for overflow, which can't happen until after 18 digits.
- answer = num - '0'; // first digit
- index++;
- for (int i = 0; i < 17; i++) // next 17 digits can't overflow
- {
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- if (!IsDigit(num))
- goto HasTrailingChars;
- index++;
- answer = 10 * answer + num - '0';
- }
-
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- if (!IsDigit(num))
- goto HasTrailingChars;
- index++;
- // Potential overflow now processing the 19th digit.
- overflow = answer > long.MaxValue / 10;
- answer = answer * 10 + num - '0';
- overflow |= (ulong)answer > (ulong)long.MaxValue + (((uint)sign) >> 31);
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
-
- // At this point, we're either overflowing or hitting a formatting error.
- // Format errors take precedence for compatibility.
- num = value[index];
- while (IsDigit(num))
- {
- overflow = true;
- index++;
- if ((uint)index >= (uint)value.Length)
- goto OverflowExit;
- num = value[index];
- }
- goto HasTrailingChars;
- }
- goto FalseExit;
-
- DoneAtEndButPotentialOverflow:
- if (overflow)
- {
- goto OverflowExit;
- }
- DoneAtEnd:
- result = answer * sign;
- ParsingStatus status = ParsingStatus.OK;
- Exit:
- return status;
-
- FalseExit: // parsing failed
- result = 0;
- status = ParsingStatus.Failed;
- goto Exit;
- OverflowExit:
- result = 0;
- status = ParsingStatus.Overflow;
- goto Exit;
-
- HasTrailingChars: // we've successfully parsed, but there are still remaining characters in the span
- // Skip past trailing whitespace, then past trailing zeros, and if anything else remains, fail.
- if (IsWhite(num))
- {
- if ((styles & NumberStyles.AllowTrailingWhite) == 0)
- goto FalseExit;
- for (index++; index < value.Length; index++)
- {
- if (!IsWhite(value[index]))
- break;
- }
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
- }
-
- if (!TrailingZeros(value, index))
- goto FalseExit;
-
- goto DoneAtEndButPotentialOverflow;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static ParsingStatus TryParseInt64(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out long result)
- {
- if ((styles & ~NumberStyles.Integer) == 0)
- {
- // Optimized path for the common case of anything that's allowed for integer style.
- return TryParseInt64IntegerStyle(value, styles, info, out result);
- }
-
- if ((styles & NumberStyles.AllowHexSpecifier) != 0)
- {
- result = 0;
- return TryParseUInt64HexNumberStyle(value, styles, out Unsafe.As<long, ulong>(ref result));
- }
-
- return TryParseInt64Number(value, styles, info, out result);
- }
-
- private static unsafe ParsingStatus TryParseInt64Number(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out long result)
- {
- result = 0;
- byte* pDigits = stackalloc byte[Int64NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, Int64NumberBufferLength);
-
- if (!TryStringToNumber(value, styles, ref number, info))
- {
- return ParsingStatus.Failed;
- }
-
- if (!TryNumberToInt64(ref number, ref result))
- {
- return ParsingStatus.Overflow;
- }
-
- return ParsingStatus.OK;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static ParsingStatus TryParseUInt32(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out uint result)
- {
- if ((styles & ~NumberStyles.Integer) == 0)
- {
- // Optimized path for the common case of anything that's allowed for integer style.
- return TryParseUInt32IntegerStyle(value, styles, info, out result);
- }
-
- if ((styles & NumberStyles.AllowHexSpecifier) != 0)
- {
- return TryParseUInt32HexNumberStyle(value, styles, out result);
- }
-
- return TryParseUInt32Number(value, styles, info, out result);
- }
-
- private static unsafe ParsingStatus TryParseUInt32Number(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out uint result)
- {
- result = 0;
- byte* pDigits = stackalloc byte[UInt32NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, UInt32NumberBufferLength);
-
- if (!TryStringToNumber(value, styles, ref number, info))
- {
- return ParsingStatus.Failed;
- }
-
- if (!TryNumberToUInt32(ref number, ref result))
- {
- return ParsingStatus.Overflow;
- }
-
- return ParsingStatus.OK;
- }
-
- /// <summary>Parses uint limited to styles that make up NumberStyles.Integer.</summary>
- internal static ParsingStatus TryParseUInt32IntegerStyle(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out uint result)
- {
- Debug.Assert((styles & ~NumberStyles.Integer) == 0, "Only handles subsets of Integer format");
-
- if (value.IsEmpty)
- goto FalseExit;
-
- int index = 0;
- int num = value[0];
-
- // Skip past any whitespace at the beginning.
- if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num))
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- while (IsWhite(num));
- }
-
- // Parse leading sign.
- bool overflow = false;
- if ((styles & NumberStyles.AllowLeadingSign) != 0)
- {
- if (info.HasInvariantNumberSigns)
- {
- if (num == '+')
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- else if (num == '-')
- {
- overflow = true;
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- }
- else
- {
- value = value.Slice(index);
- index = 0;
- string positiveSign = info.PositiveSign, negativeSign = info.NegativeSign;
- if (!string.IsNullOrEmpty(positiveSign) && value.StartsWith(positiveSign))
- {
- index += positiveSign.Length;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- else if (!string.IsNullOrEmpty(negativeSign) && value.StartsWith(negativeSign))
- {
- overflow = true;
- index += negativeSign.Length;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- }
- }
-
- int answer = 0;
-
- if (IsDigit(num))
- {
- // Skip past leading zeros.
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- } while (num == '0');
- if (!IsDigit(num))
- goto HasTrailingCharsZero;
- }
-
- // Parse most digits, up to the potential for overflow, which can't happen until after 9 digits.
- answer = num - '0'; // first digit
- index++;
- for (int i = 0; i < 8; i++) // next 8 digits can't overflow
- {
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
- num = value[index];
- if (!IsDigit(num))
- goto HasTrailingChars;
- index++;
- answer = 10 * answer + num - '0';
- }
-
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
- num = value[index];
- if (!IsDigit(num))
- goto HasTrailingChars;
- index++;
- // Potential overflow now processing the 10th digit.
- overflow |= (uint)answer > uint.MaxValue / 10 || ((uint)answer == uint.MaxValue / 10 && num > '5');
- answer = answer * 10 + num - '0';
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
-
- // At this point, we're either overflowing or hitting a formatting error.
- // Format errors take precedence for compatibility.
- num = value[index];
- while (IsDigit(num))
- {
- overflow = true;
- index++;
- if ((uint)index >= (uint)value.Length)
- goto OverflowExit;
- num = value[index];
- }
- goto HasTrailingChars;
- }
- goto FalseExit;
-
- DoneAtEndButPotentialOverflow:
- if (overflow)
- {
- goto OverflowExit;
- }
- DoneAtEnd:
- result = (uint)answer;
- ParsingStatus status = ParsingStatus.OK;
- Exit:
- return status;
-
- FalseExit: // parsing failed
- result = 0;
- status = ParsingStatus.Failed;
- goto Exit;
- OverflowExit:
- result = 0;
- status = ParsingStatus.Overflow;
- goto Exit;
-
- HasTrailingCharsZero:
- overflow = false;
- HasTrailingChars: // we've successfully parsed, but there are still remaining characters in the span
- // Skip past trailing whitespace, then past trailing zeros, and if anything else remains, fail.
- if (IsWhite(num))
- {
- if ((styles & NumberStyles.AllowTrailingWhite) == 0)
- goto FalseExit;
- for (index++; index < value.Length; index++)
- {
- if (!IsWhite(value[index]))
- break;
- }
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
- }
-
- if (!TrailingZeros(value, index))
- goto FalseExit;
-
- goto DoneAtEndButPotentialOverflow;
- }
-
- /// <summary>Parses uint limited to styles that make up NumberStyles.HexNumber.</summary>
- private static ParsingStatus TryParseUInt32HexNumberStyle(ReadOnlySpan<char> value, NumberStyles styles, out uint result)
- {
- Debug.Assert((styles & ~NumberStyles.HexNumber) == 0, "Only handles subsets of HexNumber format");
-
- if (value.IsEmpty)
- goto FalseExit;
-
- int index = 0;
- int num = value[0];
-
- // Skip past any whitespace at the beginning.
- if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num))
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- while (IsWhite(num));
- }
-
- bool overflow = false;
- uint answer = 0;
- ReadOnlySpan<byte> charToHexLookup = CharToHexLookup;
-
- if ((uint)num < (uint)charToHexLookup.Length && charToHexLookup[num] != 0xFF)
- {
- // Skip past leading zeros.
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- } while (num == '0');
- if ((uint)num >= (uint)charToHexLookup.Length || charToHexLookup[num] == 0xFF)
- goto HasTrailingChars;
- }
-
- // Parse up through 8 digits, as no overflow is possible
- answer = charToHexLookup[num]; // first digit
- index++;
- for (int i = 0; i < 7; i++) // next 7 digits can't overflow
- {
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
-
- uint numValue;
- if ((uint)num >= (uint)charToHexLookup.Length || (numValue = charToHexLookup[num]) == 0xFF)
- goto HasTrailingChars;
- index++;
- answer = 16 * answer + numValue;
- }
-
- // If there's another digit, it's an overflow.
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- if ((uint)num >= (uint)charToHexLookup.Length || charToHexLookup[num] == 0xFF)
- goto HasTrailingChars;
-
- // At this point, we're either overflowing or hitting a formatting error.
- // Format errors take precedence for compatibility. Read through any remaining digits.
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto OverflowExit;
- num = value[index];
- } while ((uint)num < (uint)charToHexLookup.Length && charToHexLookup[num] != 0xFF);
- overflow = true;
- goto HasTrailingChars;
- }
- goto FalseExit;
-
- DoneAtEndButPotentialOverflow:
- if (overflow)
- {
- goto OverflowExit;
- }
- DoneAtEnd:
- result = answer;
- ParsingStatus status = ParsingStatus.OK;
- Exit:
- return status;
-
- FalseExit: // parsing failed
- result = 0;
- status = ParsingStatus.Failed;
- goto Exit;
- OverflowExit:
- result = 0;
- status = ParsingStatus.Overflow;
- goto Exit;
-
- HasTrailingChars: // we've successfully parsed, but there are still remaining characters in the span
- // Skip past trailing whitespace, then past trailing zeros, and if anything else remains, fail.
- if (IsWhite(num))
- {
- if ((styles & NumberStyles.AllowTrailingWhite) == 0)
- goto FalseExit;
- for (index++; index < value.Length; index++)
- {
- if (!IsWhite(value[index]))
- break;
- }
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
- }
-
- if (!TrailingZeros(value, index))
- goto FalseExit;
-
- goto DoneAtEndButPotentialOverflow;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static ParsingStatus TryParseUInt64(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out ulong result)
- {
- if ((styles & ~NumberStyles.Integer) == 0)
- {
- // Optimized path for the common case of anything that's allowed for integer style.
- return TryParseUInt64IntegerStyle(value, styles, info, out result);
- }
-
- if ((styles & NumberStyles.AllowHexSpecifier) != 0)
- {
- return TryParseUInt64HexNumberStyle(value, styles, out result);
- }
-
- return TryParseUInt64Number(value, styles, info, out result);
- }
-
- private static unsafe ParsingStatus TryParseUInt64Number(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out ulong result)
- {
- result = 0;
- byte* pDigits = stackalloc byte[UInt64NumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Integer, pDigits, UInt64NumberBufferLength);
-
- if (!TryStringToNumber(value, styles, ref number, info))
- {
- return ParsingStatus.Failed;
- }
-
- if (!TryNumberToUInt64(ref number, ref result))
- {
- return ParsingStatus.Overflow;
- }
-
- return ParsingStatus.OK;
- }
-
- /// <summary>Parses ulong limited to styles that make up NumberStyles.Integer.</summary>
- internal static ParsingStatus TryParseUInt64IntegerStyle(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out ulong result)
- {
- Debug.Assert((styles & ~NumberStyles.Integer) == 0, "Only handles subsets of Integer format");
-
- if (value.IsEmpty)
- goto FalseExit;
-
- int index = 0;
- int num = value[0];
-
- // Skip past any whitespace at the beginning.
- if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num))
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- while (IsWhite(num));
- }
-
- // Parse leading sign.
- bool overflow = false;
- if ((styles & NumberStyles.AllowLeadingSign) != 0)
- {
- if (info.HasInvariantNumberSigns)
- {
- if (num == '+')
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- else if (num == '-')
- {
- overflow = true;
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- }
- else
- {
- value = value.Slice(index);
- index = 0;
- string positiveSign = info.PositiveSign, negativeSign = info.NegativeSign;
- if (!string.IsNullOrEmpty(positiveSign) && value.StartsWith(positiveSign))
- {
- index += positiveSign.Length;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- else if (!string.IsNullOrEmpty(negativeSign) && value.StartsWith(negativeSign))
- {
- overflow = true;
- index += negativeSign.Length;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- }
- }
-
- long answer = 0;
-
- if (IsDigit(num))
- {
- // Skip past leading zeros.
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- } while (num == '0');
- if (!IsDigit(num))
- goto HasTrailingCharsZero;
- }
-
- // Parse most digits, up to the potential for overflow, which can't happen until after 19 digits.
- answer = num - '0'; // first digit
- index++;
- for (int i = 0; i < 18; i++) // next 18 digits can't overflow
- {
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
- num = value[index];
- if (!IsDigit(num))
- goto HasTrailingChars;
- index++;
- answer = 10 * answer + num - '0';
- }
-
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
- num = value[index];
- if (!IsDigit(num))
- goto HasTrailingChars;
- index++;
- // Potential overflow now processing the 20th digit.
- overflow |= (ulong)answer > ulong.MaxValue / 10 || ((ulong)answer == ulong.MaxValue / 10 && num > '5');
- answer = answer * 10 + num - '0';
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
-
- // At this point, we're either overflowing or hitting a formatting error.
- // Format errors take precedence for compatibility.
- num = value[index];
- while (IsDigit(num))
- {
- overflow = true;
- index++;
- if ((uint)index >= (uint)value.Length)
- goto OverflowExit;
- num = value[index];
- }
- goto HasTrailingChars;
- }
- goto FalseExit;
-
- DoneAtEndButPotentialOverflow:
- if (overflow)
- {
- goto OverflowExit;
- }
- DoneAtEnd:
- result = (ulong)answer;
- ParsingStatus status = ParsingStatus.OK;
- Exit:
- return status;
-
- FalseExit: // parsing failed
- result = 0;
- status = ParsingStatus.Failed;
- goto Exit;
- OverflowExit:
- result = 0;
- status = ParsingStatus.Overflow;
- goto Exit;
-
- HasTrailingCharsZero:
- overflow = false;
- HasTrailingChars: // we've successfully parsed, but there are still remaining characters in the span
- // Skip past trailing whitespace, then past trailing zeros, and if anything else remains, fail.
- if (IsWhite(num))
- {
- if ((styles & NumberStyles.AllowTrailingWhite) == 0)
- goto FalseExit;
- for (index++; index < value.Length; index++)
- {
- if (!IsWhite(value[index]))
- break;
- }
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
- }
-
- if (!TrailingZeros(value, index))
- goto FalseExit;
-
- goto DoneAtEndButPotentialOverflow;
- }
-
- /// <summary>Parses ulong limited to styles that make up NumberStyles.HexNumber.</summary>
- private static ParsingStatus TryParseUInt64HexNumberStyle(ReadOnlySpan<char> value, NumberStyles styles, out ulong result)
- {
- Debug.Assert((styles & ~NumberStyles.HexNumber) == 0, "Only handles subsets of HexNumber format");
-
- if (value.IsEmpty)
- goto FalseExit;
-
- int index = 0;
- int num = value[0];
-
- // Skip past any whitespace at the beginning.
- if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num))
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto FalseExit;
- num = value[index];
- }
- while (IsWhite(num));
- }
-
- bool overflow = false;
- ulong answer = 0;
- ReadOnlySpan<byte> charToHexLookup = CharToHexLookup;
-
- if ((uint)num < (uint)charToHexLookup.Length && charToHexLookup[num] != 0xFF)
- {
- // Skip past leading zeros.
- if (num == '0')
- {
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- } while (num == '0');
- if ((uint)num >= (uint)charToHexLookup.Length || charToHexLookup[num] == 0xFF)
- goto HasTrailingChars;
- }
-
- // Parse up through 16 digits, as no overflow is possible
- answer = charToHexLookup[num]; // first digit
- index++;
- for (int i = 0; i < 15; i++) // next 15 digits can't overflow
- {
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
-
- uint numValue;
- if ((uint)num >= (uint)charToHexLookup.Length || (numValue = charToHexLookup[num]) == 0xFF)
- goto HasTrailingChars;
- index++;
- answer = 16 * answer + numValue;
- }
-
- // If there's another digit, it's an overflow.
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEnd;
- num = value[index];
- if ((uint)num >= (uint)charToHexLookup.Length || charToHexLookup[num] == 0xFF)
- goto HasTrailingChars;
-
- // At this point, we're either overflowing or hitting a formatting error.
- // Format errors take precedence for compatibility. Read through any remaining digits.
- do
- {
- index++;
- if ((uint)index >= (uint)value.Length)
- goto OverflowExit;
- num = value[index];
- } while ((uint)num < (uint)charToHexLookup.Length && charToHexLookup[num] != 0xFF);
- overflow = true;
- goto HasTrailingChars;
- }
- goto FalseExit;
-
- DoneAtEndButPotentialOverflow:
- if (overflow)
- {
- goto OverflowExit;
- }
- DoneAtEnd:
- result = answer;
- ParsingStatus status = ParsingStatus.OK;
- Exit:
- return status;
-
- FalseExit: // parsing failed
- result = 0;
- status = ParsingStatus.Failed;
- goto Exit;
- OverflowExit:
- result = 0;
- status = ParsingStatus.Overflow;
- goto Exit;
-
- HasTrailingChars: // we've successfully parsed, but there are still remaining characters in the span
- // Skip past trailing whitespace, then past trailing zeros, and if anything else remains, fail.
- if (IsWhite(num))
- {
- if ((styles & NumberStyles.AllowTrailingWhite) == 0)
- goto FalseExit;
- for (index++; index < value.Length; index++)
- {
- if (!IsWhite(value[index]))
- break;
- }
- if ((uint)index >= (uint)value.Length)
- goto DoneAtEndButPotentialOverflow;
- }
-
- if (!TrailingZeros(value, index))
- goto FalseExit;
-
- goto DoneAtEndButPotentialOverflow;
- }
-
- internal static decimal ParseDecimal(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info)
- {
- ParsingStatus status = TryParseDecimal(value, styles, info, out decimal result);
- if (status != ParsingStatus.OK)
- {
- ThrowOverflowOrFormatException(status, TypeCode.Decimal);
- }
-
- return result;
- }
-
- internal static unsafe bool TryNumberToDecimal(ref NumberBuffer number, ref decimal value)
- {
- number.CheckConsistency();
-
- byte* p = number.GetDigitsPointer();
- int e = number.Scale;
- bool sign = number.IsNegative;
- uint c = *p;
- if (c == 0)
- {
- // To avoid risking an app-compat issue with pre 4.5 (where some app was illegally using Reflection to examine the internal scale bits), we'll only force
- // the scale to 0 if the scale was previously positive (previously, such cases were unparsable to a bug.)
- value = new decimal(0, 0, 0, sign, (byte)Math.Clamp(-e, 0, 28));
- return true;
- }
-
- if (e > DecimalPrecision)
- return false;
-
- ulong low64 = 0;
- while (e > -28)
- {
- e--;
- low64 *= 10;
- low64 += c - '0';
- c = *++p;
- if (low64 >= ulong.MaxValue / 10)
- break;
- if (c == 0)
- {
- while (e > 0)
- {
- e--;
- low64 *= 10;
- if (low64 >= ulong.MaxValue / 10)
- break;
- }
- break;
- }
- }
-
- uint high = 0;
- while ((e > 0 || (c != 0 && e > -28)) &&
- (high < uint.MaxValue / 10 || (high == uint.MaxValue / 10 && (low64 < 0x99999999_99999999 || (low64 == 0x99999999_99999999 && c <= '5')))))
- {
- // multiply by 10
- ulong tmpLow = (uint)low64 * 10UL;
- ulong tmp64 = (uint)(low64 >> 32) * 10UL + (tmpLow >> 32);
- low64 = (uint)tmpLow + (tmp64 << 32);
- high = (uint)(tmp64 >> 32) + high * 10;
-
- if (c != 0)
- {
- c -= '0';
- low64 += c;
- if (low64 < c)
- high++;
- c = *++p;
- }
- e--;
- }
-
- if (c >= '5')
- {
- if ((c == '5') && ((low64 & 1) == 0))
- {
- c = *++p;
-
- bool hasZeroTail = !number.HasNonZeroTail;
-
- // We might still have some additional digits, in which case they need
- // to be considered as part of hasZeroTail. Some examples of this are:
- // * 3.0500000000000000000001e-27
- // * 3.05000000000000000000001e-27
- // In these cases, we will have processed 3 and 0, and ended on 5. The
- // buffer, however, will still contain a number of trailing zeros and
- // a trailing non-zero number.
-
- while ((c != 0) && hasZeroTail)
- {
- hasZeroTail &= (c == '0');
- c = *++p;
- }
-
- // We should either be at the end of the stream or have a non-zero tail
- Debug.Assert((c == 0) || !hasZeroTail);
-
- if (hasZeroTail)
- {
- // When the next digit is 5, the number is even, and all following
- // digits are zero we don't need to round.
- goto NoRounding;
- }
- }
-
- if (++low64 == 0 && ++high == 0)
- {
- low64 = 0x99999999_9999999A;
- high = uint.MaxValue / 10;
- e++;
- }
- }
- NoRounding:
-
- if (e > 0)
- return false;
-
- if (e <= -DecimalPrecision)
- {
- // Parsing a large scale zero can give you more precision than fits in the decimal.
- // This should only happen for actual zeros or very small numbers that round to zero.
- value = new decimal(0, 0, 0, sign, DecimalPrecision - 1);
- }
- else
- {
- value = new decimal((int)low64, (int)(low64 >> 32), (int)high, sign, (byte)-e);
- }
- return true;
- }
-
- internal static double ParseDouble(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info)
- {
- if (!TryParseDouble(value, styles, info, out double result))
- {
- ThrowOverflowOrFormatException(ParsingStatus.Failed);
- }
-
- return result;
- }
-
- internal static float ParseSingle(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info)
- {
- if (!TryParseSingle(value, styles, info, out float result))
- {
- ThrowOverflowOrFormatException(ParsingStatus.Failed);
- }
-
- return result;
- }
-
- internal static unsafe ParsingStatus TryParseDecimal(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out decimal result)
- {
- byte* pDigits = stackalloc byte[DecimalNumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.Decimal, pDigits, DecimalNumberBufferLength);
-
- result = 0;
-
- if (!TryStringToNumber(value, styles, ref number, info))
- {
- return ParsingStatus.Failed;
- }
-
- if (!TryNumberToDecimal(ref number, ref result))
- {
- return ParsingStatus.Overflow;
- }
-
- return ParsingStatus.OK;
- }
-
- internal static unsafe bool TryParseDouble(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out double result)
- {
- byte* pDigits = stackalloc byte[DoubleNumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.FloatingPoint, pDigits, DoubleNumberBufferLength);
-
- if (!TryStringToNumber(value, styles, ref number, info))
- {
- ReadOnlySpan<char> valueTrim = value.Trim();
-
- // This code would be simpler if we only had the concept of `InfinitySymbol`, but
- // we don't so we'll check the existing cases first and then handle `PositiveSign` +
- // `PositiveInfinitySymbol` and `PositiveSign/NegativeSign` + `NaNSymbol` last.
-
- if (valueTrim.EqualsOrdinalIgnoreCase(info.PositiveInfinitySymbol))
- {
- result = double.PositiveInfinity;
- }
- else if (valueTrim.EqualsOrdinalIgnoreCase(info.NegativeInfinitySymbol))
- {
- result = double.NegativeInfinity;
- }
- else if (valueTrim.EqualsOrdinalIgnoreCase(info.NaNSymbol))
- {
- result = double.NaN;
- }
- else if (valueTrim.StartsWith(info.PositiveSign, StringComparison.OrdinalIgnoreCase))
- {
- valueTrim = valueTrim.Slice(info.PositiveSign.Length);
-
- if (valueTrim.EqualsOrdinalIgnoreCase(info.PositiveInfinitySymbol))
- {
- result = double.PositiveInfinity;
- }
- else if (valueTrim.EqualsOrdinalIgnoreCase(info.NaNSymbol))
- {
- result = double.NaN;
- }
- else
- {
- result = 0;
- return false;
- }
- }
- else if (valueTrim.StartsWith(info.NegativeSign, StringComparison.OrdinalIgnoreCase) &&
- valueTrim.Slice(info.NegativeSign.Length).EqualsOrdinalIgnoreCase(info.NaNSymbol))
- {
- result = double.NaN;
- }
- else
- {
- result = 0;
- return false; // We really failed
- }
- }
- else
- {
- result = NumberToDouble(ref number);
- }
-
- return true;
- }
-
- internal static unsafe bool TryParseSingle(ReadOnlySpan<char> value, NumberStyles styles, NumberFormatInfo info, out float result)
- {
- byte* pDigits = stackalloc byte[SingleNumberBufferLength];
- NumberBuffer number = new NumberBuffer(NumberBufferKind.FloatingPoint, pDigits, SingleNumberBufferLength);
-
- if (!TryStringToNumber(value, styles, ref number, info))
- {
- ReadOnlySpan<char> valueTrim = value.Trim();
-
- // This code would be simpler if we only had the concept of `InfinitySymbol`, but
- // we don't so we'll check the existing cases first and then handle `PositiveSign` +
- // `PositiveInfinitySymbol` and `PositiveSign/NegativeSign` + `NaNSymbol` last.
- //
- // Additionally, since some cultures ("wo") actually define `PositiveInfinitySymbol`
- // to include `PositiveSign`, we need to check whether `PositiveInfinitySymbol` fits
- // that case so that we don't start parsing things like `++infini`.
-
- if (valueTrim.EqualsOrdinalIgnoreCase(info.PositiveInfinitySymbol))
- {
- result = float.PositiveInfinity;
- }
- else if (valueTrim.EqualsOrdinalIgnoreCase(info.NegativeInfinitySymbol))
- {
- result = float.NegativeInfinity;
- }
- else if (valueTrim.EqualsOrdinalIgnoreCase(info.NaNSymbol))
- {
- result = float.NaN;
- }
- else if (valueTrim.StartsWith(info.PositiveSign, StringComparison.OrdinalIgnoreCase))
- {
- valueTrim = valueTrim.Slice(info.PositiveSign.Length);
-
- if (!info.PositiveInfinitySymbol.StartsWith(info.PositiveSign, StringComparison.OrdinalIgnoreCase) && valueTrim.EqualsOrdinalIgnoreCase(info.PositiveInfinitySymbol))
- {
- result = float.PositiveInfinity;
- }
- else if (!info.NaNSymbol.StartsWith(info.PositiveSign, StringComparison.OrdinalIgnoreCase) && valueTrim.EqualsOrdinalIgnoreCase(info.NaNSymbol))
- {
- result = float.NaN;
- }
- else
- {
- result = 0;
- return false;
- }
- }
- else if (valueTrim.StartsWith(info.NegativeSign, StringComparison.OrdinalIgnoreCase) &&
- !info.NaNSymbol.StartsWith(info.NegativeSign, StringComparison.OrdinalIgnoreCase) &&
- valueTrim.Slice(info.NegativeSign.Length).EqualsOrdinalIgnoreCase(info.NaNSymbol))
- {
- result = float.NaN;
- }
- else
- {
- result = 0;
- return false; // We really failed
- }
- }
- else
- {
- result = NumberToSingle(ref number);
- }
-
- return true;
- }
-
- internal static unsafe bool TryStringToNumber(ReadOnlySpan<char> value, NumberStyles styles, ref NumberBuffer number, NumberFormatInfo info)
- {
- Debug.Assert(info != null);
- fixed (char* stringPointer = &MemoryMarshal.GetReference(value))
- {
- char* p = stringPointer;
- if (!TryParseNumber(ref p, p + value.Length, styles, ref number, info)
- || ((int)(p - stringPointer) < value.Length && !TrailingZeros(value, (int)(p - stringPointer))))
- {
- number.CheckConsistency();
- return false;
- }
- }
-
- number.CheckConsistency();
- return true;
- }
-
- private static bool TrailingZeros(ReadOnlySpan<char> value, int index)
- {
- // For compatibility, we need to allow trailing zeros at the end of a number string
- for (int i = index; (uint)i < (uint)value.Length; i++)
- {
- if (value[i] != '\0')
- {
- return false;
- }
- }
-
- return true;
- }
-
- private static bool IsSpaceReplacingChar(char c) => c == '\u00a0' || c == '\u202f';
-
- private static unsafe char* MatchChars(char* p, char* pEnd, string value)
- {
- Debug.Assert(p != null && pEnd != null && p <= pEnd && value != null);
- fixed (char* stringPointer = value)
- {
- char* str = stringPointer;
- if (*str != '\0')
- {
- // We only hurt the failure case
- // This fix is for French or Kazakh cultures. Since a user cannot type 0xA0 or 0x202F as a
- // space character we use 0x20 space character instead to mean the same.
- while (true)
- {
- char cp = p < pEnd ? *p : '\0';
- if (cp != *str && !(IsSpaceReplacingChar(*str) && cp == '\u0020'))
- {
- break;
- }
- p++;
- str++;
- if (*str == '\0')
- return p;
- }
- }
- }
-
- return null;
- }
-
- // Ternary op is a workaround for https://github.com/dotnet/coreclr/issues/914
- private static bool IsWhite(int ch) => ch == 0x20 || (uint)(ch - 0x09) <= (0x0D - 0x09) ? true : false;
-
- private static bool IsDigit(int ch) => ((uint)ch - '0') <= 9;
-
- internal enum ParsingStatus
- {
- OK,
- Failed,
- Overflow
- }
-
- [DoesNotReturn]
- internal static void ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type = 0) => throw GetException(status, type);
-
- [DoesNotReturn]
- internal static void ThrowOverflowException(TypeCode type) => throw GetException(ParsingStatus.Overflow, type);
-
- private static Exception GetException(ParsingStatus status, TypeCode type)
- {
- if (status == ParsingStatus.Failed)
- return new FormatException(SR.Format_InvalidString);
-
- string s;
- switch (type)
- {
- case TypeCode.SByte:
- s = SR.Overflow_SByte;
- break;
- case TypeCode.Byte:
- s = SR.Overflow_Byte;
- break;
- case TypeCode.Int16:
- s = SR.Overflow_Int16;
- break;
- case TypeCode.UInt16:
- s = SR.Overflow_UInt16;
- break;
- case TypeCode.Int32:
- s = SR.Overflow_Int32;
- break;
- case TypeCode.UInt32:
- s = SR.Overflow_UInt32;
- break;
- case TypeCode.Int64:
- s = SR.Overflow_Int64;
- break;
- case TypeCode.UInt64:
- s = SR.Overflow_UInt64;
- break;
- default:
- Debug.Assert(type == TypeCode.Decimal);
- s = SR.Overflow_Decimal;
- break;
- }
- return new OverflowException(s);
- }
-
- internal static double NumberToDouble(ref NumberBuffer number)
- {
- number.CheckConsistency();
- double result;
-
- if ((number.DigitsCount == 0) || (number.Scale < DoubleMinExponent))
- {
- result = 0;
- }
- else if (number.Scale > DoubleMaxExponent)
- {
- result = double.PositiveInfinity;
- }
- else
- {
- ulong bits = NumberToFloatingPointBits(ref number, in FloatingPointInfo.Double);
- result = BitConverter.Int64BitsToDouble((long)(bits));
- }
-
- return number.IsNegative ? -result : result;
- }
-
- internal static float NumberToSingle(ref NumberBuffer number)
- {
- number.CheckConsistency();
- float result;
-
- if ((number.DigitsCount == 0) || (number.Scale < SingleMinExponent))
- {
- result = 0;
- }
- else if (number.Scale > SingleMaxExponent)
- {
- result = float.PositiveInfinity;
- }
- else
- {
- uint bits = (uint)(NumberToFloatingPointBits(ref number, in FloatingPointInfo.Single));
- result = BitConverter.Int32BitsToSingle((int)(bits));
- }
-
- return number.IsNegative ? -result : result;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/BitOperations.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/BitOperations.cs
deleted file mode 100644
index b779ce0def1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/BitOperations.cs
+++ /dev/null
@@ -1,371 +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 System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics.X86;
-
-using Internal.Runtime.CompilerServices;
-
-// Some routines inspired by the Stanford Bit Twiddling Hacks by Sean Eron Anderson:
-// http://graphics.stanford.edu/~seander/bithacks.html
-
-namespace System.Numerics
-{
- /// <summary>
- /// Utility methods for intrinsic bit-twiddling operations.
- /// The methods use hardware intrinsics when available on the underlying platform,
- /// otherwise they use optimized software fallbacks.
- /// </summary>
- public static class BitOperations
- {
- // C# no-alloc optimization that directly wraps the data section of the dll (similar to string constants)
- // https://github.com/dotnet/roslyn/pull/24621
-
- private static ReadOnlySpan<byte> TrailingZeroCountDeBruijn => new byte[32]
- {
- 00, 01, 28, 02, 29, 14, 24, 03,
- 30, 22, 20, 15, 25, 17, 04, 08,
- 31, 27, 13, 23, 21, 19, 16, 07,
- 26, 12, 18, 06, 11, 05, 10, 09
- };
-
- private static ReadOnlySpan<byte> Log2DeBruijn => new byte[32]
- {
- 00, 09, 01, 10, 13, 21, 02, 29,
- 11, 14, 16, 18, 22, 25, 03, 30,
- 08, 12, 20, 28, 15, 17, 24, 07,
- 19, 27, 23, 06, 26, 05, 04, 31
- };
-
- /// <summary>
- /// Count the number of leading zero bits in a mask.
- /// Similar in behavior to the x86 instruction LZCNT.
- /// </summary>
- /// <param name="value">The value.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static int LeadingZeroCount(uint value)
- {
- if (Lzcnt.IsSupported)
- {
- // LZCNT contract is 0->32
- return (int)Lzcnt.LeadingZeroCount(value);
- }
-
- // Unguarded fallback contract is 0->31
- if (value == 0)
- {
- return 32;
- }
-
- return 31 - Log2SoftwareFallback(value);
- }
-
- /// <summary>
- /// Count the number of leading zero bits in a mask.
- /// Similar in behavior to the x86 instruction LZCNT.
- /// </summary>
- /// <param name="value">The value.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static int LeadingZeroCount(ulong value)
- {
- if (Lzcnt.X64.IsSupported)
- {
- // LZCNT contract is 0->64
- return (int)Lzcnt.X64.LeadingZeroCount(value);
- }
-
- uint hi = (uint)(value >> 32);
-
- if (hi == 0)
- {
- return 32 + LeadingZeroCount((uint)value);
- }
-
- return LeadingZeroCount(hi);
- }
-
- /// <summary>
- /// Returns the integer (floor) log of the specified value, base 2.
- /// Note that by convention, input value 0 returns 0 since Log(0) is undefined.
- /// </summary>
- /// <param name="value">The value.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static int Log2(uint value)
- {
- // value lzcnt actual expected
- // ..0000 32 0 0 (by convention, guard clause)
- // ..0001 31 31-31 0
- // ..0010 30 31-30 1
- // 0010.. 2 31-2 29
- // 0100.. 1 31-1 30
- // 1000.. 0 31-0 31
- if (Lzcnt.IsSupported)
- {
- // Enforce conventional contract 0->0 (Log(0) is undefined)
- if (value == 0)
- {
- return 0;
- }
-
- // LZCNT contract is 0->32
- return 31 - (int)Lzcnt.LeadingZeroCount(value);
- }
-
- // Fallback contract is 0->0
- return Log2SoftwareFallback(value);
- }
-
- /// <summary>
- /// Returns the integer (floor) log of the specified value, base 2.
- /// Note that by convention, input value 0 returns 0 since Log(0) is undefined.
- /// </summary>
- /// <param name="value">The value.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static int Log2(ulong value)
- {
- if (Lzcnt.X64.IsSupported)
- {
- // Enforce conventional contract 0->0 (Log(0) is undefined)
- if (value == 0)
- {
- return 0;
- }
-
- // LZCNT contract is 0->64
- return 63 - (int)Lzcnt.X64.LeadingZeroCount(value);
- }
-
- uint hi = (uint)(value >> 32);
-
- if (hi == 0)
- {
- return Log2((uint)value);
- }
-
- return 32 + Log2(hi);
- }
-
- /// <summary>
- /// Returns the integer (floor) log of the specified value, base 2.
- /// Note that by convention, input value 0 returns 0 since Log(0) is undefined.
- /// Does not directly use any hardware intrinsics, nor does it incur branching.
- /// </summary>
- /// <param name="value">The value.</param>
- private static int Log2SoftwareFallback(uint value)
- {
- // No AggressiveInlining due to large method size
- // Has conventional contract 0->0 (Log(0) is undefined)
-
- // Fill trailing zeros with ones, eg 00010010 becomes 00011111
- value |= value >> 01;
- value |= value >> 02;
- value |= value >> 04;
- value |= value >> 08;
- value |= value >> 16;
-
- // uint.MaxValue >> 27 is always in range [0 - 31] so we use Unsafe.AddByteOffset to avoid bounds check
- return Unsafe.AddByteOffset(
- // Using deBruijn sequence, k=2, n=5 (2^5=32) : 0b_0000_0111_1100_0100_1010_1100_1101_1101u
- ref MemoryMarshal.GetReference(Log2DeBruijn),
- // uint|long -> IntPtr cast on 32-bit platforms does expensive overflow checks not needed here
- (IntPtr)(int)((value * 0x07C4ACDDu) >> 27));
- }
-
- /// <summary>
- /// Returns the population count (number of bits set) of a mask.
- /// Similar in behavior to the x86 instruction POPCNT.
- /// </summary>
- /// <param name="value">The value.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static int PopCount(uint value)
- {
- if (Popcnt.IsSupported)
- {
- return (int)Popcnt.PopCount(value);
- }
-
- return SoftwareFallback(value);
-
- static int SoftwareFallback(uint value)
- {
- const uint c1 = 0x_55555555u;
- const uint c2 = 0x_33333333u;
- const uint c3 = 0x_0F0F0F0Fu;
- const uint c4 = 0x_01010101u;
-
- value -= (value >> 1) & c1;
- value = (value & c2) + ((value >> 2) & c2);
- value = (((value + (value >> 4)) & c3) * c4) >> 24;
-
- return (int)value;
- }
- }
-
- /// <summary>
- /// Returns the population count (number of bits set) of a mask.
- /// Similar in behavior to the x86 instruction POPCNT.
- /// </summary>
- /// <param name="value">The value.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static int PopCount(ulong value)
- {
- if (Popcnt.X64.IsSupported)
- {
- return (int)Popcnt.X64.PopCount(value);
- }
-
-#if BIT32
- return PopCount((uint)value) // lo
- + PopCount((uint)(value >> 32)); // hi
-#else
- return SoftwareFallback(value);
-
- static int SoftwareFallback(ulong value)
- {
- const ulong c1 = 0x_55555555_55555555ul;
- const ulong c2 = 0x_33333333_33333333ul;
- const ulong c3 = 0x_0F0F0F0F_0F0F0F0Ful;
- const ulong c4 = 0x_01010101_01010101ul;
-
- value -= (value >> 1) & c1;
- value = (value & c2) + ((value >> 2) & c2);
- value = (((value + (value >> 4)) & c3) * c4) >> 56;
-
- return (int)value;
- }
-#endif
- }
-
- /// <summary>
- /// Count the number of trailing zero bits in an integer value.
- /// Similar in behavior to the x86 instruction TZCNT.
- /// </summary>
- /// <param name="value">The value.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int TrailingZeroCount(int value)
- => TrailingZeroCount((uint)value);
-
- /// <summary>
- /// Count the number of trailing zero bits in an integer value.
- /// Similar in behavior to the x86 instruction TZCNT.
- /// </summary>
- /// <param name="value">The value.</param>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int TrailingZeroCount(uint value)
- {
- if (Bmi1.IsSupported)
- {
- // TZCNT contract is 0->32
- return (int)Bmi1.TrailingZeroCount(value);
- }
-
- // Unguarded fallback contract is 0->0
- if (value == 0)
- {
- return 32;
- }
-
- // uint.MaxValue >> 27 is always in range [0 - 31] so we use Unsafe.AddByteOffset to avoid bounds check
- return Unsafe.AddByteOffset(
- // Using deBruijn sequence, k=2, n=5 (2^5=32) : 0b_0000_0111_0111_1100_1011_0101_0011_0001u
- ref MemoryMarshal.GetReference(TrailingZeroCountDeBruijn),
- // uint|long -> IntPtr cast on 32-bit platforms does expensive overflow checks not needed here
- (IntPtr)(int)(((value & (uint)-(int)value) * 0x077CB531u) >> 27)); // Multi-cast mitigates redundant conv.u8
- }
-
- /// <summary>
- /// Count the number of trailing zero bits in a mask.
- /// Similar in behavior to the x86 instruction TZCNT.
- /// </summary>
- /// <param name="value">The value.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int TrailingZeroCount(long value)
- => TrailingZeroCount((ulong)value);
-
- /// <summary>
- /// Count the number of trailing zero bits in a mask.
- /// Similar in behavior to the x86 instruction TZCNT.
- /// </summary>
- /// <param name="value">The value.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static int TrailingZeroCount(ulong value)
- {
- if (Bmi1.X64.IsSupported)
- {
- // TZCNT contract is 0->64
- return (int)Bmi1.X64.TrailingZeroCount(value);
- }
-
- uint lo = (uint)value;
-
- if (lo == 0)
- {
- return 32 + TrailingZeroCount((uint)(value >> 32));
- }
-
- return TrailingZeroCount(lo);
- }
-
- /// <summary>
- /// Rotates the specified value left by the specified number of bits.
- /// Similar in behavior to the x86 instruction ROL.
- /// </summary>
- /// <param name="value">The value to rotate.</param>
- /// <param name="offset">The number of bits to rotate by.
- /// Any value outside the range [0..31] is treated as congruent mod 32.</param>
- /// <returns>The rotated value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static uint RotateLeft(uint value, int offset)
- => (value << offset) | (value >> (32 - offset));
-
- /// <summary>
- /// Rotates the specified value left by the specified number of bits.
- /// Similar in behavior to the x86 instruction ROL.
- /// </summary>
- /// <param name="value">The value to rotate.</param>
- /// <param name="offset">The number of bits to rotate by.
- /// Any value outside the range [0..63] is treated as congruent mod 64.</param>
- /// <returns>The rotated value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static ulong RotateLeft(ulong value, int offset)
- => (value << offset) | (value >> (64 - offset));
-
- /// <summary>
- /// Rotates the specified value right by the specified number of bits.
- /// Similar in behavior to the x86 instruction ROR.
- /// </summary>
- /// <param name="value">The value to rotate.</param>
- /// <param name="offset">The number of bits to rotate by.
- /// Any value outside the range [0..31] is treated as congruent mod 32.</param>
- /// <returns>The rotated value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static uint RotateRight(uint value, int offset)
- => (value >> offset) | (value << (32 - offset));
-
- /// <summary>
- /// Rotates the specified value right by the specified number of bits.
- /// Similar in behavior to the x86 instruction ROR.
- /// </summary>
- /// <param name="value">The value to rotate.</param>
- /// <param name="offset">The number of bits to rotate by.
- /// Any value outside the range [0..63] is treated as congruent mod 64.</param>
- /// <returns>The rotated value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static ulong RotateRight(ulong value, int offset)
- => (value >> offset) | (value << (64 - offset));
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/ConstantHelper.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/ConstantHelper.cs
deleted file mode 100644
index 72b39191842..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/ConstantHelper.cs
+++ /dev/null
@@ -1,143 +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.
-
-#nullable enable
-using System.Runtime.CompilerServices;
-
-namespace System.Numerics
-{
- internal static class ConstantHelper
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static byte GetByteWithAllBitsSet()
- {
- byte value = 0;
- unsafe
- {
- unchecked
- {
- *((byte*)&value) = (byte)0xff;
- }
- }
- return value;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static sbyte GetSByteWithAllBitsSet()
- {
- sbyte value = 0;
- unsafe
- {
- unchecked
- {
- *((sbyte*)&value) = (sbyte)0xff;
- }
- }
- return value;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ushort GetUInt16WithAllBitsSet()
- {
- ushort value = 0;
- unsafe
- {
- unchecked
- {
- *((ushort*)&value) = (ushort)0xffff;
- }
- }
- return value;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static short GetInt16WithAllBitsSet()
- {
- short value = 0;
- unsafe
- {
- unchecked
- {
- *((short*)&value) = (short)0xffff;
- }
- }
- return value;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static uint GetUInt32WithAllBitsSet()
- {
- uint value = 0;
- unsafe
- {
- unchecked
- {
- *((uint*)&value) = (uint)0xffffffff;
- }
- }
- return value;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int GetInt32WithAllBitsSet()
- {
- int value = 0;
- unsafe
- {
- unchecked
- {
- *((int*)&value) = (int)0xffffffff;
- }
- }
- return value;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ulong GetUInt64WithAllBitsSet()
- {
- ulong value = 0;
- unsafe
- {
- unchecked
- {
- *((ulong*)&value) = (ulong)0xffffffffffffffff;
- }
- }
- return value;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static long GetInt64WithAllBitsSet()
- {
- long value = 0;
- unsafe
- {
- unchecked
- {
- *((long*)&value) = (long)0xffffffffffffffff;
- }
- }
- return value;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float GetSingleWithAllBitsSet()
- {
- float value = 0;
- unsafe
- {
- unchecked
- {
- *((int*)&value) = (int)0xffffffff;
- }
- }
- return value;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static double GetDoubleWithAllBitsSet()
- {
- double value = 0;
- unsafe
- {
- unchecked
- {
- *((long*)&value) = (long)0xffffffffffffffff;
- }
- }
- return value;
- }
- }
-} \ No newline at end of file
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/ConstantHelper.tt b/netcore/System.Private.CoreLib/shared/System/Numerics/ConstantHelper.tt
deleted file mode 100644
index 4f44ba9f77e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/ConstantHelper.tt
+++ /dev/null
@@ -1,62 +0,0 @@
-<#@ template debug="true" hostSpecific="true" #>
-<#@ output extension=".cs" #>
-<#@ Assembly Name="System.Core.dll" #>
-<#@ Assembly Name="System.Xml.dll" #>
-<#@ Assembly Name="System.Xml.Linq.dll" #>
-<#@ Assembly Name="System.Windows.Forms.dll" #>
-<#@ import namespace="System" #>
-<#@ import namespace="System.IO" #>
-<#@ import namespace="System.Diagnostics" #>
-<#@ import namespace="System.Linq" #>
-<#@ import namespace="System.Xml.Linq" #>
-<#@ import namespace="System.Collections" #>
-<#@ import namespace="System.Collections.Generic" #>
-<#@ import namespace="System.Runtime.InteropServices" #>
-<#@ include file="GenerationConfig.ttinclude" #><# GenerateCopyrightHeader(); #>
-
-#nullable enable
-using System.Runtime.CompilerServices;
-
-namespace System.Numerics
-{
- internal static class ConstantHelper
- {
-<#
- foreach (var type in supportedTypes)
- {
- string hexValue = "0x" + new string('f', Marshal.SizeOf(type) * 2);
-#>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static <#= typeAliases[type] #> Get<#= type.Name #>WithAllBitsSet()
- {
- <#= typeAliases[type] #> value = 0;
- unsafe
- {
- unchecked
- {
- *((<#= typeAliases[GetIntegralEquivalent(type)] #>*)&value) = (<#= typeAliases[GetIntegralEquivalent(type)] #>)<#= hexValue #>;
- }
- }
- return value;
- }
-<#
- }
-#>
- }
-}<#+
- public Type GetIntegralEquivalent(Type type)
- {
- if (type == typeof(float))
- {
- return typeof(int);
- }
- else if (type == typeof(double))
- {
- return typeof(long);
- }
- else
- {
- return type;
- }
- }
-#>
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/GenerationConfig.ttinclude b/netcore/System.Private.CoreLib/shared/System/Numerics/GenerationConfig.ttinclude
deleted file mode 100644
index fa18bd36c41..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/GenerationConfig.ttinclude
+++ /dev/null
@@ -1,186 +0,0 @@
-<#@ import namespace="System.Linq" #>
-<#@ import namespace="System.Collections.Generic" #>
-<#@ import namespace="System.Text" #>
-<#+
- /* This file includes static data used as compilation configuration for the rest of the code generation.
- It is shared here to ensure that all generated code compiles with the same constants and configurations. */
-
- // The set of supported numeric types to compile
- public static Type[] supportedTypes = new[]
- {
- typeof(byte), typeof(sbyte), typeof(ushort), typeof(short),
- typeof(uint), typeof(int), typeof(ulong), typeof(long),
- typeof(float), typeof(double)
- };
-
- // The set of unsigned types, a subset of the above. Used for excluding from certain methods, i.e. Abs and Negate
- public static Type[] unsignedTypes = new[]
- {
- typeof(byte), typeof(ushort), typeof(uint), typeof(ulong)
- };
-
- public static Type[] integralTypes = new[]
- {
- typeof(byte), typeof(sbyte), typeof(ushort), typeof(short),
- typeof(uint), typeof(int), typeof(ulong), typeof(long)
- };
-
- public static Type[] nonClsCompliantTypes = new[]
- {
- typeof(sbyte), typeof(ushort), typeof(uint), typeof(ulong)
- };
-
- public static Dictionary<Type, string> typeAliases = new Dictionary<Type, string>()
- {
- { typeof(byte), "byte" },
- { typeof(sbyte), "sbyte" },
- { typeof(ushort), "ushort" },
- { typeof(short), "short" },
- { typeof(uint), "uint" },
- { typeof(int), "int" },
- { typeof(ulong), "ulong" },
- { typeof(long), "long" },
- { typeof(float), "float" },
- { typeof(double), "double" }
- };
-
- // The total register size, in bytes. 16 for SSE2, 32 for AVX, 64 for AVX512
- public static int totalSize = 16;
-
- /* General template helper procedures */
-
- // Returns the constructed register field name for the given type and index.
- public string GetRegisterFieldName(Type t, int index)
- {
- return "register." + t.Name.ToLowerInvariant() + "_" + index;
- }
-
- // Returns the number of fields for a given type, based on the current configuration's register size
- public int GetNumFields(Type t, int totalSize)
- {
- return totalSize / Marshal.SizeOf(t);
- }
-
- public static HashSet<Type> WidenableTypes { get; private set; } = new HashSet<Type>()
- {
- typeof(byte),
- typeof(ushort),
- typeof(uint),
- typeof(sbyte),
- typeof(short),
- typeof(int),
- typeof(float),
- };
-
- private static Dictionary<Type, Type> s_widenTargets = new Dictionary<Type, Type>()
- {
- { typeof(byte), typeof(ushort) },
- { typeof(ushort), typeof(uint) },
- { typeof(uint), typeof(ulong) },
- { typeof(sbyte), typeof(short) },
- { typeof(short), typeof(int) },
- { typeof(int), typeof(long) },
- { typeof(float), typeof(double) },
- };
-
- public Type GetWidenTarget(Type t)
- {
- Type target;
- if (!s_widenTargets.TryGetValue(t, out target))
- {
- throw new InvalidOperationException("No widen target for " + t.Name);
- }
-
- return target;
- }
-
- public static HashSet<Type> NarrowableTypes { get; private set; } = new HashSet<Type>()
- {
- typeof(ushort),
- typeof(uint),
- typeof(ulong),
- typeof(short),
- typeof(int),
- typeof(long),
- typeof(double),
- };
-
- private static Dictionary<Type, Type> s_narrowTargets = new Dictionary<Type, Type>()
- {
- { typeof(ulong), typeof(uint) },
- { typeof(uint), typeof(ushort) },
- { typeof(ushort), typeof(byte) },
- { typeof(long), typeof(int) },
- { typeof(int), typeof(short) },
- { typeof(short), typeof(sbyte) },
- { typeof(double), typeof(float) },
- };
-
- public Type GetNarrowTarget(Type t)
- {
- Type target;
- if (!s_narrowTargets.TryGetValue(t, out target))
- {
- throw new InvalidOperationException("No narrow target for " + t.Name);
- }
-
- return target;
- }
-
- public static List<KeyValuePair<Type, Type>> SameSizeConversionPairs = new List<KeyValuePair<Type, Type>>()
- {
- new KeyValuePair<Type, Type>(typeof(int), typeof(float)),
- new KeyValuePair<Type, Type>(typeof(uint), typeof(float)),
- new KeyValuePair<Type, Type>(typeof(long), typeof(double)),
- new KeyValuePair<Type, Type>(typeof(ulong), typeof(double)),
- new KeyValuePair<Type, Type>(typeof(float), typeof(int)),
- new KeyValuePair<Type, Type>(typeof(float), typeof(uint)),
- new KeyValuePair<Type, Type>(typeof(double), typeof(long)),
- new KeyValuePair<Type, Type>(typeof(double), typeof(ulong)),
- };
-
- public void GenerateCopyrightHeader()
- {
-#>// 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.
-<#+
- }
-
- public string GenerateIfStatementHeader(Type type)
- {
- string keyword = (type == supportedTypes[0]) ? "if" : "else if";
- return string.Format("{0} (typeof(T) == typeof({1}))", keyword, typeAliases[type]);
- }
-
- public string GenerateIfStatementHeader(Type type, IEnumerable<Type> allTypes)
- {
- string keyword = (type == allTypes.ToArray()[0]) ? "if" : "else if";
- return string.Format("{0} (typeof(T) == typeof({1}))", keyword, typeAliases[type]);
- }
-
- public string MakeTypeComparisonCondition(Type type)
- {
- return string.Format("(typeof(T) == typeof({0}))", typeAliases[type]);
- }
-
- public string GenerateIfConditionAllTypes(IEnumerable<Type> allTypes)
- {
- StringBuilder sbuilder = new StringBuilder();
- bool firstTime = true;
- foreach (var type in allTypes)
- {
- if (firstTime)
- {
- sbuilder.Append("if (").Append(MakeTypeComparisonCondition(type));
- firstTime = false;
- }
- else
- {
- sbuilder.AppendLine().Append(" || ").Append(MakeTypeComparisonCondition(type));
- }
- }
- sbuilder.Append(")");
- return sbuilder.ToString();
- }
-#>
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Hashing/HashHelpers.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Hashing/HashHelpers.cs
deleted file mode 100644
index fd9d708d367..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Hashing/HashHelpers.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Numerics.Hashing
-{
- internal static class HashHelpers
- {
- public static readonly int RandomSeed = new Random().Next(int.MinValue, int.MaxValue);
-
- public static int Combine(int h1, int h2)
- {
- // RyuJIT optimizes this to use the ROL instruction
- // Related GitHub pull request: dotnet/coreclr#1830
- uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27);
- return ((int)rol5 + h1) ^ h2;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Matrix3x2.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Matrix3x2.cs
deleted file mode 100644
index 4782e12cd70..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Matrix3x2.cs
+++ /dev/null
@@ -1,807 +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 System.Globalization;
-
-namespace System.Numerics
-{
- /// <summary>
- /// A structure encapsulating a 3x2 matrix.
- /// </summary>
- public struct Matrix3x2 : IEquatable<Matrix3x2>
- {
- private const float RotationEpsilon = 0.001f * MathF.PI / 180f; // 0.1% of a degree
-
- #region Public Fields
- /// <summary>
- /// The first element of the first row
- /// </summary>
- public float M11;
- /// <summary>
- /// The second element of the first row
- /// </summary>
- public float M12;
- /// <summary>
- /// The first element of the second row
- /// </summary>
- public float M21;
- /// <summary>
- /// The second element of the second row
- /// </summary>
- public float M22;
- /// <summary>
- /// The first element of the third row
- /// </summary>
- public float M31;
- /// <summary>
- /// The second element of the third row
- /// </summary>
- public float M32;
- #endregion Public Fields
-
- private static readonly Matrix3x2 _identity = new Matrix3x2
- (
- 1f, 0f,
- 0f, 1f,
- 0f, 0f
- );
-
- /// <summary>
- /// Returns the multiplicative identity matrix.
- /// </summary>
- public static Matrix3x2 Identity
- {
- get { return _identity; }
- }
-
- /// <summary>
- /// Returns whether the matrix is the identity matrix.
- /// </summary>
- public readonly bool IsIdentity
- {
- get
- {
- return M11 == 1f && M22 == 1f && // Check diagonal element first for early out.
- M12 == 0f &&
- M21 == 0f &&
- M31 == 0f && M32 == 0f;
- }
- }
-
- /// <summary>
- /// Gets or sets the translation component of this matrix.
- /// </summary>
- public Vector2 Translation
- {
- readonly get
- {
- return new Vector2(M31, M32);
- }
-
- set
- {
- M31 = value.X;
- M32 = value.Y;
- }
- }
-
- /// <summary>
- /// Constructs a Matrix3x2 from the given components.
- /// </summary>
- public Matrix3x2(float m11, float m12,
- float m21, float m22,
- float m31, float m32)
- {
- this.M11 = m11;
- this.M12 = m12;
- this.M21 = m21;
- this.M22 = m22;
- this.M31 = m31;
- this.M32 = m32;
- }
-
- /// <summary>
- /// Creates a translation matrix from the given vector.
- /// </summary>
- /// <param name="position">The translation position.</param>
- /// <returns>A translation matrix.</returns>
- public static Matrix3x2 CreateTranslation(Vector2 position)
- {
- Matrix3x2 result;
-
- result.M11 = 1.0f;
- result.M12 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = 1.0f;
-
- result.M31 = position.X;
- result.M32 = position.Y;
-
- return result;
- }
-
- /// <summary>
- /// Creates a translation matrix from the given X and Y components.
- /// </summary>
- /// <param name="xPosition">The X position.</param>
- /// <param name="yPosition">The Y position.</param>
- /// <returns>A translation matrix.</returns>
- public static Matrix3x2 CreateTranslation(float xPosition, float yPosition)
- {
- Matrix3x2 result;
-
- result.M11 = 1.0f;
- result.M12 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = 1.0f;
-
- result.M31 = xPosition;
- result.M32 = yPosition;
-
- return result;
- }
-
- /// <summary>
- /// Creates a scale matrix from the given X and Y components.
- /// </summary>
- /// <param name="xScale">Value to scale by on the X-axis.</param>
- /// <param name="yScale">Value to scale by on the Y-axis.</param>
- /// <returns>A scaling matrix.</returns>
- public static Matrix3x2 CreateScale(float xScale, float yScale)
- {
- Matrix3x2 result;
-
- result.M11 = xScale;
- result.M12 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = yScale;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a scale matrix that is offset by a given center point.
- /// </summary>
- /// <param name="xScale">Value to scale by on the X-axis.</param>
- /// <param name="yScale">Value to scale by on the Y-axis.</param>
- /// <param name="centerPoint">The center point.</param>
- /// <returns>A scaling matrix.</returns>
- public static Matrix3x2 CreateScale(float xScale, float yScale, Vector2 centerPoint)
- {
- Matrix3x2 result;
-
- float tx = centerPoint.X * (1 - xScale);
- float ty = centerPoint.Y * (1 - yScale);
-
- result.M11 = xScale;
- result.M12 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = yScale;
- result.M31 = tx;
- result.M32 = ty;
-
- return result;
- }
-
- /// <summary>
- /// Creates a scale matrix from the given vector scale.
- /// </summary>
- /// <param name="scales">The scale to use.</param>
- /// <returns>A scaling matrix.</returns>
- public static Matrix3x2 CreateScale(Vector2 scales)
- {
- Matrix3x2 result;
-
- result.M11 = scales.X;
- result.M12 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = scales.Y;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a scale matrix from the given vector scale with an offset from the given center point.
- /// </summary>
- /// <param name="scales">The scale to use.</param>
- /// <param name="centerPoint">The center offset.</param>
- /// <returns>A scaling matrix.</returns>
- public static Matrix3x2 CreateScale(Vector2 scales, Vector2 centerPoint)
- {
- Matrix3x2 result;
-
- float tx = centerPoint.X * (1 - scales.X);
- float ty = centerPoint.Y * (1 - scales.Y);
-
- result.M11 = scales.X;
- result.M12 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = scales.Y;
- result.M31 = tx;
- result.M32 = ty;
-
- return result;
- }
-
- /// <summary>
- /// Creates a scale matrix that scales uniformly with the given scale.
- /// </summary>
- /// <param name="scale">The uniform scale to use.</param>
- /// <returns>A scaling matrix.</returns>
- public static Matrix3x2 CreateScale(float scale)
- {
- Matrix3x2 result;
-
- result.M11 = scale;
- result.M12 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = scale;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a scale matrix that scales uniformly with the given scale with an offset from the given center.
- /// </summary>
- /// <param name="scale">The uniform scale to use.</param>
- /// <param name="centerPoint">The center offset.</param>
- /// <returns>A scaling matrix.</returns>
- public static Matrix3x2 CreateScale(float scale, Vector2 centerPoint)
- {
- Matrix3x2 result;
-
- float tx = centerPoint.X * (1 - scale);
- float ty = centerPoint.Y * (1 - scale);
-
- result.M11 = scale;
- result.M12 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = scale;
- result.M31 = tx;
- result.M32 = ty;
-
- return result;
- }
-
- /// <summary>
- /// Creates a skew matrix from the given angles in radians.
- /// </summary>
- /// <param name="radiansX">The X angle, in radians.</param>
- /// <param name="radiansY">The Y angle, in radians.</param>
- /// <returns>A skew matrix.</returns>
- public static Matrix3x2 CreateSkew(float radiansX, float radiansY)
- {
- Matrix3x2 result;
-
- float xTan = MathF.Tan(radiansX);
- float yTan = MathF.Tan(radiansY);
-
- result.M11 = 1.0f;
- result.M12 = yTan;
- result.M21 = xTan;
- result.M22 = 1.0f;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a skew matrix from the given angles in radians and a center point.
- /// </summary>
- /// <param name="radiansX">The X angle, in radians.</param>
- /// <param name="radiansY">The Y angle, in radians.</param>
- /// <param name="centerPoint">The center point.</param>
- /// <returns>A skew matrix.</returns>
- public static Matrix3x2 CreateSkew(float radiansX, float radiansY, Vector2 centerPoint)
- {
- Matrix3x2 result;
-
- float xTan = MathF.Tan(radiansX);
- float yTan = MathF.Tan(radiansY);
-
- float tx = -centerPoint.Y * xTan;
- float ty = -centerPoint.X * yTan;
-
- result.M11 = 1.0f;
- result.M12 = yTan;
- result.M21 = xTan;
- result.M22 = 1.0f;
- result.M31 = tx;
- result.M32 = ty;
-
- return result;
- }
-
- /// <summary>
- /// Creates a rotation matrix using the given rotation in radians.
- /// </summary>
- /// <param name="radians">The amount of rotation, in radians.</param>
- /// <returns>A rotation matrix.</returns>
- public static Matrix3x2 CreateRotation(float radians)
- {
- Matrix3x2 result;
-
- radians = MathF.IEEERemainder(radians, MathF.PI * 2);
-
- float c, s;
-
- if (radians > -RotationEpsilon && radians < RotationEpsilon)
- {
- // Exact case for zero rotation.
- c = 1;
- s = 0;
- }
- else if (radians > MathF.PI / 2 - RotationEpsilon && radians < MathF.PI / 2 + RotationEpsilon)
- {
- // Exact case for 90 degree rotation.
- c = 0;
- s = 1;
- }
- else if (radians < -MathF.PI + RotationEpsilon || radians > MathF.PI - RotationEpsilon)
- {
- // Exact case for 180 degree rotation.
- c = -1;
- s = 0;
- }
- else if (radians > -MathF.PI / 2 - RotationEpsilon && radians < -MathF.PI / 2 + RotationEpsilon)
- {
- // Exact case for 270 degree rotation.
- c = 0;
- s = -1;
- }
- else
- {
- // Arbitrary rotation.
- c = MathF.Cos(radians);
- s = MathF.Sin(radians);
- }
-
- // [ c s ]
- // [ -s c ]
- // [ 0 0 ]
- result.M11 = c;
- result.M12 = s;
- result.M21 = -s;
- result.M22 = c;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a rotation matrix using the given rotation in radians and a center point.
- /// </summary>
- /// <param name="radians">The amount of rotation, in radians.</param>
- /// <param name="centerPoint">The center point.</param>
- /// <returns>A rotation matrix.</returns>
- public static Matrix3x2 CreateRotation(float radians, Vector2 centerPoint)
- {
- Matrix3x2 result;
-
- radians = MathF.IEEERemainder(radians, MathF.PI * 2);
-
- float c, s;
-
- if (radians > -RotationEpsilon && radians < RotationEpsilon)
- {
- // Exact case for zero rotation.
- c = 1;
- s = 0;
- }
- else if (radians > MathF.PI / 2 - RotationEpsilon && radians < MathF.PI / 2 + RotationEpsilon)
- {
- // Exact case for 90 degree rotation.
- c = 0;
- s = 1;
- }
- else if (radians < -MathF.PI + RotationEpsilon || radians > MathF.PI - RotationEpsilon)
- {
- // Exact case for 180 degree rotation.
- c = -1;
- s = 0;
- }
- else if (radians > -MathF.PI / 2 - RotationEpsilon && radians < -MathF.PI / 2 + RotationEpsilon)
- {
- // Exact case for 270 degree rotation.
- c = 0;
- s = -1;
- }
- else
- {
- // Arbitrary rotation.
- c = MathF.Cos(radians);
- s = MathF.Sin(radians);
- }
-
- float x = centerPoint.X * (1 - c) + centerPoint.Y * s;
- float y = centerPoint.Y * (1 - c) - centerPoint.X * s;
-
- // [ c s ]
- // [ -s c ]
- // [ x y ]
- result.M11 = c;
- result.M12 = s;
- result.M21 = -s;
- result.M22 = c;
- result.M31 = x;
- result.M32 = y;
-
- return result;
- }
-
- /// <summary>
- /// Calculates the determinant for this matrix.
- /// The determinant is calculated by expanding the matrix with a third column whose values are (0,0,1).
- /// </summary>
- /// <returns>The determinant.</returns>
- public readonly float GetDeterminant()
- {
- // There isn't actually any such thing as a determinant for a non-square matrix,
- // but this 3x2 type is really just an optimization of a 3x3 where we happen to
- // know the rightmost column is always (0, 0, 1). So we expand to 3x3 format:
- //
- // [ M11, M12, 0 ]
- // [ M21, M22, 0 ]
- // [ M31, M32, 1 ]
- //
- // Sum the diagonal products:
- // (M11 * M22 * 1) + (M12 * 0 * M31) + (0 * M21 * M32)
- //
- // Subtract the opposite diagonal products:
- // (M31 * M22 * 0) + (M32 * 0 * M11) + (1 * M21 * M12)
- //
- // Collapse out the constants and oh look, this is just a 2x2 determinant!
-
- return (M11 * M22) - (M21 * M12);
- }
-
- /// <summary>
- /// Attempts to invert the given matrix. If the operation succeeds, the inverted matrix is stored in the result parameter.
- /// </summary>
- /// <param name="matrix">The source matrix.</param>
- /// <param name="result">The output matrix.</param>
- /// <returns>True if the operation succeeded, False otherwise.</returns>
- public static bool Invert(Matrix3x2 matrix, out Matrix3x2 result)
- {
- float det = (matrix.M11 * matrix.M22) - (matrix.M21 * matrix.M12);
-
- if (MathF.Abs(det) < float.Epsilon)
- {
- result = new Matrix3x2(float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN);
- return false;
- }
-
- float invDet = 1.0f / det;
-
- result.M11 = matrix.M22 * invDet;
- result.M12 = -matrix.M12 * invDet;
- result.M21 = -matrix.M21 * invDet;
- result.M22 = matrix.M11 * invDet;
- result.M31 = (matrix.M21 * matrix.M32 - matrix.M31 * matrix.M22) * invDet;
- result.M32 = (matrix.M31 * matrix.M12 - matrix.M11 * matrix.M32) * invDet;
-
- return true;
- }
-
- /// <summary>
- /// Linearly interpolates from matrix1 to matrix2, based on the third parameter.
- /// </summary>
- /// <param name="matrix1">The first source matrix.</param>
- /// <param name="matrix2">The second source matrix.</param>
- /// <param name="amount">The relative weighting of matrix2.</param>
- /// <returns>The interpolated matrix.</returns>
- public static Matrix3x2 Lerp(Matrix3x2 matrix1, Matrix3x2 matrix2, float amount)
- {
- Matrix3x2 result;
-
- // First row
- result.M11 = matrix1.M11 + (matrix2.M11 - matrix1.M11) * amount;
- result.M12 = matrix1.M12 + (matrix2.M12 - matrix1.M12) * amount;
-
- // Second row
- result.M21 = matrix1.M21 + (matrix2.M21 - matrix1.M21) * amount;
- result.M22 = matrix1.M22 + (matrix2.M22 - matrix1.M22) * amount;
-
- // Third row
- result.M31 = matrix1.M31 + (matrix2.M31 - matrix1.M31) * amount;
- result.M32 = matrix1.M32 + (matrix2.M32 - matrix1.M32) * amount;
-
- return result;
- }
-
- /// <summary>
- /// Negates the given matrix by multiplying all values by -1.
- /// </summary>
- /// <param name="value">The source matrix.</param>
- /// <returns>The negated matrix.</returns>
- public static Matrix3x2 Negate(Matrix3x2 value)
- {
- Matrix3x2 result;
-
- result.M11 = -value.M11;
- result.M12 = -value.M12;
- result.M21 = -value.M21;
- result.M22 = -value.M22;
- result.M31 = -value.M31;
- result.M32 = -value.M32;
-
- return result;
- }
-
- /// <summary>
- /// Adds each matrix element in value1 with its corresponding element in value2.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The matrix containing the summed values.</returns>
- public static Matrix3x2 Add(Matrix3x2 value1, Matrix3x2 value2)
- {
- Matrix3x2 result;
-
- result.M11 = value1.M11 + value2.M11;
- result.M12 = value1.M12 + value2.M12;
- result.M21 = value1.M21 + value2.M21;
- result.M22 = value1.M22 + value2.M22;
- result.M31 = value1.M31 + value2.M31;
- result.M32 = value1.M32 + value2.M32;
-
- return result;
- }
-
- /// <summary>
- /// Subtracts each matrix element in value2 from its corresponding element in value1.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The matrix containing the resulting values.</returns>
- public static Matrix3x2 Subtract(Matrix3x2 value1, Matrix3x2 value2)
- {
- Matrix3x2 result;
-
- result.M11 = value1.M11 - value2.M11;
- result.M12 = value1.M12 - value2.M12;
- result.M21 = value1.M21 - value2.M21;
- result.M22 = value1.M22 - value2.M22;
- result.M31 = value1.M31 - value2.M31;
- result.M32 = value1.M32 - value2.M32;
-
- return result;
- }
-
- /// <summary>
- /// Multiplies two matrices together and returns the resulting matrix.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The product matrix.</returns>
- public static Matrix3x2 Multiply(Matrix3x2 value1, Matrix3x2 value2)
- {
- Matrix3x2 result;
-
- // First row
- result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21;
- result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22;
-
- // Second row
- result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21;
- result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22;
-
- // Third row
- result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31;
- result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32;
-
- return result;
- }
-
- /// <summary>
- /// Scales all elements in a matrix by the given scalar factor.
- /// </summary>
- /// <param name="value1">The source matrix.</param>
- /// <param name="value2">The scaling value to use.</param>
- /// <returns>The resulting matrix.</returns>
- public static Matrix3x2 Multiply(Matrix3x2 value1, float value2)
- {
- Matrix3x2 result;
-
- result.M11 = value1.M11 * value2;
- result.M12 = value1.M12 * value2;
- result.M21 = value1.M21 * value2;
- result.M22 = value1.M22 * value2;
- result.M31 = value1.M31 * value2;
- result.M32 = value1.M32 * value2;
-
- return result;
- }
-
- /// <summary>
- /// Negates the given matrix by multiplying all values by -1.
- /// </summary>
- /// <param name="value">The source matrix.</param>
- /// <returns>The negated matrix.</returns>
- public static Matrix3x2 operator -(Matrix3x2 value)
- {
- Matrix3x2 m;
-
- m.M11 = -value.M11;
- m.M12 = -value.M12;
- m.M21 = -value.M21;
- m.M22 = -value.M22;
- m.M31 = -value.M31;
- m.M32 = -value.M32;
-
- return m;
- }
-
- /// <summary>
- /// Adds each matrix element in value1 with its corresponding element in value2.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The matrix containing the summed values.</returns>
- public static Matrix3x2 operator +(Matrix3x2 value1, Matrix3x2 value2)
- {
- Matrix3x2 m;
-
- m.M11 = value1.M11 + value2.M11;
- m.M12 = value1.M12 + value2.M12;
- m.M21 = value1.M21 + value2.M21;
- m.M22 = value1.M22 + value2.M22;
- m.M31 = value1.M31 + value2.M31;
- m.M32 = value1.M32 + value2.M32;
-
- return m;
- }
-
- /// <summary>
- /// Subtracts each matrix element in value2 from its corresponding element in value1.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The matrix containing the resulting values.</returns>
- public static Matrix3x2 operator -(Matrix3x2 value1, Matrix3x2 value2)
- {
- Matrix3x2 m;
-
- m.M11 = value1.M11 - value2.M11;
- m.M12 = value1.M12 - value2.M12;
- m.M21 = value1.M21 - value2.M21;
- m.M22 = value1.M22 - value2.M22;
- m.M31 = value1.M31 - value2.M31;
- m.M32 = value1.M32 - value2.M32;
-
- return m;
- }
-
- /// <summary>
- /// Multiplies two matrices together and returns the resulting matrix.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The product matrix.</returns>
- public static Matrix3x2 operator *(Matrix3x2 value1, Matrix3x2 value2)
- {
- Matrix3x2 m;
-
- // First row
- m.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21;
- m.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22;
-
- // Second row
- m.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21;
- m.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22;
-
- // Third row
- m.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31;
- m.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32;
-
- return m;
- }
-
- /// <summary>
- /// Scales all elements in a matrix by the given scalar factor.
- /// </summary>
- /// <param name="value1">The source matrix.</param>
- /// <param name="value2">The scaling value to use.</param>
- /// <returns>The resulting matrix.</returns>
- public static Matrix3x2 operator *(Matrix3x2 value1, float value2)
- {
- Matrix3x2 m;
-
- m.M11 = value1.M11 * value2;
- m.M12 = value1.M12 * value2;
- m.M21 = value1.M21 * value2;
- m.M22 = value1.M22 * value2;
- m.M31 = value1.M31 * value2;
- m.M32 = value1.M32 * value2;
-
- return m;
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given matrices are equal.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>True if the matrices are equal; False otherwise.</returns>
- public static bool operator ==(Matrix3x2 value1, Matrix3x2 value2)
- {
- return (value1.M11 == value2.M11 && value1.M22 == value2.M22 && // Check diagonal element first for early out.
- value1.M12 == value2.M12 &&
- value1.M21 == value2.M21 &&
- value1.M31 == value2.M31 && value1.M32 == value2.M32);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given matrices are not equal.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>True if the matrices are not equal; False if they are equal.</returns>
- public static bool operator !=(Matrix3x2 value1, Matrix3x2 value2)
- {
- return (value1.M11 != value2.M11 || value1.M12 != value2.M12 ||
- value1.M21 != value2.M21 || value1.M22 != value2.M22 ||
- value1.M31 != value2.M31 || value1.M32 != value2.M32);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the matrix is equal to the other given matrix.
- /// </summary>
- /// <param name="other">The other matrix to test equality against.</param>
- /// <returns>True if this matrix is equal to other; False otherwise.</returns>
- public readonly bool Equals(Matrix3x2 other)
- {
- return (M11 == other.M11 && M22 == other.M22 && // Check diagonal element first for early out.
- M12 == other.M12 &&
- M21 == other.M21 &&
- M31 == other.M31 && M32 == other.M32);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Object is equal to this matrix instance.
- /// </summary>
- /// <param name="obj">The Object to compare against.</param>
- /// <returns>True if the Object is equal to this matrix; False otherwise.</returns>
- public override readonly bool Equals(object? obj)
- {
- if (obj is Matrix3x2)
- {
- return Equals((Matrix3x2)obj);
- }
-
- return false;
- }
-
- /// <summary>
- /// Returns a String representing this matrix instance.
- /// </summary>
- /// <returns>The string representation.</returns>
- public override readonly string ToString()
- {
- return string.Format(CultureInfo.CurrentCulture, "{{ {{M11:{0} M12:{1}}} {{M21:{2} M22:{3}}} {{M31:{4} M32:{5}}} }}",
- M11, M12,
- M21, M22,
- M31, M32);
- }
-
- /// <summary>
- /// Returns the hash code for this instance.
- /// </summary>
- /// <returns>The hash code.</returns>
- public override readonly int GetHashCode()
- {
- return unchecked(M11.GetHashCode() + M12.GetHashCode() +
- M21.GetHashCode() + M22.GetHashCode() +
- M31.GetHashCode() + M32.GetHashCode());
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Matrix4x4.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Matrix4x4.cs
deleted file mode 100644
index e5cd43201d4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Matrix4x4.cs
+++ /dev/null
@@ -1,2208 +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 System.Globalization;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace System.Numerics
-{
- /// <summary>
- /// A structure encapsulating a 4x4 matrix.
- /// </summary>
- [StructLayout(LayoutKind.Sequential)]
- public struct Matrix4x4 : IEquatable<Matrix4x4>
- {
- private const float BillboardEpsilon = 1e-4f;
- private const float BillboardMinAngle = 1.0f - (0.1f * (MathF.PI / 180.0f)); // 0.1 degrees
- private const float DecomposeEpsilon = 0.0001f;
-
- #region Public Fields
- /// <summary>
- /// Value at row 1, column 1 of the matrix.
- /// </summary>
- public float M11;
- /// <summary>
- /// Value at row 1, column 2 of the matrix.
- /// </summary>
- public float M12;
- /// <summary>
- /// Value at row 1, column 3 of the matrix.
- /// </summary>
- public float M13;
- /// <summary>
- /// Value at row 1, column 4 of the matrix.
- /// </summary>
- public float M14;
-
- /// <summary>
- /// Value at row 2, column 1 of the matrix.
- /// </summary>
- public float M21;
- /// <summary>
- /// Value at row 2, column 2 of the matrix.
- /// </summary>
- public float M22;
- /// <summary>
- /// Value at row 2, column 3 of the matrix.
- /// </summary>
- public float M23;
- /// <summary>
- /// Value at row 2, column 4 of the matrix.
- /// </summary>
- public float M24;
-
- /// <summary>
- /// Value at row 3, column 1 of the matrix.
- /// </summary>
- public float M31;
- /// <summary>
- /// Value at row 3, column 2 of the matrix.
- /// </summary>
- public float M32;
- /// <summary>
- /// Value at row 3, column 3 of the matrix.
- /// </summary>
- public float M33;
- /// <summary>
- /// Value at row 3, column 4 of the matrix.
- /// </summary>
- public float M34;
-
- /// <summary>
- /// Value at row 4, column 1 of the matrix.
- /// </summary>
- public float M41;
- /// <summary>
- /// Value at row 4, column 2 of the matrix.
- /// </summary>
- public float M42;
- /// <summary>
- /// Value at row 4, column 3 of the matrix.
- /// </summary>
- public float M43;
- /// <summary>
- /// Value at row 4, column 4 of the matrix.
- /// </summary>
- public float M44;
- #endregion Public Fields
-
- private static readonly Matrix4x4 _identity = new Matrix4x4
- (
- 1f, 0f, 0f, 0f,
- 0f, 1f, 0f, 0f,
- 0f, 0f, 1f, 0f,
- 0f, 0f, 0f, 1f
- );
-
- /// <summary>
- /// Returns the multiplicative identity matrix.
- /// </summary>
- public static Matrix4x4 Identity
- {
- get { return _identity; }
- }
-
- /// <summary>
- /// Returns whether the matrix is the identity matrix.
- /// </summary>
- public readonly bool IsIdentity
- {
- get
- {
- return M11 == 1f && M22 == 1f && M33 == 1f && M44 == 1f && // Check diagonal element first for early out.
- M12 == 0f && M13 == 0f && M14 == 0f &&
- M21 == 0f && M23 == 0f && M24 == 0f &&
- M31 == 0f && M32 == 0f && M34 == 0f &&
- M41 == 0f && M42 == 0f && M43 == 0f;
- }
- }
-
- /// <summary>
- /// Gets or sets the translation component of this matrix.
- /// </summary>
- public Vector3 Translation
- {
- readonly get
- {
- return new Vector3(M41, M42, M43);
- }
- set
- {
- M41 = value.X;
- M42 = value.Y;
- M43 = value.Z;
- }
- }
-
- /// <summary>
- /// Constructs a Matrix4x4 from the given components.
- /// </summary>
- public Matrix4x4(float m11, float m12, float m13, float m14,
- float m21, float m22, float m23, float m24,
- float m31, float m32, float m33, float m34,
- float m41, float m42, float m43, float m44)
- {
- this.M11 = m11;
- this.M12 = m12;
- this.M13 = m13;
- this.M14 = m14;
-
- this.M21 = m21;
- this.M22 = m22;
- this.M23 = m23;
- this.M24 = m24;
-
- this.M31 = m31;
- this.M32 = m32;
- this.M33 = m33;
- this.M34 = m34;
-
- this.M41 = m41;
- this.M42 = m42;
- this.M43 = m43;
- this.M44 = m44;
- }
-
- /// <summary>
- /// Constructs a Matrix4x4 from the given Matrix3x2.
- /// </summary>
- /// <param name="value">The source Matrix3x2.</param>
- public Matrix4x4(Matrix3x2 value)
- {
- M11 = value.M11;
- M12 = value.M12;
- M13 = 0f;
- M14 = 0f;
- M21 = value.M21;
- M22 = value.M22;
- M23 = 0f;
- M24 = 0f;
- M31 = 0f;
- M32 = 0f;
- M33 = 1f;
- M34 = 0f;
- M41 = value.M31;
- M42 = value.M32;
- M43 = 0f;
- M44 = 1f;
- }
-
- /// <summary>
- /// Creates a spherical billboard that rotates around a specified object position.
- /// </summary>
- /// <param name="objectPosition">Position of the object the billboard will rotate around.</param>
- /// <param name="cameraPosition">Position of the camera.</param>
- /// <param name="cameraUpVector">The up vector of the camera.</param>
- /// <param name="cameraForwardVector">The forward vector of the camera.</param>
- /// <returns>The created billboard matrix</returns>
- public static Matrix4x4 CreateBillboard(Vector3 objectPosition, Vector3 cameraPosition, Vector3 cameraUpVector, Vector3 cameraForwardVector)
- {
- Vector3 zaxis = new Vector3(
- objectPosition.X - cameraPosition.X,
- objectPosition.Y - cameraPosition.Y,
- objectPosition.Z - cameraPosition.Z);
-
- float norm = zaxis.LengthSquared();
-
- if (norm < BillboardEpsilon)
- {
- zaxis = -cameraForwardVector;
- }
- else
- {
- zaxis = Vector3.Multiply(zaxis, 1.0f / MathF.Sqrt(norm));
- }
-
- Vector3 xaxis = Vector3.Normalize(Vector3.Cross(cameraUpVector, zaxis));
-
- Vector3 yaxis = Vector3.Cross(zaxis, xaxis);
-
- Matrix4x4 result;
-
- result.M11 = xaxis.X;
- result.M12 = xaxis.Y;
- result.M13 = xaxis.Z;
- result.M14 = 0.0f;
- result.M21 = yaxis.X;
- result.M22 = yaxis.Y;
- result.M23 = yaxis.Z;
- result.M24 = 0.0f;
- result.M31 = zaxis.X;
- result.M32 = zaxis.Y;
- result.M33 = zaxis.Z;
- result.M34 = 0.0f;
-
- result.M41 = objectPosition.X;
- result.M42 = objectPosition.Y;
- result.M43 = objectPosition.Z;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a cylindrical billboard that rotates around a specified axis.
- /// </summary>
- /// <param name="objectPosition">Position of the object the billboard will rotate around.</param>
- /// <param name="cameraPosition">Position of the camera.</param>
- /// <param name="rotateAxis">Axis to rotate the billboard around.</param>
- /// <param name="cameraForwardVector">Forward vector of the camera.</param>
- /// <param name="objectForwardVector">Forward vector of the object.</param>
- /// <returns>The created billboard matrix.</returns>
- public static Matrix4x4 CreateConstrainedBillboard(Vector3 objectPosition, Vector3 cameraPosition, Vector3 rotateAxis, Vector3 cameraForwardVector, Vector3 objectForwardVector)
- {
- // Treat the case when object and camera positions are too close.
- Vector3 faceDir = new Vector3(
- objectPosition.X - cameraPosition.X,
- objectPosition.Y - cameraPosition.Y,
- objectPosition.Z - cameraPosition.Z);
-
- float norm = faceDir.LengthSquared();
-
- if (norm < BillboardEpsilon)
- {
- faceDir = -cameraForwardVector;
- }
- else
- {
- faceDir = Vector3.Multiply(faceDir, (1.0f / MathF.Sqrt(norm)));
- }
-
- Vector3 yaxis = rotateAxis;
- Vector3 xaxis;
- Vector3 zaxis;
-
- // Treat the case when angle between faceDir and rotateAxis is too close to 0.
- float dot = Vector3.Dot(rotateAxis, faceDir);
-
- if (MathF.Abs(dot) > BillboardMinAngle)
- {
- zaxis = objectForwardVector;
-
- // Make sure passed values are useful for compute.
- dot = Vector3.Dot(rotateAxis, zaxis);
-
- if (MathF.Abs(dot) > BillboardMinAngle)
- {
- zaxis = (MathF.Abs(rotateAxis.Z) > BillboardMinAngle) ? new Vector3(1, 0, 0) : new Vector3(0, 0, -1);
- }
-
- xaxis = Vector3.Normalize(Vector3.Cross(rotateAxis, zaxis));
- zaxis = Vector3.Normalize(Vector3.Cross(xaxis, rotateAxis));
- }
- else
- {
- xaxis = Vector3.Normalize(Vector3.Cross(rotateAxis, faceDir));
- zaxis = Vector3.Normalize(Vector3.Cross(xaxis, yaxis));
- }
-
- Matrix4x4 result;
-
- result.M11 = xaxis.X;
- result.M12 = xaxis.Y;
- result.M13 = xaxis.Z;
- result.M14 = 0.0f;
- result.M21 = yaxis.X;
- result.M22 = yaxis.Y;
- result.M23 = yaxis.Z;
- result.M24 = 0.0f;
- result.M31 = zaxis.X;
- result.M32 = zaxis.Y;
- result.M33 = zaxis.Z;
- result.M34 = 0.0f;
-
- result.M41 = objectPosition.X;
- result.M42 = objectPosition.Y;
- result.M43 = objectPosition.Z;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a translation matrix.
- /// </summary>
- /// <param name="position">The amount to translate in each axis.</param>
- /// <returns>The translation matrix.</returns>
- public static Matrix4x4 CreateTranslation(Vector3 position)
- {
- Matrix4x4 result;
-
- result.M11 = 1.0f;
- result.M12 = 0.0f;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = 1.0f;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
- result.M33 = 1.0f;
- result.M34 = 0.0f;
-
- result.M41 = position.X;
- result.M42 = position.Y;
- result.M43 = position.Z;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a translation matrix.
- /// </summary>
- /// <param name="xPosition">The amount to translate on the X-axis.</param>
- /// <param name="yPosition">The amount to translate on the Y-axis.</param>
- /// <param name="zPosition">The amount to translate on the Z-axis.</param>
- /// <returns>The translation matrix.</returns>
- public static Matrix4x4 CreateTranslation(float xPosition, float yPosition, float zPosition)
- {
- Matrix4x4 result;
-
- result.M11 = 1.0f;
- result.M12 = 0.0f;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = 1.0f;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
- result.M33 = 1.0f;
- result.M34 = 0.0f;
-
- result.M41 = xPosition;
- result.M42 = yPosition;
- result.M43 = zPosition;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a scaling matrix.
- /// </summary>
- /// <param name="xScale">Value to scale by on the X-axis.</param>
- /// <param name="yScale">Value to scale by on the Y-axis.</param>
- /// <param name="zScale">Value to scale by on the Z-axis.</param>
- /// <returns>The scaling matrix.</returns>
- public static Matrix4x4 CreateScale(float xScale, float yScale, float zScale)
- {
- Matrix4x4 result;
-
- result.M11 = xScale;
- result.M12 = 0.0f;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = yScale;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
- result.M33 = zScale;
- result.M34 = 0.0f;
- result.M41 = 0.0f;
- result.M42 = 0.0f;
- result.M43 = 0.0f;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a scaling matrix with a center point.
- /// </summary>
- /// <param name="xScale">Value to scale by on the X-axis.</param>
- /// <param name="yScale">Value to scale by on the Y-axis.</param>
- /// <param name="zScale">Value to scale by on the Z-axis.</param>
- /// <param name="centerPoint">The center point.</param>
- /// <returns>The scaling matrix.</returns>
- public static Matrix4x4 CreateScale(float xScale, float yScale, float zScale, Vector3 centerPoint)
- {
- Matrix4x4 result;
-
- float tx = centerPoint.X * (1 - xScale);
- float ty = centerPoint.Y * (1 - yScale);
- float tz = centerPoint.Z * (1 - zScale);
-
- result.M11 = xScale;
- result.M12 = 0.0f;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = yScale;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
- result.M33 = zScale;
- result.M34 = 0.0f;
- result.M41 = tx;
- result.M42 = ty;
- result.M43 = tz;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a scaling matrix.
- /// </summary>
- /// <param name="scales">The vector containing the amount to scale by on each axis.</param>
- /// <returns>The scaling matrix.</returns>
- public static Matrix4x4 CreateScale(Vector3 scales)
- {
- Matrix4x4 result;
-
- result.M11 = scales.X;
- result.M12 = 0.0f;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = scales.Y;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
- result.M33 = scales.Z;
- result.M34 = 0.0f;
- result.M41 = 0.0f;
- result.M42 = 0.0f;
- result.M43 = 0.0f;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a scaling matrix with a center point.
- /// </summary>
- /// <param name="scales">The vector containing the amount to scale by on each axis.</param>
- /// <param name="centerPoint">The center point.</param>
- /// <returns>The scaling matrix.</returns>
- public static Matrix4x4 CreateScale(Vector3 scales, Vector3 centerPoint)
- {
- Matrix4x4 result;
-
- float tx = centerPoint.X * (1 - scales.X);
- float ty = centerPoint.Y * (1 - scales.Y);
- float tz = centerPoint.Z * (1 - scales.Z);
-
- result.M11 = scales.X;
- result.M12 = 0.0f;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = scales.Y;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
- result.M33 = scales.Z;
- result.M34 = 0.0f;
- result.M41 = tx;
- result.M42 = ty;
- result.M43 = tz;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a uniform scaling matrix that scales equally on each axis.
- /// </summary>
- /// <param name="scale">The uniform scaling factor.</param>
- /// <returns>The scaling matrix.</returns>
- public static Matrix4x4 CreateScale(float scale)
- {
- Matrix4x4 result;
-
- result.M11 = scale;
- result.M12 = 0.0f;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = scale;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
- result.M33 = scale;
- result.M34 = 0.0f;
- result.M41 = 0.0f;
- result.M42 = 0.0f;
- result.M43 = 0.0f;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a uniform scaling matrix that scales equally on each axis with a center point.
- /// </summary>
- /// <param name="scale">The uniform scaling factor.</param>
- /// <param name="centerPoint">The center point.</param>
- /// <returns>The scaling matrix.</returns>
- public static Matrix4x4 CreateScale(float scale, Vector3 centerPoint)
- {
- Matrix4x4 result;
-
- float tx = centerPoint.X * (1 - scale);
- float ty = centerPoint.Y * (1 - scale);
- float tz = centerPoint.Z * (1 - scale);
-
- result.M11 = scale;
- result.M12 = 0.0f;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = scale;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
- result.M33 = scale;
- result.M34 = 0.0f;
- result.M41 = tx;
- result.M42 = ty;
- result.M43 = tz;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a matrix for rotating points around the X-axis.
- /// </summary>
- /// <param name="radians">The amount, in radians, by which to rotate around the X-axis.</param>
- /// <returns>The rotation matrix.</returns>
- public static Matrix4x4 CreateRotationX(float radians)
- {
- Matrix4x4 result;
-
- float c = MathF.Cos(radians);
- float s = MathF.Sin(radians);
-
- // [ 1 0 0 0 ]
- // [ 0 c s 0 ]
- // [ 0 -s c 0 ]
- // [ 0 0 0 1 ]
- result.M11 = 1.0f;
- result.M12 = 0.0f;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = c;
- result.M23 = s;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = -s;
- result.M33 = c;
- result.M34 = 0.0f;
- result.M41 = 0.0f;
- result.M42 = 0.0f;
- result.M43 = 0.0f;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a matrix for rotating points around the X-axis, from a center point.
- /// </summary>
- /// <param name="radians">The amount, in radians, by which to rotate around the X-axis.</param>
- /// <param name="centerPoint">The center point.</param>
- /// <returns>The rotation matrix.</returns>
- public static Matrix4x4 CreateRotationX(float radians, Vector3 centerPoint)
- {
- Matrix4x4 result;
-
- float c = MathF.Cos(radians);
- float s = MathF.Sin(radians);
-
- float y = centerPoint.Y * (1 - c) + centerPoint.Z * s;
- float z = centerPoint.Z * (1 - c) - centerPoint.Y * s;
-
- // [ 1 0 0 0 ]
- // [ 0 c s 0 ]
- // [ 0 -s c 0 ]
- // [ 0 y z 1 ]
- result.M11 = 1.0f;
- result.M12 = 0.0f;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = c;
- result.M23 = s;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = -s;
- result.M33 = c;
- result.M34 = 0.0f;
- result.M41 = 0.0f;
- result.M42 = y;
- result.M43 = z;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a matrix for rotating points around the Y-axis.
- /// </summary>
- /// <param name="radians">The amount, in radians, by which to rotate around the Y-axis.</param>
- /// <returns>The rotation matrix.</returns>
- public static Matrix4x4 CreateRotationY(float radians)
- {
- Matrix4x4 result;
-
- float c = MathF.Cos(radians);
- float s = MathF.Sin(radians);
-
- // [ c 0 -s 0 ]
- // [ 0 1 0 0 ]
- // [ s 0 c 0 ]
- // [ 0 0 0 1 ]
- result.M11 = c;
- result.M12 = 0.0f;
- result.M13 = -s;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = 1.0f;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = s;
- result.M32 = 0.0f;
- result.M33 = c;
- result.M34 = 0.0f;
- result.M41 = 0.0f;
- result.M42 = 0.0f;
- result.M43 = 0.0f;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a matrix for rotating points around the Y-axis, from a center point.
- /// </summary>
- /// <param name="radians">The amount, in radians, by which to rotate around the Y-axis.</param>
- /// <param name="centerPoint">The center point.</param>
- /// <returns>The rotation matrix.</returns>
- public static Matrix4x4 CreateRotationY(float radians, Vector3 centerPoint)
- {
- Matrix4x4 result;
-
- float c = MathF.Cos(radians);
- float s = MathF.Sin(radians);
-
- float x = centerPoint.X * (1 - c) - centerPoint.Z * s;
- float z = centerPoint.Z * (1 - c) + centerPoint.X * s;
-
- // [ c 0 -s 0 ]
- // [ 0 1 0 0 ]
- // [ s 0 c 0 ]
- // [ x 0 z 1 ]
- result.M11 = c;
- result.M12 = 0.0f;
- result.M13 = -s;
- result.M14 = 0.0f;
- result.M21 = 0.0f;
- result.M22 = 1.0f;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = s;
- result.M32 = 0.0f;
- result.M33 = c;
- result.M34 = 0.0f;
- result.M41 = x;
- result.M42 = 0.0f;
- result.M43 = z;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a matrix for rotating points around the Z-axis.
- /// </summary>
- /// <param name="radians">The amount, in radians, by which to rotate around the Z-axis.</param>
- /// <returns>The rotation matrix.</returns>
- public static Matrix4x4 CreateRotationZ(float radians)
- {
- Matrix4x4 result;
-
- float c = MathF.Cos(radians);
- float s = MathF.Sin(radians);
-
- // [ c s 0 0 ]
- // [ -s c 0 0 ]
- // [ 0 0 1 0 ]
- // [ 0 0 0 1 ]
- result.M11 = c;
- result.M12 = s;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = -s;
- result.M22 = c;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
- result.M33 = 1.0f;
- result.M34 = 0.0f;
- result.M41 = 0.0f;
- result.M42 = 0.0f;
- result.M43 = 0.0f;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a matrix for rotating points around the Z-axis, from a center point.
- /// </summary>
- /// <param name="radians">The amount, in radians, by which to rotate around the Z-axis.</param>
- /// <param name="centerPoint">The center point.</param>
- /// <returns>The rotation matrix.</returns>
- public static Matrix4x4 CreateRotationZ(float radians, Vector3 centerPoint)
- {
- Matrix4x4 result;
-
- float c = MathF.Cos(radians);
- float s = MathF.Sin(radians);
-
- float x = centerPoint.X * (1 - c) + centerPoint.Y * s;
- float y = centerPoint.Y * (1 - c) - centerPoint.X * s;
-
- // [ c s 0 0 ]
- // [ -s c 0 0 ]
- // [ 0 0 1 0 ]
- // [ x y 0 1 ]
- result.M11 = c;
- result.M12 = s;
- result.M13 = 0.0f;
- result.M14 = 0.0f;
- result.M21 = -s;
- result.M22 = c;
- result.M23 = 0.0f;
- result.M24 = 0.0f;
- result.M31 = 0.0f;
- result.M32 = 0.0f;
- result.M33 = 1.0f;
- result.M34 = 0.0f;
- result.M41 = x;
- result.M42 = y;
- result.M43 = 0.0f;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a matrix that rotates around an arbitrary vector.
- /// </summary>
- /// <param name="axis">The axis to rotate around.</param>
- /// <param name="angle">The angle to rotate around the given axis, in radians.</param>
- /// <returns>The rotation matrix.</returns>
- public static Matrix4x4 CreateFromAxisAngle(Vector3 axis, float angle)
- {
- // a: angle
- // x, y, z: unit vector for axis.
- //
- // Rotation matrix M can compute by using below equation.
- //
- // T T
- // M = uu + (cos a)( I-uu ) + (sin a)S
- //
- // Where:
- //
- // u = ( x, y, z )
- //
- // [ 0 -z y ]
- // S = [ z 0 -x ]
- // [ -y x 0 ]
- //
- // [ 1 0 0 ]
- // I = [ 0 1 0 ]
- // [ 0 0 1 ]
- //
- //
- // [ xx+cosa*(1-xx) yx-cosa*yx-sina*z zx-cosa*xz+sina*y ]
- // M = [ xy-cosa*yx+sina*z yy+cosa(1-yy) yz-cosa*yz-sina*x ]
- // [ zx-cosa*zx-sina*y zy-cosa*zy+sina*x zz+cosa*(1-zz) ]
- //
- float x = axis.X, y = axis.Y, z = axis.Z;
- float sa = MathF.Sin(angle), ca = MathF.Cos(angle);
- float xx = x * x, yy = y * y, zz = z * z;
- float xy = x * y, xz = x * z, yz = y * z;
-
- Matrix4x4 result;
-
- result.M11 = xx + ca * (1.0f - xx);
- result.M12 = xy - ca * xy + sa * z;
- result.M13 = xz - ca * xz - sa * y;
- result.M14 = 0.0f;
- result.M21 = xy - ca * xy - sa * z;
- result.M22 = yy + ca * (1.0f - yy);
- result.M23 = yz - ca * yz + sa * x;
- result.M24 = 0.0f;
- result.M31 = xz - ca * xz + sa * y;
- result.M32 = yz - ca * yz - sa * x;
- result.M33 = zz + ca * (1.0f - zz);
- result.M34 = 0.0f;
- result.M41 = 0.0f;
- result.M42 = 0.0f;
- result.M43 = 0.0f;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a perspective projection matrix based on a field of view, aspect ratio, and near and far view plane distances.
- /// </summary>
- /// <param name="fieldOfView">Field of view in the y direction, in radians.</param>
- /// <param name="aspectRatio">Aspect ratio, defined as view space width divided by height.</param>
- /// <param name="nearPlaneDistance">Distance to the near view plane.</param>
- /// <param name="farPlaneDistance">Distance to the far view plane.</param>
- /// <returns>The perspective projection matrix.</returns>
- public static Matrix4x4 CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance)
- {
- if (fieldOfView <= 0.0f || fieldOfView >= MathF.PI)
- throw new ArgumentOutOfRangeException(nameof(fieldOfView));
-
- if (nearPlaneDistance <= 0.0f)
- throw new ArgumentOutOfRangeException(nameof(nearPlaneDistance));
-
- if (farPlaneDistance <= 0.0f)
- throw new ArgumentOutOfRangeException(nameof(farPlaneDistance));
-
- if (nearPlaneDistance >= farPlaneDistance)
- throw new ArgumentOutOfRangeException(nameof(nearPlaneDistance));
-
- float yScale = 1.0f / MathF.Tan(fieldOfView * 0.5f);
- float xScale = yScale / aspectRatio;
-
- Matrix4x4 result;
-
- result.M11 = xScale;
- result.M12 = result.M13 = result.M14 = 0.0f;
-
- result.M22 = yScale;
- result.M21 = result.M23 = result.M24 = 0.0f;
-
- result.M31 = result.M32 = 0.0f;
- var negFarRange = float.IsPositiveInfinity(farPlaneDistance) ? -1.0f : farPlaneDistance / (nearPlaneDistance - farPlaneDistance);
- result.M33 = negFarRange;
- result.M34 = -1.0f;
-
- result.M41 = result.M42 = result.M44 = 0.0f;
- result.M43 = nearPlaneDistance * negFarRange;
-
- return result;
- }
-
- /// <summary>
- /// Creates a perspective projection matrix from the given view volume dimensions.
- /// </summary>
- /// <param name="width">Width of the view volume at the near view plane.</param>
- /// <param name="height">Height of the view volume at the near view plane.</param>
- /// <param name="nearPlaneDistance">Distance to the near view plane.</param>
- /// <param name="farPlaneDistance">Distance to the far view plane.</param>
- /// <returns>The perspective projection matrix.</returns>
- public static Matrix4x4 CreatePerspective(float width, float height, float nearPlaneDistance, float farPlaneDistance)
- {
- if (nearPlaneDistance <= 0.0f)
- throw new ArgumentOutOfRangeException(nameof(nearPlaneDistance));
-
- if (farPlaneDistance <= 0.0f)
- throw new ArgumentOutOfRangeException(nameof(farPlaneDistance));
-
- if (nearPlaneDistance >= farPlaneDistance)
- throw new ArgumentOutOfRangeException(nameof(nearPlaneDistance));
-
- Matrix4x4 result;
-
- result.M11 = 2.0f * nearPlaneDistance / width;
- result.M12 = result.M13 = result.M14 = 0.0f;
-
- result.M22 = 2.0f * nearPlaneDistance / height;
- result.M21 = result.M23 = result.M24 = 0.0f;
-
- var negFarRange = float.IsPositiveInfinity(farPlaneDistance) ? -1.0f : farPlaneDistance / (nearPlaneDistance - farPlaneDistance);
- result.M33 = negFarRange;
- result.M31 = result.M32 = 0.0f;
- result.M34 = -1.0f;
-
- result.M41 = result.M42 = result.M44 = 0.0f;
- result.M43 = nearPlaneDistance * negFarRange;
-
- return result;
- }
-
- /// <summary>
- /// Creates a customized, perspective projection matrix.
- /// </summary>
- /// <param name="left">Minimum x-value of the view volume at the near view plane.</param>
- /// <param name="right">Maximum x-value of the view volume at the near view plane.</param>
- /// <param name="bottom">Minimum y-value of the view volume at the near view plane.</param>
- /// <param name="top">Maximum y-value of the view volume at the near view plane.</param>
- /// <param name="nearPlaneDistance">Distance to the near view plane.</param>
- /// <param name="farPlaneDistance">Distance to of the far view plane.</param>
- /// <returns>The perspective projection matrix.</returns>
- public static Matrix4x4 CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlaneDistance, float farPlaneDistance)
- {
- if (nearPlaneDistance <= 0.0f)
- throw new ArgumentOutOfRangeException(nameof(nearPlaneDistance));
-
- if (farPlaneDistance <= 0.0f)
- throw new ArgumentOutOfRangeException(nameof(farPlaneDistance));
-
- if (nearPlaneDistance >= farPlaneDistance)
- throw new ArgumentOutOfRangeException(nameof(nearPlaneDistance));
-
- Matrix4x4 result;
-
- result.M11 = 2.0f * nearPlaneDistance / (right - left);
- result.M12 = result.M13 = result.M14 = 0.0f;
-
- result.M22 = 2.0f * nearPlaneDistance / (top - bottom);
- result.M21 = result.M23 = result.M24 = 0.0f;
-
- result.M31 = (left + right) / (right - left);
- result.M32 = (top + bottom) / (top - bottom);
- var negFarRange = float.IsPositiveInfinity(farPlaneDistance) ? -1.0f : farPlaneDistance / (nearPlaneDistance - farPlaneDistance);
- result.M33 = negFarRange;
- result.M34 = -1.0f;
-
- result.M43 = nearPlaneDistance * negFarRange;
- result.M41 = result.M42 = result.M44 = 0.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates an orthographic perspective matrix from the given view volume dimensions.
- /// </summary>
- /// <param name="width">Width of the view volume.</param>
- /// <param name="height">Height of the view volume.</param>
- /// <param name="zNearPlane">Minimum Z-value of the view volume.</param>
- /// <param name="zFarPlane">Maximum Z-value of the view volume.</param>
- /// <returns>The orthographic projection matrix.</returns>
- public static Matrix4x4 CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane)
- {
- Matrix4x4 result;
-
- result.M11 = 2.0f / width;
- result.M12 = result.M13 = result.M14 = 0.0f;
-
- result.M22 = 2.0f / height;
- result.M21 = result.M23 = result.M24 = 0.0f;
-
- result.M33 = 1.0f / (zNearPlane - zFarPlane);
- result.M31 = result.M32 = result.M34 = 0.0f;
-
- result.M41 = result.M42 = 0.0f;
- result.M43 = zNearPlane / (zNearPlane - zFarPlane);
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Builds a customized, orthographic projection matrix.
- /// </summary>
- /// <param name="left">Minimum X-value of the view volume.</param>
- /// <param name="right">Maximum X-value of the view volume.</param>
- /// <param name="bottom">Minimum Y-value of the view volume.</param>
- /// <param name="top">Maximum Y-value of the view volume.</param>
- /// <param name="zNearPlane">Minimum Z-value of the view volume.</param>
- /// <param name="zFarPlane">Maximum Z-value of the view volume.</param>
- /// <returns>The orthographic projection matrix.</returns>
- public static Matrix4x4 CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane)
- {
- Matrix4x4 result;
-
- result.M11 = 2.0f / (right - left);
- result.M12 = result.M13 = result.M14 = 0.0f;
-
- result.M22 = 2.0f / (top - bottom);
- result.M21 = result.M23 = result.M24 = 0.0f;
-
- result.M33 = 1.0f / (zNearPlane - zFarPlane);
- result.M31 = result.M32 = result.M34 = 0.0f;
-
- result.M41 = (left + right) / (left - right);
- result.M42 = (top + bottom) / (bottom - top);
- result.M43 = zNearPlane / (zNearPlane - zFarPlane);
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a view matrix.
- /// </summary>
- /// <param name="cameraPosition">The position of the camera.</param>
- /// <param name="cameraTarget">The target towards which the camera is pointing.</param>
- /// <param name="cameraUpVector">The direction that is "up" from the camera's point of view.</param>
- /// <returns>The view matrix.</returns>
- public static Matrix4x4 CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector)
- {
- Vector3 zaxis = Vector3.Normalize(cameraPosition - cameraTarget);
- Vector3 xaxis = Vector3.Normalize(Vector3.Cross(cameraUpVector, zaxis));
- Vector3 yaxis = Vector3.Cross(zaxis, xaxis);
-
- Matrix4x4 result;
-
- result.M11 = xaxis.X;
- result.M12 = yaxis.X;
- result.M13 = zaxis.X;
- result.M14 = 0.0f;
- result.M21 = xaxis.Y;
- result.M22 = yaxis.Y;
- result.M23 = zaxis.Y;
- result.M24 = 0.0f;
- result.M31 = xaxis.Z;
- result.M32 = yaxis.Z;
- result.M33 = zaxis.Z;
- result.M34 = 0.0f;
- result.M41 = -Vector3.Dot(xaxis, cameraPosition);
- result.M42 = -Vector3.Dot(yaxis, cameraPosition);
- result.M43 = -Vector3.Dot(zaxis, cameraPosition);
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a world matrix with the specified parameters.
- /// </summary>
- /// <param name="position">The position of the object; used in translation operations.</param>
- /// <param name="forward">Forward direction of the object.</param>
- /// <param name="up">Upward direction of the object; usually [0, 1, 0].</param>
- /// <returns>The world matrix.</returns>
- public static Matrix4x4 CreateWorld(Vector3 position, Vector3 forward, Vector3 up)
- {
- Vector3 zaxis = Vector3.Normalize(-forward);
- Vector3 xaxis = Vector3.Normalize(Vector3.Cross(up, zaxis));
- Vector3 yaxis = Vector3.Cross(zaxis, xaxis);
-
- Matrix4x4 result;
-
- result.M11 = xaxis.X;
- result.M12 = xaxis.Y;
- result.M13 = xaxis.Z;
- result.M14 = 0.0f;
- result.M21 = yaxis.X;
- result.M22 = yaxis.Y;
- result.M23 = yaxis.Z;
- result.M24 = 0.0f;
- result.M31 = zaxis.X;
- result.M32 = zaxis.Y;
- result.M33 = zaxis.Z;
- result.M34 = 0.0f;
- result.M41 = position.X;
- result.M42 = position.Y;
- result.M43 = position.Z;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a rotation matrix from the given Quaternion rotation value.
- /// </summary>
- /// <param name="quaternion">The source Quaternion.</param>
- /// <returns>The rotation matrix.</returns>
- public static Matrix4x4 CreateFromQuaternion(Quaternion quaternion)
- {
- Matrix4x4 result;
-
- float xx = quaternion.X * quaternion.X;
- float yy = quaternion.Y * quaternion.Y;
- float zz = quaternion.Z * quaternion.Z;
-
- float xy = quaternion.X * quaternion.Y;
- float wz = quaternion.Z * quaternion.W;
- float xz = quaternion.Z * quaternion.X;
- float wy = quaternion.Y * quaternion.W;
- float yz = quaternion.Y * quaternion.Z;
- float wx = quaternion.X * quaternion.W;
-
- result.M11 = 1.0f - 2.0f * (yy + zz);
- result.M12 = 2.0f * (xy + wz);
- result.M13 = 2.0f * (xz - wy);
- result.M14 = 0.0f;
- result.M21 = 2.0f * (xy - wz);
- result.M22 = 1.0f - 2.0f * (zz + xx);
- result.M23 = 2.0f * (yz + wx);
- result.M24 = 0.0f;
- result.M31 = 2.0f * (xz + wy);
- result.M32 = 2.0f * (yz - wx);
- result.M33 = 1.0f - 2.0f * (yy + xx);
- result.M34 = 0.0f;
- result.M41 = 0.0f;
- result.M42 = 0.0f;
- result.M43 = 0.0f;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Creates a rotation matrix from the specified yaw, pitch, and roll.
- /// </summary>
- /// <param name="yaw">Angle of rotation, in radians, around the Y-axis.</param>
- /// <param name="pitch">Angle of rotation, in radians, around the X-axis.</param>
- /// <param name="roll">Angle of rotation, in radians, around the Z-axis.</param>
- /// <returns>The rotation matrix.</returns>
- public static Matrix4x4 CreateFromYawPitchRoll(float yaw, float pitch, float roll)
- {
- Quaternion q = Quaternion.CreateFromYawPitchRoll(yaw, pitch, roll);
-
- return Matrix4x4.CreateFromQuaternion(q);
- }
-
- /// <summary>
- /// Creates a Matrix that flattens geometry into a specified Plane as if casting a shadow from a specified light source.
- /// </summary>
- /// <param name="lightDirection">The direction from which the light that will cast the shadow is coming.</param>
- /// <param name="plane">The Plane onto which the new matrix should flatten geometry so as to cast a shadow.</param>
- /// <returns>A new Matrix that can be used to flatten geometry onto the specified plane from the specified direction.</returns>
- public static Matrix4x4 CreateShadow(Vector3 lightDirection, Plane plane)
- {
- Plane p = Plane.Normalize(plane);
-
- float dot = p.Normal.X * lightDirection.X + p.Normal.Y * lightDirection.Y + p.Normal.Z * lightDirection.Z;
- float a = -p.Normal.X;
- float b = -p.Normal.Y;
- float c = -p.Normal.Z;
- float d = -p.D;
-
- Matrix4x4 result;
-
- result.M11 = a * lightDirection.X + dot;
- result.M21 = b * lightDirection.X;
- result.M31 = c * lightDirection.X;
- result.M41 = d * lightDirection.X;
-
- result.M12 = a * lightDirection.Y;
- result.M22 = b * lightDirection.Y + dot;
- result.M32 = c * lightDirection.Y;
- result.M42 = d * lightDirection.Y;
-
- result.M13 = a * lightDirection.Z;
- result.M23 = b * lightDirection.Z;
- result.M33 = c * lightDirection.Z + dot;
- result.M43 = d * lightDirection.Z;
-
- result.M14 = 0.0f;
- result.M24 = 0.0f;
- result.M34 = 0.0f;
- result.M44 = dot;
-
- return result;
- }
-
- /// <summary>
- /// Creates a Matrix that reflects the coordinate system about a specified Plane.
- /// </summary>
- /// <param name="value">The Plane about which to create a reflection.</param>
- /// <returns>A new matrix expressing the reflection.</returns>
- public static Matrix4x4 CreateReflection(Plane value)
- {
- value = Plane.Normalize(value);
-
- float a = value.Normal.X;
- float b = value.Normal.Y;
- float c = value.Normal.Z;
-
- float fa = -2.0f * a;
- float fb = -2.0f * b;
- float fc = -2.0f * c;
-
- Matrix4x4 result;
-
- result.M11 = fa * a + 1.0f;
- result.M12 = fb * a;
- result.M13 = fc * a;
- result.M14 = 0.0f;
-
- result.M21 = fa * b;
- result.M22 = fb * b + 1.0f;
- result.M23 = fc * b;
- result.M24 = 0.0f;
-
- result.M31 = fa * c;
- result.M32 = fb * c;
- result.M33 = fc * c + 1.0f;
- result.M34 = 0.0f;
-
- result.M41 = fa * value.D;
- result.M42 = fb * value.D;
- result.M43 = fc * value.D;
- result.M44 = 1.0f;
-
- return result;
- }
-
- /// <summary>
- /// Calculates the determinant of the matrix.
- /// </summary>
- /// <returns>The determinant of the matrix.</returns>
- public readonly float GetDeterminant()
- {
- // | a b c d | | f g h | | e g h | | e f h | | e f g |
- // | e f g h | = a | j k l | - b | i k l | + c | i j l | - d | i j k |
- // | i j k l | | n o p | | m o p | | m n p | | m n o |
- // | m n o p |
- //
- // | f g h |
- // a | j k l | = a ( f ( kp - lo ) - g ( jp - ln ) + h ( jo - kn ) )
- // | n o p |
- //
- // | e g h |
- // b | i k l | = b ( e ( kp - lo ) - g ( ip - lm ) + h ( io - km ) )
- // | m o p |
- //
- // | e f h |
- // c | i j l | = c ( e ( jp - ln ) - f ( ip - lm ) + h ( in - jm ) )
- // | m n p |
- //
- // | e f g |
- // d | i j k | = d ( e ( jo - kn ) - f ( io - km ) + g ( in - jm ) )
- // | m n o |
- //
- // Cost of operation
- // 17 adds and 28 muls.
- //
- // add: 6 + 8 + 3 = 17
- // mul: 12 + 16 = 28
-
- float a = M11, b = M12, c = M13, d = M14;
- float e = M21, f = M22, g = M23, h = M24;
- float i = M31, j = M32, k = M33, l = M34;
- float m = M41, n = M42, o = M43, p = M44;
-
- float kp_lo = k * p - l * o;
- float jp_ln = j * p - l * n;
- float jo_kn = j * o - k * n;
- float ip_lm = i * p - l * m;
- float io_km = i * o - k * m;
- float in_jm = i * n - j * m;
-
- return a * (f * kp_lo - g * jp_ln + h * jo_kn) -
- b * (e * kp_lo - g * ip_lm + h * io_km) +
- c * (e * jp_ln - f * ip_lm + h * in_jm) -
- d * (e * jo_kn - f * io_km + g * in_jm);
- }
-
- /// <summary>
- /// Attempts to calculate the inverse of the given matrix. If successful, result will contain the inverted matrix.
- /// </summary>
- /// <param name="matrix">The source matrix to invert.</param>
- /// <param name="result">If successful, contains the inverted matrix.</param>
- /// <returns>True if the source matrix could be inverted; False otherwise.</returns>
- public static bool Invert(Matrix4x4 matrix, out Matrix4x4 result)
- {
- // -1
- // If you have matrix M, inverse Matrix M can compute
- //
- // -1 1
- // M = --------- A
- // det(M)
- //
- // A is adjugate (adjoint) of M, where,
- //
- // T
- // A = C
- //
- // C is Cofactor matrix of M, where,
- // i + j
- // C = (-1) * det(M )
- // ij ij
- //
- // [ a b c d ]
- // M = [ e f g h ]
- // [ i j k l ]
- // [ m n o p ]
- //
- // First Row
- // 2 | f g h |
- // C = (-1) | j k l | = + ( f ( kp - lo ) - g ( jp - ln ) + h ( jo - kn ) )
- // 11 | n o p |
- //
- // 3 | e g h |
- // C = (-1) | i k l | = - ( e ( kp - lo ) - g ( ip - lm ) + h ( io - km ) )
- // 12 | m o p |
- //
- // 4 | e f h |
- // C = (-1) | i j l | = + ( e ( jp - ln ) - f ( ip - lm ) + h ( in - jm ) )
- // 13 | m n p |
- //
- // 5 | e f g |
- // C = (-1) | i j k | = - ( e ( jo - kn ) - f ( io - km ) + g ( in - jm ) )
- // 14 | m n o |
- //
- // Second Row
- // 3 | b c d |
- // C = (-1) | j k l | = - ( b ( kp - lo ) - c ( jp - ln ) + d ( jo - kn ) )
- // 21 | n o p |
- //
- // 4 | a c d |
- // C = (-1) | i k l | = + ( a ( kp - lo ) - c ( ip - lm ) + d ( io - km ) )
- // 22 | m o p |
- //
- // 5 | a b d |
- // C = (-1) | i j l | = - ( a ( jp - ln ) - b ( ip - lm ) + d ( in - jm ) )
- // 23 | m n p |
- //
- // 6 | a b c |
- // C = (-1) | i j k | = + ( a ( jo - kn ) - b ( io - km ) + c ( in - jm ) )
- // 24 | m n o |
- //
- // Third Row
- // 4 | b c d |
- // C = (-1) | f g h | = + ( b ( gp - ho ) - c ( fp - hn ) + d ( fo - gn ) )
- // 31 | n o p |
- //
- // 5 | a c d |
- // C = (-1) | e g h | = - ( a ( gp - ho ) - c ( ep - hm ) + d ( eo - gm ) )
- // 32 | m o p |
- //
- // 6 | a b d |
- // C = (-1) | e f h | = + ( a ( fp - hn ) - b ( ep - hm ) + d ( en - fm ) )
- // 33 | m n p |
- //
- // 7 | a b c |
- // C = (-1) | e f g | = - ( a ( fo - gn ) - b ( eo - gm ) + c ( en - fm ) )
- // 34 | m n o |
- //
- // Fourth Row
- // 5 | b c d |
- // C = (-1) | f g h | = - ( b ( gl - hk ) - c ( fl - hj ) + d ( fk - gj ) )
- // 41 | j k l |
- //
- // 6 | a c d |
- // C = (-1) | e g h | = + ( a ( gl - hk ) - c ( el - hi ) + d ( ek - gi ) )
- // 42 | i k l |
- //
- // 7 | a b d |
- // C = (-1) | e f h | = - ( a ( fl - hj ) - b ( el - hi ) + d ( ej - fi ) )
- // 43 | i j l |
- //
- // 8 | a b c |
- // C = (-1) | e f g | = + ( a ( fk - gj ) - b ( ek - gi ) + c ( ej - fi ) )
- // 44 | i j k |
- //
- // Cost of operation
- // 53 adds, 104 muls, and 1 div.
- float a = matrix.M11, b = matrix.M12, c = matrix.M13, d = matrix.M14;
- float e = matrix.M21, f = matrix.M22, g = matrix.M23, h = matrix.M24;
- float i = matrix.M31, j = matrix.M32, k = matrix.M33, l = matrix.M34;
- float m = matrix.M41, n = matrix.M42, o = matrix.M43, p = matrix.M44;
-
- float kp_lo = k * p - l * o;
- float jp_ln = j * p - l * n;
- float jo_kn = j * o - k * n;
- float ip_lm = i * p - l * m;
- float io_km = i * o - k * m;
- float in_jm = i * n - j * m;
-
- float a11 = +(f * kp_lo - g * jp_ln + h * jo_kn);
- float a12 = -(e * kp_lo - g * ip_lm + h * io_km);
- float a13 = +(e * jp_ln - f * ip_lm + h * in_jm);
- float a14 = -(e * jo_kn - f * io_km + g * in_jm);
-
- float det = a * a11 + b * a12 + c * a13 + d * a14;
-
- if (MathF.Abs(det) < float.Epsilon)
- {
- result = new Matrix4x4(float.NaN, float.NaN, float.NaN, float.NaN,
- float.NaN, float.NaN, float.NaN, float.NaN,
- float.NaN, float.NaN, float.NaN, float.NaN,
- float.NaN, float.NaN, float.NaN, float.NaN);
- return false;
- }
-
- float invDet = 1.0f / det;
-
- result.M11 = a11 * invDet;
- result.M21 = a12 * invDet;
- result.M31 = a13 * invDet;
- result.M41 = a14 * invDet;
-
- result.M12 = -(b * kp_lo - c * jp_ln + d * jo_kn) * invDet;
- result.M22 = +(a * kp_lo - c * ip_lm + d * io_km) * invDet;
- result.M32 = -(a * jp_ln - b * ip_lm + d * in_jm) * invDet;
- result.M42 = +(a * jo_kn - b * io_km + c * in_jm) * invDet;
-
- float gp_ho = g * p - h * o;
- float fp_hn = f * p - h * n;
- float fo_gn = f * o - g * n;
- float ep_hm = e * p - h * m;
- float eo_gm = e * o - g * m;
- float en_fm = e * n - f * m;
-
- result.M13 = +(b * gp_ho - c * fp_hn + d * fo_gn) * invDet;
- result.M23 = -(a * gp_ho - c * ep_hm + d * eo_gm) * invDet;
- result.M33 = +(a * fp_hn - b * ep_hm + d * en_fm) * invDet;
- result.M43 = -(a * fo_gn - b * eo_gm + c * en_fm) * invDet;
-
- float gl_hk = g * l - h * k;
- float fl_hj = f * l - h * j;
- float fk_gj = f * k - g * j;
- float el_hi = e * l - h * i;
- float ek_gi = e * k - g * i;
- float ej_fi = e * j - f * i;
-
- result.M14 = -(b * gl_hk - c * fl_hj + d * fk_gj) * invDet;
- result.M24 = +(a * gl_hk - c * el_hi + d * ek_gi) * invDet;
- result.M34 = -(a * fl_hj - b * el_hi + d * ej_fi) * invDet;
- result.M44 = +(a * fk_gj - b * ek_gi + c * ej_fi) * invDet;
-
- return true;
- }
-
-
- private struct CanonicalBasis
- {
- public Vector3 Row0;
- public Vector3 Row1;
- public Vector3 Row2;
- };
-
-
- private struct VectorBasis
- {
- public unsafe Vector3* Element0;
- public unsafe Vector3* Element1;
- public unsafe Vector3* Element2;
- }
-
- /// <summary>
- /// Attempts to extract the scale, translation, and rotation components from the given scale/rotation/translation matrix.
- /// If successful, the out parameters will contained the extracted values.
- /// </summary>
- /// <param name="matrix">The source matrix.</param>
- /// <param name="scale">The scaling component of the transformation matrix.</param>
- /// <param name="rotation">The rotation component of the transformation matrix.</param>
- /// <param name="translation">The translation component of the transformation matrix</param>
- /// <returns>True if the source matrix was successfully decomposed; False otherwise.</returns>
- public static bool Decompose(Matrix4x4 matrix, out Vector3 scale, out Quaternion rotation, out Vector3 translation)
- {
- bool result = true;
-
- unsafe
- {
- fixed (Vector3* scaleBase = &scale)
- {
- float* pfScales = (float*)scaleBase;
- float det;
-
- VectorBasis vectorBasis;
- Vector3** pVectorBasis = (Vector3**)&vectorBasis;
-
- Matrix4x4 matTemp = Matrix4x4.Identity;
- CanonicalBasis canonicalBasis = default;
- Vector3* pCanonicalBasis = &canonicalBasis.Row0;
-
- canonicalBasis.Row0 = new Vector3(1.0f, 0.0f, 0.0f);
- canonicalBasis.Row1 = new Vector3(0.0f, 1.0f, 0.0f);
- canonicalBasis.Row2 = new Vector3(0.0f, 0.0f, 1.0f);
-
- translation = new Vector3(
- matrix.M41,
- matrix.M42,
- matrix.M43);
-
- pVectorBasis[0] = (Vector3*)&matTemp.M11;
- pVectorBasis[1] = (Vector3*)&matTemp.M21;
- pVectorBasis[2] = (Vector3*)&matTemp.M31;
-
- *(pVectorBasis[0]) = new Vector3(matrix.M11, matrix.M12, matrix.M13);
- *(pVectorBasis[1]) = new Vector3(matrix.M21, matrix.M22, matrix.M23);
- *(pVectorBasis[2]) = new Vector3(matrix.M31, matrix.M32, matrix.M33);
-
- scale.X = pVectorBasis[0]->Length();
- scale.Y = pVectorBasis[1]->Length();
- scale.Z = pVectorBasis[2]->Length();
-
- uint a, b, c;
- #region Ranking
- float x = pfScales[0], y = pfScales[1], z = pfScales[2];
- if (x < y)
- {
- if (y < z)
- {
- a = 2;
- b = 1;
- c = 0;
- }
- else
- {
- a = 1;
-
- if (x < z)
- {
- b = 2;
- c = 0;
- }
- else
- {
- b = 0;
- c = 2;
- }
- }
- }
- else
- {
- if (x < z)
- {
- a = 2;
- b = 0;
- c = 1;
- }
- else
- {
- a = 0;
-
- if (y < z)
- {
- b = 2;
- c = 1;
- }
- else
- {
- b = 1;
- c = 2;
- }
- }
- }
- #endregion
-
- if (pfScales[a] < DecomposeEpsilon)
- {
- *(pVectorBasis[a]) = pCanonicalBasis[a];
- }
-
- *pVectorBasis[a] = Vector3.Normalize(*pVectorBasis[a]);
-
- if (pfScales[b] < DecomposeEpsilon)
- {
- uint cc;
- float fAbsX, fAbsY, fAbsZ;
-
- fAbsX = MathF.Abs(pVectorBasis[a]->X);
- fAbsY = MathF.Abs(pVectorBasis[a]->Y);
- fAbsZ = MathF.Abs(pVectorBasis[a]->Z);
-
- #region Ranking
- if (fAbsX < fAbsY)
- {
- if (fAbsY < fAbsZ)
- {
- cc = 0;
- }
- else
- {
- if (fAbsX < fAbsZ)
- {
- cc = 0;
- }
- else
- {
- cc = 2;
- }
- }
- }
- else
- {
- if (fAbsX < fAbsZ)
- {
- cc = 1;
- }
- else
- {
- if (fAbsY < fAbsZ)
- {
- cc = 1;
- }
- else
- {
- cc = 2;
- }
- }
- }
- #endregion
-
- *pVectorBasis[b] = Vector3.Cross(*pVectorBasis[a], *(pCanonicalBasis + cc));
- }
-
- *pVectorBasis[b] = Vector3.Normalize(*pVectorBasis[b]);
-
- if (pfScales[c] < DecomposeEpsilon)
- {
- *pVectorBasis[c] = Vector3.Cross(*pVectorBasis[a], *pVectorBasis[b]);
- }
-
- *pVectorBasis[c] = Vector3.Normalize(*pVectorBasis[c]);
-
- det = matTemp.GetDeterminant();
-
- // use Kramer's rule to check for handedness of coordinate system
- if (det < 0.0f)
- {
- // switch coordinate system by negating the scale and inverting the basis vector on the x-axis
- pfScales[a] = -pfScales[a];
- *pVectorBasis[a] = -(*pVectorBasis[a]);
-
- det = -det;
- }
-
- det -= 1.0f;
- det *= det;
-
- if ((DecomposeEpsilon < det))
- {
- // Non-SRT matrix encountered
- rotation = Quaternion.Identity;
- result = false;
- }
- else
- {
- // generate the quaternion from the matrix
- rotation = Quaternion.CreateFromRotationMatrix(matTemp);
- }
- }
- }
-
- return result;
- }
-
- /// <summary>
- /// Transforms the given matrix by applying the given Quaternion rotation.
- /// </summary>
- /// <param name="value">The source matrix to transform.</param>
- /// <param name="rotation">The rotation to apply.</param>
- /// <returns>The transformed matrix.</returns>
- public static Matrix4x4 Transform(Matrix4x4 value, Quaternion rotation)
- {
- // Compute rotation matrix.
- float x2 = rotation.X + rotation.X;
- float y2 = rotation.Y + rotation.Y;
- float z2 = rotation.Z + rotation.Z;
-
- float wx2 = rotation.W * x2;
- float wy2 = rotation.W * y2;
- float wz2 = rotation.W * z2;
- float xx2 = rotation.X * x2;
- float xy2 = rotation.X * y2;
- float xz2 = rotation.X * z2;
- float yy2 = rotation.Y * y2;
- float yz2 = rotation.Y * z2;
- float zz2 = rotation.Z * z2;
-
- float q11 = 1.0f - yy2 - zz2;
- float q21 = xy2 - wz2;
- float q31 = xz2 + wy2;
-
- float q12 = xy2 + wz2;
- float q22 = 1.0f - xx2 - zz2;
- float q32 = yz2 - wx2;
-
- float q13 = xz2 - wy2;
- float q23 = yz2 + wx2;
- float q33 = 1.0f - xx2 - yy2;
-
- Matrix4x4 result;
-
- // First row
- result.M11 = value.M11 * q11 + value.M12 * q21 + value.M13 * q31;
- result.M12 = value.M11 * q12 + value.M12 * q22 + value.M13 * q32;
- result.M13 = value.M11 * q13 + value.M12 * q23 + value.M13 * q33;
- result.M14 = value.M14;
-
- // Second row
- result.M21 = value.M21 * q11 + value.M22 * q21 + value.M23 * q31;
- result.M22 = value.M21 * q12 + value.M22 * q22 + value.M23 * q32;
- result.M23 = value.M21 * q13 + value.M22 * q23 + value.M23 * q33;
- result.M24 = value.M24;
-
- // Third row
- result.M31 = value.M31 * q11 + value.M32 * q21 + value.M33 * q31;
- result.M32 = value.M31 * q12 + value.M32 * q22 + value.M33 * q32;
- result.M33 = value.M31 * q13 + value.M32 * q23 + value.M33 * q33;
- result.M34 = value.M34;
-
- // Fourth row
- result.M41 = value.M41 * q11 + value.M42 * q21 + value.M43 * q31;
- result.M42 = value.M41 * q12 + value.M42 * q22 + value.M43 * q32;
- result.M43 = value.M41 * q13 + value.M42 * q23 + value.M43 * q33;
- result.M44 = value.M44;
-
- return result;
- }
-
- /// <summary>
- /// Transposes the rows and columns of a matrix.
- /// </summary>
- /// <param name="matrix">The source matrix.</param>
- /// <returns>The transposed matrix.</returns>
- public static unsafe Matrix4x4 Transpose(Matrix4x4 matrix)
- {
- if (Sse.IsSupported)
- {
- var row1 = Sse.LoadVector128(&matrix.M11);
- var row2 = Sse.LoadVector128(&matrix.M21);
- var row3 = Sse.LoadVector128(&matrix.M31);
- var row4 = Sse.LoadVector128(&matrix.M41);
-
- var l12 = Sse.UnpackLow(row1, row2);
- var l34 = Sse.UnpackLow(row3, row4);
- var h12 = Sse.UnpackHigh(row1, row2);
- var h34 = Sse.UnpackHigh(row3, row4);
-
- Sse.Store(&matrix.M11, Sse.MoveLowToHigh(l12, l34));
- Sse.Store(&matrix.M21, Sse.MoveHighToLow(l34, l12));
- Sse.Store(&matrix.M31, Sse.MoveLowToHigh(h12, h34));
- Sse.Store(&matrix.M41, Sse.MoveHighToLow(h34, h12));
-
- return matrix;
- }
-
- Matrix4x4 result;
-
- result.M11 = matrix.M11;
- result.M12 = matrix.M21;
- result.M13 = matrix.M31;
- result.M14 = matrix.M41;
- result.M21 = matrix.M12;
- result.M22 = matrix.M22;
- result.M23 = matrix.M32;
- result.M24 = matrix.M42;
- result.M31 = matrix.M13;
- result.M32 = matrix.M23;
- result.M33 = matrix.M33;
- result.M34 = matrix.M43;
- result.M41 = matrix.M14;
- result.M42 = matrix.M24;
- result.M43 = matrix.M34;
- result.M44 = matrix.M44;
-
- return result;
- }
-
- /// <summary>
- /// Linearly interpolates between the corresponding values of two matrices.
- /// </summary>
- /// <param name="matrix1">The first source matrix.</param>
- /// <param name="matrix2">The second source matrix.</param>
- /// <param name="amount">The relative weight of the second source matrix.</param>
- /// <returns>The interpolated matrix.</returns>
- public static unsafe Matrix4x4 Lerp(Matrix4x4 matrix1, Matrix4x4 matrix2, float amount)
- {
- if (Sse.IsSupported)
- {
- Vector128<float> amountVec = Vector128.Create(amount);
- Sse.Store(&matrix1.M11, VectorMath.Lerp(Sse.LoadVector128(&matrix1.M11), Sse.LoadVector128(&matrix2.M11), amountVec));
- Sse.Store(&matrix1.M21, VectorMath.Lerp(Sse.LoadVector128(&matrix1.M21), Sse.LoadVector128(&matrix2.M21), amountVec));
- Sse.Store(&matrix1.M31, VectorMath.Lerp(Sse.LoadVector128(&matrix1.M31), Sse.LoadVector128(&matrix2.M31), amountVec));
- Sse.Store(&matrix1.M41, VectorMath.Lerp(Sse.LoadVector128(&matrix1.M41), Sse.LoadVector128(&matrix2.M41), amountVec));
- return matrix1;
- }
-
- Matrix4x4 result;
-
- // First row
- result.M11 = matrix1.M11 + (matrix2.M11 - matrix1.M11) * amount;
- result.M12 = matrix1.M12 + (matrix2.M12 - matrix1.M12) * amount;
- result.M13 = matrix1.M13 + (matrix2.M13 - matrix1.M13) * amount;
- result.M14 = matrix1.M14 + (matrix2.M14 - matrix1.M14) * amount;
-
- // Second row
- result.M21 = matrix1.M21 + (matrix2.M21 - matrix1.M21) * amount;
- result.M22 = matrix1.M22 + (matrix2.M22 - matrix1.M22) * amount;
- result.M23 = matrix1.M23 + (matrix2.M23 - matrix1.M23) * amount;
- result.M24 = matrix1.M24 + (matrix2.M24 - matrix1.M24) * amount;
-
- // Third row
- result.M31 = matrix1.M31 + (matrix2.M31 - matrix1.M31) * amount;
- result.M32 = matrix1.M32 + (matrix2.M32 - matrix1.M32) * amount;
- result.M33 = matrix1.M33 + (matrix2.M33 - matrix1.M33) * amount;
- result.M34 = matrix1.M34 + (matrix2.M34 - matrix1.M34) * amount;
-
- // Fourth row
- result.M41 = matrix1.M41 + (matrix2.M41 - matrix1.M41) * amount;
- result.M42 = matrix1.M42 + (matrix2.M42 - matrix1.M42) * amount;
- result.M43 = matrix1.M43 + (matrix2.M43 - matrix1.M43) * amount;
- result.M44 = matrix1.M44 + (matrix2.M44 - matrix1.M44) * amount;
-
- return result;
- }
-
- /// <summary>
- /// Returns a new matrix with the negated elements of the given matrix.
- /// </summary>
- /// <param name="value">The source matrix.</param>
- /// <returns>The negated matrix.</returns>
- public static Matrix4x4 Negate(Matrix4x4 value) => -value;
-
- /// <summary>
- /// Adds two matrices together.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The resulting matrix.</returns>
- public static Matrix4x4 Add(Matrix4x4 value1, Matrix4x4 value2) => value1 + value2;
-
- /// <summary>
- /// Subtracts the second matrix from the first.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The result of the subtraction.</returns>
- public static Matrix4x4 Subtract(Matrix4x4 value1, Matrix4x4 value2) => value1 - value2;
-
- /// <summary>
- /// Multiplies a matrix by another matrix.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The result of the multiplication.</returns>
- public static Matrix4x4 Multiply(Matrix4x4 value1, Matrix4x4 value2) => value1 * value2;
-
- /// <summary>
- /// Multiplies a matrix by a scalar value.
- /// </summary>
- /// <param name="value1">The source matrix.</param>
- /// <param name="value2">The scaling factor.</param>
- /// <returns>The scaled matrix.</returns>
- public static Matrix4x4 Multiply(Matrix4x4 value1, float value2) => value1 * value2;
-
- /// <summary>
- /// Returns a new matrix with the negated elements of the given matrix.
- /// </summary>
- /// <param name="value">The source matrix.</param>
- /// <returns>The negated matrix.</returns>
- public static unsafe Matrix4x4 operator -(Matrix4x4 value)
- {
- if (Sse.IsSupported)
- {
- Vector128<float> zero = Vector128<float>.Zero;
- Sse.Store(&value.M11, Sse.Subtract(zero, Sse.LoadVector128(&value.M11)));
- Sse.Store(&value.M21, Sse.Subtract(zero, Sse.LoadVector128(&value.M21)));
- Sse.Store(&value.M31, Sse.Subtract(zero, Sse.LoadVector128(&value.M31)));
- Sse.Store(&value.M41, Sse.Subtract(zero, Sse.LoadVector128(&value.M41)));
-
- return value;
- }
-
- Matrix4x4 m;
-
- m.M11 = -value.M11;
- m.M12 = -value.M12;
- m.M13 = -value.M13;
- m.M14 = -value.M14;
- m.M21 = -value.M21;
- m.M22 = -value.M22;
- m.M23 = -value.M23;
- m.M24 = -value.M24;
- m.M31 = -value.M31;
- m.M32 = -value.M32;
- m.M33 = -value.M33;
- m.M34 = -value.M34;
- m.M41 = -value.M41;
- m.M42 = -value.M42;
- m.M43 = -value.M43;
- m.M44 = -value.M44;
-
- return m;
- }
-
- /// <summary>
- /// Adds two matrices together.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The resulting matrix.</returns>
- public static unsafe Matrix4x4 operator +(Matrix4x4 value1, Matrix4x4 value2)
- {
- if (Sse.IsSupported)
- {
- Sse.Store(&value1.M11, Sse.Add(Sse.LoadVector128(&value1.M11), Sse.LoadVector128(&value2.M11)));
- Sse.Store(&value1.M21, Sse.Add(Sse.LoadVector128(&value1.M21), Sse.LoadVector128(&value2.M21)));
- Sse.Store(&value1.M31, Sse.Add(Sse.LoadVector128(&value1.M31), Sse.LoadVector128(&value2.M31)));
- Sse.Store(&value1.M41, Sse.Add(Sse.LoadVector128(&value1.M41), Sse.LoadVector128(&value2.M41)));
- return value1;
- }
-
- Matrix4x4 m;
-
- m.M11 = value1.M11 + value2.M11;
- m.M12 = value1.M12 + value2.M12;
- m.M13 = value1.M13 + value2.M13;
- m.M14 = value1.M14 + value2.M14;
- m.M21 = value1.M21 + value2.M21;
- m.M22 = value1.M22 + value2.M22;
- m.M23 = value1.M23 + value2.M23;
- m.M24 = value1.M24 + value2.M24;
- m.M31 = value1.M31 + value2.M31;
- m.M32 = value1.M32 + value2.M32;
- m.M33 = value1.M33 + value2.M33;
- m.M34 = value1.M34 + value2.M34;
- m.M41 = value1.M41 + value2.M41;
- m.M42 = value1.M42 + value2.M42;
- m.M43 = value1.M43 + value2.M43;
- m.M44 = value1.M44 + value2.M44;
-
- return m;
- }
-
- /// <summary>
- /// Subtracts the second matrix from the first.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The result of the subtraction.</returns>
- public static unsafe Matrix4x4 operator -(Matrix4x4 value1, Matrix4x4 value2)
- {
- if (Sse.IsSupported)
- {
- Sse.Store(&value1.M11, Sse.Subtract(Sse.LoadVector128(&value1.M11), Sse.LoadVector128(&value2.M11)));
- Sse.Store(&value1.M21, Sse.Subtract(Sse.LoadVector128(&value1.M21), Sse.LoadVector128(&value2.M21)));
- Sse.Store(&value1.M31, Sse.Subtract(Sse.LoadVector128(&value1.M31), Sse.LoadVector128(&value2.M31)));
- Sse.Store(&value1.M41, Sse.Subtract(Sse.LoadVector128(&value1.M41), Sse.LoadVector128(&value2.M41)));
- return value1;
- }
-
- Matrix4x4 m;
-
- m.M11 = value1.M11 - value2.M11;
- m.M12 = value1.M12 - value2.M12;
- m.M13 = value1.M13 - value2.M13;
- m.M14 = value1.M14 - value2.M14;
- m.M21 = value1.M21 - value2.M21;
- m.M22 = value1.M22 - value2.M22;
- m.M23 = value1.M23 - value2.M23;
- m.M24 = value1.M24 - value2.M24;
- m.M31 = value1.M31 - value2.M31;
- m.M32 = value1.M32 - value2.M32;
- m.M33 = value1.M33 - value2.M33;
- m.M34 = value1.M34 - value2.M34;
- m.M41 = value1.M41 - value2.M41;
- m.M42 = value1.M42 - value2.M42;
- m.M43 = value1.M43 - value2.M43;
- m.M44 = value1.M44 - value2.M44;
-
- return m;
- }
-
- /// <summary>
- /// Multiplies a matrix by another matrix.
- /// </summary>
- /// <param name="value1">The first source matrix.</param>
- /// <param name="value2">The second source matrix.</param>
- /// <returns>The result of the multiplication.</returns>
- public static unsafe Matrix4x4 operator *(Matrix4x4 value1, Matrix4x4 value2)
- {
- if (Sse.IsSupported)
- {
- var row = Sse.LoadVector128(&value1.M11);
- Sse.Store(&value1.M11,
- Sse.Add(Sse.Add(Sse.Multiply(Sse.Shuffle(row, row, 0x00), Sse.LoadVector128(&value2.M11)),
- Sse.Multiply(Sse.Shuffle(row, row, 0x55), Sse.LoadVector128(&value2.M21))),
- Sse.Add(Sse.Multiply(Sse.Shuffle(row, row, 0xAA), Sse.LoadVector128(&value2.M31)),
- Sse.Multiply(Sse.Shuffle(row, row, 0xFF), Sse.LoadVector128(&value2.M41)))));
-
- // 0x00 is _MM_SHUFFLE(0,0,0,0), 0x55 is _MM_SHUFFLE(1,1,1,1), etc.
- // TODO: Replace with a method once it's added to the API.
-
- row = Sse.LoadVector128(&value1.M21);
- Sse.Store(&value1.M21,
- Sse.Add(Sse.Add(Sse.Multiply(Sse.Shuffle(row, row, 0x00), Sse.LoadVector128(&value2.M11)),
- Sse.Multiply(Sse.Shuffle(row, row, 0x55), Sse.LoadVector128(&value2.M21))),
- Sse.Add(Sse.Multiply(Sse.Shuffle(row, row, 0xAA), Sse.LoadVector128(&value2.M31)),
- Sse.Multiply(Sse.Shuffle(row, row, 0xFF), Sse.LoadVector128(&value2.M41)))));
-
- row = Sse.LoadVector128(&value1.M31);
- Sse.Store(&value1.M31,
- Sse.Add(Sse.Add(Sse.Multiply(Sse.Shuffle(row, row, 0x00), Sse.LoadVector128(&value2.M11)),
- Sse.Multiply(Sse.Shuffle(row, row, 0x55), Sse.LoadVector128(&value2.M21))),
- Sse.Add(Sse.Multiply(Sse.Shuffle(row, row, 0xAA), Sse.LoadVector128(&value2.M31)),
- Sse.Multiply(Sse.Shuffle(row, row, 0xFF), Sse.LoadVector128(&value2.M41)))));
-
- row = Sse.LoadVector128(&value1.M41);
- Sse.Store(&value1.M41,
- Sse.Add(Sse.Add(Sse.Multiply(Sse.Shuffle(row, row, 0x00), Sse.LoadVector128(&value2.M11)),
- Sse.Multiply(Sse.Shuffle(row, row, 0x55), Sse.LoadVector128(&value2.M21))),
- Sse.Add(Sse.Multiply(Sse.Shuffle(row, row, 0xAA), Sse.LoadVector128(&value2.M31)),
- Sse.Multiply(Sse.Shuffle(row, row, 0xFF), Sse.LoadVector128(&value2.M41)))));
- return value1;
- }
-
- Matrix4x4 m;
-
- // First row
- m.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21 + value1.M13 * value2.M31 + value1.M14 * value2.M41;
- m.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22 + value1.M13 * value2.M32 + value1.M14 * value2.M42;
- m.M13 = value1.M11 * value2.M13 + value1.M12 * value2.M23 + value1.M13 * value2.M33 + value1.M14 * value2.M43;
- m.M14 = value1.M11 * value2.M14 + value1.M12 * value2.M24 + value1.M13 * value2.M34 + value1.M14 * value2.M44;
-
- // Second row
- m.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21 + value1.M23 * value2.M31 + value1.M24 * value2.M41;
- m.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22 + value1.M23 * value2.M32 + value1.M24 * value2.M42;
- m.M23 = value1.M21 * value2.M13 + value1.M22 * value2.M23 + value1.M23 * value2.M33 + value1.M24 * value2.M43;
- m.M24 = value1.M21 * value2.M14 + value1.M22 * value2.M24 + value1.M23 * value2.M34 + value1.M24 * value2.M44;
-
- // Third row
- m.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value1.M33 * value2.M31 + value1.M34 * value2.M41;
- m.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value1.M33 * value2.M32 + value1.M34 * value2.M42;
- m.M33 = value1.M31 * value2.M13 + value1.M32 * value2.M23 + value1.M33 * value2.M33 + value1.M34 * value2.M43;
- m.M34 = value1.M31 * value2.M14 + value1.M32 * value2.M24 + value1.M33 * value2.M34 + value1.M34 * value2.M44;
-
- // Fourth row
- m.M41 = value1.M41 * value2.M11 + value1.M42 * value2.M21 + value1.M43 * value2.M31 + value1.M44 * value2.M41;
- m.M42 = value1.M41 * value2.M12 + value1.M42 * value2.M22 + value1.M43 * value2.M32 + value1.M44 * value2.M42;
- m.M43 = value1.M41 * value2.M13 + value1.M42 * value2.M23 + value1.M43 * value2.M33 + value1.M44 * value2.M43;
- m.M44 = value1.M41 * value2.M14 + value1.M42 * value2.M24 + value1.M43 * value2.M34 + value1.M44 * value2.M44;
-
- return m;
- }
-
- /// <summary>
- /// Multiplies a matrix by a scalar value.
- /// </summary>
- /// <param name="value1">The source matrix.</param>
- /// <param name="value2">The scaling factor.</param>
- /// <returns>The scaled matrix.</returns>
- public static unsafe Matrix4x4 operator *(Matrix4x4 value1, float value2)
- {
- if (Sse.IsSupported)
- {
- Vector128<float> value2Vec = Vector128.Create(value2);
- Sse.Store(&value1.M11, Sse.Multiply(Sse.LoadVector128(&value1.M11), value2Vec));
- Sse.Store(&value1.M21, Sse.Multiply(Sse.LoadVector128(&value1.M21), value2Vec));
- Sse.Store(&value1.M31, Sse.Multiply(Sse.LoadVector128(&value1.M31), value2Vec));
- Sse.Store(&value1.M41, Sse.Multiply(Sse.LoadVector128(&value1.M41), value2Vec));
- return value1;
- }
-
- Matrix4x4 m;
-
- m.M11 = value1.M11 * value2;
- m.M12 = value1.M12 * value2;
- m.M13 = value1.M13 * value2;
- m.M14 = value1.M14 * value2;
- m.M21 = value1.M21 * value2;
- m.M22 = value1.M22 * value2;
- m.M23 = value1.M23 * value2;
- m.M24 = value1.M24 * value2;
- m.M31 = value1.M31 * value2;
- m.M32 = value1.M32 * value2;
- m.M33 = value1.M33 * value2;
- m.M34 = value1.M34 * value2;
- m.M41 = value1.M41 * value2;
- m.M42 = value1.M42 * value2;
- m.M43 = value1.M43 * value2;
- m.M44 = value1.M44 * value2;
- return m;
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given two matrices are equal.
- /// </summary>
- /// <param name="value1">The first matrix to compare.</param>
- /// <param name="value2">The second matrix to compare.</param>
- /// <returns>True if the given matrices are equal; False otherwise.</returns>
- public static unsafe bool operator ==(Matrix4x4 value1, Matrix4x4 value2)
- {
- if (Sse.IsSupported)
- {
- return
- VectorMath.Equal(Sse.LoadVector128(&value1.M11), Sse.LoadVector128(&value2.M11)) &&
- VectorMath.Equal(Sse.LoadVector128(&value1.M21), Sse.LoadVector128(&value2.M21)) &&
- VectorMath.Equal(Sse.LoadVector128(&value1.M31), Sse.LoadVector128(&value2.M31)) &&
- VectorMath.Equal(Sse.LoadVector128(&value1.M41), Sse.LoadVector128(&value2.M41));
- }
-
- return (value1.M11 == value2.M11 && value1.M22 == value2.M22 && value1.M33 == value2.M33 && value1.M44 == value2.M44 && // Check diagonal element first for early out.
- value1.M12 == value2.M12 && value1.M13 == value2.M13 && value1.M14 == value2.M14 && value1.M21 == value2.M21 &&
- value1.M23 == value2.M23 && value1.M24 == value2.M24 && value1.M31 == value2.M31 && value1.M32 == value2.M32 &&
- value1.M34 == value2.M34 && value1.M41 == value2.M41 && value1.M42 == value2.M42 && value1.M43 == value2.M43);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given two matrices are not equal.
- /// </summary>
- /// <param name="value1">The first matrix to compare.</param>
- /// <param name="value2">The second matrix to compare.</param>
- /// <returns>True if the given matrices are not equal; False if they are equal.</returns>
- public static unsafe bool operator !=(Matrix4x4 value1, Matrix4x4 value2)
- {
- if (Sse.IsSupported)
- {
- return
- VectorMath.NotEqual(Sse.LoadVector128(&value1.M11), Sse.LoadVector128(&value2.M11)) ||
- VectorMath.NotEqual(Sse.LoadVector128(&value1.M21), Sse.LoadVector128(&value2.M21)) ||
- VectorMath.NotEqual(Sse.LoadVector128(&value1.M31), Sse.LoadVector128(&value2.M31)) ||
- VectorMath.NotEqual(Sse.LoadVector128(&value1.M41), Sse.LoadVector128(&value2.M41));
- }
-
- return (value1.M11 != value2.M11 || value1.M12 != value2.M12 || value1.M13 != value2.M13 || value1.M14 != value2.M14 ||
- value1.M21 != value2.M21 || value1.M22 != value2.M22 || value1.M23 != value2.M23 || value1.M24 != value2.M24 ||
- value1.M31 != value2.M31 || value1.M32 != value2.M32 || value1.M33 != value2.M33 || value1.M34 != value2.M34 ||
- value1.M41 != value2.M41 || value1.M42 != value2.M42 || value1.M43 != value2.M43 || value1.M44 != value2.M44);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether this matrix instance is equal to the other given matrix.
- /// </summary>
- /// <param name="other">The matrix to compare this instance to.</param>
- /// <returns>True if the matrices are equal; False otherwise.</returns>
- public readonly bool Equals(Matrix4x4 other) => this == other;
-
- /// <summary>
- /// Returns a boolean indicating whether the given Object is equal to this matrix instance.
- /// </summary>
- /// <param name="obj">The Object to compare against.</param>
- /// <returns>True if the Object is equal to this matrix; False otherwise.</returns>
- public override readonly bool Equals(object? obj) => (obj is Matrix4x4 other) && (this == other);
-
- /// <summary>
- /// Returns a String representing this matrix instance.
- /// </summary>
- /// <returns>The string representation.</returns>
- public override readonly string ToString()
- {
- return string.Format(CultureInfo.CurrentCulture, "{{ {{M11:{0} M12:{1} M13:{2} M14:{3}}} {{M21:{4} M22:{5} M23:{6} M24:{7}}} {{M31:{8} M32:{9} M33:{10} M34:{11}}} {{M41:{12} M42:{13} M43:{14} M44:{15}}} }}",
- M11, M12, M13, M14,
- M21, M22, M23, M24,
- M31, M32, M33, M34,
- M41, M42, M43, M44);
- }
-
- /// <summary>
- /// Returns the hash code for this instance.
- /// </summary>
- /// <returns>The hash code.</returns>
- public override readonly int GetHashCode()
- {
- unchecked
- {
- return M11.GetHashCode() + M12.GetHashCode() + M13.GetHashCode() + M14.GetHashCode() +
- M21.GetHashCode() + M22.GetHashCode() + M23.GetHashCode() + M24.GetHashCode() +
- M31.GetHashCode() + M32.GetHashCode() + M33.GetHashCode() + M34.GetHashCode() +
- M41.GetHashCode() + M42.GetHashCode() + M43.GetHashCode() + M44.GetHashCode();
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Plane.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Plane.cs
deleted file mode 100644
index 7c4c376dda9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Plane.cs
+++ /dev/null
@@ -1,368 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-
-namespace System.Numerics
-{
- /// <summary>
- /// A structure encapsulating a 3D Plane
- /// </summary>
- public struct Plane : IEquatable<Plane>
- {
- private const float NormalizeEpsilon = 1.192092896e-07f; // smallest such that 1.0+NormalizeEpsilon != 1.0
-
- /// <summary>
- /// The normal vector of the Plane.
- /// </summary>
- public Vector3 Normal;
- /// <summary>
- /// The distance of the Plane along its normal from the origin.
- /// </summary>
- public float D;
-
- /// <summary>
- /// Constructs a Plane from the X, Y, and Z components of its normal, and its distance from the origin on that normal.
- /// </summary>
- /// <param name="x">The X-component of the normal.</param>
- /// <param name="y">The Y-component of the normal.</param>
- /// <param name="z">The Z-component of the normal.</param>
- /// <param name="d">The distance of the Plane along its normal from the origin.</param>
- public Plane(float x, float y, float z, float d)
- {
- Normal = new Vector3(x, y, z);
- this.D = d;
- }
-
- /// <summary>
- /// Constructs a Plane from the given normal and distance along the normal from the origin.
- /// </summary>
- /// <param name="normal">The Plane's normal vector.</param>
- /// <param name="d">The Plane's distance from the origin along its normal vector.</param>
- public Plane(Vector3 normal, float d)
- {
- this.Normal = normal;
- this.D = d;
- }
-
- /// <summary>
- /// Constructs a Plane from the given Vector4.
- /// </summary>
- /// <param name="value">A vector whose first 3 elements describe the normal vector,
- /// and whose W component defines the distance along that normal from the origin.</param>
- public Plane(Vector4 value)
- {
- Normal = new Vector3(value.X, value.Y, value.Z);
- D = value.W;
- }
-
- /// <summary>
- /// Creates a Plane that contains the three given points.
- /// </summary>
- /// <param name="point1">The first point defining the Plane.</param>
- /// <param name="point2">The second point defining the Plane.</param>
- /// <param name="point3">The third point defining the Plane.</param>
- /// <returns>The Plane containing the three points.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Plane CreateFromVertices(Vector3 point1, Vector3 point2, Vector3 point3)
- {
- if (Vector.IsHardwareAccelerated)
- {
- Vector3 a = point2 - point1;
- Vector3 b = point3 - point1;
-
- // N = Cross(a, b)
- Vector3 n = Vector3.Cross(a, b);
- Vector3 normal = Vector3.Normalize(n);
-
- // D = - Dot(N, point1)
- float d = -Vector3.Dot(normal, point1);
-
- return new Plane(normal, d);
- }
- else
- {
- float ax = point2.X - point1.X;
- float ay = point2.Y - point1.Y;
- float az = point2.Z - point1.Z;
-
- float bx = point3.X - point1.X;
- float by = point3.Y - point1.Y;
- float bz = point3.Z - point1.Z;
-
- // N=Cross(a,b)
- float nx = ay * bz - az * by;
- float ny = az * bx - ax * bz;
- float nz = ax * by - ay * bx;
-
- // Normalize(N)
- float ls = nx * nx + ny * ny + nz * nz;
- float invNorm = 1.0f / MathF.Sqrt(ls);
-
- Vector3 normal = new Vector3(
- nx * invNorm,
- ny * invNorm,
- nz * invNorm);
-
- return new Plane(
- normal,
- -(normal.X * point1.X + normal.Y * point1.Y + normal.Z * point1.Z));
- }
- }
-
- /// <summary>
- /// Creates a new Plane whose normal vector is the source Plane's normal vector normalized.
- /// </summary>
- /// <param name="value">The source Plane.</param>
- /// <returns>The normalized Plane.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Plane Normalize(Plane value)
- {
- if (Vector.IsHardwareAccelerated)
- {
- float normalLengthSquared = value.Normal.LengthSquared();
- if (MathF.Abs(normalLengthSquared - 1.0f) < NormalizeEpsilon)
- {
- // It already normalized, so we don't need to farther process.
- return value;
- }
- float normalLength = MathF.Sqrt(normalLengthSquared);
- return new Plane(
- value.Normal / normalLength,
- value.D / normalLength);
- }
- else
- {
- float f = value.Normal.X * value.Normal.X + value.Normal.Y * value.Normal.Y + value.Normal.Z * value.Normal.Z;
-
- if (MathF.Abs(f - 1.0f) < NormalizeEpsilon)
- {
- return value; // It already normalized, so we don't need to further process.
- }
-
- float fInv = 1.0f / MathF.Sqrt(f);
-
- return new Plane(
- value.Normal.X * fInv,
- value.Normal.Y * fInv,
- value.Normal.Z * fInv,
- value.D * fInv);
- }
- }
-
- /// <summary>
- /// Transforms a normalized Plane by a Matrix.
- /// </summary>
- /// <param name="plane"> The normalized Plane to transform.
- /// This Plane must already be normalized, so that its Normal vector is of unit length, before this method is called.</param>
- /// <param name="matrix">The transformation matrix to apply to the Plane.</param>
- /// <returns>The transformed Plane.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Plane Transform(Plane plane, Matrix4x4 matrix)
- {
- Matrix4x4 m;
- Matrix4x4.Invert(matrix, out m);
-
- float x = plane.Normal.X, y = plane.Normal.Y, z = plane.Normal.Z, w = plane.D;
-
- return new Plane(
- x * m.M11 + y * m.M12 + z * m.M13 + w * m.M14,
- x * m.M21 + y * m.M22 + z * m.M23 + w * m.M24,
- x * m.M31 + y * m.M32 + z * m.M33 + w * m.M34,
- x * m.M41 + y * m.M42 + z * m.M43 + w * m.M44);
- }
-
- /// <summary>
- /// Transforms a normalized Plane by a Quaternion rotation.
- /// </summary>
- /// <param name="plane"> The normalized Plane to transform.
- /// This Plane must already be normalized, so that its Normal vector is of unit length, before this method is called.</param>
- /// <param name="rotation">The Quaternion rotation to apply to the Plane.</param>
- /// <returns>A new Plane that results from applying the rotation.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Plane Transform(Plane plane, Quaternion rotation)
- {
- // Compute rotation matrix.
- float x2 = rotation.X + rotation.X;
- float y2 = rotation.Y + rotation.Y;
- float z2 = rotation.Z + rotation.Z;
-
- float wx2 = rotation.W * x2;
- float wy2 = rotation.W * y2;
- float wz2 = rotation.W * z2;
- float xx2 = rotation.X * x2;
- float xy2 = rotation.X * y2;
- float xz2 = rotation.X * z2;
- float yy2 = rotation.Y * y2;
- float yz2 = rotation.Y * z2;
- float zz2 = rotation.Z * z2;
-
- float m11 = 1.0f - yy2 - zz2;
- float m21 = xy2 - wz2;
- float m31 = xz2 + wy2;
-
- float m12 = xy2 + wz2;
- float m22 = 1.0f - xx2 - zz2;
- float m32 = yz2 - wx2;
-
- float m13 = xz2 - wy2;
- float m23 = yz2 + wx2;
- float m33 = 1.0f - xx2 - yy2;
-
- float x = plane.Normal.X, y = plane.Normal.Y, z = plane.Normal.Z;
-
- return new Plane(
- x * m11 + y * m21 + z * m31,
- x * m12 + y * m22 + z * m32,
- x * m13 + y * m23 + z * m33,
- plane.D);
- }
-
- /// <summary>
- /// Calculates the dot product of a Plane and Vector4.
- /// </summary>
- /// <param name="plane">The Plane.</param>
- /// <param name="value">The Vector4.</param>
- /// <returns>The dot product.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Dot(Plane plane, Vector4 value)
- {
- return plane.Normal.X * value.X +
- plane.Normal.Y * value.Y +
- plane.Normal.Z * value.Z +
- plane.D * value.W;
- }
-
- /// <summary>
- /// Returns the dot product of a specified Vector3 and the normal vector of this Plane plus the distance (D) value of the Plane.
- /// </summary>
- /// <param name="plane">The plane.</param>
- /// <param name="value">The Vector3.</param>
- /// <returns>The resulting value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float DotCoordinate(Plane plane, Vector3 value)
- {
- if (Vector.IsHardwareAccelerated)
- {
- return Vector3.Dot(plane.Normal, value) + plane.D;
- }
- else
- {
- return plane.Normal.X * value.X +
- plane.Normal.Y * value.Y +
- plane.Normal.Z * value.Z +
- plane.D;
- }
- }
-
- /// <summary>
- /// Returns the dot product of a specified Vector3 and the Normal vector of this Plane.
- /// </summary>
- /// <param name="plane">The plane.</param>
- /// <param name="value">The Vector3.</param>
- /// <returns>The resulting dot product.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float DotNormal(Plane plane, Vector3 value)
- {
- if (Vector.IsHardwareAccelerated)
- {
- return Vector3.Dot(plane.Normal, value);
- }
- else
- {
- return plane.Normal.X * value.X +
- plane.Normal.Y * value.Y +
- plane.Normal.Z * value.Z;
- }
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the two given Planes are equal.
- /// </summary>
- /// <param name="value1">The first Plane to compare.</param>
- /// <param name="value2">The second Plane to compare.</param>
- /// <returns>True if the Planes are equal; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Plane value1, Plane value2)
- {
- return (value1.Normal.X == value2.Normal.X &&
- value1.Normal.Y == value2.Normal.Y &&
- value1.Normal.Z == value2.Normal.Z &&
- value1.D == value2.D);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the two given Planes are not equal.
- /// </summary>
- /// <param name="value1">The first Plane to compare.</param>
- /// <param name="value2">The second Plane to compare.</param>
- /// <returns>True if the Planes are not equal; False if they are equal.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(Plane value1, Plane value2)
- {
- return (value1.Normal.X != value2.Normal.X ||
- value1.Normal.Y != value2.Normal.Y ||
- value1.Normal.Z != value2.Normal.Z ||
- value1.D != value2.D);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Plane is equal to this Plane instance.
- /// </summary>
- /// <param name="other">The Plane to compare this instance to.</param>
- /// <returns>True if the other Plane is equal to this instance; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly bool Equals(Plane other)
- {
- if (Vector.IsHardwareAccelerated)
- {
- return this.Normal.Equals(other.Normal) && this.D == other.D;
- }
- else
- {
- return (Normal.X == other.Normal.X &&
- Normal.Y == other.Normal.Y &&
- Normal.Z == other.Normal.Z &&
- D == other.D);
- }
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Object is equal to this Plane instance.
- /// </summary>
- /// <param name="obj">The Object to compare against.</param>
- /// <returns>True if the Object is equal to this Plane; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override readonly bool Equals(object? obj)
- {
- if (obj is Plane)
- {
- return Equals((Plane)obj);
- }
-
- return false;
- }
-
- /// <summary>
- /// Returns a String representing this Plane instance.
- /// </summary>
- /// <returns>The string representation.</returns>
- public override readonly string ToString()
- {
- CultureInfo ci = CultureInfo.CurrentCulture;
-
- return string.Format(ci, "{{Normal:{0} D:{1}}}", Normal.ToString(), D.ToString(ci));
- }
-
- /// <summary>
- /// Returns the hash code for this instance.
- /// </summary>
- /// <returns>The hash code.</returns>
- public override readonly int GetHashCode()
- {
- return Normal.GetHashCode() + D.GetHashCode();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Quaternion.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Quaternion.cs
deleted file mode 100644
index 9e4be76f635..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Quaternion.cs
+++ /dev/null
@@ -1,792 +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 System.Globalization;
-
-namespace System.Numerics
-{
- /// <summary>
- /// A structure encapsulating a four-dimensional vector (x,y,z,w),
- /// which is used to efficiently rotate an object about the (x,y,z) vector by the angle theta, where w = cos(theta/2).
- /// </summary>
- public struct Quaternion : IEquatable<Quaternion>
- {
- private const float SlerpEpsilon = 1e-6f;
-
- /// <summary>
- /// Specifies the X-value of the vector component of the Quaternion.
- /// </summary>
- public float X;
- /// <summary>
- /// Specifies the Y-value of the vector component of the Quaternion.
- /// </summary>
- public float Y;
- /// <summary>
- /// Specifies the Z-value of the vector component of the Quaternion.
- /// </summary>
- public float Z;
- /// <summary>
- /// Specifies the rotation component of the Quaternion.
- /// </summary>
- public float W;
-
- /// <summary>
- /// Returns a Quaternion representing no rotation.
- /// </summary>
- public static Quaternion Identity
- {
- get { return new Quaternion(0, 0, 0, 1); }
- }
-
- /// <summary>
- /// Returns whether the Quaternion is the identity Quaternion.
- /// </summary>
- public readonly bool IsIdentity
- {
- get { return X == 0f && Y == 0f && Z == 0f && W == 1f; }
- }
-
- /// <summary>
- /// Constructs a Quaternion from the given components.
- /// </summary>
- /// <param name="x">The X component of the Quaternion.</param>
- /// <param name="y">The Y component of the Quaternion.</param>
- /// <param name="z">The Z component of the Quaternion.</param>
- /// <param name="w">The W component of the Quaternion.</param>
- public Quaternion(float x, float y, float z, float w)
- {
- this.X = x;
- this.Y = y;
- this.Z = z;
- this.W = w;
- }
-
- /// <summary>
- /// Constructs a Quaternion from the given vector and rotation parts.
- /// </summary>
- /// <param name="vectorPart">The vector part of the Quaternion.</param>
- /// <param name="scalarPart">The rotation part of the Quaternion.</param>
- public Quaternion(Vector3 vectorPart, float scalarPart)
- {
- X = vectorPart.X;
- Y = vectorPart.Y;
- Z = vectorPart.Z;
- W = scalarPart;
- }
-
- /// <summary>
- /// Calculates the length of the Quaternion.
- /// </summary>
- /// <returns>The computed length of the Quaternion.</returns>
- public readonly float Length()
- {
- float ls = X * X + Y * Y + Z * Z + W * W;
-
- return MathF.Sqrt(ls);
- }
-
- /// <summary>
- /// Calculates the length squared of the Quaternion. This operation is cheaper than Length().
- /// </summary>
- /// <returns>The length squared of the Quaternion.</returns>
- public readonly float LengthSquared()
- {
- return X * X + Y * Y + Z * Z + W * W;
- }
-
- /// <summary>
- /// Divides each component of the Quaternion by the length of the Quaternion.
- /// </summary>
- /// <param name="value">The source Quaternion.</param>
- /// <returns>The normalized Quaternion.</returns>
- public static Quaternion Normalize(Quaternion value)
- {
- Quaternion ans;
-
- float ls = value.X * value.X + value.Y * value.Y + value.Z * value.Z + value.W * value.W;
-
- float invNorm = 1.0f / MathF.Sqrt(ls);
-
- ans.X = value.X * invNorm;
- ans.Y = value.Y * invNorm;
- ans.Z = value.Z * invNorm;
- ans.W = value.W * invNorm;
-
- return ans;
- }
-
- /// <summary>
- /// Creates the conjugate of a specified Quaternion.
- /// </summary>
- /// <param name="value">The Quaternion of which to return the conjugate.</param>
- /// <returns>A new Quaternion that is the conjugate of the specified one.</returns>
- public static Quaternion Conjugate(Quaternion value)
- {
- Quaternion ans;
-
- ans.X = -value.X;
- ans.Y = -value.Y;
- ans.Z = -value.Z;
- ans.W = value.W;
-
- return ans;
- }
-
- /// <summary>
- /// Returns the inverse of a Quaternion.
- /// </summary>
- /// <param name="value">The source Quaternion.</param>
- /// <returns>The inverted Quaternion.</returns>
- public static Quaternion Inverse(Quaternion value)
- {
- // -1 ( a -v )
- // q = ( ------------- ------------- )
- // ( a^2 + |v|^2 , a^2 + |v|^2 )
-
- Quaternion ans;
-
- float ls = value.X * value.X + value.Y * value.Y + value.Z * value.Z + value.W * value.W;
- float invNorm = 1.0f / ls;
-
- ans.X = -value.X * invNorm;
- ans.Y = -value.Y * invNorm;
- ans.Z = -value.Z * invNorm;
- ans.W = value.W * invNorm;
-
- return ans;
- }
-
- /// <summary>
- /// Creates a Quaternion from a normalized vector axis and an angle to rotate about the vector.
- /// </summary>
- /// <param name="axis">The unit vector to rotate around.
- /// This vector must be normalized before calling this function or the resulting Quaternion will be incorrect.</param>
- /// <param name="angle">The angle, in radians, to rotate around the vector.</param>
- /// <returns>The created Quaternion.</returns>
- public static Quaternion CreateFromAxisAngle(Vector3 axis, float angle)
- {
- Quaternion ans;
-
- float halfAngle = angle * 0.5f;
- float s = MathF.Sin(halfAngle);
- float c = MathF.Cos(halfAngle);
-
- ans.X = axis.X * s;
- ans.Y = axis.Y * s;
- ans.Z = axis.Z * s;
- ans.W = c;
-
- return ans;
- }
-
- /// <summary>
- /// Creates a new Quaternion from the given yaw, pitch, and roll, in radians.
- /// </summary>
- /// <param name="yaw">The yaw angle, in radians, around the Y-axis.</param>
- /// <param name="pitch">The pitch angle, in radians, around the X-axis.</param>
- /// <param name="roll">The roll angle, in radians, around the Z-axis.</param>
- /// <returns></returns>
- public static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll)
- {
- // Roll first, about axis the object is facing, then
- // pitch upward, then yaw to face into the new heading
- float sr, cr, sp, cp, sy, cy;
-
- float halfRoll = roll * 0.5f;
- sr = MathF.Sin(halfRoll);
- cr = MathF.Cos(halfRoll);
-
- float halfPitch = pitch * 0.5f;
- sp = MathF.Sin(halfPitch);
- cp = MathF.Cos(halfPitch);
-
- float halfYaw = yaw * 0.5f;
- sy = MathF.Sin(halfYaw);
- cy = MathF.Cos(halfYaw);
-
- Quaternion result;
-
- result.X = cy * sp * cr + sy * cp * sr;
- result.Y = sy * cp * cr - cy * sp * sr;
- result.Z = cy * cp * sr - sy * sp * cr;
- result.W = cy * cp * cr + sy * sp * sr;
-
- return result;
- }
-
- /// <summary>
- /// Creates a Quaternion from the given rotation matrix.
- /// </summary>
- /// <param name="matrix">The rotation matrix.</param>
- /// <returns>The created Quaternion.</returns>
- public static Quaternion CreateFromRotationMatrix(Matrix4x4 matrix)
- {
- float trace = matrix.M11 + matrix.M22 + matrix.M33;
-
- Quaternion q = default;
-
- if (trace > 0.0f)
- {
- float s = MathF.Sqrt(trace + 1.0f);
- q.W = s * 0.5f;
- s = 0.5f / s;
- q.X = (matrix.M23 - matrix.M32) * s;
- q.Y = (matrix.M31 - matrix.M13) * s;
- q.Z = (matrix.M12 - matrix.M21) * s;
- }
- else
- {
- if (matrix.M11 >= matrix.M22 && matrix.M11 >= matrix.M33)
- {
- float s = MathF.Sqrt(1.0f + matrix.M11 - matrix.M22 - matrix.M33);
- float invS = 0.5f / s;
- q.X = 0.5f * s;
- q.Y = (matrix.M12 + matrix.M21) * invS;
- q.Z = (matrix.M13 + matrix.M31) * invS;
- q.W = (matrix.M23 - matrix.M32) * invS;
- }
- else if (matrix.M22 > matrix.M33)
- {
- float s = MathF.Sqrt(1.0f + matrix.M22 - matrix.M11 - matrix.M33);
- float invS = 0.5f / s;
- q.X = (matrix.M21 + matrix.M12) * invS;
- q.Y = 0.5f * s;
- q.Z = (matrix.M32 + matrix.M23) * invS;
- q.W = (matrix.M31 - matrix.M13) * invS;
- }
- else
- {
- float s = MathF.Sqrt(1.0f + matrix.M33 - matrix.M11 - matrix.M22);
- float invS = 0.5f / s;
- q.X = (matrix.M31 + matrix.M13) * invS;
- q.Y = (matrix.M32 + matrix.M23) * invS;
- q.Z = 0.5f * s;
- q.W = (matrix.M12 - matrix.M21) * invS;
- }
- }
-
- return q;
- }
-
- /// <summary>
- /// Calculates the dot product of two Quaternions.
- /// </summary>
- /// <param name="quaternion1">The first source Quaternion.</param>
- /// <param name="quaternion2">The second source Quaternion.</param>
- /// <returns>The dot product of the Quaternions.</returns>
- public static float Dot(Quaternion quaternion1, Quaternion quaternion2)
- {
- return quaternion1.X * quaternion2.X +
- quaternion1.Y * quaternion2.Y +
- quaternion1.Z * quaternion2.Z +
- quaternion1.W * quaternion2.W;
- }
-
- /// <summary>
- /// Interpolates between two quaternions, using spherical linear interpolation.
- /// </summary>
- /// <param name="quaternion1">The first source Quaternion.</param>
- /// <param name="quaternion2">The second source Quaternion.</param>
- /// <param name="amount">The relative weight of the second source Quaternion in the interpolation.</param>
- /// <returns>The interpolated Quaternion.</returns>
- public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount)
- {
- float t = amount;
-
- float cosOmega = quaternion1.X * quaternion2.X + quaternion1.Y * quaternion2.Y +
- quaternion1.Z * quaternion2.Z + quaternion1.W * quaternion2.W;
-
- bool flip = false;
-
- if (cosOmega < 0.0f)
- {
- flip = true;
- cosOmega = -cosOmega;
- }
-
- float s1, s2;
-
- if (cosOmega > (1.0f - SlerpEpsilon))
- {
- // Too close, do straight linear interpolation.
- s1 = 1.0f - t;
- s2 = (flip) ? -t : t;
- }
- else
- {
- float omega = MathF.Acos(cosOmega);
- float invSinOmega = 1 / MathF.Sin(omega);
-
- s1 = MathF.Sin((1.0f - t) * omega) * invSinOmega;
- s2 = (flip)
- ? -MathF.Sin(t * omega) * invSinOmega
- : MathF.Sin(t * omega) * invSinOmega;
- }
-
- Quaternion ans;
-
- ans.X = s1 * quaternion1.X + s2 * quaternion2.X;
- ans.Y = s1 * quaternion1.Y + s2 * quaternion2.Y;
- ans.Z = s1 * quaternion1.Z + s2 * quaternion2.Z;
- ans.W = s1 * quaternion1.W + s2 * quaternion2.W;
-
- return ans;
- }
-
- /// <summary>
- /// Linearly interpolates between two quaternions.
- /// </summary>
- /// <param name="quaternion1">The first source Quaternion.</param>
- /// <param name="quaternion2">The second source Quaternion.</param>
- /// <param name="amount">The relative weight of the second source Quaternion in the interpolation.</param>
- /// <returns>The interpolated Quaternion.</returns>
- public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, float amount)
- {
- float t = amount;
- float t1 = 1.0f - t;
-
- Quaternion r = default;
-
- float dot = quaternion1.X * quaternion2.X + quaternion1.Y * quaternion2.Y +
- quaternion1.Z * quaternion2.Z + quaternion1.W * quaternion2.W;
-
- if (dot >= 0.0f)
- {
- r.X = t1 * quaternion1.X + t * quaternion2.X;
- r.Y = t1 * quaternion1.Y + t * quaternion2.Y;
- r.Z = t1 * quaternion1.Z + t * quaternion2.Z;
- r.W = t1 * quaternion1.W + t * quaternion2.W;
- }
- else
- {
- r.X = t1 * quaternion1.X - t * quaternion2.X;
- r.Y = t1 * quaternion1.Y - t * quaternion2.Y;
- r.Z = t1 * quaternion1.Z - t * quaternion2.Z;
- r.W = t1 * quaternion1.W - t * quaternion2.W;
- }
-
- // Normalize it.
- float ls = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
- float invNorm = 1.0f / MathF.Sqrt(ls);
-
- r.X *= invNorm;
- r.Y *= invNorm;
- r.Z *= invNorm;
- r.W *= invNorm;
-
- return r;
- }
-
- /// <summary>
- /// Concatenates two Quaternions; the result represents the value1 rotation followed by the value2 rotation.
- /// </summary>
- /// <param name="value1">The first Quaternion rotation in the series.</param>
- /// <param name="value2">The second Quaternion rotation in the series.</param>
- /// <returns>A new Quaternion representing the concatenation of the value1 rotation followed by the value2 rotation.</returns>
- public static Quaternion Concatenate(Quaternion value1, Quaternion value2)
- {
- Quaternion ans;
-
- // Concatenate rotation is actually q2 * q1 instead of q1 * q2.
- // So that's why value2 goes q1 and value1 goes q2.
- float q1x = value2.X;
- float q1y = value2.Y;
- float q1z = value2.Z;
- float q1w = value2.W;
-
- float q2x = value1.X;
- float q2y = value1.Y;
- float q2z = value1.Z;
- float q2w = value1.W;
-
- // cross(av, bv)
- float cx = q1y * q2z - q1z * q2y;
- float cy = q1z * q2x - q1x * q2z;
- float cz = q1x * q2y - q1y * q2x;
-
- float dot = q1x * q2x + q1y * q2y + q1z * q2z;
-
- ans.X = q1x * q2w + q2x * q1w + cx;
- ans.Y = q1y * q2w + q2y * q1w + cy;
- ans.Z = q1z * q2w + q2z * q1w + cz;
- ans.W = q1w * q2w - dot;
-
- return ans;
- }
-
- /// <summary>
- /// Flips the sign of each component of the quaternion.
- /// </summary>
- /// <param name="value">The source Quaternion.</param>
- /// <returns>The negated Quaternion.</returns>
- public static Quaternion Negate(Quaternion value)
- {
- Quaternion ans;
-
- ans.X = -value.X;
- ans.Y = -value.Y;
- ans.Z = -value.Z;
- ans.W = -value.W;
-
- return ans;
- }
-
- /// <summary>
- /// Adds two Quaternions element-by-element.
- /// </summary>
- /// <param name="value1">The first source Quaternion.</param>
- /// <param name="value2">The second source Quaternion.</param>
- /// <returns>The result of adding the Quaternions.</returns>
- public static Quaternion Add(Quaternion value1, Quaternion value2)
- {
- Quaternion ans;
-
- ans.X = value1.X + value2.X;
- ans.Y = value1.Y + value2.Y;
- ans.Z = value1.Z + value2.Z;
- ans.W = value1.W + value2.W;
-
- return ans;
- }
-
- /// <summary>
- /// Subtracts one Quaternion from another.
- /// </summary>
- /// <param name="value1">The first source Quaternion.</param>
- /// <param name="value2">The second Quaternion, to be subtracted from the first.</param>
- /// <returns>The result of the subtraction.</returns>
- public static Quaternion Subtract(Quaternion value1, Quaternion value2)
- {
- Quaternion ans;
-
- ans.X = value1.X - value2.X;
- ans.Y = value1.Y - value2.Y;
- ans.Z = value1.Z - value2.Z;
- ans.W = value1.W - value2.W;
-
- return ans;
- }
-
- /// <summary>
- /// Multiplies two Quaternions together.
- /// </summary>
- /// <param name="value1">The Quaternion on the left side of the multiplication.</param>
- /// <param name="value2">The Quaternion on the right side of the multiplication.</param>
- /// <returns>The result of the multiplication.</returns>
- public static Quaternion Multiply(Quaternion value1, Quaternion value2)
- {
- Quaternion ans;
-
- float q1x = value1.X;
- float q1y = value1.Y;
- float q1z = value1.Z;
- float q1w = value1.W;
-
- float q2x = value2.X;
- float q2y = value2.Y;
- float q2z = value2.Z;
- float q2w = value2.W;
-
- // cross(av, bv)
- float cx = q1y * q2z - q1z * q2y;
- float cy = q1z * q2x - q1x * q2z;
- float cz = q1x * q2y - q1y * q2x;
-
- float dot = q1x * q2x + q1y * q2y + q1z * q2z;
-
- ans.X = q1x * q2w + q2x * q1w + cx;
- ans.Y = q1y * q2w + q2y * q1w + cy;
- ans.Z = q1z * q2w + q2z * q1w + cz;
- ans.W = q1w * q2w - dot;
-
- return ans;
- }
-
- /// <summary>
- /// Multiplies a Quaternion by a scalar value.
- /// </summary>
- /// <param name="value1">The source Quaternion.</param>
- /// <param name="value2">The scalar value.</param>
- /// <returns>The result of the multiplication.</returns>
- public static Quaternion Multiply(Quaternion value1, float value2)
- {
- Quaternion ans;
-
- ans.X = value1.X * value2;
- ans.Y = value1.Y * value2;
- ans.Z = value1.Z * value2;
- ans.W = value1.W * value2;
-
- return ans;
- }
-
- /// <summary>
- /// Divides a Quaternion by another Quaternion.
- /// </summary>
- /// <param name="value1">The source Quaternion.</param>
- /// <param name="value2">The divisor.</param>
- /// <returns>The result of the division.</returns>
- public static Quaternion Divide(Quaternion value1, Quaternion value2)
- {
- Quaternion ans;
-
- float q1x = value1.X;
- float q1y = value1.Y;
- float q1z = value1.Z;
- float q1w = value1.W;
-
- //-------------------------------------
- // Inverse part.
- float ls = value2.X * value2.X + value2.Y * value2.Y +
- value2.Z * value2.Z + value2.W * value2.W;
- float invNorm = 1.0f / ls;
-
- float q2x = -value2.X * invNorm;
- float q2y = -value2.Y * invNorm;
- float q2z = -value2.Z * invNorm;
- float q2w = value2.W * invNorm;
-
- //-------------------------------------
- // Multiply part.
-
- // cross(av, bv)
- float cx = q1y * q2z - q1z * q2y;
- float cy = q1z * q2x - q1x * q2z;
- float cz = q1x * q2y - q1y * q2x;
-
- float dot = q1x * q2x + q1y * q2y + q1z * q2z;
-
- ans.X = q1x * q2w + q2x * q1w + cx;
- ans.Y = q1y * q2w + q2y * q1w + cy;
- ans.Z = q1z * q2w + q2z * q1w + cz;
- ans.W = q1w * q2w - dot;
-
- return ans;
- }
-
- /// <summary>
- /// Flips the sign of each component of the quaternion.
- /// </summary>
- /// <param name="value">The source Quaternion.</param>
- /// <returns>The negated Quaternion.</returns>
- public static Quaternion operator -(Quaternion value)
- {
- Quaternion ans;
-
- ans.X = -value.X;
- ans.Y = -value.Y;
- ans.Z = -value.Z;
- ans.W = -value.W;
-
- return ans;
- }
-
- /// <summary>
- /// Adds two Quaternions element-by-element.
- /// </summary>
- /// <param name="value1">The first source Quaternion.</param>
- /// <param name="value2">The second source Quaternion.</param>
- /// <returns>The result of adding the Quaternions.</returns>
- public static Quaternion operator +(Quaternion value1, Quaternion value2)
- {
- Quaternion ans;
-
- ans.X = value1.X + value2.X;
- ans.Y = value1.Y + value2.Y;
- ans.Z = value1.Z + value2.Z;
- ans.W = value1.W + value2.W;
-
- return ans;
- }
-
- /// <summary>
- /// Subtracts one Quaternion from another.
- /// </summary>
- /// <param name="value1">The first source Quaternion.</param>
- /// <param name="value2">The second Quaternion, to be subtracted from the first.</param>
- /// <returns>The result of the subtraction.</returns>
- public static Quaternion operator -(Quaternion value1, Quaternion value2)
- {
- Quaternion ans;
-
- ans.X = value1.X - value2.X;
- ans.Y = value1.Y - value2.Y;
- ans.Z = value1.Z - value2.Z;
- ans.W = value1.W - value2.W;
-
- return ans;
- }
-
- /// <summary>
- /// Multiplies two Quaternions together.
- /// </summary>
- /// <param name="value1">The Quaternion on the left side of the multiplication.</param>
- /// <param name="value2">The Quaternion on the right side of the multiplication.</param>
- /// <returns>The result of the multiplication.</returns>
- public static Quaternion operator *(Quaternion value1, Quaternion value2)
- {
- Quaternion ans;
-
- float q1x = value1.X;
- float q1y = value1.Y;
- float q1z = value1.Z;
- float q1w = value1.W;
-
- float q2x = value2.X;
- float q2y = value2.Y;
- float q2z = value2.Z;
- float q2w = value2.W;
-
- // cross(av, bv)
- float cx = q1y * q2z - q1z * q2y;
- float cy = q1z * q2x - q1x * q2z;
- float cz = q1x * q2y - q1y * q2x;
-
- float dot = q1x * q2x + q1y * q2y + q1z * q2z;
-
- ans.X = q1x * q2w + q2x * q1w + cx;
- ans.Y = q1y * q2w + q2y * q1w + cy;
- ans.Z = q1z * q2w + q2z * q1w + cz;
- ans.W = q1w * q2w - dot;
-
- return ans;
- }
-
- /// <summary>
- /// Multiplies a Quaternion by a scalar value.
- /// </summary>
- /// <param name="value1">The source Quaternion.</param>
- /// <param name="value2">The scalar value.</param>
- /// <returns>The result of the multiplication.</returns>
- public static Quaternion operator *(Quaternion value1, float value2)
- {
- Quaternion ans;
-
- ans.X = value1.X * value2;
- ans.Y = value1.Y * value2;
- ans.Z = value1.Z * value2;
- ans.W = value1.W * value2;
-
- return ans;
- }
-
- /// <summary>
- /// Divides a Quaternion by another Quaternion.
- /// </summary>
- /// <param name="value1">The source Quaternion.</param>
- /// <param name="value2">The divisor.</param>
- /// <returns>The result of the division.</returns>
- public static Quaternion operator /(Quaternion value1, Quaternion value2)
- {
- Quaternion ans;
-
- float q1x = value1.X;
- float q1y = value1.Y;
- float q1z = value1.Z;
- float q1w = value1.W;
-
- //-------------------------------------
- // Inverse part.
- float ls = value2.X * value2.X + value2.Y * value2.Y +
- value2.Z * value2.Z + value2.W * value2.W;
- float invNorm = 1.0f / ls;
-
- float q2x = -value2.X * invNorm;
- float q2y = -value2.Y * invNorm;
- float q2z = -value2.Z * invNorm;
- float q2w = value2.W * invNorm;
-
- //-------------------------------------
- // Multiply part.
-
- // cross(av, bv)
- float cx = q1y * q2z - q1z * q2y;
- float cy = q1z * q2x - q1x * q2z;
- float cz = q1x * q2y - q1y * q2x;
-
- float dot = q1x * q2x + q1y * q2y + q1z * q2z;
-
- ans.X = q1x * q2w + q2x * q1w + cx;
- ans.Y = q1y * q2w + q2y * q1w + cy;
- ans.Z = q1z * q2w + q2z * q1w + cz;
- ans.W = q1w * q2w - dot;
-
- return ans;
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the two given Quaternions are equal.
- /// </summary>
- /// <param name="value1">The first Quaternion to compare.</param>
- /// <param name="value2">The second Quaternion to compare.</param>
- /// <returns>True if the Quaternions are equal; False otherwise.</returns>
- public static bool operator ==(Quaternion value1, Quaternion value2)
- {
- return (value1.X == value2.X &&
- value1.Y == value2.Y &&
- value1.Z == value2.Z &&
- value1.W == value2.W);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the two given Quaternions are not equal.
- /// </summary>
- /// <param name="value1">The first Quaternion to compare.</param>
- /// <param name="value2">The second Quaternion to compare.</param>
- /// <returns>True if the Quaternions are not equal; False if they are equal.</returns>
- public static bool operator !=(Quaternion value1, Quaternion value2)
- {
- return (value1.X != value2.X ||
- value1.Y != value2.Y ||
- value1.Z != value2.Z ||
- value1.W != value2.W);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Quaternion is equal to this Quaternion instance.
- /// </summary>
- /// <param name="other">The Quaternion to compare this instance to.</param>
- /// <returns>True if the other Quaternion is equal to this instance; False otherwise.</returns>
- public readonly bool Equals(Quaternion other)
- {
- return (X == other.X &&
- Y == other.Y &&
- Z == other.Z &&
- W == other.W);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Object is equal to this Quaternion instance.
- /// </summary>
- /// <param name="obj">The Object to compare against.</param>
- /// <returns>True if the Object is equal to this Quaternion; False otherwise.</returns>
- public override readonly bool Equals(object? obj)
- {
- if (obj is Quaternion)
- {
- return Equals((Quaternion)obj);
- }
-
- return false;
- }
-
- /// <summary>
- /// Returns a String representing this Quaternion instance.
- /// </summary>
- /// <returns>The string representation.</returns>
- public override readonly string ToString()
- {
- return string.Format(CultureInfo.CurrentCulture, "{{X:{0} Y:{1} Z:{2} W:{3}}}", X, Y, Z, W);
- }
-
- /// <summary>
- /// Returns the hash code for this instance.
- /// </summary>
- /// <returns>The hash code.</returns>
- public override readonly int GetHashCode()
- {
- return unchecked(X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode() + W.GetHashCode());
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Register.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Register.cs
deleted file mode 100644
index a5dfd5e1301..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Register.cs
+++ /dev/null
@@ -1,173 +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.
-
-#nullable enable
-using System.Runtime.InteropServices;
-
-namespace System.Numerics
-{
- /// <summary>
- /// A structure describing the layout of an SSE2-sized register.
- /// Contains overlapping fields representing the set of valid numeric types.
- /// Allows the generic Vector'T struct to contain an explicit field layout.
- /// </summary>
- [StructLayout(LayoutKind.Explicit)]
- internal struct Register
- {
- #region Internal Storage Fields
- // Internal System.Byte Fields
- [FieldOffset(0)]
- internal byte byte_0;
- [FieldOffset(1)]
- internal byte byte_1;
- [FieldOffset(2)]
- internal byte byte_2;
- [FieldOffset(3)]
- internal byte byte_3;
- [FieldOffset(4)]
- internal byte byte_4;
- [FieldOffset(5)]
- internal byte byte_5;
- [FieldOffset(6)]
- internal byte byte_6;
- [FieldOffset(7)]
- internal byte byte_7;
- [FieldOffset(8)]
- internal byte byte_8;
- [FieldOffset(9)]
- internal byte byte_9;
- [FieldOffset(10)]
- internal byte byte_10;
- [FieldOffset(11)]
- internal byte byte_11;
- [FieldOffset(12)]
- internal byte byte_12;
- [FieldOffset(13)]
- internal byte byte_13;
- [FieldOffset(14)]
- internal byte byte_14;
- [FieldOffset(15)]
- internal byte byte_15;
-
- // Internal System.SByte Fields
- [FieldOffset(0)]
- internal sbyte sbyte_0;
- [FieldOffset(1)]
- internal sbyte sbyte_1;
- [FieldOffset(2)]
- internal sbyte sbyte_2;
- [FieldOffset(3)]
- internal sbyte sbyte_3;
- [FieldOffset(4)]
- internal sbyte sbyte_4;
- [FieldOffset(5)]
- internal sbyte sbyte_5;
- [FieldOffset(6)]
- internal sbyte sbyte_6;
- [FieldOffset(7)]
- internal sbyte sbyte_7;
- [FieldOffset(8)]
- internal sbyte sbyte_8;
- [FieldOffset(9)]
- internal sbyte sbyte_9;
- [FieldOffset(10)]
- internal sbyte sbyte_10;
- [FieldOffset(11)]
- internal sbyte sbyte_11;
- [FieldOffset(12)]
- internal sbyte sbyte_12;
- [FieldOffset(13)]
- internal sbyte sbyte_13;
- [FieldOffset(14)]
- internal sbyte sbyte_14;
- [FieldOffset(15)]
- internal sbyte sbyte_15;
-
- // Internal System.UInt16 Fields
- [FieldOffset(0)]
- internal ushort uint16_0;
- [FieldOffset(2)]
- internal ushort uint16_1;
- [FieldOffset(4)]
- internal ushort uint16_2;
- [FieldOffset(6)]
- internal ushort uint16_3;
- [FieldOffset(8)]
- internal ushort uint16_4;
- [FieldOffset(10)]
- internal ushort uint16_5;
- [FieldOffset(12)]
- internal ushort uint16_6;
- [FieldOffset(14)]
- internal ushort uint16_7;
-
- // Internal System.Int16 Fields
- [FieldOffset(0)]
- internal short int16_0;
- [FieldOffset(2)]
- internal short int16_1;
- [FieldOffset(4)]
- internal short int16_2;
- [FieldOffset(6)]
- internal short int16_3;
- [FieldOffset(8)]
- internal short int16_4;
- [FieldOffset(10)]
- internal short int16_5;
- [FieldOffset(12)]
- internal short int16_6;
- [FieldOffset(14)]
- internal short int16_7;
-
- // Internal System.UInt32 Fields
- [FieldOffset(0)]
- internal uint uint32_0;
- [FieldOffset(4)]
- internal uint uint32_1;
- [FieldOffset(8)]
- internal uint uint32_2;
- [FieldOffset(12)]
- internal uint uint32_3;
-
- // Internal System.Int32 Fields
- [FieldOffset(0)]
- internal int int32_0;
- [FieldOffset(4)]
- internal int int32_1;
- [FieldOffset(8)]
- internal int int32_2;
- [FieldOffset(12)]
- internal int int32_3;
-
- // Internal System.UInt64 Fields
- [FieldOffset(0)]
- internal ulong uint64_0;
- [FieldOffset(8)]
- internal ulong uint64_1;
-
- // Internal System.Int64 Fields
- [FieldOffset(0)]
- internal long int64_0;
- [FieldOffset(8)]
- internal long int64_1;
-
- // Internal System.Single Fields
- [FieldOffset(0)]
- internal float single_0;
- [FieldOffset(4)]
- internal float single_1;
- [FieldOffset(8)]
- internal float single_2;
- [FieldOffset(12)]
- internal float single_3;
-
- // Internal System.Double Fields
- [FieldOffset(0)]
- internal double double_0;
- [FieldOffset(8)]
- internal double double_1;
-
- #endregion Internal Storage Fields
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Register.tt b/netcore/System.Private.CoreLib/shared/System/Numerics/Register.tt
deleted file mode 100644
index a5bf1453d4f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Register.tt
+++ /dev/null
@@ -1,47 +0,0 @@
-<#@ template debug="true" hostSpecific="true" #>
-<#@ output extension=".cs" #>
-<#@ Assembly Name="System.Core.dll" #>
-<#@ Assembly Name="System.Xml.dll" #>
-<#@ import namespace="System" #>
-<#@ import namespace="System.Linq" #>
-<#@ import namespace="System.Runtime.InteropServices" #>
-<#@ import namespace="System.Diagnostics" #>
-<#@ include file="GenerationConfig.ttinclude" #><# GenerateCopyrightHeader(); #>
-
-#nullable enable
-using System.Runtime.InteropServices;
-
-namespace System.Numerics
-{
- /// <summary>
- /// A structure describing the layout of an SSE2-sized register.
- /// Contains overlapping fields representing the set of valid numeric types.
- /// Allows the generic Vector'T struct to contain an explicit field layout.
- /// </summary>
- [StructLayout(LayoutKind.Explicit)]
- internal struct Register
- {
- #region Internal Storage Fields
-<#
- foreach (var type in supportedTypes)
- {
- Debug.Assert(
- totalSize % Marshal.SizeOf(type) == 0,
- "The size of supported structs must be a factor of the supported register size.");
-#>
- // Internal <#= type.FullName #> Fields
-<#
- for (int g = 0; g < totalSize / Marshal.SizeOf(type); g++)
- {
-#>
- [FieldOffset(<#=Marshal.SizeOf(type) * g#>)]
- internal <#= typeAliases[type] #> <#= type.Name.ToLowerInvariant() + "_" + g #>;
-<#
- }
-#>
-
-<#
- }
-#> #endregion Internal Storage Fields
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Vector.cs
deleted file mode 100644
index 527c68b80f0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector.cs
+++ /dev/null
@@ -1,4469 +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 System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nint = System.Int64;
-#else
-using nint = System.Int32;
-#endif
-
-namespace System.Numerics
-{
- /* Note: The following patterns are used throughout the code here and are described here
- *
- * PATTERN:
- * if (typeof(T) == typeof(int)) { ... }
- * else if (typeof(T) == typeof(float)) { ... }
- * EXPLANATION:
- * At runtime, each instantiation of Vector<T> will be type-specific, and each of these typeof blocks will be eliminated,
- * as typeof(T) is a (JIT) compile-time constant for each instantiation. This design was chosen to eliminate any overhead from
- * delegates and other patterns.
- *
- * PATTERN:
- * if (Vector.IsHardwareAccelerated) { ... }
- * else { ... }
- * EXPLANATION
- * This pattern solves two problems:
- * 1. Allows us to unroll loops when we know the size (when no hardware acceleration is present)
- * 2. Allows reflection to work:
- * - If a method is called via reflection, it will not be "intrinsified", which would cause issues if we did
- * not provide an implementation for that case (i.e. if it only included a case which assumed 16-byte registers)
- * (NOTE: It is assumed that Vector.IsHardwareAccelerated will be a compile-time constant, eliminating these checks
- * from the JIT'd code.)
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- /// <summary>
- /// A structure that represents a single Vector. The count of this Vector is fixed but CPU register dependent.
- /// This struct only supports numerical types. This type is intended to be used as a building block for vectorizing
- /// large algorithms. This type is immutable, individual elements cannot be modified.
- /// </summary>
- [Intrinsic]
- public struct Vector<T> : IEquatable<Vector<T>>, IFormattable where T : struct
- {
- #region Fields
- private Register register;
- #endregion Fields
-
- #region Static Members
- /// <summary>
- /// Returns the number of elements stored in the vector. This value is hardware dependent.
- /// </summary>
- public static int Count
- {
- [Intrinsic]
- get
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Unsafe.SizeOf<Vector<T>>() / Unsafe.SizeOf<T>();
- }
- }
-
- /// <summary>
- /// Returns a vector containing all zeroes.
- /// </summary>
- public static Vector<T> Zero
- {
- [Intrinsic]
- get => s_zero;
- }
-#pragma warning disable 0649 // never assigned to
- private static readonly Vector<T> s_zero;
-#pragma warning restore 0649
-
- /// <summary>
- /// Returns a vector containing all ones.
- /// </summary>
- public static Vector<T> One
- {
- [Intrinsic]
- get => s_one;
- }
- private static readonly Vector<T> s_one = new Vector<T>(GetOneValue());
-
- internal static Vector<T> AllOnes
- {
- [Intrinsic]
- get => s_allOnes;
- }
- private static readonly Vector<T> s_allOnes = new Vector<T>(GetAllBitsSetValue());
- #endregion Static Members
-
- #region Constructors
- /// <summary>
- /// Constructs a vector whose components are all <code>value</code>
- /// </summary>
- [Intrinsic]
- public unsafe Vector(T value)
- : this()
- {
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(byte))
- {
- fixed (byte* basePtr = &this.register.byte_0)
- {
- for (nint g = 0; g < Count; g++)
- {
- *(basePtr + g) = (byte)(object)value;
- }
- }
- }
- else if (typeof(T) == typeof(sbyte))
- {
- fixed (sbyte* basePtr = &this.register.sbyte_0)
- {
- for (nint g = 0; g < Count; g++)
- {
- *(basePtr + g) = (sbyte)(object)value;
- }
- }
- }
- else if (typeof(T) == typeof(ushort))
- {
- fixed (ushort* basePtr = &this.register.uint16_0)
- {
- for (nint g = 0; g < Count; g++)
- {
- *(basePtr + g) = (ushort)(object)value;
- }
- }
- }
- else if (typeof(T) == typeof(short))
- {
- fixed (short* basePtr = &this.register.int16_0)
- {
- for (nint g = 0; g < Count; g++)
- {
- *(basePtr + g) = (short)(object)value;
- }
- }
- }
- else if (typeof(T) == typeof(uint))
- {
- fixed (uint* basePtr = &this.register.uint32_0)
- {
- for (nint g = 0; g < Count; g++)
- {
- *(basePtr + g) = (uint)(object)value;
- }
- }
- }
- else if (typeof(T) == typeof(int))
- {
- fixed (int* basePtr = &this.register.int32_0)
- {
- for (nint g = 0; g < Count; g++)
- {
- *(basePtr + g) = (int)(object)value;
- }
- }
- }
- else if (typeof(T) == typeof(ulong))
- {
- fixed (ulong* basePtr = &this.register.uint64_0)
- {
- for (nint g = 0; g < Count; g++)
- {
- *(basePtr + g) = (ulong)(object)value;
- }
- }
- }
- else if (typeof(T) == typeof(long))
- {
- fixed (long* basePtr = &this.register.int64_0)
- {
- for (nint g = 0; g < Count; g++)
- {
- *(basePtr + g) = (long)(object)value;
- }
- }
- }
- else if (typeof(T) == typeof(float))
- {
- fixed (float* basePtr = &this.register.single_0)
- {
- for (nint g = 0; g < Count; g++)
- {
- *(basePtr + g) = (float)(object)value;
- }
- }
- }
- else if (typeof(T) == typeof(double))
- {
- fixed (double* basePtr = &this.register.double_0)
- {
- for (nint g = 0; g < Count; g++)
- {
- *(basePtr + g) = (double)(object)value;
- }
- }
- }
- }
- else
- {
- if (typeof(T) == typeof(byte))
- {
- register.byte_0 = (byte)(object)value;
- register.byte_1 = (byte)(object)value;
- register.byte_2 = (byte)(object)value;
- register.byte_3 = (byte)(object)value;
- register.byte_4 = (byte)(object)value;
- register.byte_5 = (byte)(object)value;
- register.byte_6 = (byte)(object)value;
- register.byte_7 = (byte)(object)value;
- register.byte_8 = (byte)(object)value;
- register.byte_9 = (byte)(object)value;
- register.byte_10 = (byte)(object)value;
- register.byte_11 = (byte)(object)value;
- register.byte_12 = (byte)(object)value;
- register.byte_13 = (byte)(object)value;
- register.byte_14 = (byte)(object)value;
- register.byte_15 = (byte)(object)value;
- }
- else if (typeof(T) == typeof(sbyte))
- {
- register.sbyte_0 = (sbyte)(object)value;
- register.sbyte_1 = (sbyte)(object)value;
- register.sbyte_2 = (sbyte)(object)value;
- register.sbyte_3 = (sbyte)(object)value;
- register.sbyte_4 = (sbyte)(object)value;
- register.sbyte_5 = (sbyte)(object)value;
- register.sbyte_6 = (sbyte)(object)value;
- register.sbyte_7 = (sbyte)(object)value;
- register.sbyte_8 = (sbyte)(object)value;
- register.sbyte_9 = (sbyte)(object)value;
- register.sbyte_10 = (sbyte)(object)value;
- register.sbyte_11 = (sbyte)(object)value;
- register.sbyte_12 = (sbyte)(object)value;
- register.sbyte_13 = (sbyte)(object)value;
- register.sbyte_14 = (sbyte)(object)value;
- register.sbyte_15 = (sbyte)(object)value;
- }
- else if (typeof(T) == typeof(ushort))
- {
- register.uint16_0 = (ushort)(object)value;
- register.uint16_1 = (ushort)(object)value;
- register.uint16_2 = (ushort)(object)value;
- register.uint16_3 = (ushort)(object)value;
- register.uint16_4 = (ushort)(object)value;
- register.uint16_5 = (ushort)(object)value;
- register.uint16_6 = (ushort)(object)value;
- register.uint16_7 = (ushort)(object)value;
- }
- else if (typeof(T) == typeof(short))
- {
- register.int16_0 = (short)(object)value;
- register.int16_1 = (short)(object)value;
- register.int16_2 = (short)(object)value;
- register.int16_3 = (short)(object)value;
- register.int16_4 = (short)(object)value;
- register.int16_5 = (short)(object)value;
- register.int16_6 = (short)(object)value;
- register.int16_7 = (short)(object)value;
- }
- else if (typeof(T) == typeof(uint))
- {
- register.uint32_0 = (uint)(object)value;
- register.uint32_1 = (uint)(object)value;
- register.uint32_2 = (uint)(object)value;
- register.uint32_3 = (uint)(object)value;
- }
- else if (typeof(T) == typeof(int))
- {
- register.int32_0 = (int)(object)value;
- register.int32_1 = (int)(object)value;
- register.int32_2 = (int)(object)value;
- register.int32_3 = (int)(object)value;
- }
- else if (typeof(T) == typeof(ulong))
- {
- register.uint64_0 = (ulong)(object)value;
- register.uint64_1 = (ulong)(object)value;
- }
- else if (typeof(T) == typeof(long))
- {
- register.int64_0 = (long)(object)value;
- register.int64_1 = (long)(object)value;
- }
- else if (typeof(T) == typeof(float))
- {
- register.single_0 = (float)(object)value;
- register.single_1 = (float)(object)value;
- register.single_2 = (float)(object)value;
- register.single_3 = (float)(object)value;
- }
- else if (typeof(T) == typeof(double))
- {
- register.double_0 = (double)(object)value;
- register.double_1 = (double)(object)value;
- }
- }
- }
-
- /// <summary>
- /// Constructs a vector from the given array. The size of the given array must be at least Vector'T.Count.
- /// </summary>
- [Intrinsic]
- public unsafe Vector(T[] values) : this(values, 0) { }
-
- /// <summary>
- /// Constructs a vector from the given array, starting from the given index.
- /// The array must contain at least Vector'T.Count from the given index.
- /// </summary>
- [Intrinsic]
- public unsafe Vector(T[] values, int index)
- {
- if (values == null)
- {
- // Match the JIT's exception type here. For perf, a NullReference is thrown instead of an ArgumentNull.
- throw new NullReferenceException(SR.Arg_NullArgumentNullRef);
- }
- if (index < 0 || (values.Length - index) < Count)
- {
- Vector.ThrowInsufficientNumberOfElementsException(Vector<T>.Count);
- }
- this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref values[index]));
- }
-
- internal unsafe Vector(void* dataPointer)
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- this = Unsafe.ReadUnaligned<Vector<T>>(dataPointer);
- }
-
- private Vector(ref Register existingRegister)
- {
- this.register = existingRegister;
- }
-
- /// <summary>
- /// Constructs a vector from the given <see cref="ReadOnlySpan{Byte}"/>. The span must contain at least <see cref="Vector{Byte}.Count"/> elements.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Vector(ReadOnlySpan<byte> values)
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- if (values.Length < Vector<byte>.Count)
- {
- Vector.ThrowInsufficientNumberOfElementsException(Vector<byte>.Count);
- }
- this = Unsafe.ReadUnaligned<Vector<T>>(ref MemoryMarshal.GetReference(values));
- }
-
- /// <summary>
- /// Constructs a vector from the given <see cref="ReadOnlySpan{T}"/>. The span must contain at least <see cref="Vector{T}.Count"/> elements.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Vector(ReadOnlySpan<T> values)
- {
- if (values.Length < Count)
- {
- Vector.ThrowInsufficientNumberOfElementsException(Vector<T>.Count);
- }
- this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)));
- }
-
- /// <summary>
- /// Constructs a vector from the given <see cref="Span{T}"/>. The span must contain at least <see cref="Vector{T}.Count"/> elements.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Vector(Span<T> values)
- {
- if (values.Length < Count)
- {
- Vector.ThrowInsufficientNumberOfElementsException(Vector<T>.Count);
- }
- this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)));
- }
- #endregion Constructors
-
- #region Public Instance Methods
- /// <summary>
- /// Copies the vector to the given <see cref="Span{Byte}"/>. The destination span must be at least size <see cref="Vector{Byte}.Count"/>.
- /// </summary>
- /// <param name="destination">The destination span which the values are copied into</param>
- /// <exception cref="ArgumentException">If number of elements in source vector is greater than those available in destination span</exception>
- public readonly void CopyTo(Span<byte> destination)
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- if ((uint)destination.Length < (uint)Vector<byte>.Count)
- {
- ThrowHelper.ThrowArgumentException_DestinationTooShort();
- }
-
- Unsafe.WriteUnaligned<Vector<T>>(ref MemoryMarshal.GetReference(destination), this);
- }
-
- /// <summary>
- /// Copies the vector to the given <see cref="Span{T}"/>. The destination span must be at least size <see cref="Vector{T}.Count"/>.
- /// </summary>
- /// <param name="destination">The destination span which the values are copied into</param>
- /// <exception cref="ArgumentException">If number of elements in source vector is greater than those available in destination span</exception>
- public readonly void CopyTo(Span<T> destination)
- {
- if ((uint)destination.Length < (uint)Count)
- {
- ThrowHelper.ThrowArgumentException_DestinationTooShort();
- }
-
- Unsafe.WriteUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(destination)), this);
- }
-
- /// <summary>
- /// Copies the vector to the given destination array. The destination array must be at least size Vector'T.Count.
- /// </summary>
- /// <param name="destination">The destination array which the values are copied into</param>
- /// <exception cref="ArgumentNullException">If the destination array is null</exception>
- /// <exception cref="ArgumentException">If number of elements in source vector is greater than those available in destination array</exception>
- [Intrinsic]
- public readonly void CopyTo(T[] destination)
- {
- CopyTo(destination, 0);
- }
-
- /// <summary>
- /// Copies the vector to the given destination array. The destination array must be at least size Vector'T.Count.
- /// </summary>
- /// <param name="destination">The destination array which the values are copied into</param>
- /// <param name="startIndex">The index to start copying to</param>
- /// <exception cref="ArgumentNullException">If the destination array is null</exception>
- /// <exception cref="ArgumentOutOfRangeException">If index is greater than end of the array or index is less than zero</exception>
- /// <exception cref="ArgumentException">If number of elements in source vector is greater than those available in destination array</exception>
- [Intrinsic]
- public readonly unsafe void CopyTo(T[] destination, int startIndex)
- {
- if (destination == null)
- {
- // Match the JIT's exception type here. For perf, a NullReference is thrown instead of an ArgumentNull.
- throw new NullReferenceException(SR.Arg_NullArgumentNullRef);
- }
- if ((uint)startIndex >= (uint)destination.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.Format(SR.Arg_ArgumentOutOfRangeException, startIndex));
- }
- if ((destination.Length - startIndex) < Count)
- {
- throw new ArgumentException(SR.Format(SR.Arg_ElementsInSourceIsGreaterThanDestination, startIndex));
- }
-
- Unsafe.WriteUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref destination[startIndex]), this);
- }
-
- /// <summary>
- /// Returns the element at the given index.
- /// </summary>
- public readonly unsafe T this[int index]
- {
- [Intrinsic]
- get
- {
- if ((uint)index >= (uint)Count)
- {
- throw new IndexOutOfRangeException(SR.Format(SR.Arg_ArgumentOutOfRangeException, index));
- }
-
- return Unsafe.Add(ref Unsafe.As<Vector<T>, T>(ref Unsafe.AsRef<Vector<T>>(in this)), index);
- }
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Object is equal to this vector instance.
- /// </summary>
- /// <param name="obj">The Object to compare against.</param>
- /// <returns>True if the Object is equal to this vector; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override readonly bool Equals(object? obj)
- {
- if (!(obj is Vector<T>))
- {
- return false;
- }
- return Equals((Vector<T>)obj);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given vector is equal to this vector instance.
- /// </summary>
- /// <param name="other">The vector to compare this instance to.</param>
- /// <returns>True if the other vector is equal to this instance; False otherwise.</returns>
- [Intrinsic]
- public readonly bool Equals(Vector<T> other)
- {
- if (Vector.IsHardwareAccelerated)
- {
- for (int g = 0; g < Count; g++)
- {
- if (!ScalarEquals(this[g], other[g]))
- {
- return false;
- }
- }
- return true;
- }
- else
- {
- if (typeof(T) == typeof(byte))
- {
- return
- this.register.byte_0 == other.register.byte_0
- && this.register.byte_1 == other.register.byte_1
- && this.register.byte_2 == other.register.byte_2
- && this.register.byte_3 == other.register.byte_3
- && this.register.byte_4 == other.register.byte_4
- && this.register.byte_5 == other.register.byte_5
- && this.register.byte_6 == other.register.byte_6
- && this.register.byte_7 == other.register.byte_7
- && this.register.byte_8 == other.register.byte_8
- && this.register.byte_9 == other.register.byte_9
- && this.register.byte_10 == other.register.byte_10
- && this.register.byte_11 == other.register.byte_11
- && this.register.byte_12 == other.register.byte_12
- && this.register.byte_13 == other.register.byte_13
- && this.register.byte_14 == other.register.byte_14
- && this.register.byte_15 == other.register.byte_15;
- }
- else if (typeof(T) == typeof(sbyte))
- {
- return
- this.register.sbyte_0 == other.register.sbyte_0
- && this.register.sbyte_1 == other.register.sbyte_1
- && this.register.sbyte_2 == other.register.sbyte_2
- && this.register.sbyte_3 == other.register.sbyte_3
- && this.register.sbyte_4 == other.register.sbyte_4
- && this.register.sbyte_5 == other.register.sbyte_5
- && this.register.sbyte_6 == other.register.sbyte_6
- && this.register.sbyte_7 == other.register.sbyte_7
- && this.register.sbyte_8 == other.register.sbyte_8
- && this.register.sbyte_9 == other.register.sbyte_9
- && this.register.sbyte_10 == other.register.sbyte_10
- && this.register.sbyte_11 == other.register.sbyte_11
- && this.register.sbyte_12 == other.register.sbyte_12
- && this.register.sbyte_13 == other.register.sbyte_13
- && this.register.sbyte_14 == other.register.sbyte_14
- && this.register.sbyte_15 == other.register.sbyte_15;
- }
- else if (typeof(T) == typeof(ushort))
- {
- return
- this.register.uint16_0 == other.register.uint16_0
- && this.register.uint16_1 == other.register.uint16_1
- && this.register.uint16_2 == other.register.uint16_2
- && this.register.uint16_3 == other.register.uint16_3
- && this.register.uint16_4 == other.register.uint16_4
- && this.register.uint16_5 == other.register.uint16_5
- && this.register.uint16_6 == other.register.uint16_6
- && this.register.uint16_7 == other.register.uint16_7;
- }
- else if (typeof(T) == typeof(short))
- {
- return
- this.register.int16_0 == other.register.int16_0
- && this.register.int16_1 == other.register.int16_1
- && this.register.int16_2 == other.register.int16_2
- && this.register.int16_3 == other.register.int16_3
- && this.register.int16_4 == other.register.int16_4
- && this.register.int16_5 == other.register.int16_5
- && this.register.int16_6 == other.register.int16_6
- && this.register.int16_7 == other.register.int16_7;
- }
- else if (typeof(T) == typeof(uint))
- {
- return
- this.register.uint32_0 == other.register.uint32_0
- && this.register.uint32_1 == other.register.uint32_1
- && this.register.uint32_2 == other.register.uint32_2
- && this.register.uint32_3 == other.register.uint32_3;
- }
- else if (typeof(T) == typeof(int))
- {
- return
- this.register.int32_0 == other.register.int32_0
- && this.register.int32_1 == other.register.int32_1
- && this.register.int32_2 == other.register.int32_2
- && this.register.int32_3 == other.register.int32_3;
- }
- else if (typeof(T) == typeof(ulong))
- {
- return
- this.register.uint64_0 == other.register.uint64_0
- && this.register.uint64_1 == other.register.uint64_1;
- }
- else if (typeof(T) == typeof(long))
- {
- return
- this.register.int64_0 == other.register.int64_0
- && this.register.int64_1 == other.register.int64_1;
- }
- else if (typeof(T) == typeof(float))
- {
- return
- this.register.single_0 == other.register.single_0
- && this.register.single_1 == other.register.single_1
- && this.register.single_2 == other.register.single_2
- && this.register.single_3 == other.register.single_3;
- }
- else if (typeof(T) == typeof(double))
- {
- return
- this.register.double_0 == other.register.double_0
- && this.register.double_1 == other.register.double_1;
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- /// <summary>
- /// Returns the hash code for this instance.
- /// </summary>
- /// <returns>The hash code.</returns>
- public override readonly int GetHashCode()
- {
- HashCode hashCode = default;
-
- if (typeof(T) == typeof(byte) ||
- typeof(T) == typeof(sbyte) ||
- typeof(T) == typeof(ushort) ||
- typeof(T) == typeof(short) ||
- typeof(T) == typeof(int) ||
- typeof(T) == typeof(uint) ||
- typeof(T) == typeof(long) ||
- typeof(T) == typeof(ulong))
- {
- for (nint g = 0; g < Vector<int>.Count; g++)
- {
- hashCode.Add(Unsafe.Add(ref Unsafe.As<Vector<T>, int>(ref Unsafe.AsRef<Vector<T>>(in this)), (IntPtr)g));
- }
- }
- else if (typeof(T) == typeof(float))
- {
- for (nint g = 0; g < Count; g++)
- {
- hashCode.Add(Unsafe.Add(ref Unsafe.As<Vector<T>, float>(ref Unsafe.AsRef<Vector<T>>(in this)), (IntPtr)g));
- }
- }
- else if (typeof(T) == typeof(double))
- {
- for (nint g = 0; g < Count; g++)
- {
- hashCode.Add(Unsafe.Add(ref Unsafe.As<Vector<T>, double>(ref Unsafe.AsRef<Vector<T>>(in this)), (IntPtr)g));
- }
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
-
- return hashCode.ToHashCode();
- }
-
- /// <summary>
- /// Returns a String representing this vector.
- /// </summary>
- /// <returns>The string representation.</returns>
- public override readonly string ToString()
- {
- return ToString("G", CultureInfo.CurrentCulture);
- }
-
- /// <summary>
- /// Returns a String representing this vector, using the specified format string to format individual elements.
- /// </summary>
- /// <param name="format">The format of individual elements.</param>
- /// <returns>The string representation.</returns>
- public readonly string ToString(string? format)
- {
- return ToString(format, CultureInfo.CurrentCulture);
- }
-
- /// <summary>
- /// Returns a String representing this vector, using the specified format string to format individual elements
- /// and the given IFormatProvider.
- /// </summary>
- /// <param name="format">The format of individual elements.</param>
- /// <param name="formatProvider">The format provider to use when formatting elements.</param>
- /// <returns>The string representation.</returns>
- public readonly string ToString(string? format, IFormatProvider? formatProvider)
- {
- StringBuilder sb = new StringBuilder();
- string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
- sb.Append('<');
- for (int g = 0; g < Count - 1; g++)
- {
- sb.Append(((IFormattable)this[g]).ToString(format, formatProvider));
- sb.Append(separator);
- sb.Append(' ');
- }
- // Append last element w/out separator
- sb.Append(((IFormattable)this[Count - 1]).ToString(format, formatProvider));
- sb.Append('>');
- return sb.ToString();
- }
-
- /// <summary>
- /// Attempts to copy the vector to the given <see cref="Span{Byte}"/>. The destination span must be at least size <see cref="Vector{Byte}.Count"/>.
- /// </summary>
- /// <param name="destination">The destination span which the values are copied into</param>
- /// <returns>True if the source vector was successfully copied to <paramref name="destination"/>. False if
- /// <paramref name="destination"/> is not large enough to hold the source vector.</returns>
- public readonly bool TryCopyTo(Span<byte> destination)
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- if ((uint)destination.Length < (uint)Vector<byte>.Count)
- {
- return false;
- }
-
- Unsafe.WriteUnaligned<Vector<T>>(ref MemoryMarshal.GetReference(destination), this);
- return true;
- }
-
- /// <summary>
- /// Attempts to copy the vector to the given <see cref="Span{T}"/>. The destination span must be at least size <see cref="Vector{T}.Count"/>.
- /// </summary>
- /// <param name="destination">The destination span which the values are copied into</param>
- /// <returns>True if the source vector was successfully copied to <paramref name="destination"/>. False if
- /// <paramref name="destination"/> is not large enough to hold the source vector.</returns>
- public readonly bool TryCopyTo(Span<T> destination)
- {
- if ((uint)destination.Length < (uint)Count)
- {
- return false;
- }
-
- Unsafe.WriteUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(destination)), this);
- return true;
- }
- #endregion Public Instance Methods
-
- #region Arithmetic Operators
- /// <summary>
- /// Adds two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The summed vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator +(Vector<T> left, Vector<T> right)
- {
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(byte))
- {
- byte* dataPtr = stackalloc byte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (byte)(object)ScalarAdd(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte* dataPtr = stackalloc sbyte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (sbyte)(object)ScalarAdd(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort* dataPtr = stackalloc ushort[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (ushort)(object)ScalarAdd(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(short))
- {
- short* dataPtr = stackalloc short[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (short)(object)ScalarAdd(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(uint))
- {
- uint* dataPtr = stackalloc uint[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (uint)(object)ScalarAdd(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(int))
- {
- int* dataPtr = stackalloc int[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (int)(object)ScalarAdd(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong* dataPtr = stackalloc ulong[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (ulong)(object)ScalarAdd(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(long))
- {
- long* dataPtr = stackalloc long[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (long)(object)ScalarAdd(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(float))
- {
- float* dataPtr = stackalloc float[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (float)(object)ScalarAdd(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(double))
- {
- double* dataPtr = stackalloc double[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (double)(object)ScalarAdd(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> sum = default;
- if (typeof(T) == typeof(byte))
- {
- sum.register.byte_0 = (byte)(left.register.byte_0 + right.register.byte_0);
- sum.register.byte_1 = (byte)(left.register.byte_1 + right.register.byte_1);
- sum.register.byte_2 = (byte)(left.register.byte_2 + right.register.byte_2);
- sum.register.byte_3 = (byte)(left.register.byte_3 + right.register.byte_3);
- sum.register.byte_4 = (byte)(left.register.byte_4 + right.register.byte_4);
- sum.register.byte_5 = (byte)(left.register.byte_5 + right.register.byte_5);
- sum.register.byte_6 = (byte)(left.register.byte_6 + right.register.byte_6);
- sum.register.byte_7 = (byte)(left.register.byte_7 + right.register.byte_7);
- sum.register.byte_8 = (byte)(left.register.byte_8 + right.register.byte_8);
- sum.register.byte_9 = (byte)(left.register.byte_9 + right.register.byte_9);
- sum.register.byte_10 = (byte)(left.register.byte_10 + right.register.byte_10);
- sum.register.byte_11 = (byte)(left.register.byte_11 + right.register.byte_11);
- sum.register.byte_12 = (byte)(left.register.byte_12 + right.register.byte_12);
- sum.register.byte_13 = (byte)(left.register.byte_13 + right.register.byte_13);
- sum.register.byte_14 = (byte)(left.register.byte_14 + right.register.byte_14);
- sum.register.byte_15 = (byte)(left.register.byte_15 + right.register.byte_15);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sum.register.sbyte_0 = (sbyte)(left.register.sbyte_0 + right.register.sbyte_0);
- sum.register.sbyte_1 = (sbyte)(left.register.sbyte_1 + right.register.sbyte_1);
- sum.register.sbyte_2 = (sbyte)(left.register.sbyte_2 + right.register.sbyte_2);
- sum.register.sbyte_3 = (sbyte)(left.register.sbyte_3 + right.register.sbyte_3);
- sum.register.sbyte_4 = (sbyte)(left.register.sbyte_4 + right.register.sbyte_4);
- sum.register.sbyte_5 = (sbyte)(left.register.sbyte_5 + right.register.sbyte_5);
- sum.register.sbyte_6 = (sbyte)(left.register.sbyte_6 + right.register.sbyte_6);
- sum.register.sbyte_7 = (sbyte)(left.register.sbyte_7 + right.register.sbyte_7);
- sum.register.sbyte_8 = (sbyte)(left.register.sbyte_8 + right.register.sbyte_8);
- sum.register.sbyte_9 = (sbyte)(left.register.sbyte_9 + right.register.sbyte_9);
- sum.register.sbyte_10 = (sbyte)(left.register.sbyte_10 + right.register.sbyte_10);
- sum.register.sbyte_11 = (sbyte)(left.register.sbyte_11 + right.register.sbyte_11);
- sum.register.sbyte_12 = (sbyte)(left.register.sbyte_12 + right.register.sbyte_12);
- sum.register.sbyte_13 = (sbyte)(left.register.sbyte_13 + right.register.sbyte_13);
- sum.register.sbyte_14 = (sbyte)(left.register.sbyte_14 + right.register.sbyte_14);
- sum.register.sbyte_15 = (sbyte)(left.register.sbyte_15 + right.register.sbyte_15);
- }
- else if (typeof(T) == typeof(ushort))
- {
- sum.register.uint16_0 = (ushort)(left.register.uint16_0 + right.register.uint16_0);
- sum.register.uint16_1 = (ushort)(left.register.uint16_1 + right.register.uint16_1);
- sum.register.uint16_2 = (ushort)(left.register.uint16_2 + right.register.uint16_2);
- sum.register.uint16_3 = (ushort)(left.register.uint16_3 + right.register.uint16_3);
- sum.register.uint16_4 = (ushort)(left.register.uint16_4 + right.register.uint16_4);
- sum.register.uint16_5 = (ushort)(left.register.uint16_5 + right.register.uint16_5);
- sum.register.uint16_6 = (ushort)(left.register.uint16_6 + right.register.uint16_6);
- sum.register.uint16_7 = (ushort)(left.register.uint16_7 + right.register.uint16_7);
- }
- else if (typeof(T) == typeof(short))
- {
- sum.register.int16_0 = (short)(left.register.int16_0 + right.register.int16_0);
- sum.register.int16_1 = (short)(left.register.int16_1 + right.register.int16_1);
- sum.register.int16_2 = (short)(left.register.int16_2 + right.register.int16_2);
- sum.register.int16_3 = (short)(left.register.int16_3 + right.register.int16_3);
- sum.register.int16_4 = (short)(left.register.int16_4 + right.register.int16_4);
- sum.register.int16_5 = (short)(left.register.int16_5 + right.register.int16_5);
- sum.register.int16_6 = (short)(left.register.int16_6 + right.register.int16_6);
- sum.register.int16_7 = (short)(left.register.int16_7 + right.register.int16_7);
- }
- else if (typeof(T) == typeof(uint))
- {
- sum.register.uint32_0 = (uint)(left.register.uint32_0 + right.register.uint32_0);
- sum.register.uint32_1 = (uint)(left.register.uint32_1 + right.register.uint32_1);
- sum.register.uint32_2 = (uint)(left.register.uint32_2 + right.register.uint32_2);
- sum.register.uint32_3 = (uint)(left.register.uint32_3 + right.register.uint32_3);
- }
- else if (typeof(T) == typeof(int))
- {
- sum.register.int32_0 = (int)(left.register.int32_0 + right.register.int32_0);
- sum.register.int32_1 = (int)(left.register.int32_1 + right.register.int32_1);
- sum.register.int32_2 = (int)(left.register.int32_2 + right.register.int32_2);
- sum.register.int32_3 = (int)(left.register.int32_3 + right.register.int32_3);
- }
- else if (typeof(T) == typeof(ulong))
- {
- sum.register.uint64_0 = (ulong)(left.register.uint64_0 + right.register.uint64_0);
- sum.register.uint64_1 = (ulong)(left.register.uint64_1 + right.register.uint64_1);
- }
- else if (typeof(T) == typeof(long))
- {
- sum.register.int64_0 = (long)(left.register.int64_0 + right.register.int64_0);
- sum.register.int64_1 = (long)(left.register.int64_1 + right.register.int64_1);
- }
- else if (typeof(T) == typeof(float))
- {
- sum.register.single_0 = (float)(left.register.single_0 + right.register.single_0);
- sum.register.single_1 = (float)(left.register.single_1 + right.register.single_1);
- sum.register.single_2 = (float)(left.register.single_2 + right.register.single_2);
- sum.register.single_3 = (float)(left.register.single_3 + right.register.single_3);
- }
- else if (typeof(T) == typeof(double))
- {
- sum.register.double_0 = (double)(left.register.double_0 + right.register.double_0);
- sum.register.double_1 = (double)(left.register.double_1 + right.register.double_1);
- }
- return sum;
- }
- }
- }
-
- /// <summary>
- /// Subtracts the second vector from the first.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The difference vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator -(Vector<T> left, Vector<T> right)
- {
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(byte))
- {
- byte* dataPtr = stackalloc byte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (byte)(object)ScalarSubtract(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte* dataPtr = stackalloc sbyte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (sbyte)(object)ScalarSubtract(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort* dataPtr = stackalloc ushort[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (ushort)(object)ScalarSubtract(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(short))
- {
- short* dataPtr = stackalloc short[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (short)(object)ScalarSubtract(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(uint))
- {
- uint* dataPtr = stackalloc uint[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (uint)(object)ScalarSubtract(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(int))
- {
- int* dataPtr = stackalloc int[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (int)(object)ScalarSubtract(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong* dataPtr = stackalloc ulong[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (ulong)(object)ScalarSubtract(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(long))
- {
- long* dataPtr = stackalloc long[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (long)(object)ScalarSubtract(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(float))
- {
- float* dataPtr = stackalloc float[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (float)(object)ScalarSubtract(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(double))
- {
- double* dataPtr = stackalloc double[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (double)(object)ScalarSubtract(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> difference = default;
- if (typeof(T) == typeof(byte))
- {
- difference.register.byte_0 = (byte)(left.register.byte_0 - right.register.byte_0);
- difference.register.byte_1 = (byte)(left.register.byte_1 - right.register.byte_1);
- difference.register.byte_2 = (byte)(left.register.byte_2 - right.register.byte_2);
- difference.register.byte_3 = (byte)(left.register.byte_3 - right.register.byte_3);
- difference.register.byte_4 = (byte)(left.register.byte_4 - right.register.byte_4);
- difference.register.byte_5 = (byte)(left.register.byte_5 - right.register.byte_5);
- difference.register.byte_6 = (byte)(left.register.byte_6 - right.register.byte_6);
- difference.register.byte_7 = (byte)(left.register.byte_7 - right.register.byte_7);
- difference.register.byte_8 = (byte)(left.register.byte_8 - right.register.byte_8);
- difference.register.byte_9 = (byte)(left.register.byte_9 - right.register.byte_9);
- difference.register.byte_10 = (byte)(left.register.byte_10 - right.register.byte_10);
- difference.register.byte_11 = (byte)(left.register.byte_11 - right.register.byte_11);
- difference.register.byte_12 = (byte)(left.register.byte_12 - right.register.byte_12);
- difference.register.byte_13 = (byte)(left.register.byte_13 - right.register.byte_13);
- difference.register.byte_14 = (byte)(left.register.byte_14 - right.register.byte_14);
- difference.register.byte_15 = (byte)(left.register.byte_15 - right.register.byte_15);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- difference.register.sbyte_0 = (sbyte)(left.register.sbyte_0 - right.register.sbyte_0);
- difference.register.sbyte_1 = (sbyte)(left.register.sbyte_1 - right.register.sbyte_1);
- difference.register.sbyte_2 = (sbyte)(left.register.sbyte_2 - right.register.sbyte_2);
- difference.register.sbyte_3 = (sbyte)(left.register.sbyte_3 - right.register.sbyte_3);
- difference.register.sbyte_4 = (sbyte)(left.register.sbyte_4 - right.register.sbyte_4);
- difference.register.sbyte_5 = (sbyte)(left.register.sbyte_5 - right.register.sbyte_5);
- difference.register.sbyte_6 = (sbyte)(left.register.sbyte_6 - right.register.sbyte_6);
- difference.register.sbyte_7 = (sbyte)(left.register.sbyte_7 - right.register.sbyte_7);
- difference.register.sbyte_8 = (sbyte)(left.register.sbyte_8 - right.register.sbyte_8);
- difference.register.sbyte_9 = (sbyte)(left.register.sbyte_9 - right.register.sbyte_9);
- difference.register.sbyte_10 = (sbyte)(left.register.sbyte_10 - right.register.sbyte_10);
- difference.register.sbyte_11 = (sbyte)(left.register.sbyte_11 - right.register.sbyte_11);
- difference.register.sbyte_12 = (sbyte)(left.register.sbyte_12 - right.register.sbyte_12);
- difference.register.sbyte_13 = (sbyte)(left.register.sbyte_13 - right.register.sbyte_13);
- difference.register.sbyte_14 = (sbyte)(left.register.sbyte_14 - right.register.sbyte_14);
- difference.register.sbyte_15 = (sbyte)(left.register.sbyte_15 - right.register.sbyte_15);
- }
- else if (typeof(T) == typeof(ushort))
- {
- difference.register.uint16_0 = (ushort)(left.register.uint16_0 - right.register.uint16_0);
- difference.register.uint16_1 = (ushort)(left.register.uint16_1 - right.register.uint16_1);
- difference.register.uint16_2 = (ushort)(left.register.uint16_2 - right.register.uint16_2);
- difference.register.uint16_3 = (ushort)(left.register.uint16_3 - right.register.uint16_3);
- difference.register.uint16_4 = (ushort)(left.register.uint16_4 - right.register.uint16_4);
- difference.register.uint16_5 = (ushort)(left.register.uint16_5 - right.register.uint16_5);
- difference.register.uint16_6 = (ushort)(left.register.uint16_6 - right.register.uint16_6);
- difference.register.uint16_7 = (ushort)(left.register.uint16_7 - right.register.uint16_7);
- }
- else if (typeof(T) == typeof(short))
- {
- difference.register.int16_0 = (short)(left.register.int16_0 - right.register.int16_0);
- difference.register.int16_1 = (short)(left.register.int16_1 - right.register.int16_1);
- difference.register.int16_2 = (short)(left.register.int16_2 - right.register.int16_2);
- difference.register.int16_3 = (short)(left.register.int16_3 - right.register.int16_3);
- difference.register.int16_4 = (short)(left.register.int16_4 - right.register.int16_4);
- difference.register.int16_5 = (short)(left.register.int16_5 - right.register.int16_5);
- difference.register.int16_6 = (short)(left.register.int16_6 - right.register.int16_6);
- difference.register.int16_7 = (short)(left.register.int16_7 - right.register.int16_7);
- }
- else if (typeof(T) == typeof(uint))
- {
- difference.register.uint32_0 = (uint)(left.register.uint32_0 - right.register.uint32_0);
- difference.register.uint32_1 = (uint)(left.register.uint32_1 - right.register.uint32_1);
- difference.register.uint32_2 = (uint)(left.register.uint32_2 - right.register.uint32_2);
- difference.register.uint32_3 = (uint)(left.register.uint32_3 - right.register.uint32_3);
- }
- else if (typeof(T) == typeof(int))
- {
- difference.register.int32_0 = (int)(left.register.int32_0 - right.register.int32_0);
- difference.register.int32_1 = (int)(left.register.int32_1 - right.register.int32_1);
- difference.register.int32_2 = (int)(left.register.int32_2 - right.register.int32_2);
- difference.register.int32_3 = (int)(left.register.int32_3 - right.register.int32_3);
- }
- else if (typeof(T) == typeof(ulong))
- {
- difference.register.uint64_0 = (ulong)(left.register.uint64_0 - right.register.uint64_0);
- difference.register.uint64_1 = (ulong)(left.register.uint64_1 - right.register.uint64_1);
- }
- else if (typeof(T) == typeof(long))
- {
- difference.register.int64_0 = (long)(left.register.int64_0 - right.register.int64_0);
- difference.register.int64_1 = (long)(left.register.int64_1 - right.register.int64_1);
- }
- else if (typeof(T) == typeof(float))
- {
- difference.register.single_0 = (float)(left.register.single_0 - right.register.single_0);
- difference.register.single_1 = (float)(left.register.single_1 - right.register.single_1);
- difference.register.single_2 = (float)(left.register.single_2 - right.register.single_2);
- difference.register.single_3 = (float)(left.register.single_3 - right.register.single_3);
- }
- else if (typeof(T) == typeof(double))
- {
- difference.register.double_0 = (double)(left.register.double_0 - right.register.double_0);
- difference.register.double_1 = (double)(left.register.double_1 - right.register.double_1);
- }
- return difference;
- }
- }
- }
-
- // This method is intrinsic only for certain types. It cannot access fields directly unless we are sure the context is unaccelerated.
- /// <summary>
- /// Multiplies two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The product vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator *(Vector<T> left, Vector<T> right)
- {
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(byte))
- {
- byte* dataPtr = stackalloc byte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (byte)(object)ScalarMultiply(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte* dataPtr = stackalloc sbyte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (sbyte)(object)ScalarMultiply(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort* dataPtr = stackalloc ushort[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (ushort)(object)ScalarMultiply(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(short))
- {
- short* dataPtr = stackalloc short[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (short)(object)ScalarMultiply(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(uint))
- {
- uint* dataPtr = stackalloc uint[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (uint)(object)ScalarMultiply(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(int))
- {
- int* dataPtr = stackalloc int[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (int)(object)ScalarMultiply(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong* dataPtr = stackalloc ulong[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (ulong)(object)ScalarMultiply(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(long))
- {
- long* dataPtr = stackalloc long[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (long)(object)ScalarMultiply(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(float))
- {
- float* dataPtr = stackalloc float[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (float)(object)ScalarMultiply(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(double))
- {
- double* dataPtr = stackalloc double[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (double)(object)ScalarMultiply(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> product = default;
- if (typeof(T) == typeof(byte))
- {
- product.register.byte_0 = (byte)(left.register.byte_0 * right.register.byte_0);
- product.register.byte_1 = (byte)(left.register.byte_1 * right.register.byte_1);
- product.register.byte_2 = (byte)(left.register.byte_2 * right.register.byte_2);
- product.register.byte_3 = (byte)(left.register.byte_3 * right.register.byte_3);
- product.register.byte_4 = (byte)(left.register.byte_4 * right.register.byte_4);
- product.register.byte_5 = (byte)(left.register.byte_5 * right.register.byte_5);
- product.register.byte_6 = (byte)(left.register.byte_6 * right.register.byte_6);
- product.register.byte_7 = (byte)(left.register.byte_7 * right.register.byte_7);
- product.register.byte_8 = (byte)(left.register.byte_8 * right.register.byte_8);
- product.register.byte_9 = (byte)(left.register.byte_9 * right.register.byte_9);
- product.register.byte_10 = (byte)(left.register.byte_10 * right.register.byte_10);
- product.register.byte_11 = (byte)(left.register.byte_11 * right.register.byte_11);
- product.register.byte_12 = (byte)(left.register.byte_12 * right.register.byte_12);
- product.register.byte_13 = (byte)(left.register.byte_13 * right.register.byte_13);
- product.register.byte_14 = (byte)(left.register.byte_14 * right.register.byte_14);
- product.register.byte_15 = (byte)(left.register.byte_15 * right.register.byte_15);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- product.register.sbyte_0 = (sbyte)(left.register.sbyte_0 * right.register.sbyte_0);
- product.register.sbyte_1 = (sbyte)(left.register.sbyte_1 * right.register.sbyte_1);
- product.register.sbyte_2 = (sbyte)(left.register.sbyte_2 * right.register.sbyte_2);
- product.register.sbyte_3 = (sbyte)(left.register.sbyte_3 * right.register.sbyte_3);
- product.register.sbyte_4 = (sbyte)(left.register.sbyte_4 * right.register.sbyte_4);
- product.register.sbyte_5 = (sbyte)(left.register.sbyte_5 * right.register.sbyte_5);
- product.register.sbyte_6 = (sbyte)(left.register.sbyte_6 * right.register.sbyte_6);
- product.register.sbyte_7 = (sbyte)(left.register.sbyte_7 * right.register.sbyte_7);
- product.register.sbyte_8 = (sbyte)(left.register.sbyte_8 * right.register.sbyte_8);
- product.register.sbyte_9 = (sbyte)(left.register.sbyte_9 * right.register.sbyte_9);
- product.register.sbyte_10 = (sbyte)(left.register.sbyte_10 * right.register.sbyte_10);
- product.register.sbyte_11 = (sbyte)(left.register.sbyte_11 * right.register.sbyte_11);
- product.register.sbyte_12 = (sbyte)(left.register.sbyte_12 * right.register.sbyte_12);
- product.register.sbyte_13 = (sbyte)(left.register.sbyte_13 * right.register.sbyte_13);
- product.register.sbyte_14 = (sbyte)(left.register.sbyte_14 * right.register.sbyte_14);
- product.register.sbyte_15 = (sbyte)(left.register.sbyte_15 * right.register.sbyte_15);
- }
- else if (typeof(T) == typeof(ushort))
- {
- product.register.uint16_0 = (ushort)(left.register.uint16_0 * right.register.uint16_0);
- product.register.uint16_1 = (ushort)(left.register.uint16_1 * right.register.uint16_1);
- product.register.uint16_2 = (ushort)(left.register.uint16_2 * right.register.uint16_2);
- product.register.uint16_3 = (ushort)(left.register.uint16_3 * right.register.uint16_3);
- product.register.uint16_4 = (ushort)(left.register.uint16_4 * right.register.uint16_4);
- product.register.uint16_5 = (ushort)(left.register.uint16_5 * right.register.uint16_5);
- product.register.uint16_6 = (ushort)(left.register.uint16_6 * right.register.uint16_6);
- product.register.uint16_7 = (ushort)(left.register.uint16_7 * right.register.uint16_7);
- }
- else if (typeof(T) == typeof(short))
- {
- product.register.int16_0 = (short)(left.register.int16_0 * right.register.int16_0);
- product.register.int16_1 = (short)(left.register.int16_1 * right.register.int16_1);
- product.register.int16_2 = (short)(left.register.int16_2 * right.register.int16_2);
- product.register.int16_3 = (short)(left.register.int16_3 * right.register.int16_3);
- product.register.int16_4 = (short)(left.register.int16_4 * right.register.int16_4);
- product.register.int16_5 = (short)(left.register.int16_5 * right.register.int16_5);
- product.register.int16_6 = (short)(left.register.int16_6 * right.register.int16_6);
- product.register.int16_7 = (short)(left.register.int16_7 * right.register.int16_7);
- }
- else if (typeof(T) == typeof(uint))
- {
- product.register.uint32_0 = (uint)(left.register.uint32_0 * right.register.uint32_0);
- product.register.uint32_1 = (uint)(left.register.uint32_1 * right.register.uint32_1);
- product.register.uint32_2 = (uint)(left.register.uint32_2 * right.register.uint32_2);
- product.register.uint32_3 = (uint)(left.register.uint32_3 * right.register.uint32_3);
- }
- else if (typeof(T) == typeof(int))
- {
- product.register.int32_0 = (int)(left.register.int32_0 * right.register.int32_0);
- product.register.int32_1 = (int)(left.register.int32_1 * right.register.int32_1);
- product.register.int32_2 = (int)(left.register.int32_2 * right.register.int32_2);
- product.register.int32_3 = (int)(left.register.int32_3 * right.register.int32_3);
- }
- else if (typeof(T) == typeof(ulong))
- {
- product.register.uint64_0 = (ulong)(left.register.uint64_0 * right.register.uint64_0);
- product.register.uint64_1 = (ulong)(left.register.uint64_1 * right.register.uint64_1);
- }
- else if (typeof(T) == typeof(long))
- {
- product.register.int64_0 = (long)(left.register.int64_0 * right.register.int64_0);
- product.register.int64_1 = (long)(left.register.int64_1 * right.register.int64_1);
- }
- else if (typeof(T) == typeof(float))
- {
- product.register.single_0 = (float)(left.register.single_0 * right.register.single_0);
- product.register.single_1 = (float)(left.register.single_1 * right.register.single_1);
- product.register.single_2 = (float)(left.register.single_2 * right.register.single_2);
- product.register.single_3 = (float)(left.register.single_3 * right.register.single_3);
- }
- else if (typeof(T) == typeof(double))
- {
- product.register.double_0 = (double)(left.register.double_0 * right.register.double_0);
- product.register.double_1 = (double)(left.register.double_1 * right.register.double_1);
- }
- return product;
- }
- }
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <param name="factor">The scalar value.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> operator *(Vector<T> value, T factor) =>
- new Vector<T>(factor) * value;
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="factor">The scalar value.</param>
- /// <param name="value">The source vector.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> operator *(T factor, Vector<T> value) =>
- new Vector<T>(factor) * value;
-
- // This method is intrinsic only for certain types. It cannot access fields directly unless we are sure the context is unaccelerated.
- /// <summary>
- /// Divides the first vector by the second.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The vector resulting from the division.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator /(Vector<T> left, Vector<T> right)
- {
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(byte))
- {
- byte* dataPtr = stackalloc byte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (byte)(object)ScalarDivide(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte* dataPtr = stackalloc sbyte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (sbyte)(object)ScalarDivide(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort* dataPtr = stackalloc ushort[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (ushort)(object)ScalarDivide(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(short))
- {
- short* dataPtr = stackalloc short[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (short)(object)ScalarDivide(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(uint))
- {
- uint* dataPtr = stackalloc uint[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (uint)(object)ScalarDivide(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(int))
- {
- int* dataPtr = stackalloc int[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (int)(object)ScalarDivide(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong* dataPtr = stackalloc ulong[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (ulong)(object)ScalarDivide(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(long))
- {
- long* dataPtr = stackalloc long[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (long)(object)ScalarDivide(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(float))
- {
- float* dataPtr = stackalloc float[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (float)(object)ScalarDivide(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(double))
- {
- double* dataPtr = stackalloc double[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (double)(object)ScalarDivide(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> quotient = default;
- if (typeof(T) == typeof(byte))
- {
- quotient.register.byte_0 = (byte)(left.register.byte_0 / right.register.byte_0);
- quotient.register.byte_1 = (byte)(left.register.byte_1 / right.register.byte_1);
- quotient.register.byte_2 = (byte)(left.register.byte_2 / right.register.byte_2);
- quotient.register.byte_3 = (byte)(left.register.byte_3 / right.register.byte_3);
- quotient.register.byte_4 = (byte)(left.register.byte_4 / right.register.byte_4);
- quotient.register.byte_5 = (byte)(left.register.byte_5 / right.register.byte_5);
- quotient.register.byte_6 = (byte)(left.register.byte_6 / right.register.byte_6);
- quotient.register.byte_7 = (byte)(left.register.byte_7 / right.register.byte_7);
- quotient.register.byte_8 = (byte)(left.register.byte_8 / right.register.byte_8);
- quotient.register.byte_9 = (byte)(left.register.byte_9 / right.register.byte_9);
- quotient.register.byte_10 = (byte)(left.register.byte_10 / right.register.byte_10);
- quotient.register.byte_11 = (byte)(left.register.byte_11 / right.register.byte_11);
- quotient.register.byte_12 = (byte)(left.register.byte_12 / right.register.byte_12);
- quotient.register.byte_13 = (byte)(left.register.byte_13 / right.register.byte_13);
- quotient.register.byte_14 = (byte)(left.register.byte_14 / right.register.byte_14);
- quotient.register.byte_15 = (byte)(left.register.byte_15 / right.register.byte_15);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- quotient.register.sbyte_0 = (sbyte)(left.register.sbyte_0 / right.register.sbyte_0);
- quotient.register.sbyte_1 = (sbyte)(left.register.sbyte_1 / right.register.sbyte_1);
- quotient.register.sbyte_2 = (sbyte)(left.register.sbyte_2 / right.register.sbyte_2);
- quotient.register.sbyte_3 = (sbyte)(left.register.sbyte_3 / right.register.sbyte_3);
- quotient.register.sbyte_4 = (sbyte)(left.register.sbyte_4 / right.register.sbyte_4);
- quotient.register.sbyte_5 = (sbyte)(left.register.sbyte_5 / right.register.sbyte_5);
- quotient.register.sbyte_6 = (sbyte)(left.register.sbyte_6 / right.register.sbyte_6);
- quotient.register.sbyte_7 = (sbyte)(left.register.sbyte_7 / right.register.sbyte_7);
- quotient.register.sbyte_8 = (sbyte)(left.register.sbyte_8 / right.register.sbyte_8);
- quotient.register.sbyte_9 = (sbyte)(left.register.sbyte_9 / right.register.sbyte_9);
- quotient.register.sbyte_10 = (sbyte)(left.register.sbyte_10 / right.register.sbyte_10);
- quotient.register.sbyte_11 = (sbyte)(left.register.sbyte_11 / right.register.sbyte_11);
- quotient.register.sbyte_12 = (sbyte)(left.register.sbyte_12 / right.register.sbyte_12);
- quotient.register.sbyte_13 = (sbyte)(left.register.sbyte_13 / right.register.sbyte_13);
- quotient.register.sbyte_14 = (sbyte)(left.register.sbyte_14 / right.register.sbyte_14);
- quotient.register.sbyte_15 = (sbyte)(left.register.sbyte_15 / right.register.sbyte_15);
- }
- else if (typeof(T) == typeof(ushort))
- {
- quotient.register.uint16_0 = (ushort)(left.register.uint16_0 / right.register.uint16_0);
- quotient.register.uint16_1 = (ushort)(left.register.uint16_1 / right.register.uint16_1);
- quotient.register.uint16_2 = (ushort)(left.register.uint16_2 / right.register.uint16_2);
- quotient.register.uint16_3 = (ushort)(left.register.uint16_3 / right.register.uint16_3);
- quotient.register.uint16_4 = (ushort)(left.register.uint16_4 / right.register.uint16_4);
- quotient.register.uint16_5 = (ushort)(left.register.uint16_5 / right.register.uint16_5);
- quotient.register.uint16_6 = (ushort)(left.register.uint16_6 / right.register.uint16_6);
- quotient.register.uint16_7 = (ushort)(left.register.uint16_7 / right.register.uint16_7);
- }
- else if (typeof(T) == typeof(short))
- {
- quotient.register.int16_0 = (short)(left.register.int16_0 / right.register.int16_0);
- quotient.register.int16_1 = (short)(left.register.int16_1 / right.register.int16_1);
- quotient.register.int16_2 = (short)(left.register.int16_2 / right.register.int16_2);
- quotient.register.int16_3 = (short)(left.register.int16_3 / right.register.int16_3);
- quotient.register.int16_4 = (short)(left.register.int16_4 / right.register.int16_4);
- quotient.register.int16_5 = (short)(left.register.int16_5 / right.register.int16_5);
- quotient.register.int16_6 = (short)(left.register.int16_6 / right.register.int16_6);
- quotient.register.int16_7 = (short)(left.register.int16_7 / right.register.int16_7);
- }
- else if (typeof(T) == typeof(uint))
- {
- quotient.register.uint32_0 = (uint)(left.register.uint32_0 / right.register.uint32_0);
- quotient.register.uint32_1 = (uint)(left.register.uint32_1 / right.register.uint32_1);
- quotient.register.uint32_2 = (uint)(left.register.uint32_2 / right.register.uint32_2);
- quotient.register.uint32_3 = (uint)(left.register.uint32_3 / right.register.uint32_3);
- }
- else if (typeof(T) == typeof(int))
- {
- quotient.register.int32_0 = (int)(left.register.int32_0 / right.register.int32_0);
- quotient.register.int32_1 = (int)(left.register.int32_1 / right.register.int32_1);
- quotient.register.int32_2 = (int)(left.register.int32_2 / right.register.int32_2);
- quotient.register.int32_3 = (int)(left.register.int32_3 / right.register.int32_3);
- }
- else if (typeof(T) == typeof(ulong))
- {
- quotient.register.uint64_0 = (ulong)(left.register.uint64_0 / right.register.uint64_0);
- quotient.register.uint64_1 = (ulong)(left.register.uint64_1 / right.register.uint64_1);
- }
- else if (typeof(T) == typeof(long))
- {
- quotient.register.int64_0 = (long)(left.register.int64_0 / right.register.int64_0);
- quotient.register.int64_1 = (long)(left.register.int64_1 / right.register.int64_1);
- }
- else if (typeof(T) == typeof(float))
- {
- quotient.register.single_0 = (float)(left.register.single_0 / right.register.single_0);
- quotient.register.single_1 = (float)(left.register.single_1 / right.register.single_1);
- quotient.register.single_2 = (float)(left.register.single_2 / right.register.single_2);
- quotient.register.single_3 = (float)(left.register.single_3 / right.register.single_3);
- }
- else if (typeof(T) == typeof(double))
- {
- quotient.register.double_0 = (double)(left.register.double_0 / right.register.double_0);
- quotient.register.double_1 = (double)(left.register.double_1 / right.register.double_1);
- }
- return quotient;
- }
- }
- }
-
- /// <summary>
- /// Negates a given vector.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The negated vector.</returns>
- public static Vector<T> operator -(Vector<T> value) => Zero - value;
- #endregion Arithmetic Operators
-
- #region Bitwise Operators
- /// <summary>
- /// Returns a new vector by performing a bitwise-and operation on each of the elements in the given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator &(Vector<T> left, Vector<T> right)
- {
- Vector<T> result = default;
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
- long* resultBase = &result.register.int64_0;
- long* leftBase = &left.register.int64_0;
- long* rightBase = &right.register.int64_0;
- for (int g = 0; g < Vector<long>.Count; g++)
- {
- resultBase[g] = leftBase[g] & rightBase[g];
- }
- }
- else
- {
- result.register.int64_0 = left.register.int64_0 & right.register.int64_0;
- result.register.int64_1 = left.register.int64_1 & right.register.int64_1;
- }
- }
- return result;
- }
-
- /// <summary>
- /// Returns a new vector by performing a bitwise-or operation on each of the elements in the given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator |(Vector<T> left, Vector<T> right)
- {
- Vector<T> result = default;
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
- long* resultBase = &result.register.int64_0;
- long* leftBase = &left.register.int64_0;
- long* rightBase = &right.register.int64_0;
- for (int g = 0; g < Vector<long>.Count; g++)
- {
- resultBase[g] = leftBase[g] | rightBase[g];
- }
- }
- else
- {
- result.register.int64_0 = left.register.int64_0 | right.register.int64_0;
- result.register.int64_1 = left.register.int64_1 | right.register.int64_1;
- }
- }
- return result;
- }
-
- /// <summary>
- /// Returns a new vector by performing a bitwise-exclusive-or operation on each of the elements in the given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator ^(Vector<T> left, Vector<T> right)
- {
- Vector<T> result = default;
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
- long* resultBase = &result.register.int64_0;
- long* leftBase = &left.register.int64_0;
- long* rightBase = &right.register.int64_0;
- for (int g = 0; g < Vector<long>.Count; g++)
- {
- resultBase[g] = leftBase[g] ^ rightBase[g];
- }
- }
- else
- {
- result.register.int64_0 = left.register.int64_0 ^ right.register.int64_0;
- result.register.int64_1 = left.register.int64_1 ^ right.register.int64_1;
- }
- }
- return result;
- }
-
- /// <summary>
- /// Returns a new vector whose elements are obtained by taking the one's complement of the given vector's elements.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The one's complement vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> operator ~(Vector<T> value) =>
- s_allOnes ^ value;
- #endregion Bitwise Operators
-
- #region Logical Operators
- /// <summary>
- /// Returns a boolean indicating whether each pair of elements in the given vectors are equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The first vector to compare.</param>
- /// <returns>True if all elements are equal; False otherwise.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Vector<T> left, Vector<T> right) =>
- left.Equals(right);
-
- /// <summary>
- /// Returns a boolean indicating whether any single pair of elements in the given vectors are not equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if left and right are not equal; False otherwise.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(Vector<T> left, Vector<T> right) => !(left == right);
- #endregion Logical Operators
-
- #region Conversions
- /// <summary>
- /// Reinterprets the bits of the given vector into those of another type.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [Intrinsic]
- public static explicit operator Vector<byte>(Vector<T> value) =>
- new Vector<byte>(ref value.register);
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of another type.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [CLSCompliant(false)]
- [Intrinsic]
- public static explicit operator Vector<sbyte>(Vector<T> value) =>
- new Vector<sbyte>(ref value.register);
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of another type.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [CLSCompliant(false)]
- [Intrinsic]
- public static explicit operator Vector<ushort>(Vector<T> value) =>
- new Vector<ushort>(ref value.register);
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of another type.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [Intrinsic]
- public static explicit operator Vector<short>(Vector<T> value) =>
- new Vector<short>(ref value.register);
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of another type.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [CLSCompliant(false)]
- [Intrinsic]
- public static explicit operator Vector<uint>(Vector<T> value) =>
- new Vector<uint>(ref value.register);
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of another type.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [Intrinsic]
- public static explicit operator Vector<int>(Vector<T> value) =>
- new Vector<int>(ref value.register);
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of another type.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [CLSCompliant(false)]
- [Intrinsic]
- public static explicit operator Vector<ulong>(Vector<T> value) =>
- new Vector<ulong>(ref value.register);
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of another type.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [Intrinsic]
- public static explicit operator Vector<long>(Vector<T> value) =>
- new Vector<long>(ref value.register);
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of another type.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [Intrinsic]
- public static explicit operator Vector<float>(Vector<T> value) =>
- new Vector<float>(ref value.register);
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of another type.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [Intrinsic]
- public static explicit operator Vector<double>(Vector<T> value) =>
- new Vector<double>(ref value.register);
-
- #endregion Conversions
-
- #region Internal Comparison Methods
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe Vector<T> Equals(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(byte))
- {
- byte* dataPtr = stackalloc byte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarEquals(left[g], right[g]) ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte* dataPtr = stackalloc sbyte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarEquals(left[g], right[g]) ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort* dataPtr = stackalloc ushort[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarEquals(left[g], right[g]) ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(short))
- {
- short* dataPtr = stackalloc short[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarEquals(left[g], right[g]) ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(uint))
- {
- uint* dataPtr = stackalloc uint[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarEquals(left[g], right[g]) ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(int))
- {
- int* dataPtr = stackalloc int[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarEquals(left[g], right[g]) ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong* dataPtr = stackalloc ulong[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarEquals(left[g], right[g]) ? ConstantHelper.GetUInt64WithAllBitsSet() : (ulong)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(long))
- {
- long* dataPtr = stackalloc long[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarEquals(left[g], right[g]) ? ConstantHelper.GetInt64WithAllBitsSet() : (long)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(float))
- {
- float* dataPtr = stackalloc float[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarEquals(left[g], right[g]) ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(double))
- {
- double* dataPtr = stackalloc double[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarEquals(left[g], right[g]) ? ConstantHelper.GetDoubleWithAllBitsSet() : (double)0;
- }
- return new Vector<T>(dataPtr);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Register register = default;
- if (typeof(T) == typeof(byte))
- {
- register.byte_0 = left.register.byte_0 == right.register.byte_0 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_1 = left.register.byte_1 == right.register.byte_1 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_2 = left.register.byte_2 == right.register.byte_2 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_3 = left.register.byte_3 == right.register.byte_3 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_4 = left.register.byte_4 == right.register.byte_4 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_5 = left.register.byte_5 == right.register.byte_5 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_6 = left.register.byte_6 == right.register.byte_6 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_7 = left.register.byte_7 == right.register.byte_7 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_8 = left.register.byte_8 == right.register.byte_8 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_9 = left.register.byte_9 == right.register.byte_9 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_10 = left.register.byte_10 == right.register.byte_10 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_11 = left.register.byte_11 == right.register.byte_11 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_12 = left.register.byte_12 == right.register.byte_12 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_13 = left.register.byte_13 == right.register.byte_13 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_14 = left.register.byte_14 == right.register.byte_14 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_15 = left.register.byte_15 == right.register.byte_15 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- register.sbyte_0 = left.register.sbyte_0 == right.register.sbyte_0 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_1 = left.register.sbyte_1 == right.register.sbyte_1 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_2 = left.register.sbyte_2 == right.register.sbyte_2 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_3 = left.register.sbyte_3 == right.register.sbyte_3 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_4 = left.register.sbyte_4 == right.register.sbyte_4 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_5 = left.register.sbyte_5 == right.register.sbyte_5 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_6 = left.register.sbyte_6 == right.register.sbyte_6 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_7 = left.register.sbyte_7 == right.register.sbyte_7 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_8 = left.register.sbyte_8 == right.register.sbyte_8 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_9 = left.register.sbyte_9 == right.register.sbyte_9 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_10 = left.register.sbyte_10 == right.register.sbyte_10 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_11 = left.register.sbyte_11 == right.register.sbyte_11 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_12 = left.register.sbyte_12 == right.register.sbyte_12 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_13 = left.register.sbyte_13 == right.register.sbyte_13 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_14 = left.register.sbyte_14 == right.register.sbyte_14 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_15 = left.register.sbyte_15 == right.register.sbyte_15 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(ushort))
- {
- register.uint16_0 = left.register.uint16_0 == right.register.uint16_0 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_1 = left.register.uint16_1 == right.register.uint16_1 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_2 = left.register.uint16_2 == right.register.uint16_2 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_3 = left.register.uint16_3 == right.register.uint16_3 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_4 = left.register.uint16_4 == right.register.uint16_4 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_5 = left.register.uint16_5 == right.register.uint16_5 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_6 = left.register.uint16_6 == right.register.uint16_6 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_7 = left.register.uint16_7 == right.register.uint16_7 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(short))
- {
- register.int16_0 = left.register.int16_0 == right.register.int16_0 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_1 = left.register.int16_1 == right.register.int16_1 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_2 = left.register.int16_2 == right.register.int16_2 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_3 = left.register.int16_3 == right.register.int16_3 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_4 = left.register.int16_4 == right.register.int16_4 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_5 = left.register.int16_5 == right.register.int16_5 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_6 = left.register.int16_6 == right.register.int16_6 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_7 = left.register.int16_7 == right.register.int16_7 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(uint))
- {
- register.uint32_0 = left.register.uint32_0 == right.register.uint32_0 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- register.uint32_1 = left.register.uint32_1 == right.register.uint32_1 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- register.uint32_2 = left.register.uint32_2 == right.register.uint32_2 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- register.uint32_3 = left.register.uint32_3 == right.register.uint32_3 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(int))
- {
- register.int32_0 = left.register.int32_0 == right.register.int32_0 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- register.int32_1 = left.register.int32_1 == right.register.int32_1 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- register.int32_2 = left.register.int32_2 == right.register.int32_2 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- register.int32_3 = left.register.int32_3 == right.register.int32_3 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(ulong))
- {
- register.uint64_0 = left.register.uint64_0 == right.register.uint64_0 ? ConstantHelper.GetUInt64WithAllBitsSet() : (ulong)0;
- register.uint64_1 = left.register.uint64_1 == right.register.uint64_1 ? ConstantHelper.GetUInt64WithAllBitsSet() : (ulong)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(long))
- {
- register.int64_0 = left.register.int64_0 == right.register.int64_0 ? ConstantHelper.GetInt64WithAllBitsSet() : (long)0;
- register.int64_1 = left.register.int64_1 == right.register.int64_1 ? ConstantHelper.GetInt64WithAllBitsSet() : (long)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(float))
- {
- register.single_0 = left.register.single_0 == right.register.single_0 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- register.single_1 = left.register.single_1 == right.register.single_1 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- register.single_2 = left.register.single_2 == right.register.single_2 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- register.single_3 = left.register.single_3 == right.register.single_3 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(double))
- {
- register.double_0 = left.register.double_0 == right.register.double_0 ? ConstantHelper.GetDoubleWithAllBitsSet() : (double)0;
- register.double_1 = left.register.double_1 == right.register.double_1 ? ConstantHelper.GetDoubleWithAllBitsSet() : (double)0;
- return new Vector<T>(ref register);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe Vector<T> LessThan(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(byte))
- {
- byte* dataPtr = stackalloc byte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte* dataPtr = stackalloc sbyte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort* dataPtr = stackalloc ushort[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(short))
- {
- short* dataPtr = stackalloc short[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(uint))
- {
- uint* dataPtr = stackalloc uint[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(int))
- {
- int* dataPtr = stackalloc int[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong* dataPtr = stackalloc ulong[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? ConstantHelper.GetUInt64WithAllBitsSet() : (ulong)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(long))
- {
- long* dataPtr = stackalloc long[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? ConstantHelper.GetInt64WithAllBitsSet() : (long)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(float))
- {
- float* dataPtr = stackalloc float[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(double))
- {
- double* dataPtr = stackalloc double[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? ConstantHelper.GetDoubleWithAllBitsSet() : (double)0;
- }
- return new Vector<T>(dataPtr);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Register register = default;
- if (typeof(T) == typeof(byte))
- {
- register.byte_0 = left.register.byte_0 < right.register.byte_0 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_1 = left.register.byte_1 < right.register.byte_1 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_2 = left.register.byte_2 < right.register.byte_2 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_3 = left.register.byte_3 < right.register.byte_3 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_4 = left.register.byte_4 < right.register.byte_4 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_5 = left.register.byte_5 < right.register.byte_5 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_6 = left.register.byte_6 < right.register.byte_6 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_7 = left.register.byte_7 < right.register.byte_7 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_8 = left.register.byte_8 < right.register.byte_8 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_9 = left.register.byte_9 < right.register.byte_9 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_10 = left.register.byte_10 < right.register.byte_10 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_11 = left.register.byte_11 < right.register.byte_11 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_12 = left.register.byte_12 < right.register.byte_12 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_13 = left.register.byte_13 < right.register.byte_13 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_14 = left.register.byte_14 < right.register.byte_14 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_15 = left.register.byte_15 < right.register.byte_15 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- register.sbyte_0 = left.register.sbyte_0 < right.register.sbyte_0 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_1 = left.register.sbyte_1 < right.register.sbyte_1 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_2 = left.register.sbyte_2 < right.register.sbyte_2 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_3 = left.register.sbyte_3 < right.register.sbyte_3 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_4 = left.register.sbyte_4 < right.register.sbyte_4 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_5 = left.register.sbyte_5 < right.register.sbyte_5 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_6 = left.register.sbyte_6 < right.register.sbyte_6 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_7 = left.register.sbyte_7 < right.register.sbyte_7 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_8 = left.register.sbyte_8 < right.register.sbyte_8 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_9 = left.register.sbyte_9 < right.register.sbyte_9 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_10 = left.register.sbyte_10 < right.register.sbyte_10 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_11 = left.register.sbyte_11 < right.register.sbyte_11 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_12 = left.register.sbyte_12 < right.register.sbyte_12 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_13 = left.register.sbyte_13 < right.register.sbyte_13 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_14 = left.register.sbyte_14 < right.register.sbyte_14 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_15 = left.register.sbyte_15 < right.register.sbyte_15 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(ushort))
- {
- register.uint16_0 = left.register.uint16_0 < right.register.uint16_0 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_1 = left.register.uint16_1 < right.register.uint16_1 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_2 = left.register.uint16_2 < right.register.uint16_2 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_3 = left.register.uint16_3 < right.register.uint16_3 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_4 = left.register.uint16_4 < right.register.uint16_4 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_5 = left.register.uint16_5 < right.register.uint16_5 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_6 = left.register.uint16_6 < right.register.uint16_6 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_7 = left.register.uint16_7 < right.register.uint16_7 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(short))
- {
- register.int16_0 = left.register.int16_0 < right.register.int16_0 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_1 = left.register.int16_1 < right.register.int16_1 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_2 = left.register.int16_2 < right.register.int16_2 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_3 = left.register.int16_3 < right.register.int16_3 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_4 = left.register.int16_4 < right.register.int16_4 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_5 = left.register.int16_5 < right.register.int16_5 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_6 = left.register.int16_6 < right.register.int16_6 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_7 = left.register.int16_7 < right.register.int16_7 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(uint))
- {
- register.uint32_0 = left.register.uint32_0 < right.register.uint32_0 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- register.uint32_1 = left.register.uint32_1 < right.register.uint32_1 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- register.uint32_2 = left.register.uint32_2 < right.register.uint32_2 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- register.uint32_3 = left.register.uint32_3 < right.register.uint32_3 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(int))
- {
- register.int32_0 = left.register.int32_0 < right.register.int32_0 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- register.int32_1 = left.register.int32_1 < right.register.int32_1 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- register.int32_2 = left.register.int32_2 < right.register.int32_2 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- register.int32_3 = left.register.int32_3 < right.register.int32_3 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(ulong))
- {
- register.uint64_0 = left.register.uint64_0 < right.register.uint64_0 ? ConstantHelper.GetUInt64WithAllBitsSet() : (ulong)0;
- register.uint64_1 = left.register.uint64_1 < right.register.uint64_1 ? ConstantHelper.GetUInt64WithAllBitsSet() : (ulong)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(long))
- {
- register.int64_0 = left.register.int64_0 < right.register.int64_0 ? ConstantHelper.GetInt64WithAllBitsSet() : (long)0;
- register.int64_1 = left.register.int64_1 < right.register.int64_1 ? ConstantHelper.GetInt64WithAllBitsSet() : (long)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(float))
- {
- register.single_0 = left.register.single_0 < right.register.single_0 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- register.single_1 = left.register.single_1 < right.register.single_1 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- register.single_2 = left.register.single_2 < right.register.single_2 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- register.single_3 = left.register.single_3 < right.register.single_3 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(double))
- {
- register.double_0 = left.register.double_0 < right.register.double_0 ? ConstantHelper.GetDoubleWithAllBitsSet() : (double)0;
- register.double_1 = left.register.double_1 < right.register.double_1 ? ConstantHelper.GetDoubleWithAllBitsSet() : (double)0;
- return new Vector<T>(ref register);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe Vector<T> GreaterThan(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(byte))
- {
- byte* dataPtr = stackalloc byte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte* dataPtr = stackalloc sbyte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort* dataPtr = stackalloc ushort[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(short))
- {
- short* dataPtr = stackalloc short[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(uint))
- {
- uint* dataPtr = stackalloc uint[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(int))
- {
- int* dataPtr = stackalloc int[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong* dataPtr = stackalloc ulong[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? ConstantHelper.GetUInt64WithAllBitsSet() : (ulong)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(long))
- {
- long* dataPtr = stackalloc long[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? ConstantHelper.GetInt64WithAllBitsSet() : (long)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(float))
- {
- float* dataPtr = stackalloc float[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(double))
- {
- double* dataPtr = stackalloc double[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? ConstantHelper.GetDoubleWithAllBitsSet() : (double)0;
- }
- return new Vector<T>(dataPtr);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Register register = default;
- if (typeof(T) == typeof(byte))
- {
- register.byte_0 = left.register.byte_0 > right.register.byte_0 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_1 = left.register.byte_1 > right.register.byte_1 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_2 = left.register.byte_2 > right.register.byte_2 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_3 = left.register.byte_3 > right.register.byte_3 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_4 = left.register.byte_4 > right.register.byte_4 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_5 = left.register.byte_5 > right.register.byte_5 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_6 = left.register.byte_6 > right.register.byte_6 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_7 = left.register.byte_7 > right.register.byte_7 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_8 = left.register.byte_8 > right.register.byte_8 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_9 = left.register.byte_9 > right.register.byte_9 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_10 = left.register.byte_10 > right.register.byte_10 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_11 = left.register.byte_11 > right.register.byte_11 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_12 = left.register.byte_12 > right.register.byte_12 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_13 = left.register.byte_13 > right.register.byte_13 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_14 = left.register.byte_14 > right.register.byte_14 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- register.byte_15 = left.register.byte_15 > right.register.byte_15 ? ConstantHelper.GetByteWithAllBitsSet() : (byte)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- register.sbyte_0 = left.register.sbyte_0 > right.register.sbyte_0 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_1 = left.register.sbyte_1 > right.register.sbyte_1 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_2 = left.register.sbyte_2 > right.register.sbyte_2 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_3 = left.register.sbyte_3 > right.register.sbyte_3 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_4 = left.register.sbyte_4 > right.register.sbyte_4 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_5 = left.register.sbyte_5 > right.register.sbyte_5 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_6 = left.register.sbyte_6 > right.register.sbyte_6 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_7 = left.register.sbyte_7 > right.register.sbyte_7 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_8 = left.register.sbyte_8 > right.register.sbyte_8 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_9 = left.register.sbyte_9 > right.register.sbyte_9 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_10 = left.register.sbyte_10 > right.register.sbyte_10 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_11 = left.register.sbyte_11 > right.register.sbyte_11 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_12 = left.register.sbyte_12 > right.register.sbyte_12 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_13 = left.register.sbyte_13 > right.register.sbyte_13 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_14 = left.register.sbyte_14 > right.register.sbyte_14 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- register.sbyte_15 = left.register.sbyte_15 > right.register.sbyte_15 ? ConstantHelper.GetSByteWithAllBitsSet() : (sbyte)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(ushort))
- {
- register.uint16_0 = left.register.uint16_0 > right.register.uint16_0 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_1 = left.register.uint16_1 > right.register.uint16_1 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_2 = left.register.uint16_2 > right.register.uint16_2 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_3 = left.register.uint16_3 > right.register.uint16_3 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_4 = left.register.uint16_4 > right.register.uint16_4 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_5 = left.register.uint16_5 > right.register.uint16_5 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_6 = left.register.uint16_6 > right.register.uint16_6 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- register.uint16_7 = left.register.uint16_7 > right.register.uint16_7 ? ConstantHelper.GetUInt16WithAllBitsSet() : (ushort)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(short))
- {
- register.int16_0 = left.register.int16_0 > right.register.int16_0 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_1 = left.register.int16_1 > right.register.int16_1 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_2 = left.register.int16_2 > right.register.int16_2 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_3 = left.register.int16_3 > right.register.int16_3 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_4 = left.register.int16_4 > right.register.int16_4 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_5 = left.register.int16_5 > right.register.int16_5 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_6 = left.register.int16_6 > right.register.int16_6 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- register.int16_7 = left.register.int16_7 > right.register.int16_7 ? ConstantHelper.GetInt16WithAllBitsSet() : (short)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(uint))
- {
- register.uint32_0 = left.register.uint32_0 > right.register.uint32_0 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- register.uint32_1 = left.register.uint32_1 > right.register.uint32_1 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- register.uint32_2 = left.register.uint32_2 > right.register.uint32_2 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- register.uint32_3 = left.register.uint32_3 > right.register.uint32_3 ? ConstantHelper.GetUInt32WithAllBitsSet() : (uint)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(int))
- {
- register.int32_0 = left.register.int32_0 > right.register.int32_0 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- register.int32_1 = left.register.int32_1 > right.register.int32_1 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- register.int32_2 = left.register.int32_2 > right.register.int32_2 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- register.int32_3 = left.register.int32_3 > right.register.int32_3 ? ConstantHelper.GetInt32WithAllBitsSet() : (int)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(ulong))
- {
- register.uint64_0 = left.register.uint64_0 > right.register.uint64_0 ? ConstantHelper.GetUInt64WithAllBitsSet() : (ulong)0;
- register.uint64_1 = left.register.uint64_1 > right.register.uint64_1 ? ConstantHelper.GetUInt64WithAllBitsSet() : (ulong)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(long))
- {
- register.int64_0 = left.register.int64_0 > right.register.int64_0 ? ConstantHelper.GetInt64WithAllBitsSet() : (long)0;
- register.int64_1 = left.register.int64_1 > right.register.int64_1 ? ConstantHelper.GetInt64WithAllBitsSet() : (long)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(float))
- {
- register.single_0 = left.register.single_0 > right.register.single_0 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- register.single_1 = left.register.single_1 > right.register.single_1 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- register.single_2 = left.register.single_2 > right.register.single_2 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- register.single_3 = left.register.single_3 > right.register.single_3 ? ConstantHelper.GetSingleWithAllBitsSet() : (float)0;
- return new Vector<T>(ref register);
- }
- else if (typeof(T) == typeof(double))
- {
- register.double_0 = left.register.double_0 > right.register.double_0 ? ConstantHelper.GetDoubleWithAllBitsSet() : (double)0;
- register.double_1 = left.register.double_1 > right.register.double_1 ? ConstantHelper.GetDoubleWithAllBitsSet() : (double)0;
- return new Vector<T>(ref register);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- internal static Vector<T> GreaterThanOrEqual(Vector<T> left, Vector<T> right)
- {
- return Equals(left, right) | GreaterThan(left, right);
- }
-
- [Intrinsic]
- internal static Vector<T> LessThanOrEqual(Vector<T> left, Vector<T> right)
- {
- return Equals(left, right) | LessThan(left, right);
- }
-
- [Intrinsic]
- internal static Vector<T> ConditionalSelect(Vector<T> condition, Vector<T> left, Vector<T> right)
- {
- return (left & condition) | (Vector.AndNot(right, condition));
- }
- #endregion Comparison Methods
-
- #region Internal Math Methods
- [Intrinsic]
- internal static unsafe Vector<T> Abs(Vector<T> value)
- {
- if (typeof(T) == typeof(byte))
- {
- return value;
- }
- else if (typeof(T) == typeof(ushort))
- {
- return value;
- }
- else if (typeof(T) == typeof(uint))
- {
- return value;
- }
- else if (typeof(T) == typeof(ulong))
- {
- return value;
- }
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(sbyte))
- {
- sbyte* dataPtr = stackalloc sbyte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (sbyte)(object)(Math.Abs((sbyte)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(short))
- {
- short* dataPtr = stackalloc short[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (short)(object)(Math.Abs((short)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(int))
- {
- int* dataPtr = stackalloc int[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (int)(object)(Math.Abs((int)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(long))
- {
- long* dataPtr = stackalloc long[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (long)(object)(Math.Abs((long)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(float))
- {
- float* dataPtr = stackalloc float[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (float)(object)(Math.Abs((float)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(double))
- {
- double* dataPtr = stackalloc double[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (double)(object)(Math.Abs((double)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- if (typeof(T) == typeof(sbyte))
- {
- value.register.sbyte_0 = (sbyte)(Math.Abs(value.register.sbyte_0));
- value.register.sbyte_1 = (sbyte)(Math.Abs(value.register.sbyte_1));
- value.register.sbyte_2 = (sbyte)(Math.Abs(value.register.sbyte_2));
- value.register.sbyte_3 = (sbyte)(Math.Abs(value.register.sbyte_3));
- value.register.sbyte_4 = (sbyte)(Math.Abs(value.register.sbyte_4));
- value.register.sbyte_5 = (sbyte)(Math.Abs(value.register.sbyte_5));
- value.register.sbyte_6 = (sbyte)(Math.Abs(value.register.sbyte_6));
- value.register.sbyte_7 = (sbyte)(Math.Abs(value.register.sbyte_7));
- value.register.sbyte_8 = (sbyte)(Math.Abs(value.register.sbyte_8));
- value.register.sbyte_9 = (sbyte)(Math.Abs(value.register.sbyte_9));
- value.register.sbyte_10 = (sbyte)(Math.Abs(value.register.sbyte_10));
- value.register.sbyte_11 = (sbyte)(Math.Abs(value.register.sbyte_11));
- value.register.sbyte_12 = (sbyte)(Math.Abs(value.register.sbyte_12));
- value.register.sbyte_13 = (sbyte)(Math.Abs(value.register.sbyte_13));
- value.register.sbyte_14 = (sbyte)(Math.Abs(value.register.sbyte_14));
- value.register.sbyte_15 = (sbyte)(Math.Abs(value.register.sbyte_15));
- return value;
- }
- else if (typeof(T) == typeof(short))
- {
- value.register.int16_0 = (short)(Math.Abs(value.register.int16_0));
- value.register.int16_1 = (short)(Math.Abs(value.register.int16_1));
- value.register.int16_2 = (short)(Math.Abs(value.register.int16_2));
- value.register.int16_3 = (short)(Math.Abs(value.register.int16_3));
- value.register.int16_4 = (short)(Math.Abs(value.register.int16_4));
- value.register.int16_5 = (short)(Math.Abs(value.register.int16_5));
- value.register.int16_6 = (short)(Math.Abs(value.register.int16_6));
- value.register.int16_7 = (short)(Math.Abs(value.register.int16_7));
- return value;
- }
- else if (typeof(T) == typeof(int))
- {
- value.register.int32_0 = (int)(Math.Abs(value.register.int32_0));
- value.register.int32_1 = (int)(Math.Abs(value.register.int32_1));
- value.register.int32_2 = (int)(Math.Abs(value.register.int32_2));
- value.register.int32_3 = (int)(Math.Abs(value.register.int32_3));
- return value;
- }
- else if (typeof(T) == typeof(long))
- {
- value.register.int64_0 = (long)(Math.Abs(value.register.int64_0));
- value.register.int64_1 = (long)(Math.Abs(value.register.int64_1));
- return value;
- }
- else if (typeof(T) == typeof(float))
- {
- value.register.single_0 = (float)(Math.Abs(value.register.single_0));
- value.register.single_1 = (float)(Math.Abs(value.register.single_1));
- value.register.single_2 = (float)(Math.Abs(value.register.single_2));
- value.register.single_3 = (float)(Math.Abs(value.register.single_3));
- return value;
- }
- else if (typeof(T) == typeof(double))
- {
- value.register.double_0 = (double)(Math.Abs(value.register.double_0));
- value.register.double_1 = (double)(Math.Abs(value.register.double_1));
- return value;
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- internal static unsafe Vector<T> Min(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(byte))
- {
- byte* dataPtr = stackalloc byte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? (byte)(object)left[g] : (byte)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte* dataPtr = stackalloc sbyte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? (sbyte)(object)left[g] : (sbyte)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort* dataPtr = stackalloc ushort[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? (ushort)(object)left[g] : (ushort)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(short))
- {
- short* dataPtr = stackalloc short[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? (short)(object)left[g] : (short)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(uint))
- {
- uint* dataPtr = stackalloc uint[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? (uint)(object)left[g] : (uint)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(int))
- {
- int* dataPtr = stackalloc int[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? (int)(object)left[g] : (int)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong* dataPtr = stackalloc ulong[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? (ulong)(object)left[g] : (ulong)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(long))
- {
- long* dataPtr = stackalloc long[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? (long)(object)left[g] : (long)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(float))
- {
- float* dataPtr = stackalloc float[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? (float)(object)left[g] : (float)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(double))
- {
- double* dataPtr = stackalloc double[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? (double)(object)left[g] : (double)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> vec = default;
- if (typeof(T) == typeof(byte))
- {
- vec.register.byte_0 = left.register.byte_0 < right.register.byte_0 ? left.register.byte_0 : right.register.byte_0;
- vec.register.byte_1 = left.register.byte_1 < right.register.byte_1 ? left.register.byte_1 : right.register.byte_1;
- vec.register.byte_2 = left.register.byte_2 < right.register.byte_2 ? left.register.byte_2 : right.register.byte_2;
- vec.register.byte_3 = left.register.byte_3 < right.register.byte_3 ? left.register.byte_3 : right.register.byte_3;
- vec.register.byte_4 = left.register.byte_4 < right.register.byte_4 ? left.register.byte_4 : right.register.byte_4;
- vec.register.byte_5 = left.register.byte_5 < right.register.byte_5 ? left.register.byte_5 : right.register.byte_5;
- vec.register.byte_6 = left.register.byte_6 < right.register.byte_6 ? left.register.byte_6 : right.register.byte_6;
- vec.register.byte_7 = left.register.byte_7 < right.register.byte_7 ? left.register.byte_7 : right.register.byte_7;
- vec.register.byte_8 = left.register.byte_8 < right.register.byte_8 ? left.register.byte_8 : right.register.byte_8;
- vec.register.byte_9 = left.register.byte_9 < right.register.byte_9 ? left.register.byte_9 : right.register.byte_9;
- vec.register.byte_10 = left.register.byte_10 < right.register.byte_10 ? left.register.byte_10 : right.register.byte_10;
- vec.register.byte_11 = left.register.byte_11 < right.register.byte_11 ? left.register.byte_11 : right.register.byte_11;
- vec.register.byte_12 = left.register.byte_12 < right.register.byte_12 ? left.register.byte_12 : right.register.byte_12;
- vec.register.byte_13 = left.register.byte_13 < right.register.byte_13 ? left.register.byte_13 : right.register.byte_13;
- vec.register.byte_14 = left.register.byte_14 < right.register.byte_14 ? left.register.byte_14 : right.register.byte_14;
- vec.register.byte_15 = left.register.byte_15 < right.register.byte_15 ? left.register.byte_15 : right.register.byte_15;
- return vec;
- }
- else if (typeof(T) == typeof(sbyte))
- {
- vec.register.sbyte_0 = left.register.sbyte_0 < right.register.sbyte_0 ? left.register.sbyte_0 : right.register.sbyte_0;
- vec.register.sbyte_1 = left.register.sbyte_1 < right.register.sbyte_1 ? left.register.sbyte_1 : right.register.sbyte_1;
- vec.register.sbyte_2 = left.register.sbyte_2 < right.register.sbyte_2 ? left.register.sbyte_2 : right.register.sbyte_2;
- vec.register.sbyte_3 = left.register.sbyte_3 < right.register.sbyte_3 ? left.register.sbyte_3 : right.register.sbyte_3;
- vec.register.sbyte_4 = left.register.sbyte_4 < right.register.sbyte_4 ? left.register.sbyte_4 : right.register.sbyte_4;
- vec.register.sbyte_5 = left.register.sbyte_5 < right.register.sbyte_5 ? left.register.sbyte_5 : right.register.sbyte_5;
- vec.register.sbyte_6 = left.register.sbyte_6 < right.register.sbyte_6 ? left.register.sbyte_6 : right.register.sbyte_6;
- vec.register.sbyte_7 = left.register.sbyte_7 < right.register.sbyte_7 ? left.register.sbyte_7 : right.register.sbyte_7;
- vec.register.sbyte_8 = left.register.sbyte_8 < right.register.sbyte_8 ? left.register.sbyte_8 : right.register.sbyte_8;
- vec.register.sbyte_9 = left.register.sbyte_9 < right.register.sbyte_9 ? left.register.sbyte_9 : right.register.sbyte_9;
- vec.register.sbyte_10 = left.register.sbyte_10 < right.register.sbyte_10 ? left.register.sbyte_10 : right.register.sbyte_10;
- vec.register.sbyte_11 = left.register.sbyte_11 < right.register.sbyte_11 ? left.register.sbyte_11 : right.register.sbyte_11;
- vec.register.sbyte_12 = left.register.sbyte_12 < right.register.sbyte_12 ? left.register.sbyte_12 : right.register.sbyte_12;
- vec.register.sbyte_13 = left.register.sbyte_13 < right.register.sbyte_13 ? left.register.sbyte_13 : right.register.sbyte_13;
- vec.register.sbyte_14 = left.register.sbyte_14 < right.register.sbyte_14 ? left.register.sbyte_14 : right.register.sbyte_14;
- vec.register.sbyte_15 = left.register.sbyte_15 < right.register.sbyte_15 ? left.register.sbyte_15 : right.register.sbyte_15;
- return vec;
- }
- else if (typeof(T) == typeof(ushort))
- {
- vec.register.uint16_0 = left.register.uint16_0 < right.register.uint16_0 ? left.register.uint16_0 : right.register.uint16_0;
- vec.register.uint16_1 = left.register.uint16_1 < right.register.uint16_1 ? left.register.uint16_1 : right.register.uint16_1;
- vec.register.uint16_2 = left.register.uint16_2 < right.register.uint16_2 ? left.register.uint16_2 : right.register.uint16_2;
- vec.register.uint16_3 = left.register.uint16_3 < right.register.uint16_3 ? left.register.uint16_3 : right.register.uint16_3;
- vec.register.uint16_4 = left.register.uint16_4 < right.register.uint16_4 ? left.register.uint16_4 : right.register.uint16_4;
- vec.register.uint16_5 = left.register.uint16_5 < right.register.uint16_5 ? left.register.uint16_5 : right.register.uint16_5;
- vec.register.uint16_6 = left.register.uint16_6 < right.register.uint16_6 ? left.register.uint16_6 : right.register.uint16_6;
- vec.register.uint16_7 = left.register.uint16_7 < right.register.uint16_7 ? left.register.uint16_7 : right.register.uint16_7;
- return vec;
- }
- else if (typeof(T) == typeof(short))
- {
- vec.register.int16_0 = left.register.int16_0 < right.register.int16_0 ? left.register.int16_0 : right.register.int16_0;
- vec.register.int16_1 = left.register.int16_1 < right.register.int16_1 ? left.register.int16_1 : right.register.int16_1;
- vec.register.int16_2 = left.register.int16_2 < right.register.int16_2 ? left.register.int16_2 : right.register.int16_2;
- vec.register.int16_3 = left.register.int16_3 < right.register.int16_3 ? left.register.int16_3 : right.register.int16_3;
- vec.register.int16_4 = left.register.int16_4 < right.register.int16_4 ? left.register.int16_4 : right.register.int16_4;
- vec.register.int16_5 = left.register.int16_5 < right.register.int16_5 ? left.register.int16_5 : right.register.int16_5;
- vec.register.int16_6 = left.register.int16_6 < right.register.int16_6 ? left.register.int16_6 : right.register.int16_6;
- vec.register.int16_7 = left.register.int16_7 < right.register.int16_7 ? left.register.int16_7 : right.register.int16_7;
- return vec;
- }
- else if (typeof(T) == typeof(uint))
- {
- vec.register.uint32_0 = left.register.uint32_0 < right.register.uint32_0 ? left.register.uint32_0 : right.register.uint32_0;
- vec.register.uint32_1 = left.register.uint32_1 < right.register.uint32_1 ? left.register.uint32_1 : right.register.uint32_1;
- vec.register.uint32_2 = left.register.uint32_2 < right.register.uint32_2 ? left.register.uint32_2 : right.register.uint32_2;
- vec.register.uint32_3 = left.register.uint32_3 < right.register.uint32_3 ? left.register.uint32_3 : right.register.uint32_3;
- return vec;
- }
- else if (typeof(T) == typeof(int))
- {
- vec.register.int32_0 = left.register.int32_0 < right.register.int32_0 ? left.register.int32_0 : right.register.int32_0;
- vec.register.int32_1 = left.register.int32_1 < right.register.int32_1 ? left.register.int32_1 : right.register.int32_1;
- vec.register.int32_2 = left.register.int32_2 < right.register.int32_2 ? left.register.int32_2 : right.register.int32_2;
- vec.register.int32_3 = left.register.int32_3 < right.register.int32_3 ? left.register.int32_3 : right.register.int32_3;
- return vec;
- }
- else if (typeof(T) == typeof(ulong))
- {
- vec.register.uint64_0 = left.register.uint64_0 < right.register.uint64_0 ? left.register.uint64_0 : right.register.uint64_0;
- vec.register.uint64_1 = left.register.uint64_1 < right.register.uint64_1 ? left.register.uint64_1 : right.register.uint64_1;
- return vec;
- }
- else if (typeof(T) == typeof(long))
- {
- vec.register.int64_0 = left.register.int64_0 < right.register.int64_0 ? left.register.int64_0 : right.register.int64_0;
- vec.register.int64_1 = left.register.int64_1 < right.register.int64_1 ? left.register.int64_1 : right.register.int64_1;
- return vec;
- }
- else if (typeof(T) == typeof(float))
- {
- vec.register.single_0 = left.register.single_0 < right.register.single_0 ? left.register.single_0 : right.register.single_0;
- vec.register.single_1 = left.register.single_1 < right.register.single_1 ? left.register.single_1 : right.register.single_1;
- vec.register.single_2 = left.register.single_2 < right.register.single_2 ? left.register.single_2 : right.register.single_2;
- vec.register.single_3 = left.register.single_3 < right.register.single_3 ? left.register.single_3 : right.register.single_3;
- return vec;
- }
- else if (typeof(T) == typeof(double))
- {
- vec.register.double_0 = left.register.double_0 < right.register.double_0 ? left.register.double_0 : right.register.double_0;
- vec.register.double_1 = left.register.double_1 < right.register.double_1 ? left.register.double_1 : right.register.double_1;
- return vec;
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- internal static unsafe Vector<T> Max(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(byte))
- {
- byte* dataPtr = stackalloc byte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? (byte)(object)left[g] : (byte)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte* dataPtr = stackalloc sbyte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? (sbyte)(object)left[g] : (sbyte)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort* dataPtr = stackalloc ushort[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? (ushort)(object)left[g] : (ushort)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(short))
- {
- short* dataPtr = stackalloc short[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? (short)(object)left[g] : (short)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(uint))
- {
- uint* dataPtr = stackalloc uint[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? (uint)(object)left[g] : (uint)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(int))
- {
- int* dataPtr = stackalloc int[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? (int)(object)left[g] : (int)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong* dataPtr = stackalloc ulong[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? (ulong)(object)left[g] : (ulong)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(long))
- {
- long* dataPtr = stackalloc long[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? (long)(object)left[g] : (long)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(float))
- {
- float* dataPtr = stackalloc float[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? (float)(object)left[g] : (float)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(double))
- {
- double* dataPtr = stackalloc double[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? (double)(object)left[g] : (double)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> vec = default;
- if (typeof(T) == typeof(byte))
- {
- vec.register.byte_0 = left.register.byte_0 > right.register.byte_0 ? left.register.byte_0 : right.register.byte_0;
- vec.register.byte_1 = left.register.byte_1 > right.register.byte_1 ? left.register.byte_1 : right.register.byte_1;
- vec.register.byte_2 = left.register.byte_2 > right.register.byte_2 ? left.register.byte_2 : right.register.byte_2;
- vec.register.byte_3 = left.register.byte_3 > right.register.byte_3 ? left.register.byte_3 : right.register.byte_3;
- vec.register.byte_4 = left.register.byte_4 > right.register.byte_4 ? left.register.byte_4 : right.register.byte_4;
- vec.register.byte_5 = left.register.byte_5 > right.register.byte_5 ? left.register.byte_5 : right.register.byte_5;
- vec.register.byte_6 = left.register.byte_6 > right.register.byte_6 ? left.register.byte_6 : right.register.byte_6;
- vec.register.byte_7 = left.register.byte_7 > right.register.byte_7 ? left.register.byte_7 : right.register.byte_7;
- vec.register.byte_8 = left.register.byte_8 > right.register.byte_8 ? left.register.byte_8 : right.register.byte_8;
- vec.register.byte_9 = left.register.byte_9 > right.register.byte_9 ? left.register.byte_9 : right.register.byte_9;
- vec.register.byte_10 = left.register.byte_10 > right.register.byte_10 ? left.register.byte_10 : right.register.byte_10;
- vec.register.byte_11 = left.register.byte_11 > right.register.byte_11 ? left.register.byte_11 : right.register.byte_11;
- vec.register.byte_12 = left.register.byte_12 > right.register.byte_12 ? left.register.byte_12 : right.register.byte_12;
- vec.register.byte_13 = left.register.byte_13 > right.register.byte_13 ? left.register.byte_13 : right.register.byte_13;
- vec.register.byte_14 = left.register.byte_14 > right.register.byte_14 ? left.register.byte_14 : right.register.byte_14;
- vec.register.byte_15 = left.register.byte_15 > right.register.byte_15 ? left.register.byte_15 : right.register.byte_15;
- return vec;
- }
- else if (typeof(T) == typeof(sbyte))
- {
- vec.register.sbyte_0 = left.register.sbyte_0 > right.register.sbyte_0 ? left.register.sbyte_0 : right.register.sbyte_0;
- vec.register.sbyte_1 = left.register.sbyte_1 > right.register.sbyte_1 ? left.register.sbyte_1 : right.register.sbyte_1;
- vec.register.sbyte_2 = left.register.sbyte_2 > right.register.sbyte_2 ? left.register.sbyte_2 : right.register.sbyte_2;
- vec.register.sbyte_3 = left.register.sbyte_3 > right.register.sbyte_3 ? left.register.sbyte_3 : right.register.sbyte_3;
- vec.register.sbyte_4 = left.register.sbyte_4 > right.register.sbyte_4 ? left.register.sbyte_4 : right.register.sbyte_4;
- vec.register.sbyte_5 = left.register.sbyte_5 > right.register.sbyte_5 ? left.register.sbyte_5 : right.register.sbyte_5;
- vec.register.sbyte_6 = left.register.sbyte_6 > right.register.sbyte_6 ? left.register.sbyte_6 : right.register.sbyte_6;
- vec.register.sbyte_7 = left.register.sbyte_7 > right.register.sbyte_7 ? left.register.sbyte_7 : right.register.sbyte_7;
- vec.register.sbyte_8 = left.register.sbyte_8 > right.register.sbyte_8 ? left.register.sbyte_8 : right.register.sbyte_8;
- vec.register.sbyte_9 = left.register.sbyte_9 > right.register.sbyte_9 ? left.register.sbyte_9 : right.register.sbyte_9;
- vec.register.sbyte_10 = left.register.sbyte_10 > right.register.sbyte_10 ? left.register.sbyte_10 : right.register.sbyte_10;
- vec.register.sbyte_11 = left.register.sbyte_11 > right.register.sbyte_11 ? left.register.sbyte_11 : right.register.sbyte_11;
- vec.register.sbyte_12 = left.register.sbyte_12 > right.register.sbyte_12 ? left.register.sbyte_12 : right.register.sbyte_12;
- vec.register.sbyte_13 = left.register.sbyte_13 > right.register.sbyte_13 ? left.register.sbyte_13 : right.register.sbyte_13;
- vec.register.sbyte_14 = left.register.sbyte_14 > right.register.sbyte_14 ? left.register.sbyte_14 : right.register.sbyte_14;
- vec.register.sbyte_15 = left.register.sbyte_15 > right.register.sbyte_15 ? left.register.sbyte_15 : right.register.sbyte_15;
- return vec;
- }
- else if (typeof(T) == typeof(ushort))
- {
- vec.register.uint16_0 = left.register.uint16_0 > right.register.uint16_0 ? left.register.uint16_0 : right.register.uint16_0;
- vec.register.uint16_1 = left.register.uint16_1 > right.register.uint16_1 ? left.register.uint16_1 : right.register.uint16_1;
- vec.register.uint16_2 = left.register.uint16_2 > right.register.uint16_2 ? left.register.uint16_2 : right.register.uint16_2;
- vec.register.uint16_3 = left.register.uint16_3 > right.register.uint16_3 ? left.register.uint16_3 : right.register.uint16_3;
- vec.register.uint16_4 = left.register.uint16_4 > right.register.uint16_4 ? left.register.uint16_4 : right.register.uint16_4;
- vec.register.uint16_5 = left.register.uint16_5 > right.register.uint16_5 ? left.register.uint16_5 : right.register.uint16_5;
- vec.register.uint16_6 = left.register.uint16_6 > right.register.uint16_6 ? left.register.uint16_6 : right.register.uint16_6;
- vec.register.uint16_7 = left.register.uint16_7 > right.register.uint16_7 ? left.register.uint16_7 : right.register.uint16_7;
- return vec;
- }
- else if (typeof(T) == typeof(short))
- {
- vec.register.int16_0 = left.register.int16_0 > right.register.int16_0 ? left.register.int16_0 : right.register.int16_0;
- vec.register.int16_1 = left.register.int16_1 > right.register.int16_1 ? left.register.int16_1 : right.register.int16_1;
- vec.register.int16_2 = left.register.int16_2 > right.register.int16_2 ? left.register.int16_2 : right.register.int16_2;
- vec.register.int16_3 = left.register.int16_3 > right.register.int16_3 ? left.register.int16_3 : right.register.int16_3;
- vec.register.int16_4 = left.register.int16_4 > right.register.int16_4 ? left.register.int16_4 : right.register.int16_4;
- vec.register.int16_5 = left.register.int16_5 > right.register.int16_5 ? left.register.int16_5 : right.register.int16_5;
- vec.register.int16_6 = left.register.int16_6 > right.register.int16_6 ? left.register.int16_6 : right.register.int16_6;
- vec.register.int16_7 = left.register.int16_7 > right.register.int16_7 ? left.register.int16_7 : right.register.int16_7;
- return vec;
- }
- else if (typeof(T) == typeof(uint))
- {
- vec.register.uint32_0 = left.register.uint32_0 > right.register.uint32_0 ? left.register.uint32_0 : right.register.uint32_0;
- vec.register.uint32_1 = left.register.uint32_1 > right.register.uint32_1 ? left.register.uint32_1 : right.register.uint32_1;
- vec.register.uint32_2 = left.register.uint32_2 > right.register.uint32_2 ? left.register.uint32_2 : right.register.uint32_2;
- vec.register.uint32_3 = left.register.uint32_3 > right.register.uint32_3 ? left.register.uint32_3 : right.register.uint32_3;
- return vec;
- }
- else if (typeof(T) == typeof(int))
- {
- vec.register.int32_0 = left.register.int32_0 > right.register.int32_0 ? left.register.int32_0 : right.register.int32_0;
- vec.register.int32_1 = left.register.int32_1 > right.register.int32_1 ? left.register.int32_1 : right.register.int32_1;
- vec.register.int32_2 = left.register.int32_2 > right.register.int32_2 ? left.register.int32_2 : right.register.int32_2;
- vec.register.int32_3 = left.register.int32_3 > right.register.int32_3 ? left.register.int32_3 : right.register.int32_3;
- return vec;
- }
- else if (typeof(T) == typeof(ulong))
- {
- vec.register.uint64_0 = left.register.uint64_0 > right.register.uint64_0 ? left.register.uint64_0 : right.register.uint64_0;
- vec.register.uint64_1 = left.register.uint64_1 > right.register.uint64_1 ? left.register.uint64_1 : right.register.uint64_1;
- return vec;
- }
- else if (typeof(T) == typeof(long))
- {
- vec.register.int64_0 = left.register.int64_0 > right.register.int64_0 ? left.register.int64_0 : right.register.int64_0;
- vec.register.int64_1 = left.register.int64_1 > right.register.int64_1 ? left.register.int64_1 : right.register.int64_1;
- return vec;
- }
- else if (typeof(T) == typeof(float))
- {
- vec.register.single_0 = left.register.single_0 > right.register.single_0 ? left.register.single_0 : right.register.single_0;
- vec.register.single_1 = left.register.single_1 > right.register.single_1 ? left.register.single_1 : right.register.single_1;
- vec.register.single_2 = left.register.single_2 > right.register.single_2 ? left.register.single_2 : right.register.single_2;
- vec.register.single_3 = left.register.single_3 > right.register.single_3 ? left.register.single_3 : right.register.single_3;
- return vec;
- }
- else if (typeof(T) == typeof(double))
- {
- vec.register.double_0 = left.register.double_0 > right.register.double_0 ? left.register.double_0 : right.register.double_0;
- vec.register.double_1 = left.register.double_1 > right.register.double_1 ? left.register.double_1 : right.register.double_1;
- return vec;
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- internal static T Dot(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
- T product = default;
- for (int g = 0; g < Count; g++)
- {
- product = ScalarAdd(product, ScalarMultiply(left[g], right[g]));
- }
- return product;
- }
- else
- {
- if (typeof(T) == typeof(byte))
- {
- byte product = 0;
- product += (byte)(left.register.byte_0 * right.register.byte_0);
- product += (byte)(left.register.byte_1 * right.register.byte_1);
- product += (byte)(left.register.byte_2 * right.register.byte_2);
- product += (byte)(left.register.byte_3 * right.register.byte_3);
- product += (byte)(left.register.byte_4 * right.register.byte_4);
- product += (byte)(left.register.byte_5 * right.register.byte_5);
- product += (byte)(left.register.byte_6 * right.register.byte_6);
- product += (byte)(left.register.byte_7 * right.register.byte_7);
- product += (byte)(left.register.byte_8 * right.register.byte_8);
- product += (byte)(left.register.byte_9 * right.register.byte_9);
- product += (byte)(left.register.byte_10 * right.register.byte_10);
- product += (byte)(left.register.byte_11 * right.register.byte_11);
- product += (byte)(left.register.byte_12 * right.register.byte_12);
- product += (byte)(left.register.byte_13 * right.register.byte_13);
- product += (byte)(left.register.byte_14 * right.register.byte_14);
- product += (byte)(left.register.byte_15 * right.register.byte_15);
- return (T)(object)product;
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte product = 0;
- product += (sbyte)(left.register.sbyte_0 * right.register.sbyte_0);
- product += (sbyte)(left.register.sbyte_1 * right.register.sbyte_1);
- product += (sbyte)(left.register.sbyte_2 * right.register.sbyte_2);
- product += (sbyte)(left.register.sbyte_3 * right.register.sbyte_3);
- product += (sbyte)(left.register.sbyte_4 * right.register.sbyte_4);
- product += (sbyte)(left.register.sbyte_5 * right.register.sbyte_5);
- product += (sbyte)(left.register.sbyte_6 * right.register.sbyte_6);
- product += (sbyte)(left.register.sbyte_7 * right.register.sbyte_7);
- product += (sbyte)(left.register.sbyte_8 * right.register.sbyte_8);
- product += (sbyte)(left.register.sbyte_9 * right.register.sbyte_9);
- product += (sbyte)(left.register.sbyte_10 * right.register.sbyte_10);
- product += (sbyte)(left.register.sbyte_11 * right.register.sbyte_11);
- product += (sbyte)(left.register.sbyte_12 * right.register.sbyte_12);
- product += (sbyte)(left.register.sbyte_13 * right.register.sbyte_13);
- product += (sbyte)(left.register.sbyte_14 * right.register.sbyte_14);
- product += (sbyte)(left.register.sbyte_15 * right.register.sbyte_15);
- return (T)(object)product;
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort product = 0;
- product += (ushort)(left.register.uint16_0 * right.register.uint16_0);
- product += (ushort)(left.register.uint16_1 * right.register.uint16_1);
- product += (ushort)(left.register.uint16_2 * right.register.uint16_2);
- product += (ushort)(left.register.uint16_3 * right.register.uint16_3);
- product += (ushort)(left.register.uint16_4 * right.register.uint16_4);
- product += (ushort)(left.register.uint16_5 * right.register.uint16_5);
- product += (ushort)(left.register.uint16_6 * right.register.uint16_6);
- product += (ushort)(left.register.uint16_7 * right.register.uint16_7);
- return (T)(object)product;
- }
- else if (typeof(T) == typeof(short))
- {
- short product = 0;
- product += (short)(left.register.int16_0 * right.register.int16_0);
- product += (short)(left.register.int16_1 * right.register.int16_1);
- product += (short)(left.register.int16_2 * right.register.int16_2);
- product += (short)(left.register.int16_3 * right.register.int16_3);
- product += (short)(left.register.int16_4 * right.register.int16_4);
- product += (short)(left.register.int16_5 * right.register.int16_5);
- product += (short)(left.register.int16_6 * right.register.int16_6);
- product += (short)(left.register.int16_7 * right.register.int16_7);
- return (T)(object)product;
- }
- else if (typeof(T) == typeof(uint))
- {
- uint product = 0;
- product += (uint)(left.register.uint32_0 * right.register.uint32_0);
- product += (uint)(left.register.uint32_1 * right.register.uint32_1);
- product += (uint)(left.register.uint32_2 * right.register.uint32_2);
- product += (uint)(left.register.uint32_3 * right.register.uint32_3);
- return (T)(object)product;
- }
- else if (typeof(T) == typeof(int))
- {
- int product = 0;
- product += (int)(left.register.int32_0 * right.register.int32_0);
- product += (int)(left.register.int32_1 * right.register.int32_1);
- product += (int)(left.register.int32_2 * right.register.int32_2);
- product += (int)(left.register.int32_3 * right.register.int32_3);
- return (T)(object)product;
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong product = 0;
- product += (ulong)(left.register.uint64_0 * right.register.uint64_0);
- product += (ulong)(left.register.uint64_1 * right.register.uint64_1);
- return (T)(object)product;
- }
- else if (typeof(T) == typeof(long))
- {
- long product = 0;
- product += (long)(left.register.int64_0 * right.register.int64_0);
- product += (long)(left.register.int64_1 * right.register.int64_1);
- return (T)(object)product;
- }
- else if (typeof(T) == typeof(float))
- {
- float product = 0;
- product += (float)(left.register.single_0 * right.register.single_0);
- product += (float)(left.register.single_1 * right.register.single_1);
- product += (float)(left.register.single_2 * right.register.single_2);
- product += (float)(left.register.single_3 * right.register.single_3);
- return (T)(object)product;
- }
- else if (typeof(T) == typeof(double))
- {
- double product = 0;
- product += (double)(left.register.double_0 * right.register.double_0);
- product += (double)(left.register.double_1 * right.register.double_1);
- return (T)(object)product;
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- internal static unsafe Vector<T> SquareRoot(Vector<T> value)
- {
- if (Vector.IsHardwareAccelerated)
- {
- if (typeof(T) == typeof(byte))
- {
- byte* dataPtr = stackalloc byte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = unchecked((byte)Math.Sqrt((byte)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte* dataPtr = stackalloc sbyte[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = unchecked((sbyte)Math.Sqrt((sbyte)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort* dataPtr = stackalloc ushort[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = unchecked((ushort)Math.Sqrt((ushort)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(short))
- {
- short* dataPtr = stackalloc short[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = unchecked((short)Math.Sqrt((short)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(uint))
- {
- uint* dataPtr = stackalloc uint[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = unchecked((uint)Math.Sqrt((uint)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(int))
- {
- int* dataPtr = stackalloc int[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = unchecked((int)Math.Sqrt((int)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong* dataPtr = stackalloc ulong[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = unchecked((ulong)Math.Sqrt((ulong)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(long))
- {
- long* dataPtr = stackalloc long[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = unchecked((long)Math.Sqrt((long)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(float))
- {
- float* dataPtr = stackalloc float[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = unchecked((float)Math.Sqrt((float)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else if (typeof(T) == typeof(double))
- {
- double* dataPtr = stackalloc double[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = unchecked((double)Math.Sqrt((double)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- if (typeof(T) == typeof(byte))
- {
- value.register.byte_0 = (byte)Math.Sqrt(value.register.byte_0);
- value.register.byte_1 = (byte)Math.Sqrt(value.register.byte_1);
- value.register.byte_2 = (byte)Math.Sqrt(value.register.byte_2);
- value.register.byte_3 = (byte)Math.Sqrt(value.register.byte_3);
- value.register.byte_4 = (byte)Math.Sqrt(value.register.byte_4);
- value.register.byte_5 = (byte)Math.Sqrt(value.register.byte_5);
- value.register.byte_6 = (byte)Math.Sqrt(value.register.byte_6);
- value.register.byte_7 = (byte)Math.Sqrt(value.register.byte_7);
- value.register.byte_8 = (byte)Math.Sqrt(value.register.byte_8);
- value.register.byte_9 = (byte)Math.Sqrt(value.register.byte_9);
- value.register.byte_10 = (byte)Math.Sqrt(value.register.byte_10);
- value.register.byte_11 = (byte)Math.Sqrt(value.register.byte_11);
- value.register.byte_12 = (byte)Math.Sqrt(value.register.byte_12);
- value.register.byte_13 = (byte)Math.Sqrt(value.register.byte_13);
- value.register.byte_14 = (byte)Math.Sqrt(value.register.byte_14);
- value.register.byte_15 = (byte)Math.Sqrt(value.register.byte_15);
- return value;
- }
- else if (typeof(T) == typeof(sbyte))
- {
- value.register.sbyte_0 = (sbyte)Math.Sqrt(value.register.sbyte_0);
- value.register.sbyte_1 = (sbyte)Math.Sqrt(value.register.sbyte_1);
- value.register.sbyte_2 = (sbyte)Math.Sqrt(value.register.sbyte_2);
- value.register.sbyte_3 = (sbyte)Math.Sqrt(value.register.sbyte_3);
- value.register.sbyte_4 = (sbyte)Math.Sqrt(value.register.sbyte_4);
- value.register.sbyte_5 = (sbyte)Math.Sqrt(value.register.sbyte_5);
- value.register.sbyte_6 = (sbyte)Math.Sqrt(value.register.sbyte_6);
- value.register.sbyte_7 = (sbyte)Math.Sqrt(value.register.sbyte_7);
- value.register.sbyte_8 = (sbyte)Math.Sqrt(value.register.sbyte_8);
- value.register.sbyte_9 = (sbyte)Math.Sqrt(value.register.sbyte_9);
- value.register.sbyte_10 = (sbyte)Math.Sqrt(value.register.sbyte_10);
- value.register.sbyte_11 = (sbyte)Math.Sqrt(value.register.sbyte_11);
- value.register.sbyte_12 = (sbyte)Math.Sqrt(value.register.sbyte_12);
- value.register.sbyte_13 = (sbyte)Math.Sqrt(value.register.sbyte_13);
- value.register.sbyte_14 = (sbyte)Math.Sqrt(value.register.sbyte_14);
- value.register.sbyte_15 = (sbyte)Math.Sqrt(value.register.sbyte_15);
- return value;
- }
- else if (typeof(T) == typeof(ushort))
- {
- value.register.uint16_0 = (ushort)Math.Sqrt(value.register.uint16_0);
- value.register.uint16_1 = (ushort)Math.Sqrt(value.register.uint16_1);
- value.register.uint16_2 = (ushort)Math.Sqrt(value.register.uint16_2);
- value.register.uint16_3 = (ushort)Math.Sqrt(value.register.uint16_3);
- value.register.uint16_4 = (ushort)Math.Sqrt(value.register.uint16_4);
- value.register.uint16_5 = (ushort)Math.Sqrt(value.register.uint16_5);
- value.register.uint16_6 = (ushort)Math.Sqrt(value.register.uint16_6);
- value.register.uint16_7 = (ushort)Math.Sqrt(value.register.uint16_7);
- return value;
- }
- else if (typeof(T) == typeof(short))
- {
- value.register.int16_0 = (short)Math.Sqrt(value.register.int16_0);
- value.register.int16_1 = (short)Math.Sqrt(value.register.int16_1);
- value.register.int16_2 = (short)Math.Sqrt(value.register.int16_2);
- value.register.int16_3 = (short)Math.Sqrt(value.register.int16_3);
- value.register.int16_4 = (short)Math.Sqrt(value.register.int16_4);
- value.register.int16_5 = (short)Math.Sqrt(value.register.int16_5);
- value.register.int16_6 = (short)Math.Sqrt(value.register.int16_6);
- value.register.int16_7 = (short)Math.Sqrt(value.register.int16_7);
- return value;
- }
- else if (typeof(T) == typeof(uint))
- {
- value.register.uint32_0 = (uint)Math.Sqrt(value.register.uint32_0);
- value.register.uint32_1 = (uint)Math.Sqrt(value.register.uint32_1);
- value.register.uint32_2 = (uint)Math.Sqrt(value.register.uint32_2);
- value.register.uint32_3 = (uint)Math.Sqrt(value.register.uint32_3);
- return value;
- }
- else if (typeof(T) == typeof(int))
- {
- value.register.int32_0 = (int)Math.Sqrt(value.register.int32_0);
- value.register.int32_1 = (int)Math.Sqrt(value.register.int32_1);
- value.register.int32_2 = (int)Math.Sqrt(value.register.int32_2);
- value.register.int32_3 = (int)Math.Sqrt(value.register.int32_3);
- return value;
- }
- else if (typeof(T) == typeof(ulong))
- {
- value.register.uint64_0 = (ulong)Math.Sqrt(value.register.uint64_0);
- value.register.uint64_1 = (ulong)Math.Sqrt(value.register.uint64_1);
- return value;
- }
- else if (typeof(T) == typeof(long))
- {
- value.register.int64_0 = (long)Math.Sqrt(value.register.int64_0);
- value.register.int64_1 = (long)Math.Sqrt(value.register.int64_1);
- return value;
- }
- else if (typeof(T) == typeof(float))
- {
- value.register.single_0 = (float)Math.Sqrt(value.register.single_0);
- value.register.single_1 = (float)Math.Sqrt(value.register.single_1);
- value.register.single_2 = (float)Math.Sqrt(value.register.single_2);
- value.register.single_3 = (float)Math.Sqrt(value.register.single_3);
- return value;
- }
- else if (typeof(T) == typeof(double))
- {
- value.register.double_0 = (double)Math.Sqrt(value.register.double_0);
- value.register.double_1 = (double)Math.Sqrt(value.register.double_1);
- return value;
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
- #endregion Internal Math Methods
-
- #region Helper Methods
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool ScalarEquals(T left, T right)
- {
- if (typeof(T) == typeof(byte))
- {
- return (byte)(object)left == (byte)(object)right;
- }
- else if (typeof(T) == typeof(sbyte))
- {
- return (sbyte)(object)left == (sbyte)(object)right;
- }
- else if (typeof(T) == typeof(ushort))
- {
- return (ushort)(object)left == (ushort)(object)right;
- }
- else if (typeof(T) == typeof(short))
- {
- return (short)(object)left == (short)(object)right;
- }
- else if (typeof(T) == typeof(uint))
- {
- return (uint)(object)left == (uint)(object)right;
- }
- else if (typeof(T) == typeof(int))
- {
- return (int)(object)left == (int)(object)right;
- }
- else if (typeof(T) == typeof(ulong))
- {
- return (ulong)(object)left == (ulong)(object)right;
- }
- else if (typeof(T) == typeof(long))
- {
- return (long)(object)left == (long)(object)right;
- }
- else if (typeof(T) == typeof(float))
- {
- return (float)(object)left == (float)(object)right;
- }
- else if (typeof(T) == typeof(double))
- {
- return (double)(object)left == (double)(object)right;
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool ScalarLessThan(T left, T right)
- {
- if (typeof(T) == typeof(byte))
- {
- return (byte)(object)left < (byte)(object)right;
- }
- else if (typeof(T) == typeof(sbyte))
- {
- return (sbyte)(object)left < (sbyte)(object)right;
- }
- else if (typeof(T) == typeof(ushort))
- {
- return (ushort)(object)left < (ushort)(object)right;
- }
- else if (typeof(T) == typeof(short))
- {
- return (short)(object)left < (short)(object)right;
- }
- else if (typeof(T) == typeof(uint))
- {
- return (uint)(object)left < (uint)(object)right;
- }
- else if (typeof(T) == typeof(int))
- {
- return (int)(object)left < (int)(object)right;
- }
- else if (typeof(T) == typeof(ulong))
- {
- return (ulong)(object)left < (ulong)(object)right;
- }
- else if (typeof(T) == typeof(long))
- {
- return (long)(object)left < (long)(object)right;
- }
- else if (typeof(T) == typeof(float))
- {
- return (float)(object)left < (float)(object)right;
- }
- else if (typeof(T) == typeof(double))
- {
- return (double)(object)left < (double)(object)right;
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool ScalarGreaterThan(T left, T right)
- {
- if (typeof(T) == typeof(byte))
- {
- return (byte)(object)left > (byte)(object)right;
- }
- else if (typeof(T) == typeof(sbyte))
- {
- return (sbyte)(object)left > (sbyte)(object)right;
- }
- else if (typeof(T) == typeof(ushort))
- {
- return (ushort)(object)left > (ushort)(object)right;
- }
- else if (typeof(T) == typeof(short))
- {
- return (short)(object)left > (short)(object)right;
- }
- else if (typeof(T) == typeof(uint))
- {
- return (uint)(object)left > (uint)(object)right;
- }
- else if (typeof(T) == typeof(int))
- {
- return (int)(object)left > (int)(object)right;
- }
- else if (typeof(T) == typeof(ulong))
- {
- return (ulong)(object)left > (ulong)(object)right;
- }
- else if (typeof(T) == typeof(long))
- {
- return (long)(object)left > (long)(object)right;
- }
- else if (typeof(T) == typeof(float))
- {
- return (float)(object)left > (float)(object)right;
- }
- else if (typeof(T) == typeof(double))
- {
- return (double)(object)left > (double)(object)right;
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T ScalarAdd(T left, T right)
- {
- if (typeof(T) == typeof(byte))
- {
- return (T)(object)unchecked((byte)((byte)(object)left + (byte)(object)right));
- }
- else if (typeof(T) == typeof(sbyte))
- {
- return (T)(object)unchecked((sbyte)((sbyte)(object)left + (sbyte)(object)right));
- }
- else if (typeof(T) == typeof(ushort))
- {
- return (T)(object)unchecked((ushort)((ushort)(object)left + (ushort)(object)right));
- }
- else if (typeof(T) == typeof(short))
- {
- return (T)(object)unchecked((short)((short)(object)left + (short)(object)right));
- }
- else if (typeof(T) == typeof(uint))
- {
- return (T)(object)unchecked((uint)((uint)(object)left + (uint)(object)right));
- }
- else if (typeof(T) == typeof(int))
- {
- return (T)(object)unchecked((int)((int)(object)left + (int)(object)right));
- }
- else if (typeof(T) == typeof(ulong))
- {
- return (T)(object)unchecked((ulong)((ulong)(object)left + (ulong)(object)right));
- }
- else if (typeof(T) == typeof(long))
- {
- return (T)(object)unchecked((long)((long)(object)left + (long)(object)right));
- }
- else if (typeof(T) == typeof(float))
- {
- return (T)(object)unchecked((float)((float)(object)left + (float)(object)right));
- }
- else if (typeof(T) == typeof(double))
- {
- return (T)(object)unchecked((double)((double)(object)left + (double)(object)right));
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T ScalarSubtract(T left, T right)
- {
- if (typeof(T) == typeof(byte))
- {
- return (T)(object)(byte)((byte)(object)left - (byte)(object)right);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- return (T)(object)(sbyte)((sbyte)(object)left - (sbyte)(object)right);
- }
- else if (typeof(T) == typeof(ushort))
- {
- return (T)(object)(ushort)((ushort)(object)left - (ushort)(object)right);
- }
- else if (typeof(T) == typeof(short))
- {
- return (T)(object)(short)((short)(object)left - (short)(object)right);
- }
- else if (typeof(T) == typeof(uint))
- {
- return (T)(object)(uint)((uint)(object)left - (uint)(object)right);
- }
- else if (typeof(T) == typeof(int))
- {
- return (T)(object)(int)((int)(object)left - (int)(object)right);
- }
- else if (typeof(T) == typeof(ulong))
- {
- return (T)(object)(ulong)((ulong)(object)left - (ulong)(object)right);
- }
- else if (typeof(T) == typeof(long))
- {
- return (T)(object)(long)((long)(object)left - (long)(object)right);
- }
- else if (typeof(T) == typeof(float))
- {
- return (T)(object)(float)((float)(object)left - (float)(object)right);
- }
- else if (typeof(T) == typeof(double))
- {
- return (T)(object)(double)((double)(object)left - (double)(object)right);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T ScalarMultiply(T left, T right)
- {
- if (typeof(T) == typeof(byte))
- {
- return (T)(object)unchecked((byte)((byte)(object)left * (byte)(object)right));
- }
- else if (typeof(T) == typeof(sbyte))
- {
- return (T)(object)unchecked((sbyte)((sbyte)(object)left * (sbyte)(object)right));
- }
- else if (typeof(T) == typeof(ushort))
- {
- return (T)(object)unchecked((ushort)((ushort)(object)left * (ushort)(object)right));
- }
- else if (typeof(T) == typeof(short))
- {
- return (T)(object)unchecked((short)((short)(object)left * (short)(object)right));
- }
- else if (typeof(T) == typeof(uint))
- {
- return (T)(object)unchecked((uint)((uint)(object)left * (uint)(object)right));
- }
- else if (typeof(T) == typeof(int))
- {
- return (T)(object)unchecked((int)((int)(object)left * (int)(object)right));
- }
- else if (typeof(T) == typeof(ulong))
- {
- return (T)(object)unchecked((ulong)((ulong)(object)left * (ulong)(object)right));
- }
- else if (typeof(T) == typeof(long))
- {
- return (T)(object)unchecked((long)((long)(object)left * (long)(object)right));
- }
- else if (typeof(T) == typeof(float))
- {
- return (T)(object)unchecked((float)((float)(object)left * (float)(object)right));
- }
- else if (typeof(T) == typeof(double))
- {
- return (T)(object)unchecked((double)((double)(object)left * (double)(object)right));
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T ScalarDivide(T left, T right)
- {
- if (typeof(T) == typeof(byte))
- {
- return (T)(object)(byte)((byte)(object)left / (byte)(object)right);
- }
- else if (typeof(T) == typeof(sbyte))
- {
- return (T)(object)(sbyte)((sbyte)(object)left / (sbyte)(object)right);
- }
- else if (typeof(T) == typeof(ushort))
- {
- return (T)(object)(ushort)((ushort)(object)left / (ushort)(object)right);
- }
- else if (typeof(T) == typeof(short))
- {
- return (T)(object)(short)((short)(object)left / (short)(object)right);
- }
- else if (typeof(T) == typeof(uint))
- {
- return (T)(object)(uint)((uint)(object)left / (uint)(object)right);
- }
- else if (typeof(T) == typeof(int))
- {
- return (T)(object)(int)((int)(object)left / (int)(object)right);
- }
- else if (typeof(T) == typeof(ulong))
- {
- return (T)(object)(ulong)((ulong)(object)left / (ulong)(object)right);
- }
- else if (typeof(T) == typeof(long))
- {
- return (T)(object)(long)((long)(object)left / (long)(object)right);
- }
- else if (typeof(T) == typeof(float))
- {
- return (T)(object)(float)((float)(object)left / (float)(object)right);
- }
- else if (typeof(T) == typeof(double))
- {
- return (T)(object)(double)((double)(object)left / (double)(object)right);
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T GetOneValue()
- {
- if (typeof(T) == typeof(byte))
- {
- byte value = 1;
- return (T)(object)value;
- }
- else if (typeof(T) == typeof(sbyte))
- {
- sbyte value = 1;
- return (T)(object)value;
- }
- else if (typeof(T) == typeof(ushort))
- {
- ushort value = 1;
- return (T)(object)value;
- }
- else if (typeof(T) == typeof(short))
- {
- short value = 1;
- return (T)(object)value;
- }
- else if (typeof(T) == typeof(uint))
- {
- uint value = 1;
- return (T)(object)value;
- }
- else if (typeof(T) == typeof(int))
- {
- int value = 1;
- return (T)(object)value;
- }
- else if (typeof(T) == typeof(ulong))
- {
- ulong value = 1;
- return (T)(object)value;
- }
- else if (typeof(T) == typeof(long))
- {
- long value = 1;
- return (T)(object)value;
- }
- else if (typeof(T) == typeof(float))
- {
- float value = 1;
- return (T)(object)value;
- }
- else if (typeof(T) == typeof(double))
- {
- double value = 1;
- return (T)(object)value;
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T GetAllBitsSetValue()
- {
- if (typeof(T) == typeof(byte))
- {
- return (T)(object)ConstantHelper.GetByteWithAllBitsSet();
- }
- else if (typeof(T) == typeof(sbyte))
- {
- return (T)(object)ConstantHelper.GetSByteWithAllBitsSet();
- }
- else if (typeof(T) == typeof(ushort))
- {
- return (T)(object)ConstantHelper.GetUInt16WithAllBitsSet();
- }
- else if (typeof(T) == typeof(short))
- {
- return (T)(object)ConstantHelper.GetInt16WithAllBitsSet();
- }
- else if (typeof(T) == typeof(uint))
- {
- return (T)(object)ConstantHelper.GetUInt32WithAllBitsSet();
- }
- else if (typeof(T) == typeof(int))
- {
- return (T)(object)ConstantHelper.GetInt32WithAllBitsSet();
- }
- else if (typeof(T) == typeof(ulong))
- {
- return (T)(object)ConstantHelper.GetUInt64WithAllBitsSet();
- }
- else if (typeof(T) == typeof(long))
- {
- return (T)(object)ConstantHelper.GetInt64WithAllBitsSet();
- }
- else if (typeof(T) == typeof(float))
- {
- return (T)(object)ConstantHelper.GetSingleWithAllBitsSet();
- }
- else if (typeof(T) == typeof(double))
- {
- return (T)(object)ConstantHelper.GetDoubleWithAllBitsSet();
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- #endregion
- }
-
- [Intrinsic]
- public static partial class Vector
- {
- #region Widen/Narrow
- /// <summary>
- /// Widens a Vector{Byte} into two Vector{UInt16}'s.
- /// <param name="source">The source vector whose elements are widened into the outputs.</param>
- /// <param name="low">The first output vector, whose elements will contain the widened elements from lower indices in the source vector.</param>
- /// <param name="high">The second output vector, whose elements will contain the widened elements from higher indices in the source vector.</param>
- /// </summary>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe void Widen(Vector<byte> source, out Vector<ushort> low, out Vector<ushort> high)
- {
- int elements = Vector<byte>.Count;
- ushort* lowPtr = stackalloc ushort[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- lowPtr[i] = (ushort)source[i];
- }
- ushort* highPtr = stackalloc ushort[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- highPtr[i] = (ushort)source[i + (elements / 2)];
- }
-
- low = new Vector<ushort>(lowPtr);
- high = new Vector<ushort>(highPtr);
- }
-
- /// <summary>
- /// Widens a Vector{UInt16} into two Vector{UInt32}'s.
- /// <param name="source">The source vector whose elements are widened into the outputs.</param>
- /// <param name="low">The first output vector, whose elements will contain the widened elements from lower indices in the source vector.</param>
- /// <param name="high">The second output vector, whose elements will contain the widened elements from higher indices in the source vector.</param>
- /// </summary>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe void Widen(Vector<ushort> source, out Vector<uint> low, out Vector<uint> high)
- {
- int elements = Vector<ushort>.Count;
- uint* lowPtr = stackalloc uint[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- lowPtr[i] = (uint)source[i];
- }
- uint* highPtr = stackalloc uint[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- highPtr[i] = (uint)source[i + (elements / 2)];
- }
-
- low = new Vector<uint>(lowPtr);
- high = new Vector<uint>(highPtr);
- }
-
- /// <summary>
- /// Widens a Vector{UInt32} into two Vector{UInt64}'s.
- /// <param name="source">The source vector whose elements are widened into the outputs.</param>
- /// <param name="low">The first output vector, whose elements will contain the widened elements from lower indices in the source vector.</param>
- /// <param name="high">The second output vector, whose elements will contain the widened elements from higher indices in the source vector.</param>
- /// </summary>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe void Widen(Vector<uint> source, out Vector<ulong> low, out Vector<ulong> high)
- {
- int elements = Vector<uint>.Count;
- ulong* lowPtr = stackalloc ulong[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- lowPtr[i] = (ulong)source[i];
- }
- ulong* highPtr = stackalloc ulong[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- highPtr[i] = (ulong)source[i + (elements / 2)];
- }
-
- low = new Vector<ulong>(lowPtr);
- high = new Vector<ulong>(highPtr);
- }
-
- /// <summary>
- /// Widens a Vector{SByte} into two Vector{Int16}'s.
- /// <param name="source">The source vector whose elements are widened into the outputs.</param>
- /// <param name="low">The first output vector, whose elements will contain the widened elements from lower indices in the source vector.</param>
- /// <param name="high">The second output vector, whose elements will contain the widened elements from higher indices in the source vector.</param>
- /// </summary>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe void Widen(Vector<sbyte> source, out Vector<short> low, out Vector<short> high)
- {
- int elements = Vector<sbyte>.Count;
- short* lowPtr = stackalloc short[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- lowPtr[i] = (short)source[i];
- }
- short* highPtr = stackalloc short[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- highPtr[i] = (short)source[i + (elements / 2)];
- }
-
- low = new Vector<short>(lowPtr);
- high = new Vector<short>(highPtr);
- }
-
- /// <summary>
- /// Widens a Vector{Int16} into two Vector{Int32}'s.
- /// <param name="source">The source vector whose elements are widened into the outputs.</param>
- /// <param name="low">The first output vector, whose elements will contain the widened elements from lower indices in the source vector.</param>
- /// <param name="high">The second output vector, whose elements will contain the widened elements from higher indices in the source vector.</param>
- /// </summary>
- [Intrinsic]
- public static unsafe void Widen(Vector<short> source, out Vector<int> low, out Vector<int> high)
- {
- int elements = Vector<short>.Count;
- int* lowPtr = stackalloc int[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- lowPtr[i] = (int)source[i];
- }
- int* highPtr = stackalloc int[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- highPtr[i] = (int)source[i + (elements / 2)];
- }
-
- low = new Vector<int>(lowPtr);
- high = new Vector<int>(highPtr);
- }
-
- /// <summary>
- /// Widens a Vector{Int32} into two Vector{Int64}'s.
- /// <param name="source">The source vector whose elements are widened into the outputs.</param>
- /// <param name="low">The first output vector, whose elements will contain the widened elements from lower indices in the source vector.</param>
- /// <param name="high">The second output vector, whose elements will contain the widened elements from higher indices in the source vector.</param>
- /// </summary>
- [Intrinsic]
- public static unsafe void Widen(Vector<int> source, out Vector<long> low, out Vector<long> high)
- {
- int elements = Vector<int>.Count;
- long* lowPtr = stackalloc long[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- lowPtr[i] = (long)source[i];
- }
- long* highPtr = stackalloc long[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- highPtr[i] = (long)source[i + (elements / 2)];
- }
-
- low = new Vector<long>(lowPtr);
- high = new Vector<long>(highPtr);
- }
-
- /// <summary>
- /// Widens a Vector{Single} into two Vector{Double}'s.
- /// <param name="source">The source vector whose elements are widened into the outputs.</param>
- /// <param name="low">The first output vector, whose elements will contain the widened elements from lower indices in the source vector.</param>
- /// <param name="high">The second output vector, whose elements will contain the widened elements from higher indices in the source vector.</param>
- /// </summary>
- [Intrinsic]
- public static unsafe void Widen(Vector<float> source, out Vector<double> low, out Vector<double> high)
- {
- int elements = Vector<float>.Count;
- double* lowPtr = stackalloc double[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- lowPtr[i] = (double)source[i];
- }
- double* highPtr = stackalloc double[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- highPtr[i] = (double)source[i + (elements / 2)];
- }
-
- low = new Vector<double>(lowPtr);
- high = new Vector<double>(highPtr);
- }
-
- /// <summary>
- /// Narrows two Vector{UInt16}'s into one Vector{Byte}.
- /// <param name="low">The first source vector, whose elements become the lower-index elements of the return value.</param>
- /// <param name="high">The second source vector, whose elements become the higher-index elements of the return value.</param>
- /// <returns>A Vector{Byte} containing elements narrowed from the source vectors.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe Vector<byte> Narrow(Vector<ushort> low, Vector<ushort> high)
- {
- unchecked
- {
- int elements = Vector<byte>.Count;
- byte* retPtr = stackalloc byte[elements];
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i] = (byte)low[i];
- }
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i + (elements / 2)] = (byte)high[i];
- }
-
- return new Vector<byte>(retPtr);
- }
- }
-
- /// <summary>
- /// Narrows two Vector{UInt32}'s into one Vector{UInt16}.
- /// <param name="low">The first source vector, whose elements become the lower-index elements of the return value.</param>
- /// <param name="high">The second source vector, whose elements become the higher-index elements of the return value.</param>
- /// <returns>A Vector{UInt16} containing elements narrowed from the source vectors.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe Vector<ushort> Narrow(Vector<uint> low, Vector<uint> high)
- {
- unchecked
- {
- int elements = Vector<ushort>.Count;
- ushort* retPtr = stackalloc ushort[elements];
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i] = (ushort)low[i];
- }
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i + (elements / 2)] = (ushort)high[i];
- }
-
- return new Vector<ushort>(retPtr);
- }
- }
-
- /// <summary>
- /// Narrows two Vector{UInt64}'s into one Vector{UInt32}.
- /// <param name="low">The first source vector, whose elements become the lower-index elements of the return value.</param>
- /// <param name="high">The second source vector, whose elements become the higher-index elements of the return value.</param>
- /// <returns>A Vector{UInt32} containing elements narrowed from the source vectors.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe Vector<uint> Narrow(Vector<ulong> low, Vector<ulong> high)
- {
- unchecked
- {
- int elements = Vector<uint>.Count;
- uint* retPtr = stackalloc uint[elements];
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i] = (uint)low[i];
- }
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i + (elements / 2)] = (uint)high[i];
- }
-
- return new Vector<uint>(retPtr);
- }
- }
-
- /// <summary>
- /// Narrows two Vector{Int16}'s into one Vector{SByte}.
- /// <param name="low">The first source vector, whose elements become the lower-index elements of the return value.</param>
- /// <param name="high">The second source vector, whose elements become the higher-index elements of the return value.</param>
- /// <returns>A Vector{SByte} containing elements narrowed from the source vectors.</returns>
- /// </summary>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe Vector<sbyte> Narrow(Vector<short> low, Vector<short> high)
- {
- unchecked
- {
- int elements = Vector<sbyte>.Count;
- sbyte* retPtr = stackalloc sbyte[elements];
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i] = (sbyte)low[i];
- }
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i + (elements / 2)] = (sbyte)high[i];
- }
-
- return new Vector<sbyte>(retPtr);
- }
- }
-
- /// <summary>
- /// Narrows two Vector{Int32}'s into one Vector{Int16}.
- /// <param name="low">The first source vector, whose elements become the lower-index elements of the return value.</param>
- /// <param name="high">The second source vector, whose elements become the higher-index elements of the return value.</param>
- /// <returns>A Vector{Int16} containing elements narrowed from the source vectors.</returns>
- /// </summary>
- [Intrinsic]
- public static unsafe Vector<short> Narrow(Vector<int> low, Vector<int> high)
- {
- unchecked
- {
- int elements = Vector<short>.Count;
- short* retPtr = stackalloc short[elements];
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i] = (short)low[i];
- }
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i + (elements / 2)] = (short)high[i];
- }
-
- return new Vector<short>(retPtr);
- }
- }
-
- /// <summary>
- /// Narrows two Vector{Int64}'s into one Vector{Int32}.
- /// <param name="low">The first source vector, whose elements become the lower-index elements of the return value.</param>
- /// <param name="high">The second source vector, whose elements become the higher-index elements of the return value.</param>
- /// <returns>A Vector{Int32} containing elements narrowed from the source vectors.</returns>
- /// </summary>
- [Intrinsic]
- public static unsafe Vector<int> Narrow(Vector<long> low, Vector<long> high)
- {
- unchecked
- {
- int elements = Vector<int>.Count;
- int* retPtr = stackalloc int[elements];
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i] = (int)low[i];
- }
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i + (elements / 2)] = (int)high[i];
- }
-
- return new Vector<int>(retPtr);
- }
- }
-
- /// <summary>
- /// Narrows two Vector{Double}'s into one Vector{Single}.
- /// <param name="low">The first source vector, whose elements become the lower-index elements of the return value.</param>
- /// <param name="high">The second source vector, whose elements become the higher-index elements of the return value.</param>
- /// <returns>A Vector{Single} containing elements narrowed from the source vectors.</returns>
- /// </summary>
- [Intrinsic]
- public static unsafe Vector<float> Narrow(Vector<double> low, Vector<double> high)
- {
- unchecked
- {
- int elements = Vector<float>.Count;
- float* retPtr = stackalloc float[elements];
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i] = (float)low[i];
- }
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i + (elements / 2)] = (float)high[i];
- }
-
- return new Vector<float>(retPtr);
- }
- }
-
- #endregion Widen/Narrow
-
- #region Same-Size Conversion
- /// <summary>
- /// Converts a Vector{Int32} to a Vector{Single}.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The converted vector.</returns>
- [Intrinsic]
- public static unsafe Vector<float> ConvertToSingle(Vector<int> value)
- {
- unchecked
- {
- int elements = Vector<float>.Count;
- float* retPtr = stackalloc float[elements];
- for (int i = 0; i < elements; i++)
- {
- retPtr[i] = (float)value[i];
- }
-
- return new Vector<float>(retPtr);
- }
- }
-
- /// <summary>
- /// Converts a Vector{UInt32} to a Vector{Single}.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The converted vector.</returns>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe Vector<float> ConvertToSingle(Vector<uint> value)
- {
- unchecked
- {
- int elements = Vector<float>.Count;
- float* retPtr = stackalloc float[elements];
- for (int i = 0; i < elements; i++)
- {
- retPtr[i] = (float)value[i];
- }
-
- return new Vector<float>(retPtr);
- }
- }
-
- /// <summary>
- /// Converts a Vector{Int64} to a Vector{Double}.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The converted vector.</returns>
- [Intrinsic]
- public static unsafe Vector<double> ConvertToDouble(Vector<long> value)
- {
- unchecked
- {
- int elements = Vector<double>.Count;
- double* retPtr = stackalloc double[elements];
- for (int i = 0; i < elements; i++)
- {
- retPtr[i] = (double)value[i];
- }
-
- return new Vector<double>(retPtr);
- }
- }
-
- /// <summary>
- /// Converts a Vector{UInt64} to a Vector{Double}.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The converted vector.</returns>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe Vector<double> ConvertToDouble(Vector<ulong> value)
- {
- unchecked
- {
- int elements = Vector<double>.Count;
- double* retPtr = stackalloc double[elements];
- for (int i = 0; i < elements; i++)
- {
- retPtr[i] = (double)value[i];
- }
-
- return new Vector<double>(retPtr);
- }
- }
-
- /// <summary>
- /// Converts a Vector{Single} to a Vector{Int32}.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The converted vector.</returns>
- [Intrinsic]
- public static unsafe Vector<int> ConvertToInt32(Vector<float> value)
- {
- unchecked
- {
- int elements = Vector<int>.Count;
- int* retPtr = stackalloc int[elements];
- for (int i = 0; i < elements; i++)
- {
- retPtr[i] = (int)value[i];
- }
-
- return new Vector<int>(retPtr);
- }
- }
-
- /// <summary>
- /// Converts a Vector{Single} to a Vector{UInt32}.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The converted vector.</returns>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe Vector<uint> ConvertToUInt32(Vector<float> value)
- {
- unchecked
- {
- int elements = Vector<uint>.Count;
- uint* retPtr = stackalloc uint[elements];
- for (int i = 0; i < elements; i++)
- {
- retPtr[i] = (uint)value[i];
- }
-
- return new Vector<uint>(retPtr);
- }
- }
-
- /// <summary>
- /// Converts a Vector{Double} to a Vector{Int64}.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The converted vector.</returns>
- [Intrinsic]
- public static unsafe Vector<long> ConvertToInt64(Vector<double> value)
- {
- unchecked
- {
- int elements = Vector<long>.Count;
- long* retPtr = stackalloc long[elements];
- for (int i = 0; i < elements; i++)
- {
- retPtr[i] = (long)value[i];
- }
-
- return new Vector<long>(retPtr);
- }
- }
-
- /// <summary>
- /// Converts a Vector{Double} to a Vector{UInt64}.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The converted vector.</returns>
- [CLSCompliant(false)]
- [Intrinsic]
- public static unsafe Vector<ulong> ConvertToUInt64(Vector<double> value)
- {
- unchecked
- {
- int elements = Vector<ulong>.Count;
- ulong* retPtr = stackalloc ulong[elements];
- for (int i = 0; i < elements; i++)
- {
- retPtr[i] = (ulong)value[i];
- }
-
- return new Vector<ulong>(retPtr);
- }
- }
-
- #endregion Same-Size Conversion
-
- #region Throw Helpers
- [DoesNotReturn]
- internal static void ThrowInsufficientNumberOfElementsException(int requiredElementCount)
- {
- throw new IndexOutOfRangeException(SR.Format(SR.Arg_InsufficientNumberOfElements, requiredElementCount, "values"));
- }
- #endregion
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector.tt b/netcore/System.Private.CoreLib/shared/System/Numerics/Vector.tt
deleted file mode 100644
index e362fac258f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector.tt
+++ /dev/null
@@ -1,1729 +0,0 @@
-<#@ template debug="true" hostSpecific="true" #>
-<#@ output extension=".cs" #>
-<#@ Assembly Name="System.Core.dll" #>
-<#@ Assembly Name="System.Xml.dll" #>
-<#@ import namespace="System" #>
-<#@ import namespace="System.Linq" #>
-<#@ import namespace="System.Runtime.InteropServices" #>
-<#@ include file="GenerationConfig.ttinclude" #><# GenerateCopyrightHeader(); #>
-
-using System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nint = System.Int64;
-#else
-using nint = System.Int32;
-#endif
-
-namespace System.Numerics
-{
- /* Note: The following patterns are used throughout the code here and are described here
- *
- * PATTERN:
- * if (typeof(T) == typeof(int)) { ... }
- * else if (typeof(T) == typeof(float)) { ... }
- * EXPLANATION:
- * At runtime, each instantiation of Vector<T> will be type-specific, and each of these typeof blocks will be eliminated,
- * as typeof(T) is a (JIT) compile-time constant for each instantiation. This design was chosen to eliminate any overhead from
- * delegates and other patterns.
- *
- * PATTERN:
- * if (Vector.IsHardwareAccelerated) { ... }
- * else { ... }
- * EXPLANATION
- * This pattern solves two problems:
- * 1. Allows us to unroll loops when we know the size (when no hardware acceleration is present)
- * 2. Allows reflection to work:
- * - If a method is called via reflection, it will not be "intrinsified", which would cause issues if we did
- * not provide an implementation for that case (i.e. if it only included a case which assumed 16-byte registers)
- * (NOTE: It is assumed that Vector.IsHardwareAccelerated will be a compile-time constant, eliminating these checks
- * from the JIT'd code.)
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- /// <summary>
- /// A structure that represents a single Vector. The count of this Vector is fixed but CPU register dependent.
- /// This struct only supports numerical types. This type is intended to be used as a building block for vectorizing
- /// large algorithms. This type is immutable, individual elements cannot be modified.
- /// </summary>
- [Intrinsic]
- public struct Vector<T> : IEquatable<Vector<T>>, IFormattable where T : struct
- {
- #region Fields
- private Register register;
- #endregion Fields
-
- #region Static Members
- /// <summary>
- /// Returns the number of elements stored in the vector. This value is hardware dependent.
- /// </summary>
- public static int Count
- {
- [Intrinsic]
- get
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Unsafe.SizeOf<Vector<T>>() / Unsafe.SizeOf<T>();
- }
- }
-
- /// <summary>
- /// Returns a vector containing all zeroes.
- /// </summary>
- public static Vector<T> Zero
- {
- [Intrinsic]
- get => s_zero;
- }
-#pragma warning disable 0649 // never assigned to
- private static readonly Vector<T> s_zero;
-#pragma warning restore 0649
-
- /// <summary>
- /// Returns a vector containing all ones.
- /// </summary>
- public static Vector<T> One
- {
- [Intrinsic]
- get => s_one;
- }
- private static readonly Vector<T> s_one = new Vector<T>(GetOneValue());
-
- internal static Vector<T> AllOnes
- {
- [Intrinsic]
- get => s_allOnes;
- }
- private static readonly Vector<T> s_allOnes = new Vector<T>(GetAllBitsSetValue());
- #endregion Static Members
-
- #region Constructors
- /// <summary>
- /// Constructs a vector whose components are all <code>value</code>
- /// </summary>
- [Intrinsic]
- public unsafe Vector(T value)
- : this()
- {
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- fixed (<#=typeAliases[type]#>* basePtr = &this.<#=GetRegisterFieldName(type, 0)#>)
- {
- for (nint g = 0; g < Count; g++)
- {
- *(basePtr + g) = (<#=typeAliases[type]#>)(object)value;
- }
- }
- }
-<#
- }
-#>
- }
- else
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
-<#
- for (int g = 0; g < totalSize / Marshal.SizeOf(type); g++)
- {
-#>
- <#=GetRegisterFieldName(type, g)#> = (<#=typeAliases[type]#>)(object)value;
-<#
- }
-#>
- }
-<#
- }
-#>
- }
- }
-
- /// <summary>
- /// Constructs a vector from the given array. The size of the given array must be at least Vector'T.Count.
- /// </summary>
- [Intrinsic]
- public unsafe Vector(T[] values) : this(values, 0) { }
-
- /// <summary>
- /// Constructs a vector from the given array, starting from the given index.
- /// The array must contain at least Vector'T.Count from the given index.
- /// </summary>
- [Intrinsic]
- public unsafe Vector(T[] values, int index)
- {
- if (values == null)
- {
- // Match the JIT's exception type here. For perf, a NullReference is thrown instead of an ArgumentNull.
- throw new NullReferenceException(SR.Arg_NullArgumentNullRef);
- }
- if (index < 0 || (values.Length - index) < Count)
- {
- Vector.ThrowInsufficientNumberOfElementsException(Vector<T>.Count);
- }
- this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref values[index]));
- }
-
- internal unsafe Vector(void* dataPointer)
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- this = Unsafe.ReadUnaligned<Vector<T>>(dataPointer);
- }
-
- private Vector(ref Register existingRegister)
- {
- this.register = existingRegister;
- }
-
- /// <summary>
- /// Constructs a vector from the given <see cref="ReadOnlySpan{Byte}"/>. The span must contain at least <see cref="Vector{Byte}.Count"/> elements.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Vector(ReadOnlySpan<byte> values)
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- if (values.Length < Vector<byte>.Count)
- {
- Vector.ThrowInsufficientNumberOfElementsException(Vector<byte>.Count);
- }
- this = Unsafe.ReadUnaligned<Vector<T>>(ref MemoryMarshal.GetReference(values));
- }
-
- /// <summary>
- /// Constructs a vector from the given <see cref="ReadOnlySpan{T}"/>. The span must contain at least <see cref="Vector{T}.Count"/> elements.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Vector(ReadOnlySpan<T> values)
- {
- if (values.Length < Count)
- {
- Vector.ThrowInsufficientNumberOfElementsException(Vector<T>.Count);
- }
- this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)));
- }
-
- /// <summary>
- /// Constructs a vector from the given <see cref="Span{T}"/>. The span must contain at least <see cref="Vector{T}.Count"/> elements.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Vector(Span<T> values)
- {
- if (values.Length < Count)
- {
- Vector.ThrowInsufficientNumberOfElementsException(Vector<T>.Count);
- }
- this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)));
- }
- #endregion Constructors
-
- #region Public Instance Methods
- /// <summary>
- /// Copies the vector to the given <see cref="Span{Byte}"/>. The destination span must be at least size <see cref="Vector{Byte}.Count"/>.
- /// </summary>
- /// <param name="destination">The destination span which the values are copied into</param>
- /// <exception cref="ArgumentException">If number of elements in source vector is greater than those available in destination span</exception>
- public readonly void CopyTo(Span<byte> destination)
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- if ((uint)destination.Length < (uint)Vector<byte>.Count)
- {
- ThrowHelper.ThrowArgumentException_DestinationTooShort();
- }
-
- Unsafe.WriteUnaligned<Vector<T>>(ref MemoryMarshal.GetReference(destination), this);
- }
-
- /// <summary>
- /// Copies the vector to the given <see cref="Span{T}"/>. The destination span must be at least size <see cref="Vector{T}.Count"/>.
- /// </summary>
- /// <param name="destination">The destination span which the values are copied into</param>
- /// <exception cref="ArgumentException">If number of elements in source vector is greater than those available in destination span</exception>
- public readonly void CopyTo(Span<T> destination)
- {
- if ((uint)destination.Length < (uint)Count)
- {
- ThrowHelper.ThrowArgumentException_DestinationTooShort();
- }
-
- Unsafe.WriteUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(destination)), this);
- }
-
- /// <summary>
- /// Copies the vector to the given destination array. The destination array must be at least size Vector'T.Count.
- /// </summary>
- /// <param name="destination">The destination array which the values are copied into</param>
- /// <exception cref="ArgumentNullException">If the destination array is null</exception>
- /// <exception cref="ArgumentException">If number of elements in source vector is greater than those available in destination array</exception>
- [Intrinsic]
- public readonly void CopyTo(T[] destination)
- {
- CopyTo(destination, 0);
- }
-
- /// <summary>
- /// Copies the vector to the given destination array. The destination array must be at least size Vector'T.Count.
- /// </summary>
- /// <param name="destination">The destination array which the values are copied into</param>
- /// <param name="startIndex">The index to start copying to</param>
- /// <exception cref="ArgumentNullException">If the destination array is null</exception>
- /// <exception cref="ArgumentOutOfRangeException">If index is greater than end of the array or index is less than zero</exception>
- /// <exception cref="ArgumentException">If number of elements in source vector is greater than those available in destination array</exception>
- [Intrinsic]
- public readonly unsafe void CopyTo(T[] destination, int startIndex)
- {
- if (destination == null)
- {
- // Match the JIT's exception type here. For perf, a NullReference is thrown instead of an ArgumentNull.
- throw new NullReferenceException(SR.Arg_NullArgumentNullRef);
- }
- if ((uint)startIndex >= (uint)destination.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.Format(SR.Arg_ArgumentOutOfRangeException, startIndex));
- }
- if ((destination.Length - startIndex) < Count)
- {
- throw new ArgumentException(SR.Format(SR.Arg_ElementsInSourceIsGreaterThanDestination, startIndex));
- }
-
- Unsafe.WriteUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref destination[startIndex]), this);
- }
-
- /// <summary>
- /// Returns the element at the given index.
- /// </summary>
- public readonly unsafe T this[int index]
- {
- [Intrinsic]
- get
- {
- if ((uint)index >= (uint)Count)
- {
- throw new IndexOutOfRangeException(SR.Format(SR.Arg_ArgumentOutOfRangeException, index));
- }
-
- return Unsafe.Add(ref Unsafe.As<Vector<T>, T>(ref Unsafe.AsRef<Vector<T>>(in this)), index);
- }
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Object is equal to this vector instance.
- /// </summary>
- /// <param name="obj">The Object to compare against.</param>
- /// <returns>True if the Object is equal to this vector; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override readonly bool Equals(object? obj)
- {
- if (!(obj is Vector<T>))
- {
- return false;
- }
- return Equals((Vector<T>)obj);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given vector is equal to this vector instance.
- /// </summary>
- /// <param name="other">The vector to compare this instance to.</param>
- /// <returns>True if the other vector is equal to this instance; False otherwise.</returns>
- [Intrinsic]
- public readonly bool Equals(Vector<T> other)
- {
- if (Vector.IsHardwareAccelerated)
- {
- for (int g = 0; g < Count; g++)
- {
- if (!ScalarEquals(this[g], other[g]))
- {
- return false;
- }
- }
- return true;
- }
- else
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- return
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
-<#
- if (g == 0)
- {
-#>
- this.<#=GetRegisterFieldName(type, g)#> == other.<#=GetRegisterFieldName(type, g)#>
-<#
- }
- else
- {
-#>
- && this.<#=GetRegisterFieldName(type, g)#> == other.<#=GetRegisterFieldName(type, g)#><#=(g == (GetNumFields(type, totalSize) -1)) ? ";" : ""#>
-<#
- }
-#>
-<#
- }
-#>
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- /// <summary>
- /// Returns the hash code for this instance.
- /// </summary>
- /// <returns>The hash code.</returns>
- public override readonly int GetHashCode()
- {
- HashCode hashCode = default;
-
- if (typeof(T) == typeof(byte) ||
- typeof(T) == typeof(sbyte) ||
- typeof(T) == typeof(ushort) ||
- typeof(T) == typeof(short) ||
- typeof(T) == typeof(int) ||
- typeof(T) == typeof(uint) ||
- typeof(T) == typeof(long) ||
- typeof(T) == typeof(ulong))
- {
- for (nint g = 0; g < Vector<int>.Count; g++)
- {
- hashCode.Add(Unsafe.Add(ref Unsafe.As<Vector<T>, int>(ref Unsafe.AsRef<Vector<T>>(in this)), (IntPtr)g));
- }
- }
- else if (typeof(T) == typeof(float))
- {
- for (nint g = 0; g < Count; g++)
- {
- hashCode.Add(Unsafe.Add(ref Unsafe.As<Vector<T>, float>(ref Unsafe.AsRef<Vector<T>>(in this)), (IntPtr)g));
- }
- }
- else if (typeof(T) == typeof(double))
- {
- for (nint g = 0; g < Count; g++)
- {
- hashCode.Add(Unsafe.Add(ref Unsafe.As<Vector<T>, double>(ref Unsafe.AsRef<Vector<T>>(in this)), (IntPtr)g));
- }
- }
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
-
- return hashCode.ToHashCode();
- }
-
- /// <summary>
- /// Returns a String representing this vector.
- /// </summary>
- /// <returns>The string representation.</returns>
- public override readonly string ToString()
- {
- return ToString("G", CultureInfo.CurrentCulture);
- }
-
- /// <summary>
- /// Returns a String representing this vector, using the specified format string to format individual elements.
- /// </summary>
- /// <param name="format">The format of individual elements.</param>
- /// <returns>The string representation.</returns>
- public readonly string ToString(string? format)
- {
- return ToString(format, CultureInfo.CurrentCulture);
- }
-
- /// <summary>
- /// Returns a String representing this vector, using the specified format string to format individual elements
- /// and the given IFormatProvider.
- /// </summary>
- /// <param name="format">The format of individual elements.</param>
- /// <param name="formatProvider">The format provider to use when formatting elements.</param>
- /// <returns>The string representation.</returns>
- public readonly string ToString(string? format, IFormatProvider? formatProvider)
- {
- StringBuilder sb = new StringBuilder();
- string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
- sb.Append('<');
- for (int g = 0; g < Count - 1; g++)
- {
- sb.Append(((IFormattable)this[g]).ToString(format, formatProvider));
- sb.Append(separator);
- sb.Append(' ');
- }
- // Append last element w/out separator
- sb.Append(((IFormattable)this[Count - 1]).ToString(format, formatProvider));
- sb.Append('>');
- return sb.ToString();
- }
-
- /// <summary>
- /// Attempts to copy the vector to the given <see cref="Span{Byte}"/>. The destination span must be at least size <see cref="Vector{Byte}.Count"/>.
- /// </summary>
- /// <param name="destination">The destination span which the values are copied into</param>
- /// <returns>True if the source vector was successfully copied to <paramref name="destination"/>. False if
- /// <paramref name="destination"/> is not large enough to hold the source vector.</returns>
- public readonly bool TryCopyTo(Span<byte> destination)
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- if ((uint)destination.Length < (uint)Vector<byte>.Count)
- {
- return false;
- }
-
- Unsafe.WriteUnaligned<Vector<T>>(ref MemoryMarshal.GetReference(destination), this);
- return true;
- }
-
- /// <summary>
- /// Attempts to copy the vector to the given <see cref="Span{T}"/>. The destination span must be at least size <see cref="Vector{T}.Count"/>.
- /// </summary>
- /// <param name="destination">The destination span which the values are copied into</param>
- /// <returns>True if the source vector was successfully copied to <paramref name="destination"/>. False if
- /// <paramref name="destination"/> is not large enough to hold the source vector.</returns>
- public readonly bool TryCopyTo(Span<T> destination)
- {
- if ((uint)destination.Length < (uint)Count)
- {
- return false;
- }
-
- Unsafe.WriteUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(destination)), this);
- return true;
- }
- #endregion Public Instance Methods
-
- #region Arithmetic Operators
- /// <summary>
- /// Adds two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The summed vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator +(Vector<T> left, Vector<T> right)
- {
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#>* dataPtr = stackalloc <#=typeAliases[type]#>[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (<#=typeAliases[type]#>)(object)ScalarAdd(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> sum = default;
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- sum.<#= GetRegisterFieldName(type, g) #> = (<#=typeAliases[type]#>)(left.<#= GetRegisterFieldName(type, g) #> + right.<#= GetRegisterFieldName(type, g) #>);
-<#
- }
-#>
- }
-<#
- }
-#>
- return sum;
- }
- }
- }
-
- /// <summary>
- /// Subtracts the second vector from the first.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The difference vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator -(Vector<T> left, Vector<T> right)
- {
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#>* dataPtr = stackalloc <#=typeAliases[type]#>[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (<#=typeAliases[type]#>)(object)ScalarSubtract(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> difference = default;
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- difference.<#= GetRegisterFieldName(type, g) #> = (<#=typeAliases[type]#>)(left.<#= GetRegisterFieldName(type, g) #> - right.<#= GetRegisterFieldName(type, g) #>);
-<#
- }
-#>
- }
-<#
- }
-#>
- return difference;
- }
- }
- }
-
- // This method is intrinsic only for certain types. It cannot access fields directly unless we are sure the context is unaccelerated.
- /// <summary>
- /// Multiplies two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The product vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator *(Vector<T> left, Vector<T> right)
- {
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#>* dataPtr = stackalloc <#=typeAliases[type]#>[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (<#=typeAliases[type]#>)(object)ScalarMultiply(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> product = default;
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- product.<#= GetRegisterFieldName(type, g) #> = (<#=typeAliases[type]#>)(left.<#= GetRegisterFieldName(type, g) #> * right.<#= GetRegisterFieldName(type, g) #>);
-<#
- }
-#>
- }
-<#
- }
-#>
- return product;
- }
- }
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <param name="factor">The scalar value.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> operator *(Vector<T> value, T factor) =>
- new Vector<T>(factor) * value;
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="factor">The scalar value.</param>
- /// <param name="value">The source vector.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> operator *(T factor, Vector<T> value) =>
- new Vector<T>(factor) * value;
-
- // This method is intrinsic only for certain types. It cannot access fields directly unless we are sure the context is unaccelerated.
- /// <summary>
- /// Divides the first vector by the second.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The vector resulting from the division.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator /(Vector<T> left, Vector<T> right)
- {
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#>* dataPtr = stackalloc <#=typeAliases[type]#>[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (<#=typeAliases[type]#>)(object)ScalarDivide(left[g], right[g]);
- }
- return new Vector<T>(dataPtr);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> quotient = default;
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- quotient.<#= GetRegisterFieldName(type, g) #> = (<#=typeAliases[type]#>)(left.<#= GetRegisterFieldName(type, g) #> / right.<#= GetRegisterFieldName(type, g) #>);
-<#
- }
-#>
- }
-<#
- }
-#>
- return quotient;
- }
- }
- }
-
- /// <summary>
- /// Negates a given vector.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The negated vector.</returns>
- public static Vector<T> operator -(Vector<T> value) => Zero - value;
- #endregion Arithmetic Operators
-
- #region Bitwise Operators
- /// <summary>
- /// Returns a new vector by performing a bitwise-and operation on each of the elements in the given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator &(Vector<T> left, Vector<T> right)
- {
- Vector<T> result = default;
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
- long* resultBase = &result.register.int64_0;
- long* leftBase = &left.register.int64_0;
- long* rightBase = &right.register.int64_0;
- for (int g = 0; g < Vector<long>.Count; g++)
- {
- resultBase[g] = leftBase[g] & rightBase[g];
- }
- }
- else
- {
- result.<#=GetRegisterFieldName(typeof(long), 0)#> = left.<#=GetRegisterFieldName(typeof(long), 0)#> & right.<#=GetRegisterFieldName(typeof(long), 0)#>;
- result.<#=GetRegisterFieldName(typeof(long), 1)#> = left.<#=GetRegisterFieldName(typeof(long), 1)#> & right.<#=GetRegisterFieldName(typeof(long), 1)#>;
- }
- }
- return result;
- }
-
- /// <summary>
- /// Returns a new vector by performing a bitwise-or operation on each of the elements in the given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator |(Vector<T> left, Vector<T> right)
- {
- Vector<T> result = default;
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
- long* resultBase = &result.register.int64_0;
- long* leftBase = &left.register.int64_0;
- long* rightBase = &right.register.int64_0;
- for (int g = 0; g < Vector<long>.Count; g++)
- {
- resultBase[g] = leftBase[g] | rightBase[g];
- }
- }
- else
- {
- result.<#=GetRegisterFieldName(typeof(long), 0)#> = left.<#=GetRegisterFieldName(typeof(long), 0)#> | right.<#=GetRegisterFieldName(typeof(long), 0)#>;
- result.<#=GetRegisterFieldName(typeof(long), 1)#> = left.<#=GetRegisterFieldName(typeof(long), 1)#> | right.<#=GetRegisterFieldName(typeof(long), 1)#>;
- }
- }
- return result;
- }
-
- /// <summary>
- /// Returns a new vector by performing a bitwise-exclusive-or operation on each of the elements in the given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- public static unsafe Vector<T> operator ^(Vector<T> left, Vector<T> right)
- {
- Vector<T> result = default;
- unchecked
- {
- if (Vector.IsHardwareAccelerated)
- {
- long* resultBase = &result.register.int64_0;
- long* leftBase = &left.register.int64_0;
- long* rightBase = &right.register.int64_0;
- for (int g = 0; g < Vector<long>.Count; g++)
- {
- resultBase[g] = leftBase[g] ^ rightBase[g];
- }
- }
- else
- {
- result.<#=GetRegisterFieldName(typeof(long), 0)#> = left.<#=GetRegisterFieldName(typeof(long), 0)#> ^ right.<#=GetRegisterFieldName(typeof(long), 0)#>;
- result.<#=GetRegisterFieldName(typeof(long), 1)#> = left.<#=GetRegisterFieldName(typeof(long), 1)#> ^ right.<#=GetRegisterFieldName(typeof(long), 1)#>;
- }
- }
- return result;
- }
-
- /// <summary>
- /// Returns a new vector whose elements are obtained by taking the one's complement of the given vector's elements.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The one's complement vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> operator ~(Vector<T> value) =>
- s_allOnes ^ value;
- #endregion Bitwise Operators
-
- #region Logical Operators
- /// <summary>
- /// Returns a boolean indicating whether each pair of elements in the given vectors are equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The first vector to compare.</param>
- /// <returns>True if all elements are equal; False otherwise.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Vector<T> left, Vector<T> right) =>
- left.Equals(right);
-
- /// <summary>
- /// Returns a boolean indicating whether any single pair of elements in the given vectors are not equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if left and right are not equal; False otherwise.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(Vector<T> left, Vector<T> right) => !(left == right);
- #endregion Logical Operators
-
- #region Conversions
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- /// <summary>
- /// Reinterprets the bits of the given vector into those of another type.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
-<#
- if (nonClsCompliantTypes.Contains(type))
- {
-#>
- [CLSCompliant(false)]
-<#
- }
-#>
- [Intrinsic]
- public static explicit operator Vector<<#=typeAliases[type]#>>(Vector<T> value) =>
- new Vector<<#=typeAliases[type]#>>(ref value.register);
-
-<#
- }
-#>
- #endregion Conversions
-
- #region Internal Comparison Methods
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe Vector<T> Equals(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#>* dataPtr = stackalloc <#=typeAliases[type]#>[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarEquals(left[g], right[g]) ? ConstantHelper.Get<#=type.Name#>WithAllBitsSet() : (<#=typeAliases[type]#>)0;
- }
- return new Vector<T>(dataPtr);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Register register = default;
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- <#= GetRegisterFieldName(type, g) #> = left.<#= GetRegisterFieldName(type, g) #> == right.<#= GetRegisterFieldName(type, g) #> ? ConstantHelper.Get<#=type.Name#>WithAllBitsSet() : (<#=typeAliases[type]#>)0;
-<#
- }
-#>
- return new Vector<T>(ref register);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe Vector<T> LessThan(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#>* dataPtr = stackalloc <#=typeAliases[type]#>[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? ConstantHelper.Get<#=type.Name#>WithAllBitsSet() : (<#=typeAliases[type]#>)0;
- }
- return new Vector<T>(dataPtr);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Register register = default;
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- <#= GetRegisterFieldName(type, g) #> = left.<#= GetRegisterFieldName(type, g) #> < right.<#= GetRegisterFieldName(type, g) #> ? ConstantHelper.Get<#=type.Name#>WithAllBitsSet() : (<#=typeAliases[type]#>)0;
-<#
- }
-#>
- return new Vector<T>(ref register);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe Vector<T> GreaterThan(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#>* dataPtr = stackalloc <#=typeAliases[type]#>[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? ConstantHelper.Get<#=type.Name#>WithAllBitsSet() : (<#=typeAliases[type]#>)0;
- }
- return new Vector<T>(dataPtr);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Register register = default;
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- <#= GetRegisterFieldName(type, g) #> = left.<#= GetRegisterFieldName(type, g) #> > right.<#= GetRegisterFieldName(type, g) #> ? ConstantHelper.Get<#=type.Name#>WithAllBitsSet() : (<#=typeAliases[type]#>)0;
-<#
- }
-#>
- return new Vector<T>(ref register);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- internal static Vector<T> GreaterThanOrEqual(Vector<T> left, Vector<T> right)
- {
- return Equals(left, right) | GreaterThan(left, right);
- }
-
- [Intrinsic]
- internal static Vector<T> LessThanOrEqual(Vector<T> left, Vector<T> right)
- {
- return Equals(left, right) | LessThan(left, right);
- }
-
- [Intrinsic]
- internal static Vector<T> ConditionalSelect(Vector<T> condition, Vector<T> left, Vector<T> right)
- {
- return (left & condition) | (Vector.AndNot(right, condition));
- }
- #endregion Comparison Methods
-
- #region Internal Math Methods
- [Intrinsic]
- internal static unsafe Vector<T> Abs(Vector<T> value)
- {
-<#
- foreach (Type type in supportedTypes)
- {
- if (unsignedTypes.Contains(type))
- {
-#>
- <#=GenerateIfStatementHeader(type, unsignedTypes)#>
- {
- return value;
- }
-<#
- }
- }
-#>
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes.Except(unsignedTypes))
- {
-#>
- <#=GenerateIfStatementHeader(type, supportedTypes.Except(unsignedTypes))#>
- {
- <#=typeAliases[type]#>* dataPtr = stackalloc <#=typeAliases[type]#>[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = (<#=typeAliases[type]#>)(object)(Math.Abs((<#=typeAliases[type]#>)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
-<#
- foreach (Type type in supportedTypes.Except(unsignedTypes))
- {
-#>
- <#=GenerateIfStatementHeader(type, supportedTypes.Except(unsignedTypes))#>
- {
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- value.<#=GetRegisterFieldName(type, g)#> = (<#=typeAliases[type]#>)(Math.Abs(value.<#=GetRegisterFieldName(type, g)#>));
-<#
- }
-#>
- return value;
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- internal static unsafe Vector<T> Min(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#>* dataPtr = stackalloc <#=typeAliases[type]#>[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarLessThan(left[g], right[g]) ? (<#=typeAliases[type]#>)(object)left[g] : (<#=typeAliases[type]#>)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> vec = default;
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- vec.<#=GetRegisterFieldName(type, g)#> = left.<#=GetRegisterFieldName(type, g)#> < right.<#=GetRegisterFieldName(type, g)#> ? left.<#=GetRegisterFieldName(type, g)#> : right.<#=GetRegisterFieldName(type, g)#>;
-<#
- }
-#>
- return vec;
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- internal static unsafe Vector<T> Max(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#>* dataPtr = stackalloc <#=typeAliases[type]#>[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = ScalarGreaterThan(left[g], right[g]) ? (<#=typeAliases[type]#>)(object)left[g] : (<#=typeAliases[type]#>)(object)right[g];
- }
- return new Vector<T>(dataPtr);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
- Vector<T> vec = default;
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- vec.<#=GetRegisterFieldName(type, g)#> = left.<#=GetRegisterFieldName(type, g)#> > right.<#=GetRegisterFieldName(type, g)#> ? left.<#=GetRegisterFieldName(type, g)#> : right.<#=GetRegisterFieldName(type, g)#>;
-<#
- }
-#>
- return vec;
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- internal static T Dot(Vector<T> left, Vector<T> right)
- {
- if (Vector.IsHardwareAccelerated)
- {
- T product = default;
- for (int g = 0; g < Count; g++)
- {
- product = ScalarAdd(product, ScalarMultiply(left[g], right[g]));
- }
- return product;
- }
- else
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#> product = 0;
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- product += (<#=typeAliases[type]#>)(left.<#=GetRegisterFieldName(type, g)#> * right.<#=GetRegisterFieldName(type, g)#>);
-<#
- }
-#>
- return (T)(object)product;
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
-
- [Intrinsic]
- internal static unsafe Vector<T> SquareRoot(Vector<T> value)
- {
- if (Vector.IsHardwareAccelerated)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#>* dataPtr = stackalloc <#=typeAliases[type]#>[Count];
- for (int g = 0; g < Count; g++)
- {
- dataPtr[g] = unchecked((<#=typeAliases[type]#>)Math.Sqrt((<#=typeAliases[type]#>)(object)value[g]));
- }
- return new Vector<T>(dataPtr);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- else
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
-<#
- for (int g = 0; g < GetNumFields(type, totalSize); g++)
- {
-#>
- value.<#=GetRegisterFieldName(type, g)#> = (<#=typeAliases[type]#>)Math.Sqrt(value.<#=GetRegisterFieldName(type, g)#>);
-<#
- }
-#>
- return value;
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- }
- #endregion Internal Math Methods
-
- #region Helper Methods
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool ScalarEquals(T left, T right)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- return (<#=typeAliases[type]#>)(object)left == (<#=typeAliases[type]#>)(object)right;
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool ScalarLessThan(T left, T right)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- return (<#=typeAliases[type]#>)(object)left < (<#=typeAliases[type]#>)(object)right;
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool ScalarGreaterThan(T left, T right)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- return (<#=typeAliases[type]#>)(object)left > (<#=typeAliases[type]#>)(object)right;
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T ScalarAdd(T left, T right)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- return (T)(object)unchecked((<#=typeAliases[type]#>)((<#=typeAliases[type]#>)(object)left + (<#=typeAliases[type]#>)(object)right));
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T ScalarSubtract(T left, T right)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- return (T)(object)(<#=typeAliases[type]#>)((<#=typeAliases[type]#>)(object)left - (<#=typeAliases[type]#>)(object)right);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T ScalarMultiply(T left, T right)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- return (T)(object)unchecked((<#=typeAliases[type]#>)((<#=typeAliases[type]#>)(object)left * (<#=typeAliases[type]#>)(object)right));
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T ScalarDivide(T left, T right)
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- return (T)(object)(<#=typeAliases[type]#>)((<#=typeAliases[type]#>)(object)left / (<#=typeAliases[type]#>)(object)right);
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T GetOneValue()
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- <#=typeAliases[type]#> value = 1;
- return (T)(object)value;
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static T GetAllBitsSetValue()
- {
-<#
- foreach (Type type in supportedTypes)
- {
-#>
- <#=GenerateIfStatementHeader(type)#>
- {
- return (T)(object)ConstantHelper.Get<#=type.Name#>WithAllBitsSet();
- }
-<#
- }
-#>
- else
- {
- throw new NotSupportedException(SR.Arg_TypeNotSupported);
- }
- }
- #endregion
- }
-
- [Intrinsic]
- public static partial class Vector
- {
- #region Widen/Narrow
-<#
- foreach (Type type in WidenableTypes)
- {
- Type widenTarget = GetWidenTarget(type);
-#>
- /// <summary>
- /// Widens a Vector{<#=type.Name#>} into two Vector{<#=widenTarget.Name#>}'s.
- /// <param name="source">The source vector whose elements are widened into the outputs.</param>
- /// <param name="low">The first output vector, whose elements will contain the widened elements from lower indices in the source vector.</param>
- /// <param name="high">The second output vector, whose elements will contain the widened elements from higher indices in the source vector.</param>
- /// </summary>
-<#
- if (nonClsCompliantTypes.Contains(type) || nonClsCompliantTypes.Contains(widenTarget))
- {
-#>
- [CLSCompliant(false)]
-<#
- }
-#>
- [Intrinsic]
- public static unsafe void Widen(Vector<<#=typeAliases[type]#>> source, out Vector<<#=typeAliases[widenTarget]#>> low, out Vector<<#=typeAliases[widenTarget]#>> high)
- {
- int elements = Vector<<#=typeAliases[type]#>>.Count;
- <#=typeAliases[widenTarget]#>* lowPtr = stackalloc <#=typeAliases[widenTarget]#>[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- lowPtr[i] = (<#=typeAliases[widenTarget]#>)source[i];
- }
- <#=typeAliases[widenTarget]#>* highPtr = stackalloc <#=typeAliases[widenTarget]#>[elements / 2];
- for (int i = 0; i < elements / 2; i++)
- {
- highPtr[i] = (<#=typeAliases[widenTarget]#>)source[i + (elements / 2)];
- }
-
- low = new Vector<<#=typeAliases[widenTarget]#>>(lowPtr);
- high = new Vector<<#=typeAliases[widenTarget]#>>(highPtr);
- }
-
-<#
- }
-
- foreach (Type narrowSource in NarrowableTypes)
- {
- Type narrowTarget = GetNarrowTarget(narrowSource);
-#>
- /// <summary>
- /// Narrows two Vector{<#=narrowSource.Name#>}'s into one Vector{<#=narrowTarget.Name#>}.
- /// <param name="low">The first source vector, whose elements become the lower-index elements of the return value.</param>
- /// <param name="high">The second source vector, whose elements become the higher-index elements of the return value.</param>
- /// <returns>A Vector{<#=narrowTarget.Name#>} containing elements narrowed from the source vectors.</returns>
- /// </summary>
-<#
- if (nonClsCompliantTypes.Contains(narrowSource) || nonClsCompliantTypes.Contains(narrowTarget))
- {
-#>
- [CLSCompliant(false)]
-<#
- }
-#>
- [Intrinsic]
- public static unsafe Vector<<#=typeAliases[narrowTarget]#>> Narrow(Vector<<#=typeAliases[narrowSource]#>> low, Vector<<#=typeAliases[narrowSource]#>> high)
- {
- unchecked
- {
- int elements = Vector<<#=typeAliases[narrowTarget]#>>.Count;
- <#=typeAliases[narrowTarget]#>* retPtr = stackalloc <#=typeAliases[narrowTarget]#>[elements];
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i] = (<#=typeAliases[narrowTarget]#>)low[i];
- }
- for (int i = 0; i < elements / 2; i++)
- {
- retPtr[i + (elements / 2)] = (<#=typeAliases[narrowTarget]#>)high[i];
- }
-
- return new Vector<<#=typeAliases[narrowTarget]#>>(retPtr);
- }
- }
-
-<#
- }
-#>
- #endregion Widen/Narrow
-
- #region Same-Size Conversion
-<#
- foreach (var pair in SameSizeConversionPairs)
- {
-#>
- /// <summary>
- /// Converts a Vector{<#=pair.Key.Name#>} to a Vector{<#=pair.Value.Name#>}.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The converted vector.</returns>
-<#
- if (nonClsCompliantTypes.Contains(pair.Key) || nonClsCompliantTypes.Contains(pair.Value))
- {
-#>
- [CLSCompliant(false)]
-<#
- }
-#>
- [Intrinsic]
- public static unsafe Vector<<#=typeAliases[pair.Value]#>> ConvertTo<#=pair.Value.Name#>(Vector<<#=typeAliases[pair.Key]#>> value)
- {
- unchecked
- {
- int elements = Vector<<#=typeAliases[pair.Value]#>>.Count;
- <#=typeAliases[pair.Value]#>* retPtr = stackalloc <#=typeAliases[pair.Value]#>[elements];
- for (int i = 0; i < elements; i++)
- {
- retPtr[i] = (<#=typeAliases[pair.Value]#>)value[i];
- }
-
- return new Vector<<#=typeAliases[pair.Value]#>>(retPtr);
- }
- }
-
-<#
- }
-#>
- #endregion Same-Size Conversion
-
- #region Throw Helpers
- [DoesNotReturn]
- internal static void ThrowInsufficientNumberOfElementsException(int requiredElementCount)
- {
- throw new IndexOutOfRangeException(SR.Format(SR.Arg_InsufficientNumberOfElements, requiredElementCount, "values"));
- }
- #endregion
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector2.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Vector2.cs
deleted file mode 100644
index 5e710842c52..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector2.cs
+++ /dev/null
@@ -1,465 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System.Numerics
-{
- /// <summary>
- /// A structure encapsulating two single precision floating point values and provides hardware accelerated methods.
- /// </summary>
- [Intrinsic]
- public partial struct Vector2 : IEquatable<Vector2>, IFormattable
- {
- #region Public Static Properties
- /// <summary>
- /// Returns the vector (0,0).
- /// </summary>
- public static Vector2 Zero
- {
- [Intrinsic]
- get
- {
- return default;
- }
- }
- /// <summary>
- /// Returns the vector (1,1).
- /// </summary>
- public static Vector2 One
- {
- [Intrinsic]
- get
- {
- return new Vector2(1.0f, 1.0f);
- }
- }
- /// <summary>
- /// Returns the vector (1,0).
- /// </summary>
- public static Vector2 UnitX { get { return new Vector2(1.0f, 0.0f); } }
- /// <summary>
- /// Returns the vector (0,1).
- /// </summary>
- public static Vector2 UnitY { get { return new Vector2(0.0f, 1.0f); } }
- #endregion Public Static Properties
-
- #region Public instance methods
- /// <summary>
- /// Returns the hash code for this instance.
- /// </summary>
- /// <returns>The hash code.</returns>
- public override readonly int GetHashCode()
- {
- return HashCode.Combine(this.X.GetHashCode(), this.Y.GetHashCode());
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Object is equal to this Vector2 instance.
- /// </summary>
- /// <param name="obj">The Object to compare against.</param>
- /// <returns>True if the Object is equal to this Vector2; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override readonly bool Equals(object? obj)
- {
- if (!(obj is Vector2))
- return false;
- return Equals((Vector2)obj);
- }
-
- /// <summary>
- /// Returns a String representing this Vector2 instance.
- /// </summary>
- /// <returns>The string representation.</returns>
- public override readonly string ToString()
- {
- return ToString("G", CultureInfo.CurrentCulture);
- }
-
- /// <summary>
- /// Returns a String representing this Vector2 instance, using the specified format to format individual elements.
- /// </summary>
- /// <param name="format">The format of individual elements.</param>
- /// <returns>The string representation.</returns>
- public readonly string ToString(string? format)
- {
- return ToString(format, CultureInfo.CurrentCulture);
- }
-
- /// <summary>
- /// Returns a String representing this Vector2 instance, using the specified format to format individual elements
- /// and the given IFormatProvider.
- /// </summary>
- /// <param name="format">The format of individual elements.</param>
- /// <param name="formatProvider">The format provider to use when formatting elements.</param>
- /// <returns>The string representation.</returns>
- public readonly string ToString(string? format, IFormatProvider? formatProvider)
- {
- StringBuilder sb = new StringBuilder();
- string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
- sb.Append('<');
- sb.Append(this.X.ToString(format, formatProvider));
- sb.Append(separator);
- sb.Append(' ');
- sb.Append(this.Y.ToString(format, formatProvider));
- sb.Append('>');
- return sb.ToString();
- }
-
- /// <summary>
- /// Returns the length of the vector.
- /// </summary>
- /// <returns>The vector's length.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly float Length()
- {
- if (Vector.IsHardwareAccelerated)
- {
- float ls = Vector2.Dot(this, this);
- return MathF.Sqrt(ls);
- }
- else
- {
- float ls = X * X + Y * Y;
- return MathF.Sqrt(ls);
- }
- }
-
- /// <summary>
- /// Returns the length of the vector squared. This operation is cheaper than Length().
- /// </summary>
- /// <returns>The vector's length squared.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly float LengthSquared()
- {
- if (Vector.IsHardwareAccelerated)
- {
- return Vector2.Dot(this, this);
- }
- else
- {
- return X * X + Y * Y;
- }
- }
- #endregion Public Instance Methods
-
- #region Public Static Methods
- /// <summary>
- /// Returns the Euclidean distance between the two given points.
- /// </summary>
- /// <param name="value1">The first point.</param>
- /// <param name="value2">The second point.</param>
- /// <returns>The distance.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Distance(Vector2 value1, Vector2 value2)
- {
- if (Vector.IsHardwareAccelerated)
- {
- Vector2 difference = value1 - value2;
- float ls = Vector2.Dot(difference, difference);
- return MathF.Sqrt(ls);
- }
- else
- {
- float dx = value1.X - value2.X;
- float dy = value1.Y - value2.Y;
-
- float ls = dx * dx + dy * dy;
-
- return MathF.Sqrt(ls);
- }
- }
-
- /// <summary>
- /// Returns the Euclidean distance squared between the two given points.
- /// </summary>
- /// <param name="value1">The first point.</param>
- /// <param name="value2">The second point.</param>
- /// <returns>The distance squared.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float DistanceSquared(Vector2 value1, Vector2 value2)
- {
- if (Vector.IsHardwareAccelerated)
- {
- Vector2 difference = value1 - value2;
- return Vector2.Dot(difference, difference);
- }
- else
- {
- float dx = value1.X - value2.X;
- float dy = value1.Y - value2.Y;
-
- return dx * dx + dy * dy;
- }
- }
-
- /// <summary>
- /// Returns a vector with the same direction as the given vector, but with a length of 1.
- /// </summary>
- /// <param name="value">The vector to normalize.</param>
- /// <returns>The normalized vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Normalize(Vector2 value)
- {
- if (Vector.IsHardwareAccelerated)
- {
- float length = value.Length();
- return value / length;
- }
- else
- {
- float ls = value.X * value.X + value.Y * value.Y;
- float invNorm = 1.0f / MathF.Sqrt(ls);
-
- return new Vector2(
- value.X * invNorm,
- value.Y * invNorm);
- }
- }
-
- /// <summary>
- /// Returns the reflection of a vector off a surface that has the specified normal.
- /// </summary>
- /// <param name="vector">The source vector.</param>
- /// <param name="normal">The normal of the surface being reflected off.</param>
- /// <returns>The reflected vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Reflect(Vector2 vector, Vector2 normal)
- {
- if (Vector.IsHardwareAccelerated)
- {
- float dot = Vector2.Dot(vector, normal);
- return vector - (2 * dot * normal);
- }
- else
- {
- float dot = vector.X * normal.X + vector.Y * normal.Y;
-
- return new Vector2(
- vector.X - 2.0f * dot * normal.X,
- vector.Y - 2.0f * dot * normal.Y);
- }
- }
-
- /// <summary>
- /// Restricts a vector between a min and max value.
- /// </summary>
- /// <param name="value1">The source vector.</param>
- /// <param name="min">The minimum value.</param>
- /// <param name="max">The maximum value.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max)
- {
- // This compare order is very important!!!
- // We must follow HLSL behavior in the case user specified min value is bigger than max value.
- float x = value1.X;
- x = (min.X > x) ? min.X : x; // max(x, minx)
- x = (max.X < x) ? max.X : x; // min(x, maxx)
-
- float y = value1.Y;
- y = (min.Y > y) ? min.Y : y; // max(y, miny)
- y = (max.Y < y) ? max.Y : y; // min(y, maxy)
-
- return new Vector2(x, y);
- }
-
- /// <summary>
- /// Linearly interpolates between two vectors based on the given weighting.
- /// </summary>
- /// <param name="value1">The first source vector.</param>
- /// <param name="value2">The second source vector.</param>
- /// <param name="amount">Value between 0 and 1 indicating the weight of the second source vector.</param>
- /// <returns>The interpolated vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
- {
- return new Vector2(
- value1.X + (value2.X - value1.X) * amount,
- value1.Y + (value2.Y - value1.Y) * amount);
- }
-
- /// <summary>
- /// Transforms a vector by the given matrix.
- /// </summary>
- /// <param name="position">The source vector.</param>
- /// <param name="matrix">The transformation matrix.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Transform(Vector2 position, Matrix3x2 matrix)
- {
- return new Vector2(
- position.X * matrix.M11 + position.Y * matrix.M21 + matrix.M31,
- position.X * matrix.M12 + position.Y * matrix.M22 + matrix.M32);
- }
-
- /// <summary>
- /// Transforms a vector by the given matrix.
- /// </summary>
- /// <param name="position">The source vector.</param>
- /// <param name="matrix">The transformation matrix.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Transform(Vector2 position, Matrix4x4 matrix)
- {
- return new Vector2(
- position.X * matrix.M11 + position.Y * matrix.M21 + matrix.M41,
- position.X * matrix.M12 + position.Y * matrix.M22 + matrix.M42);
- }
-
- /// <summary>
- /// Transforms a vector normal by the given matrix.
- /// </summary>
- /// <param name="normal">The source vector.</param>
- /// <param name="matrix">The transformation matrix.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 TransformNormal(Vector2 normal, Matrix3x2 matrix)
- {
- return new Vector2(
- normal.X * matrix.M11 + normal.Y * matrix.M21,
- normal.X * matrix.M12 + normal.Y * matrix.M22);
- }
-
- /// <summary>
- /// Transforms a vector normal by the given matrix.
- /// </summary>
- /// <param name="normal">The source vector.</param>
- /// <param name="matrix">The transformation matrix.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 TransformNormal(Vector2 normal, Matrix4x4 matrix)
- {
- return new Vector2(
- normal.X * matrix.M11 + normal.Y * matrix.M21,
- normal.X * matrix.M12 + normal.Y * matrix.M22);
- }
-
- /// <summary>
- /// Transforms a vector by the given Quaternion rotation value.
- /// </summary>
- /// <param name="value">The source vector to be rotated.</param>
- /// <param name="rotation">The rotation to apply.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Transform(Vector2 value, Quaternion rotation)
- {
- float x2 = rotation.X + rotation.X;
- float y2 = rotation.Y + rotation.Y;
- float z2 = rotation.Z + rotation.Z;
-
- float wz2 = rotation.W * z2;
- float xx2 = rotation.X * x2;
- float xy2 = rotation.X * y2;
- float yy2 = rotation.Y * y2;
- float zz2 = rotation.Z * z2;
-
- return new Vector2(
- value.X * (1.0f - yy2 - zz2) + value.Y * (xy2 - wz2),
- value.X * (xy2 + wz2) + value.Y * (1.0f - xx2 - zz2));
- }
- #endregion Public Static Methods
-
- #region Public operator methods
- // all the below methods should be inlined as they are
- // implemented over JIT intrinsics
-
- /// <summary>
- /// Adds two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The summed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Add(Vector2 left, Vector2 right)
- {
- return left + right;
- }
-
- /// <summary>
- /// Subtracts the second vector from the first.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The difference vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Subtract(Vector2 left, Vector2 right)
- {
- return left - right;
- }
-
- /// <summary>
- /// Multiplies two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The product vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Multiply(Vector2 left, Vector2 right)
- {
- return left * right;
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The source vector.</param>
- /// <param name="right">The scalar value.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Multiply(Vector2 left, float right)
- {
- return left * right;
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The scalar value.</param>
- /// <param name="right">The source vector.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Multiply(float left, Vector2 right)
- {
- return left * right;
- }
-
- /// <summary>
- /// Divides the first vector by the second.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The vector resulting from the division.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Divide(Vector2 left, Vector2 right)
- {
- return left / right;
- }
-
- /// <summary>
- /// Divides the vector by the given scalar.
- /// </summary>
- /// <param name="left">The source vector.</param>
- /// <param name="divisor">The scalar value.</param>
- /// <returns>The result of the division.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Divide(Vector2 left, float divisor)
- {
- return left / divisor;
- }
-
- /// <summary>
- /// Negates a given vector.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The negated vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Negate(Vector2 value)
- {
- return -value;
- }
- #endregion Public operator methods
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector2_Intrinsics.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Vector2_Intrinsics.cs
deleted file mode 100644
index b2d58347904..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector2_Intrinsics.cs
+++ /dev/null
@@ -1,297 +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 System.Runtime.CompilerServices;
-
-namespace System.Numerics
-{
- // This file contains the definitions for all of the JIT intrinsic methods and properties that are recognized by the current x64 JIT compiler.
- // The implementation defined here is used in any circumstance where the JIT fails to recognize these members as intrinsic.
- // The JIT recognizes these methods and properties by name and signature: if either is changed, the JIT will no longer recognize the member.
- // Some methods declared here are not strictly intrinsic, but delegate to an intrinsic method. For example, only one overload of CopyTo()
-
- public partial struct Vector2
- {
- /// <summary>
- /// The X component of the vector.
- /// </summary>
- public float X;
- /// <summary>
- /// The Y component of the vector.
- /// </summary>
- public float Y;
-
- #region Constructors
- /// <summary>
- /// Constructs a vector whose elements are all the single specified value.
- /// </summary>
- /// <param name="value">The element to fill the vector with.</param>
- [Intrinsic]
- public Vector2(float value) : this(value, value) { }
-
- /// <summary>
- /// Constructs a vector with the given individual elements.
- /// </summary>
- /// <param name="x">The X component.</param>
- /// <param name="y">The Y component.</param>
- [Intrinsic]
- public Vector2(float x, float y)
- {
- X = x;
- Y = y;
- }
- #endregion Constructors
-
- #region Public Instance Methods
- /// <summary>
- /// Copies the contents of the vector into the given array.
- /// </summary>
- /// <param name="array">The destination array.</param>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly void CopyTo(float[] array)
- {
- CopyTo(array, 0);
- }
-
- /// <summary>
- /// Copies the contents of the vector into the given array, starting from the given index.
- /// </summary>
- /// <exception cref="ArgumentNullException">If array is null.</exception>
- /// <exception cref="RankException">If array is multidimensional.</exception>
- /// <exception cref="ArgumentOutOfRangeException">If index is greater than end of the array or index is less than zero.</exception>
- /// <exception cref="ArgumentException">If number of elements in source vector is greater than those available in destination array
- /// or if there are not enough elements to copy.</exception>
- [Intrinsic]
- public readonly void CopyTo(float[] array, int index)
- {
- if (array == null)
- {
- // Match the JIT's exception type here. For perf, a NullReference is thrown instead of an ArgumentNull.
- throw new NullReferenceException(SR.Arg_NullArgumentNullRef);
- }
- if (index < 0 || index >= array.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.Format(SR.Arg_ArgumentOutOfRangeException, index));
- }
- if ((array.Length - index) < 2)
- {
- throw new ArgumentException(SR.Format(SR.Arg_ElementsInSourceIsGreaterThanDestination, index));
- }
- array[index] = X;
- array[index + 1] = Y;
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Vector2 is equal to this Vector2 instance.
- /// </summary>
- /// <param name="other">The Vector2 to compare this instance to.</param>
- /// <returns>True if the other Vector2 is equal to this instance; False otherwise.</returns>
- [Intrinsic]
- public readonly bool Equals(Vector2 other)
- {
- return this.X == other.X && this.Y == other.Y;
- }
- #endregion Public Instance Methods
-
- #region Public Static Methods
- /// <summary>
- /// Returns the dot product of two vectors.
- /// </summary>
- /// <param name="value1">The first vector.</param>
- /// <param name="value2">The second vector.</param>
- /// <returns>The dot product.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Dot(Vector2 value1, Vector2 value2)
- {
- return value1.X * value2.X +
- value1.Y * value2.Y;
- }
-
- /// <summary>
- /// Returns a vector whose elements are the minimum of each of the pairs of elements in the two source vectors.
- /// </summary>
- /// <param name="value1">The first source vector.</param>
- /// <param name="value2">The second source vector.</param>
- /// <returns>The minimized vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Min(Vector2 value1, Vector2 value2)
- {
- return new Vector2(
- (value1.X < value2.X) ? value1.X : value2.X,
- (value1.Y < value2.Y) ? value1.Y : value2.Y);
- }
-
- /// <summary>
- /// Returns a vector whose elements are the maximum of each of the pairs of elements in the two source vectors
- /// </summary>
- /// <param name="value1">The first source vector</param>
- /// <param name="value2">The second source vector</param>
- /// <returns>The maximized vector</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Max(Vector2 value1, Vector2 value2)
- {
- return new Vector2(
- (value1.X > value2.X) ? value1.X : value2.X,
- (value1.Y > value2.Y) ? value1.Y : value2.Y);
- }
-
- /// <summary>
- /// Returns a vector whose elements are the absolute values of each of the source vector's elements.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The absolute value vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 Abs(Vector2 value)
- {
- return new Vector2(MathF.Abs(value.X), MathF.Abs(value.Y));
- }
-
- /// <summary>
- /// Returns a vector whose elements are the square root of each of the source vector's elements.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The square root vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 SquareRoot(Vector2 value)
- {
- return new Vector2(MathF.Sqrt(value.X), MathF.Sqrt(value.Y));
- }
- #endregion Public Static Methods
-
- #region Public Static Operators
- /// <summary>
- /// Adds two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The summed vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 operator +(Vector2 left, Vector2 right)
- {
- return new Vector2(left.X + right.X, left.Y + right.Y);
- }
-
- /// <summary>
- /// Subtracts the second vector from the first.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The difference vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 operator -(Vector2 left, Vector2 right)
- {
- return new Vector2(left.X - right.X, left.Y - right.Y);
- }
-
- /// <summary>
- /// Multiplies two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The product vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 operator *(Vector2 left, Vector2 right)
- {
- return new Vector2(left.X * right.X, left.Y * right.Y);
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The scalar value.</param>
- /// <param name="right">The source vector.</param>
- /// <returns>The scaled vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 operator *(float left, Vector2 right)
- {
- return new Vector2(left, left) * right;
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The source vector.</param>
- /// <param name="right">The scalar value.</param>
- /// <returns>The scaled vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 operator *(Vector2 left, float right)
- {
- return left * new Vector2(right, right);
- }
-
- /// <summary>
- /// Divides the first vector by the second.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The vector resulting from the division.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 operator /(Vector2 left, Vector2 right)
- {
- return new Vector2(left.X / right.X, left.Y / right.Y);
- }
-
- /// <summary>
- /// Divides the vector by the given scalar.
- /// </summary>
- /// <param name="value1">The source vector.</param>
- /// <param name="value2">The scalar value.</param>
- /// <returns>The result of the division.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 operator /(Vector2 value1, float value2)
- {
- return value1 / new Vector2(value2);
- }
-
- /// <summary>
- /// Negates a given vector.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The negated vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector2 operator -(Vector2 value)
- {
- return Zero - value;
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the two given vectors are equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if the vectors are equal; False otherwise.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Vector2 left, Vector2 right)
- {
- return left.Equals(right);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the two given vectors are not equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if the vectors are not equal; False if they are equal.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(Vector2 left, Vector2 right)
- {
- return !(left == right);
- }
- #endregion Public Static Operators
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector3.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Vector3.cs
deleted file mode 100644
index d69c196a9dd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector3.cs
+++ /dev/null
@@ -1,483 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System.Numerics
-{
- /// <summary>
- /// A structure encapsulating three single precision floating point values and provides hardware accelerated methods.
- /// </summary>
- [Intrinsic]
- public partial struct Vector3 : IEquatable<Vector3>, IFormattable
- {
- #region Public Static Properties
- /// <summary>
- /// Returns the vector (0,0,0).
- /// </summary>
- public static Vector3 Zero
- {
- [Intrinsic]
- get
- {
- return default;
- }
- }
- /// <summary>
- /// Returns the vector (1,1,1).
- /// </summary>
- public static Vector3 One
- {
- [Intrinsic]
- get
- {
- return new Vector3(1.0f, 1.0f, 1.0f);
- }
- }
- /// <summary>
- /// Returns the vector (1,0,0).
- /// </summary>
- public static Vector3 UnitX { get { return new Vector3(1.0f, 0.0f, 0.0f); } }
- /// <summary>
- /// Returns the vector (0,1,0).
- /// </summary>
- public static Vector3 UnitY { get { return new Vector3(0.0f, 1.0f, 0.0f); } }
- /// <summary>
- /// Returns the vector (0,0,1).
- /// </summary>
- public static Vector3 UnitZ { get { return new Vector3(0.0f, 0.0f, 1.0f); } }
- #endregion Public Static Properties
-
- #region Public Instance Methods
-
- /// <summary>
- /// Returns the hash code for this instance.
- /// </summary>
- /// <returns>The hash code.</returns>
- public override readonly int GetHashCode()
- {
- return HashCode.Combine(this.X.GetHashCode(), this.Y.GetHashCode(), this.Z.GetHashCode());
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Object is equal to this Vector3 instance.
- /// </summary>
- /// <param name="obj">The Object to compare against.</param>
- /// <returns>True if the Object is equal to this Vector3; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override readonly bool Equals(object? obj)
- {
- if (!(obj is Vector3))
- return false;
- return Equals((Vector3)obj);
- }
-
- /// <summary>
- /// Returns a String representing this Vector3 instance.
- /// </summary>
- /// <returns>The string representation.</returns>
- public override readonly string ToString()
- {
- return ToString("G", CultureInfo.CurrentCulture);
- }
-
- /// <summary>
- /// Returns a String representing this Vector3 instance, using the specified format to format individual elements.
- /// </summary>
- /// <param name="format">The format of individual elements.</param>
- /// <returns>The string representation.</returns>
- public readonly string ToString(string? format)
- {
- return ToString(format, CultureInfo.CurrentCulture);
- }
-
- /// <summary>
- /// Returns a String representing this Vector3 instance, using the specified format to format individual elements
- /// and the given IFormatProvider.
- /// </summary>
- /// <param name="format">The format of individual elements.</param>
- /// <param name="formatProvider">The format provider to use when formatting elements.</param>
- /// <returns>The string representation.</returns>
- public readonly string ToString(string? format, IFormatProvider? formatProvider)
- {
- StringBuilder sb = new StringBuilder();
- string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
- sb.Append('<');
- sb.Append(((IFormattable)this.X).ToString(format, formatProvider));
- sb.Append(separator);
- sb.Append(' ');
- sb.Append(((IFormattable)this.Y).ToString(format, formatProvider));
- sb.Append(separator);
- sb.Append(' ');
- sb.Append(((IFormattable)this.Z).ToString(format, formatProvider));
- sb.Append('>');
- return sb.ToString();
- }
-
- /// <summary>
- /// Returns the length of the vector.
- /// </summary>
- /// <returns>The vector's length.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly float Length()
- {
- if (Vector.IsHardwareAccelerated)
- {
- float ls = Vector3.Dot(this, this);
- return MathF.Sqrt(ls);
- }
- else
- {
- float ls = X * X + Y * Y + Z * Z;
- return MathF.Sqrt(ls);
- }
- }
-
- /// <summary>
- /// Returns the length of the vector squared. This operation is cheaper than Length().
- /// </summary>
- /// <returns>The vector's length squared.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly float LengthSquared()
- {
- if (Vector.IsHardwareAccelerated)
- {
- return Vector3.Dot(this, this);
- }
- else
- {
- return X * X + Y * Y + Z * Z;
- }
- }
- #endregion Public Instance Methods
-
- #region Public Static Methods
- /// <summary>
- /// Returns the Euclidean distance between the two given points.
- /// </summary>
- /// <param name="value1">The first point.</param>
- /// <param name="value2">The second point.</param>
- /// <returns>The distance.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Distance(Vector3 value1, Vector3 value2)
- {
- if (Vector.IsHardwareAccelerated)
- {
- Vector3 difference = value1 - value2;
- float ls = Vector3.Dot(difference, difference);
- return MathF.Sqrt(ls);
- }
- else
- {
- float dx = value1.X - value2.X;
- float dy = value1.Y - value2.Y;
- float dz = value1.Z - value2.Z;
-
- float ls = dx * dx + dy * dy + dz * dz;
-
- return MathF.Sqrt(ls);
- }
- }
-
- /// <summary>
- /// Returns the Euclidean distance squared between the two given points.
- /// </summary>
- /// <param name="value1">The first point.</param>
- /// <param name="value2">The second point.</param>
- /// <returns>The distance squared.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float DistanceSquared(Vector3 value1, Vector3 value2)
- {
- if (Vector.IsHardwareAccelerated)
- {
- Vector3 difference = value1 - value2;
- return Vector3.Dot(difference, difference);
- }
- else
- {
- float dx = value1.X - value2.X;
- float dy = value1.Y - value2.Y;
- float dz = value1.Z - value2.Z;
-
- return dx * dx + dy * dy + dz * dz;
- }
- }
-
- /// <summary>
- /// Returns a vector with the same direction as the given vector, but with a length of 1.
- /// </summary>
- /// <param name="value">The vector to normalize.</param>
- /// <returns>The normalized vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Normalize(Vector3 value)
- {
- if (Vector.IsHardwareAccelerated)
- {
- float length = value.Length();
- return value / length;
- }
- else
- {
- float ls = value.X * value.X + value.Y * value.Y + value.Z * value.Z;
- float length = MathF.Sqrt(ls);
- return new Vector3(value.X / length, value.Y / length, value.Z / length);
- }
- }
-
- /// <summary>
- /// Computes the cross product of two vectors.
- /// </summary>
- /// <param name="vector1">The first vector.</param>
- /// <param name="vector2">The second vector.</param>
- /// <returns>The cross product.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Cross(Vector3 vector1, Vector3 vector2)
- {
- return new Vector3(
- vector1.Y * vector2.Z - vector1.Z * vector2.Y,
- vector1.Z * vector2.X - vector1.X * vector2.Z,
- vector1.X * vector2.Y - vector1.Y * vector2.X);
- }
-
- /// <summary>
- /// Returns the reflection of a vector off a surface that has the specified normal.
- /// </summary>
- /// <param name="vector">The source vector.</param>
- /// <param name="normal">The normal of the surface being reflected off.</param>
- /// <returns>The reflected vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Reflect(Vector3 vector, Vector3 normal)
- {
- if (Vector.IsHardwareAccelerated)
- {
- float dot = Vector3.Dot(vector, normal);
- Vector3 temp = normal * dot * 2f;
- return vector - temp;
- }
- else
- {
- float dot = vector.X * normal.X + vector.Y * normal.Y + vector.Z * normal.Z;
- float tempX = normal.X * dot * 2f;
- float tempY = normal.Y * dot * 2f;
- float tempZ = normal.Z * dot * 2f;
- return new Vector3(vector.X - tempX, vector.Y - tempY, vector.Z - tempZ);
- }
- }
-
- /// <summary>
- /// Restricts a vector between a min and max value.
- /// </summary>
- /// <param name="value1">The source vector.</param>
- /// <param name="min">The minimum value.</param>
- /// <param name="max">The maximum value.</param>
- /// <returns>The restricted vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Clamp(Vector3 value1, Vector3 min, Vector3 max)
- {
- // This compare order is very important!!!
- // We must follow HLSL behavior in the case user specified min value is bigger than max value.
- float x = value1.X;
- x = (min.X > x) ? min.X : x; // max(x, minx)
- x = (max.X < x) ? max.X : x; // min(x, maxx)
-
- float y = value1.Y;
- y = (min.Y > y) ? min.Y : y; // max(y, miny)
- y = (max.Y < y) ? max.Y : y; // min(y, maxy)
-
- float z = value1.Z;
- z = (min.Z > z) ? min.Z : z; // max(z, minz)
- z = (max.Z < z) ? max.Z : z; // min(z, maxz)
-
- return new Vector3(x, y, z);
- }
-
- /// <summary>
- /// Linearly interpolates between two vectors based on the given weighting.
- /// </summary>
- /// <param name="value1">The first source vector.</param>
- /// <param name="value2">The second source vector.</param>
- /// <param name="amount">Value between 0 and 1 indicating the weight of the second source vector.</param>
- /// <returns>The interpolated vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Lerp(Vector3 value1, Vector3 value2, float amount)
- {
- if (Vector.IsHardwareAccelerated)
- {
- Vector3 firstInfluence = value1 * (1f - amount);
- Vector3 secondInfluence = value2 * amount;
- return firstInfluence + secondInfluence;
- }
- else
- {
- return new Vector3(
- value1.X + (value2.X - value1.X) * amount,
- value1.Y + (value2.Y - value1.Y) * amount,
- value1.Z + (value2.Z - value1.Z) * amount);
- }
- }
-
- /// <summary>
- /// Transforms a vector by the given matrix.
- /// </summary>
- /// <param name="position">The source vector.</param>
- /// <param name="matrix">The transformation matrix.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Transform(Vector3 position, Matrix4x4 matrix)
- {
- return new Vector3(
- position.X * matrix.M11 + position.Y * matrix.M21 + position.Z * matrix.M31 + matrix.M41,
- position.X * matrix.M12 + position.Y * matrix.M22 + position.Z * matrix.M32 + matrix.M42,
- position.X * matrix.M13 + position.Y * matrix.M23 + position.Z * matrix.M33 + matrix.M43);
- }
-
- /// <summary>
- /// Transforms a vector normal by the given matrix.
- /// </summary>
- /// <param name="normal">The source vector.</param>
- /// <param name="matrix">The transformation matrix.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 TransformNormal(Vector3 normal, Matrix4x4 matrix)
- {
- return new Vector3(
- normal.X * matrix.M11 + normal.Y * matrix.M21 + normal.Z * matrix.M31,
- normal.X * matrix.M12 + normal.Y * matrix.M22 + normal.Z * matrix.M32,
- normal.X * matrix.M13 + normal.Y * matrix.M23 + normal.Z * matrix.M33);
- }
-
- /// <summary>
- /// Transforms a vector by the given Quaternion rotation value.
- /// </summary>
- /// <param name="value">The source vector to be rotated.</param>
- /// <param name="rotation">The rotation to apply.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Transform(Vector3 value, Quaternion rotation)
- {
- float x2 = rotation.X + rotation.X;
- float y2 = rotation.Y + rotation.Y;
- float z2 = rotation.Z + rotation.Z;
-
- float wx2 = rotation.W * x2;
- float wy2 = rotation.W * y2;
- float wz2 = rotation.W * z2;
- float xx2 = rotation.X * x2;
- float xy2 = rotation.X * y2;
- float xz2 = rotation.X * z2;
- float yy2 = rotation.Y * y2;
- float yz2 = rotation.Y * z2;
- float zz2 = rotation.Z * z2;
-
- return new Vector3(
- value.X * (1.0f - yy2 - zz2) + value.Y * (xy2 - wz2) + value.Z * (xz2 + wy2),
- value.X * (xy2 + wz2) + value.Y * (1.0f - xx2 - zz2) + value.Z * (yz2 - wx2),
- value.X * (xz2 - wy2) + value.Y * (yz2 + wx2) + value.Z * (1.0f - xx2 - yy2));
- }
- #endregion Public Static Methods
-
- #region Public operator methods
-
- // All these methods should be inlined as they are implemented
- // over JIT intrinsics
-
- /// <summary>
- /// Adds two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The summed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Add(Vector3 left, Vector3 right)
- {
- return left + right;
- }
-
- /// <summary>
- /// Subtracts the second vector from the first.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The difference vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Subtract(Vector3 left, Vector3 right)
- {
- return left - right;
- }
-
- /// <summary>
- /// Multiplies two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The product vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Multiply(Vector3 left, Vector3 right)
- {
- return left * right;
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The source vector.</param>
- /// <param name="right">The scalar value.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Multiply(Vector3 left, float right)
- {
- return left * right;
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The scalar value.</param>
- /// <param name="right">The source vector.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Multiply(float left, Vector3 right)
- {
- return left * right;
- }
-
- /// <summary>
- /// Divides the first vector by the second.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The vector resulting from the division.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Divide(Vector3 left, Vector3 right)
- {
- return left / right;
- }
-
- /// <summary>
- /// Divides the vector by the given scalar.
- /// </summary>
- /// <param name="left">The source vector.</param>
- /// <param name="divisor">The scalar value.</param>
- /// <returns>The result of the division.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Divide(Vector3 left, float divisor)
- {
- return left / divisor;
- }
-
- /// <summary>
- /// Negates a given vector.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The negated vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Negate(Vector3 value)
- {
- return -value;
- }
- #endregion Public operator methods
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector3_Intrinsics.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Vector3_Intrinsics.cs
deleted file mode 100644
index c41baa46aa8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector3_Intrinsics.cs
+++ /dev/null
@@ -1,320 +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 System.Runtime.CompilerServices;
-
-namespace System.Numerics
-{
- // This file contains the definitions for all of the JIT intrinsic methods and properties that are recognized by the current x64 JIT compiler.
- // The implementation defined here is used in any circumstance where the JIT fails to recognize these members as intrinsic.
- // The JIT recognizes these methods and properties by name and signature: if either is changed, the JIT will no longer recognize the member.
- // Some methods declared here are not strictly intrinsic, but delegate to an intrinsic method. For example, only one overload of CopyTo()
- // is actually recognized by the JIT, but both are here for simplicity.
-
- public partial struct Vector3
- {
- /// <summary>
- /// The X component of the vector.
- /// </summary>
- public float X;
- /// <summary>
- /// The Y component of the vector.
- /// </summary>
- public float Y;
- /// <summary>
- /// The Z component of the vector.
- /// </summary>
- public float Z;
-
- #region Constructors
- /// <summary>
- /// Constructs a vector whose elements are all the single specified value.
- /// </summary>
- /// <param name="value">The element to fill the vector with.</param>
- [Intrinsic]
- public Vector3(float value) : this(value, value, value) { }
-
- /// <summary>
- /// Constructs a Vector3 from the given Vector2 and a third value.
- /// </summary>
- /// <param name="value">The Vector to extract X and Y components from.</param>
- /// <param name="z">The Z component.</param>
- [Intrinsic]
- public Vector3(Vector2 value, float z) : this(value.X, value.Y, z) { }
-
- /// <summary>
- /// Constructs a vector with the given individual elements.
- /// </summary>
- /// <param name="x">The X component.</param>
- /// <param name="y">The Y component.</param>
- /// <param name="z">The Z component.</param>
- [Intrinsic]
- public Vector3(float x, float y, float z)
- {
- X = x;
- Y = y;
- Z = z;
- }
- #endregion Constructors
-
- #region Public Instance Methods
- /// <summary>
- /// Copies the contents of the vector into the given array.
- /// </summary>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly void CopyTo(float[] array)
- {
- CopyTo(array, 0);
- }
-
- /// <summary>
- /// Copies the contents of the vector into the given array, starting from index.
- /// </summary>
- /// <exception cref="ArgumentNullException">If array is null.</exception>
- /// <exception cref="RankException">If array is multidimensional.</exception>
- /// <exception cref="ArgumentOutOfRangeException">If index is greater than end of the array or index is less than zero.</exception>
- /// <exception cref="ArgumentException">If number of elements in source vector is greater than those available in destination array.</exception>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly void CopyTo(float[] array, int index)
- {
- if (array == null)
- {
- // Match the JIT's exception type here. For perf, a NullReference is thrown instead of an ArgumentNull.
- throw new NullReferenceException(SR.Arg_NullArgumentNullRef);
- }
- if (index < 0 || index >= array.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.Format(SR.Arg_ArgumentOutOfRangeException, index));
- }
- if ((array.Length - index) < 3)
- {
- throw new ArgumentException(SR.Format(SR.Arg_ElementsInSourceIsGreaterThanDestination, index));
- }
- array[index] = X;
- array[index + 1] = Y;
- array[index + 2] = Z;
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Vector3 is equal to this Vector3 instance.
- /// </summary>
- /// <param name="other">The Vector3 to compare this instance to.</param>
- /// <returns>True if the other Vector3 is equal to this instance; False otherwise.</returns>
- [Intrinsic]
- public readonly bool Equals(Vector3 other)
- {
- return X == other.X &&
- Y == other.Y &&
- Z == other.Z;
- }
- #endregion Public Instance Methods
-
- #region Public Static Methods
- /// <summary>
- /// Returns the dot product of two vectors.
- /// </summary>
- /// <param name="vector1">The first vector.</param>
- /// <param name="vector2">The second vector.</param>
- /// <returns>The dot product.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Dot(Vector3 vector1, Vector3 vector2)
- {
- return vector1.X * vector2.X +
- vector1.Y * vector2.Y +
- vector1.Z * vector2.Z;
- }
-
- /// <summary>
- /// Returns a vector whose elements are the minimum of each of the pairs of elements in the two source vectors.
- /// </summary>
- /// <param name="value1">The first source vector.</param>
- /// <param name="value2">The second source vector.</param>
- /// <returns>The minimized vector.</returns>
- [Intrinsic]
- public static Vector3 Min(Vector3 value1, Vector3 value2)
- {
- return new Vector3(
- (value1.X < value2.X) ? value1.X : value2.X,
- (value1.Y < value2.Y) ? value1.Y : value2.Y,
- (value1.Z < value2.Z) ? value1.Z : value2.Z);
- }
-
- /// <summary>
- /// Returns a vector whose elements are the maximum of each of the pairs of elements in the two source vectors.
- /// </summary>
- /// <param name="value1">The first source vector.</param>
- /// <param name="value2">The second source vector.</param>
- /// <returns>The maximized vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Max(Vector3 value1, Vector3 value2)
- {
- return new Vector3(
- (value1.X > value2.X) ? value1.X : value2.X,
- (value1.Y > value2.Y) ? value1.Y : value2.Y,
- (value1.Z > value2.Z) ? value1.Z : value2.Z);
- }
-
- /// <summary>
- /// Returns a vector whose elements are the absolute values of each of the source vector's elements.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The absolute value vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 Abs(Vector3 value)
- {
- return new Vector3(MathF.Abs(value.X), MathF.Abs(value.Y), MathF.Abs(value.Z));
- }
-
- /// <summary>
- /// Returns a vector whose elements are the square root of each of the source vector's elements.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The square root vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 SquareRoot(Vector3 value)
- {
- return new Vector3(MathF.Sqrt(value.X), MathF.Sqrt(value.Y), MathF.Sqrt(value.Z));
- }
- #endregion Public Static Methods
-
- #region Public Static Operators
- /// <summary>
- /// Adds two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The summed vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 operator +(Vector3 left, Vector3 right)
- {
- return new Vector3(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
- }
-
- /// <summary>
- /// Subtracts the second vector from the first.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The difference vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 operator -(Vector3 left, Vector3 right)
- {
- return new Vector3(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
- }
-
- /// <summary>
- /// Multiplies two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The product vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 operator *(Vector3 left, Vector3 right)
- {
- return new Vector3(left.X * right.X, left.Y * right.Y, left.Z * right.Z);
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The source vector.</param>
- /// <param name="right">The scalar value.</param>
- /// <returns>The scaled vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 operator *(Vector3 left, float right)
- {
- return left * new Vector3(right);
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The scalar value.</param>
- /// <param name="right">The source vector.</param>
- /// <returns>The scaled vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 operator *(float left, Vector3 right)
- {
- return new Vector3(left) * right;
- }
-
- /// <summary>
- /// Divides the first vector by the second.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The vector resulting from the division.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 operator /(Vector3 left, Vector3 right)
- {
- return new Vector3(left.X / right.X, left.Y / right.Y, left.Z / right.Z);
- }
-
- /// <summary>
- /// Divides the vector by the given scalar.
- /// </summary>
- /// <param name="value1">The source vector.</param>
- /// <param name="value2">The scalar value.</param>
- /// <returns>The result of the division.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 operator /(Vector3 value1, float value2)
- {
- return value1 / new Vector3(value2);
- }
-
- /// <summary>
- /// Negates a given vector.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The negated vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector3 operator -(Vector3 value)
- {
- return Zero - value;
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the two given vectors are equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if the vectors are equal; False otherwise.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Vector3 left, Vector3 right)
- {
- return (left.X == right.X &&
- left.Y == right.Y &&
- left.Z == right.Z);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the two given vectors are not equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if the vectors are not equal; False if they are equal.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(Vector3 left, Vector3 right)
- {
- return (left.X != right.X ||
- left.Y != right.Y ||
- left.Z != right.Z);
- }
- #endregion Public Static Operators
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector4.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Vector4.cs
deleted file mode 100644
index 2a463dea446..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector4.cs
+++ /dev/null
@@ -1,531 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System.Numerics
-{
- /// <summary>
- /// A structure encapsulating four single precision floating point values and provides hardware accelerated methods.
- /// </summary>
- [Intrinsic]
- public partial struct Vector4 : IEquatable<Vector4>, IFormattable
- {
- #region Public Static Properties
- /// <summary>
- /// Returns the vector (0,0,0,0).
- /// </summary>
- public static Vector4 Zero
- {
- [Intrinsic]
- get
- {
- return default;
- }
- }
- /// <summary>
- /// Returns the vector (1,1,1,1).
- /// </summary>
- public static Vector4 One
- {
- [Intrinsic]
- get
- {
- return new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
- }
- }
- /// <summary>
- /// Returns the vector (1,0,0,0).
- /// </summary>
- public static Vector4 UnitX { get { return new Vector4(1.0f, 0.0f, 0.0f, 0.0f); } }
- /// <summary>
- /// Returns the vector (0,1,0,0).
- /// </summary>
- public static Vector4 UnitY { get { return new Vector4(0.0f, 1.0f, 0.0f, 0.0f); } }
- /// <summary>
- /// Returns the vector (0,0,1,0).
- /// </summary>
- public static Vector4 UnitZ { get { return new Vector4(0.0f, 0.0f, 1.0f, 0.0f); } }
- /// <summary>
- /// Returns the vector (0,0,0,1).
- /// </summary>
- public static Vector4 UnitW { get { return new Vector4(0.0f, 0.0f, 0.0f, 1.0f); } }
- #endregion Public Static Properties
-
- #region Public instance methods
- /// <summary>
- /// Returns the hash code for this instance.
- /// </summary>
- /// <returns>The hash code.</returns>
- public override readonly int GetHashCode()
- {
- return HashCode.Combine(this.X.GetHashCode(), this.Y.GetHashCode(), this.Z.GetHashCode(), this.W.GetHashCode());
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Object is equal to this Vector4 instance.
- /// </summary>
- /// <param name="obj">The Object to compare against.</param>
- /// <returns>True if the Object is equal to this Vector4; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override readonly bool Equals(object? obj)
- {
- if (!(obj is Vector4))
- return false;
- return Equals((Vector4)obj);
- }
-
- /// <summary>
- /// Returns a String representing this Vector4 instance.
- /// </summary>
- /// <returns>The string representation.</returns>
- public override readonly string ToString()
- {
- return ToString("G", CultureInfo.CurrentCulture);
- }
-
- /// <summary>
- /// Returns a String representing this Vector4 instance, using the specified format to format individual elements.
- /// </summary>
- /// <param name="format">The format of individual elements.</param>
- /// <returns>The string representation.</returns>
- public readonly string ToString(string? format)
- {
- return ToString(format, CultureInfo.CurrentCulture);
- }
-
- /// <summary>
- /// Returns a String representing this Vector4 instance, using the specified format to format individual elements
- /// and the given IFormatProvider.
- /// </summary>
- /// <param name="format">The format of individual elements.</param>
- /// <param name="formatProvider">The format provider to use when formatting elements.</param>
- /// <returns>The string representation.</returns>
- public readonly string ToString(string? format, IFormatProvider? formatProvider)
- {
- StringBuilder sb = new StringBuilder();
- string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
- sb.Append('<');
- sb.Append(this.X.ToString(format, formatProvider));
- sb.Append(separator);
- sb.Append(' ');
- sb.Append(this.Y.ToString(format, formatProvider));
- sb.Append(separator);
- sb.Append(' ');
- sb.Append(this.Z.ToString(format, formatProvider));
- sb.Append(separator);
- sb.Append(' ');
- sb.Append(this.W.ToString(format, formatProvider));
- sb.Append('>');
- return sb.ToString();
- }
-
- /// <summary>
- /// Returns the length of the vector. This operation is cheaper than Length().
- /// </summary>
- /// <returns>The vector's length.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly float Length()
- {
- if (Vector.IsHardwareAccelerated)
- {
- float ls = Vector4.Dot(this, this);
- return MathF.Sqrt(ls);
- }
- else
- {
- float ls = X * X + Y * Y + Z * Z + W * W;
-
- return MathF.Sqrt(ls);
- }
- }
-
- /// <summary>
- /// Returns the length of the vector squared.
- /// </summary>
- /// <returns>The vector's length squared.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly float LengthSquared()
- {
- if (Vector.IsHardwareAccelerated)
- {
- return Vector4.Dot(this, this);
- }
- else
- {
- return X * X + Y * Y + Z * Z + W * W;
- }
- }
- #endregion Public Instance Methods
-
- #region Public Static Methods
- /// <summary>
- /// Returns the Euclidean distance between the two given points.
- /// </summary>
- /// <param name="value1">The first point.</param>
- /// <param name="value2">The second point.</param>
- /// <returns>The distance.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Distance(Vector4 value1, Vector4 value2)
- {
- if (Vector.IsHardwareAccelerated)
- {
- Vector4 difference = value1 - value2;
- float ls = Vector4.Dot(difference, difference);
- return MathF.Sqrt(ls);
- }
- else
- {
- float dx = value1.X - value2.X;
- float dy = value1.Y - value2.Y;
- float dz = value1.Z - value2.Z;
- float dw = value1.W - value2.W;
-
- float ls = dx * dx + dy * dy + dz * dz + dw * dw;
-
- return MathF.Sqrt(ls);
- }
- }
-
- /// <summary>
- /// Returns the Euclidean distance squared between the two given points.
- /// </summary>
- /// <param name="value1">The first point.</param>
- /// <param name="value2">The second point.</param>
- /// <returns>The distance squared.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float DistanceSquared(Vector4 value1, Vector4 value2)
- {
- if (Vector.IsHardwareAccelerated)
- {
- Vector4 difference = value1 - value2;
- return Vector4.Dot(difference, difference);
- }
- else
- {
- float dx = value1.X - value2.X;
- float dy = value1.Y - value2.Y;
- float dz = value1.Z - value2.Z;
- float dw = value1.W - value2.W;
-
- return dx * dx + dy * dy + dz * dz + dw * dw;
- }
- }
-
- /// <summary>
- /// Returns a vector with the same direction as the given vector, but with a length of 1.
- /// </summary>
- /// <param name="vector">The vector to normalize.</param>
- /// <returns>The normalized vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Normalize(Vector4 vector)
- {
- if (Vector.IsHardwareAccelerated)
- {
- float length = vector.Length();
- return vector / length;
- }
- else
- {
- float ls = vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z + vector.W * vector.W;
- float invNorm = 1.0f / MathF.Sqrt(ls);
-
- return new Vector4(
- vector.X * invNorm,
- vector.Y * invNorm,
- vector.Z * invNorm,
- vector.W * invNorm);
- }
- }
-
- /// <summary>
- /// Restricts a vector between a min and max value.
- /// </summary>
- /// <param name="value1">The source vector.</param>
- /// <param name="min">The minimum value.</param>
- /// <param name="max">The maximum value.</param>
- /// <returns>The restricted vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Clamp(Vector4 value1, Vector4 min, Vector4 max)
- {
- // This compare order is very important!!!
- // We must follow HLSL behavior in the case user specified min value is bigger than max value.
- float x = value1.X;
- x = (min.X > x) ? min.X : x; // max(x, minx)
- x = (max.X < x) ? max.X : x; // min(x, maxx)
-
- float y = value1.Y;
- y = (min.Y > y) ? min.Y : y; // max(y, miny)
- y = (max.Y < y) ? max.Y : y; // min(y, maxy)
-
- float z = value1.Z;
- z = (min.Z > z) ? min.Z : z; // max(z, minz)
- z = (max.Z < z) ? max.Z : z; // min(z, maxz)
-
- float w = value1.W;
- w = (min.W > w) ? min.W : w; // max(w, minw)
- w = (max.W < w) ? max.W : w; // min(w, minw)
-
- return new Vector4(x, y, z, w);
- }
-
- /// <summary>
- /// Linearly interpolates between two vectors based on the given weighting.
- /// </summary>
- /// <param name="value1">The first source vector.</param>
- /// <param name="value2">The second source vector.</param>
- /// <param name="amount">Value between 0 and 1 indicating the weight of the second source vector.</param>
- /// <returns>The interpolated vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Lerp(Vector4 value1, Vector4 value2, float amount)
- {
- return new Vector4(
- value1.X + (value2.X - value1.X) * amount,
- value1.Y + (value2.Y - value1.Y) * amount,
- value1.Z + (value2.Z - value1.Z) * amount,
- value1.W + (value2.W - value1.W) * amount);
- }
-
- /// <summary>
- /// Transforms a vector by the given matrix.
- /// </summary>
- /// <param name="position">The source vector.</param>
- /// <param name="matrix">The transformation matrix.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Transform(Vector2 position, Matrix4x4 matrix)
- {
- return new Vector4(
- position.X * matrix.M11 + position.Y * matrix.M21 + matrix.M41,
- position.X * matrix.M12 + position.Y * matrix.M22 + matrix.M42,
- position.X * matrix.M13 + position.Y * matrix.M23 + matrix.M43,
- position.X * matrix.M14 + position.Y * matrix.M24 + matrix.M44);
- }
-
- /// <summary>
- /// Transforms a vector by the given matrix.
- /// </summary>
- /// <param name="position">The source vector.</param>
- /// <param name="matrix">The transformation matrix.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Transform(Vector3 position, Matrix4x4 matrix)
- {
- return new Vector4(
- position.X * matrix.M11 + position.Y * matrix.M21 + position.Z * matrix.M31 + matrix.M41,
- position.X * matrix.M12 + position.Y * matrix.M22 + position.Z * matrix.M32 + matrix.M42,
- position.X * matrix.M13 + position.Y * matrix.M23 + position.Z * matrix.M33 + matrix.M43,
- position.X * matrix.M14 + position.Y * matrix.M24 + position.Z * matrix.M34 + matrix.M44);
- }
-
- /// <summary>
- /// Transforms a vector by the given matrix.
- /// </summary>
- /// <param name="vector">The source vector.</param>
- /// <param name="matrix">The transformation matrix.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Transform(Vector4 vector, Matrix4x4 matrix)
- {
- return new Vector4(
- vector.X * matrix.M11 + vector.Y * matrix.M21 + vector.Z * matrix.M31 + vector.W * matrix.M41,
- vector.X * matrix.M12 + vector.Y * matrix.M22 + vector.Z * matrix.M32 + vector.W * matrix.M42,
- vector.X * matrix.M13 + vector.Y * matrix.M23 + vector.Z * matrix.M33 + vector.W * matrix.M43,
- vector.X * matrix.M14 + vector.Y * matrix.M24 + vector.Z * matrix.M34 + vector.W * matrix.M44);
- }
-
- /// <summary>
- /// Transforms a vector by the given Quaternion rotation value.
- /// </summary>
- /// <param name="value">The source vector to be rotated.</param>
- /// <param name="rotation">The rotation to apply.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Transform(Vector2 value, Quaternion rotation)
- {
- float x2 = rotation.X + rotation.X;
- float y2 = rotation.Y + rotation.Y;
- float z2 = rotation.Z + rotation.Z;
-
- float wx2 = rotation.W * x2;
- float wy2 = rotation.W * y2;
- float wz2 = rotation.W * z2;
- float xx2 = rotation.X * x2;
- float xy2 = rotation.X * y2;
- float xz2 = rotation.X * z2;
- float yy2 = rotation.Y * y2;
- float yz2 = rotation.Y * z2;
- float zz2 = rotation.Z * z2;
-
- return new Vector4(
- value.X * (1.0f - yy2 - zz2) + value.Y * (xy2 - wz2),
- value.X * (xy2 + wz2) + value.Y * (1.0f - xx2 - zz2),
- value.X * (xz2 - wy2) + value.Y * (yz2 + wx2),
- 1.0f);
- }
-
- /// <summary>
- /// Transforms a vector by the given Quaternion rotation value.
- /// </summary>
- /// <param name="value">The source vector to be rotated.</param>
- /// <param name="rotation">The rotation to apply.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Transform(Vector3 value, Quaternion rotation)
- {
- float x2 = rotation.X + rotation.X;
- float y2 = rotation.Y + rotation.Y;
- float z2 = rotation.Z + rotation.Z;
-
- float wx2 = rotation.W * x2;
- float wy2 = rotation.W * y2;
- float wz2 = rotation.W * z2;
- float xx2 = rotation.X * x2;
- float xy2 = rotation.X * y2;
- float xz2 = rotation.X * z2;
- float yy2 = rotation.Y * y2;
- float yz2 = rotation.Y * z2;
- float zz2 = rotation.Z * z2;
-
- return new Vector4(
- value.X * (1.0f - yy2 - zz2) + value.Y * (xy2 - wz2) + value.Z * (xz2 + wy2),
- value.X * (xy2 + wz2) + value.Y * (1.0f - xx2 - zz2) + value.Z * (yz2 - wx2),
- value.X * (xz2 - wy2) + value.Y * (yz2 + wx2) + value.Z * (1.0f - xx2 - yy2),
- 1.0f);
- }
-
- /// <summary>
- /// Transforms a vector by the given Quaternion rotation value.
- /// </summary>
- /// <param name="value">The source vector to be rotated.</param>
- /// <param name="rotation">The rotation to apply.</param>
- /// <returns>The transformed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Transform(Vector4 value, Quaternion rotation)
- {
- float x2 = rotation.X + rotation.X;
- float y2 = rotation.Y + rotation.Y;
- float z2 = rotation.Z + rotation.Z;
-
- float wx2 = rotation.W * x2;
- float wy2 = rotation.W * y2;
- float wz2 = rotation.W * z2;
- float xx2 = rotation.X * x2;
- float xy2 = rotation.X * y2;
- float xz2 = rotation.X * z2;
- float yy2 = rotation.Y * y2;
- float yz2 = rotation.Y * z2;
- float zz2 = rotation.Z * z2;
-
- return new Vector4(
- value.X * (1.0f - yy2 - zz2) + value.Y * (xy2 - wz2) + value.Z * (xz2 + wy2),
- value.X * (xy2 + wz2) + value.Y * (1.0f - xx2 - zz2) + value.Z * (yz2 - wx2),
- value.X * (xz2 - wy2) + value.Y * (yz2 + wx2) + value.Z * (1.0f - xx2 - yy2),
- value.W);
- }
- #endregion Public Static Methods
-
- #region Public operator methods
- // All these methods should be inlines as they are implemented
- // over JIT intrinsics
-
- /// <summary>
- /// Adds two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The summed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Add(Vector4 left, Vector4 right)
- {
- return left + right;
- }
-
- /// <summary>
- /// Subtracts the second vector from the first.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The difference vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Subtract(Vector4 left, Vector4 right)
- {
- return left - right;
- }
-
- /// <summary>
- /// Multiplies two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The product vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Multiply(Vector4 left, Vector4 right)
- {
- return left * right;
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The source vector.</param>
- /// <param name="right">The scalar value.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Multiply(Vector4 left, float right)
- {
- return left * new Vector4(right, right, right, right);
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The scalar value.</param>
- /// <param name="right">The source vector.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Multiply(float left, Vector4 right)
- {
- return new Vector4(left, left, left, left) * right;
- }
-
- /// <summary>
- /// Divides the first vector by the second.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The vector resulting from the division.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Divide(Vector4 left, Vector4 right)
- {
- return left / right;
- }
-
- /// <summary>
- /// Divides the vector by the given scalar.
- /// </summary>
- /// <param name="left">The source vector.</param>
- /// <param name="divisor">The scalar value.</param>
- /// <returns>The result of the division.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Divide(Vector4 left, float divisor)
- {
- return left / divisor;
- }
-
- /// <summary>
- /// Negates a given vector.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The negated vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Negate(Vector4 value)
- {
- return -value;
- }
- #endregion Public operator methods
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector4_Intrinsics.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Vector4_Intrinsics.cs
deleted file mode 100644
index 440c78882d4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector4_Intrinsics.cs
+++ /dev/null
@@ -1,351 +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 System.Runtime.CompilerServices;
-
-namespace System.Numerics
-{
- // This file contains the definitions for all of the JIT intrinsic methods and properties that are recognized by the current x64 JIT compiler.
- // The implementation defined here is used in any circumstance where the JIT fails to recognize these members as intrinsic.
- // The JIT recognizes these methods and properties by name and signature: if either is changed, the JIT will no longer recognize the member.
- // Some methods declared here are not strictly intrinsic, but delegate to an intrinsic method. For example, only one overload of CopyTo()
-
- public partial struct Vector4
- {
- /// <summary>
- /// The X component of the vector.
- /// </summary>
- public float X;
- /// <summary>
- /// The Y component of the vector.
- /// </summary>
- public float Y;
- /// <summary>
- /// The Z component of the vector.
- /// </summary>
- public float Z;
- /// <summary>
- /// The W component of the vector.
- /// </summary>
- public float W;
-
- #region Constructors
-
- /// <summary>
- /// Constructs a vector whose elements are all the single specified value.
- /// </summary>
- /// <param name="value">The element to fill the vector with.</param>
- [Intrinsic]
- public Vector4(float value)
- : this(value, value, value, value)
- {
- }
- /// <summary>
- /// Constructs a vector with the given individual elements.
- /// </summary>
- /// <param name="w">W component.</param>
- /// <param name="x">X component.</param>
- /// <param name="y">Y component.</param>
- /// <param name="z">Z component.</param>
- [Intrinsic]
- public Vector4(float x, float y, float z, float w)
- {
- W = w;
- X = x;
- Y = y;
- Z = z;
- }
-
- /// <summary>
- /// Constructs a Vector4 from the given Vector2 and a Z and W component.
- /// </summary>
- /// <param name="value">The vector to use as the X and Y components.</param>
- /// <param name="z">The Z component.</param>
- /// <param name="w">The W component.</param>
- [Intrinsic]
- public Vector4(Vector2 value, float z, float w)
- {
- X = value.X;
- Y = value.Y;
- Z = z;
- W = w;
- }
-
- /// <summary>
- /// Constructs a Vector4 from the given Vector3 and a W component.
- /// </summary>
- /// <param name="value">The vector to use as the X, Y, and Z components.</param>
- /// <param name="w">The W component.</param>
- [Intrinsic]
- public Vector4(Vector3 value, float w)
- {
- X = value.X;
- Y = value.Y;
- Z = value.Z;
- W = w;
- }
- #endregion Constructors
-
- #region Public Instance Methods
- /// <summary>
- /// Copies the contents of the vector into the given array.
- /// </summary>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly void CopyTo(float[] array)
- {
- CopyTo(array, 0);
- }
-
- /// <summary>
- /// Copies the contents of the vector into the given array, starting from index.
- /// </summary>
- /// <exception cref="ArgumentNullException">If array is null.</exception>
- /// <exception cref="RankException">If array is multidimensional.</exception>
- /// <exception cref="ArgumentOutOfRangeException">If index is greater than end of the array or index is less than zero.</exception>
- /// <exception cref="ArgumentException">If number of elements in source vector is greater than those available in destination array.</exception>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly void CopyTo(float[] array, int index)
- {
- if (array == null)
- {
- // Match the JIT's exception type here. For perf, a NullReference is thrown instead of an ArgumentNull.
- throw new NullReferenceException(SR.Arg_NullArgumentNullRef);
- }
- if (index < 0 || index >= array.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.Format(SR.Arg_ArgumentOutOfRangeException, index));
- }
- if ((array.Length - index) < 4)
- {
- throw new ArgumentException(SR.Format(SR.Arg_ElementsInSourceIsGreaterThanDestination, index));
- }
- array[index] = X;
- array[index + 1] = Y;
- array[index + 2] = Z;
- array[index + 3] = W;
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the given Vector4 is equal to this Vector4 instance.
- /// </summary>
- /// <param name="other">The Vector4 to compare this instance to.</param>
- /// <returns>True if the other Vector4 is equal to this instance; False otherwise.</returns>
- [Intrinsic]
- public readonly bool Equals(Vector4 other)
- {
- return this.X == other.X
- && this.Y == other.Y
- && this.Z == other.Z
- && this.W == other.W;
- }
- #endregion Public Instance Methods
-
- #region Public Static Methods
- /// <summary>
- /// Returns the dot product of two vectors.
- /// </summary>
- /// <param name="vector1">The first vector.</param>
- /// <param name="vector2">The second vector.</param>
- /// <returns>The dot product.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Dot(Vector4 vector1, Vector4 vector2)
- {
- return vector1.X * vector2.X +
- vector1.Y * vector2.Y +
- vector1.Z * vector2.Z +
- vector1.W * vector2.W;
- }
-
- /// <summary>
- /// Returns a vector whose elements are the minimum of each of the pairs of elements in the two source vectors.
- /// </summary>
- /// <param name="value1">The first source vector.</param>
- /// <param name="value2">The second source vector.</param>
- /// <returns>The minimized vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Min(Vector4 value1, Vector4 value2)
- {
- return new Vector4(
- (value1.X < value2.X) ? value1.X : value2.X,
- (value1.Y < value2.Y) ? value1.Y : value2.Y,
- (value1.Z < value2.Z) ? value1.Z : value2.Z,
- (value1.W < value2.W) ? value1.W : value2.W);
- }
-
- /// <summary>
- /// Returns a vector whose elements are the maximum of each of the pairs of elements in the two source vectors.
- /// </summary>
- /// <param name="value1">The first source vector.</param>
- /// <param name="value2">The second source vector.</param>
- /// <returns>The maximized vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Max(Vector4 value1, Vector4 value2)
- {
- return new Vector4(
- (value1.X > value2.X) ? value1.X : value2.X,
- (value1.Y > value2.Y) ? value1.Y : value2.Y,
- (value1.Z > value2.Z) ? value1.Z : value2.Z,
- (value1.W > value2.W) ? value1.W : value2.W);
- }
-
- /// <summary>
- /// Returns a vector whose elements are the absolute values of each of the source vector's elements.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The absolute value vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 Abs(Vector4 value)
- {
- return new Vector4(MathF.Abs(value.X), MathF.Abs(value.Y), MathF.Abs(value.Z), MathF.Abs(value.W));
- }
-
- /// <summary>
- /// Returns a vector whose elements are the square root of each of the source vector's elements.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The square root vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 SquareRoot(Vector4 value)
- {
- return new Vector4(MathF.Sqrt(value.X), MathF.Sqrt(value.Y), MathF.Sqrt(value.Z), MathF.Sqrt(value.W));
- }
- #endregion Public Static Methods
-
- #region Public static operators
- /// <summary>
- /// Adds two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The summed vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 operator +(Vector4 left, Vector4 right)
- {
- return new Vector4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W);
- }
-
- /// <summary>
- /// Subtracts the second vector from the first.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The difference vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 operator -(Vector4 left, Vector4 right)
- {
- return new Vector4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W);
- }
-
- /// <summary>
- /// Multiplies two vectors together.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The product vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 operator *(Vector4 left, Vector4 right)
- {
- return new Vector4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W);
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The source vector.</param>
- /// <param name="right">The scalar value.</param>
- /// <returns>The scaled vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 operator *(Vector4 left, float right)
- {
- return left * new Vector4(right);
- }
-
- /// <summary>
- /// Multiplies a vector by the given scalar.
- /// </summary>
- /// <param name="left">The scalar value.</param>
- /// <param name="right">The source vector.</param>
- /// <returns>The scaled vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 operator *(float left, Vector4 right)
- {
- return new Vector4(left) * right;
- }
-
- /// <summary>
- /// Divides the first vector by the second.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The vector resulting from the division.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 operator /(Vector4 left, Vector4 right)
- {
- return new Vector4(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W);
- }
-
- /// <summary>
- /// Divides the vector by the given scalar.
- /// </summary>
- /// <param name="value1">The source vector.</param>
- /// <param name="value2">The scalar value.</param>
- /// <returns>The result of the division.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 operator /(Vector4 value1, float value2)
- {
- return value1 / new Vector4(value2);
- }
-
- /// <summary>
- /// Negates a given vector.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The negated vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector4 operator -(Vector4 value)
- {
- return Zero - value;
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the two given vectors are equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if the vectors are equal; False otherwise.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Vector4 left, Vector4 right)
- {
- return left.Equals(right);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether the two given vectors are not equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if the vectors are not equal; False if they are equal.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(Vector4 left, Vector4 right)
- {
- return !(left == right);
- }
- #endregion Public static operators
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/VectorMath.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/VectorMath.cs
deleted file mode 100644
index 0c652c4ec41..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/VectorMath.cs
+++ /dev/null
@@ -1,31 +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 System.Diagnostics;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace System.Numerics
-{
- internal static class VectorMath
- {
- public static Vector128<float> Lerp(Vector128<float> a, Vector128<float> b, Vector128<float> t)
- {
- Debug.Assert(Sse.IsSupported);
- return Sse.Add(a, Sse.Multiply(Sse.Subtract(b, a), t));
- }
-
- public static bool Equal(Vector128<float> vector1, Vector128<float> vector2)
- {
- Debug.Assert(Sse.IsSupported);
- return Sse.MoveMask(Sse.CompareNotEqual(vector1, vector2)) == 0;
- }
-
- public static bool NotEqual(Vector128<float> vector1, Vector128<float> vector2)
- {
- Debug.Assert(Sse.IsSupported);
- return Sse.MoveMask(Sse.CompareNotEqual(vector1, vector2)) != 0;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector_Operations.cs b/netcore/System.Private.CoreLib/shared/System/Numerics/Vector_Operations.cs
deleted file mode 100644
index 8d41edaf123..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Numerics/Vector_Operations.cs
+++ /dev/null
@@ -1,896 +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 System.Runtime.CompilerServices;
-
-namespace System.Numerics
-{
- /// <summary>
- /// Contains various methods useful for creating, manipulating, combining, and converting generic vectors with one another.
- /// </summary>
- public static partial class Vector
- {
- // JIT is not looking at the Vector class methods
- // all methods here should be inlined and they must be implemented in terms of Vector<T> intrinsics
- #region Select Methods
- /// <summary>
- /// Creates a new vector with elements selected between the two given source vectors, and based on a mask vector.
- /// </summary>
- /// <param name="condition">The integral mask vector used to drive selection.</param>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The new vector with elements selected based on the mask.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<float> ConditionalSelect(Vector<int> condition, Vector<float> left, Vector<float> right)
- {
- return (Vector<float>)Vector<float>.ConditionalSelect((Vector<float>)condition, left, right);
- }
-
- /// <summary>
- /// Creates a new vector with elements selected between the two given source vectors, and based on a mask vector.
- /// </summary>
- /// <param name="condition">The integral mask vector used to drive selection.</param>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The new vector with elements selected based on the mask.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<double> ConditionalSelect(Vector<long> condition, Vector<double> left, Vector<double> right)
- {
- return (Vector<double>)Vector<double>.ConditionalSelect((Vector<double>)condition, left, right);
- }
-
- /// <summary>
- /// Creates a new vector with elements selected between the two given source vectors, and based on a mask vector.
- /// </summary>
- /// <param name="condition">The mask vector used to drive selection.</param>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The new vector with elements selected based on the mask.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> ConditionalSelect<T>(Vector<T> condition, Vector<T> left, Vector<T> right) where T : struct
- {
- return Vector<T>.ConditionalSelect(condition, left, right);
- }
- #endregion Select Methods
-
- #region Comparison methods
- #region Equals methods
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left and right were equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Equals<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return Vector<T>.Equals(left, right);
- }
-
- /// <summary>
- /// Returns an integral vector whose elements signal whether elements in the left and right floating point vectors were equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<int> Equals(Vector<float> left, Vector<float> right)
- {
- return (Vector<int>)Vector<float>.Equals(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left and right were equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<int> Equals(Vector<int> left, Vector<int> right)
- {
- return Vector<int>.Equals(left, right);
- }
-
- /// <summary>
- /// Returns an integral vector whose elements signal whether elements in the left and right floating point vectors were equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<long> Equals(Vector<double> left, Vector<double> right)
- {
- return (Vector<long>)Vector<double>.Equals(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left and right were equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<long> Equals(Vector<long> left, Vector<long> right)
- {
- return Vector<long>.Equals(left, right);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether each pair of elements in the given vectors are equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The first vector to compare.</param>
- /// <returns>True if all elements are equal; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool EqualsAll<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return left == right;
- }
-
- /// <summary>
- /// Returns a boolean indicating whether any single pair of elements in the given vectors are equal.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if any element pairs are equal; False if no element pairs are equal.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool EqualsAny<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return !Vector<T>.Equals(left, right).Equals(Vector<T>.Zero);
- }
- #endregion Equals methods
-
- #region Lessthan Methods
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were less than their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> LessThan<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return Vector<T>.LessThan(left, right);
- }
-
- /// <summary>
- /// Returns an integral vector whose elements signal whether the elements in left were less than their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant integral vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<int> LessThan(Vector<float> left, Vector<float> right)
- {
- return (Vector<int>)Vector<float>.LessThan(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were less than their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<int> LessThan(Vector<int> left, Vector<int> right)
- {
- return Vector<int>.LessThan(left, right);
- }
-
- /// <summary>
- /// Returns an integral vector whose elements signal whether the elements in left were less than their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant integral vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<long> LessThan(Vector<double> left, Vector<double> right)
- {
- return (Vector<long>)Vector<double>.LessThan(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were less than their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<long> LessThan(Vector<long> left, Vector<long> right)
- {
- return Vector<long>.LessThan(left, right);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether all of the elements in left are less than their corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if all elements in left are less than their corresponding elements in right; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool LessThanAll<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- Vector<int> cond = (Vector<int>)Vector<T>.LessThan(left, right);
- return cond.Equals(Vector<int>.AllOnes);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether any element in left is less than its corresponding element in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if any elements in left are less than their corresponding elements in right; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool LessThanAny<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- Vector<int> cond = (Vector<int>)Vector<T>.LessThan(left, right);
- return !cond.Equals(Vector<int>.Zero);
- }
- #endregion LessthanMethods
-
- #region Lessthanorequal methods
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were less than or equal to their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> LessThanOrEqual<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return Vector<T>.LessThanOrEqual(left, right);
- }
-
- /// <summary>
- /// Returns an integral vector whose elements signal whether the elements in left were less than or equal to their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant integral vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<int> LessThanOrEqual(Vector<float> left, Vector<float> right)
- {
- return (Vector<int>)Vector<float>.LessThanOrEqual(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were less than or equal to their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<int> LessThanOrEqual(Vector<int> left, Vector<int> right)
- {
- return Vector<int>.LessThanOrEqual(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were less than or equal to their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<long> LessThanOrEqual(Vector<long> left, Vector<long> right)
- {
- return Vector<long>.LessThanOrEqual(left, right);
- }
-
- /// <summary>
- /// Returns an integral vector whose elements signal whether the elements in left were less than or equal to their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant integral vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<long> LessThanOrEqual(Vector<double> left, Vector<double> right)
- {
- return (Vector<long>)Vector<double>.LessThanOrEqual(left, right);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether all elements in left are less than or equal to their corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if all elements in left are less than or equal to their corresponding elements in right; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool LessThanOrEqualAll<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- Vector<int> cond = (Vector<int>)Vector<T>.LessThanOrEqual(left, right);
- return cond.Equals(Vector<int>.AllOnes);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether any element in left is less than or equal to its corresponding element in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if any elements in left are less than their corresponding elements in right; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool LessThanOrEqualAny<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- Vector<int> cond = (Vector<int>)Vector<T>.LessThanOrEqual(left, right);
- return !cond.Equals(Vector<int>.Zero);
- }
- #endregion Lessthanorequal methods
-
- #region Greaterthan methods
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were greater than their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> GreaterThan<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return Vector<T>.GreaterThan(left, right);
- }
-
- /// <summary>
- /// Returns an integral vector whose elements signal whether the elements in left were greater than their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant integral vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<int> GreaterThan(Vector<float> left, Vector<float> right)
- {
- return (Vector<int>)Vector<float>.GreaterThan(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were greater than their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<int> GreaterThan(Vector<int> left, Vector<int> right)
- {
- return Vector<int>.GreaterThan(left, right);
- }
-
- /// <summary>
- /// Returns an integral vector whose elements signal whether the elements in left were greater than their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant integral vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<long> GreaterThan(Vector<double> left, Vector<double> right)
- {
- return (Vector<long>)Vector<double>.GreaterThan(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were greater than their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<long> GreaterThan(Vector<long> left, Vector<long> right)
- {
- return Vector<long>.GreaterThan(left, right);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether all elements in left are greater than the corresponding elements in right.
- /// elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if all elements in left are greater than their corresponding elements in right; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool GreaterThanAll<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- Vector<int> cond = (Vector<int>)Vector<T>.GreaterThan(left, right);
- return cond.Equals(Vector<int>.AllOnes);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether any element in left is greater than its corresponding element in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if any elements in left are greater than their corresponding elements in right; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool GreaterThanAny<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- Vector<int> cond = (Vector<int>)Vector<T>.GreaterThan(left, right);
- return !cond.Equals(Vector<int>.Zero);
- }
- #endregion Greaterthan methods
-
- #region Greaterthanorequal methods
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were greater than or equal to their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> GreaterThanOrEqual<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return Vector<T>.GreaterThanOrEqual(left, right);
- }
-
- /// <summary>
- /// Returns an integral vector whose elements signal whether the elements in left were greater than or equal to their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant integral vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<int> GreaterThanOrEqual(Vector<float> left, Vector<float> right)
- {
- return (Vector<int>)Vector<float>.GreaterThanOrEqual(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were greater than or equal to their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<int> GreaterThanOrEqual(Vector<int> left, Vector<int> right)
- {
- return Vector<int>.GreaterThanOrEqual(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements signal whether the elements in left were greater than or equal to their
- /// corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<long> GreaterThanOrEqual(Vector<long> left, Vector<long> right)
- {
- return Vector<long>.GreaterThanOrEqual(left, right);
- }
-
- /// <summary>
- /// Returns an integral vector whose elements signal whether the elements in left were greater than or equal to
- /// their corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>The resultant integral vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<long> GreaterThanOrEqual(Vector<double> left, Vector<double> right)
- {
- return (Vector<long>)Vector<double>.GreaterThanOrEqual(left, right);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether all of the elements in left are greater than or equal to
- /// their corresponding elements in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if all elements in left are greater than or equal to their corresponding elements in right; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool GreaterThanOrEqualAll<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- Vector<int> cond = (Vector<int>)Vector<T>.GreaterThanOrEqual(left, right);
- return cond.Equals(Vector<int>.AllOnes);
- }
-
- /// <summary>
- /// Returns a boolean indicating whether any element in left is greater than or equal to its corresponding element in right.
- /// </summary>
- /// <param name="left">The first vector to compare.</param>
- /// <param name="right">The second vector to compare.</param>
- /// <returns>True if any elements in left are greater than or equal to their corresponding elements in right; False otherwise.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool GreaterThanOrEqualAny<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- Vector<int> cond = (Vector<int>)Vector<T>.GreaterThanOrEqual(left, right);
- return !cond.Equals(Vector<int>.Zero);
- }
- #endregion Greaterthanorequal methods
- #endregion Comparison methods
-
- #region Vector Math Methods
- // Every operation must either be a JIT intrinsic or implemented over a JIT intrinsic
- // as a thin wrapper
- // Operations implemented over a JIT intrinsic should be inlined
- // Methods that do not have a <T> type parameter are recognized as intrinsics
- /// <summary>
- /// Returns whether or not vector operations are subject to hardware acceleration through JIT intrinsic support.
- /// </summary>
- public static bool IsHardwareAccelerated
- {
- [Intrinsic]
- get => false;
- }
-
- // Vector<T>
- // Basic Math
- // All Math operations for Vector<T> are aggressively inlined here
-
- /// <summary>
- /// Returns a new vector whose elements are the absolute values of the given vector's elements.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The absolute value vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Abs<T>(Vector<T> value) where T : struct
- {
- return Vector<T>.Abs(value);
- }
-
- /// <summary>
- /// Returns a new vector whose elements are the minimum of each pair of elements in the two given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The minimum vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Min<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return Vector<T>.Min(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements are the maximum of each pair of elements in the two given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The maximum vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Max<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return Vector<T>.Max(left, right);
- }
-
- // Specialized vector operations
-
- /// <summary>
- /// Returns the dot product of two vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The dot product.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static T Dot<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return Vector<T>.Dot(left, right);
- }
-
- /// <summary>
- /// Returns a new vector whose elements are the square roots of the given vector's elements.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The square root vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> SquareRoot<T>(Vector<T> value) where T : struct
- {
- return Vector<T>.SquareRoot(value);
- }
- #endregion Vector Math Methods
-
- #region Named Arithmetic Operators
- /// <summary>
- /// Creates a new vector whose values are the sum of each pair of elements from the two given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The summed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Add<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return left + right;
- }
-
- /// <summary>
- /// Creates a new vector whose values are the difference between each pairs of elements in the given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The difference vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Subtract<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return left - right;
- }
-
- /// <summary>
- /// Creates a new vector whose values are the product of each pair of elements from the two given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The summed vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Multiply<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return left * right;
- }
-
- /// <summary>
- /// Returns a new vector whose values are the values of the given vector each multiplied by a scalar value.
- /// </summary>
- /// <param name="left">The source vector.</param>
- /// <param name="right">The scalar factor.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Multiply<T>(Vector<T> left, T right) where T : struct
- {
- return left * right;
- }
-
- /// <summary>
- /// Returns a new vector whose values are the values of the given vector each multiplied by a scalar value.
- /// </summary>
- /// <param name="left">The scalar factor.</param>
- /// <param name="right">The source vector.</param>
- /// <returns>The scaled vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Multiply<T>(T left, Vector<T> right) where T : struct
- {
- return left * right;
- }
-
- /// <summary>
- /// Returns a new vector whose values are the result of dividing the first vector's elements
- /// by the corresponding elements in the second vector.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The divided vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Divide<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return left / right;
- }
-
- /// <summary>
- /// Returns a new vector whose elements are the given vector's elements negated.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The negated vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Negate<T>(Vector<T> value) where T : struct
- {
- return -value;
- }
- #endregion Named Arithmetic Operators
-
- #region Named Bitwise Operators
- /// <summary>
- /// Returns a new vector by performing a bitwise-and operation on each of the elements in the given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The resultant vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> BitwiseAnd<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return left & right;
- }
-
- /// <summary>
- /// Returns a new vector by performing a bitwise-or operation on each of the elements in the given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The resultant vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> BitwiseOr<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return left | right;
- }
-
- /// <summary>
- /// Returns a new vector whose elements are obtained by taking the one's complement of the given vector's elements.
- /// </summary>
- /// <param name="value">The source vector.</param>
- /// <returns>The one's complement vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> OnesComplement<T>(Vector<T> value) where T : struct
- {
- return ~value;
- }
-
- /// <summary>
- /// Returns a new vector by performing a bitwise-exclusive-or operation on each of the elements in the given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The resultant vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> Xor<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return left ^ right;
- }
-
- /// <summary>
- /// Returns a new vector by performing a bitwise-and-not operation on each of the elements in the given vectors.
- /// </summary>
- /// <param name="left">The first source vector.</param>
- /// <param name="right">The second source vector.</param>
- /// <returns>The resultant vector.</returns>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<T> AndNot<T>(Vector<T> left, Vector<T> right) where T : struct
- {
- return left & ~right;
- }
- #endregion Named Bitwise Operators
-
- #region Conversion Methods
- /// <summary>
- /// Reinterprets the bits of the given vector into those of a vector of unsigned bytes.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<byte> AsVectorByte<T>(Vector<T> value) where T : struct
- {
- return (Vector<byte>)value;
- }
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of a vector of signed bytes.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<sbyte> AsVectorSByte<T>(Vector<T> value) where T : struct
- {
- return (Vector<sbyte>)value;
- }
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of a vector of 16-bit integers.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<ushort> AsVectorUInt16<T>(Vector<T> value) where T : struct
- {
- return (Vector<ushort>)value;
- }
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of a vector of signed 16-bit integers.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<short> AsVectorInt16<T>(Vector<T> value) where T : struct
- {
- return (Vector<short>)value;
- }
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of a vector of unsigned 32-bit integers.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<uint> AsVectorUInt32<T>(Vector<T> value) where T : struct
- {
- return (Vector<uint>)value;
- }
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of a vector of signed 32-bit integers.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<int> AsVectorInt32<T>(Vector<T> value) where T : struct
- {
- return (Vector<int>)value;
- }
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of a vector of unsigned 64-bit integers.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<ulong> AsVectorUInt64<T>(Vector<T> value) where T : struct
- {
- return (Vector<ulong>)value;
- }
-
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of a vector of signed 64-bit integers.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<long> AsVectorInt64<T>(Vector<T> value) where T : struct
- {
- return (Vector<long>)value;
- }
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of a vector of 32-bit floating point numbers.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<float> AsVectorSingle<T>(Vector<T> value) where T : struct
- {
- return (Vector<float>)value;
- }
-
- /// <summary>
- /// Reinterprets the bits of the given vector into those of a vector of 64-bit floating point numbers.
- /// </summary>
- /// <param name="value">The source vector</param>
- /// <returns>The reinterpreted vector.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector<double> AsVectorDouble<T>(Vector<T> value) where T : struct
- {
- return (Vector<double>)value;
- }
- #endregion Conversion Methods
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Object.cs b/netcore/System.Private.CoreLib/shared/System/Object.cs
deleted file mode 100644
index a8e12bc18d0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Object.cs
+++ /dev/null
@@ -1,85 +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 System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- // The Object is the root class for all object in the CLR System. Object
- // is the super class for all other CLR objects and provide a set of methods and low level
- // services to subclasses. These services include object synchronization and support for clone
- // operations.
- //
- [Serializable]
- [ClassInterface(ClassInterfaceType.AutoDispatch)]
- [ComVisible(true)]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public partial class Object
- {
- // Creates a new instance of an Object.
- [NonVersionable]
- public Object()
- {
- }
-
- // Allow an object to free resources before the object is reclaimed by the GC.
- // This method's virtual slot number is hardcoded in runtimes. Do not add any virtual methods ahead of this.
- [NonVersionable]
- [SuppressMessage("Microsoft.Performance", "CA1821:RemoveEmptyFinalizers")]
- ~Object()
- {
- }
-
- // Returns a String which represents the object instance. The default
- // for an object is to return the fully qualified name of the class.
- public virtual string? ToString()
- {
- return GetType().ToString();
- }
-
- // Returns a boolean indicating if the passed in object obj is
- // Equal to this. Equality is defined as object equality for reference
- // types and bitwise equality for value types using a loader trick to
- // replace Equals with EqualsValue for value types).
- public virtual bool Equals(object? obj)
- {
- return RuntimeHelpers.Equals(this, obj);
- }
-
- public static bool Equals(object? objA, object? objB)
- {
- if (objA == objB)
- {
- return true;
- }
- if (objA == null || objB == null)
- {
- return false;
- }
- return objA.Equals(objB);
- }
-
- [NonVersionable]
- public static bool ReferenceEquals(object? objA, object? objB)
- {
- return objA == objB;
- }
-
- // GetHashCode is intended to serve as a hash function for this object.
- // Based on the contents of the object, the hash function will return a suitable
- // value with a relatively random distribution over the various inputs.
- //
- // The default implementation returns the sync block index for this instance.
- // Calling it on the same object multiple times will return the same value, so
- // it will technically meet the needs of a hash function, but it's less than ideal.
- // Objects (& especially value classes) should override this method.
- public virtual int GetHashCode()
- {
- return RuntimeHelpers.GetHashCode(this);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ObjectDisposedException.cs b/netcore/System.Private.CoreLib/shared/System/ObjectDisposedException.cs
deleted file mode 100644
index 41441c0e48c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ObjectDisposedException.cs
+++ /dev/null
@@ -1,74 +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 System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-
-namespace System
-{
- /// <summary>
- /// The exception that is thrown when accessing an object that was disposed.
- /// </summary>
- [Serializable]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ObjectDisposedException : InvalidOperationException
- {
- private readonly string? _objectName;
-
- // This constructor should only be called by the EE (COMPlusThrow)
- private ObjectDisposedException() :
- this(null, SR.ObjectDisposed_Generic)
- {
- }
-
- public ObjectDisposedException(string? objectName) :
- this(objectName, SR.ObjectDisposed_Generic)
- {
- }
-
- public ObjectDisposedException(string? objectName, string? message) : base(message)
- {
- HResult = HResults.COR_E_OBJECTDISPOSED;
- _objectName = objectName;
- }
-
- public ObjectDisposedException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_OBJECTDISPOSED;
- }
-
- protected ObjectDisposedException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- _objectName = info.GetString("ObjectName");
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("ObjectName", ObjectName, typeof(string));
- }
-
- /// <summary>
- /// Gets the text for the message for this exception.
- /// </summary>
- public override string Message
- {
- get
- {
- string name = ObjectName;
- if (string.IsNullOrEmpty(name))
- {
- return base.Message;
- }
-
- string objectDisposed = SR.Format(SR.ObjectDisposed_ObjectName_Name, name);
- return base.Message + Environment.NewLineConst + objectDisposed;
- }
- }
-
- public string ObjectName => _objectName ?? string.Empty;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ObsoleteAttribute.cs b/netcore/System.Private.CoreLib/shared/System/ObsoleteAttribute.cs
deleted file mode 100644
index 94a26dd9507..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ObsoleteAttribute.cs
+++ /dev/null
@@ -1,52 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Attribute for functions, etc that will be removed.
-**
-**
-===========================================================*/
-
-namespace System
-{
- // This attribute is attached to members that are not to be used any longer.
- // Message is some human readable explanation of what to use
- // Error indicates if the compiler should treat usage of such a method as an
- // error. (this would be used if the actual implementation of the obsolete
- // method's implementation had changed).
- //
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum |
- AttributeTargets.Interface | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Delegate,
- Inherited = false)]
- public sealed class ObsoleteAttribute : Attribute
- {
- private readonly string? _message;
- private readonly bool _error;
-
- public ObsoleteAttribute()
- {
- _message = null;
- _error = false;
- }
-
- public ObsoleteAttribute(string? message)
- {
- _message = message;
- _error = false;
- }
-
- public ObsoleteAttribute(string? message, bool error)
- {
- _message = message;
- _error = error;
- }
-
- public string? Message => _message;
-
- public bool IsError => _error;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/OperatingSystem.cs b/netcore/System.Private.CoreLib/shared/System/OperatingSystem.cs
deleted file mode 100644
index 952c05b852f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/OperatingSystem.cs
+++ /dev/null
@@ -1,83 +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 System.Diagnostics;
-using System.Runtime.Serialization;
-
-namespace System
-{
- public sealed class OperatingSystem : ISerializable, ICloneable
- {
- private readonly Version _version;
- private readonly PlatformID _platform;
- private readonly string? _servicePack;
- private string? _versionString;
-
- public OperatingSystem(PlatformID platform, Version version) : this(platform, version, null)
- {
- }
-
- internal OperatingSystem(PlatformID platform, Version version, string? servicePack)
- {
- if (platform < PlatformID.Win32S || platform > PlatformID.MacOSX)
- {
- throw new ArgumentOutOfRangeException(nameof(platform), platform, SR.Format(SR.Arg_EnumIllegalVal, platform));
- }
-
- if (version == null)
- {
- throw new ArgumentNullException(nameof(version));
- }
-
- _platform = platform;
- _version = version;
- _servicePack = servicePack;
- }
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- public PlatformID Platform => _platform;
-
- public string ServicePack => _servicePack ?? string.Empty;
-
- public Version Version => _version;
-
- public object Clone() => new OperatingSystem(_platform, _version, _servicePack);
-
- public override string ToString() => VersionString;
-
- public string VersionString
- {
- get
- {
- if (_versionString == null)
- {
- string os;
- switch (_platform)
- {
- case PlatformID.Win32S: os = "Microsoft Win32S "; break;
- case PlatformID.Win32Windows: os = (_version.Major > 4 || (_version.Major == 4 && _version.Minor > 0)) ? "Microsoft Windows 98 " : "Microsoft Windows 95 "; break;
- case PlatformID.Win32NT: os = "Microsoft Windows NT "; break;
- case PlatformID.WinCE: os = "Microsoft Windows CE "; break;
- case PlatformID.Unix: os = "Unix "; break;
- case PlatformID.Xbox: os = "Xbox "; break;
- case PlatformID.MacOSX: os = "Mac OS X "; break;
- default:
- Debug.Fail($"Unknown platform {_platform}");
- os = "<unknown> "; break;
- }
-
- _versionString = string.IsNullOrEmpty(_servicePack) ?
- os + _version.ToString() :
- os + _version.ToString(3) + " " + _servicePack;
- }
-
- return _versionString;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/OperationCanceledException.cs b/netcore/System.Private.CoreLib/shared/System/OperationCanceledException.cs
deleted file mode 100644
index 6eb8510eeb0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/OperationCanceledException.cs
+++ /dev/null
@@ -1,73 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Exception for cancelled IO requests.
-**
-**
-===========================================================*/
-
-using System.Runtime.Serialization;
-using System.Threading;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class OperationCanceledException : SystemException
- {
- [NonSerialized]
- private CancellationToken _cancellationToken;
-
- public CancellationToken CancellationToken
- {
- get => _cancellationToken;
- private set => _cancellationToken = value;
- }
-
- public OperationCanceledException()
- : base(SR.OperationCanceled)
- {
- HResult = HResults.COR_E_OPERATIONCANCELED;
- }
-
- public OperationCanceledException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_OPERATIONCANCELED;
- }
-
- public OperationCanceledException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_OPERATIONCANCELED;
- }
-
-
- public OperationCanceledException(CancellationToken token)
- : this()
- {
- CancellationToken = token;
- }
-
- public OperationCanceledException(string? message, CancellationToken token)
- : this(message)
- {
- CancellationToken = token;
- }
-
- public OperationCanceledException(string? message, Exception? innerException, CancellationToken token)
- : this(message, innerException)
- {
- CancellationToken = token;
- }
-
- protected OperationCanceledException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/OutOfMemoryException.cs b/netcore/System.Private.CoreLib/shared/System/OutOfMemoryException.cs
deleted file mode 100644
index 0a079959343..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/OutOfMemoryException.cs
+++ /dev/null
@@ -1,43 +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 System.Runtime.Serialization;
-
-namespace System
-{
- /// <summary>
- /// The exception class for OOM.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class OutOfMemoryException : SystemException
- {
- public OutOfMemoryException() : base(
-#if CORECLR
- GetMessageFromNativeResources(ExceptionMessageKind.OutOfMemory)
-#else
- SR.Arg_OutOfMemoryException
-#endif
- )
- {
- HResult = HResults.COR_E_OUTOFMEMORY;
- }
-
- public OutOfMemoryException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_OUTOFMEMORY;
- }
-
- public OutOfMemoryException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_OUTOFMEMORY;
- }
-
- protected OutOfMemoryException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/OverflowException.cs b/netcore/System.Private.CoreLib/shared/System/OverflowException.cs
deleted file mode 100644
index 34e63b8e717..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/OverflowException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class for Arithmetic Overflows.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class OverflowException : ArithmeticException
- {
- public OverflowException()
- : base(SR.Arg_OverflowException)
- {
- HResult = HResults.COR_E_OVERFLOW;
- }
-
- public OverflowException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_OVERFLOW;
- }
-
- public OverflowException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_OVERFLOW;
- }
-
- protected OverflowException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ParamArrayAttribute.cs b/netcore/System.Private.CoreLib/shared/System/ParamArrayAttribute.cs
deleted file mode 100644
index d3c3d46d569..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ParamArrayAttribute.cs
+++ /dev/null
@@ -1,21 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Attribute for multiple parameters.
-**
-**
-=============================================================================*/
-
-namespace System
-{
- [AttributeUsage(AttributeTargets.Parameter, Inherited = true, AllowMultiple = false)]
- public sealed class ParamArrayAttribute : Attribute
- {
- public ParamArrayAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ParamsArray.cs b/netcore/System.Private.CoreLib/shared/System/ParamsArray.cs
deleted file mode 100644
index 9ab86fa5167..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ParamsArray.cs
+++ /dev/null
@@ -1,76 +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.
-
-namespace System
-{
- internal readonly struct ParamsArray
- {
- // Sentinel fixed-length arrays eliminate the need for a "count" field keeping this
- // struct down to just 4 fields. These are only used for their "Length" property,
- // that is, their elements are never set or referenced.
- private static readonly object?[] s_oneArgArray = new object?[1];
- private static readonly object?[] s_twoArgArray = new object?[2];
- private static readonly object?[] s_threeArgArray = new object?[3];
-
- private readonly object? _arg0;
- private readonly object? _arg1;
- private readonly object? _arg2;
-
- // After construction, the first three elements of this array will never be accessed
- // because the indexer will retrieve those values from arg0, arg1, and arg2.
- private readonly object?[] _args;
-
- public ParamsArray(object? arg0)
- {
- _arg0 = arg0;
- _arg1 = null;
- _arg2 = null;
-
- // Always assign this.args to make use of its "Length" property
- _args = s_oneArgArray;
- }
-
- public ParamsArray(object? arg0, object? arg1)
- {
- _arg0 = arg0;
- _arg1 = arg1;
- _arg2 = null;
-
- // Always assign this.args to make use of its "Length" property
- _args = s_twoArgArray;
- }
-
- public ParamsArray(object? arg0, object? arg1, object? arg2)
- {
- _arg0 = arg0;
- _arg1 = arg1;
- _arg2 = arg2;
-
- // Always assign this.args to make use of its "Length" property
- _args = s_threeArgArray;
- }
-
- public ParamsArray(object?[] args)
- {
- int len = args.Length;
- _arg0 = len > 0 ? args[0] : null;
- _arg1 = len > 1 ? args[1] : null;
- _arg2 = len > 2 ? args[2] : null;
- _args = args;
- }
-
- public int Length => _args.Length;
-
- public object? this[int index] => index == 0 ? _arg0 : GetAtSlow(index);
-
- private object? GetAtSlow(int index)
- {
- if (index == 1)
- return _arg1;
- if (index == 2)
- return _arg2;
- return _args[index];
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ParseNumbers.cs b/netcore/System.Private.CoreLib/shared/System/ParseNumbers.cs
deleted file mode 100644
index 732dae9a659..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ParseNumbers.cs
+++ /dev/null
@@ -1,659 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- /// <summary>Methods for parsing numbers and strings.</summary>
- internal static class ParseNumbers
- {
- internal const int LeftAlign = 0x0001;
- internal const int RightAlign = 0x0004;
- internal const int PrefixSpace = 0x0008;
- internal const int PrintSign = 0x0010;
- internal const int PrintBase = 0x0020;
- internal const int PrintAsI1 = 0x0040;
- internal const int PrintAsI2 = 0x0080;
- internal const int PrintAsI4 = 0x0100;
- internal const int TreatAsUnsigned = 0x0200;
- internal const int TreatAsI1 = 0x0400;
- internal const int TreatAsI2 = 0x0800;
- internal const int IsTight = 0x1000;
- internal const int NoSpace = 0x2000;
- internal const int PrintRadixBase = 0x4000;
-
- private const int MinRadix = 2;
- private const int MaxRadix = 36;
-
- public static unsafe long StringToLong(ReadOnlySpan<char> s, int radix, int flags)
- {
- int pos = 0;
- return StringToLong(s, radix, flags, ref pos);
- }
-
- public static long StringToLong(ReadOnlySpan<char> s, int radix, int flags, ref int currPos)
- {
- int i = currPos;
-
- // Do some radix checking.
- // A radix of -1 says to use whatever base is spec'd on the number.
- // Parse in Base10 until we figure out what the base actually is.
- int r = (-1 == radix) ? 10 : radix;
-
- if (r != 2 && r != 10 && r != 8 && r != 16)
- throw new ArgumentException(SR.Arg_InvalidBase, nameof(radix));
-
- int length = s.Length;
-
- if (i < 0 || i >= length)
- throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Index);
-
- // Get rid of the whitespace and then check that we've still got some digits to parse.
- if (((flags & IsTight) == 0) && ((flags & NoSpace) == 0))
- {
- EatWhiteSpace(s, ref i);
- if (i == length)
- throw new FormatException(SR.Format_EmptyInputString);
- }
-
- // Check for a sign
- int sign = 1;
- if (s[i] == '-')
- {
- if (r != 10)
- throw new ArgumentException(SR.Arg_CannotHaveNegativeValue);
-
- if ((flags & TreatAsUnsigned) != 0)
- throw new OverflowException(SR.Overflow_NegativeUnsigned);
-
- sign = -1;
- i++;
- }
- else if (s[i] == '+')
- {
- i++;
- }
-
- if ((radix == -1 || radix == 16) && (i + 1 < length) && s[i] == '0')
- {
- if (s[i + 1] == 'x' || s[i + 1] == 'X')
- {
- r = 16;
- i += 2;
- }
- }
-
- int grabNumbersStart = i;
- long result = GrabLongs(r, s, ref i, (flags & TreatAsUnsigned) != 0);
-
- // Check if they passed us a string with no parsable digits.
- if (i == grabNumbersStart)
- throw new FormatException(SR.Format_NoParsibleDigits);
-
- if ((flags & IsTight) != 0)
- {
- // If we've got effluvia left at the end of the string, complain.
- if (i < length)
- throw new FormatException(SR.Format_ExtraJunkAtEnd);
- }
-
- // Put the current index back into the correct place.
- currPos = i;
-
- // Return the value properly signed.
- if ((ulong)result == 0x8000000000000000 && sign == 1 && r == 10 && ((flags & TreatAsUnsigned) == 0))
- Number.ThrowOverflowException(TypeCode.Int64);
-
- if (r == 10)
- {
- result *= sign;
- }
-
- return result;
- }
-
- public static int StringToInt(ReadOnlySpan<char> s, int radix, int flags)
- {
- int pos = 0;
- return StringToInt(s, radix, flags, ref pos);
- }
-
- public static int StringToInt(ReadOnlySpan<char> s, int radix, int flags, ref int currPos)
- {
- // They're requied to tell me where to start parsing.
- int i = currPos;
-
- // Do some radix checking.
- // A radix of -1 says to use whatever base is spec'd on the number.
- // Parse in Base10 until we figure out what the base actually is.
- int r = (-1 == radix) ? 10 : radix;
-
- if (r != 2 && r != 10 && r != 8 && r != 16)
- throw new ArgumentException(SR.Arg_InvalidBase, nameof(radix));
-
- int length = s.Length;
-
- if (i < 0 || i >= length)
- throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Index);
-
- // Get rid of the whitespace and then check that we've still got some digits to parse.
- if (((flags & IsTight) == 0) && ((flags & NoSpace) == 0))
- {
- EatWhiteSpace(s, ref i);
- if (i == length)
- throw new FormatException(SR.Format_EmptyInputString);
- }
-
- // Check for a sign
- int sign = 1;
- if (s[i] == '-')
- {
- if (r != 10)
- throw new ArgumentException(SR.Arg_CannotHaveNegativeValue);
-
- if ((flags & TreatAsUnsigned) != 0)
- throw new OverflowException(SR.Overflow_NegativeUnsigned);
-
- sign = -1;
- i++;
- }
- else if (s[i] == '+')
- {
- i++;
- }
-
- // Consume the 0x if we're in an unknown base or in base-16.
- if ((radix == -1 || radix == 16) && (i + 1 < length) && s[i] == '0')
- {
- if (s[i + 1] == 'x' || s[i + 1] == 'X')
- {
- r = 16;
- i += 2;
- }
- }
-
- int grabNumbersStart = i;
- int result = GrabInts(r, s, ref i, (flags & TreatAsUnsigned) != 0);
-
- // Check if they passed us a string with no parsable digits.
- if (i == grabNumbersStart)
- throw new FormatException(SR.Format_NoParsibleDigits);
-
- if ((flags & IsTight) != 0)
- {
- // If we've got effluvia left at the end of the string, complain.
- if (i < length)
- throw new FormatException(SR.Format_ExtraJunkAtEnd);
- }
-
- // Put the current index back into the correct place.
- currPos = i;
-
- // Return the value properly signed.
- if ((flags & TreatAsI1) != 0)
- {
- if ((uint)result > 0xFF)
- Number.ThrowOverflowException(TypeCode.SByte);
- }
- else if ((flags & TreatAsI2) != 0)
- {
- if ((uint)result > 0xFFFF)
- Number.ThrowOverflowException(TypeCode.Int16);
- }
- else if ((uint)result == 0x80000000 && sign == 1 && r == 10 && ((flags & TreatAsUnsigned) == 0))
- {
- Number.ThrowOverflowException(TypeCode.Int32);
- }
-
- if (r == 10)
- {
- result *= sign;
- }
-
- return result;
- }
-
- public static string IntToString(int n, int radix, int width, char paddingChar, int flags)
- {
- Span<char> buffer = stackalloc char[66]; // Longest possible string length for an integer in binary notation with prefix
-
- if (radix < MinRadix || radix > MaxRadix)
- throw new ArgumentException(SR.Arg_InvalidBase, nameof(radix));
-
- // If the number is negative, make it positive and remember the sign.
- // If the number is MIN_VALUE, this will still be negative, so we'll have to
- // special case this later.
- bool isNegative = false;
- uint l;
- if (n < 0)
- {
- isNegative = true;
-
- // For base 10, write out -num, but other bases write out the
- // 2's complement bit pattern
- l = (10 == radix) ? (uint)-n : (uint)n;
- }
- else
- {
- l = (uint)n;
- }
-
- // The conversion to a uint will sign extend the number. In order to ensure
- // that we only get as many bits as we expect, we chop the number.
- if ((flags & PrintAsI1) != 0)
- {
- l &= 0xFF;
- }
- else if ((flags & PrintAsI2) != 0)
- {
- l &= 0xFFFF;
- }
-
- // Special case the 0.
- int index;
- if (0 == l)
- {
- buffer[0] = '0';
- index = 1;
- }
- else
- {
- index = 0;
- for (int i = 0; i < buffer.Length; i++) // for (...;i<buffer.Length;...) loop instead of do{...}while(l!=0) to help JIT eliminate span bounds checks
- {
- uint div = l / (uint)radix; // TODO https://github.com/dotnet/coreclr/issues/3439
- uint charVal = l - (div * (uint)radix);
- l = div;
-
- buffer[i] = (charVal < 10) ?
- (char)(charVal + '0') :
- (char)(charVal + 'a' - 10);
-
- if (l == 0)
- {
- index = i + 1;
- break;
- }
- }
-
- Debug.Assert(l == 0, $"Expected {l} == 0");
- }
-
- // If they want the base, append that to the string (in reverse order)
- if (radix != 10 && ((flags & PrintBase) != 0))
- {
- if (16 == radix)
- {
- buffer[index++] = 'x';
- buffer[index++] = '0';
- }
- else if (8 == radix)
- {
- buffer[index++] = '0';
- }
- }
-
- if (10 == radix)
- {
- // If it was negative, append the sign, else if they requested, add the '+'.
- // If they requested a leading space, put it on.
- if (isNegative)
- {
- buffer[index++] = '-';
- }
- else if ((flags & PrintSign) != 0)
- {
- buffer[index++] = '+';
- }
- else if ((flags & PrefixSpace) != 0)
- {
- buffer[index++] = ' ';
- }
- }
-
- // Figure out the size of and allocate the resulting string
- string result = string.FastAllocateString(Math.Max(width, index));
- unsafe
- {
- // Put the characters into the string in reverse order.
- // Fill the remaining space, if there is any, with the correct padding character.
- fixed (char* resultPtr = result)
- {
- char* p = resultPtr;
- int padding = result.Length - index;
-
- if ((flags & LeftAlign) != 0)
- {
- for (int i = 0; i < padding; i++)
- {
- *p++ = paddingChar;
- }
-
- for (int i = 0; i < index; i++)
- {
- *p++ = buffer[index - i - 1];
- }
- }
- else
- {
- for (int i = 0; i < index; i++)
- {
- *p++ = buffer[index - i - 1];
- }
-
- for (int i = 0; i < padding; i++)
- {
- *p++ = paddingChar;
- }
- }
-
- Debug.Assert((p - resultPtr) == result.Length, $"Expected {p - resultPtr} == {result.Length}");
- }
- }
- return result;
- }
-
- public static string LongToString(long n, int radix, int width, char paddingChar, int flags)
- {
- Span<char> buffer = stackalloc char[67]; // Longest possible string length for an integer in binary notation with prefix
-
- if (radix < MinRadix || radix > MaxRadix)
- throw new ArgumentException(SR.Arg_InvalidBase, nameof(radix));
-
- // If the number is negative, make it positive and remember the sign.
- ulong ul;
- bool isNegative = false;
- if (n < 0)
- {
- isNegative = true;
-
- // For base 10, write out -num, but other bases write out the
- // 2's complement bit pattern
- ul = (10 == radix) ? (ulong)(-n) : (ulong)n;
- }
- else
- {
- ul = (ulong)n;
- }
-
- if ((flags & PrintAsI1) != 0)
- {
- ul &= 0xFF;
- }
- else if ((flags & PrintAsI2) != 0)
- {
- ul &= 0xFFFF;
- }
- else if ((flags & PrintAsI4) != 0)
- {
- ul &= 0xFFFFFFFF;
- }
-
- // Special case the 0.
- int index;
- if (0 == ul)
- {
- buffer[0] = '0';
- index = 1;
- }
- else
- {
- index = 0;
- for (int i = 0; i < buffer.Length; i++) // for loop instead of do{...}while(l!=0) to help JIT eliminate span bounds checks
- {
- ulong div = ul / (ulong)radix; // TODO https://github.com/dotnet/coreclr/issues/3439
- int charVal = (int)(ul - (div * (ulong)radix));
- ul = div;
-
- buffer[i] = (charVal < 10) ?
- (char)(charVal + '0') :
- (char)(charVal + 'a' - 10);
-
- if (ul == 0)
- {
- index = i + 1;
- break;
- }
- }
- Debug.Assert(ul == 0, $"Expected {ul} == 0");
- }
-
- // If they want the base, append that to the string (in reverse order)
- if (radix != 10 && ((flags & PrintBase) != 0))
- {
- if (16 == radix)
- {
- buffer[index++] = 'x';
- buffer[index++] = '0';
- }
- else if (8 == radix)
- {
- buffer[index++] = '0';
- }
- else if ((flags & PrintRadixBase) != 0)
- {
- buffer[index++] = '#';
- buffer[index++] = (char)((radix % 10) + '0');
- buffer[index++] = (char)((radix / 10) + '0');
- }
- }
-
- if (10 == radix)
- {
- // If it was negative, append the sign.
- if (isNegative)
- {
- buffer[index++] = '-';
- }
-
- // else if they requested, add the '+';
- else if ((flags & PrintSign) != 0)
- {
- buffer[index++] = '+';
- }
-
- // If they requested a leading space, put it on.
- else if ((flags & PrefixSpace) != 0)
- {
- buffer[index++] = ' ';
- }
- }
-
- // Figure out the size of and allocate the resulting string
- string result = string.FastAllocateString(Math.Max(width, index));
- unsafe
- {
- // Put the characters into the string in reverse order.
- // Fill the remaining space, if there is any, with the correct padding character.
- fixed (char* resultPtr = result)
- {
- char* p = resultPtr;
- int padding = result.Length - index;
-
- if ((flags & LeftAlign) != 0)
- {
- for (int i = 0; i < padding; i++)
- {
- *p++ = paddingChar;
- }
-
- for (int i = 0; i < index; i++)
- {
- *p++ = buffer[index - i - 1];
- }
- }
- else
- {
- for (int i = 0; i < index; i++)
- {
- *p++ = buffer[index - i - 1];
- }
-
- for (int i = 0; i < padding; i++)
- {
- *p++ = paddingChar;
- }
- }
-
- Debug.Assert((p - resultPtr) == result.Length, $"Expected {p - resultPtr} == {result.Length}");
- }
- }
- return result;
- }
-
- private static void EatWhiteSpace(ReadOnlySpan<char> s, ref int i)
- {
- int localIndex = i;
- for (; localIndex < s.Length && char.IsWhiteSpace(s[localIndex]); localIndex++) ;
- i = localIndex;
- }
-
- private static long GrabLongs(int radix, ReadOnlySpan<char> s, ref int i, bool isUnsigned)
- {
- ulong result = 0;
- ulong maxVal;
-
- // Allow all non-decimal numbers to set the sign bit.
- if (radix == 10 && !isUnsigned)
- {
- maxVal = 0x7FFFFFFFFFFFFFFF / 10;
-
- // Read all of the digits and convert to a number
- while (i < s.Length && IsDigit(s[i], radix, out int value))
- {
- // Check for overflows - this is sufficient & correct.
- if (result > maxVal || ((long)result) < 0)
- {
- Number.ThrowOverflowException(TypeCode.Int64);
- }
-
- result = result * (ulong)radix + (ulong)value;
- i++;
- }
-
- if ((long)result < 0 && result != 0x8000000000000000)
- {
- Number.ThrowOverflowException(TypeCode.Int64);
- }
- }
- else
- {
- Debug.Assert(radix == 2 || radix == 8 || radix == 10 || radix == 16);
- maxVal =
- radix == 10 ? 0xffffffffffffffff / 10 :
- radix == 16 ? 0xffffffffffffffff / 16 :
- radix == 8 ? 0xffffffffffffffff / 8 :
- 0xffffffffffffffff / 2;
-
- // Read all of the digits and convert to a number
- while (i < s.Length && IsDigit(s[i], radix, out int value))
- {
- // Check for overflows - this is sufficient & correct.
- if (result > maxVal)
- {
- Number.ThrowOverflowException(TypeCode.UInt64);
- }
-
- ulong temp = result * (ulong)radix + (ulong)value;
-
- if (temp < result) // this means overflow as well
- {
- Number.ThrowOverflowException(TypeCode.UInt64);
- }
-
- result = temp;
- i++;
- }
- }
-
- return (long)result;
- }
-
- private static int GrabInts(int radix, ReadOnlySpan<char> s, ref int i, bool isUnsigned)
- {
- uint result = 0;
- uint maxVal;
-
- // Allow all non-decimal numbers to set the sign bit.
- if (radix == 10 && !isUnsigned)
- {
- maxVal = (0x7FFFFFFF / 10);
-
- // Read all of the digits and convert to a number
- while (i < s.Length && IsDigit(s[i], radix, out int value))
- {
- // Check for overflows - this is sufficient & correct.
- if (result > maxVal || (int)result < 0)
- {
- Number.ThrowOverflowException(TypeCode.Int32);
- }
- result = result * (uint)radix + (uint)value;
- i++;
- }
- if ((int)result < 0 && result != 0x80000000)
- {
- Number.ThrowOverflowException(TypeCode.Int32);
- }
- }
- else
- {
- Debug.Assert(radix == 2 || radix == 8 || radix == 10 || radix == 16);
- maxVal =
- radix == 10 ? 0xffffffff / 10 :
- radix == 16 ? 0xffffffff / 16 :
- radix == 8 ? 0xffffffff / 8 :
- 0xffffffff / 2;
-
- // Read all of the digits and convert to a number
- while (i < s.Length && IsDigit(s[i], radix, out int value))
- {
- // Check for overflows - this is sufficient & correct.
- if (result > maxVal)
- {
- Number.ThrowOverflowException(TypeCode.UInt32);
- }
-
- uint temp = result * (uint)radix + (uint)value;
-
- if (temp < result) // this means overflow as well
- {
- Number.ThrowOverflowException(TypeCode.UInt32);
- }
-
- result = temp;
- i++;
- }
- }
-
- return (int)result;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsDigit(char c, int radix, out int result)
- {
- int tmp;
- if ((uint)(c - '0') <= 9)
- {
- result = tmp = c - '0';
- }
- else if ((uint)(c - 'A') <= 'Z' - 'A')
- {
- result = tmp = c - 'A' + 10;
- }
- else if ((uint)(c - 'a') <= 'z' - 'a')
- {
- result = tmp = c - 'a' + 10;
- }
- else
- {
- result = -1;
- return false;
- }
-
- return tmp < radix;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/PasteArguments.Unix.cs b/netcore/System.Private.CoreLib/shared/System/PasteArguments.Unix.cs
deleted file mode 100644
index 1a4d92850f8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/PasteArguments.Unix.cs
+++ /dev/null
@@ -1,28 +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 System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System
-{
- internal static partial class PasteArguments
- {
- /// <summary>
- /// Repastes a set of arguments into a linear string that parses back into the originals under pre- or post-2008 VC parsing rules.
- /// On Unix: the rules for parsing the executable name (argv[0]) are ignored.
- /// </summary>
- internal static string Paste(IEnumerable<string> arguments, bool pasteFirstArgumentUsingArgV0Rules)
- {
- var stringBuilder = new StringBuilder();
- foreach (string argument in arguments)
- {
- AppendArgument(stringBuilder, argument);
- }
- return stringBuilder.ToString();
- }
-
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/PasteArguments.Windows.cs b/netcore/System.Private.CoreLib/shared/System/PasteArguments.Windows.cs
deleted file mode 100644
index e760a401658..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/PasteArguments.Windows.cs
+++ /dev/null
@@ -1,64 +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 System.Collections.Generic;
-using System.Text;
-
-namespace System
-{
- internal static partial class PasteArguments
- {
- /// <summary>
- /// Repastes a set of arguments into a linear string that parses back into the originals under pre- or post-2008 VC parsing rules.
- /// The rules for parsing the executable name (argv[0]) are special, so you must indicate whether the first argument actually is argv[0].
- /// </summary>
- internal static string Paste(IEnumerable<string> arguments, bool pasteFirstArgumentUsingArgV0Rules)
- {
- var stringBuilder = new StringBuilder();
-
- foreach (string argument in arguments)
- {
- if (pasteFirstArgumentUsingArgV0Rules)
- {
- pasteFirstArgumentUsingArgV0Rules = false;
-
- // Special rules for argv[0]
- // - Backslash is a normal character.
- // - Quotes used to include whitespace characters.
- // - Parsing ends at first whitespace outside quoted region.
- // - No way to get a literal quote past the parser.
-
- bool hasWhitespace = false;
- foreach (char c in argument)
- {
- if (c == Quote)
- {
- throw new ApplicationException("The argv[0] argument cannot include a double quote.");
- }
- if (char.IsWhiteSpace(c))
- {
- hasWhitespace = true;
- }
- }
- if (argument.Length == 0 || hasWhitespace)
- {
- stringBuilder.Append(Quote);
- stringBuilder.Append(argument);
- stringBuilder.Append(Quote);
- }
- else
- {
- stringBuilder.Append(argument);
- }
- }
- else
- {
- AppendArgument(stringBuilder, argument);
- }
- }
-
- return stringBuilder.ToString();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/PasteArguments.cs b/netcore/System.Private.CoreLib/shared/System/PasteArguments.cs
deleted file mode 100644
index c088fd4eb73..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/PasteArguments.cs
+++ /dev/null
@@ -1,99 +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 System.Text;
-
-namespace System
-{
- internal static partial class PasteArguments
- {
- internal static void AppendArgument(StringBuilder stringBuilder, string argument)
- {
- if (stringBuilder.Length != 0)
- {
- stringBuilder.Append(' ');
- }
-
- // Parsing rules for non-argv[0] arguments:
- // - Backslash is a normal character except followed by a quote.
- // - 2N backslashes followed by a quote ==> N literal backslashes followed by unescaped quote
- // - 2N+1 backslashes followed by a quote ==> N literal backslashes followed by a literal quote
- // - Parsing stops at first whitespace outside of quoted region.
- // - (post 2008 rule): A closing quote followed by another quote ==> literal quote, and parsing remains in quoting mode.
- if (argument.Length != 0 && ContainsNoWhitespaceOrQuotes(argument))
- {
- // Simple case - no quoting or changes needed.
- stringBuilder.Append(argument);
- }
- else
- {
- stringBuilder.Append(Quote);
- int idx = 0;
- while (idx < argument.Length)
- {
- char c = argument[idx++];
- if (c == Backslash)
- {
- int numBackSlash = 1;
- while (idx < argument.Length && argument[idx] == Backslash)
- {
- idx++;
- numBackSlash++;
- }
-
- if (idx == argument.Length)
- {
- // We'll emit an end quote after this so must double the number of backslashes.
- stringBuilder.Append(Backslash, numBackSlash * 2);
- }
- else if (argument[idx] == Quote)
- {
- // Backslashes will be followed by a quote. Must double the number of backslashes.
- stringBuilder.Append(Backslash, numBackSlash * 2 + 1);
- stringBuilder.Append(Quote);
- idx++;
- }
- else
- {
- // Backslash will not be followed by a quote, so emit as normal characters.
- stringBuilder.Append(Backslash, numBackSlash);
- }
-
- continue;
- }
-
- if (c == Quote)
- {
- // Escape the quote so it appears as a literal. This also guarantees that we won't end up generating a closing quote followed
- // by another quote (which parses differently pre-2008 vs. post-2008.)
- stringBuilder.Append(Backslash);
- stringBuilder.Append(Quote);
- continue;
- }
-
- stringBuilder.Append(c);
- }
-
- stringBuilder.Append(Quote);
- }
- }
-
- private static bool ContainsNoWhitespaceOrQuotes(string s)
- {
- for (int i = 0; i < s.Length; i++)
- {
- char c = s[i];
- if (char.IsWhiteSpace(c) || c == Quote)
- {
- return false;
- }
- }
-
- return true;
- }
-
- private const char Quote = '\"';
- private const char Backslash = '\\';
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/PlatformID.cs b/netcore/System.Private.CoreLib/shared/System/PlatformID.cs
deleted file mode 100644
index 1e0a688ba69..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/PlatformID.cs
+++ /dev/null
@@ -1,19 +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 System.ComponentModel;
-
-namespace System
-{
- public enum PlatformID
- {
- [EditorBrowsable(EditorBrowsableState.Never)] Win32S = 0,
- [EditorBrowsable(EditorBrowsableState.Never)] Win32Windows = 1,
- Win32NT = 2,
- [EditorBrowsable(EditorBrowsableState.Never)] WinCE = 3,
- Unix = 4,
- [EditorBrowsable(EditorBrowsableState.Never)] Xbox = 5,
- [EditorBrowsable(EditorBrowsableState.Never)] MacOSX = 6
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/PlatformNotSupportedException.cs b/netcore/System.Private.CoreLib/shared/System/PlatformNotSupportedException.cs
deleted file mode 100644
index 7e3f9ae0111..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/PlatformNotSupportedException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: To handle features that don't run on particular platforms
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class PlatformNotSupportedException : NotSupportedException
- {
- public PlatformNotSupportedException()
- : base(SR.Arg_PlatformNotSupported)
- {
- HResult = HResults.COR_E_PLATFORMNOTSUPPORTED;
- }
-
- public PlatformNotSupportedException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_PLATFORMNOTSUPPORTED;
- }
-
- public PlatformNotSupportedException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_PLATFORMNOTSUPPORTED;
- }
-
- protected PlatformNotSupportedException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Progress.cs b/netcore/System.Private.CoreLib/shared/System/Progress.cs
deleted file mode 100644
index e7535bcb903..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Progress.cs
+++ /dev/null
@@ -1,103 +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 System.Threading;
-using System.Diagnostics;
-
-namespace System
-{
- /// <summary>
- /// Provides an IProgress{T} that invokes callbacks for each reported progress value.
- /// </summary>
- /// <typeparam name="T">Specifies the type of the progress report value.</typeparam>
- /// <remarks>
- /// Any handler provided to the constructor or event handlers registered with
- /// the <see cref="ProgressChanged"/> event are invoked through a
- /// <see cref="System.Threading.SynchronizationContext"/> instance captured
- /// when the instance is constructed. If there is no current SynchronizationContext
- /// at the time of construction, the callbacks will be invoked on the ThreadPool.
- /// </remarks>
- public class Progress<T> : IProgress<T>
- {
- /// <summary>The synchronization context captured upon construction. This will never be null.</summary>
- private readonly SynchronizationContext _synchronizationContext;
- /// <summary>The handler specified to the constructor. This may be null.</summary>
- private readonly Action<T>? _handler;
- /// <summary>A cached delegate used to post invocation to the synchronization context.</summary>
- private readonly SendOrPostCallback _invokeHandlers;
-
- /// <summary>Initializes the <see cref="Progress{T}"/>.</summary>
- public Progress()
- {
- // Capture the current synchronization context.
- // If there is no current context, we use a default instance targeting the ThreadPool.
- _synchronizationContext = SynchronizationContext.Current ?? ProgressStatics.DefaultContext;
- Debug.Assert(_synchronizationContext != null);
- _invokeHandlers = new SendOrPostCallback(InvokeHandlers);
- }
-
- /// <summary>Initializes the <see cref="Progress{T}"/> with the specified callback.</summary>
- /// <param name="handler">
- /// A handler to invoke for each reported progress value. This handler will be invoked
- /// in addition to any delegates registered with the <see cref="ProgressChanged"/> event.
- /// Depending on the <see cref="System.Threading.SynchronizationContext"/> instance captured by
- /// the <see cref="Progress{T}"/> at construction, it's possible that this handler instance
- /// could be invoked concurrently with itself.
- /// </param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="handler"/> is null (Nothing in Visual Basic).</exception>
- public Progress(Action<T> handler) : this()
- {
- _handler = handler ?? throw new ArgumentNullException(nameof(handler));
- }
-
- /// <summary>Raised for each reported progress value.</summary>
- /// <remarks>
- /// Handlers registered with this event will be invoked on the
- /// <see cref="System.Threading.SynchronizationContext"/> captured when the instance was constructed.
- /// </remarks>
- public event EventHandler<T>? ProgressChanged;
-
- /// <summary>Reports a progress change.</summary>
- /// <param name="value">The value of the updated progress.</param>
- protected virtual void OnReport(T value)
- {
- // If there's no handler, don't bother going through the sync context.
- // Inside the callback, we'll need to check again, in case
- // an event handler is removed between now and then.
- Action<T>? handler = _handler;
- EventHandler<T>? changedEvent = ProgressChanged;
- if (handler != null || changedEvent != null)
- {
- // Post the processing to the sync context.
- // (If T is a value type, it will get boxed here.)
- _synchronizationContext.Post(_invokeHandlers, value);
- }
- }
-
- /// <summary>Reports a progress change.</summary>
- /// <param name="value">The value of the updated progress.</param>
- void IProgress<T>.Report(T value) { OnReport(value); }
-
- /// <summary>Invokes the action and event callbacks.</summary>
- /// <param name="state">The progress value.</param>
- private void InvokeHandlers(object? state)
- {
- T value = (T)state!;
-
- Action<T>? handler = _handler;
- EventHandler<T>? changedEvent = ProgressChanged;
-
- handler?.Invoke(value);
- changedEvent?.Invoke(this, value);
- }
- }
-
- /// <summary>Holds static values for <see cref="Progress{T}"/>.</summary>
- /// <remarks>This avoids one static instance per type T.</remarks>
- internal static class ProgressStatics
- {
- /// <summary>A default synchronization context that targets the ThreadPool.</summary>
- internal static readonly SynchronizationContext DefaultContext = new SynchronizationContext();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Random.cs b/netcore/System.Private.CoreLib/shared/System/Random.cs
deleted file mode 100644
index 78dae72b261..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Random.cs
+++ /dev/null
@@ -1,256 +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.
-
-namespace System
-{
- public class Random
- {
- //
- // Private Constants
- //
- private const int MBIG = int.MaxValue;
- private const int MSEED = 161803398;
-
- //
- // Member Variables
- //
- private int _inext;
- private int _inextp;
- private readonly int[] _seedArray = new int[56];
-
- //
- // Public Constants
- //
-
- //
- // Native Declarations
- //
-
- //
- // Constructors
- //
-
- /*=========================================================================================
- **Action: Initializes a new instance of the Random class, using a default seed value
- ===========================================================================================*/
- public Random()
- : this(GenerateSeed())
- {
- }
-
- /*=========================================================================================
- **Action: Initializes a new instance of the Random class, using a specified seed value
- ===========================================================================================*/
- public Random(int Seed)
- {
- int ii = 0;
- int mj, mk;
-
- // Initialize our Seed array.
- int subtraction = (Seed == int.MinValue) ? int.MaxValue : Math.Abs(Seed);
- mj = MSEED - subtraction;
- _seedArray[55] = mj;
- mk = 1;
- for (int i = 1; i < 55; i++)
- { // Apparently the range [1..55] is special (Knuth) and so we're wasting the 0'th position.
- if ((ii += 21) >= 55) ii -= 55;
- _seedArray[ii] = mk;
- mk = mj - mk;
- if (mk < 0) mk += MBIG;
- mj = _seedArray[ii];
- }
- for (int k = 1; k < 5; k++)
- {
- for (int i = 1; i < 56; i++)
- {
- int n = i + 30;
- if (n >= 55) n -= 55;
- _seedArray[i] -= _seedArray[1 + n];
- if (_seedArray[i] < 0) _seedArray[i] += MBIG;
- }
- }
- _inext = 0;
- _inextp = 21;
- }
-
- //
- // Package Private Methods
- //
-
- /*====================================Sample====================================
- **Action: Return a new random number [0..1) and reSeed the Seed array.
- **Returns: A double [0..1)
- **Arguments: None
- **Exceptions: None
- ==============================================================================*/
- protected virtual double Sample()
- {
- // Including this division at the end gives us significantly improved
- // random number distribution.
- return InternalSample() * (1.0 / MBIG);
- }
-
- private int InternalSample()
- {
- int retVal;
- int locINext = _inext;
- int locINextp = _inextp;
-
- if (++locINext >= 56) locINext = 1;
- if (++locINextp >= 56) locINextp = 1;
-
- retVal = _seedArray[locINext] - _seedArray[locINextp];
-
- if (retVal == MBIG) retVal--;
- if (retVal < 0) retVal += MBIG;
-
- _seedArray[locINext] = retVal;
-
- _inext = locINext;
- _inextp = locINextp;
-
- return retVal;
- }
-
- [ThreadStatic]
- private static Random? t_threadRandom;
- private static readonly Random s_globalRandom = new Random(GenerateGlobalSeed());
-
- /*=====================================GenerateSeed=====================================
- **Returns: An integer that can be used as seed values for consecutively
- creating lots of instances on the same thread within a short period of time.
- ========================================================================================*/
- private static int GenerateSeed()
- {
- Random? rnd = t_threadRandom;
- if (rnd == null)
- {
- int seed;
- lock (s_globalRandom)
- {
- seed = s_globalRandom.Next();
- }
- rnd = new Random(seed);
- t_threadRandom = rnd;
- }
- return rnd.Next();
- }
-
- /*==================================GenerateGlobalSeed====================================
- **Action: Creates a number to use as global seed.
- **Returns: An integer that is safe to use as seed values for thread-local seed generators.
- ==========================================================================================*/
- private static unsafe int GenerateGlobalSeed()
- {
- int result;
- Interop.GetRandomBytes((byte*)&result, sizeof(int));
- return result;
- }
-
- //
- // Public Instance Methods
- //
-
- /*=====================================Next=====================================
- **Returns: An int [0..int.MaxValue)
- **Arguments: None
- **Exceptions: None.
- ==============================================================================*/
- public virtual int Next()
- {
- return InternalSample();
- }
-
- private double GetSampleForLargeRange()
- {
- // The distribution of double value returned by Sample
- // is not distributed well enough for a large range.
- // If we use Sample for a range [int.MinValue..int.MaxValue)
- // We will end up getting even numbers only.
-
- int result = InternalSample();
- // Note we can't use addition here. The distribution will be bad if we do that.
- bool negative = (InternalSample() % 2 == 0) ? true : false; // decide the sign based on second sample
- if (negative)
- {
- result = -result;
- }
- double d = result;
- d += (int.MaxValue - 1); // get a number in range [0 .. 2 * Int32MaxValue - 1)
- d /= 2 * (uint)int.MaxValue - 1;
- return d;
- }
-
- /*=====================================Next=====================================
- **Returns: An int [minvalue..maxvalue)
- **Arguments: minValue -- the least legal value for the Random number.
- ** maxValue -- One greater than the greatest legal return value.
- **Exceptions: None.
- ==============================================================================*/
- public virtual int Next(int minValue, int maxValue)
- {
- if (minValue > maxValue)
- {
- throw new ArgumentOutOfRangeException(nameof(minValue), SR.Format(SR.Argument_MinMaxValue, nameof(minValue), nameof(maxValue)));
- }
-
- long range = (long)maxValue - minValue;
- if (range <= int.MaxValue)
- {
- return (int)(Sample() * range) + minValue;
- }
- else
- {
- return (int)((long)(GetSampleForLargeRange() * range) + minValue);
- }
- }
-
- /*=====================================Next=====================================
- **Returns: An int [0..maxValue)
- **Arguments: maxValue -- One more than the greatest legal return value.
- **Exceptions: None.
- ==============================================================================*/
- public virtual int Next(int maxValue)
- {
- if (maxValue < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(maxValue), SR.Format(SR.ArgumentOutOfRange_MustBePositive, nameof(maxValue)));
- }
- return (int)(Sample() * maxValue);
- }
-
- /*=====================================Next=====================================
- **Returns: A double [0..1)
- **Arguments: None
- **Exceptions: None
- ==============================================================================*/
- public virtual double NextDouble()
- {
- return Sample();
- }
-
- /*==================================NextBytes===================================
- **Action: Fills the byte array with random bytes [0..0x7f]. The entire array is filled.
- **Returns:Void
- **Arguments: buffer -- the array to be filled.
- **Exceptions: None
- ==============================================================================*/
- public virtual void NextBytes(byte[] buffer)
- {
- if (buffer == null) throw new ArgumentNullException(nameof(buffer));
- for (int i = 0; i < buffer.Length; i++)
- {
- buffer[i] = (byte)InternalSample();
- }
- }
-
- public virtual void NextBytes(Span<byte> buffer)
- {
- for (int i = 0; i < buffer.Length; i++)
- {
- buffer[i] = (byte)Next();
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Range.cs b/netcore/System.Private.CoreLib/shared/System/Range.cs
deleted file mode 100644
index a45eda37ab5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Range.cs
+++ /dev/null
@@ -1,124 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- /// <summary>Represent a range has start and end indexes.</summary>
- /// <remarks>
- /// Range is used by the C# compiler to support the range syntax.
- /// <code>
- /// int[] someArray = new int[5] { 1, 2, 3, 4, 5 };
- /// int[] subArray1 = someArray[0..2]; // { 1, 2 }
- /// int[] subArray2 = someArray[1..^0]; // { 2, 3, 4, 5 }
- /// </code>
- /// </remarks>
- public readonly struct Range : IEquatable<Range>
- {
- /// <summary>Represent the inclusive start index of the Range.</summary>
- public Index Start { get; }
-
- /// <summary>Represent the exclusive end index of the Range.</summary>
- public Index End { get; }
-
- /// <summary>Construct a Range object using the start and end indexes.</summary>
- /// <param name="start">Represent the inclusive start index of the range.</param>
- /// <param name="end">Represent the exclusive end index of the range.</param>
- public Range(Index start, Index end)
- {
- Start = start;
- End = end;
- }
-
- /// <summary>Indicates whether the current Range 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 Range r &&
- r.Start.Equals(Start) &&
- r.End.Equals(End);
-
- /// <summary>Indicates whether the current Range object is equal to another Range object.</summary>
- /// <param name="other">An object to compare with this object</param>
- public bool Equals(Range other) => other.Start.Equals(Start) && other.End.Equals(End);
-
- /// <summary>Returns the hash code for this instance.</summary>
- public override int GetHashCode()
- {
- return HashCode.Combine(Start.GetHashCode(), End.GetHashCode());
- }
-
- /// <summary>Converts the value of the current Range object to its equivalent string representation.</summary>
- public override string ToString()
- {
- Span<char> span = stackalloc char[2 + (2 * 11)]; // 2 for "..", then for each index 1 for '^' and 10 for longest possible uint
- int charsWritten;
- int pos = 0;
-
- if (Start.IsFromEnd)
- {
- span[0] = '^';
- pos = 1;
- }
- bool formatted = ((uint)Start.Value).TryFormat(span.Slice(pos), out charsWritten);
- Debug.Assert(formatted);
- pos += charsWritten;
-
- span[pos++] = '.';
- span[pos++] = '.';
-
- if (End.IsFromEnd)
- {
- span[pos++] = '^';
- }
- formatted = ((uint)End.Value).TryFormat(span.Slice(pos), out charsWritten);
- Debug.Assert(formatted);
- pos += charsWritten;
-
- return new string(span.Slice(0, pos));
- }
-
- /// <summary>Create a Range object starting from start index to the end of the collection.</summary>
- public static Range StartAt(Index start) => new Range(start, Index.End);
-
- /// <summary>Create a Range object starting from first element in the collection to the end Index.</summary>
- public static Range EndAt(Index end) => new Range(Index.Start, end);
-
- /// <summary>Create a Range object starting from first element to the end.</summary>
- public static Range All => new Range(Index.Start, Index.End);
-
- /// <summary>Calculate the start offset and length of range object using a collection length.</summary>
- /// <param name="length">The length of the collection that the range will be used with. length has to be a positive value.</param>
- /// <remarks>
- /// For performance reason, we don't validate the input length parameter against negative values.
- /// It is expected Range will be used with collections which always have non negative length/count.
- /// We validate the range is inside the length scope though.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public (int Offset, int Length) GetOffsetAndLength(int length)
- {
- int start;
- Index startIndex = Start;
- if (startIndex.IsFromEnd)
- start = length - startIndex.Value;
- else
- start = startIndex.Value;
-
- int end;
- Index endIndex = End;
- if (endIndex.IsFromEnd)
- end = length - endIndex.Value;
- else
- end = endIndex.Value;
-
- if ((uint)end > (uint)length || (uint)start > (uint)end)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
- }
-
- return (start, end - start);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/RankException.cs b/netcore/System.Private.CoreLib/shared/System/RankException.cs
deleted file mode 100644
index 0f6176252f7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/RankException.cs
+++ /dev/null
@@ -1,45 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: For methods that are passed arrays with the wrong number of
-** dimensions.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class RankException : SystemException
- {
- public RankException()
- : base(SR.Arg_RankException)
- {
- HResult = HResults.COR_E_RANK;
- }
-
- public RankException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_RANK;
- }
-
- public RankException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_RANK;
- }
-
- protected RankException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ReadOnlyMemory.cs b/netcore/System.Private.CoreLib/shared/System/ReadOnlyMemory.cs
deleted file mode 100644
index 2510e0fe738..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ReadOnlyMemory.cs
+++ /dev/null
@@ -1,439 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-using EditorBrowsableAttribute = System.ComponentModel.EditorBrowsableAttribute;
-using EditorBrowsableState = System.ComponentModel.EditorBrowsableState;
-
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else // BIT64
-using nuint = System.UInt32;
-#endif // BIT64
-
-namespace System
-{
- /// <summary>
- /// Represents a contiguous region of memory, similar to <see cref="ReadOnlySpan{T}"/>.
- /// Unlike <see cref="ReadOnlySpan{T}"/>, it is not a byref-like type.
- /// </summary>
- [DebuggerTypeProxy(typeof(MemoryDebugView<>))]
- [DebuggerDisplay("{ToString(),raw}")]
- public readonly struct ReadOnlyMemory<T> : IEquatable<ReadOnlyMemory<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.
-
- // The highest order bit of _index is used to discern whether _object is a pre-pinned array.
- // (_index < 0) => _object is a pre-pinned array, so Pin() will not allocate a new GCHandle
- // (else) => Pin() needs to allocate a new GCHandle to pin the object.
- private readonly object? _object;
- private readonly int _index;
- private readonly int _length;
-
- internal const int RemoveFlagsBitMask = 0x7FFFFFFF;
-
- /// <summary>
- /// Creates a new memory over the entirety of the target array.
- /// </summary>
- /// <param name="array">The target array.</param>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ReadOnlyMemory(T[]? array)
- {
- if (array == null)
- {
- this = default;
- return; // returns default
- }
-
- _object = array;
- _index = 0;
- _length = array.Length;
- }
-
- /// <summary>
- /// Creates a new memory over the portion of the target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="array">The target array.</param>
- /// <param name="start">The index at which to begin the memory.</param>
- /// <param name="length">The number of items in the memory.</param>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ReadOnlyMemory(T[]? array, int start, int length)
- {
- if (array == null)
- {
- if (start != 0 || length != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
- this = default;
- return; // returns default
- }
-#if BIT64
- // See comment in Span<T>.Slice for how this works.
- if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)array.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#else
- if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#endif
-
- _object = array;
- _index = start;
- _length = length;
- }
-
- /// <summary>Creates a new memory over the existing object, start, and length. No validation is performed.</summary>
- /// <param name="obj">The target object.</param>
- /// <param name="start">The index at which to begin the memory.</param>
- /// <param name="length">The number of items in the memory.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal ReadOnlyMemory(object? obj, int start, int length)
- {
- // No validation performed in release builds; caller must provide any necessary validation.
-
- // 'obj is T[]' below also handles things like int[] <-> uint[] being convertible
- Debug.Assert((obj == null)
- || (typeof(T) == typeof(char) && obj is string)
-#if FEATURE_UTF8STRING
- || ((typeof(T) == typeof(byte) || typeof(T) == typeof(Char8)) && obj is Utf8String)
-#endif // FEATURE_UTF8STRING
- || (obj is T[])
- || (obj is MemoryManager<T>));
-
- _object = obj;
- _index = start;
- _length = length;
- }
-
- /// <summary>
- /// Defines an implicit conversion of an array to a <see cref="ReadOnlyMemory{T}"/>
- /// </summary>
- public static implicit operator ReadOnlyMemory<T>(T[]? array) => new ReadOnlyMemory<T>(array);
-
- /// <summary>
- /// Defines an implicit conversion of a <see cref="ArraySegment{T}"/> to a <see cref="ReadOnlyMemory{T}"/>
- /// </summary>
- public static implicit operator ReadOnlyMemory<T>(ArraySegment<T> segment) => new ReadOnlyMemory<T>(segment.Array, segment.Offset, segment.Count);
-
- /// <summary>
- /// Returns an empty <see cref="ReadOnlyMemory{T}"/>
- /// </summary>
- public static ReadOnlyMemory<T> Empty => default;
-
- /// <summary>
- /// The number of items in the memory.
- /// </summary>
- public int Length => _length;
-
- /// <summary>
- /// Returns true if Length is 0.
- /// </summary>
- public bool IsEmpty => _length == 0;
-
- /// <summary>
- /// For <see cref="ReadOnlyMemory{Char}"/>, returns a new instance of string that represents the characters pointed to by the memory.
- /// Otherwise, returns a <see cref="string"/> with the name of the type and the number of elements.
- /// </summary>
- public override string ToString()
- {
- if (typeof(T) == typeof(char))
- {
- return (_object is string str) ? str.Substring(_index, _length) : Span.ToString();
- }
-#if FEATURE_UTF8STRING
- else if (typeof(T) == typeof(Char8))
- {
- // TODO_UTF8STRING: Call into optimized transcoding routine when it's available.
- ReadOnlySpan<T> span = Span;
- return Encoding.UTF8.GetString(new ReadOnlySpan<byte>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(span)), span.Length));
- }
-#endif // FEATURE_UTF8STRING
- return string.Format("System.ReadOnlyMemory<{0}>[{1}]", typeof(T).Name, _length);
- }
-
- /// <summary>
- /// Forms a slice out of the given memory, beginning at 'start'.
- /// </summary>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> index is not in range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ReadOnlyMemory<T> Slice(int start)
- {
- if ((uint)start > (uint)_length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
- }
-
- // It is expected for _index + start to be negative if the memory is already pre-pinned.
- return new ReadOnlyMemory<T>(_object, _index + start, _length - start);
- }
-
- /// <summary>
- /// Forms a slice out of the given memory, beginning at 'start', of given length
- /// </summary>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <param name="length">The desired length for the slice (exclusive).</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ReadOnlyMemory<T> Slice(int start, int length)
- {
-#if BIT64
- // See comment in Span<T>.Slice for how this works.
- if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)_length)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
-#else
- if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
-#endif
-
- // It is expected for _index + start to be negative if the memory is already pre-pinned.
- return new ReadOnlyMemory<T>(_object, _index + start, length);
- }
-
- /// <summary>
- /// Returns a span from the memory.
- /// </summary>
- public unsafe ReadOnlySpan<T> Span
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- ref T refToReturn = ref Unsafe.NullRef<T>();
- int lengthOfUnderlyingSpan = 0;
-
- // Copy this field into a local so that it can't change out from under us mid-operation.
-
- object? tmpObject = _object;
- if (tmpObject != null)
- {
- if (typeof(T) == typeof(char) && tmpObject.GetType() == typeof(string))
- {
- // Special-case string since it's the most common for ROM<char>.
-
- refToReturn = ref Unsafe.As<char, T>(ref Unsafe.As<string>(tmpObject).GetRawStringData());
- lengthOfUnderlyingSpan = Unsafe.As<string>(tmpObject).Length;
- }
-#if FEATURE_UTF8STRING
- else if ((typeof(T) == typeof(byte) || typeof(T) == typeof(Char8)) && tmpObject.GetType() == typeof(Utf8String))
- {
- refToReturn = ref Unsafe.As<byte, T>(ref Unsafe.As<Utf8String>(tmpObject).DangerousGetMutableReference());
- lengthOfUnderlyingSpan = Unsafe.As<Utf8String>(tmpObject).Length;
- }
-#endif // FEATURE_UTF8STRING
- else if (RuntimeHelpers.ObjectHasComponentSize(tmpObject))
- {
- // We know the object is not null, it's not a string, and it is variable-length. The only
- // remaining option is for it to be a T[] (or a U[] which is blittable to T[], like int[]
- // and uint[]). Otherwise somebody used private reflection to set this field, and we're not
- // too worried about type safety violations at this point.
-
- // 'tmpObject is T[]' below also handles things like int[] <-> uint[] being convertible
- Debug.Assert(tmpObject is T[]);
-
- refToReturn = ref Unsafe.As<byte, T>(ref Unsafe.As<T[]>(tmpObject).GetRawSzArrayData());
- lengthOfUnderlyingSpan = Unsafe.As<T[]>(tmpObject).Length;
- }
- else
- {
- // We know the object is not null, and it's not variable-length, so it must be a MemoryManager<T>.
- // Otherwise somebody used private reflection to set this field, and we're not too worried about
- // type safety violations at that point. Note that it can't be a MemoryManager<U>, even if U and
- // T are blittable (e.g., MemoryManager<int> to MemoryManager<uint>), since there exists no
- // constructor or other public API which would allow such a conversion.
-
- Debug.Assert(tmpObject is MemoryManager<T>);
- Span<T> memoryManagerSpan = Unsafe.As<MemoryManager<T>>(tmpObject).GetSpan();
- refToReturn = ref MemoryMarshal.GetReference(memoryManagerSpan);
- lengthOfUnderlyingSpan = memoryManagerSpan.Length;
- }
-
- // If the Memory<T> or ReadOnlyMemory<T> instance is torn, this property getter has undefined behavior.
- // We try to detect this condition and throw an exception, but it's possible that a torn struct might
- // appear to us to be valid, and we'll return an undesired span. Such a span is always guaranteed at
- // least to be in-bounds when compared with the original Memory<T> instance, so using the span won't
- // AV the process.
-
- nuint desiredStartIndex = (uint)_index & (uint)RemoveFlagsBitMask;
- int desiredLength = _length;
-
-#if BIT64
- // See comment in Span<T>.Slice for how this works.
- if ((ulong)desiredStartIndex + (ulong)(uint)desiredLength > (ulong)(uint)lengthOfUnderlyingSpan)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException();
- }
-#else
- if ((uint)desiredStartIndex > (uint)lengthOfUnderlyingSpan || (uint)desiredLength > (uint)(lengthOfUnderlyingSpan - desiredStartIndex))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException();
- }
-#endif
-
- refToReturn = ref Unsafe.Add(ref refToReturn, (IntPtr)(void*)desiredStartIndex);
- lengthOfUnderlyingSpan = desiredLength;
- }
-
- return new ReadOnlySpan<T>(ref refToReturn, lengthOfUnderlyingSpan);
- }
- }
-
- /// <summary>
- /// Copies the contents of the read-only memory into the destination. If the source
- /// and destination overlap, this method behaves as if the original values are in
- /// a temporary location before the destination is overwritten.
- ///
- /// <param name="destination">The Memory to copy items into.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when the destination is shorter than the source.
- /// </exception>
- /// </summary>
- public void CopyTo(Memory<T> destination) => Span.CopyTo(destination.Span);
-
- /// <summary>
- /// Copies the contents of the readonly-only memory into the destination. If the source
- /// and destination overlap, this method behaves as if the original values are in
- /// a temporary location before the destination is overwritten.
- ///
- /// <returns>If the destination is shorter than the source, this method
- /// return false and no data is written to the destination.</returns>
- /// </summary>
- /// <param name="destination">The span to copy items into.</param>
- public bool TryCopyTo(Memory<T> destination) => Span.TryCopyTo(destination.Span);
-
- /// <summary>
- /// Creates a handle for the memory.
- /// The GC will not move the memory until the returned <see cref="MemoryHandle"/>
- /// is disposed, enabling taking and using the memory's address.
- /// <exception cref="System.ArgumentException">
- /// An instance with nonprimitive (non-blittable) members cannot be pinned.
- /// </exception>
- /// </summary>
- public unsafe MemoryHandle Pin()
- {
- // It's possible that the below logic could result in an AV if the struct
- // is torn. This is ok since the caller is expecting to use raw pointers,
- // and we're not required to keep this as safe as the other Span-based APIs.
-
- object? tmpObject = _object;
- if (tmpObject != null)
- {
- if (typeof(T) == typeof(char) && tmpObject is string s)
- {
- GCHandle handle = GCHandle.Alloc(tmpObject, GCHandleType.Pinned);
- ref char stringData = ref Unsafe.Add(ref s.GetRawStringData(), _index);
- return new MemoryHandle(Unsafe.AsPointer(ref stringData), handle);
- }
-#if FEATURE_UTF8STRING
- else if ((typeof(T) == typeof(byte) || typeof(T) == typeof(Char8)) && tmpObject is Utf8String utf8String)
- {
- GCHandle handle = GCHandle.Alloc(tmpObject, GCHandleType.Pinned);
- ref byte stringData = ref utf8String.DangerousGetMutableReference(_index);
- return new MemoryHandle(Unsafe.AsPointer(ref stringData), handle);
- }
-#endif // FEATURE_UTF8STRING
- else if (RuntimeHelpers.ObjectHasComponentSize(tmpObject))
- {
- // 'tmpObject is T[]' below also handles things like int[] <-> uint[] being convertible
- Debug.Assert(tmpObject is T[]);
-
- // Array is already pre-pinned
- if (_index < 0)
- {
- void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref Unsafe.As<T[]>(tmpObject).GetRawSzArrayData()), _index & RemoveFlagsBitMask);
- return new MemoryHandle(pointer);
- }
- else
- {
- GCHandle handle = GCHandle.Alloc(tmpObject, GCHandleType.Pinned);
- void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref Unsafe.As<T[]>(tmpObject).GetRawSzArrayData()), _index);
- return new MemoryHandle(pointer, handle);
- }
- }
- else
- {
- Debug.Assert(tmpObject is MemoryManager<T>);
- return Unsafe.As<MemoryManager<T>>(tmpObject).Pin(_index);
- }
- }
-
- return default;
- }
-
- /// <summary>
- /// Copies the contents from the memory into a new array. This heap
- /// allocates, so should generally be avoided, however it is sometimes
- /// necessary to bridge the gap with APIs written in terms of arrays.
- /// </summary>
- public T[] ToArray() => Span.ToArray();
-
- /// <summary>Determines whether the specified object is equal to the current object.</summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override bool Equals(object? obj)
- {
- if (obj is ReadOnlyMemory<T> readOnlyMemory)
- {
- return Equals(readOnlyMemory);
- }
- else if (obj is Memory<T> memory)
- {
- return Equals(memory);
- }
- else
- {
- return false;
- }
- }
-
- /// <summary>
- /// Returns true if the memory points to the same array and has the same length. Note that
- /// this does *not* check to see if the *contents* are equal.
- /// </summary>
- public bool Equals(ReadOnlyMemory<T> other)
- {
- return
- _object == other._object &&
- _index == other._index &&
- _length == other._length;
- }
-
- /// <summary>Returns the hash code for this <see cref="ReadOnlyMemory{T}"/></summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override int GetHashCode()
- {
- // We use RuntimeHelpers.GetHashCode instead of Object.GetHashCode because the hash
- // code is based on object identity and referential equality, not deep equality (as common with string).
- return (_object != null) ? HashCode.Combine(RuntimeHelpers.GetHashCode(_object), _index, _length) : 0;
- }
-
- /// <summary>Gets the state of the memory as individual fields.</summary>
- /// <param name="start">The offset.</param>
- /// <param name="length">The count.</param>
- /// <returns>The object.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal object? GetObjectStartLength(out int start, out int length)
- {
- start = _index;
- length = _length;
- return _object;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ReadOnlySpan.cs b/netcore/System.Private.CoreLib/shared/System/ReadOnlySpan.cs
deleted file mode 100644
index 94cc4d2462a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ReadOnlySpan.cs
+++ /dev/null
@@ -1,393 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.Versioning;
-using System.Text;
-using EditorBrowsableAttribute = System.ComponentModel.EditorBrowsableAttribute;
-using EditorBrowsableState = System.ComponentModel.EditorBrowsableState;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable 0809 //warning CS0809: Obsolete member 'Span<T>.Equals(object)' overrides non-obsolete member 'object.Equals(object)'
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- /// <summary>
- /// ReadOnlySpan represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed
- /// or native memory, or to memory allocated on the stack. It is type- and memory-safe.
- /// </summary>
- [DebuggerTypeProxy(typeof(SpanDebugView<>))]
- [DebuggerDisplay("{ToString(),raw}")]
- [NonVersionable]
- public readonly ref struct ReadOnlySpan<T>
- {
- /// <summary>A byref or a native ptr.</summary>
- internal readonly ByReference<T> _pointer;
- /// <summary>The number of elements this ReadOnlySpan contains.</summary>
- private readonly int _length;
-
- /// <summary>
- /// Creates a new read-only span over the entirety of the target array.
- /// </summary>
- /// <param name="array">The target array.</param>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ReadOnlySpan(T[]? array)
- {
- if (array == null)
- {
- this = default;
- return; // returns default
- }
-
- _pointer = new ByReference<T>(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()));
- _length = array.Length;
- }
-
- /// <summary>
- /// Creates a new read-only span over the portion of the target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="array">The target array.</param>
- /// <param name="start">The index at which to begin the read-only span.</param>
- /// <param name="length">The number of items in the read-only span.</param>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ReadOnlySpan(T[]? array, int start, int length)
- {
- if (array == null)
- {
- if (start != 0 || length != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
- this = default;
- return; // returns default
- }
-#if BIT64
- // See comment in Span<T>.Slice for how this works.
- if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)array.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#else
- if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#endif
-
- _pointer = new ByReference<T>(ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), start));
- _length = length;
- }
-
- /// <summary>
- /// Creates a new read-only span over the target unmanaged buffer. Clearly this
- /// is quite dangerous, because we are creating arbitrarily typed T's
- /// out of a void*-typed block of memory. And the length is not checked.
- /// But if this creation is correct, then all subsequent uses are correct.
- /// </summary>
- /// <param name="pointer">An unmanaged pointer to memory.</param>
- /// <param name="length">The number of <typeparamref name="T"/> elements the memory contains.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when <typeparamref name="T"/> is reference type or contains pointers and hence cannot be stored in unmanaged memory.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="length"/> is negative.
- /// </exception>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public unsafe ReadOnlySpan(void* pointer, int length)
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- if (length < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- _pointer = new ByReference<T>(ref Unsafe.As<byte, T>(ref *(byte*)pointer));
- _length = length;
- }
-
- // Constructor for internal use only.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal ReadOnlySpan(ref T ptr, int length)
- {
- Debug.Assert(length >= 0);
-
- _pointer = new ByReference<T>(ref ptr);
- _length = length;
- }
-
- /// <summary>
- /// Returns the specified element of the read-only span.
- /// </summary>
- /// <param name="index"></param>
- /// <returns></returns>
- /// <exception cref="System.IndexOutOfRangeException">
- /// Thrown when index less than 0 or index greater than or equal to Length
- /// </exception>
- public ref readonly T this[int index]
- {
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [NonVersionable]
- get
- {
- if ((uint)index >= (uint)_length)
- ThrowHelper.ThrowIndexOutOfRangeException();
- return ref Unsafe.Add(ref _pointer.Value, index);
- }
- }
-
- /// <summary>
- /// The number of items in the read-only span.
- /// </summary>
- public int Length
- {
- [NonVersionable]
- get => _length;
- }
-
- /// <summary>
- /// Returns true if Length is 0.
- /// </summary>
- public bool IsEmpty
- {
- [NonVersionable]
- get => 0 >= (uint)_length; // Workaround for https://github.com/dotnet/coreclr/issues/19620
- }
-
- /// <summary>
- /// Returns false if left and right point at the same memory and have the same length. Note that
- /// this does *not* check to see if the *contents* are equal.
- /// </summary>
- public static bool operator !=(ReadOnlySpan<T> left, ReadOnlySpan<T> right) => !(left == right);
-
- /// <summary>
- /// This method is not supported as spans cannot be boxed. To compare two spans, use operator==.
- /// <exception cref="System.NotSupportedException">
- /// Always thrown by this method.
- /// </exception>
- /// </summary>
- [Obsolete("Equals() on ReadOnlySpan will always throw an exception. Use == instead.")]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override bool Equals(object? obj) =>
- throw new NotSupportedException(SR.NotSupported_CannotCallEqualsOnSpan);
-
- /// <summary>
- /// This method is not supported as spans cannot be boxed.
- /// <exception cref="System.NotSupportedException">
- /// Always thrown by this method.
- /// </exception>
- /// </summary>
- [Obsolete("GetHashCode() on ReadOnlySpan will always throw an exception.")]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override int GetHashCode() =>
- throw new NotSupportedException(SR.NotSupported_CannotCallGetHashCodeOnSpan);
-
- /// <summary>
- /// Defines an implicit conversion of an array to a <see cref="ReadOnlySpan{T}"/>
- /// </summary>
- public static implicit operator ReadOnlySpan<T>(T[]? array) => new ReadOnlySpan<T>(array);
-
- /// <summary>
- /// Defines an implicit conversion of a <see cref="ArraySegment{T}"/> to a <see cref="ReadOnlySpan{T}"/>
- /// </summary>
- public static implicit operator ReadOnlySpan<T>(ArraySegment<T> segment)
- => new ReadOnlySpan<T>(segment.Array, segment.Offset, segment.Count);
-
- /// <summary>
- /// Returns a 0-length read-only span whose base is the null pointer.
- /// </summary>
- public static ReadOnlySpan<T> Empty => default;
-
- /// <summary>Gets an enumerator for this span.</summary>
- public Enumerator GetEnumerator() => new Enumerator(this);
-
- /// <summary>Enumerates the elements of a <see cref="ReadOnlySpan{T}"/>.</summary>
- public ref struct Enumerator
- {
- /// <summary>The span being enumerated.</summary>
- private readonly ReadOnlySpan<T> _span;
- /// <summary>The next index to yield.</summary>
- private int _index;
-
- /// <summary>Initialize the enumerator.</summary>
- /// <param name="span">The span to enumerate.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal Enumerator(ReadOnlySpan<T> span)
- {
- _span = span;
- _index = -1;
- }
-
- /// <summary>Advances the enumerator to the next element of the span.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool MoveNext()
- {
- int index = _index + 1;
- if (index < _span.Length)
- {
- _index = index;
- return true;
- }
-
- return false;
- }
-
- /// <summary>Gets the element at the current position of the enumerator.</summary>
- public ref readonly T Current
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => ref _span[_index];
- }
- }
-
- /// <summary>
- /// Returns a reference to the 0th element of the Span. If the Span is empty, returns null reference.
- /// It can be used for pinning and is required to support the use of span within a fixed statement.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public ref readonly T GetPinnableReference()
- {
- // Ensure that the native code has just one forward branch that is predicted-not-taken.
- ref T ret = ref Unsafe.NullRef<T>();
- if (_length != 0) ret = ref _pointer.Value;
- return ref ret;
- }
-
- /// <summary>
- /// Copies the contents of this read-only span into destination span. If the source
- /// and destinations overlap, this method behaves as if the original values in
- /// a temporary location before the destination is overwritten.
- ///
- /// <param name="destination">The span to copy items into.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when the destination Span is shorter than the source Span.
- /// </exception>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void CopyTo(Span<T> destination)
- {
- // Using "if (!TryCopyTo(...))" results in two branches: one for the length
- // check, and one for the result of TryCopyTo. Since these checks are equivalent,
- // we can optimize by performing the check once ourselves then calling Memmove directly.
-
- if ((uint)_length <= (uint)destination.Length)
- {
- Buffer.Memmove(ref destination._pointer.Value, ref _pointer.Value, (nuint)_length);
- }
- else
- {
- ThrowHelper.ThrowArgumentException_DestinationTooShort();
- }
- }
-
- /// <summary>
- /// Copies the contents of this read-only span into destination span. If the source
- /// and destinations overlap, this method behaves as if the original values in
- /// a temporary location before the destination is overwritten.
- /// </summary>
- /// <returns>If the destination span is shorter than the source span, this method
- /// return false and no data is written to the destination.</returns>
- /// <param name="destination">The span to copy items into.</param>
- public bool TryCopyTo(Span<T> destination)
- {
- bool retVal = false;
- if ((uint)_length <= (uint)destination.Length)
- {
- Buffer.Memmove(ref destination._pointer.Value, ref _pointer.Value, (nuint)_length);
- retVal = true;
- }
- return retVal;
- }
-
- /// <summary>
- /// Returns true if left and right point at the same memory and have the same length. Note that
- /// this does *not* check to see if the *contents* are equal.
- /// </summary>
- public static bool operator ==(ReadOnlySpan<T> left, ReadOnlySpan<T> right) =>
- left._length == right._length &&
- Unsafe.AreSame<T>(ref left._pointer.Value, ref right._pointer.Value);
-
- /// <summary>
- /// For <see cref="ReadOnlySpan{Char}"/>, returns a new instance of string that represents the characters pointed to by the span.
- /// Otherwise, returns a <see cref="string"/> with the name of the type and the number of elements.
- /// </summary>
- public override string ToString()
- {
- if (typeof(T) == typeof(char))
- {
- return new string(new ReadOnlySpan<char>(ref Unsafe.As<T, char>(ref _pointer.Value), _length));
- }
-#if FEATURE_UTF8STRING
- else if (typeof(T) == typeof(Char8))
- {
- // TODO_UTF8STRING: Call into optimized transcoding routine when it's available.
- return Encoding.UTF8.GetString(new ReadOnlySpan<byte>(ref Unsafe.As<T, byte>(ref _pointer.Value), _length));
- }
-#endif // FEATURE_UTF8STRING
- return string.Format("System.ReadOnlySpan<{0}>[{1}]", typeof(T).Name, _length);
- }
-
- /// <summary>
- /// Forms a slice out of the given read-only span, beginning at 'start'.
- /// </summary>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> index is not in range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ReadOnlySpan<T> Slice(int start)
- {
- if ((uint)start > (uint)_length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- return new ReadOnlySpan<T>(ref Unsafe.Add(ref _pointer.Value, start), _length - start);
- }
-
- /// <summary>
- /// Forms a slice out of the given read-only span, beginning at 'start', of given length
- /// </summary>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <param name="length">The desired length for the slice (exclusive).</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ReadOnlySpan<T> Slice(int start, int length)
- {
-#if BIT64
- // See comment in Span<T>.Slice for how this works.
- if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)_length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#else
- if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#endif
-
- return new ReadOnlySpan<T>(ref Unsafe.Add(ref _pointer.Value, start), length);
- }
-
- /// <summary>
- /// Copies the contents of this read-only span into a new array. This heap
- /// allocates, so should generally be avoided, however it is sometimes
- /// necessary to bridge the gap with APIs written in terms of arrays.
- /// </summary>
- public T[] ToArray()
- {
- if (_length == 0)
- return Array.Empty<T>();
-
- var destination = new T[_length];
- Buffer.Memmove(ref Unsafe.As<byte, T>(ref destination.GetRawSzArrayData()), ref _pointer.Value, (nuint)_length);
- return destination;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AmbiguousMatchException.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AmbiguousMatchException.cs
deleted file mode 100644
index f6472c9953a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AmbiguousMatchException.cs
+++ /dev/null
@@ -1,35 +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 System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class AmbiguousMatchException : SystemException
- {
- public AmbiguousMatchException()
- : base(SR.RFLCT_Ambiguous)
- {
- HResult = HResults.COR_E_AMBIGUOUSMATCH;
- }
-
- public AmbiguousMatchException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_AMBIGUOUSMATCH;
- }
-
- public AmbiguousMatchException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_AMBIGUOUSMATCH;
- }
-
- private AmbiguousMatchException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Assembly.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Assembly.cs
deleted file mode 100644
index 6e344ff052a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Assembly.cs
+++ /dev/null
@@ -1,354 +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 System.IO;
-using System.Globalization;
-using System.Collections.Generic;
-using System.Configuration.Assemblies;
-using System.Runtime.Serialization;
-using System.Security;
-using System.Runtime.CompilerServices;
-using System.Runtime.Loader;
-
-namespace System.Reflection
-{
- public abstract partial class Assembly : ICustomAttributeProvider, ISerializable
- {
- private static readonly Dictionary<string, Assembly> s_loadfile = new Dictionary<string, Assembly>();
- private static readonly List<string> s_loadFromAssemblyList = new List<string>();
- private static bool s_loadFromHandlerSet;
- private static int s_cachedSerializationSwitch;
-
- protected Assembly() { }
-
- public virtual IEnumerable<TypeInfo> DefinedTypes
- {
- get
- {
- Type[] types = GetTypes();
- TypeInfo[] typeinfos = new TypeInfo[types.Length];
- for (int i = 0; i < types.Length; i++)
- {
- TypeInfo typeinfo = types[i].GetTypeInfo();
- if (typeinfo == null)
- throw new NotSupportedException(SR.Format(SR.NotSupported_NoTypeInfo, types[i].FullName));
-
- typeinfos[i] = typeinfo;
- }
- return typeinfos;
- }
- }
-
- public virtual Type[] GetTypes()
- {
- Module[] m = GetModules(false);
- if (m.Length == 1)
- {
- return m[0].GetTypes();
- }
-
- int finalLength = 0;
- Type[][] moduleTypes = new Type[m.Length][];
-
- for (int i = 0; i < moduleTypes.Length; i++)
- {
- moduleTypes[i] = m[i].GetTypes();
- finalLength += moduleTypes[i].Length;
- }
-
- int current = 0;
- Type[] ret = new Type[finalLength];
- for (int i = 0; i < moduleTypes.Length; i++)
- {
- int length = moduleTypes[i].Length;
- Array.Copy(moduleTypes[i], 0, ret, current, length);
- current += length;
- }
-
- return ret;
- }
-
- public virtual IEnumerable<Type> ExportedTypes => GetExportedTypes();
- public virtual Type[] GetExportedTypes() { throw NotImplemented.ByDesign; }
- public virtual Type[] GetForwardedTypes() { throw NotImplemented.ByDesign; }
-
- public virtual string? CodeBase => throw NotImplemented.ByDesign;
- public virtual MethodInfo? EntryPoint => throw NotImplemented.ByDesign;
- public virtual string? FullName => throw NotImplemented.ByDesign;
- public virtual string ImageRuntimeVersion => throw NotImplemented.ByDesign;
- public virtual bool IsDynamic => false;
- public virtual string Location => throw NotImplemented.ByDesign;
- public virtual bool ReflectionOnly => throw NotImplemented.ByDesign;
- public virtual bool IsCollectible => true;
-
- public virtual ManifestResourceInfo? GetManifestResourceInfo(string resourceName) { throw NotImplemented.ByDesign; }
- public virtual string[] GetManifestResourceNames() { throw NotImplemented.ByDesign; }
- public virtual Stream? GetManifestResourceStream(string name) { throw NotImplemented.ByDesign; }
- public virtual Stream? GetManifestResourceStream(Type type, string name) { throw NotImplemented.ByDesign; }
-
- public bool IsFullyTrusted => true;
-
- public virtual AssemblyName GetName() => GetName(copiedName: false);
- public virtual AssemblyName GetName(bool copiedName) { throw NotImplemented.ByDesign; }
-
- public virtual Type? GetType(string name) => GetType(name, throwOnError: false, ignoreCase: false);
- public virtual Type? GetType(string name, bool throwOnError) => GetType(name, throwOnError: throwOnError, ignoreCase: false);
- public virtual Type? GetType(string name, bool throwOnError, bool ignoreCase) { throw NotImplemented.ByDesign; }
-
- public virtual bool IsDefined(Type attributeType, bool inherit) { throw NotImplemented.ByDesign; }
-
- public virtual IEnumerable<CustomAttributeData> CustomAttributes => GetCustomAttributesData();
- public virtual IList<CustomAttributeData> GetCustomAttributesData() { throw NotImplemented.ByDesign; }
-
- public virtual object[] GetCustomAttributes(bool inherit) { throw NotImplemented.ByDesign; }
- public virtual object[] GetCustomAttributes(Type attributeType, bool inherit) { throw NotImplemented.ByDesign; }
-
- public virtual string EscapedCodeBase => AssemblyName.EscapeCodeBase(CodeBase);
-
- public object? CreateInstance(string typeName) => CreateInstance(typeName, false, BindingFlags.Public | BindingFlags.Instance, binder: null, args: null, culture: null, activationAttributes: null);
- public object? CreateInstance(string typeName, bool ignoreCase) => CreateInstance(typeName, ignoreCase, BindingFlags.Public | BindingFlags.Instance, binder: null, args: null, culture: null, activationAttributes: null);
- public virtual object? CreateInstance(string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object[]? args, CultureInfo? culture, object[]? activationAttributes)
- {
- Type? t = GetType(typeName, throwOnError: false, ignoreCase: ignoreCase);
- if (t == null)
- return null;
-
- return Activator.CreateInstance(t, bindingAttr, binder, args, culture, activationAttributes);
- }
-
- public virtual event ModuleResolveEventHandler? ModuleResolve { add { throw NotImplemented.ByDesign; } remove { throw NotImplemented.ByDesign; } }
-
- public virtual Module ManifestModule => throw NotImplemented.ByDesign;
- public virtual Module? GetModule(string name) { throw NotImplemented.ByDesign; }
-
- public Module[] GetModules() => GetModules(getResourceModules: false);
- public virtual Module[] GetModules(bool getResourceModules) { throw NotImplemented.ByDesign; }
-
- public virtual IEnumerable<Module> Modules => GetLoadedModules(getResourceModules: true);
- public Module[] GetLoadedModules() => GetLoadedModules(getResourceModules: false);
- public virtual Module[] GetLoadedModules(bool getResourceModules) { throw NotImplemented.ByDesign; }
-
- public virtual AssemblyName[] GetReferencedAssemblies() { throw NotImplemented.ByDesign; }
-
- public virtual Assembly GetSatelliteAssembly(CultureInfo culture) { throw NotImplemented.ByDesign; }
- public virtual Assembly GetSatelliteAssembly(CultureInfo culture, Version? version) { throw NotImplemented.ByDesign; }
-
- public virtual FileStream? GetFile(string name) { throw NotImplemented.ByDesign; }
- public virtual FileStream[] GetFiles() => GetFiles(getResourceModules: false);
- public virtual FileStream[] GetFiles(bool getResourceModules) { throw NotImplemented.ByDesign; }
-
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { throw NotImplemented.ByDesign; }
-
- public override string ToString()
- {
- return FullName ?? base.ToString()!;
- }
-
- /*
- Returns true if the assembly was loaded from the global assembly cache.
- */
- public virtual bool GlobalAssemblyCache => throw NotImplemented.ByDesign;
- public virtual long HostContext => throw NotImplemented.ByDesign;
-
- public override bool Equals(object? o) => base.Equals(o);
- public override int GetHashCode() => base.GetHashCode();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Assembly? left, Assembly? right)
- {
- // Test "right" first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (right is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (left is null) ? true : false;
- }
-
- // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
- if ((object?)left == (object)right)
- {
- return true;
- }
-
- return (left is null) ? false : left.Equals(right);
- }
-
- public static bool operator !=(Assembly? left, Assembly? right) => !(left == right);
-
- public static string CreateQualifiedName(string? assemblyName, string? typeName) => typeName + ", " + assemblyName;
-
- public static Assembly? GetAssembly(Type type)
- {
- if (type == null)
- throw new ArgumentNullException(nameof(type));
-
- Module m = type.Module;
- if (m == null)
- return null;
- else
- return m.Assembly;
- }
-
- // internal test hook
- private static bool s_forceNullEntryPoint = false;
-
- public static Assembly? GetEntryAssembly()
- {
- if (s_forceNullEntryPoint)
- return null;
-
- return GetEntryAssemblyInternal();
- }
-
- public static Assembly Load(byte[] rawAssembly) => Load(rawAssembly, rawSymbolStore: null);
-
- // Loads the assembly with a COFF based IMAGE containing
- // an emitted assembly. The assembly is loaded into a fully isolated ALC with resolution fully deferred to the AssemblyLoadContext.Default.
- // The second parameter is the raw bytes representing the symbol store that matches the assembly.
- public static Assembly Load(byte[] rawAssembly, byte[]? rawSymbolStore)
- {
- if (rawAssembly == null)
- throw new ArgumentNullException(nameof(rawAssembly));
-
- if (rawAssembly.Length == 0)
- throw new BadImageFormatException(SR.BadImageFormat_BadILFormat);
-
- SerializationInfo.ThrowIfDeserializationInProgress("AllowAssembliesFromByteArrays",
- ref s_cachedSerializationSwitch);
-
- AssemblyLoadContext alc = new IndividualAssemblyLoadContext("Assembly.Load(byte[], ...)");
- return alc.InternalLoad(rawAssembly, rawSymbolStore);
- }
-
- public static Assembly LoadFile(string path)
- {
- if (path == null)
- throw new ArgumentNullException(nameof(path));
-
- if (PathInternal.IsPartiallyQualified(path))
- {
- throw new ArgumentException(SR.Format(SR.Argument_AbsolutePathRequired, path), nameof(path));
- }
-
- string normalizedPath = Path.GetFullPath(path);
-
- Assembly? result;
- lock (s_loadfile)
- {
- if (s_loadfile.TryGetValue(normalizedPath, out result))
- return result;
-
- AssemblyLoadContext alc = new IndividualAssemblyLoadContext(string.Format("Assembly.LoadFile({0})", normalizedPath));
- result = alc.LoadFromAssemblyPath(normalizedPath);
- s_loadfile.Add(normalizedPath, result);
- }
- return result;
- }
-
- private static Assembly? LoadFromResolveHandler(object? sender, ResolveEventArgs args)
- {
- Assembly? requestingAssembly = args.RequestingAssembly;
- if (requestingAssembly == null)
- {
- return null;
- }
-
- // Requesting assembly for LoadFrom is always loaded in defaultContext - proceed only if that
- // is the case.
- if (AssemblyLoadContext.Default != AssemblyLoadContext.GetLoadContext(requestingAssembly))
- return null;
-
- // Get the path where requesting assembly lives and check if it is in the list
- // of assemblies for which LoadFrom was invoked.
- string requestorPath = Path.GetFullPath(requestingAssembly.Location);
- if (string.IsNullOrEmpty(requestorPath))
- return null;
-
- lock (s_loadFromAssemblyList)
- {
- // If the requestor assembly was not loaded using LoadFrom, exit.
- if (!s_loadFromAssemblyList.Contains(requestorPath))
- {
-#if CORECLR
- if (AssemblyLoadContext.IsTracingEnabled())
- {
- AssemblyLoadContext.TraceAssemblyLoadFromResolveHandlerInvoked(args.Name, false, requestorPath, null);
- }
-#endif // CORECLR
- return null;
- }
- }
-
- // Requestor assembly was loaded using loadFrom, so look for its dependencies
- // in the same folder as it.
- // Form the name of the assembly using the path of the assembly that requested its load.
- AssemblyName requestedAssemblyName = new AssemblyName(args.Name!);
- string requestedAssemblyPath = Path.Combine(Path.GetDirectoryName(requestorPath)!, requestedAssemblyName.Name + ".dll");
-#if CORECLR
- if (AssemblyLoadContext.IsTracingEnabled())
- {
- AssemblyLoadContext.TraceAssemblyLoadFromResolveHandlerInvoked(args.Name, true, requestorPath, requestedAssemblyPath);
- }
-#endif // CORECLR
- try
- {
- // Load the dependency via LoadFrom so that it goes through the same path of being in the LoadFrom list.
- return Assembly.LoadFrom(requestedAssemblyPath);
- }
- catch (FileNotFoundException)
- {
- // Catch FileNotFoundException when attempting to resolve assemblies via this handler to account for missing assemblies.
- return null;
- }
- }
-
- public static Assembly LoadFrom(string assemblyFile)
- {
- if (assemblyFile == null)
- throw new ArgumentNullException(nameof(assemblyFile));
-
- string fullPath = Path.GetFullPath(assemblyFile);
-
- if (!s_loadFromHandlerSet)
- {
- lock (s_loadFromAssemblyList)
- {
- if (!s_loadFromHandlerSet)
- {
- AssemblyLoadContext.AssemblyResolve += LoadFromResolveHandler!;
- s_loadFromHandlerSet = true;
- }
- }
- }
-
- // Add the path to the LoadFrom path list which we will consult
- // before handling the resolves in our handler.
- lock (s_loadFromAssemblyList)
- {
- if (!s_loadFromAssemblyList.Contains(fullPath))
- {
- s_loadFromAssemblyList.Add(fullPath);
- }
- }
-
- return AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath);
- }
-
- public static Assembly LoadFrom(string assemblyFile, byte[]? hashValue, AssemblyHashAlgorithm hashAlgorithm)
- {
- throw new NotSupportedException(SR.NotSupported_AssemblyLoadFromHash);
- }
-
- public static Assembly UnsafeLoadFrom(string assemblyFile) => LoadFrom(assemblyFile);
-
- public Module LoadModule(string moduleName, byte[]? rawModule) => LoadModule(moduleName, rawModule, null);
- public virtual Module LoadModule(string moduleName, byte[]? rawModule, byte[]? rawSymbolStore) { throw NotImplemented.ByDesign; }
-
- public static Assembly ReflectionOnlyLoad(byte[] rawAssembly) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); }
- public static Assembly ReflectionOnlyLoad(string assemblyString) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); }
- public static Assembly ReflectionOnlyLoadFrom(string assemblyFile) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); }
-
- public virtual SecurityRuleSet SecurityRuleSet => SecurityRuleSet.None;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyAlgorithmIdAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyAlgorithmIdAttribute.cs
deleted file mode 100644
index 7ea8ecf6eb7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyAlgorithmIdAttribute.cs
+++ /dev/null
@@ -1,26 +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 System.Configuration.Assemblies;
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyAlgorithmIdAttribute : Attribute
- {
- public AssemblyAlgorithmIdAttribute(AssemblyHashAlgorithm algorithmId)
- {
- AlgorithmId = (uint)algorithmId;
- }
-
- [CLSCompliant(false)]
- public AssemblyAlgorithmIdAttribute(uint algorithmId)
- {
- AlgorithmId = algorithmId;
- }
-
- [CLSCompliant(false)]
- public uint AlgorithmId { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCompanyAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCompanyAttribute.cs
deleted file mode 100644
index 2c83e14624b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCompanyAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyCompanyAttribute : Attribute
- {
- public AssemblyCompanyAttribute(string company)
- {
- Company = company;
- }
-
- public string Company { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyConfigurationAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyConfigurationAttribute.cs
deleted file mode 100644
index c86642a415c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyConfigurationAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyConfigurationAttribute : Attribute
- {
- public AssemblyConfigurationAttribute(string configuration)
- {
- Configuration = configuration;
- }
-
- public string Configuration { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyContentType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyContentType.cs
deleted file mode 100644
index 6f6d0064efa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyContentType.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Reflection
-{
- public enum AssemblyContentType
- {
- Default = 0,
- WindowsRuntime = 1,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCopyrightAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCopyrightAttribute.cs
deleted file mode 100644
index a90068bc3fe..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCopyrightAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyCopyrightAttribute : Attribute
- {
- public AssemblyCopyrightAttribute(string copyright)
- {
- Copyright = copyright;
- }
-
- public string Copyright { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCultureAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCultureAttribute.cs
deleted file mode 100644
index f3af8a460c5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyCultureAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyCultureAttribute : Attribute
- {
- public AssemblyCultureAttribute(string culture)
- {
- Culture = culture;
- }
-
- public string Culture { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDefaultAliasAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDefaultAliasAttribute.cs
deleted file mode 100644
index ebe80d749bc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDefaultAliasAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyDefaultAliasAttribute : Attribute
- {
- public AssemblyDefaultAliasAttribute(string defaultAlias)
- {
- DefaultAlias = defaultAlias;
- }
-
- public string DefaultAlias { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDelaySignAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDelaySignAttribute.cs
deleted file mode 100644
index 74256a520e4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDelaySignAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyDelaySignAttribute : Attribute
- {
- public AssemblyDelaySignAttribute(bool delaySign)
- {
- DelaySign = delaySign;
- }
-
- public bool DelaySign { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDescriptionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDescriptionAttribute.cs
deleted file mode 100644
index 6e9abc9b185..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyDescriptionAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyDescriptionAttribute : Attribute
- {
- public AssemblyDescriptionAttribute(string description)
- {
- Description = description;
- }
-
- public string Description { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyFileVersionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyFileVersionAttribute.cs
deleted file mode 100644
index 5043e4afa29..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyFileVersionAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyFileVersionAttribute : Attribute
- {
- public AssemblyFileVersionAttribute(string version)
- {
- Version = version ?? throw new ArgumentNullException(nameof(version));
- }
-
- public string Version { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyFlagsAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyFlagsAttribute.cs
deleted file mode 100644
index 523430f9cd1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyFlagsAttribute.cs
+++ /dev/null
@@ -1,36 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyFlagsAttribute : Attribute
- {
- private readonly AssemblyNameFlags _flags;
-
- [Obsolete("This constructor has been deprecated. Please use AssemblyFlagsAttribute(AssemblyNameFlags) instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- [CLSCompliant(false)]
- public AssemblyFlagsAttribute(uint flags)
- {
- _flags = (AssemblyNameFlags)flags;
- }
-
- [Obsolete("This property has been deprecated. Please use AssemblyFlags instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- [CLSCompliant(false)]
- public uint Flags => (uint)_flags;
-
- public int AssemblyFlags => (int)_flags;
-
- [Obsolete("This constructor has been deprecated. Please use AssemblyFlagsAttribute(AssemblyNameFlags) instead. https://go.microsoft.com/fwlink/?linkid=14202")]
- public AssemblyFlagsAttribute(int assemblyFlags)
- {
- _flags = (AssemblyNameFlags)assemblyFlags;
- }
-
- public AssemblyFlagsAttribute(AssemblyNameFlags assemblyFlags)
- {
- _flags = assemblyFlags;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyInformationalVersionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyInformationalVersionAttribute.cs
deleted file mode 100644
index afd08343ee4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyInformationalVersionAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyInformationalVersionAttribute : Attribute
- {
- public AssemblyInformationalVersionAttribute(string informationalVersion)
- {
- InformationalVersion = informationalVersion;
- }
-
- public string InformationalVersion { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyKeyFileAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyKeyFileAttribute.cs
deleted file mode 100644
index 58157574b83..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyKeyFileAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyKeyFileAttribute : Attribute
- {
- public AssemblyKeyFileAttribute(string keyFile)
- {
- KeyFile = keyFile;
- }
-
- public string KeyFile { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyKeyNameAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyKeyNameAttribute.cs
deleted file mode 100644
index 3852a9bac77..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyKeyNameAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyKeyNameAttribute : Attribute
- {
- public AssemblyKeyNameAttribute(string keyName)
- {
- KeyName = keyName;
- }
-
- public string KeyName { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyMetadataAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyMetadataAttribute.cs
deleted file mode 100644
index 42ae3cab1b8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyMetadataAttribute.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
- public sealed class AssemblyMetadataAttribute : Attribute
- {
- public AssemblyMetadataAttribute(string key, string? value)
- {
- Key = key;
- Value = value;
- }
-
- public string Key { get; }
-
- public string? Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs
deleted file mode 100644
index 7b5f6f15222..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs
+++ /dev/null
@@ -1,478 +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 System.Configuration.Assemblies;
-using System.Runtime.Serialization;
-using System.Text;
-using CultureInfo = System.Globalization.CultureInfo;
-
-namespace System.Reflection
-{
- public sealed partial class AssemblyName : ICloneable, IDeserializationCallback, ISerializable
- {
- // If you modify any of these fields, you must also update the
- // AssemblyBaseObject structure in object.h
- private string? _name;
- private byte[]? _publicKey;
- private byte[]? _publicKeyToken;
- private CultureInfo? _cultureInfo;
- private string? _codeBase;
- private Version? _version;
-
- private StrongNameKeyPair? _strongNameKeyPair;
-
- private AssemblyHashAlgorithm _hashAlgorithm;
-
- private AssemblyVersionCompatibility _versionCompatibility;
- private AssemblyNameFlags _flags;
-
- public AssemblyName()
- {
- _versionCompatibility = AssemblyVersionCompatibility.SameMachine;
- }
-
- // Set and get the name of the assembly. If this is a weak Name
- // then it optionally contains a site. For strong assembly names,
- // the name partitions up the strong name's namespace
- public string? Name
- {
- get => _name;
- set => _name = value;
- }
-
- public Version? Version
- {
- get => _version;
- set => _version = value;
- }
-
- // Locales, internally the LCID is used for the match.
- public CultureInfo? CultureInfo
- {
- get => _cultureInfo;
- set => _cultureInfo = value;
- }
-
- public string? CultureName
- {
- get => _cultureInfo?.Name;
- set => _cultureInfo = (value == null) ? null : new CultureInfo(value);
- }
-
- public string? CodeBase
- {
- get => _codeBase;
- set => _codeBase = value;
- }
-
- public string? EscapedCodeBase
- {
- get
- {
- if (_codeBase == null)
- return null;
- else
- return EscapeCodeBase(_codeBase);
- }
- }
-
- public ProcessorArchitecture ProcessorArchitecture
- {
- get
- {
- int x = (((int)_flags) & 0x70) >> 4;
- if (x > 5)
- x = 0;
- return (ProcessorArchitecture)x;
- }
- set
- {
- int x = ((int)value) & 0x07;
- if (x <= 5)
- {
- _flags = (AssemblyNameFlags)((int)_flags & 0xFFFFFF0F);
- _flags |= (AssemblyNameFlags)(x << 4);
- }
- }
- }
-
- public AssemblyContentType ContentType
- {
- get
- {
- int x = (((int)_flags) & 0x00000E00) >> 9;
- if (x > 1)
- x = 0;
- return (AssemblyContentType)x;
- }
- set
- {
- int x = ((int)value) & 0x07;
- if (x <= 1)
- {
- _flags = (AssemblyNameFlags)((int)_flags & 0xFFFFF1FF);
- _flags |= (AssemblyNameFlags)(x << 9);
- }
- }
- }
-
- // Make a copy of this assembly name.
- public object Clone()
- {
- var name = new AssemblyName
- {
- _name = _name,
- _publicKey = (byte[]?)_publicKey?.Clone(),
- _publicKeyToken = (byte[]?)_publicKeyToken?.Clone(),
- _cultureInfo = _cultureInfo,
- _version = (Version?)_version?.Clone(),
- _flags = _flags,
- _codeBase = _codeBase,
- _hashAlgorithm = _hashAlgorithm,
- _versionCompatibility = _versionCompatibility,
- };
- return name;
- }
-
- /*
- * Get the AssemblyName for a given file. This will only work
- * if the file contains an assembly manifest. This method causes
- * the file to be opened and closed.
- */
- public static AssemblyName GetAssemblyName(string assemblyFile)
- {
- if (assemblyFile == null)
- throw new ArgumentNullException(nameof(assemblyFile));
-
- return GetFileInformationCore(assemblyFile);
- }
-
- public byte[]? GetPublicKey()
- {
- return _publicKey;
- }
-
- public void SetPublicKey(byte[]? publicKey)
- {
- _publicKey = publicKey;
-
- if (publicKey == null)
- _flags &= ~AssemblyNameFlags.PublicKey;
- else
- _flags |= AssemblyNameFlags.PublicKey;
- }
-
- // The compressed version of the public key formed from a truncated hash.
- // Will throw a SecurityException if _publicKey is invalid
- public byte[]? GetPublicKeyToken() => _publicKeyToken ??= ComputePublicKeyToken();
-
- public void SetPublicKeyToken(byte[]? publicKeyToken)
- {
- _publicKeyToken = publicKeyToken;
- }
-
- // Flags modifying the name. So far the only flag is PublicKey, which
- // indicates that a full public key and not the compressed version is
- // present.
- // Processor Architecture flags are set only through ProcessorArchitecture
- // property and can't be set or retrieved directly
- // Content Type flags are set only through ContentType property and can't be
- // set or retrieved directly
- public AssemblyNameFlags Flags
- {
- get => (AssemblyNameFlags)((uint)_flags & 0xFFFFF10F);
- set
- {
- _flags &= unchecked((AssemblyNameFlags)0x00000EF0);
- _flags |= (value & unchecked((AssemblyNameFlags)0xFFFFF10F));
- }
- }
-
- public AssemblyHashAlgorithm HashAlgorithm
- {
- get => _hashAlgorithm;
- set => _hashAlgorithm = value;
- }
-
- public AssemblyVersionCompatibility VersionCompatibility
- {
- get => _versionCompatibility;
- set => _versionCompatibility = value;
- }
-
- public StrongNameKeyPair? KeyPair
- {
- get => _strongNameKeyPair;
- set => _strongNameKeyPair = value;
- }
-
- public string FullName
- {
- get
- {
- if (this.Name == null)
- return string.Empty;
- // Do not call GetPublicKeyToken() here - that latches the result into AssemblyName which isn't a side effect we want.
- byte[]? pkt = _publicKeyToken ?? ComputePublicKeyToken();
- return AssemblyNameFormatter.ComputeDisplayName(Name, Version, CultureName, pkt, Flags, ContentType);
- }
- }
-
- public override string ToString()
- {
- string s = FullName;
- if (s == null)
- return base.ToString()!;
- else
- return s;
- }
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- public void OnDeserialization(object? sender)
- {
- throw new PlatformNotSupportedException();
- }
-
- /// <summary>
- /// Compares the simple names disregarding Version, Culture and PKT. While this clearly does not
- /// match the intent of this api, this api has been broken this way since its debut and we cannot
- /// change its behavior now.
- /// </summary>
- public static bool ReferenceMatchesDefinition(AssemblyName? reference, AssemblyName? definition)
- {
- if (object.ReferenceEquals(reference, definition))
- return true;
-
- if (reference == null)
- throw new ArgumentNullException(nameof(reference));
-
- if (definition == null)
- throw new ArgumentNullException(nameof(definition));
-
- string refName = reference.Name ?? string.Empty;
- string defName = definition.Name ?? string.Empty;
- return refName.Equals(defName, StringComparison.OrdinalIgnoreCase);
- }
-
- internal static string EscapeCodeBase(string? codebase)
- {
- if (codebase == null)
- return string.Empty;
-
- int position = 0;
- char[]? dest = EscapeString(codebase, 0, codebase.Length, null, ref position, true, c_DummyChar, c_DummyChar, c_DummyChar);
- if (dest == null)
- return codebase;
-
- return new string(dest, 0, position);
- }
-
- // This implementation of EscapeString has been copied from System.Private.Uri from corefx repo
- // - forceX characters are always escaped if found
- // - rsvd character will remain unescaped
- //
- // start - starting offset from input
- // end - the exclusive ending offset in input
- // destPos - starting offset in dest for output, on return this will be an exclusive "end" in the output.
- //
- // In case "dest" has lack of space it will be reallocated by preserving the _whole_ content up to current destPos
- //
- // Returns null if nothing has to be escaped AND passed dest was null, otherwise the resulting array with the updated destPos
- //
- internal static unsafe char[]? EscapeString(string input, int start, int end, char[]? dest, ref int destPos,
- bool isUriString, char force1, char force2, char rsvd)
- {
- int i = start;
- int prevInputPos = start;
- byte* bytes = stackalloc byte[c_MaxUnicodeCharsReallocate * c_MaxUTF_8BytesPerUnicodeChar]; // 40*4=160
-
- fixed (char* pStr = input)
- {
- for (; i < end; ++i)
- {
- char ch = pStr[i];
-
- // a Unicode ?
- if (ch > '\x7F')
- {
- short maxSize = (short)Math.Min(end - i, (int)c_MaxUnicodeCharsReallocate - 1);
-
- short count = 1;
- for (; count < maxSize && pStr[i + count] > '\x7f'; ++count) ;
-
- // Is the last a high surrogate?
- if (pStr[i + count - 1] >= 0xD800 && pStr[i + count - 1] <= 0xDBFF)
- {
- // Should be a rare case where the app tries to feed an invalid Unicode surrogates pair
- if (count == 1 || count == end - i)
- throw new FormatException(SR.Arg_FormatException);
- // need to grab one more char as a Surrogate except when it's a bogus input
- ++count;
- }
-
- dest = EnsureDestinationSize(pStr, dest, i,
- (short)(count * c_MaxUTF_8BytesPerUnicodeChar * c_EncodedCharsPerByte),
- c_MaxUnicodeCharsReallocate * c_MaxUTF_8BytesPerUnicodeChar * c_EncodedCharsPerByte,
- ref destPos, prevInputPos);
-
- short numberOfBytes = (short)Encoding.UTF8.GetBytes(pStr + i, count, bytes,
- c_MaxUnicodeCharsReallocate * c_MaxUTF_8BytesPerUnicodeChar);
-
- // This is the only exception that built in UriParser can throw after a Uri ctor.
- // Should not happen unless the app tries to feed an invalid Unicode string
- if (numberOfBytes == 0)
- throw new FormatException(SR.Arg_FormatException);
-
- i += (count - 1);
-
- for (count = 0; count < numberOfBytes; ++count)
- EscapeAsciiChar((char)bytes[count], dest, ref destPos);
-
- prevInputPos = i + 1;
- }
- else if (ch == '%' && rsvd == '%')
- {
- // Means we don't reEncode '%' but check for the possible escaped sequence
- dest = EnsureDestinationSize(pStr, dest, i, c_EncodedCharsPerByte,
- c_MaxAsciiCharsReallocate * c_EncodedCharsPerByte, ref destPos, prevInputPos);
- if (i + 2 < end && EscapedAscii(pStr[i + 1], pStr[i + 2]) != c_DummyChar)
- {
- // leave it escaped
- dest[destPos++] = '%';
- dest[destPos++] = pStr[i + 1];
- dest[destPos++] = pStr[i + 2];
- i += 2;
- }
- else
- {
- EscapeAsciiChar('%', dest, ref destPos);
- }
- prevInputPos = i + 1;
- }
- else if (ch == force1 || ch == force2 || (ch != rsvd && (isUriString ? !IsReservedUnreservedOrHash(ch) : !IsUnreserved(ch))))
- {
- dest = EnsureDestinationSize(pStr, dest, i, c_EncodedCharsPerByte,
- c_MaxAsciiCharsReallocate * c_EncodedCharsPerByte, ref destPos, prevInputPos);
- EscapeAsciiChar(ch, dest, ref destPos);
- prevInputPos = i + 1;
- }
- }
-
- if (prevInputPos != i)
- {
- // need to fill up the dest array ?
- if (prevInputPos != start || dest != null)
- dest = EnsureDestinationSize(pStr, dest, i, 0, 0, ref destPos, prevInputPos);
- }
- }
-
- return dest;
- }
-
- //
- // ensure destination array has enough space and contains all the needed input stuff
- //
- private static unsafe char[] EnsureDestinationSize(char* pStr, char[]? dest, int currentInputPos,
- short charsToAdd, short minReallocateChars, ref int destPos, int prevInputPos)
- {
- if (dest is null || dest.Length < destPos + (currentInputPos - prevInputPos) + charsToAdd)
- {
- // allocating or reallocating array by ensuring enough space based on maxCharsToAdd.
- char[] newresult = new char[destPos + (currentInputPos - prevInputPos) + minReallocateChars];
-
- if (!(dest is null) && destPos != 0)
- Buffer.BlockCopy(dest, 0, newresult, 0, destPos << 1);
- dest = newresult;
- }
-
- // ensuring we copied everything form the input string left before last escaping
- while (prevInputPos != currentInputPos)
- dest[destPos++] = pStr[prevInputPos++];
- return dest;
- }
-
- internal static void EscapeAsciiChar(char ch, char[] to, ref int pos)
- {
- to[pos++] = '%';
- to[pos++] = s_hexUpperChars[(ch & 0xf0) >> 4];
- to[pos++] = s_hexUpperChars[ch & 0xf];
- }
-
- internal static char EscapedAscii(char digit, char next)
- {
- if (!(((digit >= '0') && (digit <= '9'))
- || ((digit >= 'A') && (digit <= 'F'))
- || ((digit >= 'a') && (digit <= 'f'))))
- {
- return c_DummyChar;
- }
-
- int res = (digit <= '9')
- ? ((int)digit - (int)'0')
- : (((digit <= 'F')
- ? ((int)digit - (int)'A')
- : ((int)digit - (int)'a'))
- + 10);
-
- if (!(((next >= '0') && (next <= '9'))
- || ((next >= 'A') && (next <= 'F'))
- || ((next >= 'a') && (next <= 'f'))))
- {
- return c_DummyChar;
- }
-
- return (char)((res << 4) + ((next <= '9')
- ? ((int)next - (int)'0')
- : (((next <= 'F')
- ? ((int)next - (int)'A')
- : ((int)next - (int)'a'))
- + 10)));
- }
-
- private static bool IsReservedUnreservedOrHash(char c)
- {
- if (IsUnreserved(c))
- {
- return true;
- }
- return RFC3986ReservedMarks.Contains(c);
- }
-
- internal static bool IsUnreserved(char c)
- {
- if (IsAsciiLetterOrDigit(c))
- {
- return true;
- }
- return RFC3986UnreservedMarks.Contains(c);
- }
-
- // Only consider ASCII characters
- internal static bool IsAsciiLetter(char character)
- {
- return (character >= 'a' && character <= 'z') ||
- (character >= 'A' && character <= 'Z');
- }
-
- internal static bool IsAsciiLetterOrDigit(char character)
- {
- return IsAsciiLetter(character) || (character >= '0' && character <= '9');
- }
-
- private static readonly char[] s_hexUpperChars = {
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
- internal const char c_DummyChar = (char)0xFFFF; // An Invalid Unicode character used as a dummy char passed into the parameter
- private const short c_MaxAsciiCharsReallocate = 40;
- private const short c_MaxUnicodeCharsReallocate = 40;
- private const short c_MaxUTF_8BytesPerUnicodeChar = 4;
- private const short c_EncodedCharsPerByte = 3;
- private const string RFC3986ReservedMarks = ":/?#[]@!$&'()*+,;=";
- private const string RFC3986UnreservedMarks = "-._~";
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFlags.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFlags.cs
deleted file mode 100644
index f32f4af01c4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFlags.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Reflection
-{
- [Flags]
- public enum AssemblyNameFlags
- {
- None = 0x0000,
- // Flag used to indicate that an assembly ref contains the full public key, not the compressed token.
- // Must match afPublicKey in CorHdr.h.
- PublicKey = 0x0001,
- // ProcArchMask = 0x00F0, // Bits describing the processor architecture
- // Accessible via AssemblyName.ProcessorArchitecture
- EnableJITcompileOptimizer = 0x4000,
- EnableJITcompileTracking = 0x8000,
- Retargetable = 0x0100,
- // ContentType = 0x0E00, // Bits describing the ContentType are accessible via AssemblyName.ContentType
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFormatter.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFormatter.cs
deleted file mode 100644
index 09585f8d58f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFormatter.cs
+++ /dev/null
@@ -1,154 +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 System.IO;
-using System.Text;
-using System.Globalization;
-using System.Collections.Generic;
-
-namespace System.Reflection
-{
- internal static class AssemblyNameFormatter
- {
- public static string ComputeDisplayName(string? name, Version? version, string? cultureName, byte[]? pkt, AssemblyNameFlags flags, AssemblyContentType contentType)
- {
- const int PUBLIC_KEY_TOKEN_LEN = 8;
-
- if (name == string.Empty)
- throw new FileLoadException();
-
- StringBuilder sb = new StringBuilder();
- if (name != null)
- {
- sb.AppendQuoted(name);
- }
-
- if (version != null)
- {
- Version canonicalizedVersion = version.CanonicalizeVersion();
- if (canonicalizedVersion.Major != ushort.MaxValue)
- {
- sb.Append(", Version=");
- sb.Append(canonicalizedVersion.Major);
-
- if (canonicalizedVersion.Minor != ushort.MaxValue)
- {
- sb.Append('.');
- sb.Append(canonicalizedVersion.Minor);
-
- if (canonicalizedVersion.Build != ushort.MaxValue)
- {
- sb.Append('.');
- sb.Append(canonicalizedVersion.Build);
-
- if (canonicalizedVersion.Revision != ushort.MaxValue)
- {
- sb.Append('.');
- sb.Append(canonicalizedVersion.Revision);
- }
- }
- }
- }
- }
-
- if (cultureName != null)
- {
- if (cultureName == string.Empty)
- cultureName = "neutral";
- sb.Append(", Culture=");
- sb.AppendQuoted(cultureName);
- }
-
- if (pkt != null)
- {
- if (pkt.Length > PUBLIC_KEY_TOKEN_LEN)
- throw new ArgumentException();
-
- sb.Append(", PublicKeyToken=");
- if (pkt.Length == 0)
- sb.Append("null");
- else
- {
- foreach (byte b in pkt)
- {
- sb.Append(b.ToString("x2", CultureInfo.InvariantCulture));
- }
- }
- }
-
- if (0 != (flags & AssemblyNameFlags.Retargetable))
- sb.Append(", Retargetable=Yes");
-
- if (contentType == AssemblyContentType.WindowsRuntime)
- sb.Append(", ContentType=WindowsRuntime");
-
- // NOTE: By design (desktop compat) AssemblyName.FullName and ToString() do not include ProcessorArchitecture.
-
- return sb.ToString();
- }
-
- private static void AppendQuoted(this StringBuilder sb, string s)
- {
- bool needsQuoting = false;
- const char quoteChar = '\"';
-
- // App-compat: You can use double or single quotes to quote a name, and Fusion (or rather the IdentityAuthority) picks one
- // by some algorithm. Rather than guess at it, we use double quotes consistently.
- if (s != s.Trim() || s.Contains('\"') || s.Contains('\''))
- needsQuoting = true;
-
- if (needsQuoting)
- sb.Append(quoteChar);
-
- for (int i = 0; i < s.Length; i++)
- {
- bool addedEscape = false;
- foreach (KeyValuePair<char, string> kv in EscapeSequences)
- {
- string escapeReplacement = kv.Value;
- if (!(s[i] == escapeReplacement[0]))
- continue;
- if ((s.Length - i) < escapeReplacement.Length)
- continue;
- if (s.AsSpan(i, escapeReplacement.Length).SequenceEqual(escapeReplacement))
- {
- sb.Append('\\');
- sb.Append(kv.Key);
- addedEscape = true;
- }
- }
-
- if (!addedEscape)
- sb.Append(s[i]);
- }
-
- if (needsQuoting)
- sb.Append(quoteChar);
- }
-
- private static Version CanonicalizeVersion(this Version version)
- {
- ushort major = (ushort)version.Major;
- ushort minor = (ushort)version.Minor;
- ushort build = (ushort)version.Build;
- ushort revision = (ushort)version.Revision;
-
- if (major == version.Major && minor == version.Minor && build == version.Build && revision == version.Revision)
- return version;
-
- return new Version(major, minor, build, revision);
- }
-
- public static KeyValuePair<char, string>[] EscapeSequences =
- {
- new KeyValuePair<char, string>('\\', "\\"),
- new KeyValuePair<char, string>(',', ","),
- new KeyValuePair<char, string>('=', "="),
- new KeyValuePair<char, string>('\'', "'"),
- new KeyValuePair<char, string>('\"', "\""),
- new KeyValuePair<char, string>('n', Environment.NewLineConst),
- new KeyValuePair<char, string>('t', "\t"),
- };
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyProductAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyProductAttribute.cs
deleted file mode 100644
index acff50797f3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyProductAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyProductAttribute : Attribute
- {
- public AssemblyProductAttribute(string product)
- {
- Product = product;
- }
-
- public string Product { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblySignatureKeyAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblySignatureKeyAttribute.cs
deleted file mode 100644
index cf48f95f48e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblySignatureKeyAttribute.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]
- public sealed class AssemblySignatureKeyAttribute : Attribute
- {
- public AssemblySignatureKeyAttribute(string publicKey, string countersignature)
- {
- PublicKey = publicKey;
- Countersignature = countersignature;
- }
-
- public string PublicKey { get; }
-
- public string Countersignature { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyTitleAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyTitleAttribute.cs
deleted file mode 100644
index bc588dfbf34..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyTitleAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyTitleAttribute : Attribute
- {
- public AssemblyTitleAttribute(string title)
- {
- Title = title;
- }
-
- public string Title { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyTrademarkAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyTrademarkAttribute.cs
deleted file mode 100644
index 3f3c9a2dd95..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyTrademarkAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyTrademarkAttribute : Attribute
- {
- public AssemblyTrademarkAttribute(string trademark)
- {
- Trademark = trademark;
- }
-
- public string Trademark { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyVersionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyVersionAttribute.cs
deleted file mode 100644
index 1f78fc19f77..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/AssemblyVersionAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class AssemblyVersionAttribute : Attribute
- {
- public AssemblyVersionAttribute(string version)
- {
- Version = version;
- }
-
- public string Version { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Binder.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Binder.cs
deleted file mode 100644
index 10b6f7de1bc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Binder.cs
+++ /dev/null
@@ -1,19 +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 System.Globalization;
-
-namespace System.Reflection
-{
- public abstract class Binder
- {
- protected Binder() { }
- public abstract FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo[] match, object value, CultureInfo? culture);
- public abstract MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object?[] args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? names, out object? state);
- public abstract object ChangeType(object value, Type type, CultureInfo? culture);
- public abstract void ReorderArgumentArray(ref object?[] args, object state);
- public abstract MethodBase? SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[]? modifiers);
- public abstract PropertyInfo? SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type? returnType, Type[]? indexes, ParameterModifier[]? modifiers);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/BindingFlags.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/BindingFlags.cs
deleted file mode 100644
index 054ee6401a8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/BindingFlags.cs
+++ /dev/null
@@ -1,51 +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.
-
-namespace System.Reflection
-{
- [Flags]
- public enum BindingFlags
- {
- // NOTES: We have lookup masks defined in RuntimeType and Activator. If we
- // change the lookup values then these masks may need to change also.
-
- // a place holder for no flag specifed
- Default = 0x00,
-
- // These flags indicate what to search for when binding
- IgnoreCase = 0x01, // Ignore the case of Names while searching
- DeclaredOnly = 0x02, // Only look at the members declared on the Type
- Instance = 0x04, // Include Instance members in search
- Static = 0x08, // Include Static members in search
- Public = 0x10, // Include Public members in search
- NonPublic = 0x20, // Include Non-Public members in search
- FlattenHierarchy = 0x40, // Rollup the statics into the class.
-
- // These flags are used by InvokeMember to determine
- // what type of member we are trying to Invoke.
- // BindingAccess = 0xFF00;
- InvokeMethod = 0x0100,
- CreateInstance = 0x0200,
- GetField = 0x0400,
- SetField = 0x0800,
- GetProperty = 0x1000,
- SetProperty = 0x2000,
-
- // These flags are also used by InvokeMember but they should only
- // be used when calling InvokeMember on a COM object.
- PutDispProperty = 0x4000,
- PutRefDispProperty = 0x8000,
-
- ExactBinding = 0x010000, // Bind with Exact Type matching, No Change type
- SuppressChangeType = 0x020000,
-
- // DefaultValueBinding will return the set of methods having ArgCount or
- // more parameters. This is used for default values, etc.
- OptionalParamBinding = 0x040000,
-
- // These are a couple of misc attributes used
- IgnoreReturn = 0x01000000, // This is used in COM Interop
- DoNotWrapExceptions = 0x02000000, // Disables wrapping exceptions in TargetInvocationException
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/CallingConventions.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/CallingConventions.cs
deleted file mode 100644
index 1f159658970..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/CallingConventions.cs
+++ /dev/null
@@ -1,19 +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.
-
-// CallingConventions is a set of Bits representing the calling conventions in the system.
-
-namespace System.Reflection
-{
- [Flags]
- public enum CallingConventions
- {
- // Keep in sync with COMMember.cpp.
- Standard = 0x0001,
- VarArgs = 0x0002,
- Any = Standard | VarArgs,
- HasThis = 0x0020,
- ExplicitThis = 0x0040,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ConstructorInfo.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ConstructorInfo.cs
deleted file mode 100644
index 8b376025659..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ConstructorInfo.cs
+++ /dev/null
@@ -1,50 +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 System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-
-namespace System.Reflection
-{
- public abstract partial class ConstructorInfo : MethodBase
- {
- protected ConstructorInfo() { }
-
- public override MemberTypes MemberType => MemberTypes.Constructor;
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public object Invoke(object?[]? parameters) => Invoke(BindingFlags.Default, binder: null, parameters: parameters, culture: null);
- public abstract object Invoke(BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture);
-
- public override bool Equals(object? obj) => base.Equals(obj);
- public override int GetHashCode() => base.GetHashCode();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(ConstructorInfo? left, ConstructorInfo? right)
- {
- // Test "right" first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (right is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (left is null) ? true : false;
- }
-
- // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
- if ((object?)left == (object)right)
- {
- return true;
- }
-
- return (left is null) ? false : left.Equals(right);
- }
-
- public static bool operator !=(ConstructorInfo? left, ConstructorInfo? right) => !(left == right);
-
- public static readonly string ConstructorName = ".ctor";
- public static readonly string TypeConstructorName = ".cctor";
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/CorElementType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/CorElementType.cs
deleted file mode 100644
index 37ffcfa1e25..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/CorElementType.cs
+++ /dev/null
@@ -1,46 +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.
-
-namespace System.Reflection
-{
- internal enum CorElementType : byte
- {
- ELEMENT_TYPE_END = 0x00,
- ELEMENT_TYPE_VOID = 0x01,
- ELEMENT_TYPE_BOOLEAN = 0x02,
- ELEMENT_TYPE_CHAR = 0x03,
- ELEMENT_TYPE_I1 = 0x04,
- ELEMENT_TYPE_U1 = 0x05,
- ELEMENT_TYPE_I2 = 0x06,
- ELEMENT_TYPE_U2 = 0x07,
- ELEMENT_TYPE_I4 = 0x08,
- ELEMENT_TYPE_U4 = 0x09,
- ELEMENT_TYPE_I8 = 0x0A,
- ELEMENT_TYPE_U8 = 0x0B,
- ELEMENT_TYPE_R4 = 0x0C,
- ELEMENT_TYPE_R8 = 0x0D,
- ELEMENT_TYPE_STRING = 0x0E,
- ELEMENT_TYPE_PTR = 0x0F,
- ELEMENT_TYPE_BYREF = 0x10,
- ELEMENT_TYPE_VALUETYPE = 0x11,
- ELEMENT_TYPE_CLASS = 0x12,
- ELEMENT_TYPE_VAR = 0x13,
- ELEMENT_TYPE_ARRAY = 0x14,
- ELEMENT_TYPE_GENERICINST = 0x15,
- ELEMENT_TYPE_TYPEDBYREF = 0x16,
- ELEMENT_TYPE_I = 0x18,
- ELEMENT_TYPE_U = 0x19,
- ELEMENT_TYPE_FNPTR = 0x1B,
- ELEMENT_TYPE_OBJECT = 0x1C,
- ELEMENT_TYPE_SZARRAY = 0x1D,
- ELEMENT_TYPE_MVAR = 0x1E,
- ELEMENT_TYPE_CMOD_REQD = 0x1F,
- ELEMENT_TYPE_CMOD_OPT = 0x20,
- ELEMENT_TYPE_INTERNAL = 0x21,
- ELEMENT_TYPE_MAX = 0x22,
- ELEMENT_TYPE_MODIFIER = 0x40,
- ELEMENT_TYPE_SENTINEL = 0x41,
- ELEMENT_TYPE_PINNED = 0x45,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeExtensions.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeExtensions.cs
deleted file mode 100644
index d2c2d454d96..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeExtensions.cs
+++ /dev/null
@@ -1,175 +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 System.Collections.Generic;
-
-namespace System.Reflection
-{
- public static class CustomAttributeExtensions
- {
- #region APIs that return a single attribute
- public static Attribute? GetCustomAttribute(this Assembly element, Type attributeType)
- {
- return Attribute.GetCustomAttribute(element, attributeType);
- }
- public static Attribute? GetCustomAttribute(this Module element, Type attributeType)
- {
- return Attribute.GetCustomAttribute(element, attributeType);
- }
- public static Attribute? GetCustomAttribute(this MemberInfo element, Type attributeType)
- {
- return Attribute.GetCustomAttribute(element, attributeType);
- }
- public static Attribute? GetCustomAttribute(this ParameterInfo element, Type attributeType)
- {
- return Attribute.GetCustomAttribute(element, attributeType);
- }
-
- public static T? GetCustomAttribute<T>(this Assembly element) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T));
- }
- public static T? GetCustomAttribute<T>(this Module element) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T));
- }
- public static T? GetCustomAttribute<T>(this MemberInfo element) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T));
- }
- public static T? GetCustomAttribute<T>(this ParameterInfo element) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T));
- }
-
- public static Attribute? GetCustomAttribute(this MemberInfo element, Type attributeType, bool inherit)
- {
- return Attribute.GetCustomAttribute(element, attributeType, inherit);
- }
- public static Attribute? GetCustomAttribute(this ParameterInfo element, Type attributeType, bool inherit)
- {
- return Attribute.GetCustomAttribute(element, attributeType, inherit);
- }
-
- public static T? GetCustomAttribute<T>(this MemberInfo element, bool inherit) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T), inherit);
- }
- public static T? GetCustomAttribute<T>(this ParameterInfo element, bool inherit) where T : Attribute
- {
- return (T?)GetCustomAttribute(element, typeof(T), inherit);
- }
- #endregion
-
- #region APIs that return all attributes
- public static IEnumerable<Attribute> GetCustomAttributes(this Assembly element)
- {
- return Attribute.GetCustomAttributes(element);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this Module element)
- {
- return Attribute.GetCustomAttributes(element);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this MemberInfo element)
- {
- return Attribute.GetCustomAttributes(element);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this ParameterInfo element)
- {
- return Attribute.GetCustomAttributes(element);
- }
-
- public static IEnumerable<Attribute> GetCustomAttributes(this MemberInfo element, bool inherit)
- {
- return Attribute.GetCustomAttributes(element, inherit);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this ParameterInfo element, bool inherit)
- {
- return Attribute.GetCustomAttributes(element, inherit);
- }
- #endregion
-
- #region APIs that return all attributes of a particular type
- public static IEnumerable<Attribute> GetCustomAttributes(this Assembly element, Type attributeType)
- {
- return Attribute.GetCustomAttributes(element, attributeType);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this Module element, Type attributeType)
- {
- return Attribute.GetCustomAttributes(element, attributeType);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this MemberInfo element, Type attributeType)
- {
- return Attribute.GetCustomAttributes(element, attributeType);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this ParameterInfo element, Type attributeType)
- {
- return Attribute.GetCustomAttributes(element, attributeType);
- }
-
- public static IEnumerable<T> GetCustomAttributes<T>(this Assembly element) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T));
- }
- public static IEnumerable<T> GetCustomAttributes<T>(this Module element) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T));
- }
- public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo element) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T));
- }
- public static IEnumerable<T> GetCustomAttributes<T>(this ParameterInfo element) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T));
- }
-
- public static IEnumerable<Attribute> GetCustomAttributes(this MemberInfo element, Type attributeType, bool inherit)
- {
- return Attribute.GetCustomAttributes(element, attributeType, inherit);
- }
- public static IEnumerable<Attribute> GetCustomAttributes(this ParameterInfo element, Type attributeType, bool inherit)
- {
- return Attribute.GetCustomAttributes(element, attributeType, inherit);
- }
-
- public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo element, bool inherit) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T), inherit);
- }
- public static IEnumerable<T> GetCustomAttributes<T>(this ParameterInfo element, bool inherit) where T : Attribute
- {
- return (IEnumerable<T>)GetCustomAttributes(element, typeof(T), inherit);
- }
- #endregion
-
- #region IsDefined
- public static bool IsDefined(this Assembly element, Type attributeType)
- {
- return Attribute.IsDefined(element, attributeType);
- }
- public static bool IsDefined(this Module element, Type attributeType)
- {
- return Attribute.IsDefined(element, attributeType);
- }
- public static bool IsDefined(this MemberInfo element, Type attributeType)
- {
- return Attribute.IsDefined(element, attributeType);
- }
- public static bool IsDefined(this ParameterInfo element, Type attributeType)
- {
- return Attribute.IsDefined(element, attributeType);
- }
-
- public static bool IsDefined(this MemberInfo element, Type attributeType, bool inherit)
- {
- return Attribute.IsDefined(element, attributeType, inherit);
- }
- public static bool IsDefined(this ParameterInfo element, Type attributeType, bool inherit)
- {
- return Attribute.IsDefined(element, attributeType, inherit);
- }
- #endregion
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeFormatException.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeFormatException.cs
deleted file mode 100644
index 8bdfb3e5d50..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeFormatException.cs
+++ /dev/null
@@ -1,34 +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 System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class CustomAttributeFormatException : FormatException
- {
- public CustomAttributeFormatException()
- : this(SR.Arg_CustomAttributeFormatException)
- {
- }
-
- public CustomAttributeFormatException(string? message)
- : this(message, null)
- {
- }
-
- public CustomAttributeFormatException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_CUSTOMATTRIBUTEFORMAT;
- }
-
- protected CustomAttributeFormatException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs
deleted file mode 100644
index 8aa4d8fa72d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs
+++ /dev/null
@@ -1,75 +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.
-
-namespace System.Reflection
-{
- public readonly partial struct CustomAttributeNamedArgument
- {
- public static bool operator ==(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right) => left.Equals(right);
- public static bool operator !=(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right) => !left.Equals(right);
-
- private readonly MemberInfo m_memberInfo;
- private readonly CustomAttributeTypedArgument m_value;
-
- public CustomAttributeNamedArgument(MemberInfo memberInfo, object? value)
- {
- if (memberInfo == null)
- throw new ArgumentNullException(nameof(memberInfo));
-
- Type type;
- if (memberInfo is FieldInfo field)
- {
- type = field.FieldType;
- }
- else if (memberInfo is PropertyInfo property)
- {
- type = property.PropertyType;
- }
- else
- {
- throw new ArgumentException(SR.Argument_InvalidMemberForNamedArgument);
- }
-
- m_memberInfo = memberInfo;
- m_value = new CustomAttributeTypedArgument(type, value);
- }
-
- public CustomAttributeNamedArgument(MemberInfo memberInfo, CustomAttributeTypedArgument typedArgument)
- {
- if (memberInfo == null)
- throw new ArgumentNullException(nameof(memberInfo));
-
- m_memberInfo = memberInfo;
- m_value = typedArgument;
- }
-
- public override string ToString()
- {
- if (m_memberInfo == null)
- return base.ToString()!;
-
- return string.Format("{0} = {1}", MemberInfo.Name, TypedValue.ToString(ArgumentType != typeof(object)));
- }
-
- public override int GetHashCode()
- {
- return base.GetHashCode();
- }
-
- public override bool Equals(object? obj)
- {
- return obj == (object)this;
- }
-
- internal Type ArgumentType =>
- m_memberInfo is FieldInfo ?
- ((FieldInfo)m_memberInfo).FieldType :
- ((PropertyInfo)m_memberInfo).PropertyType;
-
- public MemberInfo MemberInfo => m_memberInfo;
- public CustomAttributeTypedArgument TypedValue => m_value;
- public string MemberName => MemberInfo.Name;
- public bool IsField => MemberInfo is FieldInfo;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeTypedArgument.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeTypedArgument.cs
deleted file mode 100644
index 4bee6bd3cd8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/CustomAttributeTypedArgument.cs
+++ /dev/null
@@ -1,82 +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 System.Collections.Generic;
-
-namespace System.Reflection
-{
- public readonly partial struct CustomAttributeTypedArgument
- {
- public static bool operator ==(CustomAttributeTypedArgument left, CustomAttributeTypedArgument right) => left.Equals(right);
-
- public static bool operator !=(CustomAttributeTypedArgument left, CustomAttributeTypedArgument right) => !left.Equals(right);
-
- private readonly object? m_value;
- private readonly Type m_argumentType;
-
- public CustomAttributeTypedArgument(Type argumentType, object? value)
- {
- // value can be null.
- if (argumentType == null)
- throw new ArgumentNullException(nameof(argumentType));
-
- m_value = (value is null) ? null : CanonicalizeValue(value);
- m_argumentType = argumentType;
- }
-
- public CustomAttributeTypedArgument(object value)
- {
- // value cannot be null.
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- m_value = CanonicalizeValue(value);
- m_argumentType = value.GetType();
- }
-
-
- public override string ToString() => ToString(false);
-
- internal string ToString(bool typed)
- {
- if (m_argumentType == null)
- return base.ToString()!;
-
- if (ArgumentType.IsEnum)
- return string.Format(typed ? "{0}" : "({1}){0}", Value, ArgumentType.FullName);
- else if (Value == null)
- return string.Format(typed ? "null" : "({0})null", ArgumentType.Name);
- else if (ArgumentType == typeof(string))
- return string.Format("\"{0}\"", Value);
- else if (ArgumentType == typeof(char))
- return string.Format("'{0}'", Value);
- else if (ArgumentType == typeof(Type))
- return string.Format("typeof({0})", ((Type)Value!).FullName);
- else if (ArgumentType.IsArray)
- {
- IList<CustomAttributeTypedArgument> array = (IList<CustomAttributeTypedArgument>)Value!;
-
- Type elementType = ArgumentType.GetElementType()!;
- string result = string.Format("new {0}[{1}] {{ ", elementType.IsEnum ? elementType.FullName : elementType.Name, array.Count);
-
- for (int i = 0; i < array.Count; i++)
- {
- result += string.Format(i == 0 ? "{0}" : ", {0}", array[i].ToString(elementType != typeof(object)));
- }
-
- result += " }";
-
- return result;
- }
-
- return string.Format(typed ? "{0}" : "({1}){0}", Value, ArgumentType.Name);
- }
-
- public override int GetHashCode() => base.GetHashCode();
- public override bool Equals(object? obj) => obj == (object)this;
-
- public Type ArgumentType => m_argumentType;
- public object? Value => m_value;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/DefaultMemberAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/DefaultMemberAttribute.cs
deleted file mode 100644
index 585fdb07cd0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/DefaultMemberAttribute.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface)]
- public sealed class DefaultMemberAttribute : Attribute
- {
- // You must provide the name of the member, this is required
- public DefaultMemberAttribute(string memberName)
- {
- MemberName = memberName;
- }
-
- // A get accessor to return the name from the attribute.
- // NOTE: There is no setter because the name must be provided
- // to the constructor. The name is not optional.
- public string MemberName { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/AssemblyBuilderAccess.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/AssemblyBuilderAccess.cs
deleted file mode 100644
index 8527463eec8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/AssemblyBuilderAccess.cs
+++ /dev/null
@@ -1,16 +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.
-
-// This enumeration defines the access modes for a dynamic assembly.
-// EE uses these enum values..look for m_dwDynamicAssemblyAccess in Assembly.hpp
-
-namespace System.Reflection.Emit
-{
- [Flags]
- public enum AssemblyBuilderAccess
- {
- Run = 1,
- RunAndCollect = 8 | Run
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/EventToken.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/EventToken.cs
deleted file mode 100644
index 2342f6edeb0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/EventToken.cs
+++ /dev/null
@@ -1,28 +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.
-
-namespace System.Reflection.Emit
-{
- public struct EventToken
- {
- public static readonly EventToken Empty = default;
-
- internal EventToken(int eventToken)
- {
- Token = eventToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is EventToken et && Equals(et);
-
- public bool Equals(EventToken obj) => obj.Token == Token;
-
- public static bool operator ==(EventToken a, EventToken b) => a.Equals(b);
-
- public static bool operator !=(EventToken a, EventToken b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/FieldToken.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/FieldToken.cs
deleted file mode 100644
index e695c021528..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/FieldToken.cs
+++ /dev/null
@@ -1,37 +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.
-
-namespace System.Reflection.Emit
-{
- /// <summary>
- /// The FieldToken class is an opaque representation of the Token returned
- /// by the Metadata to represent the field. FieldTokens are generated by
- /// Module.GetFieldToken(). There are no meaningful accessors on this class,
- /// but it can be passed to ILGenerator which understands it's internals.
- /// </summary>
- public struct FieldToken
- {
- public static readonly FieldToken Empty = default;
-
- private readonly object _class;
-
- internal FieldToken(int fieldToken, Type fieldClass)
- {
- Token = fieldToken;
- _class = fieldClass;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is FieldToken ft && Equals(ft);
-
- public bool Equals(FieldToken obj) => obj.Token == Token && obj._class == _class;
-
- public static bool operator ==(FieldToken a, FieldToken b) => a.Equals(b);
-
- public static bool operator !=(FieldToken a, FieldToken b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/FlowControl.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/FlowControl.cs
deleted file mode 100644
index 9cb947ce5a9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/FlowControl.cs
+++ /dev/null
@@ -1,30 +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.
-
-/*============================================================
-**
-** Enumeration: FlowControl
-**
-** Purpose: Exposes FlowControl Attribute of IL.
-**
-** THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND!
-** See $(RepoRoot)\src\inc\OpCodeGen.pl for more information.**
-==============================================================*/
-
-namespace System.Reflection.Emit
-{
- public enum FlowControl
- {
- Branch = 0,
- Break = 1,
- Call = 2,
- Cond_Branch = 3,
- Meta = 4,
- Next = 5,
- [Obsolete("This API has been deprecated. https://go.microsoft.com/fwlink/?linkid=14202")]
- Phi = 6,
- Return = 7,
- Throw = 8,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/Label.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/Label.cs
deleted file mode 100644
index 5f47910a05e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/Label.cs
+++ /dev/null
@@ -1,45 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-**
-** Purpose: Represents a Label to the ILGenerator class.
-**
-**
-===========================================================*/
-
-namespace System.Reflection.Emit
-{
- // The Label class is an opaque representation of a label used by the
- // ILGenerator class. The token is used to mark where labels occur in the IL
- // stream and then the necessary offsets are put back in the code when the ILGenerator
- // is passed to the MethodWriter.
- // Labels are created by using ILGenerator.CreateLabel and their position is set
- // by using ILGenerator.MarkLabel.
- public readonly struct Label : IEquatable<Label>
- {
- internal readonly int m_label;
-
- internal Label(int label) => m_label = label;
-
- internal int GetLabelValue() => m_label;
-
- public override int GetHashCode() => m_label;
-
- public override bool Equals(object? obj) =>
- obj is Label other && Equals(other);
-
- public bool Equals(Label obj) =>
- obj.m_label == m_label;
-
- public static bool operator ==(Label a, Label b) => a.Equals(b);
-
- public static bool operator !=(Label a, Label b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/MethodToken.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/MethodToken.cs
deleted file mode 100644
index eb8c15a9b31..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/MethodToken.cs
+++ /dev/null
@@ -1,28 +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.
-
-namespace System.Reflection.Emit
-{
- public struct MethodToken
- {
- public static readonly MethodToken Empty = default;
-
- internal MethodToken(int methodToken)
- {
- Token = methodToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is MethodToken mt && Equals(mt);
-
- public bool Equals(MethodToken obj) => obj.Token == Token;
-
- public static bool operator ==(MethodToken a, MethodToken b) => a.Equals(b);
-
- public static bool operator !=(MethodToken a, MethodToken b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OpCodeType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OpCodeType.cs
deleted file mode 100644
index 914b0374d55..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OpCodeType.cs
+++ /dev/null
@@ -1,27 +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.
-
-/*============================================================
-**
-** Enumeration: OpCodeType
-**
-** Purpose: Exposes OpCodeType Attribute of IL.
-**
-** THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND!
-** See $(RepoRoot)\src\inc\OpCodeGen.pl for more information.**
-==============================================================*/
-
-namespace System.Reflection.Emit
-{
- public enum OpCodeType
- {
- [Obsolete("This API has been deprecated. https://go.microsoft.com/fwlink/?linkid=14202")]
- Annotation = 0,
- Macro = 1,
- Nternal = 2,
- Objmodel = 3,
- Prefix = 4,
- Primitive = 5,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OpCodes.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OpCodes.cs
deleted file mode 100644
index 07c4b1ceb7e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OpCodes.cs
+++ /dev/null
@@ -1,2549 +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.
-
-/*============================================================
-**
-** Class: OpCodes
-**
-** Purpose: Exposes all of the IL instructions supported by the runtime.
-**
-** THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND!
-** See $(RepoRoot)\src\inc\OpCodeGen.pl for more information.**
-==============================================================*/
-
-namespace System.Reflection.Emit
-{
- //
- // Internal enums for opcode values. Note that the value names are used to construct
- // publicly visible ilasm-compatible opcode names, so their exact form is important!
- //
- internal enum OpCodeValues
- {
- Nop = 0x00,
- Break = 0x01,
- Ldarg_0 = 0x02,
- Ldarg_1 = 0x03,
- Ldarg_2 = 0x04,
- Ldarg_3 = 0x05,
- Ldloc_0 = 0x06,
- Ldloc_1 = 0x07,
- Ldloc_2 = 0x08,
- Ldloc_3 = 0x09,
- Stloc_0 = 0x0a,
- Stloc_1 = 0x0b,
- Stloc_2 = 0x0c,
- Stloc_3 = 0x0d,
- Ldarg_S = 0x0e,
- Ldarga_S = 0x0f,
- Starg_S = 0x10,
- Ldloc_S = 0x11,
- Ldloca_S = 0x12,
- Stloc_S = 0x13,
- Ldnull = 0x14,
- Ldc_I4_M1 = 0x15,
- Ldc_I4_0 = 0x16,
- Ldc_I4_1 = 0x17,
- Ldc_I4_2 = 0x18,
- Ldc_I4_3 = 0x19,
- Ldc_I4_4 = 0x1a,
- Ldc_I4_5 = 0x1b,
- Ldc_I4_6 = 0x1c,
- Ldc_I4_7 = 0x1d,
- Ldc_I4_8 = 0x1e,
- Ldc_I4_S = 0x1f,
- Ldc_I4 = 0x20,
- Ldc_I8 = 0x21,
- Ldc_R4 = 0x22,
- Ldc_R8 = 0x23,
- Dup = 0x25,
- Pop = 0x26,
- Jmp = 0x27,
- Call = 0x28,
- Calli = 0x29,
- Ret = 0x2a,
- Br_S = 0x2b,
- Brfalse_S = 0x2c,
- Brtrue_S = 0x2d,
- Beq_S = 0x2e,
- Bge_S = 0x2f,
- Bgt_S = 0x30,
- Ble_S = 0x31,
- Blt_S = 0x32,
- Bne_Un_S = 0x33,
- Bge_Un_S = 0x34,
- Bgt_Un_S = 0x35,
- Ble_Un_S = 0x36,
- Blt_Un_S = 0x37,
- Br = 0x38,
- Brfalse = 0x39,
- Brtrue = 0x3a,
- Beq = 0x3b,
- Bge = 0x3c,
- Bgt = 0x3d,
- Ble = 0x3e,
- Blt = 0x3f,
- Bne_Un = 0x40,
- Bge_Un = 0x41,
- Bgt_Un = 0x42,
- Ble_Un = 0x43,
- Blt_Un = 0x44,
- Switch = 0x45,
- Ldind_I1 = 0x46,
- Ldind_U1 = 0x47,
- Ldind_I2 = 0x48,
- Ldind_U2 = 0x49,
- Ldind_I4 = 0x4a,
- Ldind_U4 = 0x4b,
- Ldind_I8 = 0x4c,
- Ldind_I = 0x4d,
- Ldind_R4 = 0x4e,
- Ldind_R8 = 0x4f,
- Ldind_Ref = 0x50,
- Stind_Ref = 0x51,
- Stind_I1 = 0x52,
- Stind_I2 = 0x53,
- Stind_I4 = 0x54,
- Stind_I8 = 0x55,
- Stind_R4 = 0x56,
- Stind_R8 = 0x57,
- Add = 0x58,
- Sub = 0x59,
- Mul = 0x5a,
- Div = 0x5b,
- Div_Un = 0x5c,
- Rem = 0x5d,
- Rem_Un = 0x5e,
- And = 0x5f,
- Or = 0x60,
- Xor = 0x61,
- Shl = 0x62,
- Shr = 0x63,
- Shr_Un = 0x64,
- Neg = 0x65,
- Not = 0x66,
- Conv_I1 = 0x67,
- Conv_I2 = 0x68,
- Conv_I4 = 0x69,
- Conv_I8 = 0x6a,
- Conv_R4 = 0x6b,
- Conv_R8 = 0x6c,
- Conv_U4 = 0x6d,
- Conv_U8 = 0x6e,
- Callvirt = 0x6f,
- Cpobj = 0x70,
- Ldobj = 0x71,
- Ldstr = 0x72,
- Newobj = 0x73,
- Castclass = 0x74,
- Isinst = 0x75,
- Conv_R_Un = 0x76,
- Unbox = 0x79,
- Throw = 0x7a,
- Ldfld = 0x7b,
- Ldflda = 0x7c,
- Stfld = 0x7d,
- Ldsfld = 0x7e,
- Ldsflda = 0x7f,
- Stsfld = 0x80,
- Stobj = 0x81,
- Conv_Ovf_I1_Un = 0x82,
- Conv_Ovf_I2_Un = 0x83,
- Conv_Ovf_I4_Un = 0x84,
- Conv_Ovf_I8_Un = 0x85,
- Conv_Ovf_U1_Un = 0x86,
- Conv_Ovf_U2_Un = 0x87,
- Conv_Ovf_U4_Un = 0x88,
- Conv_Ovf_U8_Un = 0x89,
- Conv_Ovf_I_Un = 0x8a,
- Conv_Ovf_U_Un = 0x8b,
- Box = 0x8c,
- Newarr = 0x8d,
- Ldlen = 0x8e,
- Ldelema = 0x8f,
- Ldelem_I1 = 0x90,
- Ldelem_U1 = 0x91,
- Ldelem_I2 = 0x92,
- Ldelem_U2 = 0x93,
- Ldelem_I4 = 0x94,
- Ldelem_U4 = 0x95,
- Ldelem_I8 = 0x96,
- Ldelem_I = 0x97,
- Ldelem_R4 = 0x98,
- Ldelem_R8 = 0x99,
- Ldelem_Ref = 0x9a,
- Stelem_I = 0x9b,
- Stelem_I1 = 0x9c,
- Stelem_I2 = 0x9d,
- Stelem_I4 = 0x9e,
- Stelem_I8 = 0x9f,
- Stelem_R4 = 0xa0,
- Stelem_R8 = 0xa1,
- Stelem_Ref = 0xa2,
- Ldelem = 0xa3,
- Stelem = 0xa4,
- Unbox_Any = 0xa5,
- Conv_Ovf_I1 = 0xb3,
- Conv_Ovf_U1 = 0xb4,
- Conv_Ovf_I2 = 0xb5,
- Conv_Ovf_U2 = 0xb6,
- Conv_Ovf_I4 = 0xb7,
- Conv_Ovf_U4 = 0xb8,
- Conv_Ovf_I8 = 0xb9,
- Conv_Ovf_U8 = 0xba,
- Refanyval = 0xc2,
- Ckfinite = 0xc3,
- Mkrefany = 0xc6,
- Ldtoken = 0xd0,
- Conv_U2 = 0xd1,
- Conv_U1 = 0xd2,
- Conv_I = 0xd3,
- Conv_Ovf_I = 0xd4,
- Conv_Ovf_U = 0xd5,
- Add_Ovf = 0xd6,
- Add_Ovf_Un = 0xd7,
- Mul_Ovf = 0xd8,
- Mul_Ovf_Un = 0xd9,
- Sub_Ovf = 0xda,
- Sub_Ovf_Un = 0xdb,
- Endfinally = 0xdc,
- Leave = 0xdd,
- Leave_S = 0xde,
- Stind_I = 0xdf,
- Conv_U = 0xe0,
- Prefix7 = 0xf8,
- Prefix6 = 0xf9,
- Prefix5 = 0xfa,
- Prefix4 = 0xfb,
- Prefix3 = 0xfc,
- Prefix2 = 0xfd,
- Prefix1 = 0xfe,
- Prefixref = 0xff,
- Arglist = 0xfe00,
- Ceq = 0xfe01,
- Cgt = 0xfe02,
- Cgt_Un = 0xfe03,
- Clt = 0xfe04,
- Clt_Un = 0xfe05,
- Ldftn = 0xfe06,
- Ldvirtftn = 0xfe07,
- Ldarg = 0xfe09,
- Ldarga = 0xfe0a,
- Starg = 0xfe0b,
- Ldloc = 0xfe0c,
- Ldloca = 0xfe0d,
- Stloc = 0xfe0e,
- Localloc = 0xfe0f,
- Endfilter = 0xfe11,
- Unaligned_ = 0xfe12,
- Volatile_ = 0xfe13,
- Tail_ = 0xfe14,
- Initobj = 0xfe15,
- Constrained_ = 0xfe16,
- Cpblk = 0xfe17,
- Initblk = 0xfe18,
- Rethrow = 0xfe1a,
- Sizeof = 0xfe1c,
- Refanytype = 0xfe1d,
- Readonly_ = 0xfe1e,
- // If you add more opcodes here, modify OpCode.Name to handle them correctly
- }
-
- /// <summary>
- /// <para>
- /// The IL instruction opcodes supported by the
- /// runtime. The IL Instruction Specification describes each
- /// Opcode.
- /// </para>
- /// </summary>
- /// <seealso topic='IL Instruction Set Specification'/>
- public class OpCodes
- {
- private OpCodes()
- {
- }
-
- public static readonly OpCode Nop = new OpCode(OpCodeValues.Nop,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Break = new OpCode(OpCodeValues.Break,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Break << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldarg_0 = new OpCode(OpCodeValues.Ldarg_0,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldarg_1 = new OpCode(OpCodeValues.Ldarg_1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldarg_2 = new OpCode(OpCodeValues.Ldarg_2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldarg_3 = new OpCode(OpCodeValues.Ldarg_3,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldloc_0 = new OpCode(OpCodeValues.Ldloc_0,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldloc_1 = new OpCode(OpCodeValues.Ldloc_1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldloc_2 = new OpCode(OpCodeValues.Ldloc_2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldloc_3 = new OpCode(OpCodeValues.Ldloc_3,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stloc_0 = new OpCode(OpCodeValues.Stloc_0,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stloc_1 = new OpCode(OpCodeValues.Stloc_1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stloc_2 = new OpCode(OpCodeValues.Stloc_2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stloc_3 = new OpCode(OpCodeValues.Stloc_3,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldarg_S = new OpCode(OpCodeValues.Ldarg_S,
- ((int)OperandType.ShortInlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldarga_S = new OpCode(OpCodeValues.Ldarga_S,
- ((int)OperandType.ShortInlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Starg_S = new OpCode(OpCodeValues.Starg_S,
- ((int)OperandType.ShortInlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldloc_S = new OpCode(OpCodeValues.Ldloc_S,
- ((int)OperandType.ShortInlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldloca_S = new OpCode(OpCodeValues.Ldloca_S,
- ((int)OperandType.ShortInlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stloc_S = new OpCode(OpCodeValues.Stloc_S,
- ((int)OperandType.ShortInlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldnull = new OpCode(OpCodeValues.Ldnull,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushref << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4_M1 = new OpCode(OpCodeValues.Ldc_I4_M1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4_0 = new OpCode(OpCodeValues.Ldc_I4_0,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4_1 = new OpCode(OpCodeValues.Ldc_I4_1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4_2 = new OpCode(OpCodeValues.Ldc_I4_2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4_3 = new OpCode(OpCodeValues.Ldc_I4_3,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4_4 = new OpCode(OpCodeValues.Ldc_I4_4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4_5 = new OpCode(OpCodeValues.Ldc_I4_5,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4_6 = new OpCode(OpCodeValues.Ldc_I4_6,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4_7 = new OpCode(OpCodeValues.Ldc_I4_7,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4_8 = new OpCode(OpCodeValues.Ldc_I4_8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4_S = new OpCode(OpCodeValues.Ldc_I4_S,
- ((int)OperandType.ShortInlineI) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I4 = new OpCode(OpCodeValues.Ldc_I4,
- ((int)OperandType.InlineI) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_I8 = new OpCode(OpCodeValues.Ldc_I8,
- ((int)OperandType.InlineI8) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_R4 = new OpCode(OpCodeValues.Ldc_R4,
- ((int)OperandType.ShortInlineR) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushr4 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldc_R8 = new OpCode(OpCodeValues.Ldc_R8,
- ((int)OperandType.InlineR) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushr8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Dup = new OpCode(OpCodeValues.Dup,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1_push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Pop = new OpCode(OpCodeValues.Pop,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Jmp = new OpCode(OpCodeValues.Jmp,
- ((int)OperandType.InlineMethod) |
- ((int)FlowControl.Call << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- OpCode.EndsUncondJmpBlkFlag |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Call = new OpCode(OpCodeValues.Call,
- ((int)OperandType.InlineMethod) |
- ((int)FlowControl.Call << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Varpop << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Varpush << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Calli = new OpCode(OpCodeValues.Calli,
- ((int)OperandType.InlineSig) |
- ((int)FlowControl.Call << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Varpop << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Varpush << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ret = new OpCode(OpCodeValues.Ret,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Return << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Varpop << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- OpCode.EndsUncondJmpBlkFlag |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Br_S = new OpCode(OpCodeValues.Br_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- OpCode.EndsUncondJmpBlkFlag |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Brfalse_S = new OpCode(OpCodeValues.Brfalse_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Brtrue_S = new OpCode(OpCodeValues.Brtrue_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Beq_S = new OpCode(OpCodeValues.Beq_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Bge_S = new OpCode(OpCodeValues.Bge_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Bgt_S = new OpCode(OpCodeValues.Bgt_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ble_S = new OpCode(OpCodeValues.Ble_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Blt_S = new OpCode(OpCodeValues.Blt_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Bne_Un_S = new OpCode(OpCodeValues.Bne_Un_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Bge_Un_S = new OpCode(OpCodeValues.Bge_Un_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Bgt_Un_S = new OpCode(OpCodeValues.Bgt_Un_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ble_Un_S = new OpCode(OpCodeValues.Ble_Un_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Blt_Un_S = new OpCode(OpCodeValues.Blt_Un_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Br = new OpCode(OpCodeValues.Br,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- OpCode.EndsUncondJmpBlkFlag |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Brfalse = new OpCode(OpCodeValues.Brfalse,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Brtrue = new OpCode(OpCodeValues.Brtrue,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Beq = new OpCode(OpCodeValues.Beq,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Bge = new OpCode(OpCodeValues.Bge,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Bgt = new OpCode(OpCodeValues.Bgt,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ble = new OpCode(OpCodeValues.Ble,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Blt = new OpCode(OpCodeValues.Blt,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Bne_Un = new OpCode(OpCodeValues.Bne_Un,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Bge_Un = new OpCode(OpCodeValues.Bge_Un,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Bgt_Un = new OpCode(OpCodeValues.Bgt_Un,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ble_Un = new OpCode(OpCodeValues.Ble_Un,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Blt_Un = new OpCode(OpCodeValues.Blt_Un,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Macro << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Switch = new OpCode(OpCodeValues.Switch,
- ((int)OperandType.InlineSwitch) |
- ((int)FlowControl.Cond_Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldind_I1 = new OpCode(OpCodeValues.Ldind_I1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldind_U1 = new OpCode(OpCodeValues.Ldind_U1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldind_I2 = new OpCode(OpCodeValues.Ldind_I2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldind_U2 = new OpCode(OpCodeValues.Ldind_U2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldind_I4 = new OpCode(OpCodeValues.Ldind_I4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldind_U4 = new OpCode(OpCodeValues.Ldind_U4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldind_I8 = new OpCode(OpCodeValues.Ldind_I8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldind_I = new OpCode(OpCodeValues.Ldind_I,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldind_R4 = new OpCode(OpCodeValues.Ldind_R4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushr4 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldind_R8 = new OpCode(OpCodeValues.Ldind_R8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushr8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldind_Ref = new OpCode(OpCodeValues.Ldind_Ref,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushref << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stind_Ref = new OpCode(OpCodeValues.Stind_Ref,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stind_I1 = new OpCode(OpCodeValues.Stind_I1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stind_I2 = new OpCode(OpCodeValues.Stind_I2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stind_I4 = new OpCode(OpCodeValues.Stind_I4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stind_I8 = new OpCode(OpCodeValues.Stind_I8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_popi8 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stind_R4 = new OpCode(OpCodeValues.Stind_R4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_popr4 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stind_R8 = new OpCode(OpCodeValues.Stind_R8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_popr8 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Add = new OpCode(OpCodeValues.Add,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Sub = new OpCode(OpCodeValues.Sub,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Mul = new OpCode(OpCodeValues.Mul,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Div = new OpCode(OpCodeValues.Div,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Div_Un = new OpCode(OpCodeValues.Div_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Rem = new OpCode(OpCodeValues.Rem,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Rem_Un = new OpCode(OpCodeValues.Rem_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode And = new OpCode(OpCodeValues.And,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Or = new OpCode(OpCodeValues.Or,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Xor = new OpCode(OpCodeValues.Xor,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Shl = new OpCode(OpCodeValues.Shl,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Shr = new OpCode(OpCodeValues.Shr,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Shr_Un = new OpCode(OpCodeValues.Shr_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Neg = new OpCode(OpCodeValues.Neg,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Not = new OpCode(OpCodeValues.Not,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_I1 = new OpCode(OpCodeValues.Conv_I1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_I2 = new OpCode(OpCodeValues.Conv_I2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_I4 = new OpCode(OpCodeValues.Conv_I4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_I8 = new OpCode(OpCodeValues.Conv_I8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_R4 = new OpCode(OpCodeValues.Conv_R4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushr4 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_R8 = new OpCode(OpCodeValues.Conv_R8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushr8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_U4 = new OpCode(OpCodeValues.Conv_U4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_U8 = new OpCode(OpCodeValues.Conv_U8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Callvirt = new OpCode(OpCodeValues.Callvirt,
- ((int)OperandType.InlineMethod) |
- ((int)FlowControl.Call << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Varpop << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Varpush << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Cpobj = new OpCode(OpCodeValues.Cpobj,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldobj = new OpCode(OpCodeValues.Ldobj,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldstr = new OpCode(OpCodeValues.Ldstr,
- ((int)OperandType.InlineString) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushref << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Newobj = new OpCode(OpCodeValues.Newobj,
- ((int)OperandType.InlineMethod) |
- ((int)FlowControl.Call << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Varpop << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushref << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Castclass = new OpCode(OpCodeValues.Castclass,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushref << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Isinst = new OpCode(OpCodeValues.Isinst,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_R_Un = new OpCode(OpCodeValues.Conv_R_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushr8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Unbox = new OpCode(OpCodeValues.Unbox,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Throw = new OpCode(OpCodeValues.Throw,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Throw << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- OpCode.EndsUncondJmpBlkFlag |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldfld = new OpCode(OpCodeValues.Ldfld,
- ((int)OperandType.InlineField) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldflda = new OpCode(OpCodeValues.Ldflda,
- ((int)OperandType.InlineField) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stfld = new OpCode(OpCodeValues.Stfld,
- ((int)OperandType.InlineField) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldsfld = new OpCode(OpCodeValues.Ldsfld,
- ((int)OperandType.InlineField) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldsflda = new OpCode(OpCodeValues.Ldsflda,
- ((int)OperandType.InlineField) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stsfld = new OpCode(OpCodeValues.Stsfld,
- ((int)OperandType.InlineField) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stobj = new OpCode(OpCodeValues.Stobj,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_I1_Un = new OpCode(OpCodeValues.Conv_Ovf_I1_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_I2_Un = new OpCode(OpCodeValues.Conv_Ovf_I2_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_I4_Un = new OpCode(OpCodeValues.Conv_Ovf_I4_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_I8_Un = new OpCode(OpCodeValues.Conv_Ovf_I8_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_U1_Un = new OpCode(OpCodeValues.Conv_Ovf_U1_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_U2_Un = new OpCode(OpCodeValues.Conv_Ovf_U2_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_U4_Un = new OpCode(OpCodeValues.Conv_Ovf_U4_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_U8_Un = new OpCode(OpCodeValues.Conv_Ovf_U8_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_I_Un = new OpCode(OpCodeValues.Conv_Ovf_I_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_U_Un = new OpCode(OpCodeValues.Conv_Ovf_U_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Box = new OpCode(OpCodeValues.Box,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushref << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Newarr = new OpCode(OpCodeValues.Newarr,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushref << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldlen = new OpCode(OpCodeValues.Ldlen,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelema = new OpCode(OpCodeValues.Ldelema,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem_I1 = new OpCode(OpCodeValues.Ldelem_I1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem_U1 = new OpCode(OpCodeValues.Ldelem_U1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem_I2 = new OpCode(OpCodeValues.Ldelem_I2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem_U2 = new OpCode(OpCodeValues.Ldelem_U2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem_I4 = new OpCode(OpCodeValues.Ldelem_I4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem_U4 = new OpCode(OpCodeValues.Ldelem_U4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem_I8 = new OpCode(OpCodeValues.Ldelem_I8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem_I = new OpCode(OpCodeValues.Ldelem_I,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem_R4 = new OpCode(OpCodeValues.Ldelem_R4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushr4 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem_R8 = new OpCode(OpCodeValues.Ldelem_R8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushr8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem_Ref = new OpCode(OpCodeValues.Ldelem_Ref,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushref << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stelem_I = new OpCode(OpCodeValues.Stelem_I,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-3 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stelem_I1 = new OpCode(OpCodeValues.Stelem_I1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-3 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stelem_I2 = new OpCode(OpCodeValues.Stelem_I2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-3 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stelem_I4 = new OpCode(OpCodeValues.Stelem_I4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-3 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stelem_I8 = new OpCode(OpCodeValues.Stelem_I8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi_popi8 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-3 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stelem_R4 = new OpCode(OpCodeValues.Stelem_R4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi_popr4 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-3 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stelem_R8 = new OpCode(OpCodeValues.Stelem_R8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi_popr8 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-3 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stelem_Ref = new OpCode(OpCodeValues.Stelem_Ref,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi_popref << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-3 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldelem = new OpCode(OpCodeValues.Ldelem,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stelem = new OpCode(OpCodeValues.Stelem,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref_popi_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-3 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Unbox_Any = new OpCode(OpCodeValues.Unbox_Any,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_I1 = new OpCode(OpCodeValues.Conv_Ovf_I1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_U1 = new OpCode(OpCodeValues.Conv_Ovf_U1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_I2 = new OpCode(OpCodeValues.Conv_Ovf_I2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_U2 = new OpCode(OpCodeValues.Conv_Ovf_U2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_I4 = new OpCode(OpCodeValues.Conv_Ovf_I4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_U4 = new OpCode(OpCodeValues.Conv_Ovf_U4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_I8 = new OpCode(OpCodeValues.Conv_Ovf_I8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_U8 = new OpCode(OpCodeValues.Conv_Ovf_U8,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Refanyval = new OpCode(OpCodeValues.Refanyval,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ckfinite = new OpCode(OpCodeValues.Ckfinite,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushr8 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Mkrefany = new OpCode(OpCodeValues.Mkrefany,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldtoken = new OpCode(OpCodeValues.Ldtoken,
- ((int)OperandType.InlineTok) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_U2 = new OpCode(OpCodeValues.Conv_U2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_U1 = new OpCode(OpCodeValues.Conv_U1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_I = new OpCode(OpCodeValues.Conv_I,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_I = new OpCode(OpCodeValues.Conv_Ovf_I,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_Ovf_U = new OpCode(OpCodeValues.Conv_Ovf_U,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Add_Ovf = new OpCode(OpCodeValues.Add_Ovf,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Add_Ovf_Un = new OpCode(OpCodeValues.Add_Ovf_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Mul_Ovf = new OpCode(OpCodeValues.Mul_Ovf,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Mul_Ovf_Un = new OpCode(OpCodeValues.Mul_Ovf_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Sub_Ovf = new OpCode(OpCodeValues.Sub_Ovf,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Sub_Ovf_Un = new OpCode(OpCodeValues.Sub_Ovf_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Endfinally = new OpCode(OpCodeValues.Endfinally,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Return << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- OpCode.EndsUncondJmpBlkFlag |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Leave = new OpCode(OpCodeValues.Leave,
- ((int)OperandType.InlineBrTarget) |
- ((int)FlowControl.Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- OpCode.EndsUncondJmpBlkFlag |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Leave_S = new OpCode(OpCodeValues.Leave_S,
- ((int)OperandType.ShortInlineBrTarget) |
- ((int)FlowControl.Branch << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- OpCode.EndsUncondJmpBlkFlag |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stind_I = new OpCode(OpCodeValues.Stind_I,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (-2 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Conv_U = new OpCode(OpCodeValues.Conv_U,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Prefix7 = new OpCode(OpCodeValues.Prefix7,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Nternal << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Prefix6 = new OpCode(OpCodeValues.Prefix6,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Nternal << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Prefix5 = new OpCode(OpCodeValues.Prefix5,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Nternal << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Prefix4 = new OpCode(OpCodeValues.Prefix4,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Nternal << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Prefix3 = new OpCode(OpCodeValues.Prefix3,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Nternal << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Prefix2 = new OpCode(OpCodeValues.Prefix2,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Nternal << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Prefix1 = new OpCode(OpCodeValues.Prefix1,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Nternal << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Prefixref = new OpCode(OpCodeValues.Prefixref,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Nternal << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (1 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Arglist = new OpCode(OpCodeValues.Arglist,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ceq = new OpCode(OpCodeValues.Ceq,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Cgt = new OpCode(OpCodeValues.Cgt,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Cgt_Un = new OpCode(OpCodeValues.Cgt_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Clt = new OpCode(OpCodeValues.Clt,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Clt_Un = new OpCode(OpCodeValues.Clt_Un,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1_pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldftn = new OpCode(OpCodeValues.Ldftn,
- ((int)OperandType.InlineMethod) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldvirtftn = new OpCode(OpCodeValues.Ldvirtftn,
- ((int)OperandType.InlineMethod) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popref << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldarg = new OpCode(OpCodeValues.Ldarg,
- ((int)OperandType.InlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldarga = new OpCode(OpCodeValues.Ldarga,
- ((int)OperandType.InlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Starg = new OpCode(OpCodeValues.Starg,
- ((int)OperandType.InlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldloc = new OpCode(OpCodeValues.Ldloc,
- ((int)OperandType.InlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push1 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Ldloca = new OpCode(OpCodeValues.Ldloca,
- ((int)OperandType.InlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Stloc = new OpCode(OpCodeValues.Stloc,
- ((int)OperandType.InlineVar) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Localloc = new OpCode(OpCodeValues.Localloc,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Endfilter = new OpCode(OpCodeValues.Endfilter,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Return << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- OpCode.EndsUncondJmpBlkFlag |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Unaligned = new OpCode(OpCodeValues.Unaligned_,
- ((int)OperandType.ShortInlineI) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Prefix << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Volatile = new OpCode(OpCodeValues.Volatile_,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Prefix << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Tailcall = new OpCode(OpCodeValues.Tail_,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Prefix << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Initobj = new OpCode(OpCodeValues.Initobj,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (-1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Constrained = new OpCode(OpCodeValues.Constrained_,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Prefix << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Cpblk = new OpCode(OpCodeValues.Cpblk,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (-3 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Initblk = new OpCode(OpCodeValues.Initblk,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Popi_popi_popi << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (-3 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Rethrow = new OpCode(OpCodeValues.Rethrow,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Throw << OpCode.FlowControlShift) |
- ((int)OpCodeType.Objmodel << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- OpCode.EndsUncondJmpBlkFlag |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Sizeof = new OpCode(OpCodeValues.Sizeof,
- ((int)OperandType.InlineType) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (1 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Refanytype = new OpCode(OpCodeValues.Refanytype,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Next << OpCode.FlowControlShift) |
- ((int)OpCodeType.Primitive << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop1 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Pushi << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
- public static readonly OpCode Readonly = new OpCode(OpCodeValues.Readonly_,
- ((int)OperandType.InlineNone) |
- ((int)FlowControl.Meta << OpCode.FlowControlShift) |
- ((int)OpCodeType.Prefix << OpCode.OpCodeTypeShift) |
- ((int)StackBehaviour.Pop0 << OpCode.StackBehaviourPopShift) |
- ((int)StackBehaviour.Push0 << OpCode.StackBehaviourPushShift) |
- (2 << OpCode.SizeShift) |
- (0 << OpCode.StackChangeShift)
- );
-
-
- public static bool TakesSingleByteArgument(OpCode inst)
- {
- switch (inst.OperandType)
- {
- case OperandType.ShortInlineBrTarget:
- case OperandType.ShortInlineI:
- case OperandType.ShortInlineVar:
- return true;
- }
- return false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs
deleted file mode 100644
index 0c6933ece13..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/Opcode.cs
+++ /dev/null
@@ -1,125 +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 System.Threading;
-
-namespace System.Reflection.Emit
-{
- public readonly struct OpCode : IEquatable<OpCode>
- {
- //
- // Use packed bitfield for flags to avoid code bloat
- //
-
- internal const int OperandTypeMask = 0x1F; // 000000000000000000000000000XXXXX
-
- internal const int FlowControlShift = 5; // 00000000000000000000000XXXX00000
- internal const int FlowControlMask = 0x0F;
-
- internal const int OpCodeTypeShift = 9; // 00000000000000000000XXX000000000
- internal const int OpCodeTypeMask = 0x07;
-
- internal const int StackBehaviourPopShift = 12; // 000000000000000XXXXX000000000000
- internal const int StackBehaviourPushShift = 17; // 0000000000XXXXX00000000000000000
- internal const int StackBehaviourMask = 0x1F;
-
- internal const int SizeShift = 22; // 00000000XX0000000000000000000000
- internal const int SizeMask = 0x03;
-
- internal const int EndsUncondJmpBlkFlag = 0x01000000; // 0000000X000000000000000000000000
-
- // unused // 0000XXX0000000000000000000000000
-
- internal const int StackChangeShift = 28; // XXXX0000000000000000000000000000
-
- private readonly OpCodeValues m_value;
- private readonly int m_flags;
-
- internal OpCode(OpCodeValues value, int flags)
- {
- m_value = value;
- m_flags = flags;
- }
-
- internal bool EndsUncondJmpBlk() =>
- (m_flags & EndsUncondJmpBlkFlag) != 0;
-
- internal int StackChange() =>
- m_flags >> StackChangeShift;
-
- public OperandType OperandType => (OperandType)(m_flags & OperandTypeMask);
-
- public FlowControl FlowControl => (FlowControl)((m_flags >> FlowControlShift) & FlowControlMask);
-
- public OpCodeType OpCodeType => (OpCodeType)((m_flags >> OpCodeTypeShift) & OpCodeTypeMask);
-
- public StackBehaviour StackBehaviourPop => (StackBehaviour)((m_flags >> StackBehaviourPopShift) & StackBehaviourMask);
-
- public StackBehaviour StackBehaviourPush => (StackBehaviour)((m_flags >> StackBehaviourPushShift) & StackBehaviourMask);
-
- public int Size => (m_flags >> SizeShift) & SizeMask;
-
- public short Value => (short)m_value;
-
- private static volatile string[]? g_nameCache;
-
- public string? Name
- {
- get
- {
- if (Size == 0)
- return null;
-
- // Create and cache the opcode names lazily. They should be rarely used (only for logging, etc.)
- // Note that we do not any locks here because of we always get the same names. The last one wins.
- string[]? nameCache = g_nameCache;
- if (nameCache == null)
- {
- nameCache = new string[0x11f];
- g_nameCache = nameCache;
- }
-
- OpCodeValues opCodeValue = (OpCodeValues)(ushort)Value;
-
- int idx = (int)opCodeValue;
- if (idx > 0xFF)
- {
- if (idx >= 0xfe00 && idx <= 0xfe1e)
- {
- // Transform two byte opcode value to lower range that's suitable
- // for array index
- idx = 0x100 + (idx - 0xfe00);
- }
- else
- {
- // Unknown opcode
- return null;
- }
- }
-
- string name = Volatile.Read(ref nameCache[idx]);
- if (name != null)
- return name;
-
- // Create ilasm style name from the enum value name.
- name = Enum.GetName(typeof(OpCodeValues), opCodeValue)!.ToLowerInvariant().Replace('_', '.');
- Volatile.Write(ref nameCache[idx], name);
- return name;
- }
- }
-
- public override bool Equals(object? obj) =>
- obj is OpCode other && Equals(other);
-
- public bool Equals(OpCode obj) => obj.Value == Value;
-
- public static bool operator ==(OpCode a, OpCode b) => a.Equals(b);
-
- public static bool operator !=(OpCode a, OpCode b) => !(a == b);
-
- public override int GetHashCode() => Value;
-
- public override string? ToString() => Name;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OperandType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OperandType.cs
deleted file mode 100644
index 8abf79b5d01..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/OperandType.cs
+++ /dev/null
@@ -1,39 +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.
-
-/*============================================================
-**
-** Enumeration: OperandType
-**
-** Purpose: Exposes OperandType Attribute of IL.
-**
-** THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND!
-** See $(RepoRoot)\src\inc\OpCodeGen.pl for more information.**
-==============================================================*/
-
-namespace System.Reflection.Emit
-{
- public enum OperandType
- {
- InlineBrTarget = 0,
- InlineField = 1,
- InlineI = 2,
- InlineI8 = 3,
- InlineMethod = 4,
- InlineNone = 5,
- [Obsolete("This API has been deprecated. https://go.microsoft.com/fwlink/?linkid=14202")]
- InlinePhi = 6,
- InlineR = 7,
- InlineSig = 9,
- InlineString = 10,
- InlineSwitch = 11,
- InlineTok = 12,
- InlineType = 13,
- InlineVar = 14,
- ShortInlineBrTarget = 15,
- ShortInlineI = 16,
- ShortInlineR = 17,
- ShortInlineVar = 18,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PEFileKinds.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PEFileKinds.cs
deleted file mode 100644
index 8a35a72a85d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PEFileKinds.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Reflection.Emit
-{
- // This Enum matchs the CorFieldAttr defined in CorHdr.h
- public enum PEFileKinds
- {
- Dll = 0x0001,
- ConsoleApplication = 0x0002,
- WindowApplication = 0x0003,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PackingSize.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PackingSize.cs
deleted file mode 100644
index f734e1a3423..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PackingSize.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Reflection.Emit
-{
- public enum PackingSize
- {
- Unspecified = 0,
- Size1 = 1,
- Size2 = 2,
- Size4 = 4,
- Size8 = 8,
- Size16 = 16,
- Size32 = 32,
- Size64 = 64,
- Size128 = 128,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/ParameterToken.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/ParameterToken.cs
deleted file mode 100644
index b03ddf082e6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/ParameterToken.cs
+++ /dev/null
@@ -1,32 +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.
-
-namespace System.Reflection.Emit
-{
- /// <summary>
- /// The ParameterToken class is an opaque representation of the Token returned
- /// by the Metadata to represent the parameter.
- /// </summary>
- public struct ParameterToken
- {
- public static readonly ParameterToken Empty = default;
-
- internal ParameterToken(int parameterToken)
- {
- Token = parameterToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is ParameterToken pt && Equals(pt);
-
- public bool Equals(ParameterToken obj) => obj.Token == Token;
-
- public static bool operator ==(ParameterToken a, ParameterToken b) => a.Equals(b);
-
- public static bool operator !=(ParameterToken a, ParameterToken b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PropertyToken.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PropertyToken.cs
deleted file mode 100644
index 02d88ff79f6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/PropertyToken.cs
+++ /dev/null
@@ -1,28 +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.
-
-namespace System.Reflection.Emit
-{
- public struct PropertyToken
- {
- public static readonly PropertyToken Empty = default;
-
- internal PropertyToken(int propertyToken)
- {
- Token = propertyToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is PropertyToken pt && Equals(pt);
-
- public bool Equals(PropertyToken obj) => obj.Token == Token;
-
- public static bool operator ==(PropertyToken a, PropertyToken b) => a.Equals(b);
-
- public static bool operator !=(PropertyToken a, PropertyToken b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/SignatureToken.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/SignatureToken.cs
deleted file mode 100644
index 851dcd7ee4f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/SignatureToken.cs
+++ /dev/null
@@ -1,28 +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.
-
-namespace System.Reflection.Emit
-{
- public struct SignatureToken
- {
- public static readonly SignatureToken Empty = default;
-
- internal SignatureToken(int signatureToken)
- {
- Token = signatureToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is SignatureToken st && Equals(st);
-
- public bool Equals(SignatureToken obj) => obj.Token == Token;
-
- public static bool operator ==(SignatureToken a, SignatureToken b) => a.Equals(b);
-
- public static bool operator !=(SignatureToken a, SignatureToken b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/StackBehaviour.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/StackBehaviour.cs
deleted file mode 100644
index c3d27ad72be..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/StackBehaviour.cs
+++ /dev/null
@@ -1,49 +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.
-
-/*============================================================
-**
-** Enumeration: StackBehaviour
-**
-** Purpose: Exposes StackBehaviour Attribute of IL.
-**
-** THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND!
-** See $(RepoRoot)\src\inc\OpCodeGen.pl for more information.**
-==============================================================*/
-
-namespace System.Reflection.Emit
-{
- public enum StackBehaviour
- {
- Pop0 = 0,
- Pop1 = 1,
- Pop1_pop1 = 2,
- Popi = 3,
- Popi_pop1 = 4,
- Popi_popi = 5,
- Popi_popi8 = 6,
- Popi_popi_popi = 7,
- Popi_popr4 = 8,
- Popi_popr8 = 9,
- Popref = 10,
- Popref_pop1 = 11,
- Popref_popi = 12,
- Popref_popi_popi = 13,
- Popref_popi_popi8 = 14,
- Popref_popi_popr4 = 15,
- Popref_popi_popr8 = 16,
- Popref_popi_popref = 17,
- Push0 = 18,
- Push1 = 19,
- Push1_push1 = 20,
- Pushi = 21,
- Pushi8 = 22,
- Pushr4 = 23,
- Pushr8 = 24,
- Pushref = 25,
- Varpop = 26,
- Varpush = 27,
- Popref_popi_pop1 = 28,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/StringToken.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/StringToken.cs
deleted file mode 100644
index 0c2797a51c1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/StringToken.cs
+++ /dev/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.
-
-namespace System.Reflection.Emit
-{
- public struct StringToken
- {
- internal StringToken(int str)
- {
- Token = str;
- }
-
- // Returns the metadata token for this particular string.
- // Generated by a call to Module.GetStringConstant().
- //
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is StringToken st && Equals(st);
-
- public bool Equals(StringToken obj) => obj.Token == Token;
-
- public static bool operator ==(StringToken a, StringToken b) => a.Equals(b);
-
- public static bool operator !=(StringToken a, StringToken b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/TypeToken.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/TypeToken.cs
deleted file mode 100644
index 099b9e84729..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Emit/TypeToken.cs
+++ /dev/null
@@ -1,28 +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.
-
-namespace System.Reflection.Emit
-{
- public struct TypeToken
- {
- public static readonly TypeToken Empty = default;
-
- internal TypeToken(int typeToken)
- {
- Token = typeToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is TypeToken tt && Equals(tt);
-
- public bool Equals(TypeToken obj) => obj.Token == Token;
-
- public static bool operator ==(TypeToken a, TypeToken b) => a.Equals(b);
-
- public static bool operator !=(TypeToken a, TypeToken b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/EventAttributes.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/EventAttributes.cs
deleted file mode 100644
index fbc2972f697..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/EventAttributes.cs
+++ /dev/null
@@ -1,22 +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.
-
-// EventAttributes are an enum defining the attributes associated with and Event.
-// These are defined in CorHdr.h and are a combination of bits and enums.
-
-namespace System.Reflection
-{
- [Flags]
- public enum EventAttributes
- {
- None = 0x0000,
-
- // This Enum matchs the CorEventAttr defined in CorHdr.h
- SpecialName = 0x0200, // event is special. Name describes how.
-
- RTSpecialName = 0x0400, // Runtime(metadata internal APIs) should check name encoding.
-
- ReservedMask = 0x0400,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/EventInfo.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/EventInfo.cs
deleted file mode 100644
index 789352a16c8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/EventInfo.cs
+++ /dev/null
@@ -1,125 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-#if FEATURE_COMINTEROP
-using EventRegistrationToken = System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken;
-#endif //#if FEATURE_COMINTEROP
-
-namespace System.Reflection
-{
- public abstract class EventInfo : MemberInfo
- {
- protected EventInfo() { }
-
- public override MemberTypes MemberType => MemberTypes.Event;
-
- public abstract EventAttributes Attributes { get; }
- public bool IsSpecialName => (Attributes & EventAttributes.SpecialName) != 0;
-
- public MethodInfo[] GetOtherMethods() => GetOtherMethods(nonPublic: false);
- public virtual MethodInfo[] GetOtherMethods(bool nonPublic) { throw NotImplemented.ByDesign; }
-
- public virtual MethodInfo? AddMethod => GetAddMethod(nonPublic: true);
- public virtual MethodInfo? RemoveMethod => GetRemoveMethod(nonPublic: true);
- public virtual MethodInfo? RaiseMethod => GetRaiseMethod(nonPublic: true);
-
- public MethodInfo? GetAddMethod() => GetAddMethod(nonPublic: false);
- public MethodInfo? GetRemoveMethod() => GetRemoveMethod(nonPublic: false);
- public MethodInfo? GetRaiseMethod() => GetRaiseMethod(nonPublic: false);
-
- public abstract MethodInfo? GetAddMethod(bool nonPublic);
- public abstract MethodInfo? GetRemoveMethod(bool nonPublic);
- public abstract MethodInfo? GetRaiseMethod(bool nonPublic);
-
- public virtual bool IsMulticast
- {
- get
- {
- Type? cl = EventHandlerType;
- Type mc = typeof(MulticastDelegate);
- return mc.IsAssignableFrom(cl);
- }
- }
-
- public virtual Type? EventHandlerType
- {
- get
- {
- MethodInfo m = GetAddMethod(true)!;
- ParameterInfo[] p = m.GetParametersNoCopy();
- Type del = typeof(Delegate);
- for (int i = 0; i < p.Length; i++)
- {
- Type c = p[i].ParameterType;
- if (c.IsSubclassOf(del))
- return c;
- }
- return null;
- }
- }
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public virtual void AddEventHandler(object? target, Delegate? handler)
- {
- MethodInfo? addMethod = GetAddMethod(nonPublic: false);
-
- if (addMethod == null)
- throw new InvalidOperationException(SR.InvalidOperation_NoPublicAddMethod);
-
-#if FEATURE_COMINTEROP
- if (addMethod.ReturnType == typeof(EventRegistrationToken))
- throw new InvalidOperationException(SR.InvalidOperation_NotSupportedOnWinRTEvent);
-#endif //#if FEATURE_COMINTEROP
-
- addMethod.Invoke(target, new object?[] { handler });
- }
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public virtual void RemoveEventHandler(object? target, Delegate? handler)
- {
- MethodInfo? removeMethod = GetRemoveMethod(nonPublic: false);
-
- if (removeMethod == null)
- throw new InvalidOperationException(SR.InvalidOperation_NoPublicRemoveMethod);
-
-#if FEATURE_COMINTEROP
- ParameterInfo[] parameters = removeMethod.GetParametersNoCopy();
- if (parameters[0].ParameterType == typeof(EventRegistrationToken))
- throw new InvalidOperationException(SR.InvalidOperation_NotSupportedOnWinRTEvent);
-#endif //#if FEATURE_COMINTEROP
-
- removeMethod.Invoke(target, new object?[] { handler });
- }
-
- public override bool Equals(object? obj) => base.Equals(obj);
- public override int GetHashCode() => base.GetHashCode();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(EventInfo? left, EventInfo? right)
- {
- // Test "right" first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (right is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (left is null) ? true : false;
- }
-
- // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
- if ((object?)left == (object)right)
- {
- return true;
- }
-
- return (left is null) ? false : left.Equals(right);
- }
-
- public static bool operator !=(EventInfo? left, EventInfo? right) => !(left == right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ExceptionHandlingClause.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ExceptionHandlingClause.cs
deleted file mode 100644
index 543db08cccd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ExceptionHandlingClause.cs
+++ /dev/null
@@ -1,27 +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 System.Globalization;
-
-namespace System.Reflection
-{
- public class ExceptionHandlingClause
- {
- protected ExceptionHandlingClause() { }
- public virtual ExceptionHandlingClauseOptions Flags => default;
- public virtual int TryOffset => 0;
- public virtual int TryLength => 0;
- public virtual int HandlerOffset => 0;
- public virtual int HandlerLength => 0;
- public virtual int FilterOffset => throw new InvalidOperationException(SR.Arg_EHClauseNotFilter);
- public virtual Type? CatchType => null;
-
- public override string ToString()
- {
- return string.Format(CultureInfo.CurrentUICulture,
- "Flags={0}, TryOffset={1}, TryLength={2}, HandlerOffset={3}, HandlerLength={4}, CatchType={5}",
- Flags, TryOffset, TryLength, HandlerOffset, HandlerLength, CatchType);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ExceptionHandlingClauseOptions.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ExceptionHandlingClauseOptions.cs
deleted file mode 100644
index f121e350594..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ExceptionHandlingClauseOptions.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System.Reflection
-{
- [Flags]
- public enum ExceptionHandlingClauseOptions : int
- {
- Clause = 0x0,
- Filter = 0x1,
- Finally = 0x2,
- Fault = 0x4,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/FieldAttributes.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/FieldAttributes.cs
deleted file mode 100644
index 395763e8a60..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/FieldAttributes.cs
+++ /dev/null
@@ -1,40 +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.
-
-namespace System.Reflection
-{
- // This Enum matchs the CorFieldAttr defined in CorHdr.h
- [Flags]
- public enum FieldAttributes
- {
- // member access mask - Use this mask to retrieve accessibility information.
- FieldAccessMask = 0x0007,
- PrivateScope = 0x0000, // Member not referenceable.
- Private = 0x0001, // Accessible only by the parent type.
- FamANDAssem = 0x0002, // Accessible by sub-types only in this Assembly.
- Assembly = 0x0003, // Accessibly by anyone in the Assembly.
- Family = 0x0004, // Accessible only by type and sub-types.
- FamORAssem = 0x0005, // Accessibly by sub-types anywhere, plus anyone in assembly.
- Public = 0x0006, // Accessibly by anyone who has visibility to this scope.
- // end member access mask
-
- // field contract attributes.
- Static = 0x0010, // Defined on type, else per instance.
- InitOnly = 0x0020, // Field may only be initialized, not written to after init.
- Literal = 0x0040, // Value is compile time constant.
- NotSerialized = 0x0080, // Field does not have to be serialized when type is remoted.
-
- SpecialName = 0x0200, // field is special. Name describes how.
-
- // interop attributes
- PinvokeImpl = 0x2000, // Implementation is forwarded through pinvoke.
-
- RTSpecialName = 0x0400, // Runtime(metadata internal APIs) should check name encoding.
- HasFieldMarshal = 0x1000, // Field has marshalling information.
- HasDefault = 0x8000, // Field has default.
- HasFieldRVA = 0x0100, // Field has RVA.
-
- ReservedMask = 0x9500,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs
deleted file mode 100644
index cbb04d54a42..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs
+++ /dev/null
@@ -1,82 +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 System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-
-namespace System.Reflection
-{
- public abstract partial class FieldInfo : MemberInfo
- {
- protected FieldInfo() { }
-
- public override MemberTypes MemberType => MemberTypes.Field;
-
- public abstract FieldAttributes Attributes { get; }
- public abstract Type FieldType { get; }
-
- public bool IsInitOnly => (Attributes & FieldAttributes.InitOnly) != 0;
- public bool IsLiteral => (Attributes & FieldAttributes.Literal) != 0;
- public bool IsNotSerialized => (Attributes & FieldAttributes.NotSerialized) != 0;
- public bool IsPinvokeImpl => (Attributes & FieldAttributes.PinvokeImpl) != 0;
- public bool IsSpecialName => (Attributes & FieldAttributes.SpecialName) != 0;
- public bool IsStatic => (Attributes & FieldAttributes.Static) != 0;
-
- public bool IsAssembly => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly;
- public bool IsFamily => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family;
- public bool IsFamilyAndAssembly => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem;
- public bool IsFamilyOrAssembly => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem;
- public bool IsPrivate => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private;
- public bool IsPublic => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public;
-
- public virtual bool IsSecurityCritical => true;
- public virtual bool IsSecuritySafeCritical => false;
- public virtual bool IsSecurityTransparent => false;
-
- public abstract RuntimeFieldHandle FieldHandle { get; }
-
- public override bool Equals(object? obj) => base.Equals(obj);
- public override int GetHashCode() => base.GetHashCode();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(FieldInfo? left, FieldInfo? right)
- {
- // Test "right" first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (right is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (left is null) ? true : false;
- }
-
- // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
- if ((object?)left == (object)right)
- {
- return true;
- }
-
- return (left is null) ? false : left.Equals(right);
- }
-
- public static bool operator !=(FieldInfo? left, FieldInfo? right) => !(left == right);
-
- public abstract object? GetValue(object? obj);
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public void SetValue(object? obj, object? value) => SetValue(obj, value, BindingFlags.Default, Type.DefaultBinder, null);
- public abstract void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, CultureInfo? culture);
-
- [CLSCompliant(false)]
- public virtual void SetValueDirect(TypedReference obj, object value) { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); }
- [CLSCompliant(false)]
- public virtual object? GetValueDirect(TypedReference obj) { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); }
-
- public virtual object? GetRawConstantValue() { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); }
-
- public virtual Type[] GetOptionalCustomModifiers() { throw NotImplemented.ByDesign; }
- public virtual Type[] GetRequiredCustomModifiers() { throw NotImplemented.ByDesign; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/GenericParameterAttributes.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/GenericParameterAttributes.cs
deleted file mode 100644
index f672dc4f91c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/GenericParameterAttributes.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Reflection
-{
- [Flags]
- public enum GenericParameterAttributes
- {
- None = 0x0000,
- VarianceMask = 0x0003,
- Covariant = 0x0001,
- Contravariant = 0x0002,
- SpecialConstraintMask = 0x001C,
- ReferenceTypeConstraint = 0x0004,
- NotNullableValueTypeConstraint = 0x0008,
- DefaultConstructorConstraint = 0x0010,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ICustomAttributeProvider.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ICustomAttributeProvider.cs
deleted file mode 100644
index 3cae295bc49..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ICustomAttributeProvider.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Reflection
-{
- public interface ICustomAttributeProvider
- {
- object[] GetCustomAttributes(bool inherit);
- object[] GetCustomAttributes(Type attributeType, bool inherit);
- bool IsDefined(Type attributeType, bool inherit);
- }
-} \ No newline at end of file
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/IReflect.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/IReflect.cs
deleted file mode 100644
index 643c6eb17b1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/IReflect.cs
+++ /dev/null
@@ -1,76 +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 System.Globalization;
-
-namespace System.Reflection
-{
- public interface IReflect
- {
- // Return the requested method if it is implemented by the Reflection object. The
- // match is based upon the name and DescriptorInfo which describes the signature
- // of the method.
- MethodInfo? GetMethod(string name, BindingFlags bindingAttr, Binder? binder, Type[] types, ParameterModifier[]? modifiers);
-
- // Return the requested method if it is implemented by the Reflection object. The
- // match is based upon the name of the method. If the object implementes multiple methods
- // with the same name an AmbiguousMatchException is thrown.
- MethodInfo? GetMethod(string name, BindingFlags bindingAttr);
-
- MethodInfo[] GetMethods(BindingFlags bindingAttr);
-
- // Return the requestion field if it is implemented by the Reflection object. The
- // match is based upon a name. There cannot be more than a single field with
- // a name.
- FieldInfo? GetField(string name, BindingFlags bindingAttr);
-
- FieldInfo[] GetFields(BindingFlags bindingAttr);
-
- // Return the property based upon name. If more than one property has the given
- // name an AmbiguousMatchException will be thrown. Returns null if no property
- // is found.
- PropertyInfo? GetProperty(string name, BindingFlags bindingAttr);
-
- // Return the property based upon the name and Descriptor info describing the property
- // indexing. Return null if no property is found.
- PropertyInfo? GetProperty(string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[] types, ParameterModifier[]? modifiers);
-
- // Returns an array of PropertyInfos for all the properties defined on
- // the Reflection object.
- PropertyInfo[] GetProperties(BindingFlags bindingAttr);
-
- // Return an array of members which match the passed in name.
- MemberInfo[] GetMember(string name, BindingFlags bindingAttr);
-
- // Return an array of all of the members defined for this object.
- MemberInfo[] GetMembers(BindingFlags bindingAttr);
-
- // Description of the Binding Process.
- // We must invoke a method that is accessible and for which the provided
- // parameters have the most specific match. A method may be called if
- // 1. The number of parameters in the method declaration equals the number of
- // arguments provided to the invocation
- // 2. The type of each argument can be converted by the binder to the
- // type of the type of the parameter.
- //
- // The binder will find all of the matching methods. These method are found based
- // upon the type of binding requested (MethodInvoke, Get/Set Properties). The set
- // of methods is filtered by the name, number of arguments and a set of search modifiers
- // defined in the Binder.
- //
- // After the method is selected, it will be invoked. Accessibility is checked
- // at that point. The search may be control which set of methods are searched based
- // upon the accessibility attribute associated with the method.
- //
- // The BindToMethod method is responsible for selecting the method to be invoked.
- // For the default binder, the most specific method will be selected.
- //
- // This will invoke a specific member...
- object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters);
-
- // Return the underlying Type that represents the IReflect Object. For expando object,
- // this is the (Object) IReflectInstance.GetType(). For Type object it is this.
- Type UnderlyingSystemType { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/IReflectableType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/IReflectableType.cs
deleted file mode 100644
index f3ba94b2c85..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/IReflectableType.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Reflection
-{
- public interface IReflectableType
- {
- TypeInfo GetTypeInfo();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ImageFileMachine.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ImageFileMachine.cs
deleted file mode 100644
index a38cd9509dd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ImageFileMachine.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Reflection
-{
- public enum ImageFileMachine
- {
- I386 = 0x014c,
- IA64 = 0x0200,
- AMD64 = 0x8664,
- ARM = 0x01c4,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/InterfaceMapping.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/InterfaceMapping.cs
deleted file mode 100644
index 2e0c0d8a28e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/InterfaceMapping.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Reflection
-{
- public struct InterfaceMapping
- {
- public Type TargetType; // The type implementing the interface
- public Type InterfaceType; // The type representing the interface
- public MethodInfo[] TargetMethods; // The methods implementing the interface
- public MethodInfo[] InterfaceMethods; // The methods defined on the interface
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/IntrospectionExtensions.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/IntrospectionExtensions.cs
deleted file mode 100644
index d9674f94b26..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/IntrospectionExtensions.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Reflection
-{
- public static class IntrospectionExtensions
- {
- public static TypeInfo GetTypeInfo(this Type type)
- {
- if (type == null)
- throw new ArgumentNullException(nameof(type));
-
- if (type is IReflectableType reflectableType)
- return reflectableType.GetTypeInfo();
-
- return new TypeDelegator(type);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/InvalidFilterCriteriaException.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/InvalidFilterCriteriaException.cs
deleted file mode 100644
index 7c9093b9559..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/InvalidFilterCriteriaException.cs
+++ /dev/null
@@ -1,34 +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 System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class InvalidFilterCriteriaException : ApplicationException
- {
- public InvalidFilterCriteriaException()
- : this(SR.Arg_InvalidFilterCriteriaException)
- {
- }
-
- public InvalidFilterCriteriaException(string? message)
- : this(message, null)
- {
- }
-
- public InvalidFilterCriteriaException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_INVALIDFILTERCRITERIA;
- }
-
- protected InvalidFilterCriteriaException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/LocalVariableInfo.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/LocalVariableInfo.cs
deleted file mode 100644
index 09671e35c83..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/LocalVariableInfo.cs
+++ /dev/null
@@ -1,25 +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 System.Diagnostics;
-
-namespace System.Reflection
-{
- public class LocalVariableInfo
- {
- public virtual Type LocalType { get { Debug.Fail("type must be set!"); return null!; } }
- public virtual int LocalIndex => 0;
- public virtual bool IsPinned => false;
- protected LocalVariableInfo() { }
- public override string ToString()
- {
- string toString = LocalType.ToString() + " (" + LocalIndex + ")";
-
- if (IsPinned)
- toString += " (pinned)";
-
- return toString;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ManifestResourceInfo.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ManifestResourceInfo.cs
deleted file mode 100644
index 584e1361e4f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ManifestResourceInfo.cs
+++ /dev/null
@@ -1,22 +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.
-
-namespace System.Reflection
-{
- public class ManifestResourceInfo
- {
- public ManifestResourceInfo(Assembly containingAssembly,
- string containingFileName,
- ResourceLocation resourceLocation)
- {
- ReferencedAssembly = containingAssembly;
- FileName = containingFileName;
- ResourceLocation = resourceLocation;
- }
-
- public virtual Assembly ReferencedAssembly { get; }
- public virtual string FileName { get; }
- public virtual ResourceLocation ResourceLocation { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/MemberFilter.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/MemberFilter.cs
deleted file mode 100644
index 07198cbc4e0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/MemberFilter.cs
+++ /dev/null
@@ -1,8 +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.
-
-namespace System.Reflection
-{
- public delegate bool MemberFilter(MemberInfo m, object? filterCriteria);
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs
deleted file mode 100644
index 4c7316ff9eb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs
+++ /dev/null
@@ -1,69 +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 System.Collections.Generic;
-using System.Runtime.CompilerServices;
-
-namespace System.Reflection
-{
- public abstract partial class MemberInfo : ICustomAttributeProvider
- {
- protected MemberInfo() { }
-
- public abstract MemberTypes MemberType { get; }
- public abstract string Name { get; }
- public abstract Type? DeclaringType { get; }
- public abstract Type? ReflectedType { get; }
-
- public virtual Module Module
- {
- get
- {
- // This check is necessary because for some reason, Type adds a new "Module" property that hides the inherited one instead
- // of overriding.
-
- if (this is Type type)
- return type.Module;
-
- throw NotImplemented.ByDesign;
- }
- }
-
- public virtual bool HasSameMetadataDefinitionAs(MemberInfo other) { throw NotImplemented.ByDesign; }
-
- public abstract bool IsDefined(Type attributeType, bool inherit);
- public abstract object[] GetCustomAttributes(bool inherit);
- public abstract object[] GetCustomAttributes(Type attributeType, bool inherit);
-
- public virtual IEnumerable<CustomAttributeData> CustomAttributes => GetCustomAttributesData();
- public virtual IList<CustomAttributeData> GetCustomAttributesData() { throw NotImplemented.ByDesign; }
- public virtual bool IsCollectible => true;
- public virtual int MetadataToken => throw new InvalidOperationException();
-
- public override bool Equals(object? obj) => base.Equals(obj);
- public override int GetHashCode() => base.GetHashCode();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(MemberInfo? left, MemberInfo? right)
- {
- // Test "right" first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (right is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (left is null) ? true : false;
- }
-
- // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
- if ((object?)left == (object)right)
- {
- return true;
- }
-
- return (left is null) ? false : left.Equals(right);
- }
-
- public static bool operator !=(MemberInfo? left, MemberInfo? right) => !(left == right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/MemberTypes.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/MemberTypes.cs
deleted file mode 100644
index f73892e0a16..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/MemberTypes.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Reflection
-{
- [Flags]
- public enum MemberTypes
- {
- Constructor = 0x01,
- Event = 0x02,
- Field = 0x04,
- Method = 0x08,
- Property = 0x10,
- TypeInfo = 0x20,
- Custom = 0x40,
- NestedType = 0x80,
- All = Constructor | Event | Field | Method | Property | TypeInfo | NestedType,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodAttributes.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/MethodAttributes.cs
deleted file mode 100644
index 569ba9685c7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodAttributes.cs
+++ /dev/null
@@ -1,50 +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.
-
-namespace System.Reflection
-{
- [Flags]
- public enum MethodAttributes
- {
- // NOTE: This Enum matchs the CorMethodAttr defined in CorHdr.h
-
- // member access mask - Use this mask to retrieve accessibility information.
- MemberAccessMask = 0x0007,
- PrivateScope = 0x0000, // Member not referenceable.
- Private = 0x0001, // Accessible only by the parent type.
- FamANDAssem = 0x0002, // Accessible by sub-types only in this Assembly.
- Assembly = 0x0003, // Accessibly by anyone in the Assembly.
- Family = 0x0004, // Accessible only by type and sub-types.
- FamORAssem = 0x0005, // Accessibly by sub-types anywhere, plus anyone in assembly.
- Public = 0x0006, // Accessibly by anyone who has visibility to this scope.
- // end member access mask
-
- // method contract attributes.
- Static = 0x0010, // Defined on type, else per instance.
- Final = 0x0020, // Method may not be overridden.
- Virtual = 0x0040, // Method virtual.
- HideBySig = 0x0080, // Method hides by name+sig, else just by name.
- CheckAccessOnOverride = 0x0200,
-
- // vtable layout mask - Use this mask to retrieve vtable attributes.
- VtableLayoutMask = 0x0100,
- ReuseSlot = 0x0000, // The default.
- NewSlot = 0x0100, // Method always gets a new slot in the vtable.
- // end vtable layout mask
-
- // method implementation attributes.
- Abstract = 0x0400, // Method does not provide an implementation.
- SpecialName = 0x0800, // Method is special. Name describes how.
-
- // interop attributes
- PinvokeImpl = 0x2000, // Implementation is forwarded through pinvoke.
- UnmanagedExport = 0x0008, // Managed method exported via thunk to unmanaged code.
- RTSpecialName = 0x1000, // Runtime should check name encoding.
-
- HasSecurity = 0x4000, // Method has security associate with it.
- RequireSecObject = 0x8000, // Method calls another method containing security code.
-
- ReservedMask = 0xd000,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs
deleted file mode 100644
index d737ccff3c9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs
+++ /dev/null
@@ -1,121 +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 System.Globalization;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System.Reflection
-{
- public abstract partial class MethodBase : MemberInfo
- {
- protected MethodBase() { }
-
- public abstract ParameterInfo[] GetParameters();
- public abstract MethodAttributes Attributes { get; }
- public virtual MethodImplAttributes MethodImplementationFlags => GetMethodImplementationFlags();
- public abstract MethodImplAttributes GetMethodImplementationFlags();
- public virtual MethodBody? GetMethodBody() { throw new InvalidOperationException(); }
- public virtual CallingConventions CallingConvention => CallingConventions.Standard;
-
- public bool IsAbstract => (Attributes & MethodAttributes.Abstract) != 0;
- public bool IsConstructor =>
- // To be backward compatible we only return true for instance RTSpecialName ctors.
- this is ConstructorInfo &&
- !IsStatic &&
- (Attributes & MethodAttributes.RTSpecialName) == MethodAttributes.RTSpecialName;
- public bool IsFinal => (Attributes & MethodAttributes.Final) != 0;
- public bool IsHideBySig => (Attributes & MethodAttributes.HideBySig) != 0;
- public bool IsSpecialName => (Attributes & MethodAttributes.SpecialName) != 0;
- public bool IsStatic => (Attributes & MethodAttributes.Static) != 0;
- public bool IsVirtual => (Attributes & MethodAttributes.Virtual) != 0;
-
- public bool IsAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
- public bool IsFamily => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
- public bool IsFamilyAndAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
- public bool IsFamilyOrAssembly => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
- public bool IsPrivate => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
- public bool IsPublic => (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
-
- public virtual bool IsConstructedGenericMethod => IsGenericMethod && !IsGenericMethodDefinition;
- public virtual bool IsGenericMethod => false;
- public virtual bool IsGenericMethodDefinition => false;
- public virtual Type[] GetGenericArguments() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
- public virtual bool ContainsGenericParameters => false;
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public object? Invoke(object? obj, object?[]? parameters) => Invoke(obj, BindingFlags.Default, binder: null, parameters: parameters, culture: null);
- public abstract object? Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture);
-
- public abstract RuntimeMethodHandle MethodHandle { get; }
-
- public virtual bool IsSecurityCritical => throw NotImplemented.ByDesign;
- public virtual bool IsSecuritySafeCritical => throw NotImplemented.ByDesign;
- public virtual bool IsSecurityTransparent => throw NotImplemented.ByDesign;
-
- public override bool Equals(object? obj) => base.Equals(obj);
- public override int GetHashCode() => base.GetHashCode();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(MethodBase? left, MethodBase? right)
- {
- // Test "right" first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (right is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (left is null) ? true : false;
- }
-
- // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
- if ((object?)left == (object)right)
- {
- return true;
- }
-
- return (left is null) ? false : left.Equals(right);
- }
-
- public static bool operator !=(MethodBase? left, MethodBase? right) => !(left == right);
-
- internal const int MethodNameBufferSize = 100;
-
- internal static void AppendParameters(ref ValueStringBuilder sbParamList, Type[] parameterTypes, CallingConventions callingConvention)
- {
- string comma = "";
-
- for (int i = 0; i < parameterTypes.Length; i++)
- {
- Type t = parameterTypes[i];
-
- sbParamList.Append(comma);
-
- string typeName = t.FormatTypeName();
-
- // Legacy: Why use "ByRef" for by ref parameters? What language is this?
- // VB uses "ByRef" but it should precede (not follow) the parameter name.
- // Why don't we just use "&"?
- if (t.IsByRef)
- {
- sbParamList.Append(typeName.AsSpan().TrimEnd('&'));
- sbParamList.Append(" ByRef");
- }
- else
- {
- sbParamList.Append(typeName);
- }
-
- comma = ", ";
- }
-
- if ((callingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
- {
- sbParamList.Append(comma);
- sbParamList.Append("...");
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodBody.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/MethodBody.cs
deleted file mode 100644
index 1f05ef5b057..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodBody.cs
+++ /dev/null
@@ -1,19 +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 System.Collections.Generic;
-
-namespace System.Reflection
-{
- public class MethodBody
- {
- protected MethodBody() { }
- public virtual int LocalSignatureMetadataToken => 0;
- public virtual IList<LocalVariableInfo> LocalVariables => throw new ArgumentNullException("array");
- public virtual int MaxStackSize => 0;
- public virtual bool InitLocals => false;
- public virtual byte[]? GetILAsByteArray() => null;
- public virtual IList<ExceptionHandlingClause> ExceptionHandlingClauses => throw new ArgumentNullException("array");
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodImplAttributes.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/MethodImplAttributes.cs
deleted file mode 100644
index 7cdb5eaf35f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodImplAttributes.cs
+++ /dev/null
@@ -1,38 +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.
-
-namespace System.Reflection
-{
- // This Enum matchs the CorMethodImpl defined in CorHdr.h
- public enum MethodImplAttributes
- {
- // code impl mask
- CodeTypeMask = 0x0003, // Flags about code type.
- IL = 0x0000, // Method impl is IL.
- Native = 0x0001, // Method impl is native.
- OPTIL = 0x0002, // Method impl is OPTIL
- Runtime = 0x0003, // Method impl is provided by the runtime.
- // end code impl mask
-
- // managed mask
- ManagedMask = 0x0004, // Flags specifying whether the code is managed or unmanaged.
- Unmanaged = 0x0004, // Method impl is unmanaged, otherwise managed.
- Managed = 0x0000, // Method impl is managed.
- // end managed mask
-
- // implementation info and interop
- ForwardRef = 0x0010, // Indicates method is not defined; used primarily in merge scenarios.
- PreserveSig = 0x0080, // Indicates method sig is exported exactly as declared.
-
- InternalCall = 0x1000, // Internal Call...
-
- Synchronized = 0x0020, // Method is single threaded through the body.
- NoInlining = 0x0008, // Method may not be inlined.
- AggressiveInlining = 0x0100, // Method should be inlined if possible.
- NoOptimization = 0x0040, // Method may not be optimized.
- AggressiveOptimization = 0x0200, // Method may contain hot code and should be aggressively optimized.
-
- MaxMethodImplVal = 0xffff,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodInfo.Internal.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/MethodInfo.Internal.cs
deleted file mode 100644
index 8bb66968ddb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodInfo.Internal.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.Reflection
-{
- public abstract partial class MethodInfo : MethodBase
- {
-#if CORERT
- public // Needs to be public so that Reflection.Core can see it.
-#else
- internal
-#endif
- virtual int GenericParameterCount => GetGenericArguments().Length;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs
deleted file mode 100644
index b274a656e44..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs
+++ /dev/null
@@ -1,54 +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 System.Runtime.CompilerServices;
-
-namespace System.Reflection
-{
- public abstract partial class MethodInfo : MethodBase
- {
- protected MethodInfo() { }
-
- public override MemberTypes MemberType => MemberTypes.Method;
-
- public virtual ParameterInfo ReturnParameter => throw NotImplemented.ByDesign;
- public virtual Type ReturnType => throw NotImplemented.ByDesign;
-
- public override Type[] GetGenericArguments() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
- public virtual MethodInfo GetGenericMethodDefinition() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
- public virtual MethodInfo MakeGenericMethod(params Type[] typeArguments) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
-
- public abstract MethodInfo GetBaseDefinition();
-
- public abstract ICustomAttributeProvider ReturnTypeCustomAttributes { get; }
-
- public virtual Delegate CreateDelegate(Type delegateType) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
- public virtual Delegate CreateDelegate(Type delegateType, object? target) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
-
- public override bool Equals(object? obj) => base.Equals(obj);
- public override int GetHashCode() => base.GetHashCode();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(MethodInfo? left, MethodInfo? right)
- {
- // Test "right" first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (right is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (left is null) ? true : false;
- }
-
- // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
- if ((object?)left == (object)right)
- {
- return true;
- }
-
- return (left is null) ? false : left.Equals(right);
- }
-
- public static bool operator !=(MethodInfo? left, MethodInfo? right) => !(left == right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Missing.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Missing.cs
deleted file mode 100644
index 46ab32fccf6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Missing.cs
+++ /dev/null
@@ -1,20 +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 System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- public sealed class Missing : ISerializable
- {
- public static readonly Missing Value = new Missing();
-
- private Missing() { }
-
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Module.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Module.cs
deleted file mode 100644
index 07ac2613526..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Module.cs
+++ /dev/null
@@ -1,168 +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 System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- public abstract partial class Module : ICustomAttributeProvider, ISerializable
- {
- protected Module() { }
-
- public virtual Assembly Assembly => throw NotImplemented.ByDesign;
- public virtual string FullyQualifiedName => throw NotImplemented.ByDesign;
- public virtual string Name => throw NotImplemented.ByDesign;
-
- public virtual int MDStreamVersion => throw NotImplemented.ByDesign;
- public virtual Guid ModuleVersionId => throw NotImplemented.ByDesign;
- public virtual string ScopeName => throw NotImplemented.ByDesign;
- public ModuleHandle ModuleHandle => GetModuleHandleImpl();
- protected virtual ModuleHandle GetModuleHandleImpl() => ModuleHandle.EmptyHandle; // Not an api but declared protected because of Reflection.Core/Corelib divide (when built by CoreRt)
- public virtual void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine) { throw NotImplemented.ByDesign; }
- public virtual bool IsResource() { throw NotImplemented.ByDesign; }
-
- public virtual bool IsDefined(Type attributeType, bool inherit) { throw NotImplemented.ByDesign; }
- public virtual IEnumerable<CustomAttributeData> CustomAttributes => GetCustomAttributesData();
- public virtual IList<CustomAttributeData> GetCustomAttributesData() { throw NotImplemented.ByDesign; }
- public virtual object[] GetCustomAttributes(bool inherit) { throw NotImplemented.ByDesign; }
- public virtual object[] GetCustomAttributes(Type attributeType, bool inherit) { throw NotImplemented.ByDesign; }
-
- public MethodInfo? GetMethod(string name)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- return GetMethodImpl(name, Module.DefaultLookup, null, CallingConventions.Any, null, null);
- }
-
- public MethodInfo? GetMethod(string name, Type[] types) => GetMethod(name, Module.DefaultLookup, null, CallingConventions.Any, types, null);
- public MethodInfo? GetMethod(string name, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- if (types == null)
- throw new ArgumentNullException(nameof(types));
- for (int i = 0; i < types.Length; i++)
- {
- if (types[i] == null)
- throw new ArgumentNullException(nameof(types));
- }
- return GetMethodImpl(name, bindingAttr, binder, callConvention, types, modifiers);
- }
-
- protected virtual MethodInfo? GetMethodImpl(string name, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[]? types, ParameterModifier[]? modifiers) { throw NotImplemented.ByDesign; }
-
- public MethodInfo[] GetMethods() => GetMethods(Module.DefaultLookup);
- public virtual MethodInfo[] GetMethods(BindingFlags bindingFlags) { throw NotImplemented.ByDesign; }
-
- public FieldInfo? GetField(string name) => GetField(name, Module.DefaultLookup);
- public virtual FieldInfo? GetField(string name, BindingFlags bindingAttr) { throw NotImplemented.ByDesign; }
-
- public FieldInfo[] GetFields() => GetFields(Module.DefaultLookup);
- public virtual FieldInfo[] GetFields(BindingFlags bindingFlags) { throw NotImplemented.ByDesign; }
-
- public virtual Type[] GetTypes() { throw NotImplemented.ByDesign; }
-
- public virtual Type? GetType(string className) => GetType(className, throwOnError: false, ignoreCase: false);
- public virtual Type? GetType(string className, bool ignoreCase) => GetType(className, throwOnError: false, ignoreCase: ignoreCase);
- public virtual Type? GetType(string className, bool throwOnError, bool ignoreCase) { throw NotImplemented.ByDesign; }
-
- public virtual Type[] FindTypes(TypeFilter? filter, object? filterCriteria)
- {
- Type[] c = GetTypes();
- int cnt = 0;
- for (int i = 0; i < c.Length; i++)
- {
- if (filter != null && !filter(c[i], filterCriteria))
- c[i] = null!;
- else
- cnt++;
- }
- if (cnt == c.Length)
- return c;
-
- Type[] ret = new Type[cnt];
- cnt = 0;
- for (int i = 0; i < c.Length; i++)
- {
- if (c[i] != null)
- ret[cnt++] = c[i];
- }
- return ret;
- }
-
- public virtual int MetadataToken => throw NotImplemented.ByDesign;
-
- public FieldInfo? ResolveField(int metadataToken) => ResolveField(metadataToken, null, null);
- public virtual FieldInfo? ResolveField(int metadataToken, Type[]? genericTypeArguments, Type[]? genericMethodArguments) { throw NotImplemented.ByDesign; }
-
- public MemberInfo? ResolveMember(int metadataToken) => ResolveMember(metadataToken, null, null);
- public virtual MemberInfo? ResolveMember(int metadataToken, Type[]? genericTypeArguments, Type[]? genericMethodArguments) { throw NotImplemented.ByDesign; }
-
- public MethodBase? ResolveMethod(int metadataToken) => ResolveMethod(metadataToken, null, null);
- public virtual MethodBase? ResolveMethod(int metadataToken, Type[]? genericTypeArguments, Type[]? genericMethodArguments) { throw NotImplemented.ByDesign; }
-
- public virtual byte[] ResolveSignature(int metadataToken) { throw NotImplemented.ByDesign; }
- public virtual string ResolveString(int metadataToken) { throw NotImplemented.ByDesign; }
-
- public Type ResolveType(int metadataToken) => ResolveType(metadataToken, null, null);
- public virtual Type ResolveType(int metadataToken, Type[]? genericTypeArguments, Type[]? genericMethodArguments) { throw NotImplemented.ByDesign; }
-
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { throw NotImplemented.ByDesign; }
-
- public override bool Equals(object? o) => base.Equals(o);
- public override int GetHashCode() => base.GetHashCode();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Module? left, Module? right)
- {
- // Test "right" first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (right is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (left is null) ? true : false;
- }
-
- // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
- if ((object?)left == (object)right)
- {
- return true;
- }
-
- return (left is null) ? false : left.Equals(right);
- }
-
- public static bool operator !=(Module? left, Module? right) => !(left == right);
-
- public override string ToString() => ScopeName;
-
- public static readonly TypeFilter FilterTypeName = (m, c) => FilterTypeNameImpl(m, c!, StringComparison.Ordinal);
- public static readonly TypeFilter FilterTypeNameIgnoreCase = (m, c) => FilterTypeNameImpl(m, c!, StringComparison.OrdinalIgnoreCase);
-
- private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
-
- // FilterTypeName
- // This method will filter the class based upon the name. It supports
- // a trailing wild card.
- private static bool FilterTypeNameImpl(Type cls, object filterCriteria, StringComparison comparison)
- {
- // Check that the criteria object is a String object
- if (!(filterCriteria is string str))
- {
- throw new InvalidFilterCriteriaException(SR.InvalidFilterCriteriaException_CritString);
- }
- // Check to see if this is a prefix or exact match requirement
- if (str.Length > 0 && str[^1] == '*')
- {
- ReadOnlySpan<char> slice = str.AsSpan(0, str.Length - 1);
- return cls.Name.AsSpan().StartsWith(slice, comparison);
- }
-
- return cls.Name.Equals(str, comparison);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ModuleResolveEventHandler.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ModuleResolveEventHandler.cs
deleted file mode 100644
index 7ac0f06f67e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ModuleResolveEventHandler.cs
+++ /dev/null
@@ -1,8 +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.
-
-namespace System.Reflection
-{
- public delegate Module ModuleResolveEventHandler(object sender, ResolveEventArgs e);
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ObfuscateAssemblyAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ObfuscateAssemblyAttribute.cs
deleted file mode 100644
index f6f8438f144..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ObfuscateAssemblyAttribute.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
- public sealed class ObfuscateAssemblyAttribute : Attribute
- {
- public ObfuscateAssemblyAttribute(bool assemblyIsPrivate)
- {
- AssemblyIsPrivate = assemblyIsPrivate;
- }
-
- public bool AssemblyIsPrivate { get; }
- public bool StripAfterObfuscation { get; set; } = true;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ObfuscationAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ObfuscationAttribute.cs
deleted file mode 100644
index 5e1f555b43f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ObfuscationAttribute.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Reflection
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Delegate,
- AllowMultiple = true, Inherited = false)]
- public sealed class ObfuscationAttribute : Attribute
- {
- public ObfuscationAttribute()
- {
- }
-
- public bool StripAfterObfuscation { get; set; } = true;
- public bool Exclude { get; set; } = true;
- public bool ApplyToMembers { get; set; } = true;
- public string? Feature { get; set; } = "all";
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ParameterAttributes.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ParameterAttributes.cs
deleted file mode 100644
index 82e77a20e08..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ParameterAttributes.cs
+++ /dev/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.
-
-// ParameterAttributes is an enum defining the attributes that may be
-// associated with a Parameter. These are defined in CorHdr.h.
-
-namespace System.Reflection
-{
- // This Enum matchs the CorParamAttr defined in CorHdr.h
- [Flags]
- public enum ParameterAttributes
- {
- None = 0x0000, // no flag is specified
- In = 0x0001, // Param is [In]
- Out = 0x0002, // Param is [Out]
- Lcid = 0x0004, // Param is [lcid]
-
- Retval = 0x0008, // Param is [Retval]
- Optional = 0x0010, // Param is optional
-
- HasDefault = 0x1000, // Param has default value.
- HasFieldMarshal = 0x2000, // Param has FieldMarshal.
-
- Reserved3 = 0x4000,
- Reserved4 = 0x8000,
- ReservedMask = 0xf000,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ParameterInfo.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ParameterInfo.cs
deleted file mode 100644
index ef13b9031f5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ParameterInfo.cs
+++ /dev/null
@@ -1,110 +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 System.Collections.Generic;
-using System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- public class ParameterInfo : ICustomAttributeProvider, IObjectReference
- {
- protected ParameterInfo() { }
-
- public virtual ParameterAttributes Attributes => AttrsImpl;
- public virtual MemberInfo Member => MemberImpl;
- public virtual string? Name => NameImpl;
- public virtual Type ParameterType => ClassImpl!;
- public virtual int Position => PositionImpl;
-
- public bool IsIn => (Attributes & ParameterAttributes.In) != 0;
- public bool IsLcid => (Attributes & ParameterAttributes.Lcid) != 0;
- public bool IsOptional => (Attributes & ParameterAttributes.Optional) != 0;
- public bool IsOut => (Attributes & ParameterAttributes.Out) != 0;
- public bool IsRetval => (Attributes & ParameterAttributes.Retval) != 0;
-
- public virtual object? DefaultValue => throw NotImplemented.ByDesign;
- public virtual object? RawDefaultValue => throw NotImplemented.ByDesign;
- public virtual bool HasDefaultValue => throw NotImplemented.ByDesign;
-
- public virtual bool IsDefined(Type attributeType, bool inherit)
- {
- if (attributeType == null)
- throw new ArgumentNullException(nameof(attributeType));
-
- return false;
- }
-
- public virtual IEnumerable<CustomAttributeData> CustomAttributes => GetCustomAttributesData();
- public virtual IList<CustomAttributeData> GetCustomAttributesData() { throw NotImplemented.ByDesign; }
-
- public virtual object[] GetCustomAttributes(bool inherit) => Array.Empty<object>();
- public virtual object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- if (attributeType == null)
- throw new ArgumentNullException(nameof(attributeType));
-
- return Array.Empty<object>();
- }
-
- public virtual Type[] GetOptionalCustomModifiers() => Array.Empty<Type>();
- public virtual Type[] GetRequiredCustomModifiers() => Array.Empty<Type>();
-
- public virtual int MetadataToken => MetadataToken_ParamDef;
-
- public object GetRealObject(StreamingContext context)
- {
- // Once all the serializable fields have come in we can set up the real
- // instance based on just two of them (MemberImpl and PositionImpl).
-
- if (MemberImpl == null)
- throw new SerializationException(SR.Serialization_InsufficientState);
-
- ParameterInfo[]? args = null;
-
- switch (MemberImpl.MemberType)
- {
- case MemberTypes.Constructor:
- case MemberTypes.Method:
- if (PositionImpl == -1)
- {
- if (MemberImpl.MemberType == MemberTypes.Method)
- return ((MethodInfo)MemberImpl).ReturnParameter;
- else
- throw new SerializationException(SR.Serialization_BadParameterInfo);
- }
- else
- {
- args = ((MethodBase)MemberImpl).GetParametersNoCopy();
-
- if (args != null && PositionImpl < args.Length)
- return args[PositionImpl];
- else
- throw new SerializationException(SR.Serialization_BadParameterInfo);
- }
-
- case MemberTypes.Property:
- args = ((PropertyInfo)MemberImpl).GetIndexParameters();
-
- if (args != null && PositionImpl > -1 && PositionImpl < args.Length)
- return args[PositionImpl];
- else
- throw new SerializationException(SR.Serialization_BadParameterInfo);
-
- default:
- throw new SerializationException(SR.Serialization_NoParameterInfo);
- }
- }
-
- public override string ToString() => ParameterType.FormatTypeName() + " " + Name;
-
- protected ParameterAttributes AttrsImpl;
- protected Type? ClassImpl;
- protected object? DefaultValueImpl;
- protected MemberInfo MemberImpl = null!;
- protected string? NameImpl;
- protected int PositionImpl;
-
- private const int MetadataToken_ParamDef = 0x08000000;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ParameterModifier.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ParameterModifier.cs
deleted file mode 100644
index d280c94afb8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ParameterModifier.cs
+++ /dev/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.
-
-namespace System.Reflection
-{
- public readonly struct ParameterModifier
- {
- private readonly bool[] _byRef;
-
- public ParameterModifier(int parameterCount)
- {
- if (parameterCount <= 0)
- throw new ArgumentException(SR.Arg_ParmArraySize);
-
- _byRef = new bool[parameterCount];
- }
-
- public bool this[int index]
- {
- get => _byRef[index];
- set => _byRef[index] = value;
- }
-
-#if CORECLR
- internal bool[] IsByRefArray => _byRef;
-#endif
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Pointer.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Pointer.cs
deleted file mode 100644
index e1a9990cf0e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/Pointer.cs
+++ /dev/null
@@ -1,51 +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 System.Diagnostics;
-using System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- [CLSCompliant(false)]
- public sealed unsafe class Pointer : ISerializable
- {
- // CoreCLR: Do not add or remove fields without updating the ReflectionPointer class in runtimehandles.h
- private readonly void* _ptr;
- private readonly Type _ptrType;
-
- private Pointer(void* ptr, Type ptrType)
- {
- Debug.Assert(ptrType.IsRuntimeImplemented()); // CoreCLR: For CoreRT's sake, _ptrType has to be declared as "Type", but in fact, it is always a RuntimeType. Code on CoreCLR expects this.
- _ptr = ptr;
- _ptrType = ptrType;
- }
-
- public static object Box(void* ptr, Type type)
- {
- if (type == null)
- throw new ArgumentNullException(nameof(type));
- if (!type.IsPointer)
- throw new ArgumentException(SR.Arg_MustBePointer, nameof(ptr));
- if (!type.IsRuntimeImplemented())
- throw new ArgumentException(SR.Arg_MustBeType, nameof(ptr));
-
- return new Pointer(ptr, type);
- }
-
- public static void* Unbox(object ptr)
- {
- if (!(ptr is Pointer))
- throw new ArgumentException(SR.Arg_MustBePointer, nameof(ptr));
- return ((Pointer)ptr)._ptr;
- }
-
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- internal Type GetPointerType() => _ptrType;
- internal IntPtr GetPointerValue() => (IntPtr)_ptr;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/PortableExecutableKinds.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/PortableExecutableKinds.cs
deleted file mode 100644
index 978d5348b23..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/PortableExecutableKinds.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- [Flags]
- public enum PortableExecutableKinds
- {
- NotAPortableExecutableImage = 0x0,
- ILOnly = 0x1,
- Required32Bit = 0x2,
- PE32Plus = 0x4,
- Unmanaged32Bit = 0x8,
- Preferred32Bit = 0x10,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ProcessorArchitecture.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ProcessorArchitecture.cs
deleted file mode 100644
index becb346c4fd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ProcessorArchitecture.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.Reflection
-{
- public enum ProcessorArchitecture
- {
- None = 0x0000,
- MSIL = 0x0001,
- X86 = 0x0002,
- IA64 = 0x0003,
- Amd64 = 0x0004,
- Arm = 0x0005
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/PropertyAttributes.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/PropertyAttributes.cs
deleted file mode 100644
index b85b636e395..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/PropertyAttributes.cs
+++ /dev/null
@@ -1,25 +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.
-
-// PropertyAttributes is an enum which defines the attributes that may be associated
-// with a property. The values here are defined in Corhdr.h.
-
-namespace System.Reflection
-{
- // This Enum matchs the CorPropertyAttr defined in CorHdr.h
- [Flags]
- public enum PropertyAttributes
- {
- None = 0x0000,
- SpecialName = 0x0200, // property is special. Name describes how.
-
- RTSpecialName = 0x0400, // Runtime(metadata internal APIs) should check name encoding.
- HasDefault = 0x1000, // Property has default
-
- Reserved2 = 0x2000,
- Reserved3 = 0x4000,
- Reserved4 = 0x8000,
- ReservedMask = 0xf400,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs
deleted file mode 100644
index 663d52dbb7c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs
+++ /dev/null
@@ -1,84 +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 System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-
-namespace System.Reflection
-{
- public abstract class PropertyInfo : MemberInfo
- {
- protected PropertyInfo() { }
-
- public override MemberTypes MemberType => MemberTypes.Property;
-
- public abstract Type PropertyType { get; }
- public abstract ParameterInfo[] GetIndexParameters();
-
- public abstract PropertyAttributes Attributes { get; }
- public bool IsSpecialName => (Attributes & PropertyAttributes.SpecialName) != 0;
-
- public abstract bool CanRead { get; }
- public abstract bool CanWrite { get; }
-
- public MethodInfo[] GetAccessors() => GetAccessors(nonPublic: false);
- public abstract MethodInfo[] GetAccessors(bool nonPublic);
-
- public virtual MethodInfo? GetMethod => GetGetMethod(nonPublic: true);
- public MethodInfo? GetGetMethod() => GetGetMethod(nonPublic: false);
- public abstract MethodInfo? GetGetMethod(bool nonPublic);
-
- public virtual MethodInfo? SetMethod => GetSetMethod(nonPublic: true);
- public MethodInfo? GetSetMethod() => GetSetMethod(nonPublic: false);
- public abstract MethodInfo? GetSetMethod(bool nonPublic);
-
- public virtual Type[] GetOptionalCustomModifiers() => Array.Empty<Type>();
- public virtual Type[] GetRequiredCustomModifiers() => Array.Empty<Type>();
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public object? GetValue(object? obj) => GetValue(obj, index: null);
- [DebuggerHidden]
- [DebuggerStepThrough]
- public virtual object? GetValue(object? obj, object?[]? index) => GetValue(obj, BindingFlags.Default, binder: null, index: index, culture: null);
- public abstract object? GetValue(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? index, CultureInfo? culture);
-
- public virtual object? GetConstantValue() { throw NotImplemented.ByDesign; }
- public virtual object? GetRawConstantValue() { throw NotImplemented.ByDesign; }
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public void SetValue(object? obj, object? value) => SetValue(obj, value, index: null);
- [DebuggerHidden]
- [DebuggerStepThrough]
- public virtual void SetValue(object? obj, object? value, object?[]? index) => SetValue(obj, value, BindingFlags.Default, binder: null, index: index, culture: null);
- public abstract void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, object?[]? index, CultureInfo? culture);
-
- public override bool Equals(object? obj) => base.Equals(obj);
- public override int GetHashCode() => base.GetHashCode();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(PropertyInfo? left, PropertyInfo? right)
- {
- // Test "right" first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (right is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (left is null) ? true : false;
- }
-
- // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
- if ((object?)left == (object)right)
- {
- return true;
- }
-
- return (left is null) ? false : left.Equals(right);
- }
-
- public static bool operator !=(PropertyInfo? left, PropertyInfo? right) => !(left == right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ReflectionContext.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ReflectionContext.cs
deleted file mode 100644
index dc96d15dee0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ReflectionContext.cs
+++ /dev/null
@@ -1,23 +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.
-
-namespace System.Reflection
-{
- public abstract class ReflectionContext
- {
- protected ReflectionContext() { }
-
- public abstract Assembly MapAssembly(Assembly assembly);
-
- public abstract TypeInfo MapType(TypeInfo type);
-
- public virtual TypeInfo GetTypeForObject(object value)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- return MapType(value.GetType().GetTypeInfo());
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ReflectionTypeLoadException.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ReflectionTypeLoadException.cs
deleted file mode 100644
index 29a624e6cf5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ReflectionTypeLoadException.cs
+++ /dev/null
@@ -1,73 +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 System.Runtime.Serialization;
-using System.Text;
-
-namespace System.Reflection
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class ReflectionTypeLoadException : SystemException, ISerializable
- {
- public ReflectionTypeLoadException(Type[]? classes, Exception?[]? exceptions)
- : base(null)
- {
- Types = classes;
- LoaderExceptions = exceptions;
- HResult = HResults.COR_E_REFLECTIONTYPELOAD;
- }
-
- public ReflectionTypeLoadException(Type[]? classes, Exception?[]? exceptions, string? message)
- : base(message)
- {
- Types = classes;
- LoaderExceptions = exceptions;
- HResult = HResults.COR_E_REFLECTIONTYPELOAD;
- }
-
- private ReflectionTypeLoadException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- LoaderExceptions = (Exception[]?)(info.GetValue("Exceptions", typeof(Exception[])));
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("Types", null, typeof(Type[]));
- info.AddValue("Exceptions", LoaderExceptions, typeof(Exception[]));
- }
-
- public Type[]? Types { get; }
-
- public Exception?[]? LoaderExceptions { get; }
-
- public override string Message => CreateString(isMessage: true);
-
- public override string ToString() => CreateString(isMessage: false);
-
- private string CreateString(bool isMessage)
- {
- string baseValue = isMessage ? base.Message : base.ToString();
-
- Exception?[]? exceptions = LoaderExceptions;
- if (exceptions == null || exceptions.Length == 0)
- {
- return baseValue;
- }
-
- var text = new StringBuilder(baseValue);
- foreach (Exception? e in exceptions)
- {
- if (e != null)
- {
- text.AppendLine();
- text.Append(isMessage ? e.Message : e.ToString());
- }
- }
- return text.ToString();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ResourceAttributes.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ResourceAttributes.cs
deleted file mode 100644
index 498ef7c25c5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ResourceAttributes.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Reflection
-{
- [Flags]
- public enum ResourceAttributes
- {
- Public = 0x0001,
- Private = 0x0002,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/ResourceLocation.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/ResourceLocation.cs
deleted file mode 100644
index a5722a1b63e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/ResourceLocation.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Reflection
-{
- [Flags]
- public enum ResourceLocation
- {
- ContainedInAnotherAssembly = 2,
- ContainedInManifestFile = 4,
- Embedded = 1,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureArrayType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureArrayType.cs
deleted file mode 100644
index b02bd787f7a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureArrayType.cs
+++ /dev/null
@@ -1,46 +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 System.Diagnostics;
-
-namespace System.Reflection
-{
- internal sealed class SignatureArrayType : SignatureHasElementType
- {
- internal SignatureArrayType(SignatureType elementType, int rank, bool isMultiDim)
- : base(elementType)
- {
- Debug.Assert(rank > 0);
- Debug.Assert(rank == 1 || isMultiDim);
-
- _rank = rank;
- _isMultiDim = isMultiDim;
- }
-
- protected sealed override bool IsArrayImpl() => true;
- protected sealed override bool IsByRefImpl() => false;
- protected sealed override bool IsPointerImpl() => false;
-
- public sealed override bool IsSZArray => !_isMultiDim;
- public sealed override bool IsVariableBoundArray => _isMultiDim;
-
- public sealed override int GetArrayRank() => _rank;
-
- protected sealed override string Suffix
- {
- get
- {
- if (!_isMultiDim)
- return "[]";
- else if (_rank == 1)
- return "[*]";
- else
- return "[" + new string(',', _rank - 1) + "]";
- }
- }
-
- private readonly int _rank;
- private readonly bool _isMultiDim;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureByRefType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureByRefType.cs
deleted file mode 100644
index db083a394f6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureByRefType.cs
+++ /dev/null
@@ -1,25 +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.
-
-namespace System.Reflection
-{
- internal sealed class SignatureByRefType : SignatureHasElementType
- {
- internal SignatureByRefType(SignatureType elementType)
- : base(elementType)
- {
- }
-
- protected sealed override bool IsArrayImpl() => false;
- protected sealed override bool IsByRefImpl() => true;
- protected sealed override bool IsPointerImpl() => false;
-
- public sealed override bool IsSZArray => false;
- public sealed override bool IsVariableBoundArray => false;
-
- public sealed override int GetArrayRank() => throw new ArgumentException(SR.Argument_HasToBeArrayClass);
-
- protected sealed override string Suffix => "&";
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs
deleted file mode 100644
index 57a0dd55dcf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs
+++ /dev/null
@@ -1,85 +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 System.Text;
-
-namespace System.Reflection
-{
- internal sealed class SignatureConstructedGenericType : SignatureType
- {
- // 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)
- {
- if (genericTypeDefinition is null)
- throw new ArgumentNullException(nameof(genericTypeDefinition));
-
- if (typeArguments is null)
- throw new ArgumentNullException(nameof(typeArguments));
-
- typeArguments = (Type[])(typeArguments.Clone());
- for (int i = 0; i < typeArguments.Length; i++)
- {
- if (typeArguments[i] is null)
- throw new ArgumentNullException(nameof(typeArguments));
- }
-
- _genericTypeDefinition = genericTypeDefinition;
- _genericTypeArguments = typeArguments;
- }
-
- public sealed override bool IsTypeDefinition => false;
- public sealed override bool IsGenericTypeDefinition => false;
- protected sealed override bool HasElementTypeImpl() => false;
- protected sealed override bool IsArrayImpl() => false;
- protected sealed override bool IsByRefImpl() => false;
- public sealed override bool IsByRefLike => _genericTypeDefinition.IsByRefLike;
- protected sealed override bool IsPointerImpl() => false;
- public sealed override bool IsSZArray => false;
- public sealed override bool IsVariableBoundArray => false;
- public sealed override bool IsConstructedGenericType => true;
- public sealed override bool IsGenericParameter => false;
- public sealed override bool IsGenericTypeParameter => false;
- public sealed override bool IsGenericMethodParameter => false;
- public sealed override bool ContainsGenericParameters
- {
- get
- {
- for (int i = 0; i < _genericTypeArguments.Length; i++)
- {
- if (_genericTypeArguments[i].ContainsGenericParameters)
- return true;
- }
- return false;
- }
- }
-
- internal sealed override SignatureType? ElementType => null;
- public sealed override int GetArrayRank() => throw new ArgumentException(SR.Argument_HasToBeArrayClass);
- public sealed override Type GetGenericTypeDefinition() => _genericTypeDefinition;
- public sealed override Type[] GetGenericArguments() => GenericTypeArguments;
- public sealed override Type[] GenericTypeArguments => (Type[])(_genericTypeArguments.Clone());
- public sealed override int GenericParameterPosition => throw new InvalidOperationException(SR.Arg_NotGenericParameter);
- public sealed override string Name => _genericTypeDefinition.Name;
- public sealed override string? Namespace => _genericTypeDefinition.Namespace;
-
- public sealed override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append(_genericTypeDefinition.ToString());
- sb.Append('[');
- for (int i = 0; i < _genericTypeArguments.Length; i++)
- {
- if (i != 0)
- sb.Append(',');
- sb.Append(_genericTypeArguments[i].ToString());
- }
- sb.Append(']');
- return sb.ToString();
- }
-
- private readonly Type _genericTypeDefinition;
- private readonly Type[] _genericTypeArguments;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureGenericMethodParameterType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureGenericMethodParameterType.cs
deleted file mode 100644
index 76a13f504f4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureGenericMethodParameterType.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Reflection
-{
- internal sealed class SignatureGenericMethodParameterType : SignatureGenericParameterType
- {
- internal SignatureGenericMethodParameterType(int position)
- : base(position)
- {
- }
-
- public sealed override bool IsGenericTypeParameter => false;
- public sealed override bool IsGenericMethodParameter => true;
-
- public sealed override string Name => "!!" + GenericParameterPosition;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureGenericParameterType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureGenericParameterType.cs
deleted file mode 100644
index 2d3d4da77ca..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureGenericParameterType.cs
+++ /dev/null
@@ -1,44 +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 System.Diagnostics;
-
-namespace System.Reflection
-{
- internal abstract class SignatureGenericParameterType : SignatureType
- {
- protected SignatureGenericParameterType(int position)
- {
- Debug.Assert(position >= 0);
- _position = position;
- }
-
- public sealed override bool IsTypeDefinition => false;
- public sealed override bool IsGenericTypeDefinition => false;
- protected sealed override bool HasElementTypeImpl() => false;
- protected sealed override bool IsArrayImpl() => false;
- protected sealed override bool IsByRefImpl() => false;
- public sealed override bool IsByRefLike => false;
- protected sealed override bool IsPointerImpl() => false;
- public sealed override bool IsSZArray => false;
- public sealed override bool IsVariableBoundArray => false;
- public sealed override bool IsConstructedGenericType => false;
- public sealed override bool IsGenericParameter => true;
- public abstract override bool IsGenericMethodParameter { get; }
- public sealed override bool ContainsGenericParameters => true;
-
- internal sealed override SignatureType? ElementType => null;
- public sealed override int GetArrayRank() => throw new ArgumentException(SR.Argument_HasToBeArrayClass);
- public sealed override Type GetGenericTypeDefinition() => throw new InvalidOperationException(SR.InvalidOperation_NotGenericType);
- public sealed override Type[] GetGenericArguments() => Array.Empty<Type>();
- public sealed override Type[] GenericTypeArguments => Array.Empty<Type>();
- public sealed override int GenericParameterPosition => _position;
- public abstract override string Name { get; }
- public sealed override string? Namespace => null;
-
- public sealed override string ToString() => Name;
-
- private readonly int _position;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureHasElementType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureHasElementType.cs
deleted file mode 100644
index 55fd863d6e8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureHasElementType.cs
+++ /dev/null
@@ -1,47 +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 System.Diagnostics;
-
-namespace System.Reflection
-{
- internal abstract class SignatureHasElementType : SignatureType
- {
- protected SignatureHasElementType(SignatureType elementType)
- {
- Debug.Assert(elementType != null);
- _elementType = elementType;
- }
-
- public sealed override bool IsTypeDefinition => false;
- public sealed override bool IsGenericTypeDefinition => false;
- protected sealed override bool HasElementTypeImpl() => true;
- protected abstract override bool IsArrayImpl();
- protected abstract override bool IsByRefImpl();
- public sealed override bool IsByRefLike => false;
- protected abstract override bool IsPointerImpl();
- public abstract override bool IsSZArray { get; }
- public abstract override bool IsVariableBoundArray { get; }
- public sealed override bool IsConstructedGenericType => false;
- public sealed override bool IsGenericParameter => false;
- public sealed override bool IsGenericTypeParameter => false;
- public sealed override bool IsGenericMethodParameter => false;
- public sealed override bool ContainsGenericParameters => _elementType.ContainsGenericParameters;
-
- internal sealed override SignatureType? ElementType => _elementType;
- public abstract override int GetArrayRank();
- public sealed override Type GetGenericTypeDefinition() => throw new InvalidOperationException(SR.InvalidOperation_NotGenericType);
- public sealed override Type[] GetGenericArguments() => Array.Empty<Type>();
- public sealed override Type[] GenericTypeArguments => Array.Empty<Type>();
- public sealed override int GenericParameterPosition => throw new InvalidOperationException(SR.Arg_NotGenericParameter);
- public sealed override string Name => _elementType.Name + Suffix;
- public sealed override string? Namespace => _elementType.Namespace;
-
- public sealed override string ToString() => _elementType.ToString() + Suffix;
-
- protected abstract string Suffix { get; }
-
- private readonly SignatureType _elementType;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/SignaturePointerType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/SignaturePointerType.cs
deleted file mode 100644
index fdc32bdbe2a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/SignaturePointerType.cs
+++ /dev/null
@@ -1,25 +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.
-
-namespace System.Reflection
-{
- internal sealed class SignaturePointerType : SignatureHasElementType
- {
- internal SignaturePointerType(SignatureType elementType)
- : base(elementType)
- {
- }
-
- protected sealed override bool IsArrayImpl() => false;
- protected sealed override bool IsByRefImpl() => false;
- protected sealed override bool IsPointerImpl() => true;
-
- public sealed override bool IsSZArray => false;
- public sealed override bool IsVariableBoundArray => false;
-
- public sealed override int GetArrayRank() => throw new ArgumentException(SR.Argument_HasToBeArrayClass);
-
- protected sealed override string Suffix => "*";
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs
deleted file mode 100644
index 5d2eca3a1a3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs
+++ /dev/null
@@ -1,146 +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 System.Globalization;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection
-{
- //
- // Signature Types are highly restricted Type objects that can be passed in the Type[] parameter to Type.GetMethod(). Their primary
- // use is to pass types representing generic parameters defined by the method, or types composed from them. Passing in the normal
- // generic parameter Type obtained from MethodInfo.GetGenericArguments() is usually impractical (if you had the method, you wouldn't
- // be looking for it!)
- //
- internal abstract class SignatureType : Type
- {
- public sealed override bool IsSignatureType => true;
-
- // Type flavor predicates
- public abstract override bool IsTypeDefinition { get; }
- protected abstract override bool HasElementTypeImpl();
- protected abstract override bool IsArrayImpl();
- public abstract override bool IsSZArray { get; }
- public abstract override bool IsVariableBoundArray { get; }
- protected abstract override bool IsByRefImpl();
- public abstract override bool IsByRefLike { get; }
- protected abstract override bool IsPointerImpl();
- public sealed override bool IsGenericType => IsGenericTypeDefinition || IsConstructedGenericType;
- public abstract override bool IsGenericTypeDefinition { get; }
- public abstract override bool IsConstructedGenericType { get; }
- public abstract override bool IsGenericParameter { get; }
- public abstract override bool IsGenericTypeParameter { get; }
- public abstract override bool IsGenericMethodParameter { get; }
- public abstract override bool ContainsGenericParameters { get; }
- public sealed override MemberTypes MemberType => MemberTypes.TypeInfo;
-
- // Compositors
- public sealed override Type MakeArrayType() => new SignatureArrayType(this, rank: 1, isMultiDim: false);
- public sealed override Type MakeArrayType(int rank)
- {
- if (rank <= 0)
- throw new IndexOutOfRangeException();
- return new SignatureArrayType(this, rank: rank, isMultiDim: true);
- }
- public sealed override Type MakeByRefType() => new SignatureByRefType(this);
- public sealed override Type MakePointerType() => new SignaturePointerType(this);
- public sealed override Type MakeGenericType(params Type[] typeArguments) => throw new NotSupportedException(SR.NotSupported_SignatureType); // There is no SignatureType for type definition types so it would never be legal to call this.
-
- // Dissectors
- public sealed override Type? GetElementType() => ElementType;
- public abstract override int GetArrayRank();
- public abstract override Type GetGenericTypeDefinition();
- public abstract override Type[] GenericTypeArguments { get; }
- public abstract override Type[] GetGenericArguments();
- public abstract override int GenericParameterPosition { get; }
- internal abstract SignatureType? ElementType { get; }
-
- // Identity
-#if DEBUG
- public sealed override bool Equals(object? o) => base.Equals(o);
- public sealed override bool Equals(Type? o) => base.Equals(o);
- public sealed override int GetHashCode() => base.GetHashCode();
-#endif
- public sealed override Type UnderlyingSystemType => this; // Equals(Type) depends on this.
-
- // Naming and diagnostics
- public abstract override string Name { get; }
- public abstract override string? Namespace { get; }
- public sealed override string? FullName => null;
- public sealed override string? AssemblyQualifiedName => null;
- public abstract override string ToString();
-
- // Not supported on Signature Types
- public sealed override Assembly Assembly => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override Module Module => throw new NotSupportedException(SR.NotSupported_SignatureType);
-
- public sealed override Type ReflectedType => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override Type BaseType => throw new NotSupportedException(SR.NotSupported_SignatureType);
-
- public sealed override Type[] GetInterfaces() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool IsAssignableFrom(Type? c) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override int MetadataToken => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other) => throw new NotSupportedException(SR.NotSupported_SignatureType);
-
- public sealed override Type DeclaringType => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override MethodBase DeclaringMethod => throw new NotSupportedException(SR.NotSupported_SignatureType);
-
- public sealed override Type[] GetGenericParameterConstraints() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override GenericParameterAttributes GenericParameterAttributes => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool IsEnumDefined(object value) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override string GetEnumName(object value) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override string[] GetEnumNames() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override Type GetEnumUnderlyingType() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override Array GetEnumValues() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override Guid GUID => throw new NotSupportedException(SR.NotSupported_SignatureType);
- protected sealed override TypeCode GetTypeCodeImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- protected sealed override TypeAttributes GetAttributeFlagsImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override EventInfo GetEvent(string name, BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override EventInfo[] GetEvents(BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override FieldInfo GetField(string name, BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override FieldInfo[] GetFields(BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override MemberInfo[] GetMembers(BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override MethodInfo[] GetMethods(BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override Type GetNestedType(string name, BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override Type[] GetNestedTypes(BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override PropertyInfo[] GetProperties(BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override object InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- protected sealed override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[]? types, ParameterModifier[]? modifiers) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- protected sealed override MethodInfo GetMethodImpl(string name, int genericParameterCount, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[]? types, ParameterModifier[]? modifiers) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- protected sealed override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bindingAttr, MemberFilter? filter, object? filterCriteria) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override MemberInfo[] GetMember(string name, BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override MemberInfo[] GetDefaultMembers() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override EventInfo[] GetEvents() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override object[] GetCustomAttributes(bool inherit) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override object[] GetCustomAttributes(Type attributeType, bool inherit) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool IsDefined(Type attributeType, bool inherit) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override IList<CustomAttributeData> GetCustomAttributesData() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override Type GetInterface(string name, bool ignoreCase) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- protected sealed override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- protected sealed override bool IsCOMObjectImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- protected sealed override bool IsPrimitiveImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override IEnumerable<CustomAttributeData> CustomAttributes => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override Type[] FindInterfaces(TypeFilter filter, object? filterCriteria) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override InterfaceMapping GetInterfaceMap(Type interfaceType) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- protected sealed override bool IsContextfulImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool IsEnum => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool IsEquivalentTo(Type? other) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool IsInstanceOfType(object? o) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- protected sealed override bool IsMarshalByRefImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool IsSecurityCritical => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool IsSecuritySafeCritical => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool IsSecurityTransparent => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool IsSerializable => throw new NotSupportedException(SR.NotSupported_SignatureType);
- public sealed override bool IsSubclassOf(Type c) => throw new NotSupportedException(SR.NotSupported_SignatureType);
- protected sealed override bool IsValueTypeImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType);
-
- public sealed override StructLayoutAttribute StructLayoutAttribute => throw new NotSupportedException(SR.NotSupported_SignatureType);
-
- public sealed override RuntimeTypeHandle TypeHandle => throw new NotSupportedException(SR.NotSupported_SignatureType);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs
deleted file mode 100644
index c83f25b0e19..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs
+++ /dev/null
@@ -1,224 +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.
-
-namespace System.Reflection
-{
-#if CORERT
- [System.Runtime.CompilerServices.ReflectionBlocked]
- public // Needs to be public so that Reflection.Core can see it.
-#else
- internal
-#endif
- static class SignatureTypeExtensions
- {
- /// <summary>
- /// This is semantically identical to
- ///
- /// parameter.ParameterType == pattern.TryResolveAgainstGenericMethod(parameter.Member)
- ///
- /// but without the allocation overhead of TryResolve.
- /// </summary>
- public static bool MatchesParameterTypeExactly(this Type pattern, ParameterInfo parameter)
- {
- if (pattern is SignatureType signatureType)
- return signatureType.MatchesExactly(parameter.ParameterType);
- else
- return pattern == (object)(parameter.ParameterType);
- }
-
- /// <summary>
- /// This is semantically identical to
- ///
- /// actual == pattern.TryResolveAgainstGenericMethod(parameterMember)
- ///
- /// but without the allocation overhead of TryResolve.
- /// </summary>
- internal static bool MatchesExactly(this SignatureType pattern, Type actual)
- {
- if (pattern.IsSZArray)
- {
- return actual.IsSZArray && pattern.ElementType!.MatchesExactly(actual.GetElementType()!);
- }
- else if (pattern.IsVariableBoundArray)
- {
- return actual.IsVariableBoundArray && pattern.GetArrayRank() == actual.GetArrayRank() && pattern.ElementType!.MatchesExactly(actual.GetElementType()!);
- }
- else if (pattern.IsByRef)
- {
- return actual.IsByRef && pattern.ElementType!.MatchesExactly(actual.GetElementType()!);
- }
- else if (pattern.IsPointer)
- {
- return actual.IsPointer && pattern.ElementType!.MatchesExactly(actual.GetElementType()!);
- }
- else if (pattern.IsConstructedGenericType)
- {
- if (!actual.IsConstructedGenericType)
- return false;
- if (!(pattern.GetGenericTypeDefinition() == actual.GetGenericTypeDefinition()))
- return false;
- Type[] patternGenericTypeArguments = pattern.GenericTypeArguments;
- Type[] actualGenericTypeArguments = actual.GenericTypeArguments;
- int count = patternGenericTypeArguments.Length;
- if (count != actualGenericTypeArguments.Length)
- return false;
- for (int i = 0; i < count; i++)
- {
- Type patternGenericTypeArgument = patternGenericTypeArguments[i];
- if (patternGenericTypeArgument is SignatureType signatureType)
- {
- if (!signatureType.MatchesExactly(actualGenericTypeArguments[i]))
- return false;
- }
- else
- {
- if (patternGenericTypeArgument != actualGenericTypeArguments[i])
- return false;
- }
- }
- return true;
- }
- else if (pattern.IsGenericMethodParameter)
- {
- if (!actual.IsGenericMethodParameter)
- return false;
- if (pattern.GenericParameterPosition != actual.GenericParameterPosition)
- return false;
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /// <summary>
- /// Translates a SignatureType into its equivalent resolved Type by recursively substituting all generic parameter references
- /// with its corresponding generic parameter definition. This is slow so MatchesExactly or MatchesParameterTypeExactly should be
- /// substituted instead whenever possible. This is only used by the DefaultBinder when its fast-path checks have been exhausted and
- /// it needs to call non-trivial methods like IsAssignableFrom which SignatureTypes will never support.
- ///
- /// Because this method is used to eliminate method candidates in a GetMethod() lookup, it is entirely possible that the Type
- /// might not be creatable due to conflicting generic constraints. Since this merely implies that this candidate is not
- /// the method we're looking for, we return null rather than let the TypeLoadException bubble up. The DefaultBinder will catch
- /// the null and continue its search for a better candidate.
- /// </summary>
- internal static Type? TryResolveAgainstGenericMethod(this SignatureType signatureType, MethodInfo genericMethod)
- {
- return signatureType.TryResolve(genericMethod.GetGenericArguments());
- }
-
- private static Type? TryResolve(this SignatureType signatureType, Type[] genericMethodParameters)
- {
- if (signatureType.IsSZArray)
- {
- return signatureType.ElementType!.TryResolve(genericMethodParameters)?.TryMakeArrayType();
- }
- else if (signatureType.IsVariableBoundArray)
- {
- return signatureType.ElementType!.TryResolve(genericMethodParameters)?.TryMakeArrayType(signatureType.GetArrayRank());
- }
- else if (signatureType.IsByRef)
- {
- return signatureType.ElementType!.TryResolve(genericMethodParameters)?.TryMakeByRefType();
- }
- else if (signatureType.IsPointer)
- {
- return signatureType.ElementType!.TryResolve(genericMethodParameters)?.TryMakePointerType();
- }
- else if (signatureType.IsConstructedGenericType)
- {
- Type[] genericTypeArguments = signatureType.GenericTypeArguments;
- int count = genericTypeArguments.Length;
- Type?[] newGenericTypeArguments = new Type[count];
- for (int i = 0; i < count; i++)
- {
- Type genericTypeArgument = genericTypeArguments[i];
- if (genericTypeArgument is SignatureType signatureGenericTypeArgument)
- {
- newGenericTypeArguments[i] = signatureGenericTypeArgument.TryResolve(genericMethodParameters);
- if (newGenericTypeArguments[i] == null)
- return null;
- }
- else
- {
- newGenericTypeArguments[i] = genericTypeArgument;
- }
- }
- return signatureType.GetGenericTypeDefinition().TryMakeGenericType(newGenericTypeArguments!);
- }
- else if (signatureType.IsGenericMethodParameter)
- {
- int position = signatureType.GenericParameterPosition;
- if (position >= genericMethodParameters.Length)
- return null;
- return genericMethodParameters[position];
- }
- else
- {
- return null;
- }
- }
-
- private static Type? TryMakeArrayType(this Type type)
- {
- try
- {
- return type.MakeArrayType();
- }
- catch
- {
- return null;
- }
- }
-
- private static Type? TryMakeArrayType(this Type type, int rank)
- {
- try
- {
- return type.MakeArrayType(rank);
- }
- catch
- {
- return null;
- }
- }
-
- private static Type? TryMakeByRefType(this Type type)
- {
- try
- {
- return type.MakeByRefType();
- }
- catch
- {
- return null;
- }
- }
-
- private static Type? TryMakePointerType(this Type type)
- {
- try
- {
- return type.MakePointerType();
- }
- catch
- {
- return null;
- }
- }
-
- private static Type? TryMakeGenericType(this Type type, Type[] instantiation)
- {
- try
- {
- return type.MakeGenericType(instantiation);
- }
- catch
- {
- return null;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/StrongNameKeyPair.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/StrongNameKeyPair.cs
deleted file mode 100644
index 03e7f121a80..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/StrongNameKeyPair.cs
+++ /dev/null
@@ -1,45 +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 System.IO;
-using System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- public class StrongNameKeyPair : IDeserializationCallback, ISerializable
- {
- // Build key pair from file.
- public StrongNameKeyPair(FileStream keyPairFile)
- {
- if (keyPairFile == null)
- throw new ArgumentNullException(nameof(keyPairFile));
-
- int length = (int)keyPairFile.Length;
- byte[] keyPairArray = new byte[length];
- keyPairFile.Read(keyPairArray, 0, length);
- }
-
- // Build key pair from byte array in memory.
- public StrongNameKeyPair(byte[] keyPairArray)
- {
- if (keyPairArray == null)
- throw new ArgumentNullException(nameof(keyPairArray));
- }
-
- protected StrongNameKeyPair(SerializationInfo info, StreamingContext context) =>
- throw new PlatformNotSupportedException();
-
- public StrongNameKeyPair(string keyPairContainer) =>
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning);
-
- public byte[] PublicKey =>
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_StrongNameSigning);
-
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) =>
- throw new PlatformNotSupportedException();
-
- void IDeserializationCallback.OnDeserialization(object? sender) =>
- throw new PlatformNotSupportedException();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/TargetException.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/TargetException.cs
deleted file mode 100644
index 45d36648ca1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/TargetException.cs
+++ /dev/null
@@ -1,34 +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 System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class TargetException : ApplicationException
- {
- public TargetException()
- : this(null)
- {
- }
-
- public TargetException(string? message)
- : this(message, null)
- {
- }
-
- public TargetException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_TARGET;
- }
-
- protected TargetException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/TargetInvocationException.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/TargetInvocationException.cs
deleted file mode 100644
index d529e649927..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/TargetInvocationException.cs
+++ /dev/null
@@ -1,30 +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 System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class TargetInvocationException : ApplicationException
- {
- public TargetInvocationException(Exception? inner)
- : base(SR.Arg_TargetInvocationException, inner)
- {
- HResult = HResults.COR_E_TARGETINVOCATION;
- }
-
- public TargetInvocationException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_TARGETINVOCATION;
- }
-
- private TargetInvocationException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/TargetParameterCountException.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/TargetParameterCountException.cs
deleted file mode 100644
index 888068da7c9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/TargetParameterCountException.cs
+++ /dev/null
@@ -1,36 +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 System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class TargetParameterCountException : ApplicationException
- {
- public TargetParameterCountException()
- : base(SR.Arg_TargetParameterCountException)
- {
- HResult = HResults.COR_E_TARGETPARAMCOUNT;
- }
-
- public TargetParameterCountException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_TARGETPARAMCOUNT;
- }
-
- public TargetParameterCountException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_TARGETPARAMCOUNT;
- }
-
- private TargetParameterCountException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/TypeAttributes.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/TypeAttributes.cs
deleted file mode 100644
index 3ae314299e8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/TypeAttributes.cs
+++ /dev/null
@@ -1,61 +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.
-
-namespace System.Reflection
-{
- // This Enum matchs the CorTypeAttr defined in CorHdr.h
- [Flags]
- public enum TypeAttributes
- {
- VisibilityMask = 0x00000007,
- NotPublic = 0x00000000, // Class is not public scope.
- Public = 0x00000001, // Class is public scope.
- NestedPublic = 0x00000002, // Class is nested with public visibility.
- NestedPrivate = 0x00000003, // Class is nested with private visibility.
- NestedFamily = 0x00000004, // Class is nested with family visibility.
- NestedAssembly = 0x00000005, // Class is nested with assembly visibility.
- NestedFamANDAssem = 0x00000006, // Class is nested with family and assembly visibility.
- NestedFamORAssem = 0x00000007, // Class is nested with family or assembly visibility.
-
- // Use this mask to retrieve class layout informaiton
- // 0 is AutoLayout, 0x2 is SequentialLayout, 4 is ExplicitLayout
- LayoutMask = 0x00000018,
- AutoLayout = 0x00000000, // Class fields are auto-laid out
- SequentialLayout = 0x00000008, // Class fields are laid out sequentially
- ExplicitLayout = 0x00000010, // Layout is supplied explicitly
- // end layout mask
-
- // Use this mask to distinguish whether a type declaration is an interface. (Class vs. ValueType done based on whether it subclasses S.ValueType)
- ClassSemanticsMask = 0x00000020,
- Class = 0x00000000, // Type is a class (or a value type).
- Interface = 0x00000020, // Type is an interface.
-
- // Special semantics in addition to class semantics.
- Abstract = 0x00000080, // Class is abstract
- Sealed = 0x00000100, // Class is concrete and may not be extended
- SpecialName = 0x00000400, // Class name is special. Name describes how.
-
- // Implementation attributes.
- Import = 0x00001000, // Class / interface is imported
- Serializable = 0x00002000, // The class is Serializable.
- WindowsRuntime = 0x00004000, // Type is a Windows Runtime type.
-
- // Use tdStringFormatMask to retrieve string information for native interop
- StringFormatMask = 0x00030000,
- AnsiClass = 0x00000000, // LPTSTR is interpreted as ANSI in this class
- UnicodeClass = 0x00010000, // LPTSTR is interpreted as UNICODE
- AutoClass = 0x00020000, // LPTSTR is interpreted automatically
- CustomFormatClass = 0x00030000, // A non-standard encoding specified by CustomFormatMask
- CustomFormatMask = 0x00C00000, // Use this mask to retrieve non-standard encoding information for native interop. The meaning of the values of these 2 bits is unspecified.
-
- // end string format mask
-
- BeforeFieldInit = 0x00100000, // Initialize the class any time before first static field access.
-
- RTSpecialName = 0x00000800, // Runtime should check name encoding.
- HasSecurity = 0x00040000, // Class has security associate with it.
-
- ReservedMask = 0x00040800,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs
deleted file mode 100644
index d0d32dcca97..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs
+++ /dev/null
@@ -1,131 +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.
-
-// TypeDelegator
-//
-// This class wraps a Type object and delegates all methods to that Type.
-
-using CultureInfo = System.Globalization.CultureInfo;
-
-namespace System.Reflection
-{
- public class TypeDelegator : TypeInfo
- {
- public override bool IsAssignableFrom(TypeInfo? typeInfo)
- {
- if (typeInfo == null)
- return false;
- return IsAssignableFrom(typeInfo.AsType());
- }
-
- protected Type typeImpl = null!;
-
- protected TypeDelegator() { }
-
- public TypeDelegator(Type delegatingType)
- {
- if (delegatingType is null)
- throw new ArgumentNullException(nameof(delegatingType));
-
- typeImpl = delegatingType;
- }
-
- public override Guid GUID => typeImpl.GUID;
- public override int MetadataToken => typeImpl.MetadataToken;
-
- public override object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target,
- object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters)
- {
- return typeImpl.InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters);
- }
-
- public override Module Module => typeImpl.Module;
- public override Assembly Assembly => typeImpl.Assembly;
- public override RuntimeTypeHandle TypeHandle => typeImpl.TypeHandle;
- public override string Name => typeImpl.Name;
- public override string? FullName => typeImpl.FullName;
- public override string? Namespace => typeImpl.Namespace;
- public override string? AssemblyQualifiedName => typeImpl.AssemblyQualifiedName;
- public override Type? BaseType => typeImpl.BaseType;
-
- protected override ConstructorInfo? GetConstructorImpl(BindingFlags bindingAttr, Binder? binder,
- CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers)
- {
- return typeImpl.GetConstructor(bindingAttr, binder, callConvention, types, modifiers);
- }
-
- public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) => typeImpl.GetConstructors(bindingAttr);
-
- protected override MethodInfo? GetMethodImpl(string name, BindingFlags bindingAttr, Binder? binder,
- CallingConventions callConvention, Type[]? types, ParameterModifier[]? modifiers)
- {
- // This is interesting there are two paths into the impl. One that validates
- // type as non-null and one where type may be null.
- if (types == null)
- return typeImpl.GetMethod(name, bindingAttr);
- else
- return typeImpl.GetMethod(name, bindingAttr, binder, callConvention, types, modifiers);
- }
-
- public override MethodInfo[] GetMethods(BindingFlags bindingAttr) => typeImpl.GetMethods(bindingAttr);
-
- public override FieldInfo? GetField(string name, BindingFlags bindingAttr) => typeImpl.GetField(name, bindingAttr);
- public override FieldInfo[] GetFields(BindingFlags bindingAttr) => typeImpl.GetFields(bindingAttr);
-
- public override Type? GetInterface(string name, bool ignoreCase) => typeImpl.GetInterface(name, ignoreCase);
-
- public override Type[] GetInterfaces() => typeImpl.GetInterfaces();
-
- public override EventInfo? GetEvent(string name, BindingFlags bindingAttr) => typeImpl.GetEvent(name, bindingAttr);
-
- public override EventInfo[] GetEvents() => typeImpl.GetEvents();
-
- protected override PropertyInfo? GetPropertyImpl(string name, BindingFlags bindingAttr, Binder? binder,
- Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
- {
- if (returnType == null && types == null)
- return typeImpl.GetProperty(name, bindingAttr);
- else
- return typeImpl.GetProperty(name, bindingAttr, binder, returnType, types!, modifiers);
- }
-
- public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) => typeImpl.GetProperties(bindingAttr);
- public override EventInfo[] GetEvents(BindingFlags bindingAttr) => typeImpl.GetEvents(bindingAttr);
- public override Type[] GetNestedTypes(BindingFlags bindingAttr) => typeImpl.GetNestedTypes(bindingAttr);
- public override Type? GetNestedType(string name, BindingFlags bindingAttr) => typeImpl.GetNestedType(name, bindingAttr);
- public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr) => typeImpl.GetMember(name, type, bindingAttr);
- public override MemberInfo[] GetMembers(BindingFlags bindingAttr) => typeImpl.GetMembers(bindingAttr);
-
- protected override TypeAttributes GetAttributeFlagsImpl() => typeImpl.Attributes;
-
- public override bool IsTypeDefinition => typeImpl.IsTypeDefinition;
- public override bool IsSZArray => typeImpl.IsSZArray;
- public override bool IsVariableBoundArray => typeImpl.IsVariableBoundArray;
-
- protected override bool IsArrayImpl() => typeImpl.IsArray;
- protected override bool IsPrimitiveImpl() => typeImpl.IsPrimitive;
- protected override bool IsByRefImpl() => typeImpl.IsByRef;
- public override bool IsGenericTypeParameter => typeImpl.IsGenericTypeParameter;
- public override bool IsGenericMethodParameter => typeImpl.IsGenericMethodParameter;
- protected override bool IsPointerImpl() => typeImpl.IsPointer;
- protected override bool IsValueTypeImpl() => typeImpl.IsValueType;
- protected override bool IsCOMObjectImpl() => typeImpl.IsCOMObject;
- public override bool IsByRefLike => typeImpl.IsByRefLike;
- public override bool IsConstructedGenericType => typeImpl.IsConstructedGenericType;
-
- public override bool IsCollectible => typeImpl.IsCollectible;
-
- public override Type? GetElementType() => typeImpl.GetElementType();
- protected override bool HasElementTypeImpl() => typeImpl.HasElementType;
-
- public override Type UnderlyingSystemType => typeImpl.UnderlyingSystemType;
-
- // ICustomAttributeProvider
- public override object[] GetCustomAttributes(bool inherit) => typeImpl.GetCustomAttributes(inherit);
- public override object[] GetCustomAttributes(Type attributeType, bool inherit) => typeImpl.GetCustomAttributes(attributeType, inherit);
-
- public override bool IsDefined(Type attributeType, bool inherit) => typeImpl.IsDefined(attributeType, inherit);
- public override InterfaceMapping GetInterfaceMap(Type interfaceType) => typeImpl.GetInterfaceMap(interfaceType);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/TypeFilter.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/TypeFilter.cs
deleted file mode 100644
index befa09ac32f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/TypeFilter.cs
+++ /dev/null
@@ -1,8 +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.
-
-namespace System.Reflection
-{
- public delegate bool TypeFilter(Type m, object? filterCriteria);
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/TypeInfo.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/TypeInfo.cs
deleted file mode 100644
index eca9213e9e4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Reflection/TypeInfo.cs
+++ /dev/null
@@ -1,94 +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 System.Collections.Generic;
-
-namespace System.Reflection
-{
- public abstract partial class TypeInfo : Type, IReflectableType
- {
- protected TypeInfo() { }
-
- TypeInfo IReflectableType.GetTypeInfo() => this;
- public virtual Type AsType() => this;
-
- public virtual Type[] GenericTypeParameters => IsGenericTypeDefinition ? GetGenericArguments() : Type.EmptyTypes;
-
- public virtual EventInfo? GetDeclaredEvent(string name) => GetEvent(name, TypeInfo.DeclaredOnlyLookup);
- public virtual FieldInfo? GetDeclaredField(string name) => GetField(name, TypeInfo.DeclaredOnlyLookup);
- public virtual MethodInfo? GetDeclaredMethod(string name) => GetMethod(name, TypeInfo.DeclaredOnlyLookup);
- public virtual TypeInfo? GetDeclaredNestedType(string name) => GetNestedType(name, TypeInfo.DeclaredOnlyLookup)?.GetTypeInfo();
- public virtual PropertyInfo? GetDeclaredProperty(string name) => GetProperty(name, TypeInfo.DeclaredOnlyLookup);
-
- public virtual IEnumerable<MethodInfo> GetDeclaredMethods(string name)
- {
- foreach (MethodInfo method in GetMethods(TypeInfo.DeclaredOnlyLookup))
- {
- if (method.Name == name)
- yield return method;
- }
- }
-
- public virtual IEnumerable<ConstructorInfo> DeclaredConstructors => GetConstructors(TypeInfo.DeclaredOnlyLookup);
- public virtual IEnumerable<EventInfo> DeclaredEvents => GetEvents(TypeInfo.DeclaredOnlyLookup);
- public virtual IEnumerable<FieldInfo> DeclaredFields => GetFields(TypeInfo.DeclaredOnlyLookup);
- public virtual IEnumerable<MemberInfo> DeclaredMembers => GetMembers(TypeInfo.DeclaredOnlyLookup);
- public virtual IEnumerable<MethodInfo> DeclaredMethods => GetMethods(TypeInfo.DeclaredOnlyLookup);
- public virtual IEnumerable<System.Reflection.TypeInfo> DeclaredNestedTypes
- {
- get
- {
- foreach (Type t in GetNestedTypes(TypeInfo.DeclaredOnlyLookup))
- {
- yield return t.GetTypeInfo();
- }
- }
- }
- public virtual IEnumerable<PropertyInfo> DeclaredProperties => GetProperties(TypeInfo.DeclaredOnlyLookup);
-
- public virtual IEnumerable<Type> ImplementedInterfaces => GetInterfaces();
-
- // a re-implementation of ISAF from Type, skipping the use of UnderlyingType
- public virtual bool IsAssignableFrom(TypeInfo? typeInfo)
- {
- if (typeInfo == null)
- return false;
-
- if (this == typeInfo)
- return true;
-
- // If c is a subclass of this class, then c can be cast to this type.
- if (typeInfo.IsSubclassOf(this))
- return true;
-
- if (this.IsInterface)
- {
- return typeInfo.ImplementInterface(this);
- }
- else if (IsGenericParameter)
- {
- Type[] constraints = GetGenericParameterConstraints();
- for (int i = 0; i < constraints.Length; i++)
- if (!constraints[i].IsAssignableFrom(typeInfo))
- return false;
-
- return true;
- }
-
- return false;
- }
-
- internal static string GetRankString(int rank)
- {
- if (rank <= 0)
- throw new IndexOutOfRangeException();
-
- return rank == 1 ?
- "[*]" :
- "[" + new string(',', rank - 1) + "]";
- }
-
- private const BindingFlags DeclaredOnlyLookup = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ResolveEventArgs.cs b/netcore/System.Private.CoreLib/shared/System/ResolveEventArgs.cs
deleted file mode 100644
index d9c1d4a766a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ResolveEventArgs.cs
+++ /dev/null
@@ -1,25 +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 System.Reflection;
-
-namespace System
-{
- public class ResolveEventArgs : EventArgs
- {
- public ResolveEventArgs(string name)
- {
- Name = name;
- }
-
- public ResolveEventArgs(string name, Assembly? requestingAssembly)
- {
- Name = name;
- RequestingAssembly = requestingAssembly;
- }
-
- public string Name { get; }
- public Assembly? RequestingAssembly { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ResolveEventHandler.cs b/netcore/System.Private.CoreLib/shared/System/ResolveEventHandler.cs
deleted file mode 100644
index a08be720c48..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ResolveEventHandler.cs
+++ /dev/null
@@ -1,10 +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 System.Reflection;
-
-namespace System
-{
- public delegate Assembly? ResolveEventHandler(object? sender, ResolveEventArgs args);
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/FastResourceComparer.cs b/netcore/System.Private.CoreLib/shared/System/Resources/FastResourceComparer.cs
deleted file mode 100644
index b117fba15ff..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/FastResourceComparer.cs
+++ /dev/null
@@ -1,142 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: A collection of quick methods for comparing
-** resource keys (strings)
-**
-**
-===========================================================*/
-
-#nullable enable
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Resources
-{
- internal sealed class FastResourceComparer : IComparer, IEqualityComparer, IComparer<string?>, IEqualityComparer<string?>
- {
- internal static readonly FastResourceComparer Default = new FastResourceComparer();
-
- // Implements IHashCodeProvider too, due to Hashtable requirements.
- public int GetHashCode(object key)
- {
- string s = (string)key;
- return FastResourceComparer.HashFunction(s);
- }
-
- public int GetHashCode([DisallowNull] string? key)
- {
- return FastResourceComparer.HashFunction(key!);
- }
-
- // This hash function MUST be publically documented with the resource
- // file format, AND we may NEVER change this hash function's return
- // value (without changing the file format).
- internal static int HashFunction(string key)
- {
- // Never change this hash function. We must standardize it so that
- // others can read & write our .resources files. Additionally, we
- // have a copy of it in InternalResGen as well.
- uint hash = 5381;
- for (int i = 0; i < key.Length; i++)
- hash = ((hash << 5) + hash) ^ key[i];
- return (int)hash;
- }
-
- // Compares Strings quickly in a case-sensitive way
- public int Compare(object? a, object? b)
- {
- if (a == b) return 0;
- string? sa = (string?)a;
- string? sb = (string?)b;
- return string.CompareOrdinal(sa, sb);
- }
-
- public int Compare(string? a, string? b)
- {
- return string.CompareOrdinal(a, b);
- }
-
- public bool Equals(string? a, string? b)
- {
- return string.Equals(a, b);
- }
-
- public new bool Equals(object? a, object? b)
- {
- if (a == b) return true;
- string? sa = (string?)a;
- string? sb = (string?)b;
- return string.Equals(sa, sb);
- }
-
- // Input is one string to compare with, and a byte[] containing chars in
- // little endian unicode. Pass in the number of valid chars.
- public static unsafe int CompareOrdinal(string a, byte[] bytes, int bCharLength)
- {
- Debug.Assert(a != null && bytes != null, "FastResourceComparer::CompareOrdinal must have non-null params");
- Debug.Assert(bCharLength * 2 <= bytes.Length, "FastResourceComparer::CompareOrdinal - numChars is too big!");
- // This is a managed version of strcmp, but I can't take advantage
- // of a terminating 0, unlike strcmp in C.
- int i = 0;
- int r = 0;
- // Compare the min length # of characters, then return length diffs.
- int numChars = a.Length;
- if (numChars > bCharLength)
- numChars = bCharLength;
- if (bCharLength == 0) // Can't use fixed on a 0-element array.
- return (a.Length == 0) ? 0 : -1;
- fixed (byte* pb = bytes)
- {
- byte* pChar = pb;
- while (i < numChars && r == 0)
- {
- // little endian format
- int b = pChar[0] | pChar[1] << 8;
- r = a[i++] - b;
- pChar += sizeof(char);
- }
- }
- if (r != 0) return r;
- return a.Length - bCharLength;
- }
-
- public static int CompareOrdinal(byte[] bytes, int aCharLength, string b)
- {
- return -CompareOrdinal(b, bytes, aCharLength);
- }
-
- // This method is to handle potentially misaligned data accesses.
- // The byte* must point to little endian Unicode characters.
- internal static unsafe int CompareOrdinal(byte* a, int byteLen, string b)
- {
- Debug.Assert((byteLen & 1) == 0, "CompareOrdinal is expecting a UTF-16 string length, which must be even!");
- Debug.Assert(a != null && b != null, "Null args not allowed.");
- Debug.Assert(byteLen >= 0, "byteLen must be non-negative.");
-
- int r = 0;
- int i = 0;
- // Compare the min length # of characters, then return length diffs.
- int numChars = byteLen >> 1;
- if (numChars > b.Length)
- numChars = b.Length;
- while (i < numChars && r == 0)
- {
- // Must compare character by character, not byte by byte.
- char aCh = (char)(*a++ | (*a++ << 8));
- r = aCh - b[i++];
- }
- if (r != 0) return r;
- return byteLen - b.Length * 2;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/FileBasedResourceGroveler.cs b/netcore/System.Private.CoreLib/shared/System/Resources/FileBasedResourceGroveler.cs
deleted file mode 100644
index 27af1ffae66..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/FileBasedResourceGroveler.cs
+++ /dev/null
@@ -1,121 +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.
-
-/*============================================================
-**
-**
-** Purpose: Searches for resources on disk, used for file-
-** based resource lookup.
-**
-**
-===========================================================*/
-
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-
-using Internal.IO;
-
-namespace System.Resources
-{
- internal class FileBasedResourceGroveler : IResourceGroveler
- {
- private readonly ResourceManager.ResourceManagerMediator _mediator;
-
- public FileBasedResourceGroveler(ResourceManager.ResourceManagerMediator mediator)
- {
- Debug.Assert(mediator != null, "mediator shouldn't be null; check caller");
- _mediator = mediator;
- }
-
- // Consider modifying IResourceGroveler interface (hence this method signature) when we figure out
- // serialization compat story for moving ResourceManager members to either file-based or
- // manifest-based classes. Want to continue tightening the design to get rid of unused params.
- public ResourceSet? GrovelForResourceSet(CultureInfo culture, Dictionary<string, ResourceSet> localResourceSets, bool tryParents, bool createIfNotExists)
- {
- Debug.Assert(culture != null, "culture shouldn't be null; check caller");
-
- string? fileName = null;
- ResourceSet? rs = null;
-
- // Don't use Assembly manifest, but grovel on disk for a file.
- // Create new ResourceSet, if a file exists on disk for it.
- string tempFileName = _mediator.GetResourceFileName(culture);
- fileName = FindResourceFile(culture, tempFileName);
- if (fileName == null)
- {
- if (tryParents)
- {
- // If we've hit top of the Culture tree, return.
- if (culture.HasInvariantCultureName)
- {
- // We really don't think this should happen - we always
- // expect the neutral locale's resources to be present.
- throw new MissingManifestResourceException(SR.MissingManifestResource_NoNeutralDisk + Environment.NewLineConst + "baseName: " + _mediator.BaseNameField + " locationInfo: " + (_mediator.LocationInfo == null ? "<null>" : _mediator.LocationInfo.FullName) + " fileName: " + _mediator.GetResourceFileName(culture));
- }
- }
- }
- else
- {
- rs = CreateResourceSet(fileName);
- }
- return rs;
- }
-
- // Given a CultureInfo, it generates the path &; file name for
- // the .resources file for that CultureInfo. This method will grovel
- // the disk looking for the correct file name & path. Uses CultureInfo's
- // Name property. If the module directory was set in the ResourceManager
- // constructor, we'll look there first. If it couldn't be found in the module
- // diretory or the module dir wasn't provided, look in the current
- // directory.
- private string? FindResourceFile(CultureInfo culture, string fileName)
- {
- Debug.Assert(culture != null, "culture shouldn't be null; check caller");
- Debug.Assert(fileName != null, "fileName shouldn't be null; check caller");
-
- // If we have a moduleDir, check there first. Get module fully
- // qualified name, append path to that.
- if (_mediator.ModuleDir != null)
- {
- string path = Path.Combine(_mediator.ModuleDir, fileName);
- if (File.Exists(path))
- {
- return path;
- }
- }
-
- // look in .
- if (File.Exists(fileName))
- return fileName;
-
- return null; // give up.
- }
-
- // Constructs a new ResourceSet for a given file name.
- private ResourceSet CreateResourceSet(string file)
- {
- Debug.Assert(file != null, "file shouldn't be null; check caller");
-
- if (_mediator.UserResourceSet == null)
- {
- return new RuntimeResourceSet(file);
- }
- else
- {
- object[] args = new object[1];
- args[0] = file;
- try
- {
- return (ResourceSet)Activator.CreateInstance(_mediator.UserResourceSet, args)!;
- }
- catch (MissingMethodException e)
- {
- throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ResMgrBadResSet_Type, _mediator.UserResourceSet.AssemblyQualifiedName), e);
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/IResourceGroveler.cs b/netcore/System.Private.CoreLib/shared/System/Resources/IResourceGroveler.cs
deleted file mode 100644
index c8090aae365..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/IResourceGroveler.cs
+++ /dev/null
@@ -1,26 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: Interface for resource grovelers
-**
-**
-===========================================================*/
-
-using System.Globalization;
-using System.Collections.Generic;
-
-namespace System.Resources
-{
- internal interface IResourceGroveler
- {
- ResourceSet? GrovelForResourceSet(CultureInfo culture, Dictionary<string, ResourceSet> localResourceSets, bool tryParents,
- bool createIfNotExists);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/IResourceReader.cs b/netcore/System.Private.CoreLib/shared/System/Resources/IResourceReader.cs
deleted file mode 100644
index e45605a8305..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/IResourceReader.cs
+++ /dev/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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: Abstraction to read streams of resources.
-**
-**
-===========================================================*/
-
-using System.Collections;
-
-namespace System.Resources
-{
- public interface IResourceReader : IEnumerable, IDisposable
- {
- // Interface does not need to be marked with the serializable attribute
- // Closes the ResourceReader, releasing any resources associated with it.
- // This could close a network connection, a file, or do nothing.
- void Close();
-
- new IDictionaryEnumerator GetEnumerator();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs b/netcore/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs
deleted file mode 100644
index 982d5007cf3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/ManifestBasedResourceGroveler.cs
+++ /dev/null
@@ -1,501 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: Searches for resources in Assembly manifest, used
-** for assembly-based resource lookup.
-**
-**
-===========================================================*/
-
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Reflection;
-using System.Text;
-using System.Diagnostics;
-
-namespace System.Resources
-{
- //
- // Note: this type is integral to the construction of exception objects,
- // and sometimes this has to be done in low memory situtations (OOM) or
- // to create TypeInitializationExceptions due to failure of a static class
- // constructor. This type needs to be extremely careful and assume that
- // any type it references may have previously failed to construct, so statics
- // belonging to that type may not be initialized. FrameworkEventSource.Log
- // is one such example.
- //
- internal partial class ManifestBasedResourceGroveler : IResourceGroveler
- {
- private readonly ResourceManager.ResourceManagerMediator _mediator;
-
- public ManifestBasedResourceGroveler(ResourceManager.ResourceManagerMediator mediator)
- {
- // here and below: convert asserts to preconditions where appropriate when we get
- // contracts story in place.
- Debug.Assert(mediator != null, "mediator shouldn't be null; check caller");
- _mediator = mediator;
- }
-
- public ResourceSet? GrovelForResourceSet(CultureInfo culture, Dictionary<string, ResourceSet> localResourceSets, bool tryParents, bool createIfNotExists)
- {
- Debug.Assert(culture != null, "culture shouldn't be null; check caller");
- Debug.Assert(localResourceSets != null, "localResourceSets shouldn't be null; check caller");
-
- ResourceSet? rs = null;
- Stream? stream = null;
- Assembly? satellite;
-
- // 1. Fixups for ultimate fallbacks
- CultureInfo lookForCulture = UltimateFallbackFixup(culture);
-
- // 2. Look for satellite assembly or main assembly, as appropriate
- if (lookForCulture.HasInvariantCultureName && _mediator.FallbackLoc == UltimateResourceFallbackLocation.MainAssembly)
- {
- // don't bother looking in satellites in this case
- satellite = _mediator.MainAssembly;
- }
- else
- {
- satellite = GetSatelliteAssembly(lookForCulture);
-
- if (satellite == null)
- {
- bool raiseException = (culture.HasInvariantCultureName && (_mediator.FallbackLoc == UltimateResourceFallbackLocation.Satellite));
- // didn't find satellite, give error if necessary
- if (raiseException)
- {
- HandleSatelliteMissing();
- }
- }
- }
-
- // get resource file name we'll search for. Note, be careful if you're moving this statement
- // around because lookForCulture may be modified from originally requested culture above.
- string fileName = _mediator.GetResourceFileName(lookForCulture);
-
- // 3. If we identified an assembly to search; look in manifest resource stream for resource file
- if (satellite != null)
- {
- // Handle case in here where someone added a callback for assembly load events.
- // While no other threads have called into GetResourceSet, our own thread can!
- // At that point, we could already have an RS in our hash table, and we don't
- // want to add it twice.
- lock (localResourceSets)
- {
- localResourceSets.TryGetValue(culture.Name, out rs);
- }
-
- stream = GetManifestResourceStream(satellite, fileName);
- }
-
- // 4a. Found a stream; create a ResourceSet if possible
- if (createIfNotExists && stream != null && rs == null)
- {
- Debug.Assert(satellite != null, "satellite should not be null when stream is set");
- rs = CreateResourceSet(stream, satellite);
- }
- else if (stream == null && tryParents)
- {
- // 4b. Didn't find stream; give error if necessary
- bool raiseException = culture.HasInvariantCultureName;
- if (raiseException)
- {
- HandleResourceStreamMissing(fileName);
- }
- }
-
- return rs;
- }
-
- private CultureInfo UltimateFallbackFixup(CultureInfo lookForCulture)
- {
- CultureInfo returnCulture = lookForCulture;
-
- // If our neutral resources were written in this culture AND we know the main assembly
- // does NOT contain neutral resources, don't probe for this satellite.
- Debug.Assert(_mediator.NeutralResourcesCulture != null);
- if (lookForCulture.Name == _mediator.NeutralResourcesCulture.Name &&
- _mediator.FallbackLoc == UltimateResourceFallbackLocation.MainAssembly)
- {
- returnCulture = CultureInfo.InvariantCulture;
- }
- else if (lookForCulture.HasInvariantCultureName && _mediator.FallbackLoc == UltimateResourceFallbackLocation.Satellite)
- {
- returnCulture = _mediator.NeutralResourcesCulture;
- }
-
- return returnCulture;
- }
-
- internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, out UltimateResourceFallbackLocation fallbackLocation)
- {
- Debug.Assert(a != null, "assembly != null");
-
- NeutralResourcesLanguageAttribute? attr = a.GetCustomAttribute<NeutralResourcesLanguageAttribute>();
- if (attr == null)
- {
- fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
- return CultureInfo.InvariantCulture;
- }
-
- fallbackLocation = attr.Location;
- if (fallbackLocation < UltimateResourceFallbackLocation.MainAssembly || fallbackLocation > UltimateResourceFallbackLocation.Satellite)
- {
- throw new ArgumentException(SR.Format(SR.Arg_InvalidNeutralResourcesLanguage_FallbackLoc, fallbackLocation));
- }
-
- try
- {
- return CultureInfo.GetCultureInfo(attr.CultureName);
- }
- catch (ArgumentException e)
- { // we should catch ArgumentException only.
- // Note we could go into infinite loops if mscorlib's
- // NeutralResourcesLanguageAttribute is mangled. If this assert
- // fires, please fix the build process for the BCL directory.
- if (a == typeof(object).Assembly)
- {
- Debug.Fail(System.CoreLib.Name + "'s NeutralResourcesLanguageAttribute is a malformed culture name! name: \"" + attr.CultureName + "\" Exception: " + e);
- return CultureInfo.InvariantCulture;
- }
-
- throw new ArgumentException(SR.Format(SR.Arg_InvalidNeutralResourcesLanguage_Asm_Culture, a, attr.CultureName), e);
- }
- }
-
- // Constructs a new ResourceSet for a given file name.
- // Use the assembly to resolve assembly manifest resource references.
- // Note that is can be null, but probably shouldn't be.
- // This method could use some refactoring. One thing at a time.
- internal ResourceSet CreateResourceSet(Stream store, Assembly assembly)
- {
- Debug.Assert(store != null, "I need a Stream!");
- // Check to see if this is a Stream the ResourceManager understands,
- // and check for the correct resource reader type.
- if (store.CanSeek && store.Length > 4)
- {
- long startPos = store.Position;
-
- // not disposing because we want to leave stream open
- BinaryReader br = new BinaryReader(store);
-
- // Look for our magic number as a little endian int.
- int bytes = br.ReadInt32();
- if (bytes == ResourceManager.MagicNumber)
- {
- int resMgrHeaderVersion = br.ReadInt32();
- string? readerTypeName = null, resSetTypeName = null;
- if (resMgrHeaderVersion == ResourceManager.HeaderVersionNumber)
- {
- br.ReadInt32(); // We don't want the number of bytes to skip.
- readerTypeName = br.ReadString();
- resSetTypeName = br.ReadString();
- }
- else if (resMgrHeaderVersion > ResourceManager.HeaderVersionNumber)
- {
- // Assume that the future ResourceManager headers will
- // have two strings for us - the reader type name and
- // resource set type name. Read those, then use the num
- // bytes to skip field to correct our position.
- int numBytesToSkip = br.ReadInt32();
- long endPosition = br.BaseStream.Position + numBytesToSkip;
-
- readerTypeName = br.ReadString();
- resSetTypeName = br.ReadString();
-
- br.BaseStream.Seek(endPosition, SeekOrigin.Begin);
- }
- else
- {
- // resMgrHeaderVersion is older than this ResMgr version.
- // We should add in backwards compatibility support here.
- Debug.Assert(_mediator.MainAssembly != null);
- throw new NotSupportedException(SR.Format(SR.NotSupported_ObsoleteResourcesFile, _mediator.MainAssembly.GetName().Name));
- }
-
- store.Position = startPos;
- // Perf optimization - Don't use Reflection for our defaults.
- // Note there are two different sets of strings here - the
- // assembly qualified strings emitted by ResourceWriter, and
- // the abbreviated ones emitted by InternalResGen.
- if (CanUseDefaultResourceClasses(readerTypeName, resSetTypeName))
- {
- return new RuntimeResourceSet(store, permitDeserialization: true);
- }
- else
- {
- IResourceReader reader;
-
- // Permit deserialization as long as the default ResourceReader is used
- if (ResourceManager.IsDefaultType(readerTypeName, ResourceManager.ResReaderTypeName))
- {
- reader = new ResourceReader(
- store,
- new Dictionary<string, ResourceLocator>(FastResourceComparer.Default),
- permitDeserialization: true);
- }
- else
- {
- Type readerType = Type.GetType(readerTypeName, throwOnError: true)!;
- object[] args = new object[1];
- args[0] = store;
- reader = (IResourceReader)Activator.CreateInstance(readerType, args)!;
- }
-
- object[] resourceSetArgs = new object[1];
- resourceSetArgs[0] = reader;
-
- Type resSetType;
- if (_mediator.UserResourceSet == null)
- {
- Debug.Assert(resSetTypeName != null, "We should have a ResourceSet type name from the custom resource file here.");
- resSetType = Type.GetType(resSetTypeName, true, false)!;
- }
- else
- {
- resSetType = _mediator.UserResourceSet;
- }
-
- ResourceSet rs = (ResourceSet)Activator.CreateInstance(resSetType,
- BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance,
- null,
- resourceSetArgs,
- null,
- null)!;
- return rs;
- }
- }
- else
- {
- store.Position = startPos;
- }
- }
-
- if (_mediator.UserResourceSet == null)
- {
- return new RuntimeResourceSet(store, permitDeserialization: true);
- }
- else
- {
- object[] args = new object[2];
- args[0] = store;
- args[1] = assembly;
- try
- {
- // Add in a check for a constructor taking in an assembly first.
- try
- {
- return (ResourceSet)Activator.CreateInstance(_mediator.UserResourceSet, args)!;
- }
- catch (MissingMethodException) { }
-
- args = new object[1];
- args[0] = store;
- return (ResourceSet)Activator.CreateInstance(_mediator.UserResourceSet, args)!;
- }
- catch (MissingMethodException e)
- {
- throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ResMgrBadResSet_Type, _mediator.UserResourceSet.AssemblyQualifiedName), e);
- }
- }
- }
-
- private Stream? GetManifestResourceStream(Assembly satellite, string fileName)
- {
- Debug.Assert(satellite != null, "satellite shouldn't be null; check caller");
- Debug.Assert(fileName != null, "fileName shouldn't be null; check caller");
-
- return satellite.GetManifestResourceStream(_mediator.LocationInfo!, fileName) ??
- CaseInsensitiveManifestResourceStreamLookup(satellite, fileName);
- }
-
- // Looks up a .resources file in the assembly manifest using
- // case-insensitive lookup rules. Yes, this is slow. The metadata
- // dev lead refuses to make all assembly manifest resource lookups case-insensitive,
- // even optionally case-insensitive.
- private Stream? CaseInsensitiveManifestResourceStreamLookup(Assembly satellite, string name)
- {
- Debug.Assert(satellite != null, "satellite shouldn't be null; check caller");
- Debug.Assert(name != null, "name shouldn't be null; check caller");
-
- string? nameSpace = _mediator.LocationInfo?.Namespace;
-
- char c = Type.Delimiter;
- string resourceName = nameSpace != null && name != null ?
- string.Concat(nameSpace, new ReadOnlySpan<char>(ref c, 1), name) :
- string.Concat(nameSpace, name);
-
- string? canonicalName = null;
- foreach (string existingName in satellite.GetManifestResourceNames())
- {
- if (string.Equals(existingName, resourceName, StringComparison.InvariantCultureIgnoreCase))
- {
- if (canonicalName == null)
- {
- canonicalName = existingName;
- }
- else
- {
- throw new MissingManifestResourceException(SR.Format(SR.MissingManifestResource_MultipleBlobs, resourceName, satellite.ToString()));
- }
- }
- }
-
- if (canonicalName == null)
- {
- return null;
- }
-
- return satellite.GetManifestResourceStream(canonicalName);
- }
-
- private Assembly? GetSatelliteAssembly(CultureInfo lookForCulture)
- {
- Debug.Assert(_mediator.MainAssembly != null);
- if (!_mediator.LookedForSatelliteContractVersion)
- {
- _mediator.SatelliteContractVersion = ResourceManager.ResourceManagerMediator.ObtainSatelliteContractVersion(_mediator.MainAssembly);
- _mediator.LookedForSatelliteContractVersion = true;
- }
-
- Assembly? satellite = null;
-
- // Look up the satellite assembly, but don't let problems
- // like a partially signed satellite assembly stop us from
- // doing fallback and displaying something to the user.
- try
- {
- satellite = InternalGetSatelliteAssembly(_mediator.MainAssembly, lookForCulture, _mediator.SatelliteContractVersion);
- }
- catch (FileLoadException)
- {
- }
- catch (BadImageFormatException)
- {
- // Don't throw for zero-length satellite assemblies, for compat with v1
- }
-
- return satellite;
- }
-
- // Perf optimization - Don't use Reflection for most cases with
- // our .resources files. This makes our code run faster and we can avoid
- // creating a ResourceReader via Reflection. This would incur
- // a security check (since the link-time check on the constructor that
- // takes a String is turned into a full demand with a stack walk)
- // and causes partially trusted localized apps to fail.
- private bool CanUseDefaultResourceClasses(string readerTypeName, string resSetTypeName)
- {
- Debug.Assert(readerTypeName != null, "readerTypeName shouldn't be null; check caller");
- Debug.Assert(resSetTypeName != null, "resSetTypeName shouldn't be null; check caller");
-
- if (_mediator.UserResourceSet != null)
- return false;
-
- // Ignore the actual version of the ResourceReader and
- // RuntimeResourceSet classes. Let those classes deal with
- // versioning themselves.
-
- if (readerTypeName != null)
- {
- if (!ResourceManager.IsDefaultType(readerTypeName, ResourceManager.ResReaderTypeName))
- return false;
- }
-
- if (resSetTypeName != null)
- {
- if (!ResourceManager.IsDefaultType(resSetTypeName, ResourceManager.ResSetTypeName))
- return false;
- }
-
- return true;
- }
-
- private void HandleSatelliteMissing()
- {
- Debug.Assert(_mediator.MainAssembly != null);
- string satAssemName = _mediator.MainAssembly.GetName().Name + ".resources.dll";
- if (_mediator.SatelliteContractVersion != null)
- {
- satAssemName += ", Version=" + _mediator.SatelliteContractVersion.ToString();
- }
-
- byte[]? token = _mediator.MainAssembly.GetName().GetPublicKeyToken();
- if (token != null)
- {
- int iLen = token.Length;
- StringBuilder publicKeyTok = new StringBuilder(iLen * 2);
- for (int i = 0; i < iLen; i++)
- {
- publicKeyTok.Append(token[i].ToString("x", CultureInfo.InvariantCulture));
- }
- satAssemName += ", PublicKeyToken=" + publicKeyTok;
- }
-
- Debug.Assert(_mediator.NeutralResourcesCulture != null);
- string missingCultureName = _mediator.NeutralResourcesCulture.Name;
- if (missingCultureName.Length == 0)
- {
- missingCultureName = "<invariant>";
- }
- throw new MissingSatelliteAssemblyException(SR.Format(SR.MissingSatelliteAssembly_Culture_Name, _mediator.NeutralResourcesCulture, satAssemName), missingCultureName);
- }
-
- private static string GetManifestResourceNamesList(Assembly assembly)
- {
- try
- {
- string[] resourceSetNames = assembly.GetManifestResourceNames();
- int length = resourceSetNames.Length;
- string postfix = "\"";
-
- // If we have more than 10 resource sets, we just print the first 10 for the sake of the exception message readability.
- const int MaxLength = 10;
- if (length > MaxLength)
- {
- length = MaxLength;
- postfix = "\", ...";
- }
-
- return "\"" + string.Join("\", \"", resourceSetNames, 0, length) + postfix;
- }
- catch
- {
- return "\"\"";
- }
- }
-
- private void HandleResourceStreamMissing(string fileName)
- {
- Debug.Assert(_mediator.BaseName != null);
- // Keep people from bothering me about resources problems
- if (_mediator.MainAssembly == typeof(object).Assembly && _mediator.BaseName.Equals(System.CoreLib.Name))
- {
- // This would break CultureInfo & all our exceptions.
- Debug.Fail("Couldn't get " + System.CoreLib.Name + ResourceManager.ResFileExtension + " from " + System.CoreLib.Name + "'s assembly" + Environment.NewLineConst + Environment.NewLineConst + "Are you building the runtime on your machine? Chances are the BCL directory didn't build correctly. Type 'build -c' in the BCL directory. If you get build errors, look at buildd.log. If you then can't figure out what's wrong (and you aren't changing the assembly-related metadata code), ask a BCL dev.\n\nIf you did NOT build the runtime, you shouldn't be seeing this and you've found a bug.");
-
- // We cannot continue further - simply FailFast.
- const string MesgFailFast = System.CoreLib.Name + ResourceManager.ResFileExtension + " couldn't be found! Large parts of the BCL won't work!";
- System.Environment.FailFast(MesgFailFast);
- }
- // We really don't think this should happen - we always
- // expect the neutral locale's resources to be present.
- string resName = string.Empty;
- if (_mediator.LocationInfo != null && _mediator.LocationInfo.Namespace != null)
- resName = _mediator.LocationInfo.Namespace + Type.Delimiter;
- resName += fileName;
- Debug.Assert(_mediator.MainAssembly != null);
- throw new MissingManifestResourceException(
- SR.Format(SR.MissingManifestResource_NoNeutralAsm,
- resName, _mediator.MainAssembly.GetName().Name, GetManifestResourceNamesList(_mediator.MainAssembly)));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/MissingManifestResourceException.cs b/netcore/System.Private.CoreLib/shared/System/Resources/MissingManifestResourceException.cs
deleted file mode 100644
index 217a142c70e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/MissingManifestResourceException.cs
+++ /dev/null
@@ -1,36 +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 System.Runtime.Serialization;
-
-namespace System.Resources
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class MissingManifestResourceException : SystemException
- {
- public MissingManifestResourceException()
- : base(SR.Arg_MissingManifestResourceException)
- {
- HResult = System.HResults.COR_E_MISSINGMANIFESTRESOURCE;
- }
-
- public MissingManifestResourceException(string? message)
- : base(message)
- {
- HResult = System.HResults.COR_E_MISSINGMANIFESTRESOURCE;
- }
-
- public MissingManifestResourceException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = System.HResults.COR_E_MISSINGMANIFESTRESOURCE;
- }
-
- protected MissingManifestResourceException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/MissingSatelliteAssemblyException.cs b/netcore/System.Private.CoreLib/shared/System/Resources/MissingSatelliteAssemblyException.cs
deleted file mode 100644
index 13933627049..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/MissingSatelliteAssemblyException.cs
+++ /dev/null
@@ -1,60 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: Exception for a missing satellite assembly needed
-** for ultimate resource fallback. This usually
-** indicates a setup and/or deployment problem.
-**
-**
-===========================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System.Resources
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class MissingSatelliteAssemblyException : SystemException
- {
- private readonly string? _cultureName;
-
- public MissingSatelliteAssemblyException()
- : base(SR.MissingSatelliteAssembly_Default)
- {
- HResult = System.HResults.COR_E_MISSINGSATELLITEASSEMBLY;
- }
-
- public MissingSatelliteAssemblyException(string? message)
- : base(message)
- {
- HResult = System.HResults.COR_E_MISSINGSATELLITEASSEMBLY;
- }
-
- public MissingSatelliteAssemblyException(string? message, string? cultureName)
- : base(message)
- {
- HResult = System.HResults.COR_E_MISSINGSATELLITEASSEMBLY;
- _cultureName = cultureName;
- }
-
- public MissingSatelliteAssemblyException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = System.HResults.COR_E_MISSINGSATELLITEASSEMBLY;
- }
-
- protected MissingSatelliteAssemblyException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
-
- public string? CultureName => _cultureName;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/NeutralResourcesLanguageAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Resources/NeutralResourcesLanguageAttribute.cs
deleted file mode 100644
index 495c5205b25..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/NeutralResourcesLanguageAttribute.cs
+++ /dev/null
@@ -1,33 +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.
-
-namespace System.Resources
-{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
- public sealed class NeutralResourcesLanguageAttribute : Attribute
- {
- public NeutralResourcesLanguageAttribute(string cultureName)
- {
- if (cultureName == null)
- throw new ArgumentNullException(nameof(cultureName));
-
- CultureName = cultureName;
- Location = UltimateResourceFallbackLocation.MainAssembly;
- }
-
- public NeutralResourcesLanguageAttribute(string cultureName, UltimateResourceFallbackLocation location)
- {
- if (cultureName == null)
- throw new ArgumentNullException(nameof(cultureName));
- if (!Enum.IsDefined(typeof(UltimateResourceFallbackLocation), location))
- throw new ArgumentException(SR.Format(SR.Arg_InvalidNeutralResourcesLanguage_FallbackLoc, location));
-
- CultureName = cultureName;
- Location = location;
- }
-
- public string CultureName { get; }
- public UltimateResourceFallbackLocation Location { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceFallbackManager.cs b/netcore/System.Private.CoreLib/shared/System/Resources/ResourceFallbackManager.cs
deleted file mode 100644
index a78042f8e85..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceFallbackManager.cs
+++ /dev/null
@@ -1,83 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: Encapsulates CultureInfo fallback for resource
-** lookup
-**
-**
-===========================================================*/
-
-using System.Collections;
-using System.Collections.Generic;
-using System.Globalization;
-
-namespace System.Resources
-{
- internal class ResourceFallbackManager : IEnumerable<CultureInfo>
- {
- private readonly CultureInfo m_startingCulture;
- private readonly CultureInfo? m_neutralResourcesCulture;
- private readonly bool m_useParents;
-
- internal ResourceFallbackManager(CultureInfo? startingCulture, CultureInfo? neutralResourcesCulture, bool useParents)
- {
- if (startingCulture != null)
- {
- m_startingCulture = startingCulture;
- }
- else
- {
- m_startingCulture = CultureInfo.CurrentUICulture;
- }
-
- m_neutralResourcesCulture = neutralResourcesCulture;
- m_useParents = useParents;
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- // WARING: This function must be kept in sync with ResourceManager.GetFirstResourceSet()
- public IEnumerator<CultureInfo> GetEnumerator()
- {
- bool reachedNeutralResourcesCulture = false;
-
- // 1. starting culture chain, up to neutral
- CultureInfo currentCulture = m_startingCulture;
- do
- {
- if (m_neutralResourcesCulture != null && currentCulture.Name == m_neutralResourcesCulture.Name)
- {
- // Return the invariant culture all the time, even if the UltimateResourceFallbackLocation
- // is a satellite assembly. This is fixed up later in ManifestBasedResourceGroveler::UltimateFallbackFixup.
- yield return CultureInfo.InvariantCulture;
- reachedNeutralResourcesCulture = true;
- break;
- }
- yield return currentCulture;
- currentCulture = currentCulture.Parent;
- } while (m_useParents && !currentCulture.HasInvariantCultureName);
-
- if (!m_useParents || m_startingCulture.HasInvariantCultureName)
- {
- yield break;
- }
-
- // 2. invariant
- // Don't return invariant twice though.
- if (reachedNeutralResourcesCulture)
- yield break;
-
- yield return CultureInfo.InvariantCulture;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.Uap.cs b/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.Uap.cs
deleted file mode 100644
index 27ed243f478..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.Uap.cs
+++ /dev/null
@@ -1,198 +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 System.IO;
-using System.Globalization;
-using System.Reflection;
-using System.Diagnostics;
-using Internal.Resources;
-
-namespace System.Resources
-{
- public partial class ResourceManager
- {
- private WindowsRuntimeResourceManagerBase? _WinRTResourceManager;
- private PRIExceptionInfo? _PRIExceptionInfo;
- private bool _PRIInitialized;
- private bool _useUapResourceManagement;
-
- private string? GetStringFromPRI(string stringName, CultureInfo? culture, string? neutralResourcesCulture)
- {
- Debug.Assert(_useUapResourceManagement);
- Debug.Assert(_WinRTResourceManager != null);
- Debug.Assert(_PRIInitialized);
-
- // If the caller explicitly passed in a culture that was obtained by calling CultureInfo.CurrentUICulture,
- // null it out, so that we re-compute it. If we use modern resource lookup, we may end up getting a "better"
- // match, since CultureInfo objects can't represent all the different languages the Uap resource model supports.
- if (object.ReferenceEquals(culture, CultureInfo.CurrentUICulture))
- {
- culture = null;
- }
-
- string? startingCulture = culture?.Name;
-
- if (!_PRIInitialized)
- {
- // Always throw if we did not fully succeed in initializing the WinRT Resource Manager.
-
- if (_PRIExceptionInfo != null && _PRIExceptionInfo.PackageSimpleName != null && _PRIExceptionInfo.ResWFile != null)
- throw new MissingManifestResourceException(SR.Format(SR.MissingManifestResource_ResWFileNotLoaded, _PRIExceptionInfo.ResWFile, _PRIExceptionInfo.PackageSimpleName));
-
- throw new MissingManifestResourceException(SR.MissingManifestResource_NoPRIresources);
- }
-
- if (stringName.Length == 0)
- return null;
-
- // Do not handle exceptions. See the comment in SetUapConfiguration about throwing
- // exception types that the ResourceManager class is not documented to throw.
- return _WinRTResourceManager.GetString(
- stringName,
- string.IsNullOrEmpty(startingCulture) ? null : startingCulture,
- string.IsNullOrEmpty(neutralResourcesCulture) ? null : neutralResourcesCulture);
- }
-
- // Since we can't directly reference System.Runtime.WindowsRuntime from System.Private.CoreLib, we have to get the type via reflection.
- // It would be better if we could just implement WindowsRuntimeResourceManager in System.Private.CoreLib, but we can't, because
- // we can do very little with WinRT in System.Private.CoreLib.
- internal static WindowsRuntimeResourceManagerBase GetWinRTResourceManager()
- {
- Type WinRTResourceManagerType = Type.GetType("System.Resources.WindowsRuntimeResourceManager, System.Runtime.WindowsRuntime", throwOnError: true)!;
- return (WindowsRuntimeResourceManagerBase)Activator.CreateInstance(WinRTResourceManagerType, nonPublic: true)!;
- }
-
- // CoreCLR: When running under AppX, the following rules apply for resource lookup:
- //
- // 1) For Framework assemblies, we always use satellite assembly based lookup.
- // 2) For non-FX assemblies:
- //
- // a) If the assembly lives under PLATFORM_RESOURCE_ROOTS (as specified by the host during AppDomain creation),
- // then we will use satellite assembly based lookup in assemblies like *.resources.dll.
- //
- // b) For any other non-FX assembly, we will use the modern resource manager with the premise that app package
- // contains the PRI resources.
- //
- // .NET Native: If it is framework assembly we'll return true. The reason is in .NetNative we don't merge the
- // resources to the app PRI file.
- // The framework assemblies are tagged with attribute [assembly: AssemblyMetadata(".NETFrameworkAssembly", "")]
- private static bool ShouldUseUapResourceManagement(Assembly resourcesAssembly)
- {
- if (resourcesAssembly == typeof(object).Assembly) // We are not loading resources for System.Private.CoreLib
- return false;
-
- // Check to see if the assembly is under PLATFORM_RESOURCE_ROOTS. If it is, then we should use satellite assembly lookup for it.
- string? platformResourceRoots = (string?)AppContext.GetData("PLATFORM_RESOURCE_ROOTS");
- if (!string.IsNullOrEmpty(platformResourceRoots))
- {
- string resourceAssemblyPath = resourcesAssembly.Location;
-
- // Loop through the PLATFORM_RESOURCE_ROOTS and see if the assembly is contained in it.
- foreach (string pathPlatformResourceRoot in platformResourceRoots.Split(Path.PathSeparator))
- {
- if (resourceAssemblyPath.StartsWith(pathPlatformResourceRoot, StringComparison.CurrentCultureIgnoreCase))
- {
- // Found the resource assembly to be present in one of the PLATFORM_RESOURCE_ROOT, so stop the enumeration loop.
- return false;
- }
- }
- }
-
- return true;
- }
-
- // Only call SetUapConfiguration from ResourceManager constructors, and nowhere else.
- // Throws MissingManifestResourceException and WinRT HResults
- private void SetUapConfiguration()
- {
- Debug.Assert(!_useUapResourceManagement); // Only this function writes to this member
- Debug.Assert(_WinRTResourceManager == null); // Only this function writes to this member
- Debug.Assert(!_PRIInitialized); // Only this function writes to this member
- Debug.Assert(_PRIExceptionInfo == null); // Only this function writes to this member
-
- if (!ApplicationModel.IsUap)
- return;
-
- Debug.Assert(MainAssembly != null);
- if (!ShouldUseUapResourceManagement(MainAssembly))
- return;
-
- _useUapResourceManagement = true;
-
- // If we have the type information from the ResourceManager(Type) constructor, we use it. Otherwise, we use BaseNameField.
- string? reswFilename = _locationInfo == null ? BaseNameField : _locationInfo.FullName;
-
- // The only way this can happen is if a class inherited from ResourceManager and
- // did not set the BaseNameField before calling the protected ResourceManager() constructor.
- // For other constructors, we would already have thrown an ArgumentNullException by now.
- // Throwing an ArgumentNullException now is not the right thing to do because technically
- // ResourceManager() takes no arguments, and because it is not documented as throwing
- // any exceptions. Instead, let's go through the rest of the initialization with this set to
- // an empty string. We may in fact fail earlier for another reason, but otherwise we will
- // throw a MissingManifestResourceException when GetString is called indicating that a
- // resW filename called "" could not be found.
- reswFilename ??= string.Empty;
-
- // At this point it is important NOT to set _useUapResourceManagement to false
- // if the PRI file does not exist because we are now certain we need to load PRI
- // resources. We want to fail by throwing a MissingManifestResourceException
- // if WindowsRuntimeResourceManager.Initialize fails to locate the PRI file. We do not
- // want to fall back to using satellite assemblies anymore. Note that we would not throw
- // the MissingManifestResourceException from this function, but from GetString. See the
- // comment below on the reason for this.
-
- _WinRTResourceManager = GetWinRTResourceManager();
-
- try
- {
- _PRIInitialized = _WinRTResourceManager.Initialize(MainAssembly.Location, reswFilename, out _PRIExceptionInfo);
- // Note that _PRIExceptionInfo might be null - this is OK.
- // In that case we will just throw the generic
- // MissingManifestResource_NoPRIresources exception.
- // See the implementation of GetString for more details.
- }
- // We would like to be able to throw a MissingManifestResourceException here if PRI resources
- // could not be loaded for a recognized reason. However, the ResourceManager constructors
- // that call SetUapConfiguration are not documented as throwing MissingManifestResourceException,
- // and since they are part of the portable profile, we cannot start throwing a new exception type
- // as that would break existing portable libraries. Hence we must save the exception information
- // now and throw the exception on the first call to GetString.
- catch (FileNotFoundException)
- {
- // We will throw MissingManifestResource_NoPRIresources from GetString
- // when we see that _PRIInitialized is false.
- }
- catch (Exception e)
- {
- // ERROR_MRM_MAP_NOT_FOUND can be thrown by the call to ResourceManager.get_AllResourceMaps
- // in WindowsRuntimeResourceManager.Initialize.
- // In this case _PRIExceptionInfo is now null and we will just throw the generic
- // MissingManifestResource_NoPRIresources exception.
- // See the implementation of GetString for more details.
- if (e.HResult != HResults.ERROR_MRM_MAP_NOT_FOUND)
- throw; // Unexpected exception code. Bubble it up to the caller.
- }
-
- if (!_PRIInitialized)
- {
- _useUapResourceManagement = false;
- }
-
- // Allow all other exception types to bubble up to the caller.
-
- // Yes, this causes us to potentially throw exception types that are not documented.
-
- // Ultimately the tradeoff is the following:
- // -We could ignore unknown exceptions or rethrow them as inner exceptions
- // of exceptions that the ResourceManager class is already documented as throwing.
- // This would allow existing portable libraries to gracefully recover if they don't care
- // too much about the ResourceManager object they are using. However it could
- // mask potentially fatal errors that we are not aware of, such as a disk drive failing.
-
- // The alternative, which we chose, is to throw unknown exceptions. This may tear
- // down the process if the portable library and app don't expect this exception type.
- // On the other hand, this won't mask potentially fatal errors we don't know about.
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs b/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs
deleted file mode 100644
index 9fb40a69a89..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs
+++ /dev/null
@@ -1,811 +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 System.IO;
-using System.Globalization;
-using System.Reflection;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace System.Resources
-{
- // Resource Manager exposes an assembly's resources to an application for
- // the correct CultureInfo. An example would be localizing text for a
- // user-visible message. Create a set of resource files listing a name
- // for a message and its value, compile them using ResGen, put them in
- // an appropriate place (your assembly manifest(?)), then create a Resource
- // Manager and query for the name of the message you want. The Resource
- // Manager will use CultureInfo.GetCurrentUICulture() to look
- // up a resource for your user's locale settings.
- //
- // Users should ideally create a resource file for every culture, or
- // at least a meaningful subset. The filenames will follow the naming
- // scheme:
- //
- // basename.culture name.resources
- //
- // The base name can be the name of your application, or depending on
- // the granularity desired, possibly the name of each class. The culture
- // name is determined from CultureInfo's Name property.
- // An example file name may be MyApp.en-US.resources for
- // MyApp's US English resources.
- //
- // -----------------
- // Refactoring Notes
- // -----------------
- // In Feb 08, began first step of refactoring ResourceManager to improve
- // maintainability (sd changelist 3012100). This resulted in breaking
- // apart the InternalGetResourceSet "big loop" so that the file-based
- // and manifest-based lookup was located in separate methods.
- // In Apr 08, continued refactoring so that file-based and manifest-based
- // concerns are encapsulated by separate classes. At construction, the
- // ResourceManager creates one of these classes based on whether the
- // RM will need to use file-based or manifest-based resources, and
- // afterwards refers to this through the interface IResourceGroveler.
- //
- // Serialization Compat: Ideally, we could have refactored further but
- // this would have broken serialization compat. For example, the
- // ResourceManager member UseManifest and UseSatelliteAssem are no
- // longer relevant on ResourceManager. Similarly, other members could
- // ideally be moved to the file-based or manifest-based classes
- // because they are only relevant for those types of lookup.
- //
- // Solution now / in the future:
- // For now, we simply use a mediator class so that we can keep these
- // members on ResourceManager but allow the file-based and manifest-
- // based classes to access/set these members in a uniform way. See
- // ResourceManagerMediator.
- // We encapsulate fallback logic in a fallback iterator class, so that
- // this logic isn't duplicated in several methods.
- //
- // In the future, we can also look into further factoring and better
- // design of IResourceGroveler interface to accommodate unused parameters
- // that don't make sense for either file-based or manifest-based lookup paths.
- //
- // Benefits of this refactoring:
- // - Makes it possible to understand what the ResourceManager does,
- // which is key for maintainability.
- // - Makes the ResourceManager more extensible by identifying and
- // encapsulating what varies
- // - Unearthed a bug that's been lurking a while in file-based
- // lookup paths for InternalGetResourceSet if createIfNotExists is
- // false.
- // - Reuses logic, e.g. by breaking apart the culture fallback into
- // the fallback iterator class, we don't have to repeat the
- // sometimes confusing fallback logic across multiple methods
- // - Fxcop violations reduced to 1/5th of original count. Most
- // importantly, code complexity violations disappeared.
- // - Finally, it got rid of dead code paths. Because the big loop was
- // so confusing, it masked unused chunks of code. Also, dividing
- // between file-based and manifest-based allowed functionaliy
- // unused in silverlight to fall out.
- //
- // Note: this type is integral to the construction of exception objects,
- // and sometimes this has to be done in low memory situtations (OOM) or
- // to create TypeInitializationExceptions due to failure of a static class
- // constructor. This type needs to be extremely careful and assume that
- // any type it references may have previously failed to construct, so statics
- // belonging to that type may not be initialized. FrameworkEventSource.Log
- // is one such example.
- //
-
- public partial class ResourceManager
- {
- internal class CultureNameResourceSetPair
- {
- public string? lastCultureName;
- public ResourceSet? lastResourceSet;
- }
-
- protected string BaseNameField;
- protected Assembly? MainAssembly; // Need the assembly manifest sometimes.
-
- private Dictionary<string, ResourceSet>? _resourceSets;
- private readonly string? _moduleDir; // For assembly-ignorant directory location
- private readonly Type? _locationInfo; // For Assembly or type-based directory layout
- private readonly Type? _userResourceSet; // Which ResourceSet instance to create
- private CultureInfo? _neutralResourcesCulture; // For perf optimizations.
-
- private CultureNameResourceSetPair? _lastUsedResourceCache;
-
- private bool _ignoreCase; // Whether case matters in GetString & GetObject
-
- private bool _useManifest; // Use Assembly manifest, or grovel disk.
-
- // Whether to fall back to the main assembly or a particular
- // satellite for the neutral resources.
- private UltimateResourceFallbackLocation _fallbackLoc;
- // Version number of satellite assemblies to look for. May be null.
- private Version? _satelliteContractVersion;
- private bool _lookedForSatelliteContractVersion;
-
- private IResourceGroveler _resourceGroveler = null!;
-
- public static readonly int MagicNumber = unchecked((int)0xBEEFCACE); // If only hex had a K...
-
- // Version number so ResMgr can get the ideal set of classes for you.
- // ResMgr header is:
- // 1) MagicNumber (little endian Int32)
- // 2) HeaderVersionNumber (little endian Int32)
- // 3) Num Bytes to skip past ResMgr header (little endian Int32)
- // 4) IResourceReader type name for this file (bytelength-prefixed UTF-8 String)
- // 5) ResourceSet type name for this file (bytelength-prefixed UTF8 String)
- public static readonly int HeaderVersionNumber = 1;
-
- // It would be better if we could use a _neutralCulture instead of calling
- // CultureInfo.InvariantCulture everywhere, but we run into problems with the .cctor. CultureInfo
- // initializes assembly, which initializes ResourceManager, which tries to get a CultureInfo which isn't
- // there yet because CultureInfo's class initializer hasn't finished. If we move SystemResMgr off of
- // Assembly (or at least make it an internal property) we should be able to circumvent this problem.
-
- // This is our min required ResourceSet type.
- private static readonly Type s_minResourceSet = typeof(ResourceSet);
- // These Strings are used to avoid using Reflection in CreateResourceSet.
- internal const string ResReaderTypeName = "System.Resources.ResourceReader";
- internal const string ResSetTypeName = "System.Resources.RuntimeResourceSet";
- internal const string ResFileExtension = ".resources";
- internal const int ResFileExtensionLength = 10;
-
- protected ResourceManager()
- {
- _lastUsedResourceCache = new CultureNameResourceSetPair();
- ResourceManagerMediator mediator = new ResourceManagerMediator(this);
- _resourceGroveler = new ManifestBasedResourceGroveler(mediator);
- BaseNameField = string.Empty;
- }
-
- // Constructs a Resource Manager for files beginning with
- // baseName in the directory specified by resourceDir
- // or in the current directory. This Assembly-ignorant constructor is
- // mostly useful for testing your own ResourceSet implementation.
- //
- // A good example of a baseName might be "Strings". BaseName
- // should not end in ".resources".
- //
- // Note: System.Windows.Forms uses this method at design time.
- //
- private ResourceManager(string baseName, string resourceDir, Type? userResourceSet)
- {
- if (null == baseName)
- throw new ArgumentNullException(nameof(baseName));
- if (null == resourceDir)
- throw new ArgumentNullException(nameof(resourceDir));
-
- BaseNameField = baseName;
-
- _moduleDir = resourceDir;
- _userResourceSet = userResourceSet;
- _resourceSets = new Dictionary<string, ResourceSet>();
- _lastUsedResourceCache = new CultureNameResourceSetPair();
- _useManifest = false;
-
- ResourceManagerMediator mediator = new ResourceManagerMediator(this);
- _resourceGroveler = new FileBasedResourceGroveler(mediator);
- }
-
- public ResourceManager(string baseName, Assembly assembly)
- {
- if (null == baseName)
- throw new ArgumentNullException(nameof(baseName));
- if (null == assembly)
- throw new ArgumentNullException(nameof(assembly));
- if (!assembly.IsRuntimeImplemented())
- throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly);
-
- MainAssembly = assembly;
- BaseNameField = baseName;
-
- CommonAssemblyInit();
- }
-
- public ResourceManager(string baseName, Assembly assembly, Type? usingResourceSet)
- {
- if (null == baseName)
- throw new ArgumentNullException(nameof(baseName));
- if (null == assembly)
- throw new ArgumentNullException(nameof(assembly));
- if (!assembly.IsRuntimeImplemented())
- throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly);
-
- MainAssembly = assembly;
- BaseNameField = baseName;
-
- if (usingResourceSet != null && (usingResourceSet != s_minResourceSet) && !usingResourceSet.IsSubclassOf(s_minResourceSet))
- throw new ArgumentException(SR.Arg_ResMgrNotResSet, nameof(usingResourceSet));
- _userResourceSet = usingResourceSet;
-
- CommonAssemblyInit();
- }
-
- public ResourceManager(Type resourceSource)
- {
- if (null == resourceSource)
- throw new ArgumentNullException(nameof(resourceSource));
- if (!resourceSource.IsRuntimeImplemented())
- throw new ArgumentException(SR.Argument_MustBeRuntimeType);
-
- _locationInfo = resourceSource;
- MainAssembly = _locationInfo.Assembly;
- BaseNameField = resourceSource.Name;
-
- CommonAssemblyInit();
- }
-
- // Trying to unify code as much as possible, even though having to do a
- // security check in each constructor prevents it.
- private void CommonAssemblyInit()
- {
-#if FEATURE_APPX
- SetUapConfiguration();
-#endif
-
- // Now we can use the managed resources even when using PRI's to support the APIs GetObject, GetStream...etc.
- _useManifest = true;
-
- _resourceSets = new Dictionary<string, ResourceSet>();
- _lastUsedResourceCache = new CultureNameResourceSetPair();
-
- ResourceManagerMediator mediator = new ResourceManagerMediator(this);
- _resourceGroveler = new ManifestBasedResourceGroveler(mediator);
-
- Debug.Assert(MainAssembly != null);
- _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, out _fallbackLoc);
- }
-
- // Gets the base name for the ResourceManager.
- public virtual string BaseName => BaseNameField;
-
- // Whether we should ignore the capitalization of resources when calling
- // GetString or GetObject.
- public virtual bool IgnoreCase
- {
- get => _ignoreCase;
- set => _ignoreCase = value;
- }
-
- // Returns the Type of the ResourceSet the ResourceManager uses
- // to construct ResourceSets.
- public virtual Type ResourceSetType => _userResourceSet ?? typeof(RuntimeResourceSet);
-
- protected UltimateResourceFallbackLocation FallbackLocation
- {
- get => _fallbackLoc;
- set => _fallbackLoc = value;
- }
-
- // Tells the ResourceManager to call Close on all ResourceSets and
- // release all resources. This will shrink your working set by
- // potentially a substantial amount in a running application. Any
- // future resource lookups on this ResourceManager will be as
- // expensive as the very first lookup, since it will need to search
- // for files and load resources again.
- //
- // This may be useful in some complex threading scenarios, where
- // creating a new ResourceManager isn't quite the correct behavior.
- public virtual void ReleaseAllResources()
- {
- Debug.Assert(_resourceSets != null);
- Dictionary<string, ResourceSet> localResourceSets = _resourceSets;
-
- // If any calls to Close throw, at least leave ourselves in a
- // consistent state.
- _resourceSets = new Dictionary<string, ResourceSet>();
- _lastUsedResourceCache = new CultureNameResourceSetPair();
-
- lock (localResourceSets)
- {
- foreach ((_, ResourceSet resourceSet) in localResourceSets)
- {
- resourceSet.Close();
- }
- }
- }
-
- public static ResourceManager CreateFileBasedResourceManager(string baseName, string resourceDir, Type? usingResourceSet)
- {
- return new ResourceManager(baseName, resourceDir, usingResourceSet);
- }
-
- // Given a CultureInfo, GetResourceFileName generates the name for
- // the binary file for the given CultureInfo. This method uses
- // CultureInfo's Name property as part of the file name for all cultures
- // other than the invariant culture. This method does not touch the disk,
- // and is used only to construct what a resource file name (suitable for
- // passing to the ResourceReader constructor) or a manifest resource file
- // name should look like.
- //
- // This method can be overriden to look for a different extension,
- // such as ".ResX", or a completely different format for naming files.
- protected virtual string GetResourceFileName(CultureInfo culture)
- {
- // If this is the neutral culture, don't include the culture name.
- if (culture.HasInvariantCultureName)
- {
- return BaseNameField + ResFileExtension;
- }
- else
- {
- CultureInfo.VerifyCultureName(culture.Name, throwException: true);
- return BaseNameField + "." + culture.Name + ResFileExtension;
- }
- }
-
- // WARNING: This function must be kept in sync with ResourceFallbackManager.GetEnumerator()
- // Return the first ResourceSet, based on the first culture ResourceFallbackManager would return
- internal ResourceSet? GetFirstResourceSet(CultureInfo culture)
- {
- // Logic from ResourceFallbackManager.GetEnumerator()
- if (_neutralResourcesCulture != null && culture.Name == _neutralResourcesCulture.Name)
- {
- culture = CultureInfo.InvariantCulture;
- }
-
- if (_lastUsedResourceCache != null)
- {
- lock (_lastUsedResourceCache)
- {
- if (culture.Name == _lastUsedResourceCache.lastCultureName)
- return _lastUsedResourceCache.lastResourceSet;
- }
- }
-
- // Look in the ResourceSet table
- Dictionary<string, ResourceSet>? localResourceSets = _resourceSets;
- ResourceSet? rs = null;
- if (localResourceSets != null)
- {
- lock (localResourceSets)
- {
- localResourceSets.TryGetValue(culture.Name, out rs);
- }
- }
-
- if (rs != null)
- {
- // update the cache with the most recent ResourceSet
- if (_lastUsedResourceCache != null)
- {
- lock (_lastUsedResourceCache)
- {
- _lastUsedResourceCache.lastCultureName = culture.Name;
- _lastUsedResourceCache.lastResourceSet = rs;
- }
- }
- return rs;
- }
-
- return null;
- }
-
- // Looks up a set of resources for a particular CultureInfo. This is
- // not useful for most users of the ResourceManager - call
- // GetString() or GetObject() instead.
- //
- // The parameters let you control whether the ResourceSet is created
- // if it hasn't yet been loaded and if parent CultureInfos should be
- // loaded as well for resource inheritance.
- //
- public virtual ResourceSet? GetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
- {
- if (null == culture)
- throw new ArgumentNullException(nameof(culture));
-
- Dictionary<string, ResourceSet>? localResourceSets = _resourceSets;
- ResourceSet? rs;
- if (localResourceSets != null)
- {
- lock (localResourceSets)
- {
- if (localResourceSets.TryGetValue(culture.Name, out rs))
- return rs;
- }
- }
-
- if (_useManifest && culture.HasInvariantCultureName)
- {
- string fileName = GetResourceFileName(culture);
- Debug.Assert(MainAssembly != null);
- Stream? stream = MainAssembly.GetManifestResourceStream(_locationInfo!, fileName);
- if (createIfNotExists && stream != null)
- {
- rs = ((ManifestBasedResourceGroveler)_resourceGroveler).CreateResourceSet(stream, MainAssembly);
- Debug.Assert(localResourceSets != null);
- AddResourceSet(localResourceSets, culture.Name, ref rs);
- return rs;
- }
- }
-
- return InternalGetResourceSet(culture, createIfNotExists, tryParents);
- }
-
- // InternalGetResourceSet is a non-threadsafe method where all the logic
- // for getting a resource set lives. Access to it is controlled by
- // threadsafe methods such as GetResourceSet, GetString, & GetObject.
- // This will take a minimal number of locks.
- protected virtual ResourceSet? InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
- {
- Debug.Assert(culture != null, "culture != null");
- Debug.Assert(_resourceSets != null);
-
- Dictionary<string, ResourceSet> localResourceSets = _resourceSets;
- ResourceSet? rs = null;
- CultureInfo? foundCulture = null;
- lock (localResourceSets)
- {
- if (localResourceSets.TryGetValue(culture.Name, out rs))
- {
- return rs;
- }
- }
-
- ResourceFallbackManager mgr = new ResourceFallbackManager(culture, _neutralResourcesCulture, tryParents);
-
- foreach (CultureInfo currentCultureInfo in mgr)
- {
- lock (localResourceSets)
- {
- if (localResourceSets.TryGetValue(currentCultureInfo.Name, out rs))
- {
- // we need to update the cache if we fellback
- if (culture != currentCultureInfo) foundCulture = currentCultureInfo;
- break;
- }
- }
-
- // InternalGetResourceSet will never be threadsafe. However, it must
- // be protected against reentrancy from the SAME THREAD. (ie, calling
- // GetSatelliteAssembly may send some window messages or trigger the
- // Assembly load event, which could fail then call back into the
- // ResourceManager). It's happened.
-
- rs = _resourceGroveler.GrovelForResourceSet(currentCultureInfo, localResourceSets,
- tryParents, createIfNotExists);
-
- // found a ResourceSet; we're done
- if (rs != null)
- {
- foundCulture = currentCultureInfo;
- break;
- }
- }
-
- if (rs != null && foundCulture != null)
- {
- // add entries to the cache for the cultures we have gone through
-
- // currentCultureInfo now refers to the culture that had resources.
- // update cultures starting from requested culture up to the culture
- // that had resources.
- foreach (CultureInfo updateCultureInfo in mgr)
- {
- AddResourceSet(localResourceSets, updateCultureInfo.Name, ref rs);
-
- // stop when we've added current or reached invariant (top of chain)
- if (updateCultureInfo == foundCulture)
- {
- break;
- }
- }
- }
-
- return rs;
- }
-
- // Simple helper to ease maintenance and improve readability.
- private static void AddResourceSet(Dictionary<string, ResourceSet> localResourceSets, string cultureName, ref ResourceSet rs)
- {
- // InternalGetResourceSet is both recursive and reentrant -
- // assembly load callbacks in particular are a way we can call
- // back into the ResourceManager in unexpectedly on the same thread.
- lock (localResourceSets)
- {
- // If another thread added this culture, return that.
- ResourceSet? lostRace;
- if (localResourceSets.TryGetValue(cultureName, out lostRace))
- {
- if (!object.ReferenceEquals(lostRace, rs))
- {
- // Note: In certain cases, we can be trying to add a ResourceSet for multiple
- // cultures on one thread, while a second thread added another ResourceSet for one
- // of those cultures. If there is a race condition we must make sure our ResourceSet
- // isn't in our dictionary before closing it.
- if (!localResourceSets.ContainsValue(rs))
- rs.Dispose();
- rs = lostRace;
- }
- }
- else
- {
- localResourceSets.Add(cultureName, rs);
- }
- }
- }
-
- protected static Version? GetSatelliteContractVersion(Assembly a)
- {
- // Ensure that the assembly reference is not null
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a), SR.ArgumentNull_Assembly);
- }
-
- string? v = a.GetCustomAttribute<SatelliteContractVersionAttribute>()?.Version;
- if (v == null)
- {
- // Return null. The calling code will use the assembly version instead to avoid potential type
- // and library loads caused by CA lookup.
- return null;
- }
-
- if (!Version.TryParse(v, out Version? version))
- {
- throw new ArgumentException(SR.Format(SR.Arg_InvalidSatelliteContract_Asm_Ver, a, v));
- }
-
- return version;
- }
-
- protected static CultureInfo GetNeutralResourcesLanguage(Assembly a)
- {
- // This method should be obsolete - replace it with the one below.
- // Unfortunately, we made it protected.
- return ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(a, out _);
- }
-
- // IGNORES VERSION
- internal static bool IsDefaultType(string asmTypeName,
- string typeName)
- {
- Debug.Assert(asmTypeName != null, "asmTypeName was unexpectedly null");
-
- // First, compare type names
- int comma = asmTypeName.IndexOf(',');
- if (((comma == -1) ? asmTypeName.Length : comma) != typeName.Length)
- return false;
-
- // case sensitive
- if (string.Compare(asmTypeName, 0, typeName, 0, typeName.Length, StringComparison.Ordinal) != 0)
- return false;
- if (comma == -1)
- return true;
-
- // Now, compare assembly display names (IGNORES VERSION AND PROCESSORARCHITECTURE)
- // also, for mscorlib ignores everything, since that's what the binder is going to do
- while (char.IsWhiteSpace(asmTypeName[++comma])) ;
-
- // case insensitive
- AssemblyName an = new AssemblyName(asmTypeName.Substring(comma));
-
- // to match IsMscorlib() in VM
- return string.Equals(an.Name, "mscorlib", StringComparison.OrdinalIgnoreCase);
- }
-
- // Looks up a resource value for a particular name. Looks in the
- // current thread's CultureInfo, and if not found, all parent CultureInfos.
- // Returns null if the resource wasn't found.
- //
- public virtual string? GetString(string name)
- {
- return GetString(name, null);
- }
-
- // Looks up a resource value for a particular name. Looks in the
- // specified CultureInfo, and if not found, all parent CultureInfos.
- // Returns null if the resource wasn't found.
- //
- public virtual string? GetString(string name, CultureInfo? culture)
- {
- if (null == name)
- throw new ArgumentNullException(nameof(name));
-
-#if FEATURE_APPX
- if (_useUapResourceManagement)
- {
- // Throws WinRT hresults.
- Debug.Assert(_neutralResourcesCulture != null);
- return GetStringFromPRI(name, culture, _neutralResourcesCulture.Name);
- }
-#endif
-
- culture ??= CultureInfo.CurrentUICulture;
-
- ResourceSet? last = GetFirstResourceSet(culture);
-
- if (last != null)
- {
- string? value = last.GetString(name, _ignoreCase);
- if (value != null)
- return value;
- }
-
- // This is the CultureInfo hierarchy traversal code for resource
- // lookups, similar but necessarily orthogonal to the ResourceSet
- // lookup logic.
- ResourceFallbackManager mgr = new ResourceFallbackManager(culture, _neutralResourcesCulture, true);
- foreach (CultureInfo currentCultureInfo in mgr)
- {
- ResourceSet? rs = InternalGetResourceSet(currentCultureInfo, true, true);
- if (rs == null)
- break;
-
- if (rs != last)
- {
- string? value = rs.GetString(name, _ignoreCase);
- if (value != null)
- {
- // update last used ResourceSet
- if (_lastUsedResourceCache != null)
- {
- lock (_lastUsedResourceCache)
- {
- _lastUsedResourceCache.lastCultureName = currentCultureInfo.Name;
- _lastUsedResourceCache.lastResourceSet = rs;
- }
- }
- return value;
- }
-
- last = rs;
- }
- }
-
- return null;
- }
-
- // Looks up a resource value for a particular name. Looks in the
- // current thread's CultureInfo, and if not found, all parent CultureInfos.
- // Returns null if the resource wasn't found.
- //
- public virtual object? GetObject(string name)
- {
- return GetObject(name, null, true);
- }
-
- // Looks up a resource value for a particular name. Looks in the
- // specified CultureInfo, and if not found, all parent CultureInfos.
- // Returns null if the resource wasn't found.
- public virtual object? GetObject(string name, CultureInfo? culture)
- {
- return GetObject(name, culture, true);
- }
-
- private object? GetObject(string name, CultureInfo? culture, bool wrapUnmanagedMemStream)
- {
- if (null == name)
- throw new ArgumentNullException(nameof(name));
-
- if (null == culture)
- {
- culture = CultureInfo.CurrentUICulture;
- }
-
- ResourceSet? last = GetFirstResourceSet(culture);
- if (last != null)
- {
- object? value = last.GetObject(name, _ignoreCase);
-
- if (value != null)
- {
- if (value is UnmanagedMemoryStream stream && wrapUnmanagedMemStream)
- return new UnmanagedMemoryStreamWrapper(stream);
- else
- return value;
- }
- }
-
- // This is the CultureInfo hierarchy traversal code for resource
- // lookups, similar but necessarily orthogonal to the ResourceSet
- // lookup logic.
- ResourceFallbackManager mgr = new ResourceFallbackManager(culture, _neutralResourcesCulture, true);
-
- foreach (CultureInfo currentCultureInfo in mgr)
- {
- ResourceSet? rs = InternalGetResourceSet(currentCultureInfo, true, true);
- if (rs == null)
- break;
-
- if (rs != last)
- {
- object? value = rs.GetObject(name, _ignoreCase);
- if (value != null)
- {
- // update the last used ResourceSet
- if (_lastUsedResourceCache != null)
- {
- lock (_lastUsedResourceCache)
- {
- _lastUsedResourceCache.lastCultureName = currentCultureInfo.Name;
- _lastUsedResourceCache.lastResourceSet = rs;
- }
- }
-
- if (value is UnmanagedMemoryStream stream && wrapUnmanagedMemStream)
- return new UnmanagedMemoryStreamWrapper(stream);
- else
- return value;
- }
-
- last = rs;
- }
- }
-
- return null;
- }
-
- public UnmanagedMemoryStream? GetStream(string name)
- {
- return GetStream(name, null);
- }
-
- public UnmanagedMemoryStream? GetStream(string name, CultureInfo? culture)
- {
- object? obj = GetObject(name, culture, false);
- UnmanagedMemoryStream? ums = obj as UnmanagedMemoryStream;
- if (ums == null && obj != null)
- throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ResourceNotStream_Name, name));
- return ums;
- }
-
- internal class ResourceManagerMediator
- {
- private readonly ResourceManager _rm;
-
- internal ResourceManagerMediator(ResourceManager rm)
- {
- if (rm == null)
- {
- throw new ArgumentNullException(nameof(rm));
- }
- _rm = rm;
- }
-
- // NEEDED ONLY BY FILE-BASED
- internal string? ModuleDir => _rm._moduleDir;
-
- // NEEDED BOTH BY FILE-BASED AND ASSEMBLY-BASED
- internal Type? LocationInfo => _rm._locationInfo;
-
- internal Type? UserResourceSet => _rm._userResourceSet;
-
- internal string? BaseNameField => _rm.BaseNameField;
-
- internal CultureInfo? NeutralResourcesCulture
- {
- get => _rm._neutralResourcesCulture;
- set => _rm._neutralResourcesCulture = value;
- }
-
- internal string GetResourceFileName(CultureInfo culture) =>
- _rm.GetResourceFileName(culture);
-
- // NEEDED ONLY BY ASSEMBLY-BASED
- internal bool LookedForSatelliteContractVersion
- {
- get => _rm._lookedForSatelliteContractVersion;
- set => _rm._lookedForSatelliteContractVersion = value;
- }
-
- internal Version? SatelliteContractVersion
- {
- get => _rm._satelliteContractVersion;
- set => _rm._satelliteContractVersion = value;
- }
-
- internal static Version? ObtainSatelliteContractVersion(Assembly a) =>
- ResourceManager.GetSatelliteContractVersion(a);
-
- internal UltimateResourceFallbackLocation FallbackLoc
- {
- get => _rm.FallbackLocation;
- set => _rm._fallbackLoc = value;
- }
-
- internal Assembly? MainAssembly => _rm.MainAssembly;
-
- // this is weird because we have BaseNameField accessor above, but we're sticking
- // with it for compat.
- internal string BaseName => _rm.BaseName;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs b/netcore/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs
deleted file mode 100644
index d28976070f9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceReader.Core.cs
+++ /dev/null
@@ -1,169 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Reflection;
-using System.Text;
-using System.Threading;
-
-namespace System.Resources
-{
- public partial class ResourceReader
- {
- private readonly bool _permitDeserialization; // can deserialize BinaryFormatted resources
- private object? _binaryFormatter; // binary formatter instance to use for deserializing
-
- // statics used to dynamically call into BinaryFormatter
- // When successfully located s_binaryFormatterType will point to the BinaryFormatter type
- // and s_deserializeMethod will point to an unbound delegate to the deserialize method.
- private static Type? s_binaryFormatterType;
- private static Func<object?, Stream, object>? s_deserializeMethod;
-
- // This is the constructor the RuntimeResourceSet calls,
- // passing in the stream to read from and the RuntimeResourceSet's
- // internal hash table (hash table of names with file offsets
- // and values, coupled to this ResourceReader).
- internal ResourceReader(Stream stream, Dictionary<string, ResourceLocator> resCache, bool permitDeserialization)
- {
- Debug.Assert(stream != null, "Need a stream!");
- Debug.Assert(stream.CanRead, "Stream should be readable!");
- Debug.Assert(resCache != null, "Need a Dictionary!");
-
- _resCache = resCache;
- _store = new BinaryReader(stream, Encoding.UTF8);
-
- _ums = stream as UnmanagedMemoryStream;
-
- _permitDeserialization = permitDeserialization;
-
- ReadResources();
- }
-
- private object DeserializeObject(int typeIndex)
- {
- if (!_permitDeserialization)
- {
- throw new NotSupportedException(SR.NotSupported_ResourceObjectSerialization);
- }
-
- if (_binaryFormatter == null)
- {
- InitializeBinaryFormatter();
- }
-
- Type type = FindType(typeIndex);
-
- object graph = s_deserializeMethod!(_binaryFormatter, _store.BaseStream);
-
- // guard against corrupted resources
- if (graph.GetType() != type)
- throw new BadImageFormatException(SR.Format(SR.BadImageFormat_ResType_SerBlobMismatch, type.FullName, graph.GetType().FullName));
-
- return graph;
- }
-
- private void InitializeBinaryFormatter()
- {
- LazyInitializer.EnsureInitialized(ref s_binaryFormatterType, () =>
- Type.GetType("System.Runtime.Serialization.Formatters.Binary.BinaryFormatter, System.Runtime.Serialization.Formatters, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
- throwOnError: true)!);
-
- LazyInitializer.EnsureInitialized(ref s_deserializeMethod, () =>
- {
- MethodInfo binaryFormatterDeserialize = s_binaryFormatterType!.GetMethod("Deserialize", new Type[] { typeof(Stream) })!;
-
- // create an unbound delegate that can accept a BinaryFormatter instance as object
- return (Func<object?, Stream, object>)typeof(ResourceReader)
- .GetMethod(nameof(CreateUntypedDelegate), BindingFlags.NonPublic | BindingFlags.Static)!
- .MakeGenericMethod(s_binaryFormatterType)
- .Invoke(null, new object[] { binaryFormatterDeserialize })!;
- });
-
- _binaryFormatter = Activator.CreateInstance(s_binaryFormatterType!)!;
- }
-
- // generic method that we specialize at runtime once we've loaded the BinaryFormatter type
- // permits creating an unbound delegate so that we can avoid reflection after the initial
- // lightup code completes.
- private static Func<object, Stream, object> CreateUntypedDelegate<TInstance>(MethodInfo method)
- {
- Func<TInstance, Stream, object> typedDelegate = (Func<TInstance, Stream, object>)Delegate.CreateDelegate(typeof(Func<TInstance, Stream, object>), null, method);
-
- return (obj, stream) => typedDelegate((TInstance)obj, stream);
- }
-
- private static bool ValidateReaderType(string readerType)
- {
- return ResourceManager.IsDefaultType(readerType, ResourceManager.ResReaderTypeName);
- }
-
- public void GetResourceData(string resourceName, out string resourceType, out byte[] resourceData)
- {
- if (resourceName == null)
- throw new ArgumentNullException(nameof(resourceName));
- if (_resCache == null)
- throw new InvalidOperationException(SR.ResourceReaderIsClosed);
-
- // Get the type information from the data section. Also,
- // sort all of the data section's indexes to compute length of
- // the serialized data for this type (making sure to subtract
- // off the length of the type code).
- int[] sortedDataPositions = new int[_numResources];
- int dataPos = FindPosForResource(resourceName);
- if (dataPos == -1)
- {
- throw new ArgumentException(SR.Format(SR.Arg_ResourceNameNotExist, resourceName));
- }
-
- lock (this)
- {
- // Read all the positions of data within the data section.
- for (int i = 0; i < _numResources; i++)
- {
- _store.BaseStream.Position = _nameSectionOffset + GetNamePosition(i);
- // Skip over name of resource
- int numBytesToSkip = _store.Read7BitEncodedInt();
- if (numBytesToSkip < 0)
- {
- throw new FormatException(SR.Format(SR.BadImageFormat_ResourcesNameInvalidOffset, numBytesToSkip));
- }
- _store.BaseStream.Position += numBytesToSkip;
-
- int dPos = _store.ReadInt32();
- if (dPos < 0 || dPos >= _store.BaseStream.Length - _dataSectionOffset)
- {
- throw new FormatException(SR.Format(SR.BadImageFormat_ResourcesDataInvalidOffset, dPos));
- }
- sortedDataPositions[i] = dPos;
- }
- Array.Sort(sortedDataPositions);
-
- int index = Array.BinarySearch(sortedDataPositions, dataPos);
- Debug.Assert(index >= 0 && index < _numResources, "Couldn't find data position within sorted data positions array!");
- long nextData = (index < _numResources - 1) ? sortedDataPositions[index + 1] + _dataSectionOffset : _store.BaseStream.Length;
- int len = (int)(nextData - (dataPos + _dataSectionOffset));
- Debug.Assert(len >= 0 && len <= (int)_store.BaseStream.Length - dataPos + _dataSectionOffset, "Length was negative or outside the bounds of the file!");
-
- // Read type code then byte[]
- _store.BaseStream.Position = _dataSectionOffset + dataPos;
- ResourceTypeCode typeCode = (ResourceTypeCode)_store.Read7BitEncodedInt();
- if (typeCode < 0 || typeCode >= ResourceTypeCode.StartOfUserTypes + _typeTable.Length)
- {
- throw new BadImageFormatException(SR.BadImageFormat_InvalidType);
- }
- resourceType = TypeNameFromTypeCode(typeCode);
-
- // The length must be adjusted to subtract off the number
- // of bytes in the 7 bit encoded type code.
- len -= (int)(_store.BaseStream.Position - (_dataSectionOffset + dataPos));
- byte[] bytes = _store.ReadBytes(len);
- if (bytes.Length != len)
- throw new FormatException(SR.BadImageFormat_ResourceNameCorrupted);
- resourceData = bytes;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceReader.cs b/netcore/System.Private.CoreLib/shared/System/Resources/ResourceReader.cs
deleted file mode 100644
index 11abfc35272..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceReader.cs
+++ /dev/null
@@ -1,1094 +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.
-
-#nullable enable
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Text;
-
-namespace System.Resources
-#if RESOURCES_EXTENSIONS
- .Extensions
-#endif
-{
-#if RESOURCES_EXTENSIONS
- using ResourceReader = DeserializingResourceReader;
-#endif
-
- // Provides the default implementation of IResourceReader, reading
- // .resources file from the system default binary format. This class
- // can be treated as an enumerator once.
- //
- // See the RuntimeResourceSet overview for details on the system
- // default file format.
- //
-
- internal struct ResourceLocator
- {
- internal object? _value; // Can be null.
- internal int _dataPos;
-
- internal ResourceLocator(int dataPos, object? value)
- {
- _dataPos = dataPos;
- _value = value;
- }
-
- internal int DataPosition => _dataPos;
-
- // Allows adding in profiling data in a future version, or a special
- // resource profiling build. We could also use WeakReference.
- internal object? Value
- {
- get => _value;
- set => _value = value;
- }
-
- internal static bool CanCache(ResourceTypeCode value)
- {
- Debug.Assert(value >= 0, "negative ResourceTypeCode. What?");
- return value <= ResourceTypeCode.LastPrimitive;
- }
- }
-
- public sealed partial class
-#if RESOURCES_EXTENSIONS
- DeserializingResourceReader
-#else
- ResourceReader
-#endif
- : IResourceReader
- {
- // A reasonable default buffer size for reading from files, especially
- // when we will likely be seeking frequently. Could be smaller, but does
- // it make sense to use anything less than one page?
- private const int DefaultFileStreamBufferSize = 4096;
-
- private BinaryReader _store; // backing store we're reading from.
- // Used by RuntimeResourceSet and this class's enumerator. Maps
- // resource name to a value, a ResourceLocator, or a
- // LooselyLinkedManifestResource.
- internal Dictionary<string, ResourceLocator>? _resCache;
- private long _nameSectionOffset; // Offset to name section of file.
- private long _dataSectionOffset; // Offset to Data section of file.
-
- // Note this class is tightly coupled with UnmanagedMemoryStream.
- // At runtime when getting an embedded resource from an assembly,
- // we're given an UnmanagedMemoryStream referring to the mmap'ed portion
- // of the assembly. The pointers here are pointers into that block of
- // memory controlled by the OS's loader.
- private int[]? _nameHashes; // hash values for all names.
- private unsafe int* _nameHashesPtr; // In case we're using UnmanagedMemoryStream
- private int[]? _namePositions; // relative locations of names
- private unsafe int* _namePositionsPtr; // If we're using UnmanagedMemoryStream
- private Type?[] _typeTable = null!; // Lazy array of Types for resource values.
- private int[] _typeNamePositions = null!; // To delay initialize type table
- private int _numResources; // Num of resources files, in case arrays aren't allocated.
-
- // We'll include a separate code path that uses UnmanagedMemoryStream to
- // avoid allocating String objects and the like.
- private UnmanagedMemoryStream? _ums;
-
- // Version number of .resources file, for compatibility
- private int _version;
-
-
- public
-#if RESOURCES_EXTENSIONS
- DeserializingResourceReader(string fileName)
-#else
- ResourceReader(string fileName)
-#endif
- {
- _resCache = new Dictionary<string, ResourceLocator>(FastResourceComparer.Default);
- _store = new BinaryReader(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, DefaultFileStreamBufferSize, FileOptions.RandomAccess), Encoding.UTF8);
-
- try
- {
- ReadResources();
- }
- catch
- {
- _store.Close(); // If we threw an exception, close the file.
- throw;
- }
- }
-
- public
-#if RESOURCES_EXTENSIONS
- DeserializingResourceReader(Stream stream)
-#else
- ResourceReader(Stream stream)
-#endif
- {
- if (stream == null)
- throw new ArgumentNullException(nameof(stream));
- if (!stream.CanRead)
- throw new ArgumentException(SR.Argument_StreamNotReadable);
-
- _resCache = new Dictionary<string, ResourceLocator>(FastResourceComparer.Default);
- _store = new BinaryReader(stream, Encoding.UTF8);
- // We have a faster code path for reading resource files from an assembly.
- _ums = stream as UnmanagedMemoryStream;
-
- ReadResources();
- }
-
- public void Close()
- {
- Dispose(true);
- }
-
- public void Dispose()
- {
- Close();
- }
-
- private unsafe void Dispose(bool disposing)
- {
- if (_store != null)
- {
- _resCache = null;
- if (disposing)
- {
- // Close the stream in a thread-safe way. This fix means
- // that we may call Close n times, but that's safe.
- BinaryReader copyOfStore = _store;
- _store = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
- if (copyOfStore != null)
- copyOfStore.Close();
- }
- _store = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
- _namePositions = null;
- _nameHashes = null;
- _ums = null;
- _namePositionsPtr = null;
- _nameHashesPtr = null;
- }
- }
-
- internal static unsafe int ReadUnalignedI4(int* p)
- {
- byte* buffer = (byte*)p;
- // Unaligned, little endian format
- return buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
- }
-
-
- private void SkipString()
- {
- int stringLength = _store.Read7BitEncodedInt();
- if (stringLength < 0)
- {
- throw new BadImageFormatException(SR.BadImageFormat_NegativeStringLength);
- }
- _store.BaseStream.Seek(stringLength, SeekOrigin.Current);
- }
-
- private unsafe int GetNameHash(int index)
- {
- Debug.Assert(index >= 0 && index < _numResources, "Bad index into hash array. index: " + index);
-
- if (_ums == null)
- {
- Debug.Assert(_nameHashes != null && _nameHashesPtr == null, "Internal state mangled.");
- return _nameHashes[index];
- }
- else
- {
- Debug.Assert(_nameHashes == null && _nameHashesPtr != null, "Internal state mangled.");
- return ReadUnalignedI4(&_nameHashesPtr[index]);
- }
- }
-
- private unsafe int GetNamePosition(int index)
- {
- Debug.Assert(index >= 0 && index < _numResources, "Bad index into name position array. index: " + index);
- int r;
- if (_ums == null)
- {
- Debug.Assert(_namePositions != null && _namePositionsPtr == null, "Internal state mangled.");
- r = _namePositions[index];
- }
- else
- {
- Debug.Assert(_namePositions == null && _namePositionsPtr != null, "Internal state mangled.");
- r = ReadUnalignedI4(&_namePositionsPtr[index]);
- }
-
- if (r < 0 || r > _dataSectionOffset - _nameSectionOffset)
- {
- throw new FormatException(SR.Format(SR.BadImageFormat_ResourcesNameInvalidOffset, r));
- }
- return r;
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- public IDictionaryEnumerator GetEnumerator()
- {
- if (_resCache == null)
- throw new InvalidOperationException(SR.ResourceReaderIsClosed);
- return new ResourceEnumerator(this);
- }
-
- internal ResourceEnumerator GetEnumeratorInternal()
- {
- return new ResourceEnumerator(this);
- }
-
- // From a name, finds the associated virtual offset for the data.
- // To read the data, seek to _dataSectionOffset + dataPos, then
- // read the resource type & data.
- // This does a binary search through the names.
- internal int FindPosForResource(string name)
- {
- Debug.Assert(_store != null, "ResourceReader is closed!");
- int hash = FastResourceComparer.HashFunction(name);
-
- // Binary search over the hashes. Use the _namePositions array to
- // determine where they exist in the underlying stream.
- int lo = 0;
- int hi = _numResources - 1;
- int index = -1;
- bool success = false;
- while (lo <= hi)
- {
- index = (lo + hi) >> 1;
- // Do NOT use subtraction here, since it will wrap for large
- // negative numbers.
- int currentHash = GetNameHash(index);
- int c;
- if (currentHash == hash)
- c = 0;
- else if (currentHash < hash)
- c = -1;
- else
- c = 1;
-
- if (c == 0)
- {
- success = true;
- break;
- }
- if (c < 0)
- lo = index + 1;
- else
- hi = index - 1;
- }
- if (!success)
- {
- return -1;
- }
-
- // index is the location in our hash array that corresponds with a
- // value in the namePositions array.
- // There could be collisions in our hash function. Check on both sides
- // of index to find the range of hash values that are equal to the
- // target hash value.
- if (lo != index)
- {
- lo = index;
- while (lo > 0 && GetNameHash(lo - 1) == hash)
- lo--;
- }
- if (hi != index)
- {
- hi = index;
- while (hi < _numResources - 1 && GetNameHash(hi + 1) == hash)
- hi++;
- }
-
- lock (this)
- {
- for (int i = lo; i <= hi; i++)
- {
- _store.BaseStream.Seek(_nameSectionOffset + GetNamePosition(i), SeekOrigin.Begin);
- if (CompareStringEqualsName(name))
- {
- int dataPos = _store.ReadInt32();
- if (dataPos < 0 || dataPos >= _store.BaseStream.Length - _dataSectionOffset)
- {
- throw new FormatException(SR.Format(SR.BadImageFormat_ResourcesDataInvalidOffset, dataPos));
- }
- return dataPos;
- }
- }
- }
- return -1;
- }
-
- // This compares the String in the .resources file at the current position
- // with the string you pass in.
- // Whoever calls this method should make sure that they take a lock
- // so no one else can cause us to seek in the stream.
- private unsafe bool CompareStringEqualsName(string name)
- {
- Debug.Assert(_store != null, "ResourceReader is closed!");
- int byteLen = _store.Read7BitEncodedInt();
- if (byteLen < 0)
- {
- throw new BadImageFormatException(SR.BadImageFormat_NegativeStringLength);
- }
- if (_ums != null)
- {
- byte* bytes = _ums.PositionPointer;
- // Skip over the data in the Stream, positioning ourselves right after it.
- _ums.Seek(byteLen, SeekOrigin.Current);
- if (_ums.Position > _ums.Length)
- {
- throw new BadImageFormatException(SR.BadImageFormat_ResourcesNameTooLong);
- }
-
- // On 64-bit machines, these char*'s may be misaligned. Use a
- // byte-by-byte comparison instead.
- return FastResourceComparer.CompareOrdinal(bytes, byteLen, name) == 0;
- }
- else
- {
- // This code needs to be fast
- byte[] bytes = new byte[byteLen];
- int numBytesToRead = byteLen;
- while (numBytesToRead > 0)
- {
- int n = _store.Read(bytes, byteLen - numBytesToRead, numBytesToRead);
- if (n == 0)
- throw new BadImageFormatException(SR.BadImageFormat_ResourceNameCorrupted);
- numBytesToRead -= n;
- }
- return FastResourceComparer.CompareOrdinal(bytes, byteLen / 2, name) == 0;
- }
- }
-
- // This is used in the enumerator. The enumerator iterates from 0 to n
- // of our resources and this returns the resource name for a particular
- // index. The parameter is NOT a virtual offset.
- private unsafe string AllocateStringForNameIndex(int index, out int dataOffset)
- {
- Debug.Assert(_store != null, "ResourceReader is closed!");
- byte[] bytes;
- int byteLen;
- long nameVA = GetNamePosition(index);
- lock (this)
- {
- _store.BaseStream.Seek(nameVA + _nameSectionOffset, SeekOrigin.Begin);
- // Can't use _store.ReadString, since it's using UTF-8!
- byteLen = _store.Read7BitEncodedInt();
- if (byteLen < 0)
- {
- throw new BadImageFormatException(SR.BadImageFormat_NegativeStringLength);
- }
-
- if (_ums != null)
- {
- if (_ums.Position > _ums.Length - byteLen)
- throw new BadImageFormatException(SR.Format(SR.BadImageFormat_ResourcesIndexTooLong, index));
-
- string? s = null;
- char* charPtr = (char*)_ums.PositionPointer;
-
- s = new string(charPtr, 0, byteLen / 2);
-
- _ums.Position += byteLen;
- dataOffset = _store.ReadInt32();
- if (dataOffset < 0 || dataOffset >= _store.BaseStream.Length - _dataSectionOffset)
- {
- throw new FormatException(SR.Format(SR.BadImageFormat_ResourcesDataInvalidOffset, dataOffset));
- }
- return s;
- }
-
- bytes = new byte[byteLen];
- // We must read byteLen bytes, or we have a corrupted file.
- // Use a blocking read in case the stream doesn't give us back
- // everything immediately.
- int count = byteLen;
- while (count > 0)
- {
- int n = _store.Read(bytes, byteLen - count, count);
- if (n == 0)
- throw new EndOfStreamException(SR.Format(SR.BadImageFormat_ResourceNameCorrupted_NameIndex, index));
- count -= n;
- }
- dataOffset = _store.ReadInt32();
- if (dataOffset < 0 || dataOffset >= _store.BaseStream.Length - _dataSectionOffset)
- {
- throw new FormatException(SR.Format(SR.BadImageFormat_ResourcesDataInvalidOffset, dataOffset));
- }
- }
- return Encoding.Unicode.GetString(bytes, 0, byteLen);
- }
-
- // This is used in the enumerator. The enumerator iterates from 0 to n
- // of our resources and this returns the resource value for a particular
- // index. The parameter is NOT a virtual offset.
- private object? GetValueForNameIndex(int index)
- {
- Debug.Assert(_store != null, "ResourceReader is closed!");
- long nameVA = GetNamePosition(index);
- lock (this)
- {
- _store.BaseStream.Seek(nameVA + _nameSectionOffset, SeekOrigin.Begin);
- SkipString();
-
- int dataPos = _store.ReadInt32();
- if (dataPos < 0 || dataPos >= _store.BaseStream.Length - _dataSectionOffset)
- {
- throw new FormatException(SR.Format(SR.BadImageFormat_ResourcesDataInvalidOffset, dataPos));
- }
- ResourceTypeCode junk;
- if (_version == 1)
- return LoadObjectV1(dataPos);
- else
- return LoadObjectV2(dataPos, out junk);
- }
- }
-
- // This takes a virtual offset into the data section and reads a String
- // from that location.
- // Anyone who calls LoadObject should make sure they take a lock so
- // no one can cause us to do a seek in here.
- internal string? LoadString(int pos)
- {
- Debug.Assert(_store != null, "ResourceReader is closed!");
- _store.BaseStream.Seek(_dataSectionOffset + pos, SeekOrigin.Begin);
- string? s = null;
- int typeIndex = _store.Read7BitEncodedInt();
- if (_version == 1)
- {
- if (typeIndex == -1)
- return null;
- if (FindType(typeIndex) != typeof(string))
- throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ResourceNotString_Type, FindType(typeIndex).FullName));
- s = _store.ReadString();
- }
- else
- {
- ResourceTypeCode typeCode = (ResourceTypeCode)typeIndex;
- if (typeCode != ResourceTypeCode.String && typeCode != ResourceTypeCode.Null)
- {
- string? typeString;
- if (typeCode < ResourceTypeCode.StartOfUserTypes)
- typeString = typeCode.ToString();
- else
- typeString = FindType(typeCode - ResourceTypeCode.StartOfUserTypes).FullName;
- throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ResourceNotString_Type, typeString));
- }
- if (typeCode == ResourceTypeCode.String) // ignore Null
- s = _store.ReadString();
- }
- return s;
- }
-
- // Called from RuntimeResourceSet
- internal object? LoadObject(int pos)
- {
- if (_version == 1)
- return LoadObjectV1(pos);
- return LoadObjectV2(pos, out _);
- }
-
- internal object? LoadObject(int pos, out ResourceTypeCode typeCode)
- {
- if (_version == 1)
- {
- object? o = LoadObjectV1(pos);
- typeCode = (o is string) ? ResourceTypeCode.String : ResourceTypeCode.StartOfUserTypes;
- return o;
- }
- return LoadObjectV2(pos, out typeCode);
- }
-
- // This takes a virtual offset into the data section and reads an Object
- // from that location.
- // Anyone who calls LoadObject should make sure they take a lock so
- // no one can cause us to do a seek in here.
- internal object? LoadObjectV1(int pos)
- {
- Debug.Assert(_store != null, "ResourceReader is closed!");
- Debug.Assert(_version == 1, ".resources file was not a V1 .resources file!");
-
- try
- {
- // mega try-catch performs exceptionally bad on x64; factored out body into
- // _LoadObjectV1 and wrap here.
- return _LoadObjectV1(pos);
- }
- catch (EndOfStreamException eof)
- {
- throw new BadImageFormatException(SR.BadImageFormat_TypeMismatch, eof);
- }
- catch (ArgumentOutOfRangeException e)
- {
- throw new BadImageFormatException(SR.BadImageFormat_TypeMismatch, e);
- }
- }
-
- private object? _LoadObjectV1(int pos)
- {
- _store.BaseStream.Seek(_dataSectionOffset + pos, SeekOrigin.Begin);
- int typeIndex = _store.Read7BitEncodedInt();
- if (typeIndex == -1)
- return null;
- Type type = FindType(typeIndex);
- // Consider putting in logic to see if this type is a
- // primitive or a value type first, so we can reach the
- // deserialization code faster for arbitrary objects.
-
- if (type == typeof(string))
- return _store.ReadString();
- else if (type == typeof(int))
- return _store.ReadInt32();
- else if (type == typeof(byte))
- return _store.ReadByte();
- else if (type == typeof(sbyte))
- return _store.ReadSByte();
- else if (type == typeof(short))
- return _store.ReadInt16();
- else if (type == typeof(long))
- return _store.ReadInt64();
- else if (type == typeof(ushort))
- return _store.ReadUInt16();
- else if (type == typeof(uint))
- return _store.ReadUInt32();
- else if (type == typeof(ulong))
- return _store.ReadUInt64();
- else if (type == typeof(float))
- return _store.ReadSingle();
- else if (type == typeof(double))
- return _store.ReadDouble();
- else if (type == typeof(DateTime))
- {
- // Ideally we should use DateTime's ToBinary & FromBinary,
- // but we can't for compatibility reasons.
- return new DateTime(_store.ReadInt64());
- }
- else if (type == typeof(TimeSpan))
- return new TimeSpan(_store.ReadInt64());
- else if (type == typeof(decimal))
- {
- int[] bits = new int[4];
- for (int i = 0; i < bits.Length; i++)
- bits[i] = _store.ReadInt32();
- return new decimal(bits);
- }
- else
- {
- return DeserializeObject(typeIndex);
- }
- }
-
- internal object? LoadObjectV2(int pos, out ResourceTypeCode typeCode)
- {
- Debug.Assert(_store != null, "ResourceReader is closed!");
- Debug.Assert(_version >= 2, ".resources file was not a V2 (or higher) .resources file!");
-
- try
- {
- // mega try-catch performs exceptionally bad on x64; factored out body into
- // _LoadObjectV2 and wrap here.
- return _LoadObjectV2(pos, out typeCode);
- }
- catch (EndOfStreamException eof)
- {
- throw new BadImageFormatException(SR.BadImageFormat_TypeMismatch, eof);
- }
- catch (ArgumentOutOfRangeException e)
- {
- throw new BadImageFormatException(SR.BadImageFormat_TypeMismatch, e);
- }
- }
-
- private object? _LoadObjectV2(int pos, out ResourceTypeCode typeCode)
- {
- _store.BaseStream.Seek(_dataSectionOffset + pos, SeekOrigin.Begin);
- typeCode = (ResourceTypeCode)_store.Read7BitEncodedInt();
-
- switch (typeCode)
- {
- case ResourceTypeCode.Null:
- return null;
-
- case ResourceTypeCode.String:
- return _store.ReadString();
-
- case ResourceTypeCode.Boolean:
- return _store.ReadBoolean();
-
- case ResourceTypeCode.Char:
- return (char)_store.ReadUInt16();
-
- case ResourceTypeCode.Byte:
- return _store.ReadByte();
-
- case ResourceTypeCode.SByte:
- return _store.ReadSByte();
-
- case ResourceTypeCode.Int16:
- return _store.ReadInt16();
-
- case ResourceTypeCode.UInt16:
- return _store.ReadUInt16();
-
- case ResourceTypeCode.Int32:
- return _store.ReadInt32();
-
- case ResourceTypeCode.UInt32:
- return _store.ReadUInt32();
-
- case ResourceTypeCode.Int64:
- return _store.ReadInt64();
-
- case ResourceTypeCode.UInt64:
- return _store.ReadUInt64();
-
- case ResourceTypeCode.Single:
- return _store.ReadSingle();
-
- case ResourceTypeCode.Double:
- return _store.ReadDouble();
-
- case ResourceTypeCode.Decimal:
- return _store.ReadDecimal();
-
- case ResourceTypeCode.DateTime:
- // Use DateTime's ToBinary & FromBinary.
- long data = _store.ReadInt64();
- return DateTime.FromBinary(data);
-
- case ResourceTypeCode.TimeSpan:
- long ticks = _store.ReadInt64();
- return new TimeSpan(ticks);
-
- // Special types
- case ResourceTypeCode.ByteArray:
- {
- int len = _store.ReadInt32();
- if (len < 0)
- {
- throw new BadImageFormatException(SR.Format(SR.BadImageFormat_ResourceDataLengthInvalid, len));
- }
-
- if (_ums == null)
- {
- if (len > _store.BaseStream.Length)
- {
- throw new BadImageFormatException(SR.Format(SR.BadImageFormat_ResourceDataLengthInvalid, len));
- }
- return _store.ReadBytes(len);
- }
-
- if (len > _ums.Length - _ums.Position)
- {
- throw new BadImageFormatException(SR.Format(SR.BadImageFormat_ResourceDataLengthInvalid, len));
- }
-
- byte[] bytes = new byte[len];
- int r = _ums.Read(bytes, 0, len);
- Debug.Assert(r == len, "ResourceReader needs to use a blocking read here. (Call _store.ReadBytes(len)?)");
- return bytes;
- }
-
- case ResourceTypeCode.Stream:
- {
- int len = _store.ReadInt32();
- if (len < 0)
- {
- throw new BadImageFormatException(SR.Format(SR.BadImageFormat_ResourceDataLengthInvalid, len));
- }
- if (_ums == null)
- {
- byte[] bytes = _store.ReadBytes(len);
- // Lifetime of memory == lifetime of this stream.
- return new PinnedBufferMemoryStream(bytes);
- }
-
- // make sure we don't create an UnmanagedMemoryStream that is longer than the resource stream.
- if (len > _ums.Length - _ums.Position)
- {
- throw new BadImageFormatException(SR.Format(SR.BadImageFormat_ResourceDataLengthInvalid, len));
- }
-
- // For the case that we've memory mapped in the .resources
- // file, just return a Stream pointing to that block of memory.
- unsafe
- {
- return new UnmanagedMemoryStream(_ums.PositionPointer, len, len, FileAccess.Read);
- }
- }
-
- default:
- if (typeCode < ResourceTypeCode.StartOfUserTypes)
- {
- throw new BadImageFormatException(SR.BadImageFormat_TypeMismatch);
- }
- break;
- }
-
- // Normal serialized objects
- int typeIndex = typeCode - ResourceTypeCode.StartOfUserTypes;
- return DeserializeObject(typeIndex);
- }
-
- // Reads in the header information for a .resources file. Verifies some
- // of the assumptions about this resource set, and builds the class table
- // for the default resource file format.
- private void ReadResources()
- {
- Debug.Assert(_store != null, "ResourceReader is closed!");
-
- try
- {
- // mega try-catch performs exceptionally bad on x64; factored out body into
- // _ReadResources and wrap here.
- _ReadResources();
- }
- catch (EndOfStreamException eof)
- {
- throw new BadImageFormatException(SR.BadImageFormat_ResourcesHeaderCorrupted, eof);
- }
- catch (IndexOutOfRangeException e)
- {
- throw new BadImageFormatException(SR.BadImageFormat_ResourcesHeaderCorrupted, e);
- }
- }
-
- private void _ReadResources()
- {
- // Read ResourceManager header
- // Check for magic number
- int magicNum = _store.ReadInt32();
- if (magicNum != ResourceManager.MagicNumber)
- throw new ArgumentException(SR.Resources_StreamNotValid);
- // Assuming this is ResourceManager header V1 or greater, hopefully
- // after the version number there is a number of bytes to skip
- // to bypass the rest of the ResMgr header. For V2 or greater, we
- // use this to skip to the end of the header
- int resMgrHeaderVersion = _store.ReadInt32();
- int numBytesToSkip = _store.ReadInt32();
- if (numBytesToSkip < 0 || resMgrHeaderVersion < 0)
- {
- throw new BadImageFormatException(SR.BadImageFormat_ResourcesHeaderCorrupted);
- }
- if (resMgrHeaderVersion > 1)
- {
- _store.BaseStream.Seek(numBytesToSkip, SeekOrigin.Current);
- }
- else
- {
- // We don't care about numBytesToSkip; read the rest of the header
-
- // Read in type name for a suitable ResourceReader
- // Note ResourceWriter & InternalResGen use different Strings.
- string readerType = _store.ReadString();
-
- if (!ValidateReaderType(readerType))
- throw new NotSupportedException(SR.Format(SR.NotSupported_WrongResourceReader_Type, readerType));
-
- // Skip over type name for a suitable ResourceSet
- SkipString();
- }
-
- // Read RuntimeResourceSet header
- // Do file version check
- int version = _store.ReadInt32();
- if (version != RuntimeResourceSet.Version && version != 1)
- throw new ArgumentException(SR.Format(SR.Arg_ResourceFileUnsupportedVersion, RuntimeResourceSet.Version, version));
- _version = version;
-
- _numResources = _store.ReadInt32();
- if (_numResources < 0)
- {
- throw new BadImageFormatException(SR.BadImageFormat_ResourcesHeaderCorrupted);
- }
-
- // Read type positions into type positions array.
- // But delay initialize the type table.
- int numTypes = _store.ReadInt32();
- if (numTypes < 0)
- {
- throw new BadImageFormatException(SR.BadImageFormat_ResourcesHeaderCorrupted);
- }
- _typeTable = new Type[numTypes];
- _typeNamePositions = new int[numTypes];
- for (int i = 0; i < numTypes; i++)
- {
- _typeNamePositions[i] = (int)_store.BaseStream.Position;
-
- // Skip over the Strings in the file. Don't create types.
- SkipString();
- }
-
- // Prepare to read in the array of name hashes
- // Note that the name hashes array is aligned to 8 bytes so
- // we can use pointers into it on 64 bit machines. (4 bytes
- // may be sufficient, but let's plan for the future)
- // Skip over alignment stuff. All public .resources files
- // should be aligned No need to verify the byte values.
- long pos = _store.BaseStream.Position;
- int alignBytes = ((int)pos) & 7;
- if (alignBytes != 0)
- {
- for (int i = 0; i < 8 - alignBytes; i++)
- {
- _store.ReadByte();
- }
- }
-
- // Read in the array of name hashes
- if (_ums == null)
- {
- _nameHashes = new int[_numResources];
- for (int i = 0; i < _numResources; i++)
- {
- _nameHashes[i] = _store.ReadInt32();
- }
- }
- else
- {
- int seekPos = unchecked(4 * _numResources);
- if (seekPos < 0)
- {
- throw new BadImageFormatException(SR.BadImageFormat_ResourcesHeaderCorrupted);
- }
- unsafe
- {
- _nameHashesPtr = (int*)_ums.PositionPointer;
- // Skip over the array of nameHashes.
- _ums.Seek(seekPos, SeekOrigin.Current);
- // get the position pointer once more to check that the whole table is within the stream
- _ = _ums.PositionPointer;
- }
- }
-
- // Read in the array of relative positions for all the names.
- if (_ums == null)
- {
- _namePositions = new int[_numResources];
- for (int i = 0; i < _numResources; i++)
- {
- int namePosition = _store.ReadInt32();
- if (namePosition < 0)
- {
- throw new BadImageFormatException(SR.BadImageFormat_ResourcesHeaderCorrupted);
- }
-
- _namePositions[i] = namePosition;
- }
- }
- else
- {
- int seekPos = unchecked(4 * _numResources);
- if (seekPos < 0)
- {
- throw new BadImageFormatException(SR.BadImageFormat_ResourcesHeaderCorrupted);
- }
- unsafe
- {
- _namePositionsPtr = (int*)_ums.PositionPointer;
- // Skip over the array of namePositions.
- _ums.Seek(seekPos, SeekOrigin.Current);
- // get the position pointer once more to check that the whole table is within the stream
- _ = _ums.PositionPointer;
- }
- }
-
- // Read location of data section.
- _dataSectionOffset = _store.ReadInt32();
- if (_dataSectionOffset < 0)
- {
- throw new BadImageFormatException(SR.BadImageFormat_ResourcesHeaderCorrupted);
- }
-
- // Store current location as start of name section
- _nameSectionOffset = _store.BaseStream.Position;
-
- // _nameSectionOffset should be <= _dataSectionOffset; if not, it's corrupt
- if (_dataSectionOffset < _nameSectionOffset)
- {
- throw new BadImageFormatException(SR.BadImageFormat_ResourcesHeaderCorrupted);
- }
- }
-
- // This allows us to delay-initialize the Type[]. This might be a
- // good startup time savings, since we might have to load assemblies
- // and initialize Reflection.
- private Type FindType(int typeIndex)
- {
- if (typeIndex < 0 || typeIndex >= _typeTable.Length)
- {
- throw new BadImageFormatException(SR.BadImageFormat_InvalidType);
- }
- if (_typeTable[typeIndex] == null)
- {
- long oldPos = _store.BaseStream.Position;
- try
- {
- _store.BaseStream.Position = _typeNamePositions[typeIndex];
- string typeName = _store.ReadString();
- _typeTable[typeIndex] = Type.GetType(typeName, true);
- }
- // If serialization isn't supported, we convert FileNotFoundException to
- // NotSupportedException for consistency with v2. This is a corner-case, but the
- // idea is that we want to give the user a more accurate error message. Even if
- // the dependency were found, we know it will require serialization since it
- // can't be one of the types we special case. So if the dependency were found,
- // it would go down the serialization code path, resulting in NotSupported for
- // SKUs without serialization.
- //
- // We don't want to regress the expected case by checking the type info before
- // getting to Type.GetType -- this is costly with v1 resource formats.
- catch (FileNotFoundException)
- {
- throw new NotSupportedException(SR.NotSupported_ResourceObjectSerialization);
- }
- finally
- {
- _store.BaseStream.Position = oldPos;
- }
- }
- Debug.Assert(_typeTable[typeIndex] != null, "Should have found a type!");
- return _typeTable[typeIndex]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- }
-
- private string TypeNameFromTypeCode(ResourceTypeCode typeCode)
- {
- Debug.Assert(typeCode >= 0, "can't be negative");
- if (typeCode < ResourceTypeCode.StartOfUserTypes)
- {
- Debug.Assert(!string.Equals(typeCode.ToString(), "LastPrimitive"), "Change ResourceTypeCode metadata order so LastPrimitive isn't what Enum.ToString prefers.");
- return "ResourceTypeCode." + typeCode.ToString();
- }
- else
- {
- int typeIndex = typeCode - ResourceTypeCode.StartOfUserTypes;
- Debug.Assert(typeIndex >= 0 && typeIndex < _typeTable.Length, "TypeCode is broken or corrupted!");
- long oldPos = _store.BaseStream.Position;
- try
- {
- _store.BaseStream.Position = _typeNamePositions[typeIndex];
- return _store.ReadString();
- }
- finally
- {
- _store.BaseStream.Position = oldPos;
- }
- }
- }
-
- internal sealed class ResourceEnumerator : IDictionaryEnumerator
- {
- private const int ENUM_DONE = int.MinValue;
- private const int ENUM_NOT_STARTED = -1;
-
- private readonly ResourceReader _reader;
- private bool _currentIsValid;
- private int _currentName;
- private int _dataPosition; // cached for case-insensitive table
-
- internal ResourceEnumerator(ResourceReader reader)
- {
- _currentName = ENUM_NOT_STARTED;
- _reader = reader;
- _dataPosition = -2;
- }
-
- public bool MoveNext()
- {
- if (_currentName == _reader._numResources - 1 || _currentName == ENUM_DONE)
- {
- _currentIsValid = false;
- _currentName = ENUM_DONE;
- return false;
- }
- _currentIsValid = true;
- _currentName++;
- return true;
- }
-
- public object Key
- {
- get
- {
- if (_currentName == ENUM_DONE) throw new InvalidOperationException(SR.InvalidOperation_EnumEnded);
- if (!_currentIsValid) throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted);
- if (_reader._resCache == null) throw new InvalidOperationException(SR.ResourceReaderIsClosed);
-
- return _reader.AllocateStringForNameIndex(_currentName, out _dataPosition);
- }
- }
-
- public object Current => Entry;
-
- // Warning: This requires that you call the Key or Entry property FIRST before calling it!
- internal int DataPosition => _dataPosition;
-
- public DictionaryEntry Entry
- {
- get
- {
- if (_currentName == ENUM_DONE) throw new InvalidOperationException(SR.InvalidOperation_EnumEnded);
- if (!_currentIsValid) throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted);
- if (_reader._resCache == null) throw new InvalidOperationException(SR.ResourceReaderIsClosed);
-
- string key;
- object? value = null;
- lock (_reader)
- { // locks should be taken in the same order as in RuntimeResourceSet.GetObject to avoid deadlock
- lock (_reader._resCache)
- {
- key = _reader.AllocateStringForNameIndex(_currentName, out _dataPosition); // AllocateStringForNameIndex could lock on _reader
- ResourceLocator locator;
- if (_reader._resCache.TryGetValue(key, out locator))
- {
- value = locator.Value;
- }
- if (value == null)
- {
- if (_dataPosition == -1)
- value = _reader.GetValueForNameIndex(_currentName);
- else
- value = _reader.LoadObject(_dataPosition);
- // If enumeration and subsequent lookups happen very
- // frequently in the same process, add a ResourceLocator
- // to _resCache here. But WinForms enumerates and
- // just about everyone else does lookups. So caching
- // here may bloat working set.
- }
- }
- }
- return new DictionaryEntry(key, value);
- }
- }
-
- public object? Value
- {
- get
- {
- if (_currentName == ENUM_DONE) throw new InvalidOperationException(SR.InvalidOperation_EnumEnded);
- if (!_currentIsValid) throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted);
- if (_reader._resCache == null) throw new InvalidOperationException(SR.ResourceReaderIsClosed);
-
- // Consider using _resCache here, eventually, if
- // this proves to be an interesting perf scenario.
- // But mixing lookups and enumerators shouldn't be
- // particularly compelling.
- return _reader.GetValueForNameIndex(_currentName);
- }
- }
-
- public void Reset()
- {
- if (_reader._resCache == null) throw new InvalidOperationException(SR.ResourceReaderIsClosed);
- _currentIsValid = false;
- _currentName = ENUM_NOT_STARTED;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs b/netcore/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs
deleted file mode 100644
index 12cde70d0e6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs
+++ /dev/null
@@ -1,260 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: Culture-specific collection of resources.
-**
-**
-===========================================================*/
-
-using System.Collections;
-using System.Diagnostics;
-using System.IO;
-using System.Reflection;
-
-namespace System.Resources
-{
- // A ResourceSet stores all the resources defined in one particular CultureInfo.
- //
- // The method used to load resources is straightforward - this class
- // enumerates over an IResourceReader, loading every name and value, and
- // stores them in a hash table. Custom IResourceReaders can be used.
- //
- public class ResourceSet : IDisposable, IEnumerable
- {
- protected IResourceReader Reader = null!;
- internal Hashtable? Table; // TODO-NULLABLE: Avoid nulling out in Dispose
-
- private Hashtable? _caseInsensitiveTable; // For case-insensitive lookups.
-
- protected ResourceSet()
- {
- // To not inconvenience people subclassing us, we should allocate a new
- // hashtable here just so that Table is set to something.
- Table = new Hashtable();
- }
-
- // For RuntimeResourceSet, ignore the Table parameter - it's a wasted
- // allocation.
- internal ResourceSet(bool junk)
- {
- }
-
- // Creates a ResourceSet using the system default ResourceReader
- // implementation. Use this constructor to open & read from a file
- // on disk.
- //
- public ResourceSet(string fileName)
- : this()
- {
- Reader = new ResourceReader(fileName);
- ReadResources();
- }
-
- // Creates a ResourceSet using the system default ResourceReader
- // implementation. Use this constructor to read from an open stream
- // of data.
- //
- public ResourceSet(Stream stream)
- : this()
- {
- Reader = new ResourceReader(stream);
- ReadResources();
- }
-
- public ResourceSet(IResourceReader reader)
- : this()
- {
- if (reader == null)
- throw new ArgumentNullException(nameof(reader));
- Reader = reader;
- ReadResources();
- }
-
- // Closes and releases any resources used by this ResourceSet, if any.
- // All calls to methods on the ResourceSet after a call to close may
- // fail. Close is guaranteed to be safely callable multiple times on a
- // particular ResourceSet, and all subclasses must support these semantics.
- public virtual void Close()
- {
- Dispose(true);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
- // Close the Reader in a thread-safe way.
- IResourceReader? copyOfReader = Reader;
- Reader = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
- if (copyOfReader != null)
- copyOfReader.Close();
- }
- Reader = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
- _caseInsensitiveTable = null;
- Table = null;
- }
-
- public void Dispose()
- {
- Dispose(true);
- }
-
- // Returns the preferred IResourceReader class for this kind of ResourceSet.
- // Subclasses of ResourceSet using their own Readers &; should override
- // GetDefaultReader and GetDefaultWriter.
- public virtual Type GetDefaultReader()
- {
- return typeof(ResourceReader);
- }
-
- // Returns the preferred IResourceWriter class for this kind of ResourceSet.
- // Subclasses of ResourceSet using their own Readers &; should override
- // GetDefaultReader and GetDefaultWriter.
- public virtual Type GetDefaultWriter()
- {
- Assembly resourceWriterAssembly = Assembly.Load("System.Resources.Writer, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
- return resourceWriterAssembly.GetType("System.Resources.ResourceWriter", throwOnError: true)!;
- }
-
- public virtual IDictionaryEnumerator GetEnumerator()
- {
- return GetEnumeratorHelper();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumeratorHelper();
- }
-
- private IDictionaryEnumerator GetEnumeratorHelper()
- {
- Hashtable? copyOfTable = Table; // Avoid a race with Dispose
- if (copyOfTable == null)
- throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
- return copyOfTable.GetEnumerator();
- }
-
- // Look up a string value for a resource given its name.
- //
- public virtual string? GetString(string name)
- {
- object? obj = GetObjectInternal(name);
- try
- {
- return (string?)obj;
- }
- catch (InvalidCastException)
- {
- throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ResourceNotString_Name, name));
- }
- }
-
- public virtual string? GetString(string name, bool ignoreCase)
- {
- object? obj;
- string? s;
-
- // Case-sensitive lookup
- obj = GetObjectInternal(name);
- try
- {
- s = (string?)obj;
- }
- catch (InvalidCastException)
- {
- throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ResourceNotString_Name, name));
- }
-
- // case-sensitive lookup succeeded
- if (s != null || !ignoreCase)
- {
- return s;
- }
-
- // Try doing a case-insensitive lookup
- obj = GetCaseInsensitiveObjectInternal(name);
- try
- {
- return (string?)obj;
- }
- catch (InvalidCastException)
- {
- throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ResourceNotString_Name, name));
- }
- }
-
- // Look up an object value for a resource given its name.
- //
- public virtual object? GetObject(string name)
- {
- return GetObjectInternal(name);
- }
-
- public virtual object? GetObject(string name, bool ignoreCase)
- {
- object? obj = GetObjectInternal(name);
-
- if (obj != null || !ignoreCase)
- return obj;
-
- return GetCaseInsensitiveObjectInternal(name);
- }
-
- protected virtual void ReadResources()
- {
- Debug.Assert(Table != null);
- Debug.Assert(Reader != null);
- IDictionaryEnumerator en = Reader.GetEnumerator();
- while (en.MoveNext())
- {
- object? value = en.Value;
- Table.Add(en.Key, value);
- }
- // While technically possible to close the Reader here, don't close it
- // to help with some WinRes lifetime issues.
- }
-
- private object? GetObjectInternal(string name)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- Hashtable? copyOfTable = Table; // Avoid a race with Dispose
-
- if (copyOfTable == null)
- throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
-
- return copyOfTable[name];
- }
-
- private object? GetCaseInsensitiveObjectInternal(string name)
- {
- Hashtable? copyOfTable = Table; // Avoid a race with Dispose
-
- if (copyOfTable == null)
- throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
-
- Hashtable? caseTable = _caseInsensitiveTable; // Avoid a race condition with Close
- if (caseTable == null)
- {
- caseTable = new Hashtable(StringComparer.OrdinalIgnoreCase);
-
- IDictionaryEnumerator en = copyOfTable.GetEnumerator();
- while (en.MoveNext())
- {
- caseTable.Add(en.Key, en.Value);
- }
- _caseInsensitiveTable = caseTable;
- }
-
- return caseTable[name];
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceTypeCode.cs b/netcore/System.Private.CoreLib/shared/System/Resources/ResourceTypeCode.cs
deleted file mode 100644
index e0fc10f46dd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/ResourceTypeCode.cs
+++ /dev/null
@@ -1,47 +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.
-
-namespace System.Resources
-{
- /* An internal implementation detail for .resources files, describing
- what type an object is.
- Ranges:
- 0 - 0x1F Primitives and reserved values
- 0x20 - 0x3F Specially recognized types, like byte[] and Streams
-
- Note this data must be included in any documentation describing the
- internals of .resources files.
- */
- internal enum ResourceTypeCode
- {
- // Primitives
- Null = 0,
- String = 1,
- Boolean = 2,
- Char = 3,
- Byte = 4,
- SByte = 5,
- Int16 = 6,
- UInt16 = 7,
- Int32 = 8,
- UInt32 = 9,
- Int64 = 0xa,
- UInt64 = 0xb,
- Single = 0xc,
- Double = 0xd,
- Decimal = 0xe,
- DateTime = 0xf,
- TimeSpan = 0x10,
-
- // A meta-value - change this if you add new primitives
- LastPrimitive = TimeSpan,
-
- // Types with a special representation, like byte[] and Stream
- ByteArray = 0x20,
- Stream = 0x21,
-
- // User types - serialized using the binary formatter.
- StartOfUserTypes = 0x40
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs b/netcore/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs
deleted file mode 100644
index 76d1d4aac2b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs
+++ /dev/null
@@ -1,464 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: CultureInfo-specific collection of resources.
-**
-**
-===========================================================*/
-
-#nullable enable
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-
-namespace System.Resources
-#if RESOURCES_EXTENSIONS
- .Extensions
-#endif
-{
-#if RESOURCES_EXTENSIONS
- using ResourceReader = DeserializingResourceReader;
-#endif
- // A RuntimeResourceSet stores all the resources defined in one
- // particular CultureInfo, with some loading optimizations.
- //
- // It is expected that nearly all the runtime's users will be satisfied with the
- // default resource file format, and it will be more efficient than most simple
- // implementations. Users who would consider creating their own ResourceSets and/or
- // ResourceReaders and ResourceWriters are people who have to interop with a
- // legacy resource file format, are creating their own resource file format
- // (using XML, for instance), or require doing resource lookups at runtime over
- // the network. This group will hopefully be small, but all the infrastructure
- // should be in place to let these users write & plug in their own tools.
- //
- // The Default Resource File Format
- //
- // The fundamental problems addressed by the resource file format are:
- //
- // * Versioning - A ResourceReader could in theory support many different
- // file format revisions.
- // * Storing intrinsic datatypes (ie, ints, Strings, DateTimes, etc) in a compact
- // format
- // * Support for user-defined classes - Accomplished using Serialization
- // * Resource lookups should not require loading an entire resource file - If you
- // look up a resource, we only load the value for that resource, minimizing working set.
- //
- //
- // There are four sections to the default file format. The first
- // is the Resource Manager header, which consists of a magic number
- // that identifies this as a Resource file, and a ResourceSet class name.
- // The class name is written here to allow users to provide their own
- // implementation of a ResourceSet (and a matching ResourceReader) to
- // control policy. If objects greater than a certain size or matching a
- // certain naming scheme shouldn't be stored in memory, users can tweak that
- // with their own subclass of ResourceSet.
- //
- // The second section in the system default file format is the
- // RuntimeResourceSet specific header. This contains a version number for
- // the .resources file, the number of resources in this file, the number of
- // different types contained in the file, followed by a list of fully
- // qualified type names. After this, we include an array of hash values for
- // each resource name, then an array of virtual offsets into the name section
- // of the file. The hashes allow us to do a binary search on an array of
- // integers to find a resource name very quickly without doing many string
- // compares (except for once we find the real type, of course). If a hash
- // matches, the index into the array of hash values is used as the index
- // into the name position array to find the name of the resource. The type
- // table allows us to read multiple different classes from the same file,
- // including user-defined types, in a more efficient way than using
- // Serialization, at least when your .resources file contains a reasonable
- // proportion of base data types such as Strings or ints. We use
- // Serialization for all the non-instrinsic types.
- //
- // The third section of the file is the name section. It contains a
- // series of resource names, written out as byte-length prefixed little
- // endian Unicode strings (UTF-16). After each name is a four byte virtual
- // offset into the data section of the file, pointing to the relevant
- // string or serialized blob for this resource name.
- //
- // The fourth section in the file is the data section, which consists
- // of a type and a blob of bytes for each item in the file. The type is
- // an integer index into the type table. The data is specific to that type,
- // but may be a number written in binary format, a String, or a serialized
- // Object.
- //
- // The system default file format (V1) is as follows:
- //
- // What Type of Data
- // ==================================================== ===========
- //
- // Resource Manager header
- // Magic Number (0xBEEFCACE) Int32
- // Resource Manager header version Int32
- // Num bytes to skip from here to get past this header Int32
- // Class name of IResourceReader to parse this file String
- // Class name of ResourceSet to parse this file String
- //
- // RuntimeResourceReader header
- // ResourceReader version number Int32
- // [Only in debug V2 builds - "***DEBUG***"] String
- // Number of resources in the file Int32
- // Number of types in the type table Int32
- // Name of each type Set of Strings
- // Padding bytes for 8-byte alignment (use PAD) Bytes (0-7)
- // Hash values for each resource name Int32 array, sorted
- // Virtual offset of each resource name Int32 array, coupled with hash values
- // Absolute location of Data section Int32
- //
- // RuntimeResourceReader Name Section
- // Name & virtual offset of each resource Set of (UTF-16 String, Int32) pairs
- //
- // RuntimeResourceReader Data Section
- // Type and Value of each resource Set of (Int32, blob of bytes) pairs
- //
- // This implementation, when used with the default ResourceReader class,
- // loads only the strings that you look up for. It can do string comparisons
- // without having to create a new String instance due to some memory mapped
- // file optimizations in the ResourceReader and FastResourceComparer
- // classes. This keeps the memory we touch to a minimum when loading
- // resources.
- //
- // If you use a different IResourceReader class to read a file, or if you
- // do case-insensitive lookups (and the case-sensitive lookup fails) then
- // we will load all the names of each resource and each resource value.
- // This could probably use some optimization.
- //
- // In addition, this supports object serialization in a similar fashion.
- // We build an array of class types contained in this file, and write it
- // to RuntimeResourceReader header section of the file. Every resource
- // will contain its type (as an index into the array of classes) with the data
- // for that resource. We will use the Runtime's serialization support for this.
- //
- // All strings in the file format are written with BinaryReader and
- // BinaryWriter, which writes out the length of the String in bytes as an
- // Int32 then the contents as Unicode chars encoded in UTF-8. In the name
- // table though, each resource name is written in UTF-16 so we can do a
- // string compare byte by byte against the contents of the file, without
- // allocating objects. Ideally we'd have a way of comparing UTF-8 bytes
- // directly against a String object, but that may be a lot of work.
- //
- // The offsets of each resource string are relative to the beginning
- // of the Data section of the file. This way, if a tool decided to add
- // one resource to a file, it would only need to increment the number of
- // resources, add the hash &amp; location of last byte in the name section
- // to the array of resource hashes and resource name positions (carefully
- // keeping these arrays sorted), add the name to the end of the name &amp;
- // offset list, possibly add the type list of types (and increase
- // the number of items in the type table), and add the resource value at
- // the end of the file. The other offsets wouldn't need to be updated to
- // reflect the longer header section.
- //
- // Resource files are currently limited to 2 gigabytes due to these
- // design parameters. A future version may raise the limit to 4 gigabytes
- // by using unsigned integers, or may use negative numbers to load items
- // out of an assembly manifest. Also, we may try sectioning the resource names
- // into smaller chunks, each of size sqrt(n), would be substantially better for
- // resource files containing thousands of resources.
- //
-#if CORERT
- public // On CoreRT, this must be public because of need to whitelist past the ReflectionBlock.
-#else
- internal
-#endif
- sealed class RuntimeResourceSet : ResourceSet, IEnumerable
- {
- internal const int Version = 2; // File format version number
-
- // Cache for resources. Key is the resource name, which can be cached
- // for arbitrarily long times, since the object is usually a string
- // literal that will live for the lifetime of the appdomain. The
- // value is a ResourceLocator instance, which might cache the object.
- private Dictionary<string, ResourceLocator>? _resCache; // TODO-NULLABLE: Avoid nulling out in Dispose
-
-
- // For our special load-on-demand reader, cache the cast. The
- // RuntimeResourceSet's implementation knows how to treat this reader specially.
- private ResourceReader? _defaultReader; // TODO-NULLABLE: Avoid nulling out in Dispose
-
- // This is a lookup table for case-insensitive lookups, and may be null.
- // Consider always using a case-insensitive resource cache, as we don't
- // want to fill this out if we can avoid it. The problem is resource
- // fallback will somewhat regularly cause us to look up resources that
- // don't exist.
- private Dictionary<string, ResourceLocator>? _caseInsensitiveTable;
-
- // If we're not using our custom reader, then enumerate through all
- // the resources once, adding them into the table.
- private bool _haveReadFromReader;
-
-#if !RESOURCES_EXTENSIONS
- internal RuntimeResourceSet(string fileName) : base(false)
- {
- _resCache = new Dictionary<string, ResourceLocator>(FastResourceComparer.Default);
- Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
- _defaultReader = new ResourceReader(stream, _resCache, false);
- Reader = _defaultReader;
- }
-
- internal RuntimeResourceSet(Stream stream, bool permitDeserialization = false) : base(false)
- {
- _resCache = new Dictionary<string, ResourceLocator>(FastResourceComparer.Default);
- _defaultReader = new ResourceReader(stream, _resCache, permitDeserialization);
- Reader = _defaultReader;
- }
-#else
- private IResourceReader Reader => _defaultReader!;
-
- internal RuntimeResourceSet(IResourceReader reader) :
- // explicitly do not call IResourceReader constructor since it caches all resources
- // the purpose of RuntimeResourceSet is to lazily load and cache.
- base()
- {
- if (reader == null)
- throw new ArgumentNullException(nameof(reader));
-
- _defaultReader = reader as DeserializingResourceReader ?? throw new ArgumentException(SR.Format(SR.NotSupported_WrongResourceReader_Type, reader.GetType()), nameof(reader));
- _resCache = new Dictionary<string, ResourceLocator>(FastResourceComparer.Default);
-
- // in the CoreLib version RuntimeResourceSet creates ResourceReader and passes this in,
- // in the custom case ManifestBasedResourceReader creates the ResourceReader and passes it in
- // so we must initialize the cache here.
- _defaultReader._resCache = _resCache;
- }
-#endif
-
- protected override void Dispose(bool disposing)
- {
- if (Reader == null)
- return;
-
- if (disposing)
- {
- lock (Reader)
- {
- _resCache = null;
- if (_defaultReader != null)
- {
- _defaultReader.Close();
- _defaultReader = null;
- }
- _caseInsensitiveTable = null;
- // Set Reader to null to avoid a race in GetObject.
- base.Dispose(disposing);
- }
- }
- else
- {
- // Just to make sure we always clear these fields in the future...
- _resCache = null;
- _caseInsensitiveTable = null;
- _defaultReader = null;
- base.Dispose(disposing);
- }
- }
-
- public override IDictionaryEnumerator GetEnumerator()
- {
- return GetEnumeratorHelper();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumeratorHelper();
- }
-
- private IDictionaryEnumerator GetEnumeratorHelper()
- {
- IResourceReader copyOfReader = Reader;
- if (copyOfReader == null || _resCache == null)
- throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
-
- return copyOfReader.GetEnumerator();
- }
-
-
- public override string? GetString(string key)
- {
- object? o = GetObject(key, false, true);
- return (string?)o;
- }
-
- public override string? GetString(string key, bool ignoreCase)
- {
- object? o = GetObject(key, ignoreCase, true);
- return (string?)o;
- }
-
- public override object? GetObject(string key)
- {
- return GetObject(key, false, false);
- }
-
- public override object? GetObject(string key, bool ignoreCase)
- {
- return GetObject(key, ignoreCase, false);
- }
-
- private object? GetObject(string key, bool ignoreCase, bool isString)
- {
- if (key == null)
- throw new ArgumentNullException(nameof(key));
- if (Reader == null || _resCache == null)
- throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
-
- object? value = null;
- ResourceLocator resLocation;
-
- lock (Reader)
- {
- if (Reader == null)
- throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);
-
- if (_defaultReader != null)
- {
- // Find the offset within the data section
- int dataPos = -1;
- if (_resCache.TryGetValue(key, out resLocation))
- {
- value = resLocation.Value;
- dataPos = resLocation.DataPosition;
- }
-
- if (dataPos == -1 && value == null)
- {
- dataPos = _defaultReader.FindPosForResource(key);
- }
-
- if (dataPos != -1 && value == null)
- {
- Debug.Assert(dataPos >= 0, "data section offset cannot be negative!");
- // Normally calling LoadString or LoadObject requires
- // taking a lock. Note that in this case, we took a
- // lock on the entire RuntimeResourceSet, which is
- // sufficient since we never pass this ResourceReader
- // to anyone else.
- ResourceTypeCode typeCode;
- if (isString)
- {
- value = _defaultReader.LoadString(dataPos);
- typeCode = ResourceTypeCode.String;
- }
- else
- {
- value = _defaultReader.LoadObject(dataPos, out typeCode);
- }
-
- resLocation = new ResourceLocator(dataPos, (ResourceLocator.CanCache(typeCode)) ? value : null);
- lock (_resCache)
- {
- _resCache[key] = resLocation;
- }
- }
-
- if (value != null || !ignoreCase)
- {
- return value; // may be null
- }
- } // if (_defaultReader != null)
-
- // At this point, we either don't have our default resource reader
- // or we haven't found the particular resource we're looking for
- // and may have to search for it in a case-insensitive way.
- if (!_haveReadFromReader)
- {
- // If necessary, init our case insensitive hash table.
- if (ignoreCase)
- {
- _caseInsensitiveTable ??= new Dictionary<string, ResourceLocator>(StringComparer.OrdinalIgnoreCase);
- }
-
- if (_defaultReader == null)
- {
- IDictionaryEnumerator en = Reader.GetEnumerator();
- while (en.MoveNext())
- {
- DictionaryEntry entry = en.Entry;
- string readKey = (string)entry.Key;
- ResourceLocator resLoc = new ResourceLocator(-1, entry.Value);
- _resCache.Add(readKey, resLoc);
- if (ignoreCase)
- {
- Debug.Assert(_caseInsensitiveTable != null);
- _caseInsensitiveTable.Add(readKey, resLoc);
- }
- }
- // Only close the reader if it is NOT our default one,
- // since we need it around to resolve ResourceLocators.
- if (!ignoreCase)
- Reader.Close();
- }
- else
- {
- Debug.Assert(ignoreCase, "This should only happen for case-insensitive lookups");
- Debug.Assert(_caseInsensitiveTable != null);
- ResourceReader.ResourceEnumerator en = _defaultReader.GetEnumeratorInternal();
- while (en.MoveNext())
- {
- // Note: Always ask for the resource key before the data position.
- string currentKey = (string)en.Key;
- int dataPos = en.DataPosition;
- ResourceLocator resLoc = new ResourceLocator(dataPos, null);
- _caseInsensitiveTable.Add(currentKey, resLoc);
- }
- }
- _haveReadFromReader = true;
- }
- object? obj = null;
- bool found = false;
- bool keyInWrongCase = false;
- if (_defaultReader != null)
- {
- if (_resCache.TryGetValue(key, out resLocation))
- {
- found = true;
- obj = ResolveResourceLocator(resLocation, key, _resCache, keyInWrongCase);
- }
- }
- if (!found && ignoreCase)
- {
- Debug.Assert(_caseInsensitiveTable != null);
- if (_caseInsensitiveTable.TryGetValue(key, out resLocation))
- {
- found = true;
- keyInWrongCase = true;
- obj = ResolveResourceLocator(resLocation, key, _resCache, keyInWrongCase);
- }
- }
- return obj;
- } // lock(Reader)
- }
-
- // The last parameter indicates whether the lookup required a
- // case-insensitive lookup to succeed, indicating we shouldn't add
- // the ResourceLocation to our case-sensitive cache.
- private object? ResolveResourceLocator(ResourceLocator resLocation, string key, Dictionary<string, ResourceLocator> copyOfCache, bool keyInWrongCase)
- {
- // We need to explicitly resolve loosely linked manifest
- // resources, and we need to resolve ResourceLocators with null objects.
- object? value = resLocation.Value;
- if (value == null)
- {
- ResourceTypeCode typeCode;
- lock (Reader)
- {
- Debug.Assert(_defaultReader != null);
- value = _defaultReader.LoadObject(resLocation.DataPosition, out typeCode);
- }
- if (!keyInWrongCase && ResourceLocator.CanCache(typeCode))
- {
- resLocation.Value = value;
- copyOfCache[key] = resLocation;
- }
- }
- return value;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/SatelliteContractVersionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Resources/SatelliteContractVersionAttribute.cs
deleted file mode 100644
index 0ffeef96188..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/SatelliteContractVersionAttribute.cs
+++ /dev/null
@@ -1,31 +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.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: Specifies which version of a satellite assembly
-** the ResourceManager should ask for.
-**
-**
-===========================================================*/
-
-namespace System.Resources
-{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
- public sealed class SatelliteContractVersionAttribute : Attribute
- {
- public SatelliteContractVersionAttribute(string version)
- {
- if (version == null)
- throw new ArgumentNullException(nameof(version));
- Version = version;
- }
-
- public string Version { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Resources/UltimateResourceFallbackLocation.cs b/netcore/System.Private.CoreLib/shared/System/Resources/UltimateResourceFallbackLocation.cs
deleted file mode 100644
index b390cc24c51..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Resources/UltimateResourceFallbackLocation.cs
+++ /dev/null
@@ -1,23 +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.
-
-/*============================================================
-**
-**
-**
-**
-** Purpose: Tells the ResourceManager where to find the
-** ultimate fallback resources for your assembly.
-**
-**
-===========================================================*/
-
-namespace System.Resources
-{
- public enum UltimateResourceFallbackLocation
- {
- MainAssembly,
- Satellite
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/AmbiguousImplementationException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/AmbiguousImplementationException.cs
deleted file mode 100644
index 90f3d44f63d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/AmbiguousImplementationException.cs
+++ /dev/null
@@ -1,36 +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 System.Runtime.Serialization;
-
-namespace System.Runtime
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
- public sealed class AmbiguousImplementationException : Exception
- {
- public AmbiguousImplementationException()
- : base(SR.AmbiguousImplementationException_NullMessage)
- {
- HResult = HResults.COR_E_AMBIGUOUSIMPLEMENTATION;
- }
-
- public AmbiguousImplementationException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_AMBIGUOUSIMPLEMENTATION;
- }
-
- public AmbiguousImplementationException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_AMBIGUOUSIMPLEMENTATION;
- }
-
- private AmbiguousImplementationException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AccessedThroughPropertyAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AccessedThroughPropertyAttribute.cs
deleted file mode 100644
index 25efcafa3fd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AccessedThroughPropertyAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Field)]
- public sealed class AccessedThroughPropertyAttribute : Attribute
- {
- public AccessedThroughPropertyAttribute(string propertyName)
- {
- PropertyName = propertyName;
- }
-
- public string PropertyName { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncIteratorMethodBuilder.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncIteratorMethodBuilder.cs
deleted file mode 100644
index 4c4e2ebc05a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncIteratorMethodBuilder.cs
+++ /dev/null
@@ -1,66 +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 System.Runtime.InteropServices;
-using System.Threading;
-
-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() =>
- // _methodBuilder should be initialized to AsyncTaskMethodBuilder.Create(), but on coreclr
- // that Create() is a nop, so we can just return the default here.
- default;
-
- /// <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 =>
- AsyncMethodBuilderCore.Start(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 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;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncIteratorStateMachineAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncIteratorStateMachineAttribute.cs
deleted file mode 100644
index 489195569de..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncIteratorStateMachineAttribute.cs
+++ /dev/null
@@ -1,18 +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.
-
-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)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilderAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilderAttribute.cs
deleted file mode 100644
index 688a3a01ba7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilderAttribute.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Indicates the type of the async method builder that should be used by a language compiler to
- /// build the attributed type when used as the return type of an async method.
- /// </summary>
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Delegate | AttributeTargets.Enum, Inherited = false, AllowMultiple = false)]
- public sealed class AsyncMethodBuilderAttribute : Attribute
- {
- /// <summary>Initializes the <see cref="AsyncMethodBuilderAttribute"/>.</summary>
- /// <param name="builderType">The <see cref="Type"/> of the associated builder.</param>
- public AsyncMethodBuilderAttribute(Type builderType) => BuilderType = builderType;
-
- /// <summary>Gets the <see cref="Type"/> of the associated builder.</summary>
- public Type BuilderType { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs
deleted file mode 100644
index f8aad2f0178..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs
+++ /dev/null
@@ -1,158 +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 System.Diagnostics;
-using System.Diagnostics.Tracing;
-using System.Reflection;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Text;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>Shared helpers for manipulating state related to async state machines.</summary>
- internal static class AsyncMethodBuilderCore // debugger depends on this exact name
- {
- /// <summary>Initiates the builder's execution with the associated state machine.</summary>
- /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
- /// <param name="stateMachine">The state machine instance, passed by reference.</param>
- [DebuggerStepThrough]
- public static void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
- {
- if (stateMachine == null) // TStateMachines are generally non-nullable value types, so this check will be elided
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.stateMachine);
- }
-
- // enregistrer variables with 0 post-fix so they can be used in registers without EH forcing them to stack
- // Capture references to Thread Contexts
- Thread currentThread0 = Thread.CurrentThread;
- Thread currentThread = currentThread0;
- ExecutionContext? previousExecutionCtx0 = currentThread0._executionContext;
-
- // Store current ExecutionContext and SynchronizationContext as "previousXxx".
- // This allows us to restore them and undo any Context changes made in stateMachine.MoveNext
- // so that they won't "leak" out of the first await.
- ExecutionContext? previousExecutionCtx = previousExecutionCtx0;
- SynchronizationContext? previousSyncCtx = currentThread0._synchronizationContext;
-
- try
- {
- stateMachine.MoveNext();
- }
- finally
- {
- // Re-enregistrer variables post EH with 1 post-fix so they can be used in registers rather than from stack
- SynchronizationContext? previousSyncCtx1 = previousSyncCtx;
- Thread currentThread1 = currentThread;
- // The common case is that these have not changed, so avoid the cost of a write barrier if not needed.
- if (previousSyncCtx1 != currentThread1._synchronizationContext)
- {
- // Restore changed SynchronizationContext back to previous
- currentThread1._synchronizationContext = previousSyncCtx1;
- }
-
- ExecutionContext? previousExecutionCtx1 = previousExecutionCtx;
- ExecutionContext? currentExecutionCtx1 = currentThread1._executionContext;
- if (previousExecutionCtx1 != currentExecutionCtx1)
- {
- ExecutionContext.RestoreChangedContextToThread(currentThread1, previousExecutionCtx1, currentExecutionCtx1);
- }
- }
- }
-
- public static void SetStateMachine(IAsyncStateMachine stateMachine, Task? task)
- {
- if (stateMachine == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.stateMachine);
- }
-
- if (task != null)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.AsyncMethodBuilder_InstanceNotInitialized);
- }
-
- // SetStateMachine was originally needed in order to store the boxed state machine reference into
- // the boxed copy. Now that a normal box is no longer used, SetStateMachine is also legacy. We need not
- // do anything here, and thus assert to ensure we're not calling this from our own implementations.
- Debug.Fail("SetStateMachine should not be used.");
- }
-
-#if !CORERT
- /// <summary>Gets whether we should be tracking async method completions for eventing.</summary>
- internal static bool TrackAsyncMethodCompletion
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => TplEventSource.Log.IsEnabled(EventLevel.Warning, TplEventSource.Keywords.AsyncMethod);
- }
-#endif
-
- /// <summary>Gets a description of the state of the state machine object, suitable for debug purposes.</summary>
- /// <param name="stateMachine">The state machine object.</param>
- /// <returns>A description of the state machine.</returns>
- internal static string GetAsyncStateMachineDescription(IAsyncStateMachine stateMachine)
- {
- Debug.Assert(stateMachine != null);
-
- Type stateMachineType = stateMachine.GetType();
- FieldInfo[] fields = stateMachineType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
-
- var sb = new StringBuilder();
- sb.AppendLine(stateMachineType.FullName);
- foreach (FieldInfo fi in fields)
- {
- sb.Append(" ").Append(fi.Name).Append(": ").Append(fi.GetValue(stateMachine)).AppendLine();
- }
- return sb.ToString();
- }
-
- internal static Action CreateContinuationWrapper(Action continuation, Action<Action, Task> invokeAction, Task innerTask) =>
- new ContinuationWrapper(continuation, invokeAction, innerTask).Invoke;
-
- /// <summary>This helper routine is targeted by the debugger. Its purpose is to remove any delegate wrappers introduced by
- /// the framework that the debugger doesn't want to see.</summary>
- internal static Action TryGetStateMachineForDebugger(Action action) // debugger depends on this exact name/signature
- {
- object? target = action.Target;
- return
- target is IAsyncStateMachineBox sm ? sm.GetStateMachineObject().MoveNext :
- target is ContinuationWrapper cw ? TryGetStateMachineForDebugger(cw._continuation) :
- action;
- }
-
- internal static Task? TryGetContinuationTask(Action continuation) =>
- (continuation.Target is ContinuationWrapper wrapper) ?
- wrapper._innerTask : // A wrapped continuation, created by an awaiter
- continuation.Target as Task; // The continuation targets a task directly, such as with AsyncStateMachineBox
-
- /// <summary>
- /// Logically we pass just an Action (delegate) to a task for its action to 'ContinueWith' when it completes.
- /// However debuggers and profilers need more information about what that action is. (In particular what
- /// the action after that is and after that. To solve this problem we create a 'ContinuationWrapper
- /// which when invoked just does the original action (the invoke action), but also remembers other information
- /// (like the action after that (which is also a ContinuationWrapper and thus form a linked list).
- /// We also store that task if the action is associate with at task.
- /// </summary>
- private sealed class ContinuationWrapper // SOS DumpAsync command depends on this name
- {
- private readonly Action<Action, Task> _invokeAction; // This wrapper is an action that wraps another action, this is that Action.
- internal readonly Action _continuation; // This is continuation which will happen after m_invokeAction (and is probably a ContinuationWrapper). SOS DumpAsync command depends on this name.
- internal readonly Task _innerTask; // If the continuation is logically going to invoke a task, this is that task (may be null)
-
- internal ContinuationWrapper(Action continuation, Action<Action, Task> invokeAction, Task innerTask)
- {
- Debug.Assert(continuation != null, "Expected non-null continuation");
- Debug.Assert(invokeAction != null, "Expected non-null invokeAction");
- Debug.Assert(innerTask != null, "Expected non-null innerTask");
-
- _invokeAction = invokeAction;
- _continuation = continuation;
- _innerTask = innerTask;
- }
-
- internal void Invoke() => _invokeAction(_continuation, _innerTask);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncStateMachineAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncStateMachineAttribute.cs
deleted file mode 100644
index 66c9175ee75..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncStateMachineAttribute.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
- public sealed class AsyncStateMachineAttribute : StateMachineAttribute
- {
- public AsyncStateMachineAttribute(Type stateMachineType)
- : base(stateMachineType)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskCache.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskCache.cs
deleted file mode 100644
index 3f164a02c43..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskCache.cs
+++ /dev/null
@@ -1,66 +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 System.Diagnostics;
-using System.Threading.Tasks;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>Provides a cache of closed generic tasks for async methods.</summary>
- internal static class AsyncTaskCache
- {
- /// <summary>A cached Task{Boolean}.Result == true.</summary>
- internal static readonly Task<bool> s_trueTask = CreateCacheableTask(result: true);
- /// <summary>A cached Task{Boolean}.Result == false.</summary>
- internal static readonly Task<bool> s_falseTask = CreateCacheableTask(result: false);
- /// <summary>The cache of Task{Int32}.</summary>
- internal static readonly Task<int>[] s_int32Tasks = CreateInt32Tasks();
- /// <summary>The minimum value, inclusive, for which we want a cached task.</summary>
- internal const int InclusiveInt32Min = -1;
- /// <summary>The maximum value, exclusive, for which we want a cached task.</summary>
- internal const int ExclusiveInt32Max = 9;
-
- /// <summary>true if we should use reusable boxes for async completions of ValueTask methods; false if we should use tasks.</summary>
- /// <remarks>
- /// We rely on tiered compilation turning this into a const and doing dead code elimination to make checks on this efficient.
- /// It's also required for safety that this value never changes once observed, as Unsafe.As casts are employed based on its value.
- /// </remarks>
- internal static readonly bool s_valueTaskPoolingEnabled = GetPoolAsyncValueTasksSwitch();
- /// <summary>Maximum number of boxes that are allowed to be cached per state machine type.</summary>
- internal static readonly int s_valueTaskPoolingCacheSize = GetPoolAsyncValueTasksLimitValue();
-
- private static bool GetPoolAsyncValueTasksSwitch()
- {
- string? value = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_THREADING_POOLASYNCVALUETASKS");
- return value != null && (bool.IsTrueStringIgnoreCase(value) || value.Equals("1"));
- }
-
- private static int GetPoolAsyncValueTasksLimitValue() =>
- int.TryParse(Environment.GetEnvironmentVariable("DOTNET_SYSTEM_THREADING_POOLASYNCVALUETASKSLIMIT"), out int result) && result > 0 ?
- result :
- Environment.ProcessorCount * 4; // arbitrary default value
-
- /// <summary>Creates a non-disposable task.</summary>
- /// <typeparam name="TResult">Specifies the result type.</typeparam>
- /// <param name="result">The result for the task.</param>
- /// <returns>The cacheable task.</returns>
- internal static Task<TResult> CreateCacheableTask<TResult>([AllowNull] TResult result) =>
- new Task<TResult>(false, result, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default);
-
- /// <summary>Creates an array of cached tasks for the values in the range [INCLUSIVE_MIN,EXCLUSIVE_MAX).</summary>
- private static Task<int>[] CreateInt32Tasks()
- {
- Debug.Assert(ExclusiveInt32Max >= InclusiveInt32Min, "Expected max to be at least min");
-
- var tasks = new Task<int>[ExclusiveInt32Max - InclusiveInt32Min];
- for (int i = 0; i < tasks.Length; i++)
- {
- tasks[i] = CreateCacheableTask(i + InclusiveInt32Min);
- }
-
- return tasks;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilder.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilder.cs
deleted file mode 100644
index a3e7e5fe068..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilder.cs
+++ /dev/null
@@ -1,144 +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 System.Diagnostics;
-using System.Threading.Tasks;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Provides a builder for asynchronous methods that return <see cref="System.Threading.Tasks.Task"/>.
- /// This type is intended for compiler use only.
- /// </summary>
- /// <remarks>
- /// AsyncTaskMethodBuilder is a value type, and thus it is copied by value.
- /// Prior to being copied, one of its Task, SetResult, or SetException members must be accessed,
- /// or else the copies may end up building distinct Task instances.
- /// </remarks>
- public struct AsyncTaskMethodBuilder
- {
- /// <summary>The lazily-initialized built task.</summary>
- private Task<VoidTaskResult>? m_task; // Debugger depends on the exact name of this field.
-
- /// <summary>Initializes a new <see cref="AsyncTaskMethodBuilder"/>.</summary>
- /// <returns>The initialized <see cref="AsyncTaskMethodBuilder"/>.</returns>
- public static AsyncTaskMethodBuilder Create() => default;
-
- /// <summary>Initiates the builder's execution with the associated state machine.</summary>
- /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
- /// <param name="stateMachine">The state machine instance, passed by reference.</param>
- [DebuggerStepThrough]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
- AsyncMethodBuilderCore.Start(ref stateMachine);
-
- /// <summary>Associates the builder with the state machine it represents.</summary>
- /// <param name="stateMachine">The heap-allocated state machine object.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="stateMachine"/> argument was null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.InvalidOperationException">The builder is incorrectly initialized.</exception>
- public void SetStateMachine(IAsyncStateMachine stateMachine) =>
- AsyncMethodBuilderCore.SetStateMachine(stateMachine, task: null);
-
- /// <summary>
- /// Schedules the specified state machine to be pushed forward when the specified awaiter completes.
- /// </summary>
- /// <typeparam name="TAwaiter">Specifies the type of the awaiter.</typeparam>
- /// <typeparam name="TStateMachine">Specifies 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 =>
- AsyncTaskMethodBuilder<VoidTaskResult>.AwaitOnCompleted(ref awaiter, ref stateMachine, ref m_task);
-
- /// <summary>
- /// Schedules the specified state machine to be pushed forward when the specified awaiter completes.
- /// </summary>
- /// <typeparam name="TAwaiter">Specifies the type of the awaiter.</typeparam>
- /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
- /// <param name="awaiter">The awaiter.</param>
- /// <param name="stateMachine">The state machine.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(
- ref TAwaiter awaiter, ref TStateMachine stateMachine)
- where TAwaiter : ICriticalNotifyCompletion
- where TStateMachine : IAsyncStateMachine =>
- AsyncTaskMethodBuilder<VoidTaskResult>.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine, ref m_task);
-
- /// <summary>Gets the <see cref="System.Threading.Tasks.Task"/> for this builder.</summary>
- /// <returns>The <see cref="System.Threading.Tasks.Task"/> representing the builder's asynchronous operation.</returns>
- /// <exception cref="System.InvalidOperationException">The builder is not initialized.</exception>
- public Task Task
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => m_task ?? InitializeTaskAsPromise();
- }
-
- /// <summary>
- /// Initializes the task, which must not yet be initialized. Used only when the Task is being forced into
- /// existence when no state machine is needed, e.g. when the builder is being synchronously completed with
- /// an exception, when the builder is being used out of the context of an async method, etc.
- /// </summary>
- [MethodImpl(MethodImplOptions.NoInlining)]
- private Task<VoidTaskResult> InitializeTaskAsPromise()
- {
- Debug.Assert(m_task == null);
- return m_task = new Task<VoidTaskResult>();
- }
-
- /// <summary>
- /// Completes the <see cref="System.Threading.Tasks.Task"/> in the
- /// <see cref="System.Threading.Tasks.TaskStatus">RanToCompletion</see> state.
- /// </summary>
- /// <exception cref="System.InvalidOperationException">The builder is not initialized.</exception>
- /// <exception cref="System.InvalidOperationException">The task has already completed.</exception>
- public void SetResult()
- {
- // Get the currently stored task, which will be non-null if get_Task has already been accessed.
- // If there isn't one, store the supplied completed task.
- if (m_task is null)
- {
- m_task = Task.s_cachedCompleted;
- }
- else
- {
- // Otherwise, complete the task that's there.
- AsyncTaskMethodBuilder<VoidTaskResult>.SetExistingTaskResult(m_task, default!);
- }
- }
-
- /// <summary>
- /// Completes the <see cref="System.Threading.Tasks.Task"/> in the
- /// <see cref="System.Threading.Tasks.TaskStatus">Faulted</see> state with the specified exception.
- /// </summary>
- /// <param name="exception">The <see cref="System.Exception"/> to use to fault the task.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="exception"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.InvalidOperationException">The builder is not initialized.</exception>
- /// <exception cref="System.InvalidOperationException">The task has already completed.</exception>
- public void SetException(Exception exception) =>
- AsyncTaskMethodBuilder<VoidTaskResult>.SetException(exception, ref m_task);
-
- /// <summary>
- /// Called by the debugger to request notification when the first wait operation
- /// (await, Wait, Result, etc.) on this builder's task completes.
- /// </summary>
- /// <param name="enabled">
- /// true to enable notification; false to disable a previously set notification.
- /// </param>
- internal void SetNotificationForWaitCompletion(bool enabled) =>
- AsyncTaskMethodBuilder<VoidTaskResult>.SetNotificationForWaitCompletion(enabled, ref m_task);
-
- /// <summary>
- /// Gets an object that may be used to uniquely identify this builder to the debugger.
- /// </summary>
- /// <remarks>
- /// This property lazily instantiates the ID in a non-thread-safe manner.
- /// It must only be used by the debugger and tracing purposes, and only in a single-threaded manner
- /// when no other threads are in the middle of accessing this property or this.Task.
- /// </remarks>
- internal object ObjectIdForDebugger =>
- m_task ??= AsyncTaskMethodBuilder<VoidTaskResult>.CreateWeaklyTypedStateMachineBox();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs
deleted file mode 100644
index 043a133ab13..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs
+++ /dev/null
@@ -1,607 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Threading;
-using System.Threading.Tasks;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Provides a builder for asynchronous methods that return <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// This type is intended for compiler use only.
- /// </summary>
- /// <remarks>
- /// AsyncTaskMethodBuilder{TResult} is a value type, and thus it is copied by value.
- /// Prior to being copied, one of its Task, SetResult, or SetException members must be accessed,
- /// or else the copies may end up building distinct Task instances.
- /// </remarks>
- public struct AsyncTaskMethodBuilder<TResult>
- {
- /// <summary>A cached task for default(TResult).</summary>
- internal static readonly Task<TResult> s_defaultResultTask = AsyncTaskCache.CreateCacheableTask<TResult>(default);
-
- /// <summary>The lazily-initialized built task.</summary>
- private Task<TResult>? m_task; // Debugger depends on the exact name of this field.
-
- /// <summary>Initializes a new <see cref="AsyncTaskMethodBuilder"/>.</summary>
- /// <returns>The initialized <see cref="AsyncTaskMethodBuilder"/>.</returns>
- public static AsyncTaskMethodBuilder<TResult> Create() => default;
-
- /// <summary>Initiates the builder's execution with the associated state machine.</summary>
- /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
- /// <param name="stateMachine">The state machine instance, passed by reference.</param>
- [DebuggerStepThrough]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
- AsyncMethodBuilderCore.Start(ref stateMachine);
-
- /// <summary>Associates the builder with the state machine it represents.</summary>
- /// <param name="stateMachine">The heap-allocated state machine object.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="stateMachine"/> argument was null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.InvalidOperationException">The builder is incorrectly initialized.</exception>
- public void SetStateMachine(IAsyncStateMachine stateMachine) =>
- AsyncMethodBuilderCore.SetStateMachine(stateMachine, m_task);
-
- /// <summary>
- /// Schedules the specified state machine to be pushed forward when the specified awaiter completes.
- /// </summary>
- /// <typeparam name="TAwaiter">Specifies the type of the awaiter.</typeparam>
- /// <typeparam name="TStateMachine">Specifies 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 =>
- AwaitOnCompleted(ref awaiter, ref stateMachine, ref m_task);
-
- internal static void AwaitOnCompleted<TAwaiter, TStateMachine>(
- ref TAwaiter awaiter, ref TStateMachine stateMachine, [NotNull] ref Task<TResult>? taskField)
- where TAwaiter : INotifyCompletion
- where TStateMachine : IAsyncStateMachine
- {
- try
- {
- awaiter.OnCompleted(GetStateMachineBox(ref stateMachine, ref taskField).MoveNextAction);
- }
- catch (Exception e)
- {
- System.Threading.Tasks.Task.ThrowAsync(e, targetContext: null);
- }
- }
-
- /// <summary>
- /// Schedules the specified state machine to be pushed forward when the specified awaiter completes.
- /// </summary>
- /// <typeparam name="TAwaiter">Specifies the type of the awaiter.</typeparam>
- /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
- /// <param name="awaiter">The awaiter.</param>
- /// <param name="stateMachine">The state machine.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(
- ref TAwaiter awaiter, ref TStateMachine stateMachine)
- where TAwaiter : ICriticalNotifyCompletion
- where TStateMachine : IAsyncStateMachine =>
- AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine, ref m_task);
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(
- ref TAwaiter awaiter, ref TStateMachine stateMachine, [NotNull] ref Task<TResult>? taskField)
- where TAwaiter : ICriticalNotifyCompletion
- where TStateMachine : IAsyncStateMachine
- {
- IAsyncStateMachineBox box = GetStateMachineBox(ref stateMachine, ref taskField);
- AwaitUnsafeOnCompleted(ref awaiter, box);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)] // workaround boxing allocations in Tier0: https://github.com/dotnet/coreclr/issues/14474
- internal static void AwaitUnsafeOnCompleted<TAwaiter>(
- ref TAwaiter awaiter, IAsyncStateMachineBox box)
- where TAwaiter : ICriticalNotifyCompletion
- {
- // The null tests here ensure that the jit can optimize away the interface
- // tests when TAwaiter is a ref type.
-
- if ((null != (object)default(TAwaiter)!) && (awaiter is ITaskAwaiter)) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- ref TaskAwaiter ta = ref Unsafe.As<TAwaiter, TaskAwaiter>(ref awaiter); // relies on TaskAwaiter/TaskAwaiter<T> having the same layout
- TaskAwaiter.UnsafeOnCompletedInternal(ta.m_task, box, continueOnCapturedContext: true);
- }
- else if ((null != (object)default(TAwaiter)!) && (awaiter is IConfiguredTaskAwaiter)) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- ref ConfiguredTaskAwaitable.ConfiguredTaskAwaiter ta = ref Unsafe.As<TAwaiter, ConfiguredTaskAwaitable.ConfiguredTaskAwaiter>(ref awaiter);
- TaskAwaiter.UnsafeOnCompletedInternal(ta.m_task, box, ta.m_continueOnCapturedContext);
- }
- else if ((null != (object)default(TAwaiter)!) && (awaiter is IStateMachineBoxAwareAwaiter)) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- try
- {
- ((IStateMachineBoxAwareAwaiter)awaiter).AwaitUnsafeOnCompleted(box);
- }
- catch (Exception e)
- {
- // Whereas with Task the code that hooks up and invokes the continuation is all local to corelib,
- // with ValueTaskAwaiter we may be calling out to an arbitrary implementation of IValueTaskSource
- // wrapped in the ValueTask, and as such we protect against errant exceptions that may emerge.
- // We don't want such exceptions propagating back into the async method, which can't handle
- // exceptions well at that location in the state machine, especially if the exception may occur
- // after the ValueTaskAwaiter already successfully hooked up the callback, in which case it's possible
- // two different flows of execution could end up happening in the same async method call.
- System.Threading.Tasks.Task.ThrowAsync(e, targetContext: null);
- }
- }
- else
- {
- // The awaiter isn't specially known. Fall back to doing a normal await.
- try
- {
- awaiter.UnsafeOnCompleted(box.MoveNextAction);
- }
- catch (Exception e)
- {
- System.Threading.Tasks.Task.ThrowAsync(e, targetContext: null);
- }
- }
- }
-
- /// <summary>Gets the "boxed" state machine object.</summary>
- /// <typeparam name="TStateMachine">Specifies the type of the async state machine.</typeparam>
- /// <param name="stateMachine">The state machine.</param>
- /// <returns>The "boxed" state machine.</returns>
- private static IAsyncStateMachineBox GetStateMachineBox<TStateMachine>(
- ref TStateMachine stateMachine,
- [NotNull] ref Task<TResult>? taskField)
- where TStateMachine : IAsyncStateMachine
- {
- ExecutionContext? currentContext = ExecutionContext.Capture();
-
- // Check first for the most common case: not the first yield in an async method.
- // In this case, the first yield will have already "boxed" the state machine in
- // a strongly-typed manner into an AsyncStateMachineBox. It will already contain
- // the state machine as well as a MoveNextDelegate and a context. The only thing
- // we might need to do is update the context if that's changed since it was stored.
- if (taskField is AsyncStateMachineBox<TStateMachine> stronglyTypedBox)
- {
- if (stronglyTypedBox.Context != currentContext)
- {
- stronglyTypedBox.Context = currentContext;
- }
- return stronglyTypedBox;
- }
-
- // The least common case: we have a weakly-typed boxed. This results if the debugger
- // or some other use of reflection accesses a property like ObjectIdForDebugger or a
- // method like SetNotificationForWaitCompletion prior to the first await happening. In
- // such situations, we need to get an object to represent the builder, but we don't yet
- // know the type of the state machine, and thus can't use TStateMachine. Instead, we
- // use the IAsyncStateMachine interface, which all TStateMachines implement. This will
- // result in a boxing allocation when storing the TStateMachine if it's a struct, but
- // this only happens in active debugging scenarios where such performance impact doesn't
- // matter.
- if (taskField is AsyncStateMachineBox<IAsyncStateMachine> weaklyTypedBox)
- {
- // If this is the first await, we won't yet have a state machine, so store it.
- if (weaklyTypedBox.StateMachine == null)
- {
- Debugger.NotifyOfCrossThreadDependency(); // same explanation as with usage below
- weaklyTypedBox.StateMachine = stateMachine;
- }
-
- // Update the context. This only happens with a debugger, so no need to spend
- // extra IL checking for equality before doing the assignment.
- weaklyTypedBox.Context = currentContext;
- return weaklyTypedBox;
- }
-
- // Alert a listening debugger that we can't make forward progress unless it slips threads.
- // If we don't do this, and a method that uses "await foo;" is invoked through funceval,
- // we could end up hooking up a callback to push forward the async method's state machine,
- // the debugger would then abort the funceval after it takes too long, and then continuing
- // execution could result in another callback being hooked up. At that point we have
- // multiple callbacks registered to push the state machine, which could result in bad behavior.
- Debugger.NotifyOfCrossThreadDependency();
-
- // At this point, taskField should really be null, in which case we want to create the box.
- // However, in a variety of debugger-related (erroneous) situations, it might be non-null,
- // e.g. if the Task property is examined in a Watch window, forcing it to be lazily-intialized
- // as a Task<TResult> rather than as an AsyncStateMachineBox. The worst that happens in such
- // cases is we lose the ability to properly step in the debugger, as the debugger uses that
- // object's identity to track this specific builder/state machine. As such, we proceed to
- // overwrite whatever's there anyway, even if it's non-null.
-#if CORERT
- // DebugFinalizableAsyncStateMachineBox looks like a small type, but it actually is not because
- // it will have a copy of all the slots from its parent. It will add another hundred(s) bytes
- // per each async method in CoreRT / ProjectN binaries without adding much value. Avoid
- // generating this extra code until a better solution is implemented.
- var box = new AsyncStateMachineBox<TStateMachine>();
-#else
- AsyncStateMachineBox<TStateMachine> box = AsyncMethodBuilderCore.TrackAsyncMethodCompletion ?
- CreateDebugFinalizableAsyncStateMachineBox<TStateMachine>() :
- new AsyncStateMachineBox<TStateMachine>();
-#endif
- taskField = box; // important: this must be done before storing stateMachine into box.StateMachine!
- box.StateMachine = stateMachine;
- box.Context = currentContext;
-
- // Log the creation of the state machine box object / task for this async method.
- if (AsyncCausalityTracer.LoggingOn)
- {
- AsyncCausalityTracer.TraceOperationCreation(box, "Async: " + stateMachine.GetType().Name);
- }
-
- // And if async debugging is enabled, track the task.
- if (System.Threading.Tasks.Task.s_asyncDebuggingEnabled)
- {
- System.Threading.Tasks.Task.AddToActiveTasks(box);
- }
-
- return box;
- }
-
-#if !CORERT
- // Avoid forcing the JIT to build DebugFinalizableAsyncStateMachineBox<TStateMachine> unless it's actually needed.
- [MethodImpl(MethodImplOptions.NoInlining)]
- private static AsyncStateMachineBox<TStateMachine> CreateDebugFinalizableAsyncStateMachineBox<TStateMachine>()
- where TStateMachine : IAsyncStateMachine =>
- new DebugFinalizableAsyncStateMachineBox<TStateMachine>();
-
- /// <summary>
- /// Provides an async state machine box with a finalizer that will fire an EventSource
- /// event about the state machine if it's being finalized without having been completed.
- /// </summary>
- /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
- private sealed class DebugFinalizableAsyncStateMachineBox<TStateMachine> : // SOS DumpAsync command depends on this name
- AsyncStateMachineBox<TStateMachine>
- where TStateMachine : IAsyncStateMachine
- {
- ~DebugFinalizableAsyncStateMachineBox()
- {
- // If the state machine is being finalized, something went wrong during its processing,
- // e.g. it awaited something that got collected without itself having been completed.
- // Fire an event with details about the state machine to help with debugging.
- if (!IsCompleted) // double-check it's not completed, just to help minimize false positives
- {
- TplEventSource.Log.IncompleteAsyncMethod(this);
- }
- }
- }
-#endif
-
- /// <summary>A strongly-typed box for Task-based async state machines.</summary>
- /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
- private class AsyncStateMachineBox<TStateMachine> : // SOS DumpAsync command depends on this name
- Task<TResult>, IAsyncStateMachineBox
- where TStateMachine : IAsyncStateMachine
- {
- /// <summary>Delegate used to invoke on an ExecutionContext when passed an instance of this box type.</summary>
- private static readonly ContextCallback s_callback = ExecutionContextCallback;
-
- // Used to initialize s_callback above. We don't use a lambda for this on purpose: a lambda would
- // introduce a new generic type behind the scenes that comes with a hefty size penalty in AOT builds.
- private static void ExecutionContextCallback(object? s)
- {
- Debug.Assert(s is AsyncStateMachineBox<TStateMachine>);
- // Only used privately to pass directly to EC.Run
- Unsafe.As<AsyncStateMachineBox<TStateMachine>>(s).StateMachine!.MoveNext();
- }
-
- /// <summary>A delegate to the <see cref="MoveNext()"/> method.</summary>
- private Action? _moveNextAction;
- /// <summary>The state machine itself.</summary>
- [AllowNull, MaybeNull]
- public TStateMachine StateMachine = default; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name.
- /// <summary>Captured ExecutionContext with which to invoke <see cref="MoveNextAction"/>; may be null.</summary>
- public ExecutionContext? Context;
-
- /// <summary>A delegate to the <see cref="MoveNext()"/> method.</summary>
- public Action MoveNextAction => _moveNextAction ??= new Action(MoveNext);
-
- internal sealed override void ExecuteFromThreadPool(Thread threadPoolThread) => MoveNext(threadPoolThread);
-
- /// <summary>Calls MoveNext on <see cref="StateMachine"/></summary>
- public void MoveNext() => MoveNext(threadPoolThread: null);
-
- private void MoveNext(Thread? threadPoolThread)
- {
- Debug.Assert(!IsCompleted);
-
- bool loggingOn = AsyncCausalityTracer.LoggingOn;
- if (loggingOn)
- {
- AsyncCausalityTracer.TraceSynchronousWorkStart(this, CausalitySynchronousWork.Execution);
- }
-
- ExecutionContext? context = Context;
- if (context == null)
- {
- Debug.Assert(StateMachine != null);
- StateMachine.MoveNext();
- }
- else
- {
- if (threadPoolThread is null)
- {
- ExecutionContext.RunInternal(context, s_callback, this);
- }
- else
- {
- ExecutionContext.RunFromThreadPoolDispatchLoop(threadPoolThread, context, s_callback, this);
- }
- }
-
- if (IsCompleted)
- {
- // If async debugging is enabled, remove the task from tracking.
- if (System.Threading.Tasks.Task.s_asyncDebuggingEnabled)
- {
- System.Threading.Tasks.Task.RemoveFromActiveTasks(this);
- }
-
- // Clear out state now that the async method has completed.
- // This avoids keeping arbitrary state referenced by lifted locals
- // if this Task / state machine box is held onto.
- StateMachine = default;
- Context = default;
-
-#if !CORERT
- // In case this is a state machine box with a finalizer, suppress its finalization
- // as it's now complete. We only need the finalizer to run if the box is collected
- // without having been completed.
- if (AsyncMethodBuilderCore.TrackAsyncMethodCompletion)
- {
- GC.SuppressFinalize(this);
- }
-#endif
- }
-
- if (loggingOn)
- {
- AsyncCausalityTracer.TraceSynchronousWorkCompletion(CausalitySynchronousWork.Execution);
- }
- }
-
- /// <summary>Gets the state machine as a boxed object. This should only be used for debugging purposes.</summary>
- IAsyncStateMachine IAsyncStateMachineBox.GetStateMachineObject() => StateMachine!; // likely boxes, only use for debugging
- }
-
- /// <summary>Gets the <see cref="System.Threading.Tasks.Task{TResult}"/> for this builder.</summary>
- /// <returns>The <see cref="System.Threading.Tasks.Task{TResult}"/> representing the builder's asynchronous operation.</returns>
- public Task<TResult> Task
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => m_task ?? InitializeTaskAsPromise();
- }
-
- /// <summary>
- /// Initializes the task, which must not yet be initialized. Used only when the Task is being forced into
- /// existence when no state machine is needed, e.g. when the builder is being synchronously completed with
- /// an exception, when the builder is being used out of the context of an async method, etc.
- /// </summary>
- [MethodImpl(MethodImplOptions.NoInlining)]
- private Task<TResult> InitializeTaskAsPromise()
- {
- Debug.Assert(m_task == null);
- return m_task = new Task<TResult>();
- }
-
- internal static Task<TResult> CreateWeaklyTypedStateMachineBox()
- {
-#if CORERT
- // DebugFinalizableAsyncStateMachineBox looks like a small type, but it actually is not because
- // it will have a copy of all the slots from its parent. It will add another hundred(s) bytes
- // per each async method in CoreRT / ProjectN binaries without adding much value. Avoid
- // generating this extra code until a better solution is implemented.
- return new AsyncStateMachineBox<IAsyncStateMachine>();
-#else
- return AsyncMethodBuilderCore.TrackAsyncMethodCompletion ?
- CreateDebugFinalizableAsyncStateMachineBox<IAsyncStateMachine>() :
- new AsyncStateMachineBox<IAsyncStateMachine>();
-#endif
- }
-
- /// <summary>
- /// Completes the <see cref="System.Threading.Tasks.Task{TResult}"/> in the
- /// <see cref="System.Threading.Tasks.TaskStatus">RanToCompletion</see> state with the specified result.
- /// </summary>
- /// <param name="result">The result to use to complete the task.</param>
- /// <exception cref="System.InvalidOperationException">The task has already completed.</exception>
- public void SetResult(TResult result)
- {
- // Get the currently stored task, which will be non-null if get_Task has already been accessed.
- // If there isn't one, get a task and store it.
- if (m_task is null)
- {
- m_task = GetTaskForResult(result);
- Debug.Assert(m_task != null, $"{nameof(GetTaskForResult)} should never return null");
- }
- else
- {
- // Slow path: complete the existing task.
- SetExistingTaskResult(m_task, result);
- }
- }
-
- /// <summary>Completes the already initialized task with the specified result.</summary>
- /// <param name="result">The result to use to complete the task.</param>
- internal static void SetExistingTaskResult(Task<TResult> taskField, [AllowNull] TResult result)
- {
- Debug.Assert(taskField != null, "Expected non-null task");
-
- if (AsyncCausalityTracer.LoggingOn)
- {
- AsyncCausalityTracer.TraceOperationCompletion(taskField, AsyncCausalityStatus.Completed);
- }
-
- if (!taskField.TrySetResult(result))
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted);
- }
- }
-
- /// <summary>
- /// Completes the <see cref="System.Threading.Tasks.Task{TResult}"/> in the
- /// <see cref="System.Threading.Tasks.TaskStatus">Faulted</see> state with the specified exception.
- /// </summary>
- /// <param name="exception">The <see cref="System.Exception"/> to use to fault the task.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="exception"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.InvalidOperationException">The task has already completed.</exception>
- public void SetException(Exception exception) => SetException(exception, ref m_task);
-
- internal static void SetException(Exception exception, ref Task<TResult>? taskField)
- {
- if (exception == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
- }
-
- // Get the task, forcing initialization if it hasn't already been initialized.
- Task<TResult> task = (taskField ??= new Task<TResult>());
-
- // If the exception represents cancellation, cancel the task. Otherwise, fault the task.
- bool successfullySet = exception is OperationCanceledException oce ?
- task.TrySetCanceled(oce.CancellationToken, oce) :
- task.TrySetException(exception);
-
- // Unlike with TaskCompletionSource, we do not need to spin here until _taskAndStateMachine is completed,
- // since AsyncTaskMethodBuilder.SetException should not be immediately followed by any code
- // that depends on the task having completely completed. Moreover, with correct usage,
- // SetResult or SetException should only be called once, so the Try* methods should always
- // return true, so no spinning would be necessary anyway (the spinning in TCS is only relevant
- // if another thread completes the task first).
- if (!successfullySet)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted);
- }
- }
-
- /// <summary>
- /// Called by the debugger to request notification when the first wait operation
- /// (await, Wait, Result, etc.) on this builder's task completes.
- /// </summary>
- /// <param name="enabled">
- /// true to enable notification; false to disable a previously set notification.
- /// </param>
- /// <remarks>
- /// This should only be invoked from within an asynchronous method,
- /// and only by the debugger.
- /// </remarks>
- internal void SetNotificationForWaitCompletion(bool enabled) =>
- SetNotificationForWaitCompletion(enabled, ref m_task);
-
- internal static void SetNotificationForWaitCompletion(bool enabled, [NotNull] ref Task<TResult>? taskField)
- {
- // Get the task (forcing initialization if not already initialized), and set debug notification
- (taskField ??= CreateWeaklyTypedStateMachineBox()).SetNotificationForWaitCompletion(enabled);
-
- // NOTE: It's important that the debugger use builder.SetNotificationForWaitCompletion
- // rather than builder.Task.SetNotificationForWaitCompletion. Even though the latter will
- // lazily-initialize the task as well, it'll initialize it to a Task<T> (which is important
- // to minimize size for cases where an ATMB is used directly by user code to avoid the
- // allocation overhead of a TaskCompletionSource). If that's done prior to the first await,
- // the GetMoveNextDelegate code, which needs an AsyncStateMachineBox, will end up creating
- // a new box and overwriting the previously created task. That'll change the object identity
- // of the task being used for wait completion notification, and no notification will
- // ever arrive, breaking step-out behavior when stepping out before the first yielding await.
- }
-
- /// <summary>
- /// Gets an object that may be used to uniquely identify this builder to the debugger.
- /// </summary>
- /// <remarks>
- /// This property lazily instantiates the ID in a non-thread-safe manner.
- /// It must only be used by the debugger and tracing purposes, and only in a single-threaded manner
- /// when no other threads are in the middle of accessing this or other members that lazily initialize the task.
- /// </remarks>
- internal object ObjectIdForDebugger => m_task ??= CreateWeaklyTypedStateMachineBox();
-
- /// <summary>
- /// Gets a task for the specified result. This will either
- /// be a cached or new task, never null.
- /// </summary>
- /// <param name="result">The result for which we need a task.</param>
- /// <returns>The completed task containing the result.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // method looks long, but for a given TResult it results in a relatively small amount of asm
- internal static Task<TResult> GetTaskForResult(TResult result)
- {
- // The goal of this function is to be give back a cached task if possible,
- // or to otherwise give back a new task. To give back a cached task,
- // we need to be able to evaluate the incoming result value, and we need
- // to avoid as much overhead as possible when doing so, as this function
- // is invoked as part of the return path from every async method.
- // Most tasks won't be cached, and thus we need the checks for those that are
- // to be as close to free as possible. This requires some trickiness given the
- // lack of generic specialization in .NET.
- //
- // Be very careful when modifying this code. It has been tuned
- // to comply with patterns recognized by both 32-bit and 64-bit JITs.
- // If changes are made here, be sure to look at the generated assembly, as
- // small tweaks can have big consequences for what does and doesn't get optimized away.
- //
- // Note that this code only ever accesses a static field when it knows it'll
- // find a cached value, since static fields (even if readonly and integral types)
- // require special access helpers in this NGEN'd and domain-neutral.
-
- if (null != (object)default(TResult)!) // help the JIT avoid the value type branches for ref types // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- // Special case simple value types:
- // - Boolean
- // - Byte, SByte
- // - Char
- // - Int32, UInt32
- // - Int64, UInt64
- // - Int16, UInt16
- // - IntPtr, UIntPtr
- // As of .NET 4.5, the (Type)(object)result pattern used below
- // is recognized and optimized by both 32-bit and 64-bit JITs.
-
- // For Boolean, we cache all possible values.
- if (typeof(TResult) == typeof(bool)) // only the relevant branches are kept for each value-type generic instantiation
- {
- bool value = (bool)(object)result!;
- Task<bool> task = value ? AsyncTaskCache.s_trueTask : AsyncTaskCache.s_falseTask;
- return Unsafe.As<Task<TResult>>(task); // UnsafeCast avoids type check we know will succeed
- }
- // For Int32, we cache a range of common values, e.g. [-1,9).
- else if (typeof(TResult) == typeof(int))
- {
- // Compare to constants to avoid static field access if outside of cached range.
- // We compare to the upper bound first, as we're more likely to cache miss on the upper side than on the
- // lower side, due to positive values being more common than negative as return values.
- int value = (int)(object)result!;
- if (value < AsyncTaskCache.ExclusiveInt32Max &&
- value >= AsyncTaskCache.InclusiveInt32Min)
- {
- Task<int> task = AsyncTaskCache.s_int32Tasks[value - AsyncTaskCache.InclusiveInt32Min];
- return Unsafe.As<Task<TResult>>(task); // UnsafeCast avoids a type check we know will succeed
- }
- }
- // For other known value types, we only special-case 0 / default(TResult).
- else if (
- (typeof(TResult) == typeof(uint) && default == (uint)(object)result!) ||
- (typeof(TResult) == typeof(byte) && default(byte) == (byte)(object)result!) ||
- (typeof(TResult) == typeof(sbyte) && default(sbyte) == (sbyte)(object)result!) ||
- (typeof(TResult) == typeof(char) && default(char) == (char)(object)result!) ||
- (typeof(TResult) == typeof(long) && default == (long)(object)result!) ||
- (typeof(TResult) == typeof(ulong) && default == (ulong)(object)result!) ||
- (typeof(TResult) == typeof(short) && default(short) == (short)(object)result!) ||
- (typeof(TResult) == typeof(ushort) && default(ushort) == (ushort)(object)result!) ||
- (typeof(TResult) == typeof(IntPtr) && default == (IntPtr)(object)result!) ||
- (typeof(TResult) == typeof(UIntPtr) && default == (UIntPtr)(object)result!))
- {
- return s_defaultResultTask;
- }
- }
- else if (result == null) // optimized away for value types
- {
- return s_defaultResultTask;
- }
-
- // No cached task is available. Manufacture a new one for this result.
- return new Task<TResult>(result);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs
deleted file mode 100644
index bb5bd28393c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs
+++ /dev/null
@@ -1,175 +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 System.Runtime.InteropServices;
-using System.Threading.Tasks;
-using Internal.Runtime.CompilerServices;
-
-using StateMachineBox = System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.StateMachineBox;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>Represents a builder for asynchronous methods that return a <see cref="ValueTask"/>.</summary>
- [StructLayout(LayoutKind.Auto)]
- public struct AsyncValueTaskMethodBuilder
- {
- /// <summary>Sentinel object used to indicate that the builder completed synchronously and successfully.</summary>
- private static readonly object s_syncSuccessSentinel = AsyncValueTaskMethodBuilder<VoidTaskResult>.s_syncSuccessSentinel;
-
- /// <summary>The wrapped state machine box or task, based on the value of <see cref="AsyncTaskCache.s_valueTaskPoolingEnabled"/>.</summary>
- /// <remarks>
- /// If the operation completed synchronously and successfully, this will be <see cref="s_syncSuccessSentinel"/>.
- /// </remarks>
- private object? m_task; // Debugger depends on the exact name of this field.
-
- /// <summary>Creates an instance of the <see cref="AsyncValueTaskMethodBuilder"/> struct.</summary>
- /// <returns>The initialized instance.</returns>
- public static AsyncValueTaskMethodBuilder Create() => default;
-
- /// <summary>Begins running the builder with the associated state machine.</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 Start<TStateMachine>(ref TStateMachine stateMachine)
- where TStateMachine : IAsyncStateMachine =>
- AsyncMethodBuilderCore.Start(ref stateMachine);
-
- /// <summary>Associates the builder with the specified state machine.</summary>
- /// <param name="stateMachine">The state machine instance to associate with the builder.</param>
- public void SetStateMachine(IAsyncStateMachine stateMachine) =>
- AsyncMethodBuilderCore.SetStateMachine(stateMachine, task: null);
-
- /// <summary>Marks the task as successfully completed.</summary>
- public void SetResult()
- {
- if (m_task is null)
- {
- m_task = s_syncSuccessSentinel;
- }
- else if (AsyncTaskCache.s_valueTaskPoolingEnabled)
- {
- Unsafe.As<StateMachineBox>(m_task).SetResult(default);
- }
- else
- {
- AsyncTaskMethodBuilder<VoidTaskResult>.SetExistingTaskResult(Unsafe.As<Task<VoidTaskResult>>(m_task), default);
- }
- }
-
- /// <summary>Marks the task as failed and binds the specified exception to the task.</summary>
- /// <param name="exception">The exception to bind to the task.</param>
- public void SetException(Exception exception)
- {
- if (AsyncTaskCache.s_valueTaskPoolingEnabled)
- {
- AsyncValueTaskMethodBuilder<VoidTaskResult>.SetException(exception, ref Unsafe.As<object?, StateMachineBox?>(ref m_task));
- }
- else
- {
- AsyncTaskMethodBuilder<VoidTaskResult>.SetException(exception, ref Unsafe.As<object?, Task<VoidTaskResult>?>(ref m_task));
- }
- }
-
- /// <summary>Gets the task for this builder.</summary>
- public ValueTask Task
- {
- get
- {
- if (m_task == s_syncSuccessSentinel)
- {
- return default;
- }
-
- // With normal access paterns, m_task should always be non-null here: the async method should have
- // either completed synchronously, in which case SetResult would have set m_task to a non-null object,
- // or it should be completing asynchronously, in which case AwaitUnsafeOnCompleted would have similarly
- // initialized m_task to a state machine object. However, if the type is used manually (not via
- // compiler-generated code) and accesses Task directly, we force it to be initialized. Things will then
- // "work" but in a degraded mode, as we don't know the TStateMachine type here, and thus we use a box around
- // the interface instead.
-
- if (AsyncTaskCache.s_valueTaskPoolingEnabled)
- {
- var box = Unsafe.As<StateMachineBox?>(m_task);
- if (box is null)
- {
- m_task = box = AsyncValueTaskMethodBuilder<VoidTaskResult>.CreateWeaklyTypedStateMachineBox();
- }
- return new ValueTask(box, box.Version);
- }
- else
- {
- var task = Unsafe.As<Task<VoidTaskResult>?>(m_task);
- if (task is null)
- {
- m_task = task = new Task<VoidTaskResult>(); // base task used rather than box to minimize size when used as manual promise
- }
- return new ValueTask(task);
- }
- }
- }
-
- /// <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
- {
- if (AsyncTaskCache.s_valueTaskPoolingEnabled)
- {
- AsyncValueTaskMethodBuilder<VoidTaskResult>.AwaitOnCompleted(ref awaiter, ref stateMachine, ref Unsafe.As<object?, StateMachineBox?>(ref m_task));
- }
- else
- {
- AsyncTaskMethodBuilder<VoidTaskResult>.AwaitOnCompleted(ref awaiter, ref stateMachine, ref Unsafe.As<object?, Task<VoidTaskResult>?>(ref m_task));
- }
- }
-
- /// <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>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine)
- where TAwaiter : ICriticalNotifyCompletion
- where TStateMachine : IAsyncStateMachine
- {
- if (AsyncTaskCache.s_valueTaskPoolingEnabled)
- {
- AsyncValueTaskMethodBuilder<VoidTaskResult>.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine, ref Unsafe.As<object?, StateMachineBox?>(ref m_task));
- }
- else
- {
- AsyncTaskMethodBuilder<VoidTaskResult>.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine, ref Unsafe.As<object?, Task<VoidTaskResult>?>(ref m_task));
- }
- }
-
- /// <summary>
- /// Gets an object that may be used to uniquely identify this builder to the debugger.
- /// </summary>
- /// <remarks>
- /// This property lazily instantiates the ID in a non-thread-safe manner.
- /// It must only be used by the debugger and tracing purposes, and only in a single-threaded manner
- /// when no other threads are in the middle of accessing this or other members that lazily initialize the box.
- /// </remarks>
- internal object ObjectIdForDebugger
- {
- get
- {
- if (m_task is null)
- {
- m_task = AsyncTaskCache.s_valueTaskPoolingEnabled ? (object)
- AsyncValueTaskMethodBuilder<VoidTaskResult>.CreateWeaklyTypedStateMachineBox() :
- AsyncTaskMethodBuilder<VoidTaskResult>.CreateWeaklyTypedStateMachineBox();
- }
-
- return m_task;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs
deleted file mode 100644
index d2bd7ec111a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs
+++ /dev/null
@@ -1,513 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Threading.Tasks.Sources;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>Represents a builder for asynchronous methods that returns a <see cref="ValueTask{TResult}"/>.</summary>
- /// <typeparam name="TResult">The type of the result.</typeparam>
- [StructLayout(LayoutKind.Auto)]
- public struct AsyncValueTaskMethodBuilder<TResult>
- {
- /// <summary>Sentinel object used to indicate that the builder completed synchronously and successfully.</summary>
- /// <remarks>
- /// To avoid memory safety issues even in the face of invalid race conditions, we ensure that the type of this object
- /// is valid for the mode in which we're operating. As such, it's cached on the generic builder per TResult
- /// rather than having one sentinel instance for all types.
- /// </remarks>
- internal static readonly object s_syncSuccessSentinel = AsyncTaskCache.s_valueTaskPoolingEnabled ? (object)
- new SyncSuccessSentinelStateMachineBox() :
- new Task<TResult>(default(TResult)!);
-
- /// <summary>The wrapped state machine or task. If the operation completed synchronously and successfully, this will be a sentinel object compared by reference identity.</summary>
- private object? m_task; // Debugger depends on the exact name of this field.
- /// <summary>The result for this builder if it's completed synchronously, in which case <see cref="m_task"/> will be <see cref="s_syncSuccessSentinel"/>.</summary>
- private TResult _result;
-
- /// <summary>Creates an instance of the <see cref="AsyncValueTaskMethodBuilder{TResult}"/> struct.</summary>
- /// <returns>The initialized instance.</returns>
- public static AsyncValueTaskMethodBuilder<TResult> Create() => default;
-
- /// <summary>Begins running the builder with the associated state machine.</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 Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
- AsyncMethodBuilderCore.Start(ref stateMachine);
-
- /// <summary>Associates the builder with the specified state machine.</summary>
- /// <param name="stateMachine">The state machine instance to associate with the builder.</param>
- public void SetStateMachine(IAsyncStateMachine stateMachine) =>
- AsyncMethodBuilderCore.SetStateMachine(stateMachine, task: null);
-
- /// <summary>Marks the value task as successfully completed.</summary>
- /// <param name="result">The result to use to complete the value task.</param>
- public void SetResult(TResult result)
- {
- if (m_task is null)
- {
- _result = result;
- m_task = s_syncSuccessSentinel;
- }
- else if (AsyncTaskCache.s_valueTaskPoolingEnabled)
- {
- Unsafe.As<StateMachineBox>(m_task).SetResult(result);
- }
- else
- {
- AsyncTaskMethodBuilder<TResult>.SetExistingTaskResult(Unsafe.As<Task<TResult>>(m_task), result);
- }
- }
-
- /// <summary>Marks the value task as failed and binds the specified exception to the value task.</summary>
- /// <param name="exception">The exception to bind to the value task.</param>
- public void SetException(Exception exception)
- {
- if (AsyncTaskCache.s_valueTaskPoolingEnabled)
- {
- SetException(exception, ref Unsafe.As<object?, StateMachineBox?>(ref m_task));
- }
- else
- {
- AsyncTaskMethodBuilder<TResult>.SetException(exception, ref Unsafe.As<object?, Task<TResult>?>(ref m_task));
- }
- }
-
- internal static void SetException(Exception exception, [NotNull] ref StateMachineBox? boxFieldRef)
- {
- if (exception is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
- }
-
- (boxFieldRef ??= CreateWeaklyTypedStateMachineBox()).SetException(exception);
- }
-
- /// <summary>Gets the value task for this builder.</summary>
- public ValueTask<TResult> Task
- {
- get
- {
- if (m_task == s_syncSuccessSentinel)
- {
- return new ValueTask<TResult>(_result);
- }
-
- // With normal access paterns, m_task should always be non-null here: the async method should have
- // either completed synchronously, in which case SetResult would have set m_task to a non-null object,
- // or it should be completing asynchronously, in which case AwaitUnsafeOnCompleted would have similarly
- // initialized m_task to a state machine object. However, if the type is used manually (not via
- // compiler-generated code) and accesses Task directly, we force it to be initialized. Things will then
- // "work" but in a degraded mode, as we don't know the TStateMachine type here, and thus we use a box around
- // the interface instead.
-
- if (AsyncTaskCache.s_valueTaskPoolingEnabled)
- {
- var box = Unsafe.As<StateMachineBox?>(m_task);
- if (box is null)
- {
- m_task = box = CreateWeaklyTypedStateMachineBox();
- }
- return new ValueTask<TResult>(box, box.Version);
- }
- else
- {
- var task = Unsafe.As<Task<TResult>?>(m_task);
- if (task is null)
- {
- m_task = task = new Task<TResult>(); // base task used rather than box to minimize size when used as manual promise
- }
- return new ValueTask<TResult>(task);
- }
- }
- }
-
- /// <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
- {
- if (AsyncTaskCache.s_valueTaskPoolingEnabled)
- {
- AwaitOnCompleted(ref awaiter, ref stateMachine, ref Unsafe.As<object?, StateMachineBox?>(ref m_task));
- }
- else
- {
- AsyncTaskMethodBuilder<TResult>.AwaitOnCompleted(ref awaiter, ref stateMachine, ref Unsafe.As<object?, Task<TResult>?>(ref m_task));
- }
- }
-
- internal static void AwaitOnCompleted<TAwaiter, TStateMachine>(
- ref TAwaiter awaiter, ref TStateMachine stateMachine, [NotNull] ref StateMachineBox? box)
- where TAwaiter : INotifyCompletion
- where TStateMachine : IAsyncStateMachine
- {
- try
- {
- awaiter.OnCompleted(GetStateMachineBox(ref stateMachine, ref box).MoveNextAction);
- }
- catch (Exception e)
- {
- System.Threading.Tasks.Task.ThrowAsync(e, targetContext: null);
- }
- }
-
- /// <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>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine)
- where TAwaiter : ICriticalNotifyCompletion
- where TStateMachine : IAsyncStateMachine
- {
- if (AsyncTaskCache.s_valueTaskPoolingEnabled)
- {
- AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine, ref Unsafe.As<object?, StateMachineBox?>(ref m_task));
- }
- else
- {
- AsyncTaskMethodBuilder<TResult>.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine, ref Unsafe.As<object?, Task<TResult>?>(ref m_task));
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(
- ref TAwaiter awaiter, ref TStateMachine stateMachine, [NotNull] ref StateMachineBox? boxRef)
- where TAwaiter : ICriticalNotifyCompletion
- where TStateMachine : IAsyncStateMachine
- {
- IAsyncStateMachineBox box = GetStateMachineBox(ref stateMachine, ref boxRef);
- AsyncTaskMethodBuilder<VoidTaskResult>.AwaitUnsafeOnCompleted(ref awaiter, box);
- }
-
- /// <summary>Gets the "boxed" state machine object.</summary>
- /// <typeparam name="TStateMachine">Specifies the type of the async state machine.</typeparam>
- /// <param name="stateMachine">The state machine.</param>
- /// <param name="boxFieldRef">A reference to the field containing the initialized state machine box.</param>
- /// <returns>The "boxed" state machine.</returns>
- private static IAsyncStateMachineBox GetStateMachineBox<TStateMachine>(
- ref TStateMachine stateMachine,
- [NotNull] ref StateMachineBox? boxFieldRef)
- where TStateMachine : IAsyncStateMachine
- {
- ExecutionContext? currentContext = ExecutionContext.Capture();
-
- // Check first for the most common case: not the first yield in an async method.
- // In this case, the first yield will have already "boxed" the state machine in
- // a strongly-typed manner into an AsyncStateMachineBox. It will already contain
- // the state machine as well as a MoveNextDelegate and a context. The only thing
- // we might need to do is update the context if that's changed since it was stored.
- if (boxFieldRef is StateMachineBox<TStateMachine> stronglyTypedBox)
- {
- if (stronglyTypedBox.Context != currentContext)
- {
- stronglyTypedBox.Context = currentContext;
- }
-
- return stronglyTypedBox;
- }
-
- // The least common case: we have a weakly-typed boxed. This results if the debugger
- // or some other use of reflection accesses a property like ObjectIdForDebugger. In
- // such situations, we need to get an object to represent the builder, but we don't yet
- // know the type of the state machine, and thus can't use TStateMachine. Instead, we
- // use the IAsyncStateMachine interface, which all TStateMachines implement. This will
- // result in a boxing allocation when storing the TStateMachine if it's a struct, but
- // this only happens in active debugging scenarios where such performance impact doesn't
- // matter.
- if (boxFieldRef is StateMachineBox<IAsyncStateMachine> weaklyTypedBox)
- {
- // If this is the first await, we won't yet have a state machine, so store it.
- if (weaklyTypedBox.StateMachine is null)
- {
- Debugger.NotifyOfCrossThreadDependency(); // same explanation as with usage below
- weaklyTypedBox.StateMachine = stateMachine;
- }
-
- // Update the context. This only happens with a debugger, so no need to spend
- // extra IL checking for equality before doing the assignment.
- weaklyTypedBox.Context = currentContext;
- return weaklyTypedBox;
- }
-
- // Alert a listening debugger that we can't make forward progress unless it slips threads.
- // If we don't do this, and a method that uses "await foo;" is invoked through funceval,
- // we could end up hooking up a callback to push forward the async method's state machine,
- // the debugger would then abort the funceval after it takes too long, and then continuing
- // execution could result in another callback being hooked up. At that point we have
- // multiple callbacks registered to push the state machine, which could result in bad behavior.
- Debugger.NotifyOfCrossThreadDependency();
-
- // At this point, m_task should really be null, in which case we want to create the box.
- // However, in a variety of debugger-related (erroneous) situations, it might be non-null,
- // e.g. if the Task property is examined in a Watch window, forcing it to be lazily-intialized
- // as a Task<TResult> rather than as an ValueTaskStateMachineBox. The worst that happens in such
- // cases is we lose the ability to properly step in the debugger, as the debugger uses that
- // object's identity to track this specific builder/state machine. As such, we proceed to
- // overwrite whatever's there anyway, even if it's non-null.
- var box = StateMachineBox<TStateMachine>.GetOrCreateBox();
- boxFieldRef = box; // important: this must be done before storing stateMachine into box.StateMachine!
- box.StateMachine = stateMachine;
- box.Context = currentContext;
-
- return box;
- }
-
- /// <summary>
- /// Creates a box object for use when a non-standard access pattern is employed, e.g. when Task
- /// is evaluated in the debugger prior to the async method yielding for the first time.
- /// </summary>
- internal static StateMachineBox CreateWeaklyTypedStateMachineBox() => new StateMachineBox<IAsyncStateMachine>();
-
- /// <summary>
- /// Gets an object that may be used to uniquely identify this builder to the debugger.
- /// </summary>
- /// <remarks>
- /// This property lazily instantiates the ID in a non-thread-safe manner.
- /// It must only be used by the debugger and tracing purposes, and only in a single-threaded manner
- /// when no other threads are in the middle of accessing this or other members that lazily initialize the box.
- /// </remarks>
- internal object ObjectIdForDebugger
- {
- get
- {
- if (m_task is null)
- {
- m_task = AsyncTaskCache.s_valueTaskPoolingEnabled ? (object)
- CreateWeaklyTypedStateMachineBox() :
- AsyncTaskMethodBuilder<TResult>.CreateWeaklyTypedStateMachineBox();
- }
-
- return m_task;
- }
- }
-
- /// <summary>The base type for all value task box reusable box objects, regardless of state machine type.</summary>
- internal abstract class StateMachineBox :
- IValueTaskSource<TResult>, IValueTaskSource
- {
- /// <summary>A delegate to the MoveNext method.</summary>
- protected Action? _moveNextAction;
- /// <summary>Captured ExecutionContext with which to invoke MoveNext.</summary>
- public ExecutionContext? Context;
- /// <summary>Implementation for IValueTaskSource interfaces.</summary>
- protected ManualResetValueTaskSourceCore<TResult> _valueTaskSource;
-
- /// <summary>Completes the box with a result.</summary>
- /// <param name="result">The result.</param>
- public void SetResult(TResult result) =>
- _valueTaskSource.SetResult(result);
-
- /// <summary>Completes the box with an error.</summary>
- /// <param name="error">The exception.</param>
- public void SetException(Exception error) =>
- _valueTaskSource.SetException(error);
-
- /// <summary>Gets the status of the box.</summary>
- public ValueTaskSourceStatus GetStatus(short token) => _valueTaskSource.GetStatus(token);
-
- /// <summary>Schedules the continuation action for this box.</summary>
- public void OnCompleted(Action<object?> continuation, object? state, short token, ValueTaskSourceOnCompletedFlags flags) =>
- _valueTaskSource.OnCompleted(continuation, state, token, flags);
-
- /// <summary>Gets the current version number of the box.</summary>
- public short Version => _valueTaskSource.Version;
-
- /// <summary>Implemented by derived type.</summary>
- TResult IValueTaskSource<TResult>.GetResult(short token) => throw NotImplemented.ByDesign;
-
- /// <summary>Implemented by derived type.</summary>
- void IValueTaskSource.GetResult(short token) => throw NotImplemented.ByDesign;
- }
-
- private sealed class SyncSuccessSentinelStateMachineBox : StateMachineBox
- {
- public SyncSuccessSentinelStateMachineBox() => SetResult(default!);
- }
-
- /// <summary>Provides a strongly-typed box object based on the specific state machine type in use.</summary>
- private sealed class StateMachineBox<TStateMachine> :
- StateMachineBox,
- IValueTaskSource<TResult>, IValueTaskSource, IAsyncStateMachineBox, IThreadPoolWorkItem
- where TStateMachine : IAsyncStateMachine
- {
- /// <summary>Delegate used to invoke on an ExecutionContext when passed an instance of this box type.</summary>
- private static readonly ContextCallback s_callback = ExecutionContextCallback;
- /// <summary>Lock used to protected the shared cache of boxes.</summary>
- /// <remarks>The code that uses this assumes a runtime without thread aborts.</remarks>
- private static int s_cacheLock;
- /// <summary>Singly-linked list cache of boxes.</summary>
- private static StateMachineBox<TStateMachine>? s_cache;
- /// <summary>The number of items stored in <see cref="s_cache"/>.</summary>
- private static int s_cacheSize;
-
- // TODO:
- // AsyncTaskMethodBuilder logs about the state machine box lifecycle; AsyncValueTaskMethodBuilder currently
- // does not when it employs these pooled boxes. That logging is based on Task IDs, which we lack here.
- // We could use the box's Version, but that is very likely to conflict with the IDs of other tasks in the system.
- // For now, we don't log, but should we choose to we'll probably want to store an int ID on the state machine box,
- // and initialize it an ID from Task's generator.
-
- /// <summary>If this box is stored in the cache, the next box in the cache.</summary>
- private StateMachineBox<TStateMachine>? _next;
- /// <summary>The state machine itself.</summary>
- [AllowNull, MaybeNull]
- public TStateMachine StateMachine = default;
-
- /// <summary>Gets a box object to use for an operation. This may be a reused, pooled object, or it may be new.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // only one caller
- internal static StateMachineBox<TStateMachine> GetOrCreateBox()
- {
- // Try to acquire the lock to access the cache. If there's any contention, don't use the cache.
- if (Interlocked.CompareExchange(ref s_cacheLock, 1, 0) == 0)
- {
- // If there are any instances cached, take one from the cache stack and use it.
- StateMachineBox<TStateMachine>? box = s_cache;
- if (!(box is null))
- {
- s_cache = box._next;
- box._next = null;
- s_cacheSize--;
- Debug.Assert(s_cacheSize >= 0, "Expected the cache size to be non-negative.");
-
- // Release the lock and return the box.
- Volatile.Write(ref s_cacheLock, 0);
- return box;
- }
-
- // No objects were cached. We'll just create a new instance.
- Debug.Assert(s_cacheSize == 0, "Expected cache size to be 0.");
-
- // Release the lock.
- Volatile.Write(ref s_cacheLock, 0);
- }
-
- // Couldn't quickly get a cached instance, so create a new instance.
- return new StateMachineBox<TStateMachine>();
- }
-
- private void ReturnOrDropBox()
- {
- Debug.Assert(_next is null, "Expected box to not be part of cached list.");
-
- // Clear out the state machine and associated context to avoid keeping arbitrary state referenced by
- // lifted locals. We want to do this regardless of whether we end up caching the box or not, in case
- // the caller keeps the box alive for an arbitrary period of time.
- StateMachine = default;
- Context = default;
-
- // Reset the MRVTSC. We can either do this here, in which case we may be paying the (small) overhead
- // to reset the box even if we're going to drop it, or we could do it while holding the lock, in which
- // case we'll only reset it if necessary but causing the lock to be held for longer, thereby causing
- // more contention. For now at least, we do it outside of the lock. (This must not be done after
- // the lock is released, since at that point the instance could already be in use elsewhere.)
- // We also want to increment the version number even if we're going to drop it, to maximize the chances
- // that incorrectly double-awaiting a ValueTask will produce an error.
- _valueTaskSource.Reset();
-
- // If reusing the object would result in potentially wrapping around its version number, just throw it away.
- // This provides a modicum of additional safety when ValueTasks are misused (helping to avoid the case where
- // a ValueTask is illegally re-awaited and happens to do so at exactly 2^16 uses later on this exact same instance),
- // at the expense of potentially incurring an additional allocation every 65K uses.
- if ((ushort)_valueTaskSource.Version == ushort.MaxValue)
- {
- return;
- }
-
- // Try to acquire the cache lock. If there's any contention, or if the cache is full, we just throw away the object.
- if (Interlocked.CompareExchange(ref s_cacheLock, 1, 0) == 0)
- {
- if (s_cacheSize < AsyncTaskCache.s_valueTaskPoolingCacheSize)
- {
- // Push the box onto the cache stack for subsequent reuse.
- _next = s_cache;
- s_cache = this;
- s_cacheSize++;
- Debug.Assert(s_cacheSize > 0 && s_cacheSize <= AsyncTaskCache.s_valueTaskPoolingCacheSize, "Expected cache size to be within bounds.");
- }
-
- // Release the lock.
- Volatile.Write(ref s_cacheLock, 0);
- }
- }
-
- /// <summary>
- /// Used to initialize s_callback above. We don't use a lambda for this on purpose: a lambda would
- /// introduce a new generic type behind the scenes that comes with a hefty size penalty in AOT builds.
- /// </summary>
- private static void ExecutionContextCallback(object? s)
- {
- // Only used privately to pass directly to EC.Run
- Debug.Assert(s is StateMachineBox<TStateMachine>);
- Unsafe.As<StateMachineBox<TStateMachine>>(s).StateMachine!.MoveNext();
- }
-
- /// <summary>A delegate to the <see cref="MoveNext()"/> method.</summary>
- public Action MoveNextAction => _moveNextAction ??= new Action(MoveNext);
-
- /// <summary>Invoked to run MoveNext when this instance is executed from the thread pool.</summary>
- void IThreadPoolWorkItem.Execute() => MoveNext();
-
- /// <summary>Calls MoveNext on <see cref="StateMachine"/></summary>
- public void MoveNext()
- {
- ExecutionContext? context = Context;
-
- if (context is null)
- {
- Debug.Assert(!(StateMachine is null));
- StateMachine.MoveNext();
- }
- else
- {
- ExecutionContext.RunInternal(context, s_callback, this);
- }
- }
-
- /// <summary>Get the result of the operation.</summary>
- TResult IValueTaskSource<TResult>.GetResult(short token)
- {
- try
- {
- return _valueTaskSource.GetResult(token);
- }
- finally
- {
- // Reuse this instance if possible, otherwise clear and drop it.
- ReturnOrDropBox();
- }
- }
-
- /// <summary>Get the result of the operation.</summary>
- void IValueTaskSource.GetResult(short token)
- {
- try
- {
- _valueTaskSource.GetResult(token);
- }
- finally
- {
- // Reuse this instance if possible, otherwise clear and drop it.
- ReturnOrDropBox();
- }
- }
-
- /// <summary>Gets the state machine as a boxed object. This should only be used for debugging purposes.</summary>
- IAsyncStateMachine IAsyncStateMachineBox.GetStateMachineObject() => StateMachine!; // likely boxes, only use for debugging
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncVoidMethodBuilder.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncVoidMethodBuilder.cs
deleted file mode 100644
index 3a0a0a2c630..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncVoidMethodBuilder.cs
+++ /dev/null
@@ -1,163 +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 System.Diagnostics;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Provides a builder for asynchronous methods that return void.
- /// This type is intended for compiler use only.
- /// </summary>
- public struct AsyncVoidMethodBuilder
- {
- /// <summary>The synchronization context associated with this operation.</summary>
- private SynchronizationContext? _synchronizationContext;
- /// <summary>The builder this void builder wraps.</summary>
- private AsyncTaskMethodBuilder _builder; // mutable struct: must not be readonly
-
- /// <summary>Initializes a new <see cref="AsyncVoidMethodBuilder"/>.</summary>
- /// <returns>The initialized <see cref="AsyncVoidMethodBuilder"/>.</returns>
- public static AsyncVoidMethodBuilder Create()
- {
- SynchronizationContext? sc = SynchronizationContext.Current;
- sc?.OperationStarted();
-
- // _builder should be initialized to AsyncTaskMethodBuilder.Create(), but on coreclr
- // that Create() is a nop, so we can just return the default here.
- return new AsyncVoidMethodBuilder() { _synchronizationContext = sc };
- }
-
- /// <summary>Initiates the builder's execution with the associated state machine.</summary>
- /// <typeparam name="TStateMachine">Specifies the type of the state machine.</typeparam>
- /// <param name="stateMachine">The state machine instance, passed by reference.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="stateMachine"/> argument was null (Nothing in Visual Basic).</exception>
- [DebuggerStepThrough]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine =>
- AsyncMethodBuilderCore.Start(ref stateMachine);
-
- /// <summary>Associates the builder with the state machine it represents.</summary>
- /// <param name="stateMachine">The heap-allocated state machine object.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="stateMachine"/> argument was null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.InvalidOperationException">The builder is incorrectly initialized.</exception>
- public void SetStateMachine(IAsyncStateMachine stateMachine) =>
- _builder.SetStateMachine(stateMachine);
-
- /// <summary>
- /// Schedules the specified state machine to be pushed forward when the specified awaiter completes.
- /// </summary>
- /// <typeparam name="TAwaiter">Specifies the type of the awaiter.</typeparam>
- /// <typeparam name="TStateMachine">Specifies 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 =>
- _builder.AwaitOnCompleted(ref awaiter, ref stateMachine);
-
- /// <summary>
- /// Schedules the specified state machine to be pushed forward when the specified awaiter completes.
- /// </summary>
- /// <typeparam name="TAwaiter">Specifies the type of the awaiter.</typeparam>
- /// <typeparam name="TStateMachine">Specifies 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 =>
- _builder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
-
- /// <summary>Completes the method builder successfully.</summary>
- public void SetResult()
- {
- if (AsyncCausalityTracer.LoggingOn)
- {
- AsyncCausalityTracer.TraceOperationCompletion(this.Task, AsyncCausalityStatus.Completed);
- }
-
- // Mark the builder as completed. As this is a void-returning method, this mostly
- // doesn't matter, but it can affect things like debug events related to finalization.
- _builder.SetResult();
-
- if (_synchronizationContext != null)
- {
- NotifySynchronizationContextOfCompletion();
- }
- }
-
- /// <summary>Faults the method builder with an exception.</summary>
- /// <param name="exception">The exception that is the cause of this fault.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="exception"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.InvalidOperationException">The builder is not initialized.</exception>
- public void SetException(Exception exception)
- {
- if (exception == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
- }
-
- if (AsyncCausalityTracer.LoggingOn)
- {
- AsyncCausalityTracer.TraceOperationCompletion(this.Task, AsyncCausalityStatus.Error);
- }
-
- if (_synchronizationContext != null)
- {
- // If we captured a synchronization context, Post the throwing of the exception to it
- // and decrement its outstanding operation count.
- try
- {
- System.Threading.Tasks.Task.ThrowAsync(exception, targetContext: _synchronizationContext);
- }
- finally
- {
- NotifySynchronizationContextOfCompletion();
- }
- }
- else
- {
- // Otherwise, queue the exception to be thrown on the ThreadPool. This will
- // result in a crash unless legacy exception behavior is enabled by a config
- // file or a CLR host.
- System.Threading.Tasks.Task.ThrowAsync(exception, targetContext: null);
- }
-
- // The exception was propagated already; we don't need or want to fault the builder, just mark it as completed.
- _builder.SetResult();
- }
-
- /// <summary>Notifies the current synchronization context that the operation completed.</summary>
- private void NotifySynchronizationContextOfCompletion()
- {
- Debug.Assert(_synchronizationContext != null, "Must only be used with a non-null context.");
- try
- {
- _synchronizationContext.OperationCompleted();
- }
- catch (Exception exc)
- {
- // If the interaction with the SynchronizationContext goes awry,
- // fall back to propagating on the ThreadPool.
- Task.ThrowAsync(exc, targetContext: null);
- }
- }
-
- /// <summary>Lazily instantiate the Task in a non-thread-safe manner.</summary>
- private Task Task => _builder.Task;
-
- /// <summary>
- /// Gets an object that may be used to uniquely identify this builder to the debugger.
- /// </summary>
- /// <remarks>
- /// This property lazily instantiates the ID in a non-thread-safe manner.
- /// It must only be used by the debugger and AsyncCausalityTracer in a single-threaded manner.
- /// </remarks>
- internal object ObjectIdForDebugger => _builder.ObjectIdForDebugger;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerArgumentExpressionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerArgumentExpressionAttribute.cs
deleted file mode 100644
index 6e1c4c56cd0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerArgumentExpressionAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
- public sealed class CallerArgumentExpressionAttribute : Attribute
- {
- public CallerArgumentExpressionAttribute(string parameterName)
- {
- ParameterName = parameterName;
- }
-
- public string ParameterName { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerFilePathAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerFilePathAttribute.cs
deleted file mode 100644
index 5858634b427..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerFilePathAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- public sealed class CallerFilePathAttribute : Attribute
- {
- public CallerFilePathAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerLineNumberAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerLineNumberAttribute.cs
deleted file mode 100644
index 5bd2fcb91b9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerLineNumberAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- public sealed class CallerLineNumberAttribute : Attribute
- {
- public CallerLineNumberAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs
deleted file mode 100644
index 8b046335b5a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- public sealed class CallerMemberNameAttribute : Attribute
- {
- public CallerMemberNameAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilationRelaxations.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilationRelaxations.cs
deleted file mode 100644
index 2d1763327ac..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilationRelaxations.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System.Runtime.CompilerServices
-{
- /// IMPORTANT: Keep this in sync with corhdr.h
- [Flags]
- public enum CompilationRelaxations : int
- {
- NoStringInterning = 0x0008 // Start in 0x0008, we had other non public flags in this enum before,
- // so we'll start here just in case somebody used them. This flag is only
- // valid when set for Assemblies.
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilationRelaxationsAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilationRelaxationsAttribute.cs
deleted file mode 100644
index d6da23fdf2a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilationRelaxationsAttribute.cs
+++ /dev/null
@@ -1,22 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Method)]
- public class CompilationRelaxationsAttribute : Attribute
- {
- public CompilationRelaxationsAttribute(int relaxations)
- {
- CompilationRelaxations = relaxations;
- }
-
- public CompilationRelaxationsAttribute(CompilationRelaxations relaxations)
- {
- CompilationRelaxations = (int)relaxations;
- }
-
- public int CompilationRelaxations { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilerGeneratedAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilerGeneratedAttribute.cs
deleted file mode 100644
index 1c05abd1fec..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilerGeneratedAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.All, Inherited = true)]
- public sealed class CompilerGeneratedAttribute : Attribute
- {
- public CompilerGeneratedAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilerGlobalScopeAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilerGlobalScopeAttribute.cs
deleted file mode 100644
index 542181ce91f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CompilerGlobalScopeAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.CompilerServices
-{
- // Attribute used to communicate to the VS7 debugger that a class should be treated as if it has global scope.
-
- [AttributeUsage(AttributeTargets.Class)]
- public class CompilerGlobalScopeAttribute : Attribute
- {
- public CompilerGlobalScopeAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs
deleted file mode 100644
index ae749f45b8d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs
+++ /dev/null
@@ -1,806 +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 System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Threading;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.CompilerServices
-{
- public sealed class ConditionalWeakTable<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
- where TKey : class
- where TValue : class?
- {
- // Lifetimes of keys and values:
- // Inserting a key and value into the dictonary will not
- // prevent the key from dying, even if the key is strongly reachable
- // from the value. Once the key dies, the dictionary automatically removes
- // the key/value entry.
- //
- // Thread safety guarantees:
- // ConditionalWeakTable is fully thread-safe and requires no
- // additional locking to be done by callers.
- //
- // OOM guarantees:
- // Will not corrupt unmanaged handle table on OOM. No guarantees
- // about managed weak table consistency. Native handles reclamation
- // may be delayed until appdomain shutdown.
-
- private const int InitialCapacity = 8; // Initial length of the table. Must be a power of two.
- private readonly object _lock; // This lock protects all mutation of data in the table. Readers do not take this lock.
- private volatile Container _container; // The actual storage for the table; swapped out as the table grows.
- private int _activeEnumeratorRefCount; // The number of outstanding enumerators on the table
-
- public ConditionalWeakTable()
- {
- _lock = new object();
- _container = new Container(this);
- }
-
- /// <summary>Gets the value of the specified key.</summary>
- /// <param name="key">key of the value to find. Cannot be null.</param>
- /// <param name="value">
- /// If the key is found, contains the value associated with the key upon method return.
- /// If the key is not found, contains default(TValue).
- /// </param>
- /// <returns>Returns "true" if key was found, "false" otherwise.</returns>
- /// <remarks>
- /// The key may get garbaged collected during the TryGetValue operation. If so, TryGetValue
- /// may at its discretion, return "false" and set "value" to the default (as if the key was not present.)
- /// </remarks>
- public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
- {
- if (key is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
-
- return _container.TryGetValueWorker(key, out value);
- }
-
- /// <summary>Adds a key to the table.</summary>
- /// <param name="key">key to add. May not be null.</param>
- /// <param name="value">value to associate with key.</param>
- /// <remarks>
- /// If the key is already entered into the dictionary, this method throws an exception.
- /// The key may get garbage collected during the Add() operation. If so, Add()
- /// has the right to consider any prior entries successfully removed and add a new entry without
- /// throwing an exception.
- /// </remarks>
- public void Add(TKey key, TValue value)
- {
- if (key is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
-
- lock (_lock)
- {
- int entryIndex = _container.FindEntry(key, out _);
- if (entryIndex != -1)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_AddingDuplicate);
- }
-
- CreateEntry(key, value);
- }
- }
-
- /// <summary>Adds the key and value if the key doesn't exist, or updates the existing key's value if it does exist.</summary>
- /// <param name="key">key to add or update. May not be null.</param>
- /// <param name="value">value to associate with key.</param>
- public void AddOrUpdate(TKey key, TValue value)
- {
- if (key is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
-
- lock (_lock)
- {
- int entryIndex = _container.FindEntry(key, out _);
-
- // if we found a key we should just update, if no we should create a new entry.
- if (entryIndex != -1)
- {
- _container.UpdateValue(entryIndex, value);
- }
- else
- {
- CreateEntry(key, value);
- }
- }
- }
-
- /// <summary>Removes a key and its value from the table.</summary>
- /// <param name="key">key to remove. May not be null.</param>
- /// <returns>true if the key is found and removed. Returns false if the key was not in the dictionary.</returns>
- /// <remarks>
- /// The key may get garbage collected during the Remove() operation. If so,
- /// Remove() will not fail or throw, however, the return value can be either true or false
- /// depending on who wins the race.
- /// </remarks>
- public bool Remove(TKey key)
- {
- if (key is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
-
- lock (_lock)
- {
- return _container.Remove(key);
- }
- }
-
- /// <summary>Clear all the key/value pairs</summary>
- public void Clear()
- {
- lock (_lock)
- {
- // To clear, we would prefer to simply drop the existing container
- // and replace it with an empty one, as that's overall more efficient.
- // However, if there are any active enumerators, we don't want to do
- // that as it will end up removing all of the existing entries and
- // allowing new items to be added at the same indices when the container
- // is filled and replaced, and one of the guarantees we try to make with
- // enumeration is that new items added after enumeration starts won't be
- // included in the enumeration. As such, if there are active enumerators,
- // we simply use the container's removal functionality to remove all of the
- // keys; then when the table is resized, if there are still active enumerators,
- // these empty slots will be maintained.
- if (_activeEnumeratorRefCount > 0)
- {
- _container.RemoveAllKeys();
- }
- else
- {
- _container = new Container(this);
- }
- }
- }
-
- /// <summary>
- /// Atomically searches for a specified key in the table and returns the corresponding value.
- /// If the key does not exist in the table, the method invokes a callback method to create a
- /// value that is bound to the specified key.
- /// </summary>
- /// <param name="key">key of the value to find. Cannot be null.</param>
- /// <param name="createValueCallback">callback that creates value for key. Cannot be null.</param>
- /// <returns></returns>
- /// <remarks>
- /// If multiple threads try to initialize the same key, the table may invoke createValueCallback
- /// multiple times with the same key. Exactly one of these calls will succeed and the returned
- /// value of that call will be the one added to the table and returned by all the racing GetValue() calls.
- /// This rule permits the table to invoke createValueCallback outside the internal table lock
- /// to prevent deadlocks.
- /// </remarks>
- public TValue GetValue(TKey key, CreateValueCallback createValueCallback)
- {
- // key is validated by TryGetValue
-
- if (createValueCallback is null)
- {
- throw new ArgumentNullException(nameof(createValueCallback));
- }
-
- return TryGetValue(key, out TValue existingValue) ?
- existingValue :
- GetValueLocked(key, createValueCallback);
- }
-
- private TValue GetValueLocked(TKey key, CreateValueCallback createValueCallback)
- {
- // If we got here, the key was not in the table. Invoke the callback (outside the lock)
- // to generate the new value for the key.
- TValue newValue = createValueCallback(key);
-
- lock (_lock)
- {
- // Now that we've taken the lock, must recheck in case we lost a race to add the key.
- if (_container.TryGetValueWorker(key, out TValue existingValue))
- {
- return existingValue;
- }
- else
- {
- // Verified in-lock that we won the race to add the key. Add it now.
- CreateEntry(key, newValue);
- return newValue;
- }
- }
- }
-
- /// <summary>
- /// Helper method to call GetValue without passing a creation delegate. Uses Activator.CreateInstance
- /// to create new instances as needed. If TValue does not have a default constructor, this will throw.
- /// </summary>
- /// <param name="key">key of the value to find. Cannot be null.</param>
- public TValue GetOrCreateValue(TKey key) => GetValue(key, _ => Activator.CreateInstance<TValue>());
-
- public delegate TValue CreateValueCallback(TKey key);
-
- /// <summary>Gets an enumerator for the table.</summary>
- /// <remarks>
- /// The returned enumerator will not extend the lifetime of
- /// any object pairs in the table, other than the one that's Current. It will not return entries
- /// that have already been collected, nor will it return entries added after the enumerator was
- /// retrieved. It may not return all entries that were present when the enumerat was retrieved,
- /// however, such as not returning entries that were collected or removed after the enumerator
- /// was retrieved but before they were enumerated.
- /// </remarks>
- IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
- {
- lock (_lock)
- {
- Container c = _container;
- return c is null || c.FirstFreeEntry == 0 ?
- ((IEnumerable<KeyValuePair<TKey, TValue>>)Array.Empty<KeyValuePair<TKey, TValue>>()).GetEnumerator() :
- new Enumerator(this);
- }
- }
-
- IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable<KeyValuePair<TKey, TValue>>)this).GetEnumerator();
-
- /// <summary>Provides an enumerator for the table.</summary>
- private sealed class Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>
- {
- // The enumerator would ideally hold a reference to the Container and the end index within that
- // container. However, the safety of the CWT depends on the only reference to the Container being
- // from the CWT itself; the Container then employs a two-phase finalization scheme, where the first
- // phase nulls out that parent CWT's reference, guaranteeing that the second time it's finalized there
- // can be no other existing references to it in use that would allow for concurrent usage of the
- // native handles with finalization. We would break that if we allowed this Enumerator to hold a
- // reference to the Container. Instead, the Enumerator holds a reference to the CWT rather than to
- // the Container, and it maintains the CWT._activeEnumeratorRefCount field to track whether there
- // are outstanding enumerators that have yet to be disposed/finalized. If there aren't any, the CWT
- // behaves as it normally does. If there are, certain operations are affected, in particular resizes.
- // Normally when the CWT is resized, it enumerates the contents of the table looking for indices that
- // contain entries which have been collected or removed, and it frees those up, effectively moving
- // down all subsequent entries in the container (not in the existing container, but in a replacement).
- // This, however, would cause the enumerator's understanding of indices to break. So, as long as
- // there is any outstanding enumerator, no compaction is performed.
-
- private ConditionalWeakTable<TKey, TValue>? _table; // parent table, set to null when disposed
- private readonly int _maxIndexInclusive; // last index in the container that should be enumerated
- private int _currentIndex; // the current index into the container
- private KeyValuePair<TKey, TValue> _current; // the current entry set by MoveNext and returned from Current
-
- public Enumerator(ConditionalWeakTable<TKey, TValue> table)
- {
- Debug.Assert(table != null, "Must provide a valid table");
- Debug.Assert(Monitor.IsEntered(table._lock), "Must hold the _lock lock to construct the enumerator");
- Debug.Assert(table._container != null, "Should not be used on a finalized table");
- Debug.Assert(table._container.FirstFreeEntry > 0, "Should have returned an empty enumerator instead");
-
- // Store a reference to the parent table and increase its active enumerator count.
- _table = table;
- Debug.Assert(table._activeEnumeratorRefCount >= 0, "Should never have a negative ref count before incrementing");
- table._activeEnumeratorRefCount++;
-
- // Store the max index to be enumerated.
- _maxIndexInclusive = table._container.FirstFreeEntry - 1;
- _currentIndex = -1;
- }
-
- ~Enumerator()
- {
- Dispose();
- }
-
- public void Dispose()
- {
- // Use an interlocked operation to ensure that only one thread can get access to
- // the _table for disposal and thus only decrement the ref count once.
- ConditionalWeakTable<TKey, TValue>? table = Interlocked.Exchange(ref _table, null);
- if (table != null)
- {
- // Ensure we don't keep the last current alive unnecessarily
- _current = default;
-
- // Decrement the ref count that was incremented when constructed
- lock (table._lock)
- {
- table._activeEnumeratorRefCount--;
- Debug.Assert(table._activeEnumeratorRefCount >= 0, "Should never have a negative ref count after decrementing");
- }
-
- // Finalization is purely to decrement the ref count. We can suppress it now.
- GC.SuppressFinalize(this);
- }
- }
-
- public bool MoveNext()
- {
- // Start by getting the current table. If it's already been disposed, it will be null.
- ConditionalWeakTable<TKey, TValue>? table = _table;
- if (table != null)
- {
- // Once have the table, we need to lock to synchronize with other operations on
- // the table, like adding.
- lock (table._lock)
- {
- // From the table, we have to get the current container. This could have changed
- // since we grabbed the enumerator, but the index-to-pair mapping should not have
- // due to there being at least one active enumerator. If the table (or rather its
- // container at the time) has already been finalized, this will be null.
- Container c = table._container;
- if (c != null)
- {
- // We have the container. Find the next entry to return, if there is one.
- // We need to loop as we may try to get an entry that's already been removed
- // or collected, in which case we try again.
- while (_currentIndex < _maxIndexInclusive)
- {
- _currentIndex++;
- if (c.TryGetEntry(_currentIndex, out TKey? key, out TValue value))
- {
- _current = new KeyValuePair<TKey, TValue>(key, value);
- return true;
- }
- }
- }
- }
- }
-
- // Nothing more to enumerate.
- return false;
- }
-
- public KeyValuePair<TKey, TValue> Current
- {
- get
- {
- if (_currentIndex < 0)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
- }
- return _current;
- }
- }
-
- object? IEnumerator.Current => Current;
-
- public void Reset() { }
- }
-
- /// <summary>Worker for adding a new key/value pair. Will resize the container if it is full.</summary>
- /// <param name="key"></param>
- /// <param name="value"></param>
- private void CreateEntry(TKey key, TValue value)
- {
- Debug.Assert(Monitor.IsEntered(_lock));
- Debug.Assert(key != null); // key already validated as non-null and not already in table.
-
- Container c = _container;
- if (!c.HasCapacity)
- {
- _container = c = c.Resize();
- }
- c.CreateEntryNoResize(key, value);
- }
-
- private static bool IsPowerOfTwo(int value) => (value > 0) && ((value & (value - 1)) == 0);
-
- //--------------------------------------------------------------------------------------------
- // Entry can be in one of four states:
- //
- // - Unused (stored with an index _firstFreeEntry and above)
- // depHnd.IsAllocated == false
- // hashCode == <dontcare>
- // next == <dontcare>)
- //
- // - Used with live key (linked into a bucket list where _buckets[hashCode & (_buckets.Length - 1)] points to first entry)
- // depHnd.IsAllocated == true, depHnd.GetPrimary() != null
- // hashCode == RuntimeHelpers.GetHashCode(depHnd.GetPrimary()) & int.MaxValue
- // next links to next Entry in bucket.
- //
- // - Used with dead key (linked into a bucket list where _buckets[hashCode & (_buckets.Length - 1)] points to first entry)
- // depHnd.IsAllocated == true, depHnd.GetPrimary() is null
- // hashCode == <notcare>
- // next links to next Entry in bucket.
- //
- // - Has been removed from the table (by a call to Remove)
- // depHnd.IsAllocated == true, depHnd.GetPrimary() == <notcare>
- // hashCode == -1
- // next links to next Entry in bucket.
- //
- // The only difference between "used with live key" and "used with dead key" is that
- // depHnd.GetPrimary() returns null. The transition from "used with live key" to "used with dead key"
- // happens asynchronously as a result of normal garbage collection. The dictionary itself
- // receives no notification when this happens.
- //
- // When the dictionary grows the _entries table, it scours it for expired keys and does not
- // add those to the new container.
- //--------------------------------------------------------------------------------------------
- private struct Entry
- {
- public DependentHandle depHnd; // Holds key and value using a weak reference for the key and a strong reference
- // for the value that is traversed only if the key is reachable without going through the value.
- public int HashCode; // Cached copy of key's hashcode
- public int Next; // Index of next entry, -1 if last
- }
-
- /// <summary>
- /// Container holds the actual data for the table. A given instance of Container always has the same capacity. When we need
- /// more capacity, we create a new Container, copy the old one into the new one, and discard the old one. This helps enable lock-free
- /// reads from the table, as readers never need to deal with motion of entries due to rehashing.
- /// </summary>
- private sealed class Container
- {
- private readonly ConditionalWeakTable<TKey, TValue> _parent; // the ConditionalWeakTable with which this container is associated
- private int[] _buckets; // _buckets[hashcode & (_buckets.Length - 1)] contains index of the first entry in bucket (-1 if empty)
- private Entry[] _entries; // the table entries containing the stored dependency handles
- private int _firstFreeEntry; // _firstFreeEntry < _entries.Length => table has capacity, entries grow from the bottom of the table.
- private bool _invalid; // flag detects if OOM or other background exception threw us out of the lock.
- private bool _finalized; // set to true when initially finalized
- private volatile object? _oldKeepAlive; // used to ensure the next allocated container isn't finalized until this one is GC'd
-
- internal Container(ConditionalWeakTable<TKey, TValue> parent)
- {
- Debug.Assert(parent != null);
- Debug.Assert(IsPowerOfTwo(InitialCapacity));
-
- const int Size = InitialCapacity;
- _buckets = new int[Size];
- for (int i = 0; i < _buckets.Length; i++)
- {
- _buckets[i] = -1;
- }
- _entries = new Entry[Size];
-
- // Only store the parent after all of the allocations have happened successfully.
- // Otherwise, as part of growing or clearing the container, we could end up allocating
- // a new Container that fails (OOMs) part way through construction but that gets finalized
- // and ends up clearing out some other container present in the associated CWT.
- _parent = parent;
- }
-
- private Container(ConditionalWeakTable<TKey, TValue> parent, int[] buckets, Entry[] entries, int firstFreeEntry)
- {
- Debug.Assert(parent != null);
- Debug.Assert(buckets != null);
- Debug.Assert(entries != null);
- Debug.Assert(buckets.Length == entries.Length);
- Debug.Assert(IsPowerOfTwo(buckets.Length));
-
- _parent = parent;
- _buckets = buckets;
- _entries = entries;
- _firstFreeEntry = firstFreeEntry;
- }
-
- internal bool HasCapacity => _firstFreeEntry < _entries.Length;
-
- internal int FirstFreeEntry => _firstFreeEntry;
-
- /// <summary>Worker for adding a new key/value pair. Container must NOT be full.</summary>
- internal void CreateEntryNoResize(TKey key, TValue value)
- {
- Debug.Assert(key != null); // key already validated as non-null and not already in table.
- Debug.Assert(HasCapacity);
-
- VerifyIntegrity();
- _invalid = true;
-
- int hashCode = RuntimeHelpers.GetHashCode(key) & int.MaxValue;
- int newEntry = _firstFreeEntry++;
-
- _entries[newEntry].HashCode = hashCode;
- _entries[newEntry].depHnd = new DependentHandle(key, value);
- int bucket = hashCode & (_buckets.Length - 1);
- _entries[newEntry].Next = _buckets[bucket];
-
- // This write must be volatile, as we may be racing with concurrent readers. If they see
- // the new entry, they must also see all of the writes earlier in this method.
- Volatile.Write(ref _buckets[bucket], newEntry);
-
- _invalid = false;
- }
-
- /// <summary>Worker for finding a key/value pair. Must hold _lock.</summary>
- internal bool TryGetValueWorker(TKey key, [MaybeNullWhen(false)] out TValue value)
- {
- Debug.Assert(key != null); // Key already validated as non-null
-
- int entryIndex = FindEntry(key, out object? secondary);
- value = Unsafe.As<TValue>(secondary);
- return entryIndex != -1;
- }
-
- /// <summary>
- /// Returns -1 if not found (if key expires during FindEntry, this can be treated as "not found.").
- /// Must hold _lock, or be prepared to retry the search while holding _lock.
- /// </summary>
- internal int FindEntry(TKey key, out object? value)
- {
- Debug.Assert(key != null); // Key already validated as non-null.
-
- int hashCode = RuntimeHelpers.GetHashCode(key) & int.MaxValue;
- int bucket = hashCode & (_buckets.Length - 1);
- for (int entriesIndex = Volatile.Read(ref _buckets[bucket]); entriesIndex != -1; entriesIndex = _entries[entriesIndex].Next)
- {
- if (_entries[entriesIndex].HashCode == hashCode && _entries[entriesIndex].depHnd.GetPrimaryAndSecondary(out value) == key)
- {
- GC.KeepAlive(this); // ensure we don't get finalized while accessing DependentHandles.
- return entriesIndex;
- }
- }
-
- GC.KeepAlive(this); // ensure we don't get finalized while accessing DependentHandles.
- value = null;
- return -1;
- }
-
- /// <summary>Gets the entry at the specified entry index.</summary>
- internal bool TryGetEntry(int index, [NotNullWhen(true)] out TKey? key, [MaybeNullWhen(false)] out TValue value)
- {
- if (index < _entries.Length)
- {
- object? oKey = _entries[index].depHnd.GetPrimaryAndSecondary(out object? oValue);
- GC.KeepAlive(this); // ensure we don't get finalized while accessing DependentHandles.
-
- if (oKey != null)
- {
- key = Unsafe.As<TKey>(oKey);
- value = Unsafe.As<TValue>(oValue);
- return true;
- }
- }
-
- key = default;
- value = default!;
- return false;
- }
-
- /// <summary>Removes all of the keys in the table.</summary>
- internal void RemoveAllKeys()
- {
- for (int i = 0; i < _firstFreeEntry; i++)
- {
- RemoveIndex(i);
- }
- }
-
- /// <summary>Removes the specified key from the table, if it exists.</summary>
- internal bool Remove(TKey key)
- {
- VerifyIntegrity();
-
- int entryIndex = FindEntry(key, out _);
- if (entryIndex != -1)
- {
- RemoveIndex(entryIndex);
- return true;
- }
-
- return false;
- }
-
- private void RemoveIndex(int entryIndex)
- {
- Debug.Assert(entryIndex >= 0 && entryIndex < _firstFreeEntry);
-
- ref Entry entry = ref _entries[entryIndex];
-
- // We do not free the handle here, as we may be racing with readers who already saw the hash code.
- // Instead, we simply overwrite the entry's hash code, so subsequent reads will ignore it.
- // The handle will be free'd in Container's finalizer, after the table is resized or discarded.
- Volatile.Write(ref entry.HashCode, -1);
-
- // Also, clear the key to allow GC to collect objects pointed to by the entry
- entry.depHnd.SetPrimary(null);
- }
-
- internal void UpdateValue(int entryIndex, TValue newValue)
- {
- Debug.Assert(entryIndex != -1);
-
- VerifyIntegrity();
- _invalid = true;
-
- _entries[entryIndex].depHnd.SetSecondary(newValue);
-
- _invalid = false;
- }
-
- /// <summary>Resize, and scrub expired keys off bucket lists. Must hold _lock.</summary>
- /// <remarks>
- /// _firstEntry is less than _entries.Length on exit, that is, the table has at least one free entry.
- /// </remarks>
- internal Container Resize()
- {
- Debug.Assert(!HasCapacity);
-
- bool hasExpiredEntries = false;
- int newSize = _buckets.Length;
-
- if (_parent is null || _parent._activeEnumeratorRefCount == 0)
- {
- // If any expired or removed keys exist, we won't resize.
- // If there any active enumerators, though, we don't want
- // to compact and thus have no expired entries.
- for (int entriesIndex = 0; entriesIndex < _entries.Length; entriesIndex++)
- {
- ref Entry entry = ref _entries[entriesIndex];
-
- if (entry.HashCode == -1)
- {
- // the entry was removed
- hasExpiredEntries = true;
- break;
- }
-
- if (entry.depHnd.IsAllocated && entry.depHnd.GetPrimary() is null)
- {
- // the entry has expired
- hasExpiredEntries = true;
- break;
- }
- }
- }
-
- if (!hasExpiredEntries)
- {
- // Not necessary to check for overflow here, the attempt to allocate new arrays will throw
- newSize = _buckets.Length * 2;
- }
-
- return Resize(newSize);
- }
-
- internal Container Resize(int newSize)
- {
- Debug.Assert(newSize >= _buckets.Length);
- Debug.Assert(IsPowerOfTwo(newSize));
-
- // Reallocate both buckets and entries and rebuild the bucket and entries from scratch.
- // This serves both to scrub entries with expired keys and to put the new entries in the proper bucket.
- int[] newBuckets = new int[newSize];
- for (int bucketIndex = 0; bucketIndex < newBuckets.Length; bucketIndex++)
- {
- newBuckets[bucketIndex] = -1;
- }
- Entry[] newEntries = new Entry[newSize];
- int newEntriesIndex = 0;
- bool activeEnumerators = _parent != null && _parent._activeEnumeratorRefCount > 0;
-
- // Migrate existing entries to the new table.
- if (activeEnumerators)
- {
- // There's at least one active enumerator, which means we don't want to
- // remove any expired/removed entries, in order to not affect existing
- // entries indices. Copy over the entries while rebuilding the buckets list,
- // as the buckets are dependent on the buckets list length, which is changing.
- for (; newEntriesIndex < _entries.Length; newEntriesIndex++)
- {
- ref Entry oldEntry = ref _entries[newEntriesIndex];
- ref Entry newEntry = ref newEntries[newEntriesIndex];
- int hashCode = oldEntry.HashCode;
-
- newEntry.HashCode = hashCode;
- newEntry.depHnd = oldEntry.depHnd;
- int bucket = hashCode & (newBuckets.Length - 1);
- newEntry.Next = newBuckets[bucket];
- newBuckets[bucket] = newEntriesIndex;
- }
- }
- else
- {
- // There are no active enumerators, which means we want to compact by
- // removing expired/removed entries.
- for (int entriesIndex = 0; entriesIndex < _entries.Length; entriesIndex++)
- {
- ref Entry oldEntry = ref _entries[entriesIndex];
- int hashCode = oldEntry.HashCode;
- DependentHandle depHnd = oldEntry.depHnd;
- if (hashCode != -1 && depHnd.IsAllocated)
- {
- if (depHnd.GetPrimary() != null)
- {
- ref Entry newEntry = ref newEntries[newEntriesIndex];
-
- // Entry is used and has not expired. Link it into the appropriate bucket list.
- newEntry.HashCode = hashCode;
- newEntry.depHnd = depHnd;
- int bucket = hashCode & (newBuckets.Length - 1);
- newEntry.Next = newBuckets[bucket];
- newBuckets[bucket] = newEntriesIndex;
- newEntriesIndex++;
- }
- else
- {
- // Pretend the item was removed, so that this container's finalizer
- // will clean up this dependent handle.
- Volatile.Write(ref oldEntry.HashCode, -1);
- }
- }
- }
- }
-
- // Create the new container. We want to transfer the responsibility of freeing the handles from
- // the old container to the new container, and also ensure that the new container isn't finalized
- // while the old container may still be in use. As such, we store a reference from the old container
- // to the new one, which will keep the new container alive as long as the old one is.
- var newContainer = new Container(_parent!, newBuckets, newEntries, newEntriesIndex);
- if (activeEnumerators)
- {
- // If there are active enumerators, both the old container and the new container may be storing
- // the same entries with -1 hash codes, which the finalizer will clean up even if the container
- // is not the active container for the table. To prevent that, we want to stop the old container
- // from being finalized, as it no longer has any responsibility for any cleanup.
- GC.SuppressFinalize(this);
- }
- _oldKeepAlive = newContainer; // once this is set, the old container's finalizer will not free transferred dependent handles
-
- GC.KeepAlive(this); // ensure we don't get finalized while accessing DependentHandles.
-
- return newContainer;
- }
-
- private void VerifyIntegrity()
- {
- if (_invalid)
- {
- throw new InvalidOperationException(SR.InvalidOperation_CollectionCorrupted);
- }
- }
-
- ~Container()
- {
- // Skip doing anything if the container is invalid, including if somehow
- // the container object was allocated but its associated table never set.
- if (_invalid || _parent is null)
- {
- return;
- }
-
- // It's possible that the ConditionalWeakTable could have been resurrected, in which case code could
- // be accessing this Container as it's being finalized. We don't support usage after finalization,
- // but we also don't want to potentially corrupt state by allowing dependency handles to be used as
- // or after they've been freed. To avoid that, if it's at all possible that another thread has a
- // reference to this container via the CWT, we remove such a reference and then re-register for
- // finalization: the next time around, we can be sure that no references remain to this and we can
- // clean up the dependency handles without fear of corruption.
- if (!_finalized)
- {
- _finalized = true;
- lock (_parent._lock)
- {
- if (_parent._container == this)
- {
- _parent._container = null!;
- }
- }
- GC.ReRegisterForFinalize(this); // next time it's finalized, we'll be sure there are no remaining refs
- return;
- }
-
- Entry[] entries = _entries;
- _invalid = true;
- _entries = null!;
- _buckets = null!;
-
- if (entries != null)
- {
- for (int entriesIndex = 0; entriesIndex < entries.Length; entriesIndex++)
- {
- // We need to free handles in two cases:
- // - If this container still owns the dependency handle (meaning ownership hasn't been transferred
- // to another container that replaced this one), then it should be freed.
- // - If this container had the entry removed, then even if in general ownership was transferred to
- // another container, removed entries are not, therefore this container must free them.
- if (_oldKeepAlive is null || entries[entriesIndex].HashCode == -1)
- {
- entries[entriesIndex].depHnd.Free();
- }
- }
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredAsyncDisposable.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredAsyncDisposable.cs
deleted file mode 100644
index aa5e882dc65..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredAsyncDisposable.cs
+++ /dev/null
@@ -1,27 +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 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);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredCancelableAsyncEnumerable.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredCancelableAsyncEnumerable.cs
deleted file mode 100644
index 4f1bca71695..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredCancelableAsyncEnumerable.cs
+++ /dev/null
@@ -1,78 +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 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);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs
deleted file mode 100644
index 493269218df..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs
+++ /dev/null
@@ -1,225 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Threading.Tasks.Sources;
-
-#if !NETSTANDARD2_0
-using Internal.Runtime.CompilerServices;
-#endif
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>Provides an awaitable type that enables configured awaits on a <see cref="ValueTask"/>.</summary>
- [StructLayout(LayoutKind.Auto)]
- public readonly struct ConfiguredValueTaskAwaitable
- {
- /// <summary>The wrapped <see cref="Task"/>.</summary>
- private readonly ValueTask _value;
-
- /// <summary>Initializes the awaitable.</summary>
- /// <param name="value">The wrapped <see cref="ValueTask"/>.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal ConfiguredValueTaskAwaitable(in ValueTask value) => _value = value;
-
- /// <summary>Returns an awaiter for this <see cref="ConfiguredValueTaskAwaitable"/> instance.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ConfiguredValueTaskAwaiter GetAwaiter() => new ConfiguredValueTaskAwaiter(in _value);
-
- /// <summary>Provides an awaiter for a <see cref="ConfiguredValueTaskAwaitable"/>.</summary>
- [StructLayout(LayoutKind.Auto)]
- public readonly struct ConfiguredValueTaskAwaiter : ICriticalNotifyCompletion, IStateMachineBoxAwareAwaiter
- {
- /// <summary>The value being awaited.</summary>
- private readonly ValueTask _value;
-
- /// <summary>Initializes the awaiter.</summary>
- /// <param name="value">The value to be awaited.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal ConfiguredValueTaskAwaiter(in ValueTask value) => _value = value;
-
- /// <summary>Gets whether the <see cref="ConfiguredValueTaskAwaitable"/> has completed.</summary>
- public bool IsCompleted
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => _value.IsCompleted;
- }
-
- /// <summary>Gets the result of the ValueTask.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void GetResult() => _value.ThrowIfCompletedUnsuccessfully();
-
- /// <summary>Schedules the continuation action for the <see cref="ConfiguredValueTaskAwaitable"/>.</summary>
- public void OnCompleted(Action continuation)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
-
- if (obj is Task t)
- {
- t.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().OnCompleted(continuation);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token,
- ValueTaskSourceOnCompletedFlags.FlowExecutionContext |
- (_value._continueOnCapturedContext ? ValueTaskSourceOnCompletedFlags.UseSchedulingContext : ValueTaskSourceOnCompletedFlags.None));
- }
- else
- {
- ValueTask.CompletedTask.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().OnCompleted(continuation);
- }
- }
-
- /// <summary>Schedules the continuation action for the <see cref="ConfiguredValueTaskAwaitable"/>.</summary>
- public void UnsafeOnCompleted(Action continuation)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
-
- if (obj is Task t)
- {
- t.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token,
- _value._continueOnCapturedContext ? ValueTaskSourceOnCompletedFlags.UseSchedulingContext : ValueTaskSourceOnCompletedFlags.None);
- }
- else
- {
- ValueTask.CompletedTask.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation);
- }
- }
-
- void IStateMachineBoxAwareAwaiter.AwaitUnsafeOnCompleted(IAsyncStateMachineBox box)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
-
- if (obj is Task t)
- {
- TaskAwaiter.UnsafeOnCompletedInternal(t, box, _value._continueOnCapturedContext);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource>(obj).OnCompleted(ThreadPoolGlobals.s_invokeAsyncStateMachineBox, box, _value._token,
- _value._continueOnCapturedContext ? ValueTaskSourceOnCompletedFlags.UseSchedulingContext : ValueTaskSourceOnCompletedFlags.None);
- }
- else
- {
- TaskAwaiter.UnsafeOnCompletedInternal(Task.CompletedTask, box, _value._continueOnCapturedContext);
- }
- }
- }
- }
-
- /// <summary>Provides an awaitable type that enables configured awaits on a <see cref="ValueTask{TResult}"/>.</summary>
- /// <typeparam name="TResult">The type of the result produced.</typeparam>
- [StructLayout(LayoutKind.Auto)]
- public readonly struct ConfiguredValueTaskAwaitable<TResult>
- {
- /// <summary>The wrapped <see cref="ValueTask{TResult}"/>.</summary>
- private readonly ValueTask<TResult> _value;
-
- /// <summary>Initializes the awaitable.</summary>
- /// <param name="value">The wrapped <see cref="ValueTask{TResult}"/>.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal ConfiguredValueTaskAwaitable(in ValueTask<TResult> value) => _value = value;
-
- /// <summary>Returns an awaiter for this <see cref="ConfiguredValueTaskAwaitable{TResult}"/> instance.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ConfiguredValueTaskAwaiter GetAwaiter() => new ConfiguredValueTaskAwaiter(in _value);
-
- /// <summary>Provides an awaiter for a <see cref="ConfiguredValueTaskAwaitable{TResult}"/>.</summary>
- [StructLayout(LayoutKind.Auto)]
- public readonly struct ConfiguredValueTaskAwaiter : ICriticalNotifyCompletion, IStateMachineBoxAwareAwaiter
- {
- /// <summary>The value being awaited.</summary>
- private readonly ValueTask<TResult> _value;
-
- /// <summary>Initializes the awaiter.</summary>
- /// <param name="value">The value to be awaited.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal ConfiguredValueTaskAwaiter(in ValueTask<TResult> value) => _value = value;
-
- /// <summary>Gets whether the <see cref="ConfiguredValueTaskAwaitable{TResult}"/> has completed.</summary>
- public bool IsCompleted
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => _value.IsCompleted;
- }
-
- /// <summary>Gets the result of the ValueTask.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public TResult GetResult() => _value.Result;
-
- /// <summary>Schedules the continuation action for the <see cref="ConfiguredValueTaskAwaitable{TResult}"/>.</summary>
- public void OnCompleted(Action continuation)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj is Task<TResult> t)
- {
- t.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().OnCompleted(continuation);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token,
- ValueTaskSourceOnCompletedFlags.FlowExecutionContext |
- (_value._continueOnCapturedContext ? ValueTaskSourceOnCompletedFlags.UseSchedulingContext : ValueTaskSourceOnCompletedFlags.None));
- }
- else
- {
- ValueTask.CompletedTask.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().OnCompleted(continuation);
- }
- }
-
- /// <summary>Schedules the continuation action for the <see cref="ConfiguredValueTaskAwaitable{TResult}"/>.</summary>
- public void UnsafeOnCompleted(Action continuation)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj is Task<TResult> t)
- {
- t.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token,
- _value._continueOnCapturedContext ? ValueTaskSourceOnCompletedFlags.UseSchedulingContext : ValueTaskSourceOnCompletedFlags.None);
- }
- else
- {
- ValueTask.CompletedTask.ConfigureAwait(_value._continueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation);
- }
- }
-
- void IStateMachineBoxAwareAwaiter.AwaitUnsafeOnCompleted(IAsyncStateMachineBox box)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj is Task<TResult> t)
- {
- TaskAwaiter.UnsafeOnCompletedInternal(t, box, _value._continueOnCapturedContext);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ThreadPoolGlobals.s_invokeAsyncStateMachineBox, box, _value._token,
- _value._continueOnCapturedContext ? ValueTaskSourceOnCompletedFlags.UseSchedulingContext : ValueTaskSourceOnCompletedFlags.None);
- }
- else
- {
- TaskAwaiter.UnsafeOnCompletedInternal(Task.CompletedTask, box, _value._continueOnCapturedContext);
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs
deleted file mode 100644
index 5adf4471e8f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs
+++ /dev/null
@@ -1,156 +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.
-
-#define DEBUG // The behavior of this contract library should be consistent regardless of build type.
-
-using System.Diagnostics.Contracts;
-
-namespace System.Runtime.CompilerServices
-{
- public static class ContractHelper
- {
- /// <summary>
- /// Allows a managed application environment such as an interactive interpreter (IronPython) or a
- /// web browser host (Jolt hosting Silverlight in IE) to be notified of contract failures and
- /// potentially "handle" them, either by throwing a particular exception type, etc. If any of the
- /// event handlers sets the Cancel flag in the ContractFailedEventArgs, then the Contract class will
- /// not pop up an assert dialog box or trigger escalation policy.
- /// </summary>
- internal static event EventHandler<ContractFailedEventArgs>? InternalContractFailed;
-
- /// <summary>
- /// Rewriter will call this method on a contract failure to allow listeners to be notified.
- /// The method should not perform any failure (assert/throw) itself.
- /// This method has 3 functions:
- /// 1. Call any contract hooks (such as listeners to Contract failed events)
- /// 2. Determine if the listeners deem the failure as handled (then resultFailureMessage should be set to null)
- /// 3. Produce a localized resultFailureMessage used in advertising the failure subsequently.
- /// On exit: null if the event was handled and should not trigger a failure.
- /// Otherwise, returns the localized failure message.
- /// </summary>
- [System.Diagnostics.DebuggerNonUserCode]
- public static string? RaiseContractFailedEvent(ContractFailureKind failureKind, string? userMessage, string? conditionText, Exception? innerException)
- {
- if (failureKind < ContractFailureKind.Precondition || failureKind > ContractFailureKind.Assume)
- throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, failureKind), nameof(failureKind));
-
- string? returnValue;
- string displayMessage = "contract failed."; // Incomplete, but in case of OOM during resource lookup...
- ContractFailedEventArgs? eventArgs = null; // In case of OOM.
-
- try
- {
- displayMessage = GetDisplayMessage(failureKind, userMessage, conditionText);
- EventHandler<ContractFailedEventArgs>? contractFailedEventLocal = InternalContractFailed;
- if (contractFailedEventLocal != null)
- {
- eventArgs = new ContractFailedEventArgs(failureKind, displayMessage, conditionText, innerException);
- foreach (EventHandler<ContractFailedEventArgs> handler in contractFailedEventLocal.GetInvocationList())
- {
- try
- {
- handler(null, eventArgs);
- }
- catch (Exception e)
- {
- eventArgs.thrownDuringHandler = e;
- eventArgs.SetUnwind();
- }
- }
- if (eventArgs.Unwind)
- {
- // unwind
- innerException ??= eventArgs.thrownDuringHandler;
- throw new ContractException(failureKind, displayMessage, userMessage, conditionText, innerException);
- }
- }
- }
- finally
- {
- if (eventArgs != null && eventArgs.Handled)
- {
- returnValue = null; // handled
- }
- else
- {
- returnValue = displayMessage;
- }
- }
-
- return returnValue;
- }
-
- /// <summary>
- /// Rewriter calls this method to get the default failure behavior.
- /// </summary>
- [System.Diagnostics.DebuggerNonUserCode]
- public static void TriggerFailure(ContractFailureKind kind, string? displayMessage, string? userMessage, string? conditionText, Exception? innerException)
- {
- if (string.IsNullOrEmpty(displayMessage))
- {
- displayMessage = GetDisplayMessage(kind, userMessage, conditionText);
- }
-
- System.Diagnostics.Debug.ContractFailure(displayMessage, string.Empty, GetFailureMessage(kind, null));
- }
-
- private static string GetFailureMessage(ContractFailureKind failureKind, string? conditionText)
- {
- bool hasConditionText = !string.IsNullOrEmpty(conditionText);
- switch (failureKind)
- {
- case ContractFailureKind.Assert:
- return hasConditionText ? SR.Format(SR.AssertionFailed_Cnd, conditionText) : SR.AssertionFailed;
-
- case ContractFailureKind.Assume:
- return hasConditionText ? SR.Format(SR.AssumptionFailed_Cnd, conditionText) : SR.AssumptionFailed;
-
- case ContractFailureKind.Precondition:
- return hasConditionText ? SR.Format(SR.PreconditionFailed_Cnd, conditionText) : SR.PreconditionFailed;
-
- case ContractFailureKind.Postcondition:
- return hasConditionText ? SR.Format(SR.PostconditionFailed_Cnd, conditionText) : SR.PostconditionFailed;
-
- case ContractFailureKind.Invariant:
- return hasConditionText ? SR.Format(SR.InvariantFailed_Cnd, conditionText) : SR.InvariantFailed;
-
- case ContractFailureKind.PostconditionOnException:
- return hasConditionText ? SR.Format(SR.PostconditionOnExceptionFailed_Cnd, conditionText) : SR.PostconditionOnExceptionFailed;
-
- default:
- Contract.Assume(false, "Unreachable code");
- return SR.AssumptionFailed;
- }
- }
-
- private static string GetDisplayMessage(ContractFailureKind failureKind, string? userMessage, string? conditionText)
- {
- string failureMessage;
- // Well-formatted English messages will take one of four forms. A sentence ending in
- // either a period or a colon, the condition string, then the message tacked
- // on to the end with two spaces in front.
- // Note that both the conditionText and userMessage may be null. Also,
- // on Silverlight we may not be able to look up a friendly string for the
- // error message. Let's leverage Silverlight's default error message there.
- if (!string.IsNullOrEmpty(conditionText))
- {
- failureMessage = GetFailureMessage(failureKind, conditionText);
- }
- else
- {
- failureMessage = "";
- }
-
- // Now add in the user message, if present.
- if (!string.IsNullOrEmpty(userMessage))
- {
- return failureMessage + " " + userMessage;
- }
- else
- {
- return failureMessage;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CustomConstantAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CustomConstantAttribute.cs
deleted file mode 100644
index f3db0a276b5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/CustomConstantAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
- public abstract class CustomConstantAttribute : Attribute
- {
- public abstract object? Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DateTimeConstantAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DateTimeConstantAttribute.cs
deleted file mode 100644
index 315e9e3b938..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DateTimeConstantAttribute.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
- public sealed class DateTimeConstantAttribute : CustomConstantAttribute
- {
- private readonly DateTime _date;
-
- public DateTimeConstantAttribute(long ticks)
- {
- _date = new DateTime(ticks);
- }
-
-#pragma warning disable CS8608
- public override object Value => _date;
-#pragma warning restore CS8608
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DecimalConstantAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DecimalConstantAttribute.cs
deleted file mode 100644
index 7aea9e6cc78..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DecimalConstantAttribute.cs
+++ /dev/null
@@ -1,39 +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.
-
-// Note: If you add a new ctor overloads you need to update ParameterInfo.RawDefaultValue
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
- public sealed class DecimalConstantAttribute : Attribute
- {
- private readonly decimal _dec;
-
- [CLSCompliant(false)]
- public DecimalConstantAttribute(
- byte scale,
- byte sign,
- uint hi,
- uint mid,
- uint low
- )
- {
- _dec = new decimal((int)low, (int)mid, (int)hi, sign != 0, scale);
- }
-
- public DecimalConstantAttribute(
- byte scale,
- byte sign,
- int hi,
- int mid,
- int low
- )
- {
- _dec = new decimal(low, mid, hi, sign != 0, scale);
- }
-
- public decimal Value => _dec;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DefaultDependencyAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DefaultDependencyAttribute.cs
deleted file mode 100644
index 31abdcbb3ec..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DefaultDependencyAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Assembly)]
- public sealed class DefaultDependencyAttribute : Attribute
- {
- public DefaultDependencyAttribute(LoadHint loadHintArgument)
- {
- LoadHint = loadHintArgument;
- }
-
- public LoadHint LoadHint { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DependencyAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DependencyAttribute.cs
deleted file mode 100644
index 5b589fbde82..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DependencyAttribute.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
- public sealed class DependencyAttribute : Attribute
- {
- public DependencyAttribute(string dependentAssemblyArgument, LoadHint loadHintArgument)
- {
- DependentAssembly = dependentAssemblyArgument;
- LoadHint = loadHintArgument;
- }
-
- public string DependentAssembly { get; }
- public LoadHint LoadHint { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DisablePrivateReflectionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DisablePrivateReflectionAttribute.cs
deleted file mode 100644
index dfe4a98a949..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DisablePrivateReflectionAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
- public sealed class DisablePrivateReflectionAttribute : Attribute
- {
- public DisablePrivateReflectionAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DiscardableAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DiscardableAttribute.cs
deleted file mode 100644
index 4a860b15878..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/DiscardableAttribute.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Runtime.CompilerServices
-{
- // Custom attribute to indicating a TypeDef is a discardable attribute.
- [AttributeUsage(AttributeTargets.All)]
- public class DiscardableAttribute : Attribute
- {
- public DiscardableAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ExtensionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ExtensionAttribute.cs
deleted file mode 100644
index d971d633ef3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ExtensionAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Indicates that a method is an extension method, or that a class or assembly contains extension methods.
- /// </summary>
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
- public sealed class ExtensionAttribute : Attribute { }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FixedAddressValueTypeAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FixedAddressValueTypeAttribute.cs
deleted file mode 100644
index 1810340f545..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FixedAddressValueTypeAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Field)]
- public sealed class FixedAddressValueTypeAttribute : Attribute
- {
- public FixedAddressValueTypeAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FixedBufferAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FixedBufferAttribute.cs
deleted file mode 100644
index 2215606c19d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FixedBufferAttribute.cs
+++ /dev/null
@@ -1,30 +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.
-
-/*============================================================
-**
-**
-** Purpose: Used by a compiler for generating value types
-** in-place within other value types containing a certain
-** number of elements of the given (primitive) type. Somewhat
-** similar to P/Invoke's ByValTStr attribute.
-** Used by C# with this syntax: "fixed int buffer[10];"
-**
-===========================================================*/
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Field, Inherited = false)]
- public sealed class FixedBufferAttribute : Attribute
- {
- public FixedBufferAttribute(Type elementType, int length)
- {
- ElementType = elementType;
- Length = length;
- }
-
- public Type ElementType { get; }
- public int Length { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FormattableStringFactory.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FormattableStringFactory.cs
deleted file mode 100644
index c08ebaee061..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/FormattableStringFactory.cs
+++ /dev/null
@@ -1,58 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: implementation of the FormattableStringFactory
-** class.
-**
-===========================================================*/
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// A factory type used by compilers to create instances of the type <see cref="FormattableString"/>.
- /// </summary>
- public static class FormattableStringFactory
- {
- /// <summary>
- /// Create a <see cref="FormattableString"/> from a composite format string and object
- /// array containing zero or more objects to format.
- /// </summary>
- public static FormattableString Create(string format, params object?[] arguments)
- {
- if (format == null)
- {
- throw new ArgumentNullException(nameof(format));
- }
-
- if (arguments == null)
- {
- throw new ArgumentNullException(nameof(arguments));
- }
-
- return new ConcreteFormattableString(format, arguments);
- }
-
- private sealed class ConcreteFormattableString : FormattableString
- {
- private readonly string _format;
- private readonly object?[] _arguments;
-
- internal ConcreteFormattableString(string format, object?[] arguments)
- {
- _format = format;
- _arguments = arguments;
- }
-
- public override string Format => _format;
- public override object?[] GetArguments() { return _arguments; }
- public override int ArgumentCount => _arguments.Length;
- public override object? GetArgument(int index) { return _arguments[index]; }
- public override string ToString(IFormatProvider? formatProvider) { return string.Format(formatProvider, _format, _arguments); }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IAsyncStateMachine.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IAsyncStateMachine.cs
deleted file mode 100644
index 7fb7ea53952..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IAsyncStateMachine.cs
+++ /dev/null
@@ -1,27 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// Represents state machines generated for asynchronous methods.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Represents state machines generated for asynchronous methods.
- /// This type is intended for compiler use only.
- /// </summary>
- public interface IAsyncStateMachine
- {
- /// <summary>Moves the state machine to its next state.</summary>
- void MoveNext();
- /// <summary>Configures the state machine with a heap-allocated replica.</summary>
- /// <param name="stateMachine">The heap-allocated replica.</param>
- void SetStateMachine(IAsyncStateMachine stateMachine);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IAsyncStateMachineBox.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IAsyncStateMachineBox.cs
deleted file mode 100644
index bb09d35dd7d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IAsyncStateMachineBox.cs
+++ /dev/null
@@ -1,24 +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.
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// An interface implemented by all <see cref="AsyncTaskMethodBuilder{TResult}.AsyncStateMachineBox{TStateMachine}"/> instances, regardless of generics.
- /// </summary>
- internal interface IAsyncStateMachineBox
- {
- /// <summary>Move the state machine forward.</summary>
- void MoveNext();
-
- /// <summary>
- /// Gets an action for moving forward the contained state machine.
- /// This will lazily-allocate the delegate as needed.
- /// </summary>
- Action MoveNextAction { get; }
-
- /// <summary>Gets the state machine as a boxed object. This should only be used for debugging purposes.</summary>
- IAsyncStateMachine GetStateMachineObject();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ICastable.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ICastable.cs
deleted file mode 100644
index 7320c2d0840..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ICastable.cs
+++ /dev/null
@@ -1,61 +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 System.Diagnostics.CodeAnalysis;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Support for dynamic interface casting. Specifically implementing this interface on a type will allow the
- /// type to support interfaces (for the purposes of casting and interface dispatch) that do not appear in its
- /// interface map.
- /// </summary>
- public interface ICastable
- {
- // This is called if casting this object to the given interface type would otherwise fail. Casting
- // here means the IL isinst and castclass instructions in the case where they are given an interface
- // type as the target type.
- //
- // A return value of true indicates the cast is valid.
- //
- // If false is returned when this is called as part of a castclass then the usual InvalidCastException
- // will be thrown unless an alternate exception is assigned to the castError output parameter. This
- // parameter is ignored on successful casts or during the evaluation of an isinst (which returns null
- // rather than throwing on error).
- //
- // No exception should be thrown from this method (it will cause unpredictable effects, including the
- // possibility of an immediate failfast).
- //
- // The results of this call are not cached, so it is advisable to provide a performant implementation.
- //
- // The results of this call should be invariant for the same class, interface type pair. That is
- // because this is the only guard placed before an interface invocation at runtime. If a type decides
- // it no longer wants to implement a given interface it has no way to synchronize with callers that
- // have already cached this relationship and can invoke directly via the interface pointer.
- bool IsInstanceOfInterface(RuntimeTypeHandle interfaceType, [NotNullWhen(true)] out Exception? castError);
-
- // This is called as part of the interface dispatch mechanism when the dispatcher logic cannot find
- // the given interface type in the interface map of this object.
- //
- // It allows the implementor to return an alternate class type which does implement the interface. The
- // interface lookup shall be performed again on this type (failure to find the interface this time
- // resulting in a fail fast) and the corresponding implemented method on that class called instead.
- //
- // Naturally, since the call is dispatched to a method on a class which does not match the type of the
- // this pointer, extreme care must be taken in the implementation of the interface methods of this
- // surrogate type.
- //
- // No exception should be thrown from this method (it will cause unpredictable effects, including the
- // possibility of an immediate failfast).
- //
- // There is no error path defined here. By construction all interface dispatches will already have
- // been verified via the castclass/isinst mechanism (and thus a call to IsInstanceOfInterface above)
- // so this method is expected to succeed in all cases. The contract for interface dispatch does not
- // include any errors from the infrastructure, of which this is a part.
- //
- // The results of this lookup are cached so computation of the result is not as perf-sensitive as
- // IsInstanceOfInterface.
- RuntimeTypeHandle GetImplType(RuntimeTypeHandle interfaceType);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/INotifyCompletion.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/INotifyCompletion.cs
deleted file mode 100644
index 24f4f45cbea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/INotifyCompletion.cs
+++ /dev/null
@@ -1,36 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
-//
-//
-//
-// Interfaces used to represent instances that notify listeners of their completion via continuations.
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Represents an operation that will schedule continuations when the operation completes.
- /// </summary>
- public interface INotifyCompletion
- {
- /// <summary>Schedules the continuation action to be invoked when the instance completes.</summary>
- /// <param name="continuation">The action to invoke when the operation completes.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- void OnCompleted(Action continuation);
- }
-
- /// <summary>
- /// Represents an awaiter used to schedule continuations when an await operation completes.
- /// </summary>
- public interface ICriticalNotifyCompletion : INotifyCompletion
- {
- /// <summary>Schedules the continuation action to be invoked when the instance completes.</summary>
- /// <param name="continuation">The action to invoke when the operation completes.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- /// <remarks>Unlike OnCompleted, UnsafeOnCompleted need not propagate ExecutionContext information.</remarks>
- void UnsafeOnCompleted(Action continuation);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ITuple.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ITuple.cs
deleted file mode 100644
index 55b948b3e37..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ITuple.cs
+++ /dev/null
@@ -1,22 +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.
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// This interface is required for types that want to be indexed into by dynamic patterns.
- /// </summary>
- public interface ITuple
- {
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int Length { get; }
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? this[int index] { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IndexerNameAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IndexerNameAttribute.cs
deleted file mode 100644
index bc76250adc8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IndexerNameAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Property, Inherited = true)]
- public sealed class IndexerNameAttribute : Attribute
- {
- public IndexerNameAttribute(string indexerName)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/InternalsVisibleToAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/InternalsVisibleToAttribute.cs
deleted file mode 100644
index 0967b96c1b2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/InternalsVisibleToAttribute.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
- public sealed class InternalsVisibleToAttribute : Attribute
- {
- public InternalsVisibleToAttribute(string assemblyName)
- {
- AssemblyName = assemblyName;
- }
-
- public string AssemblyName { get; }
- public bool AllInternalsVisible { get; set; } = true;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IntrinsicAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IntrinsicAttribute.cs
deleted file mode 100644
index 6bdd91d8448..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IntrinsicAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.CompilerServices
-{
- // Calls to methods or references to fields marked with this attribute may be replaced at
- // some call sites with jit intrinsic expansions.
- // Types marked with this attribute may be specially treated by the runtime/compiler.
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field, Inherited = false)]
- internal sealed class IntrinsicAttribute : Attribute
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsByRefLikeAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsByRefLikeAttribute.cs
deleted file mode 100644
index 90e49d2a425..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsByRefLikeAttribute.cs
+++ /dev/null
@@ -1,21 +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 System.ComponentModel;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Reserved to be used by the compiler for tracking metadata.
- /// This attribute should not be used by developers in source code.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- [AttributeUsage(AttributeTargets.Struct)]
- public sealed class IsByRefLikeAttribute : Attribute
- {
- public IsByRefLikeAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsConst.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsConst.cs
deleted file mode 100644
index 7f948b608a1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsConst.cs
+++ /dev/null
@@ -1,10 +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.
-
-namespace System.Runtime.CompilerServices
-{
- public static partial class IsConst
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsReadOnlyAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsReadOnlyAttribute.cs
deleted file mode 100644
index 657df43957f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsReadOnlyAttribute.cs
+++ /dev/null
@@ -1,21 +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 System.ComponentModel;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Reserved to be used by the compiler for tracking metadata.
- /// This attribute should not be used by developers in source code.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- [AttributeUsage(AttributeTargets.All, Inherited = false)]
- public sealed class IsReadOnlyAttribute : Attribute
- {
- public IsReadOnlyAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsVolatile.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsVolatile.cs
deleted file mode 100644
index 58aaebc8d1a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IsVolatile.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.CompilerServices
-{
- public static class IsVolatile
- {
- // no instantiation, please!
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IteratorStateMachineAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IteratorStateMachineAttribute.cs
deleted file mode 100644
index 53afc956643..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/IteratorStateMachineAttribute.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
- public sealed class IteratorStateMachineAttribute : StateMachineAttribute
- {
- public IteratorStateMachineAttribute(Type stateMachineType)
- : base(stateMachineType)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/LoadHint.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/LoadHint.cs
deleted file mode 100644
index fa490c2c9bb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/LoadHint.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Runtime.CompilerServices
-{
- public enum LoadHint
- {
- Default = 0x0000, // No preference specified
- Always = 0x0001, // Dependency is always loaded
- Sometimes = 0x0002, // Dependency is sometimes loaded
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodCodeType.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodCodeType.cs
deleted file mode 100644
index 841b6661989..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodCodeType.cs
+++ /dev/null
@@ -1,16 +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 System.Reflection;
-
-namespace System.Runtime.CompilerServices
-{
- public enum MethodCodeType
- {
- IL = MethodImplAttributes.IL,
- Native = MethodImplAttributes.Native,
- OPTIL = MethodImplAttributes.OPTIL,
- Runtime = MethodImplAttributes.Runtime
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodImplAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodImplAttribute.cs
deleted file mode 100644
index 18900b37bea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodImplAttribute.cs
+++ /dev/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.
-
-namespace System.Runtime.CompilerServices
-{
- // Custom attribute to specify additional method properties.
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)]
- public sealed class MethodImplAttribute : Attribute
- {
- public MethodCodeType MethodCodeType;
-
- public MethodImplAttribute(MethodImplOptions methodImplOptions)
- {
- Value = methodImplOptions;
- }
-
- public MethodImplAttribute(short value)
- {
- Value = (MethodImplOptions)value;
- }
-
- public MethodImplAttribute()
- {
- }
-
- public MethodImplOptions Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodImplOptions.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodImplOptions.cs
deleted file mode 100644
index 27757683511..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/MethodImplOptions.cs
+++ /dev/null
@@ -1,22 +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.
-
-namespace System.Runtime.CompilerServices
-{
- // This Enum matchs the miImpl flags defined in corhdr.h. It is used to specify
- // certain method properties.
- [Flags]
- public enum MethodImplOptions
- {
- Unmanaged = 0x0004,
- NoInlining = 0x0008,
- ForwardRef = 0x0010,
- Synchronized = 0x0020,
- NoOptimization = 0x0040,
- PreserveSig = 0x0080,
- AggressiveInlining = 0x0100,
- AggressiveOptimization = 0x0200,
- InternalCall = 0x1000
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/PreserveDependencyAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/PreserveDependencyAttribute.cs
deleted file mode 100644
index de14ff35e04..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/PreserveDependencyAttribute.cs
+++ /dev/null
@@ -1,62 +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.
-
-#nullable enable
-
-// TODO https://github.com/dotnet/corefx/issues/41201: Design and expose this publicly.
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>States a dependency that one member has on another.</summary>
- /// <remarks>
- /// This can be used to inform tooling of a dependency that is otherwise not evident purely from
- /// metadata and IL, for example a member relied on via reflection.
- /// </remarks>
- [AttributeUsage(
- AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field /* AttributeTargets.Class | AttributeTargets.Struct */, // TODO: https://github.com/mono/linker/issues/797
- AllowMultiple = true, Inherited = false)]
- internal sealed class PreserveDependencyAttribute : Attribute
- {
- /// <summary>Initializes the attribute.</summary>
- /// <param name="memberSignature">The signature of the member depended.</param>
- public PreserveDependencyAttribute(string memberSignature)
- {
- MemberSignature = memberSignature;
- }
-
- /// <summary>Initializes the attribute.</summary>
- /// <param name="memberSignature">The signature of the member depended on.</param>
- /// <param name="typeName">The full name of the type containing <paramref name="memberSignature"/>.</param>
- public PreserveDependencyAttribute(string memberSignature, string typeName)
- {
- MemberSignature = memberSignature;
- TypeName = typeName;
- }
-
- /// <summary>Initializes the attribute.</summary>
- /// <param name="memberSignature">The signature of the member depended on.</param>
- /// <param name="typeName">The full name of the type containing <paramref name="memberSignature"/>.</param>
- /// <param name="assemblyName">The name of the assembly containing <paramref name="typeName"/>.</param>
- public PreserveDependencyAttribute(string memberSignature, string typeName, string assemblyName)
- {
- MemberSignature = memberSignature;
- TypeName = typeName;
- AssemblyName = assemblyName;
- }
-
- /// <summary>Gets the signature of the member depended on.</summary>
- public string MemberSignature { get; }
-
- /// <summary>Gets the full name of the type containing the specified member.</summary>
- /// <remarks>If no type name is specified, the type of the consumer is assumed.</remarks>
- public string? TypeName { get; }
-
- /// <summary>Gets the assembly name of the specified type.</summary>
- /// <remarks>If no assembly name is specified, the assembly of the consumer is assumed.</remarks>
- public string? AssemblyName { get; }
-
- /// <summary>Gets or sets the condition in which the dependency is applicable, e.g. "DEBUG".</summary>
- public string? Condition { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ReferenceAssemblyAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ReferenceAssemblyAttribute.cs
deleted file mode 100644
index e2c7cb47b4f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ReferenceAssemblyAttribute.cs
+++ /dev/null
@@ -1,32 +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.
-
-/*============================================================
-**
-** Attribute: ReferenceAssemblyAttribute
-**
-** Purpose: Identifies an assembly as being a "reference
-** assembly", meaning it contains public surface area but
-** no usable implementation. Reference assemblies
-** should be loadable for introspection, but not execution.
-**
-============================================================*/
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
- public sealed class ReferenceAssemblyAttribute : Attribute
- {
- public ReferenceAssemblyAttribute()
- {
- }
-
- public ReferenceAssemblyAttribute(string? description)
- {
- Description = description;
- }
-
- public string? Description { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeCompatibilityAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeCompatibilityAttribute.cs
deleted file mode 100644
index 609c5603300..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeCompatibilityAttribute.cs
+++ /dev/null
@@ -1,30 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Mark up the program to indicate various legacy or new opt-in behaviors.
-**
-**
-=============================================================================*/
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]
- public sealed class RuntimeCompatibilityAttribute : Attribute
- {
- public RuntimeCompatibilityAttribute()
- {
- // legacy behavior is the default, and WrapNonExceptionThrows is implicitly
- // false thanks to the CLR's guarantee of zeroed memory.
- }
-
- // If a non-CLSCompliant exception (i.e. one that doesn't derive from System.Exception) is
- // thrown, should it be wrapped up in a System.Runtime.CompilerServices.RuntimeWrappedException
- // instance when presented to catch handlers?
- public bool WrapNonExceptionThrows { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs
deleted file mode 100644
index b0cd9ddce26..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs
+++ /dev/null
@@ -1,42 +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.
-
-namespace System.Runtime.CompilerServices
-{
- public static partial class RuntimeFeature
- {
- /// <summary>
- /// Name of the Portable PDB feature.
- /// </summary>
- public const string PortablePdb = nameof(PortablePdb);
-
-#if FEATURE_DEFAULT_INTERFACES
- /// <summary>
- /// Indicates that this version of runtime supports default interface method implementations.
- /// </summary>
- public const string DefaultImplementationsOfInterfaces = nameof(DefaultImplementationsOfInterfaces);
-#endif
-
- /// <summary>
- /// Checks whether a certain feature is supported by the Runtime.
- /// </summary>
- public static bool IsSupported(string feature)
- {
- switch (feature)
- {
- case PortablePdb:
-#if FEATURE_DEFAULT_INTERFACES
- case DefaultImplementationsOfInterfaces:
-#endif
- return true;
- case nameof(IsDynamicCodeSupported):
- return IsDynamicCodeSupported;
- case nameof(IsDynamicCodeCompiled):
- return IsDynamicCodeCompiled;
- }
-
- return false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs
deleted file mode 100644
index cd2971f0350..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs
+++ /dev/null
@@ -1,109 +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 System.Runtime.Serialization;
-using System.Reflection;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.CompilerServices
-{
- public static partial class RuntimeHelpers
- {
- public delegate void TryCode(object? userData);
-
- public delegate void CleanupCode(object? userData, bool exceptionThrown);
-
- /// <summary>
- /// Slices the specified array using the specified range.
- /// </summary>
- public static T[] GetSubArray<T>(T[] array, Range range)
- {
- if (array == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- }
-
- (int offset, int length) = range.GetOffsetAndLength(array.Length);
-
- if (default(T)! != null || typeof(T[]) == array.GetType()) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- // We know the type of the array to be exactly T[].
-
- if (length == 0)
- {
- return Array.Empty<T>();
- }
-
- var dest = new T[length];
- Buffer.Memmove(
- ref Unsafe.As<byte, T>(ref dest.GetRawSzArrayData()),
- ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), offset),
- (uint)length);
- return dest;
- }
- else
- {
- // The array is actually a U[] where U:T.
- T[] dest = (T[])Array.CreateInstance(array.GetType().GetElementType()!, length);
- Array.Copy(array, offset, dest, 0, length);
- return dest;
- }
- }
-
- public static object GetUninitializedObject(Type type)
- {
- if (type is null)
- {
- throw new ArgumentNullException(nameof(type), SR.ArgumentNull_Type);
- }
-
- if (!type.IsRuntimeImplemented())
- {
- throw new SerializationException(SR.Format(SR.Serialization_InvalidType, type.ToString()));
- }
-
- return GetUninitializedObjectInternal(type);
- }
-
- public static void ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, object? userData)
- {
- if (code == null)
- throw new ArgumentNullException(nameof(code));
- if (backoutCode == null)
- throw new ArgumentNullException(nameof(backoutCode));
-
- bool exceptionThrown = true;
-
- try
- {
- code(userData);
- exceptionThrown = false;
- }
- finally
- {
- backoutCode(userData, exceptionThrown);
- }
- }
-
- public static void PrepareContractedDelegate(Delegate d)
- {
- }
-
- public static void ProbeForSufficientStack()
- {
- }
-
- public static void PrepareConstrainedRegions()
- {
- }
-
- public static void PrepareConstrainedRegionsNoOP()
- {
- }
-
- internal static bool IsPrimitiveType(this CorElementType et)
- // COR_ELEMENT_TYPE_I1,I2,I4,I8,U1,U2,U4,U8,R4,R8,I,U,CHAR,BOOLEAN
- => ((1 << (int)et) & 0b_0011_0000_0000_0011_1111_1111_1100) != 0;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs
deleted file mode 100644
index 65fd6d24e64..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeWrappedException.cs
+++ /dev/null
@@ -1,41 +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 System.Runtime.Serialization;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Exception used to wrap all non-CLS compliant exceptions.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class RuntimeWrappedException : Exception
- {
- private object _wrappedException; // EE expects this name
-
- // Not an api but has to be public as System.Linq.Expression invokes this through Reflection when an expression
- // throws an object that doesn't derive from Exception.
- public RuntimeWrappedException(object thrownObject)
- : base(SR.RuntimeWrappedException)
- {
- HResult = HResults.COR_E_RUNTIMEWRAPPED;
- _wrappedException = thrownObject;
- }
-
- private RuntimeWrappedException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- _wrappedException = info.GetValue("WrappedException", typeof(object))!;
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("WrappedException", _wrappedException, typeof(object));
- }
-
- public object WrappedException => _wrappedException;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/SpecialNameAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/SpecialNameAttribute.cs
deleted file mode 100644
index 4cd78621cb5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/SpecialNameAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Struct)]
- public sealed class SpecialNameAttribute : Attribute
- {
- public SpecialNameAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StateMachineAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StateMachineAttribute.cs
deleted file mode 100644
index d3522f5c470..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StateMachineAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
- public class StateMachineAttribute : Attribute
- {
- public StateMachineAttribute(Type stateMachineType)
- {
- StateMachineType = stateMachineType;
- }
-
- public Type StateMachineType { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StringFreezingAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StringFreezingAttribute.cs
deleted file mode 100644
index 9d73197de42..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StringFreezingAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.CompilerServices
-{
- // Custom attribute to indicate that strings should be frozen.
-
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- public sealed class StringFreezingAttribute : Attribute
- {
- public StringFreezingAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StrongBox.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StrongBox.cs
deleted file mode 100644
index bdee5189b3c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/StrongBox.cs
+++ /dev/null
@@ -1,54 +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 System.Diagnostics.CodeAnalysis;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Holds a reference to a value.
- /// </summary>
- /// <typeparam name="T">The type of the value that the <see cref = "StrongBox{T}"></see> references.</typeparam>
- public class StrongBox<T> : IStrongBox
- {
- /// <summary>
- /// Gets the strongly typed value associated with the <see cref = "StrongBox{T}"></see>
- /// <remarks>This is explicitly exposed as a field instead of a property to enable loading the address of the field.</remarks>
- /// </summary>
- [MaybeNull] public T Value = default!;
-
- /// <summary>
- /// Initializes a new StrongBox which can receive a value when used in a reference call.
- /// </summary>
- public StrongBox()
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref = "StrongBox{T}"></see> with the specified value.
- /// </summary>
- /// <param name="value">A value that the <see cref = "StrongBox{T}"></see> will reference.</param>
- public StrongBox(T value)
- {
- Value = value;
- }
-
- object? IStrongBox.Value
- {
- get => Value;
- set => Value = (T)value!;
- }
- }
-
- /// <summary>
- /// Defines a property for accessing the value that an object references.
- /// </summary>
- public interface IStrongBox
- {
- /// <summary>
- /// Gets or sets the value the object references.
- /// </summary>
- object? Value { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/SuppressIldasmAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/SuppressIldasmAttribute.cs
deleted file mode 100644
index e9abf134be9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/SuppressIldasmAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module)]
- public sealed class SuppressIldasmAttribute : Attribute
- {
- public SuppressIldasmAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs
deleted file mode 100644
index f1c5b07071a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs
+++ /dev/null
@@ -1,556 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// Types for awaiting Task and Task<T>. These types are emitted from Task{<T>}.GetAwaiter
-// and Task{<T>}.ConfigureAwait. They are meant to be used only by the compiler, e.g.
-//
-// await nonGenericTask;
-// =====================
-// var $awaiter = nonGenericTask.GetAwaiter();
-// if (!$awaiter.IsCompleted)
-// {
-// SPILL:
-// $builder.AwaitUnsafeOnCompleted(ref $awaiter, ref this);
-// return;
-// Label:
-// UNSPILL;
-// }
-// $awaiter.GetResult();
-//
-// result += await genericTask.ConfigureAwait(false);
-// ===================================================================================
-// var $awaiter = genericTask.ConfigureAwait(false).GetAwaiter();
-// if (!$awaiter.IsCompleted)
-// {
-// SPILL;
-// $builder.AwaitUnsafeOnCompleted(ref $awaiter, ref this);
-// return;
-// Label:
-// UNSPILL;
-// }
-// result += $awaiter.GetResult();
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.Diagnostics.Tracing;
-using System.Runtime.ExceptionServices;
-using System.Threading;
-using System.Threading.Tasks;
-
-// NOTE: For performance reasons, initialization is not verified. If a developer
-// incorrectly initializes a task awaiter, which should only be done by the compiler,
-// NullReferenceExceptions may be generated (the alternative would be for us to detect
-// this case and then throw a different exception instead). This is the same tradeoff
-// that's made with other compiler-focused value types like List<T>.Enumerator.
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>Provides an awaiter for awaiting a <see cref="System.Threading.Tasks.Task"/>.</summary>
- /// <remarks>This type is intended for compiler use only.</remarks>
- public readonly struct TaskAwaiter : ICriticalNotifyCompletion, ITaskAwaiter
- {
- // WARNING: Unsafe.As is used to access the generic TaskAwaiter<> as TaskAwaiter.
- // Its layout must remain the same.
-
- /// <summary>The task being awaited.</summary>
- internal readonly Task m_task;
-
- /// <summary>Initializes the <see cref="TaskAwaiter"/>.</summary>
- /// <param name="task">The <see cref="System.Threading.Tasks.Task"/> to be awaited.</param>
- internal TaskAwaiter(Task task)
- {
- Debug.Assert(task != null, "Constructing an awaiter requires a task to await.");
- m_task = task;
- }
-
- /// <summary>Gets whether the task being awaited is completed.</summary>
- /// <remarks>This property is intended for compiler user rather than use directly in code.</remarks>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- public bool IsCompleted => m_task.IsCompleted;
-
- /// <summary>Schedules the continuation onto the <see cref="System.Threading.Tasks.Task"/> associated with this <see cref="TaskAwaiter"/>.</summary>
- /// <param name="continuation">The action to invoke when the await operation completes.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.InvalidOperationException">The awaiter was not properly initialized.</exception>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- public void OnCompleted(Action continuation)
- {
- OnCompletedInternal(m_task, continuation, continueOnCapturedContext: true, flowExecutionContext: true);
- }
-
- /// <summary>Schedules the continuation onto the <see cref="System.Threading.Tasks.Task"/> associated with this <see cref="TaskAwaiter"/>.</summary>
- /// <param name="continuation">The action to invoke when the await operation completes.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.InvalidOperationException">The awaiter was not properly initialized.</exception>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- public void UnsafeOnCompleted(Action continuation)
- {
- OnCompletedInternal(m_task, continuation, continueOnCapturedContext: true, flowExecutionContext: false);
- }
-
- /// <summary>Ends the await on the completed <see cref="System.Threading.Tasks.Task"/>.</summary>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- /// <exception cref="System.Threading.Tasks.TaskCanceledException">The task was canceled.</exception>
- /// <exception cref="System.Exception">The task completed in a Faulted state.</exception>
- [StackTraceHidden]
- public void GetResult()
- {
- ValidateEnd(m_task);
- }
-
- /// <summary>
- /// Fast checks for the end of an await operation to determine whether more needs to be done
- /// prior to completing the await.
- /// </summary>
- /// <param name="task">The awaited task.</param>
- [StackTraceHidden]
- internal static void ValidateEnd(Task task)
- {
- // Fast checks that can be inlined.
- if (task.IsWaitNotificationEnabledOrNotRanToCompletion)
- {
- // If either the end await bit is set or we're not completed successfully,
- // fall back to the slower path.
- HandleNonSuccessAndDebuggerNotification(task);
- }
- }
-
- /// <summary>
- /// Ensures the task is completed, triggers any necessary debugger breakpoints for completing
- /// the await on the task, and throws an exception if the task did not complete successfully.
- /// </summary>
- /// <param name="task">The awaited task.</param>
- [StackTraceHidden]
- private static void HandleNonSuccessAndDebuggerNotification(Task task)
- {
- // NOTE: The JIT refuses to inline ValidateEnd when it contains the contents
- // of HandleNonSuccessAndDebuggerNotification, hence the separation.
-
- // Synchronously wait for the task to complete. When used by the compiler,
- // the task will already be complete. This code exists only for direct GetResult use,
- // for cases where the same exception propagation semantics used by "await" are desired,
- // but where for one reason or another synchronous rather than asynchronous waiting is needed.
- if (!task.IsCompleted)
- {
- bool taskCompleted = task.InternalWait(Timeout.Infinite, default);
- Debug.Assert(taskCompleted, "With an infinite timeout, the task should have always completed.");
- }
-
- // Now that we're done, alert the debugger if so requested
- task.NotifyDebuggerOfWaitCompletionIfNecessary();
-
- // And throw an exception if the task is faulted or canceled.
- if (!task.IsCompletedSuccessfully) ThrowForNonSuccess(task);
- }
-
- /// <summary>Throws an exception to handle a task that completed in a state other than RanToCompletion.</summary>
- [StackTraceHidden]
- private static void ThrowForNonSuccess(Task task)
- {
- Debug.Assert(task.IsCompleted, "Task must have been completed by now.");
- Debug.Assert(task.Status != TaskStatus.RanToCompletion, "Task should not be completed successfully.");
-
- // Handle whether the task has been canceled or faulted
- switch (task.Status)
- {
- // If the task completed in a canceled state, throw an OperationCanceledException.
- // This will either be the OCE that actually caused the task to cancel, or it will be a new
- // TaskCanceledException. TCE derives from OCE, and by throwing it we automatically pick up the
- // completed task's CancellationToken if it has one, including that CT in the OCE.
- case TaskStatus.Canceled:
- ExceptionDispatchInfo? oceEdi = task.GetCancellationExceptionDispatchInfo();
- if (oceEdi != null)
- {
- oceEdi.Throw();
- Debug.Fail("Throw() should have thrown");
- }
- throw new TaskCanceledException(task);
-
- // If the task faulted, throw its first exception,
- // even if it contained more than one.
- case TaskStatus.Faulted:
- ReadOnlyCollection<ExceptionDispatchInfo> edis = task.GetExceptionDispatchInfos();
- if (edis.Count > 0)
- {
- edis[0].Throw();
- Debug.Fail("Throw() should have thrown");
- break; // Necessary to compile: non-reachable, but compiler can't determine that
- }
- else
- {
- Debug.Fail("There should be exceptions if we're Faulted.");
- throw task.Exception!;
- }
- }
- }
-
- /// <summary>Schedules the continuation onto the <see cref="System.Threading.Tasks.Task"/> associated with this <see cref="TaskAwaiter"/>.</summary>
- /// <param name="task">The task being awaited.</param>
- /// <param name="continuation">The action to invoke when the await operation completes.</param>
- /// <param name="continueOnCapturedContext">Whether to capture and marshal back to the current context.</param>
- /// <param name="flowExecutionContext">Whether to flow ExecutionContext across the await.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- internal static void OnCompletedInternal(Task task, Action continuation, bool continueOnCapturedContext, bool flowExecutionContext)
- {
- if (continuation == null) throw new ArgumentNullException(nameof(continuation));
-
- // If TaskWait* ETW events are enabled, trace a beginning event for this await
- // and set up an ending event to be traced when the asynchronous await completes.
- if (TplEventSource.Log.IsEnabled() || Task.s_asyncDebuggingEnabled)
- {
- continuation = OutputWaitEtwEvents(task, continuation);
- }
-
- // Set the continuation onto the awaited task.
- task.SetContinuationForAwait(continuation, continueOnCapturedContext, flowExecutionContext);
- }
-
- /// <summary>Schedules the continuation onto the <see cref="System.Threading.Tasks.Task"/> associated with this <see cref="TaskAwaiter"/>.</summary>
- /// <param name="task">The task being awaited.</param>
- /// <param name="stateMachineBox">The box to invoke when the await operation completes.</param>
- /// <param name="continueOnCapturedContext">Whether to capture and marshal back to the current context.</param>
- internal static void UnsafeOnCompletedInternal(Task task, IAsyncStateMachineBox stateMachineBox, bool continueOnCapturedContext)
- {
- Debug.Assert(stateMachineBox != null);
-
- // If TaskWait* ETW events are enabled, trace a beginning event for this await
- // and set up an ending event to be traced when the asynchronous await completes.
- if (TplEventSource.Log.IsEnabled() || Task.s_asyncDebuggingEnabled)
- {
- task.SetContinuationForAwait(OutputWaitEtwEvents(task, stateMachineBox.MoveNextAction), continueOnCapturedContext, flowExecutionContext: false);
- }
- else
- {
- task.UnsafeSetContinuationForAwait(stateMachineBox, continueOnCapturedContext);
- }
- }
-
- /// <summary>
- /// Outputs a WaitBegin ETW event, and augments the continuation action to output a WaitEnd ETW event.
- /// </summary>
- /// <param name="task">The task being awaited.</param>
- /// <param name="continuation">The action to invoke when the await operation completes.</param>
- /// <returns>The action to use as the actual continuation.</returns>
- private static Action OutputWaitEtwEvents(Task task, Action continuation)
- {
- Debug.Assert(task != null, "Need a task to wait on");
- Debug.Assert(continuation != null, "Need a continuation to invoke when the wait completes");
-
- if (Task.s_asyncDebuggingEnabled)
- {
- Task.AddToActiveTasks(task);
- }
-
- TplEventSource log = TplEventSource.Log;
-
- if (log.IsEnabled())
- {
- // ETW event for Task Wait Begin
- Task? currentTaskAtBegin = Task.InternalCurrent;
-
- // If this task's continuation is another task, get it.
- Task? continuationTask = AsyncMethodBuilderCore.TryGetContinuationTask(continuation);
- log.TaskWaitBegin(
- currentTaskAtBegin != null ? currentTaskAtBegin.m_taskScheduler!.Id : TaskScheduler.Default.Id,
- currentTaskAtBegin != null ? currentTaskAtBegin.Id : 0,
- task.Id, TplEventSource.TaskWaitBehavior.Asynchronous,
- continuationTask != null ? continuationTask.Id : 0);
- }
-
- // Create a continuation action that outputs the end event and then invokes the user
- // provided delegate. This incurs the allocations for the closure/delegate, but only if the event
- // is enabled, and in doing so it allows us to pass the awaited task's information into the end event
- // in a purely pay-for-play manner (the alternatively would be to increase the size of TaskAwaiter
- // just for this ETW purpose, not pay-for-play, since GetResult would need to know whether a real yield occurred).
- return AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, (innerContinuation, innerTask) =>
- {
- if (Task.s_asyncDebuggingEnabled)
- {
- Task.RemoveFromActiveTasks(innerTask);
- }
-
- TplEventSource innerEtwLog = TplEventSource.Log;
-
- // ETW event for Task Wait End.
- Guid prevActivityId = default;
- bool bEtwLogEnabled = innerEtwLog.IsEnabled();
- if (bEtwLogEnabled)
- {
- Task? currentTaskAtEnd = Task.InternalCurrent;
- innerEtwLog.TaskWaitEnd(
- currentTaskAtEnd != null ? currentTaskAtEnd.m_taskScheduler!.Id : TaskScheduler.Default.Id,
- currentTaskAtEnd != null ? currentTaskAtEnd.Id : 0,
- innerTask.Id);
-
- // Ensure the continuation runs under the activity ID of the task that completed for the
- // case the antecedent is a promise (in the other cases this is already the case).
- if (innerEtwLog.TasksSetActivityIds && (innerTask.Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0)
- EventSource.SetCurrentThreadActivityId(TplEventSource.CreateGuidForTaskID(innerTask.Id), out prevActivityId);
- }
-
- // Invoke the original continuation provided to OnCompleted.
- innerContinuation();
-
- if (bEtwLogEnabled)
- {
- innerEtwLog.TaskWaitContinuationComplete(innerTask.Id);
- if (innerEtwLog.TasksSetActivityIds && (innerTask.Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0)
- EventSource.SetCurrentThreadActivityId(prevActivityId);
- }
- }, task);
- }
- }
-
- /// <summary>Provides an awaiter for awaiting a <see cref="System.Threading.Tasks.Task{TResult}"/>.</summary>
- /// <remarks>This type is intended for compiler use only.</remarks>
- public readonly struct TaskAwaiter<TResult> : ICriticalNotifyCompletion, ITaskAwaiter
- {
- // WARNING: Unsafe.As is used to access TaskAwaiter<> as the non-generic TaskAwaiter.
- // Its layout must remain the same.
-
- /// <summary>The task being awaited.</summary>
- private readonly Task<TResult> m_task;
-
- /// <summary>Initializes the <see cref="TaskAwaiter{TResult}"/>.</summary>
- /// <param name="task">The <see cref="System.Threading.Tasks.Task{TResult}"/> to be awaited.</param>
- internal TaskAwaiter(Task<TResult> task)
- {
- Debug.Assert(task != null, "Constructing an awaiter requires a task to await.");
- m_task = task;
- }
-
- /// <summary>Gets whether the task being awaited is completed.</summary>
- /// <remarks>This property is intended for compiler user rather than use directly in code.</remarks>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- public bool IsCompleted => m_task.IsCompleted;
-
- /// <summary>Schedules the continuation onto the <see cref="System.Threading.Tasks.Task"/> associated with this <see cref="TaskAwaiter"/>.</summary>
- /// <param name="continuation">The action to invoke when the await operation completes.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- public void OnCompleted(Action continuation)
- {
- TaskAwaiter.OnCompletedInternal(m_task, continuation, continueOnCapturedContext: true, flowExecutionContext: true);
- }
-
- /// <summary>Schedules the continuation onto the <see cref="System.Threading.Tasks.Task"/> associated with this <see cref="TaskAwaiter"/>.</summary>
- /// <param name="continuation">The action to invoke when the await operation completes.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- public void UnsafeOnCompleted(Action continuation)
- {
- TaskAwaiter.OnCompletedInternal(m_task, continuation, continueOnCapturedContext: true, flowExecutionContext: false);
- }
-
- /// <summary>Ends the await on the completed <see cref="System.Threading.Tasks.Task{TResult}"/>.</summary>
- /// <returns>The result of the completed <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- /// <exception cref="System.Threading.Tasks.TaskCanceledException">The task was canceled.</exception>
- /// <exception cref="System.Exception">The task completed in a Faulted state.</exception>
- [StackTraceHidden]
- public TResult GetResult()
- {
- TaskAwaiter.ValidateEnd(m_task);
- return m_task.ResultOnSuccess;
- }
- }
-
- /// <summary>
- /// Marker interface used to know whether a particular awaiter is either a
- /// TaskAwaiter or a TaskAwaiter`1. It must not be implemented by any other
- /// awaiters.
- /// </summary>
- internal interface ITaskAwaiter { }
-
- /// <summary>
- /// Marker interface used to know whether a particular awaiter is either a
- /// CTA.ConfiguredTaskAwaiter or a CTA`1.ConfiguredTaskAwaiter. It must not
- /// be implemented by any other awaiters.
- /// </summary>
- internal interface IConfiguredTaskAwaiter { }
-
- /// <summary>Provides an awaitable object that allows for configured awaits on <see cref="System.Threading.Tasks.Task"/>.</summary>
- /// <remarks>This type is intended for compiler use only.</remarks>
- public readonly struct ConfiguredTaskAwaitable
- {
- /// <summary>The task being awaited.</summary>
- private readonly ConfiguredTaskAwaitable.ConfiguredTaskAwaiter m_configuredTaskAwaiter;
-
- /// <summary>Initializes the <see cref="ConfiguredTaskAwaitable"/>.</summary>
- /// <param name="task">The awaitable <see cref="System.Threading.Tasks.Task"/>.</param>
- /// <param name="continueOnCapturedContext">
- /// true to attempt to marshal the continuation back to the original context captured; otherwise, false.
- /// </param>
- internal ConfiguredTaskAwaitable(Task task, bool continueOnCapturedContext)
- {
- Debug.Assert(task != null, "Constructing an awaitable requires a task to await.");
- m_configuredTaskAwaiter = new ConfiguredTaskAwaitable.ConfiguredTaskAwaiter(task, continueOnCapturedContext);
- }
-
- /// <summary>Gets an awaiter for this awaitable.</summary>
- /// <returns>The awaiter.</returns>
- public ConfiguredTaskAwaitable.ConfiguredTaskAwaiter GetAwaiter()
- {
- return m_configuredTaskAwaiter;
- }
-
- /// <summary>Provides an awaiter for a <see cref="ConfiguredTaskAwaitable"/>.</summary>
- /// <remarks>This type is intended for compiler use only.</remarks>
- public readonly struct ConfiguredTaskAwaiter : ICriticalNotifyCompletion, IConfiguredTaskAwaiter
- {
- // WARNING: Unsafe.As is used to access the generic ConfiguredTaskAwaiter as this.
- // Its layout must remain the same.
-
- /// <summary>The task being awaited.</summary>
- internal readonly Task m_task;
- /// <summary>Whether to attempt marshaling back to the original context.</summary>
- internal readonly bool m_continueOnCapturedContext;
-
- /// <summary>Initializes the <see cref="ConfiguredTaskAwaiter"/>.</summary>
- /// <param name="task">The <see cref="System.Threading.Tasks.Task"/> to await.</param>
- /// <param name="continueOnCapturedContext">
- /// true to attempt to marshal the continuation back to the original context captured
- /// when BeginAwait is called; otherwise, false.
- /// </param>
- internal ConfiguredTaskAwaiter(Task task, bool continueOnCapturedContext)
- {
- Debug.Assert(task != null, "Constructing an awaiter requires a task to await.");
- m_task = task;
- m_continueOnCapturedContext = continueOnCapturedContext;
- }
-
- /// <summary>Gets whether the task being awaited is completed.</summary>
- /// <remarks>This property is intended for compiler user rather than use directly in code.</remarks>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- public bool IsCompleted => m_task.IsCompleted;
-
- /// <summary>Schedules the continuation onto the <see cref="System.Threading.Tasks.Task"/> associated with this <see cref="TaskAwaiter"/>.</summary>
- /// <param name="continuation">The action to invoke when the await operation completes.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- public void OnCompleted(Action continuation)
- {
- TaskAwaiter.OnCompletedInternal(m_task, continuation, m_continueOnCapturedContext, flowExecutionContext: true);
- }
-
- /// <summary>Schedules the continuation onto the <see cref="System.Threading.Tasks.Task"/> associated with this <see cref="TaskAwaiter"/>.</summary>
- /// <param name="continuation">The action to invoke when the await operation completes.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- public void UnsafeOnCompleted(Action continuation)
- {
- TaskAwaiter.OnCompletedInternal(m_task, continuation, m_continueOnCapturedContext, flowExecutionContext: false);
- }
-
- /// <summary>Ends the await on the completed <see cref="System.Threading.Tasks.Task"/>.</summary>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- /// <exception cref="System.Threading.Tasks.TaskCanceledException">The task was canceled.</exception>
- /// <exception cref="System.Exception">The task completed in a Faulted state.</exception>
- [StackTraceHidden]
- public void GetResult()
- {
- TaskAwaiter.ValidateEnd(m_task);
- }
- }
- }
-
- /// <summary>Provides an awaitable object that allows for configured awaits on <see cref="System.Threading.Tasks.Task{TResult}"/>.</summary>
- /// <remarks>This type is intended for compiler use only.</remarks>
- public readonly struct ConfiguredTaskAwaitable<TResult>
- {
- /// <summary>The underlying awaitable on whose logic this awaitable relies.</summary>
- private readonly ConfiguredTaskAwaitable<TResult>.ConfiguredTaskAwaiter m_configuredTaskAwaiter;
-
- /// <summary>Initializes the <see cref="ConfiguredTaskAwaitable{TResult}"/>.</summary>
- /// <param name="task">The awaitable <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="continueOnCapturedContext">
- /// true to attempt to marshal the continuation back to the original context captured; otherwise, false.
- /// </param>
- internal ConfiguredTaskAwaitable(Task<TResult> task, bool continueOnCapturedContext)
- {
- m_configuredTaskAwaiter = new ConfiguredTaskAwaitable<TResult>.ConfiguredTaskAwaiter(task, continueOnCapturedContext);
- }
-
- /// <summary>Gets an awaiter for this awaitable.</summary>
- /// <returns>The awaiter.</returns>
- public ConfiguredTaskAwaitable<TResult>.ConfiguredTaskAwaiter GetAwaiter()
- {
- return m_configuredTaskAwaiter;
- }
-
- /// <summary>Provides an awaiter for a <see cref="ConfiguredTaskAwaitable{TResult}"/>.</summary>
- /// <remarks>This type is intended for compiler use only.</remarks>
- public readonly struct ConfiguredTaskAwaiter : ICriticalNotifyCompletion, IConfiguredTaskAwaiter
- {
- // WARNING: Unsafe.As is used to access this as the non-generic ConfiguredTaskAwaiter.
- // Its layout must remain the same.
-
- /// <summary>The task being awaited.</summary>
- private readonly Task<TResult> m_task;
- /// <summary>Whether to attempt marshaling back to the original context.</summary>
- private readonly bool m_continueOnCapturedContext;
-
- /// <summary>Initializes the <see cref="ConfiguredTaskAwaiter"/>.</summary>
- /// <param name="task">The awaitable <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="continueOnCapturedContext">
- /// true to attempt to marshal the continuation back to the original context captured; otherwise, false.
- /// </param>
- internal ConfiguredTaskAwaiter(Task<TResult> task, bool continueOnCapturedContext)
- {
- Debug.Assert(task != null, "Constructing an awaiter requires a task to await.");
- m_task = task;
- m_continueOnCapturedContext = continueOnCapturedContext;
- }
-
- /// <summary>Gets whether the task being awaited is completed.</summary>
- /// <remarks>This property is intended for compiler user rather than use directly in code.</remarks>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- public bool IsCompleted => m_task.IsCompleted;
-
- /// <summary>Schedules the continuation onto the <see cref="System.Threading.Tasks.Task"/> associated with this <see cref="TaskAwaiter"/>.</summary>
- /// <param name="continuation">The action to invoke when the await operation completes.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- public void OnCompleted(Action continuation)
- {
- TaskAwaiter.OnCompletedInternal(m_task, continuation, m_continueOnCapturedContext, flowExecutionContext: true);
- }
-
- /// <summary>Schedules the continuation onto the <see cref="System.Threading.Tasks.Task"/> associated with this <see cref="TaskAwaiter"/>.</summary>
- /// <param name="continuation">The action to invoke when the await operation completes.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- public void UnsafeOnCompleted(Action continuation)
- {
- TaskAwaiter.OnCompletedInternal(m_task, continuation, m_continueOnCapturedContext, flowExecutionContext: false);
- }
-
- /// <summary>Ends the await on the completed <see cref="System.Threading.Tasks.Task{TResult}"/>.</summary>
- /// <returns>The result of the completed <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
- /// <exception cref="System.Threading.Tasks.TaskCanceledException">The task was canceled.</exception>
- /// <exception cref="System.Exception">The task completed in a Faulted state.</exception>
- [StackTraceHidden]
- public TResult GetResult()
- {
- TaskAwaiter.ValidateEnd(m_task);
- return m_task.ResultOnSuccess;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TupleElementNamesAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TupleElementNamesAttribute.cs
deleted file mode 100644
index d4bdcd1fa7f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TupleElementNamesAttribute.cs
+++ /dev/null
@@ -1,57 +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 System.Collections.Generic;
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>
- /// Indicates that the use of <see cref="System.ValueTuple"/> on a member is meant to be treated as a tuple with element names.
- /// </summary>
- [CLSCompliant(false)]
- [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Event)]
- public sealed class TupleElementNamesAttribute : Attribute
- {
- private readonly string?[] _transformNames;
-
- /// <summary>
- /// Initializes a new instance of the <see
- /// cref="TupleElementNamesAttribute"/> class.
- /// </summary>
- /// <param name="transformNames">
- /// Specifies, in a pre-order depth-first traversal of a type's
- /// construction, which <see cref="System.ValueType"/> occurrences are
- /// meant to carry element names.
- /// </param>
- /// <remarks>
- /// This constructor is meant to be used on types that contain an
- /// instantiation of <see cref="System.ValueType"/> that contains
- /// element names. For instance, if <c>C</c> is a generic type with
- /// two type parameters, then a use of the constructed type <c>C{<see
- /// cref="System.ValueTuple{T1, T2}"/>, <see
- /// cref="System.ValueTuple{T1, T2, T3}"/></c> might be intended to
- /// treat the first type argument as a tuple with element names and the
- /// second as a tuple without element names. In which case, the
- /// appropriate attribute specification should use a
- /// <c>transformNames</c> value of <c>{ "name1", "name2", null, null,
- /// null }</c>.
- /// </remarks>
- public TupleElementNamesAttribute(string?[] transformNames)
- {
- if (transformNames == null)
- {
- throw new ArgumentNullException(nameof(transformNames));
- }
-
- _transformNames = transformNames;
- }
-
- /// <summary>
- /// Specifies, in a pre-order depth-first traversal of a type's
- /// construction, which <see cref="System.ValueTuple"/> elements are
- /// meant to carry element names.
- /// </summary>
- public IList<string?> TransformNames => _transformNames;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs
deleted file mode 100644
index 27dd6457557..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)]
- public sealed class TypeForwardedFromAttribute : Attribute
- {
- public TypeForwardedFromAttribute(string assemblyFullName)
- {
- if (string.IsNullOrEmpty(assemblyFullName))
- throw new ArgumentNullException(nameof(assemblyFullName));
-
- AssemblyFullName = assemblyFullName;
- }
-
- public string AssemblyFullName { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TypeForwardedToAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TypeForwardedToAttribute.cs
deleted file mode 100644
index 85d5c030c19..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TypeForwardedToAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
- public sealed class TypeForwardedToAttribute : Attribute
- {
- public TypeForwardedToAttribute(Type destination)
- {
- Destination = destination;
- }
-
- public Type Destination { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/UnsafeValueTypeAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/UnsafeValueTypeAttribute.cs
deleted file mode 100644
index b1f274367e8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/UnsafeValueTypeAttribute.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.CompilerServices
-{
- [AttributeUsage(AttributeTargets.Struct)]
- public sealed class UnsafeValueTypeAttribute : Attribute
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs
deleted file mode 100644
index b3817d33904..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs
+++ /dev/null
@@ -1,198 +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 System.Diagnostics;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Threading.Tasks.Sources;
-
-#if !NETSTANDARD2_0
-using Internal.Runtime.CompilerServices;
-#endif
-
-namespace System.Runtime.CompilerServices
-{
- /// <summary>Provides an awaiter for a <see cref="ValueTask"/>.</summary>
- public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion, IStateMachineBoxAwareAwaiter
- {
- /// <summary>Shim used to invoke an <see cref="Action"/> passed as the state argument to a <see cref="Action{Object}"/>.</summary>
- internal static readonly Action<object?> s_invokeActionDelegate = state =>
- {
- if (!(state is Action action))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.state);
- return;
- }
-
- action();
- };
- /// <summary>The value being awaited.</summary>
- private readonly ValueTask _value;
-
- /// <summary>Initializes the awaiter.</summary>
- /// <param name="value">The value to be awaited.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal ValueTaskAwaiter(in ValueTask value) => _value = value;
-
- /// <summary>Gets whether the <see cref="ValueTask"/> has completed.</summary>
- public bool IsCompleted
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => _value.IsCompleted;
- }
-
- /// <summary>Gets the result of the ValueTask.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void GetResult() => _value.ThrowIfCompletedUnsuccessfully();
-
- /// <summary>Schedules the continuation action for this ValueTask.</summary>
- public void OnCompleted(Action continuation)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
-
- if (obj is Task t)
- {
- t.GetAwaiter().OnCompleted(continuation);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource>(obj).OnCompleted(s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext | ValueTaskSourceOnCompletedFlags.FlowExecutionContext);
- }
- else
- {
- ValueTask.CompletedTask.GetAwaiter().OnCompleted(continuation);
- }
- }
-
- /// <summary>Schedules the continuation action for this ValueTask.</summary>
- public void UnsafeOnCompleted(Action continuation)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
-
- if (obj is Task t)
- {
- t.GetAwaiter().UnsafeOnCompleted(continuation);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource>(obj).OnCompleted(s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext);
- }
- else
- {
- ValueTask.CompletedTask.GetAwaiter().UnsafeOnCompleted(continuation);
- }
- }
-
- void IStateMachineBoxAwareAwaiter.AwaitUnsafeOnCompleted(IAsyncStateMachineBox box)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
-
- if (obj is Task t)
- {
- TaskAwaiter.UnsafeOnCompletedInternal(t, box, continueOnCapturedContext: true);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource>(obj).OnCompleted(ThreadPoolGlobals.s_invokeAsyncStateMachineBox, box, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext);
- }
- else
- {
- TaskAwaiter.UnsafeOnCompletedInternal(Task.CompletedTask, box, continueOnCapturedContext: true);
- }
- }
- }
-
- /// <summary>Provides an awaiter for a <see cref="ValueTask{TResult}"/>.</summary>
- public readonly struct ValueTaskAwaiter<TResult> : ICriticalNotifyCompletion, IStateMachineBoxAwareAwaiter
- {
- /// <summary>The value being awaited.</summary>
- private readonly ValueTask<TResult> _value;
-
- /// <summary>Initializes the awaiter.</summary>
- /// <param name="value">The value to be awaited.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal ValueTaskAwaiter(in ValueTask<TResult> value) => _value = value;
-
- /// <summary>Gets whether the <see cref="ValueTask{TResult}"/> has completed.</summary>
- public bool IsCompleted
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => _value.IsCompleted;
- }
-
- /// <summary>Gets the result of the ValueTask.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public TResult GetResult() => _value.Result;
-
- /// <summary>Schedules the continuation action for this ValueTask.</summary>
- public void OnCompleted(Action continuation)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj is Task<TResult> t)
- {
- t.GetAwaiter().OnCompleted(continuation);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext | ValueTaskSourceOnCompletedFlags.FlowExecutionContext);
- }
- else
- {
- ValueTask.CompletedTask.GetAwaiter().OnCompleted(continuation);
- }
- }
-
- /// <summary>Schedules the continuation action for this ValueTask.</summary>
- public void UnsafeOnCompleted(Action continuation)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj is Task<TResult> t)
- {
- t.GetAwaiter().UnsafeOnCompleted(continuation);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext);
- }
- else
- {
- ValueTask.CompletedTask.GetAwaiter().UnsafeOnCompleted(continuation);
- }
- }
-
- void IStateMachineBoxAwareAwaiter.AwaitUnsafeOnCompleted(IAsyncStateMachineBox box)
- {
- object? obj = _value._obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj is Task<TResult> t)
- {
- TaskAwaiter.UnsafeOnCompletedInternal(t, box, continueOnCapturedContext: true);
- }
- else if (obj != null)
- {
- Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ThreadPoolGlobals.s_invokeAsyncStateMachineBox, box, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext);
- }
- else
- {
- TaskAwaiter.UnsafeOnCompletedInternal(Task.CompletedTask, box, continueOnCapturedContext: true);
- }
- }
- }
-
- /// <summary>Internal interface used to enable optimizations from <see cref="AsyncTaskMethodBuilder"/>.</summary>>
- internal interface IStateMachineBoxAwareAwaiter
- {
- /// <summary>Invoked to set <see cref="ITaskCompletionAction.Invoke"/> of the <paramref name="box"/> as the awaiter's continuation.</summary>
- /// <param name="box">The box object.</param>
- void AwaitUnsafeOnCompleted(IAsyncStateMachineBox box);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/YieldAwaitable.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/YieldAwaitable.cs
deleted file mode 100644
index cda89738f3e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/YieldAwaitable.cs
+++ /dev/null
@@ -1,195 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// Compiler-targeted type for switching back into the current execution context, e.g.
-//
-// await Task.Yield();
-// =====================
-// var $awaiter = Task.Yield().GetAwaiter();
-// if (!$awaiter.IsCompleted)
-// {
-// $builder.AwaitUnsafeOnCompleted(ref $awaiter, ref this);
-// return;
-// Label:
-// }
-// $awaiter.GetResult();
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Diagnostics;
-using System.Diagnostics.Tracing;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.Runtime.CompilerServices
-{
- // NOTE: YieldAwaitable currently has no state; while developers are encouraged to use Task.Yield() to produce one,
- // no validation is performed to ensure that the developer isn't doing "await new YieldAwaitable()". Such validation
- // would require additional, useless state to be stored, and as this is a type in the CompilerServices namespace, and
- // as the above example isn't harmful, we take the cheaper approach of not validating anything.
-
- /// <summary>Provides an awaitable context for switching into a target environment.</summary>
- /// <remarks>This type is intended for compiler use only.</remarks>
- public readonly struct YieldAwaitable
- {
- /// <summary>Gets an awaiter for this <see cref="YieldAwaitable"/>.</summary>
- /// <returns>An awaiter for this awaitable.</returns>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- public YieldAwaiter GetAwaiter() { return default; }
-
- /// <summary>Provides an awaiter that switches into a target environment.</summary>
- /// <remarks>This type is intended for compiler use only.</remarks>
- public readonly struct YieldAwaiter : ICriticalNotifyCompletion, IStateMachineBoxAwareAwaiter
- {
- /// <summary>Gets whether a yield is not required.</summary>
- /// <remarks>This property is intended for compiler user rather than use directly in code.</remarks>
- public bool IsCompleted => false; // yielding is always required for YieldAwaiter, hence false
-
- /// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
- /// <param name="continuation">The action to invoke asynchronously.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- public void OnCompleted(Action continuation)
- {
- QueueContinuation(continuation, flowContext: true);
- }
-
- /// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
- /// <param name="continuation">The action to invoke asynchronously.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- public void UnsafeOnCompleted(Action continuation)
- {
- QueueContinuation(continuation, flowContext: false);
- }
-
- /// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
- /// <param name="continuation">The action to invoke asynchronously.</param>
- /// <param name="flowContext">true to flow ExecutionContext; false if flowing is not required.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
- private static void QueueContinuation(Action continuation, bool flowContext)
- {
- // Validate arguments
- if (continuation == null) throw new ArgumentNullException(nameof(continuation));
-
- if (TplEventSource.Log.IsEnabled())
- {
- continuation = OutputCorrelationEtwEvent(continuation);
- }
- // Get the current SynchronizationContext, and if there is one,
- // post the continuation to it. However, treat the base type
- // as if there wasn't a SynchronizationContext, since that's what it
- // logically represents.
- SynchronizationContext? syncCtx = SynchronizationContext.Current;
- if (syncCtx != null && syncCtx.GetType() != typeof(SynchronizationContext))
- {
- syncCtx.Post(s_sendOrPostCallbackRunAction, continuation);
- }
- else
- {
- // If we're targeting the default scheduler, queue to the thread pool, so that we go into the global
- // queue. As we're going into the global queue, we might as well use QUWI, which for the global queue is
- // just a tad faster than task, due to a smaller object getting allocated and less work on the execution path.
- TaskScheduler scheduler = TaskScheduler.Current;
- if (scheduler == TaskScheduler.Default)
- {
- if (flowContext)
- {
- ThreadPool.QueueUserWorkItem(s_waitCallbackRunAction, continuation);
- }
- else
- {
- ThreadPool.UnsafeQueueUserWorkItem(s_waitCallbackRunAction, continuation);
- }
- }
- // We're targeting a custom scheduler, so queue a task.
- else
- {
- Task.Factory.StartNew(continuation, default, TaskCreationOptions.PreferFairness, scheduler);
- }
- }
- }
-
- void IStateMachineBoxAwareAwaiter.AwaitUnsafeOnCompleted(IAsyncStateMachineBox box)
- {
- Debug.Assert(box != null);
-
- // If tracing is enabled, delegate the Action-based implementation.
- if (TplEventSource.Log.IsEnabled())
- {
- QueueContinuation(box.MoveNextAction, flowContext: false);
- return;
- }
-
- // Otherwise, this is the same logic as in QueueContinuation, except using
- // an IAsyncStateMachineBox instead of an Action, and only for flowContext:false.
-
- SynchronizationContext? syncCtx = SynchronizationContext.Current;
- if (syncCtx != null && syncCtx.GetType() != typeof(SynchronizationContext))
- {
- syncCtx.Post(s => ((IAsyncStateMachineBox)s!).MoveNext(), box);
- }
- else
- {
- TaskScheduler scheduler = TaskScheduler.Current;
- if (scheduler == TaskScheduler.Default)
- {
- ThreadPool.UnsafeQueueUserWorkItemInternal(box, preferLocal: false);
- }
- else
- {
- Task.Factory.StartNew(s => ((IAsyncStateMachineBox)s!).MoveNext(), box, default, TaskCreationOptions.PreferFairness, scheduler);
- }
- }
- }
-
- private static Action OutputCorrelationEtwEvent(Action continuation)
- {
-#if CORERT
- // TODO
- return continuation;
-#else
- int continuationId = Task.NewId();
- Task? currentTask = Task.InternalCurrent;
- // fire the correlation ETW event
- TplEventSource.Log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id, (currentTask != null) ? currentTask.Id : 0, continuationId);
-
- return AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, (innerContinuation, continuationIdTask) =>
- {
- TplEventSource log = TplEventSource.Log;
- log.TaskWaitContinuationStarted(((Task<int>)continuationIdTask).Result);
-
- // ETW event for Task Wait End.
- Guid prevActivityId = default;
- // Ensure the continuation runs under the correlated activity ID generated above
- if (log.TasksSetActivityIds)
- EventSource.SetCurrentThreadActivityId(TplEventSource.CreateGuidForTaskID(((Task<int>)continuationIdTask).Result), out prevActivityId);
-
- // Invoke the original continuation provided to OnCompleted.
- innerContinuation();
- // Restore activity ID
-
- if (log.TasksSetActivityIds)
- EventSource.SetCurrentThreadActivityId(prevActivityId);
-
- log.TaskWaitContinuationComplete(((Task<int>)continuationIdTask).Result);
- }, Task.FromResult(continuationId)); // pass the ID in a task to avoid a closure\
-#endif
- }
-
- /// <summary>WaitCallback that invokes the Action supplied as object state.</summary>
- private static readonly WaitCallback s_waitCallbackRunAction = RunAction;
- /// <summary>SendOrPostCallback that invokes the Action supplied as object state.</summary>
- private static readonly SendOrPostCallback s_sendOrPostCallbackRunAction = RunAction;
- /// <summary>Runs an Action delegate provided as state.</summary>
- /// <param name="state">The Action delegate to invoke.</param>
- private static void RunAction(object? state) { ((Action)state!)(); }
-
- /// <summary>Ends the await operation.</summary>
- public void GetResult() { } // Nop. It exists purely because the compiler pattern demands it.
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/Cer.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/Cer.cs
deleted file mode 100644
index 77ab3ea770e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/Cer.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Runtime.ConstrainedExecution
-{
- public enum Cer : int
- {
- None = 0,
- MayFail = 1, // Might fail, but the method will say it failed
- Success = 2,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/Consistency.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/Consistency.cs
deleted file mode 100644
index e2cc79ec350..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/Consistency.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.ConstrainedExecution
-{
- public enum Consistency : int
- {
- MayCorruptProcess = 0,
- MayCorruptAppDomain = 1,
- MayCorruptInstance = 2,
- WillNotCorruptState = 3,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/CriticalFinalizerObject.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/CriticalFinalizerObject.cs
deleted file mode 100644
index a6e07b8e53d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/CriticalFinalizerObject.cs
+++ /dev/null
@@ -1,30 +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.
-
-/*============================================================
-**
-**
-** Deriving from this class will cause any finalizer you define to be critical
-** (i.e. the finalizer is guaranteed to run, won't be aborted by the host and is
-** run after the finalizers of other objects collected at the same time).
-**
-**
-===========================================================*/
-
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Runtime.ConstrainedExecution
-{
- public abstract class CriticalFinalizerObject
- {
- protected CriticalFinalizerObject()
- {
- }
-
- [SuppressMessage("Microsoft.Performance", "CA1821:RemoveEmptyFinalizers")]
- ~CriticalFinalizerObject()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/ReliabilityContractAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/ReliabilityContractAttribute.cs
deleted file mode 100644
index 0b987f32fdd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/ConstrainedExecution/ReliabilityContractAttribute.cs
+++ /dev/null
@@ -1,33 +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.
-
-//
-/*============================================================
-**
-**
-**
-** Purpose: Defines a publically documentable contract for
-** reliability between a method and its callers, expressing
-** what state will remain consistent in the presence of
-** failures (ie async exceptions like thread abort) and whether
-** the method needs to be called from within a CER.
-**
-**
-===========================================================*/
-
-namespace System.Runtime.ConstrainedExecution
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Interface /* | AttributeTargets.Delegate*/, Inherited = false)]
- public sealed class ReliabilityContractAttribute : Attribute
- {
- public ReliabilityContractAttribute(Consistency consistencyGuarantee, Cer cer)
- {
- ConsistencyGuarantee = consistencyGuarantee;
- Cer = cer;
- }
-
- public Consistency ConsistencyGuarantee { get; }
- public Cer Cer { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs
deleted file mode 100644
index 93236955f2a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs
+++ /dev/null
@@ -1,83 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Runtime.ExceptionServices
-{
- // This class defines support for separating the exception dispatch details
- // (like stack trace, watson buckets, etc) from the actual managed exception
- // object. This allows us to track error (via the exception object) independent
- // of the path the error takes.
- //
- // This is particularly useful for frameworks that wish to propagate
- // exceptions (i.e. errors to be precise) across threads.
- public sealed class ExceptionDispatchInfo
- {
- private readonly Exception _exception;
- private readonly Exception.DispatchState _dispatchState;
-
- private ExceptionDispatchInfo(Exception exception)
- {
- _exception = exception;
- _dispatchState = exception.CaptureDispatchState();
- }
-
- // This static method is used to create an instance of ExceptionDispatchInfo for
- // the specified exception object and save all the required details that maybe
- // needed to be propagated when the exception is "rethrown" on a different thread.
- public static ExceptionDispatchInfo Capture(Exception source)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- return new ExceptionDispatchInfo(source);
- }
-
- // Return the exception object represented by this ExceptionDispatchInfo instance
- public Exception SourceException => _exception;
-
- // When a framework needs to "Rethrow" an exception on a thread different (but not necessarily so) from
- // where it was thrown, it should invoke this method against the ExceptionDispatchInfo
- // created for the exception in question.
- //
- // This method will restore the original stack trace and bucketing details before throwing
- // the exception so that it is easy, from debugging standpoint, to understand what really went wrong on
- // the original thread.
- [DoesNotReturn]
- [StackTraceHidden]
- public void Throw()
- {
- // Restore the exception dispatch details before throwing the exception.
- _exception.RestoreDispatchState(_dispatchState);
- throw _exception;
- }
-
- // Throws the source exception, maintaining the original bucketing details and augmenting
- // rather than replacing the original stack trace.
- [DoesNotReturn]
- public static void Throw(Exception source) => Capture(source).Throw();
-
- /// <summary>Stores the current stack trace into the specified <see cref="Exception"/> instance.</summary>
- /// <param name="source">The unthrown <see cref="Exception"/> instance.</param>
- /// <exception cref="ArgumentNullException">The <paramref name="source"/> argument was null.</exception>
- /// <exception cref="InvalidOperationException">The <paramref name="source"/> argument was previously thrown or previously had a stack trace stored into it..</exception>
- /// <returns>The <paramref name="source"/> exception instance.</returns>
- [StackTraceHidden]
- public static Exception SetCurrentStackTrace(Exception source)
- {
- if (source is null)
- {
- throw new ArgumentNullException(nameof(source));
- }
-
- source.SetCurrentStackTrace();
-
- return source;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs
deleted file mode 100644
index 605588d657f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionNotification.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Runtime.ExceptionServices
-{
- // Definition of the argument-type passed to the FirstChanceException event handler
- public class FirstChanceExceptionEventArgs : EventArgs
- {
- public FirstChanceExceptionEventArgs(Exception exception)
- {
- Exception = exception;
- }
-
- // Returns the exception object pertaining to the first chance exception
- public Exception Exception { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/HandleProcessCorruptedStateExceptionsAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/HandleProcessCorruptedStateExceptionsAttribute.cs
deleted file mode 100644
index cc1bc81e5a6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/HandleProcessCorruptedStateExceptionsAttribute.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.Runtime.ExceptionServices
-{
- // This attribute can be applied to methods to indicate that ProcessCorruptedState
- // Exceptions should be delivered to them.
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
- public sealed class HandleProcessCorruptedStateExceptionsAttribute : Attribute
- {
- public HandleProcessCorruptedStateExceptionsAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/GCSettings.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/GCSettings.cs
deleted file mode 100644
index 77303ae07d7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/GCSettings.cs
+++ /dev/null
@@ -1,69 +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 System.Diagnostics;
-
-namespace System.Runtime
-{
- public enum GCLargeObjectHeapCompactionMode
- {
- Default = 1,
- CompactOnce = 2
- }
-
- // These settings are the same format as in the GC in the runtime.
- public enum GCLatencyMode
- {
- Batch = 0,
- Interactive = 1,
- LowLatency = 2,
- SustainedLowLatency = 3,
- NoGCRegion = 4
- }
-
- public static partial class GCSettings
- {
- private enum SetLatencyModeStatus
- {
- Succeeded = 0,
- NoGCInProgress = 1 // NoGCRegion is in progress, can't change pause mode.
- }
-
- public static GCLatencyMode LatencyMode
- {
- get => GetGCLatencyMode();
- set
- {
- if ((value < GCLatencyMode.Batch) ||
- (value > GCLatencyMode.SustainedLowLatency))
- {
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_Enum);
- }
-
- SetLatencyModeStatus status = SetGCLatencyMode(value);
- if (status == SetLatencyModeStatus.NoGCInProgress)
- {
- throw new InvalidOperationException(SR.InvalidOperation_SetLatencyModeNoGC);
- }
-
- Debug.Assert(status == SetLatencyModeStatus.Succeeded, $"Unexpected return value '{status}' from {nameof(SetGCLatencyMode)}.");
- }
- }
-
- public static GCLargeObjectHeapCompactionMode LargeObjectHeapCompactionMode
- {
- get => GetLOHCompactionMode();
- set
- {
- if ((value < GCLargeObjectHeapCompactionMode.Default) ||
- (value > GCLargeObjectHeapCompactionMode.CompactOnce))
- {
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_Enum);
- }
-
- SetLOHCompactionMode(value);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs
deleted file mode 100644
index cb640a7a8c8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/AllowReversePInvokeCallsAttribute.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.Runtime.InteropServices
-{
- // To be used on methods that sink reverse P/Invoke calls.
- // This attribute was a Silverlight security measure, currently ignored.
- [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
- public sealed class AllowReversePInvokeCallsAttribute : Attribute
- {
- public AllowReversePInvokeCallsAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs
deleted file mode 100644
index ca1567c514f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ArrayWithOffset.cs
+++ /dev/null
@@ -1,74 +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 System.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System.Runtime.InteropServices
-{
- public struct ArrayWithOffset
- {
- private readonly object? m_array;
- private readonly int m_offset;
- private readonly int m_count;
-
- // From MAX_SIZE_FOR_INTEROP in mlinfo.h
- private const int MaxSizeForInterop = 0x7ffffff0;
-
- public ArrayWithOffset(object? array, int offset)
- {
- int totalSize = 0;
- if (array != null)
- {
- if (!(array is Array arrayObj) || (arrayObj.Rank != 1) || !Marshal.IsPinnable(arrayObj))
- {
- throw new ArgumentException(SR.ArgumentException_NotIsomorphic);
- }
-
- nuint nativeTotalSize = (nuint)arrayObj.LongLength * (nuint)arrayObj.GetElementSize();
- if (nativeTotalSize > MaxSizeForInterop)
- {
- throw new ArgumentException(SR.Argument_StructArrayTooLarge);
- }
-
- totalSize = (int)nativeTotalSize;
- }
-
- if ((uint)offset > (uint)totalSize)
- {
- throw new IndexOutOfRangeException(SR.IndexOutOfRange_ArrayWithOffset);
- }
-
- m_array = array;
- m_offset = offset;
- m_count = totalSize - offset;
- }
-
- public object? GetArray() => m_array;
-
- public int GetOffset() => m_offset;
-
- public override int GetHashCode() => m_count + m_offset;
-
- public override bool Equals(object? obj)
- {
- return obj is ArrayWithOffset && Equals((ArrayWithOffset)obj);
- }
-
- public bool Equals(ArrayWithOffset obj)
- {
- return obj.m_array == m_array && obj.m_offset == m_offset && obj.m_count == m_count;
- }
-
- public static bool operator ==(ArrayWithOffset a, ArrayWithOffset b) => a.Equals(b);
-
- public static bool operator !=(ArrayWithOffset a, ArrayWithOffset b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs
deleted file mode 100644
index 9329b0513cf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BStrWrapper.cs
+++ /dev/null
@@ -1,22 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_BSTR.
- public sealed class BStrWrapper
- {
- public BStrWrapper(string? value)
- {
- WrappedObject = value;
- }
-
- public BStrWrapper(object? value)
- {
- WrappedObject = (string?)value;
- }
-
- public string? WrappedObject { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BestFitMappingAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BestFitMappingAttribute.cs
deleted file mode 100644
index 4ebee1538ca..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/BestFitMappingAttribute.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
- public sealed class BestFitMappingAttribute : Attribute
- {
- public BestFitMappingAttribute(bool BestFitMapping)
- {
- this.BestFitMapping = BestFitMapping;
- }
-
- public bool BestFitMapping { get; }
-
- public bool ThrowOnUnmappableChar;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs
deleted file mode 100644
index 6b22d026313..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/COMException.cs
+++ /dev/null
@@ -1,74 +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 System.Runtime.Serialization;
-using System.Globalization;
-using System.Text;
-
-namespace System.Runtime.InteropServices
-{
- // Exception for COM Interop errors where we don't recognize the HResult.
- /// <summary>
- /// Exception class for all errors from COM Interop where we don't
- /// recognize the HResult.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class COMException : ExternalException
- {
- public COMException()
- : base(SR.Arg_COMException)
- {
- HResult = HResults.E_FAIL;
- }
-
- public COMException(string? message)
- : base(message)
- {
- HResult = HResults.E_FAIL;
- }
-
- public COMException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.E_FAIL;
- }
-
- public COMException(string? message, int errorCode)
- : base(message)
- {
- HResult = errorCode;
- }
-
- protected COMException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
-
- public override string ToString()
- {
- StringBuilder s = new StringBuilder();
-
- string className = GetType().ToString();
- s.Append(className).Append(" (0x").Append(HResult.ToString("X8", CultureInfo.InvariantCulture)).Append(')');
-
- string message = Message;
- if (!string.IsNullOrEmpty(message))
- {
- s.Append(": ").Append(message);
- }
-
- Exception? innerException = InnerException;
- if (innerException != null)
- {
- s.Append(Environment.NewLineConst + InnerExceptionPrefix).Append(innerException.ToString());
- }
-
- string? stackTrace = StackTrace;
- if (stackTrace != null)
- s.AppendLine().Append(stackTrace);
-
- return s.ToString();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CallingConvention.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CallingConvention.cs
deleted file mode 100644
index 3b18fdee3a8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CallingConvention.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Used for the CallingConvention named argument to the DllImport and NativeCallable attribute
- public enum CallingConvention
- {
- Winapi = 1,
- Cdecl = 2,
- StdCall = 3,
- ThisCall = 4,
- FastCall = 5,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CharSet.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CharSet.cs
deleted file mode 100644
index 955ec8eb2f7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CharSet.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Use this in P/Invoke function prototypes to specify
- // which character set to use when marshalling Strings.
- // Using Ansi will marshal the strings as 1 byte char*'s.
- // Using Unicode will marshal the strings as 2 byte wchar*'s.
- // Generally you probably want to use Auto, which does the
- // right thing 99% of the time.
-
- public enum CharSet
- {
- None = 1, // User didn't specify how to marshal strings.
- Ansi = 2, // Strings should be marshalled as ANSI 1 byte chars.
- Unicode = 3, // Strings should be marshalled as Unicode 2 byte chars.
- Auto = 4, // Marshal Strings in the right way for the target system.
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs
deleted file mode 100644
index 59d79ff4438..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceAttribute.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, Inherited = false)]
- public sealed class ClassInterfaceAttribute : Attribute
- {
- public ClassInterfaceAttribute(ClassInterfaceType classInterfaceType)
- {
- Value = classInterfaceType;
- }
- public ClassInterfaceAttribute(short classInterfaceType)
- {
- Value = (ClassInterfaceType)classInterfaceType;
- }
-
- public ClassInterfaceType Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs
deleted file mode 100644
index ef1fe841940..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ClassInterfaceType.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum ClassInterfaceType
- {
- None = 0,
- AutoDispatch = 1,
- AutoDual = 2
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs
deleted file mode 100644
index 4be6622c3da..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CoClassAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Interface, Inherited = false)]
- public sealed class CoClassAttribute : Attribute
- {
- public CoClassAttribute(Type coClass)
- {
- CoClass = coClass;
- }
-
- public Type CoClass { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CollectionsMarshal.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CollectionsMarshal.cs
deleted file mode 100644
index 8b38858d084..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CollectionsMarshal.cs
+++ /dev/null
@@ -1,21 +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 System.Collections.Generic;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// An unsafe class that provides a set of methods to access the underlying data representations of collections.
- /// </summary>
- public static class CollectionsMarshal
- {
- /// <summary>
- /// Get a <see cref="Span{T}"/> view over a <see cref="List{T}"/>'s data.
- /// Items should not be added or removed from the <see cref="List{T}"/> while the <see cref="Span{T}"/> is in use.
- /// </summary>
- public static Span<T> AsSpan<T>(List<T>? list)
- => list is null ? default : new Span<T>(list._items, 0, list._size);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs
deleted file mode 100644
index 1b84f5f561a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComDefaultInterfaceAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Class, Inherited = false)]
- public sealed class ComDefaultInterfaceAttribute : Attribute
- {
- public ComDefaultInterfaceAttribute(Type defaultInterface)
- {
- Value = defaultInterface;
- }
-
- public Type Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs
deleted file mode 100644
index d4ccc702e05..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Interface, Inherited = false)]
- public sealed class ComEventInterfaceAttribute : Attribute
- {
- public ComEventInterfaceAttribute(Type SourceInterface, Type EventProvider)
- {
- this.SourceInterface = SourceInterface;
- this.EventProvider = EventProvider;
- }
-
- public Type SourceInterface { get; }
- public Type EventProvider { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs
deleted file mode 100644
index 7b29d6f9ad0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComEventsHelpers.NoCom.cs
+++ /dev/null
@@ -1,21 +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 System.Runtime.InteropServices.ComTypes;
-
-namespace System.Runtime.InteropServices
-{
- public static class ComEventsHelper
- {
- public static void Combine(object rcw, Guid iid, int dispid, Delegate d)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static Delegate Remove(object rcw, Guid iid, int dispid, Delegate d)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComImportAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComImportAttribute.cs
deleted file mode 100644
index a290bf4510d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComImportAttribute.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, Inherited = false)]
- public sealed class ComImportAttribute : Attribute
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComInterfaceType.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComInterfaceType.cs
deleted file mode 100644
index 03b8ae534ad..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComInterfaceType.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum ComInterfaceType
- {
- InterfaceIsDual = 0,
- InterfaceIsIUnknown = 1,
- InterfaceIsIDispatch = 2,
- InterfaceIsIInspectable = 3,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs
deleted file mode 100644
index 4be75b03b9f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComMemberType.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum ComMemberType
- {
- Method = 0,
- PropGet = 1,
- PropSet = 2
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs
deleted file mode 100644
index a62871a3997..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComSourceInterfacesAttribute.cs
+++ /dev/null
@@ -1,37 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Class, Inherited = true)]
- public sealed class ComSourceInterfacesAttribute : Attribute
- {
- public ComSourceInterfacesAttribute(string sourceInterfaces)
- {
- Value = sourceInterfaces;
- }
-
- public ComSourceInterfacesAttribute(Type sourceInterface)
- {
- Value = sourceInterface.FullName!;
- }
-
- public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2)
- {
- Value = sourceInterface1.FullName + "\0" + sourceInterface2.FullName;
- }
-
- public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2, Type sourceInterface3)
- {
- Value = sourceInterface1.FullName + "\0" + sourceInterface2.FullName + "\0" + sourceInterface3.FullName;
- }
-
- public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2, Type sourceInterface3, Type sourceInterface4)
- {
- Value = sourceInterface1.FullName + "\0" + sourceInterface2.FullName + "\0" + sourceInterface3.FullName + "\0" + sourceInterface4.FullName;
- }
-
- public string Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IBindCtx.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IBindCtx.cs
deleted file mode 100644
index 0ad56c23bd9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IBindCtx.cs
+++ /dev/null
@@ -1,33 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [StructLayout(LayoutKind.Sequential)]
- public struct BIND_OPTS
- {
- public int cbStruct;
- public int grfFlags;
- public int grfMode;
- public int dwTickCountDeadline;
- }
-
- [Guid("0000000e-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IBindCtx
- {
- void RegisterObjectBound([MarshalAs(UnmanagedType.Interface)] object punk);
- void RevokeObjectBound([MarshalAs(UnmanagedType.Interface)] object punk);
- void ReleaseBoundObjects();
- void SetBindOptions([In] ref BIND_OPTS pbindopts);
- void GetBindOptions(ref BIND_OPTS pbindopts);
- void GetRunningObjectTable(out IRunningObjectTable? pprot);
- void RegisterObjectParam([MarshalAs(UnmanagedType.LPWStr)] string pszKey, [MarshalAs(UnmanagedType.Interface)] object punk);
- void GetObjectParam([MarshalAs(UnmanagedType.LPWStr)] string pszKey, [MarshalAs(UnmanagedType.Interface)] out object? ppunk);
- void EnumObjectParam(out IEnumString? ppenum);
- [PreserveSig]
- int RevokeObjectParam([MarshalAs(UnmanagedType.LPWStr)] string pszKey);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPoint.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPoint.cs
deleted file mode 100644
index b2ce1928a13..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPoint.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("B196B286-BAB4-101A-B69C-00AA00341D07")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IConnectionPoint
- {
- void GetConnectionInterface(out Guid pIID);
- void GetConnectionPointContainer(out IConnectionPointContainer ppCPC);
- void Advise([MarshalAs(UnmanagedType.Interface)] object pUnkSink, out int pdwCookie);
- void Unadvise(int dwCookie);
- void EnumConnections(out IEnumConnections ppEnum);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPointContainer.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPointContainer.cs
deleted file mode 100644
index 4dd08658a0d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IConnectionPointContainer.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("B196B284-BAB4-101A-B69C-00AA00341D07")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IConnectionPointContainer
- {
- void EnumConnectionPoints(out IEnumConnectionPoints ppEnum);
- void FindConnectionPoint([In] ref Guid riid, out IConnectionPoint? ppCP);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnectionPoints.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnectionPoints.cs
deleted file mode 100644
index 99df6ac60e4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnectionPoints.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("B196B285-BAB4-101A-B69C-00AA00341D07")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IEnumConnectionPoints
- {
- [PreserveSig]
- int Next(int celt, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] IConnectionPoint[] rgelt, IntPtr pceltFetched);
- [PreserveSig]
- int Skip(int celt);
- void Reset();
- void Clone(out IEnumConnectionPoints ppenum);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnections.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnections.cs
deleted file mode 100644
index 951685beff7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumConnections.cs
+++ /dev/null
@@ -1,27 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct CONNECTDATA
- {
- [MarshalAs(UnmanagedType.Interface)]
- public object pUnk;
- public int dwCookie;
- }
-
- [Guid("B196B287-BAB4-101A-B69C-00AA00341D07")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IEnumConnections
- {
- [PreserveSig]
- int Next(int celt, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] CONNECTDATA[] rgelt, IntPtr pceltFetched);
- [PreserveSig]
- int Skip(int celt);
- void Reset();
- void Clone(out IEnumConnections ppenum);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumMoniker.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumMoniker.cs
deleted file mode 100644
index 9a63ba0a11a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumMoniker.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00000102-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IEnumMoniker
- {
- [PreserveSig]
- int Next(int celt, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] IMoniker[] rgelt, IntPtr pceltFetched);
- [PreserveSig]
- int Skip(int celt);
- void Reset();
- void Clone(out IEnumMoniker ppenum);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumString.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumString.cs
deleted file mode 100644
index 57fc59121f0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumString.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00000101-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IEnumString
- {
- [PreserveSig]
- int Next(int celt, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 0), Out] string[] rgelt, IntPtr pceltFetched);
- [PreserveSig]
- int Skip(int celt);
- void Reset();
- void Clone(out IEnumString ppenum);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumVARIANT.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumVARIANT.cs
deleted file mode 100644
index bb6688ee2c7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IEnumVARIANT.cs
+++ /dev/null
@@ -1,23 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00020404-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IEnumVARIANT
- {
- [PreserveSig]
- int Next(int celt, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] object?[] rgVar, IntPtr pceltFetched);
-
- [PreserveSig]
- int Skip(int celt);
-
- [PreserveSig]
- int Reset();
-
- IEnumVARIANT Clone();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IMoniker.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IMoniker.cs
deleted file mode 100644
index f2d5242294d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IMoniker.cs
+++ /dev/null
@@ -1,49 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [StructLayout(LayoutKind.Sequential)]
- public struct FILETIME
- {
- public int dwLowDateTime;
- public int dwHighDateTime;
- }
-
- [Guid("0000000f-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IMoniker
- {
- // IPersist portion
- void GetClassID(out Guid pClassID);
-
- // IPersistStream portion
- [PreserveSig]
- int IsDirty();
- void Load(IStream pStm);
- void Save(IStream pStm, [MarshalAs(UnmanagedType.Bool)] bool fClearDirty);
- void GetSizeMax(out long pcbSize);
-
- // IMoniker portion
- void BindToObject(IBindCtx pbc, IMoniker? pmkToLeft, [In] ref Guid riidResult, [MarshalAs(UnmanagedType.Interface)] out object ppvResult);
- void BindToStorage(IBindCtx pbc, IMoniker? pmkToLeft, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvObj);
- void Reduce(IBindCtx pbc, int dwReduceHowFar, ref IMoniker? ppmkToLeft, out IMoniker? ppmkReduced);
- void ComposeWith(IMoniker pmkRight, [MarshalAs(UnmanagedType.Bool)] bool fOnlyIfNotGeneric, out IMoniker? ppmkComposite);
- void Enum([MarshalAs(UnmanagedType.Bool)] bool fForward, out IEnumMoniker? ppenumMoniker);
- [PreserveSig]
- int IsEqual(IMoniker pmkOtherMoniker);
- void Hash(out int pdwHash);
- [PreserveSig]
- int IsRunning(IBindCtx pbc, IMoniker? pmkToLeft, IMoniker? pmkNewlyRunning);
- void GetTimeOfLastChange(IBindCtx pbc, IMoniker? pmkToLeft, out FILETIME pFileTime);
- void Inverse(out IMoniker ppmk);
- void CommonPrefixWith(IMoniker pmkOther, out IMoniker? ppmkPrefix);
- void RelativePathTo(IMoniker pmkOther, out IMoniker? ppmkRelPath);
- void GetDisplayName(IBindCtx pbc, IMoniker? pmkToLeft, [MarshalAs(UnmanagedType.LPWStr)] out string ppszDisplayName);
- void ParseDisplayName(IBindCtx pbc, IMoniker pmkToLeft, [MarshalAs(UnmanagedType.LPWStr)] string pszDisplayName, out int pchEaten, out IMoniker ppmkOut);
- [PreserveSig]
- int IsSystemMoniker(out int pdwMksys);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IPersistFile.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IPersistFile.cs
deleted file mode 100644
index 4ae9d127ea9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IPersistFile.cs
+++ /dev/null
@@ -1,23 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("0000010b-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IPersistFile
- {
- // IPersist portion
- void GetClassID(out Guid pClassID);
-
- // IPersistFile portion
- [PreserveSig]
- int IsDirty();
- void Load([MarshalAs(UnmanagedType.LPWStr)] string pszFileName, int dwMode);
- void Save([MarshalAs(UnmanagedType.LPWStr)] string? pszFileName, [MarshalAs(UnmanagedType.Bool)] bool fRemember);
- void SaveCompleted([MarshalAs(UnmanagedType.LPWStr)] string pszFileName);
- void GetCurFile([MarshalAs(UnmanagedType.LPWStr)] out string ppszFileName);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IRunningObjectTable.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IRunningObjectTable.cs
deleted file mode 100644
index 1884fcc99b5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IRunningObjectTable.cs
+++ /dev/null
@@ -1,23 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00000010-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IRunningObjectTable
- {
- int Register(int grfFlags, [MarshalAs(UnmanagedType.Interface)] object punkObject, IMoniker pmkObjectName);
- void Revoke(int dwRegister);
- [PreserveSig]
- int IsRunning(IMoniker pmkObjectName);
- [PreserveSig]
- int GetObject(IMoniker pmkObjectName, [MarshalAs(UnmanagedType.Interface)] out object ppunkObject);
- void NoteChangeTime(int dwRegister, ref FILETIME pfiletime);
- [PreserveSig]
- int GetTimeOfLastChange(IMoniker pmkObjectName, out FILETIME pfiletime);
- void EnumRunning(out IEnumMoniker ppenumMoniker);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IStream.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IStream.cs
deleted file mode 100644
index 09b284041e7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/IStream.cs
+++ /dev/null
@@ -1,43 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct STATSTG
- {
- public string pwcsName;
- public int type;
- public long cbSize;
- public FILETIME mtime;
- public FILETIME ctime;
- public FILETIME atime;
- public int grfMode;
- public int grfLocksSupported;
- public Guid clsid;
- public int grfStateBits;
- public int reserved;
- }
-
- [Guid("0000000c-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface IStream
- {
- // ISequentialStream portion
- void Read([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1), Out] byte[] pv, int cb, IntPtr pcbRead);
- void Write([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] pv, int cb, IntPtr pcbWritten);
-
- // IStream portion
- void Seek(long dlibMove, int dwOrigin, IntPtr plibNewPosition);
- void SetSize(long libNewSize);
- void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten);
- void Commit(int grfCommitFlags);
- void Revert();
- void LockRegion(long libOffset, long cb, int dwLockType);
- void UnlockRegion(long libOffset, long cb, int dwLockType);
- void Stat(out STATSTG pstatstg, int grfStatFlag);
- void Clone(out IStream ppstm);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeComp.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeComp.cs
deleted file mode 100644
index 7e637936151..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeComp.cs
+++ /dev/null
@@ -1,36 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- public enum DESCKIND
- {
- DESCKIND_NONE = 0,
- DESCKIND_FUNCDESC = DESCKIND_NONE + 1,
- DESCKIND_VARDESC = DESCKIND_FUNCDESC + 1,
- DESCKIND_TYPECOMP = DESCKIND_VARDESC + 1,
- DESCKIND_IMPLICITAPPOBJ = DESCKIND_TYPECOMP + 1,
- DESCKIND_MAX = DESCKIND_IMPLICITAPPOBJ + 1
- }
-
- [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
- public struct BINDPTR
- {
- [FieldOffset(0)]
- public IntPtr lpfuncdesc;
- [FieldOffset(0)]
- public IntPtr lpvardesc;
- [FieldOffset(0)]
- public IntPtr lptcomp;
- }
-
- [Guid("00020403-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface ITypeComp
- {
- void Bind([MarshalAs(UnmanagedType.LPWStr)] string szName, int lHashVal, short wFlags, out ITypeInfo ppTInfo, out DESCKIND pDescKind, out BINDPTR pBindPtr);
- void BindType([MarshalAs(UnmanagedType.LPWStr)] string szName, int lHashVal, out ITypeInfo ppTInfo, out ITypeComp ppTComp);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo.cs
deleted file mode 100644
index 0b00fdceab8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo.cs
+++ /dev/null
@@ -1,303 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- public enum TYPEKIND
- {
- TKIND_ENUM = 0,
- TKIND_RECORD = TKIND_ENUM + 1,
- TKIND_MODULE = TKIND_RECORD + 1,
- TKIND_INTERFACE = TKIND_MODULE + 1,
- TKIND_DISPATCH = TKIND_INTERFACE + 1,
- TKIND_COCLASS = TKIND_DISPATCH + 1,
- TKIND_ALIAS = TKIND_COCLASS + 1,
- TKIND_UNION = TKIND_ALIAS + 1,
- TKIND_MAX = TKIND_UNION + 1
- }
-
- [Flags]
- public enum TYPEFLAGS : short
- {
- TYPEFLAG_FAPPOBJECT = 0x1,
- TYPEFLAG_FCANCREATE = 0x2,
- TYPEFLAG_FLICENSED = 0x4,
- TYPEFLAG_FPREDECLID = 0x8,
- TYPEFLAG_FHIDDEN = 0x10,
- TYPEFLAG_FCONTROL = 0x20,
- TYPEFLAG_FDUAL = 0x40,
- TYPEFLAG_FNONEXTENSIBLE = 0x80,
- TYPEFLAG_FOLEAUTOMATION = 0x100,
- TYPEFLAG_FRESTRICTED = 0x200,
- TYPEFLAG_FAGGREGATABLE = 0x400,
- TYPEFLAG_FREPLACEABLE = 0x800,
- TYPEFLAG_FDISPATCHABLE = 0x1000,
- TYPEFLAG_FREVERSEBIND = 0x2000,
- TYPEFLAG_FPROXY = 0x4000
- }
-
- [Flags]
- public enum IMPLTYPEFLAGS
- {
- IMPLTYPEFLAG_FDEFAULT = 0x1,
- IMPLTYPEFLAG_FSOURCE = 0x2,
- IMPLTYPEFLAG_FRESTRICTED = 0x4,
- IMPLTYPEFLAG_FDEFAULTVTABLE = 0x8,
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct TYPEATTR
- {
- // Constant used with the memid fields.
- public const int MEMBER_ID_NIL = unchecked((int)0xFFFFFFFF);
-
- // Actual fields of the TypeAttr struct.
- public Guid guid;
- public int lcid;
- public int dwReserved;
- public int memidConstructor;
- public int memidDestructor;
- public IntPtr lpstrSchema;
- public int cbSizeInstance;
- public TYPEKIND typekind;
- public short cFuncs;
- public short cVars;
- public short cImplTypes;
- public short cbSizeVft;
- public short cbAlignment;
- public TYPEFLAGS wTypeFlags;
- public short wMajorVerNum;
- public short wMinorVerNum;
- public TYPEDESC tdescAlias;
- public IDLDESC idldescType;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public struct FUNCDESC
- {
- public int memid; // MEMBERID memid;
- public IntPtr lprgscode; // /* [size_is(cScodes)] */ SCODE RPC_FAR *lprgscode;
- public IntPtr lprgelemdescParam; // /* [size_is(cParams)] */ ELEMDESC __RPC_FAR *lprgelemdescParam;
- public FUNCKIND funckind; // FUNCKIND funckind;
- public INVOKEKIND invkind; // INVOKEKIND invkind;
- public CALLCONV callconv; // CALLCONV callconv;
- public short cParams; // short cParams;
- public short cParamsOpt; // short cParamsOpt;
- public short oVft; // short oVft;
- public short cScodes; // short cScodes;
- public ELEMDESC elemdescFunc; // ELEMDESC elemdescFunc;
- public short wFuncFlags; // WORD wFuncFlags;
- }
-
- [Flags]
- public enum IDLFLAG : short
- {
- IDLFLAG_NONE = PARAMFLAG.PARAMFLAG_NONE,
- IDLFLAG_FIN = PARAMFLAG.PARAMFLAG_FIN,
- IDLFLAG_FOUT = PARAMFLAG.PARAMFLAG_FOUT,
- IDLFLAG_FLCID = PARAMFLAG.PARAMFLAG_FLCID,
- IDLFLAG_FRETVAL = PARAMFLAG.PARAMFLAG_FRETVAL
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct IDLDESC
- {
- public IntPtr dwReserved;
- public IDLFLAG wIDLFlags;
- }
-
- [Flags]
- public enum PARAMFLAG : short
- {
- PARAMFLAG_NONE = 0,
- PARAMFLAG_FIN = 0x1,
- PARAMFLAG_FOUT = 0x2,
- PARAMFLAG_FLCID = 0x4,
- PARAMFLAG_FRETVAL = 0x8,
- PARAMFLAG_FOPT = 0x10,
- PARAMFLAG_FHASDEFAULT = 0x20,
- PARAMFLAG_FHASCUSTDATA = 0x40
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct PARAMDESC
- {
- public IntPtr lpVarValue;
- public PARAMFLAG wParamFlags;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct TYPEDESC
- {
- public IntPtr lpValue;
- public short vt;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct ELEMDESC
- {
- public TYPEDESC tdesc;
-
- [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
- public struct DESCUNION
- {
- [FieldOffset(0)]
- public IDLDESC idldesc;
- [FieldOffset(0)]
- public PARAMDESC paramdesc;
- }
- public DESCUNION desc;
- }
-
- public enum VARKIND : int
- {
- VAR_PERINSTANCE = 0x0,
- VAR_STATIC = 0x1,
- VAR_CONST = 0x2,
- VAR_DISPATCH = 0x3
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
-
- public struct VARDESC
- {
- public int memid;
- public string lpstrSchema;
-
- [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
- public struct DESCUNION
- {
- [FieldOffset(0)]
- public int oInst;
- [FieldOffset(0)]
- public IntPtr lpvarValue;
- }
-
- public DESCUNION desc;
-
- public ELEMDESC elemdescVar;
- public short wVarFlags;
- public VARKIND varkind;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct DISPPARAMS
- {
- public IntPtr rgvarg;
- public IntPtr rgdispidNamedArgs;
- public int cArgs;
- public int cNamedArgs;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct EXCEPINFO
- {
- public short wCode;
- public short wReserved;
- [MarshalAs(UnmanagedType.BStr)] public string bstrSource;
- [MarshalAs(UnmanagedType.BStr)] public string bstrDescription;
- [MarshalAs(UnmanagedType.BStr)] public string bstrHelpFile;
- public int dwHelpContext;
- public IntPtr pvReserved;
- public IntPtr pfnDeferredFillIn;
- public int scode;
- }
-
- public enum FUNCKIND : int
- {
- FUNC_VIRTUAL = 0,
- FUNC_PUREVIRTUAL = 1,
- FUNC_NONVIRTUAL = 2,
- FUNC_STATIC = 3,
- FUNC_DISPATCH = 4
- }
-
- [Flags]
- public enum INVOKEKIND : int
- {
- INVOKE_FUNC = 0x1,
- INVOKE_PROPERTYGET = 0x2,
- INVOKE_PROPERTYPUT = 0x4,
- INVOKE_PROPERTYPUTREF = 0x8
- }
-
- public enum CALLCONV : int
- {
- CC_CDECL = 1,
- CC_MSCPASCAL = 2,
- CC_PASCAL = CC_MSCPASCAL,
- CC_MACPASCAL = 3,
- CC_STDCALL = 4,
- CC_RESERVED = 5,
- CC_SYSCALL = 6,
- CC_MPWCDECL = 7,
- CC_MPWPASCAL = 8,
- CC_MAX = 9
- }
-
- [Flags]
- public enum FUNCFLAGS : short
- {
- FUNCFLAG_FRESTRICTED = 0x1,
- FUNCFLAG_FSOURCE = 0x2,
- FUNCFLAG_FBINDABLE = 0x4,
- FUNCFLAG_FREQUESTEDIT = 0x8,
- FUNCFLAG_FDISPLAYBIND = 0x10,
- FUNCFLAG_FDEFAULTBIND = 0x20,
- FUNCFLAG_FHIDDEN = 0x40,
- FUNCFLAG_FUSESGETLASTERROR = 0x80,
- FUNCFLAG_FDEFAULTCOLLELEM = 0x100,
- FUNCFLAG_FUIDEFAULT = 0x200,
- FUNCFLAG_FNONBROWSABLE = 0x400,
- FUNCFLAG_FREPLACEABLE = 0x800,
- FUNCFLAG_FIMMEDIATEBIND = 0x1000
- }
-
- [Flags]
- public enum VARFLAGS : short
- {
- VARFLAG_FREADONLY = 0x1,
- VARFLAG_FSOURCE = 0x2,
- VARFLAG_FBINDABLE = 0x4,
- VARFLAG_FREQUESTEDIT = 0x8,
- VARFLAG_FDISPLAYBIND = 0x10,
- VARFLAG_FDEFAULTBIND = 0x20,
- VARFLAG_FHIDDEN = 0x40,
- VARFLAG_FRESTRICTED = 0x80,
- VARFLAG_FDEFAULTCOLLELEM = 0x100,
- VARFLAG_FUIDEFAULT = 0x200,
- VARFLAG_FNONBROWSABLE = 0x400,
- VARFLAG_FREPLACEABLE = 0x800,
- VARFLAG_FIMMEDIATEBIND = 0x1000
- }
-
- [Guid("00020401-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface ITypeInfo
- {
- void GetTypeAttr(out IntPtr ppTypeAttr);
- void GetTypeComp(out ITypeComp ppTComp);
- void GetFuncDesc(int index, out IntPtr ppFuncDesc);
- void GetVarDesc(int index, out IntPtr ppVarDesc);
- void GetNames(int memid, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2), Out] string[] rgBstrNames, int cMaxNames, out int pcNames);
- void GetRefTypeOfImplType(int index, out int href);
- void GetImplTypeFlags(int index, out IMPLTYPEFLAGS pImplTypeFlags);
- void GetIDsOfNames([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1), In] string[] rgszNames, int cNames, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1), Out] int[] pMemId);
- void Invoke([MarshalAs(UnmanagedType.IUnknown)] object pvInstance, int memid, short wFlags, ref DISPPARAMS pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, out int puArgErr);
- void GetDocumentation(int index, out string strName, out string strDocString, out int dwHelpContext, out string strHelpFile);
- void GetDllEntry(int memid, INVOKEKIND invKind, IntPtr pBstrDllName, IntPtr pBstrName, IntPtr pwOrdinal);
- void GetRefTypeInfo(int hRef, out ITypeInfo ppTI);
- void AddressOfMember(int memid, INVOKEKIND invKind, out IntPtr ppv);
- void CreateInstance([MarshalAs(UnmanagedType.IUnknown)] object? pUnkOuter, [In] ref Guid riid, [MarshalAs(UnmanagedType.IUnknown), Out] out object ppvObj);
- void GetMops(int memid, out string? pBstrMops);
- void GetContainingTypeLib(out ITypeLib ppTLB, out int pIndex);
- [PreserveSig]
- void ReleaseTypeAttr(IntPtr pTypeAttr);
- [PreserveSig]
- void ReleaseFuncDesc(IntPtr pFuncDesc);
- [PreserveSig]
- void ReleaseVarDesc(IntPtr pVarDesc);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo2.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo2.cs
deleted file mode 100644
index e322f8a4f86..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeInfo2.cs
+++ /dev/null
@@ -1,51 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00020412-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface ITypeInfo2 : ITypeInfo
- {
- new void GetTypeAttr(out IntPtr ppTypeAttr);
- new void GetTypeComp(out ITypeComp ppTComp);
- new void GetFuncDesc(int index, out IntPtr ppFuncDesc);
- new void GetVarDesc(int index, out IntPtr ppVarDesc);
- new void GetNames(int memid, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2), Out] string[] rgBstrNames, int cMaxNames, out int pcNames);
- new void GetRefTypeOfImplType(int index, out int href);
- new void GetImplTypeFlags(int index, out IMPLTYPEFLAGS pImplTypeFlags);
- new void GetIDsOfNames([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1), In] string[] rgszNames, int cNames, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1), Out] int[] pMemId);
- new void Invoke([MarshalAs(UnmanagedType.IUnknown)] object pvInstance, int memid, short wFlags, ref DISPPARAMS pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, out int puArgErr);
- new void GetDocumentation(int index, out string strName, out string strDocString, out int dwHelpContext, out string strHelpFile);
- new void GetDllEntry(int memid, INVOKEKIND invKind, IntPtr pBstrDllName, IntPtr pBstrName, IntPtr pwOrdinal);
- new void GetRefTypeInfo(int hRef, out ITypeInfo ppTI);
- new void AddressOfMember(int memid, INVOKEKIND invKind, out IntPtr ppv);
- new void CreateInstance([MarshalAs(UnmanagedType.IUnknown)] object? pUnkOuter, [In] ref Guid riid, [MarshalAs(UnmanagedType.IUnknown), Out] out object ppvObj);
- new void GetMops(int memid, out string? pBstrMops);
- new void GetContainingTypeLib(out ITypeLib ppTLB, out int pIndex);
- [PreserveSig]
- new void ReleaseTypeAttr(IntPtr pTypeAttr);
- [PreserveSig]
- new void ReleaseFuncDesc(IntPtr pFuncDesc);
- [PreserveSig]
- new void ReleaseVarDesc(IntPtr pVarDesc);
- void GetTypeKind(out TYPEKIND pTypeKind);
- void GetTypeFlags(out int pTypeFlags);
- void GetFuncIndexOfMemId(int memid, INVOKEKIND invKind, out int pFuncIndex);
- void GetVarIndexOfMemId(int memid, out int pVarIndex);
- void GetCustData(ref Guid guid, out object pVarVal);
- void GetFuncCustData(int index, ref Guid guid, out object pVarVal);
- void GetParamCustData(int indexFunc, int indexParam, ref Guid guid, out object pVarVal);
- void GetVarCustData(int index, ref Guid guid, out object pVarVal);
- void GetImplTypeCustData(int index, ref Guid guid, out object pVarVal);
- [LCIDConversion(1)]
- void GetDocumentation2(int memid, out string pbstrHelpString, out int pdwHelpStringContext, out string pbstrHelpStringDll);
- void GetAllCustData(IntPtr pCustData);
- void GetAllFuncCustData(int index, IntPtr pCustData);
- void GetAllParamCustData(int indexFunc, int indexParam, IntPtr pCustData);
- void GetAllVarCustData(int index, IntPtr pCustData);
- void GetAllImplTypeCustData(int index, IntPtr pCustData);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib.cs
deleted file mode 100644
index 6cab58e117d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib.cs
+++ /dev/null
@@ -1,54 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- public enum SYSKIND
- {
- SYS_WIN16 = 0,
- SYS_WIN32 = SYS_WIN16 + 1,
- SYS_MAC = SYS_WIN32 + 1,
- SYS_WIN64 = SYS_MAC + 1
- }
-
- [Flags]
- public enum LIBFLAGS : short
- {
- LIBFLAG_FRESTRICTED = 0x1,
- LIBFLAG_FCONTROL = 0x2,
- LIBFLAG_FHIDDEN = 0x4,
- LIBFLAG_FHASDISKIMAGE = 0x8
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct TYPELIBATTR
- {
- public Guid guid;
- public int lcid;
- public SYSKIND syskind;
- public short wMajorVerNum;
- public short wMinorVerNum;
- public LIBFLAGS wLibFlags;
- }
-
- [Guid("00020402-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface ITypeLib
- {
- [PreserveSig]
- int GetTypeInfoCount();
- void GetTypeInfo(int index, out ITypeInfo ppTI);
- void GetTypeInfoType(int index, out TYPEKIND pTKind);
- void GetTypeInfoOfGuid(ref Guid guid, out ITypeInfo ppTInfo);
- void GetLibAttr(out IntPtr ppTLibAttr);
- void GetTypeComp(out ITypeComp ppTComp);
- void GetDocumentation(int index, out string strName, out string strDocString, out int dwHelpContext, out string strHelpFile);
- [return: MarshalAs(UnmanagedType.Bool)]
- bool IsName([MarshalAs(UnmanagedType.LPWStr)] string szNameBuf, int lHashVal);
- void FindName([MarshalAs(UnmanagedType.LPWStr)] string szNameBuf, int lHashVal, [MarshalAs(UnmanagedType.LPArray), Out] ITypeInfo[] ppTInfo, [MarshalAs(UnmanagedType.LPArray), Out] int[] rgMemId, ref short pcFound);
- [PreserveSig]
- void ReleaseTLibAttr(IntPtr pTLibAttr);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib2.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib2.cs
deleted file mode 100644
index 61703d1cfe3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComTypes/ITypeLib2.cs
+++ /dev/null
@@ -1,31 +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.
-
-namespace System.Runtime.InteropServices.ComTypes
-{
- [Guid("00020411-0000-0000-C000-000000000046")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [ComImport]
- public interface ITypeLib2 : ITypeLib
- {
- [PreserveSig]
- new int GetTypeInfoCount();
- new void GetTypeInfo(int index, out ITypeInfo ppTI);
- new void GetTypeInfoType(int index, out TYPEKIND pTKind);
- new void GetTypeInfoOfGuid(ref Guid guid, out ITypeInfo ppTInfo);
- new void GetLibAttr(out IntPtr ppTLibAttr);
- new void GetTypeComp(out ITypeComp ppTComp);
- new void GetDocumentation(int index, out string strName, out string strDocString, out int dwHelpContext, out string strHelpFile);
- [return: MarshalAs(UnmanagedType.Bool)]
- new bool IsName([MarshalAs(UnmanagedType.LPWStr)] string szNameBuf, int lHashVal);
- new void FindName([MarshalAs(UnmanagedType.LPWStr)] string szNameBuf, int lHashVal, [MarshalAs(UnmanagedType.LPArray), Out] ITypeInfo[] ppTInfo, [MarshalAs(UnmanagedType.LPArray), Out] int[] rgMemId, ref short pcFound);
- [PreserveSig]
- new void ReleaseTLibAttr(IntPtr pTLibAttr);
- void GetCustData(ref Guid guid, out object pVarVal);
- [LCIDConversion(1)]
- void GetDocumentation2(int index, out string pbstrHelpString, out int pdwHelpStringContext, out string pbstrHelpStringDll);
- void GetLibStatistics(IntPtr pcUniqueNames, out int pcchUniqueNames);
- void GetAllCustData(IntPtr pCustData);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs
deleted file mode 100644
index 84b9505a5a4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ComVisibleAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Property, Inherited = false)]
- public sealed class ComVisibleAttribute : Attribute
- {
- public ComVisibleAttribute(bool visibility)
- {
- Value = visibility;
- }
-
- public bool Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CriticalHandle.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CriticalHandle.cs
deleted file mode 100644
index fc6a27d18ca..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CriticalHandle.cs
+++ /dev/null
@@ -1,211 +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.
-
-/*============================================================
-**
-**
-**
-** A specially designed handle wrapper to ensure we never leak
-** an OS handle. The runtime treats this class specially during
-** P/Invoke marshaling and finalization. Users should write
-** subclasses of CriticalHandle for each distinct handle type.
-** This class is similar to SafeHandle, but lacks the ref counting
-** behavior on marshaling that prevents handle recycling errors
-** or security holes. This lowers the overhead of using the handle
-** considerably, but leaves the onus on the caller to protect
-** themselves from any recycling effects.
-**
-** **** NOTE ****
-**
-** Since there are no ref counts tracking handle usage there is
-** no thread safety either. Your application must ensure that
-** usages of the handle do not cross with attempts to close the
-** handle (or tolerate such crossings). Normal GC mechanics will
-** prevent finalization until the handle class isn't used any more,
-** but explicit Close or Dispose operations may be initiated at any
-** time.
-**
-** Similarly, multiple calls to Close or Dispose on different
-** threads at the same time may cause the ReleaseHandle method to be
-** called more than once.
-**
-** In general (and as might be inferred from the lack of handle
-** recycle protection) you should be very cautious about exposing
-** CriticalHandle instances directly or indirectly to untrusted users.
-** At a minimum you should restrict their ability to queue multiple
-** operations against a single handle at the same time or block their
-** access to Close and Dispose unless you are very comfortable with the
-** semantics of passing an invalid (or possibly invalidated and
-** reallocated) to the unamanged routines you marshal your handle to
-** (and the effects of closing such a handle while those calls are in
-** progress). The runtime cannot protect you from undefined program
-** behvior that might result from such scenarios. You have been warned.
-**
-**
-===========================================================*/
-
-using System.Runtime.ConstrainedExecution;
-
-/*
- Problems addressed by the CriticalHandle class:
- 1) Critical finalization - ensure we never leak OS resources in SQL. Done
- without running truly arbitrary & unbounded amounts of managed code.
- 2) Reduced graph promotion - during finalization, keep object graph small
- 3) GC.KeepAlive behavior - P/Invoke vs. finalizer thread race condition (HandleRef)
- 4) Enforcement of the above via the type system - Don't use IntPtr anymore.
-
- Subclasses of CriticalHandle will implement the ReleaseHandle
- abstract method used to execute any code required to free the
- handle. This method will be prepared as a constrained execution
- region at instance construction time (along with all the methods in
- its statically determinable call graph). This implies that we won't
- get any inconvenient jit allocation errors or rude thread abort
- interrupts while releasing the handle but the user must still write
- careful code to avoid injecting fault paths of their own (see the
- CER spec for more details). In particular, any sub-methods you call
- should be decorated with a reliability contract of the appropriate
- level. In most cases this should be:
- ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)
-
- Subclasses must also implement the IsInvalid property so that the
- infrastructure can tell when critical finalization is actually required.
- Again, this method is prepared ahead of time. It's envisioned that direct
- subclasses of CriticalHandle will provide an IsInvalid implementation that suits
- the general type of handle they support (null is invalid, -1 is invalid etc.)
- and then these classes will be further derived for specific handle types.
-
- Most classes using CriticalHandle should not provide a finalizer. If they do
- need to do so (ie, for flushing out file buffers, needing to write some data
- back into memory, etc), then they can provide a finalizer that will be
- guaranteed to run before the CriticalHandle's critical finalizer.
-
- Subclasses are expected to be written as follows:
-
- internal sealed MyCriticalHandleSubclass : CriticalHandle {
- // Called by P/Invoke when returning CriticalHandles
- private MyCriticalHandleSubclass() : base(IntPtr.Zero)
- {
- }
-
- // Do not provide a finalizer - CriticalHandle's critical finalizer will
- // call ReleaseHandle for you.
-
- public override bool IsInvalid {
- get { return handle == IntPtr.Zero; }
- }
-
- [DllImport(Interop.Libraries.Kernel32), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- private static extern bool CloseHandle(IntPtr handle);
-
- override protected bool ReleaseHandle()
- {
- return CloseHandle(handle);
- }
- }
-
- Then elsewhere to create one of these CriticalHandles, define a method
- with the following type of signature (CreateFile follows this model).
- Note that when returning a CriticalHandle like this, P/Invoke will call your
- classes default constructor.
-
- [DllImport(Interop.Libraries.Kernel32)]
- private static extern MyCriticalHandleSubclass CreateHandle(int someState);
-
- */
-
-namespace System.Runtime.InteropServices
-{
- // This class should not be serializable - it's a handle
- public abstract partial class CriticalHandle : CriticalFinalizerObject, IDisposable
- {
- // ! Do not add or rearrange fields as the EE depends on this layout.
- //------------------------------------------------------------------
- protected IntPtr handle; // This must be protected so derived classes can use out params.
- private bool _isClosed; // Set by SetHandleAsInvalid or Close/Dispose/finalization.
-
- // Creates a CriticalHandle class. Users must then set the Handle property or allow P/Invoke marshaling to set it implicitly.
- protected CriticalHandle(IntPtr invalidHandleValue)
- {
- handle = invalidHandleValue;
- }
-
- ~CriticalHandle()
- {
- Dispose(false);
- }
-
- private void Cleanup()
- {
- if (IsClosed)
- return;
- _isClosed = true;
-
- if (IsInvalid)
- return;
-
- // Save last error from P/Invoke in case the implementation of
- // ReleaseHandle trashes it (important because this ReleaseHandle could
- // occur implicitly as part of unmarshaling another P/Invoke).
- int lastError = Marshal.GetLastWin32Error();
-
- ReleaseHandle();
-
- Marshal.SetLastWin32Error(lastError);
- GC.SuppressFinalize(this);
- }
-
- protected void SetHandle(IntPtr handle)
- {
- this.handle = handle;
- }
-
- // Returns whether the handle has been explicitly marked as closed
- // (Close/Dispose) or invalid (SetHandleAsInvalid).
- public bool IsClosed => _isClosed;
-
- // Returns whether the handle looks like an invalid value (i.e. matches one
- // of the handle's designated illegal values). CriticalHandle itself doesn't
- // know what an invalid handle looks like, so this method is abstract and
- // must be provided by a derived type.
- public abstract bool IsInvalid
- {
- get;
- }
-
- public void Close()
- {
- Dispose(true);
- }
-
- public void Dispose()
- {
- Dispose(true);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- Cleanup();
- }
-
- // This should only be called for cases when you know for a fact that
- // your handle is invalid and you want to record that information.
- // An example is calling a syscall and getting back ERROR_INVALID_HANDLE.
- // This method will normally leak handles!
- public void SetHandleAsInvalid()
- {
- _isClosed = true;
- GC.SuppressFinalize(this);
- }
-
- // Implement this abstract method in your derived class to specify how to
- // free the handle. Be careful not write any code that's subject to faults
- // in this method (the runtime will prepare the infrastructure for you so
- // that no jit allocations etc. will occur, but don't allocate memory unless
- // you can deal with the failure and still free the handle).
- // The boolean returned should be true for success and false if a
- // catastrophic error occurred and you wish to trigger a diagnostic for
- // debugging purposes.
- protected abstract bool ReleaseHandle();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs
deleted file mode 100644
index 373f9bb9c5e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CurrencyWrapper.cs
+++ /dev/null
@@ -1,25 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_CURRENCY.
- public sealed class CurrencyWrapper
- {
- public CurrencyWrapper(decimal obj)
- {
- WrappedObject = obj;
- }
-
- public CurrencyWrapper(object obj)
- {
- if (!(obj is decimal))
- throw new ArgumentException(SR.Arg_MustBeDecimal, nameof(obj));
-
- WrappedObject = (decimal)obj;
- }
-
- public decimal WrappedObject { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs
deleted file mode 100644
index 7b5eddacf4c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceMode.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum CustomQueryInterfaceMode
- {
- Ignore = 0,
- Allow = 1,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs
deleted file mode 100644
index 1e1d3fd7ead..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/CustomQueryInterfaceResult.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- // The enum of the return value of IQuerable.GetInterface
- public enum CustomQueryInterfaceResult
- {
- Handled = 0,
- NotHandled = 1,
- Failed = 2,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultCharSetAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultCharSetAttribute.cs
deleted file mode 100644
index 7a486f7017b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultCharSetAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Module, Inherited = false)]
- public sealed class DefaultCharSetAttribute : Attribute
- {
- public DefaultCharSetAttribute(CharSet charSet)
- {
- CharSet = charSet;
- }
-
- public CharSet CharSet { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultDllImportSearchPathsAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultDllImportSearchPathsAttribute.cs
deleted file mode 100644
index 1ff27fbbd55..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultDllImportSearchPathsAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Method, AllowMultiple = false)]
- public sealed class DefaultDllImportSearchPathsAttribute : Attribute
- {
- public DefaultDllImportSearchPathsAttribute(DllImportSearchPath paths)
- {
- Paths = paths;
- }
-
- public DllImportSearchPath Paths { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs
deleted file mode 100644
index ed709f16d1c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs
+++ /dev/null
@@ -1,23 +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.
-
-namespace System.Runtime.InteropServices
-{
- //
- // The DefaultParameterValueAttribute is used in C# to set
- // the default value for parameters when calling methods
- // from other languages. This is particularly useful for
- // methods defined in COM interop interfaces.
- //
- [AttributeUsage(AttributeTargets.Parameter)]
- public sealed class DefaultParameterValueAttribute : Attribute
- {
- public DefaultParameterValueAttribute(object? value)
- {
- Value = value;
- }
-
- public object? Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs
deleted file mode 100644
index 1f147280c5c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispIdAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Event, Inherited = false)]
- public sealed class DispIdAttribute : Attribute
- {
- public DispIdAttribute(int dispId)
- {
- Value = dispId;
- }
-
- public int Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs
deleted file mode 100644
index 3bb1507203c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs
+++ /dev/null
@@ -1,26 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_DISPATCH
- public sealed class DispatchWrapper
- {
- public DispatchWrapper(object? obj)
- {
- if (obj != null)
- {
- // Make sure this guy has an IDispatch
- IntPtr pdisp = Marshal.GetIDispatchForObject(obj);
-
- // If we got here without throwing an exception, the QI for IDispatch succeeded.
- Marshal.Release(pdisp);
-
- WrappedObject = obj;
- }
- }
-
- public object? WrappedObject { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportAttribute.cs
deleted file mode 100644
index 11e3deb21c3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportAttribute.cs
+++ /dev/null
@@ -1,26 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class DllImportAttribute : Attribute
- {
- public DllImportAttribute(string dllName)
- {
- Value = dllName;
- }
-
- public string Value { get; }
-
- public string? EntryPoint;
- public CharSet CharSet;
- public bool SetLastError;
- public bool ExactSpelling;
- public CallingConvention CallingConvention;
- public bool BestFitMapping;
- public bool PreserveSig;
- public bool ThrowOnUnmappableChar;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportSearchPath.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportSearchPath.cs
deleted file mode 100644
index 8dbdb40be96..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/DllImportSearchPath.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Runtime.InteropServices
-{
- [Flags]
- public enum DllImportSearchPath
- {
- UseDllDirectoryForDependencies = 0x100,
- ApplicationDirectory = 0x200,
- UserDirectories = 0x400,
- System32 = 0x800,
- SafeDirectories = 0x1000,
- AssemblyDirectory = 0x2,
- LegacyBehavior = 0x0
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs
deleted file mode 100644
index d25f0231a44..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ErrorWrapper.cs
+++ /dev/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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_ERROR.
- public sealed class ErrorWrapper
- {
- public ErrorWrapper(int errorCode)
- {
- ErrorCode = errorCode;
- }
-
- public ErrorWrapper(object errorCode)
- {
- if (!(errorCode is int))
- throw new ArgumentException(SR.Arg_MustBeInt32, nameof(errorCode));
- ErrorCode = (int)errorCode;
- }
-
- public ErrorWrapper(Exception e)
- {
- ErrorCode = Marshal.GetHRForException(e);
- }
-
- public int ErrorCode { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs
deleted file mode 100644
index b9bc042986e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ExternalException.cs
+++ /dev/null
@@ -1,81 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception base class for all errors from Interop or Structured
-** Exception Handling code.
-**
-**
-=============================================================================*/
-
-using System.Globalization;
-using System.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- // Base exception for COM Interop errors &; Structured Exception Handler
- // exceptions.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ExternalException : SystemException
- {
- public ExternalException()
- : base(SR.Arg_ExternalException)
- {
- HResult = HResults.E_FAIL;
- }
-
- public ExternalException(string? message)
- : base(message)
- {
- HResult = HResults.E_FAIL;
- }
-
- public ExternalException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.E_FAIL;
- }
-
- public ExternalException(string? message, int errorCode)
- : base(message)
- {
- HResult = errorCode;
- }
-
- protected ExternalException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
-
- public virtual int ErrorCode => HResult;
-
- public override string ToString()
- {
- string message = Message;
- string className = GetType().ToString();
-
- string s = className + " (0x" + HResult.ToString("X8", CultureInfo.InvariantCulture) + ")";
-
- if (!string.IsNullOrEmpty(message))
- {
- s += ": " + message;
- }
-
- Exception? innerException = InnerException;
- if (innerException != null)
- {
- s += Environment.NewLineConst + InnerExceptionPrefix + innerException.ToString();
- }
-
- if (StackTrace != null)
- s += Environment.NewLineConst + StackTrace;
-
- return s;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/FieldOffsetAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/FieldOffsetAttribute.cs
deleted file mode 100644
index 27e1097749f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/FieldOffsetAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Field, Inherited = false)]
- public sealed class FieldOffsetAttribute : Attribute
- {
- public FieldOffsetAttribute(int offset)
- {
- Value = offset;
- }
-
- public int Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandle.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandle.cs
deleted file mode 100644
index b39bc98ef37..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandle.cs
+++ /dev/null
@@ -1,195 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Threading;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nint = System.Int64;
-#else
-using nint = System.Int32;
-#endif
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// Represents an opaque, GC handle to a managed object. A GC handle is used when an
- /// object reference must be reachable from unmanaged memory.
- /// </summary>
- /// <remarks>
- /// There are 4 kinds of roots:
- /// Normal: Keeps the object from being collected.
- /// Weak: Allows object to be collected and handle contents will be zeroed.
- /// Weak references are zeroed before the finalizer runs, so if the
- /// object is resurrected in the finalizer the weak reference is still zeroed.
- /// WeakTrackResurrection: Same as Weak, but stays until after object is really gone.
- /// Pinned - same as Normal, but allows the address of the actual object to be taken.
- /// </remarks>
- [StructLayout(LayoutKind.Sequential)]
- public partial struct GCHandle
- {
- // The actual integer handle value that the EE uses internally.
- private IntPtr _handle;
-
- // Allocate a handle storing the object and the type.
- private GCHandle(object? value, GCHandleType type)
- {
- // Make sure the type parameter is within the valid range for the enum.
- if ((uint)type > (uint)GCHandleType.Pinned) // IMPORTANT: This must be kept in sync with the GCHandleType enum.
- {
- throw new ArgumentOutOfRangeException(nameof(type), SR.ArgumentOutOfRange_Enum);
- }
-
- if (type == GCHandleType.Pinned && !Marshal.IsPinnable(value))
- {
- throw new ArgumentException(SR.ArgumentException_NotIsomorphic, nameof(value));
- }
-
- IntPtr handle = InternalAlloc(value, type);
-
- if (type == GCHandleType.Pinned)
- {
- // Record if the handle is pinned.
- handle = (IntPtr)((nint)handle | 1);
- }
-
- _handle = handle;
- }
-
- // Used in the conversion functions below.
- private GCHandle(IntPtr handle) => _handle = handle;
-
- /// <summary>Creates a new GC handle for an object.</summary>
- /// <param name="value">The object that the GC handle is created for.</param>
- /// <returns>A new GC handle that protects the object.</returns>
- public static GCHandle Alloc(object? value) => new GCHandle(value, GCHandleType.Normal);
-
- /// <summary>Creates a new GC handle for an object.</summary>
- /// <param name="value">The object that the GC handle is created for.</param>
- /// <param name="type">The type of GC handle to create.</param>
- /// <returns>A new GC handle that protects the object.</returns>
- public static GCHandle Alloc(object? value, GCHandleType type) => new GCHandle(value, type);
-
- /// <summary>Frees a GC handle.</summary>
- public void Free()
- {
- // Free the handle if it hasn't already been freed.
- IntPtr handle = Interlocked.Exchange(ref _handle, IntPtr.Zero);
- ThrowIfInvalid(handle);
- InternalFree(GetHandleValue(handle));
- }
-
- // Target property - allows getting / updating of the handle's referent.
- public object? Target
- {
- get
- {
- IntPtr handle = _handle;
- ThrowIfInvalid(handle);
-
- return InternalGet(GetHandleValue(handle));
- }
- set
- {
- IntPtr handle = _handle;
- ThrowIfInvalid(handle);
-
- if (IsPinned(handle) && !Marshal.IsPinnable(value))
- {
- throw new ArgumentException(SR.ArgumentException_NotIsomorphic, nameof(value));
- }
-
- InternalSet(GetHandleValue(handle), value);
- }
- }
-
- /// <summary>
- /// Retrieve the address of an object in a Pinned handle. This throws
- /// an exception if the handle is any type other than Pinned.
- /// </summary>
- public IntPtr AddrOfPinnedObject()
- {
- // Check if the handle was not a pinned handle.
- // You can only get the address of pinned handles.
- IntPtr handle = _handle;
- ThrowIfInvalid(handle);
-
- if (!IsPinned(handle))
- {
- ThrowHelper.ThrowInvalidOperationException_HandleIsNotPinned();
- }
-
- // Get the address.
-
- object target = InternalGet(GetHandleValue(handle));
- if (target is null)
- {
- return default;
- }
-
- unsafe
- {
- if (RuntimeHelpers.ObjectHasComponentSize(target))
- {
- if (target.GetType() == typeof(string))
- {
- return (IntPtr)Unsafe.AsPointer(ref Unsafe.As<string>(target).GetRawStringData());
- }
-
- Debug.Assert(target is Array);
- return (IntPtr)Unsafe.AsPointer(ref Unsafe.As<Array>(target).GetRawArrayData());
- }
-
- return (IntPtr)Unsafe.AsPointer(ref target.GetRawData());
- }
- }
-
- /// <summary>Determine whether this handle has been allocated or not.</summary>
- public bool IsAllocated => _handle != IntPtr.Zero;
-
- /// <summary>
- /// Used to create a GCHandle from an int. This is intended to
- /// be used with the reverse conversion.
- /// </summary>
- public static explicit operator GCHandle(IntPtr value) => FromIntPtr(value);
-
- public static GCHandle FromIntPtr(IntPtr value)
- {
- ThrowIfInvalid(value);
- return new GCHandle(value);
- }
-
- /// <summary>Used to get the internal integer representation of the handle out.</summary>
- public static explicit operator IntPtr(GCHandle value) => ToIntPtr(value);
-
- public static IntPtr ToIntPtr(GCHandle value) => value._handle;
-
- public override int GetHashCode() => _handle.GetHashCode();
-
- public override bool Equals(object? o) => o is GCHandle && _handle == ((GCHandle)o)._handle;
-
- public static bool operator ==(GCHandle a, GCHandle b) => a._handle == b._handle;
-
- public static bool operator !=(GCHandle a, GCHandle b) => a._handle != b._handle;
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static IntPtr GetHandleValue(IntPtr handle) => new IntPtr((nint)handle & ~(nint)1); // Remove Pin flag
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsPinned(IntPtr handle) => ((nint)handle & 1) != 0; // Check Pin flag
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void ThrowIfInvalid(IntPtr handle)
- {
- // Check if the handle was never initialized or was freed.
- if (handle == IntPtr.Zero)
- {
- ThrowHelper.ThrowInvalidOperationException_HandleIsNotInitialized();
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandleType.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandleType.cs
deleted file mode 100644
index 68da96830ae..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandleType.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Runtime.InteropServices
-{
- // These are the types of handles used by the EE.
- // IMPORTANT: These must match the definitions in ObjectHandle.h in the EE.
- // IMPORTANT: If new values are added to the enum the GCHandle.MaxHandleType
- // constant must be updated.
- public enum GCHandleType
- {
- Weak = 0,
- WeakTrackResurrection = 1,
- Normal = 2,
- Pinned = 3
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GuidAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GuidAttribute.cs
deleted file mode 100644
index cf60b9bf70a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/GuidAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct | AttributeTargets.Delegate, Inherited = false)]
- public sealed class GuidAttribute : Attribute
- {
- public GuidAttribute(string guid)
- {
- Value = guid;
- }
-
- public string Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs
deleted file mode 100644
index 075d78f2416..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/HandleRef.cs
+++ /dev/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.
-
-namespace System.Runtime.InteropServices
-{
- public readonly struct HandleRef
- {
- // ! Do not add or rearrange fields as the EE depends on this layout.
- //------------------------------------------------------------------
- private readonly object? _wrapper;
- private readonly IntPtr _handle;
- //------------------------------------------------------------------
-
- public HandleRef(object? wrapper, IntPtr handle)
- {
- _wrapper = wrapper;
- _handle = handle;
- }
-
- public object? Wrapper => _wrapper;
-
- public IntPtr Handle => _handle;
-
- public static explicit operator IntPtr(HandleRef value) => value._handle;
-
- public static IntPtr ToIntPtr(HandleRef value) => value._handle;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs
deleted file mode 100644
index 6dd90e2dace..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomAdapter.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Runtime.InteropServices
-{
- // This the base interface that custom adapters can chose to implement when they want to expose the underlying object.
- public interface ICustomAdapter
- {
- [return: MarshalAs(UnmanagedType.IUnknown)]
- object GetUnderlyingObject();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs
deleted file mode 100644
index 799db6a2d3a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomFactory.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.InteropServices
-{
- public interface ICustomFactory
- {
- MarshalByRefObject CreateInstance(Type serverType);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs
deleted file mode 100644
index cf442d4fde1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Runtime.InteropServices
-{
- // This the base interface that must be implemented by all custom marshalers.
- public interface ICustomMarshaler
- {
- object MarshalNativeToManaged(IntPtr pNativeData);
-
- IntPtr MarshalManagedToNative(object ManagedObj);
-
- void CleanUpNativeData(IntPtr pNativeData);
-
- void CleanUpManagedData(object ManagedObj);
-
- int GetNativeDataSize();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs
deleted file mode 100644
index a91fd7f5fbb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomQueryInterface.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Runtime.InteropServices
-{
- // This the interface that be implemented by class that want to customize the behavior of QueryInterface.
- public interface ICustomQueryInterface
- {
- CustomQueryInterfaceResult GetInterface([In]ref Guid iid, out IntPtr ppv);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InAttribute.cs
deleted file mode 100644
index 39f5a958bc8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- public sealed class InAttribute : Attribute
- {
- public InAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InterfaceTypeAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InterfaceTypeAttribute.cs
deleted file mode 100644
index 695faa79378..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InterfaceTypeAttribute.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Interface, Inherited = false)]
- public sealed class InterfaceTypeAttribute : Attribute
- {
- public InterfaceTypeAttribute(ComInterfaceType interfaceType)
- {
- Value = interfaceType;
- }
- public InterfaceTypeAttribute(short interfaceType)
- {
- Value = (ComInterfaceType)interfaceType;
- }
-
- public ComInterfaceType Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs
deleted file mode 100644
index 5bc16e54b74..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidComObjectException.cs
+++ /dev/null
@@ -1,41 +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 System.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// The exception thrown when an invalid COM object is used. This happens
- /// when a the __ComObject type is used directly without having a backing
- /// class factory.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class InvalidComObjectException : SystemException
- {
- public InvalidComObjectException()
- : base(SR.Arg_InvalidComObjectException)
- {
- HResult = HResults.COR_E_INVALIDCOMOBJECT;
- }
-
- public InvalidComObjectException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_INVALIDCOMOBJECT;
- }
-
- public InvalidComObjectException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_INVALIDCOMOBJECT;
- }
-
- protected InvalidComObjectException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs
deleted file mode 100644
index e5aedb000f9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/InvalidOleVariantTypeException.cs
+++ /dev/null
@@ -1,40 +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 System.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// Exception thrown when the type of an OLE variant that was passed into the
- /// runtime is invalid.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class InvalidOleVariantTypeException : SystemException
- {
- public InvalidOleVariantTypeException()
- : base(SR.Arg_InvalidOleVariantTypeException)
- {
- HResult = HResults.COR_E_INVALIDOLEVARIANTTYPE;
- }
-
- public InvalidOleVariantTypeException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_INVALIDOLEVARIANTTYPE;
- }
-
- public InvalidOleVariantTypeException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_INVALIDOLEVARIANTTYPE;
- }
-
- protected InvalidOleVariantTypeException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LCIDConversionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LCIDConversionAttribute.cs
deleted file mode 100644
index 75f8fcfc914..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LCIDConversionAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class LCIDConversionAttribute : Attribute
- {
- public LCIDConversionAttribute(int lcid)
- {
- Value = lcid;
- }
-
- public int Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LayoutKind.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LayoutKind.cs
deleted file mode 100644
index dbd7ec62d54..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/LayoutKind.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Used in the StructLayoutAttribute class
- public enum LayoutKind
- {
- Sequential = 0,
- Explicit = 2,
- Auto = 3,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.NoCom.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.NoCom.cs
deleted file mode 100644
index b3101344516..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.NoCom.cs
+++ /dev/null
@@ -1,204 +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 System.Diagnostics.CodeAnalysis;
-using System.Reflection;
-using System.Runtime.InteropServices.ComTypes;
-
-namespace System.Runtime.InteropServices
-{
- public static partial class Marshal
- {
- public static int GetHRForException(Exception? e)
- {
- return e?.HResult ?? 0;
- }
-
- public static int AddRef(IntPtr pUnk)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static bool AreComObjectsAvailableForCleanup() => false;
-
- public static IntPtr CreateAggregatedObject(IntPtr pOuter, object o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object BindToMoniker(string monikerName)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static void CleanupUnusedObjectsInCurrentContext()
- {
- }
-
- public static IntPtr CreateAggregatedObject<T>(IntPtr pOuter, T o) where T : notnull
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object? CreateWrapperOfType(object? o, Type t)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static TWrapper CreateWrapperOfType<T, TWrapper>([AllowNull] T o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static void ChangeWrapperHandleStrength(object otp, bool fIsWeak)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static int FinalReleaseComObject(object o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static IntPtr GetComInterfaceForObject(object o, Type T)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static IntPtr GetComInterfaceForObject(object o, Type T, CustomQueryInterfaceMode mode)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static IntPtr GetComInterfaceForObject<T, TInterface>([DisallowNull] T o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object? GetComObjectData(object obj, object key)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static IntPtr GetHINSTANCE(Module m)
- {
- if (m is null)
- {
- throw new ArgumentNullException(nameof(m));
- }
-
- return (IntPtr)(-1);
- }
-
- public static IntPtr GetIUnknownForObject(object o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static void GetNativeVariantForObject(object? obj, IntPtr pDstNativeVariant)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static void GetNativeVariantForObject<T>([AllowNull] T obj, IntPtr pDstNativeVariant)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object GetTypedObjectForIUnknown(IntPtr pUnk, Type t)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object GetObjectForIUnknown(IntPtr pUnk)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object? GetObjectForNativeVariant(IntPtr pSrcNativeVariant)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- [return: MaybeNull]
- public static T GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object?[] GetObjectsForNativeVariants(IntPtr aSrcNativeVariant, int cVars)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static T[] GetObjectsForNativeVariants<T>(IntPtr aSrcNativeVariant, int cVars)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static int GetStartComSlot(Type t)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static int GetEndComSlot(Type t)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static Type GetTypeFromCLSID(Guid clsid)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static string GetTypeInfoName(ITypeInfo typeInfo)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static object GetUniqueObjectForIUnknown(IntPtr unknown)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static bool IsComObject(object o)
- {
- if (o is null)
- {
- throw new ArgumentNullException(nameof(o));
- }
-
- return false;
- }
-
- public static bool IsTypeVisibleFromCom(Type t)
- {
- if (t is null)
- {
- throw new ArgumentNullException(nameof(t));
- }
- return false;
- }
-
- public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static int Release(IntPtr pUnk)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static int ReleaseComObject(object o)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-
- public static bool SetComObjectData(object obj, object key, object? data)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs
deleted file mode 100644
index 63c790501e7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs
+++ /dev/null
@@ -1,66 +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 System.Diagnostics;
-using System.Text;
-
-namespace System.Runtime.InteropServices
-{
- public static partial class Marshal
- {
- public static string? PtrToStringAuto(IntPtr ptr, int len)
- {
- return PtrToStringUTF8(ptr, len);
- }
-
- public static string? PtrToStringAuto(IntPtr ptr)
- {
- return PtrToStringUTF8(ptr);
- }
-
- public static IntPtr StringToHGlobalAuto(string? s)
- {
- return StringToHGlobalUTF8(s);
- }
-
- public static IntPtr StringToCoTaskMemAuto(string? s)
- {
- return StringToCoTaskMemUTF8(s);
- }
-
- private static int GetSystemMaxDBCSCharSize() => 3;
-
- private static bool IsNullOrWin32Atom(IntPtr ptr) => ptr == IntPtr.Zero;
-
- internal static unsafe int StringToAnsiString(string s, byte* buffer, int bufferLength, bool bestFit = false, bool throwOnUnmappableChar = false)
- {
- Debug.Assert(bufferLength >= (s.Length + 1) * SystemMaxDBCSCharSize, "Insufficient buffer length passed to StringToAnsiString");
-
- int convertedBytes;
-
- fixed (char* pChar = s)
- {
- convertedBytes = Encoding.UTF8.GetBytes(pChar, s.Length, buffer, bufferLength);
- }
-
- buffer[convertedBytes] = 0;
-
- return convertedBytes;
- }
-
- // Returns number of bytes required to convert given string to Ansi string. The return value includes null terminator.
- internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
- {
- int byteLength = Encoding.UTF8.GetByteCount(chars);
- return checked(byteLength + 1);
- }
-
- // Converts given string to Ansi string. The destination buffer must be large enough to hold the converted value, including null terminator.
- internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<byte> bytes)
- {
- int actualByteLength = Encoding.UTF8.GetBytes(chars, bytes);
- bytes[actualByteLength] = 0;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs
deleted file mode 100644
index 9889030d882..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs
+++ /dev/null
@@ -1,131 +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 System.Diagnostics;
-
-namespace System.Runtime.InteropServices
-{
- public static partial class Marshal
- {
- public static string? PtrToStringAuto(IntPtr ptr, int len)
- {
- return PtrToStringUni(ptr, len);
- }
-
- public static string? PtrToStringAuto(IntPtr ptr)
- {
- return PtrToStringUni(ptr);
- }
-
- public static IntPtr StringToHGlobalAuto(string? s)
- {
- return StringToHGlobalUni(s);
- }
-
- public static IntPtr StringToCoTaskMemAuto(string? s)
- {
- return StringToCoTaskMemUni(s);
- }
-
- private static unsafe int GetSystemMaxDBCSCharSize()
- {
- Interop.Kernel32.CPINFO cpInfo = default;
-
- if (Interop.Kernel32.GetCPInfo(Interop.Kernel32.CP_ACP, &cpInfo) == Interop.BOOL.FALSE)
- return 2;
-
- return cpInfo.MaxCharSize;
- }
-
- // Win32 has the concept of Atoms, where a pointer can either be a pointer
- // or an int. If it's less than 64K, this is guaranteed to NOT be a
- // pointer since the bottom 64K bytes are reserved in a process' page table.
- // We should be careful about deallocating this stuff.
- private static bool IsNullOrWin32Atom(IntPtr ptr)
- {
- const long HIWORDMASK = unchecked((long)0xffffffffffff0000L);
-
- long lPtr = (long)ptr;
- return 0 == (lPtr & HIWORDMASK);
- }
-
- internal static unsafe int StringToAnsiString(string s, byte* buffer, int bufferLength, bool bestFit = false, bool throwOnUnmappableChar = false)
- {
- Debug.Assert(bufferLength >= (s.Length + 1) * SystemMaxDBCSCharSize, "Insufficient buffer length passed to StringToAnsiString");
-
- int nb;
-
- uint flags = bestFit ? 0 : Interop.Kernel32.WC_NO_BEST_FIT_CHARS;
- uint defaultCharUsed = 0;
-
- fixed (char* pwzChar = s)
- {
- nb = Interop.Kernel32.WideCharToMultiByte(
- Interop.Kernel32.CP_ACP,
- flags,
- pwzChar,
- s.Length,
- buffer,
- bufferLength,
- IntPtr.Zero,
- throwOnUnmappableChar ? new IntPtr(&defaultCharUsed) : IntPtr.Zero);
- }
-
- if (defaultCharUsed != 0)
- {
- throw new ArgumentException(SR.Interop_Marshal_Unmappable_Char);
- }
-
- buffer[nb] = 0;
- return nb;
- }
-
- // Returns number of bytes required to convert given string to Ansi string. The return value includes null terminator.
- internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
- {
- int byteLength;
-
- if (chars.Length == 0)
- {
- byteLength = 0;
- }
- else
- {
- fixed (char* pChars = chars)
- {
- byteLength = Interop.Kernel32.WideCharToMultiByte(
- Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
- if (byteLength <= 0)
- throw new ArgumentException();
- }
- }
-
- return checked(byteLength + 1);
- }
-
- // Converts given string to Ansi string. The destination buffer must be large enough to hold the converted value, including null terminator.
- internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<byte> bytes)
- {
- int byteLength;
-
- if (chars.Length == 0)
- {
- byteLength = 0;
- }
- else
- {
- fixed (char* pChars = chars)
- fixed (byte* pBytes = bytes)
- {
- byteLength = Interop.Kernel32.WideCharToMultiByte(
- Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, pBytes, bytes.Length, IntPtr.Zero, IntPtr.Zero);
- if (byteLength <= 0)
- throw new ArgumentException();
- }
- }
-
- bytes[byteLength] = 0;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs
deleted file mode 100644
index 4eaef53ec42..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.cs
+++ /dev/null
@@ -1,978 +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 System.Security;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-using Internal.Runtime.CompilerServices;
-using System.Diagnostics.CodeAnalysis;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// This class contains methods that are mainly used to marshal between unmanaged
- /// and managed types.
- /// </summary>
- public static partial class Marshal
- {
- /// <summary>
- /// The default character size for the system. This is always 2 because
- /// the framework only runs on UTF-16 systems.
- /// </summary>
- public static readonly int SystemDefaultCharSize = 2;
-
- /// <summary>
- /// The max DBCS character size for the system.
- /// </summary>
- public static readonly int SystemMaxDBCSCharSize = GetSystemMaxDBCSCharSize();
-
- public static IntPtr AllocHGlobal(int cb) => AllocHGlobal((IntPtr)cb);
-
- public static unsafe string? PtrToStringAnsi(IntPtr ptr)
- {
- if (IsNullOrWin32Atom(ptr))
- {
- return null;
- }
-
- return new string((sbyte*)ptr);
- }
-
- public static unsafe string PtrToStringAnsi(IntPtr ptr, int len)
- {
- if (ptr == IntPtr.Zero)
- {
- throw new ArgumentNullException(nameof(ptr));
- }
- if (len < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(len), len, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return new string((sbyte*)ptr, 0, len);
- }
-
- public static unsafe string? PtrToStringUni(IntPtr ptr)
- {
- if (IsNullOrWin32Atom(ptr))
- {
- return null;
- }
-
- return new string((char*)ptr);
- }
-
- public static unsafe string PtrToStringUni(IntPtr ptr, int len)
- {
- if (ptr == IntPtr.Zero)
- {
- throw new ArgumentNullException(nameof(ptr));
- }
- if (len < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(len), len, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return new string((char*)ptr, 0, len);
- }
-
- public static unsafe string? PtrToStringUTF8(IntPtr ptr)
- {
- if (IsNullOrWin32Atom(ptr))
- {
- return null;
- }
-
- int nbBytes = string.strlen((byte*)ptr);
- return string.CreateStringFromEncoding((byte*)ptr, nbBytes, Encoding.UTF8);
- }
-
- public static unsafe string PtrToStringUTF8(IntPtr ptr, int byteLen)
- {
- if (ptr == IntPtr.Zero)
- {
- throw new ArgumentNullException(nameof(ptr));
- }
- if (byteLen < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(byteLen), byteLen, SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return string.CreateStringFromEncoding((byte*)ptr, byteLen, Encoding.UTF8);
- }
-
- public static int SizeOf(object structure)
- {
- if (structure is null)
- {
- throw new ArgumentNullException(nameof(structure));
- }
-
- return SizeOfHelper(structure.GetType(), throwIfNotMarshalable: true);
- }
-
- public static int SizeOf<T>(T structure)
- {
- if (structure is null)
- {
- throw new ArgumentNullException(nameof(structure));
- }
-
- return SizeOfHelper(structure.GetType(), throwIfNotMarshalable: true);
- }
-
- public static int SizeOf(Type t)
- {
- if (t is null)
- {
- throw new ArgumentNullException(nameof(t));
- }
- if (!t.IsRuntimeImplemented())
- {
- throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(t));
- }
- if (t.IsGenericType)
- {
- throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(t));
- }
-
- return SizeOfHelper(t, throwIfNotMarshalable: true);
- }
-
- public static int SizeOf<T>() => SizeOf(typeof(T));
-
- /// <summary>
- /// IMPORTANT NOTICE: This method does not do any verification on the array.
- /// It must be used with EXTREME CAUTION since passing in invalid index or
- /// an array that is not pinned can cause unexpected results.
- /// </summary>
- public static unsafe IntPtr UnsafeAddrOfPinnedArrayElement(Array arr, int index)
- {
- if (arr is null)
- throw new ArgumentNullException(nameof(arr));
-
- void* pRawData = Unsafe.AsPointer(ref arr.GetRawArrayData());
- return (IntPtr)((byte*)pRawData + (uint)index * (nuint)arr.GetElementSize());
- }
-
- public static unsafe IntPtr UnsafeAddrOfPinnedArrayElement<T>(T[] arr, int index)
- {
- if (arr is null)
- throw new ArgumentNullException(nameof(arr));
-
- void* pRawData = Unsafe.AsPointer(ref arr.GetRawSzArrayData());
- return (IntPtr)((byte*)pRawData + (uint)index * (nuint)Unsafe.SizeOf<T>());
- }
-
- public static IntPtr OffsetOf<T>(string fieldName) => OffsetOf(typeof(T), fieldName);
-
- public static void Copy(int[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(char[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(short[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(long[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(float[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(double[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(byte[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- public static void Copy(IntPtr[] source, int startIndex, IntPtr destination, int length)
- {
- CopyToNative(source, startIndex, destination, length);
- }
-
- private static unsafe void CopyToNative<T>(T[] source, int startIndex, IntPtr destination, int length)
- {
- if (source is null)
- throw new ArgumentNullException(nameof(source));
- if (destination == IntPtr.Zero)
- throw new ArgumentNullException(nameof(destination));
-
- // The rest of the argument validation is done by CopyTo
-
- new Span<T>(source, startIndex, length).CopyTo(new Span<T>((void*)destination, length));
- }
-
- public static void Copy(IntPtr source, int[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, char[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, short[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, long[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, float[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, double[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, byte[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- public static void Copy(IntPtr source, IntPtr[] destination, int startIndex, int length)
- {
- CopyToManaged(source, destination, startIndex, length);
- }
-
- private static unsafe void CopyToManaged<T>(IntPtr source, T[] destination, int startIndex, int length)
- {
- if (source == IntPtr.Zero)
- throw new ArgumentNullException(nameof(source));
- if (destination is null)
- throw new ArgumentNullException(nameof(destination));
- if (startIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
- if (length < 0)
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // The rest of the argument validation is done by CopyTo
-
- new Span<T>((void*)source, length).CopyTo(new Span<T>(destination, startIndex, length));
- }
-
- public static unsafe byte ReadByte(IntPtr ptr, int ofs)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- return *addr;
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static byte ReadByte(IntPtr ptr) => ReadByte(ptr, 0);
-
- public static unsafe short ReadInt16(IntPtr ptr, int ofs)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x1) == 0)
- {
- // aligned read
- return *((short*)addr);
- }
- else
- {
- return Unsafe.ReadUnaligned<short>(addr);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static short ReadInt16(IntPtr ptr) => ReadInt16(ptr, 0);
-
- public static unsafe int ReadInt32(IntPtr ptr, int ofs)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x3) == 0)
- {
- // aligned read
- return *((int*)addr);
- }
- else
- {
- return Unsafe.ReadUnaligned<int>(addr);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static int ReadInt32(IntPtr ptr) => ReadInt32(ptr, 0);
-
- public static IntPtr ReadIntPtr(object ptr, int ofs)
- {
-#if BIT64
- return (IntPtr)ReadInt64(ptr, ofs);
-#else // 32
- return (IntPtr)ReadInt32(ptr, ofs);
-#endif
- }
-
- public static IntPtr ReadIntPtr(IntPtr ptr, int ofs)
- {
-#if BIT64
- return (IntPtr)ReadInt64(ptr, ofs);
-#else // 32
- return (IntPtr)ReadInt32(ptr, ofs);
-#endif
- }
-
- public static IntPtr ReadIntPtr(IntPtr ptr) => ReadIntPtr(ptr, 0);
-
- public static unsafe long ReadInt64(IntPtr ptr, int ofs)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x7) == 0)
- {
- // aligned read
- return *((long*)addr);
- }
- else
- {
- return Unsafe.ReadUnaligned<long>(addr);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static long ReadInt64(IntPtr ptr) => ReadInt64(ptr, 0);
-
- public static unsafe void WriteByte(IntPtr ptr, int ofs, byte val)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- *addr = val;
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static void WriteByte(IntPtr ptr, byte val) => WriteByte(ptr, 0, val);
-
- public static unsafe void WriteInt16(IntPtr ptr, int ofs, short val)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x1) == 0)
- {
- // aligned write
- *((short*)addr) = val;
- }
- else
- {
- Unsafe.WriteUnaligned(addr, val);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static void WriteInt16(IntPtr ptr, short val) => WriteInt16(ptr, 0, val);
-
- public static void WriteInt16(IntPtr ptr, int ofs, char val) => WriteInt16(ptr, ofs, (short)val);
-
- public static void WriteInt16([In, Out]object ptr, int ofs, char val) => WriteInt16(ptr, ofs, (short)val);
-
- public static void WriteInt16(IntPtr ptr, char val) => WriteInt16(ptr, 0, (short)val);
-
- public static unsafe void WriteInt32(IntPtr ptr, int ofs, int val)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x3) == 0)
- {
- // aligned write
- *((int*)addr) = val;
- }
- else
- {
- Unsafe.WriteUnaligned(addr, val);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static void WriteInt32(IntPtr ptr, int val) => WriteInt32(ptr, 0, val);
-
- public static void WriteIntPtr(IntPtr ptr, int ofs, IntPtr val)
- {
-#if BIT64
- WriteInt64(ptr, ofs, (long)val);
-#else // 32
- WriteInt32(ptr, ofs, (int)val);
-#endif
- }
-
- public static void WriteIntPtr(object ptr, int ofs, IntPtr val)
- {
-#if BIT64
- WriteInt64(ptr, ofs, (long)val);
-#else // 32
- WriteInt32(ptr, ofs, (int)val);
-#endif
- }
-
- public static void WriteIntPtr(IntPtr ptr, IntPtr val) => WriteIntPtr(ptr, 0, val);
-
- public static unsafe void WriteInt64(IntPtr ptr, int ofs, long val)
- {
- try
- {
- byte* addr = (byte*)ptr + ofs;
- if ((unchecked((int)addr) & 0x7) == 0)
- {
- // aligned write
- *((long*)addr) = val;
- }
- else
- {
- Unsafe.WriteUnaligned(addr, val);
- }
- }
- catch (NullReferenceException)
- {
- // this method is documented to throw AccessViolationException on any AV
- throw new AccessViolationException();
- }
- }
-
- public static void WriteInt64(IntPtr ptr, long val) => WriteInt64(ptr, 0, val);
-
- public static void Prelink(MethodInfo m)
- {
- if (m is null)
- {
- throw new ArgumentNullException(nameof(m));
- }
-
- PrelinkCore(m);
- }
-
- public static void PrelinkAll(Type c)
- {
- if (c is null)
- {
- throw new ArgumentNullException(nameof(c));
- }
-
- MethodInfo[] mi = c.GetMethods();
-
- for (int i = 0; i < mi.Length; i++)
- {
- Prelink(mi[i]);
- }
- }
-
- public static void StructureToPtr<T>([DisallowNull] T structure, IntPtr ptr, bool fDeleteOld)
- {
- StructureToPtr((object)structure!, ptr, fDeleteOld);
- }
-
- /// <summary>
- /// Creates a new instance of "structuretype" and marshals data from a
- /// native memory block to it.
- /// </summary>
- public static object? PtrToStructure(IntPtr ptr, Type structureType)
- {
- if (ptr == IntPtr.Zero)
- {
- return null;
- }
-
- if (structureType is null)
- {
- throw new ArgumentNullException(nameof(structureType));
- }
- if (structureType.IsGenericType)
- {
- throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(structureType));
- }
- if (!structureType.IsRuntimeImplemented())
- {
- throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(structureType));
- }
-
- return PtrToStructureHelper(ptr, structureType);
- }
-
- /// <summary>
- /// Marshals data from a native memory block to a preallocated structure class.
- /// </summary>
- public static void PtrToStructure(IntPtr ptr, object structure)
- {
- PtrToStructureHelper(ptr, structure, allowValueClasses: false);
- }
-
- public static void PtrToStructure<T>(IntPtr ptr, [DisallowNull] T structure)
- {
- PtrToStructure(ptr, (object)structure!);
- }
-
- [return: MaybeNull]
- public static T PtrToStructure<T>(IntPtr ptr) => (T)PtrToStructure(ptr, typeof(T))!;
-
- public static void DestroyStructure<T>(IntPtr ptr) => DestroyStructure(ptr, typeof(T));
-
- /// <summary>
- /// Converts the HRESULT to a CLR exception.
- /// </summary>
- public static Exception? GetExceptionForHR(int errorCode) => GetExceptionForHR(errorCode, IntPtr.Zero);
-
- public static Exception? GetExceptionForHR(int errorCode, IntPtr errorInfo)
- {
- if (errorCode >= 0)
- {
- return null;
- }
-
- return GetExceptionForHRInternal(errorCode, errorInfo);
- }
-
- /// <summary>
- /// Throws a CLR exception based on the HRESULT.
- /// </summary>
- public static void ThrowExceptionForHR(int errorCode)
- {
- if (errorCode < 0)
- {
- throw GetExceptionForHR(errorCode, IntPtr.Zero)!;
- }
- }
-
- public static void ThrowExceptionForHR(int errorCode, IntPtr errorInfo)
- {
- if (errorCode < 0)
- {
- throw GetExceptionForHR(errorCode, errorInfo)!;
- }
- }
-
- public static IntPtr SecureStringToBSTR(SecureString s)
- {
- if (s is null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- return s.MarshalToBSTR();
- }
-
- public static IntPtr SecureStringToCoTaskMemAnsi(SecureString s)
- {
- if (s is null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- return s.MarshalToString(globalAlloc: false, unicode: false);
- }
-
- public static IntPtr SecureStringToCoTaskMemUnicode(SecureString s)
- {
- if (s is null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- return s.MarshalToString(globalAlloc: false, unicode: true);
- }
-
- public static IntPtr SecureStringToGlobalAllocAnsi(SecureString s)
- {
- if (s is null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- return s.MarshalToString(globalAlloc: true, unicode: false);
- }
-
- public static IntPtr SecureStringToGlobalAllocUnicode(SecureString s)
- {
- if (s is null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- return s.MarshalToString(globalAlloc: true, unicode: true);
- }
-
- public static unsafe IntPtr StringToHGlobalAnsi(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- long lnb = (s.Length + 1) * (long)SystemMaxDBCSCharSize;
- int nb = (int)lnb;
-
- // Overflow checking
- if (nb != lnb)
- {
- throw new ArgumentOutOfRangeException(nameof(s));
- }
-
- IntPtr hglobal = AllocHGlobal((IntPtr)nb);
-
- StringToAnsiString(s, (byte*)hglobal, nb);
- return hglobal;
- }
-
- public static unsafe IntPtr StringToHGlobalUni(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- int nb = (s.Length + 1) * 2;
-
- // Overflow checking
- if (nb < s.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(s));
- }
-
- IntPtr hglobal = AllocHGlobal((IntPtr)nb);
-
- fixed (char* firstChar = s)
- {
- string.wstrcpy((char*)hglobal, firstChar, s.Length + 1);
- }
- return hglobal;
- }
-
- private static unsafe IntPtr StringToHGlobalUTF8(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- int nb = Encoding.UTF8.GetMaxByteCount(s.Length);
-
- IntPtr pMem = AllocHGlobal(nb + 1);
-
- int nbWritten;
- byte* pbMem = (byte*)pMem;
-
- fixed (char* firstChar = s)
- {
- nbWritten = Encoding.UTF8.GetBytes(firstChar, s.Length, pbMem, nb);
- }
-
- pbMem[nbWritten] = 0;
-
- return pMem;
- }
-
- public static unsafe IntPtr StringToCoTaskMemUni(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- int nb = (s.Length + 1) * 2;
-
- // Overflow checking
- if (nb < s.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(s));
- }
-
- IntPtr hglobal = AllocCoTaskMem(nb);
-
- fixed (char* firstChar = s)
- {
- string.wstrcpy((char*)hglobal, firstChar, s.Length + 1);
- }
- return hglobal;
- }
-
- public static unsafe IntPtr StringToCoTaskMemUTF8(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- int nb = Encoding.UTF8.GetMaxByteCount(s.Length);
-
- IntPtr pMem = AllocCoTaskMem(nb + 1);
-
- int nbWritten;
- byte* pbMem = (byte*)pMem;
-
- fixed (char* firstChar = s)
- {
- nbWritten = Encoding.UTF8.GetBytes(firstChar, s.Length, pbMem, nb);
- }
-
- pbMem[nbWritten] = 0;
-
- return pMem;
- }
-
- public static unsafe IntPtr StringToCoTaskMemAnsi(string? s)
- {
- if (s is null)
- {
- return IntPtr.Zero;
- }
-
- long lnb = (s.Length + 1) * (long)SystemMaxDBCSCharSize;
- int nb = (int)lnb;
-
- // Overflow checking
- if (nb != lnb)
- {
- throw new ArgumentOutOfRangeException(nameof(s));
- }
-
- IntPtr hglobal = AllocCoTaskMem(nb);
-
- StringToAnsiString(s, (byte*)hglobal, nb);
- return hglobal;
- }
-
- /// <summary>
- /// Generates a GUID for the specified type. If the type has a GUID in the
- /// metadata then it is returned otherwise a stable guid is generated based
- /// on the fully qualified name of the type.
- /// </summary>
- public static Guid GenerateGuidForType(Type type)
- {
- if (type is null)
- {
- throw new ArgumentNullException(nameof(type));
- }
- if (!type.IsRuntimeImplemented())
- {
- throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(type));
- }
-
- return type.GUID;
- }
-
- /// <summary>
- /// This method generates a PROGID for the specified type. If the type has
- /// a PROGID in the metadata then it is returned otherwise a stable PROGID
- /// is generated based on the fully qualified name of the type.
- /// </summary>
- public static string? GenerateProgIdForType(Type type)
- {
- if (type is null)
- {
- throw new ArgumentNullException(nameof(type));
- }
- if (type.IsImport)
- {
- throw new ArgumentException(SR.Argument_TypeMustNotBeComImport, nameof(type));
- }
- if (type.IsGenericType)
- {
- throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(type));
- }
-
- ProgIdAttribute? progIdAttribute = type.GetCustomAttribute<ProgIdAttribute>();
- if (progIdAttribute != null)
- {
- return progIdAttribute.Value ?? string.Empty;
- }
-
- // If there is no prog ID attribute then use the full name of the type as the prog id.
- return type.FullName;
- }
-
- public static Delegate GetDelegateForFunctionPointer(IntPtr ptr, Type t)
- {
- if (ptr == IntPtr.Zero)
- {
- throw new ArgumentNullException(nameof(ptr));
- }
- if (t is null)
- {
- throw new ArgumentNullException(nameof(t));
- }
- if (!t.IsRuntimeImplemented())
- {
- throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(t));
- }
- if (t.IsGenericType)
- {
- throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(t));
- }
-
- Type? c = t.BaseType;
- if (c != typeof(Delegate) && c != typeof(MulticastDelegate))
- {
- throw new ArgumentException(SR.Arg_MustBeDelegate, nameof(t));
- }
-
- return GetDelegateForFunctionPointerInternal(ptr, t);
- }
-
- public static TDelegate GetDelegateForFunctionPointer<TDelegate>(IntPtr ptr)
- {
- return (TDelegate)(object)GetDelegateForFunctionPointer(ptr, typeof(TDelegate));
- }
-
- public static IntPtr GetFunctionPointerForDelegate(Delegate d)
- {
- if (d is null)
- {
- throw new ArgumentNullException(nameof(d));
- }
-
- return GetFunctionPointerForDelegateInternal(d);
- }
-
- public static IntPtr GetFunctionPointerForDelegate<TDelegate>(TDelegate d) where TDelegate : notnull
- {
- return GetFunctionPointerForDelegate((Delegate)(object)d);
- }
-
- public static int GetHRForLastWin32Error()
- {
- int dwLastError = GetLastWin32Error();
- if ((dwLastError & 0x80000000) == 0x80000000)
- {
- return dwLastError;
- }
-
- return (dwLastError & 0x0000FFFF) | unchecked((int)0x80070000);
- }
-
- public static IntPtr /* IDispatch */ GetIDispatchForObject(object o) => throw new PlatformNotSupportedException();
-
- public static unsafe void ZeroFreeBSTR(IntPtr s)
- {
- if (s == IntPtr.Zero)
- {
- return;
- }
- Buffer.ZeroMemory((byte*)s, SysStringByteLen(s));
- FreeBSTR(s);
- }
-
- public static unsafe void ZeroFreeCoTaskMemAnsi(IntPtr s)
- {
- ZeroFreeCoTaskMemUTF8(s);
- }
-
- public static unsafe void ZeroFreeCoTaskMemUnicode(IntPtr s)
- {
- if (s == IntPtr.Zero)
- {
- return;
- }
- Buffer.ZeroMemory((byte*)s, (nuint)string.wcslen((char*)s) * sizeof(char));
- FreeCoTaskMem(s);
- }
-
- public static unsafe void ZeroFreeCoTaskMemUTF8(IntPtr s)
- {
- if (s == IntPtr.Zero)
- {
- return;
- }
- Buffer.ZeroMemory((byte*)s, (nuint)string.strlen((byte*)s));
- FreeCoTaskMem(s);
- }
-
- public static unsafe void ZeroFreeGlobalAllocAnsi(IntPtr s)
- {
- if (s == IntPtr.Zero)
- {
- return;
- }
- Buffer.ZeroMemory((byte*)s, (nuint)string.strlen((byte*)s));
- FreeHGlobal(s);
- }
-
- public static unsafe void ZeroFreeGlobalAllocUnicode(IntPtr s)
- {
- if (s == IntPtr.Zero)
- {
- return;
- }
- Buffer.ZeroMemory((byte*)s, (nuint)string.wcslen((char*)s) * sizeof(char));
- FreeHGlobal(s);
- }
-
- internal static unsafe uint SysStringByteLen(IntPtr s)
- {
- return *(((uint*)s) - 1);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalAsAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalAsAttribute.cs
deleted file mode 100644
index ae142a4323d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalAsAttribute.cs
+++ /dev/null
@@ -1,39 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.ReturnValue, Inherited = false)]
- public sealed partial class MarshalAsAttribute : Attribute
- {
- public MarshalAsAttribute(UnmanagedType unmanagedType)
- {
- Value = unmanagedType;
- }
- public MarshalAsAttribute(short unmanagedType)
- {
- Value = (UnmanagedType)unmanagedType;
- }
-
- public UnmanagedType Value { get; }
-
- // Fields used with SubType = SafeArray.
- public VarEnum SafeArraySubType;
- public Type? SafeArrayUserDefinedSubType;
-
- // Field used with iid_is attribute (interface pointers).
- public int IidParameterIndex;
-
- // Fields used with SubType = ByValArray and LPArray.
- // Array size = parameter(PI) * PM + C
- public UnmanagedType ArraySubType;
- public short SizeParamIndex; // param index PI
- public int SizeConst; // constant C
-
- // Fields used with SubType = CustomMarshaler
- public string? MarshalType; // Name of marshaler class
- public Type? MarshalTypeRef; // Type of marshaler class
- public string? MarshalCookie; // cookie to pass to marshaler
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs
deleted file mode 100644
index 1baae38e965..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MarshalDirectiveException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*=============================================================================
-**
-**
-** Purpose: This exception is thrown when the marshaller encounters a signature
-** that has an invalid MarshalAs CA for a given argument or is not
-** supported.
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class MarshalDirectiveException : SystemException
- {
- public MarshalDirectiveException()
- : base(SR.Arg_MarshalDirectiveException)
- {
- HResult = HResults.COR_E_MARSHALDIRECTIVE;
- }
-
- public MarshalDirectiveException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_MARSHALDIRECTIVE;
- }
-
- public MarshalDirectiveException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_MARSHALDIRECTIVE;
- }
-
- protected MarshalDirectiveException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs
deleted file mode 100644
index a61e0220885..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs
+++ /dev/null
@@ -1,535 +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 System.Buffers;
-using System.Runtime.CompilerServices;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-using Internal.Runtime.CompilerServices;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// Provides a collection of methods for interoperating with <see cref="Memory{T}"/>, <see cref="ReadOnlyMemory{T}"/>,
- /// <see cref="Span{T}"/>, and <see cref="ReadOnlySpan{T}"/>.
- /// </summary>
- public static class MemoryMarshal
- {
- /// <summary>
- /// Casts a Span of one primitive type <typeparamref name="T"/> to Span of bytes.
- /// That type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <param name="span">The source slice, of type <typeparamref name="T"/>.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when <typeparamref name="T"/> contains pointers.
- /// </exception>
- /// <exception cref="System.OverflowException">
- /// Thrown if the Length property of the new Span would exceed int.MaxValue.
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<byte> AsBytes<T>(Span<T> span)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
-
- return new Span<byte>(
- ref Unsafe.As<T, byte>(ref GetReference(span)),
- checked(span.Length * Unsafe.SizeOf<T>()));
- }
-
- /// <summary>
- /// Casts a ReadOnlySpan of one primitive type <typeparamref name="T"/> to ReadOnlySpan of bytes.
- /// That type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <param name="span">The source slice, of type <typeparamref name="T"/>.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when <typeparamref name="T"/> contains pointers.
- /// </exception>
- /// <exception cref="System.OverflowException">
- /// Thrown if the Length property of the new Span would exceed int.MaxValue.
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<byte> AsBytes<T>(ReadOnlySpan<T> span)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
-
- return new ReadOnlySpan<byte>(
- ref Unsafe.As<T, byte>(ref GetReference(span)),
- checked(span.Length * Unsafe.SizeOf<T>()));
- }
-
- /// <summary>Creates a <see cref="Memory{T}"/> from a <see cref="ReadOnlyMemory{T}"/>.</summary>
- /// <param name="memory">The <see cref="ReadOnlyMemory{T}"/>.</param>
- /// <returns>A <see cref="Memory{T}"/> representing the same memory as the <see cref="ReadOnlyMemory{T}"/>, but writable.</returns>
- /// <remarks>
- /// <see cref="AsMemory{T}(ReadOnlyMemory{T})"/> must be used with extreme caution. <see cref="ReadOnlyMemory{T}"/> is used
- /// to represent immutable data and other memory that is not meant to be written to; <see cref="Memory{T}"/> instances created
- /// by <see cref="AsMemory{T}(ReadOnlyMemory{T})"/> should not be written to. The method exists to enable variables typed
- /// as <see cref="Memory{T}"/> but only used for reading to store a <see cref="ReadOnlyMemory{T}"/>.
- /// </remarks>
- public static Memory<T> AsMemory<T>(ReadOnlyMemory<T> memory) =>
- Unsafe.As<ReadOnlyMemory<T>, Memory<T>>(ref memory);
-
- /// <summary>
- /// Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to the location where the 0th element
- /// would have been stored. Such a reference may or may not be null. It can be used for pinning but must never be dereferenced.
- /// </summary>
- public static ref T GetReference<T>(Span<T> span) => ref span._pointer.Value;
-
- /// <summary>
- /// Returns a reference to the 0th element of the ReadOnlySpan. If the ReadOnlySpan is empty, returns a reference to the location where the 0th element
- /// would have been stored. Such a reference may or may not be null. It can be used for pinning but must never be dereferenced.
- /// </summary>
- public static ref T GetReference<T>(ReadOnlySpan<T> span) => ref span._pointer.Value;
-
- /// <summary>
- /// Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to fake non-null pointer. Such a reference can be used
- /// for pinning but must never be dereferenced. This is useful for interop with methods that do not accept null pointers for zero-sized buffers.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe ref T GetNonNullPinnableReference<T>(Span<T> span) => ref (span.Length != 0) ? ref span._pointer.Value : ref Unsafe.AsRef<T>((void*)1);
-
- /// <summary>
- /// Returns a reference to the 0th element of the ReadOnlySpan. If the ReadOnlySpan is empty, returns a reference to fake non-null pointer. Such a reference
- /// can be used for pinning but must never be dereferenced. This is useful for interop with methods that do not accept null pointers for zero-sized buffers.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe ref T GetNonNullPinnableReference<T>(ReadOnlySpan<T> span) => ref (span.Length != 0) ? ref span._pointer.Value : ref Unsafe.AsRef<T>((void*)1);
-
- /// <summary>
- /// Casts a Span of one primitive type <typeparamref name="TFrom"/> to another primitive type <typeparamref name="TTo"/>.
- /// These types may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <remarks>
- /// Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means.
- /// </remarks>
- /// <param name="span">The source slice, of type <typeparamref name="TFrom"/>.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when <typeparamref name="TFrom"/> or <typeparamref name="TTo"/> contains pointers.
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<TTo> Cast<TFrom, TTo>(Span<TFrom> span)
- where TFrom : struct
- where TTo : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TFrom>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TTo>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));
-
- // Use unsigned integers - unsigned division by constant (especially by power of 2)
- // and checked casts are faster and smaller.
- uint fromSize = (uint)Unsafe.SizeOf<TFrom>();
- uint toSize = (uint)Unsafe.SizeOf<TTo>();
- uint fromLength = (uint)span.Length;
- int toLength;
- if (fromSize == toSize)
- {
- // Special case for same size types - `(ulong)fromLength * (ulong)fromSize / (ulong)toSize`
- // should be optimized to just `length` but the JIT doesn't do that today.
- toLength = (int)fromLength;
- }
- else if (fromSize == 1)
- {
- // Special case for byte sized TFrom - `(ulong)fromLength * (ulong)fromSize / (ulong)toSize`
- // becomes `(ulong)fromLength / (ulong)toSize` but the JIT can't narrow it down to `int`
- // and can't eliminate the checked cast. This also avoids a 32 bit specific issue,
- // the JIT can't eliminate long multiply by 1.
- toLength = (int)(fromLength / toSize);
- }
- else
- {
- // Ensure that casts are done in such a way that the JIT is able to "see"
- // the uint->ulong casts and the multiply together so that on 32 bit targets
- // 32x32to64 multiplication is used.
- ulong toLengthUInt64 = (ulong)fromLength * (ulong)fromSize / (ulong)toSize;
- toLength = checked((int)toLengthUInt64);
- }
-
- return new Span<TTo>(
- ref Unsafe.As<TFrom, TTo>(ref span._pointer.Value),
- toLength);
- }
-
- /// <summary>
- /// Casts a ReadOnlySpan of one primitive type <typeparamref name="TFrom"/> to another primitive type <typeparamref name="TTo"/>.
- /// These types may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <remarks>
- /// Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means.
- /// </remarks>
- /// <param name="span">The source slice, of type <typeparamref name="TFrom"/>.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when <typeparamref name="TFrom"/> or <typeparamref name="TTo"/> contains pointers.
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<TTo> Cast<TFrom, TTo>(ReadOnlySpan<TFrom> span)
- where TFrom : struct
- where TTo : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TFrom>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
- if (RuntimeHelpers.IsReferenceOrContainsReferences<TTo>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));
-
- // Use unsigned integers - unsigned division by constant (especially by power of 2)
- // and checked casts are faster and smaller.
- uint fromSize = (uint)Unsafe.SizeOf<TFrom>();
- uint toSize = (uint)Unsafe.SizeOf<TTo>();
- uint fromLength = (uint)span.Length;
- int toLength;
- if (fromSize == toSize)
- {
- // Special case for same size types - `(ulong)fromLength * (ulong)fromSize / (ulong)toSize`
- // should be optimized to just `length` but the JIT doesn't do that today.
- toLength = (int)fromLength;
- }
- else if (fromSize == 1)
- {
- // Special case for byte sized TFrom - `(ulong)fromLength * (ulong)fromSize / (ulong)toSize`
- // becomes `(ulong)fromLength / (ulong)toSize` but the JIT can't narrow it down to `int`
- // and can't eliminate the checked cast. This also avoids a 32 bit specific issue,
- // the JIT can't eliminate long multiply by 1.
- toLength = (int)(fromLength / toSize);
- }
- else
- {
- // Ensure that casts are done in such a way that the JIT is able to "see"
- // the uint->ulong casts and the multiply together so that on 32 bit targets
- // 32x32to64 multiplication is used.
- ulong toLengthUInt64 = (ulong)fromLength * (ulong)fromSize / (ulong)toSize;
- toLength = checked((int)toLengthUInt64);
- }
-
- return new ReadOnlySpan<TTo>(
- ref Unsafe.As<TFrom, TTo>(ref MemoryMarshal.GetReference(span)),
- toLength);
- }
-
- /// <summary>
- /// Create a new span over a portion of a regular managed object. This can be useful
- /// if part of a managed object represents a "fixed array." This is dangerous because the
- /// <paramref name="length"/> is not checked.
- /// </summary>
- /// <param name="reference">A reference to data.</param>
- /// <param name="length">The number of <typeparamref name="T"/> elements the memory contains.</param>
- /// <returns>The lifetime of the returned span will not be validated for safety by span-aware languages.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Span<T> CreateSpan<T>(ref T reference, int length) => new Span<T>(ref reference, length);
-
- /// <summary>
- /// Create a new read-only span over a portion of a regular managed object. This can be useful
- /// if part of a managed object represents a "fixed array." This is dangerous because the
- /// <paramref name="length"/> is not checked.
- /// </summary>
- /// <param name="reference">A reference to data.</param>
- /// <param name="length">The number of <typeparamref name="T"/> elements the memory contains.</param>
- /// <returns>The lifetime of the returned span will not be validated for safety by span-aware languages.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ReadOnlySpan<T> CreateReadOnlySpan<T>(ref T reference, int length) => new ReadOnlySpan<T>(ref reference, length);
-
- /// <summary>
- /// Get an array segment from the underlying memory.
- /// If unable to get the array segment, return false with a default array segment.
- /// </summary>
- public static bool TryGetArray<T>(ReadOnlyMemory<T> memory, out ArraySegment<T> segment)
- {
- object? obj = memory.GetObjectStartLength(out int index, out int length);
-
- // As an optimization, we skip the "is string?" check below if typeof(T) is not char,
- // as Memory<T> / ROM<T> can't possibly contain a string instance in this case.
-
- if (obj != null && !(
- (typeof(T) == typeof(char) && obj.GetType() == typeof(string))
-#if FEATURE_UTF8STRING
- || ((typeof(T) == typeof(byte) || typeof(T) == typeof(Char8)) && obj.GetType() == typeof(Utf8String))
-#endif // FEATURE_UTF8STRING
- ))
- {
- if (RuntimeHelpers.ObjectHasComponentSize(obj))
- {
- // The object has a component size, which means it's variable-length, but we already
- // checked above that it's not a string. The only remaining option is that it's a T[]
- // or a U[] which is blittable to a T[] (e.g., int[] and uint[]).
-
- // The array may be prepinned, so remove the high bit from the start index in the line below.
- // The ArraySegment<T> ctor will perform bounds checking on index & length.
-
- segment = new ArraySegment<T>(Unsafe.As<T[]>(obj), index & ReadOnlyMemory<T>.RemoveFlagsBitMask, length);
- return true;
- }
- else
- {
- // The object isn't null, and it's not variable-length, so the only remaining option
- // is MemoryManager<T>. The ArraySegment<T> ctor will perform bounds checking on index & length.
-
- Debug.Assert(obj is MemoryManager<T>);
- if (Unsafe.As<MemoryManager<T>>(obj).TryGetArray(out ArraySegment<T> tempArraySegment))
- {
- segment = new ArraySegment<T>(tempArraySegment.Array!, tempArraySegment.Offset + index, length);
- return true;
- }
- }
- }
-
- // If we got to this point, the object is null, or it's a string, or it's a MemoryManager<T>
- // which isn't backed by an array. We'll quickly homogenize all zero-length Memory<T> instances
- // to an empty array for the purposes of reporting back to our caller.
-
- if (length == 0)
- {
- segment = ArraySegment<T>.Empty;
- return true;
- }
-
- // Otherwise, there's *some* data, but it's not convertible to T[].
-
- segment = default;
- return false;
- }
-
- /// <summary>
- /// Gets an <see cref="MemoryManager{T}"/> from the underlying read-only memory.
- /// If unable to get the <typeparamref name="TManager"/> type, returns false.
- /// </summary>
- /// <typeparam name="T">The element type of the <paramref name="memory" />.</typeparam>
- /// <typeparam name="TManager">The type of <see cref="MemoryManager{T}"/> to try and retrive.</typeparam>
- /// <param name="memory">The memory to get the manager for.</param>
- /// <param name="manager">The returned manager of the <see cref="ReadOnlyMemory{T}"/>.</param>
- /// <returns>A <see cref="bool"/> indicating if it was successful.</returns>
- public static bool TryGetMemoryManager<T, TManager>(ReadOnlyMemory<T> memory, [NotNullWhen(true)] out TManager? manager)
- where TManager : MemoryManager<T>
- {
- TManager? localManager; // Use register for null comparison rather than byref
- manager = localManager = memory.GetObjectStartLength(out _, out _) as TManager;
- return localManager != null;
- }
-
- /// <summary>
- /// Gets an <see cref="MemoryManager{T}"/> and <paramref name="start" />, <paramref name="length" /> from the underlying read-only memory.
- /// If unable to get the <typeparamref name="TManager"/> type, returns false.
- /// </summary>
- /// <typeparam name="T">The element type of the <paramref name="memory" />.</typeparam>
- /// <typeparam name="TManager">The type of <see cref="MemoryManager{T}"/> to try and retrive.</typeparam>
- /// <param name="memory">The memory to get the manager for.</param>
- /// <param name="manager">The returned manager of the <see cref="ReadOnlyMemory{T}"/>.</param>
- /// <param name="start">The offset from the start of the <paramref name="manager" /> that the <paramref name="memory" /> represents.</param>
- /// <param name="length">The length of the <paramref name="manager" /> that the <paramref name="memory" /> represents.</param>
- /// <returns>A <see cref="bool"/> indicating if it was successful.</returns>
- public static bool TryGetMemoryManager<T, TManager>(ReadOnlyMemory<T> memory, [NotNullWhen(true)] out TManager? manager, out int start, out int length)
- where TManager : MemoryManager<T>
- {
- TManager? localManager; // Use register for null comparison rather than byref
- manager = localManager = memory.GetObjectStartLength(out start, out length) as TManager;
-
- Debug.Assert(length >= 0);
-
- if (localManager == null)
- {
- start = default;
- length = default;
- return false;
- }
- return true;
- }
-
- /// <summary>
- /// Creates an <see cref="IEnumerable{T}"/> view of the given <paramref name="memory" /> to allow
- /// the <paramref name="memory" /> to be used in existing APIs that take an <see cref="IEnumerable{T}"/>.
- /// </summary>
- /// <typeparam name="T">The element type of the <paramref name="memory" />.</typeparam>
- /// <param name="memory">The ReadOnlyMemory to view as an <see cref="IEnumerable{T}"/></param>
- /// <returns>An <see cref="IEnumerable{T}"/> view of the given <paramref name="memory" /></returns>
- public static IEnumerable<T> ToEnumerable<T>(ReadOnlyMemory<T> memory)
- {
- for (int i = 0; i < memory.Length; i++)
- yield return memory.Span[i];
- }
-
- /// <summary>Attempts to get the underlying <see cref="string"/> from a <see cref="ReadOnlyMemory{T}"/>.</summary>
- /// <param name="memory">The memory that may be wrapping a <see cref="string"/> object.</param>
- /// <param name="text">The string.</param>
- /// <param name="start">The starting location in <paramref name="text"/>.</param>
- /// <param name="length">The number of items in <paramref name="text"/>.</param>
- /// <returns></returns>
- public static bool TryGetString(ReadOnlyMemory<char> memory, [NotNullWhen(true)] out string? text, out int start, out int length)
- {
- if (memory.GetObjectStartLength(out int offset, out int count) is string s)
- {
- Debug.Assert(offset >= 0);
- Debug.Assert(count >= 0);
- text = s;
- start = offset;
- length = count;
- return true;
- }
- else
- {
- text = null;
- start = 0;
- length = 0;
- return false;
- }
- }
-
- /// <summary>
- /// Reads a structure of type T out of a read-only span of bytes.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static T Read<T>(ReadOnlySpan<byte> source)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if (Unsafe.SizeOf<T>() > source.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
- }
- return Unsafe.ReadUnaligned<T>(ref GetReference(source));
- }
-
- /// <summary>
- /// Reads a structure of type T out of a span of bytes.
- /// <returns>If the span is too small to contain the type T, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryRead<T>(ReadOnlySpan<byte> source, out T value)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if (Unsafe.SizeOf<T>() > (uint)source.Length)
- {
- value = default;
- return false;
- }
- value = Unsafe.ReadUnaligned<T>(ref GetReference(source));
- return true;
- }
-
- /// <summary>
- /// Writes a structure of type T into a span of bytes.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Write<T>(Span<byte> destination, ref T value)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if ((uint)Unsafe.SizeOf<T>() > (uint)destination.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
- }
- Unsafe.WriteUnaligned<T>(ref GetReference(destination), value);
- }
-
- /// <summary>
- /// Writes a structure of type T into a span of bytes.
- /// <returns>If the span is too small to contain the type T, return false.</returns>
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool TryWrite<T>(Span<byte> destination, ref T value)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if (Unsafe.SizeOf<T>() > (uint)destination.Length)
- {
- return false;
- }
- Unsafe.WriteUnaligned<T>(ref GetReference(destination), value);
- return true;
- }
-
- /// <summary>
- /// Re-interprets a span of bytes as a reference to structure of type T.
- /// The type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <remarks>
- /// Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref T AsRef<T>(Span<byte> span)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if (Unsafe.SizeOf<T>() > (uint)span.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
- }
- return ref Unsafe.As<byte, T>(ref GetReference(span));
- }
-
- /// <summary>
- /// Re-interprets a span of bytes as a reference to structure of type T.
- /// The type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
- /// </summary>
- /// <remarks>
- /// Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref readonly T AsRef<T>(ReadOnlySpan<byte> span)
- where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- }
- if (Unsafe.SizeOf<T>() > (uint)span.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length);
- }
- return ref Unsafe.As<byte, T>(ref GetReference(span));
- }
-
- /// <summary>
- /// Creates a new memory over the portion of the pre-pinned target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="array">The pre-pinned target array.</param>
- /// <param name="start">The index at which to begin the memory.</param>
- /// <param name="length">The number of items in the memory.</param>
- /// <remarks>This method should only be called on an array that is already pinned and
- /// that array should not be unpinned while the returned Memory<typeparamref name="T"/> is still in use.
- /// Calling this method on an unpinned array could result in memory corruption.</remarks>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;=Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Memory<T> CreateFromPinnedArray<T>(T[]? array, int start, int length)
- {
- if (array == null)
- {
- if (start != 0 || length != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
- return default;
- }
- if (default(T)! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- ThrowHelper.ThrowArrayTypeMismatchException();
- if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- // Before using _index, check if _index < 0, then 'and' it with RemoveFlagsBitMask
- return new Memory<T>((object)array, start | (1 << 31), length);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeCallableAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeCallableAttribute.cs
deleted file mode 100644
index 5fa60f460f8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeCallableAttribute.cs
+++ /dev/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.
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// Any method marked with NativeCallableAttribute can be directly called from
- /// native code. The function token can be loaded to a local variable using LDFTN
- /// and passed as a callback to native method.
- /// </summary>
- [AttributeUsage(AttributeTargets.Method)]
- public sealed class NativeCallableAttribute : Attribute
- {
- public NativeCallableAttribute()
- {
- }
-
- /// <summary>
- /// Optional. If omitted, compiler will choose one for you.
- /// </summary>
- public CallingConvention CallingConvention;
-
- /// <summary>
- /// Optional. If omitted, then the method is native callable, but no EAT is emitted.
- /// </summary>
- public string? EntryPoint;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs
deleted file mode 100644
index 9bd65fe57b1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs
+++ /dev/null
@@ -1,248 +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 System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Threading;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// A delegate used to resolve native libraries via callback.
- /// </summary>
- /// <param name="libraryName">The native library to resolve</param>
- /// <param name="assembly">The assembly requesting the resolution</param>
- /// <param name="searchPath">
- /// The DllImportSearchPathsAttribute on the PInvoke, if any.
- /// Otherwise, the DllImportSearchPathsAttribute on the assembly, if any.
- /// Otherwise null.
- /// </param>
- /// <returns>The handle for the loaded native library on success, null on failure</returns>
- public delegate IntPtr DllImportResolver(string libraryName,
- Assembly assembly,
- DllImportSearchPath? searchPath);
-
- /// <summary>
- /// APIs for managing Native Libraries
- /// </summary>
- public static partial class NativeLibrary
- {
- /// <summary>
- /// NativeLibrary Loader: Simple API
- /// This method is a wrapper around OS loader, using "default" flags.
- /// </summary>
- /// <param name="libraryPath">The name of the native library to be loaded</param>
- /// <returns>The handle for the loaded native library</returns>
- /// <exception cref="System.ArgumentNullException">If libraryPath is null</exception>
- /// <exception cref="System.DllNotFoundException ">If the library can't be found.</exception>
- /// <exception cref="System.BadImageFormatException">If the library is not valid.</exception>
- public static IntPtr Load(string libraryPath)
- {
- if (libraryPath == null)
- throw new ArgumentNullException(nameof(libraryPath));
-
- return LoadFromPath(libraryPath, throwOnError: true);
- }
-
- /// <summary>
- /// NativeLibrary Loader: Simple API that doesn't throw
- /// </summary>
- /// <param name="libraryPath">The name of the native library to be loaded</param>
- /// <param name="handle">The out-parameter for the loaded native library handle</param>
- /// <returns>True on successful load, false otherwise</returns>
- /// <exception cref="System.ArgumentNullException">If libraryPath is null</exception>
- public static bool TryLoad(string libraryPath, out IntPtr handle)
- {
- if (libraryPath == null)
- throw new ArgumentNullException(nameof(libraryPath));
-
- handle = LoadFromPath(libraryPath, throwOnError: false);
- return handle != IntPtr.Zero;
- }
-
- /// <summary>
- /// NativeLibrary Loader: High-level API
- /// Given a library name, this function searches specific paths based on the
- /// runtime configuration, input parameters, and attributes of the calling assembly.
- /// If DllImportSearchPath parameter is non-null, the flags in this enumeration are used.
- /// Otherwise, the flags specified by the DefaultDllImportSearchPaths attribute on the
- /// calling assembly (if any) are used.
- /// This LoadLibrary() method does not invoke the managed call-backs for native library resolution:
- /// * The per-assembly registered callback
- /// * AssemblyLoadContext.LoadUnmanagedDll()
- /// * AssemblyLoadContext.ResolvingUnmanagedDllEvent
- /// </summary>
- /// <param name="libraryName">The name of the native library to be loaded</param>
- /// <param name="assembly">The assembly loading the native library</param>
- /// <param name="searchPath">The search path</param>
- /// <returns>The handle for the loaded library</returns>
- /// <exception cref="System.ArgumentNullException">If libraryPath or assembly is null</exception>
- /// <exception cref="System.ArgumentException">If assembly is not a RuntimeAssembly</exception>
- /// <exception cref="System.DllNotFoundException ">If the library can't be found.</exception>
- /// <exception cref="System.BadImageFormatException">If the library is not valid.</exception>
- public static IntPtr Load(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
- {
- if (libraryName == null)
- throw new ArgumentNullException(nameof(libraryName));
- if (assembly == null)
- throw new ArgumentNullException(nameof(assembly));
- if (!assembly.IsRuntimeImplemented())
- throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly);
-
- return LoadLibraryByName(libraryName,
- assembly,
- searchPath,
- throwOnError: true);
- }
-
- /// <summary>
- /// NativeLibrary Loader: High-level API that doesn't throw.
- /// </summary>
- /// <param name="libraryName">The name of the native library to be loaded</param>
- /// <param name="searchPath">The search path</param>
- /// <param name="assembly">The assembly loading the native library</param>
- /// <param name="handle">The out-parameter for the loaded native library handle</param>
- /// <returns>True on successful load, false otherwise</returns>
- /// <exception cref="System.ArgumentNullException">If libraryPath or assembly is null</exception>
- /// <exception cref="System.ArgumentException">If assembly is not a RuntimeAssembly</exception>
- public static bool TryLoad(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out IntPtr handle)
- {
- if (libraryName == null)
- throw new ArgumentNullException(nameof(libraryName));
- if (assembly == null)
- throw new ArgumentNullException(nameof(assembly));
- if (!assembly.IsRuntimeImplemented())
- throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly);
-
- handle = LoadLibraryByName(libraryName,
- assembly,
- searchPath,
- throwOnError: false);
- return handle != IntPtr.Zero;
- }
-
- /// <summary>
- /// Free a loaded library
- /// Given a library handle, free it.
- /// No action if the input handle is null.
- /// </summary>
- /// <param name="handle">The native library handle to be freed</param>
- public static void Free(IntPtr handle)
- {
- if (handle == IntPtr.Zero)
- return;
- FreeLib(handle);
- }
-
- /// <summary>
- /// Get the address of an exported Symbol
- /// This is a simple wrapper around OS calls, and does not perform any name mangling.
- /// </summary>
- /// <param name="handle">The native library handle</param>
- /// <param name="name">The name of the exported symbol</param>
- /// <returns>The address of the symbol</returns>
- /// <exception cref="System.ArgumentNullException">If handle or name is null</exception>
- /// <exception cref="System.EntryPointNotFoundException">If the symbol is not found</exception>
- public static IntPtr GetExport(IntPtr handle, string name)
- {
- if (handle == IntPtr.Zero)
- throw new ArgumentNullException(nameof(handle));
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- return GetSymbol(handle, name, throwOnError: true);
- }
-
- /// <summary>
- /// Get the address of an exported Symbol, but do not throw
- /// </summary>
- /// <param name="handle">The native library handle</param>
- /// <param name="name">The name of the exported symbol</param>
- /// <param name="address"> The out-parameter for the symbol address, if it exists</param>
- /// <returns>True on success, false otherwise</returns>
- /// <exception cref="System.ArgumentNullException">If handle or name is null</exception>
- public static bool TryGetExport(IntPtr handle, string name, out IntPtr address)
- {
- if (handle == IntPtr.Zero)
- throw new ArgumentNullException(nameof(handle));
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- address = GetSymbol(handle, name, throwOnError: false);
- return address != IntPtr.Zero;
- }
-
- /// <summary>
- /// Map from assembly to native-library resolver.
- /// Interop specific fields and properties are generally not added to Assembly class.
- /// Therefore, this table uses weak assembly pointers to indirectly achieve
- /// similar behavior.
- /// </summary>
- private static ConditionalWeakTable<Assembly, DllImportResolver>? s_nativeDllResolveMap;
-
- /// <summary>
- /// Set a callback for resolving native library imports from an assembly.
- /// This per-assembly resolver is the first attempt to resolve native library loads
- /// initiated by this assembly.
- ///
- /// Only one resolver can be registered per assembly.
- /// Trying to register a second resolver fails with InvalidOperationException.
- /// </summary>
- /// <param name="assembly">The assembly for which the resolver is registered</param>
- /// <param name="resolver">The resolver callback to register</param>
- /// <exception cref="System.ArgumentNullException">If assembly or resolver is null</exception>
- /// <exception cref="System.ArgumentException">If a resolver is already set for this assembly</exception>
- public static void SetDllImportResolver(Assembly assembly, DllImportResolver resolver)
- {
- if (assembly == null)
- throw new ArgumentNullException(nameof(assembly));
- if (resolver == null)
- throw new ArgumentNullException(nameof(resolver));
- if (!assembly.IsRuntimeImplemented())
- throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly);
-
- if (s_nativeDllResolveMap == null)
- {
- Interlocked.CompareExchange(ref s_nativeDllResolveMap,
- new ConditionalWeakTable<Assembly, DllImportResolver>(), null);
- }
-
- try
- {
- s_nativeDllResolveMap.Add(assembly, resolver);
- }
- catch (ArgumentException)
- {
- // ConditionalWealTable throws ArgumentException if the Key already exists
- throw new InvalidOperationException(SR.InvalidOperation_CannotRegisterSecondResolver);
- }
- }
-
- /// <summary>
- /// The helper function that calls the per-assembly native-library resolver
- /// if one is registered for this assembly.
- /// </summary>
- /// <param name="libraryName">The native library to load</param>
- /// <param name="assembly">The assembly trying load the native library</param>
- /// <param name="hasDllImportSearchPathFlags">If the pInvoke has DefaultDllImportSearchPathAttribute</param>
- /// <param name="dllImportSearchPathFlags">If hasdllImportSearchPathFlags is true, the flags in
- /// DefaultDllImportSearchPathAttribute; meaningless otherwise </param>
- /// <returns>The handle for the loaded library on success. Null on failure.</returns>
- internal static IntPtr LoadLibraryCallbackStub(string libraryName, Assembly assembly,
- bool hasDllImportSearchPathFlags, uint dllImportSearchPathFlags)
- {
- if (s_nativeDllResolveMap == null)
- {
- return IntPtr.Zero;
- }
-
- if (!s_nativeDllResolveMap.TryGetValue(assembly, out DllImportResolver? resolver))
- {
- return IntPtr.Zero;
- }
-
- return resolver(libraryName, assembly, hasDllImportSearchPathFlags ? (DllImportSearchPath?)dllImportSearchPathFlags : null);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OptionalAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OptionalAttribute.cs
deleted file mode 100644
index 5ac75d7b3e9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OptionalAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- public sealed class OptionalAttribute : Attribute
- {
- public OptionalAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OutAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OutAttribute.cs
deleted file mode 100644
index 338ceac91e1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/OutAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- public sealed class OutAttribute : Attribute
- {
- public OutAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/PreserveSigAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/PreserveSigAttribute.cs
deleted file mode 100644
index 464e1abcbeb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/PreserveSigAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class PreserveSigAttribute : Attribute
- {
- public PreserveSigAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs
deleted file mode 100644
index bc4bd18bb1b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/ProgIdAttribute.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Class, Inherited = false)]
- public sealed class ProgIdAttribute : Attribute
- {
- public ProgIdAttribute(string progId)
- {
- Value = progId;
- }
-
- public string Value { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs
deleted file mode 100644
index 0f44e3e99ec..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SEHException.cs
+++ /dev/null
@@ -1,47 +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 System.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// Exception for Structured Exception Handler exceptions.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class SEHException : ExternalException
- {
- public SEHException()
- {
- HResult = HResults.E_FAIL;
- }
-
- public SEHException(string? message)
- : base(message)
- {
- HResult = HResults.E_FAIL;
- }
-
- public SEHException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.E_FAIL;
- }
-
- protected SEHException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
-
- // Exceptions can be resumable, meaning a filtered exception
- // handler can correct the problem that caused the exception,
- // and the code will continue from the point that threw the
- // exception.
- //
- // Resumable exceptions aren't implemented in this version,
- // but this method exists and always returns false.
- //
- public virtual bool CanResume() => false;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs
deleted file mode 100644
index 1bd3fdd9f3d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayRankMismatchException.cs
+++ /dev/null
@@ -1,39 +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 System.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// The exception is thrown when the runtime rank of a safe array is different
- /// than the array rank specified in the metadata.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class SafeArrayRankMismatchException : SystemException
- {
- public SafeArrayRankMismatchException()
- : base(SR.Arg_SafeArrayRankMismatchException)
- {
- HResult = HResults.COR_E_SAFEARRAYRANKMISMATCH;
- }
-
- public SafeArrayRankMismatchException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_SAFEARRAYRANKMISMATCH;
- }
-
- public SafeArrayRankMismatchException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_SAFEARRAYRANKMISMATCH;
- }
-
- protected SafeArrayRankMismatchException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs
deleted file mode 100644
index 2cb1fc475ae..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeArrayTypeMismatchException.cs
+++ /dev/null
@@ -1,39 +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 System.Runtime.Serialization;
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// The exception is thrown when the runtime type of an array is different
- /// than the safe array sub type specified in the metadata.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class SafeArrayTypeMismatchException : SystemException
- {
- public SafeArrayTypeMismatchException()
- : base(SR.Arg_SafeArrayTypeMismatchException)
- {
- HResult = HResults.COR_E_SAFEARRAYTYPEMISMATCH;
- }
-
- public SafeArrayTypeMismatchException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_SAFEARRAYTYPEMISMATCH;
- }
-
- public SafeArrayTypeMismatchException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_SAFEARRAYTYPEMISMATCH;
- }
-
- protected SafeArrayTypeMismatchException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs
deleted file mode 100644
index 19e021c6b37..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeBuffer.cs
+++ /dev/null
@@ -1,393 +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.
-
-/*============================================================
-**
-** Purpose: Unsafe code that uses pointers should use
-** SafePointer to fix subtle lifetime problems with the
-** underlying resource.
-**
-===========================================================*/
-
-// Design points:
-// *) Avoid handle-recycling problems (including ones triggered via
-// resurrection attacks) for all accesses via pointers. This requires tying
-// together the lifetime of the unmanaged resource with the code that reads
-// from that resource, in a package that uses synchronization to enforce
-// the correct semantics during finalization. We're using SafeHandle's
-// ref count as a gate on whether the pointer can be dereferenced because that
-// controls the lifetime of the resource.
-//
-// *) Keep the penalties for using this class small, both in terms of space
-// and time. Having multiple threads reading from a memory mapped file
-// will already require 2 additional interlocked operations. If we add in
-// a "current position" concept, that requires additional space in memory and
-// synchronization. Since the position in memory is often (but not always)
-// something that can be stored on the stack, we can save some memory by
-// excluding it from this object. However, avoiding the need for
-// synchronization is a more significant win. This design allows multiple
-// threads to read and write memory simultaneously without locks (as long as
-// you don't write to a region of memory that overlaps with what another
-// thread is accessing).
-//
-// *) Space-wise, we use the following memory, including SafeHandle's fields:
-// Object Header MT* handle int bool bool <2 pad bytes> length
-// On 32 bit platforms: 24 bytes. On 64 bit platforms: 40 bytes.
-// (We can safe 4 bytes on x86 only by shrinking SafeHandle)
-//
-// *) Wrapping a SafeHandle would have been a nice solution, but without an
-// ordering between critical finalizable objects, it would have required
-// changes to each SafeHandle subclass to opt in to being usable from a
-// SafeBuffer (or some clever exposure of SafeHandle's state fields and a
-// way of forcing ReleaseHandle to run even after the SafeHandle has been
-// finalized with a ref count > 1). We can use less memory and create fewer
-// objects by simply inserting a SafeBuffer into the class hierarchy.
-//
-// *) In an ideal world, we could get marshaling support for SafeBuffer that
-// would allow us to annotate a P/Invoke declaration, saying this parameter
-// specifies the length of the buffer, and the units of that length are X.
-// P/Invoke would then pass that size parameter to SafeBuffer.
-// [DllImport(...)]
-// static extern SafeMemoryHandle AllocCharBuffer(int numChars);
-// If we could put an attribute on the SafeMemoryHandle saying numChars is
-// the element length, and it must be multiplied by 2 to get to the byte
-// length, we can simplify the usage model for SafeBuffer.
-//
-// *) This class could benefit from a constraint saying T is a value type
-// containing no GC references.
-
-// Implementation notes:
-// *) The Initialize method must be called before you use any instance of
-// a SafeBuffer. To avoid race conditions when storing SafeBuffers in statics,
-// you either need to take a lock when publishing the SafeBuffer, or you
-// need to create a local, initialize the SafeBuffer, then assign to the
-// static variable (perhaps using Interlocked.CompareExchange). Of course,
-// assignments in a static class constructor are under a lock implicitly.
-
-using System.Runtime.CompilerServices;
-using Internal.Runtime.CompilerServices;
-using Microsoft.Win32.SafeHandles;
-
-namespace System.Runtime.InteropServices
-{
- public abstract unsafe class SafeBuffer : SafeHandleZeroOrMinusOneIsInvalid
- {
- // Steal UIntPtr.MaxValue as our uninitialized value.
- private static readonly UIntPtr Uninitialized = (UIntPtr.Size == 4) ?
- ((UIntPtr)uint.MaxValue) : ((UIntPtr)ulong.MaxValue);
-
- private UIntPtr _numBytes;
-
- protected SafeBuffer(bool ownsHandle) : base(ownsHandle)
- {
- _numBytes = Uninitialized;
- }
-
- /// <summary>
- /// Specifies the size of the region of memory, in bytes. Must be
- /// called before using the SafeBuffer.
- /// </summary>
- /// <param name="numBytes">Number of valid bytes in memory.</param>
- [CLSCompliant(false)]
- public void Initialize(ulong numBytes)
- {
- if (IntPtr.Size == 4 && numBytes > uint.MaxValue)
- throw new ArgumentOutOfRangeException(nameof(numBytes), SR.ArgumentOutOfRange_AddressSpace);
-
- if (numBytes >= (ulong)Uninitialized)
- throw new ArgumentOutOfRangeException(nameof(numBytes), SR.ArgumentOutOfRange_UIntPtrMax);
-
- _numBytes = (UIntPtr)numBytes;
- }
-
- /// <summary>
- /// Specifies the size of the region in memory, as the number of
- /// elements in an array. Must be called before using the SafeBuffer.
- /// </summary>
- [CLSCompliant(false)]
- public void Initialize(uint numElements, uint sizeOfEachElement)
- {
- Initialize((ulong)numElements * sizeOfEachElement);
- }
-
- /// <summary>
- /// Specifies the size of the region in memory, as the number of
- /// elements in an array. Must be called before using the SafeBuffer.
- /// </summary>
- [CLSCompliant(false)]
- public void Initialize<T>(uint numElements) where T : struct
- {
- Initialize(numElements, AlignedSizeOf<T>());
- }
-
- // Callers should ensure that they check whether the pointer ref param
- // is null when AcquirePointer returns. If it is not null, they must
- // call ReleasePointer. This method calls DangerousAddRef
- // & exposes the pointer. Unlike Read, it does not alter the "current
- // position" of the pointer. Here's how to use it:
- //
- // byte* pointer = null;
- // try {
- // safeBuffer.AcquirePointer(ref pointer);
- // // Use pointer here, with your own bounds checking
- // }
- // finally {
- // if (pointer != null)
- // safeBuffer.ReleasePointer();
- // }
- //
- // Note: If you cast this byte* to a T*, you have to worry about
- // whether your pointer is aligned. Additionally, you must take
- // responsibility for all bounds checking with this pointer.
- /// <summary>
- /// Obtain the pointer from a SafeBuffer for a block of code,
- /// with the express responsibility for bounds checking and calling
- /// ReleasePointer later to ensure the pointer can be freed later.
- /// This method either completes successfully or throws an exception
- /// and returns with pointer set to null.
- /// </summary>
- /// <param name="pointer">A byte*, passed by reference, to receive
- /// the pointer from within the SafeBuffer. You must set
- /// pointer to null before calling this method.</param>
- [CLSCompliant(false)]
- public void AcquirePointer(ref byte* pointer)
- {
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- pointer = null;
-
- bool junk = false;
- DangerousAddRef(ref junk);
- pointer = (byte*)handle;
- }
-
- public void ReleasePointer()
- {
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- DangerousRelease();
- }
-
- /// <summary>
- /// Read a value type from memory at the given offset. This is
- /// equivalent to: return *(T*)(bytePtr + byteOffset);
- /// </summary>
- /// <typeparam name="T">The value type to read</typeparam>
- /// <param name="byteOffset">Where to start reading from memory. You
- /// may have to consider alignment.</param>
- /// <returns>An instance of T read from memory.</returns>
- [CLSCompliant(false)]
- public T Read<T>(ulong byteOffset) where T : struct
- {
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- uint sizeofT = SizeOf<T>();
- byte* ptr = (byte*)handle + byteOffset;
- SpaceCheck(ptr, sizeofT);
-
- // return *(T*) (_ptr + byteOffset);
- T value = default;
- bool mustCallRelease = false;
- try
- {
- DangerousAddRef(ref mustCallRelease);
-
- fixed (byte* pStructure = &Unsafe.As<T, byte>(ref value))
- Buffer.Memmove(pStructure, ptr, sizeofT);
- }
- finally
- {
- if (mustCallRelease)
- DangerousRelease();
- }
- return value;
- }
-
- [CLSCompliant(false)]
- public void ReadArray<T>(ulong byteOffset, T[] array, int index, int count)
- where T : struct
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array), SR.ArgumentNull_Buffer);
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- uint sizeofT = SizeOf<T>();
- uint alignedSizeofT = AlignedSizeOf<T>();
- byte* ptr = (byte*)handle + byteOffset;
- SpaceCheck(ptr, checked((ulong)(alignedSizeofT * count)));
-
- bool mustCallRelease = false;
- try
- {
- DangerousAddRef(ref mustCallRelease);
-
- if (count > 0)
- {
- fixed (byte* pStructure = &Unsafe.As<T, byte>(ref array[index]))
- {
- for (int i = 0; i < count; i++)
- Buffer.Memmove(pStructure + sizeofT * i, ptr + alignedSizeofT * i, sizeofT);
- }
- }
- }
- finally
- {
- if (mustCallRelease)
- DangerousRelease();
- }
- }
-
- /// <summary>
- /// Write a value type to memory at the given offset. This is
- /// equivalent to: *(T*)(bytePtr + byteOffset) = value;
- /// </summary>
- /// <typeparam name="T">The type of the value type to write to memory.</typeparam>
- /// <param name="byteOffset">The location in memory to write to. You
- /// may have to consider alignment.</param>
- /// <param name="value">The value type to write to memory.</param>
- [CLSCompliant(false)]
- public void Write<T>(ulong byteOffset, T value) where T : struct
- {
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- uint sizeofT = SizeOf<T>();
- byte* ptr = (byte*)handle + byteOffset;
- SpaceCheck(ptr, sizeofT);
-
- // *((T*) (_ptr + byteOffset)) = value;
- bool mustCallRelease = false;
- try
- {
- DangerousAddRef(ref mustCallRelease);
-
- fixed (byte* pStructure = &Unsafe.As<T, byte>(ref value))
- Buffer.Memmove(ptr, pStructure, sizeofT);
- }
- finally
- {
- if (mustCallRelease)
- DangerousRelease();
- }
- }
-
- [CLSCompliant(false)]
- public void WriteArray<T>(ulong byteOffset, T[] array, int index, int count)
- where T : struct
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array), SR.ArgumentNull_Buffer);
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (array.Length - index < count)
- throw new ArgumentException(SR.Argument_InvalidOffLen);
-
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- uint sizeofT = SizeOf<T>();
- uint alignedSizeofT = AlignedSizeOf<T>();
- byte* ptr = (byte*)handle + byteOffset;
- SpaceCheck(ptr, checked((ulong)(alignedSizeofT * count)));
-
- bool mustCallRelease = false;
- try
- {
- DangerousAddRef(ref mustCallRelease);
-
- if (count > 0)
- {
- {
- fixed (byte* pStructure = &Unsafe.As<T, byte>(ref array[index]))
- {
- for (int i = 0; i < count; i++)
- Buffer.Memmove(ptr + alignedSizeofT * i, pStructure + sizeofT * i, sizeofT);
- }
- }
- }
- }
- finally
- {
- if (mustCallRelease)
- DangerousRelease();
- }
- }
-
- /// <summary>
- /// Returns the number of bytes in the memory region.
- /// </summary>
- [CLSCompliant(false)]
- public ulong ByteLength
- {
- get
- {
- if (_numBytes == Uninitialized)
- throw NotInitialized();
-
- return (ulong)_numBytes;
- }
- }
-
- /* No indexer. The perf would be misleadingly bad. People should use
- * AcquirePointer and ReleasePointer instead. */
-
- private void SpaceCheck(byte* ptr, ulong sizeInBytes)
- {
- if ((ulong)_numBytes < sizeInBytes)
- NotEnoughRoom();
- if ((ulong)(ptr - (byte*)handle) > ((ulong)_numBytes) - sizeInBytes)
- NotEnoughRoom();
- }
-
- private static void NotEnoughRoom()
- {
- throw new ArgumentException(SR.Arg_BufferTooSmall);
- }
-
- private static InvalidOperationException NotInitialized()
- {
- return new InvalidOperationException(SR.InvalidOperation_MustCallInitialize);
- }
-
- /// <summary>
- /// Returns the size that SafeBuffer (and hence, UnmanagedMemoryAccessor) reserves in the unmanaged buffer for each element of an array of T. This is not the same
- /// value that sizeof(T) returns! Since the primary use case is to parse memory mapped files, we cannot change this algorithm as this defines a de-facto serialization format.
- /// Throws if T contains GC references.
- /// </summary>
- internal static uint AlignedSizeOf<T>() where T : struct
- {
- uint size = SizeOf<T>();
- if (size == 1 || size == 2)
- {
- return size;
- }
-
- return (uint)((size + 3) & (~3));
- }
-
- /// <summary>
- /// Returns same value as sizeof(T) but throws if T contains GC references.
- /// </summary>
- internal static uint SizeOf<T>() where T : struct
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- throw new ArgumentException(SR.Argument_NeedStructWithNoRefs);
-
- return (uint)Unsafe.SizeOf<T>();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs
deleted file mode 100644
index 053a70f1566..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SafeHandle.cs
+++ /dev/null
@@ -1,253 +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 System.Diagnostics;
-using System.Runtime.ConstrainedExecution;
-using System.Threading;
-
-namespace System.Runtime.InteropServices
-{
- // This implementation does not employ critical execution regions and thus cannot
- // reliably guarantee handle release in the face of thread aborts.
-
- /// <summary>Represents a wrapper class for operating system handles.</summary>
- public abstract partial class SafeHandle : CriticalFinalizerObject, IDisposable
- {
- // IMPORTANT:
- // - Do not add or rearrange fields as the EE depends on this layout,
- // as well as on the values of the StateBits flags.
- // - The EE may also perform the same operations using equivalent native
- // code, so this managed code must not assume it is the only code
- // manipulating _state.
-
- /// <summary>Specifies the handle to be wrapped.</summary>
- protected IntPtr handle;
- /// <summary>Combined ref count and closed/disposed flags (so we can atomically modify them).</summary>
- private volatile int _state;
- /// <summary>Whether we can release this handle.</summary>
- private readonly bool _ownsHandle;
- /// <summary>Whether constructor completed.</summary>
- private volatile bool _fullyInitialized;
-
- /// <summary>Bitmasks for the <see cref="_state"/> field.</summary>
- /// <remarks>
- /// The state field ends up looking like this:
- ///
- /// 31 2 1 0
- /// +-----------------------------------------------------------+---+---+
- /// | Ref count | D | C |
- /// +-----------------------------------------------------------+---+---+
- ///
- /// Where D = 1 means a Dispose has been performed and C = 1 means the
- /// underlying handle has been (or will be shortly) released.
- /// </remarks>
- private static class StateBits
- {
- public const int Closed = 0b01;
- public const int Disposed = 0b10;
- public const int RefCount = unchecked(~0b11); // 2 bits reserved for closed/disposed; ref count gets 30 bits
- public const int RefCountOne = 1 << 2;
- }
-
- /// <summary>Creates a SafeHandle class.</summary>
- protected SafeHandle(IntPtr invalidHandleValue, bool ownsHandle)
- {
- handle = invalidHandleValue;
- _state = StateBits.RefCountOne; // Ref count 1 and not closed or disposed.
- _ownsHandle = ownsHandle;
-
- if (!ownsHandle)
- {
- GC.SuppressFinalize(this);
- }
-
- _fullyInitialized = true;
- }
-
-#if !CORERT // CoreRT doesn't correctly support CriticalFinalizerObject
- ~SafeHandle()
- {
- if (_fullyInitialized)
- {
- Dispose(disposing: false);
- }
- }
-#endif
-
- protected void SetHandle(IntPtr handle) => this.handle = handle;
-
- public IntPtr DangerousGetHandle() => handle;
-
- public bool IsClosed => (_state & StateBits.Closed) == StateBits.Closed;
-
- public abstract bool IsInvalid { get; }
-
- public void Close() => Dispose();
-
- public void Dispose()
- {
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- Debug.Assert(_fullyInitialized);
- InternalRelease(disposeOrFinalizeOperation: true);
- }
-
- public void SetHandleAsInvalid()
- {
- Debug.Assert(_fullyInitialized);
-
- // Attempt to set closed state (low order bit of the _state field).
- // Might have to attempt these repeatedly, if the operation suffers
- // interference from an AddRef or Release.
- int oldState, newState;
- do
- {
- oldState = _state;
- newState = oldState | StateBits.Closed;
- } while (Interlocked.CompareExchange(ref _state, newState, oldState) != oldState);
-
- GC.SuppressFinalize(this);
- }
-
- protected abstract bool ReleaseHandle();
-
- public void DangerousAddRef(ref bool success)
- {
- // To prevent handle recycling security attacks we must enforce the
- // following invariant: we cannot successfully AddRef a handle on which
- // we've committed to the process of releasing.
-
- // We ensure this by never AddRef'ing a handle that is marked closed and
- // never marking a handle as closed while the ref count is non-zero. For
- // this to be thread safe we must perform inspection/updates of the two
- // values as a single atomic operation. We achieve this by storing them both
- // in a single aligned int and modifying the entire state via interlocked
- // compare exchange operations.
-
- // Additionally we have to deal with the problem of the Dispose operation.
- // We must assume that this operation is directly exposed to untrusted
- // callers and that malicious callers will try and use what is basically a
- // Release call to decrement the ref count to zero and free the handle while
- // it's still in use (the other way a handle recycling attack can be
- // mounted). We combat this by allowing only one Dispose to operate against
- // a given safe handle (which balances the creation operation given that
- // Dispose suppresses finalization). We record the fact that a Dispose has
- // been requested in the same state field as the ref count and closed state.
-
- Debug.Assert(_fullyInitialized);
-
- // Might have to perform the following steps multiple times due to
- // interference from other AddRef's and Release's.
- int oldState, newState;
- do
- {
- // First step is to read the current handle state. We use this as a
- // basis to decide whether an AddRef is legal and, if so, to propose an
- // update predicated on the initial state (a conditional write).
- // Check for closed state.
- oldState = _state;
- if ((oldState & StateBits.Closed) != 0)
- {
- throw new ObjectDisposedException(nameof(SafeHandle), SR.ObjectDisposed_SafeHandleClosed);
- }
-
- // Not closed, let's propose an update (to the ref count, just add
- // StateBits.RefCountOne to the state to effectively add 1 to the ref count).
- // Continue doing this until the update succeeds (because nobody
- // modifies the state field between the read and write operations) or
- // the state moves to closed.
- newState = oldState + StateBits.RefCountOne;
- } while (Interlocked.CompareExchange(ref _state, newState, oldState) != oldState);
-
- // If we got here we managed to update the ref count while the state
- // remained non closed. So we're done.
- success = true;
- }
-
- public void DangerousRelease() => InternalRelease(disposeOrFinalizeOperation: false);
-
- private void InternalRelease(bool disposeOrFinalizeOperation)
- {
- Debug.Assert(_fullyInitialized || disposeOrFinalizeOperation);
-
- // See AddRef above for the design of the synchronization here. Basically we
- // will try to decrement the current ref count and, if that would take us to
- // zero refs, set the closed state on the handle as well.
- bool performRelease = false;
-
- // Might have to perform the following steps multiple times due to
- // interference from other AddRef's and Release's.
- int oldState, newState;
- do
- {
- // First step is to read the current handle state. We use this cached
- // value to predicate any modification we might decide to make to the
- // state).
- oldState = _state;
-
- // If this is a Dispose operation we have additional requirements (to
- // ensure that Dispose happens at most once as the comments in AddRef
- // detail). We must check that the dispose bit is not set in the old
- // state and, in the case of successful state update, leave the disposed
- // bit set. Silently do nothing if Dispose has already been called.
- if (disposeOrFinalizeOperation && ((oldState & StateBits.Disposed) != 0))
- {
- return;
- }
-
- // We should never see a ref count of zero (that would imply we have
- // unbalanced AddRef and Releases). (We might see a closed state before
- // hitting zero though -- that can happen if SetHandleAsInvalid is
- // used).
- if ((oldState & StateBits.RefCount) == 0)
- {
- throw new ObjectDisposedException(nameof(SafeHandle), SR.ObjectDisposed_SafeHandleClosed);
- }
-
- // If we're proposing a decrement to zero and the handle is not closed
- // and we own the handle then we need to release the handle upon a
- // successful state update. If so we need to check whether the handle is
- // currently invalid by asking the SafeHandle subclass. We must do this before
- // transitioning the handle to closed, however, since setting the closed
- // state will cause IsInvalid to always return true.
- performRelease = ((oldState & (StateBits.RefCount | StateBits.Closed)) == StateBits.RefCountOne) &&
- _ownsHandle &&
- !IsInvalid;
-
- // Attempt the update to the new state, fail and retry if the initial
- // state has been modified in the meantime. Decrement the ref count by
- // substracting StateBits.RefCountOne from the state then OR in the bits for
- // Dispose (if that's the reason for the Release) and closed (if the
- // initial ref count was 1).
- newState = oldState - StateBits.RefCountOne;
- if ((oldState & StateBits.RefCount) == StateBits.RefCountOne)
- {
- newState |= StateBits.Closed;
- }
- if (disposeOrFinalizeOperation)
- {
- newState |= StateBits.Disposed;
- }
- } while (Interlocked.CompareExchange(ref _state, newState, oldState) != oldState);
-
- // If we get here we successfully decremented the ref count. Additionally we
- // may have decremented it to zero and set the handle state as closed. In
- // this case (providng we own the handle) we will call the ReleaseHandle
- // method on the SafeHandle subclass.
- if (performRelease)
- {
- // Save last error from P/Invoke in case the implementation of ReleaseHandle
- // trashes it (important because this ReleaseHandle could occur implicitly
- // as part of unmarshaling another P/Invoke).
- int lastError = Marshal.GetLastWin32Error();
- ReleaseHandle();
- Marshal.SetLastWin32Error(lastError);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/StructLayoutAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/StructLayoutAttribute.cs
deleted file mode 100644
index c4cce9956e1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/StructLayoutAttribute.cs
+++ /dev/null
@@ -1,26 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
- public sealed class StructLayoutAttribute : Attribute
- {
- public StructLayoutAttribute(LayoutKind layoutKind)
- {
- Value = layoutKind;
- }
-
- public StructLayoutAttribute(short layoutKind)
- {
- Value = (LayoutKind)layoutKind;
- }
-
- public LayoutKind Value { get; }
-
- public int Pack;
- public int Size;
- public CharSet CharSet;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs
deleted file mode 100644
index 21f1695192c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs
+++ /dev/null
@@ -1,65 +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.
-
-namespace System.Runtime.InteropServices
-{
- /// <summary>
- /// An attribute used to indicate a GC transition should be skipped when making an unmanaged function call.
- /// </summary>
- /// <example>
- /// Example of a valid use case. The Win32 `GetTickCount()` function is a small performance related function
- /// that reads some global memory and returns the value. In this case, the GC transition overhead is significantly
- /// more than the memory read.
- /// <code>
- /// using System;
- /// using System.Runtime.InteropServices;
- /// class Program
- /// {
- /// [DllImport("Kernel32")]
- /// [SuppressGCTransition]
- /// static extern int GetTickCount();
- /// static void Main()
- /// {
- /// Console.WriteLine($"{GetTickCount()}");
- /// }
- /// }
- /// </code>
- /// </example>
- /// <remarks>
- /// This attribute is ignored if applied to a method without the <see cref="System.Runtime.InteropServices.DllImportAttribute"/>.
- ///
- /// Forgoing this transition can yield benefits when the cost of the transition is more than the execution time
- /// of the unmanaged function. However, avoiding this transition removes some of the guarantees the runtime
- /// provides through a normal P/Invoke. When exiting the managed runtime to enter an unmanaged function the
- /// GC must transition from Cooperative mode into Preemptive mode. Full details on these modes can be found at
- /// https://github.com/dotnet/coreclr/blob/master/Documentation/coding-guidelines/clr-code-guide.md#2.1.8.
- /// Suppressing the GC transition is an advanced scenario and should not be done without fully understanding
- /// potential consequences.
- ///
- /// One of these consequences is an impact to Mixed-mode debugging (https://docs.microsoft.com/visualstudio/debugger/how-to-debug-in-mixed-mode).
- /// During Mixed-mode debugging, it is not possible to step into or set breakpoints in a P/Invoke that
- /// has been marked with this attribute. A workaround is to switch to native debugging and set a breakpoint in the native function.
- /// In general, usage of this attribute is not recommended if debugging the P/Invoke is important, for example
- /// stepping through the native code or diagnosing an exception thrown from the native code.
- ///
- /// The P/Invoke method that this attribute is applied to must have all of the following properties:
- /// * Native function always executes for a trivial amount of time (less than 1 microsecond).
- /// * Native function does not perform a blocking syscall (e.g. any type of I/O).
- /// * Native function does not call back into the runtime (e.g. Reverse P/Invoke).
- /// * Native function does not throw exceptions.
- /// * Native function does not manipulate locks or other concurrency primitives.
- ///
- /// Consequences of invalid uses of this attribute:
- /// * GC starvation.
- /// * Immediate runtime termination.
- /// * Data corruption.
- /// </remarks>
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class SuppressGCTransitionAttribute : Attribute
- {
- public SuppressGCTransitionAttribute()
- {
- }
- }
-} \ No newline at end of file
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs
deleted file mode 100644
index 73069f36549..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/TypeIdentifierAttribute.cs
+++ /dev/null
@@ -1,20 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Struct | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
- public sealed class TypeIdentifierAttribute : Attribute
- {
- public TypeIdentifierAttribute() { }
- public TypeIdentifierAttribute(string? scope, string? identifier)
- {
- Scope = scope;
- Identifier = identifier;
- }
-
- public string? Scope { get; }
- public string? Identifier { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs
deleted file mode 100644
index 3581ca93a51..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnknownWrapper.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_UNKNOWN.
- public sealed class UnknownWrapper
- {
- public UnknownWrapper(object? obj)
- {
- WrappedObject = obj;
- }
-
- public object? WrappedObject { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs
deleted file mode 100644
index c4f96903ee2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedFunctionPointerAttribute.cs
+++ /dev/null
@@ -1,27 +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.
-
-namespace System.Runtime.InteropServices
-{
- [AttributeUsage(AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
- public sealed class UnmanagedFunctionPointerAttribute : Attribute
- {
- public UnmanagedFunctionPointerAttribute()
- {
- CallingConvention = CallingConvention.Winapi;
- }
-
- public UnmanagedFunctionPointerAttribute(CallingConvention callingConvention)
- {
- CallingConvention = callingConvention;
- }
-
- public CallingConvention CallingConvention { get; }
-
- public bool BestFitMapping;
- public bool SetLastError;
- public bool ThrowOnUnmappableChar;
- public CharSet CharSet;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedType.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedType.cs
deleted file mode 100644
index 4deca7fe0cf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/UnmanagedType.cs
+++ /dev/null
@@ -1,48 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum UnmanagedType
- {
- Bool = 0x2, // 4 byte boolean value (true != 0, false == 0)
- I1 = 0x3, // 1 byte signed value
- U1 = 0x4, // 1 byte unsigned value
- I2 = 0x5, // 2 byte signed value
- U2 = 0x6, // 2 byte unsigned value
- I4 = 0x7, // 4 byte signed value
- U4 = 0x8, // 4 byte unsigned value
- I8 = 0x9, // 8 byte signed value
- U8 = 0xa, // 8 byte unsigned value
- R4 = 0xb, // 4 byte floating point
- R8 = 0xc, // 8 byte floating point
- Currency = 0xf, // A currency
- BStr = 0x13, // OLE Unicode BSTR
- LPStr = 0x14, // Ptr to SBCS string
- LPWStr = 0x15, // Ptr to Unicode string
- LPTStr = 0x16, // Ptr to OS preferred (SBCS/Unicode) string
- ByValTStr = 0x17, // OS preferred (SBCS/Unicode) inline string (only valid in structs)
- IUnknown = 0x19, // COM IUnknown pointer.
- IDispatch = 0x1a, // COM IDispatch pointer
- Struct = 0x1b, // Structure
- Interface = 0x1c, // COM interface
- SafeArray = 0x1d, // OLE SafeArray
- ByValArray = 0x1e, // Array of fixed size (only valid in structs)
- SysInt = 0x1f, // Hardware natural sized signed integer
- SysUInt = 0x20,
- VBByRefStr = 0x22,
- AnsiBStr = 0x23, // OLE BSTR containing SBCS characters
- TBStr = 0x24, // Ptr to OS preferred (SBCS/Unicode) BSTR
- VariantBool = 0x25, // OLE defined BOOLEAN (2 bytes, true == -1, false == 0)
- FunctionPtr = 0x26, // Function pointer
- AsAny = 0x28, // Paired with Object type and does runtime marshalling determination
- LPArray = 0x2a, // C style array
- LPStruct = 0x2b, // Pointer to a structure
- CustomMarshaler = 0x2c,
- Error = 0x2d,
- IInspectable = 0x2e,
- HString = 0x2f, // Windows Runtime HSTRING
- LPUTF8Str = 0x30, // UTF8 string
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VarEnum.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VarEnum.cs
deleted file mode 100644
index 495aeca6d1f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VarEnum.cs
+++ /dev/null
@@ -1,54 +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.
-
-namespace System.Runtime.InteropServices
-{
- public enum VarEnum
- {
- VT_EMPTY = 0,
- VT_NULL = 1,
- VT_I2 = 2,
- VT_I4 = 3,
- VT_R4 = 4,
- VT_R8 = 5,
- VT_CY = 6,
- VT_DATE = 7,
- VT_BSTR = 8,
- VT_DISPATCH = 9,
- VT_ERROR = 10,
- VT_BOOL = 11,
- VT_VARIANT = 12,
- VT_UNKNOWN = 13,
- VT_DECIMAL = 14,
- VT_I1 = 16,
- VT_UI1 = 17,
- VT_UI2 = 18,
- VT_UI4 = 19,
- VT_I8 = 20,
- VT_UI8 = 21,
- VT_INT = 22,
- VT_UINT = 23,
- VT_VOID = 24,
- VT_HRESULT = 25,
- VT_PTR = 26,
- VT_SAFEARRAY = 27,
- VT_CARRAY = 28,
- VT_USERDEFINED = 29,
- VT_LPSTR = 30,
- VT_LPWSTR = 31,
- VT_RECORD = 36,
- VT_FILETIME = 64,
- VT_BLOB = 65,
- VT_STREAM = 66,
- VT_STORAGE = 67,
- VT_STREAMED_OBJECT = 68,
- VT_STORED_OBJECT = 69,
- VT_BLOB_OBJECT = 70,
- VT_CF = 71,
- VT_CLSID = 72,
- VT_VECTOR = 0x1000,
- VT_ARRAY = 0x2000,
- VT_BYREF = 0x4000
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs
deleted file mode 100644
index 74054d5dc9e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/VariantWrapper.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Runtime.InteropServices
-{
- // Wrapper that is converted to a variant with VT_BYREF | VT_VARIANT.
- public sealed class VariantWrapper
- {
- public VariantWrapper(object? obj)
- {
- WrappedObject = obj;
- }
-
- public object? WrappedObject { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationToken.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationToken.cs
deleted file mode 100644
index 15b4a8302e1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationToken.cs
+++ /dev/null
@@ -1,34 +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.
-
-namespace System.Runtime.InteropServices.WindowsRuntime
-{
- // Event registration tokens are 64 bit opaque structures returned from WinRT style event adders, in order
- // to signify a registration of a particular delegate to an event. The token's only real use is to
- // unregister the same delgate from the event at a later time.
- public struct EventRegistrationToken : IEquatable<EventRegistrationToken>
- {
- private readonly ulong _value;
-
- [CLSCompliant(false)]
- public EventRegistrationToken(ulong value) => _value = value;
-
- [CLSCompliant(false)]
- public ulong Value => _value;
-
- public static bool operator ==(EventRegistrationToken left, EventRegistrationToken right) =>
- left.Equals(right);
-
- public static bool operator !=(EventRegistrationToken left, EventRegistrationToken right) =>
- !left.Equals(right);
-
- public override bool Equals(object? obj) =>
- obj is EventRegistrationToken &&
- ((EventRegistrationToken)obj)._value == _value;
-
- public override int GetHashCode() => _value.GetHashCode();
-
- public bool Equals(EventRegistrationToken other) => other._value == _value;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/AdvSimd.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/AdvSimd.PlatformNotSupported.cs
deleted file mode 100644
index 8ab12cd8c70..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/AdvSimd.PlatformNotSupported.cs
+++ /dev/null
@@ -1,2172 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM AdvSIMD hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class AdvSimd : ArmBase
- {
- internal AdvSimd() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- public new abstract class Arm64 : ArmBase.Arm64
- {
- internal Arm64() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// float64x2_t vabsq_f64 (float64x2_t a)
- /// A64: FABS Vd.2D, Vn.2D
- /// </summary>
- public static Vector128<double> Abs(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vabsq_s64 (int64x2_t a)
- /// A64: ABS Vd.2D, Vn.2D
- /// </summary>
- public static Vector128<ulong> Abs(Vector128<long> value) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// int64x1_t vabs_s64 (int64x1_t a)
- // /// A64: ABS Dd, Dn
- // /// </summary>
- // public static Vector64<ulong> AbsScalar(Vector64<long> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vaddq_f64 (float64x2_t a, float64x2_t b)
- /// A64: FADD Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> Add(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8_t vaddv_u8(uint8x8_t a)
- /// A64: ADDV Bd, Vn.8B
- /// </summary>
- public static byte AddAcross(Vector64<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16_t vaddv_s16(int16x4_t a)
- /// A64: ADDV Hd, Vn.4H
- /// </summary>
- public static short AddAcross(Vector64<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8_t vaddv_s8(int8x8_t a)
- /// A64: ADDV Bd, Vn.8B
- /// </summary>
- public static sbyte AddAcross(Vector64<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16_t vaddv_u16(uint16x4_t a)
- /// A64: ADDV Hd, Vn.4H
- /// </summary>
- public static ushort AddAcross(Vector64<ushort> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8_t vaddvq_u8(uint8x16_t a)
- /// A64: ADDV Bd, Vn.16B
- /// </summary>
- public static byte AddAcross(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16_t vaddvq_s16(int16x8_t a)
- /// A64: ADDV Hd, Vn.8H
- /// </summary>
- public static short AddAcross(Vector128<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32_t vaddvq_s32(int32x4_t a)
- /// A64: ADDV Sd, Vn.4S
- /// </summary>
- public static int AddAcross(Vector128<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8_t vaddvq_s8(int8x16_t a)
- /// A64: ADDV Bd, Vn.16B
- /// </summary>
- public static sbyte AddAcross(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16_t vaddvq_u16(uint16x8_t a)
- /// A64: ADDV Hd, Vn.8H
- /// </summary>
- public static ushort AddAcross(Vector128<ushort> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32_t vaddvq_u32(uint32x4_t a)
- /// A64: ADDV Sd, Vn.4S
- /// </summary>
- public static uint AddAcross(Vector128<uint> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vsubq_f64 (float64x2_t a, float64x2_t b)
- /// A64: FSUB Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> Subtract(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vrbit_u8 (uint8x8_t a)
- /// A64: RBIT Vd.8B, Vn.8B
- /// </summary>
- public static Vector64<byte> ReverseElementBits(Vector64<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vrbit_s8 (int8x8_t a)
- /// A64: RBIT Vd.8B, Vn.8B
- /// </summary>
- public static Vector64<sbyte> ReverseElementBits(Vector64<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vrbitq_u8 (uint8x16_t a)
- /// A64: RBIT Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> ReverseElementBits(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vrbitq_s8 (int8x16_t a)
- /// A64: RBIT Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<sbyte> ReverseElementBits(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vuzp1_u8(uint8x8_t a, uint8x8_t b)
- /// A64: UZP1 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> UnzipEven(Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vuzp1_s16(int16x4_t a, int16x4_t b)
- /// A64: UZP1 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> UnzipEven(Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vuzp1_s32(int32x2_t a, int32x2_t b)
- /// A64: UZP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> UnzipEven(Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vuzp1_s8(int8x8_t a, int8x8_t b)
- /// A64: UZP1 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> UnzipEven(Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vuzp1_f32(float32x2_t a, float32x2_t b)
- /// A64: UZP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> UnzipEven(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vuzp1_u16(uint16x4_t a, uint16x4_t b)
- /// A64: UZP1 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> UnzipEven(Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vuzp1_u32(uint32x2_t a, uint32x2_t b)
- /// A64: UZP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> UnzipEven(Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vuzp1q_u8(uint8x16_t a, uint8x16_t b)
- /// A64: UZP1 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> UnzipEven(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vuzp1q_f64(float64x2_t a, float64x2_t b)
- /// A64: UZP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> UnzipEven(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vuzp1q_s16(int16x8_t a, int16x8_t b)
- /// A64: UZP1 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> UnzipEven(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vuzp1q_s32(int32x4_t a, int32x4_t b)
- /// A64: UZP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> UnzipEven(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vuzp1q_s64(int64x2_t a, int64x2_t b)
- /// A64: UZP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> UnzipEven(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vuzp1q_u8(int8x16_t a, int8x16_t b)
- /// A64: UZP1 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> UnzipEven(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vuzp1q_f32(float32x4_t a, float32x4_t b)
- /// A64: UZP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> UnzipEven(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vuzp1q_u16(uint16x8_t a, uint16x8_t b)
- /// A64: UZP1 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> UnzipEven(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vuzp1q_u32(uint32x4_t a, uint32x4_t b)
- /// A64: UZP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> UnzipEven(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vuzp1q_u64(uint64x2_t a, uint64x2_t b)
- /// A64: UZP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> UnzipEven(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vuzp2_u8(uint8x8_t a, uint8x8_t b)
- /// A64: UZP2 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> UnzipOdd(Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vuzp2_s16(int16x4_t a, int16x4_t b)
- /// A64: UZP2 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> UnzipOdd(Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vuzp2_s32(int32x2_t a, int32x2_t b)
- /// A64: UZP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> UnzipOdd(Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vuzp2_s8(int8x8_t a, int8x8_t b)
- /// A64: UZP2 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> UnzipOdd(Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vuzp2_f32(float32x2_t a, float32x2_t b)
- /// A64: UZP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> UnzipOdd(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vuzp2_u16(uint16x4_t a, uint16x4_t b)
- /// A64: UZP2 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> UnzipOdd(Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vuzp2_u32(uint32x2_t a, uint32x2_t b)
- /// A64: UZP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> UnzipOdd(Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vuzp2q_u8(uint8x16_t a, uint8x16_t b)
- /// A64: UZP2 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> UnzipOdd(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vuzp2q_f64(float64x2_t a, float64x2_t b)
- /// A64: UZP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> UnzipOdd(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vuzp2q_s16(int16x8_t a, int16x8_t b)
- /// A64: UZP2 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> UnzipOdd(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vuzp2q_s32(int32x4_t a, int32x4_t b)
- /// A64: UZP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> UnzipOdd(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vuzp2q_s64(int64x2_t a, int64x2_t b)
- /// A64: UZP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> UnzipOdd(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vuzp2q_u8(int8x16_t a, int8x16_t b)
- /// A64: UZP2 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> UnzipOdd(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vuzp2_f32(float32x4_t a, float32x4_t b)
- /// A64: UZP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> UnzipOdd(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vuzp2q_u16(uint16x8_t a, uint16x8_t b)
- /// A64: UZP2 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> UnzipOdd(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vuzp2q_u32(uint32x4_t a, uint32x4_t b)
- /// A64: UZP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> UnzipOdd(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vuzp2q_u64(uint64x2_t a, uint64x2_t b)
- /// A64: UZP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> UnzipOdd(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vzip2_u8(uint8x8_t a, uint8x8_t b)
- /// A64: ZIP2 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> ZipHigh(Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vzip2_s16(int16x4_t a, int16x4_t b)
- /// A64: ZIP2 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> ZipHigh(Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vzip2_s32(int32x2_t a, int32x2_t b)
- /// A64: ZIP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> ZipHigh(Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vzip2_s8(int8x8_t a, int8x8_t b)
- /// A64: ZIP2 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> ZipHigh(Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vzip2_f32(float32x2_t a, float32x2_t b)
- /// A64: ZIP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> ZipHigh(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vzip2_u16(uint16x4_t a, uint16x4_t b)
- /// A64: ZIP2 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> ZipHigh(Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vzip2_u32(uint32x2_t a, uint32x2_t b)
- /// A64: ZIP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> ZipHigh(Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vzip2q_u8(uint8x16_t a, uint8x16_t b)
- /// A64: ZIP2 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> ZipHigh(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vzip2q_f64(float64x2_t a, float64x2_t b)
- /// A64: ZIP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> ZipHigh(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vzip2q_s16(int16x8_t a, int16x8_t b)
- /// A64: ZIP2 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> ZipHigh(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vzip2q_s32(int32x4_t a, int32x4_t b)
- /// A64: ZIP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> ZipHigh(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vzip2q_s64(int64x2_t a, int64x2_t b)
- /// A64: ZIP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> ZipHigh(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vzip2q_u8(int8x16_t a, int8x16_t b)
- /// A64: ZIP2 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> ZipHigh(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vzip2q_f32(float32x4_t a, float32x4_t b)
- /// A64: ZIP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> ZipHigh(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vzip2q_u16(uint16x8_t a, uint16x8_t b)
- /// A64: ZIP2 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> ZipHigh(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vzip2q_u32(uint32x4_t a, uint32x4_t b)
- /// A64: ZIP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> ZipHigh(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vzip2q_u64(uint64x2_t a, uint64x2_t b)
- /// A64: ZIP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> ZipHigh(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vzip1_u8(uint8x8_t a, uint8x8_t b)
- /// A64: ZIP1 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> ZipLow(Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vzip1_s16(int16x4_t a, int16x4_t b)
- /// A64: ZIP1 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> ZipLow(Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vzip1_s32(int32x2_t a, int32x2_t b)
- /// A64: ZIP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> ZipLow(Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vzip1_s8(int8x8_t a, int8x8_t b)
- /// A64: ZIP1 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> ZipLow(Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vzip1_f32(float32x2_t a, float32x2_t b)
- /// A64: ZIP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> ZipLow(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vzip1_u16(uint16x4_t a, uint16x4_t b)
- /// A64: ZIP1 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> ZipLow(Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vzip1_u32(uint32x2_t a, uint32x2_t b)
- /// A64: ZIP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> ZipLow(Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vzip1q_u8(uint8x16_t a, uint8x16_t b)
- /// A64: ZIP1 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> ZipLow(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vzip1q_f64(float64x2_t a, float64x2_t b)
- /// A64: ZIP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> ZipLow(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vzip1q_s16(int16x8_t a, int16x8_t b)
- /// A64: ZIP1 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> ZipLow(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vzip1q_s32(int32x4_t a, int32x4_t b)
- /// A64: ZIP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> ZipLow(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vzip1q_s64(int64x2_t a, int64x2_t b)
- /// A64: ZIP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> ZipLow(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vzip1q_u8(int8x16_t a, int8x16_t b)
- /// A64: ZIP1 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> ZipLow(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vzip1q_f32(float32x4_t a, float32x4_t b)
- /// A64: ZIP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> ZipLow(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vzip1q_u16(uint16x8_t a, uint16x8_t b)
- /// A64: ZIP1 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> ZipLow(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vzip1q_u32(uint32x4_t a, uint32x4_t b)
- /// A64: ZIP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> ZipLow(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vzip1q_u64(uint64x2_t a, uint64x2_t b)
- /// A64: ZIP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> ZipLow(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
- }
-
- /// <summary>
- /// int8x8_t vabs_s8 (int8x8_t a)
- /// A32: VABS.S8 Dd, Dm
- /// A64: ABS Vd.8B, Vn.8B
- /// </summary>
- public static Vector64<byte> Abs(Vector64<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vabs_s16 (int16x4_t a)
- /// A32: VABS.S16 Dd, Dm
- /// A64: ABS Vd.4H, Vn.4H
- /// </summary>
- public static Vector64<ushort> Abs(Vector64<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vabs_s32 (int32x2_t a)
- /// A32: VABS.S32 Dd, Dm
- /// A64: ABS Vd.2S, Vn.2S
- /// </summary>
- public static Vector64<uint> Abs(Vector64<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vabs_f32 (float32x2_t a)
- /// A32: VABS.F32 Dd, Dm
- /// A64: FABS Vd.2S, Vn.2S
- /// </summary>
- public static Vector64<float> Abs(Vector64<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vabsq_s8 (int8x16_t a)
- /// A32: VABS.S8 Qd, Qm
- /// A64: ABS Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> Abs(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vabsq_s16 (int16x8_t a)
- /// A32: VABS.S16 Qd, Qm
- /// A64: ABS Vd.8H, Vn.8H
- /// </summary>
- public static Vector128<ushort> Abs(Vector128<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vabsq_s32 (int32x4_t a)
- /// A32: VABS.S32 Qd, Qm
- /// A64: ABS Vd.4S, Vn.4S
- /// </summary>
- public static Vector128<uint> Abs(Vector128<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vabsq_f32 (float32x4_t a)
- /// A32: VABS.F32 Qd, Qm
- /// A64: FABS Vd.4S, Vn.4S
- /// </summary>
- public static Vector128<float> Abs(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// float64x1_t vabs_f64 (float64x1_t a)
- // /// A32: VABS.F64 Dd, Dm
- // /// A64: FABS Dd, Dn
- // /// </summary>
- // public static Vector64<double> AbsScalar(Vector64<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// A32: VABS.F32 Sd, Sm
- /// A64: FABS Sd, Sn
- /// </summary>
- public static Vector64<float> AbsScalar(Vector64<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vadd_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VADD.I8 Dd, Dn, Dm
- /// A64: ADD Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> Add(Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vadd_s16 (int16x4_t a, int16x4_t b)
- /// A32: VADD.I16 Dd, Dn, Dm
- /// A64: ADD Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> Add(Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vadd_s32 (int32x2_t a, int32x2_t b)
- /// A32: VADD.I32 Dd, Dn, Dm
- /// A64: ADD Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> Add(Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vadd_s8 (int8x8_t a, int8x8_t b)
- /// A32: VADD.I8 Dd, Dn, Dm
- /// A64: ADD Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> Add(Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vadd_f32 (float32x2_t a, float32x2_t b)
- /// A32: VADD.F32 Dd, Dn, Dm
- /// A64: FADD Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> Add(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vadd_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VADD.I16 Dd, Dn, Dm
- /// A64: ADD Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> Add(Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vadd_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VADD.I32 Dd, Dn, Dm
- /// A64: ADD Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> Add(Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vaddq_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VADD.I8 Qd, Qn, Qm
- /// A64: ADD Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> Add(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vaddq_s16 (int16x8_t a, int16x8_t b)
- /// A32: VADD.I16 Qd, Qn, Qm
- /// A64: ADD Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> Add(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vaddq_s32 (int32x4_t a, int32x4_t b)
- /// A32: VADD.I32 Qd, Qn, Qm
- /// A64: ADD Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> Add(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vaddq_s64 (int64x2_t a, int64x2_t b)
- /// A32: VADD.I64 Qd, Qn, Qm
- /// A64: ADD Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> Add(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vaddq_s8 (int8x16_t a, int8x16_t b)
- /// A32: VADD.I8 Qd, Qn, Qm
- /// A64: ADD Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> Add(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vaddq_f32 (float32x4_t a, float32x4_t b)
- /// A32: VADD.F32 Qd, Qn, Qm
- /// A64: FADD Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> Add(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vaddq_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VADD.I16 Qd, Qn, Qm
- /// A64: ADD Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> Add(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vaddq_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VADD.I32 Qd, Qn, Qm
- /// A64: ADD Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> Add(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vaddq_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VADD.I64 Qd, Qn, Qm
- /// A64: ADD Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> Add(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// float64x1_t vadd_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VADD.F64 Dd, Dn, Dm
- // /// A64: FADD Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<double> AddScalar(Vector64<double> left, Vector64<double> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// int64x1_t vadd_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VADD.I64 Dd, Dn, Dm
- // /// A64: ADD Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<long> AddScalar(Vector64<long> left, Vector64<long> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// uint64x1_t vadd_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VADD.I64 Dd, Dn, Dm
- // /// A64: ADD Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<ulong> AddScalar(Vector64<ulong> left, Vector64<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// A32: VADD.F32 Sd, Sn, Sm
- /// A64:
- /// </summary>
- public static Vector64<float> AddScalar(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vand_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> And(Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// float64x1_t vand_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VAND Dd, Dn, Dm
- // /// A64: AND Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> And(Vector64<double> left, Vector64<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vand_s16 (int16x4_t a, int16x4_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> And(Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vand_s32(int32x2_t a, int32x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> And(Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// int64x1_t vand_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VAND Dd, Dn, Dm
- // /// A64: AND Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> And(Vector64<long> left, Vector64<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vand_s8 (int8x8_t a, int8x8_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> And(Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vand_f32 (float32x2_t a, float32x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> And(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vand_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> And(Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vand_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> And(Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// uint64x1_t vand_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VAND Dd, Dn, Dm
- // /// A64: AND Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> And(Vector64<ulong> left, Vector64<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vand_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> And(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vand_f64 (float64x2_t a, float64x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> And(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vand_s16 (int16x8_t a, int16x8_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> And(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vand_s32(int32x4_t a, int32x4_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> And(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vand_s64 (int64x2_t a, int64x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> And(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vand_s8 (int8x16_t a, int8x16_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> And(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vand_f32 (float32x4_t a, float32x4_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> And(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vand_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> And(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vand_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> And(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vand_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> And(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vbic_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> AndNot(Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// float64x1_t vbic_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VBIC Dd, Dn, Dm
- // /// A64: BIC Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> AndNot(Vector64<double> left, Vector64<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vbic_s16 (int16x4_t a, int16x4_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> AndNot(Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vbic_s32(int32x2_t a, int32x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> AndNot(Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// int64x1_t vbic_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VBIC Dd, Dn, Dm
- // /// A64: BIC Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> AndNot(Vector64<long> left, Vector64<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vbic_s8 (int8x8_t a, int8x8_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> AndNot(Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vbic_f32 (float32x2_t a, float32x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> AndNot(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vbic_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> AndNot(Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vbic_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> AndNot(Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// uint64x1_t vbic_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VBIC Dd, Dn, Dm
- // /// A64: BIC Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> AndNot(Vector64<ulong> left, Vector64<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vbic_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> AndNot(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vbic_f64 (float64x2_t a, float64x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> AndNot(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vbic_s16 (int16x8_t a, int16x8_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> AndNot(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vbic_s32(int32x4_t a, int32x4_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> AndNot(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vbic_s64 (int64x2_t a, int64x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> AndNot(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vbic_s8 (int8x16_t a, int8x16_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> AndNot(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vbic_f32 (float32x4_t a, float32x4_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> AndNot(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vbic_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> AndNot(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vbic_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> AndNot(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vbic_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> AndNot(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vbsl_u8 (uint8x8_t a, uint8x8_t b, uint8x8_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> BitwiseSelect(Vector64<byte> select, Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// float64x1_t vbsl_f64 (float64x1_t a, float64x1_t b, float64x1_t c)
- // /// A32: VBSL Dd, Dn, Dm
- // /// A64: BSL Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<double> BitwiseSelect(Vector64<double> select, Vector64<double> left, Vector64<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vbsl_s16 (int16x4_t a, int16x4_t b, int16x4_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> BitwiseSelect(Vector64<short> select, Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vbsl_s32 (int32x2_t a, int32x2_t b, int32x2_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> BitwiseSelect(Vector64<int> select, Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// int64x1_t vbsl_s64 (int64x1_t a, int64x1_t b, int64x1_t c)
- // /// A32: VBSL Dd, Dn, Dm
- // /// A64: BSL Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> BitwiseSelect(Vector64<long> select, Vector64<long> left, Vector64<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vbsl_s8 (int8x8_t a, int8x8_t b, int8x8_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> BitwiseSelect(Vector64<sbyte> select, Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vbsl_f32 (float32x2_t a, float32x2_t b, float32x2_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<float> BitwiseSelect(Vector64<float> select, Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vbsl_u16 (uint16x4_t a, uint16x4_t b, uint16x4_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> BitwiseSelect(Vector64<ushort> select, Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vbsl_u32 (uint32x2_t a, uint32x2_t b, uint32x2_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> BitwiseSelect(Vector64<uint> select, Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// uint64x1_t vbsl_u64 (uint64x1_t a, uint64x1_t b, uint64x1_t c)
- // /// A32: VBSL Dd, Dn, Dm
- // /// A64: BSL Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> BitwiseSelect(Vector64<ulong> select, Vector64<ulong> left, Vector64<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vbslq_u8 (uint8x16_t a, uint8x16_t b, uint8x16_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> BitwiseSelect(Vector128<byte> select, Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vbslq_f64 (float64x2_t a, float64x2_t b, float64x2_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<double> BitwiseSelect(Vector128<double> select, Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vbslq_s16 (int16x8_t a, int16x8_t b, int16x8_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> BitwiseSelect(Vector128<short> select, Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vbslq_s32 (int32x4_t a, int32x4_t b, int32x4_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> BitwiseSelect(Vector128<int> select, Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vbslq_s64 (int64x2_t a, int64x2_t b, int64x2_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> BitwiseSelect(Vector128<long> select, Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vbslq_s8 (int8x16_t a, int8x16_t b, int8x16_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> BitwiseSelect(Vector128<sbyte> select, Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vbslq_f32 (float32x4_t a, float32x4_t b, float32x4_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<float> BitwiseSelect(Vector128<float> select, Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vbslq_u16 (uint16x8_t a, uint16x8_t b, uint16x8_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> BitwiseSelect(Vector128<ushort> select, Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vbslq_u32 (uint32x4_t a, uint32x4_t b, uint32x4_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> BitwiseSelect(Vector128<uint> select, Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vbslq_u64 (uint64x2_t a, uint64x2_t b, uint64x2_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> BitwiseSelect(Vector128<ulong> select, Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vcls_s8 (int8x8_t a)
- /// A32: VCLS Dd, Dm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector64<sbyte> LeadingSignCount(Vector64<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vcls_s16 (int16x4_t a)
- /// A32: VCLS Dd, Dm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector64<short> LeadingSignCount(Vector64<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vcls_s32 (int32x2_t a)
- /// A32: VCLS Dd, Dm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector64<int> LeadingSignCount(Vector64<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vclsq_s8 (int8x16_t a)
- /// A32: VCLS Qd, Qm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector128<sbyte> LeadingSignCount(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vclsq_s16 (int16x8_t a)
- /// A32: VCLS Qd, Qm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector128<short> LeadingSignCount(Vector128<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vclsq_s32 (int32x4_t a)
- /// A32: VCLS Qd, Qm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector128<int> LeadingSignCount(Vector128<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vclz_s8 (int8x8_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<sbyte> LeadingZeroCount(Vector64<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vclz_u8 (uint8x8_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<byte> LeadingZeroCount(Vector64<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vclz_s16 (int16x4_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<short> LeadingZeroCount(Vector64<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vclz_u16 (uint16x4_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<ushort> LeadingZeroCount(Vector64<ushort> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vclz_s32 (int32x2_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<int> LeadingZeroCount(Vector64<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vclz_u32 (uint32x2_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<uint> LeadingZeroCount(Vector64<uint> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vclzq_s8 (int8x16_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<sbyte> LeadingZeroCount(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vclzq_u8 (uint8x16_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<byte> LeadingZeroCount(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vclzq_s16 (int16x8_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<short> LeadingZeroCount(Vector128<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vclzq_u16 (uint16x8_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<ushort> LeadingZeroCount(Vector128<ushort> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vclzq_s32 (int32x4_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<int> LeadingZeroCount(Vector128<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vclzq_u32 (uint32x4_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<uint> LeadingZeroCount(Vector128<uint> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vld1_u8 (uint8_t const * ptr)
- /// A32: VLD1.8 Dd, [Rn]
- /// A64: LD1 Vt.8B, [Xn]
- /// </summary>
- public static unsafe Vector64<byte> LoadVector64(byte* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vld1_s16 (int16_t const * ptr)
- /// A32: VLD1.16 Dd, [Rn]
- /// A64: LD1 Vt.4H, [Xn]
- /// </summary>
- public static unsafe Vector64<short> LoadVector64(short* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vld1_s32 (int32_t const * ptr)
- /// A32: VLD1.32 Dd, [Rn]
- /// A64: LD1 Vt.2S, [Xn]
- /// </summary>
- public static unsafe Vector64<int> LoadVector64(int* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vld1_s8 (int8_t const * ptr)
- /// A32: VLD1.8 Dd, [Rn]
- /// A64: LD1 Vt.8B, [Xn]
- /// </summary>
- public static unsafe Vector64<sbyte> LoadVector64(sbyte* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vld1_f32 (float32_t const * ptr)
- /// A32: VLD1.32 Dd, [Rn]
- /// A64: LD1 Vt.2S, [Xn]
- /// </summary>
- public static unsafe Vector64<float> LoadVector64(float* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vld1_u16 (uint16_t const * ptr)
- /// A32: VLD1.16 Dd, [Rn]
- /// A64: LD1 Vt.4H, [Xn]
- /// </summary>
- public static unsafe Vector64<ushort> LoadVector64(ushort* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vld1_u32 (uint32_t const * ptr)
- /// A32: VLD1.32 Dd, [Rn]
- /// A64: LD1 Vt.2S, [Xn]
- /// </summary>
- public static unsafe Vector64<uint> LoadVector64(uint* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vld1q_u8 (uint8_t const * ptr)
- /// A32: VLD1.8 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.16B, [Xn]
- /// </summary>
- public static unsafe Vector128<byte> LoadVector128(byte* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vld1q_f64 (float64_t const * ptr)
- /// A32: VLD1.64 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.2D, [Xn]
- /// </summary>
- public static unsafe Vector128<double> LoadVector128(double* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vld1q_s16 (int16_t const * ptr)
- /// A32: VLD1.16 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.8H, [Xn]
- /// </summary>
- public static unsafe Vector128<short> LoadVector128(short* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vld1q_s32 (int32_t const * ptr)
- /// A32: VLD1.32 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.4S, [Xn]
- /// </summary>
- public static unsafe Vector128<int> LoadVector128(int* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vld1q_s64 (int64_t const * ptr)
- /// A32: VLD1.64 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.2D, [Xn]
- /// </summary>
- public static unsafe Vector128<long> LoadVector128(long* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vld1q_s8 (int8_t const * ptr)
- /// A32: VLD1.8 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.16B, [Xn]
- /// </summary>
- public static unsafe Vector128<sbyte> LoadVector128(sbyte* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vld1q_f32 (float32_t const * ptr)
- /// A32: VLD1.32 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.4S, [Xn]
- /// </summary>
- public static unsafe Vector128<float> LoadVector128(float* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vld1q_s16 (uint16_t const * ptr)
- /// A32: VLD1.16 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.8H, [Xn]
- /// </summary>
- public static unsafe Vector128<ushort> LoadVector128(ushort* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vld1q_s32 (uint32_t const * ptr)
- /// A32: VLD1.32 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.4S, [Xn]
- /// </summary>
- public static unsafe Vector128<uint> LoadVector128(uint* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vld1q_u64 (uint64_t const * ptr)
- /// A32: VLD1.64 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.2D, [Xn]
- /// </summary>
- public static unsafe Vector128<ulong> LoadVector128(ulong* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vmvn_u8 (uint8x8_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> Not(Vector64<byte> value) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// float64x1_t vmvn_f64 (float64x1_t a)
- // /// A32: VMVN Dd, Dn, Dm
- // /// A64: MVN Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> Not(Vector64<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vmvn_s16 (int16x4_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> Not(Vector64<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vmvn_s32(int32x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> Not(Vector64<int> value) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// int64x1_t vmvn_s64 (int64x1_t a)
- // /// A32: VMVN Dd, Dn, Dm
- // /// A64: MVN Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> Not(Vector64<long> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vmvn_s8 (int8x8_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> Not(Vector64<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vmvn_f32 (float32x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> Not(Vector64<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vmvn_u16 (uint16x4_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> Not(Vector64<ushort> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vmvn_u32 (uint32x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> Not(Vector64<uint> value) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// uint64x1_t vmvn_u64 (uint64x1_t a)
- // /// A32: VMVN Dd, Dn, Dm
- // /// A64: MVN Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> Not(Vector64<ulong> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vmvn_u8 (uint8x16_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> Not(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vmvn_f64 (float64x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> Not(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vmvn_s16 (int16x8_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> Not(Vector128<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vmvn_s32(int32x4_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> Not(Vector128<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vmvn_s64 (int64x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> Not(Vector128<long> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vmvn_s8 (int8x16_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> Not(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vmvn_f32 (float32x4_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> Not(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vmvn_u16 (uint16x8_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> Not(Vector128<ushort> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vmvn_u32 (uint32x4_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> Not(Vector128<uint> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vmvn_u64 (uint64x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> Not(Vector128<ulong> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vorr_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> Or(Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// float64x1_t vorr_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VORR Dd, Dn, Dm
- // /// A64: ORR Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> Or(Vector64<double> left, Vector64<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vorr_s16 (int16x4_t a, int16x4_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> Or(Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vorr_s32(int32x2_t a, int32x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> Or(Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// int64x1_t vorr_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VORR Dd, Dn, Dm
- // /// A64: ORR Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> Or(Vector64<long> left, Vector64<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vorr_s8 (int8x8_t a, int8x8_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> Or(Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vorr_f32 (float32x2_t a, float32x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> Or(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vorr_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> Or(Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vorr_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> Or(Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// uint64x1_t vorr_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VORR Dd, Dn, Dm
- // /// A64: ORR Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> Or(Vector64<ulong> left, Vector64<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vorr_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> Or(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vorr_f64 (float64x2_t a, float64x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> Or(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vorr_s16 (int16x8_t a, int16x8_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> Or(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vorr_s32(int32x4_t a, int32x4_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> Or(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vorr_s64 (int64x2_t a, int64x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> Or(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vorr_s8 (int8x16_t a, int8x16_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> Or(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vorr_f32 (float32x4_t a, float32x4_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> Or(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vorr_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> Or(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vorr_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> Or(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vorr_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> Or(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vorn_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> OrNot(Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// float64x1_t vorn_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VORN Dd, Dn, Dm
- // /// A64: ORN Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> OrNot(Vector64<double> left, Vector64<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vorn_s16 (int16x4_t a, int16x4_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> OrNot(Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vorn_s32(int32x2_t a, int32x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> OrNot(Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// int64x1_t vorn_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VORN Dd, Dn, Dm
- // /// A64: ORN Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> OrNot(Vector64<long> left, Vector64<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vorn_s8 (int8x8_t a, int8x8_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> OrNot(Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vorn_f32 (float32x2_t a, float32x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> OrNot(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vorn_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> OrNot(Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vorn_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> OrNot(Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// uint64x1_t vorn_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VORN Dd, Dn, Dm
- // /// A64: ORN Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> OrNot(Vector64<ulong> left, Vector64<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vorn_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> OrNot(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t vorn_f64 (float64x2_t a, float64x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> OrNot(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vorn_s16 (int16x8_t a, int16x8_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> OrNot(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vorn_s32(int32x4_t a, int32x4_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> OrNot(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vorn_s64 (int64x2_t a, int64x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> OrNot(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vorn_s8 (int8x16_t a, int8x16_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> OrNot(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vorn_f32 (float32x4_t a, float32x4_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> OrNot(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vorn_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> OrNot(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vorn_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> OrNot(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vorn_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> OrNot(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vcnt_s8 (int8x8_t a)
- /// A32: VCNT Dd, Dm
- /// A64: CNT Vd, Vn
- /// </summary>
- public static Vector64<sbyte> PopCount(Vector64<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vcnt_u8 (uint8x8_t a)
- /// A32: VCNT Dd, Dm
- /// A64: CNT Vd, Vn
- /// </summary>
- public static Vector64<byte> PopCount(Vector64<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vcntq_s8 (int8x16_t a)
- /// A32: VCNT Qd, Qm
- /// A64: CNT Vd, Vn
- /// </summary>
- public static Vector128<sbyte> PopCount(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vcntq_u8 (uint8x16_t a)
- /// A32: VCNT Qd, Qm
- /// A64: CNT Vd, Vn
- /// </summary>
- public static Vector128<byte> PopCount(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t vsub_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VSUB.I8 Dd, Dn, Dm
- /// A64: SUB Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> Subtract(Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t vsub_s16 (int16x4_t a, int16x4_t b)
- /// A32: VSUB.I16 Dd, Dn, Dm
- /// A64: SUB Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> Subtract(Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t vsub_s32 (int32x2_t a, int32x2_t b)
- /// A32: VSUB.I32 Dd, Dn, Dm
- /// A64: SUB Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> Subtract(Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t vsub_s8 (int8x8_t a, int8x8_t b)
- /// A32: VSUB.I8 Dd, Dn, Dm
- /// A64: SUB Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> Subtract(Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t vsub_f32 (float32x2_t a, float32x2_t b)
- /// A32: VSUB.F32 Dd, Dn, Dm
- /// A64: FADD Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> Subtract(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t vsub_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VSUB.I16 Dd, Dn, Dm
- /// A64: SUB Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> Subtract(Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t vsub_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VSUB.I32 Dd, Dn, Dm
- /// A64: SUB Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> Subtract(Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vsubq_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VSUB.I8 Qd, Qn, Qm
- /// A64: SUB Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> Subtract(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t vsubq_s16 (int16x8_t a, int16x8_t b)
- /// A32: VSUB.I16 Qd, Qn, Qm
- /// A64: SUB Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> Subtract(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t vsubq_s32 (int32x4_t a, int32x4_t b)
- /// A32: VSUB.I32 Qd, Qn, Qm
- /// A64: SUB Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> Subtract(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t vsubq_s64 (int64x2_t a, int64x2_t b)
- /// A32: VSUB.I64 Qd, Qn, Qm
- /// A64: SUB Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> Subtract(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t vsubq_s8 (int8x16_t a, int8x16_t b)
- /// A32: VSUB.I8 Qd, Qn, Qm
- /// A64: SUB Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> Subtract(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t vsubq_f32 (float32x4_t a, float32x4_t b)
- /// A32: VSUB.F32 Qd, Qn, Qm
- /// A64: FADD Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> Subtract(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t vsubq_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VSUB.I16 Qd, Qn, Qm
- /// A64: SUB Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> Subtract(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vsubq_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VSUB.I32 Qd, Qn, Qm
- /// A64: SUB Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> Subtract(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t vsubq_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VSUB.I64 Qd, Qn, Qm
- /// A64: SUB Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> Subtract(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// float64x1_t vsub_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VSUB.F64 Dd, Dn, Dm
- // /// A64: FADD Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<double> SubtractScalar(Vector64<double> left, Vector64<double> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// int64x1_t vsub_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VSUB.I64 Dd, Dn, Dm
- // /// A64: SUB Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<long> SubtractScalar(Vector64<long> left, Vector64<long> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// uint64x1_t vsub_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VSUB.I64 Dd, Dn, Dm
- // /// A64: SUB Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<ulong> SubtractScalar(Vector64<ulong> left, Vector64<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// A32: VSUB.F32 Sd, Sn, Sm
- /// A64:
- /// </summary>
- public static Vector64<float> SubtractScalar(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x8_t veor_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> Xor(Vector64<byte> left, Vector64<byte> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// float64x1_t veor_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VEOR Dd, Dn, Dm
- // /// A64: EOR Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> Xor(Vector64<double> left, Vector64<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x4_t veor_s16 (int16x4_t a, int16x4_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> Xor(Vector64<short> left, Vector64<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x2_t veor_s32(int32x2_t a, int32x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> Xor(Vector64<int> left, Vector64<int> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// int64x1_t veor_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VEOR Dd, Dn, Dm
- // /// A64: EOR Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> Xor(Vector64<long> left, Vector64<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x8_t veor_s8 (int8x8_t a, int8x8_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> Xor(Vector64<sbyte> left, Vector64<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x2_t veor_f32 (float32x2_t a, float32x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> Xor(Vector64<float> left, Vector64<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x4_t veor_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> Xor(Vector64<ushort> left, Vector64<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x2_t veor_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> Xor(Vector64<uint> left, Vector64<uint> right) { throw new PlatformNotSupportedException(); }
-
- // /// <summary>
- // /// uint64x1_t veor_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VEOR Dd, Dn, Dm
- // /// A64: EOR Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> Xor(Vector64<ulong> left, Vector64<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t veor_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> Xor(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float64x2_t veor_f64 (float64x2_t a, float64x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> Xor(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int16x8_t veor_s16 (int16x8_t a, int16x8_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> Xor(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int32x4_t veor_s32(int32x4_t a, int32x4_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> Xor(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int64x2_t veor_s64 (int64x2_t a, int64x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> Xor(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int8x16_t veor_s8 (int8x16_t a, int8x16_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> Xor(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// float32x4_t veor_f32 (float32x4_t a, float32x4_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> Xor(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint16x8_t veor_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> Xor(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t veor_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> Xor(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint64x2_t veor_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> Xor(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/AdvSimd.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/AdvSimd.cs
deleted file mode 100644
index 4907e7b8f7f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/AdvSimd.cs
+++ /dev/null
@@ -1,2174 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM AdvSIMD hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class AdvSimd : ArmBase
- {
- internal AdvSimd() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- [Intrinsic]
- public new abstract class Arm64 : ArmBase.Arm64
- {
- internal Arm64() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// float64x2_t vabsq_f64 (float64x2_t a)
- /// A64: FABS Vd.2D, Vn.2D
- /// </summary>
- public static Vector128<double> Abs(Vector128<double> value) => Abs(value);
-
- /// <summary>
- /// int64x2_t vabsq_s64 (int64x2_t a)
- /// A64: ABS Vd.2D, Vn.2D
- /// </summary>
- public static Vector128<ulong> Abs(Vector128<long> value) => Abs(value);
-
- // /// <summary>
- // /// int64x1_t vabs_s64 (int64x1_t a)
- // /// A64: ABS Dd, Dn
- // /// </summary>
- // public static Vector64<ulong> AbsScalar(Vector64<long> value) => AbsScalar(value);
-
- /// <summary>
- /// float64x2_t vaddq_f64 (float64x2_t a, float64x2_t b)
- /// A64: FADD Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> Add(Vector128<double> left, Vector128<double> right) => Add(left, right);
-
- /// <summary>
- /// uint8_t vaddv_u8(uint8x8_t a)
- /// A64: ADDV Bd, Vn.8B
- /// </summary>
- public static byte AddAcross(Vector64<byte> value) => AddAcross(value);
-
- /// <summary>
- /// int16_t vaddv_s16(int16x4_t a)
- /// A64: ADDV Hd, Vn.4H
- /// </summary>
- public static short AddAcross(Vector64<short> value) => AddAcross(value);
-
- /// <summary>
- /// int8_t vaddv_s8(int8x8_t a)
- /// A64: ADDV Bd, Vn.8B
- /// </summary>
- public static sbyte AddAcross(Vector64<sbyte> value) => AddAcross(value);
-
- /// <summary>
- /// uint16_t vaddv_u16(uint16x4_t a)
- /// A64: ADDV Hd, Vn.4H
- /// </summary>
- public static ushort AddAcross(Vector64<ushort> value) => AddAcross(value);
-
- /// <summary>
- /// uint8_t vaddvq_u8(uint8x16_t a)
- /// A64: ADDV Bd, Vn.16B
- /// </summary>
- public static byte AddAcross(Vector128<byte> value) => AddAcross(value);
-
- /// <summary>
- /// int16_t vaddvq_s16(int16x8_t a)
- /// A64: ADDV Hd, Vn.8H
- /// </summary>
- public static short AddAcross(Vector128<short> value) => AddAcross(value);
-
- /// <summary>
- /// int32_t vaddvq_s32(int32x4_t a)
- /// A64: ADDV Sd, Vn.4S
- /// </summary>
- public static int AddAcross(Vector128<int> value) => AddAcross(value);
-
- /// <summary>
- /// int8_t vaddvq_s8(int8x16_t a)
- /// A64: ADDV Bd, Vn.16B
- /// </summary>
- public static sbyte AddAcross(Vector128<sbyte> value) => AddAcross(value);
-
- /// <summary>
- /// uint16_t vaddvq_u16(uint16x8_t a)
- /// A64: ADDV Hd, Vn.8H
- /// </summary>
- public static ushort AddAcross(Vector128<ushort> value) => AddAcross(value);
-
- /// <summary>
- /// uint32_t vaddvq_u32(uint32x4_t a)
- /// A64: ADDV Sd, Vn.4S
- /// </summary>
- public static uint AddAcross(Vector128<uint> value) => AddAcross(value);
-
- /// <summary>
- /// float64x2_t vsubq_f64 (float64x2_t a, float64x2_t b)
- /// A64: FSUB Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> Subtract(Vector128<double> left, Vector128<double> right) => Add(left, right);
-
- /// <summary>
- /// uint8x8_t vrbit_u8 (uint8x8_t a)
- /// A64: RBIT Vd.8B, Vn.8B
- /// </summary>
- public static Vector64<byte> ReverseElementBits(Vector64<byte> value) => ReverseElementBits(value);
-
- /// <summary>
- /// int8x8_t vrbit_s8 (int8x8_t a)
- /// A64: RBIT Vd.8B, Vn.8B
- /// </summary>
- public static Vector64<sbyte> ReverseElementBits(Vector64<sbyte> value) => ReverseElementBits(value);
-
- /// <summary>
- /// uint8x16_t vrbitq_u8 (uint8x16_t a)
- /// A64: RBIT Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> ReverseElementBits(Vector128<byte> value) => ReverseElementBits(value);
-
- /// <summary>
- /// int8x16_t vrbitq_s8 (int8x16_t a)
- /// A64: RBIT Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<sbyte> ReverseElementBits(Vector128<sbyte> value) => ReverseElementBits(value);
-
- /// <summary>
- /// uint8x8_t vuzp1_u8(uint8x8_t a, uint8x8_t b)
- /// A64: UZP1 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> UnzipEven(Vector64<byte> left, Vector64<byte> right) => UnzipEven(left, right);
-
- /// <summary>
- /// int16x4_t vuzp1_s16(int16x4_t a, int16x4_t b)
- /// A64: UZP1 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> UnzipEven(Vector64<short> left, Vector64<short> right) => UnzipEven(left, right);
-
- /// <summary>
- /// int32x2_t vuzp1_s32(int32x2_t a, int32x2_t b)
- /// A64: UZP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> UnzipEven(Vector64<int> left, Vector64<int> right) => UnzipEven(left, right);
-
- /// <summary>
- /// int8x8_t vuzp1_s8(int8x8_t a, int8x8_t b)
- /// A64: UZP1 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> UnzipEven(Vector64<sbyte> left, Vector64<sbyte> right) => UnzipEven(left, right);
-
- /// <summary>
- /// float32x2_t vuzp1_f32(float32x2_t a, float32x2_t b)
- /// A64: UZP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> UnzipEven(Vector64<float> left, Vector64<float> right) => UnzipEven(left, right);
-
- /// <summary>
- /// uint16x4_t vuzp1_u16(uint16x4_t a, uint16x4_t b)
- /// A64: UZP1 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> UnzipEven(Vector64<ushort> left, Vector64<ushort> right) => UnzipEven(left, right);
-
- /// <summary>
- /// uint32x2_t vuzp1_u32(uint32x2_t a, uint32x2_t b)
- /// A64: UZP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> UnzipEven(Vector64<uint> left, Vector64<uint> right) => UnzipEven(left, right);
-
- /// <summary>
- /// uint8x16_t vuzp1q_u8(uint8x16_t a, uint8x16_t b)
- /// A64: UZP1 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> UnzipEven(Vector128<byte> left, Vector128<byte> right) => UnzipEven(left, right);
-
- /// <summary>
- /// float64x2_t vuzp1q_f64(float64x2_t a, float64x2_t b)
- /// A64: UZP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> UnzipEven(Vector128<double> left, Vector128<double> right) => UnzipEven(left, right);
-
- /// <summary>
- /// int16x8_t vuzp1q_s16(int16x8_t a, int16x8_t b)
- /// A64: UZP1 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> UnzipEven(Vector128<short> left, Vector128<short> right) => UnzipEven(left, right);
-
- /// <summary>
- /// int32x4_t vuzp1q_s32(int32x4_t a, int32x4_t b)
- /// A64: UZP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> UnzipEven(Vector128<int> left, Vector128<int> right) => UnzipEven(left, right);
-
- /// <summary>
- /// int64x2_t vuzp1q_s64(int64x2_t a, int64x2_t b)
- /// A64: UZP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> UnzipEven(Vector128<long> left, Vector128<long> right) => UnzipEven(left, right);
-
- /// <summary>
- /// int8x16_t vuzp1q_u8(int8x16_t a, int8x16_t b)
- /// A64: UZP1 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> UnzipEven(Vector128<sbyte> left, Vector128<sbyte> right) => UnzipEven(left, right);
-
- /// <summary>
- /// float32x4_t vuzp1q_f32(float32x4_t a, float32x4_t b)
- /// A64: UZP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> UnzipEven(Vector128<float> left, Vector128<float> right) => UnzipEven(left, right);
-
- /// <summary>
- /// uint16x8_t vuzp1q_u16(uint16x8_t a, uint16x8_t b)
- /// A64: UZP1 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> UnzipEven(Vector128<ushort> left, Vector128<ushort> right) => UnzipEven(left, right);
-
- /// <summary>
- /// uint32x4_t vuzp1q_u32(uint32x4_t a, uint32x4_t b)
- /// A64: UZP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> UnzipEven(Vector128<uint> left, Vector128<uint> right) => UnzipEven(left, right);
-
- /// <summary>
- /// uint64x2_t vuzp1q_u64(uint64x2_t a, uint64x2_t b)
- /// A64: UZP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> UnzipEven(Vector128<ulong> left, Vector128<ulong> right) => UnzipEven(left, right);
-
- /// <summary>
- /// uint8x8_t vuzp2_u8(uint8x8_t a, uint8x8_t b)
- /// A64: UZP2 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> UnzipOdd(Vector64<byte> left, Vector64<byte> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// int16x4_t vuzp2_s16(int16x4_t a, int16x4_t b)
- /// A64: UZP2 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> UnzipOdd(Vector64<short> left, Vector64<short> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// int32x2_t vuzp2_s32(int32x2_t a, int32x2_t b)
- /// A64: UZP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> UnzipOdd(Vector64<int> left, Vector64<int> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// int8x8_t vuzp2_s8(int8x8_t a, int8x8_t b)
- /// A64: UZP2 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> UnzipOdd(Vector64<sbyte> left, Vector64<sbyte> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// float32x2_t vuzp2_f32(float32x2_t a, float32x2_t b)
- /// A64: UZP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> UnzipOdd(Vector64<float> left, Vector64<float> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// uint16x4_t vuzp2_u16(uint16x4_t a, uint16x4_t b)
- /// A64: UZP2 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> UnzipOdd(Vector64<ushort> left, Vector64<ushort> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// uint32x2_t vuzp2_u32(uint32x2_t a, uint32x2_t b)
- /// A64: UZP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> UnzipOdd(Vector64<uint> left, Vector64<uint> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// uint8x16_t vuzp2q_u8(uint8x16_t a, uint8x16_t b)
- /// A64: UZP2 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> UnzipOdd(Vector128<byte> left, Vector128<byte> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// float64x2_t vuzp2q_f64(float64x2_t a, float64x2_t b)
- /// A64: UZP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> UnzipOdd(Vector128<double> left, Vector128<double> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// int16x8_t vuzp2q_s16(int16x8_t a, int16x8_t b)
- /// A64: UZP2 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> UnzipOdd(Vector128<short> left, Vector128<short> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// int32x4_t vuzp2q_s32(int32x4_t a, int32x4_t b)
- /// A64: UZP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> UnzipOdd(Vector128<int> left, Vector128<int> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// int64x2_t vuzp2q_s64(int64x2_t a, int64x2_t b)
- /// A64: UZP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> UnzipOdd(Vector128<long> left, Vector128<long> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// int8x16_t vuzp2q_u8(int8x16_t a, int8x16_t b)
- /// A64: UZP2 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> UnzipOdd(Vector128<sbyte> left, Vector128<sbyte> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// float32x4_t vuzp2q_f32(float32x4_t a, float32x4_t b)
- /// A64: UZP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> UnzipOdd(Vector128<float> left, Vector128<float> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// uint16x8_t vuzp2q_u16(uint16x8_t a, uint16x8_t b)
- /// A64: UZP2 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> UnzipOdd(Vector128<ushort> left, Vector128<ushort> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// uint32x4_t vuzp2q_u32(uint32x4_t a, uint32x4_t b)
- /// A64: UZP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> UnzipOdd(Vector128<uint> left, Vector128<uint> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// uint64x2_t vuzp2q_u64(uint64x2_t a, uint64x2_t b)
- /// A64: UZP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> UnzipOdd(Vector128<ulong> left, Vector128<ulong> right) => UnzipOdd(left, right);
-
- /// <summary>
- /// uint8x8_t vzip2_u8(uint8x8_t a, uint8x8_t b)
- /// A64: ZIP2 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> ZipHigh(Vector64<byte> left, Vector64<byte> right) => ZipHigh(left, right);
-
- /// <summary>
- /// int16x4_t vzip2_s16(int16x4_t a, int16x4_t b)
- /// A64: ZIP2 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> ZipHigh(Vector64<short> left, Vector64<short> right) => ZipHigh(left, right);
-
- /// <summary>
- /// int32x2_t vzip2_s32(int32x2_t a, int32x2_t b)
- /// A64: ZIP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> ZipHigh(Vector64<int> left, Vector64<int> right) => ZipHigh(left, right);
-
- /// <summary>
- /// int8x8_t vzip2_s8(int8x8_t a, int8x8_t b)
- /// A64: ZIP2 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> ZipHigh(Vector64<sbyte> left, Vector64<sbyte> right) => ZipHigh(left, right);
-
- /// <summary>
- /// float32x2_t vzip2_f32(float32x2_t a, float32x2_t b)
- /// A64: ZIP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> ZipHigh(Vector64<float> left, Vector64<float> right) => ZipHigh(left, right);
-
- /// <summary>
- /// uint16x4_t vzip2_u16(uint16x4_t a, uint16x4_t b)
- /// A64: ZIP2 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> ZipHigh(Vector64<ushort> left, Vector64<ushort> right) => ZipHigh(left, right);
-
- /// <summary>
- /// uint32x2_t vzip2_u32(uint32x2_t a, uint32x2_t b)
- /// A64: ZIP2 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> ZipHigh(Vector64<uint> left, Vector64<uint> right) => ZipHigh(left, right);
-
- /// <summary>
- /// uint8x16_t vzip2q_u8(uint8x16_t a, uint8x16_t b)
- /// A64: ZIP2 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> ZipHigh(Vector128<byte> left, Vector128<byte> right) => ZipHigh(left, right);
-
- /// <summary>
- /// float64x2_t vzip2q_f64(float64x2_t a, float64x2_t b)
- /// A64: ZIP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> ZipHigh(Vector128<double> left, Vector128<double> right) => ZipHigh(left, right);
-
- /// <summary>
- /// int16x8_t vzip2q_s16(int16x8_t a, int16x8_t b)
- /// A64: ZIP2 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> ZipHigh(Vector128<short> left, Vector128<short> right) => ZipHigh(left, right);
-
- /// <summary>
- /// int32x4_t vzip2q_s32(int32x4_t a, int32x4_t b)
- /// A64: ZIP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> ZipHigh(Vector128<int> left, Vector128<int> right) => ZipHigh(left, right);
-
- /// <summary>
- /// int64x2_t vzip2q_s64(int64x2_t a, int64x2_t b)
- /// A64: ZIP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> ZipHigh(Vector128<long> left, Vector128<long> right) => ZipHigh(left, right);
-
- /// <summary>
- /// int8x16_t vzip2q_u8(int8x16_t a, int8x16_t b)
- /// A64: ZIP2 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> ZipHigh(Vector128<sbyte> left, Vector128<sbyte> right) => ZipHigh(left, right);
-
- /// <summary>
- /// float32x4_t vzip2q_f32(float32x4_t a, float32x4_t b)
- /// A64: ZIP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> ZipHigh(Vector128<float> left, Vector128<float> right) => ZipHigh(left, right);
-
- /// <summary>
- /// uint16x8_t vzip2q_u16(uint16x8_t a, uint16x8_t b)
- /// A64: ZIP2 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> ZipHigh(Vector128<ushort> left, Vector128<ushort> right) => ZipHigh(left, right);
-
- /// <summary>
- /// uint32x4_t vzip2q_u32(uint32x4_t a, uint32x4_t b)
- /// A64: ZIP2 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> ZipHigh(Vector128<uint> left, Vector128<uint> right) => ZipHigh(left, right);
-
- /// <summary>
- /// uint64x2_t vzip2q_u64(uint64x2_t a, uint64x2_t b)
- /// A64: ZIP2 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> ZipHigh(Vector128<ulong> left, Vector128<ulong> right) => ZipHigh(left, right);
-
- /// <summary>
- /// uint8x8_t vzip1_u8(uint8x8_t a, uint8x8_t b)
- /// A64: ZIP1 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> ZipLow(Vector64<byte> left, Vector64<byte> right) => ZipLow(left, right);
-
- /// <summary>
- /// int16x4_t vzip1_s16(int16x4_t a, int16x4_t b)
- /// A64: ZIP1 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> ZipLow(Vector64<short> left, Vector64<short> right) => ZipLow(left, right);
-
- /// <summary>
- /// int32x2_t vzip1_s32(int32x2_t a, int32x2_t b)
- /// A64: ZIP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> ZipLow(Vector64<int> left, Vector64<int> right) => ZipLow(left, right);
-
- /// <summary>
- /// int8x8_t vzip1_s8(int8x8_t a, int8x8_t b)
- /// A64: ZIP1 Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> ZipLow(Vector64<sbyte> left, Vector64<sbyte> right) => ZipLow(left, right);
-
- /// <summary>
- /// float32x2_t vzip1_f32(float32x2_t a, float32x2_t b)
- /// A64: ZIP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> ZipLow(Vector64<float> left, Vector64<float> right) => ZipLow(left, right);
-
- /// <summary>
- /// uint16x4_t vzip1_u16(uint16x4_t a, uint16x4_t b)
- /// A64: ZIP1 Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> ZipLow(Vector64<ushort> left, Vector64<ushort> right) => ZipLow(left, right);
-
- /// <summary>
- /// uint32x2_t vzip1_u32(uint32x2_t a, uint32x2_t b)
- /// A64: ZIP1 Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> ZipLow(Vector64<uint> left, Vector64<uint> right) => ZipLow(left, right);
-
- /// <summary>
- /// uint8x16_t vzip1q_u8(uint8x16_t a, uint8x16_t b)
- /// A64: ZIP1 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> ZipLow(Vector128<byte> left, Vector128<byte> right) => ZipLow(left, right);
-
- /// <summary>
- /// float64x2_t vzip1q_f64(float64x2_t a, float64x2_t b)
- /// A64: ZIP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<double> ZipLow(Vector128<double> left, Vector128<double> right) => ZipLow(left, right);
-
- /// <summary>
- /// int16x8_t vzip1q_s16(int16x8_t a, int16x8_t b)
- /// A64: ZIP1 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> ZipLow(Vector128<short> left, Vector128<short> right) => ZipLow(left, right);
-
- /// <summary>
- /// int32x4_t vzip1q_s32(int32x4_t a, int32x4_t b)
- /// A64: ZIP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> ZipLow(Vector128<int> left, Vector128<int> right) => ZipLow(left, right);
-
- /// <summary>
- /// int64x2_t vzip1q_s64(int64x2_t a, int64x2_t b)
- /// A64: ZIP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> ZipLow(Vector128<long> left, Vector128<long> right) => ZipLow(left, right);
-
- /// <summary>
- /// int8x16_t vzip1q_u8(int8x16_t a, int8x16_t b)
- /// A64: ZIP1 Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> ZipLow(Vector128<sbyte> left, Vector128<sbyte> right) => ZipLow(left, right);
-
- /// <summary>
- /// float32x4_t vzip1q_f32(float32x4_t a, float32x4_t b)
- /// A64: ZIP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> ZipLow(Vector128<float> left, Vector128<float> right) => ZipLow(left, right);
-
- /// <summary>
- /// uint16x8_t vzip1q_u16(uint16x8_t a, uint16x8_t b)
- /// A64: ZIP1 Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> ZipLow(Vector128<ushort> left, Vector128<ushort> right) => ZipLow(left, right);
-
- /// <summary>
- /// uint32x4_t vzip1q_u32(uint32x4_t a, uint32x4_t b)
- /// A64: ZIP1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> ZipLow(Vector128<uint> left, Vector128<uint> right) => ZipLow(left, right);
-
- /// <summary>
- /// uint64x2_t vzip1q_u64(uint64x2_t a, uint64x2_t b)
- /// A64: ZIP1 Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> ZipLow(Vector128<ulong> left, Vector128<ulong> right) => ZipLow(left, right);
- }
-
- /// <summary>
- /// int8x8_t vabs_s8 (int8x8_t a)
- /// A32: VABS.S8 Dd, Dm
- /// A64: ABS Vd.8B, Vn.8B
- /// </summary>
- public static Vector64<byte> Abs(Vector64<sbyte> value) => Abs(value);
-
- /// <summary>
- /// int16x4_t vabs_s16 (int16x4_t a)
- /// A32: VABS.S16 Dd, Dm
- /// A64: ABS Vd.4H, Vn.4H
- /// </summary>
- public static Vector64<ushort> Abs(Vector64<short> value) => Abs(value);
-
- /// <summary>
- /// int32x2_t vabs_s32 (int32x2_t a)
- /// A32: VABS.S32 Dd, Dm
- /// A64: ABS Vd.2S, Vn.2S
- /// </summary>
- public static Vector64<uint> Abs(Vector64<int> value) => Abs(value);
-
- /// <summary>
- /// float32x2_t vabs_f32 (float32x2_t a)
- /// A32: VABS.F32 Dd, Dm
- /// A64: FABS Vd.2S, Vn.2S
- /// </summary>
- public static Vector64<float> Abs(Vector64<float> value) => Abs(value);
-
- /// <summary>
- /// int8x16_t vabsq_s8 (int8x16_t a)
- /// A32: VABS.S8 Qd, Qm
- /// A64: ABS Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> Abs(Vector128<sbyte> value) => Abs(value);
-
- /// <summary>
- /// int16x8_t vabsq_s16 (int16x8_t a)
- /// A32: VABS.S16 Qd, Qm
- /// A64: ABS Vd.8H, Vn.8H
- /// </summary>
- public static Vector128<ushort> Abs(Vector128<short> value) => Abs(value);
-
- /// <summary>
- /// int32x4_t vabsq_s32 (int32x4_t a)
- /// A32: VABS.S32 Qd, Qm
- /// A64: ABS Vd.4S, Vn.4S
- /// </summary>
- public static Vector128<uint> Abs(Vector128<int> value) => Abs(value);
-
- /// <summary>
- /// float32x4_t vabsq_f32 (float32x4_t a)
- /// A32: VABS.F32 Qd, Qm
- /// A64: FABS Vd.4S, Vn.4S
- /// </summary>
- public static Vector128<float> Abs(Vector128<float> value) => Abs(value);
-
- // /// <summary>
- // /// float64x1_t vabs_f64 (float64x1_t a)
- // /// A32: VABS.F64 Dd, Dm
- // /// A64: FABS Dd, Dn
- // /// </summary>
- // public static Vector64<double> AbsScalar(Vector64<double> value) => Abs(value);
-
- /// <summary>
- /// A32: VABS.F32 Sd, Sm
- /// A64: FABS Sd, Sn
- /// </summary>
- public static Vector64<float> AbsScalar(Vector64<float> value) => AbsScalar(value);
-
- /// <summary>
- /// uint8x8_t vadd_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VADD.I8 Dd, Dn, Dm
- /// A64: ADD Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> Add(Vector64<byte> left, Vector64<byte> right) => Add(left, right);
-
- /// <summary>
- /// int16x4_t vadd_s16 (int16x4_t a, int16x4_t b)
- /// A32: VADD.I16 Dd, Dn, Dm
- /// A64: ADD Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> Add(Vector64<short> left, Vector64<short> right) => Add(left, right);
-
- /// <summary>
- /// int32x2_t vadd_s32 (int32x2_t a, int32x2_t b)
- /// A32: VADD.I32 Dd, Dn, Dm
- /// A64: ADD Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> Add(Vector64<int> left, Vector64<int> right) => Add(left, right);
-
- /// <summary>
- /// int8x8_t vadd_s8 (int8x8_t a, int8x8_t b)
- /// A32: VADD.I8 Dd, Dn, Dm
- /// A64: ADD Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> Add(Vector64<sbyte> left, Vector64<sbyte> right) => Add(left, right);
-
- /// <summary>
- /// float32x2_t vadd_f32 (float32x2_t a, float32x2_t b)
- /// A32: VADD.F32 Dd, Dn, Dm
- /// A64: FADD Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> Add(Vector64<float> left, Vector64<float> right) => Add(left, right);
-
- /// <summary>
- /// uint16x4_t vadd_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VADD.I16 Dd, Dn, Dm
- /// A64: ADD Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> Add(Vector64<ushort> left, Vector64<ushort> right) => Add(left, right);
-
- /// <summary>
- /// uint32x2_t vadd_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VADD.I32 Dd, Dn, Dm
- /// A64: ADD Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> Add(Vector64<uint> left, Vector64<uint> right) => Add(left, right);
-
- /// <summary>
- /// uint8x16_t vaddq_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VADD.I8 Qd, Qn, Qm
- /// A64: ADD Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> Add(Vector128<byte> left, Vector128<byte> right) => Add(left, right);
-
- /// <summary>
- /// int16x8_t vaddq_s16 (int16x8_t a, int16x8_t b)
- /// A32: VADD.I16 Qd, Qn, Qm
- /// A64: ADD Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> Add(Vector128<short> left, Vector128<short> right) => Add(left, right);
-
- /// <summary>
- /// int32x4_t vaddq_s32 (int32x4_t a, int32x4_t b)
- /// A32: VADD.I32 Qd, Qn, Qm
- /// A64: ADD Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> Add(Vector128<int> left, Vector128<int> right) => Add(left, right);
-
- /// <summary>
- /// int64x2_t vaddq_s64 (int64x2_t a, int64x2_t b)
- /// A32: VADD.I64 Qd, Qn, Qm
- /// A64: ADD Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> Add(Vector128<long> left, Vector128<long> right) => Add(left, right);
-
- /// <summary>
- /// int8x16_t vaddq_s8 (int8x16_t a, int8x16_t b)
- /// A32: VADD.I8 Qd, Qn, Qm
- /// A64: ADD Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> Add(Vector128<sbyte> left, Vector128<sbyte> right) => Add(left, right);
-
- /// <summary>
- /// float32x4_t vaddq_f32 (float32x4_t a, float32x4_t b)
- /// A32: VADD.F32 Qd, Qn, Qm
- /// A64: FADD Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> Add(Vector128<float> left, Vector128<float> right) => Add(left, right);
-
- /// <summary>
- /// uint16x8_t vaddq_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VADD.I16 Qd, Qn, Qm
- /// A64: ADD Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> Add(Vector128<ushort> left, Vector128<ushort> right) => Add(left, right);
-
- /// <summary>
- /// uint32x4_t vaddq_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VADD.I32 Qd, Qn, Qm
- /// A64: ADD Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> Add(Vector128<uint> left, Vector128<uint> right) => Add(left, right);
-
- /// <summary>
- /// uint64x2_t vaddq_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VADD.I64 Qd, Qn, Qm
- /// A64: ADD Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> Add(Vector128<ulong> left, Vector128<ulong> right) => Add(left, right);
-
- // /// <summary>
- // /// float64x1_t vadd_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VADD.F64 Dd, Dn, Dm
- // /// A64: FADD Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<double> AddScalar(Vector64<double> left, Vector64<double> right) => Add(left, right);
-
- // /// <summary>
- // /// int64x1_t vadd_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VADD.I64 Dd, Dn, Dm
- // /// A64: ADD Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<long> AddScalar(Vector64<long> left, Vector64<long> right) => AddScalar(left, right);
-
- // /// <summary>
- // /// uint64x1_t vadd_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VADD.I64 Dd, Dn, Dm
- // /// A64: ADD Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<ulong> AddScalar(Vector64<ulong> left, Vector64<ulong> right) => AddScalar(left, right);
-
- /// <summary>
- /// A32: VADD.F32 Sd, Sn, Sm
- /// A64:
- /// </summary>
- public static Vector64<float> AddScalar(Vector64<float> left, Vector64<float> right) => AddScalar(left, right);
-
- /// <summary>
- /// uint8x8_t vand_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> And(Vector64<byte> left, Vector64<byte> right) => And(left, right);
-
- // /// <summary>
- // /// float64x1_t vand_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VAND Dd, Dn, Dm
- // /// A64: AND Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> And(Vector64<double> left, Vector64<double> right) => And(left, right);
-
- /// <summary>
- /// int16x4_t vand_s16 (int16x4_t a, int16x4_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> And(Vector64<short> left, Vector64<short> right) => And(left, right);
-
- /// <summary>
- /// int32x2_t vand_s32(int32x2_t a, int32x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> And(Vector64<int> left, Vector64<int> right) => And(left, right);
-
- // /// <summary>
- // /// int64x1_t vand_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VAND Dd, Dn, Dm
- // /// A64: AND Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> And(Vector64<long> left, Vector64<long> right) => And(left, right);
-
- /// <summary>
- /// int8x8_t vand_s8 (int8x8_t a, int8x8_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> And(Vector64<sbyte> left, Vector64<sbyte> right) => And(left, right);
-
- /// <summary>
- /// float32x2_t vand_f32 (float32x2_t a, float32x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> And(Vector64<float> left, Vector64<float> right) => And(left, right);
-
- /// <summary>
- /// uint16x4_t vand_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> And(Vector64<ushort> left, Vector64<ushort> right) => And(left, right);
-
- /// <summary>
- /// uint32x2_t vand_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> And(Vector64<uint> left, Vector64<uint> right) => And(left, right);
-
- // /// <summary>
- // /// uint64x1_t vand_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VAND Dd, Dn, Dm
- // /// A64: AND Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> And(Vector64<ulong> left, Vector64<ulong> right) => And(left, right);
-
- /// <summary>
- /// uint8x16_t vand_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> And(Vector128<byte> left, Vector128<byte> right) => And(left, right);
-
- /// <summary>
- /// float64x2_t vand_f64 (float64x2_t a, float64x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> And(Vector128<double> left, Vector128<double> right) => And(left, right);
-
- /// <summary>
- /// int16x8_t vand_s16 (int16x8_t a, int16x8_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> And(Vector128<short> left, Vector128<short> right) => And(left, right);
-
- /// <summary>
- /// int32x4_t vand_s32(int32x4_t a, int32x4_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> And(Vector128<int> left, Vector128<int> right) => And(left, right);
-
- /// <summary>
- /// int64x2_t vand_s64 (int64x2_t a, int64x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> And(Vector128<long> left, Vector128<long> right) => And(left, right);
-
- /// <summary>
- /// int8x16_t vand_s8 (int8x16_t a, int8x16_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> And(Vector128<sbyte> left, Vector128<sbyte> right) => And(left, right);
-
- /// <summary>
- /// float32x4_t vand_f32 (float32x4_t a, float32x4_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> And(Vector128<float> left, Vector128<float> right) => And(left, right);
-
- /// <summary>
- /// uint16x8_t vand_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> And(Vector128<ushort> left, Vector128<ushort> right) => And(left, right);
-
- /// <summary>
- /// uint32x4_t vand_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> And(Vector128<uint> left, Vector128<uint> right) => And(left, right);
-
- /// <summary>
- /// uint64x2_t vand_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VAND Dd, Dn, Dm
- /// A64: AND Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> And(Vector128<ulong> left, Vector128<ulong> right) => And(left, right);
-
- /// <summary>
- /// uint8x8_t vbic_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> AndNot(Vector64<byte> left, Vector64<byte> right) => AndNot(left, right);
-
- // /// <summary>
- // /// float64x1_t vbic_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VBIC Dd, Dn, Dm
- // /// A64: BIC Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> AndNot(Vector64<double> left, Vector64<double> right) => AndNot(left, right);
-
- /// <summary>
- /// int16x4_t vbic_s16 (int16x4_t a, int16x4_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> AndNot(Vector64<short> left, Vector64<short> right) => AndNot(left, right);
-
- /// <summary>
- /// int32x2_t vbic_s32(int32x2_t a, int32x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> AndNot(Vector64<int> left, Vector64<int> right) => AndNot(left, right);
-
- // /// <summary>
- // /// int64x1_t vbic_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VBIC Dd, Dn, Dm
- // /// A64: BIC Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> AndNot(Vector64<long> left, Vector64<long> right) => AndNot(left, right);
-
- /// <summary>
- /// int8x8_t vbic_s8 (int8x8_t a, int8x8_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> AndNot(Vector64<sbyte> left, Vector64<sbyte> right) => AndNot(left, right);
-
- /// <summary>
- /// float32x2_t vbic_f32 (float32x2_t a, float32x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> AndNot(Vector64<float> left, Vector64<float> right) => AndNot(left, right);
-
- /// <summary>
- /// uint16x4_t vbic_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> AndNot(Vector64<ushort> left, Vector64<ushort> right) => AndNot(left, right);
-
- /// <summary>
- /// uint32x2_t vbic_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> AndNot(Vector64<uint> left, Vector64<uint> right) => AndNot(left, right);
-
- // /// <summary>
- // /// uint64x1_t vbic_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VBIC Dd, Dn, Dm
- // /// A64: BIC Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> AndNot(Vector64<ulong> left, Vector64<ulong> right) => AndNot(left, right);
-
- /// <summary>
- /// uint8x16_t vbic_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> AndNot(Vector128<byte> left, Vector128<byte> right) => AndNot(left, right);
-
- /// <summary>
- /// float64x2_t vbic_f64 (float64x2_t a, float64x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> AndNot(Vector128<double> left, Vector128<double> right) => AndNot(left, right);
-
- /// <summary>
- /// int16x8_t vbic_s16 (int16x8_t a, int16x8_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> AndNot(Vector128<short> left, Vector128<short> right) => AndNot(left, right);
-
- /// <summary>
- /// int32x4_t vbic_s32(int32x4_t a, int32x4_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> AndNot(Vector128<int> left, Vector128<int> right) => AndNot(left, right);
-
- /// <summary>
- /// int64x2_t vbic_s64 (int64x2_t a, int64x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> AndNot(Vector128<long> left, Vector128<long> right) => AndNot(left, right);
-
- /// <summary>
- /// int8x16_t vbic_s8 (int8x16_t a, int8x16_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> AndNot(Vector128<sbyte> left, Vector128<sbyte> right) => AndNot(left, right);
-
- /// <summary>
- /// float32x4_t vbic_f32 (float32x4_t a, float32x4_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> AndNot(Vector128<float> left, Vector128<float> right) => AndNot(left, right);
-
- /// <summary>
- /// uint16x8_t vbic_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> AndNot(Vector128<ushort> left, Vector128<ushort> right) => AndNot(left, right);
-
- /// <summary>
- /// uint32x4_t vbic_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> AndNot(Vector128<uint> left, Vector128<uint> right) => AndNot(left, right);
-
- /// <summary>
- /// uint64x2_t vbic_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VBIC Dd, Dn, Dm
- /// A64: BIC Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> AndNot(Vector128<ulong> left, Vector128<ulong> right) => AndNot(left, right);
-
- /// <summary>
- /// uint8x8_t vbsl_u8 (uint8x8_t a, uint8x8_t b, uint8x8_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> BitwiseSelect(Vector64<byte> select, Vector64<byte> left, Vector64<byte> right) => BitwiseSelect(select, left, right);
-
- // /// <summary>
- // /// float64x1_t vbsl_f64 (float64x1_t a, float64x1_t b, float64x1_t c)
- // /// A32: VBSL Dd, Dn, Dm
- // /// A64: BSL Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<double> BitwiseSelect(Vector64<double> select, Vector64<double> left, Vector64<double> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// int16x4_t vbsl_s16 (int16x4_t a, int16x4_t b, int16x4_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> BitwiseSelect(Vector64<short> select, Vector64<short> left, Vector64<short> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// int32x2_t vbsl_s32 (int32x2_t a, int32x2_t b, int32x2_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> BitwiseSelect(Vector64<int> select, Vector64<int> left, Vector64<int> right) => BitwiseSelect(select, left, right);
-
- // /// <summary>
- // /// int64x1_t vbsl_s64 (int64x1_t a, int64x1_t b, int64x1_t c)
- // /// A32: VBSL Dd, Dn, Dm
- // /// A64: BSL Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> BitwiseSelect(Vector64<long> select, Vector64<long> left, Vector64<long> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// int8x8_t vbsl_s8 (int8x8_t a, int8x8_t b, int8x8_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> BitwiseSelect(Vector64<sbyte> select, Vector64<sbyte> left, Vector64<sbyte> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// float32x2_t vbsl_f32 (float32x2_t a, float32x2_t b, float32x2_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<float> BitwiseSelect(Vector64<float> select, Vector64<float> left, Vector64<float> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// uint16x4_t vbsl_u16 (uint16x4_t a, uint16x4_t b, uint16x4_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> BitwiseSelect(Vector64<ushort> select, Vector64<ushort> left, Vector64<ushort> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// uint32x2_t vbsl_u32 (uint32x2_t a, uint32x2_t b, uint32x2_t c)
- /// A32: VBSL Dd, Dn, Dm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> BitwiseSelect(Vector64<uint> select, Vector64<uint> left, Vector64<uint> right) => BitwiseSelect(select, left, right);
-
- // /// <summary>
- // /// uint64x1_t vbsl_u64 (uint64x1_t a, uint64x1_t b, uint64x1_t c)
- // /// A32: VBSL Dd, Dn, Dm
- // /// A64: BSL Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> BitwiseSelect(Vector64<ulong> select, Vector64<ulong> left, Vector64<ulong> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// uint8x16_t vbslq_u8 (uint8x16_t a, uint8x16_t b, uint8x16_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> BitwiseSelect(Vector128<byte> select, Vector128<byte> left, Vector128<byte> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// float64x2_t vbslq_f64 (float64x2_t a, float64x2_t b, float64x2_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<double> BitwiseSelect(Vector128<double> select, Vector128<double> left, Vector128<double> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// int16x8_t vbslq_s16 (int16x8_t a, int16x8_t b, int16x8_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> BitwiseSelect(Vector128<short> select, Vector128<short> left, Vector128<short> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// int32x4_t vbslq_s32 (int32x4_t a, int32x4_t b, int32x4_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> BitwiseSelect(Vector128<int> select, Vector128<int> left, Vector128<int> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// int64x2_t vbslq_s64 (int64x2_t a, int64x2_t b, int64x2_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> BitwiseSelect(Vector128<long> select, Vector128<long> left, Vector128<long> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// int8x16_t vbslq_s8 (int8x16_t a, int8x16_t b, int8x16_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> BitwiseSelect(Vector128<sbyte> select, Vector128<sbyte> left, Vector128<sbyte> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// float32x4_t vbslq_f32 (float32x4_t a, float32x4_t b, float32x4_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<float> BitwiseSelect(Vector128<float> select, Vector128<float> left, Vector128<float> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// uint16x8_t vbslq_u16 (uint16x8_t a, uint16x8_t b, uint16x8_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> BitwiseSelect(Vector128<ushort> select, Vector128<ushort> left, Vector128<ushort> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// uint32x4_t vbslq_u32 (uint32x4_t a, uint32x4_t b, uint32x4_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> BitwiseSelect(Vector128<uint> select, Vector128<uint> left, Vector128<uint> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// uint64x2_t vbslq_u64 (uint64x2_t a, uint64x2_t b, uint64x2_t c)
- /// A32: VBSL Qd, Qn, Qm
- /// A64: BSL Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> BitwiseSelect(Vector128<ulong> select, Vector128<ulong> left, Vector128<ulong> right) => BitwiseSelect(select, left, right);
-
- /// <summary>
- /// int8x8_t vcls_s8 (int8x8_t a)
- /// A32: VCLS Dd, Dm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector64<sbyte> LeadingSignCount(Vector64<sbyte> value) => LeadingSignCount(value);
-
- /// <summary>
- /// int16x4_t vcls_s16 (int16x4_t a)
- /// A32: VCLS Dd, Dm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector64<short> LeadingSignCount(Vector64<short> value) => LeadingSignCount(value);
-
- /// <summary>
- /// int32x2_t vcls_s32 (int32x2_t a)
- /// A32: VCLS Dd, Dm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector64<int> LeadingSignCount(Vector64<int> value) => LeadingSignCount(value);
-
- /// <summary>
- /// int8x16_t vclsq_s8 (int8x16_t a)
- /// A32: VCLS Qd, Qm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector128<sbyte> LeadingSignCount(Vector128<sbyte> value) => LeadingSignCount(value);
-
- /// <summary>
- /// int16x8_t vclsq_s16 (int16x8_t a)
- /// A32: VCLS Qd, Qm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector128<short> LeadingSignCount(Vector128<short> value) => LeadingSignCount(value);
-
- /// <summary>
- /// int32x4_t vclsq_s32 (int32x4_t a)
- /// A32: VCLS Qd, Qm
- /// A64: CLS Vd, Vn
- /// </summary>
- public static Vector128<int> LeadingSignCount(Vector128<int> value) => LeadingSignCount(value);
-
- /// <summary>
- /// int8x8_t vclz_s8 (int8x8_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<sbyte> LeadingZeroCount(Vector64<sbyte> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// uint8x8_t vclz_u8 (uint8x8_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<byte> LeadingZeroCount(Vector64<byte> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// int16x4_t vclz_s16 (int16x4_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<short> LeadingZeroCount(Vector64<short> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// uint16x4_t vclz_u16 (uint16x4_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<ushort> LeadingZeroCount(Vector64<ushort> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// int32x2_t vclz_s32 (int32x2_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<int> LeadingZeroCount(Vector64<int> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// uint32x2_t vclz_u32 (uint32x2_t a)
- /// A32: VCLZ Dd, Dm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector64<uint> LeadingZeroCount(Vector64<uint> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// int8x16_t vclzq_s8 (int8x16_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<sbyte> LeadingZeroCount(Vector128<sbyte> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// uint8x16_t vclzq_u8 (uint8x16_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<byte> LeadingZeroCount(Vector128<byte> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// int16x8_t vclzq_s16 (int16x8_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<short> LeadingZeroCount(Vector128<short> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// uint16x8_t vclzq_u16 (uint16x8_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<ushort> LeadingZeroCount(Vector128<ushort> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// int32x4_t vclzq_s32 (int32x4_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<int> LeadingZeroCount(Vector128<int> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// uint32x4_t vclzq_u32 (uint32x4_t a)
- /// A32: VCLZ Qd, Qm
- /// A64: CLZ Vd, Vn
- /// </summary>
- public static Vector128<uint> LeadingZeroCount(Vector128<uint> value) => LeadingZeroCount(value);
-
- /// <summary>
- /// uint8x8_t vld1_u8 (uint8_t const * ptr)
- /// A32: VLD1.8 Dd, [Rn]
- /// A64: LD1 Vt.8B, [Xn]
- /// </summary>
- public static unsafe Vector64<byte> LoadVector64(byte* address) => LoadVector64(address);
-
- /// <summary>
- /// int16x4_t vld1_s16 (int16_t const * ptr)
- /// A32: VLD1.16 Dd, [Rn]
- /// A64: LD1 Vt.4H, [Xn]
- /// </summary>
- public static unsafe Vector64<short> LoadVector64(short* address) => LoadVector64(address);
-
- /// <summary>
- /// int32x2_t vld1_s32 (int32_t const * ptr)
- /// A32: VLD1.32 Dd, [Rn]
- /// A64: LD1 Vt.2S, [Xn]
- /// </summary>
- public static unsafe Vector64<int> LoadVector64(int* address) => LoadVector64(address);
-
- /// <summary>
- /// int8x8_t vld1_s8 (int8_t const * ptr)
- /// A32: VLD1.8 Dd, [Rn]
- /// A64: LD1 Vt.8B, [Xn]
- /// </summary>
- public static unsafe Vector64<sbyte> LoadVector64(sbyte* address) => LoadVector64(address);
-
- /// <summary>
- /// float32x2_t vld1_f32 (float32_t const * ptr)
- /// A32: VLD1.32 Dd, [Rn]
- /// A64: LD1 Vt.2S, [Xn]
- /// </summary>
- public static unsafe Vector64<float> LoadVector64(float* address) => LoadVector64(address);
-
- /// <summary>
- /// uint16x4_t vld1_u16 (uint16_t const * ptr)
- /// A32: VLD1.16 Dd, [Rn]
- /// A64: LD1 Vt.4H, [Xn]
- /// </summary>
- public static unsafe Vector64<ushort> LoadVector64(ushort* address) => LoadVector64(address);
-
- /// <summary>
- /// uint32x2_t vld1_u32 (uint32_t const * ptr)
- /// A32: VLD1.32 Dd, [Rn]
- /// A64: LD1 Vt.2S, [Xn]
- /// </summary>
- public static unsafe Vector64<uint> LoadVector64(uint* address) => LoadVector64(address);
-
- /// <summary>
- /// uint8x16_t vld1q_u8 (uint8_t const * ptr)
- /// A32: VLD1.8 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.16B, [Xn]
- /// </summary>
- public static unsafe Vector128<byte> LoadVector128(byte* address) => LoadVector128(address);
-
- /// <summary>
- /// float64x2_t vld1q_f64 (float64_t const * ptr)
- /// A32: VLD1.64 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.2D, [Xn]
- /// </summary>
- public static unsafe Vector128<double> LoadVector128(double* address) => LoadVector128(address);
-
- /// <summary>
- /// int16x8_t vld1q_s16 (int16_t const * ptr)
- /// A32: VLD1.16 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.8H, [Xn]
- /// </summary>
- public static unsafe Vector128<short> LoadVector128(short* address) => LoadVector128(address);
-
- /// <summary>
- /// int32x4_t vld1q_s32 (int32_t const * ptr)
- /// A32: VLD1.32 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.4S, [Xn]
- /// </summary>
- public static unsafe Vector128<int> LoadVector128(int* address) => LoadVector128(address);
-
- /// <summary>
- /// int64x2_t vld1q_s64 (int64_t const * ptr)
- /// A32: VLD1.64 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.2D, [Xn]
- /// </summary>
- public static unsafe Vector128<long> LoadVector128(long* address) => LoadVector128(address);
-
- /// <summary>
- /// int8x16_t vld1q_s8 (int8_t const * ptr)
- /// A32: VLD1.8 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.16B, [Xn]
- /// </summary>
- public static unsafe Vector128<sbyte> LoadVector128(sbyte* address) => LoadVector128(address);
-
- /// <summary>
- /// float32x4_t vld1q_f32 (float32_t const * ptr)
- /// A32: VLD1.32 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.4S, [Xn]
- /// </summary>
- public static unsafe Vector128<float> LoadVector128(float* address) => LoadVector128(address);
-
- /// <summary>
- /// uint16x8_t vld1q_s16 (uint16_t const * ptr)
- /// A32: VLD1.16 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.8H, [Xn]
- /// </summary>
- public static unsafe Vector128<ushort> LoadVector128(ushort* address) => LoadVector128(address);
-
- /// <summary>
- /// uint32x4_t vld1q_s32 (uint32_t const * ptr)
- /// A32: VLD1.32 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.4S, [Xn]
- /// </summary>
- public static unsafe Vector128<uint> LoadVector128(uint* address) => LoadVector128(address);
-
- /// <summary>
- /// uint64x2_t vld1q_u64 (uint64_t const * ptr)
- /// A32: VLD1.64 Dd, Dd+1, [Rn]
- /// A64: LD1 Vt.2D, [Xn]
- /// </summary>
- public static unsafe Vector128<ulong> LoadVector128(ulong* address) => LoadVector128(address);
-
- /// <summary>
- /// uint8x8_t vmvn_u8 (uint8x8_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> Not(Vector64<byte> value) => Not(value);
-
- // /// <summary>
- // /// float64x1_t vmvn_f64 (float64x1_t a)
- // /// A32: VMVN Dd, Dn, Dm
- // /// A64: MVN Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> Not(Vector64<double> value) => Not(value);
-
- /// <summary>
- /// int16x4_t vmvn_s16 (int16x4_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> Not(Vector64<short> value) => Not(value);
-
- /// <summary>
- /// int32x2_t vmvn_s32(int32x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> Not(Vector64<int> value) => Not(value);
-
- // /// <summary>
- // /// int64x1_t vmvn_s64 (int64x1_t a)
- // /// A32: VMVN Dd, Dn, Dm
- // /// A64: MVN Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> Not(Vector64<long> value) => Not(value);
-
- /// <summary>
- /// int8x8_t vmvn_s8 (int8x8_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> Not(Vector64<sbyte> value) => Not(value);
-
- /// <summary>
- /// float32x2_t vmvn_f32 (float32x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> Not(Vector64<float> value) => Not(value);
-
- /// <summary>
- /// uint16x4_t vmvn_u16 (uint16x4_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> Not(Vector64<ushort> value) => Not(value);
-
- /// <summary>
- /// uint32x2_t vmvn_u32 (uint32x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> Not(Vector64<uint> value) => Not(value);
-
- // /// <summary>
- // /// uint64x1_t vmvn_u64 (uint64x1_t a)
- // /// A32: VMVN Dd, Dn, Dm
- // /// A64: MVN Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> Not(Vector64<ulong> value) => Not(value);
-
- /// <summary>
- /// uint8x16_t vmvn_u8 (uint8x16_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> Not(Vector128<byte> value) => Not(value);
-
- /// <summary>
- /// float64x2_t vmvn_f64 (float64x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> Not(Vector128<double> value) => Not(value);
-
- /// <summary>
- /// int16x8_t vmvn_s16 (int16x8_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> Not(Vector128<short> value) => Not(value);
-
- /// <summary>
- /// int32x4_t vmvn_s32(int32x4_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> Not(Vector128<int> value) => Not(value);
-
- /// <summary>
- /// int64x2_t vmvn_s64 (int64x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> Not(Vector128<long> value) => Not(value);
-
- /// <summary>
- /// int8x16_t vmvn_s8 (int8x16_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> Not(Vector128<sbyte> value) => Not(value);
-
- /// <summary>
- /// float32x4_t vmvn_f32 (float32x4_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> Not(Vector128<float> value) => Not(value);
-
- /// <summary>
- /// uint16x8_t vmvn_u16 (uint16x8_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> Not(Vector128<ushort> value) => Not(value);
-
- /// <summary>
- /// uint32x4_t vmvn_u32 (uint32x4_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> Not(Vector128<uint> value) => Not(value);
-
- /// <summary>
- /// uint64x2_t vmvn_u64 (uint64x2_t a)
- /// A32: VMVN Dd, Dn, Dm
- /// A64: MVN Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> Not(Vector128<ulong> value) => Not(value);
-
- /// <summary>
- /// uint8x8_t vorr_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> Or(Vector64<byte> left, Vector64<byte> right) => Or(left, right);
-
- // /// <summary>
- // /// float64x1_t vorr_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VORR Dd, Dn, Dm
- // /// A64: ORR Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> Or(Vector64<double> left, Vector64<double> right) => Or(left, right);
-
- /// <summary>
- /// int16x4_t vorr_s16 (int16x4_t a, int16x4_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> Or(Vector64<short> left, Vector64<short> right) => Or(left, right);
-
- /// <summary>
- /// int32x2_t vorr_s32(int32x2_t a, int32x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> Or(Vector64<int> left, Vector64<int> right) => Or(left, right);
-
- // /// <summary>
- // /// int64x1_t vorr_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VORR Dd, Dn, Dm
- // /// A64: ORR Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> Or(Vector64<long> left, Vector64<long> right) => Or(left, right);
-
- /// <summary>
- /// int8x8_t vorr_s8 (int8x8_t a, int8x8_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> Or(Vector64<sbyte> left, Vector64<sbyte> right) => Or(left, right);
-
- /// <summary>
- /// float32x2_t vorr_f32 (float32x2_t a, float32x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> Or(Vector64<float> left, Vector64<float> right) => Or(left, right);
-
- /// <summary>
- /// uint16x4_t vorr_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> Or(Vector64<ushort> left, Vector64<ushort> right) => Or(left, right);
-
- /// <summary>
- /// uint32x2_t vorr_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> Or(Vector64<uint> left, Vector64<uint> right) => Or(left, right);
-
- // /// <summary>
- // /// uint64x1_t vorr_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VORR Dd, Dn, Dm
- // /// A64: ORR Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> Or(Vector64<ulong> left, Vector64<ulong> right) => Or(left, right);
-
- /// <summary>
- /// uint8x16_t vorr_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> Or(Vector128<byte> left, Vector128<byte> right) => Or(left, right);
-
- /// <summary>
- /// float64x2_t vorr_f64 (float64x2_t a, float64x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> Or(Vector128<double> left, Vector128<double> right) => Or(left, right);
-
- /// <summary>
- /// int16x8_t vorr_s16 (int16x8_t a, int16x8_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> Or(Vector128<short> left, Vector128<short> right) => Or(left, right);
-
- /// <summary>
- /// int32x4_t vorr_s32(int32x4_t a, int32x4_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> Or(Vector128<int> left, Vector128<int> right) => Or(left, right);
-
- /// <summary>
- /// int64x2_t vorr_s64 (int64x2_t a, int64x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> Or(Vector128<long> left, Vector128<long> right) => Or(left, right);
-
- /// <summary>
- /// int8x16_t vorr_s8 (int8x16_t a, int8x16_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> Or(Vector128<sbyte> left, Vector128<sbyte> right) => Or(left, right);
-
- /// <summary>
- /// float32x4_t vorr_f32 (float32x4_t a, float32x4_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> Or(Vector128<float> left, Vector128<float> right) => Or(left, right);
-
- /// <summary>
- /// uint16x8_t vorr_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> Or(Vector128<ushort> left, Vector128<ushort> right) => Or(left, right);
-
- /// <summary>
- /// uint32x4_t vorr_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> Or(Vector128<uint> left, Vector128<uint> right) => Or(left, right);
-
- /// <summary>
- /// uint64x2_t vorr_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VORR Dd, Dn, Dm
- /// A64: ORR Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> Or(Vector128<ulong> left, Vector128<ulong> right) => Or(left, right);
-
- /// <summary>
- /// uint8x8_t vorn_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> OrNot(Vector64<byte> left, Vector64<byte> right) => OrNot(left, right);
-
- // /// <summary>
- // /// float64x1_t vorn_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VORN Dd, Dn, Dm
- // /// A64: ORN Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> OrNot(Vector64<double> left, Vector64<double> right) => OrNot(left, right);
-
- /// <summary>
- /// int16x4_t vorn_s16 (int16x4_t a, int16x4_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> OrNot(Vector64<short> left, Vector64<short> right) => OrNot(left, right);
-
- /// <summary>
- /// int32x2_t vorn_s32(int32x2_t a, int32x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> OrNot(Vector64<int> left, Vector64<int> right) => OrNot(left, right);
-
- // /// <summary>
- // /// int64x1_t vorn_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VORN Dd, Dn, Dm
- // /// A64: ORN Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> OrNot(Vector64<long> left, Vector64<long> right) => OrNot(left, right);
-
- /// <summary>
- /// int8x8_t vorn_s8 (int8x8_t a, int8x8_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> OrNot(Vector64<sbyte> left, Vector64<sbyte> right) => OrNot(left, right);
-
- /// <summary>
- /// float32x2_t vorn_f32 (float32x2_t a, float32x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> OrNot(Vector64<float> left, Vector64<float> right) => OrNot(left, right);
-
- /// <summary>
- /// uint16x4_t vorn_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> OrNot(Vector64<ushort> left, Vector64<ushort> right) => OrNot(left, right);
-
- /// <summary>
- /// uint32x2_t vorn_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> OrNot(Vector64<uint> left, Vector64<uint> right) => OrNot(left, right);
-
- // /// <summary>
- // /// uint64x1_t vorn_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VORN Dd, Dn, Dm
- // /// A64: ORN Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> OrNot(Vector64<ulong> left, Vector64<ulong> right) => OrNot(left, right);
-
- /// <summary>
- /// uint8x16_t vorn_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> OrNot(Vector128<byte> left, Vector128<byte> right) => OrNot(left, right);
-
- /// <summary>
- /// float64x2_t vorn_f64 (float64x2_t a, float64x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> OrNot(Vector128<double> left, Vector128<double> right) => OrNot(left, right);
-
- /// <summary>
- /// int16x8_t vorn_s16 (int16x8_t a, int16x8_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> OrNot(Vector128<short> left, Vector128<short> right) => OrNot(left, right);
-
- /// <summary>
- /// int32x4_t vorn_s32(int32x4_t a, int32x4_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> OrNot(Vector128<int> left, Vector128<int> right) => OrNot(left, right);
-
- /// <summary>
- /// int64x2_t vorn_s64 (int64x2_t a, int64x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> OrNot(Vector128<long> left, Vector128<long> right) => OrNot(left, right);
-
- /// <summary>
- /// int8x16_t vorn_s8 (int8x16_t a, int8x16_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> OrNot(Vector128<sbyte> left, Vector128<sbyte> right) => OrNot(left, right);
-
- /// <summary>
- /// float32x4_t vorn_f32 (float32x4_t a, float32x4_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> OrNot(Vector128<float> left, Vector128<float> right) => OrNot(left, right);
-
- /// <summary>
- /// uint16x8_t vorn_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> OrNot(Vector128<ushort> left, Vector128<ushort> right) => OrNot(left, right);
-
- /// <summary>
- /// uint32x4_t vorn_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> OrNot(Vector128<uint> left, Vector128<uint> right) => OrNot(left, right);
-
- /// <summary>
- /// uint64x2_t vorn_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VORN Dd, Dn, Dm
- /// A64: ORN Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> OrNot(Vector128<ulong> left, Vector128<ulong> right) => OrNot(left, right);
-
- /// <summary>
- /// int8x8_t vcnt_s8 (int8x8_t a)
- /// A32: VCNT Dd, Dm
- /// A64: CNT Vd, Vn
- /// </summary>
- public static Vector64<sbyte> PopCount(Vector64<sbyte> value) => PopCount(value);
-
- /// <summary>
- /// uint8x8_t vcnt_u8 (uint8x8_t a)
- /// A32: VCNT Dd, Dm
- /// A64: CNT Vd, Vn
- /// </summary>
- public static Vector64<byte> PopCount(Vector64<byte> value) => PopCount(value);
-
- /// <summary>
- /// int8x16_t vcntq_s8 (int8x16_t a)
- /// A32: VCNT Qd, Qm
- /// A64: CNT Vd, Vn
- /// </summary>
- public static Vector128<sbyte> PopCount(Vector128<sbyte> value) => PopCount(value);
-
- /// <summary>
- /// uint8x16_t vcntq_u8 (uint8x16_t a)
- /// A32: VCNT Qd, Qm
- /// A64: CNT Vd, Vn
- /// </summary>
- public static Vector128<byte> PopCount(Vector128<byte> value) => PopCount(value);
-
- /// <summary>
- /// uint8x8_t vsub_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VSUB.I8 Dd, Dn, Dm
- /// A64: ADD Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<byte> Subtract(Vector64<byte> left, Vector64<byte> right) => Subtract(left, right);
-
- /// <summary>
- /// int16x4_t vsub_s16 (int16x4_t a, int16x4_t b)
- /// A32: VSUB.I16 Dd, Dn, Dm
- /// A64: ADD Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<short> Subtract(Vector64<short> left, Vector64<short> right) => Subtract(left, right);
-
- /// <summary>
- /// int32x2_t vsub_s32 (int32x2_t a, int32x2_t b)
- /// A32: VSUB.I32 Dd, Dn, Dm
- /// A64: ADD Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<int> Subtract(Vector64<int> left, Vector64<int> right) => Subtract(left, right);
-
- /// <summary>
- /// int8x8_t vsub_s8 (int8x8_t a, int8x8_t b)
- /// A32: VSUB.I8 Dd, Dn, Dm
- /// A64: ADD Vd.8B, Vn.8B, Vm.8B
- /// </summary>
- public static Vector64<sbyte> Subtract(Vector64<sbyte> left, Vector64<sbyte> right) => Subtract(left, right);
-
- /// <summary>
- /// float32x2_t vsub_f32 (float32x2_t a, float32x2_t b)
- /// A32: VSUB.F32 Dd, Dn, Dm
- /// A64: FSUB Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<float> Subtract(Vector64<float> left, Vector64<float> right) => Subtract(left, right);
-
- /// <summary>
- /// uint16x4_t vsub_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VSUB.I16 Dd, Dn, Dm
- /// A64: ADD Vd.4H, Vn.4H, Vm.4H
- /// </summary>
- public static Vector64<ushort> Subtract(Vector64<ushort> left, Vector64<ushort> right) => Subtract(left, right);
-
- /// <summary>
- /// uint32x2_t vsub_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VSUB.I32 Dd, Dn, Dm
- /// A64: ADD Vd.2S, Vn.2S, Vm.2S
- /// </summary>
- public static Vector64<uint> Subtract(Vector64<uint> left, Vector64<uint> right) => Subtract(left, right);
-
- /// <summary>
- /// uint8x16_t vsubq_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VSUB.I8 Qd, Qn, Qm
- /// A64: ADD Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<byte> Subtract(Vector128<byte> left, Vector128<byte> right) => Subtract(left, right);
-
- /// <summary>
- /// int16x8_t vsubq_s16 (int16x8_t a, int16x8_t b)
- /// A32: VSUB.I16 Qd, Qn, Qm
- /// A64: ADD Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<short> Subtract(Vector128<short> left, Vector128<short> right) => Subtract(left, right);
-
- /// <summary>
- /// int32x4_t vsubq_s32 (int32x4_t a, int32x4_t b)
- /// A32: VSUB.I32 Qd, Qn, Qm
- /// A64: ADD Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<int> Subtract(Vector128<int> left, Vector128<int> right) => Subtract(left, right);
-
- /// <summary>
- /// int64x2_t vsubq_s64 (int64x2_t a, int64x2_t b)
- /// A32: VSUB.I64 Qd, Qn, Qm
- /// A64: ADD Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<long> Subtract(Vector128<long> left, Vector128<long> right) => Subtract(left, right);
-
- /// <summary>
- /// int8x16_t vsubq_s8 (int8x16_t a, int8x16_t b)
- /// A32: VSUB.I8 Qd, Qn, Qm
- /// A64: ADD Vd.16B, Vn.16B, Vm.16B
- /// </summary>
- public static Vector128<sbyte> Subtract(Vector128<sbyte> left, Vector128<sbyte> right) => Subtract(left, right);
-
- /// <summary>
- /// float32x4_t vsubq_f32 (float32x4_t a, float32x4_t b)
- /// A32: VSUB.F32 Qd, Qn, Qm
- /// A64: FSUB Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<float> Subtract(Vector128<float> left, Vector128<float> right) => Subtract(left, right);
-
- /// <summary>
- /// uint16x8_t vsubq_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VSUB.I16 Qd, Qn, Qm
- /// A64: ADD Vd.8H, Vn.8H, Vm.8H
- /// </summary>
- public static Vector128<ushort> Subtract(Vector128<ushort> left, Vector128<ushort> right) => Subtract(left, right);
-
- /// <summary>
- /// uint32x4_t vsubq_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VSUB.I32 Qd, Qn, Qm
- /// A64: ADD Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> Subtract(Vector128<uint> left, Vector128<uint> right) => Subtract(left, right);
-
- /// <summary>
- /// uint64x2_t vsubq_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VSUB.I64 Qd, Qn, Qm
- /// A64: ADD Vd.2D, Vn.2D, Vm.2D
- /// </summary>
- public static Vector128<ulong> Subtract(Vector128<ulong> left, Vector128<ulong> right) => Subtract(left, right);
-
- // /// <summary>
- // /// float64x1_t vsub_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VSUB.F64 Dd, Dn, Dm
- // /// A64: FSUB Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<double> SubtractScalar(Vector64<double> left, Vector64<double> right) => Subtract(left, right);
-
- // /// <summary>
- // /// int64x1_t vsub_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VSUB.I64 Dd, Dn, Dm
- // /// A64: ADD Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<long> SubtractScalar(Vector64<long> left, Vector64<long> right) => SubtractScalar(left, right);
-
- // /// <summary>
- // /// uint64x1_t vsub_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VSUB.I64 Dd, Dn, Dm
- // /// A64: ADD Dd, Dn, Dm
- // /// </summary>
- // public static Vector64<ulong> SubtractScalar(Vector64<ulong> left, Vector64<ulong> right) => SubtractScalar(left, right);
-
- /// <summary>
- /// A32: VSUB.F32 Sd, Sn, Sm
- /// A64:
- /// </summary>
- public static Vector64<float> SubtractScalar(Vector64<float> left, Vector64<float> right) => SubtractScalar(left, right);
-
- /// <summary>
- /// uint8x8_t veor_u8 (uint8x8_t a, uint8x8_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<byte> Xor(Vector64<byte> left, Vector64<byte> right) => Xor(left, right);
-
- // /// <summary>
- // /// float64x1_t veor_f64 (float64x1_t a, float64x1_t b)
- // /// A32: VEOR Dd, Dn, Dm
- // /// A64: EOR Vd, Vn, Vm
- // /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- // /// </summary>
- // public static Vector64<double> Xor(Vector64<double> left, Vector64<double> right) => Xor(left, right);
-
- /// <summary>
- /// int16x4_t veor_s16 (int16x4_t a, int16x4_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<short> Xor(Vector64<short> left, Vector64<short> right) => Xor(left, right);
-
- /// <summary>
- /// int32x2_t veor_s32(int32x2_t a, int32x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<int> Xor(Vector64<int> left, Vector64<int> right) => Xor(left, right);
-
- // /// <summary>
- // /// int64x1_t veor_s64 (int64x1_t a, int64x1_t b)
- // /// A32: VEOR Dd, Dn, Dm
- // /// A64: EOR Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<long> Xor(Vector64<long> left, Vector64<long> right) => Xor(left, right);
-
- /// <summary>
- /// int8x8_t veor_s8 (int8x8_t a, int8x8_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<sbyte> Xor(Vector64<sbyte> left, Vector64<sbyte> right) => Xor(left, right);
-
- /// <summary>
- /// float32x2_t veor_f32 (float32x2_t a, float32x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector64<float> Xor(Vector64<float> left, Vector64<float> right) => Xor(left, right);
-
- /// <summary>
- /// uint16x4_t veor_u16 (uint16x4_t a, uint16x4_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<ushort> Xor(Vector64<ushort> left, Vector64<ushort> right) => Xor(left, right);
-
- /// <summary>
- /// uint32x2_t veor_u32 (uint32x2_t a, uint32x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector64<uint> Xor(Vector64<uint> left, Vector64<uint> right) => Xor(left, right);
-
- // /// <summary>
- // /// uint64x1_t veor_u64 (uint64x1_t a, uint64x1_t b)
- // /// A32: VEOR Dd, Dn, Dm
- // /// A64: EOR Vd, Vn, Vm
- // /// </summary>
- // public static Vector64<ulong> Xor(Vector64<ulong> left, Vector64<ulong> right) => Xor(left, right);
-
- /// <summary>
- /// uint8x16_t veor_u8 (uint8x16_t a, uint8x16_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<byte> Xor(Vector128<byte> left, Vector128<byte> right) => Xor(left, right);
-
- /// <summary>
- /// float64x2_t veor_f64 (float64x2_t a, float64x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<double> Xor(Vector128<double> left, Vector128<double> right) => Xor(left, right);
-
- /// <summary>
- /// int16x8_t veor_s16 (int16x8_t a, int16x8_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<short> Xor(Vector128<short> left, Vector128<short> right) => Xor(left, right);
-
- /// <summary>
- /// int32x4_t veor_s32(int32x4_t a, int32x4_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<int> Xor(Vector128<int> left, Vector128<int> right) => Xor(left, right);
-
- /// <summary>
- /// int64x2_t veor_s64 (int64x2_t a, int64x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<long> Xor(Vector128<long> left, Vector128<long> right) => Xor(left, right);
-
- /// <summary>
- /// int8x16_t veor_s8 (int8x16_t a, int8x16_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<sbyte> Xor(Vector128<sbyte> left, Vector128<sbyte> right) => Xor(left, right);
-
- /// <summary>
- /// float32x4_t veor_f32 (float32x4_t a, float32x4_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> Xor(Vector128<float> left, Vector128<float> right) => Xor(left, right);
-
- /// <summary>
- /// uint16x8_t veor_u16 (uint16x8_t a, uint16x8_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<ushort> Xor(Vector128<ushort> left, Vector128<ushort> right) => Xor(left, right);
-
- /// <summary>
- /// uint32x4_t veor_u32 (uint32x4_t a, uint32x4_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<uint> Xor(Vector128<uint> left, Vector128<uint> right) => Xor(left, right);
-
- /// <summary>
- /// uint64x2_t veor_u64 (uint64x2_t a, uint64x2_t b)
- /// A32: VEOR Dd, Dn, Dm
- /// A64: EOR Vd, Vn, Vm
- /// </summary>
- public static Vector128<ulong> Xor(Vector128<ulong> left, Vector128<ulong> right) => Xor(left, right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Aes.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Aes.PlatformNotSupported.cs
deleted file mode 100644
index 8f62ae5fcbc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Aes.PlatformNotSupported.cs
+++ /dev/null
@@ -1,48 +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.
-
-#pragma warning disable IDE0060 // unused parameters
-using System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM AES hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Aes : ArmBase
- {
- internal Aes() { }
-
- public static new bool IsSupported { [Intrinsic] get => false; }
-
- /// <summary>
- /// uint8x16_t vaesdq_u8 (uint8x16_t data, uint8x16_t key)
- /// A32: AESD.8 Qd, Qm
- /// A64: AESD Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> Decrypt(Vector128<byte> value, Vector128<byte> roundKey) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vaeseq_u8 (uint8x16_t data, uint8x16_t key)
- /// A32: AESE.8 Qd, Qm
- /// A64: AESE Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> Encrypt(Vector128<byte> value, Vector128<byte> roundKey) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vaesimcq_u8 (uint8x16_t data)
- /// A32: AESIMC.8 Qd, Qm
- /// A64: AESIMC Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> InverseMixColumns(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint8x16_t vaesmcq_u8 (uint8x16_t data)
- /// A32: AESMC.8 Qd, Qm
- /// A64: AESMC V>.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> MixColumns(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Aes.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Aes.cs
deleted file mode 100644
index fb0a1c63975..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Aes.cs
+++ /dev/null
@@ -1,48 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM AES hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Aes : ArmBase
- {
- internal Aes() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// uint8x16_t vaesdq_u8 (uint8x16_t data, uint8x16_t key)
- /// A32: AESD.8 Qd, Qm
- /// A64: AESD Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> Decrypt(Vector128<byte> value, Vector128<byte> roundKey) => Decrypt(value, roundKey);
-
- /// <summary>
- /// uint8x16_t vaeseq_u8 (uint8x16_t data, uint8x16_t key)
- /// A32: AESE.8 Qd, Qm
- /// A64: AESE Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> Encrypt(Vector128<byte> value, Vector128<byte> roundKey) => Encrypt(value, roundKey);
-
- /// <summary>
- /// uint8x16_t vaesimcq_u8 (uint8x16_t data)
- /// A32: AESIMC.8 Qd, Qm
- /// A64: AESIMC Vd.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> InverseMixColumns(Vector128<byte> value) => InverseMixColumns(value);
-
- /// <summary>
- /// uint8x16_t vaesmcq_u8 (uint8x16_t data)
- /// A32: AESMC.8 Qd, Qm
- /// A64: AESMC V>.16B, Vn.16B
- /// </summary>
- public static Vector128<byte> MixColumns(Vector128<byte> value) => MixColumns(value);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/ArmBase.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/ArmBase.PlatformNotSupported.cs
deleted file mode 100644
index 855c41bd9fc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/ArmBase.PlatformNotSupported.cs
+++ /dev/null
@@ -1,81 +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.
-
-#pragma warning disable IDE0060 // unused parameters
-using System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM base hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class ArmBase
- {
- internal ArmBase() { }
-
- public static bool IsSupported { [Intrinsic] get => false; }
-
- public abstract class Arm64
- {
- internal Arm64() { }
-
- public static bool IsSupported { [Intrinsic] get => false; }
-
- /// <summary>
- /// A64: CLS Wd, Wn
- /// </summary>
- public static int LeadingSignCount(int value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// A64: CLS Xd, Xn
- /// </summary>
- public static int LeadingSignCount(long value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// A64: CLZ Xd, Xn
- /// </summary>
- public static int LeadingZeroCount(long value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// A64: CLZ Xd, Xn
- /// </summary>
- public static int LeadingZeroCount(ulong value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// A64: RBIT Xd, Xn
- /// </summary>
- public static long ReverseElementBits(long value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// A64: RBIT Xd, Xn
- /// </summary>
- public static ulong ReverseElementBits(ulong value) { throw new PlatformNotSupportedException(); }
- }
-
- /// <summary>
- /// A32: CLZ Rd, Rm
- /// A64: CLZ Wd, Wn
- /// </summary>
- public static int LeadingZeroCount(int value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// A32: CLZ Rd, Rm
- /// A64: CLZ Wd, Wn
- /// </summary>
- public static int LeadingZeroCount(uint value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// A32: RBIT Rd, Rm
- /// A64: RBIT Wd, Wn
- /// </summary>
- public static int ReverseElementBits(int value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// A32: RBIT Rd, Rm
- /// A64: RBIT Wd, Wn
- /// </summary>
- public static uint ReverseElementBits(uint value) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/ArmBase.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/ArmBase.cs
deleted file mode 100644
index 11e2221e2a2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/ArmBase.cs
+++ /dev/null
@@ -1,82 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM base hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class ArmBase
- {
- internal ArmBase() { }
-
- public static bool IsSupported { get => IsSupported; }
-
- [Intrinsic]
- public abstract class Arm64
- {
- internal Arm64() { }
-
- public static bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// A64: CLS Wd, Wn
- /// </summary>
- public static int LeadingSignCount(int value) => LeadingSignCount(value);
-
- /// <summary>
- /// A64: CLS Xd, Xn
- /// </summary>
- public static int LeadingSignCount(long value) => LeadingSignCount(value);
-
- /// <summary>
- /// A64: CLZ Xd, Xn
- /// </summary>
- public static int LeadingZeroCount(long value) => LeadingZeroCount(value);
-
- /// <summary>
- /// A64: CLZ Xd, Xn
- /// </summary>
- public static int LeadingZeroCount(ulong value) => LeadingZeroCount(value);
-
- /// <summary>
- /// A64: RBIT Xd, Xn
- /// </summary>
- public static long ReverseElementBits(long value) => ReverseElementBits(value);
-
- /// <summary>
- /// A64: RBIT Xd, Xn
- /// </summary>
- public static ulong ReverseElementBits(ulong value) => ReverseElementBits(value);
- }
-
- /// <summary>
- /// A32: CLZ Rd, Rm
- /// A64: CLZ Wd, Wn
- /// </summary>
- public static int LeadingZeroCount(int value) => LeadingZeroCount(value);
-
- /// <summary>
- /// A32: CLZ Rd, Rm
- /// A64: CLZ Wd, Wn
- /// </summary>
- public static int LeadingZeroCount(uint value) => LeadingZeroCount(value);
-
- /// <summary>
- /// A32: RBIT Rd, Rm
- /// A64: RBIT Wd, Wn
- /// </summary>
- public static int ReverseElementBits(int value) => ReverseElementBits(value);
-
- /// <summary>
- /// A32: RBIT Rd, Rm
- /// A64: RBIT Wd, Wn
- /// </summary>
- public static uint ReverseElementBits(uint value) => ReverseElementBits(value);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Crc32.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Crc32.PlatformNotSupported.cs
deleted file mode 100644
index 36aa42e8160..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Crc32.PlatformNotSupported.cs
+++ /dev/null
@@ -1,82 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM Crc32 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Crc32 : ArmBase
- {
- internal Crc32() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- [Intrinsic]
- public new abstract class Arm64 : ArmBase.Arm64
- {
- internal Arm64() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// uint32_t __crc32d (uint32_t a, uint64_t b)
- /// A64: CRC32X Wd, Wn, Xm
- /// </summary>
- public static uint ComputeCrc32(uint crc, ulong data) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32_t __crc32cd (uint32_t a, uint64_t b)
- /// A64: CRC32CX Wd, Wn, Xm
- /// </summary>
- public static uint ComputeCrc32C(uint crc, ulong data) { throw new PlatformNotSupportedException(); }
- }
-
- /// <summary>
- /// uint32_t __crc32b (uint32_t a, uint8_t b)
- /// A32: CRC32B Rd, Rn, Rm
- /// A64: CRC32B Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32(uint crc, byte data) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32_t __crc32h (uint32_t a, uint16_t b)
- /// A32: CRC32H Rd, Rn, Rm
- /// A64: CRC32H Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32(uint crc, ushort data) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32_t __crc32w (uint32_t a, uint32_t b)
- /// A32: CRC32W Rd, Rn, Rm
- /// A64: CRC32W Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32(uint crc, uint data) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32_t __crc32cb (uint32_t a, uint8_t b)
- /// A32: CRC32CB Rd, Rn, Rm
- /// A64: CRC32CB Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32C(uint crc, byte data) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32_t __crc32ch (uint32_t a, uint16_t b)
- /// A32: CRC32CH Rd, Rn, Rm
- /// A64: CRC32CH Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32C(uint crc, ushort data) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32_t __crc32cw (uint32_t a, uint32_t b)
- /// A32: CRC32CW Rd, Rn, Rm
- /// A64: CRC32CW Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32C(uint crc, uint data) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Crc32.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Crc32.cs
deleted file mode 100644
index 8d5684c08cf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Crc32.cs
+++ /dev/null
@@ -1,82 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM Crc32 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Crc32 : ArmBase
- {
- internal Crc32() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- [Intrinsic]
- public new abstract class Arm64 : ArmBase.Arm64
- {
- internal Arm64() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// uint32_t __crc32d (uint32_t a, uint64_t b)
- /// A64: CRC32X Wd, Wn, Xm
- /// </summary>
- public static uint ComputeCrc32(uint crc, ulong data) => ComputeCrc32(crc, data);
-
- /// <summary>
- /// uint32_t __crc32cd (uint32_t a, uint64_t b)
- /// A64: CRC32CX Wd, Wn, Xm
- /// </summary>
- public static uint ComputeCrc32C(uint crc, ulong data) => ComputeCrc32C(crc, data);
- }
-
- /// <summary>
- /// uint32_t __crc32b (uint32_t a, uint8_t b)
- /// A32: CRC32B Rd, Rn, Rm
- /// A64: CRC32B Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32(uint crc, byte data) => ComputeCrc32(crc, data);
-
- /// <summary>
- /// uint32_t __crc32h (uint32_t a, uint16_t b)
- /// A32: CRC32H Rd, Rn, Rm
- /// A64: CRC32H Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32(uint crc, ushort data) => ComputeCrc32(crc, data);
-
- /// <summary>
- /// uint32_t __crc32w (uint32_t a, uint32_t b)
- /// A32: CRC32W Rd, Rn, Rm
- /// A64: CRC32W Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32(uint crc, uint data) => ComputeCrc32(crc, data);
-
- /// <summary>
- /// uint32_t __crc32cb (uint32_t a, uint8_t b)
- /// A32: CRC32CB Rd, Rn, Rm
- /// A64: CRC32CB Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32C(uint crc, byte data) => ComputeCrc32C(crc, data);
-
- /// <summary>
- /// uint32_t __crc32ch (uint32_t a, uint16_t b)
- /// A32: CRC32CH Rd, Rn, Rm
- /// A64: CRC32CH Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32C(uint crc, ushort data) => ComputeCrc32C(crc, data);
-
- /// <summary>
- /// uint32_t __crc32cw (uint32_t a, uint32_t b)
- /// A32: CRC32CW Rd, Rn, Rm
- /// A64: CRC32CW Wd, Wn, Wm
- /// </summary>
- public static uint ComputeCrc32C(uint crc, uint data) => ComputeCrc32C(crc, data);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha1.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha1.PlatformNotSupported.cs
deleted file mode 100644
index 685000e4071..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha1.PlatformNotSupported.cs
+++ /dev/null
@@ -1,62 +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.
-
-#pragma warning disable IDE0060 // unused parameters
-using System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM SHA1 hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Sha1 : ArmBase
- {
- internal Sha1() { }
-
- public static new bool IsSupported { [Intrinsic] get => false; }
-
- /// <summary>
- /// uint32_t vsha1h_u32 (uint32_t hash_e)
- /// A32: SHA1H.32 Qd, Qm
- /// A64: SHA1H Sd, Sn
- /// </summary>
- public static uint FixedRotate(uint hash_e) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vsha1cq_u32 (uint32x4_t hash_abcd, uint32_t hash_e, uint32x4_t wk)
- /// A32: SHA1C.32 Qd, Qn, Qm
- /// A64: SHA1C Qd, Sn, Vm.4S
- /// </summary>
- public static Vector128<uint> HashUpdateChoose(Vector128<uint> hash_abcd, uint hash_e, Vector128<uint> wk) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vsha1mq_u32 (uint32x4_t hash_abcd, uint32_t hash_e, uint32x4_t wk)
- /// A32: SHA1M.32 Qd, Qn, Qm
- /// A64: SHA1M Qd, Sn, Vm.4S
- /// </summary>
- public static Vector128<uint> HashUpdateMajority(Vector128<uint> hash_abcd, uint hash_e, Vector128<uint> wk) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vsha1pq_u32 (uint32x4_t hash_abcd, uint32_t hash_e, uint32x4_t wk)
- /// A32: SHA1P.32 Qd, Qn, Qm
- /// A64: SHA1P Qd, Sn, Vm.4S
- /// </summary>
- public static Vector128<uint> HashUpdateParity(Vector128<uint> hash_abcd, uint hash_e, Vector128<uint> wk) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vsha1su0q_u32 (uint32x4_t w0_3, uint32x4_t w4_7, uint32x4_t w8_11)
- /// A32: SHA1SU0.32 Qd, Qn, Qm
- /// A64: SHA1SU0 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> ScheduleUpdate0(Vector128<uint> w0_3, Vector128<uint> w4_7, Vector128<uint> w8_11) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vsha1su1q_u32 (uint32x4_t tw0_3, uint32x4_t w12_15)
- /// A32: SHA1SU1.32 Qd, Qm
- /// A64: SHA1SU1 Vd.4S, Vn.4S
- /// </summary>
- public static Vector128<uint> ScheduleUpdate1(Vector128<uint> tw0_3, Vector128<uint> w12_15) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha1.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha1.cs
deleted file mode 100644
index d4d79a3cb89..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha1.cs
+++ /dev/null
@@ -1,62 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM SHA1 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Sha1 : ArmBase
- {
- internal Sha1() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// uint32_t vsha1h_u32 (uint32_t hash_e)
- /// A32: SHA1H.32 Qd, Qm
- /// A64: SHA1H Sd, Sn
- /// </summary>
- public static uint FixedRotate(uint hash_e) => FixedRotate(hash_e);
-
- /// <summary>
- /// uint32x4_t vsha1cq_u32 (uint32x4_t hash_abcd, uint32_t hash_e, uint32x4_t wk)
- /// A32: SHA1C.32 Qd, Qn, Qm
- /// A64: SHA1C Qd, Sn, Vm.4S
- /// </summary>
- public static Vector128<uint> HashUpdateChoose(Vector128<uint> hash_abcd, uint hash_e, Vector128<uint> wk) => HashUpdateChoose(hash_abcd, hash_e, wk);
-
- /// <summary>
- /// uint32x4_t vsha1mq_u32 (uint32x4_t hash_abcd, uint32_t hash_e, uint32x4_t wk)
- /// A32: SHA1M.32 Qd, Qn, Qm
- /// A64: SHA1M Qd, Sn, Vm.4S
- /// </summary>
- public static Vector128<uint> HashUpdateMajority(Vector128<uint> hash_abcd, uint hash_e, Vector128<uint> wk) => HashUpdateMajority(hash_abcd, hash_e, wk);
-
- /// <summary>
- /// uint32x4_t vsha1pq_u32 (uint32x4_t hash_abcd, uint32_t hash_e, uint32x4_t wk)
- /// A32: SHA1P.32 Qd, Qn, Qm
- /// A64: SHA1P Qd, Sn, Vm.4S
- /// </summary>
- public static Vector128<uint> HashUpdateParity(Vector128<uint> hash_abcd, uint hash_e, Vector128<uint> wk) => HashUpdateParity(hash_abcd, hash_e, wk);
-
- /// <summary>
- /// uint32x4_t vsha1su0q_u32 (uint32x4_t w0_3, uint32x4_t w4_7, uint32x4_t w8_11)
- /// A32: SHA1SU0.32 Qd, Qn, Qm
- /// A64: SHA1SU0 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> ScheduleUpdate0(Vector128<uint> w0_3, Vector128<uint> w4_7, Vector128<uint> w8_11) => ScheduleUpdate0(w0_3, w4_7, w8_11);
-
- /// <summary>
- /// uint32x4_t vsha1su1q_u32 (uint32x4_t tw0_3, uint32x4_t w12_15)
- /// A32: SHA1SU1.32 Qd, Qm
- /// A64: SHA1SU1 Vd.4S, Vn.4S
- /// </summary>
- public static Vector128<uint> ScheduleUpdate1(Vector128<uint> tw0_3, Vector128<uint> w12_15) => ScheduleUpdate1(tw0_3, w12_15);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha256.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha256.PlatformNotSupported.cs
deleted file mode 100644
index 7263b568a0b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha256.PlatformNotSupported.cs
+++ /dev/null
@@ -1,48 +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.
-
-#pragma warning disable IDE0060 // unused parameters
-using System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM SHA256 hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Sha256 : ArmBase
- {
- internal Sha256() { }
-
- public static new bool IsSupported { [Intrinsic] get => false; }
-
- /// <summary>
- /// uint32x4_t vsha256hq_u32 (uint32x4_t hash_abcd, uint32x4_t hash_efgh, uint32x4_t wk)
- /// A32: SHA256H.32 Qd, Qn, Qm
- /// A64: SHA256H Qd, Qn, Vm.4S
- /// </summary>
- public static Vector128<uint> HashUpdate1(Vector128<uint> hash_abcd, Vector128<uint> hash_efgh, Vector128<uint> wk) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vsha256h2q_u32 (uint32x4_t hash_efgh, uint32x4_t hash_abcd, uint32x4_t wk)
- /// A32: SHA256H2.32 Qd, Qn, Qm
- /// A64: SHA256H2 Qd, Qn, Vm.4S
- /// </summary>
- public static Vector128<uint> HashUpdate2(Vector128<uint> hash_efgh, Vector128<uint> hash_abcd, Vector128<uint> wk) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vsha256su0q_u32 (uint32x4_t w0_3, uint32x4_t w4_7)
- /// A32: SHA256SU0.32 Qd, Qm
- /// A64: SHA256SU0 Vd.4S, Vn.4S
- /// </summary>
- public static Vector128<uint> ScheduleUpdate0(Vector128<uint> w0_3, Vector128<uint> w4_7) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// uint32x4_t vsha256su1q_u32 (uint32x4_t w0_3, uint32x4_t w8_11, uint32x4_t w12_15)
- /// A32: SHA256SU1.32 Qd, Qn, Qm
- /// A64: SHA256SU1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> ScheduleUpdate1(Vector128<uint> w0_3, Vector128<uint> w8_11, Vector128<uint> w12_15) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha256.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha256.cs
deleted file mode 100644
index e57b01cb5db..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Arm/Sha256.cs
+++ /dev/null
@@ -1,48 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.Arm
-{
- /// <summary>
- /// This class provides access to the ARM SHA256 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Sha256 : ArmBase
- {
- internal Sha256() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// uint32x4_t vsha256hq_u32 (uint32x4_t hash_abcd, uint32x4_t hash_efgh, uint32x4_t wk)
- /// A32: SHA256H.32 Qd, Qn, Qm
- /// A64: SHA256H Qd, Qn, Vm.4S
- /// </summary>
- public static Vector128<uint> HashUpdate1(Vector128<uint> hash_abcd, Vector128<uint> hash_efgh, Vector128<uint> wk) => HashUpdate1(hash_abcd, hash_efgh, wk);
-
- /// <summary>
- /// uint32x4_t vsha256h2q_u32 (uint32x4_t hash_efgh, uint32x4_t hash_abcd, uint32x4_t wk)
- /// A32: SHA256H2.32 Qd, Qn, Qm
- /// A64: SHA256H2 Qd, Qn, Vm.4S
- /// </summary>
- public static Vector128<uint> HashUpdate2(Vector128<uint> hash_efgh, Vector128<uint> hash_abcd, Vector128<uint> wk) => HashUpdate2(hash_efgh, hash_abcd, wk);
-
- /// <summary>
- /// uint32x4_t vsha256su0q_u32 (uint32x4_t w0_3, uint32x4_t w4_7)
- /// A32: SHA256SU0.32 Qd, Qm
- /// A64: SHA256SU0 Vd.4S, Vn.4S
- /// </summary>
- public static Vector128<uint> ScheduleUpdate0(Vector128<uint> w0_3, Vector128<uint> w4_7) => ScheduleUpdate0(w0_3, w4_7);
-
- /// <summary>
- /// uint32x4_t vsha256su1q_u32 (uint32x4_t w0_3, uint32x4_t w8_11, uint32x4_t w12_15)
- /// A32: SHA256SU1.32 Qd, Qn, Qm
- /// A64: SHA256SU1 Vd.4S, Vn.4S, Vm.4S
- /// </summary>
- public static Vector128<uint> ScheduleUpdate1(Vector128<uint> w0_3, Vector128<uint> w8_11, Vector128<uint> w12_15) => ScheduleUpdate1(w0_3, w8_11, w12_15);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs
deleted file mode 100644
index a3ca363f06a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128.cs
+++ /dev/null
@@ -1,1859 +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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics.X86;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics
-{
- // We mark certain methods with AggressiveInlining to ensure that the JIT will
- // inline them. The JIT would otherwise not inline the method since it, at the
- // point it tries to determine inline profability, currently cannot determine
- // that most of the code-paths will be optimized away as "dead code".
- //
- // We then manually inline cases (such as certain intrinsic code-paths) that
- // will generate code small enough to make the AgressiveInlining profitable. The
- // other cases (such as the software fallback) are placed in their own method.
- // This ensures we get good codegen for the "fast-path" and allows the JIT to
- // determine inline profitability of the other paths as it would normally.
-
- // Many of the instance methods were moved to be extension methods as it results
- // in overall better codegen. This is because instance methods require the C# compiler
- // to generate extra locals as the `this` parameter has to be passed by reference.
- // Having them be extension methods means that the `this` parameter can be passed by
- // value instead, thus reducing the number of locals and helping prevent us from hitting
- // the internal inlining limits of the JIT.
-
- public static class Vector128
- {
- internal const int Size = 16;
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{U}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <typeparam name="U">The type of the vector <paramref name="vector" /> should be reinterpreted as.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector128{U}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) or the type of the target (<typeparamref name="U" />) is not supported.</exception>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector128<U> As<T, U>(this Vector128<T> vector)
- where T : struct
- where U : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- ThrowHelper.ThrowForUnsupportedVectorBaseType<U>();
- return Unsafe.As<Vector128<T>, Vector128<U>>(ref vector);
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{Byte}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector128{Byte}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector128<byte> AsByte<T>(this Vector128<T> vector)
- where T : struct
- {
- return vector.As<T, byte>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{Double}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector128{Double}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector128<double> AsDouble<T>(this Vector128<T> vector)
- where T : struct
- {
- return vector.As<T, double>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{Int16}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector128{Int16}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector128<short> AsInt16<T>(this Vector128<T> vector)
- where T : struct
- {
- return vector.As<T, short>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{Int32}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector128{Int32}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector128<int> AsInt32<T>(this Vector128<T> vector)
- where T : struct
- {
- return vector.As<T, int>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{Int64}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector128{Int64}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector128<long> AsInt64<T>(this Vector128<T> vector)
- where T : struct
- {
- return vector.As<T, long>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{SByte}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector128{SByte}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector128<sbyte> AsSByte<T>(this Vector128<T> vector)
- where T : struct
- {
- return vector.As<T, sbyte>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{Single}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector128{Single}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector128<float> AsSingle<T>(this Vector128<T> vector)
- where T : struct
- {
- return vector.As<T, float>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{UInt16}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector128{UInt16}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector128<ushort> AsUInt16<T>(this Vector128<T> vector)
- where T : struct
- {
- return vector.As<T, ushort>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{UInt32}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector128{UInt32}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector128<uint> AsUInt32<T>(this Vector128<T> vector)
- where T : struct
- {
- return vector.As<T, uint>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector128{UInt64}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector128{UInt64}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector128<ulong> AsUInt64<T>(this Vector128<T> vector)
- where T : struct
- {
- return vector.As<T, ulong>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector2" /> as a new <see cref="Vector128{Single}" />.</summary>
- /// <param name="value">The vector to reinterpret.</param>
- /// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector128{Single}" />.</returns>
- public static Vector128<float> AsVector128(this Vector2 value)
- {
- return new Vector4(value, 0.0f, 0.0f).AsVector128();
- }
-
- /// <summary>Reinterprets a <see cref="Vector3" /> as a new <see cref="Vector128{Single}" />.</summary>
- /// <param name="value">The vector to reinterpret.</param>
- /// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector128{Single}" />.</returns>
- public static Vector128<float> AsVector128(this Vector3 value)
- {
- return new Vector4(value, 0.0f).AsVector128();
- }
-
- /// <summary>Reinterprets a <see cref="Vector4" /> as a new <see cref="Vector128{Single}" />.</summary>
- /// <param name="value">The vector to reinterpret.</param>
- /// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector128{Single}" />.</returns>
- public static Vector128<float> AsVector128(this Vector4 value)
- {
- return Unsafe.As<Vector4, Vector128<float>>(ref value);
- }
-
- /// <summary>Reinterprets a <see cref="Vector{T}" /> as a new <see cref="Vector128{T}" />.</summary>
- /// <typeparam name="T">The type of the vectors.</typeparam>
- /// <param name="value">The vector to reinterpret.</param>
- /// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector128{T}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="value" /> (<typeparamref name="T" />) is not supported.</exception>
- public static Vector128<T> AsVector128<T>(this Vector<T> value)
- where T : struct
- {
- Debug.Assert(Vector<T>.Count >= Vector128<T>.Count);
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Unsafe.As<Vector<T>, Vector128<T>>(ref value);
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{Single}" /> as a new <see cref="Vector2" />.</summary>
- /// <param name="value">The vector to reinterpret.</param>
- /// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector2" />.</returns>
- public static Vector2 AsVector2(this Vector128<float> value)
- {
- return Unsafe.As<Vector128<float>, Vector2>(ref value);
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{Single}" /> as a new <see cref="Vector3" />.</summary>
- /// <param name="value">The vector to reinterpret.</param>
- /// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector3" />.</returns>
- public static Vector3 AsVector3(this Vector128<float> value)
- {
- return Unsafe.As<Vector128<float>, Vector3>(ref value);
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{Single}" /> as a new <see cref="Vector4" />.</summary>
- /// <param name="value">The vector to reinterpret.</param>
- /// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector4" />.</returns>
- public static Vector4 AsVector4(this Vector128<float> value)
- {
- return Unsafe.As<Vector128<float>, Vector4>(ref value);
- }
-
- /// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector{T}" />.</summary>
- /// <typeparam name="T">The type of the vectors.</typeparam>
- /// <param name="value">The vector to reinterpret.</param>
- /// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector{T}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="value" /> (<typeparamref name="T" />) is not supported.</exception>
- public static Vector<T> AsVector<T>(this Vector128<T> value)
- where T : struct
- {
- Debug.Assert(Vector<T>.Count >= Vector128<T>.Count);
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- Vector<T> result = default;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector<T>, byte>(ref result), value);
- return result;
- }
-
- /// <summary>Creates a new <see cref="Vector128{Byte}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Byte}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<byte> Create(byte value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<byte> result = CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Avx2.BroadcastScalarToVector128(result); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- if (Ssse3.IsSupported)
- {
- Vector128<byte> result = CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Ssse3.Shuffle(result, Vector128<byte>.Zero); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- if (Sse2.IsSupported)
- {
- // We first unpack as bytes to duplicate value into the lower 2 bytes, then we treat it as a ushort and unpack again to duplicate those
- // bits into the lower 2 words, we can finally treat it as a uint and shuffle the lower dword to duplicate value across the entire result
-
- Vector128<byte> result = CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- result = Sse2.UnpackLow(result, result); // < v, v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- result = Sse2.UnpackLow(result.AsUInt16(), result.AsUInt16()).AsByte(); // < v, v, v, v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Sse2.Shuffle(result.AsUInt32(), 0x00).AsByte(); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector128<byte> SoftwareFallback(byte value)
- {
- byte* pResult = stackalloc byte[16]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector128<byte>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Double}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Double}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<double> Create(double value)
- {
- if (Sse3.IsSupported)
- {
- Vector128<double> result = CreateScalarUnsafe(value); // < v, ? >
- return Sse3.MoveAndDuplicate(result); // < v, v >
- }
-
- if (Sse2.IsSupported)
- {
- // Treating the value as a set of singles and emitting MoveLowToHigh is more efficient than dealing with the elements directly as double
- // However, we still need to check if Sse2 is supported since CreateScalarUnsafe needs it to for movsd, when value is not already in register
-
- Vector128<double> result = CreateScalarUnsafe(value); // < v, ? >
- return Sse.MoveLowToHigh(result.AsSingle(), result.AsSingle()).AsDouble(); // < v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector128<double> SoftwareFallback(double value)
- {
- double* pResult = stackalloc double[2]
- {
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector128<double>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int16}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int16}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<short> Create(short value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<short> result = CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ? >
- return Avx2.BroadcastScalarToVector128(result); // < v, v, v, v, v, v, v, v >
- }
-
- if (Sse2.IsSupported)
- {
- // We first unpack as ushort to duplicate value into the lower 2 words, then we can treat it as a uint and shuffle the lower dword to
- // duplicate value across the entire result
-
- Vector128<short> result = CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ? >
- result = Sse2.UnpackLow(result, result); // < v, v, ?, ?, ?, ?, ?, ? >
- return Sse2.Shuffle(result.AsInt32(), 0x00).AsInt16(); // < v, v, v, v, v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector128<short> SoftwareFallback(short value)
- {
- short* pResult = stackalloc short[8]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector128<short>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int32}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int32}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<int> Create(int value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<int> result = CreateScalarUnsafe(value); // < v, ?, ?, ? >
- return Avx2.BroadcastScalarToVector128(result); // < v, v, v, v >
- }
-
- if (Sse2.IsSupported)
- {
- Vector128<int> result = CreateScalarUnsafe(value); // < v, ?, ?, ? >
- return Sse2.Shuffle(result, 0x00); // < v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector128<int> SoftwareFallback(int value)
- {
- int* pResult = stackalloc int[4]
- {
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector128<int>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int64}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int64}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<long> Create(long value)
- {
- if (Sse2.X64.IsSupported)
- {
- if (Avx2.IsSupported)
- {
- Vector128<long> result = CreateScalarUnsafe(value); // < v, ? >
- return Avx2.BroadcastScalarToVector128(result); // < v, v >
- }
- else
- {
- Vector128<long> result = CreateScalarUnsafe(value); // < v, ? >
- return Sse2.UnpackLow(result, result); // < v, v >
- }
- }
-
- return SoftwareFallback(value);
-
- static Vector128<long> SoftwareFallback(long value)
- {
- long* pResult = stackalloc long[2]
- {
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector128<long>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{SByte}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{SByte}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<sbyte> Create(sbyte value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<sbyte> result = CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Avx2.BroadcastScalarToVector128(result); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- if (Ssse3.IsSupported)
- {
- Vector128<sbyte> result = CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Ssse3.Shuffle(result, Vector128<sbyte>.Zero); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- if (Sse2.IsSupported)
- {
- // We first unpack as bytes to duplicate value into the lower 2 bytes, then we treat it as a ushort and unpack again to duplicate those
- // bits into the lower 2 words, we can finally treat it as a uint and shuffle the lower dword to duplicate value across the entire result
-
- Vector128<sbyte> result = CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- result = Sse2.UnpackLow(result, result); // < v, v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- result = Sse2.UnpackLow(result.AsInt16(), result.AsInt16()).AsSByte(); // < v, v, v, v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Sse2.Shuffle(result.AsInt32(), 0x00).AsSByte(); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector128<sbyte> SoftwareFallback(sbyte value)
- {
- sbyte* pResult = stackalloc sbyte[16]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector128<sbyte>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Single}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Single}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<float> Create(float value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<float> result = CreateScalarUnsafe(value); // < v, ?, ?, ? >
- return Avx2.BroadcastScalarToVector128(result); // < v, v, v, v >
- }
-
- if (Avx.IsSupported)
- {
- Vector128<float> result = CreateScalarUnsafe(value); // < v, ?, ?, ? >
- return Avx.Permute(result, 0x00); // < v, v, v, v >
- }
-
- if (Sse.IsSupported)
- {
- Vector128<float> result = CreateScalarUnsafe(value); // < v, ?, ?, ? >
- return Sse.Shuffle(result, result, 0x00); // < v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector128<float> SoftwareFallback(float value)
- {
- float* pResult = stackalloc float[4]
- {
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector128<float>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt16}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt16}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<ushort> Create(ushort value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<ushort> result = CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ? >
- return Avx2.BroadcastScalarToVector128(result); // < v, v, v, v, v, v, v, v >
- }
-
- if (Sse2.IsSupported)
- {
- // We first unpack as ushort to duplicate value into the lower 2 words, then we can treat it as a uint and shuffle the lower dword to
- // duplicate value across the entire result
-
- Vector128<ushort> result = CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ? >
- result = Sse2.UnpackLow(result, result); // < v, v, ?, ?, ?, ?, ?, ? >
- return Sse2.Shuffle(result.AsUInt32(), 0x00).AsUInt16(); // < v, v, v, v, v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector128<ushort> SoftwareFallback(ushort value)
- {
- ushort* pResult = stackalloc ushort[8]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector128<ushort>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt32}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt32}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<uint> Create(uint value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<uint> result = CreateScalarUnsafe(value); // < v, ?, ?, ? >
- return Avx2.BroadcastScalarToVector128(result); // < v, v, v, v >
- }
-
- if (Sse2.IsSupported)
- {
- Vector128<uint> result = CreateScalarUnsafe(value); // < v, ?, ?, ? >
- return Sse2.Shuffle(result, 0x00); // < v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector128<uint> SoftwareFallback(uint value)
- {
- uint* pResult = stackalloc uint[4]
- {
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector128<uint>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt64}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt64}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<ulong> Create(ulong value)
- {
- if (Sse2.X64.IsSupported)
- {
- if (Avx2.IsSupported)
- {
- Vector128<ulong> result = CreateScalarUnsafe(value); // < v, ? >
- return Avx2.BroadcastScalarToVector128(result); // < v, v >
- }
- else
- {
- Vector128<ulong> result = CreateScalarUnsafe(value); // < v, ? >
- return Sse2.UnpackLow(result, result); // < v, v >
- }
- }
-
- return SoftwareFallback(value);
-
- static Vector128<ulong> SoftwareFallback(ulong value)
- {
- ulong* pResult = stackalloc ulong[2]
- {
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector128<ulong>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Byte}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <param name="e8">The value that element 8 will be initialized to.</param>
- /// <param name="e9">The value that element 9 will be initialized to.</param>
- /// <param name="e10">The value that element 10 will be initialized to.</param>
- /// <param name="e11">The value that element 11 will be initialized to.</param>
- /// <param name="e12">The value that element 12 will be initialized to.</param>
- /// <param name="e13">The value that element 13 will be initialized to.</param>
- /// <param name="e14">The value that element 14 will be initialized to.</param>
- /// <param name="e15">The value that element 15 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Byte}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<byte> Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7, byte e8, byte e9, byte e10, byte e11, byte e12, byte e13, byte e14, byte e15)
- {
- if (Sse41.IsSupported)
- {
- Vector128<byte> result = CreateScalarUnsafe(e0); // < 0, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e1, 1); // < 0, 1, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e2, 2); // < 0, 1, 2, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e3, 3); // < 0, 1, 2, 3, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e4, 4); // < 0, 1, 2, 3, 4, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e5, 5); // < 0, 1, 2, 3, 4, 5, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e6, 6); // < 0, 1, 2, 3, 4, 5, 6, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e7, 7); // < 0, 1, 2, 3, 4, 5, 6, 7, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e8, 8); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e9, 9); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e10, 10); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e11, 11); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e12, 12); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ??, ??, ?? >
- result = Sse41.Insert(result, e13, 13); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ??, ?? >
- result = Sse41.Insert(result, e14, 14); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ?? >
- return Sse41.Insert(result, e15, 15); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 >
- }
-
- if (Sse2.IsSupported)
- {
- // We deal with the elements in order, unpacking the ordered pairs of bytes into vectors. We then treat those vectors as ushort and
- // unpack them again, then again treating those results as uint, and a final time treating them as ulong. This efficiently gets all
- // bytes ordered into the result.
-
- Vector128<ushort> lo16, hi16;
- Vector128<uint> lo32, hi32;
- Vector128<ulong> lo64, hi64;
-
- lo16 = Sse2.UnpackLow(CreateScalarUnsafe(e0), CreateScalarUnsafe(e1)).AsUInt16(); // < 0, 1, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi16 = Sse2.UnpackLow(CreateScalarUnsafe(e2), CreateScalarUnsafe(e3)).AsUInt16(); // < 2, 3, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- lo32 = Sse2.UnpackLow(lo16, hi16).AsUInt32(); // < 0, 1, 2, 3, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- lo16 = Sse2.UnpackLow(CreateScalarUnsafe(e4), CreateScalarUnsafe(e5)).AsUInt16(); // < 4, 5, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi16 = Sse2.UnpackLow(CreateScalarUnsafe(e6), CreateScalarUnsafe(e7)).AsUInt16(); // < 6, 7, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi32 = Sse2.UnpackLow(lo16, hi16).AsUInt32(); // < 4, 5, 6, 7, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- lo64 = Sse2.UnpackLow(lo32, hi32).AsUInt64(); // < 0, 1, 2, 3, 4, 5, 6, 7, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- lo16 = Sse2.UnpackLow(CreateScalarUnsafe(e8), CreateScalarUnsafe(e9)).AsUInt16(); // < 8, 9, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi16 = Sse2.UnpackLow(CreateScalarUnsafe(e10), CreateScalarUnsafe(e11)).AsUInt16(); // < 10, 11, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- lo32 = Sse2.UnpackLow(lo16, hi16).AsUInt32(); // < 8, 9, 10, 11, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- lo16 = Sse2.UnpackLow(CreateScalarUnsafe(e12), CreateScalarUnsafe(e13)).AsUInt16(); // < 12, 13, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi16 = Sse2.UnpackLow(CreateScalarUnsafe(e14), CreateScalarUnsafe(e15)).AsUInt16(); // < 14, 15, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi32 = Sse2.UnpackLow(lo16, hi16).AsUInt32(); // < 12, 13, 14, 15, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- hi64 = Sse2.UnpackLow(lo32, hi32).AsUInt64(); // < 8, 9, 10, 11, 12, 13, 14, 15, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- return Sse2.UnpackLow(lo64, hi64).AsByte(); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 >
- }
-
- return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15);
-
- static Vector128<byte> SoftwareFallback(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7, byte e8, byte e9, byte e10, byte e11, byte e12, byte e13, byte e14, byte e15)
- {
- byte* pResult = stackalloc byte[16]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- e8,
- e9,
- e10,
- e11,
- e12,
- e13,
- e14,
- e15,
- };
-
- return Unsafe.AsRef<Vector128<byte>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Double}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Double}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<double> Create(double e0, double e1)
- {
- if (Sse2.IsSupported)
- {
- // Treating the value as a set of singles and emitting MoveLowToHigh is more efficient than dealing with the elements directly as double
- // However, we still need to check if Sse2 is supported since CreateScalarUnsafe needs it to for movsd, when value is not already in register
-
- return Sse.MoveLowToHigh(CreateScalarUnsafe(e0).AsSingle(), CreateScalarUnsafe(e1).AsSingle()).AsDouble();
- }
-
- return SoftwareFallback(e0, e1);
-
- static Vector128<double> SoftwareFallback(double e0, double e1)
- {
- double* pResult = stackalloc double[2]
- {
- e0,
- e1,
- };
-
- return Unsafe.AsRef<Vector128<double>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int16}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int16}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<short> Create(short e0, short e1, short e2, short e3, short e4, short e5, short e6, short e7)
- {
- if (Sse2.IsSupported)
- {
- Vector128<short> result = CreateScalarUnsafe(e0); // < 0, ?, ?, ?, ?, ?, ?, ? >
- result = Sse2.Insert(result, e1, 1); // < 0, 1, ?, ?, ?, ?, ?, ? >
- result = Sse2.Insert(result, e2, 2); // < 0, 1, 2, ?, ?, ?, ?, ? >
- result = Sse2.Insert(result, e3, 3); // < 0, 1, 2, 3, ?, ?, ?, ? >
- result = Sse2.Insert(result, e4, 4); // < 0, 1, 2, 3, 4, ?, ?, ? >
- result = Sse2.Insert(result, e5, 5); // < 0, 1, 2, 3, 4, 5, ?, ? >
- result = Sse2.Insert(result, e6, 6); // < 0, 1, 2, 3, 4, 5, 6, ? >
- return Sse2.Insert(result, e7, 7); // < 0, 1, 2, 3, 4, 5, 6, 7 >
- }
-
- return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7);
-
- static Vector128<short> SoftwareFallback(short e0, short e1, short e2, short e3, short e4, short e5, short e6, short e7)
- {
- short* pResult = stackalloc short[8]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- };
-
- return Unsafe.AsRef<Vector128<short>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int32}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int32}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<int> Create(int e0, int e1, int e2, int e3)
- {
- if (Sse41.IsSupported)
- {
- Vector128<int> result = CreateScalarUnsafe(e0); // < 0, ?, ?, ? >
- result = Sse41.Insert(result, e1, 1); // < 0, 1, ?, ? >
- result = Sse41.Insert(result, e2, 2); // < 0, 1, 2, ? >
- return Sse41.Insert(result, e3, 3); // < 0, 1, 2, 3 >
- }
-
- if (Sse2.IsSupported)
- {
- // We deal with the elements in order, unpacking the ordered pairs of int into vectors. We then treat those vectors as ulong and
- // unpack them again. This efficiently gets all ints ordered into the result.
-
- Vector128<long> lo64, hi64;
- lo64 = Sse2.UnpackLow(CreateScalarUnsafe(e0), CreateScalarUnsafe(e1)).AsInt64(); // < 0, 1, ?, ? >
- hi64 = Sse2.UnpackLow(CreateScalarUnsafe(e2), CreateScalarUnsafe(e3)).AsInt64(); // < 2, 3, ?, ? >
- return Sse2.UnpackLow(lo64, hi64).AsInt32(); // < 0, 1, 2, 3 >
- }
-
- return SoftwareFallback(e0, e1, e2, e3);
-
- static Vector128<int> SoftwareFallback(int e0, int e1, int e2, int e3)
- {
- int* pResult = stackalloc int[4]
- {
- e0,
- e1,
- e2,
- e3,
- };
-
- return Unsafe.AsRef<Vector128<int>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int64}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int64}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<long> Create(long e0, long e1)
- {
- if (Sse41.X64.IsSupported)
- {
- Vector128<long> result = CreateScalarUnsafe(e0); // < 0, ? >
- return Sse41.X64.Insert(result, e1, 1); // < 0, 1 >
- }
-
- if (Sse2.X64.IsSupported)
- {
- return Sse2.UnpackLow(CreateScalarUnsafe(e0), CreateScalarUnsafe(e1)); // < 0, 1 >
- }
-
- return SoftwareFallback(e0, e1);
-
- static Vector128<long> SoftwareFallback(long e0, long e1)
- {
- long* pResult = stackalloc long[2]
- {
- e0,
- e1,
- };
-
- return Unsafe.AsRef<Vector128<long>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{SByte}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <param name="e8">The value that element 8 will be initialized to.</param>
- /// <param name="e9">The value that element 9 will be initialized to.</param>
- /// <param name="e10">The value that element 10 will be initialized to.</param>
- /// <param name="e11">The value that element 11 will be initialized to.</param>
- /// <param name="e12">The value that element 12 will be initialized to.</param>
- /// <param name="e13">The value that element 13 will be initialized to.</param>
- /// <param name="e14">The value that element 14 will be initialized to.</param>
- /// <param name="e15">The value that element 15 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{SByte}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<sbyte> Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7, sbyte e8, sbyte e9, sbyte e10, sbyte e11, sbyte e12, sbyte e13, sbyte e14, sbyte e15)
- {
- if (Sse41.IsSupported)
- {
- Vector128<sbyte> result = CreateScalarUnsafe(e0); // < 0, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e1, 1); // < 0, 1, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e2, 2); // < 0, 1, 2, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e3, 3); // < 0, 1, 2, 3, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e4, 4); // < 0, 1, 2, 3, 4, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e5, 5); // < 0, 1, 2, 3, 4, 5, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e6, 6); // < 0, 1, 2, 3, 4, 5, 6, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e7, 7); // < 0, 1, 2, 3, 4, 5, 6, 7, ??, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e8, 8); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, ??, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e9, 9); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ??, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e10, 10); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ??, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e11, 11); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ??, ??, ??, ?? >
- result = Sse41.Insert(result, e12, 12); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ??, ??, ?? >
- result = Sse41.Insert(result, e13, 13); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ??, ?? >
- result = Sse41.Insert(result, e14, 14); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ?? >
- return Sse41.Insert(result, e15, 15); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 >
- }
-
- if (Sse2.IsSupported)
- {
- // We deal with the elements in order, unpacking the ordered pairs of bytes into vectors. We then treat those vectors as ushort and
- // unpack them again, then again treating those results as uint, and a final time treating them as ulong. This efficiently gets all
- // bytes ordered into the result.
-
- Vector128<short> lo16, hi16;
- Vector128<int> lo32, hi32;
- Vector128<long> lo64, hi64;
-
- lo16 = Sse2.UnpackLow(CreateScalarUnsafe(e0), CreateScalarUnsafe(e1)).AsInt16(); // < 0, 1, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi16 = Sse2.UnpackLow(CreateScalarUnsafe(e2), CreateScalarUnsafe(e3)).AsInt16(); // < 2, 3, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- lo32 = Sse2.UnpackLow(lo16, hi16).AsInt32(); // < 0, 1, 2, 3, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- lo16 = Sse2.UnpackLow(CreateScalarUnsafe(e4), CreateScalarUnsafe(e5)).AsInt16(); // < 4, 5, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi16 = Sse2.UnpackLow(CreateScalarUnsafe(e6), CreateScalarUnsafe(e7)).AsInt16(); // < 6, 7, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi32 = Sse2.UnpackLow(lo16, hi16).AsInt32(); // < 4, 5, 6, 7, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- lo64 = Sse2.UnpackLow(lo32, hi32).AsInt64(); // < 0, 1, 2, 3, 4, 5, 6, 7, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- lo16 = Sse2.UnpackLow(CreateScalarUnsafe(e8), CreateScalarUnsafe(e9)).AsInt16(); // < 8, 9, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi16 = Sse2.UnpackLow(CreateScalarUnsafe(e10), CreateScalarUnsafe(e11)).AsInt16(); // < 10, 11, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- lo32 = Sse2.UnpackLow(lo16, hi16).AsInt32(); // < 8, 9, 10, 11, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- lo16 = Sse2.UnpackLow(CreateScalarUnsafe(e12), CreateScalarUnsafe(e13)).AsInt16(); // < 12, 13, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi16 = Sse2.UnpackLow(CreateScalarUnsafe(e14), CreateScalarUnsafe(e15)).AsInt16(); // < 14, 15, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
- hi32 = Sse2.UnpackLow(lo16, hi16).AsInt32(); // < 12, 13, 14, 15, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- hi64 = Sse2.UnpackLow(lo32, hi32).AsInt64(); // < 8, 9, 10, 11, 12, 13, 14, 15, ??, ??, ??, ??, ??, ??, ??, ?? >
-
- return Sse2.UnpackLow(lo64, hi64).AsSByte(); // < 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 >
- }
-
- return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15);
-
- static Vector128<sbyte> SoftwareFallback(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7, sbyte e8, sbyte e9, sbyte e10, sbyte e11, sbyte e12, sbyte e13, sbyte e14, sbyte e15)
- {
- sbyte* pResult = stackalloc sbyte[16]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- e8,
- e9,
- e10,
- e11,
- e12,
- e13,
- e14,
- e15,
- };
-
- return Unsafe.AsRef<Vector128<sbyte>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Single}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Single}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<float> Create(float e0, float e1, float e2, float e3)
- {
- if (Sse41.IsSupported)
- {
- Vector128<float> result = CreateScalarUnsafe(e0); // < 0, ?, ?, ? >
- result = Sse41.Insert(result, CreateScalarUnsafe(e1), 0x10); // < 0, 1, ?, ? >
- result = Sse41.Insert(result, CreateScalarUnsafe(e2), 0x20); // < 0, 1, 2, ? >
- return Sse41.Insert(result, CreateScalarUnsafe(e3), 0x30); // < 0, 1, 2, 3 >
- }
-
- if (Sse.IsSupported)
- {
- Vector128<float> lo64, hi64;
- lo64 = Sse.UnpackLow(CreateScalarUnsafe(e0), CreateScalarUnsafe(e1)); // < 0, 1, ?, ? >
- hi64 = Sse.UnpackLow(CreateScalarUnsafe(e2), CreateScalarUnsafe(e3)); // < 2, 3, ?, ? >
- return Sse.MoveLowToHigh(lo64, hi64); // < 0, 1, 2, 3 >
- }
-
- return SoftwareFallback(e0, e1, e2, e3);
-
- static Vector128<float> SoftwareFallback(float e0, float e1, float e2, float e3)
- {
- float* pResult = stackalloc float[4]
- {
- e0,
- e1,
- e2,
- e3,
- };
-
- return Unsafe.AsRef<Vector128<float>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt16}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt16}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<ushort> Create(ushort e0, ushort e1, ushort e2, ushort e3, ushort e4, ushort e5, ushort e6, ushort e7)
- {
- if (Sse2.IsSupported)
- {
- Vector128<ushort> result = CreateScalarUnsafe(e0); // < 0, ?, ?, ?, ?, ?, ?, ? >
- result = Sse2.Insert(result, e1, 1); // < 0, 1, ?, ?, ?, ?, ?, ? >
- result = Sse2.Insert(result, e2, 2); // < 0, 1, 2, ?, ?, ?, ?, ? >
- result = Sse2.Insert(result, e3, 3); // < 0, 1, 2, 3, ?, ?, ?, ? >
- result = Sse2.Insert(result, e4, 4); // < 0, 1, 2, 3, 4, ?, ?, ? >
- result = Sse2.Insert(result, e5, 5); // < 0, 1, 2, 3, 4, 5, ?, ? >
- result = Sse2.Insert(result, e6, 6); // < 0, 1, 2, 3, 4, 5, 6, ? >
- return Sse2.Insert(result, e7, 7); // < 0, 1, 2, 3, 4, 5, 6, 7 >
- }
-
- return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7);
-
- static Vector128<ushort> SoftwareFallback(ushort e0, ushort e1, ushort e2, ushort e3, ushort e4, ushort e5, ushort e6, ushort e7)
- {
- ushort* pResult = stackalloc ushort[8]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- };
-
- return Unsafe.AsRef<Vector128<ushort>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt32}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt32}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<uint> Create(uint e0, uint e1, uint e2, uint e3)
- {
- if (Sse41.IsSupported)
- {
- Vector128<uint> result = CreateScalarUnsafe(e0); // < 0, ?, ?, ? >
- result = Sse41.Insert(result, e1, 1); // < 0, 1, ?, ? >
- result = Sse41.Insert(result, e2, 2); // < 0, 1, 2, ? >
- return Sse41.Insert(result, e3, 3); // < 0, 1, 2, 3 >
- }
-
- if (Sse2.IsSupported)
- {
- // We deal with the elements in order, unpacking the ordered pairs of int into vectors. We then treat those vectors as ulong and
- // unpack them again. This efficiently gets all ints ordered into the result.
-
- Vector128<ulong> lo64, hi64;
- lo64 = Sse2.UnpackLow(CreateScalarUnsafe(e0), CreateScalarUnsafe(e1)).AsUInt64(); // < 0, 1, ?, ? >
- hi64 = Sse2.UnpackLow(CreateScalarUnsafe(e2), CreateScalarUnsafe(e3)).AsUInt64(); // < 2, 3, ?, ? >
- return Sse2.UnpackLow(lo64, hi64).AsUInt32(); // < 0, 1, 2, 3 >
- }
-
- return SoftwareFallback(e0, e1, e2, e3);
-
- static Vector128<uint> SoftwareFallback(uint e0, uint e1, uint e2, uint e3)
- {
- uint* pResult = stackalloc uint[4]
- {
- e0,
- e1,
- e2,
- e3,
- };
-
- return Unsafe.AsRef<Vector128<uint>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt64}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt64}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<ulong> Create(ulong e0, ulong e1)
- {
- if (Sse41.X64.IsSupported)
- {
- Vector128<ulong> result = CreateScalarUnsafe(e0); // < 0, ? >
- return Sse41.X64.Insert(result, e1, 1); // < 0, 1 >
- }
-
- if (Sse2.X64.IsSupported)
- {
- return Sse2.UnpackLow(CreateScalarUnsafe(e0), CreateScalarUnsafe(e1)); // < 0, 1 >
- }
-
- return SoftwareFallback(e0, e1);
-
- static Vector128<ulong> SoftwareFallback(ulong e0, ulong e1)
- {
- ulong* pResult = stackalloc ulong[2]
- {
- e0,
- e1,
- };
-
- return Unsafe.AsRef<Vector128<ulong>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Byte}" /> instance from two <see cref="Vector64{Byte}" /> instances.</summary>
- /// <param name="lower">The value that the lower 64-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 64-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Byte}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- public static unsafe Vector128<byte> Create(Vector64<byte> lower, Vector64<byte> upper)
- {
- Vector128<byte> result128 = Vector128<byte>.Zero;
-
- ref Vector64<byte> result64 = ref Unsafe.As<Vector128<byte>, Vector64<byte>>(ref result128);
- result64 = lower;
- Unsafe.Add(ref result64, 1) = upper;
-
- return result128;
- }
-
- /// <summary>Creates a new <see cref="Vector128{Double}" /> instance from two <see cref="Vector64{Double}" /> instances.</summary>
- /// <param name="lower">The value that the lower 64-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 64-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Double}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- public static unsafe Vector128<double> Create(Vector64<double> lower, Vector64<double> upper)
- {
- Vector128<double> result128 = Vector128<double>.Zero;
-
- ref Vector64<double> result64 = ref Unsafe.As<Vector128<double>, Vector64<double>>(ref result128);
- result64 = lower;
- Unsafe.Add(ref result64, 1) = upper;
-
- return result128;
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int16}" /> instance from two <see cref="Vector64{Int16}" /> instances.</summary>
- /// <param name="lower">The value that the lower 64-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 64-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int16}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- public static unsafe Vector128<short> Create(Vector64<short> lower, Vector64<short> upper)
- {
- Vector128<short> result128 = Vector128<short>.Zero;
-
- ref Vector64<short> result64 = ref Unsafe.As<Vector128<short>, Vector64<short>>(ref result128);
- result64 = lower;
- Unsafe.Add(ref result64, 1) = upper;
-
- return result128;
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int32}" /> instance from two <see cref="Vector64{Int32}" /> instances.</summary>
- /// <param name="lower">The value that the lower 64-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 64-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int32}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- public static unsafe Vector128<int> Create(Vector64<int> lower, Vector64<int> upper)
- {
- Vector128<int> result128 = Vector128<int>.Zero;
-
- ref Vector64<int> result64 = ref Unsafe.As<Vector128<int>, Vector64<int>>(ref result128);
- result64 = lower;
- Unsafe.Add(ref result64, 1) = upper;
-
- return result128;
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int64}" /> instance from two <see cref="Vector64{Int64}" /> instances.</summary>
- /// <param name="lower">The value that the lower 64-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 64-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int64}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- public static unsafe Vector128<long> Create(Vector64<long> lower, Vector64<long> upper)
- {
- Vector128<long> result128 = Vector128<long>.Zero;
-
- ref Vector64<long> result64 = ref Unsafe.As<Vector128<long>, Vector64<long>>(ref result128);
- result64 = lower;
- Unsafe.Add(ref result64, 1) = upper;
-
- return result128;
- }
-
- /// <summary>Creates a new <see cref="Vector128{SByte}" /> instance from two <see cref="Vector64{SByte}" /> instances.</summary>
- /// <param name="lower">The value that the lower 64-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 64-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{SByte}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector128<sbyte> Create(Vector64<sbyte> lower, Vector64<sbyte> upper)
- {
- Vector128<sbyte> result128 = Vector128<sbyte>.Zero;
-
- ref Vector64<sbyte> result64 = ref Unsafe.As<Vector128<sbyte>, Vector64<sbyte>>(ref result128);
- result64 = lower;
- Unsafe.Add(ref result64, 1) = upper;
-
- return result128;
- }
-
- /// <summary>Creates a new <see cref="Vector128{Single}" /> instance from two <see cref="Vector64{Single}" /> instances.</summary>
- /// <param name="lower">The value that the lower 64-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 64-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Single}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- public static unsafe Vector128<float> Create(Vector64<float> lower, Vector64<float> upper)
- {
- Vector128<float> result128 = Vector128<float>.Zero;
-
- ref Vector64<float> result64 = ref Unsafe.As<Vector128<float>, Vector64<float>>(ref result128);
- result64 = lower;
- Unsafe.Add(ref result64, 1) = upper;
-
- return result128;
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt16}" /> instance from two <see cref="Vector64{UInt16}" /> instances.</summary>
- /// <param name="lower">The value that the lower 64-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 64-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt16}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector128<ushort> Create(Vector64<ushort> lower, Vector64<ushort> upper)
- {
- Vector128<ushort> result128 = Vector128<ushort>.Zero;
-
- ref Vector64<ushort> result64 = ref Unsafe.As<Vector128<ushort>, Vector64<ushort>>(ref result128);
- result64 = lower;
- Unsafe.Add(ref result64, 1) = upper;
-
- return result128;
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt32}" /> instance from two <see cref="Vector64{UInt32}" /> instances.</summary>
- /// <param name="lower">The value that the lower 64-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 64-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt32}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector128<uint> Create(Vector64<uint> lower, Vector64<uint> upper)
- {
- Vector128<uint> result128 = Vector128<uint>.Zero;
-
- ref Vector64<uint> result64 = ref Unsafe.As<Vector128<uint>, Vector64<uint>>(ref result128);
- result64 = lower;
- Unsafe.Add(ref result64, 1) = upper;
-
- return result128;
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt64}" /> instance from two <see cref="Vector64{UInt64}" /> instances.</summary>
- /// <param name="lower">The value that the lower 64-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 64-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt64}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector128<ulong> Create(Vector64<ulong> lower, Vector64<ulong> upper)
- {
- Vector128<ulong> result128 = Vector128<ulong>.Zero;
-
- ref Vector64<ulong> result64 = ref Unsafe.As<Vector128<ulong>, Vector64<ulong>>(ref result128);
- result64 = lower;
- Unsafe.Add(ref result64, 1) = upper;
-
- return result128;
- }
-
- /// <summary>Creates a new <see cref="Vector128{Byte}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Byte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<byte> CreateScalar(byte value)
- {
- if (Sse2.IsSupported)
- {
- // ConvertScalarToVector128 only deals with 32/64-bit inputs and we need to ensure all upper-bits are zeroed, so we call
- // the UInt32 overload to ensure zero extension. We can then just treat the result as byte and return.
- return Sse2.ConvertScalarToVector128UInt32(value).AsByte();
- }
-
- return SoftwareFallback(value);
-
- static Vector128<byte> SoftwareFallback(byte value)
- {
- var result = Vector128<byte>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<byte>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Double}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Double}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<double> CreateScalar(double value)
- {
- if (Sse2.IsSupported)
- {
- return Sse2.MoveScalar(Vector128<double>.Zero, CreateScalarUnsafe(value));
- }
-
- return SoftwareFallback(value);
-
- static Vector128<double> SoftwareFallback(double value)
- {
- var result = Vector128<double>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<double>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int16}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<short> CreateScalar(short value)
- {
- if (Sse2.IsSupported)
- {
- // ConvertScalarToVector128 only deals with 32/64-bit inputs and we need to ensure all upper-bits are zeroed, so we cast
- // to ushort and call the UInt32 overload to ensure zero extension. We can then just treat the result as short and return.
- return Sse2.ConvertScalarToVector128UInt32((ushort)(value)).AsInt16();
- }
-
- return SoftwareFallback(value);
-
- static Vector128<short> SoftwareFallback(short value)
- {
- var result = Vector128<short>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<short>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int32}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<int> CreateScalar(int value)
- {
- if (Sse2.IsSupported)
- {
- return Sse2.ConvertScalarToVector128Int32(value);
- }
-
- return SoftwareFallback(value);
-
- static Vector128<int> SoftwareFallback(int value)
- {
- var result = Vector128<int>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<int>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int64}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- public static unsafe Vector128<long> CreateScalar(long value)
- {
- if (Sse2.X64.IsSupported)
- {
- return Sse2.X64.ConvertScalarToVector128Int64(value);
- }
-
- return SoftwareFallback(value);
-
- static Vector128<long> SoftwareFallback(long value)
- {
- var result = Vector128<long>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<long>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{SByte}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{SByte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<sbyte> CreateScalar(sbyte value)
- {
- if (Sse2.IsSupported)
- {
- // ConvertScalarToVector128 only deals with 32/64-bit inputs and we need to ensure all upper-bits are zeroed, so we cast
- // to byte and call the UInt32 overload to ensure zero extension. We can then just treat the result as sbyte and return.
- return Sse2.ConvertScalarToVector128UInt32((byte)(value)).AsSByte();
- }
-
- return SoftwareFallback(value);
-
- static Vector128<sbyte> SoftwareFallback(sbyte value)
- {
- var result = Vector128<sbyte>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<sbyte>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Single}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Single}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector128<float> CreateScalar(float value)
- {
- if (Sse.IsSupported)
- {
- return Sse.MoveScalar(Vector128<float>.Zero, CreateScalarUnsafe(value));
- }
-
- return SoftwareFallback(value);
-
- static Vector128<float> SoftwareFallback(float value)
- {
- var result = Vector128<float>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<float>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt16}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<ushort> CreateScalar(ushort value)
- {
- if (Sse2.IsSupported)
- {
- // ConvertScalarToVector128 only deals with 32/64-bit inputs and we need to ensure all upper-bits are zeroed, so we call
- // the UInt32 overload to ensure zero extension. We can then just treat the result as ushort and return.
- return Sse2.ConvertScalarToVector128UInt32(value).AsUInt16();
- }
-
- return SoftwareFallback(value);
-
- static Vector128<ushort> SoftwareFallback(ushort value)
- {
- var result = Vector128<ushort>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<ushort>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt32}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<uint> CreateScalar(uint value)
- {
- if (Sse2.IsSupported)
- {
- return Sse2.ConvertScalarToVector128UInt32(value);
- }
-
- return SoftwareFallback(value);
-
- static Vector128<uint> SoftwareFallback(uint value)
- {
- var result = Vector128<uint>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<uint>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt64}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector128<ulong> CreateScalar(ulong value)
- {
- if (Sse2.X64.IsSupported)
- {
- return Sse2.X64.ConvertScalarToVector128UInt64(value);
- }
-
- return SoftwareFallback(value);
-
- static Vector128<ulong> SoftwareFallback(ulong value)
- {
- var result = Vector128<ulong>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector128<ulong>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector128{Byte}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Byte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector128<byte> CreateScalarUnsafe(byte value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- byte* pResult = stackalloc byte[16];
- pResult[0] = value;
- return Unsafe.AsRef<Vector128<byte>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector128{Double}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Double}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector128<double> CreateScalarUnsafe(double value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- double* pResult = stackalloc double[2];
- pResult[0] = value;
- return Unsafe.AsRef<Vector128<double>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int16}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector128<short> CreateScalarUnsafe(short value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- short* pResult = stackalloc short[8];
- pResult[0] = value;
- return Unsafe.AsRef<Vector128<short>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int32}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector128<int> CreateScalarUnsafe(int value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- int* pResult = stackalloc int[4];
- pResult[0] = value;
- return Unsafe.AsRef<Vector128<int>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector128{Int64}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Int64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector128<long> CreateScalarUnsafe(long value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- long* pResult = stackalloc long[2];
- pResult[0] = value;
- return Unsafe.AsRef<Vector128<long>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector128{SByte}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{SByte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- [CLSCompliant(false)]
- public static unsafe Vector128<sbyte> CreateScalarUnsafe(sbyte value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- sbyte* pResult = stackalloc sbyte[16];
- pResult[0] = value;
- return Unsafe.AsRef<Vector128<sbyte>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector128{Single}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{Single}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector128<float> CreateScalarUnsafe(float value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- float* pResult = stackalloc float[4];
- pResult[0] = value;
- return Unsafe.AsRef<Vector128<float>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt16}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- [CLSCompliant(false)]
- public static unsafe Vector128<ushort> CreateScalarUnsafe(ushort value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- ushort* pResult = stackalloc ushort[8];
- pResult[0] = value;
- return Unsafe.AsRef<Vector128<ushort>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt32}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- [CLSCompliant(false)]
- public static unsafe Vector128<uint> CreateScalarUnsafe(uint value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- uint* pResult = stackalloc uint[4];
- pResult[0] = value;
- return Unsafe.AsRef<Vector128<uint>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector128{UInt64}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector128{UInt64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- [CLSCompliant(false)]
- public static unsafe Vector128<ulong> CreateScalarUnsafe(ulong value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- ulong* pResult = stackalloc ulong[2];
- pResult[0] = value;
- return Unsafe.AsRef<Vector128<ulong>>(pResult);
- }
-
- /// <summary>Gets the element at the specified index.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the element from.</param>
- /// <param name="index">The index of the element to get.</param>
- /// <returns>The value of the element at <paramref name="index" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index" /> was less than zero or greater than the number of elements.</exception>
- [Intrinsic]
- public static T GetElement<T>(this Vector128<T> vector, int index)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- if ((uint)(index) >= (uint)(Vector128<T>.Count))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index);
- }
-
- ref T e0 = ref Unsafe.As<Vector128<T>, T>(ref vector);
- return Unsafe.Add(ref e0, index);
- }
-
- /// <summary>Creates a new <see cref="Vector128{T}" /> with the element at the specified index set to the specified value and the remaining elements set to the same value as that in the given vector.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the remaining elements from.</param>
- /// <param name="index">The index of the element to set.</param>
- /// <param name="value">The value to set the element to.</param>
- /// <returns>A <see cref="Vector128{T}" /> with the value of the element at <paramref name="index" /> set to <paramref name="value" /> and the remaining elements set to the same value as that in <paramref name="vector" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index" /> was less than zero or greater than the number of elements.</exception>
- [Intrinsic]
- public static Vector128<T> WithElement<T>(this Vector128<T> vector, int index, T value)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- if ((uint)(index) >= (uint)(Vector128<T>.Count))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index);
- }
-
- Vector128<T> result = vector;
- ref T e0 = ref Unsafe.As<Vector128<T>, T>(ref result);
- Unsafe.Add(ref e0, index) = value;
- return result;
- }
-
- /// <summary>Gets the value of the lower 64-bits as a new <see cref="Vector64{T}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the lower 64-bits from.</param>
- /// <returns>The value of the lower 64-bits as a new <see cref="Vector64{T}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- public static Vector64<T> GetLower<T>(this Vector128<T> vector)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Unsafe.As<Vector128<T>, Vector64<T>>(ref vector);
- }
-
- /// <summary>Creates a new <see cref="Vector128{T}" /> with the lower 64-bits set to the specified value and the upper 64-bits set to the same value as that in the given vector.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the upper 64-bits from.</param>
- /// <param name="value">The value of the lower 64-bits as a <see cref="Vector64{T}" />.</param>
- /// <returns>A new <see cref="Vector128{T}" /> with the lower 64-bits set to <paramref name="value" /> and the upper 64-bits set to the same value as that in <paramref name="vector" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- public static Vector128<T> WithLower<T>(this Vector128<T> vector, Vector64<T> value)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- Vector128<T> result = vector;
- Unsafe.As<Vector128<T>, Vector64<T>>(ref result) = value;
- return result;
- }
-
- /// <summary>Gets the value of the upper 64-bits as a new <see cref="Vector64{T}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the upper 64-bits from.</param>
- /// <returns>The value of the upper 64-bits as a new <see cref="Vector64{T}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- public static Vector64<T> GetUpper<T>(this Vector128<T> vector)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- ref Vector64<T> lower = ref Unsafe.As<Vector128<T>, Vector64<T>>(ref vector);
- return Unsafe.Add(ref lower, 1);
- }
-
- /// <summary>Creates a new <see cref="Vector128{T}" /> with the upper 64-bits set to the specified value and the upper 64-bits set to the same value as that in the given vector.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the lower 64-bits from.</param>
- /// <param name="value">The value of the upper 64-bits as a <see cref="Vector64{T}" />.</param>
- /// <returns>A new <see cref="Vector128{T}" /> with the upper 64-bits set to <paramref name="value" /> and the lower 64-bits set to the same value as that in <paramref name="vector" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- public static Vector128<T> WithUpper<T>(this Vector128<T> vector, Vector64<T> value)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- Vector128<T> result = vector;
- ref Vector64<T> lower = ref Unsafe.As<Vector128<T>, Vector64<T>>(ref result);
- Unsafe.Add(ref lower, 1) = value;
- return result;
- }
-
- /// <summary>Converts the given vector to a scalar containing the value of the first element.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the first element from.</param>
- /// <returns>A scalar <typeparamref name="T" /> containing the value of the first element.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static T ToScalar<T>(this Vector128<T> vector)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Unsafe.As<Vector128<T>, T>(ref vector);
- }
-
- /// <summary>Converts the given vector to a new <see cref="Vector256{T}" /> with the lower 128-bits set to the value of the given vector and the upper 128-bits initialized to zero.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to extend.</param>
- /// <returns>A new <see cref="Vector256{T}" /> with the lower 128-bits set to the value of <paramref name="vector" /> and the upper 128-bits initialized to zero.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector256<T> ToVector256<T>(this Vector128<T> vector)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- Vector256<T> result = Vector256<T>.Zero;
- Unsafe.As<Vector256<T>, Vector128<T>>(ref result) = vector;
- return result;
- }
-
- /// <summary>Converts the given vector to a new <see cref="Vector256{T}" /> with the lower 128-bits set to the value of the given vector and the upper 128-bits left uninitialized.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to extend.</param>
- /// <returns>A new <see cref="Vector256{T}" /> with the lower 128-bits set to the value of <paramref name="vector" /> and the upper 128-bits left uninitialized.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static unsafe Vector256<T> ToVector256Unsafe<T>(this Vector128<T> vector)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- byte* pResult = stackalloc byte[Vector256.Size];
- Unsafe.AsRef<Vector128<T>>(pResult) = vector;
- return Unsafe.AsRef<Vector256<T>>(pResult);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128DebugView_1.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128DebugView_1.cs
deleted file mode 100644
index ccdc655949c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128DebugView_1.cs
+++ /dev/null
@@ -1,118 +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 Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics
-{
- internal readonly struct Vector128DebugView<T> where T : struct
- {
- private readonly Vector128<T> _value;
-
- public Vector128DebugView(Vector128<T> value)
- {
- _value = value;
- }
-
- public byte[] ByteView
- {
- get
- {
- var items = new byte[16];
- Unsafe.WriteUnaligned(ref items[0], _value);
- return items;
- }
- }
-
- public double[] DoubleView
- {
- get
- {
- var items = new double[2];
- Unsafe.WriteUnaligned(ref Unsafe.As<double, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public short[] Int16View
- {
- get
- {
- var items = new short[8];
- Unsafe.WriteUnaligned(ref Unsafe.As<short, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public int[] Int32View
- {
- get
- {
- var items = new int[4];
- Unsafe.WriteUnaligned(ref Unsafe.As<int, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public long[] Int64View
- {
- get
- {
- var items = new long[2];
- Unsafe.WriteUnaligned(ref Unsafe.As<long, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public sbyte[] SByteView
- {
- get
- {
- var items = new sbyte[16];
- Unsafe.WriteUnaligned(ref Unsafe.As<sbyte, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public float[] SingleView
- {
- get
- {
- var items = new float[4];
- Unsafe.WriteUnaligned(ref Unsafe.As<float, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public ushort[] UInt16View
- {
- get
- {
- var items = new ushort[8];
- Unsafe.WriteUnaligned(ref Unsafe.As<ushort, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public uint[] UInt32View
- {
- get
- {
- var items = new uint[4];
- Unsafe.WriteUnaligned(ref Unsafe.As<uint, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public ulong[] UInt64View
- {
- get
- {
- var items = new ulong[2];
- Unsafe.WriteUnaligned(ref Unsafe.As<ulong, byte>(ref items[0]), _value);
- return items;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs
deleted file mode 100644
index 46c93235eeb..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector128_1.cs
+++ /dev/null
@@ -1,192 +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 System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics.X86;
-using System.Text;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics
-{
- // We mark certain methods with AggressiveInlining to ensure that the JIT will
- // inline them. The JIT would otherwise not inline the method since it, at the
- // point it tries to determine inline profability, currently cannot determine
- // that most of the code-paths will be optimized away as "dead code".
- //
- // We then manually inline cases (such as certain intrinsic code-paths) that
- // will generate code small enough to make the AgressiveInlining profitable. The
- // other cases (such as the software fallback) are placed in their own method.
- // This ensures we get good codegen for the "fast-path" and allows the JIT to
- // determine inline profitability of the other paths as it would normally.
-
- [Intrinsic]
- [DebuggerDisplay("{DisplayString,nq}")]
- [DebuggerTypeProxy(typeof(Vector128DebugView<>))]
- [StructLayout(LayoutKind.Sequential, Size = Vector128.Size)]
- public readonly struct Vector128<T> : IEquatable<Vector128<T>>
- where T : struct
- {
- // These fields exist to ensure the alignment is 8, rather than 1.
- // This also allows the debug view to work https://github.com/dotnet/coreclr/issues/15694)
- private readonly ulong _00;
- private readonly ulong _01;
-
- /// <summary>Gets the number of <typeparamref name="T" /> that are in a <see cref="Vector128{T}" />.</summary>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public static int Count
- {
- [Intrinsic]
- get
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Vector128.Size / Unsafe.SizeOf<T>();
- }
- }
-
- /// <summary>Gets a new <see cref="Vector128{T}" /> with all elements initialized to zero.</summary>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public static Vector128<T> Zero
- {
- [Intrinsic]
- get
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return default;
- }
- }
-
- internal unsafe string DisplayString
- {
- get
- {
- if (IsSupported)
- {
- return ToString();
- }
- else
- {
- return SR.NotSupported_Type;
- }
- }
- }
-
- internal static bool IsSupported
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => (typeof(T) == typeof(byte)) ||
- (typeof(T) == typeof(sbyte)) ||
- (typeof(T) == typeof(short)) ||
- (typeof(T) == typeof(ushort)) ||
- (typeof(T) == typeof(int)) ||
- (typeof(T) == typeof(uint)) ||
- (typeof(T) == typeof(long)) ||
- (typeof(T) == typeof(ulong)) ||
- (typeof(T) == typeof(float)) ||
- (typeof(T) == typeof(double));
- }
-
- /// <summary>Determines whether the specified <see cref="Vector128{T}" /> is equal to the current instance.</summary>
- /// <param name="other">The <see cref="Vector128{T}" /> to compare with the current instance.</param>
- /// <returns><c>true</c> if <paramref name="other" /> is equal to the current instance; otherwise, <c>false</c>.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool Equals(Vector128<T> other)
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- if (Sse.IsSupported && (typeof(T) == typeof(float)))
- {
- Vector128<float> result = Sse.CompareEqual(this.AsSingle(), other.AsSingle());
- return Sse.MoveMask(result) == 0b1111; // We have one bit per element
- }
-
- if (Sse2.IsSupported)
- {
- if (typeof(T) == typeof(double))
- {
- Vector128<double> result = Sse2.CompareEqual(this.AsDouble(), other.AsDouble());
- return Sse2.MoveMask(result) == 0b11; // We have one bit per element
- }
- else
- {
- // Unlike float/double, there are no special values to consider
- // for integral types and we can just do a comparison that all
- // bytes are exactly the same.
-
- Debug.Assert((typeof(T) != typeof(float)) && (typeof(T) != typeof(double)));
- Vector128<byte> result = Sse2.CompareEqual(this.AsByte(), other.AsByte());
- return Sse2.MoveMask(result) == 0b1111_1111_1111_1111; // We have one bit per element
- }
- }
-
- return SoftwareFallback(in this, other);
-
- static bool SoftwareFallback(in Vector128<T> vector, Vector128<T> other)
- {
- for (int i = 0; i < Count; i++)
- {
- if (!((IEquatable<T>)(vector.GetElement(i))).Equals(other.GetElement(i)))
- {
- return false;
- }
- }
-
- return true;
- }
- }
-
- /// <summary>Determines whether the specified object is equal to the current instance.</summary>
- /// <param name="obj">The object to compare with the current instance.</param>
- /// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Vector128{T}" /> and is equal to the current instance; otherwise, <c>false</c>.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public override bool Equals(object? obj)
- {
- return (obj is Vector128<T>) && Equals((Vector128<T>)(obj));
- }
-
- /// <summary>Gets the hash code for the instance.</summary>
- /// <returns>The hash code for the instance.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public override int GetHashCode()
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- int hashCode = 0;
-
- for (int i = 0; i < Count; i++)
- {
- hashCode = HashCode.Combine(hashCode, this.GetElement(i).GetHashCode());
- }
-
- return hashCode;
- }
-
- /// <summary>Converts the current instance to an equivalent string representation.</summary>
- /// <returns>An equivalent string representation of the current instance.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public override string ToString()
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- int lastElement = Count - 1;
- var sb = new ValueStringBuilder(stackalloc char[64]);
- CultureInfo invariant = CultureInfo.InvariantCulture;
-
- sb.Append('<');
- for (int i = 0; i < lastElement; i++)
- {
- sb.Append(((IFormattable)this.GetElement(i)).ToString("G", invariant));
- sb.Append(',');
- sb.Append(' ');
- }
- sb.Append(((IFormattable)this.GetElement(lastElement)).ToString("G", invariant));
- sb.Append('>');
-
- return sb.ToString();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs
deleted file mode 100644
index 07023b5cc69..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs
+++ /dev/null
@@ -1,1962 +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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics.X86;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics
-{
- // We mark certain methods with AggressiveInlining to ensure that the JIT will
- // inline them. The JIT would otherwise not inline the method since it, at the
- // point it tries to determine inline profability, currently cannot determine
- // that most of the code-paths will be optimized away as "dead code".
- //
- // We then manually inline cases (such as certain intrinsic code-paths) that
- // will generate code small enough to make the AgressiveInlining profitable. The
- // other cases (such as the software fallback) are placed in their own method.
- // This ensures we get good codegen for the "fast-path" and allows the JIT to
- // determine inline profitability of the other paths as it would normally.
-
- // Many of the instance methods were moved to be extension methods as it results
- // in overall better codegen. This is because instance methods require the C# compiler
- // to generate extra locals as the `this` parameter has to be passed by reference.
- // Having them be extension methods means that the `this` parameter can be passed by
- // value instead, thus reducing the number of locals and helping prevent us from hitting
- // the internal inlining limits of the JIT.
-
- public static class Vector256
- {
- internal const int Size = 32;
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{U}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <typeparam name="U">The type of the vector <paramref name="vector" /> should be reinterpreted as.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector256{U}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) or the type of the target (<typeparamref name="U" />) is not supported.</exception>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector256<U> As<T, U>(this Vector256<T> vector)
- where T : struct
- where U : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- ThrowHelper.ThrowForUnsupportedVectorBaseType<U>();
- return Unsafe.As<Vector256<T>, Vector256<U>>(ref vector);
- }
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{Byte}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector256{Byte}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector256<byte> AsByte<T>(this Vector256<T> vector)
- where T : struct
- {
- return vector.As<T, byte>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{Double}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector256{Double}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector256<double> AsDouble<T>(this Vector256<T> vector)
- where T : struct
- {
- return vector.As<T, double>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{Int16}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector256{Int16}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector256<short> AsInt16<T>(this Vector256<T> vector)
- where T : struct
- {
- return vector.As<T, short>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{Int32}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector256{Int32}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector256<int> AsInt32<T>(this Vector256<T> vector)
- where T : struct
- {
- return vector.As<T, int>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{Int64}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector256{Int64}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector256<long> AsInt64<T>(this Vector256<T> vector)
- where T : struct
- {
- return vector.As<T, long>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{SByte}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector256{SByte}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector256<sbyte> AsSByte<T>(this Vector256<T> vector)
- where T : struct
- {
- return vector.As<T, sbyte>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{Single}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector256{Single}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector256<float> AsSingle<T>(this Vector256<T> vector)
- where T : struct
- {
- return vector.As<T, float>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{UInt16}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector256{UInt16}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector256<ushort> AsUInt16<T>(this Vector256<T> vector)
- where T : struct
- {
- return vector.As<T, ushort>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{UInt32}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector256{UInt32}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector256<uint> AsUInt32<T>(this Vector256<T> vector)
- where T : struct
- {
- return vector.As<T, uint>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector256{UInt64}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector256{UInt64}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector256<ulong> AsUInt64<T>(this Vector256<T> vector)
- where T : struct
- {
- return vector.As<T, ulong>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector{T}" /> as a new <see cref="Vector256{T}" />.</summary>
- /// <typeparam name="T">The type of the vectors.</typeparam>
- /// <param name="value">The vector to reinterpret.</param>
- /// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector256{T}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="value" /> (<typeparamref name="T" />) is not supported.</exception>
- public static Vector256<T> AsVector256<T>(this Vector<T> value)
- where T : struct
- {
- Debug.Assert(Vector256<T>.Count >= Vector<T>.Count);
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- Vector256<T> result = default;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<T>, byte>(ref result), value);
- return result;
- }
-
- /// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see cref="Vector{T}" />.</summary>
- /// <typeparam name="T">The type of the vectors.</typeparam>
- /// <param name="value">The vector to reinterpret.</param>
- /// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector{T}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="value" /> (<typeparamref name="T" />) is not supported.</exception>
- public static Vector<T> AsVector<T>(this Vector256<T> value)
- where T : struct
- {
- Debug.Assert(Vector256<T>.Count >= Vector<T>.Count);
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Unsafe.As<Vector256<T>, Vector<T>>(ref value);
- }
-
- /// <summary>Creates a new <see cref="Vector256{Byte}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Byte}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<byte> Create(byte value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<byte> result = Vector128.CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Avx2.BroadcastScalarToVector256(result); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- if (Avx.IsSupported)
- {
- Vector128<byte> result = Vector128.Create(value); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Avx.InsertVector128(result.ToVector256Unsafe(), result, 1); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector256<byte> SoftwareFallback(byte value)
- {
- byte* pResult = stackalloc byte[32]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector256<byte>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Double}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Double}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<double> Create(double value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<double> result = Vector128.CreateScalarUnsafe(value); // < v, ?, ?, ? >
- return Avx2.BroadcastScalarToVector256(result); // < v, v, v, v >
- }
-
- if (Avx.IsSupported)
- {
- Vector128<double> result = Vector128.Create(value); // < v, v, ?, ? >
- return Avx.InsertVector128(result.ToVector256Unsafe(), result, 1); // < v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector256<double> SoftwareFallback(double value)
- {
- double* pResult = stackalloc double[4]
- {
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector256<double>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int16}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int16}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<short> Create(short value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<short> result = Vector128.CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Avx2.BroadcastScalarToVector256(result); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- if (Avx.IsSupported)
- {
- Vector128<short> result = Vector128.Create(value); // < v, v, v, v, v, v, v, v, ?, ?, ?, ?, ?, ?, ?, ? >
- return Avx.InsertVector128(result.ToVector256Unsafe(), result, 1); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector256<short> SoftwareFallback(short value)
- {
- short* pResult = stackalloc short[16]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector256<short>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int32}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int32}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<int> Create(int value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<int> result = Vector128.CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ? >
- return Avx2.BroadcastScalarToVector256(result); // < v, v, v, v, v, v, v, v >
- }
-
- if (Avx.IsSupported)
- {
- Vector128<int> result = Vector128.Create(value); // < v, v, v, v, ?, ?, ?, ? >
- return Avx.InsertVector128(result.ToVector256Unsafe(), result, 1); // < v, v, v, v, v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector256<int> SoftwareFallback(int value)
- {
- int* pResult = stackalloc int[8]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector256<int>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int64}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int64}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<long> Create(long value)
- {
- if (Sse2.X64.IsSupported)
- {
- if (Avx2.IsSupported)
- {
- Vector128<long> result = Vector128.CreateScalarUnsafe(value); // < v, ?, ?, ? >
- return Avx2.BroadcastScalarToVector256(result); // < v, v, v, v >
- }
- else if (Avx.IsSupported)
- {
- Vector128<long> result = Vector128.Create(value); // < v, v, ?, ? >
- return Avx.InsertVector128(result.ToVector256Unsafe(), result, 1); // < v, v, v, v >
- }
- }
-
- return SoftwareFallback(value);
-
- static Vector256<long> SoftwareFallback(long value)
- {
- long* pResult = stackalloc long[4]
- {
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector256<long>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{SByte}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{SByte}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<sbyte> Create(sbyte value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<sbyte> result = Vector128.CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Avx2.BroadcastScalarToVector256(result); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- if (Avx.IsSupported)
- {
- Vector128<sbyte> result = Vector128.Create(value); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Avx.InsertVector128(result.ToVector256Unsafe(), result, 1); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector256<sbyte> SoftwareFallback(sbyte value)
- {
- sbyte* pResult = stackalloc sbyte[32]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector256<sbyte>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Single}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Single}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<float> Create(float value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<float> result = Vector128.CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ? >
- return Avx2.BroadcastScalarToVector256(result); // < v, v, v, v, v, v, v, v >
- }
-
- if (Avx.IsSupported)
- {
- Vector128<float> result = Vector128.Create(value); // < v, v, v, v, ?, ?, ?, ? >
- return Avx.InsertVector128(result.ToVector256Unsafe(), result, 1); // < v, v, v, v, v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector256<float> SoftwareFallback(float value)
- {
- float* pResult = stackalloc float[8]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector256<float>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt16}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt16}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<ushort> Create(ushort value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<ushort> result = Vector128.CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? >
- return Avx2.BroadcastScalarToVector256(result); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- if (Avx.IsSupported)
- {
- Vector128<ushort> result = Vector128.Create(value); // < v, v, v, v, v, v, v, v, ?, ?, ?, ?, ?, ?, ?, ? >
- return Avx.InsertVector128(result.ToVector256Unsafe(), result, 1); // < v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector256<ushort> SoftwareFallback(ushort value)
- {
- ushort* pResult = stackalloc ushort[16]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector256<ushort>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt32}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt32}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<uint> Create(uint value)
- {
- if (Avx2.IsSupported)
- {
- Vector128<uint> result = Vector128.CreateScalarUnsafe(value); // < v, ?, ?, ?, ?, ?, ?, ? >
- return Avx2.BroadcastScalarToVector256(result); // < v, v, v, v, v, v, v, v >
- }
-
- if (Avx.IsSupported)
- {
- Vector128<uint> result = Vector128.Create(value); // < v, v, v, v, ?, ?, ?, ? >
- return Avx.InsertVector128(result.ToVector256Unsafe(), result, 1); // < v, v, v, v, v, v, v, v >
- }
-
- return SoftwareFallback(value);
-
- static Vector256<uint> SoftwareFallback(uint value)
- {
- uint* pResult = stackalloc uint[8]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector256<uint>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt64}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt64}" /> with all elements initialized to <paramref name="value" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<ulong> Create(ulong value)
- {
- if (Sse2.X64.IsSupported)
- {
- if (Avx2.IsSupported)
- {
- Vector128<ulong> result = Vector128.CreateScalarUnsafe(value); // < v, ?, ?, ? >
- return Avx2.BroadcastScalarToVector256(result); // < v, v, v, v >
- }
- else if (Avx.IsSupported)
- {
- Vector128<ulong> result = Vector128.Create(value); // < v, v, ?, ? >
- return Avx.InsertVector128(result.ToVector256Unsafe(), result, 1); // < v, v, v, v >
- }
- }
-
- return SoftwareFallback(value);
-
- static Vector256<ulong> SoftwareFallback(ulong value)
- {
- ulong* pResult = stackalloc ulong[4]
- {
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector256<ulong>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Byte}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <param name="e8">The value that element 8 will be initialized to.</param>
- /// <param name="e9">The value that element 9 will be initialized to.</param>
- /// <param name="e10">The value that element 10 will be initialized to.</param>
- /// <param name="e11">The value that element 11 will be initialized to.</param>
- /// <param name="e12">The value that element 12 will be initialized to.</param>
- /// <param name="e13">The value that element 13 will be initialized to.</param>
- /// <param name="e14">The value that element 14 will be initialized to.</param>
- /// <param name="e15">The value that element 15 will be initialized to.</param>
- /// <param name="e16">The value that element 16 will be initialized to.</param>
- /// <param name="e17">The value that element 17 will be initialized to.</param>
- /// <param name="e18">The value that element 18 will be initialized to.</param>
- /// <param name="e19">The value that element 19 will be initialized to.</param>
- /// <param name="e20">The value that element 20 will be initialized to.</param>
- /// <param name="e21">The value that element 21 will be initialized to.</param>
- /// <param name="e22">The value that element 22 will be initialized to.</param>
- /// <param name="e23">The value that element 23 will be initialized to.</param>
- /// <param name="e24">The value that element 24 will be initialized to.</param>
- /// <param name="e25">The value that element 25 will be initialized to.</param>
- /// <param name="e26">The value that element 26 will be initialized to.</param>
- /// <param name="e27">The value that element 27 will be initialized to.</param>
- /// <param name="e28">The value that element 28 will be initialized to.</param>
- /// <param name="e29">The value that element 29 will be initialized to.</param>
- /// <param name="e30">The value that element 30 will be initialized to.</param>
- /// <param name="e31">The value that element 31 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Byte}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<byte> Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7, byte e8, byte e9, byte e10, byte e11, byte e12, byte e13, byte e14, byte e15, byte e16, byte e17, byte e18, byte e19, byte e20, byte e21, byte e22, byte e23, byte e24, byte e25, byte e26, byte e27, byte e28, byte e29, byte e30, byte e31)
- {
- if (Avx.IsSupported)
- {
- Vector128<byte> lo128 = Vector128.Create(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15);
- Vector128<byte> hi128 = Vector128.Create(e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31);
- return Create(lo128, hi128);
- }
-
- return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31);
-
- static Vector256<byte> SoftwareFallback(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7, byte e8, byte e9, byte e10, byte e11, byte e12, byte e13, byte e14, byte e15, byte e16, byte e17, byte e18, byte e19, byte e20, byte e21, byte e22, byte e23, byte e24, byte e25, byte e26, byte e27, byte e28, byte e29, byte e30, byte e31)
- {
- byte* pResult = stackalloc byte[32]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- e8,
- e9,
- e10,
- e11,
- e12,
- e13,
- e14,
- e15,
- e16,
- e17,
- e18,
- e19,
- e20,
- e21,
- e22,
- e23,
- e24,
- e25,
- e26,
- e27,
- e28,
- e29,
- e30,
- e31,
- };
-
- return Unsafe.AsRef<Vector256<byte>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Double}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Double}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<double> Create(double e0, double e1, double e2, double e3)
- {
- if (Avx.IsSupported)
- {
- Vector128<double> lo128 = Vector128.Create(e0, e1);
- Vector128<double> hi128 = Vector128.Create(e2, e3);
- return Create(lo128, hi128);
- }
-
- return SoftwareFallback(e0, e1, e2, e3);
-
- static Vector256<double> SoftwareFallback(double e0, double e1, double e2, double e3)
- {
- double* pResult = stackalloc double[4]
- {
- e0,
- e1,
- e2,
- e3,
- };
-
- return Unsafe.AsRef<Vector256<double>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int16}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <param name="e8">The value that element 8 will be initialized to.</param>
- /// <param name="e9">The value that element 9 will be initialized to.</param>
- /// <param name="e10">The value that element 10 will be initialized to.</param>
- /// <param name="e11">The value that element 11 will be initialized to.</param>
- /// <param name="e12">The value that element 12 will be initialized to.</param>
- /// <param name="e13">The value that element 13 will be initialized to.</param>
- /// <param name="e14">The value that element 14 will be initialized to.</param>
- /// <param name="e15">The value that element 15 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int16}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<short> Create(short e0, short e1, short e2, short e3, short e4, short e5, short e6, short e7, short e8, short e9, short e10, short e11, short e12, short e13, short e14, short e15)
- {
- if (Avx.IsSupported)
- {
- Vector128<short> lo128 = Vector128.Create(e0, e1, e2, e3, e4, e5, e6, e7);
- Vector128<short> hi128 = Vector128.Create(e8, e9, e10, e11, e12, e13, e14, e15);
- return Create(lo128, hi128);
- }
-
- return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15);
-
- static Vector256<short> SoftwareFallback(short e0, short e1, short e2, short e3, short e4, short e5, short e6, short e7, short e8, short e9, short e10, short e11, short e12, short e13, short e14, short e15)
- {
- short* pResult = stackalloc short[16]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- e8,
- e9,
- e10,
- e11,
- e12,
- e13,
- e14,
- e15,
- };
-
- return Unsafe.AsRef<Vector256<short>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int32}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int32}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<int> Create(int e0, int e1, int e2, int e3, int e4, int e5, int e6, int e7)
- {
- if (Avx.IsSupported)
- {
- Vector128<int> lo128 = Vector128.Create(e0, e1, e2, e3);
- Vector128<int> hi128 = Vector128.Create(e4, e5, e6, e7);
- return Create(lo128, hi128);
- }
-
- return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7);
-
- static Vector256<int> SoftwareFallback(int e0, int e1, int e2, int e3, int e4, int e5, int e6, int e7)
- {
- int* pResult = stackalloc int[8]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- };
-
- return Unsafe.AsRef<Vector256<int>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int64}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int64}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<long> Create(long e0, long e1, long e2, long e3)
- {
- if (Sse2.X64.IsSupported && Avx.IsSupported)
- {
- Vector128<long> lo128 = Vector128.Create(e0, e1);
- Vector128<long> hi128 = Vector128.Create(e2, e3);
- return Create(lo128, hi128);
- }
-
- return SoftwareFallback(e0, e1, e2, e3);
-
- static Vector256<long> SoftwareFallback(long e0, long e1, long e2, long e3)
- {
- long* pResult = stackalloc long[4]
- {
- e0,
- e1,
- e2,
- e3,
- };
-
- return Unsafe.AsRef<Vector256<long>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{SByte}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <param name="e8">The value that element 8 will be initialized to.</param>
- /// <param name="e9">The value that element 9 will be initialized to.</param>
- /// <param name="e10">The value that element 10 will be initialized to.</param>
- /// <param name="e11">The value that element 11 will be initialized to.</param>
- /// <param name="e12">The value that element 12 will be initialized to.</param>
- /// <param name="e13">The value that element 13 will be initialized to.</param>
- /// <param name="e14">The value that element 14 will be initialized to.</param>
- /// <param name="e15">The value that element 15 will be initialized to.</param>
- /// <param name="e16">The value that element 16 will be initialized to.</param>
- /// <param name="e17">The value that element 17 will be initialized to.</param>
- /// <param name="e18">The value that element 18 will be initialized to.</param>
- /// <param name="e19">The value that element 19 will be initialized to.</param>
- /// <param name="e20">The value that element 20 will be initialized to.</param>
- /// <param name="e21">The value that element 21 will be initialized to.</param>
- /// <param name="e22">The value that element 22 will be initialized to.</param>
- /// <param name="e23">The value that element 23 will be initialized to.</param>
- /// <param name="e24">The value that element 24 will be initialized to.</param>
- /// <param name="e25">The value that element 25 will be initialized to.</param>
- /// <param name="e26">The value that element 26 will be initialized to.</param>
- /// <param name="e27">The value that element 27 will be initialized to.</param>
- /// <param name="e28">The value that element 28 will be initialized to.</param>
- /// <param name="e29">The value that element 29 will be initialized to.</param>
- /// <param name="e30">The value that element 30 will be initialized to.</param>
- /// <param name="e31">The value that element 31 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{SByte}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<sbyte> Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7, sbyte e8, sbyte e9, sbyte e10, sbyte e11, sbyte e12, sbyte e13, sbyte e14, sbyte e15, sbyte e16, sbyte e17, sbyte e18, sbyte e19, sbyte e20, sbyte e21, sbyte e22, sbyte e23, sbyte e24, sbyte e25, sbyte e26, sbyte e27, sbyte e28, sbyte e29, sbyte e30, sbyte e31)
- {
- if (Avx.IsSupported)
- {
- Vector128<sbyte> lo128 = Vector128.Create(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15);
- Vector128<sbyte> hi128 = Vector128.Create(e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31);
- return Create(lo128, hi128);
- }
-
- return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31);
-
- static Vector256<sbyte> SoftwareFallback(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7, sbyte e8, sbyte e9, sbyte e10, sbyte e11, sbyte e12, sbyte e13, sbyte e14, sbyte e15, sbyte e16, sbyte e17, sbyte e18, sbyte e19, sbyte e20, sbyte e21, sbyte e22, sbyte e23, sbyte e24, sbyte e25, sbyte e26, sbyte e27, sbyte e28, sbyte e29, sbyte e30, sbyte e31)
- {
- sbyte* pResult = stackalloc sbyte[32]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- e8,
- e9,
- e10,
- e11,
- e12,
- e13,
- e14,
- e15,
- e16,
- e17,
- e18,
- e19,
- e20,
- e21,
- e22,
- e23,
- e24,
- e25,
- e26,
- e27,
- e28,
- e29,
- e30,
- e31,
- };
-
- return Unsafe.AsRef<Vector256<sbyte>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Single}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Single}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<float> Create(float e0, float e1, float e2, float e3, float e4, float e5, float e6, float e7)
- {
- if (Avx.IsSupported)
- {
- Vector128<float> lo128 = Vector128.Create(e0, e1, e2, e3);
- Vector128<float> hi128 = Vector128.Create(e4, e5, e6, e7);
- return Create(lo128, hi128);
- }
-
- return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7);
-
- static Vector256<float> SoftwareFallback(float e0, float e1, float e2, float e3, float e4, float e5, float e6, float e7)
- {
- float* pResult = stackalloc float[8]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- };
-
- return Unsafe.AsRef<Vector256<float>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt16}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <param name="e8">The value that element 8 will be initialized to.</param>
- /// <param name="e9">The value that element 9 will be initialized to.</param>
- /// <param name="e10">The value that element 10 will be initialized to.</param>
- /// <param name="e11">The value that element 11 will be initialized to.</param>
- /// <param name="e12">The value that element 12 will be initialized to.</param>
- /// <param name="e13">The value that element 13 will be initialized to.</param>
- /// <param name="e14">The value that element 14 will be initialized to.</param>
- /// <param name="e15">The value that element 15 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt16}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<ushort> Create(ushort e0, ushort e1, ushort e2, ushort e3, ushort e4, ushort e5, ushort e6, ushort e7, ushort e8, ushort e9, ushort e10, ushort e11, ushort e12, ushort e13, ushort e14, ushort e15)
- {
- if (Avx.IsSupported)
- {
- Vector128<ushort> lo128 = Vector128.Create(e0, e1, e2, e3, e4, e5, e6, e7);
- Vector128<ushort> hi128 = Vector128.Create(e8, e9, e10, e11, e12, e13, e14, e15);
- return Create(lo128, hi128);
- }
-
- return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15);
-
- static Vector256<ushort> SoftwareFallback(ushort e0, ushort e1, ushort e2, ushort e3, ushort e4, ushort e5, ushort e6, ushort e7, ushort e8, ushort e9, ushort e10, ushort e11, ushort e12, ushort e13, ushort e14, ushort e15)
- {
- ushort* pResult = stackalloc ushort[16]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- e8,
- e9,
- e10,
- e11,
- e12,
- e13,
- e14,
- e15,
- };
-
- return Unsafe.AsRef<Vector256<ushort>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt32}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt32}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<uint> Create(uint e0, uint e1, uint e2, uint e3, uint e4, uint e5, uint e6, uint e7)
- {
- if (Avx.IsSupported)
- {
- Vector128<uint> lo128 = Vector128.Create(e0, e1, e2, e3);
- Vector128<uint> hi128 = Vector128.Create(e4, e5, e6, e7);
- return Create(lo128, hi128);
- }
-
- return SoftwareFallback(e0, e1, e2, e3, e4, e5, e6, e7);
-
- static Vector256<uint> SoftwareFallback(uint e0, uint e1, uint e2, uint e3, uint e4, uint e5, uint e6, uint e7)
- {
- uint* pResult = stackalloc uint[8]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- };
-
- return Unsafe.AsRef<Vector256<uint>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt64}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt64}" /> with each element initialized to corresponding specified value.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<ulong> Create(ulong e0, ulong e1, ulong e2, ulong e3)
- {
- if (Sse2.X64.IsSupported && Avx.IsSupported)
- {
- Vector128<ulong> lo128 = Vector128.Create(e0, e1);
- Vector128<ulong> hi128 = Vector128.Create(e2, e3);
- return Create(lo128, hi128);
- }
-
- return SoftwareFallback(e0, e1, e2, e3);
-
- static Vector256<ulong> SoftwareFallback(ulong e0, ulong e1, ulong e2, ulong e3)
- {
- ulong* pResult = stackalloc ulong[4]
- {
- e0,
- e1,
- e2,
- e3,
- };
-
- return Unsafe.AsRef<Vector256<ulong>>(pResult);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Byte}" /> instance from two <see cref="Vector128{Byte}" /> instances.</summary>
- /// <param name="lower">The value that the lower 128-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 128-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Byte}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<byte> Create(Vector128<byte> lower, Vector128<byte> upper)
- {
- if (Avx.IsSupported)
- {
- Vector256<byte> result = lower.ToVector256Unsafe();
- return result.WithUpper(upper);
- }
-
- return SoftwareFallback(lower, upper);
-
- static Vector256<byte> SoftwareFallback(Vector128<byte> lower, Vector128<byte> upper)
- {
- Vector256<byte> result256 = Vector256<byte>.Zero;
-
- ref Vector128<byte> result128 = ref Unsafe.As<Vector256<byte>, Vector128<byte>>(ref result256);
- result128 = lower;
- Unsafe.Add(ref result128, 1) = upper;
-
- return result256;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Double}" /> instance from two <see cref="Vector128{Double}" /> instances.</summary>
- /// <param name="lower">The value that the lower 128-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 128-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Double}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<double> Create(Vector128<double> lower, Vector128<double> upper)
- {
- if (Avx.IsSupported)
- {
- Vector256<double> result = lower.ToVector256Unsafe();
- return result.WithUpper(upper);
- }
-
- return SoftwareFallback(lower, upper);
-
- static Vector256<double> SoftwareFallback(Vector128<double> lower, Vector128<double> upper)
- {
- Vector256<double> result256 = Vector256<double>.Zero;
-
- ref Vector128<double> result128 = ref Unsafe.As<Vector256<double>, Vector128<double>>(ref result256);
- result128 = lower;
- Unsafe.Add(ref result128, 1) = upper;
-
- return result256;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int16}" /> instance from two <see cref="Vector128{Int16}" /> instances.</summary>
- /// <param name="lower">The value that the lower 128-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 128-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int16}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<short> Create(Vector128<short> lower, Vector128<short> upper)
- {
- if (Avx.IsSupported)
- {
- Vector256<short> result = lower.ToVector256Unsafe();
- return result.WithUpper(upper);
- }
-
- return SoftwareFallback(lower, upper);
-
- static Vector256<short> SoftwareFallback(Vector128<short> lower, Vector128<short> upper)
- {
- Vector256<short> result256 = Vector256<short>.Zero;
-
- ref Vector128<short> result128 = ref Unsafe.As<Vector256<short>, Vector128<short>>(ref result256);
- result128 = lower;
- Unsafe.Add(ref result128, 1) = upper;
-
- return result256;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int32}" /> instance from two <see cref="Vector128{Int32}" /> instances.</summary>
- /// <param name="lower">The value that the lower 128-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 128-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int32}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<int> Create(Vector128<int> lower, Vector128<int> upper)
- {
- if (Avx.IsSupported)
- {
- Vector256<int> result = lower.ToVector256Unsafe();
- return result.WithUpper(upper);
- }
-
- return SoftwareFallback(lower, upper);
-
- static Vector256<int> SoftwareFallback(Vector128<int> lower, Vector128<int> upper)
- {
- Vector256<int> result256 = Vector256<int>.Zero;
-
- ref Vector128<int> result128 = ref Unsafe.As<Vector256<int>, Vector128<int>>(ref result256);
- result128 = lower;
- Unsafe.Add(ref result128, 1) = upper;
-
- return result256;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int64}" /> instance from two <see cref="Vector128{Int64}" /> instances.</summary>
- /// <param name="lower">The value that the lower 128-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 128-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int64}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<long> Create(Vector128<long> lower, Vector128<long> upper)
- {
- if (Avx.IsSupported)
- {
- Vector256<long> result = lower.ToVector256Unsafe();
- return result.WithUpper(upper);
- }
-
- return SoftwareFallback(lower, upper);
-
- static Vector256<long> SoftwareFallback(Vector128<long> lower, Vector128<long> upper)
- {
- Vector256<long> result256 = Vector256<long>.Zero;
-
- ref Vector128<long> result128 = ref Unsafe.As<Vector256<long>, Vector128<long>>(ref result256);
- result128 = lower;
- Unsafe.Add(ref result128, 1) = upper;
-
- return result256;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{SByte}" /> instance from two <see cref="Vector128{SByte}" /> instances.</summary>
- /// <param name="lower">The value that the lower 128-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 128-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{SByte}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<sbyte> Create(Vector128<sbyte> lower, Vector128<sbyte> upper)
- {
- if (Avx.IsSupported)
- {
- Vector256<sbyte> result = lower.ToVector256Unsafe();
- return result.WithUpper(upper);
- }
-
- return SoftwareFallback(lower, upper);
-
- static Vector256<sbyte> SoftwareFallback(Vector128<sbyte> lower, Vector128<sbyte> upper)
- {
- Vector256<sbyte> result256 = Vector256<sbyte>.Zero;
-
- ref Vector128<sbyte> result128 = ref Unsafe.As<Vector256<sbyte>, Vector128<sbyte>>(ref result256);
- result128 = lower;
- Unsafe.Add(ref result128, 1) = upper;
-
- return result256;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Single}" /> instance from two <see cref="Vector128{Single}" /> instances.</summary>
- /// <param name="lower">The value that the lower 128-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 128-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Single}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<float> Create(Vector128<float> lower, Vector128<float> upper)
- {
- if (Avx.IsSupported)
- {
- Vector256<float> result = lower.ToVector256Unsafe();
- return result.WithUpper(upper);
- }
-
- return SoftwareFallback(lower, upper);
-
- static Vector256<float> SoftwareFallback(Vector128<float> lower, Vector128<float> upper)
- {
- Vector256<float> result256 = Vector256<float>.Zero;
-
- ref Vector128<float> result128 = ref Unsafe.As<Vector256<float>, Vector128<float>>(ref result256);
- result128 = lower;
- Unsafe.Add(ref result128, 1) = upper;
-
- return result256;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt16}" /> instance from two <see cref="Vector128{UInt16}" /> instances.</summary>
- /// <param name="lower">The value that the lower 128-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 128-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt16}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<ushort> Create(Vector128<ushort> lower, Vector128<ushort> upper)
- {
- if (Avx.IsSupported)
- {
- Vector256<ushort> result = lower.ToVector256Unsafe();
- return result.WithUpper(upper);
- }
-
- return SoftwareFallback(lower, upper);
-
- static Vector256<ushort> SoftwareFallback(Vector128<ushort> lower, Vector128<ushort> upper)
- {
- Vector256<ushort> result256 = Vector256<ushort>.Zero;
-
- ref Vector128<ushort> result128 = ref Unsafe.As<Vector256<ushort>, Vector128<ushort>>(ref result256);
- result128 = lower;
- Unsafe.Add(ref result128, 1) = upper;
-
- return result256;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt32}" /> instance from two <see cref="Vector128{UInt32}" /> instances.</summary>
- /// <param name="lower">The value that the lower 128-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 128-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt32}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<uint> Create(Vector128<uint> lower, Vector128<uint> upper)
- {
- if (Avx.IsSupported)
- {
- Vector256<uint> result = lower.ToVector256Unsafe();
- return result.WithUpper(upper);
- }
-
- return SoftwareFallback(lower, upper);
-
- static Vector256<uint> SoftwareFallback(Vector128<uint> lower, Vector128<uint> upper)
- {
- Vector256<uint> result256 = Vector256<uint>.Zero;
-
- ref Vector128<uint> result128 = ref Unsafe.As<Vector256<uint>, Vector128<uint>>(ref result256);
- result128 = lower;
- Unsafe.Add(ref result128, 1) = upper;
-
- return result256;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt64}" /> instance from two <see cref="Vector128{UInt64}" /> instances.</summary>
- /// <param name="lower">The value that the lower 128-bits will be initialized to.</param>
- /// <param name="upper">The value that the upper 128-bits will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt64}" /> initialized from <paramref name="lower" /> and <paramref name="upper" />.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<ulong> Create(Vector128<ulong> lower, Vector128<ulong> upper)
- {
- if (Avx.IsSupported)
- {
- Vector256<ulong> result = lower.ToVector256Unsafe();
- return result.WithUpper(upper);
- }
-
- return SoftwareFallback(lower, upper);
-
- static Vector256<ulong> SoftwareFallback(Vector128<ulong> lower, Vector128<ulong> upper)
- {
- Vector256<ulong> result256 = Vector256<ulong>.Zero;
-
- ref Vector128<ulong> result128 = ref Unsafe.As<Vector256<ulong>, Vector128<ulong>>(ref result256);
- result128 = lower;
- Unsafe.Add(ref result128, 1) = upper;
-
- return result256;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Byte}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Byte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<byte> CreateScalar(byte value)
- {
- if (Avx.IsSupported)
- {
- return Vector128.CreateScalar(value).ToVector256();
- }
-
- return SoftwareFallback(value);
-
- static Vector256<byte> SoftwareFallback(byte value)
- {
- var result = Vector256<byte>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<byte>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Double}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Double}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<double> CreateScalar(double value)
- {
- if (Avx.IsSupported)
- {
- return Vector128.CreateScalar(value).ToVector256();
- }
-
- return SoftwareFallback(value);
-
- static Vector256<double> SoftwareFallback(double value)
- {
- var result = Vector256<double>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<double>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int16}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<short> CreateScalar(short value)
- {
- if (Avx.IsSupported)
- {
- return Vector128.CreateScalar(value).ToVector256();
- }
-
- return SoftwareFallback(value);
-
- static Vector256<short> SoftwareFallback(short value)
- {
- var result = Vector256<short>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<short>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int32}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<int> CreateScalar(int value)
- {
- if (Avx.IsSupported)
- {
- return Vector128.CreateScalar(value).ToVector256();
- }
-
- return SoftwareFallback(value);
-
- static Vector256<int> SoftwareFallback(int value)
- {
- var result = Vector256<int>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<int>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int64}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<long> CreateScalar(long value)
- {
- if (Sse2.X64.IsSupported && Avx.IsSupported)
- {
- return Vector128.CreateScalar(value).ToVector256();
- }
-
- return SoftwareFallback(value);
-
- static Vector256<long> SoftwareFallback(long value)
- {
- var result = Vector256<long>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<long>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{SByte}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{SByte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<sbyte> CreateScalar(sbyte value)
- {
- if (Avx.IsSupported)
- {
- return Vector128.CreateScalar(value).ToVector256();
- }
-
- return SoftwareFallback(value);
-
- static Vector256<sbyte> SoftwareFallback(sbyte value)
- {
- var result = Vector256<sbyte>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<sbyte>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Single}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Single}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe Vector256<float> CreateScalar(float value)
- {
- if (Avx.IsSupported)
- {
- return Vector128.CreateScalar(value).ToVector256();
- }
-
- return SoftwareFallback(value);
-
- static Vector256<float> SoftwareFallback(float value)
- {
- var result = Vector256<float>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<float>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt16}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<ushort> CreateScalar(ushort value)
- {
- if (Avx.IsSupported)
- {
- return Vector128.CreateScalar(value).ToVector256();
- }
-
- return SoftwareFallback(value);
-
- static Vector256<ushort> SoftwareFallback(ushort value)
- {
- var result = Vector256<ushort>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<ushort>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt32}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<uint> CreateScalar(uint value)
- {
- if (Avx.IsSupported)
- {
- return Vector128.CreateScalar(value).ToVector256();
- }
-
- return SoftwareFallback(value);
-
- static Vector256<uint> SoftwareFallback(uint value)
- {
- var result = Vector256<uint>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<uint>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt64}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements initialized to zero.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [CLSCompliant(false)]
- public static unsafe Vector256<ulong> CreateScalar(ulong value)
- {
- if (Sse2.X64.IsSupported && Avx.IsSupported)
- {
- return Vector128.CreateScalar(value).ToVector256();
- }
-
- return SoftwareFallback(value);
-
- static Vector256<ulong> SoftwareFallback(ulong value)
- {
- var result = Vector256<ulong>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<ulong>, byte>(ref result), value);
- return result;
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{Byte}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Byte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector256<byte> CreateScalarUnsafe(byte value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- byte* pResult = stackalloc byte[32];
- pResult[0] = value;
- return Unsafe.AsRef<Vector256<byte>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector256{Double}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Double}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector256<double> CreateScalarUnsafe(double value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- double* pResult = stackalloc double[4];
- pResult[0] = value;
- return Unsafe.AsRef<Vector256<double>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int16}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector256<short> CreateScalarUnsafe(short value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- short* pResult = stackalloc short[16];
- pResult[0] = value;
- return Unsafe.AsRef<Vector256<short>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int32}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector256<int> CreateScalarUnsafe(int value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- int* pResult = stackalloc int[8];
- pResult[0] = value;
- return Unsafe.AsRef<Vector256<int>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector256{Int64}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Int64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector256<long> CreateScalarUnsafe(long value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- long* pResult = stackalloc long[4];
- pResult[0] = value;
- return Unsafe.AsRef<Vector256<long>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector256{SByte}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{SByte}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- [CLSCompliant(false)]
- public static unsafe Vector256<sbyte> CreateScalarUnsafe(sbyte value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- sbyte* pResult = stackalloc sbyte[32];
- pResult[0] = value;
- return Unsafe.AsRef<Vector256<sbyte>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector256{Single}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{Single}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- public static unsafe Vector256<float> CreateScalarUnsafe(float value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- float* pResult = stackalloc float[8];
- pResult[0] = value;
- return Unsafe.AsRef<Vector256<float>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt16}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt16}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- [CLSCompliant(false)]
- public static unsafe Vector256<ushort> CreateScalarUnsafe(ushort value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- ushort* pResult = stackalloc ushort[16];
- pResult[0] = value;
- return Unsafe.AsRef<Vector256<ushort>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt32}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt32}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- [CLSCompliant(false)]
- public static unsafe Vector256<uint> CreateScalarUnsafe(uint value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- uint* pResult = stackalloc uint[8];
- pResult[0] = value;
- return Unsafe.AsRef<Vector256<uint>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector256{UInt64}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector256{UInt64}" /> instance with the first element initialized to <paramref name="value" /> and the remaining elements left uninitialized.</returns>
- [Intrinsic]
- [CLSCompliant(false)]
- public static unsafe Vector256<ulong> CreateScalarUnsafe(ulong value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- ulong* pResult = stackalloc ulong[4];
- pResult[0] = value;
- return Unsafe.AsRef<Vector256<ulong>>(pResult);
- }
-
- /// <summary>Gets the element at the specified index.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the element from.</param>
- /// <param name="index">The index of the element to get.</param>
- /// <returns>The value of the element at <paramref name="index" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index" /> was less than zero or greater than the number of elements.</exception>
- [Intrinsic]
- public static T GetElement<T>(this Vector256<T> vector, int index)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- if ((uint)(index) >= (uint)(Vector256<T>.Count))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index);
- }
-
- ref T e0 = ref Unsafe.As<Vector256<T>, T>(ref vector);
- return Unsafe.Add(ref e0, index);
- }
-
- /// <summary>Creates a new <see cref="Vector256{T}" /> with the element at the specified index set to the specified value and the remaining elements set to the same value as that in the given vector.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the remaining elements from.</param>
- /// <param name="index">The index of the element to set.</param>
- /// <param name="value">The value to set the element to.</param>
- /// <returns>A <see cref="Vector256{T}" /> with the value of the element at <paramref name="index" /> set to <paramref name="value" /> and the remaining elements set to the same value as that in <paramref name="vector" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index" /> was less than zero or greater than the number of elements.</exception>
- [Intrinsic]
- public static Vector256<T> WithElement<T>(this Vector256<T> vector, int index, T value)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- if ((uint)(index) >= (uint)(Vector256<T>.Count))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index);
- }
-
- Vector256<T> result = vector;
- ref T e0 = ref Unsafe.As<Vector256<T>, T>(ref result);
- Unsafe.Add(ref e0, index) = value;
- return result;
- }
-
- /// <summary>Gets the value of the lower 128-bits as a new <see cref="Vector128{T}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the lower 128-bits from.</param>
- /// <returns>The value of the lower 128-bits as a new <see cref="Vector128{T}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector128<T> GetLower<T>(this Vector256<T> vector)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Unsafe.As<Vector256<T>, Vector128<T>>(ref vector);
- }
-
- /// <summary>Creates a new <see cref="Vector256{T}" /> with the lower 128-bits set to the specified value and the upper 128-bits set to the same value as that in the given vector.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the upper 128-bits from.</param>
- /// <param name="value">The value of the lower 128-bits as a <see cref="Vector128{T}" />.</param>
- /// <returns>A new <see cref="Vector256{T}" /> with the lower 128-bits set to <paramref name="value" /> and the upper 128-bits set to the same value as that in <paramref name="vector" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector256<T> WithLower<T>(this Vector256<T> vector, Vector128<T> value)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- if (Avx2.IsSupported && ((typeof(T) != typeof(float)) && (typeof(T) != typeof(double))))
- {
- // All integral types generate the same instruction, so just pick one rather than handling each T separately
- return Avx2.InsertVector128(vector.AsByte(), value.AsByte(), 0).As<byte, T>();
- }
-
- if (Avx.IsSupported)
- {
- // All floating-point types generate the same instruction, so just pick one rather than handling each T separately
- // We also just fallback to this for integral types if AVX2 isn't supported, since that is still faster than software
- return Avx.InsertVector128(vector.AsSingle(), value.AsSingle(), 0).As<float, T>();
- }
-
- return SoftwareFallback(vector, value);
-
- static Vector256<T> SoftwareFallback(Vector256<T> vector, Vector128<T> value)
- {
- Vector256<T> result = vector;
- Unsafe.As<Vector256<T>, Vector128<T>>(ref result) = value;
- return result;
- }
- }
-
- /// <summary>Gets the value of the upper 128-bits as a new <see cref="Vector128{T}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the upper 128-bits from.</param>
- /// <returns>The value of the upper 128-bits as a new <see cref="Vector128{T}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector128<T> GetUpper<T>(this Vector256<T> vector)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- if (Avx2.IsSupported && ((typeof(T) != typeof(float)) && (typeof(T) != typeof(double))))
- {
- // All integral types generate the same instruction, so just pick one rather than handling each T separately
- return Avx2.ExtractVector128(vector.AsByte(), 1).As<byte, T>();
- }
-
- if (Avx.IsSupported)
- {
- // All floating-point types generate the same instruction, so just pick one rather than handling each T separately
- // We also just fallback to this for integral types if AVX2 isn't supported, since that is still faster than software
- return Avx.ExtractVector128(vector.AsSingle(), 1).As<float, T>();
- }
-
- return SoftwareFallback(vector);
-
- static Vector128<T> SoftwareFallback(Vector256<T> vector)
- {
- ref Vector128<T> lower = ref Unsafe.As<Vector256<T>, Vector128<T>>(ref vector);
- return Unsafe.Add(ref lower, 1);
- }
- }
-
- /// <summary>Creates a new <see cref="Vector256{T}" /> with the upper 128-bits set to the specified value and the upper 128-bits set to the same value as that in the given vector.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the lower 128-bits from.</param>
- /// <param name="value">The value of the upper 128-bits as a <see cref="Vector128{T}" />.</param>
- /// <returns>A new <see cref="Vector256{T}" /> with the upper 128-bits set to <paramref name="value" /> and the lower 128-bits set to the same value as that in <paramref name="vector" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector256<T> WithUpper<T>(this Vector256<T> vector, Vector128<T> value)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- if (Avx2.IsSupported && ((typeof(T) != typeof(float)) && (typeof(T) != typeof(double))))
- {
- // All integral types generate the same instruction, so just pick one rather than handling each T separately
- return Avx2.InsertVector128(vector.AsByte(), value.AsByte(), 1).As<byte, T>();
- }
-
- if (Avx.IsSupported)
- {
- // All floating-point types generate the same instruction, so just pick one rather than handling each T separately
- // We also just fallback to this for integral types if AVX2 isn't supported, since that is still faster than software
- return Avx.InsertVector128(vector.AsSingle(), value.AsSingle(), 1).As<float, T>();
- }
-
- return SoftwareFallback(vector, value);
-
- static Vector256<T> SoftwareFallback(Vector256<T> vector, Vector128<T> value)
- {
- Vector256<T> result = vector;
- ref Vector128<T> lower = ref Unsafe.As<Vector256<T>, Vector128<T>>(ref result);
- Unsafe.Add(ref lower, 1) = value;
- return result;
- }
- }
-
- /// <summary>Converts the given vector to a scalar containing the value of the first element.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the first element from.</param>
- /// <returns>A scalar <typeparamref name="T" /> containing the value of the first element.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static T ToScalar<T>(this Vector256<T> vector)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Unsafe.As<Vector256<T>, T>(ref vector);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256DebugView_1.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256DebugView_1.cs
deleted file mode 100644
index 5131341ad89..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256DebugView_1.cs
+++ /dev/null
@@ -1,118 +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 Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics
-{
- internal readonly struct Vector256DebugView<T> where T : struct
- {
- private readonly Vector256<T> _value;
-
- public Vector256DebugView(Vector256<T> value)
- {
- _value = value;
- }
-
- public byte[] ByteView
- {
- get
- {
- var items = new byte[32];
- Unsafe.WriteUnaligned(ref items[0], _value);
- return items;
- }
- }
-
- public double[] DoubleView
- {
- get
- {
- var items = new double[4];
- Unsafe.WriteUnaligned(ref Unsafe.As<double, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public short[] Int16View
- {
- get
- {
- var items = new short[16];
- Unsafe.WriteUnaligned(ref Unsafe.As<short, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public int[] Int32View
- {
- get
- {
- var items = new int[8];
- Unsafe.WriteUnaligned(ref Unsafe.As<int, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public long[] Int64View
- {
- get
- {
- var items = new long[4];
- Unsafe.WriteUnaligned(ref Unsafe.As<long, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public sbyte[] SByteView
- {
- get
- {
- var items = new sbyte[32];
- Unsafe.WriteUnaligned(ref Unsafe.As<sbyte, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public float[] SingleView
- {
- get
- {
- var items = new float[8];
- Unsafe.WriteUnaligned(ref Unsafe.As<float, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public ushort[] UInt16View
- {
- get
- {
- var items = new ushort[16];
- Unsafe.WriteUnaligned(ref Unsafe.As<ushort, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public uint[] UInt32View
- {
- get
- {
- var items = new uint[8];
- Unsafe.WriteUnaligned(ref Unsafe.As<uint, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public ulong[] UInt64View
- {
- get
- {
- var items = new ulong[4];
- Unsafe.WriteUnaligned(ref Unsafe.As<ulong, byte>(ref items[0]), _value);
- return items;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs
deleted file mode 100644
index 09962fc47b6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256_1.cs
+++ /dev/null
@@ -1,193 +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 System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics.X86;
-using System.Text;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics
-{
- // We mark certain methods with AggressiveInlining to ensure that the JIT will
- // inline them. The JIT would otherwise not inline the method since it, at the
- // point it tries to determine inline profability, currently cannot determine
- // that most of the code-paths will be optimized away as "dead code".
- //
- // We then manually inline cases (such as certain intrinsic code-paths) that
- // will generate code small enough to make the AgressiveInlining profitable. The
- // other cases (such as the software fallback) are placed in their own method.
- // This ensures we get good codegen for the "fast-path" and allows the JIT to
- // determine inline profitability of the other paths as it would normally.
-
- [Intrinsic]
- [DebuggerDisplay("{DisplayString,nq}")]
- [DebuggerTypeProxy(typeof(Vector256DebugView<>))]
- [StructLayout(LayoutKind.Sequential, Size = Vector256.Size)]
- public readonly struct Vector256<T> : IEquatable<Vector256<T>>
- where T : struct
- {
- // These fields exist to ensure the alignment is 8, rather than 1.
- // This also allows the debug view to work https://github.com/dotnet/coreclr/issues/15694)
- private readonly ulong _00;
- private readonly ulong _01;
- private readonly ulong _02;
- private readonly ulong _03;
-
- /// <summary>Gets the number of <typeparamref name="T" /> that are in a <see cref="Vector256{T}" />.</summary>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public static int Count
- {
- [Intrinsic]
- get
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Vector256.Size / Unsafe.SizeOf<T>();
- }
- }
-
- /// <summary>Gets a new <see cref="Vector256{T}" /> with all elements initialized to zero.</summary>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public static Vector256<T> Zero
- {
- [Intrinsic]
- get
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return default;
- }
- }
-
- internal unsafe string DisplayString
- {
- get
- {
- if (IsSupported)
- {
- return ToString();
- }
- else
- {
- return SR.NotSupported_Type;
- }
- }
- }
-
- internal static bool IsSupported
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => (typeof(T) == typeof(byte)) ||
- (typeof(T) == typeof(sbyte)) ||
- (typeof(T) == typeof(short)) ||
- (typeof(T) == typeof(ushort)) ||
- (typeof(T) == typeof(int)) ||
- (typeof(T) == typeof(uint)) ||
- (typeof(T) == typeof(long)) ||
- (typeof(T) == typeof(ulong)) ||
- (typeof(T) == typeof(float)) ||
- (typeof(T) == typeof(double));
- }
-
- /// <summary>Determines whether the specified <see cref="Vector256{T}" /> is equal to the current instance.</summary>
- /// <param name="other">The <see cref="Vector256{T}" /> to compare with the current instance.</param>
- /// <returns><c>true</c> if <paramref name="other" /> is equal to the current instance; otherwise, <c>false</c>.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool Equals(Vector256<T> other)
- {
- if (Avx.IsSupported)
- {
- if (typeof(T) == typeof(float))
- {
- Vector256<float> result = Avx.Compare(this.AsSingle(), other.AsSingle(), FloatComparisonMode.OrderedEqualNonSignaling);
- return Avx.MoveMask(result) == 0b1111_1111; // We have one bit per element
- }
-
- if (typeof(T) == typeof(double))
- {
- Vector256<double> result = Avx.Compare(this.AsDouble(), other.AsDouble(), FloatComparisonMode.OrderedEqualNonSignaling);
- return Avx.MoveMask(result) == 0b1111; // We have one bit per element
- }
- }
-
- if (Avx2.IsSupported)
- {
- // Unlike float/double, there are no special values to consider
- // for integral types and we can just do a comparison that all
- // bytes are exactly the same.
-
- Debug.Assert((typeof(T) != typeof(float)) && (typeof(T) != typeof(double)));
- Vector256<byte> result = Avx2.CompareEqual(this.AsByte(), other.AsByte());
- return Avx2.MoveMask(result) == unchecked((int)(0b1111_1111_1111_1111_1111_1111_1111_1111)); // We have one bit per element
- }
-
- return SoftwareFallback(in this, other);
-
- static bool SoftwareFallback(in Vector256<T> vector, Vector256<T> other)
- {
- for (int i = 0; i < Count; i++)
- {
- if (!((IEquatable<T>)(vector.GetElement(i))).Equals(other.GetElement(i)))
- {
- return false;
- }
- }
-
- return true;
- }
- }
-
- /// <summary>Determines whether the specified object is equal to the current instance.</summary>
- /// <param name="obj">The object to compare with the current instance.</param>
- /// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Vector256{T}" /> and is equal to the current instance; otherwise, <c>false</c>.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public override bool Equals(object? obj)
- {
- return (obj is Vector256<T>) && Equals((Vector256<T>)(obj));
- }
-
- /// <summary>Gets the hash code for the instance.</summary>
- /// <returns>The hash code for the instance.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public override int GetHashCode()
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- int hashCode = 0;
-
- for (int i = 0; i < Count; i++)
- {
- hashCode = HashCode.Combine(hashCode, this.GetElement(i).GetHashCode());
- }
-
- return hashCode;
- }
-
- /// <summary>Converts the current instance to an equivalent string representation.</summary>
- /// <returns>An equivalent string representation of the current instance.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public override string ToString()
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- int lastElement = Count - 1;
- var sb = new ValueStringBuilder(stackalloc char[64]);
- CultureInfo invariant = CultureInfo.InvariantCulture;
-
- sb.Append('<');
- for (int i = 0; i < lastElement; i++)
- {
- sb.Append(((IFormattable)this.GetElement(i)).ToString("G", invariant));
- sb.Append(',');
- sb.Append(' ');
- }
- sb.Append(((IFormattable)this.GetElement(lastElement)).ToString("G", invariant));
- sb.Append('>');
-
- return sb.ToString();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs
deleted file mode 100644
index a81ff00c156..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64.cs
+++ /dev/null
@@ -1,694 +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 System.Runtime.CompilerServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics
-{
- public static class Vector64
- {
- internal const int Size = 8;
-
- /// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{U}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <typeparam name="U">The type of the vector <paramref name="vector" /> should be reinterpreted as.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector64{U}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) or the type of the target (<typeparamref name="U" />) is not supported.</exception>
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Vector64<U> As<T, U>(this Vector64<T> vector)
- where T : struct
- where U : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- ThrowHelper.ThrowForUnsupportedVectorBaseType<U>();
- return Unsafe.As<Vector64<T>, Vector64<U>>(ref vector);
- }
-
- /// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{Byte}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector64{Byte}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector64<byte> AsByte<T>(this Vector64<T> vector)
- where T : struct
- {
- return vector.As<T, byte>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{Double}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector64{Double}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector64<double> AsDouble<T>(this Vector64<T> vector)
- where T : struct
- {
- return vector.As<T, double>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{Int16}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector64{Int16}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector64<short> AsInt16<T>(this Vector64<T> vector)
- where T : struct
- {
- return vector.As<T, short>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{Int32}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector64{Int32}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector64<int> AsInt32<T>(this Vector64<T> vector)
- where T : struct
- {
- return vector.As<T, int>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{Int64}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector64{Int64}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector64<long> AsInt64<T>(this Vector64<T> vector)
- where T : struct
- {
- return vector.As<T, long>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{SByte}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector64{SByte}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector64<sbyte> AsSByte<T>(this Vector64<T> vector)
- where T : struct
- {
- return vector.As<T, sbyte>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{Single}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector64{Single}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- public static Vector64<float> AsSingle<T>(this Vector64<T> vector)
- where T : struct
- {
- return vector.As<T, float>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{UInt16}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector64{UInt16}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector64<ushort> AsUInt16<T>(this Vector64<T> vector)
- where T : struct
- {
- return vector.As<T, ushort>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{UInt32}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector64{UInt32}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector64<uint> AsUInt32<T>(this Vector64<T> vector)
- where T : struct
- {
- return vector.As<T, uint>();
- }
-
- /// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see cref="Vector64{UInt64}" />.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to reinterpret.</param>
- /// <returns><paramref name="vector" /> reinterpreted as a new <see cref="Vector64{UInt64}" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- [Intrinsic]
- [CLSCompliant(false)]
- public static Vector64<ulong> AsUInt64<T>(this Vector64<T> vector)
- where T : struct
- {
- return vector.As<T, ulong>();
- }
-
- /// <summary>Creates a new <see cref="Vector64{Byte}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Byte}" /> with all elements initialized to <paramref name="value" />.</returns>
- public static unsafe Vector64<byte> Create(byte value)
- {
- byte* pResult = stackalloc byte[8]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector64<byte>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Double}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Double}" /> with all elements initialized to <paramref name="value" />.</returns>
- public static unsafe Vector64<double> Create(double value)
- {
- return Unsafe.As<double, Vector64<double>>(ref value);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Int16}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Int16}" /> with all elements initialized to <paramref name="value" />.</returns>
- public static unsafe Vector64<short> Create(short value)
- {
- short* pResult = stackalloc short[4]
- {
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector64<short>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Int32}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Int32}" /> with all elements initialized to <paramref name="value" />.</returns>
- public static unsafe Vector64<int> Create(int value)
- {
- int* pResult = stackalloc int[2]
- {
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector64<int>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Int64}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Int64}" /> with all elements initialized to <paramref name="value" />.</returns>
- public static unsafe Vector64<long> Create(long value)
- {
- return Unsafe.As<long, Vector64<long>>(ref value);
- }
-
- /// <summary>Creates a new <see cref="Vector64{SByte}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{SByte}" /> with all elements initialized to <paramref name="value" />.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<sbyte> Create(sbyte value)
- {
- sbyte* pResult = stackalloc sbyte[8]
- {
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector64<sbyte>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Single}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Single}" /> with all elements initialized to <paramref name="value" />.</returns>
- public static unsafe Vector64<float> Create(float value)
- {
- float* pResult = stackalloc float[2]
- {
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector64<float>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{UInt16}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{UInt16}" /> with all elements initialized to <paramref name="value" />.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<ushort> Create(ushort value)
- {
- ushort* pResult = stackalloc ushort[4]
- {
- value,
- value,
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector64<ushort>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{UInt32}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{UInt32}" /> with all elements initialized to <paramref name="value" />.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<uint> Create(uint value)
- {
- uint* pResult = stackalloc uint[2]
- {
- value,
- value,
- };
-
- return Unsafe.AsRef<Vector64<uint>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{UInt64}" /> instance with all elements initialized to the specified value.</summary>
- /// <param name="value">The value that all elements will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{UInt64}" /> with all elements initialized to <paramref name="value" />.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<ulong> Create(ulong value)
- {
- return Unsafe.As<ulong, Vector64<ulong>>(ref value);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Byte}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Byte}" /> with each element initialized to corresponding specified value.</returns>
- public static unsafe Vector64<byte> Create(byte e0, byte e1, byte e2, byte e3, byte e4, byte e5, byte e6, byte e7)
- {
- byte* pResult = stackalloc byte[8]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- };
-
- return Unsafe.AsRef<Vector64<byte>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Int16}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Int16}" /> with each element initialized to corresponding specified value.</returns>
- public static unsafe Vector64<short> Create(short e0, short e1, short e2, short e3)
- {
- short* pResult = stackalloc short[4]
- {
- e0,
- e1,
- e2,
- e3,
- };
-
- return Unsafe.AsRef<Vector64<short>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Int32}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Int32}" /> with each element initialized to corresponding specified value.</returns>
- public static unsafe Vector64<int> Create(int e0, int e1)
- {
- int* pResult = stackalloc int[2]
- {
- e0,
- e1,
- };
-
- return Unsafe.AsRef<Vector64<int>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{SByte}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <param name="e4">The value that element 4 will be initialized to.</param>
- /// <param name="e5">The value that element 5 will be initialized to.</param>
- /// <param name="e6">The value that element 6 will be initialized to.</param>
- /// <param name="e7">The value that element 7 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{SByte}" /> with each element initialized to corresponding specified value.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<sbyte> Create(sbyte e0, sbyte e1, sbyte e2, sbyte e3, sbyte e4, sbyte e5, sbyte e6, sbyte e7)
- {
- sbyte* pResult = stackalloc sbyte[8]
- {
- e0,
- e1,
- e2,
- e3,
- e4,
- e5,
- e6,
- e7,
- };
-
- return Unsafe.AsRef<Vector64<sbyte>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Single}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Single}" /> with each element initialized to corresponding specified value.</returns>
- public static unsafe Vector64<float> Create(float e0, float e1)
- {
- float* pResult = stackalloc float[2]
- {
- e0,
- e1,
- };
-
- return Unsafe.AsRef<Vector64<float>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{UInt16}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <param name="e2">The value that element 2 will be initialized to.</param>
- /// <param name="e3">The value that element 3 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{UInt16}" /> with each element initialized to corresponding specified value.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<ushort> Create(ushort e0, ushort e1, ushort e2, ushort e3)
- {
- ushort* pResult = stackalloc ushort[4]
- {
- e0,
- e1,
- e2,
- e3,
- };
-
- return Unsafe.AsRef<Vector64<ushort>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{UInt32}" /> instance with each element initialized to the corresponding specified value.</summary>
- /// <param name="e0">The value that element 0 will be initialized to.</param>
- /// <param name="e1">The value that element 1 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{UInt32}" /> with each element initialized to corresponding specified value.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<uint> Create(uint e0, uint e1)
- {
- uint* pResult = stackalloc uint[2]
- {
- e0,
- e1,
- };
-
- return Unsafe.AsRef<Vector64<uint>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Byte}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Byte}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements initialized to zero.</returns>
- public static unsafe Vector64<byte> CreateScalar(byte value)
- {
- var result = Vector64<byte>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector64<byte>, byte>(ref result), value);
- return result;
- }
-
- /// <summary>Creates a new <see cref="Vector64{Int16}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Int16}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements initialized to zero.</returns>
- public static unsafe Vector64<short> CreateScalar(short value)
- {
- var result = Vector64<short>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector64<short>, byte>(ref result), value);
- return result;
- }
-
- /// <summary>Creates a new <see cref="Vector64{Int32}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Int32}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements initialized to zero.</returns>
- public static unsafe Vector64<int> CreateScalar(int value)
- {
- var result = Vector64<int>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector64<int>, byte>(ref result), value);
- return result;
- }
-
- /// <summary>Creates a new <see cref="Vector64{SByte}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{SByte}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements initialized to zero.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<sbyte> CreateScalar(sbyte value)
- {
- var result = Vector64<sbyte>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector64<sbyte>, byte>(ref result), value);
- return result;
- }
-
- /// <summary>Creates a new <see cref="Vector64{Single}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Single}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements initialized to zero.</returns>
- public static unsafe Vector64<float> CreateScalar(float value)
- {
- var result = Vector64<float>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector64<float>, byte>(ref result), value);
- return result;
- }
-
- /// <summary>Creates a new <see cref="Vector64{UInt16}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{UInt16}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements initialized to zero.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<ushort> CreateScalar(ushort value)
- {
- var result = Vector64<ushort>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector64<ushort>, byte>(ref result), value);
- return result;
- }
-
- /// <summary>Creates a new <see cref="Vector64{UInt32}" /> instance with the first element initialized to the specified value and the remaining elements initialized to zero.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{UInt32}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements initialized to zero.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<uint> CreateScalar(uint value)
- {
- var result = Vector64<uint>.Zero;
- Unsafe.WriteUnaligned(ref Unsafe.As<Vector64<uint>, byte>(ref result), value);
- return result;
- }
-
- /// <summary>Creates a new <see cref="Vector64{Byte}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Byte}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements left uninitialized.</returns>
- public static unsafe Vector64<byte> CreateScalarUnsafe(byte value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- byte* pResult = stackalloc byte[8];
- pResult[0] = value;
- return Unsafe.AsRef<Vector64<byte>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Int16}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Int16}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements left uninitialized.</returns>
- public static unsafe Vector64<short> CreateScalarUnsafe(short value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- short* pResult = stackalloc short[4];
- pResult[0] = value;
- return Unsafe.AsRef<Vector64<short>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Int32}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Int32}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements left uninitialized.</returns>
- public static unsafe Vector64<int> CreateScalarUnsafe(int value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- int* pResult = stackalloc int[2];
- pResult[0] = value;
- return Unsafe.AsRef<Vector64<int>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{SByte}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{SByte}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements left uninitialized.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<sbyte> CreateScalarUnsafe(sbyte value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- sbyte* pResult = stackalloc sbyte[8];
- pResult[0] = value;
- return Unsafe.AsRef<Vector64<sbyte>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{Single}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{Single}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements left uninitialized.</returns>
- public static unsafe Vector64<float> CreateScalarUnsafe(float value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- float* pResult = stackalloc float[2];
- pResult[0] = value;
- return Unsafe.AsRef<Vector64<float>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{UInt16}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{UInt16}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements left uninitialized.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<ushort> CreateScalarUnsafe(ushort value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- ushort* pResult = stackalloc ushort[4];
- pResult[0] = value;
- return Unsafe.AsRef<Vector64<ushort>>(pResult);
- }
-
- /// <summary>Creates a new <see cref="Vector64{UInt32}" /> instance with the first element initialized to the specified value and the remaining elements left uninitialized.</summary>
- /// <param name="value">The value that element 0 will be initialized to.</param>
- /// <returns>A new <see cref="Vector64{UInt32}" /> instance with the first element initialized to <paramref name="value"/> and the remaining elements left uninitialized.</returns>
- [CLSCompliant(false)]
- public static unsafe Vector64<uint> CreateScalarUnsafe(uint value)
- {
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- uint* pResult = stackalloc uint[2];
- pResult[0] = value;
- return Unsafe.AsRef<Vector64<uint>>(pResult);
- }
-
- /// <summary>Gets the element at the specified index.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the element from.</param>
- /// <param name="index">The index of the element to get.</param>
- /// <returns>The value of the element at <paramref name="index" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index" /> was less than zero or greater than the number of elements.</exception>
- public static T GetElement<T>(this Vector64<T> vector, int index)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- if ((uint)(index) >= (uint)(Vector64<T>.Count))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index);
- }
-
- ref T e0 = ref Unsafe.As<Vector64<T>, T>(ref vector);
- return Unsafe.Add(ref e0, index);
- }
-
- /// <summary>Creates a new <see cref="Vector64{T}" /> with the element at the specified index set to the specified value and the remaining elements set to the same value as that in the given vector.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the remaining elements from.</param>
- /// <param name="index">The index of the element to set.</param>
- /// <param name="value">The value to set the element to.</param>
- /// <returns>A <see cref="Vector64{T}" /> with the value of the element at <paramref name="index" /> set to <paramref name="value" /> and the remaining elements set to the same value as that in <paramref name="vector" />.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index" /> was less than zero or greater than the number of elements.</exception>
- public static Vector64<T> WithElement<T>(this Vector64<T> vector, int index, T value)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- if ((uint)(index) >= (uint)(Vector64<T>.Count))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index);
- }
-
- Vector64<T> result = vector;
- ref T e0 = ref Unsafe.As<Vector64<T>, T>(ref result);
- Unsafe.Add(ref e0, index) = value;
- return result;
- }
-
- /// <summary>Converts the given vector to a scalar containing the value of the first element.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to get the first element from.</param>
- /// <returns>A scalar <typeparamref name="T" /> containing the value of the first element.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- public static T ToScalar<T>(this Vector64<T> vector)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Unsafe.As<Vector64<T>, T>(ref vector);
- }
-
- /// <summary>Converts the given vector to a new <see cref="Vector128{T}" /> with the lower 64-bits set to the value of the given vector and the upper 64-bits initialized to zero.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to extend.</param>
- /// <returns>A new <see cref="Vector128{T}" /> with the lower 64-bits set to the value of <paramref name="vector" /> and the upper 64-bits initialized to zero.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- public static Vector128<T> ToVector128<T>(this Vector64<T> vector)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- Vector128<T> result = Vector128<T>.Zero;
- Unsafe.As<Vector128<T>, Vector64<T>>(ref result) = vector;
- return result;
- }
-
- /// <summary>Converts the given vector to a new <see cref="Vector128{T}" /> with the lower 64-bits set to the value of the given vector and the upper 64-bits left uninitialized.</summary>
- /// <typeparam name="T">The type of the input vector.</typeparam>
- /// <param name="vector">The vector to extend.</param>
- /// <returns>A new <see cref="Vector128{T}" /> with the lower 64-bits set to the value of <paramref name="vector" /> and the upper 64-bits left uninitialized.</returns>
- /// <exception cref="NotSupportedException">The type of <paramref name="vector" /> (<typeparamref name="T" />) is not supported.</exception>
- public static unsafe Vector128<T> ToVector128Unsafe<T>(this Vector64<T> vector)
- where T : struct
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- // This relies on us stripping the "init" flag from the ".locals"
- // declaration to let the upper bits be uninitialized.
-
- byte* pResult = stackalloc byte[Vector128.Size];
- Unsafe.AsRef<Vector64<T>>(pResult) = vector;
- return Unsafe.AsRef<Vector128<T>>(pResult);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64DebugView_1.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64DebugView_1.cs
deleted file mode 100644
index 878e29949e3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64DebugView_1.cs
+++ /dev/null
@@ -1,118 +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 Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics
-{
- internal readonly struct Vector64DebugView<T> where T : struct
- {
- private readonly Vector64<T> _value;
-
- public Vector64DebugView(Vector64<T> value)
- {
- _value = value;
- }
-
- public byte[] ByteView
- {
- get
- {
- var items = new byte[8];
- Unsafe.WriteUnaligned(ref items[0], _value);
- return items;
- }
- }
-
- public double[] DoubleView
- {
- get
- {
- var items = new double[1];
- Unsafe.WriteUnaligned(ref Unsafe.As<double, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public short[] Int16View
- {
- get
- {
- var items = new short[4];
- Unsafe.WriteUnaligned(ref Unsafe.As<short, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public int[] Int32View
- {
- get
- {
- var items = new int[2];
- Unsafe.WriteUnaligned(ref Unsafe.As<int, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public long[] Int64View
- {
- get
- {
- var items = new long[1];
- Unsafe.WriteUnaligned(ref Unsafe.As<long, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public sbyte[] SByteView
- {
- get
- {
- var items = new sbyte[8];
- Unsafe.WriteUnaligned(ref Unsafe.As<sbyte, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public float[] SingleView
- {
- get
- {
- var items = new float[2];
- Unsafe.WriteUnaligned(ref Unsafe.As<float, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public ushort[] UInt16View
- {
- get
- {
- var items = new ushort[4];
- Unsafe.WriteUnaligned(ref Unsafe.As<ushort, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public uint[] UInt32View
- {
- get
- {
- var items = new uint[2];
- Unsafe.WriteUnaligned(ref Unsafe.As<uint, byte>(ref items[0]), _value);
- return items;
- }
- }
-
- public ulong[] UInt64View
- {
- get
- {
- var items = new ulong[1];
- Unsafe.WriteUnaligned(ref Unsafe.As<ulong, byte>(ref items[0]), _value);
- return items;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs
deleted file mode 100644
index 3c35b31097e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector64_1.cs
+++ /dev/null
@@ -1,146 +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 System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics
-{
- [Intrinsic]
- [DebuggerDisplay("{DisplayString,nq}")]
- [DebuggerTypeProxy(typeof(Vector64DebugView<>))]
- [StructLayout(LayoutKind.Sequential, Size = Vector64.Size)]
- public readonly struct Vector64<T> : IEquatable<Vector64<T>>
- where T : struct
- {
- // These fields exist to ensure the alignment is 8, rather than 1.
- // This also allows the debug view to work https://github.com/dotnet/coreclr/issues/15694)
- private readonly ulong _00;
-
- /// <summary>Gets the number of <typeparamref name="T" /> that are in a <see cref="Vector64{T}" />.</summary>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public static int Count
- {
- get
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return Vector64.Size / Unsafe.SizeOf<T>();
- }
- }
-
- /// <summary>Gets a new <see cref="Vector64{T}" /> with all elements initialized to zero.</summary>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public static Vector64<T> Zero
- {
- get
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
- return default;
- }
- }
-
- internal unsafe string DisplayString
- {
- get
- {
- if (IsSupported)
- {
- return ToString();
- }
- else
- {
- return SR.NotSupported_Type;
- }
- }
- }
-
- internal static bool IsSupported
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => (typeof(T) == typeof(byte)) ||
- (typeof(T) == typeof(sbyte)) ||
- (typeof(T) == typeof(short)) ||
- (typeof(T) == typeof(ushort)) ||
- (typeof(T) == typeof(int)) ||
- (typeof(T) == typeof(uint)) ||
- (typeof(T) == typeof(long)) ||
- (typeof(T) == typeof(ulong)) ||
- (typeof(T) == typeof(float)) ||
- (typeof(T) == typeof(double));
- }
-
- /// <summary>Determines whether the specified <see cref="Vector64{T}" /> is equal to the current instance.</summary>
- /// <param name="other">The <see cref="Vector64{T}" /> to compare with the current instance.</param>
- /// <returns><c>true</c> if <paramref name="other" /> is equal to the current instance; otherwise, <c>false</c>.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public bool Equals(Vector64<T> other)
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- for (int i = 0; i < Count; i++)
- {
- if (!((IEquatable<T>)(this.GetElement(i))).Equals(other.GetElement(i)))
- {
- return false;
- }
- }
-
- return true;
- }
-
- /// <summary>Determines whether the specified object is equal to the current instance.</summary>
- /// <param name="obj">The object to compare with the current instance.</param>
- /// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Vector64{T}" /> and is equal to the current instance; otherwise, <c>false</c>.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public override bool Equals(object? obj)
- {
- return (obj is Vector64<T>) && Equals((Vector64<T>)(obj));
- }
-
- /// <summary>Gets the hash code for the instance.</summary>
- /// <returns>The hash code for the instance.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public override int GetHashCode()
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- int hashCode = 0;
-
- for (int i = 0; i < Count; i++)
- {
- hashCode = HashCode.Combine(hashCode, this.GetElement(i).GetHashCode());
- }
-
- return hashCode;
- }
-
- /// <summary>Converts the current instance to an equivalent string representation.</summary>
- /// <returns>An equivalent string representation of the current instance.</returns>
- /// <exception cref="NotSupportedException">The type of the current instance (<typeparamref name="T" />) is not supported.</exception>
- public override string ToString()
- {
- ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
-
- int lastElement = Count - 1;
- var sb = new ValueStringBuilder(stackalloc char[64]);
- CultureInfo invariant = CultureInfo.InvariantCulture;
-
- sb.Append('<');
- for (int i = 0; i < lastElement; i++)
- {
- sb.Append(((IFormattable)this.GetElement(i)).ToString("G", invariant));
- sb.Append(',');
- sb.Append(' ');
- }
- sb.Append(((IFormattable)this.GetElement(lastElement)).ToString("G", invariant));
- sb.Append('>');
-
- return sb.ToString();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Aes.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Aes.PlatformNotSupported.cs
deleted file mode 100644
index 8d2fb4d3a06..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Aes.PlatformNotSupported.cs
+++ /dev/null
@@ -1,59 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel AES hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Aes : Sse2
- {
- internal Aes() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// __m128i _mm_aesdec_si128 (__m128i a, __m128i RoundKey)
- /// AESDEC xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Decrypt(Vector128<byte> value, Vector128<byte> roundKey) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_aesdeclast_si128 (__m128i a, __m128i RoundKey)
- /// AESDECLAST xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> DecryptLast(Vector128<byte> value, Vector128<byte> roundKey) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_aesenc_si128 (__m128i a, __m128i RoundKey)
- /// AESENC xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Encrypt(Vector128<byte> value, Vector128<byte> roundKey) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_aesenclast_si128 (__m128i a, __m128i RoundKey)
- /// AESENCLAST xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> EncryptLast(Vector128<byte> value, Vector128<byte> roundKey) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_aesimc_si128 (__m128i a)
- /// AESIMC xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> InverseMixColumns(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_aeskeygenassist_si128 (__m128i a, const int imm8)
- /// AESKEYGENASSIST xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<byte> KeygenAssist(Vector128<byte> value, byte control) { throw new PlatformNotSupportedException(); }
-
- }
-
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Aes.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Aes.cs
deleted file mode 100644
index 41bed912b7b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Aes.cs
+++ /dev/null
@@ -1,56 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel AES hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Aes : Sse2
- {
- internal Aes() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// __m128i _mm_aesdec_si128 (__m128i a, __m128i RoundKey)
- /// AESDEC xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Decrypt(Vector128<byte> value, Vector128<byte> roundKey) => Decrypt(value, roundKey);
-
- /// <summary>
- /// __m128i _mm_aesdeclast_si128 (__m128i a, __m128i RoundKey)
- /// AESDECLAST xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> DecryptLast(Vector128<byte> value, Vector128<byte> roundKey) => DecryptLast(value, roundKey);
-
- /// <summary>
- /// __m128i _mm_aesenc_si128 (__m128i a, __m128i RoundKey)
- /// AESENC xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Encrypt(Vector128<byte> value, Vector128<byte> roundKey) => Encrypt(value, roundKey);
-
- /// <summary>
- /// __m128i _mm_aesenclast_si128 (__m128i a, __m128i RoundKey)
- /// AESENCLAST xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> EncryptLast(Vector128<byte> value, Vector128<byte> roundKey) => EncryptLast(value, roundKey);
-
- /// <summary>
- /// __m128i _mm_aesimc_si128 (__m128i a)
- /// AESIMC xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> InverseMixColumns(Vector128<byte> value) => InverseMixColumns(value);
-
- /// <summary>
- /// __m128i _mm_aeskeygenassist_si128 (__m128i a, const int imm8)
- /// AESKEYGENASSIST xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<byte> KeygenAssist(Vector128<byte> value, byte control) => KeygenAssist(value, control);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx.PlatformNotSupported.cs
deleted file mode 100644
index c855b8db61f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx.PlatformNotSupported.cs
+++ /dev/null
@@ -1,1227 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel AVX hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Avx : Sse42
- {
- internal Avx() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// __m256 _mm256_add_ps (__m256 a, __m256 b)
- /// VADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Add(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_add_pd (__m256d a, __m256d b)
- /// VADDPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Add(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_addsub_ps (__m256 a, __m256 b)
- /// VADDSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> AddSubtract(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_addsub_pd (__m256d a, __m256d b)
- /// VADDSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> AddSubtract(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_and_ps (__m256 a, __m256 b)
- /// VANDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> And(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_and_pd (__m256d a, __m256d b)
- /// VANDPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> And(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_andnot_ps (__m256 a, __m256 b)
- /// VANDNPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> AndNot(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_andnot_pd (__m256d a, __m256d b)
- /// VANDNPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> AndNot(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_blend_ps (__m256 a, __m256 b, const int imm8)
- /// VBLENDPS ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<float> Blend(Vector256<float> left, Vector256<float> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_blend_pd (__m256d a, __m256d b, const int imm8)
- /// VBLENDPD ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<double> Blend(Vector256<double> left, Vector256<double> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_blendv_ps (__m256 a, __m256 b, __m256 mask)
- /// VBLENDVPS ymm, ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<float> BlendVariable(Vector256<float> left, Vector256<float> right, Vector256<float> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_blendv_pd (__m256d a, __m256d b, __m256d mask)
- /// VBLENDVPD ymm, ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<double> BlendVariable(Vector256<double> left, Vector256<double> right, Vector256<double> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_broadcast_ss (float const * mem_addr)
- /// VBROADCASTSS xmm, m32
- /// </summary>
- public static unsafe Vector128<float> BroadcastScalarToVector128(float* source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_broadcast_ss (float const * mem_addr)
- /// VBROADCASTSS ymm, m32
- /// </summary>
- public static unsafe Vector256<float> BroadcastScalarToVector256(float* source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_broadcast_sd (double const * mem_addr)
- /// VBROADCASTSD ymm, m64
- /// </summary>
- public static unsafe Vector256<double> BroadcastScalarToVector256(double* source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_broadcast_ps (__m128 const * mem_addr)
- /// VBROADCASTF128, ymm, m128
- /// </summary>
- public static unsafe Vector256<float> BroadcastVector128ToVector256(float* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_broadcast_pd (__m128d const * mem_addr)
- /// VBROADCASTF128, ymm, m128
- /// </summary>
- public static unsafe Vector256<double> BroadcastVector128ToVector256(double* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_ceil_ps (__m256 a)
- /// VROUNDPS ymm, ymm/m256, imm8(10)
- /// </summary>
- public static Vector256<float> Ceiling(Vector256<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_ceil_pd (__m256d a)
- /// VROUNDPD ymm, ymm/m256, imm8(10)
- /// </summary>
- public static Vector256<double> Ceiling(Vector256<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmp_ps (__m128 a, __m128 b, const int imm8)
- /// VCMPPS xmm, xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<float> Compare(Vector128<float> left, Vector128<float> right, FloatComparisonMode mode) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_cmp_pd (__m128d a, __m128d b, const int imm8)
- /// VCMPPD xmm, xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<double> Compare(Vector128<double> left, Vector128<double> right, FloatComparisonMode mode) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_cmp_ps (__m256 a, __m256 b, const int imm8)
- /// VCMPPS ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<float> Compare(Vector256<float> left, Vector256<float> right, FloatComparisonMode mode) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_cmp_pd (__m256d a, __m256d b, const int imm8)
- /// VCMPPD ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<double> Compare(Vector256<double> left, Vector256<double> right, FloatComparisonMode mode) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmp_sd (__m128d a, __m128d b, const int imm8)
- /// VCMPSS xmm, xmm, xmm/m32, imm8
- /// </summary>
- public static Vector128<double> CompareScalar(Vector128<double> left, Vector128<double> right, FloatComparisonMode mode) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_cmp_ss (__m128 a, __m128 b, const int imm8)
- /// VCMPSD xmm, xmm, xmm/m64, imm8
- /// </summary>
- public static Vector128<float> CompareScalar(Vector128<float> left, Vector128<float> right, FloatComparisonMode mode) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_cvtpd_epi32 (__m256d a)
- /// VCVTPD2DQ xmm, ymm/m256
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector256<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm256_cvtpd_ps (__m256d a)
- /// VCVTPD2PS xmm, ymm/m256
- /// </summary>
- public static Vector128<float> ConvertToVector128Single(Vector256<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtps_epi32 (__m256 a)
- /// VCVTPS2DQ ymm, ymm/m256
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32(Vector256<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_cvtepi32_ps (__m256i a)
- /// VCVTDQ2PS ymm, ymm/m256
- /// </summary>
- public static Vector256<float> ConvertToVector256Single(Vector256<int> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_cvtps_pd (__m128 a)
- /// VCVTPS2PD ymm, xmm/m128
- /// </summary>
- public static Vector256<double> ConvertToVector256Double(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_cvtepi32_pd (__m128i a)
- /// VCVTDQ2PD ymm, xmm/m128
- /// </summary>
- public static Vector256<double> ConvertToVector256Double(Vector128<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_cvttpd_epi32 (__m256d a)
- /// VCVTTPD2DQ xmm, ymm/m256
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32WithTruncation(Vector256<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvttps_epi32 (__m256 a)
- /// VCVTTPS2DQ ymm, ymm/m256
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32WithTruncation(Vector256<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_div_ps (__m256 a, __m256 b)
- /// VDIVPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Divide(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_div_pd (__m256d a, __m256d b)
- /// VDIVPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Divide(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_dp_ps (__m256 a, __m256 b, const int imm8)
- /// VDPPS ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<float> DotProduct(Vector256<float> left, Vector256<float> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_moveldup_ps (__m256 a)
- /// VMOVSLDUP ymm, ymm/m256
- /// </summary>
- public static Vector256<float> DuplicateEvenIndexed(Vector256<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_movedup_pd (__m256d a)
- /// VMOVDDUP ymm, ymm/m256
- /// </summary>
- public static Vector256<double> DuplicateEvenIndexed(Vector256<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_movehdup_ps (__m256 a)
- /// VMOVSHDUP ymm, ymm/m256
- /// </summary>
- public static Vector256<float> DuplicateOddIndexed(Vector256<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<byte> ExtractVector128(Vector256<byte> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<sbyte> ExtractVector128(Vector256<sbyte> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<short> ExtractVector128(Vector256<short> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<ushort> ExtractVector128(Vector256<ushort> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<int> ExtractVector128(Vector256<int> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<uint> ExtractVector128(Vector256<uint> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<long> ExtractVector128(Vector256<long> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<ulong> ExtractVector128(Vector256<ulong> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm256_extractf128_ps (__m256 a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<float> ExtractVector128(Vector256<float> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm256_extractf128_pd (__m256d a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<double> ExtractVector128(Vector256<double> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_floor_ps (__m256 a)
- /// VROUNDPS ymm, ymm/m256, imm8(9)
- /// </summary>
- public static Vector256<float> Floor(Vector256<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_floor_pd (__m256d a)
- /// VROUNDPS ymm, ymm/m256, imm8(9)
- /// </summary>
- public static Vector256<double> Floor(Vector256<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_hadd_ps (__m256 a, __m256 b)
- /// VHADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> HorizontalAdd(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_hadd_pd (__m256d a, __m256d b)
- /// VHADDPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> HorizontalAdd(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_hsub_ps (__m256 a, __m256 b)
- /// VHSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> HorizontalSubtract(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_hsub_pd (__m256d a, __m256d b)
- /// VHSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> HorizontalSubtract(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<byte> InsertVector128(Vector256<byte> value, Vector128<byte> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<sbyte> InsertVector128(Vector256<sbyte> value, Vector128<sbyte> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<short> InsertVector128(Vector256<short> value, Vector128<short> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<ushort> InsertVector128(Vector256<ushort> value, Vector128<ushort> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<int> InsertVector128(Vector256<int> value, Vector128<int> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<uint> InsertVector128(Vector256<uint> value, Vector128<uint> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<long> InsertVector128(Vector256<long> value, Vector128<long> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<ulong> InsertVector128(Vector256<ulong> value, Vector128<ulong> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_insertf128_ps (__m256 a, __m128 b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<float> InsertVector128(Vector256<float> value, Vector128<float> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256d _mm256_insertf128_pd (__m256d a, __m128d b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<double> InsertVector128(Vector256<double> value, Vector128<double> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<sbyte> LoadVector256(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<byte> LoadVector256(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<short> LoadVector256(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<ushort> LoadVector256(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<int> LoadVector256(int* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<uint> LoadVector256(uint* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<long> LoadVector256(long* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<ulong> LoadVector256(ulong* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_loadu_ps (float const * mem_addr)
- /// VMOVUPS ymm, ymm/m256
- /// </summary>
- public static unsafe Vector256<float> LoadVector256(float* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_loadu_pd (double const * mem_addr)
- /// VMOVUPD ymm, ymm/m256
- /// </summary>
- public static unsafe Vector256<double> LoadVector256(double* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<sbyte> LoadAlignedVector256(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<byte> LoadAlignedVector256(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<short> LoadAlignedVector256(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<ushort> LoadAlignedVector256(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<int> LoadAlignedVector256(int* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<uint> LoadAlignedVector256(uint* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<long> LoadAlignedVector256(long* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<ulong> LoadAlignedVector256(ulong* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_load_ps (float const * mem_addr)
- /// VMOVAPS ymm, ymm/m256
- /// </summary>
- public static unsafe Vector256<float> LoadAlignedVector256(float* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_load_pd (double const * mem_addr)
- /// VMOVAPD ymm, ymm/m256
- /// </summary>
- public static unsafe Vector256<double> LoadAlignedVector256(double* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<sbyte> LoadDquVector256(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<byte> LoadDquVector256(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<short> LoadDquVector256(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<ushort> LoadDquVector256(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<int> LoadDquVector256(int* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<uint> LoadDquVector256(uint* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<long> LoadDquVector256(long* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<ulong> LoadDquVector256(ulong* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_maskload_ps (float const * mem_addr, __m128i mask)
- /// VMASKMOVPS xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<float> MaskLoad(float* address, Vector128<float> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_maskload_pd (double const * mem_addr, __m128i mask)
- /// VMASKMOVPD xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<double> MaskLoad(double* address, Vector128<double> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_maskload_ps (float const * mem_addr, __m256i mask)
- /// VMASKMOVPS ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<float> MaskLoad(float* address, Vector256<float> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_maskload_pd (double const * mem_addr, __m256i mask)
- /// VMASKMOVPD ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<double> MaskLoad(double* address, Vector256<double> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_maskstore_ps (float * mem_addr, __m128i mask, __m128 a)
- /// VMASKMOVPS m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(float* address, Vector128<float> mask, Vector128<float> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_maskstore_pd (double * mem_addr, __m128i mask, __m128d a)
- /// VMASKMOVPD m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(double* address, Vector128<double> mask, Vector128<double> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm256_maskstore_ps (float * mem_addr, __m256i mask, __m256 a)
- /// VMASKMOVPS m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(float* address, Vector256<float> mask, Vector256<float> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_maskstore_pd (double * mem_addr, __m256i mask, __m256d a)
- /// VMASKMOVPD m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(double* address, Vector256<double> mask, Vector256<double> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_max_ps (__m256 a, __m256 b)
- /// VMAXPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Max(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_max_pd (__m256d a, __m256d b)
- /// VMAXPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Max(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_min_ps (__m256 a, __m256 b)
- /// VMINPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Min(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_min_pd (__m256d a, __m256d b)
- /// VMINPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Min(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_movemask_ps (__m256 a)
- /// VMOVMSKPS reg, ymm
- /// </summary>
- public static int MoveMask(Vector256<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm256_movemask_pd (__m256d a)
- /// VMOVMSKPD reg, ymm
- /// </summary>
- public static int MoveMask(Vector256<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_mul_ps (__m256 a, __m256 b)
- /// VMULPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Multiply(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_mul_pd (__m256d a, __m256d b)
- /// VMULPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Multiply(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_or_ps (__m256 a, __m256 b)
- /// VORPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Or(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_or_pd (__m256d a, __m256d b)
- /// VORPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Or(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_permute_ps (__m128 a, int imm8)
- /// VPERMILPS xmm, xmm, imm8
- /// </summary>
- public static Vector128<float> Permute(Vector128<float> value, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_permute_pd (__m128d a, int imm8)
- /// VPERMILPD xmm, xmm, imm8
- /// </summary>
- public static Vector128<double> Permute(Vector128<double> value, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_permute_ps (__m256 a, int imm8)
- /// VPERMILPS ymm, ymm, imm8
- /// </summary>
- public static Vector256<float> Permute(Vector256<float> value, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_permute_pd (__m256d a, int imm8)
- /// VPERMILPD ymm, ymm, imm8
- /// </summary>
- public static Vector256<double> Permute(Vector256<double> value, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<byte> Permute2x128(Vector256<byte> left, Vector256<byte> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<sbyte> Permute2x128(Vector256<sbyte> left, Vector256<sbyte> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<short> Permute2x128(Vector256<short> left, Vector256<short> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ushort> Permute2x128(Vector256<ushort> left, Vector256<ushort> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<int> Permute2x128(Vector256<int> left, Vector256<int> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<uint> Permute2x128(Vector256<uint> left, Vector256<uint> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<long> Permute2x128(Vector256<long> left, Vector256<long> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ulong> Permute2x128(Vector256<ulong> left, Vector256<ulong> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_permute2f128_ps (__m256 a, __m256 b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<float> Permute2x128(Vector256<float> left, Vector256<float> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256d _mm256_permute2f128_pd (__m256d a, __m256d b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<double> Permute2x128(Vector256<double> left, Vector256<double> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_permutevar_ps (__m128 a, __m128i b)
- /// VPERMILPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> PermuteVar(Vector128<float> left, Vector128<int> control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_permutevar_pd (__m128d a, __m128i b)
- /// VPERMILPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> PermuteVar(Vector128<double> left, Vector128<long> control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_permutevar_ps (__m256 a, __m256i b)
- /// VPERMILPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> PermuteVar(Vector256<float> left, Vector256<int> control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_permutevar_pd (__m256d a, __m256i b)
- /// VPERMILPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> PermuteVar(Vector256<double> left, Vector256<long> control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_rcp_ps (__m256 a)
- /// VRCPPS ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Reciprocal(Vector256<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_rsqrt_ps (__m256 a)
- /// VRSQRTPS ymm, ymm/m256
- /// </summary>
- public static Vector256<float> ReciprocalSqrt(Vector256<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_round_ps (__m256 a, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)
- /// VROUNDPS ymm, ymm/m256, imm8(8)
- /// </summary>
- public static Vector256<float> RoundToNearestInteger(Vector256<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_round_ps (__m256 a, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)
- /// VROUNDPS ymm, ymm/m256, imm8(9)
- /// </summary>
- public static Vector256<float> RoundToNegativeInfinity(Vector256<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_round_ps (__m256 a, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)
- /// VROUNDPS ymm, ymm/m256, imm8(10)
- /// </summary>
- public static Vector256<float> RoundToPositiveInfinity(Vector256<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_round_ps (__m256 a, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC)
- /// VROUNDPS ymm, ymm/m256, imm8(11)
- /// </summary>
- public static Vector256<float> RoundToZero(Vector256<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_round_ps (__m256 a, _MM_FROUND_CUR_DIRECTION)
- /// VROUNDPS ymm, ymm/m256, imm8(4)
- /// </summary>
- public static Vector256<float> RoundCurrentDirection(Vector256<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256d _mm256_round_pd (__m256d a, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)
- /// VROUNDPD ymm, ymm/m256, imm8(8)
- /// </summary>
- public static Vector256<double> RoundToNearestInteger(Vector256<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_round_pd (__m256d a, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)
- /// VROUNDPD ymm, ymm/m256, imm8(9)
- /// </summary>
- public static Vector256<double> RoundToNegativeInfinity(Vector256<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_round_pd (__m256d a, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)
- /// VROUNDPD ymm, ymm/m256, imm8(10)
- /// </summary>
- public static Vector256<double> RoundToPositiveInfinity(Vector256<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_round_pd (__m256d a, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC)
- /// VROUNDPD ymm, ymm/m256, imm8(11)
- /// </summary>
- public static Vector256<double> RoundToZero(Vector256<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_round_pd (__m256d a, _MM_FROUND_CUR_DIRECTION)
- /// VROUNDPD ymm, ymm/m256, imm8(4)
- /// </summary>
- public static Vector256<double> RoundCurrentDirection(Vector256<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_shuffle_ps (__m256 a, __m256 b, const int imm8)
- /// VSHUFPS ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<float> Shuffle(Vector256<float> value, Vector256<float> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_shuffle_pd (__m256d a, __m256d b, const int imm8)
- /// VSHUFPD ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<double> Shuffle(Vector256<double> value, Vector256<double> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_sqrt_ps (__m256 a)
- /// VSQRTPS ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Sqrt(Vector256<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_sqrt_pd (__m256d a)
- /// VSQRTPD ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Sqrt(Vector256<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(sbyte* address, Vector256<sbyte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(byte* address, Vector256<byte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(short* address, Vector256<short> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(ushort* address, Vector256<ushort> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(int* address, Vector256<int> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(uint* address, Vector256<uint> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(long* address, Vector256<long> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(ulong* address, Vector256<ulong> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_store_ps (float * mem_addr, __m256 a)
- /// VMOVAPS m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(float* address, Vector256<float> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_store_pd (double * mem_addr, __m256d a)
- /// VMOVAPD m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(double* address, Vector256<double> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(sbyte* address, Vector256<sbyte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(byte* address, Vector256<byte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(short* address, Vector256<short> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(ushort* address, Vector256<ushort> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(int* address, Vector256<int> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(uint* address, Vector256<uint> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(long* address, Vector256<long> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(ulong* address, Vector256<ulong> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_stream_ps (float * mem_addr, __m256 a)
- /// MOVNTPS m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(float* address, Vector256<float> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_stream_pd (double * mem_addr, __m256d a)
- /// MOVNTPD m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(double* address, Vector256<double> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(sbyte* address, Vector256<sbyte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(byte* address, Vector256<byte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(short* address, Vector256<short> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(ushort* address, Vector256<ushort> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(int* address, Vector256<int> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(uint* address, Vector256<uint> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(long* address, Vector256<long> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(ulong* address, Vector256<ulong> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_storeu_ps (float * mem_addr, __m256 a)
- /// MOVUPS m256, ymm
- /// </summary>
- public static unsafe void Store(float* address, Vector256<float> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_storeu_pd (double * mem_addr, __m256d a)
- /// MOVUPD m256, ymm
- /// </summary>
- public static unsafe void Store(double* address, Vector256<double> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_sub_ps (__m256 a, __m256 b)
- /// VSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Subtract(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_sub_pd (__m256d a, __m256d b)
- /// VSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Subtract(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_testc_ps (__m128 a, __m128 b)
- /// VTESTPS xmm, xmm/m128
- /// </summary>
- public static bool TestC(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm_testc_pd (__m128d a, __m128d b)
- /// VTESTPD xmm, xmm/m128
- /// </summary>
- public static bool TestC(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testc_ps (__m256 a, __m256 b)
- /// VTESTPS ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testc_pd (__m256d a, __m256d b)
- /// VTESTPS ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_testnzc_ps (__m128 a, __m128 b)
- /// VTESTPS xmm, xmm/m128
- /// </summary>
- public static bool TestNotZAndNotC(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm_testnzc_pd (__m128d a, __m128d b)
- /// VTESTPD xmm, xmm/m128
- /// </summary>
- public static bool TestNotZAndNotC(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testnzc_ps (__m256 a, __m256 b)
- /// VTESTPS ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testnzc_pd (__m256d a, __m256d b)
- /// VTESTPD ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_testz_ps (__m128 a, __m128 b)
- /// VTESTPS xmm, xmm/m128
- /// </summary>
- public static bool TestZ(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm_testz_pd (__m128d a, __m128d b)
- /// VTESTPD xmm, xmm/m128
- /// </summary>
- public static bool TestZ(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testz_ps (__m256 a, __m256 b)
- /// VTESTPS ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_testz_pd (__m256d a, __m256d b)
- /// VTESTPD ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_unpackhi_ps (__m256 a, __m256 b)
- /// VUNPCKHPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> UnpackHigh(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_unpackhi_pd (__m256d a, __m256d b)
- /// VUNPCKHPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> UnpackHigh(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_unpacklo_ps (__m256 a, __m256 b)
- /// VUNPCKLPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> UnpackLow(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_unpacklo_pd (__m256d a, __m256d b)
- /// VUNPCKLPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> UnpackLow(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_xor_ps (__m256 a, __m256 b)
- /// VXORPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Xor(Vector256<float> left, Vector256<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_xor_pd (__m256d a, __m256d b)
- /// VXORPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Xor(Vector256<double> left, Vector256<double> right) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx.cs
deleted file mode 100644
index cf12b20bd21..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx.cs
+++ /dev/null
@@ -1,1226 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel AVX hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Avx : Sse42
- {
- internal Avx() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// __m256 _mm256_add_ps (__m256 a, __m256 b)
- /// VADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Add(Vector256<float> left, Vector256<float> right) => Add(left, right);
- /// <summary>
- /// __m256d _mm256_add_pd (__m256d a, __m256d b)
- /// VADDPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Add(Vector256<double> left, Vector256<double> right) => Add(left, right);
-
- /// <summary>
- /// __m256 _mm256_addsub_ps (__m256 a, __m256 b)
- /// VADDSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> AddSubtract(Vector256<float> left, Vector256<float> right) => AddSubtract(left, right);
- /// <summary>
- /// __m256d _mm256_addsub_pd (__m256d a, __m256d b)
- /// VADDSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> AddSubtract(Vector256<double> left, Vector256<double> right) => AddSubtract(left, right);
-
- /// <summary>
- /// __m256 _mm256_and_ps (__m256 a, __m256 b)
- /// VANDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> And(Vector256<float> left, Vector256<float> right) => And(left, right);
- /// <summary>
- /// __m256d _mm256_and_pd (__m256d a, __m256d b)
- /// VANDPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> And(Vector256<double> left, Vector256<double> right) => And(left, right);
-
- /// <summary>
- /// __m256 _mm256_andnot_ps (__m256 a, __m256 b)
- /// VANDNPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> AndNot(Vector256<float> left, Vector256<float> right) => AndNot(left, right);
- /// <summary>
- /// __m256d _mm256_andnot_pd (__m256d a, __m256d b)
- /// VANDNPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> AndNot(Vector256<double> left, Vector256<double> right) => AndNot(left, right);
-
- /// <summary>
- /// __m256 _mm256_blend_ps (__m256 a, __m256 b, const int imm8)
- /// VBLENDPS ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<float> Blend(Vector256<float> left, Vector256<float> right, byte control) => Blend(left, right, control);
- /// <summary>
- /// __m256d _mm256_blend_pd (__m256d a, __m256d b, const int imm8)
- /// VBLENDPD ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<double> Blend(Vector256<double> left, Vector256<double> right, byte control) => Blend(left, right, control);
-
- /// <summary>
- /// __m256 _mm256_blendv_ps (__m256 a, __m256 b, __m256 mask)
- /// VBLENDVPS ymm, ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<float> BlendVariable(Vector256<float> left, Vector256<float> right, Vector256<float> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m256d _mm256_blendv_pd (__m256d a, __m256d b, __m256d mask)
- /// VBLENDVPD ymm, ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<double> BlendVariable(Vector256<double> left, Vector256<double> right, Vector256<double> mask) => BlendVariable(left, right, mask);
-
- /// <summary>
- /// __m128 _mm_broadcast_ss (float const * mem_addr)
- /// VBROADCASTSS xmm, m32
- /// </summary>
- public static unsafe Vector128<float> BroadcastScalarToVector128(float* source) => BroadcastScalarToVector128(source);
-
- /// <summary>
- /// __m256 _mm256_broadcast_ss (float const * mem_addr)
- /// VBROADCASTSS ymm, m32
- /// </summary>
- public static unsafe Vector256<float> BroadcastScalarToVector256(float* source) => BroadcastScalarToVector256(source);
- /// <summary>
- /// __m256d _mm256_broadcast_sd (double const * mem_addr)
- /// VBROADCASTSD ymm, m64
- /// </summary>
- public static unsafe Vector256<double> BroadcastScalarToVector256(double* source) => BroadcastScalarToVector256(source);
-
- /// <summary>
- /// __m256 _mm256_broadcast_ps (__m128 const * mem_addr)
- /// VBROADCASTF128, ymm, m128
- /// </summary>
- public static unsafe Vector256<float> BroadcastVector128ToVector256(float* address) => BroadcastVector128ToVector256(address);
- /// <summary>
- /// __m256d _mm256_broadcast_pd (__m128d const * mem_addr)
- /// VBROADCASTF128, ymm, m128
- /// </summary>
- public static unsafe Vector256<double> BroadcastVector128ToVector256(double* address) => BroadcastVector128ToVector256(address);
-
- /// <summary>
- /// __m256 _mm256_ceil_ps (__m256 a)
- /// VROUNDPS ymm, ymm/m256, imm8(10)
- /// </summary>
- public static Vector256<float> Ceiling(Vector256<float> value) => Ceiling(value);
- /// <summary>
- /// __m256d _mm256_ceil_pd (__m256d a)
- /// VROUNDPD ymm, ymm/m256, imm8(10)
- /// </summary>
- public static Vector256<double> Ceiling(Vector256<double> value) => Ceiling(value);
-
- /// <summary>
- /// __m128 _mm_cmp_ps (__m128 a, __m128 b, const int imm8)
- /// VCMPPS xmm, xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<float> Compare(Vector128<float> left, Vector128<float> right, FloatComparisonMode mode) => Compare(left, right, mode);
- /// <summary>
- /// __m128d _mm_cmp_pd (__m128d a, __m128d b, const int imm8)
- /// VCMPPD xmm, xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<double> Compare(Vector128<double> left, Vector128<double> right, FloatComparisonMode mode) => Compare(left, right, mode);
- /// <summary>
- /// __m256 _mm256_cmp_ps (__m256 a, __m256 b, const int imm8)
- /// VCMPPS ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<float> Compare(Vector256<float> left, Vector256<float> right, FloatComparisonMode mode) => Compare(left, right, mode);
- /// <summary>
- /// __m256d _mm256_cmp_pd (__m256d a, __m256d b, const int imm8)
- /// VCMPPD ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<double> Compare(Vector256<double> left, Vector256<double> right, FloatComparisonMode mode) => Compare(left, right, mode);
-
- /// <summary>
- /// __m128d _mm_cmp_sd (__m128d a, __m128d b, const int imm8)
- /// VCMPSS xmm, xmm, xmm/m32, imm8
- /// </summary>
- public static Vector128<double> CompareScalar(Vector128<double> left, Vector128<double> right, FloatComparisonMode mode) => CompareScalar(left, right, mode);
- /// <summary>
- /// __m128 _mm_cmp_ss (__m128 a, __m128 b, const int imm8)
- /// VCMPSD xmm, xmm, xmm/m64, imm8
- /// </summary>
- public static Vector128<float> CompareScalar(Vector128<float> left, Vector128<float> right, FloatComparisonMode mode) => CompareScalar(left, right, mode);
-
- /// <summary>
- /// __m128i _mm256_cvtpd_epi32 (__m256d a)
- /// VCVTPD2DQ xmm, ymm/m256
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector256<double> value) => ConvertToVector128Int32(value);
- /// <summary>
- /// __m128 _mm256_cvtpd_ps (__m256d a)
- /// VCVTPD2PS xmm, ymm/m256
- /// </summary>
- public static Vector128<float> ConvertToVector128Single(Vector256<double> value) => ConvertToVector128Single(value);
- /// <summary>
- /// __m256i _mm256_cvtps_epi32 (__m256 a)
- /// VCVTPS2DQ ymm, ymm/m256
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32(Vector256<float> value) => ConvertToVector256Int32(value);
- /// <summary>
- /// __m256 _mm256_cvtepi32_ps (__m256i a)
- /// VCVTDQ2PS ymm, ymm/m256
- /// </summary>
- public static Vector256<float> ConvertToVector256Single(Vector256<int> value) => ConvertToVector256Single(value);
- /// <summary>
- /// __m256d _mm256_cvtps_pd (__m128 a)
- /// VCVTPS2PD ymm, xmm/m128
- /// </summary>
- public static Vector256<double> ConvertToVector256Double(Vector128<float> value) => ConvertToVector256Double(value);
- /// <summary>
- /// __m256d _mm256_cvtepi32_pd (__m128i a)
- /// VCVTDQ2PD ymm, xmm/m128
- /// </summary>
- public static Vector256<double> ConvertToVector256Double(Vector128<int> value) => ConvertToVector256Double(value);
-
- /// <summary>
- /// __m128i _mm256_cvttpd_epi32 (__m256d a)
- /// VCVTTPD2DQ xmm, ymm/m256
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32WithTruncation(Vector256<double> value) => ConvertToVector128Int32WithTruncation(value);
- /// <summary>
- /// __m256i _mm256_cvttps_epi32 (__m256 a)
- /// VCVTTPS2DQ ymm, ymm/m256
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32WithTruncation(Vector256<float> value) => ConvertToVector256Int32WithTruncation(value);
-
- /// <summary>
- /// __m256 _mm256_div_ps (__m256 a, __m256 b)
- /// VDIVPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Divide(Vector256<float> left, Vector256<float> right) => Divide(left, right);
- /// <summary>
- /// __m256d _mm256_div_pd (__m256d a, __m256d b)
- /// VDIVPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Divide(Vector256<double> left, Vector256<double> right) => Divide(left, right);
-
- /// <summary>
- /// __m256 _mm256_dp_ps (__m256 a, __m256 b, const int imm8)
- /// VDPPS ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<float> DotProduct(Vector256<float> left, Vector256<float> right, byte control) => DotProduct(left, right, control);
-
- /// <summary>
- /// __m256 _mm256_moveldup_ps (__m256 a)
- /// VMOVSLDUP ymm, ymm/m256
- /// </summary>
- public static Vector256<float> DuplicateEvenIndexed(Vector256<float> value) => DuplicateEvenIndexed(value);
- /// <summary>
- /// __m256d _mm256_movedup_pd (__m256d a)
- /// VMOVDDUP ymm, ymm/m256
- /// </summary>
- public static Vector256<double> DuplicateEvenIndexed(Vector256<double> value) => DuplicateEvenIndexed(value);
-
- /// <summary>
- /// __m256 _mm256_movehdup_ps (__m256 a)
- /// VMOVSHDUP ymm, ymm/m256
- /// </summary>
- public static Vector256<float> DuplicateOddIndexed(Vector256<float> value) => DuplicateOddIndexed(value);
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<byte> ExtractVector128(Vector256<byte> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<sbyte> ExtractVector128(Vector256<sbyte> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<short> ExtractVector128(Vector256<short> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<ushort> ExtractVector128(Vector256<ushort> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<int> ExtractVector128(Vector256<int> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<uint> ExtractVector128(Vector256<uint> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<long> ExtractVector128(Vector256<long> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<ulong> ExtractVector128(Vector256<ulong> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128 _mm256_extractf128_ps (__m256 a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<float> ExtractVector128(Vector256<float> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128d _mm256_extractf128_pd (__m256d a, const int imm8)
- /// VEXTRACTF128 xmm/m128, ymm, imm8
- /// </summary>
- public static Vector128<double> ExtractVector128(Vector256<double> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m256 _mm256_floor_ps (__m256 a)
- /// VROUNDPS ymm, ymm/m256, imm8(9)
- /// </summary>
- public static Vector256<float> Floor(Vector256<float> value) => Floor(value);
- /// <summary>
- /// __m256d _mm256_floor_pd (__m256d a)
- /// VROUNDPS ymm, ymm/m256, imm8(9)
- /// </summary>
- public static Vector256<double> Floor(Vector256<double> value) => Floor(value);
-
- /// <summary>
- /// __m256 _mm256_hadd_ps (__m256 a, __m256 b)
- /// VHADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> HorizontalAdd(Vector256<float> left, Vector256<float> right) => HorizontalAdd(left, right);
- /// <summary>
- /// __m256d _mm256_hadd_pd (__m256d a, __m256d b)
- /// VHADDPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> HorizontalAdd(Vector256<double> left, Vector256<double> right) => HorizontalAdd(left, right);
-
- /// <summary>
- /// __m256 _mm256_hsub_ps (__m256 a, __m256 b)
- /// VHSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> HorizontalSubtract(Vector256<float> left, Vector256<float> right) => HorizontalSubtract(left, right);
- /// <summary>
- /// __m256d _mm256_hsub_pd (__m256d a, __m256d b)
- /// VHSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> HorizontalSubtract(Vector256<double> left, Vector256<double> right) => HorizontalSubtract(left, right);
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<byte> InsertVector128(Vector256<byte> value, Vector128<byte> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<sbyte> InsertVector128(Vector256<sbyte> value, Vector128<sbyte> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<short> InsertVector128(Vector256<short> value, Vector128<short> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<ushort> InsertVector128(Vector256<ushort> value, Vector128<ushort> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<int> InsertVector128(Vector256<int> value, Vector128<int> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<uint> InsertVector128(Vector256<uint> value, Vector128<uint> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<long> InsertVector128(Vector256<long> value, Vector128<long> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<ulong> InsertVector128(Vector256<ulong> value, Vector128<ulong> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256 _mm256_insertf128_ps (__m256 a, __m128 b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<float> InsertVector128(Vector256<float> value, Vector128<float> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256d _mm256_insertf128_pd (__m256d a, __m128d b, int imm8)
- /// VINSERTF128 ymm, ymm, xmm/m128, imm8
- /// </summary>
- public static Vector256<double> InsertVector128(Vector256<double> value, Vector128<double> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<sbyte> LoadVector256(sbyte* address) => LoadVector256(address);
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<byte> LoadVector256(byte* address) => LoadVector256(address);
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<short> LoadVector256(short* address) => LoadVector256(address);
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<ushort> LoadVector256(ushort* address) => LoadVector256(address);
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<int> LoadVector256(int* address) => LoadVector256(address);
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<uint> LoadVector256(uint* address) => LoadVector256(address);
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<long> LoadVector256(long* address) => LoadVector256(address);
- /// <summary>
- /// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
- /// VMOVDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<ulong> LoadVector256(ulong* address) => LoadVector256(address);
- /// <summary>
- /// __m256 _mm256_loadu_ps (float const * mem_addr)
- /// VMOVUPS ymm, ymm/m256
- /// </summary>
- public static unsafe Vector256<float> LoadVector256(float* address) => LoadVector256(address);
- /// <summary>
- /// __m256d _mm256_loadu_pd (double const * mem_addr)
- /// VMOVUPD ymm, ymm/m256
- /// </summary>
- public static unsafe Vector256<double> LoadVector256(double* address) => LoadVector256(address);
-
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<sbyte> LoadAlignedVector256(sbyte* address) => LoadAlignedVector256(address);
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<byte> LoadAlignedVector256(byte* address) => LoadAlignedVector256(address);
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<short> LoadAlignedVector256(short* address) => LoadAlignedVector256(address);
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<ushort> LoadAlignedVector256(ushort* address) => LoadAlignedVector256(address);
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<int> LoadAlignedVector256(int* address) => LoadAlignedVector256(address);
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<uint> LoadAlignedVector256(uint* address) => LoadAlignedVector256(address);
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<long> LoadAlignedVector256(long* address) => LoadAlignedVector256(address);
- /// <summary>
- /// __m256i _mm256_load_si256 (__m256i const * mem_addr)
- /// VMOVDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<ulong> LoadAlignedVector256(ulong* address) => LoadAlignedVector256(address);
- /// <summary>
- /// __m256 _mm256_load_ps (float const * mem_addr)
- /// VMOVAPS ymm, ymm/m256
- /// </summary>
- public static unsafe Vector256<float> LoadAlignedVector256(float* address) => LoadAlignedVector256(address);
- /// <summary>
- /// __m256d _mm256_load_pd (double const * mem_addr)
- /// VMOVAPD ymm, ymm/m256
- /// </summary>
- public static unsafe Vector256<double> LoadAlignedVector256(double* address) => LoadAlignedVector256(address);
-
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<sbyte> LoadDquVector256(sbyte* address) => LoadDquVector256(address);
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<byte> LoadDquVector256(byte* address) => LoadDquVector256(address);
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<short> LoadDquVector256(short* address) => LoadDquVector256(address);
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<ushort> LoadDquVector256(ushort* address) => LoadDquVector256(address);
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<int> LoadDquVector256(int* address) => LoadDquVector256(address);
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<uint> LoadDquVector256(uint* address) => LoadDquVector256(address);
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<long> LoadDquVector256(long* address) => LoadDquVector256(address);
- /// <summary>
- /// __m256i _mm256_lddqu_si256 (__m256i const * mem_addr)
- /// VLDDQU ymm, m256
- /// </summary>
- public static unsafe Vector256<ulong> LoadDquVector256(ulong* address) => LoadDquVector256(address);
-
- /// <summary>
- /// __m128 _mm_maskload_ps (float const * mem_addr, __m128i mask)
- /// VMASKMOVPS xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<float> MaskLoad(float* address, Vector128<float> mask) => MaskLoad(address, mask);
- /// <summary>
- /// __m128d _mm_maskload_pd (double const * mem_addr, __m128i mask)
- /// VMASKMOVPD xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<double> MaskLoad(double* address, Vector128<double> mask) => MaskLoad(address, mask);
-
- /// <summary>
- /// __m256 _mm256_maskload_ps (float const * mem_addr, __m256i mask)
- /// VMASKMOVPS ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<float> MaskLoad(float* address, Vector256<float> mask) => MaskLoad(address, mask);
- /// <summary>
- /// __m256d _mm256_maskload_pd (double const * mem_addr, __m256i mask)
- /// VMASKMOVPD ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<double> MaskLoad(double* address, Vector256<double> mask) => MaskLoad(address, mask);
-
- /// <summary>
- /// void _mm_maskstore_ps (float * mem_addr, __m128i mask, __m128 a)
- /// VMASKMOVPS m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(float* address, Vector128<float> mask, Vector128<float> source) => MaskStore(address, mask, source);
- /// <summary>
- /// void _mm_maskstore_pd (double * mem_addr, __m128i mask, __m128d a)
- /// VMASKMOVPD m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(double* address, Vector128<double> mask, Vector128<double> source) => MaskStore(address, mask, source);
-
- /// <summary>
- /// void _mm256_maskstore_ps (float * mem_addr, __m256i mask, __m256 a)
- /// VMASKMOVPS m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(float* address, Vector256<float> mask, Vector256<float> source) => MaskStore(address, mask, source);
- /// <summary>
- /// void _mm256_maskstore_pd (double * mem_addr, __m256i mask, __m256d a)
- /// VMASKMOVPD m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(double* address, Vector256<double> mask, Vector256<double> source) => MaskStore(address, mask, source);
-
- /// <summary>
- /// __m256 _mm256_max_ps (__m256 a, __m256 b)
- /// VMAXPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Max(Vector256<float> left, Vector256<float> right) => Max(left, right);
- /// <summary>
- /// __m256d _mm256_max_pd (__m256d a, __m256d b)
- /// VMAXPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Max(Vector256<double> left, Vector256<double> right) => Max(left, right);
-
- /// <summary>
- /// __m256 _mm256_min_ps (__m256 a, __m256 b)
- /// VMINPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Min(Vector256<float> left, Vector256<float> right) => Min(left, right);
- /// <summary>
- /// __m256d _mm256_min_pd (__m256d a, __m256d b)
- /// VMINPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Min(Vector256<double> left, Vector256<double> right) => Min(left, right);
-
- /// <summary>
- /// int _mm256_movemask_ps (__m256 a)
- /// VMOVMSKPS reg, ymm
- /// </summary>
- public static int MoveMask(Vector256<float> value) => MoveMask(value);
- /// <summary>
- /// int _mm256_movemask_pd (__m256d a)
- /// VMOVMSKPD reg, ymm
- /// </summary>
- public static int MoveMask(Vector256<double> value) => MoveMask(value);
-
- /// <summary>
- /// __m256 _mm256_mul_ps (__m256 a, __m256 b)
- /// VMULPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Multiply(Vector256<float> left, Vector256<float> right) => Multiply(left, right);
- /// <summary>
- /// __m256d _mm256_mul_pd (__m256d a, __m256d b)
- /// VMULPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Multiply(Vector256<double> left, Vector256<double> right) => Multiply(left, right);
-
- /// <summary>
- /// __m256 _mm256_or_ps (__m256 a, __m256 b)
- /// VORPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Or(Vector256<float> left, Vector256<float> right) => Or(left, right);
- /// <summary>
- /// __m256d _mm256_or_pd (__m256d a, __m256d b)
- /// VORPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Or(Vector256<double> left, Vector256<double> right) => Or(left, right);
-
- /// <summary>
- /// __m128 _mm_permute_ps (__m128 a, int imm8)
- /// VPERMILPS xmm, xmm, imm8
- /// </summary>
- public static Vector128<float> Permute(Vector128<float> value, byte control) => Permute(value, control);
- /// <summary>
- /// __m128d _mm_permute_pd (__m128d a, int imm8)
- /// VPERMILPD xmm, xmm, imm8
- /// </summary>
- public static Vector128<double> Permute(Vector128<double> value, byte control) => Permute(value, control);
-
- /// <summary>
- /// __m256 _mm256_permute_ps (__m256 a, int imm8)
- /// VPERMILPS ymm, ymm, imm8
- /// </summary>
- public static Vector256<float> Permute(Vector256<float> value, byte control) => Permute(value, control);
- /// <summary>
- /// __m256d _mm256_permute_pd (__m256d a, int imm8)
- /// VPERMILPD ymm, ymm, imm8
- /// </summary>
- public static Vector256<double> Permute(Vector256<double> value, byte control) => Permute(value, control);
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<byte> Permute2x128(Vector256<byte> left, Vector256<byte> right, byte control) => Permute2x128(left, right, control);
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<sbyte> Permute2x128(Vector256<sbyte> left, Vector256<sbyte> right, byte control) => Permute2x128(left, right, control);
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<short> Permute2x128(Vector256<short> left, Vector256<short> right, byte control) => Permute2x128(left, right, control);
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ushort> Permute2x128(Vector256<ushort> left, Vector256<ushort> right, byte control) => Permute2x128(left, right, control);
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<int> Permute2x128(Vector256<int> left, Vector256<int> right, byte control) => Permute2x128(left, right, control);
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<uint> Permute2x128(Vector256<uint> left, Vector256<uint> right, byte control) => Permute2x128(left, right, control);
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<long> Permute2x128(Vector256<long> left, Vector256<long> right, byte control) => Permute2x128(left, right, control);
-
- /// <summary>
- /// __m256i _mm256_permute2f128_si256 (__m256i a, __m256i b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ulong> Permute2x128(Vector256<ulong> left, Vector256<ulong> right, byte control) => Permute2x128(left, right, control);
- /// <summary>
- /// __m256 _mm256_permute2f128_ps (__m256 a, __m256 b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<float> Permute2x128(Vector256<float> left, Vector256<float> right, byte control) => Permute2x128(left, right, control);
-
- /// <summary>
- /// __m256d _mm256_permute2f128_pd (__m256d a, __m256d b, int imm8)
- /// VPERM2F128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<double> Permute2x128(Vector256<double> left, Vector256<double> right, byte control) => Permute2x128(left, right, control);
-
- /// <summary>
- /// __m128 _mm_permutevar_ps (__m128 a, __m128i b)
- /// VPERMILPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> PermuteVar(Vector128<float> left, Vector128<int> control) => PermuteVar(left, control);
- /// <summary>
- /// __m128d _mm_permutevar_pd (__m128d a, __m128i b)
- /// VPERMILPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> PermuteVar(Vector128<double> left, Vector128<long> control) => PermuteVar(left, control);
- /// <summary>
- /// __m256 _mm256_permutevar_ps (__m256 a, __m256i b)
- /// VPERMILPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> PermuteVar(Vector256<float> left, Vector256<int> control) => PermuteVar(left, control);
- /// <summary>
- /// __m256d _mm256_permutevar_pd (__m256d a, __m256i b)
- /// VPERMILPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> PermuteVar(Vector256<double> left, Vector256<long> control) => PermuteVar(left, control);
-
- /// <summary>
- /// __m256 _mm256_rcp_ps (__m256 a)
- /// VRCPPS ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Reciprocal(Vector256<float> value) => Reciprocal(value);
-
- /// <summary>
- /// __m256 _mm256_rsqrt_ps (__m256 a)
- /// VRSQRTPS ymm, ymm/m256
- /// </summary>
- public static Vector256<float> ReciprocalSqrt(Vector256<float> value) => ReciprocalSqrt(value);
-
- /// <summary>
- /// __m256 _mm256_round_ps (__m256 a, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)
- /// VROUNDPS ymm, ymm/m256, imm8(8)
- /// </summary>
- public static Vector256<float> RoundToNearestInteger(Vector256<float> value) => RoundToNearestInteger(value);
- /// <summary>
- /// __m256 _mm256_round_ps (__m256 a, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)
- /// VROUNDPS ymm, ymm/m256, imm8(9)
- /// </summary>
- public static Vector256<float> RoundToNegativeInfinity(Vector256<float> value) => RoundToNegativeInfinity(value);
- /// <summary>
- /// __m256 _mm256_round_ps (__m256 a, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)
- /// VROUNDPS ymm, ymm/m256, imm8(10)
- /// </summary>
- public static Vector256<float> RoundToPositiveInfinity(Vector256<float> value) => RoundToPositiveInfinity(value);
- /// <summary>
- /// __m256 _mm256_round_ps (__m256 a, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC)
- /// VROUNDPS ymm, ymm/m256, imm8(11)
- /// </summary>
- public static Vector256<float> RoundToZero(Vector256<float> value) => RoundToZero(value);
- /// <summary>
- /// __m256 _mm256_round_ps (__m256 a, _MM_FROUND_CUR_DIRECTION)
- /// VROUNDPS ymm, ymm/m256, imm8(4)
- /// </summary>
- public static Vector256<float> RoundCurrentDirection(Vector256<float> value) => RoundCurrentDirection(value);
-
- /// <summary>
- /// __m256d _mm256_round_pd (__m256d a, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)
- /// VROUNDPD ymm, ymm/m256, imm8(8)
- /// </summary>
- public static Vector256<double> RoundToNearestInteger(Vector256<double> value) => RoundToNearestInteger(value);
- /// <summary>
- /// __m256d _mm256_round_pd (__m256d a, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)
- /// VROUNDPD ymm, ymm/m256, imm8(9)
- /// </summary>
- public static Vector256<double> RoundToNegativeInfinity(Vector256<double> value) => RoundToNegativeInfinity(value);
- /// <summary>
- /// __m256d _mm256_round_pd (__m256d a, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)
- /// VROUNDPD ymm, ymm/m256, imm8(10)
- /// </summary>
- public static Vector256<double> RoundToPositiveInfinity(Vector256<double> value) => RoundToPositiveInfinity(value);
- /// <summary>
- /// __m256d _mm256_round_pd (__m256d a, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC)
- /// VROUNDPD ymm, ymm/m256, imm8(11)
- /// </summary>
- public static Vector256<double> RoundToZero(Vector256<double> value) => RoundToZero(value);
- /// <summary>
- /// __m256d _mm256_round_pd (__m256d a, _MM_FROUND_CUR_DIRECTION)
- /// VROUNDPD ymm, ymm/m256, imm8(4)
- /// </summary>
- public static Vector256<double> RoundCurrentDirection(Vector256<double> value) => RoundCurrentDirection(value);
-
- /// <summary>
- /// __m256 _mm256_shuffle_ps (__m256 a, __m256 b, const int imm8)
- /// VSHUFPS ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<float> Shuffle(Vector256<float> value, Vector256<float> right, byte control) => Shuffle(value, right, control);
- /// <summary>
- /// __m256d _mm256_shuffle_pd (__m256d a, __m256d b, const int imm8)
- /// VSHUFPD ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<double> Shuffle(Vector256<double> value, Vector256<double> right, byte control) => Shuffle(value, right, control);
-
- /// <summary>
- /// __m256 _mm256_sqrt_ps (__m256 a)
- /// VSQRTPS ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Sqrt(Vector256<float> value) => Sqrt(value);
- /// <summary>
- /// __m256d _mm256_sqrt_pd (__m256d a)
- /// VSQRTPD ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Sqrt(Vector256<double> value) => Sqrt(value);
-
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(sbyte* address, Vector256<sbyte> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(byte* address, Vector256<byte> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(short* address, Vector256<short> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(ushort* address, Vector256<ushort> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(int* address, Vector256<int> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(uint* address, Vector256<uint> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(long* address, Vector256<long> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm256_store_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQA m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(ulong* address, Vector256<ulong> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm256_store_ps (float * mem_addr, __m256 a)
- /// VMOVAPS m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(float* address, Vector256<float> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm256_store_pd (double * mem_addr, __m256d a)
- /// VMOVAPD m256, ymm
- /// </summary>
- public static unsafe void StoreAligned(double* address, Vector256<double> source) => StoreAligned(address, source);
-
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(sbyte* address, Vector256<sbyte> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(byte* address, Vector256<byte> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(short* address, Vector256<short> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(ushort* address, Vector256<ushort> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(int* address, Vector256<int> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(uint* address, Vector256<uint> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(long* address, Vector256<long> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm256_stream_si256 (__m256i * mem_addr, __m256i a)
- /// VMOVNTDQ m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(ulong* address, Vector256<ulong> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm256_stream_ps (float * mem_addr, __m256 a)
- /// MOVNTPS m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(float* address, Vector256<float> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm256_stream_pd (double * mem_addr, __m256d a)
- /// MOVNTPD m256, ymm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(double* address, Vector256<double> source) => StoreAlignedNonTemporal(address, source);
-
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(sbyte* address, Vector256<sbyte> source) => Store(address, source);
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(byte* address, Vector256<byte> source) => Store(address, source);
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(short* address, Vector256<short> source) => Store(address, source);
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(ushort* address, Vector256<ushort> source) => Store(address, source);
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(int* address, Vector256<int> source) => Store(address, source);
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(uint* address, Vector256<uint> source) => Store(address, source);
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(long* address, Vector256<long> source) => Store(address, source);
- /// <summary>
- /// void _mm256_storeu_si256 (__m256i * mem_addr, __m256i a)
- /// MOVDQU m256, ymm
- /// </summary>
- public static unsafe void Store(ulong* address, Vector256<ulong> source) => Store(address, source);
- /// <summary>
- /// void _mm256_storeu_ps (float * mem_addr, __m256 a)
- /// MOVUPS m256, ymm
- /// </summary>
- public static unsafe void Store(float* address, Vector256<float> source) => Store(address, source);
- /// <summary>
- /// void _mm256_storeu_pd (double * mem_addr, __m256d a)
- /// MOVUPD m256, ymm
- /// </summary>
- public static unsafe void Store(double* address, Vector256<double> source) => Store(address, source);
-
- /// <summary>
- /// __m256 _mm256_sub_ps (__m256 a, __m256 b)
- /// VSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Subtract(Vector256<float> left, Vector256<float> right) => Subtract(left, right);
- /// <summary>
- /// __m256d _mm256_sub_pd (__m256d a, __m256d b)
- /// VSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Subtract(Vector256<double> left, Vector256<double> right) => Subtract(left, right);
-
- /// <summary>
- /// int _mm_testc_ps (__m128 a, __m128 b)
- /// VTESTPS xmm, xmm/m128
- /// </summary>
- public static bool TestC(Vector128<float> left, Vector128<float> right) => TestC(left, right);
- /// <summary>
- /// int _mm_testc_pd (__m128d a, __m128d b)
- /// VTESTPD xmm, xmm/m128
- /// </summary>
- public static bool TestC(Vector128<double> left, Vector128<double> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<byte> left, Vector256<byte> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<sbyte> left, Vector256<sbyte> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<short> left, Vector256<short> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<ushort> left, Vector256<ushort> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<int> left, Vector256<int> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<uint> left, Vector256<uint> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<long> left, Vector256<long> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm256_testc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<ulong> left, Vector256<ulong> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm256_testc_ps (__m256 a, __m256 b)
- /// VTESTPS ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<float> left, Vector256<float> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm256_testc_pd (__m256d a, __m256d b)
- /// VTESTPS ymm, ymm/m256
- /// </summary>
- public static bool TestC(Vector256<double> left, Vector256<double> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm_testnzc_ps (__m128 a, __m128 b)
- /// VTESTPS xmm, xmm/m128
- /// </summary>
- public static bool TestNotZAndNotC(Vector128<float> left, Vector128<float> right) => TestNotZAndNotC(left, right);
- /// <summary>
- /// int _mm_testnzc_pd (__m128d a, __m128d b)
- /// VTESTPD xmm, xmm/m128
- /// </summary>
- public static bool TestNotZAndNotC(Vector128<double> left, Vector128<double> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<byte> left, Vector256<byte> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<sbyte> left, Vector256<sbyte> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<short> left, Vector256<short> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<ushort> left, Vector256<ushort> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<int> left, Vector256<int> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<uint> left, Vector256<uint> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<long> left, Vector256<long> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm256_testnzc_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<ulong> left, Vector256<ulong> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm256_testnzc_ps (__m256 a, __m256 b)
- /// VTESTPS ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<float> left, Vector256<float> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm256_testnzc_pd (__m256d a, __m256d b)
- /// VTESTPD ymm, ymm/m256
- /// </summary>
- public static bool TestNotZAndNotC(Vector256<double> left, Vector256<double> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm_testz_ps (__m128 a, __m128 b)
- /// VTESTPS xmm, xmm/m128
- /// </summary>
- public static bool TestZ(Vector128<float> left, Vector128<float> right) => TestZ(left, right);
- /// <summary>
- /// int _mm_testz_pd (__m128d a, __m128d b)
- /// VTESTPD xmm, xmm/m128
- /// </summary>
- public static bool TestZ(Vector128<double> left, Vector128<double> right) => TestZ(left, right);
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<byte> left, Vector256<byte> right) => TestZ(left, right);
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<sbyte> left, Vector256<sbyte> right) => TestZ(left, right);
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<short> left, Vector256<short> right) => TestZ(left, right);
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<ushort> left, Vector256<ushort> right) => TestZ(left, right);
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<int> left, Vector256<int> right) => TestZ(left, right);
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<uint> left, Vector256<uint> right) => TestZ(left, right);
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<long> left, Vector256<long> right) => TestZ(left, right);
-
- /// <summary>
- /// int _mm256_testz_si256 (__m256i a, __m256i b)
- /// VPTEST ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<ulong> left, Vector256<ulong> right) => TestZ(left, right);
-
- /// <summary>
- /// int _mm256_testz_ps (__m256 a, __m256 b)
- /// VTESTPS ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<float> left, Vector256<float> right) => TestZ(left, right);
-
- /// <summary>
- /// int _mm256_testz_pd (__m256d a, __m256d b)
- /// VTESTPD ymm, ymm/m256
- /// </summary>
- public static bool TestZ(Vector256<double> left, Vector256<double> right) => TestZ(left, right);
-
- /// <summary>
- /// __m256 _mm256_unpackhi_ps (__m256 a, __m256 b)
- /// VUNPCKHPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> UnpackHigh(Vector256<float> left, Vector256<float> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m256d _mm256_unpackhi_pd (__m256d a, __m256d b)
- /// VUNPCKHPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> UnpackHigh(Vector256<double> left, Vector256<double> right) => UnpackHigh(left, right);
-
- /// <summary>
- /// __m256 _mm256_unpacklo_ps (__m256 a, __m256 b)
- /// VUNPCKLPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> UnpackLow(Vector256<float> left, Vector256<float> right) => UnpackLow(left, right);
- /// <summary>
- /// __m256d _mm256_unpacklo_pd (__m256d a, __m256d b)
- /// VUNPCKLPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> UnpackLow(Vector256<double> left, Vector256<double> right) => UnpackLow(left, right);
-
- /// <summary>
- /// __m256 _mm256_xor_ps (__m256 a, __m256 b)
- /// VXORPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> Xor(Vector256<float> left, Vector256<float> right) => Xor(left, right);
- /// <summary>
- /// __m256d _mm256_xor_pd (__m256d a, __m256d b)
- /// VXORPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> Xor(Vector256<double> left, Vector256<double> right) => Xor(left, right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx2.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx2.PlatformNotSupported.cs
deleted file mode 100644
index f769fbac8c4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx2.PlatformNotSupported.cs
+++ /dev/null
@@ -1,2191 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel AVX2 hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Avx2 : Avx
- {
- internal Avx2() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// __m256i _mm256_abs_epi8 (__m256i a)
- /// VPABSB ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Abs(Vector256<sbyte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_abs_epi16 (__m256i a)
- /// VPABSW ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Abs(Vector256<short> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_abs_epi32 (__m256i a)
- /// VPABSD ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Abs(Vector256<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_add_epi8 (__m256i a, __m256i b)
- /// VPADDB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Add(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_add_epi8 (__m256i a, __m256i b)
- /// VPADDB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Add(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_add_epi16 (__m256i a, __m256i b)
- /// VPADDW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Add(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_add_epi16 (__m256i a, __m256i b)
- /// VPADDW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Add(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_add_epi32 (__m256i a, __m256i b)
- /// VPADDD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Add(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_add_epi32 (__m256i a, __m256i b)
- /// VPADDD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Add(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_add_epi64 (__m256i a, __m256i b)
- /// VPADDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> Add(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_add_epi64 (__m256i a, __m256i b)
- /// VPADDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> Add(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_adds_epi8 (__m256i a, __m256i b)
- /// VPADDSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> AddSaturate(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_adds_epu8 (__m256i a, __m256i b)
- /// VPADDUSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> AddSaturate(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_adds_epi16 (__m256i a, __m256i b)
- /// VPADDSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> AddSaturate(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_adds_epu16 (__m256i a, __m256i b)
- /// VPADDUSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> AddSaturate(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<sbyte> AlignRight(Vector256<sbyte> left, Vector256<sbyte> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<byte> AlignRight(Vector256<byte> left, Vector256<byte> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<short> AlignRight(Vector256<short> left, Vector256<short> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<ushort> AlignRight(Vector256<ushort> left, Vector256<ushort> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<int> AlignRight(Vector256<int> left, Vector256<int> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<uint> AlignRight(Vector256<uint> left, Vector256<uint> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<long> AlignRight(Vector256<long> left, Vector256<long> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<ulong> AlignRight(Vector256<ulong> left, Vector256<ulong> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> And(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> And(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> And(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> And(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> And(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> And(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> And(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> And(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> AndNot(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> AndNot(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> AndNot(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> AndNot(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> AndNot(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> AndNot(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> AndNot(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> AndNot(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_avg_epu8 (__m256i a, __m256i b)
- /// VPAVGB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Average(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_avg_epu16 (__m256i a, __m256i b)
- /// VPAVGW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Average(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_blend_epi32 (__m128i a, __m128i b, const int imm8)
- /// VPBLENDD xmm, xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<int> Blend(Vector128<int> left, Vector128<int> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_blend_epi32 (__m128i a, __m128i b, const int imm8)
- /// VPBLENDD xmm, xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<uint> Blend(Vector128<uint> left, Vector128<uint> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_blend_epi16 (__m256i a, __m256i b, const int imm8)
- /// VPBLENDW ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<short> Blend(Vector256<short> left, Vector256<short> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_blend_epi16 (__m256i a, __m256i b, const int imm8)
- /// VPBLENDW ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ushort> Blend(Vector256<ushort> left, Vector256<ushort> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_blend_epi32 (__m256i a, __m256i b, const int imm8)
- /// VPBLENDD ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<int> Blend(Vector256<int> left, Vector256<int> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_blend_epi32 (__m256i a, __m256i b, const int imm8)
- /// VPBLENDD ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<uint> Blend(Vector256<uint> left, Vector256<uint> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<sbyte> BlendVariable(Vector256<sbyte> left, Vector256<sbyte> right, Vector256<sbyte> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<byte> BlendVariable(Vector256<byte> left, Vector256<byte> right, Vector256<byte> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<short> BlendVariable(Vector256<short> left, Vector256<short> right, Vector256<short> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<ushort> BlendVariable(Vector256<ushort> left, Vector256<ushort> right, Vector256<ushort> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<int> BlendVariable(Vector256<int> left, Vector256<int> right, Vector256<int> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<uint> BlendVariable(Vector256<uint> left, Vector256<uint> right, Vector256<uint> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<long> BlendVariable(Vector256<long> left, Vector256<long> right, Vector256<long> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<ulong> BlendVariable(Vector256<ulong> left, Vector256<ulong> right, Vector256<ulong> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB xmm, xmm
- /// </summary>
- public static Vector128<byte> BroadcastScalarToVector128(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB xmm, xmm
- /// </summary>
- public static Vector128<sbyte> BroadcastScalarToVector128(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW xmm, xmm
- /// </summary>
- public static Vector128<short> BroadcastScalarToVector128(Vector128<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW xmm, xmm
- /// </summary>
- public static Vector128<ushort> BroadcastScalarToVector128(Vector128<ushort> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD xmm, xmm
- /// </summary>
- public static Vector128<int> BroadcastScalarToVector128(Vector128<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD xmm, xmm
- /// </summary>
- public static Vector128<uint> BroadcastScalarToVector128(Vector128<uint> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ xmm, xmm
- /// </summary>
- public static Vector128<long> BroadcastScalarToVector128(Vector128<long> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ xmm, xmm
- /// </summary>
- public static Vector128<ulong> BroadcastScalarToVector128(Vector128<ulong> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_broadcastss_ps (__m128 a)
- /// VBROADCASTSS xmm, xmm
- /// </summary>
- public static Vector128<float> BroadcastScalarToVector128(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_broadcastsd_pd (__m128d a)
- /// VMOVDDUP xmm, xmm
- /// </summary>
- public static Vector128<double> BroadcastScalarToVector128(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB xmm, m8
- /// The above native signature does not directly correspond to the managed signature.
- /// We provide this additional overload for the lack of pointers to managed.
- /// </summary>
- public static unsafe Vector128<byte> BroadcastScalarToVector128(byte* source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB xmm, m8
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<sbyte> BroadcastScalarToVector128(sbyte* source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW xmm, m16
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<short> BroadcastScalarToVector128(short* source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW xmm, m16
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<ushort> BroadcastScalarToVector128(ushort* source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD xmm, m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<int> BroadcastScalarToVector128(int* source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD xmm, m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<uint> BroadcastScalarToVector128(uint* source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ xmm, m64
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<long> BroadcastScalarToVector128(long* source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ xmm, m64
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<ulong> BroadcastScalarToVector128(ulong* source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB ymm, xmm
- /// </summary>
- public static Vector256<byte> BroadcastScalarToVector256(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB ymm, xmm
- /// </summary>
- public static Vector256<sbyte> BroadcastScalarToVector256(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW ymm, xmm
- /// </summary>
- public static Vector256<short> BroadcastScalarToVector256(Vector128<short> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW ymm, xmm
- /// </summary>
- public static Vector256<ushort> BroadcastScalarToVector256(Vector128<ushort> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD ymm, xmm
- /// </summary>
- public static Vector256<int> BroadcastScalarToVector256(Vector128<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD ymm, xmm
- /// </summary>
- public static Vector256<uint> BroadcastScalarToVector256(Vector128<uint> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ ymm, xmm
- /// </summary>
- public static Vector256<long> BroadcastScalarToVector256(Vector128<long> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ ymm, xmm
- /// </summary>
- public static Vector256<ulong> BroadcastScalarToVector256(Vector128<ulong> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256 _mm256_broadcastss_ps (__m128 a)
- /// VBROADCASTSS ymm, xmm
- /// </summary>
- public static Vector256<float> BroadcastScalarToVector256(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256d _mm256_broadcastsd_pd (__m128d a)
- /// VBROADCASTSD ymm, xmm
- /// </summary>
- public static Vector256<double> BroadcastScalarToVector256(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB ymm, m8
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<byte> BroadcastScalarToVector256(byte* source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB ymm, m8
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<sbyte> BroadcastScalarToVector256(sbyte* source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW ymm, m16
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<short> BroadcastScalarToVector256(short* source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW ymm, m16
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<ushort> BroadcastScalarToVector256(ushort* source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD ymm, m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<int> BroadcastScalarToVector256(int* source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD ymm, m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<uint> BroadcastScalarToVector256(uint* source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ ymm, m64
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<long> BroadcastScalarToVector256(long* source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ ymm, m64
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<ulong> BroadcastScalarToVector256(ulong* source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<sbyte> BroadcastVector128ToVector256(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<byte> BroadcastVector128ToVector256(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<short> BroadcastVector128ToVector256(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<ushort> BroadcastVector128ToVector256(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<int> BroadcastVector128ToVector256(int* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<uint> BroadcastVector128ToVector256(uint* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<long> BroadcastVector128ToVector256(long* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<ulong> BroadcastVector128ToVector256(ulong* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_cmpeq_epi8 (__m256i a, __m256i b)
- /// VPCMPEQB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> CompareEqual(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cmpeq_epi8 (__m256i a, __m256i b)
- /// VPCMPEQB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> CompareEqual(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cmpeq_epi16 (__m256i a, __m256i b)
- /// VPCMPEQW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> CompareEqual(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cmpeq_epi16 (__m256i a, __m256i b)
- /// VPCMPEQW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> CompareEqual(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cmpeq_epi32 (__m256i a, __m256i b)
- /// VPCMPEQD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> CompareEqual(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cmpeq_epi32 (__m256i a, __m256i b)
- /// VPCMPEQD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> CompareEqual(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cmpeq_epi64 (__m256i a, __m256i b)
- /// VPCMPEQQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> CompareEqual(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cmpeq_epi64 (__m256i a, __m256i b)
- /// VPCMPEQQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> CompareEqual(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_cmpgt_epi8 (__m256i a, __m256i b)
- /// VPCMPGTB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> CompareGreaterThan(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cmpgt_epi16 (__m256i a, __m256i b)
- /// VPCMPGTW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> CompareGreaterThan(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cmpgt_epi32 (__m256i a, __m256i b)
- /// VPCMPGTD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> CompareGreaterThan(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cmpgt_epi64 (__m256i a, __m256i b)
- /// VPCMPGTQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> CompareGreaterThan(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_cvtsi256_si32 (__m256i a)
- /// MOVD reg/m32, xmm
- /// </summary>
- public static int ConvertToInt32(Vector256<int> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm256_cvtsi256_si32 (__m256i a)
- /// MOVD reg/m32, xmm
- /// </summary>
- public static uint ConvertToUInt32(Vector256<uint> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_cvtepi8_epi16 (__m128i a)
- /// VPMOVSXBW ymm, xmm
- /// </summary>
- public static Vector256<short> ConvertToVector256Int16(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtepu8_epi16 (__m128i a)
- /// VPMOVZXBW ymm, xmm
- /// </summary>
- public static Vector256<short> ConvertToVector256Int16(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtepi8_epi32 (__m128i a)
- /// VPMOVSXBD ymm, xmm
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtepu8_epi32 (__m128i a)
- /// VPMOVZXBD ymm, xmm
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtepi16_epi32 (__m128i a)
- /// VPMOVSXWD ymm, xmm
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32(Vector128<short> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtepu16_epi32 (__m128i a)
- /// VPMOVZXWD ymm, xmm
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32(Vector128<ushort> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtepi8_epi64 (__m128i a)
- /// VPMOVSXBQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtepu8_epi64 (__m128i a)
- /// VPMOVZXBQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtepi16_epi64 (__m128i a)
- /// VPMOVSXWQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<short> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtepu16_epi64 (__m128i a)
- /// VPMOVZXWQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<ushort> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtepi32_epi64 (__m128i a)
- /// VPMOVSXDQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<int> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_cvtepu32_epi64 (__m128i a)
- /// VPMOVZXDQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<uint> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// VPMOVSXBW ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<short> ConvertToVector256Int16(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// VPMOVZXBW ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<short> ConvertToVector256Int16(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// VPMOVSXBD ymm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<int> ConvertToVector256Int32(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// VPMOVZXBD ymm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<int> ConvertToVector256Int32(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// VPMOVSXWD ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<int> ConvertToVector256Int32(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// VPMOVZXWD ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<int> ConvertToVector256Int32(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// VPMOVSXBQ ymm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// VPMOVZXBQ ymm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// VPMOVSXWQ ymm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// VPMOVZXWQ ymm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// VPMOVSXDQ ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(int* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// VPMOVZXDQ ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(uint* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<sbyte> ExtractVector128(Vector256<sbyte> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<byte> ExtractVector128(Vector256<byte> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<short> ExtractVector128(Vector256<short> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<ushort> ExtractVector128(Vector256<ushort> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<int> ExtractVector128(Vector256<int> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<uint> ExtractVector128(Vector256<uint> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<long> ExtractVector128(Vector256<long> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<ulong> ExtractVector128(Vector256<ulong> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_i32gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherVector128(int* baseAddress, Vector128<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_i32gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherVector128(uint* baseAddress, Vector128<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDQ xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<long> GatherVector128(long* baseAddress, Vector128<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDQ xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<ulong> GatherVector128(ulong* baseAddress, Vector128<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_i32gather_ps (float const* base_addr, __m128i vindex, const int scale)
- /// VGATHERDPS xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherVector128(float* baseAddress, Vector128<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_i32gather_pd (double const* base_addr, __m128i vindex, const int scale)
- /// VGATHERDPD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<double> GatherVector128(double* baseAddress, Vector128<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_i64gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERQD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherVector128(int* baseAddress, Vector128<long> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_i64gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERQD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherVector128(uint* baseAddress, Vector128<long> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_i64gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERQQ xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<long> GatherVector128(long* baseAddress, Vector128<long> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_i64gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERQQ xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<ulong> GatherVector128(ulong* baseAddress, Vector128<long> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_i64gather_ps (float const* base_addr, __m128i vindex, const int scale)
- /// VGATHERQPS xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherVector128(float* baseAddress, Vector128<long> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_i64gather_pd (double const* base_addr, __m128i vindex, const int scale)
- /// VGATHERQPD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<double> GatherVector128(double* baseAddress, Vector128<long> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_i32gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERDD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<int> GatherVector256(int* baseAddress, Vector256<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_i32gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERDD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<uint> GatherVector256(uint* baseAddress, Vector256<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<long> GatherVector256(long* baseAddress, Vector128<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<ulong> GatherVector256(ulong* baseAddress, Vector128<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_i32gather_ps (float const* base_addr, __m256i vindex, const int scale)
- /// VGATHERDPS ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<float> GatherVector256(float* baseAddress, Vector256<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_i32gather_pd (double const* base_addr, __m128i vindex, const int scale)
- /// VGATHERDPD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<double> GatherVector256(double* baseAddress, Vector128<int> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_i64gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERQD xmm, vm64y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherVector128(int* baseAddress, Vector256<long> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_i64gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERQD xmm, vm64y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherVector128(uint* baseAddress, Vector256<long> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_i64gather_epi64 (__int64 const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERQQ ymm, vm64y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<long> GatherVector256(long* baseAddress, Vector256<long> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_i64gather_epi64 (__int64 const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERQQ ymm, vm64y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<ulong> GatherVector256(ulong* baseAddress, Vector256<long> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm256_i64gather_ps (float const* base_addr, __m256i vindex, const int scale)
- /// VGATHERQPS xmm, vm64y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherVector128(float* baseAddress, Vector256<long> index, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_i64gather_pd (double const* base_addr, __m256i vindex, const int scale)
- /// VGATHERQPD ymm, vm64y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<double> GatherVector256(double* baseAddress, Vector256<long> index, byte scale) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_mask_i32gather_epi32 (__m128i src, int const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERDD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherMaskVector128(Vector128<int> source, int* baseAddress, Vector128<int> index, Vector128<int> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_mask_i32gather_epi32 (__m128i src, int const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERDD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherMaskVector128(Vector128<uint> source, uint* baseAddress, Vector128<int> index, Vector128<uint> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_mask_i32gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERDQ xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<long> GatherMaskVector128(Vector128<long> source, long* baseAddress, Vector128<int> index, Vector128<long> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_mask_i32gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERDQ xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<ulong> GatherMaskVector128(Vector128<ulong> source, ulong* baseAddress, Vector128<int> index, Vector128<ulong> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_mask_i32gather_ps (__m128 src, float const* base_addr, __m128i vindex, __m128 mask, const int scale)
- /// VGATHERDPS xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherMaskVector128(Vector128<float> source, float* baseAddress, Vector128<int> index, Vector128<float> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_mask_i32gather_pd (__m128d src, double const* base_addr, __m128i vindex, __m128d mask, const int scale)
- /// VGATHERDPD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<double> GatherMaskVector128(Vector128<double> source, double* baseAddress, Vector128<int> index, Vector128<double> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERQD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherMaskVector128(Vector128<int> source, int* baseAddress, Vector128<long> index, Vector128<int> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERQD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherMaskVector128(Vector128<uint> source, uint* baseAddress, Vector128<long> index, Vector128<uint> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_mask_i64gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERQQ xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<long> GatherMaskVector128(Vector128<long> source, long* baseAddress, Vector128<long> index, Vector128<long> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_mask_i64gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERQQ xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<ulong> GatherMaskVector128(Vector128<ulong> source, ulong* baseAddress, Vector128<long> index, Vector128<ulong> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_mask_i64gather_ps (__m128 src, float const* base_addr, __m128i vindex, __m128 mask, const int scale)
- /// VGATHERQPS xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherMaskVector128(Vector128<float> source, float* baseAddress, Vector128<long> index, Vector128<float> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_mask_i64gather_pd (__m128d src, double const* base_addr, __m128i vindex, __m128d mask, const int scale)
- /// VGATHERQPD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<double> GatherMaskVector128(Vector128<double> source, double* baseAddress, Vector128<long> index, Vector128<double> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_mask_i32gather_epi32 (__m256i src, int const* base_addr, __m256i vindex, __m256i mask, const int scale)
- /// VPGATHERDD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<int> GatherMaskVector256(Vector256<int> source, int* baseAddress, Vector256<int> index, Vector256<int> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_mask_i32gather_epi32 (__m256i src, int const* base_addr, __m256i vindex, __m256i mask, const int scale)
- /// VPGATHERDD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<uint> GatherMaskVector256(Vector256<uint> source, uint* baseAddress, Vector256<int> index, Vector256<uint> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_mask_i32gather_epi64 (__m256i src, __int64 const* base_addr, __m128i vindex, __m256i mask, const int scale)
- /// VPGATHERDQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<long> GatherMaskVector256(Vector256<long> source, long* baseAddress, Vector128<int> index, Vector256<long> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_mask_i32gather_epi64 (__m256i src, __int64 const* base_addr, __m128i vindex, __m256i mask, const int scale)
- /// VPGATHERDQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<ulong> GatherMaskVector256(Vector256<ulong> source, ulong* baseAddress, Vector128<int> index, Vector256<ulong> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_mask_i32gather_ps (__m256 src, float const* base_addr, __m256i vindex, __m256 mask, const int scale)
- /// VPGATHERDPS ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<float> GatherMaskVector256(Vector256<float> source, float* baseAddress, Vector256<int> index, Vector256<float> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_mask_i32gather_pd (__m256d src, double const* base_addr, __m128i vindex, __m256d mask, const int scale)
- /// VPGATHERDPD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<double> GatherMaskVector256(Vector256<double> source, double* baseAddress, Vector128<int> index, Vector256<double> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m256i vindex, __m128i mask, const int scale)
- /// VPGATHERQD xmm, vm32y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherMaskVector128(Vector128<int> source, int* baseAddress, Vector256<long> index, Vector128<int> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m256i vindex, __m128i mask, const int scale)
- /// VPGATHERQD xmm, vm32y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherMaskVector128(Vector128<uint> source, uint* baseAddress, Vector256<long> index, Vector128<uint> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_mask_i64gather_epi64 (__m256i src, __int64 const* base_addr, __m256i vindex, __m256i mask, const int scale)
- /// VPGATHERQQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<long> GatherMaskVector256(Vector256<long> source, long* baseAddress, Vector256<long> index, Vector256<long> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_mask_i64gather_epi64 (__m256i src, __int64 const* base_addr, __m256i vindex, __m256i mask, const int scale)
- /// VPGATHERQQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<ulong> GatherMaskVector256(Vector256<ulong> source, ulong* baseAddress, Vector256<long> index, Vector256<ulong> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm256_mask_i64gather_ps (__m128 src, float const* base_addr, __m256i vindex, __m128 mask, const int scale)
- /// VGATHERQPS xmm, vm32y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherMaskVector128(Vector128<float> source, float* baseAddress, Vector256<long> index, Vector128<float> mask, byte scale) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_mask_i64gather_pd (__m256d src, double const* base_addr, __m256i vindex, __m256d mask, const int scale)
- /// VGATHERQPD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<double> GatherMaskVector256(Vector256<double> source, double* baseAddress, Vector256<long> index, Vector256<double> mask, byte scale) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_hadd_epi16 (__m256i a, __m256i b)
- /// VPHADDW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> HorizontalAdd(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_hadd_epi32 (__m256i a, __m256i b)
- /// VPHADDD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> HorizontalAdd(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_hadds_epi16 (__m256i a, __m256i b)
- /// VPHADDSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> HorizontalAddSaturate(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_hsub_epi16 (__m256i a, __m256i b)
- /// VPHSUBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> HorizontalSubtract(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_hsub_epi32 (__m256i a, __m256i b)
- /// VPHSUBD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> HorizontalSubtract(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_hsubs_epi16 (__m256i a, __m256i b)
- /// VPHSUBSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> HorizontalSubtractSaturate(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<sbyte> InsertVector128(Vector256<sbyte> value, Vector128<sbyte> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<byte> InsertVector128(Vector256<byte> value, Vector128<byte> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<short> InsertVector128(Vector256<short> value, Vector128<short> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<ushort> InsertVector128(Vector256<ushort> value, Vector128<ushort> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<int> InsertVector128(Vector256<int> value, Vector128<int> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<uint> InsertVector128(Vector256<uint> value, Vector128<uint> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<long> InsertVector128(Vector256<long> value, Vector128<long> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<ulong> InsertVector128(Vector256<ulong> value, Vector128<ulong> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<sbyte> LoadAlignedVector256NonTemporal(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<byte> LoadAlignedVector256NonTemporal(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<short> LoadAlignedVector256NonTemporal(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<ushort> LoadAlignedVector256NonTemporal(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<int> LoadAlignedVector256NonTemporal(int* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<uint> LoadAlignedVector256NonTemporal(uint* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<long> LoadAlignedVector256NonTemporal(long* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<ulong> LoadAlignedVector256NonTemporal(ulong* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_maskload_epi32 (int const* mem_addr, __m128i mask)
- /// VPMASKMOVD xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<int> MaskLoad(int* address, Vector128<int> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_maskload_epi32 (int const* mem_addr, __m128i mask)
- /// VPMASKMOVD xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<uint> MaskLoad(uint* address, Vector128<uint> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_maskload_epi64 (__int64 const* mem_addr, __m128i mask)
- /// VPMASKMOVQ xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<long> MaskLoad(long* address, Vector128<long> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_maskload_epi64 (__int64 const* mem_addr, __m128i mask)
- /// VPMASKMOVQ xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<ulong> MaskLoad(ulong* address, Vector128<ulong> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_maskload_epi32 (int const* mem_addr, __m256i mask)
- /// VPMASKMOVD ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<int> MaskLoad(int* address, Vector256<int> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_maskload_epi32 (int const* mem_addr, __m256i mask)
- /// VPMASKMOVD ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<uint> MaskLoad(uint* address, Vector256<uint> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_maskload_epi64 (__int64 const* mem_addr, __m256i mask)
- /// VPMASKMOVQ ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<long> MaskLoad(long* address, Vector256<long> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_maskload_epi64 (__int64 const* mem_addr, __m256i mask)
- /// VPMASKMOVQ ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<ulong> MaskLoad(ulong* address, Vector256<ulong> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_maskstore_epi32 (int* mem_addr, __m128i mask, __m128i a)
- /// VPMASKMOVD m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(int* address, Vector128<int> mask, Vector128<int> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_maskstore_epi32 (int* mem_addr, __m128i mask, __m128i a)
- /// VPMASKMOVD m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(uint* address, Vector128<uint> mask, Vector128<uint> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_maskstore_epi64 (__int64* mem_addr, __m128i mask, __m128i a)
- /// VPMASKMOVQ m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(long* address, Vector128<long> mask, Vector128<long> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_maskstore_epi64 (__int64* mem_addr, __m128i mask, __m128i a)
- /// VPMASKMOVQ m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(ulong* address, Vector128<ulong> mask, Vector128<ulong> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm256_maskstore_epi32 (int* mem_addr, __m256i mask, __m256i a)
- /// VPMASKMOVD m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(int* address, Vector256<int> mask, Vector256<int> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_maskstore_epi32 (int* mem_addr, __m256i mask, __m256i a)
- /// VPMASKMOVD m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(uint* address, Vector256<uint> mask, Vector256<uint> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_maskstore_epi64 (__int64* mem_addr, __m256i mask, __m256i a)
- /// VPMASKMOVQ m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(long* address, Vector256<long> mask, Vector256<long> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm256_maskstore_epi64 (__int64* mem_addr, __m256i mask, __m256i a)
- /// VPMASKMOVQ m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(ulong* address, Vector256<ulong> mask, Vector256<ulong> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_madd_epi16 (__m256i a, __m256i b)
- /// VPMADDWD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> MultiplyAddAdjacent(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_maddubs_epi16 (__m256i a, __m256i b)
- /// VPMADDUBSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> MultiplyAddAdjacent(Vector256<byte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_max_epi8 (__m256i a, __m256i b)
- /// VPMAXSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Max(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_max_epu8 (__m256i a, __m256i b)
- /// VPMAXUB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Max(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_max_epi16 (__m256i a, __m256i b)
- /// VPMAXSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Max(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_max_epu16 (__m256i a, __m256i b)
- /// VPMAXUW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Max(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_max_epi32 (__m256i a, __m256i b)
- /// VPMAXSD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Max(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_max_epu32 (__m256i a, __m256i b)
- /// VPMAXUD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Max(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_min_epi8 (__m256i a, __m256i b)
- /// VPMINSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Min(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_min_epu8 (__m256i a, __m256i b)
- /// VPMINUB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Min(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_min_epi16 (__m256i a, __m256i b)
- /// VPMINSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Min(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_min_epu16 (__m256i a, __m256i b)
- /// VPMINUW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Min(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_min_epi32 (__m256i a, __m256i b)
- /// VPMINSD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Min(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_min_epu32 (__m256i a, __m256i b)
- /// VPMINUD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Min(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm256_movemask_epi8 (__m256i a)
- /// VPMOVMSKB reg, ymm
- /// </summary>
- public static int MoveMask(Vector256<sbyte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm256_movemask_epi8 (__m256i a)
- /// VPMOVMSKB reg, ymm
- /// </summary>
- public static int MoveMask(Vector256<byte> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_mpsadbw_epu8 (__m256i a, __m256i b, const int imm8)
- /// VMPSADBW ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ushort> MultipleSumAbsoluteDifferences(Vector256<byte> left, Vector256<byte> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_mul_epi32 (__m256i a, __m256i b)
- /// VPMULDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> Multiply(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_mul_epu32 (__m256i a, __m256i b)
- /// VPMULUDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> Multiply(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_mulhi_epi16 (__m256i a, __m256i b)
- /// VPMULHW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> MultiplyHigh(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_mulhi_epu16 (__m256i a, __m256i b)
- /// VPMULHUW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> MultiplyHigh(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_mulhrs_epi16 (__m256i a, __m256i b)
- /// VPMULHRSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> MultiplyHighRoundScale(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_mullo_epi16 (__m256i a, __m256i b)
- /// VPMULLW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> MultiplyLow(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_mullo_epi16 (__m256i a, __m256i b)
- /// VPMULLW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> MultiplyLow(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_mullo_epi32 (__m256i a, __m256i b)
- /// VPMULLD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> MultiplyLow(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_mullo_epi32 (__m256i a, __m256i b)
- /// VPMULLD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> MultiplyLow(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Or(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Or(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Or(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Or(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Or(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Or(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> Or(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> Or(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_packs_epi16 (__m256i a, __m256i b)
- /// VPACKSSWB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> PackSignedSaturate(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_packs_epi32 (__m256i a, __m256i b)
- /// VPACKSSDW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> PackSignedSaturate(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_packus_epi16 (__m256i a, __m256i b)
- /// VPACKUSWB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> PackUnsignedSaturate(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_packus_epi32 (__m256i a, __m256i b)
- /// VPACKUSDW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> PackUnsignedSaturate(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<sbyte> Permute2x128(Vector256<sbyte> left, Vector256<sbyte> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<byte> Permute2x128(Vector256<byte> left, Vector256<byte> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<short> Permute2x128(Vector256<short> left, Vector256<short> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<ushort> Permute2x128(Vector256<ushort> left, Vector256<ushort> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<int> Permute2x128(Vector256<int> left, Vector256<int> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<uint> Permute2x128(Vector256<uint> left, Vector256<uint> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<long> Permute2x128(Vector256<long> left, Vector256<long> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<ulong> Permute2x128(Vector256<ulong> left, Vector256<ulong> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_permute4x64_epi64 (__m256i a, const int imm8)
- /// VPERMQ ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<long> Permute4x64(Vector256<long> value, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_permute4x64_epi64 (__m256i a, const int imm8)
- /// VPERMQ ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ulong> Permute4x64(Vector256<ulong> value, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_permute4x64_pd (__m256d a, const int imm8)
- /// VPERMPD ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<double> Permute4x64(Vector256<double> value, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_permutevar8x32_epi32 (__m256i a, __m256i idx)
- /// VPERMD ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<int> PermuteVar8x32(Vector256<int> left, Vector256<int> control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_permutevar8x32_epi32 (__m256i a, __m256i idx)
- /// VPERMD ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<uint> PermuteVar8x32(Vector256<uint> left, Vector256<uint> control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_permutevar8x32_ps (__m256 a, __m256i idx)
- /// VPERMPS ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<float> PermuteVar8x32(Vector256<float> left, Vector256<int> control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_sll_epi16 (__m256i a, __m128i count)
- /// VPSLLW ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<short> ShiftLeftLogical(Vector256<short> value, Vector128<short> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sll_epi16 (__m256i a, __m128i count)
- /// VPSLLW ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<ushort> ShiftLeftLogical(Vector256<ushort> value, Vector128<ushort> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sll_epi32 (__m256i a, __m128i count)
- /// VPSLLD ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<int> ShiftLeftLogical(Vector256<int> value, Vector128<int> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sll_epi32 (__m256i a, __m128i count)
- /// VPSLLD ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<uint> ShiftLeftLogical(Vector256<uint> value, Vector128<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sll_epi64 (__m256i a, __m128i count)
- /// VPSLLQ ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<long> ShiftLeftLogical(Vector256<long> value, Vector128<long> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sll_epi64 (__m256i a, __m128i count)
- /// VPSLLQ ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<ulong> ShiftLeftLogical(Vector256<ulong> value, Vector128<ulong> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_slli_epi16 (__m256i a, int imm8)
- /// VPSLLW ymm, ymm, imm8
- /// </summary>
- public static Vector256<short> ShiftLeftLogical(Vector256<short> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_slli_epi16 (__m256i a, int imm8)
- /// VPSLLW ymm, ymm, imm8
- /// </summary>
- public static Vector256<ushort> ShiftLeftLogical(Vector256<ushort> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_slli_epi32 (__m256i a, int imm8)
- /// VPSLLD ymm, ymm, imm8
- /// </summary>
- public static Vector256<int> ShiftLeftLogical(Vector256<int> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_slli_epi32 (__m256i a, int imm8)
- /// VPSLLD ymm, ymm, imm8
- /// </summary>
- public static Vector256<uint> ShiftLeftLogical(Vector256<uint> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_slli_epi64 (__m256i a, int imm8)
- /// VPSLLQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<long> ShiftLeftLogical(Vector256<long> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_slli_epi64 (__m256i a, int imm8)
- /// VPSLLQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ulong> ShiftLeftLogical(Vector256<ulong> value, byte count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<sbyte> ShiftLeftLogical128BitLane(Vector256<sbyte> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<byte> ShiftLeftLogical128BitLane(Vector256<byte> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<short> ShiftLeftLogical128BitLane(Vector256<short> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ushort> ShiftLeftLogical128BitLane(Vector256<ushort> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<int> ShiftLeftLogical128BitLane(Vector256<int> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<uint> ShiftLeftLogical128BitLane(Vector256<uint> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<long> ShiftLeftLogical128BitLane(Vector256<long> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ulong> ShiftLeftLogical128BitLane(Vector256<ulong> value, byte numBytes) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_sllv_epi32 (__m256i a, __m256i count)
- /// VPSLLVD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> ShiftLeftLogicalVariable(Vector256<int> value, Vector256<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sllv_epi32 (__m256i a, __m256i count)
- /// VPSLLVD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> ShiftLeftLogicalVariable(Vector256<uint> value, Vector256<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sllv_epi64 (__m256i a, __m256i count)
- /// VPSLLVQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> ShiftLeftLogicalVariable(Vector256<long> value, Vector256<ulong> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sllv_epi64 (__m256i a, __m256i count)
- /// VPSLLVQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> ShiftLeftLogicalVariable(Vector256<ulong> value, Vector256<ulong> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_sllv_epi32 (__m128i a, __m128i count)
- /// VPSLLVD xmm, ymm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftLeftLogicalVariable(Vector128<int> value, Vector128<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sllv_epi32 (__m128i a, __m128i count)
- /// VPSLLVD xmm, ymm, xmm/m128
- /// </summary>
- public static Vector128<uint> ShiftLeftLogicalVariable(Vector128<uint> value, Vector128<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sllv_epi64 (__m128i a, __m128i count)
- /// VPSLLVQ xmm, ymm, xmm/m128
- /// </summary>
- public static Vector128<long> ShiftLeftLogicalVariable(Vector128<long> value, Vector128<ulong> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sllv_epi64 (__m128i a, __m128i count)
- /// VPSLLVQ xmm, ymm, xmm/m128
- /// </summary>
- public static Vector128<ulong> ShiftLeftLogicalVariable(Vector128<ulong> value, Vector128<ulong> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// _mm256_sra_epi16 (__m256i a, __m128i count)
- /// VPSRAW ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<short> ShiftRightArithmetic(Vector256<short> value, Vector128<short> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// _mm256_sra_epi32 (__m256i a, __m128i count)
- /// VPSRAD ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<int> ShiftRightArithmetic(Vector256<int> value, Vector128<int> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_srai_epi16 (__m256i a, int imm8)
- /// VPSRAW ymm, ymm, imm8
- /// </summary>
- public static Vector256<short> ShiftRightArithmetic(Vector256<short> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srai_epi32 (__m256i a, int imm8)
- /// VPSRAD ymm, ymm, imm8
- /// </summary>
- public static Vector256<int> ShiftRightArithmetic(Vector256<int> value, byte count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_srav_epi32 (__m256i a, __m256i count)
- /// VPSRAVD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> ShiftRightArithmeticVariable(Vector256<int> value, Vector256<uint> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_srav_epi32 (__m128i a, __m128i count)
- /// VPSRAVD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftRightArithmeticVariable(Vector128<int> value, Vector128<uint> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_srl_epi16 (__m256i a, __m128i count)
- /// VPSRLW ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<short> ShiftRightLogical(Vector256<short> value, Vector128<short> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srl_epi16 (__m256i a, __m128i count)
- /// VPSRLW ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<ushort> ShiftRightLogical(Vector256<ushort> value, Vector128<ushort> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srl_epi32 (__m256i a, __m128i count)
- /// VPSRLD ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<int> ShiftRightLogical(Vector256<int> value, Vector128<int> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srl_epi32 (__m256i a, __m128i count)
- /// VPSRLD ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<uint> ShiftRightLogical(Vector256<uint> value, Vector128<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srl_epi64 (__m256i a, __m128i count)
- /// VPSRLQ ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<long> ShiftRightLogical(Vector256<long> value, Vector128<long> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srl_epi64 (__m256i a, __m128i count)
- /// VPSRLQ ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<ulong> ShiftRightLogical(Vector256<ulong> value, Vector128<ulong> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_srli_epi16 (__m256i a, int imm8)
- /// VPSRLW ymm, ymm, imm8
- /// </summary>
- public static Vector256<short> ShiftRightLogical(Vector256<short> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srli_epi16 (__m256i a, int imm8)
- /// VPSRLW ymm, ymm, imm8
- /// </summary>
- public static Vector256<ushort> ShiftRightLogical(Vector256<ushort> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srli_epi32 (__m256i a, int imm8)
- /// VPSRLD ymm, ymm, imm8
- /// </summary>
- public static Vector256<int> ShiftRightLogical(Vector256<int> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srli_epi32 (__m256i a, int imm8)
- /// VPSRLD ymm, ymm, imm8
- /// </summary>
- public static Vector256<uint> ShiftRightLogical(Vector256<uint> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srli_epi64 (__m256i a, int imm8)
- /// VPSRLQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<long> ShiftRightLogical(Vector256<long> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srli_epi64 (__m256i a, int imm8)
- /// VPSRLQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ulong> ShiftRightLogical(Vector256<ulong> value, byte count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<sbyte> ShiftRightLogical128BitLane(Vector256<sbyte> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<byte> ShiftRightLogical128BitLane(Vector256<byte> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<short> ShiftRightLogical128BitLane(Vector256<short> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ushort> ShiftRightLogical128BitLane(Vector256<ushort> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<int> ShiftRightLogical128BitLane(Vector256<int> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<uint> ShiftRightLogical128BitLane(Vector256<uint> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<long> ShiftRightLogical128BitLane(Vector256<long> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ulong> ShiftRightLogical128BitLane(Vector256<ulong> value, byte numBytes) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_srlv_epi32 (__m256i a, __m256i count)
- /// VPSRLVD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> ShiftRightLogicalVariable(Vector256<int> value, Vector256<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srlv_epi32 (__m256i a, __m256i count)
- /// VPSRLVD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> ShiftRightLogicalVariable(Vector256<uint> value, Vector256<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srlv_epi64 (__m256i a, __m256i count)
- /// VPSRLVQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> ShiftRightLogicalVariable(Vector256<long> value, Vector256<ulong> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_srlv_epi64 (__m256i a, __m256i count)
- /// VPSRLVQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> ShiftRightLogicalVariable(Vector256<ulong> value, Vector256<ulong> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_srlv_epi32 (__m128i a, __m128i count)
- /// VPSRLVD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftRightLogicalVariable(Vector128<int> value, Vector128<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srlv_epi32 (__m128i a, __m128i count)
- /// VPSRLVD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> ShiftRightLogicalVariable(Vector128<uint> value, Vector128<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srlv_epi64 (__m128i a, __m128i count)
- /// VPSRLVQ xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<long> ShiftRightLogicalVariable(Vector128<long> value, Vector128<ulong> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srlv_epi64 (__m128i a, __m128i count)
- /// VPSRLVQ xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> ShiftRightLogicalVariable(Vector128<ulong> value, Vector128<ulong> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_shuffle_epi8 (__m256i a, __m256i b)
- /// VPSHUFB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Shuffle(Vector256<sbyte> value, Vector256<sbyte> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_shuffle_epi8 (__m256i a, __m256i b)
- /// VPSHUFB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Shuffle(Vector256<byte> value, Vector256<byte> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_shuffle_epi32 (__m256i a, const int imm8)
- /// VPSHUFD ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<int> Shuffle(Vector256<int> value, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_shuffle_epi32 (__m256i a, const int imm8)
- /// VPSHUFD ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<uint> Shuffle(Vector256<uint> value, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_shufflehi_epi16 (__m256i a, const int imm8)
- /// VPSHUFHW ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<short> ShuffleHigh(Vector256<short> value, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_shufflehi_epi16 (__m256i a, const int imm8)
- /// VPSHUFHW ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ushort> ShuffleHigh(Vector256<ushort> value, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_shufflelo_epi16 (__m256i a, const int imm8)
- /// VPSHUFLW ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<short> ShuffleLow(Vector256<short> value, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_shufflelo_epi16 (__m256i a, const int imm8)
- /// VPSHUFLW ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ushort> ShuffleLow(Vector256<ushort> value, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_sign_epi8 (__m256i a, __m256i b)
- /// VPSIGNB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Sign(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sign_epi16 (__m256i a, __m256i b)
- /// VPSIGNW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Sign(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sign_epi32 (__m256i a, __m256i b)
- /// VPSIGND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Sign(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_sub_epi8 (__m256i a, __m256i b)
- /// VPSUBB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Subtract(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sub_epi8 (__m256i a, __m256i b)
- /// VPSUBB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Subtract(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sub_epi16 (__m256i a, __m256i b)
- /// VPSUBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Subtract(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sub_epi16 (__m256i a, __m256i b)
- /// VPSUBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Subtract(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sub_epi32 (__m256i a, __m256i b)
- /// VPSUBD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Subtract(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sub_epi32 (__m256i a, __m256i b)
- /// VPSUBD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Subtract(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sub_epi64 (__m256i a, __m256i b)
- /// VPSUBQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> Subtract(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_sub_epi64 (__m256i a, __m256i b)
- /// VPSUBQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> Subtract(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_subs_epi8 (__m256i a, __m256i b)
- /// VPSUBSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> SubtractSaturate(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_subs_epi16 (__m256i a, __m256i b)
- /// VPSUBSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> SubtractSaturate(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_subs_epu8 (__m256i a, __m256i b)
- /// VPSUBUSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> SubtractSaturate(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_subs_epu16 (__m256i a, __m256i b)
- /// VPSUBUSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> SubtractSaturate(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_sad_epu8 (__m256i a, __m256i b)
- /// VPSADBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> SumAbsoluteDifferences(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_unpackhi_epi8 (__m256i a, __m256i b)
- /// VPUNPCKHBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> UnpackHigh(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpackhi_epi8 (__m256i a, __m256i b)
- /// VPUNPCKHBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> UnpackHigh(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpackhi_epi16 (__m256i a, __m256i b)
- /// VPUNPCKHWD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> UnpackHigh(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpackhi_epi16 (__m256i a, __m256i b)
- /// VPUNPCKHWD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> UnpackHigh(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpackhi_epi32 (__m256i a, __m256i b)
- /// VPUNPCKHDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> UnpackHigh(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpackhi_epi32 (__m256i a, __m256i b)
- /// VPUNPCKHDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> UnpackHigh(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpackhi_epi64 (__m256i a, __m256i b)
- /// VPUNPCKHQDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> UnpackHigh(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpackhi_epi64 (__m256i a, __m256i b)
- /// VPUNPCKHQDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> UnpackHigh(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_unpacklo_epi8 (__m256i a, __m256i b)
- /// VPUNPCKLBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> UnpackLow(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpacklo_epi8 (__m256i a, __m256i b)
- /// VPUNPCKLBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> UnpackLow(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpacklo_epi16 (__m256i a, __m256i b)
- /// VPUNPCKLWD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> UnpackLow(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpacklo_epi16 (__m256i a, __m256i b)
- /// VPUNPCKLWD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> UnpackLow(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpacklo_epi32 (__m256i a, __m256i b)
- /// VPUNPCKLDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> UnpackLow(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpacklo_epi32 (__m256i a, __m256i b)
- /// VPUNPCKLDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> UnpackLow(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpacklo_epi64 (__m256i a, __m256i b)
- /// VPUNPCKLQDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> UnpackLow(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_unpacklo_epi64 (__m256i a, __m256i b)
- /// VPUNPCKLQDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> UnpackLow(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Xor(Vector256<sbyte> left, Vector256<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Xor(Vector256<byte> left, Vector256<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Xor(Vector256<short> left, Vector256<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Xor(Vector256<ushort> left, Vector256<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Xor(Vector256<int> left, Vector256<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Xor(Vector256<uint> left, Vector256<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> Xor(Vector256<long> left, Vector256<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> Xor(Vector256<ulong> left, Vector256<ulong> right) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx2.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx2.cs
deleted file mode 100644
index a3ff0add1b8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Avx2.cs
+++ /dev/null
@@ -1,2669 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel AVX2 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Avx2 : Avx
- {
- internal Avx2() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// __m256i _mm256_abs_epi8 (__m256i a)
- /// VPABSB ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Abs(Vector256<sbyte> value) => Abs(value);
- /// <summary>
- /// __m256i _mm256_abs_epi16 (__m256i a)
- /// VPABSW ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Abs(Vector256<short> value) => Abs(value);
- /// <summary>
- /// __m256i _mm256_abs_epi32 (__m256i a)
- /// VPABSD ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Abs(Vector256<int> value) => Abs(value);
-
- /// <summary>
- /// __m256i _mm256_add_epi8 (__m256i a, __m256i b)
- /// VPADDB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Add(Vector256<sbyte> left, Vector256<sbyte> right) => Add(left, right);
- /// <summary>
- /// __m256i _mm256_add_epi8 (__m256i a, __m256i b)
- /// VPADDB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Add(Vector256<byte> left, Vector256<byte> right) => Add(left, right);
- /// <summary>
- /// __m256i _mm256_add_epi16 (__m256i a, __m256i b)
- /// VPADDW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Add(Vector256<short> left, Vector256<short> right) => Add(left, right);
- /// <summary>
- /// __m256i _mm256_add_epi16 (__m256i a, __m256i b)
- /// VPADDW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Add(Vector256<ushort> left, Vector256<ushort> right) => Add(left, right);
- /// <summary>
- /// __m256i _mm256_add_epi32 (__m256i a, __m256i b)
- /// VPADDD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Add(Vector256<int> left, Vector256<int> right) => Add(left, right);
- /// <summary>
- /// __m256i _mm256_add_epi32 (__m256i a, __m256i b)
- /// VPADDD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Add(Vector256<uint> left, Vector256<uint> right) => Add(left, right);
- /// <summary>
- /// __m256i _mm256_add_epi64 (__m256i a, __m256i b)
- /// VPADDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> Add(Vector256<long> left, Vector256<long> right) => Add(left, right);
- /// <summary>
- /// __m256i _mm256_add_epi64 (__m256i a, __m256i b)
- /// VPADDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> Add(Vector256<ulong> left, Vector256<ulong> right) => Add(left, right);
-
- /// <summary>
- /// __m256i _mm256_adds_epi8 (__m256i a, __m256i b)
- /// VPADDSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> AddSaturate(Vector256<sbyte> left, Vector256<sbyte> right) => AddSaturate(left, right);
- /// <summary>
- /// __m256i _mm256_adds_epu8 (__m256i a, __m256i b)
- /// VPADDUSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> AddSaturate(Vector256<byte> left, Vector256<byte> right) => AddSaturate(left, right);
- /// <summary>
- /// __m256i _mm256_adds_epi16 (__m256i a, __m256i b)
- /// VPADDSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> AddSaturate(Vector256<short> left, Vector256<short> right) => AddSaturate(left, right);
- /// <summary>
- /// __m256i _mm256_adds_epu16 (__m256i a, __m256i b)
- /// VPADDUSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> AddSaturate(Vector256<ushort> left, Vector256<ushort> right) => AddSaturate(left, right);
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<sbyte> AlignRight(Vector256<sbyte> left, Vector256<sbyte> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<byte> AlignRight(Vector256<byte> left, Vector256<byte> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<short> AlignRight(Vector256<short> left, Vector256<short> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<ushort> AlignRight(Vector256<ushort> left, Vector256<ushort> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<int> AlignRight(Vector256<int> left, Vector256<int> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<uint> AlignRight(Vector256<uint> left, Vector256<uint> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<long> AlignRight(Vector256<long> left, Vector256<long> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_alignr_epi8 (__m256i a, __m256i b, const int count)
- /// VPALIGNR ymm, ymm, ymm/m256, imm8
- /// This intrinsic generates VPALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector256<ulong> AlignRight(Vector256<ulong> left, Vector256<ulong> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> And(Vector256<sbyte> left, Vector256<sbyte> right) => And(left, right);
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> And(Vector256<byte> left, Vector256<byte> right) => And(left, right);
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> And(Vector256<short> left, Vector256<short> right) => And(left, right);
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> And(Vector256<ushort> left, Vector256<ushort> right) => And(left, right);
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> And(Vector256<int> left, Vector256<int> right) => And(left, right);
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> And(Vector256<uint> left, Vector256<uint> right) => And(left, right);
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> And(Vector256<long> left, Vector256<long> right) => And(left, right);
- /// <summary>
- /// __m256i _mm256_and_si256 (__m256i a, __m256i b)
- /// VPAND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> And(Vector256<ulong> left, Vector256<ulong> right) => And(left, right);
-
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> AndNot(Vector256<sbyte> left, Vector256<sbyte> right) => AndNot(left, right);
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> AndNot(Vector256<byte> left, Vector256<byte> right) => AndNot(left, right);
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> AndNot(Vector256<short> left, Vector256<short> right) => AndNot(left, right);
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> AndNot(Vector256<ushort> left, Vector256<ushort> right) => AndNot(left, right);
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> AndNot(Vector256<int> left, Vector256<int> right) => AndNot(left, right);
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> AndNot(Vector256<uint> left, Vector256<uint> right) => AndNot(left, right);
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> AndNot(Vector256<long> left, Vector256<long> right) => AndNot(left, right);
- /// <summary>
- /// __m256i _mm256_andnot_si256 (__m256i a, __m256i b)
- /// VPANDN ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> AndNot(Vector256<ulong> left, Vector256<ulong> right) => AndNot(left, right);
-
- /// <summary>
- /// __m256i _mm256_avg_epu8 (__m256i a, __m256i b)
- /// VPAVGB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Average(Vector256<byte> left, Vector256<byte> right) => Average(left, right);
- /// <summary>
- /// __m256i _mm256_avg_epu16 (__m256i a, __m256i b)
- /// VPAVGW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Average(Vector256<ushort> left, Vector256<ushort> right) => Average(left, right);
-
- /// <summary>
- /// __m128i _mm_blend_epi32 (__m128i a, __m128i b, const int imm8)
- /// VPBLENDD xmm, xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<int> Blend(Vector128<int> left, Vector128<int> right, byte control) => Blend(left, right, control);
- /// <summary>
- /// __m128i _mm_blend_epi32 (__m128i a, __m128i b, const int imm8)
- /// VPBLENDD xmm, xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<uint> Blend(Vector128<uint> left, Vector128<uint> right, byte control) => Blend(left, right, control);
- /// <summary>
- /// __m256i _mm256_blend_epi16 (__m256i a, __m256i b, const int imm8)
- /// VPBLENDW ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<short> Blend(Vector256<short> left, Vector256<short> right, byte control) => Blend(left, right, control);
- /// <summary>
- /// __m256i _mm256_blend_epi16 (__m256i a, __m256i b, const int imm8)
- /// VPBLENDW ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ushort> Blend(Vector256<ushort> left, Vector256<ushort> right, byte control) => Blend(left, right, control);
- /// <summary>
- /// __m256i _mm256_blend_epi32 (__m256i a, __m256i b, const int imm8)
- /// VPBLENDD ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<int> Blend(Vector256<int> left, Vector256<int> right, byte control) => Blend(left, right, control);
- /// <summary>
- /// __m256i _mm256_blend_epi32 (__m256i a, __m256i b, const int imm8)
- /// VPBLENDD ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<uint> Blend(Vector256<uint> left, Vector256<uint> right, byte control) => Blend(left, right, control);
-
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<sbyte> BlendVariable(Vector256<sbyte> left, Vector256<sbyte> right, Vector256<sbyte> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<byte> BlendVariable(Vector256<byte> left, Vector256<byte> right, Vector256<byte> mask) => BlendVariable(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<short> BlendVariable(Vector256<short> left, Vector256<short> right, Vector256<short> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<ushort> BlendVariable(Vector256<ushort> left, Vector256<ushort> right, Vector256<ushort> mask) => BlendVariable(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<int> BlendVariable(Vector256<int> left, Vector256<int> right, Vector256<int> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<uint> BlendVariable(Vector256<uint> left, Vector256<uint> right, Vector256<uint> mask) => BlendVariable(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<long> BlendVariable(Vector256<long> left, Vector256<long> right, Vector256<long> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m256i _mm256_blendv_epi8 (__m256i a, __m256i b, __m256i mask)
- /// VPBLENDVB ymm, ymm, ymm/m256, ymm
- /// This intrinsic generates VPBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector256<ulong> BlendVariable(Vector256<ulong> left, Vector256<ulong> right, Vector256<ulong> mask) => BlendVariable(left, right, mask);
-
- /// <summary>
- /// __m128i _mm_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB xmm, xmm
- /// </summary>
- public static Vector128<byte> BroadcastScalarToVector128(Vector128<byte> value) => BroadcastScalarToVector128(value);
-
- /// <summary>
- /// __m128i _mm_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB xmm, xmm
- /// </summary>
- public static Vector128<sbyte> BroadcastScalarToVector128(Vector128<sbyte> value) => BroadcastScalarToVector128(value);
-
- /// <summary>
- /// __m128i _mm_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW xmm, xmm
- /// </summary>
- public static Vector128<short> BroadcastScalarToVector128(Vector128<short> value) => BroadcastScalarToVector128(value);
-
- /// <summary>
- /// __m128i _mm_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW xmm, xmm
- /// </summary>
- public static Vector128<ushort> BroadcastScalarToVector128(Vector128<ushort> value) => BroadcastScalarToVector128(value);
-
- /// <summary>
- /// __m128i _mm_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD xmm, xmm
- /// </summary>
- public static Vector128<int> BroadcastScalarToVector128(Vector128<int> value) => BroadcastScalarToVector128(value);
-
- /// <summary>
- /// __m128i _mm_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD xmm, xmm
- /// </summary>
- public static Vector128<uint> BroadcastScalarToVector128(Vector128<uint> value) => BroadcastScalarToVector128(value);
-
- /// <summary>
- /// __m128i _mm_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ xmm, xmm
- /// </summary>
- public static Vector128<long> BroadcastScalarToVector128(Vector128<long> value) => BroadcastScalarToVector128(value);
-
- /// <summary>
- /// __m128i _mm_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ xmm, xmm
- /// </summary>
- public static Vector128<ulong> BroadcastScalarToVector128(Vector128<ulong> value) => BroadcastScalarToVector128(value);
-
- /// <summary>
- /// __m128 _mm_broadcastss_ps (__m128 a)
- /// VBROADCASTSS xmm, xmm
- /// </summary>
- public static Vector128<float> BroadcastScalarToVector128(Vector128<float> value) => BroadcastScalarToVector128(value);
-
- /// <summary>
- /// __m128d _mm_broadcastsd_pd (__m128d a)
- /// VMOVDDUP xmm, xmm
- /// </summary>
- public static Vector128<double> BroadcastScalarToVector128(Vector128<double> value) => BroadcastScalarToVector128(value);
-
- /// <summary>
- /// __m128i _mm_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB xmm, m8
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<byte> BroadcastScalarToVector128(byte* source) => BroadcastScalarToVector128(source);
- /// <summary>
- /// __m128i _mm_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB xmm, m8
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<sbyte> BroadcastScalarToVector128(sbyte* source) => BroadcastScalarToVector128(source);
-
- /// <summary>
- /// __m128i _mm_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW xmm, m16
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<short> BroadcastScalarToVector128(short* source) => BroadcastScalarToVector128(source);
- /// <summary>
- /// __m128i _mm_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW xmm, m16
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<ushort> BroadcastScalarToVector128(ushort* source) => BroadcastScalarToVector128(source);
-
- /// <summary>
- /// __m128i _mm_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD xmm, m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<int> BroadcastScalarToVector128(int* source) => BroadcastScalarToVector128(source);
- /// <summary>
- /// __m128i _mm_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD xmm, m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<uint> BroadcastScalarToVector128(uint* source) => BroadcastScalarToVector128(source);
-
- /// <summary>
- /// __m128i _mm_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ xmm, m64
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<long> BroadcastScalarToVector128(long* source) => BroadcastScalarToVector128(source);
- /// <summary>
- /// __m128i _mm_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ xmm, m64
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector128<ulong> BroadcastScalarToVector128(ulong* source) => BroadcastScalarToVector128(source);
-
- /// <summary>
- /// __m256i _mm256_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB ymm, xmm
- /// </summary>
- public static Vector256<byte> BroadcastScalarToVector256(Vector128<byte> value) => BroadcastScalarToVector256(value);
-
- /// <summary>
- /// __m256i _mm256_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB ymm, xmm
- /// </summary>
- public static Vector256<sbyte> BroadcastScalarToVector256(Vector128<sbyte> value) => BroadcastScalarToVector256(value);
-
- /// <summary>
- /// __m256i _mm256_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW ymm, xmm
- /// </summary>
- public static Vector256<short> BroadcastScalarToVector256(Vector128<short> value) => BroadcastScalarToVector256(value);
-
- /// <summary>
- /// __m256i _mm256_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW ymm, xmm
- /// </summary>
- public static Vector256<ushort> BroadcastScalarToVector256(Vector128<ushort> value) => BroadcastScalarToVector256(value);
-
- /// <summary>
- /// __m256i _mm256_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD ymm, xmm
- /// </summary>
- public static Vector256<int> BroadcastScalarToVector256(Vector128<int> value) => BroadcastScalarToVector256(value);
-
- /// <summary>
- /// __m256i _mm256_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD ymm, xmm
- /// </summary>
- public static Vector256<uint> BroadcastScalarToVector256(Vector128<uint> value) => BroadcastScalarToVector256(value);
-
- /// <summary>
- /// __m256i _mm256_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ ymm, xmm
- /// </summary>
- public static Vector256<long> BroadcastScalarToVector256(Vector128<long> value) => BroadcastScalarToVector256(value);
-
- /// <summary>
- /// __m256i _mm256_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ ymm, xmm
- /// </summary>
- public static Vector256<ulong> BroadcastScalarToVector256(Vector128<ulong> value) => BroadcastScalarToVector256(value);
-
- /// <summary>
- /// __m256 _mm256_broadcastss_ps (__m128 a)
- /// VBROADCASTSS ymm, xmm
- /// </summary>
- public static Vector256<float> BroadcastScalarToVector256(Vector128<float> value) => BroadcastScalarToVector256(value);
-
- /// <summary>
- /// __m256d _mm256_broadcastsd_pd (__m128d a)
- /// VBROADCASTSD ymm, xmm
- /// </summary>
- public static Vector256<double> BroadcastScalarToVector256(Vector128<double> value) => BroadcastScalarToVector256(value);
-
- /// <summary>
- /// __m256i _mm256_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB ymm, m8
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<byte> BroadcastScalarToVector256(byte* source) => BroadcastScalarToVector256(source);
- /// <summary>
- /// __m256i _mm256_broadcastb_epi8 (__m128i a)
- /// VPBROADCASTB ymm, m8
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<sbyte> BroadcastScalarToVector256(sbyte* source) => BroadcastScalarToVector256(source);
-
- /// <summary>
- /// __m256i _mm256_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW ymm, m16
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<short> BroadcastScalarToVector256(short* source) => BroadcastScalarToVector256(source);
- /// <summary>
- /// __m256i _mm256_broadcastw_epi16 (__m128i a)
- /// VPBROADCASTW ymm, m16
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<ushort> BroadcastScalarToVector256(ushort* source) => BroadcastScalarToVector256(source);
-
- /// <summary>
- /// __m256i _mm256_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD ymm, m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<int> BroadcastScalarToVector256(int* source) => BroadcastScalarToVector256(source);
- /// <summary>
- /// __m256i _mm256_broadcastd_epi32 (__m128i a)
- /// VPBROADCASTD ymm, m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<uint> BroadcastScalarToVector256(uint* source) => BroadcastScalarToVector256(source);
-
- /// <summary>
- /// __m256i _mm256_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ ymm, m64
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<long> BroadcastScalarToVector256(long* source) => BroadcastScalarToVector256(source);
- /// <summary>
- /// __m256i _mm256_broadcastq_epi64 (__m128i a)
- /// VPBROADCASTQ ymm, m64
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<ulong> BroadcastScalarToVector256(ulong* source) => BroadcastScalarToVector256(source);
-
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<sbyte> BroadcastVector128ToVector256(sbyte* address) => BroadcastVector128ToVector256(address);
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<byte> BroadcastVector128ToVector256(byte* address) => BroadcastVector128ToVector256(address);
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<short> BroadcastVector128ToVector256(short* address) => BroadcastVector128ToVector256(address);
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<ushort> BroadcastVector128ToVector256(ushort* address) => BroadcastVector128ToVector256(address);
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<int> BroadcastVector128ToVector256(int* address) => BroadcastVector128ToVector256(address);
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<uint> BroadcastVector128ToVector256(uint* address) => BroadcastVector128ToVector256(address);
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<long> BroadcastVector128ToVector256(long* address) => BroadcastVector128ToVector256(address);
- /// <summary>
- /// __m256i _mm256_broadcastsi128_si256 (__m128i a)
- /// VBROADCASTI128 ymm, m128
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe Vector256<ulong> BroadcastVector128ToVector256(ulong* address) => BroadcastVector128ToVector256(address);
-
- /// <summary>
- /// __m256i _mm256_cmpeq_epi8 (__m256i a, __m256i b)
- /// VPCMPEQB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> CompareEqual(Vector256<sbyte> left, Vector256<sbyte> right) => CompareEqual(left, right);
- /// <summary>
- /// __m256i _mm256_cmpeq_epi8 (__m256i a, __m256i b)
- /// VPCMPEQB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> CompareEqual(Vector256<byte> left, Vector256<byte> right) => CompareEqual(left, right);
- /// <summary>
- /// __m256i _mm256_cmpeq_epi16 (__m256i a, __m256i b)
- /// VPCMPEQW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> CompareEqual(Vector256<short> left, Vector256<short> right) => CompareEqual(left, right);
- /// <summary>
- /// __m256i _mm256_cmpeq_epi16 (__m256i a, __m256i b)
- /// VPCMPEQW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> CompareEqual(Vector256<ushort> left, Vector256<ushort> right) => CompareEqual(left, right);
- /// <summary>
- /// __m256i _mm256_cmpeq_epi32 (__m256i a, __m256i b)
- /// VPCMPEQD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> CompareEqual(Vector256<int> left, Vector256<int> right) => CompareEqual(left, right);
- /// <summary>
- /// __m256i _mm256_cmpeq_epi32 (__m256i a, __m256i b)
- /// VPCMPEQD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> CompareEqual(Vector256<uint> left, Vector256<uint> right) => CompareEqual(left, right);
- /// <summary>
- /// __m256i _mm256_cmpeq_epi64 (__m256i a, __m256i b)
- /// VPCMPEQQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> CompareEqual(Vector256<long> left, Vector256<long> right) => CompareEqual(left, right);
- /// <summary>
- /// __m256i _mm256_cmpeq_epi64 (__m256i a, __m256i b)
- /// VPCMPEQQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> CompareEqual(Vector256<ulong> left, Vector256<ulong> right) => CompareEqual(left, right);
-
- /// <summary>
- /// __m256i _mm256_cmpgt_epi8 (__m256i a, __m256i b)
- /// VPCMPGTB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> CompareGreaterThan(Vector256<sbyte> left, Vector256<sbyte> right) => CompareGreaterThan(left, right);
- /// <summary>
- /// __m256i _mm256_cmpgt_epi16 (__m256i a, __m256i b)
- /// VPCMPGTW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> CompareGreaterThan(Vector256<short> left, Vector256<short> right) => CompareGreaterThan(left, right);
- /// <summary>
- /// __m256i _mm256_cmpgt_epi32 (__m256i a, __m256i b)
- /// VPCMPGTD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> CompareGreaterThan(Vector256<int> left, Vector256<int> right) => CompareGreaterThan(left, right);
- /// <summary>
- /// __m256i _mm256_cmpgt_epi64 (__m256i a, __m256i b)
- /// VPCMPGTQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> CompareGreaterThan(Vector256<long> left, Vector256<long> right) => CompareGreaterThan(left, right);
-
- /// <summary>
- /// int _mm256_cvtsi256_si32 (__m256i a)
- /// MOVD reg/m32, xmm
- /// </summary>
- public static int ConvertToInt32(Vector256<int> value) => ConvertToInt32(value);
- /// <summary>
- /// int _mm256_cvtsi256_si32 (__m256i a)
- /// MOVD reg/m32, xmm
- /// </summary>
- public static uint ConvertToUInt32(Vector256<uint> value) => ConvertToUInt32(value);
-
- /// <summary>
- /// __m256i _mm256_cvtepi8_epi16 (__m128i a)
- /// VPMOVSXBW ymm, xmm
- /// </summary>
- public static Vector256<short> ConvertToVector256Int16(Vector128<sbyte> value) => ConvertToVector256Int16(value);
- /// <summary>
- /// __m256i _mm256_cvtepu8_epi16 (__m128i a)
- /// VPMOVZXBW ymm, xmm
- /// </summary>
- public static Vector256<short> ConvertToVector256Int16(Vector128<byte> value) => ConvertToVector256Int16(value);
- /// <summary>
- /// __m256i _mm256_cvtepi8_epi32 (__m128i a)
- /// VPMOVSXBD ymm, xmm
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32(Vector128<sbyte> value) => ConvertToVector256Int32(value);
- /// <summary>
- /// __m256i _mm256_cvtepu8_epi32 (__m128i a)
- /// VPMOVZXBD ymm, xmm
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32(Vector128<byte> value) => ConvertToVector256Int32(value);
- /// <summary>
- /// __m256i _mm256_cvtepi16_epi32 (__m128i a)
- /// VPMOVSXWD ymm, xmm
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32(Vector128<short> value) => ConvertToVector256Int32(value);
- /// <summary>
- /// __m256i _mm256_cvtepu16_epi32 (__m128i a)
- /// VPMOVZXWD ymm, xmm
- /// </summary>
- public static Vector256<int> ConvertToVector256Int32(Vector128<ushort> value) => ConvertToVector256Int32(value);
- /// <summary>
- /// __m256i _mm256_cvtepi8_epi64 (__m128i a)
- /// VPMOVSXBQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<sbyte> value) => ConvertToVector256Int64(value);
- /// <summary>
- /// __m256i _mm256_cvtepu8_epi64 (__m128i a)
- /// VPMOVZXBQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<byte> value) => ConvertToVector256Int64(value);
- /// <summary>
- /// __m256i _mm256_cvtepi16_epi64 (__m128i a)
- /// VPMOVSXWQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<short> value) => ConvertToVector256Int64(value);
- /// <summary>
- /// __m256i _mm256_cvtepu16_epi64 (__m128i a)
- /// VPMOVZXWQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<ushort> value) => ConvertToVector256Int64(value);
- /// <summary>
- /// __m256i _mm256_cvtepi32_epi64 (__m128i a)
- /// VPMOVSXDQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<int> value) => ConvertToVector256Int64(value);
- /// <summary>
- /// __m256i _mm256_cvtepu32_epi64 (__m128i a)
- /// VPMOVZXDQ ymm, xmm
- /// </summary>
- public static Vector256<long> ConvertToVector256Int64(Vector128<uint> value) => ConvertToVector256Int64(value);
-
- /// <summary>
- /// VPMOVSXBW ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<short> ConvertToVector256Int16(sbyte* address) => ConvertToVector256Int16(address);
- /// <summary>
- /// VPMOVZXBW ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<short> ConvertToVector256Int16(byte* address) => ConvertToVector256Int16(address);
- /// <summary>
- /// VPMOVSXBD ymm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<int> ConvertToVector256Int32(sbyte* address) => ConvertToVector256Int32(address);
- /// <summary>
- /// VPMOVZXBD ymm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<int> ConvertToVector256Int32(byte* address) => ConvertToVector256Int32(address);
- /// <summary>
- /// VPMOVSXWD ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<int> ConvertToVector256Int32(short* address) => ConvertToVector256Int32(address);
- /// <summary>
- /// VPMOVZXWD ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<int> ConvertToVector256Int32(ushort* address) => ConvertToVector256Int32(address);
- /// <summary>
- /// VPMOVSXBQ ymm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(sbyte* address) => ConvertToVector256Int64(address);
- /// <summary>
- /// VPMOVZXBQ ymm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(byte* address) => ConvertToVector256Int64(address);
- /// <summary>
- /// VPMOVSXWQ ymm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(short* address) => ConvertToVector256Int64(address);
- /// <summary>
- /// VPMOVZXWQ ymm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(ushort* address) => ConvertToVector256Int64(address);
- /// <summary>
- /// VPMOVSXDQ ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(int* address) => ConvertToVector256Int64(address);
- /// <summary>
- /// VPMOVZXDQ ymm, m128
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector256<long> ConvertToVector256Int64(uint* address) => ConvertToVector256Int64(address);
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<sbyte> ExtractVector128(Vector256<sbyte> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<byte> ExtractVector128(Vector256<byte> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<short> ExtractVector128(Vector256<short> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<ushort> ExtractVector128(Vector256<ushort> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<int> ExtractVector128(Vector256<int> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<uint> ExtractVector128(Vector256<uint> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<long> ExtractVector128(Vector256<long> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 xmm, ymm, imm8
- /// </summary>
- public static new Vector128<ulong> ExtractVector128(Vector256<ulong> value, byte index) => ExtractVector128(value, index);
-
- /// <summary>
- /// __m128i _mm_i32gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherVector128(int* baseAddress, Vector128<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_i32gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherVector128(uint* baseAddress, Vector128<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDQ xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<long> GatherVector128(long* baseAddress, Vector128<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDQ xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<ulong> GatherVector128(ulong* baseAddress, Vector128<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128 _mm_i32gather_ps (float const* base_addr, __m128i vindex, const int scale)
- /// VGATHERDPS xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherVector128(float* baseAddress, Vector128<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128d _mm_i32gather_pd (double const* base_addr, __m128i vindex, const int scale)
- /// VGATHERDPD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<double> GatherVector128(double* baseAddress, Vector128<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_i64gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERQD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherVector128(int* baseAddress, Vector128<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_i64gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERQD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherVector128(uint* baseAddress, Vector128<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_i64gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERQQ xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<long> GatherVector128(long* baseAddress, Vector128<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_i64gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERQQ xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<ulong> GatherVector128(ulong* baseAddress, Vector128<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128 _mm_i64gather_ps (float const* base_addr, __m128i vindex, const int scale)
- /// VGATHERQPS xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherVector128(float* baseAddress, Vector128<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128d _mm_i64gather_pd (double const* base_addr, __m128i vindex, const int scale)
- /// VGATHERQPD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<double> GatherVector128(double* baseAddress, Vector128<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_i32gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERDD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<int> GatherVector256(int* baseAddress, Vector256<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector256(baseAddress, index, 1),
- 2 => GatherVector256(baseAddress, index, 2),
- 4 => GatherVector256(baseAddress, index, 4),
- 8 => GatherVector256(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_i32gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERDD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<uint> GatherVector256(uint* baseAddress, Vector256<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector256(baseAddress, index, 1),
- 2 => GatherVector256(baseAddress, index, 2),
- 4 => GatherVector256(baseAddress, index, 4),
- 8 => GatherVector256(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<long> GatherVector256(long* baseAddress, Vector128<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector256(baseAddress, index, 1),
- 2 => GatherVector256(baseAddress, index, 2),
- 4 => GatherVector256(baseAddress, index, 4),
- 8 => GatherVector256(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
- /// VPGATHERDQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<ulong> GatherVector256(ulong* baseAddress, Vector128<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector256(baseAddress, index, 1),
- 2 => GatherVector256(baseAddress, index, 2),
- 4 => GatherVector256(baseAddress, index, 4),
- 8 => GatherVector256(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256 _mm256_i32gather_ps (float const* base_addr, __m256i vindex, const int scale)
- /// VGATHERDPS ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<float> GatherVector256(float* baseAddress, Vector256<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector256(baseAddress, index, 1),
- 2 => GatherVector256(baseAddress, index, 2),
- 4 => GatherVector256(baseAddress, index, 4),
- 8 => GatherVector256(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256d _mm256_i32gather_pd (double const* base_addr, __m128i vindex, const int scale)
- /// VGATHERDPD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<double> GatherVector256(double* baseAddress, Vector128<int> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector256(baseAddress, index, 1),
- 2 => GatherVector256(baseAddress, index, 2),
- 4 => GatherVector256(baseAddress, index, 4),
- 8 => GatherVector256(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm256_i64gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERQD xmm, vm64y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherVector128(int* baseAddress, Vector256<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm256_i64gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERQD xmm, vm64y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherVector128(uint* baseAddress, Vector256<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_i64gather_epi64 (__int64 const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERQQ ymm, vm64y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<long> GatherVector256(long* baseAddress, Vector256<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector256(baseAddress, index, 1),
- 2 => GatherVector256(baseAddress, index, 2),
- 4 => GatherVector256(baseAddress, index, 4),
- 8 => GatherVector256(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_i64gather_epi64 (__int64 const* base_addr, __m256i vindex, const int scale)
- /// VPGATHERQQ ymm, vm64y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<ulong> GatherVector256(ulong* baseAddress, Vector256<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector256(baseAddress, index, 1),
- 2 => GatherVector256(baseAddress, index, 2),
- 4 => GatherVector256(baseAddress, index, 4),
- 8 => GatherVector256(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128 _mm256_i64gather_ps (float const* base_addr, __m256i vindex, const int scale)
- /// VGATHERQPS xmm, vm64y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherVector128(float* baseAddress, Vector256<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector128(baseAddress, index, 1),
- 2 => GatherVector128(baseAddress, index, 2),
- 4 => GatherVector128(baseAddress, index, 4),
- 8 => GatherVector128(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256d _mm256_i64gather_pd (double const* base_addr, __m256i vindex, const int scale)
- /// VGATHERQPD ymm, vm64y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<double> GatherVector256(double* baseAddress, Vector256<long> index, byte scale)
- {
- return scale switch
- {
- 1 => GatherVector256(baseAddress, index, 1),
- 2 => GatherVector256(baseAddress, index, 2),
- 4 => GatherVector256(baseAddress, index, 4),
- 8 => GatherVector256(baseAddress, index, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
-
- /// <summary>
- /// __m128i _mm_mask_i32gather_epi32 (__m128i src, int const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERDD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherMaskVector128(Vector128<int> source, int* baseAddress, Vector128<int> index, Vector128<int> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_mask_i32gather_epi32 (__m128i src, int const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERDD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherMaskVector128(Vector128<uint> source, uint* baseAddress, Vector128<int> index, Vector128<uint> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_mask_i32gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERDQ xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<long> GatherMaskVector128(Vector128<long> source, long* baseAddress, Vector128<int> index, Vector128<long> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_mask_i32gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERDQ xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<ulong> GatherMaskVector128(Vector128<ulong> source, ulong* baseAddress, Vector128<int> index, Vector128<ulong> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128 _mm_mask_i32gather_ps (__m128 src, float const* base_addr, __m128i vindex, __m128 mask, const int scale)
- /// VGATHERDPS xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherMaskVector128(Vector128<float> source, float* baseAddress, Vector128<int> index, Vector128<float> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128d _mm_mask_i32gather_pd (__m128d src, double const* base_addr, __m128i vindex, __m128d mask, const int scale)
- /// VGATHERDPD xmm, vm32x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<double> GatherMaskVector128(Vector128<double> source, double* baseAddress, Vector128<int> index, Vector128<double> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERQD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherMaskVector128(Vector128<int> source, int* baseAddress, Vector128<long> index, Vector128<int> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERQD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherMaskVector128(Vector128<uint> source, uint* baseAddress, Vector128<long> index, Vector128<uint> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_mask_i64gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERQQ xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<long> GatherMaskVector128(Vector128<long> source, long* baseAddress, Vector128<long> index, Vector128<long> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm_mask_i64gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
- /// VPGATHERQQ xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<ulong> GatherMaskVector128(Vector128<ulong> source, ulong* baseAddress, Vector128<long> index, Vector128<ulong> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128 _mm_mask_i64gather_ps (__m128 src, float const* base_addr, __m128i vindex, __m128 mask, const int scale)
- /// VGATHERQPS xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherMaskVector128(Vector128<float> source, float* baseAddress, Vector128<long> index, Vector128<float> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128d _mm_mask_i64gather_pd (__m128d src, double const* base_addr, __m128i vindex, __m128d mask, const int scale)
- /// VGATHERQPD xmm, vm64x, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<double> GatherMaskVector128(Vector128<double> source, double* baseAddress, Vector128<long> index, Vector128<double> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_mask_i32gather_epi32 (__m256i src, int const* base_addr, __m256i vindex, __m256i mask, const int scale)
- /// VPGATHERDD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<int> GatherMaskVector256(Vector256<int> source, int* baseAddress, Vector256<int> index, Vector256<int> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_mask_i32gather_epi32 (__m256i src, int const* base_addr, __m256i vindex, __m256i mask, const int scale)
- /// VPGATHERDD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<uint> GatherMaskVector256(Vector256<uint> source, uint* baseAddress, Vector256<int> index, Vector256<uint> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_mask_i32gather_epi64 (__m256i src, __int64 const* base_addr, __m128i vindex, __m256i mask, const int scale)
- /// VPGATHERDQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<long> GatherMaskVector256(Vector256<long> source, long* baseAddress, Vector128<int> index, Vector256<long> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_mask_i32gather_epi64 (__m256i src, __int64 const* base_addr, __m128i vindex, __m256i mask, const int scale)
- /// VPGATHERDQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<ulong> GatherMaskVector256(Vector256<ulong> source, ulong* baseAddress, Vector128<int> index, Vector256<ulong> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256 _mm256_mask_i32gather_ps (__m256 src, float const* base_addr, __m256i vindex, __m256 mask, const int scale)
- /// VPGATHERDPS ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<float> GatherMaskVector256(Vector256<float> source, float* baseAddress, Vector256<int> index, Vector256<float> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256d _mm256_mask_i32gather_pd (__m256d src, double const* base_addr, __m128i vindex, __m256d mask, const int scale)
- /// VPGATHERDPD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<double> GatherMaskVector256(Vector256<double> source, double* baseAddress, Vector128<int> index, Vector256<double> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm256_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m256i vindex, __m128i mask, const int scale)
- /// VPGATHERQD xmm, vm32y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<int> GatherMaskVector128(Vector128<int> source, int* baseAddress, Vector256<long> index, Vector128<int> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128i _mm256_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m256i vindex, __m128i mask, const int scale)
- /// VPGATHERQD xmm, vm32y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<uint> GatherMaskVector128(Vector128<uint> source, uint* baseAddress, Vector256<long> index, Vector128<uint> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_mask_i64gather_epi64 (__m256i src, __int64 const* base_addr, __m256i vindex, __m256i mask, const int scale)
- /// VPGATHERQQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<long> GatherMaskVector256(Vector256<long> source, long* baseAddress, Vector256<long> index, Vector256<long> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256i _mm256_mask_i64gather_epi64 (__m256i src, __int64 const* base_addr, __m256i vindex, __m256i mask, const int scale)
- /// VPGATHERQQ ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<ulong> GatherMaskVector256(Vector256<ulong> source, ulong* baseAddress, Vector256<long> index, Vector256<ulong> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m128 _mm256_mask_i64gather_ps (__m128 src, float const* base_addr, __m256i vindex, __m128 mask, const int scale)
- /// VGATHERQPS xmm, vm32y, xmm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector128<float> GatherMaskVector128(Vector128<float> source, float* baseAddress, Vector256<long> index, Vector128<float> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
- /// <summary>
- /// __m256d _mm256_mask_i64gather_pd (__m256d src, double const* base_addr, __m256i vindex, __m256d mask, const int scale)
- /// VGATHERQPD ymm, vm32y, ymm
- /// The scale parameter should be 1, 2, 4 or 8, otherwise, ArgumentOutOfRangeException will be thrown.
- /// </summary>
- public static unsafe Vector256<double> GatherMaskVector256(Vector256<double> source, double* baseAddress, Vector256<long> index, Vector256<double> mask, byte scale)
- {
- return scale switch
- {
- 1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
- 2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
- 4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
- 8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
- _ => throw new ArgumentOutOfRangeException(nameof(scale)),
- };
- }
-
- /// <summary>
- /// __m256i _mm256_hadd_epi16 (__m256i a, __m256i b)
- /// VPHADDW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> HorizontalAdd(Vector256<short> left, Vector256<short> right) => HorizontalAdd(left, right);
- /// <summary>
- /// __m256i _mm256_hadd_epi32 (__m256i a, __m256i b)
- /// VPHADDD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> HorizontalAdd(Vector256<int> left, Vector256<int> right) => HorizontalAdd(left, right);
-
- /// <summary>
- /// __m256i _mm256_hadds_epi16 (__m256i a, __m256i b)
- /// VPHADDSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> HorizontalAddSaturate(Vector256<short> left, Vector256<short> right) => HorizontalAddSaturate(left, right);
-
- /// <summary>
- /// __m256i _mm256_hsub_epi16 (__m256i a, __m256i b)
- /// VPHSUBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> HorizontalSubtract(Vector256<short> left, Vector256<short> right) => HorizontalSubtract(left, right);
- /// <summary>
- /// __m256i _mm256_hsub_epi32 (__m256i a, __m256i b)
- /// VPHSUBD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> HorizontalSubtract(Vector256<int> left, Vector256<int> right) => HorizontalSubtract(left, right);
-
- /// <summary>
- /// __m256i _mm256_hsubs_epi16 (__m256i a, __m256i b)
- /// VPHSUBSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> HorizontalSubtractSaturate(Vector256<short> left, Vector256<short> right) => HorizontalSubtractSaturate(left, right);
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<sbyte> InsertVector128(Vector256<sbyte> value, Vector128<sbyte> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<byte> InsertVector128(Vector256<byte> value, Vector128<byte> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<short> InsertVector128(Vector256<short> value, Vector128<short> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<ushort> InsertVector128(Vector256<ushort> value, Vector128<ushort> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<int> InsertVector128(Vector256<int> value, Vector128<int> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<uint> InsertVector128(Vector256<uint> value, Vector128<uint> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<long> InsertVector128(Vector256<long> value, Vector128<long> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xmm, imm8
- /// </summary>
- public static new Vector256<ulong> InsertVector128(Vector256<ulong> value, Vector128<ulong> data, byte index) => InsertVector128(value, data, index);
-
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<sbyte> LoadAlignedVector256NonTemporal(sbyte* address) => LoadAlignedVector256NonTemporal(address);
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<byte> LoadAlignedVector256NonTemporal(byte* address) => LoadAlignedVector256NonTemporal(address);
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<short> LoadAlignedVector256NonTemporal(short* address) => LoadAlignedVector256NonTemporal(address);
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<ushort> LoadAlignedVector256NonTemporal(ushort* address) => LoadAlignedVector256NonTemporal(address);
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<int> LoadAlignedVector256NonTemporal(int* address) => LoadAlignedVector256NonTemporal(address);
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<uint> LoadAlignedVector256NonTemporal(uint* address) => LoadAlignedVector256NonTemporal(address);
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<long> LoadAlignedVector256NonTemporal(long* address) => LoadAlignedVector256NonTemporal(address);
- /// <summary>
- /// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
- /// VMOVNTDQA ymm, m256
- /// </summary>
- public static unsafe Vector256<ulong> LoadAlignedVector256NonTemporal(ulong* address) => LoadAlignedVector256NonTemporal(address);
-
- /// <summary>
- /// __m128i _mm_maskload_epi32 (int const* mem_addr, __m128i mask)
- /// VPMASKMOVD xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<int> MaskLoad(int* address, Vector128<int> mask) => MaskLoad(address, mask);
- /// <summary>
- /// __m128i _mm_maskload_epi32 (int const* mem_addr, __m128i mask)
- /// VPMASKMOVD xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<uint> MaskLoad(uint* address, Vector128<uint> mask) => MaskLoad(address, mask);
- /// <summary>
- /// __m128i _mm_maskload_epi64 (__int64 const* mem_addr, __m128i mask)
- /// VPMASKMOVQ xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<long> MaskLoad(long* address, Vector128<long> mask) => MaskLoad(address, mask);
- /// <summary>
- /// __m128i _mm_maskload_epi64 (__int64 const* mem_addr, __m128i mask)
- /// VPMASKMOVQ xmm, xmm, m128
- /// </summary>
- public static unsafe Vector128<ulong> MaskLoad(ulong* address, Vector128<ulong> mask) => MaskLoad(address, mask);
-
- /// <summary>
- /// __m256i _mm256_maskload_epi32 (int const* mem_addr, __m256i mask)
- /// VPMASKMOVD ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<int> MaskLoad(int* address, Vector256<int> mask) => MaskLoad(address, mask);
- /// <summary>
- /// __m256i _mm256_maskload_epi32 (int const* mem_addr, __m256i mask)
- /// VPMASKMOVD ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<uint> MaskLoad(uint* address, Vector256<uint> mask) => MaskLoad(address, mask);
- /// <summary>
- /// __m256i _mm256_maskload_epi64 (__int64 const* mem_addr, __m256i mask)
- /// VPMASKMOVQ ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<long> MaskLoad(long* address, Vector256<long> mask) => MaskLoad(address, mask);
- /// <summary>
- /// __m256i _mm256_maskload_epi64 (__int64 const* mem_addr, __m256i mask)
- /// VPMASKMOVQ ymm, ymm, m256
- /// </summary>
- public static unsafe Vector256<ulong> MaskLoad(ulong* address, Vector256<ulong> mask) => MaskLoad(address, mask);
-
- /// <summary>
- /// void _mm_maskstore_epi32 (int* mem_addr, __m128i mask, __m128i a)
- /// VPMASKMOVD m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(int* address, Vector128<int> mask, Vector128<int> source) => MaskStore(address, mask, source);
- /// <summary>
- /// void _mm_maskstore_epi32 (int* mem_addr, __m128i mask, __m128i a)
- /// VPMASKMOVD m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(uint* address, Vector128<uint> mask, Vector128<uint> source) => MaskStore(address, mask, source);
- /// <summary>
- /// void _mm_maskstore_epi64 (__int64* mem_addr, __m128i mask, __m128i a)
- /// VPMASKMOVQ m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(long* address, Vector128<long> mask, Vector128<long> source) => MaskStore(address, mask, source);
- /// <summary>
- /// void _mm_maskstore_epi64 (__int64* mem_addr, __m128i mask, __m128i a)
- /// VPMASKMOVQ m128, xmm, xmm
- /// </summary>
- public static unsafe void MaskStore(ulong* address, Vector128<ulong> mask, Vector128<ulong> source) => MaskStore(address, mask, source);
-
- /// <summary>
- /// void _mm256_maskstore_epi32 (int* mem_addr, __m256i mask, __m256i a)
- /// VPMASKMOVD m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(int* address, Vector256<int> mask, Vector256<int> source) => MaskStore(address, mask, source);
- /// <summary>
- /// void _mm256_maskstore_epi32 (int* mem_addr, __m256i mask, __m256i a)
- /// VPMASKMOVD m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(uint* address, Vector256<uint> mask, Vector256<uint> source) => MaskStore(address, mask, source);
- /// <summary>
- /// void _mm256_maskstore_epi64 (__int64* mem_addr, __m256i mask, __m256i a)
- /// VPMASKMOVQ m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(long* address, Vector256<long> mask, Vector256<long> source) => MaskStore(address, mask, source);
- /// <summary>
- /// void _mm256_maskstore_epi64 (__int64* mem_addr, __m256i mask, __m256i a)
- /// VPMASKMOVQ m256, ymm, ymm
- /// </summary>
- public static unsafe void MaskStore(ulong* address, Vector256<ulong> mask, Vector256<ulong> source) => MaskStore(address, mask, source);
-
- /// <summary>
- /// __m256i _mm256_madd_epi16 (__m256i a, __m256i b)
- /// VPMADDWD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> MultiplyAddAdjacent(Vector256<short> left, Vector256<short> right) => MultiplyAddAdjacent(left, right);
-
- /// <summary>
- /// __m256i _mm256_maddubs_epi16 (__m256i a, __m256i b)
- /// VPMADDUBSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> MultiplyAddAdjacent(Vector256<byte> left, Vector256<sbyte> right) => MultiplyAddAdjacent(left, right);
-
- /// <summary>
- /// __m256i _mm256_max_epi8 (__m256i a, __m256i b)
- /// VPMAXSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Max(Vector256<sbyte> left, Vector256<sbyte> right) => Max(left, right);
- /// <summary>
- /// __m256i _mm256_max_epu8 (__m256i a, __m256i b)
- /// VPMAXUB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Max(Vector256<byte> left, Vector256<byte> right) => Max(left, right);
- /// <summary>
- /// __m256i _mm256_max_epi16 (__m256i a, __m256i b)
- /// VPMAXSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Max(Vector256<short> left, Vector256<short> right) => Max(left, right);
- /// <summary>
- /// __m256i _mm256_max_epu16 (__m256i a, __m256i b)
- /// VPMAXUW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Max(Vector256<ushort> left, Vector256<ushort> right) => Max(left, right);
- /// <summary>
- /// __m256i _mm256_max_epi32 (__m256i a, __m256i b)
- /// VPMAXSD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Max(Vector256<int> left, Vector256<int> right) => Max(left, right);
- /// <summary>
- /// __m256i _mm256_max_epu32 (__m256i a, __m256i b)
- /// VPMAXUD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Max(Vector256<uint> left, Vector256<uint> right) => Max(left, right);
-
- /// <summary>
- /// __m256i _mm256_min_epi8 (__m256i a, __m256i b)
- /// VPMINSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Min(Vector256<sbyte> left, Vector256<sbyte> right) => Min(left, right);
- /// <summary>
- /// __m256i _mm256_min_epu8 (__m256i a, __m256i b)
- /// VPMINUB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Min(Vector256<byte> left, Vector256<byte> right) => Min(left, right);
- /// <summary>
- /// __m256i _mm256_min_epi16 (__m256i a, __m256i b)
- /// VPMINSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Min(Vector256<short> left, Vector256<short> right) => Min(left, right);
- /// <summary>
- /// __m256i _mm256_min_epu16 (__m256i a, __m256i b)
- /// VPMINUW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Min(Vector256<ushort> left, Vector256<ushort> right) => Min(left, right);
- /// <summary>
- /// __m256i _mm256_min_epi32 (__m256i a, __m256i b)
- /// VPMINSD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Min(Vector256<int> left, Vector256<int> right) => Min(left, right);
- /// <summary>
- /// __m256i _mm256_min_epu32 (__m256i a, __m256i b)
- /// VPMINUD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Min(Vector256<uint> left, Vector256<uint> right) => Min(left, right);
-
- /// <summary>
- /// int _mm256_movemask_epi8 (__m256i a)
- /// VPMOVMSKB reg, ymm
- /// </summary>
- public static int MoveMask(Vector256<sbyte> value) => MoveMask(value);
- /// <summary>
- /// int _mm256_movemask_epi8 (__m256i a)
- /// VPMOVMSKB reg, ymm
- /// </summary>
- public static int MoveMask(Vector256<byte> value) => MoveMask(value);
-
- /// <summary>
- /// __m256i _mm256_mpsadbw_epu8 (__m256i a, __m256i b, const int imm8)
- /// VMPSADBW ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ushort> MultipleSumAbsoluteDifferences(Vector256<byte> left, Vector256<byte> right, byte mask) => MultipleSumAbsoluteDifferences(left, right, mask);
-
- /// <summary>
- /// __m256i _mm256_mul_epi32 (__m256i a, __m256i b)
- /// VPMULDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> Multiply(Vector256<int> left, Vector256<int> right) => Multiply(left, right);
- /// <summary>
- /// __m256i _mm256_mul_epu32 (__m256i a, __m256i b)
- /// VPMULUDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> Multiply(Vector256<uint> left, Vector256<uint> right) => Multiply(left, right);
-
- /// <summary>
- /// __m256i _mm256_mulhi_epi16 (__m256i a, __m256i b)
- /// VPMULHW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> MultiplyHigh(Vector256<short> left, Vector256<short> right) => MultiplyHigh(left, right);
- /// <summary>
- /// __m256i _mm256_mulhi_epu16 (__m256i a, __m256i b)
- /// VPMULHUW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> MultiplyHigh(Vector256<ushort> left, Vector256<ushort> right) => MultiplyHigh(left, right);
-
- /// <summary>
- /// __m256i _mm256_mulhrs_epi16 (__m256i a, __m256i b)
- /// VPMULHRSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> MultiplyHighRoundScale(Vector256<short> left, Vector256<short> right) => MultiplyHighRoundScale(left, right);
-
- /// <summary>
- /// __m256i _mm256_mullo_epi16 (__m256i a, __m256i b)
- /// VPMULLW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> MultiplyLow(Vector256<short> left, Vector256<short> right) => MultiplyLow(left, right);
- /// <summary>
- /// __m256i _mm256_mullo_epi16 (__m256i a, __m256i b)
- /// VPMULLW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> MultiplyLow(Vector256<ushort> left, Vector256<ushort> right) => MultiplyLow(left, right);
-
- /// <summary>
- /// __m256i _mm256_mullo_epi32 (__m256i a, __m256i b)
- /// VPMULLD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> MultiplyLow(Vector256<int> left, Vector256<int> right) => MultiplyLow(left, right);
- /// <summary>
- /// __m256i _mm256_mullo_epi32 (__m256i a, __m256i b)
- /// VPMULLD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> MultiplyLow(Vector256<uint> left, Vector256<uint> right) => MultiplyLow(left, right);
-
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Or(Vector256<sbyte> left, Vector256<sbyte> right) => Or(left, right);
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Or(Vector256<byte> left, Vector256<byte> right) => Or(left, right);
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Or(Vector256<short> left, Vector256<short> right) => Or(left, right);
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Or(Vector256<ushort> left, Vector256<ushort> right) => Or(left, right);
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Or(Vector256<int> left, Vector256<int> right) => Or(left, right);
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Or(Vector256<uint> left, Vector256<uint> right) => Or(left, right);
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> Or(Vector256<long> left, Vector256<long> right) => Or(left, right);
- /// <summary>
- /// __m256i _mm256_or_si256 (__m256i a, __m256i b)
- /// VPOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> Or(Vector256<ulong> left, Vector256<ulong> right) => Or(left, right);
-
- /// <summary>
- /// __m256i _mm256_packs_epi16 (__m256i a, __m256i b)
- /// VPACKSSWB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> PackSignedSaturate(Vector256<short> left, Vector256<short> right) => PackSignedSaturate(left, right);
- /// <summary>
- /// __m256i _mm256_packs_epi32 (__m256i a, __m256i b)
- /// VPACKSSDW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> PackSignedSaturate(Vector256<int> left, Vector256<int> right) => PackSignedSaturate(left, right);
- /// <summary>
- /// __m256i _mm256_packus_epi16 (__m256i a, __m256i b)
- /// VPACKUSWB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> PackUnsignedSaturate(Vector256<short> left, Vector256<short> right) => PackUnsignedSaturate(left, right);
- /// <summary>
- /// __m256i _mm256_packus_epi32 (__m256i a, __m256i b)
- /// VPACKUSDW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> PackUnsignedSaturate(Vector256<int> left, Vector256<int> right) => PackUnsignedSaturate(left, right);
-
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<sbyte> Permute2x128(Vector256<sbyte> left, Vector256<sbyte> right, byte control) => Permute2x128(left, right, control);
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<byte> Permute2x128(Vector256<byte> left, Vector256<byte> right, byte control) => Permute2x128(left, right, control);
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<short> Permute2x128(Vector256<short> left, Vector256<short> right, byte control) => Permute2x128(left, right, control);
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<ushort> Permute2x128(Vector256<ushort> left, Vector256<ushort> right, byte control) => Permute2x128(left, right, control);
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<int> Permute2x128(Vector256<int> left, Vector256<int> right, byte control) => Permute2x128(left, right, control);
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<uint> Permute2x128(Vector256<uint> left, Vector256<uint> right, byte control) => Permute2x128(left, right, control);
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<long> Permute2x128(Vector256<long> left, Vector256<long> right, byte control) => Permute2x128(left, right, control);
- /// <summary>
- /// __m256i _mm256_permute2x128_si256 (__m256i a, __m256i b, const int imm8)
- /// VPERM2I128 ymm, ymm, ymm/m256, imm8
- /// </summary>
- public static new Vector256<ulong> Permute2x128(Vector256<ulong> left, Vector256<ulong> right, byte control) => Permute2x128(left, right, control);
-
- /// <summary>
- /// __m256i _mm256_permute4x64_epi64 (__m256i a, const int imm8)
- /// VPERMQ ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<long> Permute4x64(Vector256<long> value, byte control) => Permute4x64(value, control);
- /// <summary>
- /// __m256i _mm256_permute4x64_epi64 (__m256i a, const int imm8)
- /// VPERMQ ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ulong> Permute4x64(Vector256<ulong> value, byte control) => Permute4x64(value, control);
- /// <summary>
- /// __m256d _mm256_permute4x64_pd (__m256d a, const int imm8)
- /// VPERMPD ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<double> Permute4x64(Vector256<double> value, byte control) => Permute4x64(value, control);
-
- /// <summary>
- /// __m256i _mm256_permutevar8x32_epi32 (__m256i a, __m256i idx)
- /// VPERMD ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<int> PermuteVar8x32(Vector256<int> left, Vector256<int> control) => PermuteVar8x32(left, control);
- /// <summary>
- /// __m256i _mm256_permutevar8x32_epi32 (__m256i a, __m256i idx)
- /// VPERMD ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<uint> PermuteVar8x32(Vector256<uint> left, Vector256<uint> control) => PermuteVar8x32(left, control);
- /// <summary>
- /// __m256 _mm256_permutevar8x32_ps (__m256 a, __m256i idx)
- /// VPERMPS ymm, ymm/m256, ymm
- /// </summary>
- public static Vector256<float> PermuteVar8x32(Vector256<float> left, Vector256<int> control) => PermuteVar8x32(left, control);
-
- /// <summary>
- /// __m256i _mm256_sll_epi16 (__m256i a, __m128i count)
- /// VPSLLW ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<short> ShiftLeftLogical(Vector256<short> value, Vector128<short> count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m256i _mm256_sll_epi16 (__m256i a, __m128i count)
- /// VPSLLW ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<ushort> ShiftLeftLogical(Vector256<ushort> value, Vector128<ushort> count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m256i _mm256_sll_epi32 (__m256i a, __m128i count)
- /// VPSLLD ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<int> ShiftLeftLogical(Vector256<int> value, Vector128<int> count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m256i _mm256_sll_epi32 (__m256i a, __m128i count)
- /// VPSLLD ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<uint> ShiftLeftLogical(Vector256<uint> value, Vector128<uint> count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m256i _mm256_sll_epi64 (__m256i a, __m128i count)
- /// VPSLLQ ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<long> ShiftLeftLogical(Vector256<long> value, Vector128<long> count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m256i _mm256_sll_epi64 (__m256i a, __m128i count)
- /// VPSLLQ ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<ulong> ShiftLeftLogical(Vector256<ulong> value, Vector128<ulong> count) => ShiftLeftLogical(value, count);
-
- /// <summary>
- /// __m256i _mm256_slli_epi16 (__m256i a, int imm8)
- /// VPSLLW ymm, ymm, imm8
- /// </summary>
- public static Vector256<short> ShiftLeftLogical(Vector256<short> value, byte count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m256i _mm256_slli_epi16 (__m256i a, int imm8)
- /// VPSLLW ymm, ymm, imm8
- /// </summary>
- public static Vector256<ushort> ShiftLeftLogical(Vector256<ushort> value, byte count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m256i _mm256_slli_epi32 (__m256i a, int imm8)
- /// VPSLLD ymm, ymm, imm8
- /// </summary>
- public static Vector256<int> ShiftLeftLogical(Vector256<int> value, byte count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m256i _mm256_slli_epi32 (__m256i a, int imm8)
- /// VPSLLD ymm, ymm, imm8
- /// </summary>
- public static Vector256<uint> ShiftLeftLogical(Vector256<uint> value, byte count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m256i _mm256_slli_epi64 (__m256i a, int imm8)
- /// VPSLLQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<long> ShiftLeftLogical(Vector256<long> value, byte count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m256i _mm256_slli_epi64 (__m256i a, int imm8)
- /// VPSLLQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ulong> ShiftLeftLogical(Vector256<ulong> value, byte count) => ShiftLeftLogical(value, count);
-
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<sbyte> ShiftLeftLogical128BitLane(Vector256<sbyte> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<byte> ShiftLeftLogical128BitLane(Vector256<byte> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<short> ShiftLeftLogical128BitLane(Vector256<short> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ushort> ShiftLeftLogical128BitLane(Vector256<ushort> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<int> ShiftLeftLogical128BitLane(Vector256<int> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<uint> ShiftLeftLogical128BitLane(Vector256<uint> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<long> ShiftLeftLogical128BitLane(Vector256<long> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bslli_epi128 (__m256i a, const int imm8)
- /// VPSLLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ulong> ShiftLeftLogical128BitLane(Vector256<ulong> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
-
- /// <summary>
- /// __m256i _mm256_sllv_epi32 (__m256i a, __m256i count)
- /// VPSLLVD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> ShiftLeftLogicalVariable(Vector256<int> value, Vector256<uint> count) => ShiftLeftLogicalVariable(value, count);
- /// <summary>
- /// __m256i _mm256_sllv_epi32 (__m256i a, __m256i count)
- /// VPSLLVD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> ShiftLeftLogicalVariable(Vector256<uint> value, Vector256<uint> count) => ShiftLeftLogicalVariable(value, count);
- /// <summary>
- /// __m256i _mm256_sllv_epi64 (__m256i a, __m256i count)
- /// VPSLLVQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> ShiftLeftLogicalVariable(Vector256<long> value, Vector256<ulong> count) => ShiftLeftLogicalVariable(value, count);
- /// <summary>
- /// __m256i _mm256_sllv_epi64 (__m256i a, __m256i count)
- /// VPSLLVQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> ShiftLeftLogicalVariable(Vector256<ulong> value, Vector256<ulong> count) => ShiftLeftLogicalVariable(value, count);
-
- /// <summary>
- /// __m128i _mm_sllv_epi32 (__m128i a, __m128i count)
- /// VPSLLVD xmm, ymm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftLeftLogicalVariable(Vector128<int> value, Vector128<uint> count) => ShiftLeftLogicalVariable(value, count);
- /// <summary>
- /// __m128i _mm_sllv_epi32 (__m128i a, __m128i count)
- /// VPSLLVD xmm, ymm, xmm/m128
- /// </summary>
- public static Vector128<uint> ShiftLeftLogicalVariable(Vector128<uint> value, Vector128<uint> count) => ShiftLeftLogicalVariable(value, count);
- /// <summary>
- /// __m128i _mm_sllv_epi64 (__m128i a, __m128i count)
- /// VPSLLVQ xmm, ymm, xmm/m128
- /// </summary>
- public static Vector128<long> ShiftLeftLogicalVariable(Vector128<long> value, Vector128<ulong> count) => ShiftLeftLogicalVariable(value, count);
- /// <summary>
- /// __m128i _mm_sllv_epi64 (__m128i a, __m128i count)
- /// VPSLLVQ xmm, ymm, xmm/m128
- /// </summary>
- public static Vector128<ulong> ShiftLeftLogicalVariable(Vector128<ulong> value, Vector128<ulong> count) => ShiftLeftLogicalVariable(value, count);
-
- /// <summary>
- /// _mm256_sra_epi16 (__m256i a, __m128i count)
- /// VPSRAW ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<short> ShiftRightArithmetic(Vector256<short> value, Vector128<short> count) => ShiftRightArithmetic(value, count);
- /// <summary>
- /// _mm256_sra_epi32 (__m256i a, __m128i count)
- /// VPSRAD ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<int> ShiftRightArithmetic(Vector256<int> value, Vector128<int> count) => ShiftRightArithmetic(value, count);
-
- /// <summary>
- /// __m256i _mm256_srai_epi16 (__m256i a, int imm8)
- /// VPSRAW ymm, ymm, imm8
- /// </summary>
- public static Vector256<short> ShiftRightArithmetic(Vector256<short> value, byte count) => ShiftRightArithmetic(value, count);
- /// <summary>
- /// __m256i _mm256_srai_epi32 (__m256i a, int imm8)
- /// VPSRAD ymm, ymm, imm8
- /// </summary>
- public static Vector256<int> ShiftRightArithmetic(Vector256<int> value, byte count) => ShiftRightArithmetic(value, count);
-
- /// <summary>
- /// __m256i _mm256_srav_epi32 (__m256i a, __m256i count)
- /// VPSRAVD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> ShiftRightArithmeticVariable(Vector256<int> value, Vector256<uint> count) => ShiftRightArithmeticVariable(value, count);
-
- /// <summary>
- /// __m128i _mm_srav_epi32 (__m128i a, __m128i count)
- /// VPSRAVD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftRightArithmeticVariable(Vector128<int> value, Vector128<uint> count) => ShiftRightArithmeticVariable(value, count);
-
- /// <summary>
- /// __m256i _mm256_srl_epi16 (__m256i a, __m128i count)
- /// VPSRLW ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<short> ShiftRightLogical(Vector256<short> value, Vector128<short> count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m256i _mm256_srl_epi16 (__m256i a, __m128i count)
- /// VPSRLW ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<ushort> ShiftRightLogical(Vector256<ushort> value, Vector128<ushort> count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m256i _mm256_srl_epi32 (__m256i a, __m128i count)
- /// VPSRLD ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<int> ShiftRightLogical(Vector256<int> value, Vector128<int> count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m256i _mm256_srl_epi32 (__m256i a, __m128i count)
- /// VPSRLD ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<uint> ShiftRightLogical(Vector256<uint> value, Vector128<uint> count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m256i _mm256_srl_epi64 (__m256i a, __m128i count)
- /// VPSRLQ ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<long> ShiftRightLogical(Vector256<long> value, Vector128<long> count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m256i _mm256_srl_epi64 (__m256i a, __m128i count)
- /// VPSRLQ ymm, ymm, xmm/m128
- /// </summary>
- public static Vector256<ulong> ShiftRightLogical(Vector256<ulong> value, Vector128<ulong> count) => ShiftRightLogical(value, count);
-
- /// <summary>
- /// __m256i _mm256_srli_epi16 (__m256i a, int imm8)
- /// VPSRLW ymm, ymm, imm8
- /// </summary>
- public static Vector256<short> ShiftRightLogical(Vector256<short> value, byte count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m256i _mm256_srli_epi16 (__m256i a, int imm8)
- /// VPSRLW ymm, ymm, imm8
- /// </summary>
- public static Vector256<ushort> ShiftRightLogical(Vector256<ushort> value, byte count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m256i _mm256_srli_epi32 (__m256i a, int imm8)
- /// VPSRLD ymm, ymm, imm8
- /// </summary>
- public static Vector256<int> ShiftRightLogical(Vector256<int> value, byte count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m256i _mm256_srli_epi32 (__m256i a, int imm8)
- /// VPSRLD ymm, ymm, imm8
- /// </summary>
- public static Vector256<uint> ShiftRightLogical(Vector256<uint> value, byte count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m256i _mm256_srli_epi64 (__m256i a, int imm8)
- /// VPSRLQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<long> ShiftRightLogical(Vector256<long> value, byte count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m256i _mm256_srli_epi64 (__m256i a, int imm8)
- /// VPSRLQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ulong> ShiftRightLogical(Vector256<ulong> value, byte count) => ShiftRightLogical(value, count);
-
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<sbyte> ShiftRightLogical128BitLane(Vector256<sbyte> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<byte> ShiftRightLogical128BitLane(Vector256<byte> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<short> ShiftRightLogical128BitLane(Vector256<short> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ushort> ShiftRightLogical128BitLane(Vector256<ushort> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<int> ShiftRightLogical128BitLane(Vector256<int> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<uint> ShiftRightLogical128BitLane(Vector256<uint> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<long> ShiftRightLogical128BitLane(Vector256<long> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m256i _mm256_bsrli_epi128 (__m256i a, const int imm8)
- /// VPSRLDQ ymm, ymm, imm8
- /// </summary>
- public static Vector256<ulong> ShiftRightLogical128BitLane(Vector256<ulong> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
-
- /// <summary>
- /// __m256i _mm256_srlv_epi32 (__m256i a, __m256i count)
- /// VPSRLVD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> ShiftRightLogicalVariable(Vector256<int> value, Vector256<uint> count) => ShiftRightLogicalVariable(value, count);
- /// <summary>
- /// __m256i _mm256_srlv_epi32 (__m256i a, __m256i count)
- /// VPSRLVD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> ShiftRightLogicalVariable(Vector256<uint> value, Vector256<uint> count) => ShiftRightLogicalVariable(value, count);
- /// <summary>
- /// __m256i _mm256_srlv_epi64 (__m256i a, __m256i count)
- /// VPSRLVQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> ShiftRightLogicalVariable(Vector256<long> value, Vector256<ulong> count) => ShiftRightLogicalVariable(value, count);
- /// <summary>
- /// __m256i _mm256_srlv_epi64 (__m256i a, __m256i count)
- /// VPSRLVQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> ShiftRightLogicalVariable(Vector256<ulong> value, Vector256<ulong> count) => ShiftRightLogicalVariable(value, count);
-
- /// <summary>
- /// __m128i _mm_srlv_epi32 (__m128i a, __m128i count)
- /// VPSRLVD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftRightLogicalVariable(Vector128<int> value, Vector128<uint> count) => ShiftRightLogicalVariable(value, count);
- /// <summary>
- /// __m128i _mm_srlv_epi32 (__m128i a, __m128i count)
- /// VPSRLVD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> ShiftRightLogicalVariable(Vector128<uint> value, Vector128<uint> count) => ShiftRightLogicalVariable(value, count);
- /// <summary>
- /// __m128i _mm_srlv_epi64 (__m128i a, __m128i count)
- /// VPSRLVQ xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<long> ShiftRightLogicalVariable(Vector128<long> value, Vector128<ulong> count) => ShiftRightLogicalVariable(value, count);
- /// <summary>
- /// __m128i _mm_srlv_epi64 (__m128i a, __m128i count)
- /// VPSRLVQ xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> ShiftRightLogicalVariable(Vector128<ulong> value, Vector128<ulong> count) => ShiftRightLogicalVariable(value, count);
-
- /// <summary>
- /// __m256i _mm256_shuffle_epi8 (__m256i a, __m256i b)
- /// VPSHUFB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Shuffle(Vector256<sbyte> value, Vector256<sbyte> mask) => Shuffle(value, mask);
- /// <summary>
- /// __m256i _mm256_shuffle_epi8 (__m256i a, __m256i b)
- /// VPSHUFB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Shuffle(Vector256<byte> value, Vector256<byte> mask) => Shuffle(value, mask);
- /// <summary>
- /// __m256i _mm256_shuffle_epi32 (__m256i a, const int imm8)
- /// VPSHUFD ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<int> Shuffle(Vector256<int> value, byte control) => Shuffle(value, control);
- /// <summary>
- /// __m256i _mm256_shuffle_epi32 (__m256i a, const int imm8)
- /// VPSHUFD ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<uint> Shuffle(Vector256<uint> value, byte control) => Shuffle(value, control);
-
- /// <summary>
- /// __m256i _mm256_shufflehi_epi16 (__m256i a, const int imm8)
- /// VPSHUFHW ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<short> ShuffleHigh(Vector256<short> value, byte control) => ShuffleHigh(value, control);
- /// <summary>
- /// __m256i _mm256_shufflehi_epi16 (__m256i a, const int imm8)
- /// VPSHUFHW ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ushort> ShuffleHigh(Vector256<ushort> value, byte control) => ShuffleHigh(value, control);
-
- /// <summary>
- /// __m256i _mm256_shufflelo_epi16 (__m256i a, const int imm8)
- /// VPSHUFLW ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<short> ShuffleLow(Vector256<short> value, byte control) => ShuffleLow(value, control);
- /// <summary>
- /// __m256i _mm256_shufflelo_epi16 (__m256i a, const int imm8)
- /// VPSHUFLW ymm, ymm/m256, imm8
- /// </summary>
- public static Vector256<ushort> ShuffleLow(Vector256<ushort> value, byte control) => ShuffleLow(value, control);
-
- /// <summary>
- /// __m256i _mm256_sign_epi8 (__m256i a, __m256i b)
- /// VPSIGNB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Sign(Vector256<sbyte> left, Vector256<sbyte> right) => Sign(left, right);
- /// <summary>
- /// __m256i _mm256_sign_epi16 (__m256i a, __m256i b)
- /// VPSIGNW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Sign(Vector256<short> left, Vector256<short> right) => Sign(left, right);
- /// <summary>
- /// __m256i _mm256_sign_epi32 (__m256i a, __m256i b)
- /// VPSIGND ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Sign(Vector256<int> left, Vector256<int> right) => Sign(left, right);
-
- /// <summary>
- /// __m256i _mm256_sub_epi8 (__m256i a, __m256i b)
- /// VPSUBB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Subtract(Vector256<sbyte> left, Vector256<sbyte> right) => Subtract(left, right);
- /// <summary>
- /// __m256i _mm256_sub_epi8 (__m256i a, __m256i b)
- /// VPSUBB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Subtract(Vector256<byte> left, Vector256<byte> right) => Subtract(left, right);
- /// <summary>
- /// __m256i _mm256_sub_epi16 (__m256i a, __m256i b)
- /// VPSUBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Subtract(Vector256<short> left, Vector256<short> right) => Subtract(left, right);
- /// <summary>
- /// __m256i _mm256_sub_epi16 (__m256i a, __m256i b)
- /// VPSUBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Subtract(Vector256<ushort> left, Vector256<ushort> right) => Subtract(left, right);
- /// <summary>
- /// __m256i _mm256_sub_epi32 (__m256i a, __m256i b)
- /// VPSUBD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Subtract(Vector256<int> left, Vector256<int> right) => Subtract(left, right);
- /// <summary>
- /// __m256i _mm256_sub_epi32 (__m256i a, __m256i b)
- /// VPSUBD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Subtract(Vector256<uint> left, Vector256<uint> right) => Subtract(left, right);
- /// <summary>
- /// __m256i _mm256_sub_epi64 (__m256i a, __m256i b)
- /// VPSUBQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> Subtract(Vector256<long> left, Vector256<long> right) => Subtract(left, right);
- /// <summary>
- /// __m256i _mm256_sub_epi64 (__m256i a, __m256i b)
- /// VPSUBQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> Subtract(Vector256<ulong> left, Vector256<ulong> right) => Subtract(left, right);
-
- /// <summary>
- /// __m256i _mm256_subs_epi8 (__m256i a, __m256i b)
- /// VPSUBSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> SubtractSaturate(Vector256<sbyte> left, Vector256<sbyte> right) => SubtractSaturate(left, right);
- /// <summary>
- /// __m256i _mm256_subs_epi16 (__m256i a, __m256i b)
- /// VPSUBSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> SubtractSaturate(Vector256<short> left, Vector256<short> right) => SubtractSaturate(left, right);
- /// <summary>
- /// __m256i _mm256_subs_epu8 (__m256i a, __m256i b)
- /// VPSUBUSB ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> SubtractSaturate(Vector256<byte> left, Vector256<byte> right) => SubtractSaturate(left, right);
- /// <summary>
- /// __m256i _mm256_subs_epu16 (__m256i a, __m256i b)
- /// VPSUBUSW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> SubtractSaturate(Vector256<ushort> left, Vector256<ushort> right) => SubtractSaturate(left, right);
-
- /// <summary>
- /// __m256i _mm256_sad_epu8 (__m256i a, __m256i b)
- /// VPSADBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> SumAbsoluteDifferences(Vector256<byte> left, Vector256<byte> right) => SumAbsoluteDifferences(left, right);
-
- /// <summary>
- /// __m256i _mm256_unpackhi_epi8 (__m256i a, __m256i b)
- /// VPUNPCKHBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> UnpackHigh(Vector256<sbyte> left, Vector256<sbyte> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m256i _mm256_unpackhi_epi8 (__m256i a, __m256i b)
- /// VPUNPCKHBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> UnpackHigh(Vector256<byte> left, Vector256<byte> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m256i _mm256_unpackhi_epi16 (__m256i a, __m256i b)
- /// VPUNPCKHWD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> UnpackHigh(Vector256<short> left, Vector256<short> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m256i _mm256_unpackhi_epi16 (__m256i a, __m256i b)
- /// VPUNPCKHWD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> UnpackHigh(Vector256<ushort> left, Vector256<ushort> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m256i _mm256_unpackhi_epi32 (__m256i a, __m256i b)
- /// VPUNPCKHDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> UnpackHigh(Vector256<int> left, Vector256<int> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m256i _mm256_unpackhi_epi32 (__m256i a, __m256i b)
- /// VPUNPCKHDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> UnpackHigh(Vector256<uint> left, Vector256<uint> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m256i _mm256_unpackhi_epi64 (__m256i a, __m256i b)
- /// VPUNPCKHQDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> UnpackHigh(Vector256<long> left, Vector256<long> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m256i _mm256_unpackhi_epi64 (__m256i a, __m256i b)
- /// VPUNPCKHQDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> UnpackHigh(Vector256<ulong> left, Vector256<ulong> right) => UnpackHigh(left, right);
-
- /// <summary>
- /// __m256i _mm256_unpacklo_epi8 (__m256i a, __m256i b)
- /// VPUNPCKLBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> UnpackLow(Vector256<sbyte> left, Vector256<sbyte> right) => UnpackLow(left, right);
- /// <summary>
- /// __m256i _mm256_unpacklo_epi8 (__m256i a, __m256i b)
- /// VPUNPCKLBW ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> UnpackLow(Vector256<byte> left, Vector256<byte> right) => UnpackLow(left, right);
- /// <summary>
- /// __m256i _mm256_unpacklo_epi16 (__m256i a, __m256i b)
- /// VPUNPCKLWD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> UnpackLow(Vector256<short> left, Vector256<short> right) => UnpackLow(left, right);
- /// <summary>
- /// __m256i _mm256_unpacklo_epi16 (__m256i a, __m256i b)
- /// VPUNPCKLWD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> UnpackLow(Vector256<ushort> left, Vector256<ushort> right) => UnpackLow(left, right);
- /// <summary>
- /// __m256i _mm256_unpacklo_epi32 (__m256i a, __m256i b)
- /// VPUNPCKLDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> UnpackLow(Vector256<int> left, Vector256<int> right) => UnpackLow(left, right);
- /// <summary>
- /// __m256i _mm256_unpacklo_epi32 (__m256i a, __m256i b)
- /// VPUNPCKLDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> UnpackLow(Vector256<uint> left, Vector256<uint> right) => UnpackLow(left, right);
- /// <summary>
- /// __m256i _mm256_unpacklo_epi64 (__m256i a, __m256i b)
- /// VPUNPCKLQDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> UnpackLow(Vector256<long> left, Vector256<long> right) => UnpackLow(left, right);
- /// <summary>
- /// __m256i _mm256_unpacklo_epi64 (__m256i a, __m256i b)
- /// VPUNPCKLQDQ ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> UnpackLow(Vector256<ulong> left, Vector256<ulong> right) => UnpackLow(left, right);
-
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<sbyte> Xor(Vector256<sbyte> left, Vector256<sbyte> right) => Xor(left, right);
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<byte> Xor(Vector256<byte> left, Vector256<byte> right) => Xor(left, right);
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<short> Xor(Vector256<short> left, Vector256<short> right) => Xor(left, right);
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ushort> Xor(Vector256<ushort> left, Vector256<ushort> right) => Xor(left, right);
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<int> Xor(Vector256<int> left, Vector256<int> right) => Xor(left, right);
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<uint> Xor(Vector256<uint> left, Vector256<uint> right) => Xor(left, right);
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<long> Xor(Vector256<long> left, Vector256<long> right) => Xor(left, right);
- /// <summary>
- /// __m256i _mm256_xor_si256 (__m256i a, __m256i b)
- /// VPXOR ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<ulong> Xor(Vector256<ulong> left, Vector256<ulong> right) => Xor(left, right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi1.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi1.PlatformNotSupported.cs
deleted file mode 100644
index 204932af229..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi1.PlatformNotSupported.cs
+++ /dev/null
@@ -1,119 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel BMI1 hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Bmi1
- {
- internal Bmi1() { }
-
- public static bool IsSupported { [Intrinsic] get { return false; } }
-
- public abstract class X64
- {
- internal X64() { }
-
- public static bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// unsigned __int64 _andn_u64 (unsigned __int64 a, unsigned __int64 b)
- /// ANDN r64a, r64b, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong AndNot(ulong left, ulong right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned __int64 _bextr_u64 (unsigned __int64 a, unsigned int start, unsigned int len)
- /// BEXTR r64a, reg/m64, r64b
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong BitFieldExtract(ulong value, byte start, byte length) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned __int64 _bextr2_u64 (unsigned __int64 a, unsigned __int64 control)
- /// BEXTR r64a, reg/m64, r64b
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong BitFieldExtract(ulong value, ushort control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned __int64 _blsi_u64 (unsigned __int64 a)
- /// BLSI reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ExtractLowestSetBit(ulong value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned __int64 _blsmsk_u64 (unsigned __int64 a)
- /// BLSMSK reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong GetMaskUpToLowestSetBit(ulong value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned __int64 _blsr_u64 (unsigned __int64 a)
- /// BLSR reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ResetLowestSetBit(ulong value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __int64 _mm_tzcnt_64 (unsigned __int64 a)
- /// TZCNT reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong TrailingZeroCount(ulong value) { throw new PlatformNotSupportedException(); }
- }
-
- /// <summary>
- /// unsigned int _andn_u32 (unsigned int a, unsigned int b)
- /// ANDN r32a, r32b, reg/m32
- /// </summary>
- public static uint AndNot(uint left, uint right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned int _bextr_u32 (unsigned int a, unsigned int start, unsigned int len)
- /// BEXTR r32a, reg/m32, r32b
- /// </summary>
- public static uint BitFieldExtract(uint value, byte start, byte length) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned int _bextr2_u32 (unsigned int a, unsigned int control)
- /// BEXTR r32a, reg/m32, r32b
- /// </summary>
- public static uint BitFieldExtract(uint value, ushort control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned int _blsi_u32 (unsigned int a)
- /// BLSI reg, reg/m32
- /// </summary>
- public static uint ExtractLowestSetBit(uint value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned int _blsmsk_u32 (unsigned int a)
- /// BLSMSK reg, reg/m32
- /// </summary>
- public static uint GetMaskUpToLowestSetBit(uint value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned int _blsr_u32 (unsigned int a)
- /// BLSR reg, reg/m32
- /// </summary>
- public static uint ResetLowestSetBit(uint value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_tzcnt_32 (unsigned int a)
- /// TZCNT reg, reg/m32
- /// </summary>
- public static uint TrailingZeroCount(uint value) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi1.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi1.cs
deleted file mode 100644
index 32e72af9ebe..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi1.cs
+++ /dev/null
@@ -1,119 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel BMI1 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Bmi1
- {
- internal Bmi1() { }
-
- public static bool IsSupported { get => IsSupported; }
-
- [Intrinsic]
- public abstract class X64
- {
- internal X64() { }
-
- public static bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// unsigned __int64 _andn_u64 (unsigned __int64 a, unsigned __int64 b)
- /// ANDN r64a, r64b, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong AndNot(ulong left, ulong right) => AndNot(left, right);
-
- /// <summary>
- /// unsigned __int64 _bextr_u64 (unsigned __int64 a, unsigned int start, unsigned int len)
- /// BEXTR r64a, reg/m64, r64b
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong BitFieldExtract(ulong value, byte start, byte length) => BitFieldExtract(value, (ushort)(start | (length << 8)));
-
- /// <summary>
- /// unsigned __int64 _bextr2_u64 (unsigned __int64 a, unsigned __int64 control)
- /// BEXTR r64a, reg/m64, r64b
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong BitFieldExtract(ulong value, ushort control) => BitFieldExtract(value, control);
-
- /// <summary>
- /// unsigned __int64 _blsi_u64 (unsigned __int64 a)
- /// BLSI reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ExtractLowestSetBit(ulong value) => ExtractLowestSetBit(value);
-
- /// <summary>
- /// unsigned __int64 _blsmsk_u64 (unsigned __int64 a)
- /// BLSMSK reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong GetMaskUpToLowestSetBit(ulong value) => GetMaskUpToLowestSetBit(value);
-
- /// <summary>
- /// unsigned __int64 _blsr_u64 (unsigned __int64 a)
- /// BLSR reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ResetLowestSetBit(ulong value) => ResetLowestSetBit(value);
-
- /// <summary>
- /// __int64 _mm_tzcnt_64 (unsigned __int64 a)
- /// TZCNT reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong TrailingZeroCount(ulong value) => TrailingZeroCount(value);
- }
-
- /// <summary>
- /// unsigned int _andn_u32 (unsigned int a, unsigned int b)
- /// ANDN r32a, r32b, reg/m32
- /// </summary>
- public static uint AndNot(uint left, uint right) => AndNot(left, right);
-
- /// <summary>
- /// unsigned int _bextr_u32 (unsigned int a, unsigned int start, unsigned int len)
- /// BEXTR r32a, reg/m32, r32b
- /// </summary>
- public static uint BitFieldExtract(uint value, byte start, byte length) => BitFieldExtract(value, (ushort)(start | (length << 8)));
-
- /// <summary>
- /// unsigned int _bextr2_u32 (unsigned int a, unsigned int control)
- /// BEXTR r32a, reg/m32, r32b
- /// </summary>
- public static uint BitFieldExtract(uint value, ushort control) => BitFieldExtract(value, control);
-
- /// <summary>
- /// unsigned int _blsi_u32 (unsigned int a)
- /// BLSI reg, reg/m32
- /// </summary>
- public static uint ExtractLowestSetBit(uint value) => ExtractLowestSetBit(value);
-
- /// <summary>
- /// unsigned int _blsmsk_u32 (unsigned int a)
- /// BLSMSK reg, reg/m32
- /// </summary>
- public static uint GetMaskUpToLowestSetBit(uint value) => GetMaskUpToLowestSetBit(value);
-
- /// <summary>
- /// unsigned int _blsr_u32 (unsigned int a)
- /// BLSR reg, reg/m32
- /// </summary>
- public static uint ResetLowestSetBit(uint value) => ResetLowestSetBit(value);
-
- /// <summary>
- /// int _mm_tzcnt_32 (unsigned int a)
- /// TZCNT reg, reg/m32
- /// </summary>
- public static uint TrailingZeroCount(uint value) => TrailingZeroCount(value);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi2.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi2.PlatformNotSupported.cs
deleted file mode 100644
index 053ea708425..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi2.PlatformNotSupported.cs
+++ /dev/null
@@ -1,97 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel BMI2 hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Bmi2
- {
- internal Bmi2() { }
-
- public static bool IsSupported { [Intrinsic] get { return false; } }
-
- public abstract class X64
- {
- internal X64() { }
-
- public static bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// unsigned __int64 _bzhi_u64 (unsigned __int64 a, unsigned int index)
- /// BZHI r64a, reg/m32, r64b
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ZeroHighBits(ulong value, ulong index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned __int64 _mulx_u64 (unsigned __int64 a, unsigned __int64 b, unsigned __int64* hi)
- /// MULX r64a, r64b, reg/m64
- /// The above native signature does not directly correspond to the managed signature.
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong MultiplyNoFlags(ulong left, ulong right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned __int64 _mulx_u64 (unsigned __int64 a, unsigned __int64 b, unsigned __int64* hi)
- /// MULX r64a, r64b, reg/m64
- /// The above native signature does not directly correspond to the managed signature.
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static unsafe ulong MultiplyNoFlags(ulong left, ulong right, ulong* low) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned __int64 _pdep_u64 (unsigned __int64 a, unsigned __int64 mask)
- /// PDEP r64a, r64b, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ParallelBitDeposit(ulong value, ulong mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned __int64 _pext_u64 (unsigned __int64 a, unsigned __int64 mask)
- /// PEXT r64a, r64b, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ParallelBitExtract(ulong value, ulong mask) { throw new PlatformNotSupportedException(); }
- }
-
- /// <summary>
- /// unsigned int _bzhi_u32 (unsigned int a, unsigned int index)
- /// BZHI r32a, reg/m32, r32b
- /// </summary>
- public static uint ZeroHighBits(uint value, uint index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned int _mulx_u32 (unsigned int a, unsigned int b, unsigned int* hi)
- /// MULX r32a, r32b, reg/m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static uint MultiplyNoFlags(uint left, uint right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned int _mulx_u32 (unsigned int a, unsigned int b, unsigned int* hi)
- /// MULX r32a, r32b, reg/m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe uint MultiplyNoFlags(uint left, uint right, uint* low) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned int _pdep_u32 (unsigned int a, unsigned int mask)
- /// PDEP r32a, r32b, reg/m32
- /// </summary>
- public static uint ParallelBitDeposit(uint value, uint mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned int _pext_u32 (unsigned int a, unsigned int mask)
- /// PEXT r32a, r32b, reg/m32
- /// </summary>
- public static uint ParallelBitExtract(uint value, uint mask) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi2.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi2.cs
deleted file mode 100644
index 3c692e19bfc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Bmi2.cs
+++ /dev/null
@@ -1,97 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel BMI2 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Bmi2
- {
- internal Bmi2() { }
-
- public static bool IsSupported { get => IsSupported; }
-
- [Intrinsic]
- public abstract class X64
- {
- internal X64() { }
-
- public static bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// unsigned __int64 _bzhi_u64 (unsigned __int64 a, unsigned int index)
- /// BZHI r64a, reg/m32, r64b
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ZeroHighBits(ulong value, ulong index) => ZeroHighBits(value, index);
-
- /// <summary>
- /// unsigned __int64 _mulx_u64 (unsigned __int64 a, unsigned __int64 b, unsigned __int64* hi)
- /// MULX r64a, r64b, reg/m64
- /// The above native signature does not directly correspond to the managed signature.
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong MultiplyNoFlags(ulong left, ulong right) => MultiplyNoFlags(left, right);
-
- /// <summary>
- /// unsigned __int64 _mulx_u64 (unsigned __int64 a, unsigned __int64 b, unsigned __int64* hi)
- /// MULX r64a, r64b, reg/m64
- /// The above native signature does not directly correspond to the managed signature.
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static unsafe ulong MultiplyNoFlags(ulong left, ulong right, ulong* low) => MultiplyNoFlags(left, right, low);
-
- /// <summary>
- /// unsigned __int64 _pdep_u64 (unsigned __int64 a, unsigned __int64 mask)
- /// PDEP r64a, r64b, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ParallelBitDeposit(ulong value, ulong mask) => ParallelBitDeposit(value, mask);
-
- /// <summary>
- /// unsigned __int64 _pext_u64 (unsigned __int64 a, unsigned __int64 mask)
- /// PEXT r64a, r64b, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ParallelBitExtract(ulong value, ulong mask) => ParallelBitExtract(value, mask);
- }
-
- /// <summary>
- /// unsigned int _bzhi_u32 (unsigned int a, unsigned int index)
- /// BZHI r32a, reg/m32, r32b
- /// </summary>
- public static uint ZeroHighBits(uint value, uint index) => ZeroHighBits(value, index);
-
- /// <summary>
- /// unsigned int _mulx_u32 (unsigned int a, unsigned int b, unsigned int* hi)
- /// MULX r32a, r32b, reg/m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static uint MultiplyNoFlags(uint left, uint right) => MultiplyNoFlags(left, right);
-
- /// <summary>
- /// unsigned int _mulx_u32 (unsigned int a, unsigned int b, unsigned int* hi)
- /// MULX r32a, r32b, reg/m32
- /// The above native signature does not directly correspond to the managed signature.
- /// </summary>
- public static unsafe uint MultiplyNoFlags(uint left, uint right, uint* low) => MultiplyNoFlags(left, right, low);
-
- /// <summary>
- /// unsigned int _pdep_u32 (unsigned int a, unsigned int mask)
- /// PDEP r32a, r32b, reg/m32
- /// </summary>
- public static uint ParallelBitDeposit(uint value, uint mask) => ParallelBitDeposit(value, mask);
-
- /// <summary>
- /// unsigned int _pext_u32 (unsigned int a, unsigned int mask)
- /// PEXT r32a, r32b, reg/m32
- /// </summary>
- public static uint ParallelBitExtract(uint value, uint mask) => ParallelBitExtract(value, mask);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Enums.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Enums.cs
deleted file mode 100644
index 7098f813ff7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Enums.cs
+++ /dev/null
@@ -1,169 +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.
-
-namespace System.Runtime.Intrinsics.X86
-{
- public enum FloatComparisonMode : byte
- {
- /// <summary>
- /// _CMP_EQ_OQ
- /// </summary>
- OrderedEqualNonSignaling = 0,
-
- /// <summary>
- /// _CMP_LT_OS
- /// </summary>
- OrderedLessThanSignaling = 1,
-
- /// <summary>
- /// _CMP_LE_OS
- /// </summary>
- OrderedLessThanOrEqualSignaling = 2,
-
- /// <summary>
- /// _CMP_UNORD_Q
- /// </summary>
- UnorderedNonSignaling = 3,
-
- /// <summary>
- /// _CMP_NEQ_UQ
- /// </summary>
- UnorderedNotEqualNonSignaling = 4,
-
- /// <summary>
- /// _CMP_NLT_US
- /// </summary>
- UnorderedNotLessThanSignaling = 5,
-
- /// <summary>
- /// _CMP_NLE_US
- /// </summary>
- UnorderedNotLessThanOrEqualSignaling = 6,
-
- /// <summary>
- /// _CMP_ORD_Q
- /// </summary>
- OrderedNonSignaling = 7,
-
- /// <summary>
- /// _CMP_EQ_UQ
- /// </summary>
- UnorderedEqualNonSignaling = 8,
-
- /// <summary>
- /// _CMP_NGE_US
- /// </summary>
- UnorderedNotGreaterThanOrEqualSignaling = 9,
-
- /// <summary>
- /// _CMP_NGT_US
- /// </summary>
- UnorderedNotGreaterThanSignaling = 10,
-
- /// <summary>
- /// _CMP_FALSE_OQ
- /// </summary>
- OrderedFalseNonSignaling = 11,
-
- /// <summary>
- /// _CMP_NEQ_OQ
- /// </summary>
- OrderedNotEqualNonSignaling = 12,
-
- /// <summary>
- /// _CMP_GE_OS
- /// </summary>
- OrderedGreaterThanOrEqualSignaling = 13,
-
- /// <summary>
- /// _CMP_GT_OS
- /// </summary>
- OrderedGreaterThanSignaling = 14,
-
- /// <summary>
- /// _CMP_TRUE_UQ
- /// </summary>
- UnorderedTrueNonSignaling = 15,
-
- /// <summary>
- /// _CMP_EQ_OS
- /// </summary>
- OrderedEqualSignaling = 16,
-
- /// <summary>
- /// _CMP_LT_OQ
- /// </summary>
- OrderedLessThanNonSignaling = 17,
-
- /// <summary>
- /// _CMP_LE_OQ
- /// </summary>
- OrderedLessThanOrEqualNonSignaling = 18,
-
- /// <summary>
- /// _CMP_UNORD_S
- /// </summary>
- UnorderedSignaling = 19,
-
- /// <summary>
- /// _CMP_NEQ_US
- /// </summary>
- UnorderedNotEqualSignaling = 20,
-
- /// <summary>
- /// _CMP_NLT_UQ
- /// </summary>
- UnorderedNotLessThanNonSignaling = 21,
-
- /// <summary>
- /// _CMP_NLE_UQ
- /// </summary>
- UnorderedNotLessThanOrEqualNonSignaling = 22,
-
- /// <summary>
- /// _CMP_ORD_S
- /// </summary>
- OrderedSignaling = 23,
-
- /// <summary>
- /// _CMP_EQ_US
- /// </summary>
- UnorderedEqualSignaling = 24,
-
- /// <summary>
- /// _CMP_NGE_UQ
- /// </summary>
- UnorderedNotGreaterThanOrEqualNonSignaling = 25,
-
- /// <summary>
- /// _CMP_NGT_UQ
- /// </summary>
- UnorderedNotGreaterThanNonSignaling = 26,
-
- /// <summary>
- /// _CMP_FALSE_OS
- /// </summary>
- OrderedFalseSignaling = 27,
-
- /// <summary>
- /// _CMP_NEQ_OS
- /// </summary>
- OrderedNotEqualSignaling = 28,
-
- /// <summary>
- /// _CMP_GE_OQ
- /// </summary>
- OrderedGreaterThanOrEqualNonSignaling = 29,
-
- /// <summary>
- /// _CMP_GT_OQ
- /// </summary>
- OrderedGreaterThanNonSignaling = 30,
-
- /// <summary>
- /// _CMP_TRUE_US
- /// </summary>
- UnorderedTrueSignaling = 31,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Fma.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Fma.PlatformNotSupported.cs
deleted file mode 100644
index 1899b6b530c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Fma.PlatformNotSupported.cs
+++ /dev/null
@@ -1,191 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel FMA hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Fma : Avx
- {
- internal Fma() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// __m128 _mm_fmadd_ps (__m128 a, __m128 b, __m128 c)
- /// VFMADDPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplyAdd(Vector128<float> a, Vector128<float> b, Vector128<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_fmadd_pd (__m128d a, __m128d b, __m128d c)
- /// VFMADDPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplyAdd(Vector128<double> a, Vector128<double> b, Vector128<double> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_fmadd_ps (__m256 a, __m256 b, __m256 c)
- /// VFMADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplyAdd(Vector256<float> a, Vector256<float> b, Vector256<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_fmadd_pd (__m256d a, __m256d b, __m256d c)
- /// VFMADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplyAdd(Vector256<double> a, Vector256<double> b, Vector256<double> c) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_fmadd_ss (__m128 a, __m128 b, __m128 c)
- /// VFMADDSS xmm, xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MultiplyAddScalar(Vector128<float> a, Vector128<float> b, Vector128<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_fmadd_sd (__m128d a, __m128d b, __m128d c)
- /// VFMADDSS xmm, xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MultiplyAddScalar(Vector128<double> a, Vector128<double> b, Vector128<double> c) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_fmaddsub_ps (__m128 a, __m128 b, __m128 c)
- /// VFMADDSUBPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplyAddSubtract(Vector128<float> a, Vector128<float> b, Vector128<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_fmaddsub_pd (__m128d a, __m128d b, __m128d c)
- /// VFMADDSUBPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplyAddSubtract(Vector128<double> a, Vector128<double> b, Vector128<double> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_fmaddsub_ps (__m256 a, __m256 b, __m256 c)
- /// VFMADDSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplyAddSubtract(Vector256<float> a, Vector256<float> b, Vector256<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_fmaddsub_pd (__m256d a, __m256d b, __m256d c)
- /// VFMADDSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplyAddSubtract(Vector256<double> a, Vector256<double> b, Vector256<double> c) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_fmsub_ps (__m128 a, __m128 b, __m128 c)
- /// VFMSUBPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplySubtract(Vector128<float> a, Vector128<float> b, Vector128<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_fmsub_pd (__m128d a, __m128d b, __m128d c)
- /// VFMSUBPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplySubtract(Vector128<double> a, Vector128<double> b, Vector128<double> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_fmsub_ps (__m256 a, __m256 b, __m256 c)
- /// VFMSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplySubtract(Vector256<float> a, Vector256<float> b, Vector256<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_fmsub_pd (__m256d a, __m256d b, __m256d c)
- /// VFMSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplySubtract(Vector256<double> a, Vector256<double> b, Vector256<double> c) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_fmsub_ss (__m128 a, __m128 b, __m128 c)
- /// VFMSUBSS xmm, xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MultiplySubtractScalar(Vector128<float> a, Vector128<float> b, Vector128<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_fmsub_sd (__m128d a, __m128d b, __m128d c)
- /// VFMSUBSD xmm, xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MultiplySubtractScalar(Vector128<double> a, Vector128<double> b, Vector128<double> c) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_fmsubadd_ps (__m128 a, __m128 b, __m128 c)
- /// VFMSUBADDPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplySubtractAdd(Vector128<float> a, Vector128<float> b, Vector128<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_fmsubadd_pd (__m128d a, __m128d b, __m128d c)
- /// VFMSUBADDPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplySubtractAdd(Vector128<double> a, Vector128<double> b, Vector128<double> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_fmsubadd_ps (__m256 a, __m256 b, __m256 c)
- /// VFMSUBADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplySubtractAdd(Vector256<float> a, Vector256<float> b, Vector256<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_fmsubadd_pd (__m256d a, __m256d b, __m256d c)
- /// VFMSUBADDPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplySubtractAdd(Vector256<double> a, Vector256<double> b, Vector256<double> c) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_fnmadd_ps (__m128 a, __m128 b, __m128 c)
- /// VFNMADDPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplyAddNegated(Vector128<float> a, Vector128<float> b, Vector128<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_fnmadd_pd (__m128d a, __m128d b, __m128d c)
- /// VFNMADDPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplyAddNegated(Vector128<double> a, Vector128<double> b, Vector128<double> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_fnmadd_ps (__m256 a, __m256 b, __m256 c)
- /// VFNMADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplyAddNegated(Vector256<float> a, Vector256<float> b, Vector256<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_fnmadd_pd (__m256d a, __m256d b, __m256d c)
- /// VFNMADDPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplyAddNegated(Vector256<double> a, Vector256<double> b, Vector256<double> c) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_fnmadd_ss (__m128 a, __m128 b, __m128 c)
- /// VFNMADDSS xmm, xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MultiplyAddNegatedScalar(Vector128<float> a, Vector128<float> b, Vector128<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_fnmadd_sd (__m128d a, __m128d b, __m128d c)
- /// VFNMADDSD xmm, xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MultiplyAddNegatedScalar(Vector128<double> a, Vector128<double> b, Vector128<double> c) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_fnmsub_ps (__m128 a, __m128 b, __m128 c)
- /// VFNMSUBPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplySubtractNegated(Vector128<float> a, Vector128<float> b, Vector128<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_fnmsub_pd (__m128d a, __m128d b, __m128d c)
- /// VFNMSUBPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplySubtractNegated(Vector128<double> a, Vector128<double> b, Vector128<double> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_fnmsub_ps (__m256 a, __m256 b, __m256 c)
- /// VFNMSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplySubtractNegated(Vector256<float> a, Vector256<float> b, Vector256<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_fnmsub_pd (__m256d a, __m256d b, __m256d c)
- /// VFNMSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplySubtractNegated(Vector256<double> a, Vector256<double> b, Vector256<double> c) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_fnmsub_ss (__m128 a, __m128 b, __m128 c)
- /// VFNMSUBSS xmm, xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MultiplySubtractNegatedScalar(Vector128<float> a, Vector128<float> b, Vector128<float> c) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_fnmsub_sd (__m128d a, __m128d b, __m128d c)
- /// VFNMSUBSD xmm, xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MultiplySubtractNegatedScalar(Vector128<double> a, Vector128<double> b, Vector128<double> c) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Fma.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Fma.cs
deleted file mode 100644
index 2e096613bea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Fma.cs
+++ /dev/null
@@ -1,190 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel FMA hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Fma : Avx
- {
- internal Fma() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// __m128 _mm_fmadd_ps (__m128 a, __m128 b, __m128 c)
- /// VFMADDPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplyAdd(Vector128<float> a, Vector128<float> b, Vector128<float> c) => MultiplyAdd(a, b, c);
- /// <summary>
- /// __m128d _mm_fmadd_pd (__m128d a, __m128d b, __m128d c)
- /// VFMADDPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplyAdd(Vector128<double> a, Vector128<double> b, Vector128<double> c) => MultiplyAdd(a, b, c);
- /// <summary>
- /// __m256 _mm256_fmadd_ps (__m256 a, __m256 b, __m256 c)
- /// VFMADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplyAdd(Vector256<float> a, Vector256<float> b, Vector256<float> c) => MultiplyAdd(a, b, c);
- /// <summary>
- /// __m256d _mm256_fmadd_pd (__m256d a, __m256d b, __m256d c)
- /// VFMADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplyAdd(Vector256<double> a, Vector256<double> b, Vector256<double> c) => MultiplyAdd(a, b, c);
-
- /// <summary>
- /// __m128 _mm_fmadd_ss (__m128 a, __m128 b, __m128 c)
- /// VFMADDSS xmm, xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MultiplyAddScalar(Vector128<float> a, Vector128<float> b, Vector128<float> c) => MultiplyAddScalar(a, b, c);
- /// <summary>
- /// __m128d _mm_fmadd_sd (__m128d a, __m128d b, __m128d c)
- /// VFMADDSS xmm, xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MultiplyAddScalar(Vector128<double> a, Vector128<double> b, Vector128<double> c) => MultiplyAddScalar(a, b, c);
-
- /// <summary>
- /// __m128 _mm_fmaddsub_ps (__m128 a, __m128 b, __m128 c)
- /// VFMADDSUBPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplyAddSubtract(Vector128<float> a, Vector128<float> b, Vector128<float> c) => MultiplyAddSubtract(a, b, c);
- /// <summary>
- /// __m128d _mm_fmaddsub_pd (__m128d a, __m128d b, __m128d c)
- /// VFMADDSUBPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplyAddSubtract(Vector128<double> a, Vector128<double> b, Vector128<double> c) => MultiplyAddSubtract(a, b, c);
- /// <summary>
- /// __m256 _mm256_fmaddsub_ps (__m256 a, __m256 b, __m256 c)
- /// VFMADDSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplyAddSubtract(Vector256<float> a, Vector256<float> b, Vector256<float> c) => MultiplyAddSubtract(a, b, c);
- /// <summary>
- /// __m256d _mm256_fmaddsub_pd (__m256d a, __m256d b, __m256d c)
- /// VFMADDSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplyAddSubtract(Vector256<double> a, Vector256<double> b, Vector256<double> c) => MultiplyAddSubtract(a, b, c);
-
- /// <summary>
- /// __m128 _mm_fmsub_ps (__m128 a, __m128 b, __m128 c)
- /// VFMSUBPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplySubtract(Vector128<float> a, Vector128<float> b, Vector128<float> c) => MultiplySubtract(a, b, c);
- /// <summary>
- /// __m128d _mm_fmsub_pd (__m128d a, __m128d b, __m128d c)
- /// VFMSUBPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplySubtract(Vector128<double> a, Vector128<double> b, Vector128<double> c) => MultiplySubtract(a, b, c);
- /// <summary>
- /// __m256 _mm256_fmsub_ps (__m256 a, __m256 b, __m256 c)
- /// VFMSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplySubtract(Vector256<float> a, Vector256<float> b, Vector256<float> c) => MultiplySubtract(a, b, c);
- /// <summary>
- /// __m256d _mm256_fmsub_pd (__m256d a, __m256d b, __m256d c)
- /// VFMSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplySubtract(Vector256<double> a, Vector256<double> b, Vector256<double> c) => MultiplySubtract(a, b, c);
-
- /// <summary>
- /// __m128 _mm_fmsub_ss (__m128 a, __m128 b, __m128 c)
- /// VFMSUBSS xmm, xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MultiplySubtractScalar(Vector128<float> a, Vector128<float> b, Vector128<float> c) => MultiplySubtractScalar(a, b, c);
- /// <summary>
- /// __m128d _mm_fmsub_sd (__m128d a, __m128d b, __m128d c)
- /// VFMSUBSD xmm, xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MultiplySubtractScalar(Vector128<double> a, Vector128<double> b, Vector128<double> c) => MultiplySubtractScalar(a, b, c);
-
- /// <summary>
- /// __m128 _mm_fmsubadd_ps (__m128 a, __m128 b, __m128 c)
- /// VFMSUBADDPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplySubtractAdd(Vector128<float> a, Vector128<float> b, Vector128<float> c) => MultiplySubtractAdd(a, b, c);
- /// <summary>
- /// __m128d _mm_fmsubadd_pd (__m128d a, __m128d b, __m128d c)
- /// VFMSUBADDPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplySubtractAdd(Vector128<double> a, Vector128<double> b, Vector128<double> c) => MultiplySubtractAdd(a, b, c);
- /// <summary>
- /// __m256 _mm256_fmsubadd_ps (__m256 a, __m256 b, __m256 c)
- /// VFMSUBADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplySubtractAdd(Vector256<float> a, Vector256<float> b, Vector256<float> c) => MultiplySubtractAdd(a, b, c);
- /// <summary>
- /// __m256d _mm256_fmsubadd_pd (__m256d a, __m256d b, __m256d c)
- /// VFMSUBADDPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplySubtractAdd(Vector256<double> a, Vector256<double> b, Vector256<double> c) => MultiplySubtractAdd(a, b, c);
-
- /// <summary>
- /// __m128 _mm_fnmadd_ps (__m128 a, __m128 b, __m128 c)
- /// VFNMADDPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplyAddNegated(Vector128<float> a, Vector128<float> b, Vector128<float> c) => MultiplyAddNegated(a, b, c);
- /// <summary>
- /// __m128d _mm_fnmadd_pd (__m128d a, __m128d b, __m128d c)
- /// VFNMADDPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplyAddNegated(Vector128<double> a, Vector128<double> b, Vector128<double> c) => MultiplyAddNegated(a, b, c);
- /// <summary>
- /// __m256 _mm256_fnmadd_ps (__m256 a, __m256 b, __m256 c)
- /// VFNMADDPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplyAddNegated(Vector256<float> a, Vector256<float> b, Vector256<float> c) => MultiplyAddNegated(a, b, c);
- /// <summary>
- /// __m256d _mm256_fnmadd_pd (__m256d a, __m256d b, __m256d c)
- /// VFNMADDPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplyAddNegated(Vector256<double> a, Vector256<double> b, Vector256<double> c) => MultiplyAddNegated(a, b, c);
-
- /// <summary>
- /// __m128 _mm_fnmadd_ss (__m128 a, __m128 b, __m128 c)
- /// VFNMADDSS xmm, xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MultiplyAddNegatedScalar(Vector128<float> a, Vector128<float> b, Vector128<float> c) => MultiplyAddNegatedScalar(a, b, c);
- /// <summary>
- /// __m128d _mm_fnmadd_sd (__m128d a, __m128d b, __m128d c)
- /// VFNMADDSD xmm, xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MultiplyAddNegatedScalar(Vector128<double> a, Vector128<double> b, Vector128<double> c) => MultiplyAddNegatedScalar(a, b, c);
-
- /// <summary>
- /// __m128 _mm_fnmsub_ps (__m128 a, __m128 b, __m128 c)
- /// VFNMSUBPS xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MultiplySubtractNegated(Vector128<float> a, Vector128<float> b, Vector128<float> c) => MultiplySubtractNegated(a, b, c);
- /// <summary>
- /// __m128d _mm_fnmsub_pd (__m128d a, __m128d b, __m128d c)
- /// VFNMSUBPD xmm, xmm, xmm/m128
- /// </summary>
- public static Vector128<double> MultiplySubtractNegated(Vector128<double> a, Vector128<double> b, Vector128<double> c) => MultiplySubtractNegated(a, b, c);
- /// <summary>
- /// __m256 _mm256_fnmsub_ps (__m256 a, __m256 b, __m256 c)
- /// VFNMSUBPS ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<float> MultiplySubtractNegated(Vector256<float> a, Vector256<float> b, Vector256<float> c) => MultiplySubtractNegated(a, b, c);
- /// <summary>
- /// __m256d _mm256_fnmsub_pd (__m256d a, __m256d b, __m256d c)
- /// VFNMSUBPD ymm, ymm, ymm/m256
- /// </summary>
- public static Vector256<double> MultiplySubtractNegated(Vector256<double> a, Vector256<double> b, Vector256<double> c) => MultiplySubtractNegated(a, b, c);
-
- /// <summary>
- /// __m128 _mm_fnmsub_ss (__m128 a, __m128 b, __m128 c)
- /// VFNMSUBSS xmm, xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MultiplySubtractNegatedScalar(Vector128<float> a, Vector128<float> b, Vector128<float> c) => MultiplySubtractNegatedScalar(a, b, c);
- /// <summary>
- /// __m128d _mm_fnmsub_sd (__m128d a, __m128d b, __m128d c)
- /// VFNMSUBSD xmm, xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MultiplySubtractNegatedScalar(Vector128<double> a, Vector128<double> b, Vector128<double> c) => MultiplySubtractNegatedScalar(a, b, c);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Lzcnt.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Lzcnt.PlatformNotSupported.cs
deleted file mode 100644
index 43b6712970a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Lzcnt.PlatformNotSupported.cs
+++ /dev/null
@@ -1,40 +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 System;
-using System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel LZCNT hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Lzcnt
- {
- internal Lzcnt() { }
-
- public static bool IsSupported { [Intrinsic] get { return false; } }
-
- public abstract class X64
- {
- internal X64() { }
-
- public static bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// unsigned __int64 _lzcnt_u64 (unsigned __int64 a)
- /// LZCNT reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong LeadingZeroCount(ulong value) { throw new PlatformNotSupportedException(); }
- }
-
- /// <summary>
- /// unsigned int _lzcnt_u32 (unsigned int a)
- /// LZCNT reg, reg/m32
- /// </summary>
- public static uint LeadingZeroCount(uint value) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Lzcnt.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Lzcnt.cs
deleted file mode 100644
index 63c2bb865f8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Lzcnt.cs
+++ /dev/null
@@ -1,41 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel LZCNT hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Lzcnt
- {
- internal Lzcnt() { }
-
- public static bool IsSupported { get => IsSupported; }
-
- [Intrinsic]
- public abstract class X64
- {
- internal X64() { }
-
- public static bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// unsigned __int64 _lzcnt_u64 (unsigned __int64 a)
- /// LZCNT reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong LeadingZeroCount(ulong value) => LeadingZeroCount(value);
- }
-
- /// <summary>
- /// unsigned int _lzcnt_u32 (unsigned int a)
- /// LZCNT reg, reg/m32
- /// </summary>
- public static uint LeadingZeroCount(uint value) => LeadingZeroCount(value);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Pclmulqdq.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Pclmulqdq.PlatformNotSupported.cs
deleted file mode 100644
index 53ae9d09cd9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Pclmulqdq.PlatformNotSupported.cs
+++ /dev/null
@@ -1,32 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel PCLMULQDQ hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Pclmulqdq : Sse2
- {
- internal Pclmulqdq() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// __m128i _mm_clmulepi64_si128 (__m128i a, __m128i b, const int imm8)
- /// PCLMULQDQ xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<long> CarrylessMultiply(Vector128<long> left, Vector128<long> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_clmulepi64_si128 (__m128i a, __m128i b, const int imm8)
- /// PCLMULQDQ xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<ulong> CarrylessMultiply(Vector128<ulong> left, Vector128<ulong> right, byte control) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Pclmulqdq.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Pclmulqdq.cs
deleted file mode 100644
index f9f53d51966..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Pclmulqdq.cs
+++ /dev/null
@@ -1,31 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel PCLMULQDQ hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Pclmulqdq : Sse2
- {
- internal Pclmulqdq() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// __m128i _mm_clmulepi64_si128 (__m128i a, __m128i b, const int imm8)
- /// PCLMULQDQ xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<long> CarrylessMultiply(Vector128<long> left, Vector128<long> right, byte control) => CarrylessMultiply(left, right, control);
- /// <summary>
- /// __m128i _mm_clmulepi64_si128 (__m128i a, __m128i b, const int imm8)
- /// PCLMULQDQ xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<ulong> CarrylessMultiply(Vector128<ulong> left, Vector128<ulong> right, byte control) => CarrylessMultiply(left, right, control);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Popcnt.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Popcnt.PlatformNotSupported.cs
deleted file mode 100644
index d85ee3877c4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Popcnt.PlatformNotSupported.cs
+++ /dev/null
@@ -1,40 +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 System;
-using System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel POPCNT hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Popcnt : Sse42
- {
- internal Popcnt() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- public new abstract class X64 : Sse41.X64
- {
- internal X64() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// __int64 _mm_popcnt_u64 (unsigned __int64 a)
- /// POPCNT reg64, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong PopCount(ulong value) { throw new PlatformNotSupportedException(); }
- }
-
- /// <summary>
- /// int _mm_popcnt_u32 (unsigned int a)
- /// POPCNT reg, reg/m32
- /// </summary>
- public static uint PopCount(uint value) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Popcnt.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Popcnt.cs
deleted file mode 100644
index 6b5a71973a7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Popcnt.cs
+++ /dev/null
@@ -1,39 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel POPCNT hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Popcnt : Sse42
- {
- internal Popcnt() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- [Intrinsic]
- public new abstract class X64 : Sse41.X64
- {
- internal X64() { }
- public static new bool IsSupported { get => IsSupported; }
- /// <summary>
- /// __int64 _mm_popcnt_u64 (unsigned __int64 a)
- /// POPCNT reg64, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong PopCount(ulong value) => PopCount(value);
- }
-
- /// <summary>
- /// int _mm_popcnt_u32 (unsigned int a)
- /// POPCNT reg, reg/m32
- /// </summary>
- public static uint PopCount(uint value) => PopCount(value);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse.PlatformNotSupported.cs
deleted file mode 100644
index 23532b45297..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse.PlatformNotSupported.cs
+++ /dev/null
@@ -1,574 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSE hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Sse
- {
- internal Sse() { }
-
- public static bool IsSupported { [Intrinsic] get { return false; } }
-
- public abstract class X64
- {
- internal X64() { }
-
- public static bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// __int64 _mm_cvtss_si64 (__m128 a)
- /// CVTSS2SI r64, xmm/m32
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long ConvertToInt64(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_cvtsi64_ss (__m128 a, __int64 b)
- /// CVTSI2SS xmm, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<float> ConvertScalarToVector128Single(Vector128<float> upper, long value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __int64 _mm_cvttss_si64 (__m128 a)
- /// CVTTSS2SI r64, xmm/m32
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long ConvertToInt64WithTruncation(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- }
-
- /// <summary>
- /// __m128 _mm_add_ps (__m128 a, __m128 b)
- /// ADDPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Add(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_add_ss (__m128 a, __m128 b)
- /// ADDSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> AddScalar(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_and_ps (__m128 a, __m128 b)
- /// ANDPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> And(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_andnot_ps (__m128 a, __m128 b)
- /// ANDNPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> AndNot(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpeq_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(0)
- /// </summary>
- public static Vector128<float> CompareEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comieq_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomieq_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpeq_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(0)
- /// </summary>
- public static Vector128<float> CompareScalarEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpgt_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(6)
- /// </summary>
- public static Vector128<float> CompareGreaterThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comigt_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedGreaterThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomigt_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedGreaterThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpgt_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(6)
- /// </summary>
- public static Vector128<float> CompareScalarGreaterThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpge_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(5)
- /// </summary>
- public static Vector128<float> CompareGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comige_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomige_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpge_ss (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m32, imm8(5)
- /// </summary>
- public static Vector128<float> CompareScalarGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmplt_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(1)
- /// </summary>
- public static Vector128<float> CompareLessThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comilt_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedLessThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomilt_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedLessThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmplt_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(1)
- /// </summary>
- public static Vector128<float> CompareScalarLessThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmple_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(2)
- /// </summary>
- public static Vector128<float> CompareLessThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comile_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedLessThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomile_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedLessThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmple_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(2)
- /// </summary>
- public static Vector128<float> CompareScalarLessThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpneq_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<float> CompareNotEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comineq_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedNotEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomineq_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedNotEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpneq_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(4)
- /// </summary>
- public static Vector128<float> CompareScalarNotEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpngt_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(2)
- /// </summary>
- public static Vector128<float> CompareNotGreaterThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpngt_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(2)
- /// </summary>
- public static Vector128<float> CompareScalarNotGreaterThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpnge_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(1)
- /// </summary>
- public static Vector128<float> CompareNotGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpnge_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(1)
- /// </summary>
- public static Vector128<float> CompareScalarNotGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpnlt_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(5)
- /// </summary>
- public static Vector128<float> CompareNotLessThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpnlt_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(5)
- /// </summary>
- public static Vector128<float> CompareScalarNotLessThan(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpnle_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(6)
- /// </summary>
- public static Vector128<float> CompareNotLessThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpnle_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(6)
- /// </summary>
- public static Vector128<float> CompareScalarNotLessThanOrEqual(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpord_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(7)
- /// </summary>
- public static Vector128<float> CompareOrdered(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpord_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(7)
- /// </summary>
- public static Vector128<float> CompareScalarOrdered(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpunord_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(3)
- /// </summary>
- public static Vector128<float> CompareUnordered(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cmpunord_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(3)
- /// </summary>
- public static Vector128<float> CompareScalarUnordered(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_cvtss_si32 (__m128 a)
- /// CVTSS2SI r32, xmm/m32
- /// </summary>
- public static int ConvertToInt32(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_cvtsi32_ss (__m128 a, int b)
- /// CVTSI2SS xmm, reg/m32
- /// </summary>
- public static Vector128<float> ConvertScalarToVector128Single(Vector128<float> upper, int value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_cvttss_si32 (__m128 a)
- /// CVTTSS2SI r32, xmm/m32
- /// </summary>
- public static int ConvertToInt32WithTruncation(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_div_ps (__m128 a, __m128 b)
- /// DIVPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Divide(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_div_ss (__m128 a, __m128 b)
- /// DIVSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> DivideScalar(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_loadu_ps (float const* mem_address)
- /// MOVUPS xmm, m128
- /// </summary>
- public static unsafe Vector128<float> LoadVector128(float* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_load_ss (float const* mem_address)
- /// MOVSS xmm, m32
- /// </summary>
- public static unsafe Vector128<float> LoadScalarVector128(float* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_load_ps (float const* mem_address)
- /// MOVAPS xmm, m128
- /// </summary>
- public static unsafe Vector128<float> LoadAlignedVector128(float* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_loadh_pi (__m128 a, __m64 const* mem_addr)
- /// MOVHPS xmm, m64
- /// </summary>
- public static unsafe Vector128<float> LoadHigh(Vector128<float> lower, float* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_loadl_pi (__m128 a, __m64 const* mem_addr)
- /// MOVLPS xmm, m64
- /// </summary>
- public static unsafe Vector128<float> LoadLow(Vector128<float> upper, float* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_max_ps (__m128 a, __m128 b)
- /// MAXPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Max(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_max_ss (__m128 a, __m128 b)
- /// MAXSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MaxScalar(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_min_ps (__m128 a, __m128 b)
- /// MINPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Min(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_min_ss (__m128 a, __m128 b)
- /// MINSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MinScalar(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_move_ss (__m128 a, __m128 b)
- /// MOVSS xmm, xmm
- /// </summary>
- public static Vector128<float> MoveScalar(Vector128<float> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_movehl_ps (__m128 a, __m128 b)
- /// MOVHLPS xmm, xmm
- /// </summary>
- public static Vector128<float> MoveHighToLow(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_movelh_ps (__m128 a, __m128 b)
- /// MOVLHPS xmm, xmm
- /// </summary>
- public static Vector128<float> MoveLowToHigh(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_movemask_ps (__m128 a)
- /// MOVMSKPS reg, xmm
- /// </summary>
- public static int MoveMask(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_mul_ps (__m128 a, __m128 b)
- /// MULPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Multiply(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_mul_ss (__m128 a, __m128 b)
- /// MULPS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MultiplyScalar(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_prefetch(char* p, int i)
- /// PREFETCHT0 m8
- /// </summary>
- public static unsafe void Prefetch0(void* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_prefetch(char* p, int i)
- /// PREFETCHT1 m8
- /// </summary>
- public static unsafe void Prefetch1(void* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_prefetch(char* p, int i)
- /// PREFETCHT2 m8
- /// </summary>
- public static unsafe void Prefetch2(void* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_prefetch(char* p, int i)
- /// PREFETCHNTA m8
- /// </summary>
- public static unsafe void PrefetchNonTemporal(void* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_or_ps (__m128 a, __m128 b)
- /// ORPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Or(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_rcp_ps (__m128 a)
- /// RCPPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Reciprocal(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_rcp_ss (__m128 a)
- /// RCPSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> ReciprocalScalar(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_rcp_ss (__m128 a, __m128 b)
- /// RCPSS xmm, xmm/m32
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> ReciprocalScalar(Vector128<float> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_rsqrt_ps (__m128 a)
- /// RSQRTPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> ReciprocalSqrt(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_rsqrt_ss (__m128 a)
- /// RSQRTSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> ReciprocalSqrtScalar(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_rsqrt_ss (__m128 a, __m128 b)
- /// RSQRTSS xmm, xmm/m32
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> ReciprocalSqrtScalar(Vector128<float> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_shuffle_ps (__m128 a, __m128 b, unsigned int control)
- /// SHUFPS xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<float> Shuffle(Vector128<float> left, Vector128<float> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_sqrt_ps (__m128 a)
- /// SQRTPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Sqrt(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_sqrt_ss (__m128 a)
- /// SQRTSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> SqrtScalar(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_sqrt_ss (__m128 a, __m128 b)
- /// SQRTSS xmm, xmm/m32
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> SqrtScalar(Vector128<float> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_store_ps (float* mem_addr, __m128 a)
- /// MOVAPS m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(float* address, Vector128<float> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_stream_ps (float* mem_addr, __m128 a)
- /// MOVNTPS m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(float* address, Vector128<float> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_storeu_ps (float* mem_addr, __m128 a)
- /// MOVUPS m128, xmm
- /// </summary>
- public static unsafe void Store(float* address, Vector128<float> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_sfence(void)
- /// SFENCE
- /// </summary>
- public static void StoreFence() { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_store_ss (float* mem_addr, __m128 a)
- /// MOVSS m32, xmm
- /// </summary>
- public static unsafe void StoreScalar(float* address, Vector128<float> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_storeh_pi (__m64* mem_addr, __m128 a)
- /// MOVHPS m64, xmm
- /// </summary>
- public static unsafe void StoreHigh(float* address, Vector128<float> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_storel_pi (__m64* mem_addr, __m128 a)
- /// MOVLPS m64, xmm
- /// </summary>
- public static unsafe void StoreLow(float* address, Vector128<float> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_sub_ps (__m128d a, __m128d b)
- /// SUBPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Subtract(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_sub_ss (__m128 a, __m128 b)
- /// SUBSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> SubtractScalar(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_unpackhi_ps (__m128 a, __m128 b)
- /// UNPCKHPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> UnpackHigh(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_unpacklo_ps (__m128 a, __m128 b)
- /// UNPCKLPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> UnpackLow(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_xor_ps (__m128 a, __m128 b)
- /// XORPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Xor(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse.cs
deleted file mode 100644
index f5cf132e4bc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse.cs
+++ /dev/null
@@ -1,573 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSE hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Sse
- {
- internal Sse() { }
-
- public static bool IsSupported { get => IsSupported; }
-
- [Intrinsic]
- public abstract class X64
- {
- internal X64() { }
-
- public static bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// __int64 _mm_cvtss_si64 (__m128 a)
- /// CVTSS2SI r64, xmm/m32
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long ConvertToInt64(Vector128<float> value) => ConvertToInt64(value);
- /// <summary>
- /// __m128 _mm_cvtsi64_ss (__m128 a, __int64 b)
- /// CVTSI2SS xmm, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<float> ConvertScalarToVector128Single(Vector128<float> upper, long value) => ConvertScalarToVector128Single(upper, value);
-
- /// <summary>
- /// __int64 _mm_cvttss_si64 (__m128 a)
- /// CVTTSS2SI r64, xmm/m32
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long ConvertToInt64WithTruncation(Vector128<float> value) => ConvertToInt64WithTruncation(value);
- }
-
- /// <summary>
- /// __m128 _mm_add_ps (__m128 a, __m128 b)
- /// ADDPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Add(Vector128<float> left, Vector128<float> right) => Add(left, right);
-
- /// <summary>
- /// __m128 _mm_add_ss (__m128 a, __m128 b)
- /// ADDSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> AddScalar(Vector128<float> left, Vector128<float> right) => AddScalar(left, right);
-
- /// <summary>
- /// __m128 _mm_and_ps (__m128 a, __m128 b)
- /// ANDPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> And(Vector128<float> left, Vector128<float> right) => And(left, right);
-
- /// <summary>
- /// __m128 _mm_andnot_ps (__m128 a, __m128 b)
- /// ANDNPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> AndNot(Vector128<float> left, Vector128<float> right) => AndNot(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpeq_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(0)
- /// </summary>
- public static Vector128<float> CompareEqual(Vector128<float> left, Vector128<float> right) => CompareEqual(left, right);
-
- /// <summary>
- /// int _mm_comieq_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedEqual(Vector128<float> left, Vector128<float> right) => CompareScalarOrderedEqual(left, right);
-
- /// <summary>
- /// int _mm_ucomieq_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedEqual(Vector128<float> left, Vector128<float> right) => CompareScalarUnorderedEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpeq_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(0)
- /// </summary>
- public static Vector128<float> CompareScalarEqual(Vector128<float> left, Vector128<float> right) => CompareScalarEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpgt_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(6)
- /// </summary>
- public static Vector128<float> CompareGreaterThan(Vector128<float> left, Vector128<float> right) => CompareGreaterThan(left, right);
-
- /// <summary>
- /// int _mm_comigt_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedGreaterThan(Vector128<float> left, Vector128<float> right) => CompareScalarOrderedGreaterThan(left, right);
-
- /// <summary>
- /// int _mm_ucomigt_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedGreaterThan(Vector128<float> left, Vector128<float> right) => CompareScalarUnorderedGreaterThan(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpgt_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(6)
- /// </summary>
- public static Vector128<float> CompareScalarGreaterThan(Vector128<float> left, Vector128<float> right) => CompareScalarGreaterThan(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpge_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(5)
- /// </summary>
- public static Vector128<float> CompareGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// int _mm_comige_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareScalarOrderedGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// int _mm_ucomige_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareScalarUnorderedGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpge_ss (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m32, imm8(5)
- /// </summary>
- public static Vector128<float> CompareScalarGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareScalarGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmplt_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(1)
- /// </summary>
- public static Vector128<float> CompareLessThan(Vector128<float> left, Vector128<float> right) => CompareLessThan(left, right);
-
- /// <summary>
- /// int _mm_comilt_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedLessThan(Vector128<float> left, Vector128<float> right) => CompareScalarOrderedLessThan(left, right);
-
- /// <summary>
- /// int _mm_ucomilt_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedLessThan(Vector128<float> left, Vector128<float> right) => CompareScalarUnorderedLessThan(left, right);
-
- /// <summary>
- /// __m128 _mm_cmplt_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(1)
- /// </summary>
- public static Vector128<float> CompareScalarLessThan(Vector128<float> left, Vector128<float> right) => CompareScalarLessThan(left, right);
-
- /// <summary>
- /// __m128 _mm_cmple_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(2)
- /// </summary>
- public static Vector128<float> CompareLessThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareLessThanOrEqual(left, right);
-
- /// <summary>
- /// int _mm_comile_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedLessThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareScalarOrderedLessThanOrEqual(left, right);
-
- /// <summary>
- /// int _mm_ucomile_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedLessThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareScalarUnorderedLessThanOrEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmple_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(2)
- /// </summary>
- public static Vector128<float> CompareScalarLessThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareScalarLessThanOrEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpneq_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<float> CompareNotEqual(Vector128<float> left, Vector128<float> right) => CompareNotEqual(left, right);
-
- /// <summary>
- /// int _mm_comineq_ss (__m128 a, __m128 b)
- /// COMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarOrderedNotEqual(Vector128<float> left, Vector128<float> right) => CompareScalarOrderedNotEqual(left, right);
-
- /// <summary>
- /// int _mm_ucomineq_ss (__m128 a, __m128 b)
- /// UCOMISS xmm, xmm/m32
- /// </summary>
- public static bool CompareScalarUnorderedNotEqual(Vector128<float> left, Vector128<float> right) => CompareScalarUnorderedNotEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpneq_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(4)
- /// </summary>
- public static Vector128<float> CompareScalarNotEqual(Vector128<float> left, Vector128<float> right) => CompareScalarNotEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpngt_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(2)
- /// </summary>
- public static Vector128<float> CompareNotGreaterThan(Vector128<float> left, Vector128<float> right) => CompareNotGreaterThan(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpngt_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(2)
- /// </summary>
- public static Vector128<float> CompareScalarNotGreaterThan(Vector128<float> left, Vector128<float> right) => CompareScalarNotGreaterThan(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpnge_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(1)
- /// </summary>
- public static Vector128<float> CompareNotGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareNotGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpnge_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(1)
- /// </summary>
- public static Vector128<float> CompareScalarNotGreaterThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareScalarNotGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpnlt_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(5)
- /// </summary>
- public static Vector128<float> CompareNotLessThan(Vector128<float> left, Vector128<float> right) => CompareNotLessThan(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpnlt_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(5)
- /// </summary>
- public static Vector128<float> CompareScalarNotLessThan(Vector128<float> left, Vector128<float> right) => CompareScalarNotLessThan(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpnle_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(6)
- /// </summary>
- public static Vector128<float> CompareNotLessThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareNotLessThanOrEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpnle_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(6)
- /// </summary>
- public static Vector128<float> CompareScalarNotLessThanOrEqual(Vector128<float> left, Vector128<float> right) => CompareScalarNotLessThanOrEqual(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpord_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(7)
- /// </summary>
- public static Vector128<float> CompareOrdered(Vector128<float> left, Vector128<float> right) => CompareOrdered(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpord_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(7)
- /// </summary>
- public static Vector128<float> CompareScalarOrdered(Vector128<float> left, Vector128<float> right) => CompareScalarOrdered(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpunord_ps (__m128 a, __m128 b)
- /// CMPPS xmm, xmm/m128, imm8(3)
- /// </summary>
- public static Vector128<float> CompareUnordered(Vector128<float> left, Vector128<float> right) => CompareUnordered(left, right);
-
- /// <summary>
- /// __m128 _mm_cmpunord_ss (__m128 a, __m128 b)
- /// CMPSS xmm, xmm/m32, imm8(3)
- /// </summary>
- public static Vector128<float> CompareScalarUnordered(Vector128<float> left, Vector128<float> right) => CompareScalarUnordered(left, right);
-
- /// <summary>
- /// int _mm_cvtss_si32 (__m128 a)
- /// CVTSS2SI r32, xmm/m32
- /// </summary>
- public static int ConvertToInt32(Vector128<float> value) => ConvertToInt32(value);
-
- /// <summary>
- /// __m128 _mm_cvtsi32_ss (__m128 a, int b)
- /// CVTSI2SS xmm, reg/m32
- /// </summary>
- public static Vector128<float> ConvertScalarToVector128Single(Vector128<float> upper, int value) => ConvertScalarToVector128Single(upper, value);
-
- /// <summary>
- /// int _mm_cvttss_si32 (__m128 a)
- /// CVTTSS2SI r32, xmm/m32
- /// </summary>
- public static int ConvertToInt32WithTruncation(Vector128<float> value) => ConvertToInt32WithTruncation(value);
-
- /// <summary>
- /// __m128 _mm_div_ps (__m128 a, __m128 b)
- /// DIVPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Divide(Vector128<float> left, Vector128<float> right) => Divide(left, right);
-
- /// <summary>
- /// __m128 _mm_div_ss (__m128 a, __m128 b)
- /// DIVSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> DivideScalar(Vector128<float> left, Vector128<float> right) => DivideScalar(left, right);
-
- /// <summary>
- /// __m128 _mm_loadu_ps (float const* mem_address)
- /// MOVUPS xmm, m128
- /// </summary>
- public static unsafe Vector128<float> LoadVector128(float* address) => LoadVector128(address);
-
- /// <summary>
- /// __m128 _mm_load_ss (float const* mem_address)
- /// MOVSS xmm, m32
- /// </summary>
- public static unsafe Vector128<float> LoadScalarVector128(float* address) => LoadScalarVector128(address);
-
- /// <summary>
- /// __m128 _mm_load_ps (float const* mem_address)
- /// MOVAPS xmm, m128
- /// </summary>
- public static unsafe Vector128<float> LoadAlignedVector128(float* address) => LoadAlignedVector128(address);
-
- /// <summary>
- /// __m128 _mm_loadh_pi (__m128 a, __m64 const* mem_addr)
- /// MOVHPS xmm, m64
- /// </summary>
- public static unsafe Vector128<float> LoadHigh(Vector128<float> lower, float* address) => LoadHigh(lower, address);
-
- /// <summary>
- /// __m128 _mm_loadl_pi (__m128 a, __m64 const* mem_addr)
- /// MOVLPS xmm, m64
- /// </summary>
- public static unsafe Vector128<float> LoadLow(Vector128<float> upper, float* address) => LoadLow(upper, address);
-
- /// <summary>
- /// __m128 _mm_max_ps (__m128 a, __m128 b)
- /// MAXPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Max(Vector128<float> left, Vector128<float> right) => Max(left, right);
-
- /// <summary>
- /// __m128 _mm_max_ss (__m128 a, __m128 b)
- /// MAXSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MaxScalar(Vector128<float> left, Vector128<float> right) => MaxScalar(left, right);
-
- /// <summary>
- /// __m128 _mm_min_ps (__m128 a, __m128 b)
- /// MINPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Min(Vector128<float> left, Vector128<float> right) => Min(left, right);
-
- /// <summary>
- /// __m128 _mm_min_ss (__m128 a, __m128 b)
- /// MINSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MinScalar(Vector128<float> left, Vector128<float> right) => MinScalar(left, right);
-
- /// <summary>
- /// __m128 _mm_move_ss (__m128 a, __m128 b)
- /// MOVSS xmm, xmm
- /// </summary>
- public static Vector128<float> MoveScalar(Vector128<float> upper, Vector128<float> value) => MoveScalar(upper, value);
-
- /// <summary>
- /// __m128 _mm_movehl_ps (__m128 a, __m128 b)
- /// MOVHLPS xmm, xmm
- /// </summary>
- public static Vector128<float> MoveHighToLow(Vector128<float> left, Vector128<float> right) => MoveHighToLow(left, right);
-
- /// <summary>
- /// __m128 _mm_movelh_ps (__m128 a, __m128 b)
- /// MOVLHPS xmm, xmm
- /// </summary>
- public static Vector128<float> MoveLowToHigh(Vector128<float> left, Vector128<float> right) => MoveLowToHigh(left, right);
-
- /// <summary>
- /// int _mm_movemask_ps (__m128 a)
- /// MOVMSKPS reg, xmm
- /// </summary>
- public static int MoveMask(Vector128<float> value) => MoveMask(value);
-
- /// <summary>
- /// __m128 _mm_mul_ps (__m128 a, __m128 b)
- /// MULPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Multiply(Vector128<float> left, Vector128<float> right) => Multiply(left, right);
-
- /// <summary>
- /// __m128 _mm_mul_ss (__m128 a, __m128 b)
- /// MULPS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> MultiplyScalar(Vector128<float> left, Vector128<float> right) => MultiplyScalar(left, right);
-
- /// <summary>
- /// __m128 _mm_or_ps (__m128 a, __m128 b)
- /// ORPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Or(Vector128<float> left, Vector128<float> right) => Or(left, right);
-
- /// <summary>
- /// void _mm_prefetch(char* p, int i)
- /// PREFETCHT0 m8
- /// </summary>
- public static unsafe void Prefetch0(void* address) => Prefetch0(address);
-
- /// <summary>
- /// void _mm_prefetch(char* p, int i)
- /// PREFETCHT1 m8
- /// </summary>
- public static unsafe void Prefetch1(void* address) => Prefetch1(address);
-
- /// <summary>
- /// void _mm_prefetch(char* p, int i)
- /// PREFETCHT2 m8
- /// </summary>
- public static unsafe void Prefetch2(void* address) => Prefetch2(address);
-
- /// <summary>
- /// void _mm_prefetch(char* p, int i)
- /// PREFETCHNTA m8
- /// </summary>
- public static unsafe void PrefetchNonTemporal(void* address) => PrefetchNonTemporal(address);
-
- /// <summary>
- /// __m128 _mm_rcp_ps (__m128 a)
- /// RCPPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Reciprocal(Vector128<float> value) => Reciprocal(value);
-
- /// <summary>
- /// __m128 _mm_rcp_ss (__m128 a)
- /// RCPSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> ReciprocalScalar(Vector128<float> value) => ReciprocalScalar(value);
-
- /// <summary>
- /// __m128 _mm_rcp_ss (__m128 a, __m128 b)
- /// RCPSS xmm, xmm/m32
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> ReciprocalScalar(Vector128<float> upper, Vector128<float> value) => ReciprocalScalar(upper, value);
-
- /// <summary>
- /// __m128 _mm_rsqrt_ps (__m128 a)
- /// RSQRTPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> ReciprocalSqrt(Vector128<float> value) => ReciprocalSqrt(value);
-
- /// <summary>
- /// __m128 _mm_rsqrt_ss (__m128 a)
- /// RSQRTSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> ReciprocalSqrtScalar(Vector128<float> value) => ReciprocalSqrtScalar(value);
-
- /// <summary>
- /// __m128 _mm_rsqrt_ss (__m128 a, __m128 b)
- /// RSQRTSS xmm, xmm/m32
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> ReciprocalSqrtScalar(Vector128<float> upper, Vector128<float> value) => ReciprocalSqrtScalar(upper, value);
-
- /// <summary>
- /// __m128 _mm_shuffle_ps (__m128 a, __m128 b, unsigned int control)
- /// SHUFPS xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<float> Shuffle(Vector128<float> left, Vector128<float> right, byte control) => Shuffle(left, right, control);
-
- /// <summary>
- /// __m128 _mm_sqrt_ps (__m128 a)
- /// SQRTPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Sqrt(Vector128<float> value) => Sqrt(value);
-
- /// <summary>
- /// __m128 _mm_sqrt_ss (__m128 a)
- /// SQRTSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> SqrtScalar(Vector128<float> value) => SqrtScalar(value);
-
- /// <summary>
- /// __m128 _mm_sqrt_ss (__m128 a, __m128 b)
- /// SQRTSS xmm, xmm/m32
- /// The above native signature does not exist. We provide this additional overload for consistency with the other scalar APIs.
- /// </summary>
- public static Vector128<float> SqrtScalar(Vector128<float> upper, Vector128<float> value) => SqrtScalar(upper, value);
-
- /// <summary>
- /// void _mm_store_ps (float* mem_addr, __m128 a)
- /// MOVAPS m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(float* address, Vector128<float> source) => StoreAligned(address, source);
-
- /// <summary>
- /// void _mm_stream_ps (float* mem_addr, __m128 a)
- /// MOVNTPS m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(float* address, Vector128<float> source) => StoreAlignedNonTemporal(address, source);
-
- /// <summary>
- /// void _mm_storeu_ps (float* mem_addr, __m128 a)
- /// MOVUPS m128, xmm
- /// </summary>
- public static unsafe void Store(float* address, Vector128<float> source) => Store(address, source);
-
- /// <summary>
- /// void _mm_sfence(void)
- /// SFENCE
- /// </summary>
- public static void StoreFence() => StoreFence();
-
- /// <summary>
- /// void _mm_store_ss (float* mem_addr, __m128 a)
- /// MOVSS m32, xmm
- /// </summary>
- public static unsafe void StoreScalar(float* address, Vector128<float> source) => StoreScalar(address, source);
-
- /// <summary>
- /// void _mm_storeh_pi (__m64* mem_addr, __m128 a)
- /// MOVHPS m64, xmm
- /// </summary>
- public static unsafe void StoreHigh(float* address, Vector128<float> source) => StoreHigh(address, source);
-
- /// <summary>
- /// void _mm_storel_pi (__m64* mem_addr, __m128 a)
- /// MOVLPS m64, xmm
- /// </summary>
- public static unsafe void StoreLow(float* address, Vector128<float> source) => StoreLow(address, source);
-
- /// <summary>
- /// __m128d _mm_sub_ps (__m128d a, __m128d b)
- /// SUBPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Subtract(Vector128<float> left, Vector128<float> right) => Subtract(left, right);
-
- /// <summary>
- /// __m128 _mm_sub_ss (__m128 a, __m128 b)
- /// SUBSS xmm, xmm/m32
- /// </summary>
- public static Vector128<float> SubtractScalar(Vector128<float> left, Vector128<float> right) => SubtractScalar(left, right);
-
- /// <summary>
- /// __m128 _mm_unpackhi_ps (__m128 a, __m128 b)
- /// UNPCKHPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> UnpackHigh(Vector128<float> left, Vector128<float> right) => UnpackHigh(left, right);
-
- /// <summary>
- /// __m128 _mm_unpacklo_ps (__m128 a, __m128 b)
- /// UNPCKLPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> UnpackLow(Vector128<float> left, Vector128<float> right) => UnpackLow(left, right);
-
- /// <summary>
- /// __m128 _mm_xor_ps (__m128 a, __m128 b)
- /// XORPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> Xor(Vector128<float> left, Vector128<float> right) => Xor(left, right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse2.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse2.PlatformNotSupported.cs
deleted file mode 100644
index df46013a29b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse2.PlatformNotSupported.cs
+++ /dev/null
@@ -1,1680 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSE2 hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Sse2 : Sse
- {
- internal Sse2() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- public new abstract class X64 : Sse.X64
- {
- internal X64() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// __int64 _mm_cvtsd_si64 (__m128d a)
- /// CVTSD2SI r64, xmm/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long ConvertToInt64(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __int64 _mm_cvtsi128_si64 (__m128i a)
- /// MOVQ reg/m64, xmm
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long ConvertToInt64(Vector128<long> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __int64 _mm_cvtsi128_si64 (__m128i a)
- /// MOVQ reg/m64, xmm
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ConvertToUInt64(Vector128<ulong> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cvtsi64_sd (__m128d a, __int64 b)
- /// CVTSI2SD xmm, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<double> ConvertScalarToVector128Double(Vector128<double> upper, long value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_cvtsi64_si128 (__int64 a)
- /// MOVQ xmm, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<long> ConvertScalarToVector128Int64(long value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_cvtsi64_si128 (__int64 a)
- /// MOVQ xmm, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<ulong> ConvertScalarToVector128UInt64(ulong value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __int64 _mm_cvttsd_si64 (__m128d a)
- /// CVTTSD2SI reg, xmm/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long ConvertToInt64WithTruncation(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_stream_si64(__int64 *p, __int64 a)
- /// MOVNTI m64, r64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static unsafe void StoreNonTemporal(long* address, long value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_stream_si64(__int64 *p, __int64 a)
- /// MOVNTI m64, r64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static unsafe void StoreNonTemporal(ulong* address, ulong value) { throw new PlatformNotSupportedException(); }
- }
-
- /// <summary>
- /// __m128i _mm_add_epi8 (__m128i a, __m128i b)
- /// PADDB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Add(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_add_epi8 (__m128i a, __m128i b)
- /// PADDB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Add(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_add_epi16 (__m128i a, __m128i b)
- /// PADDW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Add(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_add_epi16 (__m128i a, __m128i b)
- /// PADDW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Add(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_add_epi32 (__m128i a, __m128i b)
- /// PADDD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Add(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_add_epi32 (__m128i a, __m128i b)
- /// PADDD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Add(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_add_epi64 (__m128i a, __m128i b)
- /// PADDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> Add(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_add_epi64 (__m128i a, __m128i b)
- /// PADDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> Add(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_add_pd (__m128d a, __m128d b)
- /// ADDPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Add(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_add_sd (__m128d a, __m128d b)
- /// ADDSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> AddScalar(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_adds_epi8 (__m128i a, __m128i b)
- /// PADDSB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> AddSaturate(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_adds_epu8 (__m128i a, __m128i b)
- /// PADDUSB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> AddSaturate(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_adds_epi16 (__m128i a, __m128i b)
- /// PADDSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> AddSaturate(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_adds_epu16 (__m128i a, __m128i b)
- /// PADDUSW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> AddSaturate(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> And(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> And(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<short> And(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> And(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<int> And(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> And(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<long> And(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> And(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_and_pd (__m128d a, __m128d b)
- /// ANDPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> And(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> AndNot(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> AndNot(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<short> AndNot(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> AndNot(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<int> AndNot(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> AndNot(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<long> AndNot(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> AndNot(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_andnot_pd (__m128d a, __m128d b)
- /// ADDNPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> AndNot(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_avg_epu8 (__m128i a, __m128i b)
- /// PAVGB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Average(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_avg_epu16 (__m128i a, __m128i b)
- /// PAVGW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Average(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_cmpeq_epi8 (__m128i a, __m128i b)
- /// PCMPEQB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> CompareEqual(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cmpeq_epi8 (__m128i a, __m128i b)
- /// PCMPEQB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> CompareEqual(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cmpeq_epi16 (__m128i a, __m128i b)
- /// PCMPEQW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> CompareEqual(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cmpeq_epi16 (__m128i a, __m128i b)
- /// PCMPEQW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> CompareEqual(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cmpeq_epi32 (__m128i a, __m128i b)
- /// PCMPEQD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> CompareEqual(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cmpeq_epi32 (__m128i a, __m128i b)
- /// PCMPEQD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> CompareEqual(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_cmpeq_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(0)
- /// </summary>
- public static Vector128<double> CompareEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comieq_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomieq_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpeq_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(0)
- /// </summary>
- public static Vector128<double> CompareScalarEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_cmpgt_epi8 (__m128i a, __m128i b)
- /// PCMPGTB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> CompareGreaterThan(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cmpgt_epi16 (__m128i a, __m128i b)
- /// PCMPGTW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> CompareGreaterThan(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cmpgt_epi32 (__m128i a, __m128i b)
- /// PCMPGTD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> CompareGreaterThan(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_cmpgt_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(6)
- /// </summary>
- public static Vector128<double> CompareGreaterThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comigt_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedGreaterThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomigt_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedGreaterThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpgt_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(6)
- /// </summary>
- public static Vector128<double> CompareScalarGreaterThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpge_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(5)
- /// </summary>
- public static Vector128<double> CompareGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comige_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomige_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpge_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(5)
- /// </summary>
- public static Vector128<double> CompareScalarGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_cmplt_epi8 (__m128i a, __m128i b)
- /// PCMPGTB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> CompareLessThan(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cmplt_epi16 (__m128i a, __m128i b)
- /// PCMPGTW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> CompareLessThan(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cmplt_epi32 (__m128i a, __m128i b)
- /// PCMPGTD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> CompareLessThan(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_cmplt_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(1)
- /// </summary>
- public static Vector128<double> CompareLessThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comilt_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedLessThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomilt_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedLessThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmplt_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(1)
- /// </summary>
- public static Vector128<double> CompareScalarLessThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmple_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(2)
- /// </summary>
- public static Vector128<double> CompareLessThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comile_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedLessThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomile_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedLessThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmple_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(2)
- /// </summary>
- public static Vector128<double> CompareScalarLessThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpneq_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<double> CompareNotEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_comineq_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedNotEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_ucomineq_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedNotEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpneq_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(4)
- /// </summary>
- public static Vector128<double> CompareScalarNotEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpngt_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(2)
- /// </summary>
- public static Vector128<double> CompareNotGreaterThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpngt_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(2)
- /// </summary>
- public static Vector128<double> CompareScalarNotGreaterThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpnge_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(1)
- /// </summary>
- public static Vector128<double> CompareNotGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpnge_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(1)
- /// </summary>
- public static Vector128<double> CompareScalarNotGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpnlt_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(5)
- /// </summary>
- public static Vector128<double> CompareNotLessThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpnlt_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(5)
- /// </summary>
- public static Vector128<double> CompareScalarNotLessThan(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpnle_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(6)
- /// </summary>
- public static Vector128<double> CompareNotLessThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpnle_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(6)
- /// </summary>
- public static Vector128<double> CompareScalarNotLessThanOrEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpord_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(7)
- /// </summary>
- public static Vector128<double> CompareOrdered(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpord_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(7)
- /// </summary>
- public static Vector128<double> CompareScalarOrdered(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpunord_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(3)
- /// </summary>
- public static Vector128<double> CompareUnordered(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cmpunord_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(3)
- /// </summary>
- public static Vector128<double> CompareScalarUnordered(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_cvtps_epi32 (__m128 a)
- /// CVTPS2DQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtpd_epi32 (__m128d a)
- /// CVTPD2DQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_cvtepi32_ps (__m128i a)
- /// CVTDQ2PS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> ConvertToVector128Single(Vector128<int> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_cvtpd_ps (__m128d a)
- /// CVTPD2PS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> ConvertToVector128Single(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_cvtepi32_pd (__m128i a)
- /// CVTDQ2PD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> ConvertToVector128Double(Vector128<int> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_cvtps_pd (__m128 a)
- /// CVTPS2PD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> ConvertToVector128Double(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_cvtsd_si32 (__m128d a)
- /// CVTSD2SI r32, xmm/m64
- /// </summary>
- public static int ConvertToInt32(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm_cvtsi128_si32 (__m128i a)
- /// MOVD reg/m32, xmm
- /// </summary>
- public static int ConvertToInt32(Vector128<int> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm_cvtsi128_si32 (__m128i a)
- /// MOVD reg/m32, xmm
- /// </summary>
- public static uint ConvertToUInt32(Vector128<uint> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_cvtsi32_sd (__m128d a, int b)
- /// CVTSI2SD xmm, reg/m32
- /// </summary>
- public static Vector128<double> ConvertScalarToVector128Double(Vector128<double> upper, int value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_cvtss_sd (__m128d a, __m128 b)
- /// CVTSS2SD xmm, xmm/m32
- /// </summary>
- public static Vector128<double> ConvertScalarToVector128Double(Vector128<double> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtsi32_si128 (int a)
- /// MOVD xmm, reg/m32
- /// </summary>
- public static Vector128<int> ConvertScalarToVector128Int32(int value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_cvtsd_ss (__m128 a, __m128d b)
- /// CVTSD2SS xmm, xmm/m64
- /// </summary>
- public static Vector128<float> ConvertScalarToVector128Single(Vector128<float> upper, Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtsi32_si128 (int a)
- /// MOVD xmm, reg/m32
- /// </summary>
- public static Vector128<uint> ConvertScalarToVector128UInt32(uint value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_cvttps_epi32 (__m128 a)
- /// CVTTPS2DQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32WithTruncation(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvttpd_epi32 (__m128d a)
- /// CVTTPD2DQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32WithTruncation(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_cvttsd_si32 (__m128d a)
- /// CVTTSD2SI reg, xmm/m64
- /// </summary>
- public static int ConvertToInt32WithTruncation(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_div_pd (__m128d a, __m128d b)
- /// DIVPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Divide(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_div_sd (__m128d a, __m128d b)
- /// DIVSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> DivideScalar(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_extract_epi16 (__m128i a, int immediate)
- /// PEXTRW reg, xmm, imm8
- /// </summary>
- public static ushort Extract(Vector128<ushort> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_insert_epi16 (__m128i a, int i, int immediate)
- /// PINSRW xmm, reg/m16, imm8
- /// </summary>
- public static Vector128<short> Insert(Vector128<short> value, short data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_insert_epi16 (__m128i a, int i, int immediate)
- /// PINSRW xmm, reg/m16, imm8
- /// </summary>
- public static Vector128<ushort> Insert(Vector128<ushort> value, ushort data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<sbyte> LoadVector128(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<byte> LoadVector128(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<short> LoadVector128(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<ushort> LoadVector128(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<int> LoadVector128(int* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<uint> LoadVector128(uint* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<long> LoadVector128(long* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<ulong> LoadVector128(ulong* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_loadu_pd (double const* mem_address)
- /// MOVUPD xmm, m128
- /// </summary>
- public static unsafe Vector128<double> LoadVector128(double* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_load_sd (double const* mem_address)
- /// MOVSD xmm, m64
- /// </summary>
- public static unsafe Vector128<double> LoadScalarVector128(double* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<sbyte> LoadAlignedVector128(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<byte> LoadAlignedVector128(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<short> LoadAlignedVector128(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<ushort> LoadAlignedVector128(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<int> LoadAlignedVector128(int* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<uint> LoadAlignedVector128(uint* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<long> LoadAlignedVector128(long* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<ulong> LoadAlignedVector128(ulong* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_load_pd (double const* mem_address)
- /// MOVAPD xmm, m128
- /// </summary>
- public static unsafe Vector128<double> LoadAlignedVector128(double* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_lfence(void)
- /// LFENCE
- /// </summary>
- public static void LoadFence() { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_loadh_pd (__m128d a, double const* mem_addr)
- /// MOVHPD xmm, m64
- /// </summary>
- public static unsafe Vector128<double> LoadHigh(Vector128<double> lower, double* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_loadl_pd (__m128d a, double const* mem_addr)
- /// MOVLPD xmm, m64
- /// </summary>
- public static unsafe Vector128<double> LoadLow(Vector128<double> upper, double* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_loadl_epi32 (__m128i const* mem_addr)
- /// MOVD xmm, reg/m64
- /// The above native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<int> LoadScalarVector128(int* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_loadl_epi32 (__m128i const* mem_addr)
- /// MOVD xmm, reg/m64
- /// The above native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<uint> LoadScalarVector128(uint* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_loadl_epi64 (__m128i const* mem_addr)
- /// MOVQ xmm, reg/m64
- /// </summary>
- public static unsafe Vector128<long> LoadScalarVector128(long* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_loadl_epi64 (__m128i const* mem_addr)
- /// MOVQ xmm, reg/m64
- /// </summary>
- public static unsafe Vector128<ulong> LoadScalarVector128(ulong* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_maskmoveu_si128 (__m128i a, __m128i mask, char* mem_address)
- /// MASKMOVDQU xmm, xmm
- /// </summary>
- public static unsafe void MaskMove(Vector128<sbyte> source, Vector128<sbyte> mask, sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_maskmoveu_si128 (__m128i a, __m128i mask, char* mem_address)
- /// MASKMOVDQU xmm, xmm
- /// </summary>
- public static unsafe void MaskMove(Vector128<byte> source, Vector128<byte> mask, byte* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_max_epu8 (__m128i a, __m128i b)
- /// PMAXUB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Max(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_max_epi16 (__m128i a, __m128i b)
- /// PMAXSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Max(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_max_pd (__m128d a, __m128d b)
- /// MAXPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Max(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_max_sd (__m128d a, __m128d b)
- /// MAXSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MaxScalar(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_mfence(void)
- /// MFENCE
- /// </summary>
- public static void MemoryFence() { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_min_epu8 (__m128i a, __m128i b)
- /// PMINUB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Min(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_min_epi16 (__m128i a, __m128i b)
- /// PMINSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Min(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_min_pd (__m128d a, __m128d b)
- /// MINPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Min(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_min_sd (__m128d a, __m128d b)
- /// MINSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MinScalar(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_move_sd (__m128d a, __m128d b)
- /// MOVSD xmm, xmm
- /// </summary>
- public static Vector128<double> MoveScalar(Vector128<double> upper, Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_movemask_epi8 (__m128i a)
- /// PMOVMSKB reg, xmm
- /// </summary>
- public static int MoveMask(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm_movemask_epi8 (__m128i a)
- /// PMOVMSKB reg, xmm
- /// </summary>
- public static int MoveMask(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm_movemask_pd (__m128d a)
- /// MOVMSKPD reg, xmm
- /// </summary>
- public static int MoveMask(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_move_epi64 (__m128i a)
- /// MOVQ xmm, xmm
- /// </summary>
- public static Vector128<long> MoveScalar(Vector128<long> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_move_epi64 (__m128i a)
- /// MOVQ xmm, xmm
- /// </summary>
- public static Vector128<ulong> MoveScalar(Vector128<ulong> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_mul_epu32 (__m128i a, __m128i b)
- /// PMULUDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> Multiply(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_mul_pd (__m128d a, __m128d b)
- /// MULPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Multiply(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_mul_sd (__m128d a, __m128d b)
- /// MULSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MultiplyScalar(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_mulhi_epi16 (__m128i a, __m128i b)
- /// PMULHW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> MultiplyHigh(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_mulhi_epu16 (__m128i a, __m128i b)
- /// PMULHUW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> MultiplyHigh(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_madd_epi16 (__m128i a, __m128i b)
- /// PMADDWD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> MultiplyAddAdjacent(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_mullo_epi16 (__m128i a, __m128i b)
- /// PMULLW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> MultiplyLow(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_mullo_epi16 (__m128i a, __m128i b)
- /// PMULLW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> MultiplyLow(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Or(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Or(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Or(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Or(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Or(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Or(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<long> Or(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> Or(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_or_pd (__m128d a, __m128d b)
- /// ORPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Or(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_packs_epi16 (__m128i a, __m128i b)
- /// PACKSSWB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> PackSignedSaturate(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_packs_epi32 (__m128i a, __m128i b)
- /// PACKSSDW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> PackSignedSaturate(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_packus_epi16 (__m128i a, __m128i b)
- /// PACKUSWB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> PackUnsignedSaturate(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_sad_epu8 (__m128i a, __m128i b)
- /// PSADBW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> SumAbsoluteDifferences(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_shuffle_epi32 (__m128i a, int immediate)
- /// PSHUFD xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<int> Shuffle(Vector128<int> value, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_shuffle_epi32 (__m128i a, int immediate)
- /// PSHUFD xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<uint> Shuffle(Vector128<uint> value, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_shuffle_pd (__m128d a, __m128d b, int immediate)
- /// SHUFPD xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<double> Shuffle(Vector128<double> left, Vector128<double> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_shufflehi_epi16 (__m128i a, int immediate)
- /// PSHUFHW xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<short> ShuffleHigh(Vector128<short> value, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_shufflehi_epi16 (__m128i a, int control)
- /// PSHUFHW xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<ushort> ShuffleHigh(Vector128<ushort> value, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_shufflelo_epi16 (__m128i a, int control)
- /// PSHUFLW xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<short> ShuffleLow(Vector128<short> value, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_shufflelo_epi16 (__m128i a, int control)
- /// PSHUFLW xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<ushort> ShuffleLow(Vector128<ushort> value, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_sll_epi16 (__m128i a, __m128i count)
- /// PSLLW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> ShiftLeftLogical(Vector128<short> value, Vector128<short> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sll_epi16 (__m128i a, __m128i count)
- /// PSLLW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> ShiftLeftLogical(Vector128<ushort> value, Vector128<ushort> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sll_epi32 (__m128i a, __m128i count)
- /// PSLLD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftLeftLogical(Vector128<int> value, Vector128<int> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sll_epi32 (__m128i a, __m128i count)
- /// PSLLD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> ShiftLeftLogical(Vector128<uint> value, Vector128<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sll_epi64 (__m128i a, __m128i count)
- /// PSLLQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> ShiftLeftLogical(Vector128<long> value, Vector128<long> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sll_epi64 (__m128i a, __m128i count)
- /// PSLLQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> ShiftLeftLogical(Vector128<ulong> value, Vector128<ulong> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_slli_epi16 (__m128i a, int immediate)
- /// PSLLW xmm, imm8
- /// </summary>
- public static Vector128<short> ShiftLeftLogical(Vector128<short> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_slli_epi16 (__m128i a, int immediate)
- /// PSLLW xmm, imm8
- /// </summary>
- public static Vector128<ushort> ShiftLeftLogical(Vector128<ushort> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_slli_epi32 (__m128i a, int immediate)
- /// PSLLD xmm, imm8
- /// </summary>
- public static Vector128<int> ShiftLeftLogical(Vector128<int> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_slli_epi32 (__m128i a, int immediate)
- /// PSLLD xmm, imm8
- /// </summary>
- public static Vector128<uint> ShiftLeftLogical(Vector128<uint> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_slli_epi64 (__m128i a, int immediate)
- /// PSLLQ xmm, imm8
- /// </summary>
- public static Vector128<long> ShiftLeftLogical(Vector128<long> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_slli_epi64 (__m128i a, int immediate)
- /// PSLLQ xmm, imm8
- /// </summary>
- public static Vector128<ulong> ShiftLeftLogical(Vector128<ulong> value, byte count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<sbyte> ShiftLeftLogical128BitLane(Vector128<sbyte> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<byte> ShiftLeftLogical128BitLane(Vector128<byte> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<short> ShiftLeftLogical128BitLane(Vector128<short> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<ushort> ShiftLeftLogical128BitLane(Vector128<ushort> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<int> ShiftLeftLogical128BitLane(Vector128<int> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<uint> ShiftLeftLogical128BitLane(Vector128<uint> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<long> ShiftLeftLogical128BitLane(Vector128<long> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<ulong> ShiftLeftLogical128BitLane(Vector128<ulong> value, byte numBytes) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_sra_epi16 (__m128i a, __m128i count)
- /// PSRAW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> ShiftRightArithmetic(Vector128<short> value, Vector128<short> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sra_epi32 (__m128i a, __m128i count)
- /// PSRAD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftRightArithmetic(Vector128<int> value, Vector128<int> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_srai_epi16 (__m128i a, int immediate)
- /// PSRAW xmm, imm8
- /// </summary>
- public static Vector128<short> ShiftRightArithmetic(Vector128<short> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srai_epi32 (__m128i a, int immediate)
- /// PSRAD xmm, imm8
- /// </summary>
- public static Vector128<int> ShiftRightArithmetic(Vector128<int> value, byte count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_srl_epi16 (__m128i a, __m128i count)
- /// PSRLW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> ShiftRightLogical(Vector128<short> value, Vector128<short> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srl_epi16 (__m128i a, __m128i count)
- /// PSRLW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> ShiftRightLogical(Vector128<ushort> value, Vector128<ushort> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srl_epi32 (__m128i a, __m128i count)
- /// PSRLD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftRightLogical(Vector128<int> value, Vector128<int> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srl_epi32 (__m128i a, __m128i count)
- /// PSRLD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> ShiftRightLogical(Vector128<uint> value, Vector128<uint> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srl_epi64 (__m128i a, __m128i count)
- /// PSRLQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> ShiftRightLogical(Vector128<long> value, Vector128<long> count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srl_epi64 (__m128i a, __m128i count)
- /// PSRLQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> ShiftRightLogical(Vector128<ulong> value, Vector128<ulong> count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_srli_epi16 (__m128i a, int immediate)
- /// PSRLW xmm, imm8
- /// </summary>
- public static Vector128<short> ShiftRightLogical(Vector128<short> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srli_epi16 (__m128i a, int immediate)
- /// PSRLW xmm, imm8
- /// </summary>
- public static Vector128<ushort> ShiftRightLogical(Vector128<ushort> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srli_epi32 (__m128i a, int immediate)
- /// PSRLD xmm, imm8
- /// </summary>
- public static Vector128<int> ShiftRightLogical(Vector128<int> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srli_epi32 (__m128i a, int immediate)
- /// PSRLD xmm, imm8
- /// </summary>
- public static Vector128<uint> ShiftRightLogical(Vector128<uint> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srli_epi64 (__m128i a, int immediate)
- /// PSRLQ xmm, imm8
- /// </summary>
- public static Vector128<long> ShiftRightLogical(Vector128<long> value, byte count) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_srli_epi64 (__m128i a, int immediate)
- /// PSRLQ xmm, imm8
- /// </summary>
- public static Vector128<ulong> ShiftRightLogical(Vector128<ulong> value, byte count) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<sbyte> ShiftRightLogical128BitLane(Vector128<sbyte> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<byte> ShiftRightLogical128BitLane(Vector128<byte> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<short> ShiftRightLogical128BitLane(Vector128<short> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<ushort> ShiftRightLogical128BitLane(Vector128<ushort> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<int> ShiftRightLogical128BitLane(Vector128<int> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<uint> ShiftRightLogical128BitLane(Vector128<uint> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<long> ShiftRightLogical128BitLane(Vector128<long> value, byte numBytes) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<ulong> ShiftRightLogical128BitLane(Vector128<ulong> value, byte numBytes) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_sqrt_pd (__m128d a)
- /// SQRTPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Sqrt(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_sqrt_sd (__m128d a)
- /// SQRTSD xmm, xmm/64
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> SqrtScalar(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_sqrt_sd (__m128d a, __m128d b)
- /// SQRTSD xmm, xmm/64
- /// </summary>
- public static Vector128<double> SqrtScalar(Vector128<double> upper, Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_store_sd (double* mem_addr, __m128d a)
- /// MOVSD m64, xmm
- /// </summary>
- public static unsafe void StoreScalar(double* address, Vector128<double> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_storel_epi64 (__m128i* mem_addr, __m128i a)
- /// MOVQ m64, xmm
- /// </summary>
- public static unsafe void StoreScalar(long* address, Vector128<long> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_storel_epi64 (__m128i* mem_addr, __m128i a)
- /// MOVQ m64, xmm
- /// </summary>
- public static unsafe void StoreScalar(ulong* address, Vector128<ulong> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(sbyte* address, Vector128<sbyte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(byte* address, Vector128<byte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(short* address, Vector128<short> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(ushort* address, Vector128<ushort> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(int* address, Vector128<int> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(uint* address, Vector128<uint> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(long* address, Vector128<long> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(ulong* address, Vector128<ulong> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_store_pd (double* mem_addr, __m128d a)
- /// MOVAPD m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(double* address, Vector128<double> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(sbyte* address, Vector128<sbyte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(byte* address, Vector128<byte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(short* address, Vector128<short> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(ushort* address, Vector128<ushort> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(int* address, Vector128<int> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(uint* address, Vector128<uint> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(long* address, Vector128<long> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(ulong* address, Vector128<ulong> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_stream_pd (double* mem_addr, __m128d a)
- /// MOVNTPD m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(double* address, Vector128<double> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(sbyte* address, Vector128<sbyte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(byte* address, Vector128<byte> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(short* address, Vector128<short> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(ushort* address, Vector128<ushort> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(int* address, Vector128<int> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(uint* address, Vector128<uint> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(long* address, Vector128<long> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(ulong* address, Vector128<ulong> source) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_storeu_pd (double* mem_addr, __m128d a)
- /// MOVUPD m128, xmm
- /// </summary>
- public static unsafe void Store(double* address, Vector128<double> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_storeh_pd (double* mem_addr, __m128d a)
- /// MOVHPD m64, xmm
- /// </summary>
- public static unsafe void StoreHigh(double* address, Vector128<double> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_storel_pd (double* mem_addr, __m128d a)
- /// MOVLPD m64, xmm
- /// </summary>
- public static unsafe void StoreLow(double* address, Vector128<double> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// void _mm_stream_si32(int *p, int a)
- /// MOVNTI m32, r32
- /// </summary>
- public static unsafe void StoreNonTemporal(int* address, int value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// void _mm_stream_si32(int *p, int a)
- /// MOVNTI m32, r32
- /// </summary>
- public static unsafe void StoreNonTemporal(uint* address, uint value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_sub_epi8 (__m128i a, __m128i b)
- /// PSUBB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Subtract(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sub_epi8 (__m128i a, __m128i b)
- /// PSUBB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Subtract(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sub_epi16 (__m128i a, __m128i b)
- /// PSUBW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Subtract(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sub_epi16 (__m128i a, __m128i b)
- /// PSUBW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Subtract(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sub_epi32 (__m128i a, __m128i b)
- /// PSUBD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Subtract(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sub_epi32 (__m128i a, __m128i b)
- /// PSUBD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Subtract(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sub_epi64 (__m128i a, __m128i b)
- /// PSUBQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> Subtract(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sub_epi64 (__m128i a, __m128i b)
- /// PSUBQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> Subtract(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_sub_pd (__m128d a, __m128d b)
- /// SUBPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Subtract(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_sub_sd (__m128d a, __m128d b)
- /// SUBSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> SubtractScalar(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_subs_epi8 (__m128i a, __m128i b)
- /// PSUBSB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> SubtractSaturate(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_subs_epi16 (__m128i a, __m128i b)
- /// PSUBSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> SubtractSaturate(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_subs_epu8 (__m128i a, __m128i b)
- /// PSUBUSB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> SubtractSaturate(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_subs_epu16 (__m128i a, __m128i b)
- /// PSUBUSW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> SubtractSaturate(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_unpackhi_epi8 (__m128i a, __m128i b)
- /// PUNPCKHBW xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> UnpackHigh(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpackhi_epi8 (__m128i a, __m128i b)
- /// PUNPCKHBW xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> UnpackHigh(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpackhi_epi16 (__m128i a, __m128i b)
- /// PUNPCKHWD xmm, xmm/m128
- /// </summary>
- public static Vector128<short> UnpackHigh(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpackhi_epi16 (__m128i a, __m128i b)
- /// PUNPCKHWD xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> UnpackHigh(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpackhi_epi32 (__m128i a, __m128i b)
- /// PUNPCKHDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> UnpackHigh(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpackhi_epi32 (__m128i a, __m128i b)
- /// PUNPCKHDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> UnpackHigh(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpackhi_epi64 (__m128i a, __m128i b)
- /// PUNPCKHQDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> UnpackHigh(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpackhi_epi64 (__m128i a, __m128i b)
- /// PUNPCKHQDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> UnpackHigh(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_unpackhi_pd (__m128d a, __m128d b)
- /// UNPCKHPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> UnpackHigh(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_unpacklo_epi8 (__m128i a, __m128i b)
- /// PUNPCKLBW xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> UnpackLow(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpacklo_epi8 (__m128i a, __m128i b)
- /// PUNPCKLBW xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> UnpackLow(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpacklo_epi16 (__m128i a, __m128i b)
- /// PUNPCKLWD xmm, xmm/m128
- /// </summary>
- public static Vector128<short> UnpackLow(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpacklo_epi16 (__m128i a, __m128i b)
- /// PUNPCKLWD xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> UnpackLow(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpacklo_epi32 (__m128i a, __m128i b)
- /// PUNPCKLDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> UnpackLow(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpacklo_epi32 (__m128i a, __m128i b)
- /// PUNPCKLDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> UnpackLow(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpacklo_epi64 (__m128i a, __m128i b)
- /// PUNPCKLQDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> UnpackLow(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_unpacklo_epi64 (__m128i a, __m128i b)
- /// PUNPCKLQDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> UnpackLow(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_unpacklo_pd (__m128d a, __m128d b)
- /// UNPCKLPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> UnpackLow(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Xor(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Xor(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Xor(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Xor(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Xor(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Xor(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<long> Xor(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> Xor(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_xor_pd (__m128d a, __m128d b)
- /// XORPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Xor(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse2.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse2.cs
deleted file mode 100644
index 464faffc7df..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse2.cs
+++ /dev/null
@@ -1,1684 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSE2 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Sse2 : Sse
- {
- internal Sse2() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- [Intrinsic]
- public new abstract class X64 : Sse.X64
- {
- internal X64() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// __int64 _mm_cvtsd_si64 (__m128d a)
- /// CVTSD2SI r64, xmm/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long ConvertToInt64(Vector128<double> value) => ConvertToInt64(value);
- /// <summary>
- /// __int64 _mm_cvtsi128_si64 (__m128i a)
- /// MOVQ reg/m64, xmm
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long ConvertToInt64(Vector128<long> value) => ConvertToInt64(value);
-
- /// <summary>
- /// __int64 _mm_cvtsi128_si64 (__m128i a)
- /// MOVQ reg/m64, xmm
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong ConvertToUInt64(Vector128<ulong> value) => ConvertToUInt64(value);
-
- /// <summary>
- /// __m128d _mm_cvtsi64_sd (__m128d a, __int64 b)
- /// CVTSI2SD xmm, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<double> ConvertScalarToVector128Double(Vector128<double> upper, long value) => ConvertScalarToVector128Double(upper, value);
-
- /// <summary>
- /// __m128i _mm_cvtsi64_si128 (__int64 a)
- /// MOVQ xmm, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<long> ConvertScalarToVector128Int64(long value) => ConvertScalarToVector128Int64(value);
-
- /// <summary>
- /// __m128i _mm_cvtsi64_si128 (__int64 a)
- /// MOVQ xmm, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<ulong> ConvertScalarToVector128UInt64(ulong value) => ConvertScalarToVector128UInt64(value);
-
- /// <summary>
- /// __int64 _mm_cvttsd_si64 (__m128d a)
- /// CVTTSD2SI reg, xmm/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long ConvertToInt64WithTruncation(Vector128<double> value) => ConvertToInt64WithTruncation(value);
-
- /// <summary>
- /// void _mm_stream_si64(__int64 *p, __int64 a)
- /// MOVNTI m64, r64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static unsafe void StoreNonTemporal(long* address, long value) => StoreNonTemporal(address, value);
- /// <summary>
- /// void _mm_stream_si64(__int64 *p, __int64 a)
- /// MOVNTI m64, r64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static unsafe void StoreNonTemporal(ulong* address, ulong value) => StoreNonTemporal(address, value);
- }
-
- /// <summary>
- /// __m128i _mm_add_epi8 (__m128i a, __m128i b)
- /// PADDB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Add(Vector128<byte> left, Vector128<byte> right) => Add(left, right);
- /// <summary>
- /// __m128i _mm_add_epi8 (__m128i a, __m128i b)
- /// PADDB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Add(Vector128<sbyte> left, Vector128<sbyte> right) => Add(left, right);
- /// <summary>
- /// __m128i _mm_add_epi16 (__m128i a, __m128i b)
- /// PADDW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Add(Vector128<short> left, Vector128<short> right) => Add(left, right);
- /// <summary>
- /// __m128i _mm_add_epi16 (__m128i a, __m128i b)
- /// PADDW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Add(Vector128<ushort> left, Vector128<ushort> right) => Add(left, right);
- /// <summary>
- /// __m128i _mm_add_epi32 (__m128i a, __m128i b)
- /// PADDD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Add(Vector128<int> left, Vector128<int> right) => Add(left, right);
- /// <summary>
- /// __m128i _mm_add_epi32 (__m128i a, __m128i b)
- /// PADDD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Add(Vector128<uint> left, Vector128<uint> right) => Add(left, right);
- /// <summary>
- /// __m128i _mm_add_epi64 (__m128i a, __m128i b)
- /// PADDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> Add(Vector128<long> left, Vector128<long> right) => Add(left, right);
- /// <summary>
- /// __m128i _mm_add_epi64 (__m128i a, __m128i b)
- /// PADDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> Add(Vector128<ulong> left, Vector128<ulong> right) => Add(left, right);
- /// <summary>
- /// __m128d _mm_add_pd (__m128d a, __m128d b)
- /// ADDPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Add(Vector128<double> left, Vector128<double> right) => Add(left, right);
-
- /// <summary>
- /// __m128d _mm_add_sd (__m128d a, __m128d b)
- /// ADDSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> AddScalar(Vector128<double> left, Vector128<double> right) => AddScalar(left, right);
-
- /// <summary>
- /// __m128i _mm_adds_epi8 (__m128i a, __m128i b)
- /// PADDSB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> AddSaturate(Vector128<sbyte> left, Vector128<sbyte> right) => AddSaturate(left, right);
- /// <summary>
- /// __m128i _mm_adds_epu8 (__m128i a, __m128i b)
- /// PADDUSB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> AddSaturate(Vector128<byte> left, Vector128<byte> right) => AddSaturate(left, right);
- /// <summary>
- /// __m128i _mm_adds_epi16 (__m128i a, __m128i b)
- /// PADDSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> AddSaturate(Vector128<short> left, Vector128<short> right) => AddSaturate(left, right);
- /// <summary>
- /// __m128i _mm_adds_epu16 (__m128i a, __m128i b)
- /// PADDUSW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> AddSaturate(Vector128<ushort> left, Vector128<ushort> right) => AddSaturate(left, right);
-
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> And(Vector128<byte> left, Vector128<byte> right) => And(left, right);
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> And(Vector128<sbyte> left, Vector128<sbyte> right) => And(left, right);
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<short> And(Vector128<short> left, Vector128<short> right) => And(left, right);
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> And(Vector128<ushort> left, Vector128<ushort> right) => And(left, right);
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<int> And(Vector128<int> left, Vector128<int> right) => And(left, right);
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> And(Vector128<uint> left, Vector128<uint> right) => And(left, right);
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<long> And(Vector128<long> left, Vector128<long> right) => And(left, right);
- /// <summary>
- /// __m128i _mm_and_si128 (__m128i a, __m128i b)
- /// PAND xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> And(Vector128<ulong> left, Vector128<ulong> right) => And(left, right);
- /// <summary>
- /// __m128d _mm_and_pd (__m128d a, __m128d b)
- /// ANDPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> And(Vector128<double> left, Vector128<double> right) => And(left, right);
-
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> AndNot(Vector128<byte> left, Vector128<byte> right) => AndNot(left, right);
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> AndNot(Vector128<sbyte> left, Vector128<sbyte> right) => AndNot(left, right);
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<short> AndNot(Vector128<short> left, Vector128<short> right) => AndNot(left, right);
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> AndNot(Vector128<ushort> left, Vector128<ushort> right) => AndNot(left, right);
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<int> AndNot(Vector128<int> left, Vector128<int> right) => AndNot(left, right);
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> AndNot(Vector128<uint> left, Vector128<uint> right) => AndNot(left, right);
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<long> AndNot(Vector128<long> left, Vector128<long> right) => AndNot(left, right);
- /// <summary>
- /// __m128i _mm_andnot_si128 (__m128i a, __m128i b)
- /// PANDN xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> AndNot(Vector128<ulong> left, Vector128<ulong> right) => AndNot(left, right);
- /// <summary>
- /// __m128d _mm_andnot_pd (__m128d a, __m128d b)
- /// ADDNPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> AndNot(Vector128<double> left, Vector128<double> right) => AndNot(left, right);
-
- /// <summary>
- /// __m128i _mm_avg_epu8 (__m128i a, __m128i b)
- /// PAVGB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Average(Vector128<byte> left, Vector128<byte> right) => Average(left, right);
- /// <summary>
- /// __m128i _mm_avg_epu16 (__m128i a, __m128i b)
- /// PAVGW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Average(Vector128<ushort> left, Vector128<ushort> right) => Average(left, right);
-
- /// <summary>
- /// __m128i _mm_cmpeq_epi8 (__m128i a, __m128i b)
- /// PCMPEQB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> CompareEqual(Vector128<sbyte> left, Vector128<sbyte> right) => CompareEqual(left, right);
- /// <summary>
- /// __m128i _mm_cmpeq_epi8 (__m128i a, __m128i b)
- /// PCMPEQB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> CompareEqual(Vector128<byte> left, Vector128<byte> right) => CompareEqual(left, right);
- /// <summary>
- /// __m128i _mm_cmpeq_epi16 (__m128i a, __m128i b)
- /// PCMPEQW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> CompareEqual(Vector128<short> left, Vector128<short> right) => CompareEqual(left, right);
- /// <summary>
- /// __m128i _mm_cmpeq_epi16 (__m128i a, __m128i b)
- /// PCMPEQW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> CompareEqual(Vector128<ushort> left, Vector128<ushort> right) => CompareEqual(left, right);
- /// <summary>
- /// __m128i _mm_cmpeq_epi32 (__m128i a, __m128i b)
- /// PCMPEQD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> CompareEqual(Vector128<int> left, Vector128<int> right) => CompareEqual(left, right);
- /// <summary>
- /// __m128i _mm_cmpeq_epi32 (__m128i a, __m128i b)
- /// PCMPEQD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> CompareEqual(Vector128<uint> left, Vector128<uint> right) => CompareEqual(left, right);
- /// <summary>
- /// __m128d _mm_cmpeq_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(0)
- /// </summary>
- public static Vector128<double> CompareEqual(Vector128<double> left, Vector128<double> right) => CompareEqual(left, right);
-
- /// <summary>
- /// int _mm_comieq_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedEqual(Vector128<double> left, Vector128<double> right) => CompareScalarOrderedEqual(left, right);
-
- /// <summary>
- /// int _mm_ucomieq_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedEqual(Vector128<double> left, Vector128<double> right) => CompareScalarUnorderedEqual(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpeq_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(0)
- /// </summary>
- public static Vector128<double> CompareScalarEqual(Vector128<double> left, Vector128<double> right) => CompareScalarEqual(left, right);
-
- /// <summary>
- /// __m128i _mm_cmpgt_epi8 (__m128i a, __m128i b)
- /// PCMPGTB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> CompareGreaterThan(Vector128<sbyte> left, Vector128<sbyte> right) => CompareGreaterThan(left, right);
- /// <summary>
- /// __m128i _mm_cmpgt_epi16 (__m128i a, __m128i b)
- /// PCMPGTW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> CompareGreaterThan(Vector128<short> left, Vector128<short> right) => CompareGreaterThan(left, right);
- /// <summary>
- /// __m128i _mm_cmpgt_epi32 (__m128i a, __m128i b)
- /// PCMPGTD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> CompareGreaterThan(Vector128<int> left, Vector128<int> right) => CompareGreaterThan(left, right);
- /// <summary>
- /// __m128d _mm_cmpgt_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(6)
- /// </summary>
- public static Vector128<double> CompareGreaterThan(Vector128<double> left, Vector128<double> right) => CompareGreaterThan(left, right);
-
- /// <summary>
- /// int _mm_comigt_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedGreaterThan(Vector128<double> left, Vector128<double> right) => CompareScalarOrderedGreaterThan(left, right);
-
- /// <summary>
- /// int _mm_ucomigt_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedGreaterThan(Vector128<double> left, Vector128<double> right) => CompareScalarUnorderedGreaterThan(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpgt_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(6)
- /// </summary>
- public static Vector128<double> CompareScalarGreaterThan(Vector128<double> left, Vector128<double> right) => CompareScalarGreaterThan(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpge_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(5)
- /// </summary>
- public static Vector128<double> CompareGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// int _mm_comige_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareScalarOrderedGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// int _mm_ucomige_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareScalarUnorderedGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpge_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(5)
- /// </summary>
- public static Vector128<double> CompareScalarGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareScalarGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// __m128i _mm_cmplt_epi8 (__m128i a, __m128i b)
- /// PCMPGTB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> CompareLessThan(Vector128<sbyte> left, Vector128<sbyte> right) => CompareLessThan(left, right);
- /// <summary>
- /// __m128i _mm_cmplt_epi16 (__m128i a, __m128i b)
- /// PCMPGTW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> CompareLessThan(Vector128<short> left, Vector128<short> right) => CompareLessThan(left, right);
- /// <summary>
- /// __m128i _mm_cmplt_epi32 (__m128i a, __m128i b)
- /// PCMPGTD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> CompareLessThan(Vector128<int> left, Vector128<int> right) => CompareLessThan(left, right);
- /// <summary>
- /// __m128d _mm_cmplt_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(1)
- /// </summary>
- public static Vector128<double> CompareLessThan(Vector128<double> left, Vector128<double> right) => CompareLessThan(left, right);
-
- /// <summary>
- /// int _mm_comilt_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedLessThan(Vector128<double> left, Vector128<double> right) => CompareScalarOrderedLessThan(left, right);
-
- /// <summary>
- /// int _mm_ucomilt_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedLessThan(Vector128<double> left, Vector128<double> right) => CompareScalarUnorderedLessThan(left, right);
-
- /// <summary>
- /// __m128d _mm_cmplt_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(1)
- /// </summary>
- public static Vector128<double> CompareScalarLessThan(Vector128<double> left, Vector128<double> right) => CompareScalarLessThan(left, right);
-
- /// <summary>
- /// __m128d _mm_cmple_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(2)
- /// </summary>
- public static Vector128<double> CompareLessThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareLessThanOrEqual(left, right);
-
- /// <summary>
- /// int _mm_comile_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedLessThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareScalarOrderedLessThanOrEqual(left, right);
-
- /// <summary>
- /// int _mm_ucomile_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedLessThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareScalarUnorderedLessThanOrEqual(left, right);
-
- /// <summary>
- /// __m128d _mm_cmple_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(2)
- /// </summary>
- public static Vector128<double> CompareScalarLessThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareScalarLessThanOrEqual(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpneq_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<double> CompareNotEqual(Vector128<double> left, Vector128<double> right) => CompareNotEqual(left, right);
-
- /// <summary>
- /// int _mm_comineq_sd (__m128d a, __m128d b)
- /// COMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarOrderedNotEqual(Vector128<double> left, Vector128<double> right) => CompareScalarOrderedNotEqual(left, right);
-
- /// <summary>
- /// int _mm_ucomineq_sd (__m128d a, __m128d b)
- /// UCOMISD xmm, xmm/m64
- /// </summary>
- public static bool CompareScalarUnorderedNotEqual(Vector128<double> left, Vector128<double> right) => CompareScalarUnorderedNotEqual(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpneq_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(4)
- /// </summary>
- public static Vector128<double> CompareScalarNotEqual(Vector128<double> left, Vector128<double> right) => CompareScalarNotEqual(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpngt_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(2)
- /// </summary>
- public static Vector128<double> CompareNotGreaterThan(Vector128<double> left, Vector128<double> right) => CompareNotGreaterThan(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpngt_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(2)
- /// </summary>
- public static Vector128<double> CompareScalarNotGreaterThan(Vector128<double> left, Vector128<double> right) => CompareScalarNotGreaterThan(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpnge_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(1)
- /// </summary>
- public static Vector128<double> CompareNotGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareNotGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpnge_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(1)
- /// </summary>
- public static Vector128<double> CompareScalarNotGreaterThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareScalarNotGreaterThanOrEqual(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpnlt_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(5)
- /// </summary>
- public static Vector128<double> CompareNotLessThan(Vector128<double> left, Vector128<double> right) => CompareNotLessThan(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpnlt_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(5)
- /// </summary>
- public static Vector128<double> CompareScalarNotLessThan(Vector128<double> left, Vector128<double> right) => CompareScalarNotLessThan(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpnle_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(6)
- /// </summary>
- public static Vector128<double> CompareNotLessThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareNotLessThanOrEqual(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpnle_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(6)
- /// </summary>
- public static Vector128<double> CompareScalarNotLessThanOrEqual(Vector128<double> left, Vector128<double> right) => CompareScalarNotLessThanOrEqual(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpord_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(7)
- /// </summary>
- public static Vector128<double> CompareOrdered(Vector128<double> left, Vector128<double> right) => CompareOrdered(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpord_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(7)
- /// </summary>
- public static Vector128<double> CompareScalarOrdered(Vector128<double> left, Vector128<double> right) => CompareScalarOrdered(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpunord_pd (__m128d a, __m128d b)
- /// CMPPD xmm, xmm/m128, imm8(3)
- /// </summary>
- public static Vector128<double> CompareUnordered(Vector128<double> left, Vector128<double> right) => CompareUnordered(left, right);
-
- /// <summary>
- /// __m128d _mm_cmpunord_sd (__m128d a, __m128d b)
- /// CMPSD xmm, xmm/m64, imm8(3)
- /// </summary>
- public static Vector128<double> CompareScalarUnordered(Vector128<double> left, Vector128<double> right) => CompareScalarUnordered(left, right);
-
- /// <summary>
- /// __m128i _mm_cvtps_epi32 (__m128 a)
- /// CVTPS2DQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<float> value) => ConvertToVector128Int32(value);
- /// <summary>
- /// __m128i _mm_cvtpd_epi32 (__m128d a)
- /// CVTPD2DQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<double> value) => ConvertToVector128Int32(value);
- /// <summary>
- /// __m128 _mm_cvtepi32_ps (__m128i a)
- /// CVTDQ2PS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> ConvertToVector128Single(Vector128<int> value) => ConvertToVector128Single(value);
- /// <summary>
- /// __m128 _mm_cvtpd_ps (__m128d a)
- /// CVTPD2PS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> ConvertToVector128Single(Vector128<double> value) => ConvertToVector128Single(value);
- /// <summary>
- /// __m128d _mm_cvtepi32_pd (__m128i a)
- /// CVTDQ2PD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> ConvertToVector128Double(Vector128<int> value) => ConvertToVector128Double(value);
- /// <summary>
- /// __m128d _mm_cvtps_pd (__m128 a)
- /// CVTPS2PD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> ConvertToVector128Double(Vector128<float> value) => ConvertToVector128Double(value);
-
- /// <summary>
- /// int _mm_cvtsd_si32 (__m128d a)
- /// CVTSD2SI r32, xmm/m64
- /// </summary>
- public static int ConvertToInt32(Vector128<double> value) => ConvertToInt32(value);
- /// <summary>
- /// int _mm_cvtsi128_si32 (__m128i a)
- /// MOVD reg/m32, xmm
- /// </summary>
- public static int ConvertToInt32(Vector128<int> value) => ConvertToInt32(value);
-
- /// <summary>
- /// int _mm_cvtsi128_si32 (__m128i a)
- /// MOVD reg/m32, xmm
- /// </summary>
- public static uint ConvertToUInt32(Vector128<uint> value) => ConvertToUInt32(value);
-
- /// <summary>
- /// __m128d _mm_cvtsi32_sd (__m128d a, int b)
- /// CVTSI2SD xmm, reg/m32
- /// </summary>
- public static Vector128<double> ConvertScalarToVector128Double(Vector128<double> upper, int value) => ConvertScalarToVector128Double(upper, value);
-
- /// <summary>
- /// __m128d _mm_cvtss_sd (__m128d a, __m128 b)
- /// CVTSS2SD xmm, xmm/m32
- /// </summary>
- public static Vector128<double> ConvertScalarToVector128Double(Vector128<double> upper, Vector128<float> value) => ConvertScalarToVector128Double(upper, value);
-
- /// <summary>
- /// __m128i _mm_cvtsi32_si128 (int a)
- /// MOVD xmm, reg/m32
- /// </summary>
- public static Vector128<int> ConvertScalarToVector128Int32(int value) => ConvertScalarToVector128Int32(value);
-
- /// <summary>
- /// __m128 _mm_cvtsd_ss (__m128 a, __m128d b)
- /// CVTSD2SS xmm, xmm/m64
- /// </summary>
- public static Vector128<float> ConvertScalarToVector128Single(Vector128<float> upper, Vector128<double> value) => ConvertScalarToVector128Single(upper, value);
- /// <summary>
- /// __m128i _mm_cvtsi32_si128 (int a)
- /// MOVD xmm, reg/m32
- /// </summary>
- public static Vector128<uint> ConvertScalarToVector128UInt32(uint value) => ConvertScalarToVector128UInt32(value);
-
- /// <summary>
- /// __m128i _mm_cvttps_epi32 (__m128 a)
- /// CVTTPS2DQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32WithTruncation(Vector128<float> value) => ConvertToVector128Int32WithTruncation(value);
- /// <summary>
- /// __m128i _mm_cvttpd_epi32 (__m128d a)
- /// CVTTPD2DQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32WithTruncation(Vector128<double> value) => ConvertToVector128Int32WithTruncation(value);
-
- /// <summary>
- /// int _mm_cvttsd_si32 (__m128d a)
- /// CVTTSD2SI reg, xmm/m64
- /// </summary>
- public static int ConvertToInt32WithTruncation(Vector128<double> value) => ConvertToInt32WithTruncation(value);
-
- /// <summary>
- /// __m128d _mm_div_pd (__m128d a, __m128d b)
- /// DIVPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Divide(Vector128<double> left, Vector128<double> right) => Divide(left, right);
-
- /// <summary>
- /// __m128d _mm_div_sd (__m128d a, __m128d b)
- /// DIVSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> DivideScalar(Vector128<double> left, Vector128<double> right) => DivideScalar(left, right);
-
- /// <summary>
- /// int _mm_extract_epi16 (__m128i a, int immediate)
- /// PEXTRW reg, xmm, imm8
- /// </summary>
- public static ushort Extract(Vector128<ushort> value, byte index) => Extract(value, index);
-
- /// <summary>
- /// __m128i _mm_insert_epi16 (__m128i a, int i, int immediate)
- /// PINSRW xmm, reg/m16, imm8
- /// </summary>
- public static Vector128<short> Insert(Vector128<short> value, short data, byte index) => Insert(value, data, index);
- /// <summary>
- /// __m128i _mm_insert_epi16 (__m128i a, int i, int immediate)
- /// PINSRW xmm, reg/m16, imm8
- /// </summary>
- public static Vector128<ushort> Insert(Vector128<ushort> value, ushort data, byte index) => Insert(value, data, index);
-
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<sbyte> LoadVector128(sbyte* address) => LoadVector128(address);
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<byte> LoadVector128(byte* address) => LoadVector128(address);
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<short> LoadVector128(short* address) => LoadVector128(address);
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<ushort> LoadVector128(ushort* address) => LoadVector128(address);
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<int> LoadVector128(int* address) => LoadVector128(address);
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<uint> LoadVector128(uint* address) => LoadVector128(address);
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<long> LoadVector128(long* address) => LoadVector128(address);
- /// <summary>
- /// __m128i _mm_loadu_si128 (__m128i const* mem_address)
- /// MOVDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<ulong> LoadVector128(ulong* address) => LoadVector128(address);
- /// <summary>
- /// __m128d _mm_loadu_pd (double const* mem_address)
- /// MOVUPD xmm, m128
- /// </summary>
- public static unsafe Vector128<double> LoadVector128(double* address) => LoadVector128(address);
-
- /// <summary>
- /// __m128d _mm_load_sd (double const* mem_address)
- /// MOVSD xmm, m64
- /// </summary>
- public static unsafe Vector128<double> LoadScalarVector128(double* address) => LoadScalarVector128(address);
-
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<sbyte> LoadAlignedVector128(sbyte* address) => LoadAlignedVector128(address);
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<byte> LoadAlignedVector128(byte* address) => LoadAlignedVector128(address);
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<short> LoadAlignedVector128(short* address) => LoadAlignedVector128(address);
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<ushort> LoadAlignedVector128(ushort* address) => LoadAlignedVector128(address);
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<int> LoadAlignedVector128(int* address) => LoadAlignedVector128(address);
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<uint> LoadAlignedVector128(uint* address) => LoadAlignedVector128(address);
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<long> LoadAlignedVector128(long* address) => LoadAlignedVector128(address);
- /// <summary>
- /// __m128i _mm_load_si128 (__m128i const* mem_address)
- /// MOVDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<ulong> LoadAlignedVector128(ulong* address) => LoadAlignedVector128(address);
- /// <summary>
- /// __m128d _mm_load_pd (double const* mem_address)
- /// MOVAPD xmm, m128
- /// </summary>
- public static unsafe Vector128<double> LoadAlignedVector128(double* address) => LoadAlignedVector128(address);
-
- /// <summary>
- /// void _mm_lfence(void)
- /// LFENCE
- /// </summary>
- public static void LoadFence() => LoadFence();
-
- /// <summary>
- /// __m128d _mm_loadh_pd (__m128d a, double const* mem_addr)
- /// MOVHPD xmm, m64
- /// </summary>
- public static unsafe Vector128<double> LoadHigh(Vector128<double> lower, double* address) => LoadHigh(lower, address);
-
- /// <summary>
- /// __m128d _mm_loadl_pd (__m128d a, double const* mem_addr)
- /// MOVLPD xmm, m64
- /// </summary>
- public static unsafe Vector128<double> LoadLow(Vector128<double> upper, double* address) => LoadLow(upper, address);
-
- /// <summary>
- /// __m128i _mm_loadl_epi32 (__m128i const* mem_addr)
- /// MOVD xmm, reg/m32
- /// The above native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<int> LoadScalarVector128(int* address) => LoadScalarVector128(address);
- /// <summary>
- /// __m128i _mm_loadl_epi32 (__m128i const* mem_addr)
- /// MOVD xmm, reg/m32
- /// The above native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<uint> LoadScalarVector128(uint* address) => LoadScalarVector128(address);
- /// <summary>
- /// __m128i _mm_loadl_epi64 (__m128i const* mem_addr)
- /// MOVQ xmm, reg/m64
- /// </summary>
- public static unsafe Vector128<long> LoadScalarVector128(long* address) => LoadScalarVector128(address);
- /// <summary>
- /// __m128i _mm_loadl_epi64 (__m128i const* mem_addr)
- /// MOVQ xmm, reg/m64
- /// </summary>
- public static unsafe Vector128<ulong> LoadScalarVector128(ulong* address) => LoadScalarVector128(address);
-
- /// <summary>
- /// void _mm_maskmoveu_si128 (__m128i a, __m128i mask, char* mem_address)
- /// MASKMOVDQU xmm, xmm
- /// </summary>
- public static unsafe void MaskMove(Vector128<sbyte> source, Vector128<sbyte> mask, sbyte* address) => MaskMove(source, mask, address);
- /// <summary>
- /// void _mm_maskmoveu_si128 (__m128i a, __m128i mask, char* mem_address)
- /// MASKMOVDQU xmm, xmm
- /// </summary>
- public static unsafe void MaskMove(Vector128<byte> source, Vector128<byte> mask, byte* address) => MaskMove(source, mask, address);
-
- /// <summary>
- /// __m128i _mm_max_epu8 (__m128i a, __m128i b)
- /// PMAXUB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Max(Vector128<byte> left, Vector128<byte> right) => Max(left, right);
- /// <summary>
- /// __m128i _mm_max_epi16 (__m128i a, __m128i b)
- /// PMAXSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Max(Vector128<short> left, Vector128<short> right) => Max(left, right);
- /// <summary>
- /// __m128d _mm_max_pd (__m128d a, __m128d b)
- /// MAXPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Max(Vector128<double> left, Vector128<double> right) => Max(left, right);
-
- /// <summary>
- /// __m128d _mm_max_sd (__m128d a, __m128d b)
- /// MAXSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MaxScalar(Vector128<double> left, Vector128<double> right) => MaxScalar(left, right);
-
- /// <summary>
- /// void _mm_mfence(void)
- /// MFENCE
- /// </summary>
- public static void MemoryFence() => MemoryFence();
-
- /// <summary>
- /// __m128i _mm_min_epu8 (__m128i a, __m128i b)
- /// PMINUB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Min(Vector128<byte> left, Vector128<byte> right) => Min(left, right);
- /// <summary>
- /// __m128i _mm_min_epi16 (__m128i a, __m128i b)
- /// PMINSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Min(Vector128<short> left, Vector128<short> right) => Min(left, right);
- /// <summary>
- /// __m128d _mm_min_pd (__m128d a, __m128d b)
- /// MINPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Min(Vector128<double> left, Vector128<double> right) => Min(left, right);
-
- /// <summary>
- /// __m128d _mm_min_sd (__m128d a, __m128d b)
- /// MINSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MinScalar(Vector128<double> left, Vector128<double> right) => MinScalar(left, right);
-
- /// <summary>
- /// __m128d _mm_move_sd (__m128d a, __m128d b)
- /// MOVSD xmm, xmm
- /// </summary>
- public static Vector128<double> MoveScalar(Vector128<double> upper, Vector128<double> value) => MoveScalar(upper, value);
-
- /// <summary>
- /// int _mm_movemask_epi8 (__m128i a)
- /// PMOVMSKB reg, xmm
- /// </summary>
- public static int MoveMask(Vector128<sbyte> value) => MoveMask(value);
- /// <summary>
- /// int _mm_movemask_epi8 (__m128i a)
- /// PMOVMSKB reg, xmm
- /// </summary>
- public static int MoveMask(Vector128<byte> value) => MoveMask(value);
- /// <summary>
- /// int _mm_movemask_pd (__m128d a)
- /// MOVMSKPD reg, xmm
- /// </summary>
- public static int MoveMask(Vector128<double> value) => MoveMask(value);
-
- /// <summary>
- /// __m128i _mm_move_epi64 (__m128i a)
- /// MOVQ xmm, xmm
- /// </summary>
- public static Vector128<long> MoveScalar(Vector128<long> value) => MoveScalar(value);
- /// <summary>
- /// __m128i _mm_move_epi64 (__m128i a)
- /// MOVQ xmm, xmm
- /// </summary>
- public static Vector128<ulong> MoveScalar(Vector128<ulong> value) => MoveScalar(value);
-
- /// <summary>
- /// __m128i _mm_mul_epu32 (__m128i a, __m128i b)
- /// PMULUDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> Multiply(Vector128<uint> left, Vector128<uint> right) => Multiply(left, right);
- /// <summary>
- /// __m128d _mm_mul_pd (__m128d a, __m128d b)
- /// MULPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Multiply(Vector128<double> left, Vector128<double> right) => Multiply(left, right);
-
- /// <summary>
- /// __m128d _mm_mul_sd (__m128d a, __m128d b)
- /// MULSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MultiplyScalar(Vector128<double> left, Vector128<double> right) => MultiplyScalar(left, right);
-
- /// <summary>
- /// __m128i _mm_mulhi_epi16 (__m128i a, __m128i b)
- /// PMULHW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> MultiplyHigh(Vector128<short> left, Vector128<short> right) => MultiplyHigh(left, right);
- /// <summary>
- /// __m128i _mm_mulhi_epu16 (__m128i a, __m128i b)
- /// PMULHUW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> MultiplyHigh(Vector128<ushort> left, Vector128<ushort> right) => MultiplyHigh(left, right);
-
- /// <summary>
- /// __m128i _mm_madd_epi16 (__m128i a, __m128i b)
- /// PMADDWD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> MultiplyAddAdjacent(Vector128<short> left, Vector128<short> right) => MultiplyAddAdjacent(left, right);
-
- /// <summary>
- /// __m128i _mm_mullo_epi16 (__m128i a, __m128i b)
- /// PMULLW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> MultiplyLow(Vector128<short> left, Vector128<short> right) => MultiplyLow(left, right);
- /// <summary>
- /// __m128i _mm_mullo_epi16 (__m128i a, __m128i b)
- /// PMULLW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> MultiplyLow(Vector128<ushort> left, Vector128<ushort> right) => MultiplyLow(left, right);
-
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Or(Vector128<byte> left, Vector128<byte> right) => Or(left, right);
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Or(Vector128<sbyte> left, Vector128<sbyte> right) => Or(left, right);
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Or(Vector128<short> left, Vector128<short> right) => Or(left, right);
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Or(Vector128<ushort> left, Vector128<ushort> right) => Or(left, right);
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Or(Vector128<int> left, Vector128<int> right) => Or(left, right);
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Or(Vector128<uint> left, Vector128<uint> right) => Or(left, right);
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<long> Or(Vector128<long> left, Vector128<long> right) => Or(left, right);
- /// <summary>
- /// __m128i _mm_or_si128 (__m128i a, __m128i b)
- /// POR xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> Or(Vector128<ulong> left, Vector128<ulong> right) => Or(left, right);
- /// <summary>
- /// __m128d _mm_or_pd (__m128d a, __m128d b)
- /// ORPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Or(Vector128<double> left, Vector128<double> right) => Or(left, right);
-
- /// <summary>
- /// __m128i _mm_packs_epi16 (__m128i a, __m128i b)
- /// PACKSSWB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> PackSignedSaturate(Vector128<short> left, Vector128<short> right) => PackSignedSaturate(left, right);
- /// <summary>
- /// __m128i _mm_packs_epi32 (__m128i a, __m128i b)
- /// PACKSSDW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> PackSignedSaturate(Vector128<int> left, Vector128<int> right) => PackSignedSaturate(left, right);
-
- /// <summary>
- /// __m128i _mm_packus_epi16 (__m128i a, __m128i b)
- /// PACKUSWB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> PackUnsignedSaturate(Vector128<short> left, Vector128<short> right) => PackUnsignedSaturate(left, right);
-
- /// <summary>
- /// __m128i _mm_sad_epu8 (__m128i a, __m128i b)
- /// PSADBW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> SumAbsoluteDifferences(Vector128<byte> left, Vector128<byte> right) => SumAbsoluteDifferences(left, right);
-
- /// <summary>
- /// __m128i _mm_shuffle_epi32 (__m128i a, int immediate)
- /// PSHUFD xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<int> Shuffle(Vector128<int> value, byte control) => Shuffle(value, control);
- /// <summary>
- /// __m128i _mm_shuffle_epi32 (__m128i a, int immediate)
- /// PSHUFD xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<uint> Shuffle(Vector128<uint> value, byte control) => Shuffle(value, control);
- /// <summary>
- /// __m128d _mm_shuffle_pd (__m128d a, __m128d b, int immediate)
- /// SHUFPD xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<double> Shuffle(Vector128<double> left, Vector128<double> right, byte control) => Shuffle(left, right, control);
-
- /// <summary>
- /// __m128i _mm_shufflehi_epi16 (__m128i a, int immediate)
- /// PSHUFHW xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<short> ShuffleHigh(Vector128<short> value, byte control) => ShuffleHigh(value, control);
- /// <summary>
- /// __m128i _mm_shufflehi_epi16 (__m128i a, int control)
- /// PSHUFHW xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<ushort> ShuffleHigh(Vector128<ushort> value, byte control) => ShuffleHigh(value, control);
-
- /// <summary>
- /// __m128i _mm_shufflelo_epi16 (__m128i a, int control)
- /// PSHUFLW xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<short> ShuffleLow(Vector128<short> value, byte control) => ShuffleLow(value, control);
- /// <summary>
- /// __m128i _mm_shufflelo_epi16 (__m128i a, int control)
- /// PSHUFLW xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<ushort> ShuffleLow(Vector128<ushort> value, byte control) => ShuffleLow(value, control);
-
- /// <summary>
- /// __m128i _mm_sll_epi16 (__m128i a, __m128i count)
- /// PSLLW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> ShiftLeftLogical(Vector128<short> value, Vector128<short> count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m128i _mm_sll_epi16 (__m128i a, __m128i count)
- /// PSLLW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> ShiftLeftLogical(Vector128<ushort> value, Vector128<ushort> count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m128i _mm_sll_epi32 (__m128i a, __m128i count)
- /// PSLLD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftLeftLogical(Vector128<int> value, Vector128<int> count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m128i _mm_sll_epi32 (__m128i a, __m128i count)
- /// PSLLD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> ShiftLeftLogical(Vector128<uint> value, Vector128<uint> count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m128i _mm_sll_epi64 (__m128i a, __m128i count)
- /// PSLLQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> ShiftLeftLogical(Vector128<long> value, Vector128<long> count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m128i _mm_sll_epi64 (__m128i a, __m128i count)
- /// PSLLQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> ShiftLeftLogical(Vector128<ulong> value, Vector128<ulong> count) => ShiftLeftLogical(value, count);
-
- /// <summary>
- /// __m128i _mm_slli_epi16 (__m128i a, int immediate)
- /// PSLLW xmm, imm8
- /// </summary>
- public static Vector128<short> ShiftLeftLogical(Vector128<short> value, byte count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m128i _mm_slli_epi16 (__m128i a, int immediate)
- /// PSLLW xmm, imm8
- /// </summary>
- public static Vector128<ushort> ShiftLeftLogical(Vector128<ushort> value, byte count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m128i _mm_slli_epi32 (__m128i a, int immediate)
- /// PSLLD xmm, imm8
- /// </summary>
- public static Vector128<int> ShiftLeftLogical(Vector128<int> value, byte count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m128i _mm_slli_epi32 (__m128i a, int immediate)
- /// PSLLD xmm, imm8
- /// </summary>
- public static Vector128<uint> ShiftLeftLogical(Vector128<uint> value, byte count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m128i _mm_slli_epi64 (__m128i a, int immediate)
- /// PSLLQ xmm, imm8
- /// </summary>
- public static Vector128<long> ShiftLeftLogical(Vector128<long> value, byte count) => ShiftLeftLogical(value, count);
- /// <summary>
- /// __m128i _mm_slli_epi64 (__m128i a, int immediate)
- /// PSLLQ xmm, imm8
- /// </summary>
- public static Vector128<ulong> ShiftLeftLogical(Vector128<ulong> value, byte count) => ShiftLeftLogical(value, count);
-
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<sbyte> ShiftLeftLogical128BitLane(Vector128<sbyte> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<byte> ShiftLeftLogical128BitLane(Vector128<byte> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<short> ShiftLeftLogical128BitLane(Vector128<short> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<ushort> ShiftLeftLogical128BitLane(Vector128<ushort> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<int> ShiftLeftLogical128BitLane(Vector128<int> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<uint> ShiftLeftLogical128BitLane(Vector128<uint> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<long> ShiftLeftLogical128BitLane(Vector128<long> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bslli_si128 (__m128i a, int imm8)
- /// PSLLDQ xmm, imm8
- /// </summary>
- public static Vector128<ulong> ShiftLeftLogical128BitLane(Vector128<ulong> value, byte numBytes) => ShiftLeftLogical128BitLane(value, numBytes);
-
- /// <summary>
- /// __m128i _mm_sra_epi16 (__m128i a, __m128i count)
- /// PSRAW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> ShiftRightArithmetic(Vector128<short> value, Vector128<short> count) => ShiftRightArithmetic(value, count);
- /// <summary>
- /// __m128i _mm_sra_epi32 (__m128i a, __m128i count)
- /// PSRAD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftRightArithmetic(Vector128<int> value, Vector128<int> count) => ShiftRightArithmetic(value, count);
-
- /// <summary>
- /// __m128i _mm_srai_epi16 (__m128i a, int immediate)
- /// PSRAW xmm, imm8
- /// </summary>
- public static Vector128<short> ShiftRightArithmetic(Vector128<short> value, byte count) => ShiftRightArithmetic(value, count);
- /// <summary>
- /// __m128i _mm_srai_epi32 (__m128i a, int immediate)
- /// PSRAD xmm, imm8
- /// </summary>
- public static Vector128<int> ShiftRightArithmetic(Vector128<int> value, byte count) => ShiftRightArithmetic(value, count);
-
- /// <summary>
- /// __m128i _mm_srl_epi16 (__m128i a, __m128i count)
- /// PSRLW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> ShiftRightLogical(Vector128<short> value, Vector128<short> count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m128i _mm_srl_epi16 (__m128i a, __m128i count)
- /// PSRLW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> ShiftRightLogical(Vector128<ushort> value, Vector128<ushort> count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m128i _mm_srl_epi32 (__m128i a, __m128i count)
- /// PSRLD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> ShiftRightLogical(Vector128<int> value, Vector128<int> count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m128i _mm_srl_epi32 (__m128i a, __m128i count)
- /// PSRLD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> ShiftRightLogical(Vector128<uint> value, Vector128<uint> count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m128i _mm_srl_epi64 (__m128i a, __m128i count)
- /// PSRLQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> ShiftRightLogical(Vector128<long> value, Vector128<long> count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m128i _mm_srl_epi64 (__m128i a, __m128i count)
- /// PSRLQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> ShiftRightLogical(Vector128<ulong> value, Vector128<ulong> count) => ShiftRightLogical(value, count);
-
- /// <summary>
- /// __m128i _mm_srli_epi16 (__m128i a, int immediate)
- /// PSRLW xmm, imm8
- /// </summary>
- public static Vector128<short> ShiftRightLogical(Vector128<short> value, byte count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m128i _mm_srli_epi16 (__m128i a, int immediate)
- /// PSRLW xmm, imm8
- /// </summary>
- public static Vector128<ushort> ShiftRightLogical(Vector128<ushort> value, byte count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m128i _mm_srli_epi32 (__m128i a, int immediate)
- /// PSRLD xmm, imm8
- /// </summary>
- public static Vector128<int> ShiftRightLogical(Vector128<int> value, byte count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m128i _mm_srli_epi32 (__m128i a, int immediate)
- /// PSRLD xmm, imm8
- /// </summary>
- public static Vector128<uint> ShiftRightLogical(Vector128<uint> value, byte count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m128i _mm_srli_epi64 (__m128i a, int immediate)
- /// PSRLQ xmm, imm8
- /// </summary>
- public static Vector128<long> ShiftRightLogical(Vector128<long> value, byte count) => ShiftRightLogical(value, count);
- /// <summary>
- /// __m128i _mm_srli_epi64 (__m128i a, int immediate)
- /// PSRLQ xmm, imm8
- /// </summary>
- public static Vector128<ulong> ShiftRightLogical(Vector128<ulong> value, byte count) => ShiftRightLogical(value, count);
-
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<sbyte> ShiftRightLogical128BitLane(Vector128<sbyte> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<byte> ShiftRightLogical128BitLane(Vector128<byte> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<short> ShiftRightLogical128BitLane(Vector128<short> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<ushort> ShiftRightLogical128BitLane(Vector128<ushort> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<int> ShiftRightLogical128BitLane(Vector128<int> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<uint> ShiftRightLogical128BitLane(Vector128<uint> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<long> ShiftRightLogical128BitLane(Vector128<long> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
- /// <summary>
- /// __m128i _mm_bsrli_si128 (__m128i a, int imm8)
- /// PSRLDQ xmm, imm8
- /// </summary>
- public static Vector128<ulong> ShiftRightLogical128BitLane(Vector128<ulong> value, byte numBytes) => ShiftRightLogical128BitLane(value, numBytes);
-
- /// <summary>
- /// __m128d _mm_sqrt_pd (__m128d a)
- /// SQRTPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Sqrt(Vector128<double> value) => Sqrt(value);
-
- /// <summary>
- /// __m128d _mm_sqrt_sd (__m128d a)
- /// SQRTSD xmm, xmm/64
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> SqrtScalar(Vector128<double> value) => SqrtScalar(value);
-
- /// <summary>
- /// __m128d _mm_sqrt_sd (__m128d a, __m128d b)
- /// SQRTSD xmm, xmm/64
- /// </summary>
- public static Vector128<double> SqrtScalar(Vector128<double> upper, Vector128<double> value) => SqrtScalar(upper, value);
-
- /// <summary>
- /// void _mm_store_sd (double* mem_addr, __m128d a)
- /// MOVSD m64, xmm
- /// </summary>
- public static unsafe void StoreScalar(double* address, Vector128<double> source) => StoreScalar(address, source);
- /// <summary>
- /// void _mm_storel_epi64 (__m128i* mem_addr, __m128i a)
- /// MOVQ m64, xmm
- /// </summary>
- public static unsafe void StoreScalar(long* address, Vector128<long> source) => StoreScalar(address, source);
- /// <summary>
- /// void _mm_storel_epi64 (__m128i* mem_addr, __m128i a)
- /// MOVQ m64, xmm
- /// </summary>
- public static unsafe void StoreScalar(ulong* address, Vector128<ulong> source) => StoreScalar(address, source);
-
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(sbyte* address, Vector128<sbyte> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(byte* address, Vector128<byte> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(short* address, Vector128<short> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(ushort* address, Vector128<ushort> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(int* address, Vector128<int> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(uint* address, Vector128<uint> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(long* address, Vector128<long> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm_store_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQA m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(ulong* address, Vector128<ulong> source) => StoreAligned(address, source);
- /// <summary>
- /// void _mm_store_pd (double* mem_addr, __m128d a)
- /// MOVAPD m128, xmm
- /// </summary>
- public static unsafe void StoreAligned(double* address, Vector128<double> source) => StoreAligned(address, source);
-
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(sbyte* address, Vector128<sbyte> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(byte* address, Vector128<byte> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(short* address, Vector128<short> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(ushort* address, Vector128<ushort> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(int* address, Vector128<int> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(uint* address, Vector128<uint> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(long* address, Vector128<long> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
- /// MOVNTDQ m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(ulong* address, Vector128<ulong> source) => StoreAlignedNonTemporal(address, source);
- /// <summary>
- /// void _mm_stream_pd (double* mem_addr, __m128d a)
- /// MOVNTPD m128, xmm
- /// </summary>
- public static unsafe void StoreAlignedNonTemporal(double* address, Vector128<double> source) => StoreAlignedNonTemporal(address, source);
-
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(sbyte* address, Vector128<sbyte> source) => Store(address, source);
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(byte* address, Vector128<byte> source) => Store(address, source);
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(short* address, Vector128<short> source) => Store(address, source);
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(ushort* address, Vector128<ushort> source) => Store(address, source);
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(int* address, Vector128<int> source) => Store(address, source);
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(uint* address, Vector128<uint> source) => Store(address, source);
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(long* address, Vector128<long> source) => Store(address, source);
- /// <summary>
- /// void _mm_storeu_si128 (__m128i* mem_addr, __m128i a)
- /// MOVDQU m128, xmm
- /// </summary>
- public static unsafe void Store(ulong* address, Vector128<ulong> source) => Store(address, source);
- /// <summary>
- /// void _mm_storeu_pd (double* mem_addr, __m128d a)
- /// MOVUPD m128, xmm
- /// </summary>
- public static unsafe void Store(double* address, Vector128<double> source) => Store(address, source);
-
- /// <summary>
- /// void _mm_storeh_pd (double* mem_addr, __m128d a)
- /// MOVHPD m64, xmm
- /// </summary>
- public static unsafe void StoreHigh(double* address, Vector128<double> source) => StoreHigh(address, source);
-
- /// <summary>
- /// void _mm_storel_pd (double* mem_addr, __m128d a)
- /// MOVLPD m64, xmm
- /// </summary>
- public static unsafe void StoreLow(double* address, Vector128<double> source) => StoreLow(address, source);
-
- /// <summary>
- /// void _mm_stream_si32(int *p, int a)
- /// MOVNTI m32, r32
- /// </summary>
- public static unsafe void StoreNonTemporal(int* address, int value) => StoreNonTemporal(address, value);
- /// <summary>
- /// void _mm_stream_si32(int *p, int a)
- /// MOVNTI m32, r32
- /// </summary>
- public static unsafe void StoreNonTemporal(uint* address, uint value) => StoreNonTemporal(address, value);
-
- /// <summary>
- /// __m128i _mm_sub_epi8 (__m128i a, __m128i b)
- /// PSUBB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Subtract(Vector128<byte> left, Vector128<byte> right) => Subtract(left, right);
- /// <summary>
- /// __m128i _mm_sub_epi8 (__m128i a, __m128i b)
- /// PSUBB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Subtract(Vector128<sbyte> left, Vector128<sbyte> right) => Subtract(left, right);
- /// <summary>
- /// __m128i _mm_sub_epi16 (__m128i a, __m128i b)
- /// PSUBW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Subtract(Vector128<short> left, Vector128<short> right) => Subtract(left, right);
- /// <summary>
- /// __m128i _mm_sub_epi16 (__m128i a, __m128i b)
- /// PSUBW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Subtract(Vector128<ushort> left, Vector128<ushort> right) => Subtract(left, right);
- /// <summary>
- /// __m128i _mm_sub_epi32 (__m128i a, __m128i b)
- /// PSUBD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Subtract(Vector128<int> left, Vector128<int> right) => Subtract(left, right);
- /// <summary>
- /// __m128i _mm_sub_epi32 (__m128i a, __m128i b)
- /// PSUBD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Subtract(Vector128<uint> left, Vector128<uint> right) => Subtract(left, right);
- /// <summary>
- /// __m128i _mm_sub_epi64 (__m128i a, __m128i b)
- /// PSUBQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> Subtract(Vector128<long> left, Vector128<long> right) => Subtract(left, right);
- /// <summary>
- /// __m128i _mm_sub_epi64 (__m128i a, __m128i b)
- /// PSUBQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> Subtract(Vector128<ulong> left, Vector128<ulong> right) => Subtract(left, right);
- /// <summary>
- /// __m128d _mm_sub_pd (__m128d a, __m128d b)
- /// SUBPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Subtract(Vector128<double> left, Vector128<double> right) => Subtract(left, right);
-
- /// <summary>
- /// __m128d _mm_sub_sd (__m128d a, __m128d b)
- /// SUBSD xmm, xmm/m64
- /// </summary>
- public static Vector128<double> SubtractScalar(Vector128<double> left, Vector128<double> right) => SubtractScalar(left, right);
-
- /// <summary>
- /// __m128i _mm_subs_epi8 (__m128i a, __m128i b)
- /// PSUBSB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> SubtractSaturate(Vector128<sbyte> left, Vector128<sbyte> right) => SubtractSaturate(left, right);
- /// <summary>
- /// __m128i _mm_subs_epi16 (__m128i a, __m128i b)
- /// PSUBSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> SubtractSaturate(Vector128<short> left, Vector128<short> right) => SubtractSaturate(left, right);
- /// <summary>
- /// __m128i _mm_subs_epu8 (__m128i a, __m128i b)
- /// PSUBUSB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> SubtractSaturate(Vector128<byte> left, Vector128<byte> right) => SubtractSaturate(left, right);
- /// <summary>
- /// __m128i _mm_subs_epu16 (__m128i a, __m128i b)
- /// PSUBUSW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> SubtractSaturate(Vector128<ushort> left, Vector128<ushort> right) => SubtractSaturate(left, right);
-
- /// <summary>
- /// __m128i _mm_unpackhi_epi8 (__m128i a, __m128i b)
- /// PUNPCKHBW xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> UnpackHigh(Vector128<byte> left, Vector128<byte> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m128i _mm_unpackhi_epi8 (__m128i a, __m128i b)
- /// PUNPCKHBW xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> UnpackHigh(Vector128<sbyte> left, Vector128<sbyte> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m128i _mm_unpackhi_epi16 (__m128i a, __m128i b)
- /// PUNPCKHWD xmm, xmm/m128
- /// </summary>
- public static Vector128<short> UnpackHigh(Vector128<short> left, Vector128<short> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m128i _mm_unpackhi_epi16 (__m128i a, __m128i b)
- /// PUNPCKHWD xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> UnpackHigh(Vector128<ushort> left, Vector128<ushort> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m128i _mm_unpackhi_epi32 (__m128i a, __m128i b)
- /// PUNPCKHDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> UnpackHigh(Vector128<int> left, Vector128<int> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m128i _mm_unpackhi_epi32 (__m128i a, __m128i b)
- /// PUNPCKHDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> UnpackHigh(Vector128<uint> left, Vector128<uint> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m128i _mm_unpackhi_epi64 (__m128i a, __m128i b)
- /// PUNPCKHQDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> UnpackHigh(Vector128<long> left, Vector128<long> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m128i _mm_unpackhi_epi64 (__m128i a, __m128i b)
- /// PUNPCKHQDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> UnpackHigh(Vector128<ulong> left, Vector128<ulong> right) => UnpackHigh(left, right);
- /// <summary>
- /// __m128d _mm_unpackhi_pd (__m128d a, __m128d b)
- /// UNPCKHPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> UnpackHigh(Vector128<double> left, Vector128<double> right) => UnpackHigh(left, right);
-
- /// <summary>
- /// __m128i _mm_unpacklo_epi8 (__m128i a, __m128i b)
- /// PUNPCKLBW xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> UnpackLow(Vector128<byte> left, Vector128<byte> right) => UnpackLow(left, right);
- /// <summary>
- /// __m128i _mm_unpacklo_epi8 (__m128i a, __m128i b)
- /// PUNPCKLBW xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> UnpackLow(Vector128<sbyte> left, Vector128<sbyte> right) => UnpackLow(left, right);
- /// <summary>
- /// __m128i _mm_unpacklo_epi16 (__m128i a, __m128i b)
- /// PUNPCKLWD xmm, xmm/m128
- /// </summary>
- public static Vector128<short> UnpackLow(Vector128<short> left, Vector128<short> right) => UnpackLow(left, right);
- /// <summary>
- /// __m128i _mm_unpacklo_epi16 (__m128i a, __m128i b)
- /// PUNPCKLWD xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> UnpackLow(Vector128<ushort> left, Vector128<ushort> right) => UnpackLow(left, right);
- /// <summary>
- /// __m128i _mm_unpacklo_epi32 (__m128i a, __m128i b)
- /// PUNPCKLDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<int> UnpackLow(Vector128<int> left, Vector128<int> right) => UnpackLow(left, right);
- /// <summary>
- /// __m128i _mm_unpacklo_epi32 (__m128i a, __m128i b)
- /// PUNPCKLDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> UnpackLow(Vector128<uint> left, Vector128<uint> right) => UnpackLow(left, right);
- /// <summary>
- /// __m128i _mm_unpacklo_epi64 (__m128i a, __m128i b)
- /// PUNPCKLQDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> UnpackLow(Vector128<long> left, Vector128<long> right) => UnpackLow(left, right);
- /// <summary>
- /// __m128i _mm_unpacklo_epi64 (__m128i a, __m128i b)
- /// PUNPCKLQDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> UnpackLow(Vector128<ulong> left, Vector128<ulong> right) => UnpackLow(left, right);
- /// <summary>
- /// __m128d _mm_unpacklo_pd (__m128d a, __m128d b)
- /// UNPCKLPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> UnpackLow(Vector128<double> left, Vector128<double> right) => UnpackLow(left, right);
-
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Xor(Vector128<byte> left, Vector128<byte> right) => Xor(left, right);
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Xor(Vector128<sbyte> left, Vector128<sbyte> right) => Xor(left, right);
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Xor(Vector128<short> left, Vector128<short> right) => Xor(left, right);
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Xor(Vector128<ushort> left, Vector128<ushort> right) => Xor(left, right);
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Xor(Vector128<int> left, Vector128<int> right) => Xor(left, right);
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Xor(Vector128<uint> left, Vector128<uint> right) => Xor(left, right);
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<long> Xor(Vector128<long> left, Vector128<long> right) => Xor(left, right);
- /// <summary>
- /// __m128i _mm_xor_si128 (__m128i a, __m128i b)
- /// PXOR xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> Xor(Vector128<ulong> left, Vector128<ulong> right) => Xor(left, right);
- /// <summary>
- /// __m128d _mm_xor_pd (__m128d a, __m128d b)
- /// XORPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> Xor(Vector128<double> left, Vector128<double> right) => Xor(left, right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse3.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse3.PlatformNotSupported.cs
deleted file mode 100644
index 8e238c232b7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse3.PlatformNotSupported.cs
+++ /dev/null
@@ -1,92 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSE3 hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Sse3 : Sse2
- {
- internal Sse3() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// __m128 _mm_addsub_ps (__m128 a, __m128 b)
- /// ADDSUBPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> AddSubtract(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_addsub_pd (__m128d a, __m128d b)
- /// ADDSUBPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> AddSubtract(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_hadd_ps (__m128 a, __m128 b)
- /// HADDPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> HorizontalAdd(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_hadd_pd (__m128d a, __m128d b)
- /// HADDPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> HorizontalAdd(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_hsub_ps (__m128 a, __m128 b)
- /// HSUBPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> HorizontalSubtract(Vector128<float> left, Vector128<float> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_hsub_pd (__m128d a, __m128d b)
- /// HSUBPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> HorizontalSubtract(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_loaddup_pd (double const* mem_addr)
- /// MOVDDUP xmm, m64
- /// </summary>
- public static unsafe Vector128<double> LoadAndDuplicateToVector128(double* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_lddqu_si128 (__m128i const* mem_addr)
- /// LDDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<sbyte> LoadDquVector128(sbyte* address) { throw new PlatformNotSupportedException(); }
- public static unsafe Vector128<byte> LoadDquVector128(byte* address) { throw new PlatformNotSupportedException(); }
- public static unsafe Vector128<short> LoadDquVector128(short* address) { throw new PlatformNotSupportedException(); }
- public static unsafe Vector128<ushort> LoadDquVector128(ushort* address) { throw new PlatformNotSupportedException(); }
- public static unsafe Vector128<int> LoadDquVector128(int* address) { throw new PlatformNotSupportedException(); }
- public static unsafe Vector128<uint> LoadDquVector128(uint* address) { throw new PlatformNotSupportedException(); }
- public static unsafe Vector128<long> LoadDquVector128(long* address) { throw new PlatformNotSupportedException(); }
- public static unsafe Vector128<ulong> LoadDquVector128(ulong* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_movedup_pd (__m128d a)
- /// MOVDDUP xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MoveAndDuplicate(Vector128<double> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_movehdup_ps (__m128 a)
- /// MOVSHDUP xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MoveHighAndDuplicate(Vector128<float> source) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_moveldup_ps (__m128 a)
- /// MOVSLDUP xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MoveLowAndDuplicate(Vector128<float> source) { throw new PlatformNotSupportedException(); }
-
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse3.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse3.cs
deleted file mode 100644
index f8e10e17e3c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse3.cs
+++ /dev/null
@@ -1,90 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSE3 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Sse3 : Sse2
- {
- internal Sse3() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// __m128 _mm_addsub_ps (__m128 a, __m128 b)
- /// ADDSUBPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> AddSubtract(Vector128<float> left, Vector128<float> right) => AddSubtract(left, right);
- /// <summary>
- /// __m128d _mm_addsub_pd (__m128d a, __m128d b)
- /// ADDSUBPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> AddSubtract(Vector128<double> left, Vector128<double> right) => AddSubtract(left, right);
-
- /// <summary>
- /// __m128 _mm_hadd_ps (__m128 a, __m128 b)
- /// HADDPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> HorizontalAdd(Vector128<float> left, Vector128<float> right) => HorizontalAdd(left, right);
- /// <summary>
- /// __m128d _mm_hadd_pd (__m128d a, __m128d b)
- /// HADDPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> HorizontalAdd(Vector128<double> left, Vector128<double> right) => HorizontalAdd(left, right);
-
- /// <summary>
- /// __m128 _mm_hsub_ps (__m128 a, __m128 b)
- /// HSUBPS xmm, xmm/m128
- /// </summary>
- public static Vector128<float> HorizontalSubtract(Vector128<float> left, Vector128<float> right) => HorizontalSubtract(left, right);
- /// <summary>
- /// __m128d _mm_hsub_pd (__m128d a, __m128d b)
- /// HSUBPD xmm, xmm/m128
- /// </summary>
- public static Vector128<double> HorizontalSubtract(Vector128<double> left, Vector128<double> right) => HorizontalSubtract(left, right);
-
- /// <summary>
- /// __m128d _mm_loaddup_pd (double const* mem_addr)
- /// MOVDDUP xmm, m64
- /// </summary>
- public static unsafe Vector128<double> LoadAndDuplicateToVector128(double* address) => LoadAndDuplicateToVector128(address);
-
- /// <summary>
- /// __m128i _mm_lddqu_si128 (__m128i const* mem_addr)
- /// LDDQU xmm, m128
- /// </summary>
- public static unsafe Vector128<sbyte> LoadDquVector128(sbyte* address) => LoadDquVector128(address);
- public static unsafe Vector128<byte> LoadDquVector128(byte* address) => LoadDquVector128(address);
- public static unsafe Vector128<short> LoadDquVector128(short* address) => LoadDquVector128(address);
- public static unsafe Vector128<ushort> LoadDquVector128(ushort* address) => LoadDquVector128(address);
- public static unsafe Vector128<int> LoadDquVector128(int* address) => LoadDquVector128(address);
- public static unsafe Vector128<uint> LoadDquVector128(uint* address) => LoadDquVector128(address);
- public static unsafe Vector128<long> LoadDquVector128(long* address) => LoadDquVector128(address);
- public static unsafe Vector128<ulong> LoadDquVector128(ulong* address) => LoadDquVector128(address);
-
- /// <summary>
- /// __m128d _mm_movedup_pd (__m128d a)
- /// MOVDDUP xmm, xmm/m64
- /// </summary>
- public static Vector128<double> MoveAndDuplicate(Vector128<double> source) => MoveAndDuplicate(source);
-
- /// <summary>
- /// __m128 _mm_movehdup_ps (__m128 a)
- /// MOVSHDUP xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MoveHighAndDuplicate(Vector128<float> source) => MoveHighAndDuplicate(source);
-
- /// <summary>
- /// __m128 _mm_moveldup_ps (__m128 a)
- /// MOVSLDUP xmm, xmm/m128
- /// </summary>
- public static Vector128<float> MoveLowAndDuplicate(Vector128<float> source) => MoveLowAndDuplicate(source);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse41.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse41.PlatformNotSupported.cs
deleted file mode 100644
index c992e9bebc2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse41.PlatformNotSupported.cs
+++ /dev/null
@@ -1,713 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSE4.1 hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Sse41 : Ssse3
- {
- internal Sse41() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- public new abstract class X64 : Sse2.X64
- {
- internal X64() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// __int64 _mm_extract_epi64 (__m128i a, const int imm8)
- /// PEXTRQ reg/m64, xmm, imm8
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long Extract(Vector128<long> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __int64 _mm_extract_epi64 (__m128i a, const int imm8)
- /// PEXTRQ reg/m64, xmm, imm8
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong Extract(Vector128<ulong> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_insert_epi64 (__m128i a, __int64 i, const int imm8)
- /// PINSRQ xmm, reg/m64, imm8
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<long> Insert(Vector128<long> value, long data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_insert_epi64 (__m128i a, __int64 i, const int imm8)
- /// PINSRQ xmm, reg/m64, imm8
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<ulong> Insert(Vector128<ulong> value, ulong data, byte index) { throw new PlatformNotSupportedException(); }
- }
-
- /// <summary>
- /// __m128i _mm_blend_epi16 (__m128i a, __m128i b, const int imm8)
- /// PBLENDW xmm, xmm/m128 imm8
- /// </summary>
- public static Vector128<short> Blend(Vector128<short> left, Vector128<short> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_blend_epi16 (__m128i a, __m128i b, const int imm8)
- /// PBLENDW xmm, xmm/m128 imm8
- /// </summary>
- public static Vector128<ushort> Blend(Vector128<ushort> left, Vector128<ushort> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_blend_ps (__m128 a, __m128 b, const int imm8)
- /// BLENDPS xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<float> Blend(Vector128<float> left, Vector128<float> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_blend_pd (__m128d a, __m128d b, const int imm8)
- /// BLENDPD xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<double> Blend(Vector128<double> left, Vector128<double> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// </summary>
- public static Vector128<sbyte> BlendVariable(Vector128<sbyte> left, Vector128<sbyte> right, Vector128<sbyte> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// </summary>
- public static Vector128<byte> BlendVariable(Vector128<byte> left, Vector128<byte> right, Vector128<byte> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<short> BlendVariable(Vector128<short> left, Vector128<short> right, Vector128<short> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<ushort> BlendVariable(Vector128<ushort> left, Vector128<ushort> right, Vector128<ushort> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<int> BlendVariable(Vector128<int> left, Vector128<int> right, Vector128<int> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<uint> BlendVariable(Vector128<uint> left, Vector128<uint> right, Vector128<uint> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<long> BlendVariable(Vector128<long> left, Vector128<long> right, Vector128<long> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<ulong> BlendVariable(Vector128<ulong> left, Vector128<ulong> right, Vector128<ulong> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_blendv_ps (__m128 a, __m128 b, __m128 mask)
- /// BLENDVPS xmm, xmm/m128, xmm0
- /// </summary>
- public static Vector128<float> BlendVariable(Vector128<float> left, Vector128<float> right, Vector128<float> mask) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_blendv_pd (__m128d a, __m128d b, __m128d mask)
- /// BLENDVPD xmm, xmm/m128, xmm0
- /// </summary>
- public static Vector128<double> BlendVariable(Vector128<double> left, Vector128<double> right, Vector128<double> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_ceil_ps (__m128 a)
- /// ROUNDPS xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<float> Ceiling(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_ceil_pd (__m128d a)
- /// ROUNDPD xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<double> Ceiling(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_ceil_sd (__m128d a)
- /// ROUNDSD xmm, xmm/m128, imm8(10)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> CeilingScalar(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_ceil_ss (__m128 a)
- /// ROUNDSD xmm, xmm/m128, imm8(10)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> CeilingScalar(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_ceil_sd (__m128d a, __m128d b)
- /// ROUNDSD xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<double> CeilingScalar(Vector128<double> upper, Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_ceil_ss (__m128 a, __m128 b)
- /// ROUNDSS xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<float> CeilingScalar(Vector128<float> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_cmpeq_epi64 (__m128i a, __m128i b)
- /// PCMPEQQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> CompareEqual(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cmpeq_epi64 (__m128i a, __m128i b)
- /// PCMPEQQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> CompareEqual(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_cvtepi8_epi16 (__m128i a)
- /// PMOVSXBW xmm, xmm
- /// </summary>
- public static Vector128<short> ConvertToVector128Int16(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtepu8_epi16 (__m128i a)
- /// PMOVZXBW xmm, xmm
- /// </summary>
- public static Vector128<short> ConvertToVector128Int16(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtepi8_epi32 (__m128i a)
- /// PMOVSXBD xmm, xmm
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtepu8_epi32 (__m128i a)
- /// PMOVZXBD xmm, xmm
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtepi16_epi32 (__m128i a)
- /// PMOVSXWD xmm, xmm
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<short> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtepu16_epi32 (__m128i a)
- /// PMOVZXWD xmm, xmm
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<ushort> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtepi8_epi64 (__m128i a)
- /// PMOVSXBQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtepu8_epi64 (__m128i a)
- /// PMOVZXBQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<byte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtepi16_epi64 (__m128i a)
- /// PMOVSXWQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<short> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtepu16_epi64 (__m128i a)
- /// PMOVZXWQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<ushort> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtepi32_epi64 (__m128i a)
- /// PMOVSXDQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<int> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_cvtepu32_epi64 (__m128i a)
- /// PMOVZXDQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<uint> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// PMOVSXBW xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<short> ConvertToVector128Int16(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// PMOVZXBW xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<short> ConvertToVector128Int16(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// PMOVSXBD xmm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<int> ConvertToVector128Int32(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// PMOVZXBD xmm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<int> ConvertToVector128Int32(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// PMOVSXWD xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<int> ConvertToVector128Int32(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// PMOVZXWD xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<int> ConvertToVector128Int32(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// PMOVSXBQ xmm, m16
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// PMOVZXBQ xmm, m16
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// PMOVSXWQ xmm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// PMOVZXWQ xmm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// PMOVSXDQ xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(int* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// PMOVZXDQ xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(uint* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_dp_ps (__m128 a, __m128 b, const int imm8)
- /// DPPS xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<float> DotProduct(Vector128<float> left, Vector128<float> right, byte control) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_dp_pd (__m128d a, __m128d b, const int imm8)
- /// DPPD xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<double> DotProduct(Vector128<double> left, Vector128<double> right, byte control) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_extract_epi8 (__m128i a, const int imm8)
- /// PEXTRB reg/m8, xmm, imm8
- /// </summary>
- public static byte Extract(Vector128<byte> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm_extract_epi32 (__m128i a, const int imm8)
- /// PEXTRD reg/m32, xmm, imm8
- /// </summary>
- public static int Extract(Vector128<int> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm_extract_epi32 (__m128i a, const int imm8)
- /// PEXTRD reg/m32, xmm, imm8
- /// </summary>
- public static uint Extract(Vector128<uint> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// int _mm_extract_ps (__m128 a, const int imm8)
- /// EXTRACTPS xmm, xmm/m32, imm8
- /// </summary>
- public static float Extract(Vector128<float> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_floor_ps (__m128 a)
- /// ROUNDPS xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<float> Floor(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_floor_pd (__m128d a)
- /// ROUNDPD xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<double> Floor(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_floor_sd (__m128d a)
- /// ROUNDSD xmm, xmm/m128, imm8(9)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> FloorScalar(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_floor_ss (__m128 a)
- /// ROUNDSS xmm, xmm/m128, imm8(9)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> FloorScalar(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_floor_sd (__m128d a, __m128d b)
- /// ROUNDSD xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<double> FloorScalar(Vector128<double> upper, Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_floor_ss (__m128 a, __m128 b)
- /// ROUNDSS xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<float> FloorScalar(Vector128<float> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_insert_epi8 (__m128i a, int i, const int imm8)
- /// PINSRB xmm, reg/m8, imm8
- /// </summary>
- public static Vector128<sbyte> Insert(Vector128<sbyte> value, sbyte data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_insert_epi8 (__m128i a, int i, const int imm8)
- /// PINSRB xmm, reg/m8, imm8
- /// </summary>
- public static Vector128<byte> Insert(Vector128<byte> value, byte data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_insert_epi32 (__m128i a, int i, const int imm8)
- /// PINSRD xmm, reg/m32, imm8
- /// </summary>
- public static Vector128<int> Insert(Vector128<int> value, int data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_insert_epi32 (__m128i a, int i, const int imm8)
- /// PINSRD xmm, reg/m32, imm8
- /// </summary>
- public static Vector128<uint> Insert(Vector128<uint> value, uint data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_insert_ps (__m128 a, __m128 b, const int imm8)
- /// INSERTPS xmm, xmm/m32, imm8
- /// </summary>
- public static Vector128<float> Insert(Vector128<float> value, Vector128<float> data, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_max_epi8 (__m128i a, __m128i b)
- /// PMAXSB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Max(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_max_epu16 (__m128i a, __m128i b)
- /// PMAXUW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Max(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_max_epi32 (__m128i a, __m128i b)
- /// PMAXSD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Max(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_max_epu32 (__m128i a, __m128i b)
- /// PMAXUD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Max(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_min_epi8 (__m128i a, __m128i b)
- /// PMINSB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Min(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_min_epu16 (__m128i a, __m128i b)
- /// PMINUW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Min(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_min_epi32 (__m128i a, __m128i b)
- /// PMINSD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Min(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_min_epu32 (__m128i a, __m128i b)
- /// PMINUD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Min(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_minpos_epu16 (__m128i a)
- /// PHMINPOSUW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> MinHorizontal(Vector128<ushort> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_mpsadbw_epu8 (__m128i a, __m128i b, const int imm8)
- /// MPSADBW xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<ushort> MultipleSumAbsoluteDifferences(Vector128<byte> left, Vector128<byte> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_mul_epi32 (__m128i a, __m128i b)
- /// PMULDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> Multiply(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_mullo_epi32 (__m128i a, __m128i b)
- /// PMULLD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> MultiplyLow(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_mullo_epi32 (__m128i a, __m128i b)
- /// PMULLD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> MultiplyLow(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_packus_epi32 (__m128i a, __m128i b)
- /// PACKUSDW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> PackUnsignedSaturate(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_round_ps (__m128 a, int rounding)
- /// ROUNDPS xmm, xmm/m128, imm8(8)
- /// _MM_FROUND_TO_NEAREST_INT |_MM_FROUND_NO_EXC
- /// </summary>
- public static Vector128<float> RoundToNearestInteger(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// _MM_FROUND_TO_NEG_INF |_MM_FROUND_NO_EXC; ROUNDPS xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<float> RoundToNegativeInfinity(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// _MM_FROUND_TO_POS_INF |_MM_FROUND_NO_EXC; ROUNDPS xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<float> RoundToPositiveInfinity(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// _MM_FROUND_TO_ZERO |_MM_FROUND_NO_EXC; ROUNDPS xmm, xmm/m128, imm8(11)
- /// </summary>
- public static Vector128<float> RoundToZero(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// _MM_FROUND_CUR_DIRECTION; ROUNDPS xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<float> RoundCurrentDirection(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_round_pd (__m128d a, int rounding)
- /// ROUNDPD xmm, xmm/m128, imm8(8)
- /// _MM_FROUND_TO_NEAREST_INT |_MM_FROUND_NO_EXC
- /// </summary>
- public static Vector128<double> RoundToNearestInteger(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// _MM_FROUND_TO_NEG_INF |_MM_FROUND_NO_EXC; ROUNDPD xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<double> RoundToNegativeInfinity(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// _MM_FROUND_TO_POS_INF |_MM_FROUND_NO_EXC; ROUNDPD xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<double> RoundToPositiveInfinity(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// _MM_FROUND_TO_ZERO |_MM_FROUND_NO_EXC; ROUNDPD xmm, xmm/m128, imm8(11)
- /// </summary>
- public static Vector128<double> RoundToZero(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// _MM_FROUND_CUR_DIRECTION; ROUNDPD xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<double> RoundCurrentDirection(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, _MM_FROUND_CUR_DIRECTION)
- /// ROUNDSD xmm, xmm/m128, imm8(4)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> RoundCurrentDirectionScalar(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, _MM_FROUND_TO_NEAREST_INT |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(8)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> RoundToNearestIntegerScalar(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, _MM_FROUND_TO_NEG_INF |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(9)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> RoundToNegativeInfinityScalar(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, _MM_FROUND_TO_POS_INF |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(10)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> RoundToPositiveInfinityScalar(Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, _MM_FROUND_TO_ZERO |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(11)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> RoundToZeroScalar(Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, __m128d b, _MM_FROUND_CUR_DIRECTION)
- /// ROUNDSD xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<double> RoundCurrentDirectionScalar(Vector128<double> upper, Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, __m128d b, _MM_FROUND_TO_NEAREST_INT |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(8)
- /// </summary>
- public static Vector128<double> RoundToNearestIntegerScalar(Vector128<double> upper, Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, __m128d b, _MM_FROUND_TO_NEG_INF |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<double> RoundToNegativeInfinityScalar(Vector128<double> upper, Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, __m128d b, _MM_FROUND_TO_POS_INF |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<double> RoundToPositiveInfinityScalar(Vector128<double> upper, Vector128<double> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, __m128d b, _MM_FROUND_TO_ZERO |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(11)
- /// </summary>
- public static Vector128<double> RoundToZeroScalar(Vector128<double> upper, Vector128<double> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, _MM_FROUND_CUR_DIRECTION)
- /// ROUNDSS xmm, xmm/m128, imm8(4)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> RoundCurrentDirectionScalar(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(8)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> RoundToNearestIntegerScalar(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(9)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> RoundToNegativeInfinityScalar(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(10)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> RoundToPositiveInfinityScalar(Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(11)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> RoundToZeroScalar(Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, __m128 b, _MM_FROUND_CUR_DIRECTION)
- /// ROUNDSS xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<float> RoundCurrentDirectionScalar(Vector128<float> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, __m128 b, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(8)
- /// </summary>
- public static Vector128<float> RoundToNearestIntegerScalar(Vector128<float> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, __m128 b, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<float> RoundToNegativeInfinityScalar(Vector128<float> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, __m128 b, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<float> RoundToPositiveInfinityScalar(Vector128<float> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, __m128 b, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(11)
- /// </summary>
- public static Vector128<float> RoundToZeroScalar(Vector128<float> upper, Vector128<float> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<sbyte> LoadAlignedVector128NonTemporal(sbyte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<byte> LoadAlignedVector128NonTemporal(byte* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<short> LoadAlignedVector128NonTemporal(short* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<ushort> LoadAlignedVector128NonTemporal(ushort* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<int> LoadAlignedVector128NonTemporal(int* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<uint> LoadAlignedVector128NonTemporal(uint* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<long> LoadAlignedVector128NonTemporal(long* address) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<ulong> LoadAlignedVector128NonTemporal(ulong* address) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_testc_si128 (__m128i a, __m128i b)
- /// PTEST xmm, xmm/m128
- /// </summary>
- public static bool TestC(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- public static bool TestC(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- public static bool TestC(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- public static bool TestC(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- public static bool TestC(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- public static bool TestC(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- public static bool TestC(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- public static bool TestC(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_testnzc_si128 (__m128i a, __m128i b)
- /// PTEST xmm, xmm/m128
- /// </summary>
- public static bool TestNotZAndNotC(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- public static bool TestNotZAndNotC(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- public static bool TestNotZAndNotC(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- public static bool TestNotZAndNotC(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- public static bool TestNotZAndNotC(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- public static bool TestNotZAndNotC(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- public static bool TestNotZAndNotC(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- public static bool TestNotZAndNotC(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// int _mm_testz_si128 (__m128i a, __m128i b)
- /// PTEST xmm, xmm/m128
- /// </summary>
- public static bool TestZ(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- public static bool TestZ(Vector128<byte> left, Vector128<byte> right) { throw new PlatformNotSupportedException(); }
- public static bool TestZ(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- public static bool TestZ(Vector128<ushort> left, Vector128<ushort> right) { throw new PlatformNotSupportedException(); }
- public static bool TestZ(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- public static bool TestZ(Vector128<uint> left, Vector128<uint> right) { throw new PlatformNotSupportedException(); }
- public static bool TestZ(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
- public static bool TestZ(Vector128<ulong> left, Vector128<ulong> right) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse41.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse41.cs
deleted file mode 100644
index 300b8f0af33..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse41.cs
+++ /dev/null
@@ -1,713 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSE4.1 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Sse41 : Ssse3
- {
- internal Sse41() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- [Intrinsic]
- public new abstract class X64 : Sse2.X64
- {
- internal X64() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// __int64 _mm_extract_epi64 (__m128i a, const int imm8)
- /// PEXTRQ reg/m64, xmm, imm8
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static long Extract(Vector128<long> value, byte index) => Extract(value, index);
- /// <summary>
- /// __int64 _mm_extract_epi64 (__m128i a, const int imm8)
- /// PEXTRQ reg/m64, xmm, imm8
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong Extract(Vector128<ulong> value, byte index) => Extract(value, index);
-
- /// <summary>
- /// __m128i _mm_insert_epi64 (__m128i a, __int64 i, const int imm8)
- /// PINSRQ xmm, reg/m64, imm8
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<long> Insert(Vector128<long> value, long data, byte index) => Insert(value, data, index);
- /// <summary>
- /// __m128i _mm_insert_epi64 (__m128i a, __int64 i, const int imm8)
- /// PINSRQ xmm, reg/m64, imm8
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static Vector128<ulong> Insert(Vector128<ulong> value, ulong data, byte index) => Insert(value, data, index);
- }
-
- /// <summary>
- /// __m128i _mm_blend_epi16 (__m128i a, __m128i b, const int imm8)
- /// PBLENDW xmm, xmm/m128 imm8
- /// </summary>
- public static Vector128<short> Blend(Vector128<short> left, Vector128<short> right, byte control) => Blend(left, right, control);
-
- /// <summary>
- /// __m128i _mm_blend_epi16 (__m128i a, __m128i b, const int imm8)
- /// PBLENDW xmm, xmm/m128 imm8
- /// </summary>
- public static Vector128<ushort> Blend(Vector128<ushort> left, Vector128<ushort> right, byte control) => Blend(left, right, control);
-
- /// <summary>
- /// __m128 _mm_blend_ps (__m128 a, __m128 b, const int imm8)
- /// BLENDPS xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<float> Blend(Vector128<float> left, Vector128<float> right, byte control) => Blend(left, right, control);
-
- /// <summary>
- /// __m128d _mm_blend_pd (__m128d a, __m128d b, const int imm8)
- /// BLENDPD xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<double> Blend(Vector128<double> left, Vector128<double> right, byte control) => Blend(left, right, control);
-
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// </summary>
- public static Vector128<sbyte> BlendVariable(Vector128<sbyte> left, Vector128<sbyte> right, Vector128<sbyte> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// </summary>
- public static Vector128<byte> BlendVariable(Vector128<byte> left, Vector128<byte> right, Vector128<byte> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<short> BlendVariable(Vector128<short> left, Vector128<short> right, Vector128<short> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<ushort> BlendVariable(Vector128<ushort> left, Vector128<ushort> right, Vector128<ushort> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<int> BlendVariable(Vector128<int> left, Vector128<int> right, Vector128<int> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<uint> BlendVariable(Vector128<uint> left, Vector128<uint> right, Vector128<uint> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<long> BlendVariable(Vector128<long> left, Vector128<long> right, Vector128<long> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m128i _mm_blendv_epi8 (__m128i a, __m128i b, __m128i mask)
- /// PBLENDVB xmm, xmm/m128, xmm
- /// This intrinsic generates PBLENDVB that needs a BYTE mask-vector, so users should correctly set each mask byte for the selected elements.
- /// </summary>
- public static Vector128<ulong> BlendVariable(Vector128<ulong> left, Vector128<ulong> right, Vector128<ulong> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m128 _mm_blendv_ps (__m128 a, __m128 b, __m128 mask)
- /// BLENDVPS xmm, xmm/m128, xmm0
- /// </summary>
- public static Vector128<float> BlendVariable(Vector128<float> left, Vector128<float> right, Vector128<float> mask) => BlendVariable(left, right, mask);
- /// <summary>
- /// __m128d _mm_blendv_pd (__m128d a, __m128d b, __m128d mask)
- /// BLENDVPD xmm, xmm/m128, xmm0
- /// </summary>
- public static Vector128<double> BlendVariable(Vector128<double> left, Vector128<double> right, Vector128<double> mask) => BlendVariable(left, right, mask);
-
- /// <summary>
- /// __m128 _mm_ceil_ps (__m128 a)
- /// ROUNDPS xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<float> Ceiling(Vector128<float> value) => Ceiling(value);
- /// <summary>
- /// __m128d _mm_ceil_pd (__m128d a)
- /// ROUNDPD xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<double> Ceiling(Vector128<double> value) => Ceiling(value);
-
- /// <summary>
- /// __m128d _mm_ceil_sd (__m128d a)
- /// ROUNDSD xmm, xmm/m128, imm8(10)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> CeilingScalar(Vector128<double> value) => CeilingScalar(value);
- /// <summary>
- /// __m128 _mm_ceil_ss (__m128 a)
- /// ROUNDSD xmm, xmm/m128, imm8(10)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> CeilingScalar(Vector128<float> value) => CeilingScalar(value);
-
- /// <summary>
- /// __m128d _mm_ceil_sd (__m128d a, __m128d b)
- /// ROUNDSD xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<double> CeilingScalar(Vector128<double> upper, Vector128<double> value) => CeilingScalar(upper, value);
- /// <summary>
- /// __m128 _mm_ceil_ss (__m128 a, __m128 b)
- /// ROUNDSS xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<float> CeilingScalar(Vector128<float> upper, Vector128<float> value) => CeilingScalar(upper, value);
-
- /// <summary>
- /// __m128i _mm_cmpeq_epi64 (__m128i a, __m128i b)
- /// PCMPEQQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> CompareEqual(Vector128<long> left, Vector128<long> right) => CompareEqual(left, right);
- /// <summary>
- /// __m128i _mm_cmpeq_epi64 (__m128i a, __m128i b)
- /// PCMPEQQ xmm, xmm/m128
- /// </summary>
- public static Vector128<ulong> CompareEqual(Vector128<ulong> left, Vector128<ulong> right) => CompareEqual(left, right);
-
- /// <summary>
- /// __m128i _mm_cvtepi8_epi16 (__m128i a)
- /// PMOVSXBW xmm, xmm
- /// </summary>
- public static Vector128<short> ConvertToVector128Int16(Vector128<sbyte> value) => ConvertToVector128Int16(value);
- /// <summary>
- /// __m128i _mm_cvtepu8_epi16 (__m128i a)
- /// PMOVZXBW xmm, xmm
- /// </summary>
- public static Vector128<short> ConvertToVector128Int16(Vector128<byte> value) => ConvertToVector128Int16(value);
- /// <summary>
- /// __m128i _mm_cvtepi8_epi32 (__m128i a)
- /// PMOVSXBD xmm, xmm
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<sbyte> value) => ConvertToVector128Int32(value);
- /// <summary>
- /// __m128i _mm_cvtepu8_epi32 (__m128i a)
- /// PMOVZXBD xmm, xmm
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<byte> value) => ConvertToVector128Int32(value);
- /// <summary>
- /// __m128i _mm_cvtepi16_epi32 (__m128i a)
- /// PMOVSXWD xmm, xmm
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<short> value) => ConvertToVector128Int32(value);
- /// <summary>
- /// __m128i _mm_cvtepu16_epi32 (__m128i a)
- /// PMOVZXWD xmm, xmm
- /// </summary>
- public static Vector128<int> ConvertToVector128Int32(Vector128<ushort> value) => ConvertToVector128Int32(value);
- /// <summary>
- /// __m128i _mm_cvtepi8_epi64 (__m128i a)
- /// PMOVSXBQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<sbyte> value) => ConvertToVector128Int64(value);
- /// <summary>
- /// __m128i _mm_cvtepu8_epi64 (__m128i a)
- /// PMOVZXBQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<byte> value) => ConvertToVector128Int64(value);
- /// <summary>
- /// __m128i _mm_cvtepi16_epi64 (__m128i a)
- /// PMOVSXWQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<short> value) => ConvertToVector128Int64(value);
- /// <summary>
- /// __m128i _mm_cvtepu16_epi64 (__m128i a)
- /// PMOVZXWQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<ushort> value) => ConvertToVector128Int64(value);
- /// <summary>
- /// __m128i _mm_cvtepi32_epi64 (__m128i a)
- /// PMOVSXDQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<int> value) => ConvertToVector128Int64(value);
- /// <summary>
- /// __m128i _mm_cvtepu32_epi64 (__m128i a)
- /// PMOVZXDQ xmm, xmm
- /// </summary>
- public static Vector128<long> ConvertToVector128Int64(Vector128<uint> value) => ConvertToVector128Int64(value);
-
- /// <summary>
- /// PMOVSXBW xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<short> ConvertToVector128Int16(sbyte* address) => ConvertToVector128Int16(address);
- /// <summary>
- /// PMOVZXBW xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<short> ConvertToVector128Int16(byte* address) => ConvertToVector128Int16(address);
- /// <summary>
- /// PMOVSXBD xmm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<int> ConvertToVector128Int32(sbyte* address) => ConvertToVector128Int32(address);
- /// <summary>
- /// PMOVZXBD xmm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<int> ConvertToVector128Int32(byte* address) => ConvertToVector128Int32(address);
- /// <summary>
- /// PMOVSXWD xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<int> ConvertToVector128Int32(short* address) => ConvertToVector128Int32(address);
- /// <summary>
- /// PMOVZXWD xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<int> ConvertToVector128Int32(ushort* address) => ConvertToVector128Int32(address);
- /// <summary>
- /// PMOVSXBQ xmm, m16
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(sbyte* address) => ConvertToVector128Int64(address);
- /// <summary>
- /// PMOVZXBQ xmm, m16
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(byte* address) => ConvertToVector128Int64(address);
- /// <summary>
- /// PMOVSXWQ xmm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(short* address) => ConvertToVector128Int64(address);
- /// <summary>
- /// PMOVZXWQ xmm, m32
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(ushort* address) => ConvertToVector128Int64(address);
- /// <summary>
- /// PMOVSXDQ xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(int* address) => ConvertToVector128Int64(address);
- /// <summary>
- /// PMOVZXDQ xmm, m64
- /// The native signature does not exist. We provide this additional overload for completeness.
- /// </summary>
- public static unsafe Vector128<long> ConvertToVector128Int64(uint* address) => ConvertToVector128Int64(address);
-
- /// <summary>
- /// __m128 _mm_dp_ps (__m128 a, __m128 b, const int imm8)
- /// DPPS xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<float> DotProduct(Vector128<float> left, Vector128<float> right, byte control) => DotProduct(left, right, control);
- /// <summary>
- /// __m128d _mm_dp_pd (__m128d a, __m128d b, const int imm8)
- /// DPPD xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<double> DotProduct(Vector128<double> left, Vector128<double> right, byte control) => DotProduct(left, right, control);
-
- /// <summary>
- /// int _mm_extract_epi8 (__m128i a, const int imm8)
- /// PEXTRB reg/m8, xmm, imm8
- /// </summary>
- public static byte Extract(Vector128<byte> value, byte index) => Extract(value, index);
- /// <summary>
- /// int _mm_extract_epi32 (__m128i a, const int imm8)
- /// PEXTRD reg/m32, xmm, imm8
- /// </summary>
- public static int Extract(Vector128<int> value, byte index) => Extract(value, index);
- /// <summary>
- /// int _mm_extract_epi32 (__m128i a, const int imm8)
- /// PEXTRD reg/m32, xmm, imm8
- /// </summary>
- public static uint Extract(Vector128<uint> value, byte index) => Extract(value, index);
- /// <summary>
- /// int _mm_extract_ps (__m128 a, const int imm8)
- /// EXTRACTPS xmm, xmm/m32, imm8
- /// </summary>
- public static float Extract(Vector128<float> value, byte index) => Extract(value, index);
-
- /// <summary>
- /// __m128 _mm_floor_ps (__m128 a)
- /// ROUNDPS xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<float> Floor(Vector128<float> value) => Floor(value);
- /// <summary>
- /// __m128d _mm_floor_pd (__m128d a)
- /// ROUNDPD xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<double> Floor(Vector128<double> value) => Floor(value);
-
- /// <summary>
- /// __m128d _mm_floor_sd (__m128d a)
- /// ROUNDSD xmm, xmm/m128, imm8(9)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> FloorScalar(Vector128<double> value) => FloorScalar(value);
- /// <summary>
- /// __m128 _mm_floor_ss (__m128 a)
- /// ROUNDSS xmm, xmm/m128, imm8(9)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> FloorScalar(Vector128<float> value) => FloorScalar(value);
-
- /// <summary>
- /// __m128d _mm_floor_sd (__m128d a, __m128d b)
- /// ROUNDSD xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<double> FloorScalar(Vector128<double> upper, Vector128<double> value) => FloorScalar(upper, value);
- /// <summary>
- /// __m128 _mm_floor_ss (__m128 a, __m128 b)
- /// ROUNDSS xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<float> FloorScalar(Vector128<float> upper, Vector128<float> value) => FloorScalar(upper, value);
-
- /// <summary>
- /// __m128i _mm_insert_epi8 (__m128i a, int i, const int imm8)
- /// PINSRB xmm, reg/m8, imm8
- /// </summary>
- public static Vector128<sbyte> Insert(Vector128<sbyte> value, sbyte data, byte index) => Insert(value, data, index);
- /// <summary>
- /// __m128i _mm_insert_epi8 (__m128i a, int i, const int imm8)
- /// PINSRB xmm, reg/m8, imm8
- /// </summary>
- public static Vector128<byte> Insert(Vector128<byte> value, byte data, byte index) => Insert(value, data, index);
- /// <summary>
- /// __m128i _mm_insert_epi32 (__m128i a, int i, const int imm8)
- /// PINSRD xmm, reg/m32, imm8
- /// </summary>
- public static Vector128<int> Insert(Vector128<int> value, int data, byte index) => Insert(value, data, index);
- /// <summary>
- /// __m128i _mm_insert_epi32 (__m128i a, int i, const int imm8)
- /// PINSRD xmm, reg/m32, imm8
- /// </summary>
- public static Vector128<uint> Insert(Vector128<uint> value, uint data, byte index) => Insert(value, data, index);
- /// <summary>
- /// __m128 _mm_insert_ps (__m128 a, __m128 b, const int imm8)
- /// INSERTPS xmm, xmm/m32, imm8
- /// </summary>
- public static Vector128<float> Insert(Vector128<float> value, Vector128<float> data, byte index) => Insert(value, data, index);
-
- /// <summary>
- /// __m128i _mm_max_epi8 (__m128i a, __m128i b)
- /// PMAXSB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Max(Vector128<sbyte> left, Vector128<sbyte> right) => Max(left, right);
- /// <summary>
- /// __m128i _mm_max_epu16 (__m128i a, __m128i b)
- /// PMAXUW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Max(Vector128<ushort> left, Vector128<ushort> right) => Max(left, right);
- /// <summary>
- /// __m128i _mm_max_epi32 (__m128i a, __m128i b)
- /// PMAXSD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Max(Vector128<int> left, Vector128<int> right) => Max(left, right);
- /// <summary>
- /// __m128i _mm_max_epu32 (__m128i a, __m128i b)
- /// PMAXUD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Max(Vector128<uint> left, Vector128<uint> right) => Max(left, right);
-
- /// <summary>
- /// __m128i _mm_min_epi8 (__m128i a, __m128i b)
- /// PMINSB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Min(Vector128<sbyte> left, Vector128<sbyte> right) => Min(left, right);
- /// <summary>
- /// __m128i _mm_min_epu16 (__m128i a, __m128i b)
- /// PMINUW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Min(Vector128<ushort> left, Vector128<ushort> right) => Min(left, right);
- /// <summary>
- /// __m128i _mm_min_epi32 (__m128i a, __m128i b)
- /// PMINSD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Min(Vector128<int> left, Vector128<int> right) => Min(left, right);
- /// <summary>
- /// __m128i _mm_min_epu32 (__m128i a, __m128i b)
- /// PMINUD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Min(Vector128<uint> left, Vector128<uint> right) => Min(left, right);
-
- /// <summary>
- /// __m128i _mm_minpos_epu16 (__m128i a)
- /// PHMINPOSUW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> MinHorizontal(Vector128<ushort> value) => MinHorizontal(value);
-
- /// <summary>
- /// __m128i _mm_mpsadbw_epu8 (__m128i a, __m128i b, const int imm8)
- /// MPSADBW xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<ushort> MultipleSumAbsoluteDifferences(Vector128<byte> left, Vector128<byte> right, byte mask) => MultipleSumAbsoluteDifferences(left, right, mask);
-
- /// <summary>
- /// __m128i _mm_mul_epi32 (__m128i a, __m128i b)
- /// PMULDQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> Multiply(Vector128<int> left, Vector128<int> right) => Multiply(left, right);
-
- /// <summary>
- /// __m128i _mm_mullo_epi32 (__m128i a, __m128i b)
- /// PMULLD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> MultiplyLow(Vector128<int> left, Vector128<int> right) => MultiplyLow(left, right);
- /// <summary>
- /// __m128i _mm_mullo_epi32 (__m128i a, __m128i b)
- /// PMULLD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> MultiplyLow(Vector128<uint> left, Vector128<uint> right) => MultiplyLow(left, right);
-
- /// <summary>
- /// __m128i _mm_packus_epi32 (__m128i a, __m128i b)
- /// PACKUSDW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> PackUnsignedSaturate(Vector128<int> left, Vector128<int> right) => PackUnsignedSaturate(left, right);
-
- /// <summary>
- /// __m128 _mm_round_ps (__m128 a, int rounding)
- /// ROUNDPS xmm, xmm/m128, imm8(8)
- /// _MM_FROUND_TO_NEAREST_INT |_MM_FROUND_NO_EXC
- /// </summary>
- public static Vector128<float> RoundToNearestInteger(Vector128<float> value) => RoundToNearestInteger(value);
- /// <summary>
- /// _MM_FROUND_TO_NEG_INF |_MM_FROUND_NO_EXC; ROUNDPS xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<float> RoundToNegativeInfinity(Vector128<float> value) => RoundToNegativeInfinity(value);
- /// <summary>
- /// _MM_FROUND_TO_POS_INF |_MM_FROUND_NO_EXC; ROUNDPS xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<float> RoundToPositiveInfinity(Vector128<float> value) => RoundToPositiveInfinity(value);
- /// <summary>
- /// _MM_FROUND_TO_ZERO |_MM_FROUND_NO_EXC; ROUNDPS xmm, xmm/m128, imm8(11)
- /// </summary>
- public static Vector128<float> RoundToZero(Vector128<float> value) => RoundToZero(value);
- /// <summary>
- /// _MM_FROUND_CUR_DIRECTION; ROUNDPS xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<float> RoundCurrentDirection(Vector128<float> value) => RoundCurrentDirection(value);
-
- /// <summary>
- /// __m128d _mm_round_pd (__m128d a, int rounding)
- /// ROUNDPD xmm, xmm/m128, imm8(8)
- /// _MM_FROUND_TO_NEAREST_INT |_MM_FROUND_NO_EXC
- /// </summary>
- public static Vector128<double> RoundToNearestInteger(Vector128<double> value) => RoundToNearestInteger(value);
- /// <summary>
- /// _MM_FROUND_TO_NEG_INF |_MM_FROUND_NO_EXC; ROUNDPD xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<double> RoundToNegativeInfinity(Vector128<double> value) => RoundToNegativeInfinity(value);
- /// <summary>
- /// _MM_FROUND_TO_POS_INF |_MM_FROUND_NO_EXC; ROUNDPD xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<double> RoundToPositiveInfinity(Vector128<double> value) => RoundToPositiveInfinity(value);
- /// <summary>
- /// _MM_FROUND_TO_ZERO |_MM_FROUND_NO_EXC; ROUNDPD xmm, xmm/m128, imm8(11)
- /// </summary>
- public static Vector128<double> RoundToZero(Vector128<double> value) => RoundToZero(value);
- /// <summary>
- /// _MM_FROUND_CUR_DIRECTION; ROUNDPD xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<double> RoundCurrentDirection(Vector128<double> value) => RoundCurrentDirection(value);
-
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, _MM_FROUND_CUR_DIRECTION)
- /// ROUNDSD xmm, xmm/m128, imm8(4)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> RoundCurrentDirectionScalar(Vector128<double> value) => RoundCurrentDirectionScalar(value);
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, _MM_FROUND_TO_NEAREST_INT |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(8)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> RoundToNearestIntegerScalar(Vector128<double> value) => RoundToNearestIntegerScalar(value);
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, _MM_FROUND_TO_NEG_INF |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(9)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> RoundToNegativeInfinityScalar(Vector128<double> value) => RoundToNegativeInfinityScalar(value);
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, _MM_FROUND_TO_POS_INF |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(10)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> RoundToPositiveInfinityScalar(Vector128<double> value) => RoundToPositiveInfinityScalar(value);
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, _MM_FROUND_TO_ZERO |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(11)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<double> RoundToZeroScalar(Vector128<double> value) => RoundToZeroScalar(value);
-
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, __m128d b, _MM_FROUND_CUR_DIRECTION)
- /// ROUNDSD xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<double> RoundCurrentDirectionScalar(Vector128<double> upper, Vector128<double> value) => RoundCurrentDirectionScalar(upper, value);
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, __m128d b, _MM_FROUND_TO_NEAREST_INT |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(8)
- /// </summary>
- public static Vector128<double> RoundToNearestIntegerScalar(Vector128<double> upper, Vector128<double> value) => RoundToNearestIntegerScalar(upper, value);
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, __m128d b, _MM_FROUND_TO_NEG_INF |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<double> RoundToNegativeInfinityScalar(Vector128<double> upper, Vector128<double> value) => RoundToNegativeInfinityScalar(upper, value);
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, __m128d b, _MM_FROUND_TO_POS_INF |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<double> RoundToPositiveInfinityScalar(Vector128<double> upper, Vector128<double> value) => RoundToPositiveInfinityScalar(upper, value);
- /// <summary>
- /// __m128d _mm_round_sd (__m128d a, __m128d b, _MM_FROUND_TO_ZERO |_MM_FROUND_NO_EXC)
- /// ROUNDSD xmm, xmm/m128, imm8(11)
- /// </summary>
- public static Vector128<double> RoundToZeroScalar(Vector128<double> upper, Vector128<double> value) => RoundToZeroScalar(upper, value);
-
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, _MM_FROUND_CUR_DIRECTION)
- /// ROUNDSS xmm, xmm/m128, imm8(4)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> RoundCurrentDirectionScalar(Vector128<float> value) => RoundCurrentDirectionScalar(value);
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(8)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> RoundToNearestIntegerScalar(Vector128<float> value) => RoundToNearestIntegerScalar(value);
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(9)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> RoundToNegativeInfinityScalar(Vector128<float> value) => RoundToNegativeInfinityScalar(value);
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(10)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> RoundToPositiveInfinityScalar(Vector128<float> value) => RoundToPositiveInfinityScalar(value);
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(11)
- /// The above native signature does not exist. We provide this additional overload for the recommended use case of this intrinsic.
- /// </summary>
- public static Vector128<float> RoundToZeroScalar(Vector128<float> value) => RoundToZeroScalar(value);
-
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, __m128 b, _MM_FROUND_CUR_DIRECTION)
- /// ROUNDSS xmm, xmm/m128, imm8(4)
- /// </summary>
- public static Vector128<float> RoundCurrentDirectionScalar(Vector128<float> upper, Vector128<float> value) => RoundCurrentDirectionScalar(upper, value);
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, __m128 b, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(8)
- /// </summary>
- public static Vector128<float> RoundToNearestIntegerScalar(Vector128<float> upper, Vector128<float> value) => RoundToNearestIntegerScalar(upper, value);
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, __m128 b, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(9)
- /// </summary>
- public static Vector128<float> RoundToNegativeInfinityScalar(Vector128<float> upper, Vector128<float> value) => RoundToNegativeInfinityScalar(upper, value);
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, __m128 b, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(10)
- /// </summary>
- public static Vector128<float> RoundToPositiveInfinityScalar(Vector128<float> upper, Vector128<float> value) => RoundToPositiveInfinityScalar(upper, value);
- /// <summary>
- /// __m128 _mm_round_ss (__m128 a, __m128 b, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC)
- /// ROUNDSS xmm, xmm/m128, imm8(11)
- /// </summary>
- public static Vector128<float> RoundToZeroScalar(Vector128<float> upper, Vector128<float> value) => RoundToZeroScalar(upper, value);
-
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<sbyte> LoadAlignedVector128NonTemporal(sbyte* address) => LoadAlignedVector128NonTemporal(address);
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<byte> LoadAlignedVector128NonTemporal(byte* address) => LoadAlignedVector128NonTemporal(address);
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<short> LoadAlignedVector128NonTemporal(short* address) => LoadAlignedVector128NonTemporal(address);
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<ushort> LoadAlignedVector128NonTemporal(ushort* address) => LoadAlignedVector128NonTemporal(address);
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<int> LoadAlignedVector128NonTemporal(int* address) => LoadAlignedVector128NonTemporal(address);
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<uint> LoadAlignedVector128NonTemporal(uint* address) => LoadAlignedVector128NonTemporal(address);
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<long> LoadAlignedVector128NonTemporal(long* address) => LoadAlignedVector128NonTemporal(address);
- /// <summary>
- /// __m128i _mm_stream_load_si128 (const __m128i* mem_addr)
- /// MOVNTDQA xmm, m128
- /// </summary>
- public static unsafe Vector128<ulong> LoadAlignedVector128NonTemporal(ulong* address) => LoadAlignedVector128NonTemporal(address);
-
- /// <summary>
- /// int _mm_testc_si128 (__m128i a, __m128i b)
- /// PTEST xmm, xmm/m128
- /// </summary>
- public static bool TestC(Vector128<sbyte> left, Vector128<sbyte> right) => TestC(left, right);
- public static bool TestC(Vector128<byte> left, Vector128<byte> right) => TestC(left, right);
- public static bool TestC(Vector128<short> left, Vector128<short> right) => TestC(left, right);
- public static bool TestC(Vector128<ushort> left, Vector128<ushort> right) => TestC(left, right);
- public static bool TestC(Vector128<int> left, Vector128<int> right) => TestC(left, right);
- public static bool TestC(Vector128<uint> left, Vector128<uint> right) => TestC(left, right);
- public static bool TestC(Vector128<long> left, Vector128<long> right) => TestC(left, right);
- public static bool TestC(Vector128<ulong> left, Vector128<ulong> right) => TestC(left, right);
-
- /// <summary>
- /// int _mm_testnzc_si128 (__m128i a, __m128i b)
- /// PTEST xmm, xmm/m128
- /// </summary>
- public static bool TestNotZAndNotC(Vector128<sbyte> left, Vector128<sbyte> right) => TestNotZAndNotC(left, right);
- public static bool TestNotZAndNotC(Vector128<byte> left, Vector128<byte> right) => TestNotZAndNotC(left, right);
- public static bool TestNotZAndNotC(Vector128<short> left, Vector128<short> right) => TestNotZAndNotC(left, right);
- public static bool TestNotZAndNotC(Vector128<ushort> left, Vector128<ushort> right) => TestNotZAndNotC(left, right);
- public static bool TestNotZAndNotC(Vector128<int> left, Vector128<int> right) => TestNotZAndNotC(left, right);
- public static bool TestNotZAndNotC(Vector128<uint> left, Vector128<uint> right) => TestNotZAndNotC(left, right);
- public static bool TestNotZAndNotC(Vector128<long> left, Vector128<long> right) => TestNotZAndNotC(left, right);
- public static bool TestNotZAndNotC(Vector128<ulong> left, Vector128<ulong> right) => TestNotZAndNotC(left, right);
-
- /// <summary>
- /// int _mm_testz_si128 (__m128i a, __m128i b)
- /// PTEST xmm, xmm/m128
- /// </summary>
- public static bool TestZ(Vector128<sbyte> left, Vector128<sbyte> right) => TestZ(left, right);
- public static bool TestZ(Vector128<byte> left, Vector128<byte> right) => TestZ(left, right);
- public static bool TestZ(Vector128<short> left, Vector128<short> right) => TestZ(left, right);
- public static bool TestZ(Vector128<ushort> left, Vector128<ushort> right) => TestZ(left, right);
- public static bool TestZ(Vector128<int> left, Vector128<int> right) => TestZ(left, right);
- public static bool TestZ(Vector128<uint> left, Vector128<uint> right) => TestZ(left, right);
- public static bool TestZ(Vector128<long> left, Vector128<long> right) => TestZ(left, right);
- public static bool TestZ(Vector128<ulong> left, Vector128<ulong> right) => TestZ(left, right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse42.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse42.PlatformNotSupported.cs
deleted file mode 100644
index 9025dc504e2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse42.PlatformNotSupported.cs
+++ /dev/null
@@ -1,57 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSE4.2 hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Sse42 : Sse41
- {
- internal Sse42() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- public new abstract class X64 : Sse41.X64
- {
- internal X64() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// unsigned __int64 _mm_crc32_u64 (unsigned __int64 crc, unsigned __int64 v)
- /// CRC32 reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong Crc32(ulong crc, ulong data) { throw new PlatformNotSupportedException(); }
- }
-
- /// <summary>
- /// __m128i _mm_cmpgt_epi64 (__m128i a, __m128i b)
- /// PCMPGTQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> CompareGreaterThan(Vector128<long> left, Vector128<long> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// unsigned int _mm_crc32_u8 (unsigned int crc, unsigned char v)
- /// CRC32 reg, reg/m8
- /// </summary>
- public static uint Crc32(uint crc, byte data) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// unsigned int _mm_crc32_u16 (unsigned int crc, unsigned short v)
- /// CRC32 reg, reg/m16
- /// </summary>
- public static uint Crc32(uint crc, ushort data) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// unsigned int _mm_crc32_u32 (unsigned int crc, unsigned int v)
- /// CRC32 reg, reg/m32
- /// </summary>
- public static uint Crc32(uint crc, uint data) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse42.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse42.cs
deleted file mode 100644
index fde754ab7e9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse42.cs
+++ /dev/null
@@ -1,57 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSE4.2 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Sse42 : Sse41
- {
- internal Sse42() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- [Intrinsic]
- public new abstract class X64 : Sse41.X64
- {
- internal X64() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// unsigned __int64 _mm_crc32_u64 (unsigned __int64 crc, unsigned __int64 v)
- /// CRC32 reg, reg/m64
- /// This intrinisc is only available on 64-bit processes
- /// </summary>
- public static ulong Crc32(ulong crc, ulong data) => Crc32(crc, data);
- }
-
- /// <summary>
- /// __m128i _mm_cmpgt_epi64 (__m128i a, __m128i b)
- /// PCMPGTQ xmm, xmm/m128
- /// </summary>
- public static Vector128<long> CompareGreaterThan(Vector128<long> left, Vector128<long> right) => CompareGreaterThan(left, right);
-
- /// <summary>
- /// unsigned int _mm_crc32_u8 (unsigned int crc, unsigned char v)
- /// CRC32 reg, reg/m8
- /// </summary>
- public static uint Crc32(uint crc, byte data) => Crc32(crc, data);
- /// <summary>
- /// unsigned int _mm_crc32_u16 (unsigned int crc, unsigned short v)
- /// CRC32 reg, reg/m16
- /// </summary>
- public static uint Crc32(uint crc, ushort data) => Crc32(crc, data);
- /// <summary>
- /// unsigned int _mm_crc32_u32 (unsigned int crc, unsigned int v)
- /// CRC32 reg, reg/m32
- /// </summary>
- public static uint Crc32(uint crc, uint data) => Crc32(crc, data);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Ssse3.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Ssse3.PlatformNotSupported.cs
deleted file mode 100644
index ed02211642f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Ssse3.PlatformNotSupported.cs
+++ /dev/null
@@ -1,165 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSSE3 hardware instructions via intrinsics
- /// </summary>
- [CLSCompliant(false)]
- public abstract class Ssse3 : Sse3
- {
- internal Ssse3() { }
-
- public static new bool IsSupported { [Intrinsic] get { return false; } }
-
- /// <summary>
- /// __m128i _mm_abs_epi8 (__m128i a)
- /// PABSB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Abs(Vector128<sbyte> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_abs_epi16 (__m128i a)
- /// PABSW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Abs(Vector128<short> value) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_abs_epi32 (__m128i a)
- /// PABSD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Abs(Vector128<int> value) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<sbyte> AlignRight(Vector128<sbyte> left, Vector128<sbyte> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<byte> AlignRight(Vector128<byte> left, Vector128<byte> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<short> AlignRight(Vector128<short> left, Vector128<short> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<ushort> AlignRight(Vector128<ushort> left, Vector128<ushort> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<int> AlignRight(Vector128<int> left, Vector128<int> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<uint> AlignRight(Vector128<uint> left, Vector128<uint> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<long> AlignRight(Vector128<long> left, Vector128<long> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<ulong> AlignRight(Vector128<ulong> left, Vector128<ulong> right, byte mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_hadd_epi16 (__m128i a, __m128i b)
- /// PHADDW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> HorizontalAdd(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_hadd_epi32 (__m128i a, __m128i b)
- /// PHADDD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> HorizontalAdd(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_hadds_epi16 (__m128i a, __m128i b)
- /// PHADDSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> HorizontalAddSaturate(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_hsub_epi16 (__m128i a, __m128i b)
- /// PHSUBW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> HorizontalSubtract(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_hsub_epi32 (__m128i a, __m128i b)
- /// PHSUBD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> HorizontalSubtract(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_hsubs_epi16 (__m128i a, __m128i b)
- /// PHSUBSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> HorizontalSubtractSaturate(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_maddubs_epi16 (__m128i a, __m128i b)
- /// PMADDUBSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> MultiplyAddAdjacent(Vector128<byte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_mulhrs_epi16 (__m128i a, __m128i b)
- /// PMULHRSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> MultiplyHighRoundScale(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_shuffle_epi8 (__m128i a, __m128i b)
- /// PSHUFB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Shuffle(Vector128<sbyte> value, Vector128<sbyte> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_shuffle_epi8 (__m128i a, __m128i b)
- /// PSHUFB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Shuffle(Vector128<byte> value, Vector128<byte> mask) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
- /// __m128i _mm_sign_epi8 (__m128i a, __m128i b)
- /// PSIGNB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Sign(Vector128<sbyte> left, Vector128<sbyte> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sign_epi16 (__m128i a, __m128i b)
- /// PSIGNW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Sign(Vector128<short> left, Vector128<short> right) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm_sign_epi32 (__m128i a, __m128i b)
- /// PSIGND xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Sign(Vector128<int> left, Vector128<int> right) { throw new PlatformNotSupportedException(); }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Ssse3.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Ssse3.cs
deleted file mode 100644
index 389dd08086f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Ssse3.cs
+++ /dev/null
@@ -1,165 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.Intrinsics.X86
-{
- /// <summary>
- /// This class provides access to Intel SSSE3 hardware instructions via intrinsics
- /// </summary>
- [Intrinsic]
- [CLSCompliant(false)]
- public abstract class Ssse3 : Sse3
- {
- internal Ssse3() { }
-
- public static new bool IsSupported { get => IsSupported; }
-
- /// <summary>
- /// __m128i _mm_abs_epi8 (__m128i a)
- /// PABSB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Abs(Vector128<sbyte> value) => Abs(value);
- /// <summary>
- /// __m128i _mm_abs_epi16 (__m128i a)
- /// PABSW xmm, xmm/m128
- /// </summary>
- public static Vector128<ushort> Abs(Vector128<short> value) => Abs(value);
- /// <summary>
- /// __m128i _mm_abs_epi32 (__m128i a)
- /// PABSD xmm, xmm/m128
- /// </summary>
- public static Vector128<uint> Abs(Vector128<int> value) => Abs(value);
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// </summary>
- public static Vector128<sbyte> AlignRight(Vector128<sbyte> left, Vector128<sbyte> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<byte> AlignRight(Vector128<byte> left, Vector128<byte> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<short> AlignRight(Vector128<short> left, Vector128<short> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<ushort> AlignRight(Vector128<ushort> left, Vector128<ushort> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<int> AlignRight(Vector128<int> left, Vector128<int> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<uint> AlignRight(Vector128<uint> left, Vector128<uint> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<long> AlignRight(Vector128<long> left, Vector128<long> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m128i _mm_alignr_epi8 (__m128i a, __m128i b, int count)
- /// PALIGNR xmm, xmm/m128, imm8
- /// This intrinsic generates PALIGNR that operates over bytes rather than elements of the vectors.
- /// </summary>
- public static Vector128<ulong> AlignRight(Vector128<ulong> left, Vector128<ulong> right, byte mask) => AlignRight(left, right, mask);
-
- /// <summary>
- /// __m128i _mm_hadd_epi16 (__m128i a, __m128i b)
- /// PHADDW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> HorizontalAdd(Vector128<short> left, Vector128<short> right) => HorizontalAdd(left, right);
- /// <summary>
- /// __m128i _mm_hadd_epi32 (__m128i a, __m128i b)
- /// PHADDD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> HorizontalAdd(Vector128<int> left, Vector128<int> right) => HorizontalAdd(left, right);
-
- /// <summary>
- /// __m128i _mm_hadds_epi16 (__m128i a, __m128i b)
- /// PHADDSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> HorizontalAddSaturate(Vector128<short> left, Vector128<short> right) => HorizontalAddSaturate(left, right);
-
- /// <summary>
- /// __m128i _mm_hsub_epi16 (__m128i a, __m128i b)
- /// PHSUBW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> HorizontalSubtract(Vector128<short> left, Vector128<short> right) => HorizontalSubtract(left, right);
- /// <summary>
- /// __m128i _mm_hsub_epi32 (__m128i a, __m128i b)
- /// PHSUBD xmm, xmm/m128
- /// </summary>
- public static Vector128<int> HorizontalSubtract(Vector128<int> left, Vector128<int> right) => HorizontalSubtract(left, right);
-
- /// <summary>
- /// __m128i _mm_hsubs_epi16 (__m128i a, __m128i b)
- /// PHSUBSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> HorizontalSubtractSaturate(Vector128<short> left, Vector128<short> right) => HorizontalSubtractSaturate(left, right);
-
- /// <summary>
- /// __m128i _mm_maddubs_epi16 (__m128i a, __m128i b)
- /// PMADDUBSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> MultiplyAddAdjacent(Vector128<byte> left, Vector128<sbyte> right) => MultiplyAddAdjacent(left, right);
-
- /// <summary>
- /// __m128i _mm_mulhrs_epi16 (__m128i a, __m128i b)
- /// PMULHRSW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> MultiplyHighRoundScale(Vector128<short> left, Vector128<short> right) => MultiplyHighRoundScale(left, right);
-
- /// <summary>
- /// __m128i _mm_shuffle_epi8 (__m128i a, __m128i b)
- /// PSHUFB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Shuffle(Vector128<sbyte> value, Vector128<sbyte> mask) => Shuffle(value, mask);
-
- /// <summary>
- /// __m128i _mm_shuffle_epi8 (__m128i a, __m128i b)
- /// PSHUFB xmm, xmm/m128
- /// </summary>
- public static Vector128<byte> Shuffle(Vector128<byte> value, Vector128<byte> mask) => Shuffle(value, mask);
-
- /// <summary>
- /// __m128i _mm_sign_epi8 (__m128i a, __m128i b)
- /// PSIGNB xmm, xmm/m128
- /// </summary>
- public static Vector128<sbyte> Sign(Vector128<sbyte> left, Vector128<sbyte> right) => Sign(left, right);
- /// <summary>
- /// __m128i _mm_sign_epi16 (__m128i a, __m128i b)
- /// PSIGNW xmm, xmm/m128
- /// </summary>
- public static Vector128<short> Sign(Vector128<short> left, Vector128<short> right) => Sign(left, right);
- /// <summary>
- /// __m128i _mm_sign_epi32 (__m128i a, __m128i b)
- /// PSIGND xmm, xmm/m128
- /// </summary>
- public static Vector128<int> Sign(Vector128<int> left, Vector128<int> right) => Sign(left, right);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs
deleted file mode 100644
index 5ae3f8d06f3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs
+++ /dev/null
@@ -1,801 +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 System.Collections.Generic;
-using System.ComponentModel;
-using System.Diagnostics;
-using System.IO;
-using System.Reflection;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-namespace System.Runtime.Loader
-{
- public partial class AssemblyLoadContext
- {
- private enum InternalState
- {
- /// <summary>
- /// The ALC is alive (default)
- /// </summary>
- Alive,
-
- /// <summary>
- /// The unload process has started, the Unloading event will be called
- /// once the underlying LoaderAllocator has been finalized
- /// </summary>
- Unloading
- }
-
- private static readonly Dictionary<long, WeakReference<AssemblyLoadContext>> s_allContexts = new Dictionary<long, WeakReference<AssemblyLoadContext>>();
- private static long s_nextId;
-
-#region private data members
- // If you modify any of these fields, you must also update the
- // AssemblyLoadContextBaseObject structure in object.h
-
- // synchronization primitive to protect against usage of this instance while unloading
- private readonly object _unloadLock;
-
- private event Func<Assembly, string, IntPtr>? _resolvingUnmanagedDll;
-
- private event Func<AssemblyLoadContext, AssemblyName, Assembly>? _resolving;
-
- private event Action<AssemblyLoadContext>? _unloading;
-
- private readonly string? _name;
-
- // Contains the reference to VM's representation of the AssemblyLoadContext
- private readonly IntPtr _nativeAssemblyLoadContext;
-
- // Id used by s_allContexts
- private readonly long _id;
-
- // Indicates the state of this ALC (Alive or in Unloading state)
- private InternalState _state;
-
- private readonly bool _isCollectible;
-#endregion
-
- protected AssemblyLoadContext() : this(false, false, null)
- {
- }
-
- protected AssemblyLoadContext(bool isCollectible) : this(false, isCollectible, null)
- {
- }
-
- public AssemblyLoadContext(string? name, bool isCollectible = false) : this(false, isCollectible, name)
- {
- }
-
- private protected AssemblyLoadContext(bool representsTPALoadContext, bool isCollectible, string? name)
- {
- // Initialize the VM side of AssemblyLoadContext if not already done.
- _isCollectible = isCollectible;
-
- _name = name;
-
- // The _unloadLock needs to be assigned after the IsCollectible to ensure proper behavior of the finalizer
- // even in case the following allocation fails or the thread is aborted between these two lines.
- _unloadLock = new object();
-
- if (!isCollectible)
- {
- // For non collectible AssemblyLoadContext, the finalizer should never be called and thus the AssemblyLoadContext should not
- // be on the finalizer queue.
- GC.SuppressFinalize(this);
- }
-
- // If this is a collectible ALC, we are creating a weak handle tracking resurrection otherwise we use a strong handle
- var thisHandle = GCHandle.Alloc(this, IsCollectible ? GCHandleType.WeakTrackResurrection : GCHandleType.Normal);
- var thisHandlePtr = GCHandle.ToIntPtr(thisHandle);
- _nativeAssemblyLoadContext = InitializeAssemblyLoadContext(thisHandlePtr, representsTPALoadContext, isCollectible);
-
- // Add this instance to the list of alive ALC
- lock (s_allContexts)
- {
- _id = s_nextId++;
- s_allContexts.Add(_id, new WeakReference<AssemblyLoadContext>(this, true));
- }
- }
-
- ~AssemblyLoadContext()
- {
- // Use the _unloadLock as a guard to detect the corner case when the constructor of the AssemblyLoadContext was not executed
- // e.g. due to the JIT failing to JIT it.
- if (_unloadLock != null)
- {
- // Only valid for a Collectible ALC. Non-collectible ALCs have the finalizer suppressed.
- Debug.Assert(IsCollectible);
- // We get here only in case the explicit Unload was not initiated.
- Debug.Assert(_state != InternalState.Unloading);
- InitiateUnload();
- }
- }
-
- private void RaiseUnloadEvent()
- {
- // Ensure that we raise the Unload event only once
- Interlocked.Exchange(ref _unloading, null!)?.Invoke(this);
- }
-
- private void InitiateUnload()
- {
- RaiseUnloadEvent();
-
- // When in Unloading state, we are not supposed to be called on the finalizer
- // as the native side is holding a strong reference after calling Unload
- lock (_unloadLock)
- {
- Debug.Assert(_state == InternalState.Alive);
-
- var thisStrongHandle = GCHandle.Alloc(this, GCHandleType.Normal);
- var thisStrongHandlePtr = GCHandle.ToIntPtr(thisStrongHandle);
- // The underlying code will transform the original weak handle
- // created by InitializeLoadContext to a strong handle
- PrepareForAssemblyLoadContextRelease(_nativeAssemblyLoadContext, thisStrongHandlePtr);
-
- _state = InternalState.Unloading;
- }
-
- lock (s_allContexts)
- {
- s_allContexts.Remove(_id);
- }
- }
-
- public IEnumerable<Assembly> Assemblies
- {
- get
- {
- foreach (Assembly a in GetLoadedAssemblies())
- {
- AssemblyLoadContext? alc = GetLoadContext(a);
-
- if (alc == this)
- {
- yield return a;
- }
- }
- }
- }
-
- // Event handler for resolving native libraries.
- // This event is raised if the native library could not be resolved via
- // the default resolution logic [including AssemblyLoadContext.LoadUnmanagedDll()]
- //
- // Inputs: Invoking assembly, and library name to resolve
- // Returns: A handle to the loaded native library
- public event Func<Assembly, string, IntPtr>? ResolvingUnmanagedDll
- {
- add
- {
- _resolvingUnmanagedDll += value;
- }
- remove
- {
- _resolvingUnmanagedDll -= value;
- }
- }
-
- // Event handler for resolving managed assemblies.
- // This event is raised if the managed assembly could not be resolved via
- // the default resolution logic [including AssemblyLoadContext.Load()]
- //
- // Inputs: The AssemblyLoadContext and AssemblyName to be loaded
- // Returns: The Loaded assembly object.
- public event Func<AssemblyLoadContext, AssemblyName, Assembly?>? Resolving
- {
- add
- {
- _resolving += value;
- }
- remove
- {
- _resolving -= value;
- }
- }
-
- public event Action<AssemblyLoadContext>? Unloading
- {
- add
- {
- _unloading += value;
- }
- remove
- {
- _unloading -= value;
- }
- }
-
-#region AppDomainEvents
- // Occurs when an Assembly is loaded
- internal static event AssemblyLoadEventHandler? AssemblyLoad;
-
- // Occurs when resolution of type fails
- internal static event ResolveEventHandler? TypeResolve;
-
- // Occurs when resolution of resource fails
- internal static event ResolveEventHandler? ResourceResolve;
-
- // Occurs when resolution of assembly fails
- // This event is fired after resolve events of AssemblyLoadContext fails
- internal static event ResolveEventHandler? AssemblyResolve;
-#endregion
-
- public static AssemblyLoadContext Default => DefaultAssemblyLoadContext.s_loadContext;
-
- public bool IsCollectible => _isCollectible;
-
- public string? Name => _name;
-
- public override string ToString() => "\"" + Name + "\" " + GetType().ToString() + " #" + _id;
-
- public static IEnumerable<AssemblyLoadContext> All
- {
- get
- {
- _ = AssemblyLoadContext.Default; // Ensure default is initialized
-
- List<WeakReference<AssemblyLoadContext>>? alcList = null;
- lock (s_allContexts)
- {
- // To make this thread safe we need a quick snapshot while locked
- alcList = new List<WeakReference<AssemblyLoadContext>>(s_allContexts.Values);
- }
-
- foreach (WeakReference<AssemblyLoadContext> weakAlc in alcList)
- {
- if (weakAlc.TryGetTarget(out AssemblyLoadContext? alc))
- {
- yield return alc;
- }
- }
- }
- }
-
- // Helper to return AssemblyName corresponding to the path of an IL assembly
- public static AssemblyName GetAssemblyName(string assemblyPath)
- {
- if (assemblyPath == null)
- {
- throw new ArgumentNullException(nameof(assemblyPath));
- }
-
- return AssemblyName.GetAssemblyName(assemblyPath);
- }
-
- // Custom AssemblyLoadContext implementations can override this
- // method to perform custom processing and use one of the protected
- // helpers above to load the assembly.
- protected virtual Assembly? Load(AssemblyName assemblyName)
- {
- return null;
- }
-
-#if !CORERT
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public Assembly LoadFromAssemblyName(AssemblyName assemblyName)
- {
- if (assemblyName == null)
- throw new ArgumentNullException(nameof(assemblyName));
-
- // Attempt to load the assembly, using the same ordering as static load, in the current load context.
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return Assembly.Load(assemblyName, ref stackMark, this);
- }
-#endif
-
- // These methods load assemblies into the current AssemblyLoadContext
- // They may be used in the implementation of an AssemblyLoadContext derivation
- public Assembly LoadFromAssemblyPath(string assemblyPath)
- {
- if (assemblyPath == null)
- {
- throw new ArgumentNullException(nameof(assemblyPath));
- }
-
- if (PathInternal.IsPartiallyQualified(assemblyPath))
- {
- throw new ArgumentException(SR.Format(SR.Argument_AbsolutePathRequired, assemblyPath), nameof(assemblyPath));
- }
-
- lock (_unloadLock)
- {
- VerifyIsAlive();
-
- return InternalLoadFromPath(assemblyPath, null);
- }
- }
-
- public Assembly LoadFromNativeImagePath(string nativeImagePath, string? assemblyPath)
- {
- if (nativeImagePath == null)
- {
- throw new ArgumentNullException(nameof(nativeImagePath));
- }
-
- if (PathInternal.IsPartiallyQualified(nativeImagePath))
- {
- throw new ArgumentException(SR.Format(SR.Argument_AbsolutePathRequired, nativeImagePath), nameof(nativeImagePath));
- }
-
- if (assemblyPath != null && PathInternal.IsPartiallyQualified(assemblyPath))
- {
- throw new ArgumentException(SR.Format(SR.Argument_AbsolutePathRequired, assemblyPath), nameof(assemblyPath));
- }
-
- lock (_unloadLock)
- {
- VerifyIsAlive();
-
- return InternalLoadFromPath(assemblyPath, nativeImagePath);
- }
- }
-
- public Assembly LoadFromStream(Stream assembly)
- {
- return LoadFromStream(assembly, null);
- }
-
- public Assembly LoadFromStream(Stream assembly, Stream? assemblySymbols)
- {
- if (assembly == null)
- {
- throw new ArgumentNullException(nameof(assembly));
- }
-
- int iAssemblyStreamLength = (int)assembly.Length;
-
- if (iAssemblyStreamLength <= 0)
- {
- throw new BadImageFormatException(SR.BadImageFormat_BadILFormat);
- }
-
- // Allocate the byte[] to hold the assembly
- byte[] arrAssembly = new byte[iAssemblyStreamLength];
-
- // Copy the assembly to the byte array
- assembly.Read(arrAssembly, 0, iAssemblyStreamLength);
-
- // Get the symbol stream in byte[] if provided
- byte[]? arrSymbols = null;
- if (assemblySymbols != null)
- {
- var iSymbolLength = (int)assemblySymbols.Length;
- arrSymbols = new byte[iSymbolLength];
-
- assemblySymbols.Read(arrSymbols, 0, iSymbolLength);
- }
-
- lock (_unloadLock)
- {
- VerifyIsAlive();
-
- return InternalLoad(arrAssembly, arrSymbols);
- }
- }
-
- // This method provides a way for overriders of LoadUnmanagedDll() to load an unmanaged DLL from a specific path in a
- // platform-independent way. The DLL is loaded with default load flags.
- protected IntPtr LoadUnmanagedDllFromPath(string unmanagedDllPath)
- {
- if (unmanagedDllPath == null)
- {
- throw new ArgumentNullException(nameof(unmanagedDllPath));
- }
-
- if (unmanagedDllPath.Length == 0)
- {
- throw new ArgumentException(SR.Argument_EmptyPath, nameof(unmanagedDllPath));
- }
-
- if (PathInternal.IsPartiallyQualified(unmanagedDllPath))
- {
- throw new ArgumentException(SR.Format(SR.Argument_AbsolutePathRequired, unmanagedDllPath), nameof(unmanagedDllPath));
- }
-
- return NativeLibrary.Load(unmanagedDllPath);
- }
-
- // Custom AssemblyLoadContext implementations can override this
- // method to perform the load of unmanaged native dll
- // This function needs to return the HMODULE of the dll it loads
- protected virtual IntPtr LoadUnmanagedDll(string unmanagedDllName)
- {
- // defer to default coreclr policy of loading unmanaged dll
- return IntPtr.Zero;
- }
-
- public void Unload()
- {
- if (!IsCollectible)
- {
- throw new InvalidOperationException(SR.AssemblyLoadContext_Unload_CannotUnloadIfNotCollectible);
- }
-
- GC.SuppressFinalize(this);
- InitiateUnload();
- }
-
- internal static void OnProcessExit()
- {
- lock (s_allContexts)
- {
- foreach (KeyValuePair<long, WeakReference<AssemblyLoadContext>> alcAlive in s_allContexts)
- {
- if (alcAlive.Value.TryGetTarget(out AssemblyLoadContext? alc))
- {
- alc.RaiseUnloadEvent();
- }
- }
- }
- }
-
- private void VerifyIsAlive()
- {
- if (_state != InternalState.Alive)
- {
- throw new InvalidOperationException(SR.AssemblyLoadContext_Verify_NotUnloading);
- }
- }
-
- private static AsyncLocal<AssemblyLoadContext?>? s_asyncLocalCurrent;
-
- /// <summary>Nullable current AssemblyLoadContext used for context sensitive reflection APIs</summary>
- /// <remarks>
- /// This is an advanced setting used in reflection assembly loading scenarios.
- ///
- /// There are a set of contextual reflection APIs which load managed assemblies through an inferred AssemblyLoadContext.
- /// * <see cref="System.Activator.CreateInstance" />
- /// * <see cref="System.Reflection.Assembly.Load" />
- /// * <see cref="System.Reflection.Assembly.GetType" />
- /// * <see cref="System.Type.GetType" />
- ///
- /// When CurrentContextualReflectionContext is null, the AssemblyLoadContext is inferred.
- /// The inference logic is simple.
- /// * For static methods, it is the AssemblyLoadContext which loaded the method caller's assembly.
- /// * For instance methods, it is the AssemblyLoadContext which loaded the instance's assembly.
- ///
- /// When this property is set, the CurrentContextualReflectionContext value is used by these contextual reflection APIs for loading.
- ///
- /// This property is typically set in a using block by
- /// <see cref="System.Runtime.Loader.AssemblyLoadContext.EnterContextualReflection"/>.
- ///
- /// The property is stored in an AsyncLocal&lt;AssemblyLoadContext&gt;. This means the setting can be unique for every async or thread in the process.
- ///
- /// For more details see https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/AssemblyLoadContext.ContextualReflection.md
- /// </remarks>
- public static AssemblyLoadContext? CurrentContextualReflectionContext => s_asyncLocalCurrent?.Value;
-
- private static void SetCurrentContextualReflectionContext(AssemblyLoadContext? value)
- {
- if (s_asyncLocalCurrent == null)
- {
- Interlocked.CompareExchange<AsyncLocal<AssemblyLoadContext?>?>(ref s_asyncLocalCurrent, new AsyncLocal<AssemblyLoadContext?>(), null);
- }
- s_asyncLocalCurrent!.Value = value; // Remove ! when compiler specially-recognizes CompareExchange for nullability
- }
-
- /// <summary>Enter scope using this AssemblyLoadContext for ContextualReflection</summary>
- /// <returns>A disposable ContextualReflectionScope for use in a using block</returns>
- /// <remarks>
- /// Sets CurrentContextualReflectionContext to this instance.
- /// <see cref="System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext"/>
- ///
- /// Returns a disposable ContextualReflectionScope for use in a using block. When the using calls the
- /// Dispose() method, it restores the ContextualReflectionScope to its previous value.
- /// </remarks>
- public ContextualReflectionScope EnterContextualReflection()
- {
- return new ContextualReflectionScope(this);
- }
-
- /// <summary>Enter scope using this AssemblyLoadContext for ContextualReflection</summary>
- /// <param name="activating">Set CurrentContextualReflectionContext to the AssemblyLoadContext which loaded activating.</param>
- /// <returns>A disposable ContextualReflectionScope for use in a using block</returns>
- /// <remarks>
- /// Sets CurrentContextualReflectionContext to to the AssemblyLoadContext which loaded activating.
- /// <see cref="System.Runtime.Loader.AssemblyLoadContext.CurrentContextualReflectionContext"/>
- ///
- /// Returns a disposable ContextualReflectionScope for use in a using block. When the using calls the
- /// Dispose() method, it restores the ContextualReflectionScope to its previous value.
- /// </remarks>
- public static ContextualReflectionScope EnterContextualReflection(Assembly? activating)
- {
- if (activating == null)
- return new ContextualReflectionScope(null);
-
- AssemblyLoadContext? assemblyLoadContext = GetLoadContext(activating);
-
- if (assemblyLoadContext == null)
- {
- // All RuntimeAssemblies & Only RuntimeAssemblies have an AssemblyLoadContext
- throw new ArgumentException(SR.Arg_MustBeRuntimeAssembly, nameof(activating));
- }
-
- return assemblyLoadContext.EnterContextualReflection();
- }
-
- /// <summary>Opaque disposable struct used to restore CurrentContextualReflectionContext</summary>
- /// <remarks>
- /// This is an implmentation detail of the AssemblyLoadContext.EnterContextualReflection APIs.
- /// It is a struct, to avoid heap allocation.
- /// It is required to be public to avoid boxing.
- /// <see cref="System.Runtime.Loader.AssemblyLoadContext.EnterContextualReflection"/>
- /// </remarks>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public struct ContextualReflectionScope : IDisposable
- {
- private readonly AssemblyLoadContext? _activated;
- private readonly AssemblyLoadContext? _predecessor;
- private readonly bool _initialized;
-
- internal ContextualReflectionScope(AssemblyLoadContext? activating)
- {
- _predecessor = AssemblyLoadContext.CurrentContextualReflectionContext;
- AssemblyLoadContext.SetCurrentContextualReflectionContext(activating);
- _activated = activating;
- _initialized = true;
- }
-
- public void Dispose()
- {
- if (_initialized)
- {
- // Do not clear initialized. Always restore the _predecessor in Dispose()
- // _initialized = false;
- AssemblyLoadContext.SetCurrentContextualReflectionContext(_predecessor);
- }
- }
- }
-
-#if !CORERT
- // This method is invoked by the VM when using the host-provided assembly load context
- // implementation.
- private static Assembly? Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
- {
- AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target)!;
-
- return context.ResolveUsingLoad(assemblyName);
- }
-
- // This method is invoked by the VM to resolve an assembly reference using the Resolving event
- // after trying assembly resolution via Load override and TPA load context without success.
- private static Assembly? ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
- {
- AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target)!;
-
- // Invoke the AssemblyResolve event callbacks if wired up
- return context.ResolveUsingEvent(assemblyName);
- }
-
- // This method is invoked by the VM to resolve a satellite assembly reference
- // after trying assembly resolution via Load override without success.
- private static Assembly? ResolveSatelliteAssembly(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
- {
- AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target)!;
-
- // Invoke the ResolveSatelliteAssembly method
- return context.ResolveSatelliteAssembly(assemblyName);
- }
-
- private Assembly? GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName)
- {
- Assembly? resolvedAssembly = null;
-
- Func<AssemblyLoadContext, AssemblyName, Assembly>? resolvingHandler = _resolving;
-
- if (resolvingHandler != null)
- {
- // Loop through the event subscribers and return the first non-null Assembly instance
- foreach (Func<AssemblyLoadContext, AssemblyName, Assembly> handler in resolvingHandler.GetInvocationList())
- {
- resolvedAssembly = handler(this, assemblyName);
-#if CORECLR
- if (AssemblyLoadContext.IsTracingEnabled())
- {
- AssemblyLoadContext.TraceResolvingHandlerInvoked(
- assemblyName.FullName,
- handler.Method.Name,
- this != AssemblyLoadContext.Default ? ToString() : Name,
- resolvedAssembly?.FullName,
- resolvedAssembly != null && !resolvedAssembly.IsDynamic ? resolvedAssembly.Location : null);
- }
-#endif // CORECLR
- if (resolvedAssembly != null)
- {
- return resolvedAssembly;
- }
- }
- }
-
- return null;
- }
-
- private static Assembly ValidateAssemblyNameWithSimpleName(Assembly assembly, string? requestedSimpleName)
- {
- if (string.IsNullOrEmpty(requestedSimpleName))
- {
- throw new ArgumentException(SR.ArgumentNull_AssemblyNameName);
- }
-
- // Get the name of the loaded assembly
- string? loadedSimpleName = null;
-
- // Derived type's Load implementation is expected to use one of the LoadFrom* methods to get the assembly
- // which is a RuntimeAssembly instance. However, since Assembly type can be used build any other artifact (e.g. AssemblyBuilder),
- // we need to check for RuntimeAssembly.
- RuntimeAssembly? rtLoadedAssembly = assembly as RuntimeAssembly;
- if (rtLoadedAssembly != null)
- {
- loadedSimpleName = rtLoadedAssembly.GetSimpleName();
- }
-
- // The simple names should match at the very least
- if (string.IsNullOrEmpty(loadedSimpleName) || !requestedSimpleName.Equals(loadedSimpleName, StringComparison.InvariantCultureIgnoreCase))
- {
- throw new InvalidOperationException(SR.Argument_CustomAssemblyLoadContextRequestedNameMismatch);
- }
-
- return assembly;
- }
-
- private Assembly? ResolveUsingLoad(AssemblyName assemblyName)
- {
- string? simpleName = assemblyName.Name;
- Assembly? assembly = Load(assemblyName);
-
- if (assembly != null)
- {
- assembly = ValidateAssemblyNameWithSimpleName(assembly, simpleName);
- }
-
- return assembly;
- }
-
- private Assembly? ResolveUsingEvent(AssemblyName assemblyName)
- {
- string? simpleName = assemblyName.Name;
-
- // Invoke the Resolving event callbacks if wired up
- Assembly? assembly = GetFirstResolvedAssemblyFromResolvingEvent(assemblyName);
- if (assembly != null)
- {
- assembly = ValidateAssemblyNameWithSimpleName(assembly, simpleName);
- }
-
- return assembly;
- }
-
- // This method is called by the VM.
- private static void OnAssemblyLoad(RuntimeAssembly assembly)
- {
- AssemblyLoad?.Invoke(AppDomain.CurrentDomain, new AssemblyLoadEventArgs(assembly));
- }
-
- // This method is called by the VM.
- private static RuntimeAssembly? OnResourceResolve(RuntimeAssembly assembly, string resourceName)
- {
- return InvokeResolveEvent(ResourceResolve, assembly, resourceName);
- }
-
- // This method is called by the VM
- private static RuntimeAssembly? OnTypeResolve(RuntimeAssembly assembly, string typeName)
- {
- return InvokeResolveEvent(TypeResolve, assembly, typeName);
- }
-
- // This method is called by the VM.
- private static RuntimeAssembly? OnAssemblyResolve(RuntimeAssembly assembly, string assemblyFullName)
- {
- return InvokeResolveEvent(AssemblyResolve, assembly, assemblyFullName);
- }
-
- private static RuntimeAssembly? InvokeResolveEvent(ResolveEventHandler? eventHandler, RuntimeAssembly assembly, string name)
- {
- if (eventHandler == null)
- return null;
-
- var args = new ResolveEventArgs(name, assembly);
-
- foreach (ResolveEventHandler handler in eventHandler.GetInvocationList())
- {
- Assembly? asm = handler(AppDomain.CurrentDomain, args);
-#if CORECLR
- if (eventHandler == AssemblyResolve && AssemblyLoadContext.IsTracingEnabled())
- {
- AssemblyLoadContext.TraceAssemblyResolveHandlerInvoked(
- name,
- handler.Method.Name,
- asm?.FullName,
- asm != null && !asm.IsDynamic ? asm.Location : null);
- }
-#endif // CORECLR
- RuntimeAssembly? ret = GetRuntimeAssembly(asm);
- if (ret != null)
- return ret;
- }
-
- return null;
- }
-#endif // !CORERT
-
- private Assembly? ResolveSatelliteAssembly(AssemblyName assemblyName)
- {
- // Called by native runtime when CultureName is not empty
- Debug.Assert(assemblyName.CultureName?.Length > 0);
-
- const string SatelliteSuffix = ".resources";
-
- if (assemblyName.Name == null || !assemblyName.Name.EndsWith(SatelliteSuffix, StringComparison.Ordinal))
- return null;
-
- string parentAssemblyName = assemblyName.Name.Substring(0, assemblyName.Name.Length - SatelliteSuffix.Length);
-
- Assembly parentAssembly = LoadFromAssemblyName(new AssemblyName(parentAssemblyName));
-
- AssemblyLoadContext parentALC = GetLoadContext(parentAssembly)!;
-
- string parentDirectory = Path.GetDirectoryName(parentAssembly.Location)!;
-
- string assemblyPath = Path.Combine(parentDirectory, assemblyName.CultureName!, $"{assemblyName.Name}.dll");
-
- if (Internal.IO.File.InternalExists(assemblyPath))
- {
- return parentALC.LoadFromAssemblyPath(assemblyPath);
- }
- else if (Path.IsCaseSensitive)
- {
- assemblyPath = Path.Combine(parentDirectory, assemblyName.CultureName!.ToLowerInvariant(), $"{assemblyName.Name}.dll");
-
- if (Internal.IO.File.InternalExists(assemblyPath))
- {
- return parentALC.LoadFromAssemblyPath(assemblyPath);
- }
- }
-
- return null;
- }
-
- internal IntPtr GetResolvedUnmanagedDll(Assembly assembly, string unmanagedDllName)
- {
- IntPtr resolvedDll = IntPtr.Zero;
-
- Func<Assembly, string, IntPtr>? dllResolveHandler = _resolvingUnmanagedDll;
-
- if (dllResolveHandler != null)
- {
- // Loop through the event subscribers and return the first non-null native library handle
- foreach (Func<Assembly, string, IntPtr> handler in dllResolveHandler.GetInvocationList())
- {
- resolvedDll = handler(assembly, unmanagedDllName);
- if (resolvedDll != IntPtr.Zero)
- {
- return resolvedDll;
- }
- }
- }
-
- return IntPtr.Zero;
- }
- }
-
- internal sealed class DefaultAssemblyLoadContext : AssemblyLoadContext
- {
- internal static readonly AssemblyLoadContext s_loadContext = new DefaultAssemblyLoadContext();
-
- internal DefaultAssemblyLoadContext() : base(true, false, "Default")
- {
- }
- }
-
- internal sealed class IndividualAssemblyLoadContext : AssemblyLoadContext
- {
- internal IndividualAssemblyLoadContext(string name) : base(false, false, name)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.Unix.cs
deleted file mode 100644
index f83ceae0dee..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.Unix.cs
+++ /dev/null
@@ -1,68 +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 System.Collections.Generic;
-using System.IO;
-
-namespace System.Runtime.Loader
-{
- internal partial struct LibraryNameVariation
- {
- private const string LibraryNamePrefix = "lib";
-#if PLATFORM_OSX
- private const string LibraryNameSuffix = ".dylib";
-#else
- private const string LibraryNameSuffix = ".so";
-#endif
-
- internal static IEnumerable<LibraryNameVariation> DetermineLibraryNameVariations(string libName, bool isRelativePath)
- {
- // This is a copy of the logic in DetermineLibNameVariations in dllimport.cpp in CoreCLR
-
- if (!isRelativePath)
- {
- yield return new LibraryNameVariation(string.Empty, string.Empty);
- }
- else
- {
- bool containsSuffix = false;
- int indexOfSuffix = libName.IndexOf(LibraryNameSuffix, StringComparison.OrdinalIgnoreCase);
- if (indexOfSuffix >= 0)
- {
- indexOfSuffix += LibraryNameSuffix.Length;
- containsSuffix = indexOfSuffix == libName.Length || libName[indexOfSuffix] == '.';
- }
-
- bool containsDelim = libName.Contains(Path.DirectorySeparatorChar);
-
- if (containsSuffix)
- {
- yield return new LibraryNameVariation(string.Empty, string.Empty);
- if (!containsDelim)
- {
- yield return new LibraryNameVariation(LibraryNamePrefix, string.Empty);
- }
- yield return new LibraryNameVariation(string.Empty, LibraryNameSuffix);
- if (!containsDelim)
- {
- yield return new LibraryNameVariation(LibraryNamePrefix, LibraryNameSuffix);
- }
- }
- else
- {
- yield return new LibraryNameVariation(string.Empty, LibraryNameSuffix);
- if (!containsDelim)
- {
- yield return new LibraryNameVariation(LibraryNamePrefix, LibraryNameSuffix);
- }
- yield return new LibraryNameVariation(string.Empty, string.Empty);
- if (!containsDelim)
- {
- yield return new LibraryNameVariation(LibraryNamePrefix, string.Empty);
- }
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.Windows.cs
deleted file mode 100644
index 64b9e17075a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.Windows.cs
+++ /dev/null
@@ -1,27 +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 System.Collections.Generic;
-
-namespace System.Runtime.Loader
-{
- internal partial struct LibraryNameVariation
- {
- private const string LibraryNameSuffix = ".dll";
-
- internal static IEnumerable<LibraryNameVariation> DetermineLibraryNameVariations(string libName, bool isRelativePath)
- {
- // This is a copy of the logic in DetermineLibNameVariations in dllimport.cpp in CoreCLR
-
- yield return new LibraryNameVariation(string.Empty, string.Empty);
-
- if (isRelativePath &&
- !libName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) &&
- !libName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
- {
- yield return new LibraryNameVariation(string.Empty, LibraryNameSuffix);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.cs
deleted file mode 100644
index 2b11f8a9bef..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/LibraryNameVariation.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Runtime.Loader
-{
- internal partial struct LibraryNameVariation
- {
- public string Prefix;
- public string Suffix;
-
- public LibraryNameVariation(string prefix, string suffix)
- {
- Prefix = prefix;
- Suffix = suffix;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.Unix.cs
deleted file mode 100644
index b63068eb26a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.Unix.cs
+++ /dev/null
@@ -1,40 +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.
-
-namespace System.Runtime
-{
- public sealed partial class MemoryFailPoint
- {
- private static ulong GetTopOfMemory()
- {
- // These values are optimistic assumptions. In reality the value will
- // often be lower.
- return IntPtr.Size == 4 ? uint.MaxValue : ulong.MaxValue;
- }
-
- private static bool CheckForAvailableMemory(out ulong availPageFile, out ulong totalAddressSpaceFree)
- {
- // TODO: Implement
- availPageFile = 0;
- totalAddressSpaceFree = 0;
- return false;
- }
-
- // Based on the shouldThrow parameter, this will throw an exception, or
- // returns whether there is enough space. In all cases, we update
- // our last known free address space, hopefully avoiding needing to
- // probe again.
- private static void CheckForFreeAddressSpace(ulong size, bool shouldThrow)
- {
- // Unreachable until CheckForAvailableMemory is implemented
- }
-
- // Allocate a specified number of bytes, commit them and free them. This should enlarge
- // page file if necessary and possible.
- private static void GrowPageFileIfNecessaryAndPossible(UIntPtr numBytes)
- {
- // Unreachable until CheckForAvailableMemory is implemented
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.Windows.cs
deleted file mode 100644
index 7a8ed0c1d18..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.Windows.cs
+++ /dev/null
@@ -1,102 +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 System.IO;
-
-namespace System.Runtime
-{
- public sealed partial class MemoryFailPoint
- {
- private static ulong GetTopOfMemory()
- {
- Interop.Kernel32.GetSystemInfo(out Interop.Kernel32.SYSTEM_INFO info);
- return (ulong)info.lpMaximumApplicationAddress;
- }
-
- private static bool CheckForAvailableMemory(out ulong availPageFile, out ulong totalAddressSpaceFree)
- {
- bool r;
- Interop.Kernel32.MEMORYSTATUSEX memory = default;
- r = Interop.Kernel32.GlobalMemoryStatusEx(ref memory);
- if (!r)
- throw Win32Marshal.GetExceptionForLastWin32Error();
- availPageFile = memory.availPageFile;
- totalAddressSpaceFree = memory.availVirtual;
- // Console.WriteLine($"Memory gate: Mem load: {memory.memoryLoad}% Available memory (physical + page file): {(memory.availPageFile >> 20)} MB Total free address space: {memory.availVirtual >> 20} MB GC Heap: {(GC.GetTotalMemory(true) >> 20)} MB");
- return true;
- }
-
- // Based on the shouldThrow parameter, this will throw an exception.
- // In all cases, we update our last known free address space, hopefully
- // avoiding needing to probe again.
- private static unsafe void CheckForFreeAddressSpace(ulong size, bool shouldThrow)
- {
- // Start walking the address space at 0. VirtualAlloc may wrap
- // around the address space. We don't need to find the exact
- // pages that VirtualAlloc would return - we just need to
- // know whether VirtualAlloc could succeed.
- ulong freeSpaceAfterGCHeap = MemFreeAfterAddress(null, size);
-
- // Console.WriteLine($"MemoryFailPoint: Checked for free VA space. Found enough? {(freeSpaceAfterGCHeap >= size)} Asked for: {size} Found: {freeSpaceAfterGCHeap}");
-
- // We may set these without taking a lock - I don't believe
- // this will hurt, as long as we never increment this number in
- // the Dispose method. If we do an extra bit of checking every
- // once in a while, but we avoid taking a lock, we may win.
- LastKnownFreeAddressSpace = (long)freeSpaceAfterGCHeap;
- LastTimeCheckingAddressSpace = Environment.TickCount;
-
- if (freeSpaceAfterGCHeap < size && shouldThrow)
- throw new InsufficientMemoryException(SR.InsufficientMemory_MemFailPoint_VAFrag);
- }
-
- // Returns the amount of consecutive free memory available in a block
- // of pages. If we didn't have enough address space, we still return
- // a positive value < size, to help potentially avoid the overhead of
- // this check if we use a MemoryFailPoint with a smaller size next.
- private static unsafe ulong MemFreeAfterAddress(void* address, ulong size)
- {
- if (size >= s_topOfMemory)
- return 0;
-
- ulong largestFreeRegion = 0;
- Interop.Kernel32.MEMORY_BASIC_INFORMATION memInfo = default;
- UIntPtr sizeOfMemInfo = (UIntPtr)sizeof(Interop.Kernel32.MEMORY_BASIC_INFORMATION);
-
- while (((ulong)address) + size < s_topOfMemory)
- {
- UIntPtr r = Interop.Kernel32.VirtualQuery(address, ref memInfo, sizeOfMemInfo);
- if (r == UIntPtr.Zero)
- throw Win32Marshal.GetExceptionForLastWin32Error();
-
- ulong regionSize = memInfo.RegionSize.ToUInt64();
- if (memInfo.State == Interop.Kernel32.MEM_FREE)
- {
- if (regionSize >= size)
- return regionSize;
- else
- largestFreeRegion = Math.Max(largestFreeRegion, regionSize);
- }
- address = (void*)((ulong)address + regionSize);
- }
- return largestFreeRegion;
- }
-
- // Allocate a specified number of bytes, commit them and free them. This should enlarge
- // page file if necessary and possible.
- private static void GrowPageFileIfNecessaryAndPossible(UIntPtr numBytes)
- {
- unsafe
- {
- void* pMemory = Interop.Kernel32.VirtualAlloc(null, numBytes, Interop.Kernel32.MEM_COMMIT, Interop.Kernel32.PAGE_READWRITE);
- if (pMemory != null)
- {
- bool r = Interop.Kernel32.VirtualFree(pMemory, UIntPtr.Zero, Interop.Kernel32.MEM_RELEASE);
- if (!r)
- throw Win32Marshal.GetExceptionForLastWin32Error();
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.cs
deleted file mode 100644
index 04dcc95d38d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/MemoryFailPoint.cs
+++ /dev/null
@@ -1,404 +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.
-
-/*============================================================
-**
-**
-**
-** Provides a way for an app to not start an operation unless
-** there's a reasonable chance there's enough memory
-** available for the operation to succeed.
-**
-**
-===========================================================*/
-
-using System.Threading;
-using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
-using System.Diagnostics;
-
-/*
- This class allows an application to fail before starting certain
- activities. The idea is to fail early instead of failing in the middle
- of some long-running operation to increase the survivability of the
- application and ensure you don't have to write tricky code to handle an
- OOM anywhere in your app's code (which implies state corruption, meaning you
- should unload the appdomain, if you have a transacted environment to ensure
- rollback of individual transactions). This is an incomplete tool to attempt
- hoisting all your OOM failures from anywhere in your worker methods to one
- particular point where it is easier to handle an OOM failure, and you can
- optionally choose to not start a workitem if it will likely fail. This does
- not help the performance of your code directly (other than helping to avoid
- AD unloads). The point is to avoid starting work if it is likely to fail.
- The Enterprise Services team has used these memory gates effectively in the
- unmanaged world for a decade.
-
- In Whidbey, we will simply check to see if there is enough memory available
- in the OS's page file & attempt to ensure there might be enough space free
- within the process's address space (checking for address space fragmentation
- as well). We will not commit or reserve any memory. To avoid race conditions with
- other threads using MemoryFailPoints, we'll also keep track of a
- process-wide amount of memory "reserved" via all currently-active
- MemoryFailPoints. This has two problems:
- 1) This can account for memory twice. If a thread creates a
- MemoryFailPoint for 100 MB then allocates 99 MB, we'll see 99 MB
- less free memory and 100 MB less reserved memory. Yet, subtracting
- off the 100 MB is necessary because the thread may not have started
- allocating memory yet. Disposing of this class immediately after
- front-loaded allocations have completed is a great idea.
- 2) This is still vulnerable to race conditions with other threads that don't use
- MemoryFailPoints.
- So this class is far from perfect. But it may be good enough to
- meaningfully reduce the frequency of OutOfMemoryExceptions in managed apps.
-
- In Orcas or later, we might allocate some memory from the OS and add it
- to a allocation context for this thread. Obviously, at that point we need
- some way of conveying when we release this block of memory. So, we
- implemented IDisposable on this type in Whidbey and expect all users to call
- this from within a using block to provide lexical scope for their memory
- usage. The call to Dispose (implicit with the using block) will give us an
- opportunity to release this memory, perhaps. We anticipate this will give
- us the possibility of a more effective design in a future version.
-
- In Orcas, we may also need to differentiate between allocations that would
- go into the normal managed heap vs. the large object heap, or we should
- consider checking for enough free space in both locations (with any
- appropriate adjustments to ensure the memory is contiguous).
-*/
-
-namespace System.Runtime
-{
- public sealed partial class MemoryFailPoint : CriticalFinalizerObject, IDisposable
- {
- // Find the top section of user mode memory. Avoid the last 64K.
- // Windows reserves that block for the kernel, apparently, and doesn't
- // let us ask about that memory. But since we ask for memory in 1 MB
- // chunks, we don't have to special case this. Also, we need to
- // deal with 32 bit machines in 3 GB mode.
- // Using Win32's GetSystemInfo should handle all this for us.
- private static readonly ulong s_topOfMemory = GetTopOfMemory();
-
- // Walking the address space is somewhat expensive, taking around half
- // a millisecond. Doing that per transaction limits us to a max of
- // ~2000 transactions/second. Instead, let's do this address space
- // walk once every 10 seconds, or when we will likely fail. This
- // amortization scheme can reduce the cost of a memory gate by about
- // a factor of 100.
- private static long s_hiddenLastKnownFreeAddressSpace = 0;
- private static long s_hiddenLastTimeCheckingAddressSpace = 0;
- private const int CheckThreshold = 10 * 1000; // 10 seconds
-
- private static long LastKnownFreeAddressSpace
- {
- get => Volatile.Read(ref s_hiddenLastKnownFreeAddressSpace);
- set => Volatile.Write(ref s_hiddenLastKnownFreeAddressSpace, value);
- }
-
- private static void AddToLastKnownFreeAddressSpace(long addend) =>
- Interlocked.Add(ref s_hiddenLastKnownFreeAddressSpace, addend);
-
- private static long LastTimeCheckingAddressSpace
- {
- get => Volatile.Read(ref s_hiddenLastTimeCheckingAddressSpace);
- set => Volatile.Write(ref s_hiddenLastTimeCheckingAddressSpace, value);
- }
-
- // When allocating memory segment by segment, we've hit some cases
- // where there are only 22 MB of memory available on the machine,
- // we need 1 16 MB segment, and the OS does not succeed in giving us
- // that memory. Reasons for this could include:
- // 1) The GC does allocate memory when doing a collection.
- // 2) Another process on the machine could grab that memory.
- // 3) Some other part of the runtime might grab this memory.
- // If we build in a little padding, we can help protect
- // ourselves against some of these cases, and we want to err on the
- // conservative side with this class.
- private const int LowMemoryFudgeFactor = 16 << 20;
-
- // Round requested size to a 16MB multiple to have a better granularity
- // when checking for available memory.
- private const int MemoryCheckGranularity = 16;
-
- // Note: This may become dynamically tunable in the future.
- // Also note that we can have different segment sizes for the normal vs.
- // large object heap. We currently use the max of the two.
- private static readonly ulong s_GCSegmentSize = GC.GetSegmentSize();
-
- // For multi-threaded workers, we want to ensure that if two workers
- // use a MemoryFailPoint at the same time, and they both succeed, that
- // they don't trample over each other's memory. Keep a process-wide
- // count of "reserved" memory, and decrement this in Dispose and
- // in the critical finalizer.
- private static long s_failPointReservedMemory;
-
- private readonly ulong _reservedMemory; // The size of this request (from user)
- private bool _mustSubtractReservation; // Did we add data to SharedStatics?
-
- // We can remove this link demand in a future version - we will
- // have scenarios for this in partial trust in the future, but
- // we're doing this just to restrict this in case the code below
- // is somehow incorrect.
- public MemoryFailPoint(int sizeInMegabytes)
- {
- if (sizeInMegabytes <= 0)
- throw new ArgumentOutOfRangeException(nameof(sizeInMegabytes), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- ulong size = ((ulong)sizeInMegabytes) << 20;
- _reservedMemory = size;
-
- // Check to see that we both have enough memory on the system
- // and that we have enough room within the user section of the
- // process's address space. Also, we need to use the GC segment
- // size, not the amount of memory the user wants to allocate.
- // Consider correcting this to reflect free memory within the GC
- // heap, and to check both the normal & large object heaps.
- ulong segmentSize = (ulong)(Math.Ceiling((double)size / s_GCSegmentSize) * s_GCSegmentSize);
- if (segmentSize >= s_topOfMemory)
- throw new InsufficientMemoryException(SR.InsufficientMemory_MemFailPoint_TooBig);
-
- ulong requestedSizeRounded = (ulong)(Math.Ceiling((double)sizeInMegabytes / MemoryCheckGranularity) * MemoryCheckGranularity);
- // re-convert into bytes
- requestedSizeRounded <<= 20;
-
- ulong availPageFile = 0; // available VM (physical + page file)
- ulong totalAddressSpaceFree = 0; // non-contiguous free address space
-
- // Check for available memory, with 2 attempts at getting more
- // memory.
- // Stage 0: If we don't have enough, trigger a GC.
- // Stage 1: If we don't have enough, try growing the swap file.
- // Stage 2: Update memory state, then fail or leave loop.
- //
- // (In the future, we could consider adding another stage after
- // Stage 0 to run finalizers. However, before doing that make sure
- // that we could abort this constructor when we call
- // GC.WaitForPendingFinalizers, noting that this method uses a CER
- // so it can't be aborted, and we have a critical finalizer. It
- // would probably work, but do some thinking first.)
- for (int stage = 0; stage < 3; stage++)
- {
- if (!CheckForAvailableMemory(out availPageFile, out totalAddressSpaceFree))
- {
- // _mustSubtractReservation == false
- return;
- }
-
- // If we have enough room, then skip some stages.
- // Note that multiple threads can still lead to a race condition for our free chunk
- // of address space, which can't be easily solved.
- ulong reserved = MemoryFailPointReservedMemory;
- ulong segPlusReserved = segmentSize + reserved;
- bool overflow = segPlusReserved < segmentSize || segPlusReserved < reserved;
- bool needPageFile = availPageFile < (requestedSizeRounded + reserved + LowMemoryFudgeFactor) || overflow;
- bool needAddressSpace = totalAddressSpaceFree < segPlusReserved || overflow;
-
- // Ensure our cached amount of free address space is not stale.
- long now = Environment.TickCount; // Handle wraparound.
- if (now > LastTimeCheckingAddressSpace + CheckThreshold || now < LastTimeCheckingAddressSpace ||
- LastKnownFreeAddressSpace < (long)segmentSize)
- {
- CheckForFreeAddressSpace(segmentSize, false);
- }
- bool needContiguousVASpace = (ulong)LastKnownFreeAddressSpace < segmentSize;
-
-#if false
- Console.WriteLine($"MemoryFailPoint:" +
- $"Checking for {(segmentSize >> 20)} MB, " +
- $"for allocation size of {sizeInMegabytes} MB, " +
- $"stage {stage}. " +
- $"Need page file? {needPageFile} " +
- $"Need Address Space? {needAddressSpace} " +
- $"Need Contiguous address space? {needContiguousVASpace} " +
- $"Avail page file: {(availPageFile >> 20)} MB " +
- $"Total free VA space: {totalAddressSpaceFree >> 20} MB " +
- $"Contiguous free address space (found): {LastKnownFreeAddressSpace >> 20} MB " +
- $"Space reserved via process's MemoryFailPoints: {reserved} MB");
-#endif
-
- if (!needPageFile && !needAddressSpace && !needContiguousVASpace)
- break;
-
- switch (stage)
- {
- case 0:
- // The GC will release empty segments to the OS. This will
- // relieve us from having to guess whether there's
- // enough memory in either GC heap, and whether
- // internal fragmentation will prevent those
- // allocations from succeeding.
- GC.Collect();
- continue;
-
- case 1:
- // Do this step if and only if the page file is too small.
- if (!needPageFile)
- continue;
-
- // Attempt to grow the OS's page file. Note that we ignore
- // any allocation routines from the host intentionally.
- RuntimeHelpers.PrepareConstrainedRegions();
-
- // This shouldn't overflow due to the if clauses above.
- UIntPtr numBytes = new UIntPtr(segmentSize);
- GrowPageFileIfNecessaryAndPossible(numBytes);
- continue;
-
- case 2:
- // The call to CheckForAvailableMemory above updated our
- // state.
- if (needPageFile || needAddressSpace)
- {
- InsufficientMemoryException e = new InsufficientMemoryException(SR.InsufficientMemory_MemFailPoint);
-#if DEBUG
- e.Data["MemFailPointState"] = new MemoryFailPointState(sizeInMegabytes, segmentSize,
- needPageFile, needAddressSpace, needContiguousVASpace,
- availPageFile >> 20, totalAddressSpaceFree >> 20,
- LastKnownFreeAddressSpace >> 20, reserved);
-#endif
- throw e;
- }
-
- if (needContiguousVASpace)
- {
- InsufficientMemoryException e = new InsufficientMemoryException(SR.InsufficientMemory_MemFailPoint_VAFrag);
-#if DEBUG
- e.Data["MemFailPointState"] = new MemoryFailPointState(sizeInMegabytes, segmentSize,
- needPageFile, needAddressSpace, needContiguousVASpace,
- availPageFile >> 20, totalAddressSpaceFree >> 20,
- LastKnownFreeAddressSpace >> 20, reserved);
-#endif
- throw e;
- }
-
- break;
-
- default:
- Debug.Fail("Fell through switch statement!");
- break;
- }
- }
-
- // Success - we have enough room the last time we checked.
- // Now update our shared state in a somewhat atomic fashion
- // and handle a simple race condition with other MemoryFailPoint instances.
- AddToLastKnownFreeAddressSpace(-((long)size));
- if (LastKnownFreeAddressSpace < 0)
- CheckForFreeAddressSpace(segmentSize, true);
-
- RuntimeHelpers.PrepareConstrainedRegions();
-
- AddMemoryFailPointReservation((long)size);
- _mustSubtractReservation = true;
- }
-
- ~MemoryFailPoint()
- {
- Dispose(false);
- }
-
- // Applications must call Dispose, which conceptually "releases" the
- // memory that was "reserved" by the MemoryFailPoint. This affects a
- // global count of reserved memory in this version (helping to throttle
- // future MemoryFailPoints) in this version. We may in the
- // future create an allocation context and release it in the Dispose
- // method. While the finalizer will eventually free this block of
- // memory, apps will help their performance greatly by calling Dispose.
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- private void Dispose(bool disposing)
- {
- // This is just bookkeeping to ensure multiple threads can really
- // get enough memory, and this does not actually reserve memory
- // within the GC heap.
- if (_mustSubtractReservation)
- {
- RuntimeHelpers.PrepareConstrainedRegions();
-
- AddMemoryFailPointReservation(-((long)_reservedMemory));
- _mustSubtractReservation = false;
- }
-
- /*
- // Prototype performance
- // Let's pretend that we returned at least some free memory to
- // the GC heap. We don't know this is true - the objects could
- // have a longer lifetime, and the memory could be elsewhere in the
- // GC heap. Additionally, we subtracted off the segment size, not
- // this size. That's ok - we don't mind if this slowly degrades
- // and requires us to refresh the value a little bit sooner.
- // But releasing the memory here should help us avoid probing for
- // free address space excessively with large workItem sizes.
- Interlocked.Add(ref LastKnownFreeAddressSpace, _reservedMemory);
- */
- }
-
- internal static long AddMemoryFailPointReservation(long size) =>
- // Size can legitimately be negative - see Dispose.
- Interlocked.Add(ref s_failPointReservedMemory, (long)size);
-
- internal static ulong MemoryFailPointReservedMemory
- {
- get
- {
- Debug.Assert(Volatile.Read(ref s_failPointReservedMemory) >= 0, "Process-wide MemoryFailPoint reserved memory was negative!");
- return (ulong)Volatile.Read(ref s_failPointReservedMemory);
- }
- }
-
-#if DEBUG
- [Serializable]
- internal sealed class MemoryFailPointState
- {
- private readonly ulong _segmentSize;
- private readonly int _allocationSizeInMB;
- private readonly bool _needPageFile;
- private readonly bool _needAddressSpace;
- private readonly bool _needContiguousVASpace;
- private readonly ulong _availPageFile;
- private readonly ulong _totalFreeAddressSpace;
- private readonly long _lastKnownFreeAddressSpace;
- private readonly ulong _reservedMem;
- private readonly string _stackTrace; // Where did we fail, for additional debugging.
-
- internal MemoryFailPointState(int allocationSizeInMB, ulong segmentSize, bool needPageFile, bool needAddressSpace, bool needContiguousVASpace, ulong availPageFile, ulong totalFreeAddressSpace, long lastKnownFreeAddressSpace, ulong reservedMem)
- {
- _allocationSizeInMB = allocationSizeInMB;
- _segmentSize = segmentSize;
- _needPageFile = needPageFile;
- _needAddressSpace = needAddressSpace;
- _needContiguousVASpace = needContiguousVASpace;
- _availPageFile = availPageFile;
- _totalFreeAddressSpace = totalFreeAddressSpace;
- _lastKnownFreeAddressSpace = lastKnownFreeAddressSpace;
- _reservedMem = reservedMem;
- try
- {
- _stackTrace = Environment.StackTrace;
- }
- catch (System.Security.SecurityException)
- {
- _stackTrace = "no permission";
- }
- catch (OutOfMemoryException)
- {
- _stackTrace = "out of memory";
- }
- }
-
- public override string ToString()
- {
- return string.Format(System.Globalization.CultureInfo.InvariantCulture, "MemoryFailPoint detected insufficient memory to guarantee an operation could complete. Checked for {0} MB, for allocation size of {1} MB. Need page file? {2} Need Address Space? {3} Need Contiguous address space? {4} Avail page file: {5} MB Total free VA space: {6} MB Contiguous free address space (found): {7} MB Space reserved by process's MemoryFailPoints: {8} MB",
- _segmentSize >> 20, _allocationSizeInMB, _needPageFile,
- _needAddressSpace, _needContiguousVASpace,
- _availPageFile >> 20, _totalFreeAddressSpace >> 20,
- _lastKnownFreeAddressSpace >> 20, _reservedMem);
- }
- }
-#endif
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Remoting/ObjectHandle.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Remoting/ObjectHandle.cs
deleted file mode 100644
index 9dd987ac5d2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Remoting/ObjectHandle.cs
+++ /dev/null
@@ -1,21 +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.
-
-namespace System.Runtime.Remoting
-{
- public class ObjectHandle : MarshalByRefObject
- {
- private readonly object? _wrappedObject;
-
- public ObjectHandle(object? o)
- {
- _wrappedObject = o;
- }
-
- public object? Unwrap()
- {
- return _wrappedObject;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationToken.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationToken.cs
deleted file mode 100644
index 2be35a6553f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationToken.cs
+++ /dev/null
@@ -1,33 +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.
-
-namespace System.Runtime.Serialization
-{
- // Tracks whether deserialization is currently in progress
- public readonly struct DeserializationToken : IDisposable
- {
- private readonly DeserializationTracker? _tracker;
-
- internal DeserializationToken(DeserializationTracker? tracker)
- {
- _tracker = tracker;
- }
-
- // If this token owned the DeserializationTracker, turn off DeserializationInProgress tracking
- public void Dispose()
- {
- if (_tracker != null && _tracker.DeserializationInProgress)
- {
- lock (_tracker)
- {
- if (_tracker.DeserializationInProgress)
- {
- _tracker.DeserializationInProgress = false;
- SerializationInfo.AsyncDeserializationInProgress.Value = false;
- }
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationTracker.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationTracker.cs
deleted file mode 100644
index 1662ee02d4a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/DeserializationTracker.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Runtime.Serialization
-{
- // Tracks whether deserialization is currently in progress
- internal sealed class DeserializationTracker
- {
- // True if the thread this tracker applies to is currently deserializing
- // potentially untrusted data
- internal bool DeserializationInProgress { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IDeserializationCallback.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IDeserializationCallback.cs
deleted file mode 100644
index 22b799c78f4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IDeserializationCallback.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.Serialization
-{
- public interface IDeserializationCallback
- {
- void OnDeserialization(object? sender);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IFormatterConverter.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IFormatterConverter.cs
deleted file mode 100644
index 663123b243b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IFormatterConverter.cs
+++ /dev/null
@@ -1,28 +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.
-
-namespace System.Runtime.Serialization
-{
- [CLSCompliant(false)]
- public interface IFormatterConverter
- {
- object Convert(object value, Type type);
- object Convert(object value, TypeCode typeCode);
- bool ToBoolean(object value);
- char ToChar(object value);
- sbyte ToSByte(object value);
- byte ToByte(object value);
- short ToInt16(object value);
- ushort ToUInt16(object value);
- int ToInt32(object value);
- uint ToUInt32(object value);
- long ToInt64(object value);
- ulong ToUInt64(object value);
- float ToSingle(object value);
- double ToDouble(object value);
- decimal ToDecimal(object value);
- DateTime ToDateTime(object value);
- string? ToString(object value);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IObjectReference.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IObjectReference.cs
deleted file mode 100644
index d41bc50dde4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/IObjectReference.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.Serialization
-{
- public interface IObjectReference
- {
- object GetRealObject(StreamingContext context);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/ISafeSerializationData.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/ISafeSerializationData.cs
deleted file mode 100644
index 06ef1999da0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/ISafeSerializationData.cs
+++ /dev/null
@@ -1,207 +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.
-
-namespace System.Runtime.Serialization
-{
- //
- // #SafeSerialization
- //
- // Types which are serializable via the ISerializable interface have a problem when it comes to allowing
- // transparent subtypes which can allow themselves to serialize since the GetObjectData method is
- // SecurityCritical.
- //
- // For instance, System.Exception implements ISerializable, however it is also desirable to have
- // transparent exceptions with their own fields that need to be serialized. (For instance, in transparent
- // assemblies such as the DLR and F#, or even in partial trust application code). Since overriding
- // GetObjectData requires that the overriding method be security critical, this won't work directly.
- //
- // SafeSerializationManager solves this problem by allowing any partial trust code to contribute
- // individual chunks of serializable data to be included in the serialized version of the derived class.
- // These chunks are then deserialized back out of the serialized type and notified that they should
- // populate the fields of the deserialized object when serialization is complete. This allows partial
- // trust or transparent code to participate in serialization of an ISerializable type without having to
- // override GetObjectData or implement the ISerializable constructor.
- //
- // On the serialization side, SafeSerializationManager has an event SerializeObjectState which it will
- // fire in response to serialization in order to gather the units of serializable data that should be
- // stored with the rest of the object during serialization. Methods which respond to these events
- // create serializable objects which implement the ISafeSerializationData interface and add them to the
- // collection of other serialized data by calling AddSerializedState on the SafeSerializationEventArgs
- // passed into the event.
- //
- // By using an event rather than a virtual method on the base ISerializable object, we allow multiple
- // potentially untrusted subclasses to participate in serialization, without each one having to ensure
- // that it calls up to the base type in order for the whole system to work. (For instance Exception :
- // TrustedException : UntrustedException, in this scenario UntrustedException would be able to override
- // the virtual method an prevent TrustedException from ever seeing the method call, either accidentally
- // or maliciously).
- //
- // Further, by only allowing additions of new chunks of serialization state rather than exposing the
- // whole underlying list, we avoid exposing potentially sensitive serialized state to any of the
- // potentially untrusted subclasses.
- //
- // At deserialization time, SafeSerializationManager performs the reverse operation. It deserializes the
- // chunks of serialized state, and then notifies them that the object they belong to is deserialized by
- // calling their CompleteSerialization method. In repsonse to this call, the state objects populate the
- // fields of the object being deserialized with the state that they held.
- //
- // From a security perspective, the chunks of serialized state can only contain data that the specific
- // subclass itself had access to read (otherwise it wouldn't be able to populate the type with that
- // data), as opposed to having access to far more data in the SerializationInfo that GetObjectData uses.
- // Similarly, at deserialization time, the serialized state can only modify fields that the type itself
- // has access to (again, as opposed to the full SerializationInfo which could be modified).
- //
- // Individual types which wish to participate in safe serialization do so by containing an instance of a
- // SafeSerializationManager and exposing its serialization event. During GetObjectData, the
- // SafeSerializationManager is serialized just like any other field of the containing type. However, at
- // the end of serialization it is called back one last time to CompleteSerialization.
- //
- // In CompleteSerialization, if the SafeSerializationManager detects that it has extra chunks of
- // data to handle, it substitutes the root type being serialized (formerly the real type hosting the
- // SafeSerializationManager) with itself. This allows it to gain more control over the deserialization
- // process. It also saves away an extra bit of state in the serialization info indicating the real type
- // of object that should be recreated during deserialization.
- //
- // At this point the serialized state looks like this:
- // Data:
- // realSerializedData1
- // ...
- // realSerializedDataN
- // safeSerializationData -> this is the serialization data member of the parent type
- // _serializedState -> list of saved serialized states from subclasses responding to the safe
- // serialization event
- // RealTypeSerializationName -> type which is using safe serialization
- // Type:
- // SafeSerializationManager
- //
- // That is, the serialized data claims to be of type SafeSerializationManager, however contains only the
- // data from the real object being serialized along with one bit of safe serialization metadata.
- //
- // At deserialization time, since the serialized data claims to be of type SafeSerializationManager, the
- // root object being created is an instance of the SafeSerializationManager class. However, it detects
- // that this isn't a real SafeSerializationManager (by looking for the real type field in the metadata),
- // and simply saves away the SerializationInfo and the real type being deserialized.
- //
- // Since SafeSerializationManager implements IObjectReference, the next step of deserialization is the
- // GetRealObject callback. This callback is the one responsible for getting the
- // SafeSerializationManager out of the way and instead creating an instance of the actual type which was
- // serialized.
- //
- // It does this by first creating an instance of the real type being deserialzed (saved away in the
- // deserialzation constructor), but not running any of its constructors. Instead, it walks the
- // inheritance hierarchy (moving toward the most derived type) looking for the last full trust type to
- // implement the standard ISerializable constructor before any type does not implement the constructor.
- // It is this last type's deserialization constructor which is then invoked, passing in the saved
- // SerializationInfo. Once the constructors are run, we return this object as the real deserialized
- // object.
- //
- // The reason that we do this walk is so that ISerializable types can protect themselves from malicious
- // input during deserialization by making their deserialization constructors unavailable to partial
- // trust code. By not requiring every type have a copy of this constructor, partial trust code can
- // participate in safe serialization and not be required to have access to the parent's constructor.
- //
- // It should be noted however, that this heuristic means that if a full trust type does derive from
- // a transparent or partial trust type using this safe serialization mechanism, that full trust type
- // will not have its constructor called. Further, the protection of not invoking partial trust
- // deserialization constructors only comes into play if SafeSerializationManager is in control of
- // deserialization, which means there must be at least one (even empty) safe serialization event
- // handler registered.
- //
- // Another interesting note is that at this point there are now two SafeSerializationManagers alive for
- // this deserialization. The first object is the one which is controlling the deserialization and was
- // created as the root object of the deserialization. The second one is the object which contains the
- // serialized data chunks and is a data member of the real object being deserialized. For this reason,
- // the data objects cannot be notified that the deserialization is complete during GetRealObject since
- // the ISafeSerializationData objects are not members of the active SafeSerializationManager instance.
- //
- // The next step is the OnDeserialized callback, which comes to SafeSerializableObject since it was
- // pretending to be the root object of the deserialization. It responds to this callback by calling
- // any existing OnDeserialized callback on the real type that was deserialized.
- //
- // The real type needs to call its data member SafeSerializationData object's CompleteDeserialization
- // method in response to the OnDeserialized call. This CompleteDeserialization call will then iterate
- // through the ISafeSerializationData objects calling each of their CompleteDeserialization methods so
- // that they can plug the nearly-complete object with their saved data.
- //
- // The reason for having a new ISafeSerializationData interface which is basically identical to
- // IDeserializationCallback is that IDeserializationCallback will be called on the stored data chunks
- // by the serialization code when they are deserialized, and that's not a desirable behavior.
- // Essentially, we need to change the meaning of the object parameter to mean "parent object which
- // participated in safe serialization", rather than "this object".
- //
- // Implementing safe serialization on an ISerialiable type is relatively straight forward. (For an
- // example, see System.Exception):
- //
- // 1. Include a data member of type SafeSerializationManager:
- //
- // private SafeSerializationManager _safeSerializationManager;
- //
- // 2. Add a protected SerializeObjectState event, which passes through to the SafeSerializationManager:
- //
- // protected event EventHandler<SafeSerializationEventArgs>? SerializeObjectState
- // {
- // add { _safeSerializationManager.SerializeObjectState += value; }
- // remove { _safeSerializationManager.SerializeObjectState -= value; }
- // }
- //
- // 3. Serialize the safe serialization object in GetObjectData, and call its CompleteSerialization method:
- //
- // {
- // info.AddValue("_safeSerializationManager", _safeSerializationManager, typeof(SafeSerializationManager));
- // _safeSerializationManager.CompleteSerialization(this, info, context);
- // }
- //
- // 4. Add an OnDeserialized handler if one doesn't already exist, and call CompleteDeserialization in it:
- //
- // [OnDeserialized]
- // private void OnDeserialized(StreamingContext context)
- // {
- // _safeSerializationManager.CompleteDeserialization(this);
- // }
- //
- // On the client side, using safe serialization is also pretty easy. For example:
- //
- // [Serializable]
- // public class TransparentException : Exception
- // {
- // [Serializable]
- // private struct TransparentExceptionState : ISafeSerializationData
- // {
- // public string _extraData;
- //
- // void ISafeSerializationData.CompleteDeserialization(object obj)
- // {
- // TransparentException exception = obj as TransparentException;
- // exception._state = this;
- // }
- // }
- //
- // [NonSerialized]
- // private TransparentExceptionState _state = new TransparentExceptionState();
- //
- // public TransparentException()
- // {
- // SerializeObjectState += delegate(object exception, SafeSerializationEventArgs eventArgs)
- // {
- // eventArgs.AddSerializedState(_state);
- // };
- // }
- //
- // public string ExtraData
- // {
- // get { return _state._extraData; }
- // set { _state._extraData = value; }
- // }
- // }
- //
-
- // Interface to be supported by objects which are stored in safe serialization stores
- public interface ISafeSerializationData
- {
- // CompleteDeserialization is called when the object to which the extra serialized data was attached
- // has completed its deserialization, and now needs to be populated with the extra data stored in
- // this object.
- void CompleteDeserialization(object deserialized);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/ISerializable.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/ISerializable.cs
deleted file mode 100644
index 383b3f07af3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/ISerializable.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.Serialization
-{
- public interface ISerializable
- {
- void GetObjectData(SerializationInfo info, StreamingContext context);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs
deleted file mode 100644
index 408a55ccf9e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.Serialization
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class OnDeserializedAttribute : Attribute
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs
deleted file mode 100644
index 162857e8d3b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.Serialization
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class OnDeserializingAttribute : Attribute
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs
deleted file mode 100644
index 020dd0257ca..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.Serialization
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class OnSerializedAttribute : Attribute
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs
deleted file mode 100644
index 8dc8af3f235..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.Serialization
-{
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- public sealed class OnSerializingAttribute : Attribute
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs
deleted file mode 100644
index 3d6a523071d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs
+++ /dev/null
@@ -1,25 +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.
-
-namespace System.Runtime.Serialization
-{
- [AttributeUsage(AttributeTargets.Field, Inherited = false)]
- public sealed class OptionalFieldAttribute : Attribute
- {
- private int _versionAdded = 1;
-
- public int VersionAdded
- {
- get => _versionAdded;
- set
- {
- if (value < 1)
- {
- throw new ArgumentException(SR.Serialization_OptionalFieldVersionValue);
- }
- _versionAdded = value;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs
deleted file mode 100644
index d6613b4ac22..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Runtime.Serialization
-{
- // This type exists for public surface compatibility only.
- public sealed class SafeSerializationEventArgs : EventArgs
- {
- private SafeSerializationEventArgs() { }
-
- public void AddSerializedState(ISafeSerializationData serializedState)
- {
- }
-
- public StreamingContext StreamingContext { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationException.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationException.cs
deleted file mode 100644
index 3dc6e8fca2f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationException.cs
+++ /dev/null
@@ -1,38 +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.
-
-namespace System.Runtime.Serialization
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class SerializationException : SystemException
- {
- /// <summary>
- /// Creates a new SerializationException with its message
- /// string set to a default message.
- /// </summary>
- public SerializationException()
- : base(SR.SerializationException)
- {
- HResult = HResults.COR_E_SERIALIZATION;
- }
-
- public SerializationException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_SERIALIZATION;
- }
-
- public SerializationException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_SERIALIZATION;
- }
-
- protected SerializationException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs
deleted file mode 100644
index b44c66fcea1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs
+++ /dev/null
@@ -1,642 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Security;
-using System.Threading;
-
-namespace System.Runtime.Serialization
-{
- /// <summary>The structure for holding all of the data needed for object serialization and deserialization.</summary>
- public sealed class SerializationInfo
- {
- private const int DefaultSize = 4;
-
- // Even though we have a dictionary, we're still keeping all the arrays around for back-compat.
- // Otherwise we may run into potentially breaking behaviors like GetEnumerator() not returning entries in the same order they were added.
- private string[] _names;
- private object?[] _values;
- private Type[] _types;
- private int _count;
- private readonly Dictionary<string, int> _nameToIndex;
- private readonly IFormatterConverter _converter;
- private string _rootTypeName;
- private string _rootTypeAssemblyName;
- private Type _rootType;
-
- internal static AsyncLocal<bool> AsyncDeserializationInProgress { get; } = new AsyncLocal<bool>();
-
-#if !CORECLR
- // On AoT, assume private members are reflection blocked, so there's no further protection required
- // for the thread's DeserializationTracker
- [ThreadStatic]
- private static DeserializationTracker? t_deserializationTracker;
-
- private static DeserializationTracker GetThreadDeserializationTracker() =>
- t_deserializationTracker ??= new DeserializationTracker();
-#endif // !CORECLR
-
- // Returns true if deserialization is currently in progress
- public static bool DeserializationInProgress
- {
-#if CORECLR
- [DynamicSecurityMethod] // Methods containing StackCrawlMark local var must be marked DynamicSecurityMethod
-#endif
- get
- {
- if (AsyncDeserializationInProgress.Value)
- {
- return true;
- }
-
-#if CORECLR
- StackCrawlMark stackMark = StackCrawlMark.LookForMe;
- DeserializationTracker tracker = Thread.GetThreadDeserializationTracker(ref stackMark);
-#else
- DeserializationTracker tracker = GetThreadDeserializationTracker();
-#endif
- bool result = tracker.DeserializationInProgress;
- return result;
- }
- }
-
- // Throws a SerializationException if dangerous deserialization is currently
- // in progress
- public static void ThrowIfDeserializationInProgress()
- {
- if (DeserializationInProgress)
- {
- throw new SerializationException(SR.Serialization_DangerousDeserialization);
- }
- }
-
- // Throws a DeserializationBlockedException if dangerous deserialization is currently
- // in progress and the AppContext switch Switch.System.Runtime.Serialization.SerializationGuard.{switchSuffix}
- // is not true. The value of the switch is cached in cachedValue to avoid repeated lookups:
- // 0: No value cached
- // 1: The switch is true
- // -1: The switch is false
- public static void ThrowIfDeserializationInProgress(string switchSuffix, ref int cachedValue)
- {
- const string SwitchPrefix = "Switch.System.Runtime.Serialization.SerializationGuard.";
- if (switchSuffix == null)
- {
- throw new ArgumentNullException(nameof(switchSuffix));
- }
- if (string.IsNullOrWhiteSpace(switchSuffix))
- {
- throw new ArgumentException(SR.Argument_EmptyName, nameof(switchSuffix));
- }
-
- if (cachedValue == 0)
- {
- bool isEnabled = false;
- if (AppContext.TryGetSwitch(SwitchPrefix + switchSuffix, out isEnabled) && isEnabled)
- {
- cachedValue = 1;
- }
- else
- {
- cachedValue = -1;
- }
- }
-
- if (cachedValue == 1)
- {
- return;
- }
- else if (cachedValue == -1)
- {
- if (DeserializationInProgress)
- {
- throw new SerializationException(SR.Format(SR.Serialization_DangerousDeserialization_Switch, SwitchPrefix + switchSuffix));
- }
- }
- else
- {
- throw new ArgumentOutOfRangeException(nameof(cachedValue));
- }
- }
-
- // Declares that the current thread and async context have begun deserialization.
- // In this state, if the SerializationGuard or other related AppContext switches are set,
- // actions likely to be dangerous during deserialization, such as starting a process will be blocked.
- // Returns a DeserializationToken that must be disposed to remove the deserialization state.
-#if CORECLR
- [DynamicSecurityMethod] // Methods containing StackCrawlMark local var must be marked DynamicSecurityMethod
-#endif
- public static DeserializationToken StartDeserialization()
- {
- if (LocalAppContextSwitches.SerializationGuard)
- {
-#if CORECLR
- StackCrawlMark stackMark = StackCrawlMark.LookForMe;
- DeserializationTracker tracker = Thread.GetThreadDeserializationTracker(ref stackMark);
-#else
- DeserializationTracker tracker = GetThreadDeserializationTracker();
-#endif
- if (!tracker.DeserializationInProgress)
- {
- lock (tracker)
- {
- if (!tracker.DeserializationInProgress)
- {
- AsyncDeserializationInProgress.Value = true;
- tracker.DeserializationInProgress = true;
- return new DeserializationToken(tracker);
- }
- }
- }
- }
-
- return new DeserializationToken(null);
- }
-
- [CLSCompliant(false)]
- public SerializationInfo(Type type, IFormatterConverter converter)
- {
- if ((object)type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
-
- if (converter == null)
- {
- throw new ArgumentNullException(nameof(converter));
- }
-
- _rootType = type;
- _rootTypeName = type.FullName!;
- _rootTypeAssemblyName = type.Module.Assembly.FullName!;
-
- _names = new string[DefaultSize];
- _values = new object[DefaultSize];
- _types = new Type[DefaultSize];
-
- _nameToIndex = new Dictionary<string, int>();
-
- _converter = converter;
- }
-
- [CLSCompliant(false)]
- public SerializationInfo(Type type, IFormatterConverter converter, bool requireSameTokenInPartialTrust)
- : this(type, converter)
- {
- // requireSameTokenInPartialTrust is a vacuous parameter in a platform that does not support partial trust.
- }
-
- public string FullTypeName
- {
- get => _rootTypeName;
- set
- {
- if (null == value)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- _rootTypeName = value;
- IsFullTypeNameSetExplicit = true;
- }
- }
-
- public string AssemblyName
- {
- get => _rootTypeAssemblyName;
- set
- {
- if (null == value)
- {
- throw new ArgumentNullException(nameof(value));
- }
- _rootTypeAssemblyName = value;
- IsAssemblyNameSetExplicit = true;
- }
- }
-
- public bool IsFullTypeNameSetExplicit { get; private set; }
-
- public bool IsAssemblyNameSetExplicit { get; private set; }
-
- public void SetType(Type type)
- {
- if ((object)type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
-
- if (!ReferenceEquals(_rootType, type))
- {
- _rootType = type;
- _rootTypeName = type.FullName!;
- _rootTypeAssemblyName = type.Module.Assembly.FullName!;
- IsFullTypeNameSetExplicit = false;
- IsAssemblyNameSetExplicit = false;
- }
- }
-
- public int MemberCount => _count;
-
- public Type ObjectType => _rootType;
-
- public SerializationInfoEnumerator GetEnumerator() => new SerializationInfoEnumerator(_names, _values, _types, _count);
-
- private void ExpandArrays()
- {
- int newSize;
- Debug.Assert(_names.Length == _count, "[SerializationInfo.ExpandArrays]_names.Length == _count");
-
- newSize = (_count * 2);
-
- // In the pathological case, we may wrap
- if (newSize < _count)
- {
- if (int.MaxValue > _count)
- {
- newSize = int.MaxValue;
- }
- }
-
- // Allocate more space and copy the data
- string[] newMembers = new string[newSize];
- object[] newData = new object[newSize];
- Type[] newTypes = new Type[newSize];
-
- Array.Copy(_names, newMembers, _count);
- Array.Copy(_values, newData, _count);
- Array.Copy(_types, newTypes, _count);
-
- // Assign the new arrays back to the member vars.
- _names = newMembers;
- _values = newData;
- _types = newTypes;
- }
-
- public void AddValue(string name, object? value, Type type)
- {
- if (null == name)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- if ((object)type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
-
- AddValueInternal(name, value, type);
- }
-
- public void AddValue(string name, object? value)
- {
- if (null == value)
- {
- AddValue(name, value, typeof(object));
- }
- else
- {
- AddValue(name, value, value.GetType());
- }
- }
-
- public void AddValue(string name, bool value)
- {
- AddValue(name, (object)value, typeof(bool));
- }
-
- public void AddValue(string name, char value)
- {
- AddValue(name, (object)value, typeof(char));
- }
-
- [CLSCompliant(false)]
- public void AddValue(string name, sbyte value)
- {
- AddValue(name, (object)value, typeof(sbyte));
- }
-
- public void AddValue(string name, byte value)
- {
- AddValue(name, (object)value, typeof(byte));
- }
-
- public void AddValue(string name, short value)
- {
- AddValue(name, (object)value, typeof(short));
- }
-
- [CLSCompliant(false)]
- public void AddValue(string name, ushort value)
- {
- AddValue(name, (object)value, typeof(ushort));
- }
-
- public void AddValue(string name, int value)
- {
- AddValue(name, (object)value, typeof(int));
- }
-
- [CLSCompliant(false)]
- public void AddValue(string name, uint value)
- {
- AddValue(name, (object)value, typeof(uint));
- }
-
- public void AddValue(string name, long value)
- {
- AddValue(name, (object)value, typeof(long));
- }
-
- [CLSCompliant(false)]
- public void AddValue(string name, ulong value)
- {
- AddValue(name, (object)value, typeof(ulong));
- }
-
- public void AddValue(string name, float value)
- {
- AddValue(name, (object)value, typeof(float));
- }
-
- public void AddValue(string name, double value)
- {
- AddValue(name, (object)value, typeof(double));
- }
-
- public void AddValue(string name, decimal value)
- {
- AddValue(name, (object)value, typeof(decimal));
- }
-
- public void AddValue(string name, DateTime value)
- {
- AddValue(name, (object)value, typeof(DateTime));
- }
-
- internal void AddValueInternal(string name, object? value, Type type)
- {
- if (_nameToIndex.ContainsKey(name))
- {
- throw new SerializationException(SR.Serialization_SameNameTwice);
- }
- _nameToIndex.Add(name, _count);
-
- // If we need to expand the arrays, do so.
- if (_count >= _names.Length)
- {
- ExpandArrays();
- }
-
- // Add the data and then advance the counter.
- _names[_count] = name;
- _values[_count] = value;
- _types[_count] = type;
- _count++;
- }
-
- /// <summary>
- /// Finds the value if it exists in the current data. If it does, we replace
- /// the values, if not, we append it to the end. This is useful to the
- /// ObjectManager when it's performing fixups.
- ///
- /// All error checking is done with asserts. Although public in coreclr,
- /// it's not exposed in a contract and is only meant to be used by corefx.
- ///
- /// This isn't a public API, but it gets invoked dynamically by
- /// BinaryFormatter
- ///
- /// This should not be used by clients: exposing out this functionality would allow children
- /// to overwrite their parent's values. It is public in order to give corefx access to it for
- /// its ObjectManager implementation, but it should not be exposed out of a contract.
- /// </summary>
- /// <param name="name"> The name of the data to be updated.</param>
- /// <param name="value"> The new value.</param>
- /// <param name="type"> The type of the data being added.</param>
- public void UpdateValue(string name, object value, Type type)
- {
- Debug.Assert(null != name, "[SerializationInfo.UpdateValue]name!=null");
- Debug.Assert(null != value, "[SerializationInfo.UpdateValue]value!=null");
- Debug.Assert(null != (object)type, "[SerializationInfo.UpdateValue]type!=null");
-
- int index = FindElement(name);
- if (index < 0)
- {
- AddValueInternal(name, value, type);
- }
- else
- {
- _values[index] = value;
- _types[index] = type;
- }
- }
-
- private int FindElement(string name)
- {
- if (null == name)
- {
- throw new ArgumentNullException(nameof(name));
- }
- int index;
- if (_nameToIndex.TryGetValue(name, out index))
- {
- return index;
- }
- return -1;
- }
-
- /// <summary>
- /// Gets the location of a particular member and then returns
- /// the value of the element at that location. The type of the member is
- /// returned in the foundType field.
- /// </summary>
- /// <param name="name"> The name of the element to find.</param>
- /// <param name="foundType"> The type of the element associated with the given name.</param>
- /// <returns>The value of the element at the position associated with name.</returns>
- private object? GetElement(string name, out Type foundType)
- {
- int index = FindElement(name);
- if (index == -1)
- {
- throw new SerializationException(SR.Format(SR.Serialization_NotFound, name));
- }
-
- Debug.Assert(index < _values.Length, "[SerializationInfo.GetElement]index<_values.Length");
- Debug.Assert(index < _types.Length, "[SerializationInfo.GetElement]index<_types.Length");
-
- foundType = _types[index];
- Debug.Assert((object)foundType != null, "[SerializationInfo.GetElement]foundType!=null");
- return _values[index];
- }
-
- private object? GetElementNoThrow(string name, out Type? foundType)
- {
- int index = FindElement(name);
- if (index == -1)
- {
- foundType = null;
- return null;
- }
-
- Debug.Assert(index < _values.Length, "[SerializationInfo.GetElement]index<_values.Length");
- Debug.Assert(index < _types.Length, "[SerializationInfo.GetElement]index<_types.Length");
-
- foundType = _types[index];
- Debug.Assert((object)foundType != null, "[SerializationInfo.GetElement]foundType!=null");
- return _values[index];
- }
-
- public object? GetValue(string name, Type type)
- {
- if ((object)type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
-
- if (!type.IsRuntimeImplemented())
- throw new ArgumentException(SR.Argument_MustBeRuntimeType);
-
- Type foundType;
- object? value = GetElement(name, out foundType);
-
- if (ReferenceEquals(foundType, type) || type.IsAssignableFrom(foundType) || value == null)
- {
- return value;
- }
-
- Debug.Assert(_converter != null, "[SerializationInfo.GetValue]_converter!=null");
- return _converter.Convert(value, type);
- }
-
- internal object? GetValueNoThrow(string name, Type type)
- {
- Debug.Assert((object)type != null, "[SerializationInfo.GetValue]type ==null");
- Debug.Assert(type.IsRuntimeImplemented(), "[SerializationInfo.GetValue]type is not a runtime type");
-
- Type? foundType;
- object? value = GetElementNoThrow(name, out foundType);
- if (value == null)
- return null;
-
- if (ReferenceEquals(foundType, type) || type.IsAssignableFrom(foundType))
- {
- return value;
- }
-
- Debug.Assert(_converter != null, "[SerializationInfo.GetValue]_converter!=null");
-
- return _converter.Convert(value, type);
- }
-
- public bool GetBoolean(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(bool)) ? (bool)value! : _converter.ToBoolean(value!); // if value is null To* method will either deal with it or throw
- }
-
- public char GetChar(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(char)) ? (char)value! : _converter.ToChar(value!);
- }
-
- [CLSCompliant(false)]
- public sbyte GetSByte(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(sbyte)) ? (sbyte)value! : _converter.ToSByte(value!);
- }
-
- public byte GetByte(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(byte)) ? (byte)value! : _converter.ToByte(value!);
- }
-
- public short GetInt16(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(short)) ? (short)value! : _converter.ToInt16(value!);
- }
-
- [CLSCompliant(false)]
- public ushort GetUInt16(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(ushort)) ? (ushort)value! : _converter.ToUInt16(value!);
- }
-
- public int GetInt32(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(int)) ? (int)value! : _converter.ToInt32(value!);
- }
-
- [CLSCompliant(false)]
- public uint GetUInt32(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(uint)) ? (uint)value! : _converter.ToUInt32(value!);
- }
-
- public long GetInt64(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(long)) ? (long)value! : _converter.ToInt64(value!);
- }
-
- [CLSCompliant(false)]
- public ulong GetUInt64(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(ulong)) ? (ulong)value! : _converter.ToUInt64(value!);
- }
-
- public float GetSingle(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(float)) ? (float)value! : _converter.ToSingle(value!);
- }
-
-
- public double GetDouble(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(double)) ? (double)value! : _converter.ToDouble(value!);
- }
-
- public decimal GetDecimal(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(decimal)) ? (decimal)value! : _converter.ToDecimal(value!);
- }
-
- public DateTime GetDateTime(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(DateTime)) ? (DateTime)value! : _converter.ToDateTime(value!);
- }
-
- public string? GetString(string name)
- {
- Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(string)) || value == null ? (string?)value : _converter.ToString(value);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs
deleted file mode 100644
index bdc25c763f8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs
+++ /dev/null
@@ -1,127 +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 System.Collections;
-using System.Diagnostics;
-
-namespace System.Runtime.Serialization
-{
- public readonly struct SerializationEntry
- {
- private readonly string _name;
- private readonly object? _value;
- private readonly Type _type;
-
- internal SerializationEntry(string entryName, object? entryValue, Type entryType)
- {
- _name = entryName;
- _value = entryValue;
- _type = entryType;
- }
-
- public object? Value => _value;
- public string Name => _name;
- public Type ObjectType => _type;
- }
-
- public sealed class SerializationInfoEnumerator : IEnumerator
- {
- private readonly string[] _members;
- private readonly object?[] _data;
- private readonly Type[] _types;
- private readonly int _numItems;
- private int _currItem;
- private bool _current;
-
- internal SerializationInfoEnumerator(string[] members, object?[] info, Type[] types, int numItems)
- {
- Debug.Assert(members != null, "[SerializationInfoEnumerator.ctor]members!=null");
- Debug.Assert(info != null, "[SerializationInfoEnumerator.ctor]info!=null");
- Debug.Assert(types != null, "[SerializationInfoEnumerator.ctor]types!=null");
- Debug.Assert(numItems >= 0, "[SerializationInfoEnumerator.ctor]numItems>=0");
- Debug.Assert(members.Length >= numItems, "[SerializationInfoEnumerator.ctor]members.Length>=numItems");
- Debug.Assert(info.Length >= numItems, "[SerializationInfoEnumerator.ctor]info.Length>=numItems");
- Debug.Assert(types.Length >= numItems, "[SerializationInfoEnumerator.ctor]types.Length>=numItems");
-
- _members = members;
- _data = info;
- _types = types;
-
- // The MoveNext semantic is much easier if we enforce that [0..m_numItems] are valid entries
- // in the enumerator, hence we subtract 1.
- _numItems = numItems - 1;
- _currItem = -1;
- _current = false;
- }
-
- public bool MoveNext()
- {
- if (_currItem < _numItems)
- {
- _currItem++;
- _current = true;
- }
- else
- {
- _current = false;
- }
-
- return _current;
- }
-
- object? IEnumerator.Current => Current;
-
- public SerializationEntry Current
- {
- get
- {
- if (!_current)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
- }
- return new SerializationEntry(_members[_currItem], _data[_currItem], _types[_currItem]);
- }
- }
-
- public void Reset()
- {
- _currItem = -1;
- _current = false;
- }
-
- public string Name
- {
- get
- {
- if (!_current)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
- }
- return _members[_currItem];
- }
- }
- public object? Value
- {
- get
- {
- if (!_current)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
- }
- return _data[_currItem];
- }
- }
- public Type ObjectType
- {
- get
- {
- if (!_current)
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
- }
- return _types[_currItem];
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/StreamingContext.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/StreamingContext.cs
deleted file mode 100644
index f61366bd491..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Serialization/StreamingContext.cs
+++ /dev/null
@@ -1,52 +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.
-
-namespace System.Runtime.Serialization
-{
- public readonly struct StreamingContext
- {
- private readonly object? _additionalContext;
- private readonly StreamingContextStates _state;
-
- public StreamingContext(StreamingContextStates state) : this(state, null)
- {
- }
-
- public StreamingContext(StreamingContextStates state, object? additional)
- {
- _state = state;
- _additionalContext = additional;
- }
-
- public override bool Equals(object? obj)
- {
- if (!(obj is StreamingContext))
- {
- return false;
- }
- StreamingContext ctx = (StreamingContext)obj;
- return ctx._additionalContext == _additionalContext && ctx._state == _state;
- }
-
- public override int GetHashCode() => (int)_state;
-
- public StreamingContextStates State => _state;
-
- public object? Context => _additionalContext;
- }
-
- [Flags]
- public enum StreamingContextStates
- {
- CrossProcess = 0x01,
- CrossMachine = 0x02,
- File = 0x04,
- Persistence = 0x08,
- Remoting = 0x10,
- Other = 0x20,
- Clone = 0x40,
- CrossAppDomain = 0x80,
- All = 0xFF,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Versioning/NonVersionableAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Versioning/NonVersionableAttribute.cs
deleted file mode 100644
index cb9533f2c3b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Versioning/NonVersionableAttribute.cs
+++ /dev/null
@@ -1,33 +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.
-
-/*============================================================
-**
-**
-**
-** The [NonVersionable] attribute is applied to indicate that the implementation
-** of a particular member or layout of a struct cannot be changed for given platform in incompatible way.
-** This allows cross-module inlining of methods and data structures whose implementation
-** is never changed in ReadyToRun native images. Any changes to such members or types would be
-** breaking changes for ReadyToRun.
-**
-** Applying this type also has the side effect that the inlining tables in R2R images will not
-** report that inlining of NonVersionable attributed methods occured. These inlining tables are used
-** by profilers to figure out the set of methods that need to be rejited when one method is instrumented,
-** so in effect NonVersionable methods are also non-instrumentable. Generally this is OK for
-** extremely trivial low level methods where NonVersionable gets used, but if there is any plan to
-** significantly extend its usage or allow 3rd parties to use it please discuss with the diagnostics team.
-===========================================================*/
-
-namespace System.Runtime.Versioning
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor,
- AllowMultiple = false, Inherited = false)]
- internal sealed class NonVersionableAttribute : Attribute
- {
- public NonVersionableAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Versioning/TargetFrameworkAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Versioning/TargetFrameworkAttribute.cs
deleted file mode 100644
index 173aee56298..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Runtime/Versioning/TargetFrameworkAttribute.cs
+++ /dev/null
@@ -1,41 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Identifies which SKU and version of the .NET
-** Framework that a particular library was compiled against.
-** Emitted by VS, and can help catch deployment problems.
-**
-===========================================================*/
-
-namespace System.Runtime.Versioning
-{
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
- public sealed class TargetFrameworkAttribute : Attribute
- {
- private readonly string _frameworkName; // A target framework moniker
- private string? _frameworkDisplayName;
-
- // The frameworkName parameter is intended to be the string form of a FrameworkName instance.
- public TargetFrameworkAttribute(string frameworkName)
- {
- if (frameworkName == null)
- throw new ArgumentNullException(nameof(frameworkName));
- _frameworkName = frameworkName;
- }
-
- // The target framework moniker that this assembly was compiled against.
- // Use the FrameworkName class to interpret target framework monikers.
- public string FrameworkName => _frameworkName;
-
- public string? FrameworkDisplayName
- {
- get => _frameworkDisplayName;
- set => _frameworkDisplayName = value;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/RuntimeType.cs b/netcore/System.Private.CoreLib/shared/System/RuntimeType.cs
deleted file mode 100644
index 96cb3ce8342..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/RuntimeType.cs
+++ /dev/null
@@ -1,390 +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 System.Collections.Generic;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- internal sealed partial class RuntimeType : TypeInfo, ICloneable
- {
- public override Assembly Assembly => RuntimeTypeHandle.GetAssembly(this);
- public override Type? BaseType => GetBaseType();
- public override bool IsByRefLike => RuntimeTypeHandle.IsByRefLike(this);
- public override bool IsConstructedGenericType => IsGenericType && !IsGenericTypeDefinition;
- public override bool IsGenericType => RuntimeTypeHandle.HasInstantiation(this);
- public override bool IsGenericTypeDefinition => RuntimeTypeHandle.IsGenericTypeDefinition(this);
- public override bool IsGenericParameter => RuntimeTypeHandle.IsGenericVariable(this);
- public override bool IsTypeDefinition => RuntimeTypeHandle.IsTypeDefinition(this);
- public override bool IsSecurityCritical => true;
- public override bool IsSecuritySafeCritical => false;
- public override bool IsSecurityTransparent => false;
- public override MemberTypes MemberType => (IsPublic || IsNotPublic) ? MemberTypes.TypeInfo : MemberTypes.NestedType;
- public override int MetadataToken => RuntimeTypeHandle.GetToken(this);
- public override Module Module => GetRuntimeModule();
- public override Type? ReflectedType => DeclaringType;
- public override RuntimeTypeHandle TypeHandle => new RuntimeTypeHandle(this);
- public override Type UnderlyingSystemType => this;
-
- public object Clone() => this;
-
- public override bool Equals(object? obj)
- {
- // ComObjects are identified by the instance of the Type object and not the TypeHandle.
- return obj == (object)this;
- }
-
- public override int GetArrayRank()
- {
- if (!IsArrayImpl())
- throw new ArgumentException(SR.Argument_HasToBeArrayClass);
-
- return RuntimeTypeHandle.GetArrayRank(this);
- }
-
- protected override TypeAttributes GetAttributeFlagsImpl() => RuntimeTypeHandle.GetAttributes(this);
-
- public override object[] GetCustomAttributes(bool inherit)
- {
- return CustomAttribute.GetCustomAttributes(this, ObjectType, inherit);
- }
-
- public override object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- if (attributeType is null)
- throw new ArgumentNullException(nameof(attributeType));
-
- RuntimeType? attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType;
-
- if (attributeRuntimeType == null)
- throw new ArgumentException(SR.Arg_MustBeType, nameof(attributeType));
-
- return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType, inherit);
- }
-
- public override IList<CustomAttributeData> GetCustomAttributesData()
- {
- return CustomAttributeData.GetCustomAttributesInternal(this);
- }
-
- // GetDefaultMembers
- // This will return a MemberInfo that has been marked with the [DefaultMemberAttribute]
- public override MemberInfo[] GetDefaultMembers()
- {
- // See if we have cached the default member name
- MemberInfo[] members = null!;
-
- string? defaultMemberName = GetDefaultMemberName();
- if (defaultMemberName != null)
- {
- members = GetMember(defaultMemberName);
- }
-
- return members ?? Array.Empty<MemberInfo>();
- }
-
- public override Type GetElementType() => RuntimeTypeHandle.GetElementType(this);
-
- public override string? GetEnumName(object value)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- Type valueType = value.GetType();
-
- if (!(valueType.IsEnum || IsIntegerType(valueType)))
- throw new ArgumentException(SR.Arg_MustBeEnumBaseTypeOrEnum, nameof(value));
-
- ulong ulValue = Enum.ToUInt64(value);
-
- return Enum.GetEnumName(this, ulValue);
- }
-
- public override string[] GetEnumNames()
- {
- if (!IsEnum)
- throw new ArgumentException(SR.Arg_MustBeEnum, "enumType");
-
- string[] ret = Enum.InternalGetNames(this);
-
- // Make a copy since we can't hand out the same array since users can modify them
- return new ReadOnlySpan<string>(ret).ToArray();
- }
-
- public override Array GetEnumValues()
- {
- if (!IsEnum)
- throw new ArgumentException(SR.Arg_MustBeEnum, "enumType");
-
- // Get all of the values
- ulong[] values = Enum.InternalGetValues(this);
-
- // Create a generic Array
- Array ret = Array.CreateInstance(this, values.Length);
-
- for (int i = 0; i < values.Length; i++)
- {
- object val = Enum.ToObject(this, values[i]);
- ret.SetValue(val, i);
- }
-
- return ret;
- }
-
- public override Type GetEnumUnderlyingType()
- {
- if (!IsEnum)
- throw new ArgumentException(SR.Arg_MustBeEnum, "enumType");
-
- return Enum.InternalGetUnderlyingType(this);
- }
-
- public override Type GetGenericTypeDefinition()
- {
- if (!IsGenericType)
- throw new InvalidOperationException(SR.InvalidOperation_NotGenericType);
-
- return RuntimeTypeHandle.GetGenericTypeDefinition(this);
- }
-
- public override int GetHashCode() => RuntimeHelpers.GetHashCode(this);
-
- internal RuntimeModule GetRuntimeModule() => RuntimeTypeHandle.GetModule(this);
-
- protected override TypeCode GetTypeCodeImpl()
- {
- TypeCode typeCode = Cache.TypeCode;
-
- if (typeCode != TypeCode.Empty)
- return typeCode;
-
- CorElementType corElementType = RuntimeTypeHandle.GetCorElementType(this);
- switch (corElementType)
- {
- case CorElementType.ELEMENT_TYPE_BOOLEAN:
- typeCode = TypeCode.Boolean; break;
- case CorElementType.ELEMENT_TYPE_CHAR:
- typeCode = TypeCode.Char; break;
- case CorElementType.ELEMENT_TYPE_I1:
- typeCode = TypeCode.SByte; break;
- case CorElementType.ELEMENT_TYPE_U1:
- typeCode = TypeCode.Byte; break;
- case CorElementType.ELEMENT_TYPE_I2:
- typeCode = TypeCode.Int16; break;
- case CorElementType.ELEMENT_TYPE_U2:
- typeCode = TypeCode.UInt16; break;
- case CorElementType.ELEMENT_TYPE_I4:
- typeCode = TypeCode.Int32; break;
- case CorElementType.ELEMENT_TYPE_U4:
- typeCode = TypeCode.UInt32; break;
- case CorElementType.ELEMENT_TYPE_I8:
- typeCode = TypeCode.Int64; break;
- case CorElementType.ELEMENT_TYPE_U8:
- typeCode = TypeCode.UInt64; break;
- case CorElementType.ELEMENT_TYPE_R4:
- typeCode = TypeCode.Single; break;
- case CorElementType.ELEMENT_TYPE_R8:
- typeCode = TypeCode.Double; break;
- case CorElementType.ELEMENT_TYPE_VALUETYPE:
- if (this == Convert.ConvertTypes[(int)TypeCode.Decimal])
- typeCode = TypeCode.Decimal;
- else if (this == Convert.ConvertTypes[(int)TypeCode.DateTime])
- typeCode = TypeCode.DateTime;
- else if (IsEnum)
- typeCode = GetTypeCode(Enum.GetUnderlyingType(this));
- else
- typeCode = TypeCode.Object;
- break;
- default:
- if (this == Convert.ConvertTypes[(int)TypeCode.DBNull])
- typeCode = TypeCode.DBNull;
- else if (this == Convert.ConvertTypes[(int)TypeCode.String])
- typeCode = TypeCode.String;
- else
- typeCode = TypeCode.Object;
- break;
- }
-
- Cache.TypeCode = typeCode;
-
- return typeCode;
- }
-
- protected override bool HasElementTypeImpl() => RuntimeTypeHandle.HasElementType(this);
-
- protected override bool IsArrayImpl() => RuntimeTypeHandle.IsArray(this);
-
- protected override bool IsContextfulImpl() => false;
-
- public override bool IsDefined(Type attributeType, bool inherit)
- {
- if (attributeType is null)
- throw new ArgumentNullException(nameof(attributeType));
-
- RuntimeType? attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType;
-
- if (attributeRuntimeType == null)
- throw new ArgumentException(SR.Arg_MustBeType, nameof(attributeType));
-
- return CustomAttribute.IsDefined(this, attributeRuntimeType, inherit);
- }
-
- public override bool IsEnumDefined(object value)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- // Check if both of them are of the same type
- RuntimeType valueType = (RuntimeType)value.GetType();
-
- // If the value is an Enum then we need to extract the underlying value from it
- if (valueType.IsEnum)
- {
- if (!valueType.IsEquivalentTo(this))
- throw new ArgumentException(SR.Format(SR.Arg_EnumAndObjectMustBeSameType, valueType, this));
-
- valueType = (RuntimeType)valueType.GetEnumUnderlyingType();
- }
-
- // If a string is passed in
- if (valueType == StringType)
- {
- // Get all of the Fields, calling GetHashEntry directly to avoid copying
- string[] names = Enum.InternalGetNames(this);
- return Array.IndexOf(names, value) >= 0;
- }
-
- // If an enum or integer value is passed in
- if (IsIntegerType(valueType))
- {
- RuntimeType underlyingType = Enum.InternalGetUnderlyingType(this);
- if (underlyingType != valueType)
- throw new ArgumentException(SR.Format(SR.Arg_EnumUnderlyingTypeAndObjectMustBeSameType, valueType, underlyingType));
-
- ulong[] ulValues = Enum.InternalGetValues(this);
- ulong ulValue = Enum.ToUInt64(value);
-
- return Array.BinarySearch(ulValues, ulValue) >= 0;
- }
- else
- {
- throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
- }
- }
-
- protected override bool IsValueTypeImpl()
- {
- // We need to return true for generic parameters with the ValueType constraint.
- // So we cannot use the faster RuntimeTypeHandle.IsValueType because it returns
- // false for all generic parameters.
- if (this == typeof(ValueType) || this == typeof(Enum))
- return false;
-
- return IsSubclassOf(typeof(ValueType));
- }
-
- protected override bool IsByRefImpl() => RuntimeTypeHandle.IsByRef(this);
-
- protected override bool IsPrimitiveImpl() => RuntimeTypeHandle.IsPrimitive(this);
-
- protected override bool IsPointerImpl() => RuntimeTypeHandle.IsPointer(this);
-
- protected override bool IsCOMObjectImpl() => RuntimeTypeHandle.IsComObject(this, false);
-
- public override bool IsInstanceOfType(object? o) => RuntimeTypeHandle.IsInstanceOfType(this, o);
-
- public override bool IsAssignableFrom(TypeInfo? typeInfo)
- {
- if (typeInfo == null)
- return false;
-
- return IsAssignableFrom(typeInfo.AsType());
- }
-
- public override bool IsAssignableFrom(Type? c)
- {
- if (c is null)
- return false;
-
- if (ReferenceEquals(c, this))
- return true;
-
- // For runtime type, let the VM decide.
- if (c.UnderlyingSystemType is RuntimeType fromType)
- {
- // both this and c (or their underlying system types) are runtime types
- return RuntimeTypeHandle.CanCastTo(fromType, this);
- }
-
- // Special case for TypeBuilder to be backward-compatible.
- if (c is System.Reflection.Emit.TypeBuilder)
- {
- // If c is a subclass of this class, then c can be cast to this type.
- if (c.IsSubclassOf(this))
- return true;
-
- if (IsInterface)
- {
- return c.ImplementInterface(this);
- }
- else if (IsGenericParameter)
- {
- Type[] constraints = GetGenericParameterConstraints();
- for (int i = 0; i < constraints.Length; i++)
- if (!constraints[i].IsAssignableFrom(c))
- return false;
-
- return true;
- }
- }
-
- // For anything else we return false.
- return false;
- }
-
- private RuntimeType? GetBaseType()
- {
- if (IsInterface)
- return null;
-
- if (RuntimeTypeHandle.IsGenericVariable(this))
- {
- Type[] constraints = GetGenericParameterConstraints();
-
- RuntimeType baseType = ObjectType;
-
- for (int i = 0; i < constraints.Length; i++)
- {
- RuntimeType constraint = (RuntimeType)constraints[i];
-
- if (constraint.IsInterface)
- continue;
-
- if (constraint.IsGenericParameter)
- {
- GenericParameterAttributes special = constraint.GenericParameterAttributes & GenericParameterAttributes.SpecialConstraintMask;
-
- if ((special & GenericParameterAttributes.ReferenceTypeConstraint) == 0 &&
- (special & GenericParameterAttributes.NotNullableValueTypeConstraint) == 0)
- continue;
- }
-
- baseType = constraint;
- }
-
- if (baseType == ObjectType)
- {
- GenericParameterAttributes special = GenericParameterAttributes & GenericParameterAttributes.SpecialConstraintMask;
- if ((special & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
- baseType = ValueType;
- }
-
- return baseType;
- }
-
- return RuntimeTypeHandle.GetBaseType(this);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/SByte.cs b/netcore/System.Private.CoreLib/shared/System/SByte.cs
deleted file mode 100644
index 0d6d5e66392..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/SByte.cs
+++ /dev/null
@@ -1,306 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- [Serializable]
- [CLSCompliant(false)]
- [StructLayout(LayoutKind.Sequential)]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct SByte : IComparable, IConvertible, IFormattable, IComparable<sbyte>, IEquatable<sbyte>, ISpanFormattable
- {
- private readonly sbyte m_value; // Do not rename (binary serialization)
-
- // The maximum value that a Byte may represent: 127.
- public const sbyte MaxValue = (sbyte)0x7F;
-
- // The minimum value that a Byte may represent: -128.
- public const sbyte MinValue = unchecked((sbyte)0x80);
-
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type SByte, this method throws an ArgumentException.
- //
- public int CompareTo(object? obj)
- {
- if (obj == null)
- {
- return 1;
- }
- if (!(obj is sbyte))
- {
- throw new ArgumentException(SR.Arg_MustBeSByte);
- }
- return m_value - ((sbyte)obj).m_value;
- }
-
- public int CompareTo(sbyte value)
- {
- return m_value - value;
- }
-
- // Determines whether two Byte objects are equal.
- public override bool Equals(object? obj)
- {
- if (!(obj is sbyte))
- {
- return false;
- }
- return m_value == ((sbyte)obj).m_value;
- }
-
- [NonVersionable]
- public bool Equals(sbyte obj)
- {
- return m_value == obj;
- }
-
- // Gets a hash code for this instance.
- public override int GetHashCode()
- {
- return m_value;
- }
-
-
- // Provides a string representation of a byte.
- public override string ToString()
- {
- return Number.FormatInt32(m_value, null, null);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return Number.FormatInt32(m_value, null, provider);
- }
-
- public string ToString(string? format)
- {
- return ToString(format, null);
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- if (m_value < 0 && format != null && format.Length > 0 && (format[0] == 'X' || format[0] == 'x'))
- {
- uint temp = (uint)(m_value & 0x000000FF);
- return Number.FormatUInt32(temp, format, provider);
- }
- return Number.FormatInt32(m_value, format, provider);
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
- {
- if (m_value < 0 && format.Length > 0 && (format[0] == 'X' || format[0] == 'x'))
- {
- uint temp = (uint)(m_value & 0x000000FF);
- return Number.TryFormatUInt32(temp, format, provider, destination, out charsWritten);
- }
- return Number.TryFormatInt32(m_value, format, provider, destination, out charsWritten);
- }
-
- [CLSCompliant(false)]
- public static sbyte Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static sbyte Parse(string s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, style, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static sbyte Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- // Parses a signed byte from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- //
- [CLSCompliant(false)]
- public static sbyte Parse(string s, NumberStyles style, IFormatProvider? provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static sbyte Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- private static sbyte Parse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info)
- {
- Number.ParsingStatus status = Number.TryParseInt32(s, style, info, out int i);
- if (status != Number.ParsingStatus.OK)
- {
- Number.ThrowOverflowOrFormatException(status, TypeCode.SByte);
- }
-
- // For hex number styles AllowHexSpecifier >> 2 == 0x80 and cancels out MinValue so the check is effectively: (uint)i > byte.MaxValue
- // For integer styles it's zero and the effective check is (uint)(i - MinValue) > byte.MaxValue
- if ((uint)(i - MinValue - ((int)(style & NumberStyles.AllowHexSpecifier) >> 2)) > byte.MaxValue)
- {
- Number.ThrowOverflowException(TypeCode.SByte);
- }
- return (sbyte)i;
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(string? s, out sbyte result)
- {
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<char> s, out sbyte result)
- {
- return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out sbyte result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
-
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out sbyte result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- private static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info, out sbyte result)
- {
- // For hex number styles AllowHexSpecifier >> 2 == 0x80 and cancels out MinValue so the check is effectively: (uint)i > byte.MaxValue
- // For integer styles it's zero and the effective check is (uint)(i - MinValue) > byte.MaxValue
- if (Number.TryParseInt32(s, style, info, out int i) != Number.ParsingStatus.OK
- || (uint)(i - MinValue - ((int)(style & NumberStyles.AllowHexSpecifier) >> 2)) > byte.MaxValue)
- {
- result = 0;
- return false;
- }
- result = (sbyte)i;
- return true;
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.SByte;
- }
-
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return m_value;
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return m_value;
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "SByte", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/AllowPartiallyTrustedCallersAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Security/AllowPartiallyTrustedCallersAttribute.cs
deleted file mode 100644
index 2374ecdd414..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/AllowPartiallyTrustedCallersAttribute.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Security
-{
- // AllowPartiallyTrustedCallersAttribute:
- // Indicates that the Assembly is secure and can be used by untrusted
- // and semitrusted clients
- // For v.1, this is valid only on Assemblies, but could be expanded to
- // include Module, Method, class
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
- public sealed class AllowPartiallyTrustedCallersAttribute : Attribute
- {
- public AllowPartiallyTrustedCallersAttribute() { }
- public PartialTrustVisibilityLevel PartialTrustVisibilityLevel { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/CryptographicException.cs b/netcore/System.Private.CoreLib/shared/System/Security/CryptographicException.cs
deleted file mode 100644
index 1f9e7729742..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/CryptographicException.cs
+++ /dev/null
@@ -1,44 +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 System.Runtime.Serialization;
-
-namespace System.Security.Cryptography
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class CryptographicException : SystemException
- {
- public CryptographicException()
- : base(SR.Arg_CryptographyException)
- {
- }
-
- public CryptographicException(int hr)
- : base(SR.Arg_CryptographyException)
- {
- HResult = hr;
- }
-
- public CryptographicException(string? message)
- : base(message)
- {
- }
-
- public CryptographicException(string? message, Exception? inner)
- : base(message, inner)
- {
- }
-
- public CryptographicException(string format, string? insert)
- : base(string.Format(format, insert))
- {
- }
-
- protected CryptographicException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/IPermission.cs b/netcore/System.Private.CoreLib/shared/System/Security/IPermission.cs
deleted file mode 100644
index f593b88d398..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/IPermission.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System.Security
-{
- public partial interface IPermission : ISecurityEncodable
- {
- IPermission Copy();
- void Demand();
- IPermission? Intersect(IPermission? target);
- bool IsSubsetOf(IPermission? target);
- IPermission? Union(IPermission? target);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/ISecurityEncodable.cs b/netcore/System.Private.CoreLib/shared/System/Security/ISecurityEncodable.cs
deleted file mode 100644
index 2c4865ac10a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/ISecurityEncodable.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Security
-{
- public partial interface ISecurityEncodable
- {
- void FromXml(SecurityElement e);
- SecurityElement? ToXml();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/IStackWalk.cs b/netcore/System.Private.CoreLib/shared/System/Security/IStackWalk.cs
deleted file mode 100644
index f8d472e1bf9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/IStackWalk.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Security
-{
- public partial interface IStackWalk
- {
- void Assert();
- void Demand();
- void Deny();
- void PermitOnly();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/PartialTrustVisibilityLevel.cs b/netcore/System.Private.CoreLib/shared/System/Security/PartialTrustVisibilityLevel.cs
deleted file mode 100644
index c70d4f39cea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/PartialTrustVisibilityLevel.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Security
-{
- public enum PartialTrustVisibilityLevel
- {
- VisibleToAllHosts = 0,
- NotVisibleByDefault = 1
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/PermissionSet.cs b/netcore/System.Private.CoreLib/shared/System/Security/PermissionSet.cs
deleted file mode 100644
index 9f242985235..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/PermissionSet.cs
+++ /dev/null
@@ -1,53 +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.
-
-#nullable enable
-using System.Security.Permissions;
-using System.Collections;
-using System.Runtime.Serialization;
-
-namespace System.Security
-{
- public partial class PermissionSet : ICollection, IEnumerable, IDeserializationCallback, ISecurityEncodable, IStackWalk
- {
- public PermissionSet(PermissionState state) { }
- public PermissionSet(PermissionSet? permSet) { }
- public virtual int Count => 0;
- public virtual bool IsReadOnly => false;
- public virtual bool IsSynchronized => false;
- public virtual object SyncRoot => this;
- public IPermission? AddPermission(IPermission? perm) { return AddPermissionImpl(perm); }
- protected virtual IPermission? AddPermissionImpl(IPermission? perm) { return default; }
- public void Assert() { }
- public bool ContainsNonCodeAccessPermissions() { return false; }
- [Obsolete]
- public static byte[] ConvertPermissionSet(string inFormat, byte[] inData, string outFormat) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_CAS); }
- public virtual PermissionSet Copy() { return new PermissionSet(this); }
- public virtual void CopyTo(Array array, int index) { }
- public void Demand() { }
- [Obsolete]
- public void Deny() { throw new PlatformNotSupportedException(SR.PlatformNotSupported_CAS); }
- public override bool Equals(object? o) => base.Equals(o);
- public virtual void FromXml(SecurityElement et) { }
- public IEnumerator GetEnumerator() { return GetEnumeratorImpl(); }
- protected virtual IEnumerator GetEnumeratorImpl() { return Array.Empty<object>().GetEnumerator(); }
- public override int GetHashCode() => base.GetHashCode();
- public IPermission? GetPermission(Type? permClass) { return GetPermissionImpl(permClass); }
- protected virtual IPermission? GetPermissionImpl(Type? permClass) { return default; }
- public PermissionSet? Intersect(PermissionSet? other) { return default; }
- public bool IsEmpty() { return false; }
- public bool IsSubsetOf(PermissionSet? target) { return false; }
- public bool IsUnrestricted() { return false; }
- public void PermitOnly() { throw new PlatformNotSupportedException(SR.PlatformNotSupported_CAS); }
- public IPermission? RemovePermission(Type? permClass) { return RemovePermissionImpl(permClass); }
- protected virtual IPermission? RemovePermissionImpl(Type? permClass) { return default; }
- public static void RevertAssert() { }
- public IPermission? SetPermission(IPermission? perm) { return SetPermissionImpl(perm); }
- protected virtual IPermission? SetPermissionImpl(IPermission? perm) { return default; }
- void IDeserializationCallback.OnDeserialization(object? sender) { }
- public override string ToString() => base.ToString()!;
- public virtual SecurityElement? ToXml() { return default; }
- public PermissionSet? Union(PermissionSet? other) { return default; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/Permissions/PermissionState.cs b/netcore/System.Private.CoreLib/shared/System/Security/Permissions/PermissionState.cs
deleted file mode 100644
index aace3dc6ada..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/Permissions/PermissionState.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Security.Permissions
-{
- public enum PermissionState
- {
- None = 0,
- Unrestricted = 1,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/Principal/IIdentity.cs b/netcore/System.Private.CoreLib/shared/System/Security/Principal/IIdentity.cs
deleted file mode 100644
index cf203af45f9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/Principal/IIdentity.cs
+++ /dev/null
@@ -1,22 +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.
-
-//
-// All identities will implement this interface
-//
-
-namespace System.Security.Principal
-{
- public interface IIdentity
- {
- // Access to the name string
- string? Name { get; }
-
- // Access to Authentication 'type' info
- string? AuthenticationType { get; }
-
- // Determine if this represents the unauthenticated identity
- bool IsAuthenticated { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/Principal/IPrincipal.cs b/netcore/System.Private.CoreLib/shared/System/Security/Principal/IPrincipal.cs
deleted file mode 100644
index dea0e2b3ef7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/Principal/IPrincipal.cs
+++ /dev/null
@@ -1,19 +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.
-
-//
-// All roles will implement this interface
-//
-
-namespace System.Security.Principal
-{
- public interface IPrincipal
- {
- // Retrieve the identity object
- IIdentity? Identity { get; }
-
- // Perform a check for a specific role
- bool IsInRole(string role);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/Principal/PrincipalPolicy.cs b/netcore/System.Private.CoreLib/shared/System/Security/Principal/PrincipalPolicy.cs
deleted file mode 100644
index 3fbed647f10..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/Principal/PrincipalPolicy.cs
+++ /dev/null
@@ -1,19 +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.
-
-//
-// Enum describing what type of principal to create by default (assuming no
-// principal has been set on the AppDomain).
-//
-
-namespace System.Security.Principal
-{
- public enum PrincipalPolicy
- {
- // Note: it's important that the default policy has the value 0.
- UnauthenticatedPrincipal = 0,
- NoPrincipal = 1,
- WindowsPrincipal = 2,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecureString.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecureString.Unix.cs
deleted file mode 100644
index d3fbd9b2bdd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecureString.Unix.cs
+++ /dev/null
@@ -1,38 +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 System.Diagnostics;
-using System.Runtime;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System.Security
-{
- // SecureString attempts to provide a defense-in-depth solution.
- //
- // On Windows, this is done with several mechanisms:
- // 1. keeping the data in unmanaged memory so that copies of it aren't implicitly made by the GC moving it around
- // 2. zero'ing out that unmanaged memory so that the string is reliably removed from memory when done with it
- // 3. encrypting the data while it's not being used (it's unencrypted to manipulate and use it)
- //
- // On Unix, we do 1 and 2, but we don't do 3 as there's no CryptProtectData equivalent.
-
- public sealed partial class SecureString
- {
- private static int GetAlignedByteSize(int length)
- {
- return Math.Max(length, 1) * sizeof(char);
- }
-
- private void ProtectMemory()
- {
- _encrypted = true;
- }
-
- private void UnprotectMemory()
- {
- _encrypted = false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs
deleted file mode 100644
index 9e226ec7a8a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs
+++ /dev/null
@@ -1,52 +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 System.Diagnostics;
-using System.Runtime;
-using System.Runtime.InteropServices;
-using System.Security.Cryptography;
-
-namespace System.Security
-{
- public sealed partial class SecureString
- {
- private static int GetAlignedByteSize(int length)
- {
- int byteSize = Math.Max(length, 1) * sizeof(char);
-
- const int blockSize = (int)Interop.Crypt32.CRYPTPROTECTMEMORY_BLOCK_SIZE;
- return ((byteSize + (blockSize - 1)) / blockSize) * blockSize;
- }
-
- private void ProtectMemory()
- {
- Debug.Assert(_buffer != null);
- Debug.Assert(!_buffer.IsInvalid, "Invalid buffer!");
-
- if (_decryptedLength != 0 &&
- !_encrypted &&
- !Interop.Crypt32.CryptProtectMemory(_buffer, (uint)_buffer.ByteLength, Interop.Crypt32.CRYPTPROTECTMEMORY_SAME_PROCESS))
- {
- throw new CryptographicException(Marshal.GetLastWin32Error());
- }
-
- _encrypted = true;
- }
-
- private void UnprotectMemory()
- {
- Debug.Assert(_buffer != null);
- Debug.Assert(!_buffer.IsInvalid, "Invalid buffer!");
-
- if (_decryptedLength != 0 &&
- _encrypted &&
- !Interop.Crypt32.CryptUnprotectMemory(_buffer, (uint)_buffer.ByteLength, Interop.Crypt32.CRYPTPROTECTMEMORY_SAME_PROCESS))
- {
- throw new CryptographicException(Marshal.GetLastWin32Error());
- }
-
- _encrypted = false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecureString.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecureString.cs
deleted file mode 100644
index 35deabaf8ad..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecureString.cs
+++ /dev/null
@@ -1,480 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-namespace System.Security
-{
- public sealed partial class SecureString : IDisposable
- {
- private const int MaxLength = 65536;
- private readonly object _methodLock = new object();
- private UnmanagedBuffer? _buffer;
- private int _decryptedLength;
- private bool _encrypted;
- private bool _readOnly;
-
- public SecureString()
- {
- Initialize(ReadOnlySpan<char>.Empty);
- }
-
- [CLSCompliant(false)]
- public unsafe SecureString(char* value, int length)
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if (length < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (length > MaxLength)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Length);
- }
-
- Initialize(new ReadOnlySpan<char>(value, length));
- }
-
- private void Initialize(ReadOnlySpan<char> value)
- {
- _buffer = UnmanagedBuffer.Allocate(GetAlignedByteSize(value.Length));
- _decryptedLength = value.Length;
-
- SafeBuffer? bufferToRelease = null;
- try
- {
- Span<char> span = AcquireSpan(ref bufferToRelease);
- value.CopyTo(span);
- }
- finally
- {
- ProtectMemory();
- bufferToRelease?.DangerousRelease();
- }
- }
-
- private SecureString(SecureString str)
- {
- Debug.Assert(str._buffer != null, "Expected other SecureString's buffer to be non-null");
- Debug.Assert(str._encrypted, "Expected to be used only on encrypted SecureStrings");
-
- _buffer = UnmanagedBuffer.Allocate((int)str._buffer.ByteLength);
- Debug.Assert(_buffer != null);
- UnmanagedBuffer.Copy(str._buffer, _buffer, str._buffer.ByteLength);
-
- _decryptedLength = str._decryptedLength;
- _encrypted = str._encrypted;
- }
-
- public int Length
- {
- get
- {
- EnsureNotDisposed();
- return Volatile.Read(ref _decryptedLength);
- }
- }
-
- private void EnsureCapacity(int capacity)
- {
- if (capacity > MaxLength)
- {
- throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_Capacity);
- }
-
- Debug.Assert(_buffer != null);
- if ((uint)capacity * sizeof(char) <= _buffer.ByteLength)
- {
- return;
- }
-
- UnmanagedBuffer oldBuffer = _buffer;
- UnmanagedBuffer newBuffer = UnmanagedBuffer.Allocate(GetAlignedByteSize(capacity));
- UnmanagedBuffer.Copy(oldBuffer, newBuffer, (uint)_decryptedLength * sizeof(char));
- _buffer = newBuffer;
- oldBuffer.Dispose();
- }
-
- public void AppendChar(char c)
- {
- lock (_methodLock)
- {
- EnsureNotDisposed();
- EnsureNotReadOnly();
-
- Debug.Assert(_buffer != null);
-
- SafeBuffer? bufferToRelease = null;
-
- try
- {
- UnprotectMemory();
-
- EnsureCapacity(_decryptedLength + 1);
-
- Span<char> span = AcquireSpan(ref bufferToRelease);
- span[_decryptedLength] = c;
- _decryptedLength++;
- }
- finally
- {
- ProtectMemory();
- bufferToRelease?.DangerousRelease();
- }
- }
- }
-
- // clears the current contents. Only available if writable
- public void Clear()
- {
- lock (_methodLock)
- {
- EnsureNotDisposed();
- EnsureNotReadOnly();
-
- Debug.Assert(_buffer != null);
-
- _decryptedLength = 0;
-
- SafeBuffer? bufferToRelease = null;
- try
- {
- Span<char> span = AcquireSpan(ref bufferToRelease);
- span.Clear();
- }
- finally
- {
- bufferToRelease?.DangerousRelease();
- }
- }
- }
-
- // Do a deep-copy of the SecureString
- public SecureString Copy()
- {
- lock (_methodLock)
- {
- EnsureNotDisposed();
- return new SecureString(this);
- }
- }
-
- public void Dispose()
- {
- lock (_methodLock)
- {
- if (_buffer != null)
- {
- _buffer.Dispose();
- _buffer = null;
- }
- }
- }
-
- public void InsertAt(int index, char c)
- {
- lock (_methodLock)
- {
- if (index < 0 || index > _decryptedLength)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexString);
- }
-
- EnsureNotDisposed();
- EnsureNotReadOnly();
-
- Debug.Assert(_buffer != null);
-
- SafeBuffer? bufferToRelease = null;
-
- try
- {
- UnprotectMemory();
-
- EnsureCapacity(_decryptedLength + 1);
-
- Span<char> span = AcquireSpan(ref bufferToRelease);
- span.Slice(index, _decryptedLength - index).CopyTo(span.Slice(index + 1));
- span[index] = c;
- _decryptedLength++;
- }
- finally
- {
- ProtectMemory();
- bufferToRelease?.DangerousRelease();
- }
- }
- }
-
- public bool IsReadOnly()
- {
- EnsureNotDisposed();
- return Volatile.Read(ref _readOnly);
- }
-
- public void MakeReadOnly()
- {
- EnsureNotDisposed();
- Volatile.Write(ref _readOnly, true);
- }
-
- public void RemoveAt(int index)
- {
- lock (_methodLock)
- {
- if (index < 0 || index >= _decryptedLength)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexString);
- }
-
- EnsureNotDisposed();
- EnsureNotReadOnly();
-
- Debug.Assert(_buffer != null);
-
- SafeBuffer? bufferToRelease = null;
-
- try
- {
- UnprotectMemory();
-
- Span<char> span = AcquireSpan(ref bufferToRelease);
- span.Slice(index + 1, _decryptedLength - (index + 1)).CopyTo(span.Slice(index));
- _decryptedLength--;
- }
- finally
- {
- ProtectMemory();
- bufferToRelease?.DangerousRelease();
- }
- }
- }
-
- public void SetAt(int index, char c)
- {
- lock (_methodLock)
- {
- if (index < 0 || index >= _decryptedLength)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_IndexString);
- }
-
- EnsureNotDisposed();
- EnsureNotReadOnly();
-
- Debug.Assert(_buffer != null);
-
- SafeBuffer? bufferToRelease = null;
-
- try
- {
- UnprotectMemory();
-
- Span<char> span = AcquireSpan(ref bufferToRelease);
- span[index] = c;
- }
- finally
- {
- ProtectMemory();
- bufferToRelease?.DangerousRelease();
- }
- }
- }
-
- private unsafe Span<char> AcquireSpan(ref SafeBuffer? bufferToRelease)
- {
- SafeBuffer buffer = _buffer!;
-
- bool ignore = false;
- buffer.DangerousAddRef(ref ignore);
-
- bufferToRelease = buffer;
-
- return new Span<char>((byte*)buffer.DangerousGetHandle(), (int)(buffer.ByteLength / 2));
- }
-
- private void EnsureNotReadOnly()
- {
- if (_readOnly)
- {
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
- }
- }
-
- private void EnsureNotDisposed()
- {
- if (_buffer == null)
- {
- throw new ObjectDisposedException(GetType().Name);
- }
- }
-
- internal unsafe IntPtr MarshalToBSTR()
- {
- lock (_methodLock)
- {
- EnsureNotDisposed();
-
- UnprotectMemory();
-
- SafeBuffer? bufferToRelease = null;
- IntPtr ptr = IntPtr.Zero;
- int length = 0;
- try
- {
- Span<char> span = AcquireSpan(ref bufferToRelease);
-
- length = _decryptedLength;
- ptr = Marshal.AllocBSTR(length);
- span.Slice(0, length).CopyTo(new Span<char>((void*)ptr, length));
-
- IntPtr result = ptr;
- ptr = IntPtr.Zero;
- return result;
- }
- finally
- {
- // If we failed for any reason, free the new buffer
- if (ptr != IntPtr.Zero)
- {
- new Span<char>((void*)ptr, length).Clear();
- Marshal.FreeBSTR(ptr);
- }
-
- ProtectMemory();
- bufferToRelease?.DangerousRelease();
- }
- }
- }
-
- internal unsafe IntPtr MarshalToString(bool globalAlloc, bool unicode)
- {
- lock (_methodLock)
- {
- EnsureNotDisposed();
-
- UnprotectMemory();
-
- SafeBuffer? bufferToRelease = null;
- IntPtr ptr = IntPtr.Zero;
- int byteLength = 0;
- try
- {
- Span<char> span = AcquireSpan(ref bufferToRelease).Slice(0, _decryptedLength);
-
- if (unicode)
- {
- byteLength = (span.Length + 1) * sizeof(char);
- }
- else
- {
- byteLength = Marshal.GetAnsiStringByteCount(span);
- }
-
- if (globalAlloc)
- {
- ptr = Marshal.AllocHGlobal(byteLength);
- }
- else
- {
- ptr = Marshal.AllocCoTaskMem(byteLength);
- }
-
- if (unicode)
- {
- Span<char> resultSpan = new Span<char>((void*)ptr, byteLength / sizeof(char));
- span.CopyTo(resultSpan);
- resultSpan[resultSpan.Length - 1] = '\0';
- }
- else
- {
- Marshal.GetAnsiStringBytes(span, new Span<byte>((void*)ptr, byteLength));
- }
-
- IntPtr result = ptr;
- ptr = IntPtr.Zero;
- return result;
- }
- finally
- {
- // If we failed for any reason, free the new buffer
- if (ptr != IntPtr.Zero)
- {
- new Span<byte>((void*)ptr, byteLength).Clear();
-
- if (globalAlloc)
- {
- Marshal.FreeHGlobal(ptr);
- }
- else
- {
- Marshal.FreeCoTaskMem(ptr);
- }
- }
-
- ProtectMemory();
- bufferToRelease?.DangerousRelease();
- }
- }
- }
-
- /// <summary>SafeBuffer for managing memory meant to be kept confidential.</summary>
- private sealed class UnmanagedBuffer : SafeBuffer
- {
- // A local copy of byte length to be able to access it in ReleaseHandle without the risk of throwing exceptions
- private int _byteLength;
-
- private UnmanagedBuffer() : base(true) { }
-
- public static UnmanagedBuffer Allocate(int byteLength)
- {
- Debug.Assert(byteLength >= 0);
- UnmanagedBuffer buffer = new UnmanagedBuffer();
- buffer.SetHandle(Marshal.AllocHGlobal(byteLength));
- buffer.Initialize((ulong)byteLength);
- buffer._byteLength = byteLength;
- return buffer;
- }
-
- internal static unsafe void Copy(UnmanagedBuffer source, UnmanagedBuffer destination, ulong bytesLength)
- {
- if (bytesLength == 0)
- {
- return;
- }
-
- byte* srcPtr = null, dstPtr = null;
- try
- {
- source.AcquirePointer(ref srcPtr);
- destination.AcquirePointer(ref dstPtr);
- Buffer.MemoryCopy(srcPtr, dstPtr, destination.ByteLength, bytesLength);
- }
- finally
- {
- if (dstPtr != null)
- {
- destination.ReleasePointer();
- }
- if (srcPtr != null)
- {
- source.ReleasePointer();
- }
- }
- }
-
- protected override unsafe bool ReleaseHandle()
- {
- new Span<byte>((void*)handle, _byteLength).Clear();
- Marshal.FreeHGlobal(handle);
- return true;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecurityCriticalAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecurityCriticalAttribute.cs
deleted file mode 100644
index 40012da06d1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecurityCriticalAttribute.cs
+++ /dev/null
@@ -1,35 +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.
-
-namespace System.Security
-{
- // SecurityCriticalAttribute
- // Indicates that the decorated code or assembly performs security critical operations (e.g. Assert, "unsafe", LinkDemand, etc.)
- // The attribute can be placed on most targets, except on arguments/return values.
- [AttributeUsage(AttributeTargets.Assembly |
- AttributeTargets.Class |
- AttributeTargets.Struct |
- AttributeTargets.Enum |
- AttributeTargets.Constructor |
- AttributeTargets.Method |
- AttributeTargets.Field |
- AttributeTargets.Interface |
- AttributeTargets.Delegate,
- AllowMultiple = false,
- Inherited = false)]
- public sealed class SecurityCriticalAttribute : Attribute
- {
-#pragma warning disable 618 // We still use SecurityCriticalScope for v2 compat
- public SecurityCriticalAttribute() { }
-
- public SecurityCriticalAttribute(SecurityCriticalScope scope)
- {
- Scope = scope;
- }
-
- [Obsolete("SecurityCriticalScope is only used for .NET 2.0 transparency compatibility.")]
- public SecurityCriticalScope Scope { get; }
-#pragma warning restore 618
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecurityCriticalScope.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecurityCriticalScope.cs
deleted file mode 100644
index d9b1a05a399..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecurityCriticalScope.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Security
-{
- [Obsolete("SecurityCriticalScope is only used for .NET 2.0 transparency compatibility.")]
- public enum SecurityCriticalScope
- {
- Explicit = 0,
- Everything = 0x1
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecurityElement.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecurityElement.cs
deleted file mode 100644
index 541f22dccdc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecurityElement.cs
+++ /dev/null
@@ -1,606 +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.s
-
-using System.Collections;
-using System.Diagnostics;
-using System.Text;
-
-namespace System.Security
-{
- public sealed class SecurityElement
- {
- internal string _tag = null!;
- internal string? _text;
- private ArrayList? _children;
- internal ArrayList? _attributes;
-
- private const int AttributesTypical = 4 * 2; // 4 attributes, times 2 strings per attribute
- private const int ChildrenTypical = 1;
-
- private static readonly char[] s_tagIllegalCharacters = new char[] { ' ', '<', '>' };
- private static readonly char[] s_textIllegalCharacters = new char[] { '<', '>' };
- private static readonly char[] s_valueIllegalCharacters = new char[] { '<', '>', '\"' };
- private static readonly char[] s_escapeChars = new char[] { '<', '>', '\"', '\'', '&' };
- private static readonly string[] s_escapeStringPairs = new string[]
- {
- // these must be all once character escape sequences or a new escaping algorithm is needed
- "<", "&lt;",
- ">", "&gt;",
- "\"", "&quot;",
- "\'", "&apos;",
- "&", "&amp;"
- };
-
- //-------------------------- Constructors ---------------------------
-
- internal SecurityElement()
- {
- }
-
- public SecurityElement(string tag)
- {
- if (tag == null)
- throw new ArgumentNullException(nameof(tag));
-
- if (!IsValidTag(tag))
- throw new ArgumentException(SR.Format(SR.Argument_InvalidElementTag, tag));
-
- _tag = tag;
- _text = null;
- }
-
- public SecurityElement(string tag, string? text)
- {
- if (tag == null)
- throw new ArgumentNullException(nameof(tag));
-
- if (!IsValidTag(tag))
- throw new ArgumentException(SR.Format(SR.Argument_InvalidElementTag, tag));
-
- if (text != null && !IsValidText(text))
- throw new ArgumentException(SR.Format(SR.Argument_InvalidElementText, text));
-
- _tag = tag;
- _text = text;
- }
-
- //-------------------------- Properties -----------------------------
-
- public string Tag
- {
- get => _tag;
- set
- {
- if (value == null)
- throw new ArgumentNullException(nameof(Tag));
-
- if (!IsValidTag(value))
- throw new ArgumentException(SR.Format(SR.Argument_InvalidElementTag, value));
-
- _tag = value;
- }
- }
-
- public Hashtable? Attributes
- {
- get
- {
- if (_attributes == null || _attributes.Count == 0)
- {
- return null;
- }
- else
- {
- Hashtable hashtable = new Hashtable(_attributes.Count / 2);
-
- int iMax = _attributes.Count;
- Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");
-
- for (int i = 0; i < iMax; i += 2)
- {
- hashtable.Add(_attributes[i]!, _attributes[i + 1]);
- }
-
- return hashtable;
- }
- }
-
- set
- {
- if (value == null || value.Count == 0)
- {
- _attributes = null;
- }
- else
- {
- ArrayList list = new ArrayList(value.Count);
- IDictionaryEnumerator enumerator = value.GetEnumerator();
-
- while (enumerator.MoveNext())
- {
- string attrName = (string)enumerator.Key;
- string? attrValue = (string?)enumerator.Value;
-
- if (!IsValidAttributeName(attrName))
- throw new ArgumentException(SR.Format(SR.Argument_InvalidElementName, attrName));
-
- if (!IsValidAttributeValue(attrValue))
- throw new ArgumentException(SR.Format(SR.Argument_InvalidElementValue, attrValue));
-
- list.Add(attrName);
- list.Add(attrValue);
- }
-
- _attributes = list;
- }
- }
- }
-
- public string? Text
- {
- get => Unescape(_text);
- set
- {
- if (value == null)
- {
- _text = null;
- }
- else
- {
- if (!IsValidText(value))
- throw new ArgumentException(SR.Format(SR.Argument_InvalidElementTag, value));
-
- _text = value;
- }
- }
- }
-
- public ArrayList? Children
- {
- get
- {
- return _children;
- }
-
- set
- {
- if (value != null && value.Contains(null))
- {
- throw new ArgumentException(SR.ArgumentNull_Child);
- }
- _children = value;
- }
- }
-
- //-------------------------- Public Methods -----------------------------
-
- internal void AddAttributeSafe(string name, string value)
- {
- if (_attributes == null)
- {
- _attributes = new ArrayList(AttributesTypical);
- }
- else
- {
- int iMax = _attributes.Count;
- Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");
-
- for (int i = 0; i < iMax; i += 2)
- {
- string? strAttrName = (string?)_attributes[i];
-
- if (string.Equals(strAttrName, name))
- throw new ArgumentException(SR.Argument_AttributeNamesMustBeUnique);
- }
- }
-
- _attributes.Add(name);
- _attributes.Add(value);
- }
-
- public void AddAttribute(string name, string value)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- if (!IsValidAttributeName(name))
- throw new ArgumentException(SR.Format(SR.Argument_InvalidElementName, name));
-
- if (!IsValidAttributeValue(value))
- throw new ArgumentException(SR.Format(SR.Argument_InvalidElementValue, value));
-
- AddAttributeSafe(name, value);
- }
-
- public void AddChild(SecurityElement child)
- {
- if (child == null)
- throw new ArgumentNullException(nameof(child));
-
- _children ??= new ArrayList(ChildrenTypical);
-
- _children.Add(child);
- }
-
- public bool Equal(SecurityElement? other)
- {
- if (other == null)
- return false;
-
- // Check if the tags are the same
- if (!string.Equals(_tag, other._tag))
- return false;
-
- // Check if the text is the same
- if (!string.Equals(_text, other._text))
- return false;
-
- // Check if the attributes are the same and appear in the same
- // order.
- if (_attributes == null || other._attributes == null)
- {
- if (_attributes != other._attributes)
- return false;
- }
- else
- {
- int iMax = _attributes.Count;
- Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");
-
- // Maybe we can get away by only checking the number of attributes
- if (iMax != other._attributes.Count)
- return false;
-
- for (int i = 0; i < iMax; i++)
- {
- string? lhs = (string?)_attributes[i];
- string? rhs = (string?)other._attributes[i];
-
- if (!string.Equals(lhs, rhs))
- return false;
- }
- }
-
- // Finally we must check the child and make sure they are
- // equal and in the same order
- if (_children == null || other._children == null)
- {
- if (_children != other._children)
- return false;
- }
- else
- {
- // Maybe we can get away by only checking the number of children
- if (_children.Count != other._children.Count)
- return false;
-
- IEnumerator lhs = _children.GetEnumerator();
- IEnumerator rhs = other._children.GetEnumerator();
-
- SecurityElement? e1, e2;
- while (lhs.MoveNext())
- {
- rhs.MoveNext();
- e1 = (SecurityElement?)lhs.Current;
- e2 = (SecurityElement?)rhs.Current;
- if (e1 == null || !e1.Equal(e2))
- return false;
- }
- }
- return true;
- }
-
- public SecurityElement Copy()
- {
- SecurityElement element = new SecurityElement(_tag, _text);
- element._children = _children == null ? null : new ArrayList(_children);
- element._attributes = _attributes == null ? null : new ArrayList(_attributes);
-
- return element;
- }
-
- public static bool IsValidTag(string? tag)
- {
- if (tag == null)
- return false;
-
- return tag.IndexOfAny(s_tagIllegalCharacters) == -1;
- }
-
- public static bool IsValidText(string? text)
- {
- if (text == null)
- return false;
-
- return text.IndexOfAny(s_textIllegalCharacters) == -1;
- }
-
- public static bool IsValidAttributeName(string? name)
- {
- return IsValidTag(name);
- }
-
- public static bool IsValidAttributeValue(string? value)
- {
- if (value == null)
- return false;
-
- return value.IndexOfAny(s_valueIllegalCharacters) == -1;
- }
-
- private static string GetEscapeSequence(char c)
- {
- int iMax = s_escapeStringPairs.Length;
- Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");
-
- for (int i = 0; i < iMax; i += 2)
- {
- string strEscSeq = s_escapeStringPairs[i];
- string strEscValue = s_escapeStringPairs[i + 1];
-
- if (strEscSeq[0] == c)
- return strEscValue;
- }
-
- Debug.Fail("Unable to find escape sequence for this character");
- return c.ToString();
- }
-
- public static string? Escape(string? str)
- {
- if (str == null)
- return null;
-
- StringBuilder? sb = null;
-
- int strLen = str.Length;
- int index; // Pointer into the string that indicates the location of the current '&' character
- int newIndex = 0; // Pointer into the string that indicates the start index of the "remaining" string (that still needs to be processed).
-
- while (true)
- {
- index = str.IndexOfAny(s_escapeChars, newIndex);
-
- if (index == -1)
- {
- if (sb == null)
- return str;
- else
- {
- sb.Append(str, newIndex, strLen - newIndex);
- return sb.ToString();
- }
- }
- else
- {
- sb ??= new StringBuilder();
-
- sb.Append(str, newIndex, index - newIndex);
- sb.Append(GetEscapeSequence(str[index]));
-
- newIndex = (index + 1);
- }
- }
-
- // no normal exit is possible
- }
-
- private static string GetUnescapeSequence(string str, int index, out int newIndex)
- {
- int maxCompareLength = str.Length - index;
-
- int iMax = s_escapeStringPairs.Length;
- Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");
-
- for (int i = 0; i < iMax; i += 2)
- {
- string strEscSeq = s_escapeStringPairs[i];
- string strEscValue = s_escapeStringPairs[i + 1];
-
- int length = strEscValue.Length;
-
- if (length <= maxCompareLength && string.Compare(strEscValue, 0, str, index, length, StringComparison.Ordinal) == 0)
- {
- newIndex = index + strEscValue.Length;
- return strEscSeq;
- }
- }
-
- newIndex = index + 1;
- return str[index].ToString();
- }
-
- private static string? Unescape(string? str)
- {
- if (str == null)
- return null;
-
- StringBuilder? sb = null;
-
- int strLen = str.Length;
- int index; // Pointer into the string that indicates the location of the current '&' character
- int newIndex = 0; // Pointer into the string that indicates the start index of the "remainging" string (that still needs to be processed).
-
- while (true)
- {
- index = str.IndexOf('&', newIndex);
-
- if (index == -1)
- {
- if (sb == null)
- return str;
- else
- {
- sb.Append(str, newIndex, strLen - newIndex);
- return sb.ToString();
- }
- }
- else
- {
- sb ??= new StringBuilder();
-
- sb.Append(str, newIndex, index - newIndex);
- sb.Append(GetUnescapeSequence(str, index, out newIndex)); // updates the newIndex too
- }
- }
- }
-
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
-
- ToString(sb, (obj, str) => ((StringBuilder)obj).Append(str));
-
- return sb.ToString();
- }
-
- private void ToString(object obj, Action<object, string?> write)
- {
- write(obj, "<");
- write(obj, _tag);
-
- // If there are any attributes, plop those in.
- if (_attributes != null && _attributes.Count > 0)
- {
- write(obj, " ");
-
- int iMax = _attributes.Count;
- Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");
-
- for (int i = 0; i < iMax; i += 2)
- {
- string? strAttrName = (string?)_attributes[i];
- string? strAttrValue = (string?)_attributes[i + 1];
-
- write(obj, strAttrName);
- write(obj, "=\"");
- write(obj, strAttrValue);
- write(obj, "\"");
-
- if (i != _attributes.Count - 2)
- {
- write(obj, Environment.NewLineConst);
- }
- }
- }
-
- if (_text == null && (_children == null || _children.Count == 0))
- {
- // If we are a single tag with no children, just add the end of tag text.
- write(obj, "/>");
- write(obj, Environment.NewLineConst);
- }
- else
- {
- // Close the current tag.
- write(obj, ">");
-
- // Output the text
- write(obj, _text);
-
- // Output any children.
- if (_children != null)
- {
- write(obj, Environment.NewLineConst);
-
- for (int i = 0; i < _children.Count; ++i)
- {
- ((SecurityElement)_children[i]!).ToString(obj, write);
- }
- }
-
- // Output the closing tag
- write(obj, "</");
- write(obj, _tag);
- write(obj, ">");
- write(obj, Environment.NewLineConst);
- }
- }
-
- public string? Attribute(string name)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- // Note: we don't check for validity here because an
- // if an invalid name is passed we simply won't find it.
- if (_attributes == null)
- return null;
-
- // Go through all the attribute and see if we know about
- // the one we are asked for
- int iMax = _attributes.Count;
- Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");
-
- for (int i = 0; i < iMax; i += 2)
- {
- string? strAttrName = (string?)_attributes[i];
-
- if (string.Equals(strAttrName, name))
- {
- string? strAttrValue = (string?)_attributes[i + 1];
-
- return Unescape(strAttrValue);
- }
- }
-
- // In the case where we didn't find it, we are expected to
- // return null
- return null;
- }
-
- public SecurityElement? SearchForChildByTag(string tag)
- {
- // Go through all the children and see if we can
- // find the ones that are asked for (matching tags)
- if (tag == null)
- throw new ArgumentNullException(nameof(tag));
-
- // Note: we don't check for a valid tag here because
- // an invalid tag simply won't be found.
- if (_children == null)
- return null;
- foreach (SecurityElement? current in _children)
- {
- if (current != null && string.Equals(current.Tag, tag))
- return current;
- }
- return null;
- }
-
- public string? SearchForTextOfTag(string tag)
- {
- // Search on each child in order and each
- // child's child, depth-first
- if (tag == null)
- throw new ArgumentNullException(nameof(tag));
-
- // Note: we don't check for a valid tag here because
- // an invalid tag simply won't be found.
- if (string.Equals(_tag, tag))
- return Unescape(_text);
- if (_children == null)
- return null;
-
- foreach (SecurityElement? child in Children!)
- {
- string? text = child?.SearchForTextOfTag(tag);
- if (text != null)
- return text;
- }
- return null;
- }
-
- public static SecurityElement? FromString(string xml)
- {
- if (xml == null)
- throw new ArgumentNullException(nameof(xml));
-
- return default;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecurityException.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecurityException.cs
deleted file mode 100644
index 34373635241..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecurityException.cs
+++ /dev/null
@@ -1,89 +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 System.Reflection;
-using System.Runtime.Serialization;
-
-namespace System.Security
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class SecurityException : SystemException
- {
- private const string DemandedName = "Demanded";
- private const string GrantedSetName = "GrantedSet";
- private const string RefusedSetName = "RefusedSet";
- private const string DeniedName = "Denied";
- private const string PermitOnlyName = "PermitOnly";
- private const string UrlName = "Url";
-
- public SecurityException()
- : base(SR.Arg_SecurityException)
- {
- HResult = HResults.COR_E_SECURITY;
- }
-
- public SecurityException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_SECURITY;
- }
-
- public SecurityException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_SECURITY;
- }
-
- public SecurityException(string? message, Type? type)
- : base(message)
- {
- HResult = HResults.COR_E_SECURITY;
- PermissionType = type;
- }
-
- public SecurityException(string? message, Type? type, string? state)
- : base(message)
- {
- HResult = HResults.COR_E_SECURITY;
- PermissionType = type;
- PermissionState = state;
- }
-
- protected SecurityException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- Demanded = (string?)info.GetValueNoThrow(DemandedName, typeof(string));
- GrantedSet = (string?)info.GetValueNoThrow(GrantedSetName, typeof(string));
- RefusedSet = (string?)info.GetValueNoThrow(RefusedSetName, typeof(string));
- DenySetInstance = (string?)info.GetValueNoThrow(DeniedName, typeof(string));
- PermitOnlySetInstance = (string?)info.GetValueNoThrow(PermitOnlyName, typeof(string));
- Url = (string?)info.GetValueNoThrow(UrlName, typeof(string));
- }
-
- public override string ToString() => base.ToString();
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue(DemandedName, Demanded, typeof(string));
- info.AddValue(GrantedSetName, GrantedSet, typeof(string));
- info.AddValue(RefusedSetName, RefusedSet, typeof(string));
- info.AddValue(DeniedName, DenySetInstance, typeof(string));
- info.AddValue(PermitOnlyName, PermitOnlySetInstance, typeof(string));
- info.AddValue(UrlName, Url, typeof(string));
- }
-
- public object? Demanded { get; set; }
- public object? DenySetInstance { get; set; }
- public AssemblyName? FailedAssemblyInfo { get; set; }
- public string? GrantedSet { get; set; }
- public MethodInfo? Method { get; set; }
- public string? PermissionState { get; set; }
- public Type? PermissionType { get; set; }
- public object? PermitOnlySetInstance { get; set; }
- public string? RefusedSet { get; set; }
- public string? Url { get; set; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecurityRuleSet.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecurityRuleSet.cs
deleted file mode 100644
index 79eebf8bba0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecurityRuleSet.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Security
-{
- public enum SecurityRuleSet : byte
- {
- None = 0,
- Level1 = 1, // v2.0 transparency model
- Level2 = 2, // v4.0 transparency model
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecurityRulesAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecurityRulesAttribute.cs
deleted file mode 100644
index dc12742fc8c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecurityRulesAttribute.cs
+++ /dev/null
@@ -1,27 +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.
-
-namespace System.Security
-{
- // SecurityRulesAttribute
- //
- // Indicates which set of security rules an assembly was authored against, and therefore which set of
- // rules the runtime should enforce on the assembly. For instance, an assembly marked with
- // [SecurityRules(SecurityRuleSet.Level1)] will follow the v2.0 transparency rules, where transparent code
- // can call a LinkDemand by converting it to a full demand, public critical methods are implicitly
- // treat as safe, and the remainder of the v2.0 rules apply.
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
- public sealed class SecurityRulesAttribute : Attribute
- {
- public SecurityRulesAttribute(SecurityRuleSet ruleSet)
- {
- RuleSet = ruleSet;
- }
-
- // Should fully trusted transparent code skip IL verification
- public bool SkipVerificationInFullTrust { get; set; }
-
- public SecurityRuleSet RuleSet { get; }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecuritySafeCriticalAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecuritySafeCriticalAttribute.cs
deleted file mode 100644
index dd51857d192..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecuritySafeCriticalAttribute.cs
+++ /dev/null
@@ -1,30 +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.
-
-namespace System.Security
-{
- // SecuritySafeCriticalAttribute:
- // Indicates that the code may contain violations to the security critical rules (e.g. transitions from
- // critical to non-public transparent, transparent to non-public critical, etc.), has been audited for
- // security concerns and is considered security clean. Also indicates that the code is considered SecurityCritical.
- // The effect of this attribute is as if the code was marked [SecurityCritical][SecurityTreatAsSafe].
- // At assembly-scope, all rule checks will be suppressed within the assembly and for calls made against the assembly.
- // At type-scope, all rule checks will be suppressed for members within the type and for calls made against the type.
- // At member level (e.g. field and method) the code will be treated as public - i.e. no rule checks for the members.
-
- [AttributeUsage(AttributeTargets.Class |
- AttributeTargets.Struct |
- AttributeTargets.Enum |
- AttributeTargets.Constructor |
- AttributeTargets.Method |
- AttributeTargets.Field |
- AttributeTargets.Interface |
- AttributeTargets.Delegate,
- AllowMultiple = false,
- Inherited = false)]
- public sealed class SecuritySafeCriticalAttribute : Attribute
- {
- public SecuritySafeCriticalAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecurityTransparentAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecurityTransparentAttribute.cs
deleted file mode 100644
index e9fd1bcb348..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecurityTransparentAttribute.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Security
-{
- // SecurityTransparentAttribute:
- // Indicates the assembly contains only transparent code.
- // Security critical actions will be restricted or converted into less critical actions. For example,
- // Assert will be restricted, SuppressUnmanagedCode, LinkDemand, unsafe, and unverifiable code will be converted
- // into Full-Demands.
-
- [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
- public sealed class SecurityTransparentAttribute : Attribute
- {
- public SecurityTransparentAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SecurityTreatAsSafeAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Security/SecurityTreatAsSafeAttribute.cs
deleted file mode 100644
index 450b7e46abe..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SecurityTreatAsSafeAttribute.cs
+++ /dev/null
@@ -1,31 +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.
-
-namespace System.Security
-{
- // SecurityTreatAsSafeAttribute:
- // Indicates that the code may contain violations to the security critical rules (e.g. transitions from
- // critical to non-public transparent, transparent to non-public critical, etc.), has been audited for
- // security concerns and is considered security clean.
- // At assembly-scope, all rule checks will be suppressed within the assembly and for calls made against the assembly.
- // At type-scope, all rule checks will be suppressed for members within the type and for calls made against the type.
- // At member level (e.g. field and method) the code will be treated as public - i.e. no rule checks for the members.
-
- [AttributeUsage(AttributeTargets.Assembly |
- AttributeTargets.Class |
- AttributeTargets.Struct |
- AttributeTargets.Enum |
- AttributeTargets.Constructor |
- AttributeTargets.Method |
- AttributeTargets.Field |
- AttributeTargets.Interface |
- AttributeTargets.Delegate,
- AllowMultiple = false,
- Inherited = false)]
- [Obsolete("SecurityTreatAsSafe is only used for .NET 2.0 transparency compatibility. Please use the SecuritySafeCriticalAttribute instead.")]
- public sealed class SecurityTreatAsSafeAttribute : Attribute
- {
- public SecurityTreatAsSafeAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/SuppressUnmanagedCodeSecurityAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Security/SuppressUnmanagedCodeSecurityAttribute.cs
deleted file mode 100644
index a45c212ca8f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/SuppressUnmanagedCodeSecurityAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Security
-{
- // SuppressUnmanagedCodeSecurityAttribute:
- // This attribute has no functional impact in CoreCLR.
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = true, Inherited = false)]
- public sealed class SuppressUnmanagedCodeSecurityAttribute : Attribute
- {
- public SuppressUnmanagedCodeSecurityAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/UnverifiableCodeAttribute.cs b/netcore/System.Private.CoreLib/shared/System/Security/UnverifiableCodeAttribute.cs
deleted file mode 100644
index 544b7c9d29e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/UnverifiableCodeAttribute.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Security
-{
- // UnverifiableCodeAttribute:
- // Indicates that the target module contains unverifiable code.
- [AttributeUsage(AttributeTargets.Module, AllowMultiple = true, Inherited = false)]
- public sealed class UnverifiableCodeAttribute : Attribute
- {
- public UnverifiableCodeAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Security/VerificationException.cs b/netcore/System.Private.CoreLib/shared/System/Security/VerificationException.cs
deleted file mode 100644
index 4cd9eeb2e86..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Security/VerificationException.cs
+++ /dev/null
@@ -1,36 +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 System.Runtime.Serialization;
-
-namespace System.Security
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class VerificationException : SystemException
- {
- public VerificationException()
- : base(SR.Verification_Exception)
- {
- HResult = HResults.COR_E_VERIFICATION;
- }
-
- public VerificationException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_VERIFICATION;
- }
-
- public VerificationException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_VERIFICATION;
- }
-
- protected VerificationException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/SerializableAttribute.cs b/netcore/System.Private.CoreLib/shared/System/SerializableAttribute.cs
deleted file mode 100644
index c2569313730..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/SerializableAttribute.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate, Inherited = false)]
- public sealed class SerializableAttribute : Attribute
- {
- public SerializableAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Single.cs b/netcore/System.Private.CoreLib/shared/System/Single.cs
deleted file mode 100644
index 157d57466e4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Single.cs
+++ /dev/null
@@ -1,440 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: A wrapper class for the primitive type float.
-**
-**
-===========================================================*/
-
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- [Serializable]
- [StructLayout(LayoutKind.Sequential)]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct Single : IComparable, IConvertible, IFormattable, IComparable<float>, IEquatable<float>, ISpanFormattable
- {
- private readonly float m_value; // Do not rename (binary serialization)
-
- //
- // Public constants
- //
- public const float MinValue = (float)-3.40282346638528859e+38;
- public const float Epsilon = (float)1.4e-45;
- public const float MaxValue = (float)3.40282346638528859e+38;
- public const float PositiveInfinity = (float)1.0 / (float)0.0;
- public const float NegativeInfinity = (float)-1.0 / (float)0.0;
- public const float NaN = (float)0.0 / (float)0.0;
-
- // We use this explicit definition to avoid the confusion between 0.0 and -0.0.
- internal const float NegativeZero = (float)-0.0;
-
- //
- // Constants for manipulating the private bit-representation
- //
-
- internal const uint SignMask = 0x8000_0000;
- internal const int SignShift = 31;
- internal const int ShiftedSignMask = (int)(SignMask >> SignShift);
-
- internal const uint ExponentMask = 0x7F80_0000;
- internal const int ExponentShift = 23;
- internal const int ShiftedExponentMask = (int)(ExponentMask >> ExponentShift);
-
- internal const uint SignificandMask = 0x007F_FFFF;
-
- internal const byte MinSign = 0;
- internal const byte MaxSign = 1;
-
- internal const byte MinExponent = 0x00;
- internal const byte MaxExponent = 0xFF;
-
- internal const uint MinSignificand = 0x0000_0000;
- internal const uint MaxSignificand = 0x007F_FFFF;
-
- /// <summary>Determines whether the specified value is finite (zero, subnormal, or normal).</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsFinite(float f)
- {
- int bits = BitConverter.SingleToInt32Bits(f);
- return (bits & 0x7FFFFFFF) < 0x7F800000;
- }
-
- /// <summary>Determines whether the specified value is infinite.</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe bool IsInfinity(float f)
- {
- int bits = BitConverter.SingleToInt32Bits(f);
- return (bits & 0x7FFFFFFF) == 0x7F800000;
- }
-
- /// <summary>Determines whether the specified value is NaN.</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe bool IsNaN(float f)
- {
- // A NaN will never equal itself so this is an
- // easy and efficient way to check for NaN.
-
- #pragma warning disable CS1718
- return f != f;
- #pragma warning restore CS1718
- }
-
- /// <summary>Determines whether the specified value is negative.</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe bool IsNegative(float f)
- {
- return BitConverter.SingleToInt32Bits(f) < 0;
- }
-
- /// <summary>Determines whether the specified value is negative infinity.</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe bool IsNegativeInfinity(float f)
- {
- return f == float.NegativeInfinity;
- }
-
- /// <summary>Determines whether the specified value is normal.</summary>
- [NonVersionable]
- // This is probably not worth inlining, it has branches and should be rarely called
- public static unsafe bool IsNormal(float f)
- {
- int bits = BitConverter.SingleToInt32Bits(f);
- bits &= 0x7FFFFFFF;
- return (bits < 0x7F800000) && (bits != 0) && ((bits & 0x7F800000) != 0);
- }
-
- /// <summary>Determines whether the specified value is positive infinity.</summary>
- [NonVersionable]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe bool IsPositiveInfinity(float f)
- {
- return f == float.PositiveInfinity;
- }
-
- /// <summary>Determines whether the specified value is subnormal.</summary>
- [NonVersionable]
- // This is probably not worth inlining, it has branches and should be rarely called
- public static unsafe bool IsSubnormal(float f)
- {
- int bits = BitConverter.SingleToInt32Bits(f);
- bits &= 0x7FFFFFFF;
- return (bits < 0x7F800000) && (bits != 0) && ((bits & 0x7F800000) == 0);
- }
-
- internal static int ExtractExponentFromBits(uint bits)
- {
- return (int)(bits >> ExponentShift) & ShiftedExponentMask;
- }
-
- internal static uint ExtractSignificandFromBits(uint bits)
- {
- return bits & SignificandMask;
- }
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type Single, this method throws an ArgumentException.
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
-
- if (value is float f)
- {
- if (m_value < f) return -1;
- if (m_value > f) return 1;
- if (m_value == f) return 0;
-
- // At least one of the values is NaN.
- if (IsNaN(m_value))
- return IsNaN(f) ? 0 : -1;
- else // f is NaN.
- return 1;
- }
-
- throw new ArgumentException(SR.Arg_MustBeSingle);
- }
-
- public int CompareTo(float value)
- {
- if (m_value < value) return -1;
- if (m_value > value) return 1;
- if (m_value == value) return 0;
-
- // At least one of the values is NaN.
- if (IsNaN(m_value))
- return IsNaN(value) ? 0 : -1;
- else // f is NaN.
- return 1;
- }
-
- [NonVersionable]
- public static bool operator ==(float left, float right) => left == right;
-
- [NonVersionable]
- public static bool operator !=(float left, float right) => left != right;
-
- [NonVersionable]
- public static bool operator <(float left, float right) => left < right;
-
- [NonVersionable]
- public static bool operator >(float left, float right) => left > right;
-
- [NonVersionable]
- public static bool operator <=(float left, float right) => left <= right;
-
- [NonVersionable]
- public static bool operator >=(float left, float right) => left >= right;
-
- public override bool Equals(object? obj)
- {
- if (!(obj is float))
- {
- return false;
- }
- float temp = ((float)obj).m_value;
- if (temp == m_value)
- {
- return true;
- }
-
- return IsNaN(temp) && IsNaN(m_value);
- }
-
- public bool Equals(float obj)
- {
- if (obj == m_value)
- {
- return true;
- }
-
- return IsNaN(obj) && IsNaN(m_value);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetHashCode()
- {
- int bits = Unsafe.As<float, int>(ref Unsafe.AsRef(in m_value));
-
- // Optimized check for IsNan() || IsZero()
- if (((bits - 1) & 0x7FFFFFFF) >= 0x7F800000)
- {
- // Ensure that all NaNs and both zeros have the same hash code
- bits &= 0x7F800000;
- }
-
- return bits;
- }
-
- public override string ToString()
- {
- return Number.FormatSingle(m_value, null, NumberFormatInfo.CurrentInfo);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return Number.FormatSingle(m_value, null, NumberFormatInfo.GetInstance(provider));
- }
-
- public string ToString(string? format)
- {
- return Number.FormatSingle(m_value, format, NumberFormatInfo.CurrentInfo);
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- return Number.FormatSingle(m_value, format, NumberFormatInfo.GetInstance(provider));
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
- {
- return Number.TryFormatSingle(m_value, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten);
- }
-
- // Parses a float from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- //
- // This method will not throw an OverflowException, but will return
- // PositiveInfinity or NegativeInfinity for a number that is too
- // large or too small.
- //
- public static float Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseSingle(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo);
- }
-
- public static float Parse(string s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseSingle(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- public static float Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseSingle(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.GetInstance(provider));
- }
-
- public static float Parse(string s, NumberStyles style, IFormatProvider? provider)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseSingle(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- public static float Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Float | NumberStyles.AllowThousands, IFormatProvider? provider = null)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- return Number.ParseSingle(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- public static bool TryParse(string? s, out float result)
- {
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, out float result)
- {
- return TryParse(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, out result);
- }
-
- public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out float result)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
-
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out float result)
- {
- NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
- return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- private static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info, out float result)
- {
- return Number.TryParseSingle(s, style, info, out result);
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.Single;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Single", "Char"));
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return m_value;
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Single", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Span.cs b/netcore/System.Private.CoreLib/shared/System/Span.cs
deleted file mode 100644
index 149107b7690..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Span.cs
+++ /dev/null
@@ -1,479 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.Versioning;
-using System.Text;
-using EditorBrowsableAttribute = System.ComponentModel.EditorBrowsableAttribute;
-using EditorBrowsableState = System.ComponentModel.EditorBrowsableState;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable 0809 //warning CS0809: Obsolete member 'Span<T>.Equals(object)' overrides non-obsolete member 'object.Equals(object)'
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- /// <summary>
- /// Span represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed
- /// or native memory, or to memory allocated on the stack. It is type- and memory-safe.
- /// </summary>
- [DebuggerTypeProxy(typeof(SpanDebugView<>))]
- [DebuggerDisplay("{ToString(),raw}")]
- [NonVersionable]
- public readonly ref struct Span<T>
- {
- /// <summary>A byref or a native ptr.</summary>
- internal readonly ByReference<T> _pointer;
- /// <summary>The number of elements this Span contains.</summary>
- private readonly int _length;
-
- /// <summary>
- /// Creates a new span over the entirety of the target array.
- /// </summary>
- /// <param name="array">The target array.</param>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Span(T[]? array)
- {
- if (array == null)
- {
- this = default;
- return; // returns default
- }
- if (default(T)! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- ThrowHelper.ThrowArrayTypeMismatchException();
-
- _pointer = new ByReference<T>(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()));
- _length = array.Length;
- }
-
- /// <summary>
- /// Creates a new span over the portion of the target array beginning
- /// at 'start' index and ending at 'end' index (exclusive).
- /// </summary>
- /// <param name="array">The target array.</param>
- /// <param name="start">The index at which to begin the span.</param>
- /// <param name="length">The number of items in the span.</param>
- /// <remarks>Returns default when <paramref name="array"/> is null.</remarks>
- /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Span(T[]? array, int start, int length)
- {
- if (array == null)
- {
- if (start != 0 || length != 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
- this = default;
- return; // returns default
- }
- if (default(T)! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- ThrowHelper.ThrowArrayTypeMismatchException();
-#if BIT64
- // See comment in Span<T>.Slice for how this works.
- if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)array.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#else
- if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#endif
-
- _pointer = new ByReference<T>(ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), start));
- _length = length;
- }
-
- /// <summary>
- /// Creates a new span over the target unmanaged buffer. Clearly this
- /// is quite dangerous, because we are creating arbitrarily typed T's
- /// out of a void*-typed block of memory. And the length is not checked.
- /// But if this creation is correct, then all subsequent uses are correct.
- /// </summary>
- /// <param name="pointer">An unmanaged pointer to memory.</param>
- /// <param name="length">The number of <typeparamref name="T"/> elements the memory contains.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when <typeparamref name="T"/> is reference type or contains pointers and hence cannot be stored in unmanaged memory.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="length"/> is negative.
- /// </exception>
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public unsafe Span(void* pointer, int length)
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
- if (length < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- _pointer = new ByReference<T>(ref Unsafe.As<byte, T>(ref *(byte*)pointer));
- _length = length;
- }
-
- // Constructor for internal use only.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal Span(ref T ptr, int length)
- {
- Debug.Assert(length >= 0);
-
- _pointer = new ByReference<T>(ref ptr);
- _length = length;
- }
-
- /// <summary>
- /// Returns a reference to specified element of the Span.
- /// </summary>
- /// <param name="index"></param>
- /// <returns></returns>
- /// <exception cref="System.IndexOutOfRangeException">
- /// Thrown when index less than 0 or index greater than or equal to Length
- /// </exception>
- public ref T this[int index]
- {
- [Intrinsic]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- [NonVersionable]
- get
- {
- if ((uint)index >= (uint)_length)
- ThrowHelper.ThrowIndexOutOfRangeException();
- return ref Unsafe.Add(ref _pointer.Value, index);
- }
- }
-
- /// <summary>
- /// The number of items in the span.
- /// </summary>
- public int Length
- {
- [NonVersionable]
- get => _length;
- }
-
- /// <summary>
- /// Returns true if Length is 0.
- /// </summary>
- public bool IsEmpty
- {
- [NonVersionable]
- get => 0 >= (uint)_length; // Workaround for https://github.com/dotnet/coreclr/issues/19620
- }
-
- /// <summary>
- /// Returns false if left and right point at the same memory and have the same length. Note that
- /// this does *not* check to see if the *contents* are equal.
- /// </summary>
- public static bool operator !=(Span<T> left, Span<T> right) => !(left == right);
-
- /// <summary>
- /// This method is not supported as spans cannot be boxed. To compare two spans, use operator==.
- /// <exception cref="System.NotSupportedException">
- /// Always thrown by this method.
- /// </exception>
- /// </summary>
- [Obsolete("Equals() on Span will always throw an exception. Use == instead.")]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override bool Equals(object? obj) =>
- throw new NotSupportedException(SR.NotSupported_CannotCallEqualsOnSpan);
-
- /// <summary>
- /// This method is not supported as spans cannot be boxed.
- /// <exception cref="System.NotSupportedException">
- /// Always thrown by this method.
- /// </exception>
- /// </summary>
- [Obsolete("GetHashCode() on Span will always throw an exception.")]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public override int GetHashCode() =>
- throw new NotSupportedException(SR.NotSupported_CannotCallGetHashCodeOnSpan);
-
- /// <summary>
- /// Defines an implicit conversion of an array to a <see cref="Span{T}"/>
- /// </summary>
- public static implicit operator Span<T>(T[]? array) => new Span<T>(array);
-
- /// <summary>
- /// Defines an implicit conversion of a <see cref="ArraySegment{T}"/> to a <see cref="Span{T}"/>
- /// </summary>
- public static implicit operator Span<T>(ArraySegment<T> segment) =>
- new Span<T>(segment.Array, segment.Offset, segment.Count);
-
- /// <summary>
- /// Returns an empty <see cref="Span{T}"/>
- /// </summary>
- public static Span<T> Empty => default;
-
- /// <summary>Gets an enumerator for this span.</summary>
- public Enumerator GetEnumerator() => new Enumerator(this);
-
- /// <summary>Enumerates the elements of a <see cref="Span{T}"/>.</summary>
- public ref struct Enumerator
- {
- /// <summary>The span being enumerated.</summary>
- private readonly Span<T> _span;
- /// <summary>The next index to yield.</summary>
- private int _index;
-
- /// <summary>Initialize the enumerator.</summary>
- /// <param name="span">The span to enumerate.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal Enumerator(Span<T> span)
- {
- _span = span;
- _index = -1;
- }
-
- /// <summary>Advances the enumerator to the next element of the span.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool MoveNext()
- {
- int index = _index + 1;
- if (index < _span.Length)
- {
- _index = index;
- return true;
- }
-
- return false;
- }
-
- /// <summary>Gets the element at the current position of the enumerator.</summary>
- public ref T Current
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => ref _span[_index];
- }
- }
-
- /// <summary>
- /// Returns a reference to the 0th element of the Span. If the Span is empty, returns null reference.
- /// It can be used for pinning and is required to support the use of span within a fixed statement.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public ref T GetPinnableReference()
- {
- // Ensure that the native code has just one forward branch that is predicted-not-taken.
- ref T ret = ref Unsafe.NullRef<T>();
- if (_length != 0) ret = ref _pointer.Value;
- return ref ret;
- }
-
- /// <summary>
- /// Clears the contents of this span.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Clear()
- {
- if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
- {
- SpanHelpers.ClearWithReferences(ref Unsafe.As<T, IntPtr>(ref _pointer.Value), (nuint)_length * (nuint)(Unsafe.SizeOf<T>() / sizeof(nuint)));
- }
- else
- {
- SpanHelpers.ClearWithoutReferences(ref Unsafe.As<T, byte>(ref _pointer.Value), (nuint)_length * (nuint)Unsafe.SizeOf<T>());
- }
- }
-
- /// <summary>
- /// Fills the contents of this span with the given value.
- /// </summary>
- public void Fill(T value)
- {
- if (Unsafe.SizeOf<T>() == 1)
- {
- uint length = (uint)_length;
- if (length == 0)
- return;
-
- T tmp = value; // Avoid taking address of the "value" argument. It would regress performance of the loop below.
- Unsafe.InitBlockUnaligned(ref Unsafe.As<T, byte>(ref _pointer.Value), Unsafe.As<T, byte>(ref tmp), length);
- }
- else
- {
- // Do all math as nuint to avoid unnecessary 64->32->64 bit integer truncations
- nuint length = (uint)_length;
- if (length == 0)
- return;
-
- ref T r = ref _pointer.Value;
-
- // TODO: Create block fill for value types of power of two sizes e.g. 2,4,8,16
-
- nuint elementSize = (uint)Unsafe.SizeOf<T>();
- nuint i = 0;
- for (; i < (length & ~(nuint)7); i += 8)
- {
- Unsafe.AddByteOffset<T>(ref r, (i + 0) * elementSize) = value;
- Unsafe.AddByteOffset<T>(ref r, (i + 1) * elementSize) = value;
- Unsafe.AddByteOffset<T>(ref r, (i + 2) * elementSize) = value;
- Unsafe.AddByteOffset<T>(ref r, (i + 3) * elementSize) = value;
- Unsafe.AddByteOffset<T>(ref r, (i + 4) * elementSize) = value;
- Unsafe.AddByteOffset<T>(ref r, (i + 5) * elementSize) = value;
- Unsafe.AddByteOffset<T>(ref r, (i + 6) * elementSize) = value;
- Unsafe.AddByteOffset<T>(ref r, (i + 7) * elementSize) = value;
- }
- if (i < (length & ~(nuint)3))
- {
- Unsafe.AddByteOffset<T>(ref r, (i + 0) * elementSize) = value;
- Unsafe.AddByteOffset<T>(ref r, (i + 1) * elementSize) = value;
- Unsafe.AddByteOffset<T>(ref r, (i + 2) * elementSize) = value;
- Unsafe.AddByteOffset<T>(ref r, (i + 3) * elementSize) = value;
- i += 4;
- }
- for (; i < length; i++)
- {
- Unsafe.AddByteOffset<T>(ref r, i * elementSize) = value;
- }
- }
- }
-
- /// <summary>
- /// Copies the contents of this span into destination span. If the source
- /// and destinations overlap, this method behaves as if the original values in
- /// a temporary location before the destination is overwritten.
- /// </summary>
- /// <param name="destination">The span to copy items into.</param>
- /// <exception cref="System.ArgumentException">
- /// Thrown when the destination Span is shorter than the source Span.
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void CopyTo(Span<T> destination)
- {
- // Using "if (!TryCopyTo(...))" results in two branches: one for the length
- // check, and one for the result of TryCopyTo. Since these checks are equivalent,
- // we can optimize by performing the check once ourselves then calling Memmove directly.
-
- if ((uint)_length <= (uint)destination.Length)
- {
- Buffer.Memmove(ref destination._pointer.Value, ref _pointer.Value, (nuint)_length);
- }
- else
- {
- ThrowHelper.ThrowArgumentException_DestinationTooShort();
- }
- }
-
- /// <summary>
- /// Copies the contents of this span into destination span. If the source
- /// and destinations overlap, this method behaves as if the original values in
- /// a temporary location before the destination is overwritten.
- /// </summary>
- /// <param name="destination">The span to copy items into.</param>
- /// <returns>If the destination span is shorter than the source span, this method
- /// return false and no data is written to the destination.</returns>
- public bool TryCopyTo(Span<T> destination)
- {
- bool retVal = false;
- if ((uint)_length <= (uint)destination.Length)
- {
- Buffer.Memmove(ref destination._pointer.Value, ref _pointer.Value, (nuint)_length);
- retVal = true;
- }
- return retVal;
- }
-
- /// <summary>
- /// Returns true if left and right point at the same memory and have the same length. Note that
- /// this does *not* check to see if the *contents* are equal.
- /// </summary>
- public static bool operator ==(Span<T> left, Span<T> right) =>
- left._length == right._length &&
- Unsafe.AreSame<T>(ref left._pointer.Value, ref right._pointer.Value);
-
- /// <summary>
- /// Defines an implicit conversion of a <see cref="Span{T}"/> to a <see cref="ReadOnlySpan{T}"/>
- /// </summary>
- public static implicit operator ReadOnlySpan<T>(Span<T> span) =>
- new ReadOnlySpan<T>(ref span._pointer.Value, span._length);
-
- /// <summary>
- /// For <see cref="Span{Char}"/>, returns a new instance of string that represents the characters pointed to by the span.
- /// Otherwise, returns a <see cref="string"/> with the name of the type and the number of elements.
- /// </summary>
- public override string ToString()
- {
- if (typeof(T) == typeof(char))
- {
- return new string(new ReadOnlySpan<char>(ref Unsafe.As<T, char>(ref _pointer.Value), _length));
- }
-#if FEATURE_UTF8STRING
- else if (typeof(T) == typeof(Char8))
- {
- // TODO_UTF8STRING: Call into optimized transcoding routine when it's available.
- return Encoding.UTF8.GetString(new ReadOnlySpan<byte>(ref Unsafe.As<T, byte>(ref _pointer.Value), _length));
- }
-#endif // FEATURE_UTF8STRING
- return string.Format("System.Span<{0}>[{1}]", typeof(T).Name, _length);
- }
-
- /// <summary>
- /// Forms a slice out of the given span, beginning at 'start'.
- /// </summary>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> index is not in range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Span<T> Slice(int start)
- {
- if ((uint)start > (uint)_length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- return new Span<T>(ref Unsafe.Add(ref _pointer.Value, start), _length - start);
- }
-
- /// <summary>
- /// Forms a slice out of the given span, beginning at 'start', of given length
- /// </summary>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <param name="length">The desired length for the slice (exclusive).</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in range (&lt;0 or &gt;Length).
- /// </exception>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Span<T> Slice(int start, int length)
- {
-#if BIT64
- // Since start and length are both 32-bit, their sum can be computed across a 64-bit domain
- // without loss of fidelity. The cast to uint before the cast to ulong ensures that the
- // extension from 32- to 64-bit is zero-extending rather than sign-extending. The end result
- // of this is that if either input is negative or if the input sum overflows past Int32.MaxValue,
- // that information is captured correctly in the comparison against the backing _length field.
- // We don't use this same mechanism in a 32-bit process due to the overhead of 64-bit arithmetic.
- if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)_length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#else
- if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException();
-#endif
-
- return new Span<T>(ref Unsafe.Add(ref _pointer.Value, start), length);
- }
-
- /// <summary>
- /// Copies the contents of this span into a new array. This heap
- /// allocates, so should generally be avoided, however it is sometimes
- /// necessary to bridge the gap with APIs written in terms of arrays.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public T[] ToArray()
- {
- if (_length == 0)
- return Array.Empty<T>();
-
- var destination = new T[_length];
- Buffer.Memmove(ref Unsafe.As<byte, T>(ref destination.GetRawSzArrayData()), ref _pointer.Value, (nuint)_length);
- return destination;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/SpanDebugView.cs b/netcore/System.Private.CoreLib/shared/System/SpanDebugView.cs
deleted file mode 100644
index f79c67306ce..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/SpanDebugView.cs
+++ /dev/null
@@ -1,26 +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 System.Diagnostics;
-
-namespace System
-{
- internal sealed class SpanDebugView<T>
- {
- private readonly T[] _array;
-
- public SpanDebugView(Span<T> span)
- {
- _array = span.ToArray();
- }
-
- public SpanDebugView(ReadOnlySpan<T> span)
- {
- _array = span.ToArray();
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public T[] Items => _array;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/SpanHelpers.BinarySearch.cs b/netcore/System.Private.CoreLib/shared/System/SpanHelpers.BinarySearch.cs
deleted file mode 100644
index 385992fe45a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/SpanHelpers.BinarySearch.cs
+++ /dev/null
@@ -1,81 +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 System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- internal static partial class SpanHelpers
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int BinarySearch<T, TComparable>(
- this ReadOnlySpan<T> span, TComparable comparable)
- where TComparable : IComparable<T>
- {
- if (comparable == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparable);
-
- return BinarySearch(ref MemoryMarshal.GetReference(span), span.Length, comparable);
- }
-
- public static int BinarySearch<T, TComparable>(
- ref T spanStart, int length, TComparable comparable)
- where TComparable : IComparable<T>
- {
- int lo = 0;
- int hi = length - 1;
- // If length == 0, hi == -1, and loop will not be entered
- while (lo <= hi)
- {
- // PERF: `lo` or `hi` will never be negative inside the loop,
- // so computing median using uints is safe since we know
- // `length <= int.MaxValue`, and indices are >= 0
- // and thus cannot overflow an uint.
- // Saves one subtraction per loop compared to
- // `int i = lo + ((hi - lo) >> 1);`
- int i = (int)(((uint)hi + (uint)lo) >> 1);
-
- int c = comparable.CompareTo(Unsafe.Add(ref spanStart, i));
- if (c == 0)
- {
- return i;
- }
- else if (c > 0)
- {
- lo = i + 1;
- }
- else
- {
- hi = i - 1;
- }
- }
- // If none found, then a negative number that is the bitwise complement
- // of the index of the next element that is larger than or, if there is
- // no larger element, the bitwise complement of `length`, which
- // is `lo` at this point.
- return ~lo;
- }
-
- // Helper to allow sharing all code via IComparable<T> inlineable
- internal readonly struct ComparerComparable<T, TComparer> : IComparable<T>
- where TComparer : IComparer<T>
- {
- private readonly T _value;
- private readonly TComparer _comparer;
-
- public ComparerComparable(T value, TComparer comparer)
- {
- _value = value;
- _comparer = comparer;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public int CompareTo(T other) => _comparer.Compare(_value, other);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/SpanHelpers.Byte.cs b/netcore/System.Private.CoreLib/shared/System/SpanHelpers.Byte.cs
deleted file mode 100644
index db1490c214b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/SpanHelpers.Byte.cs
+++ /dev/null
@@ -1,1663 +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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif // BIT64
-
-namespace System
-{
- internal static partial class SpanHelpers // .Byte
- {
- public static int IndexOf(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength)
- {
- Debug.Assert(searchSpaceLength >= 0);
- Debug.Assert(valueLength >= 0);
-
- if (valueLength == 0)
- return 0; // A zero-length sequence is always treated as "found" at the start of the search space.
-
- byte valueHead = value;
- ref byte valueTail = ref Unsafe.Add(ref value, 1);
- int valueTailLength = valueLength - 1;
- int remainingSearchSpaceLength = searchSpaceLength - valueTailLength;
-
- int offset = 0;
- while (remainingSearchSpaceLength > 0)
- {
- // Do a quick search for the first element of "value".
- int relativeIndex = IndexOf(ref Unsafe.Add(ref searchSpace, offset), valueHead, remainingSearchSpaceLength);
- if (relativeIndex == -1)
- break;
-
- remainingSearchSpaceLength -= relativeIndex;
- offset += relativeIndex;
-
- if (remainingSearchSpaceLength <= 0)
- break; // The unsearched portion is now shorter than the sequence we're looking for. So it can't be there.
-
- // Found the first element of "value". See if the tail matches.
- if (SequenceEqual(ref Unsafe.Add(ref searchSpace, offset + 1), ref valueTail, valueTailLength))
- return offset; // The tail matched. Return a successful find.
-
- remainingSearchSpaceLength--;
- offset++;
- }
- return -1;
- }
-
- public static int IndexOfAny(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength)
- {
- Debug.Assert(searchSpaceLength >= 0);
- Debug.Assert(valueLength >= 0);
-
- if (valueLength == 0)
- return -1; // A zero-length set of values is always treated as "not found".
-
- int offset = -1;
- for (int i = 0; i < valueLength; i++)
- {
- int tempIndex = IndexOf(ref searchSpace, Unsafe.Add(ref value, i), searchSpaceLength);
- if ((uint)tempIndex < (uint)offset)
- {
- offset = tempIndex;
- // Reduce space for search, cause we don't care if we find the search value after the index of a previously found value
- searchSpaceLength = tempIndex;
-
- if (offset == 0)
- break;
- }
- }
- return offset;
- }
-
- public static int LastIndexOfAny(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength)
- {
- Debug.Assert(searchSpaceLength >= 0);
- Debug.Assert(valueLength >= 0);
-
- if (valueLength == 0)
- return -1; // A zero-length set of values is always treated as "not found".
-
- int offset = -1;
- for (int i = 0; i < valueLength; i++)
- {
- int tempIndex = LastIndexOf(ref searchSpace, Unsafe.Add(ref value, i), searchSpaceLength);
- if (tempIndex > offset)
- offset = tempIndex;
- }
- return offset;
- }
-
- // Adapted from IndexOf(...)
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe bool Contains(ref byte searchSpace, byte value, int length)
- {
- Debug.Assert(length >= 0);
-
- uint uValue = value; // Use uint for comparisons to avoid unnecessary 8->32 extensions
- IntPtr offset = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
- IntPtr lengthToExamine = (IntPtr)length;
-
- if (Vector.IsHardwareAccelerated && length >= Vector<byte>.Count * 2)
- {
- lengthToExamine = UnalignedCountVector(ref searchSpace);
- }
-
- SequentialScan:
- while ((byte*)lengthToExamine >= (byte*)8)
- {
- lengthToExamine -= 8;
-
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 0) ||
- uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 1) ||
- uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 2) ||
- uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 3) ||
- uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 4) ||
- uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 5) ||
- uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 6) ||
- uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 7))
- {
- goto Found;
- }
-
- offset += 8;
- }
-
- if ((byte*)lengthToExamine >= (byte*)4)
- {
- lengthToExamine -= 4;
-
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 0) ||
- uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 1) ||
- uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 2) ||
- uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 3))
- {
- goto Found;
- }
-
- offset += 4;
- }
-
- while ((byte*)lengthToExamine > (byte*)0)
- {
- lengthToExamine -= 1;
-
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset))
- goto Found;
-
- offset += 1;
- }
-
- if (Vector.IsHardwareAccelerated && ((int)(byte*)offset < length))
- {
- lengthToExamine = (IntPtr)((length - (int)(byte*)offset) & ~(Vector<byte>.Count - 1));
-
- Vector<byte> values = new Vector<byte>(value);
-
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- var matches = Vector.Equals(values, LoadVector(ref searchSpace, offset));
- if (Vector<byte>.Zero.Equals(matches))
- {
- offset += Vector<byte>.Count;
- continue;
- }
-
- goto Found;
- }
-
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = (IntPtr)(length - (int)(byte*)offset);
- goto SequentialScan;
- }
- }
-
- return false;
-
- Found:
- return true;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int IndexOf(ref byte searchSpace, byte value, int length)
- {
- Debug.Assert(length >= 0);
-
- uint uValue = value; // Use uint for comparisons to avoid unnecessary 8->32 extensions
- IntPtr offset = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
- IntPtr lengthToExamine = (IntPtr)length;
-
- if (Avx2.IsSupported || Sse2.IsSupported)
- {
- // Avx2 branch also operates on Sse2 sizes, so check is combined.
- if (length >= Vector128<byte>.Count * 2)
- {
- lengthToExamine = UnalignedCountVector128(ref searchSpace);
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- if (length >= Vector<byte>.Count * 2)
- {
- lengthToExamine = UnalignedCountVector(ref searchSpace);
- }
- }
- SequentialScan:
- while ((byte*)lengthToExamine >= (byte*)8)
- {
- lengthToExamine -= 8;
-
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset))
- goto Found;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 1))
- goto Found1;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 2))
- goto Found2;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 3))
- goto Found3;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 4))
- goto Found4;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 5))
- goto Found5;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 6))
- goto Found6;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 7))
- goto Found7;
-
- offset += 8;
- }
-
- if ((byte*)lengthToExamine >= (byte*)4)
- {
- lengthToExamine -= 4;
-
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset))
- goto Found;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 1))
- goto Found1;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 2))
- goto Found2;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 3))
- goto Found3;
-
- offset += 4;
- }
-
- while ((byte*)lengthToExamine > (byte*)0)
- {
- lengthToExamine -= 1;
-
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset))
- goto Found;
-
- offset += 1;
- }
-
- // We get past SequentialScan only if IsHardwareAccelerated or intrinsic .IsSupported is true; and remain length is greater than Vector length.
- // However, we still have the redundant check to allow the JIT to see that the code is unreachable and eliminate it when the platform does not
- // have hardware accelerated. After processing Vector lengths we return to SequentialScan to finish any remaining.
- if (Avx2.IsSupported)
- {
- if ((int)(byte*)offset < length)
- {
- if ((((nuint)Unsafe.AsPointer(ref searchSpace) + (nuint)offset) & (nuint)(Vector256<byte>.Count - 1)) != 0)
- {
- // Not currently aligned to Vector256 (is aligned to Vector128); this can cause a problem for searches
- // with no upper bound e.g. String.strlen.
- // Start with a check on Vector128 to align to Vector256, before moving to processing Vector256.
- // This ensures we do not fault across memory pages while searching for an end of string.
- Vector128<byte> values = Vector128.Create(value);
- Vector128<byte> search = LoadVector128(ref searchSpace, offset);
-
- // Same method as below
- int matches = Sse2.MoveMask(Sse2.CompareEqual(values, search));
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector128<byte>.Count;
- }
- else
- {
- // Find bitflag offset of first match and add to current offset
- return ((int)(byte*)offset) + BitOperations.TrailingZeroCount(matches);
- }
- }
-
- lengthToExamine = GetByteVector256SpanLength(offset, length);
- if ((byte*)lengthToExamine > (byte*)offset)
- {
- Vector256<byte> values = Vector256.Create(value);
- do
- {
- Vector256<byte> search = LoadVector256(ref searchSpace, offset);
- int matches = Avx2.MoveMask(Avx2.CompareEqual(values, search));
- // Note that MoveMask has converted the equal vector elements into a set of bit flags,
- // So the bit position in 'matches' corresponds to the element offset.
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector256<byte>.Count;
- continue;
- }
-
- // Find bitflag offset of first match and add to current offset
- return ((int)(byte*)offset) + BitOperations.TrailingZeroCount(matches);
- } while ((byte*)lengthToExamine > (byte*)offset);
- }
-
- lengthToExamine = GetByteVector128SpanLength(offset, length);
- if ((byte*)lengthToExamine > (byte*)offset)
- {
- Vector128<byte> values = Vector128.Create(value);
- Vector128<byte> search = LoadVector128(ref searchSpace, offset);
-
- // Same method as above
- int matches = Sse2.MoveMask(Sse2.CompareEqual(values, search));
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector128<byte>.Count;
- }
- else
- {
- // Find bitflag offset of first match and add to current offset
- return ((int)(byte*)offset) + BitOperations.TrailingZeroCount(matches);
- }
- }
-
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = (IntPtr)(length - (int)(byte*)offset);
- goto SequentialScan;
- }
- }
- }
- else if (Sse2.IsSupported)
- {
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = GetByteVector128SpanLength(offset, length);
-
- Vector128<byte> values = Vector128.Create(value);
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- Vector128<byte> search = LoadVector128(ref searchSpace, offset);
-
- // Same method as above
- int matches = Sse2.MoveMask(Sse2.CompareEqual(values, search));
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector128<byte>.Count;
- continue;
- }
-
- // Find bitflag offset of first match and add to current offset
- return ((int)(byte*)offset) + BitOperations.TrailingZeroCount(matches);
- }
-
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = (IntPtr)(length - (int)(byte*)offset);
- goto SequentialScan;
- }
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = GetByteVectorSpanLength(offset, length);
-
- Vector<byte> values = new Vector<byte>(value);
-
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- var matches = Vector.Equals(values, LoadVector(ref searchSpace, offset));
- if (Vector<byte>.Zero.Equals(matches))
- {
- offset += Vector<byte>.Count;
- continue;
- }
-
- // Find offset of first match and add to current offset
- return (int)(byte*)offset + LocateFirstFoundByte(matches);
- }
-
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = (IntPtr)(length - (int)(byte*)offset);
- goto SequentialScan;
- }
- }
- }
- return -1;
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return (int)(byte*)offset;
- Found1:
- return (int)(byte*)(offset + 1);
- Found2:
- return (int)(byte*)(offset + 2);
- Found3:
- return (int)(byte*)(offset + 3);
- Found4:
- return (int)(byte*)(offset + 4);
- Found5:
- return (int)(byte*)(offset + 5);
- Found6:
- return (int)(byte*)(offset + 6);
- Found7:
- return (int)(byte*)(offset + 7);
- }
-
- public static int LastIndexOf(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength)
- {
- Debug.Assert(searchSpaceLength >= 0);
- Debug.Assert(valueLength >= 0);
-
- if (valueLength == 0)
- return 0; // A zero-length sequence is always treated as "found" at the start of the search space.
-
- byte valueHead = value;
- ref byte valueTail = ref Unsafe.Add(ref value, 1);
- int valueTailLength = valueLength - 1;
-
- int offset = 0;
- while (true)
- {
- Debug.Assert(0 <= offset && offset <= searchSpaceLength); // Ensures no deceptive underflows in the computation of "remainingSearchSpaceLength".
- int remainingSearchSpaceLength = searchSpaceLength - offset - valueTailLength;
- if (remainingSearchSpaceLength <= 0)
- break; // The unsearched portion is now shorter than the sequence we're looking for. So it can't be there.
-
- // Do a quick search for the first element of "value".
- int relativeIndex = LastIndexOf(ref searchSpace, valueHead, remainingSearchSpaceLength);
- if (relativeIndex == -1)
- break;
-
- // Found the first element of "value". See if the tail matches.
- if (SequenceEqual(ref Unsafe.Add(ref searchSpace, relativeIndex + 1), ref valueTail, valueTailLength))
- return relativeIndex; // The tail matched. Return a successful find.
-
- offset += remainingSearchSpaceLength - relativeIndex;
- }
- return -1;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int LastIndexOf(ref byte searchSpace, byte value, int length)
- {
- Debug.Assert(length >= 0);
-
- uint uValue = value; // Use uint for comparisons to avoid unnecessary 8->32 extensions
- IntPtr offset = (IntPtr)length; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
- IntPtr lengthToExamine = (IntPtr)length;
-
- if (Vector.IsHardwareAccelerated && length >= Vector<byte>.Count * 2)
- {
- lengthToExamine = UnalignedCountVectorFromEnd(ref searchSpace, length);
- }
- SequentialScan:
- while ((byte*)lengthToExamine >= (byte*)8)
- {
- lengthToExamine -= 8;
- offset -= 8;
-
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 7))
- goto Found7;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 6))
- goto Found6;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 5))
- goto Found5;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 4))
- goto Found4;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 3))
- goto Found3;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 2))
- goto Found2;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 1))
- goto Found1;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset))
- goto Found;
- }
-
- if ((byte*)lengthToExamine >= (byte*)4)
- {
- lengthToExamine -= 4;
- offset -= 4;
-
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 3))
- goto Found3;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 2))
- goto Found2;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset + 1))
- goto Found1;
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset))
- goto Found;
- }
-
- while ((byte*)lengthToExamine > (byte*)0)
- {
- lengthToExamine -= 1;
- offset -= 1;
-
- if (uValue == Unsafe.AddByteOffset(ref searchSpace, offset))
- goto Found;
- }
-
- if (Vector.IsHardwareAccelerated && ((byte*)offset > (byte*)0))
- {
- lengthToExamine = (IntPtr)((int)(byte*)offset & ~(Vector<byte>.Count - 1));
-
- Vector<byte> values = new Vector<byte>(value);
-
- while ((byte*)lengthToExamine > (byte*)(Vector<byte>.Count - 1))
- {
- var matches = Vector.Equals(values, LoadVector(ref searchSpace, offset - Vector<byte>.Count));
- if (Vector<byte>.Zero.Equals(matches))
- {
- offset -= Vector<byte>.Count;
- lengthToExamine -= Vector<byte>.Count;
- continue;
- }
-
- // Find offset of first match and add to current offset
- return (int)(offset) - Vector<byte>.Count + LocateLastFoundByte(matches);
- }
- if ((byte*)offset > (byte*)0)
- {
- lengthToExamine = offset;
- goto SequentialScan;
- }
- }
- return -1;
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return (int)(byte*)offset;
- Found1:
- return (int)(byte*)(offset + 1);
- Found2:
- return (int)(byte*)(offset + 2);
- Found3:
- return (int)(byte*)(offset + 3);
- Found4:
- return (int)(byte*)(offset + 4);
- Found5:
- return (int)(byte*)(offset + 5);
- Found6:
- return (int)(byte*)(offset + 6);
- Found7:
- return (int)(byte*)(offset + 7);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int IndexOfAny(ref byte searchSpace, byte value0, byte value1, int length)
- {
- Debug.Assert(length >= 0);
-
- uint uValue0 = value0; // Use uint for comparisons to avoid unnecessary 8->32 extensions
- uint uValue1 = value1; // Use uint for comparisons to avoid unnecessary 8->32 extensions
- IntPtr offset = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
- IntPtr lengthToExamine = (IntPtr)length;
-
- if (Avx2.IsSupported || Sse2.IsSupported)
- {
- // Avx2 branch also operates on Sse2 sizes, so check is combined.
- if (length >= Vector128<byte>.Count * 2)
- {
- lengthToExamine = UnalignedCountVector128(ref searchSpace);
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- if (length >= Vector<byte>.Count * 2)
- {
- lengthToExamine = UnalignedCountVector(ref searchSpace);
- }
- }
- SequentialScan:
- uint lookUp;
- while ((byte*)lengthToExamine >= (byte*)8)
- {
- lengthToExamine -= 8;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 1);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found1;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 2);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found2;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 3);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found3;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 4);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found4;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 5);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found5;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 6);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found6;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 7);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found7;
-
- offset += 8;
- }
-
- if ((byte*)lengthToExamine >= (byte*)4)
- {
- lengthToExamine -= 4;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 1);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found1;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 2);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found2;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 3);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found3;
-
- offset += 4;
- }
-
- while ((byte*)lengthToExamine > (byte*)0)
- {
- lengthToExamine -= 1;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found;
-
- offset += 1;
- }
-
- // We get past SequentialScan only if IsHardwareAccelerated or intrinsic .IsSupported is true. However, we still have the redundant check to allow
- // the JIT to see that the code is unreachable and eliminate it when the platform does not have hardware accelerated.
- if (Avx2.IsSupported)
- {
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = GetByteVector256SpanLength(offset, length);
- if ((byte*)lengthToExamine > (byte*)offset)
- {
- Vector256<byte> values0 = Vector256.Create(value0);
- Vector256<byte> values1 = Vector256.Create(value1);
- do
- {
- Vector256<byte> search = LoadVector256(ref searchSpace, offset);
- // Bitwise Or to combine the matches and MoveMask to convert them to bitflags
- int matches = Avx2.MoveMask(
- Avx2.Or(
- Avx2.CompareEqual(values0, search),
- Avx2.CompareEqual(values1, search)));
- // Note that MoveMask has converted the equal vector elements into a set of bit flags,
- // So the bit position in 'matches' corresponds to the element offset.
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector256<byte>.Count;
- continue;
- }
-
- // Find bitflag offset of first match and add to current offset
- return ((int)(byte*)offset) + BitOperations.TrailingZeroCount(matches);
- } while ((byte*)lengthToExamine > (byte*)offset);
- }
-
- lengthToExamine = GetByteVector128SpanLength(offset, length);
- if ((byte*)lengthToExamine > (byte*)offset)
- {
- Vector128<byte> values0 = Vector128.Create(value0);
- Vector128<byte> values1 = Vector128.Create(value1);
-
- Vector128<byte> search = LoadVector128(ref searchSpace, offset);
- // Same method as above
- int matches = Sse2.MoveMask(
- Sse2.Or(
- Sse2.CompareEqual(values0, search),
- Sse2.CompareEqual(values1, search)));
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector128<byte>.Count;
- }
- else
- {
- // Find bitflag offset of first match and add to current offset
- return ((int)(byte*)offset) + BitOperations.TrailingZeroCount(matches);
- }
- }
-
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = (IntPtr)(length - (int)(byte*)offset);
- goto SequentialScan;
- }
- }
- }
- else if (Sse2.IsSupported)
- {
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = GetByteVector128SpanLength(offset, length);
-
- Vector128<byte> values0 = Vector128.Create(value0);
- Vector128<byte> values1 = Vector128.Create(value1);
-
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- Vector128<byte> search = LoadVector128(ref searchSpace, offset);
- // Same method as above
- int matches = Sse2.MoveMask(
- Sse2.Or(
- Sse2.CompareEqual(values0, search),
- Sse2.CompareEqual(values1, search)));
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector128<byte>.Count;
- continue;
- }
-
- // Find bitflag offset of first match and add to current offset
- return ((int)(byte*)offset) + BitOperations.TrailingZeroCount(matches);
- }
-
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = (IntPtr)(length - (int)(byte*)offset);
- goto SequentialScan;
- }
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = GetByteVectorSpanLength(offset, length);
-
- Vector<byte> values0 = new Vector<byte>(value0);
- Vector<byte> values1 = new Vector<byte>(value1);
-
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- Vector<byte> search = LoadVector(ref searchSpace, offset);
- var matches = Vector.BitwiseOr(
- Vector.Equals(search, values0),
- Vector.Equals(search, values1));
- if (Vector<byte>.Zero.Equals(matches))
- {
- offset += Vector<byte>.Count;
- continue;
- }
-
- // Find offset of first match and add to current offset
- return (int)(byte*)offset + LocateFirstFoundByte(matches);
- }
-
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = (IntPtr)(length - (int)(byte*)offset);
- goto SequentialScan;
- }
- }
- }
- return -1;
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return (int)(byte*)offset;
- Found1:
- return (int)(byte*)(offset + 1);
- Found2:
- return (int)(byte*)(offset + 2);
- Found3:
- return (int)(byte*)(offset + 3);
- Found4:
- return (int)(byte*)(offset + 4);
- Found5:
- return (int)(byte*)(offset + 5);
- Found6:
- return (int)(byte*)(offset + 6);
- Found7:
- return (int)(byte*)(offset + 7);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int IndexOfAny(ref byte searchSpace, byte value0, byte value1, byte value2, int length)
- {
- Debug.Assert(length >= 0);
-
- uint uValue0 = value0; // Use uint for comparisons to avoid unnecessary 8->32 extensions
- uint uValue1 = value1;
- uint uValue2 = value2;
- IntPtr offset = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
- IntPtr lengthToExamine = (IntPtr)length;
-
- if (Avx2.IsSupported || Sse2.IsSupported)
- {
- // Avx2 branch also operates on Sse2 sizes, so check is combined.
- if (length >= Vector128<byte>.Count * 2)
- {
- lengthToExamine = UnalignedCountVector128(ref searchSpace);
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- if (length >= Vector<byte>.Count * 2)
- {
- lengthToExamine = UnalignedCountVector(ref searchSpace);
- }
- }
- SequentialScan:
- uint lookUp;
- while ((byte*)lengthToExamine >= (byte*)8)
- {
- lengthToExamine -= 8;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 1);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found1;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 2);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found2;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 3);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found3;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 4);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found4;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 5);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found5;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 6);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found6;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 7);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found7;
-
- offset += 8;
- }
-
- if ((byte*)lengthToExamine >= (byte*)4)
- {
- lengthToExamine -= 4;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 1);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found1;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 2);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found2;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 3);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found3;
-
- offset += 4;
- }
-
- while ((byte*)lengthToExamine > (byte*)0)
- {
- lengthToExamine -= 1;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found;
-
- offset += 1;
- }
-
- if (Avx2.IsSupported)
- {
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = GetByteVector256SpanLength(offset, length);
- if ((byte*)lengthToExamine > (byte*)offset)
- {
- Vector256<byte> values0 = Vector256.Create(value0);
- Vector256<byte> values1 = Vector256.Create(value1);
- Vector256<byte> values2 = Vector256.Create(value2);
- do
- {
- Vector256<byte> search = LoadVector256(ref searchSpace, offset);
-
- Vector256<byte> matches0 = Avx2.CompareEqual(values0, search);
- Vector256<byte> matches1 = Avx2.CompareEqual(values1, search);
- Vector256<byte> matches2 = Avx2.CompareEqual(values2, search);
- // Bitwise Or to combine the matches and MoveMask to convert them to bitflags
- int matches = Avx2.MoveMask(Avx2.Or(Avx2.Or(matches0, matches1), matches2));
- // Note that MoveMask has converted the equal vector elements into a set of bit flags,
- // So the bit position in 'matches' corresponds to the element offset.
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector256<byte>.Count;
- continue;
- }
-
- // Find bitflag offset of first match and add to current offset
- return ((int)(byte*)offset) + BitOperations.TrailingZeroCount(matches);
- } while ((byte*)lengthToExamine > (byte*)offset);
- }
-
- lengthToExamine = GetByteVector128SpanLength(offset, length);
- if ((byte*)lengthToExamine > (byte*)offset)
- {
- Vector128<byte> values0 = Vector128.Create(value0);
- Vector128<byte> values1 = Vector128.Create(value1);
- Vector128<byte> values2 = Vector128.Create(value2);
-
- Vector128<byte> search = LoadVector128(ref searchSpace, offset);
-
- Vector128<byte> matches0 = Sse2.CompareEqual(values0, search);
- Vector128<byte> matches1 = Sse2.CompareEqual(values1, search);
- Vector128<byte> matches2 = Sse2.CompareEqual(values2, search);
- // Same method as above
- int matches = Sse2.MoveMask(Sse2.Or(Sse2.Or(matches0, matches1), matches2));
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector128<byte>.Count;
- }
- else
- {
- // Find bitflag offset of first match and add to current offset
- return ((int)(byte*)offset) + BitOperations.TrailingZeroCount(matches);
- }
- }
-
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = (IntPtr)(length - (int)(byte*)offset);
- goto SequentialScan;
- }
- }
- }
- else if (Sse2.IsSupported)
- {
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = GetByteVector128SpanLength(offset, length);
-
- Vector128<byte> values0 = Vector128.Create(value0);
- Vector128<byte> values1 = Vector128.Create(value1);
- Vector128<byte> values2 = Vector128.Create(value2);
-
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- Vector128<byte> search = LoadVector128(ref searchSpace, offset);
-
- Vector128<byte> matches0 = Sse2.CompareEqual(values0, search);
- Vector128<byte> matches1 = Sse2.CompareEqual(values1, search);
- Vector128<byte> matches2 = Sse2.CompareEqual(values2, search);
- // Same method as above
- int matches = Sse2.MoveMask(Sse2.Or(Sse2.Or(matches0, matches1), matches2));
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector128<byte>.Count;
- continue;
- }
-
- // Find bitflag offset of first match and add to current offset
- return ((int)(byte*)offset) + BitOperations.TrailingZeroCount(matches);
- }
-
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = (IntPtr)(length - (int)(byte*)offset);
- goto SequentialScan;
- }
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = GetByteVectorSpanLength(offset, length);
-
- Vector<byte> values0 = new Vector<byte>(value0);
- Vector<byte> values1 = new Vector<byte>(value1);
- Vector<byte> values2 = new Vector<byte>(value2);
-
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- Vector<byte> search = LoadVector(ref searchSpace, offset);
-
- var matches = Vector.BitwiseOr(
- Vector.BitwiseOr(
- Vector.Equals(search, values0),
- Vector.Equals(search, values1)),
- Vector.Equals(search, values2));
-
- if (Vector<byte>.Zero.Equals(matches))
- {
- offset += Vector<byte>.Count;
- continue;
- }
-
- // Find offset of first match and add to current offset
- return (int)(byte*)offset + LocateFirstFoundByte(matches);
- }
-
- if ((int)(byte*)offset < length)
- {
- lengthToExamine = (IntPtr)(length - (int)(byte*)offset);
- goto SequentialScan;
- }
- }
- }
- return -1;
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return (int)(byte*)offset;
- Found1:
- return (int)(byte*)(offset + 1);
- Found2:
- return (int)(byte*)(offset + 2);
- Found3:
- return (int)(byte*)(offset + 3);
- Found4:
- return (int)(byte*)(offset + 4);
- Found5:
- return (int)(byte*)(offset + 5);
- Found6:
- return (int)(byte*)(offset + 6);
- Found7:
- return (int)(byte*)(offset + 7);
- }
-
- public static unsafe int LastIndexOfAny(ref byte searchSpace, byte value0, byte value1, int length)
- {
- Debug.Assert(length >= 0);
-
- uint uValue0 = value0; // Use uint for comparisons to avoid unnecessary 8->32 extensions
- uint uValue1 = value1;
- IntPtr offset = (IntPtr)length; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
- IntPtr lengthToExamine = (IntPtr)length;
-
- if (Vector.IsHardwareAccelerated && length >= Vector<byte>.Count * 2)
- {
- lengthToExamine = UnalignedCountVectorFromEnd(ref searchSpace, length);
- }
- SequentialScan:
- uint lookUp;
- while ((byte*)lengthToExamine >= (byte*)8)
- {
- lengthToExamine -= 8;
- offset -= 8;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 7);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found7;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 6);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found6;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 5);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found5;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 4);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found4;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 3);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found3;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 2);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found2;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 1);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found1;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found;
- }
-
- if ((byte*)lengthToExamine >= (byte*)4)
- {
- lengthToExamine -= 4;
- offset -= 4;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 3);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found3;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 2);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found2;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 1);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found1;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found;
- }
-
- while ((byte*)lengthToExamine > (byte*)0)
- {
- lengthToExamine -= 1;
- offset -= 1;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp)
- goto Found;
- }
-
- if (Vector.IsHardwareAccelerated && ((byte*)offset > (byte*)0))
- {
- lengthToExamine = (IntPtr)((int)(byte*)offset & ~(Vector<byte>.Count - 1));
-
- Vector<byte> values0 = new Vector<byte>(value0);
- Vector<byte> values1 = new Vector<byte>(value1);
-
- while ((byte*)lengthToExamine > (byte*)(Vector<byte>.Count - 1))
- {
- Vector<byte> search = LoadVector(ref searchSpace, offset - Vector<byte>.Count);
- var matches = Vector.BitwiseOr(
- Vector.Equals(search, values0),
- Vector.Equals(search, values1));
- if (Vector<byte>.Zero.Equals(matches))
- {
- offset -= Vector<byte>.Count;
- lengthToExamine -= Vector<byte>.Count;
- continue;
- }
-
- // Find offset of first match and add to current offset
- return (int)(offset) - Vector<byte>.Count + LocateLastFoundByte(matches);
- }
-
- if ((byte*)offset > (byte*)0)
- {
- lengthToExamine = offset;
- goto SequentialScan;
- }
- }
- return -1;
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return (int)(byte*)offset;
- Found1:
- return (int)(byte*)(offset + 1);
- Found2:
- return (int)(byte*)(offset + 2);
- Found3:
- return (int)(byte*)(offset + 3);
- Found4:
- return (int)(byte*)(offset + 4);
- Found5:
- return (int)(byte*)(offset + 5);
- Found6:
- return (int)(byte*)(offset + 6);
- Found7:
- return (int)(byte*)(offset + 7);
- }
-
- public static unsafe int LastIndexOfAny(ref byte searchSpace, byte value0, byte value1, byte value2, int length)
- {
- Debug.Assert(length >= 0);
-
- uint uValue0 = value0; // Use uint for comparisons to avoid unnecessary 8->32 extensions
- uint uValue1 = value1;
- uint uValue2 = value2;
- IntPtr offset = (IntPtr)length; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
- IntPtr lengthToExamine = (IntPtr)length;
-
- if (Vector.IsHardwareAccelerated && length >= Vector<byte>.Count * 2)
- {
- lengthToExamine = UnalignedCountVectorFromEnd(ref searchSpace, length);
- }
- SequentialScan:
- uint lookUp;
- while ((byte*)lengthToExamine >= (byte*)8)
- {
- lengthToExamine -= 8;
- offset -= 8;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 7);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found7;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 6);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found6;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 5);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found5;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 4);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found4;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 3);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found3;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 2);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found2;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 1);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found1;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found;
- }
-
- if ((byte*)lengthToExamine >= (byte*)4)
- {
- lengthToExamine -= 4;
- offset -= 4;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 3);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found3;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 2);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found2;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset + 1);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found1;
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found;
- }
-
- while ((byte*)lengthToExamine > (byte*)0)
- {
- lengthToExamine -= 1;
- offset -= 1;
-
- lookUp = Unsafe.AddByteOffset(ref searchSpace, offset);
- if (uValue0 == lookUp || uValue1 == lookUp || uValue2 == lookUp)
- goto Found;
- }
-
- if (Vector.IsHardwareAccelerated && ((byte*)offset > (byte*)0))
- {
- lengthToExamine = (IntPtr)((int)(byte*)offset & ~(Vector<byte>.Count - 1));
-
- Vector<byte> values0 = new Vector<byte>(value0);
- Vector<byte> values1 = new Vector<byte>(value1);
- Vector<byte> values2 = new Vector<byte>(value2);
-
- while ((byte*)lengthToExamine > (byte*)(Vector<byte>.Count - 1))
- {
- Vector<byte> search = LoadVector(ref searchSpace, offset - Vector<byte>.Count);
-
- var matches = Vector.BitwiseOr(
- Vector.BitwiseOr(
- Vector.Equals(search, values0),
- Vector.Equals(search, values1)),
- Vector.Equals(search, values2));
-
- if (Vector<byte>.Zero.Equals(matches))
- {
- offset -= Vector<byte>.Count;
- lengthToExamine -= Vector<byte>.Count;
- continue;
- }
-
- // Find offset of first match and add to current offset
- return (int)(offset) - Vector<byte>.Count + LocateLastFoundByte(matches);
- }
-
- if ((byte*)offset > (byte*)0)
- {
- lengthToExamine = offset;
- goto SequentialScan;
- }
- }
- return -1;
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return (int)(byte*)offset;
- Found1:
- return (int)(byte*)(offset + 1);
- Found2:
- return (int)(byte*)(offset + 2);
- Found3:
- return (int)(byte*)(offset + 3);
- Found4:
- return (int)(byte*)(offset + 4);
- Found5:
- return (int)(byte*)(offset + 5);
- Found6:
- return (int)(byte*)(offset + 6);
- Found7:
- return (int)(byte*)(offset + 7);
- }
-
- // Optimized byte-based SequenceEquals. The "length" parameter for this one is declared a nuint rather than int as we also use it for types other than byte
- // where the length can exceed 2Gb once scaled by sizeof(T).
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe bool SequenceEqual(ref byte first, ref byte second, nuint length)
- {
- if (Unsafe.AreSame(ref first, ref second))
- goto Equal;
-
- IntPtr offset = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
- IntPtr lengthToExamine = (IntPtr)(void*)length;
-
- if (Vector.IsHardwareAccelerated && (byte*)lengthToExamine >= (byte*)Vector<byte>.Count)
- {
- lengthToExamine -= Vector<byte>.Count;
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- if (LoadVector(ref first, offset) != LoadVector(ref second, offset))
- {
- goto NotEqual;
- }
- offset += Vector<byte>.Count;
- }
- return LoadVector(ref first, lengthToExamine) == LoadVector(ref second, lengthToExamine);
- }
-
- if ((byte*)lengthToExamine >= (byte*)sizeof(UIntPtr))
- {
- lengthToExamine -= sizeof(UIntPtr);
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- if (LoadUIntPtr(ref first, offset) != LoadUIntPtr(ref second, offset))
- {
- goto NotEqual;
- }
- offset += sizeof(UIntPtr);
- }
- return LoadUIntPtr(ref first, lengthToExamine) == LoadUIntPtr(ref second, lengthToExamine);
- }
-
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- if (Unsafe.AddByteOffset(ref first, offset) != Unsafe.AddByteOffset(ref second, offset))
- goto NotEqual;
- offset += 1;
- }
-
- Equal:
- return true;
- NotEqual: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return false;
- }
-
- // Vector sub-search adapted from https://github.com/aspnet/KestrelHttpServer/pull/1138
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int LocateFirstFoundByte(Vector<byte> match)
- {
- var vector64 = Vector.AsVectorUInt64(match);
- ulong candidate = 0;
- int i = 0;
- // Pattern unrolled by jit https://github.com/dotnet/coreclr/pull/8001
- for (; i < Vector<ulong>.Count; i++)
- {
- candidate = vector64[i];
- if (candidate != 0)
- {
- break;
- }
- }
-
- // Single LEA instruction with jitted const (using function result)
- return i * 8 + LocateFirstFoundByte(candidate);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int SequenceCompareTo(ref byte first, int firstLength, ref byte second, int secondLength)
- {
- Debug.Assert(firstLength >= 0);
- Debug.Assert(secondLength >= 0);
-
- if (Unsafe.AreSame(ref first, ref second))
- goto Equal;
-
- IntPtr minLength = (IntPtr)((firstLength < secondLength) ? firstLength : secondLength);
-
- IntPtr offset = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
- IntPtr lengthToExamine = (IntPtr)(void*)minLength;
-
- if (Avx2.IsSupported)
- {
- if ((byte*)lengthToExamine >= (byte*)Vector256<byte>.Count)
- {
- lengthToExamine -= Vector256<byte>.Count;
- uint matches;
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- matches = (uint)Avx2.MoveMask(Avx2.CompareEqual(LoadVector256(ref first, offset), LoadVector256(ref second, offset)));
- // Note that MoveMask has converted the equal vector elements into a set of bit flags,
- // So the bit position in 'matches' corresponds to the element offset.
-
- // 32 elements in Vector256<byte> so we compare to uint.MaxValue to check if everything matched
- if (matches == uint.MaxValue)
- {
- // All matched
- offset += Vector256<byte>.Count;
- continue;
- }
-
- goto Difference;
- }
- // Move to Vector length from end for final compare
- offset = lengthToExamine;
- // Same as method as above
- matches = (uint)Avx2.MoveMask(Avx2.CompareEqual(LoadVector256(ref first, offset), LoadVector256(ref second, offset)));
- if (matches == uint.MaxValue)
- {
- // All matched
- goto Equal;
- }
- Difference:
- // Invert matches to find differences
- uint differences = ~matches;
- // Find bitflag offset of first difference and add to current offset
- offset = (IntPtr)((int)(byte*)offset + BitOperations.TrailingZeroCount((int)differences));
-
- int result = Unsafe.AddByteOffset(ref first, offset).CompareTo(Unsafe.AddByteOffset(ref second, offset));
- Debug.Assert(result != 0);
-
- return result;
- }
-
- if ((byte*)lengthToExamine >= (byte*)Vector128<byte>.Count)
- {
- lengthToExamine -= Vector128<byte>.Count;
- uint matches;
- if ((byte*)lengthToExamine > (byte*)offset)
- {
- matches = (uint)Sse2.MoveMask(Sse2.CompareEqual(LoadVector128(ref first, offset), LoadVector128(ref second, offset)));
- // Note that MoveMask has converted the equal vector elements into a set of bit flags,
- // So the bit position in 'matches' corresponds to the element offset.
-
- // 16 elements in Vector128<byte> so we compare to ushort.MaxValue to check if everything matched
- if (matches != ushort.MaxValue)
- {
- goto Difference;
- }
- }
- // Move to Vector length from end for final compare
- offset = lengthToExamine;
- // Same as method as above
- matches = (uint)Sse2.MoveMask(Sse2.CompareEqual(LoadVector128(ref first, offset), LoadVector128(ref second, offset)));
- if (matches == ushort.MaxValue)
- {
- // All matched
- goto Equal;
- }
- Difference:
- // Invert matches to find differences
- uint differences = ~matches;
- // Find bitflag offset of first difference and add to current offset
- offset = (IntPtr)((int)(byte*)offset + BitOperations.TrailingZeroCount((int)differences));
-
- int result = Unsafe.AddByteOffset(ref first, offset).CompareTo(Unsafe.AddByteOffset(ref second, offset));
- Debug.Assert(result != 0);
-
- return result;
- }
- }
- else if (Sse2.IsSupported)
- {
- if ((byte*)lengthToExamine >= (byte*)Vector128<byte>.Count)
- {
- lengthToExamine -= Vector128<byte>.Count;
- uint matches;
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- matches = (uint)Sse2.MoveMask(Sse2.CompareEqual(LoadVector128(ref first, offset), LoadVector128(ref second, offset)));
- // Note that MoveMask has converted the equal vector elements into a set of bit flags,
- // So the bit position in 'matches' corresponds to the element offset.
-
- // 16 elements in Vector128<byte> so we compare to ushort.MaxValue to check if everything matched
- if (matches == ushort.MaxValue)
- {
- // All matched
- offset += Vector128<byte>.Count;
- continue;
- }
-
- goto Difference;
- }
- // Move to Vector length from end for final compare
- offset = lengthToExamine;
- // Same as method as above
- matches = (uint)Sse2.MoveMask(Sse2.CompareEqual(LoadVector128(ref first, offset), LoadVector128(ref second, offset)));
- if (matches == ushort.MaxValue)
- {
- // All matched
- goto Equal;
- }
- Difference:
- // Invert matches to find differences
- uint differences = ~matches;
- // Find bitflag offset of first difference and add to current offset
- offset = (IntPtr)((int)(byte*)offset + BitOperations.TrailingZeroCount((int)differences));
-
- int result = Unsafe.AddByteOffset(ref first, offset).CompareTo(Unsafe.AddByteOffset(ref second, offset));
- Debug.Assert(result != 0);
-
- return result;
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- if ((byte*)lengthToExamine > (byte*)Vector<byte>.Count)
- {
- lengthToExamine -= Vector<byte>.Count;
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- if (LoadVector(ref first, offset) != LoadVector(ref second, offset))
- {
- goto BytewiseCheck;
- }
- offset += Vector<byte>.Count;
- }
- goto BytewiseCheck;
- }
- }
-
- if ((byte*)lengthToExamine > (byte*)sizeof(UIntPtr))
- {
- lengthToExamine -= sizeof(UIntPtr);
- while ((byte*)lengthToExamine > (byte*)offset)
- {
- if (LoadUIntPtr(ref first, offset) != LoadUIntPtr(ref second, offset))
- {
- goto BytewiseCheck;
- }
- offset += sizeof(UIntPtr);
- }
- }
-
- BytewiseCheck: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- while ((byte*)minLength > (byte*)offset)
- {
- int result = Unsafe.AddByteOffset(ref first, offset).CompareTo(Unsafe.AddByteOffset(ref second, offset));
- if (result != 0)
- return result;
- offset += 1;
- }
-
- Equal:
- return firstLength - secondLength;
- }
-
- // Vector sub-search adapted from https://github.com/aspnet/KestrelHttpServer/pull/1138
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int LocateLastFoundByte(Vector<byte> match)
- {
- var vector64 = Vector.AsVectorUInt64(match);
- ulong candidate = 0;
- int i = Vector<ulong>.Count - 1;
- // Pattern unrolled by jit https://github.com/dotnet/coreclr/pull/8001
- for (; i >= 0; i--)
- {
- candidate = vector64[i];
- if (candidate != 0)
- {
- break;
- }
- }
-
- // Single LEA instruction with jitted const (using function result)
- return i * 8 + LocateLastFoundByte(candidate);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int LocateFirstFoundByte(ulong match)
- {
- if (Bmi1.X64.IsSupported)
- {
- return (int)(Bmi1.X64.TrailingZeroCount(match) >> 3);
- }
- else
- {
- // Flag least significant power of two bit
- ulong powerOfTwoFlag = match ^ (match - 1);
- // Shift all powers of two into the high byte and extract
- return (int)((powerOfTwoFlag * XorPowerOfTwoToHighByte) >> 57);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int LocateLastFoundByte(ulong match)
- {
- return 7 - (BitOperations.LeadingZeroCount(match) >> 3);
- }
-
- private const ulong XorPowerOfTwoToHighByte = (0x07ul |
- 0x06ul << 8 |
- 0x05ul << 16 |
- 0x04ul << 24 |
- 0x03ul << 32 |
- 0x02ul << 40 |
- 0x01ul << 48) + 1;
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe UIntPtr LoadUIntPtr(ref byte start, IntPtr offset)
- => Unsafe.ReadUnaligned<UIntPtr>(ref Unsafe.AddByteOffset(ref start, offset));
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe Vector<byte> LoadVector(ref byte start, IntPtr offset)
- => Unsafe.ReadUnaligned<Vector<byte>>(ref Unsafe.AddByteOffset(ref start, offset));
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe Vector128<byte> LoadVector128(ref byte start, IntPtr offset)
- => Unsafe.ReadUnaligned<Vector128<byte>>(ref Unsafe.AddByteOffset(ref start, offset));
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe Vector256<byte> LoadVector256(ref byte start, IntPtr offset)
- => Unsafe.ReadUnaligned<Vector256<byte>>(ref Unsafe.AddByteOffset(ref start, offset));
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe IntPtr GetByteVectorSpanLength(IntPtr offset, int length)
- => (IntPtr)((length - (int)(byte*)offset) & ~(Vector<byte>.Count - 1));
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe IntPtr GetByteVector128SpanLength(IntPtr offset, int length)
- => (IntPtr)((length - (int)(byte*)offset) & ~(Vector128<byte>.Count - 1));
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe IntPtr GetByteVector256SpanLength(IntPtr offset, int length)
- => (IntPtr)((length - (int)(byte*)offset) & ~(Vector256<byte>.Count - 1));
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe IntPtr UnalignedCountVector(ref byte searchSpace)
- {
- int unaligned = (int)Unsafe.AsPointer(ref searchSpace) & (Vector<byte>.Count - 1);
- return (IntPtr)((Vector<byte>.Count - unaligned) & (Vector<byte>.Count - 1));
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe IntPtr UnalignedCountVector128(ref byte searchSpace)
- {
- int unaligned = (int)Unsafe.AsPointer(ref searchSpace) & (Vector128<byte>.Count - 1);
- return (IntPtr)((Vector128<byte>.Count - unaligned) & (Vector128<byte>.Count - 1));
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe IntPtr UnalignedCountVectorFromEnd(ref byte searchSpace, int length)
- {
- int unaligned = (int)Unsafe.AsPointer(ref searchSpace) & (Vector<byte>.Count - 1);
- return (IntPtr)(((length & (Vector<byte>.Count - 1)) + unaligned) & (Vector<byte>.Count - 1));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/SpanHelpers.Char.cs b/netcore/System.Private.CoreLib/shared/System/SpanHelpers.Char.cs
deleted file mode 100644
index 7d4d27aded2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/SpanHelpers.Char.cs
+++ /dev/null
@@ -1,1087 +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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-using nint = System.Int64;
-#else
-using nuint = System.UInt32;
-using nint = System.Int32;
-#endif
-
-namespace System
-{
- internal static partial class SpanHelpers // .Char
- {
- public static int IndexOf(ref char searchSpace, int searchSpaceLength, ref char value, int valueLength)
- {
- Debug.Assert(searchSpaceLength >= 0);
- Debug.Assert(valueLength >= 0);
-
- if (valueLength == 0)
- return 0; // A zero-length sequence is always treated as "found" at the start of the search space.
-
- char valueHead = value;
- ref char valueTail = ref Unsafe.Add(ref value, 1);
- int valueTailLength = valueLength - 1;
- int remainingSearchSpaceLength = searchSpaceLength - valueTailLength;
-
- int index = 0;
- while (remainingSearchSpaceLength > 0)
- {
- // Do a quick search for the first element of "value".
- int relativeIndex = IndexOf(ref Unsafe.Add(ref searchSpace, index), valueHead, remainingSearchSpaceLength);
- if (relativeIndex == -1)
- break;
-
- remainingSearchSpaceLength -= relativeIndex;
- index += relativeIndex;
-
- if (remainingSearchSpaceLength <= 0)
- break; // The unsearched portion is now shorter than the sequence we're looking for. So it can't be there.
-
- // Found the first element of "value". See if the tail matches.
- if (SequenceEqual(
- ref Unsafe.As<char, byte>(ref Unsafe.Add(ref searchSpace, index + 1)),
- ref Unsafe.As<char, byte>(ref valueTail),
- (nuint)valueTailLength * 2))
- {
- return index; // The tail matched. Return a successful find.
- }
-
- remainingSearchSpaceLength--;
- index++;
- }
- return -1;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int SequenceCompareTo(ref char first, int firstLength, ref char second, int secondLength)
- {
- Debug.Assert(firstLength >= 0);
- Debug.Assert(secondLength >= 0);
-
- int lengthDelta = firstLength - secondLength;
-
- if (Unsafe.AreSame(ref first, ref second))
- goto Equal;
-
- IntPtr minLength = (IntPtr)((firstLength < secondLength) ? firstLength : secondLength);
- IntPtr i = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
-
- if ((byte*)minLength >= (byte*)(sizeof(UIntPtr) / sizeof(char)))
- {
- if (Vector.IsHardwareAccelerated && (byte*)minLength >= (byte*)Vector<ushort>.Count)
- {
- IntPtr nLength = minLength - Vector<ushort>.Count;
- do
- {
- if (Unsafe.ReadUnaligned<Vector<ushort>>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref first, i))) !=
- Unsafe.ReadUnaligned<Vector<ushort>>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref second, i))))
- {
- break;
- }
- i += Vector<ushort>.Count;
- }
- while ((byte*)nLength >= (byte*)i);
- }
-
- while ((byte*)minLength >= (byte*)(i + sizeof(UIntPtr) / sizeof(char)))
- {
- if (Unsafe.ReadUnaligned<UIntPtr>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref first, i))) !=
- Unsafe.ReadUnaligned<UIntPtr>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref second, i))))
- {
- break;
- }
- i += sizeof(UIntPtr) / sizeof(char);
- }
- }
-
- if (sizeof(UIntPtr) > sizeof(int) && (byte*)minLength >= (byte*)(i + sizeof(int) / sizeof(char)))
- {
- if (Unsafe.ReadUnaligned<int>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref first, i))) ==
- Unsafe.ReadUnaligned<int>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref second, i))))
- {
- i += sizeof(int) / sizeof(char);
- }
- }
-
- while ((byte*)i < (byte*)minLength)
- {
- int result = Unsafe.Add(ref first, i).CompareTo(Unsafe.Add(ref second, i));
- if (result != 0)
- return result;
- i += 1;
- }
-
- Equal:
- return lengthDelta;
- }
-
- // Adapted from IndexOf(...)
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe bool Contains(ref char searchSpace, char value, int length)
- {
- Debug.Assert(length >= 0);
-
- fixed (char* pChars = &searchSpace)
- {
- char* pCh = pChars;
- char* pEndCh = pCh + length;
-
- if (Vector.IsHardwareAccelerated && length >= Vector<ushort>.Count * 2)
- {
- // Figure out how many characters to read sequentially until we are vector aligned
- // This is equivalent to:
- // unaligned = ((int)pCh % Unsafe.SizeOf<Vector<ushort>>()) / elementsPerByte
- // length = (Vector<ushort>.Count - unaligned) % Vector<ushort>.Count
- const int elementsPerByte = sizeof(ushort) / sizeof(byte);
- int unaligned = ((int)pCh & (Unsafe.SizeOf<Vector<ushort>>() - 1)) / elementsPerByte;
- length = (Vector<ushort>.Count - unaligned) & (Vector<ushort>.Count - 1);
- }
-
- SequentialScan:
- while (length >= 4)
- {
- length -= 4;
-
- if (value == *pCh ||
- value == *(pCh + 1) ||
- value == *(pCh + 2) ||
- value == *(pCh + 3))
- {
- goto Found;
- }
-
- pCh += 4;
- }
-
- while (length > 0)
- {
- length--;
-
- if (value == *pCh)
- goto Found;
-
- pCh++;
- }
-
- // We get past SequentialScan only if IsHardwareAccelerated is true. However, we still have the redundant check to allow
- // the JIT to see that the code is unreachable and eliminate it when the platform does not have hardware accelerated.
- if (Vector.IsHardwareAccelerated && pCh < pEndCh)
- {
- // Get the highest multiple of Vector<ushort>.Count that is within the search space.
- // That will be how many times we iterate in the loop below.
- // This is equivalent to: length = Vector<ushort>.Count * ((int)(pEndCh - pCh) / Vector<ushort>.Count)
- length = (int)((pEndCh - pCh) & ~(Vector<ushort>.Count - 1));
-
- // Get comparison Vector
- Vector<ushort> vComparison = new Vector<ushort>(value);
-
- while (length > 0)
- {
- // Using Unsafe.Read instead of ReadUnaligned since the search space is pinned and pCh is always vector aligned
- Debug.Assert(((int)pCh & (Unsafe.SizeOf<Vector<ushort>>() - 1)) == 0);
- Vector<ushort> vMatches = Vector.Equals(vComparison, Unsafe.Read<Vector<ushort>>(pCh));
- if (Vector<ushort>.Zero.Equals(vMatches))
- {
- pCh += Vector<ushort>.Count;
- length -= Vector<ushort>.Count;
- continue;
- }
-
- goto Found;
- }
-
- if (pCh < pEndCh)
- {
- length = (int)(pEndCh - pCh);
- goto SequentialScan;
- }
- }
-
- return false;
-
- Found:
- return true;
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int IndexOf(ref char searchSpace, char value, int length)
- {
- Debug.Assert(length >= 0);
-
- nint offset = 0;
- nint lengthToExamine = length;
-
- if (((int)Unsafe.AsPointer(ref searchSpace) & 1) != 0)
- {
- // Input isn't char aligned, we won't be able to align it to a Vector
- }
- else if (Sse2.IsSupported)
- {
- // Avx2 branch also operates on Sse2 sizes, so check is combined.
- // Needs to be double length to allow us to align the data first.
- if (length >= Vector128<ushort>.Count * 2)
- {
- lengthToExamine = UnalignedCountVector128(ref searchSpace);
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- // Needs to be double length to allow us to align the data first.
- if (length >= Vector<ushort>.Count * 2)
- {
- lengthToExamine = UnalignedCountVector(ref searchSpace);
- }
- }
-
- SequentialScan:
- // In the non-vector case lengthToExamine is the total length.
- // In the vector case lengthToExamine first aligns to Vector,
- // then in a second pass after the Vector lengths is the
- // remaining data that is shorter than a Vector length.
- while (lengthToExamine >= 4)
- {
- ref char current = ref Add(ref searchSpace, offset);
-
- if (value == current)
- goto Found;
- if (value == Add(ref current, 1))
- goto Found1;
- if (value == Add(ref current, 2))
- goto Found2;
- if (value == Add(ref current, 3))
- goto Found3;
-
- offset += 4;
- lengthToExamine -= 4;
- }
-
- while (lengthToExamine > 0)
- {
- if (value == Add(ref searchSpace, offset))
- goto Found;
-
- offset++;
- lengthToExamine--;
- }
-
- // We get past SequentialScan only if IsHardwareAccelerated or intrinsic .IsSupported is true. However, we still have the redundant check to allow
- // the JIT to see that the code is unreachable and eliminate it when the platform does not have hardware accelerated.
- if (Avx2.IsSupported)
- {
- if (offset < length)
- {
- Debug.Assert(length - offset >= Vector128<ushort>.Count);
- if (((nint)Unsafe.AsPointer(ref Unsafe.Add(ref searchSpace, (IntPtr)offset)) & (nint)(Vector256<byte>.Count - 1)) != 0)
- {
- // Not currently aligned to Vector256 (is aligned to Vector128); this can cause a problem for searches
- // with no upper bound e.g. String.wcslen. Start with a check on Vector128 to align to Vector256,
- // before moving to processing Vector256.
-
- // If the input searchSpan has been fixed or pinned, this ensures we do not fault across memory pages
- // while searching for an end of string. Specifically that this assumes that the length is either correct
- // or that the data is pinned otherwise it may cause an AccessViolation from crossing a page boundary into an
- // unowned page. If the search is unbounded (e.g. null terminator in wcslen) and the search value is not found,
- // again this will likely cause an AccessViolation. However, correctly bounded searches will return -1 rather
- // than ever causing an AV.
-
- // If the searchSpan has not been fixed or pinned the GC can relocate it during the execution of this
- // method, so the alignment only acts as best endeavour. The GC cost is likely to dominate over
- // the misalignment that may occur after; to we default to giving the GC a free hand to relocate and
- // its up to the caller whether they are operating over fixed data.
- Vector128<ushort> values = Vector128.Create((ushort)value);
- Vector128<ushort> search = LoadVector128(ref searchSpace, offset);
-
- // Same method as below
- int matches = Sse2.MoveMask(Sse2.CompareEqual(values, search).AsByte());
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector128<ushort>.Count;
- }
- else
- {
- // Find bitflag offset of first match and add to current offset
- return (int)(offset + ((uint)BitOperations.TrailingZeroCount(matches) / sizeof(char)));
- }
- }
-
- lengthToExamine = GetCharVector256SpanLength(offset, length);
- if (lengthToExamine > 0)
- {
- Vector256<ushort> values = Vector256.Create((ushort)value);
- do
- {
- Debug.Assert(lengthToExamine >= Vector256<ushort>.Count);
-
- Vector256<ushort> search = LoadVector256(ref searchSpace, offset);
- int matches = Avx2.MoveMask(Avx2.CompareEqual(values, search).AsByte());
- // Note that MoveMask has converted the equal vector elements into a set of bit flags,
- // So the bit position in 'matches' corresponds to the element offset.
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector256<ushort>.Count;
- lengthToExamine -= Vector256<ushort>.Count;
- continue;
- }
-
- // Find bitflag offset of first match and add to current offset,
- // flags are in bytes so divide for chars
- return (int)(offset + ((uint)BitOperations.TrailingZeroCount(matches) / sizeof(char)));
- } while (lengthToExamine > 0);
- }
-
- lengthToExamine = GetCharVector128SpanLength(offset, length);
- if (lengthToExamine > 0)
- {
- Debug.Assert(lengthToExamine >= Vector128<ushort>.Count);
-
- Vector128<ushort> values = Vector128.Create((ushort)value);
- Vector128<ushort> search = LoadVector128(ref searchSpace, offset);
-
- // Same method as above
- int matches = Sse2.MoveMask(Sse2.CompareEqual(values, search).AsByte());
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector128<ushort>.Count;
- // Don't need to change lengthToExamine here as we don't use its current value again.
- }
- else
- {
- // Find bitflag offset of first match and add to current offset,
- // flags are in bytes so divide for chars
- return (int)(offset + ((uint)BitOperations.TrailingZeroCount(matches) / sizeof(char)));
- }
- }
-
- if (offset < length)
- {
- lengthToExamine = length - offset;
- goto SequentialScan;
- }
- }
- }
- else if (Sse2.IsSupported)
- {
- if (offset < length)
- {
- Debug.Assert(length - offset >= Vector128<ushort>.Count);
-
- lengthToExamine = GetCharVector128SpanLength(offset, length);
- if (lengthToExamine > 0)
- {
- Vector128<ushort> values = Vector128.Create((ushort)value);
- do
- {
- Debug.Assert(lengthToExamine >= Vector128<ushort>.Count);
-
- Vector128<ushort> search = LoadVector128(ref searchSpace, offset);
-
- // Same method as above
- int matches = Sse2.MoveMask(Sse2.CompareEqual(values, search).AsByte());
- if (matches == 0)
- {
- // Zero flags set so no matches
- offset += Vector128<ushort>.Count;
- lengthToExamine -= Vector128<ushort>.Count;
- continue;
- }
-
- // Find bitflag offset of first match and add to current offset,
- // flags are in bytes so divide for chars
- return (int)(offset + ((uint)BitOperations.TrailingZeroCount(matches) / sizeof(char)));
- } while (lengthToExamine > 0);
- }
-
- if (offset < length)
- {
- lengthToExamine = length - offset;
- goto SequentialScan;
- }
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- if (offset < length)
- {
- Debug.Assert(length - offset >= Vector<ushort>.Count);
-
- lengthToExamine = GetCharVectorSpanLength(offset, length);
-
- if (lengthToExamine > 0)
- {
- Vector<ushort> values = new Vector<ushort>((ushort)value);
- do
- {
- Debug.Assert(lengthToExamine >= Vector<ushort>.Count);
-
- var matches = Vector.Equals(values, LoadVector(ref searchSpace, offset));
- if (Vector<ushort>.Zero.Equals(matches))
- {
- offset += Vector<ushort>.Count;
- lengthToExamine -= Vector<ushort>.Count;
- continue;
- }
-
- // Find offset of first match
- return (int)(offset + LocateFirstFoundChar(matches));
- } while (lengthToExamine > 0);
- }
-
- if (offset < length)
- {
- lengthToExamine = length - offset;
- goto SequentialScan;
- }
- }
- }
- return -1;
- Found3:
- return (int)(offset + 3);
- Found2:
- return (int)(offset + 2);
- Found1:
- return (int)(offset + 1);
- Found:
- return (int)(offset);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int IndexOfAny(ref char searchSpace, char value0, char value1, int length)
- {
- Debug.Assert(length >= 0);
-
- fixed (char* pChars = &searchSpace)
- {
- char* pCh = pChars;
- char* pEndCh = pCh + length;
-
- if (Vector.IsHardwareAccelerated && length >= Vector<ushort>.Count * 2)
- {
- // Figure out how many characters to read sequentially until we are vector aligned
- // This is equivalent to:
- // unaligned = ((int)pCh % Unsafe.SizeOf<Vector<ushort>>()) / elementsPerByte
- // length = (Vector<ushort>.Count - unaligned) % Vector<ushort>.Count
- const int elementsPerByte = sizeof(ushort) / sizeof(byte);
- int unaligned = ((int)pCh & (Unsafe.SizeOf<Vector<ushort>>() - 1)) / elementsPerByte;
- length = (Vector<ushort>.Count - unaligned) & (Vector<ushort>.Count - 1);
- }
-
- SequentialScan:
- while (length >= 4)
- {
- length -= 4;
-
- if (pCh[0] == value0 || pCh[0] == value1)
- goto Found;
- if (pCh[1] == value0 || pCh[1] == value1)
- goto Found1;
- if (pCh[2] == value0 || pCh[2] == value1)
- goto Found2;
- if (pCh[3] == value0 || pCh[3] == value1)
- goto Found3;
-
- pCh += 4;
- }
-
- while (length > 0)
- {
- length--;
-
- if (pCh[0] == value0 || pCh[0] == value1)
- goto Found;
-
- pCh++;
- }
-
- // We get past SequentialScan only if IsHardwareAccelerated is true. However, we still have the redundant check to allow
- // the JIT to see that the code is unreachable and eliminate it when the platform does not have hardware accelerated.
- if (Vector.IsHardwareAccelerated && pCh < pEndCh)
- {
- // Get the highest multiple of Vector<ushort>.Count that is within the search space.
- // That will be how many times we iterate in the loop below.
- // This is equivalent to: length = Vector<ushort>.Count * ((int)(pEndCh - pCh) / Vector<ushort>.Count)
- length = (int)((pEndCh - pCh) & ~(Vector<ushort>.Count - 1));
-
- // Get comparison Vector
- Vector<ushort> values0 = new Vector<ushort>(value0);
- Vector<ushort> values1 = new Vector<ushort>(value1);
-
- while (length > 0)
- {
- // Using Unsafe.Read instead of ReadUnaligned since the search space is pinned and pCh is always vector aligned
- Debug.Assert(((int)pCh & (Unsafe.SizeOf<Vector<ushort>>() - 1)) == 0);
- Vector<ushort> vData = Unsafe.Read<Vector<ushort>>(pCh);
- var vMatches = Vector.BitwiseOr(
- Vector.Equals(vData, values0),
- Vector.Equals(vData, values1));
- if (Vector<ushort>.Zero.Equals(vMatches))
- {
- pCh += Vector<ushort>.Count;
- length -= Vector<ushort>.Count;
- continue;
- }
- // Find offset of first match
- return (int)(pCh - pChars) + LocateFirstFoundChar(vMatches);
- }
-
- if (pCh < pEndCh)
- {
- length = (int)(pEndCh - pCh);
- goto SequentialScan;
- }
- }
-
- return -1;
- Found3:
- pCh++;
- Found2:
- pCh++;
- Found1:
- pCh++;
- Found:
- return (int)(pCh - pChars);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int IndexOfAny(ref char searchSpace, char value0, char value1, char value2, int length)
- {
- Debug.Assert(length >= 0);
-
- fixed (char* pChars = &searchSpace)
- {
- char* pCh = pChars;
- char* pEndCh = pCh + length;
-
- if (Vector.IsHardwareAccelerated && length >= Vector<ushort>.Count * 2)
- {
- // Figure out how many characters to read sequentially until we are vector aligned
- // This is equivalent to:
- // unaligned = ((int)pCh % Unsafe.SizeOf<Vector<ushort>>()) / elementsPerByte
- // length = (Vector<ushort>.Count - unaligned) % Vector<ushort>.Count
- const int elementsPerByte = sizeof(ushort) / sizeof(byte);
- int unaligned = ((int)pCh & (Unsafe.SizeOf<Vector<ushort>>() - 1)) / elementsPerByte;
- length = (Vector<ushort>.Count - unaligned) & (Vector<ushort>.Count - 1);
- }
-
- SequentialScan:
- while (length >= 4)
- {
- length -= 4;
-
- if (pCh[0] == value0 || pCh[0] == value1 || pCh[0] == value2)
- goto Found;
- if (pCh[1] == value0 || pCh[1] == value1 || pCh[1] == value2)
- goto Found1;
- if (pCh[2] == value0 || pCh[2] == value1 || pCh[2] == value2)
- goto Found2;
- if (pCh[3] == value0 || pCh[3] == value1 || pCh[3] == value2)
- goto Found3;
-
- pCh += 4;
- }
-
- while (length > 0)
- {
- length--;
-
- if (pCh[0] == value0 || pCh[0] == value1 || pCh[0] == value2)
- goto Found;
-
- pCh++;
- }
-
- // We get past SequentialScan only if IsHardwareAccelerated is true. However, we still have the redundant check to allow
- // the JIT to see that the code is unreachable and eliminate it when the platform does not have hardware accelerated.
- if (Vector.IsHardwareAccelerated && pCh < pEndCh)
- {
- // Get the highest multiple of Vector<ushort>.Count that is within the search space.
- // That will be how many times we iterate in the loop below.
- // This is equivalent to: length = Vector<ushort>.Count * ((int)(pEndCh - pCh) / Vector<ushort>.Count)
- length = (int)((pEndCh - pCh) & ~(Vector<ushort>.Count - 1));
-
- // Get comparison Vector
- Vector<ushort> values0 = new Vector<ushort>(value0);
- Vector<ushort> values1 = new Vector<ushort>(value1);
- Vector<ushort> values2 = new Vector<ushort>(value2);
-
- while (length > 0)
- {
- // Using Unsafe.Read instead of ReadUnaligned since the search space is pinned and pCh is always vector aligned
- Debug.Assert(((int)pCh & (Unsafe.SizeOf<Vector<ushort>>() - 1)) == 0);
- Vector<ushort> vData = Unsafe.Read<Vector<ushort>>(pCh);
- var vMatches = Vector.BitwiseOr(
- Vector.BitwiseOr(
- Vector.Equals(vData, values0),
- Vector.Equals(vData, values1)),
- Vector.Equals(vData, values2));
-
- if (Vector<ushort>.Zero.Equals(vMatches))
- {
- pCh += Vector<ushort>.Count;
- length -= Vector<ushort>.Count;
- continue;
- }
- // Find offset of first match
- return (int)(pCh - pChars) + LocateFirstFoundChar(vMatches);
- }
-
- if (pCh < pEndCh)
- {
- length = (int)(pEndCh - pCh);
- goto SequentialScan;
- }
- }
- return -1;
- Found3:
- pCh++;
- Found2:
- pCh++;
- Found1:
- pCh++;
- Found:
- return (int)(pCh - pChars);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int IndexOfAny(ref char searchSpace, char value0, char value1, char value2, char value3, int length)
- {
- Debug.Assert(length >= 0);
-
- fixed (char* pChars = &searchSpace)
- {
- char* pCh = pChars;
- char* pEndCh = pCh + length;
-
- if (Vector.IsHardwareAccelerated && length >= Vector<ushort>.Count * 2)
- {
- // Figure out how many characters to read sequentially until we are vector aligned
- // This is equivalent to:
- // unaligned = ((int)pCh % Unsafe.SizeOf<Vector<ushort>>()) / elementsPerByte
- // length = (Vector<ushort>.Count - unaligned) % Vector<ushort>.Count
- const int elementsPerByte = sizeof(ushort) / sizeof(byte);
- int unaligned = ((int)pCh & (Unsafe.SizeOf<Vector<ushort>>() - 1)) / elementsPerByte;
- length = (Vector<ushort>.Count - unaligned) & (Vector<ushort>.Count - 1);
- }
-
- SequentialScan:
- while (length >= 4)
- {
- length -= 4;
-
- if (pCh[0] == value0 || pCh[0] == value1 || pCh[0] == value2 || pCh[0] == value3)
- goto Found;
- if (pCh[1] == value0 || pCh[1] == value1 || pCh[1] == value2 || pCh[1] == value3)
- goto Found1;
- if (pCh[2] == value0 || pCh[2] == value1 || pCh[2] == value2 || pCh[2] == value3)
- goto Found2;
- if (pCh[3] == value0 || pCh[3] == value1 || pCh[3] == value2 || pCh[3] == value3)
- goto Found3;
-
- pCh += 4;
- }
-
- while (length > 0)
- {
- length--;
-
- if (pCh[0] == value0 || pCh[0] == value1 || pCh[0] == value2 || pCh[0] == value3)
- goto Found;
-
- pCh++;
- }
-
- // We get past SequentialScan only if IsHardwareAccelerated is true. However, we still have the redundant check to allow
- // the JIT to see that the code is unreachable and eliminate it when the platform does not have hardware accelerated.
- if (Vector.IsHardwareAccelerated && pCh < pEndCh)
- {
- // Get the highest multiple of Vector<ushort>.Count that is within the search space.
- // That will be how many times we iterate in the loop below.
- // This is equivalent to: length = Vector<ushort>.Count * ((int)(pEndCh - pCh) / Vector<ushort>.Count)
- length = (int)((pEndCh - pCh) & ~(Vector<ushort>.Count - 1));
-
- // Get comparison Vector
- Vector<ushort> values0 = new Vector<ushort>(value0);
- Vector<ushort> values1 = new Vector<ushort>(value1);
- Vector<ushort> values2 = new Vector<ushort>(value2);
- Vector<ushort> values3 = new Vector<ushort>(value3);
-
- while (length > 0)
- {
- // Using Unsafe.Read instead of ReadUnaligned since the search space is pinned and pCh is always vector aligned
- Debug.Assert(((int)pCh & (Unsafe.SizeOf<Vector<ushort>>() - 1)) == 0);
- Vector<ushort> vData = Unsafe.Read<Vector<ushort>>(pCh);
- var vMatches = Vector.BitwiseOr(
- Vector.BitwiseOr(
- Vector.BitwiseOr(Vector.Equals(vData, values0), Vector.Equals(vData, values1)),
- Vector.Equals(vData, values2)),
- Vector.Equals(vData, values3));
-
- if (Vector<ushort>.Zero.Equals(vMatches))
- {
- pCh += Vector<ushort>.Count;
- length -= Vector<ushort>.Count;
- continue;
- }
- // Find offset of first match
- return (int)(pCh - pChars) + LocateFirstFoundChar(vMatches);
- }
-
- if (pCh < pEndCh)
- {
- length = (int)(pEndCh - pCh);
- goto SequentialScan;
- }
- }
-
- return -1;
- Found3:
- pCh++;
- Found2:
- pCh++;
- Found1:
- pCh++;
- Found:
- return (int)(pCh - pChars);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int IndexOfAny(ref char searchSpace, char value0, char value1, char value2, char value3, char value4, int length)
- {
- Debug.Assert(length >= 0);
-
- fixed (char* pChars = &searchSpace)
- {
- char* pCh = pChars;
- char* pEndCh = pCh + length;
-
- if (Vector.IsHardwareAccelerated && length >= Vector<ushort>.Count * 2)
- {
- // Figure out how many characters to read sequentially until we are vector aligned
- // This is equivalent to:
- // unaligned = ((int)pCh % Unsafe.SizeOf<Vector<ushort>>()) / elementsPerByte
- // length = (Vector<ushort>.Count - unaligned) % Vector<ushort>.Count
- const int elementsPerByte = sizeof(ushort) / sizeof(byte);
- int unaligned = ((int)pCh & (Unsafe.SizeOf<Vector<ushort>>() - 1)) / elementsPerByte;
- length = (Vector<ushort>.Count - unaligned) & (Vector<ushort>.Count - 1);
- }
-
- SequentialScan:
- while (length >= 4)
- {
- length -= 4;
-
- if (pCh[0] == value0 || pCh[0] == value1 || pCh[0] == value2 || pCh[0] == value3 || pCh[0] == value4)
- goto Found;
- if (pCh[1] == value0 || pCh[1] == value1 || pCh[1] == value2 || pCh[1] == value3 || pCh[1] == value4)
- goto Found1;
- if (pCh[2] == value0 || pCh[2] == value1 || pCh[2] == value2 || pCh[2] == value3 || pCh[2] == value4)
- goto Found2;
- if (pCh[3] == value0 || pCh[3] == value1 || pCh[3] == value2 || pCh[3] == value3 || pCh[3] == value4)
- goto Found3;
-
- pCh += 4;
- }
-
- while (length > 0)
- {
- length--;
-
- if (pCh[0] == value0 || pCh[0] == value1 || pCh[0] == value2 || pCh[0] == value3 || pCh[0] == value4)
- goto Found;
-
- pCh++;
- }
-
- // We get past SequentialScan only if IsHardwareAccelerated is true. However, we still have the redundant check to allow
- // the JIT to see that the code is unreachable and eliminate it when the platform does not have hardware accelerated.
- if (Vector.IsHardwareAccelerated && pCh < pEndCh)
- {
- // Get the highest multiple of Vector<ushort>.Count that is within the search space.
- // That will be how many times we iterate in the loop below.
- // This is equivalent to: length = Vector<ushort>.Count * ((int)(pEndCh - pCh) / Vector<ushort>.Count)
- length = (int)((pEndCh - pCh) & ~(Vector<ushort>.Count - 1));
-
- // Get comparison Vector
- Vector<ushort> values0 = new Vector<ushort>(value0);
- Vector<ushort> values1 = new Vector<ushort>(value1);
- Vector<ushort> values2 = new Vector<ushort>(value2);
- Vector<ushort> values3 = new Vector<ushort>(value3);
- Vector<ushort> values4 = new Vector<ushort>(value4);
-
- while (length > 0)
- {
- // Using Unsafe.Read instead of ReadUnaligned since the search space is pinned and pCh is always vector aligned
- Debug.Assert(((int)pCh & (Unsafe.SizeOf<Vector<ushort>>() - 1)) == 0);
- Vector<ushort> vData = Unsafe.Read<Vector<ushort>>(pCh);
- var vMatches = Vector.BitwiseOr(
- Vector.BitwiseOr(
- Vector.BitwiseOr(
- Vector.BitwiseOr(Vector.Equals(vData, values0), Vector.Equals(vData, values1)),
- Vector.Equals(vData, values2)),
- Vector.Equals(vData, values3)),
- Vector.Equals(vData, values4));
-
- if (Vector<ushort>.Zero.Equals(vMatches))
- {
- pCh += Vector<ushort>.Count;
- length -= Vector<ushort>.Count;
- continue;
- }
- // Find offset of first match
- return (int)(pCh - pChars) + LocateFirstFoundChar(vMatches);
- }
-
- if (pCh < pEndCh)
- {
- length = (int)(pEndCh - pCh);
- goto SequentialScan;
- }
- }
-
- return -1;
- Found3:
- pCh++;
- Found2:
- pCh++;
- Found1:
- pCh++;
- Found:
- return (int)(pCh - pChars);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveOptimization)]
- public static unsafe int LastIndexOf(ref char searchSpace, char value, int length)
- {
- Debug.Assert(length >= 0);
-
- fixed (char* pChars = &searchSpace)
- {
- char* pCh = pChars + length;
- char* pEndCh = pChars;
-
- if (Vector.IsHardwareAccelerated && length >= Vector<ushort>.Count * 2)
- {
- // Figure out how many characters to read sequentially from the end until we are vector aligned
- // This is equivalent to: length = ((int)pCh % Unsafe.SizeOf<Vector<ushort>>()) / elementsPerByte
- const int elementsPerByte = sizeof(ushort) / sizeof(byte);
- length = ((int)pCh & (Unsafe.SizeOf<Vector<ushort>>() - 1)) / elementsPerByte;
- }
-
- SequentialScan:
- while (length >= 4)
- {
- length -= 4;
- pCh -= 4;
-
- if (*(pCh + 3) == value)
- goto Found3;
- if (*(pCh + 2) == value)
- goto Found2;
- if (*(pCh + 1) == value)
- goto Found1;
- if (*pCh == value)
- goto Found;
- }
-
- while (length > 0)
- {
- length--;
- pCh--;
-
- if (*pCh == value)
- goto Found;
- }
-
- // We get past SequentialScan only if IsHardwareAccelerated is true. However, we still have the redundant check to allow
- // the JIT to see that the code is unreachable and eliminate it when the platform does not have hardware accelerated.
- if (Vector.IsHardwareAccelerated && pCh > pEndCh)
- {
- // Get the highest multiple of Vector<ushort>.Count that is within the search space.
- // That will be how many times we iterate in the loop below.
- // This is equivalent to: length = Vector<ushort>.Count * ((int)(pCh - pEndCh) / Vector<ushort>.Count)
- length = (int)((pCh - pEndCh) & ~(Vector<ushort>.Count - 1));
-
- // Get comparison Vector
- Vector<ushort> vComparison = new Vector<ushort>(value);
-
- while (length > 0)
- {
- char* pStart = pCh - Vector<ushort>.Count;
- // Using Unsafe.Read instead of ReadUnaligned since the search space is pinned and pCh (and hence pSart) is always vector aligned
- Debug.Assert(((int)pStart & (Unsafe.SizeOf<Vector<ushort>>() - 1)) == 0);
- Vector<ushort> vMatches = Vector.Equals(vComparison, Unsafe.Read<Vector<ushort>>(pStart));
- if (Vector<ushort>.Zero.Equals(vMatches))
- {
- pCh -= Vector<ushort>.Count;
- length -= Vector<ushort>.Count;
- continue;
- }
- // Find offset of last match
- return (int)(pStart - pEndCh) + LocateLastFoundChar(vMatches);
- }
-
- if (pCh > pEndCh)
- {
- length = (int)(pCh - pEndCh);
- goto SequentialScan;
- }
- }
-
- return -1;
- Found:
- return (int)(pCh - pEndCh);
- Found1:
- return (int)(pCh - pEndCh) + 1;
- Found2:
- return (int)(pCh - pEndCh) + 2;
- Found3:
- return (int)(pCh - pEndCh) + 3;
- }
- }
-
- // Vector sub-search adapted from https://github.com/aspnet/KestrelHttpServer/pull/1138
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int LocateFirstFoundChar(Vector<ushort> match)
- {
- var vector64 = Vector.AsVectorUInt64(match);
- ulong candidate = 0;
- int i = 0;
- // Pattern unrolled by jit https://github.com/dotnet/coreclr/pull/8001
- for (; i < Vector<ulong>.Count; i++)
- {
- candidate = vector64[i];
- if (candidate != 0)
- {
- break;
- }
- }
-
- // Single LEA instruction with jitted const (using function result)
- return i * 4 + LocateFirstFoundChar(candidate);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int LocateFirstFoundChar(ulong match)
- {
- // TODO: Arm variants
- if (Bmi1.X64.IsSupported)
- {
- return (int)(Bmi1.X64.TrailingZeroCount(match) >> 4);
- }
- else
- {
- unchecked
- {
- // Flag least significant power of two bit
- ulong powerOfTwoFlag = match ^ (match - 1);
- // Shift all powers of two into the high byte and extract
- return (int)((powerOfTwoFlag * XorPowerOfTwoToHighChar) >> 49);
- }
- }
- }
-
- private const ulong XorPowerOfTwoToHighChar = (0x03ul |
- 0x02ul << 16 |
- 0x01ul << 32) + 1;
-
- // Vector sub-search adapted from https://github.com/aspnet/KestrelHttpServer/pull/1138
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int LocateLastFoundChar(Vector<ushort> match)
- {
- var vector64 = Vector.AsVectorUInt64(match);
- ulong candidate = 0;
- int i = Vector<ulong>.Count - 1;
- // Pattern unrolled by jit https://github.com/dotnet/coreclr/pull/8001
- for (; i >= 0; i--)
- {
- candidate = vector64[i];
- if (candidate != 0)
- {
- break;
- }
- }
-
- // Single LEA instruction with jitted const (using function result)
- return i * 4 + LocateLastFoundChar(candidate);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int LocateLastFoundChar(ulong match)
- {
- return 3 - (BitOperations.LeadingZeroCount(match) >> 4);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static ref char Add(ref char source, nint elementOffset)
- => ref Unsafe.Add(ref source, (IntPtr)elementOffset);
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe Vector<ushort> LoadVector(ref char start, nint offset)
- => Unsafe.ReadUnaligned<Vector<ushort>>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref start, (IntPtr)offset)));
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe Vector128<ushort> LoadVector128(ref char start, nint offset)
- => Unsafe.ReadUnaligned<Vector128<ushort>>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref start, (IntPtr)offset)));
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe Vector256<ushort> LoadVector256(ref char start, nint offset)
- => Unsafe.ReadUnaligned<Vector256<ushort>>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref start, (IntPtr)offset)));
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe nint GetCharVectorSpanLength(nint offset, nint length)
- => (length - offset) & ~(Vector<ushort>.Count - 1);
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe nint GetCharVector128SpanLength(nint offset, nint length)
- => (length - offset) & ~(Vector128<ushort>.Count - 1);
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static nint GetCharVector256SpanLength(nint offset, nint length)
- => (length - offset) & ~(Vector256<ushort>.Count - 1);
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe nint UnalignedCountVector(ref char searchSpace)
- {
- const int ElementsPerByte = sizeof(ushort) / sizeof(byte);
- // Figure out how many characters to read sequentially until we are vector aligned
- // This is equivalent to:
- // unaligned = ((int)pCh % Unsafe.SizeOf<Vector<ushort>>()) / ElementsPerByte
- // length = (Vector<ushort>.Count - unaligned) % Vector<ushort>.Count
-
- // This alignment is only valid if the GC does not relocate; so we use ReadUnaligned to get the data.
- // If a GC does occur and alignment is lost, the GC cost will outweigh any gains from alignment so it
- // isn't too important to pin to maintain the alignment.
- return (nint)(uint)(-(int)Unsafe.AsPointer(ref searchSpace) / ElementsPerByte) & (Vector<ushort>.Count - 1);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static unsafe nint UnalignedCountVector128(ref char searchSpace)
- {
- const int ElementsPerByte = sizeof(ushort) / sizeof(byte);
- // This alignment is only valid if the GC does not relocate; so we use ReadUnaligned to get the data.
- // If a GC does occur and alignment is lost, the GC cost will outweigh any gains from alignment so it
- // isn't too important to pin to maintain the alignment.
- return (nint)(uint)(-(int)Unsafe.AsPointer(ref searchSpace) / ElementsPerByte) & (Vector128<ushort>.Count - 1);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/SpanHelpers.T.cs b/netcore/System.Private.CoreLib/shared/System/SpanHelpers.T.cs
deleted file mode 100644
index 5f673c793c2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/SpanHelpers.T.cs
+++ /dev/null
@@ -1,924 +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 System.Diagnostics;
-#if !NETSTANDARD2_0
-using Internal.Runtime.CompilerServices;
-#endif
-
-namespace System
-{
- internal static partial class SpanHelpers // .T
- {
- public static int IndexOf<T>(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(searchSpaceLength >= 0);
- Debug.Assert(valueLength >= 0);
-
- if (valueLength == 0)
- return 0; // A zero-length sequence is always treated as "found" at the start of the search space.
-
- T valueHead = value;
- ref T valueTail = ref Unsafe.Add(ref value, 1);
- int valueTailLength = valueLength - 1;
-
- int index = 0;
- while (true)
- {
- Debug.Assert(0 <= index && index <= searchSpaceLength); // Ensures no deceptive underflows in the computation of "remainingSearchSpaceLength".
- int remainingSearchSpaceLength = searchSpaceLength - index - valueTailLength;
- if (remainingSearchSpaceLength <= 0)
- break; // The unsearched portion is now shorter than the sequence we're looking for. So it can't be there.
-
- // Do a quick search for the first element of "value".
- int relativeIndex = IndexOf(ref Unsafe.Add(ref searchSpace, index), valueHead, remainingSearchSpaceLength);
- if (relativeIndex == -1)
- break;
- index += relativeIndex;
-
- // Found the first element of "value". See if the tail matches.
- if (SequenceEqual(ref Unsafe.Add(ref searchSpace, index + 1), ref valueTail, valueTailLength))
- return index; // The tail matched. Return a successful find.
-
- index++;
- }
- return -1;
- }
-
- // Adapted from IndexOf(...)
- public static unsafe bool Contains<T>(ref T searchSpace, T value, int length)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(length >= 0);
-
- IntPtr index = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
-
- if (default(T)! != null || (object)value != null) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- while (length >= 8)
- {
- length -= 8;
-
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 0)) ||
- value.Equals(Unsafe.Add(ref searchSpace, index + 1)) ||
- value.Equals(Unsafe.Add(ref searchSpace, index + 2)) ||
- value.Equals(Unsafe.Add(ref searchSpace, index + 3)) ||
- value.Equals(Unsafe.Add(ref searchSpace, index + 4)) ||
- value.Equals(Unsafe.Add(ref searchSpace, index + 5)) ||
- value.Equals(Unsafe.Add(ref searchSpace, index + 6)) ||
- value.Equals(Unsafe.Add(ref searchSpace, index + 7)))
- {
- goto Found;
- }
-
- index += 8;
- }
-
- if (length >= 4)
- {
- length -= 4;
-
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 0)) ||
- value.Equals(Unsafe.Add(ref searchSpace, index + 1)) ||
- value.Equals(Unsafe.Add(ref searchSpace, index + 2)) ||
- value.Equals(Unsafe.Add(ref searchSpace, index + 3)))
- {
- goto Found;
- }
-
- index += 4;
- }
-
- while (length > 0)
- {
- length--;
-
- if (value.Equals(Unsafe.Add(ref searchSpace, index)))
- goto Found;
-
- index += 1;
- }
- }
- else
- {
- byte* len = (byte*)length;
- for (index = (IntPtr)0; index.ToPointer() < len; index += 1)
- {
- if ((object)Unsafe.Add(ref searchSpace, index) is null)
- {
- goto Found;
- }
- }
- }
-
- return false;
-
- Found:
- return true;
- }
-
- public static unsafe int IndexOf<T>(ref T searchSpace, T value, int length)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(length >= 0);
-
- IntPtr index = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
- if (default(T)! != null || (object)value != null) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- while (length >= 8)
- {
- length -= 8;
-
- if (value.Equals(Unsafe.Add(ref searchSpace, index)))
- goto Found;
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 1)))
- goto Found1;
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 2)))
- goto Found2;
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 3)))
- goto Found3;
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 4)))
- goto Found4;
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 5)))
- goto Found5;
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 6)))
- goto Found6;
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 7)))
- goto Found7;
-
- index += 8;
- }
-
- if (length >= 4)
- {
- length -= 4;
-
- if (value.Equals(Unsafe.Add(ref searchSpace, index)))
- goto Found;
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 1)))
- goto Found1;
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 2)))
- goto Found2;
- if (value.Equals(Unsafe.Add(ref searchSpace, index + 3)))
- goto Found3;
-
- index += 4;
- }
-
- while (length > 0)
- {
- if (value.Equals(Unsafe.Add(ref searchSpace, index)))
- goto Found;
-
- index += 1;
- length--;
- }
- }
- else
- {
- byte* len = (byte*)length;
- for (index = (IntPtr)0; index.ToPointer() < len; index += 1)
- {
- if ((object)Unsafe.Add(ref searchSpace, index) is null)
- {
- goto Found;
- }
- }
- }
- return -1;
-
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return (int)(byte*)index;
- Found1:
- return (int)(byte*)(index + 1);
- Found2:
- return (int)(byte*)(index + 2);
- Found3:
- return (int)(byte*)(index + 3);
- Found4:
- return (int)(byte*)(index + 4);
- Found5:
- return (int)(byte*)(index + 5);
- Found6:
- return (int)(byte*)(index + 6);
- Found7:
- return (int)(byte*)(index + 7);
- }
-
- public static int IndexOfAny<T>(ref T searchSpace, T value0, T value1, int length)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(length >= 0);
-
- T lookUp;
- int index = 0;
- if (default(T)! != null || ((object)value0 != null && (object)value1 != null)) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- while ((length - index) >= 8)
- {
- lookUp = Unsafe.Add(ref searchSpace, index);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found;
- lookUp = Unsafe.Add(ref searchSpace, index + 1);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found1;
- lookUp = Unsafe.Add(ref searchSpace, index + 2);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found2;
- lookUp = Unsafe.Add(ref searchSpace, index + 3);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found3;
- lookUp = Unsafe.Add(ref searchSpace, index + 4);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found4;
- lookUp = Unsafe.Add(ref searchSpace, index + 5);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found5;
- lookUp = Unsafe.Add(ref searchSpace, index + 6);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found6;
- lookUp = Unsafe.Add(ref searchSpace, index + 7);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found7;
-
- index += 8;
- }
-
- if ((length - index) >= 4)
- {
- lookUp = Unsafe.Add(ref searchSpace, index);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found;
- lookUp = Unsafe.Add(ref searchSpace, index + 1);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found1;
- lookUp = Unsafe.Add(ref searchSpace, index + 2);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found2;
- lookUp = Unsafe.Add(ref searchSpace, index + 3);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found3;
-
- index += 4;
- }
-
- while (index < length)
- {
- lookUp = Unsafe.Add(ref searchSpace, index);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found;
-
- index++;
- }
- }
- else
- {
- for (index = 0; index < length; index++)
- {
- lookUp = Unsafe.Add(ref searchSpace, index);
- if ((object?)lookUp is null)
- {
- if ((object?)value0 is null || (object?)value1 is null)
- {
- goto Found;
- }
- }
- else if (lookUp.Equals(value0) || lookUp.Equals(value1))
- {
- goto Found;
- }
- }
- }
-
- return -1;
-
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return index;
- Found1:
- return index + 1;
- Found2:
- return index + 2;
- Found3:
- return index + 3;
- Found4:
- return index + 4;
- Found5:
- return index + 5;
- Found6:
- return index + 6;
- Found7:
- return index + 7;
- }
-
- public static int IndexOfAny<T>(ref T searchSpace, T value0, T value1, T value2, int length)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(length >= 0);
-
- T lookUp;
- int index = 0;
- if (default(T)! != null || ((object)value0 != null && (object)value1 != null && (object)value2 != null)) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- while ((length - index) >= 8)
- {
- lookUp = Unsafe.Add(ref searchSpace, index);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found;
- lookUp = Unsafe.Add(ref searchSpace, index + 1);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found1;
- lookUp = Unsafe.Add(ref searchSpace, index + 2);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found2;
- lookUp = Unsafe.Add(ref searchSpace, index + 3);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found3;
- lookUp = Unsafe.Add(ref searchSpace, index + 4);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found4;
- lookUp = Unsafe.Add(ref searchSpace, index + 5);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found5;
- lookUp = Unsafe.Add(ref searchSpace, index + 6);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found6;
- lookUp = Unsafe.Add(ref searchSpace, index + 7);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found7;
-
- index += 8;
- }
-
- if ((length - index) >= 4)
- {
- lookUp = Unsafe.Add(ref searchSpace, index);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found;
- lookUp = Unsafe.Add(ref searchSpace, index + 1);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found1;
- lookUp = Unsafe.Add(ref searchSpace, index + 2);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found2;
- lookUp = Unsafe.Add(ref searchSpace, index + 3);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found3;
-
- index += 4;
- }
-
- while (index < length)
- {
- lookUp = Unsafe.Add(ref searchSpace, index);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found;
-
- index++;
- }
- }
- else
- {
- for (index = 0; index < length; index++)
- {
- lookUp = Unsafe.Add(ref searchSpace, index);
- if ((object?)lookUp is null)
- {
- if ((object?)value0 is null || (object?)value1 is null || (object?)value2 is null)
- {
- goto Found;
- }
- }
- else if (lookUp.Equals(value0) || lookUp.Equals(value1) || lookUp.Equals(value2))
- {
- goto Found;
- }
- }
- }
- return -1;
-
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return index;
- Found1:
- return index + 1;
- Found2:
- return index + 2;
- Found3:
- return index + 3;
- Found4:
- return index + 4;
- Found5:
- return index + 5;
- Found6:
- return index + 6;
- Found7:
- return index + 7;
- }
-
- public static int IndexOfAny<T>(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(searchSpaceLength >= 0);
- Debug.Assert(valueLength >= 0);
-
- if (valueLength == 0)
- return -1; // A zero-length set of values is always treated as "not found".
-
- int index = -1;
- for (int i = 0; i < valueLength; i++)
- {
- int tempIndex = IndexOf(ref searchSpace, Unsafe.Add(ref value, i), searchSpaceLength);
- if ((uint)tempIndex < (uint)index)
- {
- index = tempIndex;
- // Reduce space for search, cause we don't care if we find the search value after the index of a previously found value
- searchSpaceLength = tempIndex;
-
- if (index == 0)
- break;
- }
- }
- return index;
- }
-
- public static int LastIndexOf<T>(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(searchSpaceLength >= 0);
- Debug.Assert(valueLength >= 0);
-
- if (valueLength == 0)
- return 0; // A zero-length sequence is always treated as "found" at the start of the search space.
-
- T valueHead = value;
- ref T valueTail = ref Unsafe.Add(ref value, 1);
- int valueTailLength = valueLength - 1;
-
- int index = 0;
- while (true)
- {
- Debug.Assert(0 <= index && index <= searchSpaceLength); // Ensures no deceptive underflows in the computation of "remainingSearchSpaceLength".
- int remainingSearchSpaceLength = searchSpaceLength - index - valueTailLength;
- if (remainingSearchSpaceLength <= 0)
- break; // The unsearched portion is now shorter than the sequence we're looking for. So it can't be there.
-
- // Do a quick search for the first element of "value".
- int relativeIndex = LastIndexOf(ref searchSpace, valueHead, remainingSearchSpaceLength);
- if (relativeIndex == -1)
- break;
-
- // Found the first element of "value". See if the tail matches.
- if (SequenceEqual(ref Unsafe.Add(ref searchSpace, relativeIndex + 1), ref valueTail, valueTailLength))
- return relativeIndex; // The tail matched. Return a successful find.
-
- index += remainingSearchSpaceLength - relativeIndex;
- }
- return -1;
- }
-
- public static int LastIndexOf<T>(ref T searchSpace, T value, int length)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(length >= 0);
-
- if (default(T)! != null || (object)value != null) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- while (length >= 8)
- {
- length -= 8;
-
- if (value.Equals(Unsafe.Add(ref searchSpace, length + 7)))
- goto Found7;
- if (value.Equals(Unsafe.Add(ref searchSpace, length + 6)))
- goto Found6;
- if (value.Equals(Unsafe.Add(ref searchSpace, length + 5)))
- goto Found5;
- if (value.Equals(Unsafe.Add(ref searchSpace, length + 4)))
- goto Found4;
- if (value.Equals(Unsafe.Add(ref searchSpace, length + 3)))
- goto Found3;
- if (value.Equals(Unsafe.Add(ref searchSpace, length + 2)))
- goto Found2;
- if (value.Equals(Unsafe.Add(ref searchSpace, length + 1)))
- goto Found1;
- if (value.Equals(Unsafe.Add(ref searchSpace, length)))
- goto Found;
- }
-
- if (length >= 4)
- {
- length -= 4;
-
- if (value.Equals(Unsafe.Add(ref searchSpace, length + 3)))
- goto Found3;
- if (value.Equals(Unsafe.Add(ref searchSpace, length + 2)))
- goto Found2;
- if (value.Equals(Unsafe.Add(ref searchSpace, length + 1)))
- goto Found1;
- if (value.Equals(Unsafe.Add(ref searchSpace, length)))
- goto Found;
- }
-
- while (length > 0)
- {
- length--;
-
- if (value.Equals(Unsafe.Add(ref searchSpace, length)))
- goto Found;
- }
- }
- else
- {
- for (length--; length >= 0; length--)
- {
- if ((object)Unsafe.Add(ref searchSpace, length) is null)
- {
- goto Found;
- }
- }
- }
-
- return -1;
-
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return length;
- Found1:
- return length + 1;
- Found2:
- return length + 2;
- Found3:
- return length + 3;
- Found4:
- return length + 4;
- Found5:
- return length + 5;
- Found6:
- return length + 6;
- Found7:
- return length + 7;
- }
-
- public static int LastIndexOfAny<T>(ref T searchSpace, T value0, T value1, int length)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(length >= 0);
-
- T lookUp;
- if (default(T)! != null || ((object)value0 != null && (object)value1 != null)) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- while (length >= 8)
- {
- length -= 8;
-
- lookUp = Unsafe.Add(ref searchSpace, length + 7);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found7;
- lookUp = Unsafe.Add(ref searchSpace, length + 6);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found6;
- lookUp = Unsafe.Add(ref searchSpace, length + 5);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found5;
- lookUp = Unsafe.Add(ref searchSpace, length + 4);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found4;
- lookUp = Unsafe.Add(ref searchSpace, length + 3);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found3;
- lookUp = Unsafe.Add(ref searchSpace, length + 2);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found2;
- lookUp = Unsafe.Add(ref searchSpace, length + 1);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found1;
- lookUp = Unsafe.Add(ref searchSpace, length);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found;
- }
-
- if (length >= 4)
- {
- length -= 4;
-
- lookUp = Unsafe.Add(ref searchSpace, length + 3);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found3;
- lookUp = Unsafe.Add(ref searchSpace, length + 2);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found2;
- lookUp = Unsafe.Add(ref searchSpace, length + 1);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found1;
- lookUp = Unsafe.Add(ref searchSpace, length);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found;
- }
-
- while (length > 0)
- {
- length--;
-
- lookUp = Unsafe.Add(ref searchSpace, length);
- if (value0.Equals(lookUp) || value1.Equals(lookUp))
- goto Found;
- }
- }
- else
- {
- for (length--; length >= 0; length--)
- {
- lookUp = Unsafe.Add(ref searchSpace, length);
- if ((object?)lookUp is null)
- {
- if ((object?)value0 is null || (object?)value1 is null)
- {
- goto Found;
- }
- }
- else if (lookUp.Equals(value0) || lookUp.Equals(value1))
- {
- goto Found;
- }
- }
- }
-
- return -1;
-
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return length;
- Found1:
- return length + 1;
- Found2:
- return length + 2;
- Found3:
- return length + 3;
- Found4:
- return length + 4;
- Found5:
- return length + 5;
- Found6:
- return length + 6;
- Found7:
- return length + 7;
- }
-
- public static int LastIndexOfAny<T>(ref T searchSpace, T value0, T value1, T value2, int length)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(length >= 0);
-
- T lookUp;
- if (default(T)! != null || ((object)value0 != null && (object)value1 != null)) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- {
- while (length >= 8)
- {
- length -= 8;
-
- lookUp = Unsafe.Add(ref searchSpace, length + 7);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found7;
- lookUp = Unsafe.Add(ref searchSpace, length + 6);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found6;
- lookUp = Unsafe.Add(ref searchSpace, length + 5);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found5;
- lookUp = Unsafe.Add(ref searchSpace, length + 4);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found4;
- lookUp = Unsafe.Add(ref searchSpace, length + 3);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found3;
- lookUp = Unsafe.Add(ref searchSpace, length + 2);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found2;
- lookUp = Unsafe.Add(ref searchSpace, length + 1);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found1;
- lookUp = Unsafe.Add(ref searchSpace, length);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found;
- }
-
- if (length >= 4)
- {
- length -= 4;
-
- lookUp = Unsafe.Add(ref searchSpace, length + 3);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found3;
- lookUp = Unsafe.Add(ref searchSpace, length + 2);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found2;
- lookUp = Unsafe.Add(ref searchSpace, length + 1);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found1;
- lookUp = Unsafe.Add(ref searchSpace, length);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found;
- }
-
- while (length > 0)
- {
- length--;
-
- lookUp = Unsafe.Add(ref searchSpace, length);
- if (value0.Equals(lookUp) || value1.Equals(lookUp) || value2.Equals(lookUp))
- goto Found;
- }
- }
- else
- {
- for (length--; length >= 0; length--)
- {
- lookUp = Unsafe.Add(ref searchSpace, length);
- if ((object?)lookUp is null)
- {
- if ((object?)value0 is null || (object?)value1 is null || (object?)value2 is null)
- {
- goto Found;
- }
- }
- else if (lookUp.Equals(value0) || lookUp.Equals(value1) || lookUp.Equals(value2))
- {
- goto Found;
- }
- }
- }
-
- return -1;
-
- Found: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return length;
- Found1:
- return length + 1;
- Found2:
- return length + 2;
- Found3:
- return length + 3;
- Found4:
- return length + 4;
- Found5:
- return length + 5;
- Found6:
- return length + 6;
- Found7:
- return length + 7;
- }
-
- public static int LastIndexOfAny<T>(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(searchSpaceLength >= 0);
- Debug.Assert(valueLength >= 0);
-
- if (valueLength == 0)
- return -1; // A zero-length set of values is always treated as "not found".
-
- int index = -1;
- for (int i = 0; i < valueLength; i++)
- {
- int tempIndex = LastIndexOf(ref searchSpace, Unsafe.Add(ref value, i), searchSpaceLength);
- if (tempIndex > index)
- index = tempIndex;
- }
- return index;
- }
-
- public static bool SequenceEqual<T>(ref T first, ref T second, int length)
-#nullable disable // to enable use with both T and T? for reference types due to IEquatable<T> being invariant
- where T : IEquatable<T>
-#nullable restore
- {
- Debug.Assert(length >= 0);
-
- if (Unsafe.AreSame(ref first, ref second))
- goto Equal;
-
- IntPtr index = (IntPtr)0; // Use IntPtr for arithmetic to avoid unnecessary 64->32->64 truncations
- T lookUp0;
- T lookUp1;
- while (length >= 8)
- {
- length -= 8;
-
- lookUp0 = Unsafe.Add(ref first, index);
- lookUp1 = Unsafe.Add(ref second, index);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
- lookUp0 = Unsafe.Add(ref first, index + 1);
- lookUp1 = Unsafe.Add(ref second, index + 1);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
- lookUp0 = Unsafe.Add(ref first, index + 2);
- lookUp1 = Unsafe.Add(ref second, index + 2);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
- lookUp0 = Unsafe.Add(ref first, index + 3);
- lookUp1 = Unsafe.Add(ref second, index + 3);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
- lookUp0 = Unsafe.Add(ref first, index + 4);
- lookUp1 = Unsafe.Add(ref second, index + 4);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
- lookUp0 = Unsafe.Add(ref first, index + 5);
- lookUp1 = Unsafe.Add(ref second, index + 5);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
- lookUp0 = Unsafe.Add(ref first, index + 6);
- lookUp1 = Unsafe.Add(ref second, index + 6);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
- lookUp0 = Unsafe.Add(ref first, index + 7);
- lookUp1 = Unsafe.Add(ref second, index + 7);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
-
- index += 8;
- }
-
- if (length >= 4)
- {
- length -= 4;
-
- lookUp0 = Unsafe.Add(ref first, index);
- lookUp1 = Unsafe.Add(ref second, index);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
- lookUp0 = Unsafe.Add(ref first, index + 1);
- lookUp1 = Unsafe.Add(ref second, index + 1);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
- lookUp0 = Unsafe.Add(ref first, index + 2);
- lookUp1 = Unsafe.Add(ref second, index + 2);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
- lookUp0 = Unsafe.Add(ref first, index + 3);
- lookUp1 = Unsafe.Add(ref second, index + 3);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
-
- index += 4;
- }
-
- while (length > 0)
- {
- lookUp0 = Unsafe.Add(ref first, index);
- lookUp1 = Unsafe.Add(ref second, index);
- if (!(lookUp0?.Equals(lookUp1) ?? (object?)lookUp1 is null))
- goto NotEqual;
- index += 1;
- length--;
- }
-
- Equal:
- return true;
-
- NotEqual: // Workaround for https://github.com/dotnet/coreclr/issues/13549
- return false;
- }
-
- public static int SequenceCompareTo<T>(ref T first, int firstLength, ref T second, int secondLength)
- where T : IComparable<T>
- {
- Debug.Assert(firstLength >= 0);
- Debug.Assert(secondLength >= 0);
-
- int minLength = firstLength;
- if (minLength > secondLength)
- minLength = secondLength;
- for (int i = 0; i < minLength; i++)
- {
- T lookUp = Unsafe.Add(ref second, i);
- int result = (Unsafe.Add(ref first, i)?.CompareTo(lookUp) ?? (((object?)lookUp is null) ? 0 : -1));
- if (result != 0)
- return result;
- }
- return firstLength.CompareTo(secondLength);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/SpanHelpers.cs b/netcore/System.Private.CoreLib/shared/System/SpanHelpers.cs
deleted file mode 100644
index d558758f634..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/SpanHelpers.cs
+++ /dev/null
@@ -1,417 +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 System.Diagnostics;
-using System.Runtime;
-
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- internal static partial class SpanHelpers
- {
- public static unsafe void ClearWithoutReferences(ref byte b, nuint byteLength)
- {
- if (byteLength == 0)
- return;
-
-#if AMD64 || ARM64
- // The exact matrix on when ZeroMemory is faster than InitBlockUnaligned is very complex. The factors to consider include
- // type of hardware and memory aligment. This threshold was chosen as a good balance accross different configurations.
- if (byteLength > 768)
- goto PInvoke;
- Unsafe.InitBlockUnaligned(ref b, 0, (uint)byteLength);
- return;
-#else
- // TODO: Optimize other platforms to be on par with AMD64 CoreCLR
- // Note: It's important that this switch handles lengths at least up to 22.
- // See notes below near the main loop for why.
-
- // The switch will be very fast since it can be implemented using a jump
- // table in assembly. See http://stackoverflow.com/a/449297/4077294 for more info.
-
- switch (byteLength)
- {
- case 1:
- b = 0;
- return;
- case 2:
- Unsafe.As<byte, short>(ref b) = 0;
- return;
- case 3:
- Unsafe.As<byte, short>(ref b) = 0;
- Unsafe.Add<byte>(ref b, 2) = 0;
- return;
- case 4:
- Unsafe.As<byte, int>(ref b) = 0;
- return;
- case 5:
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.Add<byte>(ref b, 4) = 0;
- return;
- case 6:
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, short>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
- return;
- case 7:
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, short>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
- Unsafe.Add<byte>(ref b, 6) = 0;
- return;
- case 8:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
-#endif
- return;
- case 9:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
-#endif
- Unsafe.Add<byte>(ref b, 8) = 0;
- return;
- case 10:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
-#endif
- Unsafe.As<byte, short>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- return;
- case 11:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
-#endif
- Unsafe.As<byte, short>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- Unsafe.Add<byte>(ref b, 10) = 0;
- return;
- case 12:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
-#endif
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- return;
- case 13:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
-#endif
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- Unsafe.Add<byte>(ref b, 12) = 0;
- return;
- case 14:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
-#endif
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- Unsafe.As<byte, short>(ref Unsafe.Add<byte>(ref b, 12)) = 0;
- return;
- case 15:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
-#endif
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- Unsafe.As<byte, short>(ref Unsafe.Add<byte>(ref b, 12)) = 0;
- Unsafe.Add<byte>(ref b, 14) = 0;
- return;
- case 16:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
- Unsafe.As<byte, long>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 12)) = 0;
-#endif
- return;
- case 17:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
- Unsafe.As<byte, long>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 12)) = 0;
-#endif
- Unsafe.Add<byte>(ref b, 16) = 0;
- return;
- case 18:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
- Unsafe.As<byte, long>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 12)) = 0;
-#endif
- Unsafe.As<byte, short>(ref Unsafe.Add<byte>(ref b, 16)) = 0;
- return;
- case 19:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
- Unsafe.As<byte, long>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 12)) = 0;
-#endif
- Unsafe.As<byte, short>(ref Unsafe.Add<byte>(ref b, 16)) = 0;
- Unsafe.Add<byte>(ref b, 18) = 0;
- return;
- case 20:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
- Unsafe.As<byte, long>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 12)) = 0;
-#endif
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 16)) = 0;
- return;
- case 21:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
- Unsafe.As<byte, long>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 12)) = 0;
-#endif
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 16)) = 0;
- Unsafe.Add<byte>(ref b, 20) = 0;
- return;
- case 22:
-#if BIT64
- Unsafe.As<byte, long>(ref b) = 0;
- Unsafe.As<byte, long>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
-#else
- Unsafe.As<byte, int>(ref b) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 4)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 8)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 12)) = 0;
-#endif
- Unsafe.As<byte, int>(ref Unsafe.Add<byte>(ref b, 16)) = 0;
- Unsafe.As<byte, short>(ref Unsafe.Add<byte>(ref b, 20)) = 0;
- return;
- }
-
- // P/Invoke into the native version for large lengths
- if (byteLength >= 512) goto PInvoke;
-
- nuint i = 0; // byte offset at which we're copying
-
- if (((nuint)Unsafe.AsPointer(ref b) & 3) != 0)
- {
- if (((nuint)Unsafe.AsPointer(ref b) & 1) != 0)
- {
- b = 0;
- i += 1;
- if (((nuint)Unsafe.AsPointer(ref b) & 2) != 0)
- goto IntAligned;
- }
- Unsafe.As<byte, short>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
- i += 2;
- }
-
- IntAligned:
-
- // On 64-bit IntPtr.Size == 8, so we want to advance to the next 8-aligned address. If
- // (int)b % 8 is 0, 5, 6, or 7, we will already have advanced by 0, 3, 2, or 1
- // bytes to the next aligned address (respectively), so do nothing. On the other hand,
- // if it is 1, 2, 3, or 4 we will want to copy-and-advance another 4 bytes until
- // we're aligned.
- // The thing 1, 2, 3, and 4 have in common that the others don't is that if you
- // subtract one from them, their 3rd lsb will not be set. Hence, the below check.
-
- if ((((nuint)Unsafe.AsPointer(ref b) - 1) & 4) == 0)
- {
- Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
- i += 4;
- }
-
- nuint end = byteLength - 16;
- byteLength -= i; // lower 4 bits of byteLength represent how many bytes are left *after* the unrolled loop
-
- // We know due to the above switch-case that this loop will always run 1 iteration; max
- // bytes we clear before checking is 23 (7 to align the pointers, 16 for 1 iteration) so
- // the switch handles lengths 0-22.
- Debug.Assert(end >= 7 && i <= end);
-
- // This is separated out into a different variable, so the i + 16 addition can be
- // performed at the start of the pipeline and the loop condition does not have
- // a dependency on the writes.
- nuint counter;
-
- do
- {
- counter = i + 16;
-
- // This loop looks very costly since there appear to be a bunch of temporary values
- // being created with the adds, but the jit (for x86 anyways) will convert each of
- // these to use memory addressing operands.
-
- // So the only cost is a bit of code size, which is made up for by the fact that
- // we save on writes to b.
-
-#if BIT64
- Unsafe.As<byte, long>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
- Unsafe.As<byte, long>(ref Unsafe.AddByteOffset<byte>(ref b, i + 8)) = 0;
-#else
- Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i + 4)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i + 8)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i + 12)) = 0;
-#endif
-
- i = counter;
-
- // See notes above for why this wasn't used instead
- // i += 16;
- }
- while (counter <= end);
-
- if ((byteLength & 8) != 0)
- {
-#if BIT64
- Unsafe.As<byte, long>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
-#else
- Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
- Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i + 4)) = 0;
-#endif
- i += 8;
- }
- if ((byteLength & 4) != 0)
- {
- Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
- i += 4;
- }
- if ((byteLength & 2) != 0)
- {
- Unsafe.As<byte, short>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
- i += 2;
- }
- if ((byteLength & 1) != 0)
- {
- Unsafe.AddByteOffset<byte>(ref b, i) = 0;
- // We're not using i after this, so not needed
- // i += 1;
- }
-
- return;
-#endif
-
- PInvoke:
- Buffer._ZeroMemory(ref b, byteLength);
- }
-
- public static unsafe void ClearWithReferences(ref IntPtr ip, nuint pointerSizeLength)
- {
- Debug.Assert((int)Unsafe.AsPointer(ref ip) % sizeof(IntPtr) == 0, "Should've been aligned on natural word boundary.");
-
- // First write backward 8 natural words at a time.
- // Writing backward allows us to get away with only simple modifications to the
- // mov instruction's base and index registers between loop iterations.
-
- for (; pointerSizeLength >= 8; pointerSizeLength -= 8)
- {
- Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -1) = default;
- Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -2) = default;
- Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -3) = default;
- Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -4) = default;
- Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -5) = default;
- Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -6) = default;
- Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -7) = default;
- Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -8) = default;
- }
-
- Debug.Assert(pointerSizeLength <= 7);
-
- // The logic below works by trying to minimize the number of branches taken for any
- // given range of lengths. For example, the lengths [ 4 .. 7 ] are handled by a single
- // branch, [ 2 .. 3 ] are handled by a single branch, and [ 1 ] is handled by a single
- // branch.
- //
- // We can write both forward and backward as a perf improvement. For example,
- // the lengths [ 4 .. 7 ] can be handled by zeroing out the first four natural
- // words and the last 3 natural words. In the best case (length = 7), there are
- // no overlapping writes. In the worst case (length = 4), there are three
- // overlapping writes near the middle of the buffer. In perf testing, the
- // penalty for performing duplicate writes is less expensive than the penalty
- // for complex branching.
-
- if (pointerSizeLength >= 4)
- {
- goto Write4To7;
- }
- else if (pointerSizeLength >= 2)
- {
- goto Write2To3;
- }
- else if (pointerSizeLength > 0)
- {
- goto Write1;
- }
- else
- {
- return; // nothing to write
- }
-
- Write4To7:
- Debug.Assert(pointerSizeLength >= 4);
-
- // Write first four and last three.
- Unsafe.Add(ref ip, 2) = default;
- Unsafe.Add(ref ip, 3) = default;
- Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -3) = default;
- Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -2) = default;
-
- Write2To3:
- Debug.Assert(pointerSizeLength >= 2);
-
- // Write first two and last one.
- Unsafe.Add(ref ip, 1) = default;
- Unsafe.Add(ref Unsafe.Add(ref ip, (IntPtr)pointerSizeLength), -1) = default;
-
- Write1:
- Debug.Assert(pointerSizeLength >= 1);
-
- // Write only element.
- ip = default;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/StackOverflowException.cs b/netcore/System.Private.CoreLib/shared/System/StackOverflowException.cs
deleted file mode 100644
index a1dd460ab58..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/StackOverflowException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: The exception class for stack overflow.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class StackOverflowException : SystemException
- {
- public StackOverflowException()
- : base(SR.Arg_StackOverflowException)
- {
- HResult = HResults.COR_E_STACKOVERFLOW;
- }
-
- public StackOverflowException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_STACKOVERFLOW;
- }
-
- public StackOverflowException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_STACKOVERFLOW;
- }
-
- private StackOverflowException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/String.Comparison.cs b/netcore/System.Private.CoreLib/shared/System/String.Comparison.cs
deleted file mode 100644
index 3db93fdfc74..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/String.Comparison.cs
+++ /dev/null
@@ -1,933 +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 System.Diagnostics;
-using System.Globalization;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- public partial class String
- {
- //
- // Search/Query methods
- //
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool EqualsHelper(string strA, string strB)
- {
- Debug.Assert(strA != null);
- Debug.Assert(strB != null);
- Debug.Assert(strA.Length == strB.Length);
-
- return SpanHelpers.SequenceEqual(
- ref Unsafe.As<char, byte>(ref strA.GetRawStringData()),
- ref Unsafe.As<char, byte>(ref strB.GetRawStringData()),
- ((nuint)strA.Length) * 2);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int CompareOrdinalHelper(string strA, int indexA, int countA, string strB, int indexB, int countB)
- {
- Debug.Assert(strA != null);
- Debug.Assert(strB != null);
- Debug.Assert(indexA >= 0 && indexB >= 0);
- Debug.Assert(countA >= 0 && countB >= 0);
- Debug.Assert(indexA + countA <= strA.Length && indexB + countB <= strB.Length);
-
- return SpanHelpers.SequenceCompareTo(ref Unsafe.Add(ref strA.GetRawStringData(), indexA), countA, ref Unsafe.Add(ref strB.GetRawStringData(), indexB), countB);
- }
-
- private static bool EqualsOrdinalIgnoreCase(string strA, string strB)
- {
- Debug.Assert(strA.Length == strB.Length);
-
- return CompareInfo.EqualsOrdinalIgnoreCase(ref strA.GetRawStringData(), ref strB.GetRawStringData(), strB.Length);
- }
- private static unsafe int CompareOrdinalHelper(string strA, string strB)
- {
- Debug.Assert(strA != null);
- Debug.Assert(strB != null);
-
- // NOTE: This may be subject to change if eliminating the check
- // in the callers makes them small enough to be inlined
- Debug.Assert(strA._firstChar == strB._firstChar,
- "For performance reasons, callers of this method should " +
- "check/short-circuit beforehand if the first char is the same.");
-
- int length = Math.Min(strA.Length, strB.Length);
-
- fixed (char* ap = &strA._firstChar) fixed (char* bp = &strB._firstChar)
- {
- char* a = ap;
- char* b = bp;
-
- // Check if the second chars are different here
- // The reason we check if _firstChar is different is because
- // it's the most common case and allows us to avoid a method call
- // to here.
- // The reason we check if the second char is different is because
- // if the first two chars the same we can increment by 4 bytes,
- // leaving us word-aligned on both 32-bit (12 bytes into the string)
- // and 64-bit (16 bytes) platforms.
-
- // For empty strings, the second char will be null due to padding.
- // The start of the string is the type pointer + string length, which
- // takes up 8 bytes on 32-bit, 12 on x64. For empty strings the null
- // terminator immediately follows, leaving us with an object
- // 10/14 bytes in size. Since everything needs to be a multiple
- // of 4/8, this will get padded and zeroed out.
-
- // For one-char strings the second char will be the null terminator.
-
- // NOTE: If in the future there is a way to read the second char
- // without pinning the string (e.g. System.Runtime.CompilerServices.Unsafe
- // is exposed to mscorlib, or a future version of C# allows inline IL),
- // then do that and short-circuit before the fixed.
-
- if (*(a + 1) != *(b + 1)) goto DiffOffset1;
-
- // Since we know that the first two chars are the same,
- // we can increment by 2 here and skip 4 bytes.
- // This leaves us 8-byte aligned, which results
- // on better perf for 64-bit platforms.
- length -= 2; a += 2; b += 2;
-
- // unroll the loop
-#if BIT64
- while (length >= 12)
- {
- if (*(long*)a != *(long*)b) goto DiffOffset0;
- if (*(long*)(a + 4) != *(long*)(b + 4)) goto DiffOffset4;
- if (*(long*)(a + 8) != *(long*)(b + 8)) goto DiffOffset8;
- length -= 12; a += 12; b += 12;
- }
-#else // BIT64
- while (length >= 10)
- {
- if (*(int*)a != *(int*)b) goto DiffOffset0;
- if (*(int*)(a + 2) != *(int*)(b + 2)) goto DiffOffset2;
- if (*(int*)(a + 4) != *(int*)(b + 4)) goto DiffOffset4;
- if (*(int*)(a + 6) != *(int*)(b + 6)) goto DiffOffset6;
- if (*(int*)(a + 8) != *(int*)(b + 8)) goto DiffOffset8;
- length -= 10; a += 10; b += 10;
- }
-#endif // BIT64
-
- // Fallback loop:
- // go back to slower code path and do comparison on 4 bytes at a time.
- // This depends on the fact that the String objects are
- // always zero terminated and that the terminating zero is not included
- // in the length. For odd string sizes, the last compare will include
- // the zero terminator.
- while (length > 0)
- {
- if (*(int*)a != *(int*)b) goto DiffNextInt;
- length -= 2;
- a += 2;
- b += 2;
- }
-
- // At this point, we have compared all the characters in at least one string.
- // The longer string will be larger.
- return strA.Length - strB.Length;
-
-#if BIT64
- DiffOffset8: a += 4; b += 4;
- DiffOffset4: a += 4; b += 4;
-#else // BIT64
- // Use jumps instead of falling through, since
- // otherwise going to DiffOffset8 will involve
- // 8 add instructions before getting to DiffNextInt
- DiffOffset8: a += 8; b += 8; goto DiffOffset0;
- DiffOffset6: a += 6; b += 6; goto DiffOffset0;
- DiffOffset4: a += 2; b += 2;
- DiffOffset2: a += 2; b += 2;
-#endif // BIT64
-
- DiffOffset0:
- // If we reached here, we already see a difference in the unrolled loop above
-#if BIT64
- if (*(int*)a == *(int*)b)
- {
- a += 2; b += 2;
- }
-#endif // BIT64
-
- DiffNextInt:
- if (*a != *b) return *a - *b;
-
- DiffOffset1:
- Debug.Assert(*(a + 1) != *(b + 1), "This char must be different if we reach here!");
- return *(a + 1) - *(b + 1);
- }
- }
-
- // Provides a culture-correct string comparison. StrA is compared to StrB
- // to determine whether it is lexicographically less, equal, or greater, and then returns
- // either a negative integer, 0, or a positive integer; respectively.
- //
- public static int Compare(string? strA, string? strB)
- {
- return Compare(strA, strB, StringComparison.CurrentCulture);
- }
-
- // Provides a culture-correct string comparison. strA is compared to strB
- // to determine whether it is lexicographically less, equal, or greater, and then a
- // negative integer, 0, or a positive integer is returned; respectively.
- // The case-sensitive option is set by ignoreCase
- //
- public static int Compare(string? strA, string? strB, bool ignoreCase)
- {
- StringComparison comparisonType = ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture;
- return Compare(strA, strB, comparisonType);
- }
-
- // Provides a more flexible function for string comparison. See StringComparison
- // for meaning of different comparisonType.
- public static int Compare(string? strA, string? strB, StringComparison comparisonType)
- {
- if (object.ReferenceEquals(strA, strB))
- {
- CheckStringComparison(comparisonType);
- return 0;
- }
-
- // They can't both be null at this point.
- if (strA == null)
- {
- CheckStringComparison(comparisonType);
- return -1;
- }
- if (strB == null)
- {
- CheckStringComparison(comparisonType);
- return 1;
- }
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.Compare(strA, strB, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.Ordinal:
- // Most common case: first character is different.
- // Returns false for empty strings.
- if (strA._firstChar != strB._firstChar)
- {
- return strA._firstChar - strB._firstChar;
- }
-
- return CompareOrdinalHelper(strA, strB);
-
- case StringComparison.OrdinalIgnoreCase:
- return CompareInfo.CompareOrdinalIgnoreCase(strA, strB);
-
- default:
- throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType));
- }
- }
-
- // Provides a culture-correct string comparison. strA is compared to strB
- // to determine whether it is lexicographically less, equal, or greater, and then a
- // negative integer, 0, or a positive integer is returned; respectively.
- //
- public static int Compare(string? strA, string? strB, CultureInfo? culture, CompareOptions options)
- {
- CultureInfo compareCulture = culture ?? CultureInfo.CurrentCulture;
- return compareCulture.CompareInfo.Compare(strA, strB, options);
- }
-
- // Provides a culture-correct string comparison. strA is compared to strB
- // to determine whether it is lexicographically less, equal, or greater, and then a
- // negative integer, 0, or a positive integer is returned; respectively.
- // The case-sensitive option is set by ignoreCase, and the culture is set
- // by culture
- //
- public static int Compare(string? strA, string? strB, bool ignoreCase, CultureInfo? culture)
- {
- CompareOptions options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None;
- return Compare(strA, strB, culture, options);
- }
-
- // Determines whether two string regions match. The substring of strA beginning
- // at indexA of given length is compared with the substring of strB
- // beginning at indexB of the same length.
- //
- public static int Compare(string? strA, int indexA, string? strB, int indexB, int length)
- {
- // NOTE: It's important we call the boolean overload, and not the StringComparison
- // one. The two have some subtly different behavior (see notes in the former).
- return Compare(strA, indexA, strB, indexB, length, ignoreCase: false);
- }
-
- // Determines whether two string regions match. The substring of strA beginning
- // at indexA of given length is compared with the substring of strB
- // beginning at indexB of the same length. Case sensitivity is determined by the ignoreCase boolean.
- //
- public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, bool ignoreCase)
- {
- // Ideally we would just forward to the string.Compare overload that takes
- // a StringComparison parameter, and just pass in CurrentCulture/CurrentCultureIgnoreCase.
- // That function will return early if an optimization can be applied, e.g. if
- // (object)strA == strB && indexA == indexB then it will return 0 straightaway.
- // There are a couple of subtle behavior differences that prevent us from doing so
- // however:
- // - string.Compare(null, -1, null, -1, -1, StringComparison.CurrentCulture) works
- // since that method also returns early for nulls before validation. It shouldn't
- // for this overload.
- // - Since we originally forwarded to CompareInfo.Compare for all of the argument
- // validation logic, the ArgumentOutOfRangeExceptions thrown will contain different
- // parameter names.
- // Therefore, we have to duplicate some of the logic here.
-
- int lengthA = length;
- int lengthB = length;
-
- if (strA != null)
- {
- lengthA = Math.Min(lengthA, strA.Length - indexA);
- }
-
- if (strB != null)
- {
- lengthB = Math.Min(lengthB, strB.Length - indexB);
- }
-
- CompareOptions options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None;
- return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, options);
- }
-
- // Determines whether two string regions match. The substring of strA beginning
- // at indexA of length length is compared with the substring of strB
- // beginning at indexB of the same length. Case sensitivity is determined by the ignoreCase boolean,
- // and the culture is set by culture.
- //
- public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, bool ignoreCase, CultureInfo? culture)
- {
- CompareOptions options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None;
- return Compare(strA, indexA, strB, indexB, length, culture, options);
- }
-
- // Determines whether two string regions match. The substring of strA beginning
- // at indexA of length length is compared with the substring of strB
- // beginning at indexB of the same length.
- //
- public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, CultureInfo? culture, CompareOptions options)
- {
- CultureInfo compareCulture = culture ?? CultureInfo.CurrentCulture;
- int lengthA = length;
- int lengthB = length;
-
- if (strA != null)
- {
- lengthA = Math.Min(lengthA, strA.Length - indexA);
- }
-
- if (strB != null)
- {
- lengthB = Math.Min(lengthB, strB.Length - indexB);
- }
-
- return compareCulture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, options);
- }
-
- public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, StringComparison comparisonType)
- {
- CheckStringComparison(comparisonType);
-
- if (strA == null || strB == null)
- {
- if (object.ReferenceEquals(strA, strB))
- {
- // They're both null
- return 0;
- }
-
- return strA == null ? -1 : 1;
- }
-
- if (length < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NegativeLength);
- }
-
- if (indexA < 0 || indexB < 0)
- {
- string paramName = indexA < 0 ? nameof(indexA) : nameof(indexB);
- throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_Index);
- }
-
- if (strA.Length - indexA < 0 || strB.Length - indexB < 0)
- {
- string paramName = strA.Length - indexA < 0 ? nameof(indexA) : nameof(indexB);
- throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_Index);
- }
-
- if (length == 0 || (object.ReferenceEquals(strA, strB) && indexA == indexB))
- {
- return 0;
- }
-
- int lengthA = Math.Min(length, strA.Length - indexA);
- int lengthB = Math.Min(length, strB.Length - indexB);
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.Compare(strA, indexA, lengthA, strB, indexB, lengthB, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.Ordinal:
- return CompareOrdinalHelper(strA, indexA, lengthA, strB, indexB, lengthB);
-
- default:
- Debug.Assert(comparisonType == StringComparison.OrdinalIgnoreCase); // CheckStringComparison validated these earlier
- return CompareInfo.CompareOrdinalIgnoreCase(strA, indexA, lengthA, strB, indexB, lengthB);
- }
- }
-
- // Compares strA and strB using an ordinal (code-point) comparison.
- //
- public static int CompareOrdinal(string? strA, string? strB)
- {
- if (object.ReferenceEquals(strA, strB))
- {
- return 0;
- }
-
- // They can't both be null at this point.
- if (strA == null)
- {
- return -1;
- }
- if (strB == null)
- {
- return 1;
- }
-
- // Most common case, first character is different.
- // This will return false for empty strings.
- if (strA._firstChar != strB._firstChar)
- {
- return strA._firstChar - strB._firstChar;
- }
-
- return CompareOrdinalHelper(strA, strB);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static int CompareOrdinal(ReadOnlySpan<char> strA, ReadOnlySpan<char> strB)
- => SpanHelpers.SequenceCompareTo(ref MemoryMarshal.GetReference(strA), strA.Length, ref MemoryMarshal.GetReference(strB), strB.Length);
-
- // Compares strA and strB using an ordinal (code-point) comparison.
- //
- public static int CompareOrdinal(string? strA, int indexA, string? strB, int indexB, int length)
- {
- if (strA == null || strB == null)
- {
- if (object.ReferenceEquals(strA, strB))
- {
- // They're both null
- return 0;
- }
-
- return strA == null ? -1 : 1;
- }
-
- // COMPAT: Checking for nulls should become before the arguments are validated,
- // but other optimizations which allow us to return early should come after.
-
- if (length < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NegativeCount);
- }
-
- if (indexA < 0 || indexB < 0)
- {
- string paramName = indexA < 0 ? nameof(indexA) : nameof(indexB);
- throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_Index);
- }
-
- int lengthA = Math.Min(length, strA.Length - indexA);
- int lengthB = Math.Min(length, strB.Length - indexB);
-
- if (lengthA < 0 || lengthB < 0)
- {
- string paramName = lengthA < 0 ? nameof(indexA) : nameof(indexB);
- throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_Index);
- }
-
- if (length == 0 || (object.ReferenceEquals(strA, strB) && indexA == indexB))
- {
- return 0;
- }
-
- return CompareOrdinalHelper(strA, indexA, lengthA, strB, indexB, lengthB);
- }
-
- // Compares this String to another String (cast as object), returning an integer that
- // indicates the relationship. This method returns a value less than 0 if this is less than value, 0
- // if this is equal to value, or a value greater than 0 if this is greater than value.
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
-
- if (!(value is string other))
- {
- throw new ArgumentException(SR.Arg_MustBeString);
- }
-
- return CompareTo(other); // will call the string-based overload
- }
-
- // Determines the sorting relation of StrB to the current instance.
- //
- public int CompareTo(string? strB)
- {
- return string.Compare(this, strB, StringComparison.CurrentCulture);
- }
-
- // Determines whether a specified string is a suffix of the current instance.
- //
- // The case-sensitive and culture-sensitive option is set by options,
- // and the default culture is used.
- //
- public bool EndsWith(string value)
- {
- return EndsWith(value, StringComparison.CurrentCulture);
- }
-
- public bool EndsWith(string value, StringComparison comparisonType)
- {
- if ((object)value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- if ((object)this == (object)value)
- {
- CheckStringComparison(comparisonType);
- return true;
- }
-
- if (value.Length == 0)
- {
- CheckStringComparison(comparisonType);
- return true;
- }
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.IsSuffix(this, value, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.IsSuffix(this, value, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.Ordinal:
- int offset = this.Length - value.Length;
- return (uint)offset <= (uint)this.Length && this.AsSpan(offset).SequenceEqual(value);
-
- case StringComparison.OrdinalIgnoreCase:
- return this.Length < value.Length ? false : (CompareInfo.CompareOrdinalIgnoreCase(this, this.Length - value.Length, value.Length, value, 0, value.Length) == 0);
-
- default:
- throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType));
- }
- }
-
- public bool EndsWith(string value, bool ignoreCase, CultureInfo? culture)
- {
- if (null == value)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- if ((object)this == (object)value)
- {
- return true;
- }
-
- CultureInfo referenceCulture = culture ?? CultureInfo.CurrentCulture;
- return referenceCulture.CompareInfo.IsSuffix(this, value, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
- }
-
- public bool EndsWith(char value)
- {
- int lastPos = Length - 1;
- return ((uint)lastPos < (uint)Length) && this[lastPos] == value;
- }
-
- // Determines whether two strings match.
- public override bool Equals(object? obj)
- {
- if (object.ReferenceEquals(this, obj))
- return true;
-
- if (!(obj is string str))
- return false;
-
- if (this.Length != str.Length)
- return false;
-
- return EqualsHelper(this, str);
- }
-
- // Determines whether two strings match.
- public bool Equals(string? value)
- {
- if (object.ReferenceEquals(this, value))
- return true;
-
- // NOTE: No need to worry about casting to object here.
- // If either side of an == comparison between strings
- // is null, Roslyn generates a simple ceq instruction
- // instead of calling string.op_Equality.
- if (value == null)
- return false;
-
- if (this.Length != value.Length)
- return false;
-
- return EqualsHelper(this, value);
- }
-
- public bool Equals(string? value, StringComparison comparisonType)
- {
- if (object.ReferenceEquals(this, value))
- {
- CheckStringComparison(comparisonType);
- return true;
- }
-
- if (value is null)
- {
- CheckStringComparison(comparisonType);
- return false;
- }
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.Compare(this, value, GetCaseCompareOfComparisonCulture(comparisonType)) == 0;
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.Compare(this, value, GetCaseCompareOfComparisonCulture(comparisonType)) == 0;
-
- case StringComparison.Ordinal:
- if (this.Length != value.Length)
- return false;
- return EqualsHelper(this, value);
-
- case StringComparison.OrdinalIgnoreCase:
- if (this.Length != value.Length)
- return false;
-
- return EqualsOrdinalIgnoreCase(this, value);
-
- default:
- throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType));
- }
- }
-
- // Determines whether two Strings match.
- public static bool Equals(string? a, string? b)
- {
- if (object.ReferenceEquals(a, b))
- {
- return true;
- }
-
- if (a is null || b is null || a.Length != b.Length)
- {
- return false;
- }
-
- return EqualsHelper(a, b);
- }
-
- public static bool Equals(string? a, string? b, StringComparison comparisonType)
- {
- if (object.ReferenceEquals(a, b))
- {
- CheckStringComparison(comparisonType);
- return true;
- }
-
- if (a is null || b is null)
- {
- CheckStringComparison(comparisonType);
- return false;
- }
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.Compare(a, b, GetCaseCompareOfComparisonCulture(comparisonType)) == 0;
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.Compare(a, b, GetCaseCompareOfComparisonCulture(comparisonType)) == 0;
-
- case StringComparison.Ordinal:
- if (a.Length != b.Length)
- return false;
- return EqualsHelper(a, b);
-
- case StringComparison.OrdinalIgnoreCase:
- if (a.Length != b.Length)
- return false;
-
- return EqualsOrdinalIgnoreCase(a, b);
-
- default:
- throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType));
- }
- }
-
- public static bool operator ==(string? a, string? b) => string.Equals(a, b);
-
- public static bool operator !=(string? a, string? b) => !string.Equals(a, b);
-
- // Gets a hash code for this string. If strings A and B are such that A.Equals(B), then
- // they will return the same hash code.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public override int GetHashCode()
- {
- ulong seed = Marvin.DefaultSeed;
-
- // Multiplication below will not overflow since going from positive Int32 to UInt32.
- return Marvin.ComputeHash32(ref Unsafe.As<char, byte>(ref _firstChar), (uint)_stringLength * 2 /* in bytes, not chars */, (uint)seed, (uint)(seed >> 32));
- }
-
- // Gets a hash code for this string and this comparison. If strings A and B and comparison C are such
- // that string.Equals(A, B, C), then they will return the same hash code with this comparison C.
- public int GetHashCode(StringComparison comparisonType) => StringComparer.FromComparison(comparisonType).GetHashCode(this);
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal int GetHashCodeOrdinalIgnoreCase()
- {
- ulong seed = Marvin.DefaultSeed;
- return Marvin.ComputeHash32OrdinalIgnoreCase(ref _firstChar, _stringLength /* in chars, not bytes */, (uint)seed, (uint)(seed >> 32));
- }
-
- // A span-based equivalent of String.GetHashCode(). Computes an ordinal hash code.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int GetHashCode(ReadOnlySpan<char> value)
- {
- ulong seed = Marvin.DefaultSeed;
-
- // Multiplication below will not overflow since going from positive Int32 to UInt32.
- return Marvin.ComputeHash32(ref Unsafe.As<char, byte>(ref MemoryMarshal.GetReference(value)), (uint)value.Length * 2 /* in bytes, not chars */, (uint)seed, (uint)(seed >> 32));
- }
-
- // A span-based equivalent of String.GetHashCode(StringComparison). Uses the specified comparison type.
- public static int GetHashCode(ReadOnlySpan<char> value, StringComparison comparisonType)
- {
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.GetHashCode(value, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CultureInfo.InvariantCulture.CompareInfo.GetHashCode(value, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.Ordinal:
- return GetHashCode(value);
-
- case StringComparison.OrdinalIgnoreCase:
- return GetHashCodeOrdinalIgnoreCase(value);
-
- default:
- ThrowHelper.ThrowArgumentException(ExceptionResource.NotSupported_StringComparison, ExceptionArgument.comparisonType);
- Debug.Fail("Should not reach this point.");
- return default;
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static int GetHashCodeOrdinalIgnoreCase(ReadOnlySpan<char> value)
- {
- ulong seed = Marvin.DefaultSeed;
- return Marvin.ComputeHash32OrdinalIgnoreCase(ref MemoryMarshal.GetReference(value), value.Length /* in chars, not bytes */, (uint)seed, (uint)(seed >> 32));
- }
-
- // Use this if and only if 'Denial of Service' attacks are not a concern (i.e. never used for free-form user input),
- // or are otherwise mitigated
- internal unsafe int GetNonRandomizedHashCode()
- {
- fixed (char* src = &_firstChar)
- {
- Debug.Assert(src[this.Length] == '\0', "src[this.Length] == '\\0'");
- Debug.Assert(((int)src) % 4 == 0, "Managed string should start at 4 bytes boundary");
-
- uint hash1 = (5381 << 16) + 5381;
- uint hash2 = hash1;
-
- uint* ptr = (uint*)src;
- int length = this.Length;
-
- while (length > 2)
- {
- length -= 4;
- // Where length is 4n-1 (e.g. 3,7,11,15,19) this additionally consumes the null terminator
- hash1 = (BitOperations.RotateLeft(hash1, 5) + hash1) ^ ptr[0];
- hash2 = (BitOperations.RotateLeft(hash2, 5) + hash2) ^ ptr[1];
- ptr += 2;
- }
-
- if (length > 0)
- {
- // Where length is 4n-3 (e.g. 1,5,9,13,17) this additionally consumes the null terminator
- hash2 = (BitOperations.RotateLeft(hash2, 5) + hash2) ^ ptr[0];
- }
-
- return (int)(hash1 + (hash2 * 1566083941));
- }
- }
-
- // Determines whether a specified string is a prefix of the current instance
- //
- public bool StartsWith(string value)
- {
- if (value is null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- return StartsWith(value, StringComparison.CurrentCulture);
- }
-
- public bool StartsWith(string value, StringComparison comparisonType)
- {
- if (value is null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- if ((object)this == (object)value)
- {
- CheckStringComparison(comparisonType);
- return true;
- }
-
- if (value.Length == 0)
- {
- CheckStringComparison(comparisonType);
- return true;
- }
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.IsPrefix(this, value, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.IsPrefix(this, value, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.Ordinal:
- if (this.Length < value.Length || _firstChar != value._firstChar)
- {
- return false;
- }
- return (value.Length == 1) ?
- true : // First char is the same and thats all there is to compare
- SpanHelpers.SequenceEqual(
- ref Unsafe.As<char, byte>(ref this.GetRawStringData()),
- ref Unsafe.As<char, byte>(ref value.GetRawStringData()),
- ((nuint)value.Length) * 2);
-
- case StringComparison.OrdinalIgnoreCase:
- if (this.Length < value.Length)
- {
- return false;
- }
- return CompareInfo.EqualsOrdinalIgnoreCase(ref this.GetRawStringData(), ref value.GetRawStringData(), value.Length);
-
- default:
- throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType));
- }
- }
-
- public bool StartsWith(string value, bool ignoreCase, CultureInfo? culture)
- {
- if (null == value)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- if ((object)this == (object)value)
- {
- return true;
- }
-
- CultureInfo referenceCulture = culture ?? CultureInfo.CurrentCulture;
- return referenceCulture.CompareInfo.IsPrefix(this, value, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
- }
-
- public bool StartsWith(char value) => Length != 0 && _firstChar == value;
-
- internal static void CheckStringComparison(StringComparison comparisonType)
- {
- // Single comparison to check if comparisonType is within [CurrentCulture .. OrdinalIgnoreCase]
- if ((uint)comparisonType > (uint)StringComparison.OrdinalIgnoreCase)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.NotSupported_StringComparison, ExceptionArgument.comparisonType);
- }
- }
-
- internal static CompareOptions GetCaseCompareOfComparisonCulture(StringComparison comparisonType)
- {
- Debug.Assert((uint)comparisonType <= (uint)StringComparison.OrdinalIgnoreCase);
-
- // Culture enums can be & with CompareOptions.IgnoreCase 0x01 to extract if IgnoreCase or CompareOptions.None 0x00
- //
- // CompareOptions.None 0x00
- // CompareOptions.IgnoreCase 0x01
- //
- // StringComparison.CurrentCulture: 0x00
- // StringComparison.InvariantCulture: 0x02
- // StringComparison.Ordinal 0x04
- //
- // StringComparison.CurrentCultureIgnoreCase: 0x01
- // StringComparison.InvariantCultureIgnoreCase: 0x03
- // StringComparison.OrdinalIgnoreCase 0x05
-
- return (CompareOptions)((int)comparisonType & (int)CompareOptions.IgnoreCase);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/String.Manipulation.cs b/netcore/System.Private.CoreLib/shared/System/String.Manipulation.cs
deleted file mode 100644
index 4d703da082e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/String.Manipulation.cs
+++ /dev/null
@@ -1,1875 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.Text;
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- public partial class String
- {
- private const int StackallocIntBufferSizeLimit = 128;
-
- private static unsafe void FillStringChecked(string dest, int destPos, string src)
- {
- Debug.Assert(dest != null);
- Debug.Assert(src != null);
- if (src.Length > dest.Length - destPos)
- {
- throw new IndexOutOfRangeException();
- }
-
- fixed (char* pDest = &dest._firstChar)
- fixed (char* pSrc = &src._firstChar)
- {
- wstrcpy(pDest + destPos, pSrc, src.Length);
- }
- }
-
- public static string Concat(object? arg0) => arg0?.ToString() ?? string.Empty;
-
- public static string Concat(object? arg0, object? arg1)
- {
- if (arg0 == null)
- {
- arg0 = string.Empty;
- }
-
- if (arg1 == null)
- {
- arg1 = string.Empty;
- }
- return Concat(arg0.ToString(), arg1.ToString());
- }
-
- public static string Concat(object? arg0, object? arg1, object? arg2)
- {
- if (arg0 == null)
- {
- arg0 = string.Empty;
- }
-
- if (arg1 == null)
- {
- arg1 = string.Empty;
- }
-
- if (arg2 == null)
- {
- arg2 = string.Empty;
- }
-
- return Concat(arg0.ToString(), arg1.ToString(), arg2.ToString());
- }
-
- public static string Concat(params object?[] args)
- {
- if (args == null)
- {
- throw new ArgumentNullException(nameof(args));
- }
-
- if (args.Length <= 1)
- {
- return args.Length == 0 ?
- string.Empty :
- args[0]?.ToString() ?? string.Empty;
- }
-
- // We need to get an intermediary string array
- // to fill with each of the args' ToString(),
- // and then just concat that in one operation.
-
- // This way we avoid any intermediary string representations,
- // or buffer resizing if we use StringBuilder (although the
- // latter case is partially alleviated due to StringBuilder's
- // linked-list style implementation)
-
- var strings = new string[args.Length];
-
- int totalLength = 0;
-
- for (int i = 0; i < args.Length; i++)
- {
- object? value = args[i];
-
- string toString = value?.ToString() ?? string.Empty; // We need to handle both the cases when value or value.ToString() is null
- strings[i] = toString;
-
- totalLength += toString.Length;
-
- if (totalLength < 0) // Check for a positive overflow
- {
- throw new OutOfMemoryException();
- }
- }
-
- // If all of the ToStrings are null/empty, just return string.Empty
- if (totalLength == 0)
- {
- return string.Empty;
- }
-
- string result = FastAllocateString(totalLength);
- int position = 0; // How many characters we've copied so far
-
- for (int i = 0; i < strings.Length; i++)
- {
- string s = strings[i];
-
- Debug.Assert(s != null);
- Debug.Assert(position <= totalLength - s.Length, "We didn't allocate enough space for the result string!");
-
- FillStringChecked(result, position, s);
- position += s.Length;
- }
-
- return result;
- }
-
- public static string Concat<T>(IEnumerable<T> values)
- {
- if (values == null)
- throw new ArgumentNullException(nameof(values));
-
- if (typeof(T) == typeof(char))
- {
- // Special-case T==char, as we can handle that case much more efficiently,
- // and string.Concat(IEnumerable<char>) can be used as an efficient
- // enumerable-based equivalent of new string(char[]).
- using (IEnumerator<char> en = Unsafe.As<IEnumerable<char>>(values).GetEnumerator())
- {
- if (!en.MoveNext())
- {
- // There weren't any chars. Return the empty string.
- return Empty;
- }
-
- char c = en.Current; // save the first char
-
- if (!en.MoveNext())
- {
- // There was only one char. Return a string from it directly.
- return CreateFromChar(c);
- }
-
- // Create the StringBuilder, add the chars we've already enumerated,
- // add the rest, and then get the resulting string.
- var result = new ValueStringBuilder(stackalloc char[256]);
- result.Append(c); // first value
- do
- {
- c = en.Current;
- result.Append(c);
- }
- while (en.MoveNext());
- return result.ToString();
- }
- }
- else
- {
- using (IEnumerator<T> en = values.GetEnumerator())
- {
- if (!en.MoveNext())
- return string.Empty;
-
- // We called MoveNext once, so this will be the first item
- T currentValue = en.Current;
-
- // Call ToString before calling MoveNext again, since
- // we want to stay consistent with the below loop
- // Everything should be called in the order
- // MoveNext-Current-ToString, unless further optimizations
- // can be made, to avoid breaking changes
- string? firstString = currentValue?.ToString();
-
- // If there's only 1 item, simply call ToString on that
- if (!en.MoveNext())
- {
- // We have to handle the case of either currentValue
- // or its ToString being null
- return firstString ?? string.Empty;
- }
-
- var result = new ValueStringBuilder(stackalloc char[256]);
-
- result.Append(firstString);
-
- do
- {
- currentValue = en.Current;
-
- if (currentValue != null)
- {
- result.Append(currentValue.ToString());
- }
- }
- while (en.MoveNext());
-
- return result.ToString();
- }
- }
- }
-
- public static string Concat(IEnumerable<string?> values)
- {
- if (values == null)
- throw new ArgumentNullException(nameof(values));
-
- using (IEnumerator<string?> en = values.GetEnumerator())
- {
- if (!en.MoveNext())
- return string.Empty;
-
- string? firstValue = en.Current;
-
- if (!en.MoveNext())
- {
- return firstValue ?? string.Empty;
- }
-
- var result = new ValueStringBuilder(stackalloc char[256]);
-
- result.Append(firstValue);
-
- do
- {
- result.Append(en.Current);
- }
- while (en.MoveNext());
-
- return result.ToString();
- }
- }
-
- public static string Concat(string? str0, string? str1)
- {
- if (IsNullOrEmpty(str0))
- {
- if (IsNullOrEmpty(str1))
- {
- return string.Empty;
- }
- return str1;
- }
-
- if (IsNullOrEmpty(str1))
- {
- return str0;
- }
-
- int str0Length = str0.Length;
-
- string result = FastAllocateString(str0Length + str1.Length);
-
- FillStringChecked(result, 0, str0);
- FillStringChecked(result, str0Length, str1);
-
- return result;
- }
-
- public static string Concat(string? str0, string? str1, string? str2)
- {
- if (IsNullOrEmpty(str0))
- {
- return Concat(str1, str2);
- }
-
- if (IsNullOrEmpty(str1))
- {
- return Concat(str0, str2);
- }
-
- if (IsNullOrEmpty(str2))
- {
- return Concat(str0, str1);
- }
-
- int totalLength = str0.Length + str1.Length + str2.Length;
-
- string result = FastAllocateString(totalLength);
- FillStringChecked(result, 0, str0);
- FillStringChecked(result, str0.Length, str1);
- FillStringChecked(result, str0.Length + str1.Length, str2);
-
- return result;
- }
-
- public static string Concat(string? str0, string? str1, string? str2, string? str3)
- {
- if (IsNullOrEmpty(str0))
- {
- return Concat(str1, str2, str3);
- }
-
- if (IsNullOrEmpty(str1))
- {
- return Concat(str0, str2, str3);
- }
-
- if (IsNullOrEmpty(str2))
- {
- return Concat(str0, str1, str3);
- }
-
- if (IsNullOrEmpty(str3))
- {
- return Concat(str0, str1, str2);
- }
-
- int totalLength = str0.Length + str1.Length + str2.Length + str3.Length;
-
- string result = FastAllocateString(totalLength);
- FillStringChecked(result, 0, str0);
- FillStringChecked(result, str0.Length, str1);
- FillStringChecked(result, str0.Length + str1.Length, str2);
- FillStringChecked(result, str0.Length + str1.Length + str2.Length, str3);
-
- return result;
- }
-
- public static string Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1)
- {
- int length = checked(str0.Length + str1.Length);
- if (length == 0)
- {
- return Empty;
- }
-
- string result = FastAllocateString(length);
- Span<char> resultSpan = new Span<char>(ref result.GetRawStringData(), result.Length);
-
- str0.CopyTo(resultSpan);
- str1.CopyTo(resultSpan.Slice(str0.Length));
-
- return result;
- }
-
- public static string Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2)
- {
- int length = checked(str0.Length + str1.Length + str2.Length);
- if (length == 0)
- {
- return Empty;
- }
-
- string result = FastAllocateString(length);
- Span<char> resultSpan = new Span<char>(ref result.GetRawStringData(), result.Length);
-
- str0.CopyTo(resultSpan);
- resultSpan = resultSpan.Slice(str0.Length);
-
- str1.CopyTo(resultSpan);
- resultSpan = resultSpan.Slice(str1.Length);
-
- str2.CopyTo(resultSpan);
-
- return result;
- }
-
- public static string Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2, ReadOnlySpan<char> str3)
- {
- int length = checked(str0.Length + str1.Length + str2.Length + str3.Length);
- if (length == 0)
- {
- return Empty;
- }
-
- string result = FastAllocateString(length);
- Span<char> resultSpan = new Span<char>(ref result.GetRawStringData(), result.Length);
-
- str0.CopyTo(resultSpan);
- resultSpan = resultSpan.Slice(str0.Length);
-
- str1.CopyTo(resultSpan);
- resultSpan = resultSpan.Slice(str1.Length);
-
- str2.CopyTo(resultSpan);
- resultSpan = resultSpan.Slice(str2.Length);
-
- str3.CopyTo(resultSpan);
-
- return result;
- }
-
- public static string Concat(params string?[] values)
- {
- if (values == null)
- throw new ArgumentNullException(nameof(values));
-
- if (values.Length <= 1)
- {
- return values.Length == 0 ?
- string.Empty :
- values[0] ?? string.Empty;
- }
-
- // It's possible that the input values array could be changed concurrently on another
- // thread, such that we can't trust that each read of values[i] will be equivalent.
- // Worst case, we can make a defensive copy of the array and use that, but we first
- // optimistically try the allocation and copies assuming that the array isn't changing,
- // which represents the 99.999% case, in particular since string.Concat is used for
- // string concatenation by the languages, with the input array being a params array.
-
- // Sum the lengths of all input strings
- long totalLengthLong = 0;
- for (int i = 0; i < values.Length; i++)
- {
- string? value = values[i];
- if (value != null)
- {
- totalLengthLong += value.Length;
- }
- }
-
- // If it's too long, fail, or if it's empty, return an empty string.
- if (totalLengthLong > int.MaxValue)
- {
- throw new OutOfMemoryException();
- }
- int totalLength = (int)totalLengthLong;
- if (totalLength == 0)
- {
- return string.Empty;
- }
-
- // Allocate a new string and copy each input string into it
- string result = FastAllocateString(totalLength);
- int copiedLength = 0;
- for (int i = 0; i < values.Length; i++)
- {
- string? value = values[i];
- if (!string.IsNullOrEmpty(value))
- {
- int valueLen = value.Length;
- if (valueLen > totalLength - copiedLength)
- {
- copiedLength = -1;
- break;
- }
-
- FillStringChecked(result, copiedLength, value);
- copiedLength += valueLen;
- }
- }
-
- // If we copied exactly the right amount, return the new string. Otherwise,
- // something changed concurrently to mutate the input array: fall back to
- // doing the concatenation again, but this time with a defensive copy. This
- // fall back should be extremely rare.
- return copiedLength == totalLength ? result : Concat((string?[])values.Clone());
- }
-
- public static string Format(string format, object? arg0)
- {
- return FormatHelper(null, format, new ParamsArray(arg0));
- }
-
- public static string Format(string format, object? arg0, object? arg1)
- {
- return FormatHelper(null, format, new ParamsArray(arg0, arg1));
- }
-
- public static string Format(string format, object? arg0, object? arg1, object? arg2)
- {
- return FormatHelper(null, format, new ParamsArray(arg0, arg1, arg2));
- }
-
- public static string Format(string format, params object?[] args)
- {
- if (args == null)
- {
- // To preserve the original exception behavior, throw an exception about format if both
- // args and format are null. The actual null check for format is in FormatHelper.
- throw new ArgumentNullException((format == null) ? nameof(format) : nameof(args));
- }
-
- return FormatHelper(null, format, new ParamsArray(args));
- }
-
- public static string Format(IFormatProvider? provider, string format, object? arg0)
- {
- return FormatHelper(provider, format, new ParamsArray(arg0));
- }
-
- public static string Format(IFormatProvider? provider, string format, object? arg0, object? arg1)
- {
- return FormatHelper(provider, format, new ParamsArray(arg0, arg1));
- }
-
- public static string Format(IFormatProvider? provider, string format, object? arg0, object? arg1, object? arg2)
- {
- return FormatHelper(provider, format, new ParamsArray(arg0, arg1, arg2));
- }
-
- public static string Format(IFormatProvider? provider, string format, params object?[] args)
- {
- if (args == null)
- {
- // To preserve the original exception behavior, throw an exception about format if both
- // args and format are null. The actual null check for format is in FormatHelper.
- throw new ArgumentNullException((format == null) ? nameof(format) : nameof(args));
- }
-
- return FormatHelper(provider, format, new ParamsArray(args));
- }
-
- private static string FormatHelper(IFormatProvider? provider, string format, ParamsArray args)
- {
- if (format == null)
- throw new ArgumentNullException(nameof(format));
-
- var sb = new ValueStringBuilder(stackalloc char[256]);
- sb.EnsureCapacity(format.Length + args.Length * 8);
- sb.AppendFormatHelper(provider, format, args);
- return sb.ToString();
- }
-
- public string Insert(int startIndex, string value)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
- if (startIndex < 0 || startIndex > this.Length)
- throw new ArgumentOutOfRangeException(nameof(startIndex));
-
- int oldLength = Length;
- int insertLength = value.Length;
-
- if (oldLength == 0)
- return value;
- if (insertLength == 0)
- return this;
-
- // In case this computation overflows, newLength will be negative and FastAllocateString throws OutOfMemoryException
- int newLength = oldLength + insertLength;
- string result = FastAllocateString(newLength);
- unsafe
- {
- fixed (char* srcThis = &_firstChar)
- {
- fixed (char* srcInsert = &value._firstChar)
- {
- fixed (char* dst = &result._firstChar)
- {
- wstrcpy(dst, srcThis, startIndex);
- wstrcpy(dst + startIndex, srcInsert, insertLength);
- wstrcpy(dst + startIndex + insertLength, srcThis + startIndex, oldLength - startIndex);
- }
- }
- }
- }
- return result;
- }
-
- public static string Join(char separator, params string?[] value)
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- return Join(separator, value, 0, value.Length);
- }
-
- public static unsafe string Join(char separator, params object?[] values)
- {
- // Defer argument validation to the internal function
- return JoinCore(&separator, 1, values);
- }
-
- public static unsafe string Join<T>(char separator, IEnumerable<T> values)
- {
- // Defer argument validation to the internal function
- return JoinCore(&separator, 1, values);
- }
-
- public static unsafe string Join(char separator, string?[] value, int startIndex, int count)
- {
- // Defer argument validation to the internal function
- return JoinCore(&separator, 1, value, startIndex, count);
- }
-
- // Joins an array of strings together as one string with a separator between each original string.
- //
- public static string Join(string? separator, params string?[] value)
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- return Join(separator, value, 0, value.Length);
- }
-
- public static unsafe string Join(string? separator, params object?[] values)
- {
- separator ??= string.Empty;
- fixed (char* pSeparator = &separator._firstChar)
- {
- // Defer argument validation to the internal function
- return JoinCore(pSeparator, separator.Length, values);
- }
- }
-
- public static unsafe string Join<T>(string? separator, IEnumerable<T> values)
- {
- separator ??= string.Empty;
- fixed (char* pSeparator = &separator._firstChar)
- {
- // Defer argument validation to the internal function
- return JoinCore(pSeparator, separator.Length, values);
- }
- }
-
- public static string Join(string? separator, IEnumerable<string?> values)
- {
- if (values == null)
- {
- throw new ArgumentNullException(nameof(values));
- }
-
- using (IEnumerator<string?> en = values.GetEnumerator())
- {
- if (!en.MoveNext())
- {
- return string.Empty;
- }
-
- string? firstValue = en.Current;
-
- if (!en.MoveNext())
- {
- // Only one value available
- return firstValue ?? string.Empty;
- }
-
- // Null separator and values are handled by the StringBuilder
- var result = new ValueStringBuilder(stackalloc char[256]);
-
- result.Append(firstValue);
-
- do
- {
- result.Append(separator);
- result.Append(en.Current);
- }
- while (en.MoveNext());
-
- return result.ToString();
- }
- }
-
- // Joins an array of strings together as one string with a separator between each original string.
- //
- public static unsafe string Join(string? separator, string?[] value, int startIndex, int count)
- {
- separator ??= Empty;
- fixed (char* pSeparator = &separator._firstChar)
- {
- // Defer argument validation to the internal function
- return JoinCore(pSeparator, separator.Length, value, startIndex, count);
- }
- }
-
- private static unsafe string JoinCore(char* separator, int separatorLength, object?[] values)
- {
- if (values == null)
- {
- throw new ArgumentNullException(nameof(values));
- }
-
- if (values.Length == 0)
- {
- return string.Empty;
- }
-
- string? firstString = values[0]?.ToString();
-
- if (values.Length == 1)
- {
- return firstString ?? string.Empty;
- }
-
- var result = new ValueStringBuilder(stackalloc char[256]);
-
- result.Append(firstString);
-
- for (int i = 1; i < values.Length; i++)
- {
- result.Append(separator, separatorLength);
- object? value = values[i];
- if (value != null)
- {
- result.Append(value.ToString());
- }
- }
-
- return result.ToString();
- }
-
- private static unsafe string JoinCore<T>(char* separator, int separatorLength, IEnumerable<T> values)
- {
- if (values == null)
- {
- throw new ArgumentNullException(nameof(values));
- }
-
- using (IEnumerator<T> en = values.GetEnumerator())
- {
- if (!en.MoveNext())
- {
- return string.Empty;
- }
-
- // We called MoveNext once, so this will be the first item
- T currentValue = en.Current;
-
- // Call ToString before calling MoveNext again, since
- // we want to stay consistent with the below loop
- // Everything should be called in the order
- // MoveNext-Current-ToString, unless further optimizations
- // can be made, to avoid breaking changes
- string? firstString = currentValue?.ToString();
-
- // If there's only 1 item, simply call ToString on that
- if (!en.MoveNext())
- {
- // We have to handle the case of either currentValue
- // or its ToString being null
- return firstString ?? string.Empty;
- }
-
- var result = new ValueStringBuilder(stackalloc char[256]);
-
- result.Append(firstString);
-
- do
- {
- currentValue = en.Current;
-
- result.Append(separator, separatorLength);
- if (currentValue != null)
- {
- result.Append(currentValue.ToString());
- }
- }
- while (en.MoveNext());
-
- return result.ToString();
- }
- }
-
- private static unsafe string JoinCore(char* separator, int separatorLength, string?[] value, int startIndex, int count)
- {
- // If the separator is null, it is converted to an empty string before entering this function.
- // Even for empty strings, fixed should never return null (it should return a pointer to a null char).
- Debug.Assert(separator != null);
- Debug.Assert(separatorLength >= 0);
-
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if (startIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NegativeCount);
- }
- if (startIndex > value.Length - count)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_IndexCountBuffer);
- }
-
- if (count <= 1)
- {
- return count == 0 ?
- string.Empty :
- value[startIndex] ?? string.Empty;
- }
-
- long totalSeparatorsLength = (long)(count - 1) * separatorLength;
- if (totalSeparatorsLength > int.MaxValue)
- {
- throw new OutOfMemoryException();
- }
- int totalLength = (int)totalSeparatorsLength;
-
- // Calculate the length of the resultant string so we know how much space to allocate.
- for (int i = startIndex, end = startIndex + count; i < end; i++)
- {
- string? currentValue = value[i];
- if (currentValue != null)
- {
- totalLength += currentValue.Length;
- if (totalLength < 0) // Check for overflow
- {
- throw new OutOfMemoryException();
- }
- }
- }
-
- // Copy each of the strings into the resultant buffer, interleaving with the separator.
- string result = FastAllocateString(totalLength);
- int copiedLength = 0;
-
- for (int i = startIndex, end = startIndex + count; i < end; i++)
- {
- // It's possible that another thread may have mutated the input array
- // such that our second read of an index will not be the same string
- // we got during the first read.
-
- // We range check again to avoid buffer overflows if this happens.
-
- string? currentValue = value[i];
- if (currentValue != null)
- {
- int valueLen = currentValue.Length;
- if (valueLen > totalLength - copiedLength)
- {
- copiedLength = -1;
- break;
- }
-
- // Fill in the value.
- FillStringChecked(result, copiedLength, currentValue);
- copiedLength += valueLen;
- }
-
- if (i < end - 1)
- {
- // Fill in the separator.
- fixed (char* pResult = &result._firstChar)
- {
- // If we are called from the char-based overload, we will not
- // want to call MemoryCopy each time we fill in the separator. So
- // specialize for 1-length separators.
- if (separatorLength == 1)
- {
- pResult[copiedLength] = *separator;
- }
- else
- {
- wstrcpy(pResult + copiedLength, separator, separatorLength);
- }
- }
- copiedLength += separatorLength;
- }
- }
-
- // If we copied exactly the right amount, return the new string. Otherwise,
- // something changed concurrently to mutate the input array: fall back to
- // doing the concatenation again, but this time with a defensive copy. This
- // fall back should be extremely rare.
- return copiedLength == totalLength ?
- result :
- JoinCore(separator, separatorLength, (string?[])value.Clone(), startIndex, count);
- }
-
- public string PadLeft(int totalWidth) => PadLeft(totalWidth, ' ');
-
- public string PadLeft(int totalWidth, char paddingChar)
- {
- if (totalWidth < 0)
- throw new ArgumentOutOfRangeException(nameof(totalWidth), SR.ArgumentOutOfRange_NeedNonNegNum);
- int oldLength = Length;
- int count = totalWidth - oldLength;
- if (count <= 0)
- return this;
- string result = FastAllocateString(totalWidth);
- unsafe
- {
- fixed (char* dst = &result._firstChar)
- {
- for (int i = 0; i < count; i++)
- dst[i] = paddingChar;
- fixed (char* src = &_firstChar)
- {
- wstrcpy(dst + count, src, oldLength);
- }
- }
- }
- return result;
- }
-
- public string PadRight(int totalWidth) => PadRight(totalWidth, ' ');
-
- public string PadRight(int totalWidth, char paddingChar)
- {
- if (totalWidth < 0)
- throw new ArgumentOutOfRangeException(nameof(totalWidth), SR.ArgumentOutOfRange_NeedNonNegNum);
- int oldLength = Length;
- int count = totalWidth - oldLength;
- if (count <= 0)
- return this;
- string result = FastAllocateString(totalWidth);
- unsafe
- {
- fixed (char* dst = &result._firstChar)
- {
- fixed (char* src = &_firstChar)
- {
- wstrcpy(dst, src, oldLength);
- }
- for (int i = 0; i < count; i++)
- dst[oldLength + i] = paddingChar;
- }
- }
- return result;
- }
-
- public string Remove(int startIndex, int count)
- {
- if (startIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NegativeCount);
- int oldLength = this.Length;
- if (count > oldLength - startIndex)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_IndexCount);
-
- if (count == 0)
- return this;
- int newLength = oldLength - count;
- if (newLength == 0)
- return string.Empty;
-
- string result = FastAllocateString(newLength);
- unsafe
- {
- fixed (char* src = &_firstChar)
- {
- fixed (char* dst = &result._firstChar)
- {
- wstrcpy(dst, src, startIndex);
- wstrcpy(dst + startIndex, src + startIndex + count, newLength - startIndex);
- }
- }
- }
- return result;
- }
-
- // a remove that just takes a startindex.
- public string Remove(int startIndex)
- {
- if (startIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
-
- if (startIndex >= Length)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndexLessThanLength);
-
- return Substring(0, startIndex);
- }
-
- public string Replace(string oldValue, string? newValue, bool ignoreCase, CultureInfo? culture)
- {
- return ReplaceCore(oldValue, newValue, culture, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
- }
-
- public string Replace(string oldValue, string? newValue, StringComparison comparisonType)
- {
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return ReplaceCore(oldValue, newValue, CultureInfo.CurrentCulture, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return ReplaceCore(oldValue, newValue, CultureInfo.InvariantCulture, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.Ordinal:
- return Replace(oldValue, newValue);
-
- case StringComparison.OrdinalIgnoreCase:
- return ReplaceCore(oldValue, newValue, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase);
-
- default:
- throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType));
- }
- }
-
- private unsafe string ReplaceCore(string oldValue, string? newValue, CultureInfo? culture, CompareOptions options)
- {
- if (oldValue == null)
- throw new ArgumentNullException(nameof(oldValue));
- if (oldValue.Length == 0)
- throw new ArgumentException(SR.Argument_StringZeroLength, nameof(oldValue));
-
- // If they asked to replace oldValue with a null, replace all occurrences
- // with the empty string.
- newValue ??= string.Empty;
-
- CultureInfo referenceCulture = culture ?? CultureInfo.CurrentCulture;
- var result = new ValueStringBuilder(stackalloc char[256]);
- result.EnsureCapacity(this.Length);
-
- int startIndex = 0;
- int index = 0;
-
- int matchLength = 0;
-
- bool hasDoneAnyReplacements = false;
- CompareInfo ci = referenceCulture.CompareInfo;
-
- do
- {
- index = ci.IndexOf(this, oldValue, startIndex, this.Length - startIndex, options, &matchLength);
- if (index >= 0)
- {
- // append the unmodified portion of string
- result.Append(this.AsSpan(startIndex, index - startIndex));
-
- // append the replacement
- result.Append(newValue);
-
- startIndex = index + matchLength;
- hasDoneAnyReplacements = true;
- }
- else if (!hasDoneAnyReplacements)
- {
- // small optimization,
- // if we have not done any replacements,
- // we will return the original string
- result.Dispose();
- return this;
- }
- else
- {
- result.Append(this.AsSpan(startIndex, this.Length - startIndex));
- }
- } while (index >= 0);
-
- return result.ToString();
- }
-
- // Replaces all instances of oldChar with newChar.
- //
- public string Replace(char oldChar, char newChar)
- {
- if (oldChar == newChar)
- return this;
-
- unsafe
- {
- int remainingLength = Length;
-
- fixed (char* pChars = &_firstChar)
- {
- char* pSrc = pChars;
-
- while (remainingLength > 0)
- {
- if (*pSrc == oldChar)
- {
- break;
- }
-
- remainingLength--;
- pSrc++;
- }
- }
-
- if (remainingLength == 0)
- return this;
-
- string result = FastAllocateString(Length);
-
- fixed (char* pChars = &_firstChar)
- {
- fixed (char* pResult = &result._firstChar)
- {
- int copyLength = Length - remainingLength;
-
- // Copy the characters already proven not to match.
- if (copyLength > 0)
- {
- wstrcpy(pResult, pChars, copyLength);
- }
-
- // Copy the remaining characters, doing the replacement as we go.
- char* pSrc = pChars + copyLength;
- char* pDst = pResult + copyLength;
-
- do
- {
- char currentChar = *pSrc;
- if (currentChar == oldChar)
- currentChar = newChar;
- *pDst = currentChar;
-
- remainingLength--;
- pSrc++;
- pDst++;
- } while (remainingLength > 0);
- }
- }
-
- return result;
- }
- }
-
- public string Replace(string oldValue, string? newValue)
- {
- if (oldValue == null)
- throw new ArgumentNullException(nameof(oldValue));
- if (oldValue.Length == 0)
- throw new ArgumentException(SR.Argument_StringZeroLength, nameof(oldValue));
-
- // Api behavior: if newValue is null, instances of oldValue are to be removed.
- newValue ??= string.Empty;
-
- var replacementIndices = new ValueListBuilder<int>(stackalloc int[StackallocIntBufferSizeLimit]);
-
- unsafe
- {
- fixed (char* pThis = &_firstChar)
- {
- int matchIdx = 0;
- int lastPossibleMatchIdx = this.Length - oldValue.Length;
- while (matchIdx <= lastPossibleMatchIdx)
- {
- char* pMatch = pThis + matchIdx;
- for (int probeIdx = 0; probeIdx < oldValue.Length; probeIdx++)
- {
- if (pMatch[probeIdx] != oldValue[probeIdx])
- {
- goto Next;
- }
- }
- // Found a match for the string. Record the location of the match and skip over the "oldValue."
- replacementIndices.Append(matchIdx);
- matchIdx += oldValue.Length;
- continue;
-
- Next:
- matchIdx++;
- }
- }
- }
-
- if (replacementIndices.Length == 0)
- return this;
-
- // String allocation and copying is in separate method to make this method faster for the case where
- // nothing needs replacing.
- string dst = ReplaceHelper(oldValue.Length, newValue, replacementIndices.AsSpan());
-
- replacementIndices.Dispose();
-
- return dst;
- }
-
- private string ReplaceHelper(int oldValueLength, string newValue, ReadOnlySpan<int> indices)
- {
- Debug.Assert(indices.Length > 0);
-
- long dstLength = this.Length + ((long)(newValue.Length - oldValueLength)) * indices.Length;
- if (dstLength > int.MaxValue)
- throw new OutOfMemoryException();
- string dst = FastAllocateString((int)dstLength);
-
- Span<char> dstSpan = new Span<char>(ref dst.GetRawStringData(), dst.Length);
-
- int thisIdx = 0;
- int dstIdx = 0;
-
- for (int r = 0; r < indices.Length; r++)
- {
- int replacementIdx = indices[r];
-
- // Copy over the non-matching portion of the original that precedes this occurrence of oldValue.
- int count = replacementIdx - thisIdx;
- if (count != 0)
- {
- this.AsSpan(thisIdx, count).CopyTo(dstSpan.Slice(dstIdx));
- dstIdx += count;
- }
- thisIdx = replacementIdx + oldValueLength;
-
- // Copy over newValue to replace the oldValue.
- newValue.AsSpan().CopyTo(dstSpan.Slice(dstIdx));
- dstIdx += newValue.Length;
- }
-
- // Copy over the final non-matching portion at the end of the string.
- Debug.Assert(this.Length - thisIdx == dstSpan.Length - dstIdx);
- this.AsSpan(thisIdx).CopyTo(dstSpan.Slice(dstIdx));
-
- return dst;
- }
-
- public string[] Split(char separator, StringSplitOptions options = StringSplitOptions.None)
- {
- return SplitInternal(new ReadOnlySpan<char>(ref separator, 1), int.MaxValue, options);
- }
-
- public string[] Split(char separator, int count, StringSplitOptions options = StringSplitOptions.None)
- {
- return SplitInternal(new ReadOnlySpan<char>(ref separator, 1), count, options);
- }
-
- // Creates an array of strings by splitting this string at each
- // occurrence of a separator. The separator is searched for, and if found,
- // the substring preceding the occurrence is stored as the first element in
- // the array of strings. We then continue in this manner by searching
- // the substring that follows the occurrence. On the other hand, if the separator
- // is not found, the array of strings will contain this instance as its only element.
- // If the separator is null
- // whitespace (i.e., Character.IsWhitespace) is used as the separator.
- //
- public string[] Split(params char[]? separator)
- {
- return SplitInternal(separator, int.MaxValue, StringSplitOptions.None);
- }
-
- // Creates an array of strings by splitting this string at each
- // occurrence of a separator. The separator is searched for, and if found,
- // the substring preceding the occurrence is stored as the first element in
- // the array of strings. We then continue in this manner by searching
- // the substring that follows the occurrence. On the other hand, if the separator
- // is not found, the array of strings will contain this instance as its only element.
- // If the separator is the empty string (i.e., string.Empty), then
- // whitespace (i.e., Character.IsWhitespace) is used as the separator.
- // If there are more than count different strings, the last n-(count-1)
- // elements are concatenated and added as the last string.
- //
- public string[] Split(char[]? separator, int count)
- {
- return SplitInternal(separator, count, StringSplitOptions.None);
- }
-
- public string[] Split(char[]? separator, StringSplitOptions options)
- {
- return SplitInternal(separator, int.MaxValue, options);
- }
-
- public string[] Split(char[]? separator, int count, StringSplitOptions options)
- {
- return SplitInternal(separator, count, options);
- }
-
- private string[] SplitInternal(ReadOnlySpan<char> separators, int count, StringSplitOptions options)
- {
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count),
- SR.ArgumentOutOfRange_NegativeCount);
-
- if (options < StringSplitOptions.None || options > StringSplitOptions.RemoveEmptyEntries)
- throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, options));
-
- bool omitEmptyEntries = (options == StringSplitOptions.RemoveEmptyEntries);
-
- if ((count == 0) || (omitEmptyEntries && Length == 0))
- {
- return Array.Empty<string>();
- }
-
- if (count == 1)
- {
- return new string[] { this };
- }
-
- var sepListBuilder = new ValueListBuilder<int>(stackalloc int[StackallocIntBufferSizeLimit]);
-
- MakeSeparatorList(separators, ref sepListBuilder);
- ReadOnlySpan<int> sepList = sepListBuilder.AsSpan();
-
- // Handle the special case of no replaces.
- if (sepList.Length == 0)
- {
- return new string[] { this };
- }
-
- string[] result = omitEmptyEntries
- ? SplitOmitEmptyEntries(sepList, default, 1, count)
- : SplitKeepEmptyEntries(sepList, default, 1, count);
-
- sepListBuilder.Dispose();
-
- return result;
- }
-
- public string[] Split(string? separator, StringSplitOptions options = StringSplitOptions.None)
- {
- return SplitInternal(separator ?? string.Empty, null, int.MaxValue, options);
- }
-
- public string[] Split(string? separator, int count, StringSplitOptions options = StringSplitOptions.None)
- {
- return SplitInternal(separator ?? string.Empty, null, count, options);
- }
-
- public string[] Split(string[]? separator, StringSplitOptions options)
- {
- return SplitInternal(null, separator, int.MaxValue, options);
- }
-
- public string[] Split(string[]? separator, int count, StringSplitOptions options)
- {
- return SplitInternal(null, separator, count, options);
- }
-
- private string[] SplitInternal(string? separator, string?[]? separators, int count, StringSplitOptions options)
- {
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count),
- SR.ArgumentOutOfRange_NegativeCount);
- }
-
- if (options < StringSplitOptions.None || options > StringSplitOptions.RemoveEmptyEntries)
- {
- throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)options));
- }
-
- bool omitEmptyEntries = (options == StringSplitOptions.RemoveEmptyEntries);
-
- bool singleSeparator = separator != null;
-
- if (!singleSeparator && (separators == null || separators.Length == 0))
- {
- return SplitInternal(default(ReadOnlySpan<char>), count, options);
- }
-
- if ((count == 0) || (omitEmptyEntries && Length == 0))
- {
- return Array.Empty<string>();
- }
-
- if (count == 1 || (singleSeparator && separator!.Length == 0))
- {
- return new string[] { this };
- }
-
- if (singleSeparator)
- {
- return SplitInternal(separator!, count, options);
- }
-
- var sepListBuilder = new ValueListBuilder<int>(stackalloc int[StackallocIntBufferSizeLimit]);
- var lengthListBuilder = new ValueListBuilder<int>(stackalloc int[StackallocIntBufferSizeLimit]);
-
- MakeSeparatorList(separators!, ref sepListBuilder, ref lengthListBuilder);
- ReadOnlySpan<int> sepList = sepListBuilder.AsSpan();
- ReadOnlySpan<int> lengthList = lengthListBuilder.AsSpan();
-
- // Handle the special case of no replaces.
- if (sepList.Length == 0)
- {
- return new string[] { this };
- }
-
- string[] result = omitEmptyEntries
- ? SplitOmitEmptyEntries(sepList, lengthList, 0, count)
- : SplitKeepEmptyEntries(sepList, lengthList, 0, count);
-
- sepListBuilder.Dispose();
- lengthListBuilder.Dispose();
-
- return result;
- }
-
- private string[] SplitInternal(string separator, int count, StringSplitOptions options)
- {
- var sepListBuilder = new ValueListBuilder<int>(stackalloc int[StackallocIntBufferSizeLimit]);
-
- MakeSeparatorList(separator, ref sepListBuilder);
- ReadOnlySpan<int> sepList = sepListBuilder.AsSpan();
- if (sepList.Length == 0)
- {
- // there are no separators so sepListBuilder did not rent an array from pool and there is no need to dispose it
- return new string[] { this };
- }
-
- string[] result = options == StringSplitOptions.RemoveEmptyEntries
- ? SplitOmitEmptyEntries(sepList, default, separator.Length, count)
- : SplitKeepEmptyEntries(sepList, default, separator.Length, count);
-
- sepListBuilder.Dispose();
-
- return result;
- }
-
- private string[] SplitKeepEmptyEntries(ReadOnlySpan<int> sepList, ReadOnlySpan<int> lengthList, int defaultLength, int count)
- {
- Debug.Assert(count >= 2);
-
- int currIndex = 0;
- int arrIndex = 0;
-
- count--;
- int numActualReplaces = (sepList.Length < count) ? sepList.Length : count;
-
- // Allocate space for the new array.
- // +1 for the string from the end of the last replace to the end of the string.
- string[] splitStrings = new string[numActualReplaces + 1];
-
- for (int i = 0; i < numActualReplaces && currIndex < Length; i++)
- {
- splitStrings[arrIndex++] = Substring(currIndex, sepList[i] - currIndex);
- currIndex = sepList[i] + (lengthList.IsEmpty ? defaultLength : lengthList[i]);
- }
-
- // Handle the last string at the end of the array if there is one.
- if (currIndex < Length && numActualReplaces >= 0)
- {
- splitStrings[arrIndex] = Substring(currIndex);
- }
- else if (arrIndex == numActualReplaces)
- {
- // We had a separator character at the end of a string. Rather than just allowing
- // a null character, we'll replace the last element in the array with an empty string.
- splitStrings[arrIndex] = string.Empty;
- }
-
- return splitStrings;
- }
-
-
- // This function will not keep the Empty string
- private string[] SplitOmitEmptyEntries(ReadOnlySpan<int> sepList, ReadOnlySpan<int> lengthList, int defaultLength, int count)
- {
- Debug.Assert(count >= 2);
-
- int numReplaces = sepList.Length;
-
- // Allocate array to hold items. This array may not be
- // filled completely in this function, we will create a
- // new array and copy string references to that new array.
- int maxItems = (numReplaces < count) ? (numReplaces + 1) : count;
- string[] splitStrings = new string[maxItems];
-
- int currIndex = 0;
- int arrIndex = 0;
-
- for (int i = 0; i < numReplaces && currIndex < Length; i++)
- {
- if (sepList[i] - currIndex > 0)
- {
- splitStrings[arrIndex++] = Substring(currIndex, sepList[i] - currIndex);
- }
- currIndex = sepList[i] + (lengthList.IsEmpty ? defaultLength : lengthList[i]);
- if (arrIndex == count - 1)
- {
- // If all the remaining entries at the end are empty, skip them
- while (i < numReplaces - 1 && currIndex == sepList[++i])
- {
- currIndex += (lengthList.IsEmpty ? defaultLength : lengthList[i]);
- }
- break;
- }
- }
-
- // we must have at least one slot left to fill in the last string.
- Debug.Assert(arrIndex < maxItems);
-
- // Handle the last string at the end of the array if there is one.
- if (currIndex < Length)
- {
- splitStrings[arrIndex++] = Substring(currIndex);
- }
-
- string[] stringArray = splitStrings;
- if (arrIndex != maxItems)
- {
- stringArray = new string[arrIndex];
- for (int j = 0; j < arrIndex; j++)
- {
- stringArray[j] = splitStrings[j];
- }
- }
- return stringArray;
- }
-
- /// <summary>
- /// Uses ValueListBuilder to create list that holds indexes of separators in string.
- /// </summary>
- /// <param name="separators"><see cref="ReadOnlySpan{T}"/> of separator chars</param>
- /// <param name="sepListBuilder"><see cref="ValueListBuilder{T}"/> to store indexes</param>
- private void MakeSeparatorList(ReadOnlySpan<char> separators, ref ValueListBuilder<int> sepListBuilder)
- {
- char sep0, sep1, sep2;
-
- switch (separators.Length)
- {
- // Special-case no separators to mean any whitespace is a separator.
- case 0:
- for (int i = 0; i < Length; i++)
- {
- if (char.IsWhiteSpace(this[i]))
- {
- sepListBuilder.Append(i);
- }
- }
- break;
-
- // Special-case the common cases of 1, 2, and 3 separators, with manual comparisons against each separator.
- case 1:
- sep0 = separators[0];
- for (int i = 0; i < Length; i++)
- {
- if (this[i] == sep0)
- {
- sepListBuilder.Append(i);
- }
- }
- break;
- case 2:
- sep0 = separators[0];
- sep1 = separators[1];
- for (int i = 0; i < Length; i++)
- {
- char c = this[i];
- if (c == sep0 || c == sep1)
- {
- sepListBuilder.Append(i);
- }
- }
- break;
- case 3:
- sep0 = separators[0];
- sep1 = separators[1];
- sep2 = separators[2];
- for (int i = 0; i < Length; i++)
- {
- char c = this[i];
- if (c == sep0 || c == sep1 || c == sep2)
- {
- sepListBuilder.Append(i);
- }
- }
- break;
-
- // Handle > 3 separators with a probabilistic map, ala IndexOfAny.
- // This optimizes for chars being unlikely to match a separator.
- default:
- unsafe
- {
- ProbabilisticMap map = default;
- uint* charMap = (uint*)&map;
- InitializeProbabilisticMap(charMap, separators);
-
- for (int i = 0; i < Length; i++)
- {
- char c = this[i];
- if (IsCharBitSet(charMap, (byte)c) && IsCharBitSet(charMap, (byte)(c >> 8)) &&
- separators.Contains(c))
- {
- sepListBuilder.Append(i);
- }
- }
- }
- break;
- }
- }
-
- /// <summary>
- /// Uses ValueListBuilder to create list that holds indexes of separators in string.
- /// </summary>
- /// <param name="separator">separator string</param>
- /// <param name="sepListBuilder"><see cref="ValueListBuilder{T}"/> to store indexes</param>
- private void MakeSeparatorList(string separator, ref ValueListBuilder<int> sepListBuilder)
- {
- Debug.Assert(!IsNullOrEmpty(separator), "!string.IsNullOrEmpty(separator)");
-
- int currentSepLength = separator.Length;
-
- for (int i = 0; i < Length; i++)
- {
- if (this[i] == separator[0] && currentSepLength <= Length - i)
- {
- if (currentSepLength == 1
- || this.AsSpan(i, currentSepLength).SequenceEqual(separator))
- {
- sepListBuilder.Append(i);
- i += currentSepLength - 1;
- }
- }
- }
- }
-
- /// <summary>
- /// Uses ValueListBuilder to create list that holds indexes of separators in string and list that holds length of separator strings.
- /// </summary>
- /// <param name="separators">separator strngs</param>
- /// <param name="sepListBuilder"><see cref="ValueListBuilder{T}"/> for separator indexes</param>
- /// <param name="lengthListBuilder"><see cref="ValueListBuilder{T}"/> for separator length values</param>
- private void MakeSeparatorList(string?[] separators, ref ValueListBuilder<int> sepListBuilder, ref ValueListBuilder<int> lengthListBuilder)
- {
- Debug.Assert(separators != null && separators.Length > 0, "separators != null && separators.Length > 0");
-
- for (int i = 0; i < Length; i++)
- {
- for (int j = 0; j < separators.Length; j++)
- {
- string? separator = separators[j];
- if (IsNullOrEmpty(separator))
- {
- continue;
- }
- int currentSepLength = separator.Length;
- if (this[i] == separator[0] && currentSepLength <= Length - i)
- {
- if (currentSepLength == 1
- || this.AsSpan(i, currentSepLength).SequenceEqual(separator))
- {
- sepListBuilder.Append(i);
- lengthListBuilder.Append(currentSepLength);
- i += currentSepLength - 1;
- break;
- }
- }
- }
- }
- }
-
- // Returns a substring of this string.
- //
- public string Substring(int startIndex) => Substring(startIndex, Length - startIndex);
-
- public string Substring(int startIndex, int length)
- {
- if (startIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
- }
-
- if (startIndex > Length)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndexLargerThanLength);
- }
-
- if (length < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NegativeLength);
- }
-
- if (startIndex > Length - length)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_IndexLength);
- }
-
- if (length == 0)
- {
- return string.Empty;
- }
-
- if (startIndex == 0 && length == this.Length)
- {
- return this;
- }
-
- return InternalSubString(startIndex, length);
- }
-
- private unsafe string InternalSubString(int startIndex, int length)
- {
- Debug.Assert(startIndex >= 0 && startIndex <= this.Length, "StartIndex is out of range!");
- Debug.Assert(length >= 0 && startIndex <= this.Length - length, "length is out of range!");
-
- string result = FastAllocateString(length);
-
- fixed (char* dest = &result._firstChar)
- fixed (char* src = &_firstChar)
- {
- wstrcpy(dest, src + startIndex, length);
- }
-
- return result;
- }
-
- // Creates a copy of this string in lower case. The culture is set by culture.
- public string ToLower() => ToLower(null);
-
- // Creates a copy of this string in lower case. The culture is set by culture.
- public string ToLower(CultureInfo? culture)
- {
- CultureInfo cult = culture ?? CultureInfo.CurrentCulture;
- return cult.TextInfo.ToLower(this);
- }
-
- // Creates a copy of this string in lower case based on invariant culture.
- public string ToLowerInvariant()
- {
- return CultureInfo.InvariantCulture.TextInfo.ToLower(this);
- }
-
- public string ToUpper() => ToUpper(null);
-
- // Creates a copy of this string in upper case. The culture is set by culture.
- public string ToUpper(CultureInfo? culture)
- {
- CultureInfo cult = culture ?? CultureInfo.CurrentCulture;
- return cult.TextInfo.ToUpper(this);
- }
-
- // Creates a copy of this string in upper case based on invariant culture.
- public string ToUpperInvariant()
- {
- return CultureInfo.InvariantCulture.TextInfo.ToUpper(this);
- }
-
- // Trims the whitespace from both ends of the string. Whitespace is defined by
- // char.IsWhiteSpace.
- //
- public string Trim() => TrimWhiteSpaceHelper(TrimType.Both);
-
- // Removes a set of characters from the beginning and end of this string.
- public unsafe string Trim(char trimChar) => TrimHelper(&trimChar, 1, TrimType.Both);
-
- // Removes a set of characters from the beginning and end of this string.
- public unsafe string Trim(params char[]? trimChars)
- {
- if (trimChars == null || trimChars.Length == 0)
- {
- return TrimWhiteSpaceHelper(TrimType.Both);
- }
- fixed (char* pTrimChars = &trimChars[0])
- {
- return TrimHelper(pTrimChars, trimChars.Length, TrimType.Both);
- }
- }
-
- // Removes a set of characters from the beginning of this string.
- public string TrimStart() => TrimWhiteSpaceHelper(TrimType.Head);
-
- // Removes a set of characters from the beginning of this string.
- public unsafe string TrimStart(char trimChar) => TrimHelper(&trimChar, 1, TrimType.Head);
-
- // Removes a set of characters from the beginning of this string.
- public unsafe string TrimStart(params char[]? trimChars)
- {
- if (trimChars == null || trimChars.Length == 0)
- {
- return TrimWhiteSpaceHelper(TrimType.Head);
- }
- fixed (char* pTrimChars = &trimChars[0])
- {
- return TrimHelper(pTrimChars, trimChars.Length, TrimType.Head);
- }
- }
-
- // Removes a set of characters from the end of this string.
- public string TrimEnd() => TrimWhiteSpaceHelper(TrimType.Tail);
-
- // Removes a set of characters from the end of this string.
- public unsafe string TrimEnd(char trimChar) => TrimHelper(&trimChar, 1, TrimType.Tail);
-
- // Removes a set of characters from the end of this string.
- public unsafe string TrimEnd(params char[]? trimChars)
- {
- if (trimChars == null || trimChars.Length == 0)
- {
- return TrimWhiteSpaceHelper(TrimType.Tail);
- }
- fixed (char* pTrimChars = &trimChars[0])
- {
- return TrimHelper(pTrimChars, trimChars.Length, TrimType.Tail);
- }
- }
-
- private string TrimWhiteSpaceHelper(TrimType trimType)
- {
- // end will point to the first non-trimmed character on the right.
- // start will point to the first non-trimmed character on the left.
- int end = Length - 1;
- int start = 0;
-
- // Trim specified characters.
- if ((trimType & TrimType.Head) != 0)
- {
- for (start = 0; start < Length; start++)
- {
- if (!char.IsWhiteSpace(this[start]))
- {
- break;
- }
- }
- }
-
- if ((trimType & TrimType.Tail) != 0)
- {
- for (end = Length - 1; end >= start; end--)
- {
- if (!char.IsWhiteSpace(this[end]))
- {
- break;
- }
- }
- }
-
- return CreateTrimmedString(start, end);
- }
-
- private unsafe string TrimHelper(char* trimChars, int trimCharsLength, TrimType trimType)
- {
- Debug.Assert(trimChars != null);
- Debug.Assert(trimCharsLength > 0);
-
- // end will point to the first non-trimmed character on the right.
- // start will point to the first non-trimmed character on the left.
- int end = Length - 1;
- int start = 0;
-
- // Trim specified characters.
- if ((trimType & TrimType.Head) != 0)
- {
- for (start = 0; start < Length; start++)
- {
- int i = 0;
- char ch = this[start];
- for (i = 0; i < trimCharsLength; i++)
- {
- if (trimChars[i] == ch)
- {
- break;
- }
- }
- if (i == trimCharsLength)
- {
- // The character is not in trimChars, so stop trimming.
- break;
- }
- }
- }
-
- if ((trimType & TrimType.Tail) != 0)
- {
- for (end = Length - 1; end >= start; end--)
- {
- int i = 0;
- char ch = this[end];
- for (i = 0; i < trimCharsLength; i++)
- {
- if (trimChars[i] == ch)
- {
- break;
- }
- }
- if (i == trimCharsLength)
- {
- // The character is not in trimChars, so stop trimming.
- break;
- }
- }
- }
-
- return CreateTrimmedString(start, end);
- }
-
- private string CreateTrimmedString(int start, int end)
- {
- int len = end - start + 1;
- return
- len == Length ? this :
- len == 0 ? string.Empty :
- InternalSubString(start, len);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/String.Searching.cs b/netcore/System.Private.CoreLib/shared/System/String.Searching.cs
deleted file mode 100644
index 971202d808a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/String.Searching.cs
+++ /dev/null
@@ -1,491 +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 System.Globalization;
-using System.Runtime.InteropServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- public partial class String
- {
- public bool Contains(string value)
- {
- if (value == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
-
- return SpanHelpers.IndexOf(
- ref _firstChar,
- Length,
- ref value._firstChar,
- value.Length) >= 0;
- }
-
- public bool Contains(string value, StringComparison comparisonType)
- {
- return IndexOf(value, comparisonType) >= 0;
- }
-
- public bool Contains(char value) => SpanHelpers.Contains(ref _firstChar, value, Length);
-
- public bool Contains(char value, StringComparison comparisonType)
- {
- return IndexOf(value, comparisonType) != -1;
- }
-
- // Returns the index of the first occurrence of a specified character in the current instance.
- // The search starts at startIndex and runs thorough the next count characters.
- //
- public int IndexOf(char value) => SpanHelpers.IndexOf(ref _firstChar, value, Length);
-
- public int IndexOf(char value, int startIndex)
- {
- return IndexOf(value, startIndex, this.Length - startIndex);
- }
-
- public int IndexOf(char value, StringComparison comparisonType)
- {
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.IndexOf(this, value, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.IndexOf(this, value, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.Ordinal:
- return IndexOf(value);
-
- case StringComparison.OrdinalIgnoreCase:
- return CompareInfo.Invariant.IndexOf(this, value, CompareOptions.OrdinalIgnoreCase);
-
- default:
- throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType));
- }
- }
-
- public unsafe int IndexOf(char value, int startIndex, int count)
- {
- if ((uint)startIndex > (uint)Length)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
-
- if ((uint)count > (uint)(Length - startIndex))
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
-
- int result = SpanHelpers.IndexOf(ref Unsafe.Add(ref _firstChar, startIndex), value, count);
-
- return result == -1 ? result : result + startIndex;
- }
-
- // Returns the index of the first occurrence of any specified character in the current instance.
- // The search starts at startIndex and runs to startIndex + count - 1.
- //
- public int IndexOfAny(char[] anyOf)
- {
- return IndexOfAny(anyOf, 0, this.Length);
- }
-
- public int IndexOfAny(char[] anyOf, int startIndex)
- {
- return IndexOfAny(anyOf, startIndex, this.Length - startIndex);
- }
-
- public int IndexOfAny(char[] anyOf, int startIndex, int count)
- {
- if (anyOf == null)
- throw new ArgumentNullException(nameof(anyOf));
-
- if ((uint)startIndex > (uint)Length)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
-
- if ((uint)count > (uint)(Length - startIndex))
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
-
- if (anyOf.Length > 0 && anyOf.Length <= 5)
- {
- // The ReadOnlySpan.IndexOfAny extension is vectorized for values of 1 - 5 in length
- int result = new ReadOnlySpan<char>(ref Unsafe.Add(ref _firstChar, startIndex), count).IndexOfAny(anyOf);
- return result == -1 ? result : result + startIndex;
- }
- else if (anyOf.Length > 5)
- {
- // Use Probabilistic Map
- return IndexOfCharArray(anyOf, startIndex, count);
- }
- else // anyOf.Length == 0
- {
- return -1;
- }
- }
-
- private unsafe int IndexOfCharArray(char[] anyOf, int startIndex, int count)
- {
- // use probabilistic map, see InitializeProbabilisticMap
- ProbabilisticMap map = default;
- uint* charMap = (uint*)&map;
-
- InitializeProbabilisticMap(charMap, anyOf);
-
- fixed (char* pChars = &_firstChar)
- {
- char* pCh = pChars + startIndex;
-
- while (count > 0)
- {
- int thisChar = *pCh;
-
- if (IsCharBitSet(charMap, (byte)thisChar) &&
- IsCharBitSet(charMap, (byte)(thisChar >> 8)) &&
- ArrayContains((char)thisChar, anyOf))
- {
- return (int)(pCh - pChars);
- }
-
- count--;
- pCh++;
- }
-
- return -1;
- }
- }
-
- private const int PROBABILISTICMAP_BLOCK_INDEX_MASK = 0x7;
- private const int PROBABILISTICMAP_BLOCK_INDEX_SHIFT = 0x3;
- private const int PROBABILISTICMAP_SIZE = 0x8;
-
- // A probabilistic map is an optimization that is used in IndexOfAny/
- // LastIndexOfAny methods. The idea is to create a bit map of the characters we
- // are searching for and use this map as a "cheap" check to decide if the
- // current character in the string exists in the array of input characters.
- // There are 256 bits in the map, with each character mapped to 2 bits. Every
- // character is divided into 2 bytes, and then every byte is mapped to 1 bit.
- // The character map is an array of 8 integers acting as map blocks. The 3 lsb
- // in each byte in the character is used to index into this map to get the
- // right block, the value of the remaining 5 msb are used as the bit position
- // inside this block.
- private static unsafe void InitializeProbabilisticMap(uint* charMap, ReadOnlySpan<char> anyOf)
- {
- bool hasAscii = false;
- uint* charMapLocal = charMap; // https://github.com/dotnet/coreclr/issues/14264
-
- for (int i = 0; i < anyOf.Length; ++i)
- {
- int c = anyOf[i];
-
- // Map low bit
- SetCharBit(charMapLocal, (byte)c);
-
- // Map high bit
- c >>= 8;
-
- if (c == 0)
- {
- hasAscii = true;
- }
- else
- {
- SetCharBit(charMapLocal, (byte)c);
- }
- }
-
- if (hasAscii)
- {
- // Common to search for ASCII symbols. Just set the high value once.
- charMapLocal[0] |= 1u;
- }
- }
-
- private static bool ArrayContains(char searchChar, char[] anyOf)
- {
- for (int i = 0; i < anyOf.Length; i++)
- {
- if (anyOf[i] == searchChar)
- return true;
- }
-
- return false;
- }
-
- private static unsafe bool IsCharBitSet(uint* charMap, byte value)
- {
- return (charMap[value & PROBABILISTICMAP_BLOCK_INDEX_MASK] & (1u << (value >> PROBABILISTICMAP_BLOCK_INDEX_SHIFT))) != 0;
- }
-
- private static unsafe void SetCharBit(uint* charMap, byte value)
- {
- charMap[value & PROBABILISTICMAP_BLOCK_INDEX_MASK] |= 1u << (value >> PROBABILISTICMAP_BLOCK_INDEX_SHIFT);
- }
-
- public int IndexOf(string value)
- {
- return IndexOf(value, StringComparison.CurrentCulture);
- }
-
- public int IndexOf(string value, int startIndex)
- {
- return IndexOf(value, startIndex, StringComparison.CurrentCulture);
- }
-
- public int IndexOf(string value, int startIndex, int count)
- {
- if (startIndex < 0 || startIndex > this.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
-
- if (count < 0 || count > this.Length - startIndex)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
- }
-
- return IndexOf(value, startIndex, count, StringComparison.CurrentCulture);
- }
-
- public int IndexOf(string value, StringComparison comparisonType)
- {
- return IndexOf(value, 0, this.Length, comparisonType);
- }
-
- public int IndexOf(string value, int startIndex, StringComparison comparisonType)
- {
- return IndexOf(value, startIndex, this.Length - startIndex, comparisonType);
- }
-
- public int IndexOf(string value, int startIndex, int count, StringComparison comparisonType)
- {
- // Validate inputs
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- if (startIndex < 0 || startIndex > this.Length)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
-
- if (count < 0 || startIndex > this.Length - count)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
-
- if (comparisonType == StringComparison.Ordinal)
- {
- int result = SpanHelpers.IndexOf(
- ref Unsafe.Add(ref this._firstChar, startIndex),
- count,
- ref value._firstChar,
- value.Length);
-
- return (result >= 0 ? startIndex : 0) + result;
- }
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.IndexOf(this, value, startIndex, count, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.IndexOf(this, value, startIndex, count, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.OrdinalIgnoreCase:
- return CompareInfo.IndexOfOrdinal(this, value, startIndex, count, GetCaseCompareOfComparisonCulture(comparisonType) != CompareOptions.None);
-
- default:
- throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType));
- }
- }
-
- // Returns the index of the last occurrence of a specified character in the current instance.
- // The search starts at startIndex and runs backwards to startIndex - count + 1.
- // The character at position startIndex is included in the search. startIndex is the larger
- // index within the string.
- //
- public int LastIndexOf(char value) => SpanHelpers.LastIndexOf(ref _firstChar, value, Length);
-
- public int LastIndexOf(char value, int startIndex)
- {
- return LastIndexOf(value, startIndex, startIndex + 1);
- }
-
- public unsafe int LastIndexOf(char value, int startIndex, int count)
- {
- if (Length == 0)
- return -1;
-
- if ((uint)startIndex >= (uint)Length)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
-
- if ((uint)count > (uint)startIndex + 1)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
-
- int startSearchAt = startIndex + 1 - count;
- int result = SpanHelpers.LastIndexOf(ref Unsafe.Add(ref _firstChar, startSearchAt), value, count);
-
- return result == -1 ? result : result + startSearchAt;
- }
-
- // Returns the index of the last occurrence of any specified character in the current instance.
- // The search starts at startIndex and runs backwards to startIndex - count + 1.
- // The character at position startIndex is included in the search. startIndex is the larger
- // index within the string.
- //
- public int LastIndexOfAny(char[] anyOf)
- {
- return LastIndexOfAny(anyOf, this.Length - 1, this.Length);
- }
-
- public int LastIndexOfAny(char[] anyOf, int startIndex)
- {
- return LastIndexOfAny(anyOf, startIndex, startIndex + 1);
- }
-
- public unsafe int LastIndexOfAny(char[] anyOf, int startIndex, int count)
- {
- if (anyOf == null)
- throw new ArgumentNullException(nameof(anyOf));
-
- if (Length == 0)
- return -1;
-
- if ((uint)startIndex >= (uint)Length)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
-
- if ((count < 0) || ((count - 1) > startIndex))
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
- }
-
- if (anyOf.Length > 1)
- {
- return LastIndexOfCharArray(anyOf, startIndex, count);
- }
- else if (anyOf.Length == 1)
- {
- return LastIndexOf(anyOf[0], startIndex, count);
- }
- else // anyOf.Length == 0
- {
- return -1;
- }
- }
-
- private unsafe int LastIndexOfCharArray(char[] anyOf, int startIndex, int count)
- {
- // use probabilistic map, see InitializeProbabilisticMap
- ProbabilisticMap map = default;
- uint* charMap = (uint*)&map;
-
- InitializeProbabilisticMap(charMap, anyOf);
-
- fixed (char* pChars = &_firstChar)
- {
- char* pCh = pChars + startIndex;
-
- while (count > 0)
- {
- int thisChar = *pCh;
-
- if (IsCharBitSet(charMap, (byte)thisChar) &&
- IsCharBitSet(charMap, (byte)(thisChar >> 8)) &&
- ArrayContains((char)thisChar, anyOf))
- {
- return (int)(pCh - pChars);
- }
-
- count--;
- pCh--;
- }
-
- return -1;
- }
- }
-
- // Returns the index of the last occurrence of any character in value in the current instance.
- // The search starts at startIndex and runs backwards to startIndex - count + 1.
- // The character at position startIndex is included in the search. startIndex is the larger
- // index within the string.
- //
- public int LastIndexOf(string value)
- {
- return LastIndexOf(value, this.Length - 1, this.Length, StringComparison.CurrentCulture);
- }
-
- public int LastIndexOf(string value, int startIndex)
- {
- return LastIndexOf(value, startIndex, startIndex + 1, StringComparison.CurrentCulture);
- }
-
- public int LastIndexOf(string value, int startIndex, int count)
- {
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
- }
-
- return LastIndexOf(value, startIndex, count, StringComparison.CurrentCulture);
- }
-
- public int LastIndexOf(string value, StringComparison comparisonType)
- {
- return LastIndexOf(value, this.Length - 1, this.Length, comparisonType);
- }
-
- public int LastIndexOf(string value, int startIndex, StringComparison comparisonType)
- {
- return LastIndexOf(value, startIndex, startIndex + 1, comparisonType);
- }
-
- public int LastIndexOf(string value, int startIndex, int count, StringComparison comparisonType)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- // Special case for 0 length input strings
- if (this.Length == 0 && (startIndex == -1 || startIndex == 0))
- return (value.Length == 0) ? 0 : -1;
-
- // Now after handling empty strings, make sure we're not out of range
- if (startIndex < 0 || startIndex > this.Length)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
-
- // Make sure that we allow startIndex == this.Length
- if (startIndex == this.Length)
- {
- startIndex--;
- if (count > 0)
- count--;
- }
-
- // 2nd half of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
- if (count < 0 || startIndex - count + 1 < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
-
- // If we are looking for nothing, just return startIndex
- if (value.Length == 0)
- return startIndex;
-
- switch (comparisonType)
- {
- case StringComparison.CurrentCulture:
- case StringComparison.CurrentCultureIgnoreCase:
- return CultureInfo.CurrentCulture.CompareInfo.LastIndexOf(this, value, startIndex, count, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.InvariantCulture:
- case StringComparison.InvariantCultureIgnoreCase:
- return CompareInfo.Invariant.LastIndexOf(this, value, startIndex, count, GetCaseCompareOfComparisonCulture(comparisonType));
-
- case StringComparison.Ordinal:
- case StringComparison.OrdinalIgnoreCase:
- return CompareInfo.LastIndexOfOrdinal(this, value, startIndex, count, GetCaseCompareOfComparisonCulture(comparisonType) != CompareOptions.None);
-
- default:
- throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType));
- }
- }
-
- [StructLayout(LayoutKind.Explicit, Size = PROBABILISTICMAP_SIZE * sizeof(uint))]
- private struct ProbabilisticMap { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/String.cs b/netcore/System.Private.CoreLib/shared/System/String.cs
deleted file mode 100644
index 228b5840b14..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/String.cs
+++ /dev/null
@@ -1,718 +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 System.Buffers;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-using System.Text;
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- // The String class represents a static string of characters. Many of
- // the string methods perform some type of transformation on the current
- // instance and return the result as a new string. As with arrays, character
- // positions (indices) are zero-based.
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed partial class String : IComparable, IEnumerable, IConvertible, IEnumerable<char>, IComparable<string?>,
- // IEquatable<string> is invariant by design. However, the lack of covariance means that String?
- // couldn't be used in places constrained to T : IEquatable<String>. As a workaround, until the
- // language provides a mechanism for this, we make the generic type argument oblivious, in conjunction
- // with making all such constraints oblivious as well.
-#nullable disable
- IEquatable<string>,
-#nullable restore
- ICloneable
- {
- //
- // These fields map directly onto the fields in an EE StringObject. See object.h for the layout.
- //
- [NonSerialized]
- private int _stringLength;
-
- // For empty strings, this will be '\0' since
- // strings are both null-terminated and length prefixed
- [NonSerialized]
- private char _firstChar;
-
- /*
- * CONSTRUCTORS
- *
- * Defining a new constructor for string-like types (like String) requires changes both
- * to the managed code below and to the native VM code. See the comment at the top of
- * src/vm/ecall.cpp for instructions on how to add new overloads.
- */
-
- [MethodImpl(MethodImplOptions.InternalCall)]
- public extern String(char[] value);
-
-#if !CORECLR
- static
-#endif
- private string Ctor(char[]? value)
- {
- if (value == null || value.Length == 0)
- return Empty;
-
- string result = FastAllocateString(value.Length);
- unsafe
- {
- fixed (char* dest = &result._firstChar, source = value)
- wstrcpy(dest, source, value.Length);
- }
- return result;
- }
-
- [MethodImpl(MethodImplOptions.InternalCall)]
- public extern String(char[] value, int startIndex, int length);
-
-#if !CORECLR
- static
-#endif
- private string Ctor(char[] value, int startIndex, int length)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- if (startIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
-
- if (length < 0)
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NegativeLength);
-
- if (startIndex > value.Length - length)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
-
- if (length == 0)
- return Empty;
-
- string result = FastAllocateString(length);
- unsafe
- {
- fixed (char* dest = &result._firstChar, source = value)
- wstrcpy(dest, source + startIndex, length);
- }
- return result;
- }
-
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.InternalCall)]
- public extern unsafe String(char* value);
-
-#if !CORECLR
- static
-#endif
- private unsafe string Ctor(char* ptr)
- {
- if (ptr == null)
- return Empty;
-
- int count = wcslen(ptr);
- if (count == 0)
- return Empty;
-
- string result = FastAllocateString(count);
- fixed (char* dest = &result._firstChar)
- wstrcpy(dest, ptr, count);
- return result;
- }
-
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.InternalCall)]
- public extern unsafe String(char* value, int startIndex, int length);
-
-#if !CORECLR
- static
-#endif
- private unsafe string Ctor(char* ptr, int startIndex, int length)
- {
- if (length < 0)
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NegativeLength);
-
- if (startIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
-
- char* pStart = ptr + startIndex;
-
- // overflow check
- if (pStart < ptr)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_PartialWCHAR);
-
- if (length == 0)
- return Empty;
-
- if (ptr == null)
- throw new ArgumentOutOfRangeException(nameof(ptr), SR.ArgumentOutOfRange_PartialWCHAR);
-
- string result = FastAllocateString(length);
- fixed (char* dest = &result._firstChar)
- wstrcpy(dest, pStart, length);
- return result;
- }
-
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.InternalCall)]
- public extern unsafe String(sbyte* value);
-
-#if !CORECLR
- static
-#endif
- private unsafe string Ctor(sbyte* value)
- {
- byte* pb = (byte*)value;
- if (pb == null)
- return Empty;
-
- int numBytes = strlen((byte*)value);
-
- return CreateStringForSByteConstructor(pb, numBytes);
- }
-
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.InternalCall)]
- public extern unsafe String(sbyte* value, int startIndex, int length);
-
-#if !CORECLR
- static
-#endif
- private unsafe string Ctor(sbyte* value, int startIndex, int length)
- {
- if (startIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
-
- if (length < 0)
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NegativeLength);
-
- if (value == null)
- {
- if (length == 0)
- return Empty;
-
- throw new ArgumentNullException(nameof(value));
- }
-
- byte* pStart = (byte*)(value + startIndex);
-
- // overflow check
- if (pStart < value)
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_PartialWCHAR);
-
- return CreateStringForSByteConstructor(pStart, length);
- }
-
- // Encoder for String..ctor(sbyte*) and String..ctor(sbyte*, int, int)
- private static unsafe string CreateStringForSByteConstructor(byte* pb, int numBytes)
- {
- Debug.Assert(numBytes >= 0);
- Debug.Assert(pb <= (pb + numBytes));
-
- if (numBytes == 0)
- return Empty;
-
-#if PLATFORM_WINDOWS
- int numCharsRequired = Interop.Kernel32.MultiByteToWideChar(Interop.Kernel32.CP_ACP, Interop.Kernel32.MB_PRECOMPOSED, pb, numBytes, (char*)null, 0);
- if (numCharsRequired == 0)
- throw new ArgumentException(SR.Arg_InvalidANSIString);
-
- string newString = FastAllocateString(numCharsRequired);
- fixed (char* pFirstChar = &newString._firstChar)
- {
- numCharsRequired = Interop.Kernel32.MultiByteToWideChar(Interop.Kernel32.CP_ACP, Interop.Kernel32.MB_PRECOMPOSED, pb, numBytes, pFirstChar, numCharsRequired);
- }
- if (numCharsRequired == 0)
- throw new ArgumentException(SR.Arg_InvalidANSIString);
- return newString;
-#else
- return Encoding.UTF8.GetString(pb, numBytes);
-#endif
- }
-
- [CLSCompliant(false)]
- [MethodImpl(MethodImplOptions.InternalCall)]
- public extern unsafe String(sbyte* value, int startIndex, int length, Encoding enc);
-
-#if !CORECLR
- static
-#endif
- private unsafe string Ctor(sbyte* value, int startIndex, int length, Encoding? enc)
- {
- if (enc == null)
- return new string(value, startIndex, length);
-
- if (length < 0)
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (startIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
-
- if (value == null)
- {
- if (length == 0)
- return Empty;
-
- throw new ArgumentNullException(nameof(value));
- }
-
- byte* pStart = (byte*)(value + startIndex);
-
- // overflow check
- if (pStart < value)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_PartialWCHAR);
-
- return enc.GetString(new ReadOnlySpan<byte>(pStart, length));
- }
-
- [MethodImpl(MethodImplOptions.InternalCall)]
- public extern String(char c, int count);
-
-#if !CORECLR
- static
-#endif
- private string Ctor(char c, int count)
- {
- if (count <= 0)
- {
- if (count == 0)
- return Empty;
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NegativeCount);
- }
-
- string result = FastAllocateString(count);
-
- if (c != '\0') // Fast path null char string
- {
- unsafe
- {
- fixed (char* dest = &result._firstChar)
- {
- uint cc = (uint)((c << 16) | c);
- uint* dmem = (uint*)dest;
- if (count >= 4)
- {
- count -= 4;
- do
- {
- dmem[0] = cc;
- dmem[1] = cc;
- dmem += 2;
- count -= 4;
- } while (count >= 0);
- }
- if ((count & 2) != 0)
- {
- *dmem = cc;
- dmem++;
- }
- if ((count & 1) != 0)
- ((char*)dmem)[0] = c;
- }
- }
- }
- return result;
- }
-
- [MethodImpl(MethodImplOptions.InternalCall)]
- public extern String(ReadOnlySpan<char> value);
-
-#if !CORECLR
- static
-#endif
- private unsafe string Ctor(ReadOnlySpan<char> value)
- {
- if (value.Length == 0)
- return Empty;
-
- string result = FastAllocateString(value.Length);
- Buffer.Memmove(ref result._firstChar, ref MemoryMarshal.GetReference(value), (uint)value.Length);
- return result;
- }
-
- public static string Create<TState>(int length, TState state, SpanAction<char, TState> action)
- {
- if (action == null)
- throw new ArgumentNullException(nameof(action));
-
- if (length <= 0)
- {
- if (length == 0)
- return Empty;
- throw new ArgumentOutOfRangeException(nameof(length));
- }
-
- string result = FastAllocateString(length);
- action(new Span<char>(ref result.GetRawStringData(), length), state);
- return result;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static implicit operator ReadOnlySpan<char>(string? value) =>
- value != null ? new ReadOnlySpan<char>(ref value.GetRawStringData(), value.Length) : default;
-
- public object Clone()
- {
- return this;
- }
-
- public static unsafe string Copy(string str)
- {
- if (str == null)
- throw new ArgumentNullException(nameof(str));
-
- string result = FastAllocateString(str.Length);
- fixed (char* dest = &result._firstChar, src = &str._firstChar)
- wstrcpy(dest, src, str.Length);
- return result;
- }
-
- // Converts a substring of this string to an array of characters. Copies the
- // characters of this string beginning at position sourceIndex and ending at
- // sourceIndex + count - 1 to the character array buffer, beginning
- // at destinationIndex.
- //
- public unsafe void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
- {
- if (destination == null)
- throw new ArgumentNullException(nameof(destination));
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NegativeCount);
- if (sourceIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_Index);
- if (count > Length - sourceIndex)
- throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_IndexCount);
- if (destinationIndex > destination.Length - count || destinationIndex < 0)
- throw new ArgumentOutOfRangeException(nameof(destinationIndex), SR.ArgumentOutOfRange_IndexCount);
-
- fixed (char* src = &_firstChar, dest = destination)
- wstrcpy(dest + destinationIndex, src + sourceIndex, count);
- }
-
- // Returns the entire string as an array of characters.
- public unsafe char[] ToCharArray()
- {
- if (Length == 0)
- return Array.Empty<char>();
-
- char[] chars = new char[Length];
- fixed (char* src = &_firstChar, dest = &chars[0])
- wstrcpy(dest, src, Length);
- return chars;
- }
-
- // Returns a substring of this string as an array of characters.
- //
- public unsafe char[] ToCharArray(int startIndex, int length)
- {
- // Range check everything.
- if (startIndex < 0 || startIndex > Length || startIndex > Length - length)
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
-
- if (length <= 0)
- {
- if (length == 0)
- return Array.Empty<char>();
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Index);
- }
-
- char[] chars = new char[length];
- fixed (char* src = &_firstChar, dest = &chars[0])
- wstrcpy(dest, src + startIndex, length);
- return chars;
- }
-
- [NonVersionable]
- public static bool IsNullOrEmpty([NotNullWhen(false)] string? value)
- {
- // Using 0u >= (uint)value.Length rather than
- // value.Length == 0 as it will elide the bounds check to
- // the first char: value[0] if that is performed following the test
- // for the same test cost.
- // Ternary operator returning true/false prevents redundant asm generation:
- // https://github.com/dotnet/coreclr/issues/914
- return (value == null || 0u >= (uint)value.Length) ? true : false;
- }
-
- public static bool IsNullOrWhiteSpace([NotNullWhen(false)] string? value)
- {
- if (value == null) return true;
-
- for (int i = 0; i < value.Length; i++)
- {
- if (!char.IsWhiteSpace(value[i])) return false;
- }
-
- return true;
- }
-
- /// <summary>
- /// Returns a reference to the first element of the String. If the string is null, an access will throw a NullReferenceException.
- /// </summary>
- [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
- [NonVersionable]
- public ref readonly char GetPinnableReference() => ref _firstChar;
-
- internal ref char GetRawStringData() => ref _firstChar;
-
- // Helper for encodings so they can talk to our buffer directly
- // stringLength must be the exact size we'll expect
- internal static unsafe string CreateStringFromEncoding(
- byte* bytes, int byteLength, Encoding encoding)
- {
- Debug.Assert(bytes != null);
- Debug.Assert(byteLength >= 0);
-
- // Get our string length
- int stringLength = encoding.GetCharCount(bytes, byteLength);
- Debug.Assert(stringLength >= 0, "stringLength >= 0");
-
- // They gave us an empty string if they needed one
- // 0 bytelength might be possible if there's something in an encoder
- if (stringLength == 0)
- return Empty;
-
- string s = FastAllocateString(stringLength);
- fixed (char* pTempChars = &s._firstChar)
- {
- int doubleCheck = encoding.GetChars(bytes, byteLength, pTempChars, stringLength);
- Debug.Assert(stringLength == doubleCheck,
- "Expected encoding.GetChars to return same length as encoding.GetCharCount");
- }
-
- return s;
- }
-
- // This is only intended to be used by char.ToString.
- // It is necessary to put the code in this class instead of Char, since _firstChar is a private member.
- // Making _firstChar internal would be dangerous since it would make it much easier to break String's immutability.
- internal static string CreateFromChar(char c)
- {
- string result = FastAllocateString(1);
- result._firstChar = c;
- return result;
- }
-
- internal static string CreateFromChar(char c1, char c2)
- {
- string result = FastAllocateString(2);
- result._firstChar = c1;
- Unsafe.Add(ref result._firstChar, 1) = c2;
- return result;
- }
-
- internal static unsafe void wstrcpy(char* dmem, char* smem, int charCount)
- {
- Buffer.Memmove((byte*)dmem, (byte*)smem, ((uint)charCount) * 2);
- }
-
-
- // Returns this string.
- public override string ToString()
- {
- return this;
- }
-
- // Returns this string.
- public string ToString(IFormatProvider? provider)
- {
- return this;
- }
-
- public CharEnumerator GetEnumerator()
- {
- return new CharEnumerator(this);
- }
-
- IEnumerator<char> IEnumerable<char>.GetEnumerator()
- {
- return new CharEnumerator(this);
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return new CharEnumerator(this);
- }
-
- /// <summary>
- /// Returns an enumeration of <see cref="Rune"/> from this string.
- /// </summary>
- /// <remarks>
- /// Invalid sequences will be represented in the enumeration by <see cref="Rune.ReplacementChar"/>.
- /// </remarks>
- public StringRuneEnumerator EnumerateRunes()
- {
- return new StringRuneEnumerator(this);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe int wcslen(char* ptr)
- {
- // IndexOf processes memory in aligned chunks, and thus it won't crash even if it accesses memory beyond the null terminator.
- int length = SpanHelpers.IndexOf(ref *ptr, '\0', int.MaxValue);
- if (length < 0)
- {
- ThrowMustBeNullTerminatedString();
- }
-
- return length;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static unsafe int strlen(byte* ptr)
- {
- // IndexOf processes memory in aligned chunks, and thus it won't crash even if it accesses memory beyond the null terminator.
- int length = SpanHelpers.IndexOf(ref *ptr, (byte)'\0', int.MaxValue);
- if (length < 0)
- {
- ThrowMustBeNullTerminatedString();
- }
-
- return length;
- }
-
- [DoesNotReturn]
- private static void ThrowMustBeNullTerminatedString()
- {
- throw new ArgumentException(SR.Arg_MustBeNullTerminatedString);
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.String;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(this, provider);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- return Convert.ToChar(this, provider);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(this, provider);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(this, provider);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(this, provider);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(this, provider);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(this, provider);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(this, provider);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(this, provider);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(this, provider);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(this, provider);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(this, provider);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(this, provider);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- return Convert.ToDateTime(this, provider);
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
-
- // Normalization Methods
- // These just wrap calls to Normalization class
- public bool IsNormalized()
- {
- return IsNormalized(NormalizationForm.FormC);
- }
-
- public bool IsNormalized(NormalizationForm normalizationForm)
- {
- if (this.IsAscii())
- {
- // If its ASCII && one of the 4 main forms, then its already normalized
- if (normalizationForm == NormalizationForm.FormC ||
- normalizationForm == NormalizationForm.FormKC ||
- normalizationForm == NormalizationForm.FormD ||
- normalizationForm == NormalizationForm.FormKD)
- return true;
- }
- return Normalization.IsNormalized(this, normalizationForm);
- }
-
- public string Normalize()
- {
- return Normalize(NormalizationForm.FormC);
- }
-
- public string Normalize(NormalizationForm normalizationForm)
- {
- if (this.IsAscii())
- {
- // If its ASCII && one of the 4 main forms, then its already normalized
- if (normalizationForm == NormalizationForm.FormC ||
- normalizationForm == NormalizationForm.FormKC ||
- normalizationForm == NormalizationForm.FormD ||
- normalizationForm == NormalizationForm.FormKD)
- return this;
- }
- return Normalization.Normalize(this, normalizationForm);
- }
-
- private unsafe bool IsAscii()
- {
- fixed (char* str = &_firstChar)
- {
- return ASCIIUtility.GetIndexOfFirstNonAsciiChar(str, (uint)Length) == (uint)Length;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/StringComparer.cs b/netcore/System.Private.CoreLib/shared/System/StringComparer.cs
deleted file mode 100644
index 32f41612055..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/StringComparer.cs
+++ /dev/null
@@ -1,358 +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 System.Collections;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public abstract class StringComparer : IComparer, IEqualityComparer, IComparer<string?>, IEqualityComparer<string?>
- {
- private static readonly CultureAwareComparer s_invariantCulture = new CultureAwareComparer(CultureInfo.InvariantCulture, CompareOptions.None);
- private static readonly CultureAwareComparer s_invariantCultureIgnoreCase = new CultureAwareComparer(CultureInfo.InvariantCulture, CompareOptions.IgnoreCase);
- private static readonly OrdinalCaseSensitiveComparer s_ordinal = new OrdinalCaseSensitiveComparer();
- private static readonly OrdinalIgnoreCaseComparer s_ordinalIgnoreCase = new OrdinalIgnoreCaseComparer();
-
- public static StringComparer InvariantCulture => s_invariantCulture;
-
- public static StringComparer InvariantCultureIgnoreCase => s_invariantCultureIgnoreCase;
-
- public static StringComparer CurrentCulture =>
- new CultureAwareComparer(CultureInfo.CurrentCulture, CompareOptions.None);
-
- public static StringComparer CurrentCultureIgnoreCase =>
- new CultureAwareComparer(CultureInfo.CurrentCulture, CompareOptions.IgnoreCase);
-
- public static StringComparer Ordinal => s_ordinal;
-
- public static StringComparer OrdinalIgnoreCase => s_ordinalIgnoreCase;
-
- // Convert a StringComparison to a StringComparer
- public static StringComparer FromComparison(StringComparison comparisonType)
- {
- return comparisonType switch
- {
- StringComparison.CurrentCulture => CurrentCulture,
- StringComparison.CurrentCultureIgnoreCase => CurrentCultureIgnoreCase,
- StringComparison.InvariantCulture => InvariantCulture,
- StringComparison.InvariantCultureIgnoreCase => InvariantCultureIgnoreCase,
- StringComparison.Ordinal => Ordinal,
- StringComparison.OrdinalIgnoreCase => OrdinalIgnoreCase,
- _ => throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType)),
- };
- }
-
- public static StringComparer Create(CultureInfo culture, bool ignoreCase)
- {
- if (culture == null)
- {
- throw new ArgumentNullException(nameof(culture));
- }
-
- return new CultureAwareComparer(culture, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
- }
-
- public static StringComparer Create(CultureInfo culture, CompareOptions options)
- {
- if (culture == null)
- {
- throw new ArgumentNullException(nameof(culture));
- }
-
- return new CultureAwareComparer(culture, options);
- }
-
- public int Compare(object? x, object? y)
- {
- if (x == y) return 0;
- if (x == null) return -1;
- if (y == null) return 1;
-
- if (x is string sa)
- {
- if (y is string sb)
- {
- return Compare(sa, sb);
- }
- }
-
- if (x is IComparable ia)
- {
- return ia.CompareTo(y);
- }
-
- throw new ArgumentException(SR.Argument_ImplementIComparable);
- }
-
- public new bool Equals(object? x, object? y)
- {
- if (x == y) return true;
- if (x == null || y == null) return false;
-
- if (x is string sa)
- {
- if (y is string sb)
- {
- return Equals(sa, sb);
- }
- }
- return x.Equals(y);
- }
-
- public int GetHashCode(object obj)
- {
- if (obj == null)
- {
- throw new ArgumentNullException(nameof(obj));
- }
-
- if (obj is string s)
- {
- return GetHashCode(s);
- }
- return obj.GetHashCode();
- }
-
- public abstract int Compare(string? x, string? y);
- public abstract bool Equals(string? x, string? y);
-#pragma warning disable CS8614 // Remove warning disable when nullable attributes are respected
- public abstract int GetHashCode(string obj);
-#pragma warning restore CS8614
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class CultureAwareComparer : StringComparer, ISerializable
- {
- private const CompareOptions ValidCompareMaskOffFlags = ~(CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreWidth | CompareOptions.IgnoreKanaType | CompareOptions.StringSort);
-
- private readonly CompareInfo _compareInfo; // Do not rename (binary serialization)
- private readonly CompareOptions _options;
-
- internal CultureAwareComparer(CultureInfo culture, CompareOptions options) : this(culture.CompareInfo, options) { }
-
- internal CultureAwareComparer(CompareInfo compareInfo, CompareOptions options)
- {
- _compareInfo = compareInfo;
-
- if ((options & ValidCompareMaskOffFlags) != 0)
- {
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
- }
- _options = options;
- }
-
- private CultureAwareComparer(SerializationInfo info, StreamingContext context)
- {
- _compareInfo = (CompareInfo)info.GetValue("_compareInfo", typeof(CompareInfo))!;
- bool ignoreCase = info.GetBoolean("_ignoreCase");
-
- object? obj = info.GetValueNoThrow("_options", typeof(CompareOptions));
- if (obj != null)
- _options = (CompareOptions)obj;
-
- // fix up the _options value in case we are getting old serialized object not having _options
- _options |= ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None;
- }
-
- public override int Compare(string? x, string? y)
- {
- if (object.ReferenceEquals(x, y)) return 0;
- if (x == null) return -1;
- if (y == null) return 1;
- return _compareInfo.Compare(x, y, _options);
- }
-
- public override bool Equals(string? x, string? y)
- {
- if (object.ReferenceEquals(x, y)) return true;
- if (x == null || y == null) return false;
- return _compareInfo.Compare(x, y, _options) == 0;
- }
-
- public override int GetHashCode(string obj)
- {
- if (obj == null)
- {
- throw new ArgumentNullException(nameof(obj));
- }
- return _compareInfo.GetHashCodeOfString(obj, _options);
- }
-
- // Equals method for the comparer itself.
- public override bool Equals(object? obj)
- {
- return
- obj is CultureAwareComparer comparer &&
- _options == comparer._options &&
- _compareInfo.Equals(comparer._compareInfo);
- }
-
- public override int GetHashCode()
- {
- return _compareInfo.GetHashCode() ^ ((int)_options & 0x7FFFFFFF);
- }
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- info.AddValue("_compareInfo", _compareInfo);
- info.AddValue("_options", _options);
- info.AddValue("_ignoreCase", (_options & CompareOptions.IgnoreCase) != 0);
- }
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class OrdinalComparer : StringComparer
- {
- private readonly bool _ignoreCase; // Do not rename (binary serialization)
-
- internal OrdinalComparer(bool ignoreCase)
- {
- _ignoreCase = ignoreCase;
- }
-
- public override int Compare(string? x, string? y)
- {
- if (ReferenceEquals(x, y))
- return 0;
- if (x == null)
- return -1;
- if (y == null)
- return 1;
-
- if (_ignoreCase)
- {
- return string.Compare(x, y, StringComparison.OrdinalIgnoreCase);
- }
-
- return string.CompareOrdinal(x, y);
- }
-
- public override bool Equals(string? x, string? y)
- {
- if (ReferenceEquals(x, y))
- return true;
- if (x == null || y == null)
- return false;
-
- if (_ignoreCase)
- {
- if (x.Length != y.Length)
- {
- return false;
- }
- return CompareInfo.EqualsOrdinalIgnoreCase(ref x.GetRawStringData(), ref y.GetRawStringData(), x.Length);
- }
- return x.Equals(y);
- }
-
- public override int GetHashCode(string obj)
- {
- if (obj == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.obj);
- }
-
- if (_ignoreCase)
- {
- return obj.GetHashCodeOrdinalIgnoreCase();
- }
-
- return obj.GetHashCode();
- }
-
- // Equals method for the comparer itself.
- public override bool Equals(object? obj)
- {
- if (!(obj is OrdinalComparer comparer))
- {
- return false;
- }
- return this._ignoreCase == comparer._ignoreCase;
- }
-
- public override int GetHashCode()
- {
- int hashCode = nameof(OrdinalComparer).GetHashCode();
- return _ignoreCase ? (~hashCode) : hashCode;
- }
- }
-
- [Serializable]
- internal sealed class OrdinalCaseSensitiveComparer : OrdinalComparer, ISerializable
- {
- public OrdinalCaseSensitiveComparer() : base(false)
- {
- }
-
- public override int Compare(string? x, string? y) => string.CompareOrdinal(x, y);
-
- public override bool Equals(string? x, string? y) => string.Equals(x, y);
-
- public override int GetHashCode(string obj)
- {
- if (obj == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.obj);
- }
- return obj.GetHashCode();
- }
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- info.SetType(typeof(OrdinalComparer));
- info.AddValue("_ignoreCase", false);
- }
- }
-
- [Serializable]
- internal sealed class OrdinalIgnoreCaseComparer : OrdinalComparer, ISerializable
- {
- public OrdinalIgnoreCaseComparer() : base(true)
- {
- }
-
- public override int Compare(string? x, string? y) => string.Compare(x, y, StringComparison.OrdinalIgnoreCase);
-
- public override bool Equals(string? x, string? y)
- {
- if (ReferenceEquals(x, y))
- {
- return true;
- }
-
- if (x is null || y is null)
- {
- return false;
- }
-
- if (x.Length != y.Length)
- {
- return false;
- }
-
- return CompareInfo.EqualsOrdinalIgnoreCase(ref x.GetRawStringData(), ref y.GetRawStringData(), x.Length);
- }
-
- public override int GetHashCode(string obj)
- {
- if (obj == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.obj);
- }
- return obj.GetHashCodeOrdinalIgnoreCase();
- }
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- info.SetType(typeof(OrdinalComparer));
- info.AddValue("_ignoreCase", true);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/StringComparison.cs b/netcore/System.Private.CoreLib/shared/System/StringComparison.cs
deleted file mode 100644
index d5c18c8021e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/StringComparison.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System
-{
- public enum StringComparison
- {
- CurrentCulture = 0,
- CurrentCultureIgnoreCase = 1,
- InvariantCulture = 2,
- InvariantCultureIgnoreCase = 3,
- Ordinal = 4,
- OrdinalIgnoreCase = 5,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/StringSplitOptions.cs b/netcore/System.Private.CoreLib/shared/System/StringSplitOptions.cs
deleted file mode 100644
index d7020559a1d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/StringSplitOptions.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System
-{
- [Flags]
- public enum StringSplitOptions
- {
- None = 0,
- RemoveEmptyEntries = 1
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/SystemException.cs b/netcore/System.Private.CoreLib/shared/System/SystemException.cs
deleted file mode 100644
index faf05c68e71..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/SystemException.cs
+++ /dev/null
@@ -1,35 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class SystemException : Exception
- {
- public SystemException()
- : base(SR.Arg_SystemException)
- {
- HResult = HResults.COR_E_SYSTEM;
- }
-
- public SystemException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_SYSTEM;
- }
-
- public SystemException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_SYSTEM;
- }
-
- protected SystemException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/ASCIIEncoding.cs b/netcore/System.Private.CoreLib/shared/System/Text/ASCIIEncoding.cs
deleted file mode 100644
index 9fc31980da8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/ASCIIEncoding.cs
+++ /dev/null
@@ -1,879 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Text
-{
- // ASCIIEncoding
- //
- // Note that ASCIIEncoding is optimized with no best fit and ? for fallback.
- // It doesn't come in other flavors.
- //
- // Note: ASCIIEncoding is the only encoding that doesn't do best fit (windows has best fit).
- //
- // Note: IsAlwaysNormalized remains false because 1/2 the code points are unassigned, so they'd
- // use fallbacks, and we cannot guarantee that fallbacks are normalized.
-
- public partial class ASCIIEncoding : Encoding
- {
- // This specialized sealed type has two benefits:
- // 1) it allows for devirtualization (see https://github.com/dotnet/coreclr/pull/9230), and
- // 2) it allows us to provide highly optimized implementations of certain routines because
- // we can make assumptions about the fallback mechanisms in use (in particular, always
- // replace with "?").
- //
- // (We don't take advantage of #2 yet, but we can do so in the future because the implementation
- // of cloning below allows us to make assumptions about the behaviors of the sealed type.)
- internal sealed class ASCIIEncodingSealed : ASCIIEncoding
- {
- public override object Clone()
- {
- // The base implementation of Encoding.Clone calls object.MemberwiseClone and marks the new object mutable.
- // We don't want to do this because it violates the invariants we have set for the sealed type.
- // Instead, we'll create a new instance of the base ASCIIEncoding type and mark it mutable.
-
- return new ASCIIEncoding()
- {
- IsReadOnly = false
- };
- }
- }
-
- // Used by Encoding.ASCII for lazy initialization
- // The initialization code will not be run until a static member of the class is referenced
- internal static readonly ASCIIEncodingSealed s_default = new ASCIIEncodingSealed();
-
- public ASCIIEncoding() : base(Encoding.CodePageASCII)
- {
- }
-
- internal sealed override void SetDefaultFallbacks()
- {
- // For ASCIIEncoding we just use default replacement fallback
- this.encoderFallback = EncoderFallback.ReplacementFallback;
- this.decoderFallback = DecoderFallback.ReplacementFallback;
- }
-
- // WARNING: GetByteCount(string chars), GetBytes(string chars,...), and GetString(byte[] byteIndex...)
- // WARNING: have different variable names than EncodingNLS.cs, so this can't just be cut & pasted,
- // WARNING: or it'll break VB's way of calling these.
- //
- // The following methods are copied from EncodingNLS.cs.
- // Unfortunately EncodingNLS.cs is internal and we're public, so we have to re-implement them here.
- // These should be kept in sync for the following classes:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- // Returns the number of bytes required to encode a range of characters in
- // a character array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetByteCount(char[] chars, int index, int count)
- {
- // Validate input parameters
-
- if (chars is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.chars, ExceptionResource.ArgumentNull_Array);
- }
-
- if ((index | count) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (chars!.Length - index < count)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
- }
-
- fixed (char* pChars = chars)
- {
- return GetByteCountCommon(pChars + index, count);
- }
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetByteCount(string chars)
- {
- // Validate input parameters
-
- if (chars is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.chars);
- }
-
- fixed (char* pChars = chars)
- {
- return GetByteCountCommon(pChars, chars!.Length);
- }
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetByteCount(char* chars, int count)
- {
- // Validate Parameters
-
- if (chars == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.chars);
- }
-
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return GetByteCountCommon(chars, count);
- }
-
- public override unsafe int GetByteCount(ReadOnlySpan<char> chars)
- {
- // It's ok for us to pass null pointers down to the workhorse below.
-
- fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
- {
- return GetByteCountCommon(charsPtr, chars.Length);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private unsafe int GetByteCountCommon(char* pChars, int charCount)
- {
- // Common helper method for all non-EncoderNLS entry points to GetByteCount.
- // A modification of this method should be copied in to each of the supported encodings: ASCII, UTF8, UTF16, UTF32.
-
- Debug.Assert(charCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pChars != null || charCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
-
- // First call into the fast path.
-
- int totalByteCount = GetByteCountFast(pChars, charCount, EncoderFallback, out int charsConsumed);
-
- if (charsConsumed != charCount)
- {
- // If there's still data remaining in the source buffer, go down the fallback path.
- // We need to check for integer overflow since the fallback could change the required
- // output count in unexpected ways.
-
- totalByteCount += GetByteCountWithFallback(pChars, charCount, charsConsumed);
- if (totalByteCount < 0)
- {
- ThrowConversionOverflow();
- }
- }
-
- return totalByteCount;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetByteCountCommon
- private protected sealed override unsafe int GetByteCountFast(char* pChars, int charsLength, EncoderFallback? fallback, out int charsConsumed)
- {
- // First: Can we short-circuit the entire calculation?
- // If an EncoderReplacementFallback is in use, all non-ASCII chars
- // (including surrogate halves) are replaced with the default string.
- // If the default string consists of a single ASCII value, then we
- // know there's a 1:1 char->byte transcoding in all cases.
-
- int byteCount = charsLength;
-
- if (!(fallback is EncoderReplacementFallback replacementFallback
- && replacementFallback.MaxCharCount == 1
- && replacementFallback.DefaultString[0] <= 0x7F))
- {
- // Unrecognized fallback mechanism - count chars manually.
-
- byteCount = (int)ASCIIUtility.GetIndexOfFirstNonAsciiChar(pChars, (uint)charsLength);
- }
-
- charsConsumed = byteCount;
- return byteCount;
- }
-
- // Parent method is safe.
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- public override unsafe int GetBytes(string chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- // Validate Parameters
-
- if (chars is null || bytes is null)
- {
- ThrowHelper.ThrowArgumentNullException(
- argument: (chars is null) ? ExceptionArgument.chars : ExceptionArgument.bytes,
- resource: ExceptionResource.ArgumentNull_Array);
- }
-
- if ((charIndex | charCount) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (charIndex < 0) ? ExceptionArgument.charIndex : ExceptionArgument.charCount,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (chars!.Length - charIndex < charCount)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCount);
- }
-
- if ((uint)byteIndex > bytes!.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index);
- }
-
- fixed (char* pChars = chars)
- fixed (byte* pBytes = bytes)
- {
- return GetBytesCommon(pChars + charIndex, charCount, pBytes + byteIndex, bytes.Length - byteIndex);
- }
- }
-
- // Encodes a range of characters in a character array into a range of bytes
- // in a byte array. An exception occurs if the byte array is not large
- // enough to hold the complete encoding of the characters. The
- // GetByteCount method can be used to determine the exact number of
- // bytes that will be produced for a given range of characters.
- // Alternatively, the GetMaxByteCount method can be used to
- // determine the maximum number of bytes that will be produced for a given
- // number of characters, regardless of the actual character values.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- // Validate parameters
-
- if (chars is null || bytes is null)
- {
- ThrowHelper.ThrowArgumentNullException(
- argument: (chars is null) ? ExceptionArgument.chars : ExceptionArgument.bytes,
- resource: ExceptionResource.ArgumentNull_Array);
- }
-
- if ((charIndex | charCount) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (charIndex < 0) ? ExceptionArgument.charIndex : ExceptionArgument.charCount,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (chars!.Length - charIndex < charCount)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCount);
- }
-
- if ((uint)byteIndex > bytes!.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index);
- }
-
- fixed (char* pChars = chars)
- fixed (byte* pBytes = bytes)
- {
- return GetBytesCommon(pChars + charIndex, charCount, pBytes + byteIndex, bytes.Length - byteIndex);
- }
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount)
- {
- // Validate Parameters
-
- if (chars == null || bytes == null)
- {
- ThrowHelper.ThrowArgumentNullException(
- argument: (chars is null) ? ExceptionArgument.chars : ExceptionArgument.bytes,
- resource: ExceptionResource.ArgumentNull_Array);
- }
-
- if ((charCount | byteCount) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (charCount < 0) ? ExceptionArgument.charCount : ExceptionArgument.byteCount,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return GetBytesCommon(chars, charCount, bytes, byteCount);
- }
-
- public override unsafe int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes)
- {
- // It's ok for us to operate on null / empty spans.
-
- fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
- fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
- {
- return GetBytesCommon(charsPtr, chars.Length, bytesPtr, bytes.Length);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private unsafe int GetBytesCommon(char* pChars, int charCount, byte* pBytes, int byteCount)
- {
- // Common helper method for all non-EncoderNLS entry points to GetBytes.
- // A modification of this method should be copied in to each of the supported encodings: ASCII, UTF8, UTF16, UTF32.
-
- Debug.Assert(charCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pChars != null || charCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
- Debug.Assert(byteCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pBytes != null || byteCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
-
- // First call into the fast path.
-
- int bytesWritten = GetBytesFast(pChars, charCount, pBytes, byteCount, out int charsConsumed);
-
- if (charsConsumed == charCount)
- {
- // All elements converted - return immediately.
-
- return bytesWritten;
- }
- else
- {
- // Simple narrowing conversion couldn't operate on entire buffer - invoke fallback.
-
- return GetBytesWithFallback(pChars, charCount, pBytes, byteCount, charsConsumed, bytesWritten);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetBytesCommon
- private protected sealed override unsafe int GetBytesFast(char* pChars, int charsLength, byte* pBytes, int bytesLength, out int charsConsumed)
- {
- int bytesWritten = (int)ASCIIUtility.NarrowUtf16ToAscii(pChars, pBytes, (uint)Math.Min(charsLength, bytesLength));
-
- charsConsumed = bytesWritten;
- return bytesWritten;
- }
-
- private protected sealed override unsafe int GetBytesWithFallback(ReadOnlySpan<char> chars, int originalCharsLength, Span<byte> bytes, int originalBytesLength, EncoderNLS? encoder)
- {
- // We special-case EncoderReplacementFallback if it's telling us to write a single ASCII char,
- // since we believe this to be relatively common and we can handle it more efficiently than
- // the base implementation.
-
- if (((encoder is null) ? this.EncoderFallback : encoder.Fallback) is EncoderReplacementFallback replacementFallback
- && replacementFallback.MaxCharCount == 1
- && replacementFallback.DefaultString[0] <= 0x7F)
- {
- byte replacementByte = (byte)replacementFallback.DefaultString[0];
-
- int numElementsToConvert = Math.Min(chars.Length, bytes.Length);
- int idx = 0;
-
- fixed (char* pChars = &MemoryMarshal.GetReference(chars))
- fixed (byte* pBytes = &MemoryMarshal.GetReference(bytes))
- {
- // In a loop, replace the non-convertible data, then bulk-convert as much as we can.
-
- while (idx < numElementsToConvert)
- {
- pBytes[idx++] = replacementByte;
-
- if (idx < numElementsToConvert)
- {
- idx += (int)ASCIIUtility.NarrowUtf16ToAscii(&pChars[idx], &pBytes[idx], (uint)(numElementsToConvert - idx));
- }
-
- Debug.Assert(idx <= numElementsToConvert, "Somehow went beyond bounds of source or destination buffer?");
- }
- }
-
- // Slice off how much we consumed / wrote.
-
- chars = chars.Slice(numElementsToConvert);
- bytes = bytes.Slice(numElementsToConvert);
- }
-
- // If we couldn't go through our fast fallback mechanism, or if we still have leftover
- // data because we couldn't consume everything in the loop above, we need to go down the
- // slow fallback path.
-
- if (chars.IsEmpty)
- {
- return originalBytesLength - bytes.Length; // total number of bytes written
- }
- else
- {
- return base.GetBytesWithFallback(chars, originalCharsLength, bytes, originalBytesLength, encoder);
- }
- }
-
- // Returns the number of characters produced by decoding a range of bytes
- // in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetCharCount(byte[] bytes, int index, int count)
- {
- // Validate Parameters
-
- if (bytes is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.bytes, ExceptionResource.ArgumentNull_Array);
- }
-
- if ((index | count) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (bytes!.Length - index < count)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
- }
-
- fixed (byte* pBytes = bytes)
- {
- return GetCharCountCommon(pBytes + index, count);
- }
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetCharCount(byte* bytes, int count)
- {
- // Validate Parameters
-
- if (bytes == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.bytes, ExceptionResource.ArgumentNull_Array);
- }
-
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return GetCharCountCommon(bytes, count);
- }
-
- public override unsafe int GetCharCount(ReadOnlySpan<byte> bytes)
- {
- // It's ok for us to pass null pointers down to the workhorse routine.
-
- fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
- {
- return GetCharCountCommon(bytesPtr, bytes.Length);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private unsafe int GetCharCountCommon(byte* pBytes, int byteCount)
- {
- // Common helper method for all non-DecoderNLS entry points to GetCharCount.
- // A modification of this method should be copied in to each of the supported encodings: ASCII, UTF8, UTF16, UTF32.
-
- Debug.Assert(byteCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pBytes != null || byteCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
-
- // First call into the fast path.
-
- int totalCharCount = GetCharCountFast(pBytes, byteCount, DecoderFallback, out int bytesConsumed);
-
- if (bytesConsumed != byteCount)
- {
- // If there's still data remaining in the source buffer, go down the fallback path.
- // We need to check for integer overflow since the fallback could change the required
- // output count in unexpected ways.
-
- totalCharCount += GetCharCountWithFallback(pBytes, byteCount, bytesConsumed);
- if (totalCharCount < 0)
- {
- ThrowConversionOverflow();
- }
- }
-
- return totalCharCount;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetCharCountCommon
- private protected sealed override unsafe int GetCharCountFast(byte* pBytes, int bytesLength, DecoderFallback? fallback, out int bytesConsumed)
- {
- // First: Can we short-circuit the entire calculation?
- // If a DecoderReplacementFallback is in use, all non-ASCII bytes are replaced with
- // the default string. If the default string consists of a single BMP value, then we
- // know there's a 1:1 byte->char transcoding in all cases.
-
- int charCount = bytesLength;
-
- if (!(fallback is DecoderReplacementFallback replacementFallback) || replacementFallback.MaxCharCount != 1)
- {
- // Unrecognized fallback mechanism - count bytes manually.
-
- charCount = (int)ASCIIUtility.GetIndexOfFirstNonAsciiByte(pBytes, (uint)bytesLength);
- }
-
- bytesConsumed = charCount;
- return charCount;
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex)
- {
- // Validate Parameters
-
- if (bytes is null || chars is null)
- {
- ThrowHelper.ThrowArgumentNullException(
- argument: (bytes is null) ? ExceptionArgument.bytes : ExceptionArgument.chars,
- resource: ExceptionResource.ArgumentNull_Array);
- }
-
- if ((byteIndex | byteCount) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (byteIndex < 0) ? ExceptionArgument.byteIndex : ExceptionArgument.byteCount,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (bytes!.Length - byteIndex < byteCount)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
- }
-
- if ((uint)charIndex > (uint)chars!.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_Index);
- }
-
- fixed (byte* pBytes = bytes)
- fixed (char* pChars = chars)
- {
- return GetCharsCommon(pBytes + byteIndex, byteCount, pChars + charIndex, chars.Length - charIndex);
- }
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetChars(byte* bytes, int byteCount, char* chars, int charCount)
- {
- // Validate Parameters
-
- if (bytes is null || chars is null)
- {
- ThrowHelper.ThrowArgumentNullException(
- argument: (bytes is null) ? ExceptionArgument.bytes : ExceptionArgument.chars,
- resource: ExceptionResource.ArgumentNull_Array);
- }
-
- if ((byteCount | charCount) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (byteCount < 0) ? ExceptionArgument.byteCount : ExceptionArgument.charCount,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return GetCharsCommon(bytes, byteCount, chars, charCount);
- }
-
- public override unsafe int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars)
- {
- // It's ok for us to pass null pointers down to the workhorse below.
-
- fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
- fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
- {
- return GetCharsCommon(bytesPtr, bytes.Length, charsPtr, chars.Length);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private unsafe int GetCharsCommon(byte* pBytes, int byteCount, char* pChars, int charCount)
- {
- // Common helper method for all non-DecoderNLS entry points to GetChars.
- // A modification of this method should be copied in to each of the supported encodings: ASCII, UTF8, UTF16, UTF32.
-
- Debug.Assert(byteCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pBytes != null || byteCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
- Debug.Assert(charCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pChars != null || charCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
-
- // First call into the fast path.
-
- int charsWritten = GetCharsFast(pBytes, byteCount, pChars, charCount, out int bytesConsumed);
-
- if (bytesConsumed == byteCount)
- {
- // All elements converted - return immediately.
-
- return charsWritten;
- }
- else
- {
- // Simple narrowing conversion couldn't operate on entire buffer - invoke fallback.
-
- return GetCharsWithFallback(pBytes, byteCount, pChars, charCount, bytesConsumed, charsWritten);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetCharsCommon
- private protected sealed override unsafe int GetCharsFast(byte* pBytes, int bytesLength, char* pChars, int charsLength, out int bytesConsumed)
- {
- int charsWritten = (int)ASCIIUtility.WidenAsciiToUtf16(pBytes, pChars, (uint)Math.Min(bytesLength, charsLength));
-
- bytesConsumed = charsWritten;
- return charsWritten;
- }
-
- private protected sealed override unsafe int GetCharsWithFallback(ReadOnlySpan<byte> bytes, int originalBytesLength, Span<char> chars, int originalCharsLength, DecoderNLS? decoder)
- {
- // We special-case DecoderReplacementFallback if it's telling us to write a single BMP char,
- // since we believe this to be relatively common and we can handle it more efficiently than
- // the base implementation.
-
- if ((decoder is null ? DecoderFallback : decoder.Fallback) is DecoderReplacementFallback replacementFallback
- && replacementFallback.MaxCharCount == 1)
- {
- char replacementChar = replacementFallback.DefaultString[0];
-
- int numElementsToConvert = Math.Min(bytes.Length, chars.Length);
- int idx = 0;
-
- fixed (byte* pBytes = &MemoryMarshal.GetReference(bytes))
- fixed (char* pChars = &MemoryMarshal.GetReference(chars))
- {
- // In a loop, replace the non-convertible data, then bulk-convert as much as we can.
-
- while (idx < numElementsToConvert)
- {
- pChars[idx++] = replacementChar;
-
- if (idx < numElementsToConvert)
- {
- idx += (int)ASCIIUtility.WidenAsciiToUtf16(&pBytes[idx], &pChars[idx], (uint)(numElementsToConvert - idx));
- }
-
- Debug.Assert(idx <= numElementsToConvert, "Somehow went beyond bounds of source or destination buffer?");
- }
- }
-
- // Slice off how much we consumed / wrote.
-
- bytes = bytes.Slice(numElementsToConvert);
- chars = chars.Slice(numElementsToConvert);
- }
-
- // If we couldn't go through our fast fallback mechanism, or if we still have leftover
- // data because we couldn't consume everything in the loop above, we need to go down the
- // slow fallback path.
-
- if (bytes.IsEmpty)
- {
- return originalCharsLength - chars.Length; // total number of chars written
- }
- else
- {
- return base.GetCharsWithFallback(bytes, originalBytesLength, chars, originalCharsLength, decoder);
- }
- }
-
- // Returns a string containing the decoded representation of a range of
- // bytes in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe string GetString(byte[] bytes, int byteIndex, int byteCount)
- {
- // Validate Parameters
-
- if (bytes is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.bytes, ExceptionResource.ArgumentNull_Array);
- }
-
- if ((byteIndex | byteCount) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (byteIndex < 0) ? ExceptionArgument.byteIndex : ExceptionArgument.byteCount,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (bytes!.Length - byteIndex < byteCount)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
- }
-
- // Avoid problems with empty input buffer
- if (byteCount == 0)
- return string.Empty;
-
- fixed (byte* pBytes = bytes)
- {
- return string.CreateStringFromEncoding(pBytes + byteIndex, byteCount, this);
- }
- }
-
- //
- // End of standard methods copied from EncodingNLS.cs
- //
-
- //
- // Beginning of methods used by shared fallback logic.
- //
-
- internal sealed override bool TryGetByteCount(Rune value, out int byteCount)
- {
- if (value.IsAscii)
- {
- byteCount = 1;
- return true;
- }
- else
- {
- byteCount = default;
- return false;
- }
- }
-
- internal sealed override OperationStatus EncodeRune(Rune value, Span<byte> bytes, out int bytesWritten)
- {
- if (value.IsAscii)
- {
- if (!bytes.IsEmpty)
- {
- bytes[0] = (byte)value.Value;
- bytesWritten = 1;
- return OperationStatus.Done;
- }
- else
- {
- bytesWritten = 0;
- return OperationStatus.DestinationTooSmall;
- }
- }
- else
- {
- bytesWritten = 0;
- return OperationStatus.InvalidData;
- }
- }
-
- internal sealed override OperationStatus DecodeFirstRune(ReadOnlySpan<byte> bytes, out Rune value, out int bytesConsumed)
- {
- if (!bytes.IsEmpty)
- {
- byte b = bytes[0];
- if (b <= 0x7F)
- {
- // ASCII byte
-
- value = new Rune(b);
- bytesConsumed = 1;
- return OperationStatus.Done;
- }
- else
- {
- // Non-ASCII byte
-
- value = Rune.ReplacementChar;
- bytesConsumed = 1;
- return OperationStatus.InvalidData;
- }
- }
- else
- {
- // No data to decode
-
- value = Rune.ReplacementChar;
- bytesConsumed = 0;
- return OperationStatus.NeedMoreData;
- }
- }
-
- //
- // End of methods used by shared fallback logic.
- //
-
- public override int GetMaxByteCount(int charCount)
- {
- if (charCount < 0)
- throw new ArgumentOutOfRangeException(nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Characters would be # of characters + 1 in case high surrogate is ? * max fallback
- long byteCount = (long)charCount + 1;
-
- if (EncoderFallback.MaxCharCount > 1)
- byteCount *= EncoderFallback.MaxCharCount;
-
- // 1 to 1 for most characters. Only surrogates with fallbacks have less.
-
- if (byteCount > 0x7fffffff)
- throw new ArgumentOutOfRangeException(nameof(charCount), SR.ArgumentOutOfRange_GetByteCountOverflow);
- return (int)byteCount;
- }
-
-
- public override int GetMaxCharCount(int byteCount)
- {
- if (byteCount < 0)
- throw new ArgumentOutOfRangeException(nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Just return length, SBCS stay the same length because they don't map to surrogate
- long charCount = (long)byteCount;
-
- // 1 to 1 for most characters. Only surrogates with fallbacks have less, unknown fallbacks could be longer.
- if (DecoderFallback.MaxCharCount > 1)
- charCount *= DecoderFallback.MaxCharCount;
-
- if (charCount > 0x7fffffff)
- throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ArgumentOutOfRange_GetCharCountOverflow);
-
- return (int)charCount;
- }
-
- // True if and only if the encoding only uses single byte code points. (Ie, ASCII, 1252, etc)
-
- public override bool IsSingleByte => true;
-
- public override Decoder GetDecoder() => new DecoderNLS(this);
-
-
- public override Encoder GetEncoder() => new EncoderNLS(this);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/ASCIIUtility.Helpers.cs b/netcore/System.Private.CoreLib/shared/System/Text/ASCIIUtility.Helpers.cs
deleted file mode 100644
index 731d52ab822..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/ASCIIUtility.Helpers.cs
+++ /dev/null
@@ -1,108 +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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics.X86;
-
-namespace System.Text
-{
- internal static partial class ASCIIUtility
- {
- /// <summary>
- /// A mask which selects only the high bit of each byte of the given <see cref="uint"/>.
- /// </summary>
- private const uint UInt32HighBitsOnlyMask = 0x80808080u;
-
- /// <summary>
- /// A mask which selects only the high bit of each byte of the given <see cref="ulong"/>.
- /// </summary>
- private const ulong UInt64HighBitsOnlyMask = 0x80808080_80808080ul;
-
- /// <summary>
- /// Returns <see langword="true"/> iff all bytes in <paramref name="value"/> are ASCII.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool AllBytesInUInt32AreAscii(uint value)
- {
- // If the high bit of any byte is set, that byte is non-ASCII.
-
- return (value & UInt32HighBitsOnlyMask) == 0;
- }
-
- /// <summary>
- /// Given a DWORD which represents a four-byte buffer read in machine endianness, and which
- /// the caller has asserted contains a non-ASCII byte *somewhere* in the data, counts the
- /// number of consecutive ASCII bytes starting from the beginning of the buffer. Returns
- /// a value 0 - 3, inclusive. (The caller is responsible for ensuring that the buffer doesn't
- /// contain all-ASCII data.)
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static uint CountNumberOfLeadingAsciiBytesFromUInt32WithSomeNonAsciiData(uint value)
- {
- Debug.Assert(!AllBytesInUInt32AreAscii(value), "Caller shouldn't provide an all-ASCII value.");
-
- // Use BMI1 directly rather than going through BitOperations. We only see a perf gain here
- // if we're able to emit a real tzcnt instruction; the software fallback used by BitOperations
- // is too slow for our purposes since we can provide our own faster, specialized software fallback.
-
- if (Bmi1.IsSupported)
- {
- Debug.Assert(BitConverter.IsLittleEndian);
- return Bmi1.TrailingZeroCount(value & UInt32HighBitsOnlyMask) >> 3;
- }
-
- // Couldn't emit tzcnt, use specialized software fallback.
- // The 'allBytesUpToNowAreAscii' DWORD uses bit twiddling to hold a 1 or a 0 depending
- // on whether all processed bytes were ASCII. Then we accumulate all of the
- // results to calculate how many consecutive ASCII bytes are present.
-
- value = ~value;
-
- if (BitConverter.IsLittleEndian)
- {
- // Read first byte
- value >>= 7;
- uint allBytesUpToNowAreAscii = value & 1;
- uint numAsciiBytes = allBytesUpToNowAreAscii;
-
- // Read second byte
- value >>= 8;
- allBytesUpToNowAreAscii &= value;
- numAsciiBytes += allBytesUpToNowAreAscii;
-
- // Read third byte
- value >>= 8;
- allBytesUpToNowAreAscii &= value;
- numAsciiBytes += allBytesUpToNowAreAscii;
-
- return numAsciiBytes;
- }
- else
- {
- // BinaryPrimitives.ReverseEndianness is only implemented as an intrinsic on
- // little-endian platforms, so using it in this big-endian path would be too
- // expensive. Instead we'll just change how we perform the shifts.
-
- // Read first byte
- value = BitOperations.RotateLeft(value, 1);
- uint allBytesUpToNowAreAscii = value & 1;
- uint numAsciiBytes = allBytesUpToNowAreAscii;
-
- // Read second byte
- value = BitOperations.RotateLeft(value, 8);
- allBytesUpToNowAreAscii &= value;
- numAsciiBytes += allBytesUpToNowAreAscii;
-
- // Read third byte
- value = BitOperations.RotateLeft(value, 8);
- allBytesUpToNowAreAscii &= value;
- numAsciiBytes += allBytesUpToNowAreAscii;
-
- return numAsciiBytes;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/ASCIIUtility.cs b/netcore/System.Private.CoreLib/shared/System/Text/ASCIIUtility.cs
deleted file mode 100644
index 2f8846cc658..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/ASCIIUtility.cs
+++ /dev/null
@@ -1,1732 +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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nint = System.Int64;
-using nuint = System.UInt64;
-#else // BIT64
-using nint = System.Int32;
-using nuint = System.UInt32;
-#endif // BIT64
-
-namespace System.Text
-{
- internal static partial class ASCIIUtility
- {
-#if DEBUG
- static ASCIIUtility()
- {
- Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly.");
- Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly.");
- }
-#endif // DEBUG
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool AllBytesInUInt64AreAscii(ulong value)
- {
- // If the high bit of any byte is set, that byte is non-ASCII.
-
- return (value & UInt64HighBitsOnlyMask) == 0;
- }
-
- /// <summary>
- /// Returns <see langword="true"/> iff all chars in <paramref name="value"/> are ASCII.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool AllCharsInUInt32AreAscii(uint value)
- {
- return (value & ~0x007F007Fu) == 0;
- }
-
- /// <summary>
- /// Returns <see langword="true"/> iff all chars in <paramref name="value"/> are ASCII.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool AllCharsInUInt64AreAscii(ulong value)
- {
- return (value & ~0x007F007F_007F007Ful) == 0;
- }
-
- /// <summary>
- /// Given a DWORD which represents two packed chars in machine-endian order,
- /// <see langword="true"/> iff the first char (in machine-endian order) is ASCII.
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- private static bool FirstCharInUInt32IsAscii(uint value)
- {
- return (BitConverter.IsLittleEndian && (value & 0xFF80u) == 0)
- || (!BitConverter.IsLittleEndian && (value & 0xFF800000u) == 0);
- }
-
- /// <summary>
- /// Returns the index in <paramref name="pBuffer"/> where the first non-ASCII byte is found.
- /// Returns <paramref name="bufferLength"/> if the buffer is empty or all-ASCII.
- /// </summary>
- /// <returns>An ASCII byte is defined as 0x00 - 0x7F, inclusive.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe nuint GetIndexOfFirstNonAsciiByte(byte* pBuffer, nuint bufferLength)
- {
- // If SSE2 is supported, use those specific intrinsics instead of the generic vectorized
- // code below. This has two benefits: (a) we can take advantage of specific instructions like
- // pmovmskb which we know are optimized, and (b) we can avoid downclocking the processor while
- // this method is running.
-
- return (Sse2.IsSupported)
- ? GetIndexOfFirstNonAsciiByte_Sse2(pBuffer, bufferLength)
- : GetIndexOfFirstNonAsciiByte_Default(pBuffer, bufferLength);
- }
-
- private static unsafe nuint GetIndexOfFirstNonAsciiByte_Default(byte* pBuffer, nuint bufferLength)
- {
- // Squirrel away the original buffer reference. This method works by determining the exact
- // byte reference where non-ASCII data begins, so we need this base value to perform the
- // final subtraction at the end of the method to get the index into the original buffer.
-
- byte* pOriginalBuffer = pBuffer;
-
- // Before we drain off byte-by-byte, try a generic vectorized loop.
- // Only run the loop if we have at least two vectors we can pull out.
- // Note use of SBYTE instead of BYTE below; we're using the two's-complement
- // representation of negative integers to act as a surrogate for "is ASCII?".
-
- if (Vector.IsHardwareAccelerated && bufferLength >= 2 * (uint)Vector<sbyte>.Count)
- {
- uint SizeOfVectorInBytes = (uint)Vector<sbyte>.Count; // JIT will make this a const
-
- if (Vector.GreaterThanOrEqualAll(Unsafe.ReadUnaligned<Vector<sbyte>>(pBuffer), Vector<sbyte>.Zero))
- {
- // The first several elements of the input buffer were ASCII. Bump up the pointer to the
- // next aligned boundary, then perform aligned reads from here on out until we find non-ASCII
- // data or we approach the end of the buffer. It's possible we'll reread data; this is ok.
-
- byte* pFinalVectorReadPos = pBuffer + bufferLength - SizeOfVectorInBytes;
- pBuffer = (byte*)(((nuint)pBuffer + SizeOfVectorInBytes) & ~(nuint)(SizeOfVectorInBytes - 1));
-
-#if DEBUG
- long numBytesRead = pBuffer - pOriginalBuffer;
- Debug.Assert(0 < numBytesRead && numBytesRead <= SizeOfVectorInBytes, "We should've made forward progress of at least one byte.");
- Debug.Assert((nuint)numBytesRead <= bufferLength, "We shouldn't have read past the end of the input buffer.");
-#endif
-
- Debug.Assert(pBuffer <= pFinalVectorReadPos, "Should be able to read at least one vector.");
-
- do
- {
- Debug.Assert((nuint)pBuffer % SizeOfVectorInBytes == 0, "Vector read should be aligned.");
- if (Vector.LessThanAny(Unsafe.Read<Vector<sbyte>>(pBuffer), Vector<sbyte>.Zero))
- {
- break; // found non-ASCII data
- }
-
- pBuffer += SizeOfVectorInBytes;
- } while (pBuffer <= pFinalVectorReadPos);
-
- // Adjust the remaining buffer length for the number of elements we just consumed.
-
- bufferLength -= (nuint)pBuffer;
- bufferLength += (nuint)pOriginalBuffer;
- }
- }
-
- // At this point, the buffer length wasn't enough to perform a vectorized search, or we did perform
- // a vectorized search and encountered non-ASCII data. In either case go down a non-vectorized code
- // path to drain any remaining ASCII bytes.
- //
- // We're going to perform unaligned reads, so prefer 32-bit reads instead of 64-bit reads.
- // This also allows us to perform more optimized bit twiddling tricks to count the number of ASCII bytes.
-
- uint currentUInt32;
-
- // Try reading 64 bits at a time in a loop.
-
- for (; bufferLength >= 8; bufferLength -= 8)
- {
- currentUInt32 = Unsafe.ReadUnaligned<uint>(pBuffer);
- uint nextUInt32 = Unsafe.ReadUnaligned<uint>(pBuffer + 4);
-
- if (!AllBytesInUInt32AreAscii(currentUInt32 | nextUInt32))
- {
- // One of these two values contains non-ASCII bytes.
- // Figure out which one it is, then put it in 'current' so that we can drain the ASCII bytes.
-
- if (AllBytesInUInt32AreAscii(currentUInt32))
- {
- currentUInt32 = nextUInt32;
- pBuffer += 4;
- }
-
- goto FoundNonAsciiData;
- }
-
- pBuffer += 8; // consumed 8 ASCII bytes
- }
-
- // From this point forward we don't need to update bufferLength.
- // Try reading 32 bits.
-
- if ((bufferLength & 4) != 0)
- {
- currentUInt32 = Unsafe.ReadUnaligned<uint>(pBuffer);
- if (!AllBytesInUInt32AreAscii(currentUInt32))
- {
- goto FoundNonAsciiData;
- }
-
- pBuffer += 4;
- }
-
- // Try reading 16 bits.
-
- if ((bufferLength & 2) != 0)
- {
- currentUInt32 = Unsafe.ReadUnaligned<ushort>(pBuffer);
- if (!AllBytesInUInt32AreAscii(currentUInt32))
- {
- goto FoundNonAsciiData;
- }
-
- pBuffer += 2;
- }
-
- // Try reading 8 bits
-
- if ((bufferLength & 1) != 0)
- {
- // If the buffer contains non-ASCII data, the comparison below will fail, and
- // we'll end up not incrementing the buffer reference.
-
- if (*(sbyte*)pBuffer >= 0)
- {
- pBuffer++;
- }
- }
-
- Finish:
-
- nuint totalNumBytesRead = (nuint)pBuffer - (nuint)pOriginalBuffer;
- return totalNumBytesRead;
-
- FoundNonAsciiData:
-
- Debug.Assert(!AllBytesInUInt32AreAscii(currentUInt32), "Shouldn't have reached this point if we have an all-ASCII input.");
-
- // The method being called doesn't bother looking at whether the high byte is ASCII. There are only
- // two scenarios: (a) either one of the earlier bytes is not ASCII and the search terminates before
- // we get to the high byte; or (b) all of the earlier bytes are ASCII, so the high byte must be
- // non-ASCII. In both cases we only care about the low 24 bits.
-
- pBuffer += CountNumberOfLeadingAsciiBytesFromUInt32WithSomeNonAsciiData(currentUInt32);
- goto Finish;
- }
-
- private static unsafe nuint GetIndexOfFirstNonAsciiByte_Sse2(byte* pBuffer, nuint bufferLength)
- {
- // JIT turns the below into constants
-
- uint SizeOfVector128 = (uint)Unsafe.SizeOf<Vector128<byte>>();
- nuint MaskOfAllBitsInVector128 = (nuint)(SizeOfVector128 - 1);
-
- Debug.Assert(Sse2.IsSupported, "Should've been checked by caller.");
- Debug.Assert(BitConverter.IsLittleEndian, "SSE2 assumes little-endian.");
-
- uint currentMask, secondMask;
- byte* pOriginalBuffer = pBuffer;
-
- // This method is written such that control generally flows top-to-bottom, avoiding
- // jumps as much as possible in the optimistic case of a large enough buffer and
- // "all ASCII". If we see non-ASCII data, we jump out of the hot paths to targets
- // after all the main logic.
-
- if (bufferLength < SizeOfVector128)
- {
- goto InputBufferLessThanOneVectorInLength; // can't vectorize; drain primitives instead
- }
-
- // Read the first vector unaligned.
-
- currentMask = (uint)Sse2.MoveMask(Sse2.LoadVector128(pBuffer)); // unaligned load
-
- if (currentMask != 0)
- {
- goto FoundNonAsciiDataInCurrentMask;
- }
-
- // If we have less than 32 bytes to process, just go straight to the final unaligned
- // read. There's no need to mess with the loop logic in the middle of this method.
-
- if (bufferLength < 2 * SizeOfVector128)
- {
- goto IncrementCurrentOffsetBeforeFinalUnalignedVectorRead;
- }
-
- // Now adjust the read pointer so that future reads are aligned.
-
- pBuffer = (byte*)(((nuint)pBuffer + SizeOfVector128) & ~(nuint)MaskOfAllBitsInVector128);
-
-#if DEBUG
- long numBytesRead = pBuffer - pOriginalBuffer;
- Debug.Assert(0 < numBytesRead && numBytesRead <= SizeOfVector128, "We should've made forward progress of at least one byte.");
- Debug.Assert((nuint)numBytesRead <= bufferLength, "We shouldn't have read past the end of the input buffer.");
-#endif
-
- // Adjust the remaining length to account for what we just read.
-
- bufferLength += (nuint)pOriginalBuffer;
- bufferLength -= (nuint)pBuffer;
-
- // The buffer is now properly aligned.
- // Read 2 vectors at a time if possible.
-
- if (bufferLength >= 2 * SizeOfVector128)
- {
- byte* pFinalVectorReadPos = (byte*)((nuint)pBuffer + bufferLength - 2 * SizeOfVector128);
-
- // After this point, we no longer need to update the bufferLength value.
-
- do
- {
- Vector128<byte> firstVector = Sse2.LoadAlignedVector128(pBuffer);
- Vector128<byte> secondVector = Sse2.LoadAlignedVector128(pBuffer + SizeOfVector128);
-
- currentMask = (uint)Sse2.MoveMask(firstVector);
- secondMask = (uint)Sse2.MoveMask(secondVector);
-
- if ((currentMask | secondMask) != 0)
- {
- goto FoundNonAsciiDataInInnerLoop;
- }
-
- pBuffer += 2 * SizeOfVector128;
- } while (pBuffer <= pFinalVectorReadPos);
- }
-
- // We have somewhere between 0 and (2 * vector length) - 1 bytes remaining to read from.
- // Since the above loop doesn't update bufferLength, we can't rely on its absolute value.
- // But we _can_ rely on it to tell us how much remaining data must be drained by looking
- // at what bits of it are set. This works because had we updated it within the loop above,
- // we would've been adding 2 * SizeOfVector128 on each iteration, but we only care about
- // bits which are less significant than those that the addition would've acted on.
-
- // If there is fewer than one vector length remaining, skip the next aligned read.
-
- if ((bufferLength & SizeOfVector128) == 0)
- {
- goto DoFinalUnalignedVectorRead;
- }
-
- // At least one full vector's worth of data remains, so we can safely read it.
- // Remember, at this point pBuffer is still aligned.
-
- currentMask = (uint)Sse2.MoveMask(Sse2.LoadAlignedVector128(pBuffer));
- if (currentMask != 0)
- {
- goto FoundNonAsciiDataInCurrentMask;
- }
-
- IncrementCurrentOffsetBeforeFinalUnalignedVectorRead:
-
- pBuffer += SizeOfVector128;
-
- DoFinalUnalignedVectorRead:
-
- if (((byte)bufferLength & MaskOfAllBitsInVector128) != 0)
- {
- // Perform an unaligned read of the last vector.
- // We need to adjust the pointer because we're re-reading data.
-
- pBuffer += (bufferLength & MaskOfAllBitsInVector128) - SizeOfVector128;
-
- currentMask = (uint)Sse2.MoveMask(Sse2.LoadVector128(pBuffer)); // unaligned load
- if (currentMask != 0)
- {
- goto FoundNonAsciiDataInCurrentMask;
- }
-
- pBuffer += SizeOfVector128;
- }
-
- Finish:
-
- return (nuint)pBuffer - (nuint)pOriginalBuffer; // and we're done!
-
- FoundNonAsciiDataInInnerLoop:
-
- // If the current (first) mask isn't the mask that contains non-ASCII data, then it must
- // instead be the second mask. If so, skip the entire first mask and drain ASCII bytes
- // from the second mask.
-
- if (currentMask == 0)
- {
- pBuffer += SizeOfVector128;
- currentMask = secondMask;
- }
-
- FoundNonAsciiDataInCurrentMask:
-
- // The mask contains - from the LSB - a 0 for each ASCII byte we saw, and a 1 for each non-ASCII byte.
- // Tzcnt is the correct operation to count the number of zero bits quickly. If this instruction isn't
- // available, we'll fall back to a normal loop.
-
- Debug.Assert(currentMask != 0, "Shouldn't be here unless we see non-ASCII data.");
- pBuffer += (uint)BitOperations.TrailingZeroCount(currentMask);
-
- goto Finish;
-
- FoundNonAsciiDataInCurrentDWord:
-
- uint currentDWord;
- Debug.Assert(!AllBytesInUInt32AreAscii(currentDWord), "Shouldn't be here unless we see non-ASCII data.");
- pBuffer += CountNumberOfLeadingAsciiBytesFromUInt32WithSomeNonAsciiData(currentDWord);
-
- goto Finish;
-
- InputBufferLessThanOneVectorInLength:
-
- // These code paths get hit if the original input length was less than one vector in size.
- // We can't perform vectorized reads at this point, so we'll fall back to reading primitives
- // directly. Note that all of these reads are unaligned.
-
- Debug.Assert(bufferLength < SizeOfVector128);
-
- // QWORD drain
-
- if ((bufferLength & 8) != 0)
- {
- if (Bmi1.X64.IsSupported)
- {
- // If we can use 64-bit tzcnt to count the number of leading ASCII bytes, prefer it.
-
- ulong candidateUInt64 = Unsafe.ReadUnaligned<ulong>(pBuffer);
- if (!AllBytesInUInt64AreAscii(candidateUInt64))
- {
- // Clear everything but the high bit of each byte, then tzcnt.
- // Remember the / 8 at the end to convert bit count to byte count.
-
- candidateUInt64 &= UInt64HighBitsOnlyMask;
- pBuffer += (nuint)(Bmi1.X64.TrailingZeroCount(candidateUInt64) / 8);
- goto Finish;
- }
- }
- else
- {
- // If we can't use 64-bit tzcnt, no worries. We'll just do 2x 32-bit reads instead.
-
- currentDWord = Unsafe.ReadUnaligned<uint>(pBuffer);
- uint nextDWord = Unsafe.ReadUnaligned<uint>(pBuffer + 4);
-
- if (!AllBytesInUInt32AreAscii(currentDWord | nextDWord))
- {
- // At least one of the values wasn't all-ASCII.
- // We need to figure out which one it was and stick it in the currentMask local.
-
- if (AllBytesInUInt32AreAscii(currentDWord))
- {
- currentDWord = nextDWord; // this one is the culprit
- pBuffer += 4;
- }
-
- goto FoundNonAsciiDataInCurrentDWord;
- }
- }
-
- pBuffer += 8; // successfully consumed 8 ASCII bytes
- }
-
- // DWORD drain
-
- if ((bufferLength & 4) != 0)
- {
- currentDWord = Unsafe.ReadUnaligned<uint>(pBuffer);
-
- if (!AllBytesInUInt32AreAscii(currentDWord))
- {
- goto FoundNonAsciiDataInCurrentDWord;
- }
-
- pBuffer += 4; // successfully consumed 4 ASCII bytes
- }
-
- // WORD drain
- // (We movzx to a DWORD for ease of manipulation.)
-
- if ((bufferLength & 2) != 0)
- {
- currentDWord = Unsafe.ReadUnaligned<ushort>(pBuffer);
-
- if (!AllBytesInUInt32AreAscii(currentDWord))
- {
- // We only care about the 0x0080 bit of the value. If it's not set, then we
- // increment currentOffset by 1. If it's set, we don't increment it at all.
-
- pBuffer += (nuint)((nint)(sbyte)currentDWord >> 7) + 1;
- goto Finish;
- }
-
- pBuffer += 2; // successfully consumed 2 ASCII bytes
- }
-
- // BYTE drain
-
- if ((bufferLength & 1) != 0)
- {
- // sbyte has non-negative value if byte is ASCII.
-
- if (*(sbyte*)(pBuffer) >= 0)
- {
- pBuffer++; // successfully consumed a single byte
- }
- }
-
- goto Finish;
- }
-
- /// <summary>
- /// Returns the index in <paramref name="pBuffer"/> where the first non-ASCII char is found.
- /// Returns <paramref name="bufferLength"/> if the buffer is empty or all-ASCII.
- /// </summary>
- /// <returns>An ASCII char is defined as 0x0000 - 0x007F, inclusive.</returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe nuint GetIndexOfFirstNonAsciiChar(char* pBuffer, nuint bufferLength /* in chars */)
- {
- // If SSE2 is supported, use those specific intrinsics instead of the generic vectorized
- // code below. This has two benefits: (a) we can take advantage of specific instructions like
- // pmovmskb which we know are optimized, and (b) we can avoid downclocking the processor while
- // this method is running.
-
- return (Sse2.IsSupported)
- ? GetIndexOfFirstNonAsciiChar_Sse2(pBuffer, bufferLength)
- : GetIndexOfFirstNonAsciiChar_Default(pBuffer, bufferLength);
- }
-
- private static unsafe nuint GetIndexOfFirstNonAsciiChar_Default(char* pBuffer, nuint bufferLength /* in chars */)
- {
- // Squirrel away the original buffer reference.This method works by determining the exact
- // char reference where non-ASCII data begins, so we need this base value to perform the
- // final subtraction at the end of the method to get the index into the original buffer.
-
- char* pOriginalBuffer = pBuffer;
-
- Debug.Assert(bufferLength <= nuint.MaxValue / sizeof(char));
-
- // Before we drain off char-by-char, try a generic vectorized loop.
- // Only run the loop if we have at least two vectors we can pull out.
-
- if (Vector.IsHardwareAccelerated && bufferLength >= 2 * (uint)Vector<ushort>.Count)
- {
- uint SizeOfVectorInChars = (uint)Vector<ushort>.Count; // JIT will make this a const
- uint SizeOfVectorInBytes = (uint)Vector<byte>.Count; // JIT will make this a const
-
- Vector<ushort> maxAscii = new Vector<ushort>(0x007F);
-
- if (Vector.LessThanOrEqualAll(Unsafe.ReadUnaligned<Vector<ushort>>(pBuffer), maxAscii))
- {
- // The first several elements of the input buffer were ASCII. Bump up the pointer to the
- // next aligned boundary, then perform aligned reads from here on out until we find non-ASCII
- // data or we approach the end of the buffer. It's possible we'll reread data; this is ok.
-
- char* pFinalVectorReadPos = pBuffer + bufferLength - SizeOfVectorInChars;
- pBuffer = (char*)(((nuint)pBuffer + SizeOfVectorInBytes) & ~(nuint)(SizeOfVectorInBytes - 1));
-
-#if DEBUG
- long numCharsRead = pBuffer - pOriginalBuffer;
- Debug.Assert(0 < numCharsRead && numCharsRead <= SizeOfVectorInChars, "We should've made forward progress of at least one char.");
- Debug.Assert((nuint)numCharsRead <= bufferLength, "We shouldn't have read past the end of the input buffer.");
-#endif
-
- Debug.Assert(pBuffer <= pFinalVectorReadPos, "Should be able to read at least one vector.");
-
- do
- {
- Debug.Assert((nuint)pBuffer % SizeOfVectorInChars == 0, "Vector read should be aligned.");
- if (Vector.GreaterThanAny(Unsafe.Read<Vector<ushort>>(pBuffer), maxAscii))
- {
- break; // found non-ASCII data
- }
- pBuffer += SizeOfVectorInChars;
- } while (pBuffer <= pFinalVectorReadPos);
-
- // Adjust the remaining buffer length for the number of elements we just consumed.
-
- bufferLength -= ((nuint)pBuffer - (nuint)pOriginalBuffer) / sizeof(char);
- }
- }
-
- // At this point, the buffer length wasn't enough to perform a vectorized search, or we did perform
- // a vectorized search and encountered non-ASCII data. In either case go down a non-vectorized code
- // path to drain any remaining ASCII chars.
- //
- // We're going to perform unaligned reads, so prefer 32-bit reads instead of 64-bit reads.
- // This also allows us to perform more optimized bit twiddling tricks to count the number of ASCII chars.
-
- uint currentUInt32;
-
- // Try reading 64 bits at a time in a loop.
-
- for (; bufferLength >= 4; bufferLength -= 4) // 64 bits = 4 * 16-bit chars
- {
- currentUInt32 = Unsafe.ReadUnaligned<uint>(pBuffer);
- uint nextUInt32 = Unsafe.ReadUnaligned<uint>(pBuffer + 4 / sizeof(char));
-
- if (!AllCharsInUInt32AreAscii(currentUInt32 | nextUInt32))
- {
- // One of these two values contains non-ASCII chars.
- // Figure out which one it is, then put it in 'current' so that we can drain the ASCII chars.
-
- if (AllCharsInUInt32AreAscii(currentUInt32))
- {
- currentUInt32 = nextUInt32;
- pBuffer += 2;
- }
-
- goto FoundNonAsciiData;
- }
-
- pBuffer += 4; // consumed 4 ASCII chars
- }
-
- // From this point forward we don't need to keep track of the remaining buffer length.
- // Try reading 32 bits.
-
- if ((bufferLength & 2) != 0) // 32 bits = 2 * 16-bit chars
- {
- currentUInt32 = Unsafe.ReadUnaligned<uint>(pBuffer);
- if (!AllCharsInUInt32AreAscii(currentUInt32))
- {
- goto FoundNonAsciiData;
- }
-
- pBuffer += 2;
- }
-
- // Try reading 16 bits.
- // No need to try an 8-bit read after this since we're working with chars.
-
- if ((bufferLength & 1) != 0)
- {
- // If the buffer contains non-ASCII data, the comparison below will fail, and
- // we'll end up not incrementing the buffer reference.
-
- if (*pBuffer <= 0x007F)
- {
- pBuffer++;
- }
- }
-
- Finish:
-
- nuint totalNumBytesRead = (nuint)pBuffer - (nuint)pOriginalBuffer;
- Debug.Assert(totalNumBytesRead % sizeof(char) == 0, "Total number of bytes read should be even since we're working with chars.");
- return totalNumBytesRead / sizeof(char); // convert byte count -> char count before returning
-
- FoundNonAsciiData:
-
- Debug.Assert(!AllCharsInUInt32AreAscii(currentUInt32), "Shouldn't have reached this point if we have an all-ASCII input.");
-
- // We don't bother looking at the second char - only the first char.
-
- if (FirstCharInUInt32IsAscii(currentUInt32))
- {
- pBuffer++;
- }
-
- goto Finish;
- }
-
- private static unsafe nuint GetIndexOfFirstNonAsciiChar_Sse2(char* pBuffer, nuint bufferLength /* in chars */)
- {
- // This method contains logic optimized for both SSE2 and SSE41. Much of the logic in this method
- // will be elided by JIT once we determine which specific ISAs we support.
-
- // Quick check for empty inputs.
-
- if (bufferLength == 0)
- {
- return 0;
- }
-
- // JIT turns the below into constants
-
- uint SizeOfVector128InBytes = (uint)Unsafe.SizeOf<Vector128<byte>>();
- uint SizeOfVector128InChars = SizeOfVector128InBytes / sizeof(char);
-
- Debug.Assert(Sse2.IsSupported, "Should've been checked by caller.");
- Debug.Assert(BitConverter.IsLittleEndian, "SSE2 assumes little-endian.");
-
- Vector128<short> firstVector, secondVector;
- uint currentMask;
- char* pOriginalBuffer = pBuffer;
-
- if (bufferLength < SizeOfVector128InChars)
- {
- goto InputBufferLessThanOneVectorInLength; // can't vectorize; drain primitives instead
- }
-
- // This method is written such that control generally flows top-to-bottom, avoiding
- // jumps as much as possible in the optimistic case of "all ASCII". If we see non-ASCII
- // data, we jump out of the hot paths to targets at the end of the method.
-
- Vector128<short> asciiMaskForPTEST = Vector128.Create(unchecked((short)0xFF80)); // used for PTEST on supported hardware
- Vector128<ushort> asciiMaskForPMINUW = Vector128.Create((ushort)0x0080); // used for PMINUW on supported hardware
- Vector128<short> asciiMaskForPXOR = Vector128.Create(unchecked((short)0x8000)); // used for PXOR
- Vector128<short> asciiMaskForPCMPGTW = Vector128.Create(unchecked((short)0x807F)); // used for PCMPGTW
-
- Debug.Assert(bufferLength <= nuint.MaxValue / sizeof(char));
-
- // Read the first vector unaligned.
-
- firstVector = Sse2.LoadVector128((short*)pBuffer); // unaligned load
-
- if (Sse41.IsSupported)
- {
- // The SSE41-optimized code path works by forcing the 0x0080 bit in each WORD of the vector to be
- // set iff the WORD element has value >= 0x0080 (non-ASCII). Then we'll treat it as a BYTE vector
- // in order to extract the mask.
- currentMask = (uint)Sse2.MoveMask(Sse41.Min(firstVector.AsUInt16(), asciiMaskForPMINUW).AsByte());
- }
- else
- {
- // The SSE2-optimized code path works by forcing each WORD of the vector to be 0xFFFF iff the WORD
- // element has value >= 0x0080 (non-ASCII). Then we'll treat it as a BYTE vector in order to extract
- // the mask.
- currentMask = (uint)Sse2.MoveMask(Sse2.CompareGreaterThan(Sse2.Xor(firstVector, asciiMaskForPXOR), asciiMaskForPCMPGTW).AsByte());
- }
-
- if (currentMask != 0)
- {
- goto FoundNonAsciiDataInCurrentMask;
- }
-
- // If we have less than 32 bytes to process, just go straight to the final unaligned
- // read. There's no need to mess with the loop logic in the middle of this method.
-
- // Adjust the remaining length to account for what we just read.
- // For the remainder of this code path, bufferLength will be in bytes, not chars.
-
- bufferLength <<= 1; // chars to bytes
-
- if (bufferLength < 2 * SizeOfVector128InBytes)
- {
- goto IncrementCurrentOffsetBeforeFinalUnalignedVectorRead;
- }
-
- // Now adjust the read pointer so that future reads are aligned.
-
- pBuffer = (char*)(((nuint)pBuffer + SizeOfVector128InBytes) & ~(nuint)(SizeOfVector128InBytes - 1));
-
-#if DEBUG
- long numCharsRead = pBuffer - pOriginalBuffer;
- Debug.Assert(0 < numCharsRead && numCharsRead <= SizeOfVector128InChars, "We should've made forward progress of at least one char.");
- Debug.Assert((nuint)numCharsRead <= bufferLength, "We shouldn't have read past the end of the input buffer.");
-#endif
-
- // Adjust remaining buffer length.
-
- bufferLength += (nuint)pOriginalBuffer;
- bufferLength -= (nuint)pBuffer;
-
- // The buffer is now properly aligned.
- // Read 2 vectors at a time if possible.
-
- if (bufferLength >= 2 * SizeOfVector128InBytes)
- {
- char* pFinalVectorReadPos = (char*)((nuint)pBuffer + bufferLength - 2 * SizeOfVector128InBytes);
-
- // After this point, we no longer need to update the bufferLength value.
-
- do
- {
- firstVector = Sse2.LoadAlignedVector128((short*)pBuffer);
- secondVector = Sse2.LoadAlignedVector128((short*)pBuffer + SizeOfVector128InChars);
- Vector128<short> combinedVector = Sse2.Or(firstVector, secondVector);
-
- if (Sse41.IsSupported)
- {
- // If a non-ASCII bit is set in any WORD of the combined vector, we have seen non-ASCII data.
- // Jump to the non-ASCII handler to figure out which particular vector contained non-ASCII data.
- if (!Sse41.TestZ(combinedVector, asciiMaskForPTEST))
- {
- goto FoundNonAsciiDataInFirstOrSecondVector;
- }
- }
- else
- {
- // See comment earlier in the method for an explanation of how the below logic works.
- if (Sse2.MoveMask(Sse2.CompareGreaterThan(Sse2.Xor(combinedVector, asciiMaskForPXOR), asciiMaskForPCMPGTW).AsByte()) != 0)
- {
- goto FoundNonAsciiDataInFirstOrSecondVector;
- }
- }
-
- pBuffer += 2 * SizeOfVector128InChars;
- } while (pBuffer <= pFinalVectorReadPos);
- }
-
- // We have somewhere between 0 and (2 * vector length) - 1 bytes remaining to read from.
- // Since the above loop doesn't update bufferLength, we can't rely on its absolute value.
- // But we _can_ rely on it to tell us how much remaining data must be drained by looking
- // at what bits of it are set. This works because had we updated it within the loop above,
- // we would've been adding 2 * SizeOfVector128 on each iteration, but we only care about
- // bits which are less significant than those that the addition would've acted on.
-
- // If there is fewer than one vector length remaining, skip the next aligned read.
- // Remember, at this point bufferLength is measured in bytes, not chars.
-
- if ((bufferLength & SizeOfVector128InBytes) == 0)
- {
- goto DoFinalUnalignedVectorRead;
- }
-
- // At least one full vector's worth of data remains, so we can safely read it.
- // Remember, at this point pBuffer is still aligned.
-
- firstVector = Sse2.LoadAlignedVector128((short*)pBuffer);
-
- if (Sse41.IsSupported)
- {
- // If a non-ASCII bit is set in any WORD of the combined vector, we have seen non-ASCII data.
- // Jump to the non-ASCII handler to figure out which particular vector contained non-ASCII data.
- if (!Sse41.TestZ(firstVector, asciiMaskForPTEST))
- {
- goto FoundNonAsciiDataInFirstVector;
- }
- }
- else
- {
- // See comment earlier in the method for an explanation of how the below logic works.
- currentMask = (uint)Sse2.MoveMask(Sse2.CompareGreaterThan(Sse2.Xor(firstVector, asciiMaskForPXOR), asciiMaskForPCMPGTW).AsByte());
- if (currentMask != 0)
- {
- goto FoundNonAsciiDataInCurrentMask;
- }
- }
-
- IncrementCurrentOffsetBeforeFinalUnalignedVectorRead:
-
- pBuffer += SizeOfVector128InChars;
-
- DoFinalUnalignedVectorRead:
-
- if (((byte)bufferLength & (SizeOfVector128InBytes - 1)) != 0)
- {
- // Perform an unaligned read of the last vector.
- // We need to adjust the pointer because we're re-reading data.
-
- pBuffer = (char*)((byte*)pBuffer + (bufferLength & (SizeOfVector128InBytes - 1)) - SizeOfVector128InBytes);
- firstVector = Sse2.LoadVector128((short*)pBuffer); // unaligned load
-
- if (Sse41.IsSupported)
- {
- // If a non-ASCII bit is set in any WORD of the combined vector, we have seen non-ASCII data.
- // Jump to the non-ASCII handler to figure out which particular vector contained non-ASCII data.
- if (!Sse41.TestZ(firstVector, asciiMaskForPTEST))
- {
- goto FoundNonAsciiDataInFirstVector;
- }
- }
- else
- {
- // See comment earlier in the method for an explanation of how the below logic works.
- currentMask = (uint)Sse2.MoveMask(Sse2.CompareGreaterThan(Sse2.Xor(firstVector, asciiMaskForPXOR), asciiMaskForPCMPGTW).AsByte());
- if (currentMask != 0)
- {
- goto FoundNonAsciiDataInCurrentMask;
- }
- }
-
- pBuffer += SizeOfVector128InChars;
- }
-
- Finish:
-
- Debug.Assert(((nuint)pBuffer - (nuint)pOriginalBuffer) % 2 == 0, "Shouldn't have incremented any pointer by an odd byte count.");
- return ((nuint)pBuffer - (nuint)pOriginalBuffer) / sizeof(char); // and we're done! (remember to adjust for char count)
-
- FoundNonAsciiDataInFirstOrSecondVector:
-
- // We don't know if the first or the second vector contains non-ASCII data. Check the first
- // vector, and if that's all-ASCII then the second vector must be the culprit. Either way
- // we'll make sure the first vector local is the one that contains the non-ASCII data.
-
- // See comment earlier in the method for an explanation of how the below logic works.
- if (Sse41.IsSupported)
- {
- if (!Sse41.TestZ(firstVector, asciiMaskForPTEST))
- {
- goto FoundNonAsciiDataInFirstVector;
- }
- }
- else
- {
- currentMask = (uint)Sse2.MoveMask(Sse2.CompareGreaterThan(Sse2.Xor(firstVector, asciiMaskForPXOR), asciiMaskForPCMPGTW).AsByte());
- if (currentMask != 0)
- {
- goto FoundNonAsciiDataInCurrentMask;
- }
- }
-
- // Wasn't the first vector; must be the second.
-
- pBuffer += SizeOfVector128InChars;
- firstVector = secondVector;
-
- FoundNonAsciiDataInFirstVector:
-
- // See comment earlier in the method for an explanation of how the below logic works.
- if (Sse41.IsSupported)
- {
- currentMask = (uint)Sse2.MoveMask(Sse41.Min(firstVector.AsUInt16(), asciiMaskForPMINUW).AsByte());
- }
- else
- {
- currentMask = (uint)Sse2.MoveMask(Sse2.CompareGreaterThan(Sse2.Xor(firstVector, asciiMaskForPXOR), asciiMaskForPCMPGTW).AsByte());
- }
-
- FoundNonAsciiDataInCurrentMask:
-
- // The mask contains - from the LSB - a 0 for each ASCII byte we saw, and a 1 for each non-ASCII byte.
- // Tzcnt is the correct operation to count the number of zero bits quickly. If this instruction isn't
- // available, we'll fall back to a normal loop. (Even though the original vector used WORD elements,
- // masks work on BYTE elements, and we account for this in the final fixup.)
-
- Debug.Assert(currentMask != 0, "Shouldn't be here unless we see non-ASCII data.");
- pBuffer = (char*)((byte*)pBuffer + (uint)BitOperations.TrailingZeroCount(currentMask));
-
- goto Finish;
-
- FoundNonAsciiDataInCurrentDWord:
-
- uint currentDWord;
- Debug.Assert(!AllCharsInUInt32AreAscii(currentDWord), "Shouldn't be here unless we see non-ASCII data.");
-
- if (FirstCharInUInt32IsAscii(currentDWord))
- {
- pBuffer++; // skip past the ASCII char
- }
-
- goto Finish;
-
- InputBufferLessThanOneVectorInLength:
-
- // These code paths get hit if the original input length was less than one vector in size.
- // We can't perform vectorized reads at this point, so we'll fall back to reading primitives
- // directly. Note that all of these reads are unaligned.
-
- // Reminder: If this code path is hit, bufferLength is still a char count, not a byte count.
- // We skipped the code path that multiplied the count by sizeof(char).
-
- Debug.Assert(bufferLength < SizeOfVector128InChars);
-
- // QWORD drain
-
- if ((bufferLength & 4) != 0)
- {
- if (Bmi1.X64.IsSupported)
- {
- // If we can use 64-bit tzcnt to count the number of leading ASCII chars, prefer it.
-
- ulong candidateUInt64 = Unsafe.ReadUnaligned<ulong>(pBuffer);
- if (!AllCharsInUInt64AreAscii(candidateUInt64))
- {
- // Clear the low 7 bits (the ASCII bits) of each char, then tzcnt.
- // Remember the / 8 at the end to convert bit count to byte count,
- // then the & ~1 at the end to treat a match in the high byte of
- // any char the same as a match in the low byte of that same char.
-
- candidateUInt64 &= 0xFF80FF80_FF80FF80ul;
- pBuffer = (char*)((byte*)pBuffer + ((nuint)(Bmi1.X64.TrailingZeroCount(candidateUInt64) / 8) & ~(nuint)1));
- goto Finish;
- }
- }
- else
- {
- // If we can't use 64-bit tzcnt, no worries. We'll just do 2x 32-bit reads instead.
-
- currentDWord = Unsafe.ReadUnaligned<uint>(pBuffer);
- uint nextDWord = Unsafe.ReadUnaligned<uint>(pBuffer + 4 / sizeof(char));
-
- if (!AllCharsInUInt32AreAscii(currentDWord | nextDWord))
- {
- // At least one of the values wasn't all-ASCII.
- // We need to figure out which one it was and stick it in the currentMask local.
-
- if (AllCharsInUInt32AreAscii(currentDWord))
- {
- currentDWord = nextDWord; // this one is the culprit
- pBuffer += 4 / sizeof(char);
- }
-
- goto FoundNonAsciiDataInCurrentDWord;
- }
- }
-
- pBuffer += 4; // successfully consumed 4 ASCII chars
- }
-
- // DWORD drain
-
- if ((bufferLength & 2) != 0)
- {
- currentDWord = Unsafe.ReadUnaligned<uint>(pBuffer);
-
- if (!AllCharsInUInt32AreAscii(currentDWord))
- {
- goto FoundNonAsciiDataInCurrentDWord;
- }
-
- pBuffer += 2; // successfully consumed 2 ASCII chars
- }
-
- // WORD drain
- // This is the final drain; there's no need for a BYTE drain since our elemental type is 16-bit char.
-
- if ((bufferLength & 1) != 0)
- {
- if (*pBuffer <= 0x007F)
- {
- pBuffer++; // successfully consumed a single char
- }
- }
-
- goto Finish;
- }
-
- /// <summary>
- /// Given a QWORD which represents a buffer of 4 ASCII chars in machine-endian order,
- /// narrows each WORD to a BYTE, then writes the 4-byte result to the output buffer
- /// also in machine-endian order.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void NarrowFourUtf16CharsToAsciiAndWriteToBuffer(ref byte outputBuffer, ulong value)
- {
- Debug.Assert(AllCharsInUInt64AreAscii(value));
-
- if (Bmi2.X64.IsSupported)
- {
- // BMI2 will work regardless of the processor's endianness.
- Unsafe.WriteUnaligned(ref outputBuffer, (uint)Bmi2.X64.ParallelBitExtract(value, 0x00FF00FF_00FF00FFul));
- }
- else
- {
- if (BitConverter.IsLittleEndian)
- {
- outputBuffer = (byte)value;
- value >>= 16;
- Unsafe.Add(ref outputBuffer, 1) = (byte)value;
- value >>= 16;
- Unsafe.Add(ref outputBuffer, 2) = (byte)value;
- value >>= 16;
- Unsafe.Add(ref outputBuffer, 3) = (byte)value;
- }
- else
- {
- Unsafe.Add(ref outputBuffer, 3) = (byte)value;
- value >>= 16;
- Unsafe.Add(ref outputBuffer, 2) = (byte)value;
- value >>= 16;
- Unsafe.Add(ref outputBuffer, 1) = (byte)value;
- value >>= 16;
- outputBuffer = (byte)value;
- }
- }
- }
-
- /// <summary>
- /// Given a DWORD which represents a buffer of 2 ASCII chars in machine-endian order,
- /// narrows each WORD to a BYTE, then writes the 2-byte result to the output buffer also in
- /// machine-endian order.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void NarrowTwoUtf16CharsToAsciiAndWriteToBuffer(ref byte outputBuffer, uint value)
- {
- Debug.Assert(AllCharsInUInt32AreAscii(value));
-
- if (BitConverter.IsLittleEndian)
- {
- outputBuffer = (byte)value;
- Unsafe.Add(ref outputBuffer, 1) = (byte)(value >> 16);
- }
- else
- {
- Unsafe.Add(ref outputBuffer, 1) = (byte)value;
- outputBuffer = (byte)(value >> 16);
- }
- }
-
- /// <summary>
- /// Copies as many ASCII characters (U+0000..U+007F) as possible from <paramref name="pUtf16Buffer"/>
- /// to <paramref name="pAsciiBuffer"/>, stopping when the first non-ASCII character is encountered
- /// or once <paramref name="elementCount"/> elements have been converted. Returns the total number
- /// of elements that were able to be converted.
- /// </summary>
- public static unsafe nuint NarrowUtf16ToAscii(char* pUtf16Buffer, byte* pAsciiBuffer, nuint elementCount)
- {
- nuint currentOffset = 0;
-
- uint utf16Data32BitsHigh = 0, utf16Data32BitsLow = 0;
- ulong utf16Data64Bits = 0;
-
- // If SSE2 is supported, use those specific intrinsics instead of the generic vectorized
- // code below. This has two benefits: (a) we can take advantage of specific instructions like
- // pmovmskb, ptest, vpminuw which we know are optimized, and (b) we can avoid downclocking the
- // processor while this method is running.
-
- if (Sse2.IsSupported)
- {
- Debug.Assert(BitConverter.IsLittleEndian, "Assume little endian if SSE2 is supported.");
-
- if (elementCount >= 2 * (uint)Unsafe.SizeOf<Vector128<byte>>())
- {
- // Since there's overhead to setting up the vectorized code path, we only want to
- // call into it after a quick probe to ensure the next immediate characters really are ASCII.
- // If we see non-ASCII data, we'll jump immediately to the draining logic at the end of the method.
-
- if (IntPtr.Size >= 8)
- {
- utf16Data64Bits = Unsafe.ReadUnaligned<ulong>(pUtf16Buffer);
- if (!AllCharsInUInt64AreAscii(utf16Data64Bits))
- {
- goto FoundNonAsciiDataIn64BitRead;
- }
- }
- else
- {
- utf16Data32BitsHigh = Unsafe.ReadUnaligned<uint>(pUtf16Buffer);
- utf16Data32BitsLow = Unsafe.ReadUnaligned<uint>(pUtf16Buffer + 4 / sizeof(char));
- if (!AllCharsInUInt32AreAscii(utf16Data32BitsHigh | utf16Data32BitsLow))
- {
- goto FoundNonAsciiDataIn64BitRead;
- }
- }
-
- currentOffset = NarrowUtf16ToAscii_Sse2(pUtf16Buffer, pAsciiBuffer, elementCount);
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- uint SizeOfVector = (uint)Unsafe.SizeOf<Vector<byte>>(); // JIT will make this a const
-
- // Only bother vectorizing if we have enough data to do so.
- if (elementCount >= 2 * SizeOfVector)
- {
- // Since there's overhead to setting up the vectorized code path, we only want to
- // call into it after a quick probe to ensure the next immediate characters really are ASCII.
- // If we see non-ASCII data, we'll jump immediately to the draining logic at the end of the method.
-
- if (IntPtr.Size >= 8)
- {
- utf16Data64Bits = Unsafe.ReadUnaligned<ulong>(pUtf16Buffer);
- if (!AllCharsInUInt64AreAscii(utf16Data64Bits))
- {
- goto FoundNonAsciiDataIn64BitRead;
- }
- }
- else
- {
- utf16Data32BitsHigh = Unsafe.ReadUnaligned<uint>(pUtf16Buffer);
- utf16Data32BitsLow = Unsafe.ReadUnaligned<uint>(pUtf16Buffer + 4 / sizeof(char));
- if (!AllCharsInUInt32AreAscii(utf16Data32BitsHigh | utf16Data32BitsLow))
- {
- goto FoundNonAsciiDataIn64BitRead;
- }
- }
-
- Vector<ushort> maxAscii = new Vector<ushort>(0x007F);
-
- nuint finalOffsetWhereCanLoop = elementCount - 2 * SizeOfVector;
- do
- {
- Vector<ushort> utf16VectorHigh = Unsafe.ReadUnaligned<Vector<ushort>>(pUtf16Buffer + currentOffset);
- Vector<ushort> utf16VectorLow = Unsafe.ReadUnaligned<Vector<ushort>>(pUtf16Buffer + currentOffset + Vector<ushort>.Count);
-
- if (Vector.GreaterThanAny(Vector.BitwiseOr(utf16VectorHigh, utf16VectorLow), maxAscii))
- {
- break; // found non-ASCII data
- }
-
- // TODO: Is the below logic also valid for big-endian platforms?
- Vector<byte> asciiVector = Vector.Narrow(utf16VectorHigh, utf16VectorLow);
- Unsafe.WriteUnaligned<Vector<byte>>(pAsciiBuffer + currentOffset, asciiVector);
-
- currentOffset += SizeOfVector;
- } while (currentOffset <= finalOffsetWhereCanLoop);
- }
- }
-
- Debug.Assert(currentOffset <= elementCount);
- nuint remainingElementCount = elementCount - currentOffset;
-
- // Try to narrow 64 bits -> 32 bits at a time.
- // We needn't update remainingElementCount after this point.
-
- if (remainingElementCount >= 4)
- {
- nuint finalOffsetWhereCanLoop = currentOffset + remainingElementCount - 4;
- do
- {
- if (IntPtr.Size >= 8)
- {
- // Only perform QWORD reads on a 64-bit platform.
- utf16Data64Bits = Unsafe.ReadUnaligned<ulong>(pUtf16Buffer + currentOffset);
- if (!AllCharsInUInt64AreAscii(utf16Data64Bits))
- {
- goto FoundNonAsciiDataIn64BitRead;
- }
-
- NarrowFourUtf16CharsToAsciiAndWriteToBuffer(ref pAsciiBuffer[currentOffset], utf16Data64Bits);
- }
- else
- {
- utf16Data32BitsHigh = Unsafe.ReadUnaligned<uint>(pUtf16Buffer + currentOffset);
- utf16Data32BitsLow = Unsafe.ReadUnaligned<uint>(pUtf16Buffer + currentOffset + 4 / sizeof(char));
- if (!AllCharsInUInt32AreAscii(utf16Data32BitsHigh | utf16Data32BitsLow))
- {
- goto FoundNonAsciiDataIn64BitRead;
- }
-
- NarrowTwoUtf16CharsToAsciiAndWriteToBuffer(ref pAsciiBuffer[currentOffset], utf16Data32BitsHigh);
- NarrowTwoUtf16CharsToAsciiAndWriteToBuffer(ref pAsciiBuffer[currentOffset + 2], utf16Data32BitsLow);
- }
-
- currentOffset += 4;
- } while (currentOffset <= finalOffsetWhereCanLoop);
- }
-
- // Try to narrow 32 bits -> 16 bits.
-
- if (((uint)remainingElementCount & 2) != 0)
- {
- utf16Data32BitsHigh = Unsafe.ReadUnaligned<uint>(pUtf16Buffer + currentOffset);
- if (!AllCharsInUInt32AreAscii(utf16Data32BitsHigh))
- {
- goto FoundNonAsciiDataInHigh32Bits;
- }
-
- NarrowTwoUtf16CharsToAsciiAndWriteToBuffer(ref pAsciiBuffer[currentOffset], utf16Data32BitsHigh);
- currentOffset += 2;
- }
-
- // Try to narrow 16 bits -> 8 bits.
-
- if (((uint)remainingElementCount & 1) != 0)
- {
- utf16Data32BitsHigh = pUtf16Buffer[currentOffset];
- if (utf16Data32BitsHigh <= 0x007Fu)
- {
- pAsciiBuffer[currentOffset] = (byte)utf16Data32BitsHigh;
- currentOffset++;
- }
- }
-
- Finish:
-
- return currentOffset;
-
- FoundNonAsciiDataIn64BitRead:
-
- if (IntPtr.Size >= 8)
- {
- // Try checking the first 32 bits of the buffer for non-ASCII data.
- // Regardless, we'll move the non-ASCII data into the utf16Data32BitsHigh local.
-
- if (BitConverter.IsLittleEndian)
- {
- utf16Data32BitsHigh = (uint)utf16Data64Bits;
- }
- else
- {
- utf16Data32BitsHigh = (uint)(utf16Data64Bits >> 32);
- }
-
- if (AllCharsInUInt32AreAscii(utf16Data32BitsHigh))
- {
- NarrowTwoUtf16CharsToAsciiAndWriteToBuffer(ref pAsciiBuffer[currentOffset], utf16Data32BitsHigh);
-
- if (BitConverter.IsLittleEndian)
- {
- utf16Data32BitsHigh = (uint)(utf16Data64Bits >> 32);
- }
- else
- {
- utf16Data32BitsHigh = (uint)utf16Data64Bits;
- }
-
- currentOffset += 2;
- }
- }
- else
- {
- // Need to determine if the high or the low 32-bit value contained non-ASCII data.
- // Regardless, we'll move the non-ASCII data into the utf16Data32BitsHigh local.
-
- if (AllCharsInUInt32AreAscii(utf16Data32BitsHigh))
- {
- NarrowTwoUtf16CharsToAsciiAndWriteToBuffer(ref pAsciiBuffer[currentOffset], utf16Data32BitsHigh);
- utf16Data32BitsHigh = utf16Data32BitsLow;
- currentOffset += 2;
- }
- }
-
- FoundNonAsciiDataInHigh32Bits:
-
- Debug.Assert(!AllCharsInUInt32AreAscii(utf16Data32BitsHigh), "Shouldn't have reached this point if we have an all-ASCII input.");
-
- // There's at most one char that needs to be drained.
-
- if (FirstCharInUInt32IsAscii(utf16Data32BitsHigh))
- {
- if (!BitConverter.IsLittleEndian)
- {
- utf16Data32BitsHigh >>= 16; // move high char down to low char
- }
-
- pAsciiBuffer[currentOffset] = (byte)utf16Data32BitsHigh;
- currentOffset++;
- }
-
- goto Finish;
- }
-
- private static unsafe nuint NarrowUtf16ToAscii_Sse2(char* pUtf16Buffer, byte* pAsciiBuffer, nuint elementCount)
- {
- // This method contains logic optimized for both SSE2 and SSE41. Much of the logic in this method
- // will be elided by JIT once we determine which specific ISAs we support.
-
- // JIT turns the below into constants
-
- uint SizeOfVector128 = (uint)Unsafe.SizeOf<Vector128<byte>>();
- nuint MaskOfAllBitsInVector128 = (nuint)(SizeOfVector128 - 1);
-
- // This method is written such that control generally flows top-to-bottom, avoiding
- // jumps as much as possible in the optimistic case of "all ASCII". If we see non-ASCII
- // data, we jump out of the hot paths to targets at the end of the method.
-
- Debug.Assert(Sse2.IsSupported);
- Debug.Assert(BitConverter.IsLittleEndian);
- Debug.Assert(elementCount >= 2 * SizeOfVector128);
-
- Vector128<short> asciiMaskForPTEST = Vector128.Create(unchecked((short)0xFF80)); // used for PTEST on supported hardware
- Vector128<short> asciiMaskForPXOR = Vector128.Create(unchecked((short)0x8000)); // used for PXOR
- Vector128<short> asciiMaskForPCMPGTW = Vector128.Create(unchecked((short)0x807F)); // used for PCMPGTW
-
- // First, perform an unaligned read of the first part of the input buffer.
-
- Vector128<short> utf16VectorFirst = Sse2.LoadVector128((short*)pUtf16Buffer); // unaligned load
-
- // If there's non-ASCII data in the first 8 elements of the vector, there's nothing we can do.
- // See comments in GetIndexOfFirstNonAsciiChar_Sse2 for information about how this works.
-
- if (Sse41.IsSupported)
- {
- if (!Sse41.TestZ(utf16VectorFirst, asciiMaskForPTEST))
- {
- return 0;
- }
- }
- else
- {
- if (Sse2.MoveMask(Sse2.CompareGreaterThan(Sse2.Xor(utf16VectorFirst, asciiMaskForPXOR), asciiMaskForPCMPGTW).AsByte()) != 0)
- {
- return 0;
- }
- }
-
- // Turn the 8 ASCII chars we just read into 8 ASCII bytes, then copy it to the destination.
-
- Vector128<byte> asciiVector = Sse2.PackUnsignedSaturate(utf16VectorFirst, utf16VectorFirst);
- Sse2.StoreScalar((ulong*)pAsciiBuffer, asciiVector.AsUInt64()); // ulong* calculated here is UNALIGNED
-
- nuint currentOffsetInElements = SizeOfVector128 / 2; // we processed 8 elements so far
-
- // We're going to get the best performance when we have aligned writes, so we'll take the
- // hit of potentially unaligned reads in order to hit this sweet spot.
-
- // pAsciiBuffer points to the start of the destination buffer, immediately before where we wrote
- // the 8 bytes previously. If the 0x08 bit is set at the pinned address, then the 8 bytes we wrote
- // previously mean that the 0x08 bit is *not* set at address &pAsciiBuffer[SizeOfVector128 / 2]. In
- // that case we can immediately back up to the previous aligned boundary and start the main loop.
- // If the 0x08 bit is *not* set at the pinned address, then it means the 0x08 bit *is* set at
- // address &pAsciiBuffer[SizeOfVector128 / 2], and we should perform one more 8-byte write to bump
- // just past the next aligned boundary address.
-
- if (((uint)pAsciiBuffer & (SizeOfVector128 / 2)) == 0)
- {
- // We need to perform one more partial vector write before we can get the alignment we want.
-
- utf16VectorFirst = Sse2.LoadVector128((short*)pUtf16Buffer + currentOffsetInElements); // unaligned load
-
- // See comments earlier in this method for information about how this works.
- if (Sse41.IsSupported)
- {
- if (!Sse41.TestZ(utf16VectorFirst, asciiMaskForPTEST))
- {
- goto Finish;
- }
- }
- else
- {
- if (Sse2.MoveMask(Sse2.CompareGreaterThan(Sse2.Xor(utf16VectorFirst, asciiMaskForPXOR), asciiMaskForPCMPGTW).AsByte()) != 0)
- {
- goto Finish;
- }
- }
-
- // Turn the 8 ASCII chars we just read into 8 ASCII bytes, then copy it to the destination.
- asciiVector = Sse2.PackUnsignedSaturate(utf16VectorFirst, utf16VectorFirst);
- Sse2.StoreScalar((ulong*)(pAsciiBuffer + currentOffsetInElements), asciiVector.AsUInt64()); // ulong* calculated here is UNALIGNED
- }
-
- // Calculate how many elements we wrote in order to get pAsciiBuffer to its next alignment
- // point, then use that as the base offset going forward.
-
- currentOffsetInElements = SizeOfVector128 - ((nuint)pAsciiBuffer & MaskOfAllBitsInVector128);
- Debug.Assert(0 < currentOffsetInElements && currentOffsetInElements <= SizeOfVector128, "We wrote at least 1 byte but no more than a whole vector.");
-
- Debug.Assert(currentOffsetInElements <= elementCount, "Shouldn't have overrun the destination buffer.");
- Debug.Assert(elementCount - currentOffsetInElements >= SizeOfVector128, "We should be able to run at least one whole vector.");
-
- nuint finalOffsetWhereCanRunLoop = elementCount - SizeOfVector128;
- do
- {
- // In a loop, perform two unaligned reads, narrow to a single vector, then aligned write one vector.
-
- utf16VectorFirst = Sse2.LoadVector128((short*)pUtf16Buffer + currentOffsetInElements); // unaligned load
- Vector128<short> utf16VectorSecond = Sse2.LoadVector128((short*)pUtf16Buffer + currentOffsetInElements + SizeOfVector128 / sizeof(short)); // unaligned load
- Vector128<short> combinedVector = Sse2.Or(utf16VectorFirst, utf16VectorSecond);
-
- // See comments in GetIndexOfFirstNonAsciiChar_Sse2 for information about how this works.
- if (Sse41.IsSupported)
- {
- if (!Sse41.TestZ(combinedVector, asciiMaskForPTEST))
- {
- goto FoundNonAsciiDataInLoop;
- }
- }
- else
- {
- if (Sse2.MoveMask(Sse2.CompareGreaterThan(Sse2.Xor(combinedVector, asciiMaskForPXOR), asciiMaskForPCMPGTW).AsByte()) != 0)
- {
- goto FoundNonAsciiDataInLoop;
- }
- }
-
- // Build up the UTF-8 vector and perform the store.
-
- asciiVector = Sse2.PackUnsignedSaturate(utf16VectorFirst, utf16VectorSecond);
-
- Debug.Assert(((nuint)pAsciiBuffer + currentOffsetInElements) % SizeOfVector128 == 0, "Write should be aligned.");
- Sse2.StoreAligned(pAsciiBuffer + currentOffsetInElements, asciiVector); // aligned
-
- currentOffsetInElements += SizeOfVector128;
- } while (currentOffsetInElements <= finalOffsetWhereCanRunLoop);
-
- Finish:
-
- // There might be some ASCII data left over. That's fine - we'll let our caller handle the final drain.
- return currentOffsetInElements;
-
- FoundNonAsciiDataInLoop:
-
- // Can we at least narrow the high vector?
- // See comments in GetIndexOfFirstNonAsciiChar_Sse2 for information about how this works.
- if (Sse41.IsSupported)
- {
- if (!Sse41.TestZ(utf16VectorFirst, asciiMaskForPTEST))
- {
- goto Finish; // found non-ASCII data
- }
- }
- else
- {
- if (Sse2.MoveMask(Sse2.CompareGreaterThan(Sse2.Xor(utf16VectorFirst, asciiMaskForPXOR), asciiMaskForPCMPGTW).AsByte()) != 0)
- {
- goto Finish; // found non-ASCII data
- }
- }
-
- // First part was all ASCII, narrow and aligned write. Note we're only filling in the low half of the vector.
- asciiVector = Sse2.PackUnsignedSaturate(utf16VectorFirst, utf16VectorFirst);
-
- Debug.Assert(((nuint)pAsciiBuffer + currentOffsetInElements) % sizeof(ulong) == 0, "Destination should be ulong-aligned.");
-
- Sse2.StoreScalar((ulong*)(pAsciiBuffer + currentOffsetInElements), asciiVector.AsUInt64()); // ulong* calculated here is aligned
- currentOffsetInElements += SizeOfVector128 / 2;
-
- goto Finish;
- }
-
- /// <summary>
- /// Copies as many ASCII bytes (00..7F) as possible from <paramref name="pAsciiBuffer"/>
- /// to <paramref name="pUtf16Buffer"/>, stopping when the first non-ASCII byte is encountered
- /// or once <paramref name="elementCount"/> elements have been converted. Returns the total number
- /// of elements that were able to be converted.
- /// </summary>
- public static unsafe nuint WidenAsciiToUtf16(byte* pAsciiBuffer, char* pUtf16Buffer, nuint elementCount)
- {
- nuint currentOffset = 0;
-
- // If SSE2 is supported, use those specific intrinsics instead of the generic vectorized
- // code below. This has two benefits: (a) we can take advantage of specific instructions like
- // pmovmskb which we know are optimized, and (b) we can avoid downclocking the processor while
- // this method is running.
-
- if (Sse2.IsSupported)
- {
- if (elementCount >= 2 * (uint)Unsafe.SizeOf<Vector128<byte>>())
- {
- currentOffset = WidenAsciiToUtf16_Sse2(pAsciiBuffer, pUtf16Buffer, elementCount);
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- uint SizeOfVector = (uint)Unsafe.SizeOf<Vector<byte>>(); // JIT will make this a const
-
- // Only bother vectorizing if we have enough data to do so.
- if (elementCount >= SizeOfVector)
- {
- // Note use of SBYTE instead of BYTE below; we're using the two's-complement
- // representation of negative integers to act as a surrogate for "is ASCII?".
-
- nuint finalOffsetWhereCanLoop = elementCount - SizeOfVector;
- do
- {
- Vector<sbyte> asciiVector = Unsafe.ReadUnaligned<Vector<sbyte>>(pAsciiBuffer + currentOffset);
- if (Vector.LessThanAny(asciiVector, Vector<sbyte>.Zero))
- {
- break; // found non-ASCII data
- }
-
- Vector.Widen(Vector.AsVectorByte(asciiVector), out Vector<ushort> utf16LowVector, out Vector<ushort> utf16HighVector);
-
- // TODO: Is the below logic also valid for big-endian platforms?
- Unsafe.WriteUnaligned<Vector<ushort>>(pUtf16Buffer + currentOffset, utf16LowVector);
- Unsafe.WriteUnaligned<Vector<ushort>>(pUtf16Buffer + currentOffset + Vector<ushort>.Count, utf16HighVector);
-
- currentOffset += SizeOfVector;
- } while (currentOffset <= finalOffsetWhereCanLoop);
- }
- }
-
- Debug.Assert(currentOffset <= elementCount);
- nuint remainingElementCount = elementCount - currentOffset;
-
- // Try to widen 32 bits -> 64 bits at a time.
- // We needn't update remainingElementCount after this point.
-
- uint asciiData;
-
- if (remainingElementCount >= 4)
- {
- nuint finalOffsetWhereCanLoop = currentOffset + remainingElementCount - 4;
- do
- {
- asciiData = Unsafe.ReadUnaligned<uint>(pAsciiBuffer + currentOffset);
- if (!AllBytesInUInt32AreAscii(asciiData))
- {
- goto FoundNonAsciiData;
- }
-
- WidenFourAsciiBytesToUtf16AndWriteToBuffer(ref pUtf16Buffer[currentOffset], asciiData);
- currentOffset += 4;
- } while (currentOffset <= finalOffsetWhereCanLoop);
- }
-
- // Try to widen 16 bits -> 32 bits.
-
- if (((uint)remainingElementCount & 2) != 0)
- {
- asciiData = Unsafe.ReadUnaligned<ushort>(pAsciiBuffer + currentOffset);
- if (!AllBytesInUInt32AreAscii(asciiData))
- {
- goto FoundNonAsciiData;
- }
-
- if (BitConverter.IsLittleEndian)
- {
- pUtf16Buffer[currentOffset] = (char)(byte)asciiData;
- pUtf16Buffer[currentOffset + 1] = (char)(asciiData >> 8);
- }
- else
- {
- pUtf16Buffer[currentOffset + 1] = (char)(byte)asciiData;
- pUtf16Buffer[currentOffset] = (char)(asciiData >> 8);
- }
-
- currentOffset += 2;
- }
-
- // Try to widen 8 bits -> 16 bits.
-
- if (((uint)remainingElementCount & 1) != 0)
- {
- asciiData = pAsciiBuffer[currentOffset];
- if (((byte)asciiData & 0x80) != 0)
- {
- goto Finish;
- }
-
- pUtf16Buffer[currentOffset] = (char)asciiData;
- currentOffset++;
- }
-
- Finish:
-
- return currentOffset;
-
- FoundNonAsciiData:
-
- Debug.Assert(!AllBytesInUInt32AreAscii(asciiData), "Shouldn't have reached this point if we have an all-ASCII input.");
-
- // Drain ASCII bytes one at a time.
-
- while (((byte)asciiData & 0x80) == 0)
- {
- pUtf16Buffer[currentOffset] = (char)(byte)asciiData;
- currentOffset++;
- asciiData >>= 8;
- }
-
- goto Finish;
- }
-
- private static unsafe nuint WidenAsciiToUtf16_Sse2(byte* pAsciiBuffer, char* pUtf16Buffer, nuint elementCount)
- {
- // JIT turns the below into constants
-
- uint SizeOfVector128 = (uint)Unsafe.SizeOf<Vector128<byte>>();
- nuint MaskOfAllBitsInVector128 = (nuint)(SizeOfVector128 - 1);
-
- // This method is written such that control generally flows top-to-bottom, avoiding
- // jumps as much as possible in the optimistic case of "all ASCII". If we see non-ASCII
- // data, we jump out of the hot paths to targets at the end of the method.
-
- Debug.Assert(Sse2.IsSupported);
- Debug.Assert(BitConverter.IsLittleEndian);
- Debug.Assert(elementCount >= 2 * SizeOfVector128);
-
- // We're going to get the best performance when we have aligned writes, so we'll take the
- // hit of potentially unaligned reads in order to hit this sweet spot.
-
- Vector128<byte> asciiVector;
- Vector128<byte> utf16FirstHalfVector;
- uint mask;
-
- // First, perform an unaligned read of the first part of the input buffer.
-
- asciiVector = Sse2.LoadVector128(pAsciiBuffer); // unaligned load
- mask = (uint)Sse2.MoveMask(asciiVector);
-
- // If there's non-ASCII data in the first 8 elements of the vector, there's nothing we can do.
-
- if ((byte)mask != 0)
- {
- return 0;
- }
-
- // Then perform an unaligned write of the first part of the input buffer.
-
- Vector128<byte> zeroVector = Vector128<byte>.Zero;
-
- utf16FirstHalfVector = Sse2.UnpackLow(asciiVector, zeroVector);
- Sse2.Store((byte*)pUtf16Buffer, utf16FirstHalfVector); // unaligned
-
- // Calculate how many elements we wrote in order to get pOutputBuffer to its next alignment
- // point, then use that as the base offset going forward. Remember the >> 1 to account for
- // that we wrote chars, not bytes. This means we may re-read data in the next iteration of
- // the loop, but this is ok.
-
- nuint currentOffset = (SizeOfVector128 >> 1) - (((nuint)pUtf16Buffer >> 1) & (MaskOfAllBitsInVector128 >> 1));
- Debug.Assert(0 < currentOffset && currentOffset <= SizeOfVector128 / sizeof(char));
-
- nuint finalOffsetWhereCanRunLoop = elementCount - SizeOfVector128;
-
- do
- {
- // In a loop, perform an unaligned read, widen to two vectors, then aligned write the two vectors.
-
- asciiVector = Sse2.LoadVector128(pAsciiBuffer + currentOffset); // unaligned load
- mask = (uint)Sse2.MoveMask(asciiVector);
-
- if (mask != 0)
- {
- // non-ASCII byte somewhere
- goto NonAsciiDataSeenInInnerLoop;
- }
-
- byte* pStore = (byte*)(pUtf16Buffer + currentOffset);
- Sse2.StoreAligned(pStore, Sse2.UnpackLow(asciiVector, zeroVector));
-
- pStore += SizeOfVector128;
- Sse2.StoreAligned(pStore, Sse2.UnpackHigh(asciiVector, zeroVector));
-
- currentOffset += SizeOfVector128;
- } while (currentOffset <= finalOffsetWhereCanRunLoop);
-
- Finish:
-
- return currentOffset;
-
- NonAsciiDataSeenInInnerLoop:
-
- // Can we at least widen the first part of the vector?
-
- if ((byte)mask == 0)
- {
- // First part was all ASCII, widen
- utf16FirstHalfVector = Sse2.UnpackLow(asciiVector, zeroVector);
- Sse2.StoreAligned((byte*)(pUtf16Buffer + currentOffset), utf16FirstHalfVector);
- currentOffset += SizeOfVector128 / 2;
- }
-
- goto Finish;
- }
-
- /// <summary>
- /// Given a DWORD which represents a buffer of 4 bytes, widens the buffer into 4 WORDs and
- /// writes them to the output buffer with machine endianness.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void WidenFourAsciiBytesToUtf16AndWriteToBuffer(ref char outputBuffer, uint value)
- {
- Debug.Assert(AllBytesInUInt32AreAscii(value));
-
- if (Bmi2.X64.IsSupported)
- {
- // BMI2 will work regardless of the processor's endianness.
- Unsafe.WriteUnaligned(ref Unsafe.As<char, byte>(ref outputBuffer), Bmi2.X64.ParallelBitDeposit(value, 0x00FF00FF_00FF00FFul));
- }
- else
- {
- if (BitConverter.IsLittleEndian)
- {
- outputBuffer = (char)(byte)value;
- value >>= 8;
- Unsafe.Add(ref outputBuffer, 1) = (char)(byte)value;
- value >>= 8;
- Unsafe.Add(ref outputBuffer, 2) = (char)(byte)value;
- value >>= 8;
- Unsafe.Add(ref outputBuffer, 3) = (char)value;
- }
- else
- {
- Unsafe.Add(ref outputBuffer, 3) = (char)(byte)value;
- value >>= 8;
- Unsafe.Add(ref outputBuffer, 2) = (char)(byte)value;
- value >>= 8;
- Unsafe.Add(ref outputBuffer, 1) = (char)(byte)value;
- value >>= 8;
- outputBuffer = (char)value;
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/CodePageDataItem.cs b/netcore/System.Private.CoreLib/shared/System/Text/CodePageDataItem.cs
deleted file mode 100644
index 25184528283..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/CodePageDataItem.cs
+++ /dev/null
@@ -1,32 +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.
-
-namespace System.Text
-{
- internal class CodePageDataItem
- {
- public int UIFamilyCodePage { get; }
- public string WebName { get; }
- public string HeaderName { get; }
- public string BodyName { get; }
- public string DisplayName { get; }
- public uint Flags { get; }
-
- internal CodePageDataItem(
- int uiFamilyCodePage,
- string webName,
- string headerName,
- string bodyName,
- string displayName,
- uint flags)
- {
- UIFamilyCodePage = uiFamilyCodePage;
- WebName = webName;
- HeaderName = headerName;
- BodyName = bodyName;
- DisplayName = displayName;
- Flags = flags;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Decoder.cs b/netcore/System.Private.CoreLib/shared/System/Text/Decoder.cs
deleted file mode 100644
index 9de773cb676..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Decoder.cs
+++ /dev/null
@@ -1,339 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Text
-{
- // A Decoder is used to decode a sequence of blocks of bytes into a
- // sequence of blocks of characters. Following instantiation of a decoder,
- // sequential blocks of bytes are converted into blocks of characters through
- // calls to the GetChars method. The decoder maintains state between the
- // conversions, allowing it to correctly decode byte sequences that span
- // adjacent blocks.
- //
- // Instances of specific implementations of the Decoder abstract base
- // class are typically obtained through calls to the GetDecoder method
- // of Encoding objects.
- //
- public abstract class Decoder
- {
- internal DecoderFallback? _fallback = null;
-
- internal DecoderFallbackBuffer? _fallbackBuffer = null;
-
- protected Decoder()
- {
- // We don't call default reset because default reset probably isn't good if we aren't initialized.
- }
-
- public DecoderFallback? Fallback
- {
- get => _fallback;
- set
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- // Can't change fallback if buffer is wrong
- if (_fallbackBuffer != null && _fallbackBuffer.Remaining > 0)
- throw new ArgumentException(
- SR.Argument_FallbackBufferNotEmpty, nameof(value));
-
- _fallback = value;
- _fallbackBuffer = null;
- }
- }
-
- // Note: we don't test for threading here because async access to Encoders and Decoders
- // doesn't work anyway.
- public DecoderFallbackBuffer FallbackBuffer
- {
- get
- {
- if (_fallbackBuffer == null)
- {
- if (_fallback != null)
- _fallbackBuffer = _fallback.CreateFallbackBuffer();
- else
- _fallbackBuffer = DecoderFallback.ReplacementFallback.CreateFallbackBuffer();
- }
-
- return _fallbackBuffer;
- }
- }
-
- internal bool InternalHasFallbackBuffer => _fallbackBuffer != null;
-
- // Reset the Decoder
- //
- // Normally if we call GetChars() and an error is thrown we don't change the state of the Decoder. This
- // would allow the caller to correct the error condition and try again (such as if they need a bigger buffer.)
- //
- // If the caller doesn't want to try again after GetChars() throws an error, then they need to call Reset().
- //
- // Virtual implementation has to call GetChars with flush and a big enough buffer to clear a 0 byte string
- // We avoid GetMaxCharCount() because a) we can't call the base encoder and b) it might be really big.
- public virtual void Reset()
- {
- byte[] byteTemp = Array.Empty<byte>();
- char[] charTemp = new char[GetCharCount(byteTemp, 0, 0, true)];
- GetChars(byteTemp, 0, 0, charTemp, 0, true);
- _fallbackBuffer?.Reset();
- }
-
- // Returns the number of characters the next call to GetChars will
- // produce if presented with the given range of bytes. The returned value
- // takes into account the state in which the decoder was left following the
- // last call to GetChars. The state of the decoder is not affected
- // by a call to this method.
- //
- public abstract int GetCharCount(byte[] bytes, int index, int count);
-
- public virtual int GetCharCount(byte[] bytes, int index, int count, bool flush)
- {
- return GetCharCount(bytes, index, count);
- }
-
- // We expect this to be the workhorse for NLS Encodings, but for existing
- // ones we need a working (if slow) default implementation)
- [CLSCompliant(false)]
- public virtual unsafe int GetCharCount(byte* bytes, int count, bool flush)
- {
- // Validate input parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- byte[] arrbyte = new byte[count];
- int index;
-
- for (index = 0; index < count; index++)
- arrbyte[index] = bytes[index];
-
- return GetCharCount(arrbyte, 0, count);
- }
-
- public virtual unsafe int GetCharCount(ReadOnlySpan<byte> bytes, bool flush)
- {
- fixed (byte* bytesPtr = &MemoryMarshal.GetNonNullPinnableReference(bytes))
- {
- return GetCharCount(bytesPtr, bytes.Length, flush);
- }
- }
-
- // Decodes a range of bytes in a byte array into a range of characters
- // in a character array. The method decodes byteCount bytes from
- // bytes starting at index byteIndex, storing the resulting
- // characters in chars starting at index charIndex. The
- // decoding takes into account the state in which the decoder was left
- // following the last call to this method.
- //
- // An exception occurs if the character array is not large enough to
- // hold the complete decoding of the bytes. The GetCharCount method
- // can be used to determine the exact number of characters that will be
- // produced for a given range of bytes. Alternatively, the
- // GetMaxCharCount method of the Encoding that produced this
- // decoder can be used to determine the maximum number of characters that
- // will be produced for a given number of bytes, regardless of the actual
- // byte values.
- //
- public abstract int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex);
-
- public virtual int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex, bool flush)
- {
- return GetChars(bytes, byteIndex, byteCount, chars, charIndex);
- }
-
- // We expect this to be the workhorse for NLS Encodings, but for existing
- // ones we need a working (if slow) default implementation)
- //
- // WARNING WARNING WARNING
- //
- // WARNING: If this breaks it could be a security threat. Obviously we
- // call this internally, so you need to make sure that your pointers, counts
- // and indexes are correct when you call this method.
- //
- // In addition, we have internal code, which will be marked as "safe" calling
- // this code. However this code is dependent upon the implementation of an
- // external GetChars() method, which could be overridden by a third party and
- // the results of which cannot be guaranteed. We use that result to copy
- // the char[] to our char* output buffer. If the result count was wrong, we
- // could easily overflow our output buffer. Therefore we do an extra test
- // when we copy the buffer so that we don't overflow charCount either.
- [CLSCompliant(false)]
- public virtual unsafe int GetChars(byte* bytes, int byteCount,
- char* chars, int charCount, bool flush)
- {
- // Validate input parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (byteCount < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(byteCount < 0 ? nameof(byteCount) : nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Get the byte array to convert
- byte[] arrByte = new byte[byteCount];
-
- int index;
- for (index = 0; index < byteCount; index++)
- arrByte[index] = bytes[index];
-
- // Get the char array to fill
- char[] arrChar = new char[charCount];
-
- // Do the work
- int result = GetChars(arrByte, 0, byteCount, arrChar, 0, flush);
-
- Debug.Assert(result <= charCount, "Returned more chars than we have space for");
-
- // Copy the char array
- // WARNING: We MUST make sure that we don't copy too many chars. We can't
- // rely on result because it could be a 3rd party implementation. We need
- // to make sure we never copy more than charCount chars no matter the value
- // of result
- if (result < charCount)
- charCount = result;
-
- // We check both result and charCount so that we don't accidentally overrun
- // our pointer buffer just because of an issue in GetChars
- for (index = 0; index < charCount; index++)
- chars[index] = arrChar[index];
-
- return charCount;
- }
-
- public virtual unsafe int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars, bool flush)
- {
- fixed (byte* bytesPtr = &MemoryMarshal.GetNonNullPinnableReference(bytes))
- fixed (char* charsPtr = &MemoryMarshal.GetNonNullPinnableReference(chars))
- {
- return GetChars(bytesPtr, bytes.Length, charsPtr, chars.Length, flush);
- }
- }
-
- // This method is used when the output buffer might not be large enough.
- // It will decode until it runs out of bytes, and then it will return
- // true if it the entire input was converted. In either case it
- // will also return the number of converted bytes and output characters used.
- // It will only throw a buffer overflow exception if the entire lenght of chars[] is
- // too small to store the next char. (like 0 or maybe 1 or 4 for some encodings)
- // We're done processing this buffer only if completed returns true.
- //
- // Might consider checking Max...Count to avoid the extra counting step.
- //
- // Note that if all of the input bytes are not consumed, then we'll do a /2, which means
- // that its likely that we didn't consume as many bytes as we could have. For some
- // applications this could be slow. (Like trying to exactly fill an output buffer from a bigger stream)
- public virtual void Convert(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex, int charCount, bool flush,
- out int bytesUsed, out int charsUsed, out bool completed)
- {
- // Validate parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars),
- SR.ArgumentNull_Array);
-
- if (byteIndex < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(byteIndex < 0 ? nameof(byteIndex) : nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - byteIndex < byteCount)
- throw new ArgumentOutOfRangeException(nameof(bytes),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(chars),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- bytesUsed = byteCount;
-
- // Its easy to do if it won't overrun our buffer.
- while (bytesUsed > 0)
- {
- if (GetCharCount(bytes, byteIndex, bytesUsed, flush) <= charCount)
- {
- charsUsed = GetChars(bytes, byteIndex, bytesUsed, chars, charIndex, flush);
- completed = (bytesUsed == byteCount &&
- (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0));
- return;
- }
-
- // Try again with 1/2 the count, won't flush then 'cause won't read it all
- flush = false;
- bytesUsed /= 2;
- }
-
- // Oops, we didn't have anything, we'll have to throw an overflow
- throw new ArgumentException(SR.Argument_ConversionOverflow);
- }
-
- // This is the version that uses *.
- // We're done processing this buffer only if completed returns true.
- //
- // Might consider checking Max...Count to avoid the extra counting step.
- //
- // Note that if all of the input bytes are not consumed, then we'll do a /2, which means
- // that its likely that we didn't consume as many bytes as we could have. For some
- // applications this could be slow. (Like trying to exactly fill an output buffer from a bigger stream)
- [CLSCompliant(false)]
- public virtual unsafe void Convert(byte* bytes, int byteCount,
- char* chars, int charCount, bool flush,
- out int bytesUsed, out int charsUsed, out bool completed)
- {
- // Validate input parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (byteCount < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(byteCount < 0 ? nameof(byteCount) : nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Get ready to do it
- bytesUsed = byteCount;
-
- // Its easy to do if it won't overrun our buffer.
- while (bytesUsed > 0)
- {
- if (GetCharCount(bytes, bytesUsed, flush) <= charCount)
- {
- charsUsed = GetChars(bytes, bytesUsed, chars, charCount, flush);
- completed = (bytesUsed == byteCount &&
- (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0));
- return;
- }
-
- // Try again with 1/2 the count, won't flush then 'cause won't read it all
- flush = false;
- bytesUsed /= 2;
- }
-
- // Oops, we didn't have anything, we'll have to throw an overflow
- throw new ArgumentException(SR.Argument_ConversionOverflow);
- }
-
- public virtual unsafe void Convert(ReadOnlySpan<byte> bytes, Span<char> chars, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
- {
- fixed (byte* bytesPtr = &MemoryMarshal.GetNonNullPinnableReference(bytes))
- fixed (char* charsPtr = &MemoryMarshal.GetNonNullPinnableReference(chars))
- {
- Convert(bytesPtr, bytes.Length, charsPtr, chars.Length, flush, out bytesUsed, out charsUsed, out completed);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs
deleted file mode 100644
index 764ff011192..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs
+++ /dev/null
@@ -1,218 +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.
-
-//
-// This is used internally to create best fit behavior as per the original windows best fit behavior.
-//
-
-using System.Diagnostics;
-using System.Threading;
-
-namespace System.Text
-{
- internal sealed class InternalDecoderBestFitFallback : DecoderFallback
- {
- // Our variables
- internal Encoding _encoding;
- internal char[]? _arrayBestFit = null;
- internal char _cReplacement = '?';
-
- internal InternalDecoderBestFitFallback(Encoding encoding)
- {
- // Need to load our replacement characters table.
- _encoding = encoding;
- }
-
- public override DecoderFallbackBuffer CreateFallbackBuffer() =>
- new InternalDecoderBestFitFallbackBuffer(this);
-
- // Maximum number of characters that this instance of this fallback could return
- public override int MaxCharCount => 1;
-
- public override bool Equals(object? value) =>
- value is InternalDecoderBestFitFallback that &&
- _encoding.CodePage == that._encoding.CodePage;
-
- public override int GetHashCode() => _encoding.CodePage;
- }
-
- internal sealed class InternalDecoderBestFitFallbackBuffer : DecoderFallbackBuffer
- {
- // Our variables
- private char _cBestFit = '\0';
- private int _iCount = -1;
- private int _iSize;
- private readonly InternalDecoderBestFitFallback _oFallback;
-
- // Private object for locking instead of locking on a public type for SQL reliability work.
- private static object? s_InternalSyncObject;
- private static object InternalSyncObject
- {
- get
- {
- if (s_InternalSyncObject == null)
- {
- object o = new object();
- Interlocked.CompareExchange<object?>(ref s_InternalSyncObject, o, null);
- }
- return s_InternalSyncObject;
- }
- }
-
- // Constructor
- public InternalDecoderBestFitFallbackBuffer(InternalDecoderBestFitFallback fallback)
- {
- _oFallback = fallback;
-
- if (_oFallback._arrayBestFit == null)
- {
- // Lock so we don't confuse ourselves.
- lock (InternalSyncObject)
- {
- // Double check before we do it again.
- _oFallback._arrayBestFit ??= fallback._encoding.GetBestFitBytesToUnicodeData();
- }
- }
- }
-
- // Fallback methods
- public override bool Fallback(byte[] bytesUnknown, int index)
- {
- // We expect no previous fallback in our buffer
- Debug.Assert(_iCount < 1, "[DecoderReplacementFallbackBuffer.Fallback] Calling fallback without a previously empty buffer");
-
- _cBestFit = TryBestFit(bytesUnknown);
- if (_cBestFit == '\0')
- _cBestFit = _oFallback._cReplacement;
-
- _iCount = _iSize = 1;
-
- return true;
- }
-
- // Default version is overridden in DecoderReplacementFallback.cs
- public override char GetNextChar()
- {
- // We want it to get < 0 because == 0 means that the current/last character is a fallback
- // and we need to detect recursion. We could have a flag but we already have this counter.
- _iCount--;
-
- // Do we have anything left? 0 is now last fallback char, negative is nothing left
- if (_iCount < 0)
- return '\0';
-
- // Need to get it out of the buffer.
- // Make sure it didn't wrap from the fast count-- path
- if (_iCount == int.MaxValue)
- {
- _iCount = -1;
- return '\0';
- }
-
- // Return the best fit character
- return _cBestFit;
- }
-
- public override bool MovePrevious()
- {
- // Exception fallback doesn't have anywhere to back up to.
- if (_iCount >= 0)
- _iCount++;
-
- // Return true if we could do it.
- return _iCount >= 0 && _iCount <= _iSize;
- }
-
- // How many characters left to output?
- public override int Remaining => (_iCount > 0) ? _iCount : 0;
-
- // Clear the buffer
- public override unsafe void Reset()
- {
- _iCount = -1;
- byteStart = null;
- }
-
- // This version just counts the fallback and doesn't actually copy anything.
- internal override unsafe int InternalFallback(byte[] bytes, byte* pBytes)
- // Right now this has both bytes and bytes[], since we might have extra bytes, hence the
- // array, and we might need the index, hence the byte*
- {
- // return our replacement string Length (always 1 for InternalDecoderBestFitFallback, either
- // a best fit char or ?
- return 1;
- }
-
- // private helper methods
- private char TryBestFit(byte[] bytesCheck)
- {
- // Need to figure out our best fit character, low is beginning of array, high is 1 AFTER end of array
- int lowBound = 0;
- Debug.Assert(_oFallback._arrayBestFit != null);
- int highBound = _oFallback._arrayBestFit.Length;
- int index;
- char cCheck;
-
- // Check trivial case first (no best fit)
- if (highBound == 0)
- return '\0';
-
- // If our array is too small or too big we can't check
- if (bytesCheck.Length == 0 || bytesCheck.Length > 2)
- return '\0';
-
- if (bytesCheck.Length == 1)
- cCheck = unchecked((char)bytesCheck[0]);
- else
- cCheck = unchecked((char)((bytesCheck[0] << 8) + bytesCheck[1]));
-
- // Check trivial out of range case
- if (cCheck < _oFallback._arrayBestFit[0] || cCheck > _oFallback._arrayBestFit[highBound - 2])
- return '\0';
-
- // Binary search the array
- int iDiff;
- while ((iDiff = (highBound - lowBound)) > 6)
- {
- // Look in the middle, which is complicated by the fact that we have 2 #s for each pair,
- // so we don't want index to be odd because it must be word aligned.
- // Also note that index can never == highBound (because diff is rounded down)
- index = ((iDiff / 2) + lowBound) & 0xFFFE;
-
- char cTest = _oFallback._arrayBestFit[index];
- if (cTest == cCheck)
- {
- // We found it
- Debug.Assert(index + 1 < _oFallback._arrayBestFit.Length,
- "[InternalDecoderBestFitFallbackBuffer.TryBestFit]Expected replacement character at end of array");
- return _oFallback._arrayBestFit[index + 1];
- }
- else if (cTest < cCheck)
- {
- // We weren't high enough
- lowBound = index;
- }
- else
- {
- // We weren't low enough
- highBound = index;
- }
- }
-
- for (index = lowBound; index < highBound; index += 2)
- {
- if (_oFallback._arrayBestFit[index] == cCheck)
- {
- // We found it
- Debug.Assert(index + 1 < _oFallback._arrayBestFit.Length,
- "[InternalDecoderBestFitFallbackBuffer.TryBestFit]Expected replacement character at end of array");
- return _oFallback._arrayBestFit[index + 1];
- }
- }
-
- // Char wasn't in our table
- return '\0';
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/DecoderExceptionFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/DecoderExceptionFallback.cs
deleted file mode 100644
index 4ea00ef65a8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/DecoderExceptionFallback.cs
+++ /dev/null
@@ -1,113 +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 System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.Runtime.Serialization;
-
-namespace System.Text
-{
- public sealed class DecoderExceptionFallback : DecoderFallback
- {
- public override DecoderFallbackBuffer CreateFallbackBuffer() =>
- new DecoderExceptionFallbackBuffer();
-
- // Maximum number of characters that this instance of this fallback could return
- public override int MaxCharCount => 0;
-
- public override bool Equals(object? value) =>
- value is DecoderExceptionFallback;
-
- public override int GetHashCode() => 879;
- }
-
-
- public sealed class DecoderExceptionFallbackBuffer : DecoderFallbackBuffer
- {
- public override bool Fallback(byte[] bytesUnknown, int index)
- {
- Throw(bytesUnknown, index);
- return true;
- }
-
- public override char GetNextChar() => (char)0;
-
- // Exception fallback doesn't have anywhere to back up to.
- public override bool MovePrevious() => false;
-
- // Exceptions are always empty
- public override int Remaining => 0;
-
- [DoesNotReturn]
- private void Throw(byte[] bytesUnknown, int index)
- {
- bytesUnknown ??= Array.Empty<byte>();
-
- // Create a string representation of our bytes.
- StringBuilder strBytes = new StringBuilder(bytesUnknown.Length * 4);
-
- const int MaxLength = 20;
- for (int i = 0; i < bytesUnknown.Length && i < MaxLength; i++)
- {
- strBytes.Append('[');
- strBytes.Append(bytesUnknown[i].ToString("X2", CultureInfo.InvariantCulture));
- strBytes.Append(']');
- }
-
- // In case the string's really long
- if (bytesUnknown.Length > MaxLength)
- {
- strBytes.Append(" ...");
- }
-
- // Known index
- throw new DecoderFallbackException(
- SR.Format(SR.Argument_InvalidCodePageBytesIndex,
- strBytes, index), bytesUnknown, index);
- }
- }
-
- // Exception for decoding unknown byte sequences.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class DecoderFallbackException : ArgumentException
- {
- private readonly byte[]? _bytesUnknown = null;
- private readonly int _index = 0;
-
- public DecoderFallbackException()
- : base(SR.Arg_ArgumentException)
- {
- HResult = HResults.COR_E_ARGUMENT;
- }
-
- public DecoderFallbackException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_ARGUMENT;
- }
-
- public DecoderFallbackException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_ARGUMENT;
- }
-
- public DecoderFallbackException(string? message, byte[]? bytesUnknown, int index)
- : base(message)
- {
- _bytesUnknown = bytesUnknown;
- _index = index;
- }
-
- private DecoderFallbackException(SerializationInfo serializationInfo, StreamingContext streamingContext)
- : base(serializationInfo, streamingContext)
- {
- }
-
- public byte[]? BytesUnknown => _bytesUnknown;
-
- public int Index => _index;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/DecoderFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/DecoderFallback.cs
deleted file mode 100644
index fda5edce1df..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/DecoderFallback.cs
+++ /dev/null
@@ -1,324 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.Threading;
-
-namespace System.Text
-{
- public abstract class DecoderFallback
- {
- private static DecoderFallback? s_replacementFallback; // Default fallback, uses no best fit & "?"
- private static DecoderFallback? s_exceptionFallback;
-
- public static DecoderFallback ReplacementFallback =>
- s_replacementFallback ?? Interlocked.CompareExchange(ref s_replacementFallback, new DecoderReplacementFallback(), null) ?? s_replacementFallback;
-
-
- public static DecoderFallback ExceptionFallback =>
- s_exceptionFallback ?? Interlocked.CompareExchange<DecoderFallback?>(ref s_exceptionFallback, new DecoderExceptionFallback(), null) ?? s_exceptionFallback;
-
- // Fallback
- //
- // Return the appropriate unicode string alternative to the character that need to fall back.
- // Most implementations will be:
- // return new MyCustomDecoderFallbackBuffer(this);
-
- public abstract DecoderFallbackBuffer CreateFallbackBuffer();
-
- // Maximum number of characters that this instance of this fallback could return
-
- public abstract int MaxCharCount { get; }
- }
-
-
- public abstract class DecoderFallbackBuffer
- {
- // Most implementations will probably need an implementation-specific constructor
-
- // internal methods that cannot be overridden that let us do our fallback thing
- // These wrap the internal methods so that we can check for people doing stuff that's incorrect
-
- public abstract bool Fallback(byte[] bytesUnknown, int index);
-
- // Get next character
-
- public abstract char GetNextChar();
-
- // Back up a character
-
- public abstract bool MovePrevious();
-
- // How many chars left in this fallback?
-
- public abstract int Remaining { get; }
-
- // Clear the buffer
-
- public virtual void Reset()
- {
- while (GetNextChar() != (char)0) ;
- }
-
- // Internal items to help us figure out what we're doing as far as error messages, etc.
- // These help us with our performance and messages internally
- internal unsafe byte* byteStart;
- internal unsafe char* charEnd;
-
- internal Encoding? _encoding;
- internal DecoderNLS? _decoder;
- private int _originalByteCount;
-
- // Internal Reset
- internal unsafe void InternalReset()
- {
- byteStart = null;
- Reset();
- }
-
- // Set the above values
- // This can't be part of the constructor because DecoderFallbacks would have to know how to implement these.
- internal unsafe void InternalInitialize(byte* byteStart, char* charEnd)
- {
- this.byteStart = byteStart;
- this.charEnd = charEnd;
- }
-
- internal static DecoderFallbackBuffer CreateAndInitialize(Encoding encoding, DecoderNLS? decoder, int originalByteCount)
- {
- // The original byte count is only used for keeping track of what 'index' value needs
- // to be passed to the abstract Fallback method. The index value is calculated by subtracting
- // 'bytes.Length' (where bytes is expected to be the entire remaining input buffer)
- // from the 'originalByteCount' value specified here.
-
- DecoderFallbackBuffer fallbackBuffer = (decoder is null) ? encoding.DecoderFallback.CreateFallbackBuffer() : decoder.FallbackBuffer;
-
- fallbackBuffer._encoding = encoding;
- fallbackBuffer._decoder = decoder;
- fallbackBuffer._originalByteCount = originalByteCount;
-
- return fallbackBuffer;
- }
-
- // Fallback the current byte by sticking it into the remaining char buffer.
- // This can only be called by our encodings (other have to use the public fallback methods), so
- // we can use our DecoderNLS here too (except we don't).
- // Returns true if we are successful, false if we can't fallback the character (no buffer space)
- // So caller needs to throw buffer space if return false.
- // Right now this has both bytes and bytes[], since we might have extra bytes, hence the
- // array, and we might need the index, hence the byte*
- // Don't touch ref chars unless we succeed
- internal virtual unsafe bool InternalFallback(byte[] bytes, byte* pBytes, ref char* chars)
- {
- Debug.Assert(byteStart != null, "[DecoderFallback.InternalFallback]Used InternalFallback without calling InternalInitialize");
-
- // See if there's a fallback character and we have an output buffer then copy our string.
- if (this.Fallback(bytes, (int)(pBytes - byteStart - bytes.Length)))
- {
- // Copy the chars to our output
- char ch;
- char* charTemp = chars;
- bool bHighSurrogate = false;
- while ((ch = GetNextChar()) != 0)
- {
- // Make sure no mixed up surrogates
- if (char.IsSurrogate(ch))
- {
- if (char.IsHighSurrogate(ch))
- {
- // High Surrogate
- if (bHighSurrogate)
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex);
- bHighSurrogate = true;
- }
- else
- {
- // Low surrogate
- if (!bHighSurrogate)
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex);
- bHighSurrogate = false;
- }
- }
-
- if (charTemp >= charEnd)
- {
- // No buffer space
- return false;
- }
-
- *(charTemp++) = ch;
- }
-
- // Need to make sure that bHighSurrogate isn't true
- if (bHighSurrogate)
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex);
-
- // Now we aren't going to be false, so its OK to update chars
- chars = charTemp;
- }
-
- return true;
- }
-
- // This version just counts the fallback and doesn't actually copy anything.
- internal virtual unsafe int InternalFallback(byte[] bytes, byte* pBytes)
- // Right now this has both bytes and bytes[], since we might have extra bytes, hence the
- // array, and we might need the index, hence the byte*
- {
- Debug.Assert(byteStart != null, "[DecoderFallback.InternalFallback]Used InternalFallback without calling InternalInitialize");
-
- // See if there's a fallback character and we have an output buffer then copy our string.
- if (this.Fallback(bytes, (int)(pBytes - byteStart - bytes.Length)))
- {
- int count = 0;
-
- char ch;
- bool bHighSurrogate = false;
- while ((ch = GetNextChar()) != 0)
- {
- // Make sure no mixed up surrogates
- if (char.IsSurrogate(ch))
- {
- if (char.IsHighSurrogate(ch))
- {
- // High Surrogate
- if (bHighSurrogate)
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex);
- bHighSurrogate = true;
- }
- else
- {
- // Low surrogate
- if (!bHighSurrogate)
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex);
- bHighSurrogate = false;
- }
- }
-
- count++;
- }
-
- // Need to make sure that bHighSurrogate isn't true
- if (bHighSurrogate)
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex);
-
- return count;
- }
-
- // If no fallback return 0
- return 0;
- }
-
- internal int InternalFallbackGetCharCount(ReadOnlySpan<byte> remainingBytes, int fallbackLength)
- {
- return (Fallback(remainingBytes.Slice(0, fallbackLength).ToArray(), index: _originalByteCount - remainingBytes.Length))
- ? DrainRemainingDataForGetCharCount()
- : 0;
- }
-
- internal bool TryInternalFallbackGetChars(ReadOnlySpan<byte> remainingBytes, int fallbackLength, Span<char> chars, out int charsWritten)
- {
- if (Fallback(remainingBytes.Slice(0, fallbackLength).ToArray(), index: _originalByteCount - remainingBytes.Length))
- {
- return TryDrainRemainingDataForGetChars(chars, out charsWritten);
- }
- else
- {
- // Return true because we weren't asked to write anything, so this is a "success" in the sense that
- // the output buffer was large enough to hold the desired 0 chars of output.
-
- charsWritten = 0;
- return true;
- }
- }
-
- private Rune GetNextRune()
- {
- // Call GetNextChar() and try treating it as a non-surrogate character.
- // If that fails, call GetNextChar() again and attempt to treat the two chars
- // as a surrogate pair. If that still fails, throw an exception since the fallback
- // mechanism is giving us a bad replacement character.
-
- Rune rune;
- char ch = GetNextChar();
- if (!Rune.TryCreate(ch, out rune) && !Rune.TryCreate(ch, GetNextChar(), out rune))
- {
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex);
- }
-
- return rune;
- }
-
- internal int DrainRemainingDataForGetCharCount()
- {
- int totalCharCount = 0;
-
- Rune thisRune;
- while ((thisRune = GetNextRune()).Value != 0)
- {
- // We need to check for overflow while tallying the fallback char count.
-
- totalCharCount += thisRune.Utf16SequenceLength;
- if (totalCharCount < 0)
- {
- InternalReset();
- Encoding.ThrowConversionOverflow();
- }
- }
-
- return totalCharCount;
- }
-
- internal bool TryDrainRemainingDataForGetChars(Span<char> chars, out int charsWritten)
- {
- int originalCharCount = chars.Length;
-
- Rune thisRune;
- while ((thisRune = GetNextRune()).Value != 0)
- {
- if (thisRune.TryEncodeToUtf16(chars, out int charsWrittenJustNow))
- {
- chars = chars.Slice(charsWrittenJustNow);
- continue;
- }
- else
- {
- InternalReset();
- charsWritten = default;
- return false;
- }
- }
-
- charsWritten = originalCharCount - chars.Length;
- return true;
- }
-
- // private helper methods
- [DoesNotReturn]
- internal void ThrowLastBytesRecursive(byte[] bytesUnknown)
- {
- bytesUnknown ??= Array.Empty<byte>();
-
- // Create a string representation of our bytes.
- StringBuilder strBytes = new StringBuilder(bytesUnknown.Length * 3);
- int i;
- for (i = 0; i < bytesUnknown.Length && i < 20; i++)
- {
- if (strBytes.Length > 0)
- strBytes.Append(' ');
- strBytes.AppendFormat(CultureInfo.InvariantCulture, "\\x{0:X2}", bytesUnknown[i]);
- }
- // In case the string's really long
- if (i == 20)
- strBytes.Append(" ...");
-
- // Throw it, using our complete bytes
- throw new ArgumentException(
- SR.Format(SR.Argument_RecursiveFallbackBytes,
- strBytes.ToString()), nameof(bytesUnknown));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/DecoderNLS.cs b/netcore/System.Private.CoreLib/shared/System/Text/DecoderNLS.cs
deleted file mode 100644
index 49aa166b76e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/DecoderNLS.cs
+++ /dev/null
@@ -1,434 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Text
-{
- // A Decoder is used to decode a sequence of blocks of bytes into a
- // sequence of blocks of characters. Following instantiation of a decoder,
- // sequential blocks of bytes are converted into blocks of characters through
- // calls to the GetChars method. The decoder maintains state between the
- // conversions, allowing it to correctly decode byte sequences that span
- // adjacent blocks.
- //
- // Instances of specific implementations of the Decoder abstract base
- // class are typically obtained through calls to the GetDecoder method
- // of Encoding objects.
-
- internal class DecoderNLS : Decoder
- {
- // Remember our encoding
- private readonly Encoding _encoding;
- private bool _mustFlush;
- internal bool _throwOnOverflow;
- internal int _bytesUsed;
- private int _leftoverBytes; // leftover data from a previous invocation of GetChars (up to 4 bytes)
- private int _leftoverByteCount; // number of bytes of actual data in _leftoverBytes
-
- internal DecoderNLS(Encoding encoding)
- {
- _encoding = encoding;
- _fallback = this._encoding.DecoderFallback;
- this.Reset();
- }
-
- public override void Reset()
- {
- ClearLeftoverData();
- _fallbackBuffer?.Reset();
- }
-
- public override int GetCharCount(byte[] bytes, int index, int count)
- {
- return GetCharCount(bytes, index, count, false);
- }
-
- public override unsafe int GetCharCount(byte[] bytes, int index, int count, bool flush)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(bytes),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // Just call pointer version
- fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- return GetCharCount(pBytes + index, count, flush);
- }
-
- public override unsafe int GetCharCount(byte* bytes, int count, bool flush)
- {
- // Validate parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Remember the flush
- _mustFlush = flush;
- _throwOnOverflow = true;
-
- // By default just call the encoding version, no flush by default
- Debug.Assert(_encoding != null);
- return _encoding.GetCharCount(bytes, count, this);
- }
-
- public override int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex)
- {
- return GetChars(bytes, byteIndex, byteCount, chars, charIndex, false);
- }
-
- public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex, bool flush)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars),
- SR.ArgumentNull_Array);
-
- if (byteIndex < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(byteIndex < 0 ? nameof(byteIndex) : nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - byteIndex < byteCount)
- throw new ArgumentOutOfRangeException(nameof(bytes),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (charIndex < 0 || charIndex > chars.Length)
- throw new ArgumentOutOfRangeException(nameof(charIndex),
- SR.ArgumentOutOfRange_Index);
-
- int charCount = chars.Length - charIndex;
-
- // Just call pointer version
- fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
- // Remember that charCount is # to decode, not size of array
- return GetChars(pBytes + byteIndex, byteCount,
- pChars + charIndex, charCount, flush);
- }
-
- public override unsafe int GetChars(byte* bytes, int byteCount,
- char* chars, int charCount, bool flush)
- {
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (byteCount < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(byteCount < 0 ? nameof(byteCount) : nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Remember our flush
- _mustFlush = flush;
- _throwOnOverflow = true;
-
- // By default just call the encodings version
- Debug.Assert(_encoding != null);
- return _encoding.GetChars(bytes, byteCount, chars, charCount, this);
- }
-
- // This method is used when the output buffer might not be big enough.
- // Just call the pointer version. (This gets chars)
- public override unsafe void Convert(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex, int charCount, bool flush,
- out int bytesUsed, out int charsUsed, out bool completed)
- {
- // Validate parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars),
- SR.ArgumentNull_Array);
-
- if (byteIndex < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(byteIndex < 0 ? nameof(byteIndex) : nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - byteIndex < byteCount)
- throw new ArgumentOutOfRangeException(nameof(bytes),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(chars),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // Just call the pointer version (public overrides can't do this)
- fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- {
- fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
- {
- Convert(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, flush,
- out bytesUsed, out charsUsed, out completed);
- }
- }
- }
-
- // This is the version that used pointers. We call the base encoding worker function
- // after setting our appropriate internal variables. This is getting chars
- public override unsafe void Convert(byte* bytes, int byteCount,
- char* chars, int charCount, bool flush,
- out int bytesUsed, out int charsUsed, out bool completed)
- {
- // Validate input parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (byteCount < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(byteCount < 0 ? nameof(byteCount) : nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // We don't want to throw
- _mustFlush = flush;
- _throwOnOverflow = false;
- _bytesUsed = 0;
-
- // Do conversion
- Debug.Assert(_encoding != null);
- charsUsed = _encoding.GetChars(bytes, byteCount, chars, charCount, this);
- bytesUsed = _bytesUsed;
-
- // Per MSDN, "The completed output parameter indicates whether all the data in the input
- // buffer was converted and stored in the output buffer." That means we've successfully
- // consumed all the input _and_ there's no pending state or fallback data remaining to be output.
-
- completed = (bytesUsed == byteCount)
- && !this.HasState
- && (_fallbackBuffer is null || _fallbackBuffer.Remaining == 0);
- }
-
- public bool MustFlush => _mustFlush;
-
- // Anything left in our decoder?
- internal virtual bool HasState => _leftoverByteCount != 0;
-
- // Allow encoding to clear our must flush instead of throwing (in ThrowCharsOverflow)
- internal void ClearMustFlush()
- {
- _mustFlush = false;
- }
-
- internal ReadOnlySpan<byte> GetLeftoverData() =>
- MemoryMarshal.AsBytes(new ReadOnlySpan<int>(ref _leftoverBytes, 1)).Slice(0, _leftoverByteCount);
-
- internal void SetLeftoverData(ReadOnlySpan<byte> bytes)
- {
- bytes.CopyTo(MemoryMarshal.AsBytes(new Span<int>(ref _leftoverBytes, 1)));
- _leftoverByteCount = bytes.Length;
- }
-
- internal bool HasLeftoverData => _leftoverByteCount != 0;
-
- internal void ClearLeftoverData()
- {
- _leftoverByteCount = 0;
- }
-
- internal int DrainLeftoverDataForGetCharCount(ReadOnlySpan<byte> bytes, out int bytesConsumed)
- {
- // Quick check: we _should not_ have leftover fallback data from a previous invocation,
- // as we'd end up consuming any such data and would corrupt whatever Convert call happens
- // to be in progress. Unlike EncoderNLS, this is simply a Debug.Assert. No exception is thrown.
-
- Debug.Assert(_fallbackBuffer is null || _fallbackBuffer.Remaining == 0, "Should have no data remaining in the fallback buffer.");
- Debug.Assert(HasLeftoverData, "Caller shouldn't invoke this routine unless there's leftover data in the decoder.");
-
- // Copy the existing leftover data plus as many bytes as possible of the new incoming data
- // into a temporary concated buffer, then get its char count by decoding it.
-
- Span<byte> combinedBuffer = stackalloc byte[4];
- combinedBuffer = combinedBuffer.Slice(0, ConcatInto(GetLeftoverData(), bytes, combinedBuffer));
- int charCount = 0;
-
- Debug.Assert(_encoding != null);
- switch (_encoding.DecodeFirstRune(combinedBuffer, out Rune value, out int combinedBufferBytesConsumed))
- {
- case OperationStatus.Done:
- charCount = value.Utf16SequenceLength;
- goto Finish; // successfully transcoded bytes -> chars
-
- case OperationStatus.NeedMoreData:
- if (MustFlush)
- {
- goto case OperationStatus.InvalidData; // treat as equivalent to bad data
- }
- else
- {
- goto Finish; // consumed some bytes, output 0 chars
- }
-
- case OperationStatus.InvalidData:
- break;
-
- default:
- Debug.Fail("Unexpected OperationStatus return value.");
- break;
- }
-
- // Couldn't decode the buffer. Fallback the buffer instead. See comment in DrainLeftoverDataForGetChars
- // for more information on why a negative index is provided.
-
- if (FallbackBuffer.Fallback(combinedBuffer.Slice(0, combinedBufferBytesConsumed).ToArray(), index: -_leftoverByteCount))
- {
- charCount = _fallbackBuffer!.DrainRemainingDataForGetCharCount();
- Debug.Assert(charCount >= 0, "Fallback buffer shouldn't have returned a negative char count.");
- }
-
- Finish:
-
- bytesConsumed = combinedBufferBytesConsumed - _leftoverByteCount; // amount of 'bytes' buffer consumed just now
- return charCount;
- }
-
- internal int DrainLeftoverDataForGetChars(ReadOnlySpan<byte> bytes, Span<char> chars, out int bytesConsumed)
- {
- // Quick check: we _should not_ have leftover fallback data from a previous invocation,
- // as we'd end up consuming any such data and would corrupt whatever Convert call happens
- // to be in progress. Unlike EncoderNLS, this is simply a Debug.Assert. No exception is thrown.
-
- Debug.Assert(_fallbackBuffer is null || _fallbackBuffer.Remaining == 0, "Should have no data remaining in the fallback buffer.");
- Debug.Assert(HasLeftoverData, "Caller shouldn't invoke this routine unless there's leftover data in the decoder.");
-
- // Copy the existing leftover data plus as many bytes as possible of the new incoming data
- // into a temporary concated buffer, then transcode it from bytes to chars.
-
- Span<byte> combinedBuffer = stackalloc byte[4];
- combinedBuffer = combinedBuffer.Slice(0, ConcatInto(GetLeftoverData(), bytes, combinedBuffer));
- int charsWritten = 0;
-
- bool persistNewCombinedBuffer = false;
-
- Debug.Assert(_encoding != null);
- switch (_encoding.DecodeFirstRune(combinedBuffer, out Rune value, out int combinedBufferBytesConsumed))
- {
- case OperationStatus.Done:
- if (value.TryEncodeToUtf16(chars, out charsWritten))
- {
- goto Finish; // successfully transcoded bytes -> chars
- }
- else
- {
- goto DestinationTooSmall;
- }
-
- case OperationStatus.NeedMoreData:
- if (MustFlush)
- {
- goto case OperationStatus.InvalidData; // treat as equivalent to bad data
- }
- else
- {
- persistNewCombinedBuffer = true;
- goto Finish; // successfully consumed some bytes, output no chars
- }
-
- case OperationStatus.InvalidData:
- break;
-
- default:
- Debug.Fail("Unexpected OperationStatus return value.");
- break;
- }
-
- // Couldn't decode the buffer. Fallback the buffer instead. The fallback mechanism relies
- // on a negative index to convey "the start of the invalid sequence was some number of
- // bytes back before the current buffer." Since we know the invalid sequence must have
- // started at the beginning of our leftover byte buffer, we can signal to our caller that
- // they must backtrack that many bytes to find the real start of the invalid sequence.
-
- if (FallbackBuffer.Fallback(combinedBuffer.Slice(0, combinedBufferBytesConsumed).ToArray(), index: -_leftoverByteCount)
- && !_fallbackBuffer!.TryDrainRemainingDataForGetChars(chars, out charsWritten))
- {
- goto DestinationTooSmall;
- }
-
- Finish:
-
- // Report back the number of bytes (from the new incoming span) we consumed just now.
- // This calculation is simple: it's the difference between the original leftover byte
- // count and the number of bytes from the combined buffer we needed to decode the first
- // scalar value. We need to report this before the call to SetLeftoverData /
- // ClearLeftoverData because those methods will overwrite the _leftoverByteCount field.
-
- bytesConsumed = combinedBufferBytesConsumed - _leftoverByteCount;
-
- if (persistNewCombinedBuffer)
- {
- Debug.Assert(combinedBufferBytesConsumed == combinedBuffer.Length, "We should be asked to persist the entire combined buffer.");
- SetLeftoverData(combinedBuffer); // the buffer still only contains partial data; a future call to Convert will need it
- }
- else
- {
- ClearLeftoverData(); // the buffer contains no partial data; we'll go down the normal paths
- }
-
- return charsWritten;
-
- DestinationTooSmall:
-
- // If we got to this point, we're trying to write chars to the output buffer, but we're unable to do
- // so. Unlike EncoderNLS, this type does not allow partial writes to the output buffer. Since we know
- // draining leftover data is the first operation performed by any DecoderNLS API, there was no
- // opportunity for any code before us to make forward progress, so we must fail immediately.
-
- _encoding.ThrowCharsOverflow(this, nothingDecoded: true);
- throw null!; // will never reach this point
- }
-
- /// <summary>
- /// Given a byte buffer <paramref name="dest"/>, concatenates as much of <paramref name="srcLeft"/> followed
- /// by <paramref name="srcRight"/> into it as will fit, then returns the total number of bytes copied.
- /// </summary>
- private static int ConcatInto(ReadOnlySpan<byte> srcLeft, ReadOnlySpan<byte> srcRight, Span<byte> dest)
- {
- int total = 0;
-
- for (int i = 0; i < srcLeft.Length; i++)
- {
- if ((uint)total >= (uint)dest.Length)
- {
- goto Finish;
- }
- else
- {
- dest[total++] = srcLeft[i];
- }
- }
-
- for (int i = 0; i < srcRight.Length; i++)
- {
- if ((uint)total >= (uint)dest.Length)
- {
- goto Finish;
- }
- else
- {
- dest[total++] = srcRight[i];
- }
- }
-
- Finish:
-
- return total;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/DecoderReplacementFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/DecoderReplacementFallback.cs
deleted file mode 100644
index 87db1d0e51c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/DecoderReplacementFallback.cs
+++ /dev/null
@@ -1,171 +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 System.Diagnostics;
-
-namespace System.Text
-{
- public sealed class DecoderReplacementFallback : DecoderFallback
- {
- // Our variables
- private readonly string _strDefault;
-
- // Construction. Default replacement fallback uses no best fit and ? replacement string
- public DecoderReplacementFallback() : this("?")
- {
- }
-
- public DecoderReplacementFallback(string replacement)
- {
- if (replacement == null)
- throw new ArgumentNullException(nameof(replacement));
-
- // Make sure it doesn't have bad surrogate pairs
- bool bFoundHigh = false;
- for (int i = 0; i < replacement.Length; i++)
- {
- // Found a surrogate?
- if (char.IsSurrogate(replacement, i))
- {
- // High or Low?
- if (char.IsHighSurrogate(replacement, i))
- {
- // if already had a high one, stop
- if (bFoundHigh)
- break; // break & throw at the bFoundHIgh below
- bFoundHigh = true;
- }
- else
- {
- // Low, did we have a high?
- if (!bFoundHigh)
- {
- // Didn't have one, make if fail when we stop
- bFoundHigh = true;
- break;
- }
-
- // Clear flag
- bFoundHigh = false;
- }
- }
- // If last was high we're in trouble (not surrogate so not low surrogate, so break)
- else if (bFoundHigh)
- break;
- }
- if (bFoundHigh)
- throw new ArgumentException(SR.Format(SR.Argument_InvalidCharSequenceNoIndex, nameof(replacement)));
-
- _strDefault = replacement;
- }
-
- public string DefaultString => _strDefault;
-
- public override DecoderFallbackBuffer CreateFallbackBuffer() =>
- new DecoderReplacementFallbackBuffer(this);
-
- // Maximum number of characters that this instance of this fallback could return
- public override int MaxCharCount => _strDefault.Length;
-
- public override bool Equals(object? value) =>
- value is DecoderReplacementFallback that &&
- _strDefault == that._strDefault;
-
- public override int GetHashCode() => _strDefault.GetHashCode();
- }
-
- public sealed class DecoderReplacementFallbackBuffer : DecoderFallbackBuffer
- {
- // Store our default string
- private readonly string _strDefault;
- private int _fallbackCount = -1;
- private int _fallbackIndex = -1;
-
- // Construction
- public DecoderReplacementFallbackBuffer(DecoderReplacementFallback fallback)
- {
- _strDefault = fallback.DefaultString;
- }
-
- // Fallback Methods
- public override bool Fallback(byte[] bytesUnknown, int index)
- {
- // We expect no previous fallback in our buffer
- // We can't call recursively but others might (note, we don't test on last char!!!)
- if (_fallbackCount >= 1)
- {
- ThrowLastBytesRecursive(bytesUnknown);
- }
-
- // Go ahead and get our fallback
- if (_strDefault.Length == 0)
- return false;
-
- _fallbackCount = _strDefault.Length;
- _fallbackIndex = -1;
-
- return true;
- }
-
- public override char GetNextChar()
- {
- // We want it to get < 0 because == 0 means that the current/last character is a fallback
- // and we need to detect recursion. We could have a flag but we already have this counter.
- _fallbackCount--;
- _fallbackIndex++;
-
- // Do we have anything left? 0 is now last fallback char, negative is nothing left
- if (_fallbackCount < 0)
- return '\0';
-
- // Need to get it out of the buffer.
- // Make sure it didn't wrap from the fast count-- path
- if (_fallbackCount == int.MaxValue)
- {
- _fallbackCount = -1;
- return '\0';
- }
-
- // Now make sure its in the expected range
- Debug.Assert(_fallbackIndex < _strDefault.Length && _fallbackIndex >= 0,
- "Index exceeds buffer range");
-
- return _strDefault[_fallbackIndex];
- }
-
- public override bool MovePrevious()
- {
- // Back up one, only if we just processed the last character (or earlier)
- if (_fallbackCount >= -1 && _fallbackIndex >= 0)
- {
- _fallbackIndex--;
- _fallbackCount++;
- return true;
- }
-
- // Return false 'cause we couldn't do it.
- return false;
- }
-
- // How many characters left to output?
- public override int Remaining =>
- // Our count is 0 for 1 character left.
- (_fallbackCount < 0) ? 0 : _fallbackCount;
-
- // Clear the buffer
- public override unsafe void Reset()
- {
- _fallbackCount = -1;
- _fallbackIndex = -1;
- byteStart = null;
- }
-
- // This version just counts the fallback and doesn't actually copy anything.
- internal override unsafe int InternalFallback(byte[] bytes, byte* pBytes) =>
- // Right now this has both bytes and bytes[], since we might have extra bytes,
- // hence the array, and we might need the index, hence the byte*.
- // Return our replacement string Length
- _strDefault.Length;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Encoder.cs b/netcore/System.Private.CoreLib/shared/System/Text/Encoder.cs
deleted file mode 100644
index 2d6d10cc86e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Encoder.cs
+++ /dev/null
@@ -1,333 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Text
-{
- // An Encoder is used to encode a sequence of blocks of characters into
- // a sequence of blocks of bytes. Following instantiation of an encoder,
- // sequential blocks of characters are converted into blocks of bytes through
- // calls to the GetBytes method. The encoder maintains state between the
- // conversions, allowing it to correctly encode character sequences that span
- // adjacent blocks.
- //
- // Instances of specific implementations of the Encoder abstract base
- // class are typically obtained through calls to the GetEncoder method
- // of Encoding objects.
- //
- public abstract class Encoder
- {
- internal EncoderFallback? _fallback = null;
-
- internal EncoderFallbackBuffer? _fallbackBuffer = null;
-
- protected Encoder()
- {
- // We don't call default reset because default reset probably isn't good if we aren't initialized.
- }
-
- public EncoderFallback? Fallback
- {
- get => _fallback;
- set
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- // Can't change fallback if buffer is wrong
- if (_fallbackBuffer != null && _fallbackBuffer.Remaining > 0)
- throw new ArgumentException(
- SR.Argument_FallbackBufferNotEmpty, nameof(value));
-
- _fallback = value;
- _fallbackBuffer = null;
- }
- }
-
- // Note: we don't test for threading here because async access to Encoders and Decoders
- // doesn't work anyway.
- public EncoderFallbackBuffer FallbackBuffer
- {
- get
- {
- if (_fallbackBuffer == null)
- {
- if (_fallback != null)
- _fallbackBuffer = _fallback.CreateFallbackBuffer();
- else
- _fallbackBuffer = EncoderFallback.ReplacementFallback.CreateFallbackBuffer();
- }
-
- return _fallbackBuffer;
- }
- }
-
- internal bool InternalHasFallbackBuffer => _fallbackBuffer != null;
-
- // Reset the Encoder
- //
- // Normally if we call GetBytes() and an error is thrown we don't change the state of the encoder. This
- // would allow the caller to correct the error condition and try again (such as if they need a bigger buffer.)
- //
- // If the caller doesn't want to try again after GetBytes() throws an error, then they need to call Reset().
- //
- // Virtual implementation has to call GetBytes with flush and a big enough buffer to clear a 0 char string
- // We avoid GetMaxByteCount() because a) we can't call the base encoder and b) it might be really big.
- public virtual void Reset()
- {
- char[] charTemp = Array.Empty<char>();
- byte[] byteTemp = new byte[GetByteCount(charTemp, 0, 0, true)];
- GetBytes(charTemp, 0, 0, byteTemp, 0, true);
- if (_fallbackBuffer != null)
- _fallbackBuffer.Reset();
- }
-
- // Returns the number of bytes the next call to GetBytes will
- // produce if presented with the given range of characters and the given
- // value of the flush parameter. The returned value takes into
- // account the state in which the encoder was left following the last call
- // to GetBytes. The state of the encoder is not affected by a call
- // to this method.
- //
- public abstract int GetByteCount(char[] chars, int index, int count, bool flush);
-
- // We expect this to be the workhorse for NLS encodings
- // unfortunately for existing overrides, it has to call the [] version,
- // which is really slow, so avoid this method if you might be calling external encodings.
- [CLSCompliant(false)]
- public virtual unsafe int GetByteCount(char* chars, int count, bool flush)
- {
- // Validate input parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars),
- SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- char[] arrChar = new char[count];
- int index;
-
- for (index = 0; index < count; index++)
- arrChar[index] = chars[index];
-
- return GetByteCount(arrChar, 0, count, flush);
- }
-
- public virtual unsafe int GetByteCount(ReadOnlySpan<char> chars, bool flush)
- {
- fixed (char* charsPtr = &MemoryMarshal.GetNonNullPinnableReference(chars))
- {
- return GetByteCount(charsPtr, chars.Length, flush);
- }
- }
-
- // Encodes a range of characters in a character array into a range of bytes
- // in a byte array. The method encodes charCount characters from
- // chars starting at index charIndex, storing the resulting
- // bytes in bytes starting at index byteIndex. The encoding
- // takes into account the state in which the encoder was left following the
- // last call to this method. The flush parameter indicates whether
- // the encoder should flush any shift-states and partial characters at the
- // end of the conversion. To ensure correct termination of a sequence of
- // blocks of encoded bytes, the last call to GetBytes should specify
- // a value of true for the flush parameter.
- //
- // An exception occurs if the byte array is not large enough to hold the
- // complete encoding of the characters. The GetByteCount method can
- // be used to determine the exact number of bytes that will be produced for
- // a given range of characters. Alternatively, the GetMaxByteCount
- // method of the Encoding that produced this encoder can be used to
- // determine the maximum number of bytes that will be produced for a given
- // number of characters, regardless of the actual character values.
- //
- public abstract int GetBytes(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex, bool flush);
-
- // We expect this to be the workhorse for NLS Encodings, but for existing
- // ones we need a working (if slow) default implementation)
- //
- // WARNING WARNING WARNING
- //
- // WARNING: If this breaks it could be a security threat. Obviously we
- // call this internally, so you need to make sure that your pointers, counts
- // and indexes are correct when you call this method.
- //
- // In addition, we have internal code, which will be marked as "safe" calling
- // this code. However this code is dependent upon the implementation of an
- // external GetBytes() method, which could be overridden by a third party and
- // the results of which cannot be guaranteed. We use that result to copy
- // the byte[] to our byte* output buffer. If the result count was wrong, we
- // could easily overflow our output buffer. Therefore we do an extra test
- // when we copy the buffer so that we don't overflow byteCount either.
- [CLSCompliant(false)]
- public virtual unsafe int GetBytes(char* chars, int charCount,
- byte* bytes, int byteCount, bool flush)
- {
- // Validate input parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars),
- SR.ArgumentNull_Array);
-
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Get the char array to convert
- char[] arrChar = new char[charCount];
-
- int index;
- for (index = 0; index < charCount; index++)
- arrChar[index] = chars[index];
-
- // Get the byte array to fill
- byte[] arrByte = new byte[byteCount];
-
- // Do the work
- int result = GetBytes(arrChar, 0, charCount, arrByte, 0, flush);
-
- Debug.Assert(result <= byteCount, "Returned more bytes than we have space for");
-
- // Copy the byte array
- // WARNING: We MUST make sure that we don't copy too many bytes. We can't
- // rely on result because it could be a 3rd party implementation. We need
- // to make sure we never copy more than byteCount bytes no matter the value
- // of result
- if (result < byteCount)
- byteCount = result;
-
- // Don't copy too many bytes!
- for (index = 0; index < byteCount; index++)
- bytes[index] = arrByte[index];
-
- return byteCount;
- }
-
- public virtual unsafe int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes, bool flush)
- {
- fixed (char* charsPtr = &MemoryMarshal.GetNonNullPinnableReference(chars))
- fixed (byte* bytesPtr = &MemoryMarshal.GetNonNullPinnableReference(bytes))
- {
- return GetBytes(charsPtr, chars.Length, bytesPtr, bytes.Length, flush);
- }
- }
-
- // This method is used to avoid running out of output buffer space.
- // It will encode until it runs out of chars, and then it will return
- // true if it the entire input was converted. In either case it
- // will also return the number of converted chars and output bytes used.
- // It will only throw a buffer overflow exception if the entire lenght of bytes[] is
- // too small to store the next byte. (like 0 or maybe 1 or 4 for some encodings)
- // We're done processing this buffer only if completed returns true.
- //
- // Might consider checking Max...Count to avoid the extra counting step.
- //
- // Note that if all of the input chars are not consumed, then we'll do a /2, which means
- // that its likely that we didn't consume as many chars as we could have. For some
- // applications this could be slow. (Like trying to exactly fill an output buffer from a bigger stream)
- public virtual void Convert(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex, int byteCount, bool flush,
- out int charsUsed, out int bytesUsed, out bool completed)
- {
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (byteIndex < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(byteIndex < 0 ? nameof(byteIndex) : nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(chars),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (bytes.Length - byteIndex < byteCount)
- throw new ArgumentOutOfRangeException(nameof(bytes),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- charsUsed = charCount;
-
- // Its easy to do if it won't overrun our buffer.
- // Note: We don't want to call unsafe version because that might be an untrusted version
- // which could be really unsafe and we don't want to mix it up.
- while (charsUsed > 0)
- {
- if (GetByteCount(chars, charIndex, charsUsed, flush) <= byteCount)
- {
- bytesUsed = GetBytes(chars, charIndex, charsUsed, bytes, byteIndex, flush);
- completed = (charsUsed == charCount &&
- (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0));
- return;
- }
-
- // Try again with 1/2 the count, won't flush then 'cause won't read it all
- flush = false;
- charsUsed /= 2;
- }
-
- // Oops, we didn't have anything, we'll have to throw an overflow
- throw new ArgumentException(SR.Argument_ConversionOverflow);
- }
-
- // Same thing, but using pointers
- //
- // Might consider checking Max...Count to avoid the extra counting step.
- //
- // Note that if all of the input chars are not consumed, then we'll do a /2, which means
- // that its likely that we didn't consume as many chars as we could have. For some
- // applications this could be slow. (Like trying to exactly fill an output buffer from a bigger stream)
- [CLSCompliant(false)]
- public virtual unsafe void Convert(char* chars, int charCount,
- byte* bytes, int byteCount, bool flush,
- out int charsUsed, out int bytesUsed, out bool completed)
- {
- // Validate input parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars),
- SR.ArgumentNull_Array);
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Get ready to do it
- charsUsed = charCount;
-
- // Its easy to do if it won't overrun our buffer.
- while (charsUsed > 0)
- {
- if (GetByteCount(chars, charsUsed, flush) <= byteCount)
- {
- bytesUsed = GetBytes(chars, charsUsed, bytes, byteCount, flush);
- completed = (charsUsed == charCount &&
- (_fallbackBuffer == null || _fallbackBuffer.Remaining == 0));
- return;
- }
-
- // Try again with 1/2 the count, won't flush then 'cause won't read it all
- flush = false;
- charsUsed /= 2;
- }
-
- // Oops, we didn't have anything, we'll have to throw an overflow
- throw new ArgumentException(SR.Argument_ConversionOverflow);
- }
-
- public virtual unsafe void Convert(ReadOnlySpan<char> chars, Span<byte> bytes, bool flush, out int charsUsed, out int bytesUsed, out bool completed)
- {
- fixed (char* charsPtr = &MemoryMarshal.GetNonNullPinnableReference(chars))
- fixed (byte* bytesPtr = &MemoryMarshal.GetNonNullPinnableReference(bytes))
- {
- Convert(charsPtr, chars.Length, bytesPtr, bytes.Length, flush, out charsUsed, out bytesUsed, out completed);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs
deleted file mode 100644
index 19851fa0c4e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs
+++ /dev/null
@@ -1,217 +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.
-
-//
-// This is used internally to create best fit behavior as per the original windows best fit behavior.
-//
-
-using System.Diagnostics;
-using System.Globalization;
-using System.Threading;
-
-namespace System.Text
-{
- internal class InternalEncoderBestFitFallback : EncoderFallback
- {
- // Our variables
- internal Encoding _encoding;
- internal char[]? _arrayBestFit = null;
-
- internal InternalEncoderBestFitFallback(Encoding encoding)
- {
- // Need to load our replacement characters table.
- _encoding = encoding;
- }
-
- public override EncoderFallbackBuffer CreateFallbackBuffer() =>
- new InternalEncoderBestFitFallbackBuffer(this);
-
- // Maximum number of characters that this instance of this fallback could return
- public override int MaxCharCount => 1;
-
- public override bool Equals(object? value) =>
- value is InternalEncoderBestFitFallback that &&
- _encoding.CodePage == that._encoding.CodePage;
-
- public override int GetHashCode() => _encoding.CodePage;
- }
-
- internal sealed class InternalEncoderBestFitFallbackBuffer : EncoderFallbackBuffer
- {
- // Our variables
- private char _cBestFit = '\0';
- private readonly InternalEncoderBestFitFallback _oFallback;
- private int _iCount = -1;
- private int _iSize;
-
- // Private object for locking instead of locking on a public type for SQL reliability work.
- private static object? s_InternalSyncObject;
- private static object InternalSyncObject
- {
- get
- {
- if (s_InternalSyncObject == null)
- {
- object o = new object();
- Interlocked.CompareExchange<object?>(ref s_InternalSyncObject, o, null);
- }
- return s_InternalSyncObject;
- }
- }
-
- // Constructor
- public InternalEncoderBestFitFallbackBuffer(InternalEncoderBestFitFallback fallback)
- {
- _oFallback = fallback;
-
- if (_oFallback._arrayBestFit == null)
- {
- // Lock so we don't confuse ourselves.
- lock (InternalSyncObject)
- {
- // Double check before we do it again.
- _oFallback._arrayBestFit ??= fallback._encoding.GetBestFitUnicodeToBytesData();
- }
- }
- }
-
- // Fallback methods
- public override bool Fallback(char charUnknown, int index)
- {
- // If we had a buffer already we're being recursive, throw, it's probably at the suspect
- // character in our array.
- // Shouldn't be able to get here for all of our code pages, table would have to be messed up.
- Debug.Assert(_iCount < 1, "[InternalEncoderBestFitFallbackBuffer.Fallback(non surrogate)] Fallback char " + ((int)_cBestFit).ToString("X4", CultureInfo.InvariantCulture) + " caused recursive fallback");
-
- _iCount = _iSize = 1;
- _cBestFit = TryBestFit(charUnknown);
- if (_cBestFit == '\0')
- _cBestFit = '?';
-
- return true;
- }
-
- public override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
- {
- // Double check input surrogate pair
- if (!char.IsHighSurrogate(charUnknownHigh))
- throw new ArgumentOutOfRangeException(nameof(charUnknownHigh),
- SR.Format(SR.ArgumentOutOfRange_Range,
- 0xD800, 0xDBFF));
-
- if (!char.IsLowSurrogate(charUnknownLow))
- throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
- SR.Format(SR.ArgumentOutOfRange_Range,
- 0xDC00, 0xDFFF));
-
- // If we had a buffer already we're being recursive, throw, it's probably at the suspect
- // character in our array. 0 is processing last character, < 0 is not falling back
- // Shouldn't be able to get here, table would have to be messed up.
- Debug.Assert(_iCount < 1, "[InternalEncoderBestFitFallbackBuffer.Fallback(surrogate)] Fallback char " + ((int)_cBestFit).ToString("X4", CultureInfo.InvariantCulture) + " caused recursive fallback");
-
- // Go ahead and get our fallback, surrogates don't have best fit
- _cBestFit = '?';
- _iCount = _iSize = 2;
-
- return true;
- }
-
- // Default version is overridden in EncoderReplacementFallback.cs
- public override char GetNextChar()
- {
- // We want it to get < 0 because == 0 means that the current/last character is a fallback
- // and we need to detect recursion. We could have a flag but we already have this counter.
- _iCount--;
-
- // Do we have anything left? 0 is now last fallback char, negative is nothing left
- if (_iCount < 0)
- return '\0';
-
- // Need to get it out of the buffer.
- // Make sure it didn't wrap from the fast count-- path
- if (_iCount == int.MaxValue)
- {
- _iCount = -1;
- return '\0';
- }
-
- // Return the best fit character
- return _cBestFit;
- }
-
- public override bool MovePrevious()
- {
- // Exception fallback doesn't have anywhere to back up to.
- if (_iCount >= 0)
- _iCount++;
-
- // Return true if we could do it.
- return _iCount >= 0 && _iCount <= _iSize;
- }
-
- // How many characters left to output?
- public override int Remaining => (_iCount > 0) ? _iCount : 0;
-
- // Clear the buffer
- public override unsafe void Reset()
- {
- _iCount = -1;
- charStart = null;
- bFallingBack = false;
- }
-
- // private helper methods
- private char TryBestFit(char cUnknown)
- {
- // Need to figure out our best fit character, low is beginning of array, high is 1 AFTER end of array
- int lowBound = 0;
- Debug.Assert(_oFallback._arrayBestFit != null);
- int highBound = _oFallback._arrayBestFit.Length;
- int index;
-
- // Binary search the array
- int iDiff;
- while ((iDiff = (highBound - lowBound)) > 6)
- {
- // Look in the middle, which is complicated by the fact that we have 2 #s for each pair,
- // so we don't want index to be odd because we want to be on word boundaries.
- // Also note that index can never == highBound (because diff is rounded down)
- index = ((iDiff / 2) + lowBound) & 0xFFFE;
-
- char cTest = _oFallback._arrayBestFit[index];
- if (cTest == cUnknown)
- {
- // We found it
- Debug.Assert(index + 1 < _oFallback._arrayBestFit.Length,
- "[InternalEncoderBestFitFallbackBuffer.TryBestFit]Expected replacement character at end of array");
- return _oFallback._arrayBestFit[index + 1];
- }
- else if (cTest < cUnknown)
- {
- // We weren't high enough
- lowBound = index;
- }
- else
- {
- // We weren't low enough
- highBound = index;
- }
- }
-
- for (index = lowBound; index < highBound; index += 2)
- {
- if (_oFallback._arrayBestFit[index] == cUnknown)
- {
- // We found it
- Debug.Assert(index + 1 < _oFallback._arrayBestFit.Length,
- "[InternalEncoderBestFitFallbackBuffer.TryBestFit]Expected replacement character at end of array");
- return _oFallback._arrayBestFit[index + 1];
- }
- }
-
- // Char wasn't in our table
- return '\0';
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncoderExceptionFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncoderExceptionFallback.cs
deleted file mode 100644
index 665e4d8509b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/EncoderExceptionFallback.cs
+++ /dev/null
@@ -1,137 +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 System.Runtime.Serialization;
-
-namespace System.Text
-{
- public sealed class EncoderExceptionFallback : EncoderFallback
- {
- // Construction
- public EncoderExceptionFallback()
- {
- }
-
- public override EncoderFallbackBuffer CreateFallbackBuffer() =>
- new EncoderExceptionFallbackBuffer();
-
- // Maximum number of characters that this instance of this fallback could return
- public override int MaxCharCount => 0;
-
- public override bool Equals(object? value) =>
- value is EncoderExceptionFallback;
-
- public override int GetHashCode() => 654;
- }
-
-
- public sealed class EncoderExceptionFallbackBuffer : EncoderFallbackBuffer
- {
- public EncoderExceptionFallbackBuffer() { }
- public override bool Fallback(char charUnknown, int index)
- {
- // Fall back our char
- throw new EncoderFallbackException(
- SR.Format(SR.Argument_InvalidCodePageConversionIndex, (int)charUnknown, index), charUnknown, index);
- }
-
- public override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
- {
- if (!char.IsHighSurrogate(charUnknownHigh))
- {
- throw new ArgumentOutOfRangeException(nameof(charUnknownHigh),
- SR.Format(SR.ArgumentOutOfRange_Range, 0xD800, 0xDBFF));
- }
- if (!char.IsLowSurrogate(charUnknownLow))
- {
- throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
- SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
- }
-
- int iTemp = char.ConvertToUtf32(charUnknownHigh, charUnknownLow);
-
- // Fall back our char
- throw new EncoderFallbackException(
- SR.Format(SR.Argument_InvalidCodePageConversionIndex, iTemp, index), charUnknownHigh, charUnknownLow, index);
- }
-
- public override char GetNextChar() => (char)0;
-
- // Exception fallback doesn't have anywhere to back up to.
- public override bool MovePrevious() => false;
-
- // Exceptions are always empty
- public override int Remaining => 0;
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class EncoderFallbackException : ArgumentException
- {
- private readonly char _charUnknown;
- private readonly char _charUnknownHigh;
- private readonly char _charUnknownLow;
- private readonly int _index;
-
- public EncoderFallbackException()
- : base(SR.Arg_ArgumentException)
- {
- HResult = HResults.COR_E_ARGUMENT;
- }
-
- public EncoderFallbackException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_ARGUMENT;
- }
-
- public EncoderFallbackException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_ARGUMENT;
- }
-
- internal EncoderFallbackException(
- string? message, char charUnknown, int index) : base(message)
- {
- _charUnknown = charUnknown;
- _index = index;
- }
-
- internal EncoderFallbackException(
- string message, char charUnknownHigh, char charUnknownLow, int index) : base(message)
- {
- if (!char.IsHighSurrogate(charUnknownHigh))
- {
- throw new ArgumentOutOfRangeException(nameof(charUnknownHigh),
- SR.Format(SR.ArgumentOutOfRange_Range, 0xD800, 0xDBFF));
- }
- if (!char.IsLowSurrogate(charUnknownLow))
- {
- throw new ArgumentOutOfRangeException(nameof(CharUnknownLow),
- SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
- }
-
- _charUnknownHigh = charUnknownHigh;
- _charUnknownLow = charUnknownLow;
- _index = index;
- }
-
- private EncoderFallbackException(SerializationInfo serializationInfo, StreamingContext streamingContext)
- : base(serializationInfo, streamingContext)
- {
- }
-
- public char CharUnknown => _charUnknown;
-
- public char CharUnknownHigh => _charUnknownHigh;
-
- public char CharUnknownLow => _charUnknownLow;
-
- public int Index => _index;
-
- // Return true if the unknown character is a surrogate pair.
- public bool IsUnknownSurrogate() => _charUnknownHigh != '\0';
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs
deleted file mode 100644
index 8a2f546771e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs
+++ /dev/null
@@ -1,384 +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 System.Buffers;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Threading;
-
-namespace System.Text
-{
- public abstract class EncoderFallback
- {
- private static EncoderFallback? s_replacementFallback; // Default fallback, uses no best fit & "?"
- private static EncoderFallback? s_exceptionFallback;
-
- // Get each of our generic fallbacks.
-
- public static EncoderFallback ReplacementFallback
- {
- get
- {
- if (s_replacementFallback == null)
- Interlocked.CompareExchange<EncoderFallback?>(ref s_replacementFallback, new EncoderReplacementFallback(), null);
-
- return s_replacementFallback;
- }
- }
-
-
- public static EncoderFallback ExceptionFallback
- {
- get
- {
- if (s_exceptionFallback == null)
- Interlocked.CompareExchange<EncoderFallback?>(ref s_exceptionFallback, new EncoderExceptionFallback(), null);
-
- return s_exceptionFallback;
- }
- }
-
- // Fallback
- //
- // Return the appropriate unicode string alternative to the character that need to fall back.
- // Most implementations will be:
- // return new MyCustomEncoderFallbackBuffer(this);
-
- public abstract EncoderFallbackBuffer CreateFallbackBuffer();
-
- // Maximum number of characters that this instance of this fallback could return
-
- public abstract int MaxCharCount { get; }
- }
-
-
- public abstract class EncoderFallbackBuffer
- {
- // Most implementations will probably need an implementation-specific constructor
-
- // Public methods that cannot be overridden that let us do our fallback thing
- // These wrap the internal methods so that we can check for people doing stuff that is incorrect
-
- public abstract bool Fallback(char charUnknown, int index);
-
- public abstract bool Fallback(char charUnknownHigh, char charUnknownLow, int index);
-
- // Get next character
-
- public abstract char GetNextChar();
-
- // Back up a character
-
- public abstract bool MovePrevious();
-
- // How many chars left in this fallback?
-
- public abstract int Remaining { get; }
-
- // Not sure if this should be public or not.
- // Clear the buffer
-
- public virtual void Reset()
- {
- while (GetNextChar() != (char)0) ;
- }
-
- // Internal items to help us figure out what we're doing as far as error messages, etc.
- // These help us with our performance and messages internally
- internal unsafe char* charStart;
- internal unsafe char* charEnd;
- internal EncoderNLS? encoder; // TODO: MAKE ME PRIVATE
- internal bool setEncoder;
- internal bool bUsedEncoder;
- internal bool bFallingBack = false;
- internal int iRecursionCount = 0;
- private const int iMaxRecursion = 250;
- private Encoding? encoding;
- private int originalCharCount;
-
- // Internal Reset
- // For example, what if someone fails a conversion and wants to reset one of our fallback buffers?
- internal unsafe void InternalReset()
- {
- charStart = null;
- bFallingBack = false;
- iRecursionCount = 0;
- Reset();
- }
-
- // Set the above values
- // This can't be part of the constructor because EncoderFallbacks would have to know how to implement these.
- internal unsafe void InternalInitialize(char* charStart, char* charEnd, EncoderNLS? encoder, bool setEncoder)
- {
- this.charStart = charStart;
- this.charEnd = charEnd;
- this.encoder = encoder;
- this.setEncoder = setEncoder;
- this.bUsedEncoder = false;
- this.bFallingBack = false;
- this.iRecursionCount = 0;
- }
-
- internal static EncoderFallbackBuffer CreateAndInitialize(Encoding encoding, EncoderNLS? encoder, int originalCharCount)
- {
- // The original char count is only used for keeping track of what 'index' value needs
- // to be passed to the abstract Fallback method. The index value is calculated by subtracting
- // 'chars.Length' (where chars is expected to be the entire remaining input buffer)
- // from the 'originalCharCount' value specified here.
-
- EncoderFallbackBuffer fallbackBuffer = (encoder is null) ? encoding.EncoderFallback.CreateFallbackBuffer() : encoder.FallbackBuffer;
-
- fallbackBuffer.encoding = encoding;
- fallbackBuffer.encoder = encoder;
- fallbackBuffer.originalCharCount = originalCharCount;
-
- return fallbackBuffer;
- }
-
- internal char InternalGetNextChar()
- {
- char ch = GetNextChar();
- bFallingBack = (ch != 0);
- if (ch == 0) iRecursionCount = 0;
- return ch;
- }
-
- private bool InternalFallback(ReadOnlySpan<char> chars, out int charsConsumed)
- {
- Debug.Assert(!chars.IsEmpty, "Caller shouldn't invoke this if there's no data to fall back.");
-
- // First, try falling back a single BMP character or a standalone low surrogate.
- // If the first char is a high surrogate, we'll try to combine it with the next
- // char in the input sequence.
-
- char firstChar = chars[0];
- char secondChar = default;
-
- if (!chars.IsEmpty)
- {
- firstChar = chars[0];
-
- if (1 < (uint)chars.Length)
- {
- secondChar = chars[1];
- }
- }
-
- // Ask the subclassed type to initiate fallback logic.
-
- int index = originalCharCount - chars.Length;
-
- if (!char.IsSurrogatePair(firstChar, secondChar))
- {
- // This code path is also used when 'firstChar' is a standalone surrogate or
- // if it's a high surrogate at the end of the input buffer.
-
- charsConsumed = 1;
- return Fallback(firstChar, index);
- }
- else
- {
- charsConsumed = 2;
- return Fallback(firstChar, secondChar, index);
- }
- }
-
- internal int InternalFallbackGetByteCount(ReadOnlySpan<char> chars, out int charsConsumed)
- {
- int bytesWritten = 0;
-
- if (InternalFallback(chars, out charsConsumed))
- {
- // There's data in the fallback buffer - pull it out now.
-
- bytesWritten = DrainRemainingDataForGetByteCount();
- }
-
- return bytesWritten;
- }
-
- internal bool TryInternalFallbackGetBytes(ReadOnlySpan<char> chars, Span<byte> bytes, out int charsConsumed, out int bytesWritten)
- {
- if (InternalFallback(chars, out charsConsumed))
- {
- // There's data in the fallback buffer - pull it out now.
-
- return TryDrainRemainingDataForGetBytes(bytes, out bytesWritten);
- }
- else
- {
- // There's no data in the fallback buffer.
-
- bytesWritten = 0;
- return true; // true = didn't run out of space in destination buffer
- }
- }
-
- internal bool TryDrainRemainingDataForGetBytes(Span<byte> bytes, out int bytesWritten)
- {
- int originalBytesLength = bytes.Length;
-
- Debug.Assert(encoding != null);
- Rune thisRune;
- while ((thisRune = GetNextRune()).Value != 0)
- {
- switch (encoding.EncodeRune(thisRune, bytes, out int bytesWrittenJustNow))
- {
- case OperationStatus.Done:
-
- bytes = bytes.Slice(bytesWrittenJustNow);
- continue;
-
- case OperationStatus.DestinationTooSmall:
-
- // Since we're not consuming the Rune we just read, back up as many chars as necessary
- // to undo the read we just performed, then report to our caller that we ran out of space.
-
- for (int i = 0; i < thisRune.Utf16SequenceLength; i++)
- {
- MovePrevious();
- }
-
- bytesWritten = originalBytesLength - bytes.Length;
- return false; // ran out of destination buffer
-
- case OperationStatus.InvalidData:
-
- // We can't fallback the fallback. We can't make forward progress, so report to our caller
- // that something went terribly wrong. The error message contains the fallback char that
- // couldn't be converted. (Ideally we'd provide the first char that originally triggered
- // the fallback, but it's complicated to keep this state around, and a fallback producing
- // invalid data should be a very rare occurrence.)
-
- ThrowLastCharRecursive(thisRune.Value);
- break; // will never be hit; call above throws
-
- default:
-
- Debug.Fail("Unexpected return value.");
- break;
- }
- }
-
- bytesWritten = originalBytesLength - bytes.Length;
- return true; // finished successfully
- }
-
- internal int DrainRemainingDataForGetByteCount()
- {
- int totalByteCount = 0;
-
- Debug.Assert(encoding != null);
- Rune thisRune;
- while ((thisRune = GetNextRune()).Value != 0)
- {
- if (!encoding.TryGetByteCount(thisRune, out int byteCountThisIteration))
- {
- // We can't fallback the fallback. We can't make forward progress, so report to our caller
- // that something went terribly wrong. The error message contains the fallback char that
- // couldn't be converted. (Ideally we'd provide the first char that originally triggered
- // the fallback, but it's complicated to keep this state around, and a fallback producing
- // invalid data should be a very rare occurrence.)
-
- ThrowLastCharRecursive(thisRune.Value);
- }
-
- Debug.Assert(byteCountThisIteration >= 0, "Encoding shouldn't have returned a negative byte count.");
-
- // We need to check for overflow while tallying the fallback byte count.
-
- totalByteCount += byteCountThisIteration;
- if (totalByteCount < 0)
- {
- InternalReset();
- Encoding.ThrowConversionOverflow();
- }
- }
-
- return totalByteCount;
- }
-
- private Rune GetNextRune()
- {
- char firstChar = GetNextChar();
- if (Rune.TryCreate(firstChar, out Rune value) || Rune.TryCreate(firstChar, GetNextChar(), out value))
- {
- return value;
- }
-
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex);
- }
-
- // Fallback the current character using the remaining buffer and encoder if necessary
- // This can only be called by our encodings (other have to use the public fallback methods), so
- // we can use our EncoderNLS here too.
- // setEncoder is true if we're calling from a GetBytes method, false if we're calling from a GetByteCount
- //
- // Note that this could also change the contents of this.encoder, which is the same
- // object that the caller is using, so the caller could mess up the encoder for us
- // if they aren't careful.
- internal virtual unsafe bool InternalFallback(char ch, ref char* chars)
- {
- // Shouldn't have null charStart
- Debug.Assert(charStart != null,
- "[EncoderFallback.InternalFallbackBuffer]Fallback buffer is not initialized");
-
- // Get our index, remember chars was preincremented to point at next char, so have to -1
- int index = (int)(chars - charStart) - 1;
-
- // See if it was a high surrogate
- if (char.IsHighSurrogate(ch))
- {
- // See if there's a low surrogate to go with it
- if (chars >= this.charEnd)
- {
- // Nothing left in input buffer
- // No input, return 0 if mustflush is false
- if (this.encoder != null && !this.encoder.MustFlush)
- {
- // Done, nothing to fallback
- if (this.setEncoder)
- {
- bUsedEncoder = true;
- this.encoder._charLeftOver = ch;
- }
- bFallingBack = false;
- return false;
- }
- }
- else
- {
- // Might have a low surrogate
- char cNext = *chars;
- if (char.IsLowSurrogate(cNext))
- {
- // If already falling back then fail
- if (bFallingBack && iRecursionCount++ > iMaxRecursion)
- ThrowLastCharRecursive(char.ConvertToUtf32(ch, cNext));
-
- // Next is a surrogate, add it as surrogate pair, and increment chars
- chars++;
- bFallingBack = Fallback(ch, cNext, index);
- return bFallingBack;
- }
- // Next isn't a low surrogate, just fallback the high surrogate
- }
- }
-
- // If already falling back then fail
- if (bFallingBack && iRecursionCount++ > iMaxRecursion)
- ThrowLastCharRecursive((int)ch);
-
- // Fall back our char
- bFallingBack = Fallback(ch, index);
-
- return bFallingBack;
- }
-
- [DoesNotReturn]
- internal static void ThrowLastCharRecursive(int charRecursive) =>
- // Throw it, using our complete character
- throw new ArgumentException(SR.Format(SR.Argument_RecursiveFallback, charRecursive), "chars");
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncoderNLS.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncoderNLS.cs
deleted file mode 100644
index 5c813dc213c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/EncoderNLS.cs
+++ /dev/null
@@ -1,388 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Text
-{
- // An Encoder is used to encode a sequence of blocks of characters into
- // a sequence of blocks of bytes. Following instantiation of an encoder,
- // sequential blocks of characters are converted into blocks of bytes through
- // calls to the GetBytes method. The encoder maintains state between the
- // conversions, allowing it to correctly encode character sequences that span
- // adjacent blocks.
- //
- // Instances of specific implementations of the Encoder abstract base
- // class are typically obtained through calls to the GetEncoder method
- // of Encoding objects.
- //
-
- internal class EncoderNLS : Encoder
- {
- // Need a place for the last left over character, most of our encodings use this
- internal char _charLeftOver;
- private readonly Encoding _encoding;
- private bool _mustFlush;
- internal bool _throwOnOverflow;
- internal int _charsUsed;
-
- internal EncoderNLS(Encoding encoding)
- {
- _encoding = encoding;
- _fallback = _encoding.EncoderFallback;
- this.Reset();
- }
-
- public override void Reset()
- {
- _charLeftOver = (char)0;
- if (_fallbackBuffer != null)
- _fallbackBuffer.Reset();
- }
-
- public override unsafe int GetByteCount(char[] chars, int index, int count, bool flush)
- {
- // Validate input parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars),
- SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(chars),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // Just call the pointer version
- int result = -1;
- fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
- {
- result = GetByteCount(pChars + index, count, flush);
- }
- return result;
- }
-
- public override unsafe int GetByteCount(char* chars, int count, bool flush)
- {
- // Validate input parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars),
- SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- _mustFlush = flush;
- _throwOnOverflow = true;
- Debug.Assert(_encoding != null);
- return _encoding.GetByteCount(chars, count, this);
- }
-
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex, bool flush)
- {
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(chars),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException(nameof(byteIndex),
- SR.ArgumentOutOfRange_Index);
-
- int byteCount = bytes.Length - byteIndex;
-
- // Just call pointer version
- fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
- fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
-
- // Remember that charCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount,
- pBytes + byteIndex, byteCount, flush);
- }
-
- public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount, bool flush)
- {
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (byteCount < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(byteCount < 0 ? nameof(byteCount) : nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- _mustFlush = flush;
- _throwOnOverflow = true;
- Debug.Assert(_encoding != null);
- return _encoding.GetBytes(chars, charCount, bytes, byteCount, this);
- }
-
- // This method is used when your output buffer might not be large enough for the entire result.
- // Just call the pointer version. (This gets bytes)
- public override unsafe void Convert(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex, int byteCount, bool flush,
- out int charsUsed, out int bytesUsed, out bool completed)
- {
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (byteIndex < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(byteIndex < 0 ? nameof(byteIndex) : nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(chars),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (bytes.Length - byteIndex < byteCount)
- throw new ArgumentOutOfRangeException(nameof(bytes),
- SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // Just call the pointer version (can't do this for non-msft encoders)
- fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
- {
- fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- {
- Convert(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, flush,
- out charsUsed, out bytesUsed, out completed);
- }
- }
- }
-
- // This is the version that uses pointers. We call the base encoding worker function
- // after setting our appropriate internal variables. This is getting bytes
- public override unsafe void Convert(char* chars, int charCount,
- byte* bytes, int byteCount, bool flush,
- out int charsUsed, out int bytesUsed, out bool completed)
- {
- // Validate input parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars),
- SR.ArgumentNull_Array);
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // We don't want to throw
- _mustFlush = flush;
- _throwOnOverflow = false;
- _charsUsed = 0;
-
- // Do conversion
- Debug.Assert(_encoding != null);
- bytesUsed = _encoding.GetBytes(chars, charCount, bytes, byteCount, this);
- charsUsed = _charsUsed;
-
- // Per MSDN, "The completed output parameter indicates whether all the data in the input
- // buffer was converted and stored in the output buffer." That means we've successfully
- // consumed all the input _and_ there's no pending state or fallback data remaining to be output.
-
- completed = (charsUsed == charCount)
- && !this.HasState
- && (_fallbackBuffer is null || _fallbackBuffer.Remaining == 0);
- }
-
- public Encoding Encoding
- {
- get
- {
- Debug.Assert(_encoding != null);
- return _encoding;
- }
- }
-
- public bool MustFlush => _mustFlush;
-
- /// <summary>
- /// States whether a call to <see cref="Encoding.GetBytes(char*, int, byte*, int, EncoderNLS)"/> must first drain data on this <see cref="EncoderNLS"/> instance.
- /// </summary>
- internal bool HasLeftoverData => _charLeftOver != default || (_fallbackBuffer != null && _fallbackBuffer.Remaining > 0);
-
- // Anything left in our encoder?
- internal virtual bool HasState => _charLeftOver != (char)0;
-
- // Allow encoding to clear our must flush instead of throwing (in ThrowBytesOverflow)
- internal void ClearMustFlush()
- {
- _mustFlush = false;
- }
-
- internal int DrainLeftoverDataForGetByteCount(ReadOnlySpan<char> chars, out int charsConsumed)
- {
- // Quick check: we _should not_ have leftover fallback data from a previous invocation,
- // as we'd end up consuming any such data and would corrupt whatever Convert call happens
- // to be in progress.
-
- if (_fallbackBuffer != null && _fallbackBuffer.Remaining > 0)
- {
- throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty, Encoding.EncodingName, _fallbackBuffer.GetType()));
- }
-
- // If we have a leftover high surrogate from a previous operation, consume it now.
- // We won't clear the _charLeftOver field since GetByteCount is supposed to be
- // a non-mutating operation, and we need the field to retain its value for the
- // next call to Convert.
-
- charsConsumed = 0; // could be incorrect, will fix up later in the method
-
- if (_charLeftOver == default)
- {
- return 0; // no leftover high surrogate char - short-circuit and finish
- }
- else
- {
- char secondChar = default;
-
- if (chars.IsEmpty)
- {
- // If the input buffer is empty and we're not being asked to flush, no-op and return
- // success to our caller. If we're being asked to flush, the leftover high surrogate from
- // the previous operation will go through the fallback mechanism by itself.
-
- if (!MustFlush)
- {
- return 0; // no-op = success
- }
- }
- else
- {
- secondChar = chars[0];
- }
-
- // If we have to fallback the chars we're reading immediately below, populate the
- // fallback buffer with the invalid data. We'll just fall through to the "consume
- // fallback buffer" logic at the end of the method.
-
- bool didFallback;
-
- if (Rune.TryCreate(_charLeftOver, secondChar, out Rune rune))
- {
- charsConsumed = 1; // consumed the leftover high surrogate + the first char in the input buffer
-
- Debug.Assert(_encoding != null);
- if (_encoding.TryGetByteCount(rune, out int byteCount))
- {
- Debug.Assert(byteCount >= 0, "Encoding shouldn't have returned a negative byte count.");
- return byteCount;
- }
- else
- {
- // The fallback mechanism relies on a negative index to convey "the start of the invalid
- // sequence was some number of chars back before the current buffer." In this block and
- // in the block immediately thereafter, we know we have a single leftover high surrogate
- // character from a previous operation, so we provide an index of -1 to convey that the
- // char immediately before the current buffer was the start of the invalid sequence.
-
- didFallback = FallbackBuffer.Fallback(_charLeftOver, secondChar, index: -1);
- }
- }
- else
- {
- didFallback = FallbackBuffer.Fallback(_charLeftOver, index: -1);
- }
-
- // Now tally the number of bytes that would've been emitted as part of fallback.
- Debug.Assert(_fallbackBuffer != null);
- return _fallbackBuffer.DrainRemainingDataForGetByteCount();
- }
- }
-
- internal bool TryDrainLeftoverDataForGetBytes(ReadOnlySpan<char> chars, Span<byte> bytes, out int charsConsumed, out int bytesWritten)
- {
- // We may have a leftover high surrogate data from a previous invocation, or we may have leftover
- // data in the fallback buffer, or we may have neither, but we will never have both. Check for these
- // conditions and handle them now.
-
- charsConsumed = 0; // could be incorrect, will fix up later in the method
- bytesWritten = 0; // could be incorrect, will fix up later in the method
-
- if (_charLeftOver != default)
- {
- char secondChar = default;
-
- if (chars.IsEmpty)
- {
- // If the input buffer is empty and we're not being asked to flush, no-op and return
- // success to our caller. If we're being asked to flush, the leftover high surrogate from
- // the previous operation will go through the fallback mechanism by itself.
-
- if (!MustFlush)
- {
- charsConsumed = 0;
- bytesWritten = 0;
- return true; // no-op = success
- }
- }
- else
- {
- secondChar = chars[0];
- }
-
- // If we have to fallback the chars we're reading immediately below, populate the
- // fallback buffer with the invalid data. We'll just fall through to the "consume
- // fallback buffer" logic at the end of the method.
-
- if (Rune.TryCreate(_charLeftOver, secondChar, out Rune rune))
- {
- charsConsumed = 1; // at the very least, we consumed 1 char from the input
- Debug.Assert(_encoding != null);
- switch (_encoding.EncodeRune(rune, bytes, out bytesWritten))
- {
- case OperationStatus.Done:
- _charLeftOver = default; // we just consumed this char
- return true; // that's all - we've handled the leftover data
-
- case OperationStatus.DestinationTooSmall:
- _charLeftOver = default; // we just consumed this char
- _encoding.ThrowBytesOverflow(this, nothingEncoded: true); // will throw
- break;
-
- case OperationStatus.InvalidData:
- FallbackBuffer.Fallback(_charLeftOver, secondChar, index: -1); // see comment in DrainLeftoverDataForGetByteCount
- break;
-
- default:
- Debug.Fail("Unknown return value.");
- break;
- }
- }
- else
- {
- FallbackBuffer.Fallback(_charLeftOver, index: -1); // see comment in DrainLeftoverDataForGetByteCount
- }
- }
-
- // Now check the fallback buffer for any remaining data.
-
- if (_fallbackBuffer != null && _fallbackBuffer.Remaining > 0)
- {
- return _fallbackBuffer.TryDrainRemainingDataForGetBytes(bytes, out bytesWritten);
- }
-
- // And we're done!
-
- return true; // success
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncoderReplacementFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncoderReplacementFallback.cs
deleted file mode 100644
index ff13d691185..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/EncoderReplacementFallback.cs
+++ /dev/null
@@ -1,194 +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 System.Diagnostics;
-
-namespace System.Text
-{
- public sealed class EncoderReplacementFallback : EncoderFallback
- {
- // Our variables
- private readonly string _strDefault;
-
- // Construction. Default replacement fallback uses no best fit and ? replacement string
- public EncoderReplacementFallback() : this("?")
- {
- }
-
- public EncoderReplacementFallback(string replacement)
- {
- // Must not be null
- if (replacement == null)
- throw new ArgumentNullException(nameof(replacement));
-
- // Make sure it doesn't have bad surrogate pairs
- bool bFoundHigh = false;
- for (int i = 0; i < replacement.Length; i++)
- {
- // Found a surrogate?
- if (char.IsSurrogate(replacement, i))
- {
- // High or Low?
- if (char.IsHighSurrogate(replacement, i))
- {
- // if already had a high one, stop
- if (bFoundHigh)
- break; // break & throw at the bFoundHIgh below
- bFoundHigh = true;
- }
- else
- {
- // Low, did we have a high?
- if (!bFoundHigh)
- {
- // Didn't have one, make if fail when we stop
- bFoundHigh = true;
- break;
- }
-
- // Clear flag
- bFoundHigh = false;
- }
- }
- // If last was high we're in trouble (not surrogate so not low surrogate, so break)
- else if (bFoundHigh)
- break;
- }
- if (bFoundHigh)
- throw new ArgumentException(SR.Format(SR.Argument_InvalidCharSequenceNoIndex, nameof(replacement)));
-
- _strDefault = replacement;
- }
-
- public string DefaultString => _strDefault;
-
- public override EncoderFallbackBuffer CreateFallbackBuffer() =>
- new EncoderReplacementFallbackBuffer(this);
-
- // Maximum number of characters that this instance of this fallback could return
- public override int MaxCharCount => _strDefault.Length;
-
- public override bool Equals(object? value) =>
- value is EncoderReplacementFallback that &&
- _strDefault == that._strDefault;
-
- public override int GetHashCode() => _strDefault.GetHashCode();
- }
-
- public sealed class EncoderReplacementFallbackBuffer : EncoderFallbackBuffer
- {
- // Store our default string
- private readonly string _strDefault;
- private int _fallbackCount = -1;
- private int _fallbackIndex = -1;
-
- // Construction
- public EncoderReplacementFallbackBuffer(EncoderReplacementFallback fallback)
- {
- // 2X in case we're a surrogate pair
- _strDefault = fallback.DefaultString + fallback.DefaultString;
- }
-
- // Fallback Methods
- public override bool Fallback(char charUnknown, int index)
- {
- // If we had a buffer already we're being recursive, throw, it's probably at the suspect
- // character in our array.
- if (_fallbackCount >= 1)
- {
- // If we're recursive we may still have something in our buffer that makes this a surrogate
- if (char.IsHighSurrogate(charUnknown) && _fallbackCount >= 0 &&
- char.IsLowSurrogate(_strDefault[_fallbackIndex + 1]))
- ThrowLastCharRecursive(char.ConvertToUtf32(charUnknown, _strDefault[_fallbackIndex + 1]));
-
- // Nope, just one character
- ThrowLastCharRecursive(unchecked((int)charUnknown));
- }
-
- // Go ahead and get our fallback
- // Divide by 2 because we aren't a surrogate pair
- _fallbackCount = _strDefault.Length / 2;
- _fallbackIndex = -1;
-
- return _fallbackCount != 0;
- }
-
- public override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
- {
- // Double check input surrogate pair
- if (!char.IsHighSurrogate(charUnknownHigh))
- throw new ArgumentOutOfRangeException(nameof(charUnknownHigh),
- SR.Format(SR.ArgumentOutOfRange_Range, 0xD800, 0xDBFF));
-
- if (!char.IsLowSurrogate(charUnknownLow))
- throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
- SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
-
- // If we had a buffer already we're being recursive, throw, it's probably at the suspect
- // character in our array.
- if (_fallbackCount >= 1)
- ThrowLastCharRecursive(char.ConvertToUtf32(charUnknownHigh, charUnknownLow));
-
- // Go ahead and get our fallback
- _fallbackCount = _strDefault.Length;
- _fallbackIndex = -1;
-
- return _fallbackCount != 0;
- }
-
- public override char GetNextChar()
- {
- // We want it to get < 0 because == 0 means that the current/last character is a fallback
- // and we need to detect recursion. We could have a flag but we already have this counter.
- _fallbackCount--;
- _fallbackIndex++;
-
- // Do we have anything left? 0 is now last fallback char, negative is nothing left
- if (_fallbackCount < 0)
- return '\0';
-
- // Need to get it out of the buffer.
- // Make sure it didn't wrap from the fast count-- path
- if (_fallbackCount == int.MaxValue)
- {
- _fallbackCount = -1;
- return '\0';
- }
-
- // Now make sure its in the expected range
- Debug.Assert(_fallbackIndex < _strDefault.Length && _fallbackIndex >= 0,
- "Index exceeds buffer range");
-
- return _strDefault[_fallbackIndex];
- }
-
- public override bool MovePrevious()
- {
- // Back up one, only if we just processed the last character (or earlier)
- if (_fallbackCount >= -1 && _fallbackIndex >= 0)
- {
- _fallbackIndex--;
- _fallbackCount++;
- return true;
- }
-
- // Return false 'cause we couldn't do it.
- return false;
- }
-
- // How many characters left to output?
- public override int Remaining =>
- // Our count is 0 for 1 character left.
- (_fallbackCount < 0) ? 0 : _fallbackCount;
-
- // Clear the buffer
- public override unsafe void Reset()
- {
- _fallbackCount = -1;
- _fallbackIndex = 0;
- charStart = null;
- bFallingBack = false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Encoding.Internal.cs b/netcore/System.Private.CoreLib/shared/System/Text/Encoding.Internal.cs
deleted file mode 100644
index 83d8c56f9fd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Encoding.Internal.cs
+++ /dev/null
@@ -1,1288 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Text
-{
- public partial class Encoding
- {
- /*
- * This file contains infrastructure code that supports a simplified way of writing
- * internally-implemented Encoding types. In this system, the individual Encoding types
- * are no longer responsible for handling anything related to the EncoderNLS / DecoderNLS
- * infrastructure, nor are they responsible for implementing anything related to fallback
- * buffers logic.
- *
- * Instead, subclassed types are responsible only for transcoding of individual scalar values
- * to and from the encoding's byte representation (see the two methods immediately below).
- * They can optionally implement fast-path logic to perform bulk transcoding up until the
- * first segment of data that cannot be transcoded. They can special-case certain fallback
- * mechanisms if desired.
- *
- * Most of the fast-path code is written using raw pointers as the exchange types, just as
- * in the standard Encoding infrastructure. Since the fallback logic is more complex, most
- * of it is written using type-safe constructs like Span<T>, with some amount of glue to
- * allow it to work correctly with pointer-based fast-path code.
- *
- * A typical call graph for GetBytes is represented below, using ASCIIEncoding as an example.
- *
- * ASCIIEncoding.GetBytes(...) [non-EncoderNLS path, public virtual override]
- * `- <parameter validation>
- * - ASCIIEncoding.GetBytesCommon [private helper method per derived type, inlined]
- * `- ASCIIEncoding.GetBytesFast [overridden fast-path implementation, inlined]
- * - <if all data transcoded, return immediately>
- * - <if all data not transcoded...>
- * `- Encoding.GetBytesWithFallback [non-virtual stub method to call main GetBytesWithFallback worker]
- * `- Encoding.GetBytesWithFallback [virtual method whose base implementation contains slow fallback logic]
- * `- <may be overridden to provide optimized fallback logic>
- * - <create EncodeFallbackBuffer instance>
- * - <perform the following in a loop:>
- * `- <invoke fast-path logic via virtual method dispatch on derived type>
- * - <read next "bad" scalar value from source>
- * - <run this bad value through the fallback buffer>
- * - <drain the fallback buffer to the destination>
- * - <loop until source is fully consumed or destination is full>
- * - <signal full or partial success to EncoderNLS instance / throw if necessary>
- *
- * The call graph for GetBytes(..., EncoderNLS) is similar:
- *
- * Encoding.GetBytes(..., EncoderNLS) [base implementation]
- * `- <if no leftover data from previous invocation, invoke fast-path>
- * - <if fast-path invocation above completed, return immediately>
- * - <if not all data transcoded, or if there was leftover data from previous invocation...>
- * `- Encoding.GetBytesWithFallback [non-virtual stub method]
- * `- <drain any leftover data from previous invocation>
- * - <invoke fast-path again>
- * - <if all data transcoded, return immediately>
- * - <if all data not transcoded...>
- * `- Encoding.GetBytesWithFallback [virtual method as described above]
- *
- * There are different considerations in each call graph for things like error handling,
- * since the error conditions will be different depending on whether or not an EncoderNLS
- * instance is available and what values its properties have.
- */
-
- /*
- * THESE TWO METHODS MUST BE OVERRIDDEN BY A SUBCLASSED TYPE
- */
-
- internal virtual OperationStatus DecodeFirstRune(ReadOnlySpan<byte> bytes, out Rune value, out int bytesConsumed)
- {
- Debug.Fail("This should be overridden by a subclassed type.");
- throw NotImplemented.ByDesign;
- }
-
- internal virtual OperationStatus EncodeRune(Rune value, Span<byte> bytes, out int bytesWritten)
- {
- Debug.Fail("This should be overridden by a subclassed type.");
- throw NotImplemented.ByDesign;
- }
-
- /*
- * ALL OTHER LOGIC CAN BE IMPLEMENTED IN TERMS OF THE TWO METHODS ABOVE.
- * FOR IMPROVED PERFORMANCE, SUBCLASSED TYPES MAY WANT TO OVERRIDE ONE OR MORE VIRTUAL METHODS BELOW.
- */
-
- /*
- * GETBYTECOUNT FAMILY OF FUNCTIONS
- */
-
- /// <summary>
- /// Given a <see cref="Rune"/>, determines its byte count under the current <see cref="Encoding"/>.
- /// Returns <see langword="false"/> if the <see cref="Rune"/> cannot be represented in the
- /// current <see cref="Encoding"/>.
- /// </summary>
- internal virtual bool TryGetByteCount(Rune value, out int byteCount)
- {
- // Any production-quality type would override this method and provide a real
- // implementation, so we won't provide a base implementation. However, a
- // non-shipping slow reference implementation is provided below for convenience.
-
-#if false
- Span<byte> bytes = stackalloc byte[4]; // max 4 bytes per input scalar
-
- OperationStatus opStatus = EncodeRune(value, bytes, out byteCount);
- Debug.Assert(opStatus == OperationStatus.Done || opStatus == OperationStatus.InvalidData, "Unexpected return value.");
-
- return (opStatus == OperationStatus.Done);
-#else
- Debug.Fail("This should be overridden by a subclassed type.");
- throw NotImplemented.ByDesign;
-#endif
- }
-
- /// <summary>
- /// Entry point from <see cref="EncoderNLS.GetByteCount"/>.
- /// </summary>
- internal virtual unsafe int GetByteCount(char* pChars, int charCount, EncoderNLS? encoder)
- {
- Debug.Assert(encoder != null, "This code path should only be called from EncoderNLS.");
- Debug.Assert(charCount >= 0, "Caller should've checked this condition.");
- Debug.Assert(pChars != null || charCount == 0, "Cannot provide a null pointer and a non-zero count.");
-
- // We're going to try to stay on the fast-path as much as we can. That means that we have
- // no leftover data to drain and the entire source buffer can be consumed in a single
- // fast-path invocation. If either of these doesn't hold, we'll go down the slow path of
- // creating spans, draining the EncoderNLS instance, and falling back.
-
- int totalByteCount = 0;
- int charsConsumed = 0;
-
- if (!encoder.HasLeftoverData)
- {
- totalByteCount = GetByteCountFast(pChars, charCount, encoder.Fallback, out charsConsumed);
- if (charsConsumed == charCount)
- {
- return totalByteCount;
- }
- }
-
- // We had leftover data, or we couldn't consume the entire input buffer.
- // Let's go down the draining + fallback mechanisms.
-
- totalByteCount += GetByteCountWithFallback(pChars, charCount, charsConsumed, encoder);
- if (totalByteCount < 0)
- {
- ThrowConversionOverflow();
- }
-
- return totalByteCount;
- }
-
- /// <summary>
- /// Counts the number of <see langword="byte"/>s that would result from transcoding the source
- /// data, exiting when the source buffer is consumed or when the first unreadable data is encountered.
- /// The implementation may inspect <paramref name="fallback"/> to short-circuit any counting
- /// operation, but it should not attempt to call <see cref="EncoderFallback.CreateFallbackBuffer"/>.
- /// </summary>
- /// <returns>
- /// Via <paramref name="charsConsumed"/>, the number of elements from <paramref name="pChars"/> which
- /// were consumed; and returns the transcoded byte count up to this point.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the byte count would be greater than <see cref="int.MaxValue"/>.
- /// (Implementation should call <see cref="ThrowConversionOverflow"/>.)
- /// </exception>
- /// <remarks>
- /// The implementation should not attempt to perform any sort of fallback behavior.
- /// If custom fallback behavior is necessary, override <see cref="GetByteCountWithFallback"/>.
- /// </remarks>
- private protected virtual unsafe int GetByteCountFast(char* pChars, int charsLength, EncoderFallback? fallback, out int charsConsumed)
- {
- // Any production-quality type would override this method and provide a real
- // implementation, so we won't provide a base implementation. However, a
- // non-shipping slow reference implementation is provided below for convenience.
-
-#if false
- ReadOnlySpan<char> chars = new ReadOnlySpan<char>(pChars, charsLength);
- int totalByteCount = 0;
-
- while (!chars.IsEmpty)
- {
- if (Rune.DecodeUtf16(chars, out Rune scalarValue, out int charsConsumedThisIteration) != OperationStatus.Done
- || !TryGetByteCount(scalarValue, out int byteCountThisIteration))
- {
- // Invalid UTF-16 data, or not convertible to target encoding
-
- break;
- }
-
- chars = chars.Slice(charsConsumedThisIteration);
-
- totalByteCount += byteCountThisIteration;
- if (totalByteCount < 0)
- {
- ThrowConversionOverflow();
- }
- }
-
- charsConsumed = charsLength - chars.Length; // number of chars consumed across all loop iterations above
- return totalByteCount;
-#else
- Debug.Fail("This should be overridden by a subclassed type.");
- throw NotImplemented.ByDesign;
-#endif
- }
-
- /// <summary>
- /// Counts the number of bytes that would result from transcoding the provided chars,
- /// with no associated <see cref="EncoderNLS"/>. The first two arguments are based on the
- /// original input before invoking this method; and <paramref name="charsConsumedSoFar"/>
- /// signals where in the provided buffer the fallback loop should begin operating.
- /// </summary>
- /// <returns>
- /// The byte count resulting from transcoding the input data.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the resulting byte count is greater than <see cref="int.MaxValue"/>.
- /// (Implementation should call <see cref="ThrowConversionOverflow"/>.)
- /// </exception>
- [MethodImpl(MethodImplOptions.NoInlining)] // don't stack spill spans into our caller
- private protected unsafe int GetByteCountWithFallback(char* pCharsOriginal, int originalCharCount, int charsConsumedSoFar)
- {
- // This is a stub method that's marked "no-inlining" so that it we don't stack-spill spans
- // into our immediate caller. Doing so increases the method prolog in what's supposed to
- // be a very fast path.
-
- Debug.Assert(0 <= charsConsumedSoFar && charsConsumedSoFar < originalCharCount, "Invalid arguments provided to method.");
-
- return GetByteCountWithFallback(
- chars: new ReadOnlySpan<char>(pCharsOriginal, originalCharCount).Slice(charsConsumedSoFar),
- originalCharsLength: originalCharCount,
- encoder: null);
- }
-
- /// <summary>
- /// Gets the number of <see langword="byte"/>s that would result from transcoding the provided
- /// input data, with an associated <see cref="EncoderNLS"/>. The first two arguments are
- /// based on the original input before invoking this method; and <paramref name="charsConsumedSoFar"/>
- /// signals where in the provided source buffer the fallback loop should begin operating.
- /// The behavior of this method is to consume (non-destructively) any leftover data in the
- /// <see cref="EncoderNLS"/> instance, then to invoke the <see cref="GetByteCountFast"/> virtual method
- /// after data has been drained, then to call <see cref="GetByteCountWithFallback(ReadOnlySpan{char}, int, EncoderNLS)"/>.
- /// </summary>
- /// <returns>
- /// The total number of bytes that would result from transcoding the remaining portion of the source buffer.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the return value would exceed <see cref="int.MaxValue"/>.
- /// (The implementation should call <see cref="ThrowConversionOverflow"/>.)
- /// </exception>
- private unsafe int GetByteCountWithFallback(char* pOriginalChars, int originalCharCount, int charsConsumedSoFar, EncoderNLS encoder)
- {
- Debug.Assert(encoder != null, "This code path should only be called from EncoderNLS.");
- Debug.Assert(0 <= charsConsumedSoFar && charsConsumedSoFar <= originalCharCount, "Caller should've checked this condition.");
-
- // First, try draining any data that already exists on the encoder instance. If we can't complete
- // that operation, there's no point to continuing down to the main workhorse methods.
-
- ReadOnlySpan<char> chars = new ReadOnlySpan<char>(pOriginalChars, originalCharCount).Slice(charsConsumedSoFar);
-
- int totalByteCount = encoder.DrainLeftoverDataForGetByteCount(chars, out int charsConsumedJustNow);
- chars = chars.Slice(charsConsumedJustNow);
-
- // Now try invoking the "fast path" (no fallback) implementation.
- // We can use Unsafe.AsPointer here since these spans are created from pinned data (raw pointers).
-
- totalByteCount += GetByteCountFast(
- pChars: (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(chars)),
- charsLength: chars.Length,
- fallback: encoder.Fallback,
- charsConsumed: out charsConsumedJustNow);
-
- if (totalByteCount < 0)
- {
- ThrowConversionOverflow();
- }
-
- chars = chars.Slice(charsConsumedJustNow);
-
- // If there's still data remaining in the source buffer, go down the fallback path.
- // Otherwise we're finished.
-
- if (!chars.IsEmpty)
- {
- totalByteCount += GetByteCountWithFallback(chars, originalCharCount, encoder);
- if (totalByteCount < 0)
- {
- ThrowConversionOverflow();
- }
- }
-
- return totalByteCount;
- }
-
- /// <summary>
- /// Counts the number of bytes that would result from transcoding the provided chars,
- /// using the provided <see cref="EncoderFallbackBuffer"/> if necessary.
- /// </summary>
- /// <returns>
- /// The byte count resulting from transcoding the input data.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the resulting byte count is greater than <see cref="int.MaxValue"/>.
- /// (Implementation should call <see cref="ThrowConversionOverflow"/>.)
- /// </exception>
- private protected virtual unsafe int GetByteCountWithFallback(ReadOnlySpan<char> chars, int originalCharsLength, EncoderNLS? encoder)
- {
- Debug.Assert(!chars.IsEmpty, "Caller shouldn't invoke this method with an empty input buffer.");
- Debug.Assert(originalCharsLength >= 0, "Caller provided invalid parameter.");
-
- // Since we're using Unsafe.AsPointer in our central loop, we want to ensure everything is pinned.
-
- fixed (char* _pChars_Unused = &MemoryMarshal.GetReference(chars))
- {
- EncoderFallbackBuffer fallbackBuffer = EncoderFallbackBuffer.CreateAndInitialize(this, encoder, originalCharsLength);
- int totalByteCount = 0;
-
- do
- {
- // There's still data in the source buffer; why wasn't the previous fast-path able to consume it fully?
- // There are two scenarios: (a) the source buffer contained invalid / incomplete UTF-16 data;
- // or (b) the encoding can't translate this scalar value.
-
- if (Rune.DecodeFromUtf16(chars, out Rune firstScalarValue, out int charsConsumedThisIteration) == OperationStatus.NeedMoreData
- && encoder != null
- && !encoder.MustFlush)
- {
- // We saw a standalone high surrogate at the end of the buffer, and the
- // active EncoderNLS instance isn't asking us to flush. Since a call to
- // GetBytes would've consumed this char by storing it in EncoderNLS._charLeftOver,
- // we'll "consume" it by ignoring it. The next call to GetBytes will
- // pick it up correctly.
-
- goto Finish;
- }
-
- // We saw invalid UTF-16 data, or we saw a high surrogate that we need to flush (and
- // thus treat as invalid), or we saw valid UTF-16 data that this encoder doesn't support.
- // In any case we'll run it through the fallback mechanism.
-
- int byteCountThisIteration = fallbackBuffer.InternalFallbackGetByteCount(chars, out charsConsumedThisIteration);
-
- Debug.Assert(byteCountThisIteration >= 0, "Fallback shouldn't have returned a negative value.");
- Debug.Assert(charsConsumedThisIteration >= 0, "Fallback shouldn't have returned a negative value.");
-
- totalByteCount += byteCountThisIteration;
- if (totalByteCount < 0)
- {
- ThrowConversionOverflow();
- }
-
- chars = chars.Slice(charsConsumedThisIteration);
-
- if (!chars.IsEmpty)
- {
- // Still data remaining - run it through the fast-path to find the next data to fallback.
- // While building up the tally we need to continually check for integer overflow
- // since fallbacks can change the total byte count in unexpected ways.
-
- byteCountThisIteration = GetByteCountFast(
- pChars: (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(chars)),
- charsLength: chars.Length,
- fallback: null, // already tried this earlier and we still fell down the common path, so skip from now on
- charsConsumed: out charsConsumedThisIteration);
-
- Debug.Assert(byteCountThisIteration >= 0, "Workhorse shouldn't have returned a negative value.");
- Debug.Assert(charsConsumedThisIteration >= 0, "Workhorse shouldn't have returned a negative value.");
-
- totalByteCount += byteCountThisIteration;
- if (totalByteCount < 0)
- {
- ThrowConversionOverflow();
- }
-
- chars = chars.Slice(charsConsumedThisIteration);
- }
- } while (!chars.IsEmpty);
-
- Finish:
-
- Debug.Assert(fallbackBuffer.Remaining == 0, "There should be no data in the fallback buffer after GetByteCount.");
-
- return totalByteCount;
- }
- }
-
- /*
- * GETBYTES FAMILY OF FUNCTIONS
- */
-
- /// <summary>
- /// Entry point from <see cref="EncoderNLS.GetBytes"/> and <see cref="EncoderNLS.Convert"/>.
- /// </summary>
- internal virtual unsafe int GetBytes(char* pChars, int charCount, byte* pBytes, int byteCount, EncoderNLS? encoder)
- {
- Debug.Assert(encoder != null, "This code path should only be called from EncoderNLS.");
- Debug.Assert(charCount >= 0, "Caller should've checked this condition.");
- Debug.Assert(pChars != null || charCount == 0, "Cannot provide a null pointer and a non-zero count.");
- Debug.Assert(byteCount >= 0, "Caller should've checked this condition.");
- Debug.Assert(pBytes != null || byteCount == 0, "Cannot provide a null pointer and a non-zero count.");
-
- // We're going to try to stay on the fast-path as much as we can. That means that we have
- // no leftover data to drain and the entire source buffer can be transcoded in a single
- // fast-path invocation. If either of these doesn't hold, we'll go down the slow path of
- // creating spans, draining the EncoderNLS instance, and falling back.
-
- int bytesWritten = 0;
- int charsConsumed = 0;
-
- if (!encoder.HasLeftoverData)
- {
- bytesWritten = GetBytesFast(pChars, charCount, pBytes, byteCount, out charsConsumed);
- if (charsConsumed == charCount)
- {
- encoder._charsUsed = charCount;
- return bytesWritten;
- }
- }
-
- // We had leftover data, or we couldn't consume the entire input buffer.
- // Let's go down the draining + fallback mechanisms.
-
- return GetBytesWithFallback(pChars, charCount, pBytes, byteCount, charsConsumed, bytesWritten, encoder);
- }
-
- /// <summary>
- /// Transcodes <see langword="char"/>s to <see langword="byte"/>s, exiting when the source or destination
- /// buffer is consumed or when the first unreadable data is encountered.
- /// </summary>
- /// <returns>
- /// Via <paramref name="charsConsumed"/>, the number of elements from <paramref name="pChars"/> which
- /// were consumed; and returns the number of elements written to <paramref name="pBytes"/>.
- /// </returns>
- /// <remarks>
- /// The implementation should not attempt to perform any sort of fallback behavior.
- /// If custom fallback behavior is necessary, override <see cref="GetBytesWithFallback"/>.
- /// </remarks>
- private protected virtual unsafe int GetBytesFast(char* pChars, int charsLength, byte* pBytes, int bytesLength, out int charsConsumed)
- {
- // Any production-quality type would override this method and provide a real
- // implementation, so we won't provide a base implementation. However, a
- // non-shipping slow reference implementation is provided below for convenience.
-
-#if false
- ReadOnlySpan<char> chars = new ReadOnlySpan<char>(pChars, charsLength);
- Span<byte> bytes = new Span<byte>(pBytes, bytesLength);
-
- while (!chars.IsEmpty)
- {
- if (Rune.DecodeUtf16(chars, out Rune scalarValue, out int charsConsumedJustNow) != OperationStatus.Done
- || EncodeRune(scalarValue, bytes, out int bytesWrittenJustNow) != OperationStatus.Done)
- {
- // Invalid UTF-16 data, or not convertible to target encoding, or destination buffer too small to contain encoded value
-
- break;
- }
-
- chars = chars.Slice(charsConsumedJustNow);
- bytes = bytes.Slice(bytesWrittenJustNow);
- }
-
- charsConsumed = charsLength - chars.Length; // number of chars consumed across all loop iterations above
- return bytesLength - bytes.Length; // number of bytes written across all loop iterations above
-#else
- Debug.Fail("This should be overridden by a subclassed type.");
- throw NotImplemented.ByDesign;
-#endif
- }
-
- /// <summary>
- /// Transcodes chars to bytes, with no associated <see cref="EncoderNLS"/>. The first four arguments are
- /// based on the original input before invoking this method; and <paramref name="charsConsumedSoFar"/>
- /// and <paramref name="bytesWrittenSoFar"/> signal where in the provided buffers the fallback loop
- /// should begin operating. The behavior of this method is to call the <see cref="GetBytesWithFallback"/>
- /// virtual method as overridden by the specific type, and failing that go down the shared fallback path.
- /// </summary>
- /// <returns>
- /// The total number of bytes written to <paramref name="pOriginalBytes"/>, including <paramref name="bytesWrittenSoFar"/>.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the destination buffer is not large enough to hold the entirety of the transcoded data.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoInlining)]
- private protected unsafe int GetBytesWithFallback(char* pOriginalChars, int originalCharCount, byte* pOriginalBytes, int originalByteCount, int charsConsumedSoFar, int bytesWrittenSoFar)
- {
- // This is a stub method that's marked "no-inlining" so that it we don't stack-spill spans
- // into our immediate caller. Doing so increases the method prolog in what's supposed to
- // be a very fast path.
-
- Debug.Assert(0 <= charsConsumedSoFar && charsConsumedSoFar < originalCharCount, "Invalid arguments provided to method.");
- Debug.Assert(0 <= bytesWrittenSoFar && bytesWrittenSoFar <= originalByteCount, "Invalid arguments provided to method.");
-
- return GetBytesWithFallback(
- chars: new ReadOnlySpan<char>(pOriginalChars, originalCharCount).Slice(charsConsumedSoFar),
- originalCharsLength: originalCharCount,
- bytes: new Span<byte>(pOriginalBytes, originalByteCount).Slice(bytesWrittenSoFar),
- originalBytesLength: originalByteCount,
- encoder: null);
- }
-
- /// <summary>
- /// Transcodes chars to bytes, with an associated <see cref="EncoderNLS"/>. The first four arguments are
- /// based on the original input before invoking this method; and <paramref name="charsConsumedSoFar"/>
- /// and <paramref name="bytesWrittenSoFar"/> signal where in the provided buffers the fallback loop
- /// should begin operating. The behavior of this method is to drain any leftover data in the
- /// <see cref="EncoderNLS"/> instance, then to invoke the <see cref="GetBytesFast"/> virtual method
- /// after data has been drained, then to call <see cref="GetBytesWithFallback(ReadOnlySpan{char}, int, Span{byte}, int, EncoderNLS)"/>.
- /// </summary>
- /// <returns>
- /// The total number of bytes written to <paramref name="pOriginalBytes"/>, including <paramref name="bytesWrittenSoFar"/>.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the destination buffer is too small to make any forward progress at all, or if the destination buffer is
- /// too small to contain the entirety of the transcoded data and the <see cref="EncoderNLS"/> instance disallows
- /// partial transcoding.
- /// </exception>
- private unsafe int GetBytesWithFallback(char* pOriginalChars, int originalCharCount, byte* pOriginalBytes, int originalByteCount, int charsConsumedSoFar, int bytesWrittenSoFar, EncoderNLS encoder)
- {
- Debug.Assert(encoder != null, "This code path should only be called from EncoderNLS.");
- Debug.Assert(0 <= charsConsumedSoFar && charsConsumedSoFar <= originalCharCount, "Caller should've checked this condition.");
- Debug.Assert(0 <= bytesWrittenSoFar && bytesWrittenSoFar <= originalByteCount, "Caller should've checked this condition.");
-
- // First, try draining any data that already exists on the encoder instance. If we can't complete
- // that operation, there's no point to continuing down to the main workhorse methods.
-
- ReadOnlySpan<char> chars = new ReadOnlySpan<char>(pOriginalChars, originalCharCount).Slice(charsConsumedSoFar);
- Span<byte> bytes = new Span<byte>(pOriginalBytes, originalByteCount).Slice(bytesWrittenSoFar);
-
- bool drainFinishedSuccessfully = encoder.TryDrainLeftoverDataForGetBytes(chars, bytes, out int charsConsumedJustNow, out int bytesWrittenJustNow);
-
- chars = chars.Slice(charsConsumedJustNow); // whether or not the drain finished, we may have made some progress
- bytes = bytes.Slice(bytesWrittenJustNow);
-
- if (!drainFinishedSuccessfully)
- {
- ThrowBytesOverflow(encoder, nothingEncoded: bytes.Length == originalByteCount); // might not throw if we wrote at least one byte
- }
- else
- {
- // Now try invoking the "fast path" (no fallback) implementation.
- // We can use Unsafe.AsPointer here since these spans are created from pinned data (raw pointers).
-
- bytesWrittenJustNow = GetBytesFast(
- pChars: (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(chars)),
- charsLength: chars.Length,
- pBytes: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(bytes)),
- bytesLength: bytes.Length,
- charsConsumed: out charsConsumedJustNow);
-
- chars = chars.Slice(charsConsumedJustNow);
- bytes = bytes.Slice(bytesWrittenJustNow);
-
- // If there's still data remaining in the source buffer, go down the fallback path.
- // Otherwise we're finished.
-
- if (!chars.IsEmpty)
- {
- // We'll optimistically tell the encoder that we're using everything; the
- // GetBytesWithFallback method will overwrite this field if necessary.
-
- encoder._charsUsed = originalCharCount;
- return GetBytesWithFallback(chars, originalCharCount, bytes, originalByteCount, encoder);
- }
- }
-
- encoder._charsUsed = originalCharCount - chars.Length; // total number of characters consumed up until now
- return originalByteCount - bytes.Length; // total number of bytes written up until now
- }
-
- /// <summary>
- /// Transcodes chars to bytes, using <see cref="Encoding.EncoderFallback"/> or <see cref="Encoder.Fallback"/> if needed.
- /// </summary>
- /// <returns>
- /// The total number of bytes written to <paramref name="bytes"/> (based on <paramref name="originalBytesLength"/>).
- /// </returns>
- /// <remarks>
- /// The derived class should override this method if it might be able to provide a more optimized fallback
- /// implementation, deferring to the base implementation if needed. This method calls <see cref="ThrowBytesOverflow"/>
- /// if necessary.
- /// </remarks>
- private protected virtual unsafe int GetBytesWithFallback(ReadOnlySpan<char> chars, int originalCharsLength, Span<byte> bytes, int originalBytesLength, EncoderNLS? encoder)
- {
- Debug.Assert(!chars.IsEmpty, "Caller shouldn't invoke this method with an empty input buffer.");
- Debug.Assert(originalCharsLength >= 0, "Caller provided invalid parameter.");
- Debug.Assert(originalBytesLength >= 0, "Caller provided invalid parameter.");
-
- // Since we're using Unsafe.AsPointer in our central loop, we want to ensure everything is pinned.
-
- fixed (char* _pChars_Unused = &MemoryMarshal.GetReference(chars))
- fixed (byte* _pBytes_Unused = &MemoryMarshal.GetReference(bytes))
- {
- EncoderFallbackBuffer fallbackBuffer = EncoderFallbackBuffer.CreateAndInitialize(this, encoder, originalCharsLength);
-
- do
- {
- // There's still data in the source buffer; why wasn't the previous fast-path able to consume it fully?
- // There are two scenarios: (a) the source buffer contained invalid / incomplete UTF-16 data;
- // or (b) the encoding can't translate this scalar value.
-
- switch (Rune.DecodeFromUtf16(chars, out Rune firstScalarValue, out int charsConsumedThisIteration))
- {
- case OperationStatus.NeedMoreData:
- Debug.Assert(charsConsumedThisIteration == chars.Length, "If returning NeedMoreData, should out the entire buffer length as chars consumed.");
- if (encoder is null || encoder.MustFlush)
- {
- goto case OperationStatus.InvalidData; // see comment in GetByteCountWithFallback
- }
- else
- {
- encoder._charLeftOver = chars[0]; // squirrel away remaining high surrogate char and finish
- chars = ReadOnlySpan<char>.Empty;
- goto Finish;
- }
-
- case OperationStatus.InvalidData:
- break;
-
- default:
- if (EncodeRune(firstScalarValue, bytes, out _) == OperationStatus.DestinationTooSmall)
- {
- goto Finish; // source buffer contained valid UTF-16 but encoder ran out of space in destination buffer
- }
- break; // source buffer contained valid UTF-16 but encoder doesn't support this scalar value
- }
-
- // Now we know the reason for failure was that the original input was invalid
- // for the encoding in use. Run it through the fallback mechanism.
-
- bool fallbackFinished = fallbackBuffer.TryInternalFallbackGetBytes(chars, bytes, out charsConsumedThisIteration, out int bytesWrittenThisIteration);
-
- // Regardless of whether the fallback finished, it did consume some number of
- // chars, and it may have written some number of bytes.
-
- chars = chars.Slice(charsConsumedThisIteration);
- bytes = bytes.Slice(bytesWrittenThisIteration);
-
- if (!fallbackFinished)
- {
- goto Finish; // fallback has pending state - it'll get written out on the next GetBytes call
- }
-
- if (!chars.IsEmpty)
- {
- // Still data remaining - run it through the fast-path to find the next data to fallback.
-
- bytesWrittenThisIteration = GetBytesFast(
- pChars: (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(chars)),
- charsLength: chars.Length,
- pBytes: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(bytes)),
- bytesLength: bytes.Length,
- charsConsumed: out charsConsumedThisIteration);
-
- Debug.Assert(bytesWrittenThisIteration >= 0, "Workhorse shouldn't have returned a negative value.");
- Debug.Assert(charsConsumedThisIteration >= 0, "Workhorse shouldn't have returned a negative value.");
-
- chars = chars.Slice(charsConsumedThisIteration);
- bytes = bytes.Slice(bytesWrittenThisIteration);
- }
- } while (!chars.IsEmpty);
-
- Finish:
-
- // We reach this point when we deplete the source or destination buffer. There are a few
- // cases to consider now. If the source buffer has been fully consumed and there's no
- // leftover data in the EncoderNLS or the fallback buffer, we've completed transcoding.
- // If the source buffer isn't empty or there's leftover data in the fallback buffer,
- // it means we ran out of space in the destintion buffer. This is an unrecoverable error
- // if no EncoderNLS is in use (because only EncoderNLS can handle partial success), and
- // even if an EncoderNLS is in use this is only recoverable if the EncoderNLS instance
- // allows partial completion. Let's check all of these conditions now.
-
- if (!chars.IsEmpty || fallbackBuffer.Remaining > 0)
- {
- // The line below will also throw if the encoder couldn't make any progress at all
- // because the output buffer wasn't large enough to contain the result of even
- // a single scalar conversion or fallback.
-
- ThrowBytesOverflow(encoder, nothingEncoded: bytes.Length == originalBytesLength);
- }
-
- // If an EncoderNLS instance is active, update its "total consumed character count" value.
-
- if (encoder != null)
- {
- Debug.Assert(originalCharsLength >= chars.Length, "About to report a negative number of chars used?");
- encoder._charsUsed = originalCharsLength - chars.Length; // number of chars consumed
- }
-
- Debug.Assert(fallbackBuffer.Remaining == 0 || encoder != null, "Shouldn't have any leftover data in fallback buffer unless an EncoderNLS is in use.");
-
- return originalBytesLength - bytes.Length;
- }
- }
-
- /*
- * GETCHARCOUNT FAMILY OF FUNCTIONS
- */
-
- /// <summary>
- /// Entry point from <see cref="DecoderNLS.GetCharCount"/>.
- /// </summary>
- internal virtual unsafe int GetCharCount(byte* pBytes, int byteCount, DecoderNLS? decoder)
- {
- Debug.Assert(decoder != null, "This code path should only be called from DecoderNLS.");
- Debug.Assert(byteCount >= 0, "Caller should've checked this condition.");
- Debug.Assert(pBytes != null || byteCount == 0, "Cannot provide a null pointer and a non-zero count.");
-
- // We're going to try to stay on the fast-path as much as we can. That means that we have
- // no leftover data to drain and the entire source buffer can be consumed in a single
- // fast-path invocation. If either of these doesn't hold, we'll go down the slow path of
- // creating spans, draining the DecoderNLS instance, and falling back.
-
- Debug.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0, "Fallback buffer can't hold data between GetChars invocations.");
-
- int totalCharCount = 0;
- int bytesConsumed = 0;
-
- if (!decoder.HasLeftoverData)
- {
- totalCharCount = GetCharCountFast(pBytes, byteCount, decoder.Fallback, out bytesConsumed);
- if (bytesConsumed == byteCount)
- {
- return totalCharCount;
- }
- }
-
- // We had leftover data, or we couldn't consume the entire input buffer.
- // Let's go down the draining + fallback mechanisms.
-
- totalCharCount += GetCharCountWithFallback(pBytes, byteCount, bytesConsumed, decoder);
- if (totalCharCount < 0)
- {
- ThrowConversionOverflow();
- }
-
- return totalCharCount;
- }
-
- /// <summary>
- /// Counts the number of <see langword="char"/>s that would result from transcoding the source
- /// data, exiting when the source buffer is consumed or when the first unreadable data is encountered.
- /// The implementation may inspect <paramref name="fallback"/> to short-circuit any counting
- /// operation, but it should not attempt to call <see cref="DecoderFallback.CreateFallbackBuffer"/>.
- /// </summary>
- /// <returns>
- /// Via <paramref name="bytesConsumed"/>, the number of elements from <paramref name="pBytes"/> which
- /// were consumed; and returns the transcoded char count up to this point.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the char count would be greater than <see cref="int.MaxValue"/>.
- /// (Implementation should call <see cref="ThrowConversionOverflow"/>.)
- /// </exception>
- /// <remarks>
- /// The implementation should not attempt to perform any sort of fallback behavior.
- /// If custom fallback behavior is necessary, override <see cref="GetCharCountWithFallback"/>.
- /// </remarks>
- private protected virtual unsafe int GetCharCountFast(byte* pBytes, int bytesLength, DecoderFallback? fallback, out int bytesConsumed)
- {
- // Any production-quality type would override this method and provide a real
- // implementation, so we won't provide a base implementation. However, a
- // non-shipping slow reference implementation is provided below for convenience.
-
-#if false
- ReadOnlySpan<byte> bytes = new ReadOnlySpan<byte>(pBytes, bytesLength);
- int totalCharCount = 0;
-
- while (!bytes.IsEmpty)
- {
- // We don't care about statuses other than Done. The fallback mechanism will handle those.
-
- if (DecodeFirstRune(bytes, out Rune value, out int bytesConsumedJustNow) != OperationStatus.Done)
- {
- break;
- }
-
- totalCharCount += value.Utf16SequenceLength;
- if (totalCharCount < 0)
- {
- ThrowConversionOverflow();
- }
-
- bytes = bytes.Slice(bytesConsumedJustNow);
- }
-
- bytesConsumed = bytesLength - bytes.Length; // number of bytes consumed across all loop iterations above
- return totalCharCount;
-#else
- Debug.Fail("This should be overridden by a subclassed type.");
- throw NotImplemented.ByDesign;
-#endif
- }
-
- /// <summary>
- /// Counts the number of chars that would result from transcoding the provided bytes,
- /// with no associated <see cref="DecoderNLS"/>. The first two arguments are based on the
- /// original input before invoking this method; and <paramref name="bytesConsumedSoFar"/>
- /// signals where in the provided buffer the fallback loop should begin operating.
- /// </summary>
- /// <returns>
- /// The char count resulting from transcoding the input data.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the resulting char count is greater than <see cref="int.MaxValue"/>.
- /// (Implementation should call <see cref="ThrowConversionOverflow"/>.)
- /// </exception>
- [MethodImpl(MethodImplOptions.NoInlining)] // don't stack spill spans into our caller
- private protected unsafe int GetCharCountWithFallback(byte* pBytesOriginal, int originalByteCount, int bytesConsumedSoFar)
- {
- // This is a stub method that's marked "no-inlining" so that it we don't stack-spill spans
- // into our immediate caller. Doing so increases the method prolog in what's supposed to
- // be a very fast path.
-
- Debug.Assert(0 <= bytesConsumedSoFar && bytesConsumedSoFar < originalByteCount, "Invalid arguments provided to method.");
-
- return GetCharCountWithFallback(
- bytes: new ReadOnlySpan<byte>(pBytesOriginal, originalByteCount).Slice(bytesConsumedSoFar),
- originalBytesLength: originalByteCount,
- decoder: null);
- }
-
- /// <summary>
- /// Gets the number of <see langword="char"/>s that would result from transcoding the provided
- /// input data, with an associated <see cref="DecoderNLS"/>. The first two arguments are
- /// based on the original input before invoking this method; and <paramref name="bytesConsumedSoFar"/>
- /// signals where in the provided source buffer the fallback loop should begin operating.
- /// The behavior of this method is to consume (non-destructively) any leftover data in the
- /// <see cref="DecoderNLS"/> instance, then to invoke the <see cref="GetCharCountFast"/> virtual method
- /// after data has been drained, then to call <see cref="GetCharCountWithFallback(ReadOnlySpan{byte}, int, DecoderNLS)"/>.
- /// </summary>
- /// <returns>
- /// The total number of chars that would result from transcoding the remaining portion of the source buffer.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the return value would exceed <see cref="int.MaxValue"/>.
- /// (The implementation should call <see cref="ThrowConversionOverflow"/>.)
- /// </exception>
- private unsafe int GetCharCountWithFallback(byte* pOriginalBytes, int originalByteCount, int bytesConsumedSoFar, DecoderNLS decoder)
- {
- Debug.Assert(decoder != null, "This code path should only be called from DecoderNLS.");
- Debug.Assert(0 <= bytesConsumedSoFar && bytesConsumedSoFar <= originalByteCount, "Caller should've checked this condition.");
-
- // First, try draining any data that already exists on the decoder instance. If we can't complete
- // that operation, there's no point to continuing down to the main workhorse methods.
-
- ReadOnlySpan<byte> bytes = new ReadOnlySpan<byte>(pOriginalBytes, originalByteCount).Slice(bytesConsumedSoFar);
-
- int bytesConsumedJustNow;
- int totalCharCount = 0;
-
- if (decoder.HasLeftoverData)
- {
- totalCharCount = decoder.DrainLeftoverDataForGetCharCount(bytes, out bytesConsumedJustNow);
- bytes = bytes.Slice(bytesConsumedJustNow);
- }
-
- // Now try invoking the "fast path" (no fallback) implementation.
- // We can use Unsafe.AsPointer here since these spans are created from pinned data (raw pointers).
-
- totalCharCount += GetCharCountFast(
- pBytes: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(bytes)),
- bytesLength: bytes.Length,
- fallback: decoder.Fallback,
- bytesConsumed: out bytesConsumedJustNow);
-
- if (totalCharCount < 0)
- {
- ThrowConversionOverflow();
- }
-
- bytes = bytes.Slice(bytesConsumedJustNow);
-
- // If there's still data remaining in the source buffer, go down the fallback path.
- // Otherwise we're finished.
-
- if (!bytes.IsEmpty)
- {
- totalCharCount += GetCharCountWithFallback(bytes, originalByteCount, decoder);
- if (totalCharCount < 0)
- {
- ThrowConversionOverflow();
- }
- }
-
- return totalCharCount;
- }
-
- /// <summary>
- /// Counts the number of chars that would result from transcoding the provided bytes,
- /// using the provided <see cref="DecoderFallbackBuffer"/> if necessary.
- /// </summary>
- /// <returns>
- /// The char count resulting from transcoding the input data.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the resulting char count is greater than <see cref="int.MaxValue"/>.
- /// (Implementation should call <see cref="ThrowConversionOverflow"/>.)
- /// </exception>
- private unsafe int GetCharCountWithFallback(ReadOnlySpan<byte> bytes, int originalBytesLength, DecoderNLS? decoder)
- {
- Debug.Assert(!bytes.IsEmpty, "Caller shouldn't invoke this method with an empty input buffer.");
- Debug.Assert(originalBytesLength >= 0, "Caller provided invalid parameter.");
-
- // Since we're using Unsafe.AsPointer in our central loop, we want to ensure everything is pinned.
-
- fixed (byte* _pBytes_Unused = &MemoryMarshal.GetReference(bytes))
- {
- DecoderFallbackBuffer fallbackBuffer = DecoderFallbackBuffer.CreateAndInitialize(this, decoder, originalBytesLength);
- int totalCharCount = 0;
-
- do
- {
- // There's still data in the source buffer; why wasn't the previous fast-path able to consume it fully?
- // There are two scenarios: (a) the source buffer contained invalid data, or it contained incomplete data.
-
- if (DecodeFirstRune(bytes, out Rune firstScalarValue, out int bytesConsumedThisIteration) == OperationStatus.NeedMoreData
- && decoder != null
- && !decoder.MustFlush)
- {
- // We saw incomplete data at the end of the buffer, and the active DecoderNLS isntance
- // isn't asking us to flush. Since a call to GetChars would've consumed this data by
- // storing it in the DecoderNLS instance, we'll "consume" it by ignoring it.
- // The next call to GetChars will pick it up correctly.
-
- goto Finish;
- }
-
- // We saw invalid binary data, or we saw incomplete data that we need to flush (and thus
- // treat as invalid). In any case we'll run through the fallback mechanism.
-
- int charCountThisIteration = fallbackBuffer.InternalFallbackGetCharCount(bytes, bytesConsumedThisIteration);
-
- Debug.Assert(charCountThisIteration >= 0, "Fallback shouldn't have returned a negative value.");
-
- totalCharCount += charCountThisIteration;
- if (totalCharCount < 0)
- {
- ThrowConversionOverflow();
- }
-
- bytes = bytes.Slice(bytesConsumedThisIteration);
-
- if (!bytes.IsEmpty)
- {
- // Still data remaining - run it through the fast-path to find the next data to fallback.
- // While building up the tally we need to continually check for integer overflow
- // since fallbacks can change the total byte count in unexpected ways.
-
- charCountThisIteration = GetCharCountFast(
- pBytes: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(bytes)),
- bytesLength: bytes.Length,
- fallback: null, // wasn't able to be short-circuited by our caller; don't bother trying again
- bytesConsumed: out bytesConsumedThisIteration);
-
- Debug.Assert(charCountThisIteration >= 0, "Workhorse shouldn't have returned a negative value.");
- Debug.Assert(bytesConsumedThisIteration >= 0, "Workhorse shouldn't have returned a negative value.");
-
- totalCharCount += charCountThisIteration;
- if (totalCharCount < 0)
- {
- ThrowConversionOverflow();
- }
-
- bytes = bytes.Slice(bytesConsumedThisIteration);
- }
- } while (!bytes.IsEmpty);
-
- Finish:
-
- Debug.Assert(fallbackBuffer.Remaining == 0, "There should be no data in the fallback buffer after GetCharCount.");
-
- return totalCharCount;
- }
- }
-
- /*
- * GETCHARS FAMILY OF FUNCTIONS
- */
-
- /// <summary>
- /// Entry point from <see cref="DecoderNLS.GetChars"/> and <see cref="DecoderNLS.Convert"/>.
- /// </summary>
- internal virtual unsafe int GetChars(byte* pBytes, int byteCount, char* pChars, int charCount, DecoderNLS? decoder)
- {
- Debug.Assert(decoder != null, "This code path should only be called from DecoderNLS.");
- Debug.Assert(byteCount >= 0, "Caller should've checked this condition.");
- Debug.Assert(pBytes != null || byteCount == 0, "Cannot provide a null pointer and a non-zero count.");
- Debug.Assert(charCount >= 0, "Caller should've checked this condition.");
- Debug.Assert(pChars != null || charCount == 0, "Cannot provide a null pointer and a non-zero count.");
-
- // We're going to try to stay on the fast-path as much as we can. That means that we have
- // no leftover data to drain and the entire source buffer can be transcoded in a single
- // fast-path invocation. If either of these doesn't hold, we'll go down the slow path of
- // creating spans, draining the DecoderNLS instance, and falling back.
-
- int charsWritten = 0;
- int bytesConsumed = 0;
-
- if (!decoder.HasLeftoverData)
- {
- charsWritten = GetCharsFast(pBytes, byteCount, pChars, charCount, out bytesConsumed);
- if (bytesConsumed == byteCount)
- {
- decoder._bytesUsed = byteCount;
- return charsWritten;
- }
- }
-
- // We had leftover data, or we couldn't consume the entire input buffer.
- // Let's go down the draining + fallback mechanisms.
-
- return GetCharsWithFallback(pBytes, byteCount, pChars, charCount, bytesConsumed, charsWritten, decoder);
- }
-
- /// <summary>
- /// Transcodes <see langword="byte"/>s to <see langword="char"/>s, exiting when the source or destination
- /// buffer is consumed or when the first unreadable data is encountered.
- /// </summary>
- /// <returns>
- /// Via <paramref name="bytesConsumed"/>, the number of elements from <paramref name="pBytes"/> which
- /// were consumed; and returns the number of elements written to <paramref name="pChars"/>.
- /// </returns>
- /// <remarks>
- /// The implementation should not attempt to perform any sort of fallback behavior.
- /// If custom fallback behavior is necessary, override <see cref="GetCharsWithFallback"/>.
- /// </remarks>
- private protected virtual unsafe int GetCharsFast(byte* pBytes, int bytesLength, char* pChars, int charsLength, out int bytesConsumed)
- {
- // Any production-quality type would override this method and provide a real
- // implementation, so we won't provide a base implementation. However, a
- // non-shipping slow reference implementation is provided below for convenience.
-
-#if false
- ReadOnlySpan<byte> bytes = new ReadOnlySpan<byte>(pBytes, bytesLength);
- Span<char> chars = new Span<char>(pChars, charsLength);
-
- while (!bytes.IsEmpty)
- {
- if ((DecodeFirstRune(bytes, out Rune firstScalarValue, out int bytesConsumedJustNow) != OperationStatus.Done)
- || !firstScalarValue.TryEncode(chars, out int charsWrittenJustNow))
- {
- // Invalid or incomplete binary data, or destination buffer too small to contain decoded value
-
- break;
- }
-
- bytes = bytes.Slice(bytesConsumedJustNow);
- chars = chars.Slice(charsWrittenJustNow);
- }
-
- bytesConsumed = bytesLength - bytes.Length; // number of bytes consumed across all loop iterations above
- return charsLength - chars.Length; // number of chars written across all loop iterations above
-#else
- Debug.Fail("This should be overridden by a subclassed type.");
- throw NotImplemented.ByDesign;
-#endif
- }
-
- /// <summary>
- /// Transcodes bytes to chars, with no associated <see cref="DecoderNLS"/>. The first four arguments are
- /// based on the original input before invoking this method; and <paramref name="bytesConsumedSoFar"/>
- /// and <paramref name="charsWrittenSoFar"/> signal where in the provided buffers the fallback loop
- /// should begin operating. The behavior of this method is to call the <see cref="GetCharsWithFallback"/>
- /// virtual method as overridden by the specific type, and failing that go down the shared fallback path.
- /// </summary>
- /// <returns>
- /// The total number of chars written to <paramref name="pOriginalChars"/>, including <paramref name="charsWrittenSoFar"/>.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the destination buffer is not large enough to hold the entirety of the transcoded data.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoInlining)]
- private protected unsafe int GetCharsWithFallback(byte* pOriginalBytes, int originalByteCount, char* pOriginalChars, int originalCharCount, int bytesConsumedSoFar, int charsWrittenSoFar)
- {
- // This is a stub method that's marked "no-inlining" so that it we don't stack-spill spans
- // into our immediate caller. Doing so increases the method prolog in what's supposed to
- // be a very fast path.
-
- Debug.Assert(0 <= bytesConsumedSoFar && bytesConsumedSoFar < originalByteCount, "Invalid arguments provided to method.");
- Debug.Assert(0 <= charsWrittenSoFar && charsWrittenSoFar <= originalCharCount, "Invalid arguments provided to method.");
-
- return GetCharsWithFallback(
- bytes: new ReadOnlySpan<byte>(pOriginalBytes, originalByteCount).Slice(bytesConsumedSoFar),
- originalBytesLength: originalByteCount,
- chars: new Span<char>(pOriginalChars, originalCharCount).Slice(charsWrittenSoFar),
- originalCharsLength: originalCharCount,
- decoder: null);
- }
-
- /// <summary>
- /// Transcodes bytes to chars, with an associated <see cref="DecoderNLS"/>. The first four arguments are
- /// based on the original input before invoking this method; and <paramref name="bytesConsumedSoFar"/>
- /// and <paramref name="charsWrittenSoFar"/> signal where in the provided buffers the fallback loop
- /// should begin operating. The behavior of this method is to drain any leftover data in the
- /// <see cref="DecoderNLS"/> instance, then to invoke the <see cref="GetCharsFast"/> virtual method
- /// after data has been drained, then to call <see cref="GetCharsWithFallback(ReadOnlySpan{byte}, int, Span{char}, int, DecoderNLS)"/>.
- /// </summary>
- /// <returns>
- /// The total number of chars written to <paramref name="pOriginalChars"/>, including <paramref name="charsWrittenSoFar"/>.
- /// </returns>
- /// <exception cref="ArgumentException">
- /// If the destination buffer is too small to make any forward progress at all, or if the destination buffer is
- /// too small to contain the entirety of the transcoded data and the <see cref="DecoderNLS"/> instance disallows
- /// partial transcoding.
- /// </exception>
- private protected unsafe int GetCharsWithFallback(byte* pOriginalBytes, int originalByteCount, char* pOriginalChars, int originalCharCount, int bytesConsumedSoFar, int charsWrittenSoFar, DecoderNLS decoder)
- {
- Debug.Assert(decoder != null, "This code path should only be called from DecoderNLS.");
- Debug.Assert(0 <= bytesConsumedSoFar && bytesConsumedSoFar <= originalByteCount, "Caller should've checked this condition.");
- Debug.Assert(0 <= charsWrittenSoFar && charsWrittenSoFar <= originalCharCount, "Caller should've checked this condition.");
-
- // First, try draining any data that already exists on the encoder instance. If we can't complete
- // that operation, there's no point to continuing down to the main workhorse methods.
- //
- // Like GetBytes, there may be leftover data in the DecoderNLS instance. But unlike GetBytes,
- // the bytes -> chars conversion doesn't allow leftover data in the fallback buffer. This means
- // that the drain operation below will either succeed fully or fail; there's no partial success
- // condition as with the chars -> bytes conversion. The drain method will throw if there's not
- // enough space in the destination buffer.
-
- ReadOnlySpan<byte> bytes = new ReadOnlySpan<byte>(pOriginalBytes, originalByteCount).Slice(bytesConsumedSoFar);
- Span<char> chars = new Span<char>(pOriginalChars, originalCharCount).Slice(charsWrittenSoFar);
-
- int bytesConsumedJustNow;
- int charsWrittenJustNow;
-
- if (decoder.HasLeftoverData)
- {
- charsWrittenJustNow = decoder.DrainLeftoverDataForGetChars(bytes, chars, out bytesConsumedJustNow);
- bytes = bytes.Slice(bytesConsumedJustNow);
- chars = chars.Slice(charsWrittenJustNow);
- }
-
- Debug.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0, "Should be no remaining fallback data at this point.");
-
- // Now try invoking the "fast path" (no fallback buffer) implementation.
- // We can use Unsafe.AsPointer here since these spans are created from pinned data (raw pointers).
-
- charsWrittenJustNow = GetCharsFast(
- pBytes: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(bytes)),
- bytesLength: bytes.Length,
- pChars: (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(chars)),
- charsLength: chars.Length,
- bytesConsumed: out bytesConsumedJustNow);
-
- bytes = bytes.Slice(bytesConsumedJustNow);
- chars = chars.Slice(charsWrittenJustNow);
-
- // We'll optimistically tell the decoder that we're using everything; the
- // GetCharsWithFallback method will overwrite this field if necessary.
-
- decoder._bytesUsed = originalByteCount;
-
- if (bytes.IsEmpty)
- {
- return originalCharCount - chars.Length; // total number of chars written
- }
- else
- {
- return GetCharsWithFallback(bytes, originalByteCount, chars, originalCharCount, decoder);
- }
- }
-
- /// <summary>
- /// Transcodes bytes to chars, using <see cref="Encoding.DecoderFallback"/> or <see cref="Decoder.Fallback"/> if needed.
- /// </summary>
- /// <returns>
- /// The total number of chars written to <paramref name="chars"/> (based on <paramref name="originalCharsLength"/>).
- /// </returns>
- /// <remarks>
- /// The derived class should override this method if it might be able to provide a more optimized fallback
- /// implementation, deferring to the base implementation if needed. This method calls <see cref="ThrowCharsOverflow"/>
- /// if necessary.
- /// </remarks>
- private protected virtual unsafe int GetCharsWithFallback(ReadOnlySpan<byte> bytes, int originalBytesLength, Span<char> chars, int originalCharsLength, DecoderNLS? decoder)
- {
- Debug.Assert(!bytes.IsEmpty, "Caller shouldn't invoke this method with an empty input buffer.");
- Debug.Assert(originalBytesLength >= 0, "Caller provided invalid parameter.");
- Debug.Assert(originalCharsLength >= 0, "Caller provided invalid parameter.");
-
- // Since we're using Unsafe.AsPointer in our central loop, we want to ensure everything is pinned.
-
- fixed (byte* _pBytes_Unused = &MemoryMarshal.GetReference(bytes))
- fixed (char* _pChars_Unused = &MemoryMarshal.GetReference(chars))
- {
- DecoderFallbackBuffer fallbackBuffer = DecoderFallbackBuffer.CreateAndInitialize(this, decoder, originalBytesLength);
-
- do
- {
- // There's still data in the source buffer; why wasn't the previous fast-path able to consume it fully?
- // There are two scenarios: (a) the source buffer contained invalid data, or it contained incomplete data.
-
- int charsWrittenThisIteration;
-
- switch (DecodeFirstRune(bytes, out _, out int bytesConsumedThisIteration))
- {
- case OperationStatus.NeedMoreData:
- Debug.Assert(bytesConsumedThisIteration == bytes.Length, "If returning NeedMoreData, should out the entire buffer length as bytes consumed.");
- if (decoder is null || decoder.MustFlush)
- {
- goto case OperationStatus.InvalidData; // see comment in GetCharCountWithFallback
- }
- else
- {
- decoder.SetLeftoverData(bytes); // squirrel away remaining data and finish
- bytes = ReadOnlySpan<byte>.Empty;
- goto Finish;
- }
-
- case OperationStatus.InvalidData:
- if (fallbackBuffer.TryInternalFallbackGetChars(bytes, bytesConsumedThisIteration, chars, out charsWrittenThisIteration))
- {
- // We successfully consumed some bytes, sent it through the fallback, and wrote some chars.
-
- Debug.Assert(charsWrittenThisIteration >= 0, "Fallback shouldn't have returned a negative value.");
- break;
- }
- else
- {
- // We generated fallback data, but the destination buffer wasn't large enough to hold it.
- // Don't mark any of the bytes we ran through the fallback as consumed, and terminate
- // the loop now and let our caller handle this condition.
-
- goto Finish;
- }
-
- default:
- goto Finish; // no error on input, so destination must have been too small
- }
-
- bytes = bytes.Slice(bytesConsumedThisIteration);
- chars = chars.Slice(charsWrittenThisIteration);
-
- if (!bytes.IsEmpty)
- {
- // Still data remaining - run it through the fast-path to find the next data to fallback.
- // We need to figure out why we weren't able to make progress.
-
- charsWrittenThisIteration = GetCharsFast(
- pBytes: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(bytes)),
- bytesLength: bytes.Length,
- pChars: (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(chars)),
- charsLength: chars.Length,
- bytesConsumed: out bytesConsumedThisIteration);
-
- Debug.Assert(charsWrittenThisIteration >= 0, "Workhorse shouldn't have returned a negative value.");
- Debug.Assert(bytesConsumedThisIteration >= 0, "Workhorse shouldn't have returned a negative value.");
-
- bytes = bytes.Slice(bytesConsumedThisIteration);
- chars = chars.Slice(charsWrittenThisIteration);
- }
- } while (!bytes.IsEmpty);
-
- Finish:
-
- // We reach this point when we deplete the source or destination buffer. See main comment
- // at the end of GetBytesWithFallback for how the below logic works; the primary difference
- // here is that GetChars disallows leftover data in the fallback buffer between calls.
-
- Debug.Assert(fallbackBuffer.Remaining == 0);
-
- if (!bytes.IsEmpty)
- {
- // The line below will also throw if the decoder couldn't make any progress at all
- // because the output buffer wasn't large enough to contain the result of even
- // a single scalar conversion or fallback.
-
- ThrowCharsOverflow(decoder, nothingDecoded: chars.Length == originalCharsLength);
- }
-
- // If a DecoderNLS instance is active, update its "total consumed byte count" value.
-
- if (decoder != null)
- {
- Debug.Assert(originalBytesLength >= bytes.Length, "About to report a negative number of bytes used?");
- decoder._bytesUsed = originalBytesLength - bytes.Length; // number of bytes consumed
- }
-
- return originalCharsLength - chars.Length; // total number of chars written
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Encoding.cs b/netcore/System.Private.CoreLib/shared/System/Text/Encoding.cs
deleted file mode 100644
index bbf5d62abea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Encoding.cs
+++ /dev/null
@@ -1,1491 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.InteropServices;
-using System.Runtime.Serialization;
-
-namespace System.Text
-{
- // This abstract base class represents a character encoding. The class provides
- // methods to convert arrays and strings of Unicode characters to and from
- // arrays of bytes. A number of Encoding implementations are provided in
- // the System.Text package, including:
- //
- // ASCIIEncoding, which encodes Unicode characters as single 7-bit
- // ASCII characters. This encoding only supports character values between 0x00
- // and 0x7F.
- // BaseCodePageEncoding, which encapsulates a Windows code page. Any
- // installed code page can be accessed through this encoding, and conversions
- // are performed using the WideCharToMultiByte and
- // MultiByteToWideChar Windows API functions.
- // UnicodeEncoding, which encodes each Unicode character as two
- // consecutive bytes. Both little-endian (code page 1200) and big-endian (code
- // page 1201) encodings are recognized.
- // UTF7Encoding, which encodes Unicode characters using the UTF-7
- // encoding (UTF-7 stands for UCS Transformation Format, 7-bit form). This
- // encoding supports all Unicode character values, and can also be accessed
- // as code page 65000.
- // UTF8Encoding, which encodes Unicode characters using the UTF-8
- // encoding (UTF-8 stands for UCS Transformation Format, 8-bit form). This
- // encoding supports all Unicode character values, and can also be accessed
- // as code page 65001.
- // UTF32Encoding, both 12000 (little endian) & 12001 (big endian)
- //
- // In addition to directly instantiating Encoding objects, an
- // application can use the ForCodePage, GetASCII,
- // GetDefault, GetUnicode, GetUTF7, and GetUTF8
- // methods in this class to obtain encodings.
- //
- // Through an encoding, the GetBytes method is used to convert arrays
- // of characters to arrays of bytes, and the GetChars method is used to
- // convert arrays of bytes to arrays of characters. The GetBytes and
- // GetChars methods maintain no state between conversions, and are
- // generally intended for conversions of complete blocks of bytes and
- // characters in one operation. When the data to be converted is only available
- // in sequential blocks (such as data read from a stream) or when the amount of
- // data is so large that it needs to be divided into smaller blocks, an
- // application may choose to use a Decoder or an Encoder to
- // perform the conversion. Decoders and encoders allow sequential blocks of
- // data to be converted and they maintain the state required to support
- // conversions of data that spans adjacent blocks. Decoders and encoders are
- // obtained using the GetDecoder and GetEncoder methods.
- //
- // The core GetBytes and GetChars methods require the caller
- // to provide the destination buffer and ensure that the buffer is large enough
- // to hold the entire result of the conversion. When using these methods,
- // either directly on an Encoding object or on an associated
- // Decoder or Encoder, an application can use one of two methods
- // to allocate destination buffers.
- //
- // The GetByteCount and GetCharCount methods can be used to
- // compute the exact size of the result of a particular conversion, and an
- // appropriately sized buffer for that conversion can then be allocated.
- // The GetMaxByteCount and GetMaxCharCount methods can be
- // be used to compute the maximum possible size of a conversion of a given
- // number of bytes or characters, and a buffer of that size can then be reused
- // for multiple conversions.
- //
- // The first method generally uses less memory, whereas the second method
- // generally executes faster.
- //
-
- public abstract partial class Encoding : ICloneable
- {
- // For netcore we use UTF8 as default encoding since ANSI isn't available
- private static readonly UTF8Encoding.UTF8EncodingSealed s_defaultEncoding = new UTF8Encoding.UTF8EncodingSealed(encoderShouldEmitUTF8Identifier: false);
-
- // Returns an encoding for the system's current ANSI code page.
- public static Encoding Default => s_defaultEncoding;
-
- //
- // The following values are from mlang.idl. These values
- // should be in sync with those in mlang.idl.
- //
- internal const int MIMECONTF_MAILNEWS = 0x00000001;
- internal const int MIMECONTF_BROWSER = 0x00000002;
- internal const int MIMECONTF_SAVABLE_MAILNEWS = 0x00000100;
- internal const int MIMECONTF_SAVABLE_BROWSER = 0x00000200;
-
- // Special Case Code Pages
- private const int CodePageDefault = 0;
- private const int CodePageNoOEM = 1; // OEM Code page not supported
- private const int CodePageNoMac = 2; // MAC code page not supported
- private const int CodePageNoThread = 3; // Thread code page not supported
- private const int CodePageNoSymbol = 42; // Symbol code page not supported
- private const int CodePageUnicode = 1200; // Unicode
- private const int CodePageBigEndian = 1201; // Big Endian Unicode
-
- // Latin 1 & ASCII Code Pages
- internal const int CodePageASCII = 20127; // ASCII
- internal const int ISO_8859_1 = 28591; // Latin1
-
- // Special code pages
- private const int CodePageUTF7 = 65000;
- private const int CodePageUTF8 = 65001;
- private const int CodePageUTF32 = 12000;
- private const int CodePageUTF32BE = 12001;
-
- internal int _codePage = 0;
-
- internal CodePageDataItem? _dataItem = null;
-
- // Because of encoders we may be read only
- [OptionalField(VersionAdded = 2)]
- private bool _isReadOnly = true;
-
- // Encoding (encoder) fallback
- internal EncoderFallback encoderFallback = null!;
- internal DecoderFallback decoderFallback = null!;
-
- protected Encoding() : this(0)
- {
- }
-
- protected Encoding(int codePage)
- {
- // Validate code page
- if (codePage < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(codePage));
- }
-
- // Remember code page
- _codePage = codePage;
-
- // Use default encoder/decoder fallbacks
- this.SetDefaultFallbacks();
- }
-
- // This constructor is needed to allow any sub-classing implementation to provide encoder/decoder fallback objects
- // because the encoding object is always created as read-only object and don't allow setting encoder/decoder fallback
- // after the creation is done.
- protected Encoding(int codePage, EncoderFallback? encoderFallback, DecoderFallback? decoderFallback)
- {
- // Validate code page
- if (codePage < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(codePage));
- }
-
- // Remember code page
- _codePage = codePage;
-
- this.encoderFallback = encoderFallback ?? new InternalEncoderBestFitFallback(this);
- this.decoderFallback = decoderFallback ?? new InternalDecoderBestFitFallback(this);
- }
-
- // Default fallback that we'll use.
- internal virtual void SetDefaultFallbacks()
- {
- // For UTF-X encodings, we use a replacement fallback with an "\xFFFD" string,
- // For ASCII we use "?" replacement fallback, etc.
- encoderFallback = new InternalEncoderBestFitFallback(this);
- decoderFallback = new InternalDecoderBestFitFallback(this);
- }
-
- // Converts a byte array from one encoding to another. The bytes in the
- // bytes array are converted from srcEncoding to
- // dstEncoding, and the returned value is a new byte array
- // containing the result of the conversion.
- //
- public static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding,
- byte[] bytes)
- {
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes));
-
- return Convert(srcEncoding, dstEncoding, bytes, 0, bytes.Length);
- }
-
- // Converts a range of bytes in a byte array from one encoding to another.
- // This method converts count bytes from bytes starting at
- // index index from srcEncoding to dstEncoding, and
- // returns a new byte array containing the result of the conversion.
- //
- public static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding,
- byte[] bytes, int index, int count)
- {
- if (srcEncoding == null || dstEncoding == null)
- {
- throw new ArgumentNullException(srcEncoding == null ? nameof(srcEncoding) : nameof(dstEncoding),
- SR.ArgumentNull_Array);
- }
- if (bytes == null)
- {
- throw new ArgumentNullException(nameof(bytes),
- SR.ArgumentNull_Array);
- }
-
- return dstEncoding.GetBytes(srcEncoding.GetChars(bytes, index, count));
- }
-
- public static void RegisterProvider(EncodingProvider provider)
- {
- // Parameters validated inside EncodingProvider
- EncodingProvider.AddProvider(provider);
- }
-
- public static Encoding GetEncoding(int codepage)
- {
- Encoding? result = EncodingProvider.GetEncodingFromProvider(codepage);
- if (result != null)
- return result;
-
- switch (codepage)
- {
- case CodePageDefault: return Default; // 0
- case CodePageUnicode: return Unicode; // 1200
- case CodePageBigEndian: return BigEndianUnicode; // 1201
- case CodePageUTF32: return UTF32; // 12000
- case CodePageUTF32BE: return BigEndianUTF32; // 12001
- case CodePageUTF7: return UTF7; // 65000
- case CodePageUTF8: return UTF8; // 65001
- case CodePageASCII: return ASCII; // 20127
- case ISO_8859_1: return Latin1; // 28591
-
- // We don't allow the following special code page values that Win32 allows.
- case CodePageNoOEM: // 1 CP_OEMCP
- case CodePageNoMac: // 2 CP_MACCP
- case CodePageNoThread: // 3 CP_THREAD_ACP
- case CodePageNoSymbol: // 42 CP_SYMBOL
- throw new ArgumentException(SR.Format(SR.Argument_CodepageNotSupported, codepage), nameof(codepage));
- }
-
- if (codepage < 0 || codepage > 65535)
- {
- throw new ArgumentOutOfRangeException(
- nameof(codepage), SR.Format(SR.ArgumentOutOfRange_Range, 0, 65535));
- }
-
- throw new NotSupportedException(SR.Format(SR.NotSupported_NoCodepageData, codepage));
- }
-
- public static Encoding GetEncoding(int codepage,
- EncoderFallback encoderFallback, DecoderFallback decoderFallback)
- {
- Encoding? baseEncoding = EncodingProvider.GetEncodingFromProvider(codepage, encoderFallback, decoderFallback);
-
- if (baseEncoding != null)
- return baseEncoding;
-
- // Get the default encoding (which is cached and read only)
- baseEncoding = GetEncoding(codepage);
-
- // Clone it and set the fallback
- Encoding fallbackEncoding = (Encoding)baseEncoding.Clone();
- fallbackEncoding.EncoderFallback = encoderFallback;
- fallbackEncoding.DecoderFallback = decoderFallback;
-
- return fallbackEncoding;
- }
-
- // Returns an Encoding object for a given name or a given code page value.
- //
- public static Encoding GetEncoding(string name)
- {
- // NOTE: If you add a new encoding that can be requested by name, be sure to
- // add the corresponding item in EncodingTable.
- // Otherwise, the code below will throw exception when trying to call
- // EncodingTable.GetCodePageFromName().
- return EncodingProvider.GetEncodingFromProvider(name) ??
- GetEncoding(EncodingTable.GetCodePageFromName(name));
- }
-
- // Returns an Encoding object for a given name or a given code page value.
- //
- public static Encoding GetEncoding(string name,
- EncoderFallback encoderFallback, DecoderFallback decoderFallback)
- {
- // NOTE: If you add a new encoding that can be requested by name, be sure to
- // add the corresponding item in EncodingTable.
- // Otherwise, the code below will throw exception when trying to call
- // EncodingTable.GetCodePageFromName().
- return EncodingProvider.GetEncodingFromProvider(name, encoderFallback, decoderFallback) ??
- GetEncoding(EncodingTable.GetCodePageFromName(name), encoderFallback, decoderFallback);
- }
-
- // Return a list of all EncodingInfo objects describing all of our encodings
- public static EncodingInfo[] GetEncodings() => EncodingTable.GetEncodings();
-
- public virtual byte[] GetPreamble() => Array.Empty<byte>();
-
- public virtual ReadOnlySpan<byte> Preamble => GetPreamble();
-
- private void GetDataItem()
- {
- if (_dataItem == null)
- {
- _dataItem = EncodingTable.GetCodePageDataItem(_codePage);
- if (_dataItem == null)
- {
- throw new NotSupportedException(SR.Format(SR.NotSupported_NoCodepageData, _codePage));
- }
- }
- }
-
- // Returns the name for this encoding that can be used with mail agent body tags.
- // If the encoding may not be used, the string is empty.
-
- public virtual string BodyName
- {
- get
- {
- if (_dataItem == null)
- {
- GetDataItem();
- }
- return _dataItem!.BodyName;
- }
- }
-
- // Returns the human-readable description of the encoding ( e.g. Hebrew (DOS)).
- public virtual string EncodingName
- {
- get
- {
- if (_dataItem == null)
- {
- GetDataItem();
- }
-
- return _dataItem!.DisplayName;
- }
- }
-
- // Returns the name for this encoding that can be used with mail agent header
- // tags. If the encoding may not be used, the string is empty.
-
- public virtual string HeaderName
- {
- get
- {
- if (_dataItem == null)
- {
- GetDataItem();
- }
- return _dataItem!.HeaderName;
- }
- }
-
- // Returns the IANA preferred name for this encoding.
- public virtual string WebName
- {
- get
- {
- if (_dataItem == null)
- {
- GetDataItem();
- }
- return _dataItem!.WebName;
- }
- }
-
- // Returns the windows code page that most closely corresponds to this encoding.
-
- public virtual int WindowsCodePage
- {
- get
- {
- if (_dataItem == null)
- {
- GetDataItem();
- }
- return _dataItem!.UIFamilyCodePage;
- }
- }
-
- // True if and only if the encoding is used for display by browsers clients.
-
- public virtual bool IsBrowserDisplay
- {
- get
- {
- if (_dataItem == null)
- {
- GetDataItem();
- }
- return (_dataItem!.Flags & MIMECONTF_BROWSER) != 0;
- }
- }
-
- // True if and only if the encoding is used for saving by browsers clients.
-
- public virtual bool IsBrowserSave
- {
- get
- {
- if (_dataItem == null)
- {
- GetDataItem();
- }
- return (_dataItem!.Flags & MIMECONTF_SAVABLE_BROWSER) != 0;
- }
- }
-
- // True if and only if the encoding is used for display by mail and news clients.
-
- public virtual bool IsMailNewsDisplay
- {
- get
- {
- if (_dataItem == null)
- {
- GetDataItem();
- }
- return (_dataItem!.Flags & MIMECONTF_MAILNEWS) != 0;
- }
- }
-
- // True if and only if the encoding is used for saving documents by mail and
- // news clients
-
- public virtual bool IsMailNewsSave
- {
- get
- {
- if (_dataItem == null)
- {
- GetDataItem();
- }
- return (_dataItem!.Flags & MIMECONTF_SAVABLE_MAILNEWS) != 0;
- }
- }
-
- // True if and only if the encoding only uses single byte code points. (Ie, ASCII, 1252, etc)
-
- public virtual bool IsSingleByte => false;
-
- public EncoderFallback EncoderFallback
- {
- get => encoderFallback;
- set
- {
- if (this.IsReadOnly)
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
-
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- encoderFallback = value;
- }
- }
-
- public DecoderFallback DecoderFallback
- {
- get => decoderFallback;
- set
- {
- if (this.IsReadOnly)
- throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
-
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- decoderFallback = value;
- }
- }
-
- public virtual object Clone()
- {
- Encoding newEncoding = (Encoding)this.MemberwiseClone();
-
- // New one should be readable
- newEncoding._isReadOnly = false;
- return newEncoding;
- }
-
- public bool IsReadOnly
- {
- get => _isReadOnly;
- private protected set => _isReadOnly = value;
- }
-
- // Returns an encoding for the ASCII character set. The returned encoding
- // will be an instance of the ASCIIEncoding class.
-
- public static Encoding ASCII => ASCIIEncoding.s_default;
-
- // Returns an encoding for the Latin1 character set. The returned encoding
- // will be an instance of the Latin1Encoding class.
- //
- // This is for our optimizations
- private static Encoding Latin1 => Latin1Encoding.s_default;
-
- // Returns the number of bytes required to encode the given character
- // array.
- //
- public virtual int GetByteCount(char[] chars)
- {
- if (chars == null)
- {
- throw new ArgumentNullException(nameof(chars),
- SR.ArgumentNull_Array);
- }
-
- return GetByteCount(chars, 0, chars.Length);
- }
-
- public virtual int GetByteCount(string s)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
-
- char[] chars = s.ToCharArray();
- return GetByteCount(chars, 0, chars.Length);
- }
-
- // Returns the number of bytes required to encode a range of characters in
- // a character array.
- //
- public abstract int GetByteCount(char[] chars, int index, int count);
-
- // Returns the number of bytes required to encode a string range.
- //
- public int GetByteCount(string s, int index, int count)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s),
- SR.ArgumentNull_String);
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index),
- SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count),
- SR.ArgumentOutOfRange_NeedNonNegNum);
- if (index > s.Length - count)
- throw new ArgumentOutOfRangeException(nameof(index),
- SR.ArgumentOutOfRange_IndexCount);
-
- unsafe
- {
- fixed (char* pChar = s)
- {
- return GetByteCount(pChar + index, count);
- }
- }
- }
-
- // We expect this to be the workhorse for NLS encodings
- // unfortunately for existing overrides, it has to call the [] version,
- // which is really slow, so this method should be avoided if you're calling
- // a 3rd party encoding.
- [CLSCompliant(false)]
- public virtual unsafe int GetByteCount(char* chars, int count)
- {
- // Validate input parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars),
- SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- char[] arrChar = new ReadOnlySpan<char>(chars, count).ToArray();
-
- return GetByteCount(arrChar, 0, count);
- }
-
- public virtual unsafe int GetByteCount(ReadOnlySpan<char> chars)
- {
- fixed (char* charsPtr = &MemoryMarshal.GetNonNullPinnableReference(chars))
- {
- return GetByteCount(charsPtr, chars.Length);
- }
- }
-
- // Returns a byte array containing the encoded representation of the given
- // character array.
- //
- public virtual byte[] GetBytes(char[] chars)
- {
- if (chars == null)
- {
- throw new ArgumentNullException(nameof(chars),
- SR.ArgumentNull_Array);
- }
- return GetBytes(chars, 0, chars.Length);
- }
-
- // Returns a byte array containing the encoded representation of a range
- // of characters in a character array.
- //
- public virtual byte[] GetBytes(char[] chars, int index, int count)
- {
- byte[] result = new byte[GetByteCount(chars, index, count)];
- GetBytes(chars, index, count, result, 0);
- return result;
- }
-
- // Encodes a range of characters in a character array into a range of bytes
- // in a byte array. An exception occurs if the byte array is not large
- // enough to hold the complete encoding of the characters. The
- // GetByteCount method can be used to determine the exact number of
- // bytes that will be produced for a given range of characters.
- // Alternatively, the GetMaxByteCount method can be used to
- // determine the maximum number of bytes that will be produced for a given
- // number of characters, regardless of the actual character values.
- //
- public abstract int GetBytes(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex);
-
- // Returns a byte array containing the encoded representation of the given
- // string.
- //
- public virtual byte[] GetBytes(string s)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s),
- SR.ArgumentNull_String);
-
- int byteCount = GetByteCount(s);
- byte[] bytes = new byte[byteCount];
- int bytesReceived = GetBytes(s, 0, s.Length, bytes, 0);
- Debug.Assert(byteCount == bytesReceived);
- return bytes;
- }
-
- // Returns a byte array containing the encoded representation of the given
- // string range.
- //
- public byte[] GetBytes(string s, int index, int count)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s),
- SR.ArgumentNull_String);
- if (index < 0)
- throw new ArgumentOutOfRangeException(nameof(index),
- SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count),
- SR.ArgumentOutOfRange_NeedNonNegNum);
- if (index > s.Length - count)
- throw new ArgumentOutOfRangeException(nameof(index),
- SR.ArgumentOutOfRange_IndexCount);
-
- unsafe
- {
- fixed (char* pChar = s)
- {
- int byteCount = GetByteCount(pChar + index, count);
- if (byteCount == 0)
- return Array.Empty<byte>();
-
- byte[] bytes = new byte[byteCount];
- fixed (byte* pBytes = &bytes[0])
- {
- int bytesReceived = GetBytes(pChar + index, count, pBytes, byteCount);
- Debug.Assert(byteCount == bytesReceived);
- }
- return bytes;
- }
- }
- }
-
- public virtual int GetBytes(string s, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
- return GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
- }
-
- // We expect this to be the workhorse for NLS Encodings, but for existing
- // ones we need a working (if slow) default implementation)
- //
- // WARNING WARNING WARNING
- //
- // WARNING: If this breaks it could be a security threat. Obviously we
- // call this internally, so you need to make sure that your pointers, counts
- // and indexes are correct when you call this method.
- //
- // In addition, we have internal code, which will be marked as "safe" calling
- // this code. However this code is dependent upon the implementation of an
- // external GetBytes() method, which could be overridden by a third party and
- // the results of which cannot be guaranteed. We use that result to copy
- // the byte[] to our byte* output buffer. If the result count was wrong, we
- // could easily overflow our output buffer. Therefore we do an extra test
- // when we copy the buffer so that we don't overflow byteCount either.
-
- [CLSCompliant(false)]
- public virtual unsafe int GetBytes(char* chars, int charCount,
- byte* bytes, int byteCount)
- {
- // Validate input parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars),
- SR.ArgumentNull_Array);
-
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Get the char array to convert
- char[] arrChar = new ReadOnlySpan<char>(chars, charCount).ToArray();
-
- // Get the byte array to fill
- byte[] arrByte = new byte[byteCount];
-
- // Do the work
- int result = GetBytes(arrChar, 0, charCount, arrByte, 0);
-
- Debug.Assert(result <= byteCount, "[Encoding.GetBytes]Returned more bytes than we have space for");
-
- // Copy the byte array
- // WARNING: We MUST make sure that we don't copy too many bytes. We can't
- // rely on result because it could be a 3rd party implementation. We need
- // to make sure we never copy more than byteCount bytes no matter the value
- // of result
- if (result < byteCount)
- byteCount = result;
-
- // Copy the data, don't overrun our array!
- new ReadOnlySpan<byte>(arrByte, 0, byteCount).CopyTo(new Span<byte>(bytes, byteCount));
-
- return byteCount;
- }
-
- public virtual unsafe int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes)
- {
- fixed (char* charsPtr = &MemoryMarshal.GetNonNullPinnableReference(chars))
- fixed (byte* bytesPtr = &MemoryMarshal.GetNonNullPinnableReference(bytes))
- {
- return GetBytes(charsPtr, chars.Length, bytesPtr, bytes.Length);
- }
- }
-
- // Returns the number of characters produced by decoding the given byte
- // array.
- //
- public virtual int GetCharCount(byte[] bytes)
- {
- if (bytes == null)
- {
- throw new ArgumentNullException(nameof(bytes),
- SR.ArgumentNull_Array);
- }
- return GetCharCount(bytes, 0, bytes.Length);
- }
-
- // Returns the number of characters produced by decoding a range of bytes
- // in a byte array.
- //
- public abstract int GetCharCount(byte[] bytes, int index, int count);
-
- // We expect this to be the workhorse for NLS Encodings, but for existing
- // ones we need a working (if slow) default implementation)
- [CLSCompliant(false)]
- public virtual unsafe int GetCharCount(byte* bytes, int count)
- {
- // Validate input parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- byte[] arrByte = new ReadOnlySpan<byte>(bytes, count).ToArray();
-
- return GetCharCount(arrByte, 0, count);
- }
-
- public virtual unsafe int GetCharCount(ReadOnlySpan<byte> bytes)
- {
- fixed (byte* bytesPtr = &MemoryMarshal.GetNonNullPinnableReference(bytes))
- {
- return GetCharCount(bytesPtr, bytes.Length);
- }
- }
-
- // Returns a character array containing the decoded representation of a
- // given byte array.
- //
- public virtual char[] GetChars(byte[] bytes)
- {
- if (bytes == null)
- {
- throw new ArgumentNullException(nameof(bytes),
- SR.ArgumentNull_Array);
- }
- return GetChars(bytes, 0, bytes.Length);
- }
-
- // Returns a character array containing the decoded representation of a
- // range of bytes in a byte array.
- //
- public virtual char[] GetChars(byte[] bytes, int index, int count)
- {
- char[] result = new char[GetCharCount(bytes, index, count)];
- GetChars(bytes, index, count, result, 0);
- return result;
- }
-
- // Decodes a range of bytes in a byte array into a range of characters in a
- // character array. An exception occurs if the character array is not large
- // enough to hold the complete decoding of the bytes. The
- // GetCharCount method can be used to determine the exact number of
- // characters that will be produced for a given range of bytes.
- // Alternatively, the GetMaxCharCount method can be used to
- // determine the maximum number of characters that will be produced for a
- // given number of bytes, regardless of the actual byte values.
- //
-
- public abstract int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex);
-
- // We expect this to be the workhorse for NLS Encodings, but for existing
- // ones we need a working (if slow) default implementation)
- //
- // WARNING WARNING WARNING
- //
- // WARNING: If this breaks it could be a security threat. Obviously we
- // call this internally, so you need to make sure that your pointers, counts
- // and indexes are correct when you call this method.
- //
- // In addition, we have internal code, which will be marked as "safe" calling
- // this code. However this code is dependent upon the implementation of an
- // external GetChars() method, which could be overridden by a third party and
- // the results of which cannot be guaranteed. We use that result to copy
- // the char[] to our char* output buffer. If the result count was wrong, we
- // could easily overflow our output buffer. Therefore we do an extra test
- // when we copy the buffer so that we don't overflow charCount either.
-
- [CLSCompliant(false)]
- public virtual unsafe int GetChars(byte* bytes, int byteCount,
- char* chars, int charCount)
- {
- // Validate input parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes),
- SR.ArgumentNull_Array);
-
- if (byteCount < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(byteCount < 0 ? nameof(byteCount) : nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Get the byte array to convert
- byte[] arrByte = new ReadOnlySpan<byte>(bytes, byteCount).ToArray();
-
- // Get the char array to fill
- char[] arrChar = new char[charCount];
-
- // Do the work
- int result = GetChars(arrByte, 0, byteCount, arrChar, 0);
-
- Debug.Assert(result <= charCount, "[Encoding.GetChars]Returned more chars than we have space for");
-
- // Copy the char array
- // WARNING: We MUST make sure that we don't copy too many chars. We can't
- // rely on result because it could be a 3rd party implementation. We need
- // to make sure we never copy more than charCount chars no matter the value
- // of result
- if (result < charCount)
- charCount = result;
-
- // Copy the data, don't overrun our array!
- new ReadOnlySpan<char>(arrChar, 0, charCount).CopyTo(new Span<char>(chars, charCount));
-
- return charCount;
- }
-
- public virtual unsafe int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars)
- {
- fixed (byte* bytesPtr = &MemoryMarshal.GetNonNullPinnableReference(bytes))
- fixed (char* charsPtr = &MemoryMarshal.GetNonNullPinnableReference(chars))
- {
- return GetChars(bytesPtr, bytes.Length, charsPtr, chars.Length);
- }
- }
-
- [CLSCompliant(false)]
- public unsafe string GetString(byte* bytes, int byteCount)
- {
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (byteCount < 0)
- throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return string.CreateStringFromEncoding(bytes, byteCount, this);
- }
-
- public unsafe string GetString(ReadOnlySpan<byte> bytes)
- {
- fixed (byte* bytesPtr = &MemoryMarshal.GetNonNullPinnableReference(bytes))
- {
- return string.CreateStringFromEncoding(bytesPtr, bytes.Length, this);
- }
- }
-
- // Returns the code page identifier of this encoding. The returned value is
- // an integer between 0 and 65535 if the encoding has a code page
- // identifier, or -1 if the encoding does not represent a code page.
- //
-
- public virtual int CodePage => _codePage;
-
- // IsAlwaysNormalized
- // Returns true if the encoding is always normalized for the specified encoding form
- public bool IsAlwaysNormalized() =>
- IsAlwaysNormalized(NormalizationForm.FormC);
-
- public virtual bool IsAlwaysNormalized(NormalizationForm form) =>
- // Assume false unless the encoding knows otherwise
- false;
-
- // Returns a Decoder object for this encoding. The returned object
- // can be used to decode a sequence of bytes into a sequence of characters.
- // Contrary to the GetChars family of methods, a Decoder can
- // convert partial sequences of bytes into partial sequences of characters
- // by maintaining the appropriate state between the conversions.
- //
- // This default implementation returns a Decoder that simply
- // forwards calls to the GetCharCount and GetChars methods to
- // the corresponding methods of this encoding. Encodings that require state
- // to be maintained between successive conversions should override this
- // method and return an instance of an appropriate Decoder
- // implementation.
- //
-
- public virtual Decoder GetDecoder() => new DefaultDecoder(this);
-
- // Returns an Encoder object for this encoding. The returned object
- // can be used to encode a sequence of characters into a sequence of bytes.
- // Contrary to the GetBytes family of methods, an Encoder can
- // convert partial sequences of characters into partial sequences of bytes
- // by maintaining the appropriate state between the conversions.
- //
- // This default implementation returns an Encoder that simply
- // forwards calls to the GetByteCount and GetBytes methods to
- // the corresponding methods of this encoding. Encodings that require state
- // to be maintained between successive conversions should override this
- // method and return an instance of an appropriate Encoder
- // implementation.
- //
-
- public virtual Encoder GetEncoder() => new DefaultEncoder(this);
-
- // Returns the maximum number of bytes required to encode a given number of
- // characters. This method can be used to determine an appropriate buffer
- // size for byte arrays passed to the GetBytes method of this
- // encoding or the GetBytes method of an Encoder for this
- // encoding. All encodings must guarantee that no buffer overflow
- // exceptions will occur if buffers are sized according to the results of
- // this method.
- //
- // WARNING: If you're using something besides the default replacement encoder fallback,
- // then you could have more bytes than this returned from an actual call to GetBytes().
- //
- public abstract int GetMaxByteCount(int charCount);
-
- // Returns the maximum number of characters produced by decoding a given
- // number of bytes. This method can be used to determine an appropriate
- // buffer size for character arrays passed to the GetChars method of
- // this encoding or the GetChars method of a Decoder for this
- // encoding. All encodings must guarantee that no buffer overflow
- // exceptions will occur if buffers are sized according to the results of
- // this method.
- //
- public abstract int GetMaxCharCount(int byteCount);
-
- // Returns a string containing the decoded representation of a given byte
- // array.
- //
- public virtual string GetString(byte[] bytes)
- {
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes),
- SR.ArgumentNull_Array);
-
- return GetString(bytes, 0, bytes.Length);
- }
-
- // Returns a string containing the decoded representation of a range of
- // bytes in a byte array.
- //
- // Internally we override this for performance
- //
- public virtual string GetString(byte[] bytes, int index, int count) =>
- new string(GetChars(bytes, index, count));
-
- // Returns an encoding for Unicode format. The returned encoding will be
- // an instance of the UnicodeEncoding class.
- //
- // It will use little endian byte order, but will detect
- // input in big endian if it finds a byte order mark per Unicode 2.0.
-
- public static Encoding Unicode => UnicodeEncoding.s_littleEndianDefault;
-
- // Returns an encoding for Unicode format. The returned encoding will be
- // an instance of the UnicodeEncoding class.
- //
- // It will use big endian byte order, but will detect
- // input in little endian if it finds a byte order mark per Unicode 2.0.
-
- public static Encoding BigEndianUnicode => UnicodeEncoding.s_bigEndianDefault;
-
- // Returns an encoding for the UTF-7 format. The returned encoding will be
- // an instance of the UTF7Encoding class.
-
- public static Encoding UTF7 => UTF7Encoding.s_default;
-
- // Returns an encoding for the UTF-8 format. The returned encoding will be
- // an instance of the UTF8Encoding class.
-
- public static Encoding UTF8 => UTF8Encoding.s_default;
-
- // Returns an encoding for the UTF-32 format. The returned encoding will be
- // an instance of the UTF32Encoding class.
-
- public static Encoding UTF32 => UTF32Encoding.s_default;
-
- // Returns an encoding for the UTF-32 format. The returned encoding will be
- // an instance of the UTF32Encoding class.
- //
- // It will use big endian byte order.
-
- private static Encoding BigEndianUTF32 => UTF32Encoding.s_bigEndianDefault;
-
- public override bool Equals(object? value) =>
- value is Encoding that &&
- (_codePage == that._codePage) &&
- (EncoderFallback.Equals(that.EncoderFallback)) &&
- (DecoderFallback.Equals(that.DecoderFallback));
-
- public override int GetHashCode() =>
- _codePage + this.EncoderFallback.GetHashCode() + this.DecoderFallback.GetHashCode();
-
- internal virtual char[] GetBestFitUnicodeToBytesData() =>
- // Normally we don't have any best fit data.
- Array.Empty<char>();
-
- internal virtual char[] GetBestFitBytesToUnicodeData() =>
- // Normally we don't have any best fit data.
- Array.Empty<char>();
-
- [DoesNotReturn]
- internal void ThrowBytesOverflow() =>
- // Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implemented an encoder fallback with a broken GetMaxCharCount
- throw new ArgumentException(
- SR.Format(SR.Argument_EncodingConversionOverflowBytes, EncodingName, EncoderFallback.GetType()), "bytes");
-
- internal void ThrowBytesOverflow(EncoderNLS? encoder, bool nothingEncoded)
- {
- if (encoder == null || encoder._throwOnOverflow || nothingEncoded)
- {
- if (encoder != null && encoder.InternalHasFallbackBuffer)
- encoder.FallbackBuffer.InternalReset();
- // Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implemented an encoder fallback with a broken GetMaxCharCount
- ThrowBytesOverflow();
- }
-
- // If we didn't throw, we are in convert and have to remember our flushing
- encoder!.ClearMustFlush();
- }
-
- [DoesNotReturn]
- [StackTraceHidden]
- internal static void ThrowConversionOverflow() =>
- throw new ArgumentException(SR.Argument_ConversionOverflow);
-
- [DoesNotReturn]
- [StackTraceHidden]
- internal void ThrowCharsOverflow() =>
- // Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implemented a decoder fallback with a broken GetMaxCharCount
- throw new ArgumentException(
- SR.Format(SR.Argument_EncodingConversionOverflowChars, EncodingName, DecoderFallback.GetType()), "chars");
-
- internal void ThrowCharsOverflow(DecoderNLS? decoder, bool nothingDecoded)
- {
- if (decoder == null || decoder._throwOnOverflow || nothingDecoded)
- {
- if (decoder != null && decoder.InternalHasFallbackBuffer)
- decoder.FallbackBuffer.InternalReset();
-
- // Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implemented a decoder fallback with a broken GetMaxCharCount
- ThrowCharsOverflow();
- }
-
- // If we didn't throw, we are in convert and have to remember our flushing
- decoder!.ClearMustFlush();
- }
-
- internal sealed class DefaultEncoder : Encoder, IObjectReference
- {
- private readonly Encoding _encoding;
-
- public DefaultEncoder(Encoding encoding)
- {
- _encoding = encoding;
- }
-
- public object GetRealObject(StreamingContext context) =>
- throw new PlatformNotSupportedException();
-
- // Returns the number of bytes the next call to GetBytes will
- // produce if presented with the given range of characters and the given
- // value of the flush parameter. The returned value takes into
- // account the state in which the encoder was left following the last call
- // to GetBytes. The state of the encoder is not affected by a call
- // to this method.
- //
-
- public override int GetByteCount(char[] chars, int index, int count, bool flush) =>
- _encoding.GetByteCount(chars, index, count);
-
- public override unsafe int GetByteCount(char* chars, int count, bool flush) =>
- _encoding.GetByteCount(chars, count);
-
- // Encodes a range of characters in a character array into a range of bytes
- // in a byte array. The method encodes charCount characters from
- // chars starting at index charIndex, storing the resulting
- // bytes in bytes starting at index byteIndex. The encoding
- // takes into account the state in which the encoder was left following the
- // last call to this method. The flush parameter indicates whether
- // the encoder should flush any shift-states and partial characters at the
- // end of the conversion. To ensure correct termination of a sequence of
- // blocks of encoded bytes, the last call to GetBytes should specify
- // a value of true for the flush parameter.
- //
- // An exception occurs if the byte array is not large enough to hold the
- // complete encoding of the characters. The GetByteCount method can
- // be used to determine the exact number of bytes that will be produced for
- // a given range of characters. Alternatively, the GetMaxByteCount
- // method of the Encoding that produced this encoder can be used to
- // determine the maximum number of bytes that will be produced for a given
- // number of characters, regardless of the actual character values.
- //
-
- public override int GetBytes(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex, bool flush) =>
- _encoding.GetBytes(chars, charIndex, charCount, bytes, byteIndex);
-
- public override unsafe int GetBytes(char* chars, int charCount,
- byte* bytes, int byteCount, bool flush) =>
- _encoding.GetBytes(chars, charCount, bytes, byteCount);
- }
-
- internal sealed class DefaultDecoder : Decoder, IObjectReference
- {
- private readonly Encoding _encoding;
-
- public DefaultDecoder(Encoding encoding)
- {
- _encoding = encoding;
- }
-
- public object GetRealObject(StreamingContext context) =>
- throw new PlatformNotSupportedException();
-
- // Returns the number of characters the next call to GetChars will
- // produce if presented with the given range of bytes. The returned value
- // takes into account the state in which the decoder was left following the
- // last call to GetChars. The state of the decoder is not affected
- // by a call to this method.
- //
-
- public override int GetCharCount(byte[] bytes, int index, int count) =>
- GetCharCount(bytes, index, count, false);
-
- public override int GetCharCount(byte[] bytes, int index, int count, bool flush) =>
- _encoding.GetCharCount(bytes, index, count);
-
- public override unsafe int GetCharCount(byte* bytes, int count, bool flush) =>
- // By default just call the encoding version, no flush by default
- _encoding.GetCharCount(bytes, count);
-
- // Decodes a range of bytes in a byte array into a range of characters
- // in a character array. The method decodes byteCount bytes from
- // bytes starting at index byteIndex, storing the resulting
- // characters in chars starting at index charIndex. The
- // decoding takes into account the state in which the decoder was left
- // following the last call to this method.
- //
- // An exception occurs if the character array is not large enough to
- // hold the complete decoding of the bytes. The GetCharCount method
- // can be used to determine the exact number of characters that will be
- // produced for a given range of bytes. Alternatively, the
- // GetMaxCharCount method of the Encoding that produced this
- // decoder can be used to determine the maximum number of characters that
- // will be produced for a given number of bytes, regardless of the actual
- // byte values.
- //
-
- public override int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex) =>
- GetChars(bytes, byteIndex, byteCount, chars, charIndex, false);
-
- public override int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex, bool flush) =>
- _encoding.GetChars(bytes, byteIndex, byteCount, chars, charIndex);
-
- public override unsafe int GetChars(byte* bytes, int byteCount,
- char* chars, int charCount, bool flush) =>
- // By default just call the encoding's version
- _encoding.GetChars(bytes, byteCount, chars, charCount);
- }
-
- internal class EncodingCharBuffer
- {
- private unsafe char* _chars;
- private readonly unsafe char* _charStart;
- private readonly unsafe char* _charEnd;
- private int _charCountResult = 0;
- private readonly Encoding _enc;
- private readonly DecoderNLS? _decoder;
- private readonly unsafe byte* _byteStart;
- private readonly unsafe byte* _byteEnd;
- private unsafe byte* _bytes;
- private readonly DecoderFallbackBuffer _fallbackBuffer;
-
- internal unsafe EncodingCharBuffer(Encoding enc, DecoderNLS? decoder, char* charStart, int charCount,
- byte* byteStart, int byteCount)
- {
- _enc = enc;
- _decoder = decoder;
-
- _chars = charStart;
- _charStart = charStart;
- _charEnd = charStart + charCount;
-
- _byteStart = byteStart;
- _bytes = byteStart;
- _byteEnd = byteStart + byteCount;
-
- if (_decoder == null)
- _fallbackBuffer = enc.DecoderFallback.CreateFallbackBuffer();
- else
- _fallbackBuffer = _decoder.FallbackBuffer;
-
- // If we're getting chars or getting char count we don't expect to have
- // to remember fallbacks between calls (so it should be empty)
- Debug.Assert(_fallbackBuffer.Remaining == 0,
- "[Encoding.EncodingCharBuffer.EncodingCharBuffer]Expected empty fallback buffer for getchars/charcount");
- _fallbackBuffer.InternalInitialize(_bytes, _charEnd);
- }
-
- internal unsafe bool AddChar(char ch, int numBytes)
- {
- if (_chars != null)
- {
- if (_chars >= _charEnd)
- {
- // Throw maybe
- _bytes -= numBytes; // Didn't encode these bytes
- _enc.ThrowCharsOverflow(_decoder, _bytes <= _byteStart); // Throw?
- return false; // No throw, but no store either
- }
-
- *(_chars++) = ch;
- }
- _charCountResult++;
- return true;
- }
-
- internal bool AddChar(char ch) => AddChar(ch, 1);
-
- internal unsafe bool AddChar(char ch1, char ch2, int numBytes)
- {
- // Need room for 2 chars
- if (_chars >= _charEnd - 1)
- {
- // Throw maybe
- _bytes -= numBytes; // Didn't encode these bytes
- _enc.ThrowCharsOverflow(_decoder, _bytes <= _byteStart); // Throw?
- return false; // No throw, but no store either
- }
- return AddChar(ch1, numBytes) && AddChar(ch2, numBytes);
- }
-
- internal unsafe void AdjustBytes(int count)
- {
- _bytes += count;
- }
-
- internal unsafe bool MoreData => _bytes < _byteEnd;
-
- // Do we have count more bytes?
- internal unsafe bool EvenMoreData(int count) => _bytes <= _byteEnd - count;
-
- // GetNextByte shouldn't be called unless the caller's already checked more data or even more data,
- // but we'll double check just to make sure.
- internal unsafe byte GetNextByte()
- {
- Debug.Assert(_bytes < _byteEnd, "[EncodingCharBuffer.GetNextByte]Expected more date");
- if (_bytes >= _byteEnd)
- return 0;
- return *(_bytes++);
- }
-
- internal unsafe int BytesUsed => (int)(_bytes - _byteStart);
-
- internal bool Fallback(byte fallbackByte)
- {
- // Build our buffer
- byte[] byteBuffer = new byte[] { fallbackByte };
-
- // Do the fallback and add the data.
- return Fallback(byteBuffer);
- }
-
- internal bool Fallback(byte byte1, byte byte2)
- {
- // Build our buffer
- byte[] byteBuffer = new byte[] { byte1, byte2 };
-
- // Do the fallback and add the data.
- return Fallback(byteBuffer);
- }
-
- internal bool Fallback(byte byte1, byte byte2, byte byte3, byte byte4)
- {
- // Build our buffer
- byte[] byteBuffer = new byte[] { byte1, byte2, byte3, byte4 };
-
- // Do the fallback and add the data.
- return Fallback(byteBuffer);
- }
-
- internal unsafe bool Fallback(byte[] byteBuffer)
- {
- // Do the fallback and add the data.
- if (_chars != null)
- {
- char* pTemp = _chars;
- if (!_fallbackBuffer.InternalFallback(byteBuffer, _bytes, ref _chars))
- {
- // Throw maybe
- _bytes -= byteBuffer.Length; // Didn't use how many ever bytes we're falling back
- _fallbackBuffer.InternalReset(); // We didn't use this fallback.
- _enc.ThrowCharsOverflow(_decoder, _chars == _charStart); // Throw?
- return false; // No throw, but no store either
- }
- _charCountResult += unchecked((int)(_chars - pTemp));
- }
- else
- {
- _charCountResult += _fallbackBuffer.InternalFallback(byteBuffer, _bytes);
- }
-
- return true;
- }
-
- internal int Count => _charCountResult;
- }
-
- internal class EncodingByteBuffer
- {
- private unsafe byte* _bytes;
- private readonly unsafe byte* _byteStart;
- private readonly unsafe byte* _byteEnd;
- private unsafe char* _chars;
- private readonly unsafe char* _charStart;
- private readonly unsafe char* _charEnd;
- private int _byteCountResult = 0;
- private readonly Encoding _enc;
- private readonly EncoderNLS? _encoder;
- internal EncoderFallbackBuffer fallbackBuffer;
-
- internal unsafe EncodingByteBuffer(Encoding inEncoding, EncoderNLS? inEncoder,
- byte* inByteStart, int inByteCount, char* inCharStart, int inCharCount)
- {
- _enc = inEncoding;
- _encoder = inEncoder;
-
- _charStart = inCharStart;
- _chars = inCharStart;
- _charEnd = inCharStart + inCharCount;
-
- _bytes = inByteStart;
- _byteStart = inByteStart;
- _byteEnd = inByteStart + inByteCount;
-
- if (_encoder == null)
- this.fallbackBuffer = _enc.EncoderFallback.CreateFallbackBuffer();
- else
- {
- this.fallbackBuffer = _encoder.FallbackBuffer;
- // If we're not converting we must not have data in our fallback buffer
- if (_encoder._throwOnOverflow && _encoder.InternalHasFallbackBuffer &&
- this.fallbackBuffer.Remaining > 0)
- throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty,
- _encoder.Encoding.EncodingName, _encoder.Fallback!.GetType()));
- }
- fallbackBuffer.InternalInitialize(_chars, _charEnd, _encoder, _bytes != null);
- }
-
- internal unsafe bool AddByte(byte b, int moreBytesExpected)
- {
- Debug.Assert(moreBytesExpected >= 0, "[EncodingByteBuffer.AddByte]expected non-negative moreBytesExpected");
- if (_bytes != null)
- {
- if (_bytes >= _byteEnd - moreBytesExpected)
- {
- // Throw maybe. Check which buffer to back up (only matters if Converting)
- this.MovePrevious(true); // Throw if necessary
- return false; // No throw, but no store either
- }
-
- *(_bytes++) = b;
- }
- _byteCountResult++;
- return true;
- }
-
- internal bool AddByte(byte b1) => AddByte(b1, 0);
-
- internal bool AddByte(byte b1, byte b2) => AddByte(b1, b2, 0);
-
- internal bool AddByte(byte b1, byte b2, int moreBytesExpected) =>
- AddByte(b1, 1 + moreBytesExpected) && AddByte(b2, moreBytesExpected);
-
- internal bool AddByte(byte b1, byte b2, byte b3) =>
- AddByte(b1, b2, b3, (int)0);
-
- internal bool AddByte(byte b1, byte b2, byte b3, int moreBytesExpected) =>
- AddByte(b1, 2 + moreBytesExpected) &&
- AddByte(b2, 1 + moreBytesExpected) &&
- AddByte(b3, moreBytesExpected);
-
- internal bool AddByte(byte b1, byte b2, byte b3, byte b4) => AddByte(b1, 3) &&
- AddByte(b2, 2) &&
- AddByte(b3, 1) &&
- AddByte(b4, 0);
-
- internal unsafe void MovePrevious(bool bThrow)
- {
- if (fallbackBuffer.bFallingBack)
- fallbackBuffer.MovePrevious(); // don't use last fallback
- else
- {
- Debug.Assert(_chars > _charStart ||
- (bThrow && (_bytes == _byteStart)),
- "[EncodingByteBuffer.MovePrevious]expected previous data or throw");
- if (_chars > _charStart)
- _chars--; // don't use last char
- }
-
- if (bThrow)
- _enc.ThrowBytesOverflow(_encoder, _bytes == _byteStart); // Throw? (and reset fallback if not converting)
- }
-
- internal unsafe bool Fallback(char charFallback)
- {
- // Do the fallback
- return fallbackBuffer.InternalFallback(charFallback, ref _chars);
- }
-
- internal unsafe bool MoreData =>
- // See if fallbackBuffer is not empty or if there's data left in chars buffer.
- (fallbackBuffer.Remaining > 0) || (_chars < _charEnd);
-
- internal unsafe char GetNextChar()
- {
- // See if there's something in our fallback buffer
- char cReturn = fallbackBuffer.InternalGetNextChar();
-
- // Nothing in the fallback buffer, return our normal data.
- if (cReturn == 0)
- {
- if (_chars < _charEnd)
- cReturn = *(_chars++);
- }
-
- return cReturn;
- }
-
- internal unsafe int CharsUsed => (int)(_chars - _charStart);
-
- internal int Count => _byteCountResult;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncodingData.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncodingData.cs
deleted file mode 100644
index 7b2daeaadf9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/EncodingData.cs
+++ /dev/null
@@ -1,296 +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.
-//
-// THIS IS AUTOGENERATED FILE CREATED BY
-// https://github.com/dotnet/buildtools/blob/6736870b84e06b75e7df32bb84d442db1b2afa10/src/Microsoft.DotNet.Build.Tasks/PackageFiles/encoding.targets
-//
-
-namespace System.Text
-{
- internal static partial class EncodingTable
- {
- //
- // s_encodingNames is the concatenation of all supported IANA names for each codepage.
- // This is done rather than using a large readonly array of strings to avoid
- // generating a large amount of code in the static constructor.
- // Using indices from s_encodingNamesIndices, we binary search this string when mapping
- // an encoding name to a codepage. Note that these names are all lowercase and are
- // sorted alphabetically.
- //
- private const string s_encodingNames =
- "ansi_x3.4-1968" + // 20127
- "ansi_x3.4-1986" + // 20127
- "ascii" + // 20127
- "cp367" + // 20127
- "cp819" + // 28591
- "csascii" + // 20127
- "csisolatin1" + // 28591
- "csunicode11utf7" + // 65000
- "ibm367" + // 20127
- "ibm819" + // 28591
- "iso-10646-ucs-2" + // 1200
- "iso-8859-1" + // 28591
- "iso-ir-100" + // 28591
- "iso-ir-6" + // 20127
- "iso646-us" + // 20127
- "iso8859-1" + // 28591
- "iso_646.irv:1991" + // 20127
- "iso_8859-1" + // 28591
- "iso_8859-1:1987" + // 28591
- "l1" + // 28591
- "latin1" + // 28591
- "ucs-2" + // 1200
- "unicode" + // 1200
- "unicode-1-1-utf-7" + // 65000
- "unicode-1-1-utf-8" + // 65001
- "unicode-2-0-utf-7" + // 65000
- "unicode-2-0-utf-8" + // 65001
- "unicodefffe" + // 1201
- "us" + // 20127
- "us-ascii" + // 20127
- "utf-16" + // 1200
- "utf-16be" + // 1201
- "utf-16le" + // 1200
- "utf-32" + // 12000
- "utf-32be" + // 12001
- "utf-32le" + // 12000
- "utf-7" + // 65000
- "utf-8" + // 65001
- "x-unicode-1-1-utf-7" + // 65000
- "x-unicode-1-1-utf-8" + // 65001
- "x-unicode-2-0-utf-7" + // 65000
- "x-unicode-2-0-utf-8"; // 65001
-
- //
- // s_encodingNameIndices contains the start index of every encoding name in the string
- // s_encodingNames. We infer the length of each string by looking at the start index
- // of the next string.
- //
- private static readonly int[] s_encodingNameIndices = new int[]
- {
- 0, // ansi_x3.4-1968 (20127)
- 14, // ansi_x3.4-1986 (20127)
- 28, // ascii (20127)
- 33, // cp367 (20127)
- 38, // cp819 (28591)
- 43, // csascii (20127)
- 50, // csisolatin1 (28591)
- 61, // csunicode11utf7 (65000)
- 76, // ibm367 (20127)
- 82, // ibm819 (28591)
- 88, // iso-10646-ucs-2 (1200)
- 103, // iso-8859-1 (28591)
- 113, // iso-ir-100 (28591)
- 123, // iso-ir-6 (20127)
- 131, // iso646-us (20127)
- 140, // iso8859-1 (28591)
- 149, // iso_646.irv:1991 (20127)
- 165, // iso_8859-1 (28591)
- 175, // iso_8859-1:1987 (28591)
- 190, // l1 (28591)
- 192, // latin1 (28591)
- 198, // ucs-2 (1200)
- 203, // unicode (1200)
- 210, // unicode-1-1-utf-7 (65000)
- 227, // unicode-1-1-utf-8 (65001)
- 244, // unicode-2-0-utf-7 (65000)
- 261, // unicode-2-0-utf-8 (65001)
- 278, // unicodefffe (1201)
- 289, // us (20127)
- 291, // us-ascii (20127)
- 299, // utf-16 (1200)
- 305, // utf-16be (1201)
- 313, // utf-16le (1200)
- 321, // utf-32 (12000)
- 327, // utf-32be (12001)
- 335, // utf-32le (12000)
- 343, // utf-7 (65000)
- 348, // utf-8 (65001)
- 353, // x-unicode-1-1-utf-7 (65000)
- 372, // x-unicode-1-1-utf-8 (65001)
- 391, // x-unicode-2-0-utf-7 (65000)
- 410, // x-unicode-2-0-utf-8 (65001)
- 429
- };
-
- //
- // s_codePagesByName contains the list of supported codepages which match the encoding
- // names listed in s_encodingNames. The way mapping works is we binary search
- // s_encodingNames using s_encodingNamesIndices until we find a match for a given name.
- // The index of the entry in s_encodingNamesIndices will be the index of codepage in
- // s_codePagesByName.
- //
- private static readonly ushort[] s_codePagesByName = new ushort[]
- {
- 20127, // ansi_x3.4-1968
- 20127, // ansi_x3.4-1986
- 20127, // ascii
- 20127, // cp367
- 28591, // cp819
- 20127, // csascii
- 28591, // csisolatin1
- 65000, // csunicode11utf7
- 20127, // ibm367
- 28591, // ibm819
- 1200, // iso-10646-ucs-2
- 28591, // iso-8859-1
- 28591, // iso-ir-100
- 20127, // iso-ir-6
- 20127, // iso646-us
- 28591, // iso8859-1
- 20127, // iso_646.irv:1991
- 28591, // iso_8859-1
- 28591, // iso_8859-1:1987
- 28591, // l1
- 28591, // latin1
- 1200, // ucs-2
- 1200, // unicode
- 65000, // unicode-1-1-utf-7
- 65001, // unicode-1-1-utf-8
- 65000, // unicode-2-0-utf-7
- 65001, // unicode-2-0-utf-8
- 1201, // unicodefffe
- 20127, // us
- 20127, // us-ascii
- 1200, // utf-16
- 1201, // utf-16be
- 1200, // utf-16le
- 12000, // utf-32
- 12001, // utf-32be
- 12000, // utf-32le
- 65000, // utf-7
- 65001, // utf-8
- 65000, // x-unicode-1-1-utf-7
- 65001, // x-unicode-1-1-utf-8
- 65000, // x-unicode-2-0-utf-7
- 65001 // x-unicode-2-0-utf-8
- };
-
- //
- // When retrieving the value for System.Text.Encoding.WebName or
- // System.Text.Encoding.EncodingName given System.Text.Encoding.CodePage,
- // we perform a linear search on s_mappedCodePages to find the index of the
- // given codepage. This is used to index WebNameIndices to get the start
- // index of the web name in the string WebNames, and to index
- // s_englishNameIndices to get the start of the English name in
- // s_englishNames. In addition, this arrays indices correspond to the indices
- // into s_uiFamilyCodePages and s_flags.
- //
- private static readonly ushort[] s_mappedCodePages = new ushort[]
- {
- 1200, // utf-16
- 1201, // utf-16be
- 12000, // utf-32
- 12001, // utf-32be
- 20127, // us-ascii
- 28591, // iso-8859-1
- 65000, // utf-7
- 65001 // utf-8
- };
-
- //
- // s_uiFamilyCodePages is indexed by the corresponding index in s_mappedCodePages.
- //
- private static readonly int[] s_uiFamilyCodePages = new int[]
- {
- 1200,
- 1200,
- 1200,
- 1200,
- 1252,
- 1252,
- 1200,
- 1200
- };
-
- //
- // s_webNames is a concatenation of the default encoding names
- // for each code page. It is used in retrieving the value for
- // System.Text.Encoding.WebName given System.Text.Encoding.CodePage.
- // This is done rather than using a large readonly array of strings to avoid
- // generating a large amount of code in the static constructor.
- //
- private const string s_webNames =
- "utf-16" + // 1200
- "utf-16BE" + // 1201
- "utf-32" + // 12000
- "utf-32BE" + // 12001
- "us-ascii" + // 20127
- "iso-8859-1" + // 28591
- "utf-7" + // 65000
- "utf-8"; // 65001
-
- //
- // s_webNameIndices contains the start index of each code page's default
- // web name in the string s_webNames. It is indexed by an index into
- // s_mappedCodePages.
- //
- private static readonly int[] s_webNameIndices = new int[]
- {
- 0, // utf-16 (1200)
- 6, // utf-16be (1201)
- 14, // utf-32 (12000)
- 20, // utf-32be (12001)
- 28, // us-ascii (20127)
- 36, // iso-8859-1 (28591)
- 46, // utf-7 (65000)
- 51, // utf-8 (65001)
- 56
- };
-
- //
- // s_englishNames is the concatenation of the English names for each codepage.
- // It is used in retrieving the value for System.Text.Encoding.EncodingName
- // given System.Text.Encoding.CodePage.
- // This is done rather than using a large readonly array of strings to avoid
- // generating a large amount of code in the static constructor.
- //
- private const string s_englishNames =
- "Unicode" + // 1200
- "Unicode (Big-Endian)" + // 1201
- "Unicode (UTF-32)" + // 12000
- "Unicode (UTF-32 Big-Endian)" + // 12001
- "US-ASCII" + // 20127
- "Western European (ISO)" + // 28591
- "Unicode (UTF-7)" + // 65000
- "Unicode (UTF-8)"; // 65001
-
- //
- // s_englishNameIndices contains the start index of each code page's English
- // name in the string s_englishNames. It is indexed by an index into
- // s_mappedCodePages.
- //
- private static readonly int[] s_englishNameIndices = new int[]
- {
- 0, // Unicode (1200)
- 7, // Unicode (Big-Endian) (1201)
- 27, // Unicode (UTF-32) (12000)
- 43, // Unicode (UTF-32 Big-Endian) (12001)
- 70, // US-ASCII (20127)
- 78, // Western European (ISO) (28591)
- 100, // Unicode (UTF-7) (65000)
- 115, // Unicode (UTF-8) (65001)
- 130
- };
-
- // redeclaring these constants here for readability below
- private const uint MIMECONTF_MAILNEWS = Encoding.MIMECONTF_MAILNEWS;
- private const uint MIMECONTF_BROWSER = Encoding.MIMECONTF_BROWSER;
- private const uint MIMECONTF_SAVABLE_MAILNEWS = Encoding.MIMECONTF_SAVABLE_MAILNEWS;
- private const uint MIMECONTF_SAVABLE_BROWSER = Encoding.MIMECONTF_SAVABLE_BROWSER;
-
- // s_flags is indexed by the corresponding index in s_mappedCodePages.
- private static readonly uint[] s_flags = new uint[]
- {
- MIMECONTF_SAVABLE_BROWSER,
- 0,
- 0,
- 0,
- MIMECONTF_MAILNEWS | MIMECONTF_SAVABLE_MAILNEWS,
- MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER,
- MIMECONTF_MAILNEWS | MIMECONTF_SAVABLE_MAILNEWS,
- MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER
- };
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncodingInfo.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncodingInfo.cs
deleted file mode 100644
index febecfa6651..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/EncodingInfo.cs
+++ /dev/null
@@ -1,39 +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.
-
-namespace System.Text
-{
- public sealed class EncodingInfo
- {
- internal EncodingInfo(int codePage, string name, string displayName)
- {
- CodePage = codePage;
- Name = name;
- DisplayName = displayName;
- }
-
- public int CodePage { get; }
- public string Name { get; }
- public string DisplayName { get; }
-
- public Encoding GetEncoding()
- {
- return Encoding.GetEncoding(CodePage);
- }
-
- public override bool Equals(object? value)
- {
- if (value is EncodingInfo that)
- {
- return this.CodePage == that.CodePage;
- }
- return false;
- }
-
- public override int GetHashCode()
- {
- return CodePage;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncodingNLS.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncodingNLS.cs
deleted file mode 100644
index d292a2d5874..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/EncodingNLS.cs
+++ /dev/null
@@ -1,296 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Text
-{
- // This class overrides Encoding with the things we need for our NLS Encodings
- //
- // All of the GetBytes/Chars GetByte/CharCount methods are just wrappers for the pointer
- // plus decoder/encoder method that is our real workhorse. Note that this is an internal
- // class, so our public classes cannot derive from this class. Because of this, all of the
- // GetBytes/Chars GetByte/CharCount wrapper methods are duplicated in all of our public
- // encodings, which currently include:
- //
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, & UnicodeEncoding
- //
- // So if you change the wrappers in this class, you must change the wrappers in the other classes
- // as well because they should have the same behavior.
-
- internal abstract class EncodingNLS : Encoding
- {
- protected EncodingNLS(int codePage) : base(codePage)
- {
- Debug.Assert(GetType() == typeof(Latin1Encoding), "Should be no instantiations of this type except via Latin1Encoding.");
- }
-
- // Returns the number of bytes required to encode a range of characters in
- // a character array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
- public override unsafe int GetByteCount(char[] chars, int index, int count)
- {
- // Validate input parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // If no input, return 0, avoid fixed empty array problem
- if (count == 0)
- return 0;
-
- // Just call the pointer version
- fixed (char* pChars = chars)
- return GetByteCount(pChars + index, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
- public override unsafe int GetByteCount(string s)
- {
- // Validate input
- if (s == null)
- throw new ArgumentNullException(nameof(s));
-
- fixed (char* pChars = s)
- return GetByteCount(pChars, s.Length, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- public override unsafe int GetByteCount(char* chars, int count)
- {
- // Validate Parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars), SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Call it with empty encoder
- return GetByteCount(chars, count, null);
- }
-
- // Parent method is safe.
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- public override unsafe int GetBytes(string s, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- if (s == null || bytes == null)
- throw new ArgumentNullException(s == null ? nameof(s) : nameof(bytes), SR.ArgumentNull_Array);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (s.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(s), SR.ArgumentOutOfRange_IndexCount);
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index);
-
- int byteCount = bytes.Length - byteIndex;
-
- fixed (char* pChars = s) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
- }
-
- // Encodes a range of characters in a character array into a range of bytes
- // in a byte array. An exception occurs if the byte array is not large
- // enough to hold the complete encoding of the characters. The
- // GetByteCount method can be used to determine the exact number of
- // bytes that will be produced for a given range of characters.
- // Alternatively, the GetMaxByteCount method can be used to
- // determine the maximum number of bytes that will be produced for a given
- // number of characters, regardless of the actual character values.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes), SR.ArgumentNull_Array);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index);
-
- // If nothing to encode return 0, avoid fixed problem
- if (charCount == 0)
- return 0;
-
- // Just call pointer version
- int byteCount = bytes.Length - byteIndex;
-
- fixed (char* pChars = chars) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- // Remember that byteCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetBytes(chars, charCount, bytes, byteCount, null);
- }
-
- // Returns the number of characters produced by decoding a range of bytes
- // in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
- public override unsafe int GetCharCount(byte[] bytes, int index, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // If no input just return 0, fixed doesn't like 0 length arrays
- if (count == 0)
- return 0;
-
- // Just call pointer version
- fixed (byte* pBytes = bytes)
- return GetCharCount(pBytes + index, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- public override unsafe int GetCharCount(byte* bytes, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetCharCount(bytes, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
- public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (byteIndex < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(byteIndex < 0 ? nameof(byteIndex) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - byteIndex < byteCount)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (charIndex < 0 || charIndex > chars.Length)
- throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_Index);
-
- // If no input, return 0 & avoid fixed problem
- if (byteCount == 0)
- return 0;
-
- // Just call pointer version
- int charCount = chars.Length - charIndex;
-
- fixed (byte* pBytes = bytes) fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
- // Remember that charCount is # to decode, not size of array
- return GetChars(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- public override unsafe int GetChars(byte* bytes, int byteCount, char* chars, int charCount)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetChars(bytes, byteCount, chars, charCount, null);
- }
-
- // Returns a string containing the decoded representation of a range of
- // bytes in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
- public override unsafe string GetString(byte[] bytes, int index, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // Avoid problems with empty input buffer
- if (count == 0) return string.Empty;
-
- fixed (byte* pBytes = bytes)
- return string.CreateStringFromEncoding(
- pBytes + index, count, this);
- }
-
- public override Decoder GetDecoder()
- {
- return new DecoderNLS(this);
- }
-
- public override Encoder GetEncoder()
- {
- return new EncoderNLS(this);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncodingProvider.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncodingProvider.cs
deleted file mode 100644
index ac7fc541f60..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/EncodingProvider.cs
+++ /dev/null
@@ -1,132 +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.
-
-namespace System.Text
-{
- public abstract class EncodingProvider
- {
- public EncodingProvider() { }
- public abstract Encoding? GetEncoding(string name);
- public abstract Encoding? GetEncoding(int codepage);
-
- // GetEncoding should return either valid encoding or null. shouldn't throw any exception except on null name
- public virtual Encoding? GetEncoding(string name, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
- {
- Encoding? enc = GetEncoding(name);
- if (enc != null)
- {
- enc = (Encoding)enc.Clone();
- enc.EncoderFallback = encoderFallback;
- enc.DecoderFallback = decoderFallback;
- }
-
- return enc;
- }
-
- public virtual Encoding? GetEncoding(int codepage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
- {
- Encoding? enc = GetEncoding(codepage);
- if (enc != null)
- {
- enc = (Encoding)enc.Clone();
- enc.EncoderFallback = encoderFallback;
- enc.DecoderFallback = decoderFallback;
- }
-
- return enc;
- }
-
- internal static void AddProvider(EncodingProvider provider)
- {
- if (provider == null)
- throw new ArgumentNullException(nameof(provider));
-
- lock (s_InternalSyncObject)
- {
- if (s_providers == null)
- {
- s_providers = new EncodingProvider[1] { provider };
- return;
- }
-
- if (Array.IndexOf(s_providers, provider) >= 0)
- {
- return;
- }
-
- EncodingProvider[] providers = new EncodingProvider[s_providers.Length + 1];
- Array.Copy(s_providers, providers, s_providers.Length);
- providers[^1] = provider;
- s_providers = providers;
- }
- }
-
- internal static Encoding? GetEncodingFromProvider(int codepage)
- {
- if (s_providers == null)
- return null;
-
- EncodingProvider[] providers = s_providers;
- foreach (EncodingProvider provider in providers)
- {
- Encoding? enc = provider.GetEncoding(codepage);
- if (enc != null)
- return enc;
- }
-
- return null;
- }
-
- internal static Encoding? GetEncodingFromProvider(string encodingName)
- {
- if (s_providers == null)
- return null;
-
- EncodingProvider[] providers = s_providers;
- foreach (EncodingProvider provider in providers)
- {
- Encoding? enc = provider.GetEncoding(encodingName);
- if (enc != null)
- return enc;
- }
-
- return null;
- }
-
- internal static Encoding? GetEncodingFromProvider(int codepage, EncoderFallback enc, DecoderFallback dec)
- {
- if (s_providers == null)
- return null;
-
- EncodingProvider[] providers = s_providers;
- foreach (EncodingProvider provider in providers)
- {
- Encoding? encoding = provider.GetEncoding(codepage, enc, dec);
- if (encoding != null)
- return encoding;
- }
-
- return null;
- }
-
- internal static Encoding? GetEncodingFromProvider(string encodingName, EncoderFallback enc, DecoderFallback dec)
- {
- if (s_providers == null)
- return null;
-
- EncodingProvider[] providers = s_providers;
- foreach (EncodingProvider provider in providers)
- {
- Encoding? encoding = provider.GetEncoding(encodingName, enc, dec);
- if (encoding != null)
- return encoding;
- }
-
- return null;
- }
-
- private static readonly object s_InternalSyncObject = new object();
- private static volatile EncodingProvider[]? s_providers;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncodingTable.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncodingTable.cs
deleted file mode 100644
index cc69f793d6e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/EncodingTable.cs
+++ /dev/null
@@ -1,193 +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 System.Collections;
-using System.Diagnostics;
-using System.Threading;
-
-namespace System.Text
-{
- //
- // Data table for encoding classes. Used by System.Text.Encoding.
- // This class contains two hashtables to allow System.Text.Encoding
- // to retrieve the data item either by codepage value or by webName.
- //
- internal static partial class EncodingTable
- {
- private static readonly Hashtable s_nameToCodePage = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase));
- private static CodePageDataItem?[]? s_codePageToCodePageData;
-
- /*=================================GetCodePageFromName==========================
- **Action: Given a encoding name, return the correct code page number for this encoding.
- **Returns: The code page for the encoding.
- **Arguments:
- ** name the name of the encoding
- **Exceptions:
- ** ArgumentNullException if name is null.
- ** internalGetCodePageFromName will throw ArgumentException if name is not a valid encoding name.
- ============================================================================*/
-
- internal static int GetCodePageFromName(string name)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- object? codePageObj = s_nameToCodePage[name];
-
- if (codePageObj != null)
- {
- return (int)codePageObj;
- }
-
- int codePage = InternalGetCodePageFromName(name);
-
- s_nameToCodePage[name] = codePage;
-
- return codePage;
- }
-
- // Find the data item by binary searching the table.
- private static int InternalGetCodePageFromName(string name)
- {
- int left = 0;
- int right = s_encodingNameIndices.Length - 2;
- int index;
- int result;
-
- Debug.Assert(s_encodingNameIndices.Length == s_codePagesByName.Length + 1);
- Debug.Assert(s_encodingNameIndices[^1] == s_encodingNames.Length);
-
- ReadOnlySpan<char> invariantName = name.ToLowerInvariant().AsSpan();
-
- // Binary search the array until we have only a couple of elements left and then
- // just walk those elements.
- while ((right - left) > 3)
- {
- index = ((right - left) / 2) + left;
-
- Debug.Assert(index < s_encodingNameIndices.Length - 1);
- result = string.CompareOrdinal(invariantName, s_encodingNames.AsSpan(s_encodingNameIndices[index], s_encodingNameIndices[index + 1] - s_encodingNameIndices[index]));
-
- if (result == 0)
- {
- // We found the item, return the associated codePage.
- return s_codePagesByName[index];
- }
- else if (result < 0)
- {
- // The name that we're looking for is less than our current index.
- right = index;
- }
- else
- {
- // The name that we're looking for is greater than our current index
- left = index;
- }
- }
-
- // Walk the remaining elements (it'll be 3 or fewer).
- for (; left <= right; left++)
- {
- Debug.Assert(left < s_encodingNameIndices.Length - 1);
- if (string.CompareOrdinal(invariantName, s_encodingNames.AsSpan(s_encodingNameIndices[left], s_encodingNameIndices[left + 1] - s_encodingNameIndices[left])) == 0)
- {
- return s_codePagesByName[left];
- }
- }
-
- // The encoding name is not valid.
- throw new ArgumentException(
- SR.Format(SR.Argument_EncodingNotSupported, name),
- nameof(name));
- }
-
- // Return a list of all EncodingInfo objects describing all of our encodings
- internal static EncodingInfo[] GetEncodings()
- {
- EncodingInfo[] arrayEncodingInfo = new EncodingInfo[s_mappedCodePages.Length];
-
- for (int i = 0; i < s_mappedCodePages.Length; i++)
- {
- arrayEncodingInfo[i] = new EncodingInfo(
- s_mappedCodePages[i],
- s_webNames[s_webNameIndices[i]..s_webNameIndices[i + 1]],
- GetDisplayName(s_mappedCodePages[i], i)
- );
- }
-
- return arrayEncodingInfo;
- }
-
- internal static CodePageDataItem? GetCodePageDataItem(int codePage)
- {
- if (s_codePageToCodePageData == null)
- {
- Interlocked.CompareExchange<CodePageDataItem?[]?>(ref s_codePageToCodePageData, new CodePageDataItem[s_mappedCodePages.Length], null);
- }
-
- // Keep in sync with s_mappedCodePages
- int index;
- switch (codePage)
- {
- case 1200: // utf-16
- index = 0;
- break;
- case 1201: // utf-16be
- index = 1;
- break;
- case 12000: // utf-32
- index = 2;
- break;
- case 12001: // utf-32be
- index = 3;
- break;
- case 20127: // us-ascii
- index = 4;
- break;
- case 28591: // iso-8859-1
- index = 5;
- break;
- case 65000: // utf-7
- index = 6;
- break;
- case 65001: // utf-8
- index = 7;
- break;
- default:
- return null;
- }
-
- CodePageDataItem? data = s_codePageToCodePageData[index];
- if (data == null)
- {
- Interlocked.CompareExchange<CodePageDataItem?>(ref s_codePageToCodePageData[index], InternalGetCodePageDataItem(codePage, index), null);
- data = s_codePageToCodePageData[index];
- }
-
- return data;
- }
-
- private static CodePageDataItem InternalGetCodePageDataItem(int codePage, int index)
- {
- int uiFamilyCodePage = s_uiFamilyCodePages[index];
- string webName = s_webNames[s_webNameIndices[index]..s_webNameIndices[index + 1]];
- // All supported code pages have identical header names, and body names.
- string headerName = webName;
- string bodyName = webName;
- string displayName = GetDisplayName(codePage, index);
- uint flags = s_flags[index];
-
- return new CodePageDataItem(uiFamilyCodePage, webName, headerName, bodyName, displayName, flags);
- }
-
- private static string GetDisplayName(int codePage, int englishNameIndex)
- {
- string? displayName = SR.GetResourceString("Globalization_cp_" + codePage.ToString());
- if (string.IsNullOrEmpty(displayName))
- displayName = s_englishNames[s_englishNameIndices[englishNameIndex]..s_englishNameIndices[englishNameIndex + 1]];
-
- return displayName;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Latin1Encoding.cs b/netcore/System.Private.CoreLib/shared/System/Text/Latin1Encoding.cs
deleted file mode 100644
index 327718ccb44..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Latin1Encoding.cs
+++ /dev/null
@@ -1,877 +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 System.Diagnostics;
-
-namespace System.Text
-{
- //
- // Latin1Encoding is a simple override to optimize the GetString version of Latin1Encoding.
- // because of the best fit cases we can't do this when encoding the string, only when decoding
- //
- internal sealed class Latin1Encoding : EncodingNLS
- {
- // Used by Encoding.Latin1 for lazy initialization
- // The initialization code will not be run until a static member of the class is referenced
- internal static readonly Latin1Encoding s_default = new Latin1Encoding();
-
- // We only use the best-fit table, of which ASCII is a superset for us.
- public Latin1Encoding() : base(Encoding.ISO_8859_1)
- {
- }
-
- // GetByteCount
- // Note: We start by assuming that the output will be the same as count. Having
- // an encoder or fallback may change that assumption
- internal override unsafe int GetByteCount(char* chars, int charCount, EncoderNLS? encoder)
- {
- // Just need to ASSERT, this is called by something else internal that checked parameters already
- Debug.Assert(charCount >= 0, "[Latin1Encoding.GetByteCount]count is negative");
- Debug.Assert(chars != null, "[Latin1Encoding.GetByteCount]chars is null");
-
- // Assert because we shouldn't be able to have a null encoder.
- Debug.Assert(encoderFallback != null, "[Latin1Encoding.GetByteCount]Attempting to use null fallback encoder");
-
- char charLeftOver = (char)0;
-
- // If we have an encoder AND we aren't using default fallback,
- // then we may have a complicated count.
- EncoderReplacementFallback? fallback;
- if (encoder != null)
- {
- charLeftOver = encoder._charLeftOver;
- Debug.Assert(charLeftOver == 0 || char.IsHighSurrogate(charLeftOver),
- "[Latin1Encoding.GetByteCount]leftover character should be high surrogate");
-
- fallback = encoder.Fallback as EncoderReplacementFallback;
-
- // Verify that we have no fallbackbuffer, for Latin1 its always empty, so just assert
- Debug.Assert(!encoder._throwOnOverflow || !encoder.InternalHasFallbackBuffer ||
- encoder.FallbackBuffer.Remaining == 0,
- "[Latin1CodePageEncoding.GetByteCount]Expected empty fallback buffer");
- }
- else
- fallback = this.EncoderFallback as EncoderReplacementFallback;
-
- if (fallback != null && fallback.MaxCharCount == 1/* || bIsBestFit*/)
- {
- // Replacement fallback encodes surrogate pairs as two ?? (or two whatever), so return size is always
- // same as input size.
- // Note that no existing SBCS code pages map code points to supplimentary characters, so this is easy.
-
- // We could however have 1 extra byte if the last call had an encoder and a funky fallback and
- // if we don't use the funky fallback this time.
-
- // Do we have an extra char left over from last time?
- if (charLeftOver > 0)
- charCount++;
-
- return charCount;
- }
-
- // Count is more complicated if you have a funky fallback
- // For fallback we may need a fallback buffer, we know we're not default fallback
- int byteCount = 0;
-
- // Start by assuming default count, then +/- for fallback characters
- char* charEnd = chars + charCount;
-
- // For fallback we may need a fallback buffer, we know we aren't default fallback.
- EncoderFallbackBuffer? fallbackBuffer = null;
- char* charsForFallback;
-
- // We may have a left over character from last time, try and process it.
- if (charLeftOver > 0)
- {
- // Initialize the buffer
- Debug.Assert(encoder != null,
- "[Latin1Encoding.GetByteCount]Expected encoder if we have charLeftOver");
- fallbackBuffer = encoder.FallbackBuffer;
- fallbackBuffer.InternalInitialize(chars, charEnd, encoder, false);
-
- // Since left over char was a surrogate, it'll have to be fallen back.
- // Get Fallback
- // This will fallback a pair if *chars is a low surrogate
- charsForFallback = chars;
- fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
- chars = charsForFallback;
- }
-
- // Now we may have fallback char[] already from the encoder
-
- // Go ahead and do it, including the fallback.
- char ch;
- while ((ch = (fallbackBuffer == null) ? '\0' : fallbackBuffer.InternalGetNextChar()) != 0 ||
- chars < charEnd)
- {
- // First unwind any fallback
- if (ch == 0)
- {
- // No fallback, just get next char
- ch = *chars;
- chars++;
- }
-
- // Check for fallback, this'll catch surrogate pairs too.
- // no chars >= 0x100 are allowed.
- if (ch > 0xff)
- {
- // Initialize the buffer
- if (fallbackBuffer == null)
- {
- if (encoder == null)
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = encoder.FallbackBuffer;
- fallbackBuffer.InternalInitialize(charEnd - charCount, charEnd, encoder, false);
- }
-
- // Get Fallback
- charsForFallback = chars;
- fallbackBuffer.InternalFallback(ch, ref charsForFallback);
- chars = charsForFallback;
- continue;
- }
-
- // We'll use this one
- byteCount++;
- }
-
- Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0,
- "[Latin1Encoding.GetByteCount]Expected Empty fallback buffer");
-
- return byteCount;
- }
-
- internal override unsafe int GetBytes(char* chars, int charCount,
- byte* bytes, int byteCount, EncoderNLS? encoder)
- {
- // Just need to ASSERT, this is called by something else internal that checked parameters already
- Debug.Assert(bytes != null, "[Latin1Encoding.GetBytes]bytes is null");
- Debug.Assert(byteCount >= 0, "[Latin1Encoding.GetBytes]byteCount is negative");
- Debug.Assert(chars != null, "[Latin1Encoding.GetBytes]chars is null");
- Debug.Assert(charCount >= 0, "[Latin1Encoding.GetBytes]charCount is negative");
-
- // Assert because we shouldn't be able to have a null encoder.
- Debug.Assert(encoderFallback != null, "[Latin1Encoding.GetBytes]Attempting to use null encoder fallback");
-
- // Get any left over characters & check fast or slower fallback type
- char charLeftOver = (char)0;
- EncoderReplacementFallback? fallback = null;
- if (encoder != null)
- {
- charLeftOver = encoder._charLeftOver;
- fallback = encoder.Fallback as EncoderReplacementFallback;
- Debug.Assert(charLeftOver == 0 || char.IsHighSurrogate(charLeftOver),
- "[Latin1Encoding.GetBytes]leftover character should be high surrogate");
-
- // Verify that we have no fallbackbuffer, for ASCII its always empty, so just assert
- Debug.Assert(!encoder._throwOnOverflow || !encoder.InternalHasFallbackBuffer ||
- encoder.FallbackBuffer.Remaining == 0,
- "[Latin1CodePageEncoding.GetBytes]Expected empty fallback buffer");
- }
- else
- {
- fallback = this.EncoderFallback as EncoderReplacementFallback;
- }
-
- // prepare our end
- char* charEnd = chars + charCount;
- byte* byteStart = bytes;
- char* charStart = chars;
-
- // See if we do the fast default or slightly slower fallback
- if (fallback != null && fallback.MaxCharCount == 1)
- {
- // Fast version
- char cReplacement = fallback.DefaultString[0];
-
- // Check for replacements in range, otherwise fall back to slow version.
- if (cReplacement <= (char)0xff)
- {
- // We should have exactly as many output bytes as input bytes, unless there's a left
- // over character, in which case we may need one more.
-
- // If we had a left over character will have to add a ? (This happens if they had a funky
- // fallback last time, but not this time.) (We can't spit any out though
- // because with fallback encoder each surrogate is treated as a seperate code point)
- if (charLeftOver > 0)
- {
- // Have to have room
- // Throw even if doing no throw version because this is just 1 char,
- // so buffer will never be big enough
- if (byteCount == 0)
- ThrowBytesOverflow(encoder, true);
-
- // This'll make sure we still have more room and also make sure our return value is correct.
- *(bytes++) = (byte)cReplacement;
- byteCount--; // We used one of the ones we were counting.
- }
-
- // This keeps us from overrunning our output buffer
- if (byteCount < charCount)
- {
- // Throw or make buffer smaller?
- ThrowBytesOverflow(encoder, byteCount < 1);
-
- // Just use what we can
- charEnd = chars + byteCount;
- }
-
- // We just do a quick copy
- while (chars < charEnd)
- {
- char ch2 = *(chars++);
- if (ch2 > 0x00ff) *(bytes++) = (byte)cReplacement;
- else *(bytes++) = (byte)ch2;
- }
-
- // Clear encoder
- if (encoder != null)
- {
- encoder._charLeftOver = (char)0;
- encoder._charsUsed = (int)(chars - charStart);
- }
- return (int)(bytes - byteStart);
- }
- }
-
- // Slower version, have to do real fallback.
-
- // prepare our end
- byte* byteEnd = bytes + byteCount;
-
- // For fallback we may need a fallback buffer, we know we aren't default fallback, create & init it
- EncoderFallbackBuffer? fallbackBuffer = null;
- char* charsForFallback;
-
- // We may have a left over character from last time, try and process it.
- if (charLeftOver > 0)
- {
- // Since left over char was a surrogate, it'll have to be fallen back.
- // Get Fallback
- Debug.Assert(encoder != null,
- "[Latin1Encoding.GetBytes]Expected encoder if we have charLeftOver");
- fallbackBuffer = encoder.FallbackBuffer;
- fallbackBuffer.InternalInitialize(chars, charEnd, encoder, true);
-
- // Since left over char was a surrogate, it'll have to be fallen back.
- // Get Fallback
- // This will fallback a pair if *chars is a low surrogate
- charsForFallback = chars;
- fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
- chars = charsForFallback;
-
- if (fallbackBuffer.Remaining > byteEnd - bytes)
- {
- // Throw it, if we don't have enough for this we never will
- ThrowBytesOverflow(encoder, true);
- }
- }
-
- // Now we may have fallback char[] already from the encoder fallback above
-
- // Go ahead and do it, including the fallback.
- char ch;
- while ((ch = (fallbackBuffer == null) ? '\0' : fallbackBuffer.InternalGetNextChar()) != 0 ||
- chars < charEnd)
- {
- // First unwind any fallback
- if (ch == 0)
- {
- // No fallback, just get next char
- ch = *chars;
- chars++;
- }
-
- // Check for fallback, this'll catch surrogate pairs too.
- // All characters >= 0x100 must fall back.
- if (ch > 0xff)
- {
- // Initialize the buffer
- if (fallbackBuffer == null)
- {
- if (encoder == null)
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = encoder.FallbackBuffer;
- fallbackBuffer.InternalInitialize(charEnd - charCount, charEnd, encoder, true);
- }
-
- // Get Fallback
- charsForFallback = chars;
- fallbackBuffer.InternalFallback(ch, ref charsForFallback);
- chars = charsForFallback;
-
- // Make sure we have enough room. Each fallback char will be 1 output char
- // (or else cause a recursion exception)
- if (fallbackBuffer.Remaining > byteEnd - bytes)
- {
- // Didn't use this char, throw it. Chars should've advanced by now
- // If we had encoder fallback data it would've thrown before the loop
- Debug.Assert(chars > charStart,
- "[Latin1Encoding.GetBytes]Expected chars to have advanced (fallback case)");
- chars--;
- fallbackBuffer.InternalReset();
-
- // Throw it
- ThrowBytesOverflow(encoder, chars == charStart);
- break;
- }
-
- continue;
- }
-
- // We'll use this one
- // Bounds check
- if (bytes >= byteEnd)
- {
- // didn't use this char, we'll throw or use buffer
- Debug.Assert(fallbackBuffer == null || !fallbackBuffer.bFallingBack,
- "[Latin1Encoding.GetBytes]Expected fallback to have throw initially if insufficient space");
- if (fallbackBuffer == null || !fallbackBuffer.bFallingBack)
- {
- Debug.Assert(chars > charStart,
- "[Latin1Encoding.GetBytes]Expected chars to have advanced (fallback case)");
- chars--; // don't use last char
- }
- ThrowBytesOverflow(encoder, chars == charStart); // throw ?
- break; // don't throw, stop
- }
-
- // Go ahead and add it
- *bytes = unchecked((byte)ch);
- bytes++;
- }
-
- // Need to do encoder stuff
- if (encoder != null)
- {
- // Fallback stuck it in encoder if necessary, but we have to clear MustFlush cases
- if (fallbackBuffer != null && !fallbackBuffer.bUsedEncoder)
- // Clear it in case of MustFlush
- encoder._charLeftOver = (char)0;
-
- // Set our chars used count
- encoder._charsUsed = (int)(chars - charStart);
- }
-
- Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0,
- "[Latin1Encoding.GetBytes]Expected Empty fallback buffer");
-
- return (int)(bytes - byteStart);
- }
-
- // This is internal and called by something else,
- internal override unsafe int GetCharCount(byte* bytes, int count, DecoderNLS? decoder)
- {
- // Just assert, we're called internally so these should be safe, checked already
- Debug.Assert(bytes != null, "[Latin1Encoding.GetCharCount]bytes is null");
- Debug.Assert(count >= 0, "[Latin1Encoding.GetCharCount]byteCount is negative");
-
- // Just return length, SBCS stay the same length because they don't map to surrogate
- // pairs and we don't have to fallback because all latin1Encoding code points are unicode
- return count;
- }
-
- internal override unsafe int GetChars(byte* bytes, int byteCount,
- char* chars, int charCount, DecoderNLS? decoder)
- {
- // Just need to ASSERT, this is called by something else internal that checked parameters already
- Debug.Assert(bytes != null, "[Latin1Encoding.GetChars]bytes is null");
- Debug.Assert(byteCount >= 0, "[Latin1Encoding.GetChars]byteCount is negative");
- Debug.Assert(chars != null, "[Latin1Encoding.GetChars]chars is null");
- Debug.Assert(charCount >= 0, "[Latin1Encoding.GetChars]charCount is negative");
-
- // Need byteCount chars, otherwise too small buffer
- if (charCount < byteCount)
- {
- // Buffer too small. Do we throw?
- ThrowCharsOverflow(decoder, charCount < 1);
-
- // Don't throw, correct buffer size
- byteCount = charCount;
- }
-
- // Do it our fast way
- byte* byteEnd = bytes + byteCount;
-
- // Quick loop, all bytes are the same as chars, so no fallbacks for latin1
- while (bytes < byteEnd)
- {
- *(chars) = unchecked((char)*(bytes));
- chars++;
- bytes++;
- }
-
- // Might need to know input bytes used
- if (decoder != null)
- decoder._bytesUsed = byteCount;
-
- // Converted sequence is same length as input, so output charsUsed is same as byteCount;
- return byteCount;
- }
-
- public override int GetMaxByteCount(int charCount)
- {
- if (charCount < 0)
- throw new ArgumentOutOfRangeException(nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Characters would be # of characters + 1 in case high surrogate is ? * max fallback
- long byteCount = (long)charCount + 1;
-
- if (EncoderFallback.MaxCharCount > 1)
- byteCount *= EncoderFallback.MaxCharCount;
-
- // 1 to 1 for most characters. Only surrogates with fallbacks have less.
-
- if (byteCount > 0x7fffffff)
- throw new ArgumentOutOfRangeException(nameof(charCount), SR.ArgumentOutOfRange_GetByteCountOverflow);
- return (int)byteCount;
- }
-
- public override int GetMaxCharCount(int byteCount)
- {
- if (byteCount < 0)
- throw new ArgumentOutOfRangeException(nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Just return length, SBCS stay the same length because they don't map to surrogate
- long charCount = (long)byteCount;
-
- // 1 to 1 for most characters. Only surrogates with fallbacks have less, unknown fallbacks could be longer.
- if (DecoderFallback.MaxCharCount > 1)
- charCount *= DecoderFallback.MaxCharCount;
-
- if (charCount > 0x7fffffff)
- throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ArgumentOutOfRange_GetCharCountOverflow);
-
- return (int)charCount;
- }
-
- // True if and only if the encoding only uses single byte code points. (Ie, ASCII, 1252, etc)
- public override bool IsSingleByte => true;
-
- public override bool IsAlwaysNormalized(NormalizationForm form)
- {
- // Latin-1 contains precomposed characters, so normal for Form C.
- // Since some are composed, not normal for D & KD.
- // Also some letters like 0x00A8 (spacing diarisis) have compatibility decompositions, so false for KD & KC.
-
- // Only true for form C.
- return form == NormalizationForm.FormC;
- }
- // Since our best fit table is small we'll hard code it
- internal override char[] GetBestFitUnicodeToBytesData()
- {
- // Get our best fit data
- return Latin1Encoding.arrayCharBestFit;
- }
-
- // Best fit for ASCII, and since it works for ASCII, we use it for latin1 as well.
- private static readonly char[] arrayCharBestFit =
- {
-// The first many are in case you wanted to use this for ASCIIEncoding, which we don't need to do any more.
-// (char)0x00a0, (char)0x0020, // No-Break Space -> Space
-// (char)0x00a1, (char)0x0021, // Inverted Exclamation Mark -> !
-// (char)0x00a2, (char)0x0063, // Cent Sign -> c
-// (char)0x00a3, (char)0x003f, // Pound Sign
-// (char)0x00a4, (char)0x0024, // Currency Sign -> $
-// (char)0x00a5, (char)0x0059, // Yen Sign -> Y
-// (char)0x00a6, (char)0x007c, // Broken Bar -> |
-// (char)0x00a7, (char)0x003f, // Section Sign
-// (char)0x00a8, (char)0x003f, // Diaeresis
-// (char)0x00a9, (char)0x0043, // Copyright Sign -> C
-// (char)0x00aa, (char)0x0061, // Feminine Ordinal Indicator -> a
-// (char)0x00ab, (char)0x003c, // Left-Pointing Double Angle Quotation Mark -> <
-// (char)0x00ac, (char)0x003f, // Not Sign
-// (char)0x00ad, (char)0x002d, // Soft Hyphen -> -
-// (char)0x00ae, (char)0x0052, // Registered Sign -> R
-// (char)0x00af, (char)0x003f, // Macron
-// (char)0x00b0, (char)0x003f, // Degree Sign
-// (char)0x00b1, (char)0x003f, // Plus-Minus Sign
-// (char)0x00b2, (char)0x0032, // Superscript Two -> 2
-// (char)0x00b3, (char)0x0033, // Superscript Three -> 3
-// (char)0x00b4, (char)0x003f, // Acute Accent
-// (char)0x00b5, (char)0x003f, // Micro Sign
-// (char)0x00b6, (char)0x003f, // Pilcrow Sign
-// (char)0x00b7, (char)0x002e, // Middle Dot -> .
-// (char)0x00b8, (char)0x002c, // Cedilla -> ,
-// (char)0x00b9, (char)0x0031, // Superscript One -> 1
-// (char)0x00ba, (char)0x006f, // Masculine Ordinal Indicator -> o
-// (char)0x00bb, (char)0x003e, // Right-Pointing Double Angle Quotation Mark -> >
-// (char)0x00bc, (char)0x003f, // Vulgar Fraction One Quarter
-// (char)0x00bd, (char)0x003f, // Vulgar Fraction One Half
-// (char)0x00be, (char)0x003f, // Vulgar Fraction Three Quarters
-// (char)0x00bf, (char)0x003f, // Inverted Question Mark
-// (char)0x00c0, (char)0x0041, // Latin Capital Letter A With Grave -> A
-// (char)0x00c1, (char)0x0041, // Latin Capital Letter A With Acute -> A
-// (char)0x00c2, (char)0x0041, // Latin Capital Letter A With Circumflex -> A
-// (char)0x00c3, (char)0x0041, // Latin Capital Letter A With Tilde -> A
-// (char)0x00c4, (char)0x0041, // Latin Capital Letter A With Diaeresis -> A
-// (char)0x00c5, (char)0x0041, // Latin Capital Letter A With Ring Above -> A
-// (char)0x00c6, (char)0x0041, // Latin Capital Ligature Ae -> A
-// (char)0x00c7, (char)0x0043, // Latin Capital Letter C With Cedilla -> C
-// (char)0x00c8, (char)0x0045, // Latin Capital Letter E With Grave -> E
-// (char)0x00c9, (char)0x0045, // Latin Capital Letter E With Acute -> E
-// (char)0x00ca, (char)0x0045, // Latin Capital Letter E With Circumflex -> E
-// (char)0x00cb, (char)0x0045, // Latin Capital Letter E With Diaeresis -> E
-// (char)0x00cc, (char)0x0049, // Latin Capital Letter I With Grave -> I
-// (char)0x00cd, (char)0x0049, // Latin Capital Letter I With Acute -> I
-// (char)0x00ce, (char)0x0049, // Latin Capital Letter I With Circumflex -> I
-// (char)0x00cf, (char)0x0049, // Latin Capital Letter I With Diaeresis -> I
-// (char)0x00d0, (char)0x0044, // Latin Capital Letter Eth -> D
-// (char)0x00d1, (char)0x004e, // Latin Capital Letter N With Tilde -> N
-// (char)0x00d2, (char)0x004f, // Latin Capital Letter O With Grave -> O
-// (char)0x00d3, (char)0x004f, // Latin Capital Letter O With Acute -> O
-// (char)0x00d4, (char)0x004f, // Latin Capital Letter O With Circumflex -> O
-// (char)0x00d5, (char)0x004f, // Latin Capital Letter O With Tilde -> O
-// (char)0x00d6, (char)0x004f, // Latin Capital Letter O With Diaeresis -> O
-// (char)0x00d7, (char)0x003f, // Multiplication Sign
-// (char)0x00d8, (char)0x004f, // Latin Capital Letter O With Stroke -> O
-// (char)0x00d9, (char)0x0055, // Latin Capital Letter U With Grave -> U
-// (char)0x00da, (char)0x0055, // Latin Capital Letter U With Acute -> U
-// (char)0x00db, (char)0x0055, // Latin Capital Letter U With Circumflex -> U
-// (char)0x00dc, (char)0x0055, // Latin Capital Letter U With Diaeresis -> U
-// (char)0x00dd, (char)0x0059, // Latin Capital Letter Y With Acute -> Y
-// (char)0x00de, (char)0x003f, // Latin Capital Letter Thorn
-// (char)0x00df, (char)0x003f, // Latin Small Letter Sharp S
-// (char)0x00e0, (char)0x0061, // Latin Small Letter A With Grave -> a
-// (char)0x00e1, (char)0x0061, // Latin Small Letter A With Acute -> a
-// (char)0x00e2, (char)0x0061, // Latin Small Letter A With Circumflex -> a
-// (char)0x00e3, (char)0x0061, // Latin Small Letter A With Tilde -> a
-// (char)0x00e4, (char)0x0061, // Latin Small Letter A With Diaeresis -> a
-// (char)0x00e5, (char)0x0061, // Latin Small Letter A With Ring Above -> a
-// (char)0x00e6, (char)0x0061, // Latin Small Ligature Ae -> a
-// (char)0x00e7, (char)0x0063, // Latin Small Letter C With Cedilla -> c
-// (char)0x00e8, (char)0x0065, // Latin Small Letter E With Grave -> e
-// (char)0x00e9, (char)0x0065, // Latin Small Letter E With Acute -> e
-// (char)0x00ea, (char)0x0065, // Latin Small Letter E With Circumflex -> e
-// (char)0x00eb, (char)0x0065, // Latin Small Letter E With Diaeresis -> e
-// (char)0x00ec, (char)0x0069, // Latin Small Letter I With Grave -> i
-// (char)0x00ed, (char)0x0069, // Latin Small Letter I With Acute -> i
-// (char)0x00ee, (char)0x0069, // Latin Small Letter I With Circumflex -> i
-// (char)0x00ef, (char)0x0069, // Latin Small Letter I With Diaeresis -> i
-// (char)0x00f0, (char)0x003f, // Latin Small Letter Eth
-// (char)0x00f1, (char)0x006e, // Latin Small Letter N With Tilde -> n
-// (char)0x00f2, (char)0x006f, // Latin Small Letter O With Grave -> o
-// (char)0x00f3, (char)0x006f, // Latin Small Letter O With Acute -> o
-// (char)0x00f4, (char)0x006f, // Latin Small Letter O With Circumflex -> o
-// (char)0x00f5, (char)0x006f, // Latin Small Letter O With Tilde -> o
-// (char)0x00f6, (char)0x006f, // Latin Small Letter O With Diaeresis -> o
-// (char)0x00f7, (char)0x003f, // Division Sign
-// (char)0x00f8, (char)0x006f, // Latin Small Letter O With Stroke -> o
-// (char)0x00f9, (char)0x0075, // Latin Small Letter U With Grave -> u
-// (char)0x00fa, (char)0x0075, // Latin Small Letter U With Acute -> u
-// (char)0x00fb, (char)0x0075, // Latin Small Letter U With Circumflex -> u
-// (char)0x00fc, (char)0x0075, // Latin Small Letter U With Diaeresis -> u
-// (char)0x00fd, (char)0x0079, // Latin Small Letter Y With Acute -> y
-// (char)0x00fe, (char)0x003f, // Latin Small Letter Thorn
-// (char)0x00ff, (char)0x0079, // Latin Small Letter Y With Diaeresis -> y
- (char)0x0100, (char)0x0041, // Latin Capital Letter A With Macron -> A
- (char)0x0101, (char)0x0061, // Latin Small Letter A With Macron -> a
- (char)0x0102, (char)0x0041, // Latin Capital Letter A With Breve -> A
- (char)0x0103, (char)0x0061, // Latin Small Letter A With Breve -> a
- (char)0x0104, (char)0x0041, // Latin Capital Letter A With Ogonek -> A
- (char)0x0105, (char)0x0061, // Latin Small Letter A With Ogonek -> a
- (char)0x0106, (char)0x0043, // Latin Capital Letter C With Acute -> C
- (char)0x0107, (char)0x0063, // Latin Small Letter C With Acute -> c
- (char)0x0108, (char)0x0043, // Latin Capital Letter C With Circumflex -> C
- (char)0x0109, (char)0x0063, // Latin Small Letter C With Circumflex -> c
- (char)0x010a, (char)0x0043, // Latin Capital Letter C With Dot Above -> C
- (char)0x010b, (char)0x0063, // Latin Small Letter C With Dot Above -> c
- (char)0x010c, (char)0x0043, // Latin Capital Letter C With Caron -> C
- (char)0x010d, (char)0x0063, // Latin Small Letter C With Caron -> c
- (char)0x010e, (char)0x0044, // Latin Capital Letter D With Caron -> D
- (char)0x010f, (char)0x0064, // Latin Small Letter D With Caron -> d
- (char)0x0110, (char)0x0044, // Latin Capital Letter D With Stroke -> D
- (char)0x0111, (char)0x0064, // Latin Small Letter D With Stroke -> d
- (char)0x0112, (char)0x0045, // Latin Capital Letter E With Macron -> E
- (char)0x0113, (char)0x0065, // Latin Small Letter E With Macron -> e
- (char)0x0114, (char)0x0045, // Latin Capital Letter E With Breve -> E
- (char)0x0115, (char)0x0065, // Latin Small Letter E With Breve -> e
- (char)0x0116, (char)0x0045, // Latin Capital Letter E With Dot Above -> E
- (char)0x0117, (char)0x0065, // Latin Small Letter E With Dot Above -> e
- (char)0x0118, (char)0x0045, // Latin Capital Letter E With Ogonek -> E
- (char)0x0119, (char)0x0065, // Latin Small Letter E With Ogonek -> e
- (char)0x011a, (char)0x0045, // Latin Capital Letter E With Caron -> E
- (char)0x011b, (char)0x0065, // Latin Small Letter E With Caron -> e
- (char)0x011c, (char)0x0047, // Latin Capital Letter G With Circumflex -> G
- (char)0x011d, (char)0x0067, // Latin Small Letter G With Circumflex -> g
- (char)0x011e, (char)0x0047, // Latin Capital Letter G With Breve -> G
- (char)0x011f, (char)0x0067, // Latin Small Letter G With Breve -> g
- (char)0x0120, (char)0x0047, // Latin Capital Letter G With Dot Above -> G
- (char)0x0121, (char)0x0067, // Latin Small Letter G With Dot Above -> g
- (char)0x0122, (char)0x0047, // Latin Capital Letter G With Cedilla -> G
- (char)0x0123, (char)0x0067, // Latin Small Letter G With Cedilla -> g
- (char)0x0124, (char)0x0048, // Latin Capital Letter H With Circumflex -> H
- (char)0x0125, (char)0x0068, // Latin Small Letter H With Circumflex -> h
- (char)0x0126, (char)0x0048, // Latin Capital Letter H With Stroke -> H
- (char)0x0127, (char)0x0068, // Latin Small Letter H With Stroke -> h
- (char)0x0128, (char)0x0049, // Latin Capital Letter I With Tilde -> I
- (char)0x0129, (char)0x0069, // Latin Small Letter I With Tilde -> i
- (char)0x012a, (char)0x0049, // Latin Capital Letter I With Macron -> I
- (char)0x012b, (char)0x0069, // Latin Small Letter I With Macron -> i
- (char)0x012c, (char)0x0049, // Latin Capital Letter I With Breve -> I
- (char)0x012d, (char)0x0069, // Latin Small Letter I With Breve -> i
- (char)0x012e, (char)0x0049, // Latin Capital Letter I With Ogonek -> I
- (char)0x012f, (char)0x0069, // Latin Small Letter I With Ogonek -> i
- (char)0x0130, (char)0x0049, // Latin Capital Letter I With Dot Above -> I
- (char)0x0131, (char)0x0069, // Latin Small Letter Dotless I -> i
- (char)0x0134, (char)0x004a, // Latin Capital Letter J With Circumflex -> J
- (char)0x0135, (char)0x006a, // Latin Small Letter J With Circumflex -> j
- (char)0x0136, (char)0x004b, // Latin Capital Letter K With Cedilla -> K
- (char)0x0137, (char)0x006b, // Latin Small Letter K With Cedilla -> k
- (char)0x0139, (char)0x004c, // Latin Capital Letter L With Acute -> L
- (char)0x013a, (char)0x006c, // Latin Small Letter L With Acute -> l
- (char)0x013b, (char)0x004c, // Latin Capital Letter L With Cedilla -> L
- (char)0x013c, (char)0x006c, // Latin Small Letter L With Cedilla -> l
- (char)0x013d, (char)0x004c, // Latin Capital Letter L With Caron -> L
- (char)0x013e, (char)0x006c, // Latin Small Letter L With Caron -> l
- (char)0x0141, (char)0x004c, // Latin Capital Letter L With Stroke -> L
- (char)0x0142, (char)0x006c, // Latin Small Letter L With Stroke -> l
- (char)0x0143, (char)0x004e, // Latin Capital Letter N With Acute -> N
- (char)0x0144, (char)0x006e, // Latin Small Letter N With Acute -> n
- (char)0x0145, (char)0x004e, // Latin Capital Letter N With Cedilla -> N
- (char)0x0146, (char)0x006e, // Latin Small Letter N With Cedilla -> n
- (char)0x0147, (char)0x004e, // Latin Capital Letter N With Caron -> N
- (char)0x0148, (char)0x006e, // Latin Small Letter N With Caron -> n
- (char)0x014c, (char)0x004f, // Latin Capital Letter O With Macron -> O
- (char)0x014d, (char)0x006f, // Latin Small Letter O With Macron -> o
- (char)0x014e, (char)0x004f, // Latin Capital Letter O With Breve -> O
- (char)0x014f, (char)0x006f, // Latin Small Letter O With Breve -> o
- (char)0x0150, (char)0x004f, // Latin Capital Letter O With Double Acute -> O
- (char)0x0151, (char)0x006f, // Latin Small Letter O With Double Acute -> o
- (char)0x0152, (char)0x004f, // Latin Capital Ligature Oe -> O
- (char)0x0153, (char)0x006f, // Latin Small Ligature Oe -> o
- (char)0x0154, (char)0x0052, // Latin Capital Letter R With Acute -> R
- (char)0x0155, (char)0x0072, // Latin Small Letter R With Acute -> r
- (char)0x0156, (char)0x0052, // Latin Capital Letter R With Cedilla -> R
- (char)0x0157, (char)0x0072, // Latin Small Letter R With Cedilla -> r
- (char)0x0158, (char)0x0052, // Latin Capital Letter R With Caron -> R
- (char)0x0159, (char)0x0072, // Latin Small Letter R With Caron -> r
- (char)0x015a, (char)0x0053, // Latin Capital Letter S With Acute -> S
- (char)0x015b, (char)0x0073, // Latin Small Letter S With Acute -> s
- (char)0x015c, (char)0x0053, // Latin Capital Letter S With Circumflex -> S
- (char)0x015d, (char)0x0073, // Latin Small Letter S With Circumflex -> s
- (char)0x015e, (char)0x0053, // Latin Capital Letter S With Cedilla -> S
- (char)0x015f, (char)0x0073, // Latin Small Letter S With Cedilla -> s
- (char)0x0160, (char)0x0053, // Latin Capital Letter S With Caron -> S
- (char)0x0161, (char)0x0073, // Latin Small Letter S With Caron -> s
- (char)0x0162, (char)0x0054, // Latin Capital Letter T With Cedilla -> T
- (char)0x0163, (char)0x0074, // Latin Small Letter T With Cedilla -> t
- (char)0x0164, (char)0x0054, // Latin Capital Letter T With Caron -> T
- (char)0x0165, (char)0x0074, // Latin Small Letter T With Caron -> t
- (char)0x0166, (char)0x0054, // Latin Capital Letter T With Stroke -> T
- (char)0x0167, (char)0x0074, // Latin Small Letter T With Stroke -> t
- (char)0x0168, (char)0x0055, // Latin Capital Letter U With Tilde -> U
- (char)0x0169, (char)0x0075, // Latin Small Letter U With Tilde -> u
- (char)0x016a, (char)0x0055, // Latin Capital Letter U With Macron -> U
- (char)0x016b, (char)0x0075, // Latin Small Letter U With Macron -> u
- (char)0x016c, (char)0x0055, // Latin Capital Letter U With Breve -> U
- (char)0x016d, (char)0x0075, // Latin Small Letter U With Breve -> u
- (char)0x016e, (char)0x0055, // Latin Capital Letter U With Ring Above -> U
- (char)0x016f, (char)0x0075, // Latin Small Letter U With Ring Above -> u
- (char)0x0170, (char)0x0055, // Latin Capital Letter U With Double Acute -> U
- (char)0x0171, (char)0x0075, // Latin Small Letter U With Double Acute -> u
- (char)0x0172, (char)0x0055, // Latin Capital Letter U With Ogonek -> U
- (char)0x0173, (char)0x0075, // Latin Small Letter U With Ogonek -> u
- (char)0x0174, (char)0x0057, // Latin Capital Letter W With Circumflex -> W
- (char)0x0175, (char)0x0077, // Latin Small Letter W With Circumflex -> w
- (char)0x0176, (char)0x0059, // Latin Capital Letter Y With Circumflex -> Y
- (char)0x0177, (char)0x0079, // Latin Small Letter Y With Circumflex -> y
- (char)0x0178, (char)0x0059, // Latin Capital Letter Y With Diaeresis -> Y
- (char)0x0179, (char)0x005a, // Latin Capital Letter Z With Acute -> Z
- (char)0x017a, (char)0x007a, // Latin Small Letter Z With Acute -> z
- (char)0x017b, (char)0x005a, // Latin Capital Letter Z With Dot Above -> Z
- (char)0x017c, (char)0x007a, // Latin Small Letter Z With Dot Above -> z
- (char)0x017d, (char)0x005a, // Latin Capital Letter Z With Caron -> Z
- (char)0x017e, (char)0x007a, // Latin Small Letter Z With Caron -> z
- (char)0x0180, (char)0x0062, // Latin Small Letter B With Stroke -> b
- (char)0x0189, (char)0x0044, // Latin Capital Letter African D -> D
- (char)0x0191, (char)0x0046, // Latin Capital Letter F With Hook -> F
- (char)0x0192, (char)0x0066, // Latin Small Letter F With Hook -> f
- (char)0x0197, (char)0x0049, // Latin Capital Letter I With Stroke -> I
- (char)0x019a, (char)0x006c, // Latin Small Letter L With Bar -> l
- (char)0x019f, (char)0x004f, // Latin Capital Letter O With Middle Tilde -> O
- (char)0x01a0, (char)0x004f, // Latin Capital Letter O With Horn -> O
- (char)0x01a1, (char)0x006f, // Latin Small Letter O With Horn -> o
- (char)0x01ab, (char)0x0074, // Latin Small Letter T With Palatal Hook -> t
- (char)0x01ae, (char)0x0054, // Latin Capital Letter T With Retroflex Hook -> T
- (char)0x01af, (char)0x0055, // Latin Capital Letter U With Horn -> U
- (char)0x01b0, (char)0x0075, // Latin Small Letter U With Horn -> u
- (char)0x01b6, (char)0x007a, // Latin Small Letter Z With Stroke -> z
- (char)0x01cd, (char)0x0041, // Latin Capital Letter A With Caron -> A
- (char)0x01ce, (char)0x0061, // Latin Small Letter A With Caron -> a
- (char)0x01cf, (char)0x0049, // Latin Capital Letter I With Caron -> I
- (char)0x01d0, (char)0x0069, // Latin Small Letter I With Caron -> i
- (char)0x01d1, (char)0x004f, // Latin Capital Letter O With Caron -> O
- (char)0x01d2, (char)0x006f, // Latin Small Letter O With Caron -> o
- (char)0x01d3, (char)0x0055, // Latin Capital Letter U With Caron -> U
- (char)0x01d4, (char)0x0075, // Latin Small Letter U With Caron -> u
- (char)0x01d5, (char)0x0055, // Latin Capital Letter U With Diaeresis And Macron -> U
- (char)0x01d6, (char)0x0075, // Latin Small Letter U With Diaeresis And Macron -> u
- (char)0x01d7, (char)0x0055, // Latin Capital Letter U With Diaeresis And Acute -> U
- (char)0x01d8, (char)0x0075, // Latin Small Letter U With Diaeresis And Acute -> u
- (char)0x01d9, (char)0x0055, // Latin Capital Letter U With Diaeresis And Caron -> U
- (char)0x01da, (char)0x0075, // Latin Small Letter U With Diaeresis And Caron -> u
- (char)0x01db, (char)0x0055, // Latin Capital Letter U With Diaeresis And Grave -> U
- (char)0x01dc, (char)0x0075, // Latin Small Letter U With Diaeresis And Grave -> u
- (char)0x01de, (char)0x0041, // Latin Capital Letter A With Diaeresis And Macron -> A
- (char)0x01df, (char)0x0061, // Latin Small Letter A With Diaeresis And Macron -> a
- (char)0x01e4, (char)0x0047, // Latin Capital Letter G With Stroke -> G
- (char)0x01e5, (char)0x0067, // Latin Small Letter G With Stroke -> g
- (char)0x01e6, (char)0x0047, // Latin Capital Letter G With Caron -> G
- (char)0x01e7, (char)0x0067, // Latin Small Letter G With Caron -> g
- (char)0x01e8, (char)0x004b, // Latin Capital Letter K With Caron -> K
- (char)0x01e9, (char)0x006b, // Latin Small Letter K With Caron -> k
- (char)0x01ea, (char)0x004f, // Latin Capital Letter O With Ogonek -> O
- (char)0x01eb, (char)0x006f, // Latin Small Letter O With Ogonek -> o
- (char)0x01ec, (char)0x004f, // Latin Capital Letter O With Ogonek And Macron -> O
- (char)0x01ed, (char)0x006f, // Latin Small Letter O With Ogonek And Macron -> o
- (char)0x01f0, (char)0x006a, // Latin Small Letter J With Caron -> j
- (char)0x0261, (char)0x0067, // Latin Small Letter Script G -> g
- (char)0x02b9, (char)0x0027, // Modifier Letter Prime -> '
- (char)0x02ba, (char)0x0022, // Modifier Letter Double Prime -> "
- (char)0x02bc, (char)0x0027, // Modifier Letter Apostrophe -> '
- (char)0x02c4, (char)0x005e, // Modifier Letter Up Arrowhead -> ^
- (char)0x02c6, (char)0x005e, // Modifier Letter Circumflex Accent -> ^
- (char)0x02c8, (char)0x0027, // Modifier Letter Vertical Line -> '
- (char)0x02c9, (char)0x003f, // Modifier Letter Macron
- (char)0x02ca, (char)0x003f, // Modifier Letter Acute Accent
- (char)0x02cb, (char)0x0060, // Modifier Letter Grave Accent -> `
- (char)0x02cd, (char)0x005f, // Modifier Letter Low Macron -> _
- (char)0x02da, (char)0x003f, // Ring Above
- (char)0x02dc, (char)0x007e, // Small Tilde -> ~
- (char)0x0300, (char)0x0060, // Combining Grave Accent -> `
- (char)0x0302, (char)0x005e, // Combining Circumflex Accent -> ^
- (char)0x0303, (char)0x007e, // Combining Tilde -> ~
- (char)0x030e, (char)0x0022, // Combining Double Vertical Line Above -> "
- (char)0x0331, (char)0x005f, // Combining Macron Below -> _
- (char)0x0332, (char)0x005f, // Combining Low Line -> _
- (char)0x2000, (char)0x0020, // En Quad
- (char)0x2001, (char)0x0020, // Em Quad
- (char)0x2002, (char)0x0020, // En Space
- (char)0x2003, (char)0x0020, // Em Space
- (char)0x2004, (char)0x0020, // Three-Per-Em Space
- (char)0x2005, (char)0x0020, // Four-Per-Em Space
- (char)0x2006, (char)0x0020, // Six-Per-Em Space
- (char)0x2010, (char)0x002d, // Hyphen -> -
- (char)0x2011, (char)0x002d, // Non-Breaking Hyphen -> -
- (char)0x2013, (char)0x002d, // En Dash -> -
- (char)0x2014, (char)0x002d, // Em Dash -> -
- (char)0x2018, (char)0x0027, // Left Single Quotation Mark -> '
- (char)0x2019, (char)0x0027, // Right Single Quotation Mark -> '
- (char)0x201a, (char)0x002c, // Single Low-9 Quotation Mark -> ,
- (char)0x201c, (char)0x0022, // Left Double Quotation Mark -> "
- (char)0x201d, (char)0x0022, // Right Double Quotation Mark -> "
- (char)0x201e, (char)0x0022, // Double Low-9 Quotation Mark -> "
- (char)0x2020, (char)0x003f, // Dagger
- (char)0x2021, (char)0x003f, // Double Dagger
- (char)0x2022, (char)0x002e, // Bullet -> .
- (char)0x2026, (char)0x002e, // Horizontal Ellipsis -> .
- (char)0x2030, (char)0x003f, // Per Mille Sign
- (char)0x2032, (char)0x0027, // Prime -> '
- (char)0x2035, (char)0x0060, // Reversed Prime -> `
- (char)0x2039, (char)0x003c, // Single Left-Pointing Angle Quotation Mark -> <
- (char)0x203a, (char)0x003e, // Single Right-Pointing Angle Quotation Mark -> >
- (char)0x2122, (char)0x0054, // Trade Mark Sign -> T
- (char)0xff01, (char)0x0021, // Fullwidth Exclamation Mark -> !
- (char)0xff02, (char)0x0022, // Fullwidth Quotation Mark -> "
- (char)0xff03, (char)0x0023, // Fullwidth Number Sign -> #
- (char)0xff04, (char)0x0024, // Fullwidth Dollar Sign -> $
- (char)0xff05, (char)0x0025, // Fullwidth Percent Sign -> %
- (char)0xff06, (char)0x0026, // Fullwidth Ampersand -> &
- (char)0xff07, (char)0x0027, // Fullwidth Apostrophe -> '
- (char)0xff08, (char)0x0028, // Fullwidth Left Parenthesis -> (
- (char)0xff09, (char)0x0029, // Fullwidth Right Parenthesis -> )
- (char)0xff0a, (char)0x002a, // Fullwidth Asterisk -> *
- (char)0xff0b, (char)0x002b, // Fullwidth Plus Sign -> +
- (char)0xff0c, (char)0x002c, // Fullwidth Comma -> ,
- (char)0xff0d, (char)0x002d, // Fullwidth Hyphen-Minus -> -
- (char)0xff0e, (char)0x002e, // Fullwidth Full Stop -> .
- (char)0xff0f, (char)0x002f, // Fullwidth Solidus -> /
- (char)0xff10, (char)0x0030, // Fullwidth Digit Zero -> 0
- (char)0xff11, (char)0x0031, // Fullwidth Digit One -> 1
- (char)0xff12, (char)0x0032, // Fullwidth Digit Two -> 2
- (char)0xff13, (char)0x0033, // Fullwidth Digit Three -> 3
- (char)0xff14, (char)0x0034, // Fullwidth Digit Four -> 4
- (char)0xff15, (char)0x0035, // Fullwidth Digit Five -> 5
- (char)0xff16, (char)0x0036, // Fullwidth Digit Six -> 6
- (char)0xff17, (char)0x0037, // Fullwidth Digit Seven -> 7
- (char)0xff18, (char)0x0038, // Fullwidth Digit Eight -> 8
- (char)0xff19, (char)0x0039, // Fullwidth Digit Nine -> 9
- (char)0xff1a, (char)0x003a, // Fullwidth Colon -> :
- (char)0xff1b, (char)0x003b, // Fullwidth Semicolon -> ;
- (char)0xff1c, (char)0x003c, // Fullwidth Less-Than Sign -> <
- (char)0xff1d, (char)0x003d, // Fullwidth Equals Sign -> =
- (char)0xff1e, (char)0x003e, // Fullwidth Greater-Than Sign -> >
- (char)0xff1f, (char)0x003f, // Fullwidth Question Mark
- (char)0xff20, (char)0x0040, // Fullwidth Commercial At -> @
- (char)0xff21, (char)0x0041, // Fullwidth Latin Capital Letter A -> A
- (char)0xff22, (char)0x0042, // Fullwidth Latin Capital Letter B -> B
- (char)0xff23, (char)0x0043, // Fullwidth Latin Capital Letter C -> C
- (char)0xff24, (char)0x0044, // Fullwidth Latin Capital Letter D -> D
- (char)0xff25, (char)0x0045, // Fullwidth Latin Capital Letter E -> E
- (char)0xff26, (char)0x0046, // Fullwidth Latin Capital Letter F -> F
- (char)0xff27, (char)0x0047, // Fullwidth Latin Capital Letter G -> G
- (char)0xff28, (char)0x0048, // Fullwidth Latin Capital Letter H -> H
- (char)0xff29, (char)0x0049, // Fullwidth Latin Capital Letter I -> I
- (char)0xff2a, (char)0x004a, // Fullwidth Latin Capital Letter J -> J
- (char)0xff2b, (char)0x004b, // Fullwidth Latin Capital Letter K -> K
- (char)0xff2c, (char)0x004c, // Fullwidth Latin Capital Letter L -> L
- (char)0xff2d, (char)0x004d, // Fullwidth Latin Capital Letter M -> M
- (char)0xff2e, (char)0x004e, // Fullwidth Latin Capital Letter N -> N
- (char)0xff2f, (char)0x004f, // Fullwidth Latin Capital Letter O -> O
- (char)0xff30, (char)0x0050, // Fullwidth Latin Capital Letter P -> P
- (char)0xff31, (char)0x0051, // Fullwidth Latin Capital Letter Q -> Q
- (char)0xff32, (char)0x0052, // Fullwidth Latin Capital Letter R -> R
- (char)0xff33, (char)0x0053, // Fullwidth Latin Capital Letter S -> S
- (char)0xff34, (char)0x0054, // Fullwidth Latin Capital Letter T -> T
- (char)0xff35, (char)0x0055, // Fullwidth Latin Capital Letter U -> U
- (char)0xff36, (char)0x0056, // Fullwidth Latin Capital Letter V -> V
- (char)0xff37, (char)0x0057, // Fullwidth Latin Capital Letter W -> W
- (char)0xff38, (char)0x0058, // Fullwidth Latin Capital Letter X -> X
- (char)0xff39, (char)0x0059, // Fullwidth Latin Capital Letter Y -> Y
- (char)0xff3a, (char)0x005a, // Fullwidth Latin Capital Letter Z -> Z
- (char)0xff3b, (char)0x005b, // Fullwidth Left Square Bracket -> [
- (char)0xff3c, (char)0x005c, // Fullwidth Reverse Solidus -> \
- (char)0xff3d, (char)0x005d, // Fullwidth Right Square Bracket -> ]
- (char)0xff3e, (char)0x005e, // Fullwidth Circumflex Accent -> ^
- (char)0xff3f, (char)0x005f, // Fullwidth Low Line -> _
- (char)0xff40, (char)0x0060, // Fullwidth Grave Accent -> `
- (char)0xff41, (char)0x0061, // Fullwidth Latin Small Letter A -> a
- (char)0xff42, (char)0x0062, // Fullwidth Latin Small Letter B -> b
- (char)0xff43, (char)0x0063, // Fullwidth Latin Small Letter C -> c
- (char)0xff44, (char)0x0064, // Fullwidth Latin Small Letter D -> d
- (char)0xff45, (char)0x0065, // Fullwidth Latin Small Letter E -> e
- (char)0xff46, (char)0x0066, // Fullwidth Latin Small Letter F -> f
- (char)0xff47, (char)0x0067, // Fullwidth Latin Small Letter G -> g
- (char)0xff48, (char)0x0068, // Fullwidth Latin Small Letter H -> h
- (char)0xff49, (char)0x0069, // Fullwidth Latin Small Letter I -> i
- (char)0xff4a, (char)0x006a, // Fullwidth Latin Small Letter J -> j
- (char)0xff4b, (char)0x006b, // Fullwidth Latin Small Letter K -> k
- (char)0xff4c, (char)0x006c, // Fullwidth Latin Small Letter L -> l
- (char)0xff4d, (char)0x006d, // Fullwidth Latin Small Letter M -> m
- (char)0xff4e, (char)0x006e, // Fullwidth Latin Small Letter N -> n
- (char)0xff4f, (char)0x006f, // Fullwidth Latin Small Letter O -> o
- (char)0xff50, (char)0x0070, // Fullwidth Latin Small Letter P -> p
- (char)0xff51, (char)0x0071, // Fullwidth Latin Small Letter Q -> q
- (char)0xff52, (char)0x0072, // Fullwidth Latin Small Letter R -> r
- (char)0xff53, (char)0x0073, // Fullwidth Latin Small Letter S -> s
- (char)0xff54, (char)0x0074, // Fullwidth Latin Small Letter T -> t
- (char)0xff55, (char)0x0075, // Fullwidth Latin Small Letter U -> u
- (char)0xff56, (char)0x0076, // Fullwidth Latin Small Letter V -> v
- (char)0xff57, (char)0x0077, // Fullwidth Latin Small Letter W -> w
- (char)0xff58, (char)0x0078, // Fullwidth Latin Small Letter X -> x
- (char)0xff59, (char)0x0079, // Fullwidth Latin Small Letter Y -> y
- (char)0xff5a, (char)0x007a, // Fullwidth Latin Small Letter Z -> z
- (char)0xff5b, (char)0x007b, // Fullwidth Left Curly Bracket -> {
- (char)0xff5c, (char)0x007c, // Fullwidth Vertical Line -> |
- (char)0xff5d, (char)0x007d, // Fullwidth Right Curly Bracket -> }
- (char)0xff5e, (char)0x007e // Fullwidth Tilde -> ~
- };
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/NormalizationForm.cs b/netcore/System.Private.CoreLib/shared/System/Text/NormalizationForm.cs
deleted file mode 100644
index 976756251a6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/NormalizationForm.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.Text
-{
- public enum NormalizationForm
- {
- FormC = 1,
- FormD = 2,
- FormKC = 5,
- FormKD = 6
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Rune.cs b/netcore/System.Private.CoreLib/shared/System/Text/Rune.cs
deleted file mode 100644
index b704f8440b6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Rune.cs
+++ /dev/null
@@ -1,1338 +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 System.Buffers;
-using System.Diagnostics;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Text.Unicode;
-
-namespace System.Text
-{
- /// <summary>
- /// Represents a Unicode scalar value ([ U+0000..U+D7FF ], inclusive; or [ U+E000..U+10FFFF ], inclusive).
- /// </summary>
- /// <remarks>
- /// This type's constructors and conversion operators validate the input, so consumers can call the APIs
- /// assuming that the underlying <see cref="Rune"/> instance is well-formed.
- /// </remarks>
- [DebuggerDisplay("{DebuggerDisplay,nq}")]
- public readonly struct Rune : IComparable<Rune>, IEquatable<Rune>
- {
- private const byte IsWhiteSpaceFlag = 0x80;
- private const byte IsLetterOrDigitFlag = 0x40;
- private const byte UnicodeCategoryMask = 0x1F;
-
- // Contains information about the ASCII character range [ U+0000..U+007F ], with:
- // - 0x80 bit if set means 'is whitespace'
- // - 0x40 bit if set means 'is letter or digit'
- // - 0x20 bit is reserved for future use
- // - bottom 5 bits are the UnicodeCategory of the character
- private static ReadOnlySpan<byte> AsciiCharInfo => new byte[]
- {
- 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x8E, 0x8E, 0x8E, 0x8E, 0x8E, 0x0E, 0x0E, // U+0000..U+000F
- 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, // U+0010..U+001F
- 0x8B, 0x18, 0x18, 0x18, 0x1A, 0x18, 0x18, 0x18, 0x14, 0x15, 0x18, 0x19, 0x18, 0x13, 0x18, 0x18, // U+0020..U+002F
- 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x18, 0x18, 0x19, 0x19, 0x19, 0x18, // U+0030..U+003F
- 0x18, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, // U+0040..U+004F
- 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x14, 0x18, 0x15, 0x1B, 0x12, // U+0050..U+005F
- 0x1B, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // U+0060..U+006F
- 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x14, 0x19, 0x15, 0x19, 0x0E, // U+0070..U+007F
- };
-
- private readonly uint _value;
-
- /// <summary>
- /// Creates a <see cref="Rune"/> from the provided UTF-16 code unit.
- /// </summary>
- /// <exception cref="ArgumentOutOfRangeException">
- /// If <paramref name="ch"/> represents a UTF-16 surrogate code point
- /// U+D800..U+DFFF, inclusive.
- /// </exception>
- public Rune(char ch)
- {
- uint expanded = ch;
- if (UnicodeUtility.IsSurrogateCodePoint(expanded))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.ch);
- }
- _value = expanded;
- }
-
- /// <summary>
- /// Creates a <see cref="Rune"/> from the provided UTF-16 surrogate pair.
- /// </summary>
- /// <exception cref="ArgumentOutOfRangeException">
- /// If <paramref name="highSurrogate"/> does not represent a UTF-16 high surrogate code point
- /// or <paramref name="lowSurrogate"/> does not represent a UTF-16 low surrogate code point.
- /// </exception>
- public Rune(char highSurrogate, char lowSurrogate)
- : this((uint)char.ConvertToUtf32(highSurrogate, lowSurrogate), false)
- {
- }
-
- /// <summary>
- /// Creates a <see cref="Rune"/> from the provided Unicode scalar value.
- /// </summary>
- /// <exception cref="ArgumentOutOfRangeException">
- /// If <paramref name="value"/> does not represent a value Unicode scalar value.
- /// </exception>
- public Rune(int value)
- : this((uint)value)
- {
- }
-
- /// <summary>
- /// Creates a <see cref="Rune"/> from the provided Unicode scalar value.
- /// </summary>
- /// <exception cref="ArgumentOutOfRangeException">
- /// If <paramref name="value"/> does not represent a value Unicode scalar value.
- /// </exception>
- [CLSCompliant(false)]
- public Rune(uint value)
- {
- if (!UnicodeUtility.IsValidUnicodeScalar(value))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- }
- _value = value;
- }
-
- // non-validating ctor
- private Rune(uint scalarValue, bool unused)
- {
- UnicodeDebug.AssertIsValidScalar(scalarValue);
- _value = scalarValue;
- }
-
- public static bool operator ==(Rune left, Rune right) => left._value == right._value;
-
- public static bool operator !=(Rune left, Rune right) => left._value != right._value;
-
- public static bool operator <(Rune left, Rune right) => left._value < right._value;
-
- public static bool operator <=(Rune left, Rune right) => left._value <= right._value;
-
- public static bool operator >(Rune left, Rune right) => left._value > right._value;
-
- public static bool operator >=(Rune left, Rune right) => left._value >= right._value;
-
- // Operators below are explicit because they may throw.
-
- public static explicit operator Rune(char ch) => new Rune(ch);
-
- [CLSCompliant(false)]
- public static explicit operator Rune(uint value) => new Rune(value);
-
- public static explicit operator Rune(int value) => new Rune(value);
-
- // Displayed as "'<char>' (U+XXXX)"; e.g., "'e' (U+0065)"
- private string DebuggerDisplay => FormattableString.Invariant($"U+{_value:X4} '{(IsValid(_value) ? ToString() : "\uFFFD")}'");
-
- /// <summary>
- /// Returns true if and only if this scalar value is ASCII ([ U+0000..U+007F ])
- /// and therefore representable by a single UTF-8 code unit.
- /// </summary>
- public bool IsAscii => UnicodeUtility.IsAsciiCodePoint(_value);
-
- /// <summary>
- /// Returns true if and only if this scalar value is within the BMP ([ U+0000..U+FFFF ])
- /// and therefore representable by a single UTF-16 code unit.
- /// </summary>
- public bool IsBmp => UnicodeUtility.IsBmpCodePoint(_value);
-
- /// <summary>
- /// Returns the Unicode plane (0 to 16, inclusive) which contains this scalar.
- /// </summary>
- public int Plane => UnicodeUtility.GetPlane(_value);
-
- /// <summary>
- /// A <see cref="Rune"/> instance that represents the Unicode replacement character U+FFFD.
- /// </summary>
- public static Rune ReplacementChar => UnsafeCreate(UnicodeUtility.ReplacementChar);
-
- /// <summary>
- /// Returns the length in code units (<see cref="char"/>) of the
- /// UTF-16 sequence required to represent this scalar value.
- /// </summary>
- /// <remarks>
- /// The return value will be 1 or 2.
- /// </remarks>
- public int Utf16SequenceLength => UnicodeUtility.GetUtf16SequenceLength(_value);
-
- /// <summary>
- /// Returns the length in code units of the
- /// UTF-8 sequence required to represent this scalar value.
- /// </summary>
- /// <remarks>
- /// The return value will be 1 through 4, inclusive.
- /// </remarks>
- public int Utf8SequenceLength => UnicodeUtility.GetUtf8SequenceLength(_value);
-
- /// <summary>
- /// Returns the Unicode scalar value as an integer.
- /// </summary>
- public int Value => (int)_value;
-
- private static Rune ChangeCaseCultureAware(Rune rune, TextInfo textInfo, bool toUpper)
- {
- Debug.Assert(!GlobalizationMode.Invariant, "This should've been checked by the caller.");
- Debug.Assert(textInfo != null, "This should've been checked by the caller.");
-
- Span<char> original = stackalloc char[2]; // worst case scenario = 2 code units (for a surrogate pair)
- Span<char> modified = stackalloc char[2]; // case change should preserve UTF-16 code unit count
-
- int charCount = rune.EncodeToUtf16(original);
- original = original.Slice(0, charCount);
- modified = modified.Slice(0, charCount);
-
- if (toUpper)
- {
- textInfo.ChangeCaseToUpper(original, modified);
- }
- else
- {
- textInfo.ChangeCaseToLower(original, modified);
- }
-
- // We use simple case folding rules, which disallows moving between the BMP and supplementary
- // planes when performing a case conversion. The helper methods which reconstruct a Rune
- // contain debug asserts for this condition.
-
- if (rune.IsBmp)
- {
- return UnsafeCreate(modified[0]);
- }
- else
- {
- return UnsafeCreate(UnicodeUtility.GetScalarFromUtf16SurrogatePair(modified[0], modified[1]));
- }
- }
-
- public int CompareTo(Rune other) => this._value.CompareTo(other._value);
-
- /// <summary>
- /// Decodes the <see cref="Rune"/> at the beginning of the provided UTF-16 source buffer.
- /// </summary>
- /// <returns>
- /// <para>
- /// If the source buffer begins with a valid UTF-16 encoded scalar value, returns <see cref="OperationStatus.Done"/>,
- /// and outs via <paramref name="result"/> the decoded <see cref="Rune"/> and via <paramref name="charsConsumed"/> the
- /// number of <see langword="char"/>s used in the input buffer to encode the <see cref="Rune"/>.
- /// </para>
- /// <para>
- /// If the source buffer is empty or contains only a standalone UTF-16 high surrogate character, returns <see cref="OperationStatus.NeedMoreData"/>,
- /// and outs via <paramref name="result"/> <see cref="ReplacementChar"/> and via <paramref name="charsConsumed"/> the length of the input buffer.
- /// </para>
- /// <para>
- /// If the source buffer begins with an ill-formed UTF-16 encoded scalar value, returns <see cref="OperationStatus.InvalidData"/>,
- /// and outs via <paramref name="result"/> <see cref="ReplacementChar"/> and via <paramref name="charsConsumed"/> the number of
- /// <see langword="char"/>s used in the input buffer to encode the ill-formed sequence.
- /// </para>
- /// </returns>
- /// <remarks>
- /// The general calling convention is to call this method in a loop, slicing the <paramref name="source"/> buffer by
- /// <paramref name="charsConsumed"/> elements on each iteration of the loop. On each iteration of the loop <paramref name="result"/>
- /// will contain the real scalar value if successfully decoded, or it will contain <see cref="ReplacementChar"/> if
- /// the data could not be successfully decoded. This pattern provides convenient automatic U+FFFD substitution of
- /// invalid sequences while iterating through the loop.
- /// </remarks>
- public static OperationStatus DecodeFromUtf16(ReadOnlySpan<char> source, out Rune result, out int charsConsumed)
- {
- if (!source.IsEmpty)
- {
- // First, check for the common case of a BMP scalar value.
- // If this is correct, return immediately.
-
- char firstChar = source[0];
- if (TryCreate(firstChar, out result))
- {
- charsConsumed = 1;
- return OperationStatus.Done;
- }
-
- // First thing we saw was a UTF-16 surrogate code point.
- // Let's optimistically assume for now it's a high surrogate and hope
- // that combining it with the next char yields useful results.
-
- if (1 < (uint)source.Length)
- {
- char secondChar = source[1];
- if (TryCreate(firstChar, secondChar, out result))
- {
- // Success! Formed a supplementary scalar value.
- charsConsumed = 2;
- return OperationStatus.Done;
- }
- else
- {
- // Either the first character was a low surrogate, or the second
- // character was not a low surrogate. This is an error.
- goto InvalidData;
- }
- }
- else if (!char.IsHighSurrogate(firstChar))
- {
- // Quick check to make sure we're not going to report NeedMoreData for
- // a single-element buffer where the data is a standalone low surrogate
- // character. Since no additional data will ever make this valid, we'll
- // report an error immediately.
- goto InvalidData;
- }
- }
-
- // If we got to this point, the input buffer was empty, or the buffer
- // was a single element in length and that element was a high surrogate char.
-
- charsConsumed = source.Length;
- result = ReplacementChar;
- return OperationStatus.NeedMoreData;
-
- InvalidData:
-
- charsConsumed = 1; // maximal invalid subsequence for UTF-16 is always a single code unit in length
- result = ReplacementChar;
- return OperationStatus.InvalidData;
- }
-
- /// <summary>
- /// Decodes the <see cref="Rune"/> at the beginning of the provided UTF-8 source buffer.
- /// </summary>
- /// <returns>
- /// <para>
- /// If the source buffer begins with a valid UTF-8 encoded scalar value, returns <see cref="OperationStatus.Done"/>,
- /// and outs via <paramref name="result"/> the decoded <see cref="Rune"/> and via <paramref name="bytesConsumed"/> the
- /// number of <see langword="byte"/>s used in the input buffer to encode the <see cref="Rune"/>.
- /// </para>
- /// <para>
- /// If the source buffer is empty or contains only a standalone UTF-8 high surrogate character, returns <see cref="OperationStatus.NeedMoreData"/>,
- /// and outs via <paramref name="result"/> <see cref="ReplacementChar"/> and via <paramref name="bytesConsumed"/> the length of the input buffer.
- /// </para>
- /// <para>
- /// If the source buffer begins with an ill-formed UTF-8 encoded scalar value, returns <see cref="OperationStatus.InvalidData"/>,
- /// and outs via <paramref name="result"/> <see cref="ReplacementChar"/> and via <paramref name="bytesConsumed"/> the number of
- /// <see langword="char"/>s used in the input buffer to encode the ill-formed sequence.
- /// </para>
- /// </returns>
- /// <remarks>
- /// The general calling convention is to call this method in a loop, slicing the <paramref name="source"/> buffer by
- /// <paramref name="bytesConsumed"/> elements on each iteration of the loop. On each iteration of the loop <paramref name="result"/>
- /// will contain the real scalar value if successfully decoded, or it will contain <see cref="ReplacementChar"/> if
- /// the data could not be successfully decoded. This pattern provides convenient automatic U+FFFD substitution of
- /// invalid sequences while iterating through the loop.
- /// </remarks>
- public static OperationStatus DecodeFromUtf8(ReadOnlySpan<byte> source, out Rune result, out int bytesConsumed)
- {
- // This method follows the Unicode Standard's recommendation for detecting
- // the maximal subpart of an ill-formed subsequence. See The Unicode Standard,
- // Ch. 3.9 for more details. In summary, when reporting an invalid subsequence,
- // it tries to consume as many code units as possible as long as those code
- // units constitute the beginning of a longer well-formed subsequence per Table 3-7.
-
- int index = 0;
-
- // Try reading input[0].
-
- if ((uint)index >= (uint)source.Length)
- {
- goto NeedsMoreData;
- }
-
- uint tempValue = source[index];
- if (!UnicodeUtility.IsAsciiCodePoint(tempValue))
- {
- goto NotAscii;
- }
-
- Finish:
-
- bytesConsumed = index + 1;
- Debug.Assert(1 <= bytesConsumed && bytesConsumed <= 4); // Valid subsequences are always length [1..4]
- result = UnsafeCreate(tempValue);
- return OperationStatus.Done;
-
- NotAscii:
-
- // Per Table 3-7, the beginning of a multibyte sequence must be a code unit in
- // the range [C2..F4]. If it's outside of that range, it's either a standalone
- // continuation byte, or it's an overlong two-byte sequence, or it's an out-of-range
- // four-byte sequence.
-
- if (!UnicodeUtility.IsInRangeInclusive(tempValue, 0xC2, 0xF4))
- {
- goto FirstByteInvalid;
- }
-
- tempValue = (tempValue - 0xC2) << 6;
-
- // Try reading input[1].
-
- index++;
- if ((uint)index >= (uint)source.Length)
- {
- goto NeedsMoreData;
- }
-
- // Continuation bytes are of the form [10xxxxxx], which means that their two's
- // complement representation is in the range [-65..-128]. This allows us to
- // perform a single comparison to see if a byte is a continuation byte.
-
- int thisByteSignExtended = (sbyte)source[index];
- if (thisByteSignExtended >= -64)
- {
- goto Invalid;
- }
-
- tempValue += (uint)thisByteSignExtended;
- tempValue += 0x80; // remove the continuation byte marker
- tempValue += (0xC2 - 0xC0) << 6; // remove the leading byte marker
-
- if (tempValue < 0x0800)
- {
- Debug.Assert(UnicodeUtility.IsInRangeInclusive(tempValue, 0x0080, 0x07FF));
- goto Finish; // this is a valid 2-byte sequence
- }
-
- // This appears to be a 3- or 4-byte sequence. Since per Table 3-7 we now have
- // enough information (from just two code units) to detect overlong or surrogate
- // sequences, we need to perform these checks now.
-
- if (!UnicodeUtility.IsInRangeInclusive(tempValue, ((0xE0 - 0xC0) << 6) + (0xA0 - 0x80), ((0xF4 - 0xC0) << 6) + (0x8F - 0x80)))
- {
- // The first two bytes were not in the range [[E0 A0]..[F4 8F]].
- // This is an overlong 3-byte sequence or an out-of-range 4-byte sequence.
- goto Invalid;
- }
-
- if (UnicodeUtility.IsInRangeInclusive(tempValue, ((0xED - 0xC0) << 6) + (0xA0 - 0x80), ((0xED - 0xC0) << 6) + (0xBF - 0x80)))
- {
- // This is a UTF-16 surrogate code point, which is invalid in UTF-8.
- goto Invalid;
- }
-
- if (UnicodeUtility.IsInRangeInclusive(tempValue, ((0xF0 - 0xC0) << 6) + (0x80 - 0x80), ((0xF0 - 0xC0) << 6) + (0x8F - 0x80)))
- {
- // This is an overlong 4-byte sequence.
- goto Invalid;
- }
-
- // The first two bytes were just fine. We don't need to perform any other checks
- // on the remaining bytes other than to see that they're valid continuation bytes.
-
- // Try reading input[2].
-
- index++;
- if ((uint)index >= (uint)source.Length)
- {
- goto NeedsMoreData;
- }
-
- thisByteSignExtended = (sbyte)source[index];
- if (thisByteSignExtended >= -64)
- {
- goto Invalid; // this byte is not a UTF-8 continuation byte
- }
-
- tempValue <<= 6;
- tempValue += (uint)thisByteSignExtended;
- tempValue += 0x80; // remove the continuation byte marker
- tempValue -= (0xE0 - 0xC0) << 12; // remove the leading byte marker
-
- if (tempValue <= 0xFFFF)
- {
- Debug.Assert(UnicodeUtility.IsInRangeInclusive(tempValue, 0x0800, 0xFFFF));
- goto Finish; // this is a valid 3-byte sequence
- }
-
- // Try reading input[3].
-
- index++;
- if ((uint)index >= (uint)source.Length)
- {
- goto NeedsMoreData;
- }
-
- thisByteSignExtended = (sbyte)source[index];
- if (thisByteSignExtended >= -64)
- {
- goto Invalid; // this byte is not a UTF-8 continuation byte
- }
-
- tempValue <<= 6;
- tempValue += (uint)thisByteSignExtended;
- tempValue += 0x80; // remove the continuation byte marker
- tempValue -= (0xF0 - 0xE0) << 18; // remove the leading byte marker
-
- UnicodeDebug.AssertIsValidSupplementaryPlaneScalar(tempValue);
- goto Finish; // this is a valid 4-byte sequence
-
- FirstByteInvalid:
-
- index = 1; // Invalid subsequences are always at least length 1.
-
- Invalid:
-
- Debug.Assert(1 <= index && index <= 3); // Invalid subsequences are always length 1..3
- bytesConsumed = index;
- result = ReplacementChar;
- return OperationStatus.InvalidData;
-
- NeedsMoreData:
-
- Debug.Assert(0 <= index && index <= 3); // Incomplete subsequences are always length 0..3
- bytesConsumed = index;
- result = ReplacementChar;
- return OperationStatus.NeedMoreData;
- }
-
- /// <summary>
- /// Decodes the <see cref="Rune"/> at the end of the provided UTF-16 source buffer.
- /// </summary>
- /// <remarks>
- /// This method is very similar to <see cref="DecodeFromUtf16(ReadOnlySpan{char}, out Rune, out int)"/>, but it allows
- /// the caller to loop backward instead of forward. The typical calling convention is that on each iteration
- /// of the loop, the caller should slice off the final <paramref name="charsConsumed"/> elements of
- /// the <paramref name="source"/> buffer.
- /// </remarks>
- public static OperationStatus DecodeLastFromUtf16(ReadOnlySpan<char> source, out Rune result, out int charsConsumed)
- {
- int index = source.Length - 1;
- if ((uint)index < (uint)source.Length)
- {
- // First, check for the common case of a BMP scalar value.
- // If this is correct, return immediately.
-
- char finalChar = source[index];
- if (TryCreate(finalChar, out result))
- {
- charsConsumed = 1;
- return OperationStatus.Done;
- }
-
- if (char.IsLowSurrogate(finalChar))
- {
- // The final character was a UTF-16 low surrogate code point.
- // This must be preceded by a UTF-16 high surrogate code point, otherwise
- // we have a standalone low surrogate, which is always invalid.
-
- index--;
- if ((uint)index < (uint)source.Length)
- {
- char penultimateChar = source[index];
- if (TryCreate(penultimateChar, finalChar, out result))
- {
- // Success! Formed a supplementary scalar value.
- charsConsumed = 2;
- return OperationStatus.Done;
- }
- }
-
- // If we got to this point, we saw a standalone low surrogate
- // and must report an error.
-
- charsConsumed = 1; // standalone surrogate
- result = ReplacementChar;
- return OperationStatus.InvalidData;
- }
- }
-
- // If we got this far, the source buffer was empty, or the source buffer ended
- // with a UTF-16 high surrogate code point. These aren't errors since they could
- // be valid given more input data.
-
- charsConsumed = (int)((uint)(-source.Length) >> 31); // 0 -> 0, all other lengths -> 1
- result = ReplacementChar;
- return OperationStatus.NeedMoreData;
- }
-
- /// <summary>
- /// Decodes the <see cref="Rune"/> at the end of the provided UTF-8 source buffer.
- /// </summary>
- /// <remarks>
- /// This method is very similar to <see cref="DecodeFromUtf8(ReadOnlySpan{byte}, out Rune, out int)"/>, but it allows
- /// the caller to loop backward instead of forward. The typical calling convention is that on each iteration
- /// of the loop, the caller should slice off the final <paramref name="bytesConsumed"/> elements of
- /// the <paramref name="source"/> buffer.
- /// </remarks>
- public static OperationStatus DecodeLastFromUtf8(ReadOnlySpan<byte> source, out Rune value, out int bytesConsumed)
- {
- int index = source.Length - 1;
- if ((uint)index < (uint)source.Length)
- {
- // The buffer contains at least one byte. Let's check the fast case where the
- // buffer ends with an ASCII byte.
-
- uint tempValue = source[index];
- if (UnicodeUtility.IsAsciiCodePoint(tempValue))
- {
- bytesConsumed = 1;
- value = UnsafeCreate(tempValue);
- return OperationStatus.Done;
- }
-
- // If the final byte is not an ASCII byte, we may be beginning or in the middle of
- // a UTF-8 multi-code unit sequence. We need to back up until we see the start of
- // the multi-code unit sequence; we can detect the leading byte because all multi-byte
- // sequences begin with a byte whose 0x40 bit is set. Since all multi-byte sequences
- // are no greater than 4 code units in length, we only need to search back a maximum
- // of four bytes.
-
- if (((byte)tempValue & 0x40) != 0)
- {
- // This is a UTF-8 leading byte. We'll do a forward read from here.
- // It'll return invalid (if given C0, F5, etc.) or incomplete. Both are fine.
-
- return DecodeFromUtf8(source.Slice(index), out value, out bytesConsumed);
- }
-
- // If we got to this point, the final byte was a UTF-8 continuation byte.
- // Let's check the three bytes immediately preceding this, looking for the starting byte.
-
- for (int i = 3; i > 0; i--)
- {
- index--;
- if ((uint)index >= (uint)source.Length)
- {
- goto Invalid; // out of data
- }
-
- // The check below will get hit for ASCII (values 00..7F) and for UTF-8 starting bytes
- // (bits 0xC0 set, values C0..FF). In two's complement this is the range [-64..127].
- // It's just a fast way for us to terminate the search.
-
- if ((sbyte)source[index] >= -64)
- {
- goto ForwardDecode;
- }
- }
-
- Invalid:
-
- // If we got to this point, either:
- // - the last 4 bytes of the input buffer are continuation bytes;
- // - the entire input buffer (if fewer than 4 bytes) consists only of continuation bytes; or
- // - there's no UTF-8 leading byte between the final continuation byte of the buffer and
- // the previous well-formed subsequence or maximal invalid subsequence.
- //
- // In all of these cases, the final byte must be a maximal invalid subsequence of length 1.
- // See comment near the end of this method for more information.
-
- value = ReplacementChar;
- bytesConsumed = 1;
- return OperationStatus.InvalidData;
-
- ForwardDecode:
-
- // If we got to this point, we found an ASCII byte or a UTF-8 starting byte at position source[index].
- // Technically this could also mean we found an invalid byte like C0 or F5 at this position, but that's
- // fine since it'll be handled by the forward read. From this position, we'll perform a forward read
- // and see if we consumed the entirety of the buffer.
-
- source = source.Slice(index);
- Debug.Assert(!source.IsEmpty, "Shouldn't reach this for empty inputs.");
-
- OperationStatus operationStatus = DecodeFromUtf8(source, out Rune tempRune, out int tempBytesConsumed);
- if (tempBytesConsumed == source.Length)
- {
- // If this forward read consumed the entirety of the end of the input buffer, we can return it
- // as the result of this function. It could be well-formed, incomplete, or invalid. If it's
- // invalid and we consumed the remainder of the buffer, we know we've found the maximal invalid
- // subsequence, which is what we wanted anyway.
-
- bytesConsumed = tempBytesConsumed;
- value = tempRune;
- return operationStatus;
- }
-
- // If we got to this point, we know that the final continuation byte wasn't consumed by the forward
- // read that we just performed above. This means that the continuation byte has to be part of an
- // invalid subsequence since there's no UTF-8 leading byte between what we just consumed and the
- // continuation byte at the end of the input. Furthermore, since any maximal invalid subsequence
- // of length > 1 must have a UTF-8 leading byte as its first code unit, this implies that the
- // continuation byte at the end of the buffer is itself a maximal invalid subsequence of length 1.
-
- goto Invalid;
- }
- else
- {
- // Source buffer was empty.
- value = ReplacementChar;
- bytesConsumed = 0;
- return OperationStatus.NeedMoreData;
- }
- }
-
- /// <summary>
- /// Encodes this <see cref="Rune"/> to a UTF-16 destination buffer.
- /// </summary>
- /// <param name="destination">The buffer to which to write this value as UTF-16.</param>
- /// <returns>The number of <see cref="char"/>s written to <paramref name="destination"/>.</returns>
- /// <exception cref="ArgumentException">
- /// If <paramref name="destination"/> is not large enough to hold the output.
- /// </exception>
- public int EncodeToUtf16(Span<char> destination)
- {
- if (!TryEncodeToUtf16(destination, out int charsWritten))
- {
- ThrowHelper.ThrowArgumentException_DestinationTooShort();
- }
-
- return charsWritten;
- }
-
- /// <summary>
- /// Encodes this <see cref="Rune"/> to a UTF-8 destination buffer.
- /// </summary>
- /// <param name="destination">The buffer to which to write this value as UTF-8.</param>
- /// <returns>The number of <see cref="byte"/>s written to <paramref name="destination"/>.</returns>
- /// <exception cref="ArgumentException">
- /// If <paramref name="destination"/> is not large enough to hold the output.
- /// </exception>
- public int EncodeToUtf8(Span<byte> destination)
- {
- if (!TryEncodeToUtf8(destination, out int bytesWritten))
- {
- ThrowHelper.ThrowArgumentException_DestinationTooShort();
- }
-
- return bytesWritten;
- }
-
- public override bool Equals(object? obj) => (obj is Rune other) && this.Equals(other);
-
- public bool Equals(Rune other) => this == other;
-
- public override int GetHashCode() => Value;
-
- /// <summary>
- /// Gets the <see cref="Rune"/> which begins at index <paramref name="index"/> in
- /// string <paramref name="input"/>.
- /// </summary>
- /// <remarks>
- /// Throws if <paramref name="input"/> is null, if <paramref name="index"/> is out of range, or
- /// if <paramref name="index"/> does not reference the start of a valid scalar value within <paramref name="input"/>.
- /// </remarks>
- public static Rune GetRuneAt(string input, int index)
- {
- int runeValue = ReadRuneFromString(input, index);
- if (runeValue < 0)
- {
- ThrowHelper.ThrowArgumentException_CannotExtractScalar(ExceptionArgument.index);
- }
-
- return UnsafeCreate((uint)runeValue);
- }
-
- /// <summary>
- /// Returns <see langword="true"/> iff <paramref name="value"/> is a valid Unicode scalar
- /// value, i.e., is in [ U+0000..U+D7FF ], inclusive; or [ U+E000..U+10FFFF ], inclusive.
- /// </summary>
- public static bool IsValid(int value) => IsValid((uint)value);
-
- /// <summary>
- /// Returns <see langword="true"/> iff <paramref name="value"/> is a valid Unicode scalar
- /// value, i.e., is in [ U+0000..U+D7FF ], inclusive; or [ U+E000..U+10FFFF ], inclusive.
- /// </summary>
- [CLSCompliant(false)]
- public static bool IsValid(uint value) => UnicodeUtility.IsValidUnicodeScalar(value);
-
- // returns a negative number on failure
- internal static int ReadFirstRuneFromUtf16Buffer(ReadOnlySpan<char> input)
- {
- if (input.IsEmpty)
- {
- return -1;
- }
-
- // Optimistically assume input is within BMP.
-
- uint returnValue = input[0];
- if (UnicodeUtility.IsSurrogateCodePoint(returnValue))
- {
- if (!UnicodeUtility.IsHighSurrogateCodePoint(returnValue))
- {
- return -1;
- }
-
- // Treat 'returnValue' as the high surrogate.
-
- if (1 >= (uint)input.Length)
- {
- return -1; // not an argument exception - just a "bad data" failure
- }
-
- uint potentialLowSurrogate = input[1];
- if (!UnicodeUtility.IsLowSurrogateCodePoint(potentialLowSurrogate))
- {
- return -1;
- }
-
- returnValue = UnicodeUtility.GetScalarFromUtf16SurrogatePair(returnValue, potentialLowSurrogate);
- }
-
- return (int)returnValue;
- }
-
- // returns a negative number on failure
- private static int ReadRuneFromString(string input, int index)
- {
- if (input is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
- }
-
- if ((uint)index >= (uint)input!.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
- }
-
- // Optimistically assume input is within BMP.
-
- uint returnValue = input[index];
- if (UnicodeUtility.IsSurrogateCodePoint(returnValue))
- {
- if (!UnicodeUtility.IsHighSurrogateCodePoint(returnValue))
- {
- return -1;
- }
-
- // Treat 'returnValue' as the high surrogate.
- //
- // If this becomes a hot code path, we can skip the below bounds check by reading
- // off the end of the string using unsafe code. Since strings are null-terminated,
- // we're guaranteed not to read a valid low surrogate, so we'll fail correctly if
- // the string terminates unexpectedly.
-
- index++;
- if ((uint)index >= (uint)input.Length)
- {
- return -1; // not an argument exception - just a "bad data" failure
- }
-
- uint potentialLowSurrogate = input[index];
- if (!UnicodeUtility.IsLowSurrogateCodePoint(potentialLowSurrogate))
- {
- return -1;
- }
-
- returnValue = UnicodeUtility.GetScalarFromUtf16SurrogatePair(returnValue, potentialLowSurrogate);
- }
-
- return (int)returnValue;
- }
-
- /// <summary>
- /// Returns a <see cref="string"/> representation of this <see cref="Rune"/> instance.
- /// </summary>
- public override string ToString()
- {
- if (IsBmp)
- {
- return string.CreateFromChar((char)_value);
- }
- else
- {
- UnicodeUtility.GetUtf16SurrogatesFromSupplementaryPlaneScalar(_value, out char high, out char low);
- return string.CreateFromChar(high, low);
- }
- }
-
- /// <summary>
- /// Attempts to create a <see cref="Rune"/> from the provided input value.
- /// </summary>
- public static bool TryCreate(char ch, out Rune result)
- {
- uint extendedValue = ch;
- if (!UnicodeUtility.IsSurrogateCodePoint(extendedValue))
- {
- result = UnsafeCreate(extendedValue);
- return true;
- }
- else
- {
- result = default;
- return false;
- }
- }
-
- /// <summary>
- /// Attempts to create a <see cref="Rune"/> from the provided UTF-16 surrogate pair.
- /// Returns <see langword="false"/> if the input values don't represent a well-formed UTF-16surrogate pair.
- /// </summary>
- public static bool TryCreate(char highSurrogate, char lowSurrogate, out Rune result)
- {
- // First, extend both to 32 bits, then calculate the offset of
- // each candidate surrogate char from the start of its range.
-
- uint highSurrogateOffset = (uint)highSurrogate - CharUnicodeInfo.HIGH_SURROGATE_START;
- uint lowSurrogateOffset = (uint)lowSurrogate - CharUnicodeInfo.LOW_SURROGATE_START;
-
- // This is a single comparison which allows us to check both for validity at once since
- // both the high surrogate range and the low surrogate range are the same length.
- // If the comparison fails, we call to a helper method to throw the correct exception message.
-
- if ((highSurrogateOffset | lowSurrogateOffset) <= CharUnicodeInfo.HIGH_SURROGATE_RANGE)
- {
- // The 0x40u << 10 below is to account for uuuuu = wwww + 1 in the surrogate encoding.
- result = UnsafeCreate((highSurrogateOffset << 10) + ((uint)lowSurrogate - CharUnicodeInfo.LOW_SURROGATE_START) + (0x40u << 10));
- return true;
- }
- else
- {
- // Didn't have a high surrogate followed by a low surrogate.
- result = default;
- return false;
- }
- }
-
- /// <summary>
- /// Attempts to create a <see cref="Rune"/> from the provided input value.
- /// </summary>
- public static bool TryCreate(int value, out Rune result) => TryCreate((uint)value, out result);
-
- /// <summary>
- /// Attempts to create a <see cref="Rune"/> from the provided input value.
- /// </summary>
- [CLSCompliant(false)]
- public static bool TryCreate(uint value, out Rune result)
- {
- if (UnicodeUtility.IsValidUnicodeScalar(value))
- {
- result = UnsafeCreate(value);
- return true;
- }
- else
- {
- result = default;
- return false;
- }
- }
-
- /// <summary>
- /// Encodes this <see cref="Rune"/> to a UTF-16 destination buffer.
- /// </summary>
- /// <param name="destination">The buffer to which to write this value as UTF-16.</param>
- /// <param name="charsWritten">
- /// The number of <see cref="char"/>s written to <paramref name="destination"/>,
- /// or 0 if the destination buffer is not large enough to contain the output.</param>
- /// <returns>True if the value was written to the buffer; otherwise, false.</returns>
- /// <remarks>
- /// The <see cref="Utf16SequenceLength"/> property can be queried ahead of time to determine
- /// the required size of the <paramref name="destination"/> buffer.
- /// </remarks>
- public bool TryEncodeToUtf16(Span<char> destination, out int charsWritten)
- {
- if (destination.Length >= 1)
- {
- if (IsBmp)
- {
- destination[0] = (char)_value;
- charsWritten = 1;
- return true;
- }
- else if (destination.Length >= 2)
- {
- UnicodeUtility.GetUtf16SurrogatesFromSupplementaryPlaneScalar(_value, out destination[0], out destination[1]);
- charsWritten = 2;
- return true;
- }
- }
-
- // Destination buffer not large enough
-
- charsWritten = default;
- return false;
- }
-
- /// <summary>
- /// Encodes this <see cref="Rune"/> to a destination buffer as UTF-8 bytes.
- /// </summary>
- /// <param name="destination">The buffer to which to write this value as UTF-8.</param>
- /// <param name="bytesWritten">
- /// The number of <see cref="byte"/>s written to <paramref name="destination"/>,
- /// or 0 if the destination buffer is not large enough to contain the output.</param>
- /// <returns>True if the value was written to the buffer; otherwise, false.</returns>
- /// <remarks>
- /// The <see cref="Utf8SequenceLength"/> property can be queried ahead of time to determine
- /// the required size of the <paramref name="destination"/> buffer.
- /// </remarks>
- public bool TryEncodeToUtf8(Span<byte> destination, out int bytesWritten)
- {
- // The bit patterns below come from the Unicode Standard, Table 3-6.
-
- if (destination.Length >= 1)
- {
- if (IsAscii)
- {
- destination[0] = (byte)_value;
- bytesWritten = 1;
- return true;
- }
-
- if (destination.Length >= 2)
- {
- if (_value <= 0x7FFu)
- {
- // Scalar 00000yyy yyxxxxxx -> bytes [ 110yyyyy 10xxxxxx ]
- destination[0] = (byte)((_value + (0b110u << 11)) >> 6);
- destination[1] = (byte)((_value & 0x3Fu) + 0x80u);
- bytesWritten = 2;
- return true;
- }
-
- if (destination.Length >= 3)
- {
- if (_value <= 0xFFFFu)
- {
- // Scalar zzzzyyyy yyxxxxxx -> bytes [ 1110zzzz 10yyyyyy 10xxxxxx ]
- destination[0] = (byte)((_value + (0b1110 << 16)) >> 12);
- destination[1] = (byte)(((_value & (0x3Fu << 6)) >> 6) + 0x80u);
- destination[2] = (byte)((_value & 0x3Fu) + 0x80u);
- bytesWritten = 3;
- return true;
- }
-
- if (destination.Length >= 4)
- {
- // Scalar 000uuuuu zzzzyyyy yyxxxxxx -> bytes [ 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx ]
- destination[0] = (byte)((_value + (0b11110 << 21)) >> 18);
- destination[1] = (byte)(((_value & (0x3Fu << 12)) >> 12) + 0x80u);
- destination[2] = (byte)(((_value & (0x3Fu << 6)) >> 6) + 0x80u);
- destination[3] = (byte)((_value & 0x3Fu) + 0x80u);
- bytesWritten = 4;
- return true;
- }
- }
- }
- }
-
- // Destination buffer not large enough
-
- bytesWritten = default;
- return false;
- }
-
- /// <summary>
- /// Attempts to get the <see cref="Rune"/> which begins at index <paramref name="index"/> in
- /// string <paramref name="input"/>.
- /// </summary>
- /// <returns><see langword="true"/> if a scalar value was successfully extracted from the specified index,
- /// <see langword="false"/> if a value could not be extracted due to invalid data.</returns>
- /// <remarks>
- /// Throws only if <paramref name="input"/> is null or <paramref name="index"/> is out of range.
- /// </remarks>
- public static bool TryGetRuneAt(string input, int index, out Rune value)
- {
- int runeValue = ReadRuneFromString(input, index);
- if (runeValue >= 0)
- {
- value = UnsafeCreate((uint)runeValue);
- return true;
- }
- else
- {
- value = default;
- return false;
- }
- }
-
- // Allows constructing a Unicode scalar value from an arbitrary 32-bit integer without
- // validation. It is the caller's responsibility to have performed manual validation
- // before calling this method. If a Rune instance is forcibly constructed
- // from invalid input, the APIs on this type have undefined behavior, potentially including
- // introducing a security hole in the consuming application.
- //
- // An example of a security hole resulting from an invalid Rune value, which could result
- // in a stack overflow.
- //
- // public int GetMarvin32HashCode(Rune r) {
- // Span<char> buffer = stackalloc char[r.Utf16SequenceLength];
- // r.TryEncode(buffer, ...);
- // return Marvin32.ComputeHash(buffer.AsBytes());
- // }
-
- /// <summary>
- /// Creates a <see cref="Rune"/> without performing validation on the input.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static Rune UnsafeCreate(uint scalarValue) => new Rune(scalarValue, false);
-
- // These are analogs of APIs on System.Char
-
- public static double GetNumericValue(Rune value)
- {
- if (value.IsAscii)
- {
- uint baseNum = value._value - '0';
- return (baseNum <= 9) ? (double)baseNum : -1;
- }
- else
- {
- // not an ASCII char; fall back to globalization table
- return CharUnicodeInfo.InternalGetNumericValue(value.Value);
- }
- }
-
- public static UnicodeCategory GetUnicodeCategory(Rune value)
- {
- if (value.IsAscii)
- {
- return (UnicodeCategory)(AsciiCharInfo[value.Value] & UnicodeCategoryMask);
- }
- else
- {
- return GetUnicodeCategoryNonAscii(value);
- }
- }
-
- private static UnicodeCategory GetUnicodeCategoryNonAscii(Rune value)
- {
- Debug.Assert(!value.IsAscii, "Shouldn't use this non-optimized code path for ASCII characters.");
- return CharUnicodeInfo.GetUnicodeCategory(value.Value);
- }
-
- // Returns true iff this Unicode category represents a letter
- private static bool IsCategoryLetter(UnicodeCategory category)
- {
- return UnicodeUtility.IsInRangeInclusive((uint)category, (uint)UnicodeCategory.UppercaseLetter, (uint)UnicodeCategory.OtherLetter);
- }
-
- // Returns true iff this Unicode category represents a letter or a decimal digit
- private static bool IsCategoryLetterOrDecimalDigit(UnicodeCategory category)
- {
- return UnicodeUtility.IsInRangeInclusive((uint)category, (uint)UnicodeCategory.UppercaseLetter, (uint)UnicodeCategory.OtherLetter)
- || (category == UnicodeCategory.DecimalDigitNumber);
- }
-
- // Returns true iff this Unicode category represents a number
- private static bool IsCategoryNumber(UnicodeCategory category)
- {
- return UnicodeUtility.IsInRangeInclusive((uint)category, (uint)UnicodeCategory.DecimalDigitNumber, (uint)UnicodeCategory.OtherNumber);
- }
-
- // Returns true iff this Unicode category represents a punctuation mark
- private static bool IsCategoryPunctuation(UnicodeCategory category)
- {
- return UnicodeUtility.IsInRangeInclusive((uint)category, (uint)UnicodeCategory.ConnectorPunctuation, (uint)UnicodeCategory.OtherPunctuation);
- }
-
- // Returns true iff this Unicode category represents a separator
- private static bool IsCategorySeparator(UnicodeCategory category)
- {
- return UnicodeUtility.IsInRangeInclusive((uint)category, (uint)UnicodeCategory.SpaceSeparator, (uint)UnicodeCategory.ParagraphSeparator);
- }
-
- // Returns true iff this Unicode category represents a symbol
- private static bool IsCategorySymbol(UnicodeCategory category)
- {
- return UnicodeUtility.IsInRangeInclusive((uint)category, (uint)UnicodeCategory.MathSymbol, (uint)UnicodeCategory.OtherSymbol);
- }
-
- public static bool IsControl(Rune value)
- {
- // Per the Unicode stability policy, the set of control characters
- // is forever fixed at [ U+0000..U+001F ], [ U+007F..U+009F ]. No
- // characters will ever be added to the "control characters" group.
- // See http://www.unicode.org/policies/stability_policy.html.
-
- // Logic below depends on Rune.Value never being -1 (since Rune is a validating type)
- // 00..1F (+1) => 01..20 (&~80) => 01..20
- // 7F..9F (+1) => 80..A0 (&~80) => 00..20
-
- return ((value._value + 1) & ~0x80u) <= 0x20u;
- }
-
- public static bool IsDigit(Rune value)
- {
- if (value.IsAscii)
- {
- return UnicodeUtility.IsInRangeInclusive(value._value, '0', '9');
- }
- else
- {
- return GetUnicodeCategoryNonAscii(value) == UnicodeCategory.DecimalDigitNumber;
- }
- }
-
- public static bool IsLetter(Rune value)
- {
- if (value.IsAscii)
- {
- return ((value._value - 'A') & ~0x20u) <= (uint)('Z' - 'A'); // [A-Za-z]
- }
- else
- {
- return IsCategoryLetter(GetUnicodeCategoryNonAscii(value));
- }
- }
-
- public static bool IsLetterOrDigit(Rune value)
- {
- if (value.IsAscii)
- {
- return (AsciiCharInfo[value.Value] & IsLetterOrDigitFlag) != 0;
- }
- else
- {
- return IsCategoryLetterOrDecimalDigit(GetUnicodeCategoryNonAscii(value));
- }
- }
-
- public static bool IsLower(Rune value)
- {
- if (value.IsAscii)
- {
- return UnicodeUtility.IsInRangeInclusive(value._value, 'a', 'z');
- }
- else
- {
- return GetUnicodeCategoryNonAscii(value) == UnicodeCategory.LowercaseLetter;
- }
- }
-
- public static bool IsNumber(Rune value)
- {
- if (value.IsAscii)
- {
- return UnicodeUtility.IsInRangeInclusive(value._value, '0', '9');
- }
- else
- {
- return IsCategoryNumber(GetUnicodeCategoryNonAscii(value));
- }
- }
-
- public static bool IsPunctuation(Rune value)
- {
- return IsCategoryPunctuation(GetUnicodeCategory(value));
- }
-
- public static bool IsSeparator(Rune value)
- {
- return IsCategorySeparator(GetUnicodeCategory(value));
- }
-
- public static bool IsSymbol(Rune value)
- {
- return IsCategorySymbol(GetUnicodeCategory(value));
- }
-
- public static bool IsUpper(Rune value)
- {
- if (value.IsAscii)
- {
- return UnicodeUtility.IsInRangeInclusive(value._value, 'A', 'Z');
- }
- else
- {
- return GetUnicodeCategoryNonAscii(value) == UnicodeCategory.UppercaseLetter;
- }
- }
-
- public static bool IsWhiteSpace(Rune value)
- {
- if (value.IsAscii)
- {
- return (AsciiCharInfo[value.Value] & IsWhiteSpaceFlag) != 0;
- }
-
- // U+0085 is special since it's a whitespace character but is in the Control category
- // instead of a normal separator category. No other code point outside the ASCII range
- // has this mismatch.
-
- if (value._value == 0x0085u)
- {
- return true;
- }
-
- return IsCategorySeparator(GetUnicodeCategoryNonAscii(value));
- }
-
- public static Rune ToLower(Rune value, CultureInfo culture)
- {
- if (culture is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.culture);
- }
-
- // We don't want to special-case ASCII here since the specified culture might handle
- // ASCII characters differently than the invariant culture (e.g., Turkish I). Instead
- // we'll just jump straight to the globalization tables if they're available.
-
- if (GlobalizationMode.Invariant)
- {
- return ToLowerInvariant(value);
- }
-
- return ChangeCaseCultureAware(value, culture!.TextInfo, toUpper: false);
- }
-
- public static Rune ToLowerInvariant(Rune value)
- {
- // Handle the most common case (ASCII data) first. Within the common case, we expect
- // that there'll be a mix of lowercase & uppercase chars, so make the conversion branchless.
-
- if (value.IsAscii)
- {
- // It's ok for us to use the UTF-16 conversion utility for this since the high
- // 16 bits of the value will never be set so will be left unchanged.
- return UnsafeCreate(Utf16Utility.ConvertAllAsciiCharsInUInt32ToLowercase(value._value));
- }
-
- if (GlobalizationMode.Invariant)
- {
- // If the value isn't ASCII and if the globalization tables aren't available,
- // case changing has no effect.
- return value;
- }
-
- // Non-ASCII data requires going through the case folding tables.
-
- return ChangeCaseCultureAware(value, TextInfo.Invariant, toUpper: false);
- }
-
- public static Rune ToUpper(Rune value, CultureInfo culture)
- {
- if (culture is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.culture);
- }
-
- // We don't want to special-case ASCII here since the specified culture might handle
- // ASCII characters differently than the invariant culture (e.g., Turkish I). Instead
- // we'll just jump straight to the globalization tables if they're available.
-
- if (GlobalizationMode.Invariant)
- {
- return ToUpperInvariant(value);
- }
-
- return ChangeCaseCultureAware(value, culture!.TextInfo, toUpper: true);
- }
-
- public static Rune ToUpperInvariant(Rune value)
- {
- // Handle the most common case (ASCII data) first. Within the common case, we expect
- // that there'll be a mix of lowercase & uppercase chars, so make the conversion branchless.
-
- if (value.IsAscii)
- {
- // It's ok for us to use the UTF-16 conversion utility for this since the high
- // 16 bits of the value will never be set so will be left unchanged.
- return UnsafeCreate(Utf16Utility.ConvertAllAsciiCharsInUInt32ToUppercase(value._value));
- }
-
- if (GlobalizationMode.Invariant)
- {
- // If the value isn't ASCII and if the globalization tables aren't available,
- // case changing has no effect.
- return value;
- }
-
- // Non-ASCII data requires going through the case folding tables.
-
- return ChangeCaseCultureAware(value, TextInfo.Invariant, toUpper: true);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/SpanRuneEnumerator.cs b/netcore/System.Private.CoreLib/shared/System/Text/SpanRuneEnumerator.cs
deleted file mode 100644
index 082a5108c14..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/SpanRuneEnumerator.cs
+++ /dev/null
@@ -1,51 +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.
-
-namespace System.Text
-{
- // An enumerator for retrieving System.Text.Rune instances from a ROS<char>.
- // Methods are pattern-matched by compiler to allow using foreach pattern.
- public ref struct SpanRuneEnumerator
- {
- private ReadOnlySpan<char> _remaining;
- private Rune _current;
-
- internal SpanRuneEnumerator(ReadOnlySpan<char> buffer)
- {
- _remaining = buffer;
- _current = default;
- }
-
- public Rune Current => _current;
-
- public SpanRuneEnumerator GetEnumerator() => this;
-
- public bool MoveNext()
- {
- if (_remaining.IsEmpty)
- {
- // reached the end of the buffer
- _current = default;
- return false;
- }
-
- int scalarValue = Rune.ReadFirstRuneFromUtf16Buffer(_remaining);
- if (scalarValue < 0)
- {
- // replace invalid sequences with U+FFFD
- scalarValue = Rune.ReplacementChar.Value;
- }
-
- // In UTF-16 specifically, invalid sequences always have length 1, which is the same
- // length as the replacement character U+FFFD. This means that we can always bump the
- // next index by the current scalar's UTF-16 sequence length. This optimization is not
- // generally applicable; for example, enumerating scalars from UTF-8 cannot utilize
- // this same trick.
-
- _current = Rune.UnsafeCreate((uint)scalarValue);
- _remaining = _remaining.Slice(_current.Utf16SequenceLength);
- return true;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.Debug.cs b/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.Debug.cs
deleted file mode 100644
index d74bb67dce1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.Debug.cs
+++ /dev/null
@@ -1,43 +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 System.Diagnostics;
-
-namespace System.Text
-{
- public sealed partial class StringBuilder
- {
- private void ShowChunks(int maxChunksToShow = 10)
- {
- int count = 0;
- StringBuilder head = this;
- StringBuilder? current = this;
-
- while (current != null)
- {
- if (count < maxChunksToShow)
- {
- count++;
- }
- else
- {
- Debug.Assert(head.m_ChunkPrevious != null);
- head = head.m_ChunkPrevious;
- }
- current = current.m_ChunkPrevious;
- }
-
- current = head;
- string[] chunks = new string[count];
- for (int i = count; i > 0; i--)
- {
- chunks[i - 1] = new string(current.m_ChunkChars).Replace('\0', '.');
- Debug.Assert(current.m_ChunkPrevious != null);
- current = current.m_ChunkPrevious;
- }
-
- Debug.WriteLine('|' + string.Join('|', chunks) + '|');
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
deleted file mode 100644
index 785faba78b2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
+++ /dev/null
@@ -1,2662 +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 System.Runtime.Serialization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Diagnostics;
-using System.Collections.Generic;
-
-namespace System.Text
-{
- // This class represents a mutable string. It is convenient for situations in
- // which it is desirable to modify a string, perhaps by removing, replacing, or
- // inserting characters, without creating a new String subsequent to
- // each modification.
- //
- // The methods contained within this class do not return a new StringBuilder
- // object unless specified otherwise. This class may be used in conjunction with the String
- // class to carry out modifications upon strings.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed partial class StringBuilder : ISerializable
- {
- // A StringBuilder is internally represented as a linked list of blocks each of which holds
- // a chunk of the string. It turns out string as a whole can also be represented as just a chunk,
- // so that is what we do.
-
- /// <summary>
- /// The character buffer for this chunk.
- /// </summary>
- internal char[] m_ChunkChars;
-
- /// <summary>
- /// The chunk that logically precedes this chunk.
- /// </summary>
- internal StringBuilder? m_ChunkPrevious;
-
- /// <summary>
- /// The number of characters in this chunk.
- /// This is the number of elements in <see cref="m_ChunkChars"/> that are in use, from the start of the buffer.
- /// </summary>
- internal int m_ChunkLength;
-
- /// <summary>
- /// The logical offset of this chunk's characters in the string it is a part of.
- /// This is the sum of the number of characters in preceding blocks.
- /// </summary>
- internal int m_ChunkOffset;
-
- /// <summary>
- /// The maximum capacity this builder is allowed to have.
- /// </summary>
- internal int m_MaxCapacity;
-
- /// <summary>
- /// The default capacity of a <see cref="StringBuilder"/>.
- /// </summary>
- internal const int DefaultCapacity = 16;
-
- private const string CapacityField = "Capacity"; // Do not rename (binary serialization)
- private const string MaxCapacityField = "m_MaxCapacity"; // Do not rename (binary serialization)
- private const string StringValueField = "m_StringValue"; // Do not rename (binary serialization)
- private const string ThreadIDField = "m_currentThread"; // Do not rename (binary serialization)
-
- // We want to keep chunk arrays out of large object heap (< 85K bytes ~ 40K chars) to be sure.
- // Making the maximum chunk size big means less allocation code called, but also more waste
- // in unused characters and slower inserts / replaces (since you do need to slide characters over
- // within a buffer).
- internal const int MaxChunkSize = 8000;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="StringBuilder"/> class.
- /// </summary>
- public StringBuilder()
- {
- m_MaxCapacity = int.MaxValue;
- m_ChunkChars = new char[DefaultCapacity];
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="StringBuilder"/> class.
- /// </summary>
- /// <param name="capacity">The initial capacity of this builder.</param>
- public StringBuilder(int capacity)
- : this(capacity, int.MaxValue)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="StringBuilder"/> class.
- /// </summary>
- /// <param name="value">The initial contents of this builder.</param>
- public StringBuilder(string? value)
- : this(value, DefaultCapacity)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="StringBuilder"/> class.
- /// </summary>
- /// <param name="value">The initial contents of this builder.</param>
- /// <param name="capacity">The initial capacity of this builder.</param>
- public StringBuilder(string? value, int capacity)
- : this(value, 0, value?.Length ?? 0, capacity)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="StringBuilder"/> class.
- /// </summary>
- /// <param name="value">The initial contents of this builder.</param>
- /// <param name="startIndex">The index to start in <paramref name="value"/>.</param>
- /// <param name="length">The number of characters to read in <paramref name="value"/>.</param>
- /// <param name="capacity">The initial capacity of this builder.</param>
- public StringBuilder(string? value, int startIndex, int length, int capacity)
- {
- if (capacity < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(capacity), SR.Format(SR.ArgumentOutOfRange_MustBePositive, nameof(capacity)));
- }
- if (length < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.Format(SR.ArgumentOutOfRange_MustBeNonNegNum, nameof(length)));
- }
- if (startIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
- }
-
- if (value == null)
- {
- value = string.Empty;
- }
- if (startIndex > value.Length - length)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_IndexLength);
- }
-
- m_MaxCapacity = int.MaxValue;
- if (capacity == 0)
- {
- capacity = DefaultCapacity;
- }
- capacity = Math.Max(capacity, length);
-
- m_ChunkChars = GC.AllocateUninitializedArray<char>(capacity);
- m_ChunkLength = length;
-
- unsafe
- {
- fixed (char* sourcePtr = value)
- {
- ThreadSafeCopy(sourcePtr + startIndex, m_ChunkChars, 0, length);
- }
- }
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="StringBuilder"/> class.
- /// </summary>
- /// <param name="capacity">The initial capacity of this builder.</param>
- /// <param name="maxCapacity">The maximum capacity of this builder.</param>
- public StringBuilder(int capacity, int maxCapacity)
- {
- if (capacity > maxCapacity)
- {
- throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_Capacity);
- }
- if (maxCapacity < 1)
- {
- throw new ArgumentOutOfRangeException(nameof(maxCapacity), SR.ArgumentOutOfRange_SmallMaxCapacity);
- }
- if (capacity < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(capacity), SR.Format(SR.ArgumentOutOfRange_MustBePositive, nameof(capacity)));
- }
-
- if (capacity == 0)
- {
- capacity = Math.Min(DefaultCapacity, maxCapacity);
- }
-
- m_MaxCapacity = maxCapacity;
- m_ChunkChars = GC.AllocateUninitializedArray<char>(capacity);
- }
-
- private StringBuilder(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- int persistedCapacity = 0;
- string? persistedString = null;
- int persistedMaxCapacity = int.MaxValue;
- bool capacityPresent = false;
-
- // Get the data
- SerializationInfoEnumerator enumerator = info.GetEnumerator();
- while (enumerator.MoveNext())
- {
- switch (enumerator.Name)
- {
- case MaxCapacityField:
- persistedMaxCapacity = info.GetInt32(MaxCapacityField);
- break;
- case StringValueField:
- persistedString = info.GetString(StringValueField);
- break;
- case CapacityField:
- persistedCapacity = info.GetInt32(CapacityField);
- capacityPresent = true;
- break;
- default:
- // Ignore other fields for forwards-compatibility.
- break;
- }
- }
-
- // Check values and set defaults
- if (persistedString == null)
- {
- persistedString = string.Empty;
- }
- if (persistedMaxCapacity < 1 || persistedString.Length > persistedMaxCapacity)
- {
- throw new SerializationException(SR.Serialization_StringBuilderMaxCapacity);
- }
-
- if (!capacityPresent)
- {
- // StringBuilder in V1.X did not persist the Capacity, so this is a valid legacy code path.
- persistedCapacity = Math.Min(Math.Max(DefaultCapacity, persistedString.Length), persistedMaxCapacity);
- }
-
- if (persistedCapacity < 0 || persistedCapacity < persistedString.Length || persistedCapacity > persistedMaxCapacity)
- {
- throw new SerializationException(SR.Serialization_StringBuilderCapacity);
- }
-
- // Assign
- m_MaxCapacity = persistedMaxCapacity;
- m_ChunkChars = GC.AllocateUninitializedArray<char>(persistedCapacity);
- persistedString.CopyTo(0, m_ChunkChars, 0, persistedString.Length);
- m_ChunkLength = persistedString.Length;
- m_ChunkPrevious = null;
- AssertInvariants();
- }
-
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- AssertInvariants();
- info.AddValue(MaxCapacityField, m_MaxCapacity);
- info.AddValue(CapacityField, Capacity);
- info.AddValue(StringValueField, ToString());
- // Note: persist "m_currentThread" to be compatible with old versions
- info.AddValue(ThreadIDField, 0);
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- private void AssertInvariants()
- {
- Debug.Assert(m_ChunkOffset + m_ChunkChars.Length >= m_ChunkOffset, "The length of the string is greater than int.MaxValue.");
-
- StringBuilder currentBlock = this;
- int maxCapacity = this.m_MaxCapacity;
- while (true)
- {
- // All blocks have the same max capacity.
- Debug.Assert(currentBlock.m_MaxCapacity == maxCapacity);
- Debug.Assert(currentBlock.m_ChunkChars != null);
-
- Debug.Assert(currentBlock.m_ChunkLength <= currentBlock.m_ChunkChars.Length);
- Debug.Assert(currentBlock.m_ChunkLength >= 0);
- Debug.Assert(currentBlock.m_ChunkOffset >= 0);
-
- StringBuilder? prevBlock = currentBlock.m_ChunkPrevious;
- if (prevBlock == null)
- {
- Debug.Assert(currentBlock.m_ChunkOffset == 0);
- break;
- }
- // There are no gaps in the blocks.
- Debug.Assert(currentBlock.m_ChunkOffset == prevBlock.m_ChunkOffset + prevBlock.m_ChunkLength);
- currentBlock = prevBlock;
- }
- }
-
- public int Capacity
- {
- get => m_ChunkChars.Length + m_ChunkOffset;
- set
- {
- if (value < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_NegativeCapacity);
- }
- if (value > MaxCapacity)
- {
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_Capacity);
- }
- if (value < Length)
- {
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_SmallCapacity);
- }
-
- if (Capacity != value)
- {
- int newLen = value - m_ChunkOffset;
- char[] newArray = GC.AllocateUninitializedArray<char>(newLen);
- Array.Copy(m_ChunkChars, newArray, m_ChunkLength);
- m_ChunkChars = newArray;
- }
- }
- }
-
- /// <summary>
- /// Gets the maximum capacity this builder is allowed to have.
- /// </summary>
- public int MaxCapacity => m_MaxCapacity;
-
- /// <summary>
- /// Ensures that the capacity of this builder is at least the specified value.
- /// </summary>
- /// <param name="capacity">The new capacity for this builder.</param>
- /// <remarks>
- /// If <paramref name="capacity"/> is less than or equal to the current capacity of
- /// this builder, the capacity remains unchanged.
- /// </remarks>
- public int EnsureCapacity(int capacity)
- {
- if (capacity < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_NegativeCapacity);
- }
-
- if (Capacity < capacity)
- {
- Capacity = capacity;
- }
- return Capacity;
- }
-
- public override string ToString()
- {
- AssertInvariants();
-
- if (Length == 0)
- {
- return string.Empty;
- }
-
- string result = string.FastAllocateString(Length);
- StringBuilder? chunk = this;
- unsafe
- {
- fixed (char* destinationPtr = result)
- {
- do
- {
- if (chunk.m_ChunkLength > 0)
- {
- // Copy these into local variables so that they are stable even in the presence of race conditions
- char[] sourceArray = chunk.m_ChunkChars;
- int chunkOffset = chunk.m_ChunkOffset;
- int chunkLength = chunk.m_ChunkLength;
-
- // Check that we will not overrun our boundaries.
- if ((uint)(chunkLength + chunkOffset) <= (uint)result.Length && (uint)chunkLength <= (uint)sourceArray.Length)
- {
- fixed (char* sourcePtr = &sourceArray[0])
- string.wstrcpy(destinationPtr + chunkOffset, sourcePtr, chunkLength);
- }
- else
- {
- throw new ArgumentOutOfRangeException(nameof(chunkLength), SR.ArgumentOutOfRange_Index);
- }
- }
- chunk = chunk.m_ChunkPrevious;
- }
- while (chunk != null);
-
- return result;
- }
- }
- }
-
- /// <summary>
- /// Creates a string from a substring of this builder.
- /// </summary>
- /// <param name="startIndex">The index to start in this builder.</param>
- /// <param name="length">The number of characters to read in this builder.</param>
- public string ToString(int startIndex, int length)
- {
- int currentLength = this.Length;
- if (startIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
- }
- if (startIndex > currentLength)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndexLargerThanLength);
- }
- if (length < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NegativeLength);
- }
- if (startIndex > currentLength - length)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_IndexLength);
- }
-
- AssertInvariants();
- string result = string.FastAllocateString(length);
- unsafe
- {
- fixed (char* destinationPtr = result)
- {
- this.CopyTo(startIndex, new Span<char>(destinationPtr, length), length);
- return result;
- }
- }
- }
-
- public StringBuilder Clear()
- {
- this.Length = 0;
- return this;
- }
-
- /// <summary>
- /// Gets or sets the length of this builder.
- /// </summary>
- public int Length
- {
- get => m_ChunkOffset + m_ChunkLength;
- set
- {
- // If the new length is less than 0 or greater than our Maximum capacity, bail.
- if (value < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_NegativeLength);
- }
-
- if (value > MaxCapacity)
- {
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_SmallCapacity);
- }
-
- if (value == 0 && m_ChunkPrevious == null)
- {
- m_ChunkLength = 0;
- m_ChunkOffset = 0;
- return;
- }
-
- int delta = value - Length;
- if (delta > 0)
- {
- // Pad ourselves with null characters.
- Append('\0', delta);
- }
- else
- {
- StringBuilder chunk = FindChunkForIndex(value);
- if (chunk != this)
- {
- // Avoid possible infinite capacity growth. See https://github.com/dotnet/coreclr/pull/16926
- int capacityToPreserve = Math.Min(Capacity, Math.Max(Length * 6 / 5, m_ChunkChars.Length));
- int newLen = capacityToPreserve - chunk.m_ChunkOffset;
- if (newLen > chunk.m_ChunkChars.Length)
- {
- // We crossed a chunk boundary when reducing the Length. We must replace this middle-chunk with a new larger chunk,
- // to ensure the capacity we want is preserved.
- char[] newArray = GC.AllocateUninitializedArray<char>(newLen);
- Array.Copy(chunk.m_ChunkChars, newArray, chunk.m_ChunkLength);
- m_ChunkChars = newArray;
- }
- else
- {
- // Special case where the capacity we want to keep corresponds exactly to the size of the content.
- // Just take ownership of the array.
- Debug.Assert(newLen == chunk.m_ChunkChars.Length, "The new chunk should be larger or equal to the one it is replacing.");
- m_ChunkChars = chunk.m_ChunkChars;
- }
-
- m_ChunkPrevious = chunk.m_ChunkPrevious;
- m_ChunkOffset = chunk.m_ChunkOffset;
- }
- m_ChunkLength = value - chunk.m_ChunkOffset;
- AssertInvariants();
- }
- Debug.Assert(Length == value, "Something went wrong setting Length.");
- }
- }
-
- [IndexerName("Chars")]
- public char this[int index]
- {
- get
- {
- StringBuilder? chunk = this;
- while (true)
- {
- int indexInBlock = index - chunk.m_ChunkOffset;
- if (indexInBlock >= 0)
- {
- if (indexInBlock >= chunk.m_ChunkLength)
- {
- throw new IndexOutOfRangeException();
- }
- return chunk.m_ChunkChars[indexInBlock];
- }
- chunk = chunk.m_ChunkPrevious;
- if (chunk == null)
- {
- throw new IndexOutOfRangeException();
- }
- }
- }
- set
- {
- StringBuilder? chunk = this;
- while (true)
- {
- int indexInBlock = index - chunk.m_ChunkOffset;
- if (indexInBlock >= 0)
- {
- if (indexInBlock >= chunk.m_ChunkLength)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
- chunk.m_ChunkChars[indexInBlock] = value;
- return;
- }
- chunk = chunk.m_ChunkPrevious;
- if (chunk == null)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
- }
- }
- }
-
- /// <summary>
- /// GetChunks returns ChunkEnumerator that follows the IEnumerable pattern and
- /// thus can be used in a C# 'foreach' statements to retrieve the data in the StringBuilder
- /// as chunks (ReadOnlyMemory) of characters. An example use is:
- ///
- /// foreach (ReadOnlyMemory&lt;char&gt; chunk in sb.GetChunks())
- /// foreach (char c in chunk.Span)
- /// { /* operation on c }
- ///
- /// It is undefined what happens if the StringBuilder is modified while the chunk
- /// enumeration is incomplete. StringBuilder is also not thread-safe, so operating
- /// on it with concurrent threads is illegal. Finally the ReadOnlyMemory chunks returned
- /// are NOT guarenteed to remain unchanged if the StringBuilder is modified, so do
- /// not cache them for later use either. This API's purpose is efficiently extracting
- /// the data of a CONSTANT StringBuilder.
- ///
- /// Creating a ReadOnlySpan from a ReadOnlyMemory (the .Span property) is expensive
- /// compared to the fetching of the character, so create a local variable for the SPAN
- /// if you need to use it in a nested for statement. For example
- ///
- /// foreach (ReadOnlyMemory&lt;char&gt; chunk in sb.GetChunks())
- /// {
- /// var span = chunk.Span;
- /// for (int i = 0; i &lt; span.Length; i++)
- /// { /* operation on span[i] */ }
- /// }
- /// </summary>
- public ChunkEnumerator GetChunks() => new ChunkEnumerator(this);
-
- /// <summary>
- /// ChunkEnumerator supports both the IEnumerable and IEnumerator pattern so foreach
- /// works (see GetChunks). It needs to be public (so the compiler can use it
- /// when building a foreach statement) but users typically don't use it explicitly.
- /// (which is why it is a nested type).
- /// </summary>
- public struct ChunkEnumerator
- {
- private readonly StringBuilder _firstChunk; // The first Stringbuilder chunk (which is the end of the logical string)
- private StringBuilder? _currentChunk; // The chunk that this enumerator is currently returning (Current).
- private readonly ManyChunkInfo? _manyChunks; // Only used for long string builders with many chunks (see constructor)
-
- /// <summary>
- /// Implement IEnumerable.GetEnumerator() to return 'this' as the IEnumerator
- /// </summary>
- [ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)] // Only here to make foreach work
- public ChunkEnumerator GetEnumerator() { return this; }
-
- /// <summary>
- /// Implements the IEnumerator pattern.
- /// </summary>
- public bool MoveNext()
- {
- if (_currentChunk == _firstChunk)
- {
- return false;
- }
-
-
- if (_manyChunks != null)
- {
- return _manyChunks.MoveNext(ref _currentChunk);
- }
-
- StringBuilder next = _firstChunk;
- while (next.m_ChunkPrevious != _currentChunk)
- {
- Debug.Assert(next.m_ChunkPrevious != null);
- next = next.m_ChunkPrevious;
- }
- _currentChunk = next;
- return true;
- }
-
- /// <summary>
- /// Implements the IEnumerator pattern.
- /// </summary>
- public ReadOnlyMemory<char> Current
- {
- get
- {
- if (_currentChunk == null)
- {
- ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
- }
-
- return new ReadOnlyMemory<char>(_currentChunk.m_ChunkChars, 0, _currentChunk.m_ChunkLength);
- }
- }
-
- #region private
- internal ChunkEnumerator(StringBuilder stringBuilder)
- {
- Debug.Assert(stringBuilder != null);
- _firstChunk = stringBuilder;
- _currentChunk = null; // MoveNext will find the last chunk if we do this.
- _manyChunks = null;
-
- // There is a performance-vs-allocation tradeoff. Because the chunks
- // are a linked list with each chunk pointing to its PREDECESSOR, walking
- // the list FORWARD is not efficient. If there are few chunks (< 8) we
- // simply scan from the start each time, and tolerate the N*N behavior.
- // However above this size, we allocate an array to hold pointers to all
- // the chunks and we can be efficient for large N.
- int chunkCount = ChunkCount(stringBuilder);
- if (8 < chunkCount)
- {
- _manyChunks = new ManyChunkInfo(stringBuilder, chunkCount);
- }
- }
-
- private static int ChunkCount(StringBuilder? stringBuilder)
- {
- int ret = 0;
- while (stringBuilder != null)
- {
- ret++;
- stringBuilder = stringBuilder.m_ChunkPrevious;
- }
- return ret;
- }
-
- /// <summary>
- /// Used to hold all the chunks indexes when you have many chunks.
- /// </summary>
- private class ManyChunkInfo
- {
- private readonly StringBuilder[] _chunks; // These are in normal order (first chunk first)
- private int _chunkPos;
-
- public bool MoveNext(ref StringBuilder? current)
- {
- int pos = ++_chunkPos;
- if (_chunks.Length <= pos)
- {
- return false;
- }
- current = _chunks[pos];
- return true;
- }
-
- public ManyChunkInfo(StringBuilder? stringBuilder, int chunkCount)
- {
- _chunks = new StringBuilder[chunkCount];
- while (0 <= --chunkCount)
- {
- Debug.Assert(stringBuilder != null);
- _chunks[chunkCount] = stringBuilder;
- stringBuilder = stringBuilder.m_ChunkPrevious;
- }
- _chunkPos = -1;
- }
- }
-#endregion
- }
-
- /// <summary>
- /// Appends a character 0 or more times to the end of this builder.
- /// </summary>
- /// <param name="value">The character to append.</param>
- /// <param name="repeatCount">The number of times to append <paramref name="value"/>.</param>
- public StringBuilder Append(char value, int repeatCount)
- {
- if (repeatCount < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(repeatCount), SR.ArgumentOutOfRange_NegativeCount);
- }
-
- if (repeatCount == 0)
- {
- return this;
- }
-
- // this is where we can check if the repeatCount will put us over m_MaxCapacity
- // We are doing the check here to prevent the corruption of the StringBuilder.
- int newLength = Length + repeatCount;
- if (newLength > m_MaxCapacity || newLength < repeatCount)
- {
- throw new ArgumentOutOfRangeException(nameof(repeatCount), SR.ArgumentOutOfRange_LengthGreaterThanCapacity);
- }
-
- int index = m_ChunkLength;
- while (repeatCount > 0)
- {
- if (index < m_ChunkChars.Length)
- {
- m_ChunkChars[index++] = value;
- --repeatCount;
- }
- else
- {
- m_ChunkLength = index;
- ExpandByABlock(repeatCount);
- Debug.Assert(m_ChunkLength == 0);
- index = 0;
- }
- }
-
- m_ChunkLength = index;
- AssertInvariants();
- return this;
- }
-
- /// <summary>
- /// Appends a range of characters to the end of this builder.
- /// </summary>
- /// <param name="value">The characters to append.</param>
- /// <param name="startIndex">The index to start in <paramref name="value"/>.</param>
- /// <param name="charCount">The number of characters to read in <paramref name="value"/>.</param>
- public StringBuilder Append(char[]? value, int startIndex, int charCount)
- {
- if (startIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_GenericPositive);
- }
- if (charCount < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(charCount), SR.ArgumentOutOfRange_GenericPositive);
- }
-
- if (value == null)
- {
- if (startIndex == 0 && charCount == 0)
- {
- return this;
- }
-
- throw new ArgumentNullException(nameof(value));
- }
- if (charCount > value.Length - startIndex)
- {
- throw new ArgumentOutOfRangeException(nameof(charCount), SR.ArgumentOutOfRange_Index);
- }
-
- if (charCount == 0)
- {
- return this;
- }
-
- unsafe
- {
- fixed (char* valueChars = &value[startIndex])
- {
- Append(valueChars, charCount);
- return this;
- }
- }
- }
-
-
- /// <summary>
- /// Appends a string to the end of this builder.
- /// </summary>
- /// <param name="value">The string to append.</param>
- public StringBuilder Append(string? value)
- {
- if (value != null)
- {
- // We could have just called AppendHelper here; this is a hand-specialization of that code.
- char[] chunkChars = m_ChunkChars;
- int chunkLength = m_ChunkLength;
- int valueLen = value.Length;
- int newCurrentIndex = chunkLength + valueLen;
-
- if (newCurrentIndex < chunkChars.Length) // Use strictly < to avoid issues if count == 0, newIndex == length
- {
- if (valueLen <= 2)
- {
- if (valueLen > 0)
- {
- chunkChars[chunkLength] = value[0];
- }
- if (valueLen > 1)
- {
- chunkChars[chunkLength + 1] = value[1];
- }
- }
- else
- {
- unsafe
- {
- fixed (char* valuePtr = value)
- fixed (char* destPtr = &chunkChars[chunkLength])
- {
- string.wstrcpy(destPtr, valuePtr, valueLen);
- }
- }
- }
-
- m_ChunkLength = newCurrentIndex;
- }
- else
- {
- AppendHelper(value);
- }
- }
-
- return this;
- }
-
- // We put this fixed in its own helper to avoid the cost of zero-initing `valueChars` in the
- // case we don't actually use it.
- private void AppendHelper(string value)
- {
- unsafe
- {
- fixed (char* valueChars = value)
- {
- Append(valueChars, value.Length);
- }
- }
- }
-
- /// <summary>
- /// Appends part of a string to the end of this builder.
- /// </summary>
- /// <param name="value">The string to append.</param>
- /// <param name="startIndex">The index to start in <paramref name="value"/>.</param>
- /// <param name="count">The number of characters to read in <paramref name="value"/>.</param>
- public StringBuilder Append(string? value, int startIndex, int count)
- {
- if (startIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_GenericPositive);
- }
-
- if (value == null)
- {
- if (startIndex == 0 && count == 0)
- {
- return this;
- }
- throw new ArgumentNullException(nameof(value));
- }
-
- if (count == 0)
- {
- return this;
- }
-
- if (startIndex > value.Length - count)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
-
- unsafe
- {
- fixed (char* valueChars = value)
- {
- Append(valueChars + startIndex, count);
- return this;
- }
- }
- }
-
- public StringBuilder Append(StringBuilder? value)
- {
- if (value != null && value.Length != 0)
- {
- return AppendCore(value, 0, value.Length);
- }
- return this;
- }
-
- public StringBuilder Append(StringBuilder? value, int startIndex, int count)
- {
- if (startIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
-
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_GenericPositive);
- }
-
- if (value == null)
- {
- if (startIndex == 0 && count == 0)
- {
- return this;
- }
- throw new ArgumentNullException(nameof(value));
- }
-
- if (count == 0)
- {
- return this;
- }
-
- if (count > value.Length - startIndex)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
-
- return AppendCore(value, startIndex, count);
- }
-
- private StringBuilder AppendCore(StringBuilder value, int startIndex, int count)
- {
- if (value == this)
- {
- return Append(value.ToString(startIndex, count));
- }
-
- int newLength = Length + count;
-
- if ((uint)newLength > (uint)m_MaxCapacity)
- {
- throw new ArgumentOutOfRangeException(nameof(Capacity), SR.ArgumentOutOfRange_Capacity);
- }
-
- while (count > 0)
- {
- int length = Math.Min(m_ChunkChars.Length - m_ChunkLength, count);
- if (length == 0)
- {
- ExpandByABlock(count);
- length = Math.Min(m_ChunkChars.Length - m_ChunkLength, count);
- }
- value.CopyTo(startIndex, new Span<char>(m_ChunkChars, m_ChunkLength, length), length);
-
- m_ChunkLength += length;
- startIndex += length;
- count -= length;
- }
-
- return this;
- }
-
- public StringBuilder AppendLine() => Append(Environment.NewLineConst);
-
- public StringBuilder AppendLine(string? value)
- {
- Append(value);
- return Append(Environment.NewLineConst);
- }
-
- public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
- {
- if (destination == null)
- {
- throw new ArgumentNullException(nameof(destination));
- }
-
- if (destinationIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(destinationIndex), SR.Format(SR.ArgumentOutOfRange_MustBeNonNegNum, nameof(destinationIndex)));
- }
-
- if (destinationIndex > destination.Length - count)
- {
- throw new ArgumentException(SR.ArgumentOutOfRange_OffsetOut);
- }
-
- CopyTo(sourceIndex, new Span<char>(destination).Slice(destinationIndex), count);
- }
-
- public void CopyTo(int sourceIndex, Span<char> destination, int count)
- {
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.Arg_NegativeArgCount);
- }
-
- if ((uint)sourceIndex > (uint)Length)
- {
- throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_Index);
- }
-
- if (sourceIndex > Length - count)
- {
- throw new ArgumentException(SR.Arg_LongerThanSrcString);
- }
-
- AssertInvariants();
-
- StringBuilder? chunk = this;
- int sourceEndIndex = sourceIndex + count;
- int curDestIndex = count;
- while (count > 0)
- {
- Debug.Assert(chunk != null);
- int chunkEndIndex = sourceEndIndex - chunk.m_ChunkOffset;
- if (chunkEndIndex >= 0)
- {
- chunkEndIndex = Math.Min(chunkEndIndex, chunk.m_ChunkLength);
-
- int chunkCount = count;
- int chunkStartIndex = chunkEndIndex - count;
- if (chunkStartIndex < 0)
- {
- chunkCount += chunkStartIndex;
- chunkStartIndex = 0;
- }
- curDestIndex -= chunkCount;
- count -= chunkCount;
-
- // We ensure that chunkStartIndex + chunkCount are within range of m_chunkChars as well as
- // ensuring that curDestIndex + chunkCount are within range of destination
- ThreadSafeCopy(chunk.m_ChunkChars, chunkStartIndex, destination, curDestIndex, chunkCount);
- }
- chunk = chunk.m_ChunkPrevious;
- }
- }
-
- /// <summary>
- /// Inserts a string 0 or more times into this builder at the specified position.
- /// </summary>
- /// <param name="index">The index to insert in this builder.</param>
- /// <param name="value">The string to insert.</param>
- /// <param name="count">The number of times to insert the string.</param>
- public StringBuilder Insert(int index, string? value, int count)
- {
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- int currentLength = Length;
- if ((uint)index > (uint)currentLength)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
-
- if (string.IsNullOrEmpty(value) || count == 0)
- {
- return this;
- }
-
- // Ensure we don't insert more chars than we can hold, and we don't
- // have any integer overflow in our new length.
- long insertingChars = (long)value.Length * count;
- if (insertingChars > MaxCapacity - this.Length)
- {
- throw new OutOfMemoryException();
- }
- Debug.Assert(insertingChars + this.Length < int.MaxValue);
-
- StringBuilder chunk;
- int indexInChunk;
- MakeRoom(index, (int)insertingChars, out chunk, out indexInChunk, false);
- unsafe
- {
- fixed (char* valuePtr = value)
- {
- while (count > 0)
- {
- ReplaceInPlaceAtChunk(ref chunk!, ref indexInChunk, valuePtr, value.Length);
- --count;
- }
-
- return this;
- }
- }
- }
-
- /// <summary>
- /// Removes a range of characters from this builder.
- /// </summary>
- /// <remarks>
- /// This method does not reduce the capacity of this builder.
- /// </remarks>
- public StringBuilder Remove(int startIndex, int length)
- {
- if (length < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_NegativeLength);
- }
-
- if (startIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
- }
-
- if (length > Length - startIndex)
- {
- throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_Index);
- }
-
- if (Length == length && startIndex == 0)
- {
- Length = 0;
- return this;
- }
-
- if (length > 0)
- {
- StringBuilder chunk;
- int indexInChunk;
- Remove(startIndex, length, out chunk, out indexInChunk);
- }
-
- return this;
- }
-
- public StringBuilder Append(bool value) => Append(value.ToString());
-
- public StringBuilder Append(char value)
- {
- int nextCharIndex = m_ChunkLength;
- char[] chars = m_ChunkChars;
-
- if ((uint)chars.Length > (uint)nextCharIndex)
- {
- chars[nextCharIndex] = value;
- m_ChunkLength++;
- }
- else
- {
- Append(value, 1);
- }
-
- return this;
- }
-
- [CLSCompliant(false)]
- public StringBuilder Append(sbyte value) => AppendSpanFormattable(value);
-
- public StringBuilder Append(byte value) => AppendSpanFormattable(value);
-
- public StringBuilder Append(short value) => AppendSpanFormattable(value);
-
- public StringBuilder Append(int value) => AppendSpanFormattable(value);
-
- public StringBuilder Append(long value) => AppendSpanFormattable(value);
-
- public StringBuilder Append(float value) => AppendSpanFormattable(value);
-
- public StringBuilder Append(double value) => AppendSpanFormattable(value);
-
- public StringBuilder Append(decimal value) => AppendSpanFormattable(value);
-
- [CLSCompliant(false)]
- public StringBuilder Append(ushort value) => AppendSpanFormattable(value);
-
- [CLSCompliant(false)]
- public StringBuilder Append(uint value) => AppendSpanFormattable(value);
-
- [CLSCompliant(false)]
- public StringBuilder Append(ulong value) => AppendSpanFormattable(value);
-
- private StringBuilder AppendSpanFormattable<T>(T value) where T : ISpanFormattable
- {
- if (value.TryFormat(RemainingCurrentChunk, out int charsWritten, format: default, provider: null))
- {
- m_ChunkLength += charsWritten;
- return this;
- }
-
- return Append(value.ToString());
- }
-
- internal StringBuilder AppendSpanFormattable<T>(T value, string? format, IFormatProvider? provider) where T : ISpanFormattable, IFormattable
- {
- if (value.TryFormat(RemainingCurrentChunk, out int charsWritten, format, provider))
- {
- m_ChunkLength += charsWritten;
- return this;
- }
-
- return Append(value.ToString(format, provider));
- }
-
- public StringBuilder Append(object? value) => (value == null) ? this : Append(value.ToString());
-
- public StringBuilder Append(char[]? value)
- {
- if (value?.Length > 0)
- {
- unsafe
- {
- fixed (char* valueChars = &value[0])
- {
- Append(valueChars, value.Length);
- }
- }
- }
- return this;
- }
-
- public StringBuilder Append(ReadOnlySpan<char> value)
- {
- if (value.Length > 0)
- {
- unsafe
- {
- fixed (char* valueChars = &MemoryMarshal.GetReference(value))
- {
- Append(valueChars, value.Length);
- }
- }
- }
- return this;
- }
-
- public StringBuilder Append(ReadOnlyMemory<char> value) => Append(value.Span);
-
- #region AppendJoin
-
- public unsafe StringBuilder AppendJoin(string? separator, params object?[] values)
- {
- separator ??= string.Empty;
- fixed (char* pSeparator = separator)
- {
- return AppendJoinCore(pSeparator, separator.Length, values);
- }
- }
-
- public unsafe StringBuilder AppendJoin<T>(string? separator, IEnumerable<T> values)
- {
- separator ??= string.Empty;
- fixed (char* pSeparator = separator)
- {
- return AppendJoinCore(pSeparator, separator.Length, values);
- }
- }
-
- public unsafe StringBuilder AppendJoin(string? separator, params string?[] values)
- {
- separator ??= string.Empty;
- fixed (char* pSeparator = separator)
- {
- return AppendJoinCore(pSeparator, separator.Length, values);
- }
- }
-
- public unsafe StringBuilder AppendJoin(char separator, params object?[] values)
- {
- return AppendJoinCore(&separator, 1, values);
- }
-
- public unsafe StringBuilder AppendJoin<T>(char separator, IEnumerable<T> values)
- {
- return AppendJoinCore(&separator, 1, values);
- }
-
- public unsafe StringBuilder AppendJoin(char separator, params string?[] values)
- {
- return AppendJoinCore(&separator, 1, values);
- }
-
- private unsafe StringBuilder AppendJoinCore<T>(char* separator, int separatorLength, IEnumerable<T> values)
- {
- Debug.Assert(separator != null);
- Debug.Assert(separatorLength >= 0);
-
- if (values == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.values);
- }
-
- Debug.Assert(values != null);
- using (IEnumerator<T> en = values.GetEnumerator())
- {
- if (!en.MoveNext())
- {
- return this;
- }
-
- T value = en.Current;
- if (value != null)
- {
- Append(value.ToString());
- }
-
- while (en.MoveNext())
- {
- Append(separator, separatorLength);
- value = en.Current;
- if (value != null)
- {
- Append(value.ToString());
- }
- }
- }
- return this;
- }
-
- private unsafe StringBuilder AppendJoinCore<T>(char* separator, int separatorLength, T[] values)
- {
- if (values == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.values);
- }
-
- Debug.Assert(values != null);
- if (values.Length == 0)
- {
- return this;
- }
-
- if (values[0] != null)
- {
- Append(values[0]!.ToString()); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- }
-
- for (int i = 1; i < values.Length; i++)
- {
- Append(separator, separatorLength);
- if (values[i] != null)
- {
- Append(values[i]!.ToString()); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- }
- }
- return this;
- }
-
- #endregion
-
- public StringBuilder Insert(int index, string? value)
- {
- if ((uint)index > (uint)Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
-
- if (value != null)
- {
- unsafe
- {
- fixed (char* sourcePtr = value)
- Insert(index, sourcePtr, value.Length);
- }
- }
- return this;
- }
-
- public StringBuilder Insert(int index, bool value) => Insert(index, value.ToString(), 1);
-
- [CLSCompliant(false)]
- public StringBuilder Insert(int index, sbyte value) => Insert(index, value.ToString(), 1);
-
- public StringBuilder Insert(int index, byte value) => Insert(index, value.ToString(), 1);
-
- public StringBuilder Insert(int index, short value) => Insert(index, value.ToString(), 1);
-
- public StringBuilder Insert(int index, char value)
- {
- unsafe
- {
- Insert(index, &value, 1);
- }
- return this;
- }
-
- public StringBuilder Insert(int index, char[]? value)
- {
- if ((uint)index > (uint)Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
-
- if (value != null)
- {
- Insert(index, value, 0, value.Length);
- }
- return this;
- }
-
- public StringBuilder Insert(int index, char[]? value, int startIndex, int charCount)
- {
- int currentLength = Length;
- if ((uint)index > (uint)currentLength)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
-
- if (value == null)
- {
- if (startIndex == 0 && charCount == 0)
- {
- return this;
- }
- throw new ArgumentNullException(nameof(value), SR.ArgumentNull_String);
- }
-
- if (startIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndex);
- }
-
- if (charCount < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(charCount), SR.ArgumentOutOfRange_GenericPositive);
- }
-
- if (startIndex > value.Length - charCount)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
-
- if (charCount > 0)
- {
- unsafe
- {
- fixed (char* sourcePtr = &value[startIndex])
- Insert(index, sourcePtr, charCount);
- }
- }
- return this;
- }
-
- public StringBuilder Insert(int index, int value) => Insert(index, value.ToString(), 1);
-
- public StringBuilder Insert(int index, long value) => Insert(index, value.ToString(), 1);
-
- public StringBuilder Insert(int index, float value) => Insert(index, value.ToString(), 1);
-
- public StringBuilder Insert(int index, double value) => Insert(index, value.ToString(), 1);
-
- public StringBuilder Insert(int index, decimal value) => Insert(index, value.ToString(), 1);
-
- [CLSCompliant(false)]
- public StringBuilder Insert(int index, ushort value) => Insert(index, value.ToString(), 1);
-
- [CLSCompliant(false)]
- public StringBuilder Insert(int index, uint value) => Insert(index, value.ToString(), 1);
-
- [CLSCompliant(false)]
- public StringBuilder Insert(int index, ulong value) => Insert(index, value.ToString(), 1);
-
- public StringBuilder Insert(int index, object? value) => (value == null) ? this : Insert(index, value.ToString(), 1);
-
- public StringBuilder Insert(int index, ReadOnlySpan<char> value)
- {
- if ((uint)index > (uint)Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
-
- if (value.Length > 0)
- {
- unsafe
- {
- fixed (char* sourcePtr = &MemoryMarshal.GetReference(value))
- Insert(index, sourcePtr, value.Length);
- }
- }
- return this;
- }
-
- public StringBuilder AppendFormat(string format, object? arg0) => AppendFormatHelper(null, format, new ParamsArray(arg0));
-
- public StringBuilder AppendFormat(string format, object? arg0, object? arg1) => AppendFormatHelper(null, format, new ParamsArray(arg0, arg1));
-
- public StringBuilder AppendFormat(string format, object? arg0, object? arg1, object? arg2) => AppendFormatHelper(null, format, new ParamsArray(arg0, arg1, arg2));
-
- public StringBuilder AppendFormat(string format, params object?[] args)
- {
- if (args == null)
- {
- // To preserve the original exception behavior, throw an exception about format if both
- // args and format are null. The actual null check for format is in AppendFormatHelper.
- string paramName = (format == null) ? nameof(format) : nameof(args);
- throw new ArgumentNullException(paramName);
- }
-
- return AppendFormatHelper(null, format, new ParamsArray(args));
- }
-
- public StringBuilder AppendFormat(IFormatProvider? provider, string format, object? arg0) => AppendFormatHelper(provider, format, new ParamsArray(arg0));
-
- public StringBuilder AppendFormat(IFormatProvider? provider, string format, object? arg0, object? arg1) => AppendFormatHelper(provider, format, new ParamsArray(arg0, arg1));
-
- public StringBuilder AppendFormat(IFormatProvider? provider, string format, object? arg0, object? arg1, object? arg2) => AppendFormatHelper(provider, format, new ParamsArray(arg0, arg1, arg2));
-
- public StringBuilder AppendFormat(IFormatProvider? provider, string format, params object?[] args)
- {
- if (args == null)
- {
- // To preserve the original exception behavior, throw an exception about format if both
- // args and format are null. The actual null check for format is in AppendFormatHelper.
- string paramName = (format == null) ? nameof(format) : nameof(args);
- throw new ArgumentNullException(paramName);
- }
-
- return AppendFormatHelper(provider, format, new ParamsArray(args));
- }
-
- private static void FormatError()
- {
- throw new FormatException(SR.Format_InvalidString);
- }
-
- // Undocumented exclusive limits on the range for Argument Hole Index and Argument Hole Alignment.
- private const int IndexLimit = 1000000; // Note: 0 <= ArgIndex < IndexLimit
- private const int WidthLimit = 1000000; // Note: -WidthLimit < ArgAlign < WidthLimit
-
- internal StringBuilder AppendFormatHelper(IFormatProvider? provider, string format, ParamsArray args)
- {
- if (format == null)
- {
- throw new ArgumentNullException(nameof(format));
- }
-
- int pos = 0;
- int len = format.Length;
- char ch = '\x0';
-
- ICustomFormatter? cf = null;
- if (provider != null)
- {
- cf = (ICustomFormatter?)provider.GetFormat(typeof(ICustomFormatter));
- }
-
- while (true)
- {
- while (pos < len)
- {
- ch = format[pos];
-
- pos++;
- // Is it a closing brace?
- if (ch == '}')
- {
- // Check next character (if there is one) to see if it is escaped. eg }}
- if (pos < len && format[pos] == '}')
- {
- pos++;
- }
- else
- {
- // Otherwise treat it as an error (Mismatched closing brace)
- FormatError();
- }
- }
- // Is it an opening brace?
- else if (ch == '{')
- {
- // Check next character (if there is one) to see if it is escaped. eg {{
- if (pos < len && format[pos] == '{')
- {
- pos++;
- }
- else
- {
- // Otherwise treat it as the opening brace of an Argument Hole.
- pos--;
- break;
- }
- }
- // If it's neither then treat the character as just text.
- Append(ch);
- }
-
- //
- // Start of parsing of Argument Hole.
- // Argument Hole ::= { Index (, WS* Alignment WS*)? (: Formatting)? }
- //
- if (pos == len)
- {
- break;
- }
-
- //
- // Start of parsing required Index parameter.
- // Index ::= ('0'-'9')+ WS*
- //
- pos++;
- // If reached end of text then error (Unexpected end of text)
- // or character is not a digit then error (Unexpected Character)
- if (pos == len || (ch = format[pos]) < '0' || ch > '9') FormatError();
- int index = 0;
- do
- {
- index = index * 10 + ch - '0';
- pos++;
- // If reached end of text then error (Unexpected end of text)
- if (pos == len)
- {
- FormatError();
- }
- ch = format[pos];
- // so long as character is digit and value of the index is less than 1000000 ( index limit )
- }
- while (ch >= '0' && ch <= '9' && index < IndexLimit);
-
- // If value of index is not within the range of the arguments passed in then error (Index out of range)
- if (index >= args.Length)
- {
- throw new FormatException(SR.Format_IndexOutOfRange);
- }
-
- // Consume optional whitespace.
- while (pos < len && (ch = format[pos]) == ' ') pos++;
- // End of parsing index parameter.
-
- //
- // Start of parsing of optional Alignment
- // Alignment ::= comma WS* minus? ('0'-'9')+ WS*
- //
- bool leftJustify = false;
- int width = 0;
- // Is the character a comma, which indicates the start of alignment parameter.
- if (ch == ',')
- {
- pos++;
-
- // Consume Optional whitespace
- while (pos < len && format[pos] == ' ') pos++;
-
- // If reached the end of the text then error (Unexpected end of text)
- if (pos == len)
- {
- FormatError();
- }
-
- // Is there a minus sign?
- ch = format[pos];
- if (ch == '-')
- {
- // Yes, then alignment is left justified.
- leftJustify = true;
- pos++;
- // If reached end of text then error (Unexpected end of text)
- if (pos == len)
- {
- FormatError();
- }
- ch = format[pos];
- }
-
- // If current character is not a digit then error (Unexpected character)
- if (ch < '0' || ch > '9')
- {
- FormatError();
- }
- // Parse alignment digits.
- do
- {
- width = width * 10 + ch - '0';
- pos++;
- // If reached end of text then error. (Unexpected end of text)
- if (pos == len)
- {
- FormatError();
- }
- ch = format[pos];
- // So long a current character is a digit and the value of width is less than 100000 ( width limit )
- }
- while (ch >= '0' && ch <= '9' && width < WidthLimit);
- // end of parsing Argument Alignment
- }
-
- // Consume optional whitespace
- while (pos < len && (ch = format[pos]) == ' ') pos++;
-
- //
- // Start of parsing of optional formatting parameter.
- //
- object? arg = args[index];
-
- ReadOnlySpan<char> itemFormatSpan = default; // used if itemFormat is null
- // Is current character a colon? which indicates start of formatting parameter.
- if (ch == ':')
- {
- pos++;
- int startPos = pos;
-
- while (true)
- {
- // If reached end of text then error. (Unexpected end of text)
- if (pos == len)
- {
- FormatError();
- }
- ch = format[pos];
-
- if (ch == '}')
- {
- // Argument hole closed
- break;
- }
- else if (ch == '{')
- {
- // Braces inside the argument hole are not supported
- FormatError();
- }
-
- pos++;
- }
-
- if (pos > startPos)
- {
- itemFormatSpan = format.AsSpan(startPos, pos - startPos);
- }
- }
- else if (ch != '}')
- {
- // Unexpected character
- FormatError();
- }
-
- // Construct the output for this arg hole.
- pos++;
- string? s = null;
- string? itemFormat = null;
-
- if (cf != null)
- {
- if (itemFormatSpan.Length != 0)
- {
- itemFormat = new string(itemFormatSpan);
- }
- s = cf.Format(itemFormat, arg, provider);
- }
-
- if (s == null)
- {
- // If arg is ISpanFormattable and the beginning doesn't need padding,
- // try formatting it into the remaining current chunk.
- if (arg is ISpanFormattable spanFormattableArg &&
- (leftJustify || width == 0) &&
- spanFormattableArg.TryFormat(RemainingCurrentChunk, out int charsWritten, itemFormatSpan, provider))
- {
- m_ChunkLength += charsWritten;
-
- // Pad the end, if needed.
- int padding = width - charsWritten;
- if (leftJustify && padding > 0)
- {
- Append(' ', padding);
- }
-
- // Continue to parse other characters.
- continue;
- }
-
- // Otherwise, fallback to trying IFormattable or calling ToString.
- if (arg is IFormattable formattableArg)
- {
- if (itemFormatSpan.Length != 0)
- {
- itemFormat ??= new string(itemFormatSpan);
- }
- s = formattableArg.ToString(itemFormat, provider);
- }
- else if (arg != null)
- {
- s = arg.ToString();
- }
- }
- // Append it to the final output of the Format String.
- if (s == null)
- {
- s = string.Empty;
- }
- int pad = width - s.Length;
- if (!leftJustify && pad > 0)
- {
- Append(' ', pad);
- }
-
- Append(s);
- if (leftJustify && pad > 0)
- {
- Append(' ', pad);
- }
- // Continue to parse other characters.
- }
- return this;
- }
-
- /// <summary>
- /// Replaces all instances of one string with another in this builder.
- /// </summary>
- /// <param name="oldValue">The string to replace.</param>
- /// <param name="newValue">The string to replace <paramref name="oldValue"/> with.</param>
- /// <remarks>
- /// If <paramref name="newValue"/> is <c>null</c>, instances of <paramref name="oldValue"/>
- /// are removed from this builder.
- /// </remarks>
- public StringBuilder Replace(string oldValue, string? newValue) => Replace(oldValue, newValue, 0, Length);
-
- /// <summary>
- /// Determines if the contents of this builder are equal to the contents of another builder.
- /// </summary>
- /// <param name="sb">The other builder.</param>
- public bool Equals(StringBuilder? sb)
- {
- if (sb == null)
- {
- return false;
- }
- if (Length != sb.Length)
- {
- return false;
- }
- if (sb == this)
- {
- return true;
- }
- StringBuilder? thisChunk = this;
- int thisChunkIndex = thisChunk.m_ChunkLength;
- StringBuilder? sbChunk = sb;
- int sbChunkIndex = sbChunk.m_ChunkLength;
- while (true)
- {
- --thisChunkIndex;
- --sbChunkIndex;
-
- while (thisChunkIndex < 0)
- {
- thisChunk = thisChunk.m_ChunkPrevious;
- if (thisChunk == null)
- {
- break;
- }
- thisChunkIndex = thisChunk.m_ChunkLength + thisChunkIndex;
- }
-
- while (sbChunkIndex < 0)
- {
- sbChunk = sbChunk.m_ChunkPrevious;
- if (sbChunk == null)
- {
- break;
- }
- sbChunkIndex = sbChunk.m_ChunkLength + sbChunkIndex;
- }
-
- if (thisChunkIndex < 0)
- {
- return sbChunkIndex < 0;
- }
- if (sbChunkIndex < 0)
- {
- return false;
- }
-
- Debug.Assert(thisChunk != null && sbChunk != null);
- if (thisChunk.m_ChunkChars[thisChunkIndex] != sbChunk.m_ChunkChars[sbChunkIndex])
- {
- return false;
- }
- }
- }
-
- /// <summary>
- /// Determines if the contents of this builder are equal to the contents of <see cref="ReadOnlySpan{Char}"/>.
- /// </summary>
- /// <param name="span">The <see cref="ReadOnlySpan{Char}"/>.</param>
- public bool Equals(ReadOnlySpan<char> span)
- {
- if (span.Length != Length)
- {
- return false;
- }
-
- StringBuilder? sbChunk = this;
- int offset = 0;
-
- do
- {
- int chunk_length = sbChunk.m_ChunkLength;
- offset += chunk_length;
-
- ReadOnlySpan<char> chunk = new ReadOnlySpan<char>(sbChunk.m_ChunkChars, 0, chunk_length);
-
- if (!chunk.EqualsOrdinal(span.Slice(span.Length - offset, chunk_length)))
- {
- return false;
- }
-
- sbChunk = sbChunk.m_ChunkPrevious;
- } while (sbChunk != null);
-
- Debug.Assert(offset == Length);
- return true;
- }
-
- /// <summary>
- /// Replaces all instances of one string with another in part of this builder.
- /// </summary>
- /// <param name="oldValue">The string to replace.</param>
- /// <param name="newValue">The string to replace <paramref name="oldValue"/> with.</param>
- /// <param name="startIndex">The index to start in this builder.</param>
- /// <param name="count">The number of characters to read in this builder.</param>
- /// <remarks>
- /// If <paramref name="newValue"/> is <c>null</c>, instances of <paramref name="oldValue"/>
- /// are removed from this builder.
- /// </remarks>
- public StringBuilder Replace(string oldValue, string? newValue, int startIndex, int count)
- {
- int currentLength = Length;
- if ((uint)startIndex > (uint)currentLength)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
- if (count < 0 || startIndex > currentLength - count)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Index);
- }
- if (oldValue == null)
- {
- throw new ArgumentNullException(nameof(oldValue));
- }
- if (oldValue.Length == 0)
- {
- throw new ArgumentException(SR.Argument_EmptyName, nameof(oldValue));
- }
-
- newValue ??= string.Empty;
-
- int[]? replacements = null; // A list of replacement positions in a chunk to apply
- int replacementsCount = 0;
-
- // Find the chunk, indexInChunk for the starting point
- StringBuilder chunk = FindChunkForIndex(startIndex);
- int indexInChunk = startIndex - chunk.m_ChunkOffset;
- while (count > 0)
- {
- Debug.Assert(chunk != null, "chunk was null in replace");
- // Look for a match in the chunk,indexInChunk pointer
- if (StartsWith(chunk, indexInChunk, count, oldValue))
- {
- // Push it on the replacements array (with growth), we will do all replacements in a
- // given chunk in one operation below (see ReplaceAllInChunk) so we don't have to slide
- // many times.
- if (replacements == null)
- {
- replacements = new int[5];
- }
- else if (replacementsCount >= replacements.Length)
- {
- Array.Resize(ref replacements, replacements.Length * 3 / 2 + 4); // Grow by ~1.5x, but more in the begining
- }
- replacements[replacementsCount++] = indexInChunk;
- indexInChunk += oldValue.Length;
- count -= oldValue.Length;
- }
- else
- {
- indexInChunk++;
- --count;
- }
-
- if (indexInChunk >= chunk.m_ChunkLength || count == 0) // Have we moved out of the current chunk?
- {
- // Replacing mutates the blocks, so we need to convert to a logical index and back afterwards.
- int index = indexInChunk + chunk.m_ChunkOffset;
-
- // See if we accumulated any replacements, if so apply them.
- Debug.Assert(replacements != null || replacementsCount == 0, "replacements was null and replacementsCount != 0");
- ReplaceAllInChunk(replacements, replacementsCount, chunk, oldValue.Length, newValue);
- // The replacement has affected the logical index. Adjust it.
- index += ((newValue.Length - oldValue.Length) * replacementsCount);
- replacementsCount = 0;
-
- chunk = FindChunkForIndex(index);
- indexInChunk = index - chunk.m_ChunkOffset;
- Debug.Assert(chunk != null || count == 0, "Chunks ended prematurely!");
- }
- }
-
- AssertInvariants();
- return this;
- }
-
- /// <summary>
- /// Replaces all instances of one character with another in this builder.
- /// </summary>
- /// <param name="oldChar">The character to replace.</param>
- /// <param name="newChar">The character to replace <paramref name="oldChar"/> with.</param>
- public StringBuilder Replace(char oldChar, char newChar)
- {
- return Replace(oldChar, newChar, 0, Length);
- }
-
- /// <summary>
- /// Replaces all instances of one character with another in this builder.
- /// </summary>
- /// <param name="oldChar">The character to replace.</param>
- /// <param name="newChar">The character to replace <paramref name="oldChar"/> with.</param>
- /// <param name="startIndex">The index to start in this builder.</param>
- /// <param name="count">The number of characters to read in this builder.</param>
- public StringBuilder Replace(char oldChar, char newChar, int startIndex, int count)
- {
- int currentLength = Length;
- if ((uint)startIndex > (uint)currentLength)
- {
- throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
- }
-
- if (count < 0 || startIndex > currentLength - count)
- {
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Index);
- }
-
- int endIndex = startIndex + count;
- StringBuilder chunk = this;
-
- while (true)
- {
- int endIndexInChunk = endIndex - chunk.m_ChunkOffset;
- int startIndexInChunk = startIndex - chunk.m_ChunkOffset;
- if (endIndexInChunk >= 0)
- {
- int curInChunk = Math.Max(startIndexInChunk, 0);
- int endInChunk = Math.Min(chunk.m_ChunkLength, endIndexInChunk);
- while (curInChunk < endInChunk)
- {
- if (chunk.m_ChunkChars[curInChunk] == oldChar)
- chunk.m_ChunkChars[curInChunk] = newChar;
- curInChunk++;
- }
- }
- if (startIndexInChunk >= 0)
- {
- break;
- }
-
- Debug.Assert(chunk.m_ChunkPrevious != null);
- chunk = chunk.m_ChunkPrevious;
- }
-
- AssertInvariants();
- return this;
- }
-
- /// <summary>
- /// Appends a character buffer to this builder.
- /// </summary>
- /// <param name="value">The pointer to the start of the buffer.</param>
- /// <param name="valueCount">The number of characters in the buffer.</param>
- [CLSCompliant(false)]
- public unsafe StringBuilder Append(char* value, int valueCount)
- {
- // We don't check null value as this case will throw null reference exception anyway
- if (valueCount < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(valueCount), SR.ArgumentOutOfRange_NegativeCount);
- }
-
- // this is where we can check if the valueCount will put us over m_MaxCapacity
- // We are doing the check here to prevent the corruption of the StringBuilder.
- int newLength = Length + valueCount;
- if (newLength > m_MaxCapacity || newLength < valueCount)
- {
- throw new ArgumentOutOfRangeException(nameof(valueCount), SR.ArgumentOutOfRange_LengthGreaterThanCapacity);
- }
-
- // This case is so common we want to optimize for it heavily.
- int newIndex = valueCount + m_ChunkLength;
- if (newIndex <= m_ChunkChars.Length)
- {
- ThreadSafeCopy(value, m_ChunkChars, m_ChunkLength, valueCount);
- m_ChunkLength = newIndex;
- }
- else
- {
- // Copy the first chunk
- int firstLength = m_ChunkChars.Length - m_ChunkLength;
- if (firstLength > 0)
- {
- ThreadSafeCopy(value, m_ChunkChars, m_ChunkLength, firstLength);
- m_ChunkLength = m_ChunkChars.Length;
- }
-
- // Expand the builder to add another chunk.
- int restLength = valueCount - firstLength;
- ExpandByABlock(restLength);
- Debug.Assert(m_ChunkLength == 0, "A new block was not created.");
-
- // Copy the second chunk
- ThreadSafeCopy(value + firstLength, m_ChunkChars, 0, restLength);
- m_ChunkLength = restLength;
- }
- AssertInvariants();
- return this;
- }
-
- /// <summary>
- /// Inserts a character buffer into this builder at the specified position.
- /// </summary>
- /// <param name="index">The index to insert in this builder.</param>
- /// <param name="value">The pointer to the start of the buffer.</param>
- /// <param name="valueCount">The number of characters in the buffer.</param>
- private unsafe void Insert(int index, char* value, int valueCount)
- {
- if ((uint)index > (uint)Length)
- {
- throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- }
-
- if (valueCount > 0)
- {
- StringBuilder chunk;
- int indexInChunk;
- MakeRoom(index, valueCount, out chunk, out indexInChunk, false);
- ReplaceInPlaceAtChunk(ref chunk!, ref indexInChunk, value, valueCount);
- }
- }
-
- /// <summary>
- /// Replaces strings at specified indices with a new string in a chunk.
- /// </summary>
- /// <param name="replacements">The list of indices, relative to the beginning of the chunk, to remove at.</param>
- /// <param name="replacementsCount">The number of replacements to make.</param>
- /// <param name="sourceChunk">The source chunk.</param>
- /// <param name="removeCount">The number of characters to remove at each replacement.</param>
- /// <param name="value">The string to insert at each replacement.</param>
- /// <remarks>
- /// This routine is very efficient because it does replacements in bulk.
- /// </remarks>
- private void ReplaceAllInChunk(int[]? replacements, int replacementsCount, StringBuilder sourceChunk, int removeCount, string value)
- {
- if (replacementsCount <= 0)
- {
- return;
- }
-
- unsafe
- {
- fixed (char* valuePtr = value)
- {
- Debug.Assert(replacements != null, "replacements was null when replacementsCount > 0");
- // calculate the total amount of extra space or space needed for all the replacements.
- long longDelta = (value.Length - removeCount) * (long)replacementsCount;
- int delta = (int)longDelta;
- if (delta != longDelta)
- {
- throw new OutOfMemoryException();
- }
-
- StringBuilder targetChunk = sourceChunk; // the target as we copy chars down
- int targetIndexInChunk = replacements[0];
-
- // Make the room needed for all the new characters if needed.
- if (delta > 0)
- {
- MakeRoom(targetChunk.m_ChunkOffset + targetIndexInChunk, delta, out targetChunk, out targetIndexInChunk, true);
- }
-
- // We made certain that characters after the insertion point are not moved,
- int i = 0;
- while (true)
- {
- // Copy in the new string for the ith replacement
- ReplaceInPlaceAtChunk(ref targetChunk!, ref targetIndexInChunk, valuePtr, value.Length);
- int gapStart = replacements[i] + removeCount;
- i++;
- if (i >= replacementsCount)
- {
- break;
- }
-
- int gapEnd = replacements[i];
- Debug.Assert(gapStart < sourceChunk.m_ChunkChars.Length, "gap starts at end of buffer. Should not happen");
- Debug.Assert(gapStart <= gapEnd, "negative gap size");
- Debug.Assert(gapEnd <= sourceChunk.m_ChunkLength, "gap too big");
- if (delta != 0) // can skip the sliding of gaps if source an target string are the same size.
- {
- // Copy the gap data between the current replacement and the next replacement
- fixed (char* sourcePtr = &sourceChunk.m_ChunkChars[gapStart])
- ReplaceInPlaceAtChunk(ref targetChunk!, ref targetIndexInChunk, sourcePtr, gapEnd - gapStart);
- }
- else
- {
- targetIndexInChunk += gapEnd - gapStart;
- Debug.Assert(targetIndexInChunk <= targetChunk.m_ChunkLength, "gap not in chunk");
- }
- }
-
- // Remove extra space if necessary.
- if (delta < 0)
- {
- Remove(targetChunk.m_ChunkOffset + targetIndexInChunk, -delta, out targetChunk, out targetIndexInChunk);
- }
- }
- }
- }
-
- /// <summary>
- /// Returns a value indicating whether a substring of a builder starts with a specified prefix.
- /// </summary>
- /// <param name="chunk">The chunk in which the substring starts.</param>
- /// <param name="indexInChunk">The index in <paramref name="chunk"/> at which the substring starts.</param>
- /// <param name="count">The logical count of the substring.</param>
- /// <param name="value">The prefix.</param>
- private bool StartsWith(StringBuilder chunk, int indexInChunk, int count, string value)
- {
- for (int i = 0; i < value.Length; i++)
- {
- if (count == 0)
- {
- return false;
- }
-
- if (indexInChunk >= chunk.m_ChunkLength)
- {
- chunk = Next(chunk)!;
- if (chunk == null)
- {
- return false;
- }
- indexInChunk = 0;
- }
-
- if (value[i] != chunk.m_ChunkChars[indexInChunk])
- {
- return false;
- }
-
- indexInChunk++;
- --count;
- }
-
- return true;
- }
-
- /// <summary>
- /// Replaces characters at a specified location with the contents of a character buffer.
- /// This function is the logical equivalent of memcpy.
- /// </summary>
- /// <param name="chunk">
- /// The chunk in which to start replacing characters.
- /// Receives the chunk in which character replacement ends.
- /// </param>
- /// <param name="indexInChunk">
- /// The index in <paramref name="chunk"/> to start replacing characters at.
- /// Receives the index at which character replacement ends.
- /// </param>
- /// <param name="value">The pointer to the start of the character buffer.</param>
- /// <param name="count">The number of characters in the buffer.</param>
- private unsafe void ReplaceInPlaceAtChunk(ref StringBuilder? chunk, ref int indexInChunk, char* value, int count)
- {
- if (count != 0)
- {
- while (true)
- {
- Debug.Assert(chunk != null, "chunk should not be null at this point");
- int lengthInChunk = chunk.m_ChunkLength - indexInChunk;
- Debug.Assert(lengthInChunk >= 0, "Index isn't in the chunk.");
-
- int lengthToCopy = Math.Min(lengthInChunk, count);
- ThreadSafeCopy(value, chunk.m_ChunkChars, indexInChunk, lengthToCopy);
-
- // Advance the index.
- indexInChunk += lengthToCopy;
- if (indexInChunk >= chunk.m_ChunkLength)
- {
- chunk = Next(chunk);
- indexInChunk = 0;
- }
- count -= lengthToCopy;
- if (count == 0)
- {
- break;
- }
- value += lengthToCopy;
- }
- }
- }
-
- /// <remarks>
- /// This method prevents out-of-bounds writes in the case a different thread updates a field in the builder just before a copy begins.
- /// All interesting variables are copied out of the heap into the parameters of this method, and then bounds checks are run.
- /// </remarks>
- private static unsafe void ThreadSafeCopy(char* sourcePtr, char[] destination, int destinationIndex, int count)
- {
- if (count > 0)
- {
- if ((uint)destinationIndex <= (uint)destination.Length && (destinationIndex + count) <= destination.Length)
- {
- fixed (char* destinationPtr = &destination[destinationIndex])
- string.wstrcpy(destinationPtr, sourcePtr, count);
- }
- else
- {
- throw new ArgumentOutOfRangeException(nameof(destinationIndex), SR.ArgumentOutOfRange_Index);
- }
- }
- }
-
- private static unsafe void ThreadSafeCopy(char[] source, int sourceIndex, Span<char> destination, int destinationIndex, int count)
- {
- if (count > 0)
- {
- if ((uint)sourceIndex > (uint)source.Length || count > source.Length - sourceIndex)
- {
- throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_Index);
- }
-
- if ((uint)destinationIndex > (uint)destination.Length || count > destination.Length - destinationIndex)
- {
- throw new ArgumentOutOfRangeException(nameof(destinationIndex), SR.ArgumentOutOfRange_Index);
- }
-
- fixed (char* sourcePtr = &source[sourceIndex])
- fixed (char* destinationPtr = &MemoryMarshal.GetReference(destination))
- string.wstrcpy(destinationPtr + destinationIndex, sourcePtr, count);
- }
- }
-
- /// <summary>
- /// Gets the chunk corresponding to the logical index in this builder.
- /// </summary>
- /// <param name="index">The logical index in this builder.</param>
- /// <remarks>
- /// After calling this method, you can obtain the actual index within the chunk by
- /// subtracting <see cref="m_ChunkOffset"/> from <paramref name="index"/>.
- /// </remarks>
- private StringBuilder FindChunkForIndex(int index)
- {
- Debug.Assert(0 <= index && index <= Length);
-
- StringBuilder result = this;
- while (result.m_ChunkOffset > index)
- {
- Debug.Assert(result.m_ChunkPrevious != null);
- result = result.m_ChunkPrevious;
- }
-
- Debug.Assert(result != null);
- return result;
- }
-
- /// <summary>Gets a span representing the remaining space available in the current chunk.</summary>
- private Span<char> RemainingCurrentChunk
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => new Span<char>(m_ChunkChars, m_ChunkLength, m_ChunkChars.Length - m_ChunkLength);
- }
-
- /// <summary>
- /// Finds the chunk that logically succeeds the specified chunk.
- /// </summary>
- /// <param name="chunk">The chunk whose successor should be found.</param>
- /// <remarks>
- /// Each chunk only stores the pointer to its logical predecessor, so this routine has to start
- /// from the 'this' pointer (which is assumed to represent the whole StringBuilder) and work its
- /// way down until it finds the specified chunk (which is O(n)). Thus, it is more expensive than
- /// a field fetch.
- /// </remarks>
- private StringBuilder? Next(StringBuilder chunk) => chunk == this ? null : FindChunkForIndex(chunk.m_ChunkOffset + chunk.m_ChunkLength);
-
- /// <summary>
- /// Transfers the character buffer from this chunk to a new chunk, and allocates a new buffer with a minimum size for this chunk.
- /// </summary>
- /// <param name="minBlockCharCount">The minimum size of the new buffer to be allocated for this chunk.</param>
- /// <remarks>
- /// This method requires that the current chunk is full. Otherwise, there's no point in shifting the characters over.
- /// It also assumes that 'this' is the last chunk in the linked list.
- /// </remarks>
- private void ExpandByABlock(int minBlockCharCount)
- {
- Debug.Assert(Capacity == Length, nameof(ExpandByABlock) + " should only be called when there is no space left.");
- Debug.Assert(minBlockCharCount > 0);
-
- AssertInvariants();
-
- if ((minBlockCharCount + Length) > m_MaxCapacity || minBlockCharCount + Length < minBlockCharCount)
- {
- throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
- }
-
- // - We always need to make the new chunk at least as big as was requested (`minBlockCharCount`).
- // - We'd also prefer to make it at least at big as the current length (thus doubling capacity).
- // - But this is only up to a maximum, so we stay in the small object heap, and never allocate
- // really big chunks even if the string gets really big.
- int newBlockLength = Math.Max(minBlockCharCount, Math.Min(Length, MaxChunkSize));
-
- // Check for integer overflow (logical buffer size > int.MaxValue)
- if (m_ChunkOffset + m_ChunkLength + newBlockLength < newBlockLength)
- {
- throw new OutOfMemoryException();
- }
-
- // Allocate the array before updating any state to avoid leaving inconsistent state behind in case of out of memory exception
- char[] chunkChars = GC.AllocateUninitializedArray<char>(newBlockLength);
-
- // Move all of the data from this chunk to a new one, via a few O(1) pointer adjustments.
- // Then, have this chunk point to the new one as its predecessor.
- m_ChunkPrevious = new StringBuilder(this);
- m_ChunkOffset += m_ChunkLength;
- m_ChunkLength = 0;
-
- m_ChunkChars = chunkChars;
-
- AssertInvariants();
- }
-
- /// <summary>
- /// Creates a new chunk with fields copied from an existing chunk.
- /// </summary>
- /// <param name="from">The chunk from which to copy fields.</param>
- /// <remarks>
- /// <para>
- /// This method runs in O(1) time. It does not copy data within the character buffer
- /// <paramref name="from"/> holds, but copies the reference to the character buffer itself
- /// (plus a few other fields).
- /// </para>
- /// <para>
- /// Callers are expected to update <paramref name="from"/> subsequently to point to this
- /// chunk as its predecessor.
- /// </para>
- /// </remarks>
- private StringBuilder(StringBuilder from)
- {
- m_ChunkLength = from.m_ChunkLength;
- m_ChunkOffset = from.m_ChunkOffset;
- m_ChunkChars = from.m_ChunkChars;
- m_ChunkPrevious = from.m_ChunkPrevious;
- m_MaxCapacity = from.m_MaxCapacity;
-
- AssertInvariants();
- }
-
- /// <summary>
- /// Creates a gap at a logical index with the specified count.
- /// </summary>
- /// <param name="index">The logical index in this builder.</param>
- /// <param name="count">The number of characters in the gap.</param>
- /// <param name="chunk">Receives the chunk containing the gap.</param>
- /// <param name="indexInChunk">The index in <paramref name="chunk"/> that points to the gap.</param>
- /// <param name="doNotMoveFollowingChars">
- /// - If <c>true</c>, then room must be made by inserting a chunk before the current chunk.
- /// - If <c>false</c>, then room can be made by shifting characters ahead of <paramref name="index"/>
- /// in this block forward by <paramref name="count"/> provided the characters will still fit in
- /// the current chunk after being shifted.
- /// - Providing <c>false</c> does not make a difference most of the time, but it can matter when someone
- /// inserts lots of small strings at a position in the buffer.
- /// </param>
- /// <remarks>
- /// <para>
- /// Since chunks do not contain references to their successors, it is not always possible for us to make room
- /// by inserting space after <paramref name="index"/> in case this chunk runs out of space. Thus, we make room
- /// by inserting space before the specified index, and having logical indices refer to new locations by the end
- /// of this method.
- /// </para>
- /// <para>
- /// <see cref="ReplaceInPlaceAtChunk"/> can be used in conjunction with this method to fill in the newly created gap.
- /// </para>
- /// </remarks>
- private void MakeRoom(int index, int count, out StringBuilder chunk, out int indexInChunk, bool doNotMoveFollowingChars)
- {
- AssertInvariants();
- Debug.Assert(count > 0);
- Debug.Assert(index >= 0);
-
- if (count + Length > m_MaxCapacity || count + Length < count)
- {
- throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
- }
-
- chunk = this;
- while (chunk.m_ChunkOffset > index)
- {
- chunk.m_ChunkOffset += count;
- Debug.Assert(chunk.m_ChunkPrevious != null);
- chunk = chunk.m_ChunkPrevious;
- }
- indexInChunk = index - chunk.m_ChunkOffset;
-
- // Cool, we have some space in this block, and we don't have to copy much to get at it, so go ahead and use it.
- // This typically happens when someone repeatedly inserts small strings at a spot (usually the absolute front) of the buffer.
- if (!doNotMoveFollowingChars && chunk.m_ChunkLength <= DefaultCapacity * 2 && chunk.m_ChunkChars.Length - chunk.m_ChunkLength >= count)
- {
- for (int i = chunk.m_ChunkLength; i > indexInChunk;)
- {
- --i;
- chunk.m_ChunkChars[i + count] = chunk.m_ChunkChars[i];
- }
- chunk.m_ChunkLength += count;
- return;
- }
-
- // Allocate space for the new chunk, which will go before the current one.
- StringBuilder newChunk = new StringBuilder(Math.Max(count, DefaultCapacity), chunk.m_MaxCapacity, chunk.m_ChunkPrevious);
- newChunk.m_ChunkLength = count;
-
- // Copy the head of the current buffer to the new buffer.
- int copyCount1 = Math.Min(count, indexInChunk);
- if (copyCount1 > 0)
- {
- unsafe
- {
- fixed (char* chunkCharsPtr = &chunk.m_ChunkChars[0])
- {
- ThreadSafeCopy(chunkCharsPtr, newChunk.m_ChunkChars, 0, copyCount1);
-
- // Slide characters over in the current buffer to make room.
- int copyCount2 = indexInChunk - copyCount1;
- if (copyCount2 >= 0)
- {
- ThreadSafeCopy(chunkCharsPtr + copyCount1, chunk.m_ChunkChars, 0, copyCount2);
- indexInChunk = copyCount2;
- }
- }
- }
- }
-
- // Wire in the new chunk.
- chunk.m_ChunkPrevious = newChunk;
- chunk.m_ChunkOffset += count;
- if (copyCount1 < count)
- {
- chunk = newChunk;
- indexInChunk = copyCount1;
- }
-
- AssertInvariants();
- }
-
- /// <summary>
- /// Used by <see cref="MakeRoom"/> to allocate another chunk.
- /// </summary>
- /// <param name="size">The size of the character buffer for this chunk.</param>
- /// <param name="maxCapacity">The maximum capacity, to be stored in this chunk.</param>
- /// <param name="previousBlock">The predecessor of this chunk.</param>
- private StringBuilder(int size, int maxCapacity, StringBuilder? previousBlock)
- {
- Debug.Assert(size > 0);
- Debug.Assert(maxCapacity > 0);
-
- m_ChunkChars = GC.AllocateUninitializedArray<char>(size);
- m_MaxCapacity = maxCapacity;
- m_ChunkPrevious = previousBlock;
- if (previousBlock != null)
- {
- m_ChunkOffset = previousBlock.m_ChunkOffset + previousBlock.m_ChunkLength;
- }
-
- AssertInvariants();
- }
-
- /// <summary>
- /// Removes a specified number of characters beginning at a logical index in this builder.
- /// </summary>
- /// <param name="startIndex">The logical index in this builder to start removing characters.</param>
- /// <param name="count">The number of characters to remove.</param>
- /// <param name="chunk">Receives the new chunk containing the logical index.</param>
- /// <param name="indexInChunk">
- /// Receives the new index in <paramref name="chunk"/> that is associated with the logical index.
- /// </param>
- private void Remove(int startIndex, int count, out StringBuilder chunk, out int indexInChunk)
- {
- AssertInvariants();
- Debug.Assert(startIndex >= 0 && startIndex < Length);
-
- int endIndex = startIndex + count;
-
- // Find the chunks for the start and end of the block to delete.
- chunk = this;
- StringBuilder? endChunk = null;
- int endIndexInChunk = 0;
- while (true)
- {
- if (endIndex - chunk.m_ChunkOffset >= 0)
- {
- if (endChunk == null)
- {
- endChunk = chunk;
- endIndexInChunk = endIndex - endChunk.m_ChunkOffset;
- }
- if (startIndex - chunk.m_ChunkOffset >= 0)
- {
- indexInChunk = startIndex - chunk.m_ChunkOffset;
- break;
- }
- }
- else
- {
- chunk.m_ChunkOffset -= count;
- }
-
- Debug.Assert(chunk.m_ChunkPrevious != null);
- chunk = chunk.m_ChunkPrevious;
- }
- Debug.Assert(chunk != null, "We fell off the beginning of the string!");
-
- int copyTargetIndexInChunk = indexInChunk;
- int copyCount = endChunk.m_ChunkLength - endIndexInChunk;
- if (endChunk != chunk)
- {
- copyTargetIndexInChunk = 0;
- // Remove the characters after `startIndex` to the end of the chunk.
- chunk.m_ChunkLength = indexInChunk;
-
- // Remove the characters in chunks between the start and the end chunk.
- endChunk.m_ChunkPrevious = chunk;
- endChunk.m_ChunkOffset = chunk.m_ChunkOffset + chunk.m_ChunkLength;
-
- // If the start is 0, then we can throw away the whole start chunk.
- if (indexInChunk == 0)
- {
- endChunk.m_ChunkPrevious = chunk.m_ChunkPrevious;
- chunk = endChunk;
- }
- }
- endChunk.m_ChunkLength -= (endIndexInChunk - copyTargetIndexInChunk);
-
- // SafeCritical: We ensure that `endIndexInChunk + copyCount` is within range of `m_ChunkChars`, and
- // also ensure that `copyTargetIndexInChunk + copyCount` is within the chunk.
-
- // Remove any characters in the end chunk, by sliding the characters down.
- if (copyTargetIndexInChunk != endIndexInChunk) // Sometimes no move is necessary
- {
- ThreadSafeCopy(endChunk.m_ChunkChars, endIndexInChunk, endChunk.m_ChunkChars, copyTargetIndexInChunk, copyCount);
- }
-
- Debug.Assert(chunk != null, "We fell off the beginning of the string!");
- AssertInvariants();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/StringBuilderCache.cs b/netcore/System.Private.CoreLib/shared/System/Text/StringBuilderCache.cs
deleted file mode 100644
index aac2c2e8a9a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/StringBuilderCache.cs
+++ /dev/null
@@ -1,64 +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.
-
-#nullable enable
-namespace System.Text
-{
- /// <summary>Provide a cached reusable instance of stringbuilder per thread.</summary>
- internal static class StringBuilderCache
- {
- // The value 360 was chosen in discussion with performance experts as a compromise between using
- // as litle memory per thread as possible and still covering a large part of short-lived
- // StringBuilder creations on the startup path of VS designers.
- private const int MaxBuilderSize = 360;
- private const int DefaultCapacity = 16; // == StringBuilder.DefaultCapacity
-
- // WARNING: We allow diagnostic tools to directly inspect this member (t_cachedInstance).
- // 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.
- [ThreadStatic]
- private static StringBuilder? t_cachedInstance;
-
- /// <summary>Get a StringBuilder for the specified capacity.</summary>
- /// <remarks>If a StringBuilder of an appropriate size is cached, it will be returned and the cache emptied.</remarks>
- public static StringBuilder Acquire(int capacity = DefaultCapacity)
- {
- if (capacity <= MaxBuilderSize)
- {
- StringBuilder? sb = t_cachedInstance;
- if (sb != null)
- {
- // Avoid stringbuilder block fragmentation by getting a new StringBuilder
- // when the requested size is larger than the current capacity
- if (capacity <= sb.Capacity)
- {
- t_cachedInstance = null;
- sb.Clear();
- return sb;
- }
- }
- }
-
- return new StringBuilder(capacity);
- }
-
- /// <summary>Place the specified builder in the cache if it is not too big.</summary>
- public static void Release(StringBuilder sb)
- {
- if (sb.Capacity <= MaxBuilderSize)
- {
- t_cachedInstance = sb;
- }
- }
-
- /// <summary>ToString() the stringbuilder, Release it to the cache, and return the resulting string.</summary>
- public static string GetStringAndRelease(StringBuilder sb)
- {
- string result = sb.ToString();
- Release(sb);
- return result;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/StringRuneEnumerator.cs b/netcore/System.Private.CoreLib/shared/System/Text/StringRuneEnumerator.cs
deleted file mode 100644
index 37c45db2654..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/StringRuneEnumerator.cs
+++ /dev/null
@@ -1,70 +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 System.Collections;
-using System.Collections.Generic;
-
-namespace System.Text
-{
- // An enumerator for retrieving System.Text.Rune instances from a System.String.
- public struct StringRuneEnumerator : IEnumerable<Rune>, IEnumerator<Rune>
- {
- private readonly string _string;
- private Rune _current;
- private int _nextIndex;
-
- internal StringRuneEnumerator(string value)
- {
- _string = value;
- _current = default;
- _nextIndex = 0;
- }
-
- public Rune Current => _current;
-
- public StringRuneEnumerator GetEnumerator() => this;
-
- public bool MoveNext()
- {
- if ((uint)_nextIndex >= _string.Length)
- {
- // reached the end of the string
- _current = default;
- return false;
- }
-
- if (!Rune.TryGetRuneAt(_string, _nextIndex, out _current))
- {
- // replace invalid sequences with U+FFFD
- _current = Rune.ReplacementChar;
- }
-
- // In UTF-16 specifically, invalid sequences always have length 1, which is the same
- // length as the replacement character U+FFFD. This means that we can always bump the
- // next index by the current scalar's UTF-16 sequence length. This optimization is not
- // generally applicable; for example, enumerating scalars from UTF-8 cannot utilize
- // this same trick.
-
- _nextIndex += _current.Utf16SequenceLength;
- return true;
- }
-
- object? IEnumerator.Current => _current;
-
- void IDisposable.Dispose()
- {
- // no-op
- }
-
- IEnumerator IEnumerable.GetEnumerator() => this;
-
- IEnumerator<Rune> IEnumerable<Rune>.GetEnumerator() => this;
-
- void IEnumerator.Reset()
- {
- _current = default;
- _nextIndex = 0;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/TrimType.cs b/netcore/System.Private.CoreLib/shared/System/Text/TrimType.cs
deleted file mode 100644
index 76df3276cfa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/TrimType.cs
+++ /dev/null
@@ -1,28 +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.
-
-namespace System.Text
-{
- /// <summary>
- /// Specifies which portions of the string should be trimmed in a trimming operation.
- /// </summary>
- [Flags]
- internal enum TrimType
- {
- /// <summary>
- /// Trim from the beginning of the string.
- /// </summary>
- Head = 1 << 0,
-
- /// <summary>
- /// Trim from the end of the string.
- /// </summary>
- Tail = 1 << 1,
-
- /// <summary>
- /// Trim from both the beginning and the end of the string.
- /// </summary>
- Both = Head | Tail
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/UTF32Encoding.cs b/netcore/System.Private.CoreLib/shared/System/Text/UTF32Encoding.cs
deleted file mode 100644
index e300db5de32..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/UTF32Encoding.cs
+++ /dev/null
@@ -1,1192 +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.
-
-//
-// Don't override IsAlwaysNormalized because it is just a Unicode Transformation and could be confused.
-//
-
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Text
-{
- // Encodes text into and out of UTF-32. UTF-32 is a way of writing
- // Unicode characters with a single storage unit (32 bits) per character,
- //
- // The UTF-32 byte order mark is simply the Unicode byte order mark
- // (0x00FEFF) written in UTF-32 (0x0000FEFF or 0xFFFE0000). The byte order
- // mark is used mostly to distinguish UTF-32 text from other encodings, and doesn't
- // switch the byte orderings.
-
- public sealed class UTF32Encoding : Encoding
- {
- /*
- words bits UTF-32 representation
- ----- ---- -----------------------------------
- 1 16 00000000 00000000 xxxxxxxx xxxxxxxx
- 2 21 00000000 000xxxxx hhhhhhll llllllll
- ----- ---- -----------------------------------
-
- Surrogate:
- Real Unicode value = (HighSurrogate - 0xD800) * 0x400 + (LowSurrogate - 0xDC00) + 0x10000
- */
-
- // Used by Encoding.UTF32/BigEndianUTF32 for lazy initialization
- // The initialization code will not be run until a static member of the class is referenced
- internal static readonly UTF32Encoding s_default = new UTF32Encoding(bigEndian: false, byteOrderMark: true);
- internal static readonly UTF32Encoding s_bigEndianDefault = new UTF32Encoding(bigEndian: true, byteOrderMark: true);
-
- private readonly bool _emitUTF32ByteOrderMark = false;
- private readonly bool _isThrowException = false;
- private readonly bool _bigEndian = false;
-
- public UTF32Encoding() : this(false, true)
- {
- }
-
- public UTF32Encoding(bool bigEndian, bool byteOrderMark) :
- base(bigEndian ? 12001 : 12000)
- {
- _bigEndian = bigEndian;
- _emitUTF32ByteOrderMark = byteOrderMark;
- }
-
- public UTF32Encoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidCharacters) :
- this(bigEndian, byteOrderMark)
- {
- _isThrowException = throwOnInvalidCharacters;
-
- // Encoding constructor already did this, but it'll be wrong if we're throwing exceptions
- if (_isThrowException)
- SetDefaultFallbacks();
- }
-
- internal override void SetDefaultFallbacks()
- {
- // For UTF-X encodings, we use a replacement fallback with an empty string
- if (_isThrowException)
- {
- this.encoderFallback = EncoderFallback.ExceptionFallback;
- this.decoderFallback = DecoderFallback.ExceptionFallback;
- }
- else
- {
- this.encoderFallback = new EncoderReplacementFallback("\xFFFD");
- this.decoderFallback = new DecoderReplacementFallback("\xFFFD");
- }
- }
-
- // The following methods are copied from EncodingNLS.cs.
- // Unfortunately EncodingNLS.cs is internal and we're public, so we have to re-implement them here.
- // These should be kept in sync for the following classes:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- // Returns the number of bytes required to encode a range of characters in
- // a character array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetByteCount(char[] chars, int index, int count)
- {
- // Validate input parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // If no input, return 0, avoid fixed empty array problem
- if (count == 0)
- return 0;
-
- // Just call the pointer version
- fixed (char* pChars = chars)
- return GetByteCount(pChars + index, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetByteCount(string s)
- {
- // Validate input
- if (s == null)
- throw new ArgumentNullException(nameof(s));
-
- fixed (char* pChars = s)
- return GetByteCount(pChars, s.Length, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetByteCount(char* chars, int count)
- {
- // Validate Parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars), SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Call it with empty encoder
- return GetByteCount(chars, count, null);
- }
-
- // Parent method is safe.
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- public override unsafe int GetBytes(string s, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- if (s == null || bytes == null)
- throw new ArgumentNullException(s == null ? nameof(s) : nameof(bytes), SR.ArgumentNull_Array);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (s.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(s), SR.ArgumentOutOfRange_IndexCount);
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index);
-
- int byteCount = bytes.Length - byteIndex;
-
- fixed (char* pChars = s) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
- }
-
- // Encodes a range of characters in a character array into a range of bytes
- // in a byte array. An exception occurs if the byte array is not large
- // enough to hold the complete encoding of the characters. The
- // GetByteCount method can be used to determine the exact number of
- // bytes that will be produced for a given range of characters.
- // Alternatively, the GetMaxByteCount method can be used to
- // determine the maximum number of bytes that will be produced for a given
- // number of characters, regardless of the actual character values.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes), SR.ArgumentNull_Array);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index);
-
- // If nothing to encode return 0, avoid fixed problem
- if (charCount == 0)
- return 0;
-
- // Just call pointer version
- int byteCount = bytes.Length - byteIndex;
-
- fixed (char* pChars = chars) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- // Remember that byteCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetBytes(chars, charCount, bytes, byteCount, null);
- }
-
- // Returns the number of characters produced by decoding a range of bytes
- // in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetCharCount(byte[] bytes, int index, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // If no input just return 0, fixed doesn't like 0 length arrays.
- if (count == 0)
- return 0;
-
- // Just call pointer version
- fixed (byte* pBytes = bytes)
- return GetCharCount(pBytes + index, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetCharCount(byte* bytes, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetCharCount(bytes, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (byteIndex < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(byteIndex < 0 ? nameof(byteIndex) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - byteIndex < byteCount)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (charIndex < 0 || charIndex > chars.Length)
- throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_Index);
-
- // If no input, return 0 & avoid fixed problem
- if (byteCount == 0)
- return 0;
-
- // Just call pointer version
- int charCount = chars.Length - charIndex;
-
- fixed (byte* pBytes = bytes) fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
- // Remember that charCount is # to decode, not size of array
- return GetChars(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetChars(byte* bytes, int byteCount, char* chars, int charCount)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetChars(bytes, byteCount, chars, charCount, null);
- }
-
- // Returns a string containing the decoded representation of a range of
- // bytes in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe string GetString(byte[] bytes, int index, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // Avoid problems with empty input buffer
- if (count == 0) return string.Empty;
-
- fixed (byte* pBytes = bytes)
- return string.CreateStringFromEncoding(
- pBytes + index, count, this);
- }
-
- //
- // End of standard methods copied from EncodingNLS.cs
- //
- internal override unsafe int GetByteCount(char* chars, int count, EncoderNLS? encoder)
- {
- Debug.Assert(chars != null, "[UTF32Encoding.GetByteCount]chars!=null");
- Debug.Assert(count >= 0, "[UTF32Encoding.GetByteCount]count >=0");
-
- char* end = chars + count;
- char* charStart = chars;
- int byteCount = 0;
-
- char highSurrogate = '\0';
-
- // For fallback we may need a fallback buffer
- EncoderFallbackBuffer? fallbackBuffer = null;
- char* charsForFallback;
-
- if (encoder != null)
- {
- highSurrogate = encoder._charLeftOver;
- fallbackBuffer = encoder.FallbackBuffer;
-
- // We mustn't have left over fallback data when counting
- if (fallbackBuffer.Remaining > 0)
- throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty, this.EncodingName, encoder.Fallback?.GetType().ToString() ?? string.Empty));
- }
- else
- {
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- }
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, end, encoder, false);
-
- char ch;
- TryAgain:
-
- while (((ch = fallbackBuffer.InternalGetNextChar()) != 0) || chars < end)
- {
- // First unwind any fallback
- if (ch == 0)
- {
- // No fallback, just get next char
- ch = *chars;
- chars++;
- }
-
- // Do we need a low surrogate?
- if (highSurrogate != '\0')
- {
- //
- // In previous char, we encounter a high surrogate, so we are expecting a low surrogate here.
- //
- if (char.IsLowSurrogate(ch))
- {
- // They're all legal
- highSurrogate = '\0';
-
- //
- // One surrogate pair will be translated into 4 bytes UTF32.
- //
-
- byteCount += 4;
- continue;
- }
-
- // We are missing our low surrogate, decrement chars and fallback the high surrogate
- // The high surrogate may have come from the encoder, but nothing else did.
- Debug.Assert(chars > charStart,
- "[UTF32Encoding.GetByteCount]Expected chars to have advanced if no low surrogate");
- chars--;
-
- // Do the fallback
- charsForFallback = chars;
- fallbackBuffer.InternalFallback(highSurrogate, ref charsForFallback);
- chars = charsForFallback;
-
- // We're going to fallback the old high surrogate.
- highSurrogate = '\0';
- continue;
- }
-
- // Do we have another high surrogate?
- if (char.IsHighSurrogate(ch))
- {
- //
- // We'll have a high surrogate to check next time.
- //
- highSurrogate = ch;
- continue;
- }
-
- // Check for illegal characters
- if (char.IsLowSurrogate(ch))
- {
- // We have a leading low surrogate, do the fallback
- charsForFallback = chars;
- fallbackBuffer.InternalFallback(ch, ref charsForFallback);
- chars = charsForFallback;
-
- // Try again with fallback buffer
- continue;
- }
-
- // We get to add the character (4 bytes UTF32)
- byteCount += 4;
- }
-
- // May have to do our last surrogate
- if ((encoder == null || encoder.MustFlush) && highSurrogate > 0)
- {
- // We have to do the fallback for the lonely high surrogate
- charsForFallback = chars;
- fallbackBuffer.InternalFallback(highSurrogate, ref charsForFallback);
- chars = charsForFallback;
-
- highSurrogate = (char)0;
- goto TryAgain;
- }
-
- // Check for overflows.
- if (byteCount < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_GetByteCountOverflow);
-
- // Shouldn't have anything in fallback buffer for GetByteCount
- // (don't have to check _throwOnOverflow for count)
- Debug.Assert(fallbackBuffer.Remaining == 0,
- "[UTF32Encoding.GetByteCount]Expected empty fallback buffer at end");
-
- // Return our count
- return byteCount;
- }
-
- internal override unsafe int GetBytes(char* chars, int charCount,
- byte* bytes, int byteCount, EncoderNLS? encoder)
- {
- Debug.Assert(chars != null, "[UTF32Encoding.GetBytes]chars!=null");
- Debug.Assert(bytes != null, "[UTF32Encoding.GetBytes]bytes!=null");
- Debug.Assert(byteCount >= 0, "[UTF32Encoding.GetBytes]byteCount >=0");
- Debug.Assert(charCount >= 0, "[UTF32Encoding.GetBytes]charCount >=0");
-
- char* charStart = chars;
- char* charEnd = chars + charCount;
- byte* byteStart = bytes;
- byte* byteEnd = bytes + byteCount;
-
- char highSurrogate = '\0';
-
- // For fallback we may need a fallback buffer
- EncoderFallbackBuffer? fallbackBuffer = null;
- char* charsForFallback;
-
- if (encoder != null)
- {
- highSurrogate = encoder._charLeftOver;
- fallbackBuffer = encoder.FallbackBuffer;
-
- // We mustn't have left over fallback data when not converting
- if (encoder._throwOnOverflow && fallbackBuffer.Remaining > 0)
- throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty, this.EncodingName, encoder.Fallback?.GetType()));
- }
- else
- {
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- }
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, true);
-
- char ch;
- TryAgain:
-
- while (((ch = fallbackBuffer.InternalGetNextChar()) != 0) || chars < charEnd)
- {
- // First unwind any fallback
- if (ch == 0)
- {
- // No fallback, just get next char
- ch = *chars;
- chars++;
- }
-
- // Do we need a low surrogate?
- if (highSurrogate != '\0')
- {
- //
- // In previous char, we encountered a high surrogate, so we are expecting a low surrogate here.
- //
- if (char.IsLowSurrogate(ch))
- {
- // Is it a legal one?
- uint iTemp = GetSurrogate(highSurrogate, ch);
- highSurrogate = '\0';
-
- //
- // One surrogate pair will be translated into 4 bytes UTF32.
- //
- if (bytes + 3 >= byteEnd)
- {
- // Don't have 4 bytes
- if (fallbackBuffer.bFallingBack)
- {
- fallbackBuffer.MovePrevious(); // Aren't using these 2 fallback chars
- fallbackBuffer.MovePrevious();
- }
- else
- {
- // If we don't have enough room, then either we should've advanced a while
- // or we should have bytes==byteStart and throw below
- Debug.Assert(chars > charStart + 1 || bytes == byteStart,
- "[UnicodeEncoding.GetBytes]Expected chars to have when no room to add surrogate pair");
- chars -= 2; // Aren't using those 2 chars
- }
- ThrowBytesOverflow(encoder, bytes == byteStart); // Throw maybe (if no bytes written)
- highSurrogate = (char)0; // Nothing left over (we backed up to start of pair if supplimentary)
- break;
- }
-
- if (_bigEndian)
- {
- *(bytes++) = (byte)(0x00);
- *(bytes++) = (byte)(iTemp >> 16); // Implies & 0xFF, which isn't needed cause high are all 0
- *(bytes++) = (byte)(iTemp >> 8); // Implies & 0xFF
- *(bytes++) = (byte)(iTemp); // Implies & 0xFF
- }
- else
- {
- *(bytes++) = (byte)(iTemp); // Implies & 0xFF
- *(bytes++) = (byte)(iTemp >> 8); // Implies & 0xFF
- *(bytes++) = (byte)(iTemp >> 16); // Implies & 0xFF, which isn't needed cause high are all 0
- *(bytes++) = (byte)(0x00);
- }
- continue;
- }
-
- // We are missing our low surrogate, decrement chars and fallback the high surrogate
- // The high surrogate may have come from the encoder, but nothing else did.
- Debug.Assert(chars > charStart,
- "[UTF32Encoding.GetBytes]Expected chars to have advanced if no low surrogate");
- chars--;
-
- // Do the fallback
- charsForFallback = chars;
- fallbackBuffer.InternalFallback(highSurrogate, ref charsForFallback);
- chars = charsForFallback;
-
- // We're going to fallback the old high surrogate.
- highSurrogate = '\0';
- continue;
- }
-
- // Do we have another high surrogate?, if so remember it
- if (char.IsHighSurrogate(ch))
- {
- //
- // We'll have a high surrogate to check next time.
- //
- highSurrogate = ch;
- continue;
- }
-
- // Check for illegal characters (low surrogate)
- if (char.IsLowSurrogate(ch))
- {
- // We have a leading low surrogate, do the fallback
- charsForFallback = chars;
- fallbackBuffer.InternalFallback(ch, ref charsForFallback);
- chars = charsForFallback;
-
- // Try again with fallback buffer
- continue;
- }
-
- // We get to add the character, yippee.
- if (bytes + 3 >= byteEnd)
- {
- // Don't have 4 bytes
- if (fallbackBuffer.bFallingBack)
- fallbackBuffer.MovePrevious(); // Aren't using this fallback char
- else
- {
- // Must've advanced already
- Debug.Assert(chars > charStart,
- "[UTF32Encoding.GetBytes]Expected chars to have advanced if normal character");
- chars--; // Aren't using this char
- }
- ThrowBytesOverflow(encoder, bytes == byteStart); // Throw maybe (if no bytes written)
- break; // Didn't throw, stop
- }
-
- if (_bigEndian)
- {
- *(bytes++) = (byte)(0x00);
- *(bytes++) = (byte)(0x00);
- *(bytes++) = (byte)((uint)ch >> 8); // Implies & 0xFF
- *(bytes++) = (byte)(ch); // Implies & 0xFF
- }
- else
- {
- *(bytes++) = (byte)(ch); // Implies & 0xFF
- *(bytes++) = (byte)((uint)ch >> 8); // Implies & 0xFF
- *(bytes++) = (byte)(0x00);
- *(bytes++) = (byte)(0x00);
- }
- }
-
- // May have to do our last surrogate
- if ((encoder == null || encoder.MustFlush) && highSurrogate > 0)
- {
- // We have to do the fallback for the lonely high surrogate
- charsForFallback = chars;
- fallbackBuffer.InternalFallback(highSurrogate, ref charsForFallback);
- chars = charsForFallback;
-
- highSurrogate = (char)0;
- goto TryAgain;
- }
-
- // Fix our encoder if we have one
- Debug.Assert(highSurrogate == 0 || (encoder != null && !encoder.MustFlush),
- "[UTF32Encoding.GetBytes]Expected encoder to be flushed.");
-
- if (encoder != null)
- {
- // Remember our left over surrogate (or 0 if flushing)
- encoder._charLeftOver = highSurrogate;
-
- // Need # chars used
- encoder._charsUsed = (int)(chars - charStart);
- }
-
- // return the new length
- return (int)(bytes - byteStart);
- }
-
- internal override unsafe int GetCharCount(byte* bytes, int count, DecoderNLS? baseDecoder)
- {
- Debug.Assert(bytes != null, "[UTF32Encoding.GetCharCount]bytes!=null");
- Debug.Assert(count >= 0, "[UTF32Encoding.GetCharCount]count >=0");
-
- UTF32Decoder? decoder = (UTF32Decoder?)baseDecoder;
-
- // None so far!
- int charCount = 0;
- byte* end = bytes + count;
- byte* byteStart = bytes;
-
- // Set up decoder
- int readCount = 0;
- uint iChar = 0;
-
- // For fallback we may need a fallback buffer
- DecoderFallbackBuffer? fallbackBuffer = null;
-
- // See if there's anything in our decoder
- if (decoder != null)
- {
- readCount = decoder.readByteCount;
- iChar = (uint)decoder.iChar;
- fallbackBuffer = decoder.FallbackBuffer;
-
- // Shouldn't have anything in fallback buffer for GetCharCount
- // (don't have to check _throwOnOverflow for chars or count)
- Debug.Assert(fallbackBuffer.Remaining == 0,
- "[UTF32Encoding.GetCharCount]Expected empty fallback buffer at start");
- }
- else
- {
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- }
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(byteStart, null);
-
- // Loop through our input, 4 characters at a time!
- while (bytes < end && charCount >= 0)
- {
- // Get our next character
- if (_bigEndian)
- {
- // Scoot left and add it to the bottom
- iChar <<= 8;
- iChar += *(bytes++);
- }
- else
- {
- // Scoot right and add it to the top
- iChar >>= 8;
- iChar += (uint)(*(bytes++)) << 24;
- }
-
- readCount++;
-
- // See if we have all the bytes yet
- if (readCount < 4)
- continue;
-
- // Have the bytes
- readCount = 0;
-
- // See if its valid to encode
- if (iChar > 0x10FFFF || (iChar >= 0xD800 && iChar <= 0xDFFF))
- {
- // Need to fall back these 4 bytes
- byte[] fallbackBytes;
- if (_bigEndian)
- {
- fallbackBytes = new byte[] {
- unchecked((byte)(iChar >> 24)), unchecked((byte)(iChar >> 16)),
- unchecked((byte)(iChar >> 8)), unchecked((byte)(iChar)) };
- }
- else
- {
- fallbackBytes = new byte[] {
- unchecked((byte)(iChar)), unchecked((byte)(iChar >> 8)),
- unchecked((byte)(iChar >> 16)), unchecked((byte)(iChar >> 24)) };
- }
-
- charCount += fallbackBuffer.InternalFallback(fallbackBytes, bytes);
-
- // Ignore the illegal character
- iChar = 0;
- continue;
- }
-
- // Ok, we have something we can add to our output
- if (iChar >= 0x10000)
- {
- // Surrogates take 2
- charCount++;
- }
-
- // Add the rest of the surrogate or our normal character
- charCount++;
-
- // iChar is back to 0
- iChar = 0;
- }
-
- // See if we have something left over that has to be decoded
- if (readCount > 0 && (decoder == null || decoder.MustFlush))
- {
- // Oops, there's something left over with no place to go.
- byte[] fallbackBytes = new byte[readCount];
- if (_bigEndian)
- {
- while (readCount > 0)
- {
- fallbackBytes[--readCount] = unchecked((byte)iChar);
- iChar >>= 8;
- }
- }
- else
- {
- while (readCount > 0)
- {
- fallbackBytes[--readCount] = unchecked((byte)(iChar >> 24));
- iChar <<= 8;
- }
- }
-
- charCount += fallbackBuffer.InternalFallback(fallbackBytes, bytes);
- }
-
- // Check for overflows.
- if (charCount < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_GetByteCountOverflow);
-
- // Shouldn't have anything in fallback buffer for GetCharCount
- // (don't have to check _throwOnOverflow for chars or count)
- Debug.Assert(fallbackBuffer.Remaining == 0,
- "[UTF32Encoding.GetCharCount]Expected empty fallback buffer at end");
-
- // Return our count
- return charCount;
- }
-
- internal override unsafe int GetChars(byte* bytes, int byteCount,
- char* chars, int charCount, DecoderNLS? baseDecoder)
- {
- Debug.Assert(chars != null, "[UTF32Encoding.GetChars]chars!=null");
- Debug.Assert(bytes != null, "[UTF32Encoding.GetChars]bytes!=null");
- Debug.Assert(byteCount >= 0, "[UTF32Encoding.GetChars]byteCount >=0");
- Debug.Assert(charCount >= 0, "[UTF32Encoding.GetChars]charCount >=0");
-
- UTF32Decoder? decoder = (UTF32Decoder?)baseDecoder;
-
- // None so far!
- char* charStart = chars;
- char* charEnd = chars + charCount;
-
- byte* byteStart = bytes;
- byte* byteEnd = bytes + byteCount;
-
- // See if there's anything in our decoder (but don't clear it yet)
- int readCount = 0;
- uint iChar = 0;
-
- // For fallback we may need a fallback buffer
- DecoderFallbackBuffer? fallbackBuffer = null;
- char* charsForFallback;
-
- // See if there's anything in our decoder
- if (decoder != null)
- {
- readCount = decoder.readByteCount;
- iChar = (uint)decoder.iChar;
- Debug.Assert(baseDecoder != null);
- fallbackBuffer = baseDecoder.FallbackBuffer;
-
- // Shouldn't have anything in fallback buffer for GetChars
- // (don't have to check _throwOnOverflow for chars)
- Debug.Assert(fallbackBuffer.Remaining == 0,
- "[UTF32Encoding.GetChars]Expected empty fallback buffer at start");
- }
- else
- {
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- }
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(bytes, chars + charCount);
-
- // Loop through our input, 4 characters at a time!
- while (bytes < byteEnd)
- {
- // Get our next character
- if (_bigEndian)
- {
- // Scoot left and add it to the bottom
- iChar <<= 8;
- iChar += *(bytes++);
- }
- else
- {
- // Scoot right and add it to the top
- iChar >>= 8;
- iChar += (uint)(*(bytes++)) << 24;
- }
-
- readCount++;
-
- // See if we have all the bytes yet
- if (readCount < 4)
- continue;
-
- // Have the bytes
- readCount = 0;
-
- // See if its valid to encode
- if (iChar > 0x10FFFF || (iChar >= 0xD800 && iChar <= 0xDFFF))
- {
- // Need to fall back these 4 bytes
- byte[] fallbackBytes;
- if (_bigEndian)
- {
- fallbackBytes = new byte[] {
- unchecked((byte)(iChar >> 24)), unchecked((byte)(iChar >> 16)),
- unchecked((byte)(iChar >> 8)), unchecked((byte)(iChar)) };
- }
- else
- {
- fallbackBytes = new byte[] {
- unchecked((byte)(iChar)), unchecked((byte)(iChar >> 8)),
- unchecked((byte)(iChar >> 16)), unchecked((byte)(iChar >> 24)) };
- }
-
- // Chars won't be updated unless this works.
- charsForFallback = chars;
- bool fallbackResult = fallbackBuffer.InternalFallback(fallbackBytes, bytes, ref charsForFallback);
- chars = charsForFallback;
-
- if (!fallbackResult)
- {
- // Couldn't fallback, throw or wait til next time
- // We either read enough bytes for bytes-=4 to work, or we're
- // going to throw in ThrowCharsOverflow because chars == charStart
- Debug.Assert(bytes >= byteStart + 4 || chars == charStart,
- "[UTF32Encoding.GetChars]Expected to have consumed bytes or throw (bad surrogate)");
- bytes -= 4; // get back to where we were
- iChar = 0; // Remembering nothing
- fallbackBuffer.InternalReset();
- ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output
- break; // Stop here, didn't throw
- }
-
- // Ignore the illegal character
- iChar = 0;
- continue;
- }
-
- // Ok, we have something we can add to our output
- if (iChar >= 0x10000)
- {
- // Surrogates take 2
- if (chars >= charEnd - 1)
- {
- // Throwing or stopping
- // We either read enough bytes for bytes-=4 to work, or we're
- // going to throw in ThrowCharsOverflow because chars == charStart
- Debug.Assert(bytes >= byteStart + 4 || chars == charStart,
- "[UTF32Encoding.GetChars]Expected to have consumed bytes or throw (surrogate)");
- bytes -= 4; // get back to where we were
- iChar = 0; // Remembering nothing
- ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output
- break; // Stop here, didn't throw
- }
-
- *(chars++) = GetHighSurrogate(iChar);
- iChar = GetLowSurrogate(iChar);
- }
- // Bounds check for normal character
- else if (chars >= charEnd)
- {
- // Throwing or stopping
- // We either read enough bytes for bytes-=4 to work, or we're
- // going to throw in ThrowCharsOverflow because chars == charStart
- Debug.Assert(bytes >= byteStart + 4 || chars == charStart,
- "[UTF32Encoding.GetChars]Expected to have consumed bytes or throw (normal char)");
- bytes -= 4; // get back to where we were
- iChar = 0; // Remembering nothing
- ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output
- break; // Stop here, didn't throw
- }
-
- // Add the rest of the surrogate or our normal character
- *(chars++) = (char)iChar;
-
- // iChar is back to 0
- iChar = 0;
- }
-
- // See if we have something left over that has to be decoded
- if (readCount > 0 && (decoder == null || decoder.MustFlush))
- {
- // Oops, there's something left over with no place to go.
- byte[] fallbackBytes = new byte[readCount];
- int tempCount = readCount;
- if (_bigEndian)
- {
- while (tempCount > 0)
- {
- fallbackBytes[--tempCount] = unchecked((byte)iChar);
- iChar >>= 8;
- }
- }
- else
- {
- while (tempCount > 0)
- {
- fallbackBytes[--tempCount] = unchecked((byte)(iChar >> 24));
- iChar <<= 8;
- }
- }
-
- charsForFallback = chars;
- bool fallbackResult = fallbackBuffer.InternalFallback(fallbackBytes, bytes, ref charsForFallback);
- chars = charsForFallback;
-
- if (!fallbackResult)
- {
- // Couldn't fallback.
- fallbackBuffer.InternalReset();
- ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output
- // Stop here, didn't throw, backed up, so still nothing in buffer
- }
- else
- {
- // Don't clear our decoder unless we could fall it back.
- // If we caught the if above, then we're a convert() and will catch this next time.
- readCount = 0;
- iChar = 0;
- }
- }
-
- // Remember any left over stuff, clearing buffer as well for MustFlush
- if (decoder != null)
- {
- decoder.iChar = (int)iChar;
- decoder.readByteCount = readCount;
- decoder._bytesUsed = (int)(bytes - byteStart);
- }
-
- // Shouldn't have anything in fallback buffer for GetChars
- // (don't have to check _throwOnOverflow for chars)
- Debug.Assert(fallbackBuffer.Remaining == 0,
- "[UTF32Encoding.GetChars]Expected empty fallback buffer at end");
-
- // Return our count
- return (int)(chars - charStart);
- }
-
- private uint GetSurrogate(char cHigh, char cLow)
- {
- return (((uint)cHigh - 0xD800) * 0x400) + ((uint)cLow - 0xDC00) + 0x10000;
- }
-
- private char GetHighSurrogate(uint iChar)
- {
- return (char)((iChar - 0x10000) / 0x400 + 0xD800);
- }
-
- private char GetLowSurrogate(uint iChar)
- {
- return (char)((iChar - 0x10000) % 0x400 + 0xDC00);
- }
-
- public override Decoder GetDecoder()
- {
- return new UTF32Decoder(this);
- }
-
- public override Encoder GetEncoder()
- {
- return new EncoderNLS(this);
- }
-
- public override int GetMaxByteCount(int charCount)
- {
- if (charCount < 0)
- throw new ArgumentOutOfRangeException(nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Characters would be # of characters + 1 in case left over high surrogate is ? * max fallback
- long byteCount = (long)charCount + 1;
-
- if (EncoderFallback.MaxCharCount > 1)
- byteCount *= EncoderFallback.MaxCharCount;
-
- // 4 bytes per char
- byteCount *= 4;
-
- if (byteCount > 0x7fffffff)
- throw new ArgumentOutOfRangeException(nameof(charCount), SR.ArgumentOutOfRange_GetByteCountOverflow);
-
- return (int)byteCount;
- }
-
- public override int GetMaxCharCount(int byteCount)
- {
- if (byteCount < 0)
- throw new ArgumentOutOfRangeException(nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // A supplementary character becomes 2 surrogate characters, so 4 input bytes becomes 2 chars,
- // plus we may have 1 surrogate char left over if the decoder has 3 bytes in it already for a non-bmp char.
- // Have to add another one because 1/2 == 0, but 3 bytes left over could be 2 char surrogate pair
- int charCount = (byteCount / 2) + 2;
-
- // Also consider fallback because our input bytes could be out of range of unicode.
- // Since fallback would fallback 4 bytes at a time, we'll only fall back 1/2 of MaxCharCount.
- if (DecoderFallback.MaxCharCount > 2)
- {
- // Multiply time fallback size
- charCount *= DecoderFallback.MaxCharCount;
-
- // We were already figuring 2 chars per 4 bytes, but fallback will be different #
- charCount /= 2;
- }
-
- if (charCount > 0x7fffffff)
- throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ArgumentOutOfRange_GetCharCountOverflow);
-
- return (int)charCount;
- }
-
- public override byte[] GetPreamble()
- {
- if (_emitUTF32ByteOrderMark)
- {
- // Allocate new array to prevent users from modifying it.
- if (_bigEndian)
- {
- return new byte[4] { 0x00, 0x00, 0xFE, 0xFF };
- }
- else
- {
- return new byte[4] { 0xFF, 0xFE, 0x00, 0x00 }; // 00 00 FE FF
- }
- }
- else
- return Array.Empty<byte>();
- }
-
- public override ReadOnlySpan<byte> Preamble =>
- GetType() != typeof(UTF32Encoding) ? new ReadOnlySpan<byte>(GetPreamble()) : // in case a derived UTF32Encoding overrode GetPreamble
- !_emitUTF32ByteOrderMark ? default :
- _bigEndian ? (ReadOnlySpan<byte>)new byte[4] { 0x00, 0x00, 0xFE, 0xFF } : // uses C# compiler's optimization for static byte[] data
- (ReadOnlySpan<byte>)new byte[4] { 0xFF, 0xFE, 0x00, 0x00 };
-
- public override bool Equals(object? value)
- {
- if (value is UTF32Encoding that)
- {
- return (_emitUTF32ByteOrderMark == that._emitUTF32ByteOrderMark) &&
- (_bigEndian == that._bigEndian) &&
- (EncoderFallback.Equals(that.EncoderFallback)) &&
- (DecoderFallback.Equals(that.DecoderFallback));
- }
-
- return false;
- }
-
- public override int GetHashCode()
- {
- // Not great distribution, but this is relatively unlikely to be used as the key in a hashtable.
- return this.EncoderFallback.GetHashCode() + this.DecoderFallback.GetHashCode() +
- CodePage + (_emitUTF32ByteOrderMark ? 4 : 0) + (_bigEndian ? 8 : 0);
- }
-
- private sealed class UTF32Decoder : DecoderNLS
- {
- // Need a place to store any extra bytes we may have picked up
- internal int iChar = 0;
- internal int readByteCount = 0;
-
- public UTF32Decoder(UTF32Encoding encoding) : base(encoding)
- {
- // base calls reset
- }
-
- public override void Reset()
- {
- this.iChar = 0;
- this.readByteCount = 0;
- if (_fallbackBuffer != null)
- _fallbackBuffer.Reset();
- }
-
- // Anything left in our decoder?
- internal override bool HasState =>
- // ReadByteCount is our flag. (iChar==0 doesn't mean much).
- this.readByteCount != 0;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/UTF7Encoding.cs b/netcore/System.Private.CoreLib/shared/System/Text/UTF7Encoding.cs
deleted file mode 100644
index 3f697491d21..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/UTF7Encoding.cs
+++ /dev/null
@@ -1,925 +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.
-
-//
-// Don't override IsAlwaysNormalized because it is just a Unicode Transformation and could be confused.
-//
-
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Text
-{
- public class UTF7Encoding : Encoding
- {
- private const string base64Chars =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- // 0123456789111111111122222222223333333333444444444455555555556666
- // 012345678901234567890123456789012345678901234567890123
-
- // These are the characters that can be directly encoded in UTF7.
- private const string directChars =
- "\t\n\r '(),-./0123456789:?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-
- // These are the characters that can be optionally directly encoded in UTF7.
- private const string optionalChars =
- "!\"#$%&*;<=>@[]^_`{|}";
-
- // Used by Encoding.UTF7 for lazy initialization
- // The initialization code will not be run until a static member of the class is referenced
- internal static readonly UTF7Encoding s_default = new UTF7Encoding();
-
- // The set of base 64 characters.
- private byte[] _base64Bytes = null!;
- // The decoded bits for every base64 values. This array has a size of 128 elements.
- // The index is the code point value of the base 64 characters. The value is -1 if
- // the code point is not a valid base 64 character. Otherwise, the value is a value
- // from 0 ~ 63.
- private sbyte[] _base64Values = null!;
- // The array to decide if a Unicode code point below 0x80 can be directly encoded in UTF7.
- // This array has a size of 128.
- private bool[] _directEncode = null!;
-
- private readonly bool _allowOptionals;
-
- private const int UTF7_CODEPAGE = 65000;
-
- public UTF7Encoding()
- : this(false)
- {
- }
-
- public UTF7Encoding(bool allowOptionals)
- : base(UTF7_CODEPAGE) // Set the data item.
- {
- // Allowing optionals?
- _allowOptionals = allowOptionals;
-
- // Make our tables
- MakeTables();
- }
-
- private void MakeTables()
- {
- // Build our tables
- _base64Bytes = new byte[64];
- for (int i = 0; i < 64; i++) _base64Bytes[i] = (byte)base64Chars[i];
- _base64Values = new sbyte[128];
- for (int i = 0; i < 128; i++) _base64Values[i] = -1;
- for (int i = 0; i < 64; i++) _base64Values[_base64Bytes[i]] = (sbyte)i;
- _directEncode = new bool[128];
- int count = directChars.Length;
- for (int i = 0; i < count; i++)
- {
- _directEncode[directChars[i]] = true;
- }
-
- if (_allowOptionals)
- {
- count = optionalChars.Length;
- for (int i = 0; i < count; i++)
- {
- _directEncode[optionalChars[i]] = true;
- }
- }
- }
-
- // We go ahead and set this because Encoding expects it, however nothing can fall back in UTF7.
- internal sealed override void SetDefaultFallbacks()
- {
- // UTF7 had an odd decoderFallback behavior, and the Encoder fallback
- // is irrelevant because we encode surrogates individually and never check for unmatched ones
- // (so nothing can fallback during encoding)
- this.encoderFallback = new EncoderReplacementFallback(string.Empty);
- this.decoderFallback = new DecoderUTF7Fallback();
- }
-
- public override bool Equals(object? value)
- {
- if (value is UTF7Encoding that)
- {
- return (_allowOptionals == that._allowOptionals) &&
- (EncoderFallback.Equals(that.EncoderFallback)) &&
- (DecoderFallback.Equals(that.DecoderFallback));
- }
- return false;
- }
-
- // Compared to all the other encodings, variations of UTF7 are unlikely
-
- public override int GetHashCode()
- {
- return this.CodePage + this.EncoderFallback.GetHashCode() + this.DecoderFallback.GetHashCode();
- }
-
- // The following methods are copied from EncodingNLS.cs.
- // Unfortunately EncodingNLS.cs is internal and we're public, so we have to re-implement them here.
- // These should be kept in sync for the following classes:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- // Returns the number of bytes required to encode a range of characters in
- // a character array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetByteCount(char[] chars, int index, int count)
- {
- // Validate input parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // If no input, return 0, avoid fixed empty array problem
- if (count == 0)
- return 0;
-
- // Just call the pointer version
- fixed (char* pChars = chars)
- return GetByteCount(pChars + index, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetByteCount(string s)
- {
- // Validate input
- if (s == null)
- throw new ArgumentNullException(nameof(s));
-
- fixed (char* pChars = s)
- return GetByteCount(pChars, s.Length, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetByteCount(char* chars, int count)
- {
- // Validate Parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars), SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Call it with empty encoder
- return GetByteCount(chars, count, null);
- }
-
- // Parent method is safe.
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- public override unsafe int GetBytes(string s, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- if (s == null || bytes == null)
- throw new ArgumentNullException(s == null ? nameof(s) : nameof(bytes), SR.ArgumentNull_Array);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (s.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(s), SR.ArgumentOutOfRange_IndexCount);
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index);
-
- int byteCount = bytes.Length - byteIndex;
-
- fixed (char* pChars = s) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
- }
-
- // Encodes a range of characters in a character array into a range of bytes
- // in a byte array. An exception occurs if the byte array is not large
- // enough to hold the complete encoding of the characters. The
- // GetByteCount method can be used to determine the exact number of
- // bytes that will be produced for a given range of characters.
- // Alternatively, the GetMaxByteCount method can be used to
- // determine the maximum number of bytes that will be produced for a given
- // number of characters, regardless of the actual character values.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes), SR.ArgumentNull_Array);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index);
-
- // If nothing to encode return 0, avoid fixed problem
- if (charCount == 0)
- return 0;
-
- // Just call pointer version
- int byteCount = bytes.Length - byteIndex;
-
- fixed (char* pChars = chars) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- // Remember that byteCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetBytes(chars, charCount, bytes, byteCount, null);
- }
-
- // Returns the number of characters produced by decoding a range of bytes
- // in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetCharCount(byte[] bytes, int index, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // If no input just return 0, fixed doesn't like 0 length arrays.
- if (count == 0)
- return 0;
-
- // Just call pointer version
- fixed (byte* pBytes = bytes)
- return GetCharCount(pBytes + index, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetCharCount(byte* bytes, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetCharCount(bytes, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (byteIndex < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(byteIndex < 0 ? nameof(byteIndex) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - byteIndex < byteCount)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (charIndex < 0 || charIndex > chars.Length)
- throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_Index);
-
- // If no input, return 0 & avoid fixed problem
- if (byteCount == 0)
- return 0;
-
- // Just call pointer version
- int charCount = chars.Length - charIndex;
-
- fixed (byte* pBytes = bytes) fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
- // Remember that charCount is # to decode, not size of array
- return GetChars(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetChars(byte* bytes, int byteCount, char* chars, int charCount)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetChars(bytes, byteCount, chars, charCount, null);
- }
-
- // Returns a string containing the decoded representation of a range of
- // bytes in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe string GetString(byte[] bytes, int index, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // Avoid problems with empty input buffer
- if (count == 0) return string.Empty;
-
- fixed (byte* pBytes = bytes)
- return string.CreateStringFromEncoding(
- pBytes + index, count, this);
- }
-
- //
- // End of standard methods copied from EncodingNLS.cs
- //
- internal sealed override unsafe int GetByteCount(char* chars, int count, EncoderNLS? baseEncoder)
- {
- Debug.Assert(chars != null, "[UTF7Encoding.GetByteCount]chars!=null");
- Debug.Assert(count >= 0, "[UTF7Encoding.GetByteCount]count >=0");
-
- // Just call GetBytes with bytes == null
- return GetBytes(chars, count, null, 0, baseEncoder);
- }
-
- internal sealed override unsafe int GetBytes(
- char* chars, int charCount, byte* bytes, int byteCount, EncoderNLS? baseEncoder)
- {
- Debug.Assert(byteCount >= 0, "[UTF7Encoding.GetBytes]byteCount >=0");
- Debug.Assert(chars != null, "[UTF7Encoding.GetBytes]chars!=null");
- Debug.Assert(charCount >= 0, "[UTF7Encoding.GetBytes]charCount >=0");
-
- // Get encoder info
- UTF7Encoding.Encoder? encoder = (UTF7Encoding.Encoder?)baseEncoder;
-
- // Default bits & count
- int bits = 0;
- int bitCount = -1;
-
- // prepare our helpers
- Encoding.EncodingByteBuffer buffer = new Encoding.EncodingByteBuffer(
- this, encoder, bytes, byteCount, chars, charCount);
-
- if (encoder != null)
- {
- bits = encoder.bits;
- bitCount = encoder.bitCount;
-
- // May have had too many left over
- while (bitCount >= 6)
- {
- bitCount -= 6;
- // If we fail we'll never really have enough room
- if (!buffer.AddByte(_base64Bytes[(bits >> bitCount) & 0x3F]))
- ThrowBytesOverflow(encoder, buffer.Count == 0);
- }
- }
-
- while (buffer.MoreData)
- {
- char currentChar = buffer.GetNextChar();
-
- if (currentChar < 0x80 && _directEncode[currentChar])
- {
- if (bitCount >= 0)
- {
- if (bitCount > 0)
- {
- // Try to add the next byte
- if (!buffer.AddByte(_base64Bytes[bits << 6 - bitCount & 0x3F]))
- break; // Stop here, didn't throw
-
- bitCount = 0;
- }
-
- // Need to get emit '-' and our char, 2 bytes total
- if (!buffer.AddByte((byte)'-'))
- break; // Stop here, didn't throw
-
- bitCount = -1;
- }
-
- // Need to emit our char
- if (!buffer.AddByte((byte)currentChar))
- break; // Stop here, didn't throw
- }
- else if (bitCount < 0 && currentChar == '+')
- {
- if (!buffer.AddByte((byte)'+', (byte)'-'))
- break; // Stop here, didn't throw
- }
- else
- {
- if (bitCount < 0)
- {
- // Need to emit a + and 12 bits (3 bytes)
- // Only 12 of the 16 bits will be emitted this time, the other 4 wait 'til next time
- if (!buffer.AddByte((byte)'+'))
- break; // Stop here, didn't throw
-
- // We're now in bit mode, but haven't stored data yet
- bitCount = 0;
- }
-
- // Add our bits
- bits = bits << 16 | currentChar;
- bitCount += 16;
-
- while (bitCount >= 6)
- {
- bitCount -= 6;
- if (!buffer.AddByte(_base64Bytes[(bits >> bitCount) & 0x3F]))
- {
- bitCount += 6; // We didn't use these bits
- buffer.GetNextChar(); // We're processing this char still, but AddByte
- // --'d it when we ran out of space
- break; // Stop here, not enough room for bytes
- }
- }
-
- if (bitCount >= 6)
- break; // Didn't have room to encode enough bits
- }
- }
-
- // Now if we have bits left over we have to encode them.
- // MustFlush may have been cleared by encoding.ThrowBytesOverflow earlier if converting
- if (bitCount >= 0 && (encoder == null || encoder.MustFlush))
- {
- // Do we have bits we have to stick in?
- if (bitCount > 0)
- {
- if (buffer.AddByte(_base64Bytes[(bits << (6 - bitCount)) & 0x3F]))
- {
- // Emitted spare bits, 0 bits left
- bitCount = 0;
- }
- }
-
- // If converting and failed bitCount above, then we'll fail this too
- if (buffer.AddByte((byte)'-'))
- {
- // turned off bit mode';
- bits = 0;
- bitCount = -1;
- }
- else
- // If not successful, convert will maintain state for next time, also
- // AddByte will have decremented our char count, however we need it to remain the same
- buffer.GetNextChar();
- }
-
- // Do we have an encoder we're allowed to use?
- // bytes == null if counting, so don't use encoder then
- if (bytes != null && encoder != null)
- {
- // We already cleared bits & bitcount for mustflush case
- encoder.bits = bits;
- encoder.bitCount = bitCount;
- encoder._charsUsed = buffer.CharsUsed;
- }
-
- return buffer.Count;
- }
-
- internal sealed override unsafe int GetCharCount(byte* bytes, int count, DecoderNLS? baseDecoder)
- {
- Debug.Assert(count >= 0, "[UTF7Encoding.GetCharCount]count >=0");
- Debug.Assert(bytes != null, "[UTF7Encoding.GetCharCount]bytes!=null");
-
- // Just call GetChars with null char* to do counting
- return GetChars(bytes, count, null, 0, baseDecoder);
- }
-
- internal sealed override unsafe int GetChars(
- byte* bytes, int byteCount, char* chars, int charCount, DecoderNLS? baseDecoder)
- {
- Debug.Assert(byteCount >= 0, "[UTF7Encoding.GetChars]byteCount >=0");
- Debug.Assert(bytes != null, "[UTF7Encoding.GetChars]bytes!=null");
- Debug.Assert(charCount >= 0, "[UTF7Encoding.GetChars]charCount >=0");
-
- // Might use a decoder
- UTF7Encoding.Decoder? decoder = (UTF7Encoding.Decoder?)baseDecoder;
-
- // Get our output buffer info.
- Encoding.EncodingCharBuffer buffer = new Encoding.EncodingCharBuffer(
- this, decoder, chars, charCount, bytes, byteCount);
-
- // Get decoder info
- int bits = 0;
- int bitCount = -1;
- bool firstByte = false;
- if (decoder != null)
- {
- bits = decoder.bits;
- bitCount = decoder.bitCount;
- firstByte = decoder.firstByte;
-
- Debug.Assert(!firstByte || decoder.bitCount <= 0,
- "[UTF7Encoding.GetChars]If remembered bits, then first byte flag shouldn't be set");
- }
-
- // We may have had bits in the decoder that we couldn't output last time, so do so now
- if (bitCount >= 16)
- {
- // Check our decoder buffer
- if (!buffer.AddChar((char)((bits >> (bitCount - 16)) & 0xFFFF)))
- ThrowCharsOverflow(decoder, true); // Always throw, they need at least 1 char even in Convert
-
- // Used this one, clean up extra bits
- bitCount -= 16;
- }
-
- // Loop through the input
- while (buffer.MoreData)
- {
- byte currentByte = buffer.GetNextByte();
- int c;
-
- if (bitCount >= 0)
- {
- //
- // Modified base 64 encoding.
- //
- sbyte v;
- if (currentByte < 0x80 && ((v = _base64Values[currentByte]) >= 0))
- {
- firstByte = false;
- bits = (bits << 6) | ((byte)v);
- bitCount += 6;
- if (bitCount >= 16)
- {
- c = (bits >> (bitCount - 16)) & 0xFFFF;
- bitCount -= 16;
- }
- // If not enough bits just continue
- else continue;
- }
- else
- {
- // If it wasn't a base 64 byte, everything's going to turn off base 64 mode
- bitCount = -1;
-
- if (currentByte != '-')
- {
- // >= 0x80 (because of 1st if statemtn)
- // We need this check since the _base64Values[b] check below need b <= 0x7f.
- // This is not a valid base 64 byte. Terminate the shifted-sequence and
- // emit this byte.
-
- // not in base 64 table
- // According to the RFC 1642 and the example code of UTF-7
- // in Unicode 2.0, we should just zero-extend the invalid UTF7 byte
-
- // Chars won't be updated unless this works, try to fallback
- if (!buffer.Fallback(currentByte))
- break; // Stop here, didn't throw
-
- // Used that byte, we're done with it
- continue;
- }
-
- //
- // The encoding for '+' is "+-".
- //
- if (firstByte) c = '+';
- // We just turn it off if not emitting a +, so we're done.
- else continue;
- }
- //
- // End of modified base 64 encoding block.
- //
- }
- else if (currentByte == '+')
- {
- //
- // Found the start of a modified base 64 encoding block or a plus sign.
- //
- bitCount = 0;
- firstByte = true;
- continue;
- }
- else
- {
- // Normal character
- if (currentByte >= 0x80)
- {
- // Try to fallback
- if (!buffer.Fallback(currentByte))
- break; // Stop here, didn't throw
-
- // Done falling back
- continue;
- }
-
- // Use the normal character
- c = currentByte;
- }
-
- if (c >= 0)
- {
- // Check our buffer
- if (!buffer.AddChar((char)c))
- {
- // No room. If it was a plain char we'll try again later.
- // Note, we'll consume this byte and stick it in decoder, even if we can't output it
- if (bitCount >= 0) // Can we rememmber this byte (char)
- {
- buffer.AdjustBytes(+1); // Need to readd the byte that AddChar subtracted when it failed
- bitCount += 16; // We'll still need that char we have in our bits
- }
- break; // didn't throw, stop
- }
- }
- }
-
- // Stick stuff in the decoder if we can (chars == null if counting, so don't store decoder)
- if (chars != null && decoder != null)
- {
- // MustFlush? (Could've been cleared by ThrowCharsOverflow if Convert & didn't reach end of buffer)
- if (decoder.MustFlush)
- {
- // RFC doesn't specify what would happen if we have non-0 leftover bits, we just drop them
- decoder.bits = 0;
- decoder.bitCount = -1;
- decoder.firstByte = false;
- }
- else
- {
- decoder.bits = bits;
- decoder.bitCount = bitCount;
- decoder.firstByte = firstByte;
- }
- decoder._bytesUsed = buffer.BytesUsed;
- }
- // else ignore any hanging bits.
-
- // Return our count
- return buffer.Count;
- }
-
- public override System.Text.Decoder GetDecoder()
- {
- return new UTF7Encoding.Decoder(this);
- }
-
- public override System.Text.Encoder GetEncoder()
- {
- return new UTF7Encoding.Encoder(this);
- }
-
- public override int GetMaxByteCount(int charCount)
- {
- if (charCount < 0)
- throw new ArgumentOutOfRangeException(nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Suppose that every char can not be direct-encoded, we know that
- // a byte can encode 6 bits of the Unicode character. And we will
- // also need two extra bytes for the shift-in ('+') and shift-out ('-') mark.
- // Therefore, the max byte should be:
- // byteCount = 2 + Math.Ceiling((double)charCount * 16 / 6);
- // That is always <= 2 + 3 * charCount;
- // Longest case is alternating encoded, direct, encoded data for 5 + 1 + 5... bytes per char.
- // UTF7 doesn't have left over surrogates, but if no input we may need an output - to turn off
- // encoding if MustFlush is true.
-
- // Its easiest to think of this as 2 bytes to turn on/off the base64 mode, then 3 bytes per char.
- // 3 bytes is 18 bits of encoding, which is more than we need, but if its direct encoded then 3
- // bytes allows us to turn off and then back on base64 mode if necessary.
-
- // Note that UTF7 encoded surrogates individually and isn't worried about mismatches, so all
- // code points are encodable int UTF7.
- long byteCount = (long)charCount * 3 + 2;
-
- // check for overflow
- if (byteCount > 0x7fffffff)
- throw new ArgumentOutOfRangeException(nameof(charCount), SR.ArgumentOutOfRange_GetByteCountOverflow);
-
- return (int)byteCount;
- }
-
- public override int GetMaxCharCount(int byteCount)
- {
- if (byteCount < 0)
- throw new ArgumentOutOfRangeException(nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Worst case is 1 char per byte. Minimum 1 for left over bits in case decoder is being flushed
- // Also note that we ignore extra bits (per spec), so UTF7 doesn't have unknown in this direction.
- int charCount = byteCount;
- if (charCount == 0) charCount = 1;
-
- return charCount;
- }
-
- // Of all the amazing things... This MUST be Decoder so that our com name
- // for System.Text.Decoder doesn't change
- private sealed class Decoder : DecoderNLS
- {
- /*private*/
- internal int bits;
- /*private*/
- internal int bitCount;
- /*private*/
- internal bool firstByte;
-
- public Decoder(UTF7Encoding encoding) : base(encoding)
- {
- // base calls reset
- }
-
- public override void Reset()
- {
- this.bits = 0;
- this.bitCount = -1;
- this.firstByte = false;
- if (_fallbackBuffer != null)
- _fallbackBuffer.Reset();
- }
-
- // Anything left in our encoder?
- internal override bool HasState =>
- // NOTE: This forces the last -, which some encoder might not encode. If we
- // don't see it we don't think we're done reading.
- this.bitCount != -1;
- }
-
- // Of all the amazing things... This MUST be Encoder so that our com name
- // for System.Text.Encoder doesn't change
- private sealed class Encoder : EncoderNLS
- {
- /*private*/
- internal int bits;
- /*private*/
- internal int bitCount;
-
- public Encoder(UTF7Encoding encoding) : base(encoding)
- {
- // base calls reset
- }
-
- public override void Reset()
- {
- this.bitCount = -1;
- this.bits = 0;
- if (_fallbackBuffer != null)
- _fallbackBuffer.Reset();
- }
-
- // Anything left in our encoder?
- internal override bool HasState => this.bits != 0 || this.bitCount != -1;
- }
-
- // 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.
- private sealed class DecoderUTF7Fallback : DecoderFallback
- {
- // Default replacement fallback uses no best fit and ? replacement string
-
- public override DecoderFallbackBuffer CreateFallbackBuffer() =>
- new DecoderUTF7FallbackBuffer();
-
- // Maximum number of characters that this instance of this fallback could return
- public override int MaxCharCount => 1; // returns 1 char per bad byte
-
- public override bool Equals(object? value) => value is DecoderUTF7Fallback;
-
- public override int GetHashCode() => 984;
- }
-
- private sealed class DecoderUTF7FallbackBuffer : DecoderFallbackBuffer
- {
- // Store our default string
- private char cFallback = (char)0;
- private int iCount = -1;
- private int iSize;
-
- // Fallback Methods
- public override bool Fallback(byte[] bytesUnknown, int index)
- {
- // We expect no previous fallback in our buffer
- Debug.Assert(iCount < 0, "[DecoderUTF7FallbackBuffer.Fallback] Can't have recursive fallbacks");
- Debug.Assert(bytesUnknown.Length == 1, "[DecoderUTF7FallbackBuffer.Fallback] Only possible fallback case should be 1 unknown byte");
-
- // Go ahead and get our fallback
- cFallback = (char)bytesUnknown[0];
-
- // Any of the fallback characters can be handled except for 0
- if (cFallback == 0)
- {
- return false;
- }
-
- iCount = iSize = 1;
-
- return true;
- }
-
- public override char GetNextChar()
- {
- if (iCount-- > 0)
- return cFallback;
-
- // Note: this means that 0 in UTF7 stream will never be emitted.
- return (char)0;
- }
-
- public override bool MovePrevious()
- {
- if (iCount >= 0)
- {
- iCount++;
- }
-
- // return true if we were allowed to do this
- return iCount >= 0 && iCount <= iSize;
- }
-
- // Return # of chars left in this fallback
- public override int Remaining => (iCount > 0) ? iCount : 0;
-
- // Clear the buffer
- public override unsafe void Reset()
- {
- iCount = -1;
- byteStart = null;
- }
-
- // This version just counts the fallback and doesn't actually copy anything.
- internal override unsafe int InternalFallback(byte[] bytes, byte* pBytes)
- // Right now this has both bytes and bytes[], since we might have extra bytes, hence the
- // array, and we might need the index, hence the byte*
- {
- // We expect no previous fallback in our buffer
- Debug.Assert(iCount < 0, "[DecoderUTF7FallbackBuffer.InternalFallback] Can't have recursive fallbacks");
- if (bytes.Length != 1)
- {
- throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex);
- }
-
- // Can't fallback a byte 0, so return for that case, 1 otherwise.
- return bytes[0] == 0 ? 0 : 1;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/UTF8Encoding.Sealed.cs b/netcore/System.Private.CoreLib/shared/System/Text/UTF8Encoding.Sealed.cs
deleted file mode 100644
index 32243039e93..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/UTF8Encoding.Sealed.cs
+++ /dev/null
@@ -1,108 +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 System.Diagnostics;
-
-namespace System.Text
-{
- public partial class UTF8Encoding
- {
- /// <summary>
- /// A special instance of <see cref="UTF8Encoding"/> that is initialized with "don't throw on invalid sequences;
- /// perform <see cref="Rune.ReplacementChar"/> substitution instead" semantics. This type allows for devirtualization
- /// of calls made directly off of <see cref="Encoding.UTF8"/>. See https://github.com/dotnet/coreclr/pull/9230.
- /// </summary>
- internal sealed class UTF8EncodingSealed : UTF8Encoding
- {
- /// <summary>
- /// Maximum number of input elements we'll allow for going through the fast one-pass stackalloc code paths.
- /// </summary>
- private const int MaxSmallInputElementCount = 32;
-
- public UTF8EncodingSealed(bool encoderShouldEmitUTF8Identifier) : base(encoderShouldEmitUTF8Identifier) { }
-
- public override ReadOnlySpan<byte> Preamble => _emitUTF8Identifier ? PreambleSpan : default;
-
- public override object Clone()
- {
- // The base implementation of Encoding.Clone calls object.MemberwiseClone and marks the new object mutable.
- // We don't want to do this because it violates the invariants we have set for the sealed type.
- // Instead, we'll create a new instance of the base UTF8Encoding type and mark it mutable.
-
- return new UTF8Encoding(_emitUTF8Identifier)
- {
- IsReadOnly = false
- };
- }
-
- public override byte[] GetBytes(string s)
- {
- // This method is short and can be inlined, meaning that the null check below
- // might be elided if the JIT can prove not-null at the call site.
-
- if (s?.Length <= MaxSmallInputElementCount)
- {
- return GetBytesForSmallInput(s);
- }
- else
- {
- return base.GetBytes(s!); // make the base method responsible for the null check
- }
- }
-
- private unsafe byte[] GetBytesForSmallInput(string s)
- {
- Debug.Assert(s != null);
- Debug.Assert(s.Length <= MaxSmallInputElementCount);
-
- byte* pDestination = stackalloc byte[MaxSmallInputElementCount * MaxUtf8BytesPerChar];
-
- int sourceLength = s.Length; // hoist this to avoid having the JIT auto-insert null checks
- int bytesWritten;
-
- fixed (char* pSource = s)
- {
- bytesWritten = GetBytesCommon(pSource, sourceLength, pDestination, MaxSmallInputElementCount * MaxUtf8BytesPerChar);
- Debug.Assert(0 <= bytesWritten && bytesWritten <= s.Length * MaxUtf8BytesPerChar);
- }
-
- return new Span<byte>(ref *pDestination, bytesWritten).ToArray(); // this overload of Span ctor doesn't validate length
- }
-
- public override string GetString(byte[] bytes)
- {
- // This method is short and can be inlined, meaning that the null check below
- // might be elided if the JIT can prove not-null at the call site.
-
- if (bytes?.Length <= MaxSmallInputElementCount)
- {
- return GetStringForSmallInput(bytes);
- }
- else
- {
- return base.GetString(bytes!); // make the base method responsible for the null check
- }
- }
-
- private unsafe string GetStringForSmallInput(byte[] bytes)
- {
- Debug.Assert(bytes != null);
- Debug.Assert(bytes.Length <= MaxSmallInputElementCount);
-
- char* pDestination = stackalloc char[MaxSmallInputElementCount]; // each byte produces at most one char
-
- int sourceLength = bytes.Length; // hoist this to avoid having the JIT auto-insert null checks
- int charsWritten;
-
- fixed (byte* pSource = bytes)
- {
- charsWritten = GetCharsCommon(pSource, sourceLength, pDestination, MaxSmallInputElementCount);
- Debug.Assert(0 <= charsWritten && charsWritten <= sourceLength); // should never have more output chars than input bytes
- }
-
- return new string(new ReadOnlySpan<char>(ref *pDestination, charsWritten)); // this overload of ROS ctor doesn't validate length
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs b/netcore/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs
deleted file mode 100644
index a8b3626c908..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs
+++ /dev/null
@@ -1,858 +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.
-
-// The worker functions in this file was optimized for performance. If you make changes
-// you should use care to consider all of the interesting cases.
-
-// The code of all worker functions in this file is written twice: Once as a slow loop, and the
-// second time as a fast loop. The slow loops handles all special cases, throws exceptions, etc.
-// The fast loops attempts to blaze through as fast as possible with optimistic range checks,
-// processing multiple characters at a time, and falling back to the slow loop for all special cases.
-
-using System.Buffers;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text.Unicode;
-
-namespace System.Text
-{
- // Encodes text into and out of UTF-8. UTF-8 is a way of writing
- // Unicode characters with variable numbers of bytes per character,
- // optimized for the lower 127 ASCII characters. It's an efficient way
- // of encoding US English in an internationalizable way.
- //
- // Don't override IsAlwaysNormalized because it is just a Unicode Transformation and could be confused.
- //
- // The UTF-8 byte order mark is simply the Unicode byte order mark
- // (0xFEFF) written in UTF-8 (0xEF 0xBB 0xBF). The byte order mark is
- // used mostly to distinguish UTF-8 text from other encodings, and doesn't
- // switch the byte orderings.
-
- public partial class UTF8Encoding : Encoding
- {
- /*
- bytes bits UTF-8 representation
- ----- ---- -----------------------------------
- 1 7 0vvvvvvv
- 2 11 110vvvvv 10vvvvvv
- 3 16 1110vvvv 10vvvvvv 10vvvvvv
- 4 21 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv
- ----- ---- -----------------------------------
-
- Surrogate:
- Real Unicode value = (HighSurrogate - 0xD800) * 0x400 + (LowSurrogate - 0xDC00) + 0x10000
- */
-
- private const int UTF8_CODEPAGE = 65001;
-
- /// <summary>
- /// Transcoding to UTF-8 bytes from UTF-16 input chars will result in a maximum 3:1 expansion.
- /// </summary>
- /// <remarks>
- /// Supplementary code points are expanded to UTF-8 from UTF-16 at a 4:2 ratio,
- /// so 3:1 is still the correct value for maximum expansion.
- /// </remarks>
- private const int MaxUtf8BytesPerChar = 3;
-
-
- // Used by Encoding.UTF8 for lazy initialization
- // The initialization code will not be run until a static member of the class is referenced
- internal static readonly UTF8EncodingSealed s_default = new UTF8EncodingSealed(encoderShouldEmitUTF8Identifier: true);
-
- internal static ReadOnlySpan<byte> PreambleSpan => new byte[3] { 0xEF, 0xBB, 0xBF }; // uses C# compiler's optimization for static byte[] data
-
- // Yes, the idea of emitting U+FEFF as a UTF-8 identifier has made it into
- // the standard.
- private readonly bool _emitUTF8Identifier = false;
-
- private readonly bool _isThrowException = false;
-
-
- public UTF8Encoding() : this(false)
- {
- }
-
-
- public UTF8Encoding(bool encoderShouldEmitUTF8Identifier) :
- base(UTF8_CODEPAGE)
- {
- _emitUTF8Identifier = encoderShouldEmitUTF8Identifier;
- }
-
-
- public UTF8Encoding(bool encoderShouldEmitUTF8Identifier, bool throwOnInvalidBytes) :
- this(encoderShouldEmitUTF8Identifier)
- {
- _isThrowException = throwOnInvalidBytes;
-
- // Encoding's constructor already did this, but it'll be wrong if we're throwing exceptions
- if (_isThrowException)
- SetDefaultFallbacks();
- }
-
- internal sealed override void SetDefaultFallbacks()
- {
- // For UTF-X encodings, we use a replacement fallback with an empty string
- if (_isThrowException)
- {
- this.encoderFallback = EncoderFallback.ExceptionFallback;
- this.decoderFallback = DecoderFallback.ExceptionFallback;
- }
- else
- {
- this.encoderFallback = new EncoderReplacementFallback("\xFFFD");
- this.decoderFallback = new DecoderReplacementFallback("\xFFFD");
- }
- }
-
-
- // WARNING: GetByteCount(string chars)
- // WARNING: has different variable names than EncodingNLS.cs, so this can't just be cut & pasted,
- // WARNING: otherwise it'll break VB's way of declaring these.
- //
- // The following methods are copied from EncodingNLS.cs.
- // Unfortunately EncodingNLS.cs is internal and we're public, so we have to re-implement them here.
- // These should be kept in sync for the following classes:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- // Returns the number of bytes required to encode a range of characters in
- // a character array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetByteCount(char[] chars, int index, int count)
- {
- // Validate input parameters
-
- if (chars is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.chars, ExceptionResource.ArgumentNull_Array);
- }
-
- if ((index | count) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (chars.Length - index < count)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
- }
-
- fixed (char* pChars = chars)
- {
- return GetByteCountCommon(pChars + index, count);
- }
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetByteCount(string chars)
- {
- // Validate input parameters
-
- if (chars is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.chars);
- }
-
- fixed (char* pChars = chars)
- {
- return GetByteCountCommon(pChars, chars.Length);
- }
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetByteCount(char* chars, int count)
- {
- // Validate Parameters
-
- if (chars == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.chars);
- }
-
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return GetByteCountCommon(chars, count);
- }
-
- public override unsafe int GetByteCount(ReadOnlySpan<char> chars)
- {
- // It's ok for us to pass null pointers down to the workhorse below.
-
- fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
- {
- return GetByteCountCommon(charsPtr, chars.Length);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private unsafe int GetByteCountCommon(char* pChars, int charCount)
- {
- // Common helper method for all non-EncoderNLS entry points to GetByteCount.
- // A modification of this method should be copied in to each of the supported encodings: ASCII, UTF8, UTF16, UTF32.
-
- Debug.Assert(charCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pChars != null || charCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
-
- // First call into the fast path.
- // Don't bother providing a fallback mechanism; our fast path doesn't use it.
-
- int totalByteCount = GetByteCountFast(pChars, charCount, fallback: null, out int charsConsumed);
-
- if (charsConsumed != charCount)
- {
- // If there's still data remaining in the source buffer, go down the fallback path.
- // We need to check for integer overflow since the fallback could change the required
- // output count in unexpected ways.
-
- totalByteCount += GetByteCountWithFallback(pChars, charCount, charsConsumed);
- if (totalByteCount < 0)
- {
- ThrowConversionOverflow();
- }
- }
-
- return totalByteCount;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetCharCountCommon
- private protected sealed override unsafe int GetByteCountFast(char* pChars, int charsLength, EncoderFallback? fallback, out int charsConsumed)
- {
- // The number of UTF-8 code units may exceed the number of UTF-16 code units,
- // so we'll need to check for overflow before casting to Int32.
-
- char* ptrToFirstInvalidChar = Utf16Utility.GetPointerToFirstInvalidChar(pChars, charsLength, out long utf8CodeUnitCountAdjustment, out _);
-
- int tempCharsConsumed = (int)(ptrToFirstInvalidChar - pChars);
- charsConsumed = tempCharsConsumed;
-
- long totalUtf8Bytes = tempCharsConsumed + utf8CodeUnitCountAdjustment;
- if ((ulong)totalUtf8Bytes > int.MaxValue)
- {
- ThrowConversionOverflow();
- }
-
- return (int)totalUtf8Bytes;
- }
-
- // Parent method is safe.
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- public override unsafe int GetBytes(string s, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- // Validate Parameters
-
- if (s is null || bytes is null)
- {
- ThrowHelper.ThrowArgumentNullException(
- argument: (s is null) ? ExceptionArgument.s : ExceptionArgument.bytes,
- resource: ExceptionResource.ArgumentNull_Array);
- }
-
- if ((charIndex | charCount) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (charIndex < 0) ? ExceptionArgument.charIndex : ExceptionArgument.charCount,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (s.Length - charIndex < charCount)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.s, ExceptionResource.ArgumentOutOfRange_IndexCount);
- }
-
- if ((uint)byteIndex > bytes.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index);
- }
-
- fixed (char* pChars = s)
- fixed (byte* pBytes = bytes)
- {
- return GetBytesCommon(pChars + charIndex, charCount, pBytes + byteIndex, bytes.Length - byteIndex);
- }
- }
-
- // Encodes a range of characters in a character array into a range of bytes
- // in a byte array. An exception occurs if the byte array is not large
- // enough to hold the complete encoding of the characters. The
- // GetByteCount method can be used to determine the exact number of
- // bytes that will be produced for a given range of characters.
- // Alternatively, the GetMaxByteCount method can be used to
- // determine the maximum number of bytes that will be produced for a given
- // number of characters, regardless of the actual character values.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- // Validate parameters
-
- if (chars is null || bytes is null)
- {
- ThrowHelper.ThrowArgumentNullException(
- argument: (chars is null) ? ExceptionArgument.chars : ExceptionArgument.bytes,
- resource: ExceptionResource.ArgumentNull_Array);
- }
-
- if ((charIndex | charCount) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (charIndex < 0) ? ExceptionArgument.charIndex : ExceptionArgument.charCount,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (chars.Length - charIndex < charCount)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCount);
- }
-
- if ((uint)byteIndex > bytes.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index);
- }
-
- fixed (char* pChars = chars)
- fixed (byte* pBytes = bytes)
- {
- return GetBytesCommon(pChars + charIndex, charCount, pBytes + byteIndex, bytes.Length - byteIndex);
- }
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount)
- {
- // Validate Parameters
-
- if (chars == null || bytes == null)
- {
- ThrowHelper.ThrowArgumentNullException(
- argument: (chars is null) ? ExceptionArgument.chars : ExceptionArgument.bytes,
- resource: ExceptionResource.ArgumentNull_Array);
- }
-
- if ((charCount | byteCount) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (charCount < 0) ? ExceptionArgument.charCount : ExceptionArgument.byteCount,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return GetBytesCommon(chars, charCount, bytes, byteCount);
- }
-
- public override unsafe int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes)
- {
- // It's ok for us to operate on null / empty spans.
-
- fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
- fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
- {
- return GetBytesCommon(charsPtr, chars.Length, bytesPtr, bytes.Length);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private unsafe int GetBytesCommon(char* pChars, int charCount, byte* pBytes, int byteCount)
- {
- // Common helper method for all non-EncoderNLS entry points to GetBytes.
- // A modification of this method should be copied in to each of the supported encodings: ASCII, UTF8, UTF16, UTF32.
-
- Debug.Assert(charCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pChars != null || charCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
- Debug.Assert(byteCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pBytes != null || byteCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
-
- // First call into the fast path.
-
- int bytesWritten = GetBytesFast(pChars, charCount, pBytes, byteCount, out int charsConsumed);
-
- if (charsConsumed == charCount)
- {
- // All elements converted - return immediately.
-
- return bytesWritten;
- }
- else
- {
- // Simple narrowing conversion couldn't operate on entire buffer - invoke fallback.
-
- return GetBytesWithFallback(pChars, charCount, pBytes, byteCount, charsConsumed, bytesWritten);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetBytesCommon
- private protected sealed override unsafe int GetBytesFast(char* pChars, int charsLength, byte* pBytes, int bytesLength, out int charsConsumed)
- {
- // We don't care about the exact OperationStatus value returned by the workhorse routine; we only
- // care if the workhorse was able to consume the entire input payload. If we're unable to do so,
- // we'll handle the remainder in the fallback routine.
-
- Utf8Utility.TranscodeToUtf8(pChars, charsLength, pBytes, bytesLength, out char* pInputBufferRemaining, out byte* pOutputBufferRemaining);
-
- charsConsumed = (int)(pInputBufferRemaining - pChars);
- return (int)(pOutputBufferRemaining - pBytes);
- }
-
- // Returns the number of characters produced by decoding a range of bytes
- // in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetCharCount(byte[] bytes, int index, int count)
- {
- // Validate Parameters
-
- if (bytes is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.bytes, ExceptionResource.ArgumentNull_Array);
- }
-
- if ((index | count) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (bytes.Length - index < count)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
- }
-
- fixed (byte* pBytes = bytes)
- {
- return GetCharCountCommon(pBytes + index, count);
- }
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetCharCount(byte* bytes, int count)
- {
- // Validate Parameters
-
- if (bytes == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.bytes, ExceptionResource.ArgumentNull_Array);
- }
-
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return GetCharCountCommon(bytes, count);
- }
-
- public override unsafe int GetCharCount(ReadOnlySpan<byte> bytes)
- {
- // It's ok for us to pass null pointers down to the workhorse routine.
-
- fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
- {
- return GetCharCountCommon(bytesPtr, bytes.Length);
- }
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex)
- {
- // Validate Parameters
-
- if (bytes is null || chars is null)
- {
- ThrowHelper.ThrowArgumentNullException(
- argument: (bytes is null) ? ExceptionArgument.bytes : ExceptionArgument.chars,
- resource: ExceptionResource.ArgumentNull_Array);
- }
-
- if ((byteIndex | byteCount) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (byteIndex < 0) ? ExceptionArgument.byteIndex : ExceptionArgument.byteCount,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (bytes.Length - byteIndex < byteCount)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
- }
-
- if ((uint)charIndex > (uint)chars.Length)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_Index);
- }
-
- fixed (byte* pBytes = bytes)
- fixed (char* pChars = chars)
- {
- return GetCharsCommon(pBytes + byteIndex, byteCount, pChars + charIndex, chars.Length - charIndex);
- }
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetChars(byte* bytes, int byteCount, char* chars, int charCount)
- {
- // Validate Parameters
-
- if (bytes is null || chars is null)
- {
- ThrowHelper.ThrowArgumentNullException(
- argument: (bytes is null) ? ExceptionArgument.bytes : ExceptionArgument.chars,
- resource: ExceptionResource.ArgumentNull_Array);
- }
-
- if ((byteCount | charCount) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (byteCount < 0) ? ExceptionArgument.byteCount : ExceptionArgument.charCount,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- return GetCharsCommon(bytes, byteCount, chars, charCount);
- }
-
- public override unsafe int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars)
- {
- // It's ok for us to pass null pointers down to the workhorse below.
-
- fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
- fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
- {
- return GetCharsCommon(bytesPtr, bytes.Length, charsPtr, chars.Length);
- }
- }
-
- // WARNING: If we throw an error, then System.Resources.ResourceReader calls this method.
- // So if we're really broken, then that could also throw an error... recursively.
- // So try to make sure GetChars can at least process all uses by
- // System.Resources.ResourceReader!
- //
- // Note: We throw exceptions on individually encoded surrogates and other non-shortest forms.
- // If exceptions aren't turned on, then we drop all non-shortest &individual surrogates.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private unsafe int GetCharsCommon(byte* pBytes, int byteCount, char* pChars, int charCount)
- {
- // Common helper method for all non-DecoderNLS entry points to GetChars.
- // A modification of this method should be copied in to each of the supported encodings: ASCII, UTF8, UTF16, UTF32.
-
- Debug.Assert(byteCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pBytes != null || byteCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
- Debug.Assert(charCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pChars != null || charCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
-
- // First call into the fast path.
-
- int charsWritten = GetCharsFast(pBytes, byteCount, pChars, charCount, out int bytesConsumed);
-
- if (bytesConsumed == byteCount)
- {
- // All elements converted - return immediately.
-
- return charsWritten;
- }
- else
- {
- // Simple narrowing conversion couldn't operate on entire buffer - invoke fallback.
-
- return GetCharsWithFallback(pBytes, byteCount, pChars, charCount, bytesConsumed, charsWritten);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetCharsCommon
- private protected sealed override unsafe int GetCharsFast(byte* pBytes, int bytesLength, char* pChars, int charsLength, out int bytesConsumed)
- {
- // We don't care about the exact OperationStatus value returned by the workhorse routine; we only
- // care if the workhorse was able to consume the entire input payload. If we're unable to do so,
- // we'll handle the remainder in the fallback routine.
-
- Utf8Utility.TranscodeToUtf16(pBytes, bytesLength, pChars, charsLength, out byte* pInputBufferRemaining, out char* pOutputBufferRemaining);
-
- bytesConsumed = (int)(pInputBufferRemaining - pBytes);
- return (int)(pOutputBufferRemaining - pChars);
- }
-
- private protected sealed override unsafe int GetCharsWithFallback(ReadOnlySpan<byte> bytes, int originalBytesLength, Span<char> chars, int originalCharsLength, DecoderNLS? decoder)
- {
- // We special-case DecoderReplacementFallback if it's telling us to write a single U+FFFD char,
- // since we believe this to be relatively common and we can handle it more efficiently than
- // the base implementation.
-
- if (((decoder is null) ? this.DecoderFallback : decoder.Fallback) is DecoderReplacementFallback replacementFallback
- && replacementFallback.MaxCharCount == 1
- && replacementFallback.DefaultString[0] == UnicodeUtility.ReplacementChar)
- {
- // Don't care about the exact OperationStatus, just how much of the payload we were able
- // to process.
-
- Utf8.ToUtf16(bytes, chars, out int bytesRead, out int charsWritten, replaceInvalidSequences: true, isFinalBlock: decoder is null || decoder.MustFlush);
-
- // Slice off how much we consumed / wrote.
-
- bytes = bytes.Slice(bytesRead);
- chars = chars.Slice(charsWritten);
- }
-
- // If we couldn't go through our fast fallback mechanism, or if we still have leftover
- // data because we couldn't consume everything in the loop above, we need to go down the
- // slow fallback path.
-
- if (bytes.IsEmpty)
- {
- return originalCharsLength - chars.Length; // total number of chars written
- }
- else
- {
- return base.GetCharsWithFallback(bytes, originalBytesLength, chars, originalCharsLength, decoder);
- }
- }
-
- // Returns a string containing the decoded representation of a range of
- // bytes in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe string GetString(byte[] bytes, int index, int count)
- {
- // Validate Parameters
-
- if (bytes is null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.bytes, ExceptionResource.ArgumentNull_Array);
- }
-
- if ((index | count) < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(
- argument: (index < 0) ? ExceptionArgument.index : ExceptionArgument.count,
- resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- if (bytes.Length - index < count)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
- }
-
- // Avoid problems with empty input buffer
- if (count == 0)
- return string.Empty;
-
- fixed (byte* pBytes = bytes)
- {
- return string.CreateStringFromEncoding(pBytes + index, count, this);
- }
- }
-
- //
- // End of standard methods copied from EncodingNLS.cs
- //
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private unsafe int GetCharCountCommon(byte* pBytes, int byteCount)
- {
- // Common helper method for all non-DecoderNLS entry points to GetCharCount.
- // A modification of this method should be copied in to each of the supported encodings: ASCII, UTF8, UTF16, UTF32.
-
- Debug.Assert(byteCount >= 0, "Caller shouldn't specify negative length buffer.");
- Debug.Assert(pBytes != null || byteCount == 0, "Input pointer shouldn't be null if non-zero length specified.");
-
- // First call into the fast path.
- // Don't bother providing a fallback mechanism; our fast path doesn't use it.
-
- int totalCharCount = GetCharCountFast(pBytes, byteCount, fallback: null, out int bytesConsumed);
-
- if (bytesConsumed != byteCount)
- {
- // If there's still data remaining in the source buffer, go down the fallback path.
- // We need to check for integer overflow since the fallback could change the required
- // output count in unexpected ways.
-
- totalCharCount += GetCharCountWithFallback(pBytes, byteCount, bytesConsumed);
- if (totalCharCount < 0)
- {
- ThrowConversionOverflow();
- }
- }
-
- return totalCharCount;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetCharCountCommon
- private protected sealed override unsafe int GetCharCountFast(byte* pBytes, int bytesLength, DecoderFallback? fallback, out int bytesConsumed)
- {
- // The number of UTF-16 code units will never exceed the number of UTF-8 code units,
- // so the addition at the end of this method will not overflow.
-
- byte* ptrToFirstInvalidByte = Utf8Utility.GetPointerToFirstInvalidByte(pBytes, bytesLength, out int utf16CodeUnitCountAdjustment, out _);
-
- int tempBytesConsumed = (int)(ptrToFirstInvalidByte - pBytes);
- bytesConsumed = tempBytesConsumed;
-
- return tempBytesConsumed + utf16CodeUnitCountAdjustment;
- }
-
- public override Decoder GetDecoder()
- {
- return new DecoderNLS(this);
- }
-
-
- public override Encoder GetEncoder()
- {
- return new EncoderNLS(this);
- }
-
- //
- // Beginning of methods used by shared fallback logic.
- //
-
- internal sealed override bool TryGetByteCount(Rune value, out int byteCount)
- {
- // All well-formed Rune instances can be converted to 1..4 UTF-8 code units.
-
- byteCount = value.Utf8SequenceLength;
- return true;
- }
-
- internal sealed override OperationStatus EncodeRune(Rune value, Span<byte> bytes, out int bytesWritten)
- {
- // All well-formed Rune instances can be encoded as 1..4 UTF-8 code units.
- // If there's an error, it's because the destination was too small.
-
- return value.TryEncodeToUtf8(bytes, out bytesWritten) ? OperationStatus.Done : OperationStatus.DestinationTooSmall;
- }
-
- internal sealed override OperationStatus DecodeFirstRune(ReadOnlySpan<byte> bytes, out Rune value, out int bytesConsumed)
- {
- return Rune.DecodeFromUtf8(bytes, out value, out bytesConsumed);
- }
-
- //
- // End of methods used by shared fallback logic.
- //
-
- public override int GetMaxByteCount(int charCount)
- {
- if (charCount < 0)
- throw new ArgumentOutOfRangeException(nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Characters would be # of characters + 1 in case left over high surrogate is ? * max fallback
- long byteCount = (long)charCount + 1;
-
- if (EncoderFallback.MaxCharCount > 1)
- byteCount *= EncoderFallback.MaxCharCount;
-
- byteCount *= MaxUtf8BytesPerChar;
-
- if (byteCount > 0x7fffffff)
- throw new ArgumentOutOfRangeException(nameof(charCount), SR.ArgumentOutOfRange_GetByteCountOverflow);
-
- return (int)byteCount;
- }
-
-
- public override int GetMaxCharCount(int byteCount)
- {
- if (byteCount < 0)
- throw new ArgumentOutOfRangeException(nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Figure out our length, 1 char per input byte + 1 char if 1st byte is last byte of 4 byte surrogate pair
- long charCount = ((long)byteCount + 1);
-
- // Non-shortest form would fall back, so get max count from fallback.
- // So would 11... followed by 11..., so you could fall back every byte
- if (DecoderFallback.MaxCharCount > 1)
- {
- charCount *= DecoderFallback.MaxCharCount;
- }
-
- if (charCount > 0x7fffffff)
- throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ArgumentOutOfRange_GetCharCountOverflow);
-
- return (int)charCount;
- }
-
-
- public override byte[] GetPreamble()
- {
- if (_emitUTF8Identifier)
- {
- // Allocate new array to prevent users from modifying it.
- return new byte[3] { 0xEF, 0xBB, 0xBF };
- }
- else
- return Array.Empty<byte>();
- }
-
- public override ReadOnlySpan<byte> Preamble =>
- GetType() != typeof(UTF8Encoding) ? new ReadOnlySpan<byte>(GetPreamble()) : // in case a derived UTF8Encoding overrode GetPreamble
- _emitUTF8Identifier ? PreambleSpan :
- default;
-
- public override bool Equals(object? value)
- {
- if (value is UTF8Encoding that)
- {
- return (_emitUTF8Identifier == that._emitUTF8Identifier) &&
- (EncoderFallback.Equals(that.EncoderFallback)) &&
- (DecoderFallback.Equals(that.DecoderFallback));
- }
- return false;
- }
-
-
- public override int GetHashCode()
- {
- // Not great distribution, but this is relatively unlikely to be used as the key in a hashtable.
- return this.EncoderFallback.GetHashCode() + this.DecoderFallback.GetHashCode() +
- UTF8_CODEPAGE + (_emitUTF8Identifier ? 1 : 0);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.Validation.cs b/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.Validation.cs
deleted file mode 100644
index 0909c22bafe..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.Validation.cs
+++ /dev/null
@@ -1,434 +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 System.Diagnostics;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using System.Numerics;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nint = System.Int64;
-using nuint = System.UInt64;
-#else // BIT64
-using nint = System.Int32;
-using nuint = System.UInt32;
-#endif // BIT64
-
-namespace System.Text.Unicode
-{
- internal static unsafe partial class Utf16Utility
- {
-#if DEBUG
- static Utf16Utility()
- {
- Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly.");
- Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly.");
- }
-#endif // DEBUG
-
- // Returns &inputBuffer[inputLength] if the input buffer is valid.
- /// <summary>
- /// Given an input buffer <paramref name="pInputBuffer"/> of char length <paramref name="inputLength"/>,
- /// returns a pointer to where the first invalid data appears in <paramref name="pInputBuffer"/>.
- /// </summary>
- /// <remarks>
- /// Returns a pointer to the end of <paramref name="pInputBuffer"/> if the buffer is well-formed.
- /// </remarks>
- public static char* GetPointerToFirstInvalidChar(char* pInputBuffer, int inputLength, out long utf8CodeUnitCountAdjustment, out int scalarCountAdjustment)
- {
- Debug.Assert(inputLength >= 0, "Input length must not be negative.");
- Debug.Assert(pInputBuffer != null || inputLength == 0, "Input length must be zero if input buffer pointer is null.");
-
- // First, we'll handle the common case of all-ASCII. If this is able to
- // consume the entire buffer, we'll skip the remainder of this method's logic.
-
- int numAsciiCharsConsumedJustNow = (int)ASCIIUtility.GetIndexOfFirstNonAsciiChar(pInputBuffer, (uint)inputLength);
- Debug.Assert(0 <= numAsciiCharsConsumedJustNow && numAsciiCharsConsumedJustNow <= inputLength);
-
- pInputBuffer += (uint)numAsciiCharsConsumedJustNow;
- inputLength -= numAsciiCharsConsumedJustNow;
-
- if (inputLength == 0)
- {
- utf8CodeUnitCountAdjustment = 0;
- scalarCountAdjustment = 0;
- return pInputBuffer;
- }
-
- // If we got here, it means we saw some non-ASCII data, so within our
- // vectorized code paths below we'll handle all non-surrogate UTF-16
- // code points branchlessly. We'll only branch if we see surrogates.
- //
- // We still optimistically assume the data is mostly ASCII. This means that the
- // number of UTF-8 code units and the number of scalars almost matches the number
- // of UTF-16 code units. As we go through the input and find non-ASCII
- // characters, we'll keep track of these "adjustment" fixups. To get the
- // total number of UTF-8 code units required to encode the input data, add
- // the UTF-8 code unit count adjustment to the number of UTF-16 code units
- // seen. To get the total number of scalars present in the input data,
- // add the scalar count adjustment to the number of UTF-16 code units seen.
-
- long tempUtf8CodeUnitCountAdjustment = 0;
- int tempScalarCountAdjustment = 0;
-
- if (Sse2.IsSupported)
- {
- if (inputLength >= Vector128<ushort>.Count)
- {
- Vector128<ushort> vector0080 = Vector128.Create((ushort)0x80);
- Vector128<ushort> vectorA800 = Vector128.Create((ushort)0xA800);
- Vector128<short> vector8800 = Vector128.Create(unchecked((short)0x8800));
- Vector128<ushort> vectorZero = Vector128<ushort>.Zero;
-
- do
- {
- Vector128<ushort> utf16Data = Sse2.LoadVector128((ushort*)pInputBuffer); // unaligned
- uint mask;
-
- // The 'charIsNonAscii' vector we're about to build will have the 0x8000 or the 0x0080
- // bit set (but not both!) only if the corresponding input char is non-ASCII. Which of
- // the two bits is set doesn't matter, as will be explained in the diagram a few lines
- // below.
-
- Vector128<ushort> charIsNonAscii;
- if (Sse41.IsSupported)
- {
- // sets 0x0080 bit if corresponding char element is >= 0x0080
- charIsNonAscii = Sse41.Min(utf16Data, vector0080);
- }
- else
- {
- // sets 0x8000 bit if corresponding char element is >= 0x0080
- charIsNonAscii = Sse2.AndNot(vector0080, Sse2.Subtract(vectorZero, Sse2.ShiftRightLogical(utf16Data, 7)));
- }
-
-#if DEBUG
- // Quick check to ensure we didn't accidentally set both 0x8080 bits in any element.
- uint debugMask = (uint)Sse2.MoveMask(charIsNonAscii.AsByte());
- Debug.Assert((debugMask & (debugMask << 1)) == 0, "Two set bits shouldn't occur adjacent to each other in this mask.");
-#endif // DEBUG
-
- // sets 0x8080 bits if corresponding char element is >= 0x0800
- Vector128<ushort> charIsThreeByteUtf8Encoded = Sse2.Subtract(vectorZero, Sse2.ShiftRightLogical(utf16Data, 11));
-
- mask = (uint)Sse2.MoveMask(Sse2.Or(charIsNonAscii, charIsThreeByteUtf8Encoded).AsByte());
-
- // Each odd bit of mask will be 1 only if the char was >= 0x0080,
- // and each even bit of mask will be 1 only if the char was >= 0x0800.
- //
- // Example for UTF-16 input "[ 0123 ] [ 1234 ] ...":
- //
- // ,-- set if char[1] is non-ASCII
- // | ,-- set if char[0] is non-ASCII
- // v v
- // mask = ... 1 1 1 0
- // ^ ^-- set if char[0] is >= 0x0800
- // `-- set if char[1] is >= 0x0800
- //
- // (If the SSE4.1 code path is taken above, the meaning of the odd and even
- // bits are swapped, but the logic below otherwise holds.)
- //
- // This means we can popcnt the number of set bits, and the result is the
- // number of *additional* UTF-8 bytes that each UTF-16 code unit requires as
- // it expands. This results in the wrong count for UTF-16 surrogate code
- // units (we just counted that each individual code unit expands to 3 bytes,
- // but in reality a well-formed UTF-16 surrogate pair expands to 4 bytes).
- // We'll handle this in just a moment.
- //
- // For now, compute the popcnt but squirrel it away. We'll fold it in to the
- // cumulative UTF-8 adjustment factor once we determine that there are no
- // unpaired surrogates in our data. (Unpaired surrogates would invalidate
- // our computed result and we'd have to throw it away.)
-
- uint popcnt = (uint)BitOperations.PopCount(mask);
-
- // Surrogates need to be special-cased for two reasons: (a) we need
- // to account for the fact that we over-counted in the addition above;
- // and (b) they require separate validation.
-
- utf16Data = Sse2.Add(utf16Data, vectorA800);
- mask = (uint)Sse2.MoveMask(Sse2.CompareLessThan(utf16Data.AsInt16(), vector8800).AsByte());
-
- if (mask != 0)
- {
- // There's at least one UTF-16 surrogate code unit present.
- // Since we performed a pmovmskb operation on the result of a 16-bit pcmpgtw,
- // the resulting bits of 'mask' will occur in pairs:
- // - 00 if the corresponding UTF-16 char was not a surrogate code unit;
- // - 11 if the corresponding UTF-16 char was a surrogate code unit.
- //
- // A UTF-16 high/low surrogate code unit has the bit pattern [ 11011q## ######## ],
- // where # is any bit; q = 0 represents a high surrogate, and q = 1 represents
- // a low surrogate. Since we added 0xA800 in the vectorized operation above,
- // our surrogate pairs will now have the bit pattern [ 10000q## ######## ].
- // If we logical right-shift each word by 3, we'll end up with the bit pattern
- // [ 00010000 q####### ], which means that we can immediately use pmovmskb to
- // determine whether a given char was a high or a low surrogate.
- //
- // Therefore the resulting bits of 'mask2' will occur in pairs:
- // - 00 if the corresponding UTF-16 char was a high surrogate code unit;
- // - 01 if the corresponding UTF-16 char was a low surrogate code unit;
- // - ## (garbage) if the corresponding UTF-16 char was not a surrogate code unit.
- // Since 'mask' already has 00 in these positions (since the corresponding char
- // wasn't a surrogate), "mask AND mask2 == 00" holds for these positions.
-
- uint mask2 = (uint)Sse2.MoveMask(Sse2.ShiftRightLogical(utf16Data, 3).AsByte());
-
- // 'lowSurrogatesMask' has its bits occur in pairs:
- // - 01 if the corresponding char was a low surrogate char,
- // - 00 if the corresponding char was a high surrogate char or not a surrogate at all.
-
- uint lowSurrogatesMask = mask2 & mask;
-
- // 'highSurrogatesMask' has its bits occur in pairs:
- // - 01 if the corresponding char was a high surrogate char,
- // - 00 if the corresponding char was a low surrogate char or not a surrogate at all.
-
- uint highSurrogatesMask = (mask2 ^ 0b_0101_0101_0101_0101u /* flip all even-numbered bits 00 <-> 01 */) & mask;
-
- Debug.Assert((highSurrogatesMask & lowSurrogatesMask) == 0,
- "A char cannot simultaneously be both a high and a low surrogate char.");
-
- Debug.Assert(((highSurrogatesMask | lowSurrogatesMask) & 0b_1010_1010_1010_1010u) == 0,
- "Only even bits (no odd bits) of the masks should be set.");
-
- // Now check that each high surrogate is followed by a low surrogate and that each
- // low surrogate follows a high surrogate. We make an exception for the case where
- // the final char of the vector is a high surrogate, since we can't perform validation
- // on it until the next iteration of the loop when we hope to consume the matching
- // low surrogate.
-
- highSurrogatesMask <<= 2;
- if ((ushort)highSurrogatesMask != lowSurrogatesMask)
- {
- goto NonVectorizedLoop; // error: mismatched surrogate pair; break out of vectorized logic
- }
-
- if (highSurrogatesMask > ushort.MaxValue)
- {
- // There was a standalone high surrogate at the end of the vector.
- // We'll adjust our counters so that we don't consider this char consumed.
-
- highSurrogatesMask = (ushort)highSurrogatesMask; // don't allow stray high surrogate to be consumed by popcnt
- popcnt -= 2; // the '0xC000_0000' bits in the original mask are shifted out and discarded, so account for that here
- pInputBuffer--;
- inputLength++;
- }
-
- // If we're 64-bit, we can perform the zero-extension of the surrogate pairs count for
- // free right now, saving the extension step a few lines below. If we're 32-bit, the
- // convertion to nuint immediately below is a no-op, and we'll pay the cost of the real
- // 64 -bit extension a few lines below.
- nuint surrogatePairsCountNuint = (uint)BitOperations.PopCount(highSurrogatesMask);
-
- // 2 UTF-16 chars become 1 Unicode scalar
-
- tempScalarCountAdjustment -= (int)surrogatePairsCountNuint;
-
- // Since each surrogate code unit was >= 0x0800, we eagerly assumed
- // it'd be encoded as 3 UTF-8 code units, so our earlier popcnt computation
- // assumes that the pair is encoded as 6 UTF-8 code units. Since each
- // pair is in reality only encoded as 4 UTF-8 code units, we need to
- // perform this adjustment now.
-
- if (IntPtr.Size == 8)
- {
- // Since we've already zero-extended surrogatePairsCountNuint, we can directly
- // sub + sub. It's more efficient than shl + sub.
- tempUtf8CodeUnitCountAdjustment -= (long)surrogatePairsCountNuint;
- tempUtf8CodeUnitCountAdjustment -= (long)surrogatePairsCountNuint;
- }
- else
- {
- // Take the hit of the 64-bit extension now.
- tempUtf8CodeUnitCountAdjustment -= 2 * (uint)surrogatePairsCountNuint;
- }
- }
-
- tempUtf8CodeUnitCountAdjustment += popcnt;
- pInputBuffer += Vector128<ushort>.Count;
- inputLength -= Vector128<ushort>.Count;
- } while (inputLength >= Vector128<ushort>.Count);
- }
- }
- else if (Vector.IsHardwareAccelerated)
- {
- if (inputLength >= Vector<ushort>.Count)
- {
- Vector<ushort> vector0080 = new Vector<ushort>(0x0080);
- Vector<ushort> vector0400 = new Vector<ushort>(0x0400);
- Vector<ushort> vector0800 = new Vector<ushort>(0x0800);
- Vector<ushort> vectorD800 = new Vector<ushort>(0xD800);
-
- do
- {
- // The 'twoOrMoreUtf8Bytes' and 'threeOrMoreUtf8Bytes' vectors will contain
- // elements whose values are 0xFFFF (-1 as signed word) iff the corresponding
- // UTF-16 code unit was >= 0x0080 and >= 0x0800, respectively. By summing these
- // vectors, each element of the sum will contain one of three values:
- //
- // 0x0000 ( 0) = original char was 0000..007F
- // 0xFFFF (-1) = original char was 0080..07FF
- // 0xFFFE (-2) = original char was 0800..FFFF
- //
- // We'll negate them to produce a value 0..2 for each element, then sum all the
- // elements together to produce the number of *additional* UTF-8 code units
- // required to represent this UTF-16 data. This is similar to the popcnt step
- // performed by the SSE2 code path. This will overcount surrogates, but we'll
- // handle that shortly.
-
- Vector<ushort> utf16Data = Unsafe.ReadUnaligned<Vector<ushort>>(pInputBuffer);
- Vector<ushort> twoOrMoreUtf8Bytes = Vector.GreaterThanOrEqual(utf16Data, vector0080);
- Vector<ushort> threeOrMoreUtf8Bytes = Vector.GreaterThanOrEqual(utf16Data, vector0800);
- Vector<nuint> sumVector = (Vector<nuint>)(Vector<ushort>.Zero - twoOrMoreUtf8Bytes - threeOrMoreUtf8Bytes);
-
- // We'll try summing by a natural word (rather than a 16-bit word) at a time,
- // which should halve the number of operations we must perform.
-
- nuint popcnt = 0;
- for (int i = 0; i < Vector<nuint>.Count; i++)
- {
- popcnt += sumVector[i];
- }
-
- uint popcnt32 = (uint)popcnt;
- if (IntPtr.Size == 8)
- {
- popcnt32 += (uint)(popcnt >> 32);
- }
-
- // As in the SSE4.1 paths, compute popcnt but don't fold it in until we
- // know there aren't any unpaired surrogates in the input data.
-
- popcnt32 = (ushort)popcnt32 + (popcnt32 >> 16);
-
- // Now check for surrogates.
-
- utf16Data -= vectorD800;
- Vector<ushort> surrogateChars = Vector.LessThan(utf16Data, vector0800);
- if (surrogateChars != Vector<ushort>.Zero)
- {
- // There's at least one surrogate (high or low) UTF-16 code unit in
- // the vector. We'll build up additional vectors: 'highSurrogateChars'
- // and 'lowSurrogateChars', where the elements are 0xFFFF iff the original
- // UTF-16 code unit was a high or low surrogate, respectively.
-
- Vector<ushort> highSurrogateChars = Vector.LessThan(utf16Data, vector0400);
- Vector<ushort> lowSurrogateChars = Vector.AndNot(surrogateChars, highSurrogateChars);
-
- // We want to make sure that each high surrogate code unit is followed by
- // a low surrogate code unit and each low surrogate code unit follows a
- // high surrogate code unit. Since we don't have an equivalent of pmovmskb
- // or palignr available to us, we'll do this as a loop. We won't look at
- // the very last high surrogate char element since we don't yet know if
- // the next vector read will have a low surrogate char element.
-
- if (lowSurrogateChars[0] != 0)
- {
- goto Error; // error: start of buffer contains standalone low surrogate char
- }
-
- ushort surrogatePairsCount = 0;
- for (int i = 0; i < Vector<ushort>.Count - 1; i++)
- {
- surrogatePairsCount -= highSurrogateChars[i]; // turns into +1 or +0
- if (highSurrogateChars[i] != lowSurrogateChars[i + 1])
- {
- goto NonVectorizedLoop; // error: mismatched surrogate pair; break out of vectorized logic
- }
- }
-
- if (highSurrogateChars[Vector<ushort>.Count - 1] != 0)
- {
- // There was a standalone high surrogate at the end of the vector.
- // We'll adjust our counters so that we don't consider this char consumed.
-
- pInputBuffer--;
- inputLength++;
- popcnt32 -= 2;
- }
-
- nint surrogatePairsCountNint = (nint)surrogatePairsCount; // zero-extend to native int size
-
- // 2 UTF-16 chars become 1 Unicode scalar
-
- tempScalarCountAdjustment -= (int)surrogatePairsCountNint;
-
- // Since each surrogate code unit was >= 0x0800, we eagerly assumed
- // it'd be encoded as 3 UTF-8 code units. Each surrogate half is only
- // encoded as 2 UTF-8 code units (for 4 UTF-8 code units total),
- // so we'll adjust this now.
-
- tempUtf8CodeUnitCountAdjustment -= surrogatePairsCountNint;
- tempUtf8CodeUnitCountAdjustment -= surrogatePairsCountNint;
- }
-
- tempUtf8CodeUnitCountAdjustment += popcnt32;
- pInputBuffer += Vector<ushort>.Count;
- inputLength -= Vector<ushort>.Count;
- } while (inputLength >= Vector<ushort>.Count);
- }
- }
-
- NonVectorizedLoop:
-
- // Vectorization isn't supported on our current platform, or the input was too small to benefit
- // from vectorization, or we saw invalid UTF-16 data in the vectorized code paths and need to
- // drain remaining valid chars before we report failure.
-
- for (; inputLength > 0; pInputBuffer++, inputLength--)
- {
- uint thisChar = pInputBuffer[0];
- if (thisChar <= 0x7F)
- {
- continue;
- }
-
- // Bump adjustment by +1 for U+0080..U+07FF; by +2 for U+0800..U+FFFF.
- // This optimistically assumes no surrogates, which we'll handle shortly.
-
- tempUtf8CodeUnitCountAdjustment += (thisChar + 0x0001_F800u) >> 16;
-
- if (!UnicodeUtility.IsSurrogateCodePoint(thisChar))
- {
- continue;
- }
-
- // Found a surrogate char. Back out the adjustment we made above, then
- // try to consume the entire surrogate pair all at once. We won't bother
- // trying to interpret the surrogate pair as a scalar value; we'll only
- // validate that its bit pattern matches what's expected for a surrogate pair.
-
- tempUtf8CodeUnitCountAdjustment -= 2;
-
- if (inputLength == 1)
- {
- goto Error; // input buffer too small to read a surrogate pair
- }
-
- thisChar = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- if (((thisChar - (BitConverter.IsLittleEndian ? 0xDC00_D800u : 0xD800_DC00u)) & 0xFC00_FC00u) != 0)
- {
- goto Error; // not a well-formed surrogate pair
- }
-
- tempScalarCountAdjustment--; // 2 UTF-16 code units -> 1 scalar
- tempUtf8CodeUnitCountAdjustment += 2; // 2 UTF-16 code units -> 4 UTF-8 code units
-
- pInputBuffer++; // consumed one extra char
- inputLength--;
- }
-
- Error:
-
- // Also used for normal return.
-
- utf8CodeUnitCountAdjustment = tempUtf8CodeUnitCountAdjustment;
- scalarCountAdjustment = tempScalarCountAdjustment;
- return pInputBuffer;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.cs b/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.cs
deleted file mode 100644
index 828776b4361..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf16Utility.cs
+++ /dev/null
@@ -1,215 +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 System.Runtime.CompilerServices;
-using System.Diagnostics;
-
-namespace System.Text.Unicode
-{
- internal static partial class Utf16Utility
- {
- /// <summary>
- /// Returns true iff the UInt32 represents two ASCII UTF-16 characters in machine endianness.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool AllCharsInUInt32AreAscii(uint value)
- {
- return (value & ~0x007F_007Fu) == 0;
- }
-
- /// <summary>
- /// Returns true iff the UInt64 represents four ASCII UTF-16 characters in machine endianness.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool AllCharsInUInt64AreAscii(ulong value)
- {
- return (value & ~0x007F_007F_007F_007Ful) == 0;
- }
-
- /// <summary>
- /// Given a UInt32 that represents two ASCII UTF-16 characters, returns the invariant
- /// lowercase representation of those characters. Requires the input value to contain
- /// two ASCII UTF-16 characters in machine endianness.
- /// </summary>
- /// <remarks>
- /// This is a branchless implementation.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static uint ConvertAllAsciiCharsInUInt32ToLowercase(uint value)
- {
- // ASSUMPTION: Caller has validated that input value is ASCII.
- Debug.Assert(AllCharsInUInt32AreAscii(value));
-
- // the 0x80 bit of each word of 'lowerIndicator' will be set iff the word has value >= 'A'
- uint lowerIndicator = value + 0x0080_0080u - 0x0041_0041u;
-
- // the 0x80 bit of each word of 'upperIndicator' will be set iff the word has value > 'Z'
- uint upperIndicator = value + 0x0080_0080u - 0x005B_005Bu;
-
- // the 0x80 bit of each word of 'combinedIndicator' will be set iff the word has value >= 'A' and <= 'Z'
- uint combinedIndicator = (lowerIndicator ^ upperIndicator);
-
- // the 0x20 bit of each word of 'mask' will be set iff the word has value >= 'A' and <= 'Z'
- uint mask = (combinedIndicator & 0x0080_0080u) >> 2;
-
- return value ^ mask; // bit flip uppercase letters [A-Z] => [a-z]
- }
-
- /// <summary>
- /// Given a UInt32 that represents two ASCII UTF-16 characters, returns the invariant
- /// uppercase representation of those characters. Requires the input value to contain
- /// two ASCII UTF-16 characters in machine endianness.
- /// </summary>
- /// <remarks>
- /// This is a branchless implementation.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static uint ConvertAllAsciiCharsInUInt32ToUppercase(uint value)
- {
- // ASSUMPTION: Caller has validated that input value is ASCII.
- Debug.Assert(AllCharsInUInt32AreAscii(value));
-
- // the 0x80 bit of each word of 'lowerIndicator' will be set iff the word has value >= 'a'
- uint lowerIndicator = value + 0x0080_0080u - 0x0061_0061u;
-
- // the 0x80 bit of each word of 'upperIndicator' will be set iff the word has value > 'z'
- uint upperIndicator = value + 0x0080_0080u - 0x007B_007Bu;
-
- // the 0x80 bit of each word of 'combinedIndicator' will be set iff the word has value >= 'a' and <= 'z'
- uint combinedIndicator = (lowerIndicator ^ upperIndicator);
-
- // the 0x20 bit of each word of 'mask' will be set iff the word has value >= 'a' and <= 'z'
- uint mask = (combinedIndicator & 0x0080_0080u) >> 2;
-
- return value ^ mask; // bit flip lowercase letters [a-z] => [A-Z]
- }
-
- /// <summary>
- /// Given a UInt32 that represents two ASCII UTF-16 characters, returns true iff
- /// the input contains one or more lowercase ASCII characters.
- /// </summary>
- /// <remarks>
- /// This is a branchless implementation.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool UInt32ContainsAnyLowercaseAsciiChar(uint value)
- {
- // ASSUMPTION: Caller has validated that input value is ASCII.
- Debug.Assert(AllCharsInUInt32AreAscii(value));
-
- // the 0x80 bit of each word of 'lowerIndicator' will be set iff the word has value >= 'a'
- uint lowerIndicator = value + 0x0080_0080u - 0x0061_0061u;
-
- // the 0x80 bit of each word of 'upperIndicator' will be set iff the word has value > 'z'
- uint upperIndicator = value + 0x0080_0080u - 0x007B_007Bu;
-
- // the 0x80 bit of each word of 'combinedIndicator' will be set iff the word has value >= 'a' and <= 'z'
- uint combinedIndicator = (lowerIndicator ^ upperIndicator);
-
- return (combinedIndicator & 0x0080_0080u) != 0;
- }
-
- /// <summary>
- /// Given a UInt32 that represents two ASCII UTF-16 characters, returns true iff
- /// the input contains one or more uppercase ASCII characters.
- /// </summary>
- /// <remarks>
- /// This is a branchless implementation.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool UInt32ContainsAnyUppercaseAsciiChar(uint value)
- {
- // ASSUMPTION: Caller has validated that input value is ASCII.
- Debug.Assert(AllCharsInUInt32AreAscii(value));
-
- // the 0x80 bit of each word of 'lowerIndicator' will be set iff the word has value >= 'A'
- uint lowerIndicator = value + 0x0080_0080u - 0x0041_0041u;
-
- // the 0x80 bit of each word of 'upperIndicator' will be set iff the word has value > 'Z'
- uint upperIndicator = value + 0x0080_0080u - 0x005B_005Bu;
-
- // the 0x80 bit of each word of 'combinedIndicator' will be set iff the word has value >= 'A' and <= 'Z'
- uint combinedIndicator = (lowerIndicator ^ upperIndicator);
-
- return (combinedIndicator & 0x0080_0080u) != 0;
- }
-
- /// <summary>
- /// Given two UInt32s that represent two ASCII UTF-16 characters each, returns true iff
- /// the two inputs are equal using an ordinal case-insensitive comparison.
- /// </summary>
- /// <remarks>
- /// This is a branchless implementation.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool UInt32OrdinalIgnoreCaseAscii(uint valueA, uint valueB)
- {
- // ASSUMPTION: Caller has validated that input values are ASCII.
- Debug.Assert(AllCharsInUInt32AreAscii(valueA));
- Debug.Assert(AllCharsInUInt32AreAscii(valueB));
-
- // a mask of all bits which are different between A and B
- uint differentBits = valueA ^ valueB;
-
- // the 0x80 bit of each word of 'lowerIndicator' will be set iff the word has value < 'A'
- uint lowerIndicator = valueA + 0x0100_0100u - 0x0041_0041u;
-
- // the 0x80 bit of each word of 'upperIndicator' will be set iff (word | 0x20) has value > 'z'
- uint upperIndicator = (valueA | 0x0020_0020u) + 0x0080_0080u - 0x007B_007Bu;
-
- // the 0x80 bit of each word of 'combinedIndicator' will be set iff the word is *not* [A-Za-z]
- uint combinedIndicator = lowerIndicator | upperIndicator;
-
- // Shift all the 0x80 bits of 'combinedIndicator' into the 0x20 positions, then set all bits
- // aside from 0x20. This creates a mask where all bits are set *except* for the 0x20 bits
- // which correspond to alpha chars (either lower or upper). For these alpha chars only, the
- // 0x20 bit is allowed to differ between the two input values. Every other char must be an
- // exact bitwise match between the two input values. In other words, (valueA & mask) will
- // convert valueA to uppercase, so (valueA & mask) == (valueB & mask) answers "is the uppercase
- // form of valueA equal to the uppercase form of valueB?" (Technically if valueA has an alpha
- // char in the same position as a non-alpha char in valueB, or vice versa, this operation will
- // result in nonsense, but it'll still compute as inequal regardless, which is what we want ultimately.)
- // The line below is a more efficient way of doing the same check taking advantage of the XOR
- // computation we performed at the beginning of the method.
-
- return (((combinedIndicator >> 2) | ~0x0020_0020u) & differentBits) == 0;
- }
-
- /// <summary>
- /// Given two UInt64s that represent four ASCII UTF-16 characters each, returns true iff
- /// the two inputs are equal using an ordinal case-insensitive comparison.
- /// </summary>
- /// <remarks>
- /// This is a branchless implementation.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool UInt64OrdinalIgnoreCaseAscii(ulong valueA, ulong valueB)
- {
- // ASSUMPTION: Caller has validated that input values are ASCII.
- Debug.Assert(AllCharsInUInt64AreAscii(valueA));
- Debug.Assert(AllCharsInUInt64AreAscii(valueB));
-
- // the 0x80 bit of each word of 'lowerIndicator' will be set iff the word has value >= 'A'
- ulong lowerIndicator = valueA + 0x0080_0080_0080_0080ul - 0x0041_0041_0041_0041ul;
-
- // the 0x80 bit of each word of 'upperIndicator' will be set iff (word | 0x20) has value <= 'z'
- ulong upperIndicator = (valueA | 0x0020_0020_0020_0020ul) + 0x0100_0100_0100_0100ul - 0x007B_007B_007B_007Bul;
-
- // the 0x20 bit of each word of 'combinedIndicator' will be set iff the word is [A-Za-z]
- ulong combinedIndicator = (0x0080_0080_0080_0080ul & lowerIndicator & upperIndicator) >> 2;
-
- // Convert both values to lowercase (using the combined indicator from the first value)
- // and compare for equality. It's possible that the first value will contain an alpha character
- // where the second value doesn't (or vice versa), and applying the combined indicator will
- // create nonsensical data, but the comparison would have failed anyway in this case so it's
- // a safe operation to perform.
- //
- // This 64-bit method is similar to the 32-bit method, but it performs the equivalent of convert-to-
- // lowercase-then-compare rather than convert-to-uppercase-and-compare. This particular operation
- // happens to be faster on x64.
-
- return (valueA | combinedIndicator) == (valueB | combinedIndicator);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8.cs b/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8.cs
deleted file mode 100644
index c9279997ea7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8.cs
+++ /dev/null
@@ -1,221 +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 System.Buffers;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Text.Unicode
-{
- public static class Utf8
- {
- /*
- * OperationStatus-based APIs for transcoding of chunked data.
- * This method is similar to Encoding.UTF8.GetBytes / GetChars but has a
- * different calling convention, different error handling mechanisms, and
- * different performance characteristics.
- *
- * If 'replaceInvalidSequences' is true, the method will replace any ill-formed
- * subsequence in the source with U+FFFD when transcoding to the destination,
- * then it will continue processing the remainder of the buffers. Otherwise
- * the method will return OperationStatus.InvalidData.
- *
- * If the method does return an error code, the out parameters will represent
- * how much of the data was successfully transcoded, and the location of the
- * ill-formed subsequence can be deduced from these values.
- *
- * If 'replaceInvalidSequences' is true, the method is guaranteed never to return
- * OperationStatus.InvalidData. If 'isFinalBlock' is true, the method is
- * guaranteed never to return OperationStatus.NeedMoreData.
- */
-
- /// <summary>
- /// Transcodes the UTF-16 <paramref name="source"/> buffer to <paramref name="destination"/> as UTF-8.
- /// </summary>
- /// <remarks>
- /// If <paramref name="replaceInvalidSequences"/> is <see langword="true"/>, invalid UTF-16 sequences
- /// in <paramref name="source"/> will be replaced with U+FFFD in <paramref name="destination"/>, and
- /// this method will not return <see cref="OperationStatus.InvalidData"/>.
- /// </remarks>
- public static unsafe OperationStatus FromUtf16(ReadOnlySpan<char> source, Span<byte> destination, out int charsRead, out int bytesWritten, bool replaceInvalidSequences = true, bool isFinalBlock = true)
- {
- // Throwaway span accesses - workaround for https://github.com/dotnet/coreclr/issues/23437
-
- _ = source.Length;
- _ = destination.Length;
-
- fixed (char* pOriginalSource = &MemoryMarshal.GetReference(source))
- fixed (byte* pOriginalDestination = &MemoryMarshal.GetReference(destination))
- {
- // We're going to bulk transcode as much as we can in a loop, iterating
- // every time we see bad data that requires replacement.
-
- OperationStatus operationStatus = OperationStatus.Done;
- char* pInputBufferRemaining = pOriginalSource;
- byte* pOutputBufferRemaining = pOriginalDestination;
-
- while (!source.IsEmpty)
- {
- // We've pinned the spans at the entry point to this method.
- // It's safe for us to use Unsafe.AsPointer on them during this loop.
-
- operationStatus = Utf8Utility.TranscodeToUtf8(
- pInputBuffer: (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(source)),
- inputLength: source.Length,
- pOutputBuffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(destination)),
- outputBytesRemaining: destination.Length,
- pInputBufferRemaining: out pInputBufferRemaining,
- pOutputBufferRemaining: out pOutputBufferRemaining);
-
- // If we finished the operation entirely or we ran out of space in the destination buffer,
- // or if we need more input data and the caller told us that there's possibly more data
- // coming, return immediately.
-
- if (operationStatus <= OperationStatus.DestinationTooSmall
- || (operationStatus == OperationStatus.NeedMoreData && !isFinalBlock))
- {
- break;
- }
-
- // We encountered invalid data, or we need more data but the caller told us we're
- // at the end of the stream. In either case treat this as truly invalid.
- // If the caller didn't tell us to replace invalid sequences, return immediately.
-
- if (!replaceInvalidSequences)
- {
- operationStatus = OperationStatus.InvalidData; // status code may have been NeedMoreData - force to be error
- break;
- }
-
- // We're going to attempt to write U+FFFD to the destination buffer.
- // Do we even have enough space to do so?
-
- destination = destination.Slice((int)(pOutputBufferRemaining - (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(destination))));
-
- if (2 >= (uint)destination.Length)
- {
- operationStatus = OperationStatus.DestinationTooSmall;
- break;
- }
-
- destination[0] = 0xEF; // U+FFFD = [ EF BF BD ] in UTF-8
- destination[1] = 0xBF;
- destination[2] = 0xBD;
- destination = destination.Slice(3);
-
- // Invalid UTF-16 sequences are always of length 1. Just skip the next character.
-
- source = source.Slice((int)(pInputBufferRemaining - (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(source))) + 1);
-
- operationStatus = OperationStatus.Done; // we patched the error - if we're about to break out of the loop this is a success case
- pInputBufferRemaining = (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(source));
- pOutputBufferRemaining = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(destination));
- }
-
- // Not possible to make any further progress - report to our caller how far we got.
-
- charsRead = (int)(pInputBufferRemaining - pOriginalSource);
- bytesWritten = (int)(pOutputBufferRemaining - pOriginalDestination);
- return operationStatus;
- }
- }
-
- /// <summary>
- /// Transcodes the UTF-8 <paramref name="source"/> buffer to <paramref name="destination"/> as UTF-16.
- /// </summary>
- /// <remarks>
- /// If <paramref name="replaceInvalidSequences"/> is <see langword="true"/>, invalid UTF-8 sequences
- /// in <paramref name="source"/> will be replaced with U+FFFD in <paramref name="destination"/>, and
- /// this method will not return <see cref="OperationStatus.InvalidData"/>.
- /// </remarks>
- public static unsafe OperationStatus ToUtf16(ReadOnlySpan<byte> source, Span<char> destination, out int bytesRead, out int charsWritten, bool replaceInvalidSequences = true, bool isFinalBlock = true)
- {
- // Throwaway span accesses - workaround for https://github.com/dotnet/coreclr/issues/23437
-
- _ = source.Length;
- _ = destination.Length;
-
- // We'll be mutating these values throughout our loop.
-
- fixed (byte* pOriginalSource = &MemoryMarshal.GetReference(source))
- fixed (char* pOriginalDestination = &MemoryMarshal.GetReference(destination))
- {
- // We're going to bulk transcode as much as we can in a loop, iterating
- // every time we see bad data that requires replacement.
-
- OperationStatus operationStatus = OperationStatus.Done;
- byte* pInputBufferRemaining = pOriginalSource;
- char* pOutputBufferRemaining = pOriginalDestination;
-
- while (!source.IsEmpty)
- {
- // We've pinned the spans at the entry point to this method.
- // It's safe for us to use Unsafe.AsPointer on them during this loop.
-
- operationStatus = Utf8Utility.TranscodeToUtf16(
- pInputBuffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(source)),
- inputLength: source.Length,
- pOutputBuffer: (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(destination)),
- outputCharsRemaining: destination.Length,
- pInputBufferRemaining: out pInputBufferRemaining,
- pOutputBufferRemaining: out pOutputBufferRemaining);
-
- // If we finished the operation entirely or we ran out of space in the destination buffer,
- // or if we need more input data and the caller told us that there's possibly more data
- // coming, return immediately.
-
- if (operationStatus <= OperationStatus.DestinationTooSmall
- || (operationStatus == OperationStatus.NeedMoreData && !isFinalBlock))
- {
- break;
- }
-
- // We encountered invalid data, or we need more data but the caller told us we're
- // at the end of the stream. In either case treat this as truly invalid.
- // If the caller didn't tell us to replace invalid sequences, return immediately.
-
- if (!replaceInvalidSequences)
- {
- operationStatus = OperationStatus.InvalidData; // status code may have been NeedMoreData - force to be error
- break;
- }
-
- // We're going to attempt to write U+FFFD to the destination buffer.
- // Do we even have enough space to do so?
-
- destination = destination.Slice((int)(pOutputBufferRemaining - (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(destination))));
-
- if (destination.IsEmpty)
- {
- operationStatus = OperationStatus.DestinationTooSmall;
- break;
- }
-
- destination[0] = (char)UnicodeUtility.ReplacementChar;
- destination = destination.Slice(1);
-
- // Now figure out how many bytes of the source we must skip over before we should retry
- // the operation. This might be more than 1 byte.
-
- source = source.Slice((int)(pInputBufferRemaining - (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(source))));
- Debug.Assert(!source.IsEmpty, "Expected 'Done' if source is fully consumed.");
-
- Rune.DecodeFromUtf8(source, out _, out int bytesConsumedJustNow);
- source = source.Slice(bytesConsumedJustNow);
-
- operationStatus = OperationStatus.Done; // we patched the error - if we're about to break out of the loop this is a success case
- pInputBufferRemaining = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(source));
- pOutputBufferRemaining = (char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(destination));
- }
-
- // Not possible to make any further progress - report to our caller how far we got.
-
- bytesRead = (int)(pInputBufferRemaining - pOriginalSource);
- charsWritten = (int)(pOutputBufferRemaining - pOriginalDestination);
- return operationStatus;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Helpers.cs b/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Helpers.cs
deleted file mode 100644
index 693c6f41ddd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Helpers.cs
+++ /dev/null
@@ -1,862 +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 System.Buffers.Binary;
-using System.Diagnostics;
-using System.Numerics;
-using System.Runtime.CompilerServices;
-using System.Runtime.Intrinsics.X86;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Text.Unicode
-{
- internal static partial class Utf8Utility
- {
- /// <summary>
- /// Given a machine-endian DWORD which four bytes of UTF-8 data, interprets the
- /// first three bytes as a three-byte UTF-8 subsequence and returns the UTF-16 representation.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint ExtractCharFromFirstThreeByteSequence(uint value)
- {
- Debug.Assert(UInt32BeginsWithUtf8ThreeByteMask(value));
-
- if (BitConverter.IsLittleEndian)
- {
- // value = [ ######## | 10xxxxxx 10yyyyyy 1110zzzz ]
- return ((value & 0x003F0_000u) >> 16)
- | ((value & 0x0000_3F00u) >> 2)
- | ((value & 0x0000_000Fu) << 12);
- }
- else
- {
- // value = [ 1110zzzz 10yyyyyy 10xxxxxx | ######## ]
- return ((value & 0x0F00_0000u) >> 12)
- | ((value & 0x003F_0000u) >> 10)
- | ((value & 0x0000_3F00u) >> 8);
- }
- }
-
- /// <summary>
- /// Given a machine-endian DWORD which four bytes of UTF-8 data, interprets the
- /// first two bytes as a two-byte UTF-8 subsequence and returns the UTF-16 representation.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint ExtractCharFromFirstTwoByteSequence(uint value)
- {
- Debug.Assert(UInt32BeginsWithUtf8TwoByteMask(value) && !UInt32BeginsWithOverlongUtf8TwoByteSequence(value));
-
- if (BitConverter.IsLittleEndian)
- {
- // value = [ ######## ######## | 10xxxxxx 110yyyyy ]
- uint leadingByte = (uint)(byte)value << 6;
- return (uint)(byte)(value >> 8) + leadingByte - (0xC0u << 6) - 0x80u; // remove header bits
- }
- else
- {
- // value = [ 110yyyyy 10xxxxxx | ######## ######## ]
- return (char)(((value & 0x1F00_0000u) >> 18) | ((value & 0x003F_0000u) >> 16));
- }
- }
-
- /// <summary>
- /// Given a machine-endian DWORD which four bytes of UTF-8 data, interprets the input as a
- /// four-byte UTF-8 sequence and returns the machine-endian DWORD of the UTF-16 representation.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint ExtractCharsFromFourByteSequence(uint value)
- {
- if (BitConverter.IsLittleEndian)
- {
- if (Bmi2.IsSupported)
- {
- // need to reverse endianness for bit manipulation to work correctly
- value = BinaryPrimitives.ReverseEndianness(value);
-
- // value = [ 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx ]
- // want to return [ 110110wwwwxxxxxx 110111xxxxxxxxxx ]
- // where wwww = uuuuu - 1
-
- uint highSurrogateChar = Bmi2.ParallelBitExtract(value, 0b00000111_00111111_00110000_00000000u);
- uint lowSurrogateChar = Bmi2.ParallelBitExtract(value, 0b00000000_00000000_00001111_00111111u);
-
- uint combined = (lowSurrogateChar << 16) + highSurrogateChar;
- combined -= 0x40u; // wwww = uuuuu - 1
- combined += 0xDC00_D800u; // add surrogate markers
- return combined;
- }
- else
- {
- // input is UTF8 [ 10xxxxxx 10yyyyyy 10uuzzzz 11110uuu ] = scalar 000uuuuu zzzzyyyy yyxxxxxx
- // want to return UTF16 scalar 000uuuuuzzzzyyyyyyxxxxxx = [ 110111yy yyxxxxxx 110110ww wwzzzzyy ]
- // where wwww = uuuuu - 1
- uint retVal = (uint)(byte)value << 8; // retVal = [ 00000000 00000000 11110uuu 00000000 ]
- retVal |= (value & 0x0000_3F00u) >> 6; // retVal = [ 00000000 00000000 11110uuu uuzzzz00 ]
- retVal |= (value & 0x0030_0000u) >> 20; // retVal = [ 00000000 00000000 11110uuu uuzzzzyy ]
- retVal |= (value & 0x3F00_0000u) >> 8; // retVal = [ 00000000 00xxxxxx 11110uuu uuzzzzyy ]
- retVal |= (value & 0x000F_0000u) << 6; // retVal = [ 000000yy yyxxxxxx 11110uuu uuzzzzyy ]
- retVal -= 0x0000_0040u; // retVal = [ 000000yy yyxxxxxx 111100ww wwzzzzyy ]
- retVal -= 0x0000_2000u; // retVal = [ 000000yy yyxxxxxx 110100ww wwzzzzyy ]
- retVal += 0x0000_0800u; // retVal = [ 000000yy yyxxxxxx 110110ww wwzzzzyy ]
- retVal += 0xDC00_0000u; // retVal = [ 110111yy yyxxxxxx 110110ww wwzzzzyy ]
- return retVal;
- }
- }
- else
- {
- // input is UTF8 [ 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx ] = scalar 000uuuuu zzzzyyyy yyxxxxxx
- // want to return UTF16 scalar 000uuuuuxxxxxxxxxxxxxxxx = [ 110110wwwwxxxxxx 110111xxxxxxxxx ]
- // where wwww = uuuuu - 1
- uint retVal = value & 0xFF00_0000u; // retVal = [ 11110uuu 00000000 00000000 00000000 ]
- retVal |= (value & 0x003F_0000u) << 2; // retVal = [ 11110uuu uuzzzz00 00000000 00000000 ]
- retVal |= (value & 0x0000_3000u) << 4; // retVal = [ 11110uuu uuzzzzyy 00000000 00000000 ]
- retVal |= (value & 0x0000_0F00u) >> 2; // retVal = [ 11110uuu uuzzzzyy 000000yy yy000000 ]
- retVal |= (value & 0x0000_003Fu); // retVal = [ 11110uuu uuzzzzyy 000000yy yyxxxxxx ]
- retVal -= 0x2000_0000u; // retVal = [ 11010uuu uuzzzzyy 000000yy yyxxxxxx ]
- retVal -= 0x0040_0000u; // retVal = [ 110100ww wwzzzzyy 000000yy yyxxxxxx ]
- retVal += 0x0000_DC00u; // retVal = [ 110100ww wwzzzzyy 110111yy yyxxxxxx ]
- retVal += 0x0800_0000u; // retVal = [ 110110ww wwzzzzyy 110111yy yyxxxxxx ]
- return retVal;
- }
- }
-
- /// <summary>
- /// Given a 32-bit integer that represents a valid packed UTF-16 surrogate pair, all in machine-endian order,
- /// returns the packed 4-byte UTF-8 representation of this scalar value, also in machine-endian order.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint ExtractFourUtf8BytesFromSurrogatePair(uint value)
- {
- Debug.Assert(IsWellFormedUtf16SurrogatePair(value));
-
- if (BitConverter.IsLittleEndian)
- {
- // input = [ 110111yyyyxxxxxx 110110wwwwzzzzyy ] = scalar (000uuuuu zzzzyyyy yyxxxxxx)
- // must return [ 10xxxxxx 10yyyyyy 10uuzzzz 11110uuu ], where wwww = uuuuu - 1
-
- if (Bmi2.IsSupported)
- {
- // Since pdep and pext have high latencies and can only be dispatched to a single execution port, we want
- // to use them conservatively. Here, we'll build up the scalar value (this would normally be pext) via simple
- // logical and arithmetic operations, and use only pdep for the expensive step of exploding the scalar across
- // all four output bytes.
-
- uint unmaskedScalar = (value << 10) + (value >> 16) + (0x40u << 10) /* uuuuu = wwww + 1 */ - 0xDC00u /* remove low surrogate marker */;
-
- // Now, unmaskedScalar = [ xxxxxx11 011uuuuu zzzzyyyy yyxxxxxx ]. There's a bit of unneeded junk at the beginning
- // that should normally be masked out via an and, but we'll just direct pdep to ignore it.
-
- uint exploded = Bmi2.ParallelBitDeposit(unmaskedScalar, 0b00000111_00111111_00111111_00111111u); // = [ 00000uuu 00uuzzzz 00yyyyyy 00xxxxxx ]
- return BinaryPrimitives.ReverseEndianness(exploded + 0xF080_8080u); // = [ 10xxxxxx 10yyyyyy 10uuzzzz 11110uuu ]
- }
- else
- {
- value += 0x0000_0040u; // = [ 110111yyyyxxxxxx 11011uuuuuzzzzyy ]
-
- uint tempA = BinaryPrimitives.ReverseEndianness(value & 0x003F_0700u); // = [ 00000000 00000uuu 00xxxxxx 00000000 ]
- tempA = BitOperations.RotateLeft(tempA, 16); // = [ 00xxxxxx 00000000 00000000 00000uuu ]
-
- uint tempB = (value & 0x00FCu) << 6; // = [ 00000000 00000000 00uuzzzz 00000000 ]
- uint tempC = (value >> 6) & 0x000F_0000u; // = [ 00000000 0000yyyy 00000000 00000000 ]
- tempC |= tempB;
-
- uint tempD = (value & 0x03u) << 20; // = [ 00000000 00yy0000 00000000 00000000 ]
- tempD |= 0x8080_80F0u;
-
- return tempD | tempA | tempC; // = [ 10xxxxxx 10yyyyyy 10uuzzzz 11110uuu ]
- }
- }
- else
- {
- // input = [ 110110wwwwzzzzyy 110111yyyyxxxxxx ], where wwww = uuuuu - 1
- // must return [ 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx ], where wwww = uuuuu - 1
-
- value -= 0xD800_DC00u; // = [ 000000wwwwzzzzyy 000000yyyyxxxxxx ]
- value += 0x0040_0000u; // = [ 00000uuuuuzzzzyy 000000yyyyxxxxxx ]
-
- uint tempA = value & 0x0700_0000u; // = [ 00000uuu 00000000 00000000 00000000 ]
- uint tempB = (value >> 2) & 0x003F_0000u; // = [ 00000000 00uuzzzz 00000000 00000000 ]
- tempB |= tempA;
-
- uint tempC = (value << 2) & 0x0000_0F00u; // = [ 00000000 00000000 0000yyyy 00000000 ]
- uint tempD = (value >> 6) & 0x0003_0000u; // = [ 00000000 00000000 00yy0000 00000000 ]
- tempD |= tempC;
-
- uint tempE = (value & 0x3Fu) + 0xF080_8080u; // = [ 11110000 10000000 10000000 10xxxxxx ]
- return tempE | tempB | tempD; // = [ 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx ]
- }
- }
-
- /// <summary>
- /// Given a machine-endian DWORD which represents two adjacent UTF-8 two-byte sequences,
- /// returns the machine-endian DWORD representation of that same data as two adjacent
- /// UTF-16 byte sequences.
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint ExtractTwoCharsPackedFromTwoAdjacentTwoByteSequences(uint value)
- {
- // We don't want to swap the position of the high and low WORDs,
- // as the buffer was read in machine order and will be written in
- // machine order.
-
- if (BitConverter.IsLittleEndian)
- {
- // value = [ 10xxxxxx 110yyyyy | 10xxxxxx 110yyyyy ]
- return ((value & 0x3F003F00u) >> 8) | ((value & 0x001F001Fu) << 6);
- }
- else
- {
- // value = [ 110yyyyy 10xxxxxx | 110yyyyy 10xxxxxx ]
- return ((value & 0x1F001F00u) >> 2) | (value & 0x003F003Fu);
- }
- }
-
- /// <summary>
- /// Given a machine-endian DWORD which represents two adjacent UTF-16 sequences,
- /// returns the machine-endian DWORD representation of that same data as two
- /// adjacent UTF-8 two-byte sequences.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint ExtractTwoUtf8TwoByteSequencesFromTwoPackedUtf16Chars(uint value)
- {
- // stays in machine endian
-
- Debug.Assert(IsFirstCharTwoUtf8Bytes(value) && IsSecondCharTwoUtf8Bytes(value));
-
- if (BitConverter.IsLittleEndian)
- {
- // value = [ 00000YYY YYXXXXXX 00000yyy yyxxxxxx ]
- // want to return [ 10XXXXXX 110YYYYY 10xxxxxx 110yyyyy ]
-
- return ((value >> 6) & 0x001F_001Fu) + ((value << 8) & 0x3F00_3F00u) + 0x80C0_80C0u;
- }
- else
- {
- // value = [ 00000YYY YYXXXXXX 00000yyy yyxxxxxx ]
- // want to return [ 110YYYYY 10XXXXXX 110yyyyy 10xxxxxx ]
-
- return ((value << 2) & 0x1F00_1F00u) + (value & 0x003F_003Fu) + 0xC080_C080u;
- }
- }
-
- /// <summary>
- /// Given a machine-endian DWORD which represents two adjacent UTF-16 sequences,
- /// returns the machine-endian DWORD representation of the first UTF-16 char
- /// as a UTF-8 two-byte sequence packed into a WORD and zero-extended to DWORD.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint ExtractUtf8TwoByteSequenceFromFirstUtf16Char(uint value)
- {
- // stays in machine endian
-
- Debug.Assert(IsFirstCharTwoUtf8Bytes(value));
-
- if (BitConverter.IsLittleEndian)
- {
- // value = [ ######## ######## 00000yyy yyxxxxxx ]
- // want to return [ ######## ######## 10xxxxxx 110yyyyy ]
-
- uint temp = (value << 2) & 0x1F00u; // [ 00000000 00000000 000yyyyy 00000000 ]
- value &= 0x3Fu; // [ 00000000 00000000 00000000 00xxxxxx ]
- return BinaryPrimitives.ReverseEndianness((ushort)(temp + value + 0xC080u)); // [ 00000000 00000000 10xxxxxx 110yyyyy ]
- }
- else
- {
- // value = [ 00000yyy yyxxxxxx ######## ######## ]
- // want to return [ ######## ######## 110yyyyy 10xxxxxx ]
-
- uint temp = (value >> 16) & 0x3Fu; // [ 00000000 00000000 00000000 00xxxxxx ]
- value = (value >> 22) & 0x1F00u; // [ 00000000 00000000 000yyyyy 0000000 ]
- return value + temp + 0xC080u;
- }
- }
-
- /// <summary>
- /// Given a 32-bit integer that represents two packed UTF-16 characters, all in machine-endian order,
- /// returns true iff the first UTF-16 character is ASCII.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsFirstCharAscii(uint value)
- {
- // Little-endian: Given [ #### AAAA ], return whether AAAA is in range [ 0000..007F ].
- // Big-endian: Given [ AAAA #### ], return whether AAAA is in range [ 0000..007F ].
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && (value & 0xFF80u) == 0)
- || (!BitConverter.IsLittleEndian && value < 0x0080_0000u);
- }
-
- /// <summary>
- /// Given a 32-bit integer that represents two packed UTF-16 characters, all in machine-endian order,
- /// returns true iff the first UTF-16 character requires *at least* 3 bytes to encode in UTF-8.
- /// This also returns true if the first UTF-16 character is a surrogate character (well-formedness is not validated).
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsFirstCharAtLeastThreeUtf8Bytes(uint value)
- {
- // Little-endian: Given [ #### AAAA ], return whether AAAA is in range [ 0800..FFFF ].
- // Big-endian: Given [ AAAA #### ], return whether AAAA is in range [ 0800..FFFF ].
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && (value & 0xF800u) != 0)
- || (!BitConverter.IsLittleEndian && value >= 0x0800_0000u);
- }
-
- /// <summary>
- /// Given a 32-bit integer that represents two packed UTF-16 characters, all in machine-endian order,
- /// returns true iff the first UTF-16 character is a surrogate character (either high or low).
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsFirstCharSurrogate(uint value)
- {
- // Little-endian: Given [ #### AAAA ], return whether AAAA is in range [ D800..DFFF ].
- // Big-endian: Given [ AAAA #### ], return whether AAAA is in range [ D800..DFFF ].
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && ((value - 0xD800u) & 0xF800u) == 0)
- || (!BitConverter.IsLittleEndian && (value - 0xD800_0000u) < 0x0800_0000u);
- }
-
- /// <summary>
- /// Given a 32-bit integer that represents two packed UTF-16 characters, all in machine-endian order,
- /// returns true iff the first UTF-16 character would be encoded as exactly 2 bytes in UTF-8.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsFirstCharTwoUtf8Bytes(uint value)
- {
- // Little-endian: Given [ #### AAAA ], return whether AAAA is in range [ 0080..07FF ].
- // Big-endian: Given [ AAAA #### ], return whether AAAA is in range [ 0080..07FF ].
-
- // TODO: I'd like to be able to write "(ushort)(value - 0x0080u) < 0x0780u" for the little-endian
- // case, but the JIT doesn't currently emit 16-bit comparisons efficiently.
- // Tracked as https://github.com/dotnet/coreclr/issues/18022.
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && ((value - 0x0080u) & 0xFFFFu) < 0x0780u)
- || (!BitConverter.IsLittleEndian && UnicodeUtility.IsInRangeInclusive(value, 0x0080_0000u, 0x07FF_FFFFu));
- }
-
- /// <summary>
- /// Returns <see langword="true"/> iff the low byte of <paramref name="value"/>
- /// is a UTF-8 continuation byte.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsLowByteUtf8ContinuationByte(uint value)
- {
- // The JIT won't emit a single 8-bit signed cmp instruction (see IsUtf8ContinuationByte),
- // so the best we can do for now is the lea / cmp pair.
- // Tracked as https://github.com/dotnet/coreclr/issues/18022.
-
- return (byte)(value - 0x80u) <= 0x3Fu;
- }
-
- /// <summary>
- /// Given a 32-bit integer that represents two packed UTF-16 characters, all in machine-endian order,
- /// returns true iff the second UTF-16 character is ASCII.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsSecondCharAscii(uint value)
- {
- // Little-endian: Given [ BBBB #### ], return whether BBBB is in range [ 0000..007F ].
- // Big-endian: Given [ #### BBBB ], return whether BBBB is in range [ 0000..007F ].
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && value < 0x0080_0000u)
- || (!BitConverter.IsLittleEndian && (value & 0xFF80u) == 0);
- }
-
- /// <summary>
- /// Given a 32-bit integer that represents two packed UTF-16 characters, all in machine-endian order,
- /// returns true iff the second UTF-16 character requires *at least* 3 bytes to encode in UTF-8.
- /// This also returns true if the second UTF-16 character is a surrogate character (well-formedness is not validated).
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsSecondCharAtLeastThreeUtf8Bytes(uint value)
- {
- // Little-endian: Given [ BBBB #### ], return whether BBBB is in range [ 0800..FFFF ].
- // Big-endian: Given [ #### BBBB ], return whether ABBBBAAA is in range [ 0800..FFFF ].
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && (value & 0xF800_0000u) != 0)
- || (!BitConverter.IsLittleEndian && (value & 0xF800u) != 0);
- }
-
- /// <summary>
- /// Given a 32-bit integer that represents two packed UTF-16 characters, all in machine-endian order,
- /// returns true iff the second UTF-16 character is a surrogate character (either high or low).
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsSecondCharSurrogate(uint value)
- {
- // Little-endian: Given [ BBBB #### ], return whether BBBB is in range [ D800..DFFF ].
- // Big-endian: Given [ #### BBBB ], return whether BBBB is in range [ D800..DFFF ].
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && (value - 0xD800_0000u) < 0x0800_0000u)
- || (!BitConverter.IsLittleEndian && ((value - 0xD800u) & 0xF800u) == 0);
- }
-
- /// <summary>
- /// Given a 32-bit integer that represents two packed UTF-16 characters, all in machine-endian order,
- /// returns true iff the second UTF-16 character would be encoded as exactly 2 bytes in UTF-8.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsSecondCharTwoUtf8Bytes(uint value)
- {
- // Little-endian: Given [ BBBB #### ], return whether BBBB is in range [ 0080..07FF ].
- // Big-endian: Given [ #### BBBB ], return whether BBBB is in range [ 0080..07FF ].
-
- // TODO: I'd like to be able to write "(ushort)(value - 0x0080u) < 0x0780u" for the big-endian
- // case, but the JIT doesn't currently emit 16-bit comparisons efficiently.
- // Tracked as https://github.com/dotnet/coreclr/issues/18022.
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && UnicodeUtility.IsInRangeInclusive(value, 0x0080_0000u, 0x07FF_FFFFu))
- || (!BitConverter.IsLittleEndian && ((value - 0x0080u) & 0xFFFFu) < 0x0780u);
- }
-
- /// <summary>
- /// Returns <see langword="true"/> iff <paramref name="value"/> is a UTF-8 continuation byte;
- /// i.e., has binary representation 10xxxxxx, where x is any bit.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static bool IsUtf8ContinuationByte(in byte value)
- {
- // This API takes its input as a readonly ref so that the JIT can emit "cmp ModRM" statements
- // directly rather than bounce a temporary through a register. That is, we want the JIT to be
- // able to emit a single "cmp byte ptr [data], C0h" statement if we're querying a memory location
- // to see if it's a continuation byte. Data that's already enregistered will go through the
- // normal "cmp reg, C0h" code paths, perhaps with some extra unnecessary "movzx" instructions.
- //
- // The below check takes advantage of the two's complement representation of negative numbers.
- // [ 0b1000_0000, 0b1011_1111 ] is [ -127 (sbyte.MinValue), -65 ]
-
- return (sbyte)value < -64;
- }
-
- /// <summary>
- /// Given a 32-bit integer that represents two packed UTF-16 characters, all in machine-endian order,
- /// returns true iff the two characters represent a well-formed UTF-16 surrogate pair.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsWellFormedUtf16SurrogatePair(uint value)
- {
- // Little-endian: Given [ LLLL HHHH ], validate that LLLL in [ DC00..DFFF ] and HHHH in [ D800..DBFF ].
- // Big-endian: Given [ HHHH LLLL ], validate that HHHH in [ D800..DBFF ] and LLLL in [ DC00..DFFF ].
- //
- // We're essentially performing a range check on each component of the input in parallel. The allowed range
- // ends up being "< 0x0400" after the beginning of the allowed range is subtracted from each element. We
- // can't perform the equivalent of two CMPs in parallel, but we can take advantage of the fact that 0x0400
- // is a whole power of 2, which means that a CMP is really just a glorified TEST operation. Two TESTs *can*
- // be performed in parallel. The logic below then becomes 3 operations: "add/lea; test; jcc".
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && ((value - 0xDC00_D800u) & 0xFC00_FC00u) == 0)
- || (!BitConverter.IsLittleEndian && ((value - 0xD800_DC00u) & 0xFC00_FC00u) == 0);
- }
-
- /// <summary>
- /// Converts a DWORD from machine-endian to little-endian.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint ToLittleEndian(uint value)
- {
- if (BitConverter.IsLittleEndian)
- {
- return value;
- }
- else
- {
- return BinaryPrimitives.ReverseEndianness(value);
- }
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD in machine endianness,
- /// returns <see langword="true"/> iff the first two bytes of the buffer are
- /// an overlong representation of a sequence that should be represented as one byte.
- /// This method *does not* validate that the sequence matches the appropriate
- /// 2-byte sequence mask (see <see cref="UInt32BeginsWithUtf8TwoByteMask"/>).
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32BeginsWithOverlongUtf8TwoByteSequence(uint value)
- {
- // ASSUMPTION: Caller has already checked the '110yyyyy 10xxxxxx' mask of the input.
- Debug.Assert(UInt32BeginsWithUtf8TwoByteMask(value));
-
- // Per Table 3-7, first byte of two-byte sequence must be within range C2 .. DF.
- // Since we already validated it's 80 <= ?? <= DF (per mask check earlier), now only need
- // to check that it's < C2.
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && ((byte)value < 0xC2u))
- || (!BitConverter.IsLittleEndian && (value < 0xC200_0000u));
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD in machine endianness,
- /// returns <see langword="true"/> iff the first four bytes of the buffer match
- /// the UTF-8 4-byte sequence mask [ 11110www 10zzzzzz 10yyyyyy 10xxxxxx ]. This
- /// method *does not* validate that the sequence is well-formed; the caller must
- /// still perform overlong form or out-of-range checking.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32BeginsWithUtf8FourByteMask(uint value)
- {
- // The code in this method is equivalent to the code
- // below but is slightly more optimized.
- //
- // if (BitConverter.IsLittleEndian)
- // {
- // const uint mask = 0xC0C0C0F8U;
- // const uint comparand = 0x808080F0U;
- // return ((value & mask) == comparand);
- // }
- // else
- // {
- // const uint mask = 0xF8C0C0C0U;
- // const uint comparand = 0xF0808000U;
- // return ((value & mask) == comparand);
- // }
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && (((value - 0x8080_80F0u) & 0xC0C0_C0F8u) == 0))
- || (!BitConverter.IsLittleEndian && (((value - 0xF080_8000u) & 0xF8C0_C0C0u) == 0));
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD in machine endianness,
- /// returns <see langword="true"/> iff the first three bytes of the buffer match
- /// the UTF-8 3-byte sequence mask [ 1110zzzz 10yyyyyy 10xxxxxx ]. This method *does not*
- /// validate that the sequence is well-formed; the caller must still perform
- /// overlong form or surrogate checking.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32BeginsWithUtf8ThreeByteMask(uint value)
- {
- // The code in this method is equivalent to the code
- // below but is slightly more optimized.
- //
- // if (BitConverter.IsLittleEndian)
- // {
- // const uint mask = 0x00C0C0F0U;
- // const uint comparand = 0x008080E0U;
- // return ((value & mask) == comparand);
- // }
- // else
- // {
- // const uint mask = 0xF0C0C000U;
- // const uint comparand = 0xE0808000U;
- // return ((value & mask) == comparand);
- // }
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && (((value - 0x0080_80E0u) & 0x00C0_C0F0u) == 0))
- || (!BitConverter.IsLittleEndian && (((value - 0xE080_8000u) & 0xF0C0_C000u) == 0));
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD in machine endianness,
- /// returns <see langword="true"/> iff the first two bytes of the buffer match
- /// the UTF-8 2-byte sequence mask [ 110yyyyy 10xxxxxx ]. This method *does not*
- /// validate that the sequence is well-formed; the caller must still perform
- /// overlong form checking.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32BeginsWithUtf8TwoByteMask(uint value)
- {
- // The code in this method is equivalent to the code
- // below but is slightly more optimized.
- //
- // if (BitConverter.IsLittleEndian)
- // {
- // const uint mask = 0x0000C0E0U;
- // const uint comparand = 0x000080C0U;
- // return ((value & mask) == comparand);
- // }
- // else
- // {
- // const uint mask = 0xE0C00000U;
- // const uint comparand = 0xC0800000U;
- // return ((value & mask) == comparand);
- // }
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && (((value - 0x0000_80C0u) & 0x0000_C0E0u) == 0))
- || (!BitConverter.IsLittleEndian && (((value - 0xC080_0000u) & 0xE0C0_0000u) == 0));
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD in machine endianness,
- /// returns <see langword="true"/> iff the first two bytes of the buffer are
- /// an overlong representation of a sequence that should be represented as one byte.
- /// This method *does not* validate that the sequence matches the appropriate
- /// 2-byte sequence mask (see <see cref="UInt32BeginsWithUtf8TwoByteMask"/>).
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32EndsWithOverlongUtf8TwoByteSequence(uint value)
- {
- // ASSUMPTION: Caller has already checked the '110yyyyy 10xxxxxx' mask of the input.
- Debug.Assert(UInt32EndsWithUtf8TwoByteMask(value));
-
- // Per Table 3-7, first byte of two-byte sequence must be within range C2 .. DF.
- // We already validated that it's 80 .. DF (per mask check earlier).
- // C2 = 1100 0010
- // DF = 1101 1111
- // This means that we can AND the leading byte with the mask 0001 1110 (1E),
- // and if the result is zero the sequence is overlong.
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && ((value & 0x001E_0000u) == 0))
- || (!BitConverter.IsLittleEndian && ((value & 0x1E00u) == 0));
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD in machine endianness,
- /// returns <see langword="true"/> iff the last two bytes of the buffer match
- /// the UTF-8 2-byte sequence mask [ 110yyyyy 10xxxxxx ]. This method *does not*
- /// validate that the sequence is well-formed; the caller must still perform
- /// overlong form checking.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32EndsWithUtf8TwoByteMask(uint value)
- {
- // The code in this method is equivalent to the code
- // below but is slightly more optimized.
- //
- // if (BitConverter.IsLittleEndian)
- // {
- // const uint mask = 0xC0E00000U;
- // const uint comparand = 0x80C00000U;
- // return ((value & mask) == comparand);
- // }
- // else
- // {
- // const uint mask = 0x0000E0C0U;
- // const uint comparand = 0x0000C080U;
- // return ((value & mask) == comparand);
- // }
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && (((value - 0x80C0_0000u) & 0xC0E0_0000u) == 0))
- || (!BitConverter.IsLittleEndian && (((value - 0x0000_C080u) & 0x0000_E0C0u) == 0));
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD on a little-endian machine,
- /// returns <see langword="true"/> iff the first two bytes of the buffer are a well-formed
- /// UTF-8 two-byte sequence. This wraps the mask check and the overlong check into a
- /// single operation. Returns <see langword="false"/> if running on a big-endian machine.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32BeginsWithValidUtf8TwoByteSequenceLittleEndian(uint value)
- {
- // Per Table 3-7, valid 2-byte sequences are [ C2..DF ] [ 80..BF ].
- // In little-endian, that would be represented as:
- // [ ######## ######## 10xxxxxx 110yyyyy ].
- // Due to the little-endian representation we can perform a trick by ANDing the low
- // WORD with the bitmask [ 11000000 11111111 ] and checking that the value is within
- // the range [ 10000000_11000010, 10000000_11011111 ]. This performs both the
- // 2-byte-sequence bitmask check and overlong form validation with one comparison.
-
- Debug.Assert(BitConverter.IsLittleEndian);
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && UnicodeUtility.IsInRangeInclusive(value & 0xC0FFu, 0x80C2u, 0x80DFu))
- || (!BitConverter.IsLittleEndian && false);
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD on a little-endian machine,
- /// returns <see langword="true"/> iff the last two bytes of the buffer are a well-formed
- /// UTF-8 two-byte sequence. This wraps the mask check and the overlong check into a
- /// single operation. Returns <see langword="false"/> if running on a big-endian machine.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32EndsWithValidUtf8TwoByteSequenceLittleEndian(uint value)
- {
- // See comments in UInt32BeginsWithValidUtf8TwoByteSequenceLittleEndian.
-
- Debug.Assert(BitConverter.IsLittleEndian);
-
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && UnicodeUtility.IsInRangeInclusive(value & 0xC0FF_0000u, 0x80C2_0000u, 0x80DF_0000u))
- || (!BitConverter.IsLittleEndian && false);
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD in machine endianness,
- /// returns <see langword="true"/> iff the first byte of the buffer is ASCII.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32FirstByteIsAscii(uint value)
- {
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && ((value & 0x80u) == 0))
- || (!BitConverter.IsLittleEndian && ((int)value >= 0));
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD in machine endianness,
- /// returns <see langword="true"/> iff the fourth byte of the buffer is ASCII.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32FourthByteIsAscii(uint value)
- {
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && ((int)value >= 0))
- || (!BitConverter.IsLittleEndian && ((value & 0x80u) == 0));
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD in machine endianness,
- /// returns <see langword="true"/> iff the second byte of the buffer is ASCII.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32SecondByteIsAscii(uint value)
- {
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && ((value & 0x8000u) == 0))
- || (!BitConverter.IsLittleEndian && ((value & 0x0080_0000u) == 0));
- }
-
- /// <summary>
- /// Given a UTF-8 buffer which has been read into a DWORD in machine endianness,
- /// returns <see langword="true"/> iff the third byte of the buffer is ASCII.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool UInt32ThirdByteIsAscii(uint value)
- {
- // Return statement is written this way to work around https://github.com/dotnet/coreclr/issues/914.
-
- return (BitConverter.IsLittleEndian && ((value & 0x0080_0000u) == 0))
- || (!BitConverter.IsLittleEndian && ((value & 0x8000u) == 0));
- }
-
- /// <summary>
- /// Given a DWORD which represents a buffer of 4 ASCII bytes, widen each byte to a 16-bit WORD
- /// and writes the resulting QWORD into the destination with machine endianness.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void Widen4AsciiBytesToCharsAndWrite(ref char outputBuffer, uint value)
- {
- if (Bmi2.X64.IsSupported)
- {
- // BMI2 will work regardless of the processor's endianness.
- Unsafe.WriteUnaligned(ref Unsafe.As<char, byte>(ref outputBuffer), Bmi2.X64.ParallelBitDeposit(value, 0x00FF00FF_00FF00FFul));
- }
- else
- {
- if (BitConverter.IsLittleEndian)
- {
- outputBuffer = (char)(byte)value;
- value >>= 8;
- Unsafe.Add(ref outputBuffer, 1) = (char)(byte)value;
- value >>= 8;
- Unsafe.Add(ref outputBuffer, 2) = (char)(byte)value;
- value >>= 8;
- Unsafe.Add(ref outputBuffer, 3) = (char)value;
- }
- else
- {
- Unsafe.Add(ref outputBuffer, 3) = (char)(byte)value;
- value >>= 8;
- Unsafe.Add(ref outputBuffer, 2) = (char)(byte)value;
- value >>= 8;
- Unsafe.Add(ref outputBuffer, 1) = (char)(byte)value;
- value >>= 8;
- outputBuffer = (char)value;
- }
- }
- }
-
- /// <summary>
- /// Given a DWORD which represents a buffer of 2 packed UTF-16 values in machine endianess,
- /// converts those scalar values to their 3-byte UTF-8 representation and writes the
- /// resulting 6 bytes to the destination buffer.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void WriteTwoUtf16CharsAsTwoUtf8ThreeByteSequences(ref byte outputBuffer, uint value)
- {
- Debug.Assert(IsFirstCharAtLeastThreeUtf8Bytes(value) && !IsFirstCharSurrogate(value), "First half of value should've been 0800..D7FF or E000..FFFF");
- Debug.Assert(IsSecondCharAtLeastThreeUtf8Bytes(value) && !IsSecondCharSurrogate(value), "Second half of value should've been 0800..D7FF or E000..FFFF");
-
- if (BitConverter.IsLittleEndian)
- {
- // value = [ ZZZZYYYY YYXXXXXX zzzzyyyy yyxxxxxx ]
- // want to write [ 1110ZZZZ 10xxxxxx 10yyyyyy 1110zzzz ] [ 10XXXXXX 10YYYYYY ]
-
- uint tempA = ((value << 2) & 0x3F00u) | ((value & 0x3Fu) << 16); // = [ 00000000 00xxxxxx 00yyyyyy 00000000 ]
- uint tempB = ((value >> 4) & 0x0F00_0000u) | ((value >> 12) & 0x0Fu); // = [ 0000ZZZZ 00000000 00000000 0000zzzz ]
- Unsafe.WriteUnaligned<uint>(ref outputBuffer, tempA + tempB + 0xE080_80E0u); // = [ 1110ZZZZ 10xxxxxx 10yyyyyy 1110zzzz ]
- Unsafe.WriteUnaligned<ushort>(ref Unsafe.Add(ref outputBuffer, 4), (ushort)(((value >> 22) & 0x3Fu) + ((value >> 8) & 0x3F00u) + 0x8080u)); // = [ 10XXXXXX 10YYYYYY ]
- }
- else
- {
- // value = [ zzzzyyyy yyxxxxxx ZZZZYYYY YYXXXXXX ]
- // want to write [ 1110zzzz ] [ 10yyyyyy ] [ 10xxxxxx ] [ 1110ZZZZ ] [ 10YYYYYY ] [ 10XXXXXX ]
-
- Unsafe.Add(ref outputBuffer, 5) = (byte)((value & 0x3Fu) | 0x80u);
- Unsafe.Add(ref outputBuffer, 4) = (byte)(((value >>= 6) & 0x3Fu) | 0x80u);
- Unsafe.Add(ref outputBuffer, 3) = (byte)(((value >>= 6) & 0x0Fu) | 0xE0u);
- Unsafe.Add(ref outputBuffer, 2) = (byte)(((value >>= 4) & 0x3Fu) | 0x80u);
- Unsafe.Add(ref outputBuffer, 1) = (byte)(((value >>= 6) & 0x3Fu) | 0x80u);
- outputBuffer = (byte)((value >>= 6) | 0xE0u);
- }
- }
-
- /// <summary>
- /// Given a DWORD which represents a buffer of 2 packed UTF-16 values in machine endianess,
- /// converts the first UTF-16 value to its 3-byte UTF-8 representation and writes the
- /// resulting 3 bytes to the destination buffer.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static void WriteFirstUtf16CharAsUtf8ThreeByteSequence(ref byte outputBuffer, uint value)
- {
- Debug.Assert(IsFirstCharAtLeastThreeUtf8Bytes(value) && !IsFirstCharSurrogate(value), "First half of value should've been 0800..D7FF or E000..FFFF");
-
- if (BitConverter.IsLittleEndian)
- {
- // value = [ ######## ######## zzzzyyyy yyxxxxxx ]
- // want to write [ 10yyyyyy 1110zzzz ] [ 10xxxxxx ]
-
- uint tempA = (value << 2) & 0x3F00u; // [ 00yyyyyy 00000000 ]
- uint tempB = ((uint)(ushort)value >> 12); // [ 00000000 0000zzzz ]
- Unsafe.WriteUnaligned<ushort>(ref outputBuffer, (ushort)(tempA + tempB + 0x80E0u)); // [ 10yyyyyy 1110zzzz ]
- Unsafe.Add(ref outputBuffer, 2) = (byte)((value & 0x3Fu) | ~0x7Fu); // [ 10xxxxxx ]
- }
- else
- {
- // value = [ zzzzyyyy yyxxxxxx ######## ######## ]
- // want to write [ 1110zzzz ] [ 10yyyyyy ] [ 10xxxxxx ]
-
- Unsafe.Add(ref outputBuffer, 2) = (byte)(((value >>= 16) & 0x3Fu) | 0x80u);
- Unsafe.Add(ref outputBuffer, 1) = (byte)(((value >>= 6) & 0x3Fu) | 0x80u);
- outputBuffer = (byte)((value >>= 6) | 0xE0u);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Transcoding.cs b/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Transcoding.cs
deleted file mode 100644
index 09a843c8123..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Transcoding.cs
+++ /dev/null
@@ -1,1479 +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 System.Buffers;
-using System.Buffers.Binary;
-using System.Diagnostics;
-using System.Numerics;
-using System.Runtime.Intrinsics.X86;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nint = System.Int64;
-using nuint = System.UInt64;
-#else // BIT64
-using nint = System.Int32;
-using nuint = System.UInt32;
-#endif // BIT64
-
-namespace System.Text.Unicode
-{
- internal static unsafe partial class Utf8Utility
- {
-#if DEBUG
- static Utf8Utility()
- {
- Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly.");
- Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly.");
-
- _ValidateAdditionalNIntDefinitions();
- }
-#endif // DEBUG
-
- // On method return, pInputBufferRemaining and pOutputBufferRemaining will both point to where
- // the next byte would have been consumed from / the next char would have been written to.
- // inputLength in bytes, outputCharsRemaining in chars.
- public static OperationStatus TranscodeToUtf16(byte* pInputBuffer, int inputLength, char* pOutputBuffer, int outputCharsRemaining, out byte* pInputBufferRemaining, out char* pOutputBufferRemaining)
- {
- Debug.Assert(inputLength >= 0, "Input length must not be negative.");
- Debug.Assert(pInputBuffer != null || inputLength == 0, "Input length must be zero if input buffer pointer is null.");
-
- Debug.Assert(outputCharsRemaining >= 0, "Destination length must not be negative.");
- Debug.Assert(pOutputBuffer != null || outputCharsRemaining == 0, "Destination length must be zero if destination buffer pointer is null.");
-
- // First, try vectorized conversion.
-
- {
- nuint numElementsConverted = ASCIIUtility.WidenAsciiToUtf16(pInputBuffer, pOutputBuffer, (uint)Math.Min(inputLength, outputCharsRemaining));
-
- pInputBuffer += numElementsConverted;
- pOutputBuffer += numElementsConverted;
-
- // Quick check - did we just end up consuming the entire input buffer?
- // If so, short-circuit the remainder of the method.
-
- if ((int)numElementsConverted == inputLength)
- {
- pInputBufferRemaining = pInputBuffer;
- pOutputBufferRemaining = pOutputBuffer;
- return OperationStatus.Done;
- }
-
- inputLength -= (int)numElementsConverted;
- outputCharsRemaining -= (int)numElementsConverted;
- }
-
- if (inputLength < sizeof(uint))
- {
- goto ProcessInputOfLessThanDWordSize;
- }
-
- byte* pFinalPosWhereCanReadDWordFromInputBuffer = pInputBuffer + (uint)inputLength - 4;
-
- // Begin the main loop.
-
-#if DEBUG
- byte* pLastBufferPosProcessed = null; // used for invariant checking in debug builds
-#endif
-
- while (pInputBuffer <= pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- // Read 32 bits at a time. This is enough to hold any possible UTF8-encoded scalar.
-
- uint thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
-
- AfterReadDWord:
-
-#if DEBUG
- Debug.Assert(pLastBufferPosProcessed < pInputBuffer, "Algorithm should've made forward progress since last read.");
- pLastBufferPosProcessed = pInputBuffer;
-#endif
- // First, check for the common case of all-ASCII bytes.
-
- if (ASCIIUtility.AllBytesInUInt32AreAscii(thisDWord))
- {
- // We read an all-ASCII sequence.
-
- if (outputCharsRemaining < sizeof(uint))
- {
- goto ProcessRemainingBytesSlow; // running out of space, but may be able to write some data
- }
-
- Widen4AsciiBytesToCharsAndWrite(ref *pOutputBuffer, thisDWord);
- pInputBuffer += 4;
- pOutputBuffer += 4;
- outputCharsRemaining -= 4;
-
- // If we saw a sequence of all ASCII, there's a good chance a significant amount of following data is also ASCII.
- // Below is basically unrolled loops with poor man's vectorization.
-
- uint remainingInputBytes = (uint)(void*)Unsafe.ByteOffset(ref *pInputBuffer, ref *pFinalPosWhereCanReadDWordFromInputBuffer) + 4;
- uint maxIters = Math.Min(remainingInputBytes, (uint)outputCharsRemaining) / (2 * sizeof(uint));
- uint secondDWord;
- int i;
- for (i = 0; (uint)i < maxIters; i++)
- {
- // Reading two DWORDs in parallel benchmarked faster than reading a single QWORD.
-
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- secondDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer + sizeof(uint));
-
- if (!ASCIIUtility.AllBytesInUInt32AreAscii(thisDWord | secondDWord))
- {
- goto LoopTerminatedEarlyDueToNonAsciiData;
- }
-
- pInputBuffer += 8;
-
- Widen4AsciiBytesToCharsAndWrite(ref pOutputBuffer[0], thisDWord);
- Widen4AsciiBytesToCharsAndWrite(ref pOutputBuffer[4], secondDWord);
-
- pOutputBuffer += 8;
- }
-
- outputCharsRemaining -= 8 * i;
-
- continue; // need to perform a bounds check because we might be running out of data
-
- LoopTerminatedEarlyDueToNonAsciiData:
-
- if (ASCIIUtility.AllBytesInUInt32AreAscii(thisDWord))
- {
- // The first DWORD contained all-ASCII bytes, so expand it.
-
- Widen4AsciiBytesToCharsAndWrite(ref *pOutputBuffer, thisDWord);
-
- // continue the outer loop from the second DWORD
-
- Debug.Assert(!ASCIIUtility.AllBytesInUInt32AreAscii(secondDWord));
- thisDWord = secondDWord;
-
- pInputBuffer += 4;
- pOutputBuffer += 4;
- outputCharsRemaining -= 4;
- }
-
- outputCharsRemaining -= 8 * i;
-
- // We know that there's *at least* one DWORD of data remaining in the buffer.
- // We also know that it's not all-ASCII. We can skip the logic at the beginning of the main loop.
-
- goto AfterReadDWordSkipAllBytesAsciiCheck;
- }
-
- AfterReadDWordSkipAllBytesAsciiCheck:
-
- Debug.Assert(!ASCIIUtility.AllBytesInUInt32AreAscii(thisDWord)); // this should have been handled earlier
-
- // Next, try stripping off ASCII bytes one at a time.
- // We only handle up to three ASCII bytes here since we handled the four ASCII byte case above.
-
- if (UInt32FirstByteIsAscii(thisDWord))
- {
- if (outputCharsRemaining >= 3)
- {
- // Fast-track: we don't need to check the destination length for subsequent
- // ASCII bytes since we know we can write them all now.
-
- uint thisDWordLittleEndian = ToLittleEndian(thisDWord);
-
- nuint adjustment = 1;
- pOutputBuffer[0] = (char)(byte)thisDWordLittleEndian;
-
- if (UInt32SecondByteIsAscii(thisDWord))
- {
- adjustment++;
- thisDWordLittleEndian >>= 8;
- pOutputBuffer[1] = (char)(byte)thisDWordLittleEndian;
-
- if (UInt32ThirdByteIsAscii(thisDWord))
- {
- adjustment++;
- thisDWordLittleEndian >>= 8;
- pOutputBuffer[2] = (char)(byte)thisDWordLittleEndian;
- }
- }
-
- pInputBuffer += adjustment;
- pOutputBuffer += adjustment;
- outputCharsRemaining -= (int)adjustment;
- }
- else
- {
- // Slow-track: we need to make sure each individual write has enough
- // of a buffer so that we don't overrun the destination.
-
- if (outputCharsRemaining == 0)
- {
- goto OutputBufferTooSmall;
- }
-
- uint thisDWordLittleEndian = ToLittleEndian(thisDWord);
-
- pInputBuffer++;
- *pOutputBuffer++ = (char)(byte)thisDWordLittleEndian;
- outputCharsRemaining--;
-
- if (UInt32SecondByteIsAscii(thisDWord))
- {
- if (outputCharsRemaining == 0)
- {
- goto OutputBufferTooSmall;
- }
-
- pInputBuffer++;
- thisDWordLittleEndian >>= 8;
- *pOutputBuffer++ = (char)(byte)thisDWordLittleEndian;
-
- // We can perform a small optimization here. We know at this point that
- // the output buffer is fully consumed (we read two ASCII bytes and wrote
- // two ASCII chars, and we checked earlier that the destination buffer
- // can't store a third byte). If the next byte is ASCII, we can jump straight
- // to the return statement since the end-of-method logic only relies on the
- // destination buffer pointer -- NOT the output chars remaining count -- being
- // correct. If the next byte is not ASCII, we'll need to continue with the
- // rest of the main loop, but we can set the buffer length directly to zero
- // rather than decrementing it from 1 to 0.
-
- Debug.Assert(outputCharsRemaining == 1);
-
- if (UInt32ThirdByteIsAscii(thisDWord))
- {
- goto OutputBufferTooSmall;
- }
- else
- {
- outputCharsRemaining = 0;
- }
- }
- }
-
- if (pInputBuffer > pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- goto ProcessRemainingBytesSlow; // input buffer doesn't contain enough data to read a DWORD
- }
- else
- {
- // The input buffer at the current offset contains a non-ASCII byte.
- // Read an entire DWORD and fall through to multi-byte consumption logic.
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- }
- }
-
- BeforeProcessTwoByteSequence:
-
- // At this point, we know we're working with a multi-byte code unit,
- // but we haven't yet validated it.
-
- // The masks and comparands are derived from the Unicode Standard, Table 3-6.
- // Additionally, we need to check for valid byte sequences per Table 3-7.
-
- // Check the 2-byte case.
-
- if (UInt32BeginsWithUtf8TwoByteMask(thisDWord))
- {
- // Per Table 3-7, valid sequences are:
- // [ C2..DF ] [ 80..BF ]
-
- if (UInt32BeginsWithOverlongUtf8TwoByteSequence(thisDWord))
- {
- goto Error;
- }
-
- ProcessTwoByteSequenceSkipOverlongFormCheck:
-
- // Optimization: If this is a two-byte-per-character language like Cyrillic or Hebrew,
- // there's a good chance that if we see one two-byte run then there's another two-byte
- // run immediately after. Let's check that now.
-
- // On little-endian platforms, we can check for the two-byte UTF8 mask *and* validate that
- // the value isn't overlong using a single comparison. On big-endian platforms, we'll need
- // to validate the mask and validate that the sequence isn't overlong as two separate comparisons.
-
- if ((BitConverter.IsLittleEndian && UInt32EndsWithValidUtf8TwoByteSequenceLittleEndian(thisDWord))
- || (!BitConverter.IsLittleEndian && (UInt32EndsWithUtf8TwoByteMask(thisDWord) && !UInt32EndsWithOverlongUtf8TwoByteSequence(thisDWord))))
- {
- // We have two runs of two bytes each.
-
- if (outputCharsRemaining < 2)
- {
- goto ProcessRemainingBytesSlow; // running out of output buffer
- }
-
- Unsafe.WriteUnaligned<uint>(pOutputBuffer, ExtractTwoCharsPackedFromTwoAdjacentTwoByteSequences(thisDWord));
-
- pInputBuffer += 4;
- pOutputBuffer += 2;
- outputCharsRemaining -= 2;
-
- if (pInputBuffer <= pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- // Optimization: If we read a long run of two-byte sequences, the next sequence is probably
- // also two bytes. Check for that first before going back to the beginning of the loop.
-
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
-
- if (BitConverter.IsLittleEndian)
- {
- if (UInt32BeginsWithValidUtf8TwoByteSequenceLittleEndian(thisDWord))
- {
- // The next sequence is a valid two-byte sequence.
- goto ProcessTwoByteSequenceSkipOverlongFormCheck;
- }
- }
- else
- {
- if (UInt32BeginsWithUtf8TwoByteMask(thisDWord))
- {
- if (UInt32BeginsWithOverlongUtf8TwoByteSequence(thisDWord))
- {
- goto Error; // The next sequence purports to be a 2-byte sequence but is overlong.
- }
-
- goto ProcessTwoByteSequenceSkipOverlongFormCheck;
- }
- }
-
- // If we reached this point, the next sequence is something other than a valid
- // two-byte sequence, so go back to the beginning of the loop.
- goto AfterReadDWord;
- }
- else
- {
- goto ProcessRemainingBytesSlow; // Running out of data - go down slow path
- }
- }
-
- // The buffer contains a 2-byte sequence followed by 2 bytes that aren't a 2-byte sequence.
- // Unlikely that a 3-byte sequence would follow a 2-byte sequence, so perhaps remaining
- // bytes are ASCII?
-
- uint charToWrite = ExtractCharFromFirstTwoByteSequence(thisDWord); // optimistically compute this now, but don't store until we know dest is large enough
-
- if (UInt32ThirdByteIsAscii(thisDWord))
- {
- if (UInt32FourthByteIsAscii(thisDWord))
- {
- if (outputCharsRemaining < 3)
- {
- goto ProcessRemainingBytesSlow; // running out of output buffer
- }
-
- pOutputBuffer[0] = (char)charToWrite;
- if (BitConverter.IsLittleEndian)
- {
- thisDWord >>= 16;
- pOutputBuffer[1] = (char)(byte)thisDWord;
- thisDWord >>= 8;
- pOutputBuffer[2] = (char)thisDWord;
- }
- else
- {
- pOutputBuffer[2] = (char)(byte)thisDWord;
- pOutputBuffer[1] = (char)(byte)(thisDWord >> 8);
- }
- pInputBuffer += 4;
- pOutputBuffer += 3;
- outputCharsRemaining -= 3;
-
- continue; // go back to original bounds check and check for ASCII
- }
- else
- {
- if (outputCharsRemaining < 2)
- {
- goto ProcessRemainingBytesSlow; // running out of output buffer
- }
-
- pOutputBuffer[0] = (char)charToWrite;
- pOutputBuffer[1] = (char)(byte)(thisDWord >> (BitConverter.IsLittleEndian ? 16 : 8));
- pInputBuffer += 3;
- pOutputBuffer += 2;
- outputCharsRemaining -= 2;
-
- // A two-byte sequence followed by an ASCII byte followed by a non-ASCII byte.
- // Read in the next DWORD and jump directly to the start of the multi-byte processing block.
-
- if (pFinalPosWhereCanReadDWordFromInputBuffer < pInputBuffer)
- {
- goto ProcessRemainingBytesSlow; // Running out of data - go down slow path
- }
- else
- {
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- goto BeforeProcessTwoByteSequence;
- }
- }
- }
- else
- {
- if (outputCharsRemaining == 0)
- {
- goto ProcessRemainingBytesSlow; // running out of output buffer
- }
-
- pOutputBuffer[0] = (char)charToWrite;
- pInputBuffer += 2;
- pOutputBuffer++;
- outputCharsRemaining--;
-
- if (pFinalPosWhereCanReadDWordFromInputBuffer < pInputBuffer)
- {
- goto ProcessRemainingBytesSlow; // Running out of data - go down slow path
- }
- else
- {
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- goto BeforeProcessThreeByteSequence; // we know the next byte isn't ASCII, and it's not the start of a 2-byte sequence (this was checked above)
- }
- }
- }
-
- // Check the 3-byte case.
-
- BeforeProcessThreeByteSequence:
-
- if (UInt32BeginsWithUtf8ThreeByteMask(thisDWord))
- {
- ProcessThreeByteSequenceWithCheck:
-
- // We need to check for overlong or surrogate three-byte sequences.
- //
- // Per Table 3-7, valid sequences are:
- // [ E0 ] [ A0..BF ] [ 80..BF ]
- // [ E1..EC ] [ 80..BF ] [ 80..BF ]
- // [ ED ] [ 80..9F ] [ 80..BF ]
- // [ EE..EF ] [ 80..BF ] [ 80..BF ]
- //
- // Big-endian examples of using the above validation table:
- // E0A0 = 1110 0000 1010 0000 => invalid (overlong ) patterns are 1110 0000 100# ####
- // ED9F = 1110 1101 1001 1111 => invalid (surrogate) patterns are 1110 1101 101# ####
- // If using the bitmask ......................................... 0000 1111 0010 0000 (=0F20),
- // Then invalid (overlong) patterns match the comparand ......... 0000 0000 0000 0000 (=0000),
- // And invalid (surrogate) patterns match the comparand ......... 0000 1101 0010 0000 (=0D20).
-
- if (BitConverter.IsLittleEndian)
- {
- // The "overlong or surrogate" check can be implemented using a single jump, but there's
- // some overhead to moving the bits into the correct locations in order to perform the
- // correct comparison, and in practice the processor's branch prediction capability is
- // good enough that we shouldn't bother. So we'll use two jumps instead.
-
- // Can't extract this check into its own helper method because JITter produces suboptimal
- // assembly, even with aggressive inlining.
-
- // Code below becomes 5 instructions: test, jz, lea, test, jz
-
- if (((thisDWord & 0x0000_200Fu) == 0) || (((thisDWord - 0x0000_200Du) & 0x0000_200Fu) == 0))
- {
- goto Error; // overlong or surrogate
- }
- }
- else
- {
- if (((thisDWord & 0x0F20_0000u) == 0) || (((thisDWord - 0x0D20_0000u) & 0x0F20_0000u) == 0))
- {
- goto Error; // overlong or surrogate
- }
- }
-
- // At this point, we know the incoming scalar is well-formed.
-
- if (outputCharsRemaining == 0)
- {
- goto OutputBufferTooSmall; // not enough space in the destination buffer to write
- }
-
- // As an optimization, on compatible platforms check if a second three-byte sequence immediately
- // follows the one we just read, and if so use BSWAP and BMI2 to extract them together.
-
- if (Bmi2.X64.IsSupported)
- {
- Debug.Assert(BitConverter.IsLittleEndian, "BMI2 requires little-endian.");
-
- // First, check that the leftover byte from the original DWORD is in the range [ E0..EF ], which
- // would indicate the potential start of a second three-byte sequence.
-
- if (((thisDWord - 0xE000_0000u) & 0xF000_0000u) == 0)
- {
- // The const '3' below is correct because pFinalPosWhereCanReadDWordFromInputBuffer represents
- // the final place where we can safely perform a DWORD read, and we want to probe whether it's
- // safe to read a DWORD beginning at address &pInputBuffer[3].
-
- if (outputCharsRemaining > 1 && (nint)(void*)Unsafe.ByteOffset(ref *pInputBuffer, ref *pFinalPosWhereCanReadDWordFromInputBuffer) >= 3)
- {
- // We're going to attempt to read a second 3-byte sequence and write them both out simultaneously using PEXT.
- // We need to check the continuation bit mask on the remaining two bytes (and we may as well check the leading
- // byte mask again since it's free), then perform overlong + surrogate checks. If the overlong or surrogate
- // checks fail, we'll fall through to the remainder of the logic which will transcode the original valid
- // 3-byte UTF-8 sequence we read; and on the next iteration of the loop the validation routine will run again,
- // fail, and redirect control flow to the error handling logic at the very end of this method.
-
- uint secondDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer + 3);
-
- if (UInt32BeginsWithUtf8ThreeByteMask(secondDWord)
- && ((secondDWord & 0x0000_200Fu) != 0)
- && (((secondDWord - 0x0000_200Du) & 0x0000_200Fu) != 0))
- {
- // combinedQWord = [ 1110ZZZZ 10YYYYYY 10XXXXXX ######## | 1110zzzz 10yyyyyy 10xxxxxx ######## ], where xyz are from first DWORD, XYZ are from second DWORD
- ulong combinedQWord = ((ulong)BinaryPrimitives.ReverseEndianness(secondDWord) << 32) | BinaryPrimitives.ReverseEndianness(thisDWord);
- thisDWord = secondDWord; // store this value in the correct local for the ASCII drain logic
-
- // extractedQWord = [ 00000000 00000000 00000000 00000000 | ZZZZYYYYYYXXXXXX zzzzyyyyyyxxxxxx ]
- ulong extractedQWord = Bmi2.X64.ParallelBitExtract(combinedQWord, 0x0F3F3F00_0F3F3F00ul);
-
- Unsafe.WriteUnaligned<uint>(pOutputBuffer, (uint)extractedQWord);
- pInputBuffer += 6;
- pOutputBuffer += 2;
- outputCharsRemaining -= 2;
-
- // Drain any ASCII data following the second three-byte sequence.
-
- goto CheckForAsciiByteAfterThreeByteSequence;
- }
- }
- }
- }
-
- // Couldn't extract 2x three-byte sequences together, just do this one by itself.
-
- *pOutputBuffer = (char)ExtractCharFromFirstThreeByteSequence(thisDWord);
- pInputBuffer += 3;
- pOutputBuffer++;
- outputCharsRemaining--;
-
- CheckForAsciiByteAfterThreeByteSequence:
-
- // Occasionally one-off ASCII characters like spaces, periods, or newlines will make their way
- // in to the text. If this happens strip it off now before seeing if the next character
- // consists of three code units.
-
- if (UInt32FourthByteIsAscii(thisDWord))
- {
- if (outputCharsRemaining == 0)
- {
- goto OutputBufferTooSmall;
- }
-
- if (BitConverter.IsLittleEndian)
- {
- *pOutputBuffer = (char)(thisDWord >> 24);
- }
- else
- {
- *pOutputBuffer = (char)(byte)thisDWord;
- }
-
- pInputBuffer++;
- pOutputBuffer++;
- outputCharsRemaining--;
- }
-
- if (pInputBuffer <= pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
-
- // Optimization: A three-byte character could indicate CJK text, which makes it likely
- // that the character following this one is also CJK. We'll check for a three-byte sequence
- // marker now and jump directly to three-byte sequence processing if we see one, skipping
- // all of the logic at the beginning of the loop.
-
- if (UInt32BeginsWithUtf8ThreeByteMask(thisDWord))
- {
- goto ProcessThreeByteSequenceWithCheck; // found a three-byte sequence marker; validate and consume
- }
- else
- {
- goto AfterReadDWord; // probably ASCII punctuation or whitespace
- }
- }
- else
- {
- goto ProcessRemainingBytesSlow; // Running out of data - go down slow path
- }
- }
-
- // Assume the 4-byte case, but we need to validate.
-
- {
- // We need to check for overlong or invalid (over U+10FFFF) four-byte sequences.
- //
- // Per Table 3-7, valid sequences are:
- // [ F0 ] [ 90..BF ] [ 80..BF ] [ 80..BF ]
- // [ F1..F3 ] [ 80..BF ] [ 80..BF ] [ 80..BF ]
- // [ F4 ] [ 80..8F ] [ 80..BF ] [ 80..BF ]
-
- if (!UInt32BeginsWithUtf8FourByteMask(thisDWord))
- {
- goto Error;
- }
-
- // Now check for overlong / out-of-range sequences.
-
- if (BitConverter.IsLittleEndian)
- {
- // The DWORD we read is [ 10xxxxxx 10yyyyyy 10zzzzzz 11110www ].
- // We want to get the 'w' byte in front of the 'z' byte so that we can perform
- // a single range comparison. We'll take advantage of the fact that the JITter
- // can detect a ROR / ROL operation, then we'll just zero out the bytes that
- // aren't involved in the range check.
-
- uint toCheck = thisDWord & 0x0000_FFFFu;
-
- // At this point, toCheck = [ 00000000 00000000 10zzzzzz 11110www ].
-
- toCheck = BitOperations.RotateRight(toCheck, 8);
-
- // At this point, toCheck = [ 11110www 00000000 00000000 10zzzzzz ].
-
- if (!UnicodeUtility.IsInRangeInclusive(toCheck, 0xF000_0090u, 0xF400_008Fu))
- {
- goto Error;
- }
- }
- else
- {
- if (!UnicodeUtility.IsInRangeInclusive(thisDWord, 0xF090_0000u, 0xF48F_FFFFu))
- {
- goto Error;
- }
- }
-
- // Validation complete.
-
- if (outputCharsRemaining < 2)
- {
- // There's no point to falling back to the "drain the input buffer" logic, since we know
- // we can't write anything to the destination. So we'll just exit immediately.
- goto OutputBufferTooSmall;
- }
-
- Unsafe.WriteUnaligned<uint>(pOutputBuffer, ExtractCharsFromFourByteSequence(thisDWord));
-
- pInputBuffer += 4;
- pOutputBuffer += 2;
- outputCharsRemaining -= 2;
-
- continue; // go back to beginning of loop for processing
- }
- }
-
- ProcessRemainingBytesSlow:
- inputLength = (int)(void*)Unsafe.ByteOffset(ref *pInputBuffer, ref *pFinalPosWhereCanReadDWordFromInputBuffer) + 4;
-
- ProcessInputOfLessThanDWordSize:
- while (inputLength > 0)
- {
- uint firstByte = pInputBuffer[0];
- if (firstByte <= 0x7Fu)
- {
- if (outputCharsRemaining == 0)
- {
- goto OutputBufferTooSmall; // we have no hope of writing anything to the output
- }
-
- // 1-byte (ASCII) case
- *pOutputBuffer = (char)firstByte;
-
- pInputBuffer++;
- pOutputBuffer++;
- inputLength--;
- outputCharsRemaining--;
- continue;
- }
-
- // Potentially the start of a multi-byte sequence?
-
- firstByte -= 0xC2u;
- if ((byte)firstByte <= (0xDFu - 0xC2u))
- {
- // Potentially a 2-byte sequence?
- if (inputLength < 2)
- {
- goto InputBufferTooSmall; // out of data
- }
-
- uint secondByte = pInputBuffer[1];
- if (!IsLowByteUtf8ContinuationByte(secondByte))
- {
- goto Error; // 2-byte marker not followed by continuation byte
- }
-
- if (outputCharsRemaining == 0)
- {
- goto OutputBufferTooSmall; // we have no hope of writing anything to the output
- }
-
- uint asChar = (firstByte << 6) + secondByte + ((0xC2u - 0xC0u) << 6) - 0x80u; // remove UTF-8 markers from scalar
- *pOutputBuffer = (char)asChar;
-
- pInputBuffer += 2;
- pOutputBuffer++;
- inputLength -= 2;
- outputCharsRemaining--;
- continue;
- }
- else if ((byte)firstByte <= (0xEFu - 0xC2u))
- {
- // Potentially a 3-byte sequence?
- if (inputLength >= 3)
- {
- uint secondByte = pInputBuffer[1];
- uint thirdByte = pInputBuffer[2];
- if (!IsLowByteUtf8ContinuationByte(secondByte) || !IsLowByteUtf8ContinuationByte(thirdByte))
- {
- goto Error; // 3-byte marker not followed by 2 continuation bytes
- }
-
- // To speed up the validation logic below, we're not going to remove the UTF-8 markers from the partial char just yet.
- // We account for this in the comparisons below.
-
- uint partialChar = (firstByte << 12) + (secondByte << 6);
- if (partialChar < ((0xE0u - 0xC2u) << 12) + (0xA0u << 6))
- {
- goto Error; // this is an overlong encoding; fail
- }
-
- partialChar -= ((0xEDu - 0xC2u) << 12) + (0xA0u << 6); // if partialChar = 0, we're at beginning of UTF-16 surrogate code point range
- if (partialChar < 0x0800u /* number of code points in UTF-16 surrogate code point range */)
- {
- goto Error; // attempted to encode a UTF-16 surrogate code point; fail
- }
-
- if (outputCharsRemaining == 0)
- {
- goto OutputBufferTooSmall; // we have no hope of writing anything to the output
- }
-
- // Now restore the full scalar value.
-
- partialChar += thirdByte;
- partialChar += 0xD800; // undo "move to beginning of UTF-16 surrogate code point range" from earlier, fold it with later adds
- partialChar -= 0x80u; // remove third byte continuation marker
-
- *pOutputBuffer = (char)partialChar;
-
- pInputBuffer += 3;
- pOutputBuffer++;
- inputLength -= 3;
- outputCharsRemaining--;
- continue;
- }
- else if (inputLength >= 2)
- {
- uint secondByte = pInputBuffer[1];
- if (!IsLowByteUtf8ContinuationByte(secondByte))
- {
- goto Error; // 3-byte marker not followed by continuation byte
- }
-
- // We can't build up the entire scalar value now, but we can check for overlong / surrogate representations
- // from just the first two bytes.
-
- uint partialChar = (firstByte << 6) + secondByte; // don't worry about fixing up the UTF-8 markers; we'll account for it in the below comparison
- if (partialChar < ((0xE0u - 0xC2u) << 6) + 0xA0u)
- {
- goto Error; // failed overlong check
- }
- if (UnicodeUtility.IsInRangeInclusive(partialChar, ((0xEDu - 0xC2u) << 6) + 0xA0u, ((0xEEu - 0xC2u) << 6) + 0x7Fu))
- {
- goto Error; // failed surrogate check
- }
- }
-
- goto InputBufferTooSmall; // out of data
- }
- else if ((byte)firstByte <= (0xF4u - 0xC2u))
- {
- // Potentially a 4-byte sequence?
-
- if (inputLength < 2)
- {
- goto InputBufferTooSmall; // ran out of data
- }
-
- uint nextByte = pInputBuffer[1];
- if (!IsLowByteUtf8ContinuationByte(nextByte))
- {
- goto Error; // 4-byte marker not followed by a continuation byte
- }
-
- uint asPartialChar = (firstByte << 6) + nextByte; // don't worry about fixing up the UTF-8 markers; we'll account for it in the below comparison
- if (!UnicodeUtility.IsInRangeInclusive(asPartialChar, ((0xF0u - 0xC2u) << 6) + 0x90u, ((0xF4u - 0xC2u) << 6) + 0x8Fu))
- {
- goto Error; // failed overlong / out-of-range check
- }
-
- if (inputLength < 3)
- {
- goto InputBufferTooSmall; // ran out of data
- }
-
- if (!IsLowByteUtf8ContinuationByte(pInputBuffer[2]))
- {
- goto Error; // third byte in 4-byte sequence not a continuation byte
- }
-
- if (inputLength < 4)
- {
- goto InputBufferTooSmall; // ran out of data
- }
-
- if (!IsLowByteUtf8ContinuationByte(pInputBuffer[3]))
- {
- goto Error; // fourth byte in 4-byte sequence not a continuation byte
- }
-
- // If we read a valid astral scalar value, the only way we could've fallen down this code path
- // is that we didn't have enough output buffer to write the result.
-
- goto OutputBufferTooSmall;
- }
- else
- {
- goto Error; // didn't begin with [ C2 .. F4 ], so invalid multi-byte sequence header byte
- }
- }
-
- OperationStatus retVal = OperationStatus.Done;
- goto ReturnCommon;
-
- InputBufferTooSmall:
- retVal = OperationStatus.NeedMoreData;
- goto ReturnCommon;
-
- OutputBufferTooSmall:
- retVal = OperationStatus.DestinationTooSmall;
- goto ReturnCommon;
-
- Error:
- retVal = OperationStatus.InvalidData;
- goto ReturnCommon;
-
- ReturnCommon:
- pInputBufferRemaining = pInputBuffer;
- pOutputBufferRemaining = pOutputBuffer;
- return retVal;
- }
-
- // On method return, pInputBufferRemaining and pOutputBufferRemaining will both point to where
- // the next char would have been consumed from / the next byte would have been written to.
- // inputLength in chars, outputBytesRemaining in bytes.
- public static OperationStatus TranscodeToUtf8(char* pInputBuffer, int inputLength, byte* pOutputBuffer, int outputBytesRemaining, out char* pInputBufferRemaining, out byte* pOutputBufferRemaining)
- {
- const int CharsPerDWord = sizeof(uint) / sizeof(char);
-
- Debug.Assert(inputLength >= 0, "Input length must not be negative.");
- Debug.Assert(pInputBuffer != null || inputLength == 0, "Input length must be zero if input buffer pointer is null.");
-
- Debug.Assert(outputBytesRemaining >= 0, "Destination length must not be negative.");
- Debug.Assert(pOutputBuffer != null || outputBytesRemaining == 0, "Destination length must be zero if destination buffer pointer is null.");
-
- // First, try vectorized conversion.
-
- {
- nuint numElementsConverted = ASCIIUtility.NarrowUtf16ToAscii(pInputBuffer, pOutputBuffer, (uint)Math.Min(inputLength, outputBytesRemaining));
-
- pInputBuffer += numElementsConverted;
- pOutputBuffer += numElementsConverted;
-
- // Quick check - did we just end up consuming the entire input buffer?
- // If so, short-circuit the remainder of the method.
-
- if ((int)numElementsConverted == inputLength)
- {
- pInputBufferRemaining = pInputBuffer;
- pOutputBufferRemaining = pOutputBuffer;
- return OperationStatus.Done;
- }
-
- inputLength -= (int)numElementsConverted;
- outputBytesRemaining -= (int)numElementsConverted;
- }
-
- if (inputLength < CharsPerDWord)
- {
- goto ProcessInputOfLessThanDWordSize;
- }
-
- char* pFinalPosWhereCanReadDWordFromInputBuffer = pInputBuffer + (uint)inputLength - CharsPerDWord;
-
- // Begin the main loop.
-
-#if DEBUG
- char* pLastBufferPosProcessed = null; // used for invariant checking in debug builds
-#endif
-
- uint thisDWord;
-
- while (pInputBuffer <= pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- // Read 32 bits at a time. This is enough to hold any possible UTF16-encoded scalar.
-
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
-
- AfterReadDWord:
-
-#if DEBUG
- Debug.Assert(pLastBufferPosProcessed < pInputBuffer, "Algorithm should've made forward progress since last read.");
- pLastBufferPosProcessed = pInputBuffer;
-#endif
-
- // First, check for the common case of all-ASCII chars.
-
- if (Utf16Utility.AllCharsInUInt32AreAscii(thisDWord))
- {
- // We read an all-ASCII sequence (2 chars).
-
- if (outputBytesRemaining < 2)
- {
- goto ProcessOneCharFromCurrentDWordAndFinish; // running out of space, but may be able to write some data
- }
-
- // The high WORD of the local declared below might be populated with garbage
- // as a result of our shifts below, but that's ok since we're only going to
- // write the low WORD.
- //
- // [ 00000000 0bbbbbbb | 00000000 0aaaaaaa ] -> [ 00000000 0bbbbbbb | 0bbbbbbb 0aaaaaaa ]
- // (Same logic works regardless of endianness.)
- uint valueToWrite = thisDWord | (thisDWord >> 8);
-
- Unsafe.WriteUnaligned<ushort>(pOutputBuffer, (ushort)valueToWrite);
-
- pInputBuffer += 2;
- pOutputBuffer += 2;
- outputBytesRemaining -= 2;
-
- // If we saw a sequence of all ASCII, there's a good chance a significant amount of following data is also ASCII.
- // Below is basically unrolled loops with poor man's vectorization.
-
- uint inputCharsRemaining = (uint)(pFinalPosWhereCanReadDWordFromInputBuffer - pInputBuffer) + 2;
- uint minElementsRemaining = (uint)Math.Min(inputCharsRemaining, outputBytesRemaining);
-
- if (Bmi2.X64.IsSupported)
- {
- Debug.Assert(BitConverter.IsLittleEndian, "BMI2 requires little-endian.");
- const ulong PEXT_MASK = 0x00FF00FF_00FF00FFul;
-
- // Try reading and writing 8 elements per iteration.
- uint maxIters = minElementsRemaining / 8;
- ulong firstQWord, secondQWord;
- int i;
- for (i = 0; (uint)i < maxIters; i++)
- {
- firstQWord = Unsafe.ReadUnaligned<ulong>(pInputBuffer);
- secondQWord = Unsafe.ReadUnaligned<ulong>(pInputBuffer + 4);
-
- if (!Utf16Utility.AllCharsInUInt64AreAscii(firstQWord | secondQWord))
- {
- goto LoopTerminatedDueToNonAsciiData;
- }
-
- Unsafe.WriteUnaligned<uint>(pOutputBuffer, (uint)Bmi2.X64.ParallelBitExtract(firstQWord, PEXT_MASK));
- Unsafe.WriteUnaligned<uint>(pOutputBuffer + 4, (uint)Bmi2.X64.ParallelBitExtract(secondQWord, PEXT_MASK));
-
- pInputBuffer += 8;
- pOutputBuffer += 8;
- }
-
- outputBytesRemaining -= 8 * i;
-
- // Can we perform one more iteration, but reading & writing 4 elements instead of 8?
-
- if ((minElementsRemaining & 4) != 0)
- {
- secondQWord = Unsafe.ReadUnaligned<ulong>(pInputBuffer);
-
- if (!Utf16Utility.AllCharsInUInt64AreAscii(secondQWord))
- {
- goto LoopTerminatedDueToNonAsciiDataInSecondQWord;
- }
-
- Unsafe.WriteUnaligned<uint>(pOutputBuffer, (uint)Bmi2.X64.ParallelBitExtract(secondQWord, PEXT_MASK));
-
- pInputBuffer += 4;
- pOutputBuffer += 4;
- outputBytesRemaining -= 4;
- }
-
- continue; // Go back to beginning of main loop, read data, check for ASCII
-
- LoopTerminatedDueToNonAsciiData:
-
- outputBytesRemaining -= 8 * i;
-
- // First, see if we can drain any ASCII data from the first QWORD.
-
- if (Utf16Utility.AllCharsInUInt64AreAscii(firstQWord))
- {
- Unsafe.WriteUnaligned<uint>(pOutputBuffer, (uint)Bmi2.X64.ParallelBitExtract(firstQWord, PEXT_MASK));
- pInputBuffer += 4;
- pOutputBuffer += 4;
- outputBytesRemaining -= 4;
- }
- else
- {
- secondQWord = firstQWord;
- }
-
- LoopTerminatedDueToNonAsciiDataInSecondQWord:
-
- Debug.Assert(!Utf16Utility.AllCharsInUInt64AreAscii(secondQWord)); // this condition should've been checked earlier
-
- thisDWord = (uint)secondQWord;
- if (Utf16Utility.AllCharsInUInt32AreAscii(thisDWord))
- {
- // [ 00000000 0bbbbbbb | 00000000 0aaaaaaa ] -> [ 00000000 0bbbbbbb | 0bbbbbbb 0aaaaaaa ]
- Unsafe.WriteUnaligned<ushort>(pOutputBuffer, (ushort)(thisDWord | (thisDWord >> 8)));
- pInputBuffer += 2;
- pOutputBuffer += 2;
- outputBytesRemaining -= 2;
- thisDWord = (uint)(secondQWord >> 32);
- }
-
- goto AfterReadDWordSkipAllCharsAsciiCheck;
- }
- else
- {
- // Can't use BMI2 x64, so we'll only read and write 4 elements per iteration.
- uint maxIters = minElementsRemaining / 4;
- uint secondDWord;
- int i;
- for (i = 0; (uint)i < maxIters; i++)
- {
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- secondDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer + 2);
-
- if (!Utf16Utility.AllCharsInUInt32AreAscii(thisDWord | secondDWord))
- {
- goto LoopTerminatedDueToNonAsciiData;
- }
-
- // [ 00000000 0bbbbbbb | 00000000 0aaaaaaa ] -> [ 00000000 0bbbbbbb | 0bbbbbbb 0aaaaaaa ]
- // (Same logic works regardless of endianness.)
- Unsafe.WriteUnaligned<ushort>(pOutputBuffer, (ushort)(thisDWord | (thisDWord >> 8)));
- Unsafe.WriteUnaligned<ushort>(pOutputBuffer + 2, (ushort)(secondDWord | (secondDWord >> 8)));
-
- pInputBuffer += 4;
- pOutputBuffer += 4;
- }
-
- outputBytesRemaining -= 4 * i;
-
- continue; // Go back to beginning of main loop, read data, check for ASCII
-
- LoopTerminatedDueToNonAsciiData:
-
- outputBytesRemaining -= 4 * i;
-
- // First, see if we can drain any ASCII data from the first DWORD.
-
- if (Utf16Utility.AllCharsInUInt32AreAscii(thisDWord))
- {
- // [ 00000000 0bbbbbbb | 00000000 0aaaaaaa ] -> [ 00000000 0bbbbbbb | 0bbbbbbb 0aaaaaaa ]
- // (Same logic works regardless of endianness.)
- Unsafe.WriteUnaligned<ushort>(pOutputBuffer, (ushort)(thisDWord | (thisDWord >> 8)));
- pInputBuffer += 2;
- pOutputBuffer += 2;
- outputBytesRemaining -= 2;
- thisDWord = secondDWord;
- }
-
- goto AfterReadDWordSkipAllCharsAsciiCheck;
- }
- }
-
- AfterReadDWordSkipAllCharsAsciiCheck:
-
- Debug.Assert(!Utf16Utility.AllCharsInUInt32AreAscii(thisDWord)); // this should have been handled earlier
-
- // Next, try stripping off the first ASCII char if it exists.
- // We don't check for a second ASCII char since that should have been handled above.
-
- if (IsFirstCharAscii(thisDWord))
- {
- if (outputBytesRemaining == 0)
- {
- goto OutputBufferTooSmall;
- }
-
- if (BitConverter.IsLittleEndian)
- {
- pOutputBuffer[0] = (byte)thisDWord; // extract [ ## ## 00 AA ]
- }
- else
- {
- pOutputBuffer[0] = (byte)(thisDWord >> 24); // extract [ AA 00 ## ## ]
- }
-
- pInputBuffer++;
- pOutputBuffer++;
- outputBytesRemaining--;
-
- if (pInputBuffer > pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- goto ProcessNextCharAndFinish; // input buffer doesn't contain enough data to read a DWORD
- }
- else
- {
- // The input buffer at the current offset contains a non-ASCII char.
- // Read an entire DWORD and fall through to non-ASCII consumption logic.
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- }
- }
-
- // At this point, we know the first char in the buffer is non-ASCII, but we haven't yet validated it.
-
- if (!IsFirstCharAtLeastThreeUtf8Bytes(thisDWord))
- {
- TryConsumeMultipleTwoByteSequences:
-
- // For certain text (Greek, Cyrillic, ...), 2-byte sequences tend to be clustered. We'll try transcoding them in
- // a tight loop without falling back to the main loop.
-
- if (IsSecondCharTwoUtf8Bytes(thisDWord))
- {
- // We have two runs of two bytes each.
-
- if (outputBytesRemaining < 4)
- {
- goto ProcessOneCharFromCurrentDWordAndFinish; // running out of output buffer
- }
-
- Unsafe.WriteUnaligned<uint>(pOutputBuffer, ExtractTwoUtf8TwoByteSequencesFromTwoPackedUtf16Chars(thisDWord));
-
- pInputBuffer += 2;
- pOutputBuffer += 4;
- outputBytesRemaining -= 4;
-
- if (pInputBuffer > pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- goto ProcessNextCharAndFinish; // Running out of data - go down slow path
- }
- else
- {
- // Optimization: If we read a long run of two-byte sequences, the next sequence is probably
- // also two bytes. Check for that first before going back to the beginning of the loop.
-
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
-
- if (IsFirstCharTwoUtf8Bytes(thisDWord))
- {
- // Validated we have a two-byte sequence coming up
- goto TryConsumeMultipleTwoByteSequences;
- }
-
- // If we reached this point, the next sequence is something other than a valid
- // two-byte sequence, so go back to the beginning of the loop.
- goto AfterReadDWord;
- }
- }
-
- if (outputBytesRemaining < 2)
- {
- goto OutputBufferTooSmall;
- }
-
- Unsafe.WriteUnaligned<ushort>(pOutputBuffer, (ushort)ExtractUtf8TwoByteSequenceFromFirstUtf16Char(thisDWord));
-
- // The buffer contains a 2-byte sequence followed by 2 bytes that aren't a 2-byte sequence.
- // Unlikely that a 3-byte sequence would follow a 2-byte sequence, so perhaps remaining
- // char is ASCII?
-
- if (IsSecondCharAscii(thisDWord))
- {
- if (outputBytesRemaining >= 3)
- {
- if (BitConverter.IsLittleEndian)
- {
- thisDWord >>= 16;
- }
- pOutputBuffer[2] = (byte)thisDWord;
-
- pInputBuffer += 2;
- pOutputBuffer += 3;
- outputBytesRemaining -= 3;
-
- continue; // go back to original bounds check and check for ASCII
- }
- else
- {
- pInputBuffer++;
- pOutputBuffer += 2;
- goto OutputBufferTooSmall;
- }
- }
- else
- {
- pInputBuffer++;
- pOutputBuffer += 2;
- outputBytesRemaining -= 2;
-
- if (pInputBuffer > pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- goto ProcessNextCharAndFinish; // Running out of data - go down slow path
- }
- else
- {
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- goto BeforeProcessThreeByteSequence; // we know the next byte isn't ASCII, and it's not the start of a 2-byte sequence (this was checked above)
- }
- }
- }
-
- // Check the 3-byte case.
-
- BeforeProcessThreeByteSequence:
-
- if (!IsFirstCharSurrogate(thisDWord))
- {
- // Optimization: A three-byte character could indicate CJK text, which makes it likely
- // that the character following this one is also CJK. We'll perform the check now
- // rather than jumping to the beginning of the main loop.
-
- if (IsSecondCharAtLeastThreeUtf8Bytes(thisDWord))
- {
- if (!IsSecondCharSurrogate(thisDWord))
- {
- if (outputBytesRemaining < 6)
- {
- goto ConsumeSingleThreeByteRun; // not enough space - try consuming as much as we can
- }
-
- WriteTwoUtf16CharsAsTwoUtf8ThreeByteSequences(ref *pOutputBuffer, thisDWord);
-
- pInputBuffer += 2;
- pOutputBuffer += 6;
- outputBytesRemaining -= 6;
-
- // Try to remain in the 3-byte processing loop if at all possible.
-
- if (pInputBuffer > pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- goto ProcessNextCharAndFinish; // Running out of data - go down slow path
- }
- else
- {
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
-
- if (IsFirstCharAtLeastThreeUtf8Bytes(thisDWord))
- {
- goto BeforeProcessThreeByteSequence;
- }
- else
- {
- // Fall back to standard processing loop since we don't know how to optimize this.
- goto AfterReadDWord;
- }
- }
- }
- }
-
- ConsumeSingleThreeByteRun:
-
- if (outputBytesRemaining < 3)
- {
- goto OutputBufferTooSmall;
- }
-
- WriteFirstUtf16CharAsUtf8ThreeByteSequence(ref *pOutputBuffer, thisDWord);
-
- pInputBuffer++;
- pOutputBuffer += 3;
- outputBytesRemaining -= 3;
-
- // Occasionally one-off ASCII characters like spaces, periods, or newlines will make their way
- // in to the text. If this happens strip it off now before seeing if the next character
- // consists of three code units.
-
- if (IsSecondCharAscii(thisDWord))
- {
- if (outputBytesRemaining == 0)
- {
- goto OutputBufferTooSmall;
- }
-
- if (BitConverter.IsLittleEndian)
- {
- *pOutputBuffer = (byte)(thisDWord >> 16);
- }
- else
- {
- *pOutputBuffer = (byte)(thisDWord);
- }
-
- pInputBuffer++;
- pOutputBuffer++;
- outputBytesRemaining--;
-
- if (pInputBuffer > pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- goto ProcessNextCharAndFinish; // Running out of data - go down slow path
- }
- else
- {
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
-
- if (IsFirstCharAtLeastThreeUtf8Bytes(thisDWord))
- {
- goto BeforeProcessThreeByteSequence;
- }
- else
- {
- // Fall back to standard processing loop since we don't know how to optimize this.
- goto AfterReadDWord;
- }
- }
- }
-
- if (pInputBuffer > pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- goto ProcessNextCharAndFinish; // Running out of data - go down slow path
- }
- else
- {
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- goto AfterReadDWordSkipAllCharsAsciiCheck; // we just checked above that this value isn't ASCII
- }
- }
-
- // Four byte sequence processing
-
- if (IsWellFormedUtf16SurrogatePair(thisDWord))
- {
- if (outputBytesRemaining < 4)
- {
- goto OutputBufferTooSmall;
- }
-
- Unsafe.WriteUnaligned<uint>(pOutputBuffer, ExtractFourUtf8BytesFromSurrogatePair(thisDWord));
-
- pInputBuffer += 2;
- pOutputBuffer += 4;
- outputBytesRemaining -= 4;
-
- continue; // go back to beginning of loop for processing
- }
-
- goto Error; // an ill-formed surrogate sequence: high not followed by low, or low not preceded by high
- }
-
- ProcessNextCharAndFinish:
- inputLength = (int)(pFinalPosWhereCanReadDWordFromInputBuffer - pInputBuffer) + CharsPerDWord;
-
- ProcessInputOfLessThanDWordSize:
- Debug.Assert(inputLength < CharsPerDWord);
-
- if (inputLength == 0)
- {
- goto InputBufferFullyConsumed;
- }
-
- uint thisChar = *pInputBuffer;
- goto ProcessFinalChar;
-
- ProcessOneCharFromCurrentDWordAndFinish:
- if (BitConverter.IsLittleEndian)
- {
- thisChar = thisDWord & 0xFFFFu; // preserve only the first char
- }
- else
- {
- thisChar = thisDWord >> 16; // preserve only the first char
- }
-
- ProcessFinalChar:
- {
- if (thisChar <= 0x7Fu)
- {
- if (outputBytesRemaining == 0)
- {
- goto OutputBufferTooSmall; // we have no hope of writing anything to the output
- }
-
- // 1-byte (ASCII) case
- *pOutputBuffer = (byte)thisChar;
-
- pInputBuffer++;
- pOutputBuffer++;
- }
- else if (thisChar < 0x0800u)
- {
- if (outputBytesRemaining < 2)
- {
- goto OutputBufferTooSmall; // we have no hope of writing anything to the output
- }
-
- // 2-byte case
- pOutputBuffer[1] = (byte)((thisChar & 0x3Fu) | unchecked((uint)(sbyte)0x80)); // [ 10xxxxxx ]
- pOutputBuffer[0] = (byte)((thisChar >> 6) | unchecked((uint)(sbyte)0xC0)); // [ 110yyyyy ]
-
- pInputBuffer++;
- pOutputBuffer += 2;
- }
- else if (!UnicodeUtility.IsSurrogateCodePoint(thisChar))
- {
- if (outputBytesRemaining < 3)
- {
- goto OutputBufferTooSmall; // we have no hope of writing anything to the output
- }
-
- // 3-byte case
- pOutputBuffer[2] = (byte)((thisChar & 0x3Fu) | unchecked((uint)(sbyte)0x80)); // [ 10xxxxxx ]
- pOutputBuffer[1] = (byte)(((thisChar >> 6) & 0x3Fu) | unchecked((uint)(sbyte)0x80)); // [ 10yyyyyy ]
- pOutputBuffer[0] = (byte)((thisChar >> 12) | unchecked((uint)(sbyte)0xE0)); // [ 1110zzzz ]
-
- pInputBuffer++;
- pOutputBuffer += 3;
- }
- else if (thisChar <= 0xDBFFu)
- {
- // UTF-16 high surrogate code point with no trailing data, report incomplete input buffer
- goto InputBufferTooSmall;
- }
- else
- {
- // UTF-16 low surrogate code point with no leading data, report error
- goto Error;
- }
- }
-
- // There are two ways we can end up here. Either we were running low on input data,
- // or we were running low on space in the destination buffer. If we're running low on
- // input data (label targets ProcessInputOfLessThanDWordSize and ProcessNextCharAndFinish),
- // then the inputLength value is guaranteed to be between 0 and 1, and we should return Done.
- // If we're running low on destination buffer space (label target ProcessOneCharFromCurrentDWordAndFinish),
- // then we didn't modify inputLength since entering the main loop, which means it should
- // still have a value of >= 2. So checking the value of inputLength is all we need to do to determine
- // which of the two scenarios we're in.
-
- if (inputLength > 1)
- {
- goto OutputBufferTooSmall;
- }
-
- InputBufferFullyConsumed:
- OperationStatus retVal = OperationStatus.Done;
- goto ReturnCommon;
-
- InputBufferTooSmall:
- retVal = OperationStatus.NeedMoreData;
- goto ReturnCommon;
-
- OutputBufferTooSmall:
- retVal = OperationStatus.DestinationTooSmall;
- goto ReturnCommon;
-
- Error:
- retVal = OperationStatus.InvalidData;
- goto ReturnCommon;
-
- ReturnCommon:
- pInputBufferRemaining = pInputBuffer;
- pOutputBufferRemaining = pOutputBuffer;
- return retVal;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Validation.cs b/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Validation.cs
deleted file mode 100644
index 14dc98ed776..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.Validation.cs
+++ /dev/null
@@ -1,738 +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 System.Diagnostics;
-using System.Numerics;
-using System.Runtime.Intrinsics.X86;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nint = System.Int64;
-using nuint = System.UInt64;
-#else // BIT64
-using nint = System.Int32;
-using nuint = System.UInt32;
-#endif // BIT64
-
-namespace System.Text.Unicode
-{
- internal static unsafe partial class Utf8Utility
- {
-#if DEBUG
- private static void _ValidateAdditionalNIntDefinitions()
- {
- Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly.");
- Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly.");
- }
-#endif // DEBUG
-
- // Returns &inputBuffer[inputLength] if the input buffer is valid.
- /// <summary>
- /// Given an input buffer <paramref name="pInputBuffer"/> of byte length <paramref name="inputLength"/>,
- /// returns a pointer to where the first invalid data appears in <paramref name="pInputBuffer"/>.
- /// </summary>
- /// <remarks>
- /// Returns a pointer to the end of <paramref name="pInputBuffer"/> if the buffer is well-formed.
- /// </remarks>
- public static byte* GetPointerToFirstInvalidByte(byte* pInputBuffer, int inputLength, out int utf16CodeUnitCountAdjustment, out int scalarCountAdjustment)
- {
- Debug.Assert(inputLength >= 0, "Input length must not be negative.");
- Debug.Assert(pInputBuffer != null || inputLength == 0, "Input length must be zero if input buffer pointer is null.");
-
- // First, try to drain off as many ASCII bytes as we can from the beginning.
-
- {
- nuint numAsciiBytesCounted = ASCIIUtility.GetIndexOfFirstNonAsciiByte(pInputBuffer, (uint)inputLength);
- pInputBuffer += numAsciiBytesCounted;
-
- // Quick check - did we just end up consuming the entire input buffer?
- // If so, short-circuit the remainder of the method.
-
- inputLength -= (int)numAsciiBytesCounted;
- if (inputLength == 0)
- {
- utf16CodeUnitCountAdjustment = 0;
- scalarCountAdjustment = 0;
- return pInputBuffer;
- }
- }
-
-#if DEBUG
- // Keep these around for final validation at the end of the method.
- byte* pOriginalInputBuffer = pInputBuffer;
- int originalInputLength = inputLength;
-#endif
-
- // Enregistered locals that we'll eventually out to our caller.
-
- int tempUtf16CodeUnitCountAdjustment = 0;
- int tempScalarCountAdjustment = 0;
-
- if (inputLength < sizeof(uint))
- {
- goto ProcessInputOfLessThanDWordSize;
- }
-
- byte* pFinalPosWhereCanReadDWordFromInputBuffer = pInputBuffer + (uint)inputLength - sizeof(uint);
-
- // Begin the main loop.
-
-#if DEBUG
- byte* pLastBufferPosProcessed = null; // used for invariant checking in debug builds
-#endif
-
- while (pInputBuffer <= pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- // Read 32 bits at a time. This is enough to hold any possible UTF8-encoded scalar.
-
- uint thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
-
- AfterReadDWord:
-
-#if DEBUG
- Debug.Assert(pLastBufferPosProcessed < pInputBuffer, "Algorithm should've made forward progress since last read.");
- pLastBufferPosProcessed = pInputBuffer;
-#endif
-
- // First, check for the common case of all-ASCII bytes.
-
- if (ASCIIUtility.AllBytesInUInt32AreAscii(thisDWord))
- {
- // We read an all-ASCII sequence.
-
- pInputBuffer += sizeof(uint);
-
- // If we saw a sequence of all ASCII, there's a good chance a significant amount of following data is also ASCII.
- // Below is basically unrolled loops with poor man's vectorization.
-
- // Below check is "can I read at least five DWORDs from the input stream?"
- // n.b. Since we incremented pInputBuffer above the below subtraction may result in a negative value,
- // hence using nint instead of nuint.
-
- if ((nint)(void*)Unsafe.ByteOffset(ref *pInputBuffer, ref *pFinalPosWhereCanReadDWordFromInputBuffer) >= 4 * sizeof(uint))
- {
- // We want reads in the inner loop to be aligned. So let's perform a quick
- // ASCII check of the next 32 bits (4 bytes) now, and if that succeeds bump
- // the read pointer up to the next aligned address.
-
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- if (!ASCIIUtility.AllBytesInUInt32AreAscii(thisDWord))
- {
- goto AfterReadDWordSkipAllBytesAsciiCheck;
- }
-
- pInputBuffer = (byte*)((nuint)(pInputBuffer + 4) & ~(nuint)3);
-
- // At this point, the input buffer offset points to an aligned DWORD. We also know that there's
- // enough room to read at least four DWORDs from the buffer. (Heed the comment a few lines above:
- // the original 'if' check confirmed that there were 5 DWORDs before the alignment check, and
- // the alignment check consumes at most a single DWORD.)
-
- byte* pInputBufferFinalPosAtWhichCanSafelyLoop = pFinalPosWhereCanReadDWordFromInputBuffer - 3 * sizeof(uint); // can safely read 4 DWORDs here
- uint mask;
-
- do
- {
- if (Sse2.IsSupported && Bmi1.IsSupported)
- {
- // pInputBuffer is 32-bit aligned but not necessary 128-bit aligned, so we're
- // going to perform an unaligned load. We don't necessarily care about aligning
- // this because we pessimistically assume we'll encounter non-ASCII data at some
- // point in the not-too-distant future (otherwise we would've stayed entirely
- // within the all-ASCII vectorized code at the entry to this method).
-
- mask = (uint)Sse2.MoveMask(Sse2.LoadVector128((byte*)pInputBuffer));
- if (mask != 0)
- {
- goto Sse2LoopTerminatedEarlyDueToNonAsciiData;
- }
- }
- else
- {
- if (!ASCIIUtility.AllBytesInUInt32AreAscii(((uint*)pInputBuffer)[0] | ((uint*)pInputBuffer)[1]))
- {
- goto LoopTerminatedEarlyDueToNonAsciiDataInFirstPair;
- }
-
- if (!ASCIIUtility.AllBytesInUInt32AreAscii(((uint*)pInputBuffer)[2] | ((uint*)pInputBuffer)[3]))
- {
- goto LoopTerminatedEarlyDueToNonAsciiDataInSecondPair;
- }
- }
-
- pInputBuffer += 4 * sizeof(uint); // consumed 4 DWORDs
- } while (pInputBuffer <= pInputBufferFinalPosAtWhichCanSafelyLoop);
-
- continue; // need to perform a bounds check because we might be running out of data
-
- Sse2LoopTerminatedEarlyDueToNonAsciiData:
-
- Debug.Assert(BitConverter.IsLittleEndian);
- Debug.Assert(Sse2.IsSupported);
- Debug.Assert(Bmi1.IsSupported);
-
- // The 'mask' value will have a 0 bit for each ASCII byte we saw and a 1 bit
- // for each non-ASCII byte we saw. We can count the number of ASCII bytes,
- // bump our input counter by that amount, and resume processing from the
- // "the first byte is no longer ASCII" portion of the main loop.
-
- Debug.Assert(mask != 0);
-
- pInputBuffer += Bmi1.TrailingZeroCount(mask);
- if (pInputBuffer > pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- goto ProcessRemainingBytesSlow;
- }
-
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer); // no longer guaranteed to be aligned
- goto BeforeProcessTwoByteSequence;
-
- LoopTerminatedEarlyDueToNonAsciiDataInSecondPair:
-
- pInputBuffer += 2 * sizeof(uint); // consumed 2 DWORDs
-
- LoopTerminatedEarlyDueToNonAsciiDataInFirstPair:
-
- // We know that there's *at least* two DWORDs of data remaining in the buffer.
- // We also know that one of them (or both of them) contains non-ASCII data somewhere.
- // Let's perform a quick check here to bypass the logic at the beginning of the main loop.
-
- thisDWord = *(uint*)pInputBuffer; // still aligned here
- if (ASCIIUtility.AllBytesInUInt32AreAscii(thisDWord))
- {
- pInputBuffer += sizeof(uint); // consumed 1 more DWORD
- thisDWord = *(uint*)pInputBuffer; // still aligned here
- }
-
- goto AfterReadDWordSkipAllBytesAsciiCheck;
- }
-
- continue; // not enough data remaining to unroll loop - go back to beginning with bounds checks
- }
-
- AfterReadDWordSkipAllBytesAsciiCheck:
-
- Debug.Assert(!ASCIIUtility.AllBytesInUInt32AreAscii(thisDWord)); // this should have been handled earlier
-
- // Next, try stripping off ASCII bytes one at a time.
- // We only handle up to three ASCII bytes here since we handled the four ASCII byte case above.
-
- {
- uint numLeadingAsciiBytes = ASCIIUtility.CountNumberOfLeadingAsciiBytesFromUInt32WithSomeNonAsciiData(thisDWord);
- pInputBuffer += numLeadingAsciiBytes;
-
- if (pFinalPosWhereCanReadDWordFromInputBuffer < pInputBuffer)
- {
- goto ProcessRemainingBytesSlow; // Input buffer doesn't contain enough data to read a DWORD
- }
- else
- {
- // The input buffer at the current offset contains a non-ASCII byte.
- // Read an entire DWORD and fall through to multi-byte consumption logic.
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- }
- }
-
- BeforeProcessTwoByteSequence:
-
- // At this point, we suspect we're working with a multi-byte code unit sequence,
- // but we haven't yet validated it for well-formedness.
-
- // The masks and comparands are derived from the Unicode Standard, Table 3-6.
- // Additionally, we need to check for valid byte sequences per Table 3-7.
-
- // Check the 2-byte case.
-
- thisDWord -= (BitConverter.IsLittleEndian) ? 0x0000_80C0u : 0xC080_0000u;
- if ((thisDWord & (BitConverter.IsLittleEndian ? 0x0000_C0E0u : 0xE0C0_0000u)) == 0)
- {
- // Per Table 3-7, valid sequences are:
- // [ C2..DF ] [ 80..BF ]
- //
- // Due to our modification of 'thisDWord' above, this becomes:
- // [ 02..1F ] [ 00..3F ]
- //
- // We've already checked that the leading byte was originally in the range [ C0..DF ]
- // and that the trailing byte was originally in the range [ 80..BF ], so now we only need
- // to check that the modified leading byte is >= [ 02 ].
-
- if ((BitConverter.IsLittleEndian && (byte)thisDWord < 0x02u)
- || (!BitConverter.IsLittleEndian && thisDWord < 0x0200_0000u))
- {
- goto Error; // overlong form - leading byte was [ C0 ] or [ C1 ]
- }
-
- ProcessTwoByteSequenceSkipOverlongFormCheck:
-
- // Optimization: If this is a two-byte-per-character language like Cyrillic or Hebrew,
- // there's a good chance that if we see one two-byte run then there's another two-byte
- // run immediately after. Let's check that now.
-
- // On little-endian platforms, we can check for the two-byte UTF8 mask *and* validate that
- // the value isn't overlong using a single comparison. On big-endian platforms, we'll need
- // to validate the mask and validate that the sequence isn't overlong as two separate comparisons.
-
- if ((BitConverter.IsLittleEndian && UInt32EndsWithValidUtf8TwoByteSequenceLittleEndian(thisDWord))
- || (!BitConverter.IsLittleEndian && (UInt32EndsWithUtf8TwoByteMask(thisDWord) && !UInt32EndsWithOverlongUtf8TwoByteSequence(thisDWord))))
- {
- // We have two runs of two bytes each.
- pInputBuffer += 4;
- tempUtf16CodeUnitCountAdjustment -= 2; // 4 UTF-8 code units -> 2 UTF-16 code units (and 2 scalars)
-
- if (pInputBuffer <= pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- // Optimization: If we read a long run of two-byte sequences, the next sequence is probably
- // also two bytes. Check for that first before going back to the beginning of the loop.
-
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
-
- if (BitConverter.IsLittleEndian)
- {
- if (UInt32BeginsWithValidUtf8TwoByteSequenceLittleEndian(thisDWord))
- {
- // The next sequence is a valid two-byte sequence.
- goto ProcessTwoByteSequenceSkipOverlongFormCheck;
- }
- }
- else
- {
- if (UInt32BeginsWithUtf8TwoByteMask(thisDWord))
- {
- if (UInt32BeginsWithOverlongUtf8TwoByteSequence(thisDWord))
- {
- goto Error; // The next sequence purports to be a 2-byte sequence but is overlong.
- }
-
- goto ProcessTwoByteSequenceSkipOverlongFormCheck;
- }
- }
-
- // If we reached this point, the next sequence is something other than a valid
- // two-byte sequence, so go back to the beginning of the loop.
- goto AfterReadDWord;
- }
- else
- {
- goto ProcessRemainingBytesSlow; // Running out of data - go down slow path
- }
- }
-
- // The buffer contains a 2-byte sequence followed by 2 bytes that aren't a 2-byte sequence.
- // Unlikely that a 3-byte sequence would follow a 2-byte sequence, so perhaps remaining
- // bytes are ASCII?
-
- tempUtf16CodeUnitCountAdjustment--; // 2-byte sequence + (some number of ASCII bytes) -> 1 UTF-16 code units (and 1 scalar) [+ trailing]
-
- if (UInt32ThirdByteIsAscii(thisDWord))
- {
- if (UInt32FourthByteIsAscii(thisDWord))
- {
- pInputBuffer += 4;
- }
- else
- {
- pInputBuffer += 3;
-
- // A two-byte sequence followed by an ASCII byte followed by a non-ASCII byte.
- // Read in the next DWORD and jump directly to the start of the multi-byte processing block.
-
- if (pInputBuffer <= pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
- goto BeforeProcessTwoByteSequence;
- }
- }
- }
- else
- {
- pInputBuffer += 2;
- }
-
- continue;
- }
-
- // Check the 3-byte case.
- // We need to restore the C0 leading byte we stripped out earlier, then we can strip out the expected E0 byte.
-
- thisDWord -= (BitConverter.IsLittleEndian) ? (0x0080_00E0u - 0x0000_00C0u) : (0xE000_8000u - 0xC000_0000u);
- if ((thisDWord & (BitConverter.IsLittleEndian ? 0x00C0_C0F0u : 0xF0C0_C000u)) == 0)
- {
- ProcessThreeByteSequenceWithCheck:
-
- // We assume the caller has confirmed that the bit pattern is representative of a three-byte
- // sequence, but it may still be overlong or surrogate. We need to check for these possibilities.
- //
- // Per Table 3-7, valid sequences are:
- // [ E0 ] [ A0..BF ] [ 80..BF ]
- // [ E1..EC ] [ 80..BF ] [ 80..BF ]
- // [ ED ] [ 80..9F ] [ 80..BF ]
- // [ EE..EF ] [ 80..BF ] [ 80..BF ]
- //
- // Big-endian examples of using the above validation table:
- // E0A0 = 1110 0000 1010 0000 => invalid (overlong ) patterns are 1110 0000 100# ####
- // ED9F = 1110 1101 1001 1111 => invalid (surrogate) patterns are 1110 1101 101# ####
- // If using the bitmask ......................................... 0000 1111 0010 0000 (=0F20),
- // Then invalid (overlong) patterns match the comparand ......... 0000 0000 0000 0000 (=0000),
- // And invalid (surrogate) patterns match the comparand ......... 0000 1101 0010 0000 (=0D20).
- //
- // It's ok if the caller has manipulated 'thisDWord' (e.g., by subtracting 0xE0 or 0x80)
- // as long as they haven't touched the bits we're about to use in our mask checking below.
-
- if (BitConverter.IsLittleEndian)
- {
- // The "overlong or surrogate" check can be implemented using a single jump, but there's
- // some overhead to moving the bits into the correct locations in order to perform the
- // correct comparison, and in practice the processor's branch prediction capability is
- // good enough that we shouldn't bother. So we'll use two jumps instead.
-
- // Can't extract this check into its own helper method because JITter produces suboptimal
- // assembly, even with aggressive inlining.
-
- // Code below becomes 5 instructions: test, jz, lea, test, jz
-
- if (((thisDWord & 0x0000_200Fu) == 0) || (((thisDWord - 0x0000_200Du) & 0x0000_200Fu) == 0))
- {
- goto Error; // overlong or surrogate
- }
- }
- else
- {
- if (((thisDWord & 0x0F20_0000u) == 0) || (((thisDWord - 0x0D20_0000u) & 0x0F20_0000u) == 0))
- {
- goto Error; // overlong or surrogate
- }
- }
-
- ProcessSingleThreeByteSequenceSkipOverlongAndSurrogateChecks:
-
- // Occasionally one-off ASCII characters like spaces, periods, or newlines will make their way
- // in to the text. If this happens strip it off now before seeing if the next character
- // consists of three code units.
-
- // Branchless: consume a 3-byte UTF-8 sequence and optionally an extra ASCII byte hanging off the end
-
- nint asciiAdjustment;
- if (BitConverter.IsLittleEndian)
- {
- asciiAdjustment = (int)thisDWord >> 31; // smear most significant bit across entire value
- }
- else
- {
- asciiAdjustment = (nint)(sbyte)thisDWord >> 7; // smear most significant bit of least significant byte across entire value
- }
-
- // asciiAdjustment = 0 if fourth byte is ASCII; -1 otherwise
-
- // Please *DO NOT* reorder the below two lines. It provides extra defense in depth in case this method
- // is ever changed such that pInputBuffer becomes a 'ref byte' instead of a simple 'byte*'. It's valid
- // to add 4 before backing up since we already checked previously that the input buffer contains at
- // least a DWORD's worth of data, so we're not going to run past the end of the buffer where the GC can
- // no longer track the reference. However, we can't back up before adding 4, since we might back up to
- // before the start of the buffer, and the GC isn't guaranteed to be able to track this.
-
- pInputBuffer += 4; // optimistically, assume consumed a 3-byte UTF-8 sequence plus an extra ASCII byte
- pInputBuffer += asciiAdjustment; // back up if we didn't actually consume an ASCII byte
-
- tempUtf16CodeUnitCountAdjustment -= 2; // 3 (or 4) UTF-8 bytes -> 1 (or 2) UTF-16 code unit (and 1 [or 2] scalar)
-
- SuccessfullyProcessedThreeByteSequence:
-
- if (IntPtr.Size >= 8 && BitConverter.IsLittleEndian)
- {
- // x64 little-endian optimization: A three-byte character could indicate CJK text,
- // which makes it likely that the character following this one is also CJK.
- // We'll try to process several three-byte sequences at a time.
-
- // The check below is really "can we read 9 bytes from the input buffer?" since 'pFinalPos...' is already offset
- // n.b. The subtraction below could result in a negative value (since we advanced pInputBuffer above), so
- // use nint instead of nuint.
-
- if ((nint)(pFinalPosWhereCanReadDWordFromInputBuffer - pInputBuffer) >= 5)
- {
- ulong thisQWord = Unsafe.ReadUnaligned<ulong>(pInputBuffer);
-
- // Stage the next 32 bits into 'thisDWord' so that it's ready for us in case we need to jump backward
- // to a previous location in the loop. This offers defense against reading main memory again (which may
- // have been modified and could lead to a race condition).
-
- thisDWord = (uint)thisQWord;
-
- // Is this three 3-byte sequences in a row?
- // thisQWord = [ 10yyyyyy 1110zzzz | 10xxxxxx 10yyyyyy 1110zzzz | 10xxxxxx 10yyyyyy 1110zzzz ] [ 10xxxxxx ]
- // ---- CHAR 3 ---- --------- CHAR 2 --------- --------- CHAR 1 --------- -CHAR 3-
- if ((thisQWord & 0xC0F0_C0C0_F0C0_C0F0ul) == 0x80E0_8080_E080_80E0ul && IsUtf8ContinuationByte(in pInputBuffer[8]))
- {
- // Saw a proper bitmask for three incoming 3-byte sequences, perform the
- // overlong and surrogate sequence checking now.
-
- // Check the first character.
- // If the first character is overlong or a surrogate, fail immediately.
-
- if ((((uint)thisQWord & 0x200Fu) == 0) || ((((uint)thisQWord - 0x200Du) & 0x200Fu) == 0))
- {
- goto Error;
- }
-
- // Check the second character.
- // At this point, we now know the first three bytes represent a well-formed sequence.
- // If there's an error beyond here, we'll jump back to the "process three known good bytes"
- // logic.
-
- thisQWord >>= 24;
- if ((((uint)thisQWord & 0x200Fu) == 0) || ((((uint)thisQWord - 0x200Du) & 0x200Fu) == 0))
- {
- goto ProcessSingleThreeByteSequenceSkipOverlongAndSurrogateChecks;
- }
-
- // Check the third character (we already checked that it's followed by a continuation byte).
-
- thisQWord >>= 24;
- if ((((uint)thisQWord & 0x200Fu) == 0) || ((((uint)thisQWord - 0x200Du) & 0x200Fu) == 0))
- {
- goto ProcessSingleThreeByteSequenceSkipOverlongAndSurrogateChecks;
- }
-
- pInputBuffer += 9;
- tempUtf16CodeUnitCountAdjustment -= 6; // 9 UTF-8 bytes -> 3 UTF-16 code units (and 3 scalars)
-
- goto SuccessfullyProcessedThreeByteSequence;
- }
-
- // Is this two 3-byte sequences in a row?
- // thisQWord = [ ######## ######## | 10xxxxxx 10yyyyyy 1110zzzz | 10xxxxxx 10yyyyyy 1110zzzz ]
- // --------- CHAR 2 --------- --------- CHAR 1 ---------
- if ((thisQWord & 0xC0C0_F0C0_C0F0ul) == 0x8080_E080_80E0ul)
- {
- // Saw a proper bitmask for two incoming 3-byte sequences, perform the
- // overlong and surrogate sequence checking now.
-
- // Check the first character.
- // If the first character is overlong or a surrogate, fail immediately.
-
- if ((((uint)thisQWord & 0x200Fu) == 0) || ((((uint)thisQWord - 0x200Du) & 0x200Fu) == 0))
- {
- goto Error;
- }
-
- // Check the second character.
- // At this point, we now know the first three bytes represent a well-formed sequence.
- // If there's an error beyond here, we'll jump back to the "process three known good bytes"
- // logic.
-
- thisQWord >>= 24;
- if ((((uint)thisQWord & 0x200Fu) == 0) || ((((uint)thisQWord - 0x200Du) & 0x200Fu) == 0))
- {
- goto ProcessSingleThreeByteSequenceSkipOverlongAndSurrogateChecks;
- }
-
- pInputBuffer += 6;
- tempUtf16CodeUnitCountAdjustment -= 4; // 6 UTF-8 bytes -> 2 UTF-16 code units (and 2 scalars)
-
- // The next byte in the sequence didn't have a 3-byte marker, so it's probably
- // an ASCII character. Jump back to the beginning of loop processing.
-
- continue;
- }
-
- if (UInt32BeginsWithUtf8ThreeByteMask(thisDWord))
- {
- // A single three-byte sequence.
- goto ProcessThreeByteSequenceWithCheck;
- }
- else
- {
- // Not a three-byte sequence; perhaps ASCII?
- goto AfterReadDWord;
- }
- }
- }
-
- if (pInputBuffer <= pFinalPosWhereCanReadDWordFromInputBuffer)
- {
- thisDWord = Unsafe.ReadUnaligned<uint>(pInputBuffer);
-
- // Optimization: A three-byte character could indicate CJK text, which makes it likely
- // that the character following this one is also CJK. We'll check for a three-byte sequence
- // marker now and jump directly to three-byte sequence processing if we see one, skipping
- // all of the logic at the beginning of the loop.
-
- if (UInt32BeginsWithUtf8ThreeByteMask(thisDWord))
- {
- goto ProcessThreeByteSequenceWithCheck; // Found another [not yet validated] three-byte sequence; process
- }
- else
- {
- goto AfterReadDWord; // Probably ASCII punctuation or whitespace; go back to start of loop
- }
- }
- else
- {
- goto ProcessRemainingBytesSlow; // Running out of data
- }
- }
-
- // Assume the 4-byte case, but we need to validate.
-
- if (BitConverter.IsLittleEndian)
- {
- thisDWord &= 0xC0C0_FFFFu;
-
- // After the above modifications earlier in this method, we expect 'thisDWord'
- // to have the structure [ 10000000 00000000 00uuzzzz 00010uuu ]. We'll now
- // perform two checks to confirm this. The first will verify the
- // [ 10000000 00000000 00###### ######## ] structure by taking advantage of two's
- // complement representation to perform a single *signed* integer check.
-
- if ((int)thisDWord > unchecked((int)0x8000_3FFF))
- {
- goto Error; // didn't have three trailing bytes
- }
-
- // Now we want to confirm that 0x01 <= uuuuu (otherwise this is an overlong encoding)
- // and that uuuuu <= 0x10 (otherwise this is an out-of-range encoding).
-
- thisDWord = BitOperations.RotateRight(thisDWord, 8);
-
- // Now, thisDWord = [ 00010uuu 10000000 00000000 00uuzzzz ].
- // The check is now a simple add / cmp / jcc combo.
-
- if (!UnicodeUtility.IsInRangeInclusive(thisDWord, 0x1080_0010u, 0x1480_000Fu))
- {
- goto Error; // overlong or out-of-range
- }
- }
- else
- {
- thisDWord -= 0x80u;
-
- // After the above modifications earlier in this method, we expect 'thisDWord'
- // to have the structure [ 00010uuu 00uuzzzz 00yyyyyy 00xxxxxx ]. We'll now
- // perform two checks to confirm this. The first will verify the
- // [ ######## 00###### 00###### 00###### ] structure.
-
- if ((thisDWord & 0x00C0_C0C0u) != 0)
- {
- goto Error; // didn't have three trailing bytes
- }
-
- // Now we want to confirm that 0x01 <= uuuuu (otherwise this is an overlong encoding)
- // and that uuuuu <= 0x10 (otherwise this is an out-of-range encoding).
- // This is a simple range check. (We don't care about the low two bytes.)
-
- if (!UnicodeUtility.IsInRangeInclusive(thisDWord, 0x1010_0000u, 0x140F_FFFFu))
- {
- goto Error; // overlong or out-of-range
- }
- }
-
- // Validation of 4-byte case complete.
-
- pInputBuffer += 4;
- tempUtf16CodeUnitCountAdjustment -= 2; // 4 UTF-8 bytes -> 2 UTF-16 code units
- tempScalarCountAdjustment--; // 2 UTF-16 code units -> 1 scalar
-
- continue; // go back to beginning of loop for processing
- }
-
- goto ProcessRemainingBytesSlow;
-
- ProcessInputOfLessThanDWordSize:
-
- Debug.Assert(inputLength < 4);
- nuint inputBufferRemainingBytes = (uint)inputLength;
- goto ProcessSmallBufferCommon;
-
- ProcessRemainingBytesSlow:
-
- inputBufferRemainingBytes = (nuint)(void*)Unsafe.ByteOffset(ref *pInputBuffer, ref *pFinalPosWhereCanReadDWordFromInputBuffer) + 4;
-
- ProcessSmallBufferCommon:
-
- Debug.Assert(inputBufferRemainingBytes < 4);
- while (inputBufferRemainingBytes > 0)
- {
- uint firstByte = pInputBuffer[0];
-
- if ((byte)firstByte < 0x80u)
- {
- // 1-byte (ASCII) case
- pInputBuffer++;
- inputBufferRemainingBytes--;
- continue;
- }
- else if (inputBufferRemainingBytes >= 2)
- {
- uint secondByte = pInputBuffer[1]; // typed as 32-bit since we perform arithmetic (not just comparisons) on this value
- if ((byte)firstByte < 0xE0u)
- {
- // 2-byte case
- if ((byte)firstByte >= 0xC2u && IsLowByteUtf8ContinuationByte(secondByte))
- {
- pInputBuffer += 2;
- tempUtf16CodeUnitCountAdjustment--; // 2 UTF-8 bytes -> 1 UTF-16 code unit (and 1 scalar)
- inputBufferRemainingBytes -= 2;
- continue;
- }
- }
- else if (inputBufferRemainingBytes >= 3)
- {
- if ((byte)firstByte < 0xF0u)
- {
- if ((byte)firstByte == 0xE0u)
- {
- if (!UnicodeUtility.IsInRangeInclusive(secondByte, 0xA0u, 0xBFu))
- {
- goto Error; // overlong encoding
- }
- }
- else if ((byte)firstByte == 0xEDu)
- {
- if (!UnicodeUtility.IsInRangeInclusive(secondByte, 0x80u, 0x9Fu))
- {
- goto Error; // would be a UTF-16 surrogate code point
- }
- }
- else
- {
- if (!IsLowByteUtf8ContinuationByte(secondByte))
- {
- goto Error; // first trailing byte doesn't have proper continuation marker
- }
- }
-
- if (IsUtf8ContinuationByte(in pInputBuffer[2]))
- {
- pInputBuffer += 3;
- tempUtf16CodeUnitCountAdjustment -= 2; // 3 UTF-8 bytes -> 2 UTF-16 code units (and 2 scalars)
- inputBufferRemainingBytes -= 3;
- continue;
- }
- }
- }
- }
-
- // Error - no match.
-
- goto Error;
- }
-
- // If we reached this point, we're out of data, and we saw no bad UTF8 sequence.
-
-#if DEBUG
- // Quick check that for the success case we're going to fulfill our contract of returning &inputBuffer[inputLength].
- Debug.Assert(pOriginalInputBuffer + originalInputLength == pInputBuffer, "About to return an unexpected value.");
-#endif
-
- Error:
-
- // Report back to our caller how far we got before seeing invalid data.
- // (Also used for normal termination when falling out of the loop above.)
-
- utf16CodeUnitCountAdjustment = tempUtf16CodeUnitCountAdjustment;
- scalarCountAdjustment = tempScalarCountAdjustment;
- return pInputBuffer;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.WhiteSpace.cs b/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.WhiteSpace.cs
deleted file mode 100644
index 6f8561571d5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.WhiteSpace.cs
+++ /dev/null
@@ -1,138 +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 System.Runtime.InteropServices;
-using Internal.Runtime.CompilerServices;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nint = System.Int64;
-using nuint = System.UInt64;
-#else
-using nint = System.Int32;
-using nuint = System.UInt32;
-#endif
-
-namespace System.Text.Unicode
-{
- internal static partial class Utf8Utility
- {
- /// <summary>
- /// Returns the index in <paramref name="utf8Data"/> where the first non-whitespace character
- /// appears, or the input length if the data contains only whitespace characters.
- /// </summary>
- public static int GetIndexOfFirstNonWhiteSpaceChar(ReadOnlySpan<byte> utf8Data)
- {
- return (int)GetIndexOfFirstNonWhiteSpaceChar(ref MemoryMarshal.GetReference(utf8Data), (uint)utf8Data.Length);
- }
-
- private static nuint GetIndexOfFirstNonWhiteSpaceChar(ref byte utf8Data, nuint length)
- {
- // This method is optimized for the case where the input data is ASCII, and if the
- // data does need to be trimmed it's likely that only a relatively small number of
- // bytes will be trimmed.
-
- nuint i = 0;
-
- while (i < length)
- {
- // Very quick check: see if the byte is in the range [ 21 .. 7F ].
- // If so, we can skip the more expensive logic later in this method.
-
- if ((sbyte)Unsafe.AddByteOffset(ref utf8Data, i) > (sbyte)0x20)
- {
- break;
- }
-
- uint possibleAsciiByte = Unsafe.AddByteOffset(ref utf8Data, i);
- if (UnicodeUtility.IsAsciiCodePoint(possibleAsciiByte))
- {
- // The simple comparison failed. Let's read the actual byte value,
- // and if it's ASCII we can delegate to Rune's inlined method
- // implementation.
-
- if (Rune.IsWhiteSpace(Rune.UnsafeCreate(possibleAsciiByte)))
- {
- i++;
- continue;
- }
- }
- else
- {
- // Not ASCII data. Go back to the slower "decode the entire scalar"
- // code path, then compare it against our Unicode tables.
-
- Rune.DecodeFromUtf8(new ReadOnlySpan<byte>(ref utf8Data, (int)length).Slice((int)i), out Rune decodedRune, out int bytesConsumed);
- if (Rune.IsWhiteSpace(decodedRune))
- {
- i += (uint)bytesConsumed;
- continue;
- }
- }
-
- break; // If we got here, we saw a non-whitespace subsequence.
- }
-
- return i;
- }
-
- /// <summary>
- /// Returns the index in <paramref name="utf8Data"/> where the trailing whitespace sequence
- /// begins, or 0 if the data contains only whitespace characters, or the span length if the
- /// data does not end with any whitespace characters.
- /// </summary>
- public static int GetIndexOfTrailingWhiteSpaceSequence(ReadOnlySpan<byte> utf8Data)
- {
- return (int)GetIndexOfTrailingWhiteSpaceSequence(ref MemoryMarshal.GetReference(utf8Data), (uint)utf8Data.Length);
- }
-
- private static nuint GetIndexOfTrailingWhiteSpaceSequence(ref byte utf8Data, nuint length)
- {
- // This method is optimized for the case where the input data is ASCII, and if the
- // data does need to be trimmed it's likely that only a relatively small number of
- // bytes will be trimmed.
-
- while (length > 0)
- {
- // Very quick check: see if the byte is in the range [ 21 .. 7F ].
- // If so, we can skip the more expensive logic later in this method.
-
- if ((sbyte)Unsafe.Add(ref Unsafe.AddByteOffset(ref utf8Data, length), -1) > (sbyte)0x20)
- {
- break;
- }
-
- uint possibleAsciiByte = Unsafe.Add(ref Unsafe.AddByteOffset(ref utf8Data, length), -1);
- if (UnicodeUtility.IsAsciiCodePoint(possibleAsciiByte))
- {
- // The simple comparison failed. Let's read the actual byte value,
- // and if it's ASCII we can delegate to Rune's inlined method
- // implementation.
-
- if (Rune.IsWhiteSpace(Rune.UnsafeCreate(possibleAsciiByte)))
- {
- length--;
- continue;
- }
- }
- else
- {
- // Not ASCII data. Go back to the slower "decode the entire scalar"
- // code path, then compare it against our Unicode tables.
-
- Rune.DecodeLastFromUtf8(new ReadOnlySpan<byte>(ref utf8Data, (int)length), out Rune decodedRune, out int bytesConsumed);
- if (Rune.IsWhiteSpace(decodedRune))
- {
- length -= (uint)bytesConsumed;
- continue;
- }
- }
-
- break; // If we got here, we saw a non-whitespace subsequence.
- }
-
- return length;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.cs b/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.cs
deleted file mode 100644
index bb6853b072e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/Unicode/Utf8Utility.cs
+++ /dev/null
@@ -1,112 +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 System.Buffers;
-using System.Diagnostics;
-using System.IO;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Text.Unicode
-{
- internal static partial class Utf8Utility
- {
- /// <summary>
- /// The maximum number of bytes that can result from UTF-8 transcoding
- /// any Unicode scalar value.
- /// </summary>
- internal const int MaxBytesPerScalar = 4;
-
- /// <summary>
- /// The UTF-8 representation of <see cref="UnicodeUtility.ReplacementChar"/>.
- /// </summary>
- private static ReadOnlySpan<byte> ReplacementCharSequence => new byte[] { 0xEF, 0xBF, 0xBD };
-
- /// <summary>
- /// Returns the byte index in <paramref name="utf8Data"/> where the first invalid UTF-8 sequence begins,
- /// or -1 if the buffer contains no invalid sequences. Also outs the <paramref name="isAscii"/> parameter
- /// stating whether all data observed (up to the first invalid sequence or the end of the buffer, whichever
- /// comes first) is ASCII.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe int GetIndexOfFirstInvalidUtf8Sequence(ReadOnlySpan<byte> utf8Data, out bool isAscii)
- {
- fixed (byte* pUtf8Data = &MemoryMarshal.GetReference(utf8Data))
- {
- byte* pFirstInvalidByte = GetPointerToFirstInvalidByte(pUtf8Data, utf8Data.Length, out int utf16CodeUnitCountAdjustment, out _);
- int index = (int)(void*)Unsafe.ByteOffset(ref *pUtf8Data, ref *pFirstInvalidByte);
-
- isAscii = (utf16CodeUnitCountAdjustment == 0); // If UTF-16 char count == UTF-8 byte count, it's ASCII.
- return (index < utf8Data.Length) ? index : -1;
- }
- }
-
-#if FEATURE_UTF8STRING
- /// <summary>
- /// Returns a value stating whether <paramref name="utf8Data"/> contains only well-formed UTF-8 data.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe bool IsWellFormedUtf8(ReadOnlySpan<byte> utf8Data)
- {
- fixed (byte* pUtf8Data = &MemoryMarshal.GetReference(utf8Data))
- {
- // The return value here will point to the end of the span if the data is well-formed.
- byte* pFirstInvalidByte = GetPointerToFirstInvalidByte(pUtf8Data, utf8Data.Length, out int _, out _);
- return (pFirstInvalidByte == (pUtf8Data + (uint)utf8Data.Length));
- }
- }
-
- /// <summary>
- /// Returns <paramref name="value"/> if it is null or contains only well-formed UTF-8 data;
- /// otherwises allocates a new <see cref="Utf8String"/> instance containing the same data as
- /// <paramref name="value"/> but where all invalid UTF-8 sequences have been replaced
- /// with U+FFFD.
- /// </summary>
- public static Utf8String ValidateAndFixupUtf8String(Utf8String value)
- {
- if (value.Length == 0)
- {
- return value;
- }
-
- ReadOnlySpan<byte> valueAsBytes = value.AsBytes();
-
- int idxOfFirstInvalidData = GetIndexOfFirstInvalidUtf8Sequence(valueAsBytes, out _);
- if (idxOfFirstInvalidData < 0)
- {
- return value;
- }
-
- // TODO_UTF8STRING: Replace this with the faster implementation once it's available.
- // (The faster implementation is in the dev/utf8string_bak branch currently.)
-
- MemoryStream memStream = new MemoryStream();
- memStream.Write(valueAsBytes.Slice(0, idxOfFirstInvalidData));
-
- valueAsBytes = valueAsBytes.Slice(idxOfFirstInvalidData);
- do
- {
- if (Rune.DecodeFromUtf8(valueAsBytes, out _, out int bytesConsumed) == OperationStatus.Done)
- {
- // Valid scalar value - copy data as-is to MemoryStream
- memStream.Write(valueAsBytes.Slice(0, bytesConsumed));
- }
- else
- {
- // Invalid scalar value - copy U+FFFD to MemoryStream
- memStream.Write(ReplacementCharSequence);
- }
-
- valueAsBytes = valueAsBytes.Slice(bytesConsumed);
- } while (!valueAsBytes.IsEmpty);
-
- bool success = memStream.TryGetBuffer(out ArraySegment<byte> memStreamBuffer);
- Debug.Assert(success, "Couldn't get underlying MemoryStream buffer.");
-
- return Utf8String.UnsafeCreateWithoutValidation(memStreamBuffer);
- }
-#endif // FEATURE_UTF8STRING
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/UnicodeDebug.cs b/netcore/System.Private.CoreLib/shared/System/Text/UnicodeDebug.cs
deleted file mode 100644
index 0ea7de8c33c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/UnicodeDebug.cs
+++ /dev/null
@@ -1,52 +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 System.Diagnostics;
-
-namespace System.Text
-{
- internal static class UnicodeDebug
- {
- [Conditional("DEBUG")]
- internal static void AssertIsHighSurrogateCodePoint(uint codePoint)
- {
- Debug.Assert(UnicodeUtility.IsHighSurrogateCodePoint(codePoint), $"The value {ToHexString(codePoint)} is not a valid UTF-16 high surrogate code point.");
- }
-
- [Conditional("DEBUG")]
- internal static void AssertIsLowSurrogateCodePoint(uint codePoint)
- {
- Debug.Assert(UnicodeUtility.IsLowSurrogateCodePoint(codePoint), $"The value {ToHexString(codePoint)} is not a valid UTF-16 low surrogate code point.");
- }
-
- [Conditional("DEBUG")]
- internal static void AssertIsValidCodePoint(uint codePoint)
- {
- Debug.Assert(UnicodeUtility.IsValidCodePoint(codePoint), $"The value {ToHexString(codePoint)} is not a valid Unicode code point.");
- }
-
- [Conditional("DEBUG")]
- internal static void AssertIsValidScalar(uint scalarValue)
- {
- Debug.Assert(UnicodeUtility.IsValidUnicodeScalar(scalarValue), $"The value {ToHexString(scalarValue)} is not a valid Unicode scalar value.");
- }
-
- [Conditional("DEBUG")]
- internal static void AssertIsValidSupplementaryPlaneScalar(uint scalarValue)
- {
- Debug.Assert(UnicodeUtility.IsValidUnicodeScalar(scalarValue) && !UnicodeUtility.IsBmpCodePoint(scalarValue), $"The value {ToHexString(scalarValue)} is not a valid supplementary plane Unicode scalar value.");
- }
-
- /// <summary>
- /// Formats a code point as the hex string "U+XXXX".
- /// </summary>
- /// <remarks>
- /// The input value doesn't have to be a real code point in the Unicode codespace. It can be any integer.
- /// </remarks>
- private static string ToHexString(uint codePoint)
- {
- return FormattableString.Invariant($"U+{codePoint:X4}");
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/UnicodeEncoding.cs b/netcore/System.Private.CoreLib/shared/System/Text/UnicodeEncoding.cs
deleted file mode 100644
index 1b457771c45..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/UnicodeEncoding.cs
+++ /dev/null
@@ -1,1877 +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.
-
-//
-// Don't override IsAlwaysNormalized because it is just a Unicode Transformation and could be confused.
-//
-
-// This define can be used to turn off the fast loops. Useful for finding whether
-// the problem is fastloop-specific.
-#define FASTLOOP
-
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-using Internal.Runtime.CompilerServices;
-
-namespace System.Text
-{
- public class UnicodeEncoding : Encoding
- {
- // Used by Encoding.BigEndianUnicode/Unicode for lazy initialization
- // The initialization code will not be run until a static member of the class is referenced
- internal static readonly UnicodeEncoding s_bigEndianDefault = new UnicodeEncoding(bigEndian: true, byteOrderMark: true);
- internal static readonly UnicodeEncoding s_littleEndianDefault = new UnicodeEncoding(bigEndian: false, byteOrderMark: true);
-
- private readonly bool isThrowException = false;
-
- private readonly bool bigEndian = false;
- private readonly bool byteOrderMark = false;
-
- // Unicode version 2.0 character size in bytes
- public const int CharSize = 2;
-
- public UnicodeEncoding()
- : this(false, true)
- {
- }
-
- public UnicodeEncoding(bool bigEndian, bool byteOrderMark)
- : base(bigEndian ? 1201 : 1200) // Set the data item.
- {
- this.bigEndian = bigEndian;
- this.byteOrderMark = byteOrderMark;
- }
-
- public UnicodeEncoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes)
- : this(bigEndian, byteOrderMark)
- {
- this.isThrowException = throwOnInvalidBytes;
-
- // Encoding constructor already did this, but it'll be wrong if we're throwing exceptions
- if (this.isThrowException)
- SetDefaultFallbacks();
- }
-
- internal sealed override void SetDefaultFallbacks()
- {
- // For UTF-X encodings, we use a replacement fallback with an empty string
- if (this.isThrowException)
- {
- this.encoderFallback = EncoderFallback.ExceptionFallback;
- this.decoderFallback = DecoderFallback.ExceptionFallback;
- }
- else
- {
- this.encoderFallback = new EncoderReplacementFallback("\xFFFD");
- this.decoderFallback = new DecoderReplacementFallback("\xFFFD");
- }
- }
-
- // The following methods are copied from EncodingNLS.cs.
- // Unfortunately EncodingNLS.cs is internal and we're public, so we have to re-implement them here.
- // These should be kept in sync for the following classes:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- //
-
- // Returns the number of bytes required to encode a range of characters in
- // a character array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetByteCount(char[] chars, int index, int count)
- {
- // Validate input parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // If no input, return 0, avoid fixed empty array problem
- if (count == 0)
- return 0;
-
- // Just call the pointer version
- fixed (char* pChars = chars)
- return GetByteCount(pChars + index, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetByteCount(string s)
- {
- // Validate input
- if (s == null)
- throw new ArgumentNullException(nameof(s));
-
- fixed (char* pChars = s)
- return GetByteCount(pChars, s.Length, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetByteCount(char* chars, int count)
- {
- // Validate Parameters
- if (chars == null)
- throw new ArgumentNullException(nameof(chars), SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Call it with empty encoder
- return GetByteCount(chars, count, null);
- }
-
- // Parent method is safe.
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- public override unsafe int GetBytes(string s, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- if (s == null || bytes == null)
- throw new ArgumentNullException(s == null ? nameof(s) : nameof(bytes), SR.ArgumentNull_Array);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (s.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(s), SR.ArgumentOutOfRange_IndexCount);
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index);
-
- int byteCount = bytes.Length - byteIndex;
-
- fixed (char* pChars = s) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
- }
-
- // Encodes a range of characters in a character array into a range of bytes
- // in a byte array. An exception occurs if the byte array is not large
- // enough to hold the complete encoding of the characters. The
- // GetByteCount method can be used to determine the exact number of
- // bytes that will be produced for a given range of characters.
- // Alternatively, the GetMaxByteCount method can be used to
- // determine the maximum number of bytes that will be produced for a given
- // number of characters, regardless of the actual character values.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetBytes(char[] chars, int charIndex, int charCount,
- byte[] bytes, int byteIndex)
- {
- // Validate parameters
- if (chars == null || bytes == null)
- throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes), SR.ArgumentNull_Array);
-
- if (charIndex < 0 || charCount < 0)
- throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (chars.Length - charIndex < charCount)
- throw new ArgumentOutOfRangeException(nameof(chars), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ArgumentOutOfRange_Index);
-
- // If nothing to encode return 0, avoid fixed problem
- if (charCount == 0)
- return 0;
-
- // Just call pointer version
- int byteCount = bytes.Length - byteIndex;
-
- fixed (char* pChars = chars) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
- // Remember that byteCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetBytes(char* chars, int charCount, byte* bytes, int byteCount)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetBytes(chars, charCount, bytes, byteCount, null);
- }
-
- // Returns the number of characters produced by decoding a range of bytes
- // in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetCharCount(byte[] bytes, int index, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // If no input just return 0, fixed doesn't like 0 length arrays
- if (count == 0)
- return 0;
-
- // Just call pointer version
- fixed (byte* pBytes = bytes)
- return GetCharCount(pBytes + index, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetCharCount(byte* bytes, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (count < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetCharCount(bytes, count, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount,
- char[] chars, int charIndex)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (byteIndex < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(byteIndex < 0 ? nameof(byteIndex) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - byteIndex < byteCount)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- if (charIndex < 0 || charIndex > chars.Length)
- throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ArgumentOutOfRange_Index);
-
- // If no input, return 0 & avoid fixed problem
- if (byteCount == 0)
- return 0;
-
- // Just call pointer version
- int charCount = chars.Length - charIndex;
-
- fixed (byte* pBytes = bytes) fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
- // Remember that charCount is # to decode, not size of array
- return GetChars(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, null);
- }
-
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
-
- [CLSCompliant(false)]
- public override unsafe int GetChars(byte* bytes, int byteCount, char* chars, int charCount)
- {
- // Validate Parameters
- if (bytes == null || chars == null)
- throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), SR.ArgumentNull_Array);
-
- if (charCount < 0 || byteCount < 0)
- throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return GetChars(bytes, byteCount, chars, charCount, null);
- }
-
- // Returns a string containing the decoded representation of a range of
- // bytes in a byte array.
- //
- // All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
- // So if you fix this, fix the others. Currently those include:
- // EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
- // parent method is safe
-
- public override unsafe string GetString(byte[] bytes, int index, int count)
- {
- // Validate Parameters
- if (bytes == null)
- throw new ArgumentNullException(nameof(bytes), SR.ArgumentNull_Array);
-
- if (index < 0 || count < 0)
- throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (bytes.Length - index < count)
- throw new ArgumentOutOfRangeException(nameof(bytes), SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // Avoid problems with empty input buffer
- if (count == 0) return string.Empty;
-
- fixed (byte* pBytes = bytes)
- return string.CreateStringFromEncoding(
- pBytes + index, count, this);
- }
-
- //
- // End of standard methods copied from EncodingNLS.cs
- //
- internal sealed override unsafe int GetByteCount(char* chars, int count, EncoderNLS? encoder)
- {
- Debug.Assert(chars != null, "[UnicodeEncoding.GetByteCount]chars!=null");
- Debug.Assert(count >= 0, "[UnicodeEncoding.GetByteCount]count >=0");
-
- // Start by assuming each char gets 2 bytes
- int byteCount = count << 1;
-
- // Check for overflow in byteCount
- // (If they were all invalid chars, this would actually be wrong,
- // but that's a ridiculously large # so we're not concerned about that case)
- if (byteCount < 0)
- throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_GetByteCountOverflow);
-
- char* charStart = chars;
- char* charEnd = chars + count;
- char charLeftOver = (char)0;
-
- bool wasHereBefore = false;
-
- // For fallback we may need a fallback buffer
- EncoderFallbackBuffer? fallbackBuffer = null;
- char* charsForFallback;
-
- if (encoder != null)
- {
- charLeftOver = encoder._charLeftOver;
-
- // Assume extra bytes to encode charLeftOver if it existed
- if (charLeftOver > 0)
- byteCount += 2;
-
- // We mustn't have left over fallback data when counting
- if (encoder.InternalHasFallbackBuffer)
- {
- fallbackBuffer = encoder.FallbackBuffer;
- if (fallbackBuffer.Remaining > 0)
- throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty, this.EncodingName, encoder.Fallback?.GetType()));
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, false);
- }
- }
-
- char ch;
- TryAgain:
-
- while (((ch = (fallbackBuffer == null) ? (char)0 : fallbackBuffer.InternalGetNextChar()) != 0) || chars < charEnd)
- {
- // First unwind any fallback
- if (ch == 0)
- {
- // No fallback, maybe we can do it fast
-#if FASTLOOP
- // If endianess is backwards then each pair of bytes would be backwards.
- if ((bigEndian ^ BitConverter.IsLittleEndian) &&
-#if BIT64
- (unchecked((long)chars) & 7) == 0 &&
-#else
- (unchecked((int)chars) & 3) == 0 &&
-#endif
- charLeftOver == 0)
- {
- // Need -1 to check 2 at a time. If we have an even #, longChars will go
- // from longEnd - 1/2 long to longEnd + 1/2 long. If we're odd, longChars
- // will go from longEnd - 1 long to longEnd. (Might not get to use this)
- ulong* longEnd = (ulong*)(charEnd - 3);
-
- // Need new char* so we can check 4 at a time
- ulong* longChars = (ulong*)chars;
-
- while (longChars < longEnd)
- {
- // See if we potentially have surrogates (0x8000 bit set)
- // (We're either big endian on a big endian machine or little endian on
- // a little endian machine so that'll work)
- if ((0x8000800080008000 & *longChars) != 0)
- {
- // See if any of these are high or low surrogates (0xd800 - 0xdfff). If the high
- // 5 bits looks like 11011, then its a high or low surrogate.
- // We do the & f800 to filter the 5 bits, then ^ d800 to ensure the 0 isn't set.
- // Note that we expect BMP characters to be more common than surrogates
- // & each char with 11111... then ^ with 11011. Zeroes then indicate surrogates
- ulong uTemp = (0xf800f800f800f800 & *longChars) ^ 0xd800d800d800d800;
-
- // Check each of the 4 chars. 0 for those 16 bits means it was a surrogate
- // but no clue if they're high or low.
- // If each of the 4 characters are non-zero, then none are surrogates.
- if ((uTemp & 0xFFFF000000000000) == 0 ||
- (uTemp & 0x0000FFFF00000000) == 0 ||
- (uTemp & 0x00000000FFFF0000) == 0 ||
- (uTemp & 0x000000000000FFFF) == 0)
- {
- // It has at least 1 surrogate, but we don't know if they're high or low surrogates,
- // or if there's 1 or 4 surrogates
-
- // If they happen to be high/low/high/low, we may as well continue. Check the next
- // bit to see if its set (low) or not (high) in the right pattern
- if ((0xfc00fc00fc00fc00 & *longChars) !=
- (BitConverter.IsLittleEndian ? (ulong)0xdc00d800dc00d800 : (ulong)0xd800dc00d800dc00))
- {
- // Either there weren't 4 surrogates, or the 0x0400 bit was set when a high
- // was hoped for or the 0x0400 bit wasn't set where a low was hoped for.
-
- // Drop out to the slow loop to resolve the surrogates
- break;
- }
- // else they are all surrogates in High/Low/High/Low order, so we can use them.
- }
- // else none are surrogates, so we can use them.
- }
- // else all < 0x8000 so we can use them
-
- // We already counted these four chars, go to next long.
- longChars++;
- }
-
- chars = (char*)longChars;
-
- if (chars >= charEnd)
- break;
- }
-#endif // FASTLOOP
-
- // No fallback, just get next char
- ch = *chars;
- chars++;
- }
- else
- {
- // We weren't preallocating fallback space.
- byteCount += 2;
- }
-
- // Check for high or low surrogates
- if (ch >= 0xd800 && ch <= 0xdfff)
- {
- // Was it a high surrogate?
- if (ch <= 0xdbff)
- {
- // Its a high surrogate, if we already had a high surrogate do its fallback
- if (charLeftOver > 0)
- {
- // Unwind the current character, this should be safe because we
- // don't have leftover data in the fallback, so chars must have
- // advanced already.
- Debug.Assert(chars > charStart,
- "[UnicodeEncoding.GetByteCount]Expected chars to have advanced in unexpected high surrogate");
- chars--;
-
- // If previous high surrogate deallocate 2 bytes
- byteCount -= 2;
-
- // Fallback the previous surrogate
- // Need to initialize fallback buffer?
- if (fallbackBuffer == null)
- {
- if (encoder == null)
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = encoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, false);
- }
-
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be enregistered
- fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
- chars = charsForFallback;
-
- // Now no high surrogate left over
- charLeftOver = (char)0;
- continue;
- }
-
- // Remember this high surrogate
- charLeftOver = ch;
- continue;
- }
-
- // Its a low surrogate
- if (charLeftOver == 0)
- {
- // Expected a previous high surrogate.
- // Don't count this one (we'll count its fallback if necessary)
- byteCount -= 2;
-
- // fallback this one
- // Need to initialize fallback buffer?
- if (fallbackBuffer == null)
- {
- if (encoder == null)
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = encoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, false);
- }
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- fallbackBuffer.InternalFallback(ch, ref charsForFallback);
- chars = charsForFallback;
- continue;
- }
-
- // Valid surrogate pair, add our charLeftOver
- charLeftOver = (char)0;
- continue;
- }
- else if (charLeftOver > 0)
- {
- // Expected a low surrogate, but this char is normal
-
- // Rewind the current character, fallback previous character.
- // this should be safe because we don't have leftover data in the
- // fallback, so chars must have advanced already.
- Debug.Assert(chars > charStart,
- "[UnicodeEncoding.GetByteCount]Expected chars to have advanced when expected low surrogate");
- chars--;
-
- // fallback previous chars
- // Need to initialize fallback buffer?
- if (fallbackBuffer == null)
- {
- if (encoder == null)
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = encoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, false);
- }
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
- chars = charsForFallback;
-
- // Ignore charLeftOver or throw
- byteCount -= 2;
- charLeftOver = (char)0;
-
- continue;
- }
-
- // Ok we had something to add (already counted)
- }
-
- // Don't allocate space for left over char
- if (charLeftOver > 0)
- {
- byteCount -= 2;
-
- // If we have to flush, stick it in fallback and try again
- if (encoder == null || encoder.MustFlush)
- {
- if (wasHereBefore)
- {
- // Throw it, using our complete character
- throw new ArgumentException(
- SR.Format(SR.Argument_RecursiveFallback, charLeftOver), nameof(chars));
- }
- else
- {
- // Need to initialize fallback buffer?
- if (fallbackBuffer == null)
- {
- if (encoder == null)
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = encoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, false);
- }
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
- chars = charsForFallback;
- charLeftOver = (char)0;
- wasHereBefore = true;
- goto TryAgain;
- }
- }
- }
-
- // Shouldn't have anything in fallback buffer for GetByteCount
- // (don't have to check _throwOnOverflow for count)
- Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0,
- "[UnicodeEncoding.GetByteCount]Expected empty fallback buffer at end");
-
- // Don't remember fallbackBuffer.encoder for counting
- return byteCount;
- }
-
- internal sealed override unsafe int GetBytes(
- char* chars, int charCount, byte* bytes, int byteCount, EncoderNLS? encoder)
- {
- Debug.Assert(chars != null, "[UnicodeEncoding.GetBytes]chars!=null");
- Debug.Assert(byteCount >= 0, "[UnicodeEncoding.GetBytes]byteCount >=0");
- Debug.Assert(charCount >= 0, "[UnicodeEncoding.GetBytes]charCount >=0");
- Debug.Assert(bytes != null, "[UnicodeEncoding.GetBytes]bytes!=null");
-
- char charLeftOver = (char)0;
- char ch;
- bool wasHereBefore = false;
-
- byte* byteEnd = bytes + byteCount;
- char* charEnd = chars + charCount;
- byte* byteStart = bytes;
- char* charStart = chars;
-
- // For fallback we may need a fallback buffer
- EncoderFallbackBuffer? fallbackBuffer = null;
- char* charsForFallback;
-
- // Get our encoder, but don't clear it yet.
- if (encoder != null)
- {
- charLeftOver = encoder._charLeftOver;
-
- // We mustn't have left over fallback data when counting
- if (encoder.InternalHasFallbackBuffer)
- {
- // We always need the fallback buffer in get bytes so we can flush any remaining ones if necessary
- fallbackBuffer = encoder.FallbackBuffer;
- if (fallbackBuffer.Remaining > 0 && encoder._throwOnOverflow)
- throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty, this.EncodingName, encoder.Fallback?.GetType()));
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, false);
- }
- }
-
- TryAgain:
- while (((ch = (fallbackBuffer == null) ?
- (char)0 : fallbackBuffer.InternalGetNextChar()) != 0) ||
- chars < charEnd)
- {
- // First unwind any fallback
- if (ch == 0)
- {
- // No fallback, maybe we can do it fast
-#if FASTLOOP
- // If endianess is backwards then each pair of bytes would be backwards.
- if ((bigEndian ^ BitConverter.IsLittleEndian) &&
-#if BIT64
- (unchecked((long)chars) & 7) == 0 &&
-#else
- (unchecked((int)chars) & 3) == 0 &&
-#endif
- charLeftOver == 0)
- {
- // Need -1 to check 2 at a time. If we have an even #, longChars will go
- // from longEnd - 1/2 long to longEnd + 1/2 long. If we're odd, longChars
- // will go from longEnd - 1 long to longEnd. (Might not get to use this)
- // We can only go iCount units (limited by shorter of char or byte buffers.
- ulong* longEnd = (ulong*)(chars - 3 +
- (((byteEnd - bytes) >> 1 < charEnd - chars) ?
- (byteEnd - bytes) >> 1 : charEnd - chars));
-
- // Need new char* so we can check 4 at a time
- ulong* longChars = (ulong*)chars;
- ulong* longBytes = (ulong*)bytes;
-
- while (longChars < longEnd)
- {
- // See if we potentially have surrogates (0x8000 bit set)
- // (We're either big endian on a big endian machine or little endian on
- // a little endian machine so that'll work)
- if ((0x8000800080008000 & *longChars) != 0)
- {
- // See if any of these are high or low surrogates (0xd800 - 0xdfff). If the high
- // 5 bits looks like 11011, then its a high or low surrogate.
- // We do the & f800 to filter the 5 bits, then ^ d800 to ensure the 0 isn't set.
- // Note that we expect BMP characters to be more common than surrogates
- // & each char with 11111... then ^ with 11011. Zeroes then indicate surrogates
- ulong uTemp = (0xf800f800f800f800 & *longChars) ^ 0xd800d800d800d800;
-
- // Check each of the 4 chars. 0 for those 16 bits means it was a surrogate
- // but no clue if they're high or low.
- // If each of the 4 characters are non-zero, then none are surrogates.
- if ((uTemp & 0xFFFF000000000000) == 0 ||
- (uTemp & 0x0000FFFF00000000) == 0 ||
- (uTemp & 0x00000000FFFF0000) == 0 ||
- (uTemp & 0x000000000000FFFF) == 0)
- {
- // It has at least 1 surrogate, but we don't know if they're high or low surrogates,
- // or if there's 1 or 4 surrogates
-
- // If they happen to be high/low/high/low, we may as well continue. Check the next
- // bit to see if its set (low) or not (high) in the right pattern
- if ((0xfc00fc00fc00fc00 & *longChars) !=
- (BitConverter.IsLittleEndian ? (ulong)0xdc00d800dc00d800 : (ulong)0xd800dc00d800dc00))
- {
- // Either there weren't 4 surrogates, or the 0x0400 bit was set when a high
- // was hoped for or the 0x0400 bit wasn't set where a low was hoped for.
-
- // Drop out to the slow loop to resolve the surrogates
- break;
- }
- // else they are all surrogates in High/Low/High/Low order, so we can use them.
- }
- // else none are surrogates, so we can use them.
- }
- // else all < 0x8000 so we can use them
-
- // We can use these 4 chars.
- Unsafe.WriteUnaligned<ulong>(longBytes, *longChars);
- longChars++;
- longBytes++;
- }
-
- chars = (char*)longChars;
- bytes = (byte*)longBytes;
-
- if (chars >= charEnd)
- break;
- }
-#endif // FASTLOOP
-
- // No fallback, just get next char
- ch = *chars;
- chars++;
- }
-
- // Check for high or low surrogates
- if (ch >= 0xd800 && ch <= 0xdfff)
- {
- // Was it a high surrogate?
- if (ch <= 0xdbff)
- {
- // Its a high surrogate, see if we already had a high surrogate
- if (charLeftOver > 0)
- {
- // Unwind the current character, this should be safe because we
- // don't have leftover data in the fallback, so chars must have
- // advanced already.
- Debug.Assert(chars > charStart,
- "[UnicodeEncoding.GetBytes]Expected chars to have advanced in unexpected high surrogate");
- chars--;
-
- // Fallback the previous surrogate
- // Might need to create our fallback buffer
- if (fallbackBuffer == null)
- {
- if (encoder == null)
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = encoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, true);
- }
-
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
- chars = charsForFallback;
-
- charLeftOver = (char)0;
- continue;
- }
-
- // Remember this high surrogate
- charLeftOver = ch;
- continue;
- }
-
- // Its a low surrogate
- if (charLeftOver == 0)
- {
- // We'll fall back this one
- // Might need to create our fallback buffer
- if (fallbackBuffer == null)
- {
- if (encoder == null)
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = encoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, true);
- }
-
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- fallbackBuffer.InternalFallback(ch, ref charsForFallback);
- chars = charsForFallback;
- continue;
- }
-
- // Valid surrogate pair, add our charLeftOver
- if (bytes + 3 >= byteEnd)
- {
- // Not enough room to add this surrogate pair
- if (fallbackBuffer != null && fallbackBuffer.bFallingBack)
- {
- // These must have both been from the fallbacks.
- // Both of these MUST have been from a fallback because if the 1st wasn't
- // from a fallback, then a high surrogate followed by an illegal char
- // would've caused the high surrogate to fall back. If a high surrogate
- // fell back, then it was consumed and both chars came from the fallback.
- fallbackBuffer.MovePrevious(); // Didn't use either fallback surrogate
- fallbackBuffer.MovePrevious();
- }
- else
- {
- // If we don't have enough room, then either we should've advanced a while
- // or we should have bytes==byteStart and throw below
- Debug.Assert(chars > charStart + 1 || bytes == byteStart,
- "[UnicodeEncoding.GetBytes]Expected chars to have when no room to add surrogate pair");
- chars -= 2; // Didn't use either surrogate
- }
- ThrowBytesOverflow(encoder, bytes == byteStart); // Throw maybe (if no bytes written)
- charLeftOver = (char)0; // we'll retry it later
- break; // Didn't throw, but stop 'til next time.
- }
-
- if (bigEndian)
- {
- *(bytes++) = (byte)(charLeftOver >> 8);
- *(bytes++) = (byte)charLeftOver;
- }
- else
- {
- *(bytes++) = (byte)charLeftOver;
- *(bytes++) = (byte)(charLeftOver >> 8);
- }
-
- charLeftOver = (char)0;
- }
- else if (charLeftOver > 0)
- {
- // Expected a low surrogate, but this char is normal
-
- // Rewind the current character, fallback previous character.
- // this should be safe because we don't have leftover data in the
- // fallback, so chars must have advanced already.
- Debug.Assert(chars > charStart,
- "[UnicodeEncoding.GetBytes]Expected chars to have advanced after expecting low surrogate");
- chars--;
-
- // fallback previous chars
- // Might need to create our fallback buffer
- if (fallbackBuffer == null)
- {
- if (encoder == null)
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = encoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, true);
- }
-
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
- chars = charsForFallback;
-
- // Ignore charLeftOver or throw
- charLeftOver = (char)0;
- continue;
- }
-
- // Ok, we have a char to add
- if (bytes + 1 >= byteEnd)
- {
- // Couldn't add this char
- if (fallbackBuffer != null && fallbackBuffer.bFallingBack)
- fallbackBuffer.MovePrevious(); // Not using this fallback char
- else
- {
- // Lonely charLeftOver (from previous call) would've been caught up above,
- // so this must be a case where we've already read an input char.
- Debug.Assert(chars > charStart,
- "[UnicodeEncoding.GetBytes]Expected chars to have advanced for failed fallback");
- chars--; // Not using this char
- }
- ThrowBytesOverflow(encoder, bytes == byteStart); // Throw maybe (if no bytes written)
- break; // didn't throw, just stop
- }
-
- if (bigEndian)
- {
- *(bytes++) = (byte)(ch >> 8);
- *(bytes++) = (byte)ch;
- }
- else
- {
- *(bytes++) = (byte)ch;
- *(bytes++) = (byte)(ch >> 8);
- }
- }
-
- // Don't allocate space for left over char
- if (charLeftOver > 0)
- {
- // If we aren't flushing we need to fall this back
- if (encoder == null || encoder.MustFlush)
- {
- if (wasHereBefore)
- {
- // Throw it, using our complete character
- throw new ArgumentException(
- SR.Format(SR.Argument_RecursiveFallback, charLeftOver), nameof(chars));
- }
- else
- {
- // If we have to flush, stick it in fallback and try again
- // Might need to create our fallback buffer
- if (fallbackBuffer == null)
- {
- if (encoder == null)
- fallbackBuffer = this.encoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = encoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(charStart, charEnd, encoder, true);
- }
-
- // If we're not flushing, that'll remember the left over character.
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- fallbackBuffer.InternalFallback(charLeftOver, ref charsForFallback);
- chars = charsForFallback;
-
- charLeftOver = (char)0;
- wasHereBefore = true;
- goto TryAgain;
- }
- }
- }
-
- // Not flushing, remember it in the encoder
- if (encoder != null)
- {
- encoder._charLeftOver = charLeftOver;
- encoder._charsUsed = (int)(chars - charStart);
- }
-
- // Remember charLeftOver if we must, or clear it if we're flushing
- // (charLeftOver should be 0 if we're flushing)
- Debug.Assert((encoder != null && !encoder.MustFlush) || charLeftOver == (char)0,
- "[UnicodeEncoding.GetBytes] Expected no left over characters if flushing");
-
- Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0 ||
- encoder == null || !encoder._throwOnOverflow,
- "[UnicodeEncoding.GetBytes]Expected empty fallback buffer if not converting");
-
- return (int)(bytes - byteStart);
- }
-
- internal sealed override unsafe int GetCharCount(byte* bytes, int count, DecoderNLS? baseDecoder)
- {
- Debug.Assert(bytes != null, "[UnicodeEncoding.GetCharCount]bytes!=null");
- Debug.Assert(count >= 0, "[UnicodeEncoding.GetCharCount]count >=0");
-
- UnicodeEncoding.Decoder? decoder = (UnicodeEncoding.Decoder?)baseDecoder;
-
- byte* byteEnd = bytes + count;
- byte* byteStart = bytes;
-
- // Need last vars
- int lastByte = -1;
- char lastChar = (char)0;
-
- // Start by assuming same # of chars as bytes
- int charCount = count >> 1;
-
- // For fallback we may need a fallback buffer
- DecoderFallbackBuffer? fallbackBuffer = null;
-
- if (decoder != null)
- {
- lastByte = decoder.lastByte;
- lastChar = decoder.lastChar;
-
- // Assume extra char if last char was around
- if (lastChar > 0)
- charCount++;
-
- // Assume extra char if extra last byte makes up odd # of input bytes
- if (lastByte >= 0 && (count & 1) == 1)
- {
- charCount++;
- }
-
- // Shouldn't have anything in fallback buffer for GetCharCount
- // (don't have to check _throwOnOverflow for count)
- Debug.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0,
- "[UnicodeEncoding.GetCharCount]Expected empty fallback buffer at start");
- }
-
- while (bytes < byteEnd)
- {
- // If we're aligned then maybe we can do it fast
- // That'll hurt if we're unaligned because we'll always test but never be aligned
-#if FASTLOOP
- if ((bigEndian ^ BitConverter.IsLittleEndian) &&
-#if BIT64
- (unchecked((long)bytes) & 7) == 0 &&
-#else
- (unchecked((int)bytes) & 3) == 0 &&
-#endif // BIT64
- lastByte == -1 && lastChar == 0)
- {
- // Need -1 to check 2 at a time. If we have an even #, longBytes will go
- // from longEnd - 1/2 long to longEnd + 1/2 long. If we're odd, longBytes
- // will go from longEnd - 1 long to longEnd. (Might not get to use this)
- ulong* longEnd = (ulong*)(byteEnd - 7);
-
- // Need new char* so we can check 4 at a time
- ulong* longBytes = (ulong*)bytes;
-
- while (longBytes < longEnd)
- {
- // See if we potentially have surrogates (0x8000 bit set)
- // (We're either big endian on a big endian machine or little endian on
- // a little endian machine so that'll work)
- if ((0x8000800080008000 & *longBytes) != 0)
- {
- // See if any of these are high or low surrogates (0xd800 - 0xdfff). If the high
- // 5 bits looks like 11011, then its a high or low surrogate.
- // We do the & f800 to filter the 5 bits, then ^ d800 to ensure the 0 isn't set.
- // Note that we expect BMP characters to be more common than surrogates
- // & each char with 11111... then ^ with 11011. Zeroes then indicate surrogates
- ulong uTemp = (0xf800f800f800f800 & *longBytes) ^ 0xd800d800d800d800;
-
- // Check each of the 4 chars. 0 for those 16 bits means it was a surrogate
- // but no clue if they're high or low.
- // If each of the 4 characters are non-zero, then none are surrogates.
- if ((uTemp & 0xFFFF000000000000) == 0 ||
- (uTemp & 0x0000FFFF00000000) == 0 ||
- (uTemp & 0x00000000FFFF0000) == 0 ||
- (uTemp & 0x000000000000FFFF) == 0)
- {
- // It has at least 1 surrogate, but we don't know if they're high or low surrogates,
- // or if there's 1 or 4 surrogates
-
- // If they happen to be high/low/high/low, we may as well continue. Check the next
- // bit to see if its set (low) or not (high) in the right pattern
- if ((0xfc00fc00fc00fc00 & *longBytes) !=
- (BitConverter.IsLittleEndian ? (ulong)0xdc00d800dc00d800 : (ulong)0xd800dc00d800dc00))
- {
- // Either there weren't 4 surrogates, or the 0x0400 bit was set when a high
- // was hoped for or the 0x0400 bit wasn't set where a low was hoped for.
-
- // Drop out to the slow loop to resolve the surrogates
- break;
- }
- // else they are all surrogates in High/Low/High/Low order, so we can use them.
- }
- // else none are surrogates, so we can use them.
- }
- // else all < 0x8000 so we can use them
-
- // We can use these 4 chars.
- longBytes++;
- }
-
- bytes = (byte*)longBytes;
-
- if (bytes >= byteEnd)
- break;
- }
-#endif // FASTLOOP
-
- // Get 1st byte
- if (lastByte < 0)
- {
- lastByte = *bytes++;
- if (bytes >= byteEnd) break;
- }
-
- // Get full char
- char ch;
- if (bigEndian)
- {
- ch = (char)(lastByte << 8 | *(bytes++));
- }
- else
- {
- ch = (char)(*(bytes++) << 8 | lastByte);
- }
- lastByte = -1;
-
- // See if the char's valid
- if (ch >= 0xd800 && ch <= 0xdfff)
- {
- // Was it a high surrogate?
- if (ch <= 0xdbff)
- {
- // Its a high surrogate, if we had one then do fallback for previous one
- if (lastChar > 0)
- {
- // Ignore previous bad high surrogate
- charCount--;
-
- // Get fallback for previous high surrogate
- // Note we have to reconstruct bytes because some may have been in decoder
- byte[]? byteBuffer = null;
- if (bigEndian)
- {
- byteBuffer = new byte[]
- { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) };
- }
- else
- {
- byteBuffer = new byte[]
- { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) };
- }
-
- if (fallbackBuffer == null)
- {
- if (decoder == null)
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = decoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(byteStart, null);
- }
-
- // Get fallback.
- charCount += fallbackBuffer.InternalFallback(byteBuffer, bytes);
- }
-
- // Ignore the last one which fell back already,
- // and remember the new high surrogate
- lastChar = ch;
- continue;
- }
-
- // Its a low surrogate
- if (lastChar == 0)
- {
- // Expected a previous high surrogate
- charCount--;
-
- // Get fallback for this low surrogate
- // Note we have to reconstruct bytes because some may have been in decoder
- byte[]? byteBuffer = null;
- if (bigEndian)
- {
- byteBuffer = new byte[]
- { unchecked((byte)(ch >> 8)), unchecked((byte)ch) };
- }
- else
- {
- byteBuffer = new byte[]
- { unchecked((byte)ch), unchecked((byte)(ch >> 8)) };
- }
-
- if (fallbackBuffer == null)
- {
- if (decoder == null)
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = decoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(byteStart, null);
- }
-
- charCount += fallbackBuffer.InternalFallback(byteBuffer, bytes);
-
- // Ignore this one (we already did its fallback)
- continue;
- }
-
- // Valid surrogate pair, already counted.
- lastChar = (char)0;
- }
- else if (lastChar > 0)
- {
- // Had a high surrogate, expected a low surrogate
- // Un-count the last high surrogate
- charCount--;
-
- // fall back the high surrogate.
- byte[]? byteBuffer = null;
- if (bigEndian)
- {
- byteBuffer = new byte[]
- { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) };
- }
- else
- {
- byteBuffer = new byte[]
- { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) };
- }
-
- if (fallbackBuffer == null)
- {
- if (decoder == null)
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = decoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(byteStart, null);
- }
-
- // Already subtracted high surrogate
- charCount += fallbackBuffer.InternalFallback(byteBuffer, bytes);
-
- // Not left over now, clear previous high surrogate and continue to add current char
- lastChar = (char)0;
- }
-
- // Valid char, already counted
- }
-
- // Extra space if we can't use decoder
- if (decoder == null || decoder.MustFlush)
- {
- if (lastChar > 0)
- {
- // No hanging high surrogates allowed, do fallback and remove count for it
- charCount--;
- byte[]? byteBuffer = null;
- if (bigEndian)
- {
- byteBuffer = new byte[]
- { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) };
- }
- else
- {
- byteBuffer = new byte[]
- { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) };
- }
-
- if (fallbackBuffer == null)
- {
- if (decoder == null)
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = decoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(byteStart, null);
- }
-
- charCount += fallbackBuffer.InternalFallback(byteBuffer, bytes);
-
- lastChar = (char)0;
- }
-
- if (lastByte >= 0)
- {
- if (fallbackBuffer == null)
- {
- if (decoder == null)
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = decoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(byteStart, null);
- }
-
- // No hanging odd bytes allowed if must flush
- charCount += fallbackBuffer.InternalFallback(new byte[] { unchecked((byte)lastByte) }, bytes);
- lastByte = -1;
- }
- }
-
- // If we had a high surrogate left over, we can't count it
- if (lastChar > 0)
- charCount--;
-
- // Shouldn't have anything in fallback buffer for GetCharCount
- // (don't have to check _throwOnOverflow for count)
- Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0,
- "[UnicodeEncoding.GetCharCount]Expected empty fallback buffer at end");
-
- return charCount;
- }
-
- internal sealed override unsafe int GetChars(
- byte* bytes, int byteCount, char* chars, int charCount, DecoderNLS? baseDecoder)
- {
- Debug.Assert(chars != null, "[UnicodeEncoding.GetChars]chars!=null");
- Debug.Assert(byteCount >= 0, "[UnicodeEncoding.GetChars]byteCount >=0");
- Debug.Assert(charCount >= 0, "[UnicodeEncoding.GetChars]charCount >=0");
- Debug.Assert(bytes != null, "[UnicodeEncoding.GetChars]bytes!=null");
-
- UnicodeEncoding.Decoder? decoder = (UnicodeEncoding.Decoder?)baseDecoder;
-
- // Need last vars
- int lastByte = -1;
- char lastChar = (char)0;
-
- // Get our decoder (but don't clear it yet)
- if (decoder != null)
- {
- lastByte = decoder.lastByte;
- lastChar = decoder.lastChar;
-
- // Shouldn't have anything in fallback buffer for GetChars
- // (don't have to check _throwOnOverflow for chars)
- Debug.Assert(!decoder.InternalHasFallbackBuffer || decoder.FallbackBuffer.Remaining == 0,
- "[UnicodeEncoding.GetChars]Expected empty fallback buffer at start");
- }
-
- // For fallback we may need a fallback buffer
- DecoderFallbackBuffer? fallbackBuffer = null;
- char* charsForFallback;
-
- byte* byteEnd = bytes + byteCount;
- char* charEnd = chars + charCount;
- byte* byteStart = bytes;
- char* charStart = chars;
-
- while (bytes < byteEnd)
- {
- // If we're aligned then maybe we can do it fast
- // That'll hurt if we're unaligned because we'll always test but never be aligned
-#if FASTLOOP
- if ((bigEndian ^ BitConverter.IsLittleEndian) &&
-#if BIT64
- (unchecked((long)chars) & 7) == 0 &&
-#else
- (unchecked((int)chars) & 3) == 0 &&
-#endif
- lastByte == -1 && lastChar == 0)
- {
- // Need -1 to check 2 at a time. If we have an even #, longChars will go
- // from longEnd - 1/2 long to longEnd + 1/2 long. If we're odd, longChars
- // will go from longEnd - 1 long to longEnd. (Might not get to use this)
- // We can only go iCount units (limited by shorter of char or byte buffers.
- ulong* longEnd = (ulong*)(bytes - 7 +
- (((byteEnd - bytes) >> 1 < charEnd - chars) ?
- (byteEnd - bytes) : (charEnd - chars) << 1));
-
- // Need new char* so we can check 4 at a time
- ulong* longBytes = (ulong*)bytes;
- ulong* longChars = (ulong*)chars;
-
- while (longBytes < longEnd)
- {
- // See if we potentially have surrogates (0x8000 bit set)
- // (We're either big endian on a big endian machine or little endian on
- // a little endian machine so that'll work)
- if ((0x8000800080008000 & *longBytes) != 0)
- {
- // See if any of these are high or low surrogates (0xd800 - 0xdfff). If the high
- // 5 bits looks like 11011, then its a high or low surrogate.
- // We do the & f800 to filter the 5 bits, then ^ d800 to ensure the 0 isn't set.
- // Note that we expect BMP characters to be more common than surrogates
- // & each char with 11111... then ^ with 11011. Zeroes then indicate surrogates
- ulong uTemp = (0xf800f800f800f800 & *longBytes) ^ 0xd800d800d800d800;
-
- // Check each of the 4 chars. 0 for those 16 bits means it was a surrogate
- // but no clue if they're high or low.
- // If each of the 4 characters are non-zero, then none are surrogates.
- if ((uTemp & 0xFFFF000000000000) == 0 ||
- (uTemp & 0x0000FFFF00000000) == 0 ||
- (uTemp & 0x00000000FFFF0000) == 0 ||
- (uTemp & 0x000000000000FFFF) == 0)
- {
- // It has at least 1 surrogate, but we don't know if they're high or low surrogates,
- // or if there's 1 or 4 surrogates
-
- // If they happen to be high/low/high/low, we may as well continue. Check the next
- // bit to see if its set (low) or not (high) in the right pattern
- if ((0xfc00fc00fc00fc00 & *longBytes) !=
- (BitConverter.IsLittleEndian ? (ulong)0xdc00d800dc00d800 : (ulong)0xd800dc00d800dc00))
- {
- // Either there weren't 4 surrogates, or the 0x0400 bit was set when a high
- // was hoped for or the 0x0400 bit wasn't set where a low was hoped for.
-
- // Drop out to the slow loop to resolve the surrogates
- break;
- }
- // else they are all surrogates in High/Low/High/Low order, so we can use them.
- }
- // else none are surrogates, so we can use them.
- }
- // else all < 0x8000 so we can use them
-
- // We can use these 4 chars.
- Unsafe.WriteUnaligned<ulong>(longChars, *longBytes);
- longBytes++;
- longChars++;
- }
-
- chars = (char*)longChars;
- bytes = (byte*)longBytes;
-
- if (bytes >= byteEnd)
- break;
- }
-#endif // FASTLOOP
-
- // Get 1st byte
- if (lastByte < 0)
- {
- lastByte = *bytes++;
- continue;
- }
-
- // Get full char
- char ch;
- if (bigEndian)
- {
- ch = (char)(lastByte << 8 | *(bytes++));
- }
- else
- {
- ch = (char)(*(bytes++) << 8 | lastByte);
- }
- lastByte = -1;
-
- // See if the char's valid
- if (ch >= 0xd800 && ch <= 0xdfff)
- {
- // Was it a high surrogate?
- if (ch <= 0xdbff)
- {
- // Its a high surrogate, if we had one then do fallback for previous one
- if (lastChar > 0)
- {
- // Get fallback for previous high surrogate
- // Note we have to reconstruct bytes because some may have been in decoder
- byte[]? byteBuffer = null;
- if (bigEndian)
- {
- byteBuffer = new byte[]
- { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) };
- }
- else
- {
- byteBuffer = new byte[]
- { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) };
- }
-
- if (fallbackBuffer == null)
- {
- if (decoder == null)
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = decoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(byteStart, charEnd);
- }
-
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- bool fallbackResult = fallbackBuffer.InternalFallback(byteBuffer, bytes, ref charsForFallback);
- chars = charsForFallback;
-
- if (!fallbackResult)
- {
- // couldn't fall back lonely surrogate
- // We either advanced bytes or chars should == charStart and throw below
- Debug.Assert(bytes >= byteStart + 2 || chars == charStart,
- "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (bad surrogate)");
- bytes -= 2; // didn't use these 2 bytes
- fallbackBuffer.InternalReset();
- ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output
- break; // couldn't fallback but didn't throw
- }
- }
-
- // Ignore the previous high surrogate which fell back already,
- // yet remember the current high surrogate for next time.
- lastChar = ch;
- continue;
- }
-
- // Its a low surrogate
- if (lastChar == 0)
- {
- // Expected a previous high surrogate
- // Get fallback for this low surrogate
- // Note we have to reconstruct bytes because some may have been in decoder
- byte[]? byteBuffer = null;
- if (bigEndian)
- {
- byteBuffer = new byte[]
- { unchecked((byte)(ch >> 8)), unchecked((byte)ch) };
- }
- else
- {
- byteBuffer = new byte[]
- { unchecked((byte)ch), unchecked((byte)(ch >> 8)) };
- }
-
- if (fallbackBuffer == null)
- {
- if (decoder == null)
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = decoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(byteStart, charEnd);
- }
-
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- bool fallbackResult = fallbackBuffer.InternalFallback(byteBuffer, bytes, ref charsForFallback);
- chars = charsForFallback;
-
- if (!fallbackResult)
- {
- // couldn't fall back lonely surrogate
- // We either advanced bytes or chars should == charStart and throw below
- Debug.Assert(bytes >= byteStart + 2 || chars == charStart,
- "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (lonely surrogate)");
- bytes -= 2; // didn't use these 2 bytes
- fallbackBuffer.InternalReset();
- ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output
- break; // couldn't fallback but didn't throw
- }
-
- // Didn't throw, ignore this one (we already did its fallback)
- continue;
- }
-
- // Valid surrogate pair, add our lastChar (will need 2 chars)
- if (chars >= charEnd - 1)
- {
- // couldn't find room for this surrogate pair
- // We either advanced bytes or chars should == charStart and throw below
- Debug.Assert(bytes >= byteStart + 2 || chars == charStart,
- "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (surrogate pair)");
- bytes -= 2; // didn't use these 2 bytes
- ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output
- // Leave lastChar for next call to Convert()
- break; // couldn't fallback but didn't throw
- }
-
- *chars++ = lastChar;
- lastChar = (char)0;
- }
- else if (lastChar > 0)
- {
- // Had a high surrogate, expected a low surrogate, fall back the high surrogate.
- byte[]? byteBuffer = null;
- if (bigEndian)
- {
- byteBuffer = new byte[]
- { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) };
- }
- else
- {
- byteBuffer = new byte[]
- { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) };
- }
-
- if (fallbackBuffer == null)
- {
- if (decoder == null)
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = decoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(byteStart, charEnd);
- }
-
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- bool fallbackResult = fallbackBuffer.InternalFallback(byteBuffer, bytes, ref charsForFallback);
- chars = charsForFallback;
-
- if (!fallbackResult)
- {
- // couldn't fall back high surrogate, or char that would be next
- // We either advanced bytes or chars should == charStart and throw below
- Debug.Assert(bytes >= byteStart + 2 || chars == charStart,
- "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (no low surrogate)");
- bytes -= 2; // didn't use these 2 bytes
- fallbackBuffer.InternalReset();
- ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output
- break; // couldn't fallback but didn't throw
- }
-
- // Not left over now, clear previous high surrogate and continue to add current char
- lastChar = (char)0;
- }
-
- // Valid char, room for it?
- if (chars >= charEnd)
- {
- // 2 bytes couldn't fall back
- // We either advanced bytes or chars should == charStart and throw below
- Debug.Assert(bytes >= byteStart + 2 || chars == charStart,
- "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (normal)");
- bytes -= 2; // didn't use these bytes
- ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output
- break; // couldn't fallback but didn't throw
- }
-
- // add it
- *chars++ = ch;
- }
-
- // Remember our decoder if we must
- if (decoder == null || decoder.MustFlush)
- {
- if (lastChar > 0)
- {
- // No hanging high surrogates allowed, do fallback and remove count for it
- byte[]? byteBuffer = null;
- if (bigEndian)
- {
- byteBuffer = new byte[]
- { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) };
- }
- else
- {
- byteBuffer = new byte[]
- { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) };
- }
-
- if (fallbackBuffer == null)
- {
- if (decoder == null)
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = decoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(byteStart, charEnd);
- }
-
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- bool fallbackResult = fallbackBuffer.InternalFallback(byteBuffer, bytes, ref charsForFallback);
- chars = charsForFallback;
-
- if (!fallbackResult)
- {
- // 2 bytes couldn't fall back
- // We either advanced bytes or chars should == charStart and throw below
- Debug.Assert(bytes >= byteStart + 2 || chars == charStart,
- "[UnicodeEncoding.GetChars]Expected bytes to have advanced or no output (decoder)");
- bytes -= 2; // didn't use these bytes
- if (lastByte >= 0)
- bytes--; // had an extra last byte hanging around
- fallbackBuffer.InternalReset();
- ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output
- // We'll remember these in our decoder though
- bytes += 2;
- if (lastByte >= 0)
- bytes++;
- goto End;
- }
-
- // done with this one
- lastChar = (char)0;
- }
-
- if (lastByte >= 0)
- {
- if (fallbackBuffer == null)
- {
- if (decoder == null)
- fallbackBuffer = this.decoderFallback.CreateFallbackBuffer();
- else
- fallbackBuffer = decoder.FallbackBuffer;
-
- // Set our internal fallback interesting things.
- fallbackBuffer.InternalInitialize(byteStart, charEnd);
- }
-
- // No hanging odd bytes allowed if must flush
- charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered
- bool fallbackResult = fallbackBuffer.InternalFallback(new byte[] { unchecked((byte)lastByte) }, bytes, ref charsForFallback);
- chars = charsForFallback;
-
- if (!fallbackResult)
- {
- // odd byte couldn't fall back
- bytes--; // didn't use this byte
- fallbackBuffer.InternalReset();
- ThrowCharsOverflow(decoder, chars == charStart); // Might throw, if no chars output
- // didn't throw, but we'll remember it in the decoder
- bytes++;
- goto End;
- }
-
- // Didn't fail, clear buffer
- lastByte = -1;
- }
- }
-
- End:
-
- // Remember our decoder if we must
- if (decoder != null)
- {
- Debug.Assert(!decoder.MustFlush || ((lastChar == (char)0) && (lastByte == -1)),
- "[UnicodeEncoding.GetChars] Expected no left over chars or bytes if flushing"
- // + " " + ((int)lastChar).ToString("X4") + " " + lastByte.ToString("X2")
- );
-
- decoder._bytesUsed = (int)(bytes - byteStart);
- decoder.lastChar = lastChar;
- decoder.lastByte = lastByte;
- }
-
- // Shouldn't have anything in fallback buffer for GetChars
- // (don't have to check _throwOnOverflow for count or chars)
- Debug.Assert(fallbackBuffer == null || fallbackBuffer.Remaining == 0,
- "[UnicodeEncoding.GetChars]Expected empty fallback buffer at end");
-
- return (int)(chars - charStart);
- }
-
- public override System.Text.Encoder GetEncoder()
- {
- return new EncoderNLS(this);
- }
-
- public override System.Text.Decoder GetDecoder()
- {
- return new UnicodeEncoding.Decoder(this);
- }
-
- public override byte[] GetPreamble()
- {
- if (byteOrderMark)
- {
- // Note - we must allocate new byte[]'s here to prevent someone
- // from modifying a cached byte[].
- if (bigEndian)
- return new byte[2] { 0xfe, 0xff };
- else
- return new byte[2] { 0xff, 0xfe };
- }
- return Array.Empty<byte>();
- }
-
- public override ReadOnlySpan<byte> Preamble =>
- GetType() != typeof(UnicodeEncoding) ? new ReadOnlySpan<byte>(GetPreamble()) : // in case a derived UnicodeEncoding overrode GetPreamble
- !byteOrderMark ? default :
- bigEndian ? (ReadOnlySpan<byte>)new byte[2] { 0xfe, 0xff } : // uses C# compiler's optimization for static byte[] data
- (ReadOnlySpan<byte>)new byte[2] { 0xff, 0xfe };
-
- public override int GetMaxByteCount(int charCount)
- {
- if (charCount < 0)
- throw new ArgumentOutOfRangeException(nameof(charCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // Characters would be # of characters + 1 in case left over high surrogate is ? * max fallback
- long byteCount = (long)charCount + 1;
-
- if (EncoderFallback.MaxCharCount > 1)
- byteCount *= EncoderFallback.MaxCharCount;
-
- // 2 bytes per char
- byteCount <<= 1;
-
- if (byteCount > 0x7fffffff)
- throw new ArgumentOutOfRangeException(nameof(charCount), SR.ArgumentOutOfRange_GetByteCountOverflow);
-
- return (int)byteCount;
- }
-
- public override int GetMaxCharCount(int byteCount)
- {
- if (byteCount < 0)
- throw new ArgumentOutOfRangeException(nameof(byteCount),
- SR.ArgumentOutOfRange_NeedNonNegNum);
-
- // long because byteCount could be biggest int.
- // 1 char per 2 bytes. Round up in case 1 left over in decoder.
- // Round up using &1 in case byteCount is max size
- // Might also need an extra 1 if there's a left over high surrogate in the decoder.
- long charCount = (long)(byteCount >> 1) + (byteCount & 1) + 1;
-
- // Don't forget fallback (in case they have a bunch of lonely surrogates or something bizarre like that)
- if (DecoderFallback.MaxCharCount > 1)
- charCount *= DecoderFallback.MaxCharCount;
-
- if (charCount > 0x7fffffff)
- throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ArgumentOutOfRange_GetCharCountOverflow);
-
- return (int)charCount;
- }
-
- public override bool Equals(object? value)
- {
- if (value is UnicodeEncoding that)
- {
- //
- // Big Endian Unicode has different code page (1201) than small Endian one (1200),
- // so we still have to check _codePage here.
- //
- return (CodePage == that.CodePage) &&
- byteOrderMark == that.byteOrderMark &&
- // isThrowException == that.isThrowException && // Same as Encoder/Decoder being exception fallbacks
- bigEndian == that.bigEndian &&
- (EncoderFallback.Equals(that.EncoderFallback)) &&
- (DecoderFallback.Equals(that.DecoderFallback));
- }
- return false;
- }
-
- public override int GetHashCode()
- {
- return CodePage + this.EncoderFallback.GetHashCode() + this.DecoderFallback.GetHashCode() +
- (byteOrderMark ? 4 : 0) + (bigEndian ? 8 : 0);
- }
-
- private sealed class Decoder : System.Text.DecoderNLS
- {
- internal int lastByte = -1;
- internal char lastChar = '\0';
-
- public Decoder(UnicodeEncoding encoding) : base(encoding)
- {
- // base calls reset
- }
-
- public override void Reset()
- {
- lastByte = -1;
- lastChar = '\0';
- if (_fallbackBuffer != null)
- _fallbackBuffer.Reset();
- }
-
- // Anything left in our decoder?
- internal override bool HasState => this.lastByte != -1 || this.lastChar != '\0';
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/UnicodeUtility.cs b/netcore/System.Private.CoreLib/shared/System/Text/UnicodeUtility.cs
deleted file mode 100644
index e53e1c0d66b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/UnicodeUtility.cs
+++ /dev/null
@@ -1,186 +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 System.Runtime.CompilerServices;
-
-namespace System.Text
-{
- internal static class UnicodeUtility
- {
- /// <summary>
- /// The Unicode replacement character U+FFFD.
- /// </summary>
- public const uint ReplacementChar = 0xFFFD;
-
- /// <summary>
- /// Returns the Unicode plane (0 through 16, inclusive) which contains this code point.
- /// </summary>
- public static int GetPlane(uint codePoint)
- {
- UnicodeDebug.AssertIsValidCodePoint(codePoint);
-
- return (int)(codePoint >> 16);
- }
-
- /// <summary>
- /// Returns a Unicode scalar value from two code points representing a UTF-16 surrogate pair.
- /// </summary>
- public static uint GetScalarFromUtf16SurrogatePair(uint highSurrogateCodePoint, uint lowSurrogateCodePoint)
- {
- UnicodeDebug.AssertIsHighSurrogateCodePoint(highSurrogateCodePoint);
- UnicodeDebug.AssertIsLowSurrogateCodePoint(lowSurrogateCodePoint);
-
- // This calculation comes from the Unicode specification, Table 3-5.
- // Need to remove the D800 marker from the high surrogate and the DC00 marker from the low surrogate,
- // then fix up the "wwww = uuuuu - 1" section of the bit distribution. The code is written as below
- // to become just two instructions: shl, lea.
-
- return (highSurrogateCodePoint << 10) + lowSurrogateCodePoint - ((0xD800U << 10) + 0xDC00U - (1 << 16));
- }
-
- /// <summary>
- /// Given a Unicode scalar value, gets the number of UTF-16 code units required to represent this value.
- /// </summary>
- public static int GetUtf16SequenceLength(uint value)
- {
- UnicodeDebug.AssertIsValidScalar(value);
-
- value -= 0x10000; // if value < 0x10000, high byte = 0xFF; else high byte = 0x00
- value += (2 << 24); // if value < 0x10000, high byte = 0x01; else high byte = 0x02
- value >>= 24; // shift high byte down
- return (int)value; // and return it
- }
-
- /// <summary>
- /// Decomposes an astral Unicode scalar into UTF-16 high and low surrogate code units.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void GetUtf16SurrogatesFromSupplementaryPlaneScalar(uint value, out char highSurrogateCodePoint, out char lowSurrogateCodePoint)
- {
- UnicodeDebug.AssertIsValidSupplementaryPlaneScalar(value);
-
- // This calculation comes from the Unicode specification, Table 3-5.
-
- highSurrogateCodePoint = (char)((value + ((0xD800u - 0x40u) << 10)) >> 10);
- lowSurrogateCodePoint = (char)((value & 0x3FFu) + 0xDC00u);
- }
-
- /// <summary>
- /// Given a Unicode scalar value, gets the number of UTF-8 code units required to represent this value.
- /// </summary>
- public static int GetUtf8SequenceLength(uint value)
- {
- UnicodeDebug.AssertIsValidScalar(value);
-
- // The logic below can handle all valid scalar values branchlessly.
- // It gives generally good performance across all inputs, and on x86
- // it's only six instructions: lea, sar, xor, add, shr, lea.
-
- // 'a' will be -1 if input is < 0x800; else 'a' will be 0
- // => 'a' will be -1 if input is 1 or 2 UTF-8 code units; else 'a' will be 0
-
- int a = ((int)value - 0x0800) >> 31;
-
- // The number of UTF-8 code units for a given scalar is as follows:
- // - U+0000..U+007F => 1 code unit
- // - U+0080..U+07FF => 2 code units
- // - U+0800..U+FFFF => 3 code units
- // - U+10000+ => 4 code units
- //
- // If we XOR the incoming scalar with 0xF800, the chart mutates:
- // - U+0000..U+F7FF => 3 code units
- // - U+F800..U+F87F => 1 code unit
- // - U+F880..U+FFFF => 2 code units
- // - U+10000+ => 4 code units
- //
- // Since the 1- and 3-code unit cases are now clustered, they can
- // both be checked together very cheaply.
-
- value ^= 0xF800u;
- value -= 0xF880u; // if scalar is 1 or 3 code units, high byte = 0xFF; else high byte = 0x00
- value += (4 << 24); // if scalar is 1 or 3 code units, high byte = 0x03; else high byte = 0x04
- value >>= 24; // shift high byte down
-
- // Final return value:
- // - U+0000..U+007F => 3 + (-1) * 2 = 1
- // - U+0080..U+07FF => 4 + (-1) * 2 = 2
- // - U+0800..U+FFFF => 3 + ( 0) * 2 = 3
- // - U+10000+ => 4 + ( 0) * 2 = 4
- return (int)value + (a * 2);
- }
-
- /// <summary>
- /// Returns <see langword="true"/> iff <paramref name="value"/> is an ASCII
- /// character ([ U+0000..U+007F ]).
- /// </summary>
- /// <remarks>
- /// Per http://www.unicode.org/glossary/#ASCII, ASCII is only U+0000..U+007F.
- /// </remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsAsciiCodePoint(uint value) => value <= 0x7Fu;
-
- /// <summary>
- /// Returns <see langword="true"/> iff <paramref name="value"/> is in the
- /// Basic Multilingual Plane (BMP).
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsBmpCodePoint(uint value) => value <= 0xFFFFu;
-
- /// <summary>
- /// Returns <see langword="true"/> iff <paramref name="value"/> is a UTF-16 high surrogate code point,
- /// i.e., is in [ U+D800..U+DBFF ], inclusive.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsHighSurrogateCodePoint(uint value) => IsInRangeInclusive(value, 0xD800U, 0xDBFFU);
-
- /// <summary>
- /// Returns <see langword="true"/> iff <paramref name="value"/> is between
- /// <paramref name="lowerBound"/> and <paramref name="upperBound"/>, inclusive.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsInRangeInclusive(uint value, uint lowerBound, uint upperBound) => (value - lowerBound) <= (upperBound - lowerBound);
-
- /// <summary>
- /// Returns <see langword="true"/> iff <paramref name="value"/> is a UTF-16 low surrogate code point,
- /// i.e., is in [ U+DC00..U+DFFF ], inclusive.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsLowSurrogateCodePoint(uint value) => IsInRangeInclusive(value, 0xDC00U, 0xDFFFU);
-
- /// <summary>
- /// Returns <see langword="true"/> iff <paramref name="value"/> is a UTF-16 surrogate code point,
- /// i.e., is in [ U+D800..U+DFFF ], inclusive.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsSurrogateCodePoint(uint value) => IsInRangeInclusive(value, 0xD800U, 0xDFFFU);
-
- /// <summary>
- /// Returns <see langword="true"/> iff <paramref name="codePoint"/> is a valid Unicode code
- /// point, i.e., is in [ U+0000..U+10FFFF ], inclusive.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsValidCodePoint(uint codePoint) => codePoint <= 0x10FFFFU;
-
- /// <summary>
- /// Returns <see langword="true"/> iff <paramref name="value"/> is a valid Unicode scalar
- /// value, i.e., is in [ U+0000..U+D7FF ], inclusive; or [ U+E000..U+10FFFF ], inclusive.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool IsValidUnicodeScalar(uint value)
- {
- // This is an optimized check that on x86 is just three instructions: lea, xor, cmp.
- //
- // After the subtraction operation, the input value is modified as such:
- // [ 00000000..0010FFFF ] -> [ FFEF0000..FFFFFFFF ]
- //
- // We now want to _exclude_ the range [ FFEFD800..FFEFDFFF ] (surrogates) from being valid.
- // After the xor, this particular exclusion range becomes [ FFEF0000..FFEF07FF ].
- //
- // So now the range [ FFEF0800..FFFFFFFF ] contains all valid code points,
- // excluding surrogates. This allows us to perform a single comparison.
-
- return ((value - 0x110000u) ^ 0xD800u) >= 0xFFEF0800u;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.AppendFormat.cs b/netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.AppendFormat.cs
deleted file mode 100644
index b54bf77601f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.AppendFormat.cs
+++ /dev/null
@@ -1,355 +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.
-
-namespace System.Text
-{
- internal ref partial struct ValueStringBuilder
- {
- public void AppendFormat(string format, object? arg0) => AppendFormatHelper(null, format, new ParamsArray(arg0));
-
- public void AppendFormat(string format, object? arg0, object? arg1) => AppendFormatHelper(null, format, new ParamsArray(arg0, arg1));
-
- public void AppendFormat(string format, object? arg0, object? arg1, object? arg2) => AppendFormatHelper(null, format, new ParamsArray(arg0, arg1, arg2));
-
- public void AppendFormat(string format, params object?[] args)
- {
- if (args == null)
- {
- // To preserve the original exception behavior, throw an exception about format if both
- // args and format are null. The actual null check for format is in AppendFormatHelper.
- string paramName = (format == null) ? nameof(format) : nameof(args);
- throw new ArgumentNullException(paramName);
- }
-
- AppendFormatHelper(null, format, new ParamsArray(args));
- }
-
- public void AppendFormat(IFormatProvider? provider, string format, object? arg0) => AppendFormatHelper(provider, format, new ParamsArray(arg0));
-
- public void AppendFormat(IFormatProvider? provider, string format, object? arg0, object? arg1) => AppendFormatHelper(provider, format, new ParamsArray(arg0, arg1));
-
- public void AppendFormat(IFormatProvider? provider, string format, object? arg0, object? arg1, object? arg2) => AppendFormatHelper(provider, format, new ParamsArray(arg0, arg1, arg2));
-
- public void AppendFormat(IFormatProvider? provider, string format, params object?[] args)
- {
- if (args == null)
- {
- // To preserve the original exception behavior, throw an exception about format if both
- // args and format are null. The actual null check for format is in AppendFormatHelper.
- string paramName = (format == null) ? nameof(format) : nameof(args);
- throw new ArgumentNullException(paramName);
- }
-
- AppendFormatHelper(provider, format, new ParamsArray(args));
- }
-
- private void AppendSpanFormattable<T>(T value) where T : ISpanFormattable
- {
- if (value.TryFormat(_chars.Slice(_pos), out int charsWritten, format: default, provider: null))
- {
- _pos += charsWritten;
- }
- else
- {
- string? s = value.ToString();
- if (s != null)
- {
- Append(s);
- }
- }
- }
-
- internal void AppendSpanFormattable<T>(T value, string? format, IFormatProvider? provider) where T : ISpanFormattable, IFormattable
- {
- if (value.TryFormat(_chars.Slice(_pos), out int charsWritten, format, provider))
- {
- _pos += charsWritten;
- }
- else
- {
- Append(value.ToString(format, provider));
- }
- }
-
- // Copied from StringBuilder, can't be done via generic extension
- // as ValueStringBuilder is a ref struct and cannot be used in a generic.
- internal void AppendFormatHelper(IFormatProvider? provider, string format, ParamsArray args)
- {
- // Undocumented exclusive limits on the range for Argument Hole Index and Argument Hole Alignment.
- const int IndexLimit = 1000000; // Note: 0 <= ArgIndex < IndexLimit
- const int WidthLimit = 1000000; // Note: -WidthLimit < ArgAlign < WidthLimit
-
- if (format == null)
- {
- throw new ArgumentNullException(nameof(format));
- }
-
- int pos = 0;
- int len = format.Length;
- char ch = '\0';
- ICustomFormatter? cf = (ICustomFormatter?)provider?.GetFormat(typeof(ICustomFormatter));
-
- while (true)
- {
- while (pos < len)
- {
- ch = format[pos];
-
- pos++;
- // Is it a closing brace?
- if (ch == '}')
- {
- // Check next character (if there is one) to see if it is escaped. eg }}
- if (pos < len && format[pos] == '}')
- {
- pos++;
- }
- else
- {
- // Otherwise treat it as an error (Mismatched closing brace)
- ThrowFormatError();
- }
- }
- // Is it a opening brace?
- else if (ch == '{')
- {
- // Check next character (if there is one) to see if it is escaped. eg {{
- if (pos < len && format[pos] == '{')
- {
- pos++;
- }
- else
- {
- // Otherwise treat it as the opening brace of an Argument Hole.
- pos--;
- break;
- }
- }
- // If it's neither then treat the character as just text.
- Append(ch);
- }
-
- //
- // Start of parsing of Argument Hole.
- // Argument Hole ::= { Index (, WS* Alignment WS*)? (: Formatting)? }
- //
- if (pos == len)
- {
- break;
- }
-
- //
- // Start of parsing required Index parameter.
- // Index ::= ('0'-'9')+ WS*
- //
- pos++;
- // If reached end of text then error (Unexpected end of text)
- // or character is not a digit then error (Unexpected Character)
- if (pos == len || (ch = format[pos]) < '0' || ch > '9') ThrowFormatError();
- int index = 0;
- do
- {
- index = index * 10 + ch - '0';
- pos++;
- // If reached end of text then error (Unexpected end of text)
- if (pos == len)
- {
- ThrowFormatError();
- }
- ch = format[pos];
- // so long as character is digit and value of the index is less than 1000000 ( index limit )
- }
- while (ch >= '0' && ch <= '9' && index < IndexLimit);
-
- // If value of index is not within the range of the arguments passed in then error (Index out of range)
- if (index >= args.Length)
- {
- throw new FormatException(SR.Format_IndexOutOfRange);
- }
-
- // Consume optional whitespace.
- while (pos < len && (ch = format[pos]) == ' ') pos++;
- // End of parsing index parameter.
-
- //
- // Start of parsing of optional Alignment
- // Alignment ::= comma WS* minus? ('0'-'9')+ WS*
- //
- bool leftJustify = false;
- int width = 0;
- // Is the character a comma, which indicates the start of alignment parameter.
- if (ch == ',')
- {
- pos++;
-
- // Consume Optional whitespace
- while (pos < len && format[pos] == ' ') pos++;
-
- // If reached the end of the text then error (Unexpected end of text)
- if (pos == len)
- {
- ThrowFormatError();
- }
-
- // Is there a minus sign?
- ch = format[pos];
- if (ch == '-')
- {
- // Yes, then alignment is left justified.
- leftJustify = true;
- pos++;
- // If reached end of text then error (Unexpected end of text)
- if (pos == len)
- {
- ThrowFormatError();
- }
- ch = format[pos];
- }
-
- // If current character is not a digit then error (Unexpected character)
- if (ch < '0' || ch > '9')
- {
- ThrowFormatError();
- }
- // Parse alignment digits.
- do
- {
- width = width * 10 + ch - '0';
- pos++;
- // If reached end of text then error. (Unexpected end of text)
- if (pos == len)
- {
- ThrowFormatError();
- }
- ch = format[pos];
- // So long a current character is a digit and the value of width is less than 100000 ( width limit )
- }
- while (ch >= '0' && ch <= '9' && width < WidthLimit);
- // end of parsing Argument Alignment
- }
-
- // Consume optional whitespace
- while (pos < len && (ch = format[pos]) == ' ') pos++;
-
- //
- // Start of parsing of optional formatting parameter.
- //
- object? arg = args[index];
-
- ReadOnlySpan<char> itemFormatSpan = default; // used if itemFormat is null
- // Is current character a colon? which indicates start of formatting parameter.
- if (ch == ':')
- {
- pos++;
- int startPos = pos;
-
- while (true)
- {
- // If reached end of text then error. (Unexpected end of text)
- if (pos == len)
- {
- ThrowFormatError();
- }
- ch = format[pos];
-
- if (ch == '}')
- {
- // Argument hole closed
- break;
- }
- else if (ch == '{')
- {
- // Braces inside the argument hole are not supported
- ThrowFormatError();
- }
-
- pos++;
- }
-
- if (pos > startPos)
- {
- itemFormatSpan = format.AsSpan(startPos, pos - startPos);
- }
- }
- else if (ch != '}')
- {
- // Unexpected character
- ThrowFormatError();
- }
-
- // Construct the output for this arg hole.
- pos++;
- string? s = null;
- string? itemFormat = null;
-
- if (cf != null)
- {
- if (itemFormatSpan.Length != 0)
- {
- itemFormat = new string(itemFormatSpan);
- }
- s = cf.Format(itemFormat, arg, provider);
- }
-
- if (s == null)
- {
- // If arg is ISpanFormattable and the beginning doesn't need padding,
- // try formatting it into the remaining current chunk.
- if (arg is ISpanFormattable spanFormattableArg &&
- (leftJustify || width == 0) &&
- spanFormattableArg.TryFormat(_chars.Slice(_pos), out int charsWritten, itemFormatSpan, provider))
- {
- _pos += charsWritten;
-
- // Pad the end, if needed.
- int padding = width - charsWritten;
- if (leftJustify && padding > 0)
- {
- Append(' ', padding);
- }
-
- // Continue to parse other characters.
- continue;
- }
-
- // Otherwise, fallback to trying IFormattable or calling ToString.
- if (arg is IFormattable formattableArg)
- {
- if (itemFormatSpan.Length != 0)
- {
- itemFormat ??= new string(itemFormatSpan);
- }
- s = formattableArg.ToString(itemFormat, provider);
- }
- else if (arg != null)
- {
- s = arg.ToString();
- }
- }
- // Append it to the final output of the Format String.
- if (s == null)
- {
- s = string.Empty;
- }
- int pad = width - s.Length;
- if (!leftJustify && pad > 0)
- {
- Append(' ', pad);
- }
-
- Append(s);
- if (leftJustify && pad > 0)
- {
- Append(' ', pad);
- }
- // Continue to parse other characters.
- }
- }
-
- private static void ThrowFormatError()
- {
- throw new FormatException(SR.Format_InvalidString);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs b/netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs
deleted file mode 100644
index c7563cb62f4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs
+++ /dev/null
@@ -1,310 +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.
-
-#nullable enable
-using System.Buffers;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Text
-{
- internal ref partial struct ValueStringBuilder
- {
- private char[]? _arrayToReturnToPool;
- private Span<char> _chars;
- private int _pos;
-
- public ValueStringBuilder(Span<char> initialBuffer)
- {
- _arrayToReturnToPool = null;
- _chars = initialBuffer;
- _pos = 0;
- }
-
- public ValueStringBuilder(int initialCapacity)
- {
- _arrayToReturnToPool = ArrayPool<char>.Shared.Rent(initialCapacity);
- _chars = _arrayToReturnToPool;
- _pos = 0;
- }
-
- public int Length
- {
- get => _pos;
- set
- {
- Debug.Assert(value >= 0);
- Debug.Assert(value <= _chars.Length);
- _pos = value;
- }
- }
-
- public int Capacity => _chars.Length;
-
- public void EnsureCapacity(int capacity)
- {
- if (capacity > _chars.Length)
- Grow(capacity - _pos);
- }
-
- /// <summary>
- /// Get a pinnable reference to the builder.
- /// Does not ensure there is a null char after <see cref="Length"/>
- /// This overload is pattern matched in the C# 7.3+ compiler so you can omit
- /// the explicit method call, and write eg "fixed (char* c = builder)"
- /// </summary>
- public ref char GetPinnableReference()
- {
- return ref MemoryMarshal.GetReference(_chars);
- }
-
- /// <summary>
- /// Get a pinnable reference to the builder.
- /// </summary>
- /// <param name="terminate">Ensures that the builder has a null char after <see cref="Length"/></param>
- public ref char GetPinnableReference(bool terminate)
- {
- if (terminate)
- {
- EnsureCapacity(Length + 1);
- _chars[Length] = '\0';
- }
- return ref MemoryMarshal.GetReference(_chars);
- }
-
- public ref char this[int index]
- {
- get
- {
- Debug.Assert(index < _pos);
- return ref _chars[index];
- }
- }
-
- public override string ToString()
- {
- string s = _chars.Slice(0, _pos).ToString();
- Dispose();
- return s;
- }
-
- /// <summary>Returns the underlying storage of the builder.</summary>
- public Span<char> RawChars => _chars;
-
- /// <summary>
- /// Returns a span around the contents of the builder.
- /// </summary>
- /// <param name="terminate">Ensures that the builder has a null char after <see cref="Length"/></param>
- public ReadOnlySpan<char> AsSpan(bool terminate)
- {
- if (terminate)
- {
- EnsureCapacity(Length + 1);
- _chars[Length] = '\0';
- }
- return _chars.Slice(0, _pos);
- }
-
- public ReadOnlySpan<char> AsSpan() => _chars.Slice(0, _pos);
- public ReadOnlySpan<char> AsSpan(int start) => _chars.Slice(start, _pos - start);
- public ReadOnlySpan<char> AsSpan(int start, int length) => _chars.Slice(start, length);
-
- public bool TryCopyTo(Span<char> destination, out int charsWritten)
- {
- if (_chars.Slice(0, _pos).TryCopyTo(destination))
- {
- charsWritten = _pos;
- Dispose();
- return true;
- }
- else
- {
- charsWritten = 0;
- Dispose();
- return false;
- }
- }
-
- public void Insert(int index, char value, int count)
- {
- if (_pos > _chars.Length - count)
- {
- Grow(count);
- }
-
- int remaining = _pos - index;
- _chars.Slice(index, remaining).CopyTo(_chars.Slice(index + count));
- _chars.Slice(index, count).Fill(value);
- _pos += count;
- }
-
- public void Insert(int index, string? s)
- {
- if (s == null)
- {
- return;
- }
-
- int count = s.Length;
-
- if (_pos > (_chars.Length - count))
- {
- Grow(count);
- }
-
- int remaining = _pos - index;
- _chars.Slice(index, remaining).CopyTo(_chars.Slice(index + count));
- s.AsSpan().CopyTo(_chars.Slice(index));
- _pos += count;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Append(char c)
- {
- int pos = _pos;
- if ((uint)pos < (uint)_chars.Length)
- {
- _chars[pos] = c;
- _pos = pos + 1;
- }
- else
- {
- GrowAndAppend(c);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Append(string? s)
- {
- if (s == null)
- {
- return;
- }
-
- int pos = _pos;
- if (s.Length == 1 && (uint)pos < (uint)_chars.Length) // very common case, e.g. appending strings from NumberFormatInfo like separators, percent symbols, etc.
- {
- _chars[pos] = s[0];
- _pos = pos + 1;
- }
- else
- {
- AppendSlow(s);
- }
- }
-
- private void AppendSlow(string s)
- {
- int pos = _pos;
- if (pos > _chars.Length - s.Length)
- {
- Grow(s.Length);
- }
-
- s.AsSpan().CopyTo(_chars.Slice(pos));
- _pos += s.Length;
- }
-
- public void Append(char c, int count)
- {
- if (_pos > _chars.Length - count)
- {
- Grow(count);
- }
-
- Span<char> dst = _chars.Slice(_pos, count);
- for (int i = 0; i < dst.Length; i++)
- {
- dst[i] = c;
- }
- _pos += count;
- }
-
- public unsafe void Append(char* value, int length)
- {
- int pos = _pos;
- if (pos > _chars.Length - length)
- {
- Grow(length);
- }
-
- Span<char> dst = _chars.Slice(_pos, length);
- for (int i = 0; i < dst.Length; i++)
- {
- dst[i] = *value++;
- }
- _pos += length;
- }
-
- public void Append(ReadOnlySpan<char> value)
- {
- int pos = _pos;
- if (pos > _chars.Length - value.Length)
- {
- Grow(value.Length);
- }
-
- value.CopyTo(_chars.Slice(_pos));
- _pos += value.Length;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Span<char> AppendSpan(int length)
- {
- int origPos = _pos;
- if (origPos > _chars.Length - length)
- {
- Grow(length);
- }
-
- _pos = origPos + length;
- return _chars.Slice(origPos, length);
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private void GrowAndAppend(char c)
- {
- Grow(1);
- Append(c);
- }
-
- /// <summary>
- /// Resize the internal buffer either by doubling current buffer size or
- /// by adding <paramref name="additionalCapacityBeyondPos"/> to
- /// <see cref="_pos"/> whichever is greater.
- /// </summary>
- /// <param name="additionalCapacityBeyondPos">
- /// Number of chars requested beyond current position.
- /// </param>
- [MethodImpl(MethodImplOptions.NoInlining)]
- private void Grow(int additionalCapacityBeyondPos)
- {
- Debug.Assert(additionalCapacityBeyondPos > 0);
- Debug.Assert(_pos > _chars.Length - additionalCapacityBeyondPos, "Grow called incorrectly, no resize is needed.");
-
- char[] poolArray = ArrayPool<char>.Shared.Rent(Math.Max(_pos + additionalCapacityBeyondPos, _chars.Length * 2));
-
- _chars.Slice(0, _pos).CopyTo(poolArray);
-
- char[]? toReturn = _arrayToReturnToPool;
- _chars = _arrayToReturnToPool = poolArray;
- if (toReturn != null)
- {
- ArrayPool<char>.Shared.Return(toReturn);
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Dispose()
- {
- char[]? toReturn = _arrayToReturnToPool;
- this = default; // for safety, to avoid using pooled array if this instance is erroneously appended to again
- if (toReturn != null)
- {
- ArrayPool<char>.Shared.Return(toReturn);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ThreadAttributes.cs b/netcore/System.Private.CoreLib/shared/System/ThreadAttributes.cs
deleted file mode 100644
index 62487361077..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ThreadAttributes.cs
+++ /dev/null
@@ -1,28 +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.
-
-/*=============================================================================
-**
-** Purpose: For Threads-related custom attributes.
-**
-=============================================================================*/
-
-namespace System
-{
- [AttributeUsage(AttributeTargets.Method)]
- public sealed class STAThreadAttribute : Attribute
- {
- public STAThreadAttribute()
- {
- }
- }
-
- [AttributeUsage(AttributeTargets.Method)]
- public sealed class MTAThreadAttribute : Attribute
- {
- public MTAThreadAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ThreadStaticAttribute.cs b/netcore/System.Private.CoreLib/shared/System/ThreadStaticAttribute.cs
deleted file mode 100644
index cb92fc49664..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ThreadStaticAttribute.cs
+++ /dev/null
@@ -1,25 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Custom attribute to indicate that the field should be treated
-** as a static relative to a thread.
-**
-**
-**
-===========================================================*/
-
-namespace System
-{
- [AttributeUsage(AttributeTargets.Field, Inherited = false)]
- public class ThreadStaticAttribute : Attribute
- {
- public ThreadStaticAttribute()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/AbandonedMutexException.cs b/netcore/System.Private.CoreLib/shared/System/Threading/AbandonedMutexException.cs
deleted file mode 100644
index c2e5f0014da..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/AbandonedMutexException.cs
+++ /dev/null
@@ -1,74 +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.
-//
-// AbandonedMutexException
-// Thrown when a wait completes because one or more mutexes was abandoned.
-// AbandonedMutexs indicate serious error in user code or machine state.
-////////////////////////////////////////////////////////////////////////////////
-
-using System.Runtime.Serialization;
-
-namespace System.Threading
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class AbandonedMutexException : SystemException
- {
- private int _mutexIndex = -1;
- private Mutex? _mutex = null;
-
- public AbandonedMutexException()
- : base(SR.Threading_AbandonedMutexException)
- {
- HResult = HResults.COR_E_ABANDONEDMUTEX;
- }
-
- public AbandonedMutexException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_ABANDONEDMUTEX;
- }
-
- public AbandonedMutexException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_ABANDONEDMUTEX;
- }
-
- public AbandonedMutexException(int location, WaitHandle? handle)
- : base(SR.Threading_AbandonedMutexException)
- {
- HResult = HResults.COR_E_ABANDONEDMUTEX;
- SetupException(location, handle);
- }
-
- public AbandonedMutexException(string? message, int location, WaitHandle? handle)
- : base(message)
- {
- HResult = HResults.COR_E_ABANDONEDMUTEX;
- SetupException(location, handle);
- }
-
- public AbandonedMutexException(string? message, Exception? inner, int location, WaitHandle? handle)
- : base(message, inner)
- {
- HResult = HResults.COR_E_ABANDONEDMUTEX;
- SetupException(location, handle);
- }
-
- protected AbandonedMutexException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
-
- private void SetupException(int location, WaitHandle? handle)
- {
- _mutexIndex = location;
- _mutex = handle as Mutex;
- }
-
- public Mutex? Mutex => _mutex;
- public int MutexIndex => _mutexIndex;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ApartmentState.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ApartmentState.cs
deleted file mode 100644
index 47c1677cb59..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ApartmentState.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.Threading
-{
- public enum ApartmentState
- {
- /*=========================================================================
- ** Constants for thread apartment states.
- =========================================================================*/
- STA = 0,
- MTA = 1,
- Unknown = 2
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs b/netcore/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs
deleted file mode 100644
index e80fb97e249..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs
+++ /dev/null
@@ -1,497 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Threading
-{
- //
- // AsyncLocal<T> represents "ambient" data that is local to a given asynchronous control flow, such as an
- // async method. For example, say you want to associate a culture with a given async flow:
- //
- // static AsyncLocal<Culture> s_currentCulture = new AsyncLocal<Culture>();
- //
- // static async Task SomeOperationAsync(Culture culture)
- // {
- // s_currentCulture.Value = culture;
- //
- // await FooAsync();
- // }
- //
- // static async Task FooAsync()
- // {
- // PrintStringWithCulture(s_currentCulture.Value);
- // }
- //
- // AsyncLocal<T> also provides optional notifications when the value associated with the current thread
- // changes, either because it was explicitly changed by setting the Value property, or implicitly changed
- // when the thread encountered an "await" or other context transition. For example, we might want our
- // current culture to be communicated to the OS as well:
- //
- // static AsyncLocal<Culture> s_currentCulture = new AsyncLocal<Culture>(
- // args =>
- // {
- // NativeMethods.SetThreadCulture(args.CurrentValue.LCID);
- // });
- //
- public sealed class AsyncLocal<T> : IAsyncLocal
- {
- private readonly Action<AsyncLocalValueChangedArgs<T>>? m_valueChangedHandler;
-
- //
- // Constructs an AsyncLocal<T> that does not receive change notifications.
- //
- public AsyncLocal()
- {
- }
-
- //
- // Constructs an AsyncLocal<T> with a delegate that is called whenever the current value changes
- // on any thread.
- //
- public AsyncLocal(Action<AsyncLocalValueChangedArgs<T>>? valueChangedHandler)
- {
- m_valueChangedHandler = valueChangedHandler;
- }
-
- [MaybeNull]
- public T Value
- {
- get
- {
- object? obj = ExecutionContext.GetLocalValue(this);
- return (obj == null) ? default : (T)obj;
- }
- set => ExecutionContext.SetLocalValue(this, value, m_valueChangedHandler != null);
- }
-
- void IAsyncLocal.OnValueChanged(object? previousValueObj, object? currentValueObj, bool contextChanged)
- {
- Debug.Assert(m_valueChangedHandler != null);
- T previousValue = previousValueObj == null ? default! : (T)previousValueObj;
- T currentValue = currentValueObj == null ? default! : (T)currentValueObj;
- m_valueChangedHandler(new AsyncLocalValueChangedArgs<T>(previousValue, currentValue, contextChanged));
- }
- }
-
- //
- // Interface to allow non-generic code in ExecutionContext to call into the generic AsyncLocal<T> type.
- //
- internal interface IAsyncLocal
- {
- void OnValueChanged(object? previousValue, object? currentValue, bool contextChanged);
- }
-
- public readonly struct AsyncLocalValueChangedArgs<T>
- {
- [MaybeNull] public T PreviousValue { get; }
- [MaybeNull] 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; }
-
- internal AsyncLocalValueChangedArgs([AllowNull] T previousValue, [AllowNull] T currentValue, bool contextChanged)
- {
- PreviousValue = previousValue;
- CurrentValue = currentValue;
- ThreadContextChanged = contextChanged;
- }
- }
-
- //
- // Interface used to store an IAsyncLocal => object mapping in ExecutionContext.
- // Implementations are specialized based on the number of elements in the immutable
- // map in order to minimize memory consumption and look-up times.
- //
- internal interface IAsyncLocalValueMap
- {
- bool TryGetValue(IAsyncLocal key, out object? value);
- IAsyncLocalValueMap Set(IAsyncLocal key, object? value, bool treatNullValueAsNonexistent);
- }
-
- //
- // Utility functions for getting/creating instances of IAsyncLocalValueMap
- //
- internal static class AsyncLocalValueMap
- {
- public static IAsyncLocalValueMap Empty { get; } = new EmptyAsyncLocalValueMap();
-
- public static bool IsEmpty(IAsyncLocalValueMap asyncLocalValueMap)
- {
- Debug.Assert(asyncLocalValueMap != null);
- Debug.Assert(asyncLocalValueMap == Empty || asyncLocalValueMap.GetType() != typeof(EmptyAsyncLocalValueMap));
-
- return asyncLocalValueMap == Empty;
- }
-
- public static IAsyncLocalValueMap Create(IAsyncLocal key, object? value, bool treatNullValueAsNonexistent)
- {
- // If the value isn't null or a null value may not be treated as nonexistent, then create a new one-element map
- // to store the key/value pair. Otherwise, use the empty map.
- return value != null || !treatNullValueAsNonexistent ?
- new OneElementAsyncLocalValueMap(key, value) :
- Empty;
- }
-
- // Instance without any key/value pairs. Used as a singleton/
- private sealed class EmptyAsyncLocalValueMap : IAsyncLocalValueMap
- {
- public IAsyncLocalValueMap Set(IAsyncLocal key, object? value, bool treatNullValueAsNonexistent)
- {
- // If the value isn't null or a null value may not be treated as nonexistent, then create a new one-element map
- // to store the key/value pair. Otherwise, use the empty map.
- return value != null || !treatNullValueAsNonexistent ?
- new OneElementAsyncLocalValueMap(key, value) :
- (IAsyncLocalValueMap)this;
- }
-
- public bool TryGetValue(IAsyncLocal key, out object? value)
- {
- value = null;
- return false;
- }
- }
-
- // Instance with one key/value pair.
- private sealed class OneElementAsyncLocalValueMap : IAsyncLocalValueMap
- {
- private readonly IAsyncLocal _key1;
- private readonly object? _value1;
-
- public OneElementAsyncLocalValueMap(IAsyncLocal key, object? value)
- {
- _key1 = key; _value1 = value;
- }
-
- public IAsyncLocalValueMap Set(IAsyncLocal key, object? value, bool treatNullValueAsNonexistent)
- {
- if (value != null || !treatNullValueAsNonexistent)
- {
- // If the key matches one already contained in this map, then create a new one-element map with the updated
- // value, otherwise create a two-element map with the additional key/value.
- return ReferenceEquals(key, _key1) ?
- new OneElementAsyncLocalValueMap(key, value) :
- (IAsyncLocalValueMap)new TwoElementAsyncLocalValueMap(_key1, _value1, key, value);
- }
- else
- {
- // If the key exists in this map, remove it by downgrading to an empty map. Otherwise, there's nothing to
- // add or remove, so just return this map.
- return ReferenceEquals(key, _key1) ?
- Empty :
- (IAsyncLocalValueMap)this;
- }
- }
-
- public bool TryGetValue(IAsyncLocal key, out object? value)
- {
- if (ReferenceEquals(key, _key1))
- {
- value = _value1;
- return true;
- }
- else
- {
- value = null;
- return false;
- }
- }
- }
-
- // Instance with two key/value pairs.
- private sealed class TwoElementAsyncLocalValueMap : IAsyncLocalValueMap
- {
- private readonly IAsyncLocal _key1, _key2;
- private readonly object? _value1, _value2;
-
- public TwoElementAsyncLocalValueMap(IAsyncLocal key1, object? value1, IAsyncLocal key2, object? value2)
- {
- _key1 = key1; _value1 = value1;
- _key2 = key2; _value2 = value2;
- }
-
- public IAsyncLocalValueMap Set(IAsyncLocal key, object? value, bool treatNullValueAsNonexistent)
- {
- if (value != null || !treatNullValueAsNonexistent)
- {
- // If the key matches one already contained in this map, then create a new two-element map with the updated
- // value, otherwise create a three-element map with the additional key/value.
- return
- ReferenceEquals(key, _key1) ? new TwoElementAsyncLocalValueMap(key, value, _key2, _value2) :
- ReferenceEquals(key, _key2) ? new TwoElementAsyncLocalValueMap(_key1, _value1, key, value) :
- (IAsyncLocalValueMap)new ThreeElementAsyncLocalValueMap(_key1, _value1, _key2, _value2, key, value);
- }
- else
- {
- // If the key exists in this map, remove it by downgrading to a one-element map without the key. Otherwise,
- // there's nothing to add or remove, so just return this map.
- return
- ReferenceEquals(key, _key1) ? new OneElementAsyncLocalValueMap(_key2, _value2) :
- ReferenceEquals(key, _key2) ? new OneElementAsyncLocalValueMap(_key1, _value1) :
- (IAsyncLocalValueMap)this;
- }
- }
-
- public bool TryGetValue(IAsyncLocal key, out object? value)
- {
- if (ReferenceEquals(key, _key1))
- {
- value = _value1;
- return true;
- }
- else if (ReferenceEquals(key, _key2))
- {
- value = _value2;
- return true;
- }
- else
- {
- value = null;
- return false;
- }
- }
- }
-
- // Instance with three key/value pairs.
- private sealed class ThreeElementAsyncLocalValueMap : IAsyncLocalValueMap
- {
- private readonly IAsyncLocal _key1, _key2, _key3;
- private readonly object? _value1, _value2, _value3;
-
- public ThreeElementAsyncLocalValueMap(IAsyncLocal key1, object? value1, IAsyncLocal key2, object? value2, IAsyncLocal key3, object? value3)
- {
- _key1 = key1; _value1 = value1;
- _key2 = key2; _value2 = value2;
- _key3 = key3; _value3 = value3;
- }
-
- public IAsyncLocalValueMap Set(IAsyncLocal key, object? value, bool treatNullValueAsNonexistent)
- {
- if (value != null || !treatNullValueAsNonexistent)
- {
- // If the key matches one already contained in this map, then create a new three-element map with the
- // updated value.
- if (ReferenceEquals(key, _key1)) return new ThreeElementAsyncLocalValueMap(key, value, _key2, _value2, _key3, _value3);
- if (ReferenceEquals(key, _key2)) return new ThreeElementAsyncLocalValueMap(_key1, _value1, key, value, _key3, _value3);
- if (ReferenceEquals(key, _key3)) return new ThreeElementAsyncLocalValueMap(_key1, _value1, _key2, _value2, key, value);
-
- // The key doesn't exist in this map, so upgrade to a multi map that contains
- // the additional key/value pair.
- var multi = new MultiElementAsyncLocalValueMap(4);
- multi.UnsafeStore(0, _key1, _value1);
- multi.UnsafeStore(1, _key2, _value2);
- multi.UnsafeStore(2, _key3, _value3);
- multi.UnsafeStore(3, key, value);
- return multi;
- }
- else
- {
- // If the key exists in this map, remove it by downgrading to a two-element map without the key. Otherwise,
- // there's nothing to add or remove, so just return this map.
- return
- ReferenceEquals(key, _key1) ? new TwoElementAsyncLocalValueMap(_key2, _value2, _key3, _value3) :
- ReferenceEquals(key, _key2) ? new TwoElementAsyncLocalValueMap(_key1, _value1, _key3, _value3) :
- ReferenceEquals(key, _key3) ? new TwoElementAsyncLocalValueMap(_key1, _value1, _key2, _value2) :
- (IAsyncLocalValueMap)this;
- }
- }
-
- public bool TryGetValue(IAsyncLocal key, out object? value)
- {
- if (ReferenceEquals(key, _key1))
- {
- value = _value1;
- return true;
- }
- else if (ReferenceEquals(key, _key2))
- {
- value = _value2;
- return true;
- }
- else if (ReferenceEquals(key, _key3))
- {
- value = _value3;
- return true;
- }
- else
- {
- value = null;
- return false;
- }
- }
- }
-
- // Instance with up to 16 key/value pairs.
- private sealed class MultiElementAsyncLocalValueMap : IAsyncLocalValueMap
- {
- internal const int MaxMultiElements = 16;
- private readonly KeyValuePair<IAsyncLocal, object?>[] _keyValues;
-
- internal MultiElementAsyncLocalValueMap(int count)
- {
- Debug.Assert(count <= MaxMultiElements);
- _keyValues = new KeyValuePair<IAsyncLocal, object?>[count];
- }
-
- internal void UnsafeStore(int index, IAsyncLocal key, object? value)
- {
- Debug.Assert(index < _keyValues.Length);
- _keyValues[index] = new KeyValuePair<IAsyncLocal, object?>(key, value);
- }
-
- public IAsyncLocalValueMap Set(IAsyncLocal key, object? value, bool treatNullValueAsNonexistent)
- {
- // Find the key in this map.
- for (int i = 0; i < _keyValues.Length; i++)
- {
- if (ReferenceEquals(key, _keyValues[i].Key))
- {
- // The key is in the map.
- if (value != null || !treatNullValueAsNonexistent)
- {
- // Create a new map of the same size that has all of the same pairs, with this new key/value pair
- // overwriting the old.
- var multi = new MultiElementAsyncLocalValueMap(_keyValues.Length);
- Array.Copy(_keyValues, multi._keyValues, _keyValues.Length);
- multi._keyValues[i] = new KeyValuePair<IAsyncLocal, object?>(key, value);
- return multi;
- }
- else if (_keyValues.Length == 4)
- {
- // We only have four elements, one of which we're removing, so downgrade to a three-element map,
- // without the matching element.
- return
- i == 0 ? new ThreeElementAsyncLocalValueMap(_keyValues[1].Key, _keyValues[1].Value, _keyValues[2].Key, _keyValues[2].Value, _keyValues[3].Key, _keyValues[3].Value) :
- i == 1 ? new ThreeElementAsyncLocalValueMap(_keyValues[0].Key, _keyValues[0].Value, _keyValues[2].Key, _keyValues[2].Value, _keyValues[3].Key, _keyValues[3].Value) :
- i == 2 ? new ThreeElementAsyncLocalValueMap(_keyValues[0].Key, _keyValues[0].Value, _keyValues[1].Key, _keyValues[1].Value, _keyValues[3].Key, _keyValues[3].Value) :
- (IAsyncLocalValueMap)new ThreeElementAsyncLocalValueMap(_keyValues[0].Key, _keyValues[0].Value, _keyValues[1].Key, _keyValues[1].Value, _keyValues[2].Key, _keyValues[2].Value);
- }
- else
- {
- // We have enough elements remaining to warrant a multi map. Create a new one and copy all of the
- // elements from this one, except the one to be removed.
- var multi = new MultiElementAsyncLocalValueMap(_keyValues.Length - 1);
- if (i != 0) Array.Copy(_keyValues, multi._keyValues, i);
- if (i != _keyValues.Length - 1) Array.Copy(_keyValues, i + 1, multi._keyValues, i, _keyValues.Length - i - 1);
- return multi;
- }
- }
- }
-
- // The key does not already exist in this map.
-
- if (value == null && treatNullValueAsNonexistent)
- {
- // We can simply return this same map, as there's nothing to add or remove.
- return this;
- }
-
- // We need to create a new map that has the additional key/value pair.
- // If with the addition we can still fit in a multi map, create one.
- if (_keyValues.Length < MaxMultiElements)
- {
- var multi = new MultiElementAsyncLocalValueMap(_keyValues.Length + 1);
- Array.Copy(_keyValues, multi._keyValues, _keyValues.Length);
- multi._keyValues[_keyValues.Length] = new KeyValuePair<IAsyncLocal, object?>(key, value);
- return multi;
- }
-
- // Otherwise, upgrade to a many map.
- var many = new ManyElementAsyncLocalValueMap(MaxMultiElements + 1);
- foreach (KeyValuePair<IAsyncLocal, object?> pair in _keyValues)
- {
- many[pair.Key] = pair.Value;
- }
- many[key] = value;
- return many;
- }
-
- public bool TryGetValue(IAsyncLocal key, out object? value)
- {
- foreach (KeyValuePair<IAsyncLocal, object?> pair in _keyValues)
- {
- if (ReferenceEquals(key, pair.Key))
- {
- value = pair.Value;
- return true;
- }
- }
- value = null;
- return false;
- }
- }
-
- // Instance with any number of key/value pairs.
- private sealed class ManyElementAsyncLocalValueMap : Dictionary<IAsyncLocal, object?>, IAsyncLocalValueMap
- {
- public ManyElementAsyncLocalValueMap(int capacity) : base(capacity) { }
-
- public IAsyncLocalValueMap Set(IAsyncLocal key, object? value, bool treatNullValueAsNonexistent)
- {
- int count = Count;
- bool containsKey = ContainsKey(key);
-
- // If the value being set exists, create a new many map, copy all of the elements from this one,
- // and then store the new key/value pair into it. This is the most common case.
- if (value != null || !treatNullValueAsNonexistent)
- {
- var map = new ManyElementAsyncLocalValueMap(count + (containsKey ? 0 : 1));
- foreach (KeyValuePair<IAsyncLocal, object?> pair in this)
- {
- map[pair.Key] = pair.Value;
- }
- map[key] = value;
- return map;
- }
-
- // Otherwise, the value is null and a null value may be treated as nonexistent. We can downgrade to a smaller
- // map rather than storing null.
-
- // If the key is contained in this map, we're going to create a new map that's one pair smaller.
- if (containsKey)
- {
- // If the new count would be within range of a multi map instead of a many map,
- // downgrade to the multi map, which uses less memory and is faster to access.
- // Otherwise, just create a new many map that's missing this key.
- if (count == MultiElementAsyncLocalValueMap.MaxMultiElements + 1)
- {
- var multi = new MultiElementAsyncLocalValueMap(MultiElementAsyncLocalValueMap.MaxMultiElements);
- int index = 0;
- foreach (KeyValuePair<IAsyncLocal, object?> pair in this)
- {
- if (!ReferenceEquals(key, pair.Key))
- {
- multi.UnsafeStore(index++, pair.Key, pair.Value);
- }
- }
- Debug.Assert(index == MultiElementAsyncLocalValueMap.MaxMultiElements);
- return multi;
- }
- else
- {
- var map = new ManyElementAsyncLocalValueMap(count - 1);
- foreach (KeyValuePair<IAsyncLocal, object?> pair in this)
- {
- if (!ReferenceEquals(key, pair.Key))
- {
- map[pair.Key] = pair.Value;
- }
- }
- Debug.Assert(map.Count == count - 1);
- return map;
- }
- }
-
- // We were storing null and a null value may be treated as nonexistent, but the key wasn't in the map, so
- // there's nothing to change. Just return this instance.
- return this;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/AutoResetEvent.cs b/netcore/System.Private.CoreLib/shared/System/Threading/AutoResetEvent.cs
deleted file mode 100644
index 6c306af6168..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/AutoResetEvent.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Threading
-{
- public sealed class AutoResetEvent : EventWaitHandle
- {
- public AutoResetEvent(bool initialState) : base(initialState, EventResetMode.AutoReset) { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/CancellationToken.cs b/netcore/System.Private.CoreLib/shared/System/Threading/CancellationToken.cs
deleted file mode 100644
index 498ccd4f2ca..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/CancellationToken.cs
+++ /dev/null
@@ -1,356 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Threading
-{
- /// <summary>
- /// Propagates notification that operations should be canceled.
- /// </summary>
- /// <remarks>
- /// <para>
- /// A <see cref="CancellationToken"/> may be created directly in an unchangeable canceled or non-canceled state
- /// using the CancellationToken's constructors. However, to have a CancellationToken that can change
- /// from a non-canceled to a canceled state,
- /// <see cref="System.Threading.CancellationTokenSource">CancellationTokenSource</see> must be used.
- /// CancellationTokenSource exposes the associated CancellationToken that may be canceled by the source through its
- /// <see cref="System.Threading.CancellationTokenSource.Token">Token</see> property.
- /// </para>
- /// <para>
- /// Once canceled, a token may not transition to a non-canceled state, and a token whose
- /// <see cref="CanBeCanceled"/> is false will never change to one that can be canceled.
- /// </para>
- /// <para>
- /// All members of this struct are thread-safe and may be used concurrently from multiple threads.
- /// </para>
- /// </remarks>
- [DebuggerDisplay("IsCancellationRequested = {IsCancellationRequested}")]
- public readonly struct CancellationToken
- {
- // The backing TokenSource.
- // if null, it implicitly represents the same thing as new CancellationToken(false).
- // When required, it will be instantiated to reflect this.
- private readonly CancellationTokenSource? _source;
- // !! warning. If more fields are added, the assumptions in CreateLinkedToken may no longer be valid
-
- private static readonly Action<object?> s_actionToActionObjShunt = obj =>
- {
- Debug.Assert(obj is Action, $"Expected {typeof(Action)}, got {obj}");
- ((Action)obj)();
- };
-
- /// <summary>
- /// Returns an empty CancellationToken value.
- /// </summary>
- /// <remarks>
- /// The <see cref="CancellationToken"/> value returned by this property will be non-cancelable by default.
- /// </remarks>
- public static CancellationToken None => default;
-
- /// <summary>
- /// Gets whether cancellation has been requested for this token.
- /// </summary>
- /// <value>Whether cancellation has been requested for this token.</value>
- /// <remarks>
- /// <para>
- /// This property indicates whether cancellation has been requested for this token,
- /// either through the token initially being constructed in a canceled state, or through
- /// calling <see cref="System.Threading.CancellationTokenSource.Cancel()">Cancel</see>
- /// on the token's associated <see cref="CancellationTokenSource"/>.
- /// </para>
- /// <para>
- /// If this property is true, it only guarantees that cancellation has been requested.
- /// It does not guarantee that every registered handler
- /// has finished executing, nor that cancellation requests have finished propagating
- /// to all registered handlers. Additional synchronization may be required,
- /// particularly in situations where related objects are being canceled concurrently.
- /// </para>
- /// </remarks>
- public bool IsCancellationRequested => _source != null && _source.IsCancellationRequested;
-
- /// <summary>
- /// Gets whether this token is capable of being in the canceled state.
- /// </summary>
- /// <remarks>
- /// If CanBeCanceled returns false, it is guaranteed that the token will never transition
- /// into a canceled state, meaning that <see cref="IsCancellationRequested"/> will never
- /// return true.
- /// </remarks>
- public bool CanBeCanceled => _source != null;
-
- /// <summary>
- /// Gets a <see cref="System.Threading.WaitHandle"/> that is signaled when the token is canceled.</summary>
- /// <remarks>
- /// Accessing this property causes a <see cref="System.Threading.WaitHandle">WaitHandle</see>
- /// to be instantiated. It is preferable to only use this property when necessary, and to then
- /// dispose the associated <see cref="CancellationTokenSource"/> instance at the earliest opportunity (disposing
- /// the source will dispose of this allocated handle). The handle should not be closed or disposed directly.
- /// </remarks>
- /// <exception cref="System.ObjectDisposedException">The associated <see
- /// cref="System.Threading.CancellationTokenSource">CancellationTokenSource</see> has been disposed.</exception>
- public WaitHandle WaitHandle => (_source ?? CancellationTokenSource.s_neverCanceledSource).WaitHandle;
-
- // public CancellationToken()
- // this constructor is implicit for structs
- // -> this should behaves exactly as for new CancellationToken(false)
-
- /// <summary>
- /// Internal constructor only a CancellationTokenSource should create a CancellationToken
- /// </summary>
- internal CancellationToken(CancellationTokenSource? source) => _source = source;
-
- /// <summary>
- /// Initializes the <see cref="System.Threading.CancellationToken">CancellationToken</see>.
- /// </summary>
- /// <param name="canceled">
- /// The canceled state for the token.
- /// </param>
- /// <remarks>
- /// Tokens created with this constructor will remain in the canceled state specified
- /// by the <paramref name="canceled"/> parameter. If <paramref name="canceled"/> is false,
- /// both <see cref="CanBeCanceled"/> and <see cref="IsCancellationRequested"/> will be false.
- /// If <paramref name="canceled"/> is true,
- /// both <see cref="CanBeCanceled"/> and <see cref="IsCancellationRequested"/> will be true.
- /// </remarks>
- public CancellationToken(bool canceled) : this(canceled ? CancellationTokenSource.s_canceledSource : null)
- {
- }
-
- /// <summary>
- /// Registers a delegate that will be called when this <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.
- /// </summary>
- /// <remarks>
- /// <para>
- /// If this token is already in the canceled state, the
- /// delegate will be run immediately and synchronously. Any exception the delegate generates will be
- /// propagated out of this method call.
- /// </para>
- /// <para>
- /// The current <see cref="System.Threading.ExecutionContext">ExecutionContext</see>, if one exists, will be captured
- /// along with the delegate and will be used when executing it.
- /// </para>
- /// </remarks>
- /// <param name="callback">The delegate to be executed when the <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.</param>
- /// <returns>The <see cref="System.Threading.CancellationTokenRegistration"/> instance that can
- /// be used to unregister the callback.</returns>
- /// <exception cref="System.ArgumentNullException"><paramref name="callback"/> is null.</exception>
- public CancellationTokenRegistration Register(Action callback) =>
- Register(
- s_actionToActionObjShunt,
- callback ?? throw new ArgumentNullException(nameof(callback)),
- useSynchronizationContext: false,
- useExecutionContext: true);
-
- /// <summary>
- /// Registers a delegate that will be called when this
- /// <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.
- /// </summary>
- /// <remarks>
- /// <para>
- /// If this token is already in the canceled state, the
- /// delegate will be run immediately and synchronously. Any exception the delegate generates will be
- /// propagated out of this method call.
- /// </para>
- /// <para>
- /// The current <see cref="System.Threading.ExecutionContext">ExecutionContext</see>, if one exists, will be captured
- /// along with the delegate and will be used when executing it.
- /// </para>
- /// </remarks>
- /// <param name="callback">The delegate to be executed when the <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.</param>
- /// <param name="useSynchronizationContext">A Boolean value that indicates whether to capture
- /// the current <see cref="System.Threading.SynchronizationContext">SynchronizationContext</see> and use it
- /// when invoking the <paramref name="callback"/>.</param>
- /// <returns>The <see cref="System.Threading.CancellationTokenRegistration"/> instance that can
- /// be used to unregister the callback.</returns>
- /// <exception cref="System.ArgumentNullException"><paramref name="callback"/> is null.</exception>
- public CancellationTokenRegistration Register(Action callback, bool useSynchronizationContext) =>
- Register(
- s_actionToActionObjShunt,
- callback ?? throw new ArgumentNullException(nameof(callback)),
- useSynchronizationContext,
- useExecutionContext: true);
-
- /// <summary>
- /// Registers a delegate that will be called when this
- /// <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.
- /// </summary>
- /// <remarks>
- /// <para>
- /// If this token is already in the canceled state, the
- /// delegate will be run immediately and synchronously. Any exception the delegate generates will be
- /// propagated out of this method call.
- /// </para>
- /// <para>
- /// The current <see cref="System.Threading.ExecutionContext">ExecutionContext</see>, if one exists, will be captured
- /// along with the delegate and will be used when executing it.
- /// </para>
- /// </remarks>
- /// <param name="callback">The delegate to be executed when the <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.</param>
- /// <param name="state">The state to pass to the <paramref name="callback"/> when the delegate is invoked. This may be null.</param>
- /// <returns>The <see cref="System.Threading.CancellationTokenRegistration"/> instance that can
- /// be used to unregister the callback.</returns>
- /// <exception cref="System.ArgumentNullException"><paramref name="callback"/> is null.</exception>
- public CancellationTokenRegistration Register(Action<object?> callback, object? state) =>
- Register(callback, state, useSynchronizationContext: false, useExecutionContext: true);
-
- /// <summary>
- /// Registers a delegate that will be called when this
- /// <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.
- /// </summary>
- /// <remarks>
- /// <para>
- /// If this token is already in the canceled state, the
- /// delegate will be run immediately and synchronously. Any exception the delegate generates will be
- /// propagated out of this method call.
- /// </para>
- /// <para>
- /// The current <see cref="System.Threading.ExecutionContext">ExecutionContext</see>, if one exists,
- /// will be captured along with the delegate and will be used when executing it.
- /// </para>
- /// </remarks>
- /// <param name="callback">The delegate to be executed when the <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.</param>
- /// <param name="state">The state to pass to the <paramref name="callback"/> when the delegate is invoked. This may be null.</param>
- /// <param name="useSynchronizationContext">A Boolean value that indicates whether to capture
- /// the current <see cref="System.Threading.SynchronizationContext">SynchronizationContext</see> and use it
- /// when invoking the <paramref name="callback"/>.</param>
- /// <returns>The <see cref="System.Threading.CancellationTokenRegistration"/> instance that can
- /// be used to unregister the callback.</returns>
- /// <exception cref="System.ArgumentNullException"><paramref name="callback"/> is null.</exception>
- /// <exception cref="System.ObjectDisposedException">The associated <see
- /// cref="System.Threading.CancellationTokenSource">CancellationTokenSource</see> has been disposed.</exception>
- public CancellationTokenRegistration Register(Action<object?> callback, object? state, bool useSynchronizationContext) =>
- Register(callback, state, useSynchronizationContext, useExecutionContext: true);
-
- /// <summary>
- /// Registers a delegate that will be called when this
- /// <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.
- /// </summary>
- /// <remarks>
- /// <para>
- /// If this token is already in the canceled state, the delegate will be run immediately and synchronously.
- /// Any exception the delegate generates will be propagated out of this method call.
- /// </para>
- /// <para>
- /// <see cref="System.Threading.ExecutionContext">ExecutionContext</see> is not captured nor flowed
- /// to the callback's invocation.
- /// </para>
- /// </remarks>
- /// <param name="callback">The delegate to be executed when the <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.</param>
- /// <param name="state">The state to pass to the <paramref name="callback"/> when the delegate is invoked. This may be null.</param>
- /// <returns>The <see cref="System.Threading.CancellationTokenRegistration"/> instance that can
- /// be used to unregister the callback.</returns>
- /// <exception cref="System.ArgumentNullException"><paramref name="callback"/> is null.</exception>
- public CancellationTokenRegistration UnsafeRegister(Action<object?> callback, object? state) =>
- Register(callback, state, useSynchronizationContext: false, useExecutionContext: false);
-
- /// <summary>
- /// Registers a delegate that will be called when this
- /// <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.
- /// </summary>
- /// <remarks>
- /// <para>
- /// If this token is already in the canceled state, the
- /// delegate will be run immediately and synchronously. Any exception the delegate generates will be
- /// propagated out of this method call.
- /// </para>
- /// </remarks>
- /// <param name="callback">The delegate to be executed when the <see cref="System.Threading.CancellationToken">CancellationToken</see> is canceled.</param>
- /// <param name="state">The state to pass to the <paramref name="callback"/> when the delegate is invoked. This may be null.</param>
- /// <param name="useSynchronizationContext">A Boolean value that indicates whether to capture
- /// the current <see cref="System.Threading.SynchronizationContext">SynchronizationContext</see> and use it
- /// when invoking the <paramref name="callback"/>.</param>
- /// <returns>The <see cref="System.Threading.CancellationTokenRegistration"/> instance that can
- /// be used to unregister the callback.</returns>
- /// <exception cref="System.ArgumentNullException"><paramref name="callback"/> is null.</exception>
- /// <exception cref="System.ObjectDisposedException">The associated <see
- /// cref="System.Threading.CancellationTokenSource">CancellationTokenSource</see> has been disposed.</exception>
- private CancellationTokenRegistration Register(Action<object?> callback, object? state, bool useSynchronizationContext, bool useExecutionContext)
- {
- if (callback == null)
- throw new ArgumentNullException(nameof(callback));
-
- CancellationTokenSource? source = _source;
- return source != null ?
- source.InternalRegister(callback, state, useSynchronizationContext ? SynchronizationContext.Current : null, useExecutionContext ? ExecutionContext.Capture() : null) :
- default; // Nothing to do for tokens than can never reach the canceled state. Give back a dummy registration.
- }
-
- /// <summary>
- /// Determines whether the current <see cref="System.Threading.CancellationToken">CancellationToken</see> instance is equal to the
- /// specified token.
- /// </summary>
- /// <param name="other">The other <see cref="System.Threading.CancellationToken">CancellationToken</see> to which to compare this
- /// instance.</param>
- /// <returns>True if the instances are equal; otherwise, false. Two tokens are equal if they are associated
- /// with the same <see cref="System.Threading.CancellationTokenSource">CancellationTokenSource</see> or if they were both constructed
- /// from public CancellationToken constructors and their <see cref="IsCancellationRequested"/> values are equal.</returns>
- public bool Equals(CancellationToken other) => _source == other._source;
-
- /// <summary>
- /// Determines whether the current <see cref="System.Threading.CancellationToken">CancellationToken</see> instance is equal to the
- /// specified <see cref="object"/>.
- /// </summary>
- /// <param name="other">The other object to which to compare this instance.</param>
- /// <returns>True if <paramref name="other"/> is a <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// and if the two instances are equal; otherwise, false. Two tokens are equal if they are associated
- /// with the same <see cref="System.Threading.CancellationTokenSource">CancellationTokenSource</see> or if they were both constructed
- /// from public CancellationToken constructors and their <see cref="IsCancellationRequested"/> values are equal.</returns>
- /// <exception cref="System.ObjectDisposedException">An associated <see
- /// cref="System.Threading.CancellationTokenSource">CancellationTokenSource</see> has been disposed.</exception>
- public override bool Equals(object? other) => other is CancellationToken && Equals((CancellationToken)other);
-
- /// <summary>
- /// Serves as a hash function for a <see cref="System.Threading.CancellationToken">CancellationToken</see>.
- /// </summary>
- /// <returns>A hash code for the current <see cref="System.Threading.CancellationToken">CancellationToken</see> instance.</returns>
- public override int GetHashCode() => (_source ?? CancellationTokenSource.s_neverCanceledSource).GetHashCode();
-
- /// <summary>
- /// Determines whether two <see cref="System.Threading.CancellationToken">CancellationToken</see> instances are equal.
- /// </summary>
- /// <param name="left">The first instance.</param>
- /// <param name="right">The second instance.</param>
- /// <returns>True if the instances are equal; otherwise, false.</returns>
- /// <exception cref="System.ObjectDisposedException">An associated <see
- /// cref="System.Threading.CancellationTokenSource">CancellationTokenSource</see> has been disposed.</exception>
- public static bool operator ==(CancellationToken left, CancellationToken right) => left.Equals(right);
-
- /// <summary>
- /// Determines whether two <see cref="System.Threading.CancellationToken">CancellationToken</see> instances are not equal.
- /// </summary>
- /// <param name="left">The first instance.</param>
- /// <param name="right">The second instance.</param>
- /// <returns>True if the instances are not equal; otherwise, false.</returns>
- /// <exception cref="System.ObjectDisposedException">An associated <see
- /// cref="System.Threading.CancellationTokenSource">CancellationTokenSource</see> has been disposed.</exception>
- public static bool operator !=(CancellationToken left, CancellationToken right) => !left.Equals(right);
-
- /// <summary>
- /// Throws a <see cref="System.OperationCanceledException">OperationCanceledException</see> if
- /// this token has had cancellation requested.
- /// </summary>
- /// <remarks>
- /// This method provides functionality equivalent to:
- /// <code>
- /// if (token.IsCancellationRequested)
- /// throw new OperationCanceledException(token);
- /// </code>
- /// </remarks>
- /// <exception cref="System.OperationCanceledException">The token has had cancellation requested.</exception>
- /// <exception cref="System.ObjectDisposedException">The associated <see
- /// cref="System.Threading.CancellationTokenSource">CancellationTokenSource</see> has been disposed.</exception>
- public void ThrowIfCancellationRequested()
- {
- if (IsCancellationRequested)
- ThrowOperationCanceledException();
- }
-
- // Throws an OCE; separated out to enable better inlining of ThrowIfCancellationRequested
- [DoesNotReturn]
- private void ThrowOperationCanceledException() =>
- throw new OperationCanceledException(SR.OperationCanceled, this);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenRegistration.cs b/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenRegistration.cs
deleted file mode 100644
index c078b7eb5c1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenRegistration.cs
+++ /dev/null
@@ -1,170 +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 System.Threading.Tasks;
-
-namespace System.Threading
-{
- /// <summary>
- /// Represents a callback delegate that has been registered with a <see cref="System.Threading.CancellationToken">CancellationToken</see>.
- /// </summary>
- /// <remarks>
- /// To unregister a callback, dispose the corresponding Registration instance.
- /// </remarks>
- public readonly struct CancellationTokenRegistration : IEquatable<CancellationTokenRegistration>, IDisposable, IAsyncDisposable
- {
- private readonly long _id;
- private readonly CancellationTokenSource.CallbackNode _node;
-
- internal CancellationTokenRegistration(long id, CancellationTokenSource.CallbackNode node)
- {
- _id = id;
- _node = node;
- }
-
- /// <summary>
- /// Disposes of the registration and unregisters the target callback from the associated
- /// <see cref="System.Threading.CancellationToken">CancellationToken</see>.
- /// If the target callback is currently executing, this method will wait until it completes, except
- /// in the degenerate cases where a callback method unregisters itself.
- /// </summary>
- public void Dispose()
- {
- CancellationTokenSource.CallbackNode node = _node;
- if (node != null && !node.Partition.Unregister(_id, node))
- {
- WaitForCallbackIfNecessary();
- }
- }
-
- /// <summary>
- /// Disposes of the registration and unregisters the target callback from the associated
- /// <see cref="System.Threading.CancellationToken">CancellationToken</see>.
- /// The returned <see cref="ValueTask"/> will complete once the associated callback
- /// is unregistered without having executed or once it's finished executing, except
- /// in the degenerate case where the callback itself is unregistering itself.
- /// </summary>
- public ValueTask DisposeAsync()
- {
- CancellationTokenSource.CallbackNode node = _node;
- return node != null && !node.Partition.Unregister(_id, node) ?
- WaitForCallbackIfNecessaryAsync() :
- default;
- }
-
- /// <summary>
- /// Gets the <see cref="CancellationToken"/> with which this registration is associated. If the
- /// registration isn't associated with a token (such as after the registration has been disposed),
- /// this will return a default token.
- /// </summary>
- public CancellationToken Token
- {
- get
- {
- CancellationTokenSource.CallbackNode node = _node;
- return node != null ?
- new CancellationToken(node.Partition.Source) : // avoid CTS.Token, which throws after disposal
- default;
- }
- }
-
- /// <summary>
- /// Disposes of the registration and unregisters the target callback from the associated
- /// <see cref="System.Threading.CancellationToken">CancellationToken</see>.
- /// </summary>
- public bool Unregister()
- {
- CancellationTokenSource.CallbackNode node = _node;
- return node != null && node.Partition.Unregister(_id, node);
- }
-
- private void WaitForCallbackIfNecessary()
- {
- // We're a valid registration but we were unable to unregister, which means the callback wasn't in the list,
- // which means either it already executed or it's currently executing. We guarantee that we will not return
- // if the callback is being executed (assuming we are not currently called by the callback itself)
- // We achieve this by the following rules:
- // 1. If we are called in the context of an executing callback, no need to wait (determined by tracking callback-executor threadID)
- // - if the currently executing callback is this CTR, then waiting would deadlock. (We choose to return rather than deadlock)
- // - if not, then this CTR cannot be the one executing, hence no need to wait
- // 2. If unregistration failed, and we are on a different thread, then the callback may be running under control of cts.Cancel()
- // => poll until cts.ExecutingCallback is not the one we are trying to unregister.
- CancellationTokenSource source = _node.Partition.Source;
- if (source.IsCancellationRequested && // Running callbacks has commenced.
- !source.IsCancellationCompleted && // Running callbacks hasn't finished.
- source.ThreadIDExecutingCallbacks != Environment.CurrentManagedThreadId) // The executing thread ID is not this thread's ID.
- {
- // Callback execution is in progress, the executing thread is different from this thread and has taken the callback for execution
- // so observe and wait until this target callback is no longer the executing callback.
- source.WaitForCallbackToComplete(_id);
- }
- }
-
- private ValueTask WaitForCallbackIfNecessaryAsync()
- {
- // Same as WaitForCallbackIfNecessary, except returning a task that'll be completed when callbacks complete.
-
- CancellationTokenSource source = _node.Partition.Source;
- if (source.IsCancellationRequested && // Running callbacks has commenced.
- !source.IsCancellationCompleted && // Running callbacks hasn't finished.
- source.ThreadIDExecutingCallbacks != Environment.CurrentManagedThreadId) // The executing thread ID is not this thread's ID.
- {
- // Callback execution is in progress, the executing thread is different from this thread and has taken the callback for execution
- // so get a task that'll complete when this target callback is no longer the executing callback.
- return source.WaitForCallbackToCompleteAsync(_id);
- }
-
- // Callback is either already completed, won't execute, or the callback itself is calling this.
- return default;
- }
-
- /// <summary>
- /// Determines whether two <see
- /// cref="System.Threading.CancellationTokenRegistration">CancellationTokenRegistration</see>
- /// instances are equal.
- /// </summary>
- /// <param name="left">The first instance.</param>
- /// <param name="right">The second instance.</param>
- /// <returns>True if the instances are equal; otherwise, false.</returns>
- public static bool operator ==(CancellationTokenRegistration left, CancellationTokenRegistration right) => left.Equals(right);
-
- /// <summary>
- /// Determines whether two <see cref="System.Threading.CancellationTokenRegistration">CancellationTokenRegistration</see> instances are not equal.
- /// </summary>
- /// <param name="left">The first instance.</param>
- /// <param name="right">The second instance.</param>
- /// <returns>True if the instances are not equal; otherwise, false.</returns>
- public static bool operator !=(CancellationTokenRegistration left, CancellationTokenRegistration right) => !left.Equals(right);
-
- /// <summary>
- /// Determines whether the current <see cref="System.Threading.CancellationTokenRegistration">CancellationTokenRegistration</see> instance is equal to the
- /// specified <see cref="object"/>.
- /// </summary>
- /// <param name="obj">The other object to which to compare this instance.</param>
- /// <returns>True, if both this and <paramref name="obj"/> are equal. False, otherwise.
- /// Two <see cref="System.Threading.CancellationTokenRegistration">CancellationTokenRegistration</see> instances are equal if
- /// they both refer to the output of a single call to the same Register method of a
- /// <see cref="System.Threading.CancellationToken">CancellationToken</see>.
- /// </returns>
- public override bool Equals(object? obj) => obj is CancellationTokenRegistration && Equals((CancellationTokenRegistration)obj);
-
- /// <summary>
- /// Determines whether the current <see cref="System.Threading.CancellationToken">CancellationToken</see> instance is equal to the
- /// specified <see cref="object"/>.
- /// </summary>
- /// <param name="other">The other <see cref="System.Threading.CancellationTokenRegistration">CancellationTokenRegistration</see> to which to compare this instance.</param>
- /// <returns>True, if both this and <paramref name="other"/> are equal. False, otherwise.
- /// Two <see cref="System.Threading.CancellationTokenRegistration">CancellationTokenRegistration</see> instances are equal if
- /// they both refer to the output of a single call to the same Register method of a
- /// <see cref="System.Threading.CancellationToken">CancellationToken</see>.
- /// </returns>
- public bool Equals(CancellationTokenRegistration other) => _node == other._node && _id == other._id;
-
- /// <summary>
- /// Serves as a hash function for a <see cref="System.Threading.CancellationTokenRegistration">CancellationTokenRegistration.</see>.
- /// </summary>
- /// <returns>A hash code for the current <see cref="System.Threading.CancellationTokenRegistration">CancellationTokenRegistration</see> instance.</returns>
- public override int GetHashCode() => _node != null ? _node.GetHashCode() ^ _id.GetHashCode() : _id.GetHashCode();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs b/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs
deleted file mode 100644
index 4577591dfcf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs
+++ /dev/null
@@ -1,1041 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Threading.Tasks;
-
-namespace System.Threading
-{
- /// <summary>Signals to a <see cref="CancellationToken"/> that it should be canceled.</summary>
- /// <remarks>
- /// <para>
- /// <see cref="CancellationTokenSource"/> is used to instantiate a <see cref="CancellationToken"/> (via
- /// the source's <see cref="Token">Token</see> property) that can be handed to operations that wish to be
- /// notified of cancellation or that can be used to register asynchronous operations for cancellation. That
- /// token may have cancellation requested by calling to the source's <see cref="Cancel()"/> method.
- /// </para>
- /// <para>
- /// All members of this class, except <see cref="Dispose()"/>, are thread-safe and may be used
- /// concurrently from multiple threads.
- /// </para>
- /// </remarks>
- public class CancellationTokenSource : IDisposable
- {
- /// <summary>A <see cref="CancellationTokenSource"/> that's already canceled.</summary>
- internal static readonly CancellationTokenSource s_canceledSource = new CancellationTokenSource() { _state = NotifyingCompleteState };
- /// <summary>A <see cref="CancellationTokenSource"/> that's never canceled. This isn't enforced programmatically, only by usage. Do not cancel!</summary>
- internal static readonly CancellationTokenSource s_neverCanceledSource = new CancellationTokenSource();
-
- /// <summary>Delegate used with <see cref="Timer"/> to trigger cancellation of a <see cref="CancellationTokenSource"/>.</summary>
- private static readonly TimerCallback s_timerCallback = obj =>
- {
- Debug.Assert(obj is CancellationTokenSource, $"Expected {typeof(CancellationTokenSource)}, got {obj}");
- ((CancellationTokenSource)obj).NotifyCancellation(throwOnFirstException: false); // skip ThrowIfDisposed() check in Cancel()
- };
-
- /// <summary>The number of callback partitions to use in a <see cref="CancellationTokenSource"/>. Must be a power of 2.</summary>
- private static readonly int s_numPartitions = GetPartitionCount();
- /// <summary><see cref="s_numPartitions"/> - 1, used to quickly mod into <see cref="_callbackPartitions"/>.</summary>
- private static readonly int s_numPartitionsMask = s_numPartitions - 1;
-
- /// <summary>The current state of the CancellationTokenSource.</summary>
- private volatile int _state;
- /// <summary>The ID of the thread currently executing the main body of CTS.Cancel()</summary>
- /// <remarks>
- /// This helps us to know if a call to ctr.Dispose() is running 'within' a cancellation callback.
- /// This is updated as we move between the main thread calling cts.Cancel() and any syncContexts
- /// that are used to actually run the callbacks.
- /// </remarks>
- private volatile int _threadIDExecutingCallbacks = -1;
- /// <summary>Tracks the running callback to assist ctr.Dispose() to wait for the target callback to complete.</summary>
- private long _executingCallbackId;
- /// <summary>Partitions of callbacks. Split into multiple partitions to help with scalability of registering/unregistering; each is protected by its own lock.</summary>
- private volatile CallbackPartition?[]? _callbackPartitions;
- /// <summary>TimerQueueTimer used by CancelAfter and Timer-related ctors. Used instead of Timer to avoid extra allocations and because the rooted behavior is desired.</summary>
- private volatile TimerQueueTimer? _timer;
- /// <summary><see cref="System.Threading.WaitHandle"/> lazily initialized and returned from <see cref="WaitHandle"/>.</summary>
- private volatile ManualResetEvent? _kernelEvent;
- /// <summary>Whether this <see cref="CancellationTokenSource"/> has been disposed.</summary>
- private bool _disposed;
-
- // legal values for _state
- private const int NotCanceledState = 1;
- private const int NotifyingState = 2;
- private const int NotifyingCompleteState = 3;
-
- /// <summary>Gets whether cancellation has been requested for this <see cref="CancellationTokenSource" />.</summary>
- /// <value>Whether cancellation has been requested for this <see cref="CancellationTokenSource" />.</value>
- /// <remarks>
- /// <para>
- /// This property indicates whether cancellation has been requested for this token source, such as
- /// due to a call to its <see cref="Cancel()"/> method.
- /// </para>
- /// <para>
- /// If this property returns true, it only guarantees that cancellation has been requested. It does not
- /// guarantee that every handler registered with the corresponding token has finished executing, nor
- /// that cancellation requests have finished propagating to all registered handlers. Additional
- /// synchronization may be required, particularly in situations where related objects are being
- /// canceled concurrently.
- /// </para>
- /// </remarks>
- public bool IsCancellationRequested => _state >= NotifyingState;
-
- /// <summary>A simple helper to determine whether cancellation has finished.</summary>
- internal bool IsCancellationCompleted => _state == NotifyingCompleteState;
-
- /// <summary>A simple helper to determine whether disposal has occurred.</summary>
- internal bool IsDisposed => _disposed;
-
- /// <summary>The ID of the thread that is running callbacks.</summary>
- internal int ThreadIDExecutingCallbacks
- {
- get => _threadIDExecutingCallbacks;
- set => _threadIDExecutingCallbacks = value;
- }
-
- /// <summary>Gets the <see cref="CancellationToken"/> associated with this <see cref="CancellationTokenSource"/>.</summary>
- /// <value>The <see cref="CancellationToken"/> associated with this <see cref="CancellationTokenSource"/>.</value>
- /// <exception cref="ObjectDisposedException">The token source has been disposed.</exception>
- public CancellationToken Token
- {
- get
- {
- ThrowIfDisposed();
- return new CancellationToken(this);
- }
- }
-
- internal WaitHandle WaitHandle
- {
- get
- {
- ThrowIfDisposed();
-
- // Return the handle if it was already allocated.
- if (_kernelEvent != null)
- {
- return _kernelEvent;
- }
-
- // Lazily-initialize the handle.
- var mre = new ManualResetEvent(false);
- if (Interlocked.CompareExchange(ref _kernelEvent, mre, null) != null)
- {
- mre.Dispose();
- }
-
- // There is a race condition between checking IsCancellationRequested and setting the event.
- // However, at this point, the kernel object definitely exists and the cases are:
- // 1. if IsCancellationRequested = true, then we will call Set()
- // 2. if IsCancellationRequested = false, then NotifyCancellation will see that the event exists, and will call Set().
- if (IsCancellationRequested)
- {
- _kernelEvent.Set();
- }
-
- return _kernelEvent;
- }
- }
-
-
- /// <summary>Gets the ID of the currently executing callback.</summary>
- internal long ExecutingCallback => Volatile.Read(ref _executingCallbackId);
-
- /// <summary>Initializes the <see cref="CancellationTokenSource"/>.</summary>
- public CancellationTokenSource() => _state = NotCanceledState;
-
- /// <summary>
- /// Constructs a <see cref="CancellationTokenSource"/> that will be canceled after a specified time span.
- /// </summary>
- /// <param name="delay">The time span to wait before canceling this <see cref="CancellationTokenSource"/></param>
- /// <exception cref="ArgumentOutOfRangeException">
- /// The exception that is thrown when <paramref name="delay"/> is less than -1 or greater than int.MaxValue.
- /// </exception>
- /// <remarks>
- /// <para>
- /// The countdown for the delay starts during the call to the constructor. When the delay expires,
- /// the constructed <see cref="CancellationTokenSource"/> is canceled, if it has
- /// not been canceled already.
- /// </para>
- /// <para>
- /// Subsequent calls to CancelAfter will reset the delay for the constructed
- /// <see cref="CancellationTokenSource"/>, if it has not been
- /// canceled already.
- /// </para>
- /// </remarks>
- public CancellationTokenSource(TimeSpan delay)
- {
- long totalMilliseconds = (long)delay.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- throw new ArgumentOutOfRangeException(nameof(delay));
- }
-
- InitializeWithTimer((int)totalMilliseconds);
- }
-
- /// <summary>
- /// Constructs a <see cref="CancellationTokenSource"/> that will be canceled after a specified time span.
- /// </summary>
- /// <param name="millisecondsDelay">The time span to wait before canceling this <see cref="CancellationTokenSource"/></param>
- /// <exception cref="ArgumentOutOfRangeException">
- /// The exception that is thrown when <paramref name="millisecondsDelay"/> is less than -1.
- /// </exception>
- /// <remarks>
- /// <para>
- /// The countdown for the millisecondsDelay starts during the call to the constructor. When the millisecondsDelay expires,
- /// the constructed <see cref="CancellationTokenSource"/> is canceled (if it has
- /// not been canceled already).
- /// </para>
- /// <para>
- /// Subsequent calls to CancelAfter will reset the millisecondsDelay for the constructed
- /// <see cref="CancellationTokenSource"/>, if it has not been
- /// canceled already.
- /// </para>
- /// </remarks>
- public CancellationTokenSource(int millisecondsDelay)
- {
- if (millisecondsDelay < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(millisecondsDelay));
- }
-
- InitializeWithTimer(millisecondsDelay);
- }
-
- /// <summary>
- /// Common initialization logic when constructing a CTS with a delay parameter.
- /// A zero delay will result in immediate cancellation.
- /// </summary>
- private void InitializeWithTimer(int millisecondsDelay)
- {
- if (millisecondsDelay == 0)
- {
- _state = NotifyingCompleteState;
- }
- else
- {
- _state = NotCanceledState;
- _timer = new TimerQueueTimer(s_timerCallback, this, (uint)millisecondsDelay, Timeout.UnsignedInfinite, flowExecutionContext: false);
-
- // The timer roots this CTS instance while it's scheduled. That is by design, so
- // that code like:
- // CancellationToken ct = new CancellationTokenSource(timeout).Token;
- // will successfully cancel the token after the timeout.
- }
- }
-
- /// <summary>Communicates a request for cancellation.</summary>
- /// <remarks>
- /// <para>
- /// The associated <see cref="CancellationToken" /> will be notified of the cancellation
- /// and will transition to a state where <see cref="CancellationToken.IsCancellationRequested"/> returns true.
- /// Any callbacks or cancelable operations registered with the <see cref="CancellationToken"/> will be executed.
- /// </para>
- /// <para>
- /// Cancelable operations and callbacks registered with the token should not throw exceptions.
- /// However, this overload of Cancel will aggregate any exceptions thrown into a <see cref="AggregateException"/>,
- /// such that one callback throwing an exception will not prevent other registered callbacks from being executed.
- /// </para>
- /// <para>
- /// The <see cref="ExecutionContext"/> that was captured when each callback was registered
- /// will be reestablished when the callback is invoked.
- /// </para>
- /// </remarks>
- /// <exception cref="AggregateException">An aggregate exception containing all the exceptions thrown
- /// by the registered callbacks on the associated <see cref="CancellationToken"/>.</exception>
- /// <exception cref="ObjectDisposedException">This <see cref="CancellationTokenSource"/> has been disposed.</exception>
- public void Cancel() => Cancel(false);
-
- /// <summary>Communicates a request for cancellation.</summary>
- /// <remarks>
- /// <para>
- /// The associated <see cref="CancellationToken" /> will be notified of the cancellation and will transition to a state where
- /// <see cref="CancellationToken.IsCancellationRequested"/> returns true. Any callbacks or cancelable operationsregistered
- /// with the <see cref="CancellationToken"/> will be executed.
- /// </para>
- /// <para>
- /// Cancelable operations and callbacks registered with the token should not throw exceptions.
- /// If <paramref name="throwOnFirstException"/> is true, an exception will immediately propagate out of the
- /// call to Cancel, preventing the remaining callbacks and cancelable operations from being processed.
- /// If <paramref name="throwOnFirstException"/> is false, this overload will aggregate any
- /// exceptions thrown into a <see cref="AggregateException"/>,
- /// such that one callback throwing an exception will not prevent other registered callbacks from being executed.
- /// </para>
- /// <para>
- /// The <see cref="ExecutionContext"/> that was captured when each callback was registered
- /// will be reestablished when the callback is invoked.
- /// </para>
- /// </remarks>
- /// <param name="throwOnFirstException">Specifies whether exceptions should immediately propagate.</param>
- /// <exception cref="AggregateException">An aggregate exception containing all the exceptions thrown
- /// by the registered callbacks on the associated <see cref="CancellationToken"/>.</exception>
- /// <exception cref="ObjectDisposedException">This <see cref="CancellationTokenSource"/> has been disposed.</exception>
- public void Cancel(bool throwOnFirstException)
- {
- ThrowIfDisposed();
- NotifyCancellation(throwOnFirstException);
- }
-
- /// <summary>Schedules a Cancel operation on this <see cref="CancellationTokenSource"/>.</summary>
- /// <param name="delay">The time span to wait before canceling this <see cref="CancellationTokenSource"/>.
- /// </param>
- /// <exception cref="ObjectDisposedException">The exception thrown when this <see
- /// cref="CancellationTokenSource"/> has been disposed.
- /// </exception>
- /// <exception cref="ArgumentOutOfRangeException">
- /// The exception thrown when <paramref name="delay"/> is less than -1 or
- /// greater than int.MaxValue.
- /// </exception>
- /// <remarks>
- /// <para>
- /// The countdown for the delay starts during this call. When the delay expires,
- /// this <see cref="CancellationTokenSource"/> is canceled, if it has
- /// not been canceled already.
- /// </para>
- /// <para>
- /// Subsequent calls to CancelAfter will reset the delay for this
- /// <see cref="CancellationTokenSource"/>, if it has not been canceled already.
- /// </para>
- /// </remarks>
- public void CancelAfter(TimeSpan delay)
- {
- long totalMilliseconds = (long)delay.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- throw new ArgumentOutOfRangeException(nameof(delay));
- }
-
- CancelAfter((int)totalMilliseconds);
- }
-
- /// <summary>
- /// Schedules a Cancel operation on this <see cref="CancellationTokenSource"/>.
- /// </summary>
- /// <param name="millisecondsDelay">The time span to wait before canceling this <see
- /// cref="CancellationTokenSource"/>.
- /// </param>
- /// <exception cref="ObjectDisposedException">The exception thrown when this <see
- /// cref="CancellationTokenSource"/> has been disposed.
- /// </exception>
- /// <exception cref="ArgumentOutOfRangeException">
- /// The exception thrown when <paramref name="millisecondsDelay"/> is less than -1.
- /// </exception>
- /// <remarks>
- /// <para>
- /// The countdown for the millisecondsDelay starts during this call. When the millisecondsDelay expires,
- /// this <see cref="CancellationTokenSource"/> is canceled, if it has
- /// not been canceled already.
- /// </para>
- /// <para>
- /// Subsequent calls to CancelAfter will reset the millisecondsDelay for this
- /// <see cref="CancellationTokenSource"/>, if it has not been
- /// canceled already.
- /// </para>
- /// </remarks>
- public void CancelAfter(int millisecondsDelay)
- {
- ThrowIfDisposed();
-
- if (millisecondsDelay < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(millisecondsDelay));
- }
-
- if (IsCancellationRequested)
- {
- return;
- }
-
- // There is a race condition here as a Cancel could occur between the check of
- // IsCancellationRequested and the creation of the timer. This is benign; in the
- // worst case, a timer will be created that has no effect when it expires.
-
- // Also, if Dispose() is called right here (after ThrowIfDisposed(), before timer
- // creation), it would result in a leaked Timer object (at least until the timer
- // expired and Disposed itself). But this would be considered bad behavior, as
- // Dispose() is not thread-safe and should not be called concurrently with CancelAfter().
-
- TimerQueueTimer? timer = _timer;
- if (timer == null)
- {
- // Lazily initialize the timer in a thread-safe fashion.
- // Initially set to "never go off" because we don't want to take a
- // chance on a timer "losing" the initialization and then
- // cancelling the token before it (the timer) can be disposed.
- timer = new TimerQueueTimer(s_timerCallback, this, Timeout.UnsignedInfinite, Timeout.UnsignedInfinite, flowExecutionContext: false);
- TimerQueueTimer? currentTimer = Interlocked.CompareExchange(ref _timer, timer, null);
- if (currentTimer != null)
- {
- // We did not initialize the timer. Dispose the new timer.
- timer.Close();
- timer = currentTimer;
- }
- }
-
- // It is possible that _timer has already been disposed, so we must do
- // the following in a try/catch block.
- try
- {
- timer.Change((uint)millisecondsDelay, Timeout.UnsignedInfinite);
- }
- catch (ObjectDisposedException)
- {
- // Just eat the exception. There is no other way to tell that
- // the timer has been disposed, and even if there were, there
- // would not be a good way to deal with the observe/dispose
- // race condition.
- }
- }
-
-
-
- /// <summary>Releases the resources used by this <see cref="CancellationTokenSource" />.</summary>
- /// <remarks>This method is not thread-safe for any other concurrent calls.</remarks>
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- /// <summary>
- /// Releases the unmanaged resources used by the <see cref="CancellationTokenSource" /> class and optionally releases the managed resources.
- /// </summary>
- /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
- protected virtual void Dispose(bool disposing)
- {
- if (disposing && !_disposed)
- {
- // We specifically tolerate that a callback can be unregistered
- // after the CTS has been disposed and/or concurrently with cts.Dispose().
- // This is safe without locks because Dispose doesn't interact with values
- // in the callback partitions, only nulling out the ref to existing partitions.
- //
- // We also tolerate that a callback can be registered after the CTS has been
- // disposed. This is safe because InternalRegister is tolerant
- // of _callbackPartitions becoming null during its execution. However,
- // we run the acceptable risk of _callbackPartitions getting reinitialized
- // to non-null if there is a race between Dispose and Register, in which case this
- // instance may unnecessarily hold onto a registered callback. But that's no worse
- // than if Dispose wasn't safe to use concurrently, as Dispose would never be called,
- // and thus no handlers would be dropped.
- //
- // And, we tolerate Dispose being used concurrently with Cancel. This is necessary
- // to properly support, e.g., LinkedCancellationTokenSource, where, due to common usage patterns,
- // it's possible for this pairing to occur with valid usage (e.g. a component accepts
- // an external CancellationToken and uses CreateLinkedTokenSource to combine it with an
- // internal source of cancellation, then Disposes of that linked source, which could
- // happen at the same time the external entity is requesting cancellation).
-
- TimerQueueTimer? timer = _timer;
- if (timer != null)
- {
- _timer = null;
- timer.Close(); // TimerQueueTimer.Close is thread-safe
- }
-
- _callbackPartitions = null; // free for GC; Cancel correctly handles a null field
-
- // If a kernel event was created via WaitHandle, we'd like to Dispose of it. However,
- // we only want to do so if it's not being used by Cancel concurrently. First, we
- // interlocked exchange it to be null, and then we check whether cancellation is currently
- // in progress. NotifyCancellation will only try to set the event if it exists after it's
- // transitioned to and while it's in the NotifyingState.
- if (_kernelEvent != null)
- {
- ManualResetEvent? mre = Interlocked.Exchange<ManualResetEvent?>(ref _kernelEvent!, null);
- if (mre != null && _state != NotifyingState)
- {
- mre.Dispose();
- }
- }
-
- _disposed = true;
- }
- }
-
- /// <summary>Throws an exception if the source has been disposed.</summary>
- private void ThrowIfDisposed()
- {
- if (_disposed)
- {
- ThrowObjectDisposedException();
- }
- }
-
- /// <summary>Throws an <see cref="ObjectDisposedException"/>. Separated out from ThrowIfDisposed to help with inlining.</summary>
- [DoesNotReturn]
- private static void ThrowObjectDisposedException() =>
- throw new ObjectDisposedException(null, SR.CancellationTokenSource_Disposed);
-
- /// <summary>
- /// Registers a callback object. If cancellation has already occurred, the
- /// callback will have been run by the time this method returns.
- /// </summary>
- internal CancellationTokenRegistration InternalRegister(
- Action<object?> callback, object? stateForCallback, SynchronizationContext? syncContext, ExecutionContext? executionContext)
- {
- Debug.Assert(this != s_neverCanceledSource, "This source should never be exposed via a CancellationToken.");
-
- // If not canceled, register the handler; if canceled already, run the callback synchronously.
- // This also ensures that during ExecuteCallbackHandlers() there will be no mutation of the _callbackPartitions.
- if (!IsCancellationRequested)
- {
- // In order to enable code to not leak too many handlers, we allow Dispose to be called concurrently
- // with Register. While this is not a recommended practice, consumers can and do use it this way.
- // We don't make any guarantees about whether the CTS will hold onto the supplied callback if the CTS
- // has already been disposed when the callback is registered, but we try not to while at the same time
- // not paying any non-negligible overhead. The simple compromise is to check whether we're disposed
- // (not volatile), and if we see we are, to return an empty registration. If there's a race and _disposed
- // is false even though it's been disposed, or if the disposal request comes in after this line, we simply
- // run the minor risk of having _callbackPartitions reinitialized (after it was cleared to null during Dispose).
- if (_disposed)
- {
- return default;
- }
-
- // Get the partitions...
- CallbackPartition?[]? partitions = _callbackPartitions;
- if (partitions == null)
- {
- partitions = new CallbackPartition[s_numPartitions];
- partitions = Interlocked.CompareExchange(ref _callbackPartitions, partitions, null) ?? partitions;
- }
-
- // ...and determine which partition to use.
- int partitionIndex = Environment.CurrentManagedThreadId & s_numPartitionsMask;
- Debug.Assert(partitionIndex < partitions.Length, $"Expected {partitionIndex} to be less than {partitions.Length}");
- CallbackPartition? partition = partitions[partitionIndex];
- if (partition == null)
- {
- partition = new CallbackPartition(this);
- partition = Interlocked.CompareExchange(ref partitions[partitionIndex], partition, null) ?? partition;
- }
-
- // Store the callback information into the callback arrays.
- long id;
- CallbackNode? node;
- bool lockTaken = false;
- partition.Lock.Enter(ref lockTaken);
- try
- {
- // Assign the next available unique ID.
- id = partition.NextAvailableId++;
-
- // Get a node, from the free list if possible or else a new one.
- node = partition.FreeNodeList;
- if (node != null)
- {
- partition.FreeNodeList = node.Next;
- Debug.Assert(node.Prev == null, "Nodes in the free list should all have a null Prev");
- // node.Next will be overwritten below so no need to set it here.
- }
- else
- {
- node = new CallbackNode(partition);
- }
-
- // Configure the node.
- node.Id = id;
- node.Callback = callback;
- node.CallbackState = stateForCallback;
- node.ExecutionContext = executionContext;
- node.SynchronizationContext = syncContext;
-
- // Add it to the callbacks list.
- node.Next = partition.Callbacks;
- if (node.Next != null)
- {
- node.Next.Prev = node;
- }
- partition.Callbacks = node;
- }
- finally
- {
- partition.Lock.Exit(useMemoryBarrier: false); // no check on lockTaken needed without thread aborts
- }
-
- // If cancellation hasn't been requested, return the registration.
- // if cancellation has been requested, try to undo the registration and run the callback
- // ourselves, but if we can't unregister it (e.g. the thread running Cancel snagged
- // our callback for execution), return the registration so that the caller can wait
- // for callback completion in ctr.Dispose().
- var ctr = new CancellationTokenRegistration(id, node);
- if (!IsCancellationRequested || !partition.Unregister(id, node))
- {
- return ctr;
- }
- }
-
- // Cancellation already occurred. Run the callback on this thread and return an empty registration.
- callback(stateForCallback);
- return default;
- }
-
- private void NotifyCancellation(bool throwOnFirstException)
- {
- // If we're the first to signal cancellation, do the main extra work.
- if (!IsCancellationRequested && Interlocked.CompareExchange(ref _state, NotifyingState, NotCanceledState) == NotCanceledState)
- {
- // Dispose of the timer, if any. Dispose may be running concurrently here, but TimerQueueTimer.Close is thread-safe.
- TimerQueueTimer? timer = _timer;
- if (timer != null)
- {
- _timer = null;
- timer.Close();
- }
-
- // Set the event if it's been lazily initialized and hasn't yet been disposed of. Dispose may
- // be running concurrently, in which case either it'll have set m_kernelEvent back to null and
- // we won't see it here, or it'll see that we've transitioned to NOTIFYING and will skip disposing it,
- // leaving cleanup to finalization.
- _kernelEvent?.Set(); // update the MRE value.
-
- // - late enlisters to the Canceled event will have their callbacks called immediately in the Register() methods.
- // - Callbacks are not called inside a lock.
- // - After transition, no more delegates will be added to the
- // - list of handlers, and hence it can be consumed and cleared at leisure by ExecuteCallbackHandlers.
- ExecuteCallbackHandlers(throwOnFirstException);
- Debug.Assert(IsCancellationCompleted, "Expected cancellation to have finished");
- }
- }
-
- /// <summary>Invoke all registered callbacks.</summary>
- /// <remarks>The handlers are invoked synchronously in LIFO order.</remarks>
- private void ExecuteCallbackHandlers(bool throwOnFirstException)
- {
- Debug.Assert(IsCancellationRequested, "ExecuteCallbackHandlers should only be called after setting IsCancellationRequested->true");
-
- // Record the threadID being used for running the callbacks.
- ThreadIDExecutingCallbacks = Environment.CurrentManagedThreadId;
-
- // If there are no callbacks to run, we can safely exit. Any race conditions to lazy initialize it
- // will see IsCancellationRequested and will then run the callback themselves.
- CallbackPartition?[]? partitions = Interlocked.Exchange(ref _callbackPartitions, null);
- if (partitions == null)
- {
- Interlocked.Exchange(ref _state, NotifyingCompleteState);
- return;
- }
-
- List<Exception>? exceptionList = null;
- try
- {
- // For each partition, and each callback in that partition, execute the associated handler.
- // We call the delegates in LIFO order on each partition so that callbacks fire 'deepest first'.
- // This is intended to help with nesting scenarios so that child enlisters cancel before their parents.
- foreach (CallbackPartition? partition in partitions)
- {
- if (partition == null)
- {
- // Uninitialized partition. Nothing to do.
- continue;
- }
-
- // Iterate through all nodes in the partition. We remove each node prior
- // to processing it. This allows for unregistration of subsequent registrations
- // to still be effective even as other registrations are being invoked.
- while (true)
- {
- CallbackNode? node;
- bool lockTaken = false;
- partition.Lock.Enter(ref lockTaken);
- try
- {
- // Pop the next registration from the callbacks list.
- node = partition.Callbacks;
- if (node == null)
- {
- // No more registrations to process.
- break;
- }
- else
- {
- Debug.Assert(node.Prev == null);
- if (node.Next != null) node.Next.Prev = null;
- partition.Callbacks = node.Next;
- }
-
- // Publish the intended callback ID, to ensure ctr.Dispose can tell if a wait is necessary.
- // This write happens while the lock is held so that Dispose is either able to successfully
- // unregister or is guaranteed to see an accurate executing callback ID, since it takes
- // the same lock to remove the node from the callback list.
- _executingCallbackId = node.Id;
-
- // Now that we've grabbed the Id, reset the node's Id to 0. This signals
- // to code unregistering that the node is no longer associated with a callback.
- node.Id = 0;
- }
- finally
- {
- partition.Lock.Exit(useMemoryBarrier: false); // no check on lockTaken needed without thread aborts
- }
-
- // Invoke the callback on this thread if there's no sync context or on the
- // target sync context if there is one.
- try
- {
- if (node.SynchronizationContext != null)
- {
- // Transition to the target syncContext and continue there.
- node.SynchronizationContext.Send(s =>
- {
- var n = (CallbackNode)s!;
- n.Partition.Source.ThreadIDExecutingCallbacks = Environment.CurrentManagedThreadId;
- n.ExecuteCallback();
- }, node);
- ThreadIDExecutingCallbacks = Environment.CurrentManagedThreadId; // above may have altered ThreadIDExecutingCallbacks, so reset it
- }
- else
- {
- node.ExecuteCallback();
- }
- }
- catch (Exception ex) when (!throwOnFirstException)
- {
- // Store the exception and continue
- (exceptionList ??= new List<Exception>()).Add(ex);
- }
-
- // Drop the node. While we could add it to the free list, doing so has cost (we'd need to take the lock again)
- // and very limited value. Since a source can only be canceled once, and after it's canceled registrations don't
- // need nodes, the only benefit to putting this on the free list would be if Register raced with cancellation
- // occurring, such that it could have used this free node but would instead need to allocate a new node (if
- // there wasn't another free node available).
- }
- }
- }
- finally
- {
- _state = NotifyingCompleteState;
- Volatile.Write(ref _executingCallbackId, 0);
- Interlocked.MemoryBarrier(); // for safety, prevent reorderings crossing this point and seeing inconsistent state.
- }
-
- if (exceptionList != null)
- {
- Debug.Assert(exceptionList.Count > 0, $"Expected {exceptionList.Count} > 0");
- throw new AggregateException(exceptionList);
- }
- }
-
- /// <summary>Gets the number of callback partitions to use based on the number of cores.</summary>
- /// <returns>A power of 2 representing the number of partitions to use.</returns>
- private static int GetPartitionCount()
- {
- int procs = Environment.ProcessorCount;
- int count =
- procs > 8 ? 16 : // capped at 16 to limit memory usage on larger machines
- procs > 4 ? 8 :
- procs > 2 ? 4 :
- procs > 1 ? 2 :
- 1;
- Debug.Assert(count > 0 && (count & (count - 1)) == 0, $"Got {count}, but expected a power of 2");
- return count;
- }
-
- /// <summary>
- /// Creates a <see cref="CancellationTokenSource"/> that will be in the canceled state
- /// when any of the source tokens are in the canceled state.
- /// </summary>
- /// <param name="token1">The first <see cref="CancellationToken">CancellationToken</see> to observe.</param>
- /// <param name="token2">The second <see cref="CancellationToken">CancellationToken</see> to observe.</param>
- /// <returns>A <see cref="CancellationTokenSource"/> that is linked
- /// to the source tokens.</returns>
- public static CancellationTokenSource CreateLinkedTokenSource(CancellationToken token1, CancellationToken token2) =>
- !token1.CanBeCanceled ? CreateLinkedTokenSource(token2) :
- token2.CanBeCanceled ? new Linked2CancellationTokenSource(token1, token2) :
- (CancellationTokenSource)new Linked1CancellationTokenSource(token1);
-
- /// <summary>
- /// Creates a <see cref="CancellationTokenSource"/> that will be in the canceled state
- /// when any of the source tokens are in the canceled state.
- /// </summary>
- /// <param name="token">The first <see cref="CancellationToken">CancellationToken</see> to observe.</param>
- /// <returns>A <see cref="CancellationTokenSource"/> that is linked to the source tokens.</returns>
- internal static CancellationTokenSource CreateLinkedTokenSource(CancellationToken token) =>
- token.CanBeCanceled ? new Linked1CancellationTokenSource(token) : new CancellationTokenSource();
-
- /// <summary>
- /// Creates a <see cref="CancellationTokenSource"/> that will be in the canceled state
- /// when any of the source tokens are in the canceled state.
- /// </summary>
- /// <param name="tokens">The <see cref="CancellationToken">CancellationToken</see> instances to observe.</param>
- /// <returns>A <see cref="CancellationTokenSource"/> that is linked to the source tokens.</returns>
- /// <exception cref="System.ArgumentNullException"><paramref name="tokens"/> is null.</exception>
- public static CancellationTokenSource CreateLinkedTokenSource(params CancellationToken[] tokens)
- {
- if (tokens == null)
- {
- throw new ArgumentNullException(nameof(tokens));
- }
-
- return tokens.Length switch
- {
- 0 => throw new ArgumentException(SR.CancellationToken_CreateLinkedToken_TokensIsEmpty),
- 1 => CreateLinkedTokenSource(tokens[0]),
- 2 => CreateLinkedTokenSource(tokens[0], tokens[1]),
-
- // a defensive copy is not required as the array has value-items that have only a single reference field,
- // hence each item cannot be null itself, and reads of the payloads cannot be torn.
- _ => new LinkedNCancellationTokenSource(tokens),
- };
- }
-
- /// <summary>
- /// Wait for a single callback to complete (or, more specifically, to not be running).
- /// It is ok to call this method if the callback has already finished.
- /// Calling this method before the target callback has been selected for execution would be an error.
- /// </summary>
- internal void WaitForCallbackToComplete(long id)
- {
- SpinWait sw = default;
- while (ExecutingCallback == id)
- {
- sw.SpinOnce(); // spin, as we assume callback execution is fast and that this situation is rare.
- }
- }
-
- /// <summary>
- /// Asynchronously wait for a single callback to complete (or, more specifically, to not be running).
- /// It is ok to call this method if the callback has already finished.
- /// Calling this method before the target callback has been selected for execution would be an error.
- /// </summary>
- internal ValueTask WaitForCallbackToCompleteAsync(long id)
- {
- // If the currently executing callback is not the target one, then the target one has already
- // completed and we can simply return. This should be the most common case, as the caller
- // calls if we're currently canceling but doesn't know what callback is running, if any.
- if (ExecutingCallback != id)
- {
- return default;
- }
-
- // The specified callback is actually running: queue a task that'll poll for the currently
- // executing callback to complete. In general scheduling such a work item that polls is a really
- // unfortunate thing to do. However, we expect this to be a rare case (disposing while the associated
- // callback is running), and brief when it happens (so the polling will be minimal), and making
- // this work with a callback mechanism will add additional cost to other more common cases.
- return new ValueTask(Task.Factory.StartNew(s =>
- {
- Debug.Assert(s is Tuple<CancellationTokenSource, long>);
- var state = (Tuple<CancellationTokenSource, long>)s;
- state.Item1.WaitForCallbackToComplete(state.Item2);
- }, Tuple.Create(this, id), CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default));
- }
-
- private sealed class Linked1CancellationTokenSource : CancellationTokenSource
- {
- private readonly CancellationTokenRegistration _reg1;
-
- internal Linked1CancellationTokenSource(CancellationToken token1)
- {
- _reg1 = token1.UnsafeRegister(LinkedNCancellationTokenSource.s_linkedTokenCancelDelegate, this);
- }
-
- protected override void Dispose(bool disposing)
- {
- if (!disposing || _disposed)
- {
- return;
- }
-
- _reg1.Dispose();
- base.Dispose(disposing);
- }
- }
-
- private sealed class Linked2CancellationTokenSource : CancellationTokenSource
- {
- private readonly CancellationTokenRegistration _reg1;
- private readonly CancellationTokenRegistration _reg2;
-
- internal Linked2CancellationTokenSource(CancellationToken token1, CancellationToken token2)
- {
- _reg1 = token1.UnsafeRegister(LinkedNCancellationTokenSource.s_linkedTokenCancelDelegate, this);
- _reg2 = token2.UnsafeRegister(LinkedNCancellationTokenSource.s_linkedTokenCancelDelegate, this);
- }
-
- protected override void Dispose(bool disposing)
- {
- if (!disposing || _disposed)
- {
- return;
- }
-
- _reg1.Dispose();
- _reg2.Dispose();
- base.Dispose(disposing);
- }
- }
-
- private sealed class LinkedNCancellationTokenSource : CancellationTokenSource
- {
- internal static readonly Action<object?> s_linkedTokenCancelDelegate = s =>
- {
- Debug.Assert(s is CancellationTokenSource, $"Expected {typeof(CancellationTokenSource)}, got {s}");
- ((CancellationTokenSource)s).NotifyCancellation(throwOnFirstException: false); // skip ThrowIfDisposed() check in Cancel()
- };
- private CancellationTokenRegistration[]? _linkingRegistrations;
-
- internal LinkedNCancellationTokenSource(params CancellationToken[] tokens)
- {
- _linkingRegistrations = new CancellationTokenRegistration[tokens.Length];
-
- for (int i = 0; i < tokens.Length; i++)
- {
- if (tokens[i].CanBeCanceled)
- {
- _linkingRegistrations[i] = tokens[i].UnsafeRegister(s_linkedTokenCancelDelegate, this);
- }
- // Empty slots in the array will be default(CancellationTokenRegistration), which are nops to Dispose.
- // Based on usage patterns, such occurrences should also be rare, such that it's not worth resizing
- // the array and incurring the related costs.
- }
- }
-
- protected override void Dispose(bool disposing)
- {
- if (!disposing || _disposed)
- {
- return;
- }
-
- CancellationTokenRegistration[]? linkingRegistrations = _linkingRegistrations;
- if (linkingRegistrations != null)
- {
- _linkingRegistrations = null; // release for GC once we're done enumerating
- for (int i = 0; i < linkingRegistrations.Length; i++)
- {
- linkingRegistrations[i].Dispose();
- }
- }
-
- base.Dispose(disposing);
- }
- }
-
- internal sealed class CallbackPartition
- {
- /// <summary>The associated source that owns this partition.</summary>
- public readonly CancellationTokenSource Source;
- /// <summary>Lock that protects all state in the partition.</summary>
- public SpinLock Lock = new SpinLock(enableThreadOwnerTracking: false); // mutable struct; do not make this readonly
- /// <summary>Doubly-linked list of callbacks registered with the partition. Callbacks are removed during unregistration and as they're invoked.</summary>
- public CallbackNode? Callbacks;
- /// <summary>Singly-linked list of free nodes that can be used for subsequent callback registrations.</summary>
- public CallbackNode? FreeNodeList;
- /// <summary>Every callback is assigned a unique, never-reused ID. This defines the next available ID.</summary>
- public long NextAvailableId = 1; // avoid using 0, as that's the default long value and used to represent an empty node
-
- public CallbackPartition(CancellationTokenSource source)
- {
- Debug.Assert(source != null, "Expected non-null source");
- Source = source;
- }
-
- internal bool Unregister(long id, CallbackNode node)
- {
- Debug.Assert(id != 0, "Expected non-zero id");
- Debug.Assert(node != null, "Expected non-null node");
-
- bool lockTaken = false;
- Lock.Enter(ref lockTaken);
- try
- {
- if (node.Id != id)
- {
- // Either:
- // - The callback is currently or has already been invoked, in which case node.Id
- // will no longer equal the assigned id, as it will have transitioned to 0.
- // - The registration was already disposed of, in which case node.Id will similarly
- // no longer equal the assigned id, as it will have transitioned to 0 and potentially
- // then to another (larger) value when reused for a new registration.
- // In either case, there's nothing to unregister.
- return false;
- }
-
- // The registration must still be in the callbacks list. Remove it.
- if (Callbacks == node)
- {
- Debug.Assert(node.Prev == null);
- Callbacks = node.Next;
- }
- else
- {
- Debug.Assert(node.Prev != null);
- node.Prev.Next = node.Next;
- }
-
- if (node.Next != null)
- {
- node.Next.Prev = node.Prev;
- }
-
- // Clear out the now unused node and put it on the singly-linked free list.
- // The only field we don't clear out is the associated Partition, as that's fixed
- // throughout the nodes lifetime, regardless of how many times its reused by
- // the same partition (it's never used on a different partition).
- node.Id = 0;
- node.Callback = null;
- node.CallbackState = null;
- node.ExecutionContext = null;
- node.SynchronizationContext = null;
- node.Prev = null;
- node.Next = FreeNodeList;
- FreeNodeList = node;
-
- return true;
- }
- finally
- {
- Lock.Exit(useMemoryBarrier: false); // no check on lockTaken needed without thread aborts
- }
- }
- }
-
- /// <summary>All of the state associated a registered callback, in a node that's part of a linked list of registered callbacks.</summary>
- internal sealed class CallbackNode
- {
- public readonly CallbackPartition Partition;
- public CallbackNode? Prev;
- public CallbackNode? Next;
-
- public long Id;
- public Action<object?>? Callback;
- public object? CallbackState;
- public ExecutionContext? ExecutionContext;
- public SynchronizationContext? SynchronizationContext;
-
- public CallbackNode(CallbackPartition partition)
- {
- Debug.Assert(partition != null, "Expected non-null partition");
- Partition = partition;
- }
-
- public void ExecuteCallback()
- {
- ExecutionContext? context = ExecutionContext;
- if (context != null)
- {
- ExecutionContext.RunInternal(context, s =>
- {
- Debug.Assert(s is CallbackNode, $"Expected {typeof(CallbackNode)}, got {s}");
- CallbackNode n = (CallbackNode)s;
-
- Debug.Assert(n.Callback != null);
- n.Callback(n.CallbackState);
- }, this);
- }
- else
- {
- Debug.Assert(Callback != null);
- Callback(CallbackState);
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/CompressedStack.cs b/netcore/System.Private.CoreLib/shared/System/Threading/CompressedStack.cs
deleted file mode 100644
index 6faa326e473..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/CompressedStack.cs
+++ /dev/null
@@ -1,46 +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 System.Runtime.Serialization;
-
-namespace System.Threading
-{
- public sealed class CompressedStack : ISerializable
- {
- private CompressedStack()
- {
- }
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- public static CompressedStack Capture()
- {
- return GetCompressedStack();
- }
-
- public CompressedStack CreateCopy()
- {
- return this;
- }
-
- public static CompressedStack GetCompressedStack()
- {
- return new CompressedStack();
- }
-
- public static void Run(CompressedStack compressedStack, ContextCallback callback, object? state)
- {
- if (compressedStack == null)
- {
- throw new ArgumentNullException(nameof(compressedStack));
- }
-
- // The original code was not checking for a null callback and would throw NullReferenceException
- callback(state);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/DeferredDisposableLifetime.cs b/netcore/System.Private.CoreLib/shared/System/Threading/DeferredDisposableLifetime.cs
deleted file mode 100644
index e8e4dcdd97e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/DeferredDisposableLifetime.cs
+++ /dev/null
@@ -1,114 +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 System.Diagnostics;
-
-namespace System.Threading
-{
- /// <summary>
- /// Provides callbacks to objects whose lifetime is managed by <see cref="DeferredDisposableLifetime{T}"/>.
- /// </summary>
- internal interface IDeferredDisposable
- {
- /// <summary>
- /// Called when the object's refcount reaches zero.
- /// </summary>
- /// <param name="disposed">
- /// Indicates whether the object has been disposed.
- /// </param>
- /// <remarks>
- /// If the refcount reaches zero before the object is disposed, this method will be called with
- /// <paramref name="disposed"/> set to false. If the object is then disposed, this method will be
- /// called again, with <paramref name="disposed"/> set to true. If the refcount reaches zero
- /// after the object has already been disposed, this will be called a single time, with
- /// <paramref name="disposed"/> set to true.
- /// </remarks>
- void OnFinalRelease(bool disposed);
- }
-
- /// <summary>
- /// Manages the lifetime of an object which implements IDisposable, but which must defer the actual
- /// cleanup of state until all existing uses of the object are complete.
- /// </summary>
- /// <typeparam name="T">The type of object whose lifetime will be managed.</typeparam>
- /// <remarks>
- /// This type maintains a reference count, and tracks whether the object has been disposed. When
- /// Callbacks are made to <see cref="IDeferredDisposable.OnFinalRelease(bool)"/> when the refcount
- /// reaches zero. Objects that need to defer cleanup until they have been disposed *and* they have
- /// no more references can do so in <see cref="IDeferredDisposable.OnFinalRelease(bool)"/> when
- /// 'disposed' is true.
- /// </remarks>
- internal struct DeferredDisposableLifetime<T> where T : class, IDeferredDisposable
- {
- /// <summary>_count is positive until Dispose is called, after which it's (-1 - refcount).</summary>
- private int _count;
-
- public bool AddRef()
- {
- while (true)
- {
- int oldCount = Volatile.Read(ref _count);
-
- // Have we been disposed?
- if (oldCount < 0)
- throw new ObjectDisposedException(typeof(T).ToString());
-
- int newCount = checked(oldCount + 1);
-
- if (Interlocked.CompareExchange(ref _count, newCount, oldCount) == oldCount)
- return true;
- }
- }
-
- public void Release(T obj)
- {
- while (true)
- {
- int oldCount = Volatile.Read(ref _count);
- if (oldCount > 0)
- {
- // We haven't been disposed. Decrement _count.
- int newCount = oldCount - 1;
- if (Interlocked.CompareExchange(ref _count, newCount, oldCount) == oldCount)
- {
- if (newCount == 0)
- obj.OnFinalRelease(disposed: false);
- return;
- }
- }
- else
- {
- Debug.Assert(oldCount != 0 && oldCount != -1);
-
- // We've been disposed. Increment _count.
- int newCount = oldCount + 1;
- if (Interlocked.CompareExchange(ref _count, newCount, oldCount) == oldCount)
- {
- if (newCount == -1)
- obj.OnFinalRelease(disposed: true);
- return;
- }
- }
- }
- }
-
- public void Dispose(T obj)
- {
- while (true)
- {
- int oldCount = Volatile.Read(ref _count);
- if (oldCount < 0)
- return; // already disposed
-
- int newCount = -1 - oldCount;
- if (Interlocked.CompareExchange(ref _count, newCount, oldCount) == oldCount)
- {
- if (newCount == -1)
- obj.OnFinalRelease(disposed: true);
- return;
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/EventResetMode.cs b/netcore/System.Private.CoreLib/shared/System/Threading/EventResetMode.cs
deleted file mode 100644
index 7aac0f51eb8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/EventResetMode.cs
+++ /dev/null
@@ -1,22 +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.
-
-/*=============================================================================
-**
-** Enum: EventResetMode
-**
-**
-** Purpose: Enum to determine the Event type to create
-**
-**
-=============================================================================*/
-
-namespace System.Threading
-{
- public enum EventResetMode
- {
- AutoReset = 0,
- ManualReset = 1
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.Windows.cs
deleted file mode 100644
index cb2c96f5ecf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.Windows.cs
+++ /dev/null
@@ -1,97 +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 System.IO;
-using System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-namespace System.Threading
-{
- public partial class EventWaitHandle
- {
- private const uint AccessRights = (uint)Interop.Kernel32.MAXIMUM_ALLOWED | Interop.Kernel32.SYNCHRONIZE | Interop.Kernel32.EVENT_MODIFY_STATE;
-
- private EventWaitHandle(SafeWaitHandle handle)
- {
- SafeWaitHandle = handle;
- }
-
- private void CreateEventCore(bool initialState, EventResetMode mode, string? name, out bool createdNew)
- {
-#if !PLATFORM_WINDOWS
- if (name != null)
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives);
-#endif
- uint eventFlags = initialState ? Interop.Kernel32.CREATE_EVENT_INITIAL_SET : 0;
- if (mode == EventResetMode.ManualReset)
- eventFlags |= (uint)Interop.Kernel32.CREATE_EVENT_MANUAL_RESET;
-
- SafeWaitHandle handle = Interop.Kernel32.CreateEventEx(IntPtr.Zero, name, eventFlags, AccessRights);
-
- int errorCode = Marshal.GetLastWin32Error();
- if (handle.IsInvalid)
- {
- handle.SetHandleAsInvalid();
- if (!string.IsNullOrEmpty(name) && errorCode == Interop.Errors.ERROR_INVALID_HANDLE)
- throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));
-
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, name);
- }
- createdNew = errorCode != Interop.Errors.ERROR_ALREADY_EXISTS;
- SafeWaitHandle = handle;
- }
-
- private static OpenExistingResult OpenExistingWorker(string name, out EventWaitHandle? result)
- {
-#if PLATFORM_WINDOWS
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- if (name.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
-
- result = null;
- SafeWaitHandle myHandle = Interop.Kernel32.OpenEvent(AccessRights, false, name);
-
- if (myHandle.IsInvalid)
- {
- int errorCode = Marshal.GetLastWin32Error();
-
- if (errorCode == Interop.Errors.ERROR_FILE_NOT_FOUND || errorCode == Interop.Errors.ERROR_INVALID_NAME)
- return OpenExistingResult.NameNotFound;
- if (errorCode == Interop.Errors.ERROR_PATH_NOT_FOUND)
- return OpenExistingResult.PathNotFound;
- if (!string.IsNullOrEmpty(name) && errorCode == Interop.Errors.ERROR_INVALID_HANDLE)
- return OpenExistingResult.NameInvalid;
-
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, name);
- }
- result = new EventWaitHandle(myHandle);
- return OpenExistingResult.Success;
-#else
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives);
-#endif
- }
-
- public bool Reset()
- {
- bool res = Interop.Kernel32.ResetEvent(SafeWaitHandle);
- if (!res)
- throw Win32Marshal.GetExceptionForLastWin32Error();
- return res;
- }
-
- public bool Set()
- {
- bool res = Interop.Kernel32.SetEvent(SafeWaitHandle);
- if (!res)
- throw Win32Marshal.GetExceptionForLastWin32Error();
- return res;
- }
-
- internal static bool Set(SafeWaitHandle waitHandle)
- {
- return Interop.Kernel32.SetEvent(waitHandle);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.cs b/netcore/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.cs
deleted file mode 100644
index 96c2ef89c65..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.cs
+++ /dev/null
@@ -1,53 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.IO;
-
-namespace System.Threading
-{
- public partial class EventWaitHandle : WaitHandle
- {
- public EventWaitHandle(bool initialState, EventResetMode mode) :
- this(initialState, mode, null, out _)
- {
- }
-
- public EventWaitHandle(bool initialState, EventResetMode mode, string? name) :
- this(initialState, mode, name, out _)
- {
- }
-
- public EventWaitHandle(bool initialState, EventResetMode mode, string? name, out bool createdNew)
- {
- if (mode != EventResetMode.AutoReset && mode != EventResetMode.ManualReset)
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(mode));
-
- CreateEventCore(initialState, mode, name, out createdNew);
- }
-
- public static EventWaitHandle OpenExisting(string name)
- {
- EventWaitHandle? result;
- switch (OpenExistingWorker(name, out result))
- {
- case OpenExistingResult.NameNotFound:
- throw new WaitHandleCannotBeOpenedException();
- case OpenExistingResult.NameInvalid:
- throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));
- case OpenExistingResult.PathNotFound:
- throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, name));
- default:
- Debug.Assert(result != null, "result should be non-null on success");
- return result;
- }
- }
-
- public static bool TryOpenExisting(string name, [NotNullWhen(true)] out EventWaitHandle? result)
- {
- return OpenExistingWorker(name, out result) == OpenExistingResult.Success;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs
deleted file mode 100644
index aa2ec5456f9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs
+++ /dev/null
@@ -1,639 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Capture execution context for a thread
-**
-**
-===========================================================*/
-
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.ExceptionServices;
-using System.Runtime.Serialization;
-
-namespace System.Threading
-{
- public delegate void ContextCallback(object? state);
-
- internal delegate void ContextCallback<TState>(ref TState state);
-
- public sealed class ExecutionContext : IDisposable, ISerializable
- {
- internal static readonly ExecutionContext Default = new ExecutionContext(isDefault: true);
- internal static readonly ExecutionContext DefaultFlowSuppressed = new ExecutionContext(AsyncLocalValueMap.Empty, Array.Empty<IAsyncLocal>(), isFlowSuppressed: true);
-
- private readonly IAsyncLocalValueMap? m_localValues;
- private readonly IAsyncLocal[]? m_localChangeNotifications;
- private readonly bool m_isFlowSuppressed;
- private readonly bool m_isDefault;
-
- private ExecutionContext(bool isDefault)
- {
- m_isDefault = isDefault;
- }
-
- private ExecutionContext(
- IAsyncLocalValueMap localValues,
- IAsyncLocal[]? localChangeNotifications,
- bool isFlowSuppressed)
- {
- m_localValues = localValues;
- m_localChangeNotifications = localChangeNotifications;
- m_isFlowSuppressed = isFlowSuppressed;
- }
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- public static ExecutionContext? Capture()
- {
- ExecutionContext? executionContext = Thread.CurrentThread._executionContext;
- if (executionContext == null)
- {
- executionContext = Default;
- }
- else if (executionContext.m_isFlowSuppressed)
- {
- executionContext = null;
- }
-
- return executionContext;
- }
-
- private ExecutionContext? ShallowClone(bool isFlowSuppressed)
- {
- Debug.Assert(isFlowSuppressed != m_isFlowSuppressed);
-
- if (m_localValues == null || AsyncLocalValueMap.IsEmpty(m_localValues))
- {
- return isFlowSuppressed ?
- DefaultFlowSuppressed :
- null; // implies the default context
- }
-
- return new ExecutionContext(m_localValues, m_localChangeNotifications, isFlowSuppressed);
- }
-
- public static AsyncFlowControl SuppressFlow()
- {
- Thread currentThread = Thread.CurrentThread;
- ExecutionContext? executionContext = currentThread._executionContext ?? Default;
- if (executionContext.m_isFlowSuppressed)
- {
- throw new InvalidOperationException(SR.InvalidOperation_CannotSupressFlowMultipleTimes);
- }
-
- executionContext = executionContext.ShallowClone(isFlowSuppressed: true);
- AsyncFlowControl asyncFlowControl = default;
- currentThread._executionContext = executionContext;
- asyncFlowControl.Initialize(currentThread);
- return asyncFlowControl;
- }
-
- public static void RestoreFlow()
- {
- Thread currentThread = Thread.CurrentThread;
- ExecutionContext? executionContext = currentThread._executionContext;
- if (executionContext == null || !executionContext.m_isFlowSuppressed)
- {
- throw new InvalidOperationException(SR.InvalidOperation_CannotRestoreUnsupressedFlow);
- }
-
- currentThread._executionContext = executionContext.ShallowClone(isFlowSuppressed: false);
- }
-
- public static bool IsFlowSuppressed()
- {
- ExecutionContext? executionContext = Thread.CurrentThread._executionContext;
- return executionContext != null && executionContext.m_isFlowSuppressed;
- }
-
- internal bool HasChangeNotifications => m_localChangeNotifications != null;
-
- internal bool IsDefault => m_isDefault;
-
- public static void Run(ExecutionContext executionContext, ContextCallback callback, object? state)
- {
- // Note: ExecutionContext.Run is an extremely hot function and used by every await, ThreadPool execution, etc.
- if (executionContext == null)
- {
- ThrowNullContext();
- }
-
- RunInternal(executionContext, callback, state);
- }
-
- internal static void RunInternal(ExecutionContext? executionContext, ContextCallback callback, object? state)
- {
- // Note: ExecutionContext.RunInternal is an extremely hot function and used by every await, ThreadPool execution, etc.
- // Note: Manual enregistering may be addressed by "Exception Handling Write Through Optimization"
- // https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/eh-writethru.md
-
- // Enregister variables with 0 post-fix so they can be used in registers without EH forcing them to stack
- // Capture references to Thread Contexts
- Thread currentThread0 = Thread.CurrentThread;
- Thread currentThread = currentThread0;
- ExecutionContext? previousExecutionCtx0 = currentThread0._executionContext;
- if (previousExecutionCtx0 != null && previousExecutionCtx0.m_isDefault)
- {
- // Default is a null ExecutionContext internally
- previousExecutionCtx0 = null;
- }
-
- // Store current ExecutionContext and SynchronizationContext as "previousXxx".
- // This allows us to restore them and undo any Context changes made in callback.Invoke
- // so that they won't "leak" back into caller.
- // These variables will cross EH so be forced to stack
- ExecutionContext? previousExecutionCtx = previousExecutionCtx0;
- SynchronizationContext? previousSyncCtx = currentThread0._synchronizationContext;
-
- if (executionContext != null && executionContext.m_isDefault)
- {
- // Default is a null ExecutionContext internally
- executionContext = null;
- }
-
- if (previousExecutionCtx0 != executionContext)
- {
- RestoreChangedContextToThread(currentThread0, executionContext, previousExecutionCtx0);
- }
-
- ExceptionDispatchInfo? edi = null;
- try
- {
- callback.Invoke(state);
- }
- catch (Exception ex)
- {
- // Note: we have a "catch" rather than a "finally" because we want
- // to stop the first pass of EH here. That way we can restore the previous
- // context before any of our callers' EH filters run.
- edi = ExceptionDispatchInfo.Capture(ex);
- }
-
- // Re-enregistrer variables post EH with 1 post-fix so they can be used in registers rather than from stack
- SynchronizationContext? previousSyncCtx1 = previousSyncCtx;
- Thread currentThread1 = currentThread;
- // The common case is that these have not changed, so avoid the cost of a write barrier if not needed.
- if (currentThread1._synchronizationContext != previousSyncCtx1)
- {
- // Restore changed SynchronizationContext back to previous
- currentThread1._synchronizationContext = previousSyncCtx1;
- }
-
- ExecutionContext? previousExecutionCtx1 = previousExecutionCtx;
- ExecutionContext? currentExecutionCtx1 = currentThread1._executionContext;
- if (currentExecutionCtx1 != previousExecutionCtx1)
- {
- RestoreChangedContextToThread(currentThread1, previousExecutionCtx1, currentExecutionCtx1);
- }
-
- // If exception was thrown by callback, rethrow it now original contexts are restored
- edi?.Throw();
- }
-
- // Direct copy of the above RunInternal overload, except that it passes the state into the callback strongly-typed and by ref.
- internal static void RunInternal<TState>(ExecutionContext? executionContext, ContextCallback<TState> callback, ref TState state)
- {
- // Note: ExecutionContext.RunInternal is an extremely hot function and used by every await, ThreadPool execution, etc.
- // Note: Manual enregistering may be addressed by "Exception Handling Write Through Optimization"
- // https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/eh-writethru.md
-
- // Enregister variables with 0 post-fix so they can be used in registers without EH forcing them to stack
- // Capture references to Thread Contexts
- Thread currentThread0 = Thread.CurrentThread;
- Thread currentThread = currentThread0;
- ExecutionContext? previousExecutionCtx0 = currentThread0._executionContext;
- if (previousExecutionCtx0 != null && previousExecutionCtx0.m_isDefault)
- {
- // Default is a null ExecutionContext internally
- previousExecutionCtx0 = null;
- }
-
- // Store current ExecutionContext and SynchronizationContext as "previousXxx".
- // This allows us to restore them and undo any Context changes made in callback.Invoke
- // so that they won't "leak" back into caller.
- // These variables will cross EH so be forced to stack
- ExecutionContext? previousExecutionCtx = previousExecutionCtx0;
- SynchronizationContext? previousSyncCtx = currentThread0._synchronizationContext;
-
- if (executionContext != null && executionContext.m_isDefault)
- {
- // Default is a null ExecutionContext internally
- executionContext = null;
- }
-
- if (previousExecutionCtx0 != executionContext)
- {
- RestoreChangedContextToThread(currentThread0, executionContext, previousExecutionCtx0);
- }
-
- ExceptionDispatchInfo? edi = null;
- try
- {
- callback.Invoke(ref state);
- }
- catch (Exception ex)
- {
- // Note: we have a "catch" rather than a "finally" because we want
- // to stop the first pass of EH here. That way we can restore the previous
- // context before any of our callers' EH filters run.
- edi = ExceptionDispatchInfo.Capture(ex);
- }
-
- // Re-enregistrer variables post EH with 1 post-fix so they can be used in registers rather than from stack
- SynchronizationContext? previousSyncCtx1 = previousSyncCtx;
- Thread currentThread1 = currentThread;
- // The common case is that these have not changed, so avoid the cost of a write barrier if not needed.
- if (currentThread1._synchronizationContext != previousSyncCtx1)
- {
- // Restore changed SynchronizationContext back to previous
- currentThread1._synchronizationContext = previousSyncCtx1;
- }
-
- ExecutionContext? previousExecutionCtx1 = previousExecutionCtx;
- ExecutionContext? currentExecutionCtx1 = currentThread1._executionContext;
- if (currentExecutionCtx1 != previousExecutionCtx1)
- {
- RestoreChangedContextToThread(currentThread1, previousExecutionCtx1, currentExecutionCtx1);
- }
-
- // If exception was thrown by callback, rethrow it now original contexts are restored
- edi?.Throw();
- }
-
- internal static void RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, object state)
- {
- Debug.Assert(threadPoolThread == Thread.CurrentThread);
- CheckThreadPoolAndContextsAreDefault();
- // ThreadPool starts on Default Context so we don't need to save the "previous" state as we know it is Default (null)
-
- // Default is a null ExecutionContext internally
- if (executionContext != null && !executionContext.m_isDefault)
- {
- // Non-Default context to restore
- RestoreChangedContextToThread(threadPoolThread, contextToRestore: executionContext, currentContext: null);
- }
-
- ExceptionDispatchInfo? edi = null;
- try
- {
- callback.Invoke(state);
- }
- catch (Exception ex)
- {
- // Note: we have a "catch" rather than a "finally" because we want
- // to stop the first pass of EH here. That way we can restore the previous
- // context before any of our callers' EH filters run.
- edi = ExceptionDispatchInfo.Capture(ex);
- }
-
- // Enregister threadPoolThread as it crossed EH, and use enregistered variable
- Thread currentThread = threadPoolThread;
-
- ExecutionContext? currentExecutionCtx = currentThread._executionContext;
-
- // Restore changed SynchronizationContext back to Default
- currentThread._synchronizationContext = null;
- if (currentExecutionCtx != null)
- {
- // The EC always needs to be reset for this overload, as it will flow back to the caller if it performs
- // extra work prior to returning to the Dispatch loop. For example for Task-likes it will flow out of await points
- RestoreChangedContextToThread(currentThread, contextToRestore: null, currentExecutionCtx);
- }
-
- // If exception was thrown by callback, rethrow it now original contexts are restored
- edi?.Throw();
- }
-
- internal static void RunForThreadPoolUnsafe<TState>(ExecutionContext executionContext, Action<TState> callback, in TState state)
- {
- // We aren't running in try/catch as if an exception is directly thrown on the ThreadPool either process
- // will crash or its a ThreadAbortException.
-
- CheckThreadPoolAndContextsAreDefault();
- Debug.Assert(executionContext != null && !executionContext.m_isDefault, "ExecutionContext argument is Default.");
-
- // Restore Non-Default context
- Thread.CurrentThread._executionContext = executionContext;
- if (executionContext.HasChangeNotifications)
- {
- OnValuesChanged(previousExecutionCtx: null, executionContext);
- }
-
- callback.Invoke(state);
-
- // ThreadPoolWorkQueue.Dispatch will handle notifications and reset EC and SyncCtx back to default
- }
-
- internal static void RestoreChangedContextToThread(Thread currentThread, ExecutionContext? contextToRestore, ExecutionContext? currentContext)
- {
- Debug.Assert(currentThread == Thread.CurrentThread);
- Debug.Assert(contextToRestore != currentContext);
-
- // Restore changed ExecutionContext back to previous
- currentThread._executionContext = contextToRestore;
- if ((currentContext != null && currentContext.HasChangeNotifications) ||
- (contextToRestore != null && contextToRestore.HasChangeNotifications))
- {
- // There are change notifications; trigger any affected
- OnValuesChanged(currentContext, contextToRestore);
- }
- }
-
- // Inline as only called in one place and always called
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void ResetThreadPoolThread(Thread currentThread)
- {
- ExecutionContext? currentExecutionCtx = currentThread._executionContext;
-
- // Reset to defaults
- currentThread._synchronizationContext = null;
- currentThread._executionContext = null;
-
- if (currentExecutionCtx != null && currentExecutionCtx.HasChangeNotifications)
- {
- OnValuesChanged(currentExecutionCtx, nextExecutionCtx: null);
-
- // Reset to defaults again without change notifications in case the Change handler changed the contexts
- currentThread._synchronizationContext = null;
- currentThread._executionContext = null;
- }
- }
-
- [System.Diagnostics.Conditional("DEBUG")]
- internal static void CheckThreadPoolAndContextsAreDefault()
- {
- Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
- Debug.Assert(Thread.CurrentThread._executionContext == null, "ThreadPool thread not on Default ExecutionContext.");
- Debug.Assert(Thread.CurrentThread._synchronizationContext == null, "ThreadPool thread not on Default SynchronizationContext.");
- }
-
- internal static void OnValuesChanged(ExecutionContext? previousExecutionCtx, ExecutionContext? nextExecutionCtx)
- {
- Debug.Assert(previousExecutionCtx != nextExecutionCtx);
-
- // Collect Change Notifications
- IAsyncLocal[]? previousChangeNotifications = previousExecutionCtx?.m_localChangeNotifications;
- IAsyncLocal[]? nextChangeNotifications = nextExecutionCtx?.m_localChangeNotifications;
-
- // At least one side must have notifications
- Debug.Assert(previousChangeNotifications != null || nextChangeNotifications != null);
-
- // Fire Change Notifications
- try
- {
- if (previousChangeNotifications != null && nextChangeNotifications != null)
- {
- // Notifications can't exist without values
- Debug.Assert(previousExecutionCtx!.m_localValues != null);
- Debug.Assert(nextExecutionCtx!.m_localValues != null);
- // Both contexts have change notifications, check previousExecutionCtx first
- foreach (IAsyncLocal local in previousChangeNotifications)
- {
- previousExecutionCtx.m_localValues.TryGetValue(local, out object? previousValue);
- nextExecutionCtx.m_localValues.TryGetValue(local, out object? currentValue);
-
- if (previousValue != currentValue)
- {
- local.OnValueChanged(previousValue, currentValue, contextChanged: true);
- }
- }
-
- if (nextChangeNotifications != previousChangeNotifications)
- {
- // Check for additional notifications in nextExecutionCtx
- foreach (IAsyncLocal local in nextChangeNotifications)
- {
- // If the local has a value in the previous context, we already fired the event
- // for that local in the code above.
- if (!previousExecutionCtx.m_localValues.TryGetValue(local, out object? previousValue))
- {
- nextExecutionCtx.m_localValues.TryGetValue(local, out object? currentValue);
- if (previousValue != currentValue)
- {
- local.OnValueChanged(previousValue, currentValue, contextChanged: true);
- }
- }
- }
- }
- }
- else if (previousChangeNotifications != null)
- {
- // Notifications can't exist without values
- Debug.Assert(previousExecutionCtx!.m_localValues != null);
- // No current values, so just check previous against null
- foreach (IAsyncLocal local in previousChangeNotifications)
- {
- previousExecutionCtx.m_localValues.TryGetValue(local, out object? previousValue);
- if (previousValue != null)
- {
- local.OnValueChanged(previousValue, null, contextChanged: true);
- }
- }
- }
- else // Implied: nextChangeNotifications != null
- {
- // Notifications can't exist without values
- Debug.Assert(nextExecutionCtx!.m_localValues != null);
- // No previous values, so just check current against null
- foreach (IAsyncLocal local in nextChangeNotifications!)
- {
- nextExecutionCtx.m_localValues.TryGetValue(local, out object? currentValue);
- if (currentValue != null)
- {
- local.OnValueChanged(null, currentValue, contextChanged: true);
- }
- }
- }
- }
- catch (Exception ex)
- {
- Environment.FailFast(
- SR.ExecutionContext_ExceptionInAsyncLocalNotification,
- ex);
- }
- }
-
- [DoesNotReturn]
- [StackTraceHidden]
- private static void ThrowNullContext()
- {
- throw new InvalidOperationException(SR.InvalidOperation_NullContext);
- }
-
- internal static object? GetLocalValue(IAsyncLocal local)
- {
- ExecutionContext? current = Thread.CurrentThread._executionContext;
- if (current == null)
- {
- return null;
- }
-
- Debug.Assert(!current.IsDefault);
- Debug.Assert(current.m_localValues != null, "Only the default context should have null, and we shouldn't be here on the default context");
- current.m_localValues.TryGetValue(local, out object? value);
- return value;
- }
-
- internal static void SetLocalValue(IAsyncLocal local, object? newValue, bool needChangeNotifications)
- {
- ExecutionContext? current = Thread.CurrentThread._executionContext;
-
- object? previousValue = null;
- bool hadPreviousValue = false;
- if (current != null)
- {
- Debug.Assert(!current.IsDefault);
- Debug.Assert(current.m_localValues != null, "Only the default context should have null, and we shouldn't be here on the default context");
-
- hadPreviousValue = current.m_localValues.TryGetValue(local, out previousValue);
- }
-
- if (previousValue == newValue)
- {
- return;
- }
-
- // Regarding 'treatNullValueAsNonexistent: !needChangeNotifications' below:
- // - When change notifications are not necessary for this IAsyncLocal, there is no observable difference between
- // storing a null value and removing the IAsyncLocal from 'm_localValues'
- // - When change notifications are necessary for this IAsyncLocal, the IAsyncLocal's absence in 'm_localValues'
- // indicates that this is the first value change for the IAsyncLocal and it needs to be registered for change
- // notifications. So in this case, a null value must be stored in 'm_localValues' to indicate that the IAsyncLocal
- // is already registered for change notifications.
- IAsyncLocal[]? newChangeNotifications = null;
- IAsyncLocalValueMap newValues;
- bool isFlowSuppressed = false;
- if (current != null)
- {
- Debug.Assert(!current.IsDefault);
- Debug.Assert(current.m_localValues != null, "Only the default context should have null, and we shouldn't be here on the default context");
-
- isFlowSuppressed = current.m_isFlowSuppressed;
- newValues = current.m_localValues.Set(local, newValue, treatNullValueAsNonexistent: !needChangeNotifications);
- newChangeNotifications = current.m_localChangeNotifications;
- }
- else
- {
- // First AsyncLocal
- newValues = AsyncLocalValueMap.Create(local, newValue, treatNullValueAsNonexistent: !needChangeNotifications);
- }
-
- //
- // Either copy the change notification array, or create a new one, depending on whether we need to add a new item.
- //
- if (needChangeNotifications)
- {
- if (hadPreviousValue)
- {
- Debug.Assert(newChangeNotifications != null);
- Debug.Assert(Array.IndexOf(newChangeNotifications, local) >= 0);
- }
- else if (newChangeNotifications == null)
- {
- newChangeNotifications = new IAsyncLocal[1] { local };
- }
- else
- {
- int newNotificationIndex = newChangeNotifications.Length;
- Array.Resize(ref newChangeNotifications, newNotificationIndex + 1);
- newChangeNotifications[newNotificationIndex] = local;
- }
- }
-
- Thread.CurrentThread._executionContext =
- (!isFlowSuppressed && AsyncLocalValueMap.IsEmpty(newValues)) ?
- null : // No values, return to Default context
- new ExecutionContext(newValues, newChangeNotifications, isFlowSuppressed);
-
- if (needChangeNotifications)
- {
- local.OnValueChanged(previousValue, newValue, contextChanged: false);
- }
- }
-
- public ExecutionContext CreateCopy()
- {
- return this; // since CoreCLR's ExecutionContext is immutable, we don't need to create copies.
- }
-
- public void Dispose()
- {
- // For CLR compat only
- }
- }
-
- public struct AsyncFlowControl : IDisposable
- {
- private Thread? _thread;
-
- internal void Initialize(Thread currentThread)
- {
- Debug.Assert(currentThread == Thread.CurrentThread);
- _thread = currentThread;
- }
-
- public void Undo()
- {
- if (_thread == null)
- {
- throw new InvalidOperationException(SR.InvalidOperation_CannotUseAFCMultiple);
- }
- if (Thread.CurrentThread != _thread)
- {
- throw new InvalidOperationException(SR.InvalidOperation_CannotUseAFCOtherThread);
- }
-
- // An async flow control cannot be undone when a different execution context is applied. The desktop framework
- // mutates the execution context when its state changes, and only changes the instance when an execution context
- // is applied (for instance, through ExecutionContext.Run). The framework prevents a suppressed-flow execution
- // context from being applied by returning null from ExecutionContext.Capture, so the only type of execution
- // context that can be applied is one whose flow is not suppressed. After suppressing flow and changing an async
- // local's value, the desktop framework verifies that a different execution context has not been applied by
- // checking the execution context instance against the one saved from when flow was suppressed. In .NET Core,
- // since the execution context instance will change after changing the async local's value, it verifies that a
- // different execution context has not been applied, by instead ensuring that the current execution context's
- // flow is suppressed.
- if (!ExecutionContext.IsFlowSuppressed())
- {
- throw new InvalidOperationException(SR.InvalidOperation_AsyncFlowCtrlCtxMismatch);
- }
-
- _thread = null;
- ExecutionContext.RestoreFlow();
- }
-
- public void Dispose()
- {
- Undo();
- }
-
- public override bool Equals(object? obj)
- {
- return obj is AsyncFlowControl && Equals((AsyncFlowControl)obj);
- }
-
- public bool Equals(AsyncFlowControl obj)
- {
- return _thread == obj._thread;
- }
-
- public override int GetHashCode()
- {
- return _thread?.GetHashCode() ?? 0;
- }
-
- public static bool operator ==(AsyncFlowControl a, AsyncFlowControl b) => a.Equals(b);
-
- public static bool operator !=(AsyncFlowControl a, AsyncFlowControl b) => !(a == b);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/IOCompletionCallback.cs b/netcore/System.Private.CoreLib/shared/System/Threading/IOCompletionCallback.cs
deleted file mode 100644
index 571ce467eb5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/IOCompletionCallback.cs
+++ /dev/null
@@ -1,9 +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.
-
-namespace System.Threading
-{
- [CLSCompliant(false)]
- public unsafe delegate void IOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped* pOVERLAP);
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/IThreadPoolWorkItem.cs b/netcore/System.Private.CoreLib/shared/System/Threading/IThreadPoolWorkItem.cs
deleted file mode 100644
index 301c39e30b3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/IThreadPoolWorkItem.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Threading
-{
- /// <summary>Represents a work item that can be executed by the ThreadPool.</summary>
- public interface IThreadPoolWorkItem
- {
- void Execute();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs b/netcore/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs
deleted file mode 100644
index b8b05a77473..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs
+++ /dev/null
@@ -1,289 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-// a set of lightweight static helpers for lazy initialization.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Threading
-{
- /// <summary>
- /// Provides lazy initialization routines.
- /// </summary>
- /// <remarks>
- /// These routines avoid needing to allocate a dedicated, lazy-initialization instance, instead using
- /// references to ensure targets have been initialized as they are accessed.
- /// </remarks>
- public static class LazyInitializer
- {
- /// <summary>
- /// Initializes a target reference type with the type's default constructor if the target has not
- /// already been initialized.
- /// </summary>
- /// <typeparam name="T">The reference type of the reference to be initialized.</typeparam>
- /// <param name="target">A reference of type <typeparamref name="T"/> to initialize if it has not
- /// already been initialized.</param>
- /// <returns>The initialized reference of type <typeparamref name="T"/>.</returns>
- /// <exception cref="System.MissingMemberException">Type <typeparamref name="T"/> does not have a default
- /// constructor.</exception>
- /// <exception cref="System.MemberAccessException">
- /// Permissions to access the constructor of type <typeparamref name="T"/> were missing.
- /// </exception>
- /// <remarks>
- /// <para>
- /// This method may only be used on reference types. To ensure initialization of value
- /// types, see other overloads of EnsureInitialized.
- /// </para>
- /// <para>
- /// This method may be used concurrently by multiple threads to initialize <paramref name="target"/>.
- /// In the event that multiple threads access this method concurrently, multiple instances of <typeparamref name="T"/>
- /// may be created, but only one will be stored into <paramref name="target"/>. In such an occurrence, this method will not dispose of the
- /// objects that were not stored. If such objects must be disposed, it is up to the caller to determine
- /// if an object was not used and to then dispose of the object appropriately.
- /// </para>
- /// </remarks>
- public static T EnsureInitialized<T>([NotNull] ref T? target) where T : class =>
- Volatile.Read(ref target) ?? EnsureInitializedCore(ref target);
-
- /// <summary>
- /// Initializes a target reference type with the type's default constructor (slow path)
- /// </summary>
- /// <typeparam name="T">The reference type of the reference to be initialized.</typeparam>
- /// <param name="target">The variable that need to be initialized</param>
- /// <returns>The initialized variable</returns>
- private static T EnsureInitializedCore<T>([NotNull] ref T? target) where T : class
- {
- try
- {
- Interlocked.CompareExchange(ref target, Activator.CreateInstance<T>(), null!);
- }
- catch (MissingMethodException)
- {
- throw new MissingMemberException(SR.Lazy_CreateValue_NoParameterlessCtorForT);
- }
-
- Debug.Assert(target != null);
- return target;
- }
-
- /// <summary>
- /// Initializes a target reference type using the specified function if it has not already been
- /// initialized.
- /// </summary>
- /// <typeparam name="T">The reference type of the reference to be initialized.</typeparam>
- /// <param name="target">The reference of type <typeparamref name="T"/> to initialize if it has not
- /// already been initialized.</param>
- /// <param name="valueFactory">The <see cref="System.Func{T}"/> invoked to initialize the
- /// reference.</param>
- /// <returns>The initialized reference of type <typeparamref name="T"/>.</returns>
- /// <exception cref="System.MissingMemberException">Type <typeparamref name="T"/> does not have a
- /// default constructor.</exception>
- /// <exception cref="System.InvalidOperationException"><paramref name="valueFactory"/> returned
- /// null.</exception>
- /// <remarks>
- /// <para>
- /// This method may only be used on reference types, and <paramref name="valueFactory"/> may
- /// not return a null reference (Nothing in Visual Basic). To ensure initialization of value types or
- /// to allow null reference types, see other overloads of EnsureInitialized.
- /// </para>
- /// <para>
- /// This method may be used concurrently by multiple threads to initialize <paramref name="target"/>.
- /// In the event that multiple threads access this method concurrently, multiple instances of <typeparamref name="T"/>
- /// may be created, but only one will be stored into <paramref name="target"/>. In such an occurrence, this method will not dispose of the
- /// objects that were not stored. If such objects must be disposed, it is up to the caller to determine
- /// if an object was not used and to then dispose of the object appropriately.
- /// </para>
- /// </remarks>
- public static T EnsureInitialized<T>([NotNull] ref T? target, Func<T> valueFactory) where T : class =>
- Volatile.Read(ref target) ?? EnsureInitializedCore(ref target, valueFactory);
-
- /// <summary>
- /// Initialize the target using the given delegate (slow path).
- /// </summary>
- /// <typeparam name="T">The reference type of the reference to be initialized.</typeparam>
- /// <param name="target">The variable that need to be initialized</param>
- /// <param name="valueFactory">The delegate that will be executed to initialize the target</param>
- /// <returns>The initialized variable</returns>
- private static T EnsureInitializedCore<T>([NotNull] ref T? target, Func<T> valueFactory) where T : class
- {
- T value = valueFactory();
- if (value == null)
- {
- throw new InvalidOperationException(SR.Lazy_StaticInit_InvalidOperation);
- }
-
- Interlocked.CompareExchange(ref target, value, null!);
- Debug.Assert(target != null);
- return target;
- }
-
- /// <summary>
- /// Initializes a target reference or value type with its default constructor if it has not already
- /// been initialized.
- /// </summary>
- /// <typeparam name="T">The type of the reference to be initialized.</typeparam>
- /// <param name="target">A reference or value of type <typeparamref name="T"/> to initialize if it
- /// has not already been initialized.</param>
- /// <param name="initialized">A reference to a boolean that determines whether the target has already
- /// been initialized.</param>
- /// <param name="syncLock">A reference to an object used as the mutually exclusive lock for initializing
- /// <paramref name="target"/>. If <paramref name="syncLock"/> is null, a new object will be instantiated.</param>
- /// <returns>The initialized value of type <typeparamref name="T"/>.</returns>
- public static T EnsureInitialized<T>([AllowNull] ref T target, ref bool initialized, [NotNull] ref object? syncLock)
- {
- // Fast path.
- if (Volatile.Read(ref initialized))
- {
- return target;
- }
-
- return EnsureInitializedCore(ref target, ref initialized, ref syncLock);
- }
-
- /// <summary>
- /// Ensure the target is initialized and return the value (slow path). This overload permits nulls
- /// and also works for value type targets. Uses the type's default constructor to create the value.
- /// </summary>
- /// <typeparam name="T">The type of target.</typeparam>
- /// <param name="target">A reference to the target to be initialized.</param>
- /// <param name="initialized">A reference to a location tracking whether the target has been initialized.</param>
- /// <param name="syncLock">A reference to a location containing a mutual exclusive lock. If <paramref name="syncLock"/> is null,
- /// a new object will be instantiated.
- /// </param>
- /// <returns>The initialized object.</returns>
- private static T EnsureInitializedCore<T>([AllowNull] ref T target, ref bool initialized, [NotNull] ref object? syncLock)
- {
- // Lazily initialize the lock if necessary and then double check if initialization is still required.
- lock (EnsureLockInitialized(ref syncLock))
- {
- if (!Volatile.Read(ref initialized))
- {
- try
- {
- target = Activator.CreateInstance<T>();
- }
- catch (MissingMethodException)
- {
- throw new MissingMemberException(SR.Lazy_CreateValue_NoParameterlessCtorForT);
- }
-
- Volatile.Write(ref initialized, true);
- }
- }
-
- return target;
- }
-
- /// <summary>
- /// Initializes a target reference or value type with a specified function if it has not already been
- /// initialized.
- /// </summary>
- /// <typeparam name="T">The type of the reference to be initialized.</typeparam>
- /// <param name="target">A reference or value of type <typeparamref name="T"/> to initialize if it
- /// has not already been initialized.</param>
- /// <param name="initialized">A reference to a boolean that determines whether the target has already
- /// been initialized.</param>
- /// <param name="syncLock">A reference to an object used as the mutually exclusive lock for initializing
- /// <paramref name="target"/>. If <paramref name="syncLock"/> is null, a new object will be instantiated.</param>
- /// <param name="valueFactory">The <see cref="System.Func{T}"/> invoked to initialize the
- /// reference or value.</param>
- /// <returns>The initialized value of type <typeparamref name="T"/>.</returns>
- public static T EnsureInitialized<T>([AllowNull] ref T target, ref bool initialized, [NotNull] ref object? syncLock, Func<T> valueFactory)
- {
- // Fast path.
- if (Volatile.Read(ref initialized))
- {
- return target;
- }
-
- return EnsureInitializedCore(ref target, ref initialized, ref syncLock, valueFactory);
- }
-
- /// <summary>
- /// Ensure the target is initialized and return the value (slow path). This overload permits nulls
- /// and also works for value type targets. Uses the supplied function to create the value.
- /// </summary>
- /// <typeparam name="T">The type of target.</typeparam>
- /// <param name="target">A reference to the target to be initialized.</param>
- /// <param name="initialized">A reference to a location tracking whether the target has been initialized.</param>
- /// <param name="syncLock">A reference to a location containing a mutual exclusive lock. If <paramref name="syncLock"/> is null,
- /// a new object will be instantiated.</param>
- /// <param name="valueFactory">
- /// The <see cref="System.Func{T}"/> to invoke in order to produce the lazily-initialized value.
- /// </param>
- /// <returns>The initialized object.</returns>
- private static T EnsureInitializedCore<T>([AllowNull] ref T target, ref bool initialized, [NotNull] ref object? syncLock, Func<T> valueFactory)
- {
- // Lazily initialize the lock if necessary and then double check if initialization is still required.
- lock (EnsureLockInitialized(ref syncLock))
- {
- if (!Volatile.Read(ref initialized))
- {
- target = valueFactory();
- Volatile.Write(ref initialized, true);
- }
- }
-
- return target;
- }
-
- /// <summary>
- /// Initializes a target reference type with a specified function if it has not already been initialized.
- /// </summary>
- /// <typeparam name="T">The type of the reference to be initialized. Has to be reference type.</typeparam>
- /// <param name="target">A reference of type <typeparamref name="T"/> to initialize if it has not already been initialized.</param>
- /// <param name="syncLock">A reference to an object used as the mutually exclusive lock for initializing
- /// <paramref name="target"/>. If <paramref name="syncLock"/> is null, a new object will be instantiated.</param>
- /// <param name="valueFactory">The <see cref="System.Func{T}"/> invoked to initialize the reference.</param>
- /// <returns>The initialized value of type <typeparamref name="T"/>.</returns>
- public static T EnsureInitialized<T>([NotNull] ref T? target, [NotNull] ref object? syncLock, Func<T> valueFactory) where T : class =>
- Volatile.Read(ref target) ?? EnsureInitializedCore(ref target, ref syncLock, valueFactory);
-
- /// <summary>
- /// Ensure the target is initialized and return the value (slow path). This overload works only for reference type targets.
- /// Uses the supplied function to create the value.
- /// </summary>
- /// <typeparam name="T">The type of target. Has to be reference type.</typeparam>
- /// <param name="target">A reference to the target to be initialized.</param>
- /// <param name="syncLock">A reference to a location containing a mutual exclusive lock. If <paramref name="syncLock"/> is null,
- /// a new object will be instantiated.</param>
- /// <param name="valueFactory">
- /// The <see cref="System.Func{T}"/> to invoke in order to produce the lazily-initialized value.
- /// </param>
- /// <returns>The initialized object.</returns>
- private static T EnsureInitializedCore<T>([NotNull] ref T? target, [NotNull] ref object? syncLock, Func<T> valueFactory) where T : class
- {
- // Lazily initialize the lock if necessary and then double check if initialization is still required.
- lock (EnsureLockInitialized(ref syncLock))
- {
- if (Volatile.Read(ref target) == null)
- {
- Volatile.Write(ref target, valueFactory());
- if (target == null)
- {
- throw new InvalidOperationException(SR.Lazy_StaticInit_InvalidOperation);
- }
- }
- }
-
- return target!; // TODO-NULLABLE: Compiler can't infer target's non-nullness (https://github.com/dotnet/roslyn/issues/37300)
- }
-
- /// <summary>
- /// Ensure the lock object is initialized.
- /// </summary>
- /// <param name="syncLock">A reference to a location containing a mutual exclusive lock. If <paramref name="syncLock"/> is null,
- /// a new object will be instantiated.</param>
- /// <returns>Initialized lock object.</returns>
- private static object EnsureLockInitialized([NotNull] ref object? syncLock) =>
- syncLock ??
- Interlocked.CompareExchange(ref syncLock, new object(), null) ??
- syncLock;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/LazyThreadSafetyMode.cs b/netcore/System.Private.CoreLib/shared/System/Threading/LazyThreadSafetyMode.cs
deleted file mode 100644
index d2cc50f51b0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/LazyThreadSafetyMode.cs
+++ /dev/null
@@ -1,44 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-// a set of lightweight static helpers for lazy initialization.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-namespace System.Threading
-{
- /// <summary>
- /// Specifies how a <see cref="System.Lazy{T}"/> instance should synchronize access among multiple threads.
- /// </summary>
- public enum LazyThreadSafetyMode
- {
- /// <summary>
- /// This mode makes no guarantees around the thread-safety of the <see cref="System.Lazy{T}"/> instance. If used from multiple threads, the behavior of the <see cref="System.Lazy{T}"/> is undefined.
- /// This mode should be used when a <see cref="System.Lazy{T}"/> is guaranteed to never be initialized from more than one thread simultaneously and high performance is crucial.
- /// If valueFactory throws an exception when the <see cref="System.Lazy{T}"/> is initialized, the exception will be cached and returned on subsequent accesses to Value. Also, if valueFactory recursively
- /// accesses Value on this <see cref="System.Lazy{T}"/> instance, a <see cref="System.InvalidOperationException"/> will be thrown.
- /// </summary>
- None,
-
- /// <summary>
- /// When multiple threads attempt to simultaneously initialize a <see cref="System.Lazy{T}"/> instance, this mode allows each thread to execute the
- /// valueFactory but only the first thread to complete initialization will be allowed to set the final value of the <see cref="System.Lazy{T}"/>.
- /// Once initialized successfully, any future calls to Value will return the cached result. If valueFactory throws an exception on any thread, that exception will be
- /// propagated out of Value. If any thread executes valueFactory without throwing an exception and, therefore, successfully sets the value, that value will be returned on
- /// subsequent accesses to Value from any thread. If no thread succeeds in setting the value, IsValueCreated will remain false and subsequent accesses to Value will result in
- /// the valueFactory delegate re-executing. Also, if valueFactory recursively accesses Value on this <see cref="System.Lazy{T}"/> instance, an exception will NOT be thrown.
- /// </summary>
- PublicationOnly,
-
- /// <summary>
- /// This mode uses locks to ensure that only a single thread can initialize a <see cref="System.Lazy{T}"/> instance in a thread-safe manner. In general,
- /// taken if this mode is used in conjunction with a <see cref="System.Lazy{T}"/> valueFactory delegate that uses locks internally, a deadlock can occur if not
- /// handled carefully. If valueFactory throws an exception when the<see cref="System.Lazy{T}"/> is initialized, the exception will be cached and returned on
- /// subsequent accesses to Value. Also, if valueFactory recursively accesses Value on this <see cref="System.Lazy{T}"/> instance, a <see cref="System.InvalidOperationException"/> will be thrown.
- /// </summary>
- ExecutionAndPublication
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/LockRecursionException.cs b/netcore/System.Private.CoreLib/shared/System/Threading/LockRecursionException.cs
deleted file mode 100644
index 849417256e6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/LockRecursionException.cs
+++ /dev/null
@@ -1,31 +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 System.Runtime.Serialization;
-
-namespace System.Threading
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class LockRecursionException : System.Exception
- {
- public LockRecursionException()
- {
- }
-
- public LockRecursionException(string? message)
- : base(message)
- {
- }
-
- public LockRecursionException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- }
-
- protected LockRecursionException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/LowLevelLifoSemaphore.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Threading/LowLevelLifoSemaphore.Windows.cs
deleted file mode 100644
index 34d2895dd7d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/LowLevelLifoSemaphore.Windows.cs
+++ /dev/null
@@ -1,79 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- /// <summary>
- /// A LIFO semaphore implemented using Win32 IO Completion Ports.
- /// </summary>
- /// <remarks>
- /// IO Completion ports release waiting threads in LIFO order, so we can use them to create a LIFO semaphore.
- /// See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365198(v=vs.85).aspx under How I/O Completion Ports Work.
- /// From the docs "Threads that block their execution on an I/O completion port are released in last-in-first-out (LIFO) order."
- /// </remarks>
- internal sealed partial class LowLevelLifoSemaphore : IDisposable
- {
- private IntPtr _completionPort;
-
- private void Create(int maximumSignalCount)
- {
- Debug.Assert(maximumSignalCount > 0);
-
- _completionPort =
- Interop.Kernel32.CreateIoCompletionPort(new IntPtr(-1), IntPtr.Zero, UIntPtr.Zero, maximumSignalCount);
- if (_completionPort == IntPtr.Zero)
- {
- var error = Marshal.GetLastWin32Error();
- var exception = new OutOfMemoryException();
- exception.HResult = error;
- throw exception;
- }
- }
-
- ~LowLevelLifoSemaphore()
- {
- if (_completionPort != IntPtr.Zero)
- {
- Dispose();
- }
- }
-
- public bool WaitCore(int timeoutMs)
- {
- Debug.Assert(timeoutMs >= -1);
-
- bool success = Interop.Kernel32.GetQueuedCompletionStatus(_completionPort, out var numberOfBytes, out var completionKey, out var pointerToOverlapped, timeoutMs);
- Debug.Assert(success || (Marshal.GetLastWin32Error() == WaitHandle.WaitTimeout));
- return success;
- }
-
- public void ReleaseCore(int count)
- {
- Debug.Assert(count > 0);
-
- for (int i = 0; i < count; i++)
- {
- if(!Interop.Kernel32.PostQueuedCompletionStatus(_completionPort, 1, UIntPtr.Zero, IntPtr.Zero))
- {
- var lastError = Marshal.GetLastWin32Error();
- var exception = new OutOfMemoryException();
- exception.HResult = lastError;
- throw exception;
- }
- }
- }
-
- public void Dispose()
- {
- Debug.Assert(_completionPort != IntPtr.Zero);
-
- Interop.Kernel32.CloseHandle(_completionPort);
- _completionPort = IntPtr.Zero;
- GC.SuppressFinalize(this);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/LowLevelLifoSemaphore.cs b/netcore/System.Private.CoreLib/shared/System/Threading/LowLevelLifoSemaphore.cs
deleted file mode 100644
index 4e812549e3c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/LowLevelLifoSemaphore.cs
+++ /dev/null
@@ -1,295 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- /// <summary>
- /// A LIFO semaphore.
- /// Waits on this semaphore are uninterruptible.
- /// </summary>
- internal sealed partial class LowLevelLifoSemaphore : IDisposable
- {
- private CacheLineSeparatedCounts _separated;
-
- private int _maximumSignalCount;
- private int _spinCount;
-
- private const int SpinSleep0Threshold = 10;
-
- public LowLevelLifoSemaphore(int initialSignalCount, int maximumSignalCount, int spinCount)
- {
- Debug.Assert(initialSignalCount >= 0);
- Debug.Assert(initialSignalCount <= maximumSignalCount);
- Debug.Assert(maximumSignalCount > 0);
- Debug.Assert(spinCount >= 0);
-
- _separated = new CacheLineSeparatedCounts();
- _separated._counts._signalCount = (uint)initialSignalCount;
- _maximumSignalCount = maximumSignalCount;
- _spinCount = spinCount;
-
- Create(maximumSignalCount);
- }
-
- public bool Wait(int timeoutMs)
- {
- Debug.Assert(timeoutMs >= -1);
-
- // Try to acquire the semaphore or
- // a) register as a spinner if spinCount > 0 and timeoutMs > 0
- // b) register as a waiter if there's already too many spinners or spinCount == 0 and timeoutMs > 0
- // c) bail out if timeoutMs == 0 and return false
- Counts counts = _separated._counts;
- while (true)
- {
- Debug.Assert(counts._signalCount <= _maximumSignalCount);
- Counts newCounts = counts;
-
- if (counts._signalCount != 0)
- {
- newCounts._signalCount--;
- }
- else if (timeoutMs != 0)
- {
- if (_spinCount > 0 && newCounts._spinnerCount < byte.MaxValue)
- {
- newCounts._spinnerCount++;
- }
- else
- {
- // Maximum number of spinners reached, register as a waiter instead
- newCounts._waiterCount++;
- Debug.Assert(newCounts._waiterCount != 0); // overflow check, this many waiters is currently not supported
- }
- }
-
- Counts countsBeforeUpdate = _separated._counts.CompareExchange(newCounts, counts);
- if (countsBeforeUpdate == counts)
- {
- if (counts._signalCount != 0)
- {
- return true;
- }
- if (newCounts._waiterCount != counts._waiterCount)
- {
- return WaitForSignal(timeoutMs);
- }
- if (timeoutMs == 0)
- {
- return false;
- }
- break;
- }
-
- counts = countsBeforeUpdate;
- }
-
- int processorCount = Environment.ProcessorCount;
- int spinIndex = processorCount > 1 ? 0 : SpinSleep0Threshold;
- while (spinIndex < _spinCount)
- {
- LowLevelSpinWaiter.Wait(spinIndex, SpinSleep0Threshold, processorCount);
- spinIndex++;
-
- // Try to acquire the semaphore and unregister as a spinner
- counts = _separated._counts;
- while (counts._signalCount > 0)
- {
- Counts newCounts = counts;
- newCounts._signalCount--;
- newCounts._spinnerCount--;
-
- Counts countsBeforeUpdate = _separated._counts.CompareExchange(newCounts, counts);
- if (countsBeforeUpdate == counts)
- {
- return true;
- }
-
- counts = countsBeforeUpdate;
- }
- }
-
- // Unregister as spinner and acquire the semaphore or register as a waiter
- counts = _separated._counts;
- while (true)
- {
- Counts newCounts = counts;
- newCounts._spinnerCount--;
- if (counts._signalCount != 0)
- {
- newCounts._signalCount--;
- }
- else
- {
- newCounts._waiterCount++;
- Debug.Assert(newCounts._waiterCount != 0); // overflow check, this many waiters is currently not supported
- }
-
- Counts countsBeforeUpdate = _separated._counts.CompareExchange(newCounts, counts);
- if (countsBeforeUpdate == counts)
- {
- return counts._signalCount != 0 || WaitForSignal(timeoutMs);
- }
-
- counts = countsBeforeUpdate;
- }
- }
-
-
- public void Release(int releaseCount)
- {
- Debug.Assert(releaseCount > 0);
- Debug.Assert(releaseCount <= _maximumSignalCount);
-
- int countOfWaitersToWake;
- Counts counts = _separated._counts;
- while (true)
- {
- Counts newCounts = counts;
-
- // Increase the signal count. The addition doesn't overflow because of the limit on the max signal count in constructor.
- newCounts._signalCount += (uint)releaseCount;
- Debug.Assert(newCounts._signalCount > counts._signalCount);
-
- // Determine how many waiters to wake, taking into account how many spinners and waiters there are and how many waiters
- // have previously been signaled to wake but have not yet woken
- countOfWaitersToWake =
- (int)Math.Min(newCounts._signalCount, (uint)newCounts._waiterCount + newCounts._spinnerCount) -
- newCounts._spinnerCount -
- newCounts._countOfWaitersSignaledToWake;
- if (countOfWaitersToWake > 0)
- {
- // Ideally, limiting to a maximum of releaseCount would not be necessary and could be an assert instead, but since
- // WaitForSignal() does not have enough information to tell whether a woken thread was signaled, and due to the cap
- // below, it's possible for countOfWaitersSignaledToWake to be less than the number of threads that have actually
- // been signaled to wake.
- if (countOfWaitersToWake > releaseCount)
- {
- countOfWaitersToWake = releaseCount;
- }
-
- // Cap countOfWaitersSignaledToWake to its max value. It's ok to ignore some woken threads in this count, it just
- // means some more threads will be woken next time. Typically, it won't reach the max anyway.
- newCounts._countOfWaitersSignaledToWake += (byte)Math.Min(countOfWaitersToWake, byte.MaxValue);
- if (newCounts._countOfWaitersSignaledToWake <= counts._countOfWaitersSignaledToWake)
- {
- newCounts._countOfWaitersSignaledToWake = byte.MaxValue;
- }
- }
-
- Counts countsBeforeUpdate = _separated._counts.CompareExchange(newCounts, counts);
- if (countsBeforeUpdate == counts)
- {
- Debug.Assert(releaseCount <= _maximumSignalCount - counts._signalCount);
- if (countOfWaitersToWake > 0)
- ReleaseCore(countOfWaitersToWake);
- return;
- }
-
- counts = countsBeforeUpdate;
- }
- }
-
- private bool WaitForSignal(int timeoutMs)
- {
- Debug.Assert(timeoutMs > 0 || timeoutMs == -1);
-
- while (true)
- {
- if (!WaitCore(timeoutMs))
- {
- // Unregister the waiter. The wait subsystem used above guarantees that a thread that wakes due to a timeout does
- // not observe a signal to the object being waited upon.
- Counts toSubtract = new Counts();
- toSubtract._waiterCount++;
- Counts newCounts = _separated._counts.Subtract(toSubtract);
- Debug.Assert(newCounts._waiterCount != ushort.MaxValue); // Check for underflow
- return false;
- }
-
- // Unregister the waiter if this thread will not be waiting anymore, and try to acquire the semaphore
- Counts counts = _separated._counts;
- while (true)
- {
- Debug.Assert(counts._waiterCount != 0);
- Counts newCounts = counts;
- if (counts._signalCount != 0)
- {
- --newCounts._signalCount;
- --newCounts._waiterCount;
- }
-
- // This waiter has woken up and this needs to be reflected in the count of waiters signaled to wake
- if (counts._countOfWaitersSignaledToWake != 0)
- {
- --newCounts._countOfWaitersSignaledToWake;
- }
-
- Counts countsBeforeUpdate = _separated._counts.CompareExchange(newCounts, counts);
- if (countsBeforeUpdate == counts)
- {
- if (counts._signalCount != 0)
- {
- return true;
- }
- break;
- }
-
- counts = countsBeforeUpdate;
- }
- }
- }
-
- [StructLayout(LayoutKind.Explicit)]
- private struct Counts
- {
- [FieldOffset(0)]
- public uint _signalCount;
- [FieldOffset(4)]
- public ushort _waiterCount;
- [FieldOffset(6)]
- public byte _spinnerCount;
- [FieldOffset(8)]
- public byte _countOfWaitersSignaledToWake;
-
- [FieldOffset(0)]
- private long _asLong;
-
- public Counts CompareExchange(Counts newCounts, Counts oldCounts)
- {
- return new Counts { _asLong = Interlocked.CompareExchange(ref _asLong, newCounts._asLong, oldCounts._asLong) };
- }
-
- public Counts Subtract(Counts subtractCounts)
- {
- return new Counts { _asLong = Interlocked.Add(ref _asLong, -subtractCounts._asLong) };
- }
-
- public static bool operator ==(Counts lhs, Counts rhs) => lhs._asLong == rhs._asLong;
-
- public static bool operator !=(Counts lhs, Counts rhs) => lhs._asLong != rhs._asLong;
-
- public override bool Equals(object? obj)
- {
- return obj is Counts counts && this._asLong == counts._asLong;
- }
-
- public override int GetHashCode()
- {
- return (int)(_asLong >> 8);
- }
- }
-
- [StructLayout(LayoutKind.Sequential)]
- private struct CacheLineSeparatedCounts
- {
- private Internal.PaddingFor32 _pad1;
- public Counts _counts;
- private Internal.PaddingFor32 _pad2;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ManualResetEvent.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ManualResetEvent.cs
deleted file mode 100644
index 0e08108b3c0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ManualResetEvent.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Threading
-{
- public sealed class ManualResetEvent : EventWaitHandle
- {
- public ManualResetEvent(bool initialState) : base(initialState, EventResetMode.ManualReset) { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ManualResetEventSlim.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ManualResetEventSlim.cs
deleted file mode 100644
index 19f39ac7ec4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ManualResetEventSlim.cs
+++ /dev/null
@@ -1,726 +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 System.Diagnostics;
-
-namespace System.Threading
-{
- // ManualResetEventSlim wraps a manual-reset event internally with a little bit of
- // spinning. When an event will be set imminently, it is often advantageous to avoid
- // a 4k+ cycle context switch in favor of briefly spinning. Therefore we layer on to
- // a brief amount of spinning that should, on the average, make using the slim event
- // cheaper than using Win32 events directly. This can be reset manually, much like
- // a Win32 manual-reset would be.
- //
- // Notes:
- // We lazily allocate the Win32 event internally. Therefore, the caller should
- // always call Dispose to clean it up, just in case. This API is a no-op of the
- // event wasn't allocated, but if it was, ensures that the event goes away
- // eagerly, instead of waiting for finalization.
-
- /// <summary>
- /// Provides a slimmed down version of <see cref="System.Threading.ManualResetEvent"/>.
- /// </summary>
- /// <remarks>
- /// All public and protected members of <see cref="ManualResetEventSlim"/> are thread-safe and may be used
- /// concurrently from multiple threads, with the exception of Dispose, which
- /// must only be used when all other operations on the <see cref="ManualResetEventSlim"/> have
- /// completed, and Reset, which should only be used when no other threads are
- /// accessing the event.
- /// </remarks>
- [DebuggerDisplay("Set = {IsSet}")]
- public class ManualResetEventSlim : IDisposable
- {
- // These are the default spin counts we use on single-proc and MP machines.
- private const int DEFAULT_SPIN_SP = 1;
-
- private volatile object? m_lock;
- // A lock used for waiting and pulsing. Lazily initialized via EnsureLockObjectCreated()
-
- private volatile ManualResetEvent? m_eventObj; // A true Win32 event used for waiting.
-
- // -- State -- //
- // For a packed word a uint would seem better, but Interlocked.* doesn't support them as uint isn't CLS-compliant.
- private volatile int m_combinedState; // ie a uint. Used for the state items listed below.
-
- // 1-bit for signalled state
- private const int SignalledState_BitMask = unchecked((int)0x80000000); // 1000 0000 0000 0000 0000 0000 0000 0000
- private const int SignalledState_ShiftCount = 31;
-
- // 1-bit for disposed state
- private const int Dispose_BitMask = unchecked((int)0x40000000); // 0100 0000 0000 0000 0000 0000 0000 0000
-
- // 11-bits for m_spinCount
- private const int SpinCountState_BitMask = unchecked((int)0x3FF80000); // 0011 1111 1111 1000 0000 0000 0000 0000
- private const int SpinCountState_ShiftCount = 19;
- private const int SpinCountState_MaxValue = (1 << 11) - 1; // 2047
-
- // 19-bits for m_waiters. This allows support of 512K threads waiting which should be ample
- private const int NumWaitersState_BitMask = unchecked((int)0x0007FFFF); // 0000 0000 0000 0111 1111 1111 1111 1111
- private const int NumWaitersState_ShiftCount = 0;
- private const int NumWaitersState_MaxValue = (1 << 19) - 1; // 512K-1
- // ----------- //
-
- /// <summary>
- /// Gets the underlying <see cref="System.Threading.WaitHandle"/> object for this <see
- /// cref="ManualResetEventSlim"/>.
- /// </summary>
- /// <value>The underlying <see cref="System.Threading.WaitHandle"/> event object fore this <see
- /// cref="ManualResetEventSlim"/>.</value>
- /// <remarks>
- /// Accessing this property forces initialization of an underlying event object if one hasn't
- /// already been created. To simply wait on this <see cref="ManualResetEventSlim"/>,
- /// the public Wait methods should be preferred.
- /// </remarks>
- public WaitHandle WaitHandle
- {
- get
- {
- ThrowIfDisposed();
- if (m_eventObj == null)
- {
- // Lazily initialize the event object if needed.
- LazyInitializeEvent();
- Debug.Assert(m_eventObj != null);
- }
-
- return m_eventObj;
- }
- }
-
- /// <summary>
- /// Gets whether the event is set.
- /// </summary>
- /// <value>true if the event has is set; otherwise, false.</value>
- public bool IsSet
- {
- get => 0 != ExtractStatePortion(m_combinedState, SignalledState_BitMask);
- private set => UpdateStateAtomically(((value) ? 1 : 0) << SignalledState_ShiftCount, SignalledState_BitMask);
- }
-
- /// <summary>
- /// Gets the number of spin waits that will be occur before falling back to a true wait.
- /// </summary>
- public int SpinCount
- {
- get => ExtractStatePortionAndShiftRight(m_combinedState, SpinCountState_BitMask, SpinCountState_ShiftCount);
- private set
- {
- Debug.Assert(value >= 0, "SpinCount is a restricted-width integer. The value supplied is outside the legal range.");
- Debug.Assert(value <= SpinCountState_MaxValue, "SpinCount is a restricted-width integer. The value supplied is outside the legal range.");
- // Don't worry about thread safety because it's set one time from the constructor
- m_combinedState = (m_combinedState & ~SpinCountState_BitMask) | (value << SpinCountState_ShiftCount);
- }
- }
-
- /// <summary>
- /// How many threads are waiting.
- /// </summary>
- private int Waiters
- {
- get => ExtractStatePortionAndShiftRight(m_combinedState, NumWaitersState_BitMask, NumWaitersState_ShiftCount);
- set
- {
- // setting to <0 would indicate an internal flaw, hence Assert is appropriate.
- Debug.Assert(value >= 0, "NumWaiters should never be less than zero. This indicates an internal error.");
-
- // it is possible for the max number of waiters to be exceeded via user-code, hence we use a real exception here.
- if (value >= NumWaitersState_MaxValue)
- throw new InvalidOperationException(SR.Format(SR.ManualResetEventSlim_ctor_TooManyWaiters, NumWaitersState_MaxValue));
-
- UpdateStateAtomically(value << NumWaitersState_ShiftCount, NumWaitersState_BitMask);
- }
- }
-
- //-----------------------------------------------------------------------------------
- // Constructs a new event, optionally specifying the initial state and spin count.
- // The defaults are that the event is unsignaled and some reasonable default spin.
- //
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ManualResetEventSlim"/>
- /// class with an initial state of nonsignaled.
- /// </summary>
- public ManualResetEventSlim()
- : this(false)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ManualResetEventSlim"/>
- /// class with a boolean value indicating whether to set the initial state to signaled.
- /// </summary>
- /// <param name="initialState">true to set the initial state signaled; false to set the initial state
- /// to nonsignaled.</param>
- public ManualResetEventSlim(bool initialState)
- {
- // Specify the default spin count, and use default spin if we're
- // on a multi-processor machine. Otherwise, we won't.
- Initialize(initialState, SpinWait.SpinCountforSpinBeforeWait);
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ManualResetEventSlim"/>
- /// class with a Boolean value indicating whether to set the initial state to signaled and a specified
- /// spin count.
- /// </summary>
- /// <param name="initialState">true to set the initial state to signaled; false to set the initial state
- /// to nonsignaled.</param>
- /// <param name="spinCount">The number of spin waits that will occur before falling back to a true
- /// wait.</param>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="spinCount"/> is less than
- /// 0 or greater than the maximum allowed value.</exception>
- public ManualResetEventSlim(bool initialState, int spinCount)
- {
- if (spinCount < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(spinCount));
- }
-
- if (spinCount > SpinCountState_MaxValue)
- {
- throw new ArgumentOutOfRangeException(
- nameof(spinCount),
- SR.Format(SR.ManualResetEventSlim_ctor_SpinCountOutOfRange, SpinCountState_MaxValue));
- }
-
- // We will suppress default spin because the user specified a count.
- Initialize(initialState, spinCount);
- }
-
- /// <summary>
- /// Initializes the internal state of the event.
- /// </summary>
- /// <param name="initialState">Whether the event is set initially or not.</param>
- /// <param name="spinCount">The spin count that decides when the event will block.</param>
- private void Initialize(bool initialState, int spinCount)
- {
- m_combinedState = initialState ? (1 << SignalledState_ShiftCount) : 0;
- // the spinCount argument has been validated by the ctors.
- // but we now sanity check our predefined constants.
- Debug.Assert(DEFAULT_SPIN_SP >= 0, "Internal error - DEFAULT_SPIN_SP is outside the legal range.");
- Debug.Assert(DEFAULT_SPIN_SP <= SpinCountState_MaxValue, "Internal error - DEFAULT_SPIN_SP is outside the legal range.");
-
- SpinCount = Environment.IsSingleProcessor ? DEFAULT_SPIN_SP : spinCount;
- }
-
- /// <summary>
- /// Helper to ensure the lock object is created before first use.
- /// </summary>
- private void EnsureLockObjectCreated()
- {
- if (m_lock != null)
- return;
-
- object newObj = new object();
- Interlocked.CompareExchange(ref m_lock, newObj, null); // failure is benign. Someone else set the value.
- }
-
- /// <summary>
- /// This method lazily initializes the event object. It uses CAS to guarantee that
- /// many threads racing to call this at once don't result in more than one event
- /// being stored and used. The event will be signaled or unsignaled depending on
- /// the state of the thin-event itself, with synchronization taken into account.
- /// </summary>
- private void LazyInitializeEvent()
- {
- bool preInitializeIsSet = IsSet;
- ManualResetEvent newEventObj = new ManualResetEvent(preInitializeIsSet);
-
- // We have to CAS this in case we are racing with another thread. We must
- // guarantee only one event is actually stored in this field.
- if (Interlocked.CompareExchange(ref m_eventObj, newEventObj, null) != null)
- {
- // Someone else set the value due to a race condition. Destroy the garbage event.
- newEventObj.Dispose();
- }
- else
- {
- // Now that the event is published, verify that the state hasn't changed since
- // we snapped the preInitializeState. Another thread could have done that
- // between our initial observation above and here. The barrier incurred from
- // the CAS above (in addition to m_state being volatile) prevents this read
- // from moving earlier and being collapsed with our original one.
- bool currentIsSet = IsSet;
- if (currentIsSet != preInitializeIsSet)
- {
- Debug.Assert(currentIsSet,
- "The only safe concurrent transition is from unset->set: detected set->unset.");
-
- // We saw it as unsignaled, but it has since become set.
- lock (newEventObj)
- {
- // If our event hasn't already been disposed of, we must set it.
- if (m_eventObj == newEventObj)
- {
- newEventObj.Set();
- }
- }
- }
- }
- }
-
- /// <summary>
- /// Sets the state of the event to signaled, which allows one or more threads waiting on the event to
- /// proceed.
- /// </summary>
- public void Set()
- {
- Set(false);
- }
-
- /// <summary>
- /// Private helper to actually perform the Set.
- /// </summary>
- /// <param name="duringCancellation">Indicates whether we are calling Set() during cancellation.</param>
- /// <exception cref="System.OperationCanceledException">The object has been canceled.</exception>
- private void Set(bool duringCancellation)
- {
- // We need to ensure that IsSet=true does not get reordered past the read of m_eventObj
- // This would be a legal movement according to the .NET memory model.
- // The code is safe as IsSet involves an Interlocked.CompareExchange which provides a full memory barrier.
- IsSet = true;
-
- // If there are waiting threads, we need to pulse them.
- if (Waiters > 0)
- {
- Debug.Assert(m_lock != null); // if waiters>0, then m_lock has already been created.
- lock (m_lock)
- {
- Monitor.PulseAll(m_lock);
- }
- }
-
- ManualResetEvent? eventObj = m_eventObj;
-
- // Design-decision: do not set the event if we are in cancellation -> better to deadlock than to wake up waiters incorrectly
- // It would be preferable to wake up the event and have it throw OCE. This requires MRE to implement cancellation logic
-
- if (eventObj != null && !duringCancellation)
- {
- // We must surround this call to Set in a lock. The reason is fairly subtle.
- // Sometimes a thread will issue a Wait and wake up after we have set m_state,
- // but before we have gotten around to setting m_eventObj (just below). That's
- // because Wait first checks m_state and will only access the event if absolutely
- // necessary. However, the coding pattern { event.Wait(); event.Dispose() } is
- // quite common, and we must support it. If the waiter woke up and disposed of
- // the event object before the setter has finished, however, we would try to set a
- // now-disposed Win32 event. Crash! To deal with this race condition, we use a lock to
- // protect access to the event object when setting and disposing of it. We also
- // double-check that the event has not become null in the meantime when in the lock.
-
- lock (eventObj)
- {
- if (m_eventObj != null)
- {
- // If somebody is waiting, we must set the event.
- m_eventObj.Set();
- }
- }
- }
- }
-
- /// <summary>
- /// Sets the state of the event to nonsignaled, which causes threads to block.
- /// </summary>
- /// <remarks>
- /// Unlike most of the members of <see cref="ManualResetEventSlim"/>, <see cref="Reset()"/> is not
- /// thread-safe and may not be used concurrently with other members of this instance.
- /// </remarks>
- public void Reset()
- {
- ThrowIfDisposed();
- // If there's an event, reset it.
- if (m_eventObj != null)
- {
- m_eventObj.Reset();
- }
-
- // There is a race condition here. If another thread Sets the event, we will get into a state
- // where m_state will be unsignaled, yet the Win32 event object will have been signaled.
- // This could cause waiting threads to wake up even though the event is in an
- // unsignaled state. This is fine -- those that are calling Reset concurrently are
- // responsible for doing "the right thing" -- e.g. rechecking the condition and
- // resetting the event manually.
-
- // And finally set our state back to unsignaled.
- IsSet = false;
- }
-
- /// <summary>
- /// Blocks the current thread until the current <see cref="ManualResetEventSlim"/> is set.
- /// </summary>
- /// <exception cref="System.InvalidOperationException">
- /// The maximum number of waiters has been exceeded.
- /// </exception>
- /// <remarks>
- /// The caller of this method blocks indefinitely until the current instance is set. The caller will
- /// return immediately if the event is currently in a set state.
- /// </remarks>
- public void Wait()
- {
- Wait(Timeout.Infinite, CancellationToken.None);
- }
-
- /// <summary>
- /// Blocks the current thread until the current <see cref="ManualResetEventSlim"/> receives a signal,
- /// while observing a <see cref="System.Threading.CancellationToken"/>.
- /// </summary>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> to
- /// observe.</param>
- /// <exception cref="System.InvalidOperationException">
- /// The maximum number of waiters has been exceeded.
- /// </exception>
- /// <exception cref="System.OperationCanceledException"><paramref name="cancellationToken"/> was
- /// canceled.</exception>
- /// <remarks>
- /// The caller of this method blocks indefinitely until the current instance is set. The caller will
- /// return immediately if the event is currently in a set state.
- /// </remarks>
- public void Wait(CancellationToken cancellationToken)
- {
- Wait(Timeout.Infinite, cancellationToken);
- }
-
- /// <summary>
- /// Blocks the current thread until the current <see cref="ManualResetEventSlim"/> is set, using a
- /// <see cref="System.TimeSpan"/> to measure the time interval.
- /// </summary>
- /// <param name="timeout">A <see cref="System.TimeSpan"/> that represents the number of milliseconds
- /// to wait, or a <see cref="System.TimeSpan"/> that represents -1 milliseconds to wait indefinitely.
- /// </param>
- /// <returns>true if the <see cref="System.Threading.ManualResetEventSlim"/> was set; otherwise,
- /// false.</returns>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="timeout"/> is a negative
- /// number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater
- /// than <see cref="int.MaxValue"/>.</exception>
- /// <exception cref="System.InvalidOperationException">
- /// The maximum number of waiters has been exceeded.
- /// </exception>
- public bool Wait(TimeSpan timeout)
- {
- long totalMilliseconds = (long)timeout.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- throw new ArgumentOutOfRangeException(nameof(timeout));
- }
-
- return Wait((int)totalMilliseconds, CancellationToken.None);
- }
-
- /// <summary>
- /// Blocks the current thread until the current <see cref="ManualResetEventSlim"/> is set, using a
- /// <see cref="System.TimeSpan"/> to measure the time interval, while observing a <see
- /// cref="System.Threading.CancellationToken"/>.
- /// </summary>
- /// <param name="timeout">A <see cref="System.TimeSpan"/> that represents the number of milliseconds
- /// to wait, or a <see cref="System.TimeSpan"/> that represents -1 milliseconds to wait indefinitely.
- /// </param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> to
- /// observe.</param>
- /// <returns>true if the <see cref="System.Threading.ManualResetEventSlim"/> was set; otherwise,
- /// false.</returns>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="timeout"/> is a negative
- /// number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater
- /// than <see cref="int.MaxValue"/>.</exception>
- /// <exception cref="System.OperationCanceledException"><paramref
- /// name="cancellationToken"/> was canceled.</exception>
- /// <exception cref="System.InvalidOperationException">
- /// The maximum number of waiters has been exceeded.
- /// </exception>
- public bool Wait(TimeSpan timeout, CancellationToken cancellationToken)
- {
- long totalMilliseconds = (long)timeout.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- throw new ArgumentOutOfRangeException(nameof(timeout));
- }
-
- return Wait((int)totalMilliseconds, cancellationToken);
- }
-
- /// <summary>
- /// Blocks the current thread until the current <see cref="ManualResetEventSlim"/> is set, using a
- /// 32-bit signed integer to measure the time interval.
- /// </summary>
- /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see
- /// cref="Timeout.Infinite"/>(-1) to wait indefinitely.</param>
- /// <returns>true if the <see cref="System.Threading.ManualResetEventSlim"/> was set; otherwise,
- /// false.</returns>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is a
- /// negative number other than -1, which represents an infinite time-out.</exception>
- /// <exception cref="System.InvalidOperationException">
- /// The maximum number of waiters has been exceeded.
- /// </exception>
- public bool Wait(int millisecondsTimeout)
- {
- return Wait(millisecondsTimeout, CancellationToken.None);
- }
-
- /// <summary>
- /// Blocks the current thread until the current <see cref="ManualResetEventSlim"/> is set, using a
- /// 32-bit signed integer to measure the time interval, while observing a <see
- /// cref="System.Threading.CancellationToken"/>.
- /// </summary>
- /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see
- /// cref="Timeout.Infinite"/>(-1) to wait indefinitely.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> to
- /// observe.</param>
- /// <returns>true if the <see cref="System.Threading.ManualResetEventSlim"/> was set; otherwise,
- /// false.</returns>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is a
- /// negative number other than -1, which represents an infinite time-out.</exception>
- /// <exception cref="System.InvalidOperationException">
- /// The maximum number of waiters has been exceeded.
- /// </exception>
- /// <exception cref="System.OperationCanceledException"><paramref
- /// name="cancellationToken"/> was canceled.</exception>
- public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
- {
- ThrowIfDisposed();
- cancellationToken.ThrowIfCancellationRequested(); // an early convenience check
-
- if (millisecondsTimeout < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout));
- }
-
- if (!IsSet)
- {
- if (millisecondsTimeout == 0)
- {
- // For 0-timeouts, we just return immediately.
- return false;
- }
-
-
- // We spin briefly before falling back to allocating and/or waiting on a true event.
- uint startTime = 0;
- bool bNeedTimeoutAdjustment = false;
- int realMillisecondsTimeout = millisecondsTimeout; // this will be adjusted if necessary.
-
- if (millisecondsTimeout != Timeout.Infinite)
- {
- // We will account for time spent spinning, so that we can decrement it from our
- // timeout. In most cases the time spent in this section will be negligible. But
- // we can't discount the possibility of our thread being switched out for a lengthy
- // period of time. The timeout adjustments only take effect when and if we actually
- // decide to block in the kernel below.
-
- startTime = TimeoutHelper.GetTime();
- bNeedTimeoutAdjustment = true;
- }
-
- // Spin
- int spinCount = SpinCount;
- SpinWait spinner = default;
- while (spinner.Count < spinCount)
- {
- spinner.SpinOnce(sleep1Threshold: -1);
-
- if (IsSet)
- {
- return true;
- }
-
- if (spinner.Count >= 100 && spinner.Count % 10 == 0) // check the cancellation token if the user passed a very large spin count
- cancellationToken.ThrowIfCancellationRequested();
- }
-
- // Now enter the lock and wait. Must be created before registering the cancellation callback,
- // which will try to take this lock.
- EnsureLockObjectCreated();
-
- // We must register and unregister the token outside of the lock, to avoid deadlocks.
- using (cancellationToken.UnsafeRegister(s_cancellationTokenCallback, this))
- {
- lock (m_lock!)
- {
- // Loop to cope with spurious wakeups from other waits being canceled
- while (!IsSet)
- {
- // If our token was canceled, we must throw and exit.
- cancellationToken.ThrowIfCancellationRequested();
-
- // update timeout (delays in wait commencement are due to spinning and/or spurious wakeups from other waits being canceled)
- if (bNeedTimeoutAdjustment)
- {
- realMillisecondsTimeout = TimeoutHelper.UpdateTimeOut(startTime, millisecondsTimeout);
- if (realMillisecondsTimeout <= 0)
- return false;
- }
-
- // There is a race condition that Set will fail to see that there are waiters as Set does not take the lock,
- // so after updating waiters, we must check IsSet again.
- // Also, we must ensure there cannot be any reordering of the assignment to Waiters and the
- // read from IsSet. This is guaranteed as Waiters{set;} involves an Interlocked.CompareExchange
- // operation which provides a full memory barrier.
- // If we see IsSet=false, then we are guaranteed that Set() will see that we are
- // waiting and will pulse the monitor correctly.
-
- Waiters++;
-
- if (IsSet) // This check must occur after updating Waiters.
- {
- Waiters--; // revert the increment.
- return true;
- }
-
- // Now finally perform the wait.
- try
- {
- // ** the actual wait **
- if (!Monitor.Wait(m_lock, realMillisecondsTimeout))
- return false; // return immediately if the timeout has expired.
- }
- finally
- {
- // Clean up: we're done waiting.
- Waiters--;
- }
- // Now just loop back around, and the right thing will happen. Either:
- // 1. We had a spurious wake-up due to some other wait being canceled via a different cancellationToken (rewait)
- // or 2. the wait was successful. (the loop will break)
- }
- }
- }
- } // automatically disposes (and unregisters) the callback
-
- return true; // done. The wait was satisfied.
- }
-
- /// <summary>
- /// Releases all resources used by the current instance of <see cref="ManualResetEventSlim"/>.
- /// </summary>
- /// <remarks>
- /// Unlike most of the members of <see cref="ManualResetEventSlim"/>, <see cref="Dispose()"/> is not
- /// thread-safe and may not be used concurrently with other members of this instance.
- /// </remarks>
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- /// <summary>
- /// When overridden in a derived class, releases the unmanaged resources used by the
- /// <see cref="ManualResetEventSlim"/>, and optionally releases the managed resources.
- /// </summary>
- /// <param name="disposing">true to release both managed and unmanaged resources;
- /// false to release only unmanaged resources.</param>
- /// <remarks>
- /// Unlike most of the members of <see cref="ManualResetEventSlim"/>, <see cref="Dispose(bool)"/> is not
- /// thread-safe and may not be used concurrently with other members of this instance.
- /// </remarks>
- protected virtual void Dispose(bool disposing)
- {
- if ((m_combinedState & Dispose_BitMask) != 0)
- return; // already disposed
-
- m_combinedState |= Dispose_BitMask; // set the dispose bit
- if (disposing)
- {
- // We will dispose of the event object. We do this under a lock to protect
- // against the race condition outlined in the Set method above.
- ManualResetEvent? eventObj = m_eventObj;
- if (eventObj != null)
- {
- lock (eventObj)
- {
- eventObj.Dispose();
- m_eventObj = null;
- }
- }
- }
- }
-
- /// <summary>
- /// Throw ObjectDisposedException if the MRES is disposed
- /// </summary>
- private void ThrowIfDisposed()
- {
- if ((m_combinedState & Dispose_BitMask) != 0)
- throw new ObjectDisposedException(SR.ManualResetEventSlim_Disposed);
- }
-
- /// <summary>
- /// Private helper method to wake up waiters when a cancellationToken gets canceled.
- /// </summary>
- private static readonly Action<object?> s_cancellationTokenCallback = new Action<object?>(CancellationTokenCallback);
- private static void CancellationTokenCallback(object? obj)
- {
- Debug.Assert(obj is ManualResetEventSlim, "Expected a ManualResetEventSlim");
- ManualResetEventSlim mre = (ManualResetEventSlim)obj;
- Debug.Assert(mre.m_lock != null); // the lock should have been created before this callback is registered for use.
- lock (mre.m_lock)
- {
- Monitor.PulseAll(mre.m_lock); // awaken all waiters
- }
- }
-
- /// <summary>
- /// Private helper method for updating parts of a bit-string state value.
- /// Mainly called from the IsSet and Waiters properties setters
- /// </summary>
- /// <remarks>
- /// Note: the parameter types must be int as CompareExchange cannot take a Uint
- /// </remarks>
- /// <param name="newBits">The new value</param>
- /// <param name="updateBitsMask">The mask used to set the bits</param>
- private void UpdateStateAtomically(int newBits, int updateBitsMask)
- {
- SpinWait sw = default;
-
- Debug.Assert((newBits | updateBitsMask) == updateBitsMask, "newBits do not fall within the updateBitsMask.");
-
- while (true)
- {
- int oldState = m_combinedState; // cache the old value for testing in CAS
-
- // Procedure:(1) zero the updateBits. eg oldState = [11111111] flag= [00111000] newState = [11000111]
- // then (2) map in the newBits. eg [11000111] newBits=00101000, newState=[11101111]
- int newState = (oldState & ~updateBitsMask) | newBits;
-
- if (Interlocked.CompareExchange(ref m_combinedState, newState, oldState) == oldState)
- {
- return;
- }
-
- sw.SpinOnce(sleep1Threshold: -1);
- }
- }
-
- /// <summary>
- /// Private helper method - performs Mask and shift, particular helpful to extract a field from a packed word.
- /// eg ExtractStatePortionAndShiftRight(0x12345678, 0xFF000000, 24) => 0x12, ie extracting the top 8-bits as a simple integer
- ///
- /// ?? is there a common place to put this rather than being private to MRES?
- /// </summary>
- /// <param name="state"></param>
- /// <param name="mask"></param>
- /// <param name="rightBitShiftCount"></param>
- /// <returns></returns>
- private static int ExtractStatePortionAndShiftRight(int state, int mask, int rightBitShiftCount)
- {
- // convert to uint before shifting so that right-shift does not replicate the sign-bit,
- // then convert back to int.
- return unchecked((int)(((uint)(state & mask)) >> rightBitShiftCount));
- }
-
- /// <summary>
- /// Performs a Mask operation, but does not perform the shift.
- /// This is acceptable for boolean values for which the shift is unnecessary
- /// eg (val &amp; Mask) != 0 is an appropriate way to extract a boolean rather than using
- /// ((val &amp; Mask) &gt;&gt; shiftAmount) == 1
- ///
- /// ?? is there a common place to put this rather than being private to MRES?
- /// </summary>
- /// <param name="state"></param>
- /// <param name="mask"></param>
- private static int ExtractStatePortion(int state, int mask)
- {
- return state & mask;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs
deleted file mode 100644
index 7226538f7e7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs
+++ /dev/null
@@ -1,97 +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 System.IO;
-using Microsoft.Win32.SafeHandles;
-using System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- /// <summary>
- /// Synchronization primitive that can also be used for interprocess synchronization
- /// </summary>
- public sealed partial class Mutex : WaitHandle
- {
- private const uint AccessRights =
- (uint)Interop.Kernel32.MAXIMUM_ALLOWED | Interop.Kernel32.SYNCHRONIZE | Interop.Kernel32.MUTEX_MODIFY_STATE;
-
- private void CreateMutexCore(bool initiallyOwned, string? name, out bool createdNew)
- {
- uint mutexFlags = initiallyOwned ? Interop.Kernel32.CREATE_MUTEX_INITIAL_OWNER : 0;
- SafeWaitHandle mutexHandle = Interop.Kernel32.CreateMutexEx(IntPtr.Zero, name, mutexFlags, AccessRights);
- int errorCode = Marshal.GetLastWin32Error();
-
- if (mutexHandle.IsInvalid)
- {
- mutexHandle.SetHandleAsInvalid();
-#if !PLATFORM_WINDOWS
- if (errorCode == Interop.Errors.ERROR_FILENAME_EXCED_RANGE)
- // On Unix, length validation is done by CoreCLR's PAL after converting to utf-8
- throw new ArgumentException(SR.Argument_WaitHandleNameTooLong, nameof(name));
-#endif
- if (errorCode == Interop.Errors.ERROR_INVALID_HANDLE)
- throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));
-
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, name);
- }
-
- createdNew = errorCode != Interop.Errors.ERROR_ALREADY_EXISTS;
- SafeWaitHandle = mutexHandle;
- }
-
- private static OpenExistingResult OpenExistingWorker(string name, out Mutex? result)
- {
- if (name == null)
- {
- throw new ArgumentNullException(nameof(name));
- }
-
- if (name.Length == 0)
- {
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
- }
-
- result = null;
- // To allow users to view & edit the ACL's, call OpenMutex
- // with parameters to allow us to view & edit the ACL. This will
- // fail if we don't have permission to view or edit the ACL's.
- // If that happens, ask for less permissions.
- SafeWaitHandle myHandle = Interop.Kernel32.OpenMutex(AccessRights, false, name);
-
- if (myHandle.IsInvalid)
- {
- int errorCode = Marshal.GetLastWin32Error();
-#if !PLATFORM_WINDOWS
- if (errorCode == Interop.Errors.ERROR_FILENAME_EXCED_RANGE)
- {
- // On Unix, length validation is done by CoreCLR's PAL after converting to utf-8
- throw new ArgumentException(SR.Argument_WaitHandleNameTooLong, nameof(name));
- }
-#endif
- if (Interop.Errors.ERROR_FILE_NOT_FOUND == errorCode || Interop.Errors.ERROR_INVALID_NAME == errorCode)
- return OpenExistingResult.NameNotFound;
- if (Interop.Errors.ERROR_PATH_NOT_FOUND == errorCode)
- return OpenExistingResult.PathNotFound;
- if (Interop.Errors.ERROR_INVALID_HANDLE == errorCode)
- return OpenExistingResult.NameInvalid;
-
- throw Win32Marshal.GetExceptionForWin32Error(errorCode, name);
- }
-
- result = new Mutex(myHandle);
- return OpenExistingResult.Success;
- }
-
- // Note: To call ReleaseMutex, you must have an ACL granting you
- // MUTEX_MODIFY_STATE rights (0x0001). The other interesting value
- // in a Mutex's ACL is MUTEX_ALL_ACCESS (0x1F0001).
- public void ReleaseMutex()
- {
- if (!Interop.Kernel32.ReleaseMutex(SafeWaitHandle))
- {
- throw new ApplicationException(SR.Arg_SynchronizationLockException);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Mutex.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Mutex.cs
deleted file mode 100644
index 1effbc63bd1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Mutex.cs
+++ /dev/null
@@ -1,62 +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.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.IO;
-
-namespace System.Threading
-{
- /// <summary>
- /// Synchronization primitive that can also be used for interprocess synchronization
- /// </summary>
- public sealed partial class Mutex : WaitHandle
- {
- public Mutex(bool initiallyOwned, string? name, out bool createdNew)
- {
- CreateMutexCore(initiallyOwned, name, out createdNew);
- }
-
- public Mutex(bool initiallyOwned, string? name)
- {
- CreateMutexCore(initiallyOwned, name, out _);
- }
-
- public Mutex(bool initiallyOwned)
- {
- CreateMutexCore(initiallyOwned, null, out _);
- }
-
- public Mutex()
- {
- CreateMutexCore(false, null, out _);
- }
-
- private Mutex(SafeWaitHandle handle)
- {
- SafeWaitHandle = handle;
- }
-
- public static Mutex OpenExisting(string name)
- {
- switch (OpenExistingWorker(name, out Mutex? result))
- {
- case OpenExistingResult.NameNotFound:
- throw new WaitHandleCannotBeOpenedException();
- case OpenExistingResult.NameInvalid:
- throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));
- case OpenExistingResult.PathNotFound:
- throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, name));
-
- default:
- Debug.Assert(result != null, "result should be non-null on success");
- return result;
- }
- }
-
- public static bool TryOpenExisting(string name, [NotNullWhen(true)] out Mutex? result) =>
- OpenExistingWorker(name, out result) == OpenExistingResult.Success;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/NativeOverlapped.cs b/netcore/System.Private.CoreLib/shared/System/Threading/NativeOverlapped.cs
deleted file mode 100644
index 933cb81ecc6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/NativeOverlapped.cs
+++ /dev/null
@@ -1,18 +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 System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- [StructLayout(LayoutKind.Sequential)]
- public struct NativeOverlapped
- {
- public IntPtr InternalLow;
- public IntPtr InternalHigh;
- public int OffsetLow;
- public int OffsetHigh;
- public IntPtr EventHandle;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ParameterizedThreadStart.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ParameterizedThreadStart.cs
deleted file mode 100644
index 124840a3bf7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ParameterizedThreadStart.cs
+++ /dev/null
@@ -1,18 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: This class is a Delegate which defines the start method
-** for starting a thread. That method must match this delegate.
-**
-**
-=============================================================================*/
-
-namespace System.Threading
-{
- public delegate void ParameterizedThreadStart(object? obj);
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.CpuUtilizationReader.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.CpuUtilizationReader.Unix.cs
deleted file mode 100644
index 582fc74a778..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.CpuUtilizationReader.Unix.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.Threading
-{
- internal partial class PortableThreadPool
- {
- private class CpuUtilizationReader
- {
- private Interop.Sys.ProcessCpuInformation _cpuInfo;
-
- public int CurrentUtilization => Interop.Sys.GetCpuUtilization(ref _cpuInfo); // Updates cpuInfo as a side effect for the next call
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.CpuUtilizationReader.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.CpuUtilizationReader.Windows.cs
deleted file mode 100644
index d04cd2ada59..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.CpuUtilizationReader.Windows.cs
+++ /dev/null
@@ -1,54 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- internal partial class PortableThreadPool
- {
- private class CpuUtilizationReader
- {
- private struct ProcessCpuInformation
- {
- public long idleTime;
- public long kernelTime;
- public long userTime;
- }
-
- private ProcessCpuInformation _processCpuInfo = new ProcessCpuInformation();
-
- public int CurrentUtilization
- {
- get
- {
- if (!Interop.Kernel32.GetSystemTimes(out var idleTime, out var kernelTime, out var userTime))
- {
- int error = Marshal.GetLastWin32Error();
- var exception = new OutOfMemoryException();
- exception.HResult = error;
- throw exception;
- }
-
- long cpuTotalTime = ((long)userTime - _processCpuInfo.userTime) + ((long)kernelTime - _processCpuInfo.kernelTime);
- long cpuBusyTime = cpuTotalTime - ((long)idleTime - _processCpuInfo.idleTime);
-
- _processCpuInfo.kernelTime = (long)kernelTime;
- _processCpuInfo.userTime = (long)userTime;
- _processCpuInfo.idleTime = (long)idleTime;
-
- if (cpuTotalTime > 0 && cpuBusyTime > 0)
- {
- long reading = cpuBusyTime * 100 / cpuTotalTime;
- reading = Math.Min(reading, 100);
- Debug.Assert(0 <= reading);
- return (int)reading;
- }
- return 0;
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.GateThread.cs b/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.GateThread.cs
deleted file mode 100644
index b5bbc8201ca..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.GateThread.cs
+++ /dev/null
@@ -1,144 +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 System.Diagnostics;
-
-namespace System.Threading
-{
- internal partial class PortableThreadPool
- {
- private static class GateThread
- {
- private const int GateThreadDelayMs = 500;
- private const int DequeueDelayThresholdMs = GateThreadDelayMs * 2;
- private const int GateThreadRunningMask = 0x4;
-
- private static int s_runningState;
-
- private static AutoResetEvent s_runGateThreadEvent = new AutoResetEvent(true);
-
- private static LowLevelLock s_createdLock = new LowLevelLock();
-
- private static readonly CpuUtilizationReader s_cpu = new CpuUtilizationReader();
- private const int MaxRuns = 2;
-
- // TODO: CoreCLR: Worker Tracking in CoreCLR? (Config name: ThreadPool_EnableWorkerTracking)
- private static void GateThreadStart()
- {
- var initialCpuRead = s_cpu.CurrentUtilization; // The first reading is over a time range other than what we are focusing on, so we do not use the read.
-
- AppContext.TryGetSwitch("System.Threading.ThreadPool.DisableStarvationDetection", out bool disableStarvationDetection);
- AppContext.TryGetSwitch("System.Threading.ThreadPool.DebugBreakOnWorkerStarvation", out bool debuggerBreakOnWorkStarvation);
-
- while (true)
- {
- s_runGateThreadEvent.WaitOne();
- do
- {
- Thread.Sleep(GateThreadDelayMs);
-
- ThreadPoolInstance._cpuUtilization = s_cpu.CurrentUtilization;
-
- if (!disableStarvationDetection)
- {
- if (ThreadPoolInstance._numRequestedWorkers > 0 && SufficientDelaySinceLastDequeue())
- {
- try
- {
- ThreadPoolInstance._hillClimbingThreadAdjustmentLock.Acquire();
- ThreadCounts counts = ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts);
- // don't add a thread if we're at max or if we are already in the process of adding threads
- while (counts.numExistingThreads < ThreadPoolInstance._maxThreads && counts.numExistingThreads >= counts.numThreadsGoal)
- {
- if (debuggerBreakOnWorkStarvation)
- {
- Debugger.Break();
- }
-
- ThreadCounts newCounts = counts;
- newCounts.numThreadsGoal = (short)(newCounts.numExistingThreads + 1);
- ThreadCounts oldCounts = ThreadCounts.CompareExchangeCounts(ref ThreadPoolInstance._separated.counts, newCounts, counts);
- if (oldCounts == counts)
- {
- HillClimbing.ThreadPoolHillClimber.ForceChange(newCounts.numThreadsGoal, HillClimbing.StateOrTransition.Starvation);
- WorkerThread.MaybeAddWorkingWorker();
- break;
- }
- counts = oldCounts;
- }
- }
- finally
- {
- ThreadPoolInstance._hillClimbingThreadAdjustmentLock.Release();
- }
- }
- }
- } while (ThreadPoolInstance._numRequestedWorkers > 0 || Interlocked.Decrement(ref s_runningState) > GetRunningStateForNumRuns(0));
- }
- }
-
- // called by logic to spawn new worker threads, return true if it's been too long
- // since the last dequeue operation - takes number of worker threads into account
- // in deciding "too long"
- private static bool SufficientDelaySinceLastDequeue()
- {
- int delay = Environment.TickCount - Volatile.Read(ref ThreadPoolInstance._separated.lastDequeueTime);
-
- int minimumDelay;
-
- if(ThreadPoolInstance._cpuUtilization < CpuUtilizationLow)
- {
- minimumDelay = GateThreadDelayMs;
- }
- else
- {
- ThreadCounts counts = ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts);
- int numThreads = counts.numThreadsGoal;
- minimumDelay = numThreads * DequeueDelayThresholdMs;
- }
- return delay > minimumDelay;
- }
-
- // This is called by a worker thread
- internal static void EnsureRunning()
- {
- int numRunsMask = Interlocked.Exchange(ref s_runningState, GetRunningStateForNumRuns(MaxRuns));
- if ((numRunsMask & GateThreadRunningMask) == 0)
- {
- bool created = false;
- try
- {
- CreateGateThread();
- created = true;
- }
- finally
- {
- if (!created)
- {
- Interlocked.Exchange(ref s_runningState, 0);
- }
- }
- }
- else if (numRunsMask == GetRunningStateForNumRuns(0))
- {
- s_runGateThreadEvent.Set();
- }
- }
-
- private static int GetRunningStateForNumRuns(int numRuns)
- {
- Debug.Assert(numRuns >= 0);
- Debug.Assert(numRuns <= MaxRuns);
- return GateThreadRunningMask | numRuns;
- }
-
- private static void CreateGateThread()
- {
- Thread gateThread = new Thread(GateThreadStart);
- gateThread.IsBackground = true;
- gateThread.Start();
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.HillClimbing.Complex.cs b/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.HillClimbing.Complex.cs
deleted file mode 100644
index 7093ba3ad93..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.HillClimbing.Complex.cs
+++ /dev/null
@@ -1,40 +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.
-
-namespace System.Threading
-{
- internal partial class PortableThreadPool
- {
- private partial class HillClimbing
- {
- private struct Complex
- {
- public Complex(double real, double imaginary)
- {
- Real = real;
- Imaginary = imaginary;
- }
-
- public double Imaginary { get; }
- public double Real { get; }
-
- public static Complex operator*(double scalar, Complex complex) => new Complex(scalar * complex.Real, scalar * complex.Imaginary);
-
- public static Complex operator*(Complex complex, double scalar) => scalar * complex;
-
- public static Complex operator/(Complex complex, double scalar) => new Complex(complex.Real / scalar, complex.Imaginary / scalar);
-
- public static Complex operator-(Complex lhs, Complex rhs) => new Complex(lhs.Real - rhs.Real, lhs.Imaginary - rhs.Imaginary);
-
- public static Complex operator/(Complex lhs, Complex rhs)
- {
- double denom = rhs.Real * rhs.Real + rhs.Imaginary * rhs.Imaginary;
- return new Complex((lhs.Real * rhs.Real + lhs.Imaginary * rhs.Imaginary) / denom, (-lhs.Real * rhs.Imaginary + lhs.Imaginary * rhs.Real) / denom);
- }
-
- public double Abs() => Math.Sqrt(Real * Real + Imaginary * Imaginary);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.HillClimbing.cs b/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.HillClimbing.cs
deleted file mode 100644
index 24cdf5f5884..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.HillClimbing.cs
+++ /dev/null
@@ -1,455 +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 System.Diagnostics;
-using System.Globalization;
-
-namespace System.Threading
-{
- internal partial class PortableThreadPool
- {
- /// <summary>
- /// Hill climbing algorithm used for determining the number of threads needed for the thread pool.
- /// </summary>
- private partial class HillClimbing
- {
- private static readonly Lazy<HillClimbing> s_threadPoolHillClimber = new Lazy<HillClimbing>(CreateHillClimber, true);
- public static HillClimbing ThreadPoolHillClimber => s_threadPoolHillClimber.Value;
-
- private const int DefaultSampleIntervalMsLow = 10;
- private const int DefaultSampleIntervalMsHigh = 200;
-
- private static HillClimbing CreateHillClimber()
- {
- // Default values pulled from CoreCLR
- return new HillClimbing(wavePeriod: AppContextConfigHelper.GetInt32Config("HillClimbing_WavePeriod", 4, false),
- maxWaveMagnitude: AppContextConfigHelper.GetInt32Config("HillClimbing_MaxWaveMagnitude", 20, false),
- waveMagnitudeMultiplier: AppContextConfigHelper.GetInt32Config("HillClimbing_WaveMagnitudeMultiplier", 100, false) / 100.0,
- waveHistorySize: AppContextConfigHelper.GetInt32Config("HillClimbing_WaveHistorySize", 8, false),
- targetThroughputRatio: AppContextConfigHelper.GetInt32Config("HillClimbing_Bias", 15, false) / 100.0,
- targetSignalToNoiseRatio: AppContextConfigHelper.GetInt32Config("HillClimbing_TargetSignalToNoiseRatio", 300, false) / 100.0,
- maxChangePerSecond: AppContextConfigHelper.GetInt32Config("HillClimbing_MaxChangePerSecond", 4, false),
- maxChangePerSample: AppContextConfigHelper.GetInt32Config("HillClimbing_MaxChangePerSample", 20, false),
- sampleIntervalMsLow: AppContextConfigHelper.GetInt32Config("HillClimbing_SampleIntervalLow", DefaultSampleIntervalMsLow, false),
- sampleIntervalMsHigh: AppContextConfigHelper.GetInt32Config("HillClimbing_SampleIntervalHigh", DefaultSampleIntervalMsHigh, false),
- errorSmoothingFactor: AppContextConfigHelper.GetInt32Config("HillClimbing_ErrorSmoothingFactor", 1, false) / 100.0,
- gainExponent: AppContextConfigHelper.GetInt32Config("HillClimbing_GainExponent", 200, false) / 100.0,
- maxSampleError: AppContextConfigHelper.GetInt32Config("HillClimbing_MaxSampleErrorPercent", 15, false) / 100.0
- );
- }
- private const int LogCapacity = 200;
-
- public enum StateOrTransition
- {
- Warmup,
- Initializing,
- RandomMove,
- ClimbingMove,
- ChangePoint,
- Stabilizing,
- Starvation, // Used as a message from the thread pool for a forced transition
- ThreadTimedOut, // Usage as a message from the thread pool for a forced transition
- }
-
- private struct LogEntry
- {
- public int tickCount;
- public StateOrTransition stateOrTransition;
- public int newControlSetting;
- public int lastHistoryCount;
- public double lastHistoryMean;
- }
-
- private readonly int _wavePeriod;
- private readonly int _samplesToMeasure;
- private readonly double _targetThroughputRatio;
- private readonly double _targetSignalToNoiseRatio;
- private readonly double _maxChangePerSecond;
- private readonly double _maxChangePerSample;
- private readonly int _maxThreadWaveMagnitude;
- private readonly int _sampleIntervalMsLow;
- private readonly double _threadMagnitudeMultiplier;
- private readonly int _sampleIntervalMsHigh;
- private readonly double _throughputErrorSmoothingFactor;
- private readonly double _gainExponent;
- private readonly double _maxSampleError;
-
- private double _currentControlSetting;
- private long _totalSamples;
- private int _lastThreadCount;
- private double _averageThroughputNoise;
- private double _secondsElapsedSinceLastChange;
- private double _completionsSinceLastChange;
- private int _accumulatedCompletionCount;
- private double _accumulatedSampleDurationSeconds;
- private double[] _samples;
- private double[] _threadCounts;
- private int _currentSampleMs;
-
- private Random _randomIntervalGenerator = new Random();
-
- private LogEntry[] _log = new LogEntry[LogCapacity];
- private int _logStart = 0;
- private int _logSize = 0;
-
- public HillClimbing(int wavePeriod, int maxWaveMagnitude, double waveMagnitudeMultiplier, int waveHistorySize, double targetThroughputRatio,
- double targetSignalToNoiseRatio, double maxChangePerSecond, double maxChangePerSample, int sampleIntervalMsLow, int sampleIntervalMsHigh,
- double errorSmoothingFactor, double gainExponent, double maxSampleError)
- {
- _wavePeriod = wavePeriod;
- _maxThreadWaveMagnitude = maxWaveMagnitude;
- _threadMagnitudeMultiplier = waveMagnitudeMultiplier;
- _samplesToMeasure = wavePeriod * waveHistorySize;
- _targetThroughputRatio = targetThroughputRatio;
- _targetSignalToNoiseRatio = targetSignalToNoiseRatio;
- _maxChangePerSecond = maxChangePerSecond;
- _maxChangePerSample = maxChangePerSample;
- if (sampleIntervalMsLow <= sampleIntervalMsHigh)
- {
- _sampleIntervalMsLow = sampleIntervalMsLow;
- _sampleIntervalMsHigh = sampleIntervalMsHigh;
- }
- else
- {
- _sampleIntervalMsLow = DefaultSampleIntervalMsLow;
- _sampleIntervalMsHigh = DefaultSampleIntervalMsHigh;
- }
- _throughputErrorSmoothingFactor = errorSmoothingFactor;
- _gainExponent = gainExponent;
- _maxSampleError = maxSampleError;
-
- _samples = new double[_samplesToMeasure];
- _threadCounts = new double[_samplesToMeasure];
-
- _currentSampleMs = _randomIntervalGenerator.Next(_sampleIntervalMsLow, _sampleIntervalMsHigh + 1);
- }
-
- public (int newThreadCount, int newSampleMs) Update(int currentThreadCount, double sampleDurationSeconds, int numCompletions)
- {
-
- //
- // If someone changed the thread count without telling us, update our records accordingly.
- //
- if (currentThreadCount != _lastThreadCount)
- ForceChange(currentThreadCount, StateOrTransition.Initializing);
-
- //
- // Update the cumulative stats for this thread count
- //
- _secondsElapsedSinceLastChange += sampleDurationSeconds;
- _completionsSinceLastChange += numCompletions;
-
- //
- // Add in any data we've already collected about this sample
- //
- sampleDurationSeconds += _accumulatedSampleDurationSeconds;
- numCompletions += _accumulatedCompletionCount;
-
- //
- // We need to make sure we're collecting reasonably accurate data. Since we're just counting the end
- // of each work item, we are goinng to be missing some data about what really happened during the
- // sample interval. The count produced by each thread includes an initial work item that may have
- // started well before the start of the interval, and each thread may have been running some new
- // work item for some time before the end of the interval, which did not yet get counted. So
- // our count is going to be off by +/- threadCount workitems.
- //
- // The exception is that the thread that reported to us last time definitely wasn't running any work
- // at that time, and the thread that's reporting now definitely isn't running a work item now. So
- // we really only need to consider threadCount-1 threads.
- //
- // Thus the percent error in our count is +/- (threadCount-1)/numCompletions.
- //
- // We cannot rely on the frequency-domain analysis we'll be doing later to filter out this error, because
- // of the way it accumulates over time. If this sample is off by, say, 33% in the negative direction,
- // then the next one likely will be too. The one after that will include the sum of the completions
- // we missed in the previous samples, and so will be 33% positive. So every three samples we'll have
- // two "low" samples and one "high" sample. This will appear as periodic variation right in the frequency
- // range we're targeting, which will not be filtered by the frequency-domain translation.
- //
- if (_totalSamples > 0 && ((currentThreadCount - 1.0) / numCompletions) >= _maxSampleError)
- {
- // not accurate enough yet. Let's accumulate the data so far, and tell the ThreadPool
- // to collect a little more.
- _accumulatedSampleDurationSeconds = sampleDurationSeconds;
- _accumulatedCompletionCount = numCompletions;
- return (currentThreadCount, 10);
- }
-
- //
- // We've got enouugh data for our sample; reset our accumulators for next time.
- //
- _accumulatedSampleDurationSeconds = 0;
- _accumulatedCompletionCount = 0;
-
- //
- // Add the current thread count and throughput sample to our history
- //
- double throughput = numCompletions / sampleDurationSeconds;
-
- PortableThreadPoolEventSource.Log.WorkerThreadAdjustmentSample(throughput);
-
- int sampleIndex = (int)(_totalSamples % _samplesToMeasure);
- _samples[sampleIndex] = throughput;
- _threadCounts[sampleIndex] = currentThreadCount;
- _totalSamples++;
-
- //
- // Set up defaults for our metrics
- //
- Complex threadWaveComponent = default(Complex);
- Complex throughputWaveComponent = default(Complex);
- double throughputErrorEstimate = 0;
- Complex ratio = default(Complex);
- double confidence = 0;
-
- StateOrTransition state = StateOrTransition.Warmup;
-
- //
- // How many samples will we use? It must be at least the three wave periods we're looking for, and it must also be a whole
- // multiple of the primary wave's period; otherwise the frequency we're looking for will fall between two frequency bands
- // in the Fourier analysis, and we won't be able to measure it accurately.
- //
- int sampleCount = ((int)Math.Min(_totalSamples - 1, _samplesToMeasure)) / _wavePeriod * _wavePeriod;
-
- if (sampleCount > _wavePeriod)
- {
- //
- // Average the throughput and thread count samples, so we can scale the wave magnitudes later.
- //
- double sampleSum = 0;
- double threadSum = 0;
- for (int i = 0; i < sampleCount; i++)
- {
- sampleSum += _samples[(_totalSamples - sampleCount + i) % _samplesToMeasure];
- threadSum += _threadCounts[(_totalSamples - sampleCount + i) % _samplesToMeasure];
- }
- double averageThroughput = sampleSum / sampleCount;
- double averageThreadCount = threadSum / sampleCount;
-
- if (averageThroughput > 0 && averageThreadCount > 0)
- {
- //
- // Calculate the periods of the adjacent frequency bands we'll be using to measure noise levels.
- // We want the two adjacent Fourier frequency bands.
- //
- double adjacentPeriod1 = sampleCount / (((double)sampleCount / _wavePeriod) + 1);
- double adjacentPeriod2 = sampleCount / (((double)sampleCount / _wavePeriod) - 1);
-
- //
- // Get the the three different frequency components of the throughput (scaled by average
- // throughput). Our "error" estimate (the amount of noise that might be present in the
- // frequency band we're really interested in) is the average of the adjacent bands.
- //
- throughputWaveComponent = GetWaveComponent(_samples, sampleCount, _wavePeriod) / averageThroughput;
- throughputErrorEstimate = (GetWaveComponent(_samples, sampleCount, adjacentPeriod1) / averageThroughput).Abs();
- if (adjacentPeriod2 <= sampleCount)
- {
- throughputErrorEstimate = Math.Max(throughputErrorEstimate, (GetWaveComponent(_samples, sampleCount, adjacentPeriod2) / averageThroughput).Abs());
- }
-
- //
- // Do the same for the thread counts, so we have something to compare to. We don't measure thread count
- // noise, because there is none; these are exact measurements.
- //
- threadWaveComponent = GetWaveComponent(_threadCounts, sampleCount, _wavePeriod) / averageThreadCount;
-
- //
- // Update our moving average of the throughput noise. We'll use this later as feedback to
- // determine the new size of the thread wave.
- //
- if (_averageThroughputNoise == 0)
- _averageThroughputNoise = throughputErrorEstimate;
- else
- _averageThroughputNoise = (_throughputErrorSmoothingFactor * throughputErrorEstimate) + ((1.0 - _throughputErrorSmoothingFactor) * _averageThroughputNoise);
-
- if (threadWaveComponent.Abs() > 0)
- {
- //
- // Adjust the throughput wave so it's centered around the target wave, and then calculate the adjusted throughput/thread ratio.
- //
- ratio = (throughputWaveComponent - (_targetThroughputRatio * threadWaveComponent)) / threadWaveComponent;
- state = StateOrTransition.ClimbingMove;
- }
- else
- {
- ratio = new Complex(0, 0);
- state = StateOrTransition.Stabilizing;
- }
-
- //
- // Calculate how confident we are in the ratio. More noise == less confident. This has
- // the effect of slowing down movements that might be affected by random noise.
- //
- double noiseForConfidence = Math.Max(_averageThroughputNoise, throughputErrorEstimate);
- if (noiseForConfidence > 0)
- confidence = (threadWaveComponent.Abs() / noiseForConfidence) / _targetSignalToNoiseRatio;
- else
- confidence = 1.0; //there is no noise!
-
- }
- }
-
- //
- // We use just the real part of the complex ratio we just calculated. If the throughput signal
- // is exactly in phase with the thread signal, this will be the same as taking the magnitude of
- // the complex move and moving that far up. If they're 180 degrees out of phase, we'll move
- // backward (because this indicates that our changes are having the opposite of the intended effect).
- // If they're 90 degrees out of phase, we won't move at all, because we can't tell wether we're
- // having a negative or positive effect on throughput.
- //
- double move = Math.Min(1.0, Math.Max(-1.0, ratio.Real));
-
- //
- // Apply our confidence multiplier.
- //
- move *= Math.Min(1.0, Math.Max(0.0, confidence));
-
- //
- // Now apply non-linear gain, such that values around zero are attenuated, while higher values
- // are enhanced. This allows us to move quickly if we're far away from the target, but more slowly
- // if we're getting close, giving us rapid ramp-up without wild oscillations around the target.
- //
- double gain = _maxChangePerSecond * sampleDurationSeconds;
- move = Math.Pow(Math.Abs(move), _gainExponent) * (move >= 0.0 ? 1 : -1) * gain;
- move = Math.Min(move, _maxChangePerSample);
-
- //
- // If the result was positive, and CPU is > 95%, refuse the move.
- //
- if (move > 0.0 && ThreadPoolInstance._cpuUtilization > CpuUtilizationHigh)
- move = 0.0;
-
- //
- // Apply the move to our control setting
- //
- _currentControlSetting += move;
-
- //
- // Calculate the new thread wave magnitude, which is based on the moving average we've been keeping of
- // the throughput error. This average starts at zero, so we'll start with a nice safe little wave at first.
- //
- int newThreadWaveMagnitude = (int)(0.5 + (_currentControlSetting * _averageThroughputNoise * _targetSignalToNoiseRatio * _threadMagnitudeMultiplier * 2.0));
- newThreadWaveMagnitude = Math.Min(newThreadWaveMagnitude, _maxThreadWaveMagnitude);
- newThreadWaveMagnitude = Math.Max(newThreadWaveMagnitude, 1);
-
- //
- // Make sure our control setting is within the ThreadPool's limits
- //
- int maxThreads = ThreadPoolInstance._maxThreads;
- int minThreads = ThreadPoolInstance._minThreads;
-
- _currentControlSetting = Math.Min(maxThreads - newThreadWaveMagnitude, _currentControlSetting);
- _currentControlSetting = Math.Max(minThreads, _currentControlSetting);
-
- //
- // Calculate the new thread count (control setting + square wave)
- //
- int newThreadCount = (int)(_currentControlSetting + newThreadWaveMagnitude * ((_totalSamples / (_wavePeriod / 2)) % 2));
-
- //
- // Make sure the new thread count doesn't exceed the ThreadPool's limits
- //
- newThreadCount = Math.Min(maxThreads, newThreadCount);
- newThreadCount = Math.Max(minThreads, newThreadCount);
-
- //
- // Record these numbers for posterity
- //
-
- PortableThreadPoolEventSource.Log.WorkerThreadAdjustmentStats(sampleDurationSeconds, throughput, threadWaveComponent.Real, throughputWaveComponent.Real,
- throughputErrorEstimate, _averageThroughputNoise, ratio.Real, confidence, _currentControlSetting, (ushort)newThreadWaveMagnitude);
-
-
- //
- // If all of this caused an actual change in thread count, log that as well.
- //
- if (newThreadCount != currentThreadCount)
- ChangeThreadCount(newThreadCount, state);
-
- //
- // Return the new thread count and sample interval. This is randomized to prevent correlations with other periodic
- // changes in throughput. Among other things, this prevents us from getting confused by Hill Climbing instances
- // running in other processes.
- //
- // If we're at minThreads, and we seem to be hurting performance by going higher, we can't go any lower to fix this. So
- // we'll simply stay at minThreads much longer, and only occasionally try a higher value.
- //
- int newSampleInterval;
- if (ratio.Real < 0.0 && newThreadCount == minThreads)
- newSampleInterval = (int)(0.5 + _currentSampleMs * (10.0 * Math.Max(-ratio.Real, 1.0)));
- else
- newSampleInterval = _currentSampleMs;
-
- return (newThreadCount, newSampleInterval);
- }
-
- private void ChangeThreadCount(int newThreadCount, StateOrTransition state)
- {
- _lastThreadCount = newThreadCount;
- _currentSampleMs = _randomIntervalGenerator.Next(_sampleIntervalMsLow, _sampleIntervalMsHigh + 1);
- double throughput = _secondsElapsedSinceLastChange > 0 ? _completionsSinceLastChange / _secondsElapsedSinceLastChange : 0;
- LogTransition(newThreadCount, throughput, state);
- _secondsElapsedSinceLastChange = 0;
- _completionsSinceLastChange = 0;
- }
-
- private void LogTransition(int newThreadCount, double throughput, StateOrTransition stateOrTransition)
- {
- // Use the _log array as a circular array for log entries
- int index = (_logStart + _logSize) % LogCapacity;
-
- if(_logSize == LogCapacity)
- {
- _logStart = (_logStart + 1) % LogCapacity;
- _logSize--; // hide this slot while we update it
- }
-
- ref LogEntry entry = ref _log[index];
-
- entry.tickCount = Environment.TickCount;
- entry.stateOrTransition = stateOrTransition;
- entry.newControlSetting = newThreadCount;
- entry.lastHistoryCount = ((int)Math.Min(_totalSamples, _samplesToMeasure) / _wavePeriod) * _wavePeriod;
- entry.lastHistoryMean = throughput;
-
- _logSize++;
-
- PortableThreadPoolEventSource.Log.WorkerThreadAdjustmentAdjustment(throughput, newThreadCount, (int)stateOrTransition);
- }
-
- public void ForceChange(int newThreadCount, StateOrTransition state)
- {
- if(_lastThreadCount != newThreadCount)
- {
- _currentControlSetting += newThreadCount - _lastThreadCount;
- ChangeThreadCount(newThreadCount, state);
- }
- }
-
- private Complex GetWaveComponent(double[] samples, int numSamples, double period)
- {
- Debug.Assert(numSamples >= period); // can't measure a wave that doesn't fit
- Debug.Assert(period >= 2); // can't measure above the Nyquist frequency
- Debug.Assert(numSamples <= samples.Length); // can't measure more samples than we have
-
- //
- // Calculate the sinusoid with the given period.
- // We're using the Goertzel algorithm for this. See http://en.wikipedia.org/wiki/Goertzel_algorithm.
- //
-
- double w = 2 * Math.PI / period;
- double cos = Math.Cos(w);
- double coeff = 2 * cos;
- double q0 = 0, q1 = 0, q2 = 0;
- for(int i = 0; i < numSamples; ++i)
- {
- q0 = coeff * q1 - q2 + samples[(_totalSamples - numSamples + i) % _samplesToMeasure];
- q2 = q1;
- q1 = q0;
- }
- return new Complex(q1 - q2 * cos, q2 * Math.Sin(w)) / numSamples;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.ThreadCounts.cs b/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.ThreadCounts.cs
deleted file mode 100644
index 3fc6cf9fd96..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.ThreadCounts.cs
+++ /dev/null
@@ -1,85 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- internal partial class PortableThreadPool
- {
- /// <summary>
- /// Tracks information on the number of threads we want/have in different states in our thread pool.
- /// </summary>
- [StructLayout(LayoutKind.Explicit)]
- struct ThreadCounts
- {
- /// <summary>
- /// Max possible thread pool threads we want to have.
- /// </summary>
- [FieldOffset(0)]
- public short numThreadsGoal;
-
- /// <summary>
- /// Number of thread pool threads that currently exist.
- /// </summary>
- [FieldOffset(2)]
- public short numExistingThreads;
-
- /// <summary>
- /// Number of threads processing work items.
- /// </summary>
- [FieldOffset(4)]
- public short numProcessingWork;
-
- [FieldOffset(0)]
- private long _asLong;
-
- public static ThreadCounts VolatileReadCounts(ref ThreadCounts counts)
- {
- return new ThreadCounts
- {
- _asLong = Volatile.Read(ref counts._asLong)
- };
- }
-
- public static ThreadCounts CompareExchangeCounts(ref ThreadCounts location, ThreadCounts newCounts, ThreadCounts oldCounts)
- {
- ThreadCounts result = new ThreadCounts
- {
- _asLong = Interlocked.CompareExchange(ref location._asLong, newCounts._asLong, oldCounts._asLong)
- };
-
- if (result == oldCounts)
- {
- result.Validate();
- newCounts.Validate();
- }
- return result;
- }
-
- public static bool operator ==(ThreadCounts lhs, ThreadCounts rhs) => lhs._asLong == rhs._asLong;
-
- public static bool operator !=(ThreadCounts lhs, ThreadCounts rhs) => lhs._asLong != rhs._asLong;
-
- public override bool Equals(object? obj)
- {
- return obj is ThreadCounts counts && this._asLong == counts._asLong;
- }
-
- public override int GetHashCode()
- {
- return (int)(_asLong >> 8) + numThreadsGoal;
- }
-
- private void Validate()
- {
- Debug.Assert(numThreadsGoal > 0, "Goal must be positive");
- Debug.Assert(numExistingThreads >= 0, "Number of existing threads must be non-zero");
- Debug.Assert(numProcessingWork >= 0, "Number of threads processing work must be non-zero");
- Debug.Assert(numProcessingWork <= numExistingThreads, $"Num processing work ({numProcessingWork}) must be less than or equal to Num existing threads ({numExistingThreads})");
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.WaitThread.cs b/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.WaitThread.cs
deleted file mode 100644
index d34576bcde2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.WaitThread.cs
+++ /dev/null
@@ -1,421 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- internal partial class PortableThreadPool
- {
- /// <summary>
- /// A linked list of <see cref="WaitThread"/>s.
- /// </summary>
- private WaitThreadNode _waitThreadsHead;
- private WaitThreadNode _waitThreadsTail;
-
- private LowLevelLock _waitThreadLock = new LowLevelLock();
-
- /// <summary>
- /// Register a wait handle on a <see cref="WaitThread"/>.
- /// </summary>
- /// <param name="handle">A description of the requested registration.</param>
- internal void RegisterWaitHandle(RegisteredWaitHandle handle)
- {
- _waitThreadLock.Acquire();
- try
- {
- if (_waitThreadsHead == null) // Lazily create the first wait thread.
- {
- _waitThreadsTail = _waitThreadsHead = new WaitThreadNode
- {
- Thread = new WaitThread()
- };
- }
-
- // Register the wait handle on the first wait thread that is not at capacity.
- WaitThreadNode prev;
- WaitThreadNode current = _waitThreadsHead;
- do
- {
- if (current.Thread.RegisterWaitHandle(handle))
- {
- return;
- }
- prev = current;
- current = current.Next;
- } while (current != null);
-
- // If all wait threads are full, create a new one.
- prev.Next = _waitThreadsTail = new WaitThreadNode
- {
- Thread = new WaitThread()
- };
- prev.Next.Thread.RegisterWaitHandle(handle);
- return;
- }
- finally
- {
- _waitThreadLock.Release();
- }
- }
-
- /// <summary>
- /// Attempt to remove the given wait thread from the list. It is only removed if there are no user-provided waits on the thread.
- /// </summary>
- /// <param name="thread">The thread to remove.</param>
- /// <returns><c>true</c> if the thread was successfully removed; otherwise, <c>false</c></returns>
- private bool TryRemoveWaitThread(WaitThread thread)
- {
- _waitThreadLock.Acquire();
- try
- {
- if (thread.AnyUserWaits)
- {
- return false;
- }
- RemoveWaitThread(thread);
- }
- finally
- {
- _waitThreadLock.Release();
- }
- return true;
- }
-
- /// <summary>
- /// Removes the wait thread from the list.
- /// </summary>
- /// <param name="thread">The wait thread to remove from the list.</param>
- private void RemoveWaitThread(WaitThread thread)
- {
- if (_waitThreadsHead.Thread == thread)
- {
- _waitThreadsHead = _waitThreadsHead.Next;
- return;
- }
-
- WaitThreadNode prev;
- WaitThreadNode current = _waitThreadsHead;
-
- do
- {
- prev = current;
- current = current.Next;
- } while (current != null && current.Thread != thread);
-
- Debug.Assert(current != null, "The wait thread to remove was not found in the list of thread pool wait threads.");
-
- if (current != null)
- {
- prev.Next = current.Next;
- }
- }
-
- private class WaitThreadNode
- {
- public WaitThread Thread { get; set; }
- public WaitThreadNode Next { get; set; }
- }
-
- /// <summary>
- /// A thread pool wait thread.
- /// </summary>
- internal class WaitThread
- {
- /// <summary>
- /// The info for a completed wait on a specific <see cref="RegisteredWaitHandle"/>.
- /// </summary>
- private struct CompletedWaitHandle
- {
- public CompletedWaitHandle(RegisteredWaitHandle completedHandle, bool timedOut)
- {
- CompletedHandle = completedHandle;
- TimedOut = timedOut;
- }
-
- public RegisteredWaitHandle CompletedHandle { get; }
- public bool TimedOut { get; }
- }
-
- /// <summary>
- /// The wait handles registered on this wait thread.
- /// </summary>
- private readonly RegisteredWaitHandle[] _registeredWaits = new RegisteredWaitHandle[WaitHandle.MaxWaitHandles - 1];
- /// <summary>
- /// The raw wait handles to wait on.
- /// </summary>
- /// <remarks>
- /// The zeroth element of this array is always <see cref="_changeHandlesEvent"/>.
- /// </remarks>
- private readonly WaitHandle[] _waitHandles = new WaitHandle[WaitHandle.MaxWaitHandles];
- /// <summary>
- /// The number of user-registered waits on this wait thread.
- /// </summary>
- private int _numUserWaits = 0;
-
- /// <summary>
- /// A list of removals of wait handles that are waiting for the wait thread to process.
- /// </summary>
- private readonly RegisteredWaitHandle[] _pendingRemoves = new RegisteredWaitHandle[WaitHandle.MaxWaitHandles - 1];
- /// <summary>
- /// The number of pending removals.
- /// </summary>
- private int _numPendingRemoves = 0;
-
- /// <summary>
- /// An event to notify the wait thread that there are pending adds or removals of wait handles so it needs to wake up.
- /// </summary>
- private readonly AutoResetEvent _changeHandlesEvent = new AutoResetEvent(false);
-
- internal bool AnyUserWaits => _numUserWaits != 0;
-
- public WaitThread()
- {
- _waitHandles[0] = _changeHandlesEvent;
- Thread waitThread = new Thread(WaitThreadStart);
- waitThread.IsBackground = true;
- waitThread.Start();
- }
-
- /// <summary>
- /// The main routine for the wait thread.
- /// </summary>
- private void WaitThreadStart()
- {
- while (true)
- {
- ProcessRemovals();
- int numUserWaits = _numUserWaits;
- int preWaitTimeMs = Environment.TickCount;
-
- // Recalculate Timeout
- int timeoutDurationMs = Timeout.Infinite;
- if (numUserWaits == 0)
- {
- timeoutDurationMs = ThreadPoolThreadTimeoutMs;
- }
- else
- {
- for (int i = 0; i < numUserWaits; i++)
- {
- if (_registeredWaits[i].IsInfiniteTimeout)
- {
- continue;
- }
-
- int handleTimeoutDurationMs = _registeredWaits[i].TimeoutTimeMs - preWaitTimeMs;
-
- if (timeoutDurationMs == Timeout.Infinite)
- {
- timeoutDurationMs = handleTimeoutDurationMs > 0 ? handleTimeoutDurationMs : 0;
- }
- else
- {
- timeoutDurationMs = Math.Min(handleTimeoutDurationMs > 0 ? handleTimeoutDurationMs : 0, timeoutDurationMs);
- }
-
- if (timeoutDurationMs == 0)
- {
- break;
- }
- }
- }
-
- int signaledHandleIndex = WaitHandle.WaitAny(new ReadOnlySpan<WaitHandle>(_waitHandles, 0, numUserWaits + 1), timeoutDurationMs);
-
- if (signaledHandleIndex == 0) // If we were woken up for a change in our handles, continue.
- {
- continue;
- }
-
- RegisteredWaitHandle signaledHandle = signaledHandleIndex != WaitHandle.WaitTimeout ? _registeredWaits[signaledHandleIndex - 1] : null;
-
- if (signaledHandle != null)
- {
- QueueWaitCompletion(signaledHandle, false);
- }
- else
- {
- if(numUserWaits == 0)
- {
- if (ThreadPoolInstance.TryRemoveWaitThread(this))
- {
- return;
- }
- }
-
- int elapsedDurationMs = Environment.TickCount - preWaitTimeMs; // Calculate using relative time to ensure we don't have issues with overflow wraparound
- for (int i = 0; i < numUserWaits; i++)
- {
- RegisteredWaitHandle registeredHandle = _registeredWaits[i];
- int handleTimeoutDurationMs = registeredHandle.TimeoutTimeMs - preWaitTimeMs;
- if (elapsedDurationMs >= handleTimeoutDurationMs)
- {
- QueueWaitCompletion(registeredHandle, true);
- }
- }
- }
- }
- }
-
- /// <summary>
- /// Go through the <see cref="_pendingRemoves"/> array and remove those registered wait handles from the <see cref="_registeredWaits"/>
- /// and <see cref="_waitHandles"/> arrays, filling the holes along the way.
- /// </summary>
- private void ProcessRemovals()
- {
- ThreadPoolInstance._waitThreadLock.Acquire();
- try
- {
- Debug.Assert(_numPendingRemoves >= 0);
- Debug.Assert(_numPendingRemoves <= _pendingRemoves.Length);
- Debug.Assert(_numUserWaits >= 0);
- Debug.Assert(_numUserWaits <= _registeredWaits.Length);
- Debug.Assert(_numPendingRemoves <= _numUserWaits, $"Num removals {_numPendingRemoves} should be less than or equal to num user waits {_numUserWaits}");
-
- if (_numPendingRemoves == 0 || _numUserWaits == 0)
- {
- return;
- }
- int originalNumUserWaits = _numUserWaits;
- int originalNumPendingRemoves = _numPendingRemoves;
-
- // This is O(N^2), but max(N) = 63 and N will usually be very low
- for (int i = 0; i < _numPendingRemoves; i++)
- {
- for (int j = 0; j < _numUserWaits; j++)
- {
- if (_pendingRemoves[i] == _registeredWaits[j])
- {
- _registeredWaits[j].OnRemoveWait();
- _registeredWaits[j] = _registeredWaits[_numUserWaits - 1];
- _waitHandles[j + 1] = _waitHandles[_numUserWaits];
- _registeredWaits[_numUserWaits - 1] = null;
- _waitHandles[_numUserWaits] = null;
- --_numUserWaits;
- _pendingRemoves[i] = null;
- break;
- }
- }
- Debug.Assert(_pendingRemoves[i] == null);
- }
- _numPendingRemoves = 0;
-
- Debug.Assert(originalNumUserWaits - originalNumPendingRemoves == _numUserWaits,
- $"{originalNumUserWaits} - {originalNumPendingRemoves} == {_numUserWaits}");
- }
- finally
- {
- ThreadPoolInstance._waitThreadLock.Release();
- }
- }
-
- /// <summary>
- /// Queue a call to <see cref="CompleteWait(object)"/> on the ThreadPool.
- /// </summary>
- /// <param name="registeredHandle">The handle that completed.</param>
- /// <param name="timedOut">Whether or not the wait timed out.</param>
- private void QueueWaitCompletion(RegisteredWaitHandle registeredHandle, bool timedOut)
- {
- registeredHandle.RequestCallback();
- // If the handle is a repeating handle, set up the next call. Otherwise, remove it from the wait thread.
- if (registeredHandle.Repeating)
- {
- registeredHandle.RestartTimeout(Environment.TickCount);
- }
- else
- {
- UnregisterWait(registeredHandle, blocking: false); // We shouldn't block the wait thread on the unregistration.
- }
- ThreadPool.QueueUserWorkItem(CompleteWait, new CompletedWaitHandle(registeredHandle, timedOut));
- }
-
- /// <summary>
- /// Process the completion of a user-registered wait (call the callback).
- /// </summary>
- /// <param name="state">A <see cref="CompletedWaitHandle"/> object representing the wait completion.</param>
- private void CompleteWait(object? state)
- {
- CompletedWaitHandle handle = (CompletedWaitHandle)state!;
- handle.CompletedHandle.PerformCallback(handle.TimedOut);
- }
-
- /// <summary>
- /// Register a wait handle on this <see cref="WaitThread"/>.
- /// </summary>
- /// <param name="handle">The handle to register.</param>
- /// <returns>If the handle was successfully registered on this wait thread.</returns>
- public bool RegisterWaitHandle(RegisteredWaitHandle handle)
- {
- ThreadPoolInstance._waitThreadLock.VerifyIsLocked();
- if (_numUserWaits == WaitHandle.MaxWaitHandles - 1)
- {
- return false;
- }
-
- _registeredWaits[_numUserWaits] = handle;
- _waitHandles[_numUserWaits + 1] = handle.Handle;
- _numUserWaits++;
-
- handle.WaitThread = this;
-
- _changeHandlesEvent.Set();
- return true;
- }
-
- /// <summary>
- /// Unregisters a wait handle.
- /// </summary>
- /// <param name="handle">The handle to unregister.</param>
- /// <remarks>
- /// As per CoreCLR's behavior, if the user passes in an invalid <see cref="WaitHandle"/>
- /// into <see cref="RegisteredWaitHandle.Unregister(WaitHandle)"/>, then the unregistration of the wait handle is blocking.
- /// Otherwise, the unregistration of the wait handle is queued on the wait thread.
- /// </remarks>
- public void UnregisterWait(RegisteredWaitHandle handle)
- {
- UnregisterWait(handle, true);
- }
-
- /// <summary>
- /// Unregister a wait handle.
- /// </summary>
- /// <param name="handle">The wait handle to unregister.</param>
- /// <param name="blocking">Should the unregistration block at all.</param>
- private void UnregisterWait(RegisteredWaitHandle handle, bool blocking)
- {
- bool pendingRemoval = false;
- // TODO: Optimization: Try to unregister wait directly if it isn't being waited on.
- ThreadPoolInstance._waitThreadLock.Acquire();
- try
- {
- // If this handle is not already pending removal and hasn't already been removed
- if (Array.IndexOf(_registeredWaits, handle) != -1 && Array.IndexOf(_pendingRemoves, handle) == -1)
- {
- _pendingRemoves[_numPendingRemoves++] = handle;
- _changeHandlesEvent.Set(); // Tell the wait thread that there are changes pending.
- pendingRemoval = true;
- }
- }
- finally
- {
- ThreadPoolInstance._waitThreadLock.Release();
- }
-
- if (blocking)
- {
- if (handle.IsBlocking)
- {
- handle.WaitForCallbacks();
- }
- else if (pendingRemoval)
- {
- handle.WaitForRemoval();
- }
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.WorkerThread.cs b/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.WorkerThread.cs
deleted file mode 100644
index 5a96fdd6172..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.WorkerThread.cs
+++ /dev/null
@@ -1,259 +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 System.Globalization;
-
-namespace System.Threading
-{
- internal partial class PortableThreadPool
- {
- /// <summary>
- /// The worker thread infastructure for the CLR thread pool.
- /// </summary>
- private static class WorkerThread
- {
- /// <summary>
- /// Semaphore for controlling how many threads are currently working.
- /// </summary>
- private static LowLevelLifoSemaphore s_semaphore = new LowLevelLifoSemaphore(0, MaxPossibleThreadCount, SemaphoreSpinCount);
-
- /// <summary>
- /// Maximum number of spins a thread pool worker thread performs before waiting for work
- /// </summary>
- private static int SemaphoreSpinCount
- {
- get => AppContextConfigHelper.GetInt16Config("ThreadPool_UnfairSemaphoreSpinLimit", 70, false);
- }
-
- private static void WorkerThreadStart()
- {
- PortableThreadPoolEventSource.Log.WorkerThreadStart(ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts).numExistingThreads);
-
- while (true)
- {
- while (WaitForRequest())
- {
- if (TakeActiveRequest())
- {
- Volatile.Write(ref ThreadPoolInstance._separated.lastDequeueTime, Environment.TickCount);
- if (ThreadPoolWorkQueue.Dispatch())
- {
- // If the queue runs out of work for us, we need to update the number of working workers to reflect that we are done working for now
- RemoveWorkingWorker();
- }
- }
- else
- {
- // If we woke up but couldn't find a request, we need to update the number of working workers to reflect that we are done working for now
- RemoveWorkingWorker();
- }
- }
-
- ThreadPoolInstance._hillClimbingThreadAdjustmentLock.Acquire();
- try
- {
- // At this point, the thread's wait timed out. We are shutting down this thread.
- // We are going to decrement the number of exisiting threads to no longer include this one
- // and then change the max number of threads in the thread pool to reflect that we don't need as many
- // as we had. Finally, we are going to tell hill climbing that we changed the max number of threads.
- ThreadCounts counts = ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts);
- while (true)
- {
- if (counts.numExistingThreads == counts.numProcessingWork)
- {
- // In this case, enough work came in that this thread should not time out and should go back to work.
- break;
- }
-
- ThreadCounts newCounts = counts;
- newCounts.numExistingThreads--;
- newCounts.numThreadsGoal = Math.Max(ThreadPoolInstance._minThreads, Math.Min(newCounts.numExistingThreads, newCounts.numThreadsGoal));
- ThreadCounts oldCounts = ThreadCounts.CompareExchangeCounts(ref ThreadPoolInstance._separated.counts, newCounts, counts);
- if (oldCounts == counts)
- {
- HillClimbing.ThreadPoolHillClimber.ForceChange(newCounts.numThreadsGoal, HillClimbing.StateOrTransition.ThreadTimedOut);
- PortableThreadPoolEventSource.Log.WorkerThreadStop(newCounts.numExistingThreads);
- return;
- }
- }
- }
- finally
- {
- ThreadPoolInstance._hillClimbingThreadAdjustmentLock.Release();
- }
- }
- }
-
- /// <summary>
- /// Waits for a request to work.
- /// </summary>
- /// <returns>If this thread was woken up before it timed out.</returns>
- private static bool WaitForRequest()
- {
- PortableThreadPoolEventSource.Log.WorkerThreadWait(ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts).numExistingThreads);
- return s_semaphore.Wait(ThreadPoolThreadTimeoutMs);
- }
-
- /// <summary>
- /// Reduce the number of working workers by one, but maybe add back a worker (possibily this thread) if a thread request comes in while we are marking this thread as not working.
- /// </summary>
- private static void RemoveWorkingWorker()
- {
- ThreadCounts currentCounts = ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts);
- while (true)
- {
- ThreadCounts newCounts = currentCounts;
- newCounts.numProcessingWork--;
- ThreadCounts oldCounts = ThreadCounts.CompareExchangeCounts(ref ThreadPoolInstance._separated.counts, newCounts, currentCounts);
-
- if (oldCounts == currentCounts)
- {
- break;
- }
- currentCounts = oldCounts;
- }
-
- // It's possible that we decided we had thread requests just before a request came in,
- // but reduced the worker count *after* the request came in. In this case, we might
- // miss the notification of a thread request. So we wake up a thread (maybe this one!)
- // if there is work to do.
- if (ThreadPoolInstance._numRequestedWorkers > 0)
- {
- MaybeAddWorkingWorker();
- }
- }
-
- internal static void MaybeAddWorkingWorker()
- {
- ThreadCounts counts = ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts);
- ThreadCounts newCounts;
- while (true)
- {
- newCounts = counts;
- newCounts.numProcessingWork = Math.Max(counts.numProcessingWork, Math.Min((short)(counts.numProcessingWork + 1), counts.numThreadsGoal));
- newCounts.numExistingThreads = Math.Max(counts.numExistingThreads, newCounts.numProcessingWork);
-
- if (newCounts == counts)
- {
- return;
- }
-
- ThreadCounts oldCounts = ThreadCounts.CompareExchangeCounts(ref ThreadPoolInstance._separated.counts, newCounts, counts);
-
- if (oldCounts == counts)
- {
- break;
- }
-
- counts = oldCounts;
- }
-
- int toCreate = newCounts.numExistingThreads - counts.numExistingThreads;
- int toRelease = newCounts.numProcessingWork - counts.numProcessingWork;
-
- if (toRelease > 0)
- {
- s_semaphore.Release(toRelease);
- }
-
- while (toCreate > 0)
- {
- if (TryCreateWorkerThread())
- {
- toCreate--;
- }
- else
- {
- counts = ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts);
- while (true)
- {
- newCounts = counts;
- newCounts.numProcessingWork -= (short)toCreate;
- newCounts.numExistingThreads -= (short)toCreate;
-
- ThreadCounts oldCounts = ThreadCounts.CompareExchangeCounts(ref ThreadPoolInstance._separated.counts, newCounts, counts);
- if(oldCounts == counts)
- {
- break;
- }
- counts = oldCounts;
- }
- toCreate = 0;
- }
- }
- }
-
- /// <summary>
- /// Returns if the current thread should stop processing work on the thread pool.
- /// A thread should stop processing work on the thread pool when work remains only when
- /// there are more worker threads in the thread pool than we currently want.
- /// </summary>
- /// <returns>Whether or not this thread should stop processing work even if there is still work in the queue.</returns>
- internal static bool ShouldStopProcessingWorkNow()
- {
- ThreadCounts counts = ThreadCounts.VolatileReadCounts(ref ThreadPoolInstance._separated.counts);
- while (true)
- {
- // When there are more threads processing work than the thread count goal, hill climbing must have decided
- // to decrease the number of threads. Stop processing if the counts can be updated. We may have more
- // threads existing than the thread count goal and that is ok, the cold ones will eventually time out if
- // the thread count goal is not increased again. This logic is a bit different from the original CoreCLR
- // code from which this implementation was ported, which turns a processing thread into a retired thread
- // and checks for pending requests like RemoveWorkingWorker. In this implementation there are
- // no retired threads, so only the count of threads processing work is considered.
- if (counts.numProcessingWork <= counts.numThreadsGoal)
- {
- return false;
- }
-
- ThreadCounts newCounts = counts;
- newCounts.numProcessingWork--;
-
- ThreadCounts oldCounts = ThreadCounts.CompareExchangeCounts(ref ThreadPoolInstance._separated.counts, newCounts, counts);
-
- if (oldCounts == counts)
- {
- return true;
- }
- counts = oldCounts;
- }
- }
-
- private static bool TakeActiveRequest()
- {
- int count = ThreadPoolInstance._numRequestedWorkers;
- while (count > 0)
- {
- int prevCount = Interlocked.CompareExchange(ref ThreadPoolInstance._numRequestedWorkers, count - 1, count);
- if (prevCount == count)
- {
- return true;
- }
- count = prevCount;
- }
- return false;
- }
-
- private static bool TryCreateWorkerThread()
- {
- try
- {
- Thread workerThread = new Thread(WorkerThreadStart);
- workerThread.IsThreadPoolThread = true;
- workerThread.IsBackground = true;
- workerThread.Start();
- }
- catch (ThreadStartException)
- {
- return false;
- }
- catch (OutOfMemoryException)
- {
- return false;
- }
- return true;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.cs b/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.cs
deleted file mode 100644
index fde4b5b7399..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPool.cs
+++ /dev/null
@@ -1,308 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- /// <summary>
- /// A thread-pool run and managed on the CLR.
- /// </summary>
- internal sealed partial class PortableThreadPool
- {
-#pragma warning disable IDE1006 // Naming Styles
- public static readonly PortableThreadPool ThreadPoolInstance = new PortableThreadPool();
-#pragma warning restore IDE1006 // Naming Styles
-
- private const int ThreadPoolThreadTimeoutMs = 20 * 1000; // If you change this make sure to change the timeout times in the tests.
-
-#if BIT64
- private const short MaxPossibleThreadCount = short.MaxValue;
-#elif BIT32
- private const short MaxPossibleThreadCount = 1023;
-#else
- #error Unknown platform
-#endif
-
- private const int CpuUtilizationHigh = 95;
- private const int CpuUtilizationLow = 80;
- private int _cpuUtilization = 0;
-
- private static readonly short s_forcedMinWorkerThreads = AppContextConfigHelper.GetInt16Config("System.Threading.ThreadPool.MinThreads", 0, false);
- private static readonly short s_forcedMaxWorkerThreads = AppContextConfigHelper.GetInt16Config("System.Threading.ThreadPool.MaxThreads", 0, false);
-
- private short _minThreads;
- private short _maxThreads;
- private readonly LowLevelLock _maxMinThreadLock = new LowLevelLock();
-
- [StructLayout(LayoutKind.Explicit, Size = CacheLineSize * 5)]
- private struct CacheLineSeparated
- {
-#if ARM64
- private const int CacheLineSize = 128;
-#else
- private const int CacheLineSize = 64;
-#endif
- [FieldOffset(CacheLineSize * 1)]
- public ThreadCounts counts;
- [FieldOffset(CacheLineSize * 2)]
- public int lastDequeueTime;
- [FieldOffset(CacheLineSize * 3)]
- public int priorCompletionCount;
- [FieldOffset(CacheLineSize * 3 + sizeof(int))]
- public int priorCompletedWorkRequestsTime;
- [FieldOffset(CacheLineSize * 3 + sizeof(int) * 2)]
- public int nextCompletedWorkRequestsTime;
- }
-
- private CacheLineSeparated _separated;
- private long _currentSampleStartTime;
- private readonly ThreadInt64PersistentCounter _completionCounter = new ThreadInt64PersistentCounter();
- private int _threadAdjustmentIntervalMs;
-
- private LowLevelLock _hillClimbingThreadAdjustmentLock = new LowLevelLock();
-
- private volatile int _numRequestedWorkers = 0;
-
- private PortableThreadPool()
- {
- _minThreads = s_forcedMinWorkerThreads > 0 ? s_forcedMinWorkerThreads : (short)Environment.ProcessorCount;
- if (_minThreads > MaxPossibleThreadCount)
- {
- _minThreads = MaxPossibleThreadCount;
- }
-
- _maxThreads = s_forcedMaxWorkerThreads > 0 ? s_forcedMaxWorkerThreads : MaxPossibleThreadCount;
- if (_maxThreads < _minThreads)
- {
- _maxThreads = _minThreads;
- }
-
- _separated = new CacheLineSeparated
- {
- counts = new ThreadCounts
- {
- numThreadsGoal = _minThreads
- }
- };
- }
-
- public bool SetMinThreads(int minThreads)
- {
- _maxMinThreadLock.Acquire();
- try
- {
- if (minThreads < 0 || minThreads > _maxThreads)
- {
- return false;
- }
- else
- {
- short threads = (short)Math.Min(minThreads, MaxPossibleThreadCount);
- if (s_forcedMinWorkerThreads == 0)
- {
- _minThreads = threads;
-
- ThreadCounts counts = ThreadCounts.VolatileReadCounts(ref _separated.counts);
- while (counts.numThreadsGoal < _minThreads)
- {
- ThreadCounts newCounts = counts;
- newCounts.numThreadsGoal = _minThreads;
-
- ThreadCounts oldCounts = ThreadCounts.CompareExchangeCounts(ref _separated.counts, newCounts, counts);
- if (oldCounts == counts)
- {
- counts = newCounts;
-
- if (newCounts.numThreadsGoal > oldCounts.numThreadsGoal && _numRequestedWorkers > 0)
- {
- WorkerThread.MaybeAddWorkingWorker();
- }
- }
- else
- {
- counts = oldCounts;
- }
- }
- }
- return true;
- }
- }
- finally
- {
- _maxMinThreadLock.Release();
- }
- }
-
- public int GetMinThreads() => _minThreads;
-
- public bool SetMaxThreads(int maxThreads)
- {
- _maxMinThreadLock.Acquire();
- try
- {
- if (maxThreads < _minThreads || maxThreads == 0)
- {
- return false;
- }
- else
- {
- short threads = (short)Math.Min(maxThreads, MaxPossibleThreadCount);
- if (s_forcedMaxWorkerThreads == 0)
- {
- _maxThreads = threads;
-
- ThreadCounts counts = ThreadCounts.VolatileReadCounts(ref _separated.counts);
- while (counts.numThreadsGoal > _maxThreads)
- {
- ThreadCounts newCounts = counts;
- newCounts.numThreadsGoal = _maxThreads;
-
- ThreadCounts oldCounts = ThreadCounts.CompareExchangeCounts(ref _separated.counts, newCounts, counts);
- if (oldCounts == counts)
- {
- counts = newCounts;
- }
- else
- {
- counts = oldCounts;
- }
- }
- }
- return true;
- }
- }
- finally
- {
- _maxMinThreadLock.Release();
- }
- }
-
- public int GetMaxThreads() => _maxThreads;
-
- public int GetAvailableThreads()
- {
- ThreadCounts counts = ThreadCounts.VolatileReadCounts(ref _separated.counts);
- int count = _maxThreads - counts.numProcessingWork;
- if (count < 0)
- {
- return 0;
- }
- return count;
- }
-
- public int ThreadCount => ThreadCounts.VolatileReadCounts(ref _separated.counts).numExistingThreads;
- public long CompletedWorkItemCount => _completionCounter.Count;
-
- internal bool NotifyWorkItemComplete()
- {
- _completionCounter.Increment();
- Volatile.Write(ref _separated.lastDequeueTime, Environment.TickCount);
-
- if (ShouldAdjustMaxWorkersActive() && _hillClimbingThreadAdjustmentLock.TryAcquire())
- {
- try
- {
- AdjustMaxWorkersActive();
- }
- finally
- {
- _hillClimbingThreadAdjustmentLock.Release();
- }
- }
-
- return !WorkerThread.ShouldStopProcessingWorkNow();
- }
-
- //
- // This method must only be called if ShouldAdjustMaxWorkersActive has returned true, *and*
- // _hillClimbingThreadAdjustmentLock is held.
- //
- private void AdjustMaxWorkersActive()
- {
- _hillClimbingThreadAdjustmentLock.VerifyIsLocked();
- int currentTicks = Environment.TickCount;
- int totalNumCompletions = (int)_completionCounter.Count;
- int numCompletions = totalNumCompletions - _separated.priorCompletionCount;
- long startTime = _currentSampleStartTime;
- long endTime = Stopwatch.GetTimestamp();
- long freq = Stopwatch.Frequency;
-
- double elapsedSeconds = (double)(endTime - startTime) / freq;
-
- if(elapsedSeconds * 1000 >= _threadAdjustmentIntervalMs / 2)
- {
- ThreadCounts currentCounts = ThreadCounts.VolatileReadCounts(ref _separated.counts);
- int newMax;
- (newMax, _threadAdjustmentIntervalMs) = HillClimbing.ThreadPoolHillClimber.Update(currentCounts.numThreadsGoal, elapsedSeconds, numCompletions);
-
- while(newMax != currentCounts.numThreadsGoal)
- {
- ThreadCounts newCounts = currentCounts;
- newCounts.numThreadsGoal = (short)newMax;
-
- ThreadCounts oldCounts = ThreadCounts.CompareExchangeCounts(ref _separated.counts, newCounts, currentCounts);
- if (oldCounts == currentCounts)
- {
- //
- // If we're increasing the max, inject a thread. If that thread finds work, it will inject
- // another thread, etc., until nobody finds work or we reach the new maximum.
- //
- // If we're reducing the max, whichever threads notice this first will sleep and timeout themselves.
- //
- if (newMax > oldCounts.numThreadsGoal)
- {
- WorkerThread.MaybeAddWorkingWorker();
- }
- break;
- }
- else
- {
- if(oldCounts.numThreadsGoal > currentCounts.numThreadsGoal && oldCounts.numThreadsGoal >= newMax)
- {
- // someone (probably the gate thread) increased the thread count more than
- // we are about to do. Don't interfere.
- break;
- }
-
- currentCounts = oldCounts;
- }
- }
- _separated.priorCompletionCount = totalNumCompletions;
- _separated.nextCompletedWorkRequestsTime = currentTicks + _threadAdjustmentIntervalMs;
- Volatile.Write(ref _separated.priorCompletedWorkRequestsTime, currentTicks);
- _currentSampleStartTime = endTime;
- }
- }
-
- private bool ShouldAdjustMaxWorkersActive()
- {
- // We need to subtract by prior time because Environment.TickCount can wrap around, making a comparison of absolute times unreliable.
- int priorTime = Volatile.Read(ref _separated.priorCompletedWorkRequestsTime);
- int requiredInterval = _separated.nextCompletedWorkRequestsTime - priorTime;
- int elapsedInterval = Environment.TickCount - priorTime;
- if(elapsedInterval >= requiredInterval)
- {
- // Avoid trying to adjust the thread count goal if there are already more threads than the thread count goal.
- // In that situation, hill climbing must have previously decided to decrease the thread count goal, so let's
- // wait until the system responds to that change before calling into hill climbing again. This condition should
- // be the opposite of the condition in WorkerThread.ShouldStopProcessingWorkNow that causes
- // threads processing work to stop in response to a decreased thread count goal. The logic here is a bit
- // different from the original CoreCLR code from which this implementation was ported because in this
- // implementation there are no retired threads, so only the count of threads processing work is considered.
- ThreadCounts counts = ThreadCounts.VolatileReadCounts(ref _separated.counts);
- return counts.numProcessingWork <= counts.numThreadsGoal;
- }
- return false;
- }
-
- internal void RequestWorker()
- {
- Interlocked.Increment(ref _numRequestedWorkers);
- WorkerThread.MaybeAddWorkingWorker();
- GateThread.EnsureRunning();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPoolEventSource.cs b/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPoolEventSource.cs
deleted file mode 100644
index 97fad82779e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/PortableThreadPoolEventSource.cs
+++ /dev/null
@@ -1,123 +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 System.Diagnostics.Tracing;
-
-namespace System.Threading
-{
- [EventSource(Name = "Microsoft-Windows-DotNETRuntime", Guid = "{e13c0d23-ccbc-4e12-931b-d9cc2eee27e4}")]
- public sealed class PortableThreadPoolEventSource : EventSource
- {
- private const string WorkerThreadMessage = "WorkerThreadCount=%1";
- private const string WorkerThreadAdjustmentSampleMessage = "Throughput=%1";
- private const string WorkerThreadAdjustmentAdjustmentEventMessage = "AverageThroughput=%1;%nNewWorkerThreadCount=%2;%nReason=%3";
- private const string WorkerThreadAdjustmentStatsEventMessage = "Duration=%1;%nThroughput=%2;%nThreadWave=%3;%nThroughputWave=%4;%nThroughputErrorEstimate=%5;%nAverageThroughputErrorEstimate=%6;%nThroughputRatio=%7;%nConfidence=%8;%nNewControlSetting=%9;%nNewThreadWaveMagnitude=%10";
-
- // The task definitions for the ETW manifest
- public static class Tasks
- {
- public const EventTask WorkerThreadTask = (EventTask)16;
- public const EventTask WorkerThreadAdjustmentTask = (EventTask)18;
- }
-
- public static class Opcodes
- {
- public const EventOpcode WaitOpcode = (EventOpcode)90;
- public const EventOpcode SampleOpcode = (EventOpcode)100;
- public const EventOpcode AdjustmentOpcode = (EventOpcode)101;
- public const EventOpcode StatsOpcode = (EventOpcode)102;
- }
-
- public static class Keywords
- {
- public const EventKeywords ThreadingKeyword = (EventKeywords)0x10000;
- }
-
- private PortableThreadPoolEventSource()
- {
- }
-
- [Event(1, Level = EventLevel.Informational, Message = WorkerThreadMessage, Task = Tasks.WorkerThreadTask, Opcode = EventOpcode.Start, Version = 0, Keywords = Keywords.ThreadingKeyword)]
- public void WorkerThreadStart(short numExistingThreads)
- {
- WriteEvent(1, numExistingThreads);
- }
-
- [Event(2, Level = EventLevel.Informational, Message = WorkerThreadMessage, Task = Tasks.WorkerThreadTask, Opcode = EventOpcode.Stop, Version = 0, Keywords = Keywords.ThreadingKeyword)]
- public void WorkerThreadStop(short numExistingThreads)
- {
- WriteEvent(2, numExistingThreads);
- }
-
- [Event(3, Level = EventLevel.Informational, Message = WorkerThreadMessage, Task = Tasks.WorkerThreadTask, Opcode = Opcodes.WaitOpcode, Version = 0, Keywords = Keywords.ThreadingKeyword)]
- public void WorkerThreadWait(short numExistingThreads)
- {
- WriteEvent(3, numExistingThreads);
- }
-
- [Event(4, Level = EventLevel.Informational, Message = WorkerThreadAdjustmentSampleMessage, Opcode = Opcodes.SampleOpcode, Version = 0, Task = Tasks.WorkerThreadAdjustmentTask, Keywords = Keywords.ThreadingKeyword)]
- public unsafe void WorkerThreadAdjustmentSample(double throughput)
- {
- if (IsEnabled())
- {
- EventData* data = stackalloc EventData[1];
- data[0].DataPointer = (IntPtr)(&throughput);
- data[0].Size = sizeof(double);
- WriteEventCore(4, 1, data);
- }
- }
-
- [Event(5, Level = EventLevel.Informational, Message = WorkerThreadAdjustmentSampleMessage, Opcode = Opcodes.AdjustmentOpcode, Version = 0, Task = Tasks.WorkerThreadAdjustmentTask, Keywords = Keywords.ThreadingKeyword)]
- public unsafe void WorkerThreadAdjustmentAdjustment(double averageThroughput, int newWorkerThreadCount, int stateOrTransition)
- {
- if (IsEnabled())
- {
- EventData* data = stackalloc EventData[3];
- data[0].DataPointer = (IntPtr)(&averageThroughput);
- data[0].Size = sizeof(double);
- data[1].DataPointer = (IntPtr)(&newWorkerThreadCount);
- data[1].Size = sizeof(int);
- data[2].DataPointer = (IntPtr)(&stateOrTransition);
- data[2].Size = sizeof(int);
- WriteEventCore(5, 3, data);
- }
- }
-
- [Event(6, Level = EventLevel.Verbose, Message = WorkerThreadAdjustmentSampleMessage, Opcode = Opcodes.StatsOpcode, Version = 0, Task = Tasks.WorkerThreadAdjustmentTask, Keywords = Keywords.ThreadingKeyword)]
- [CLSCompliant(false)]
- public unsafe void WorkerThreadAdjustmentStats(double duration, double throughput, double threadWave, double throughputWave, double throughputErrorEstimate,
- double averageThroughputNoise, double ratio, double confidence, double currentControlSetting, ushort newThreadWaveMagnitude)
- {
- if (IsEnabled())
- {
- EventData* data = stackalloc EventData[10];
- data[0].DataPointer = (IntPtr)(&duration);
- data[0].Size = sizeof(double);
- data[1].DataPointer = (IntPtr)(&throughput);
- data[1].Size = sizeof(double);
- data[2].DataPointer = (IntPtr)(&threadWave);
- data[2].Size = sizeof(double);
- data[3].DataPointer = (IntPtr)(&throughputWave);
- data[3].Size = sizeof(double);
- data[4].DataPointer = (IntPtr)(&throughputErrorEstimate);
- data[4].Size = sizeof(double);
- data[5].DataPointer = (IntPtr)(&averageThroughputNoise);
- data[5].Size = sizeof(double);
- data[6].DataPointer = (IntPtr)(&ratio);
- data[6].Size = sizeof(double);
- data[7].DataPointer = (IntPtr)(&confidence);
- data[7].Size = sizeof(double);
- data[8].DataPointer = (IntPtr)(&currentControlSetting);
- data[8].Size = sizeof(double);
- data[9].DataPointer = (IntPtr)(&newThreadWaveMagnitude);
- data[9].Size = sizeof(ushort);
- WriteEventCore(6, 10, data);
- }
- }
-
-#pragma warning disable IDE1006 // Naming Styles
- public static readonly PortableThreadPoolEventSource Log = new PortableThreadPoolEventSource();
-#pragma warning restore IDE1006 // Naming Styles
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ReaderWriterLockSlim.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ReaderWriterLockSlim.cs
deleted file mode 100644
index 928f4c62c24..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ReaderWriterLockSlim.cs
+++ /dev/null
@@ -1,1656 +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 System.Diagnostics; // for TraceInformation
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-
-namespace System.Threading
-{
- public enum LockRecursionPolicy
- {
- NoRecursion = 0,
- SupportsRecursion = 1,
- }
-
- //
- // ReaderWriterCount tracks how many of each kind of lock is held by each thread.
- // We keep a linked list for each thread, attached to a ThreadStatic field.
- // These are reused wherever possible, so that a given thread will only
- // allocate N of these, where N is the maximum number of locks held simultaneously
- // by that thread.
- //
- internal class ReaderWriterCount
- {
- // Which lock does this object belong to? This is a numeric ID for two reasons:
- // 1) We don't want this field to keep the lock object alive, and a WeakReference would
- // be too expensive.
- // 2) Setting the value of a long is faster than setting the value of a reference.
- // The "hot" paths in ReaderWriterLockSlim are short enough that this actually
- // matters.
- public long lockID;
-
- // How many reader locks does this thread hold on this ReaderWriterLockSlim instance?
- public int readercount;
-
- // Ditto for writer/upgrader counts. These are only used if the lock allows recursion.
- // But we have to have the fields on every ReaderWriterCount instance, because
- // we reuse it for different locks.
- public int writercount;
- public int upgradecount;
-
- // Next RWC in this thread's list.
- public ReaderWriterCount? next;
- }
-
- /// <summary>
- /// A reader-writer lock implementation that is intended to be simple, yet very
- /// efficient. In particular only 1 interlocked operation is taken for any lock
- /// operation (we use spin locks to achieve this). The spin lock is never held
- /// for more than a few instructions (in particular, we never call event APIs
- /// or in fact any non-trivial API while holding the spin lock).
- /// </summary>
- public class ReaderWriterLockSlim : IDisposable
- {
- // Specifying if the lock can be reacquired recursively.
- private readonly bool _fIsReentrant;
-
- // Lock specification for _spinLock: This lock protects exactly the local fields associated with this
- // instance of ReaderWriterLockSlim. It does NOT protect the memory associated with
- // the events that hang off this lock (eg writeEvent, readEvent upgradeEvent).
- private SpinLock _spinLock;
-
- // These variables allow use to avoid Setting events (which is expensive) if we don't have to.
- private uint _numWriteWaiters; // maximum number of threads that can be doing a WaitOne on the writeEvent
- private uint _numReadWaiters; // maximum number of threads that can be doing a WaitOne on the readEvent
- private uint _numWriteUpgradeWaiters; // maximum number of threads that can be doing a WaitOne on the upgradeEvent (at most 1).
- private uint _numUpgradeWaiters;
-
- private WaiterStates _waiterStates;
-
- private int _upgradeLockOwnerId;
- private int _writeLockOwnerId;
-
- // conditions we wait on.
- private EventWaitHandle? _writeEvent; // threads waiting to acquire a write lock go here.
- private EventWaitHandle? _readEvent; // threads waiting to acquire a read lock go here (will be released in bulk)
- private EventWaitHandle? _upgradeEvent; // thread waiting to acquire the upgrade lock
- private EventWaitHandle? _waitUpgradeEvent; // thread waiting to upgrade from the upgrade lock to a write lock go here (at most one)
-
- // Every lock instance has a unique ID, which is used by ReaderWriterCount to associate itself with the lock
- // without holding a reference to it.
- private static long s_nextLockID;
- private readonly long _lockID;
-
- // See comments on ReaderWriterCount.
- [ThreadStatic]
- private static ReaderWriterCount? t_rwc;
-
- private bool _fUpgradeThreadHoldingRead;
-
- private const int MaxSpinCount = 20;
-
- // The uint, that contains info like if the writer lock is held, num of
- // readers etc.
- private uint _owners;
-
- // Various R/W masks
- // Note:
- // The Uint is divided as follows:
- //
- // Writer-Owned Waiting-Writers Waiting Upgraders Num-Readers
- // 31 30 29 28.......0
- //
- // Dividing the uint, allows to vastly simplify logic for checking if a
- // reader should go in etc. Setting the writer bit will automatically
- // make the value of the uint much larger than the max num of readers
- // allowed, thus causing the check for max_readers to fail.
-
- private const uint WRITER_HELD = 0x80000000;
- private const uint WAITING_WRITERS = 0x40000000;
- private const uint WAITING_UPGRADER = 0x20000000;
-
- // The max readers is actually one less then its theoretical max.
- // This is done in order to prevent reader count overflows. If the reader
- // count reaches max, other readers will wait.
- private const uint MAX_READER = 0x10000000 - 2;
-
- private const uint READER_MASK = 0x10000000 - 1;
-
- private bool _fDisposed;
-
- private void InitializeThreadCounts()
- {
- _upgradeLockOwnerId = -1;
- _writeLockOwnerId = -1;
- }
-
- public ReaderWriterLockSlim()
- : this(LockRecursionPolicy.NoRecursion)
- {
- }
-
- public ReaderWriterLockSlim(LockRecursionPolicy recursionPolicy)
- {
- if (recursionPolicy == LockRecursionPolicy.SupportsRecursion)
- {
- _fIsReentrant = true;
- }
- InitializeThreadCounts();
- _waiterStates = WaiterStates.NoWaiters;
- _lockID = Interlocked.Increment(ref s_nextLockID);
- }
-
- private bool HasNoWaiters
- {
- get
- {
-#if DEBUG
- Debug.Assert(_spinLock.IsHeld);
-#endif
-
- return (_waiterStates & WaiterStates.NoWaiters) != WaiterStates.None;
- }
- set
- {
-#if DEBUG
- Debug.Assert(_spinLock.IsHeld);
-#endif
-
- if (value)
- {
- _waiterStates |= WaiterStates.NoWaiters;
- }
- else
- {
- _waiterStates &= ~WaiterStates.NoWaiters;
- }
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool IsRWEntryEmpty(ReaderWriterCount rwc)
- {
- if (rwc.lockID == 0)
- return true;
- else if (rwc.readercount == 0 && rwc.writercount == 0 && rwc.upgradecount == 0)
- return true;
- else
- return false;
- }
-
- private bool IsRwHashEntryChanged(ReaderWriterCount lrwc)
- {
- return lrwc.lockID != _lockID;
- }
-
- /// <summary>
- /// This routine retrieves/sets the per-thread counts needed to enforce the
- /// various rules related to acquiring the lock.
- ///
- /// DontAllocate is set to true if the caller just wants to get an existing
- /// entry for this thread, but doesn't want to add one if an existing one
- /// could not be found.
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private ReaderWriterCount? GetThreadRWCount(bool dontAllocate)
- {
- ReaderWriterCount? rwc = t_rwc;
- ReaderWriterCount? empty = null;
- while (rwc != null)
- {
- if (rwc.lockID == _lockID)
- return rwc;
-
- if (!dontAllocate && empty == null && IsRWEntryEmpty(rwc))
- empty = rwc;
-
- rwc = rwc.next;
- }
-
- if (dontAllocate)
- return null;
-
- if (empty == null)
- {
- empty = new ReaderWriterCount();
- empty.next = t_rwc;
- t_rwc = empty;
- }
-
- empty.lockID = _lockID;
- return empty;
- }
-
- public void EnterReadLock()
- {
- TryEnterReadLock(-1);
- }
-
- //
- // Common timeout support
- //
- private struct TimeoutTracker
- {
- private readonly int _total;
- private readonly int _start;
-
- public TimeoutTracker(TimeSpan timeout)
- {
- long ltm = (long)timeout.TotalMilliseconds;
- if (ltm < -1 || ltm > (long)int.MaxValue)
- throw new ArgumentOutOfRangeException(nameof(timeout));
- _total = (int)ltm;
- if (_total != -1 && _total != 0)
- _start = Environment.TickCount;
- else
- _start = 0;
- }
-
- public TimeoutTracker(int millisecondsTimeout)
- {
- if (millisecondsTimeout < -1)
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout));
- _total = millisecondsTimeout;
- if (_total != -1 && _total != 0)
- _start = Environment.TickCount;
- else
- _start = 0;
- }
-
- public int RemainingMilliseconds
- {
- get
- {
- if (_total == -1 || _total == 0)
- return _total;
-
- int elapsed = Environment.TickCount - _start;
- // elapsed may be negative if TickCount has overflowed by 2^31 milliseconds.
- if (elapsed < 0 || elapsed >= _total)
- return 0;
-
- return _total - elapsed;
- }
- }
-
- public bool IsExpired => RemainingMilliseconds == 0;
- }
-
- public bool TryEnterReadLock(TimeSpan timeout)
- {
- return TryEnterReadLock(new TimeoutTracker(timeout));
- }
-
- public bool TryEnterReadLock(int millisecondsTimeout)
- {
- return TryEnterReadLock(new TimeoutTracker(millisecondsTimeout));
- }
-
- private bool TryEnterReadLock(TimeoutTracker timeout)
- {
- return TryEnterReadLockCore(timeout);
- }
-
- private bool TryEnterReadLockCore(TimeoutTracker timeout)
- {
- if (_fDisposed)
- throw new ObjectDisposedException(null);
-
- ReaderWriterCount lrwc;
- int id = Environment.CurrentManagedThreadId;
-
- if (!_fIsReentrant)
- {
- if (id == _writeLockOwnerId)
- {
- // Check for AW->AR
- throw new LockRecursionException(SR.LockRecursionException_ReadAfterWriteNotAllowed);
- }
-
- _spinLock.Enter(EnterSpinLockReason.EnterAnyRead);
-
- lrwc = GetThreadRWCount(dontAllocate: false)!;
-
- // Check if the reader lock is already acquired. Note, we could
- // check the presence of a reader by not allocating rwc (But that
- // would lead to two lookups in the common case. It's better to keep
- // a count in the structure).
- if (lrwc.readercount > 0)
- {
- _spinLock.Exit();
- throw new LockRecursionException(SR.LockRecursionException_RecursiveReadNotAllowed);
- }
- else if (id == _upgradeLockOwnerId)
- {
- // The upgrade lock is already held.
- // Update the global read counts and exit.
-
- lrwc.readercount++;
- _owners++;
- _spinLock.Exit();
- return true;
- }
- }
- else
- {
- _spinLock.Enter(EnterSpinLockReason.EnterAnyRead);
- lrwc = GetThreadRWCount(dontAllocate: false)!;
- if (lrwc.readercount > 0)
- {
- lrwc.readercount++;
- _spinLock.Exit();
- return true;
- }
- else if (id == _upgradeLockOwnerId)
- {
- // The upgrade lock is already held.
- // Update the global read counts and exit.
- lrwc.readercount++;
- _owners++;
- _spinLock.Exit();
- _fUpgradeThreadHoldingRead = true;
- return true;
- }
- else if (id == _writeLockOwnerId)
- {
- // The write lock is already held.
- // Update global read counts here,
- lrwc.readercount++;
- _owners++;
- _spinLock.Exit();
- return true;
- }
- }
-
- bool retVal = true;
- int spinCount = 0;
-
- while (true)
- {
- // We can enter a read lock if there are only read-locks have been given out
- // and a writer is not trying to get in.
-
- if (_owners < MAX_READER)
- {
- // Good case, there is no contention, we are basically done
- _owners++; // Indicate we have another reader
- lrwc.readercount++;
- break;
- }
-
- if (timeout.IsExpired)
- {
- _spinLock.Exit();
- return false;
- }
-
- if (spinCount < MaxSpinCount && ShouldSpinForEnterAnyRead())
- {
- _spinLock.Exit();
- spinCount++;
- SpinWait(spinCount);
- _spinLock.Enter(EnterSpinLockReason.EnterAnyRead);
- // The per-thread structure may have been recycled as the lock is acquired (due to message pumping), load again.
- if (IsRwHashEntryChanged(lrwc))
- lrwc = GetThreadRWCount(dontAllocate: false)!;
- continue;
- }
-
- // Drat, we need to wait. Mark that we have waiters and wait.
- if (_readEvent == null) // Create the needed event
- {
- LazyCreateEvent(ref _readEvent, EnterLockType.Read);
- if (IsRwHashEntryChanged(lrwc))
- lrwc = GetThreadRWCount(dontAllocate: false)!;
- continue; // since we left the lock, start over.
- }
-
- retVal = WaitOnEvent(_readEvent, ref _numReadWaiters, timeout, EnterLockType.Read);
- if (!retVal)
- {
- return false;
- }
- if (IsRwHashEntryChanged(lrwc))
- lrwc = GetThreadRWCount(dontAllocate: false)!;
- }
-
- _spinLock.Exit();
- return retVal;
- }
-
- public void EnterWriteLock()
- {
- TryEnterWriteLock(-1);
- }
-
- public bool TryEnterWriteLock(TimeSpan timeout)
- {
- return TryEnterWriteLock(new TimeoutTracker(timeout));
- }
-
- public bool TryEnterWriteLock(int millisecondsTimeout)
- {
- return TryEnterWriteLock(new TimeoutTracker(millisecondsTimeout));
- }
-
- private bool TryEnterWriteLock(TimeoutTracker timeout)
- {
- return TryEnterWriteLockCore(timeout);
- }
-
- private bool TryEnterWriteLockCore(TimeoutTracker timeout)
- {
- if (_fDisposed)
- throw new ObjectDisposedException(null);
-
- int id = Environment.CurrentManagedThreadId;
- ReaderWriterCount? lrwc;
- bool upgradingToWrite = false;
-
- if (!_fIsReentrant)
- {
- EnterSpinLockReason enterMyLockReason;
- if (id == _writeLockOwnerId)
- {
- // Check for AW->AW
- throw new LockRecursionException(SR.LockRecursionException_RecursiveWriteNotAllowed);
- }
- else if (id == _upgradeLockOwnerId)
- {
- // AU->AW case is allowed once.
- upgradingToWrite = true;
- enterMyLockReason = EnterSpinLockReason.UpgradeToWrite;
- }
- else
- {
- enterMyLockReason = EnterSpinLockReason.EnterWrite;
- }
- _spinLock.Enter(enterMyLockReason);
-
- lrwc = GetThreadRWCount(dontAllocate: true);
-
- // Can't acquire write lock with reader lock held.
- if (lrwc != null && lrwc.readercount > 0)
- {
- _spinLock.Exit();
- throw new LockRecursionException(SR.LockRecursionException_WriteAfterReadNotAllowed);
- }
- }
- else
- {
- EnterSpinLockReason enterMyLockReason;
- if (id == _writeLockOwnerId)
- {
- enterMyLockReason = EnterSpinLockReason.EnterRecursiveWrite;
- }
- else if (id == _upgradeLockOwnerId)
- {
- enterMyLockReason = EnterSpinLockReason.UpgradeToWrite;
- }
- else
- {
- enterMyLockReason = EnterSpinLockReason.EnterWrite;
- }
- _spinLock.Enter(enterMyLockReason);
-
- lrwc = GetThreadRWCount(dontAllocate: false)!;
-
- if (id == _writeLockOwnerId)
- {
- lrwc.writercount++;
- _spinLock.Exit();
- return true;
- }
- else if (id == _upgradeLockOwnerId)
- {
- upgradingToWrite = true;
- }
- else if (lrwc.readercount > 0)
- {
- // Write locks may not be acquired if only read locks have been
- // acquired.
- _spinLock.Exit();
- throw new LockRecursionException(SR.LockRecursionException_WriteAfterReadNotAllowed);
- }
- }
-
- bool retVal = true;
- int spinCount = 0;
-
- while (true)
- {
- if (IsWriterAcquired())
- {
- // Good case, there is no contention, we are basically done
- SetWriterAcquired();
- break;
- }
-
- // Check if there is just one upgrader, and no readers.
- // Assumption: Only one thread can have the upgrade lock, so the
- // following check will fail for all other threads that may sneak in
- // when the upgrading thread is waiting.
-
- if (upgradingToWrite)
- {
- uint readercount = GetNumReaders();
-
- if (readercount == 1)
- {
- // Good case again, there is just one upgrader, and no readers.
- SetWriterAcquired(); // indicate we have a writer.
- break;
- }
- else if (readercount == 2)
- {
- if (lrwc != null)
- {
- if (IsRwHashEntryChanged(lrwc))
- lrwc = GetThreadRWCount(dontAllocate: false)!;
-
- if (lrwc.readercount > 0)
- {
- // This check is needed for EU->ER->EW case, as the owner count will be two.
- Debug.Assert(_fIsReentrant);
- Debug.Assert(_fUpgradeThreadHoldingRead);
-
- // Good case again, there is just one upgrader, and no readers.
- SetWriterAcquired(); // indicate we have a writer.
- break;
- }
- }
- }
- }
-
- if (timeout.IsExpired)
- {
- _spinLock.Exit();
- return false;
- }
-
- if (spinCount < MaxSpinCount && ShouldSpinForEnterAnyWrite(upgradingToWrite))
- {
- _spinLock.Exit();
- spinCount++;
- SpinWait(spinCount);
- _spinLock.Enter(upgradingToWrite ? EnterSpinLockReason.UpgradeToWrite : EnterSpinLockReason.EnterWrite);
- continue;
- }
-
- if (upgradingToWrite)
- {
- if (_waitUpgradeEvent == null) // Create the needed event
- {
- LazyCreateEvent(ref _waitUpgradeEvent, EnterLockType.UpgradeToWrite);
- continue; // since we left the lock, start over.
- }
-
- Debug.Assert(_numWriteUpgradeWaiters == 0, "There can be at most one thread with the upgrade lock held.");
-
- retVal = WaitOnEvent(_waitUpgradeEvent, ref _numWriteUpgradeWaiters, timeout, EnterLockType.UpgradeToWrite);
-
- // The lock is not held in case of failure.
- if (!retVal)
- return false;
- }
- else
- {
- // Drat, we need to wait. Mark that we have waiters and wait.
- if (_writeEvent == null) // create the needed event.
- {
- LazyCreateEvent(ref _writeEvent, EnterLockType.Write);
- continue; // since we left the lock, start over.
- }
-
- retVal = WaitOnEvent(_writeEvent, ref _numWriteWaiters, timeout, EnterLockType.Write);
- // The lock is not held in case of failure.
- if (!retVal)
- return false;
- }
- }
-
- Debug.Assert((_owners & WRITER_HELD) > 0);
-
- if (_fIsReentrant)
- {
- Debug.Assert(lrwc != null, "Initialized based on _fIsReentrant earlier in the method");
- if (IsRwHashEntryChanged(lrwc))
- lrwc = GetThreadRWCount(dontAllocate: false)!;
- lrwc.writercount++;
- }
-
- _spinLock.Exit();
-
- _writeLockOwnerId = id;
-
- return true;
- }
-
- public void EnterUpgradeableReadLock()
- {
- TryEnterUpgradeableReadLock(-1);
- }
-
- public bool TryEnterUpgradeableReadLock(TimeSpan timeout)
- {
- return TryEnterUpgradeableReadLock(new TimeoutTracker(timeout));
- }
-
- public bool TryEnterUpgradeableReadLock(int millisecondsTimeout)
- {
- return TryEnterUpgradeableReadLock(new TimeoutTracker(millisecondsTimeout));
- }
-
- private bool TryEnterUpgradeableReadLock(TimeoutTracker timeout)
- {
- return TryEnterUpgradeableReadLockCore(timeout);
- }
-
- private bool TryEnterUpgradeableReadLockCore(TimeoutTracker timeout)
- {
- if (_fDisposed)
- throw new ObjectDisposedException(null);
-
- int id = Environment.CurrentManagedThreadId;
- ReaderWriterCount? lrwc;
-
- if (!_fIsReentrant)
- {
- if (id == _upgradeLockOwnerId)
- {
- // Check for AU->AU
- throw new LockRecursionException(SR.LockRecursionException_RecursiveUpgradeNotAllowed);
- }
- else if (id == _writeLockOwnerId)
- {
- // Check for AU->AW
- throw new LockRecursionException(SR.LockRecursionException_UpgradeAfterWriteNotAllowed);
- }
-
- _spinLock.Enter(EnterSpinLockReason.EnterAnyRead);
- lrwc = GetThreadRWCount(dontAllocate: true);
- // Can't acquire upgrade lock with reader lock held.
- if (lrwc != null && lrwc.readercount > 0)
- {
- _spinLock.Exit();
- throw new LockRecursionException(SR.LockRecursionException_UpgradeAfterReadNotAllowed);
- }
- }
- else
- {
- _spinLock.Enter(EnterSpinLockReason.EnterAnyRead);
- lrwc = GetThreadRWCount(dontAllocate: false)!;
-
- if (id == _upgradeLockOwnerId)
- {
- lrwc.upgradecount++;
- _spinLock.Exit();
- return true;
- }
- else if (id == _writeLockOwnerId)
- {
- // Write lock is already held, Just update the global state
- // to show presence of upgrader.
- Debug.Assert((_owners & WRITER_HELD) > 0);
- _owners++;
- _upgradeLockOwnerId = id;
- lrwc.upgradecount++;
- if (lrwc.readercount > 0)
- _fUpgradeThreadHoldingRead = true;
- _spinLock.Exit();
- return true;
- }
- else if (lrwc.readercount > 0)
- {
- // Upgrade locks may not be acquired if only read locks have been
- // acquired.
- _spinLock.Exit();
- throw new LockRecursionException(SR.LockRecursionException_UpgradeAfterReadNotAllowed);
- }
- }
-
- bool retVal = true;
- int spinCount = 0;
-
- while (true)
- {
- // Once an upgrade lock is taken, it's like having a reader lock held
- // until upgrade or downgrade operations are performed.
-
- if ((_upgradeLockOwnerId == -1) && (_owners < MAX_READER))
- {
- _owners++;
- _upgradeLockOwnerId = id;
- break;
- }
-
- if (timeout.IsExpired)
- {
- _spinLock.Exit();
- return false;
- }
-
- if (spinCount < MaxSpinCount && ShouldSpinForEnterAnyRead())
- {
- _spinLock.Exit();
- spinCount++;
- SpinWait(spinCount);
- _spinLock.Enter(EnterSpinLockReason.EnterAnyRead);
- continue;
- }
-
- // Drat, we need to wait. Mark that we have waiters and wait.
- if (_upgradeEvent == null) // Create the needed event
- {
- LazyCreateEvent(ref _upgradeEvent, EnterLockType.UpgradeableRead);
- continue; // since we left the lock, start over.
- }
-
- // Only one thread with the upgrade lock held can proceed.
- retVal = WaitOnEvent(_upgradeEvent, ref _numUpgradeWaiters, timeout, EnterLockType.UpgradeableRead);
- if (!retVal)
- return false;
- }
-
- if (_fIsReentrant)
- {
- // The lock may have been dropped getting here, so make a quick check to see whether some other
- // thread did not grab the entry.
- Debug.Assert(lrwc != null, "Initialized based on _fIsReentrant earlier in the method");
- if (IsRwHashEntryChanged(lrwc))
- lrwc = GetThreadRWCount(dontAllocate: false)!;
- lrwc.upgradecount++;
- }
-
- _spinLock.Exit();
-
- return true;
- }
-
- public void ExitReadLock()
- {
- _spinLock.Enter(EnterSpinLockReason.ExitAnyRead);
-
- ReaderWriterCount? lrwc = GetThreadRWCount(dontAllocate: true);
-
- if (lrwc == null || lrwc.readercount < 1)
- {
- // You have to be holding the read lock to make this call.
- _spinLock.Exit();
- throw new SynchronizationLockException(SR.SynchronizationLockException_MisMatchedRead);
- }
-
- if (_fIsReentrant)
- {
- if (lrwc.readercount > 1)
- {
- lrwc.readercount--;
- _spinLock.Exit();
- return;
- }
-
- if (Environment.CurrentManagedThreadId == _upgradeLockOwnerId)
- {
- _fUpgradeThreadHoldingRead = false;
- }
- }
-
- Debug.Assert(_owners > 0, "ReleasingReaderLock: releasing lock and no read lock taken");
-
- --_owners;
-
- Debug.Assert(lrwc.readercount == 1);
- lrwc.readercount--;
-
- ExitAndWakeUpAppropriateWaiters();
- }
-
- public void ExitWriteLock()
- {
- ReaderWriterCount lrwc;
- if (!_fIsReentrant)
- {
- if (Environment.CurrentManagedThreadId != _writeLockOwnerId)
- {
- // You have to be holding the write lock to make this call.
- throw new SynchronizationLockException(SR.SynchronizationLockException_MisMatchedWrite);
- }
- _spinLock.Enter(EnterSpinLockReason.ExitAnyWrite);
- }
- else
- {
- _spinLock.Enter(EnterSpinLockReason.ExitAnyWrite);
- lrwc = GetThreadRWCount(dontAllocate: false)!;
-
- if (lrwc == null)
- {
- _spinLock.Exit();
- throw new SynchronizationLockException(SR.SynchronizationLockException_MisMatchedWrite);
- }
-
- if (lrwc.writercount < 1)
- {
- _spinLock.Exit();
- throw new SynchronizationLockException(SR.SynchronizationLockException_MisMatchedWrite);
- }
-
- lrwc.writercount--;
-
- if (lrwc.writercount > 0)
- {
- _spinLock.Exit();
- return;
- }
- }
-
- Debug.Assert((_owners & WRITER_HELD) > 0, "Calling ReleaseWriterLock when no write lock is held");
-
- ClearWriterAcquired();
-
- _writeLockOwnerId = -1;
-
- ExitAndWakeUpAppropriateWaiters();
- }
-
- public void ExitUpgradeableReadLock()
- {
- ReaderWriterCount? lrwc;
- if (!_fIsReentrant)
- {
- if (Environment.CurrentManagedThreadId != _upgradeLockOwnerId)
- {
- // You have to be holding the upgrade lock to make this call.
- throw new SynchronizationLockException(SR.SynchronizationLockException_MisMatchedUpgrade);
- }
- _spinLock.Enter(EnterSpinLockReason.ExitAnyRead);
- }
- else
- {
- _spinLock.Enter(EnterSpinLockReason.ExitAnyRead);
- lrwc = GetThreadRWCount(dontAllocate: true);
-
- if (lrwc == null)
- {
- _spinLock.Exit();
- throw new SynchronizationLockException(SR.SynchronizationLockException_MisMatchedUpgrade);
- }
-
- if (lrwc.upgradecount < 1)
- {
- _spinLock.Exit();
- throw new SynchronizationLockException(SR.SynchronizationLockException_MisMatchedUpgrade);
- }
-
- lrwc.upgradecount--;
-
- if (lrwc.upgradecount > 0)
- {
- _spinLock.Exit();
- return;
- }
-
- _fUpgradeThreadHoldingRead = false;
- }
-
- _owners--;
- _upgradeLockOwnerId = -1;
-
- ExitAndWakeUpAppropriateWaiters();
- }
-
- /// <summary>
- /// A routine for lazily creating a event outside the lock (so if errors
- /// happen they are outside the lock and that we don't do much work
- /// while holding a spin lock). If all goes well, reenter the lock and
- /// set 'waitEvent'
- /// </summary>
- private void LazyCreateEvent([NotNull] ref EventWaitHandle? waitEvent, EnterLockType enterLockType)
- {
-#if DEBUG
- Debug.Assert(_spinLock.IsHeld);
- Debug.Assert(waitEvent == null);
-#endif
-
- _spinLock.Exit();
-
- var newEvent =
- new EventWaitHandle(
- false,
- enterLockType == EnterLockType.Read ? EventResetMode.ManualReset : EventResetMode.AutoReset);
-
- EnterSpinLockReason enterMyLockReason;
- switch (enterLockType)
- {
- case EnterLockType.Read:
- case EnterLockType.UpgradeableRead:
- enterMyLockReason = EnterSpinLockReason.EnterAnyRead | EnterSpinLockReason.Wait;
- break;
-
- case EnterLockType.Write:
- enterMyLockReason = EnterSpinLockReason.EnterWrite | EnterSpinLockReason.Wait;
- break;
-
- default:
- Debug.Assert(enterLockType == EnterLockType.UpgradeToWrite);
- enterMyLockReason = EnterSpinLockReason.UpgradeToWrite | EnterSpinLockReason.Wait;
- break;
- }
- _spinLock.Enter(enterMyLockReason);
-
- if (waitEvent == null) // maybe someone snuck in.
- waitEvent = newEvent;
- else
- newEvent.Dispose();
- }
-
- /// <summary>
- /// Waits on 'waitEvent' with a timeout
- /// Before the wait 'numWaiters' is incremented and is restored before leaving this routine.
- /// </summary>
- private bool WaitOnEvent(
- EventWaitHandle waitEvent,
- ref uint numWaiters,
- TimeoutTracker timeout,
- EnterLockType enterLockType)
- {
-#if DEBUG
- Debug.Assert(_spinLock.IsHeld);
-#endif
-
- WaiterStates waiterSignaledState = WaiterStates.None;
- EnterSpinLockReason enterMyLockReason;
- switch (enterLockType)
- {
- case EnterLockType.UpgradeableRead:
- waiterSignaledState = WaiterStates.UpgradeableReadWaiterSignaled;
- goto case EnterLockType.Read;
-
- case EnterLockType.Read:
- enterMyLockReason = EnterSpinLockReason.EnterAnyRead;
- break;
-
- case EnterLockType.Write:
- waiterSignaledState = WaiterStates.WriteWaiterSignaled;
- enterMyLockReason = EnterSpinLockReason.EnterWrite;
- break;
-
- default:
- Debug.Assert(enterLockType == EnterLockType.UpgradeToWrite);
- enterMyLockReason = EnterSpinLockReason.UpgradeToWrite;
- break;
- }
-
- // It was not possible to acquire the RW lock because some other thread was holding some type of lock. The other
- // thread, when it releases its lock, will wake appropriate waiters. Along with resetting the wait event, clear the
- // waiter signaled bit for this type of waiter if applicable, to indicate that a waiter of this type is no longer
- // signaled.
- //
- // If the waiter signaled bit is not updated upon event reset, the following scenario would lead to deadlock:
- // - Thread T0 signals the write waiter event or the upgradeable read waiter event to wake a waiter
- // - There are no threads waiting on the event, but T1 is in WaitOnEvent() after exiting the spin lock and before
- // actually waiting on the event (that is, it's recorded that there is one waiter for the event). It remains in
- // this region for a while, in the repro case it typically gets context-switched out.
- // - T2 acquires the RW lock in some fashion that blocks T0 or T3 from acquiring the RW lock
- // - T0 or T3 fails to acquire the RW lock enough times for it to enter WaitOnEvent for the same event as T1
- // - T0 or T3 resets the event
- // - T2 releases the RW lock and does not wake a waiter because the reset at the previous step lost a signal but
- // _waiterStates was not updated to reflect that
- // - T1 and other threads begin waiting on the event, but there's no longer any thread that would wake them
- if (waiterSignaledState != WaiterStates.None && (_waiterStates & waiterSignaledState) != WaiterStates.None)
- {
- _waiterStates &= ~waiterSignaledState;
- }
- waitEvent.Reset();
-
- numWaiters++;
- HasNoWaiters = false;
-
- // Setting these bits will prevent new readers from getting in.
- if (_numWriteWaiters == 1)
- SetWritersWaiting();
- if (_numWriteUpgradeWaiters == 1)
- SetUpgraderWaiting();
-
- bool waitSuccessful = false;
- _spinLock.Exit(); // Do the wait outside of any lock
-
- try
- {
- waitSuccessful = waitEvent.WaitOne(timeout.RemainingMilliseconds);
- }
- finally
- {
- _spinLock.Enter(enterMyLockReason);
-
- --numWaiters;
-
- if (waitSuccessful &&
- waiterSignaledState != WaiterStates.None &&
- (_waiterStates & waiterSignaledState) != WaiterStates.None)
- {
- // Indicate that a signaled waiter of this type has woken. Since non-read waiters are signaled to wake one
- // at a time, we avoid waking up more than one waiter of that type upon successive enter/exit loops until
- // the signaled thread actually wakes up. For example, if there are multiple write waiters and one thread is
- // repeatedly entering and exiting a write lock, every exit would otherwise signal a different write waiter
- // to wake up unnecessarily when only one woken waiter may actually succeed in entering the write lock.
- _waiterStates &= ~waiterSignaledState;
- }
-
- if (_numWriteWaiters == 0 && _numWriteUpgradeWaiters == 0 && _numUpgradeWaiters == 0 && _numReadWaiters == 0)
- HasNoWaiters = true;
-
- if (_numWriteWaiters == 0)
- ClearWritersWaiting();
- if (_numWriteUpgradeWaiters == 0)
- ClearUpgraderWaiting();
-
- if (!waitSuccessful) // We may also be about to throw for some reason. Exit myLock.
- {
- if (enterLockType >= EnterLockType.Write)
- {
- // Write waiters block read waiters from acquiring the lock. Since this was the last write waiter, try
- // to wake up the appropriate read waiters.
- ExitAndWakeUpAppropriateReadWaiters();
- }
- else
- {
- _spinLock.Exit();
- }
- }
- }
- return waitSuccessful;
- }
-
- /// <summary>
- /// Determines the appropriate events to set, leaves the locks, and sets the events.
- /// </summary>
- private void ExitAndWakeUpAppropriateWaiters()
- {
-#if DEBUG
- Debug.Assert(_spinLock.IsHeld);
-#endif
- if (HasNoWaiters)
- {
- _spinLock.Exit();
- return;
- }
-
- ExitAndWakeUpAppropriateWaitersPreferringWriters();
- }
-
- private void ExitAndWakeUpAppropriateWaitersPreferringWriters()
- {
- uint readercount = GetNumReaders();
-
- // We need this case for EU->ER->EW case, as the read count will be 2 in
- // that scenario.
- if (_fIsReentrant)
- {
- if (_numWriteUpgradeWaiters > 0 && _fUpgradeThreadHoldingRead && readercount == 2)
- {
- _spinLock.Exit(); // Exit before signaling to improve efficiency (wakee will need the lock)
- _waitUpgradeEvent!.Set(); // release all upgraders (however there can be at most one). Known non-null because _numWriteUpgradeWaiters > 0.
- return;
- }
- }
-
- if (readercount == 1 && _numWriteUpgradeWaiters > 0)
- {
- // We have to be careful now, as we are dropping the lock.
- // No new writes should be allowed to sneak in if an upgrade
- // was pending.
-
- _spinLock.Exit(); // Exit before signaling to improve efficiency (wakee will need the lock)
- _waitUpgradeEvent!.Set(); // release all upgraders (however there can be at most one). Known non-null because _numWriteUpgradeWaiters > 0.
- }
- else if (readercount == 0 && _numWriteWaiters > 0)
- {
- // Check if a waiter of the same type has already been signaled but hasn't woken yet. If so, avoid signaling
- // and waking another waiter unnecessarily.
- WaiterStates signaled = _waiterStates & WaiterStates.WriteWaiterSignaled;
- if (signaled == WaiterStates.None)
- {
- _waiterStates |= WaiterStates.WriteWaiterSignaled;
- }
-
- _spinLock.Exit(); // Exit before signaling to improve efficiency (wakee will need the lock)
-
- if (signaled == WaiterStates.None)
- {
- _writeEvent!.Set(); // release one writer. Known non-null because _numWriteWaiters > 0.
- }
- }
- else
- {
- ExitAndWakeUpAppropriateReadWaiters();
- }
- }
-
- private void ExitAndWakeUpAppropriateReadWaiters()
- {
-#if DEBUG
- Debug.Assert(_spinLock.IsHeld);
-#endif
-
- if (_numWriteWaiters != 0 || _numWriteUpgradeWaiters != 0 || HasNoWaiters)
- {
- _spinLock.Exit();
- return;
- }
-
- Debug.Assert(_numReadWaiters != 0 || _numUpgradeWaiters != 0);
-
- bool setReadEvent = _numReadWaiters != 0;
- bool setUpgradeEvent = _numUpgradeWaiters != 0 && _upgradeLockOwnerId == -1;
- if (setUpgradeEvent)
- {
- // Check if a waiter of the same type has already been signaled but hasn't woken yet. If so, avoid signaling
- // and waking another waiter unnecessarily.
- if ((_waiterStates & WaiterStates.UpgradeableReadWaiterSignaled) == WaiterStates.None)
- {
- _waiterStates |= WaiterStates.UpgradeableReadWaiterSignaled;
- }
- else
- {
- setUpgradeEvent = false;
- }
- }
-
- _spinLock.Exit(); // Exit before signaling to improve efficiency (wakee will need the lock)
-
- if (setReadEvent)
- _readEvent!.Set(); // release all readers. Known non-null because _numUpgradeWaiters != 0.
-
- if (setUpgradeEvent)
- _upgradeEvent!.Set(); // release one upgrader.
- }
-
- private bool IsWriterAcquired()
- {
- return (_owners & ~WAITING_WRITERS) == 0;
- }
-
- private void SetWriterAcquired()
- {
- _owners |= WRITER_HELD; // indicate we have a writer.
- }
-
- private void ClearWriterAcquired()
- {
- _owners &= ~WRITER_HELD;
- }
-
- private void SetWritersWaiting()
- {
- _owners |= WAITING_WRITERS;
- }
-
- private void ClearWritersWaiting()
- {
- _owners &= ~WAITING_WRITERS;
- }
-
- private void SetUpgraderWaiting()
- {
- _owners |= WAITING_UPGRADER;
- }
-
- private void ClearUpgraderWaiting()
- {
- _owners &= ~WAITING_UPGRADER;
- }
-
- private uint GetNumReaders()
- {
- return _owners & READER_MASK;
- }
-
- private bool ShouldSpinForEnterAnyRead()
- {
- // If there is a write waiter or write upgrade waiter, the waiter would block a reader from acquiring the RW lock
- // because the waiter takes precedence. In that case, the reader is not likely to make progress by spinning.
- // Although another thread holding a write lock would prevent this thread from acquiring a read lock, it is by
- // itself not a good enough reason to skip spinning.
- return HasNoWaiters || (_numWriteWaiters == 0 && _numWriteUpgradeWaiters == 0);
- }
-
- private bool ShouldSpinForEnterAnyWrite(bool isUpgradeToWrite)
- {
- // If there is a write upgrade waiter, the waiter would block a writer from acquiring the RW lock because the waiter
- // holds a read lock. In that case, the writer is not likely to make progress by spinning. Regarding upgrading to a
- // write lock, there is no type of waiter that would block the upgrade from happening. Although another thread
- // holding a read or write lock would prevent this thread from acquiring the write lock, it is by itself not a good
- // enough reason to skip spinning.
- return isUpgradeToWrite || _numWriteUpgradeWaiters == 0;
- }
-
- private static void SpinWait(int spinCount)
- {
- const int LockSpinCycles = 20;
-
- // Exponential back-off
- if ((spinCount < 5) && (Environment.ProcessorCount > 1))
- {
- Thread.SpinWait(LockSpinCycles * spinCount);
- }
- else
- {
- Thread.Sleep(0);
- }
-
- // Don't want to Sleep(1) in this spin wait:
- // - Don't want to spin for that long, since a proper wait will follow when the spin wait fails. The artificial
- // delay introduced by Sleep(1) will in some cases be much longer than desired.
- // - Sleep(1) would put the thread into a wait state, and a proper wait will follow when the spin wait fails
- // anyway, so it's preferable to put the thread into the proper wait state
- }
-
- public void Dispose()
- {
- Dispose(true);
- }
-
- private void Dispose(bool disposing)
- {
- if (disposing && !_fDisposed)
- {
- if (WaitingReadCount > 0 || WaitingUpgradeCount > 0 || WaitingWriteCount > 0)
- throw new SynchronizationLockException(SR.SynchronizationLockException_IncorrectDispose);
-
- if (IsReadLockHeld || IsUpgradeableReadLockHeld || IsWriteLockHeld)
- throw new SynchronizationLockException(SR.SynchronizationLockException_IncorrectDispose);
-
- if (_writeEvent != null)
- {
- _writeEvent.Dispose();
- _writeEvent = null;
- }
-
- if (_readEvent != null)
- {
- _readEvent.Dispose();
- _readEvent = null;
- }
-
- if (_upgradeEvent != null)
- {
- _upgradeEvent.Dispose();
- _upgradeEvent = null;
- }
-
- if (_waitUpgradeEvent != null)
- {
- _waitUpgradeEvent.Dispose();
- _waitUpgradeEvent = null;
- }
-
- _fDisposed = true;
- }
- }
-
- public bool IsReadLockHeld
- {
- get
- {
- if (RecursiveReadCount > 0)
- return true;
- else
- return false;
- }
- }
-
- public bool IsUpgradeableReadLockHeld
- {
- get
- {
- if (RecursiveUpgradeCount > 0)
- return true;
- else
- return false;
- }
- }
-
- public bool IsWriteLockHeld
- {
- get
- {
- if (RecursiveWriteCount > 0)
- return true;
- else
- return false;
- }
- }
-
- public LockRecursionPolicy RecursionPolicy
- {
- get
- {
- if (_fIsReentrant)
- {
- return LockRecursionPolicy.SupportsRecursion;
- }
- else
- {
- return LockRecursionPolicy.NoRecursion;
- }
- }
- }
-
- public int CurrentReadCount
- {
- get
- {
- int numreaders = (int)GetNumReaders();
-
- if (_upgradeLockOwnerId != -1)
- return numreaders - 1;
- else
- return numreaders;
- }
- }
-
-
- public int RecursiveReadCount
- {
- get
- {
- int count = 0;
- ReaderWriterCount? lrwc = GetThreadRWCount(dontAllocate: true);
- if (lrwc != null)
- count = lrwc.readercount;
-
- return count;
- }
- }
-
- public int RecursiveUpgradeCount
- {
- get
- {
- if (_fIsReentrant)
- {
- int count = 0;
-
- ReaderWriterCount? lrwc = GetThreadRWCount(dontAllocate: true);
- if (lrwc != null)
- count = lrwc.upgradecount;
-
- return count;
- }
- else
- {
- if (Environment.CurrentManagedThreadId == _upgradeLockOwnerId)
- return 1;
- else
- return 0;
- }
- }
- }
-
- public int RecursiveWriteCount
- {
- get
- {
- if (_fIsReentrant)
- {
- int count = 0;
-
- ReaderWriterCount? lrwc = GetThreadRWCount(dontAllocate: true);
- if (lrwc != null)
- count = lrwc.writercount;
-
- return count;
- }
- else
- {
- if (Environment.CurrentManagedThreadId == _writeLockOwnerId)
- return 1;
- else
- return 0;
- }
- }
- }
-
- public int WaitingReadCount => (int)_numReadWaiters;
-
- public int WaitingUpgradeCount => (int)_numUpgradeWaiters;
-
- public int WaitingWriteCount => (int)_numWriteWaiters;
-
- private struct SpinLock
- {
- private int _isLocked;
-
- /// <summary>
- /// Used to deprioritize threads attempting to enter the lock when they would not make progress after doing so.
- /// <see cref="EnterSpin(EnterSpinLockReason)"/> avoids acquiring the lock as long as the operation for which it
- /// was called is deprioritized.
- ///
- /// Layout:
- /// - Low 16 bits: Number of threads that have deprioritized an enter-any-write operation
- /// - High 16 bits: Number of threads that have deprioritized an enter-any-read operation
- /// </summary>
- private int _enterDeprioritizationState;
-
- // Layout-specific constants for _enterDeprioritizationState
- private const int DeprioritizeEnterAnyReadIncrement = 1 << 16;
- private const int DeprioritizeEnterAnyWriteIncrement = 1;
-
- // The variables controlling spinning behavior of this spin lock
- private const int LockSpinCycles = 20;
- private const int LockSpinCount = 10;
- private const int LockSleep0Count = 5;
- private const int DeprioritizedLockSleep1Count = 5;
-
- private static int GetEnterDeprioritizationStateChange(EnterSpinLockReason reason)
- {
- EnterSpinLockReason operation = reason & EnterSpinLockReason.OperationMask;
- switch (operation)
- {
- case EnterSpinLockReason.EnterAnyRead:
- return 0;
-
- case EnterSpinLockReason.ExitAnyRead:
- // A read lock is held until this thread is able to exit it, so deprioritize enter-write threads as they
- // will not be able to make progress
- return DeprioritizeEnterAnyWriteIncrement;
-
- case EnterSpinLockReason.EnterWrite:
- // Writers are typically much less frequent and much less in number than readers. Waiting writers take
- // precedence over new read attempts in order to let current readers release their lock and allow a
- // writer to obtain the lock. Before a writer can register as a waiter though, the presence of just
- // relatively few enter-read spins can easily starve the enter-write from even entering this lock,
- // delaying its spin loop for an unreasonable duration.
- //
- // Deprioritize enter-read to preference enter-write. This makes it easier for enter-write threads to
- // starve enter-read threads. However, writers can already by design starve readers. A waiting writer
- // blocks enter-read threads and a new enter-write that needs to wait will be given precedence over
- // previously waiting enter-read threads. So this is not a new problem, and the RW lock is designed for
- // scenarios where writers are rare compared to readers.
- return DeprioritizeEnterAnyReadIncrement;
-
- default:
- Debug.Assert(
- operation == EnterSpinLockReason.UpgradeToWrite ||
- operation == EnterSpinLockReason.EnterRecursiveWrite ||
- operation == EnterSpinLockReason.ExitAnyWrite);
-
- // UpgradeToWrite:
- // - A read lock is held and an exit-read is not nearby, so deprioritize enter-write threads as they
- // will not be able to make progress. This thread also intends to enter a write lock, so deprioritize
- // enter -read threads as well, see case EnterSpinLockReason.EnterWrite for the rationale.
- // EnterRecursiveWrite, ExitAnyWrite:
- // - In both cases, a write lock is held until this thread is able to exit it, so deprioritize
- // enter -read and enter-write threads as they will not be able to make progress
- return DeprioritizeEnterAnyReadIncrement + DeprioritizeEnterAnyWriteIncrement;
- }
- }
-
- private ushort EnterForEnterAnyReadDeprioritizedCount
- {
- get
- {
- Debug.Assert(DeprioritizeEnterAnyReadIncrement == (1 << 16));
- return (ushort)((uint)_enterDeprioritizationState >> 16);
- }
- }
-
- private ushort EnterForEnterAnyWriteDeprioritizedCount
- {
- get
- {
- Debug.Assert(DeprioritizeEnterAnyWriteIncrement == 1);
- return (ushort)_enterDeprioritizationState;
- }
- }
-
- private bool IsEnterDeprioritized(EnterSpinLockReason reason)
- {
- Debug.Assert((reason & EnterSpinLockReason.Wait) != 0 || reason == (reason & EnterSpinLockReason.OperationMask));
- Debug.Assert(
- (reason & EnterSpinLockReason.Wait) == 0 ||
- (reason & EnterSpinLockReason.OperationMask) == EnterSpinLockReason.EnterAnyRead ||
- (reason & EnterSpinLockReason.OperationMask) == EnterSpinLockReason.EnterWrite ||
- (reason & EnterSpinLockReason.OperationMask) == EnterSpinLockReason.UpgradeToWrite);
-
- switch (reason)
- {
- default:
- Debug.Assert(
- (reason & EnterSpinLockReason.Wait) != 0 ||
- reason == EnterSpinLockReason.ExitAnyRead ||
- reason == EnterSpinLockReason.EnterRecursiveWrite ||
- reason == EnterSpinLockReason.ExitAnyWrite);
- return false;
-
- case EnterSpinLockReason.EnterAnyRead:
- return EnterForEnterAnyReadDeprioritizedCount != 0;
-
- case EnterSpinLockReason.EnterWrite:
- Debug.Assert((GetEnterDeprioritizationStateChange(reason) & DeprioritizeEnterAnyWriteIncrement) == 0);
- return EnterForEnterAnyWriteDeprioritizedCount != 0;
-
- case EnterSpinLockReason.UpgradeToWrite:
- Debug.Assert((GetEnterDeprioritizationStateChange(reason) & DeprioritizeEnterAnyWriteIncrement) != 0);
- return EnterForEnterAnyWriteDeprioritizedCount > 1;
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private bool TryEnter()
- {
- return Interlocked.CompareExchange(ref _isLocked, 1, 0) == 0;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Enter(EnterSpinLockReason reason)
- {
- if (!TryEnter())
- {
- EnterSpin(reason);
- }
- }
-
- private void EnterSpin(EnterSpinLockReason reason)
- {
- int deprioritizationStateChange = GetEnterDeprioritizationStateChange(reason);
- if (deprioritizationStateChange != 0)
- {
- Interlocked.Add(ref _enterDeprioritizationState, deprioritizationStateChange);
- }
-
- int processorCount = Environment.ProcessorCount;
- for (int spinIndex = 0; ; spinIndex++)
- {
- if (spinIndex < LockSpinCount && processorCount > 1)
- {
- Thread.SpinWait(LockSpinCycles * (spinIndex + 1)); // Wait a few dozen instructions to let another processor release lock.
- }
- else if (spinIndex < (LockSpinCount + LockSleep0Count))
- {
- Thread.Sleep(0); // Give up my quantum.
- }
- else
- {
- Thread.Sleep(1); // Give up my quantum.
- }
-
- if (!IsEnterDeprioritized(reason))
- {
- if (_isLocked == 0 && TryEnter())
- {
- if (deprioritizationStateChange != 0)
- {
- Interlocked.Add(ref _enterDeprioritizationState, -deprioritizationStateChange);
- }
- return;
- }
- continue;
- }
-
- // It's possible for an Enter thread to be deprioritized for an extended duration. It's undesirable for a
- // deprioritized thread to keep waking up to spin despite a Sleep(1) when a large number of such threads are
- // involved. After a threshold of Sleep(1)s, ignore the deprioritization and enter this lock to allow this
- // thread to stop spinning and hopefully enter a proper wait state.
- Debug.Assert(
- reason == EnterSpinLockReason.EnterAnyRead ||
- reason == EnterSpinLockReason.EnterWrite ||
- reason == EnterSpinLockReason.UpgradeToWrite);
- if (spinIndex >= (LockSpinCount + LockSleep0Count + DeprioritizedLockSleep1Count))
- {
- reason |= EnterSpinLockReason.Wait;
- spinIndex = -1;
- }
- }
- }
-
- public void Exit()
- {
- Debug.Assert(_isLocked != 0, "Exiting spin lock that is not held");
- Volatile.Write(ref _isLocked, 0);
- }
-
-#if DEBUG
- public bool IsHeld => _isLocked != 0;
-#endif
- }
-
- [Flags]
- private enum WaiterStates : byte
- {
- None = 0x0,
-
- // Used for quick check when there are no waiters
- NoWaiters = 0x1,
-
- // Used to avoid signaling more than one waiter to wake up when only one can make progress, see WaitOnEvent
- WriteWaiterSignaled = 0x2,
- UpgradeableReadWaiterSignaled = 0x4
- // Write upgrade waiters are excluded because there can only be one at any given time
- }
-
- private enum EnterSpinLockReason
- {
- EnterAnyRead = 0,
- ExitAnyRead = 1,
- EnterWrite = 2,
- UpgradeToWrite = 3,
- EnterRecursiveWrite = 4,
- ExitAnyWrite = 5,
-
- OperationMask = 0x7,
-
- Wait = 0x8
- }
-
- private enum EnterLockType
- {
- Read,
- UpgradeableRead,
- Write,
- UpgradeToWrite
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Semaphore.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Semaphore.Windows.cs
deleted file mode 100644
index 0d17f79bdaa..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Semaphore.Windows.cs
+++ /dev/null
@@ -1,88 +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.Diagnostics;
-using System.IO;
-using System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- public sealed partial class Semaphore
- {
- private const uint AccessRights = (uint)Interop.Kernel32.MAXIMUM_ALLOWED | Interop.Kernel32.SYNCHRONIZE | Interop.Kernel32.SEMAPHORE_MODIFY_STATE;
-
- private Semaphore(SafeWaitHandle handle)
- {
- SafeWaitHandle = handle;
- }
-
- private void CreateSemaphoreCore(int initialCount, int maximumCount, string? name, out bool createdNew)
- {
- Debug.Assert(initialCount >= 0);
- Debug.Assert(maximumCount >= 1);
- Debug.Assert(initialCount <= maximumCount);
-
-#if !PLATFORM_WINDOWS
- if (name != null)
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives);
-#endif
- SafeWaitHandle myHandle = Interop.Kernel32.CreateSemaphoreEx(IntPtr.Zero, initialCount, maximumCount, name, 0, AccessRights);
-
- int errorCode = Marshal.GetLastWin32Error();
- if (myHandle.IsInvalid)
- {
- if (!string.IsNullOrEmpty(name) && errorCode == Interop.Errors.ERROR_INVALID_HANDLE)
- throw new WaitHandleCannotBeOpenedException(
- SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));
-
- throw Win32Marshal.GetExceptionForLastWin32Error();
- }
- createdNew = errorCode != Interop.Errors.ERROR_ALREADY_EXISTS;
- this.SafeWaitHandle = myHandle;
- }
-
- private static OpenExistingResult OpenExistingWorker(string name, out Semaphore? result)
- {
-#if PLATFORM_WINDOWS
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- if (name.Length == 0)
- throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
-
- // Pass false to OpenSemaphore to prevent inheritedHandles
- SafeWaitHandle myHandle = Interop.Kernel32.OpenSemaphore(AccessRights, false, name);
-
- if (myHandle.IsInvalid)
- {
- result = null;
- int errorCode = Marshal.GetLastWin32Error();
-
- if (errorCode == Interop.Errors.ERROR_FILE_NOT_FOUND || errorCode == Interop.Errors.ERROR_INVALID_NAME)
- return OpenExistingResult.NameNotFound;
- if (errorCode == Interop.Errors.ERROR_PATH_NOT_FOUND)
- return OpenExistingResult.PathNotFound;
- if (!string.IsNullOrEmpty(name) && errorCode == Interop.Errors.ERROR_INVALID_HANDLE)
- return OpenExistingResult.NameInvalid;
- // this is for passed through NativeMethods Errors
- throw Win32Marshal.GetExceptionForLastWin32Error();
- }
-
- result = new Semaphore(myHandle);
- return OpenExistingResult.Success;
-#else
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives);
-#endif
- }
-
- private int ReleaseCore(int releaseCount)
- {
- int previousCount;
- if (!Interop.Kernel32.ReleaseSemaphore(SafeWaitHandle!, releaseCount, out previousCount))
- throw new SemaphoreFullException();
-
- return previousCount;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Semaphore.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Semaphore.cs
deleted file mode 100644
index 94ed6150210..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Semaphore.cs
+++ /dev/null
@@ -1,67 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.IO;
-
-namespace System.Threading
-{
- public sealed partial class Semaphore : WaitHandle
- {
- // creates a nameless semaphore object
- // Win32 only takes maximum count of int.MaxValue
- public Semaphore(int initialCount, int maximumCount) : this(initialCount, maximumCount, null) { }
-
- public Semaphore(int initialCount, int maximumCount, string? name) :
- this(initialCount, maximumCount, name, out _)
- {
- }
-
- public Semaphore(int initialCount, int maximumCount, string? name, out bool createdNew)
- {
- if (initialCount < 0)
- throw new ArgumentOutOfRangeException(nameof(initialCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (maximumCount < 1)
- throw new ArgumentOutOfRangeException(nameof(maximumCount), SR.ArgumentOutOfRange_NeedPosNum);
-
- if (initialCount > maximumCount)
- throw new ArgumentException(SR.Argument_SemaphoreInitialMaximum);
-
- CreateSemaphoreCore(initialCount, maximumCount, name, out createdNew);
- }
-
- public static Semaphore OpenExisting(string name)
- {
- Semaphore? result;
- switch (OpenExistingWorker(name, out result))
- {
- case OpenExistingResult.NameNotFound:
- throw new WaitHandleCannotBeOpenedException();
- case OpenExistingResult.NameInvalid:
- throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));
- case OpenExistingResult.PathNotFound:
- throw new IOException(SR.Format(SR.IO_PathNotFound_Path, name));
- default:
- Debug.Assert(result != null, "result should be non-null on success");
- return result;
- }
- }
-
- public static bool TryOpenExisting(string name, [NotNullWhen(true)] out Semaphore? result) =>
- OpenExistingWorker(name, out result) == OpenExistingResult.Success;
-
- public int Release() => ReleaseCore(1);
-
- // increase the count on a semaphore, returns previous count
- public int Release(int releaseCount)
- {
- if (releaseCount < 1)
- throw new ArgumentOutOfRangeException(nameof(releaseCount), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- return ReleaseCore(releaseCount);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/SemaphoreFullException.cs b/netcore/System.Private.CoreLib/shared/System/Threading/SemaphoreFullException.cs
deleted file mode 100644
index f79cdb8927f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/SemaphoreFullException.cs
+++ /dev/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 System.Runtime.Serialization;
-
-namespace System.Threading
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class SemaphoreFullException : SystemException
- {
- public SemaphoreFullException() : base(SR.Threading_SemaphoreFullException)
- {
- }
-
- public SemaphoreFullException(string? message) : base(message)
- {
- }
-
- public SemaphoreFullException(string? message, Exception? innerException) : base(message, innerException)
- {
- }
-
- protected SemaphoreFullException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/SemaphoreSlim.cs b/netcore/System.Private.CoreLib/shared/System/Threading/SemaphoreSlim.cs
deleted file mode 100644
index 03af031bb4c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/SemaphoreSlim.cs
+++ /dev/null
@@ -1,937 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Threading.Tasks;
-
-namespace System.Threading
-{
- /// <summary>
- /// Limits the number of threads that can access a resource or pool of resources concurrently.
- /// </summary>
- /// <remarks>
- /// <para>
- /// The <see cref="SemaphoreSlim"/> provides a lightweight semaphore class that doesn't
- /// use Windows kernel semaphores.
- /// </para>
- /// <para>
- /// All public and protected members of <see cref="SemaphoreSlim"/> are thread-safe and may be used
- /// concurrently from multiple threads, with the exception of Dispose, which
- /// must only be used when all other operations on the <see cref="SemaphoreSlim"/> have
- /// completed.
- /// </para>
- /// </remarks>
- [DebuggerDisplay("Current Count = {m_currentCount}")]
- public class SemaphoreSlim : IDisposable
- {
- #region Private Fields
-
- // The semaphore count, initialized in the constructor to the initial value, every release call incremetns it
- // and every wait call decrements it as long as its value is positive otherwise the wait will block.
- // Its value must be between the maximum semaphore value and zero
- private volatile int m_currentCount;
-
- // The maximum semaphore value, it is initialized to Int.MaxValue if the client didn't specify it. it is used
- // to check if the count excceeded the maxi value or not.
- private readonly int m_maxCount;
-
- // The number of synchronously waiting threads, it is set to zero in the constructor and increments before blocking the
- // threading and decrements it back after that. It is used as flag for the release call to know if there are
- // waiting threads in the monitor or not.
- private int m_waitCount;
-
- /// <summary>
- /// This is used to help prevent waking more waiters than necessary. It's not perfect and sometimes more waiters than
- /// necessary may still be woken, see <see cref="WaitUntilCountOrTimeout"/>.
- /// </summary>
- private int m_countOfWaitersPulsedToWake;
-
- // Object used to synchronize access to state on the instance. The contained
- // Boolean value indicates whether the instance has been disposed.
- private readonly StrongBox<bool> m_lockObjAndDisposed;
-
- // Act as the semaphore wait handle, it's lazily initialized if needed, the first WaitHandle call initialize it
- // and wait an release sets and resets it respectively as long as it is not null
- private volatile ManualResetEvent? m_waitHandle;
-
- // Head of list representing asynchronous waits on the semaphore.
- private TaskNode? m_asyncHead;
-
- // Tail of list representing asynchronous waits on the semaphore.
- private TaskNode? m_asyncTail;
-
- // A pre-completed task with Result==true
- private static readonly Task<bool> s_trueTask =
- new Task<bool>(false, true, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default);
- // A pre-completed task with Result==false
- private static readonly Task<bool> s_falseTask =
- new Task<bool>(false, false, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default);
-
- // No maximum constant
- private const int NO_MAXIMUM = int.MaxValue;
-
- // Task in a linked list of asynchronous waiters
- private sealed class TaskNode : Task<bool>
- {
- internal TaskNode? Prev, Next;
- internal TaskNode() : base((object?)null, TaskCreationOptions.RunContinuationsAsynchronously) { }
- }
- #endregion
-
- #region Public properties
-
- /// <summary>
- /// Gets the current count of the <see cref="SemaphoreSlim"/>.
- /// </summary>
- /// <value>The current count of the <see cref="SemaphoreSlim"/>.</value>
- public int CurrentCount => m_currentCount;
-
- /// <summary>
- /// Returns a <see cref="System.Threading.WaitHandle"/> that can be used to wait on the semaphore.
- /// </summary>
- /// <value>A <see cref="System.Threading.WaitHandle"/> that can be used to wait on the
- /// semaphore.</value>
- /// <remarks>
- /// A successful wait on the <see cref="AvailableWaitHandle"/> does not imply a successful wait on
- /// the <see cref="SemaphoreSlim"/> itself, nor does it decrement the semaphore's
- /// count. <see cref="AvailableWaitHandle"/> exists to allow a thread to block waiting on multiple
- /// semaphores, but such a wait should be followed by a true wait on the target semaphore.
- /// </remarks>
- /// <exception cref="System.ObjectDisposedException">The <see
- /// cref="SemaphoreSlim"/> has been disposed.</exception>
- public WaitHandle AvailableWaitHandle
- {
- get
- {
- CheckDispose();
-
- // Return it directly if it is not null
- if (m_waitHandle != null)
- return m_waitHandle;
-
- // lock the count to avoid multiple threads initializing the handle if it is null
- lock (m_lockObjAndDisposed)
- {
- if (m_waitHandle == null)
- {
- // The initial state for the wait handle is true if the count is greater than zero
- // false otherwise
- m_waitHandle = new ManualResetEvent(m_currentCount != 0);
- }
- }
- return m_waitHandle;
- }
- }
-
- #endregion
-
- #region Constructors
- /// <summary>
- /// Initializes a new instance of the <see cref="SemaphoreSlim"/> class, specifying
- /// the initial number of requests that can be granted concurrently.
- /// </summary>
- /// <param name="initialCount">The initial number of requests for the semaphore that can be granted
- /// concurrently.</param>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="initialCount"/>
- /// is less than 0.</exception>
- public SemaphoreSlim(int initialCount)
- : this(initialCount, NO_MAXIMUM)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="SemaphoreSlim"/> class, specifying
- /// the initial and maximum number of requests that can be granted concurrently.
- /// </summary>
- /// <param name="initialCount">The initial number of requests for the semaphore that can be granted
- /// concurrently.</param>
- /// <param name="maxCount">The maximum number of requests for the semaphore that can be granted
- /// concurrently.</param>
- /// <exception cref="System.ArgumentOutOfRangeException"> <paramref name="initialCount"/>
- /// is less than 0. -or-
- /// <paramref name="initialCount"/> is greater than <paramref name="maxCount"/>. -or-
- /// <paramref name="maxCount"/> is less than 0.</exception>
- public SemaphoreSlim(int initialCount, int maxCount)
- {
- if (initialCount < 0 || initialCount > maxCount)
- {
- throw new ArgumentOutOfRangeException(
- nameof(initialCount), initialCount, SR.SemaphoreSlim_ctor_InitialCountWrong);
- }
-
- // validate input
- if (maxCount <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(maxCount), maxCount, SR.SemaphoreSlim_ctor_MaxCountWrong);
- }
-
- m_maxCount = maxCount;
- m_currentCount = initialCount;
- m_lockObjAndDisposed = new StrongBox<bool>();
- }
-
- #endregion
-
- #region Methods
- /// <summary>
- /// Blocks the current thread until it can enter the <see cref="SemaphoreSlim"/>.
- /// </summary>
- /// <exception cref="System.ObjectDisposedException">The current instance has already been
- /// disposed.</exception>
- public void Wait()
- {
- // Call wait with infinite timeout
- Wait(Timeout.Infinite, CancellationToken.None);
- }
-
- /// <summary>
- /// Blocks the current thread until it can enter the <see cref="SemaphoreSlim"/>, while observing a
- /// <see cref="System.Threading.CancellationToken"/>.
- /// </summary>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> token to
- /// observe.</param>
- /// <exception cref="System.OperationCanceledException"><paramref name="cancellationToken"/> was
- /// canceled.</exception>
- /// <exception cref="System.ObjectDisposedException">The current instance has already been
- /// disposed.</exception>
- public void Wait(CancellationToken cancellationToken)
- {
- // Call wait with infinite timeout
- Wait(Timeout.Infinite, cancellationToken);
- }
-
- /// <summary>
- /// Blocks the current thread until it can enter the <see cref="SemaphoreSlim"/>, using a <see
- /// cref="System.TimeSpan"/> to measure the time interval.
- /// </summary>
- /// <param name="timeout">A <see cref="System.TimeSpan"/> that represents the number of milliseconds
- /// to wait, or a <see cref="System.TimeSpan"/> that represents -1 milliseconds to wait indefinitely.
- /// </param>
- /// <returns>true if the current thread successfully entered the <see cref="SemaphoreSlim"/>;
- /// otherwise, false.</returns>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="timeout"/> is a negative
- /// number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater
- /// than <see cref="int.MaxValue"/>.</exception>
- public bool Wait(TimeSpan timeout)
- {
- // Validate the timeout
- long totalMilliseconds = (long)timeout.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- throw new System.ArgumentOutOfRangeException(
- nameof(timeout), timeout, SR.SemaphoreSlim_Wait_TimeoutWrong);
- }
-
- // Call wait with the timeout milliseconds
- return Wait((int)timeout.TotalMilliseconds, CancellationToken.None);
- }
-
- /// <summary>
- /// Blocks the current thread until it can enter the <see cref="SemaphoreSlim"/>, using a <see
- /// cref="System.TimeSpan"/> to measure the time interval, while observing a <see
- /// cref="System.Threading.CancellationToken"/>.
- /// </summary>
- /// <param name="timeout">A <see cref="System.TimeSpan"/> that represents the number of milliseconds
- /// to wait, or a <see cref="System.TimeSpan"/> that represents -1 milliseconds to wait indefinitely.
- /// </param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> to
- /// observe.</param>
- /// <returns>true if the current thread successfully entered the <see cref="SemaphoreSlim"/>;
- /// otherwise, false.</returns>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="timeout"/> is a negative
- /// number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater
- /// than <see cref="int.MaxValue"/>.</exception>
- /// <exception cref="System.OperationCanceledException"><paramref name="cancellationToken"/> was canceled.</exception>
- public bool Wait(TimeSpan timeout, CancellationToken cancellationToken)
- {
- // Validate the timeout
- long totalMilliseconds = (long)timeout.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- throw new System.ArgumentOutOfRangeException(
- nameof(timeout), timeout, SR.SemaphoreSlim_Wait_TimeoutWrong);
- }
-
- // Call wait with the timeout milliseconds
- return Wait((int)timeout.TotalMilliseconds, cancellationToken);
- }
-
- /// <summary>
- /// Blocks the current thread until it can enter the <see cref="SemaphoreSlim"/>, using a 32-bit
- /// signed integer to measure the time interval.
- /// </summary>
- /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see
- /// cref="Timeout.Infinite"/>(-1) to wait indefinitely.</param>
- /// <returns>true if the current thread successfully entered the <see cref="SemaphoreSlim"/>;
- /// otherwise, false.</returns>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is a
- /// negative number other than -1, which represents an infinite time-out.</exception>
- public bool Wait(int millisecondsTimeout)
- {
- return Wait(millisecondsTimeout, CancellationToken.None);
- }
-
- /// <summary>
- /// Blocks the current thread until it can enter the <see cref="SemaphoreSlim"/>,
- /// using a 32-bit signed integer to measure the time interval,
- /// while observing a <see cref="System.Threading.CancellationToken"/>.
- /// </summary>
- /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see cref="Timeout.Infinite"/>(-1) to
- /// wait indefinitely.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> to observe.</param>
- /// <returns>true if the current thread successfully entered the <see cref="SemaphoreSlim"/>; otherwise, false.</returns>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is a negative number other than -1,
- /// which represents an infinite time-out.</exception>
- /// <exception cref="System.OperationCanceledException"><paramref name="cancellationToken"/> was canceled.</exception>
- public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
- {
- CheckDispose();
-
- // Validate input
- if (millisecondsTimeout < -1)
- {
- throw new ArgumentOutOfRangeException(
- nameof(millisecondsTimeout), millisecondsTimeout, SR.SemaphoreSlim_Wait_TimeoutWrong);
- }
-
- cancellationToken.ThrowIfCancellationRequested();
-
- // Perf: Check the stack timeout parameter before checking the volatile count
- if (millisecondsTimeout == 0 && m_currentCount == 0)
- {
- // Pessimistic fail fast, check volatile count outside lock (only when timeout is zero!)
- return false;
- }
-
- uint startTime = 0;
- if (millisecondsTimeout != Timeout.Infinite && millisecondsTimeout > 0)
- {
- startTime = TimeoutHelper.GetTime();
- }
-
- bool waitSuccessful = false;
- Task<bool>? asyncWaitTask = null;
- bool lockTaken = false;
-
- // Register for cancellation outside of the main lock.
- // NOTE: Register/unregister inside the lock can deadlock as different lock acquisition orders could
- // occur for (1)this.m_lockObjAndDisposed and (2)cts.internalLock
- CancellationTokenRegistration cancellationTokenRegistration = cancellationToken.UnsafeRegister(s_cancellationTokenCanceledEventHandler, this);
- try
- {
- // Perf: first spin wait for the count to be positive.
- // This additional amount of spinwaiting in addition
- // to Monitor.Enter()'s spinwaiting has shown measurable perf gains in test scenarios.
- if (m_currentCount == 0)
- {
- // Monitor.Enter followed by Monitor.Wait is much more expensive than waiting on an event as it involves another
- // spin, contention, etc. The usual number of spin iterations that would otherwise be used here is increased to
- // lessen that extra expense of doing a proper wait.
- int spinCount = SpinWait.SpinCountforSpinBeforeWait * 4;
-
- SpinWait spinner = default;
- while (spinner.Count < spinCount)
- {
- spinner.SpinOnce(sleep1Threshold: -1);
-
- if (m_currentCount != 0)
- {
- break;
- }
- }
- }
- // entering the lock and incrementing waiters must not suffer a thread-abort, else we cannot
- // clean up m_waitCount correctly, which may lead to deadlock due to non-woken waiters.
- try { }
- finally
- {
- Monitor.Enter(m_lockObjAndDisposed, ref lockTaken);
- if (lockTaken)
- {
- m_waitCount++;
- }
- }
-
- // If there are any async waiters, for fairness we'll get in line behind
- // then by translating our synchronous wait into an asynchronous one that we
- // then block on (once we've released the lock).
- if (m_asyncHead != null)
- {
- Debug.Assert(m_asyncTail != null, "tail should not be null if head isn't");
- asyncWaitTask = WaitAsync(millisecondsTimeout, cancellationToken);
- }
- // There are no async waiters, so we can proceed with normal synchronous waiting.
- else
- {
- // If the count > 0 we are good to move on.
- // If not, then wait if we were given allowed some wait duration
-
- OperationCanceledException? oce = null;
-
- if (m_currentCount == 0)
- {
- if (millisecondsTimeout == 0)
- {
- return false;
- }
-
- // Prepare for the main wait...
- // wait until the count become greater than zero or the timeout is expired
- try
- {
- waitSuccessful = WaitUntilCountOrTimeout(millisecondsTimeout, startTime, cancellationToken);
- }
- catch (OperationCanceledException e) { oce = e; }
- }
-
- // Now try to acquire. We prioritize acquisition over cancellation/timeout so that we don't
- // lose any counts when there are asynchronous waiters in the mix. Asynchronous waiters
- // defer to synchronous waiters in priority, which means that if it's possible an asynchronous
- // waiter didn't get released because a synchronous waiter was present, we need to ensure
- // that synchronous waiter succeeds so that they have a chance to release.
- Debug.Assert(!waitSuccessful || m_currentCount > 0,
- "If the wait was successful, there should be count available.");
- if (m_currentCount > 0)
- {
- waitSuccessful = true;
- m_currentCount--;
- }
- else if (oce != null)
- {
- throw oce;
- }
-
- // Exposing wait handle which is lazily initialized if needed
- if (m_waitHandle != null && m_currentCount == 0)
- {
- m_waitHandle.Reset();
- }
- }
- }
- finally
- {
- // Release the lock
- if (lockTaken)
- {
- m_waitCount--;
- Monitor.Exit(m_lockObjAndDisposed);
- }
-
- // Unregister the cancellation callback.
- cancellationTokenRegistration.Dispose();
- }
-
- // If we had to fall back to asynchronous waiting, block on it
- // here now that we've released the lock, and return its
- // result when available. Otherwise, this was a synchronous
- // wait, and whether we successfully acquired the semaphore is
- // stored in waitSuccessful.
-
- return (asyncWaitTask != null) ? asyncWaitTask.GetAwaiter().GetResult() : waitSuccessful;
- }
-
- /// <summary>
- /// Local helper function, waits on the monitor until the monitor receives signal or the
- /// timeout is expired
- /// </summary>
- /// <param name="millisecondsTimeout">The maximum timeout</param>
- /// <param name="startTime">The start ticks to calculate the elapsed time</param>
- /// <param name="cancellationToken">The CancellationToken to observe.</param>
- /// <returns>true if the monitor received a signal, false if the timeout expired</returns>
- private bool WaitUntilCountOrTimeout(int millisecondsTimeout, uint startTime, CancellationToken cancellationToken)
- {
- int remainingWaitMilliseconds = Timeout.Infinite;
-
- // Wait on the monitor as long as the count is zero
- while (m_currentCount == 0)
- {
- // If cancelled, we throw. Trying to wait could lead to deadlock.
- cancellationToken.ThrowIfCancellationRequested();
-
- if (millisecondsTimeout != Timeout.Infinite)
- {
- remainingWaitMilliseconds = TimeoutHelper.UpdateTimeOut(startTime, millisecondsTimeout);
- if (remainingWaitMilliseconds <= 0)
- {
- // The thread has expires its timeout
- return false;
- }
- }
- // ** the actual wait **
- bool waitSuccessful = Monitor.Wait(m_lockObjAndDisposed, remainingWaitMilliseconds);
-
- // This waiter has woken up and this needs to be reflected in the count of waiters pulsed to wake. Since we
- // don't have thread-specific pulse state, there is not enough information to tell whether this thread woke up
- // because it was pulsed. For instance, this thread may have timed out and may have been waiting to reacquire
- // the lock before returning from Monitor.Wait, in which case we don't know whether this thread got pulsed. So
- // in any woken case, decrement the count if possible. As such, timeouts could cause more waiters to wake than
- // necessary.
- if (m_countOfWaitersPulsedToWake != 0)
- {
- --m_countOfWaitersPulsedToWake;
- }
-
- if (!waitSuccessful)
- {
- return false;
- }
- }
-
- return true;
- }
-
- /// <summary>
- /// Asynchronously waits to enter the <see cref="SemaphoreSlim"/>.
- /// </summary>
- /// <returns>A task that will complete when the semaphore has been entered.</returns>
- public Task WaitAsync()
- {
- return WaitAsync(Timeout.Infinite, default);
- }
-
- /// <summary>
- /// Asynchronously waits to enter the <see cref="SemaphoreSlim"/>, while observing a
- /// <see cref="System.Threading.CancellationToken"/>.
- /// </summary>
- /// <returns>A task that will complete when the semaphore has been entered.</returns>
- /// <param name="cancellationToken">
- /// The <see cref="System.Threading.CancellationToken"/> token to observe.
- /// </param>
- /// <exception cref="System.ObjectDisposedException">
- /// The current instance has already been disposed.
- /// </exception>
- public Task WaitAsync(CancellationToken cancellationToken)
- {
- return WaitAsync(Timeout.Infinite, cancellationToken);
- }
-
- /// <summary>
- /// Asynchronously waits to enter the <see cref="SemaphoreSlim"/>,
- /// using a 32-bit signed integer to measure the time interval.
- /// </summary>
- /// <param name="millisecondsTimeout">
- /// The number of milliseconds to wait, or <see cref="Timeout.Infinite"/>(-1) to wait indefinitely.
- /// </param>
- /// <returns>
- /// A task that will complete with a result of true if the current thread successfully entered
- /// the <see cref="SemaphoreSlim"/>, otherwise with a result of false.
- /// </returns>
- /// <exception cref="System.ObjectDisposedException">The current instance has already been
- /// disposed.</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is a negative number other than -1,
- /// which represents an infinite time-out.
- /// </exception>
- public Task<bool> WaitAsync(int millisecondsTimeout)
- {
- return WaitAsync(millisecondsTimeout, default);
- }
-
- /// <summary>
- /// Asynchronously waits to enter the <see cref="SemaphoreSlim"/>, using a <see
- /// cref="System.TimeSpan"/> to measure the time interval, while observing a
- /// <see cref="System.Threading.CancellationToken"/>.
- /// </summary>
- /// <param name="timeout">
- /// A <see cref="System.TimeSpan"/> that represents the number of milliseconds
- /// to wait, or a <see cref="System.TimeSpan"/> that represents -1 milliseconds to wait indefinitely.
- /// </param>
- /// <returns>
- /// A task that will complete with a result of true if the current thread successfully entered
- /// the <see cref="SemaphoreSlim"/>, otherwise with a result of false.
- /// </returns>
- /// <exception cref="System.ObjectDisposedException">
- /// The current instance has already been disposed.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// <paramref name="timeout"/> is a negative number other than -1 milliseconds, which represents
- /// an infinite time-out -or- timeout is greater than <see cref="int.MaxValue"/>.
- /// </exception>
- public Task<bool> WaitAsync(TimeSpan timeout)
- {
- return WaitAsync(timeout, default);
- }
-
- /// <summary>
- /// Asynchronously waits to enter the <see cref="SemaphoreSlim"/>, using a <see
- /// cref="System.TimeSpan"/> to measure the time interval.
- /// </summary>
- /// <param name="timeout">
- /// A <see cref="System.TimeSpan"/> that represents the number of milliseconds
- /// to wait, or a <see cref="System.TimeSpan"/> that represents -1 milliseconds to wait indefinitely.
- /// </param>
- /// <param name="cancellationToken">
- /// The <see cref="System.Threading.CancellationToken"/> token to observe.
- /// </param>
- /// <returns>
- /// A task that will complete with a result of true if the current thread successfully entered
- /// the <see cref="SemaphoreSlim"/>, otherwise with a result of false.
- /// </returns>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// <paramref name="timeout"/> is a negative number other than -1 milliseconds, which represents
- /// an infinite time-out -or- timeout is greater than <see cref="int.MaxValue"/>.
- /// </exception>
- public Task<bool> WaitAsync(TimeSpan timeout, CancellationToken cancellationToken)
- {
- // Validate the timeout
- long totalMilliseconds = (long)timeout.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- throw new System.ArgumentOutOfRangeException(
- nameof(timeout), timeout, SR.SemaphoreSlim_Wait_TimeoutWrong);
- }
-
- // Call wait with the timeout milliseconds
- return WaitAsync((int)timeout.TotalMilliseconds, cancellationToken);
- }
-
- /// <summary>
- /// Asynchronously waits to enter the <see cref="SemaphoreSlim"/>,
- /// using a 32-bit signed integer to measure the time interval,
- /// while observing a <see cref="System.Threading.CancellationToken"/>.
- /// </summary>
- /// <param name="millisecondsTimeout">
- /// The number of milliseconds to wait, or <see cref="Timeout.Infinite"/>(-1) to wait indefinitely.
- /// </param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> to observe.</param>
- /// <returns>
- /// A task that will complete with a result of true if the current thread successfully entered
- /// the <see cref="SemaphoreSlim"/>, otherwise with a result of false.
- /// </returns>
- /// <exception cref="System.ObjectDisposedException">The current instance has already been
- /// disposed.</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is a negative number other than -1,
- /// which represents an infinite time-out.
- /// </exception>
- public Task<bool> WaitAsync(int millisecondsTimeout, CancellationToken cancellationToken)
- {
- CheckDispose();
-
- // Validate input
- if (millisecondsTimeout < -1)
- {
- throw new ArgumentOutOfRangeException(
- nameof(millisecondsTimeout), millisecondsTimeout, SR.SemaphoreSlim_Wait_TimeoutWrong);
- }
-
- // Bail early for cancellation
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled<bool>(cancellationToken);
-
- lock (m_lockObjAndDisposed)
- {
- // If there are counts available, allow this waiter to succeed.
- if (m_currentCount > 0)
- {
- --m_currentCount;
- if (m_waitHandle != null && m_currentCount == 0) m_waitHandle.Reset();
- return s_trueTask;
- }
- else if (millisecondsTimeout == 0)
- {
- // No counts, if timeout is zero fail fast
- return s_falseTask;
- }
- // If there aren't, create and return a task to the caller.
- // The task will be completed either when they've successfully acquired
- // the semaphore or when the timeout expired or cancellation was requested.
- else
- {
- Debug.Assert(m_currentCount == 0, "m_currentCount should never be negative");
- TaskNode asyncWaiter = CreateAndAddAsyncWaiter();
- return (millisecondsTimeout == Timeout.Infinite && !cancellationToken.CanBeCanceled) ?
- asyncWaiter :
- WaitUntilCountOrTimeoutAsync(asyncWaiter, millisecondsTimeout, cancellationToken);
- }
- }
- }
-
- /// <summary>Creates a new task and stores it into the async waiters list.</summary>
- /// <returns>The created task.</returns>
- private TaskNode CreateAndAddAsyncWaiter()
- {
- Debug.Assert(Monitor.IsEntered(m_lockObjAndDisposed), "Requires the lock be held");
-
- // Create the task
- var task = new TaskNode();
-
- // Add it to the linked list
- if (m_asyncHead == null)
- {
- Debug.Assert(m_asyncTail == null, "If head is null, so too should be tail");
- m_asyncHead = task;
- m_asyncTail = task;
- }
- else
- {
- Debug.Assert(m_asyncTail != null, "If head is not null, neither should be tail");
- m_asyncTail.Next = task;
- task.Prev = m_asyncTail;
- m_asyncTail = task;
- }
-
- // Hand it back
- return task;
- }
-
- /// <summary>Removes the waiter task from the linked list.</summary>
- /// <param name="task">The task to remove.</param>
- /// <returns>true if the waiter was in the list; otherwise, false.</returns>
- private bool RemoveAsyncWaiter(TaskNode task)
- {
- Debug.Assert(task != null, "Expected non-null task");
- Debug.Assert(Monitor.IsEntered(m_lockObjAndDisposed), "Requires the lock be held");
-
- // Is the task in the list? To be in the list, either it's the head or it has a predecessor that's in the list.
- bool wasInList = m_asyncHead == task || task.Prev != null;
-
- // Remove it from the linked list
- if (task.Next != null) task.Next.Prev = task.Prev;
- if (task.Prev != null) task.Prev.Next = task.Next;
- if (m_asyncHead == task) m_asyncHead = task.Next;
- if (m_asyncTail == task) m_asyncTail = task.Prev;
- Debug.Assert((m_asyncHead == null) == (m_asyncTail == null), "Head is null iff tail is null");
-
- // Make sure not to leak
- task.Next = task.Prev = null;
-
- // Return whether the task was in the list
- return wasInList;
- }
-
- /// <summary>Performs the asynchronous wait.</summary>
- /// <param name="asyncWaiter">The asynchronous waiter.</param>
- /// <param name="millisecondsTimeout">The timeout.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>The task to return to the caller.</returns>
- private async Task<bool> WaitUntilCountOrTimeoutAsync(TaskNode asyncWaiter, int millisecondsTimeout, CancellationToken cancellationToken)
- {
- Debug.Assert(asyncWaiter != null, "Waiter should have been constructed");
- Debug.Assert(Monitor.IsEntered(m_lockObjAndDisposed), "Requires the lock be held");
-
- if (millisecondsTimeout != Timeout.Infinite)
- {
- // Wait until either the task is completed, cancellation is requested, or the timeout occurs.
- // We need to ensure that the Task.Delay task is appropriately cleaned up if the await
- // completes due to the asyncWaiter completing, so we use our own token that we can explicitly
- // cancel, and we chain the caller's supplied token into it.
- using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, default))
- {
- if (asyncWaiter == await TaskFactory.CommonCWAnyLogic(new Task[] { asyncWaiter, Task.Delay(millisecondsTimeout, cts.Token) }).ConfigureAwait(false))
- {
- cts.Cancel(); // ensure that the Task.Delay task is cleaned up
- return true; // successfully acquired
- }
- }
- }
- else // millisecondsTimeout == Timeout.Infinite
- {
- // Wait until either the task is completed or cancellation is requested.
- var cancellationTask = new Task();
- using (cancellationToken.UnsafeRegister(s => ((Task)s!).TrySetResult(), cancellationTask))
- {
- if (asyncWaiter == await TaskFactory.CommonCWAnyLogic(new Task[] { asyncWaiter, cancellationTask }).ConfigureAwait(false))
- {
- return true; // successfully acquired
- }
- }
- }
-
- // If we get here, the wait has timed out or been canceled.
-
- // If the await completed synchronously, we still hold the lock. If it didn't,
- // we no longer hold the lock. As such, acquire it.
- lock (m_lockObjAndDisposed)
- {
- // Remove the task from the list. If we're successful in doing so,
- // we know that no one else has tried to complete this waiter yet,
- // so we can safely cancel or timeout.
- if (RemoveAsyncWaiter(asyncWaiter))
- {
- cancellationToken.ThrowIfCancellationRequested(); // cancellation occurred
- return false; // timeout occurred
- }
- }
-
- // The waiter had already been removed, which means it's already completed or is about to
- // complete, so let it, and don't return until it does.
- return await asyncWaiter.ConfigureAwait(false);
- }
-
- /// <summary>
- /// Exits the <see cref="SemaphoreSlim"/> once.
- /// </summary>
- /// <returns>The previous count of the <see cref="SemaphoreSlim"/>.</returns>
- /// <exception cref="System.ObjectDisposedException">The current instance has already been
- /// disposed.</exception>
- public int Release()
- {
- return Release(1);
- }
-
- /// <summary>
- /// Exits the <see cref="SemaphoreSlim"/> a specified number of times.
- /// </summary>
- /// <param name="releaseCount">The number of times to exit the semaphore.</param>
- /// <returns>The previous count of the <see cref="SemaphoreSlim"/>.</returns>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="releaseCount"/> is less
- /// than 1.</exception>
- /// <exception cref="System.Threading.SemaphoreFullException">The <see cref="SemaphoreSlim"/> has
- /// already reached its maximum size.</exception>
- /// <exception cref="System.ObjectDisposedException">The current instance has already been
- /// disposed.</exception>
- public int Release(int releaseCount)
- {
- CheckDispose();
-
- // Validate input
- if (releaseCount < 1)
- {
- throw new ArgumentOutOfRangeException(
- nameof(releaseCount), releaseCount, SR.SemaphoreSlim_Release_CountWrong);
- }
- int returnCount;
-
- lock (m_lockObjAndDisposed)
- {
- // Read the m_currentCount into a local variable to avoid unnecessary volatile accesses inside the lock.
- int currentCount = m_currentCount;
- returnCount = currentCount;
-
- // If the release count would result exceeding the maximum count, throw SemaphoreFullException.
- if (m_maxCount - currentCount < releaseCount)
- {
- throw new SemaphoreFullException();
- }
-
- // Increment the count by the actual release count
- currentCount += releaseCount;
-
- // Signal to any synchronous waiters, taking into account how many waiters have previously been pulsed to wake
- // but have not yet woken
- int waitCount = m_waitCount;
- Debug.Assert(m_countOfWaitersPulsedToWake <= waitCount);
- int waitersToNotify = Math.Min(currentCount, waitCount) - m_countOfWaitersPulsedToWake;
- if (waitersToNotify > 0)
- {
- // Ideally, limiting to a maximum of releaseCount would not be necessary and could be an assert instead, but
- // since WaitUntilCountOrTimeout() does not have enough information to tell whether a woken thread was
- // pulsed, it's possible for m_countOfWaitersPulsedToWake to be less than the number of threads that have
- // actually been pulsed to wake.
- if (waitersToNotify > releaseCount)
- {
- waitersToNotify = releaseCount;
- }
-
- m_countOfWaitersPulsedToWake += waitersToNotify;
- for (int i = 0; i < waitersToNotify; i++)
- {
- Monitor.Pulse(m_lockObjAndDisposed);
- }
- }
-
- // Now signal to any asynchronous waiters, if there are any. While we've already
- // signaled the synchronous waiters, we still hold the lock, and thus
- // they won't have had an opportunity to acquire this yet. So, when releasing
- // asynchronous waiters, we assume that all synchronous waiters will eventually
- // acquire the semaphore. That could be a faulty assumption if those synchronous
- // waits are canceled, but the wait code path will handle that.
- if (m_asyncHead != null)
- {
- Debug.Assert(m_asyncTail != null, "tail should not be null if head isn't null");
- int maxAsyncToRelease = currentCount - waitCount;
- while (maxAsyncToRelease > 0 && m_asyncHead != null)
- {
- --currentCount;
- --maxAsyncToRelease;
-
- // Get the next async waiter to release and queue it to be completed
- TaskNode waiterTask = m_asyncHead;
- RemoveAsyncWaiter(waiterTask); // ensures waiterTask.Next/Prev are null
- waiterTask.TrySetResult(result: true);
- }
- }
- m_currentCount = currentCount;
-
- // Exposing wait handle if it is not null
- if (m_waitHandle != null && returnCount == 0 && currentCount > 0)
- {
- m_waitHandle.Set();
- }
- }
-
- // And return the count
- return returnCount;
- }
-
- /// <summary>
- /// Releases all resources used by the current instance of <see
- /// cref="SemaphoreSlim"/>.
- /// </summary>
- /// <remarks>
- /// Unlike most of the members of <see cref="SemaphoreSlim"/>, <see cref="Dispose()"/> is not
- /// thread-safe and may not be used concurrently with other members of this instance.
- /// </remarks>
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- /// <summary>
- /// When overridden in a derived class, releases the unmanaged resources used by the
- /// <see cref="System.Threading.ManualResetEventSlim"/>, and optionally releases the managed resources.
- /// </summary>
- /// <param name="disposing">true to release both managed and unmanaged resources;
- /// false to release only unmanaged resources.</param>
- /// <remarks>
- /// Unlike most of the members of <see cref="SemaphoreSlim"/>, <see cref="Dispose(bool)"/> is not
- /// thread-safe and may not be used concurrently with other members of this instance.
- /// </remarks>
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
- WaitHandle? wh = m_waitHandle;
- if (wh != null)
- {
- wh.Dispose();
- m_waitHandle = null;
- }
-
- m_lockObjAndDisposed.Value = true;
-
- m_asyncHead = null;
- m_asyncTail = null;
- }
- }
-
- /// <summary>
- /// Private helper method to wake up waiters when a cancellationToken gets canceled.
- /// </summary>
- private static readonly Action<object?> s_cancellationTokenCanceledEventHandler = new Action<object?>(CancellationTokenCanceledEventHandler);
- private static void CancellationTokenCanceledEventHandler(object? obj)
- {
- Debug.Assert(obj is SemaphoreSlim, "Expected a SemaphoreSlim");
- SemaphoreSlim semaphore = (SemaphoreSlim)obj;
- lock (semaphore.m_lockObjAndDisposed)
- {
- Monitor.PulseAll(semaphore.m_lockObjAndDisposed); // wake up all waiters.
- }
- }
-
- /// <summary>
- /// Checks the dispose status by checking the lock object, if it is null means that object
- /// has been disposed and throw ObjectDisposedException
- /// </summary>
- private void CheckDispose()
- {
- if (m_lockObjAndDisposed.Value)
- {
- throw new ObjectDisposedException(null, SR.SemaphoreSlim_Disposed);
- }
- }
- #endregion
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/SendOrPostCallback.cs b/netcore/System.Private.CoreLib/shared/System/Threading/SendOrPostCallback.cs
deleted file mode 100644
index bf8decf4920..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/SendOrPostCallback.cs
+++ /dev/null
@@ -1,8 +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.
-
-namespace System.Threading
-{
- public delegate void SendOrPostCallback(object? state);
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/SpinLock.cs b/netcore/System.Private.CoreLib/shared/System/Threading/SpinLock.cs
deleted file mode 100644
index 759860623b7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/SpinLock.cs
+++ /dev/null
@@ -1,648 +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.
-#pragma warning disable 0420
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-// A spin lock is a mutual exclusion lock primitive where a thread trying to acquire the lock waits in a loop ("spins")
-// repeatedly checking until the lock becomes available. As the thread remains active performing a non-useful task,
-// the use of such a lock is a kind of busy waiting and consumes CPU resources without performing real work.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Threading
-{
- /// <summary>
- /// Provides a mutual exclusion lock primitive where a thread trying to acquire the lock waits in a loop
- /// repeatedly checking until the lock becomes available.
- /// </summary>
- /// <remarks>
- /// <para>
- /// Spin locks can be used for leaf-level locks where the object allocation implied by using a <see
- /// cref="System.Threading.Monitor"/>, in size or due to garbage collection pressure, is overly
- /// expensive. Avoiding blocking is another reason that a spin lock can be useful, however if you expect
- /// any significant amount of blocking, you are probably best not using spin locks due to excessive
- /// spinning. Spinning can be beneficial when locks are fine grained and large in number (for example, a
- /// lock per node in a linked list) as well as when lock hold times are always extremely short. In
- /// general, while holding a spin lock, one should avoid blocking, calling anything that itself may
- /// block, holding more than one spin lock at once, making dynamically dispatched calls (interface and
- /// virtuals), making statically dispatched calls into any code one doesn't own, or allocating memory.
- /// </para>
- /// <para>
- /// <see cref="SpinLock"/> should only be used when it's been determined that doing so will improve an
- /// application's performance. It's also important to note that <see cref="SpinLock"/> is a value type,
- /// for performance reasons. As such, one must be very careful not to accidentally copy a SpinLock
- /// instance, as the two instances (the original and the copy) would then be completely independent of
- /// one another, which would likely lead to erroneous behavior of the application. If a SpinLock instance
- /// must be passed around, it should be passed by reference rather than by value.
- /// </para>
- /// <para>
- /// Do not store <see cref="SpinLock"/> instances in readonly fields.
- /// </para>
- /// <para>
- /// All members of <see cref="SpinLock"/> are thread-safe and may be used from multiple threads
- /// concurrently.
- /// </para>
- /// </remarks>
- [DebuggerTypeProxy(typeof(SystemThreading_SpinLockDebugView))]
- [DebuggerDisplay("IsHeld = {IsHeld}")]
- public struct SpinLock
- {
- // The current ownership state is a single signed int. There are two modes:
- //
- // 1) Ownership tracking enabled: the high bit is 0, and the remaining bits
- // store the managed thread ID of the current owner. When the 31 low bits
- // are 0, the lock is available.
- // 2) Performance mode: when the high bit is 1, lock availability is indicated by the low bit.
- // When the low bit is 1 -- the lock is held; 0 -- the lock is available.
- //
- // There are several masks and constants below for convenience.
-
- private volatile int _owner;
-
- // After how many yields, call Sleep(1)
- private const int SLEEP_ONE_FREQUENCY = 40;
-
- // After how many yields, check the timeout
- private const int TIMEOUT_CHECK_FREQUENCY = 10;
-
- // Thr thread tracking disabled mask
- private const int LOCK_ID_DISABLE_MASK = unchecked((int)0x80000000); // 1000 0000 0000 0000 0000 0000 0000 0000
-
- // the lock is held by some thread, but we don't know which
- private const int LOCK_ANONYMOUS_OWNED = 0x1; // 0000 0000 0000 0000 0000 0000 0000 0001
-
- // Waiters mask if the thread tracking is disabled
- private const int WAITERS_MASK = ~(LOCK_ID_DISABLE_MASK | 1); // 0111 1111 1111 1111 1111 1111 1111 1110
-
- // The Thread tacking is disabled and the lock bit is set, used in Enter fast path to make sure the id is disabled and lock is available
- private const int ID_DISABLED_AND_ANONYMOUS_OWNED = unchecked((int)0x80000001); // 1000 0000 0000 0000 0000 0000 0000 0001
-
- // If the thread is unowned if:
- // m_owner zero and the thread tracking is enabled
- // m_owner & LOCK_ANONYMOUS_OWNED = zero and the thread tracking is disabled
- private const int LOCK_UNOWNED = 0;
-
- // The maximum number of waiters (only used if the thread tracking is disabled)
- // The actual maximum waiters count is this number divided by two because each waiter increments the waiters count by 2
- // The waiters count is calculated by m_owner & WAITERS_MASK 01111....110
- private const int MAXIMUM_WAITERS = WAITERS_MASK;
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int CompareExchange(ref int location, int value, int comparand, ref bool success)
- {
- int result = Interlocked.CompareExchange(ref location, value, comparand);
- success = (result == comparand);
- return result;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.SpinLock"/>
- /// structure with the option to track thread IDs to improve debugging.
- /// </summary>
- /// <remarks>
- /// The default constructor for <see cref="SpinLock"/> tracks thread ownership.
- /// </remarks>
- /// <param name="enableThreadOwnerTracking">Whether to capture and use thread IDs for debugging
- /// purposes.</param>
- public SpinLock(bool enableThreadOwnerTracking)
- {
- _owner = LOCK_UNOWNED;
- if (!enableThreadOwnerTracking)
- {
- _owner |= LOCK_ID_DISABLE_MASK;
- Debug.Assert(!IsThreadOwnerTrackingEnabled, "property should be false by now");
- }
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.SpinLock"/>
- /// structure with the option to track thread IDs to improve debugging.
- /// </summary>
- /// <remarks>
- /// The default constructor for <see cref="SpinLock"/> tracks thread ownership.
- /// </remarks>
- /// <summary>
- /// Acquires the lock in a reliable manner, such that even if an exception occurs within the method
- /// call, <paramref name="lockTaken"/> can be examined reliably to determine whether the lock was
- /// acquired.
- /// </summary>
- /// <remarks>
- /// <see cref="SpinLock"/> is a non-reentrant lock, meaning that if a thread holds the lock, it is
- /// not allowed to enter the lock again. If thread ownership tracking is enabled (whether it's
- /// enabled is available through <see cref="IsThreadOwnerTrackingEnabled"/>), an exception will be
- /// thrown when a thread tries to re-enter a lock it already holds. However, if thread ownership
- /// tracking is disabled, attempting to enter a lock already held will result in deadlock.
- /// </remarks>
- /// <param name="lockTaken">True if the lock is acquired; otherwise, false. <paramref
- /// name="lockTaken"/> must be initialized to false prior to calling this method.</param>
- /// <exception cref="System.Threading.LockRecursionException">
- /// Thread ownership tracking is enabled, and the current thread has already acquired this lock.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="lockTaken"/> argument must be initialized to false prior to calling Enter.
- /// </exception>
- public void Enter(ref bool lockTaken)
- {
- // Try to keep the code and branching in this method as small as possible in order to inline the method
- int observedOwner = _owner;
- if (lockTaken || // invalid parameter
- (observedOwner & ID_DISABLED_AND_ANONYMOUS_OWNED) != LOCK_ID_DISABLE_MASK || // thread tracking is enabled or the lock is already acquired
- CompareExchange(ref _owner, observedOwner | LOCK_ANONYMOUS_OWNED, observedOwner, ref lockTaken) != observedOwner) // acquiring the lock failed
- ContinueTryEnter(Timeout.Infinite, ref lockTaken); // Then try the slow path if any of the above conditions is met
- }
-
- /// <summary>
- /// Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within
- /// the method call, <paramref name="lockTaken"/> can be examined reliably to determine whether the
- /// lock was acquired.
- /// </summary>
- /// <remarks>
- /// Unlike <see cref="Enter"/>, TryEnter will not block waiting for the lock to be available. If the
- /// lock is not available when TryEnter is called, it will return immediately without any further
- /// spinning.
- /// </remarks>
- /// <param name="lockTaken">True if the lock is acquired; otherwise, false. <paramref
- /// name="lockTaken"/> must be initialized to false prior to calling this method.</param>
- /// <exception cref="System.Threading.LockRecursionException">
- /// Thread ownership tracking is enabled, and the current thread has already acquired this lock.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="lockTaken"/> argument must be initialized to false prior to calling TryEnter.
- /// </exception>
- public void TryEnter(ref bool lockTaken)
- {
- int observedOwner = _owner;
- if (((observedOwner & LOCK_ID_DISABLE_MASK) == 0) | lockTaken)
- {
- // Thread tracking enabled or invalid arg. Take slow path.
- ContinueTryEnter(0, ref lockTaken);
- }
- else if ((observedOwner & LOCK_ANONYMOUS_OWNED) != 0)
- {
- // Lock already held by someone
- lockTaken = false;
- }
- else
- {
- // Lock wasn't held; try to acquire it.
- CompareExchange(ref _owner, observedOwner | LOCK_ANONYMOUS_OWNED, observedOwner, ref lockTaken);
- }
- }
-
- /// <summary>
- /// Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within
- /// the method call, <paramref name="lockTaken"/> can be examined reliably to determine whether the
- /// lock was acquired.
- /// </summary>
- /// <remarks>
- /// Unlike <see cref="Enter"/>, TryEnter will not block indefinitely waiting for the lock to be
- /// available. It will block until either the lock is available or until the <paramref
- /// name="timeout"/>
- /// has expired.
- /// </remarks>
- /// <param name="timeout">A <see cref="System.TimeSpan"/> that represents the number of milliseconds
- /// to wait, or a <see cref="System.TimeSpan"/> that represents -1 milliseconds to wait indefinitely.
- /// </param>
- /// <param name="lockTaken">True if the lock is acquired; otherwise, false. <paramref
- /// name="lockTaken"/> must be initialized to false prior to calling this method.</param>
- /// <exception cref="System.Threading.LockRecursionException">
- /// Thread ownership tracking is enabled, and the current thread has already acquired this lock.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="lockTaken"/> argument must be initialized to false prior to calling TryEnter.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="timeout"/> is a negative
- /// number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater
- /// than <see cref="int.MaxValue"/> milliseconds.
- /// </exception>
- public void TryEnter(TimeSpan timeout, ref bool lockTaken)
- {
- // Validate the timeout
- long totalMilliseconds = (long)timeout.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- throw new System.ArgumentOutOfRangeException(
- nameof(timeout), timeout, SR.SpinLock_TryEnter_ArgumentOutOfRange);
- }
-
- // Call reliable enter with the int-based timeout milliseconds
- TryEnter((int)timeout.TotalMilliseconds, ref lockTaken);
- }
-
- /// <summary>
- /// Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within
- /// the method call, <paramref name="lockTaken"/> can be examined reliably to determine whether the
- /// lock was acquired.
- /// </summary>
- /// <remarks>
- /// Unlike <see cref="Enter"/>, TryEnter will not block indefinitely waiting for the lock to be
- /// available. It will block until either the lock is available or until the <paramref
- /// name="millisecondsTimeout"/> has expired.
- /// </remarks>
- /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see
- /// cref="System.Threading.Timeout.Infinite"/> (-1) to wait indefinitely.</param>
- /// <param name="lockTaken">True if the lock is acquired; otherwise, false. <paramref
- /// name="lockTaken"/> must be initialized to false prior to calling this method.</param>
- /// <exception cref="System.Threading.LockRecursionException">
- /// Thread ownership tracking is enabled, and the current thread has already acquired this lock.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="lockTaken"/> argument must be initialized to false prior to calling TryEnter.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is
- /// a negative number other than -1, which represents an infinite time-out.</exception>
- public void TryEnter(int millisecondsTimeout, ref bool lockTaken)
- {
- int observedOwner = _owner;
- if (millisecondsTimeout < -1 || // invalid parameter
- lockTaken || // invalid parameter
- (observedOwner & ID_DISABLED_AND_ANONYMOUS_OWNED) != LOCK_ID_DISABLE_MASK || // thread tracking is enabled or the lock is already acquired
- CompareExchange(ref _owner, observedOwner | LOCK_ANONYMOUS_OWNED, observedOwner, ref lockTaken) != observedOwner) // acquiring the lock failed
- ContinueTryEnter(millisecondsTimeout, ref lockTaken); // The call the slow pth
- }
-
- /// <summary>
- /// Try acquire the lock with long path, this is usually called after the first path in Enter and
- /// TryEnter failed The reason for short path is to make it inline in the run time which improves the
- /// performance. This method assumed that the parameter are validated in Enter or TryEnter method.
- /// </summary>
- /// <param name="millisecondsTimeout">The timeout milliseconds</param>
- /// <param name="lockTaken">The lockTaken param</param>
- private void ContinueTryEnter(int millisecondsTimeout, ref bool lockTaken)
- {
- // The fast path doesn't throw any exception, so we have to validate the parameters here
- if (lockTaken)
- {
- lockTaken = false;
- throw new ArgumentException(SR.SpinLock_TryReliableEnter_ArgumentException);
- }
-
- if (millisecondsTimeout < -1)
- {
- throw new ArgumentOutOfRangeException(
- nameof(millisecondsTimeout), millisecondsTimeout, SR.SpinLock_TryEnter_ArgumentOutOfRange);
- }
-
- uint startTime = 0;
- if (millisecondsTimeout != Timeout.Infinite && millisecondsTimeout != 0)
- {
- startTime = TimeoutHelper.GetTime();
- }
-
- if (IsThreadOwnerTrackingEnabled)
- {
- // Slow path for enabled thread tracking mode
- ContinueTryEnterWithThreadTracking(millisecondsTimeout, startTime, ref lockTaken);
- return;
- }
-
- // then thread tracking is disabled
- // In this case there are three ways to acquire the lock
- // 1- the first way the thread either tries to get the lock if it's free or updates the waiters, if the turn >= the processors count then go to 3 else go to 2
- // 2- In this step the waiter threads spins and tries to acquire the lock, the number of spin iterations and spin count is dependent on the thread turn
- // the late the thread arrives the more it spins and less frequent it check the lock availability
- // Also the spins count is increases each iteration
- // If the spins iterations finished and failed to acquire the lock, go to step 3
- // 3- This is the yielding step, there are two ways of yielding Thread.Yield and Sleep(1)
- // If the timeout is expired in after step 1, we need to decrement the waiters count before returning
-
- int observedOwner;
- int turn = int.MaxValue;
- // ***Step 1, take the lock or update the waiters
-
- // try to acquire the lock directly if possible or update the waiters count
- observedOwner = _owner;
- if ((observedOwner & LOCK_ANONYMOUS_OWNED) == LOCK_UNOWNED)
- {
- if (CompareExchange(ref _owner, observedOwner | 1, observedOwner, ref lockTaken) == observedOwner)
- {
- // Acquired lock
- return;
- }
-
- if (millisecondsTimeout == 0)
- {
- // Did not acquire lock in CompareExchange and timeout is 0 so fail fast
- return;
- }
- }
- else if (millisecondsTimeout == 0)
- {
- // Did not acquire lock as owned and timeout is 0 so fail fast
- return;
- }
- else // failed to acquire the lock, then try to update the waiters. If the waiters count reached the maximum, just break the loop to avoid overflow
- {
- if ((observedOwner & WAITERS_MASK) != MAXIMUM_WAITERS)
- {
- // This can still overflow, but maybe there will never be that many waiters
- turn = (Interlocked.Add(ref _owner, 2) & WAITERS_MASK) >> 1;
- }
- }
-
- // lock acquired failed and waiters updated
-
- // *** Step 2, Spinning and Yielding
- SpinWait spinner = default;
- if (turn > Environment.ProcessorCount)
- {
- spinner.Count = SpinWait.YieldThreshold;
- }
- while (true)
- {
- spinner.SpinOnce(SLEEP_ONE_FREQUENCY);
-
- observedOwner = _owner;
- if ((observedOwner & LOCK_ANONYMOUS_OWNED) == LOCK_UNOWNED)
- {
- int newOwner = (observedOwner & WAITERS_MASK) == 0 ? // Gets the number of waiters, if zero
- observedOwner | 1 // don't decrement it. just set the lock bit, it is zero because a previous call of Exit(false) which corrupted the waiters
- : (observedOwner - 2) | 1; // otherwise decrement the waiters and set the lock bit
- Debug.Assert((newOwner & WAITERS_MASK) >= 0);
-
- if (CompareExchange(ref _owner, newOwner, observedOwner, ref lockTaken) == observedOwner)
- {
- return;
- }
- }
-
- if (spinner.Count % TIMEOUT_CHECK_FREQUENCY == 0)
- {
- // Check the timeout.
- if (millisecondsTimeout != Timeout.Infinite && TimeoutHelper.UpdateTimeOut(startTime, millisecondsTimeout) <= 0)
- {
- DecrementWaiters();
- return;
- }
- }
- }
- }
-
- /// <summary>
- /// decrements the waiters, in case of the timeout is expired
- /// </summary>
- private void DecrementWaiters()
- {
- SpinWait spinner = default;
- while (true)
- {
- int observedOwner = _owner;
- if ((observedOwner & WAITERS_MASK) == 0) return; // don't decrement the waiters if it's corrupted by previous call of Exit(false)
- if (Interlocked.CompareExchange(ref _owner, observedOwner - 2, observedOwner) == observedOwner)
- {
- Debug.Assert(!IsThreadOwnerTrackingEnabled); // Make sure the waiters never be negative which will cause the thread tracking bit to be flipped
- break;
- }
- spinner.SpinOnce();
- }
- }
-
- /// <summary>
- /// ContinueTryEnter for the thread tracking mode enabled
- /// </summary>
- private void ContinueTryEnterWithThreadTracking(int millisecondsTimeout, uint startTime, ref bool lockTaken)
- {
- Debug.Assert(IsThreadOwnerTrackingEnabled);
-
- const int LockUnowned = 0;
- // We are using thread IDs to mark ownership. Snap the thread ID and check for recursion.
- // We also must or the ID enablement bit, to ensure we propagate when we CAS it in.
- int newOwner = Environment.CurrentManagedThreadId;
- if (_owner == newOwner)
- {
- // We don't allow lock recursion.
- throw new LockRecursionException(SR.SpinLock_TryEnter_LockRecursionException);
- }
-
- SpinWait spinner = default;
-
- // Loop until the lock has been successfully acquired or, if specified, the timeout expires.
- while (true)
- {
- // We failed to get the lock, either from the fast route or the last iteration
- // and the timeout hasn't expired; spin once and try again.
- spinner.SpinOnce();
-
- // Test before trying to CAS, to avoid acquiring the line exclusively unnecessarily.
-
- if (_owner == LockUnowned)
- {
- if (CompareExchange(ref _owner, newOwner, LockUnowned, ref lockTaken) == LockUnowned)
- {
- return;
- }
- }
- // Check the timeout. We only RDTSC if the next spin will yield, to amortize the cost.
- if (millisecondsTimeout == 0 ||
- (millisecondsTimeout != Timeout.Infinite && spinner.NextSpinWillYield &&
- TimeoutHelper.UpdateTimeOut(startTime, millisecondsTimeout) <= 0))
- {
- return;
- }
- }
- }
-
- /// <summary>
- /// Releases the lock.
- /// </summary>
- /// <remarks>
- /// The default overload of <see cref="Exit()"/> provides the same behavior as if calling <see
- /// cref="Exit(bool)"/> using true as the argument, but Exit() could be slightly faster than Exit(true).
- /// </remarks>
- /// <exception cref="SynchronizationLockException">
- /// Thread ownership tracking is enabled, and the current thread is not the owner of this lock.
- /// </exception>
- public void Exit()
- {
- // This is the fast path for the thread tracking is disabled, otherwise go to the slow path
- if ((_owner & LOCK_ID_DISABLE_MASK) == 0)
- ExitSlowPath(true);
- else
- Interlocked.Decrement(ref _owner);
- }
-
- /// <summary>
- /// Releases the lock.
- /// </summary>
- /// <param name="useMemoryBarrier">
- /// A Boolean value that indicates whether a memory fence should be issued in order to immediately
- /// publish the exit operation to other threads.
- /// </param>
- /// <remarks>
- /// Calling <see cref="Exit(bool)"/> with the <paramref name="useMemoryBarrier"/> argument set to
- /// true will improve the fairness of the lock at the expense of some performance. The default <see
- /// cref="Enter"/>
- /// overload behaves as if specifying true for <paramref name="useMemoryBarrier"/>.
- /// </remarks>
- /// <exception cref="SynchronizationLockException">
- /// Thread ownership tracking is enabled, and the current thread is not the owner of this lock.
- /// </exception>
- public void Exit(bool useMemoryBarrier)
- {
- // This is the fast path for the thread tracking is disabled and not to use memory barrier, otherwise go to the slow path
- // The reason not to add else statement if the usememorybarrier is that it will add more branching in the code and will prevent
- // method inlining, so this is optimized for useMemoryBarrier=false and Exit() overload optimized for useMemoryBarrier=true.
- int tmpOwner = _owner;
- if ((tmpOwner & LOCK_ID_DISABLE_MASK) != 0 & !useMemoryBarrier)
- {
- _owner = tmpOwner & (~LOCK_ANONYMOUS_OWNED);
- }
- else
- {
- ExitSlowPath(useMemoryBarrier);
- }
- }
-
- /// <summary>
- /// The slow path for exit method if the fast path failed
- /// </summary>
- /// <param name="useMemoryBarrier">
- /// A Boolean value that indicates whether a memory fence should be issued in order to immediately
- /// publish the exit operation to other threads
- /// </param>
- private void ExitSlowPath(bool useMemoryBarrier)
- {
- bool threadTrackingEnabled = (_owner & LOCK_ID_DISABLE_MASK) == 0;
- if (threadTrackingEnabled && !IsHeldByCurrentThread)
- {
- throw new SynchronizationLockException(SR.SpinLock_Exit_SynchronizationLockException);
- }
-
- if (useMemoryBarrier)
- {
- if (threadTrackingEnabled)
- {
- Interlocked.Exchange(ref _owner, LOCK_UNOWNED);
- }
- else
- {
- Interlocked.Decrement(ref _owner);
- }
- }
- else
- {
- if (threadTrackingEnabled)
- {
- _owner = LOCK_UNOWNED;
- }
- else
- {
- int tmpOwner = _owner;
- _owner = tmpOwner & (~LOCK_ANONYMOUS_OWNED);
- }
- }
- }
-
- /// <summary>
- /// Gets whether the lock is currently held by any thread.
- /// </summary>
- public bool IsHeld
- {
- get
- {
- if (IsThreadOwnerTrackingEnabled)
- return _owner != LOCK_UNOWNED;
-
- return (_owner & LOCK_ANONYMOUS_OWNED) != LOCK_UNOWNED;
- }
- }
-
- /// <summary>
- /// Gets whether the lock is currently held by any thread.
- /// </summary>
- /// <summary>
- /// Gets whether the lock is held by the current thread.
- /// </summary>
- /// <remarks>
- /// If the lock was initialized to track owner threads, this will return whether the lock is acquired
- /// by the current thread. It is invalid to use this property when the lock was initialized to not
- /// track thread ownership.
- /// </remarks>
- /// <exception cref="System.InvalidOperationException">
- /// Thread ownership tracking is disabled.
- /// </exception>
- public bool IsHeldByCurrentThread
- {
- get
- {
- if (!IsThreadOwnerTrackingEnabled)
- {
- throw new InvalidOperationException(SR.SpinLock_IsHeldByCurrentThread);
- }
- return (_owner & (~LOCK_ID_DISABLE_MASK)) == Environment.CurrentManagedThreadId;
- }
- }
-
- /// <summary>Gets whether thread ownership tracking is enabled for this instance.</summary>
- public bool IsThreadOwnerTrackingEnabled => (_owner & LOCK_ID_DISABLE_MASK) == 0;
-
- #region Debugger proxy class
- /// <summary>
- /// Internal class used by debug type proxy attribute to display the owner thread ID
- /// </summary>
- internal class SystemThreading_SpinLockDebugView
- {
- // SpinLock object
- private SpinLock _spinLock;
-
- /// <summary>
- /// SystemThreading_SpinLockDebugView constructor
- /// </summary>
- /// <param name="spinLock">The SpinLock to be proxied.</param>
- public SystemThreading_SpinLockDebugView(SpinLock spinLock)
- {
- // Note that this makes a copy of the SpinLock (struct). It doesn't hold a reference to it.
- _spinLock = spinLock;
- }
-
- /// <summary>
- /// Checks if the lock is held by the current thread or not
- /// </summary>
- public bool? IsHeldByCurrentThread
- {
- get
- {
- try
- {
- return _spinLock.IsHeldByCurrentThread;
- }
- catch (InvalidOperationException)
- {
- return null;
- }
- }
- }
-
- /// <summary>
- /// Gets the current owner thread, zero if it is released
- /// </summary>
- public int? OwnerThreadID
- {
- get
- {
- if (_spinLock.IsThreadOwnerTrackingEnabled)
- {
- return _spinLock._owner;
- }
- else
- {
- return null;
- }
- }
- }
-
- /// <summary>
- /// Gets whether the lock is currently held by any thread or not.
- /// </summary>
- public bool IsHeld => _spinLock.IsHeld;
- }
- #endregion
-
- }
-}
-#pragma warning restore 0420
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/SpinWait.cs b/netcore/System.Private.CoreLib/shared/System/Threading/SpinWait.cs
deleted file mode 100644
index 0b2008bfa41..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/SpinWait.cs
+++ /dev/null
@@ -1,349 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-// Central spin logic used across the entire code-base.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Diagnostics;
-
-namespace System.Threading
-{
- // SpinWait is just a little value type that encapsulates some common spinning
- // logic. It ensures we always yield on single-proc machines (instead of using busy
- // waits), and that we work well on HT. It encapsulates a good mixture of spinning
- // and real yielding. It's a value type so that various areas of the engine can use
- // one by allocating it on the stack w/out unnecessary GC allocation overhead, e.g.:
- //
- // void f() {
- // SpinWait wait = new SpinWait();
- // while (!p) { wait.SpinOnce(); }
- // ...
- // }
- //
- // Internally it just maintains a counter that is used to decide when to yield, etc.
- //
- // A common usage is to spin before blocking. In those cases, the NextSpinWillYield
- // property allows a user to decide to fall back to waiting once it returns true:
- //
- // void f() {
- // SpinWait wait = new SpinWait();
- // while (!p) {
- // if (wait.NextSpinWillYield) { /* block! */ }
- // else { wait.SpinOnce(); }
- // }
- // ...
- // }
-
- /// <summary>
- /// Provides support for spin-based waiting.
- /// </summary>
- /// <remarks>
- /// <para>
- /// <see cref="SpinWait"/> encapsulates common spinning logic. On single-processor machines, yields are
- /// always used instead of busy waits, and on computers with Intel(R) processors employing Hyper-Threading
- /// technology, it helps to prevent hardware thread starvation. SpinWait encapsulates a good mixture of
- /// spinning and true yielding.
- /// </para>
- /// <para>
- /// <see cref="SpinWait"/> is a value type, which means that low-level code can utilize SpinWait without
- /// fear of unnecessary allocation overheads. SpinWait is not generally useful for ordinary applications.
- /// In most cases, you should use the synchronization classes provided by the .NET Framework, such as
- /// <see cref="System.Threading.Monitor"/>. For most purposes where spin waiting is required, however,
- /// the <see cref="SpinWait"/> type should be preferred over the <see
- /// cref="System.Threading.Thread.SpinWait"/> method.
- /// </para>
- /// <para>
- /// While SpinWait is designed to be used in concurrent applications, it is not designed to be
- /// used from multiple threads concurrently. SpinWait's members are not thread-safe. If multiple
- /// threads must spin, each should use its own instance of SpinWait.
- /// </para>
- /// </remarks>
- public struct SpinWait
- {
- // These constants determine the frequency of yields versus spinning. The
- // numbers may seem fairly arbitrary, but were derived with at least some
- // thought in the design document. I fully expect they will need to change
- // over time as we gain more experience with performance.
- internal const int YieldThreshold = 10; // When to switch over to a true yield.
- private const int Sleep0EveryHowManyYields = 5; // After how many yields should we Sleep(0)?
- internal const int DefaultSleep1Threshold = 20; // After how many yields should we Sleep(1) frequently?
-
- /// <summary>
- /// A suggested number of spin iterations before doing a proper wait, such as waiting on an event that becomes signaled
- /// when the resource becomes available.
- /// </summary>
- /// <remarks>
- /// These numbers were arrived at by experimenting with different numbers in various cases that currently use it. It's
- /// only a suggested value and typically works well when the proper wait is something like an event.
- ///
- /// Spinning less can lead to early waiting and more context switching, spinning more can decrease latency but may use
- /// up some CPU time unnecessarily. Depends on the situation too, for instance SemaphoreSlim uses more iterations
- /// because the waiting there is currently a lot more expensive (involves more spinning, taking a lock, etc.). It also
- /// depends on the likelihood of the spin being successful and how long the wait would be but those are not accounted
- /// for here.
- /// </remarks>
- internal static readonly int SpinCountforSpinBeforeWait = Environment.IsSingleProcessor ? 1 : 35;
-
- // The number of times we've spun already.
- private int _count;
-
- /// <summary>
- /// Gets the number of times <see cref="SpinOnce()"/> has been called on this instance.
- /// </summary>
- public int Count
- {
- get => _count;
- internal set
- {
- Debug.Assert(value >= 0);
- _count = value;
- }
- }
-
- /// <summary>
- /// Gets whether the next call to <see cref="SpinOnce()"/> will yield the processor, triggering a
- /// forced context switch.
- /// </summary>
- /// <value>Whether the next call to <see cref="SpinOnce()"/> will yield the processor, triggering a
- /// forced context switch.</value>
- /// <remarks>
- /// On a single-CPU machine, <see cref="SpinOnce()"/> always yields the processor. On machines with
- /// multiple CPUs, <see cref="SpinOnce()"/> may yield after an unspecified number of calls.
- /// </remarks>
- public bool NextSpinWillYield => _count >= YieldThreshold || Environment.IsSingleProcessor;
-
- /// <summary>
- /// Performs a single spin.
- /// </summary>
- /// <remarks>
- /// This is typically called in a loop, and may change in behavior based on the number of times a
- /// <see cref="SpinOnce()"/> has been called thus far on this instance.
- /// </remarks>
- public void SpinOnce()
- {
- SpinOnceCore(DefaultSleep1Threshold);
- }
-
- /// <summary>
- /// Performs a single spin.
- /// </summary>
- /// <param name="sleep1Threshold">
- /// A minimum spin count after which <code>Thread.Sleep(1)</code> may be used. A value of <code>-1</code> may be used to
- /// disable the use of <code>Thread.Sleep(1)</code>.
- /// </param>
- /// <exception cref="ArgumentOutOfRangeException">
- /// <paramref name="sleep1Threshold"/> is less than <code>-1</code>.
- /// </exception>
- /// <remarks>
- /// This is typically called in a loop, and may change in behavior based on the number of times a
- /// <see cref="SpinOnce()"/> has been called thus far on this instance.
- /// </remarks>
- public void SpinOnce(int sleep1Threshold)
- {
- if (sleep1Threshold < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(sleep1Threshold), sleep1Threshold, SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- }
-
- if (sleep1Threshold >= 0 && sleep1Threshold < YieldThreshold)
- {
- sleep1Threshold = YieldThreshold;
- }
-
- SpinOnceCore(sleep1Threshold);
- }
-
- private void SpinOnceCore(int sleep1Threshold)
- {
- Debug.Assert(sleep1Threshold >= -1);
- Debug.Assert(sleep1Threshold < 0 || sleep1Threshold >= YieldThreshold);
-
- // (_count - YieldThreshold) % 2 == 0: The purpose of this check is to interleave Thread.Yield/Sleep(0) with
- // Thread.SpinWait. Otherwise, the following issues occur:
- // - When there are no threads to switch to, Yield and Sleep(0) become no-op and it turns the spin loop into a
- // busy-spin that may quickly reach the max spin count and cause the thread to enter a wait state, or may
- // just busy-spin for longer than desired before a Sleep(1). Completing the spin loop too early can cause
- // excessive context switcing if a wait follows, and entering the Sleep(1) stage too early can cause
- // excessive delays.
- // - If there are multiple threads doing Yield and Sleep(0) (typically from the same spin loop due to
- // contention), they may switch between one another, delaying work that can make progress.
- if ((
- _count >= YieldThreshold &&
- ((_count >= sleep1Threshold && sleep1Threshold >= 0) || (_count - YieldThreshold) % 2 == 0)
- ) ||
- Environment.IsSingleProcessor)
- {
- //
- // We must yield.
- //
- // We prefer to call Thread.Yield first, triggering a SwitchToThread. This
- // unfortunately doesn't consider all runnable threads on all OS SKUs. In
- // some cases, it may only consult the runnable threads whose ideal processor
- // is the one currently executing code. Thus we occasionally issue a call to
- // Sleep(0), which considers all runnable threads at equal priority. Even this
- // is insufficient since we may be spin waiting for lower priority threads to
- // execute; we therefore must call Sleep(1) once in a while too, which considers
- // all runnable threads, regardless of ideal processor and priority, but may
- // remove the thread from the scheduler's queue for 10+ms, if the system is
- // configured to use the (default) coarse-grained system timer.
- //
-
- if (_count >= sleep1Threshold && sleep1Threshold >= 0)
- {
- Thread.Sleep(1);
- }
- else
- {
- int yieldsSoFar = _count >= YieldThreshold ? (_count - YieldThreshold) / 2 : _count;
- if ((yieldsSoFar % Sleep0EveryHowManyYields) == (Sleep0EveryHowManyYields - 1))
- {
- Thread.Sleep(0);
- }
- else
- {
- Thread.Yield();
- }
- }
- }
- else
- {
- //
- // Otherwise, we will spin.
- //
- // We do this using the CLR's SpinWait API, which is just a busy loop that
- // issues YIELD/PAUSE instructions to ensure multi-threaded CPUs can react
- // intelligently to avoid starving. (These are NOOPs on other CPUs.) We
- // choose a number for the loop iteration count such that each successive
- // call spins for longer, to reduce cache contention. We cap the total
- // number of spins we are willing to tolerate to reduce delay to the caller,
- // since we expect most callers will eventually block anyway.
- //
- // Also, cap the maximum spin count to a value such that many thousands of CPU cycles would not be wasted doing
- // the equivalent of YieldProcessor(), as at that point SwitchToThread/Sleep(0) are more likely to be able to
- // allow other useful work to run. Long YieldProcessor() loops can help to reduce contention, but Sleep(1) is
- // usually better for that.
- //
- // Thread.OptimalMaxSpinWaitsPerSpinIteration:
- // - See Thread::InitializeYieldProcessorNormalized(), which describes and calculates this value.
- //
- int n = Thread.OptimalMaxSpinWaitsPerSpinIteration;
- if (_count <= 30 && (1 << _count) < n)
- {
- n = 1 << _count;
- }
- Thread.SpinWait(n);
- }
-
- // Finally, increment our spin counter.
- _count = (_count == int.MaxValue ? YieldThreshold : _count + 1);
- }
-
- /// <summary>
- /// Resets the spin counter.
- /// </summary>
- /// <remarks>
- /// This makes <see cref="SpinOnce()"/> and <see cref="NextSpinWillYield"/> behave as though no calls
- /// to <see cref="SpinOnce()"/> had been issued on this instance. If a <see cref="SpinWait"/> instance
- /// is reused many times, it may be useful to reset it to avoid yielding too soon.
- /// </remarks>
- public void Reset()
- {
- _count = 0;
- }
-
- #region Static Methods
- /// <summary>
- /// Spins until the specified condition is satisfied.
- /// </summary>
- /// <param name="condition">A delegate to be executed over and over until it returns true.</param>
- /// <exception cref="ArgumentNullException">The <paramref name="condition"/> argument is null.</exception>
- public static void SpinUntil(Func<bool> condition)
- {
-#if DEBUG
- bool result =
-#endif
- SpinUntil(condition, Timeout.Infinite);
-#if DEBUG
- Debug.Assert(result);
-#endif
- }
-
- /// <summary>
- /// Spins until the specified condition is satisfied or until the specified timeout is expired.
- /// </summary>
- /// <param name="condition">A delegate to be executed over and over until it returns true.</param>
- /// <param name="timeout">
- /// A <see cref="TimeSpan"/> that represents the number of milliseconds to wait,
- /// or a TimeSpan that represents -1 milliseconds to wait indefinitely.</param>
- /// <returns>True if the condition is satisfied within the timeout; otherwise, false</returns>
- /// <exception cref="ArgumentNullException">The <paramref name="condition"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="timeout"/> is a negative number
- /// other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater than
- /// <see cref="int.MaxValue"/>.</exception>
- public static bool SpinUntil(Func<bool> condition, TimeSpan timeout)
- {
- // Validate the timeout
- long totalMilliseconds = (long)timeout.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- throw new System.ArgumentOutOfRangeException(
- nameof(timeout), timeout, SR.SpinWait_SpinUntil_TimeoutWrong);
- }
-
- // Call wait with the timeout milliseconds
- return SpinUntil(condition, (int)totalMilliseconds);
- }
-
- /// <summary>
- /// Spins until the specified condition is satisfied or until the specified timeout is expired.
- /// </summary>
- /// <param name="condition">A delegate to be executed over and over until it returns true.</param>
- /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see
- /// cref="System.Threading.Timeout.Infinite"/> (-1) to wait indefinitely.</param>
- /// <returns>True if the condition is satisfied within the timeout; otherwise, false</returns>
- /// <exception cref="ArgumentNullException">The <paramref name="condition"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is a
- /// negative number other than -1, which represents an infinite time-out.</exception>
- public static bool SpinUntil(Func<bool> condition, int millisecondsTimeout)
- {
- if (millisecondsTimeout < Timeout.Infinite)
- {
- throw new ArgumentOutOfRangeException(
- nameof(millisecondsTimeout), millisecondsTimeout, SR.SpinWait_SpinUntil_TimeoutWrong);
- }
- if (condition == null)
- {
- throw new ArgumentNullException(nameof(condition), SR.SpinWait_SpinUntil_ArgumentNull);
- }
- uint startTime = 0;
- if (millisecondsTimeout != 0 && millisecondsTimeout != Timeout.Infinite)
- {
- startTime = TimeoutHelper.GetTime();
- }
- SpinWait spinner = default;
- while (!condition())
- {
- if (millisecondsTimeout == 0)
- {
- return false;
- }
-
- spinner.SpinOnce();
-
- if (millisecondsTimeout != Timeout.Infinite && spinner.NextSpinWillYield)
- {
- if (millisecondsTimeout <= (TimeoutHelper.GetTime() - startTime))
- {
- return false;
- }
- }
- }
- return true;
- }
- #endregion
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs b/netcore/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs
deleted file mode 100644
index 7ce1cd9472f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs
+++ /dev/null
@@ -1,62 +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.
-
-namespace System.Threading
-{
- public partial class SynchronizationContext
- {
- private bool _requireWaitNotification;
-
- public SynchronizationContext()
- {
- }
-
-#if !FEATURE_APPX
- public static SynchronizationContext? Current => Thread.CurrentThread._synchronizationContext;
-#endif
-
- protected void SetWaitNotificationRequired() => _requireWaitNotification = true;
-
- public bool IsWaitNotificationRequired() => _requireWaitNotification;
-
- public virtual void Send(SendOrPostCallback d, object? state) => d(state);
-
- public virtual void Post(SendOrPostCallback d, object? state) => ThreadPool.QueueUserWorkItem(s => s.d(s.state), (d, state), preferLocal: false);
-
- /// <summary>
- /// Optional override for subclasses, for responding to notification that operation is starting.
- /// </summary>
- public virtual void OperationStarted()
- {
- }
-
- /// <summary>
- /// Optional override for subclasses, for responding to notification that operation has completed.
- /// </summary>
- public virtual void OperationCompleted()
- {
- }
-
- [CLSCompliant(false)]
- public virtual int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
- {
- return WaitHelper(waitHandles, waitAll, millisecondsTimeout);
- }
-
- [CLSCompliant(false)]
- protected static int WaitHelper(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
- {
- if (waitHandles == null)
- {
- throw new ArgumentNullException(nameof(waitHandles));
- }
-
- return WaitHandle.WaitMultipleIgnoringSyncContext(waitHandles, waitAll, millisecondsTimeout);
- }
-
- public static void SetSynchronizationContext(SynchronizationContext? syncContext) => Thread.CurrentThread._synchronizationContext = syncContext;
-
- public virtual SynchronizationContext CreateCopy() => new SynchronizationContext();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/SynchronizationLockException.cs b/netcore/System.Private.CoreLib/shared/System/Threading/SynchronizationLockException.cs
deleted file mode 100644
index 2762a8e503a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/SynchronizationLockException.cs
+++ /dev/null
@@ -1,45 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Wait(), Notify() or NotifyAll() was called from an unsynchronized
-** block of code.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System.Threading
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class SynchronizationLockException : SystemException
- {
- public SynchronizationLockException()
- : base(SR.Arg_SynchronizationLockException)
- {
- HResult = HResults.COR_E_SYNCHRONIZATIONLOCK;
- }
-
- public SynchronizationLockException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_SYNCHRONIZATIONLOCK;
- }
-
- public SynchronizationLockException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_SYNCHRONIZATIONLOCK;
- }
-
- protected SynchronizationLockException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/AsyncCausalityTracer.Noop.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/AsyncCausalityTracer.Noop.cs
deleted file mode 100644
index b00d5d67561..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/AsyncCausalityTracer.Noop.cs
+++ /dev/null
@@ -1,46 +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 System.Diagnostics;
-
-namespace System.Threading.Tasks
-{
- //
- // Empty implementation of AsyncCausality events
- //
- internal static class AsyncCausalityTracer
- {
- public static bool LoggingOn => false;
-
- [Conditional("NOOP_ASYNCCASUALITYTRACER")]
- public static void EnableToETW(bool enabled)
- {
- }
-
- [Conditional("NOOP_ASYNCCASUALITYTRACER")]
- public static void TraceOperationCreation(Task task, string operationName)
- {
- }
-
- [Conditional("NOOP_ASYNCCASUALITYTRACER")]
- public static void TraceOperationCompletion(Task task, AsyncCausalityStatus status)
- {
- }
-
- [Conditional("NOOP_ASYNCCASUALITYTRACER")]
- public static void TraceOperationRelation(Task task, CausalityRelation relation)
- {
- }
-
- [Conditional("NOOP_ASYNCCASUALITYTRACER")]
- public static void TraceSynchronousWorkStart(Task task, CausalitySynchronousWork work)
- {
- }
-
- [Conditional("NOOP_ASYNCCASUALITYTRACER")]
- public static void TraceSynchronousWorkCompletion(CausalitySynchronousWork work)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/AsyncCausalityTracerConstants.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/AsyncCausalityTracerConstants.cs
deleted file mode 100644
index 3677051f058..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/AsyncCausalityTracerConstants.cs
+++ /dev/null
@@ -1,30 +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.
-
-namespace System.Threading.Tasks
-{
- internal enum AsyncCausalityStatus
- {
- Started = 0,
- Completed = 1,
- Canceled = 2,
- Error = 3,
- }
-
- internal enum CausalityRelation
- {
- AssignDelegate = 0,
- Join = 1,
- Choice = 2,
- Cancel = 3,
- Error = 4,
- }
-
- internal enum CausalitySynchronousWork
- {
- CompletionNotification = 0,
- ProgressNotification = 1,
- Execution = 2,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs
deleted file mode 100644
index 04992d550c5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs
+++ /dev/null
@@ -1,773 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// A pair of schedulers that together support concurrent (reader) / exclusive (writer)
-// task scheduling. Using just the exclusive scheduler can be used to simulate a serial
-// processing queue, and using just the concurrent scheduler with a specified
-// MaximumConcurrentlyLevel can be used to achieve a MaxDegreeOfParallelism across
-// a bunch of tasks, parallel loops, dataflow blocks, etc.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// Provides concurrent and exclusive task schedulers that coordinate to execute
- /// tasks while ensuring that concurrent tasks may run concurrently and exclusive tasks never do.
- /// </summary>
- [DebuggerDisplay("Concurrent={ConcurrentTaskCountForDebugger}, Exclusive={ExclusiveTaskCountForDebugger}, Mode={ModeForDebugger}")]
- [DebuggerTypeProxy(typeof(ConcurrentExclusiveSchedulerPair.DebugView))]
- public class ConcurrentExclusiveSchedulerPair
- {
- /// <summary>A processing mode to denote what kinds of tasks are currently being processed on this thread.</summary>
- private readonly ThreadLocal<ProcessingMode> m_threadProcessingMode = new ThreadLocal<ProcessingMode>();
- /// <summary>The scheduler used to queue and execute "concurrent" tasks that may run concurrently with other concurrent tasks.</summary>
- private readonly ConcurrentExclusiveTaskScheduler m_concurrentTaskScheduler;
- /// <summary>The scheduler used to queue and execute "exclusive" tasks that must run exclusively while no other tasks for this pair are running.</summary>
- private readonly ConcurrentExclusiveTaskScheduler m_exclusiveTaskScheduler;
- /// <summary>The underlying task scheduler to which all work should be scheduled.</summary>
- private readonly TaskScheduler m_underlyingTaskScheduler;
- /// <summary>
- /// The maximum number of tasks allowed to run concurrently. This only applies to concurrent tasks,
- /// since exclusive tasks are inherently limited to 1.
- /// </summary>
- private readonly int m_maxConcurrencyLevel;
- /// <summary>The maximum number of tasks we can process before recycling our runner tasks.</summary>
- private readonly int m_maxItemsPerTask;
- /// <summary>
- /// If positive, it represents the number of concurrently running concurrent tasks.
- /// If negative, it means an exclusive task has been scheduled.
- /// If 0, nothing has been scheduled.
- /// </summary>
- private int m_processingCount;
- /// <summary>Completion state for a task representing the completion of this pair.</summary>
- /// <remarks>Lazily-initialized only if the scheduler pair is shutting down or if the Completion is requested.</remarks>
- private CompletionState? m_completionState;
- /// <summary>Lazily-initialized work item for processing when targeting the default scheduler.</summary>
- private SchedulerWorkItem? m_threadPoolWorkItem;
-
- /// <summary>A constant value used to signal unlimited processing.</summary>
- private const int UNLIMITED_PROCESSING = -1;
- /// <summary>Constant used for m_processingCount to indicate that an exclusive task is being processed.</summary>
- private const int EXCLUSIVE_PROCESSING_SENTINEL = -1;
- /// <summary>Default MaxItemsPerTask to use for processing if none is specified.</summary>
- private const int DEFAULT_MAXITEMSPERTASK = UNLIMITED_PROCESSING;
- /// <summary>Default MaxConcurrencyLevel is the processor count if not otherwise specified.</summary>
- private static int DefaultMaxConcurrencyLevel => Environment.ProcessorCount;
-
- /// <summary>Gets the sync obj used to protect all state on this instance.</summary>
- private object ValueLock => m_threadProcessingMode;
-
- /// <summary>
- /// Initializes the ConcurrentExclusiveSchedulerPair.
- /// </summary>
- public ConcurrentExclusiveSchedulerPair() :
- this(TaskScheduler.Default, DefaultMaxConcurrencyLevel, DEFAULT_MAXITEMSPERTASK)
- { }
-
- /// <summary>
- /// Initializes the ConcurrentExclusiveSchedulerPair to target the specified scheduler.
- /// </summary>
- /// <param name="taskScheduler">The target scheduler on which this pair should execute.</param>
- public ConcurrentExclusiveSchedulerPair(TaskScheduler taskScheduler) :
- this(taskScheduler, DefaultMaxConcurrencyLevel, DEFAULT_MAXITEMSPERTASK)
- { }
-
- /// <summary>
- /// Initializes the ConcurrentExclusiveSchedulerPair to target the specified scheduler with a maximum concurrency level.
- /// </summary>
- /// <param name="taskScheduler">The target scheduler on which this pair should execute.</param>
- /// <param name="maxConcurrencyLevel">The maximum number of tasks to run concurrently.</param>
- public ConcurrentExclusiveSchedulerPair(TaskScheduler taskScheduler, int maxConcurrencyLevel) :
- this(taskScheduler, maxConcurrencyLevel, DEFAULT_MAXITEMSPERTASK)
- { }
-
- /// <summary>
- /// Initializes the ConcurrentExclusiveSchedulerPair to target the specified scheduler with a maximum
- /// concurrency level and a maximum number of scheduled tasks that may be processed as a unit.
- /// </summary>
- /// <param name="taskScheduler">The target scheduler on which this pair should execute.</param>
- /// <param name="maxConcurrencyLevel">The maximum number of tasks to run concurrently.</param>
- /// <param name="maxItemsPerTask">The maximum number of tasks to process for each underlying scheduled task used by the pair.</param>
- public ConcurrentExclusiveSchedulerPair(TaskScheduler taskScheduler, int maxConcurrencyLevel, int maxItemsPerTask)
- {
- // Validate arguments
- if (taskScheduler == null) throw new ArgumentNullException(nameof(taskScheduler));
- if (maxConcurrencyLevel == 0 || maxConcurrencyLevel < -1) throw new ArgumentOutOfRangeException(nameof(maxConcurrencyLevel));
- if (maxItemsPerTask == 0 || maxItemsPerTask < -1) throw new ArgumentOutOfRangeException(nameof(maxItemsPerTask));
-
- // Store configuration
- m_underlyingTaskScheduler = taskScheduler;
- m_maxConcurrencyLevel = maxConcurrencyLevel;
- m_maxItemsPerTask = maxItemsPerTask;
-
- // Downgrade to the underlying scheduler's max degree of parallelism if it's lower than the user-supplied level
- int mcl = taskScheduler.MaximumConcurrencyLevel;
- if (mcl > 0 && mcl < m_maxConcurrencyLevel) m_maxConcurrencyLevel = mcl;
-
- // Treat UNLIMITED_PROCESSING/-1 for both MCL and MIPT as the biggest possible value so that we don't
- // have to special case UNLIMITED_PROCESSING later on in processing.
- if (m_maxConcurrencyLevel == UNLIMITED_PROCESSING) m_maxConcurrencyLevel = int.MaxValue;
- if (m_maxItemsPerTask == UNLIMITED_PROCESSING) m_maxItemsPerTask = int.MaxValue;
-
- // Create the concurrent/exclusive schedulers for this pair
- m_exclusiveTaskScheduler = new ConcurrentExclusiveTaskScheduler(this, 1, ProcessingMode.ProcessingExclusiveTask);
- m_concurrentTaskScheduler = new ConcurrentExclusiveTaskScheduler(this, m_maxConcurrencyLevel, ProcessingMode.ProcessingConcurrentTasks);
- }
-
- /// <summary>Informs the scheduler pair that it should not accept any more tasks.</summary>
- /// <remarks>
- /// Calling <see cref="Complete"/> is optional, and it's only necessary if the <see cref="Completion"/>
- /// will be relied on for notification of all processing being completed.
- /// </remarks>
- public void Complete()
- {
- lock (ValueLock)
- {
- if (!CompletionRequested)
- {
- RequestCompletion();
- CleanupStateIfCompletingAndQuiesced();
- }
- }
- }
-
- /// <summary>Gets a <see cref="System.Threading.Tasks.Task"/> that will complete when the scheduler has completed processing.</summary>
- public Task Completion => EnsureCompletionStateInitialized();
-
- /// <summary>Gets the lazily-initialized completion state.</summary>
- private CompletionState EnsureCompletionStateInitialized() =>
- // ValueLock not needed, but it's ok if it's held
- LazyInitializer.EnsureInitialized(ref m_completionState, () => new CompletionState());
-
- /// <summary>Gets whether completion has been requested.</summary>
- private bool CompletionRequested => m_completionState != null && Volatile.Read(ref m_completionState.m_completionRequested);
-
- /// <summary>Sets that completion has been requested.</summary>
- private void RequestCompletion()
- {
- ContractAssertMonitorStatus(ValueLock, held: true);
- EnsureCompletionStateInitialized().m_completionRequested = true;
- }
-
- /// <summary>
- /// Cleans up state if and only if there's no processing currently happening
- /// and no more to be done later.
- /// </summary>
- private void CleanupStateIfCompletingAndQuiesced()
- {
- ContractAssertMonitorStatus(ValueLock, held: true);
- if (ReadyToComplete) CompleteTaskAsync();
- }
-
- /// <summary>Gets whether the pair is ready to complete.</summary>
- private bool ReadyToComplete
- {
- get
- {
- ContractAssertMonitorStatus(ValueLock, held: true);
-
- // We can only complete if completion has been requested and no processing is currently happening.
- if (!CompletionRequested || m_processingCount != 0) return false;
-
- // Now, only allow shutdown if an exception occurred or if there are no more tasks to process.
- CompletionState cs = EnsureCompletionStateInitialized();
- return
- (cs.m_exceptions != null && cs.m_exceptions.Count > 0) ||
- (m_concurrentTaskScheduler.m_tasks.IsEmpty && m_exclusiveTaskScheduler.m_tasks.IsEmpty);
- }
- }
-
- /// <summary>Completes the completion task asynchronously.</summary>
- private void CompleteTaskAsync()
- {
- Debug.Assert(ReadyToComplete, "The block must be ready to complete to be here.");
- ContractAssertMonitorStatus(ValueLock, held: true);
-
- // Ensure we only try to complete once, then schedule completion
- // in order to escape held locks and the caller's context
- CompletionState cs = EnsureCompletionStateInitialized();
- if (!cs.m_completionQueued)
- {
- cs.m_completionQueued = true;
- ThreadPool.QueueUserWorkItem(state =>
- {
- Debug.Assert(state is ConcurrentExclusiveSchedulerPair);
- var localThis = (ConcurrentExclusiveSchedulerPair)state;
- Debug.Assert(!localThis.m_completionState!.IsCompleted, "Completion should only happen once.");
-
- List<Exception>? exceptions = localThis.m_completionState.m_exceptions;
- bool success = (exceptions != null && exceptions.Count > 0) ?
- localThis.m_completionState.TrySetException(exceptions) :
- localThis.m_completionState.TrySetResult();
- Debug.Assert(success, "Expected to complete completion task.");
-
- localThis.m_threadProcessingMode.Dispose();
- }, this);
- }
- }
-
- /// <summary>Initiates scheduler shutdown due to a worker task faulting.</summary>
- /// <param name="faultedTask">The faulted worker task that's initiating the shutdown.</param>
- private void FaultWithTask(Task faultedTask)
- {
- Debug.Assert(faultedTask != null && faultedTask.IsFaulted && faultedTask.Exception!.InnerExceptions.Count > 0,
- "Needs a task in the faulted state and thus with exceptions.");
- ContractAssertMonitorStatus(ValueLock, held: true);
-
- // Store the faulted task's exceptions
- CompletionState cs = EnsureCompletionStateInitialized();
- cs.m_exceptions ??= new List<Exception>();
- cs.m_exceptions.AddRange(faultedTask.Exception.InnerExceptions);
-
- // Now that we're doomed, request completion
- RequestCompletion();
- }
-
- /// <summary>
- /// Gets a TaskScheduler that can be used to schedule tasks to this pair
- /// that may run concurrently with other tasks on this pair.
- /// </summary>
- public TaskScheduler ConcurrentScheduler => m_concurrentTaskScheduler;
- /// <summary>
- /// Gets a TaskScheduler that can be used to schedule tasks to this pair
- /// that must run exclusively with regards to other tasks on this pair.
- /// </summary>
- public TaskScheduler ExclusiveScheduler => m_exclusiveTaskScheduler;
-
- /// <summary>Gets the number of tasks waiting to run concurrently.</summary>
- /// <remarks>This does not take the necessary lock, as it's only called from under the debugger.</remarks>
- private int ConcurrentTaskCountForDebugger => m_concurrentTaskScheduler.m_tasks.Count;
-
- /// <summary>Gets the number of tasks waiting to run exclusively.</summary>
- /// <remarks>This does not take the necessary lock, as it's only called from under the debugger.</remarks>
- private int ExclusiveTaskCountForDebugger => m_exclusiveTaskScheduler.m_tasks.Count;
-
- /// <summary>Notifies the pair that new work has arrived to be processed.</summary>
- /// <param name="fairly">Whether tasks should be scheduled fairly with regards to other tasks.</param>
- /// <remarks>Must only be called while holding the lock.</remarks>
- private void ProcessAsyncIfNecessary(bool fairly = false)
- {
- ContractAssertMonitorStatus(ValueLock, held: true);
-
- // If the current processing count is >= 0, we can potentially launch further processing.
- if (m_processingCount >= 0)
- {
- // We snap whether there are any exclusive tasks or concurrent tasks waiting.
- // (We grab the concurrent count below only once we know we need it.)
- // With processing happening concurrent to this operation, this data may
- // immediately be out of date, but it can only go from non-empty
- // to empty and not the other way around. As such, this is safe,
- // as worst case is we'll schedule an extra task when we didn't
- // otherwise need to, and we'll just eat its overhead.
- bool exclusiveTasksAreWaiting = !m_exclusiveTaskScheduler.m_tasks.IsEmpty;
-
- // If there's no processing currently happening but there are waiting exclusive tasks,
- // let's start processing those exclusive tasks.
- Task? processingTask = null;
- if (m_processingCount == 0 && exclusiveTasksAreWaiting)
- {
- // Launch exclusive task processing
- m_processingCount = EXCLUSIVE_PROCESSING_SENTINEL; // -1
- if (!TryQueueThreadPoolWorkItem(fairly))
- {
- try
- {
- processingTask = new Task(thisPair => ((ConcurrentExclusiveSchedulerPair)thisPair!).ProcessExclusiveTasks(), this,
- default, GetCreationOptionsForTask(fairly));
- processingTask.Start(m_underlyingTaskScheduler);
- // When we call Start, if the underlying scheduler throws in QueueTask, TPL will fault the task and rethrow
- // the exception. To deal with that, we need a reference to the task object, so that we can observe its exception.
- // Hence, we separate creation and starting, so that we can store a reference to the task before we attempt QueueTask.
- }
- catch (Exception e)
- {
- m_processingCount = 0;
- FaultWithTask(processingTask ?? Task.FromException(e));
- }
- }
- }
- // If there are no waiting exclusive tasks, there are concurrent tasks, and we haven't reached our maximum
- // concurrency level for processing, let's start processing more concurrent tasks.
- else
- {
- int concurrentTasksWaitingCount = m_concurrentTaskScheduler.m_tasks.Count;
-
- if (concurrentTasksWaitingCount > 0 && !exclusiveTasksAreWaiting && m_processingCount < m_maxConcurrencyLevel)
- {
- // Launch concurrent task processing, up to the allowed limit
- for (int i = 0; i < concurrentTasksWaitingCount && m_processingCount < m_maxConcurrencyLevel; ++i)
- {
- ++m_processingCount;
- if (!TryQueueThreadPoolWorkItem(fairly))
- {
- try
- {
- processingTask = new Task(thisPair => ((ConcurrentExclusiveSchedulerPair)thisPair!).ProcessConcurrentTasks(), this,
- default, GetCreationOptionsForTask(fairly));
- processingTask.Start(m_underlyingTaskScheduler); // See above logic for why we use new + Start rather than StartNew
- }
- catch (Exception e)
- {
- --m_processingCount;
- FaultWithTask(processingTask ?? Task.FromException(e));
- }
- }
- }
- }
- }
-
- // Check to see if all tasks have completed and if completion has been requested.
- CleanupStateIfCompletingAndQuiesced();
- }
- else Debug.Assert(m_processingCount == EXCLUSIVE_PROCESSING_SENTINEL, "The processing count must be the sentinel if it's not >= 0.");
- }
-
- /// <summary>Queues concurrent or exclusive task processing to the ThreadPool if the underlying scheduler is the default.</summary>
- /// <param name="fairly">Whether tasks should be scheduled fairly with regards to other tasks.</param>
- /// <returns>true if we're targeting the thread pool such that a worker could be queued; otherwise, false.</returns>
- private bool TryQueueThreadPoolWorkItem(bool fairly)
- {
- if (TaskScheduler.Default == m_underlyingTaskScheduler)
- {
- IThreadPoolWorkItem workItem = m_threadPoolWorkItem ??= new SchedulerWorkItem(this);
- ThreadPool.UnsafeQueueUserWorkItemInternal(workItem, preferLocal: !fairly);
- return true;
- }
-
- return false;
- }
-
- /// <summary>
- /// Processes exclusive tasks serially until either there are no more to process
- /// or we've reached our user-specified maximum limit.
- /// </summary>
- private void ProcessExclusiveTasks()
- {
- Debug.Assert(m_processingCount == EXCLUSIVE_PROCESSING_SENTINEL, "Processing exclusive tasks requires being in exclusive mode.");
- Debug.Assert(!m_exclusiveTaskScheduler.m_tasks.IsEmpty, "Processing exclusive tasks requires tasks to be processed.");
- ContractAssertMonitorStatus(ValueLock, held: false);
- try
- {
- // Note that we're processing exclusive tasks on the current thread
- Debug.Assert(m_threadProcessingMode.Value == ProcessingMode.NotCurrentlyProcessing,
- "This thread should not yet be involved in this pair's processing.");
- m_threadProcessingMode.Value = ProcessingMode.ProcessingExclusiveTask;
-
- // Process up to the maximum number of items per task allowed
- for (int i = 0; i < m_maxItemsPerTask; i++)
- {
- // Get the next available exclusive task. If we can't find one, bail.
- Task? exclusiveTask;
- if (!m_exclusiveTaskScheduler.m_tasks.TryDequeue(out exclusiveTask)) break;
-
- // Execute the task. If the scheduler was previously faulted,
- // this task could have been faulted when it was queued; ignore such tasks.
- if (!exclusiveTask.IsFaulted) m_exclusiveTaskScheduler.ExecuteTask(exclusiveTask);
- }
- }
- finally
- {
- // We're no longer processing exclusive tasks on the current thread
- Debug.Assert(m_threadProcessingMode.Value == ProcessingMode.ProcessingExclusiveTask,
- "Somehow we ended up escaping exclusive mode.");
- m_threadProcessingMode.Value = ProcessingMode.NotCurrentlyProcessing;
-
- lock (ValueLock)
- {
- // When this task was launched, we tracked it by setting m_processingCount to WRITER_IN_PROGRESS.
- // now reset it to 0. Then check to see whether there's more processing to be done.
- // There might be more concurrent tasks available, for example, if concurrent tasks arrived
- // after we exited the loop, or if we exited the loop while concurrent tasks were still
- // available but we hit our maxItemsPerTask limit.
- Debug.Assert(m_processingCount == EXCLUSIVE_PROCESSING_SENTINEL, "The processing mode should not have deviated from exclusive.");
- m_processingCount = 0;
- ProcessAsyncIfNecessary(true);
- }
- }
- }
-
- /// <summary>
- /// Processes concurrent tasks serially until either there are no more to process,
- /// we've reached our user-specified maximum limit, or exclusive tasks have arrived.
- /// </summary>
- private void ProcessConcurrentTasks()
- {
- Debug.Assert(m_processingCount > 0, "Processing concurrent tasks requires us to be in concurrent mode.");
- ContractAssertMonitorStatus(ValueLock, held: false);
- try
- {
- // Note that we're processing concurrent tasks on the current thread
- Debug.Assert(m_threadProcessingMode.Value == ProcessingMode.NotCurrentlyProcessing,
- "This thread should not yet be involved in this pair's processing.");
- m_threadProcessingMode.Value = ProcessingMode.ProcessingConcurrentTasks;
-
- // Process up to the maximum number of items per task allowed
- for (int i = 0; i < m_maxItemsPerTask; i++)
- {
- // Get the next available concurrent task. If we can't find one, bail.
- Task? concurrentTask;
- if (!m_concurrentTaskScheduler.m_tasks.TryDequeue(out concurrentTask)) break;
-
- // Execute the task. If the scheduler was previously faulted,
- // this task could have been faulted when it was queued; ignore such tasks.
- if (!concurrentTask.IsFaulted) m_concurrentTaskScheduler.ExecuteTask(concurrentTask);
-
- // Now check to see if exclusive tasks have arrived; if any have, they take priority
- // so we'll bail out here. Note that we could have checked this condition
- // in the for loop's condition, but that could lead to extra overhead
- // in the case where a concurrent task arrives, this task is launched, and then
- // before entering the loop an exclusive task arrives. If we didn't execute at
- // least one task, we would have spent all of the overhead to launch a
- // task but with none of the benefit. There's of course also an inherent
- // race condition here with regards to exclusive tasks arriving, and we're ok with
- // executing one more concurrent task than we should before giving priority to exclusive tasks.
- if (!m_exclusiveTaskScheduler.m_tasks.IsEmpty) break;
- }
- }
- finally
- {
- // We're no longer processing concurrent tasks on the current thread
- Debug.Assert(m_threadProcessingMode.Value == ProcessingMode.ProcessingConcurrentTasks,
- "Somehow we ended up escaping concurrent mode.");
- m_threadProcessingMode.Value = ProcessingMode.NotCurrentlyProcessing;
-
- lock (ValueLock)
- {
- // When this task was launched, we tracked it with a positive processing count;
- // decrement that count. Then check to see whether there's more processing to be done.
- // There might be more concurrent tasks available, for example, if concurrent tasks arrived
- // after we exited the loop, or if we exited the loop while concurrent tasks were still
- // available but we hit our maxItemsPerTask limit.
- Debug.Assert(m_processingCount > 0, "The procesing mode should not have deviated from concurrent.");
- if (m_processingCount > 0) --m_processingCount;
- ProcessAsyncIfNecessary(true);
- }
- }
- }
-
- /// <summary>
- /// Holder for lazily-initialized state about the completion of a scheduler pair.
- /// Completion is only triggered either by rare exceptional conditions or by
- /// the user calling Complete, and as such we only lazily initialize this
- /// state in one of those conditions or if the user explicitly asks for
- /// the Completion.
- /// </summary>
- private sealed class CompletionState : Task
- {
- /// <summary>Whether the scheduler has had completion requested.</summary>
- /// <remarks>This variable is not volatile, so to gurantee safe reading reads, Volatile.Read is used in TryExecuteTaskInline.</remarks>
- internal bool m_completionRequested;
- /// <summary>Whether completion processing has been queued.</summary>
- internal bool m_completionQueued;
- /// <summary>Unrecoverable exceptions incurred while processing.</summary>
- internal List<Exception>? m_exceptions;
- }
-
- /// <summary>Reusable immutable work item that can be scheduled to the thread pool to run processing.</summary>
- private sealed class SchedulerWorkItem : IThreadPoolWorkItem
- {
- private readonly ConcurrentExclusiveSchedulerPair _pair;
-
- internal SchedulerWorkItem(ConcurrentExclusiveSchedulerPair pair) => _pair = pair;
-
- void IThreadPoolWorkItem.Execute()
- {
- if (_pair.m_processingCount == EXCLUSIVE_PROCESSING_SENTINEL)
- {
- _pair.ProcessExclusiveTasks();
- }
- else
- {
- _pair.ProcessConcurrentTasks();
- }
- }
- }
-
- /// <summary>
- /// A scheduler shim used to queue tasks to the pair and execute those tasks on request of the pair.
- /// </summary>
- [DebuggerDisplay("Count={CountForDebugger}, MaxConcurrencyLevel={m_maxConcurrencyLevel}, Id={Id}")]
- [DebuggerTypeProxy(typeof(ConcurrentExclusiveTaskScheduler.DebugView))]
- private sealed class ConcurrentExclusiveTaskScheduler : TaskScheduler
- {
- /// <summary>Cached delegate for invoking TryExecuteTaskShim.</summary>
- private static readonly Func<object?, bool> s_tryExecuteTaskShim = new Func<object?, bool>(TryExecuteTaskShim);
- /// <summary>The parent pair.</summary>
- private readonly ConcurrentExclusiveSchedulerPair m_pair;
- /// <summary>The maximum concurrency level for the scheduler.</summary>
- private readonly int m_maxConcurrencyLevel;
- /// <summary>The processing mode of this scheduler, exclusive or concurrent.</summary>
- private readonly ProcessingMode m_processingMode;
- /// <summary>Gets the queue of tasks for this scheduler.</summary>
- internal readonly IProducerConsumerQueue<Task> m_tasks;
-
- /// <summary>Initializes the scheduler.</summary>
- /// <param name="pair">The parent pair.</param>
- /// <param name="maxConcurrencyLevel">The maximum degree of concurrency this scheduler may use.</param>
- /// <param name="processingMode">The processing mode of this scheduler.</param>
- internal ConcurrentExclusiveTaskScheduler(ConcurrentExclusiveSchedulerPair pair, int maxConcurrencyLevel, ProcessingMode processingMode)
- {
- Debug.Assert(pair != null, "Scheduler must be associated with a valid pair.");
- Debug.Assert(processingMode == ProcessingMode.ProcessingConcurrentTasks || processingMode == ProcessingMode.ProcessingExclusiveTask,
- "Scheduler must be for concurrent or exclusive processing.");
- Debug.Assert(
- (processingMode == ProcessingMode.ProcessingConcurrentTasks && (maxConcurrencyLevel >= 1 || maxConcurrencyLevel == UNLIMITED_PROCESSING)) ||
- (processingMode == ProcessingMode.ProcessingExclusiveTask && maxConcurrencyLevel == 1),
- "If we're in concurrent mode, our concurrency level should be positive or unlimited. If exclusive, it should be 1.");
-
- m_pair = pair;
- m_maxConcurrencyLevel = maxConcurrencyLevel;
- m_processingMode = processingMode;
- m_tasks = (processingMode == ProcessingMode.ProcessingExclusiveTask) ?
- (IProducerConsumerQueue<Task>)new SingleProducerSingleConsumerQueue<Task>() :
- (IProducerConsumerQueue<Task>)new MultiProducerMultiConsumerQueue<Task>();
- }
-
- /// <summary>Gets the maximum concurrency level this scheduler is able to support.</summary>
- public override int MaximumConcurrencyLevel => m_maxConcurrencyLevel;
-
- /// <summary>Queues a task to the scheduler.</summary>
- /// <param name="task">The task to be queued.</param>
- protected internal override void QueueTask(Task task)
- {
- Debug.Assert(task != null, "Infrastructure should have provided a non-null task.");
- lock (m_pair.ValueLock)
- {
- // If the scheduler has already had completion requested, no new work is allowed to be scheduled
- if (m_pair.CompletionRequested) throw new InvalidOperationException(GetType().ToString());
-
- // Queue the task, and then let the pair know that more work is now available to be scheduled
- m_tasks.Enqueue(task);
- m_pair.ProcessAsyncIfNecessary();
- }
- }
-
- /// <summary>Executes a task on this scheduler.</summary>
- /// <param name="task">The task to be executed.</param>
- internal void ExecuteTask(Task task)
- {
- Debug.Assert(task != null, "Infrastructure should have provided a non-null task.");
- base.TryExecuteTask(task);
- }
-
- /// <summary>Tries to execute the task synchronously on this scheduler.</summary>
- /// <param name="task">The task to execute.</param>
- /// <param name="taskWasPreviouslyQueued">Whether the task was previously queued to the scheduler.</param>
- /// <returns>true if the task could be executed; otherwise, false.</returns>
- protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
- {
- Debug.Assert(task != null, "Infrastructure should have provided a non-null task.");
-
- // If the scheduler has had completion requested, no new work is allowed to be scheduled.
- // A non-locked read on m_completionRequested (in CompletionRequested) is acceptable here because:
- // a) we don't need to be exact... a Complete call could come in later in the function anyway
- // b) this is only a fast path escape hatch. To actually inline the task,
- // we need to be inside of an already executing task, and in such a case,
- // while completion may have been requested, we can't have shutdown yet.
- if (!taskWasPreviouslyQueued && m_pair.CompletionRequested) return false;
-
- // We know the implementation of the default scheduler and how it will behave.
- // As it's the most common underlying scheduler, we optimize for it.
- bool isDefaultScheduler = m_pair.m_underlyingTaskScheduler == TaskScheduler.Default;
-
- // If we're targeting the default scheduler and taskWasPreviouslyQueued is true,
- // we know that the default scheduler will only allow it to be inlined
- // if we're on a thread pool thread (but it won't always allow it in that case,
- // since it'll only allow inlining if it can find the task in the local queue).
- // As such, if we're not on a thread pool thread, we know for sure the
- // task won't be inlined, so let's not even try.
- if (isDefaultScheduler && taskWasPreviouslyQueued && !Thread.CurrentThread.IsThreadPoolThread)
- {
- return false;
- }
- else
- {
- // If a task is already running on this thread, allow inline execution to proceed.
- // If there's already a task from this scheduler running on the current thread, we know it's safe
- // to run this task, in effect temporarily taking that task's count allocation.
- if (m_pair.m_threadProcessingMode.Value == m_processingMode)
- {
- // If we're targeting the default scheduler and taskWasPreviouslyQueued is false,
- // we know the default scheduler will allow it, so we can just execute it here.
- // Otherwise, delegate to the target scheduler's inlining.
- return (isDefaultScheduler && !taskWasPreviouslyQueued) ?
- TryExecuteTask(task) :
- TryExecuteTaskInlineOnTargetScheduler(task);
- }
- }
-
- // We're not in the context of a task already executing on this scheduler. Bail.
- return false;
- }
-
- /// <summary>
- /// Implements a reasonable approximation for TryExecuteTaskInline on the underlying scheduler,
- /// which we can't call directly on the underlying scheduler.
- /// </summary>
- /// <param name="task">The task to execute inline if possible.</param>
- /// <returns>true if the task was inlined successfully; otherwise, false.</returns>
- private bool TryExecuteTaskInlineOnTargetScheduler(Task task)
- {
- // We'd like to simply call TryExecuteTaskInline here, but we can't.
- // As there's no built-in API for this, a workaround is to create a new task that,
- // when executed, will simply call TryExecuteTask to run the real task, and then
- // we run our new shim task synchronously on the target scheduler. If all goes well,
- // our synchronous invocation will succeed in running the shim task on the current thread,
- // which will in turn run the real task on the current thread. If the scheduler
- // doesn't allow that execution, RunSynchronously will block until the underlying scheduler
- // is able to invoke the task, which might account for an additional but unavoidable delay.
- // Once it's done, we can return whether the task executed by returning the
- // shim task's Result, which is in turn the result of TryExecuteTask.
- var t = new Task<bool>(s_tryExecuteTaskShim, Tuple.Create(this, task));
- try
- {
- t.RunSynchronously(m_pair.m_underlyingTaskScheduler);
- return t.Result;
- }
- catch
- {
- Debug.Assert(t.IsFaulted, "Task should be faulted due to the scheduler faulting it and throwing the exception.");
- _ = t.Exception;
- throw;
- }
- finally { t.Dispose(); }
- }
-
- /// <summary>Shim used to invoke this.TryExecuteTask(task).</summary>
- /// <param name="state">A tuple of the ConcurrentExclusiveTaskScheduler and the task to execute.</param>
- /// <returns>true if the task was successfully inlined; otherwise, false.</returns>
- /// <remarks>
- /// This method is separated out not because of performance reasons but so that
- /// the SecuritySafeCritical attribute may be employed.
- /// </remarks>
- private static bool TryExecuteTaskShim(object? state)
- {
- Debug.Assert(state is Tuple<ConcurrentExclusiveTaskScheduler, Task>);
- var tuple = (Tuple<ConcurrentExclusiveTaskScheduler, Task>)state;
- return tuple.Item1.TryExecuteTask(tuple.Item2);
- }
-
- /// <summary>Gets for debugging purposes the tasks scheduled to this scheduler.</summary>
- /// <returns>An enumerable of the tasks queued.</returns>
- protected override IEnumerable<Task> GetScheduledTasks() { return m_tasks; }
-
- /// <summary>Gets the number of tasks queued to this scheduler.</summary>
- private int CountForDebugger => m_tasks.Count;
-
- /// <summary>Provides a debug view for ConcurrentExclusiveTaskScheduler.</summary>
- private sealed class DebugView
- {
- /// <summary>The scheduler being debugged.</summary>
- private readonly ConcurrentExclusiveTaskScheduler m_taskScheduler;
-
- /// <summary>Initializes the debug view.</summary>
- /// <param name="scheduler">The scheduler being debugged.</param>
- public DebugView(ConcurrentExclusiveTaskScheduler scheduler)
- {
- Debug.Assert(scheduler != null, "Need a scheduler with which to construct the debug view.");
- m_taskScheduler = scheduler;
- }
-
- /// <summary>Gets this pair's maximum allowed concurrency level.</summary>
- public int MaximumConcurrencyLevel => m_taskScheduler.m_maxConcurrencyLevel;
- /// <summary>Gets the tasks scheduled to this scheduler.</summary>
- public IEnumerable<Task> ScheduledTasks => m_taskScheduler.m_tasks;
- /// <summary>Gets the scheduler pair with which this scheduler is associated.</summary>
- public ConcurrentExclusiveSchedulerPair SchedulerPair => m_taskScheduler.m_pair;
- }
- }
-
- /// <summary>Provides a debug view for ConcurrentExclusiveSchedulerPair.</summary>
- private sealed class DebugView
- {
- /// <summary>The pair being debugged.</summary>
- private readonly ConcurrentExclusiveSchedulerPair m_pair;
-
- /// <summary>Initializes the debug view.</summary>
- /// <param name="pair">The pair being debugged.</param>
- public DebugView(ConcurrentExclusiveSchedulerPair pair)
- {
- Debug.Assert(pair != null, "Need a pair with which to construct the debug view.");
- m_pair = pair;
- }
-
- /// <summary>Gets a representation of the execution state of the pair.</summary>
- public ProcessingMode Mode => m_pair.ModeForDebugger;
- /// <summary>Gets the number of tasks waiting to run exclusively.</summary>
- public IEnumerable<Task> ScheduledExclusive => m_pair.m_exclusiveTaskScheduler.m_tasks;
- /// <summary>Gets the number of tasks waiting to run concurrently.</summary>
- public IEnumerable<Task> ScheduledConcurrent => m_pair.m_concurrentTaskScheduler.m_tasks;
- /// <summary>Gets the number of tasks currently being executed.</summary>
- public int CurrentlyExecutingTaskCount => (m_pair.m_processingCount == EXCLUSIVE_PROCESSING_SENTINEL) ? 1 : m_pair.m_processingCount;
- /// <summary>Gets the underlying task scheduler that actually executes the tasks.</summary>
- public TaskScheduler TargetScheduler => m_pair.m_underlyingTaskScheduler;
- }
-
- /// <summary>Gets an enumeration for debugging that represents the current state of the scheduler pair.</summary>
- /// <remarks>This is only for debugging. It does not take the necessary locks to be useful for runtime usage.</remarks>
- private ProcessingMode ModeForDebugger
- {
- get
- {
- // If our completion task is done, so are we.
- if (m_completionState != null && m_completionState.IsCompleted) return ProcessingMode.Completed;
-
- // Otherwise, summarize our current state.
- ProcessingMode mode = ProcessingMode.NotCurrentlyProcessing;
- if (m_processingCount == EXCLUSIVE_PROCESSING_SENTINEL) mode |= ProcessingMode.ProcessingExclusiveTask;
- if (m_processingCount >= 1) mode |= ProcessingMode.ProcessingConcurrentTasks;
- if (CompletionRequested) mode |= ProcessingMode.Completing;
- return mode;
- }
- }
-
- /// <summary>Asserts that a given synchronization object is either held or not held.</summary>
- /// <param name="syncObj">The monitor to check.</param>
- /// <param name="held">Whether we want to assert that it's currently held or not held.</param>
- [Conditional("DEBUG")]
- private static void ContractAssertMonitorStatus(object syncObj, bool held)
- {
- Debug.Assert(syncObj != null, "The monitor object to check must be provided.");
- Debug.Assert(Monitor.IsEntered(syncObj) == held, "The locking scheme was not correctly followed.");
- }
-
- /// <summary>Gets the options to use for tasks.</summary>
- /// <param name="isReplacementReplica">If this task is being created to replace another.</param>
- /// <remarks>
- /// These options should be used for all tasks that have the potential to run user code or
- /// that are repeatedly spawned and thus need a modicum of fair treatment.
- /// </remarks>
- /// <returns>The options to use.</returns>
- internal static TaskCreationOptions GetCreationOptionsForTask(bool isReplacementReplica = false)
- {
- TaskCreationOptions options = TaskCreationOptions.DenyChildAttach;
- if (isReplacementReplica) options |= TaskCreationOptions.PreferFairness;
- return options;
- }
-
- /// <summary>Provides an enumeration that represents the current state of the scheduler pair.</summary>
- [Flags]
- private enum ProcessingMode : byte
- {
- /// <summary>The scheduler pair is currently dormant, with no work scheduled.</summary>
- NotCurrentlyProcessing = 0x0,
- /// <summary>The scheduler pair has queued processing for exclusive tasks.</summary>
- ProcessingExclusiveTask = 0x1,
- /// <summary>The scheduler pair has queued processing for concurrent tasks.</summary>
- ProcessingConcurrentTasks = 0x2,
- /// <summary>Completion has been requested.</summary>
- Completing = 0x4,
- /// <summary>The scheduler pair is finished processing.</summary>
- Completed = 0x8
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs
deleted file mode 100644
index 71181d7502f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs
+++ /dev/null
@@ -1,1377 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// A task that produces a value.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// Represents an asynchronous operation that produces a result at some time in the future.
- /// </summary>
- /// <typeparam name="TResult">
- /// The type of the result produced by this <see cref="Task{TResult}"/>.
- /// </typeparam>
- /// <remarks>
- /// <para>
- /// <see cref="Task{TResult}"/> instances may be created in a variety of ways. The most common approach is by
- /// using the task's <see cref="Factory"/> property to retrieve a <see
- /// cref="System.Threading.Tasks.TaskFactory{TResult}"/> instance that can be used to create tasks for several
- /// purposes. For example, to create a <see cref="Task{TResult}"/> that runs a function, the factory's StartNew
- /// method may be used:
- /// <code>
- /// // C#
- /// var t = Task&lt;int&gt;.Factory.StartNew(() => GenerateResult());
- /// - or -
- /// var t = Task.Factory.StartNew(() => GenerateResult());
- ///
- /// ' Visual Basic
- /// Dim t = Task&lt;int&gt;.Factory.StartNew(Function() GenerateResult())
- /// - or -
- /// Dim t = Task.Factory.StartNew(Function() GenerateResult())
- /// </code>
- /// </para>
- /// <para>
- /// The <see cref="Task{TResult}"/> class also provides constructors that initialize the task but that do not
- /// schedule it for execution. For performance reasons, the StartNew method should be the
- /// preferred mechanism for creating and scheduling computational tasks, but for scenarios where creation
- /// and scheduling must be separated, the constructors may be used, and the task's
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see>
- /// method may then be used to schedule the task for execution at a later time.
- /// </para>
- /// <para>
- /// All members of <see cref="Task{TResult}"/>, except for
- /// <see cref="System.Threading.Tasks.Task.Dispose()">Dispose</see>, are thread-safe
- /// and may be used from multiple threads concurrently.
- /// </para>
- /// </remarks>
- [DebuggerTypeProxy(typeof(SystemThreadingTasks_FutureDebugView<>))]
- [DebuggerDisplay("Id = {Id}, Status = {Status}, Method = {DebuggerDisplayMethodDescription}, Result = {DebuggerDisplayResultDescription}")]
- public class Task<TResult> : Task
- {
- // The value itself, if set.
- [MaybeNull] internal TResult m_result = default!;
-
- private static readonly TaskFactory<TResult> s_Factory = new TaskFactory<TResult>();
-
- // Extract rarely used helper for a static method in a separate type so that the Func<Task<Task>, Task<TResult>>
- // generic instantiations don't contribute to all Task instantiations, but only those where WhenAny is used.
- internal static class TaskWhenAnyCast
- {
- // Delegate used by:
- // public static Task<Task<TResult>> WhenAny<TResult>(IEnumerable<Task<TResult>> tasks);
- // public static Task<Task<TResult>> WhenAny<TResult>(params Task<TResult>[] tasks);
- // Used to "cast" from Task<Task> to Task<Task<TResult>>.
- internal static readonly Func<Task<Task>, Task<TResult>> Value = completed => (Task<TResult>)completed.Result;
- }
-
- // Construct a promise-style task without any options.
- internal Task()
- {
- }
-
- // Construct a promise-style task with state and options.
- internal Task(object? state, TaskCreationOptions options) :
- base(state, options, promiseStyle: true)
- {
- }
-
-
- // Construct a pre-completed Task<TResult>
- internal Task(TResult result) :
- base(false, TaskCreationOptions.None, default)
- {
- m_result = result;
- }
-
- internal Task(bool canceled, [AllowNull] TResult result, TaskCreationOptions creationOptions, CancellationToken ct)
- : base(canceled, creationOptions, ct)
- {
- if (!canceled)
- {
- m_result = result;
- }
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task{TResult}"/> with the specified function.
- /// </summary>
- /// <param name="function">
- /// The delegate that represents the code to execute in the task. When the function has completed,
- /// the task's <see cref="Result"/> property will be set to return the result value of the function.
- /// </param>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="function"/> argument is null.
- /// </exception>
- public Task(Func<TResult> function)
- : this(function, null, default,
- TaskCreationOptions.None, InternalTaskOptions.None, null)
- {
- }
-
-
- /// <summary>
- /// Initializes a new <see cref="Task{TResult}"/> with the specified function.
- /// </summary>
- /// <param name="function">
- /// The delegate that represents the code to execute in the task. When the function has completed,
- /// the task's <see cref="Result"/> property will be set to return the result value of the function.
- /// </param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> to be assigned to this task.</param>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="function"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task(Func<TResult> function, CancellationToken cancellationToken)
- : this(function, null, cancellationToken,
- TaskCreationOptions.None, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task{TResult}"/> with the specified function and creation options.
- /// </summary>
- /// <param name="function">
- /// The delegate that represents the code to execute in the task. When the function has completed,
- /// the task's <see cref="Result"/> property will be set to return the result value of the function.
- /// </param>
- /// <param name="creationOptions">
- /// The <see cref="System.Threading.Tasks.TaskCreationOptions">TaskCreationOptions</see> used to
- /// customize the task's behavior.
- /// </param>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="function"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="creationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskCreationOptions"/>.
- /// </exception>
- public Task(Func<TResult> function, TaskCreationOptions creationOptions)
- : this(function, Task.InternalCurrentIfAttached(creationOptions), default, creationOptions, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task{TResult}"/> with the specified function and creation options.
- /// </summary>
- /// <param name="function">
- /// The delegate that represents the code to execute in the task. When the function has completed,
- /// the task's <see cref="Result"/> property will be set to return the result value of the function.
- /// </param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <param name="creationOptions">
- /// The <see cref="System.Threading.Tasks.TaskCreationOptions">TaskCreationOptions</see> used to
- /// customize the task's behavior.
- /// </param>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="function"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="creationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskCreationOptions"/>.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task(Func<TResult> function, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
- : this(function, Task.InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task{TResult}"/> with the specified function and state.
- /// </summary>
- /// <param name="function">
- /// The delegate that represents the code to execute in the task. When the function has completed,
- /// the task's <see cref="Result"/> property will be set to return the result value of the function.
- /// </param>
- /// <param name="state">An object representing data to be used by the action.</param>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="function"/> argument is null.
- /// </exception>
- public Task(Func<object?, TResult> function, object? state)
- : this(function, state, null, default,
- TaskCreationOptions.None, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task{TResult}"/> with the specified action, state, and options.
- /// </summary>
- /// <param name="function">
- /// The delegate that represents the code to execute in the task. When the function has completed,
- /// the task's <see cref="Result"/> property will be set to return the result value of the function.
- /// </param>
- /// <param name="state">An object representing data to be used by the function.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> to be assigned to the new task.</param>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="function"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task(Func<object?, TResult> function, object? state, CancellationToken cancellationToken)
- : this(function, state, null, cancellationToken,
- TaskCreationOptions.None, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task{TResult}"/> with the specified action, state, and options.
- /// </summary>
- /// <param name="function">
- /// The delegate that represents the code to execute in the task. When the function has completed,
- /// the task's <see cref="Result"/> property will be set to return the result value of the function.
- /// </param>
- /// <param name="state">An object representing data to be used by the function.</param>
- /// <param name="creationOptions">
- /// The <see cref="System.Threading.Tasks.TaskCreationOptions">TaskCreationOptions</see> used to
- /// customize the task's behavior.
- /// </param>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="function"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="creationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskCreationOptions"/>.
- /// </exception>
- public Task(Func<object?, TResult> function, object? state, TaskCreationOptions creationOptions)
- : this(function, state, Task.InternalCurrentIfAttached(creationOptions), default,
- creationOptions, InternalTaskOptions.None, null)
- {
- }
-
-
- /// <summary>
- /// Initializes a new <see cref="Task{TResult}"/> with the specified action, state, and options.
- /// </summary>
- /// <param name="function">
- /// The delegate that represents the code to execute in the task. When the function has completed,
- /// the task's <see cref="Result"/> property will be set to return the result value of the function.
- /// </param>
- /// <param name="state">An object representing data to be used by the function.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> to be assigned to the new task.</param>
- /// <param name="creationOptions">
- /// The <see cref="System.Threading.Tasks.TaskCreationOptions">TaskCreationOptions</see> used to
- /// customize the task's behavior.
- /// </param>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="function"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="creationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskCreationOptions"/>.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task(Func<object?, TResult> function, object? state, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
- : this(function, state, Task.InternalCurrentIfAttached(creationOptions), cancellationToken,
- creationOptions, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Creates a new future object.
- /// </summary>
- /// <param name="parent">The parent task for this future.</param>
- /// <param name="valueSelector">A function that yields the future value.</param>
- /// <param name="scheduler">The task scheduler which will be used to execute the future.</param>
- /// <param name="cancellationToken">The CancellationToken for the task.</param>
- /// <param name="creationOptions">Options to control the future's behavior.</param>
- /// <param name="internalOptions">Internal options to control the future's behavior.</param>
- internal Task(Func<TResult> valueSelector, Task? parent, CancellationToken cancellationToken,
- TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler? scheduler) :
- base(valueSelector, null, parent, cancellationToken, creationOptions, internalOptions, scheduler)
- {
- }
-
- /// <summary>
- /// Creates a new future object.
- /// </summary>
- /// <param name="parent">The parent task for this future.</param>
- /// <param name="state">An object containing data to be used by the action; may be null.</param>
- /// <param name="valueSelector">A function that yields the future value.</param>
- /// <param name="cancellationToken">The CancellationToken for the task.</param>
- /// <param name="scheduler">The task scheduler which will be used to execute the future.</param>
- /// <param name="creationOptions">Options to control the future's behavior.</param>
- /// <param name="internalOptions">Internal options to control the future's behavior.</param>
- internal Task(Delegate valueSelector, object? state, Task? parent, CancellationToken cancellationToken,
- TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler? scheduler) :
- base(valueSelector, state, parent, cancellationToken, creationOptions, internalOptions, scheduler)
- {
- }
-
-
- // Internal method used by TaskFactory<TResult>.StartNew() methods
- internal static Task<TResult> StartNew(Task? parent, Func<TResult> function, CancellationToken cancellationToken,
- TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
- {
- if (function == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function);
- }
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- // Create and schedule the future.
- Task<TResult> f = new Task<TResult>(function, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler);
-
- f.ScheduleAndStart(false);
- return f;
- }
-
- // Internal method used by TaskFactory<TResult>.StartNew() methods
- internal static Task<TResult> StartNew(Task? parent, Func<object?, TResult> function, object? state, CancellationToken cancellationToken,
- TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
- {
- if (function == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function);
- }
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- // Create and schedule the future.
- Task<TResult> f = new Task<TResult>(function, state, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler);
-
- f.ScheduleAndStart(false);
- return f;
- }
-
- // Debugger support
- private string DebuggerDisplayResultDescription =>
- IsCompletedSuccessfully ? "" + m_result : SR.TaskT_DebuggerNoResult;
-
- // Debugger support
- private string DebuggerDisplayMethodDescription =>
- m_action?.Method.ToString() ?? "{null}";
-
-
- // internal helper function breaks out logic used by TaskCompletionSource
- internal bool TrySetResult([AllowNull] TResult result)
- {
- Debug.Assert(m_action == null, "Task<T>.TrySetResult(): non-null m_action");
-
- bool returnValue = false;
-
- // "Reserve" the completion for this task, while making sure that: (1) No prior reservation
- // has been made, (2) The result has not already been set, (3) An exception has not previously
- // been recorded, and (4) Cancellation has not been requested.
- //
- // If the reservation is successful, then set the result and finish completion processing.
- if (AtomicStateUpdate(TASK_STATE_COMPLETION_RESERVED,
- TASK_STATE_COMPLETION_RESERVED | TASK_STATE_RAN_TO_COMPLETION | TASK_STATE_FAULTED | TASK_STATE_CANCELED))
- {
- m_result = result;
-
- // Signal completion, for waiting tasks
-
- // This logic used to be:
- // Finish(false);
- // However, that goes through a windy code path, involves many non-inlineable functions
- // and which can be summarized more concisely with the following snippet from
- // FinishStageTwo, omitting everything that doesn't pertain to TrySetResult.
- Interlocked.Exchange(ref m_stateFlags, m_stateFlags | TASK_STATE_RAN_TO_COMPLETION);
- ContingentProperties? props = m_contingentProperties;
- if (props != null)
- {
- NotifyParentIfPotentiallyAttachedTask();
- props.SetCompleted();
- }
- FinishContinuations();
- returnValue = true;
- }
-
- return returnValue;
- }
-
- // Transitions the promise task into a successfully completed state with the specified result.
- // This is dangerous, as no synchronization is used, and thus must only be used
- // before this task is handed out to any consumers, before any continuations are hooked up,
- // before its wait handle is accessed, etc. It's use is limited to places like in FromAsync
- // where the operation completes synchronously, and thus we know we can forcefully complete
- // the task, avoiding expensive completion paths, before the task is actually given to anyone.
- internal void DangerousSetResult(TResult result)
- {
- Debug.Assert(!IsCompleted, "The promise must not yet be completed.");
-
- // If we have a parent, we need to notify it of the completion. Take the slow path to handle that.
- if (m_contingentProperties?.m_parent != null)
- {
- bool success = TrySetResult(result);
-
- // Nobody else has had a chance to complete this Task yet, so we should succeed.
- Debug.Assert(success);
- }
- else
- {
- m_result = result;
- m_stateFlags |= TASK_STATE_RAN_TO_COMPLETION;
- }
- }
-
- /// <summary>
- /// Gets the result value of this <see cref="Task{TResult}"/>.
- /// </summary>
- /// <remarks>
- /// The get accessor for this property ensures that the asynchronous operation is complete before
- /// returning. Once the result of the computation is available, it is stored and will be returned
- /// immediately on later calls to <see cref="Result"/>.
- /// </remarks>
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public TResult Result =>
- IsWaitNotificationEnabledOrNotRanToCompletion ?
- GetResultCore(waitCompletionNotification: true) :
- m_result;
-
- /// <summary>
- /// Gets the result value of this <see cref="Task{TResult}"/> once the task has completed successfully.
- /// </summary>
- /// <remarks>
- /// This version of Result should only be used if the task completed successfully and if there's
- /// no debugger wait notification enabled for this task.
- /// </remarks>
- internal TResult ResultOnSuccess
- {
- get
- {
- Debug.Assert(!IsWaitNotificationEnabledOrNotRanToCompletion,
- "Should only be used when the task completed successfully and there's no wait notification enabled");
- return m_result;
- }
- }
-
- // Implements Result. Result delegates to this method if the result isn't already available.
- internal TResult GetResultCore(bool waitCompletionNotification)
- {
- // If the result has not been calculated yet, wait for it.
- if (!IsCompleted) InternalWait(Timeout.Infinite, default); // won't throw if task faulted or canceled; that's handled below
-
- // Notify the debugger of the wait completion if it's requested such a notification
- if (waitCompletionNotification) NotifyDebuggerOfWaitCompletionIfNecessary();
-
- // Throw an exception if appropriate.
- if (!IsCompletedSuccessfully) ThrowIfExceptional(includeTaskCanceledExceptions: true);
-
- // We shouldn't be here if the result has not been set.
- Debug.Assert(IsCompletedSuccessfully, "Task<T>.Result getter: Expected result to have been set.");
-
- return m_result;
- }
-
- /// <summary>
- /// Provides access to factory methods for creating <see cref="Task{TResult}"/> instances.
- /// </summary>
- /// <remarks>
- /// The factory returned from <see cref="Factory"/> is a default instance
- /// of <see cref="System.Threading.Tasks.TaskFactory{TResult}"/>, as would result from using
- /// the default constructor on the factory type.
- /// </remarks>
- public static new TaskFactory<TResult> Factory => s_Factory;
-
- /// <summary>
- /// Evaluates the value selector of the Task which is passed in as an object and stores the result.
- /// </summary>
- internal override void InnerInvoke()
- {
- // Invoke the delegate
- Debug.Assert(m_action != null);
- if (m_action is Func<TResult> func)
- {
- m_result = func();
- return;
- }
-
- if (m_action is Func<object?, TResult> funcWithState)
- {
- m_result = funcWithState(m_stateObject);
- return;
- }
- Debug.Fail("Invalid m_action in Task<TResult>");
- }
-
- #region Await Support
-
- /// <summary>Gets an awaiter used to await this <see cref="System.Threading.Tasks.Task{TResult}"/>.</summary>
- /// <returns>An awaiter instance.</returns>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- public new TaskAwaiter<TResult> GetAwaiter()
- {
- return new TaskAwaiter<TResult>(this);
- }
-
- /// <summary>Configures an awaiter used to await this <see cref="System.Threading.Tasks.Task{TResult}"/>.</summary>
- /// <param name="continueOnCapturedContext">
- /// true to attempt to marshal the continuation back to the original context captured; otherwise, false.
- /// </param>
- /// <returns>An object used to await this task.</returns>
- public new ConfiguredTaskAwaitable<TResult> ConfigureAwait(bool continueOnCapturedContext)
- {
- return new ConfiguredTaskAwaitable<TResult>(this, continueOnCapturedContext);
- }
-
- #endregion
-
- #region Continuation methods
-
- #region Action<Task<TResult>> continuations
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- public Task ContinueWith(Action<Task<TResult>> continuationAction)
- {
- return ContinueWith(continuationAction, TaskScheduler.Current, default, TaskContinuationOptions.None);
- }
-
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWith(Action<Task<TResult>> continuationAction, CancellationToken cancellationToken)
- {
- return ContinueWith(continuationAction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None);
- }
-
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- public Task ContinueWith(Action<Task<TResult>> continuationAction, TaskScheduler scheduler)
- {
- return ContinueWith(continuationAction, scheduler, default, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed. If the continuation criteria specified through the <paramref
- /// name="continuationOptions"/> parameter are not met, the continuation task will be canceled
- /// instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- public Task ContinueWith(Action<Task<TResult>> continuationAction, TaskContinuationOptions continuationOptions)
- {
- return ContinueWith(continuationAction, TaskScheduler.Current, default, continuationOptions);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its
- /// execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed. If the criteria specified through the <paramref name="continuationOptions"/> parameter
- /// are not met, the continuation task will be canceled instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWith(Action<Task<TResult>> continuationAction, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- return ContinueWith(continuationAction, scheduler, cancellationToken, continuationOptions);
- }
-
- // Same as the above overload, only with a stack mark.
- internal Task ContinueWith(Action<Task<TResult>> continuationAction, TaskScheduler scheduler, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions)
- {
- if (continuationAction == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction);
- }
-
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- TaskCreationOptions creationOptions;
- InternalTaskOptions internalOptions;
- CreationOptionsFromContinuationOptions(
- continuationOptions,
- out creationOptions,
- out internalOptions);
-
- Task continuationTask = new ContinuationTaskFromResultTask<TResult>(
- this, continuationAction, null,
- creationOptions, internalOptions
- );
-
- // Register the continuation. If synchronous execution is requested, this may
- // actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
-
- return continuationTask;
- }
- #endregion
-
- #region Action<Task<TResult>, Object> continuations
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation action.</param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- public Task ContinueWith(Action<Task<TResult>, object?> continuationAction, object? state)
- {
- return ContinueWith(continuationAction, state, TaskScheduler.Current, default, TaskContinuationOptions.None);
- }
-
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation action.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWith(Action<Task<TResult>, object?> continuationAction, object? state, CancellationToken cancellationToken)
- {
- return ContinueWith(continuationAction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None);
- }
-
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation action.</param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- public Task ContinueWith(Action<Task<TResult>, object?> continuationAction, object? state, TaskScheduler scheduler)
- {
- return ContinueWith(continuationAction, state, scheduler, default, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation action.</param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed. If the continuation criteria specified through the <paramref
- /// name="continuationOptions"/> parameter are not met, the continuation task will be canceled
- /// instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- public Task ContinueWith(Action<Task<TResult>, object?> continuationAction, object? state, TaskContinuationOptions continuationOptions)
- {
- return ContinueWith(continuationAction, state, TaskScheduler.Current, default, continuationOptions);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation action.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its
- /// execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed. If the criteria specified through the <paramref name="continuationOptions"/> parameter
- /// are not met, the continuation task will be canceled instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWith(Action<Task<TResult>, object?> continuationAction, object? state, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- return ContinueWith(continuationAction, state, scheduler, cancellationToken, continuationOptions);
- }
-
- // Same as the above overload, only with a stack mark.
- internal Task ContinueWith(Action<Task<TResult>, object?> continuationAction, object? state, TaskScheduler scheduler, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions)
- {
- if (continuationAction == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction);
- }
-
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- TaskCreationOptions creationOptions;
- InternalTaskOptions internalOptions;
- CreationOptionsFromContinuationOptions(
- continuationOptions,
- out creationOptions,
- out internalOptions);
-
- Task continuationTask = new ContinuationTaskFromResultTask<TResult>(
- this, continuationAction, state,
- creationOptions, internalOptions
- );
-
- // Register the continuation. If synchronous execution is requested, this may
- // actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
-
- return continuationTask;
- }
-
- #endregion
-
- #region Func<Task<TResult>,TNewResult> continuations
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <typeparam name="TNewResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TNewResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TNewResult}"/> will not be scheduled for execution until the current
- /// task has completed, whether it completes due to running to completion successfully, faulting due
- /// to an unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- public Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, TNewResult> continuationFunction)
- {
- return ContinueWith<TNewResult>(continuationFunction, TaskScheduler.Current, default, TaskContinuationOptions.None);
- }
-
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <typeparam name="TNewResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <returns>A new continuation <see cref="Task{TNewResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TNewResult}"/> will not be scheduled for execution until the current
- /// task has completed, whether it completes due to running to completion successfully, faulting due
- /// to an unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, TNewResult> continuationFunction, CancellationToken cancellationToken)
- {
- return ContinueWith<TNewResult>(continuationFunction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <typeparam name="TNewResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TNewResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TNewResult}"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- public Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, TNewResult> continuationFunction, TaskScheduler scheduler)
- {
- return ContinueWith<TNewResult>(continuationFunction, scheduler, default, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <typeparam name="TNewResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TNewResult}"/>.</returns>
- /// <remarks>
- /// <para>
- /// The returned <see cref="Task{TNewResult}"/> will not be scheduled for execution until the current
- /// task has completed, whether it completes due to running to completion successfully, faulting due
- /// to an unhandled exception, or exiting out early due to being canceled.
- /// </para>
- /// <para>
- /// The <paramref name="continuationFunction"/>, when executed, should return a <see
- /// cref="Task{TNewResult}"/>. This task's completion state will be transferred to the task returned
- /// from the ContinueWith call.
- /// </para>
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- public Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, TNewResult> continuationFunction, TaskContinuationOptions continuationOptions)
- {
- return ContinueWith<TNewResult>(continuationFunction, TaskScheduler.Current, default, continuationOptions);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <typeparam name="TNewResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be passed as
- /// an argument this completed task.
- /// </param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its
- /// execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TNewResult}"/>.</returns>
- /// <remarks>
- /// <para>
- /// The returned <see cref="Task{TNewResult}"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </para>
- /// <para>
- /// The <paramref name="continuationFunction"/>, when executed, should return a <see cref="Task{TNewResult}"/>.
- /// This task's completion state will be transferred to the task returned from the
- /// ContinueWith call.
- /// </para>
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, TNewResult> continuationFunction, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- return ContinueWith<TNewResult>(continuationFunction, scheduler, cancellationToken, continuationOptions);
- }
-
- // Same as the above overload, just with a stack mark.
- internal Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, TNewResult> continuationFunction, TaskScheduler scheduler,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions)
- {
- if (continuationFunction == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
- }
-
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- TaskCreationOptions creationOptions;
- InternalTaskOptions internalOptions;
- CreationOptionsFromContinuationOptions(
- continuationOptions,
- out creationOptions,
- out internalOptions);
-
- Task<TNewResult> continuationFuture = new ContinuationResultTaskFromResultTask<TResult, TNewResult>(
- this, continuationFunction, null,
- creationOptions, internalOptions
- );
-
- // Register the continuation. If synchronous execution is requested, this may
- // actually invoke the continuation before returning.
- ContinueWithCore(continuationFuture, scheduler, cancellationToken, continuationOptions);
-
- return continuationFuture;
- }
- #endregion
-
- #region Func<Task<TResult>, Object,TNewResult> continuations
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <typeparam name="TNewResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation function.</param>
- /// <returns>A new continuation <see cref="Task{TNewResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TNewResult}"/> will not be scheduled for execution until the current
- /// task has completed, whether it completes due to running to completion successfully, faulting due
- /// to an unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- public Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, object?, TNewResult> continuationFunction, object? state)
- {
- return ContinueWith<TNewResult>(continuationFunction, state, TaskScheduler.Current, default, TaskContinuationOptions.None);
- }
-
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <typeparam name="TNewResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation function.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <returns>A new continuation <see cref="Task{TNewResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TNewResult}"/> will not be scheduled for execution until the current
- /// task has completed, whether it completes due to running to completion successfully, faulting due
- /// to an unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, object?, TNewResult> continuationFunction, object? state,
- CancellationToken cancellationToken)
- {
- return ContinueWith<TNewResult>(continuationFunction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <typeparam name="TNewResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation function.</param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TNewResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TNewResult}"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- public Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, object?, TNewResult> continuationFunction, object? state,
- TaskScheduler scheduler)
- {
- return ContinueWith<TNewResult>(continuationFunction, state, scheduler, default, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <typeparam name="TNewResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation function.</param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TNewResult}"/>.</returns>
- /// <remarks>
- /// <para>
- /// The returned <see cref="Task{TNewResult}"/> will not be scheduled for execution until the current
- /// task has completed, whether it completes due to running to completion successfully, faulting due
- /// to an unhandled exception, or exiting out early due to being canceled.
- /// </para>
- /// <para>
- /// The <paramref name="continuationFunction"/>, when executed, should return a <see
- /// cref="Task{TNewResult}"/>. This task's completion state will be transferred to the task returned
- /// from the ContinueWith call.
- /// </para>
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- public Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, object?, TNewResult> continuationFunction, object? state,
- TaskContinuationOptions continuationOptions)
- {
- return ContinueWith<TNewResult>(continuationFunction, state, TaskScheduler.Current, default, continuationOptions);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task{TResult}"/> completes.
- /// </summary>
- /// <typeparam name="TNewResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task{TResult}"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation function.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its
- /// execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TNewResult}"/>.</returns>
- /// <remarks>
- /// <para>
- /// The returned <see cref="Task{TNewResult}"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </para>
- /// <para>
- /// The <paramref name="continuationFunction"/>, when executed, should return a <see cref="Task{TNewResult}"/>.
- /// This task's completion state will be transferred to the task returned from the
- /// ContinueWith call.
- /// </para>
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, object?, TNewResult> continuationFunction, object? state,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- return ContinueWith<TNewResult>(continuationFunction, state, scheduler, cancellationToken, continuationOptions);
- }
-
- // Same as the above overload, just with a stack mark.
- internal Task<TNewResult> ContinueWith<TNewResult>(Func<Task<TResult>, object?, TNewResult> continuationFunction, object? state,
- TaskScheduler scheduler, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions)
- {
- if (continuationFunction == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
- }
-
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- TaskCreationOptions creationOptions;
- InternalTaskOptions internalOptions;
- CreationOptionsFromContinuationOptions(
- continuationOptions,
- out creationOptions,
- out internalOptions);
-
- Task<TNewResult> continuationFuture = new ContinuationResultTaskFromResultTask<TResult, TNewResult>(
- this, continuationFunction, state,
- creationOptions, internalOptions
- );
-
- // Register the continuation. If synchronous execution is requested, this may
- // actually invoke the continuation before returning.
- ContinueWithCore(continuationFuture, scheduler, cancellationToken, continuationOptions);
-
- return continuationFuture;
- }
-
- #endregion
-
- #endregion
- }
-
- // Proxy class for better debugging experience
- internal class SystemThreadingTasks_FutureDebugView<TResult>
- {
- private readonly Task<TResult> m_task;
-
- public SystemThreadingTasks_FutureDebugView(Task<TResult> task)
- {
- Debug.Assert(task != null);
- m_task = task;
- }
-
- [MaybeNull] public TResult Result => m_task.Status == TaskStatus.RanToCompletion ? m_task.Result : default!;
- public object? AsyncState => m_task.AsyncState;
- public TaskCreationOptions CreationOptions => m_task.CreationOptions;
- public Exception? Exception => m_task.Exception;
- public int Id => m_task.Id;
- public bool CancellationPending => (m_task.Status == TaskStatus.WaitingToRun) && m_task.CancellationToken.IsCancellationRequested;
- public TaskStatus Status => m_task.Status;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs
deleted file mode 100644
index d66db7b7379..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs
+++ /dev/null
@@ -1,2108 +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 System.Diagnostics;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// Provides support for creating and scheduling
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task{TResult}</see> objects.
- /// </summary>
- /// <typeparam name="TResult">The type of the results that are available though
- /// the <see cref="System.Threading.Tasks.Task{TResult}">Task{TResult}</see> objects that are associated with
- /// the methods in this class.</typeparam>
- /// <remarks>
- /// <para>
- /// There are many common patterns for which tasks are relevant. The <see cref="TaskFactory{TResult}"/>
- /// class encodes some of these patterns into methods that pick up default settings, which are
- /// configurable through its constructors.
- /// </para>
- /// <para>
- /// A default instance of <see cref="TaskFactory{TResult}"/> is available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}.Factory">Task{TResult}.Factory</see> property.
- /// </para>
- /// </remarks>
- public class TaskFactory<TResult>
- {
- // Member variables, DefaultScheduler, other properties and ctors
- // copied right out of TaskFactory... Lots of duplication here...
- // Should we be thinking about a TaskFactoryBase class?
-
- // member variables
- private readonly CancellationToken m_defaultCancellationToken;
- private readonly TaskScheduler? m_defaultScheduler;
- private readonly TaskCreationOptions m_defaultCreationOptions;
- private readonly TaskContinuationOptions m_defaultContinuationOptions;
-
- private TaskScheduler DefaultScheduler => m_defaultScheduler ?? TaskScheduler.Current;
-
- // sister method to above property -- avoids a TLS lookup
- private TaskScheduler GetDefaultScheduler(Task? currTask)
- {
- if (m_defaultScheduler != null) return m_defaultScheduler;
- else if ((currTask != null)
- && ((currTask.CreationOptions & TaskCreationOptions.HideScheduler) == 0)
- )
- return currTask.ExecutingTaskScheduler!; // a "current" task must be executing, which means it must have a scheduler
- else return TaskScheduler.Default;
- }
-
- /* Constructors */
-
- /// <summary>
- /// Initializes a <see cref="TaskFactory{TResult}"/> instance with the default configuration.
- /// </summary>
- /// <remarks>
- /// This constructor creates a <see cref="TaskFactory{TResult}"/> instance with a default configuration. The
- /// <see cref="TaskCreationOptions"/> property is initialized to
- /// <see cref="System.Threading.Tasks.TaskCreationOptions.None">TaskCreationOptions.None</see>, the
- /// <see cref="TaskContinuationOptions"/> property is initialized to <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.None">TaskContinuationOptions.None</see>,
- /// and the <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> property is
- /// initialized to the current scheduler (see <see
- /// cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>).
- /// </remarks>
- public TaskFactory()
- : this(default, TaskCreationOptions.None, TaskContinuationOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a <see cref="TaskFactory{TResult}"/> instance with the default configuration.
- /// </summary>
- /// <param name="cancellationToken">The default <see cref="CancellationToken"/> that will be assigned
- /// to tasks created by this <see cref="TaskFactory"/> unless another CancellationToken is explicitly specified
- /// while calling the factory methods.</param>
- /// <remarks>
- /// This constructor creates a <see cref="TaskFactory{TResult}"/> instance with a default configuration. The
- /// <see cref="TaskCreationOptions"/> property is initialized to
- /// <see cref="System.Threading.Tasks.TaskCreationOptions.None">TaskCreationOptions.None</see>, the
- /// <see cref="TaskContinuationOptions"/> property is initialized to <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.None">TaskContinuationOptions.None</see>,
- /// and the <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> property is
- /// initialized to the current scheduler (see <see
- /// cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>).
- /// </remarks>
- public TaskFactory(CancellationToken cancellationToken)
- : this(cancellationToken, TaskCreationOptions.None, TaskContinuationOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a <see cref="TaskFactory{TResult}"/> instance with the specified configuration.
- /// </summary>
- /// <param name="scheduler">
- /// The <see cref="System.Threading.Tasks.TaskScheduler">
- /// TaskScheduler</see> to use to schedule any tasks created with this TaskFactory{TResult}. A null value
- /// indicates that the current TaskScheduler should be used.
- /// </param>
- /// <remarks>
- /// With this constructor, the
- /// <see cref="TaskCreationOptions"/> property is initialized to
- /// <see cref="System.Threading.Tasks.TaskCreationOptions.None">TaskCreationOptions.None</see>, the
- /// <see cref="TaskContinuationOptions"/> property is initialized to <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.None">TaskContinuationOptions.None</see>,
- /// and the <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> property is
- /// initialized to <paramref name="scheduler"/>, unless it's null, in which case the property is
- /// initialized to the current scheduler (see <see
- /// cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>).
- /// </remarks>
- public TaskFactory(TaskScheduler? scheduler) // null means to use TaskScheduler.Current
- : this(default, TaskCreationOptions.None, TaskContinuationOptions.None, scheduler)
- {
- }
-
- /// <summary>
- /// Initializes a <see cref="TaskFactory{TResult}"/> instance with the specified configuration.
- /// </summary>
- /// <param name="creationOptions">
- /// The default <see cref="System.Threading.Tasks.TaskCreationOptions">
- /// TaskCreationOptions</see> to use when creating tasks with this TaskFactory{TResult}.
- /// </param>
- /// <param name="continuationOptions">
- /// The default <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> to use when creating continuation tasks with this TaskFactory{TResult}.
- /// </param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument or the <paramref name="continuationOptions"/>
- /// argument specifies an invalid value.
- /// </exception>
- /// <remarks>
- /// With this constructor, the
- /// <see cref="TaskCreationOptions"/> property is initialized to <paramref name="creationOptions"/>,
- /// the
- /// <see cref="TaskContinuationOptions"/> property is initialized to <paramref
- /// name="continuationOptions"/>, and the <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> property is initialized to the
- /// current scheduler (see <see
- /// cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>).
- /// </remarks>
- public TaskFactory(TaskCreationOptions creationOptions, TaskContinuationOptions continuationOptions)
- : this(default, creationOptions, continuationOptions, null)
- {
- }
-
- /// <summary>
- /// Initializes a <see cref="TaskFactory{TResult}"/> instance with the specified configuration.
- /// </summary>
- /// <param name="cancellationToken">The default <see cref="CancellationToken"/> that will be assigned
- /// to tasks created by this <see cref="TaskFactory"/> unless another CancellationToken is explicitly specified
- /// while calling the factory methods.</param>
- /// <param name="creationOptions">
- /// The default <see cref="System.Threading.Tasks.TaskCreationOptions">
- /// TaskCreationOptions</see> to use when creating tasks with this TaskFactory{TResult}.
- /// </param>
- /// <param name="continuationOptions">
- /// The default <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> to use when creating continuation tasks with this TaskFactory{TResult}.
- /// </param>
- /// <param name="scheduler">
- /// The default <see cref="System.Threading.Tasks.TaskScheduler">
- /// TaskScheduler</see> to use to schedule any Tasks created with this TaskFactory{TResult}. A null value
- /// indicates that TaskScheduler.Current should be used.
- /// </param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument or the <paramref name="continuationOptions"/>
- /// argumentspecifies an invalid value.
- /// </exception>
- /// <remarks>
- /// With this constructor, the
- /// <see cref="TaskCreationOptions"/> property is initialized to <paramref name="creationOptions"/>,
- /// the
- /// <see cref="TaskContinuationOptions"/> property is initialized to <paramref
- /// name="continuationOptions"/>, and the <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> property is initialized to
- /// <paramref name="scheduler"/>, unless it's null, in which case the property is initialized to the
- /// current scheduler (see <see
- /// cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>).
- /// </remarks>
- public TaskFactory(CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskContinuationOptions continuationOptions, TaskScheduler? scheduler)
- {
- TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions);
- TaskFactory.CheckCreationOptions(creationOptions);
-
- m_defaultCancellationToken = cancellationToken;
- m_defaultScheduler = scheduler;
- m_defaultCreationOptions = creationOptions;
- m_defaultContinuationOptions = continuationOptions;
- }
-
- /* Properties */
-
- /// <summary>
- /// Gets the default <see cref="System.Threading.CancellationToken">CancellationToken</see> of this
- /// TaskFactory.
- /// </summary>
- /// <remarks>
- /// This property returns the default <see cref="CancellationToken"/> that will be assigned to all
- /// tasks created by this factory unless another CancellationToken value is explicitly specified
- /// during the call to the factory methods.
- /// </remarks>
- public CancellationToken CancellationToken => m_defaultCancellationToken;
-
- /// <summary>
- /// Gets the <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> of this
- /// TaskFactory{TResult}.
- /// </summary>
- /// <remarks>
- /// This property returns the default scheduler for this factory. It will be used to schedule all
- /// tasks unless another scheduler is explicitly specified during calls to this factory's methods.
- /// If null, <see cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>
- /// will be used.
- /// </remarks>
- public TaskScheduler? Scheduler => m_defaultScheduler;
-
- /// <summary>
- /// Gets the <see cref="System.Threading.Tasks.TaskCreationOptions">TaskCreationOptions
- /// </see> value of this TaskFactory{TResult}.
- /// </summary>
- /// <remarks>
- /// This property returns the default creation options for this factory. They will be used to create all
- /// tasks unless other options are explicitly specified during calls to this factory's methods.
- /// </remarks>
- public TaskCreationOptions CreationOptions => m_defaultCreationOptions;
-
- /// <summary>
- /// Gets the <see cref="System.Threading.Tasks.TaskCreationOptions">TaskContinuationOptions
- /// </see> value of this TaskFactory{TResult}.
- /// </summary>
- /// <remarks>
- /// This property returns the default continuation options for this factory. They will be used to create
- /// all continuation tasks unless other options are explicitly specified during calls to this factory's methods.
- /// </remarks>
- public TaskContinuationOptions ContinuationOptions => m_defaultContinuationOptions;
-
-
- /* StartNew */
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew(Func<TResult> function)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, m_defaultCancellationToken,
- m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew(Func<TResult> function, CancellationToken cancellationToken)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, cancellationToken,
- m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew(Func<TResult> function, TaskCreationOptions creationOptions)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, m_defaultCancellationToken,
- creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <param name="scheduler">The <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created <see cref="System.Threading.Tasks.Task{TResult}">
- /// Task{TResult}</see>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="scheduler"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew(Func<TResult> function, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler)
- {
- return Task<TResult>.StartNew(
- Task.InternalCurrentIfAttached(creationOptions), function, cancellationToken,
- creationOptions, InternalTaskOptions.None, scheduler);
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="function"/>
- /// delegate.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew(Func<object?, TResult> function, object? state)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, state, m_defaultCancellationToken,
- m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="function"/>
- /// delegate.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew(Func<object?, TResult> function, object? state, CancellationToken cancellationToken)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, state, cancellationToken,
- m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="function"/>
- /// delegate.</param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew(Func<object?, TResult> function, object? state, TaskCreationOptions creationOptions)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, state, m_defaultCancellationToken,
- creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="function"/>
- /// delegate.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="scheduler">The <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created <see cref="System.Threading.Tasks.Task{TResult}">
- /// Task{TResult}</see>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="scheduler"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew(Func<object?, TResult> function, object? state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler)
- {
- return Task<TResult>.StartNew(Task.InternalCurrentIfAttached(creationOptions), function, state, cancellationToken,
- creationOptions, InternalTaskOptions.None, scheduler);
- }
-
- //
- // APM Factory methods
- //
-
- // Common core logic for FromAsync calls. This minimizes the chance of "drift" between overload implementations.
- private static void FromAsyncCoreLogic(
- IAsyncResult iar,
- Func<IAsyncResult, TResult>? endFunction,
- Action<IAsyncResult>? endAction,
- Task<TResult> promise,
- bool requiresSynchronization)
- {
- Debug.Assert((endFunction != null) != (endAction != null), "Expected exactly one of endFunction/endAction to be non-null");
-
- Exception? ex = null;
- OperationCanceledException? oce = null;
- TResult result = default!;
-
- try
- {
- if (endFunction != null)
- {
- result = endFunction(iar);
- }
- else
- {
- endAction!(iar);
- }
- }
- catch (OperationCanceledException _oce) { oce = _oce; }
- catch (Exception e) { ex = e; }
- finally
- {
- if (oce != null)
- {
- promise.TrySetCanceled(oce.CancellationToken, oce);
- }
- else if (ex != null)
- {
- promise.TrySetException(ex);
- }
- else
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(promise, AsyncCausalityStatus.Completed);
-
- if (Task.s_asyncDebuggingEnabled)
- Task.RemoveFromActiveTasks(promise);
-
- if (requiresSynchronization)
- {
- promise.TrySetResult(result);
- }
- else
- {
- promise.DangerousSetResult(result);
- }
- }
- }
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that executes an end
- /// method function when a specified <see cref="System.IAsyncResult">IAsyncResult</see> completes.
- /// </summary>
- /// <param name="asyncResult">The IAsyncResult whose completion should trigger the processing of the
- /// <paramref name="endMethod"/>.</param>
- /// <param name="endMethod">The function delegate that processes the completed <paramref
- /// name="asyncResult"/>.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="asyncResult"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>A <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents the
- /// asynchronous operation.</returns>
- public Task<TResult> FromAsync(IAsyncResult asyncResult, Func<IAsyncResult, TResult> endMethod)
- {
- return FromAsyncImpl(asyncResult, endMethod, null, m_defaultCreationOptions, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that executes an end
- /// method function when a specified <see cref="System.IAsyncResult">IAsyncResult</see> completes.
- /// </summary>
- /// <param name="asyncResult">The IAsyncResult whose completion should trigger the processing of the
- /// <paramref name="endMethod"/>.</param>
- /// <param name="endMethod">The function delegate that processes the completed <paramref
- /// name="asyncResult"/>.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="asyncResult"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>A <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents the
- /// asynchronous operation.</returns>
- public Task<TResult> FromAsync(
- IAsyncResult asyncResult,
- Func<IAsyncResult, TResult> endMethod,
- TaskCreationOptions creationOptions)
- {
- return FromAsyncImpl(asyncResult, endMethod, null, creationOptions, DefaultScheduler);
- }
-
-
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that executes an end
- /// method function when a specified <see cref="System.IAsyncResult">IAsyncResult</see> completes.
- /// </summary>
- /// <param name="asyncResult">The IAsyncResult whose completion should trigger the processing of the
- /// <paramref name="endMethod"/>.</param>
- /// <param name="endMethod">The function delegate that processes the completed <paramref
- /// name="asyncResult"/>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the task that executes the end method.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="asyncResult"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>A <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents the
- /// asynchronous operation.</returns>
- public Task<TResult> FromAsync(
- IAsyncResult asyncResult,
- Func<IAsyncResult, TResult> endMethod,
- TaskCreationOptions creationOptions,
- TaskScheduler scheduler)
- {
- return FromAsyncImpl(asyncResult, endMethod, null, creationOptions, scheduler);
- }
-
- // We need this logic broken out into a static method so that the similar TaskFactory.FromAsync()
- // method can access the logic w/o declaring a TaskFactory<TResult> instance.
- internal static Task<TResult> FromAsyncImpl(
- IAsyncResult asyncResult,
- Func<IAsyncResult, TResult>? endFunction,
- Action<IAsyncResult>? endAction,
- TaskCreationOptions creationOptions,
- TaskScheduler scheduler)
- {
- if (asyncResult == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.asyncResult);
-
- if (endFunction == null && endAction == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.endMethod);
-
- Debug.Assert((endFunction != null) != (endAction != null), "Both endFunction and endAction were non-null");
-
- if (scheduler == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
-
- TaskFactory.CheckFromAsyncOptions(creationOptions, false);
-
- Task<TResult> promise = new Task<TResult>((object?)null, creationOptions);
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync");
-
- if (Task.s_asyncDebuggingEnabled)
- Task.AddToActiveTasks(promise);
-
- // Just specify this task as detached. No matter what happens, we want endMethod
- // to be called -- even if the parent is canceled. So we don't want to flow
- // RespectParentCancellation.
- Task t = new Task(new Action<object>(delegate
- {
- FromAsyncCoreLogic(asyncResult, endFunction, endAction, promise, requiresSynchronization: true);
- }),
- (object?)null, null,
- default, TaskCreationOptions.None, InternalTaskOptions.None, null);
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(t, "TaskFactory.FromAsync Callback");
-
- if (Task.s_asyncDebuggingEnabled)
- Task.AddToActiveTasks(t);
-
- if (asyncResult.IsCompleted)
- {
- try { t.InternalRunSynchronously(scheduler, waitForCompletion: false); }
- catch (Exception e) { promise.TrySetException(e); } // catch and log any scheduler exceptions
- }
- else
- {
- ThreadPool.RegisterWaitForSingleObject(
- asyncResult.AsyncWaitHandle,
- delegate
- {
- try { t.InternalRunSynchronously(scheduler, waitForCompletion: false); }
- catch (Exception e) { promise.TrySetException(e); } // catch and log any scheduler exceptions
- },
- null,
- Timeout.Infinite,
- true);
- }
-
- return promise;
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync(
- Func<AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod, object? state)
- {
- return FromAsyncImpl(beginMethod, endMethod, null, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync(
- Func<AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod, object? state, TaskCreationOptions creationOptions)
- {
- return FromAsyncImpl(beginMethod, endMethod, null, state, creationOptions);
- }
-
- // We need this logic broken out into a static method so that the similar TaskFactory.FromAsync()
- // method can access the logic w/o declaring a TaskFactory<TResult> instance.
- internal static Task<TResult> FromAsyncImpl(Func<AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult>? endFunction, Action<IAsyncResult>? endAction,
- object? state, TaskCreationOptions creationOptions)
- {
- if (beginMethod == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.beginMethod);
-
- if (endFunction == null && endAction == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.endMethod);
-
- Debug.Assert((endFunction != null) != (endAction != null), "Both endFunction and endAction were non-null");
-
- TaskFactory.CheckFromAsyncOptions(creationOptions, true);
-
- Task<TResult> promise = new Task<TResult>(state, creationOptions);
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name);
-
- if (Task.s_asyncDebuggingEnabled)
- Task.AddToActiveTasks(promise);
-
- try
- {
- // if we don't require synchronization, a faster set result path is taken
- IAsyncResult asyncResult = beginMethod(iar =>
- {
- if (!iar.CompletedSynchronously)
- FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true);
- }, state);
- if (asyncResult.CompletedSynchronously)
- {
- Debug.Assert(asyncResult.IsCompleted, "If the operation completed synchronously, it must be completed.");
- FromAsyncCoreLogic(asyncResult, endFunction, endAction, promise, requiresSynchronization: false);
- }
- }
- catch
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(promise, AsyncCausalityStatus.Error);
-
- if (Task.s_asyncDebuggingEnabled)
- Task.RemoveFromActiveTasks(promise);
-
- // Make sure we don't leave promise "dangling".
- promise.TrySetResult();
- throw;
- }
-
- return promise;
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1>(
- Func<TArg1, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod,
- TArg1 arg1, object? state)
- {
- return FromAsyncImpl(beginMethod, endMethod, null, arg1, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1>(
- Func<TArg1, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod,
- TArg1 arg1, object? state, TaskCreationOptions creationOptions)
- {
- return FromAsyncImpl(beginMethod, endMethod, null, arg1, state, creationOptions);
- }
-
- // We need this logic broken out into a static method so that the similar TaskFactory.FromAsync()
- // method can access the logic w/o declaring a TaskFactory<TResult> instance.
- internal static Task<TResult> FromAsyncImpl<TArg1>(Func<TArg1, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult>? endFunction, Action<IAsyncResult>? endAction,
- TArg1 arg1, object? state, TaskCreationOptions creationOptions)
- {
- if (beginMethod == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.beginMethod);
-
- if (endFunction == null && endAction == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.endFunction);
-
- Debug.Assert((endFunction != null) != (endAction != null), "Both endFunction and endAction were non-null");
-
- TaskFactory.CheckFromAsyncOptions(creationOptions, true);
-
- Task<TResult> promise = new Task<TResult>(state, creationOptions);
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name);
-
- if (Task.s_asyncDebuggingEnabled)
- Task.AddToActiveTasks(promise);
-
- try
- {
- // if we don't require synchronization, a faster set result path is taken
- IAsyncResult asyncResult = beginMethod(arg1, iar =>
- {
- if (!iar.CompletedSynchronously)
- FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true);
- }, state);
- if (asyncResult.CompletedSynchronously)
- {
- Debug.Assert(asyncResult.IsCompleted, "If the operation completed synchronously, it must be completed.");
- FromAsyncCoreLogic(asyncResult, endFunction, endAction, promise, requiresSynchronization: false);
- }
- }
- catch
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(promise, AsyncCausalityStatus.Error);
-
- if (Task.s_asyncDebuggingEnabled)
- Task.RemoveFromActiveTasks(promise);
-
- // Make sure we don't leave promise "dangling".
- promise.TrySetResult();
- throw;
- }
-
- return promise;
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1, TArg2>(
- Func<TArg1, TArg2, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod,
- TArg1 arg1, TArg2 arg2, object? state)
- {
- return FromAsyncImpl(beginMethod, endMethod, null, arg1, arg2, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1, TArg2>(
- Func<TArg1, TArg2, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod,
- TArg1 arg1, TArg2 arg2, object? state, TaskCreationOptions creationOptions)
- {
- return FromAsyncImpl(beginMethod, endMethod, null, arg1, arg2, state, creationOptions);
- }
-
- // We need this logic broken out into a static method so that the similar TaskFactory.FromAsync()
- // method can access the logic w/o declaring a TaskFactory<TResult> instance.
- internal static Task<TResult> FromAsyncImpl<TArg1, TArg2>(Func<TArg1, TArg2, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult>? endFunction, Action<IAsyncResult>? endAction,
- TArg1 arg1, TArg2 arg2, object? state, TaskCreationOptions creationOptions)
- {
- if (beginMethod == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.beginMethod);
-
- if (endFunction == null && endAction == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.endMethod);
-
- Debug.Assert((endFunction != null) != (endAction != null), "Both endFunction and endAction were non-null");
-
- TaskFactory.CheckFromAsyncOptions(creationOptions, true);
-
- Task<TResult> promise = new Task<TResult>(state, creationOptions);
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name);
-
- if (Task.s_asyncDebuggingEnabled)
- Task.AddToActiveTasks(promise);
-
- try
- {
- // if we don't require synchronization, a faster set result path is taken
- IAsyncResult asyncResult = beginMethod(arg1, arg2, iar =>
- {
- if (!iar.CompletedSynchronously)
- FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true);
- }, state);
- if (asyncResult.CompletedSynchronously)
- {
- Debug.Assert(asyncResult.IsCompleted, "If the operation completed synchronously, it must be completed.");
- FromAsyncCoreLogic(asyncResult, endFunction, endAction, promise, requiresSynchronization: false);
- }
- }
- catch
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(promise, AsyncCausalityStatus.Error);
-
- if (Task.s_asyncDebuggingEnabled)
- Task.RemoveFromActiveTasks(promise);
-
- // Make sure we don't leave promise "dangling".
- promise.TrySetResult();
- throw;
- }
-
- return promise;
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TArg3">The type of the third argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg3">The third argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1, TArg2, TArg3>(
- Func<TArg1, TArg2, TArg3, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod,
- TArg1 arg1, TArg2 arg2, TArg3 arg3, object? state)
- {
- return FromAsyncImpl(beginMethod, endMethod, null, arg1, arg2, arg3, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TArg3">The type of the third argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg3">The third argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1, TArg2, TArg3>(
- Func<TArg1, TArg2, TArg3, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod,
- TArg1 arg1, TArg2 arg2, TArg3 arg3, object? state, TaskCreationOptions creationOptions)
- {
- return FromAsyncImpl(beginMethod, endMethod, null, arg1, arg2, arg3, state, creationOptions);
- }
-
- // We need this logic broken out into a static method so that the similar TaskFactory.FromAsync()
- // method can access the logic w/o declaring a TaskFactory<TResult> instance.
- internal static Task<TResult> FromAsyncImpl<TArg1, TArg2, TArg3>(Func<TArg1, TArg2, TArg3, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult>? endFunction, Action<IAsyncResult>? endAction,
- TArg1 arg1, TArg2 arg2, TArg3 arg3, object? state, TaskCreationOptions creationOptions)
- {
- if (beginMethod == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.beginMethod);
-
- if (endFunction == null && endAction == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.endMethod);
-
- Debug.Assert((endFunction != null) != (endAction != null), "Both endFunction and endAction were non-null");
-
- TaskFactory.CheckFromAsyncOptions(creationOptions, true);
-
- Task<TResult> promise = new Task<TResult>(state, creationOptions);
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name);
-
- if (Task.s_asyncDebuggingEnabled)
- Task.AddToActiveTasks(promise);
-
- try
- {
- // if we don't require synchronization, a faster set result path is taken
- IAsyncResult asyncResult = beginMethod(arg1, arg2, arg3, iar =>
- {
- if (!iar.CompletedSynchronously)
- FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true);
- }, state);
- if (asyncResult.CompletedSynchronously)
- {
- Debug.Assert(asyncResult.IsCompleted, "If the operation completed synchronously, it must be completed.");
- FromAsyncCoreLogic(asyncResult, endFunction, endAction, promise, requiresSynchronization: false);
- }
- }
- catch
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(promise, AsyncCausalityStatus.Error);
-
- if (Task.s_asyncDebuggingEnabled)
- Task.RemoveFromActiveTasks(promise);
-
- // Make sure we don't leave the promise "dangling".
- promise.TrySetResult();
- throw;
- }
-
- return promise;
- }
-
- /// <summary>
- /// Special internal-only FromAsync support used by System.IO to wrap
- /// APM implementations with minimal overhead, avoiding unnecessary closure
- /// and delegate allocations.
- /// </summary>
- /// <typeparam name="TInstance">Specifies the type of the instance on which the APM implementation lives.</typeparam>
- /// <typeparam name="TArgs">Specifies the type containing the arguments.</typeparam>
- /// <param name="thisRef">The instance from which the begin and end methods are invoked.</param>
- /// <param name="beginMethod">The begin method.</param>
- /// <param name="endMethod">The end method.</param>
- /// <param name="args">The arguments.</param>
- /// <returns>A task representing the asynchronous operation.</returns>
- internal static Task<TResult> FromAsyncTrim<TInstance, TArgs>(
- TInstance thisRef, TArgs args,
- Func<TInstance, TArgs, AsyncCallback, object, IAsyncResult> beginMethod,
- Func<TInstance, IAsyncResult, TResult> endMethod)
- where TInstance : class
- {
- // Validate arguments, but only with asserts, as this is an internal only implementation.
- Debug.Assert(thisRef != null, "Expected a non-null thisRef");
- Debug.Assert(beginMethod != null, "Expected a non-null beginMethod");
- Debug.Assert(endMethod != null, "Expected a non-null endMethod");
-
- // Create the promise and start the operation.
- // No try/catch is necessary here as we want exceptions to bubble out, and because
- // the task doesn't have AttachedToParent set on it, there's no need to complete it in
- // case of an exception occurring... we can just let it go unresolved.
- var promise = new FromAsyncTrimPromise<TInstance>(thisRef, endMethod);
- IAsyncResult asyncResult = beginMethod(thisRef, args, FromAsyncTrimPromise<TInstance>.s_completeFromAsyncResult, promise);
-
- // If the IAsyncResult completed asynchronously, completing the promise will be handled by the callback.
- // If it completed synchronously, we'll handle that here.
- if (asyncResult.CompletedSynchronously)
- {
- Debug.Assert(asyncResult.IsCompleted, "If the operation completed synchronously, it must be completed.");
- promise.Complete(thisRef, endMethod, asyncResult, requiresSynchronization: false);
- }
-
- // Return the promise
- return promise;
- }
-
- /// <summary>
- /// A specialized task used by FromAsyncTrim. Stores relevant information as instance
- /// state so that we can avoid unnecessary closure/delegate allocations.
- /// </summary>
- /// <typeparam name="TInstance">Specifies the type of the instance on which the APM implementation lives.</typeparam>
- private sealed class FromAsyncTrimPromise<TInstance> : Task<TResult> where TInstance : class
- {
- /// <summary>A cached delegate used as the callback for the BeginXx method.</summary>
- internal static readonly AsyncCallback s_completeFromAsyncResult = CompleteFromAsyncResult;
-
- /// <summary>A reference to the object on which the begin/end methods are invoked.</summary>
- private TInstance? m_thisRef;
- /// <summary>The end method.</summary>
- private Func<TInstance, IAsyncResult, TResult>? m_endMethod;
-
- /// <summary>Initializes the promise.</summary>
- /// <param name="thisRef">A reference to the object on which the begin/end methods are invoked.</param>
- /// <param name="endMethod">The end method.</param>
- internal FromAsyncTrimPromise(TInstance thisRef, Func<TInstance, IAsyncResult, TResult> endMethod)
- {
- Debug.Assert(thisRef != null, "Expected a non-null thisRef");
- Debug.Assert(endMethod != null, "Expected a non-null endMethod");
- m_thisRef = thisRef;
- m_endMethod = endMethod;
- }
-
- /// <summary>
- /// Completes the asynchronous operation using information in the IAsyncResult.
- /// IAsyncResult.AsyncState needs to be the FromAsyncTrimPromise to complete.
- /// </summary>
- /// <param name="asyncResult">The IAsyncResult for the async operation.</param>
- internal static void CompleteFromAsyncResult(IAsyncResult asyncResult)
- {
- // Validate argument
- if (asyncResult == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.asyncResult);
-
- var promise = asyncResult.AsyncState as FromAsyncTrimPromise<TInstance>;
- if (promise == null) ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple, ExceptionArgument.asyncResult);
-
- // Grab the relevant state and then null it out so that the task doesn't hold onto the state unnecessarily
- TInstance? thisRef = promise.m_thisRef;
- Func<TInstance, IAsyncResult, TResult>? endMethod = promise.m_endMethod;
- promise.m_thisRef = default;
- promise.m_endMethod = null;
- if (endMethod == null) ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple, ExceptionArgument.asyncResult);
-
- // Complete the promise. If the IAsyncResult completed synchronously,
- // we'll instead complete the promise at the call site.
- if (!asyncResult.CompletedSynchronously)
- {
- Debug.Assert(thisRef != null);
- promise.Complete(thisRef, endMethod, asyncResult, requiresSynchronization: true);
- }
- }
-
- /// <summary>Completes the promise.</summary>
- /// <param name="thisRef">The target instance on which the end method should be called.</param>
- /// <param name="endMethod">The end method to call to retrieve the result.</param>
- /// <param name="asyncResult">The IAsyncResult for the async operation.</param>
- /// <param name="requiresSynchronization">
- /// Whether completing the task requires synchronization. This should be true
- /// unless absolutely sure that the task has not yet been handed out to any consumers.
- /// </param>
- internal void Complete(
- TInstance thisRef, Func<TInstance, IAsyncResult, TResult> endMethod, IAsyncResult asyncResult,
- bool requiresSynchronization)
- {
- Debug.Assert(!IsCompleted, "The task should not have been completed yet.");
-
- // Run the end method and complete the task
- bool successfullySet;
- try
- {
- TResult result = endMethod(thisRef, asyncResult);
- if (requiresSynchronization)
- {
- successfullySet = TrySetResult(result);
- }
- else
- {
- // If requiresSynchronization is false, we can use the DangerousSetResult
- // method, which uses no synchronization to complete the task. This is
- // only valid when the operation is completing synchronously such
- // that the task has not yet been handed out to any consumers.
- DangerousSetResult(result);
- successfullySet = true;
- }
- }
- catch (OperationCanceledException oce)
- {
- successfullySet = TrySetCanceled(oce.CancellationToken, oce);
- }
- catch (Exception exc)
- {
- successfullySet = TrySetException(exc);
- }
- Debug.Assert(successfullySet, "Expected the task to not yet be completed");
- }
- }
-
- // Utility method to create a canceled future-style task.
- // Used by ContinueWhenAll/Any to bail out early on a pre-canceled token.
- private static Task<TResult> CreateCanceledTask(TaskContinuationOptions continuationOptions, CancellationToken ct)
- {
- TaskCreationOptions tco;
- Task.CreationOptionsFromContinuationOptions(continuationOptions, out tco, out _);
- return new Task<TResult>(true, default, tco, ct);
- }
-
- //
- // ContinueWhenAll() methods
- //
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in
- /// the <paramref name="tasks"/> array have completed.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task<TResult> ContinueWhenAll(Task[] tasks, Func<Task[], TResult> continuationFunction)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in
- /// the <paramref name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWhenAll(Task[] tasks, Func<Task[], TResult> continuationFunction, CancellationToken cancellationToken)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the <paramref
- /// name="tasks"/> array have completed.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task<TResult> ContinueWhenAll(Task[] tasks, Func<Task[], TResult> continuationFunction, TaskContinuationOptions continuationOptions)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the <paramref
- /// name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task<TResult> ContinueWhenAll(Task[] tasks, Func<Task[], TResult> continuationFunction,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task<TResult> ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAllImpl<TAntecedentResult>(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction,
- CancellationToken cancellationToken)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAllImpl<TAntecedentResult>(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task<TResult> ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction,
- TaskContinuationOptions continuationOptions)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAllImpl<TAntecedentResult>(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task<TResult> ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAllImpl<TAntecedentResult>(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler);
- }
-
-
- // Core implementation of ContinueWhenAll -- the generic version
- // Note: if you make any changes to this method, please do the same to the non-generic version too.
- internal static Task<TResult> ContinueWhenAllImpl<TAntecedentResult>(Task<TAntecedentResult>[] tasks,
- Func<Task<TAntecedentResult>[], TResult>? continuationFunction, Action<Task<TAntecedentResult>[]>? continuationAction,
- TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler)
- {
- // check arguments
- TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions);
- if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- // ArgumentNullException of continuationFunction or continuationAction is checked by the caller
- Debug.Assert((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null");
- if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
-
- // Check tasks array and make defensive copy
- Task<TAntecedentResult>[] tasksCopy = TaskFactory.CheckMultiContinuationTasksAndCopy<TAntecedentResult>(tasks);
-
- // Bail early if cancellation has been requested.
- if (cancellationToken.IsCancellationRequested
- && ((continuationOptions & TaskContinuationOptions.LazyCancellation) == 0)
- )
- {
- return CreateCanceledTask(continuationOptions, cancellationToken);
- }
-
- // Call common ContinueWhenAll() setup logic, extract starter task.
- Task<Task<TAntecedentResult>[]> starter = TaskFactory.CommonCWAllLogic(tasksCopy);
-
- // returned continuation task, off of starter
- if (continuationFunction != null)
- {
- return starter.ContinueWith<TResult>(
- GenericDelegateCache<TAntecedentResult, TResult>.CWAllFuncDelegate,
- continuationFunction, scheduler, cancellationToken, continuationOptions);
- }
- else
- {
- Debug.Assert(continuationAction != null);
-
- return starter.ContinueWith<TResult>(
- GenericDelegateCache<TAntecedentResult, TResult>.CWAllActionDelegate,
- continuationAction, scheduler, cancellationToken, continuationOptions);
- }
- }
-
- // Core implementation of ContinueWhenAll -- the non-generic version
- // Note: if you make any changes to this method, please do the same to the generic version too.
- internal static Task<TResult> ContinueWhenAllImpl(Task[] tasks,
- Func<Task[], TResult>? continuationFunction, Action<Task[]>? continuationAction,
- TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler)
- {
- // check arguments
- TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions);
- if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- // ArgumentNullException of continuationFunction or continuationAction is checked by the caller
- Debug.Assert((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null");
- if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
-
- // Check tasks array and make defensive copy
- Task[] tasksCopy = TaskFactory.CheckMultiContinuationTasksAndCopy(tasks);
-
- // Bail early if cancellation has been requested.
- if (cancellationToken.IsCancellationRequested
- && ((continuationOptions & TaskContinuationOptions.LazyCancellation) == 0)
- )
- {
- return CreateCanceledTask(continuationOptions, cancellationToken);
- }
-
- // Perform common ContinueWhenAll() setup logic, extract starter task
- Task<Task[]> starter = TaskFactory.CommonCWAllLogic(tasksCopy);
-
- // returned continuation task, off of starter
- if (continuationFunction != null)
- {
- return starter.ContinueWith(
- (completedTasks, state) =>
- {
- completedTasks.NotifyDebuggerOfWaitCompletionIfNecessary();
- Debug.Assert(state is Func<Task[], TResult>);
- return ((Func<Task[], TResult>)state)(completedTasks.Result);
- },
- continuationFunction, scheduler, cancellationToken, continuationOptions);
- }
- else
- {
- Debug.Assert(continuationAction != null);
- return starter.ContinueWith<TResult>(
- (completedTasks, state) =>
- {
- completedTasks.NotifyDebuggerOfWaitCompletionIfNecessary();
- Debug.Assert(state is Action<Task[]>);
- ((Action<Task[]>)state)(completedTasks.Result); return default!;
- },
- continuationAction, scheduler, cancellationToken, continuationOptions);
- }
- }
-
- //
- // ContinueWhenAny() methods
- //
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the <paramref
- /// name="tasks"/> array completes.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task<TResult> ContinueWhenAny(Task[] tasks, Func<Task, TResult> continuationFunction)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the <paramref
- /// name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWhenAny(Task[] tasks, Func<Task, TResult> continuationFunction, CancellationToken cancellationToken)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the <paramref
- /// name="tasks"/> array completes.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task<TResult> ContinueWhenAny(Task[] tasks, Func<Task, TResult> continuationFunction, TaskContinuationOptions continuationOptions)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the <paramref
- /// name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task<TResult> ContinueWhenAny(Task[] tasks, Func<Task, TResult> continuationFunction,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task<TResult> ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAnyImpl<TAntecedentResult>(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction,
- CancellationToken cancellationToken)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAnyImpl<TAntecedentResult>(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task<TResult> ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction,
- TaskContinuationOptions continuationOptions)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAnyImpl<TAntecedentResult>(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task<TResult> ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
-
- return ContinueWhenAnyImpl<TAntecedentResult>(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler);
- }
-
- // Core implementation of ContinueWhenAny, non-generic version
- // Note: if you make any changes to this method, be sure to do the same to the generic version
- internal static Task<TResult> ContinueWhenAnyImpl(Task[] tasks,
- Func<Task, TResult>? continuationFunction, Action<Task>? continuationAction,
- TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler)
- {
- // check arguments
- TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions);
- if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- if (tasks.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
-
- // ArgumentNullException of continuationFunction or continuationAction is checked by the caller
- Debug.Assert((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null");
- if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
-
- // Call common ContinueWhenAny() setup logic, extract starter
- Task<Task> starter = TaskFactory.CommonCWAnyLogic(tasks);
-
- // Bail early if cancellation has been requested.
- if (cancellationToken.IsCancellationRequested
- && ((continuationOptions & TaskContinuationOptions.LazyCancellation) == 0)
- )
- {
- return CreateCanceledTask(continuationOptions, cancellationToken);
- }
-
- // returned continuation task, off of starter
- if (continuationFunction != null)
- {
- return starter.ContinueWith(
- (completedTask, state) =>
- {
- Debug.Assert(state is Func<Task, TResult>);
- return ((Func<Task, TResult>)state)(completedTask.Result);
- },
- continuationFunction, scheduler, cancellationToken, continuationOptions);
- }
- else
- {
- Debug.Assert(continuationAction != null);
- return starter.ContinueWith<TResult>(
- (completedTask, state) =>
- {
- Debug.Assert(state is Action<Task>);
- ((Action<Task>)state)(completedTask.Result);
- return default!;
- },
- continuationAction, scheduler, cancellationToken, continuationOptions);
- }
- }
-
-
- // Core implementation of ContinueWhenAny, generic version
- // Note: if you make any changes to this method, be sure to do the same to the non-generic version
- internal static Task<TResult> ContinueWhenAnyImpl<TAntecedentResult>(Task<TAntecedentResult>[] tasks,
- Func<Task<TAntecedentResult>, TResult>? continuationFunction, Action<Task<TAntecedentResult>>? continuationAction,
- TaskContinuationOptions continuationOptions, CancellationToken cancellationToken, TaskScheduler scheduler)
- {
- // check arguments
- TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions);
- if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- if (tasks.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
- // ArgumentNullException of continuationFunction or continuationAction is checked by the caller
- Debug.Assert((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null");
- if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
-
- // Call common ContinueWhenAny setup logic, extract starter
- Task<Task> starter = TaskFactory.CommonCWAnyLogic(tasks);
-
- // Bail early if cancellation has been requested.
- if (cancellationToken.IsCancellationRequested
- && ((continuationOptions & TaskContinuationOptions.LazyCancellation) == 0)
- )
- {
- return CreateCanceledTask(continuationOptions, cancellationToken);
- }
-
- // returned continuation task, off of starter
- if (continuationFunction != null)
- {
- return starter.ContinueWith<TResult>(
- GenericDelegateCache<TAntecedentResult, TResult>.CWAnyFuncDelegate,
- continuationFunction, scheduler, cancellationToken, continuationOptions);
- }
- else
- {
- Debug.Assert(continuationAction != null);
- return starter.ContinueWith<TResult>(
- GenericDelegateCache<TAntecedentResult, TResult>.CWAnyActionDelegate,
- continuationAction, scheduler, cancellationToken, continuationOptions);
- }
- }
- }
-
- // For the ContinueWhenAnyImpl/ContinueWhenAllImpl methods that are generic on TAntecedentResult,
- // the compiler won't cache the internal ContinueWith delegate because it is generic on both
- // TAntecedentResult and TResult. The GenericDelegateCache serves as a cache for those delegates.
- internal static class GenericDelegateCache<TAntecedentResult, TResult>
- {
- // ContinueWith delegate for TaskFactory<TResult>.ContinueWhenAnyImpl<TAntecedentResult>(non-null continuationFunction)
- internal static Func<Task<Task>, object?, TResult> CWAnyFuncDelegate =
- (Task<Task> wrappedWinner, object? state) =>
- {
- Debug.Assert(state is Func<Task<TAntecedentResult>, TResult>);
- var func = (Func<Task<TAntecedentResult>, TResult>)state;
- var arg = (Task<TAntecedentResult>)wrappedWinner.Result;
- return func(arg);
- };
-
- // ContinueWith delegate for TaskFactory<TResult>.ContinueWhenAnyImpl<TAntecedentResult>(non-null continuationAction)
- internal static Func<Task<Task>, object?, TResult> CWAnyActionDelegate =
- (Task<Task> wrappedWinner, object? state) =>
- {
- Debug.Assert(state is Action<Task<TAntecedentResult>>);
- var action = (Action<Task<TAntecedentResult>>)state;
- var arg = (Task<TAntecedentResult>)wrappedWinner.Result;
- action(arg);
- return default!;
- };
-
- // ContinueWith delegate for TaskFactory<TResult>.ContinueWhenAllImpl<TAntecedentResult>(non-null continuationFunction)
- internal static Func<Task<Task<TAntecedentResult>[]>, object?, TResult> CWAllFuncDelegate =
- (Task<Task<TAntecedentResult>[]> wrappedAntecedents, object? state) =>
- {
- wrappedAntecedents.NotifyDebuggerOfWaitCompletionIfNecessary();
- Debug.Assert(state is Func<Task<TAntecedentResult>[], TResult>);
- var func = (Func<Task<TAntecedentResult>[], TResult>)state;
- return func(wrappedAntecedents.Result);
- };
-
- // ContinueWith delegate for TaskFactory<TResult>.ContinueWhenAllImpl<TAntecedentResult>(non-null continuationAction)
- internal static Func<Task<Task<TAntecedentResult>[]>, object?, TResult> CWAllActionDelegate =
- (Task<Task<TAntecedentResult>[]> wrappedAntecedents, object? state) =>
- {
- wrappedAntecedents.NotifyDebuggerOfWaitCompletionIfNecessary();
- Debug.Assert(state is Action<Task<TAntecedentResult>[]>);
- var action = (Action<Task<TAntecedentResult>[]>)state;
- action(wrappedAntecedents.Result);
- return default!;
- };
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ProducerConsumerQueues.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ProducerConsumerQueues.cs
deleted file mode 100644
index 252b5ad9d06..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ProducerConsumerQueues.cs
+++ /dev/null
@@ -1,369 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// Specialized producer/consumer queues.
-//
-//
-// ************<IMPORTANT NOTE>*************
-//
-// src\ndp\clr\src\bcl\system\threading\tasks\producerConsumerQueue.cs
-// src\ndp\fx\src\dataflow\system\threading\tasks\dataflow\internal\producerConsumerQueue.cs
-// Keep both of them consistent by changing the other file when you change this one, also avoid:
-// 1- To reference interneal types in mscorlib
-// 2- To reference any dataflow specific types
-// This should be fixed post Dev11 when this class becomes public.
-//
-// ************</IMPORTANT NOTE>*************
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Collections;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.InteropServices;
-
-namespace System.Threading.Tasks
-{
- /// <summary>Represents a producer/consumer queue used internally by dataflow blocks.</summary>
- /// <typeparam name="T">Specifies the type of data contained in the queue.</typeparam>
- internal interface IProducerConsumerQueue<T> : IEnumerable<T>
- {
- /// <summary>Enqueues an item into the queue.</summary>
- /// <param name="item">The item to enqueue.</param>
- /// <remarks>This method is meant to be thread-safe subject to the particular nature of the implementation.</remarks>
- void Enqueue(T item);
-
- /// <summary>Attempts to dequeue an item from the queue.</summary>
- /// <param name="result">The dequeued item.</param>
- /// <returns>true if an item could be dequeued; otherwise, false.</returns>
- /// <remarks>This method is meant to be thread-safe subject to the particular nature of the implementation.</remarks>
- bool TryDequeue([MaybeNullWhen(false)] out T result);
-
- /// <summary>Gets whether the collection is currently empty.</summary>
- /// <remarks>This method may or may not be thread-safe.</remarks>
- bool IsEmpty { get; }
-
- /// <summary>Gets the number of items in the collection.</summary>
- /// <remarks>In many implementations, this method will not be thread-safe.</remarks>
- int Count { get; }
- }
-
- /// <summary>
- /// Provides a producer/consumer queue safe to be used by any number of producers and consumers concurrently.
- /// </summary>
- /// <typeparam name="T">Specifies the type of data contained in the queue.</typeparam>
- [DebuggerDisplay("Count = {Count}")]
- internal sealed class MultiProducerMultiConsumerQueue<T> : ConcurrentQueue<T>, IProducerConsumerQueue<T>
- {
- /// <summary>Enqueues an item into the queue.</summary>
- /// <param name="item">The item to enqueue.</param>
- void IProducerConsumerQueue<T>.Enqueue(T item) { base.Enqueue(item); }
-
- /// <summary>Attempts to dequeue an item from the queue.</summary>
- /// <param name="result">The dequeued item.</param>
- /// <returns>true if an item could be dequeued; otherwise, false.</returns>
- bool IProducerConsumerQueue<T>.TryDequeue([MaybeNullWhen(false)] out T result) { return base.TryDequeue(out result); }
-
- /// <summary>Gets whether the collection is currently empty.</summary>
- bool IProducerConsumerQueue<T>.IsEmpty => base.IsEmpty;
-
- /// <summary>Gets the number of items in the collection.</summary>
- int IProducerConsumerQueue<T>.Count => base.Count;
- }
-
- /// <summary>
- /// Provides a producer/consumer queue safe to be used by only one producer and one consumer concurrently.
- /// </summary>
- /// <typeparam name="T">Specifies the type of data contained in the queue.</typeparam>
- [DebuggerDisplay("Count = {Count}")]
- [DebuggerTypeProxy(typeof(SingleProducerSingleConsumerQueue<>.SingleProducerSingleConsumerQueue_DebugView))]
- internal sealed class SingleProducerSingleConsumerQueue<T> : IProducerConsumerQueue<T>
- {
- // Design:
- //
- // SingleProducerSingleConsumerQueue (SPSCQueue) is a concurrent queue designed to be used
- // by one producer thread and one consumer thread. SPSCQueue does not work correctly when used by
- // multiple producer threads concurrently or multiple consumer threads concurrently.
- //
- // SPSCQueue is based on segments that behave like circular buffers. Each circular buffer is represented
- // as an array with two indexes: m_first and m_last. m_first is the index of the array slot for the consumer
- // to read next, and m_last is the slot for the producer to write next. The circular buffer is empty when
- // (m_first == m_last), and full when ((m_last+1) % m_array.Length == m_first).
- //
- // Since m_first is only ever modified by the consumer thread and m_last by the producer, the two indices can
- // be updated without interlocked operations. As long as the queue size fits inside a single circular buffer,
- // enqueues and dequeues simply advance the corresponding indices around the circular buffer. If an enqueue finds
- // that there is no room in the existing buffer, however, a new circular buffer is allocated that is twice as big
- // as the old buffer. From then on, the producer will insert values into the new buffer. The consumer will first
- // empty out the old buffer and only then follow the producer into the new (larger) buffer.
- //
- // As described above, the enqueue operation on the fast path only modifies the m_first field of the current segment.
- // However, it also needs to read m_last in order to verify that there is room in the current segment. Similarly, the
- // dequeue operation on the fast path only needs to modify m_last, but also needs to read m_first to verify that the
- // queue is non-empty. This results in true cache line sharing between the producer and the consumer.
- //
- // The cache line sharing issue can be mitigating by having a possibly stale copy of m_first that is owned by the producer,
- // and a possibly stale copy of m_last that is owned by the consumer. So, the consumer state is described using
- // (m_first, m_lastCopy) and the producer state using (m_firstCopy, m_last). The consumer state is separated from
- // the producer state by padding, which allows fast-path enqueues and dequeues from hitting shared cache lines.
- // m_lastCopy is the consumer's copy of m_last. Whenever the consumer can tell that there is room in the buffer
- // simply by observing m_lastCopy, the consumer thread does not need to read m_last and thus encounter a cache miss. Only
- // when the buffer appears to be empty will the consumer refresh m_lastCopy from m_last. m_firstCopy is used by the producer
- // in the same way to avoid reading m_first on the hot path.
-
- /// <summary>The initial size to use for segments (in number of elements).</summary>
- private const int INIT_SEGMENT_SIZE = 32; // must be a power of 2
- /// <summary>The maximum size to use for segments (in number of elements).</summary>
- private const int MAX_SEGMENT_SIZE = 0x1000000; // this could be made as large as int.MaxValue / 2
-
- /// <summary>The head of the linked list of segments.</summary>
- private volatile Segment m_head;
- /// <summary>The tail of the linked list of segments.</summary>
- private volatile Segment m_tail;
-
- /// <summary>Initializes the queue.</summary>
- internal SingleProducerSingleConsumerQueue()
- {
- // Validate constants in ctor rather than in an explicit cctor that would cause perf degradation
- Debug.Assert(INIT_SEGMENT_SIZE > 0, "Initial segment size must be > 0.");
- Debug.Assert((INIT_SEGMENT_SIZE & (INIT_SEGMENT_SIZE - 1)) == 0, "Initial segment size must be a power of 2");
- Debug.Assert(INIT_SEGMENT_SIZE <= MAX_SEGMENT_SIZE, "Initial segment size should be <= maximum.");
- Debug.Assert(MAX_SEGMENT_SIZE < int.MaxValue / 2, "Max segment size * 2 must be < int.MaxValue, or else overflow could occur.");
-
- // Initialize the queue
- m_head = m_tail = new Segment(INIT_SEGMENT_SIZE);
- }
-
- /// <summary>Enqueues an item into the queue.</summary>
- /// <param name="item">The item to enqueue.</param>
- public void Enqueue(T item)
- {
- Segment segment = m_tail;
- T[] array = segment.m_array;
- int last = segment.m_state.m_last; // local copy to avoid multiple volatile reads
-
- // Fast path: there's obviously room in the current segment
- int tail2 = (last + 1) & (array.Length - 1);
- if (tail2 != segment.m_state.m_firstCopy)
- {
- array[last] = item;
- segment.m_state.m_last = tail2;
- }
- // Slow path: there may not be room in the current segment.
- else EnqueueSlow(item, ref segment);
- }
-
- /// <summary>Enqueues an item into the queue.</summary>
- /// <param name="item">The item to enqueue.</param>
- /// <param name="segment">The segment in which to first attempt to store the item.</param>
- private void EnqueueSlow(T item, ref Segment segment)
- {
- Debug.Assert(segment != null, "Expected a non-null segment.");
-
- if (segment.m_state.m_firstCopy != segment.m_state.m_first)
- {
- segment.m_state.m_firstCopy = segment.m_state.m_first;
- Enqueue(item); // will only recur once for this enqueue operation
- return;
- }
-
- int newSegmentSize = m_tail.m_array.Length << 1; // double size
- Debug.Assert(newSegmentSize > 0, "The max size should always be small enough that we don't overflow.");
- if (newSegmentSize > MAX_SEGMENT_SIZE) newSegmentSize = MAX_SEGMENT_SIZE;
-
- var newSegment = new Segment(newSegmentSize);
- newSegment.m_array[0] = item;
- newSegment.m_state.m_last = 1;
- newSegment.m_state.m_lastCopy = 1;
-
- try { }
- finally
- {
- // Finally block to protect against corruption due to a thread abort
- // between setting m_next and setting m_tail.
- Volatile.Write(ref m_tail.m_next, newSegment); // ensure segment not published until item is fully stored
- m_tail = newSegment;
- }
- }
-
- /// <summary>Attempts to dequeue an item from the queue.</summary>
- /// <param name="result">The dequeued item.</param>
- /// <returns>true if an item could be dequeued; otherwise, false.</returns>
- public bool TryDequeue([MaybeNullWhen(false)] out T result)
- {
- Segment segment = m_head;
- T[] array = segment.m_array;
- int first = segment.m_state.m_first; // local copy to avoid multiple volatile reads
-
- // Fast path: there's obviously data available in the current segment
- if (first != segment.m_state.m_lastCopy)
- {
- result = array[first];
- array[first] = default!; // Clear the slot to release the element
- segment.m_state.m_first = (first + 1) & (array.Length - 1);
- return true;
- }
- // Slow path: there may not be data available in the current segment
- else return TryDequeueSlow(ref segment, ref array, out result);
- }
-
- /// <summary>Attempts to dequeue an item from the queue.</summary>
- /// <param name="array">The array from which the item was dequeued.</param>
- /// <param name="segment">The segment from which the item was dequeued.</param>
- /// <param name="result">The dequeued item.</param>
- /// <returns>true if an item could be dequeued; otherwise, false.</returns>
- private bool TryDequeueSlow(ref Segment segment, ref T[] array, [MaybeNullWhen(false)] out T result)
- {
- Debug.Assert(segment != null, "Expected a non-null segment.");
- Debug.Assert(array != null, "Expected a non-null item array.");
-
- if (segment.m_state.m_last != segment.m_state.m_lastCopy)
- {
- segment.m_state.m_lastCopy = segment.m_state.m_last;
- return TryDequeue(out result); // will only recur once for this dequeue operation
- }
-
- if (segment.m_next != null && segment.m_state.m_first == segment.m_state.m_last)
- {
- segment = segment.m_next;
- array = segment.m_array;
- m_head = segment;
- }
-
- int first = segment.m_state.m_first; // local copy to avoid extraneous volatile reads
-
- if (first == segment.m_state.m_last)
- {
- result = default!;
- return false;
- }
-
- result = array[first];
- array[first] = default!; // Clear the slot to release the element
- segment.m_state.m_first = (first + 1) & (segment.m_array.Length - 1);
- segment.m_state.m_lastCopy = segment.m_state.m_last; // Refresh m_lastCopy to ensure that m_first has not passed m_lastCopy
-
- return true;
- }
-
- /// <summary>Gets whether the collection is currently empty.</summary>
- /// <remarks>WARNING: This should not be used concurrently without further vetting.</remarks>
- public bool IsEmpty
- {
- // This implementation is optimized for calls from the consumer.
- get
- {
- Segment head = m_head;
- if (head.m_state.m_first != head.m_state.m_lastCopy) return false; // m_first is volatile, so the read of m_lastCopy cannot get reordered
- if (head.m_state.m_first != head.m_state.m_last) return false;
- return head.m_next == null;
- }
- }
-
- /// <summary>Gets an enumerable for the collection.</summary>
- /// <remarks>WARNING: This should only be used for debugging purposes. It is not safe to be used concurrently.</remarks>
- public IEnumerator<T> GetEnumerator()
- {
- for (Segment? segment = m_head; segment != null; segment = segment.m_next)
- {
- for (int pt = segment.m_state.m_first;
- pt != segment.m_state.m_last;
- pt = (pt + 1) & (segment.m_array.Length - 1))
- {
- yield return segment.m_array[pt];
- }
- }
- }
- /// <summary>Gets an enumerable for the collection.</summary>
- /// <remarks>WARNING: This should only be used for debugging purposes. It is not safe to be used concurrently.</remarks>
- IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
-
- /// <summary>Gets the number of items in the collection.</summary>
- /// <remarks>WARNING: This should only be used for debugging purposes. It is not meant to be used concurrently.</remarks>
- public int Count
- {
- get
- {
- int count = 0;
- for (Segment? segment = m_head; segment != null; segment = segment.m_next)
- {
- int arraySize = segment.m_array.Length;
- int first, last;
- while (true) // Count is not meant to be used concurrently, but this helps to avoid issues if it is
- {
- first = segment.m_state.m_first;
- last = segment.m_state.m_last;
- if (first == segment.m_state.m_first) break;
- }
- count += (last - first) & (arraySize - 1);
- }
- return count;
- }
- }
-
- /// <summary>A segment in the queue containing one or more items.</summary>
- [StructLayout(LayoutKind.Sequential)]
- private sealed class Segment
- {
- /// <summary>The next segment in the linked list of segments.</summary>
- internal Segment? m_next;
- /// <summary>The data stored in this segment.</summary>
- internal readonly T[] m_array;
- /// <summary>Details about the segment.</summary>
- internal SegmentState m_state; // separated out to enable StructLayout attribute to take effect
-
- /// <summary>Initializes the segment.</summary>
- /// <param name="size">The size to use for this segment.</param>
- internal Segment(int size)
- {
- Debug.Assert((size & (size - 1)) == 0, "Size must be a power of 2");
- m_array = new T[size];
- }
- }
-
- /// <summary>Stores information about a segment.</summary>
- [StructLayout(LayoutKind.Sequential)] // enforce layout so that padding reduces false sharing
- private struct SegmentState
- {
- /// <summary>Padding to reduce false sharing between the segment's array and m_first.</summary>
- internal Internal.PaddingFor32 m_pad0;
-
- /// <summary>The index of the current head in the segment.</summary>
- internal volatile int m_first;
- /// <summary>A copy of the current tail index.</summary>
- internal int m_lastCopy; // not volatile as read and written by the producer, except for IsEmpty, and there m_lastCopy is only read after reading the volatile m_first
-
- /// <summary>Padding to reduce false sharing between the first and last.</summary>
- internal Internal.PaddingFor32 m_pad1;
-
- /// <summary>A copy of the current head index.</summary>
- internal int m_firstCopy; // not voliatle as only read and written by the consumer thread
- /// <summary>The index of the current tail in the segment.</summary>
- internal volatile int m_last;
-
- /// <summary>Padding to reduce false sharing with the last and what's after the segment.</summary>
- internal Internal.PaddingFor32 m_pad2;
- }
-
- /// <summary>Debugger type proxy for a SingleProducerSingleConsumerQueue of T.</summary>
- private sealed class SingleProducerSingleConsumerQueue_DebugView
- {
- /// <summary>The queue being visualized.</summary>
- private readonly SingleProducerSingleConsumerQueue<T> m_queue;
-
- /// <summary>Initializes the debug view.</summary>
- /// <param name="queue">The queue being debugged.</param>
- public SingleProducerSingleConsumerQueue_DebugView(SingleProducerSingleConsumerQueue<T> queue)
- {
- Debug.Assert(queue != null, "Expected a non-null queue.");
- m_queue = queue;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs
deleted file mode 100644
index 5f071b2749b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs
+++ /dev/null
@@ -1,82 +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.
-
-namespace System.Threading.Tasks.Sources
-{
- /// <summary>
- /// Flags passed from <see cref="ValueTask"/> and <see cref="ValueTask{TResult}"/> to
- /// <see cref="IValueTaskSource.OnCompleted"/> and <see cref="IValueTaskSource{TResult}.OnCompleted"/>
- /// to control behavior.
- /// </summary>
- [Flags]
- public enum ValueTaskSourceOnCompletedFlags
- {
- /// <summary>
- /// No requirements are placed on how the continuation is invoked.
- /// </summary>
- None,
- /// <summary>
- /// Set if OnCompleted should capture the current scheduling context (e.g. SynchronizationContext)
- /// and use it when queueing the continuation for execution. If this is not set, the implementation
- /// may choose to execute the continuation in an arbitrary location.
- /// </summary>
- UseSchedulingContext = 0x1,
- /// <summary>
- /// Set if OnCompleted should capture the current ExecutionContext and use it to run the continuation.
- /// </summary>
- FlowExecutionContext = 0x2,
- }
-
- /// <summary>Indicates the status of an <see cref="IValueTaskSource"/> or <see cref="IValueTaskSource{TResult}"/>.</summary>
- public enum ValueTaskSourceStatus
- {
- /// <summary>The operation has not yet completed.</summary>
- Pending = 0,
- /// <summary>The operation completed successfully.</summary>
- Succeeded = 1,
- /// <summary>The operation completed with an error.</summary>
- Faulted = 2,
- /// <summary>The operation completed due to cancellation.</summary>
- Canceled = 3
- }
-
- /// <summary>Represents an object that can be wrapped by a <see cref="ValueTask"/>.</summary>
- public interface IValueTaskSource
- {
- /// <summary>Gets the status of the current operation.</summary>
- /// <param name="token">Opaque value that was provided to the <see cref="ValueTask"/>'s constructor.</param>
- ValueTaskSourceStatus GetStatus(short token);
-
- /// <summary>Schedules the continuation action for this <see cref="IValueTaskSource"/>.</summary>
- /// <param name="continuation">The continuation to invoke when the operation has completed.</param>
- /// <param name="state">The state object to pass to <paramref name="continuation"/> when it's invoked.</param>
- /// <param name="token">Opaque value that was provided to the <see cref="ValueTask"/>'s constructor.</param>
- /// <param name="flags">The flags describing the behavior of the continuation.</param>
- void OnCompleted(Action<object?> continuation, object? state, short token, ValueTaskSourceOnCompletedFlags flags);
-
- /// <summary>Gets the result of the <see cref="IValueTaskSource"/>.</summary>
- /// <param name="token">Opaque value that was provided to the <see cref="ValueTask"/>'s constructor.</param>
- void GetResult(short token);
- }
-
- /// <summary>Represents an object that can be wrapped by a <see cref="ValueTask{TResult}"/>.</summary>
- /// <typeparam name="TResult">Specifies the type of data returned from the object.</typeparam>
- public interface IValueTaskSource<out TResult>
- {
- /// <summary>Gets the status of the current operation.</summary>
- /// <param name="token">Opaque value that was provided to the <see cref="ValueTask"/>'s constructor.</param>
- ValueTaskSourceStatus GetStatus(short token);
-
- /// <summary>Schedules the continuation action for this <see cref="IValueTaskSource{TResult}"/>.</summary>
- /// <param name="continuation">The continuation to invoke when the operation has completed.</param>
- /// <param name="state">The state object to pass to <paramref name="continuation"/> when it's invoked.</param>
- /// <param name="token">Opaque value that was provided to the <see cref="ValueTask"/>'s constructor.</param>
- /// <param name="flags">The flags describing the behavior of the continuation.</param>
- void OnCompleted(Action<object?> continuation, object? state, short token, ValueTaskSourceOnCompletedFlags flags);
-
- /// <summary>Gets the result of the <see cref="IValueTaskSource{TResult}"/>.</summary>
- /// <param name="token">Opaque value that was provided to the <see cref="ValueTask"/>'s constructor.</param>
- TResult GetResult(short token);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs
deleted file mode 100644
index bef04bd62c7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs
+++ /dev/null
@@ -1,279 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.ExceptionServices;
-using System.Runtime.InteropServices;
-
-namespace System.Threading.Tasks.Sources
-{
- /// <summary>Provides the core logic for implementing a manual-reset <see cref="IValueTaskSource"/> or <see cref="IValueTaskSource{TResult}"/>.</summary>
- /// <typeparam name="TResult"></typeparam>
- [StructLayout(LayoutKind.Auto)]
- public struct ManualResetValueTaskSourceCore<TResult>
- {
- /// <summary>
- /// The callback to invoke when the operation completes if <see cref="OnCompleted"/> was called before the operation completed,
- /// or <see cref="ManualResetValueTaskSourceCoreShared.s_sentinel"/> if the operation completed before a callback was supplied,
- /// or null if a callback hasn't yet been provided and the operation hasn't yet completed.
- /// </summary>
- private Action<object?>? _continuation;
- /// <summary>State to pass to <see cref="_continuation"/>.</summary>
- private object? _continuationState;
- /// <summary><see cref="ExecutionContext"/> to flow to the callback, or null if no flowing is required.</summary>
- private ExecutionContext? _executionContext;
- /// <summary>
- /// A "captured" <see cref="SynchronizationContext"/> or <see cref="TaskScheduler"/> with which to invoke the callback,
- /// or null if no special context is required.
- /// </summary>
- private object? _capturedContext;
- /// <summary>Whether the current operation has completed.</summary>
- private bool _completed;
- /// <summary>The result with which the operation succeeded, or the default value if it hasn't yet completed or failed.</summary>
- [AllowNull, MaybeNull] private TResult _result;
- /// <summary>The exception with which the operation failed, or null if it hasn't yet completed or completed successfully.</summary>
- private ExceptionDispatchInfo? _error;
- /// <summary>The current version of this value, used to help prevent misuse.</summary>
- private short _version;
-
- /// <summary>Gets or sets whether to force continuations to run asynchronously.</summary>
- /// <remarks>Continuations may run asynchronously if this is false, but they'll never run synchronously if this is true.</remarks>
- public bool RunContinuationsAsynchronously { get; set; }
-
- /// <summary>Resets to prepare for the next operation.</summary>
- public void Reset()
- {
- // Reset/update state for the next use/await of this instance.
- _version++;
- _completed = false;
- _result = default;
- _error = null;
- _executionContext = null;
- _capturedContext = null;
- _continuation = null;
- _continuationState = null;
- }
-
- /// <summary>Completes with a successful result.</summary>
- /// <param name="result">The result.</param>
- public void SetResult(TResult result)
- {
- _result = result;
- SignalCompletion();
- }
-
- /// <summary>Completes with an error.</summary>
- /// <param name="error">The exception.</param>
- public void SetException(Exception error)
- {
- _error = ExceptionDispatchInfo.Capture(error);
- SignalCompletion();
- }
-
- /// <summary>Gets the operation version.</summary>
- public short Version => _version;
-
- /// <summary>Gets the status of the operation.</summary>
- /// <param name="token">Opaque value that was provided to the <see cref="ValueTask"/>'s constructor.</param>
- public ValueTaskSourceStatus GetStatus(short token)
- {
- ValidateToken(token);
- return
- _continuation == null || !_completed ? ValueTaskSourceStatus.Pending :
- _error == null ? ValueTaskSourceStatus.Succeeded :
- _error.SourceException is OperationCanceledException ? ValueTaskSourceStatus.Canceled :
- ValueTaskSourceStatus.Faulted;
- }
-
- /// <summary>Gets the result of the operation.</summary>
- /// <param name="token">Opaque value that was provided to the <see cref="ValueTask"/>'s constructor.</param>
- [StackTraceHidden]
- public TResult GetResult(short token)
- {
- ValidateToken(token);
- if (!_completed)
- {
- ThrowHelper.ThrowInvalidOperationException();
- }
-
- _error?.Throw();
- return _result;
- }
-
- /// <summary>Schedules the continuation action for this operation.</summary>
- /// <param name="continuation">The continuation to invoke when the operation has completed.</param>
- /// <param name="state">The state object to pass to <paramref name="continuation"/> when it's invoked.</param>
- /// <param name="token">Opaque value that was provided to the <see cref="ValueTask"/>'s constructor.</param>
- /// <param name="flags">The flags describing the behavior of the continuation.</param>
- public void OnCompleted(Action<object?> continuation, object? state, short token, ValueTaskSourceOnCompletedFlags flags)
- {
- if (continuation == null)
- {
- throw new ArgumentNullException(nameof(continuation));
- }
- ValidateToken(token);
-
- if ((flags & ValueTaskSourceOnCompletedFlags.FlowExecutionContext) != 0)
- {
- _executionContext = ExecutionContext.Capture();
- }
-
- if ((flags & ValueTaskSourceOnCompletedFlags.UseSchedulingContext) != 0)
- {
- SynchronizationContext? sc = SynchronizationContext.Current;
- if (sc != null && sc.GetType() != typeof(SynchronizationContext))
- {
- _capturedContext = sc;
- }
- else
- {
- TaskScheduler ts = TaskScheduler.Current;
- if (ts != TaskScheduler.Default)
- {
- _capturedContext = ts;
- }
- }
- }
-
- // We need to set the continuation state before we swap in the delegate, so that
- // if there's a race between this and SetResult/Exception and SetResult/Exception
- // sees the _continuation as non-null, it'll be able to invoke it with the state
- // stored here. However, this also means that if this is used incorrectly (e.g.
- // awaited twice concurrently), _continuationState might get erroneously overwritten.
- // To minimize the chances of that, we check preemptively whether _continuation
- // is already set to something other than the completion sentinel.
-
- object? oldContinuation = _continuation;
- if (oldContinuation == null)
- {
- _continuationState = state;
- oldContinuation = Interlocked.CompareExchange(ref _continuation, continuation, null);
- }
-
- if (oldContinuation != null)
- {
- // Operation already completed, so we need to queue the supplied callback.
- if (!ReferenceEquals(oldContinuation, ManualResetValueTaskSourceCoreShared.s_sentinel))
- {
- ThrowHelper.ThrowInvalidOperationException();
- }
-
- switch (_capturedContext)
- {
- case null:
- if (_executionContext != null)
- {
- ThreadPool.QueueUserWorkItem(continuation, state, preferLocal: true);
- }
- else
- {
- ThreadPool.UnsafeQueueUserWorkItem(continuation, state, preferLocal: true);
- }
- break;
-
- case SynchronizationContext sc:
- sc.Post(s =>
- {
- var tuple = (Tuple<Action<object?>, object?>)s!;
- tuple.Item1(tuple.Item2);
- }, Tuple.Create(continuation, state));
- break;
-
- case TaskScheduler ts:
- Task.Factory.StartNew(continuation, state, CancellationToken.None, TaskCreationOptions.DenyChildAttach, ts);
- break;
- }
- }
- }
-
- /// <summary>Ensures that the specified token matches the current version.</summary>
- /// <param name="token">The token supplied by <see cref="ValueTask"/>.</param>
- private void ValidateToken(short token)
- {
- if (token != _version)
- {
- ThrowHelper.ThrowInvalidOperationException();
- }
- }
-
- /// <summary>Signals that the operation has completed. Invoked after the result or error has been set.</summary>
- private void SignalCompletion()
- {
- if (_completed)
- {
- ThrowHelper.ThrowInvalidOperationException();
- }
- _completed = true;
-
- if (_continuation != null || Interlocked.CompareExchange(ref _continuation, ManualResetValueTaskSourceCoreShared.s_sentinel, null) != null)
- {
- if (_executionContext != null)
- {
- ExecutionContext.RunInternal(
- _executionContext,
- (ref ManualResetValueTaskSourceCore<TResult> s) => s.InvokeContinuation(),
- ref this);
- }
- else
- {
- InvokeContinuation();
- }
- }
- }
-
- /// <summary>
- /// Invokes the continuation with the appropriate captured context / scheduler.
- /// This assumes that if <see cref="_executionContext"/> is not null we're already
- /// running within that <see cref="ExecutionContext"/>.
- /// </summary>
- private void InvokeContinuation()
- {
- Debug.Assert(_continuation != null);
-
- switch (_capturedContext)
- {
- case null:
- if (RunContinuationsAsynchronously)
- {
- if (_executionContext != null)
- {
- ThreadPool.QueueUserWorkItem(_continuation, _continuationState, preferLocal: true);
- }
- else
- {
- ThreadPool.UnsafeQueueUserWorkItem(_continuation, _continuationState, preferLocal: true);
- }
- }
- else
- {
- _continuation(_continuationState);
- }
- break;
-
- case SynchronizationContext sc:
- sc.Post(s =>
- {
- var state = (Tuple<Action<object?>, object?>)s!;
- state.Item1(state.Item2);
- }, Tuple.Create(_continuation, _continuationState));
- break;
-
- case TaskScheduler ts:
- Task.Factory.StartNew(_continuation, _continuationState, CancellationToken.None, TaskCreationOptions.DenyChildAttach, ts);
- break;
- }
- }
- }
-
- internal static class ManualResetValueTaskSourceCoreShared // separated out of generic to avoid unnecessary duplication
- {
- internal static readonly Action<object?> s_sentinel = CompletionSentinel;
- private static void CompletionSentinel(object? _) // named method to aid debugging
- {
- Debug.Fail("The sentinel delegate should never be invoked.");
- ThrowHelper.ThrowInvalidOperationException();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs
deleted file mode 100644
index 05cd310369b..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs
+++ /dev/null
@@ -1,6614 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// A schedulable unit of work.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.Diagnostics.Tracing;
-using System.Runtime.CompilerServices;
-using System.Runtime.ExceptionServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// Represents the current stage in the lifecycle of a <see cref="Task"/>.
- /// </summary>
- public enum TaskStatus
- {
- /// <summary>
- /// The task has been initialized but has not yet been scheduled.
- /// </summary>
- Created,
- /// <summary>
- /// The task is waiting to be activated and scheduled internally by the .NET Framework infrastructure.
- /// </summary>
- WaitingForActivation,
- /// <summary>
- /// The task has been scheduled for execution but has not yet begun executing.
- /// </summary>
- WaitingToRun,
- /// <summary>
- /// The task is running but has not yet completed.
- /// </summary>
- Running,
- // /// <summary>
- // /// The task is currently blocked in a wait state.
- // /// </summary>
- // Blocked,
- /// <summary>
- /// The task has finished executing and is implicitly waiting for
- /// attached child tasks to complete.
- /// </summary>
- WaitingForChildrenToComplete,
- /// <summary>
- /// The task completed execution successfully.
- /// </summary>
- RanToCompletion,
- /// <summary>
- /// The task acknowledged cancellation by throwing an OperationCanceledException with its own CancellationToken
- /// while the token was in signaled state, or the task's CancellationToken was already signaled before the
- /// task started executing.
- /// </summary>
- Canceled,
- /// <summary>
- /// The task completed due to an unhandled exception.
- /// </summary>
- Faulted
- }
-
- /// <summary>
- /// Represents an asynchronous operation.
- /// </summary>
- /// <remarks>
- /// <para>
- /// <see cref="Task"/> instances may be created in a variety of ways. The most common approach is by
- /// using the Task type's <see cref="Factory"/> property to retrieve a <see
- /// cref="System.Threading.Tasks.TaskFactory"/> instance that can be used to create tasks for several
- /// purposes. For example, to create a <see cref="Task"/> that runs an action, the factory's StartNew
- /// method may be used:
- /// <code>
- /// // C#
- /// var t = Task.Factory.StartNew(() => DoAction());
- ///
- /// ' Visual Basic
- /// Dim t = Task.Factory.StartNew(Function() DoAction())
- /// </code>
- /// </para>
- /// <para>
- /// The <see cref="Task"/> class also provides constructors that initialize the Task but that do not
- /// schedule it for execution. For performance reasons, TaskFactory's StartNew method should be the
- /// preferred mechanism for creating and scheduling computational tasks, but for scenarios where creation
- /// and scheduling must be separated, the constructors may be used, and the task's <see cref="Start()"/>
- /// method may then be used to schedule the task for execution at a later time.
- /// </para>
- /// <para>
- /// All members of <see cref="Task"/>, except for <see cref="Dispose()"/>, are thread-safe
- /// and may be used from multiple threads concurrently.
- /// </para>
- /// <para>
- /// For operations that return values, the <see cref="System.Threading.Tasks.Task{TResult}"/> class
- /// should be used.
- /// </para>
- /// <para>
- /// For developers implementing custom debuggers, several internal and private members of Task may be
- /// useful (these may change from release to release). The Int32 m_taskId field serves as the backing
- /// store for the <see cref="Id"/> property, however accessing this field directly from a debugger may be
- /// more efficient than accessing the same value through the property's getter method (the
- /// s_taskIdCounter Int32 counter is used to retrieve the next available ID for a Task). Similarly, the
- /// Int32 m_stateFlags field stores information about the current lifecycle stage of the Task,
- /// information also accessible through the <see cref="Status"/> property. The m_action System.Object
- /// field stores a reference to the Task's delegate, and the m_stateObject System.Object field stores the
- /// async state passed to the Task by the developer. Finally, for debuggers that parse stack frames, the
- /// InternalWait method serves a potential marker for when a Task is entering a wait operation.
- /// </para>
- /// </remarks>
- [DebuggerTypeProxy(typeof(SystemThreadingTasks_TaskDebugView))]
- [DebuggerDisplay("Id = {Id}, Status = {Status}, Method = {DebuggerDisplayMethodDescription}")]
- public class Task : IAsyncResult, IDisposable
- {
- [ThreadStatic]
- internal static Task? t_currentTask; // The currently executing task.
-
- internal static int s_taskIdCounter; // static counter used to generate unique task IDs
-
- private volatile int m_taskId; // this task's unique ID. initialized only if it is ever requested
-
- internal Delegate? m_action; // The body of the task. Might be Action<object>, Action<TState> or Action. Or possibly a Func.
- // If m_action is set to null it will indicate that we operate in the
- // "externally triggered completion" mode, which is exclusively meant
- // for the signalling Task<TResult> (aka. promise). In this mode,
- // we don't call InnerInvoke() in response to a Wait(), but simply wait on
- // the completion event which will be set when the Future class calls Finish().
- // But the event would now be signalled if Cancel() is called
-
- internal object? m_stateObject; // A state object that can be optionally supplied, passed to action.
- internal TaskScheduler? m_taskScheduler; // The task scheduler this task runs under.
-
- internal volatile int m_stateFlags; // SOS DumpAsync command depends on this name
-
- private Task? ParentForDebugger => m_contingentProperties?.m_parent; // Private property used by a debugger to access this Task's parent
- private int StateFlagsForDebugger => m_stateFlags; // Private property used by a debugger to access this Task's state flags
-
- // State constants for m_stateFlags;
- // The bits of m_stateFlags are allocated as follows:
- // 0x40000000 - TaskBase state flag
- // 0x3FFF0000 - Task state flags
- // 0x0000FF00 - internal TaskCreationOptions flags
- // 0x000000FF - publicly exposed TaskCreationOptions flags
- //
- // See TaskCreationOptions for bit values associated with TaskCreationOptions
- //
- private const int OptionsMask = 0xFFFF; // signifies the Options portion of m_stateFlags bin: 0000 0000 0000 0000 1111 1111 1111 1111
- internal const int TASK_STATE_STARTED = 0x10000; // bin: 0000 0000 0000 0001 0000 0000 0000 0000
- internal const int TASK_STATE_DELEGATE_INVOKED = 0x20000; // bin: 0000 0000 0000 0010 0000 0000 0000 0000
- internal const int TASK_STATE_DISPOSED = 0x40000; // bin: 0000 0000 0000 0100 0000 0000 0000 0000
- internal const int TASK_STATE_EXCEPTIONOBSERVEDBYPARENT = 0x80000; // bin: 0000 0000 0000 1000 0000 0000 0000 0000
- internal const int TASK_STATE_CANCELLATIONACKNOWLEDGED = 0x100000; // bin: 0000 0000 0001 0000 0000 0000 0000 0000
- internal const int TASK_STATE_FAULTED = 0x200000; // bin: 0000 0000 0010 0000 0000 0000 0000 0000
- internal const int TASK_STATE_CANCELED = 0x400000; // bin: 0000 0000 0100 0000 0000 0000 0000 0000
- internal const int TASK_STATE_WAITING_ON_CHILDREN = 0x800000; // bin: 0000 0000 1000 0000 0000 0000 0000 0000
- internal const int TASK_STATE_RAN_TO_COMPLETION = 0x1000000; // bin: 0000 0001 0000 0000 0000 0000 0000 0000
- internal const int TASK_STATE_WAITINGFORACTIVATION = 0x2000000; // bin: 0000 0010 0000 0000 0000 0000 0000 0000
- internal const int TASK_STATE_COMPLETION_RESERVED = 0x4000000; // bin: 0000 0100 0000 0000 0000 0000 0000 0000
- internal const int TASK_STATE_WAIT_COMPLETION_NOTIFICATION = 0x10000000; // bin: 0001 0000 0000 0000 0000 0000 0000 0000
- // This could be moved to InternalTaskOptions enum
- internal const int TASK_STATE_EXECUTIONCONTEXT_IS_NULL = 0x20000000; // bin: 0010 0000 0000 0000 0000 0000 0000 0000
- internal const int TASK_STATE_TASKSCHEDULED_WAS_FIRED = 0x40000000; // bin: 0100 0000 0000 0000 0000 0000 0000 0000
-
- // A mask for all of the final states a task may be in.
- // SOS DumpAsync command depends on these values.
- private const int TASK_STATE_COMPLETED_MASK = TASK_STATE_CANCELED | TASK_STATE_FAULTED | TASK_STATE_RAN_TO_COMPLETION;
-
- // Values for ContingentProperties.m_internalCancellationRequested.
- private const int CANCELLATION_REQUESTED = 0x1;
-
- // Can be null, a single continuation, a list of continuations, or s_taskCompletionSentinel,
- // in that order. The logic arround this object assumes it will never regress to a previous state.
- private volatile object? m_continuationObject = null; // SOS DumpAsync command depends on this name
-
- // m_continuationObject is set to this when the task completes.
- private static readonly object s_taskCompletionSentinel = new object();
-
- // A private flag that would be set (only) by the debugger
- // When true the Async Causality logging trace is enabled as well as a dictionary to relate operation ids with Tasks
- internal static bool s_asyncDebuggingEnabled; // false by default
-
- // This dictonary relates the task id, from an operation id located in the Async Causality log to the actual
- // task. This is to be used by the debugger ONLY. Task in this dictionary represent current active tasks.
- private static Dictionary<int, Task>? s_currentActiveTasks;
-
- // These methods are a way to access the dictionary both from this class and for other classes that also
- // activate dummy tasks. Specifically the AsyncTaskMethodBuilder and AsyncTaskMethodBuilder<>
- internal static bool AddToActiveTasks(Task task)
- {
- Debug.Assert(task != null, "Null Task objects can't be added to the ActiveTasks collection");
-
- LazyInitializer.EnsureInitialized(ref s_currentActiveTasks, () => new Dictionary<int, Task>());
-
- int taskId = task.Id;
- lock (s_currentActiveTasks)
- {
- s_currentActiveTasks[taskId] = task;
- }
- // always return true to keep signature as bool for backwards compatibility
- return true;
- }
-
- internal static void RemoveFromActiveTasks(Task task)
- {
- if (s_currentActiveTasks == null)
- return;
-
- int taskId = task.Id;
- lock (s_currentActiveTasks)
- {
- s_currentActiveTasks.Remove(taskId);
- }
- }
-
- // We moved a number of Task properties into this class. The idea is that in most cases, these properties never
- // need to be accessed during the life cycle of a Task, so we don't want to instantiate them every time. Once
- // one of these properties needs to be written, we will instantiate a ContingentProperties object and set
- // the appropriate property.
- internal class ContingentProperties
- {
- // Additional context
-
- internal ExecutionContext? m_capturedContext; // The execution context to run the task within, if any. Only set from non-concurrent contexts.
-
- // Completion fields (exceptions and event)
-
- internal volatile ManualResetEventSlim? m_completionEvent; // Lazily created if waiting is required.
- internal volatile TaskExceptionHolder? m_exceptionsHolder; // Tracks exceptions, if any have occurred
-
- // Cancellation fields (token, registration, and internally requested)
-
- internal CancellationToken m_cancellationToken; // Task's cancellation token, if it has one
- internal StrongBox<CancellationTokenRegistration>? m_cancellationRegistration; // Task's registration with the cancellation token
- internal volatile int m_internalCancellationRequested; // Its own field because multiple threads legally try to set it.
-
- // Parenting fields
-
- // # of active children + 1 (for this task itself).
- // Used for ensuring all children are done before this task can complete
- // The extra count helps prevent the race condition for executing the final state transition
- // (i.e. whether the last child or this task itself should call FinishStageTwo())
- internal volatile int m_completionCountdown = 1;
- // A list of child tasks that threw an exception (TCEs don't count),
- // but haven't yet been waited on by the parent, lazily initialized.
- internal volatile List<Task>? m_exceptionalChildren;
- // A task's parent, or null if parent-less. Only set during Task construction.
- internal Task? m_parent;
-
- /// <summary>
- /// Sets the internal completion event.
- /// </summary>
- internal void SetCompleted()
- {
- ManualResetEventSlim? mres = m_completionEvent;
- if (mres != null) mres.Set();
- }
-
- /// <summary>
- /// Checks if we registered a CT callback during construction, and unregisters it.
- /// This should be called when we know the registration isn't useful anymore. Specifically from Finish() if the task has completed
- /// successfully or with an exception.
- /// </summary>
- internal void UnregisterCancellationCallback()
- {
- if (m_cancellationRegistration != null)
- {
- // Harden against ODEs thrown from disposing of the CTR.
- // Since the task has already been put into a final state by the time this
- // is called, all we can do here is suppress the exception.
- try { m_cancellationRegistration.Value.Dispose(); }
- catch (ObjectDisposedException) { }
- m_cancellationRegistration = null;
- }
- }
- }
-
- // This field will only be instantiated to some non-null value if any ContingentProperties need to be set.
- // This will be a ContingentProperties instance or a type derived from it
- internal ContingentProperties? m_contingentProperties;
-
- // Special internal constructor to create an already-completed task.
- // if canceled==true, create a Canceled task, or else create a RanToCompletion task.
- // Constructs the task as already completed
- internal Task(bool canceled, TaskCreationOptions creationOptions, CancellationToken ct)
- {
- int optionFlags = (int)creationOptions;
- if (canceled)
- {
- m_stateFlags = TASK_STATE_CANCELED | TASK_STATE_CANCELLATIONACKNOWLEDGED | optionFlags;
- m_contingentProperties = new ContingentProperties() // can't have children, so just instantiate directly
- {
- m_cancellationToken = ct,
- m_internalCancellationRequested = CANCELLATION_REQUESTED,
- };
- }
- else
- m_stateFlags = TASK_STATE_RAN_TO_COMPLETION | optionFlags;
- }
-
- /// <summary>Constructor for use with promise-style tasks that aren't configurable.</summary>
- internal Task()
- {
- m_stateFlags = TASK_STATE_WAITINGFORACTIVATION | (int)InternalTaskOptions.PromiseTask;
- }
-
- // Special constructor for use with promise-style tasks.
- // Added promiseStyle parameter as an aid to the compiler to distinguish between (state,TCO) and
- // (action,TCO). It should always be true.
- internal Task(object? state, TaskCreationOptions creationOptions, bool promiseStyle)
- {
- Debug.Assert(promiseStyle, "Promise CTOR: promiseStyle was false");
-
- // Check the creationOptions. We allow the AttachedToParent option to be specified for promise tasks.
- // Also allow RunContinuationsAsynchronously because this is the constructor called by TCS
- if ((creationOptions & ~(TaskCreationOptions.AttachedToParent | TaskCreationOptions.RunContinuationsAsynchronously)) != 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions);
- }
-
- // Only set a parent if AttachedToParent is specified.
- if ((creationOptions & TaskCreationOptions.AttachedToParent) != 0)
- {
- Task? parent = Task.InternalCurrent;
- if (parent != null)
- {
- EnsureContingentPropertiesInitializedUnsafe().m_parent = parent;
- }
- }
-
- TaskConstructorCore(null, state, default, creationOptions, InternalTaskOptions.PromiseTask, null);
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task"/> with the specified action.
- /// </summary>
- /// <param name="action">The delegate that represents the code to execute in the Task.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="action"/> argument is null.</exception>
- public Task(Action action)
- : this(action, null, null, default, TaskCreationOptions.None, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task"/> with the specified action and <see cref="System.Threading.CancellationToken">CancellationToken</see>.
- /// </summary>
- /// <param name="action">The delegate that represents the code to execute in the Task.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new Task.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="action"/> argument is null.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task(Action action, CancellationToken cancellationToken)
- : this(action, null, null, cancellationToken, TaskCreationOptions.None, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task"/> with the specified action and creation options.
- /// </summary>
- /// <param name="action">The delegate that represents the code to execute in the task.</param>
- /// <param name="creationOptions">
- /// The <see cref="System.Threading.Tasks.TaskCreationOptions">TaskCreationOptions</see> used to
- /// customize the Task's behavior.
- /// </param>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="action"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="creationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskCreationOptions"/>.
- /// </exception>
- public Task(Action action, TaskCreationOptions creationOptions)
- : this(action, null, Task.InternalCurrentIfAttached(creationOptions), default, creationOptions, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task"/> with the specified action and creation options.
- /// </summary>
- /// <param name="action">The delegate that represents the code to execute in the task.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <param name="creationOptions">
- /// The <see cref="System.Threading.Tasks.TaskCreationOptions">TaskCreationOptions</see> used to
- /// customize the Task's behavior.
- /// </param>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="action"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="creationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskCreationOptions"/>.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task(Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
- : this(action, null, Task.InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task"/> with the specified action and state.
- /// </summary>
- /// <param name="action">The delegate that represents the code to execute in the task.</param>
- /// <param name="state">An object representing data to be used by the action.</param>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="action"/> argument is null.
- /// </exception>
- public Task(Action<object?> action, object? state)
- : this(action, state, null, default, TaskCreationOptions.None, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task"/> with the specified action, state, and options.
- /// </summary>
- /// <param name="action">The delegate that represents the code to execute in the task.</param>
- /// <param name="state">An object representing data to be used by the action.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="action"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task(Action<object?> action, object? state, CancellationToken cancellationToken)
- : this(action, state, null, cancellationToken, TaskCreationOptions.None, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task"/> with the specified action, state, and options.
- /// </summary>
- /// <param name="action">The delegate that represents the code to execute in the task.</param>
- /// <param name="state">An object representing data to be used by the action.</param>
- /// <param name="creationOptions">
- /// The <see cref="System.Threading.Tasks.TaskCreationOptions">TaskCreationOptions</see> used to
- /// customize the Task's behavior.
- /// </param>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="action"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="creationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskCreationOptions"/>.
- /// </exception>
- public Task(Action<object?> action, object? state, TaskCreationOptions creationOptions)
- : this(action, state, Task.InternalCurrentIfAttached(creationOptions), default, creationOptions, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a new <see cref="Task"/> with the specified action, state, and options.
- /// </summary>
- /// <param name="action">The delegate that represents the code to execute in the task.</param>
- /// <param name="state">An object representing data to be used by the action.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <param name="creationOptions">
- /// The <see cref="System.Threading.Tasks.TaskCreationOptions">TaskCreationOptions</see> used to
- /// customize the Task's behavior.
- /// </param>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="action"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="creationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskCreationOptions"/>.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task(Action<object?> action, object? state, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
- : this(action, state, Task.InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.None, null)
- {
- }
-
- /// <summary>
- /// An internal constructor used by the factory methods on task and its descendent(s).
- /// </summary>
- /// <param name="action">An action to execute.</param>
- /// <param name="state">Optional state to pass to the action.</param>
- /// <param name="parent">Parent of Task.</param>
- /// <param name="cancellationToken">A CancellationToken for the task.</param>
- /// <param name="scheduler">A task scheduler under which the task will run.</param>
- /// <param name="creationOptions">Options to control its execution.</param>
- /// <param name="internalOptions">Internal options to control its execution</param>
- internal Task(Delegate action, object? state, Task? parent, CancellationToken cancellationToken,
- TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler? scheduler)
- {
- if (action == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.action);
- }
-
- // Keep a link to the parent if attached
- if (parent != null && (creationOptions & TaskCreationOptions.AttachedToParent) != 0)
- {
- EnsureContingentPropertiesInitializedUnsafe().m_parent = parent;
- }
-
- TaskConstructorCore(action, state, cancellationToken, creationOptions, internalOptions, scheduler);
-
- Debug.Assert(m_contingentProperties == null || m_contingentProperties.m_capturedContext == null,
- "Captured an ExecutionContext when one was already captured.");
- CapturedContext = ExecutionContext.Capture();
- }
-
- /// <summary>
- /// Common logic used by the following internal ctors:
- /// Task()
- /// Task(object action, object state, Task parent, TaskCreationOptions options, TaskScheduler taskScheduler)
- /// </summary>
- /// <param name="action">Action for task to execute.</param>
- /// <param name="state">Object to which to pass to action (may be null)</param>
- /// <param name="scheduler">Task scheduler on which to run thread (only used by continuation tasks).</param>
- /// <param name="cancellationToken">A CancellationToken for the Task.</param>
- /// <param name="creationOptions">Options to customize behavior of Task.</param>
- /// <param name="internalOptions">Internal options to customize behavior of Task.</param>
- internal void TaskConstructorCore(Delegate? action, object? state, CancellationToken cancellationToken,
- TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler? scheduler)
- {
- m_action = action;
- m_stateObject = state;
- m_taskScheduler = scheduler;
-
- // Check for validity of options
- if ((creationOptions &
- ~(TaskCreationOptions.AttachedToParent |
- TaskCreationOptions.LongRunning |
- TaskCreationOptions.DenyChildAttach |
- TaskCreationOptions.HideScheduler |
- TaskCreationOptions.PreferFairness |
- TaskCreationOptions.RunContinuationsAsynchronously)) != 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions);
- }
-
-#if DEBUG
- // Check the validity of internalOptions
- int illegalInternalOptions =
- (int)(internalOptions &
- ~(InternalTaskOptions.PromiseTask |
- InternalTaskOptions.ContinuationTask |
- InternalTaskOptions.LazyCancellation |
- InternalTaskOptions.QueuedByRuntime));
- Debug.Assert(illegalInternalOptions == 0, "TaskConstructorCore: Illegal internal options");
-#endif
-
- // Assign options to m_stateAndOptionsFlag.
- Debug.Assert(m_stateFlags == 0, "TaskConstructorCore: non-zero m_stateFlags");
- Debug.Assert((((int)creationOptions) | OptionsMask) == OptionsMask, "TaskConstructorCore: options take too many bits");
- int tmpFlags = (int)creationOptions | (int)internalOptions; // one write to the volatile m_stateFlags instead of two when setting the above options
- m_stateFlags = m_action == null || (internalOptions & InternalTaskOptions.ContinuationTask) != 0 ?
- tmpFlags | TASK_STATE_WAITINGFORACTIVATION :
- tmpFlags;
-
- // Now is the time to add the new task to the children list
- // of the creating task if the options call for it.
- // We can safely call the creator task's AddNewChild() method to register it,
- // because at this point we are already on its thread of execution.
-
- ContingentProperties? props = m_contingentProperties;
- if (props != null)
- {
- Task? parent = props.m_parent;
- if (parent != null
- && ((creationOptions & TaskCreationOptions.AttachedToParent) != 0)
- && ((parent.CreationOptions & TaskCreationOptions.DenyChildAttach) == 0))
- {
- parent.AddNewChild();
- }
- }
-
- // if we have a non-null cancellationToken, allocate the contingent properties to save it
- // we need to do this as the very last thing in the construction path, because the CT registration could modify m_stateFlags
- if (cancellationToken.CanBeCanceled)
- {
- Debug.Assert((internalOptions & InternalTaskOptions.ContinuationTask) == 0, "TaskConstructorCore: Did not expect to see cancelable token for continuation task.");
-
- AssignCancellationToken(cancellationToken, null, null);
- }
- }
-
- /// <summary>
- /// Handles everything needed for associating a CancellationToken with a task which is being constructed.
- /// This method is meant to be called either from the TaskConstructorCore or from ContinueWithCore.
- /// </summary>
- private void AssignCancellationToken(CancellationToken cancellationToken, Task? antecedent, TaskContinuation? continuation)
- {
- // There is no need to worry about concurrency issues here because we are in the constructor path of the task --
- // there should not be any race conditions to set m_contingentProperties at this point.
- ContingentProperties props = EnsureContingentPropertiesInitializedUnsafe();
- props.m_cancellationToken = cancellationToken;
-
- try
- {
- // If an unstarted task has a valid CancellationToken that gets signalled while the task is still not queued
- // we need to proactively cancel it, because it may never execute to transition itself.
- // The only way to accomplish this is to register a callback on the CT.
- // We exclude Promise tasks from this, because TaskCompletionSource needs to fully control the inner tasks's lifetime (i.e. not allow external cancellations)
- if (((InternalTaskOptions)Options &
- (InternalTaskOptions.QueuedByRuntime | InternalTaskOptions.PromiseTask | InternalTaskOptions.LazyCancellation)) == 0)
- {
- if (cancellationToken.IsCancellationRequested)
- {
- // Fast path for an already-canceled cancellationToken
- this.InternalCancel(false);
- }
- else
- {
- // Regular path for an uncanceled cancellationToken
- CancellationTokenRegistration ctr;
- if (antecedent == null)
- {
- // if no antecedent was specified, use this task's reference as the cancellation state object
- ctr = cancellationToken.UnsafeRegister(t => ((Task)t!).InternalCancel(false), this);
- }
- else
- {
- Debug.Assert(continuation != null);
-
- // If an antecedent was specified, pack this task, its antecedent and the TaskContinuation together as a tuple
- // and use it as the cancellation state object. This will be unpacked in the cancellation callback so that
- // antecedent.RemoveCancellation(continuation) can be invoked.
- ctr = cancellationToken.UnsafeRegister(t =>
- {
- var tuple = (Tuple<Task, Task, TaskContinuation>)t!;
-
- Task targetTask = tuple.Item1;
- Task antecedentTask = tuple.Item2;
-
- antecedentTask.RemoveContinuation(tuple.Item3);
- targetTask.InternalCancel(false);
- },
- new Tuple<Task, Task, TaskContinuation>(this, antecedent, continuation));
- }
-
- props.m_cancellationRegistration = new StrongBox<CancellationTokenRegistration>(ctr);
- }
- }
- }
- catch
- {
- // If we have an exception related to our CancellationToken, then we need to subtract ourselves
- // from our parent before throwing it.
- Task? parent = m_contingentProperties?.m_parent;
- if ((parent != null) &&
- ((Options & TaskCreationOptions.AttachedToParent) != 0)
- && ((parent.Options & TaskCreationOptions.DenyChildAttach) == 0))
- {
- parent.DisregardChild();
- }
- throw;
- }
- }
-
- // Debugger support
- private string DebuggerDisplayMethodDescription => m_action?.Method.ToString() ?? "{null}";
-
- // Internal property to process TaskCreationOptions access and mutation.
- internal TaskCreationOptions Options => OptionsMethod(m_stateFlags);
-
- // Similar to Options property, but allows for the use of a cached flags value rather than
- // a read of the volatile m_stateFlags field.
- internal static TaskCreationOptions OptionsMethod(int flags)
- {
- Debug.Assert((OptionsMask & 1) == 1, "OptionsMask needs a shift in Options.get");
- return (TaskCreationOptions)(flags & OptionsMask);
- }
-
- // Atomically OR-in newBits to m_stateFlags, while making sure that
- // no illegalBits are set. Returns true on success, false on failure.
- internal bool AtomicStateUpdate(int newBits, int illegalBits)
- {
- int oldFlags = m_stateFlags;
- return
- (oldFlags & illegalBits) == 0 &&
- (Interlocked.CompareExchange(ref m_stateFlags, oldFlags | newBits, oldFlags) == oldFlags ||
- AtomicStateUpdateSlow(newBits, illegalBits));
- }
-
- private bool AtomicStateUpdateSlow(int newBits, int illegalBits)
- {
- int flags = m_stateFlags;
- while (true)
- {
- if ((flags & illegalBits) != 0) return false;
- int oldFlags = Interlocked.CompareExchange(ref m_stateFlags, flags | newBits, flags);
- if (oldFlags == flags)
- {
- return true;
- }
- flags = oldFlags;
- }
- }
-
- internal bool AtomicStateUpdate(int newBits, int illegalBits, ref int oldFlags)
- {
- int flags = oldFlags = m_stateFlags;
- while (true)
- {
- if ((flags & illegalBits) != 0) return false;
- oldFlags = Interlocked.CompareExchange(ref m_stateFlags, flags | newBits, flags);
- if (oldFlags == flags)
- {
- return true;
- }
- flags = oldFlags;
- }
- }
-
- /// <summary>
- /// Sets or clears the TASK_STATE_WAIT_COMPLETION_NOTIFICATION state bit.
- /// The debugger sets this bit to aid it in "stepping out" of an async method body.
- /// If enabled is true, this must only be called on a task that has not yet been completed.
- /// If enabled is false, this may be called on completed tasks.
- /// Either way, it should only be used for promise-style tasks.
- /// </summary>
- /// <param name="enabled">true to set the bit; false to unset the bit.</param>
- internal void SetNotificationForWaitCompletion(bool enabled)
- {
- Debug.Assert((Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0,
- "Should only be used for promise-style tasks"); // hasn't been vetted on other kinds as there hasn't been a need
-
- if (enabled)
- {
- // Atomically set the END_AWAIT_NOTIFICATION bit
- bool success = AtomicStateUpdate(TASK_STATE_WAIT_COMPLETION_NOTIFICATION,
- TASK_STATE_COMPLETED_MASK | TASK_STATE_COMPLETION_RESERVED);
- Debug.Assert(success, "Tried to set enabled on completed Task");
- }
- else
- {
- // Atomically clear the END_AWAIT_NOTIFICATION bit
- int flags = m_stateFlags;
- while (true)
- {
- int oldFlags = Interlocked.CompareExchange(ref m_stateFlags, flags & (~TASK_STATE_WAIT_COMPLETION_NOTIFICATION), flags);
- if (oldFlags == flags) break;
- flags = oldFlags;
- }
- }
- }
-
- /// <summary>
- /// Calls the debugger notification method if the right bit is set and if
- /// the task itself allows for the notification to proceed.
- /// </summary>
- /// <returns>true if the debugger was notified; otherwise, false.</returns>
- internal bool NotifyDebuggerOfWaitCompletionIfNecessary()
- {
- // Notify the debugger if of any of the tasks we've waited on requires notification
- if (IsWaitNotificationEnabled && ShouldNotifyDebuggerOfWaitCompletion)
- {
- NotifyDebuggerOfWaitCompletion();
- return true;
- }
- return false;
- }
-
- /// <summary>Returns true if any of the supplied tasks require wait notification.</summary>
- /// <param name="tasks">The tasks to check.</param>
- /// <returns>true if any of the tasks require notification; otherwise, false.</returns>
- internal static bool AnyTaskRequiresNotifyDebuggerOfWaitCompletion(Task?[] tasks)
- {
- Debug.Assert(tasks != null, "Expected non-null array of tasks");
- foreach (Task? task in tasks)
- {
- if (task != null &&
- task.IsWaitNotificationEnabled &&
- task.ShouldNotifyDebuggerOfWaitCompletion) // potential recursion
- {
- return true;
- }
- }
- return false;
- }
-
- /// <summary>Gets whether either the end await bit is set or (not xor) the task has not completed successfully.</summary>
- /// <returns>(DebuggerBitSet || !RanToCompletion)</returns>
- internal bool IsWaitNotificationEnabledOrNotRanToCompletion
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => (m_stateFlags & (Task.TASK_STATE_WAIT_COMPLETION_NOTIFICATION | Task.TASK_STATE_RAN_TO_COMPLETION))
- != Task.TASK_STATE_RAN_TO_COMPLETION;
- }
-
- /// <summary>
- /// Determines whether we should inform the debugger that we're ending a join with a task.
- /// This should only be called if the debugger notification bit is set, as it is has some cost,
- /// namely it is a virtual call (however calling it if the bit is not set is not functionally
- /// harmful). Derived implementations may choose to only conditionally call down to this base
- /// implementation.
- /// </summary>
- internal virtual bool ShouldNotifyDebuggerOfWaitCompletion // ideally would be familyAndAssembly, but that can't be done in C#
- {
- get
- {
- // It's theoretically possible but extremely rare that this assert could fire because the
- // bit was unset between the time that it was checked and this method was called.
- // It's so remote a chance that it's worth having the assert to protect against misuse.
- bool isWaitNotificationEnabled = IsWaitNotificationEnabled;
- Debug.Assert(isWaitNotificationEnabled, "Should only be called if the wait completion bit is set.");
- return isWaitNotificationEnabled;
- }
- }
-
- /// <summary>Gets whether the task's debugger notification for wait completion bit is set.</summary>
- /// <returns>true if the bit is set; false if it's not set.</returns>
- internal bool IsWaitNotificationEnabled => // internal only to enable unit tests; would otherwise be private
- (m_stateFlags & TASK_STATE_WAIT_COMPLETION_NOTIFICATION) != 0;
-
- /// <summary>Placeholder method used as a breakpoint target by the debugger. Must not be inlined or optimized.</summary>
- /// <remarks>All joins with a task should end up calling this if their debugger notification bit is set.</remarks>
- [MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
- private void NotifyDebuggerOfWaitCompletion()
- {
- // It's theoretically possible but extremely rare that this assert could fire because the
- // bit was unset between the time that it was checked and this method was called.
- // It's so remote a chance that it's worth having the assert to protect against misuse.
- Debug.Assert(IsWaitNotificationEnabled, "Should only be called if the wait completion bit is set.");
-
- // Now that we're notifying the debugger, clear the bit. The debugger should do this anyway,
- // but this adds a bit of protection in case it fails to, and given that the debugger is involved,
- // the overhead here for the interlocked is negligable. We do still rely on the debugger
- // to clear bits, as this doesn't recursively clear bits in the case of, for example, WhenAny.
- SetNotificationForWaitCompletion(enabled: false);
- }
-
- // Atomically mark a Task as started while making sure that it is not canceled.
- internal bool MarkStarted()
- {
- return AtomicStateUpdate(TASK_STATE_STARTED, TASK_STATE_CANCELED | TASK_STATE_STARTED);
- }
-
- internal void FireTaskScheduledIfNeeded(TaskScheduler ts)
- {
- if ((m_stateFlags & Task.TASK_STATE_TASKSCHEDULED_WAS_FIRED) == 0)
- {
- m_stateFlags |= Task.TASK_STATE_TASKSCHEDULED_WAS_FIRED;
-
- Task? currentTask = Task.InternalCurrent;
- Task? parentTask = m_contingentProperties?.m_parent;
- TplEventSource.Log.TaskScheduled(ts.Id, currentTask == null ? 0 : currentTask.Id,
- this.Id, parentTask == null ? 0 : parentTask.Id, (int)this.Options);
- }
- }
-
- /// <summary>
- /// Internal function that will be called by a new child task to add itself to
- /// the children list of the parent (this).
- ///
- /// Since a child task can only be created from the thread executing the action delegate
- /// of this task, reentrancy is neither required nor supported. This should not be called from
- /// anywhere other than the task construction/initialization codepaths.
- /// </summary>
- internal void AddNewChild()
- {
- Debug.Assert(Task.InternalCurrent == this, "Task.AddNewChild(): Called from an external context");
-
- ContingentProperties props = EnsureContingentPropertiesInitialized();
-
- if (props.m_completionCountdown == 1)
- {
- // A count of 1 indicates so far there was only the parent, and this is the first child task
- // Single kid => no fuss about who else is accessing the count. Let's save ourselves 100 cycles
- props.m_completionCountdown++;
- }
- else
- {
- // otherwise do it safely
- Interlocked.Increment(ref props.m_completionCountdown);
- }
- }
-
- // This is called in the case where a new child is added, but then encounters a CancellationToken-related exception.
- // We need to subtract that child from m_completionCountdown, or the parent will never complete.
- internal void DisregardChild()
- {
- Debug.Assert(Task.InternalCurrent == this, "Task.DisregardChild(): Called from an external context");
-
- ContingentProperties props = EnsureContingentPropertiesInitialized();
- Debug.Assert(props.m_completionCountdown >= 2, "Task.DisregardChild(): Expected parent count to be >= 2");
- Interlocked.Decrement(ref props.m_completionCountdown);
- }
-
- /// <summary>
- /// Starts the <see cref="Task"/>, scheduling it for execution to the current <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>.
- /// </summary>
- /// <remarks>
- /// A task may only be started and run only once. Any attempts to schedule a task a second time
- /// will result in an exception.
- /// </remarks>
- /// <exception cref="InvalidOperationException">
- /// The <see cref="Task"/> is not in a valid state to be started. It may have already been started,
- /// executed, or canceled, or it may have been created in a manner that doesn't support direct
- /// scheduling.
- /// </exception>
- public void Start()
- {
- Start(TaskScheduler.Current);
- }
-
- /// <summary>
- /// Starts the <see cref="Task"/>, scheduling it for execution to the specified <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>.
- /// </summary>
- /// <remarks>
- /// A task may only be started and run only once. Any attempts to schedule a task a second time will
- /// result in an exception.
- /// </remarks>
- /// <param name="scheduler">
- /// The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> with which to associate
- /// and execute this task.
- /// </param>
- /// <exception cref="ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- /// <exception cref="InvalidOperationException">
- /// The <see cref="Task"/> is not in a valid state to be started. It may have already been started,
- /// executed, or canceled, or it may have been created in a manner that doesn't support direct
- /// scheduling.
- /// </exception>
- public void Start(TaskScheduler scheduler)
- {
- // Read the volatile m_stateFlags field once and cache it for subsequent operations
- int flags = m_stateFlags;
-
- // Need to check this before (m_action == null) because completed tasks will
- // set m_action to null. We would want to know if this is the reason that m_action == null.
- if (IsCompletedMethod(flags))
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_Start_TaskCompleted);
- }
-
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- TaskCreationOptions options = OptionsMethod(flags);
- if ((options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_Start_Promise);
- }
- if ((options & (TaskCreationOptions)InternalTaskOptions.ContinuationTask) != 0)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_Start_ContinuationTask);
- }
-
- // Make sure that Task only gets started once. Or else throw an exception.
- if (Interlocked.CompareExchange(ref m_taskScheduler, scheduler, null) != null)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_Start_AlreadyStarted);
- }
-
- ScheduleAndStart(true);
- }
-
- /// <summary>
- /// Runs the <see cref="Task"/> synchronously on the current <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>.
- /// </summary>
- /// <remarks>
- /// <para>
- /// A task may only be started and run only once. Any attempts to schedule a task a second time will
- /// result in an exception.
- /// </para>
- /// <para>
- /// Tasks executed with <see cref="RunSynchronously()"/> will be associated with the current <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>.
- /// </para>
- /// <para>
- /// If the target scheduler does not support running this Task on the current thread, the Task will
- /// be scheduled for execution on the scheduler, and the current thread will block until the
- /// Task has completed execution.
- /// </para>
- /// </remarks>
- /// <exception cref="InvalidOperationException">
- /// The <see cref="Task"/> is not in a valid state to be started. It may have already been started,
- /// executed, or canceled, or it may have been created in a manner that doesn't support direct
- /// scheduling.
- /// </exception>
- public void RunSynchronously()
- {
- InternalRunSynchronously(TaskScheduler.Current, waitForCompletion: true);
- }
-
- /// <summary>
- /// Runs the <see cref="Task"/> synchronously on the <see
- /// cref="System.Threading.Tasks.TaskScheduler">scheduler</see> provided.
- /// </summary>
- /// <remarks>
- /// <para>
- /// A task may only be started and run only once. Any attempts to schedule a task a second time will
- /// result in an exception.
- /// </para>
- /// <para>
- /// If the target scheduler does not support running this Task on the current thread, the Task will
- /// be scheduled for execution on the scheduler, and the current thread will block until the
- /// Task has completed execution.
- /// </para>
- /// </remarks>
- /// <exception cref="InvalidOperationException">
- /// The <see cref="Task"/> is not in a valid state to be started. It may have already been started,
- /// executed, or canceled, or it may have been created in a manner that doesn't support direct
- /// scheduling.
- /// </exception>
- /// <exception cref="ArgumentNullException">The <paramref name="scheduler"/> parameter
- /// is null.</exception>
- /// <param name="scheduler">The scheduler on which to attempt to run this task inline.</param>
- public void RunSynchronously(TaskScheduler scheduler)
- {
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- InternalRunSynchronously(scheduler, waitForCompletion: true);
- }
-
- //
- // Internal version of RunSynchronously that allows not waiting for completion.
- //
- internal void InternalRunSynchronously(TaskScheduler scheduler, bool waitForCompletion)
- {
- Debug.Assert(scheduler != null, "Task.InternalRunSynchronously(): null TaskScheduler");
-
- // Read the volatile m_stateFlags field once and cache it for subsequent operations
- int flags = m_stateFlags;
-
- // Can't call this method on a continuation task
- TaskCreationOptions options = OptionsMethod(flags);
- if ((options & (TaskCreationOptions)InternalTaskOptions.ContinuationTask) != 0)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_Continuation);
- }
-
- // Can't call this method on a promise-style task
- if ((options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_Promise);
- }
-
- // Can't call this method on a task that has already completed
- if (IsCompletedMethod(flags))
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_TaskCompleted);
- }
-
- // Make sure that Task only gets started once. Or else throw an exception.
- if (Interlocked.CompareExchange(ref m_taskScheduler, scheduler, null) != null)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_AlreadyStarted);
- }
-
- // execute only if we successfully cancel when concurrent cancel attempts are made.
- // otherwise throw an exception, because we've been canceled.
- if (MarkStarted())
- {
- bool taskQueued = false;
- try
- {
- // We wrap TryRunInline() in a try/catch block and move an excepted task to Faulted here,
- // but not in Wait()/WaitAll()/FastWaitAll(). Here, we know for sure that the
- // task will not be subsequently scheduled (assuming that the scheduler adheres
- // to the guideline that an exception implies that no state change took place),
- // so it is safe to catch the exception and move the task to a final state. The
- // same cannot be said for Wait()/WaitAll()/FastWaitAll().
- if (!scheduler.TryRunInline(this, false))
- {
- scheduler.InternalQueueTask(this);
- taskQueued = true; // only mark this after successfully queuing the task.
- }
-
- // A successful TryRunInline doesn't guarantee completion, as there may be unfinished children.
- // Also if we queued the task above, the task may not be done yet.
- if (waitForCompletion && !IsCompleted)
- {
- SpinThenBlockingWait(Timeout.Infinite, default);
- }
- }
- catch (Exception e)
- {
- // we received an unexpected exception originating from a custom scheduler, which needs to be wrapped in a TSE and thrown
- if (!taskQueued)
- {
- // We had a problem with TryRunInline() or QueueTask().
- // Record the exception, marking ourselves as Completed/Faulted.
- TaskSchedulerException tse = new TaskSchedulerException(e);
- AddException(tse);
- Finish(false);
-
- // Mark ourselves as "handled" to avoid crashing the finalizer thread if the caller neglects to
- // call Wait() on this task.
- // m_contingentProperties.m_exceptionsHolder *should* already exist after AddException()
- Debug.Assert(
- (m_contingentProperties != null) &&
- (m_contingentProperties.m_exceptionsHolder != null) &&
- (m_contingentProperties.m_exceptionsHolder.ContainsFaultList),
- "Task.InternalRunSynchronously(): Expected m_contingentProperties.m_exceptionsHolder to exist " +
- "and to have faults recorded.");
- m_contingentProperties.m_exceptionsHolder.MarkAsHandled(false);
-
- // And re-throw.
- throw tse;
- }
- // We had a problem with waiting. Just re-throw.
- else throw;
- }
- }
- else
- {
- Debug.Assert((m_stateFlags & TASK_STATE_CANCELED) != 0, "Task.RunSynchronously: expected TASK_STATE_CANCELED to be set");
- // Can't call this method on canceled task.
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_TaskCompleted);
- }
- }
-
- ////
- //// Helper methods for Factory StartNew methods.
- ////
-
- // Implicitly converts action to object and handles the meat of the StartNew() logic.
- internal static Task InternalStartNew(
- Task? creatingTask, Delegate action, object? state, CancellationToken cancellationToken, TaskScheduler scheduler,
- TaskCreationOptions options, InternalTaskOptions internalOptions)
- {
- // Validate arguments.
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- // Create and schedule the task. This throws an InvalidOperationException if already shut down.
- // Here we add the InternalTaskOptions.QueuedByRuntime to the internalOptions, so that TaskConstructorCore can skip the cancellation token registration
- Task t = new Task(action, state, creatingTask, cancellationToken, options, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler);
-
- t.ScheduleAndStart(false);
- return t;
- }
-
- /// <summary>
- /// Gets a unique ID for a <see cref="Task">Task</see> or task continuation instance.
- /// </summary>
- internal static int NewId()
- {
- int newId;
-
- // We need to repeat if Interlocked.Increment wraps around and returns 0.
- // Otherwise next time this task's Id is queried it will get a new value
- do
- {
- newId = Interlocked.Increment(ref s_taskIdCounter);
- }
- while (newId == 0);
-
- if (TplEventSource.Log.IsEnabled())
- TplEventSource.Log.NewID(newId);
-
- return newId;
- }
-
- /////////////
- // properties
-
- /// <summary>
- /// Gets a unique ID for this <see cref="Task">Task</see> instance.
- /// </summary>
- /// <remarks>
- /// Task IDs are assigned on-demand and do not necessarily represent the order in the which Task
- /// instances were created.
- /// </remarks>
- public int Id
- {
- get
- {
- if (m_taskId == 0)
- {
- int newId = NewId();
- Interlocked.CompareExchange(ref m_taskId, newId, 0);
- }
-
- return m_taskId;
- }
- }
-
- /// <summary>
- /// Returns the unique ID of the currently executing <see cref="Task">Task</see>.
- /// </summary>
- public static int? CurrentId
- {
- get
- {
- Task? currentTask = InternalCurrent;
- if (currentTask != null)
- return currentTask.Id;
- else
- return null;
- }
- }
-
- /// <summary>
- /// Gets the <see cref="Task">Task</see> instance currently executing, or
- /// null if none exists.
- /// </summary>
- internal static Task? InternalCurrent => t_currentTask;
-
- /// <summary>
- /// Gets the Task instance currently executing if the specified creation options
- /// contain AttachedToParent.
- /// </summary>
- /// <param name="creationOptions">The options to check.</param>
- /// <returns>The current task if there is one and if AttachToParent is in the options; otherwise, null.</returns>
- internal static Task? InternalCurrentIfAttached(TaskCreationOptions creationOptions)
- {
- return (creationOptions & TaskCreationOptions.AttachedToParent) != 0 ? InternalCurrent : null;
- }
-
- /// <summary>
- /// Gets the <see cref="System.AggregateException">Exception</see> that caused the <see
- /// cref="Task">Task</see> to end prematurely. If the <see
- /// cref="Task">Task</see> completed successfully or has not yet thrown any
- /// exceptions, this will return null.
- /// </summary>
- /// <remarks>
- /// Tasks that throw unhandled exceptions store the resulting exception and propagate it wrapped in a
- /// <see cref="System.AggregateException"/> in calls to <see cref="Wait()">Wait</see>
- /// or in accesses to the <see cref="Exception"/> property. Any exceptions not observed by the time
- /// the Task instance is garbage collected will be propagated on the finalizer thread.
- /// </remarks>
- public AggregateException? Exception
- {
- get
- {
- AggregateException? e = null;
-
- // If you're faulted, retrieve the exception(s)
- if (IsFaulted) e = GetExceptions(false);
-
- // Only return an exception in faulted state (skip manufactured exceptions)
- // A "benevolent" race condition makes it possible to return null when IsFaulted is
- // true (i.e., if IsFaulted is set just after the check to IsFaulted above).
- Debug.Assert((e == null) || IsFaulted, "Task.Exception_get(): returning non-null value when not Faulted");
-
- return e;
- }
- }
-
- /// <summary>
- /// Gets the <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> of this Task.
- /// </summary>
- public TaskStatus Status
- {
- get
- {
- TaskStatus rval;
-
- // get a cached copy of the state flags. This should help us
- // to get a consistent view of the flags if they are changing during the
- // execution of this method.
- int sf = m_stateFlags;
-
- if ((sf & TASK_STATE_FAULTED) != 0) rval = TaskStatus.Faulted;
- else if ((sf & TASK_STATE_CANCELED) != 0) rval = TaskStatus.Canceled;
- else if ((sf & TASK_STATE_RAN_TO_COMPLETION) != 0) rval = TaskStatus.RanToCompletion;
- else if ((sf & TASK_STATE_WAITING_ON_CHILDREN) != 0) rval = TaskStatus.WaitingForChildrenToComplete;
- else if ((sf & TASK_STATE_DELEGATE_INVOKED) != 0) rval = TaskStatus.Running;
- else if ((sf & TASK_STATE_STARTED) != 0) rval = TaskStatus.WaitingToRun;
- else if ((sf & TASK_STATE_WAITINGFORACTIVATION) != 0) rval = TaskStatus.WaitingForActivation;
- else rval = TaskStatus.Created;
-
- return rval;
- }
- }
-
- /// <summary>
- /// Gets whether this <see cref="Task">Task</see> instance has completed
- /// execution due to being canceled.
- /// </summary>
- /// <remarks>
- /// A <see cref="Task">Task</see> will complete in Canceled state either if its <see cref="CancellationToken">CancellationToken</see>
- /// was marked for cancellation before the task started executing, or if the task acknowledged the cancellation request on
- /// its already signaled CancellationToken by throwing an
- /// <see cref="System.OperationCanceledException">OperationCanceledException</see> that bears the same
- /// <see cref="System.Threading.CancellationToken">CancellationToken</see>.
- /// </remarks>
- public bool IsCanceled =>
- // Return true if canceled bit is set and faulted bit is not set
- (m_stateFlags & (TASK_STATE_CANCELED | TASK_STATE_FAULTED)) == TASK_STATE_CANCELED;
-
- /// <summary>
- /// Returns true if this task has a cancellation token and it was signaled.
- /// To be used internally in execute entry codepaths.
- /// </summary>
- internal bool IsCancellationRequested
- {
- get
- {
- // check both the internal cancellation request flag and the CancellationToken attached to this task
- ContingentProperties? props = Volatile.Read(ref m_contingentProperties);
- return props != null &&
- (props.m_internalCancellationRequested == CANCELLATION_REQUESTED ||
- props.m_cancellationToken.IsCancellationRequested);
- }
- }
-
- /// <summary>
- /// Ensures that the contingent properties field has been initialized.
- /// ASSUMES THAT m_stateFlags IS ALREADY SET!
- /// </summary>
- /// <returns>The initialized contingent properties object.</returns>
- internal ContingentProperties EnsureContingentPropertiesInitialized()
- {
- return LazyInitializer.EnsureInitialized(ref m_contingentProperties, () => new ContingentProperties());
- }
-
- /// <summary>
- /// Without synchronization, ensures that the contingent properties field has been initialized.
- /// ASSUMES THAT m_stateFlags IS ALREADY SET!
- /// </summary>
- /// <returns>The initialized contingent properties object.</returns>
- internal ContingentProperties EnsureContingentPropertiesInitializedUnsafe() =>
- m_contingentProperties ??= new ContingentProperties();
-
- /// <summary>
- /// This internal property provides access to the CancellationToken that was set on the task
- /// when it was constructed.
- /// </summary>
- internal CancellationToken CancellationToken
- {
- get
- {
- ContingentProperties? props = Volatile.Read(ref m_contingentProperties);
- return (props == null) ? default : props.m_cancellationToken;
- }
- }
-
- /// <summary>
- /// Gets whether this <see cref="Task"/> threw an OperationCanceledException while its CancellationToken was signaled.
- /// </summary>
- internal bool IsCancellationAcknowledged => (m_stateFlags & TASK_STATE_CANCELLATIONACKNOWLEDGED) != 0;
-
- /// <summary>
- /// Gets whether this <see cref="Task">Task</see> has completed.
- /// </summary>
- /// <remarks>
- /// <see cref="IsCompleted"/> will return true when the Task is in one of the three
- /// final states: <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
- /// </remarks>
- public bool IsCompleted
- {
- get
- {
- int stateFlags = m_stateFlags; // enable inlining of IsCompletedMethod by "cast"ing away the volatility
- return IsCompletedMethod(stateFlags);
- }
- }
-
- // Similar to IsCompleted property, but allows for the use of a cached flags value
- // rather than reading the volatile m_stateFlags field.
- private static bool IsCompletedMethod(int flags)
- {
- return (flags & TASK_STATE_COMPLETED_MASK) != 0;
- }
-
- public bool IsCompletedSuccessfully => (m_stateFlags & TASK_STATE_COMPLETED_MASK) == TASK_STATE_RAN_TO_COMPLETION;
-
- /// <summary>
- /// Gets the <see cref="System.Threading.Tasks.TaskCreationOptions">TaskCreationOptions</see> used
- /// to create this task.
- /// </summary>
- public TaskCreationOptions CreationOptions => Options & (TaskCreationOptions)(~InternalTaskOptions.InternalOptionsMask);
-
- /// <summary>
- /// Gets a <see cref="System.Threading.WaitHandle"/> that can be used to wait for the task to
- /// complete.
- /// </summary>
- /// <remarks>
- /// Using the wait functionality provided by <see cref="Wait()"/>
- /// should be preferred over using <see cref="IAsyncResult.AsyncWaitHandle"/> for similar
- /// functionality.
- /// </remarks>
- /// <exception cref="System.ObjectDisposedException">
- /// The <see cref="Task"/> has been disposed.
- /// </exception>
- WaitHandle IAsyncResult.AsyncWaitHandle
- {
- // Although a slim event is used internally to avoid kernel resource allocation, this function
- // forces allocation of a true WaitHandle when called.
- get
- {
- bool isDisposed = (m_stateFlags & TASK_STATE_DISPOSED) != 0;
- if (isDisposed)
- {
- ThrowHelper.ThrowObjectDisposedException(ExceptionResource.Task_ThrowIfDisposed);
- }
- return CompletedEvent.WaitHandle;
- }
- }
-
- /// <summary>
- /// Gets the state object supplied when the <see cref="Task">Task</see> was created,
- /// or null if none was supplied.
- /// </summary>
- public object? AsyncState => m_stateObject;
-
- /// <summary>
- /// Gets an indication of whether the asynchronous operation completed synchronously.
- /// </summary>
- /// <value>true if the asynchronous operation completed synchronously; otherwise, false.</value>
- bool IAsyncResult.CompletedSynchronously => false;
-
- /// <summary>
- /// Provides access to the TaskScheduler responsible for executing this Task.
- /// </summary>
- internal TaskScheduler? ExecutingTaskScheduler => m_taskScheduler;
-
- /// <summary>
- /// Provides access to factory methods for creating <see cref="Task"/> and <see cref="Task{TResult}"/> instances.
- /// </summary>
- /// <remarks>
- /// The factory returned from <see cref="Factory"/> is a default instance
- /// of <see cref="System.Threading.Tasks.TaskFactory"/>, as would result from using
- /// the default constructor on TaskFactory.
- /// </remarks>
- public static TaskFactory Factory { get; } = new TaskFactory();
-
- /// <summary>Singleton cached task that's been completed successfully.</summary>
- /// <remarks>It's a <see cref="Task{VoidTaskResult}"/> so it can be shared with <see cref="AsyncTaskMethodBuilder"/>.</remarks>
- internal static readonly Task<VoidTaskResult> s_cachedCompleted = new Task<VoidTaskResult>(false, default, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default);
-
- /// <summary>Gets a task that's already been completed successfully.</summary>
- public static Task CompletedTask => s_cachedCompleted;
-
- /// <summary>
- /// Provides an event that can be used to wait for completion.
- /// Only called by IAsyncResult.AsyncWaitHandle, which means that we really do need to instantiate a completion event.
- /// </summary>
- internal ManualResetEventSlim CompletedEvent
- {
- get
- {
- ContingentProperties contingentProps = EnsureContingentPropertiesInitialized();
- if (contingentProps.m_completionEvent == null)
- {
- bool wasCompleted = IsCompleted;
- ManualResetEventSlim newMre = new ManualResetEventSlim(wasCompleted);
- if (Interlocked.CompareExchange(ref contingentProps.m_completionEvent, newMre, null) != null)
- {
- // Someone else already set the value, so we will just close the event right away.
- newMre.Dispose();
- }
- else if (!wasCompleted && IsCompleted)
- {
- // We published the event as unset, but the task has subsequently completed.
- // Set the event's state properly so that callers don't deadlock.
- newMre.Set();
- }
- }
-
- return contingentProps.m_completionEvent;
- }
- }
-
- /// <summary>
- /// Whether an exception has been stored into the task.
- /// </summary>
- internal bool ExceptionRecorded
- {
- get
- {
- ContingentProperties? props = Volatile.Read(ref m_contingentProperties);
- return (props != null) && (props.m_exceptionsHolder != null) && (props.m_exceptionsHolder.ContainsFaultList);
- }
- }
-
- /// <summary>
- /// Gets whether the <see cref="Task"/> completed due to an unhandled exception.
- /// </summary>
- /// <remarks>
- /// If <see cref="IsFaulted"/> is true, the Task's <see cref="Status"/> will be equal to
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">TaskStatus.Faulted</see>, and its
- /// <see cref="Exception"/> property will be non-null.
- /// </remarks>
- public bool IsFaulted =>
- // Faulted is "king" -- if that bit is present (regardless of other bits), we are faulted.
- (m_stateFlags & TASK_STATE_FAULTED) != 0;
-
- /// <summary>
- /// The captured execution context for the current task to run inside
- /// If the TASK_STATE_EXECUTIONCONTEXT_IS_NULL flag is set, this means ExecutionContext.Capture returned null, otherwise
- /// If the captured context is the default, nothing is saved, otherwise the m_contingentProperties inflates to save the context
- /// </summary>
- internal ExecutionContext? CapturedContext
- {
- get
- {
- if ((m_stateFlags & TASK_STATE_EXECUTIONCONTEXT_IS_NULL) == TASK_STATE_EXECUTIONCONTEXT_IS_NULL)
- {
- return null;
- }
- else
- {
- return m_contingentProperties?.m_capturedContext ?? ExecutionContext.Default;
- }
- }
- set
- {
- // There is no need to atomically set this bit because this set() method is only called during construction, and therefore there should be no contending accesses to m_stateFlags
- if (value == null)
- {
- m_stateFlags |= TASK_STATE_EXECUTIONCONTEXT_IS_NULL;
- }
- else if (value != ExecutionContext.Default) // not the default context, then inflate the contingent properties and set it
- {
- EnsureContingentPropertiesInitializedUnsafe().m_capturedContext = value;
- }
- // else do nothing, this is the default context
- }
- }
-
- /////////////
- // methods
-
- /// <summary>
- /// Disposes the <see cref="Task"/>, releasing all of its unmanaged resources.
- /// </summary>
- /// <remarks>
- /// Unlike most of the members of <see cref="Task"/>, this method is not thread-safe.
- /// Also, <see cref="Dispose()"/> may only be called on a <see cref="Task"/> that is in one of
- /// the final states: <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
- /// </remarks>
- /// <exception cref="System.InvalidOperationException">
- /// The exception that is thrown if the <see cref="Task"/> is not in
- /// one of the final states: <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
- /// </exception>
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- /// <summary>
- /// Disposes the <see cref="Task"/>, releasing all of its unmanaged resources.
- /// </summary>
- /// <param name="disposing">
- /// A Boolean value that indicates whether this method is being called due to a call to <see
- /// cref="Dispose()"/>.
- /// </param>
- /// <remarks>
- /// Unlike most of the members of <see cref="Task"/>, this method is not thread-safe.
- /// </remarks>
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
- // Dispose is a nop if this task was created with the DoNotDispose internal option.
- // This is done before the completed check, because if we're not touching any
- // state on the task, it's ok for it to happen before completion.
- if ((Options & (TaskCreationOptions)InternalTaskOptions.DoNotDispose) != 0)
- {
- return;
- }
-
- // Task must be completed to dispose
- if (!IsCompleted)
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_Dispose_NotCompleted);
- }
-
- // Dispose of the underlying completion event if it exists
- ContingentProperties? cp = Volatile.Read(ref m_contingentProperties);
- if (cp != null)
- {
- // Make a copy to protect against racing Disposes.
- // If we wanted to make this a bit safer, we could use an interlocked here,
- // but we state that Dispose is not thread safe.
- ManualResetEventSlim? ev = cp.m_completionEvent;
- if (ev != null)
- {
- // Null out the completion event in contingent props; we'll use our copy from here on out
- cp.m_completionEvent = null;
-
- // In the unlikely event that our completion event is inflated but not yet signaled,
- // go ahead and signal the event. If you dispose of an unsignaled MRES, then any waiters
- // will deadlock; an ensuing Set() will not wake them up. In the event of an AppDomainUnload,
- // there is no guarantee that anyone else is going to signal the event, and it does no harm to
- // call Set() twice on m_completionEvent.
- if (!ev.IsSet) ev.Set();
-
- // Finally, dispose of the event
- ev.Dispose();
- }
- }
- }
-
- // We OR the flags to indicate the object has been disposed. The task
- // has already completed at this point, and the only conceivable race condition would
- // be with the unsetting of the TASK_STATE_WAIT_COMPLETION_NOTIFICATION flag, which
- // is extremely unlikely and also benign. (Worst case: we hit a breakpoint
- // twice instead of once in the debugger. Weird, but not lethal.)
- m_stateFlags |= TASK_STATE_DISPOSED;
- }
-
- /////////////
- // internal helpers
-
- /// <summary>
- /// Schedules the task for execution.
- /// </summary>
- /// <param name="needsProtection">If true, TASK_STATE_STARTED bit is turned on in
- /// an atomic fashion, making sure that TASK_STATE_CANCELED does not get set
- /// underneath us. If false, TASK_STATE_STARTED bit is OR-ed right in. This
- /// allows us to streamline things a bit for StartNew(), where competing cancellations
- /// are not a problem.</param>
- internal void ScheduleAndStart(bool needsProtection)
- {
- Debug.Assert(m_taskScheduler != null, "expected a task scheduler to have been selected");
- Debug.Assert((m_stateFlags & TASK_STATE_STARTED) == 0, "task has already started");
-
- // Set the TASK_STATE_STARTED bit
- if (needsProtection)
- {
- if (!MarkStarted())
- {
- // A cancel has snuck in before we could get started. Quietly exit.
- return;
- }
- }
- else
- {
- m_stateFlags |= TASK_STATE_STARTED;
- }
-
- if (s_asyncDebuggingEnabled)
- AddToActiveTasks(this);
-
- if (AsyncCausalityTracer.LoggingOn && (Options & (TaskCreationOptions)InternalTaskOptions.ContinuationTask) == 0)
- {
- // For all other task than TaskContinuations we want to log. TaskContinuations log in their constructor
- Debug.Assert(m_action != null, "Must have a delegate to be in ScheduleAndStart");
- AsyncCausalityTracer.TraceOperationCreation(this, "Task: " + m_action.Method.Name);
- }
-
- try
- {
- // Queue to the indicated scheduler.
- m_taskScheduler.InternalQueueTask(this);
- }
- catch (Exception e)
- {
- // The scheduler had a problem queueing this task. Record the exception, leaving this task in
- // a Faulted state.
- TaskSchedulerException tse = new TaskSchedulerException(e);
- AddException(tse);
- Finish(false);
-
- // Now we need to mark ourselves as "handled" to avoid crashing the finalizer thread if we are called from StartNew(),
- // because the exception is either propagated outside directly, or added to an enclosing parent. However we won't do this for
- // continuation tasks, because in that case we internally eat the exception and therefore we need to make sure the user does
- // later observe it explicitly or see it on the finalizer.
-
- if ((Options & (TaskCreationOptions)InternalTaskOptions.ContinuationTask) == 0)
- {
- // m_contingentProperties.m_exceptionsHolder *should* already exist after AddException()
- Debug.Assert(
- (m_contingentProperties != null) &&
- (m_contingentProperties.m_exceptionsHolder != null) &&
- (m_contingentProperties.m_exceptionsHolder.ContainsFaultList),
- "Task.ScheduleAndStart(): Expected m_contingentProperties.m_exceptionsHolder to exist " +
- "and to have faults recorded.");
-
- m_contingentProperties.m_exceptionsHolder.MarkAsHandled(false);
- }
- // re-throw the exception wrapped as a TaskSchedulerException.
- throw tse;
- }
- }
-
- /// <summary>
- /// Adds an exception to the list of exceptions this task has thrown.
- /// </summary>
- /// <param name="exceptionObject">An object representing either an Exception or a collection of Exceptions.</param>
- internal void AddException(object exceptionObject)
- {
- Debug.Assert(exceptionObject != null, "Task.AddException: Expected a non-null exception object");
- AddException(exceptionObject, representsCancellation: false);
- }
-
- /// <summary>
- /// Adds an exception to the list of exceptions this task has thrown.
- /// </summary>
- /// <param name="exceptionObject">An object representing either an Exception or a collection of Exceptions.</param>
- /// <param name="representsCancellation">Whether the exceptionObject is an OperationCanceledException representing cancellation.</param>
- internal void AddException(object exceptionObject, bool representsCancellation)
- {
- Debug.Assert(exceptionObject != null, "Task.AddException: Expected a non-null exception object");
-
-#if DEBUG
- var eoAsException = exceptionObject as Exception;
- var eoAsEnumerableException = exceptionObject as IEnumerable<Exception>;
- var eoAsEdi = exceptionObject as ExceptionDispatchInfo;
- var eoAsEnumerableEdi = exceptionObject as IEnumerable<ExceptionDispatchInfo>;
-
- Debug.Assert(
- eoAsException != null || eoAsEnumerableException != null || eoAsEdi != null || eoAsEnumerableEdi != null,
- "Task.AddException: Expected an Exception, ExceptionDispatchInfo, or an IEnumerable<> of one of those");
-
- var eoAsOce = exceptionObject as OperationCanceledException;
-
- Debug.Assert(
- !representsCancellation ||
- eoAsOce != null ||
- (eoAsEdi != null && eoAsEdi.SourceException is OperationCanceledException),
- "representsCancellation should be true only if an OCE was provided.");
-#endif
-
- //
- // WARNING: A great deal of care went into ensuring that
- // AddException() and GetExceptions() are never called
- // simultaneously. See comment at start of GetExceptions().
- //
-
- // Lazily initialize the holder, ensuring only one thread wins.
- ContingentProperties props = EnsureContingentPropertiesInitialized();
- if (props.m_exceptionsHolder == null)
- {
- TaskExceptionHolder holder = new TaskExceptionHolder(this);
- if (Interlocked.CompareExchange(ref props.m_exceptionsHolder, holder, null) != null)
- {
- // If someone else already set the value, suppress finalization.
- holder.MarkAsHandled(false);
- }
- }
-
- lock (props)
- {
- props.m_exceptionsHolder.Add(exceptionObject, representsCancellation);
- }
- }
-
- /// <summary>
- /// Returns a list of exceptions by aggregating the holder's contents. Or null if
- /// no exceptions have been thrown.
- /// </summary>
- /// <param name="includeTaskCanceledExceptions">Whether to include a TCE if cancelled.</param>
- /// <returns>An aggregate exception, or null if no exceptions have been caught.</returns>
- private AggregateException? GetExceptions(bool includeTaskCanceledExceptions)
- {
- //
- // WARNING: The Task/Task<TResult>/TaskCompletionSource classes
- // have all been carefully crafted to insure that GetExceptions()
- // is never called while AddException() is being called. There
- // are locks taken on m_contingentProperties in several places:
- //
- // -- Task<TResult>.TrySetException(): The lock allows the
- // task to be set to Faulted state, and all exceptions to
- // be recorded, in one atomic action.
- //
- // -- Task.Exception_get(): The lock ensures that Task<TResult>.TrySetException()
- // is allowed to complete its operation before Task.Exception_get()
- // can access GetExceptions().
- //
- // -- Task.ThrowIfExceptional(): The lock insures that Wait() will
- // not attempt to call GetExceptions() while Task<TResult>.TrySetException()
- // is in the process of calling AddException().
- //
- // For "regular" tasks, we effectively keep AddException() and GetException()
- // from being called concurrently by the way that the state flows. Until
- // a Task is marked Faulted, Task.Exception_get() returns null. And
- // a Task is not marked Faulted until it and all of its children have
- // completed, which means that all exceptions have been recorded.
- //
- // It might be a lot easier to follow all of this if we just required
- // that all calls to GetExceptions() and AddExceptions() were made
- // under a lock on m_contingentProperties. But that would also
- // increase our lock occupancy time and the frequency with which we
- // would need to take the lock.
- //
- // If you add a call to GetExceptions() anywhere in the code,
- // please continue to maintain the invariant that it can't be
- // called when AddException() is being called.
- //
-
- // We'll lazily create a TCE if the task has been canceled.
- Exception? canceledException = null;
- if (includeTaskCanceledExceptions && IsCanceled)
- {
- // Backcompat:
- // Ideally we'd just use the cached OCE from this.GetCancellationExceptionDispatchInfo()
- // here. However, that would result in a potentially breaking change from .NET 4, which
- // has the code here that throws a new exception instead of the original, and the EDI
- // may not contain a TCE, but an OCE or any OCE-derived type, which would mean we'd be
- // propagating an exception of a different type.
- canceledException = new TaskCanceledException(this);
- canceledException.SetCurrentStackTrace();
- }
-
- if (ExceptionRecorded)
- {
- // There are exceptions; get the aggregate and optionally add the canceled
- // exception to the aggregate (if applicable).
- Debug.Assert(m_contingentProperties != null && m_contingentProperties.m_exceptionsHolder != null, "ExceptionRecorded should imply this");
-
- // No need to lock around this, as other logic prevents the consumption of exceptions
- // before they have been completely processed.
- return m_contingentProperties.m_exceptionsHolder.CreateExceptionObject(false, canceledException);
- }
- else if (canceledException != null)
- {
- // No exceptions, but there was a cancelation. Aggregate and return it.
- return new AggregateException(canceledException);
- }
-
- return null;
- }
-
- /// <summary>Gets the exception dispatch infos once the task has faulted.</summary>
- internal ReadOnlyCollection<ExceptionDispatchInfo> GetExceptionDispatchInfos()
- {
- Debug.Assert(IsFaulted && ExceptionRecorded, "Must only be used when the task has faulted with exceptions.");
- return m_contingentProperties!.m_exceptionsHolder!.GetExceptionDispatchInfos();
- }
-
- /// <summary>Gets the ExceptionDispatchInfo containing the OperationCanceledException for this task.</summary>
- /// <returns>The ExceptionDispatchInfo. May be null if no OCE was stored for the task.</returns>
- internal ExceptionDispatchInfo? GetCancellationExceptionDispatchInfo()
- {
- Debug.Assert(IsCanceled, "Must only be used when the task has canceled.");
- return Volatile.Read(ref m_contingentProperties)?.m_exceptionsHolder?.GetCancellationExceptionDispatchInfo(); // may be null
- }
-
- /// <summary>
- /// Throws an aggregate exception if the task contains exceptions.
- /// </summary>
- internal void ThrowIfExceptional(bool includeTaskCanceledExceptions)
- {
- Debug.Assert(IsCompleted, "ThrowIfExceptional(): Expected IsCompleted == true");
-
- Exception? exception = GetExceptions(includeTaskCanceledExceptions);
- if (exception != null)
- {
- UpdateExceptionObservedStatus();
- throw exception;
- }
- }
-
- /// <summary>Throws the exception on the ThreadPool.</summary>
- /// <param name="exception">The exception to propagate.</param>
- /// <param name="targetContext">The target context on which to propagate the exception. Null to use the ThreadPool.</param>
- internal static void ThrowAsync(Exception exception, SynchronizationContext? targetContext)
- {
- // Capture the exception into an ExceptionDispatchInfo so that its
- // stack trace and Watson bucket info will be preserved
- var edi = ExceptionDispatchInfo.Capture(exception);
-
- // If the user supplied a SynchronizationContext...
- if (targetContext != null)
- {
- try
- {
- // Post the throwing of the exception to that context, and return.
- targetContext.Post(state => ((ExceptionDispatchInfo)state!).Throw(), edi);
- return;
- }
- catch (Exception postException)
- {
- // If something goes horribly wrong in the Post, we'll
- // propagate both exceptions on the ThreadPool
- edi = ExceptionDispatchInfo.Capture(new AggregateException(exception, postException));
- }
- }
-
-#if CORERT
- RuntimeExceptionHelpers.ReportUnhandledException(edi.SourceException);
-#else
-
-#if FEATURE_COMINTEROP
- // If we have the new error reporting APIs, report this error.
- if (System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal.ReportUnhandledError(edi.SourceException))
- return;
-#endif
-
- // Propagate the exception(s) on the ThreadPool
- ThreadPool.QueueUserWorkItem(state => ((ExceptionDispatchInfo)state!).Throw(), edi);
-
-#endif // CORERT
- }
-
- /// <summary>
- /// Checks whether this is an attached task, and whether we are being called by the parent task.
- /// And sets the TASK_STATE_EXCEPTIONOBSERVEDBYPARENT status flag based on that.
- ///
- /// This is meant to be used internally when throwing an exception, and when WaitAll is gathering
- /// exceptions for tasks it waited on. If this flag gets set, the implicit wait on children
- /// will skip exceptions to prevent duplication.
- ///
- /// This should only be called when this task has completed with an exception
- ///
- /// </summary>
- internal void UpdateExceptionObservedStatus()
- {
- Task? parent = m_contingentProperties?.m_parent;
- if ((parent != null)
- && ((Options & TaskCreationOptions.AttachedToParent) != 0)
- && ((parent.CreationOptions & TaskCreationOptions.DenyChildAttach) == 0)
- && Task.InternalCurrent == parent)
- {
- m_stateFlags |= TASK_STATE_EXCEPTIONOBSERVEDBYPARENT;
- }
- }
-
- /// <summary>
- /// Checks whether the TASK_STATE_EXCEPTIONOBSERVEDBYPARENT status flag is set,
- /// This will only be used by the implicit wait to prevent double throws
- ///
- /// </summary>
- internal bool IsExceptionObservedByParent => (m_stateFlags & TASK_STATE_EXCEPTIONOBSERVEDBYPARENT) != 0;
-
- /// <summary>
- /// Checks whether the body was ever invoked. Used by task scheduler code to verify custom schedulers actually ran the task.
- /// </summary>
- internal bool IsDelegateInvoked => (m_stateFlags & TASK_STATE_DELEGATE_INVOKED) != 0;
-
- /// <summary>
- /// Signals completion of this particular task.
- ///
- /// The userDelegateExecute parameter indicates whether this Finish() call comes following the
- /// full execution of the user delegate.
- ///
- /// If userDelegateExecute is false, it mean user delegate wasn't invoked at all (either due to
- /// a cancellation request, or because this task is a promise style Task). In this case, the steps
- /// involving child tasks (i.e. WaitForChildren) will be skipped.
- ///
- /// </summary>
- internal void Finish(bool userDelegateExecute)
- {
- if (m_contingentProperties == null)
- {
- FinishStageTwo();
- }
- else
- {
- FinishSlow(userDelegateExecute);
- }
- }
-
- private void FinishSlow(bool userDelegateExecute)
- {
- Debug.Assert(userDelegateExecute || m_contingentProperties != null);
-
- if (!userDelegateExecute)
- {
- // delegate didn't execute => no children. We can safely call the remaining finish stages
- FinishStageTwo();
- }
- else
- {
- ContingentProperties props = m_contingentProperties!;
-
- // Count of 1 => either all children finished, or there were none. Safe to complete ourselves
- // without paying the price of an Interlocked.Decrement.
- if ((props.m_completionCountdown == 1) ||
- Interlocked.Decrement(ref props.m_completionCountdown) == 0) // Reaching this sub clause means there may be remaining active children,
- // and we could be racing with one of them to call FinishStageTwo().
- // So whoever does the final Interlocked.Dec is responsible to finish.
- {
- FinishStageTwo();
- }
- else
- {
- // Apparently some children still remain. It will be up to the last one to process the completion of this task on their own thread.
- // We will now yield the thread back to ThreadPool. Mark our state appropriately before getting out.
-
- // We have to use an atomic update for this and make sure not to overwrite a final state,
- // because at this very moment the last child's thread may be concurrently completing us.
- // Otherwise we risk overwriting the TASK_STATE_RAN_TO_COMPLETION, _CANCELED or _FAULTED bit which may have been set by that child task.
- // Note that the concurrent update by the last child happening in FinishStageTwo could still wipe out the TASK_STATE_WAITING_ON_CHILDREN flag,
- // but it is not critical to maintain, therefore we dont' need to intruduce a full atomic update into FinishStageTwo
-
- AtomicStateUpdate(TASK_STATE_WAITING_ON_CHILDREN, TASK_STATE_FAULTED | TASK_STATE_CANCELED | TASK_STATE_RAN_TO_COMPLETION);
- }
-
- // Now is the time to prune exceptional children. We'll walk the list and removes the ones whose exceptions we might have observed after they threw.
- // we use a local variable for exceptional children here because some other thread may be nulling out m_contingentProperties.m_exceptionalChildren
- List<Task>? exceptionalChildren = props.m_exceptionalChildren;
- if (exceptionalChildren != null)
- {
- lock (exceptionalChildren)
- {
- exceptionalChildren.RemoveAll(t => t.IsExceptionObservedByParent); // RemoveAll has better performance than doing it ourselves
- }
- }
- }
- }
-
- /// <summary>
- /// FinishStageTwo is to be executed as soon as we known there are no more children to complete.
- /// It can happen i) either on the thread that originally executed this task (if no children were spawned, or they all completed by the time this task's delegate quit)
- /// ii) or on the thread that executed the last child.
- /// </summary>
- private void FinishStageTwo()
- {
- // At this point, the task is done executing and waiting for its children,
- // we can transition our task to a completion state.
-
- ContingentProperties? cp = Volatile.Read(ref m_contingentProperties);
- if (cp != null)
- {
- AddExceptionsFromChildren(cp);
- }
-
- int completionState;
- if (ExceptionRecorded)
- {
- completionState = TASK_STATE_FAULTED;
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Error);
-
- if (s_asyncDebuggingEnabled)
- RemoveFromActiveTasks(this);
- }
- else if (IsCancellationRequested && IsCancellationAcknowledged)
- {
- // We transition into the TASK_STATE_CANCELED final state if the task's CT was signalled for cancellation,
- // and the user delegate acknowledged the cancellation request by throwing an OCE,
- // and the task hasn't otherwise transitioned into faulted state. (TASK_STATE_FAULTED trumps TASK_STATE_CANCELED)
- //
- // If the task threw an OCE without cancellation being requestsed (while the CT not being in signaled state),
- // then we regard it as a regular exception
-
- completionState = TASK_STATE_CANCELED;
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Canceled);
-
- if (s_asyncDebuggingEnabled)
- RemoveFromActiveTasks(this);
- }
- else
- {
- completionState = TASK_STATE_RAN_TO_COMPLETION;
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Completed);
-
- if (s_asyncDebuggingEnabled)
- RemoveFromActiveTasks(this);
- }
-
- // Use Interlocked.Exchange() to effect a memory fence, preventing
- // any SetCompleted() (or later) instructions from sneak back before it.
- Interlocked.Exchange(ref m_stateFlags, m_stateFlags | completionState);
-
- // Set the completion event if it's been lazy allocated.
- // And if we made a cancellation registration, it's now unnecessary.
- cp = Volatile.Read(ref m_contingentProperties); // need to re-read after updating state
- if (cp != null)
- {
- cp.SetCompleted();
- cp.UnregisterCancellationCallback();
- }
-
- // ready to run continuations and notify parent.
- FinishStageThree();
- }
-
- /// <summary>
- /// Final stage of the task completion code path. Notifies the parent (if any) that another of its children are done, and runs continuations.
- /// This function is only separated out from FinishStageTwo because these two operations are also needed to be called from CancellationCleanupLogic()
- /// </summary>
- internal void FinishStageThree()
- {
- // Release the action so that holding this task object alive doesn't also
- // hold alive the body of the task. We do this before notifying a parent,
- // so that if notifying the parent completes the parent and causes
- // its synchronous continuations to run, the GC can collect the state
- // in the interim. And we do it before finishing continuations, because
- // continuations hold onto the task, and therefore are keeping it alive.
- m_action = null;
-
- ContingentProperties? cp = m_contingentProperties;
- if (cp != null)
- {
- // Similarly, null out any ExecutionContext we may have captured,
- // to avoid keeping state like async locals alive unnecessarily
- // when the Task is kept alive.
- cp.m_capturedContext = null;
-
- // Notify parent if this was an attached task
- NotifyParentIfPotentiallyAttachedTask();
- }
-
- // Activate continuations (if any).
- FinishContinuations();
- }
-
- internal void NotifyParentIfPotentiallyAttachedTask()
- {
- Task? parent = m_contingentProperties?.m_parent;
- if (parent != null
- && ((parent.CreationOptions & TaskCreationOptions.DenyChildAttach) == 0)
- && (((TaskCreationOptions)(m_stateFlags & OptionsMask)) & TaskCreationOptions.AttachedToParent) != 0)
- {
- parent.ProcessChildCompletion(this);
- }
- }
-
- /// <summary>
- /// This is called by children of this task when they are completed.
- /// </summary>
- internal void ProcessChildCompletion(Task childTask)
- {
- Debug.Assert(childTask != null);
- Debug.Assert(childTask.IsCompleted, "ProcessChildCompletion was called for an uncompleted task");
-
- Debug.Assert(childTask.m_contingentProperties?.m_parent == this, "ProcessChildCompletion should only be called for a child of this task");
-
- ContingentProperties? props = Volatile.Read(ref m_contingentProperties);
-
- // if the child threw and we haven't observed it we need to save it for future reference
- if (childTask.IsFaulted && !childTask.IsExceptionObservedByParent)
- {
- // Lazily initialize the child exception list
- if (props!.m_exceptionalChildren == null)
- {
- Interlocked.CompareExchange(ref props.m_exceptionalChildren, new List<Task>(), null);
- }
-
- // In rare situations involving AppDomainUnload, it's possible (though unlikely) for FinishStageTwo() to be called
- // multiple times for the same task. In that case, AddExceptionsFromChildren() could be nulling m_exceptionalChildren
- // out at the same time that we're processing it, resulting in a NullReferenceException here. We'll protect
- // ourselves by caching m_exceptionChildren in a local variable.
- List<Task>? tmp = props.m_exceptionalChildren;
- if (tmp != null)
- {
- lock (tmp)
- {
- tmp.Add(childTask);
- }
- }
- }
-
- if (Interlocked.Decrement(ref props!.m_completionCountdown) == 0)
- {
- // This call came from the final child to complete, and apparently we have previously given up this task's right to complete itself.
- // So we need to invoke the final finish stage.
-
- FinishStageTwo();
- }
- }
-
- /// <summary>
- /// This is to be called just before the task does its final state transition.
- /// It traverses the list of exceptional children, and appends their aggregate exceptions into this one's exception list
- /// </summary>
- internal void AddExceptionsFromChildren(ContingentProperties props)
- {
- Debug.Assert(props != null);
-
- // In rare occurences during AppDomainUnload() processing, it is possible for this method to be called
- // simultaneously on the same task from two different contexts. This can result in m_exceptionalChildren
- // being nulled out while it is being processed, which could lead to a NullReferenceException. To
- // protect ourselves, we'll cache m_exceptionalChildren in a local variable.
- List<Task>? exceptionalChildren = props.m_exceptionalChildren;
-
- if (exceptionalChildren != null)
- {
- // This lock is necessary because even though AddExceptionsFromChildren is last to execute, it may still
- // be racing with the code segment at the bottom of Finish() that prunes the exceptional child array.
- lock (exceptionalChildren)
- {
- foreach (Task task in exceptionalChildren)
- {
- // Ensure any exceptions thrown by children are added to the parent.
- // In doing this, we are implicitly marking children as being "handled".
- Debug.Assert(task.IsCompleted, "Expected all tasks in list to be completed");
- if (task.IsFaulted && !task.IsExceptionObservedByParent)
- {
- TaskExceptionHolder? exceptionHolder = Volatile.Read(ref task.m_contingentProperties)!.m_exceptionsHolder;
- Debug.Assert(exceptionHolder != null);
-
- // No locking necessary since child task is finished adding exceptions
- // and concurrent CreateExceptionObject() calls do not constitute
- // a concurrency hazard.
- AddException(exceptionHolder.CreateExceptionObject(false, null));
- }
- }
- }
-
- // Reduce memory pressure by getting rid of the array
- props.m_exceptionalChildren = null;
- }
- }
-
- /// <summary>
- /// Outermost entry function to execute this task. Handles all aspects of executing a task on the caller thread.
- /// </summary>
- internal bool ExecuteEntry()
- {
- // Do atomic state transition from queued to invoked. If we observe a task that's already invoked,
- // we will return false so that TaskScheduler.ExecuteTask can throw an exception back to the custom scheduler.
- // However we don't want this exception to be throw if the task was already canceled, because it's a
- // legitimate scenario for custom schedulers to dequeue a task and mark it as canceled (example: throttling scheduler)
- int previousState = 0;
- if (!AtomicStateUpdate(TASK_STATE_DELEGATE_INVOKED,
- TASK_STATE_DELEGATE_INVOKED | TASK_STATE_COMPLETED_MASK,
- ref previousState) && (previousState & TASK_STATE_CANCELED) == 0)
- {
- // This task has already been invoked. Don't invoke it again.
- return false;
- }
-
- if (!IsCancellationRequested & !IsCanceled)
- {
- ExecuteWithThreadLocal(ref t_currentTask);
- }
- else
- {
- ExecuteEntryCancellationRequestedOrCanceled();
- }
-
- return true;
- }
-
- /// <summary>
- /// ThreadPool's entry point into the Task. The base behavior is simply to
- /// use the entry point that's not protected from double-invoke; derived internal tasks
- /// can override to customize their behavior, which is usually done by promises
- /// that want to reuse the same object as a queued work item.
- /// </summary>
- internal virtual void ExecuteFromThreadPool(Thread threadPoolThread) => ExecuteEntryUnsafe(threadPoolThread);
-
- internal void ExecuteEntryUnsafe(Thread? threadPoolThread) // used instead of ExecuteEntry() when we don't have to worry about double-execution prevent
- {
- // Remember that we started running the task delegate.
- m_stateFlags |= TASK_STATE_DELEGATE_INVOKED;
-
- if (!IsCancellationRequested & !IsCanceled)
- {
- ExecuteWithThreadLocal(ref t_currentTask, threadPoolThread);
- }
- else
- {
- ExecuteEntryCancellationRequestedOrCanceled();
- }
- }
-
- internal void ExecuteEntryCancellationRequestedOrCanceled()
- {
- if (!IsCanceled)
- {
- int prevState = Interlocked.Exchange(ref m_stateFlags, m_stateFlags | TASK_STATE_CANCELED);
- if ((prevState & TASK_STATE_CANCELED) == 0)
- {
- CancellationCleanupLogic();
- }
- }
- }
-
- // A trick so we can refer to the TLS slot with a byref.
- private void ExecuteWithThreadLocal(ref Task? currentTaskSlot, Thread? threadPoolThread = null)
- {
- // Remember the current task so we can restore it after running, and then
- Task? previousTask = currentTaskSlot;
-
- // ETW event for Task Started
- TplEventSource log = TplEventSource.Log;
- Guid savedActivityID = default;
- bool etwIsEnabled = log.IsEnabled();
- if (etwIsEnabled)
- {
- if (log.TasksSetActivityIds)
- EventSource.SetCurrentThreadActivityId(TplEventSource.CreateGuidForTaskID(this.Id), out savedActivityID);
- // previousTask holds the actual "current task" we want to report in the event
- if (previousTask != null)
- log.TaskStarted(previousTask.m_taskScheduler!.Id, previousTask.Id, this.Id);
- else
- log.TaskStarted(TaskScheduler.Current.Id, 0, this.Id);
- }
-
- bool loggingOn = AsyncCausalityTracer.LoggingOn;
- if (loggingOn)
- AsyncCausalityTracer.TraceSynchronousWorkStart(this, CausalitySynchronousWork.Execution);
-
- try
- {
- // place the current task into TLS.
- currentTaskSlot = this;
-
- // Execute the task body
- try
- {
- ExecutionContext? ec = CapturedContext;
- if (ec == null)
- {
- // No context, just run the task directly.
- InnerInvoke();
- }
- else
- {
- // Invoke it under the captured ExecutionContext
- if (threadPoolThread is null)
- {
- ExecutionContext.RunInternal(ec, s_ecCallback, this);
- }
- else
- {
- ExecutionContext.RunFromThreadPoolDispatchLoop(threadPoolThread, ec, s_ecCallback, this);
- }
- }
- }
- catch (Exception exn)
- {
- // Record this exception in the task's exception list
- HandleException(exn);
- }
-
- if (loggingOn)
- AsyncCausalityTracer.TraceSynchronousWorkCompletion(CausalitySynchronousWork.Execution);
-
- Finish(true);
- }
- finally
- {
- currentTaskSlot = previousTask;
-
- // ETW event for Task Completed
- if (etwIsEnabled)
- {
- // previousTask holds the actual "current task" we want to report in the event
- if (previousTask != null)
- log.TaskCompleted(previousTask.m_taskScheduler!.Id, previousTask.Id, this.Id, IsFaulted);
- else
- log.TaskCompleted(TaskScheduler.Current.Id, 0, this.Id, IsFaulted);
-
- if (log.TasksSetActivityIds)
- EventSource.SetCurrentThreadActivityId(savedActivityID);
- }
- }
- }
-
- private static readonly ContextCallback s_ecCallback = obj =>
- {
- Debug.Assert(obj is Task);
- // Only used privately to pass directly to EC.Run
- Unsafe.As<Task>(obj).InnerInvoke();
- };
-
- /// <summary>
- /// The actual code which invokes the body of the task. This can be overridden in derived types.
- /// </summary>
- internal virtual void InnerInvoke()
- {
- // Invoke the delegate
- Debug.Assert(m_action != null, "Null action in InnerInvoke()");
- if (m_action is Action action)
- {
- action();
- return;
- }
-
- if (m_action is Action<object?> actionWithState)
- {
- actionWithState(m_stateObject);
- return;
- }
- Debug.Fail("Invalid m_action in Task");
- }
-
- /// <summary>
- /// Performs whatever handling is necessary for an unhandled exception. Normally
- /// this just entails adding the exception to the holder object.
- /// </summary>
- /// <param name="unhandledException">The exception that went unhandled.</param>
- private void HandleException(Exception unhandledException)
- {
- Debug.Assert(unhandledException != null);
-
- if (unhandledException is OperationCanceledException exceptionAsOce && IsCancellationRequested &&
- m_contingentProperties!.m_cancellationToken == exceptionAsOce.CancellationToken)
- {
- // All conditions are satisfied for us to go into canceled state in Finish().
- // Mark the acknowledgement. The exception is also stored to enable it to be
- // the exception propagated from an await.
-
- SetCancellationAcknowledged();
- AddException(exceptionAsOce, representsCancellation: true);
- }
- else
- {
- // Other exceptions, including any OCE from the task that doesn't match the tasks' own CT,
- // or that gets thrown without the CT being set will be treated as an ordinary exception
- // and added to the aggregate.
-
- AddException(unhandledException);
- }
- }
-
- #region Await Support
- /// <summary>Gets an awaiter used to await this <see cref="System.Threading.Tasks.Task"/>.</summary>
- /// <returns>An awaiter instance.</returns>
- /// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
- public TaskAwaiter GetAwaiter()
- {
- return new TaskAwaiter(this);
- }
-
- /// <summary>Configures an awaiter used to await this <see cref="System.Threading.Tasks.Task"/>.</summary>
- /// <param name="continueOnCapturedContext">
- /// true to attempt to marshal the continuation back to the original context captured; otherwise, false.
- /// </param>
- /// <returns>An object used to await this task.</returns>
- public ConfiguredTaskAwaitable ConfigureAwait(bool continueOnCapturedContext)
- {
- return new ConfiguredTaskAwaitable(this, continueOnCapturedContext);
- }
-
- /// <summary>
- /// Sets a continuation onto the <see cref="System.Threading.Tasks.Task"/>.
- /// The continuation is scheduled to run in the current synchronization context is one exists,
- /// otherwise in the current task scheduler.
- /// </summary>
- /// <param name="continuationAction">The action to invoke when the <see cref="System.Threading.Tasks.Task"/> has completed.</param>
- /// <param name="continueOnCapturedContext">
- /// true to attempt to marshal the continuation back to the original context captured; otherwise, false.
- /// </param>
- /// <param name="flowExecutionContext">Whether to flow ExecutionContext across the await.</param>
- /// <exception cref="System.InvalidOperationException">The awaiter was not properly initialized.</exception>
- internal void SetContinuationForAwait(
- Action continuationAction, bool continueOnCapturedContext, bool flowExecutionContext)
- {
- Debug.Assert(continuationAction != null);
-
- // Create the best AwaitTaskContinuation object given the request.
- // If this remains null by the end of the function, we can use the
- // continuationAction directly without wrapping it.
- TaskContinuation? tc = null;
-
- // If the user wants the continuation to run on the current "context" if there is one...
- if (continueOnCapturedContext)
- {
- // First try getting the current synchronization context.
- // If the current context is really just the base SynchronizationContext type,
- // which is intended to be equivalent to not having a current SynchronizationContext at all,
- // then ignore it. This helps with performance by avoiding unnecessary posts and queueing
- // of work items, but more so it ensures that if code happens to publish the default context
- // as current, it won't prevent usage of a current task scheduler if there is one.
- SynchronizationContext? syncCtx = SynchronizationContext.Current;
- if (syncCtx != null && syncCtx.GetType() != typeof(SynchronizationContext))
- {
- tc = new SynchronizationContextAwaitTaskContinuation(syncCtx, continuationAction, flowExecutionContext);
- }
- else
- {
- // If there was no SynchronizationContext, then try for the current scheduler.
- // We only care about it if it's not the default.
- TaskScheduler? scheduler = TaskScheduler.InternalCurrent;
- if (scheduler != null && scheduler != TaskScheduler.Default)
- {
- tc = new TaskSchedulerAwaitTaskContinuation(scheduler, continuationAction, flowExecutionContext);
- }
- }
- }
-
- if (tc == null && flowExecutionContext)
- {
- // We're targeting the default scheduler, so we can use the faster path
- // that assumes the default, and thus we don't need to store it. If we're flowing
- // ExecutionContext, we need to capture it and wrap it in an AwaitTaskContinuation.
- // Otherwise, we're targeting the default scheduler and we don't need to flow ExecutionContext, so
- // we don't actually need a continuation object. We can just store/queue the action itself.
- tc = new AwaitTaskContinuation(continuationAction, flowExecutionContext: true);
- }
-
- // Now register the continuation, and if we couldn't register it because the task is already completing,
- // process the continuation directly (in which case make sure we schedule the continuation
- // rather than inlining it, the latter of which could result in a rare but possible stack overflow).
- if (tc != null)
- {
- if (!AddTaskContinuation(tc, addBeforeOthers: false))
- tc.Run(this, canInlineContinuationTask: false);
- }
- else
- {
- Debug.Assert(!flowExecutionContext, "We already determined we're not required to flow context.");
- if (!AddTaskContinuation(continuationAction, addBeforeOthers: false))
- AwaitTaskContinuation.UnsafeScheduleAction(continuationAction, this);
- }
- }
-
- /// <summary>
- /// Sets a continuation onto the <see cref="System.Threading.Tasks.Task"/>.
- /// The continuation is scheduled to run in the current synchronization context is one exists,
- /// otherwise in the current task scheduler.
- /// </summary>
- /// <param name="stateMachineBox">The action to invoke when the <see cref="System.Threading.Tasks.Task"/> has completed.</param>
- /// <param name="continueOnCapturedContext">
- /// true to attempt to marshal the continuation back to the original context captured; otherwise, false.
- /// </param>
- /// <exception cref="System.InvalidOperationException">The awaiter was not properly initialized.</exception>
- internal void UnsafeSetContinuationForAwait(IAsyncStateMachineBox stateMachineBox, bool continueOnCapturedContext)
- {
- Debug.Assert(stateMachineBox != null);
-
- // This code path doesn't emit all expected TPL-related events, such as for continuations.
- // It's expected that all callers check whether events are enabled before calling this function,
- // and only call it if they're not, so we assert. However, as events can be dynamically turned
- // on and off, it's possible this assert could fire even when used correctly. If it becomes
- // noisy, it can be deleted.
- Debug.Assert(!TplEventSource.Log.IsEnabled());
-
- // If the caller wants to continue on the current context/scheduler and there is one,
- // fall back to using the state machine's delegate.
- if (continueOnCapturedContext)
- {
- SynchronizationContext? syncCtx = SynchronizationContext.Current;
- if (syncCtx != null && syncCtx.GetType() != typeof(SynchronizationContext))
- {
- var tc = new SynchronizationContextAwaitTaskContinuation(syncCtx, stateMachineBox.MoveNextAction, flowExecutionContext: false);
- if (!AddTaskContinuation(tc, addBeforeOthers: false))
- {
- tc.Run(this, canInlineContinuationTask: false);
- }
- return;
- }
- else
- {
- TaskScheduler? scheduler = TaskScheduler.InternalCurrent;
- if (scheduler != null && scheduler != TaskScheduler.Default)
- {
- var tc = new TaskSchedulerAwaitTaskContinuation(scheduler, stateMachineBox.MoveNextAction, flowExecutionContext: false);
- if (!AddTaskContinuation(tc, addBeforeOthers: false))
- {
- tc.Run(this, canInlineContinuationTask: false);
- }
- return;
- }
- }
- }
-
- // Otherwise, add the state machine box directly as the continuation.
- // If we're unable to because the task has already completed, queue it.
- if (!AddTaskContinuation(stateMachineBox, addBeforeOthers: false))
- {
- ThreadPool.UnsafeQueueUserWorkItemInternal(stateMachineBox, preferLocal: true);
- }
- }
-
- /// <summary>Creates an awaitable that asynchronously yields back to the current context when awaited.</summary>
- /// <returns>
- /// A context that, when awaited, will asynchronously transition back into the current context at the
- /// time of the await. If the current SynchronizationContext is non-null, that is treated as the current context.
- /// Otherwise, TaskScheduler.Current is treated as the current context.
- /// </returns>
- public static YieldAwaitable Yield()
- {
- return default;
- }
- #endregion
-
- /// <summary>
- /// Waits for the <see cref="Task"/> to complete execution.
- /// </summary>
- /// <exception cref="System.AggregateException">
- /// The <see cref="Task"/> was canceled -or- an exception was thrown during
- /// the execution of the <see cref="Task"/>.
- /// </exception>
- public void Wait()
- {
-#if DEBUG
- bool waitResult =
-#endif
- Wait(Timeout.Infinite, default);
-
-#if DEBUG
- Debug.Assert(waitResult, "expected wait to succeed");
-#endif
- }
-
- /// <summary>
- /// Waits for the <see cref="Task"/> to complete execution.
- /// </summary>
- /// <param name="timeout">
- /// A <see cref="System.TimeSpan"/> that represents the number of milliseconds to wait, or a <see
- /// cref="System.TimeSpan"/> that represents -1 milliseconds to wait indefinitely.
- /// </param>
- /// <returns>
- /// true if the <see cref="Task"/> completed execution within the allotted time; otherwise, false.
- /// </returns>
- /// <exception cref="System.AggregateException">
- /// The <see cref="Task"/> was canceled -or- an exception was thrown during the execution of the <see
- /// cref="Task"/>.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// <paramref name="timeout"/> is a negative number other than -1 milliseconds, which represents an
- /// infinite time-out -or- timeout is greater than
- /// <see cref="int.MaxValue"/>.
- /// </exception>
- public bool Wait(TimeSpan timeout)
- {
- long totalMilliseconds = (long)timeout.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.timeout);
- }
-
- return Wait((int)totalMilliseconds, default);
- }
-
- /// <summary>
- /// Waits for the <see cref="Task"/> to complete execution.
- /// </summary>
- /// <param name="cancellationToken">
- /// A <see cref="CancellationToken"/> to observe while waiting for the task to complete.
- /// </param>
- /// <exception cref="System.OperationCanceledException">
- /// The <paramref name="cancellationToken"/> was canceled.
- /// </exception>
- /// <exception cref="System.AggregateException">
- /// The <see cref="Task"/> was canceled -or- an exception was thrown during the execution of the <see
- /// cref="Task"/>.
- /// </exception>
- public void Wait(CancellationToken cancellationToken)
- {
- Wait(Timeout.Infinite, cancellationToken);
- }
-
- /// <summary>
- /// Waits for the <see cref="Task"/> to complete execution.
- /// </summary>
- /// <param name="millisecondsTimeout">
- /// The number of milliseconds to wait, or <see cref="System.Threading.Timeout.Infinite"/> (-1) to
- /// wait indefinitely.</param>
- /// <returns>true if the <see cref="Task"/> completed execution within the allotted time; otherwise,
- /// false.
- /// </returns>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// <paramref name="millisecondsTimeout"/> is a negative number other than -1, which represents an
- /// infinite time-out.
- /// </exception>
- /// <exception cref="System.AggregateException">
- /// The <see cref="Task"/> was canceled -or- an exception was thrown during the execution of the <see
- /// cref="Task"/>.
- /// </exception>
- public bool Wait(int millisecondsTimeout)
- {
- return Wait(millisecondsTimeout, default);
- }
-
- /// <summary>
- /// Waits for the <see cref="Task"/> to complete execution.
- /// </summary>
- /// <param name="millisecondsTimeout">
- /// The number of milliseconds to wait, or <see cref="System.Threading.Timeout.Infinite"/> (-1) to
- /// wait indefinitely.
- /// </param>
- /// <param name="cancellationToken">
- /// A <see cref="CancellationToken"/> to observe while waiting for the task to complete.
- /// </param>
- /// <returns>
- /// true if the <see cref="Task"/> completed execution within the allotted time; otherwise, false.
- /// </returns>
- /// <exception cref="System.AggregateException">
- /// The <see cref="Task"/> was canceled -or- an exception was thrown during the execution of the <see
- /// cref="Task"/>.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// <paramref name="millisecondsTimeout"/> is a negative number other than -1, which represents an
- /// infinite time-out.
- /// </exception>
- /// <exception cref="System.OperationCanceledException">
- /// The <paramref name="cancellationToken"/> was canceled.
- /// </exception>
- public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
- {
- if (millisecondsTimeout < -1)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsTimeout);
- }
-
- // Return immediately if we know that we've completed "clean" -- no exceptions, no cancellations
- // and if no notification to the debugger is required
- if (!IsWaitNotificationEnabledOrNotRanToCompletion) // (!DebuggerBitSet && RanToCompletion)
- return true;
-
- // Wait, and then return if we're still not done.
- if (!InternalWait(millisecondsTimeout, cancellationToken))
- return false;
-
- if (IsWaitNotificationEnabledOrNotRanToCompletion) // avoid a few unnecessary volatile reads if we completed successfully
- {
- // Notify the debugger of the wait completion if it's requested such a notification
- NotifyDebuggerOfWaitCompletionIfNecessary();
-
- // If cancellation was requested and the task was canceled, throw an
- // OperationCanceledException. This is prioritized ahead of the ThrowIfExceptional
- // call to bring more determinism to cases where the same token is used to
- // cancel the Wait and to cancel the Task. Otherwise, there's a race condition between
- // whether the Wait or the Task observes the cancellation request first,
- // and different exceptions result from the different cases.
- if (IsCanceled) cancellationToken.ThrowIfCancellationRequested();
-
- // If an exception occurred, or the task was cancelled, throw an exception.
- ThrowIfExceptional(true);
- }
-
- Debug.Assert((m_stateFlags & TASK_STATE_FAULTED) == 0, "Task.Wait() completing when in Faulted state.");
-
- return true;
- }
-
- // Convenience method that wraps any scheduler exception in a TaskSchedulerException
- // and rethrows it.
- private bool WrappedTryRunInline()
- {
- if (m_taskScheduler == null)
- return false;
-
- try
- {
- return m_taskScheduler.TryRunInline(this, true);
- }
- catch (Exception e)
- {
- throw new TaskSchedulerException(e);
- }
- }
-
- /// <summary>
- /// The core wait function, which is only accessible internally. It's meant to be used in places in TPL code where
- /// the current context is known or cached.
- /// </summary>
- [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger
- internal bool InternalWait(int millisecondsTimeout, CancellationToken cancellationToken) =>
- InternalWaitCore(millisecondsTimeout, cancellationToken);
-
- // Separated out to allow it to be optimized (caller is marked NoOptimization for VS parallel debugger
- // to be able to see the method on the stack and inspect arguments).
- private bool InternalWaitCore(int millisecondsTimeout, CancellationToken cancellationToken)
- {
- // If the task has already completed, there's nothing to wait for.
- bool returnValue = IsCompleted;
- if (returnValue)
- {
- return true;
- }
-
- // ETW event for Task Wait Begin
- TplEventSource log = TplEventSource.Log;
- bool etwIsEnabled = log.IsEnabled();
- if (etwIsEnabled)
- {
- Task? currentTask = Task.InternalCurrent;
- log.TaskWaitBegin(
- currentTask != null ? currentTask.m_taskScheduler!.Id : TaskScheduler.Default.Id, currentTask != null ? currentTask.Id : 0,
- this.Id, TplEventSource.TaskWaitBehavior.Synchronous, 0);
- }
-
- // Alert a listening debugger that we can't make forward progress unless it slips threads.
- // We call NOCTD for two reasons:
- // 1. If the task runs on another thread, then we'll be blocked here indefinitely.
- // 2. If the task runs inline but takes some time to complete, it will suffer ThreadAbort with possible state corruption,
- // and it is best to prevent this unless the user explicitly asks to view the value with thread-slipping enabled.
- Debugger.NotifyOfCrossThreadDependency();
-
- // We will attempt inline execution only if an infinite wait was requested
- // Inline execution doesn't make sense for finite timeouts and if a cancellation token was specified
- // because we don't know how long the task delegate will take.
- if (millisecondsTimeout == Timeout.Infinite && !cancellationToken.CanBeCanceled &&
- WrappedTryRunInline() && IsCompleted) // TryRunInline doesn't guarantee completion, as there may be unfinished children.
- {
- returnValue = true;
- }
- else
- {
- returnValue = SpinThenBlockingWait(millisecondsTimeout, cancellationToken);
- }
-
- Debug.Assert(IsCompleted || millisecondsTimeout != Timeout.Infinite);
-
- // ETW event for Task Wait End
- if (etwIsEnabled)
- {
- Task? currentTask = Task.InternalCurrent;
- if (currentTask != null)
- {
- log.TaskWaitEnd(currentTask.m_taskScheduler!.Id, currentTask.Id, this.Id);
- }
- else
- {
- log.TaskWaitEnd(TaskScheduler.Default.Id, 0, this.Id);
- }
- // logically the continuation is empty so we immediately fire
- log.TaskWaitContinuationComplete(this.Id);
- }
-
- return returnValue;
- }
-
- // An MRES that gets set when Invoke is called. This replaces old logic that looked like this:
- // ManualResetEventSlim mres = new ManualResetEventSlim(false, 0);
- // Action<Task> completionAction = delegate {mres.Set();}
- // AddCompletionAction(completionAction);
- // with this:
- // SetOnInvokeMres mres = new SetOnInvokeMres();
- // AddCompletionAction(mres, addBeforeOthers: true);
- // which saves a couple of allocations.
- //
- // Used in SpinThenBlockingWait (below), but could be seen as a general purpose mechanism.
- private sealed class SetOnInvokeMres : ManualResetEventSlim, ITaskCompletionAction
- {
- internal SetOnInvokeMres() : base(false, 0) { }
- public void Invoke(Task completingTask) { Set(); }
- public bool InvokeMayRunArbitraryCode => false;
- }
-
- /// <summary>
- /// Waits for the task to complete, for a timeout to occur, or for cancellation to be requested.
- /// The method first spins and then falls back to blocking on a new event.
- /// </summary>
- /// <param name="millisecondsTimeout">The timeout.</param>
- /// <param name="cancellationToken">The token.</param>
- /// <returns>true if the task is completed; otherwise, false.</returns>
- private bool SpinThenBlockingWait(int millisecondsTimeout, CancellationToken cancellationToken)
- {
- bool infiniteWait = millisecondsTimeout == Timeout.Infinite;
- uint startTimeTicks = infiniteWait ? 0 : (uint)Environment.TickCount;
- bool returnValue = SpinWait(millisecondsTimeout);
- if (!returnValue)
- {
- var mres = new SetOnInvokeMres();
- try
- {
- AddCompletionAction(mres, addBeforeOthers: true);
- if (infiniteWait)
- {
- returnValue = mres.Wait(Timeout.Infinite, cancellationToken);
- }
- else
- {
- uint elapsedTimeTicks = ((uint)Environment.TickCount) - startTimeTicks;
- if (elapsedTimeTicks < millisecondsTimeout)
- {
- returnValue = mres.Wait((int)(millisecondsTimeout - elapsedTimeTicks), cancellationToken);
- }
- }
- }
- finally
- {
- if (!IsCompleted) RemoveContinuation(mres);
- // Don't Dispose of the MRES, because the continuation off of this task may
- // still be running. This is ok, however, as we never access the MRES' WaitHandle,
- // and thus no finalizable resources are actually allocated.
- }
- }
- return returnValue;
- }
-
- /// <summary>
- /// Spins briefly while checking IsCompleted
- /// </summary>
- /// <param name="millisecondsTimeout">The timeout.</param>
- /// <returns>true if the task is completed; otherwise, false.</returns>
- /// <exception cref="System.OperationCanceledException">The wait was canceled.</exception>
- private bool SpinWait(int millisecondsTimeout)
- {
- if (IsCompleted) return true;
-
- if (millisecondsTimeout == 0)
- {
- // For 0-timeouts, we just return immediately.
- return false;
- }
-
- int spinCount = Threading.SpinWait.SpinCountforSpinBeforeWait;
- SpinWait spinner = default;
- while (spinner.Count < spinCount)
- {
- spinner.SpinOnce(sleep1Threshold: -1);
-
- if (IsCompleted)
- {
- return true;
- }
- }
-
- return false;
- }
-
- /// <summary>
- /// Cancels the <see cref="Task"/>.
- /// </summary>
- /// <param name="bCancelNonExecutingOnly">
- /// Indicates whether we should only cancel non-invoked tasks.
- /// For the default scheduler this option will only be serviced through TryDequeue.
- /// For custom schedulers we also attempt an atomic state transition.
- /// </param>
- /// <returns>true if the task was successfully canceled; otherwise, false.</returns>
- internal bool InternalCancel(bool bCancelNonExecutingOnly)
- {
- Debug.Assert((Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) == 0, "Task.InternalCancel() did not expect promise-style task");
-
- bool bPopSucceeded = false;
- bool mustCleanup = false;
-
- TaskSchedulerException? tse = null;
-
- // If started, and running in a task context, we can try to pop the chore.
- if ((m_stateFlags & TASK_STATE_STARTED) != 0)
- {
- TaskScheduler? ts = m_taskScheduler;
-
- try
- {
- bPopSucceeded = (ts != null) && ts.TryDequeue(this);
- }
- catch (Exception e)
- {
- // TryDequeue threw. We don't know whether the task was properly dequeued or not. So we must let the rest of
- // the cancellation logic run its course (record the request, attempt atomic state transition and do cleanup where appropriate)
- // Here we will only record a TaskSchedulerException, which will later be thrown at function exit.
-
- tse = new TaskSchedulerException(e);
- }
-
- bool bRequiresAtomicStartTransition = ts != null && ts.RequiresAtomicStartTransition;
-
- if (!bPopSucceeded && bCancelNonExecutingOnly && bRequiresAtomicStartTransition)
- {
- // The caller requested cancellation of non-invoked tasks only, and TryDequeue was one way of doing it...
- // Since that seems to have failed, we should now try an atomic state transition (from non-invoked state to canceled)
- // An atomic transition here is only safe if we know we're on a custom task scheduler, which also forces a CAS on ExecuteEntry
-
- // Even though this task can't have any children, we should be ready for handling any continuations that
- // may be attached to it (although currently
- // So we need to remeber whether we actually did the flip, so we can do clean up (finish continuations etc)
- mustCleanup = AtomicStateUpdate(TASK_STATE_CANCELED, TASK_STATE_DELEGATE_INVOKED | TASK_STATE_CANCELED);
-
- // PS: This is slightly different from the regular cancellation codepath
- // since we record the cancellation request *after* doing the state transition.
- // However that shouldn't matter too much because the task was never invoked, thus can't have children
- }
- }
-
- if (!bCancelNonExecutingOnly || bPopSucceeded || mustCleanup)
- {
- // Record the cancellation request.
- RecordInternalCancellationRequest();
-
- // Determine whether we need to clean up
- // This will be the case
- // 1) if we were able to pop, and we are able to update task state to TASK_STATE_CANCELED
- // 2) if the task seems to be yet unstarted, and we can transition to
- // TASK_STATE_CANCELED before anyone else can transition into _STARTED or _CANCELED or
- // _RAN_TO_COMPLETION or _FAULTED
- // Note that we do not check for TASK_STATE_COMPLETION_RESERVED. That only applies to promise-style
- // tasks, and a promise-style task should not enter into this codepath.
- if (bPopSucceeded)
- {
- // hitting this would mean something wrong with the AtomicStateUpdate above
- Debug.Assert(!mustCleanup, "Possibly an invalid state transition call was made in InternalCancel()");
-
- // Include TASK_STATE_DELEGATE_INVOKED in "illegal" bits to protect against the situation where
- // TS.TryDequeue() returns true but the task is still left on the queue.
- mustCleanup = AtomicStateUpdate(TASK_STATE_CANCELED, TASK_STATE_CANCELED | TASK_STATE_DELEGATE_INVOKED);
- }
- else if (!mustCleanup && (m_stateFlags & TASK_STATE_STARTED) == 0)
- {
- mustCleanup = AtomicStateUpdate(TASK_STATE_CANCELED,
- TASK_STATE_CANCELED | TASK_STATE_STARTED | TASK_STATE_RAN_TO_COMPLETION |
- TASK_STATE_FAULTED | TASK_STATE_DELEGATE_INVOKED);
- }
-
- // do the cleanup (i.e. set completion event and finish continuations)
- if (mustCleanup)
- {
- CancellationCleanupLogic();
- }
- }
-
- if (tse != null)
- throw tse;
- else
- return mustCleanup;
- }
-
- // Breaks out logic for recording a cancellation request
- internal void RecordInternalCancellationRequest()
- {
- // Record the cancellation request.
- EnsureContingentPropertiesInitialized().m_internalCancellationRequested = CANCELLATION_REQUESTED;
- }
-
- // Breaks out logic for recording a cancellation request
- // This overload should only be used for promise tasks where no cancellation token
- // was supplied when the task was created.
- internal void RecordInternalCancellationRequest(CancellationToken tokenToRecord)
- {
- RecordInternalCancellationRequest();
-
- Debug.Assert((Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0, "Task.RecordInternalCancellationRequest(CancellationToken) only valid for promise-style task");
- Debug.Assert(m_contingentProperties!.m_cancellationToken == default);
-
- // Store the supplied cancellation token as this task's token.
- // Waiting on this task will then result in an OperationCanceledException containing this token.
- if (tokenToRecord != default)
- {
- m_contingentProperties.m_cancellationToken = tokenToRecord;
- }
- }
-
- // Breaks out logic for recording a cancellation request
- // This overload should only be used for promise tasks where no cancellation token
- // was supplied when the task was created.
- internal void RecordInternalCancellationRequest(CancellationToken tokenToRecord, object? cancellationException)
- {
- RecordInternalCancellationRequest(tokenToRecord);
-
- // Store the supplied cancellation exception
- if (cancellationException != null)
- {
-#if DEBUG
- var oce = cancellationException as OperationCanceledException;
- if (oce == null)
- {
- var edi = cancellationException as ExceptionDispatchInfo;
- Debug.Assert(edi != null, "Expected either an OCE or an EDI");
- oce = edi.SourceException as OperationCanceledException;
- Debug.Assert(oce != null, "Expected EDI to contain an OCE");
- }
- Debug.Assert(oce.CancellationToken == tokenToRecord,
- "Expected OCE's token to match the provided token.");
-#endif
- AddException(cancellationException, representsCancellation: true);
- }
- }
-
- // ASSUMES THAT A SUCCESSFUL CANCELLATION HAS JUST OCCURRED ON THIS TASK!!!
- // And this method should be called at most once per task.
- internal void CancellationCleanupLogic()
- {
- Debug.Assert((m_stateFlags & (TASK_STATE_CANCELED | TASK_STATE_COMPLETION_RESERVED)) != 0, "Task.CancellationCleanupLogic(): Task not canceled or reserved.");
- // We'd like to be able to:
- // Debug.Assert((m_completionEvent == null) || !m_completionEvent.IsSet, "Task.CancellationCleanupLogic(): Completion event already set.");
- // However, there is a small window for a race condition. If someone calls Wait() between InternalCancel() and
- // here, that will set m_completionEvent, leading to a meaningless/harmless assertion.
-
- // This may have been set already, but we need to make sure.
- Interlocked.Exchange(ref m_stateFlags, m_stateFlags | TASK_STATE_CANCELED);
-
- // Fire completion event if it has been lazily initialized
- ContingentProperties? cp = Volatile.Read(ref m_contingentProperties);
- if (cp != null)
- {
- cp.SetCompleted();
- cp.UnregisterCancellationCallback();
- }
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Canceled);
-
- if (s_asyncDebuggingEnabled)
- RemoveFromActiveTasks(this);
-
- // Notify parents, fire continuations, other cleanup.
- FinishStageThree();
- }
-
- /// <summary>
- /// Sets the task's cancellation acknowledged flag.
- /// </summary>
- private void SetCancellationAcknowledged()
- {
- Debug.Assert(this == Task.InternalCurrent, "SetCancellationAcknowledged() should only be called while this is still the current task");
- Debug.Assert(IsCancellationRequested, "SetCancellationAcknowledged() should not be called if the task's CT wasn't signaled");
-
- m_stateFlags |= TASK_STATE_CANCELLATIONACKNOWLEDGED;
- }
-
- /// <summary>Completes a promise task as RanToCompletion.</summary>
- /// <remarks>If this is a Task{T}, default(T) is the implied result.</remarks>
- /// <returns>true if the task was transitioned to ran to completion; false if it was already completed.</returns>
- internal bool TrySetResult()
- {
- Debug.Assert(m_action == null, "Task<T>.TrySetResult(): non-null m_action");
-
- if (AtomicStateUpdate(
- TASK_STATE_COMPLETION_RESERVED | TASK_STATE_RAN_TO_COMPLETION,
- TASK_STATE_COMPLETION_RESERVED | TASK_STATE_RAN_TO_COMPLETION | TASK_STATE_FAULTED | TASK_STATE_CANCELED))
- {
- ContingentProperties? props = m_contingentProperties;
- if (props != null)
- {
- NotifyParentIfPotentiallyAttachedTask();
- props.SetCompleted();
- }
- FinishContinuations();
- return true;
- }
-
- return false;
- }
-
- // Allow multiple exceptions to be assigned to a promise-style task.
- // This is useful when a TaskCompletionSource<T> stands in as a proxy
- // for a "real" task (as we do in Unwrap(), ContinueWhenAny() and ContinueWhenAll())
- // and the "real" task ends up with multiple exceptions, which is possible when
- // a task has children.
- //
- // Called from TaskCompletionSource<T>.SetException(IEnumerable<Exception>).
- internal bool TrySetException(object exceptionObject)
- {
- Debug.Assert(m_action == null, "Task<T>.TrySetException(): non-null m_action");
-
- // TCS.{Try}SetException() should have checked for this
- Debug.Assert(exceptionObject != null, "Expected non-null exceptionObject argument");
-
- // Only accept these types.
- Debug.Assert(
- (exceptionObject is Exception) || (exceptionObject is IEnumerable<Exception>) ||
- (exceptionObject is ExceptionDispatchInfo) || (exceptionObject is IEnumerable<ExceptionDispatchInfo>),
- "Expected exceptionObject to be either Exception, ExceptionDispatchInfo, or IEnumerable<> of one of those");
-
- bool returnValue = false;
-
- // "Reserve" the completion for this task, while making sure that: (1) No prior reservation
- // has been made, (2) The result has not already been set, (3) An exception has not previously
- // been recorded, and (4) Cancellation has not been requested.
- //
- // If the reservation is successful, then add the exception(s) and finish completion processing.
- //
- // The lazy initialization may not be strictly necessary, but I'd like to keep it here
- // anyway. Some downstream logic may depend upon an inflated m_contingentProperties.
- EnsureContingentPropertiesInitialized();
- if (AtomicStateUpdate(
- TASK_STATE_COMPLETION_RESERVED,
- TASK_STATE_COMPLETION_RESERVED | TASK_STATE_RAN_TO_COMPLETION | TASK_STATE_FAULTED | TASK_STATE_CANCELED))
- {
- AddException(exceptionObject); // handles singleton exception or exception collection
- Finish(false);
- returnValue = true;
- }
-
- return returnValue;
- }
-
- // internal helper function breaks out logic used by TaskCompletionSource and AsyncMethodBuilder
- // If the tokenToRecord is not None, it will be stored onto the task.
- // This method is only valid for promise tasks.
- internal bool TrySetCanceled(CancellationToken tokenToRecord)
- {
- return TrySetCanceled(tokenToRecord, null);
- }
-
- // internal helper function breaks out logic used by TaskCompletionSource and AsyncMethodBuilder
- // If the tokenToRecord is not None, it will be stored onto the task.
- // If the OperationCanceledException is not null, it will be stored into the task's exception holder.
- // This method is only valid for promise tasks.
- internal bool TrySetCanceled(CancellationToken tokenToRecord, object? cancellationException)
- {
- Debug.Assert(m_action == null, "Task<T>.TrySetCanceled(): non-null m_action");
- Debug.Assert(
- cancellationException == null ||
- cancellationException is OperationCanceledException ||
- (cancellationException as ExceptionDispatchInfo)?.SourceException is OperationCanceledException,
- "Expected null or an OperationCanceledException");
-
- bool returnValue = false;
-
- // "Reserve" the completion for this task, while making sure that: (1) No prior reservation
- // has been made, (2) The result has not already been set, (3) An exception has not previously
- // been recorded, and (4) Cancellation has not been requested.
- //
- // If the reservation is successful, then record the cancellation and finish completion processing.
- if (AtomicStateUpdate(
- TASK_STATE_COMPLETION_RESERVED,
- TASK_STATE_COMPLETION_RESERVED | TASK_STATE_CANCELED | TASK_STATE_FAULTED | TASK_STATE_RAN_TO_COMPLETION))
- {
- RecordInternalCancellationRequest(tokenToRecord, cancellationException);
- CancellationCleanupLogic(); // perform cancellation cleanup actions
- returnValue = true;
- }
-
- return returnValue;
- }
-
- //
- // Continuation passing functionality (aka ContinueWith)
- //
-
- /// <summary>
- /// Runs all of the continuations, as appropriate.
- /// </summary>
- internal void FinishContinuations()
- {
- // Atomically store the fact that this task is completing. From this point on, the adding of continuations will
- // result in the continuations being run/launched directly rather than being added to the continuation list.
- // Then if we grabbed any continuations, run them.
- object? continuationObject = Interlocked.Exchange(ref m_continuationObject, s_taskCompletionSentinel);
- if (continuationObject != null)
- {
- RunContinuations(continuationObject);
- }
- }
-
- private void RunContinuations(object continuationObject) // separated out of FinishContinuations to enable it to be inlined
- {
- Debug.Assert(continuationObject != null);
-
- TplEventSource? log = TplEventSource.Log;
- if (!log.IsEnabled())
- {
- log = null;
- }
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceSynchronousWorkStart(this, CausalitySynchronousWork.CompletionNotification);
-
- bool canInlineContinuations =
- (m_stateFlags & (int)TaskCreationOptions.RunContinuationsAsynchronously) == 0 &&
- RuntimeHelpers.TryEnsureSufficientExecutionStack();
-
- switch (continuationObject)
- {
- // Handle the single IAsyncStateMachineBox case. This could be handled as part of the ITaskCompletionAction
- // but we want to ensure that inlining is properly handled in the face of schedulers, so its behavior
- // needs to be customized ala raw Actions. This is also the most important case, as it represents the
- // most common form of continuation, so we check it first.
- case IAsyncStateMachineBox stateMachineBox:
- AwaitTaskContinuation.RunOrScheduleAction(stateMachineBox, canInlineContinuations);
- LogFinishCompletionNotification();
- return;
-
- // Handle the single Action case.
- case Action action:
- AwaitTaskContinuation.RunOrScheduleAction(action, canInlineContinuations);
- LogFinishCompletionNotification();
- return;
-
- // Handle the single TaskContinuation case.
- case TaskContinuation tc:
- tc.Run(this, canInlineContinuations);
- LogFinishCompletionNotification();
- return;
-
- // Handle the single ITaskCompletionAction case.
- case ITaskCompletionAction completionAction:
- RunOrQueueCompletionAction(completionAction, canInlineContinuations);
- LogFinishCompletionNotification();
- return;
- }
-
- // Not a single; it must be a list.
- List<object?> continuations = (List<object?>)continuationObject;
-
- //
- // Begin processing of continuation list
- //
-
- // Wait for any concurrent adds or removes to be retired
- lock (continuations) { }
- int continuationCount = continuations.Count;
-
- // Fire the asynchronous continuations first. However, if we're not able to run any continuations synchronously,
- // then we can skip this first pass, since the second pass that tries to run everything synchronously will instead
- // run everything asynchronously anyway.
- if (canInlineContinuations)
- {
- bool forceContinuationsAsync = false;
- for (int i = 0; i < continuationCount; i++)
- {
- // For StandardTaskContinuations, we respect the TaskContinuationOptions.ExecuteSynchronously option,
- // as the developer needs to explicitly opt-into running the continuation synchronously, and if they do,
- // they get what they asked for. ITaskCompletionActions are only ever created by the runtime, and we always
- // try to execute them synchronously. For all other continuations (related to await), we only run it synchronously
- // if it's the first such continuation; otherwise, we force it to run asynchronously so as to not artificially
- // delay an await continuation behind other arbitrary user code created as a previous await continuation.
-
- object? currentContinuation = continuations[i];
- if (currentContinuation == null)
- {
- // The continuation was unregistered and null'd out, so just skip it.
- continue;
- }
- else if (currentContinuation is StandardTaskContinuation stc)
- {
- if ((stc.m_options & TaskContinuationOptions.ExecuteSynchronously) == 0)
- {
- continuations[i] = null; // so that we can skip this later
- log?.RunningContinuationList(Id, i, stc);
- stc.Run(this, canInlineContinuationTask: false);
- }
- }
- else if (!(currentContinuation is ITaskCompletionAction))
- {
- if (forceContinuationsAsync)
- {
- continuations[i] = null;
- log?.RunningContinuationList(Id, i, currentContinuation);
- switch (currentContinuation)
- {
- case IAsyncStateMachineBox stateMachineBox:
- AwaitTaskContinuation.RunOrScheduleAction(stateMachineBox, allowInlining: false);
- break;
-
- case Action action:
- AwaitTaskContinuation.RunOrScheduleAction(action, allowInlining: false);
- break;
-
- default:
- Debug.Assert(currentContinuation is TaskContinuation);
- ((TaskContinuation)currentContinuation).Run(this, canInlineContinuationTask: false);
- break;
- }
- }
- forceContinuationsAsync = true;
- }
- }
- }
-
- // ... and then fire the synchronous continuations (if there are any).
- for (int i = 0; i < continuationCount; i++)
- {
- object? currentContinuation = continuations[i];
- if (currentContinuation == null)
- {
- continue;
- }
- continuations[i] = null; // to enable free'ing up memory earlier
- log?.RunningContinuationList(Id, i, currentContinuation);
-
- switch (currentContinuation)
- {
- case IAsyncStateMachineBox stateMachineBox:
- AwaitTaskContinuation.RunOrScheduleAction(stateMachineBox, canInlineContinuations);
- break;
-
- case Action action:
- AwaitTaskContinuation.RunOrScheduleAction(action, canInlineContinuations);
- break;
-
- case TaskContinuation tc:
- tc.Run(this, canInlineContinuations);
- break;
-
- default:
- Debug.Assert(currentContinuation is ITaskCompletionAction);
- RunOrQueueCompletionAction((ITaskCompletionAction)currentContinuation, canInlineContinuations);
- break;
- }
- }
-
- LogFinishCompletionNotification();
- }
-
- private void RunOrQueueCompletionAction(ITaskCompletionAction completionAction, bool allowInlining)
- {
- if (allowInlining || !completionAction.InvokeMayRunArbitraryCode)
- {
- completionAction.Invoke(this);
- }
- else
- {
- ThreadPool.UnsafeQueueUserWorkItemInternal(new CompletionActionInvoker(completionAction, this), preferLocal: true);
- }
- }
-
- private static void LogFinishCompletionNotification()
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceSynchronousWorkCompletion(CausalitySynchronousWork.CompletionNotification);
- }
-
- #region Continuation methods
-
- #region Action<Task> continuation
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- public Task ContinueWith(Action<Task> continuationAction)
- {
- return ContinueWith(continuationAction, TaskScheduler.Current, default, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="cancellationToken"> The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWith(Action<Task> continuationAction, CancellationToken cancellationToken)
- {
- return ContinueWith(continuationAction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- public Task ContinueWith(Action<Task> continuationAction, TaskScheduler scheduler)
- {
- return ContinueWith(continuationAction, scheduler, default, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed. If the continuation criteria specified through the <paramref
- /// name="continuationOptions"/> parameter are not met, the continuation task will be canceled
- /// instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- public Task ContinueWith(Action<Task> continuationAction, TaskContinuationOptions continuationOptions)
- {
- return ContinueWith(continuationAction, TaskScheduler.Current, default, continuationOptions);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its
- /// execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed. If the criteria specified through the <paramref name="continuationOptions"/> parameter
- /// are not met, the continuation task will be canceled instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWith(Action<Task> continuationAction, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- return ContinueWith(continuationAction, scheduler, cancellationToken, continuationOptions);
- }
-
- // Same as the above overload, just with a stack mark parameter.
- private Task ContinueWith(Action<Task> continuationAction, TaskScheduler scheduler,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions)
- {
- // Throw on continuation with null action
- if (continuationAction == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction);
- }
-
- // Throw on continuation with null TaskScheduler
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- TaskCreationOptions creationOptions;
- InternalTaskOptions internalOptions;
- CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions);
-
- Task continuationTask = new ContinuationTaskFromTask(
- this, continuationAction, null,
- creationOptions, internalOptions
- );
-
- // Register the continuation. If synchronous execution is requested, this may
- // actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
-
- return continuationTask;
- }
- #endregion
-
- #region Action<Task, Object> continuation
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task as and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation action.</param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- public Task ContinueWith(Action<Task, object?> continuationAction, object? state)
- {
- return ContinueWith(continuationAction, state, TaskScheduler.Current, default, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation action.</param>
- /// <param name="cancellationToken"> The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWith(Action<Task, object?> continuationAction, object? state, CancellationToken cancellationToken)
- {
- return ContinueWith(continuationAction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation action.</param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- public Task ContinueWith(Action<Task, object?> continuationAction, object? state, TaskScheduler scheduler)
- {
- return ContinueWith(continuationAction, state, scheduler, default, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation action.</param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed. If the continuation criteria specified through the <paramref
- /// name="continuationOptions"/> parameter are not met, the continuation task will be canceled
- /// instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- public Task ContinueWith(Action<Task, object?> continuationAction, object? state, TaskContinuationOptions continuationOptions)
- {
- return ContinueWith(continuationAction, state, TaskScheduler.Current, default, continuationOptions);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <param name="continuationAction">
- /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation action.</param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its
- /// execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
- /// completed. If the criteria specified through the <paramref name="continuationOptions"/> parameter
- /// are not met, the continuation task will be canceled instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationAction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWith(Action<Task, object?> continuationAction, object? state, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- return ContinueWith(continuationAction, state, scheduler, cancellationToken, continuationOptions);
- }
-
- // Same as the above overload, just with a stack mark parameter.
- private Task ContinueWith(Action<Task, object?> continuationAction, object? state, TaskScheduler scheduler,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions)
- {
- // Throw on continuation with null action
- if (continuationAction == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction);
- }
-
- // Throw on continuation with null TaskScheduler
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- TaskCreationOptions creationOptions;
- InternalTaskOptions internalOptions;
- CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions);
-
- Task continuationTask = new ContinuationTaskFromTask(
- this, continuationAction, state,
- creationOptions, internalOptions
- );
-
- // Register the continuation. If synchronous execution is requested, this may
- // actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
-
- return continuationTask;
- }
-
- #endregion
-
- #region Func<Task, TResult> continuation
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <typeparam name="TResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TResult}"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- public Task<TResult> ContinueWith<TResult>(Func<Task, TResult> continuationFunction)
- {
- return ContinueWith<TResult>(continuationFunction, TaskScheduler.Current, default,
- TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <typeparam name="TResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <returns>A new continuation <see cref="Task{TResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TResult}"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWith<TResult>(Func<Task, TResult> continuationFunction, CancellationToken cancellationToken)
- {
- return ContinueWith<TResult>(continuationFunction, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <typeparam name="TResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TResult}"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- public Task<TResult> ContinueWith<TResult>(Func<Task, TResult> continuationFunction, TaskScheduler scheduler)
- {
- return ContinueWith<TResult>(continuationFunction, scheduler, default, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <typeparam name="TResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TResult}"/> will not be scheduled for execution until the current task has
- /// completed. If the continuation criteria specified through the <paramref
- /// name="continuationOptions"/> parameter are not met, the continuation task will be canceled
- /// instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- public Task<TResult> ContinueWith<TResult>(Func<Task, TResult> continuationFunction, TaskContinuationOptions continuationOptions)
- {
- return ContinueWith<TResult>(continuationFunction, TaskScheduler.Current, default, continuationOptions);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <typeparam name="TResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task as an argument.
- /// </param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its
- /// execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TResult}"/> will not be scheduled for execution until the current task has
- /// completed. If the criteria specified through the <paramref name="continuationOptions"/> parameter
- /// are not met, the continuation task will be canceled instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWith<TResult>(Func<Task, TResult> continuationFunction, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- return ContinueWith<TResult>(continuationFunction, scheduler, cancellationToken, continuationOptions);
- }
-
- // Same as the above overload, just with a stack mark parameter.
- private Task<TResult> ContinueWith<TResult>(Func<Task, TResult> continuationFunction, TaskScheduler scheduler,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions)
- {
- // Throw on continuation with null function
- if (continuationFunction == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
- }
-
- // Throw on continuation with null task scheduler
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- TaskCreationOptions creationOptions;
- InternalTaskOptions internalOptions;
- CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions);
-
- Task<TResult> continuationTask = new ContinuationResultTaskFromTask<TResult>(
- this, continuationFunction, null,
- creationOptions, internalOptions
- );
-
- // Register the continuation. If synchronous execution is requested, this may
- // actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
-
- return continuationTask;
- }
- #endregion
-
- #region Func<Task, Object, TResult> continuation
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <typeparam name="TResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation function.</param>
- /// <returns>A new continuation <see cref="Task{TResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TResult}"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- public Task<TResult> ContinueWith<TResult>(Func<Task, object?, TResult> continuationFunction, object? state)
- {
- return ContinueWith<TResult>(continuationFunction, state, TaskScheduler.Current, default,
- TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <typeparam name="TResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation function.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <returns>A new continuation <see cref="Task{TResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TResult}"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWith<TResult>(Func<Task, object?, TResult> continuationFunction, object? state, CancellationToken cancellationToken)
- {
- return ContinueWith<TResult>(continuationFunction, state, TaskScheduler.Current, cancellationToken, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <typeparam name="TResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation function.</param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TResult}"/> will not be scheduled for execution until the current task has
- /// completed, whether it completes due to running to completion successfully, faulting due to an
- /// unhandled exception, or exiting out early due to being canceled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- public Task<TResult> ContinueWith<TResult>(Func<Task, object?, TResult> continuationFunction, object? state, TaskScheduler scheduler)
- {
- return ContinueWith<TResult>(continuationFunction, state, scheduler, default, TaskContinuationOptions.None);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <typeparam name="TResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation function.</param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TResult}"/> will not be scheduled for execution until the current task has
- /// completed. If the continuation criteria specified through the <paramref
- /// name="continuationOptions"/> parameter are not met, the continuation task will be canceled
- /// instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- public Task<TResult> ContinueWith<TResult>(Func<Task, object?, TResult> continuationFunction, object? state, TaskContinuationOptions continuationOptions)
- {
- return ContinueWith<TResult>(continuationFunction, state, TaskScheduler.Current, default, continuationOptions);
- }
-
- /// <summary>
- /// Creates a continuation that executes when the target <see cref="Task"/> completes.
- /// </summary>
- /// <typeparam name="TResult">
- /// The type of the result produced by the continuation.
- /// </typeparam>
- /// <param name="continuationFunction">
- /// A function to run when the <see cref="Task"/> completes. When run, the delegate will be
- /// passed the completed task and the caller-supplied state object as arguments.
- /// </param>
- /// <param name="state">An object representing data to be used by the continuation function.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">
- /// Options for when the continuation is scheduled and how it behaves. This includes criteria, such
- /// as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled">OnlyOnCanceled</see>, as
- /// well as execution options, such as <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously">ExecuteSynchronously</see>.
- /// </param>
- /// <param name="scheduler">
- /// The <see cref="TaskScheduler"/> to associate with the continuation task and to use for its
- /// execution.
- /// </param>
- /// <returns>A new continuation <see cref="Task{TResult}"/>.</returns>
- /// <remarks>
- /// The returned <see cref="Task{TResult}"/> will not be scheduled for execution until the current task has
- /// completed. If the criteria specified through the <paramref name="continuationOptions"/> parameter
- /// are not met, the continuation task will be canceled instead of scheduled.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="continuationFunction"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="continuationOptions"/> argument specifies an invalid value for <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="scheduler"/> argument is null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWith<TResult>(Func<Task, object?, TResult> continuationFunction, object? state, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- return ContinueWith<TResult>(continuationFunction, state, scheduler, cancellationToken, continuationOptions);
- }
-
- // Same as the above overload, just with a stack mark parameter.
- private Task<TResult> ContinueWith<TResult>(Func<Task, object?, TResult> continuationFunction, object? state, TaskScheduler scheduler,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions)
- {
- // Throw on continuation with null function
- if (continuationFunction == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction);
- }
-
- // Throw on continuation with null task scheduler
- if (scheduler == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
- }
-
- TaskCreationOptions creationOptions;
- InternalTaskOptions internalOptions;
- CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions);
-
- Task<TResult> continuationTask = new ContinuationResultTaskFromTask<TResult>(
- this, continuationFunction, state,
- creationOptions, internalOptions
- );
-
- // Register the continuation. If synchronous execution is requested, this may
- // actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
-
- return continuationTask;
- }
- #endregion
-
- /// <summary>
- /// Converts TaskContinuationOptions to TaskCreationOptions, and also does
- /// some validity checking along the way.
- /// </summary>
- /// <param name="continuationOptions">Incoming TaskContinuationOptions</param>
- /// <param name="creationOptions">Outgoing TaskCreationOptions</param>
- /// <param name="internalOptions">Outgoing InternalTaskOptions</param>
- internal static void CreationOptionsFromContinuationOptions(
- TaskContinuationOptions continuationOptions,
- out TaskCreationOptions creationOptions,
- out InternalTaskOptions internalOptions)
- {
- // This is used a couple of times below
- const TaskContinuationOptions NotOnAnything =
- TaskContinuationOptions.NotOnCanceled |
- TaskContinuationOptions.NotOnFaulted |
- TaskContinuationOptions.NotOnRanToCompletion;
-
- const TaskContinuationOptions CreationOptionsMask =
- TaskContinuationOptions.PreferFairness |
- TaskContinuationOptions.LongRunning |
- TaskContinuationOptions.DenyChildAttach |
- TaskContinuationOptions.HideScheduler |
- TaskContinuationOptions.AttachedToParent |
- TaskContinuationOptions.RunContinuationsAsynchronously;
-
- // Check that LongRunning and ExecuteSynchronously are not specified together
- const TaskContinuationOptions IllegalMask = TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.LongRunning;
- if ((continuationOptions & IllegalMask) == IllegalMask)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.continuationOptions, ExceptionResource.Task_ContinueWith_ESandLR);
- }
-
- // Check that no illegal options were specified
- if ((continuationOptions &
- ~(CreationOptionsMask | NotOnAnything |
- TaskContinuationOptions.LazyCancellation | TaskContinuationOptions.ExecuteSynchronously)) != 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.continuationOptions);
- }
-
- // Check that we didn't specify "not on anything"
- if ((continuationOptions & NotOnAnything) == NotOnAnything)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.continuationOptions, ExceptionResource.Task_ContinueWith_NotOnAnything);
- }
-
- // This passes over all but LazyCancellation, which has no representation in TaskCreationOptions
- creationOptions = (TaskCreationOptions)(continuationOptions & CreationOptionsMask);
-
- // internalOptions has at least ContinuationTask and possibly LazyCancellation
- internalOptions = (continuationOptions & TaskContinuationOptions.LazyCancellation) != 0 ?
- InternalTaskOptions.ContinuationTask | InternalTaskOptions.LazyCancellation :
- InternalTaskOptions.ContinuationTask;
- }
-
- /// <summary>
- /// Registers the continuation and possibly runs it (if the task is already finished).
- /// </summary>
- /// <param name="continuationTask">The continuation task itself.</param>
- /// <param name="scheduler">TaskScheduler with which to associate continuation task.</param>
- /// <param name="options">Restrictions on when the continuation becomes active.</param>
- internal void ContinueWithCore(Task continuationTask,
- TaskScheduler scheduler,
- CancellationToken cancellationToken,
- TaskContinuationOptions options)
- {
- Debug.Assert(continuationTask != null, "Task.ContinueWithCore(): null continuationTask");
- Debug.Assert(scheduler != null, "Task.ContinueWithCore(): null scheduler");
- Debug.Assert(!continuationTask.IsCompleted, "Did not expect continuationTask to be completed");
-
- // Create a TaskContinuation
- TaskContinuation continuation = new StandardTaskContinuation(continuationTask, options, scheduler);
-
- // If cancellationToken is cancellable, then assign it.
- if (cancellationToken.CanBeCanceled)
- {
- if (IsCompleted || cancellationToken.IsCancellationRequested)
- {
- // If the antecedent has completed, then we will not be queuing up
- // the continuation in the antecedent's continuation list. Likewise,
- // if the cancellationToken has been canceled, continuationTask will
- // be completed in the AssignCancellationToken call below, and there
- // is no need to queue the continuation to the antecedent's continuation
- // list. In either of these two cases, we will pass "null" for the antecedent,
- // meaning "the cancellation callback should not attempt to remove the
- // continuation from its antecedent's continuation list".
- continuationTask.AssignCancellationToken(cancellationToken, null, null);
- }
- else
- {
- // The antecedent is not yet complete, so there is a pretty good chance
- // that the continuation will be queued up in the antecedent. Assign the
- // cancellation token with information about the antecedent, so that the
- // continuation can be dequeued upon the signalling of the token.
- //
- // It's possible that the antecedent completes before the call to AddTaskContinuation,
- // and that is a benign race condition. It just means that the cancellation will result in
- // a futile search of the antecedent's continuation list.
- continuationTask.AssignCancellationToken(cancellationToken, this, continuation);
- }
- }
-
- // In the case of a pre-canceled token, continuationTask will have been completed
- // in a Canceled state by now. If such is the case, there is no need to go through
- // the motions of queuing up the continuation for eventual execution.
- if (!continuationTask.IsCompleted)
- {
- // We need additional correlation produced here to ensure that at least the continuation
- // code will be correlatable to the currrent activity that initiated "this" task:
- // . when the antecendent ("this") is a promise we have very little control over where
- // the code for the promise will run (e.g. it can be a task from a user provided
- // TaskCompletionSource or from a classic Begin/End async operation); this user or
- // system code will likely not have stamped an activity id on the thread, so there's
- // generally no easy correlation that can be provided between the current activity
- // and the promise. Also the continuation code may run practically on any thread.
- // Since there may be no correlation between the current activity and the TCS's task
- // activity, we ensure we at least create a correlation from the current activity to
- // the continuation that runs when the promise completes.
- if ((this.Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0 &&
- !(this is ITaskCompletionAction))
- {
- TplEventSource log = TplEventSource.Log;
- if (log.IsEnabled())
- {
- log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id, Task.CurrentId ?? 0, continuationTask.Id);
- }
- }
-
- // Attempt to enqueue the continuation
- bool continuationQueued = AddTaskContinuation(continuation, addBeforeOthers: false);
-
- // If the continuation was not queued (because the task completed), then run it now.
- if (!continuationQueued) continuation.Run(this, canInlineContinuationTask: true);
- }
- }
- #endregion
-
- // Adds a lightweight completion action to a task. This is similar to a continuation
- // task except that it is stored as an action, and thus does not require the allocation/
- // execution resources of a continuation task.
- //
- // Used internally by ContinueWhenAll() and ContinueWhenAny().
- internal void AddCompletionAction(ITaskCompletionAction action)
- {
- AddCompletionAction(action, addBeforeOthers: false);
- }
-
- internal void AddCompletionAction(ITaskCompletionAction action, bool addBeforeOthers)
- {
- if (!AddTaskContinuation(action, addBeforeOthers))
- action.Invoke(this); // run the action directly if we failed to queue the continuation (i.e., the task completed)
- }
-
- // Support method for AddTaskContinuation that takes care of multi-continuation logic.
- // Returns true if and only if the continuation was successfully queued.
- // THIS METHOD ASSUMES THAT m_continuationObject IS NOT NULL. That case was taken
- // care of in the calling method, AddTaskContinuation().
- private bool AddTaskContinuationComplex(object tc, bool addBeforeOthers)
- {
- Debug.Assert(tc != null, "Expected non-null tc object in AddTaskContinuationComplex");
-
- object? oldValue = m_continuationObject;
-
- // Logic for the case where we were previously storing a single continuation
- if ((oldValue != s_taskCompletionSentinel) && (!(oldValue is List<object?>)))
- {
- // Construct a new TaskContinuation list and CAS it in.
- Interlocked.CompareExchange(ref m_continuationObject, new List<object?> { oldValue }, oldValue);
-
- // We might be racing against another thread converting the single into
- // a list, or we might be racing against task completion, so resample "list"
- // below.
- }
-
- // m_continuationObject is guaranteed at this point to be either a List or
- // s_taskCompletionSentinel.
- List<object?>? list = m_continuationObject as List<object?>;
- Debug.Assert((list != null) || (m_continuationObject == s_taskCompletionSentinel),
- "Expected m_continuationObject to be list or sentinel");
-
- // If list is null, it can only mean that s_taskCompletionSentinel has been exchanged
- // into m_continuationObject. Thus, the task has completed and we should return false
- // from this method, as we will not be queuing up the continuation.
- if (list != null)
- {
- lock (list)
- {
- // It is possible for the task to complete right after we snap the copy of
- // the list. If so, then fall through and return false without queuing the
- // continuation.
- if (m_continuationObject != s_taskCompletionSentinel)
- {
- // Before growing the list we remove possible null entries that are the
- // result from RemoveContinuations()
- if (list.Count == list.Capacity)
- {
- list.RemoveAll(l => l == null);
- }
-
- if (addBeforeOthers)
- list.Insert(0, tc);
- else
- list.Add(tc);
-
- return true; // continuation successfully queued, so return true.
- }
- }
- }
-
- // We didn't succeed in queuing the continuation, so return false.
- return false;
- }
-
- // Record a continuation task or action.
- // Return true if and only if we successfully queued a continuation.
- private bool AddTaskContinuation(object tc, bool addBeforeOthers)
- {
- Debug.Assert(tc != null);
-
- // Make sure that, if someone calls ContinueWith() right after waiting for the predecessor to complete,
- // we don't queue up a continuation.
- if (IsCompleted) return false;
-
- // Try to just jam tc into m_continuationObject
- if ((m_continuationObject != null) || (Interlocked.CompareExchange(ref m_continuationObject, tc, null) != null))
- {
- // If we get here, it means that we failed to CAS tc into m_continuationObject.
- // Therefore, we must go the more complicated route.
- return AddTaskContinuationComplex(tc, addBeforeOthers);
- }
- else return true;
- }
-
- // Removes a continuation task from m_continuations
- internal void RemoveContinuation(object continuationObject) // could be TaskContinuation or Action<Task>
- {
- // We need to snap a local reference to m_continuations since reading a volatile object is more costly.
- // Also to prevent the value to be changed as result of a race condition with another method.
- object? continuationsLocalRef = m_continuationObject;
-
- // Task is completed. Nothing to do here.
- if (continuationsLocalRef == s_taskCompletionSentinel) return;
-
- List<object?>? continuationsLocalListRef = continuationsLocalRef as List<object?>;
- if (continuationsLocalListRef is null)
- {
- // This is not a list. If we have a single object (the one we want to remove) we try to replace it with an empty list.
- // Note we cannot go back to a null state, since it will mess up the AddTaskContinuation logic.
- if (Interlocked.CompareExchange(ref m_continuationObject, new List<object?>(), continuationObject) != continuationObject)
- {
- // If we fail it means that either AddContinuationComplex won the race condition and m_continuationObject is now a List
- // that contains the element we want to remove. Or FinishContinuations set the s_taskCompletionSentinel.
- // So we should try to get a list one more time
- continuationsLocalListRef = m_continuationObject as List<object?>;
- }
- else
- {
- // Exchange was successful so we can skip the last comparison
- return;
- }
- }
-
- // if continuationsLocalRef == null it means s_taskCompletionSentinel has been set already and there is nothing else to do.
- if (continuationsLocalListRef != null)
- {
- lock (continuationsLocalListRef)
- {
- // There is a small chance that this task completed since we took a local snapshot into
- // continuationsLocalRef. In that case, just return; we don't want to be manipulating the
- // continuation list as it is being processed.
- if (m_continuationObject == s_taskCompletionSentinel) return;
-
- // Find continuationObject in the continuation list
- int index = continuationsLocalListRef.IndexOf(continuationObject);
-
- if (index != -1)
- {
- // null out that TaskContinuation entry, which will be interpreted as "to be cleaned up"
- continuationsLocalListRef[index] = null;
- }
- }
- }
- }
-
- //
- // Wait methods
- //
-
- /// <summary>
- /// Waits for all of the provided <see cref="Task"/> objects to complete execution.
- /// </summary>
- /// <param name="tasks">
- /// An array of <see cref="Task"/> instances on which to wait.
- /// </param>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument contains a null element.
- /// </exception>
- /// <exception cref="System.AggregateException">
- /// At least one of the <see cref="Task"/> instances was canceled -or- an exception was thrown during
- /// the execution of at least one of the <see cref="Task"/> instances.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger
- public static void WaitAll(params Task[] tasks)
- {
-#if DEBUG
- bool waitResult =
-#endif
- WaitAllCore(tasks, Timeout.Infinite, default);
-
-#if DEBUG
- Debug.Assert(waitResult, "expected wait to succeed");
-#endif
- }
-
- /// <summary>
- /// Waits for all of the provided <see cref="Task"/> objects to complete execution.
- /// </summary>
- /// <returns>
- /// true if all of the <see cref="Task"/> instances completed execution within the allotted time;
- /// otherwise, false.
- /// </returns>
- /// <param name="tasks">
- /// An array of <see cref="Task"/> instances on which to wait.
- /// </param>
- /// <param name="timeout">
- /// A <see cref="System.TimeSpan"/> that represents the number of milliseconds to wait, or a <see
- /// cref="System.TimeSpan"/> that represents -1 milliseconds to wait indefinitely.
- /// </param>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> argument contains a null element.
- /// </exception>
- /// <exception cref="System.AggregateException">
- /// At least one of the <see cref="Task"/> instances was canceled -or- an exception was thrown during
- /// the execution of at least one of the <see cref="Task"/> instances.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// <paramref name="timeout"/> is a negative number other than -1 milliseconds, which represents an
- /// infinite time-out -or- timeout is greater than
- /// <see cref="int.MaxValue"/>.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger
- public static bool WaitAll(Task[] tasks, TimeSpan timeout)
- {
- long totalMilliseconds = (long)timeout.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.timeout);
- }
-
- return WaitAllCore(tasks, (int)totalMilliseconds, default);
- }
-
- /// <summary>
- /// Waits for all of the provided <see cref="Task"/> objects to complete execution.
- /// </summary>
- /// <returns>
- /// true if all of the <see cref="Task"/> instances completed execution within the allotted time;
- /// otherwise, false.
- /// </returns>
- /// <param name="millisecondsTimeout">
- /// The number of milliseconds to wait, or <see cref="System.Threading.Timeout.Infinite"/> (-1) to
- /// wait indefinitely.</param>
- /// <param name="tasks">An array of <see cref="Task"/> instances on which to wait.
- /// </param>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> argument contains a null element.
- /// </exception>
- /// <exception cref="System.AggregateException">
- /// At least one of the <see cref="Task"/> instances was canceled -or- an exception was thrown during
- /// the execution of at least one of the <see cref="Task"/> instances.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// <paramref name="millisecondsTimeout"/> is a negative number other than -1, which represents an
- /// infinite time-out.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger
- public static bool WaitAll(Task[] tasks, int millisecondsTimeout)
- {
- return WaitAllCore(tasks, millisecondsTimeout, default);
- }
-
- /// <summary>
- /// Waits for all of the provided <see cref="Task"/> objects to complete execution.
- /// </summary>
- /// <param name="tasks">
- /// An array of <see cref="Task"/> instances on which to wait.
- /// </param>
- /// <param name="cancellationToken">
- /// A <see cref="CancellationToken"/> to observe while waiting for the tasks to complete.
- /// </param>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> argument contains a null element.
- /// </exception>
- /// <exception cref="System.AggregateException">
- /// At least one of the <see cref="Task"/> instances was canceled -or- an exception was thrown during
- /// the execution of at least one of the <see cref="Task"/> instances.
- /// </exception>
- /// <exception cref="System.OperationCanceledException">
- /// The <paramref name="cancellationToken"/> was canceled.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger
- public static void WaitAll(Task[] tasks, CancellationToken cancellationToken)
- {
- WaitAllCore(tasks, Timeout.Infinite, cancellationToken);
- }
-
- /// <summary>
- /// Waits for all of the provided <see cref="Task"/> objects to complete execution.
- /// </summary>
- /// <returns>
- /// true if all of the <see cref="Task"/> instances completed execution within the allotted time;
- /// otherwise, false.
- /// </returns>
- /// <param name="tasks">
- /// An array of <see cref="Task"/> instances on which to wait.
- /// </param>
- /// <param name="millisecondsTimeout">
- /// The number of milliseconds to wait, or <see cref="System.Threading.Timeout.Infinite"/> (-1) to
- /// wait indefinitely.
- /// </param>
- /// <param name="cancellationToken">
- /// A <see cref="CancellationToken"/> to observe while waiting for the tasks to complete.
- /// </param>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> argument contains a null element.
- /// </exception>
- /// <exception cref="System.AggregateException">
- /// At least one of the <see cref="Task"/> instances was canceled -or- an exception was thrown during
- /// the execution of at least one of the <see cref="Task"/> instances.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// <paramref name="millisecondsTimeout"/> is a negative number other than -1, which represents an
- /// infinite time-out.
- /// </exception>
- /// <exception cref="System.OperationCanceledException">
- /// The <paramref name="cancellationToken"/> was canceled.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger
- public static bool WaitAll(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken) =>
- WaitAllCore(tasks, millisecondsTimeout, cancellationToken);
-
- // Separated out to allow it to be optimized (caller is marked NoOptimization for VS parallel debugger
- // to be able to see the method on the stack and inspect arguments).
- private static bool WaitAllCore(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken)
- {
- if (tasks == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- }
- if (millisecondsTimeout < -1)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsTimeout);
- }
-
- cancellationToken.ThrowIfCancellationRequested(); // early check before we make any allocations
-
- //
- // In this WaitAll() implementation we have 2 alternate code paths for a task to be handled:
- // CODEPATH1: skip an already completed task, CODEPATH2: actually wait on tasks
- // We make sure that the exception behavior of Task.Wait() is replicated the same for tasks handled in either of these codepaths
- //
-
- List<Exception>? exceptions = null;
- List<Task>? waitedOnTaskList = null;
- List<Task>? notificationTasks = null;
-
- // If any of the waited-upon tasks end as Faulted or Canceled, set these to true.
- bool exceptionSeen = false, cancellationSeen = false;
-
- bool returnValue = true;
-
- // Collects incomplete tasks in "waitedOnTaskList"
- for (int i = tasks.Length - 1; i >= 0; i--)
- {
- Task task = tasks[i];
-
- if (task == null)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Task_WaitMulti_NullTask, ExceptionArgument.tasks);
- }
-
- bool taskIsCompleted = task.IsCompleted;
- if (!taskIsCompleted)
- {
- // try inlining the task only if we have an infinite timeout and an empty cancellation token
- if (millisecondsTimeout != Timeout.Infinite || cancellationToken.CanBeCanceled)
- {
- // We either didn't attempt inline execution because we had a non-infinite timeout or we had a cancellable token.
- // In all cases we need to do a full wait on the task (=> add its event into the list.)
- AddToList(task, ref waitedOnTaskList, initSize: tasks.Length);
- }
- else
- {
- // We are eligible for inlining. If it doesn't work, we'll do a full wait.
- taskIsCompleted = task.WrappedTryRunInline() && task.IsCompleted; // A successful TryRunInline doesn't guarantee completion
- if (!taskIsCompleted) AddToList(task, ref waitedOnTaskList, initSize: tasks.Length);
- }
- }
-
- if (taskIsCompleted)
- {
- if (task.IsFaulted) exceptionSeen = true;
- else if (task.IsCanceled) cancellationSeen = true;
- if (task.IsWaitNotificationEnabled) AddToList(task, ref notificationTasks, initSize: 1);
- }
- }
-
- if (waitedOnTaskList != null)
- {
- // Block waiting for the tasks to complete.
- returnValue = WaitAllBlockingCore(waitedOnTaskList, millisecondsTimeout, cancellationToken);
-
- // If the wait didn't time out, ensure exceptions are propagated, and if a debugger is
- // attached and one of these tasks requires it, that we notify the debugger of a wait completion.
- if (returnValue)
- {
- // Add any exceptions for this task to the collection, and if it's wait
- // notification bit is set, store it to operate on at the end.
- foreach (Task task in waitedOnTaskList)
- {
- if (task.IsFaulted) exceptionSeen = true;
- else if (task.IsCanceled) cancellationSeen = true;
- if (task.IsWaitNotificationEnabled) AddToList(task, ref notificationTasks, initSize: 1);
- }
- }
-
- // We need to prevent the tasks array from being GC'ed until we come out of the wait.
- // This is necessary so that the Parallel Debugger can traverse it during the long wait and
- // deduce waiter/waitee relationships
- GC.KeepAlive(tasks);
- }
-
- // Now that we're done and about to exit, if the wait completed and if we have
- // any tasks with a notification bit set, signal the debugger if any requires it.
- if (returnValue && notificationTasks != null)
- {
- // Loop through each task tha that had its bit set, and notify the debugger
- // about the first one that requires it. The debugger will reset the bit
- // for any tasks we don't notify of as soon as we break, so we only need to notify
- // for one.
- foreach (Task task in notificationTasks)
- {
- if (task.NotifyDebuggerOfWaitCompletionIfNecessary()) break;
- }
- }
-
- // If one or more threw exceptions, aggregate and throw them.
- if (returnValue && (exceptionSeen || cancellationSeen))
- {
- // If the WaitAll was canceled and tasks were canceled but not faulted,
- // prioritize throwing an OCE for canceling the WaitAll over throwing an
- // AggregateException for all of the canceled Tasks. This helps
- // to bring determinism to an otherwise non-determistic case of using
- // the same token to cancel both the WaitAll and the Tasks.
- if (!exceptionSeen) cancellationToken.ThrowIfCancellationRequested();
-
- // Now gather up and throw all of the exceptions.
- foreach (Task task in tasks) AddExceptionsForCompletedTask(ref exceptions, task);
- Debug.Assert(exceptions != null, "Should have seen at least one exception");
- ThrowHelper.ThrowAggregateException(exceptions);
- }
-
- return returnValue;
- }
-
- /// <summary>Adds an element to the list, initializing the list if it's null.</summary>
- /// <typeparam name="T">Specifies the type of data stored in the list.</typeparam>
- /// <param name="item">The item to add.</param>
- /// <param name="list">The list.</param>
- /// <param name="initSize">The size to which to initialize the list if the list is null.</param>
- private static void AddToList<T>(T item, ref List<T>? list, int initSize)
- {
- list ??= new List<T>(initSize);
- list.Add(item);
- }
-
- /// <summary>Performs a blocking WaitAll on the vetted list of tasks.</summary>
- /// <param name="tasks">The tasks, which have already been checked and filtered for completion.</param>
- /// <param name="millisecondsTimeout">The timeout.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>true if all of the tasks completed; otherwise, false.</returns>
- private static bool WaitAllBlockingCore(List<Task> tasks, int millisecondsTimeout, CancellationToken cancellationToken)
- {
- Debug.Assert(tasks != null, "Expected a non-null list of tasks");
- Debug.Assert(tasks.Count > 0, "Expected at least one task");
-
- bool waitCompleted = false;
- var mres = new SetOnCountdownMres(tasks.Count);
- try
- {
- foreach (Task task in tasks)
- {
- task.AddCompletionAction(mres, addBeforeOthers: true);
- }
- waitCompleted = mres.Wait(millisecondsTimeout, cancellationToken);
- }
- finally
- {
- if (!waitCompleted)
- {
- foreach (Task task in tasks)
- {
- if (!task.IsCompleted) task.RemoveContinuation(mres);
- }
- }
- // It's ok that we don't dispose of the MRES here, as we never
- // access the MRES' WaitHandle, and thus no finalizable resources
- // are actually created. We don't always just Dispose it because
- // a continuation that's accessing the MRES could still be executing.
- }
- return waitCompleted;
- }
-
- // A ManualResetEventSlim that will get Set after Invoke is called count times.
- // This allows us to replace this logic:
- // var mres = new ManualResetEventSlim(tasks.Count);
- // Action<Task> completionAction = delegate { if (Interlocked.Decrement(ref count) == 0) mres.Set(); };
- // foreach (var task in tasks) task.AddCompletionAction(completionAction);
- // with this logic:
- // var mres = new SetOnCountdownMres(tasks.Count);
- // foreach (var task in tasks) task.AddCompletionAction(mres);
- // which saves a couple of allocations.
- //
- // Used in WaitAllBlockingCore (above).
- private sealed class SetOnCountdownMres : ManualResetEventSlim, ITaskCompletionAction
- {
- private int _count;
-
- internal SetOnCountdownMres(int count)
- {
- Debug.Assert(count > 0, "Expected count > 0");
- _count = count;
- }
-
- public void Invoke(Task completingTask)
- {
- if (Interlocked.Decrement(ref _count) == 0) Set();
- Debug.Assert(_count >= 0, "Count should never go below 0");
- }
-
- public bool InvokeMayRunArbitraryCode => false;
- }
-
- /// <summary>
- /// This internal function is only meant to be called by WaitAll()
- /// If the completed task is canceled or it has other exceptions, here we will add those
- /// into the passed in exception list (which will be lazily initialized here).
- /// </summary>
- internal static void AddExceptionsForCompletedTask(ref List<Exception>? exceptions, Task t)
- {
- AggregateException? ex = t.GetExceptions(true);
- if (ex != null)
- {
- // make sure the task's exception observed status is set appropriately
- // it's possible that WaitAll was called by the parent of an attached child,
- // this will make sure it won't throw again in the implicit wait
- t.UpdateExceptionObservedStatus();
-
- exceptions ??= new List<Exception>(ex.InnerExceptions.Count);
- exceptions.AddRange(ex.InnerExceptions);
- }
- }
-
- /// <summary>
- /// Waits for any of the provided <see cref="Task"/> objects to complete execution.
- /// </summary>
- /// <param name="tasks">
- /// An array of <see cref="Task"/> instances on which to wait.
- /// </param>
- /// <returns>The index of the completed task in the <paramref name="tasks"/> array argument.</returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> argument contains a null element.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger
- public static int WaitAny(params Task[] tasks)
- {
- int waitResult = WaitAnyCore(tasks, Timeout.Infinite, default);
- Debug.Assert(tasks.Length == 0 || waitResult != -1, "expected wait to succeed");
- return waitResult;
- }
-
- /// <summary>
- /// Waits for any of the provided <see cref="Task"/> objects to complete execution.
- /// </summary>
- /// <param name="tasks">
- /// An array of <see cref="Task"/> instances on which to wait.
- /// </param>
- /// <param name="timeout">
- /// A <see cref="System.TimeSpan"/> that represents the number of milliseconds to wait, or a <see
- /// cref="System.TimeSpan"/> that represents -1 milliseconds to wait indefinitely.
- /// </param>
- /// <returns>
- /// The index of the completed task in the <paramref name="tasks"/> array argument, or -1 if the
- /// timeout occurred.
- /// </returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> argument contains a null element.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// <paramref name="timeout"/> is a negative number other than -1 milliseconds, which represents an
- /// infinite time-out -or- timeout is greater than
- /// <see cref="int.MaxValue"/>.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger
- public static int WaitAny(Task[] tasks, TimeSpan timeout)
- {
- long totalMilliseconds = (long)timeout.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.timeout);
- }
-
- return WaitAnyCore(tasks, (int)totalMilliseconds, default);
- }
-
- /// <summary>
- /// Waits for any of the provided <see cref="Task"/> objects to complete execution.
- /// </summary>
- /// <param name="tasks">
- /// An array of <see cref="Task"/> instances on which to wait.
- /// </param>
- /// <param name="cancellationToken">
- /// A <see cref="CancellationToken"/> to observe while waiting for a task to complete.
- /// </param>
- /// <returns>
- /// The index of the completed task in the <paramref name="tasks"/> array argument.
- /// </returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> argument contains a null element.
- /// </exception>
- /// <exception cref="System.OperationCanceledException">
- /// The <paramref name="cancellationToken"/> was canceled.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger
- public static int WaitAny(Task[] tasks, CancellationToken cancellationToken)
- {
- return WaitAnyCore(tasks, Timeout.Infinite, cancellationToken);
- }
-
- /// <summary>
- /// Waits for any of the provided <see cref="Task"/> objects to complete execution.
- /// </summary>
- /// <param name="tasks">
- /// An array of <see cref="Task"/> instances on which to wait.
- /// </param>
- /// <param name="millisecondsTimeout">
- /// The number of milliseconds to wait, or <see cref="System.Threading.Timeout.Infinite"/> (-1) to
- /// wait indefinitely.
- /// </param>
- /// <returns>
- /// The index of the completed task in the <paramref name="tasks"/> array argument, or -1 if the
- /// timeout occurred.
- /// </returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> argument contains a null element.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// <paramref name="millisecondsTimeout"/> is a negative number other than -1, which represents an
- /// infinite time-out.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger
- public static int WaitAny(Task[] tasks, int millisecondsTimeout)
- {
- return WaitAnyCore(tasks, millisecondsTimeout, default);
- }
-
- /// <summary>
- /// Waits for any of the provided <see cref="Task"/> objects to complete execution.
- /// </summary>
- /// <param name="tasks">
- /// An array of <see cref="Task"/> instances on which to wait.
- /// </param>
- /// <param name="millisecondsTimeout">
- /// The number of milliseconds to wait, or <see cref="System.Threading.Timeout.Infinite"/> (-1) to
- /// wait indefinitely.
- /// </param>
- /// <param name="cancellationToken">
- /// A <see cref="CancellationToken"/> to observe while waiting for a task to complete.
- /// </param>
- /// <returns>
- /// The index of the completed task in the <paramref name="tasks"/> array argument, or -1 if the
- /// timeout occurred.
- /// </returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument is null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> argument contains a null element.
- /// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// <paramref name="millisecondsTimeout"/> is a negative number other than -1, which represents an
- /// infinite time-out.
- /// </exception>
- /// <exception cref="System.OperationCanceledException">
- /// The <paramref name="cancellationToken"/> was canceled.
- /// </exception>
- [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger
- public static int WaitAny(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken) =>
- WaitAnyCore(tasks, millisecondsTimeout, cancellationToken);
-
- // Separated out to allow it to be optimized (caller is marked NoOptimization for VS parallel debugger
- // to be able to inspect arguments).
- private static int WaitAnyCore(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken)
- {
- if (tasks == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- }
- if (millisecondsTimeout < -1)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsTimeout);
- }
-
- cancellationToken.ThrowIfCancellationRequested(); // early check before we make any allocations
-
- int signaledTaskIndex = -1;
-
- // Make a pass through the loop to check for any tasks that may have
- // already been completed, and to verify that no tasks are null.
-
- for (int taskIndex = 0; taskIndex < tasks.Length; taskIndex++)
- {
- Task task = tasks[taskIndex];
-
- if (task == null)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Task_WaitMulti_NullTask, ExceptionArgument.tasks);
- }
-
- if (signaledTaskIndex == -1 && task.IsCompleted)
- {
- // We found our first completed task. Store it, but we can't just return here,
- // as we still need to validate the whole array for nulls.
- signaledTaskIndex = taskIndex;
- }
- }
-
- if (signaledTaskIndex == -1 && tasks.Length != 0)
- {
- Task<Task> firstCompleted = TaskFactory.CommonCWAnyLogic(tasks, isSyncBlocking: true);
- bool waitCompleted = firstCompleted.Wait(millisecondsTimeout, cancellationToken);
- if (waitCompleted)
- {
- Debug.Assert(firstCompleted.Status == TaskStatus.RanToCompletion);
- signaledTaskIndex = Array.IndexOf(tasks, firstCompleted.Result);
- Debug.Assert(signaledTaskIndex >= 0);
- }
- else
- {
- TaskFactory.CommonCWAnyLogicCleanup(firstCompleted);
- }
- }
-
- // We need to prevent the tasks array from being GC'ed until we come out of the wait.
- // This is necessary so that the Parallel Debugger can traverse it during the long wait
- // and deduce waiter/waitee relationships
- GC.KeepAlive(tasks);
-
- // Return the index
- return signaledTaskIndex;
- }
-
- #region FromResult / FromException / FromCanceled
-
- /// <summary>Creates a <see cref="Task{TResult}"/> that's completed successfully with the specified result.</summary>
- /// <typeparam name="TResult">The type of the result returned by the task.</typeparam>
- /// <param name="result">The result to store into the completed task.</param>
- /// <returns>The successfully completed task.</returns>
- public static Task<TResult> FromResult<TResult>(TResult result)
- {
- return new Task<TResult>(result);
- }
-
- /// <summary>Creates a <see cref="Task{TResult}"/> that's completed exceptionally with the specified exception.</summary>
- /// <param name="exception">The exception with which to complete the task.</param>
- /// <returns>The faulted task.</returns>
- public static Task FromException(Exception exception)
- {
- if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
-
- var task = new Task();
- bool succeeded = task.TrySetException(exception);
- Debug.Assert(succeeded, "This should always succeed on a new task.");
- return task;
- }
-
- /// <summary>Creates a <see cref="Task{TResult}"/> that's completed exceptionally with the specified exception.</summary>
- /// <typeparam name="TResult">The type of the result returned by the task.</typeparam>
- /// <param name="exception">The exception with which to complete the task.</param>
- /// <returns>The faulted task.</returns>
- public static Task<TResult> FromException<TResult>(Exception exception)
- {
- if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
-
- var task = new Task<TResult>();
- bool succeeded = task.TrySetException(exception);
- Debug.Assert(succeeded, "This should always succeed on a new task.");
- return task;
- }
-
- /// <summary>Creates a <see cref="Task"/> that's completed due to cancellation with the specified token.</summary>
- /// <param name="cancellationToken">The token with which to complete the task.</param>
- /// <returns>The canceled task.</returns>
- public static Task FromCanceled(CancellationToken cancellationToken)
- {
- if (!cancellationToken.IsCancellationRequested)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.cancellationToken);
- return new Task(true, TaskCreationOptions.None, cancellationToken);
- }
-
- /// <summary>Creates a <see cref="Task{TResult}"/> that's completed due to cancellation with the specified token.</summary>
- /// <typeparam name="TResult">The type of the result returned by the task.</typeparam>
- /// <param name="cancellationToken">The token with which to complete the task.</param>
- /// <returns>The canceled task.</returns>
- public static Task<TResult> FromCanceled<TResult>(CancellationToken cancellationToken)
- {
- if (!cancellationToken.IsCancellationRequested)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.cancellationToken);
- return new Task<TResult>(true, default, TaskCreationOptions.None, cancellationToken);
- }
-
- /// <summary>Creates a <see cref="Task"/> that's completed due to cancellation with the specified exception.</summary>
- /// <param name="exception">The exception with which to complete the task.</param>
- /// <returns>The canceled task.</returns>
- internal static Task FromCanceled(OperationCanceledException exception)
- {
- Debug.Assert(exception != null);
-
- var task = new Task();
- bool succeeded = task.TrySetCanceled(exception.CancellationToken, exception);
- Debug.Assert(succeeded, "This should always succeed on a new task.");
- return task;
- }
-
- /// <summary>Creates a <see cref="Task{TResult}"/> that's completed due to cancellation with the specified exception.</summary>
- /// <typeparam name="TResult">The type of the result returned by the task.</typeparam>
- /// <param name="exception">The exception with which to complete the task.</param>
- /// <returns>The canceled task.</returns>
- internal static Task<TResult> FromCanceled<TResult>(OperationCanceledException exception)
- {
- Debug.Assert(exception != null);
-
- var task = new Task<TResult>();
- bool succeeded = task.TrySetCanceled(exception.CancellationToken, exception);
- Debug.Assert(succeeded, "This should always succeed on a new task.");
- return task;
- }
-
- #endregion
-
- #region Run methods
-
- /// <summary>
- /// Queues the specified work to run on the ThreadPool and returns a Task handle for that work.
- /// </summary>
- /// <param name="action">The work to execute asynchronously</param>
- /// <returns>A Task that represents the work queued to execute in the ThreadPool.</returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="action"/> parameter was null.
- /// </exception>
- public static Task Run(Action action)
- {
- return Task.InternalStartNew(null, action, null, default, TaskScheduler.Default,
- TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None);
- }
-
- /// <summary>
- /// Queues the specified work to run on the ThreadPool and returns a Task handle for that work.
- /// </summary>
- /// <param name="action">The work to execute asynchronously</param>
- /// <param name="cancellationToken">A cancellation token that should be used to cancel the work</param>
- /// <returns>A Task that represents the work queued to execute in the ThreadPool.</returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="action"/> parameter was null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">
- /// The CancellationTokenSource associated with <paramref name="cancellationToken"/> was disposed.
- /// </exception>
- public static Task Run(Action action, CancellationToken cancellationToken)
- {
- return Task.InternalStartNew(null, action, null, cancellationToken, TaskScheduler.Default,
- TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None);
- }
-
- /// <summary>
- /// Queues the specified work to run on the ThreadPool and returns a Task(TResult) handle for that work.
- /// </summary>
- /// <param name="function">The work to execute asynchronously</param>
- /// <returns>A Task(TResult) that represents the work queued to execute in the ThreadPool.</returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="function"/> parameter was null.
- /// </exception>
- public static Task<TResult> Run<TResult>(Func<TResult> function)
- {
- return Task<TResult>.StartNew(null, function, default,
- TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None, TaskScheduler.Default);
- }
-
- /// <summary>
- /// Queues the specified work to run on the ThreadPool and returns a Task(TResult) handle for that work.
- /// </summary>
- /// <param name="function">The work to execute asynchronously</param>
- /// <param name="cancellationToken">A cancellation token that should be used to cancel the work</param>
- /// <returns>A Task(TResult) that represents the work queued to execute in the ThreadPool.</returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="function"/> parameter was null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">
- /// The CancellationTokenSource associated with <paramref name="cancellationToken"/> was disposed.
- /// </exception>
- public static Task<TResult> Run<TResult>(Func<TResult> function, CancellationToken cancellationToken)
- {
- return Task<TResult>.StartNew(null, function, cancellationToken,
- TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None, TaskScheduler.Default);
- }
-
- /// <summary>
- /// Queues the specified work to run on the ThreadPool and returns a proxy for the
- /// Task returned by <paramref name="function"/>.
- /// </summary>
- /// <param name="function">The work to execute asynchronously</param>
- /// <returns>A Task that represents a proxy for the Task returned by <paramref name="function"/>.</returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="function"/> parameter was null.
- /// </exception>
- public static Task Run(Func<Task?> function)
- {
- return Run(function, default);
- }
-
- /// <summary>
- /// Queues the specified work to run on the ThreadPool and returns a proxy for the
- /// Task returned by <paramref name="function"/>.
- /// </summary>
- /// <param name="function">The work to execute asynchronously</param>
- /// <param name="cancellationToken">A cancellation token that should be used to cancel the work</param>
- /// <returns>A Task that represents a proxy for the Task returned by <paramref name="function"/>.</returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="function"/> parameter was null.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">
- /// The CancellationTokenSource associated with <paramref name="cancellationToken"/> was disposed.
- /// </exception>
- public static Task Run(Func<Task?> function, CancellationToken cancellationToken)
- {
- // Check arguments
- if (function == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function);
-
- // Short-circuit if we are given a pre-canceled token
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled(cancellationToken);
-
- // Kick off initial Task, which will call the user-supplied function and yield a Task.
- Task<Task?> task1 = Task<Task?>.Factory.StartNew(function, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
-
- // Create a promise-style Task to be used as a proxy for the operation
- // Set lookForOce == true so that unwrap logic can be on the lookout for OCEs thrown as faults from task1, to support in-delegate cancellation.
- UnwrapPromise<VoidTaskResult> promise = new UnwrapPromise<VoidTaskResult>(task1, lookForOce: true);
-
- return promise;
- }
-
- /// <summary>
- /// Queues the specified work to run on the ThreadPool and returns a proxy for the
- /// Task(TResult) returned by <paramref name="function"/>.
- /// </summary>
- /// <typeparam name="TResult">The type of the result returned by the proxy Task.</typeparam>
- /// <param name="function">The work to execute asynchronously</param>
- /// <returns>A Task(TResult) that represents a proxy for the Task(TResult) returned by <paramref name="function"/>.</returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="function"/> parameter was null.
- /// </exception>
- public static Task<TResult> Run<TResult>(Func<Task<TResult>?> function)
- {
- return Run(function, default);
- }
-
- /// <summary>
- /// Queues the specified work to run on the ThreadPool and returns a proxy for the
- /// Task(TResult) returned by <paramref name="function"/>.
- /// </summary>
- /// <typeparam name="TResult">The type of the result returned by the proxy Task.</typeparam>
- /// <param name="function">The work to execute asynchronously</param>
- /// <param name="cancellationToken">A cancellation token that should be used to cancel the work</param>
- /// <returns>A Task(TResult) that represents a proxy for the Task(TResult) returned by <paramref name="function"/>.</returns>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="function"/> parameter was null.
- /// </exception>
- public static Task<TResult> Run<TResult>(Func<Task<TResult>?> function, CancellationToken cancellationToken)
- {
- // Check arguments
- if (function == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function);
-
- // Short-circuit if we are given a pre-canceled token
- if (cancellationToken.IsCancellationRequested)
- return Task.FromCanceled<TResult>(cancellationToken);
-
- // Kick off initial Task, which will call the user-supplied function and yield a Task.
- Task<Task<TResult>?> task1 = Task<Task<TResult>?>.Factory.StartNew(function, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
-
- // Create a promise-style Task to be used as a proxy for the operation
- // Set lookForOce == true so that unwrap logic can be on the lookout for OCEs thrown as faults from task1, to support in-delegate cancellation.
- UnwrapPromise<TResult> promise = new UnwrapPromise<TResult>(task1, lookForOce: true);
-
- return promise;
- }
-
- #endregion
-
- #region Delay methods
-
- /// <summary>
- /// Creates a Task that will complete after a time delay.
- /// </summary>
- /// <param name="delay">The time span to wait before completing the returned Task</param>
- /// <returns>A Task that represents the time delay</returns>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="delay"/> is less than -1 or greater than int.MaxValue.
- /// </exception>
- /// <remarks>
- /// After the specified time delay, the Task is completed in RanToCompletion state.
- /// </remarks>
- public static Task Delay(TimeSpan delay)
- {
- return Delay(delay, default);
- }
-
- /// <summary>
- /// Creates a Task that will complete after a time delay.
- /// </summary>
- /// <param name="delay">The time span to wait before completing the returned Task</param>
- /// <param name="cancellationToken">The cancellation token that will be checked prior to completing the returned Task</param>
- /// <returns>A Task that represents the time delay</returns>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="delay"/> is less than -1 or greater than int.MaxValue.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">
- /// The provided <paramref name="cancellationToken"/> has already been disposed.
- /// </exception>
- /// <remarks>
- /// If the cancellation token is signaled before the specified time delay, then the Task is completed in
- /// Canceled state. Otherwise, the Task is completed in RanToCompletion state once the specified time
- /// delay has expired.
- /// </remarks>
- public static Task Delay(TimeSpan delay, CancellationToken cancellationToken)
- {
- long totalMilliseconds = (long)delay.TotalMilliseconds;
- if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.delay, ExceptionResource.Task_Delay_InvalidDelay);
- }
-
- return Delay((int)totalMilliseconds, cancellationToken);
- }
-
- /// <summary>
- /// Creates a Task that will complete after a time delay.
- /// </summary>
- /// <param name="millisecondsDelay">The number of milliseconds to wait before completing the returned Task</param>
- /// <returns>A Task that represents the time delay</returns>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="millisecondsDelay"/> is less than -1.
- /// </exception>
- /// <remarks>
- /// After the specified time delay, the Task is completed in RanToCompletion state.
- /// </remarks>
- public static Task Delay(int millisecondsDelay)
- {
- return Delay(millisecondsDelay, default);
- }
-
- /// <summary>
- /// Creates a Task that will complete after a time delay.
- /// </summary>
- /// <param name="millisecondsDelay">The number of milliseconds to wait before completing the returned Task</param>
- /// <param name="cancellationToken">The cancellation token that will be checked prior to completing the returned Task</param>
- /// <returns>A Task that represents the time delay</returns>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="millisecondsDelay"/> is less than -1.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">
- /// The provided <paramref name="cancellationToken"/> has already been disposed.
- /// </exception>
- /// <remarks>
- /// If the cancellation token is signaled before the specified time delay, then the Task is completed in
- /// Canceled state. Otherwise, the Task is completed in RanToCompletion state once the specified time
- /// delay has expired.
- /// </remarks>
- public static Task Delay(int millisecondsDelay, CancellationToken cancellationToken)
- {
- // Throw on non-sensical time
- if (millisecondsDelay < -1)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsDelay, ExceptionResource.Task_Delay_InvalidMillisecondsDelay);
- }
-
- return
- cancellationToken.IsCancellationRequested ? FromCanceled(cancellationToken) :
- millisecondsDelay == 0 ? CompletedTask :
- cancellationToken.CanBeCanceled ? new DelayPromiseWithCancellation(millisecondsDelay, cancellationToken) :
- new DelayPromise(millisecondsDelay);
- }
-
- /// <summary>Task that also stores the completion closure and logic for Task.Delay implementation.</summary>
- private class DelayPromise : Task
- {
- private readonly TimerQueueTimer? _timer;
-
- internal DelayPromise(int millisecondsDelay)
- {
- Debug.Assert(millisecondsDelay != 0);
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(this, "Task.Delay");
-
- if (s_asyncDebuggingEnabled)
- AddToActiveTasks(this);
-
- if (millisecondsDelay != Timeout.Infinite) // no need to create the timer if it's an infinite timeout
- {
- _timer = new TimerQueueTimer(state => ((DelayPromise)state!).CompleteTimedOut(), this, (uint)millisecondsDelay, Timeout.UnsignedInfinite, flowExecutionContext: false);
- if (IsCanceled)
- {
- // Handle rare race condition where cancellation occurs prior to our having created and stored the timer, in which case
- // the timer won't have been cleaned up appropriately. This call to close might race with the Cleanup call to Close,
- // but Close is thread-safe and will be a nop if it's already been closed.
- _timer.Close();
- }
- }
- }
-
- private void CompleteTimedOut()
- {
- if (TrySetResult())
- {
- Cleanup();
-
- if (s_asyncDebuggingEnabled)
- RemoveFromActiveTasks(this);
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Completed);
- }
- }
-
- protected virtual void Cleanup() => _timer?.Close();
- }
-
- /// <summary>DelayPromise that also supports cancellation.</summary>
- private sealed class DelayPromiseWithCancellation : DelayPromise
- {
- private readonly CancellationToken _token;
- private readonly CancellationTokenRegistration _registration;
-
- internal DelayPromiseWithCancellation(int millisecondsDelay, CancellationToken token) : base(millisecondsDelay)
- {
- Debug.Assert(token.CanBeCanceled);
-
- _token = token;
- _registration = token.UnsafeRegister(state => ((DelayPromiseWithCancellation)state!).CompleteCanceled(), this);
- }
-
- private void CompleteCanceled()
- {
- if (TrySetCanceled(_token))
- {
- Cleanup();
- // This path doesn't invoke RemoveFromActiveTasks or TraceOperationCompletion
- // because that's strangely already handled inside of TrySetCanceled.
- }
- }
-
- protected override void Cleanup()
- {
- _registration.Dispose();
- base.Cleanup();
- }
- }
- #endregion
-
- #region WhenAll
- /// <summary>
- /// Creates a task that will complete when all of the supplied tasks have completed.
- /// </summary>
- /// <param name="tasks">The tasks to wait on for completion.</param>
- /// <returns>A task that represents the completion of all of the supplied tasks.</returns>
- /// <remarks>
- /// <para>
- /// If any of the supplied tasks completes in a faulted state, the returned task will also complete in a Faulted state,
- /// where its exceptions will contain the aggregation of the set of unwrapped exceptions from each of the supplied tasks.
- /// </para>
- /// <para>
- /// If none of the supplied tasks faulted but at least one of them was canceled, the returned task will end in the Canceled state.
- /// </para>
- /// <para>
- /// If none of the tasks faulted and none of the tasks were canceled, the resulting task will end in the RanToCompletion state.
- /// </para>
- /// <para>
- /// If the supplied array/enumerable contains no tasks, the returned task will immediately transition to a RanToCompletion
- /// state before it's returned to the caller.
- /// </para>
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument was null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> collection contained a null task.
- /// </exception>
- public static Task WhenAll(IEnumerable<Task> tasks)
- {
- // Take a more efficient path if tasks is actually an array
- if (tasks is Task[] taskArray)
- {
- return WhenAll(taskArray);
- }
-
- // Skip a List allocation/copy if tasks is a collection
- if (tasks is ICollection<Task> taskCollection)
- {
- int index = 0;
- taskArray = new Task[taskCollection.Count];
- foreach (Task task in tasks)
- {
- if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- taskArray[index++] = task;
- }
- return InternalWhenAll(taskArray);
- }
-
- // Do some argument checking and convert tasks to a List (and later an array).
- if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- List<Task> taskList = new List<Task>();
- foreach (Task task in tasks)
- {
- if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- taskList.Add(task);
- }
-
- // Delegate the rest to InternalWhenAll()
- return InternalWhenAll(taskList.ToArray());
- }
-
- /// <summary>
- /// Creates a task that will complete when all of the supplied tasks have completed.
- /// </summary>
- /// <param name="tasks">The tasks to wait on for completion.</param>
- /// <returns>A task that represents the completion of all of the supplied tasks.</returns>
- /// <remarks>
- /// <para>
- /// If any of the supplied tasks completes in a faulted state, the returned task will also complete in a Faulted state,
- /// where its exceptions will contain the aggregation of the set of unwrapped exceptions from each of the supplied tasks.
- /// </para>
- /// <para>
- /// If none of the supplied tasks faulted but at least one of them was canceled, the returned task will end in the Canceled state.
- /// </para>
- /// <para>
- /// If none of the tasks faulted and none of the tasks were canceled, the resulting task will end in the RanToCompletion state.
- /// </para>
- /// <para>
- /// If the supplied array/enumerable contains no tasks, the returned task will immediately transition to a RanToCompletion
- /// state before it's returned to the caller.
- /// </para>
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument was null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> array contained a null task.
- /// </exception>
- public static Task WhenAll(params Task[] tasks)
- {
- // Do some argument checking and make a defensive copy of the tasks array
- if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
-
- int taskCount = tasks.Length;
- if (taskCount == 0) return InternalWhenAll(tasks); // Small optimization in the case of an empty array.
-
- Task[] tasksCopy = new Task[taskCount];
- for (int i = 0; i < taskCount; i++)
- {
- Task task = tasks[i];
- if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- tasksCopy[i] = task;
- }
-
- // The rest can be delegated to InternalWhenAll()
- return InternalWhenAll(tasksCopy);
- }
-
- // Some common logic to support WhenAll() methods
- // tasks should be a defensive copy.
- private static Task InternalWhenAll(Task[] tasks)
- {
- Debug.Assert(tasks != null, "Expected a non-null tasks array");
- return (tasks.Length == 0) ? // take shortcut if there are no tasks upon which to wait
- Task.CompletedTask :
- new WhenAllPromise(tasks);
- }
-
- // A Task that gets completed when all of its constituent tasks complete.
- // Completion logic will analyze the antecedents in order to choose completion status.
- // This type allows us to replace this logic:
- // Task promise = new Task(...);
- // Action<Task> completionAction = delegate { <completion logic>};
- // TaskFactory.CommonCWAllLogic(tasksCopy).AddCompletionAction(completionAction);
- // return promise;
- // which involves several allocations, with this logic:
- // return new WhenAllPromise(tasksCopy);
- // which saves a couple of allocations and enables debugger notification specialization.
- //
- // Used in InternalWhenAll(Task[])
- private sealed class WhenAllPromise : Task, ITaskCompletionAction
- {
- /// <summary>
- /// Stores all of the constituent tasks. Tasks clear themselves out of this
- /// array as they complete, but only if they don't have their wait notification bit set.
- /// </summary>
- private readonly Task?[] m_tasks;
- /// <summary>The number of tasks remaining to complete.</summary>
- private int m_count;
-
- internal WhenAllPromise(Task[] tasks)
- {
- Debug.Assert(tasks != null, "Expected a non-null task array");
- Debug.Assert(tasks.Length > 0, "Expected a non-zero length task array");
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(this, "Task.WhenAll");
-
- if (s_asyncDebuggingEnabled)
- AddToActiveTasks(this);
-
- m_tasks = tasks;
- m_count = tasks.Length;
-
- foreach (Task task in tasks)
- {
- if (task.IsCompleted) this.Invoke(task); // short-circuit the completion action, if possible
- else task.AddCompletionAction(this); // simple completion action
- }
- }
-
- public void Invoke(Task completedTask)
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationRelation(this, CausalityRelation.Join);
-
- // Decrement the count, and only continue to complete the promise if we're the last one.
- if (Interlocked.Decrement(ref m_count) == 0)
- {
- // Set up some accounting variables
- List<ExceptionDispatchInfo>? observedExceptions = null;
- Task? canceledTask = null;
-
- // Loop through antecedents:
- // If any one of them faults, the result will be faulted
- // If none fault, but at least one is canceled, the result will be canceled
- // If none fault or are canceled, then result will be RanToCompletion
- for (int i = 0; i < m_tasks.Length; i++)
- {
- Task? task = m_tasks[i];
- Debug.Assert(task != null, "Constituent task in WhenAll should never be null");
-
- if (task.IsFaulted)
- {
- observedExceptions ??= new List<ExceptionDispatchInfo>();
- observedExceptions.AddRange(task.GetExceptionDispatchInfos());
- }
- else if (task.IsCanceled)
- {
- canceledTask ??= task; // use the first task that's canceled
- }
-
- // Regardless of completion state, if the task has its debug bit set, transfer it to the
- // WhenAll task. We must do this before we complete the task.
- if (task.IsWaitNotificationEnabled) this.SetNotificationForWaitCompletion(enabled: true);
- else m_tasks[i] = null; // avoid holding onto tasks unnecessarily
- }
-
- if (observedExceptions != null)
- {
- Debug.Assert(observedExceptions.Count > 0, "Expected at least one exception");
-
- // We don't need to TraceOperationCompleted here because TrySetException will call Finish and we'll log it there
-
- TrySetException(observedExceptions);
- }
- else if (canceledTask != null)
- {
- TrySetCanceled(canceledTask.CancellationToken, canceledTask.GetCancellationExceptionDispatchInfo());
- }
- else
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Completed);
-
- if (s_asyncDebuggingEnabled)
- RemoveFromActiveTasks(this);
-
- TrySetResult();
- }
- }
- Debug.Assert(m_count >= 0, "Count should never go below 0");
- }
-
- public bool InvokeMayRunArbitraryCode => true;
-
- /// <summary>
- /// Returns whether we should notify the debugger of a wait completion. This returns
- /// true iff at least one constituent task has its bit set.
- /// </summary>
- internal override bool ShouldNotifyDebuggerOfWaitCompletion =>
- base.ShouldNotifyDebuggerOfWaitCompletion &&
- AnyTaskRequiresNotifyDebuggerOfWaitCompletion(m_tasks);
- }
-
- /// <summary>
- /// Creates a task that will complete when all of the supplied tasks have completed.
- /// </summary>
- /// <param name="tasks">The tasks to wait on for completion.</param>
- /// <returns>A task that represents the completion of all of the supplied tasks.</returns>
- /// <remarks>
- /// <para>
- /// If any of the supplied tasks completes in a faulted state, the returned task will also complete in a Faulted state,
- /// where its exceptions will contain the aggregation of the set of unwrapped exceptions from each of the supplied tasks.
- /// </para>
- /// <para>
- /// If none of the supplied tasks faulted but at least one of them was canceled, the returned task will end in the Canceled state.
- /// </para>
- /// <para>
- /// If none of the tasks faulted and none of the tasks were canceled, the resulting task will end in the RanToCompletion state.
- /// The Result of the returned task will be set to an array containing all of the results of the
- /// supplied tasks in the same order as they were provided (e.g. if the input tasks array contained t1, t2, t3, the output
- /// task's Result will return an TResult[] where arr[0] == t1.Result, arr[1] == t2.Result, and arr[2] == t3.Result).
- /// </para>
- /// <para>
- /// If the supplied array/enumerable contains no tasks, the returned task will immediately transition to a RanToCompletion
- /// state before it's returned to the caller. The returned TResult[] will be an array of 0 elements.
- /// </para>
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument was null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> collection contained a null task.
- /// </exception>
- public static Task<TResult[]> WhenAll<TResult>(IEnumerable<Task<TResult>> tasks)
- {
- // Take a more efficient route if tasks is actually an array
- if (tasks is Task<TResult>[] taskArray)
- {
- return WhenAll<TResult>(taskArray);
- }
-
- // Skip a List allocation/copy if tasks is a collection
- if (tasks is ICollection<Task<TResult>> taskCollection)
- {
- int index = 0;
- taskArray = new Task<TResult>[taskCollection.Count];
- foreach (Task<TResult> task in tasks)
- {
- if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- taskArray[index++] = task;
- }
- return InternalWhenAll<TResult>(taskArray);
- }
-
- // Do some argument checking and convert tasks into a List (later an array)
- if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- List<Task<TResult>> taskList = new List<Task<TResult>>();
- foreach (Task<TResult> task in tasks)
- {
- if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- taskList.Add(task);
- }
-
- // Delegate the rest to InternalWhenAll<TResult>().
- return InternalWhenAll<TResult>(taskList.ToArray());
- }
-
- /// <summary>
- /// Creates a task that will complete when all of the supplied tasks have completed.
- /// </summary>
- /// <param name="tasks">The tasks to wait on for completion.</param>
- /// <returns>A task that represents the completion of all of the supplied tasks.</returns>
- /// <remarks>
- /// <para>
- /// If any of the supplied tasks completes in a faulted state, the returned task will also complete in a Faulted state,
- /// where its exceptions will contain the aggregation of the set of unwrapped exceptions from each of the supplied tasks.
- /// </para>
- /// <para>
- /// If none of the supplied tasks faulted but at least one of them was canceled, the returned task will end in the Canceled state.
- /// </para>
- /// <para>
- /// If none of the tasks faulted and none of the tasks were canceled, the resulting task will end in the RanToCompletion state.
- /// The Result of the returned task will be set to an array containing all of the results of the
- /// supplied tasks in the same order as they were provided (e.g. if the input tasks array contained t1, t2, t3, the output
- /// task's Result will return an TResult[] where arr[0] == t1.Result, arr[1] == t2.Result, and arr[2] == t3.Result).
- /// </para>
- /// <para>
- /// If the supplied array/enumerable contains no tasks, the returned task will immediately transition to a RanToCompletion
- /// state before it's returned to the caller. The returned TResult[] will be an array of 0 elements.
- /// </para>
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument was null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> array contained a null task.
- /// </exception>
- public static Task<TResult[]> WhenAll<TResult>(params Task<TResult>[] tasks)
- {
- // Do some argument checking and make a defensive copy of the tasks array
- if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
-
- int taskCount = tasks.Length;
- if (taskCount == 0) return InternalWhenAll<TResult>(tasks); // small optimization in the case of an empty task array
-
- Task<TResult>[] tasksCopy = new Task<TResult>[taskCount];
- for (int i = 0; i < taskCount; i++)
- {
- Task<TResult> task = tasks[i];
- if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- tasksCopy[i] = task;
- }
-
- // Delegate the rest to InternalWhenAll<TResult>()
- return InternalWhenAll<TResult>(tasksCopy);
- }
-
- // Some common logic to support WhenAll<TResult> methods
- private static Task<TResult[]> InternalWhenAll<TResult>(Task<TResult>[] tasks)
- {
- Debug.Assert(tasks != null, "Expected a non-null tasks array");
- return (tasks.Length == 0) ? // take shortcut if there are no tasks upon which to wait
- new Task<TResult[]>(false, Array.Empty<TResult>(), TaskCreationOptions.None, default) :
- new WhenAllPromise<TResult>(tasks);
- }
-
- // A Task<T> that gets completed when all of its constituent tasks complete.
- // Completion logic will analyze the antecedents in order to choose completion status.
- // See comments for non-generic version of WhenAllPromise class.
- //
- // Used in InternalWhenAll<TResult>(Task<TResult>[])
- private sealed class WhenAllPromise<T> : Task<T[]>, ITaskCompletionAction
- {
- /// <summary>
- /// Stores all of the constituent tasks. Tasks clear themselves out of this
- /// array as they complete, but only if they don't have their wait notification bit set.
- /// </summary>
- private readonly Task<T>?[] m_tasks;
- /// <summary>The number of tasks remaining to complete.</summary>
- private int m_count;
-
- internal WhenAllPromise(Task<T>[] tasks)
- {
- Debug.Assert(tasks != null, "Expected a non-null task array");
- Debug.Assert(tasks.Length > 0, "Expected a non-zero length task array");
-
- m_tasks = tasks;
- m_count = tasks.Length;
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(this, "Task.WhenAll");
-
- if (s_asyncDebuggingEnabled)
- AddToActiveTasks(this);
-
- foreach (Task<T> task in tasks)
- {
- if (task.IsCompleted) this.Invoke(task); // short-circuit the completion action, if possible
- else task.AddCompletionAction(this); // simple completion action
- }
- }
-
- public void Invoke(Task ignored)
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationRelation(this, CausalityRelation.Join);
-
- // Decrement the count, and only continue to complete the promise if we're the last one.
- if (Interlocked.Decrement(ref m_count) == 0)
- {
- // Set up some accounting variables
- T[] results = new T[m_tasks.Length];
- List<ExceptionDispatchInfo>? observedExceptions = null;
- Task? canceledTask = null;
-
- // Loop through antecedents:
- // If any one of them faults, the result will be faulted
- // If none fault, but at least one is canceled, the result will be canceled
- // If none fault or are canceled, then result will be RanToCompletion
- for (int i = 0; i < m_tasks.Length; i++)
- {
- Task<T>? task = m_tasks[i];
- Debug.Assert(task != null, "Constituent task in WhenAll should never be null");
-
- if (task.IsFaulted)
- {
- observedExceptions ??= new List<ExceptionDispatchInfo>();
- observedExceptions.AddRange(task.GetExceptionDispatchInfos());
- }
- else if (task.IsCanceled)
- {
- canceledTask ??= task; // use the first task that's canceled
- }
- else
- {
- Debug.Assert(task.Status == TaskStatus.RanToCompletion);
- results[i] = task.GetResultCore(waitCompletionNotification: false); // avoid Result, which would triggering debug notification
- }
-
- // Regardless of completion state, if the task has its debug bit set, transfer it to the
- // WhenAll task. We must do this before we complete the task.
- if (task.IsWaitNotificationEnabled) this.SetNotificationForWaitCompletion(enabled: true);
- else m_tasks[i] = null; // avoid holding onto tasks unnecessarily
- }
-
- if (observedExceptions != null)
- {
- Debug.Assert(observedExceptions.Count > 0, "Expected at least one exception");
-
- // We don't need to TraceOperationCompleted here because TrySetException will call Finish and we'll log it there
-
- TrySetException(observedExceptions);
- }
- else if (canceledTask != null)
- {
- TrySetCanceled(canceledTask.CancellationToken, canceledTask.GetCancellationExceptionDispatchInfo());
- }
- else
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Completed);
-
- if (Task.s_asyncDebuggingEnabled)
- RemoveFromActiveTasks(this);
-
- TrySetResult(results);
- }
- }
- Debug.Assert(m_count >= 0, "Count should never go below 0");
- }
-
- public bool InvokeMayRunArbitraryCode => true;
-
- /// <summary>
- /// Returns whether we should notify the debugger of a wait completion. This returns true
- /// iff at least one constituent task has its bit set.
- /// </summary>
- internal override bool ShouldNotifyDebuggerOfWaitCompletion =>
- base.ShouldNotifyDebuggerOfWaitCompletion &&
- AnyTaskRequiresNotifyDebuggerOfWaitCompletion(m_tasks);
- }
- #endregion
-
- #region WhenAny
- /// <summary>
- /// Creates a task that will complete when any of the supplied tasks have completed.
- /// </summary>
- /// <param name="tasks">The tasks to wait on for completion.</param>
- /// <returns>A task that represents the completion of one of the supplied tasks. The return Task's Result is the task that completed.</returns>
- /// <remarks>
- /// The returned task will complete when any of the supplied tasks has completed. The returned task will always end in the RanToCompletion state
- /// with its Result set to the first task to complete. This is true even if the first task to complete ended in the Canceled or Faulted state.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument was null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> array contained a null task, or was empty.
- /// </exception>
- public static Task<Task> WhenAny(params Task[] tasks)
- {
- if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- if (tasks.Length == 0)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
- }
-
- // Make a defensive copy, as the user may manipulate the tasks array
- // after we return but before the WhenAny asynchronously completes.
- int taskCount = tasks.Length;
- Task[] tasksCopy = new Task[taskCount];
- for (int i = 0; i < taskCount; i++)
- {
- Task task = tasks[i];
- if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- tasksCopy[i] = task;
- }
-
- // Previously implemented CommonCWAnyLogic() can handle the rest
- return TaskFactory.CommonCWAnyLogic(tasksCopy);
- }
-
- /// <summary>
- /// Creates a task that will complete when any of the supplied tasks have completed.
- /// </summary>
- /// <param name="tasks">The tasks to wait on for completion.</param>
- /// <returns>A task that represents the completion of one of the supplied tasks. The return Task's Result is the task that completed.</returns>
- /// <remarks>
- /// The returned task will complete when any of the supplied tasks has completed. The returned task will always end in the RanToCompletion state
- /// with its Result set to the first task to complete. This is true even if the first task to complete ended in the Canceled or Faulted state.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument was null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> collection contained a null task, or was empty.
- /// </exception>
- public static Task<Task> WhenAny(IEnumerable<Task> tasks)
- {
- if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
-
- // Make a defensive copy, as the user may manipulate the tasks collection
- // after we return but before the WhenAny asynchronously completes.
- List<Task> taskList = new List<Task>();
- foreach (Task task in tasks)
- {
- if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- taskList.Add(task);
- }
-
- if (taskList.Count == 0)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
- }
-
- // Previously implemented CommonCWAnyLogic() can handle the rest
- return TaskFactory.CommonCWAnyLogic(taskList);
- }
-
- /// <summary>
- /// Creates a task that will complete when any of the supplied tasks have completed.
- /// </summary>
- /// <param name="tasks">The tasks to wait on for completion.</param>
- /// <returns>A task that represents the completion of one of the supplied tasks. The return Task's Result is the task that completed.</returns>
- /// <remarks>
- /// The returned task will complete when any of the supplied tasks has completed. The returned task will always end in the RanToCompletion state
- /// with its Result set to the first task to complete. This is true even if the first task to complete ended in the Canceled or Faulted state.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument was null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> array contained a null task, or was empty.
- /// </exception>
- public static Task<Task<TResult>> WhenAny<TResult>(params Task<TResult>[] tasks)
- {
- // We would just like to do this:
- // return (Task<Task<TResult>>) WhenAny( (Task[]) tasks);
- // but classes are not covariant to enable casting Task<TResult> to Task<Task<TResult>>.
-
- // Call WhenAny(Task[]) for basic functionality
- Task<Task> intermediate = WhenAny((Task[])tasks);
-
- // Return a continuation task with the correct result type
- return intermediate.ContinueWith(Task<TResult>.TaskWhenAnyCast.Value, default,
- TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.DenyChildAttach, TaskScheduler.Default);
- }
-
- /// <summary>
- /// Creates a task that will complete when any of the supplied tasks have completed.
- /// </summary>
- /// <param name="tasks">The tasks to wait on for completion.</param>
- /// <returns>A task that represents the completion of one of the supplied tasks. The return Task's Result is the task that completed.</returns>
- /// <remarks>
- /// The returned task will complete when any of the supplied tasks has completed. The returned task will always end in the RanToCompletion state
- /// with its Result set to the first task to complete. This is true even if the first task to complete ended in the Canceled or Faulted state.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">
- /// The <paramref name="tasks"/> argument was null.
- /// </exception>
- /// <exception cref="System.ArgumentException">
- /// The <paramref name="tasks"/> collection contained a null task, or was empty.
- /// </exception>
- public static Task<Task<TResult>> WhenAny<TResult>(IEnumerable<Task<TResult>> tasks)
- {
- // We would just like to do this:
- // return (Task<Task<TResult>>) WhenAny( (IEnumerable<Task>) tasks);
- // but classes are not covariant to enable casting Task<TResult> to Task<Task<TResult>>.
-
- // Call WhenAny(IEnumerable<Task>) for basic functionality
- Task<Task> intermediate = WhenAny((IEnumerable<Task>)tasks);
-
- // Return a continuation task with the correct result type
- return intermediate.ContinueWith(Task<TResult>.TaskWhenAnyCast.Value, default,
- TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.DenyChildAttach, TaskScheduler.Default);
- }
- #endregion
-
- internal static Task<TResult> CreateUnwrapPromise<TResult>(Task outerTask, bool lookForOce)
- {
- Debug.Assert(outerTask != null);
-
- return new UnwrapPromise<TResult>(outerTask, lookForOce);
- }
-
- internal virtual Delegate[]? GetDelegateContinuationsForDebugger()
- {
- // Avoid an infinite loop by making sure the continuation object is not a reference to istelf.
- if (m_continuationObject != this)
- return GetDelegatesFromContinuationObject(m_continuationObject);
- else
- return null;
- }
-
- private static Delegate[]? GetDelegatesFromContinuationObject(object? continuationObject)
- {
- if (continuationObject != null)
- {
- if (continuationObject is Action singleAction)
- {
- return new Delegate[] { AsyncMethodBuilderCore.TryGetStateMachineForDebugger(singleAction) };
- }
-
- if (continuationObject is TaskContinuation taskContinuation)
- {
- return taskContinuation.GetDelegateContinuationsForDebugger();
- }
-
- if (continuationObject is Task continuationTask)
- {
- Debug.Assert(continuationTask.m_action == null);
- Delegate[]? delegates = continuationTask.GetDelegateContinuationsForDebugger();
- if (delegates != null)
- return delegates;
- }
-
- // We need this ITaskCompletionAction after the Task because in the case of UnwrapPromise
- // the VS debugger is more interested in the continuation than the internal invoke()
- if (continuationObject is ITaskCompletionAction singleCompletionAction)
- {
- return new Delegate[] { new Action<Task>(singleCompletionAction.Invoke) };
- }
-
- if (continuationObject is List<object?> continuationList)
- {
- List<Delegate> result = new List<Delegate>();
- foreach (object? obj in continuationList)
- {
- Delegate[]? innerDelegates = GetDelegatesFromContinuationObject(obj);
- if (innerDelegates != null)
- {
- foreach (Delegate del in innerDelegates)
- {
- if (del != null)
- result.Add(del);
- }
- }
- }
-
- return result.ToArray();
- }
- }
-
- return null;
- }
-
- // Do not remove: VS debugger calls this API directly using func-eval to populate data in the tasks window
- private static Task? GetActiveTaskFromId(int taskId)
- {
- Task? task = null;
- s_currentActiveTasks?.TryGetValue(taskId, out task);
- return task;
- }
- }
-
- internal sealed class CompletionActionInvoker : IThreadPoolWorkItem
- {
- private readonly ITaskCompletionAction m_action;
- private readonly Task m_completingTask;
-
- internal CompletionActionInvoker(ITaskCompletionAction action, Task completingTask)
- {
- m_action = action;
- m_completingTask = completingTask;
- }
-
- void IThreadPoolWorkItem.Execute()
- {
- m_action.Invoke(m_completingTask);
- }
- }
-
- // Proxy class for better debugging experience
- internal class SystemThreadingTasks_TaskDebugView
- {
- private readonly Task m_task;
-
- public SystemThreadingTasks_TaskDebugView(Task task)
- {
- m_task = task;
- }
-
- public object? AsyncState => m_task.AsyncState;
- public TaskCreationOptions CreationOptions => m_task.CreationOptions;
- public Exception? Exception => m_task.Exception;
- public int Id => m_task.Id;
- public bool CancellationPending => (m_task.Status == TaskStatus.WaitingToRun) && m_task.CancellationToken.IsCancellationRequested;
- public TaskStatus Status => m_task.Status;
- }
-
- /// <summary>
- /// Specifies flags that control optional behavior for the creation and execution of tasks.
- /// </summary>
- // NOTE: These options are a subset of TaskContinuationsOptions, thus before adding a flag check it is
- // not already in use.
- [Flags]
- public enum TaskCreationOptions
- {
- /// <summary>
- /// Specifies that the default behavior should be used.
- /// </summary>
- None = 0x0,
-
- /// <summary>
- /// A hint to a <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> to schedule a
- /// task in as fair a manner as possible, meaning that tasks scheduled sooner will be more likely to
- /// be run sooner, and tasks scheduled later will be more likely to be run later.
- /// </summary>
- PreferFairness = 0x01,
-
- /// <summary>
- /// Specifies that a task will be a long-running, course-grained operation. It provides a hint to the
- /// <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> that oversubscription may be
- /// warranted.
- /// </summary>
- LongRunning = 0x02,
-
- /// <summary>
- /// Specifies that a task is attached to a parent in the task hierarchy.
- /// </summary>
- AttachedToParent = 0x04,
-
- /// <summary>
- /// Specifies that an InvalidOperationException will be thrown if an attempt is made to attach a child task to the created task.
- /// </summary>
- DenyChildAttach = 0x08,
-
- /// <summary>
- /// Prevents the ambient scheduler from being seen as the current scheduler in the created task. This means that operations
- /// like StartNew or ContinueWith that are performed in the created task will see TaskScheduler.Default as the current scheduler.
- /// </summary>
- HideScheduler = 0x10,
-
- // 0x20 is already being used in TaskContinuationOptions
-
- /// <summary>
- /// Forces continuations added to the current task to be executed asynchronously.
- /// This option has precedence over TaskContinuationOptions.ExecuteSynchronously
- /// </summary>
- RunContinuationsAsynchronously = 0x40
- }
-
- /// <summary>
- /// Task creation flags which are only used internally.
- /// </summary>
- [Flags]
- internal enum InternalTaskOptions
- {
- /// <summary> Specifies "No internal task options" </summary>
- None,
-
- /// <summary>Used to filter out internal vs. public task creation options.</summary>
- InternalOptionsMask = 0x0000FF00,
-
- ContinuationTask = 0x0200,
- PromiseTask = 0x0400,
-
- /// <summary>
- /// Store the presence of TaskContinuationOptions.LazyCancellation, since it does not directly
- /// translate into any TaskCreationOptions.
- /// </summary>
- LazyCancellation = 0x1000,
-
- /// <summary>Specifies that the task will be queued by the runtime before handing it over to the user.
- /// This flag will be used to skip the cancellationtoken registration step, which is only meant for unstarted tasks.</summary>
- QueuedByRuntime = 0x2000,
-
- /// <summary>
- /// Denotes that Dispose should be a complete nop for a Task. Used when constructing tasks that are meant to be cached/reused.
- /// </summary>
- DoNotDispose = 0x4000
- }
-
- /// <summary>
- /// Specifies flags that control optional behavior for the creation and execution of continuation tasks.
- /// </summary>
- [Flags]
- public enum TaskContinuationOptions
- {
- /// <summary>
- /// Default = "Continue on any, no task options, run asynchronously"
- /// Specifies that the default behavior should be used. Continuations, by default, will
- /// be scheduled when the antecedent task completes, regardless of the task's final <see
- /// cref="System.Threading.Tasks.TaskStatus">TaskStatus</see>.
- /// </summary>
- None = 0,
-
- // These are identical to their meanings and values in TaskCreationOptions
-
- /// <summary>
- /// A hint to a <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> to schedule a
- /// task in as fair a manner as possible, meaning that tasks scheduled sooner will be more likely to
- /// be run sooner, and tasks scheduled later will be more likely to be run later.
- /// </summary>
- PreferFairness = 0x01,
-
- /// <summary>
- /// Specifies that a task will be a long-running, course-grained operation. It provides
- /// a hint to the <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> that
- /// oversubscription may be warranted.
- /// </summary>
- LongRunning = 0x02,
- /// <summary>
- /// Specifies that a task is attached to a parent in the task hierarchy.
- /// </summary>
- AttachedToParent = 0x04,
-
- /// <summary>
- /// Specifies that an InvalidOperationException will be thrown if an attempt is made to attach a child task to the created task.
- /// </summary>
- DenyChildAttach = 0x08,
- /// <summary>
- /// Prevents the ambient scheduler from being seen as the current scheduler in the created task. This means that operations
- /// like StartNew or ContinueWith that are performed in the created task will see TaskScheduler.Default as the current scheduler.
- /// </summary>
- HideScheduler = 0x10,
-
- /// <summary>
- /// In the case of continuation cancellation, prevents completion of the continuation until the antecedent has completed.
- /// </summary>
- LazyCancellation = 0x20,
-
- RunContinuationsAsynchronously = 0x40,
-
- // These are specific to continuations
-
- /// <summary>
- /// Specifies that the continuation task should not be scheduled if its antecedent ran to completion.
- /// This option is not valid for multi-task continuations.
- /// </summary>
- NotOnRanToCompletion = 0x10000,
- /// <summary>
- /// Specifies that the continuation task should not be scheduled if its antecedent threw an unhandled
- /// exception. This option is not valid for multi-task continuations.
- /// </summary>
- NotOnFaulted = 0x20000,
- /// <summary>
- /// Specifies that the continuation task should not be scheduled if its antecedent was canceled. This
- /// option is not valid for multi-task continuations.
- /// </summary>
- NotOnCanceled = 0x40000,
- /// <summary>
- /// Specifies that the continuation task should be scheduled only if its antecedent ran to
- /// completion. This option is not valid for multi-task continuations.
- /// </summary>
- OnlyOnRanToCompletion = NotOnFaulted | NotOnCanceled,
- /// <summary>
- /// Specifies that the continuation task should be scheduled only if its antecedent threw an
- /// unhandled exception. This option is not valid for multi-task continuations.
- /// </summary>
- OnlyOnFaulted = NotOnRanToCompletion | NotOnCanceled,
- /// <summary>
- /// Specifies that the continuation task should be scheduled only if its antecedent was canceled.
- /// This option is not valid for multi-task continuations.
- /// </summary>
- OnlyOnCanceled = NotOnRanToCompletion | NotOnFaulted,
- /// <summary>
- /// Specifies that the continuation task should be executed synchronously. With this option
- /// specified, the continuation will be run on the same thread that causes the antecedent task to
- /// transition into its final state. If the antecedent is already complete when the continuation is
- /// created, the continuation will run on the thread creating the continuation. Only very
- /// short-running continuations should be executed synchronously.
- /// </summary>
- ExecuteSynchronously = 0x80000
- }
-
- // Special internal struct that we use to signify that we are not interested in
- // a Task<VoidTaskResult>'s result.
- internal struct VoidTaskResult { }
-
- // Interface to which all completion actions must conform.
- // This interface allows us to combine functionality and reduce allocations.
- // For example, see Task.SetOnInvokeMres, and its use in Task.SpinThenBlockingWait().
- // This code:
- // ManualResetEvent mres = new ManualResetEventSlim(false, 0);
- // Action<Task> completionAction = delegate { mres.Set() ; };
- // AddCompletionAction(completionAction);
- // gets replaced with this:
- // SetOnInvokeMres mres = new SetOnInvokeMres();
- // AddCompletionAction(mres);
- // For additional examples of where this is used, see internal classes Task.SignalOnInvokeCDE,
- // Task.WhenAllPromise, Task.WhenAllPromise<T>, TaskFactory.CompleteOnCountdownPromise,
- // TaskFactory.CompleteOnCountdownPromise<T>, and TaskFactory.CompleteOnInvokePromise.
- internal interface ITaskCompletionAction
- {
- /// <summary>Invoked to run the completion action.</summary>
- void Invoke(Task completingTask);
-
- /// <summary>
- /// Some completion actions are considered internal implementation details of tasks,
- /// using the continuation mechanism only for performance reasons. Such actions perform
- /// known quantities and types of work, and can be invoked safely as a continuation even
- /// if the system wants to prevent arbitrary continuations from running synchronously.
- /// This should only return false for a limited set of implementations where a small amount
- /// of work is guaranteed to be performed, e.g. setting a ManualResetEventSlim.
- /// </summary>
- bool InvokeMayRunArbitraryCode { get; }
- }
-
- // This class encapsulates all "unwrap" logic, and also implements ITaskCompletionAction,
- // which minimizes the allocations needed for queuing it to its antecedent. This
- // logic is used by both the Unwrap extension methods and the unwrap-style Task.Run methods.
- internal sealed class UnwrapPromise<TResult> : Task<TResult>, ITaskCompletionAction
- {
- // The possible states for our UnwrapPromise, used by Invoke() to determine which logic to execute
- private const byte STATE_WAITING_ON_OUTER_TASK = 0; // Invoke() means "process completed outer task"
- private const byte STATE_WAITING_ON_INNER_TASK = 1; // Invoke() means "process completed inner task"
- private const byte STATE_DONE = 2; // Invoke() means "something went wrong and we are hosed!"
-
- // Keep track of our state; initialized to STATE_WAITING_ON_OUTER_TASK in the constructor
- private byte _state;
-
- // "Should we check for OperationCanceledExceptions on the outer task and interpret them as proxy cancellation?"
- // Unwrap() sets this to false, Run() sets it to true.
- private readonly bool _lookForOce;
-
- public UnwrapPromise(Task outerTask, bool lookForOce)
- : base((object?)null, outerTask.CreationOptions & TaskCreationOptions.AttachedToParent)
- {
- Debug.Assert(outerTask != null, "Expected non-null outerTask");
- _lookForOce = lookForOce;
- _state = STATE_WAITING_ON_OUTER_TASK;
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(this, "Task.Unwrap");
-
- if (s_asyncDebuggingEnabled)
- AddToActiveTasks(this);
-
- // Link ourselves to the outer task.
- // If the outer task has already completed, take the fast path
- // of immediately transferring its results or processing the inner task.
- if (outerTask.IsCompleted)
- {
- ProcessCompletedOuterTask(outerTask);
- }
- else // Otherwise, process its completion asynchronously.
- {
- outerTask.AddCompletionAction(this);
- }
- }
-
- // For ITaskCompletionAction
- public void Invoke(Task completingTask)
- {
- // If we're ok to inline, process the task. Otherwise, we're too deep on the stack, and
- // we shouldn't run the continuation chain here, so queue a work item to call back here
- // to Invoke asynchronously.
- if (RuntimeHelpers.TryEnsureSufficientExecutionStack())
- {
- InvokeCore(completingTask);
- }
- else
- {
- InvokeCoreAsync(completingTask);
- }
- }
-
- /// <summary>
- /// Processes the completed task. InvokeCore could be called twice:
- /// once for the outer task, once for the inner task.
- /// </summary>
- /// <param name="completingTask">The completing outer or inner task.</param>
- private void InvokeCore(Task completingTask)
- {
- switch (_state)
- {
- case STATE_WAITING_ON_OUTER_TASK:
- ProcessCompletedOuterTask(completingTask);
- // We bump the state inside of ProcessCompletedOuterTask because it can also be called from the constructor.
- break;
- case STATE_WAITING_ON_INNER_TASK:
- bool result = TrySetFromTask(completingTask, lookForOce: false);
- _state = STATE_DONE; // bump the state
- Debug.Assert(result, "Expected TrySetFromTask from inner task to succeed");
- break;
- default:
- Debug.Fail("UnwrapPromise in illegal state");
- break;
- }
- }
-
- // Calls InvokeCore asynchronously.
- private void InvokeCoreAsync(Task completingTask)
- {
- // Queue a call to Invoke. If we're so deep on the stack that we're at risk of overflowing,
- // there's a high liklihood this thread is going to be doing lots more work before
- // returning to the thread pool (at the very least unwinding through thousands of
- // stack frames). So we queue to the global queue.
- ThreadPool.UnsafeQueueUserWorkItem(state =>
- {
- // InvokeCore(completingTask);
- var tuple = (Tuple<UnwrapPromise<TResult>, Task>)state!;
- tuple.Item1.InvokeCore(tuple.Item2);
- }, Tuple.Create<UnwrapPromise<TResult>, Task>(this, completingTask));
- }
-
- /// <summary>Processes the outer task once it's completed.</summary>
- /// <param name="task">The now-completed outer task.</param>
- private void ProcessCompletedOuterTask(Task task)
- {
- Debug.Assert(task != null && task.IsCompleted, "Expected non-null, completed outer task");
- Debug.Assert(_state == STATE_WAITING_ON_OUTER_TASK, "We're in the wrong state!");
-
- // Bump our state before proceeding any further
- _state = STATE_WAITING_ON_INNER_TASK;
-
- switch (task.Status)
- {
- // If the outer task did not complete successfully, then record the
- // cancellation/fault information to tcs.Task.
- case TaskStatus.Canceled:
- case TaskStatus.Faulted:
- bool result = TrySetFromTask(task, _lookForOce);
- Debug.Assert(result, "Expected TrySetFromTask from outer task to succeed");
- break;
-
- // Otherwise, process the inner task it returned.
- case TaskStatus.RanToCompletion:
- ProcessInnerTask(task is Task<Task<TResult>> taskOfTaskOfTResult ? // it's either a Task<Task> or Task<Task<TResult>>
- taskOfTaskOfTResult.Result : ((Task<Task>)task).Result);
- break;
- }
- }
-
- /// <summary>Transfer the completion status from "task" to ourself.</summary>
- /// <param name="task">The source task whose results should be transfered to this.</param>
- /// <param name="lookForOce">Whether or not to look for OperationCanceledExceptions in task's exceptions if it faults.</param>
- /// <returns>true if the transfer was successful; otherwise, false.</returns>
- private bool TrySetFromTask(Task task, bool lookForOce)
- {
- Debug.Assert(task != null && task.IsCompleted, "TrySetFromTask: Expected task to have completed.");
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationRelation(this, CausalityRelation.Join);
-
- bool result = false;
- switch (task.Status)
- {
- case TaskStatus.Canceled:
- result = TrySetCanceled(task.CancellationToken, task.GetCancellationExceptionDispatchInfo());
- break;
-
- case TaskStatus.Faulted:
- ReadOnlyCollection<ExceptionDispatchInfo> edis = task.GetExceptionDispatchInfos();
- ExceptionDispatchInfo oceEdi;
- if (lookForOce && edis.Count > 0 &&
- (oceEdi = edis[0]) != null &&
- oceEdi.SourceException is OperationCanceledException oce)
- {
- result = TrySetCanceled(oce.CancellationToken, oceEdi);
- }
- else
- {
- result = TrySetException(edis);
- }
- break;
-
- case TaskStatus.RanToCompletion:
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Completed);
-
- if (Task.s_asyncDebuggingEnabled)
- RemoveFromActiveTasks(this);
-
- result = TrySetResult(task is Task<TResult> taskTResult ? taskTResult.Result : default);
- break;
- }
- return result;
- }
-
- /// <summary>
- /// Processes the inner task of a Task{Task} or Task{Task{TResult}},
- /// transferring the appropriate results to ourself.
- /// </summary>
- /// <param name="task">The inner task returned by the task provided by the user.</param>
- private void ProcessInnerTask(Task? task)
- {
- // If the inner task is null, the proxy should be canceled.
- if (task == null)
- {
- TrySetCanceled(default);
- _state = STATE_DONE; // ... and record that we are done
- }
-
- // Fast path for if the inner task is already completed
- else if (task.IsCompleted)
- {
- TrySetFromTask(task, lookForOce: false);
- _state = STATE_DONE; // ... and record that we are done
- }
-
- // The inner task exists but is not yet complete, so when it does complete,
- // take some action to set our completion state.
- else
- {
- task.AddCompletionAction(this);
- // We'll record that we are done when Invoke() is called.
- }
- }
-
- public bool InvokeMayRunArbitraryCode => true;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskAsyncEnumerableExtensions.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskAsyncEnumerableExtensions.cs
deleted file mode 100644
index 57aab524485..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskAsyncEnumerableExtensions.cs
+++ /dev/null
@@ -1,38 +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 System.Collections.Generic;
-using System.Runtime.CompilerServices;
-
-namespace System.Threading.Tasks
-{
- /// <summary>Provides a set of static methods for configuring <see cref="Task"/>-related behaviors on asynchronous enumerables and disposables.</summary>
- public static class TaskAsyncEnumerableExtensions
- {
- /// <summary>Configures how awaits on the tasks returned from an async disposable will be performed.</summary>
- /// <param name="source">The source async disposable.</param>
- /// <param name="continueOnCapturedContext">Whether to capture and marshal back to the current context.</param>
- /// <returns>The configured async disposable.</returns>
- public static ConfiguredAsyncDisposable ConfigureAwait(this IAsyncDisposable source, bool continueOnCapturedContext) =>
- new ConfiguredAsyncDisposable(source, continueOnCapturedContext);
-
- /// <summary>Configures how awaits on the tasks returned from an async iteration will be performed.</summary>
- /// <typeparam name="T">The type of the objects being iterated.</typeparam>
- /// <param name="source">The source enumerable being iterated.</param>
- /// <param name="continueOnCapturedContext">Whether to capture and marshal back to the current context.</param>
- /// <returns>The configured enumerable.</returns>
- public static ConfiguredCancelableAsyncEnumerable<T> ConfigureAwait<T>(
- this IAsyncEnumerable<T> source, bool continueOnCapturedContext) =>
- new ConfiguredCancelableAsyncEnumerable<T>(source, continueOnCapturedContext, cancellationToken: default);
-
- /// <summary>Sets the <see cref="CancellationToken"/> to be passed to <see cref="IAsyncEnumerable{T}.GetAsyncEnumerator(CancellationToken)"/> when iterating.</summary>
- /// <typeparam name="T">The type of the objects being iterated.</typeparam>
- /// <param name="source">The source enumerable being iterated.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
- /// <returns>The configured enumerable.</returns>
- public static ConfiguredCancelableAsyncEnumerable<T> WithCancellation<T>(
- this IAsyncEnumerable<T> source, CancellationToken cancellationToken) =>
- new ConfiguredCancelableAsyncEnumerable<T>(source, continueOnCapturedContext: true, cancellationToken);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCanceledException.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCanceledException.cs
deleted file mode 100644
index 10b0ae9a3d0..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCanceledException.cs
+++ /dev/null
@@ -1,97 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// An exception for task cancellations.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Runtime.Serialization;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// Represents an exception used to communicate task cancellation.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class TaskCanceledException : OperationCanceledException
- {
- [NonSerialized]
- private readonly Task? _canceledTask; // The task which has been canceled.
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.Tasks.TaskCanceledException"/> class.
- /// </summary>
- public TaskCanceledException() : base(SR.TaskCanceledException_ctor_DefaultMessage)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.Tasks.TaskCanceledException"/>
- /// class with a specified error message.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- public TaskCanceledException(string? message) : base(message)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.Tasks.TaskCanceledException"/>
- /// class with a specified error message and a reference to the inner exception that is the cause of
- /// this exception.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- /// <param name="innerException">The exception that is the cause of the current exception.</param>
- public TaskCanceledException(string? message, Exception? innerException) : base(message, innerException)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.Tasks.TaskCanceledException"/>
- /// class with a specified error message, a reference to the inner exception that is the cause of
- /// this exception, and the <see cref="CancellationToken"/> that triggered the cancellation.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- /// <param name="innerException">The exception that is the cause of the current exception.</param>
- /// <param name="token">The <see cref="CancellationToken"/> that triggered the cancellation.</param>
- public TaskCanceledException(string? message, Exception? innerException, CancellationToken token) : base(message, innerException, token)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.Tasks.TaskCanceledException"/> class
- /// with a reference to the <see cref="System.Threading.Tasks.Task"/> that has been canceled.
- /// </summary>
- /// <param name="task">A task that has been canceled.</param>
- public TaskCanceledException(Task? task) :
- base(SR.TaskCanceledException_ctor_DefaultMessage, task != null ? task.CancellationToken : CancellationToken.None)
- {
- _canceledTask = task;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.Tasks.TaskCanceledException"/>
- /// class with serialized data.
- /// </summary>
- /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
- /// <param name="context">The <see cref="System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination. </param>
- protected TaskCanceledException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
-
- /// <summary>
- /// Gets the task associated with this exception.
- /// </summary>
- /// <remarks>
- /// It is permissible for no Task to be associated with a
- /// <see cref="System.Threading.Tasks.TaskCanceledException"/>, in which case
- /// this property will return null.
- /// </remarks>
- public Task? Task => _canceledTask;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCompletionSource.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCompletionSource.cs
deleted file mode 100644
index 28773c755ef..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCompletionSource.cs
+++ /dev/null
@@ -1,341 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// TaskCompletionSource<TResult> is the producer end of an unbound future. Its
-// Task member may be distributed as the consumer end of the future.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Collections.Generic;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// Represents the producer side of a <see cref="System.Threading.Tasks.Task{TResult}"/> unbound to a
- /// delegate, providing access to the consumer side through the <see cref="Task"/> property.
- /// </summary>
- /// <remarks>
- /// <para>
- /// It is often the case that a <see cref="System.Threading.Tasks.Task{TResult}"/> is desired to
- /// represent another asynchronous operation.
- /// <see cref="TaskCompletionSource{TResult}">TaskCompletionSource</see> is provided for this purpose. It enables
- /// the creation of a task that can be handed out to consumers, and those consumers can use the members
- /// of the task as they would any other. However, unlike most tasks, the state of a task created by a
- /// TaskCompletionSource is controlled explicitly by the methods on TaskCompletionSource. This enables the
- /// completion of the external asynchronous operation to be propagated to the underlying Task. The
- /// separation also ensures that consumers are not able to transition the state without access to the
- /// corresponding TaskCompletionSource.
- /// </para>
- /// <para>
- /// All members of <see cref="TaskCompletionSource{TResult}"/> are thread-safe
- /// and may be used from multiple threads concurrently.
- /// </para>
- /// </remarks>
- /// <typeparam name="TResult">The type of the result value associated with this <see
- /// cref="TaskCompletionSource{TResult}"/>.</typeparam>
- public class TaskCompletionSource<TResult>
- {
- private readonly Task<TResult> _task;
-
- /// <summary>
- /// Creates a <see cref="TaskCompletionSource{TResult}"/>.
- /// </summary>
- public TaskCompletionSource()
- {
- _task = new Task<TResult>();
- }
-
- /// <summary>
- /// Creates a <see cref="TaskCompletionSource{TResult}"/>
- /// with the specified options.
- /// </summary>
- /// <remarks>
- /// The <see cref="System.Threading.Tasks.Task{TResult}"/> created
- /// by this instance and accessible through its <see cref="Task"/> property
- /// will be instantiated using the specified <paramref name="creationOptions"/>.
- /// </remarks>
- /// <param name="creationOptions">The options to use when creating the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="creationOptions"/> represent options invalid for use
- /// with a <see cref="TaskCompletionSource{TResult}"/>.
- /// </exception>
- public TaskCompletionSource(TaskCreationOptions creationOptions)
- : this(null, creationOptions)
- {
- }
-
- /// <summary>
- /// Creates a <see cref="TaskCompletionSource{TResult}"/>
- /// with the specified state.
- /// </summary>
- /// <param name="state">The state to use as the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>'s AsyncState.</param>
- public TaskCompletionSource(object? state)
- : this(state, TaskCreationOptions.None)
- {
- }
-
- /// <summary>
- /// Creates a <see cref="TaskCompletionSource{TResult}"/> with
- /// the specified state and options.
- /// </summary>
- /// <param name="creationOptions">The options to use when creating the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="state">The state to use as the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>'s AsyncState.</param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The <paramref name="creationOptions"/> represent options invalid for use
- /// with a <see cref="TaskCompletionSource{TResult}"/>.
- /// </exception>
- public TaskCompletionSource(object? state, TaskCreationOptions creationOptions)
- {
- _task = new Task<TResult>(state, creationOptions);
- }
-
-
- /// <summary>
- /// Gets the <see cref="System.Threading.Tasks.Task{TResult}"/> created
- /// by this <see cref="TaskCompletionSource{TResult}"/>.
- /// </summary>
- /// <remarks>
- /// This property enables a consumer access to the <see
- /// cref="System.Threading.Tasks.Task{TResult}"/> that is controlled by this instance.
- /// The <see cref="SetResult"/>, <see cref="SetException(System.Exception)"/>,
- /// <see cref="SetException(System.Collections.Generic.IEnumerable{System.Exception})"/>, and <see cref="SetCanceled"/>
- /// methods (and their "Try" variants) on this instance all result in the relevant state
- /// transitions on this underlying Task.
- /// </remarks>
- public Task<TResult> Task => _task;
-
- /// <summary>Spins until the underlying task is completed.</summary>
- /// <remarks>This should only be called if the task is in the process of being completed by another thread.</remarks>
- private void SpinUntilCompleted()
- {
- // Spin wait until the completion is finalized by another thread.
- SpinWait sw = default;
- while (!_task.IsCompleted)
- sw.SpinOnce();
- }
-
- /// <summary>
- /// Attempts to transition the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> into the
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>
- /// state.
- /// </summary>
- /// <param name="exception">The exception to bind to this <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>True if the operation was successful; otherwise, false.</returns>
- /// <remarks>This operation will return false if the
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> is already in one
- /// of the three final states:
- /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">The <paramref name="exception"/> argument is null.</exception>
- /// <exception cref="System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
- public bool TrySetException(Exception exception)
- {
- if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
-
- bool rval = _task.TrySetException(exception);
- if (!rval && !_task.IsCompleted) SpinUntilCompleted();
- return rval;
- }
-
- /// <summary>
- /// Attempts to transition the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> into the
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>
- /// state.
- /// </summary>
- /// <param name="exceptions">The collection of exceptions to bind to this <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>True if the operation was successful; otherwise, false.</returns>
- /// <remarks>This operation will return false if the
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> is already in one
- /// of the three final states:
- /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
- /// </remarks>
- /// <exception cref="System.ArgumentNullException">The <paramref name="exceptions"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">There are one or more null elements in <paramref name="exceptions"/>.</exception>
- /// <exception cref="System.ArgumentException">The <paramref name="exceptions"/> collection is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
- public bool TrySetException(IEnumerable<Exception> exceptions)
- {
- if (exceptions == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exceptions);
-
- List<Exception> defensiveCopy = new List<Exception>();
- foreach (Exception e in exceptions)
- {
- if (e == null)
- ThrowHelper.ThrowArgumentException(ExceptionResource.TaskCompletionSourceT_TrySetException_NullException, ExceptionArgument.exceptions);
- defensiveCopy.Add(e);
- }
-
- if (defensiveCopy.Count == 0)
- ThrowHelper.ThrowArgumentException(ExceptionResource.TaskCompletionSourceT_TrySetException_NoExceptions, ExceptionArgument.exceptions);
-
- bool rval = _task.TrySetException(defensiveCopy);
- if (!rval && !_task.IsCompleted) SpinUntilCompleted();
- return rval;
- }
-
- /// <summary>
- /// Transitions the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> into the
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>
- /// state.
- /// </summary>
- /// <param name="exception">The exception to bind to this <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="exception"/> argument is null.</exception>
- /// <exception cref="System.InvalidOperationException">
- /// The underlying <see cref="System.Threading.Tasks.Task{TResult}"/> is already in one
- /// of the three final states:
- /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
- public void SetException(Exception exception)
- {
- if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
-
- if (!TrySetException(exception))
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted);
- }
- }
-
- /// <summary>
- /// Transitions the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> into the
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>
- /// state.
- /// </summary>
- /// <param name="exceptions">The collection of exceptions to bind to this <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="exceptions"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">There are one or more null elements in <paramref name="exceptions"/>.</exception>
- /// <exception cref="System.InvalidOperationException">
- /// The underlying <see cref="System.Threading.Tasks.Task{TResult}"/> is already in one
- /// of the three final states:
- /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
- public void SetException(IEnumerable<Exception> exceptions)
- {
- if (!TrySetException(exceptions))
- {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted);
- }
- }
-
-
- /// <summary>
- /// Attempts to transition the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> into the
- /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>
- /// state.
- /// </summary>
- /// <param name="result">The result value to bind to this <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>True if the operation was successful; otherwise, false.</returns>
- /// <remarks>This operation will return false if the
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> is already in one
- /// of the three final states:
- /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
- /// </remarks>
- /// <exception cref="System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
- public bool TrySetResult(TResult result)
- {
- bool rval = _task.TrySetResult(result);
- if (!rval) SpinUntilCompleted();
- return rval;
- }
-
- /// <summary>
- /// Transitions the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> into the
- /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>
- /// state.
- /// </summary>
- /// <param name="result">The result value to bind to this <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <exception cref="System.InvalidOperationException">
- /// The underlying <see cref="System.Threading.Tasks.Task{TResult}"/> is already in one
- /// of the three final states:
- /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
- public void SetResult(TResult result)
- {
- if (!TrySetResult(result))
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted);
- }
-
- /// <summary>
- /// Attempts to transition the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> into the
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>
- /// state.
- /// </summary>
- /// <returns>True if the operation was successful; otherwise, false.</returns>
- /// <remarks>This operation will return false if the
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> is already in one
- /// of the three final states:
- /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
- /// </remarks>
- /// <exception cref="System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
- public bool TrySetCanceled()
- {
- return TrySetCanceled(default);
- }
-
- // Enables a token to be stored into the canceled task
- public bool TrySetCanceled(CancellationToken cancellationToken)
- {
- bool rval = _task.TrySetCanceled(cancellationToken);
- if (!rval && !_task.IsCompleted) SpinUntilCompleted();
- return rval;
- }
-
- /// <summary>
- /// Transitions the underlying
- /// <see cref="System.Threading.Tasks.Task{TResult}"/> into the
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>
- /// state.
- /// </summary>
- /// <exception cref="System.InvalidOperationException">
- /// The underlying <see cref="System.Threading.Tasks.Task{TResult}"/> is already in one
- /// of the three final states:
- /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
- /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
- /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
- public void SetCanceled()
- {
- if (!TrySetCanceled())
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs
deleted file mode 100644
index c7ebe538662..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskContinuation.cs
+++ /dev/null
@@ -1,820 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Threading.Tasks
-{
- // Task type used to implement: Task ContinueWith(Action<Task,...>)
- internal sealed class ContinuationTaskFromTask : Task
- {
- private Task? m_antecedent;
-
- public ContinuationTaskFromTask(
- Task antecedent, Delegate action, object? state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions) :
- base(action, state, Task.InternalCurrentIfAttached(creationOptions), default, creationOptions, internalOptions, null)
- {
- Debug.Assert(action is Action<Task> || action is Action<Task, object?>,
- "Invalid delegate type in ContinuationTaskFromTask");
- m_antecedent = antecedent;
- }
-
- /// <summary>
- /// Evaluates the value selector of the Task which is passed in as an object and stores the result.
- /// </summary>
- internal override void InnerInvoke()
- {
- // Get and null out the antecedent. This is crucial to avoid a memory
- // leak with long chains of continuations.
- Task? antecedent = m_antecedent;
- Debug.Assert(antecedent != null,
- "No antecedent was set for the ContinuationTaskFromTask.");
- m_antecedent = null;
-
- // Notify the debugger we're completing an asynchronous wait on a task
- antecedent.NotifyDebuggerOfWaitCompletionIfNecessary();
-
- // Invoke the delegate
- Debug.Assert(m_action != null);
- if (m_action is Action<Task> action)
- {
- action(antecedent);
- return;
- }
-
- if (m_action is Action<Task, object?> actionWithState)
- {
- actionWithState(antecedent, m_stateObject);
- return;
- }
- Debug.Fail("Invalid m_action in ContinuationTaskFromTask");
- }
- }
-
- // Task type used to implement: Task<TResult> ContinueWith(Func<Task,...>)
- internal sealed class ContinuationResultTaskFromTask<TResult> : Task<TResult>
- {
- private Task? m_antecedent;
-
- public ContinuationResultTaskFromTask(
- Task antecedent, Delegate function, object? state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions) :
- base(function, state, Task.InternalCurrentIfAttached(creationOptions), default, creationOptions, internalOptions, null)
- {
- Debug.Assert(function is Func<Task, TResult> || function is Func<Task, object?, TResult>,
- "Invalid delegate type in ContinuationResultTaskFromTask");
- m_antecedent = antecedent;
- }
-
- /// <summary>
- /// Evaluates the value selector of the Task which is passed in as an object and stores the result.
- /// </summary>
- internal override void InnerInvoke()
- {
- // Get and null out the antecedent. This is crucial to avoid a memory
- // leak with long chains of continuations.
- Task? antecedent = m_antecedent;
- Debug.Assert(antecedent != null,
- "No antecedent was set for the ContinuationResultTaskFromTask.");
- m_antecedent = null;
-
- // Notify the debugger we're completing an asynchronous wait on a task
- antecedent.NotifyDebuggerOfWaitCompletionIfNecessary();
-
- // Invoke the delegate
- Debug.Assert(m_action != null);
- if (m_action is Func<Task, TResult> func)
- {
- m_result = func(antecedent);
- return;
- }
-
- if (m_action is Func<Task, object?, TResult> funcWithState)
- {
- m_result = funcWithState(antecedent, m_stateObject);
- return;
- }
- Debug.Fail("Invalid m_action in ContinuationResultTaskFromTask");
- }
- }
-
- // Task type used to implement: Task ContinueWith(Action<Task<TAntecedentResult>,...>)
- internal sealed class ContinuationTaskFromResultTask<TAntecedentResult> : Task
- {
- private Task<TAntecedentResult>? m_antecedent;
-
- public ContinuationTaskFromResultTask(
- Task<TAntecedentResult> antecedent, Delegate action, object? state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions) :
- base(action, state, Task.InternalCurrentIfAttached(creationOptions), default, creationOptions, internalOptions, null)
- {
- Debug.Assert(action is Action<Task<TAntecedentResult>> || action is Action<Task<TAntecedentResult>, object?>,
- "Invalid delegate type in ContinuationTaskFromResultTask");
- m_antecedent = antecedent;
- }
-
- /// <summary>
- /// Evaluates the value selector of the Task which is passed in as an object and stores the result.
- /// </summary>
- internal override void InnerInvoke()
- {
- // Get and null out the antecedent. This is crucial to avoid a memory
- // leak with long chains of continuations.
- Task<TAntecedentResult>? antecedent = m_antecedent;
- Debug.Assert(antecedent != null,
- "No antecedent was set for the ContinuationTaskFromResultTask.");
- m_antecedent = null;
-
- // Notify the debugger we're completing an asynchronous wait on a task
- antecedent.NotifyDebuggerOfWaitCompletionIfNecessary();
-
- // Invoke the delegate
- Debug.Assert(m_action != null);
- if (m_action is Action<Task<TAntecedentResult>> action)
- {
- action(antecedent);
- return;
- }
-
- if (m_action is Action<Task<TAntecedentResult>, object?> actionWithState)
- {
- actionWithState(antecedent, m_stateObject);
- return;
- }
- Debug.Fail("Invalid m_action in ContinuationTaskFromResultTask");
- }
- }
-
- // Task type used to implement: Task<TResult> ContinueWith(Func<Task<TAntecedentResult>,...>)
- internal sealed class ContinuationResultTaskFromResultTask<TAntecedentResult, TResult> : Task<TResult>
- {
- private Task<TAntecedentResult>? m_antecedent;
-
- public ContinuationResultTaskFromResultTask(
- Task<TAntecedentResult> antecedent, Delegate function, object? state, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions) :
- base(function, state, Task.InternalCurrentIfAttached(creationOptions), default, creationOptions, internalOptions, null)
- {
- Debug.Assert(function is Func<Task<TAntecedentResult>, TResult> || function is Func<Task<TAntecedentResult>, object?, TResult>,
- "Invalid delegate type in ContinuationResultTaskFromResultTask");
- m_antecedent = antecedent;
- }
-
- /// <summary>
- /// Evaluates the value selector of the Task which is passed in as an object and stores the result.
- /// </summary>
- internal override void InnerInvoke()
- {
- // Get and null out the antecedent. This is crucial to avoid a memory
- // leak with long chains of continuations.
- Task<TAntecedentResult>? antecedent = m_antecedent;
- Debug.Assert(antecedent != null,
- "No antecedent was set for the ContinuationResultTaskFromResultTask.");
- m_antecedent = null;
-
- // Notify the debugger we're completing an asynchronous wait on a task
- antecedent.NotifyDebuggerOfWaitCompletionIfNecessary();
-
- // Invoke the delegate
- Debug.Assert(m_action != null);
- if (m_action is Func<Task<TAntecedentResult>, TResult> func)
- {
- m_result = func(antecedent);
- return;
- }
-
- if (m_action is Func<Task<TAntecedentResult>, object?, TResult> funcWithState)
- {
- m_result = funcWithState(antecedent, m_stateObject);
- return;
- }
- Debug.Fail("Invalid m_action in ContinuationResultTaskFromResultTask");
- }
- }
-
- // For performance reasons, we don't just have a single way of representing
- // a continuation object. Rather, we have a hierarchy of types:
- // - TaskContinuation: abstract base that provides a virtual Run method
- // - StandardTaskContinuation: wraps a task,options,and scheduler, and overrides Run to process the task with that configuration
- // - AwaitTaskContinuation: base for continuations created through TaskAwaiter; targets default scheduler by default
- // - TaskSchedulerAwaitTaskContinuation: awaiting with a non-default TaskScheduler
- // - SynchronizationContextAwaitTaskContinuation: awaiting with a "current" sync ctx
-
- /// <summary>Represents a continuation.</summary>
- internal abstract class TaskContinuation
- {
- /// <summary>Inlines or schedules the continuation.</summary>
- /// <param name="completedTask">The antecedent task that has completed.</param>
- /// <param name="canInlineContinuationTask">true if inlining is permitted; otherwise, false.</param>
- internal abstract void Run(Task completedTask, bool canInlineContinuationTask);
-
- /// <summary>Tries to run the task on the current thread, if possible; otherwise, schedules it.</summary>
- /// <param name="task">The task to run</param>
- /// <param name="needsProtection">
- /// true if we need to protect against multiple threads racing to start/cancel the task; otherwise, false.
- /// </param>
- protected static void InlineIfPossibleOrElseQueue(Task task, bool needsProtection)
- {
- Debug.Assert(task != null);
- Debug.Assert(task.m_taskScheduler != null);
-
- // Set the TASK_STATE_STARTED flag. This only needs to be done
- // if the task may be canceled or if someone else has a reference to it
- // that may try to execute it.
- if (needsProtection)
- {
- if (!task.MarkStarted())
- return; // task has been previously started or canceled. Stop processing.
- }
- else
- {
- task.m_stateFlags |= Task.TASK_STATE_STARTED;
- }
-
- // Try to inline it but queue if we can't
- try
- {
- if (!task.m_taskScheduler.TryRunInline(task, taskWasPreviouslyQueued: false))
- {
- task.m_taskScheduler.InternalQueueTask(task);
- }
- }
- catch (Exception e)
- {
- // Either TryRunInline() or QueueTask() threw an exception. Record the exception, marking the task as Faulted.
- // However if it was a ThreadAbortException coming from TryRunInline we need to skip here,
- // because it would already have been handled in Task.Execute()
- TaskSchedulerException tse = new TaskSchedulerException(e);
- task.AddException(tse);
- task.Finish(false);
- // Don't re-throw.
- }
- }
-
- //
- // This helper routine is targeted by the debugger.
- //
- internal abstract Delegate[]? GetDelegateContinuationsForDebugger();
- }
-
- /// <summary>Provides the standard implementation of a task continuation.</summary>
- internal class StandardTaskContinuation : TaskContinuation
- {
- /// <summary>The unstarted continuation task.</summary>
- internal readonly Task m_task;
- /// <summary>The options to use with the continuation task.</summary>
- internal readonly TaskContinuationOptions m_options;
- /// <summary>The task scheduler with which to run the continuation task.</summary>
- private readonly TaskScheduler m_taskScheduler;
-
- /// <summary>Initializes a new continuation.</summary>
- /// <param name="task">The task to be activated.</param>
- /// <param name="options">The continuation options.</param>
- /// <param name="scheduler">The scheduler to use for the continuation.</param>
- internal StandardTaskContinuation(Task task, TaskContinuationOptions options, TaskScheduler scheduler)
- {
- Debug.Assert(task != null, "TaskContinuation ctor: task is null");
- Debug.Assert(scheduler != null, "TaskContinuation ctor: scheduler is null");
- m_task = task;
- m_options = options;
- m_taskScheduler = scheduler;
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(m_task, "Task.ContinueWith: " + task.m_action!.Method.Name);
-
- if (Task.s_asyncDebuggingEnabled)
- Task.AddToActiveTasks(m_task);
- }
-
- /// <summary>Invokes the continuation for the target completion task.</summary>
- /// <param name="completedTask">The completed task.</param>
- /// <param name="canInlineContinuationTask">Whether the continuation can be inlined.</param>
- internal override void Run(Task completedTask, bool canInlineContinuationTask)
- {
- Debug.Assert(completedTask != null);
- Debug.Assert(completedTask.IsCompleted, "ContinuationTask.Run(): completedTask not completed");
-
- // Check if the completion status of the task works with the desired
- // activation criteria of the TaskContinuationOptions.
- TaskContinuationOptions options = m_options;
- bool isRightKind =
- completedTask.IsCompletedSuccessfully ?
- (options & TaskContinuationOptions.NotOnRanToCompletion) == 0 :
- (completedTask.IsCanceled ?
- (options & TaskContinuationOptions.NotOnCanceled) == 0 :
- (options & TaskContinuationOptions.NotOnFaulted) == 0);
-
- // If the completion status is allowed, run the continuation.
- Task continuationTask = m_task;
- if (isRightKind)
- {
- // If the task was cancel before running (e.g a ContinueWhenAll with a cancelled caancelation token)
- // we will still flow it to ScheduleAndStart() were it will check the status before running
- // We check here to avoid faulty logs that contain a join event to an operation that was already set as completed.
- if (!continuationTask.IsCanceled && AsyncCausalityTracer.LoggingOn)
- {
- // Log now that we are sure that this continuation is being ran
- AsyncCausalityTracer.TraceOperationRelation(continuationTask, CausalityRelation.AssignDelegate);
- }
- continuationTask.m_taskScheduler = m_taskScheduler;
-
- // Either run directly or just queue it up for execution, depending
- // on whether synchronous or asynchronous execution is wanted.
- if (canInlineContinuationTask && // inlining is allowed by the caller
- (options & TaskContinuationOptions.ExecuteSynchronously) != 0) // synchronous execution was requested by the continuation's creator
- {
- InlineIfPossibleOrElseQueue(continuationTask, needsProtection: true);
- }
- else
- {
- try { continuationTask.ScheduleAndStart(needsProtection: true); }
- catch (TaskSchedulerException)
- {
- // No further action is necessary -- ScheduleAndStart() already transitioned the
- // task to faulted. But we want to make sure that no exception is thrown from here.
- }
- }
- }
- // Otherwise, the final state of this task does not match the desired
- // continuation activation criteria; cancel it to denote this.
- else continuationTask.InternalCancel(false);
- }
-
- internal override Delegate[]? GetDelegateContinuationsForDebugger()
- {
- if (m_task.m_action == null)
- {
- return m_task.GetDelegateContinuationsForDebugger();
- }
-
- return new Delegate[] { m_task.m_action };
- }
- }
-
- /// <summary>Task continuation for awaiting with a current synchronization context.</summary>
- internal sealed class SynchronizationContextAwaitTaskContinuation : AwaitTaskContinuation
- {
- /// <summary>SendOrPostCallback delegate to invoke the action.</summary>
- private static readonly SendOrPostCallback s_postCallback = state =>
- {
- Debug.Assert(state is Action);
- ((Action)state)();
- };
- /// <summary>Cached delegate for PostAction</summary>
- private static ContextCallback? s_postActionCallback;
- /// <summary>The context with which to run the action.</summary>
- private readonly SynchronizationContext m_syncContext;
-
- /// <summary>Initializes the SynchronizationContextAwaitTaskContinuation.</summary>
- /// <param name="context">The synchronization context with which to invoke the action. Must not be null.</param>
- /// <param name="action">The action to invoke. Must not be null.</param>
- /// <param name="flowExecutionContext">Whether to capture and restore ExecutionContext.</param>
- internal SynchronizationContextAwaitTaskContinuation(
- SynchronizationContext context, Action action, bool flowExecutionContext) :
- base(action, flowExecutionContext)
- {
- Debug.Assert(context != null);
- m_syncContext = context;
- }
-
- /// <summary>Inlines or schedules the continuation.</summary>
- /// <param name="task">The antecedent task, which is ignored.</param>
- /// <param name="canInlineContinuationTask">true if inlining is permitted; otherwise, false.</param>
- internal sealed override void Run(Task task, bool canInlineContinuationTask)
- {
- // If we're allowed to inline, run the action on this thread.
- if (canInlineContinuationTask &&
- m_syncContext == SynchronizationContext.Current)
- {
- RunCallback(GetInvokeActionCallback(), m_action, ref Task.t_currentTask);
- }
- // Otherwise, Post the action back to the SynchronizationContext.
- else
- {
- TplEventSource log = TplEventSource.Log;
- if (log.IsEnabled())
- {
- m_continuationId = Task.NewId();
- log.AwaitTaskContinuationScheduled((task.ExecutingTaskScheduler ?? TaskScheduler.Default).Id, task.Id, m_continuationId);
- }
- RunCallback(GetPostActionCallback(), this, ref Task.t_currentTask);
- }
- // Any exceptions will be handled by RunCallback.
- }
-
- /// <summary>Calls InvokeOrPostAction(false) on the supplied SynchronizationContextAwaitTaskContinuation.</summary>
- /// <param name="state">The SynchronizationContextAwaitTaskContinuation.</param>
- private static void PostAction(object? state)
- {
- Debug.Assert(state is SynchronizationContextAwaitTaskContinuation);
- var c = (SynchronizationContextAwaitTaskContinuation)state;
-
- TplEventSource log = TplEventSource.Log;
- if (log.TasksSetActivityIds && c.m_continuationId != 0)
- {
- c.m_syncContext.Post(s_postCallback, GetActionLogDelegate(c.m_continuationId, c.m_action));
- }
- else
- {
- c.m_syncContext.Post(s_postCallback, c.m_action); // s_postCallback is manually cached, as the compiler won't in a SecurityCritical method
- }
- }
-
- private static Action GetActionLogDelegate(int continuationId, Action action)
- {
- return () =>
- {
- Guid savedActivityId;
- Guid activityId = TplEventSource.CreateGuidForTaskID(continuationId);
- System.Diagnostics.Tracing.EventSource.SetCurrentThreadActivityId(activityId, out savedActivityId);
- try { action(); }
- finally { System.Diagnostics.Tracing.EventSource.SetCurrentThreadActivityId(savedActivityId); }
- };
- }
-
- /// <summary>Gets a cached delegate for the PostAction method.</summary>
- /// <returns>
- /// A delegate for PostAction, which expects a SynchronizationContextAwaitTaskContinuation
- /// to be passed as state.
- /// </returns>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static ContextCallback GetPostActionCallback() => s_postActionCallback ??= PostAction;
- }
-
- /// <summary>Task continuation for awaiting with a task scheduler.</summary>
- internal sealed class TaskSchedulerAwaitTaskContinuation : AwaitTaskContinuation
- {
- /// <summary>The scheduler on which to run the action.</summary>
- private readonly TaskScheduler m_scheduler;
-
- /// <summary>Initializes the TaskSchedulerAwaitTaskContinuation.</summary>
- /// <param name="scheduler">The task scheduler with which to invoke the action. Must not be null.</param>
- /// <param name="action">The action to invoke. Must not be null.</param>
- /// <param name="flowExecutionContext">Whether to capture and restore ExecutionContext.</param>
- internal TaskSchedulerAwaitTaskContinuation(
- TaskScheduler scheduler, Action action, bool flowExecutionContext) :
- base(action, flowExecutionContext)
- {
- Debug.Assert(scheduler != null);
- m_scheduler = scheduler;
- }
-
- /// <summary>Inlines or schedules the continuation.</summary>
- /// <param name="ignored">The antecedent task, which is ignored.</param>
- /// <param name="canInlineContinuationTask">true if inlining is permitted; otherwise, false.</param>
- internal sealed override void Run(Task ignored, bool canInlineContinuationTask)
- {
- // If we're targeting the default scheduler, we can use the faster path provided by the base class.
- if (m_scheduler == TaskScheduler.Default)
- {
- base.Run(ignored, canInlineContinuationTask);
- }
- else
- {
- // We permit inlining if the caller allows us to, and
- // either we're on a thread pool thread (in which case we're fine running arbitrary code)
- // or we're already on the target scheduler (in which case we'll just ask the scheduler
- // whether it's ok to run here). We include the IsThreadPoolThread check here, whereas
- // we don't in AwaitTaskContinuation.Run, since here it expands what's allowed as opposed
- // to in AwaitTaskContinuation.Run where it restricts what's allowed.
- bool inlineIfPossible = canInlineContinuationTask &&
- (TaskScheduler.InternalCurrent == m_scheduler || Thread.CurrentThread.IsThreadPoolThread);
-
- // Create the continuation task task. If we're allowed to inline, try to do so.
- // The target scheduler may still deny us from executing on this thread, in which case this'll be queued.
- Task task = CreateTask(state =>
- {
- try
- {
- ((Action)state!)();
- }
- catch (Exception exception)
- {
- Task.ThrowAsync(exception, targetContext: null);
- }
- }, m_action, m_scheduler);
-
- if (inlineIfPossible)
- {
- InlineIfPossibleOrElseQueue(task, needsProtection: false);
- }
- else
- {
- // We need to run asynchronously, so just schedule the task.
- try { task.ScheduleAndStart(needsProtection: false); }
- catch (TaskSchedulerException) { } // No further action is necessary, as ScheduleAndStart already transitioned task to faulted
- }
- }
- }
- }
-
- /// <summary>Base task continuation class used for await continuations.</summary>
- internal class AwaitTaskContinuation : TaskContinuation, IThreadPoolWorkItem
- {
- /// <summary>The ExecutionContext with which to run the continuation.</summary>
- private readonly ExecutionContext? m_capturedContext;
- /// <summary>The action to invoke.</summary>
- protected readonly Action m_action;
-
- protected int m_continuationId;
-
- /// <summary>Initializes the continuation.</summary>
- /// <param name="action">The action to invoke. Must not be null.</param>
- /// <param name="flowExecutionContext">Whether to capture and restore ExecutionContext.</param>
- internal AwaitTaskContinuation(Action action, bool flowExecutionContext)
- {
- Debug.Assert(action != null);
- m_action = action;
- if (flowExecutionContext)
- {
- m_capturedContext = ExecutionContext.Capture();
- }
- }
-
- /// <summary>Creates a task to run the action with the specified state on the specified scheduler.</summary>
- /// <param name="action">The action to run. Must not be null.</param>
- /// <param name="state">The state to pass to the action. Must not be null.</param>
- /// <param name="scheduler">The scheduler to target.</param>
- /// <returns>The created task.</returns>
- protected Task CreateTask(Action<object?> action, object? state, TaskScheduler scheduler)
- {
- Debug.Assert(action != null);
- Debug.Assert(scheduler != null);
-
- return new Task(
- action, state, null, default,
- TaskCreationOptions.None, InternalTaskOptions.QueuedByRuntime, scheduler)
- {
- CapturedContext = m_capturedContext
- };
- }
-
- /// <summary>Inlines or schedules the continuation onto the default scheduler.</summary>
- /// <param name="task">The antecedent task, which is ignored.</param>
- /// <param name="canInlineContinuationTask">true if inlining is permitted; otherwise, false.</param>
- internal override void Run(Task task, bool canInlineContinuationTask)
- {
- // For the base AwaitTaskContinuation, we allow inlining if our caller allows it
- // and if we're in a "valid location" for it. See the comments on
- // IsValidLocationForInlining for more about what's valid. For performance
- // reasons we would like to always inline, but we don't in some cases to avoid
- // running arbitrary amounts of work in suspected "bad locations", like UI threads.
- if (canInlineContinuationTask && IsValidLocationForInlining)
- {
- RunCallback(GetInvokeActionCallback(), m_action, ref Task.t_currentTask); // any exceptions from m_action will be handled by s_callbackRunAction
- }
- else
- {
- TplEventSource log = TplEventSource.Log;
- if (log.IsEnabled())
- {
- m_continuationId = Task.NewId();
- log.AwaitTaskContinuationScheduled((task.ExecutingTaskScheduler ?? TaskScheduler.Default).Id, task.Id, m_continuationId);
- }
-
- // We couldn't inline, so now we need to schedule it
- ThreadPool.UnsafeQueueUserWorkItemInternal(this, preferLocal: true);
- }
- }
-
- /// <summary>
- /// Gets whether the current thread is an appropriate location to inline a continuation's execution.
- /// </summary>
- /// <remarks>
- /// Returns whether SynchronizationContext is null and we're in the default scheduler.
- /// If the await had a SynchronizationContext/TaskScheduler where it began and the
- /// default/ConfigureAwait(true) was used, then we won't be on this path. If, however,
- /// ConfigureAwait(false) was used, or the SynchronizationContext and TaskScheduler were
- /// naturally null/Default, then we might end up here. If we do, we need to make sure
- /// that we don't execute continuations in a place that isn't set up to handle them, e.g.
- /// running arbitrary amounts of code on the UI thread. It would be "correct", but very
- /// expensive, to always run the continuations asynchronously, incurring lots of context
- /// switches and allocations and locks and the like. As such, we employ the heuristic
- /// that if the current thread has a non-null SynchronizationContext or a non-default
- /// scheduler, then we better not run arbitrary continuations here.
- /// </remarks>
- internal static bool IsValidLocationForInlining
- {
- get
- {
- // If there's a SynchronizationContext, we'll be conservative and say
- // this is a bad location to inline.
- SynchronizationContext? ctx = SynchronizationContext.Current;
- if (ctx != null && ctx.GetType() != typeof(SynchronizationContext)) return false;
-
- // Similarly, if there's a non-default TaskScheduler, we'll be conservative
- // and say this is a bad location to inline.
- TaskScheduler? sched = TaskScheduler.InternalCurrent;
- return sched == null || sched == TaskScheduler.Default;
- }
- }
-
- void IThreadPoolWorkItem.Execute()
- {
- TplEventSource log = TplEventSource.Log;
- ExecutionContext? context = m_capturedContext;
-
- if (!log.IsEnabled() && context == null)
- {
- m_action();
- return;
- }
-
- Guid savedActivityId = default;
- if (log.TasksSetActivityIds && m_continuationId != 0)
- {
- Guid activityId = TplEventSource.CreateGuidForTaskID(m_continuationId);
- System.Diagnostics.Tracing.EventSource.SetCurrentThreadActivityId(activityId, out savedActivityId);
- }
- try
- {
- // We're not inside of a task, so t_currentTask doesn't need to be specially maintained.
- // We're on a thread pool thread with no higher-level callers, so exceptions can just propagate.
-
- ExecutionContext.CheckThreadPoolAndContextsAreDefault();
- // If there's no execution context or Default, just invoke the delegate as ThreadPool is on Default context.
- // We don't have to use ExecutionContext.Run for the Default context here as there is no extra processing after the delegate
- if (context == null || context.IsDefault)
- {
- m_action();
- }
- // If there is an execution context, get the cached delegate and run the action under the context.
- else
- {
- ExecutionContext.RunForThreadPoolUnsafe(context, s_invokeAction, m_action);
- }
-
- // ThreadPoolWorkQueue.Dispatch handles notifications and reset context back to default
- }
- finally
- {
- if (log.TasksSetActivityIds && m_continuationId != 0)
- {
- System.Diagnostics.Tracing.EventSource.SetCurrentThreadActivityId(savedActivityId);
- }
- }
- }
-
- /// <summary>Cached delegate that invokes an Action passed as an object parameter.</summary>
- private static readonly ContextCallback s_invokeContextCallback = (state) =>
- {
- Debug.Assert(state is Action);
- ((Action)state)();
- };
- private static readonly Action<Action> s_invokeAction = (action) => action();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- protected static ContextCallback GetInvokeActionCallback() => s_invokeContextCallback;
-
- /// <summary>Runs the callback synchronously with the provided state.</summary>
- /// <param name="callback">The callback to run.</param>
- /// <param name="state">The state to pass to the callback.</param>
- /// <param name="currentTask">A reference to Task.t_currentTask.</param>
- protected void RunCallback(ContextCallback callback, object? state, ref Task? currentTask)
- {
- Debug.Assert(callback != null);
- Debug.Assert(currentTask == Task.t_currentTask);
-
- // Pretend there's no current task, so that no task is seen as a parent
- // and TaskScheduler.Current does not reflect false information
- Task? prevCurrentTask = currentTask;
- try
- {
- if (prevCurrentTask != null) currentTask = null;
-
- ExecutionContext? context = m_capturedContext;
- if (context == null)
- {
- // If there's no captured context, just run the callback directly.
- callback(state);
- }
- else
- {
- // Otherwise, use the captured context to do so.
- ExecutionContext.RunInternal(context, callback, state);
- }
- }
- catch (Exception exception) // we explicitly do not request handling of dangerous exceptions like AVs
- {
- Task.ThrowAsync(exception, targetContext: null);
- }
- finally
- {
- // Restore the current task information
- if (prevCurrentTask != null) currentTask = prevCurrentTask;
- }
- }
-
- /// <summary>Invokes or schedules the action to be executed.</summary>
- /// <param name="action">The action to invoke or queue.</param>
- /// <param name="allowInlining">
- /// true to allow inlining, or false to force the action to run asynchronously.
- /// </param>
- /// <remarks>
- /// No ExecutionContext work is performed used. This method is only used in the
- /// case where a raw Action continuation delegate was stored into the Task, which
- /// only happens in Task.SetContinuationForAwait if execution context flow was disabled
- /// via using TaskAwaiter.UnsafeOnCompleted or a similar path.
- /// </remarks>
- internal static void RunOrScheduleAction(Action action, bool allowInlining)
- {
- ref Task? currentTask = ref Task.t_currentTask;
- Task? prevCurrentTask = currentTask;
-
- // If we're not allowed to run here, schedule the action
- if (!allowInlining || !IsValidLocationForInlining)
- {
- UnsafeScheduleAction(action, prevCurrentTask);
- return;
- }
-
- // Otherwise, run it, making sure that t_currentTask is null'd out appropriately during the execution
- try
- {
- if (prevCurrentTask != null) currentTask = null;
- action();
- }
- catch (Exception exception)
- {
- Task.ThrowAsync(exception, targetContext: null);
- }
- finally
- {
- if (prevCurrentTask != null) currentTask = prevCurrentTask;
- }
- }
-
- /// <summary>Invokes or schedules the action to be executed.</summary>
- /// <param name="box">The <see cref="IAsyncStateMachineBox"/> that needs to be invoked or queued.</param>
- /// <param name="allowInlining">
- /// true to allow inlining, or false to force the box's action to run asynchronously.
- /// </param>
- internal static void RunOrScheduleAction(IAsyncStateMachineBox box, bool allowInlining)
- {
- // Same logic as in the RunOrScheduleAction(Action, ...) overload, except invoking
- // box.Invoke instead of action().
-
- ref Task? currentTask = ref Task.t_currentTask;
- Task? prevCurrentTask = currentTask;
-
- // If we're not allowed to run here, schedule the action
- if (!allowInlining || !IsValidLocationForInlining)
- {
- // If logging is disabled, we can simply queue the box itself as a custom work
- // item, and its work item execution will just invoke its MoveNext. However, if
- // logging is enabled, there is pre/post-work we need to do around logging to
- // match what's done for other continuations, and that requires flowing additional
- // information into the continuation, which we don't want to burden other cases of the
- // box with... so, in that case we just delegate to the AwaitTaskContinuation-based
- // path that already handles this, albeit at the expense of allocating the ATC
- // object, and potentially forcing the box's delegate into existence, when logging
- // is enabled.
- if (TplEventSource.Log.IsEnabled())
- {
- UnsafeScheduleAction(box.MoveNextAction, prevCurrentTask);
- }
- else
- {
- ThreadPool.UnsafeQueueUserWorkItemInternal(box, preferLocal: true);
- }
- return;
- }
-
- // Otherwise, run it, making sure that t_currentTask is null'd out appropriately during the execution
- try
- {
- if (prevCurrentTask != null) currentTask = null;
- box.MoveNext();
- }
- catch (Exception exception)
- {
- Task.ThrowAsync(exception, targetContext: null);
- }
- finally
- {
- if (prevCurrentTask != null) currentTask = prevCurrentTask;
- }
- }
-
- /// <summary>Schedules the action to be executed. No ExecutionContext work is performed used.</summary>
- /// <param name="action">The action to invoke or queue.</param>
- /// <param name="task">The task scheduling the action.</param>
- internal static void UnsafeScheduleAction(Action action, Task? task)
- {
- AwaitTaskContinuation atc = new AwaitTaskContinuation(action, flowExecutionContext: false);
-
- TplEventSource log = TplEventSource.Log;
- if (log.IsEnabled() && task != null)
- {
- atc.m_continuationId = Task.NewId();
- log.AwaitTaskContinuationScheduled((task.ExecutingTaskScheduler ?? TaskScheduler.Default).Id, task.Id, atc.m_continuationId);
- }
-
- ThreadPool.UnsafeQueueUserWorkItemInternal(atc, preferLocal: true);
- }
-
- internal override Delegate[] GetDelegateContinuationsForDebugger()
- {
- Debug.Assert(m_action != null);
- return new Delegate[] { AsyncMethodBuilderCore.TryGetStateMachineForDebugger(m_action) };
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExceptionHolder.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExceptionHolder.cs
deleted file mode 100644
index f7edb3c6d92..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExceptionHolder.cs
+++ /dev/null
@@ -1,309 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// An abstraction for holding and aggregating exceptions.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.Runtime.ExceptionServices;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// An exception holder manages a list of exceptions for one particular task.
- /// It offers the ability to aggregate, but more importantly, also offers intrinsic
- /// support for propagating unhandled exceptions that are never observed. It does
- /// this by aggregating and calling UnobservedTaskException event event if the holder
- /// is ever GC'd without the holder's contents ever having been requested
- /// (e.g. by a Task.Wait, Task.get_Exception, etc).
- /// </summary>
- internal class TaskExceptionHolder
- {
- /// <summary>The task with which this holder is associated.</summary>
- private readonly Task m_task;
- /// <summary>
- /// The lazily-initialized list of faulting exceptions. Volatile
- /// so that it may be read to determine whether any exceptions were stored.
- /// </summary>
- private volatile List<ExceptionDispatchInfo>? m_faultExceptions;
- /// <summary>An exception that triggered the task to cancel.</summary>
- private ExceptionDispatchInfo? m_cancellationException;
- /// <summary>Whether the holder was "observed" and thus doesn't cause finalization behavior.</summary>
- private volatile bool m_isHandled;
-
- /// <summary>
- /// Creates a new holder; it will be registered for finalization.
- /// </summary>
- /// <param name="task">The task this holder belongs to.</param>
- internal TaskExceptionHolder(Task task)
- {
- Debug.Assert(task != null, "Expected a non-null task.");
- m_task = task;
- }
-
- /// <summary>
- /// A finalizer that repropagates unhandled exceptions.
- /// </summary>
- ~TaskExceptionHolder()
- {
- if (m_faultExceptions != null && !m_isHandled)
- {
- // We will only propagate if this is truly unhandled. The reason this could
- // ever occur is somewhat subtle: if a Task's exceptions are observed in some
- // other finalizer, and the Task was finalized before the holder, the holder
- // will have been marked as handled before even getting here.
-
- // Publish the unobserved exception and allow users to observe it
- AggregateException exceptionToThrow = new AggregateException(
- SR.TaskExceptionHolder_UnhandledException,
- m_faultExceptions);
- UnobservedTaskExceptionEventArgs ueea = new UnobservedTaskExceptionEventArgs(exceptionToThrow);
- TaskScheduler.PublishUnobservedTaskException(m_task, ueea);
- }
- }
-
- /// <summary>Gets whether the exception holder is currently storing any exceptions for faults.</summary>
- internal bool ContainsFaultList => m_faultExceptions != null;
-
- /// <summary>
- /// Add an exception to the holder. This will ensure the holder is
- /// in the proper state (handled/unhandled) depending on the list's contents.
- /// </summary>
- /// <param name="representsCancellation">
- /// Whether the exception represents a cancellation request (true) or a fault (false).
- /// </param>
- /// <param name="exceptionObject">
- /// An exception object (either an Exception, an ExceptionDispatchInfo,
- /// an IEnumerable{Exception}, or an IEnumerable{ExceptionDispatchInfo})
- /// to add to the list.
- /// </param>
- /// <remarks>
- /// Must be called under lock.
- /// </remarks>
- internal void Add(object exceptionObject, bool representsCancellation)
- {
- Debug.Assert(exceptionObject != null, "TaskExceptionHolder.Add(): Expected a non-null exceptionObject");
- Debug.Assert(
- exceptionObject is Exception || exceptionObject is IEnumerable<Exception> ||
- exceptionObject is ExceptionDispatchInfo || exceptionObject is IEnumerable<ExceptionDispatchInfo>,
- "TaskExceptionHolder.Add(): Expected Exception, IEnumerable<Exception>, ExceptionDispatchInfo, or IEnumerable<ExceptionDispatchInfo>");
-
- if (representsCancellation) SetCancellationException(exceptionObject);
- else AddFaultException(exceptionObject);
- }
-
- /// <summary>Sets the cancellation exception.</summary>
- /// <param name="exceptionObject">The cancellation exception.</param>
- /// <remarks>
- /// Must be called under lock.
- /// </remarks>
- private void SetCancellationException(object exceptionObject)
- {
- Debug.Assert(exceptionObject != null, "Expected exceptionObject to be non-null.");
-
- Debug.Assert(m_cancellationException == null,
- "Expected SetCancellationException to be called only once.");
- // Breaking this assumption will overwrite a previously OCE,
- // and implies something may be wrong elsewhere, since there should only ever be one.
-
- Debug.Assert(m_faultExceptions == null,
- "Expected SetCancellationException to be called before any faults were added.");
- // Breaking this assumption shouldn't hurt anything here, but it implies something may be wrong elsewhere.
- // If this changes, make sure to only conditionally mark as handled below.
-
- // Store the cancellation exception
- if (exceptionObject is OperationCanceledException oce)
- {
- m_cancellationException = ExceptionDispatchInfo.Capture(oce);
- }
- else
- {
- var edi = exceptionObject as ExceptionDispatchInfo;
- Debug.Assert(edi != null && edi.SourceException is OperationCanceledException,
- "Expected an OCE or an EDI that contained an OCE");
- m_cancellationException = edi;
- }
-
- // This is just cancellation, and there are no faults, so mark the holder as handled.
- MarkAsHandled(false);
- }
-
- /// <summary>Adds the exception to the fault list.</summary>
- /// <param name="exceptionObject">The exception to store.</param>
- /// <remarks>
- /// Must be called under lock.
- /// </remarks>
- private void AddFaultException(object exceptionObject)
- {
- Debug.Assert(exceptionObject != null, "AddFaultException(): Expected a non-null exceptionObject");
-
- // Initialize the exceptions list if necessary. The list should be non-null iff it contains exceptions.
- List<ExceptionDispatchInfo>? exceptions = m_faultExceptions;
- if (exceptions == null) m_faultExceptions = exceptions = new List<ExceptionDispatchInfo>(1);
- else Debug.Assert(exceptions.Count > 0, "Expected existing exceptions list to have > 0 exceptions.");
-
- // Handle Exception by capturing it into an ExceptionDispatchInfo and storing that
- if (exceptionObject is Exception exception)
- {
- exceptions.Add(ExceptionDispatchInfo.Capture(exception));
- }
- else
- {
- // Handle ExceptionDispatchInfo by storing it into the list
- if (exceptionObject is ExceptionDispatchInfo edi)
- {
- exceptions.Add(edi);
- }
- else
- {
- // Handle enumerables of exceptions by capturing each of the contained exceptions into an EDI and storing it
- if (exceptionObject is IEnumerable<Exception> exColl)
- {
-#if DEBUG
- int numExceptions = 0;
-#endif
- foreach (Exception exc in exColl)
- {
-#if DEBUG
- Debug.Assert(exc != null, "No exceptions should be null");
- numExceptions++;
-#endif
- exceptions.Add(ExceptionDispatchInfo.Capture(exc));
- }
-#if DEBUG
- Debug.Assert(numExceptions > 0, "Collection should contain at least one exception.");
-#endif
- }
- else
- {
- // Handle enumerables of EDIs by storing them directly
- if (exceptionObject is IEnumerable<ExceptionDispatchInfo> ediColl)
- {
- exceptions.AddRange(ediColl);
-#if DEBUG
- Debug.Assert(exceptions.Count > 0, "There should be at least one dispatch info.");
- foreach (ExceptionDispatchInfo tmp in exceptions)
- {
- Debug.Assert(tmp != null, "No dispatch infos should be null");
- }
-#endif
- }
- // Anything else is a programming error
- else
- {
- throw new ArgumentException(SR.TaskExceptionHolder_UnknownExceptionType, nameof(exceptionObject));
- }
- }
- }
- }
-
- if (exceptions.Count > 0)
- MarkAsUnhandled();
- }
-
- /// <summary>
- /// A private helper method that ensures the holder is considered
- /// unhandled, i.e. it is registered for finalization.
- /// </summary>
- private void MarkAsUnhandled()
- {
- // If a thread partially observed this thread's exceptions, we
- // should revert back to "not handled" so that subsequent exceptions
- // must also be seen. Otherwise, some could go missing. We also need
- // to reregister for finalization.
- if (m_isHandled)
- {
- GC.ReRegisterForFinalize(this);
- m_isHandled = false;
- }
- }
-
- /// <summary>
- /// A private helper method that ensures the holder is considered
- /// handled, i.e. it is not registered for finalization.
- /// </summary>
- /// <param name="calledFromFinalizer">Whether this is called from the finalizer thread.</param>
- internal void MarkAsHandled(bool calledFromFinalizer)
- {
- if (!m_isHandled)
- {
- if (!calledFromFinalizer)
- {
- GC.SuppressFinalize(this);
- }
-
- m_isHandled = true;
- }
- }
-
- /// <summary>
- /// Allocates a new aggregate exception and adds the contents of the list to
- /// it. By calling this method, the holder assumes exceptions to have been
- /// "observed", such that the finalization check will be subsequently skipped.
- /// </summary>
- /// <param name="calledFromFinalizer">Whether this is being called from a finalizer.</param>
- /// <param name="includeThisException">An extra exception to be included (optionally).</param>
- /// <returns>The aggregate exception to throw.</returns>
- internal AggregateException CreateExceptionObject(bool calledFromFinalizer, Exception? includeThisException)
- {
- List<ExceptionDispatchInfo>? exceptions = m_faultExceptions;
- Debug.Assert(exceptions != null, "Expected an initialized list.");
- Debug.Assert(exceptions.Count > 0, "Expected at least one exception.");
-
- // Mark as handled and aggregate the exceptions.
- MarkAsHandled(calledFromFinalizer);
-
- // If we're only including the previously captured exceptions,
- // return them immediately in an aggregate.
- if (includeThisException == null)
- return new AggregateException(exceptions);
-
- // Otherwise, the caller wants a specific exception to be included,
- // so return an aggregate containing that exception and the rest.
- Exception[] combinedExceptions = new Exception[exceptions.Count + 1];
- for (int i = 0; i < combinedExceptions.Length - 1; i++)
- {
- combinedExceptions[i] = exceptions[i].SourceException;
- }
- combinedExceptions[^1] = includeThisException;
- return new AggregateException(combinedExceptions);
- }
-
- /// <summary>
- /// Wraps the exception dispatch infos into a new read-only collection. By calling this method,
- /// the holder assumes exceptions to have been "observed", such that the finalization
- /// check will be subsequently skipped.
- /// </summary>
- internal ReadOnlyCollection<ExceptionDispatchInfo> GetExceptionDispatchInfos()
- {
- List<ExceptionDispatchInfo>? exceptions = m_faultExceptions;
- Debug.Assert(exceptions != null, "Expected an initialized list.");
- Debug.Assert(exceptions.Count > 0, "Expected at least one exception.");
- MarkAsHandled(false);
- return new ReadOnlyCollection<ExceptionDispatchInfo>(exceptions);
- }
-
- /// <summary>
- /// Gets the ExceptionDispatchInfo representing the singular exception
- /// that was the cause of the task's cancellation.
- /// </summary>
- /// <returns>
- /// The ExceptionDispatchInfo for the cancellation exception. May be null.
- /// </returns>
- internal ExceptionDispatchInfo? GetCancellationExceptionDispatchInfo()
- {
- ExceptionDispatchInfo? edi = m_cancellationException;
- Debug.Assert(edi == null || edi.SourceException is OperationCanceledException,
- "Expected the EDI to be for an OperationCanceledException");
- return edi;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExtensions.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExtensions.cs
deleted file mode 100644
index f6576912953..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskExtensions.cs
+++ /dev/null
@@ -1,48 +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.
-
-namespace System.Threading.Tasks
-{
- /// <summary>Provides a set of static methods for working with specific kinds of <see cref="Task"/> instances.</summary>
- public static class TaskExtensions
- {
- /// <summary>Creates a proxy <see cref="Task"/> that represents the asynchronous operation of a <see cref="Task{Task}"/>.</summary>
- /// <param name="task">The <see cref="Task{Task}"/> to unwrap.</param>
- /// <returns>A <see cref="Task"/> that represents the asynchronous operation of the provided <see cref="Task{Task}"/>.</returns>
- public static Task Unwrap(this Task<Task> task)
- {
- if (task == null)
- {
- throw new ArgumentNullException(nameof(task));
- }
-
- // If the task hasn't completed or was faulted/canceled, wrap it in an unwrap promise. Otherwise,
- // it completed successfully. Return its inner task to avoid unnecessary wrapping, or if the inner
- // task is null, return a canceled task to match the same semantics as CreateUnwrapPromise.
- return
- !task.IsCompletedSuccessfully ? Task.CreateUnwrapPromise<VoidTaskResult>(task, lookForOce: false) :
- task.Result ??
- Task.FromCanceled(new CancellationToken(true));
- }
-
- /// <summary>Creates a proxy <see cref="Task{TResult}"/> that represents the asynchronous operation of a wrapped <see cref="Task{TResult}"/>.</summary>
- /// <param name="task">The wrapped <see cref="Task{TResult}"/> to unwrap.</param>
- /// <returns>A <see cref="Task{TResult}"/> that represents the asynchronous operation of the provided wrapped <see cref="Task{TResult}"/>.</returns>
- public static Task<TResult> Unwrap<TResult>(this Task<Task<TResult>> task)
- {
- if (task == null)
- {
- throw new ArgumentNullException(nameof(task));
- }
-
- // If the task hasn't completed or was faulted/canceled, wrap it in an unwrap promise. Otherwise,
- // it completed successfully. Return its inner task to avoid unnecessary wrapping, or if the inner
- // task is null, return a canceled task to match the same semantics as CreateUnwrapPromise.
- return
- !task.IsCompletedSuccessfully ? Task.CreateUnwrapPromise<TResult>(task, lookForOce: false) :
- task.Result ??
- Task.FromCanceled<TResult>(new CancellationToken(true));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskFactory.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskFactory.cs
deleted file mode 100644
index c10aae54db5..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskFactory.cs
+++ /dev/null
@@ -1,3042 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// There are a plethora of common patterns for which Tasks are created. TaskFactory encodes
-// these patterns into helper methods. These helpers also pick up default configuration settings
-// applicable to the entire factory and configurable through its constructors.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// Provides support for creating and scheduling
- /// <see cref="System.Threading.Tasks.Task">Tasks</see>.
- /// </summary>
- /// <remarks>
- /// <para>
- /// There are many common patterns for which tasks are relevant. The <see cref="TaskFactory"/>
- /// class encodes some of these patterns into methods that pick up default settings, which are
- /// configurable through its constructors.
- /// </para>
- /// <para>
- /// A default instance of <see cref="TaskFactory"/> is available through the
- /// <see cref="System.Threading.Tasks.Task.Factory">Task.Factory</see> property.
- /// </para>
- /// </remarks>
- public class TaskFactory
- {
- // member variables
- private readonly CancellationToken m_defaultCancellationToken;
- private readonly TaskScheduler? m_defaultScheduler;
- private readonly TaskCreationOptions m_defaultCreationOptions;
- private readonly TaskContinuationOptions m_defaultContinuationOptions;
-
- private TaskScheduler DefaultScheduler => m_defaultScheduler ?? TaskScheduler.Current;
-
- // sister method to above property -- avoids a TLS lookup
- private TaskScheduler GetDefaultScheduler(Task? currTask)
- {
- return
- m_defaultScheduler ??
- (currTask != null && (currTask.CreationOptions & TaskCreationOptions.HideScheduler) == 0 ? currTask.ExecutingTaskScheduler! : // a "current" task must be executing, which means it must have a scheduler
- TaskScheduler.Default);
- }
-
- /* Constructors */
-
- // ctor parameters provide defaults for the factory, which can be overridden by options provided to
- // specific calls on the factory
-
-
- /// <summary>
- /// Initializes a <see cref="TaskFactory"/> instance with the default configuration.
- /// </summary>
- /// <remarks>
- /// This constructor creates a <see cref="TaskFactory"/> instance with a default configuration. The
- /// <see cref="TaskCreationOptions"/> property is initialized to
- /// <see cref="System.Threading.Tasks.TaskCreationOptions.None">TaskCreationOptions.None</see>, the
- /// <see cref="TaskContinuationOptions"/> property is initialized to <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.None">TaskContinuationOptions.None</see>,
- /// and the <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> property is
- /// initialized to the current scheduler (see <see
- /// cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>).
- /// </remarks>
- public TaskFactory()
- : this(default, TaskCreationOptions.None, TaskContinuationOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a <see cref="TaskFactory"/> instance with the specified configuration.
- /// </summary>
- /// <param name="cancellationToken">The default <see cref="CancellationToken"/> that will be assigned
- /// to tasks created by this <see cref="TaskFactory"/> unless another CancellationToken is explicitly specified
- /// while calling the factory methods.</param>
- /// <remarks>
- /// This constructor creates a <see cref="TaskFactory"/> instance with a default configuration. The
- /// <see cref="TaskCreationOptions"/> property is initialized to
- /// <see cref="System.Threading.Tasks.TaskCreationOptions.None">TaskCreationOptions.None</see>, the
- /// <see cref="TaskContinuationOptions"/> property is initialized to <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.None">TaskContinuationOptions.None</see>,
- /// and the <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> property is
- /// initialized to the current scheduler (see <see
- /// cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>).
- /// </remarks>
- public TaskFactory(CancellationToken cancellationToken)
- : this(cancellationToken, TaskCreationOptions.None, TaskContinuationOptions.None, null)
- {
- }
-
- /// <summary>
- /// Initializes a <see cref="TaskFactory"/> instance with the specified configuration.
- /// </summary>
- /// <param name="scheduler">
- /// The <see cref="System.Threading.Tasks.TaskScheduler">
- /// TaskScheduler</see> to use to schedule any tasks created with this TaskFactory. A null value
- /// indicates that the current TaskScheduler should be used.
- /// </param>
- /// <remarks>
- /// With this constructor, the
- /// <see cref="TaskCreationOptions"/> property is initialized to
- /// <see cref="System.Threading.Tasks.TaskCreationOptions.None">TaskCreationOptions.None</see>, the
- /// <see cref="TaskContinuationOptions"/> property is initialized to <see
- /// cref="System.Threading.Tasks.TaskContinuationOptions.None">TaskContinuationOptions.None</see>,
- /// and the <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> property is
- /// initialized to <paramref name="scheduler"/>, unless it's null, in which case the property is
- /// initialized to the current scheduler (see <see
- /// cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>).
- /// </remarks>
- public TaskFactory(TaskScheduler? scheduler) // null means to use TaskScheduler.Current
- : this(default, TaskCreationOptions.None, TaskContinuationOptions.None, scheduler)
- {
- }
-
- /// <summary>
- /// Initializes a <see cref="TaskFactory"/> instance with the specified configuration.
- /// </summary>
- /// <param name="creationOptions">
- /// The default <see cref="System.Threading.Tasks.TaskCreationOptions">
- /// TaskCreationOptions</see> to use when creating tasks with this TaskFactory.
- /// </param>
- /// <param name="continuationOptions">
- /// The default <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> to use when creating continuation tasks with this TaskFactory.
- /// </param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument or the <paramref name="continuationOptions"/>
- /// argument specifies an invalid value.
- /// </exception>
- /// <remarks>
- /// With this constructor, the
- /// <see cref="TaskCreationOptions"/> property is initialized to <paramref name="creationOptions"/>,
- /// the
- /// <see cref="TaskContinuationOptions"/> property is initialized to <paramref
- /// name="continuationOptions"/>, and the <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> property is initialized to the
- /// current scheduler (see <see
- /// cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>).
- /// </remarks>
- public TaskFactory(TaskCreationOptions creationOptions, TaskContinuationOptions continuationOptions)
- : this(default, creationOptions, continuationOptions, null)
- {
- }
-
- /// <summary>
- /// Initializes a <see cref="TaskFactory"/> instance with the specified configuration.
- /// </summary>
- /// <param name="cancellationToken">The default <see cref="CancellationToken"/> that will be assigned
- /// to tasks created by this <see cref="TaskFactory"/> unless another CancellationToken is explicitly specified
- /// while calling the factory methods.</param>
- /// <param name="creationOptions">
- /// The default <see cref="System.Threading.Tasks.TaskCreationOptions">
- /// TaskCreationOptions</see> to use when creating tasks with this TaskFactory.
- /// </param>
- /// <param name="continuationOptions">
- /// The default <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> to use when creating continuation tasks with this TaskFactory.
- /// </param>
- /// <param name="scheduler">
- /// The default <see cref="System.Threading.Tasks.TaskScheduler">
- /// TaskScheduler</see> to use to schedule any Tasks created with this TaskFactory. A null value
- /// indicates that TaskScheduler.Current should be used.
- /// </param>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument or the <paramref name="continuationOptions"/>
- /// argumentspecifies an invalid value.
- /// </exception>
- /// <remarks>
- /// With this constructor, the
- /// <see cref="TaskCreationOptions"/> property is initialized to <paramref name="creationOptions"/>,
- /// the
- /// <see cref="TaskContinuationOptions"/> property is initialized to <paramref
- /// name="continuationOptions"/>, and the <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> property is initialized to
- /// <paramref name="scheduler"/>, unless it's null, in which case the property is initialized to the
- /// current scheduler (see <see
- /// cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>).
- /// </remarks>
- public TaskFactory(CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskContinuationOptions continuationOptions, TaskScheduler? scheduler)
- {
- CheckMultiTaskContinuationOptions(continuationOptions);
- CheckCreationOptions(creationOptions);
-
- m_defaultCancellationToken = cancellationToken;
- m_defaultScheduler = scheduler;
- m_defaultCreationOptions = creationOptions;
- m_defaultContinuationOptions = continuationOptions;
- }
-
- internal static void CheckCreationOptions(TaskCreationOptions creationOptions)
- {
- // Check for validity of options
- if ((creationOptions &
- ~(TaskCreationOptions.AttachedToParent |
- TaskCreationOptions.DenyChildAttach |
- TaskCreationOptions.HideScheduler |
- TaskCreationOptions.LongRunning |
- TaskCreationOptions.PreferFairness |
- TaskCreationOptions.RunContinuationsAsynchronously)) != 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions);
- }
- }
-
- /* Properties */
-
- /// <summary>
- /// Gets the default <see cref="System.Threading.CancellationToken">CancellationToken</see> of this
- /// TaskFactory.
- /// </summary>
- /// <remarks>
- /// This property returns the default <see cref="CancellationToken"/> that will be assigned to all
- /// tasks created by this factory unless another CancellationToken value is explicitly specified
- /// during the call to the factory methods.
- /// </remarks>
- public CancellationToken CancellationToken => m_defaultCancellationToken;
-
- /// <summary>
- /// Gets the <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> of this
- /// TaskFactory.
- /// </summary>
- /// <remarks>
- /// This property returns the default scheduler for this factory. It will be used to schedule all
- /// tasks unless another scheduler is explicitly specified during calls to this factory's methods.
- /// If null, <see cref="System.Threading.Tasks.TaskScheduler.Current">TaskScheduler.Current</see>
- /// will be used.
- /// </remarks>
- public TaskScheduler? Scheduler => m_defaultScheduler;
-
- /// <summary>
- /// Gets the <see cref="System.Threading.Tasks.TaskCreationOptions">TaskCreationOptions
- /// </see> value of this TaskFactory.
- /// </summary>
- /// <remarks>
- /// This property returns the default creation options for this factory. They will be used to create all
- /// tasks unless other options are explicitly specified during calls to this factory's methods.
- /// </remarks>
- public TaskCreationOptions CreationOptions => m_defaultCreationOptions;
-
- /// <summary>
- /// Gets the <see cref="System.Threading.Tasks.TaskCreationOptions">TaskContinuationOptions
- /// </see> value of this TaskFactory.
- /// </summary>
- /// <remarks>
- /// This property returns the default continuation options for this factory. They will be used to create
- /// all continuation tasks unless other options are explicitly specified during calls to this factory's methods.
- /// </remarks>
- public TaskContinuationOptions ContinuationOptions => m_defaultContinuationOptions;
-
- //
- // StartNew methods
- //
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task">Task</see>.
- /// </summary>
- /// <param name="action">The action delegate to execute asynchronously.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref name="action"/>
- /// argument is null.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a Task using one of its constructors
- /// and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution. However,
- /// unless creation and scheduling must be separated, StartNew is the recommended
- /// approach for both simplicity and performance.
- /// </remarks>
- public Task StartNew(Action action)
- {
- Task? currTask = Task.InternalCurrent;
- return Task.InternalStartNew(currTask, action, null, m_defaultCancellationToken, GetDefaultScheduler(currTask),
- m_defaultCreationOptions, InternalTaskOptions.None);
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task">Task</see>.
- /// </summary>
- /// <param name="action">The action delegate to execute asynchronously.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref name="action"/>
- /// argument is null.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a Task using one of its constructors
- /// and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution. However,
- /// unless creation and scheduling must be separated, StartNew is the recommended
- /// approach for both simplicity and performance.
- /// </remarks>
- public Task StartNew(Action action, CancellationToken cancellationToken)
- {
- Task? currTask = Task.InternalCurrent;
- return Task.InternalStartNew(currTask, action, null, cancellationToken, GetDefaultScheduler(currTask),
- m_defaultCreationOptions, InternalTaskOptions.None);
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task">Task</see>.
- /// </summary>
- /// <param name="action">The action delegate to execute asynchronously.</param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task">Task.</see></param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="action"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a Task using one of its constructors and
- /// then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task StartNew(Action action, TaskCreationOptions creationOptions)
- {
- Task? currTask = Task.InternalCurrent;
- return Task.InternalStartNew(currTask, action, null, m_defaultCancellationToken, GetDefaultScheduler(currTask), creationOptions,
- InternalTaskOptions.None);
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task">Task</see>.
- /// </summary>
- /// <param name="action">The action delegate to execute asynchronously.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new <see cref="Task"/></param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task">Task.</see></param>
- /// <param name="scheduler">The <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created <see
- /// cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="action"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="scheduler"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a Task using one of its constructors and
- /// then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task StartNew(Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler)
- {
- return Task.InternalStartNew(
- Task.InternalCurrentIfAttached(creationOptions), action, null, cancellationToken, scheduler, creationOptions,
- InternalTaskOptions.None);
- }
-
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task">Task</see>.
- /// </summary>
- /// <param name="action">The action delegate to execute asynchronously.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="action"/>
- /// delegate.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="action"/>
- /// argument is null.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a Task using one of its constructors and
- /// then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task StartNew(Action<object?> action, object? state)
- {
- Task? currTask = Task.InternalCurrent;
- return Task.InternalStartNew(currTask, action, state, m_defaultCancellationToken, GetDefaultScheduler(currTask),
- m_defaultCreationOptions, InternalTaskOptions.None);
- }
-
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task">Task</see>.
- /// </summary>
- /// <param name="action">The action delegate to execute asynchronously.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="action"/>
- /// delegate.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new <see cref="Task"/></param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="action"/>
- /// argument is null.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a Task using one of its constructors and
- /// then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task StartNew(Action<object?> action, object? state, CancellationToken cancellationToken)
- {
- Task? currTask = Task.InternalCurrent;
- return Task.InternalStartNew(currTask, action, state, cancellationToken, GetDefaultScheduler(currTask),
- m_defaultCreationOptions, InternalTaskOptions.None);
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task">Task</see>.
- /// </summary>
- /// <param name="action">The action delegate to execute asynchronously.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="action"/>
- /// delegate.</param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task">Task.</see></param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="action"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a Task using one of its constructors and
- /// then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task StartNew(Action<object?> action, object? state, TaskCreationOptions creationOptions)
- {
- Task? currTask = Task.InternalCurrent;
- return Task.InternalStartNew(currTask, action, state, m_defaultCancellationToken, GetDefaultScheduler(currTask),
- creationOptions, InternalTaskOptions.None);
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task">Task</see>.
- /// </summary>
- /// <param name="action">The action delegate to execute asynchronously.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="action"/>
- /// delegate.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task">Task.</see></param>
- /// <param name="scheduler">The <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created <see
- /// cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="action"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="scheduler"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a Task using one of its constructors and
- /// then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task StartNew(Action<object?> action, object? state, CancellationToken cancellationToken,
- TaskCreationOptions creationOptions, TaskScheduler scheduler)
- {
- return Task.InternalStartNew(
- Task.InternalCurrentIfAttached(creationOptions), action, state, cancellationToken, scheduler,
- creationOptions, InternalTaskOptions.None);
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew<TResult>(Func<TResult> function)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, m_defaultCancellationToken,
- m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new <see cref="Task"/></param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew<TResult>(Func<TResult> function, CancellationToken cancellationToken)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, cancellationToken,
- m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew<TResult>(Func<TResult> function, TaskCreationOptions creationOptions)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, m_defaultCancellationToken,
- creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="scheduler">The <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created <see cref="System.Threading.Tasks.Task{TResult}">
- /// Task{TResult}</see>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="scheduler"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew<TResult>(Func<TResult> function, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler)
- {
- return Task<TResult>.StartNew(
- Task.InternalCurrentIfAttached(creationOptions), function, cancellationToken,
- creationOptions, InternalTaskOptions.None, scheduler);
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="function"/>
- /// delegate.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew<TResult>(Func<object?, TResult> function, object? state)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, state, m_defaultCancellationToken,
- m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="function"/>
- /// delegate.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new <see cref="Task"/></param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew<TResult>(Func<object?, TResult> function, object? state, CancellationToken cancellationToken)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, state, cancellationToken,
- m_defaultCreationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="function"/>
- /// delegate.</param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew<TResult>(Func<object?, TResult> function, object? state, TaskCreationOptions creationOptions)
- {
- Task? currTask = Task.InternalCurrent;
- return Task<TResult>.StartNew(currTask, function, state, m_defaultCancellationToken,
- creationOptions, InternalTaskOptions.None, GetDefaultScheduler(currTask));
- }
-
- /// <summary>
- /// Creates and starts a <see cref="System.Threading.Tasks.Task{TResult}"/>.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="function">A function delegate that returns the future result to be available through
- /// the <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="function"/>
- /// delegate.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> that will be assigned to the new task.</param>
- /// <param name="creationOptions">A TaskCreationOptions value that controls the behavior of the
- /// created
- /// <see cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <param name="scheduler">The <see
- /// cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created <see cref="System.Threading.Tasks.Task{TResult}">
- /// Task{TResult}</see>.</param>
- /// <returns>The started <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="function"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the <paramref
- /// name="scheduler"/>
- /// argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// Calling StartNew is functionally equivalent to creating a <see cref="Task{TResult}"/> using one
- /// of its constructors and then calling
- /// <see cref="System.Threading.Tasks.Task.Start()">Start</see> to schedule it for execution.
- /// However, unless creation and scheduling must be separated, StartNew is the recommended approach
- /// for both simplicity and performance.
- /// </remarks>
- public Task<TResult> StartNew<TResult>(Func<object?, TResult> function, object? state, CancellationToken cancellationToken,
- TaskCreationOptions creationOptions, TaskScheduler scheduler)
- {
- return Task<TResult>.StartNew(
- Task.InternalCurrentIfAttached(creationOptions), function, state, cancellationToken,
- creationOptions, InternalTaskOptions.None, scheduler);
- }
-
- //
- // FromAsync methods
- //
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task">Task</see> that executes an end method action
- /// when a specified <see cref="System.IAsyncResult">IAsyncResult</see> completes.
- /// </summary>
- /// <param name="asyncResult">The IAsyncResult whose completion should trigger the processing of the
- /// <paramref name="endMethod"/>.</param>
- /// <param name="endMethod">The action delegate that processes the completed <paramref
- /// name="asyncResult"/>.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="asyncResult"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>A <see cref="System.Threading.Tasks.Task">Task</see> that represents the asynchronous
- /// operation.</returns>
- public Task FromAsync(
- IAsyncResult asyncResult,
- Action<IAsyncResult> endMethod)
- {
- return FromAsync(asyncResult, endMethod, m_defaultCreationOptions, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task">Task</see> that executes an end method action
- /// when a specified <see cref="System.IAsyncResult">IAsyncResult</see> completes.
- /// </summary>
- /// <param name="asyncResult">The IAsyncResult whose completion should trigger the processing of the
- /// <paramref name="endMethod"/>.</param>
- /// <param name="endMethod">The action delegate that processes the completed <paramref
- /// name="asyncResult"/>.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="asyncResult"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>A <see cref="System.Threading.Tasks.Task">Task</see> that represents the asynchronous
- /// operation.</returns>
- public Task FromAsync(
- IAsyncResult asyncResult,
- Action<IAsyncResult> endMethod,
- TaskCreationOptions creationOptions)
- {
- return FromAsync(asyncResult, endMethod, creationOptions, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task">Task</see> that executes an end method action
- /// when a specified <see cref="System.IAsyncResult">IAsyncResult</see> completes.
- /// </summary>
- /// <param name="asyncResult">The IAsyncResult whose completion should trigger the processing of the
- /// <paramref name="endMethod"/>.</param>
- /// <param name="endMethod">The action delegate that processes the completed <paramref
- /// name="asyncResult"/>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the task that executes the end method.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="asyncResult"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>A <see cref="System.Threading.Tasks.Task">Task</see> that represents the asynchronous
- /// operation.</returns>
- public Task FromAsync(
- IAsyncResult asyncResult,
- Action<IAsyncResult> endMethod,
- TaskCreationOptions creationOptions,
- TaskScheduler scheduler)
- {
- return TaskFactory<VoidTaskResult>.FromAsyncImpl(asyncResult, null, endMethod, creationOptions, scheduler);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task">Task</see> that represents a pair of begin
- /// and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task">Task</see> that represents the
- /// asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task FromAsync(
- Func<AsyncCallback, object?, IAsyncResult> beginMethod,
- Action<IAsyncResult> endMethod,
- object? state)
- {
- return FromAsync(beginMethod, endMethod, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task">Task</see> that represents a pair of begin
- /// and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task">Task</see> that represents the
- /// asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task FromAsync(
- Func<AsyncCallback, object?, IAsyncResult> beginMethod,
- Action<IAsyncResult> endMethod, object? state, TaskCreationOptions creationOptions)
- {
- return TaskFactory<VoidTaskResult>.FromAsyncImpl(beginMethod, null, endMethod, state, creationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task">Task</see> that represents a pair of begin
- /// and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/>
- /// delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task">Task</see> that represents the
- /// asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task FromAsync<TArg1>(
- Func<TArg1, AsyncCallback, object?, IAsyncResult> beginMethod,
- Action<IAsyncResult> endMethod,
- TArg1 arg1,
- object? state)
- {
- return FromAsync(beginMethod, endMethod, arg1, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task">Task</see> that represents a pair of begin
- /// and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/>
- /// delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task">Task</see> that represents the
- /// asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task FromAsync<TArg1>(
- Func<TArg1, AsyncCallback, object?, IAsyncResult> beginMethod,
- Action<IAsyncResult> endMethod,
- TArg1 arg1, object? state, TaskCreationOptions creationOptions)
- {
- return TaskFactory<VoidTaskResult>.FromAsyncImpl(beginMethod, null, endMethod, arg1, state, creationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task">Task</see> that represents a pair of begin
- /// and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task">Task</see> that represents the
- /// asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task FromAsync<TArg1, TArg2>(
- Func<TArg1, TArg2, AsyncCallback, object?, IAsyncResult> beginMethod,
- Action<IAsyncResult> endMethod,
- TArg1 arg1, TArg2 arg2, object? state)
- {
- return FromAsync(beginMethod, endMethod, arg1, arg2, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task">Task</see> that represents a pair of begin
- /// and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task">Task</see> that represents the
- /// asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task FromAsync<TArg1, TArg2>(
- Func<TArg1, TArg2, AsyncCallback, object?, IAsyncResult> beginMethod,
- Action<IAsyncResult> endMethod,
- TArg1 arg1, TArg2 arg2, object? state, TaskCreationOptions creationOptions)
- {
- return TaskFactory<VoidTaskResult>.FromAsyncImpl(beginMethod, null, endMethod, arg1, arg2, state, creationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task">Task</see> that represents a pair of begin
- /// and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TArg3">The type of the third argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg3">The third argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task">Task</see> that represents the
- /// asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task FromAsync<TArg1, TArg2, TArg3>(
- Func<TArg1, TArg2, TArg3, AsyncCallback, object?, IAsyncResult> beginMethod,
- Action<IAsyncResult> endMethod,
- TArg1 arg1, TArg2 arg2, TArg3 arg3, object? state)
- {
- return FromAsync(beginMethod, endMethod, arg1, arg2, arg3, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task">Task</see> that represents a pair of begin
- /// and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TArg3">The type of the third argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg3">The third argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task">Task</see> that represents the
- /// asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task FromAsync<TArg1, TArg2, TArg3>(
- Func<TArg1, TArg2, TArg3, AsyncCallback, object?, IAsyncResult> beginMethod,
- Action<IAsyncResult> endMethod,
- TArg1 arg1, TArg2 arg2, TArg3 arg3, object? state, TaskCreationOptions creationOptions)
- {
- return TaskFactory<VoidTaskResult>.FromAsyncImpl<TArg1, TArg2, TArg3>(beginMethod, null, endMethod, arg1, arg2, arg3, state, creationOptions);
- }
-
- //
- // Additional FromAsync() overloads used for inferencing convenience
- //
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that executes an end
- /// method function when a specified <see cref="System.IAsyncResult">IAsyncResult</see> completes.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="asyncResult">The IAsyncResult whose completion should trigger the processing of the
- /// <paramref name="endMethod"/>.</param>
- /// <param name="endMethod">The function delegate that processes the completed <paramref
- /// name="asyncResult"/>.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="asyncResult"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>A <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents the
- /// asynchronous operation.</returns>
- public Task<TResult> FromAsync<TResult>(
- IAsyncResult asyncResult, Func<IAsyncResult, TResult> endMethod)
- {
- return TaskFactory<TResult>.FromAsyncImpl(asyncResult, endMethod, null, m_defaultCreationOptions, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that executes an end
- /// method function when a specified <see cref="System.IAsyncResult">IAsyncResult</see> completes.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="asyncResult">The IAsyncResult whose completion should trigger the processing of the
- /// <paramref name="endMethod"/>.</param>
- /// <param name="endMethod">The function delegate that processes the completed <paramref
- /// name="asyncResult"/>.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="asyncResult"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>A <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents the
- /// asynchronous operation.</returns>
- public Task<TResult> FromAsync<TResult>(
- IAsyncResult asyncResult, Func<IAsyncResult, TResult> endMethod, TaskCreationOptions creationOptions)
- {
- return TaskFactory<TResult>.FromAsyncImpl(asyncResult, endMethod, null, creationOptions, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that executes an end
- /// method function when a specified <see cref="System.IAsyncResult">IAsyncResult</see> completes.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="asyncResult">The IAsyncResult whose completion should trigger the processing of the
- /// <paramref name="endMethod"/>.</param>
- /// <param name="endMethod">The function delegate that processes the completed <paramref
- /// name="asyncResult"/>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the task that executes the end method.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="asyncResult"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>A <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents the
- /// asynchronous operation.</returns>
- public Task<TResult> FromAsync<TResult>(
- IAsyncResult asyncResult, Func<IAsyncResult, TResult> endMethod, TaskCreationOptions creationOptions, TaskScheduler scheduler)
- {
- return TaskFactory<TResult>.FromAsyncImpl(asyncResult, endMethod, null, creationOptions, scheduler);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TResult>(
- Func<AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod, object? state)
- {
- return TaskFactory<TResult>.FromAsyncImpl(beginMethod, endMethod, null, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TResult>(
- Func<AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod, object? state, TaskCreationOptions creationOptions)
- {
- return TaskFactory<TResult>.FromAsyncImpl(beginMethod, endMethod, null, state, creationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1, TResult>(
- Func<TArg1, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod, TArg1 arg1, object? state)
- {
- return TaskFactory<TResult>.FromAsyncImpl(beginMethod, endMethod, null, arg1, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1, TResult>(Func<TArg1, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod, TArg1 arg1, object? state, TaskCreationOptions creationOptions)
- {
- return TaskFactory<TResult>.FromAsyncImpl(beginMethod, endMethod, null, arg1, state, creationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1, TArg2, TResult>(Func<TArg1, TArg2, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod, TArg1 arg1, TArg2 arg2, object? state)
- {
- return TaskFactory<TResult>.FromAsyncImpl(beginMethod, endMethod, null, arg1, arg2, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1, TArg2, TResult>(
- Func<TArg1, TArg2, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod, TArg1 arg1, TArg2 arg2, object? state, TaskCreationOptions creationOptions)
- {
- return TaskFactory<TResult>.FromAsyncImpl(beginMethod, endMethod, null, arg1, arg2, state, creationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TArg3">The type of the third argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg3">The third argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1, TArg2, TArg3, TResult>(
- Func<TArg1, TArg2, TArg3, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod, TArg1 arg1, TArg2 arg2, TArg3 arg3, object? state)
- {
- return TaskFactory<TResult>.FromAsyncImpl(beginMethod, endMethod, null, arg1, arg2, arg3, state, m_defaultCreationOptions);
- }
-
- /// <summary>
- /// Creates a <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that represents a pair of
- /// begin and end methods that conform to the Asynchronous Programming Model pattern.
- /// </summary>
- /// <typeparam name="TArg1">The type of the first argument passed to the <paramref
- /// name="beginMethod"/> delegate.</typeparam>
- /// <typeparam name="TArg2">The type of the second argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TArg3">The type of the third argument passed to <paramref name="beginMethod"/>
- /// delegate.</typeparam>
- /// <typeparam name="TResult">The type of the result available through the
- /// <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.
- /// </typeparam>
- /// <param name="beginMethod">The delegate that begins the asynchronous operation.</param>
- /// <param name="endMethod">The delegate that ends the asynchronous operation.</param>
- /// <param name="arg1">The first argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg2">The second argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="arg3">The third argument passed to the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <param name="creationOptions">The TaskCreationOptions value that controls the behavior of the
- /// created <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="state">An object containing data to be used by the <paramref name="beginMethod"/>
- /// delegate.</param>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="beginMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="endMethod"/> argument is null.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="creationOptions"/> argument specifies an invalid TaskCreationOptions
- /// value.</exception>
- /// <returns>The created <see cref="System.Threading.Tasks.Task{TResult}">Task</see> that
- /// represents the asynchronous operation.</returns>
- /// <remarks>
- /// This method throws any exceptions thrown by the <paramref name="beginMethod"/>.
- /// </remarks>
- public Task<TResult> FromAsync<TArg1, TArg2, TArg3, TResult>(
- Func<TArg1, TArg2, TArg3, AsyncCallback, object?, IAsyncResult> beginMethod,
- Func<IAsyncResult, TResult> endMethod, TArg1 arg1, TArg2 arg2, TArg3 arg3, object? state, TaskCreationOptions creationOptions)
- {
- return TaskFactory<TResult>.FromAsyncImpl(beginMethod, endMethod, null, arg1, arg2, arg3, state, creationOptions);
- }
-
- /// <summary>
- /// Check validity of options passed to FromAsync method
- /// </summary>
- /// <param name="creationOptions">The options to be validated.</param>
- /// <param name="hasBeginMethod">determines type of FromAsync method that called this method</param>
- internal static void CheckFromAsyncOptions(TaskCreationOptions creationOptions, bool hasBeginMethod)
- {
- if (hasBeginMethod)
- {
- // Options detected here cause exceptions in FromAsync methods that take beginMethod as a parameter
- if ((creationOptions & TaskCreationOptions.LongRunning) != 0)
- throw new ArgumentOutOfRangeException(nameof(creationOptions), SR.Task_FromAsync_LongRunning);
- if ((creationOptions & TaskCreationOptions.PreferFairness) != 0)
- throw new ArgumentOutOfRangeException(nameof(creationOptions), SR.Task_FromAsync_PreferFairness);
- }
-
- // Check for general validity of options
- if ((creationOptions &
- ~(TaskCreationOptions.AttachedToParent |
- TaskCreationOptions.DenyChildAttach |
- TaskCreationOptions.HideScheduler |
- TaskCreationOptions.PreferFairness |
- TaskCreationOptions.LongRunning)) != 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions);
- }
- }
-
-
- //
- // ContinueWhenAll methods
- //
-
- // A Task<Task[]> that, given an initial collection of N tasks, will complete when
- // it has been invoked N times. This allows us to replace this logic:
- // Task<Task[]> promise = new Task<Task[]>(...);
- // int _count = tasksCopy.Length;
- // Action<Task> completionAction = delegate {if (Interlocked.Decrement(ref _count) == 0) promise.TrySetResult(tasksCopy);
- // for (int i=0; i<_count; i++)
- // tasksCopy[i].AddCompletionAction(completionAction);
- // with this logic:
- // CompletionOnCountdownPromise promise = new CompletionOnCountdownPromise(tasksCopy);
- // for (int i=0; i<tasksCopy.Length; i++) tasksCopy[i].AddCompletionAction(promise);
- // which saves a few allocations.
- //
- // Used in TaskFactory.CommonCWAllLogic(Task[]), below.
- private sealed class CompleteOnCountdownPromise : Task<Task[]>, ITaskCompletionAction
- {
- private readonly Task[] _tasks;
- private int _count;
-
- internal CompleteOnCountdownPromise(Task[] tasksCopy)
- {
- Debug.Assert((tasksCopy != null) && (tasksCopy.Length > 0), "Expected non-null task array with at least one element in it");
- _tasks = tasksCopy;
- _count = tasksCopy.Length;
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(this, "TaskFactory.ContinueWhenAll");
-
- if (Task.s_asyncDebuggingEnabled)
- AddToActiveTasks(this);
- }
-
- public void Invoke(Task completingTask)
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationRelation(this, CausalityRelation.Join);
-
- if (completingTask.IsWaitNotificationEnabled) this.SetNotificationForWaitCompletion(enabled: true);
- if (Interlocked.Decrement(ref _count) == 0)
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Completed);
-
- if (Task.s_asyncDebuggingEnabled)
- RemoveFromActiveTasks(this);
-
- TrySetResult(_tasks);
- }
- Debug.Assert(_count >= 0, "Count should never go below 0");
- }
-
- public bool InvokeMayRunArbitraryCode => true;
-
- /// <summary>
- /// Returns whether we should notify the debugger of a wait completion. This returns
- /// true iff at least one constituent task has its bit set.
- /// </summary>
- internal override bool ShouldNotifyDebuggerOfWaitCompletion =>
- base.ShouldNotifyDebuggerOfWaitCompletion &&
- AnyTaskRequiresNotifyDebuggerOfWaitCompletion(_tasks);
- }
-
- // Performs some logic common to all ContinueWhenAll() overloads
- internal static Task<Task[]> CommonCWAllLogic(Task[] tasksCopy)
- {
- Debug.Assert(tasksCopy != null);
-
- // Create a promise task to be returned to the user
- CompleteOnCountdownPromise promise = new CompleteOnCountdownPromise(tasksCopy);
-
- for (int i = 0; i < tasksCopy.Length; i++)
- {
- if (tasksCopy[i].IsCompleted) promise.Invoke(tasksCopy[i]); // Short-circuit the completion action, if possible
- else tasksCopy[i].AddCompletionAction(promise); // simple completion action
- }
-
- return promise;
- }
-
-
- // A Task<Task<T>[]> that, given an initial collection of N tasks, will complete when
- // it has been invoked N times. See comments for non-generic CompleteOnCountdownPromise class.
- //
- // Used in TaskFactory.CommonCWAllLogic<TResult>(Task<TResult>[]), below.
- private sealed class CompleteOnCountdownPromise<T> : Task<Task<T>[]>, ITaskCompletionAction
- {
- private readonly Task<T>[] _tasks;
- private int _count;
-
- internal CompleteOnCountdownPromise(Task<T>[] tasksCopy)
- {
- Debug.Assert((tasksCopy != null) && (tasksCopy.Length > 0), "Expected non-null task array with at least one element in it");
- _tasks = tasksCopy;
- _count = tasksCopy.Length;
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(this, "TaskFactory.ContinueWhenAll<>");
-
- if (Task.s_asyncDebuggingEnabled)
- AddToActiveTasks(this);
- }
-
- public void Invoke(Task completingTask)
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationRelation(this, CausalityRelation.Join);
-
- if (completingTask.IsWaitNotificationEnabled) this.SetNotificationForWaitCompletion(enabled: true);
- if (Interlocked.Decrement(ref _count) == 0)
- {
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Completed);
-
- if (Task.s_asyncDebuggingEnabled)
- RemoveFromActiveTasks(this);
-
- TrySetResult(_tasks);
- }
- Debug.Assert(_count >= 0, "Count should never go below 0");
- }
-
- public bool InvokeMayRunArbitraryCode => true;
-
- /// <summary>
- /// Returns whether we should notify the debugger of a wait completion. This returns
- /// true iff at least one constituent task has its bit set.
- /// </summary>
- internal override bool ShouldNotifyDebuggerOfWaitCompletion =>
- base.ShouldNotifyDebuggerOfWaitCompletion &&
- AnyTaskRequiresNotifyDebuggerOfWaitCompletion(_tasks);
- }
-
-
- internal static Task<Task<T>[]> CommonCWAllLogic<T>(Task<T>[] tasksCopy)
- {
- Debug.Assert(tasksCopy != null);
-
- // Create a promise task to be returned to the user
- CompleteOnCountdownPromise<T> promise = new CompleteOnCountdownPromise<T>(tasksCopy);
-
- for (int i = 0; i < tasksCopy.Length; i++)
- {
- if (tasksCopy[i].IsCompleted) promise.Invoke(tasksCopy[i]); // Short-circuit the completion action, if possible
- else tasksCopy[i].AddCompletionAction(promise); // simple completion action
- }
-
- return promise;
- }
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationAction">The action delegate to execute when all tasks in
- /// the <paramref name="tasks"/> array have completed.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task ContinueWhenAll(Task[] tasks, Action<Task[]> continuationAction)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAllImpl(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationAction">The action delegate to execute when all tasks in
- /// the <paramref name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWhenAll(Task[] tasks, Action<Task[]> continuationAction, CancellationToken cancellationToken)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAllImpl(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationAction">The action delegate to execute when all tasks in the <paramref
- /// name="tasks"/> array have completed.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task ContinueWhenAll(Task[] tasks, Action<Task[]> continuationAction, TaskContinuationOptions continuationOptions)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAllImpl(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationAction">The action delegate to execute when all tasks in the <paramref
- /// name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task ContinueWhenAll(Task[] tasks, Action<Task[]> continuationAction, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAllImpl(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationAction">The action delegate to execute when all tasks in
- /// the <paramref name="tasks"/> array have completed.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>[]> continuationAction)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAllImpl<TAntecedentResult>(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationAction">The action delegate to execute when all tasks in
- /// the <paramref name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>[]> continuationAction,
- CancellationToken cancellationToken)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAllImpl<TAntecedentResult>(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationAction">The action delegate to execute when all tasks in the <paramref
- /// name="tasks"/> array have completed.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>[]> continuationAction,
- TaskContinuationOptions continuationOptions)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAllImpl<TAntecedentResult>(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationAction">The action delegate to execute when all tasks in the <paramref
- /// name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>[]> continuationAction,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAllImpl<TAntecedentResult>(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task<TResult> ContinueWhenAll<TResult>(Task[] tasks, Func<Task[], TResult> continuationFunction)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWhenAll<TResult>(Task[] tasks, Func<Task[], TResult> continuationFunction, CancellationToken cancellationToken)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAllImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task<TResult> ContinueWhenAll<TResult>(Task[] tasks, Func<Task[], TResult> continuationFunction, TaskContinuationOptions continuationOptions)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task<TResult> ContinueWhenAll<TResult>(Task[] tasks, Func<Task[], TResult> continuationFunction, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAllImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler);
- }
-
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAllImpl<TAntecedentResult>(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction,
- CancellationToken cancellationToken)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAllImpl<TAntecedentResult>(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction,
- TaskContinuationOptions continuationOptions)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAllImpl<TAntecedentResult>(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of a set of provided Tasks.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue.</param>
- /// <param name="continuationFunction">The function delegate to execute when all tasks in the
- /// <paramref name="tasks"/> array have completed.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAll.
- /// </remarks>
- public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAllImpl<TAntecedentResult>(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler);
- }
-
- //
- // ContinueWhenAny methods
- //
-
- // A Task<Task> that will be completed the first time that Invoke is called.
- // It allows us to replace this logic:
- // Task<Task> promise = new Task<Task>(...);
- // Action<Task> completionAction = delegate(Task completingTask) { promise.TrySetResult(completingTask); }
- // for (int i=0; i<tasksCopy.Length; i++) tasksCopy[i].AddCompletionAction(completionAction);
- // with this logic:
- // CompletionOnInvokePromise promise = new CompletionOnInvokePromise(tasksCopy);
- // for (int i=0; i<tasksCopy.Length; i++) tasksCopy[i].AddCompletionAction(promise);
- // which saves a couple of allocations.
- //
- // Used in TaskFactory.CommonCWAnyLogic(), below.
- internal sealed class CompleteOnInvokePromise : Task<Task>, ITaskCompletionAction
- {
- private const int CompletedFlag = 0b_01;
- private const int SyncBlockingFlag = 0b_10;
-
- private IList<Task>? _tasks; // must track this for cleanup
- private int _stateFlags;
-
- public CompleteOnInvokePromise(IList<Task> tasks, bool isSyncBlocking)
- {
- Debug.Assert(tasks != null, "Expected non-null collection of tasks");
- _tasks = tasks;
-
- if (isSyncBlocking)
- {
- // Not completed, but blocking thread, set second bit
- _stateFlags = SyncBlockingFlag;
- }
-
- if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(this, "TaskFactory.ContinueWhenAny");
-
- if (Task.s_asyncDebuggingEnabled)
- AddToActiveTasks(this);
- }
-
- public void Invoke(Task completingTask)
- {
- int flags = _stateFlags;
- int isSyncBlockingFlag = flags & SyncBlockingFlag;
- int isCompleted = flags & CompletedFlag;
-
- if (isCompleted == 0 &&
- Interlocked.Exchange(ref _stateFlags, isSyncBlockingFlag | CompletedFlag) == isSyncBlockingFlag)
- {
- if (AsyncCausalityTracer.LoggingOn)
- {
- AsyncCausalityTracer.TraceOperationRelation(this, CausalityRelation.Choice);
- AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Completed);
- }
-
- if (Task.s_asyncDebuggingEnabled)
- RemoveFromActiveTasks(this);
-
- bool success = TrySetResult(completingTask);
- Debug.Assert(success, "Only one task should have gotten to this point, and thus this must be successful.");
-
- // We need to remove continuations that may be left straggling on other tasks.
- // Otherwise, repeated calls to WhenAny using the same task could leak actions.
- // This may also help to avoided unnecessary invocations of this whenComplete delegate.
- // Note that we may be attempting to remove a continuation from a task that hasn't had it
- // added yet; while there's overhead there, the operation won't hurt anything.
- IList<Task>? tasks = _tasks;
- Debug.Assert(tasks != null, "Should not have been nulled out yet.");
- int numTasks = tasks.Count;
- for (int i = 0; i < numTasks; i++)
- {
- Task task = tasks[i];
- if (task != null && // if an element was erroneously nulled out concurrently, just skip it; worst case is we don't remove a continuation
- !task.IsCompleted) task.RemoveContinuation(this);
- }
- _tasks = null;
- }
- }
-
- public bool InvokeMayRunArbitraryCode => (_stateFlags & SyncBlockingFlag) == 0;
- }
- // Common ContinueWhenAny logic
- // If the tasks list is not an array, it must be an internal defensive copy so that
- // we don't need to be concerned about concurrent modifications to the list. If the task list
- // is an array, it should be a defensive copy if this functionality is being used
- // asynchronously (e.g. WhenAny) rather than synchronously (e.g. WaitAny).
- internal static Task<Task> CommonCWAnyLogic(IList<Task> tasks, bool isSyncBlocking = false)
- {
- Debug.Assert(tasks != null);
-
- // Create a promise task to be returned to the user.
- // (If this logic ever changes, also update CommonCWAnyLogicCleanup.)
- var promise = new CompleteOnInvokePromise(tasks, isSyncBlocking);
-
- // At the completion of any of the tasks, complete the promise.
-
- bool checkArgsOnly = false;
- int numTasks = tasks.Count;
- for (int i = 0; i < numTasks; i++)
- {
- Task task = tasks[i];
- if (task == null) throw new ArgumentException(SR.Task_MultiTaskContinuation_NullTask, nameof(tasks));
-
- if (checkArgsOnly) continue;
-
- // If the promise has already completed, don't bother with checking any more tasks.
- if (promise.IsCompleted)
- {
- checkArgsOnly = true;
- }
- // If a task has already completed, complete the promise.
- else if (task.IsCompleted)
- {
- promise.Invoke(task);
- checkArgsOnly = true;
- }
- // Otherwise, add the completion action and keep going.
- else
- {
- task.AddCompletionAction(promise, addBeforeOthers: isSyncBlocking);
- if (promise.IsCompleted)
- {
- // One of the previous tasks that already had its continuation registered may have
- // raced to complete with our adding the continuation to this task. The completion
- // routine would have gone through and removed the continuation from all of the tasks
- // with which it was already registered, but if the race causes this continuation to
- // be added after that, it'll never be removed. As such, after adding the continuation,
- // we check to see whether the promise has already completed, and if it has, we try to
- // manually remove the continuation from this task. If it was already removed, it'll be
- // a nop, and if we race to remove it, the synchronization in RemoveContinuation will
- // keep things consistent.
- task.RemoveContinuation(promise);
- }
- }
- }
-
- return promise;
- }
-
- /// <summary>
- /// Cleans up the operations performed by CommonCWAnyLogic in a case where
- /// the created continuation task is being discarded.
- /// </summary>
- /// <param name="continuation">The task returned from CommonCWAnyLogic.</param>
- internal static void CommonCWAnyLogicCleanup(Task<Task> continuation)
- {
- // Force cleanup of the promise (e.g. removing continuations from each
- // constituent task), by completing the promise with any value (it's not observable).
- ((CompleteOnInvokePromise)continuation).Invoke(null!);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationAction">The action delegate to execute when one task in the <paramref
- /// name="tasks"/> array completes.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task ContinueWhenAny(Task[] tasks, Action<Task> continuationAction)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAnyImpl(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationAction">The action delegate to execute when one task in the <paramref
- /// name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWhenAny(Task[] tasks, Action<Task> continuationAction, CancellationToken cancellationToken)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAnyImpl(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationAction">The action delegate to execute when one task in the <paramref
- /// name="tasks"/> array completes.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task ContinueWhenAny(Task[] tasks, Action<Task> continuationAction, TaskContinuationOptions continuationOptions)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAnyImpl(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationAction">The action delegate to execute when one task in the <paramref
- /// name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task">Task</see>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task ContinueWhenAny(Task[] tasks, Action<Task> continuationAction, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAnyImpl(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler);
- }
-
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task<TResult> ContinueWhenAny<TResult>(Task[] tasks, Func<Task, TResult> continuationFunction)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWhenAny<TResult>(Task[] tasks, Func<Task, TResult> continuationFunction, CancellationToken cancellationToken)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAnyImpl(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task<TResult> ContinueWhenAny<TResult>(Task[] tasks, Func<Task, TResult> continuationFunction, TaskContinuationOptions continuationOptions)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task<TResult> ContinueWhenAny<TResult>(Task[] tasks, Func<Task, TResult> continuationFunction, CancellationToken cancellationToken,
- TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAnyImpl(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
- return TaskFactory<TResult>.ContinueWhenAnyImpl<TAntecedentResult>(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction,
- CancellationToken cancellationToken)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAnyImpl<TAntecedentResult>(tasks, continuationFunction, null, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction,
- TaskContinuationOptions continuationOptions)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAnyImpl<TAntecedentResult>(tasks, continuationFunction, null, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <typeparam name="TResult">The type of the result that is returned by the <paramref
- /// name="continuationFunction"/>
- /// delegate and associated with the created <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationFunction">The function delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task{TResult}">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task{TResult}"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationFunction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction));
-
- return TaskFactory<TResult>.ContinueWhenAnyImpl<TAntecedentResult>(tasks, continuationFunction, null, continuationOptions, cancellationToken, scheduler);
- }
-
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationAction">The action delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- public Task ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>> continuationAction)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAnyImpl<TAntecedentResult>(tasks, null, continuationAction, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationAction">The action delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- public Task ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>> continuationAction,
- CancellationToken cancellationToken)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAnyImpl<TAntecedentResult>(tasks, null, continuationAction, m_defaultContinuationOptions, cancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationAction">The action delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>> continuationAction,
- TaskContinuationOptions continuationOptions)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAnyImpl<TAntecedentResult>(tasks, null, continuationAction, continuationOptions, m_defaultCancellationToken, DefaultScheduler);
- }
-
- /// <summary>
- /// Creates a continuation <see cref="System.Threading.Tasks.Task">Task</see>
- /// that will be started upon the completion of any Task in the provided set.
- /// </summary>
- /// <typeparam name="TAntecedentResult">The type of the result of the antecedent <paramref name="tasks"/>.</typeparam>
- /// <param name="tasks">The array of tasks from which to continue when one task completes.</param>
- /// <param name="continuationAction">The action delegate to execute when one task in the
- /// <paramref name="tasks"/> array completes.</param>
- /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// that will be assigned to the new continuation task.</param>
- /// <param name="continuationOptions">The <see cref="System.Threading.Tasks.TaskContinuationOptions">
- /// TaskContinuationOptions</see> value that controls the behavior of
- /// the created continuation <see cref="System.Threading.Tasks.Task">Task</see>.</param>
- /// <param name="scheduler">The <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// that is used to schedule the created continuation <see
- /// cref="System.Threading.Tasks.Task{TResult}"/>.</param>
- /// <returns>The new continuation <see cref="System.Threading.Tasks.Task"/>.</returns>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="continuationAction"/> argument is null.</exception>
- /// <exception cref="System.ArgumentNullException">The exception that is thrown when the
- /// <paramref name="scheduler"/> argument is null.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array contains a null value.</exception>
- /// <exception cref="System.ArgumentException">The exception that is thrown when the
- /// <paramref name="tasks"/> array is empty.</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">The exception that is thrown when the
- /// <paramref name="continuationOptions"/> argument specifies an invalid TaskContinuationOptions
- /// value.</exception>
- /// <exception cref="System.ObjectDisposedException">The provided <see cref="System.Threading.CancellationToken">CancellationToken</see>
- /// has already been disposed.
- /// </exception>
- /// <remarks>
- /// The NotOn* and OnlyOn* <see cref="System.Threading.Tasks.TaskContinuationOptions">TaskContinuationOptions</see>,
- /// which constrain for which <see cref="System.Threading.Tasks.TaskStatus">TaskStatus</see> states a continuation
- /// will be executed, are illegal with ContinueWhenAny.
- /// </remarks>
- public Task ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>> continuationAction,
- CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
- {
- if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction));
-
- return TaskFactory<VoidTaskResult>.ContinueWhenAnyImpl<TAntecedentResult>(tasks, null, continuationAction, continuationOptions, cancellationToken, scheduler);
- }
-
- // Check task array and return a defensive copy.
- // Used with ContinueWhenAll()/ContinueWhenAny().
- internal static Task[] CheckMultiContinuationTasksAndCopy(Task[] tasks)
- {
- if (tasks == null)
- throw new ArgumentNullException(nameof(tasks));
- if (tasks.Length == 0)
- throw new ArgumentException(SR.Task_MultiTaskContinuation_EmptyTaskList, nameof(tasks));
-
- Task[] tasksCopy = new Task[tasks.Length];
- for (int i = 0; i < tasks.Length; i++)
- {
- tasksCopy[i] = tasks[i];
-
- if (tasksCopy[i] == null)
- throw new ArgumentException(SR.Task_MultiTaskContinuation_NullTask, nameof(tasks));
- }
-
- return tasksCopy;
- }
-
- internal static Task<TResult>[] CheckMultiContinuationTasksAndCopy<TResult>(Task<TResult>[] tasks)
- {
- if (tasks == null)
- throw new ArgumentNullException(nameof(tasks));
- if (tasks.Length == 0)
- throw new ArgumentException(SR.Task_MultiTaskContinuation_EmptyTaskList, nameof(tasks));
-
- Task<TResult>[] tasksCopy = new Task<TResult>[tasks.Length];
- for (int i = 0; i < tasks.Length; i++)
- {
- tasksCopy[i] = tasks[i];
-
- if (tasksCopy[i] == null)
- throw new ArgumentException(SR.Task_MultiTaskContinuation_NullTask, nameof(tasks));
- }
-
- return tasksCopy;
- }
-
- // Throw an exception if "options" argument specifies illegal options
- internal static void CheckMultiTaskContinuationOptions(TaskContinuationOptions continuationOptions)
- {
- // Construct a mask to check for illegal options
- const TaskContinuationOptions NotOnAny = TaskContinuationOptions.NotOnCanceled |
- TaskContinuationOptions.NotOnFaulted |
- TaskContinuationOptions.NotOnRanToCompletion;
-
- // Check that LongRunning and ExecuteSynchronously are not specified together
- const TaskContinuationOptions illegalMask = TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.LongRunning;
- if ((continuationOptions & illegalMask) == illegalMask)
- {
- throw new ArgumentOutOfRangeException(nameof(continuationOptions), SR.Task_ContinueWith_ESandLR);
- }
-
- // Check that no nonsensical options are specified.
- if ((continuationOptions & ~(
- TaskContinuationOptions.LongRunning |
- TaskContinuationOptions.PreferFairness |
- TaskContinuationOptions.AttachedToParent |
- TaskContinuationOptions.DenyChildAttach |
- TaskContinuationOptions.HideScheduler |
- TaskContinuationOptions.LazyCancellation |
- NotOnAny |
- TaskContinuationOptions.ExecuteSynchronously)) != 0)
- {
- throw new ArgumentOutOfRangeException(nameof(continuationOptions));
- }
-
- // Check that no "fire" options are specified.
- if ((continuationOptions & NotOnAny) != 0)
- throw new ArgumentOutOfRangeException(nameof(continuationOptions), SR.Task_MultiTaskContinuation_FireOptions);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs
deleted file mode 100644
index 545d22410bd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs
+++ /dev/null
@@ -1,649 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// This file contains the primary interface and management of tasks and queues.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// Represents an abstract scheduler for tasks.
- /// </summary>
- /// <remarks>
- /// <para>
- /// <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> acts as the extension point for all
- /// pluggable scheduling logic. This includes mechanisms such as how to schedule a task for execution, and
- /// how scheduled tasks should be exposed to debuggers.
- /// </para>
- /// <para>
- /// All members of the abstract <see cref="TaskScheduler"/> type are thread-safe
- /// and may be used from multiple threads concurrently.
- /// </para>
- /// </remarks>
- [DebuggerDisplay("Id={Id}")]
- [DebuggerTypeProxy(typeof(SystemThreadingTasks_TaskSchedulerDebugView))]
- public abstract class TaskScheduler
- {
- ////////////////////////////////////////////////////////////
- //
- // User Provided Methods and Properties
- //
-
- /// <summary>
- /// Queues a <see cref="System.Threading.Tasks.Task">Task</see> to the scheduler.
- /// </summary>
- /// <remarks>
- /// <para>
- /// A class derived from <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// implements this method to accept tasks being scheduled on the scheduler.
- /// A typical implementation would store the task in an internal data structure, which would
- /// be serviced by threads that would execute those tasks at some time in the future.
- /// </para>
- /// <para>
- /// This method is only meant to be called by the .NET Framework and
- /// should not be called directly by the derived class. This is necessary
- /// for maintaining the consistency of the system.
- /// </para>
- /// </remarks>
- /// <param name="task">The <see cref="System.Threading.Tasks.Task">Task</see> to be queued.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="task"/> argument is null.</exception>
- protected internal abstract void QueueTask(Task task);
-
- /// <summary>
- /// Determines whether the provided <see cref="System.Threading.Tasks.Task">Task</see>
- /// can be executed synchronously in this call, and if it can, executes it.
- /// </summary>
- /// <remarks>
- /// <para>
- /// A class derived from <see cref="TaskScheduler">TaskScheduler</see> implements this function to
- /// support inline execution of a task on a thread that initiates a wait on that task object. Inline
- /// execution is optional, and the request may be rejected by returning false. However, better
- /// scalability typically results the more tasks that can be inlined, and in fact a scheduler that
- /// inlines too little may be prone to deadlocks. A proper implementation should ensure that a
- /// request executing under the policies guaranteed by the scheduler can successfully inline. For
- /// example, if a scheduler uses a dedicated thread to execute tasks, any inlining requests from that
- /// thread should succeed.
- /// </para>
- /// <para>
- /// If a scheduler decides to perform the inline execution, it should do so by calling to the base
- /// TaskScheduler's
- /// <see cref="TryExecuteTask">TryExecuteTask</see> method with the provided task object, propagating
- /// the return value. It may also be appropriate for the scheduler to remove an inlined task from its
- /// internal data structures if it decides to honor the inlining request. Note, however, that under
- /// some circumstances a scheduler may be asked to inline a task that was not previously provided to
- /// it with the <see cref="QueueTask"/> method.
- /// </para>
- /// <para>
- /// The derived scheduler is responsible for making sure that the calling thread is suitable for
- /// executing the given task as far as its own scheduling and execution policies are concerned.
- /// </para>
- /// </remarks>
- /// <param name="task">The <see cref="System.Threading.Tasks.Task">Task</see> to be
- /// executed.</param>
- /// <param name="taskWasPreviouslyQueued">A Boolean denoting whether or not task has previously been
- /// queued. If this parameter is True, then the task may have been previously queued (scheduled); if
- /// False, then the task is known not to have been queued, and this call is being made in order to
- /// execute the task inline without queueing it.</param>
- /// <returns>A Boolean value indicating whether the task was executed inline.</returns>
- /// <exception cref="System.ArgumentNullException">The <paramref name="task"/> argument is
- /// null.</exception>
- /// <exception cref="System.InvalidOperationException">The <paramref name="task"/> was already
- /// executed.</exception>
- protected abstract bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued);
-
- /// <summary>
- /// Generates an enumerable of <see cref="System.Threading.Tasks.Task">Task</see> instances
- /// currently queued to the scheduler waiting to be executed.
- /// </summary>
- /// <remarks>
- /// <para>
- /// A class derived from <see cref="TaskScheduler"/> implements this method in order to support
- /// integration with debuggers. This method will only be invoked by the .NET Framework when the
- /// debugger requests access to the data. The enumerable returned will be traversed by debugging
- /// utilities to access the tasks currently queued to this scheduler, enabling the debugger to
- /// provide a representation of this information in the user interface.
- /// </para>
- /// <para>
- /// It is important to note that, when this method is called, all other threads in the process will
- /// be frozen. Therefore, it's important to avoid synchronization with other threads that may lead to
- /// blocking. If synchronization is necessary, the method should prefer to throw a <see
- /// cref="System.NotSupportedException"/>
- /// than to block, which could cause a debugger to experience delays. Additionally, this method and
- /// the enumerable returned must not modify any globally visible state.
- /// </para>
- /// <para>
- /// The returned enumerable should never be null. If there are currently no queued tasks, an empty
- /// enumerable should be returned instead.
- /// </para>
- /// <para>
- /// For developers implementing a custom debugger, this method shouldn't be called directly, but
- /// rather this functionality should be accessed through the internal wrapper method
- /// GetScheduledTasksForDebugger:
- /// <c>internal Task[] GetScheduledTasksForDebugger()</c>. This method returns an array of tasks,
- /// rather than an enumerable. In order to retrieve a list of active schedulers, a debugger may use
- /// another internal method: <c>internal static TaskScheduler[] GetTaskSchedulersForDebugger()</c>.
- /// This static method returns an array of all active TaskScheduler instances.
- /// GetScheduledTasksForDebugger then may be used on each of these scheduler instances to retrieve
- /// the list of scheduled tasks for each.
- /// </para>
- /// </remarks>
- /// <returns>An enumerable that allows traversal of tasks currently queued to this scheduler.
- /// </returns>
- /// <exception cref="System.NotSupportedException">
- /// This scheduler is unable to generate a list of queued tasks at this time.
- /// </exception>
- protected abstract IEnumerable<Task>? GetScheduledTasks();
-
- /// <summary>
- /// Indicates the maximum concurrency level this
- /// <see cref="TaskScheduler"/> is able to support.
- /// </summary>
- public virtual int MaximumConcurrencyLevel => int.MaxValue;
-
- ////////////////////////////////////////////////////////////
- //
- // Internal overridable methods
- //
-
-
- /// <summary>
- /// Attempts to execute the target task synchronously.
- /// </summary>
- /// <param name="task">The task to run.</param>
- /// <param name="taskWasPreviouslyQueued">True if the task may have been previously queued,
- /// false if the task was absolutely not previously queued.</param>
- /// <returns>True if it ran, false otherwise.</returns>
- internal bool TryRunInline(Task task, bool taskWasPreviouslyQueued)
- {
- // Do not inline unstarted tasks (i.e., task.ExecutingTaskScheduler == null).
- // Do not inline TaskCompletionSource-style (a.k.a. "promise") tasks.
- // No need to attempt inlining if the task body was already run (i.e. either TASK_STATE_DELEGATE_INVOKED or TASK_STATE_CANCELED bits set)
- TaskScheduler? ets = task.ExecutingTaskScheduler;
-
- // Delegate cross-scheduler inlining requests to target scheduler
- if (ets != this && ets != null) return ets.TryRunInline(task, taskWasPreviouslyQueued);
-
- if ((ets == null) ||
- (task.m_action == null) ||
- task.IsDelegateInvoked ||
- task.IsCanceled ||
- !RuntimeHelpers.TryEnsureSufficientExecutionStack())
- {
- return false;
- }
-
- // Task class will still call into TaskScheduler.TryRunInline rather than TryExecuteTaskInline() so that
- // 1) we can adjust the return code from TryExecuteTaskInline in case a buggy custom scheduler lies to us
- // 2) we maintain a mechanism for the TLS lookup optimization that we used to have for the ConcRT scheduler (will potentially introduce the same for TP)
- if (TplEventSource.Log.IsEnabled())
- task.FireTaskScheduledIfNeeded(this);
-
- bool inlined = TryExecuteTaskInline(task, taskWasPreviouslyQueued);
-
- // If the custom scheduler returned true, we should either have the TASK_STATE_DELEGATE_INVOKED or TASK_STATE_CANCELED bit set
- // Otherwise the scheduler is buggy
- if (inlined && !(task.IsDelegateInvoked || task.IsCanceled))
- {
- throw new InvalidOperationException(SR.TaskScheduler_InconsistentStateAfterTryExecuteTaskInline);
- }
-
- return inlined;
- }
-
- /// <summary>
- /// Attempts to dequeue a <see cref="System.Threading.Tasks.Task">Task</see> that was previously queued to
- /// this scheduler.
- /// </summary>
- /// <param name="task">The <see cref="System.Threading.Tasks.Task">Task</see> to be dequeued.</param>
- /// <returns>A Boolean denoting whether the <paramref name="task"/> argument was successfully dequeued.</returns>
- /// <exception cref="System.ArgumentNullException">The <paramref name="task"/> argument is null.</exception>
- protected internal virtual bool TryDequeue(Task task)
- {
- return false;
- }
-
- /// <summary>
- /// Notifies the scheduler that a work item has made progress.
- /// </summary>
- internal virtual void NotifyWorkItemProgress()
- {
- }
-
- /// <summary>
- /// Indicates whether this is a custom scheduler, in which case the safe code paths will be taken upon task entry
- /// using a CAS to transition from queued state to executing.
- /// </summary>
- internal virtual bool RequiresAtomicStartTransition => true;
-
- /// <summary>
- /// Calls QueueTask() after performing any needed firing of events
- /// </summary>
- internal void InternalQueueTask(Task task)
- {
- Debug.Assert(task != null);
-
- if (TplEventSource.Log.IsEnabled())
- task.FireTaskScheduledIfNeeded(this);
-
- this.QueueTask(task);
- }
-
-
- ////////////////////////////////////////////////////////////
- //
- // Member variables
- //
-
- // The global container that keeps track of TaskScheduler instances for debugging purposes.
- private static ConditionalWeakTable<TaskScheduler, object?>? s_activeTaskSchedulers;
-
- // An AppDomain-wide default manager.
- private static readonly TaskScheduler s_defaultTaskScheduler = new ThreadPoolTaskScheduler();
-
- // static counter used to generate unique TaskScheduler IDs
- internal static int s_taskSchedulerIdCounter;
-
- // this TaskScheduler's unique ID
- private volatile int m_taskSchedulerId;
-
-
-
- ////////////////////////////////////////////////////////////
- //
- // Constructors and public properties
- //
-
- /// <summary>
- /// Initializes the <see cref="System.Threading.Tasks.TaskScheduler"/>.
- /// </summary>
- protected TaskScheduler()
- {
-#if CORECLR // Debugger support
- // Register the scheduler in the active scheduler list. This is only relevant when debugging,
- // so we only pay the cost if the debugger is attached when the scheduler is created. This
- // means that the internal TaskScheduler.GetTaskSchedulersForDebugger() will only include
- // schedulers created while the debugger is attached.
- if (Debugger.IsAttached)
- {
- AddToActiveTaskSchedulers();
- }
-#endif
- }
-
- /// <summary>Adds this scheduler ot the active schedulers tracking collection for debugging purposes.</summary>
- private void AddToActiveTaskSchedulers()
- {
- ConditionalWeakTable<TaskScheduler, object?>? activeTaskSchedulers = s_activeTaskSchedulers;
- if (activeTaskSchedulers == null)
- {
- Interlocked.CompareExchange(ref s_activeTaskSchedulers, new ConditionalWeakTable<TaskScheduler, object?>(), null);
- activeTaskSchedulers = s_activeTaskSchedulers;
- }
- activeTaskSchedulers.Add(this, null);
- }
-
- /// <summary>
- /// Gets the default <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> instance.
- /// </summary>
- public static TaskScheduler Default => s_defaultTaskScheduler;
-
- /// <summary>
- /// Gets the <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// associated with the currently executing task.
- /// </summary>
- /// <remarks>
- /// When not called from within a task, <see cref="Current"/> will return the <see cref="Default"/> scheduler.
- /// </remarks>
- public static TaskScheduler Current => InternalCurrent ?? Default;
-
- /// <summary>
- /// Gets the <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// associated with the currently executing task.
- /// </summary>
- /// <remarks>
- /// When not called from within a task, <see cref="InternalCurrent"/> will return null.
- /// </remarks>
- internal static TaskScheduler? InternalCurrent
- {
- get
- {
- Task? currentTask = Task.InternalCurrent;
- return ((currentTask != null)
- && ((currentTask.CreationOptions & TaskCreationOptions.HideScheduler) == 0)
- ) ? currentTask.ExecutingTaskScheduler : null;
- }
- }
-
- /// <summary>
- /// Creates a <see cref="TaskScheduler"/>
- /// associated with the current <see cref="System.Threading.SynchronizationContext"/>.
- /// </summary>
- /// <remarks>
- /// All <see cref="System.Threading.Tasks.Task">Task</see> instances queued to
- /// the returned scheduler will be executed through a call to the
- /// <see cref="System.Threading.SynchronizationContext.Post">Post</see> method
- /// on that context.
- /// </remarks>
- /// <returns>
- /// A <see cref="TaskScheduler"/> associated with
- /// the current <see cref="System.Threading.SynchronizationContext">SynchronizationContext</see>, as
- /// determined by <see cref="System.Threading.SynchronizationContext.Current">SynchronizationContext.Current</see>.
- /// </returns>
- /// <exception cref="System.InvalidOperationException">
- /// The current SynchronizationContext may not be used as a TaskScheduler.
- /// </exception>
- public static TaskScheduler FromCurrentSynchronizationContext()
- {
- return new SynchronizationContextTaskScheduler();
- }
-
- /// <summary>
- /// Gets the unique ID for this <see cref="TaskScheduler"/>.
- /// </summary>
- public int Id
- {
- get
- {
- if (m_taskSchedulerId == 0)
- {
- int newId;
-
- // We need to repeat if Interlocked.Increment wraps around and returns 0.
- // Otherwise next time this scheduler's Id is queried it will get a new value
- do
- {
- newId = Interlocked.Increment(ref s_taskSchedulerIdCounter);
- } while (newId == 0);
-
- Interlocked.CompareExchange(ref m_taskSchedulerId, newId, 0);
- }
-
- return m_taskSchedulerId;
- }
- }
-
- /// <summary>
- /// Attempts to execute the provided <see cref="System.Threading.Tasks.Task">Task</see>
- /// on this scheduler.
- /// </summary>
- /// <remarks>
- /// <para>
- /// Scheduler implementations are provided with <see cref="System.Threading.Tasks.Task">Task</see>
- /// instances to be executed through either the <see cref="QueueTask"/> method or the
- /// <see cref="TryExecuteTaskInline"/> method. When the scheduler deems it appropriate to run the
- /// provided task, <see cref="TryExecuteTask"/> should be used to do so. TryExecuteTask handles all
- /// aspects of executing a task, including action invocation, exception handling, state management,
- /// and lifecycle control.
- /// </para>
- /// <para>
- /// <see cref="TryExecuteTask"/> must only be used for tasks provided to this scheduler by the .NET
- /// Framework infrastructure. It should not be used to execute arbitrary tasks obtained through
- /// custom mechanisms.
- /// </para>
- /// </remarks>
- /// <param name="task">
- /// A <see cref="System.Threading.Tasks.Task">Task</see> object to be executed.</param>
- /// <exception cref="System.InvalidOperationException">
- /// The <paramref name="task"/> is not associated with this scheduler.
- /// </exception>
- /// <returns>A Boolean that is true if <paramref name="task"/> was successfully executed, false if it
- /// was not. A common reason for execution failure is that the task had previously been executed or
- /// is in the process of being executed by another thread.</returns>
- protected bool TryExecuteTask(Task task)
- {
- if (task.ExecutingTaskScheduler != this)
- {
- throw new InvalidOperationException(SR.TaskScheduler_ExecuteTask_WrongTaskScheduler);
- }
-
- return task.ExecuteEntry();
- }
-
- ////////////////////////////////////////////////////////////
- //
- // Events
- //
-
- /// <summary>
- /// Occurs when a faulted <see cref="System.Threading.Tasks.Task"/>'s unobserved exception is about to trigger exception escalation
- /// policy, which, by default, would terminate the process.
- /// </summary>
- /// <remarks>
- /// This AppDomain-wide event provides a mechanism to prevent exception
- /// escalation policy (which, by default, terminates the process) from triggering.
- /// Each handler is passed a <see cref="System.Threading.Tasks.UnobservedTaskExceptionEventArgs"/>
- /// instance, which may be used to examine the exception and to mark it as observed.
- /// </remarks>
- public static event EventHandler<UnobservedTaskExceptionEventArgs>? UnobservedTaskException;
-
- ////////////////////////////////////////////////////////////
- //
- // Internal methods
- //
-
- // This is called by the TaskExceptionHolder finalizer.
- internal static void PublishUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs ueea)
- {
- UnobservedTaskException?.Invoke(sender, ueea);
- }
-
- /// <summary>
- /// Provides an array of all queued <see cref="System.Threading.Tasks.Task">Task</see> instances
- /// for the debugger.
- /// </summary>
- /// <remarks>
- /// The returned array is populated through a call to <see cref="GetScheduledTasks"/>.
- /// Note that this function is only meant to be invoked by a debugger remotely.
- /// It should not be called by any other codepaths.
- /// </remarks>
- /// <returns>An array of <see cref="System.Threading.Tasks.Task">Task</see> instances.</returns>
- /// <exception cref="System.NotSupportedException">
- /// This scheduler is unable to generate a list of queued tasks at this time.
- /// </exception>
- internal Task[]? GetScheduledTasksForDebugger()
- {
- // this can throw InvalidOperationException indicating that they are unable to provide the info
- // at the moment. We should let the debugger receive that exception so that it can indicate it in the UI
- IEnumerable<Task>? activeTasksSource = GetScheduledTasks();
-
- if (activeTasksSource == null)
- return null;
-
- // If it can be cast to an array, use it directly
- if (!(activeTasksSource is Task[] activeTasksArray))
- {
- activeTasksArray = (new List<Task>(activeTasksSource)).ToArray();
- }
-
- // touch all Task.Id fields so that the debugger doesn't need to do a lot of cross-proc calls to generate them
- foreach (Task t in activeTasksArray)
- {
- _ = t.Id;
- }
-
- return activeTasksArray;
- }
-
- /// <summary>
- /// Provides an array of all active <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see>
- /// instances for the debugger.
- /// </summary>
- /// <remarks>
- /// This function is only meant to be invoked by a debugger remotely.
- /// It should not be called by any other codepaths.
- /// </remarks>
- /// <returns>An array of <see cref="System.Threading.Tasks.TaskScheduler">TaskScheduler</see> instances.</returns>
- internal static TaskScheduler[] GetTaskSchedulersForDebugger()
- {
- if (s_activeTaskSchedulers == null)
- {
- // No schedulers were tracked. Just give back the default.
- return new TaskScheduler[] { s_defaultTaskScheduler };
- }
-
- List<TaskScheduler> schedulers = new List<TaskScheduler>();
- foreach (KeyValuePair<TaskScheduler, object?> item in s_activeTaskSchedulers)
- {
- schedulers.Add(item.Key);
- }
-
- if (!schedulers.Contains(s_defaultTaskScheduler))
- {
- // Make sure the default is included, in case the debugger attached
- // after it was created.
- schedulers.Add(s_defaultTaskScheduler);
- }
-
- TaskScheduler[] arr = schedulers.ToArray();
- foreach (TaskScheduler scheduler in arr)
- {
- Debug.Assert(scheduler != null, "Table returned an incorrect Count or CopyTo failed");
- _ = scheduler.Id; // force Ids for debugger
- }
- return arr;
- }
-
- /// <summary>
- /// Nested class that provides debugger view for TaskScheduler
- /// </summary>
- internal sealed class SystemThreadingTasks_TaskSchedulerDebugView
- {
- private readonly TaskScheduler m_taskScheduler;
- public SystemThreadingTasks_TaskSchedulerDebugView(TaskScheduler scheduler)
- {
- m_taskScheduler = scheduler;
- }
-
- // returns the scheduler's Id
- public int Id => m_taskScheduler.Id;
-
- // returns the scheduler's GetScheduledTasks
- public IEnumerable<Task>? ScheduledTasks => m_taskScheduler.GetScheduledTasks();
- }
- }
-
-
-
-
- /// <summary>
- /// A TaskScheduler implementation that executes all tasks queued to it through a call to
- /// <see cref="System.Threading.SynchronizationContext.Post"/> on the <see cref="System.Threading.SynchronizationContext"/>
- /// that its associated with. The default constructor for this class binds to the current <see cref="System.Threading.SynchronizationContext"/>
- /// </summary>
- internal sealed class SynchronizationContextTaskScheduler : TaskScheduler
- {
- private readonly SynchronizationContext m_synchronizationContext;
-
- /// <summary>
- /// Constructs a SynchronizationContextTaskScheduler associated with <see cref="System.Threading.SynchronizationContext.Current"/>
- /// </summary>
- /// <exception cref="System.InvalidOperationException">This constructor expects <see cref="System.Threading.SynchronizationContext.Current"/> to be set.</exception>
- internal SynchronizationContextTaskScheduler()
- {
- m_synchronizationContext = SynchronizationContext.Current ??
- // make sure we have a synccontext to work with
- throw new InvalidOperationException(SR.TaskScheduler_FromCurrentSynchronizationContext_NoCurrent);
- }
-
- /// <summary>
- /// Implementation of <see cref="System.Threading.Tasks.TaskScheduler.QueueTask"/> for this scheduler class.
- ///
- /// Simply posts the tasks to be executed on the associated <see cref="System.Threading.SynchronizationContext"/>.
- /// </summary>
- /// <param name="task"></param>
- protected internal override void QueueTask(Task task)
- {
- m_synchronizationContext.Post(s_postCallback, (object)task);
- }
-
- /// <summary>
- /// Implementation of <see cref="System.Threading.Tasks.TaskScheduler.TryExecuteTaskInline"/> for this scheduler class.
- ///
- /// The task will be executed inline only if the call happens within
- /// the associated <see cref="System.Threading.SynchronizationContext"/>.
- /// </summary>
- /// <param name="task"></param>
- /// <param name="taskWasPreviouslyQueued"></param>
- protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
- {
- if (SynchronizationContext.Current == m_synchronizationContext)
- {
- return TryExecuteTask(task);
- }
- else
- {
- return false;
- }
- }
-
- protected override IEnumerable<Task>? GetScheduledTasks()
- {
- return null;
- }
-
- /// <summary>
- /// Implements the <see cref="System.Threading.Tasks.TaskScheduler.MaximumConcurrencyLevel"/> property for
- /// this scheduler class.
- ///
- /// By default it returns 1, because a <see cref="System.Threading.SynchronizationContext"/> based
- /// scheduler only supports execution on a single thread.
- /// </summary>
- public override int MaximumConcurrencyLevel => 1;
-
- // preallocated SendOrPostCallback delegate
- private static readonly SendOrPostCallback s_postCallback = s =>
- {
- Debug.Assert(s is Task);
- ((Task)s).ExecuteEntry(); // with double-execute check because SC could be buggy
- };
- }
-
- /// <summary>
- /// Provides data for the event that is raised when a faulted <see cref="System.Threading.Tasks.Task"/>'s
- /// exception goes unobserved.
- /// </summary>
- /// <remarks>
- /// The Exception property is used to examine the exception without marking it
- /// as observed, whereas the <see cref="SetObserved"/> method is used to mark the exception
- /// as observed. Marking the exception as observed prevents it from triggering exception escalation policy
- /// which, by default, terminates the process.
- /// </remarks>
- public class UnobservedTaskExceptionEventArgs : EventArgs
- {
- private readonly AggregateException? m_exception;
- internal bool m_observed = false;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="UnobservedTaskExceptionEventArgs"/> class
- /// with the unobserved exception.
- /// </summary>
- /// <param name="exception">The Exception that has gone unobserved.</param>
- public UnobservedTaskExceptionEventArgs(AggregateException? exception) { m_exception = exception; }
-
- /// <summary>
- /// Marks the <see cref="Exception"/> as "observed," thus preventing it
- /// from triggering exception escalation policy which, by default, terminates the process.
- /// </summary>
- public void SetObserved() { m_observed = true; }
-
- /// <summary>
- /// Gets whether this exception has been marked as "observed."
- /// </summary>
- public bool Observed => m_observed;
-
- /// <summary>
- /// The Exception that went unobserved.
- /// </summary>
- public AggregateException? Exception => m_exception;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskSchedulerException.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskSchedulerException.cs
deleted file mode 100644
index ee1bbacecbd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskSchedulerException.cs
+++ /dev/null
@@ -1,76 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-//
-//
-// An exception for task schedulers.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Runtime.Serialization;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// Represents an exception used to communicate an invalid operation by a
- /// <see cref="System.Threading.Tasks.TaskScheduler"/>.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class TaskSchedulerException : Exception
- {
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.Tasks.TaskSchedulerException"/> class.
- /// </summary>
- public TaskSchedulerException() : base(SR.TaskSchedulerException_ctor_DefaultMessage) //
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.Tasks.TaskSchedulerException"/>
- /// class with a specified error message.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- public TaskSchedulerException(string? message) : base(message)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.Tasks.TaskSchedulerException"/>
- /// class using the default error message and a reference to the inner exception that is the cause of
- /// this exception.
- /// </summary>
- /// <param name="innerException">The exception that is the cause of the current exception.</param>
- public TaskSchedulerException(Exception? innerException)
- : base(SR.TaskSchedulerException_ctor_DefaultMessage, innerException)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.Tasks.TaskSchedulerException"/>
- /// class with a specified error message and a reference to the inner exception that is the cause of
- /// this exception.
- /// </summary>
- /// <param name="message">The error message that explains the reason for the exception.</param>
- /// <param name="innerException">The exception that is the cause of the current exception.</param>
- public TaskSchedulerException(string? message, Exception? innerException) : base(message, innerException)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="System.Threading.Tasks.TaskSchedulerException"/>
- /// class with serialized data.
- /// </summary>
- /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/> that holds
- /// the serialized object data about the exception being thrown.</param>
- /// <param name="context">The <see cref="System.Runtime.Serialization.StreamingContext"/> that
- /// contains contextual information about the source or destination. </param>
- protected TaskSchedulerException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskToApm.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskToApm.cs
deleted file mode 100644
index ecd9f27ecb8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskToApm.cs
+++ /dev/null
@@ -1,121 +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.
-
-// Helper methods for using Tasks to implement the APM pattern.
-//
-// Example usage, wrapping a Task<int>-returning FooAsync method with Begin/EndFoo methods:
-//
-// public IAsyncResult BeginFoo(..., AsyncCallback callback, object state) =>
-// TaskToApm.Begin(FooAsync(...), callback, state);
-//
-// public int EndFoo(IAsyncResult asyncResult) =>
-// TaskToApm.End<int>(asyncResult);
-
-#nullable enable
-using System.Diagnostics;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// Provides support for efficiently using Tasks to implement the APM (Begin/End) pattern.
- /// </summary>
- internal static class TaskToApm
- {
- /// <summary>
- /// Marshals the Task as an IAsyncResult, using the supplied callback and state
- /// to implement the APM pattern.
- /// </summary>
- /// <param name="task">The Task to be marshaled.</param>
- /// <param name="callback">The callback to be invoked upon completion.</param>
- /// <param name="state">The state to be stored in the IAsyncResult.</param>
- /// <returns>An IAsyncResult to represent the task's asynchronous operation.</returns>
- public static IAsyncResult Begin(Task task, AsyncCallback? callback, object? state) =>
- new TaskAsyncResult(task, state, callback);
-
- /// <summary>Processes an IAsyncResult returned by Begin.</summary>
- /// <param name="asyncResult">The IAsyncResult to unwrap.</param>
- public static void End(IAsyncResult asyncResult)
- {
- if (asyncResult is TaskAsyncResult twar)
- {
- twar._task.GetAwaiter().GetResult();
- return;
- }
-
- throw new ArgumentNullException();
- }
-
- /// <summary>Processes an IAsyncResult returned by Begin.</summary>
- /// <param name="asyncResult">The IAsyncResult to unwrap.</param>
- public static TResult End<TResult>(IAsyncResult asyncResult)
- {
- if (asyncResult is TaskAsyncResult twar && twar._task is Task<TResult> task)
- {
- return task.GetAwaiter().GetResult();
- }
-
- throw new ArgumentNullException();
- }
-
- /// <summary>Provides a simple IAsyncResult that wraps a Task.</summary>
- /// <remarks>
- /// We could use the Task as the IAsyncResult if the Task's AsyncState is the same as the object state,
- /// but that's very rare, in particular in a situation where someone cares about allocation, and always
- /// using TaskAsyncResult simplifies things and enables additional optimizations.
- /// </remarks>
- internal sealed class TaskAsyncResult : IAsyncResult
- {
- /// <summary>The wrapped Task.</summary>
- internal readonly Task _task;
- /// <summary>Callback to invoke when the wrapped task completes.</summary>
- private readonly AsyncCallback? _callback;
-
- /// <summary>Initializes the IAsyncResult with the Task to wrap and the associated object state.</summary>
- /// <param name="task">The Task to wrap.</param>
- /// <param name="state">The new AsyncState value.</param>
- /// <param name="callback">Callback to invoke when the wrapped task completes.</param>
- internal TaskAsyncResult(Task task, object? state, AsyncCallback? callback)
- {
- Debug.Assert(task != null);
- _task = task;
- AsyncState = state;
-
- if (task.IsCompleted)
- {
- // Synchronous completion. Invoke the callback. No need to store it.
- CompletedSynchronously = true;
- callback?.Invoke(this);
- }
- else if (callback != null)
- {
- // Asynchronous completion, and we have a callback; schedule it. We use OnCompleted rather than ContinueWith in
- // order to avoid running synchronously if the task has already completed by the time we get here but still run
- // synchronously as part of the task's completion if the task completes after (the more common case).
- _callback = callback;
- _task.ConfigureAwait(continueOnCapturedContext: false)
- .GetAwaiter()
- .OnCompleted(InvokeCallback); // allocates a delegate, but avoids a closure
- }
- }
-
- /// <summary>Invokes the callback.</summary>
- private void InvokeCallback()
- {
- Debug.Assert(!CompletedSynchronously);
- Debug.Assert(_callback != null);
- _callback.Invoke(this);
- }
-
- /// <summary>Gets a user-defined object that qualifies or contains information about an asynchronous operation.</summary>
- public object? AsyncState { get; }
- /// <summary>Gets a value that indicates whether the asynchronous operation completed synchronously.</summary>
- /// <remarks>This is set lazily based on whether the <see cref="_task"/> has completed by the time this object is created.</remarks>
- public bool CompletedSynchronously { get; }
- /// <summary>Gets a value that indicates whether the asynchronous operation has completed.</summary>
- public bool IsCompleted => _task.IsCompleted;
- /// <summary>Gets a <see cref="WaitHandle"/> that is used to wait for an asynchronous operation to complete.</summary>
- public WaitHandle AsyncWaitHandle => ((IAsyncResult)_task).AsyncWaitHandle;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ThreadPoolTaskScheduler.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ThreadPoolTaskScheduler.cs
deleted file mode 100644
index dd7b77f71f9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ThreadPoolTaskScheduler.cs
+++ /dev/null
@@ -1,124 +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.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-// TaskScheduler.cs
-//
-//
-// This file contains the primary interface and management of tasks and queues.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace System.Threading.Tasks
-{
- /// <summary>
- /// An implementation of TaskScheduler that uses the ThreadPool scheduler
- /// </summary>
- internal sealed class ThreadPoolTaskScheduler : TaskScheduler
- {
- /// <summary>
- /// Constructs a new ThreadPool task scheduler object
- /// </summary>
- internal ThreadPoolTaskScheduler()
- {
- _ = base.Id; // force ID creation of the default scheduler
- }
-
- // static delegate for threads allocated to handle LongRunning tasks.
- private static readonly ParameterizedThreadStart s_longRunningThreadWork = s =>
- {
- Debug.Assert(s is Task);
- ((Task)s).ExecuteEntryUnsafe(threadPoolThread: null);
- };
-
- /// <summary>
- /// Schedules a task to the ThreadPool.
- /// </summary>
- /// <param name="task">The task to schedule.</param>
- protected internal override void QueueTask(Task task)
- {
- TaskCreationOptions options = task.Options;
- if ((options & TaskCreationOptions.LongRunning) != 0)
- {
- // Run LongRunning tasks on their own dedicated thread.
- Thread thread = new Thread(s_longRunningThreadWork);
- thread.IsBackground = true; // Keep this thread from blocking process shutdown
- thread.Start(task);
- }
- else
- {
- // Normal handling for non-LongRunning tasks.
- bool preferLocal = ((options & TaskCreationOptions.PreferFairness) == 0);
- ThreadPool.UnsafeQueueUserWorkItemInternal(task, preferLocal);
- }
- }
-
- /// <summary>
- /// This internal function will do this:
- /// (1) If the task had previously been queued, attempt to pop it and return false if that fails.
- /// (2) Return whether the task is executed
- ///
- /// IMPORTANT NOTE: TryExecuteTaskInline will NOT throw task exceptions itself. Any wait code path using this function needs
- /// to account for exceptions that need to be propagated, and throw themselves accordingly.
- /// </summary>
- protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
- {
- // If the task was previously scheduled, and we can't pop it, then return false.
- if (taskWasPreviouslyQueued && !ThreadPool.TryPopCustomWorkItem(task))
- return false;
-
- try
- {
- task.ExecuteEntryUnsafe(threadPoolThread: null); // handles switching Task.Current etc.
- }
- finally
- {
- // Only call NWIP() if task was previously queued
- if (taskWasPreviouslyQueued) NotifyWorkItemProgress();
- }
-
- return true;
- }
-
- protected internal override bool TryDequeue(Task task)
- {
- // just delegate to TP
- return ThreadPool.TryPopCustomWorkItem(task);
- }
-
- protected override IEnumerable<Task> GetScheduledTasks()
- {
- return FilterTasksFromWorkItems(ThreadPool.GetQueuedWorkItems());
- }
-
- private IEnumerable<Task> FilterTasksFromWorkItems(IEnumerable<object> tpwItems)
- {
- foreach (object tpwi in tpwItems)
- {
- if (tpwi is Task t)
- {
- yield return t;
- }
- }
- }
-
- /// <summary>
- /// Notifies the scheduler that work is progressing (no-op).
- /// </summary>
- internal override void NotifyWorkItemProgress()
- {
- ThreadPool.NotifyWorkItemProgress();
- }
-
- /// <summary>
- /// This is the only scheduler that returns false for this property, indicating that the task entry codepath is unsafe (CAS free)
- /// since we know that the underlying scheduler already takes care of atomic transitions from queued to non-queued.
- /// </summary>
- internal override bool RequiresAtomicStartTransition => false;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TplEventSource.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TplEventSource.cs
deleted file mode 100644
index 359d3363c54..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TplEventSource.cs
+++ /dev/null
@@ -1,571 +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 System.Runtime.CompilerServices;
-using System.Diagnostics.Tracing;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Threading.Tasks
-{
- /// <summary>Provides an event source for tracing TPL information.</summary>
- [EventSource(
- Name = "System.Threading.Tasks.TplEventSource",
- Guid = "2e5dba47-a3d2-4d16-8ee0-6671ffdcd7b5",
- LocalizationResources =
-#if CORECLR
- "System.Private.CoreLib.Resources.Strings"
-#else
- null
-#endif
- )]
- internal sealed class TplEventSource : EventSource
- {
- /// Used to determine if tasks should generate Activity IDs for themselves
- internal bool TasksSetActivityIds; // This keyword is set
- internal bool Debug;
- private bool DebugActivityId;
-
- private const int DefaultAppDomainID = 1;
-
- /// <summary>
- /// Get callbacks when the ETW sends us commands`
- /// </summary>
- protected override void OnEventCommand(EventCommandEventArgs command)
- {
- // To get the AsyncCausality events, we need to inform the AsyncCausalityTracer
- if (command.Command == EventCommand.Enable)
- AsyncCausalityTracer.EnableToETW(true);
- else if (command.Command == EventCommand.Disable)
- AsyncCausalityTracer.EnableToETW(false);
-
- if (IsEnabled(EventLevel.Informational, Keywords.TasksFlowActivityIds))
- ActivityTracker.Instance.Enable();
- else
- TasksSetActivityIds = IsEnabled(EventLevel.Informational, Keywords.TasksSetActivityIds);
-
- Debug = IsEnabled(EventLevel.Informational, Keywords.Debug);
- DebugActivityId = IsEnabled(EventLevel.Informational, Keywords.DebugActivityId);
- }
-
- /// <summary>
- /// Defines the singleton instance for the TPL ETW provider.
- /// The TPL Event provider GUID is {2e5dba47-a3d2-4d16-8ee0-6671ffdcd7b5}.
- /// </summary>
- public static readonly TplEventSource Log = new TplEventSource();
-
- /// <summary>Prevent external instantiation. All logging should go through the Log instance.</summary>
- private TplEventSource() : base(new Guid(0x2e5dba47, 0xa3d2, 0x4d16, 0x8e, 0xe0, 0x66, 0x71, 0xff, 0xdc, 0xd7, 0xb5), "System.Threading.Tasks.TplEventSource") { }
-
- /// <summary>Configured behavior of a task wait operation.</summary>
- public enum TaskWaitBehavior : int
- {
- /// <summary>A synchronous wait.</summary>
- Synchronous = 1,
- /// <summary>An asynchronous await.</summary>
- Asynchronous = 2
- }
-
- /// <summary>ETW tasks that have start/stop events.</summary>
- public static class Tasks // this name is important for EventSource
- {
- /// <summary>A parallel loop.</summary>
- public const EventTask Loop = (EventTask)1;
- /// <summary>A parallel invoke.</summary>
- public const EventTask Invoke = (EventTask)2;
- /// <summary>Executing a Task.</summary>
- public const EventTask TaskExecute = (EventTask)3;
- /// <summary>Waiting on a Task.</summary>
- public const EventTask TaskWait = (EventTask)4;
- /// <summary>A fork/join task within a loop or invoke.</summary>
- public const EventTask ForkJoin = (EventTask)5;
- /// <summary>A task is scheduled to execute.</summary>
- public const EventTask TaskScheduled = (EventTask)6;
- /// <summary>An await task continuation is scheduled to execute.</summary>
- public const EventTask AwaitTaskContinuationScheduled = (EventTask)7;
-
- /// <summary>AsyncCausalityFunctionality.</summary>
- public const EventTask TraceOperation = (EventTask)8;
- public const EventTask TraceSynchronousWork = (EventTask)9;
- }
-
- public static class Keywords // this name is important for EventSource
- {
- /// <summary>
- /// Only the most basic information about the workings of the task library
- /// This sets activity IDS and logs when tasks are schedules (or waits begin)
- /// But are otherwise silent
- /// </summary>
- public const EventKeywords TaskTransfer = (EventKeywords)1;
- /// <summary>
- /// TaskTranser events plus events when tasks start and stop
- /// </summary>
- public const EventKeywords Tasks = (EventKeywords)2;
- /// <summary>
- /// Events associted with the higher level parallel APIs
- /// </summary>
- public const EventKeywords Parallel = (EventKeywords)4;
- /// <summary>
- /// These are relatively verbose events that effectively just redirect
- /// the windows AsyncCausalityTracer to ETW
- /// </summary>
- public const EventKeywords AsyncCausalityOperation = (EventKeywords)8;
- public const EventKeywords AsyncCausalityRelation = (EventKeywords)0x10;
- public const EventKeywords AsyncCausalitySynchronousWork = (EventKeywords)0x20;
-
- /// <summary>
- /// Emit the stops as well as the schedule/start events
- /// </summary>
- public const EventKeywords TaskStops = (EventKeywords)0x40;
-
- /// <summary>
- /// TasksFlowActivityIds indicate that activity ID flow from one task
- /// to any task created by it.
- /// </summary>
- public const EventKeywords TasksFlowActivityIds = (EventKeywords)0x80;
-
- /// <summary>
- /// Events related to the happenings of async methods.
- /// </summary>
- public const EventKeywords AsyncMethod = (EventKeywords)0x100;
-
- /// <summary>
- /// TasksSetActivityIds will cause the task operations to set Activity Ids
- /// This option is incompatible with TasksFlowActivityIds flow is ignored
- /// if that keyword is set. This option is likely to be removed in the future
- /// </summary>
- public const EventKeywords TasksSetActivityIds = (EventKeywords)0x10000;
-
- /// <summary>
- /// Relatively Verbose logging meant for debugging the Task library itself. Will probably be removed in the future
- /// </summary>
- public const EventKeywords Debug = (EventKeywords)0x20000;
- /// <summary>
- /// Relatively Verbose logging meant for debugging the Task library itself. Will probably be removed in the future
- /// </summary>
- public const EventKeywords DebugActivityId = (EventKeywords)0x40000;
- }
-
- //-----------------------------------------------------------------------------------
- //
- // TPL Event IDs (must be unique)
- //
-
- /// <summary>A task is scheduled to a task scheduler.</summary>
- private const int TASKSCHEDULED_ID = 7;
- /// <summary>A task is about to execute.</summary>
- private const int TASKSTARTED_ID = 8;
- /// <summary>A task has finished executing.</summary>
- private const int TASKCOMPLETED_ID = 9;
- /// <summary>A wait on a task is beginning.</summary>
- private const int TASKWAITBEGIN_ID = 10;
- /// <summary>A wait on a task is ending.</summary>
- private const int TASKWAITEND_ID = 11;
- /// <summary>A continuation of a task is scheduled.</summary>
- private const int AWAITTASKCONTINUATIONSCHEDULED_ID = 12;
- /// <summary>A continuation of a taskWaitEnd is complete </summary>
- private const int TASKWAITCONTINUATIONCOMPLETE_ID = 13;
- /// <summary>A continuation of a taskWaitEnd is complete </summary>
- private const int TASKWAITCONTINUATIONSTARTED_ID = 19;
-
- private const int TRACEOPERATIONSTART_ID = 14;
- private const int TRACEOPERATIONSTOP_ID = 15;
- private const int TRACEOPERATIONRELATION_ID = 16;
- private const int TRACESYNCHRONOUSWORKSTART_ID = 17;
- private const int TRACESYNCHRONOUSWORKSTOP_ID = 18;
-
-
- //-----------------------------------------------------------------------------------
- //
- // Task Events
- //
-
- // These are all verbose events, so we need to call IsEnabled(EventLevel.Verbose, ALL_KEYWORDS)
- // call. However since the IsEnabled(l,k) call is more expensive than IsEnabled(), we only want
- // to incur this cost when instrumentation is enabled. So the Task codepaths that call these
- // event functions still do the check for IsEnabled()
-
- #region TaskScheduled
- /// <summary>
- /// Fired when a task is queued to a TaskScheduler.
- /// </summary>
- /// <param name="OriginatingTaskSchedulerID">The scheduler ID.</param>
- /// <param name="OriginatingTaskID">The task ID.</param>
- /// <param name="TaskID">The task ID.</param>
- /// <param name="CreatingTaskID">The task ID</param>
- /// <param name="TaskCreationOptions">The options used to create the task.</param>
- [Event(TASKSCHEDULED_ID, Task = Tasks.TaskScheduled, Version = 1, Opcode = EventOpcode.Send,
- Level = EventLevel.Informational, Keywords = Keywords.TaskTransfer | Keywords.Tasks)]
- public void TaskScheduled(
- int OriginatingTaskSchedulerID, int OriginatingTaskID, // PFX_COMMON_EVENT_HEADER
- int TaskID, int CreatingTaskID, int TaskCreationOptions, int appDomain = DefaultAppDomainID)
- {
- // IsEnabled() call is an inlined quick check that makes this very fast when provider is off
- if (IsEnabled() && IsEnabled(EventLevel.Informational, Keywords.TaskTransfer | Keywords.Tasks))
- {
- unsafe
- {
- EventData* eventPayload = stackalloc EventData[6];
- eventPayload[0].Size = sizeof(int);
- eventPayload[0].DataPointer = ((IntPtr)(&OriginatingTaskSchedulerID));
- eventPayload[0].Reserved = 0;
- eventPayload[1].Size = sizeof(int);
- eventPayload[1].DataPointer = ((IntPtr)(&OriginatingTaskID));
- eventPayload[1].Reserved = 0;
- eventPayload[2].Size = sizeof(int);
- eventPayload[2].DataPointer = ((IntPtr)(&TaskID));
- eventPayload[2].Reserved = 0;
- eventPayload[3].Size = sizeof(int);
- eventPayload[3].DataPointer = ((IntPtr)(&CreatingTaskID));
- eventPayload[3].Reserved = 0;
- eventPayload[4].Size = sizeof(int);
- eventPayload[4].DataPointer = ((IntPtr)(&TaskCreationOptions));
- eventPayload[4].Reserved = 0;
- eventPayload[5].Size = sizeof(int);
- eventPayload[5].DataPointer = ((IntPtr)(&appDomain));
- eventPayload[5].Reserved = 0;
- if (TasksSetActivityIds)
- {
- Guid childActivityId = CreateGuidForTaskID(TaskID);
- WriteEventWithRelatedActivityIdCore(TASKSCHEDULED_ID, &childActivityId, 6, eventPayload);
- }
- else
- WriteEventCore(TASKSCHEDULED_ID, 6, eventPayload);
- }
- }
- }
- #endregion
-
- #region TaskStarted
- /// <summary>
- /// Fired just before a task actually starts executing.
- /// </summary>
- /// <param name="OriginatingTaskSchedulerID">The scheduler ID.</param>
- /// <param name="OriginatingTaskID">The task ID.</param>
- /// <param name="TaskID">The task ID.</param>
- [Event(TASKSTARTED_ID,
- Level = EventLevel.Informational, Keywords = Keywords.Tasks)]
- public void TaskStarted(
- int OriginatingTaskSchedulerID, int OriginatingTaskID, // PFX_COMMON_EVENT_HEADER
- int TaskID)
- {
- if (IsEnabled(EventLevel.Informational, Keywords.Tasks))
- WriteEvent(TASKSTARTED_ID, OriginatingTaskSchedulerID, OriginatingTaskID, TaskID);
- }
- #endregion
-
- #region TaskCompleted
- /// <summary>
- /// Fired right after a task finished executing.
- /// </summary>
- /// <param name="OriginatingTaskSchedulerID">The scheduler ID.</param>
- /// <param name="OriginatingTaskID">The task ID.</param>
- /// <param name="TaskID">The task ID.</param>
- /// <param name="IsExceptional">Whether the task completed due to an error.</param>
- [Event(TASKCOMPLETED_ID, Version = 1,
- Level = EventLevel.Informational, Keywords = Keywords.TaskStops)]
- public void TaskCompleted(
- int OriginatingTaskSchedulerID, int OriginatingTaskID, // PFX_COMMON_EVENT_HEADER
- int TaskID, bool IsExceptional)
- {
- if (IsEnabled(EventLevel.Informational, Keywords.Tasks))
- {
- unsafe
- {
- EventData* eventPayload = stackalloc EventData[4];
- int isExceptionalInt = IsExceptional ? 1 : 0;
- eventPayload[0].Size = sizeof(int);
- eventPayload[0].DataPointer = ((IntPtr)(&OriginatingTaskSchedulerID));
- eventPayload[0].Reserved = 0;
- eventPayload[1].Size = sizeof(int);
- eventPayload[1].DataPointer = ((IntPtr)(&OriginatingTaskID));
- eventPayload[1].Reserved = 0;
- eventPayload[2].Size = sizeof(int);
- eventPayload[2].DataPointer = ((IntPtr)(&TaskID));
- eventPayload[2].Reserved = 0;
- eventPayload[3].Size = sizeof(int);
- eventPayload[3].DataPointer = ((IntPtr)(&isExceptionalInt));
- eventPayload[3].Reserved = 0;
- WriteEventCore(TASKCOMPLETED_ID, 4, eventPayload);
- }
- }
- }
- #endregion
-
- #region TaskWaitBegin
- /// <summary>
- /// Fired when starting to wait for a taks's completion explicitly or implicitly.
- /// </summary>
- /// <param name="OriginatingTaskSchedulerID">The scheduler ID.</param>
- /// <param name="OriginatingTaskID">The task ID.</param>
- /// <param name="TaskID">The task ID.</param>
- /// <param name="Behavior">Configured behavior for the wait.</param>
- /// <param name="ContinueWithTaskID">
- /// If known, if 'TaskID' has a 'continueWith' task, mention give its ID here.
- /// 0 means unknown. This allows better visualization of the common sequential chaining case.
- /// </param>
- [Event(TASKWAITBEGIN_ID, Version = 3, Task = TplEventSource.Tasks.TaskWait, Opcode = EventOpcode.Send,
- Level = EventLevel.Informational, Keywords = Keywords.TaskTransfer | Keywords.Tasks)]
- public void TaskWaitBegin(
- int OriginatingTaskSchedulerID, int OriginatingTaskID, // PFX_COMMON_EVENT_HEADER
- int TaskID, TaskWaitBehavior Behavior, int ContinueWithTaskID)
- {
- if (IsEnabled() && IsEnabled(EventLevel.Informational, Keywords.TaskTransfer | Keywords.Tasks))
- {
- unsafe
- {
- EventData* eventPayload = stackalloc EventData[5];
- eventPayload[0].Size = sizeof(int);
- eventPayload[0].DataPointer = ((IntPtr)(&OriginatingTaskSchedulerID));
- eventPayload[0].Reserved = 0;
- eventPayload[1].Size = sizeof(int);
- eventPayload[1].DataPointer = ((IntPtr)(&OriginatingTaskID));
- eventPayload[1].Reserved = 0;
- eventPayload[2].Size = sizeof(int);
- eventPayload[2].DataPointer = ((IntPtr)(&TaskID));
- eventPayload[2].Reserved = 0;
- eventPayload[3].Size = sizeof(int);
- eventPayload[3].DataPointer = ((IntPtr)(&Behavior));
- eventPayload[3].Reserved = 0;
- eventPayload[4].Size = sizeof(int);
- eventPayload[4].DataPointer = ((IntPtr)(&ContinueWithTaskID));
- eventPayload[4].Reserved = 0;
- if (TasksSetActivityIds)
- {
- Guid childActivityId = CreateGuidForTaskID(TaskID);
- WriteEventWithRelatedActivityIdCore(TASKWAITBEGIN_ID, &childActivityId, 5, eventPayload);
- }
- else
- {
- WriteEventCore(TASKWAITBEGIN_ID, 5, eventPayload);
- }
- }
- }
- }
- #endregion
-
- /// <summary>
- /// Fired when the wait for a tasks completion returns.
- /// </summary>
- /// <param name="OriginatingTaskSchedulerID">The scheduler ID.</param>
- /// <param name="OriginatingTaskID">The task ID.</param>
- /// <param name="TaskID">The task ID.</param>
- [Event(TASKWAITEND_ID,
- Level = EventLevel.Verbose, Keywords = Keywords.Tasks)]
- public void TaskWaitEnd(
- int OriginatingTaskSchedulerID, int OriginatingTaskID, // PFX_COMMON_EVENT_HEADER
- int TaskID)
- {
- // Log an event if indicated.
- if (IsEnabled() && IsEnabled(EventLevel.Verbose, Keywords.Tasks))
- WriteEvent(TASKWAITEND_ID, OriginatingTaskSchedulerID, OriginatingTaskID, TaskID);
- }
-
- /// <summary>
- /// Fired when the work (method) associated with a TaskWaitEnd completes
- /// </summary>
- /// <param name="TaskID">The task ID.</param>
- [Event(TASKWAITCONTINUATIONCOMPLETE_ID,
- Level = EventLevel.Verbose, Keywords = Keywords.TaskStops)]
- public void TaskWaitContinuationComplete(int TaskID)
- {
- // Log an event if indicated.
- if (IsEnabled() && IsEnabled(EventLevel.Verbose, Keywords.Tasks))
- WriteEvent(TASKWAITCONTINUATIONCOMPLETE_ID, TaskID);
- }
-
- /// <summary>
- /// Fired when the work (method) associated with a TaskWaitEnd completes
- /// </summary>
- /// <param name="TaskID">The task ID.</param>
- [Event(TASKWAITCONTINUATIONSTARTED_ID,
- Level = EventLevel.Verbose, Keywords = Keywords.TaskStops)]
- public void TaskWaitContinuationStarted(int TaskID)
- {
- // Log an event if indicated.
- if (IsEnabled() && IsEnabled(EventLevel.Verbose, Keywords.Tasks))
- WriteEvent(TASKWAITCONTINUATIONSTARTED_ID, TaskID);
- }
-
- /// <summary>
- /// Fired when the an asynchronous continuation for a task is scheduled
- /// </summary>
- /// <param name="OriginatingTaskSchedulerID">The scheduler ID.</param>
- /// <param name="OriginatingTaskID">The task ID.</param>
- [Event(AWAITTASKCONTINUATIONSCHEDULED_ID, Task = Tasks.AwaitTaskContinuationScheduled, Opcode = EventOpcode.Send,
- Level = EventLevel.Informational, Keywords = Keywords.TaskTransfer | Keywords.Tasks)]
- public void AwaitTaskContinuationScheduled(
- int OriginatingTaskSchedulerID, int OriginatingTaskID, // PFX_COMMON_EVENT_HEADER
- int ContinuwWithTaskId)
- {
- if (IsEnabled() && IsEnabled(EventLevel.Informational, Keywords.TaskTransfer | Keywords.Tasks))
- {
- unsafe
- {
- EventData* eventPayload = stackalloc EventData[3];
- eventPayload[0].Size = sizeof(int);
- eventPayload[0].DataPointer = ((IntPtr)(&OriginatingTaskSchedulerID));
- eventPayload[0].Reserved = 0;
- eventPayload[1].Size = sizeof(int);
- eventPayload[1].DataPointer = ((IntPtr)(&OriginatingTaskID));
- eventPayload[1].Reserved = 0;
- eventPayload[2].Size = sizeof(int);
- eventPayload[2].DataPointer = ((IntPtr)(&ContinuwWithTaskId));
- eventPayload[2].Reserved = 0;
- if (TasksSetActivityIds)
- {
- Guid continuationActivityId = CreateGuidForTaskID(ContinuwWithTaskId);
- WriteEventWithRelatedActivityIdCore(AWAITTASKCONTINUATIONSCHEDULED_ID, &continuationActivityId, 3, eventPayload);
- }
- else
- WriteEventCore(AWAITTASKCONTINUATIONSCHEDULED_ID, 3, eventPayload);
- }
- }
- }
-
- [Event(TRACEOPERATIONSTART_ID, Version = 1,
- Level = EventLevel.Informational, Keywords = Keywords.AsyncCausalityOperation)]
- public void TraceOperationBegin(int TaskID, string OperationName, long RelatedContext)
- {
- if (IsEnabled() && IsEnabled(EventLevel.Informational, Keywords.AsyncCausalityOperation))
- {
- unsafe
- {
- fixed (char* operationNamePtr = OperationName)
- {
- EventData* eventPayload = stackalloc EventData[3];
- eventPayload[0].Size = sizeof(int);
- eventPayload[0].DataPointer = ((IntPtr)(&TaskID));
- eventPayload[0].Reserved = 0;
-
- eventPayload[1].Size = ((OperationName.Length + 1) * 2);
- eventPayload[1].DataPointer = ((IntPtr)operationNamePtr);
- eventPayload[1].Reserved = 0;
-
- eventPayload[2].Size = sizeof(long);
- eventPayload[2].DataPointer = ((IntPtr)(&RelatedContext));
- eventPayload[2].Reserved = 0;
- WriteEventCore(TRACEOPERATIONSTART_ID, 3, eventPayload);
- }
- }
- }
- }
-
- [Event(TRACEOPERATIONRELATION_ID, Version = 1,
- Level = EventLevel.Informational, Keywords = Keywords.AsyncCausalityRelation)]
- public void TraceOperationRelation(int TaskID, CausalityRelation Relation)
- {
- if (IsEnabled() && IsEnabled(EventLevel.Informational, Keywords.AsyncCausalityRelation))
- WriteEvent(TRACEOPERATIONRELATION_ID, TaskID, (int)Relation); // optimized overload for this exists
- }
-
- [Event(TRACEOPERATIONSTOP_ID, Version = 1,
- Level = EventLevel.Informational, Keywords = Keywords.AsyncCausalityOperation)]
- public void TraceOperationEnd(int TaskID, AsyncCausalityStatus Status)
- {
- if (IsEnabled() && IsEnabled(EventLevel.Informational, Keywords.AsyncCausalityOperation))
- WriteEvent(TRACEOPERATIONSTOP_ID, TaskID, (int)Status); // optimized overload for this exists
- }
-
- [Event(TRACESYNCHRONOUSWORKSTART_ID, Version = 1,
- Level = EventLevel.Informational, Keywords = Keywords.AsyncCausalitySynchronousWork)]
- public void TraceSynchronousWorkBegin(int TaskID, CausalitySynchronousWork Work)
- {
- if (IsEnabled() && IsEnabled(EventLevel.Informational, Keywords.AsyncCausalitySynchronousWork))
- WriteEvent(TRACESYNCHRONOUSWORKSTART_ID, TaskID, (int)Work); // optimized overload for this exists
- }
-
- [Event(TRACESYNCHRONOUSWORKSTOP_ID, Version = 1,
- Level = EventLevel.Informational, Keywords = Keywords.AsyncCausalitySynchronousWork)]
- public void TraceSynchronousWorkEnd(CausalitySynchronousWork Work)
- {
- if (IsEnabled() && IsEnabled(EventLevel.Informational, Keywords.AsyncCausalitySynchronousWork))
- {
- unsafe
- {
- EventData* eventPayload = stackalloc EventData[1];
- eventPayload[0].Size = sizeof(int);
- eventPayload[0].DataPointer = ((IntPtr)(&Work));
- eventPayload[0].Reserved = 0;
-
- WriteEventCore(TRACESYNCHRONOUSWORKSTOP_ID, 1, eventPayload);
- }
- }
- }
-
- [NonEvent]
- public unsafe void RunningContinuation(int TaskID, object Object) { RunningContinuation(TaskID, (long)*((void**)Unsafe.AsPointer(ref Object))); }
- [Event(20, Keywords = Keywords.Debug)]
- private void RunningContinuation(int TaskID, long Object)
- {
- if (Debug)
- WriteEvent(20, TaskID, Object);
- }
-
- [NonEvent]
- public unsafe void RunningContinuationList(int TaskID, int Index, object Object) { RunningContinuationList(TaskID, Index, (long)*((void**)Unsafe.AsPointer(ref Object))); }
-
- [Event(21, Keywords = Keywords.Debug)]
- public void RunningContinuationList(int TaskID, int Index, long Object)
- {
- if (Debug)
- WriteEvent(21, TaskID, Index, Object);
- }
-
- [Event(23, Keywords = Keywords.Debug)]
- public void DebugFacilityMessage(string Facility, string Message) { WriteEvent(23, Facility, Message); }
-
- [Event(24, Keywords = Keywords.Debug)]
- public void DebugFacilityMessage1(string Facility, string Message, string Value1) { WriteEvent(24, Facility, Message, Value1); }
-
- [Event(25, Keywords = Keywords.DebugActivityId)]
- public void SetActivityId(Guid NewId)
- {
- if (DebugActivityId)
- WriteEvent(25, NewId);
- }
-
- [Event(26, Keywords = Keywords.Debug)]
- public void NewID(int TaskID)
- {
- if (Debug)
- WriteEvent(26, TaskID);
- }
-
- [NonEvent]
- public void IncompleteAsyncMethod(IAsyncStateMachineBox stateMachineBox)
- {
- System.Diagnostics.Debug.Assert(stateMachineBox != null);
- if (IsEnabled(EventLevel.Warning, Keywords.AsyncMethod))
- {
- IAsyncStateMachine stateMachine = stateMachineBox.GetStateMachineObject();
- if (stateMachine != null)
- {
- string description = AsyncMethodBuilderCore.GetAsyncStateMachineDescription(stateMachine);
- IncompleteAsyncMethod(description);
- }
- }
- }
-
- [Event(27, Level = EventLevel.Warning, Keywords = Keywords.AsyncMethod)]
- private void IncompleteAsyncMethod(string stateMachineDescription) =>
- WriteEvent(27, stateMachineDescription);
-
- /// <summary>
- /// Activity IDs are GUIDS but task IDS are integers (and are not unique across appdomains
- /// This routine creates a process wide unique GUID given a task ID
- /// </summary>
- internal static Guid CreateGuidForTaskID(int taskID)
- {
- // The thread pool generated a process wide unique GUID from a task GUID by
- // using the taskGuid, the appdomain ID, and 8 bytes of 'randomization' chosen by
- // using the last 8 bytes as the provider GUID for this provider.
- // These were generated by CreateGuid, and are reasonably random (and thus unlikely to collide
- uint pid = EventSource.s_currentPid;
- return new Guid(taskID,
- (short)DefaultAppDomainID, (short)(DefaultAppDomainID >> 16),
- (byte)pid, (byte)(pid >> 8), (byte)(pid >> 16), (byte)(pid >> 24),
- 0xff, 0xdc, 0xd7, 0xb5);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs
deleted file mode 100644
index d945938bb0e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs
+++ /dev/null
@@ -1,796 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Threading.Tasks.Sources;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Threading.Tasks
-{
- // TYPE SAFETY WARNING:
- // This code uses Unsafe.As to cast _obj. This is done in order to minimize the costs associated with
- // casting _obj to a variety of different types that can be stored in a ValueTask, e.g. Task<TResult>
- // vs IValueTaskSource<TResult>. Previous attempts at this were faulty due to using a separate field
- // to store information about the type of the object in _obj; this is faulty because if the ValueTask
- // is stored into a field, concurrent read/writes can result in tearing the _obj from the type information
- // stored in a separate field. This means we can rely only on the _obj field to determine how to handle
- // it. As such, the pattern employed is to copy _obj into a local obj, and then check it for null and
- // type test against Task/Task<TResult>. Since the ValueTask can only be constructed with null, Task,
- // or IValueTaskSource, we can then be confident in knowing that if it doesn't match one of those values,
- // it must be an IValueTaskSource, and we can use Unsafe.As. This could be defeated by other unsafe means,
- // like private reflection or using Unsafe.As manually, but at that point you're already doing things
- // that can violate type safety; we only care about getting correct behaviors when using "safe" code.
- // There are still other race conditions in user's code that can result in errors, but such errors don't
- // cause ValueTask to violate type safety.
-
- /// <summary>Provides an awaitable result of an asynchronous operation.</summary>
- /// <remarks>
- /// <see cref="ValueTask"/> instances are meant to be directly awaited. To do more complicated operations with them, a <see cref="Task"/>
- /// should be extracted using <see cref="AsTask"/>. Such operations might include caching a task instance to be awaited later,
- /// registering multiple continuations with a single task, awaiting the same task multiple times, and using combinators over
- /// multiple operations:
- /// <list type="bullet">
- /// <item>
- /// Once the result of a <see cref="ValueTask"/> instance has been retrieved, do not attempt to retrieve it again.
- /// <see cref="ValueTask"/> instances may be backed by <see cref="IValueTaskSource"/> instances that are reusable, and such
- /// instances may use the act of retrieving the instances result as a notification that the instance may now be reused for
- /// a different operation. Attempting to then reuse that same <see cref="ValueTask"/> results in undefined behavior.
- /// </item>
- /// <item>
- /// Do not attempt to add multiple continuations to the same <see cref="ValueTask"/>. While this might work if the
- /// <see cref="ValueTask"/> wraps a <code>T</code> or a <see cref="Task"/>, it may not work if the <see cref="ValueTask"/>
- /// was constructed from an <see cref="IValueTaskSource"/>.
- /// </item>
- /// <item>
- /// Some operations that return a <see cref="ValueTask"/> may invalidate it based on some subsequent operation being performed.
- /// Unless otherwise documented, assume that a <see cref="ValueTask"/> should be awaited prior to performing any additional operations
- /// on the instance from which it was retrieved.
- /// </item>
- /// </list>
- /// </remarks>
- [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder))]
- [StructLayout(LayoutKind.Auto)]
- public readonly struct ValueTask : IEquatable<ValueTask>
- {
- /// <summary>A task canceled using `new CancellationToken(true)`.</summary>
- private static readonly Task s_canceledTask = Task.FromCanceled(new CancellationToken(canceled: true));
-
- /// <summary>A successfully completed task.</summary>
- internal static Task CompletedTask => Task.CompletedTask;
-
- /// <summary>null if representing a successful synchronous completion, otherwise a <see cref="Task"/> or a <see cref="IValueTaskSource"/>.</summary>
- internal readonly object? _obj;
- /// <summary>Opaque value passed through to the <see cref="IValueTaskSource"/>.</summary>
- internal readonly short _token;
- /// <summary>true to continue on the capture context; otherwise, true.</summary>
- /// <remarks>Stored in the <see cref="ValueTask"/> rather than in the configured awaiter to utilize otherwise padding space.</remarks>
- internal readonly bool _continueOnCapturedContext;
-
- // An instance created with the default ctor (a zero init'd struct) represents a synchronously, successfully completed operation.
-
- /// <summary>Initialize the <see cref="ValueTask"/> with a <see cref="Task"/> that represents the operation.</summary>
- /// <param name="task">The task.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ValueTask(Task task)
- {
- if (task == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.task);
- }
-
- _obj = task;
-
- _continueOnCapturedContext = true;
- _token = 0;
- }
-
- /// <summary>Initialize the <see cref="ValueTask"/> with a <see cref="IValueTaskSource"/> object that represents the operation.</summary>
- /// <param name="source">The source.</param>
- /// <param name="token">Opaque value passed through to the <see cref="IValueTaskSource"/>.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ValueTask(IValueTaskSource source, short token)
- {
- if (source == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
- }
-
- _obj = source;
- _token = token;
-
- _continueOnCapturedContext = true;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private ValueTask(object? obj, short token, bool continueOnCapturedContext)
- {
- _obj = obj;
- _token = token;
- _continueOnCapturedContext = continueOnCapturedContext;
- }
-
- /// <summary>Returns the hash code for this instance.</summary>
- public override int GetHashCode() => _obj?.GetHashCode() ?? 0;
-
- /// <summary>Returns a value indicating whether this value is equal to a specified <see cref="object"/>.</summary>
- public override bool Equals(object? obj) =>
- obj is ValueTask &&
- Equals((ValueTask)obj);
-
- /// <summary>Returns a value indicating whether this value is equal to a specified <see cref="ValueTask"/> value.</summary>
- public bool Equals(ValueTask other) => _obj == other._obj && _token == other._token;
-
- /// <summary>Returns a value indicating whether two <see cref="ValueTask"/> values are equal.</summary>
- public static bool operator ==(ValueTask left, ValueTask right) =>
- left.Equals(right);
-
- /// <summary>Returns a value indicating whether two <see cref="ValueTask"/> values are not equal.</summary>
- public static bool operator !=(ValueTask left, ValueTask right) =>
- !left.Equals(right);
-
- /// <summary>
- /// Gets a <see cref="Task"/> object to represent this ValueTask.
- /// </summary>
- /// <remarks>
- /// It will either return the wrapped task object if one exists, or it'll
- /// manufacture a new task object to represent the result.
- /// </remarks>
- public Task AsTask()
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
- return
- obj == null ? CompletedTask :
- obj as Task ??
- GetTaskForValueTaskSource(Unsafe.As<IValueTaskSource>(obj));
- }
-
- /// <summary>Gets a <see cref="ValueTask"/> that may be used at any point in the future.</summary>
- public ValueTask Preserve() => _obj == null ? this : new ValueTask(AsTask());
-
- /// <summary>Creates a <see cref="Task"/> to represent the <see cref="IValueTaskSource"/>.</summary>
- /// <remarks>
- /// The <see cref="IValueTaskSource"/> is passed in rather than reading and casting <see cref="_obj"/>
- /// so that the caller can pass in an object it's already validated.
- /// </remarks>
- private Task GetTaskForValueTaskSource(IValueTaskSource t)
- {
- ValueTaskSourceStatus status = t.GetStatus(_token);
- if (status != ValueTaskSourceStatus.Pending)
- {
- try
- {
- // Propagate any exceptions that may have occurred, then return
- // an already successfully completed task.
- t.GetResult(_token);
- return CompletedTask;
-
- // If status is Faulted or Canceled, GetResult should throw. But
- // we can't guarantee every implementation will do the "right thing".
- // If it doesn't throw, we just treat that as success and ignore
- // the status.
- }
- catch (Exception exc)
- {
- if (status == ValueTaskSourceStatus.Canceled)
- {
- if (exc is OperationCanceledException oce)
- {
- var task = new Task();
- task.TrySetCanceled(oce.CancellationToken, oce);
- return task;
- }
-
- return s_canceledTask;
- }
- else
- {
- return Task.FromException(exc);
- }
- }
- }
-
- return new ValueTaskSourceAsTask(t, _token);
- }
-
- /// <summary>Type used to create a <see cref="Task"/> to represent a <see cref="IValueTaskSource"/>.</summary>
- private sealed class ValueTaskSourceAsTask : Task
- {
- private static readonly Action<object?> s_completionAction = state =>
- {
- if (!(state is ValueTaskSourceAsTask vtst) ||
- !(vtst._source is IValueTaskSource source))
- {
- // This could only happen if the IValueTaskSource passed the wrong state
- // or if this callback were invoked multiple times such that the state
- // was previously nulled out.
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.state);
- return;
- }
-
- vtst._source = null;
- ValueTaskSourceStatus status = source.GetStatus(vtst._token);
- try
- {
- source.GetResult(vtst._token);
- vtst.TrySetResult();
- }
- catch (Exception exc)
- {
- if (status == ValueTaskSourceStatus.Canceled)
- {
- if (exc is OperationCanceledException oce)
- {
- vtst.TrySetCanceled(oce.CancellationToken, oce);
- }
- else
- {
- vtst.TrySetCanceled(new CancellationToken(true));
- }
- }
- else
- {
- vtst.TrySetException(exc);
- }
- }
- };
-
- /// <summary>The associated <see cref="IValueTaskSource"/>.</summary>
- private IValueTaskSource? _source;
- /// <summary>The token to pass through to operations on <see cref="_source"/></summary>
- private readonly short _token;
-
- internal ValueTaskSourceAsTask(IValueTaskSource source, short token)
- {
- _token = token;
- _source = source;
- source.OnCompleted(s_completionAction, this, token, ValueTaskSourceOnCompletedFlags.None);
- }
- }
-
- /// <summary>Gets whether the <see cref="ValueTask"/> represents a completed operation.</summary>
- public bool IsCompleted
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
-
- if (obj == null)
- {
- return true;
- }
-
- if (obj is Task t)
- {
- return t.IsCompleted;
- }
-
- return Unsafe.As<IValueTaskSource>(obj).GetStatus(_token) != ValueTaskSourceStatus.Pending;
- }
- }
-
- /// <summary>Gets whether the <see cref="ValueTask"/> represents a successfully completed operation.</summary>
- public bool IsCompletedSuccessfully
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
-
- if (obj == null)
- {
- return true;
- }
-
- if (obj is Task t)
- {
- return t.IsCompletedSuccessfully;
- }
-
- return Unsafe.As<IValueTaskSource>(obj).GetStatus(_token) == ValueTaskSourceStatus.Succeeded;
- }
- }
-
- /// <summary>Gets whether the <see cref="ValueTask"/> represents a failed operation.</summary>
- public bool IsFaulted
- {
- get
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
-
- if (obj == null)
- {
- return false;
- }
-
- if (obj is Task t)
- {
- return t.IsFaulted;
- }
-
- return Unsafe.As<IValueTaskSource>(obj).GetStatus(_token) == ValueTaskSourceStatus.Faulted;
- }
- }
-
- /// <summary>Gets whether the <see cref="ValueTask"/> represents a canceled operation.</summary>
- /// <remarks>
- /// If the <see cref="ValueTask"/> is backed by a result or by a <see cref="IValueTaskSource"/>,
- /// this will always return false. If it's backed by a <see cref="Task"/>, it'll return the
- /// value of the task's <see cref="Task.IsCanceled"/> property.
- /// </remarks>
- public bool IsCanceled
- {
- get
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
-
- if (obj == null)
- {
- return false;
- }
-
- if (obj is Task t)
- {
- return t.IsCanceled;
- }
-
- return Unsafe.As<IValueTaskSource>(obj).GetStatus(_token) == ValueTaskSourceStatus.Canceled;
- }
- }
-
- /// <summary>Throws the exception that caused the <see cref="ValueTask"/> to fail. If it completed successfully, nothing is thrown.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal void ThrowIfCompletedUnsuccessfully()
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
-
- if (obj != null)
- {
- if (obj is Task t)
- {
- TaskAwaiter.ValidateEnd(t);
- }
- else
- {
- Unsafe.As<IValueTaskSource>(obj).GetResult(_token);
- }
- }
- }
-
- /// <summary>Gets an awaiter for this <see cref="ValueTask"/>.</summary>
- public ValueTaskAwaiter GetAwaiter() => new ValueTaskAwaiter(in this);
-
- /// <summary>Configures an awaiter for this <see cref="ValueTask"/>.</summary>
- /// <param name="continueOnCapturedContext">
- /// true to attempt to marshal the continuation back to the captured context; otherwise, false.
- /// </param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) =>
- new ConfiguredValueTaskAwaitable(new ValueTask(_obj, _token, continueOnCapturedContext));
- }
-
- /// <summary>Provides a value type that can represent a synchronously available value or a task object.</summary>
- /// <typeparam name="TResult">Specifies the type of the result.</typeparam>
- /// <remarks>
- /// <see cref="ValueTask{TResult}"/> instances are meant to be directly awaited. To do more complicated operations with them, a <see cref="Task{TResult}"/>
- /// should be extracted using <see cref="AsTask"/>. Such operations might include caching a task instance to be awaited later,
- /// registering multiple continuations with a single task, awaiting the same task multiple times, and using combinators over
- /// multiple operations:
- /// <list type="bullet">
- /// <item>
- /// Once the result of a <see cref="ValueTask{TResult}"/> instance has been retrieved, do not attempt to retrieve it again.
- /// <see cref="ValueTask{TResult}"/> instances may be backed by <see cref="IValueTaskSource{TResult}"/> instances that are reusable, and such
- /// instances may use the act of retrieving the instances result as a notification that the instance may now be reused for
- /// a different operation. Attempting to then reuse that same <see cref="ValueTask{TResult}"/> results in undefined behavior.
- /// </item>
- /// <item>
- /// Do not attempt to add multiple continuations to the same <see cref="ValueTask{TResult}"/>. While this might work if the
- /// <see cref="ValueTask{TResult}"/> wraps a <code>T</code> or a <see cref="Task{TResult}"/>, it may not work if the <see cref="Task{TResult}"/>
- /// was constructed from an <see cref="IValueTaskSource{TResult}"/>.
- /// </item>
- /// <item>
- /// Some operations that return a <see cref="ValueTask{TResult}"/> may invalidate it based on some subsequent operation being performed.
- /// Unless otherwise documented, assume that a <see cref="ValueTask{TResult}"/> should be awaited prior to performing any additional operations
- /// on the instance from which it was retrieved.
- /// </item>
- /// </list>
- /// </remarks>
- [AsyncMethodBuilder(typeof(AsyncValueTaskMethodBuilder<>))]
- [StructLayout(LayoutKind.Auto)]
- public readonly struct ValueTask<TResult> : IEquatable<ValueTask<TResult>>
- {
- /// <summary>A task canceled using `new CancellationToken(true)`. Lazily created only when first needed.</summary>
- private static Task<TResult>? s_canceledTask;
- /// <summary>null if <see cref="_result"/> has the result, otherwise a <see cref="Task{TResult}"/> or a <see cref="IValueTaskSource{TResult}"/>.</summary>
- internal readonly object? _obj;
- /// <summary>The result to be used if the operation completed successfully synchronously.</summary>
- [AllowNull] internal readonly TResult _result;
- /// <summary>Opaque value passed through to the <see cref="IValueTaskSource{TResult}"/>.</summary>
- internal readonly short _token;
- /// <summary>true to continue on the captured context; otherwise, false.</summary>
- /// <remarks>Stored in the <see cref="ValueTask{TResult}"/> rather than in the configured awaiter to utilize otherwise padding space.</remarks>
- internal readonly bool _continueOnCapturedContext;
-
- // An instance created with the default ctor (a zero init'd struct) represents a synchronously, successfully completed operation
- // with a result of default(TResult).
-
- /// <summary>Initialize the <see cref="ValueTask{TResult}"/> with a <typeparamref name="TResult"/> result value.</summary>
- /// <param name="result">The result.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ValueTask(TResult result)
- {
- _result = result;
-
- _obj = null;
- _continueOnCapturedContext = true;
- _token = 0;
- }
-
- /// <summary>Initialize the <see cref="ValueTask{TResult}"/> with a <see cref="Task{TResult}"/> that represents the operation.</summary>
- /// <param name="task">The task.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ValueTask(Task<TResult> task)
- {
- if (task == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.task);
- }
-
- _obj = task;
-
- _result = default;
- _continueOnCapturedContext = true;
- _token = 0;
- }
-
- /// <summary>Initialize the <see cref="ValueTask{TResult}"/> with a <see cref="IValueTaskSource{TResult}"/> object that represents the operation.</summary>
- /// <param name="source">The source.</param>
- /// <param name="token">Opaque value passed through to the <see cref="IValueTaskSource"/>.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ValueTask(IValueTaskSource<TResult> source, short token)
- {
- if (source == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
- }
-
- _obj = source;
- _token = token;
-
- _result = default;
- _continueOnCapturedContext = true;
- }
-
- /// <summary>Non-verified initialization of the struct to the specified values.</summary>
- /// <param name="obj">The object.</param>
- /// <param name="result">The result.</param>
- /// <param name="token">The token.</param>
- /// <param name="continueOnCapturedContext">true to continue on captured context; otherwise, false.</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private ValueTask(object? obj, TResult result, short token, bool continueOnCapturedContext)
- {
- _obj = obj;
- _result = result;
- _token = token;
- _continueOnCapturedContext = continueOnCapturedContext;
- }
-
-
- /// <summary>Returns the hash code for this instance.</summary>
- public override int GetHashCode() =>
- _obj != null ? _obj.GetHashCode() :
- _result != null ? _result.GetHashCode() :
- 0;
-
- /// <summary>Returns a value indicating whether this value is equal to a specified <see cref="object"/>.</summary>
- public override bool Equals(object? obj) =>
- obj is ValueTask<TResult> &&
- Equals((ValueTask<TResult>)obj);
-
- /// <summary>Returns a value indicating whether this value is equal to a specified <see cref="ValueTask{TResult}"/> value.</summary>
- public bool Equals(ValueTask<TResult> other) =>
- _obj != null || other._obj != null ?
- _obj == other._obj && _token == other._token :
- EqualityComparer<TResult>.Default.Equals(_result, other._result);
-
- /// <summary>Returns a value indicating whether two <see cref="ValueTask{TResult}"/> values are equal.</summary>
- public static bool operator ==(ValueTask<TResult> left, ValueTask<TResult> right) =>
- left.Equals(right);
-
- /// <summary>Returns a value indicating whether two <see cref="ValueTask{TResult}"/> values are not equal.</summary>
- public static bool operator !=(ValueTask<TResult> left, ValueTask<TResult> right) =>
- !left.Equals(right);
-
- /// <summary>
- /// Gets a <see cref="Task{TResult}"/> object to represent this ValueTask.
- /// </summary>
- /// <remarks>
- /// It will either return the wrapped task object if one exists, or it'll
- /// manufacture a new task object to represent the result.
- /// </remarks>
- public Task<TResult> AsTask()
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj == null)
- {
- return AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result);
- }
-
- if (obj is Task<TResult> t)
- {
- return t;
- }
-
- return GetTaskForValueTaskSource(Unsafe.As<IValueTaskSource<TResult>>(obj));
- }
-
- /// <summary>Gets a <see cref="ValueTask{TResult}"/> that may be used at any point in the future.</summary>
- public ValueTask<TResult> Preserve() => _obj == null ? this : new ValueTask<TResult>(AsTask());
-
- /// <summary>Creates a <see cref="Task{TResult}"/> to represent the <see cref="IValueTaskSource{TResult}"/>.</summary>
- /// <remarks>
- /// The <see cref="IValueTaskSource{TResult}"/> is passed in rather than reading and casting <see cref="_obj"/>
- /// so that the caller can pass in an object it's already validated.
- /// </remarks>
- private Task<TResult> GetTaskForValueTaskSource(IValueTaskSource<TResult> t)
- {
- ValueTaskSourceStatus status = t.GetStatus(_token);
- if (status != ValueTaskSourceStatus.Pending)
- {
- try
- {
- // Get the result of the operation and return a task for it.
- // If any exception occurred, propagate it
- return AsyncTaskMethodBuilder<TResult>.GetTaskForResult(t.GetResult(_token));
-
- // If status is Faulted or Canceled, GetResult should throw. But
- // we can't guarantee every implementation will do the "right thing".
- // If it doesn't throw, we just treat that as success and ignore
- // the status.
- }
- catch (Exception exc)
- {
- if (status == ValueTaskSourceStatus.Canceled)
- {
- if (exc is OperationCanceledException oce)
- {
- var task = new Task<TResult>();
- task.TrySetCanceled(oce.CancellationToken, oce);
- return task;
- }
-
- Task<TResult>? canceledTask = s_canceledTask;
- if (canceledTask == null)
- {
- // Benign race condition to initialize cached task, as identity doesn't matter.
- s_canceledTask = canceledTask = Task.FromCanceled<TResult>(new CancellationToken(true));
- }
- return canceledTask;
- }
- else
- {
- return Task.FromException<TResult>(exc);
- }
- }
- }
-
- return new ValueTaskSourceAsTask(t, _token);
- }
-
- /// <summary>Type used to create a <see cref="Task{TResult}"/> to represent a <see cref="IValueTaskSource{TResult}"/>.</summary>
- private sealed class ValueTaskSourceAsTask : Task<TResult>
- {
- private static readonly Action<object?> s_completionAction = state =>
- {
- if (!(state is ValueTaskSourceAsTask vtst) ||
- !(vtst._source is IValueTaskSource<TResult> source))
- {
- // This could only happen if the IValueTaskSource<TResult> passed the wrong state
- // or if this callback were invoked multiple times such that the state
- // was previously nulled out.
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.state);
- return;
- }
-
- vtst._source = null;
- ValueTaskSourceStatus status = source.GetStatus(vtst._token);
- try
- {
- vtst.TrySetResult(source.GetResult(vtst._token));
- }
- catch (Exception exc)
- {
- if (status == ValueTaskSourceStatus.Canceled)
- {
- if (exc is OperationCanceledException oce)
- {
- vtst.TrySetCanceled(oce.CancellationToken, oce);
- }
- else
- {
- vtst.TrySetCanceled(new CancellationToken(true));
- }
- }
- else
- {
- vtst.TrySetException(exc);
- }
- }
- };
-
- /// <summary>The associated <see cref="IValueTaskSource"/>.</summary>
- private IValueTaskSource<TResult>? _source;
- /// <summary>The token to pass through to operations on <see cref="_source"/></summary>
- private readonly short _token;
-
- public ValueTaskSourceAsTask(IValueTaskSource<TResult> source, short token)
- {
- _source = source;
- _token = token;
- source.OnCompleted(s_completionAction, this, token, ValueTaskSourceOnCompletedFlags.None);
- }
- }
-
- /// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a completed operation.</summary>
- public bool IsCompleted
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj == null)
- {
- return true;
- }
-
- if (obj is Task<TResult> t)
- {
- return t.IsCompleted;
- }
-
- return Unsafe.As<IValueTaskSource<TResult>>(obj).GetStatus(_token) != ValueTaskSourceStatus.Pending;
- }
- }
-
- /// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a successfully completed operation.</summary>
- public bool IsCompletedSuccessfully
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj == null)
- {
- return true;
- }
-
- if (obj is Task<TResult> t)
- {
- return t.IsCompletedSuccessfully;
- }
-
- return Unsafe.As<IValueTaskSource<TResult>>(obj).GetStatus(_token) == ValueTaskSourceStatus.Succeeded;
- }
- }
-
- /// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a failed operation.</summary>
- public bool IsFaulted
- {
- get
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj == null)
- {
- return false;
- }
-
- if (obj is Task<TResult> t)
- {
- return t.IsFaulted;
- }
-
- return Unsafe.As<IValueTaskSource<TResult>>(obj).GetStatus(_token) == ValueTaskSourceStatus.Faulted;
- }
- }
-
- /// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a canceled operation.</summary>
- /// <remarks>
- /// If the <see cref="ValueTask{TResult}"/> is backed by a result or by a <see cref="IValueTaskSource{TResult}"/>,
- /// this will always return false. If it's backed by a <see cref="Task"/>, it'll return the
- /// value of the task's <see cref="Task.IsCanceled"/> property.
- /// </remarks>
- public bool IsCanceled
- {
- get
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj == null)
- {
- return false;
- }
-
- if (obj is Task<TResult> t)
- {
- return t.IsCanceled;
- }
-
- return Unsafe.As<IValueTaskSource<TResult>>(obj).GetStatus(_token) == ValueTaskSourceStatus.Canceled;
- }
- }
-
- /// <summary>Gets the result.</summary>
- [DebuggerBrowsable(DebuggerBrowsableState.Never)] // prevent debugger evaluation from invalidating an underling IValueTaskSource<T>
- public TResult Result
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- object? obj = _obj;
- Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
-
- if (obj == null)
- {
- return _result;
- }
-
- if (obj is Task<TResult> t)
- {
- TaskAwaiter.ValidateEnd(t);
- return t.ResultOnSuccess;
- }
-
- return Unsafe.As<IValueTaskSource<TResult>>(obj).GetResult(_token);
- }
- }
-
- /// <summary>Gets an awaiter for this <see cref="ValueTask{TResult}"/>.</summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ValueTaskAwaiter<TResult> GetAwaiter() => new ValueTaskAwaiter<TResult>(in this);
-
- /// <summary>Configures an awaiter for this <see cref="ValueTask{TResult}"/>.</summary>
- /// <param name="continueOnCapturedContext">
- /// true to attempt to marshal the continuation back to the captured context; otherwise, false.
- /// </param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ConfiguredValueTaskAwaitable<TResult> ConfigureAwait(bool continueOnCapturedContext) =>
- new ConfiguredValueTaskAwaitable<TResult>(new ValueTask<TResult>(_obj, _result, _token, continueOnCapturedContext));
-
- /// <summary>Gets a string-representation of this <see cref="ValueTask{TResult}"/>.</summary>
- public override string? ToString()
- {
- if (IsCompletedSuccessfully)
- {
- Debugger.NotifyOfCrossThreadDependency(); // prevent debugger evaluation from invalidating an underling IValueTaskSource<T> unless forced
-
- TResult result = Result;
- if (result != null)
- {
- return result.ToString();
- }
- }
-
- return string.Empty;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Thread.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Thread.Unix.cs
deleted file mode 100644
index 902fcf2650e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Thread.Unix.cs
+++ /dev/null
@@ -1,13 +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 System.Runtime.ConstrainedExecution;
-
-namespace System.Threading
-{
- public sealed partial class Thread
- {
- private static Exception GetApartmentStateChangeFailedException() => new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Thread.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Thread.Windows.cs
deleted file mode 100644
index 18882091ab6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Thread.Windows.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Threading
-{
- public sealed partial class Thread
- {
- private static Exception GetApartmentStateChangeFailedException() =>
- new InvalidOperationException(SR.Thread_ApartmentState_ChangeFailed);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Thread.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Thread.cs
deleted file mode 100644
index ca1d94f6fdf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Thread.cs
+++ /dev/null
@@ -1,390 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.Runtime.ConstrainedExecution;
-using System.Security.Principal;
-
-namespace System.Threading
-{
- public sealed partial class Thread : CriticalFinalizerObject
- {
- private static AsyncLocal<IPrincipal?>? s_asyncLocalPrincipal;
-
- [ThreadStatic]
- private static Thread? t_currentThread;
-
- public Thread(ThreadStart start)
- : this()
- {
- if (start == null)
- {
- throw new ArgumentNullException(nameof(start));
- }
-
- Create(start);
- }
-
- public Thread(ThreadStart start, int maxStackSize)
- : this()
- {
- if (start == null)
- {
- throw new ArgumentNullException(nameof(start));
- }
- if (maxStackSize < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(maxStackSize), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- Create(start, maxStackSize);
- }
-
- public Thread(ParameterizedThreadStart start)
- : this()
- {
- if (start == null)
- {
- throw new ArgumentNullException(nameof(start));
- }
-
- Create(start);
- }
-
- public Thread(ParameterizedThreadStart start, int maxStackSize)
- : this()
- {
- if (start == null)
- {
- throw new ArgumentNullException(nameof(start));
- }
- if (maxStackSize < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(maxStackSize), SR.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- Create(start, maxStackSize);
- }
-
- private void RequireCurrentThread()
- {
- if (this != CurrentThread)
- {
- throw new InvalidOperationException(SR.Thread_Operation_RequiresCurrentThread);
- }
- }
-
- private void SetCultureOnUnstartedThread(CultureInfo value, bool uiCulture)
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if ((ThreadState & ThreadState.Unstarted) == 0)
- {
- throw new InvalidOperationException(SR.Thread_Operation_RequiresCurrentThread);
- }
- SetCultureOnUnstartedThreadNoCheck(value, uiCulture);
- }
-
- partial void ThreadNameChanged(string? value);
-
- public CultureInfo CurrentCulture
- {
- get
- {
- RequireCurrentThread();
- return CultureInfo.CurrentCulture;
- }
- set
- {
- if (this != CurrentThread)
- {
- SetCultureOnUnstartedThread(value, uiCulture: false);
- return;
- }
- CultureInfo.CurrentCulture = value;
- }
- }
-
- public CultureInfo CurrentUICulture
- {
- get
- {
- RequireCurrentThread();
- return CultureInfo.CurrentUICulture;
- }
- set
- {
- if (this != CurrentThread)
- {
- SetCultureOnUnstartedThread(value, uiCulture: true);
- return;
- }
- CultureInfo.CurrentUICulture = value;
- }
- }
-
- public static IPrincipal? CurrentPrincipal
- {
- get
- {
- if (s_asyncLocalPrincipal is null)
- {
- CurrentPrincipal = AppDomain.CurrentDomain.GetThreadPrincipal();
- }
- return s_asyncLocalPrincipal?.Value;
- }
- set
- {
- if (s_asyncLocalPrincipal is null)
- {
- if (value is null)
- {
- return;
- }
- Interlocked.CompareExchange(ref s_asyncLocalPrincipal, new AsyncLocal<IPrincipal?>(), null);
- }
- s_asyncLocalPrincipal.Value = value;
- }
- }
-
- public static Thread CurrentThread => t_currentThread ?? InitializeCurrentThread();
-
- public ExecutionContext? ExecutionContext => ExecutionContext.Capture();
-
- public string? Name
- {
- get => _name;
- set
- {
- lock (this)
- {
- if (_name != null)
- {
- throw new InvalidOperationException(SR.InvalidOperation_WriteOnce);
- }
-
- _name = value;
-
- ThreadNameChanged(value);
- }
- }
- }
-
- public void Abort()
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ThreadAbort);
- }
-
- public void Abort(object? stateInfo)
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ThreadAbort);
- }
-
- public static void ResetAbort()
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ThreadAbort);
- }
-
- [Obsolete("Thread.Suspend has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. https://go.microsoft.com/fwlink/?linkid=14202", false)]
- public void Suspend()
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ThreadSuspend);
- }
-
- [Obsolete("Thread.Resume has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. https://go.microsoft.com/fwlink/?linkid=14202", false)]
- public void Resume()
- {
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_ThreadSuspend);
- }
-
- // Currently, no special handling is done for critical regions, and no special handling is necessary to ensure thread
- // affinity. If that changes, the relevant functions would instead need to delegate to RuntimeThread.
- public static void BeginCriticalRegion() { }
- public static void EndCriticalRegion() { }
- public static void BeginThreadAffinity() { }
- public static void EndThreadAffinity() { }
-
- public static LocalDataStoreSlot AllocateDataSlot() => LocalDataStore.AllocateSlot();
- public static LocalDataStoreSlot AllocateNamedDataSlot(string name) => LocalDataStore.AllocateNamedSlot(name);
- public static LocalDataStoreSlot GetNamedDataSlot(string name) => LocalDataStore.GetNamedSlot(name);
- public static void FreeNamedDataSlot(string name) => LocalDataStore.FreeNamedSlot(name);
- public static object? GetData(LocalDataStoreSlot slot) => LocalDataStore.GetData(slot);
- public static void SetData(LocalDataStoreSlot slot, object? data) => LocalDataStore.SetData(slot, data);
-
- [Obsolete("The ApartmentState property has been deprecated. Use GetApartmentState, SetApartmentState or TrySetApartmentState instead.", false)]
- public ApartmentState ApartmentState
- {
- get => GetApartmentState();
- set => TrySetApartmentState(value);
- }
-
- public void SetApartmentState(ApartmentState state)
- {
- if (!TrySetApartmentState(state))
- {
- throw GetApartmentStateChangeFailedException();
- }
- }
-
- public bool TrySetApartmentState(ApartmentState state)
- {
- switch (state)
- {
- case ApartmentState.STA:
- case ApartmentState.MTA:
- case ApartmentState.Unknown:
- break;
-
- default:
- throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum, nameof(state));
- }
-
- return TrySetApartmentStateUnchecked(state);
- }
-
- [Obsolete("Thread.GetCompressedStack is no longer supported. Please use the System.Threading.CompressedStack class")]
- public CompressedStack GetCompressedStack()
- {
- throw new InvalidOperationException(SR.Thread_GetSetCompressedStack_NotSupported);
- }
-
- [Obsolete("Thread.SetCompressedStack is no longer supported. Please use the System.Threading.CompressedStack class")]
- public void SetCompressedStack(CompressedStack stack)
- {
- throw new InvalidOperationException(SR.Thread_GetSetCompressedStack_NotSupported);
- }
-
- public static AppDomain GetDomain() => AppDomain.CurrentDomain;
- public static int GetDomainID() => 1;
- public override int GetHashCode() => ManagedThreadId;
- public void Join() => Join(-1);
- public bool Join(TimeSpan timeout) => Join(WaitHandle.ToTimeoutMilliseconds(timeout));
- public static void MemoryBarrier() => Interlocked.MemoryBarrier();
- public static void Sleep(TimeSpan timeout) => Sleep(WaitHandle.ToTimeoutMilliseconds(timeout));
-
- public static byte VolatileRead(ref byte address) => Volatile.Read(ref address);
- public static double VolatileRead(ref double address) => Volatile.Read(ref address);
- public static short VolatileRead(ref short address) => Volatile.Read(ref address);
- public static int VolatileRead(ref int address) => Volatile.Read(ref address);
- public static long VolatileRead(ref long address) => Volatile.Read(ref address);
- public static IntPtr VolatileRead(ref IntPtr address) => Volatile.Read(ref address);
- [return: NotNullIfNotNull("address")]
- public static object? VolatileRead(ref object? address) => Volatile.Read(ref address);
- [CLSCompliant(false)]
- public static sbyte VolatileRead(ref sbyte address) => Volatile.Read(ref address);
- public static float VolatileRead(ref float address) => Volatile.Read(ref address);
- [CLSCompliant(false)]
- public static ushort VolatileRead(ref ushort address) => Volatile.Read(ref address);
- [CLSCompliant(false)]
- public static uint VolatileRead(ref uint address) => Volatile.Read(ref address);
- [CLSCompliant(false)]
- public static ulong VolatileRead(ref ulong address) => Volatile.Read(ref address);
- [CLSCompliant(false)]
- public static UIntPtr VolatileRead(ref UIntPtr address) => Volatile.Read(ref address);
- public static void VolatileWrite(ref byte address, byte value) => Volatile.Write(ref address, value);
- public static void VolatileWrite(ref double address, double value) => Volatile.Write(ref address, value);
- public static void VolatileWrite(ref short address, short value) => Volatile.Write(ref address, value);
- public static void VolatileWrite(ref int address, int value) => Volatile.Write(ref address, value);
- public static void VolatileWrite(ref long address, long value) => Volatile.Write(ref address, value);
- public static void VolatileWrite(ref IntPtr address, IntPtr value) => Volatile.Write(ref address, value);
- public static void VolatileWrite([NotNullIfNotNull("value")] ref object? address, object? value) => Volatile.Write(ref address, value);
- [CLSCompliant(false)]
- public static void VolatileWrite(ref sbyte address, sbyte value) => Volatile.Write(ref address, value);
- public static void VolatileWrite(ref float address, float value) => Volatile.Write(ref address, value);
- [CLSCompliant(false)]
- public static void VolatileWrite(ref ushort address, ushort value) => Volatile.Write(ref address, value);
- [CLSCompliant(false)]
- public static void VolatileWrite(ref uint address, uint value) => Volatile.Write(ref address, value);
- [CLSCompliant(false)]
- public static void VolatileWrite(ref ulong address, ulong value) => Volatile.Write(ref address, value);
- [CLSCompliant(false)]
- public static void VolatileWrite(ref UIntPtr address, UIntPtr value) => Volatile.Write(ref address, value);
-
- /// <summary>
- /// Manages functionality required to support members of <see cref="Thread"/> dealing with thread-local data
- /// </summary>
- private static class LocalDataStore
- {
- private static Dictionary<string, LocalDataStoreSlot>? s_nameToSlotMap;
-
- public static LocalDataStoreSlot AllocateSlot()
- {
- return new LocalDataStoreSlot(new ThreadLocal<object?>());
- }
-
- private static Dictionary<string, LocalDataStoreSlot> EnsureNameToSlotMap()
- {
- Dictionary<string, LocalDataStoreSlot>? nameToSlotMap = s_nameToSlotMap;
- if (nameToSlotMap != null)
- {
- return nameToSlotMap;
- }
-
- nameToSlotMap = new Dictionary<string, LocalDataStoreSlot>();
- return Interlocked.CompareExchange(ref s_nameToSlotMap, nameToSlotMap, null) ?? nameToSlotMap;
- }
-
- public static LocalDataStoreSlot AllocateNamedSlot(string name)
- {
- LocalDataStoreSlot slot = AllocateSlot();
- Dictionary<string, LocalDataStoreSlot> nameToSlotMap = EnsureNameToSlotMap();
- lock (nameToSlotMap)
- {
- nameToSlotMap.Add(name, slot);
- }
- return slot;
- }
-
- public static LocalDataStoreSlot GetNamedSlot(string name)
- {
- Dictionary<string, LocalDataStoreSlot> nameToSlotMap = EnsureNameToSlotMap();
- lock (nameToSlotMap)
- {
- LocalDataStoreSlot? slot;
- if (!nameToSlotMap.TryGetValue(name, out slot))
- {
- slot = AllocateSlot();
- nameToSlotMap[name] = slot;
- }
- return slot;
- }
- }
-
- public static void FreeNamedSlot(string name)
- {
- Dictionary<string, LocalDataStoreSlot> nameToSlotMap = EnsureNameToSlotMap();
- lock (nameToSlotMap)
- {
- nameToSlotMap.Remove(name);
- }
- }
-
- private static ThreadLocal<object?> GetThreadLocal(LocalDataStoreSlot slot)
- {
- if (slot == null)
- {
- throw new ArgumentNullException(nameof(slot));
- }
-
- Debug.Assert(slot.Data != null);
- return slot.Data;
- }
-
- public static object? GetData(LocalDataStoreSlot slot)
- {
- return GetThreadLocal(slot).Value;
- }
-
- public static void SetData(LocalDataStoreSlot slot, object? value)
- {
- GetThreadLocal(slot).Value = value;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadAbortException.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadAbortException.cs
deleted file mode 100644
index 574e27f4177..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadAbortException.cs
+++ /dev/null
@@ -1,37 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: An exception class which is thrown into a thread to cause it to
-** abort. This is a special non-catchable exception and results in
-** the thread's death. This is thrown by the VM only and can NOT be
-** thrown by any user thread, and subclassing this is useless.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System.Threading
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class ThreadAbortException : SystemException
- {
- internal ThreadAbortException()
- {
- HResult = HResults.COR_E_THREADABORTED;
- }
-
- public object? ExceptionState => null;
-
- private ThreadAbortException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadInt64PersistentCounter.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadInt64PersistentCounter.cs
deleted file mode 100644
index 440d38f9ecd..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadInt64PersistentCounter.cs
+++ /dev/null
@@ -1,144 +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 System.Diagnostics;
-using System.Runtime.CompilerServices;
-
-namespace System.Threading
-{
- internal sealed class ThreadInt64PersistentCounter
- {
- // This type is used by Monitor for lock contention counting, so can't use an object for a lock. Also it's preferable
- // (though currently not required) to disallow/ignore thread interrupt for uses of this lock here. Using Lock directly
- // is a possibility but maybe less compatible with other runtimes. Lock cases are relatively rare, static instance
- // should be ok.
- private static readonly LowLevelLock s_lock = new LowLevelLock();
-
- private readonly ThreadLocal<ThreadLocalNode> _threadLocalNode = new ThreadLocal<ThreadLocalNode>(trackAllValues: true);
- private long _overflowCount;
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Increment()
- {
- ThreadLocalNode node = _threadLocalNode.Value;
- if (node != null)
- {
- node.Increment();
- return;
- }
-
- TryCreateNode();
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private void TryCreateNode()
- {
- Debug.Assert(_threadLocalNode.Value == null);
-
- try
- {
- _threadLocalNode.Value = new ThreadLocalNode(this);
- }
- catch (OutOfMemoryException)
- {
- }
- }
-
- public long Count
- {
- get
- {
- long count = 0;
- try
- {
- s_lock.Acquire();
- try
- {
- count = _overflowCount;
- foreach (ThreadLocalNode node in _threadLocalNode.ValuesAsEnumerable)
- {
- if (node != null)
- {
- count += node.Count;
- }
- }
- return count;
- }
- finally
- {
- s_lock.Release();
- }
- }
- catch (OutOfMemoryException)
- {
- // Some allocation occurs above and it may be a bit awkward to get an OOM from this property getter
- return count;
- }
- }
- }
-
- private sealed class ThreadLocalNode
- {
- private uint _count;
- private readonly ThreadInt64PersistentCounter _counter;
-
- public ThreadLocalNode(ThreadInt64PersistentCounter counter)
- {
- Debug.Assert(counter != null);
-
- _count = 1;
- _counter = counter;
- }
-
- ~ThreadLocalNode()
- {
- ThreadInt64PersistentCounter counter = _counter;
- s_lock.Acquire();
- try
- {
- counter._overflowCount += _count;
- }
- finally
- {
- s_lock.Release();
- }
- }
-
- public uint Count => _count;
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Increment()
- {
- uint newCount = _count + 1;
- if (newCount != 0)
- {
- _count = newCount;
- return;
- }
-
- OnIncrementOverflow();
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private void OnIncrementOverflow()
- {
- // Accumulate the count for this increment into the overflow count and reset the thread-local count
-
- // The lock, in coordination with other places that read these values, ensures that both changes below become
- // visible together
- ThreadInt64PersistentCounter counter = _counter;
- s_lock.Acquire();
- try
- {
- _count = 0;
- counter._overflowCount += (long)uint.MaxValue + 1;
- }
- finally
- {
- s_lock.Release();
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadInterruptedException.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadInterruptedException.cs
deleted file mode 100644
index af80bb620f9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadInterruptedException.cs
+++ /dev/null
@@ -1,43 +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 System.Runtime.Serialization;
-
-namespace System.Threading
-{
- /// <summary>
- /// An exception class to indicate that the thread was interrupted from a waiting state.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ThreadInterruptedException : SystemException
- {
- public ThreadInterruptedException() : base(
-#if CORECLR
- GetMessageFromNativeResources(ExceptionMessageKind.ThreadInterrupted)
-#else
- SR.Threading_ThreadInterrupted
-#endif
- )
- {
- HResult = HResults.COR_E_THREADINTERRUPTED;
- }
-
- public ThreadInterruptedException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_THREADINTERRUPTED;
- }
-
- public ThreadInterruptedException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_THREADINTERRUPTED;
- }
-
- protected ThreadInterruptedException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadLocal.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadLocal.cs
deleted file mode 100644
index dbaf1627c7d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadLocal.cs
+++ /dev/null
@@ -1,813 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-
-// A class that provides a simple, lightweight implementation of thread-local lazy-initialization, where a value is initialized once per accessing
-// thread; this provides an alternative to using a ThreadStatic static variable and having
-// to check the variable prior to every access to see if it's been initialized.
-
-namespace System.Threading
-{
- /// <summary>
- /// Provides thread-local storage of data.
- /// </summary>
- /// <typeparam name="T">Specifies the type of data stored per-thread.</typeparam>
- /// <remarks>
- /// <para>
- /// With the exception of <see cref="Dispose()"/>, all public and protected members of
- /// <see cref="ThreadLocal{T}"/> are thread-safe and may be used
- /// concurrently from multiple threads.
- /// </para>
- /// </remarks>
- [DebuggerTypeProxy(typeof(SystemThreading_ThreadLocalDebugView<>))]
- [DebuggerDisplay("IsValueCreated={IsValueCreated}, Value={ValueForDebugDisplay}, Count={ValuesCountForDebugDisplay}")]
- public class ThreadLocal<T> : IDisposable
- {
- // a delegate that returns the created value, if null the created value will be default(T)
- private Func<T>? _valueFactory;
-
- // ts_slotArray is a table of thread-local values for all ThreadLocal<T> instances
- //
- // So, when a thread reads ts_slotArray, it gets back an array of *all* ThreadLocal<T> values for this thread and this T.
- // The slot relevant to this particular ThreadLocal<T> instance is determined by the _idComplement instance field stored in
- // the ThreadLocal<T> instance.
- [ThreadStatic]
- private static LinkedSlotVolatile[]? ts_slotArray;
-
- [ThreadStatic]
- private static FinalizationHelper? ts_finalizationHelper;
-
- // Slot ID of this ThreadLocal<> instance. We store a bitwise complement of the ID (that is ~ID), which allows us to distinguish
- // between the case when ID is 0 and an incompletely initialized object, either due to a thread abort in the constructor, or
- // possibly due to a memory model issue in user code.
- private int _idComplement;
-
- // This field is set to true when the constructor completes. That is helpful for recognizing whether a constructor
- // threw an exception - either due to invalid argument or due to a thread abort. Finally, the field is set to false
- // when the instance is disposed.
- private volatile bool _initialized;
-
- // IdManager assigns and reuses slot IDs. Additionally, the object is also used as a global lock.
- private static readonly IdManager s_idManager = new IdManager();
-
- // A linked list of all values associated with this ThreadLocal<T> instance.
- // We create a dummy head node. That allows us to remove any (non-dummy) node without having to locate the m_linkedSlot field.
- private LinkedSlot? _linkedSlot = new LinkedSlot(null);
-
- // Whether the Values property is supported
- private bool _trackAllValues;
-
- /// <summary>
- /// Initializes the <see cref="System.Threading.ThreadLocal{T}"/> instance.
- /// </summary>
- public ThreadLocal()
- {
- Initialize(null, false);
- }
-
- /// <summary>
- /// Initializes the <see cref="System.Threading.ThreadLocal{T}"/> instance.
- /// </summary>
- /// <param name="trackAllValues">Whether to track all values set on the instance and expose them through the Values property.</param>
- public ThreadLocal(bool trackAllValues)
- {
- Initialize(null, trackAllValues);
- }
-
-
- /// <summary>
- /// Initializes the <see cref="System.Threading.ThreadLocal{T}"/> instance with the
- /// specified <paramref name="valueFactory"/> function.
- /// </summary>
- /// <param name="valueFactory">
- /// The <see cref="System.Func{T}"/> invoked to produce a lazily-initialized value when
- /// an attempt is made to retrieve <see cref="Value"/> without it having been previously initialized.
- /// </param>
- /// <exception cref="System.ArgumentNullException">
- /// <paramref name="valueFactory"/> is a null reference (Nothing in Visual Basic).
- /// </exception>
- public ThreadLocal(Func<T> valueFactory)
- {
- if (valueFactory == null)
- throw new ArgumentNullException(nameof(valueFactory));
-
- Initialize(valueFactory, false);
- }
-
- /// <summary>
- /// Initializes the <see cref="System.Threading.ThreadLocal{T}"/> instance with the
- /// specified <paramref name="valueFactory"/> function.
- /// </summary>
- /// <param name="valueFactory">
- /// The <see cref="System.Func{T}"/> invoked to produce a lazily-initialized value when
- /// an attempt is made to retrieve <see cref="Value"/> without it having been previously initialized.
- /// </param>
- /// <param name="trackAllValues">Whether to track all values set on the instance and expose them via the Values property.</param>
- /// <exception cref="System.ArgumentNullException">
- /// <paramref name="valueFactory"/> is a null reference (Nothing in Visual Basic).
- /// </exception>
- public ThreadLocal(Func<T> valueFactory, bool trackAllValues)
- {
- if (valueFactory == null)
- throw new ArgumentNullException(nameof(valueFactory));
-
- Initialize(valueFactory, trackAllValues);
- }
-
- private void Initialize(Func<T>? valueFactory, bool trackAllValues)
- {
- _valueFactory = valueFactory;
- _trackAllValues = trackAllValues;
-
- // Assign the ID and mark the instance as initialized. To avoid leaking IDs, we assign the ID and set _initialized
- // in a finally block, to avoid a thread abort in between the two statements.
- try { }
- finally
- {
- _idComplement = ~s_idManager.GetId();
-
- // As the last step, mark the instance as fully initialized. (Otherwise, if _initialized=false, we know that an exception
- // occurred in the constructor.)
- _initialized = true;
- }
- }
-
- /// <summary>
- /// Releases the resources used by this <see cref="System.Threading.ThreadLocal{T}" /> instance.
- /// </summary>
- ~ThreadLocal()
- {
- // finalizer to return the type combination index to the pool
- Dispose(false);
- }
-
- #region IDisposable Members
-
- /// <summary>
- /// Releases the resources used by this <see cref="System.Threading.ThreadLocal{T}" /> instance.
- /// </summary>
- /// <remarks>
- /// Unlike most of the members of <see cref="System.Threading.ThreadLocal{T}"/>, this method is not thread-safe.
- /// </remarks>
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- /// <summary>
- /// Releases the resources used by this <see cref="System.Threading.ThreadLocal{T}" /> instance.
- /// </summary>
- /// <param name="disposing">
- /// A Boolean value that indicates whether this method is being called due to a call to <see cref="Dispose()"/>.
- /// </param>
- /// <remarks>
- /// Unlike most of the members of <see cref="System.Threading.ThreadLocal{T}"/>, this method is not thread-safe.
- /// </remarks>
- protected virtual void Dispose(bool disposing)
- {
- int id;
-
- lock (s_idManager)
- {
- id = ~_idComplement;
- _idComplement = 0;
-
- if (id < 0 || !_initialized)
- {
- Debug.Assert(id >= 0 || !_initialized, "expected id >= 0 if initialized");
-
- // Handle double Dispose calls or disposal of an instance whose constructor threw an exception.
- return;
- }
- _initialized = false;
-
- Debug.Assert(_linkedSlot != null, "Should be non-null if not yet disposed");
- for (LinkedSlot? linkedSlot = _linkedSlot._next; linkedSlot != null; linkedSlot = linkedSlot._next)
- {
- LinkedSlotVolatile[]? slotArray = linkedSlot._slotArray;
-
- if (slotArray == null)
- {
- // The thread that owns this slotArray has already finished.
- continue;
- }
-
- // Remove the reference from the LinkedSlot to the slot table.
- linkedSlot._slotArray = null;
-
- // And clear the references from the slot table to the linked slot and the value so that
- // both can get garbage collected.
- slotArray[id].Value!._value = default;
- slotArray[id].Value = null;
- }
- }
- _linkedSlot = null;
- s_idManager.ReturnId(id);
- }
-
- #endregion
-
- /// <summary>Creates and returns a string representation of this instance for the current thread.</summary>
- /// <returns>The result of calling <see cref="object.ToString"/> on the <see cref="Value"/>.</returns>
- /// <exception cref="System.NullReferenceException">
- /// The <see cref="Value"/> for the current thread is a null reference (Nothing in Visual Basic).
- /// </exception>
- /// <exception cref="System.InvalidOperationException">
- /// The initialization function referenced <see cref="Value"/> in an improper manner.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">
- /// The <see cref="ThreadLocal{T}"/> instance has been disposed.
- /// </exception>
- /// <remarks>
- /// Calling this method forces initialization for the current thread, as is the
- /// case with accessing <see cref="Value"/> directly.
- /// </remarks>
- public override string? ToString()
- {
- return Value!.ToString(); // Throws NullReferenceException as if caller called ToString on the value itself
- }
-
- /// <summary>
- /// Gets or sets the value of this instance for the current thread.
- /// </summary>
- /// <exception cref="System.InvalidOperationException">
- /// The initialization function referenced <see cref="Value"/> in an improper manner.
- /// </exception>
- /// <exception cref="System.ObjectDisposedException">
- /// The <see cref="ThreadLocal{T}"/> instance has been disposed.
- /// </exception>
- /// <remarks>
- /// If this instance was not previously initialized for the current thread,
- /// accessing <see cref="Value"/> will attempt to initialize it. If an initialization function was
- /// supplied during the construction, that initialization will happen by invoking the function
- /// to retrieve the initial value for <see cref="Value"/>. Otherwise, the default value of
- /// <typeparamref name="T"/> will be used.
- /// </remarks>
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- [MaybeNull]
- public T Value
- {
- get
- {
- LinkedSlotVolatile[]? slotArray = ts_slotArray;
- LinkedSlot? slot;
- int id = ~_idComplement;
-
- //
- // Attempt to get the value using the fast path
- //
- if (slotArray != null // Has the slot array been initialized?
- && id >= 0 // Is the ID non-negative (i.e., instance is not disposed)?
- && id < slotArray.Length // Is the table large enough?
- && (slot = slotArray[id].Value) != null // Has a LinkedSlot object has been allocated for this ID?
- && _initialized // Has the instance *still* not been disposed (important for a race condition with Dispose)?
- )
- {
- // We verified that the instance has not been disposed *after* we got a reference to the slot.
- // This guarantees that we have a reference to the right slot.
- //
- // Volatile read of the LinkedSlotVolatile.Value property ensures that the m_initialized read
- // will not be reordered before the read of slotArray[id].
- return slot._value;
- }
-
- return GetValueSlow();
- }
- set
- {
- LinkedSlotVolatile[]? slotArray = ts_slotArray;
- LinkedSlot? slot;
- int id = ~_idComplement;
-
- // Attempt to set the value using the fast path
- if (slotArray != null // Has the slot array been initialized?
- && id >= 0 // Is the ID non-negative (i.e., instance is not disposed)?
- && id < slotArray.Length // Is the table large enough?
- && (slot = slotArray[id].Value) != null // Has a LinkedSlot object has been allocated for this ID?
- && _initialized // Has the instance *still* not been disposed (important for a race condition with Dispose)?
- )
- {
- // We verified that the instance has not been disposed *after* we got a reference to the slot.
- // This guarantees that we have a reference to the right slot.
- //
- // Volatile read of the LinkedSlotVolatile.Value property ensures that the m_initialized read
- // will not be reordered before the read of slotArray[id].
- slot._value = value;
- }
- else
- {
- SetValueSlow(value, slotArray);
- }
- }
- }
-
- [return: MaybeNull]
- private T GetValueSlow()
- {
- // If the object has been disposed, the id will be -1.
- int id = ~_idComplement;
- if (id < 0)
- {
- throw new ObjectDisposedException(SR.ThreadLocal_Disposed);
- }
-
- Debugger.NotifyOfCrossThreadDependency();
-
- // Determine the initial value
- T value;
- if (_valueFactory == null)
- {
- value = default!;
- }
- else
- {
- value = _valueFactory();
-
- if (IsValueCreated)
- {
- throw new InvalidOperationException(SR.ThreadLocal_Value_RecursiveCallsToValue);
- }
- }
-
- // Since the value has been previously uninitialized, we also need to set it (according to the ThreadLocal semantics).
- Value = value;
- return value;
- }
-
- private void SetValueSlow(T value, LinkedSlotVolatile[]? slotArray)
- {
- int id = ~_idComplement;
-
- // If the object has been disposed, id will be -1.
- if (id < 0)
- {
- throw new ObjectDisposedException(SR.ThreadLocal_Disposed);
- }
-
- // If a slot array has not been created on this thread yet, create it.
- if (slotArray == null)
- {
- slotArray = new LinkedSlotVolatile[GetNewTableSize(id + 1)];
- ts_finalizationHelper = new FinalizationHelper(slotArray, _trackAllValues);
- ts_slotArray = slotArray;
- }
-
- // If the slot array is not big enough to hold this ID, increase the table size.
- if (id >= slotArray.Length)
- {
- GrowTable(ref slotArray!, id + 1);
- Debug.Assert(ts_finalizationHelper != null, "Should have been initialized when this thread's slot array was created.");
- ts_finalizationHelper.SlotArray = slotArray;
- ts_slotArray = slotArray;
- }
-
- // If we are using the slot in this table for the first time, create a new LinkedSlot and add it into
- // the linked list for this ThreadLocal instance.
- if (slotArray[id].Value == null)
- {
- CreateLinkedSlot(slotArray, id, value);
- }
- else
- {
- // Volatile read of the LinkedSlotVolatile.Value property ensures that the m_initialized read
- // that follows will not be reordered before the read of slotArray[id].
- LinkedSlot? slot = slotArray[id].Value;
-
- // It is important to verify that the ThreadLocal instance has not been disposed. The check must come
- // after capturing slotArray[id], but before assigning the value into the slot. This ensures that
- // if this ThreadLocal instance was disposed on another thread and another ThreadLocal instance was
- // created, we definitely won't assign the value into the wrong instance.
-
- if (!_initialized)
- {
- throw new ObjectDisposedException(SR.ThreadLocal_Disposed);
- }
-
- slot!._value = value;
- }
- }
-
- /// <summary>
- /// Creates a LinkedSlot and inserts it into the linked list for this ThreadLocal instance.
- /// </summary>
- private void CreateLinkedSlot(LinkedSlotVolatile[] slotArray, int id, T value)
- {
- // Create a LinkedSlot
- var linkedSlot = new LinkedSlot(slotArray);
-
- // Insert the LinkedSlot into the linked list maintained by this ThreadLocal<> instance and into the slot array
- lock (s_idManager)
- {
- // Check that the instance has not been disposed. It is important to check this under a lock, since
- // Dispose also executes under a lock.
- if (!_initialized)
- {
- throw new ObjectDisposedException(SR.ThreadLocal_Disposed);
- }
-
- Debug.Assert(_linkedSlot != null, "Should only be null if disposed");
- LinkedSlot? firstRealNode = _linkedSlot._next;
-
- // Insert linkedSlot between nodes m_linkedSlot and firstRealNode.
- // (_linkedSlot is the dummy head node that should always be in the front.)
- linkedSlot._next = firstRealNode;
- linkedSlot._previous = _linkedSlot;
- linkedSlot._value = value;
-
- if (firstRealNode != null)
- {
- firstRealNode._previous = linkedSlot;
- }
- _linkedSlot._next = linkedSlot;
-
- // Assigning the slot under a lock prevents a race condition with Dispose (dispose also acquires the lock).
- // Otherwise, it would be possible that the ThreadLocal instance is disposed, another one gets created
- // with the same ID, and the write would go to the wrong instance.
- slotArray[id].Value = linkedSlot;
- }
- }
-
- /// <summary>
- /// Gets a list for all of the values currently stored by all of the threads that have accessed this instance.
- /// </summary>
- /// <exception cref="System.ObjectDisposedException">
- /// The <see cref="ThreadLocal{T}"/> instance has been disposed.
- /// </exception>
- public IList<T> Values
- {
- get
- {
- if (!_trackAllValues)
- {
- throw new InvalidOperationException(SR.ThreadLocal_ValuesNotAvailable);
- }
-
- List<T>? list = GetValuesAsList(); // returns null if disposed
- if (list == null) throw new ObjectDisposedException(SR.ThreadLocal_Disposed);
- return list;
- }
- }
-
- /// <summary>Gets all of the threads' values in a list.</summary>
- private List<T>? GetValuesAsList()
- {
- LinkedSlot? linkedSlot = _linkedSlot;
- int id = ~_idComplement;
- if (id == -1 || linkedSlot == null)
- {
- return null;
- }
-
- // Walk over the linked list of slots and gather the values associated with this ThreadLocal instance.
- var valueList = new List<T>();
- for (linkedSlot = linkedSlot._next; linkedSlot != null; linkedSlot = linkedSlot._next)
- {
- // We can safely read linkedSlot.Value. Even if this ThreadLocal has been disposed in the meantime, the LinkedSlot
- // objects will never be assigned to another ThreadLocal instance.
- valueList.Add(linkedSlot._value!);
- }
-
- return valueList;
- }
-
- internal IEnumerable<T> ValuesAsEnumerable
- {
- get
- {
- if (!_trackAllValues)
- {
- throw new InvalidOperationException(SR.ThreadLocal_ValuesNotAvailable);
- }
-
- LinkedSlot? linkedSlot = _linkedSlot;
- int id = ~_idComplement;
- if (id == -1 || linkedSlot == null)
- {
- throw new ObjectDisposedException(SR.ThreadLocal_Disposed);
- }
-
- // Walk over the linked list of slots and gather the values associated with this ThreadLocal instance.
- for (linkedSlot = linkedSlot._next; linkedSlot != null; linkedSlot = linkedSlot._next)
- {
- // We can safely read linkedSlot.Value. Even if this ThreadLocal has been disposed in the meantime, the LinkedSlot
- // objects will never be assigned to another ThreadLocal instance.
- yield return linkedSlot._value!;
- }
- }
- }
-
- /// <summary>Gets the number of threads that have data in this instance.</summary>
- private int ValuesCountForDebugDisplay
- {
- get
- {
- int count = 0;
- for (LinkedSlot? linkedSlot = _linkedSlot?._next; linkedSlot != null; linkedSlot = linkedSlot._next)
- {
- count++;
- }
- return count;
- }
- }
-
- /// <summary>
- /// Gets whether <see cref="Value"/> is initialized on the current thread.
- /// </summary>
- /// <exception cref="System.ObjectDisposedException">
- /// The <see cref="ThreadLocal{T}"/> instance has been disposed.
- /// </exception>
- public bool IsValueCreated
- {
- get
- {
- int id = ~_idComplement;
- if (id < 0)
- {
- throw new ObjectDisposedException(SR.ThreadLocal_Disposed);
- }
-
- LinkedSlotVolatile[]? slotArray = ts_slotArray;
- return slotArray != null && id < slotArray.Length && slotArray[id].Value != null;
- }
- }
-
-
- /// <summary>Gets the value of the ThreadLocal&lt;T&gt; for debugging display purposes. It takes care of getting
- /// the value for the current thread in the ThreadLocal mode.</summary>
- [MaybeNull]
- internal T ValueForDebugDisplay
- {
- get
- {
- LinkedSlotVolatile[]? slotArray = ts_slotArray;
- int id = ~_idComplement;
-
- LinkedSlot? slot;
- if (slotArray == null || id >= slotArray.Length || (slot = slotArray[id].Value) == null || !_initialized)
- return default!;
- return slot._value;
- }
- }
-
- /// <summary>Gets the values of all threads that accessed the ThreadLocal&lt;T&gt;.</summary>
- internal List<T>? ValuesForDebugDisplay => // same as Values property, but doesn't throw if disposed
- GetValuesAsList();
-
- /// <summary>
- /// Resizes a table to a certain length (or larger).
- /// </summary>
- private static void GrowTable(ref LinkedSlotVolatile[] table, int minLength)
- {
- Debug.Assert(table.Length < minLength);
-
- // Determine the size of the new table and allocate it.
- int newLen = GetNewTableSize(minLength);
- LinkedSlotVolatile[] newTable = new LinkedSlotVolatile[newLen];
-
- //
- // The lock is necessary to avoid a race with ThreadLocal.Dispose. GrowTable has to point all
- // LinkedSlot instances referenced in the old table to reference the new table. Without locking,
- // Dispose could use a stale SlotArray reference and clear out a slot in the old array only, while
- // the value continues to be referenced from the new (larger) array.
- //
- lock (s_idManager)
- {
- for (int i = 0; i < table.Length; i++)
- {
- LinkedSlot? linkedSlot = table[i].Value;
- if (linkedSlot != null && linkedSlot._slotArray != null)
- {
- linkedSlot._slotArray = newTable;
- newTable[i] = table[i];
- }
- }
- }
-
- table = newTable;
- }
-
- /// <summary>
- /// Chooses the next larger table size
- /// </summary>
- private static int GetNewTableSize(int minSize)
- {
- if ((uint)minSize > Array.MaxArrayLength)
- {
- // Intentionally return a value that will result in an OutOfMemoryException
- return int.MaxValue;
- }
- Debug.Assert(minSize > 0);
-
- //
- // Round up the size to the next power of 2
- //
- // The algorithm takes three steps:
- // input -> subtract one -> propagate 1-bits to the right -> add one
- //
- // Let's take a look at the 3 steps in both interesting cases: where the input
- // is (Example 1) and isn't (Example 2) a power of 2.
- //
- // Example 1: 100000 -> 011111 -> 011111 -> 100000
- // Example 2: 011010 -> 011001 -> 011111 -> 100000
- //
- int newSize = minSize;
-
- // Step 1: Decrement
- newSize--;
-
- // Step 2: Propagate 1-bits to the right.
- newSize |= newSize >> 1;
- newSize |= newSize >> 2;
- newSize |= newSize >> 4;
- newSize |= newSize >> 8;
- newSize |= newSize >> 16;
-
- // Step 3: Increment
- newSize++;
-
- // Don't set newSize to more than Array.MaxArrayLength
- if ((uint)newSize > Array.MaxArrayLength)
- {
- newSize = Array.MaxArrayLength;
- }
-
- return newSize;
- }
-
- /// <summary>
- /// A wrapper struct used as LinkedSlotVolatile[] - an array of LinkedSlot instances, but with volatile semantics
- /// on array accesses.
- /// </summary>
- private struct LinkedSlotVolatile
- {
- internal volatile LinkedSlot? Value;
- }
-
- /// <summary>
- /// A node in the doubly-linked list stored in the ThreadLocal instance.
- ///
- /// The value is stored in one of two places:
- ///
- /// 1. If SlotArray is not null, the value is in SlotArray.Table[id]
- /// 2. If SlotArray is null, the value is in FinalValue.
- /// </summary>
- private sealed class LinkedSlot
- {
- internal LinkedSlot(LinkedSlotVolatile[]? slotArray)
- {
- _slotArray = slotArray;
- }
-
- // The next LinkedSlot for this ThreadLocal<> instance
- internal volatile LinkedSlot? _next;
-
- // The previous LinkedSlot for this ThreadLocal<> instance
- internal volatile LinkedSlot? _previous;
-
- // The SlotArray that stores this LinkedSlot at SlotArray.Table[id].
- internal volatile LinkedSlotVolatile[]? _slotArray;
-
- // The value for this slot.
- [AllowNull, MaybeNull] internal T _value = default;
- }
-
- /// <summary>
- /// A manager class that assigns IDs to ThreadLocal instances
- /// </summary>
- private class IdManager
- {
- // The next ID to try
- private int _nextIdToTry = 0;
-
- // Stores whether each ID is free or not. Additionally, the object is also used as a lock for the IdManager.
- private readonly List<bool> _freeIds = new List<bool>();
-
- internal int GetId()
- {
- lock (_freeIds)
- {
- int availableId = _nextIdToTry;
- while (availableId < _freeIds.Count)
- {
- if (_freeIds[availableId]) { break; }
- availableId++;
- }
-
- if (availableId == _freeIds.Count)
- {
- _freeIds.Add(false);
- }
- else
- {
- _freeIds[availableId] = false;
- }
-
- _nextIdToTry = availableId + 1;
-
- return availableId;
- }
- }
-
- // Return an ID to the pool
- internal void ReturnId(int id)
- {
- lock (_freeIds)
- {
- _freeIds[id] = true;
- if (id < _nextIdToTry) _nextIdToTry = id;
- }
- }
- }
-
- /// <summary>
- /// A class that facilitates ThreadLocal cleanup after a thread exits.
- ///
- /// After a thread with an associated thread-local table has exited, the FinalizationHelper
- /// is responsible for removing back-references to the table. Since an instance of FinalizationHelper
- /// is only referenced from a single thread-local slot, the FinalizationHelper will be GC'd once
- /// the thread has exited.
- ///
- /// The FinalizationHelper then locates all LinkedSlot instances with back-references to the table
- /// (all those LinkedSlot instances can be found by following references from the table slots) and
- /// releases the table so that it can get GC'd.
- /// </summary>
- private class FinalizationHelper
- {
- internal LinkedSlotVolatile[] SlotArray;
- private readonly bool _trackAllValues;
-
- internal FinalizationHelper(LinkedSlotVolatile[] slotArray, bool trackAllValues)
- {
- SlotArray = slotArray;
- _trackAllValues = trackAllValues;
- }
-
- ~FinalizationHelper()
- {
- LinkedSlotVolatile[] slotArray = SlotArray;
- Debug.Assert(slotArray != null);
-
- for (int i = 0; i < slotArray.Length; i++)
- {
- LinkedSlot? linkedSlot = slotArray[i].Value;
- if (linkedSlot == null)
- {
- // This slot in the table is empty
- continue;
- }
-
- if (_trackAllValues)
- {
- // Set the SlotArray field to null to release the slot array.
- linkedSlot._slotArray = null;
- }
- else
- {
- // Remove the LinkedSlot from the linked list. Once the FinalizationHelper is done, all back-references to
- // the table will be have been removed, and so the table can get GC'd.
- lock (s_idManager)
- {
- if (linkedSlot._next != null)
- {
- linkedSlot._next._previous = linkedSlot._previous;
- }
-
- // Since the list uses a dummy head node, the Previous reference should never be null.
- Debug.Assert(linkedSlot._previous != null);
- linkedSlot._previous._next = linkedSlot._next;
- }
- }
- }
- }
- }
- }
-
- /// <summary>A debugger view of the ThreadLocal&lt;T&gt; to surface additional debugging properties and
- /// to ensure that the ThreadLocal&lt;T&gt; does not become initialized if it was not already.</summary>
- internal sealed class SystemThreading_ThreadLocalDebugView<T>
- {
- // The ThreadLocal object being viewed.
- private readonly ThreadLocal<T> _tlocal;
-
- /// <summary>Constructs a new debugger view object for the provided ThreadLocal object.</summary>
- /// <param name="tlocal">A ThreadLocal object to browse in the debugger.</param>
- public SystemThreading_ThreadLocalDebugView(ThreadLocal<T> tlocal)
- {
- _tlocal = tlocal;
- }
-
- /// <summary>Returns whether the ThreadLocal object is initialized or not.</summary>
- public bool IsValueCreated => _tlocal.IsValueCreated;
-
- /// <summary>Returns the value of the ThreadLocal object.</summary>
- public T Value => _tlocal.ValueForDebugDisplay;
-
- /// <summary>Return all values for all threads that have accessed this instance.</summary>
- public List<T>? Values => _tlocal.ValuesForDebugDisplay;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.Portable.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.Portable.cs
deleted file mode 100644
index e63b7e50a83..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.Portable.cs
+++ /dev/null
@@ -1,431 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
-
-namespace System.Threading
-{
- //
- // Portable implementation of ThreadPool
- //
-
- /// <summary>
- /// An object representing the registration of a <see cref="WaitHandle"/> via <see cref="ThreadPool.RegisterWaitForSingleObject"/>.
- /// </summary>
- public sealed class RegisteredWaitHandle : MarshalByRefObject
- {
- internal RegisteredWaitHandle(WaitHandle waitHandle, _ThreadPoolWaitOrTimerCallback callbackHelper,
- int millisecondsTimeout, bool repeating)
- {
- Handle = waitHandle;
- Callback = callbackHelper;
- TimeoutDurationMs = millisecondsTimeout;
- Repeating = repeating;
- RestartTimeout(Environment.TickCount);
- }
-
- ~RegisteredWaitHandle()
- {
- if(WaitThread != null)
- {
- Unregister(null);
- }
- }
-
- private static AutoResetEvent s_cachedEvent;
-
- private static AutoResetEvent RentEvent()
- {
- AutoResetEvent resetEvent = Interlocked.Exchange(ref s_cachedEvent, (AutoResetEvent)null);
- if (resetEvent == null)
- {
- resetEvent = new AutoResetEvent(false);
- }
- return resetEvent;
- }
-
- private static void ReturnEvent(AutoResetEvent resetEvent)
- {
- if (Interlocked.CompareExchange(ref s_cachedEvent, resetEvent, null) != null)
- {
- resetEvent.Dispose();
- }
- }
-
- /// <summary>
- /// The callback to execute when the wait on <see cref="Handle"/> either times out or completes.
- /// </summary>
- internal _ThreadPoolWaitOrTimerCallback Callback { get; }
-
-
- /// <summary>
- /// The <see cref="WaitHandle"/> that was registered.
- /// </summary>
- internal WaitHandle Handle { get; }
-
- /// <summary>
- /// The time this handle times out at in ms.
- /// </summary>
- internal int TimeoutTimeMs { get; private set; }
-
- private int TimeoutDurationMs { get; }
-
- internal bool IsInfiniteTimeout => TimeoutDurationMs == -1;
-
- internal void RestartTimeout(int currentTimeMs)
- {
- TimeoutTimeMs = currentTimeMs + TimeoutDurationMs;
- }
-
- /// <summary>
- /// Whether or not the wait is a repeating wait.
- /// </summary>
- internal bool Repeating { get; }
-
- /// <summary>
- /// The <see cref="WaitHandle"/> the user passed in via <see cref="Unregister(WaitHandle)"/>.
- /// </summary>
- private SafeWaitHandle UserUnregisterWaitHandle { get; set; }
-
- private IntPtr UserUnregisterWaitHandleValue { get; set; }
-
- internal bool IsBlocking => UserUnregisterWaitHandleValue == (IntPtr)(-1);
-
- /// <summary>
- /// The <see cref="PortableThreadPool.WaitThread"/> this <see cref="RegisteredWaitHandle"/> was registered on.
- /// </summary>
- internal PortableThreadPool.WaitThread WaitThread { get; set; }
-
- /// <summary>
- /// The number of callbacks that are currently queued on the Thread Pool or executing.
- /// </summary>
- private int _numRequestedCallbacks;
-
- private LowLevelLock _callbackLock = new LowLevelLock();
-
- /// <summary>
- /// Notes if we need to signal the user's unregister event after all callbacks complete.
- /// </summary>
- private bool _signalAfterCallbacksComplete;
-
- private bool _unregisterCalled;
-
- private bool _unregistered;
-
- private AutoResetEvent _callbacksComplete;
-
- private AutoResetEvent _removed;
-
- /// <summary>
- /// Unregisters this wait handle registration from the wait threads.
- /// </summary>
- /// <param name="waitObject">The event to signal when the handle is unregistered.</param>
- /// <returns>If the handle was successfully marked to be removed and the provided wait handle was set as the user provided event.</returns>
- /// <remarks>
- /// This method will only return true on the first call.
- /// Passing in a wait handle with a value of -1 will result in a blocking wait, where Unregister will not return until the full unregistration is completed.
- /// </remarks>
- public bool Unregister(WaitHandle waitObject)
- {
- GC.SuppressFinalize(this);
- _callbackLock.Acquire();
- bool needToRollBackRefCountOnException = false;
- try
- {
- if (_unregisterCalled)
- {
- return false;
- }
-
- UserUnregisterWaitHandle = waitObject?.SafeWaitHandle;
- UserUnregisterWaitHandle?.DangerousAddRef(ref needToRollBackRefCountOnException);
-
- UserUnregisterWaitHandleValue = UserUnregisterWaitHandle?.DangerousGetHandle() ?? IntPtr.Zero;
-
- if (_unregistered)
- {
- SignalUserWaitHandle();
- return true;
- }
-
- if (IsBlocking)
- {
- _callbacksComplete = RentEvent();
- }
- else
- {
- _removed = RentEvent();
- }
- _unregisterCalled = true;
- }
- catch (Exception) // Rollback state on exception
- {
- if (_removed != null)
- {
- ReturnEvent(_removed);
- _removed = null;
- }
- else if (_callbacksComplete != null)
- {
- ReturnEvent(_callbacksComplete);
- _callbacksComplete = null;
- }
-
- UserUnregisterWaitHandleValue = IntPtr.Zero;
-
- if (needToRollBackRefCountOnException)
- {
- UserUnregisterWaitHandle?.DangerousRelease();
- }
-
- UserUnregisterWaitHandle = null;
- throw;
- }
- finally
- {
- _callbackLock.Release();
- }
-
- WaitThread.UnregisterWait(this);
- return true;
- }
-
- /// <summary>
- /// Signal <see cref="UserUnregisterWaitHandle"/> if it has not been signaled yet and is a valid handle.
- /// </summary>
- private void SignalUserWaitHandle()
- {
- _callbackLock.VerifyIsLocked();
- SafeWaitHandle handle = UserUnregisterWaitHandle;
- IntPtr handleValue = UserUnregisterWaitHandleValue;
- try
- {
- if (handleValue != IntPtr.Zero && handleValue != (IntPtr)(-1))
- {
- Debug.Assert(handleValue == handle.DangerousGetHandle());
- EventWaitHandle.Set(handle);
- }
- }
- finally
- {
- handle?.DangerousRelease();
- _callbacksComplete?.Set();
- _unregistered = true;
- }
- }
-
- /// <summary>
- /// Perform the registered callback if the <see cref="UserUnregisterWaitHandle"/> has not been signaled.
- /// </summary>
- /// <param name="timedOut">Whether or not the wait timed out.</param>
- internal void PerformCallback(bool timedOut)
- {
-#if DEBUG
- _callbackLock.Acquire();
- try
- {
- Debug.Assert(_numRequestedCallbacks != 0);
- }
- finally
- {
- _callbackLock.Release();
- }
-#endif
- _ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Callback, timedOut);
- CompleteCallbackRequest();
- }
-
- /// <summary>
- /// Tell this handle that there is a callback queued on the thread pool for this handle.
- /// </summary>
- internal void RequestCallback()
- {
- _callbackLock.Acquire();
- try
- {
- _numRequestedCallbacks++;
- }
- finally
- {
- _callbackLock.Release();
- }
- }
-
- /// <summary>
- /// Called when the wait thread removes this handle registration. This will signal the user's event if there are no callbacks pending,
- /// or note that the user's event must be signaled when the callbacks complete.
- /// </summary>
- internal void OnRemoveWait()
- {
- _callbackLock.Acquire();
- try
- {
- _removed?.Set();
- if (_numRequestedCallbacks == 0)
- {
- SignalUserWaitHandle();
- }
- else
- {
- _signalAfterCallbacksComplete = true;
- }
- }
- finally
- {
- _callbackLock.Release();
- }
- }
-
- /// <summary>
- /// Reduces the number of callbacks requested. If there are no more callbacks and the user's handle is queued to be signaled, signal it.
- /// </summary>
- private void CompleteCallbackRequest()
- {
- _callbackLock.Acquire();
- try
- {
- --_numRequestedCallbacks;
- if (_numRequestedCallbacks == 0 && _signalAfterCallbacksComplete)
- {
- SignalUserWaitHandle();
- }
- }
- finally
- {
- _callbackLock.Release();
- }
- }
-
- /// <summary>
- /// Wait for all queued callbacks and the full unregistration to complete.
- /// </summary>
- internal void WaitForCallbacks()
- {
- Debug.Assert(IsBlocking);
- Debug.Assert(_unregisterCalled); // Should only be called when the wait is unregistered by the user.
-
- _callbacksComplete.WaitOne();
- ReturnEvent(_callbacksComplete);
- _callbacksComplete = null;
- }
-
- internal void WaitForRemoval()
- {
- Debug.Assert(!IsBlocking);
- Debug.Assert(_unregisterCalled); // Should only be called when the wait is unregistered by the user.
-
- _removed.WaitOne();
- ReturnEvent(_removed);
- _removed = null;
- }
- }
-
- public static partial class ThreadPool
- {
- internal static void InitializeForThreadPoolThread() { }
-
- public static bool SetMaxThreads(int workerThreads, int completionPortThreads)
- {
- if (workerThreads < 0 || completionPortThreads < 0)
- {
- return false;
- }
- return PortableThreadPool.ThreadPoolInstance.SetMaxThreads(workerThreads);
- }
-
- public static void GetMaxThreads(out int workerThreads, out int completionPortThreads)
- {
- // Note that worker threads and completion port threads share the same thread pool.
- // The total number of threads cannot exceed MaxThreadCount.
- workerThreads = PortableThreadPool.ThreadPoolInstance.GetMaxThreads();
- completionPortThreads = 1;
- }
-
- public static bool SetMinThreads(int workerThreads, int completionPortThreads)
- {
- if (workerThreads < 0 || completionPortThreads < 0)
- {
- return false;
- }
- return PortableThreadPool.ThreadPoolInstance.SetMinThreads(workerThreads);
- }
-
- public static void GetMinThreads(out int workerThreads, out int completionPortThreads)
- {
- // All threads are pre-created at present
- workerThreads = PortableThreadPool.ThreadPoolInstance.GetMinThreads();
- completionPortThreads = 0;
- }
-
- public static void GetAvailableThreads(out int workerThreads, out int completionPortThreads)
- {
- workerThreads = PortableThreadPool.ThreadPoolInstance.GetAvailableThreads();
- completionPortThreads = 0;
- }
-
- /// <summary>
- /// Gets the number of thread pool threads that currently exist.
- /// </summary>
- /// <remarks>
- /// For a thread pool implementation that may have different types of threads, the count includes all types.
- /// </remarks>
- public static int ThreadCount => PortableThreadPool.ThreadPoolInstance.ThreadCount;
-
- /// <summary>
- /// Gets the number of work items that have been processed by the thread pool so far.
- /// </summary>
- /// <remarks>
- /// For a thread pool implementation that may have different types of work items, the count includes all types.
- /// </remarks>
- public static long CompletedWorkItemCount => PortableThreadPool.ThreadPoolInstance.CompletedWorkItemCount;
-
- /// <summary>
- /// This method is called to request a new thread pool worker to handle pending work.
- /// </summary>
- internal static void RequestWorkerThread()
- {
- PortableThreadPool.ThreadPoolInstance.RequestWorker();
- }
-
- internal static bool KeepDispatching(int startTickCount)
- {
- return true;
- }
-
- internal static void NotifyWorkItemProgress()
- {
- PortableThreadPool.ThreadPoolInstance.NotifyWorkItemComplete();
- }
-
- internal static bool NotifyWorkItemComplete()
- {
- return PortableThreadPool.ThreadPoolInstance.NotifyWorkItemComplete();
- }
-
- private static RegisteredWaitHandle RegisterWaitForSingleObject(
- WaitHandle waitObject,
- WaitOrTimerCallback callBack,
- Object state,
- uint millisecondsTimeOutInterval,
- bool executeOnlyOnce,
- bool flowExecutionContext)
- {
- if (waitObject == null)
- throw new ArgumentNullException(nameof(waitObject));
-
- if (callBack == null)
- throw new ArgumentNullException(nameof(callBack));
-
- RegisteredWaitHandle registeredHandle = new RegisteredWaitHandle(
- waitObject,
- new _ThreadPoolWaitOrTimerCallback(callBack, state, flowExecutionContext),
- (int)millisecondsTimeOutInterval,
- !executeOnlyOnce);
- PortableThreadPool.ThreadPoolInstance.RegisterWaitHandle(registeredHandle);
- return registeredHandle;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs
deleted file mode 100644
index 98ca59c2db9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs
+++ /dev/null
@@ -1,1295 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Class for creating and managing a threadpool
-**
-**
-=============================================================================*/
-
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Diagnostics.Tracing;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Threading.Tasks;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Threading
-{
- internal static class ThreadPoolGlobals
- {
- public static volatile bool threadPoolInitialized;
- public static bool enableWorkerTracking;
-
- public static readonly ThreadPoolWorkQueue workQueue = new ThreadPoolWorkQueue();
-
- /// <summary>Shim used to invoke <see cref="IAsyncStateMachineBox.MoveNext"/> of the supplied <see cref="IAsyncStateMachineBox"/>.</summary>
- internal static readonly Action<object?> s_invokeAsyncStateMachineBox = state =>
- {
- if (!(state is IAsyncStateMachineBox box))
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.state);
- return;
- }
-
- box.MoveNext();
- };
- }
-
- [StructLayout(LayoutKind.Sequential)] // enforce layout so that padding reduces false sharing
- internal sealed class ThreadPoolWorkQueue
- {
- internal static class WorkStealingQueueList
- {
-#pragma warning disable CA1825 // avoid the extra generic instantation for Array.Empty<T>(); this is the only place we'll ever create this array
- private static volatile WorkStealingQueue[] _queues = new WorkStealingQueue[0];
-#pragma warning restore CA1825
-
- public static WorkStealingQueue[] Queues => _queues;
-
- public static void Add(WorkStealingQueue queue)
- {
- Debug.Assert(queue != null);
- while (true)
- {
- WorkStealingQueue[] oldQueues = _queues;
- Debug.Assert(Array.IndexOf(oldQueues, queue) == -1);
-
- var newQueues = new WorkStealingQueue[oldQueues.Length + 1];
- Array.Copy(oldQueues, newQueues, oldQueues.Length);
- newQueues[^1] = queue;
- if (Interlocked.CompareExchange(ref _queues, newQueues, oldQueues) == oldQueues)
- {
- break;
- }
- }
- }
-
- public static void Remove(WorkStealingQueue queue)
- {
- Debug.Assert(queue != null);
- while (true)
- {
- WorkStealingQueue[] oldQueues = _queues;
- if (oldQueues.Length == 0)
- {
- return;
- }
-
- int pos = Array.IndexOf(oldQueues, queue);
- if (pos == -1)
- {
- Debug.Fail("Should have found the queue");
- return;
- }
-
- var newQueues = new WorkStealingQueue[oldQueues.Length - 1];
- if (pos == 0)
- {
- Array.Copy(oldQueues, 1, newQueues, 0, newQueues.Length);
- }
- else if (pos == oldQueues.Length - 1)
- {
- Array.Copy(oldQueues, newQueues, newQueues.Length);
- }
- else
- {
- Array.Copy(oldQueues, newQueues, pos);
- Array.Copy(oldQueues, pos + 1, newQueues, pos, newQueues.Length - pos);
- }
-
- if (Interlocked.CompareExchange(ref _queues, newQueues, oldQueues) == oldQueues)
- {
- break;
- }
- }
- }
- }
-
- internal sealed class WorkStealingQueue
- {
- private const int INITIAL_SIZE = 32;
- internal volatile object?[] m_array = new object[INITIAL_SIZE]; // SOS's ThreadPool command depends on this name
- private volatile int m_mask = INITIAL_SIZE - 1;
-
-#if DEBUG
- // in debug builds, start at the end so we exercise the index reset logic.
- private const int START_INDEX = int.MaxValue;
-#else
- private const int START_INDEX = 0;
-#endif
-
- private volatile int m_headIndex = START_INDEX;
- private volatile int m_tailIndex = START_INDEX;
-
- private SpinLock m_foreignLock = new SpinLock(enableThreadOwnerTracking: false);
-
- public void LocalPush(object obj)
- {
- int tail = m_tailIndex;
-
- // We're going to increment the tail; if we'll overflow, then we need to reset our counts
- if (tail == int.MaxValue)
- {
- bool lockTaken = false;
- try
- {
- m_foreignLock.Enter(ref lockTaken);
-
- if (m_tailIndex == int.MaxValue)
- {
- //
- // Rather than resetting to zero, we'll just mask off the bits we don't care about.
- // This way we don't need to rearrange the items already in the queue; they'll be found
- // correctly exactly where they are. One subtlety here is that we need to make sure that
- // if head is currently < tail, it remains that way. This happens to just fall out from
- // the bit-masking, because we only do this if tail == int.MaxValue, meaning that all
- // bits are set, so all of the bits we're keeping will also be set. Thus it's impossible
- // for the head to end up > than the tail, since you can't set any more bits than all of
- // them.
- //
- m_headIndex &= m_mask;
- m_tailIndex = tail = m_tailIndex & m_mask;
- Debug.Assert(m_headIndex <= m_tailIndex);
- }
- }
- finally
- {
- if (lockTaken)
- m_foreignLock.Exit(useMemoryBarrier: true);
- }
- }
-
- // When there are at least 2 elements' worth of space, we can take the fast path.
- if (tail < m_headIndex + m_mask)
- {
- Volatile.Write(ref m_array[tail & m_mask], obj);
- m_tailIndex = tail + 1;
- }
- else
- {
- // We need to contend with foreign pops, so we lock.
- bool lockTaken = false;
- try
- {
- m_foreignLock.Enter(ref lockTaken);
-
- int head = m_headIndex;
- int count = m_tailIndex - m_headIndex;
-
- // If there is still space (one left), just add the element.
- if (count >= m_mask)
- {
- // We're full; expand the queue by doubling its size.
- var newArray = new object?[m_array.Length << 1];
- for (int i = 0; i < m_array.Length; i++)
- newArray[i] = m_array[(i + head) & m_mask];
-
- // Reset the field values, incl. the mask.
- m_array = newArray;
- m_headIndex = 0;
- m_tailIndex = tail = count;
- m_mask = (m_mask << 1) | 1;
- }
-
- Volatile.Write(ref m_array[tail & m_mask], obj);
- m_tailIndex = tail + 1;
- }
- finally
- {
- if (lockTaken)
- m_foreignLock.Exit(useMemoryBarrier: false);
- }
- }
- }
-
- public bool LocalFindAndPop(object obj)
- {
- // Fast path: check the tail. If equal, we can skip the lock.
- if (m_array[(m_tailIndex - 1) & m_mask] == obj)
- {
- object? unused = LocalPop();
- Debug.Assert(unused == null || unused == obj);
- return unused != null;
- }
-
- // Else, do an O(N) search for the work item. The theory of work stealing and our
- // inlining logic is that most waits will happen on recently queued work. And
- // since recently queued work will be close to the tail end (which is where we
- // begin our search), we will likely find it quickly. In the worst case, we
- // will traverse the whole local queue; this is typically not going to be a
- // problem (although degenerate cases are clearly an issue) because local work
- // queues tend to be somewhat shallow in length, and because if we fail to find
- // the work item, we are about to block anyway (which is very expensive).
- for (int i = m_tailIndex - 2; i >= m_headIndex; i--)
- {
- if (m_array[i & m_mask] == obj)
- {
- // If we found the element, block out steals to avoid interference.
- bool lockTaken = false;
- try
- {
- m_foreignLock.Enter(ref lockTaken);
-
- // If we encountered a race condition, bail.
- if (m_array[i & m_mask] == null)
- return false;
-
- // Otherwise, null out the element.
- Volatile.Write(ref m_array[i & m_mask], null);
-
- // And then check to see if we can fix up the indexes (if we're at
- // the edge). If we can't, we just leave nulls in the array and they'll
- // get filtered out eventually (but may lead to superfluous resizing).
- if (i == m_tailIndex)
- m_tailIndex--;
- else if (i == m_headIndex)
- m_headIndex++;
-
- return true;
- }
- finally
- {
- if (lockTaken)
- m_foreignLock.Exit(useMemoryBarrier: false);
- }
- }
- }
-
- return false;
- }
-
- public object? LocalPop() => m_headIndex < m_tailIndex ? LocalPopCore() : null;
-
- private object? LocalPopCore()
- {
- while (true)
- {
- int tail = m_tailIndex;
- if (m_headIndex >= tail)
- {
- return null;
- }
-
- // Decrement the tail using a fence to ensure subsequent read doesn't come before.
- tail--;
- Interlocked.Exchange(ref m_tailIndex, tail);
-
- // If there is no interaction with a take, we can head down the fast path.
- if (m_headIndex <= tail)
- {
- int idx = tail & m_mask;
- object? obj = Volatile.Read(ref m_array[idx]);
-
- // Check for nulls in the array.
- if (obj == null) continue;
-
- m_array[idx] = null;
- return obj;
- }
- else
- {
- // Interaction with takes: 0 or 1 elements left.
- bool lockTaken = false;
- try
- {
- m_foreignLock.Enter(ref lockTaken);
-
- if (m_headIndex <= tail)
- {
- // Element still available. Take it.
- int idx = tail & m_mask;
- object? obj = Volatile.Read(ref m_array[idx]);
-
- // Check for nulls in the array.
- if (obj == null) continue;
-
- m_array[idx] = null;
- return obj;
- }
- else
- {
- // If we encountered a race condition and element was stolen, restore the tail.
- m_tailIndex = tail + 1;
- return null;
- }
- }
- finally
- {
- if (lockTaken)
- m_foreignLock.Exit(useMemoryBarrier: false);
- }
- }
- }
- }
-
- public bool CanSteal => m_headIndex < m_tailIndex;
-
- public object? TrySteal(ref bool missedSteal)
- {
- while (true)
- {
- if (CanSteal)
- {
- bool taken = false;
- try
- {
- m_foreignLock.TryEnter(ref taken);
- if (taken)
- {
- // Increment head, and ensure read of tail doesn't move before it (fence).
- int head = m_headIndex;
- Interlocked.Exchange(ref m_headIndex, head + 1);
-
- if (head < m_tailIndex)
- {
- int idx = head & m_mask;
- object? obj = Volatile.Read(ref m_array[idx]);
-
- // Check for nulls in the array.
- if (obj == null) continue;
-
- m_array[idx] = null;
- return obj;
- }
- else
- {
- // Failed, restore head.
- m_headIndex = head;
- }
- }
- }
- finally
- {
- if (taken)
- m_foreignLock.Exit(useMemoryBarrier: false);
- }
-
- missedSteal = true;
- }
-
- return null;
- }
- }
-
- public int Count
- {
- get
- {
- bool lockTaken = false;
- try
- {
- m_foreignLock.Enter(ref lockTaken);
- return Math.Max(0, m_tailIndex - m_headIndex);
- }
- finally
- {
- if (lockTaken)
- {
- m_foreignLock.Exit(useMemoryBarrier: false);
- }
- }
- }
- }
- }
-
- internal bool loggingEnabled;
- internal readonly ConcurrentQueue<object> workItems = new ConcurrentQueue<object>(); // SOS's ThreadPool command depends on this name
-
- private readonly Internal.PaddingFor32 pad1;
-
- private volatile int numOutstandingThreadRequests = 0;
-
- private readonly Internal.PaddingFor32 pad2;
-
- public ThreadPoolWorkQueue()
- {
- loggingEnabled = FrameworkEventSource.Log.IsEnabled(EventLevel.Verbose, FrameworkEventSource.Keywords.ThreadPool | FrameworkEventSource.Keywords.ThreadTransfer);
- }
-
- public ThreadPoolWorkQueueThreadLocals GetOrCreateThreadLocals() =>
- ThreadPoolWorkQueueThreadLocals.threadLocals ?? CreateThreadLocals();
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private ThreadPoolWorkQueueThreadLocals CreateThreadLocals()
- {
- Debug.Assert(ThreadPoolWorkQueueThreadLocals.threadLocals == null);
-
- return ThreadPoolWorkQueueThreadLocals.threadLocals = new ThreadPoolWorkQueueThreadLocals(this);
- }
-
- internal void EnsureThreadRequested()
- {
- //
- // If we have not yet requested #procs threads, then request a new thread.
- //
- // CoreCLR: Note that there is a separate count in the VM which has already been incremented
- // by the VM by the time we reach this point.
- //
- int count = numOutstandingThreadRequests;
- while (count < Environment.ProcessorCount)
- {
- int prev = Interlocked.CompareExchange(ref numOutstandingThreadRequests, count + 1, count);
- if (prev == count)
- {
- ThreadPool.RequestWorkerThread();
- break;
- }
- count = prev;
- }
- }
-
- internal void MarkThreadRequestSatisfied()
- {
- //
- // One of our outstanding thread requests has been satisfied.
- // Decrement the count so that future calls to EnsureThreadRequested will succeed.
- //
- // CoreCLR: Note that there is a separate count in the VM which has already been decremented
- // by the VM by the time we reach this point.
- //
- int count = numOutstandingThreadRequests;
- while (count > 0)
- {
- int prev = Interlocked.CompareExchange(ref numOutstandingThreadRequests, count - 1, count);
- if (prev == count)
- {
- break;
- }
- count = prev;
- }
- }
-
- public void Enqueue(object callback, bool forceGlobal)
- {
- Debug.Assert((callback is IThreadPoolWorkItem) ^ (callback is Task));
-
- if (loggingEnabled)
- System.Diagnostics.Tracing.FrameworkEventSource.Log.ThreadPoolEnqueueWorkObject(callback);
-
- ThreadPoolWorkQueueThreadLocals? tl = null;
- if (!forceGlobal)
- tl = ThreadPoolWorkQueueThreadLocals.threadLocals;
-
- if (null != tl)
- {
- tl.workStealingQueue.LocalPush(callback);
- }
- else
- {
- workItems.Enqueue(callback);
- }
-
- EnsureThreadRequested();
- }
-
- internal bool LocalFindAndPop(object callback)
- {
- ThreadPoolWorkQueueThreadLocals? tl = ThreadPoolWorkQueueThreadLocals.threadLocals;
- return tl != null && tl.workStealingQueue.LocalFindAndPop(callback);
- }
-
- public object? Dequeue(ThreadPoolWorkQueueThreadLocals tl, ref bool missedSteal)
- {
- WorkStealingQueue localWsq = tl.workStealingQueue;
- object? callback;
-
- if ((callback = localWsq.LocalPop()) == null && // first try the local queue
- !workItems.TryDequeue(out callback)) // then try the global queue
- {
- // finally try to steal from another thread's local queue
- WorkStealingQueue[] queues = WorkStealingQueueList.Queues;
- int c = queues.Length;
- Debug.Assert(c > 0, "There must at least be a queue for this thread.");
- int maxIndex = c - 1;
- int i = tl.random.Next(c);
- while (c > 0)
- {
- i = (i < maxIndex) ? i + 1 : 0;
- WorkStealingQueue otherQueue = queues[i];
- if (otherQueue != localWsq && otherQueue.CanSteal)
- {
- callback = otherQueue.TrySteal(ref missedSteal);
- if (callback != null)
- {
- break;
- }
- }
- c--;
- }
- }
-
- return callback;
- }
-
- public long LocalCount
- {
- get
- {
- long count = 0;
- foreach (WorkStealingQueue workStealingQueue in WorkStealingQueueList.Queues)
- {
- count += workStealingQueue.Count;
- }
- return count;
- }
- }
-
- public long GlobalCount => workItems.Count;
-
- /// <summary>
- /// Dispatches work items to this thread.
- /// </summary>
- /// <returns>
- /// <c>true</c> if this thread did as much work as was available or its quantum expired.
- /// <c>false</c> if this thread stopped working early.
- /// </returns>
- internal static bool Dispatch()
- {
- ThreadPoolWorkQueue outerWorkQueue = ThreadPoolGlobals.workQueue;
-
- //
- // Save the start time
- //
- int startTickCount = Environment.TickCount;
-
- //
- // Update our records to indicate that an outstanding request for a thread has now been fulfilled.
- // From this point on, we are responsible for requesting another thread if we stop working for any
- // reason, and we believe there might still be work in the queue.
- //
- // CoreCLR: Note that if this thread is aborted before we get a chance to request another one, the VM will
- // record a thread request on our behalf. So we don't need to worry about getting aborted right here.
- //
- outerWorkQueue.MarkThreadRequestSatisfied();
-
- // Has the desire for logging changed since the last time we entered?
- outerWorkQueue.loggingEnabled = FrameworkEventSource.Log.IsEnabled(EventLevel.Verbose, FrameworkEventSource.Keywords.ThreadPool | FrameworkEventSource.Keywords.ThreadTransfer);
-
- //
- // Assume that we're going to need another thread if this one returns to the VM. We'll set this to
- // false later, but only if we're absolutely certain that the queue is empty.
- //
- bool needAnotherThread = true;
- try
- {
- //
- // Set up our thread-local data
- //
- // Use operate on workQueue local to try block so it can be enregistered
- ThreadPoolWorkQueue workQueue = outerWorkQueue;
- ThreadPoolWorkQueueThreadLocals tl = workQueue.GetOrCreateThreadLocals();
- Thread currentThread = tl.currentThread;
-
- // Start on clean ExecutionContext and SynchronizationContext
- currentThread._executionContext = null;
- currentThread._synchronizationContext = null;
-
- //
- // Loop until our quantum expires or there is no work.
- //
- while (ThreadPool.KeepDispatching(startTickCount))
- {
- bool missedSteal = false;
- // Use operate on workItem local to try block so it can be enregistered
- object? workItem = workQueue.Dequeue(tl, ref missedSteal);
-
- if (workItem == null)
- {
- //
- // No work.
- // If we missed a steal, though, there may be more work in the queue.
- // Instead of looping around and trying again, we'll just request another thread. Hopefully the thread
- // that owns the contended work-stealing queue will pick up its own workitems in the meantime,
- // which will be more efficient than this thread doing it anyway.
- //
- needAnotherThread = missedSteal;
-
- // Tell the VM we're returning normally, not because Hill Climbing asked us to return.
- return true;
- }
-
- if (workQueue.loggingEnabled)
- System.Diagnostics.Tracing.FrameworkEventSource.Log.ThreadPoolDequeueWorkObject(workItem);
-
- //
- // If we found work, there may be more work. Ask for another thread so that the other work can be processed
- // in parallel. Note that this will only ask for a max of #procs threads, so it's safe to call it for every dequeue.
- //
- workQueue.EnsureThreadRequested();
-
- //
- // Execute the workitem outside of any finally blocks, so that it can be aborted if needed.
- //
- if (ThreadPoolGlobals.enableWorkerTracking)
- {
- bool reportedStatus = false;
- try
- {
- ThreadPool.ReportThreadStatus(isWorking: true);
- reportedStatus = true;
- if (workItem is Task task)
- {
- task.ExecuteFromThreadPool(currentThread);
- }
- else
- {
- Debug.Assert(workItem is IThreadPoolWorkItem);
- Unsafe.As<IThreadPoolWorkItem>(workItem).Execute();
- }
- }
- finally
- {
- if (reportedStatus)
- ThreadPool.ReportThreadStatus(isWorking: false);
- }
- }
- else if (workItem is Task task)
- {
- // Check for Task first as it's currently faster to type check
- // for Task and then Unsafe.As for the interface, rather than
- // vice versa, in particular when the object implements a bunch
- // of interfaces.
- task.ExecuteFromThreadPool(currentThread);
- }
- else
- {
- Debug.Assert(workItem is IThreadPoolWorkItem);
- Unsafe.As<IThreadPoolWorkItem>(workItem).Execute();
- }
-
- currentThread.ResetThreadPoolThread();
-
- // Release refs
- workItem = null;
-
- // Return to clean ExecutionContext and SynchronizationContext
- ExecutionContext.ResetThreadPoolThread(currentThread);
-
- //
- // Notify the VM that we executed this workitem. This is also our opportunity to ask whether Hill Climbing wants
- // us to return the thread to the pool or not.
- //
- if (!ThreadPool.NotifyWorkItemComplete())
- return false;
- }
-
- // If we get here, it's because our quantum expired. Tell the VM we're returning normally.
- return true;
- }
- finally
- {
- //
- // If we are exiting for any reason other than that the queue is definitely empty, ask for another
- // thread to pick up where we left off.
- //
- if (needAnotherThread)
- outerWorkQueue.EnsureThreadRequested();
- }
- }
- }
-
- // Simple random number generator. We don't need great randomness, we just need a little and for it to be fast.
- internal struct FastRandom // xorshift prng
- {
- private uint _w, _x, _y, _z;
-
- public FastRandom(int seed)
- {
- _x = (uint)seed;
- _w = 88675123;
- _y = 362436069;
- _z = 521288629;
- }
-
- public int Next(int maxValue)
- {
- Debug.Assert(maxValue > 0);
-
- uint t = _x ^ (_x << 11);
- _x = _y; _y = _z; _z = _w;
- _w = _w ^ (_w >> 19) ^ (t ^ (t >> 8));
-
- return (int)(_w % (uint)maxValue);
- }
- }
-
- // Holds a WorkStealingQueue, and removes it from the list when this object is no longer referenced.
- internal sealed class ThreadPoolWorkQueueThreadLocals
- {
- [ThreadStatic]
- public static ThreadPoolWorkQueueThreadLocals? threadLocals;
-
- public readonly ThreadPoolWorkQueue workQueue;
- public readonly ThreadPoolWorkQueue.WorkStealingQueue workStealingQueue;
- public readonly Thread currentThread;
- public FastRandom random = new FastRandom(Thread.CurrentThread.ManagedThreadId); // mutable struct, do not copy or make readonly
-
- public ThreadPoolWorkQueueThreadLocals(ThreadPoolWorkQueue tpq)
- {
- workQueue = tpq;
- workStealingQueue = new ThreadPoolWorkQueue.WorkStealingQueue();
- ThreadPoolWorkQueue.WorkStealingQueueList.Add(workStealingQueue);
- currentThread = Thread.CurrentThread;
- }
-
- ~ThreadPoolWorkQueueThreadLocals()
- {
- // Transfer any pending workitems into the global queue so that they will be executed by another thread
- if (null != workStealingQueue)
- {
- if (null != workQueue)
- {
- object? cb;
- while ((cb = workStealingQueue.LocalPop()) != null)
- {
- Debug.Assert(null != cb);
- workQueue.Enqueue(cb, forceGlobal: true);
- }
- }
-
- ThreadPoolWorkQueue.WorkStealingQueueList.Remove(workStealingQueue);
- }
- }
- }
-
- public delegate void WaitCallback(object? state);
-
- public delegate void WaitOrTimerCallback(object? state, bool timedOut); // signaled or timed out
-
- internal abstract class QueueUserWorkItemCallbackBase : IThreadPoolWorkItem
- {
-#if DEBUG
- private int executed;
-
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1821:RemoveEmptyFinalizers")]
- ~QueueUserWorkItemCallbackBase()
- {
- Interlocked.MemoryBarrier(); // ensure that an old cached value is not read below
- Debug.Assert(
- executed != 0, "A QueueUserWorkItemCallback was never called!");
- }
-#endif
-
- public virtual void Execute()
- {
-#if DEBUG
- GC.SuppressFinalize(this);
- Debug.Assert(
- 0 == Interlocked.Exchange(ref executed, 1),
- "A QueueUserWorkItemCallback was called twice!");
-#endif
- }
- }
-
- internal sealed class QueueUserWorkItemCallback : QueueUserWorkItemCallbackBase
- {
- private WaitCallback? _callback; // SOS's ThreadPool command depends on this name
- private readonly object? _state;
- private readonly ExecutionContext _context;
-
- private static readonly Action<QueueUserWorkItemCallback> s_executionContextShim = quwi =>
- {
- Debug.Assert(quwi._callback != null);
- WaitCallback callback = quwi._callback;
- quwi._callback = null;
-
- callback(quwi._state);
- };
-
- internal QueueUserWorkItemCallback(WaitCallback callback, object? state, ExecutionContext context)
- {
- Debug.Assert(context != null);
-
- _callback = callback;
- _state = state;
- _context = context;
- }
-
- public override void Execute()
- {
- base.Execute();
-
- ExecutionContext.RunForThreadPoolUnsafe(_context, s_executionContextShim, this);
- }
- }
-
- internal sealed class QueueUserWorkItemCallback<TState> : QueueUserWorkItemCallbackBase
- {
- private Action<TState>? _callback; // SOS's ThreadPool command depends on this name
- private readonly TState _state;
- private readonly ExecutionContext _context;
-
- internal QueueUserWorkItemCallback(Action<TState> callback, TState state, ExecutionContext context)
- {
- Debug.Assert(callback != null);
-
- _callback = callback;
- _state = state;
- _context = context;
- }
-
- public override void Execute()
- {
- base.Execute();
-
- Debug.Assert(_callback != null);
- Action<TState> callback = _callback;
- _callback = null;
-
- ExecutionContext.RunForThreadPoolUnsafe(_context, callback, in _state);
- }
- }
-
- internal sealed class QueueUserWorkItemCallbackDefaultContext : QueueUserWorkItemCallbackBase
- {
- private WaitCallback? _callback; // SOS's ThreadPool command depends on this name
- private readonly object? _state;
-
- internal QueueUserWorkItemCallbackDefaultContext(WaitCallback callback, object? state)
- {
- Debug.Assert(callback != null);
-
- _callback = callback;
- _state = state;
- }
-
- public override void Execute()
- {
- ExecutionContext.CheckThreadPoolAndContextsAreDefault();
- base.Execute();
-
- Debug.Assert(_callback != null);
- WaitCallback callback = _callback;
- _callback = null;
-
- callback(_state);
-
- // ThreadPoolWorkQueue.Dispatch will handle notifications and reset EC and SyncCtx back to default
- }
- }
-
- internal sealed class QueueUserWorkItemCallbackDefaultContext<TState> : QueueUserWorkItemCallbackBase
- {
- private Action<TState>? _callback; // SOS's ThreadPool command depends on this name
- private readonly TState _state;
-
- internal QueueUserWorkItemCallbackDefaultContext(Action<TState> callback, TState state)
- {
- Debug.Assert(callback != null);
-
- _callback = callback;
- _state = state;
- }
-
- public override void Execute()
- {
- ExecutionContext.CheckThreadPoolAndContextsAreDefault();
- base.Execute();
-
- Debug.Assert(_callback != null);
- Action<TState> callback = _callback;
- _callback = null;
-
- callback(_state);
-
- // ThreadPoolWorkQueue.Dispatch will handle notifications and reset EC and SyncCtx back to default
- }
- }
-
- internal sealed class _ThreadPoolWaitOrTimerCallback
- {
- private readonly WaitOrTimerCallback _waitOrTimerCallback;
- private readonly ExecutionContext? _executionContext;
- private readonly object? _state;
- private static readonly ContextCallback _ccbt = new ContextCallback(WaitOrTimerCallback_Context_t);
- private static readonly ContextCallback _ccbf = new ContextCallback(WaitOrTimerCallback_Context_f);
-
- internal _ThreadPoolWaitOrTimerCallback(WaitOrTimerCallback waitOrTimerCallback, object? state, bool flowExecutionContext)
- {
- _waitOrTimerCallback = waitOrTimerCallback;
- _state = state;
-
- if (flowExecutionContext)
- {
- // capture the exection context
- _executionContext = ExecutionContext.Capture();
- }
- }
-
- private static void WaitOrTimerCallback_Context_t(object? state) =>
- WaitOrTimerCallback_Context(state, timedOut: true);
-
- private static void WaitOrTimerCallback_Context_f(object? state) =>
- WaitOrTimerCallback_Context(state, timedOut: false);
-
- private static void WaitOrTimerCallback_Context(object? state, bool timedOut)
- {
- _ThreadPoolWaitOrTimerCallback helper = (_ThreadPoolWaitOrTimerCallback)state!;
- helper._waitOrTimerCallback(helper._state, timedOut);
- }
-
- // call back helper
- internal static void PerformWaitOrTimerCallback(_ThreadPoolWaitOrTimerCallback helper, bool timedOut)
- {
- Debug.Assert(helper != null, "Null state passed to PerformWaitOrTimerCallback!");
- // call directly if it is an unsafe call OR EC flow is suppressed
- ExecutionContext? context = helper._executionContext;
- if (context == null)
- {
- WaitOrTimerCallback callback = helper._waitOrTimerCallback;
- callback(helper._state, timedOut);
- }
- else
- {
- ExecutionContext.Run(context, timedOut ? _ccbt : _ccbf, helper);
- }
- }
- }
-
- public static partial class ThreadPool
- {
- [CLSCompliant(false)]
- public static RegisteredWaitHandle RegisterWaitForSingleObject(
- WaitHandle waitObject,
- WaitOrTimerCallback callBack,
- object? state,
- uint millisecondsTimeOutInterval,
- bool executeOnlyOnce // NOTE: we do not allow other options that allow the callback to be queued as an APC
- )
- {
- if (millisecondsTimeOutInterval > (uint)int.MaxValue && millisecondsTimeOutInterval != uint.MaxValue)
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), SR.ArgumentOutOfRange_LessEqualToIntegerMaxVal);
- return RegisterWaitForSingleObject(waitObject, callBack, state, millisecondsTimeOutInterval, executeOnlyOnce, true);
- }
-
- [CLSCompliant(false)]
- public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(
- WaitHandle waitObject,
- WaitOrTimerCallback callBack,
- object? state,
- uint millisecondsTimeOutInterval,
- bool executeOnlyOnce // NOTE: we do not allow other options that allow the callback to be queued as an APC
- )
- {
- if (millisecondsTimeOutInterval > (uint)int.MaxValue && millisecondsTimeOutInterval != uint.MaxValue)
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- return RegisterWaitForSingleObject(waitObject, callBack, state, millisecondsTimeOutInterval, executeOnlyOnce, false);
- }
-
- public static RegisteredWaitHandle RegisterWaitForSingleObject(
- WaitHandle waitObject,
- WaitOrTimerCallback callBack,
- object? state,
- int millisecondsTimeOutInterval,
- bool executeOnlyOnce // NOTE: we do not allow other options that allow the callback to be queued as an APC
- )
- {
- if (millisecondsTimeOutInterval < -1)
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, true);
- }
-
- public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(
- WaitHandle waitObject,
- WaitOrTimerCallback callBack,
- object? state,
- int millisecondsTimeOutInterval,
- bool executeOnlyOnce // NOTE: we do not allow other options that allow the callback to be queued as an APC
- )
- {
- if (millisecondsTimeOutInterval < -1)
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, false);
- }
-
- public static RegisteredWaitHandle RegisterWaitForSingleObject(
- WaitHandle waitObject,
- WaitOrTimerCallback callBack,
- object? state,
- long millisecondsTimeOutInterval,
- bool executeOnlyOnce // NOTE: we do not allow other options that allow the callback to be queued as an APC
- )
- {
- if (millisecondsTimeOutInterval < -1)
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (millisecondsTimeOutInterval > (uint)int.MaxValue)
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), SR.ArgumentOutOfRange_LessEqualToIntegerMaxVal);
- return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, true);
- }
-
- public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(
- WaitHandle waitObject,
- WaitOrTimerCallback callBack,
- object? state,
- long millisecondsTimeOutInterval,
- bool executeOnlyOnce // NOTE: we do not allow other options that allow the callback to be queued as an APC
- )
- {
- if (millisecondsTimeOutInterval < -1)
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (millisecondsTimeOutInterval > (uint)int.MaxValue)
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), SR.ArgumentOutOfRange_LessEqualToIntegerMaxVal);
- return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, false);
- }
-
- public static RegisteredWaitHandle RegisterWaitForSingleObject(
- WaitHandle waitObject,
- WaitOrTimerCallback callBack,
- object? state,
- TimeSpan timeout,
- bool executeOnlyOnce
- )
- {
- long tm = (long)timeout.TotalMilliseconds;
- if (tm < -1)
- throw new ArgumentOutOfRangeException(nameof(timeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (tm > (long)int.MaxValue)
- throw new ArgumentOutOfRangeException(nameof(timeout), SR.ArgumentOutOfRange_LessEqualToIntegerMaxVal);
- return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)tm, executeOnlyOnce, true);
- }
-
- public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(
- WaitHandle waitObject,
- WaitOrTimerCallback callBack,
- object? state,
- TimeSpan timeout,
- bool executeOnlyOnce
- )
- {
- long tm = (long)timeout.TotalMilliseconds;
- if (tm < -1)
- throw new ArgumentOutOfRangeException(nameof(timeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (tm > (long)int.MaxValue)
- throw new ArgumentOutOfRangeException(nameof(timeout), SR.ArgumentOutOfRange_LessEqualToIntegerMaxVal);
- return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)tm, executeOnlyOnce, false);
- }
-
- public static bool QueueUserWorkItem(WaitCallback callBack) =>
- QueueUserWorkItem(callBack, null);
-
- public static bool QueueUserWorkItem(WaitCallback callBack, object? state)
- {
- if (callBack == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.callBack);
- }
-
- EnsureInitialized();
-
- ExecutionContext? context = ExecutionContext.Capture();
-
- object tpcallBack = (context == null || context.IsDefault) ?
- new QueueUserWorkItemCallbackDefaultContext(callBack!, state) :
- (object)new QueueUserWorkItemCallback(callBack!, state, context);
-
- ThreadPoolGlobals.workQueue.Enqueue(tpcallBack, forceGlobal: true);
-
- return true;
- }
-
- public static bool QueueUserWorkItem<TState>(Action<TState> callBack, TState state, bool preferLocal)
- {
- if (callBack == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.callBack);
- }
-
- EnsureInitialized();
-
- ExecutionContext? context = ExecutionContext.Capture();
-
- object tpcallBack = (context == null || context.IsDefault) ?
- new QueueUserWorkItemCallbackDefaultContext<TState>(callBack!, state) :
- (object)new QueueUserWorkItemCallback<TState>(callBack!, state, context);
-
- ThreadPoolGlobals.workQueue.Enqueue(tpcallBack, forceGlobal: !preferLocal);
-
- return true;
- }
-
- public static bool UnsafeQueueUserWorkItem<TState>(Action<TState> callBack, TState state, bool preferLocal)
- {
- if (callBack == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.callBack);
- }
-
- // If the callback is the runtime-provided invocation of an IAsyncStateMachineBox,
- // then we can queue the Task state directly to the ThreadPool instead of
- // wrapping it in a QueueUserWorkItemCallback.
- //
- // This occurs when user code queues its provided continuation to the ThreadPool;
- // internally we call UnsafeQueueUserWorkItemInternal directly for Tasks.
- if (ReferenceEquals(callBack, ThreadPoolGlobals.s_invokeAsyncStateMachineBox))
- {
- if (!(state is IAsyncStateMachineBox))
- {
- // The provided state must be the internal IAsyncStateMachineBox (Task) type
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.state);
- }
-
- UnsafeQueueUserWorkItemInternal((object)state!, preferLocal);
- return true;
- }
-
- EnsureInitialized();
-
- ThreadPoolGlobals.workQueue.Enqueue(
- new QueueUserWorkItemCallbackDefaultContext<TState>(callBack!, state), forceGlobal: !preferLocal);
-
- return true;
- }
-
- public static bool UnsafeQueueUserWorkItem(WaitCallback callBack, object? state)
- {
- if (callBack == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.callBack);
- }
-
- EnsureInitialized();
-
- object tpcallBack = new QueueUserWorkItemCallbackDefaultContext(callBack!, state);
-
- ThreadPoolGlobals.workQueue.Enqueue(tpcallBack, forceGlobal: true);
-
- return true;
- }
-
- public static bool UnsafeQueueUserWorkItem(IThreadPoolWorkItem callBack, bool preferLocal)
- {
- if (callBack == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.callBack);
- }
- if (callBack is Task)
- {
- // Prevent code from queueing a derived Task that also implements the interface,
- // as that would bypass Task.Start and its safety checks.
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.callBack);
- }
-
- UnsafeQueueUserWorkItemInternal(callBack!, preferLocal);
- return true;
- }
-
- internal static void UnsafeQueueUserWorkItemInternal(object callBack, bool preferLocal)
- {
- Debug.Assert((callBack is IThreadPoolWorkItem) ^ (callBack is Task));
-
- EnsureInitialized();
-
- ThreadPoolGlobals.workQueue.Enqueue(callBack, forceGlobal: !preferLocal);
- }
-
- // This method tries to take the target callback out of the current thread's queue.
- internal static bool TryPopCustomWorkItem(object workItem)
- {
- Debug.Assert(null != workItem);
- return
- ThreadPoolGlobals.threadPoolInitialized && // if not initialized, so there's no way this workitem was ever queued.
- ThreadPoolGlobals.workQueue.LocalFindAndPop(workItem);
- }
-
- // Get all workitems. Called by TaskScheduler in its debugger hooks.
- internal static IEnumerable<object> GetQueuedWorkItems()
- {
- // Enumerate global queue
- foreach (object workItem in ThreadPoolGlobals.workQueue.workItems)
- {
- yield return workItem;
- }
-
- // Enumerate each local queue
- foreach (ThreadPoolWorkQueue.WorkStealingQueue wsq in ThreadPoolWorkQueue.WorkStealingQueueList.Queues)
- {
- if (wsq != null && wsq.m_array != null)
- {
- object?[] items = wsq.m_array;
- for (int i = 0; i < items.Length; i++)
- {
- object? item = items[i];
- if (item != null)
- {
- yield return item;
- }
- }
- }
- }
- }
-
- internal static IEnumerable<object> GetLocallyQueuedWorkItems()
- {
- ThreadPoolWorkQueue.WorkStealingQueue? wsq = ThreadPoolWorkQueueThreadLocals.threadLocals?.workStealingQueue;
- if (wsq != null && wsq.m_array != null)
- {
- object?[] items = wsq.m_array;
- for (int i = 0; i < items.Length; i++)
- {
- object? item = items[i];
- if (item != null)
- yield return item;
- }
- }
- }
-
- internal static IEnumerable<object> GetGloballyQueuedWorkItems() => ThreadPoolGlobals.workQueue.workItems;
-
- private static object[] ToObjectArray(IEnumerable<object> workitems)
- {
- int i = 0;
- foreach (object item in workitems)
- {
- i++;
- }
-
- object[] result = new object[i];
- i = 0;
- foreach (object item in workitems)
- {
- if (i < result.Length) // just in case someone calls us while the queues are in motion
- result[i] = item;
- i++;
- }
-
- return result;
- }
-
- // This is the method the debugger will actually call, if it ends up calling
- // into ThreadPool directly. Tests can use this to simulate a debugger, as well.
- internal static object[] GetQueuedWorkItemsForDebugger() =>
- ToObjectArray(GetQueuedWorkItems());
-
- internal static object[] GetGloballyQueuedWorkItemsForDebugger() =>
- ToObjectArray(GetGloballyQueuedWorkItems());
-
- internal static object[] GetLocallyQueuedWorkItemsForDebugger() =>
- ToObjectArray(GetLocallyQueuedWorkItems());
-
- /// <summary>
- /// Gets the number of work items that are currently queued to be processed.
- /// </summary>
- /// <remarks>
- /// For a thread pool implementation that may have different types of work items, the count includes all types that can
- /// be tracked, which may only be the user work items including tasks. Some implementations may also include queued
- /// timer and wait callbacks in the count. On Windows, the count is unlikely to include the number of pending IO
- /// completions, as they get posted directly to an IO completion port.
- /// </remarks>
- public static long PendingWorkItemCount
- {
- get
- {
- ThreadPoolWorkQueue workQueue = ThreadPoolGlobals.workQueue;
- return workQueue.LocalCount + workQueue.GlobalCount + PendingUnmanagedWorkItemCount;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPoolBoundHandle.PlatformNotSupported.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPoolBoundHandle.PlatformNotSupported.cs
deleted file mode 100644
index e71a90e9a55..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPoolBoundHandle.PlatformNotSupported.cs
+++ /dev/null
@@ -1,72 +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.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.IO;
-
-namespace System.Threading
-{
- public sealed class ThreadPoolBoundHandle : IDisposable
- {
- public SafeHandle Handle => null;
-
- private ThreadPoolBoundHandle()
- {
- }
-
- public static ThreadPoolBoundHandle BindHandle(SafeHandle handle)
- {
- if (handle == null)
- throw new ArgumentNullException(nameof(handle));
-
- if (handle.IsClosed || handle.IsInvalid)
- throw new ArgumentException(SR.Argument_InvalidHandle, nameof(handle));
-
- throw new PlatformNotSupportedException(SR.NotSupported_Overlapped);
- }
-
- [CLSCompliant(false)]
- public unsafe NativeOverlapped* AllocateNativeOverlapped(IOCompletionCallback callback, object state, object pinData)
- {
- if (callback == null)
- throw new ArgumentNullException(nameof(callback));
-
- throw new PlatformNotSupportedException(SR.NotSupported_Overlapped);
- }
-
- [CLSCompliant(false)]
- public unsafe NativeOverlapped* AllocateNativeOverlapped(PreAllocatedOverlapped preAllocated)
- {
- if (preAllocated == null)
- throw new ArgumentNullException(nameof(preAllocated));
-
- throw new PlatformNotSupportedException(SR.NotSupported_Overlapped);
- }
-
- [CLSCompliant(false)]
- public unsafe void FreeNativeOverlapped(NativeOverlapped* overlapped)
- {
- if (overlapped == null)
- throw new ArgumentNullException(nameof(overlapped));
-
- throw new PlatformNotSupportedException(SR.NotSupported_Overlapped);
- }
-
- [CLSCompliant(false)]
- public static unsafe object GetNativeOverlappedState(NativeOverlapped* overlapped)
- {
- if (overlapped == null)
- throw new ArgumentNullException(nameof(overlapped));
-
- throw new PlatformNotSupportedException(SR.NotSupported_Overlapped);
- }
-
- public void Dispose()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPriority.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPriority.cs
deleted file mode 100644
index 3b34bd5eac8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadPriority.cs
+++ /dev/null
@@ -1,18 +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.
-
-namespace System.Threading
-{
- public enum ThreadPriority
- {
- /*=========================================================================
- ** Constants for thread priorities.
- =========================================================================*/
- Lowest = 0,
- BelowNormal = 1,
- Normal = 2,
- AboveNormal = 3,
- Highest = 4
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadStart.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadStart.cs
deleted file mode 100644
index 5532539fc77..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadStart.cs
+++ /dev/null
@@ -1,18 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: This class is a Delegate which defines the start method
-** for starting a thread. That method must match this delegate.
-**
-**
-=============================================================================*/
-
-namespace System.Threading
-{
- public delegate void ThreadStart();
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadStartException.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadStartException.cs
deleted file mode 100644
index 51725554183..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadStartException.cs
+++ /dev/null
@@ -1,30 +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 System.Runtime.Serialization;
-
-namespace System.Threading
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class ThreadStartException : SystemException
- {
- internal ThreadStartException()
- : base(SR.Arg_ThreadStartException)
- {
- HResult = HResults.COR_E_THREADSTART;
- }
-
- internal ThreadStartException(Exception reason)
- : base(SR.Arg_ThreadStartException, reason)
- {
- HResult = HResults.COR_E_THREADSTART;
- }
-
- private ThreadStartException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadState.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadState.cs
deleted file mode 100644
index 4bf3b5184d6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadState.cs
+++ /dev/null
@@ -1,24 +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.
-
-namespace System.Threading
-{
- [Flags]
- public enum ThreadState
- {
- /*=========================================================================
- ** Constants for thread states.
- =========================================================================*/
- Running = 0,
- StopRequested = 1,
- SuspendRequested = 2,
- Background = 4,
- Unstarted = 8,
- Stopped = 16,
- WaitSleepJoin = 32,
- Suspended = 64,
- AbortRequested = 128,
- Aborted = 256
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadStateException.cs b/netcore/System.Private.CoreLib/shared/System/Threading/ThreadStateException.cs
deleted file mode 100644
index 2c1a5c97a3f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/ThreadStateException.cs
+++ /dev/null
@@ -1,46 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: An exception class to indicate that the Thread class is in an
-** invalid state for the method.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System.Threading
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class ThreadStateException : SystemException
- {
- public ThreadStateException()
- : base(SR.Arg_ThreadStateException)
- {
- HResult = HResults.COR_E_THREADSTATE;
- }
-
- public ThreadStateException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_THREADSTATE;
- }
-
- public ThreadStateException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_THREADSTATE;
- }
-
- protected ThreadStateException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Timeout.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Timeout.cs
deleted file mode 100644
index 995ca4ef813..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Timeout.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Threading
-{
- // A constant used by methods that take a timeout (Object.Wait, Thread.Sleep
- // etc) to indicate that no timeout should occur.
- //
- public static class Timeout
- {
- public static readonly TimeSpan InfiniteTimeSpan = new TimeSpan(0, 0, 0, 0, Timeout.Infinite);
-
- public const int Infinite = -1;
- internal const uint UnsignedInfinite = unchecked((uint)-1);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/TimeoutHelper.cs b/netcore/System.Private.CoreLib/shared/System/Threading/TimeoutHelper.cs
deleted file mode 100644
index 80552a4ff6a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/TimeoutHelper.cs
+++ /dev/null
@@ -1,54 +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 System.Diagnostics;
-
-namespace System.Threading
-{
- /// <summary>
- /// A helper class to capture a start time using <see cref="Environment.TickCount"/> as a time in milliseconds.
- /// Also updates a given timeout by subtracting the current time from the start time.
- /// </summary>
- internal static class TimeoutHelper
- {
- /// <summary>
- /// Returns <see cref="Environment.TickCount"/> as a start time in milliseconds as a <see cref="uint"/>.
- /// <see cref="Environment.TickCount"/> rolls over from positive to negative every ~25 days, then ~25 days to back to positive again.
- /// <see cref="uint"/> is used to ignore the sign and double the range to 50 days.
- /// </summary>
- public static uint GetTime()
- {
- return (uint)Environment.TickCount;
- }
-
- /// <summary>
- /// Helper function to measure and update the elapsed time
- /// </summary>
- /// <param name="startTime"> The first time (in milliseconds) observed when the wait started</param>
- /// <param name="originalWaitMillisecondsTimeout">The original wait timeout in milliseconds</param>
- /// <returns>The new wait time in milliseconds, or -1 if the time expired</returns>
- public static int UpdateTimeOut(uint startTime, int originalWaitMillisecondsTimeout)
- {
- // The function must be called in case the time out is not infinite
- Debug.Assert(originalWaitMillisecondsTimeout != Timeout.Infinite);
-
- uint elapsedMilliseconds = (GetTime() - startTime);
-
- // Check the elapsed milliseconds is greater than max int because this property is uint
- if (elapsedMilliseconds > int.MaxValue)
- {
- return 0;
- }
-
- // Subtract the elapsed time from the current wait time
- int currentWaitTimeout = originalWaitMillisecondsTimeout - (int)elapsedMilliseconds;
- if (currentWaitTimeout <= 0)
- {
- return 0;
- }
-
- return currentWaitTimeout;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Timer.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Timer.cs
deleted file mode 100644
index d7c0537f559..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Timer.cs
+++ /dev/null
@@ -1,863 +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 System.Diagnostics;
-using System.Diagnostics.Tracing;
-using System.Runtime.ExceptionServices;
-using System.Threading.Tasks;
-
-namespace System.Threading
-{
- public delegate void TimerCallback(object? state);
-
- // TimerQueue maintains a list of active timers. We use a single native timer to schedule all managed timers
- // in the process.
- //
- // Perf assumptions: We assume that timers are created and destroyed frequently, but rarely actually fire.
- // There are roughly two types of timer:
- //
- // - timeouts for operations. These are created and destroyed very frequently, but almost never fire, because
- // the whole point is that the timer only fires if something has gone wrong.
- //
- // - scheduled background tasks. These typically do fire, but they usually have quite long durations.
- // So the impact of spending a few extra cycles to fire these is negligible.
- //
- // Because of this, we want to choose a data structure with very fast insert and delete times, and we can live
- // with linear traversal times when firing timers. However, we still want to minimize the number of timers
- // we need to traverse while doing the linear walk: in cases where we have lots of long-lived timers as well as
- // lots of short-lived timers, when the short-lived timers fire, they incur the cost of walking the long-lived ones.
- //
- // The data structure we've chosen is an unordered doubly-linked list of active timers. This gives O(1) insertion
- // and removal, and O(N) traversal when finding expired timers. We maintain two such lists: one for all of the
- // timers that'll next fire within a certain threshold, and one for the rest.
- //
- // Note that all instance methods of this class require that the caller hold a lock on the TimerQueue instance.
- // We partition the timers across multiple TimerQueues, each with its own lock and set of short/long lists,
- // in order to minimize contention when lots of threads are concurrently creating and destroying timers often.
- internal partial class TimerQueue
- {
- #region Shared TimerQueue instances
-
- public static TimerQueue[] Instances { get; } = CreateTimerQueues();
-
- private static TimerQueue[] CreateTimerQueues()
- {
- var queues = new TimerQueue[Environment.ProcessorCount];
- for (int i = 0; i < queues.Length; i++)
- {
- queues[i] = new TimerQueue(i);
- }
- return queues;
- }
-
- #endregion
-
- #region interface to native timer
-
- private bool _isTimerScheduled;
- private long _currentTimerStartTicks;
- private uint _currentTimerDuration;
-
- private bool EnsureTimerFiresBy(uint requestedDuration)
- {
- // The VM's timer implementation does not work well for very long-duration timers.
- // So we limit our native timer duration to a "small" value.
- // This may cause us to attempt to fire timers early, but that's ok -
- // we'll just see that none of our timers has actually reached its due time,
- // and schedule the native timer again.
- const uint maxPossibleDuration = 0x0fffffff;
- uint actualDuration = Math.Min(requestedDuration, maxPossibleDuration);
-
- if (_isTimerScheduled)
- {
- long elapsed = TickCount64 - _currentTimerStartTicks;
- if (elapsed >= _currentTimerDuration)
- return true; // the timer's about to fire
-
- uint remainingDuration = _currentTimerDuration - (uint)elapsed;
- if (actualDuration >= remainingDuration)
- return true; // the timer will fire earlier than this request
- }
-
- if (SetTimer(actualDuration))
- {
- _isTimerScheduled = true;
- _currentTimerStartTicks = TickCount64;
- _currentTimerDuration = actualDuration;
- return true;
- }
-
- return false;
- }
-
- #endregion
-
- #region Firing timers
-
- // The two lists of timers that are part of this TimerQueue. They conform to a single guarantee:
- // no timer in _longTimers has an absolute next firing time <= _currentAbsoluteThreshold.
- // That way, when FireNextTimers is invoked, we always process the short list, and we then only
- // process the long list if the current time is greater than _currentAbsoluteThreshold (or
- // if the short list is now empty and we need to process the long list to know when to next
- // invoke FireNextTimers).
- private TimerQueueTimer? _shortTimers;
- private TimerQueueTimer? _longTimers;
-
- // The current threshold, an absolute time where any timers scheduled to go off at or
- // before this time must be queued to the short list.
- private long _currentAbsoluteThreshold = TickCount64 + ShortTimersThresholdMilliseconds;
-
- // Default threshold that separates which timers target _shortTimers vs _longTimers. The threshold
- // is chosen to balance the number of timers in the small list against the frequency with which
- // we need to scan the long list. It's thus somewhat arbitrary and could be changed based on
- // observed workload demand. The larger the number, the more timers we'll likely need to enumerate
- // every time the timer fires, but also the more likely it is that when it does we won't
- // need to look at the long list because the current time will be <= _currentAbsoluteThreshold.
- private const int ShortTimersThresholdMilliseconds = 333;
-
- // Fire any timers that have expired, and update the native timer to schedule the rest of them.
- // We're in a thread pool work item here, and if there are multiple timers to be fired, we want
- // to queue all but the first one. The first may can then be invoked synchronously or queued,
- // a task left up to our caller, which might be firing timers from multiple queues.
- private void FireNextTimers()
- {
- // We fire the first timer on this thread; any other timers that need to be fired
- // are queued to the ThreadPool.
- TimerQueueTimer? timerToFireOnThisThread = null;
-
- lock (this)
- {
- // Since we got here, that means our previous timer has fired.
- _isTimerScheduled = false;
- bool haveTimerToSchedule = false;
- uint nextTimerDuration = uint.MaxValue;
-
- long nowTicks = TickCount64;
-
- // Sweep through the "short" timers. If the current tick count is greater than
- // the current threshold, also sweep through the "long" timers. Finally, as part
- // of sweeping the long timers, move anything that'll fire within the next threshold
- // to the short list. It's functionally ok if more timers end up in the short list
- // than is truly necessary (but not the opposite).
- TimerQueueTimer? timer = _shortTimers;
- for (int listNum = 0; listNum < 2; listNum++) // short == 0, long == 1
- {
- while (timer != null)
- {
- Debug.Assert(timer._dueTime != Timeout.UnsignedInfinite, "A timer in the list must have a valid due time.");
-
- // Save off the next timer to examine, in case our examination of this timer results
- // in our deleting or moving it; we'll continue after with this saved next timer.
- TimerQueueTimer? next = timer._next;
-
- long elapsed = nowTicks - timer._startTicks;
- long remaining = timer._dueTime - elapsed;
- if (remaining <= 0)
- {
- // Timer is ready to fire.
-
- if (timer._period != Timeout.UnsignedInfinite)
- {
- // This is a repeating timer; schedule it to run again.
-
- // Discount the extra amount of time that has elapsed since the previous firing time to
- // prevent timer ticks from drifting. If enough time has already elapsed for the timer to fire
- // again, meaning the timer can't keep up with the short period, have it fire 1 ms from now to
- // avoid spinning without a delay.
- timer._startTicks = nowTicks;
- long elapsedForNextDueTime = elapsed - timer._dueTime;
- timer._dueTime = (elapsedForNextDueTime < timer._period) ?
- timer._period - (uint)elapsedForNextDueTime :
- 1;
-
- // Update the timer if this becomes the next timer to fire.
- if (timer._dueTime < nextTimerDuration)
- {
- haveTimerToSchedule = true;
- nextTimerDuration = timer._dueTime;
- }
-
- // Validate that the repeating timer is still on the right list. It's likely that
- // it started in the long list and was moved to the short list at some point, so
- // we now want to move it back to the long list if that's where it belongs. Note that
- // if we're currently processing the short list and move it to the long list, we may
- // end up revisiting it again if we also enumerate the long list, but we will have already
- // updated the due time appropriately so that we won't fire it again (it's also possible
- // but rare that we could be moving a timer from the long list to the short list here,
- // if the initial due time was set to be long but the timer then had a short period).
- bool targetShortList = (nowTicks + timer._dueTime) - _currentAbsoluteThreshold <= 0;
- if (timer._short != targetShortList)
- {
- MoveTimerToCorrectList(timer, targetShortList);
- }
- }
- else
- {
- // Not repeating; remove it from the queue
- DeleteTimer(timer);
- }
-
- // If this is the first timer, we'll fire it on this thread (after processing
- // all others). Otherwise, queue it to the ThreadPool.
- if (timerToFireOnThisThread == null)
- {
- timerToFireOnThisThread = timer;
- }
- else
- {
- ThreadPool.UnsafeQueueUserWorkItemInternal(timer, preferLocal: false);
- }
- }
- else
- {
- // This timer isn't ready to fire. Update the next time the native timer fires if necessary,
- // and move this timer to the short list if its remaining time is now at or under the threshold.
-
- if (remaining < nextTimerDuration)
- {
- haveTimerToSchedule = true;
- nextTimerDuration = (uint)remaining;
- }
-
- if (!timer._short && remaining <= ShortTimersThresholdMilliseconds)
- {
- MoveTimerToCorrectList(timer, shortList: true);
- }
- }
-
- timer = next;
- }
-
- // Switch to process the long list if necessary.
- if (listNum == 0)
- {
- // Determine how much time remains between now and the current threshold. If time remains,
- // we can skip processing the long list. We use > rather than >= because, although we
- // know that if remaining == 0 no timers in the long list will need to be fired, we
- // don't know without looking at them when we'll need to call FireNextTimers again. We
- // could in that case just set the next firing to 1, but we may as well just iterate the
- // long list now; otherwise, most timers created in the interim would end up in the long
- // list and we'd likely end up paying for another invocation of FireNextTimers that could
- // have been delayed longer (to whatever is the current minimum in the long list).
- long remaining = _currentAbsoluteThreshold - nowTicks;
- if (remaining > 0)
- {
- if (_shortTimers == null && _longTimers != null)
- {
- // We don't have any short timers left and we haven't examined the long list,
- // which means we likely don't have an accurate nextTimerDuration.
- // But we do know that nothing in the long list will be firing before or at _currentAbsoluteThreshold,
- // so we can just set nextTimerDuration to the difference between then and now.
- nextTimerDuration = (uint)remaining + 1;
- haveTimerToSchedule = true;
- }
- break;
- }
-
- // Switch to processing the long list.
- timer = _longTimers;
-
- // Now that we're going to process the long list, update the current threshold.
- _currentAbsoluteThreshold = nowTicks + ShortTimersThresholdMilliseconds;
- }
- }
-
- // If we still have scheduled timers, update the timer to ensure it fires
- // in time for the next one in line.
- if (haveTimerToSchedule)
- {
- EnsureTimerFiresBy(nextTimerDuration);
- }
- }
-
- // Fire the user timer outside of the lock!
- timerToFireOnThisThread?.Fire();
- }
-
- #endregion
-
- #region Queue implementation
-
- public long ActiveCount { get; private set; }
-
- public bool UpdateTimer(TimerQueueTimer timer, uint dueTime, uint period)
- {
- long nowTicks = TickCount64;
-
- // The timer can be put onto the short list if it's next absolute firing time
- // is <= the current absolute threshold.
- long absoluteDueTime = nowTicks + dueTime;
- bool shouldBeShort = _currentAbsoluteThreshold - absoluteDueTime >= 0;
-
- if (timer._dueTime == Timeout.UnsignedInfinite)
- {
- // If the timer wasn't previously scheduled, now add it to the right list.
- timer._short = shouldBeShort;
- LinkTimer(timer);
- ++ActiveCount;
- }
- else if (timer._short != shouldBeShort)
- {
- // If the timer was previously scheduled, but this update should cause
- // it to move over the list threshold in either direction, do so.
- UnlinkTimer(timer);
- timer._short = shouldBeShort;
- LinkTimer(timer);
- }
-
- timer._dueTime = dueTime;
- timer._period = (period == 0) ? Timeout.UnsignedInfinite : period;
- timer._startTicks = nowTicks;
- return EnsureTimerFiresBy(dueTime);
- }
-
- public void MoveTimerToCorrectList(TimerQueueTimer timer, bool shortList)
- {
- Debug.Assert(timer._dueTime != Timeout.UnsignedInfinite, "Expected timer to be on a list.");
- Debug.Assert(timer._short != shortList, "Unnecessary if timer is already on the right list.");
-
- // Unlink it from whatever list it's on, change its list association, then re-link it.
- UnlinkTimer(timer);
- timer._short = shortList;
- LinkTimer(timer);
- }
-
- private void LinkTimer(TimerQueueTimer timer)
- {
- // Use timer._short to decide to which list to add.
- ref TimerQueueTimer? listHead = ref timer._short ? ref _shortTimers : ref _longTimers;
- timer._next = listHead;
- if (timer._next != null)
- {
- timer._next._prev = timer;
- }
- timer._prev = null;
- listHead = timer;
- }
-
- private void UnlinkTimer(TimerQueueTimer timer)
- {
- TimerQueueTimer? t = timer._next;
- if (t != null)
- {
- t._prev = timer._prev;
- }
-
- if (_shortTimers == timer)
- {
- Debug.Assert(timer._short);
- _shortTimers = t;
- }
- else if (_longTimers == timer)
- {
- Debug.Assert(!timer._short);
- _longTimers = t;
- }
-
- t = timer._prev;
- if (t != null)
- {
- t._next = timer._next;
- }
-
- // At this point the timer is no longer in a list, but its next and prev
- // references may still point to other nodes. UnlinkTimer should thus be
- // followed by something that overwrites those references, either with null
- // if deleting the timer or other nodes if adding it to another list.
- }
-
- public void DeleteTimer(TimerQueueTimer timer)
- {
- if (timer._dueTime != Timeout.UnsignedInfinite)
- {
- --ActiveCount;
- Debug.Assert(ActiveCount >= 0);
- UnlinkTimer(timer);
- timer._prev = null;
- timer._next = null;
- timer._dueTime = Timeout.UnsignedInfinite;
- timer._period = Timeout.UnsignedInfinite;
- timer._startTicks = 0;
- timer._short = false;
- }
- }
-
- #endregion
- }
-
- // A timer in our TimerQueue.
- internal sealed partial class TimerQueueTimer : IThreadPoolWorkItem
- {
- // The associated timer queue.
- private readonly TimerQueue _associatedTimerQueue;
-
- // All mutable fields of this class are protected by a lock on _associatedTimerQueue.
- // The first six fields are maintained by TimerQueue.
-
- // Links to the next and prev timers in the list.
- internal TimerQueueTimer? _next;
- internal TimerQueueTimer? _prev;
-
- // true if on the short list; otherwise, false.
- internal bool _short;
-
- // The time, according to TimerQueue.TickCount, when this timer's current interval started.
- internal long _startTicks;
-
- // Timeout.UnsignedInfinite if we are not going to fire. Otherwise, the offset from _startTime when we will fire.
- internal uint _dueTime;
-
- // Timeout.UnsignedInfinite if we are a single-shot timer. Otherwise, the repeat interval.
- internal uint _period;
-
- // Info about the user's callback
- private readonly TimerCallback _timerCallback;
- private readonly object? _state;
- private readonly ExecutionContext? _executionContext;
-
- // When Timer.Dispose(WaitHandle) is used, we need to signal the wait handle only
- // after all pending callbacks are complete. We set _canceled to prevent any callbacks that
- // are already queued from running. We track the number of callbacks currently executing in
- // _callbacksRunning. We set _notifyWhenNoCallbacksRunning only when _callbacksRunning
- // reaches zero. Same applies if Timer.DisposeAsync() is used, except with a Task<bool>
- // instead of with a provided WaitHandle.
- private int _callbacksRunning;
- private volatile bool _canceled;
- private volatile object? _notifyWhenNoCallbacksRunning; // may be either WaitHandle or Task<bool>
-
-
- internal TimerQueueTimer(TimerCallback timerCallback, object? state, uint dueTime, uint period, bool flowExecutionContext)
- {
- _timerCallback = timerCallback;
- _state = state;
- _dueTime = Timeout.UnsignedInfinite;
- _period = Timeout.UnsignedInfinite;
- if (flowExecutionContext)
- {
- _executionContext = ExecutionContext.Capture();
- }
- _associatedTimerQueue = TimerQueue.Instances[Thread.GetCurrentProcessorId() % TimerQueue.Instances.Length];
-
- // After the following statement, the timer may fire. No more manipulation of timer state outside of
- // the lock is permitted beyond this point!
- if (dueTime != Timeout.UnsignedInfinite)
- Change(dueTime, period);
- }
-
- internal bool Change(uint dueTime, uint period)
- {
- bool success;
-
- lock (_associatedTimerQueue)
- {
- if (_canceled)
- throw new ObjectDisposedException(null, SR.ObjectDisposed_Generic);
-
- _period = period;
-
- if (dueTime == Timeout.UnsignedInfinite)
- {
- _associatedTimerQueue.DeleteTimer(this);
- success = true;
- }
- else
- {
- if (FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.ThreadTransfer))
- FrameworkEventSource.Log.ThreadTransferSendObj(this, 1, string.Empty, true, (int)dueTime, (int)period);
- success = _associatedTimerQueue.UpdateTimer(this, dueTime, period);
- }
- }
-
- return success;
- }
-
-
- public void Close()
- {
- lock (_associatedTimerQueue)
- {
- if (!_canceled)
- {
- _canceled = true;
- _associatedTimerQueue.DeleteTimer(this);
- }
- }
- }
-
-
- public bool Close(WaitHandle toSignal)
- {
- bool success;
- bool shouldSignal = false;
-
- lock (_associatedTimerQueue)
- {
- if (_canceled)
- {
- success = false;
- }
- else
- {
- _canceled = true;
- _notifyWhenNoCallbacksRunning = toSignal;
- _associatedTimerQueue.DeleteTimer(this);
- shouldSignal = _callbacksRunning == 0;
- success = true;
- }
- }
-
- if (shouldSignal)
- SignalNoCallbacksRunning();
-
- return success;
- }
-
- public ValueTask CloseAsync()
- {
- lock (_associatedTimerQueue)
- {
- object? notifyWhenNoCallbacksRunning = _notifyWhenNoCallbacksRunning;
-
- // Mark the timer as canceled if it's not already.
- if (_canceled)
- {
- if (notifyWhenNoCallbacksRunning is WaitHandle)
- {
- // A previous call to Close(WaitHandle) stored a WaitHandle. We could try to deal with
- // this case by using ThreadPool.RegisterWaitForSingleObject to create a Task that'll
- // complete when the WaitHandle is set, but since arbitrary WaitHandle's can be supplied
- // by the caller, it could be for an auto-reset event or similar where that caller's
- // WaitOne on the WaitHandle could prevent this wrapper Task from completing. We could also
- // change the implementation to support storing multiple objects, but that's not pay-for-play,
- // and the existing Close(WaitHandle) already discounts this as being invalid, instead just
- // returning false if you use it multiple times. Since first calling Timer.Dispose(WaitHandle)
- // and then calling Timer.DisposeAsync is not something anyone is likely to or should do, we
- // simplify by just failing in that case.
- var e = new InvalidOperationException(SR.InvalidOperation_TimerAlreadyClosed);
- e.SetCurrentStackTrace();
- return new ValueTask(Task.FromException(e));
- }
- }
- else
- {
- _canceled = true;
- _associatedTimerQueue.DeleteTimer(this);
- }
-
- // We've deleted the timer, so if there are no callbacks queued or running,
- // we're done and return an already-completed value task.
- if (_callbacksRunning == 0)
- {
- return default;
- }
-
- Debug.Assert(
- notifyWhenNoCallbacksRunning == null ||
- notifyWhenNoCallbacksRunning is Task<bool>);
-
- // There are callbacks queued or running, so we need to store a Task<bool>
- // that'll be used to signal the caller when all callbacks complete. Do so as long as
- // there wasn't a previous CloseAsync call that did.
- if (notifyWhenNoCallbacksRunning == null)
- {
- var t = new Task<bool>((object?)null, TaskCreationOptions.RunContinuationsAsynchronously);
- _notifyWhenNoCallbacksRunning = t;
- return new ValueTask(t);
- }
-
- // A previous CloseAsync call already hooked up a task. Just return it.
- return new ValueTask((Task<bool>)notifyWhenNoCallbacksRunning);
- }
- }
-
- void IThreadPoolWorkItem.Execute() => Fire(isThreadPool: true);
-
- internal void Fire(bool isThreadPool = false)
- {
- bool canceled = false;
-
- lock (_associatedTimerQueue)
- {
- canceled = _canceled;
- if (!canceled)
- _callbacksRunning++;
- }
-
- if (canceled)
- return;
-
- CallCallback(isThreadPool);
-
- bool shouldSignal = false;
- lock (_associatedTimerQueue)
- {
- _callbacksRunning--;
- if (_canceled && _callbacksRunning == 0 && _notifyWhenNoCallbacksRunning != null)
- shouldSignal = true;
- }
-
- if (shouldSignal)
- SignalNoCallbacksRunning();
- }
-
- internal void SignalNoCallbacksRunning()
- {
- object? toSignal = _notifyWhenNoCallbacksRunning;
- Debug.Assert(toSignal is WaitHandle || toSignal is Task<bool>);
-
- if (toSignal is WaitHandle wh)
- {
- EventWaitHandle.Set(wh.SafeWaitHandle);
- }
- else
- {
- ((Task<bool>)toSignal).TrySetResult(true);
- }
- }
-
- internal void CallCallback(bool isThreadPool)
- {
- if (FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.ThreadTransfer))
- FrameworkEventSource.Log.ThreadTransferReceiveObj(this, 1, string.Empty);
-
- // Call directly if EC flow is suppressed
- ExecutionContext? context = _executionContext;
- if (context == null)
- {
- _timerCallback(_state);
- }
- else
- {
- if (isThreadPool)
- {
- ExecutionContext.RunFromThreadPoolDispatchLoop(Thread.CurrentThread, context, s_callCallbackInContext, this);
- }
- else
- {
- ExecutionContext.RunInternal(context, s_callCallbackInContext, this);
- }
- }
- }
-
- private static readonly ContextCallback s_callCallbackInContext = state =>
- {
- Debug.Assert(state is TimerQueueTimer);
- var t = (TimerQueueTimer)state;
- t._timerCallback(t._state);
- };
- }
-
- // TimerHolder serves as an intermediary between Timer and TimerQueueTimer, releasing the TimerQueueTimer
- // if the Timer is collected.
- // This is necessary because Timer itself cannot use its finalizer for this purpose. If it did,
- // then users could control timer lifetimes using GC.SuppressFinalize/ReRegisterForFinalize.
- // You might ask, wouldn't that be a good thing? Maybe (though it would be even better to offer this
- // via first-class APIs), but Timer has never offered this, and adding it now would be a breaking
- // change, because any code that happened to be suppressing finalization of Timer objects would now
- // unwittingly be changing the lifetime of those timers.
- internal sealed class TimerHolder
- {
- internal readonly TimerQueueTimer _timer;
-
- public TimerHolder(TimerQueueTimer timer)
- {
- _timer = timer;
- }
-
- ~TimerHolder()
- {
- _timer.Close();
- }
-
- public void Close()
- {
- _timer.Close();
- GC.SuppressFinalize(this);
- }
-
- public bool Close(WaitHandle notifyObject)
- {
- bool result = _timer.Close(notifyObject);
- GC.SuppressFinalize(this);
- return result;
- }
-
- public ValueTask CloseAsync()
- {
- ValueTask result = _timer.CloseAsync();
- GC.SuppressFinalize(this);
- return result;
- }
- }
-
-
- public sealed class Timer : MarshalByRefObject, IDisposable, IAsyncDisposable
- {
- private const uint MAX_SUPPORTED_TIMEOUT = (uint)0xfffffffe;
-
- private TimerHolder _timer = null!; // initialized in helper called by ctors
-
- public Timer(TimerCallback callback,
- object? state,
- int dueTime,
- int period) :
- this(callback, state, dueTime, period, flowExecutionContext: true)
- {
- }
-
- internal Timer(TimerCallback callback,
- object? state,
- int dueTime,
- int period,
- bool flowExecutionContext)
- {
- if (dueTime < -1)
- throw new ArgumentOutOfRangeException(nameof(dueTime), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (period < -1)
- throw new ArgumentOutOfRangeException(nameof(period), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
-
- TimerSetup(callback, state, (uint)dueTime, (uint)period, flowExecutionContext);
- }
-
- public Timer(TimerCallback callback,
- object? state,
- TimeSpan dueTime,
- TimeSpan period)
- {
- long dueTm = (long)dueTime.TotalMilliseconds;
- if (dueTm < -1)
- throw new ArgumentOutOfRangeException(nameof(dueTime), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (dueTm > MAX_SUPPORTED_TIMEOUT)
- throw new ArgumentOutOfRangeException(nameof(dueTime), SR.ArgumentOutOfRange_TimeoutTooLarge);
-
- long periodTm = (long)period.TotalMilliseconds;
- if (periodTm < -1)
- throw new ArgumentOutOfRangeException(nameof(period), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (periodTm > MAX_SUPPORTED_TIMEOUT)
- throw new ArgumentOutOfRangeException(nameof(period), SR.ArgumentOutOfRange_PeriodTooLarge);
-
- TimerSetup(callback, state, (uint)dueTm, (uint)periodTm);
- }
-
- [CLSCompliant(false)]
- public Timer(TimerCallback callback,
- object? state,
- uint dueTime,
- uint period)
- {
- TimerSetup(callback, state, dueTime, period);
- }
-
- public Timer(TimerCallback callback,
- object? state,
- long dueTime,
- long period)
- {
- if (dueTime < -1)
- throw new ArgumentOutOfRangeException(nameof(dueTime), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (period < -1)
- throw new ArgumentOutOfRangeException(nameof(period), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (dueTime > MAX_SUPPORTED_TIMEOUT)
- throw new ArgumentOutOfRangeException(nameof(dueTime), SR.ArgumentOutOfRange_TimeoutTooLarge);
- if (period > MAX_SUPPORTED_TIMEOUT)
- throw new ArgumentOutOfRangeException(nameof(period), SR.ArgumentOutOfRange_PeriodTooLarge);
- TimerSetup(callback, state, (uint)dueTime, (uint)period);
- }
-
- public Timer(TimerCallback callback)
- {
- const uint DueTime = unchecked((uint)(-1)); // We want timer to be registered, but not activated. Requires caller to call
- const uint Period = unchecked((uint)(-1)); // Change after a timer instance is created. This is to avoid the potential
- // for a timer to be fired before the returned value is assigned to the variable,
- // potentially causing the callback to reference a bogus value (if passing the timer to the callback).
-
- TimerSetup(callback, this, DueTime, Period);
- }
-
- private void TimerSetup(TimerCallback callback,
- object? state,
- uint dueTime,
- uint period,
- bool flowExecutionContext = true)
- {
- if (callback == null)
- throw new ArgumentNullException(nameof(callback));
-
- _timer = new TimerHolder(new TimerQueueTimer(callback, state, dueTime, period, flowExecutionContext));
- }
-
- public bool Change(int dueTime, int period)
- {
- if (dueTime < -1)
- throw new ArgumentOutOfRangeException(nameof(dueTime), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (period < -1)
- throw new ArgumentOutOfRangeException(nameof(period), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
-
- return _timer._timer.Change((uint)dueTime, (uint)period);
- }
-
- public bool Change(TimeSpan dueTime, TimeSpan period)
- {
- return Change((long)dueTime.TotalMilliseconds, (long)period.TotalMilliseconds);
- }
-
- [CLSCompliant(false)]
- public bool Change(uint dueTime, uint period)
- {
- return _timer._timer.Change(dueTime, period);
- }
-
- public bool Change(long dueTime, long period)
- {
- if (dueTime < -1)
- throw new ArgumentOutOfRangeException(nameof(dueTime), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (period < -1)
- throw new ArgumentOutOfRangeException(nameof(period), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- if (dueTime > MAX_SUPPORTED_TIMEOUT)
- throw new ArgumentOutOfRangeException(nameof(dueTime), SR.ArgumentOutOfRange_TimeoutTooLarge);
- if (period > MAX_SUPPORTED_TIMEOUT)
- throw new ArgumentOutOfRangeException(nameof(period), SR.ArgumentOutOfRange_PeriodTooLarge);
-
- return _timer._timer.Change((uint)dueTime, (uint)period);
- }
-
- /// <summary>
- /// Gets the number of timers that are currently active. An active timer is registered to tick at some point in the
- /// future, and has not yet been canceled.
- /// </summary>
- public static long ActiveCount
- {
- get
- {
- long count = 0;
- foreach (TimerQueue queue in TimerQueue.Instances)
- {
- lock (queue)
- {
- count += queue.ActiveCount;
- }
- }
- return count;
- }
- }
-
- public bool Dispose(WaitHandle notifyObject)
- {
- if (notifyObject == null)
- throw new ArgumentNullException(nameof(notifyObject));
-
- return _timer.Close(notifyObject);
- }
-
- public void Dispose()
- {
- _timer.Close();
- }
-
- public ValueTask DisposeAsync()
- {
- return _timer.CloseAsync();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Portable.cs b/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Portable.cs
deleted file mode 100644
index 2e47b71aa01..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Portable.cs
+++ /dev/null
@@ -1,139 +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 System.Collections.Generic;
-using System.Diagnostics;
-
-namespace System.Threading
-{
- //
- // Unix-specific implementation of Timer
- //
- internal partial class TimerQueue : IThreadPoolWorkItem
- {
- private static List<TimerQueue>? s_scheduledTimers;
- private static List<TimerQueue>? s_scheduledTimersToFire;
-
- /// <summary>
- /// This event is used by the timer thread to wait for timer expiration. It is also
- /// used to notify the timer thread that a new timer has been set.
- /// </summary>
- private static readonly AutoResetEvent s_timerEvent = new AutoResetEvent(false);
-
- private bool _isScheduled;
- private long _scheduledDueTimeMs;
-
- private TimerQueue(int id)
- {
- }
-
- private static List<TimerQueue> InitializeScheduledTimerManager_Locked()
- {
- Debug.Assert(s_scheduledTimers == null);
-
- var timers = new List<TimerQueue>(Instances.Length);
- s_scheduledTimersToFire ??= new List<TimerQueue>(Instances.Length);
-
- Thread timerThread = new Thread(TimerThread);
- timerThread.IsBackground = true;
- timerThread.Start();
-
- // Do this after creating the thread in case thread creation fails so that it will try again next time
- s_scheduledTimers = timers;
- return timers;
- }
-
- private bool SetTimer(uint actualDuration)
- {
- Debug.Assert((int)actualDuration >= 0);
- long dueTimeMs = TickCount64 + (int)actualDuration;
- AutoResetEvent timerEvent = s_timerEvent;
- lock (timerEvent)
- {
- if (!_isScheduled)
- {
- List<TimerQueue>? timers = s_scheduledTimers;
- if (timers == null)
- {
- timers = InitializeScheduledTimerManager_Locked();
- }
-
- timers.Add(this);
- _isScheduled = true;
- }
-
- _scheduledDueTimeMs = dueTimeMs;
- }
-
- timerEvent.Set();
- return true;
- }
-
- /// <summary>
- /// This method is executed on a dedicated a timer thread. Its purpose is
- /// to handle timer requests and notify the TimerQueue when a timer expires.
- /// </summary>
- private static void TimerThread()
- {
- AutoResetEvent timerEvent = s_timerEvent;
- List<TimerQueue> timersToFire = s_scheduledTimersToFire!;
- List<TimerQueue> timers;
- lock (timerEvent)
- {
- timers = s_scheduledTimers!;
- }
-
- int shortestWaitDurationMs = Timeout.Infinite;
- while (true)
- {
- timerEvent.WaitOne(shortestWaitDurationMs);
-
- long currentTimeMs = TickCount64;
- shortestWaitDurationMs = int.MaxValue;
- lock (timerEvent)
- {
- for (int i = timers.Count - 1; i >= 0; --i)
- {
- TimerQueue timer = timers[i];
- long waitDurationMs = timer._scheduledDueTimeMs - currentTimeMs;
- if (waitDurationMs <= 0)
- {
- timer._isScheduled = false;
- timersToFire.Add(timer);
-
- int lastIndex = timers.Count - 1;
- if (i != lastIndex)
- {
- timers[i] = timers[lastIndex];
- }
- timers.RemoveAt(lastIndex);
- continue;
- }
-
- if (waitDurationMs < shortestWaitDurationMs)
- {
- shortestWaitDurationMs = (int)waitDurationMs;
- }
- }
- }
-
- if (timersToFire.Count > 0)
- {
- foreach (TimerQueue timerToFire in timersToFire)
- {
- ThreadPool.UnsafeQueueUserWorkItemInternal(timerToFire, preferLocal: false);
- }
- timersToFire.Clear();
- }
-
- if (shortestWaitDurationMs == int.MaxValue)
- {
- shortestWaitDurationMs = Timeout.Infinite;
- }
- }
- }
-
- void IThreadPoolWorkItem.Execute() => FireNextTimers();
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Unix.cs b/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Unix.cs
deleted file mode 100644
index 043b590af0e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Unix.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Threading
-{
- internal partial class TimerQueue
- {
- private static long TickCount64 => Environment.TickCount64;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Windows.cs
deleted file mode 100644
index 9957abd730e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/TimerQueue.Windows.cs
+++ /dev/null
@@ -1,38 +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 System.Diagnostics;
-
-namespace System.Threading
-{
- internal partial class TimerQueue
- {
- private static long TickCount64
- {
- get
- {
- // We need to keep our notion of time synchronized with the calls to SleepEx that drive
- // the underlying native timer. In Win8, SleepEx does not count the time the machine spends
- // sleeping/hibernating. Environment.TickCount (GetTickCount) *does* count that time,
- // so we will get out of sync with SleepEx if we use that method.
- //
- // So, on Win8, we use QueryUnbiasedInterruptTime instead; this does not count time spent
- // in sleep/hibernate mode.
- if (Environment.IsWindows8OrAbove)
- {
- // Based on its documentation the QueryUnbiasedInterruptTime() function validates
- // the argument is non-null. In this case we are always supplying an argument,
- // so will skip return value validation.
- bool success = Interop.Kernel32.QueryUnbiasedInterruptTime(out ulong time100ns);
- Debug.Assert(success);
- return (long)(time100ns / 10_000); // convert from 100ns to milliseconds
- }
- else
- {
- return Environment.TickCount64;
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Volatile.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Volatile.cs
deleted file mode 100644
index 23046bbe25e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/Volatile.cs
+++ /dev/null
@@ -1,232 +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 System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.Versioning;
-using Internal.Runtime.CompilerServices;
-
-namespace System.Threading
-{
- /// <summary>Methods for accessing memory with volatile semantics.</summary>
- public static unsafe class Volatile
- {
- // The VM may replace these implementations with more efficient ones in some cases.
- // In coreclr, for example, see getILIntrinsicImplementationForVolatile() in jitinterface.cpp.
-
- #region Boolean
- private struct VolatileBoolean { public volatile bool Value; }
-
- [Intrinsic]
- [NonVersionable]
- public static bool Read(ref bool location) =>
- Unsafe.As<bool, VolatileBoolean>(ref location).Value;
-
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref bool location, bool value) =>
- Unsafe.As<bool, VolatileBoolean>(ref location).Value = value;
- #endregion
-
- #region Byte
- private struct VolatileByte { public volatile byte Value; }
-
- [Intrinsic]
- [NonVersionable]
- public static byte Read(ref byte location) =>
- Unsafe.As<byte, VolatileByte>(ref location).Value;
-
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref byte location, byte value) =>
- Unsafe.As<byte, VolatileByte>(ref location).Value = value;
- #endregion
-
- #region Double
- [Intrinsic]
- [NonVersionable]
- public static double Read(ref double location)
- {
- long result = Read(ref Unsafe.As<double, long>(ref location));
- return *(double*)&result;
- }
-
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref double location, double value) =>
- Write(ref Unsafe.As<double, long>(ref location), *(long*)&value);
- #endregion
-
- #region Int16
- private struct VolatileInt16 { public volatile short Value; }
-
- [Intrinsic]
- [NonVersionable]
- public static short Read(ref short location) =>
- Unsafe.As<short, VolatileInt16>(ref location).Value;
-
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref short location, short value) =>
- Unsafe.As<short, VolatileInt16>(ref location).Value = value;
- #endregion
-
- #region Int32
- private struct VolatileInt32 { public volatile int Value; }
-
- [Intrinsic]
- [NonVersionable]
- public static int Read(ref int location) =>
- Unsafe.As<int, VolatileInt32>(ref location).Value;
-
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref int location, int value) =>
- Unsafe.As<int, VolatileInt32>(ref location).Value = value;
- #endregion
-
- #region Int64
- [Intrinsic]
- [NonVersionable]
- public static long Read(ref long location) =>
-#if BIT64
- (long)Unsafe.As<long, VolatileIntPtr>(ref location).Value;
-#else
- // On 32-bit machines, we use Interlocked, since an ordinary volatile read would not be atomic.
- Interlocked.CompareExchange(ref location, 0, 0);
-#endif
-
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref long location, long value) =>
-#if BIT64
- Unsafe.As<long, VolatileIntPtr>(ref location).Value = (IntPtr)value;
-#else
- // On 32-bit, we use Interlocked, since an ordinary volatile write would not be atomic.
- Interlocked.Exchange(ref location, value);
-#endif
- #endregion
-
- #region IntPtr
- private struct VolatileIntPtr { public volatile IntPtr Value; }
-
- [Intrinsic]
- [NonVersionable]
- public static IntPtr Read(ref IntPtr location) =>
- Unsafe.As<IntPtr, VolatileIntPtr>(ref location).Value;
-
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref IntPtr location, IntPtr value) =>
- Unsafe.As<IntPtr, VolatileIntPtr>(ref location).Value = value;
- #endregion
-
- #region SByte
- private struct VolatileSByte { public volatile sbyte Value; }
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static sbyte Read(ref sbyte location) =>
- Unsafe.As<sbyte, VolatileSByte>(ref location).Value;
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref sbyte location, sbyte value) =>
- Unsafe.As<sbyte, VolatileSByte>(ref location).Value = value;
- #endregion
-
- #region Single
- private struct VolatileSingle { public volatile float Value; }
-
- [Intrinsic]
- [NonVersionable]
- public static float Read(ref float location) =>
- Unsafe.As<float, VolatileSingle>(ref location).Value;
-
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref float location, float value) =>
- Unsafe.As<float, VolatileSingle>(ref location).Value = value;
- #endregion
-
- #region UInt16
- private struct VolatileUInt16 { public volatile ushort Value; }
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static ushort Read(ref ushort location) =>
- Unsafe.As<ushort, VolatileUInt16>(ref location).Value;
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref ushort location, ushort value) =>
- Unsafe.As<ushort, VolatileUInt16>(ref location).Value = value;
- #endregion
-
- #region UInt32
- private struct VolatileUInt32 { public volatile uint Value; }
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static uint Read(ref uint location) =>
- Unsafe.As<uint, VolatileUInt32>(ref location).Value;
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref uint location, uint value) =>
- Unsafe.As<uint, VolatileUInt32>(ref location).Value = value;
- #endregion
-
- #region UInt64
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static ulong Read(ref ulong location) =>
- (ulong)Read(ref Unsafe.As<ulong, long>(ref location));
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref ulong location, ulong value) =>
- Write(ref Unsafe.As<ulong, long>(ref location), (long)value);
- #endregion
-
- #region UIntPtr
- private struct VolatileUIntPtr { public volatile UIntPtr Value; }
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static UIntPtr Read(ref UIntPtr location) =>
- Unsafe.As<UIntPtr, VolatileUIntPtr>(ref location).Value;
-
- [CLSCompliant(false)]
- [Intrinsic]
- [NonVersionable]
- public static void Write(ref UIntPtr location, UIntPtr value) =>
- Unsafe.As<UIntPtr, VolatileUIntPtr>(ref location).Value = value;
- #endregion
-
- #region T
- private struct VolatileObject { public volatile object? Value; }
-
- [Intrinsic]
- [NonVersionable]
- [return: NotNullIfNotNull("location")]
- public static T Read<T>(ref T location) where T : class? =>
- Unsafe.As<T>(Unsafe.As<T, VolatileObject>(ref location).Value);
-
- [Intrinsic]
- [NonVersionable]
- public static void Write<T>([NotNullIfNotNull("value")] ref T location, T value) where T : class? =>
- Unsafe.As<T, VolatileObject>(ref location).Value = value;
- #endregion
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/WaitHandle.cs b/netcore/System.Private.CoreLib/shared/System/Threading/WaitHandle.cs
deleted file mode 100644
index 399f78ef3b2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/WaitHandle.cs
+++ /dev/null
@@ -1,425 +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 System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using Microsoft.Win32.SafeHandles;
-
-namespace System.Threading
-{
- public abstract partial class WaitHandle : MarshalByRefObject, IDisposable
- {
- internal const int MaxWaitHandles = 64;
-
- protected static readonly IntPtr InvalidHandle = new IntPtr(-1);
-
- // IMPORTANT:
- // - Do not add or rearrange fields as the EE depends on this layout.
-
- private SafeWaitHandle? _waitHandle;
-
- [ThreadStatic]
- private static SafeWaitHandle?[]? t_safeWaitHandlesForRent;
-
- private protected enum OpenExistingResult
- {
- Success,
- NameNotFound,
- PathNotFound,
- NameInvalid
- }
-
- // The wait result values below match Win32 wait result codes (WAIT_OBJECT_0,
- // WAIT_ABANDONED, WAIT_TIMEOUT).
-
- // Successful wait on first object. When waiting for multiple objects the
- // return value is (WaitSuccess + waitIndex).
- internal const int WaitSuccess = 0;
-
- // The specified object is a mutex object that was not released by the
- // thread that owned the mutex object before the owning thread terminated.
- // When waiting for multiple objects the return value is (WaitAbandoned +
- // waitIndex).
- internal const int WaitAbandoned = 0x80;
-
- public const int WaitTimeout = 0x102;
-
- protected WaitHandle()
- {
- }
-
- [Obsolete("Use the SafeWaitHandle property instead.")]
- public virtual IntPtr Handle
- {
- get => _waitHandle == null ? InvalidHandle : _waitHandle.DangerousGetHandle();
- set
- {
- if (value == InvalidHandle)
- {
- // This line leaks a handle. However, it's currently
- // not perfectly clear what the right behavior is here
- // anyways. This preserves Everett behavior. We should
- // ideally do these things:
- // *) Expose a settable SafeHandle property on WaitHandle.
- // *) Expose a settable OwnsHandle property on SafeHandle.
- if (_waitHandle != null)
- {
- _waitHandle.SetHandleAsInvalid();
- _waitHandle = null;
- }
- }
- else
- {
- _waitHandle = new SafeWaitHandle(value, true);
- }
- }
- }
-
- [AllowNull]
- public SafeWaitHandle SafeWaitHandle
- {
- get => _waitHandle ??= new SafeWaitHandle(InvalidHandle, false);
- set => _waitHandle = value;
- }
-
- internal static int ToTimeoutMilliseconds(TimeSpan timeout)
- {
- long timeoutMilliseconds = (long)timeout.TotalMilliseconds;
- if (timeoutMilliseconds < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(timeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- }
- if (timeoutMilliseconds > int.MaxValue)
- {
- throw new ArgumentOutOfRangeException(nameof(timeout), SR.ArgumentOutOfRange_LessEqualToIntegerMaxVal);
- }
- return (int)timeoutMilliseconds;
- }
-
- public virtual void Close() => Dispose();
-
- protected virtual void Dispose(bool explicitDisposing)
- {
- _waitHandle?.Close();
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- public virtual bool WaitOne(int millisecondsTimeout)
- {
- if (millisecondsTimeout < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- }
-
- return WaitOneNoCheck(millisecondsTimeout);
- }
-
- private bool WaitOneNoCheck(int millisecondsTimeout)
- {
- Debug.Assert(millisecondsTimeout >= -1);
-
- // The field value is modifiable via the public <see cref="WaitHandle.SafeWaitHandle"/> property, save it locally
- // to ensure that one instance is used in all places in this method
- SafeWaitHandle waitHandle = _waitHandle ?? throw new ObjectDisposedException(null, SR.ObjectDisposed_Generic);
-
- bool success = false;
- try
- {
- int waitResult;
-
- waitHandle.DangerousAddRef(ref success);
-
- SynchronizationContext? context = SynchronizationContext.Current;
- if (context != null && context.IsWaitNotificationRequired())
- {
- waitResult = context.Wait(new[] { waitHandle.DangerousGetHandle() }, false, millisecondsTimeout);
- }
- else
- {
- waitResult = WaitOneCore(waitHandle.DangerousGetHandle(), millisecondsTimeout);
- }
-
- if (waitResult == WaitAbandoned)
- {
- throw new AbandonedMutexException();
- }
-
- return waitResult != WaitTimeout;
- }
- finally
- {
- if (success)
- waitHandle.DangerousRelease();
- }
- }
-
- // Returns an array for storing SafeWaitHandles in WaitMultiple calls. The array
- // is reused for subsequent calls to reduce GC pressure.
- private static SafeWaitHandle?[] RentSafeWaitHandleArray(int capacity)
- {
- SafeWaitHandle?[]? safeWaitHandles = t_safeWaitHandlesForRent;
-
- t_safeWaitHandlesForRent = null;
-
- // t_safeWaitHandlesForRent can be null when it was not initialized yet or
- // if a re-entrant wait is performed and the array is already rented. In
- // that case we just allocate a new one and reuse it as necessary.
- int currentLength = (safeWaitHandles != null) ? safeWaitHandles.Length : 0;
- if (currentLength < capacity)
- {
- safeWaitHandles = new SafeWaitHandle[Math.Max(capacity,
- Math.Min(MaxWaitHandles, 2 * currentLength))];
- }
-
- return safeWaitHandles;
- }
-
- private static void ReturnSafeWaitHandleArray(SafeWaitHandle?[]? safeWaitHandles)
- => t_safeWaitHandlesForRent = safeWaitHandles;
-
- /// <summary>
- /// Obtains all of the corresponding safe wait handles and adds a ref to each. Since the <see cref="SafeWaitHandle"/>
- /// property is publically modifiable, this makes sure that we add and release refs one the same set of safe wait
- /// handles to keep them alive during a multi-wait operation.
- /// </summary>
- private static void ObtainSafeWaitHandles(
- ReadOnlySpan<WaitHandle> waitHandles,
- Span<SafeWaitHandle?> safeWaitHandles,
- Span<IntPtr> unsafeWaitHandles)
- {
- Debug.Assert(waitHandles.Length > 0);
- Debug.Assert(waitHandles.Length <= MaxWaitHandles);
-
- bool lastSuccess = true;
- SafeWaitHandle? lastSafeWaitHandle = null;
- try
- {
- for (int i = 0; i < waitHandles.Length; ++i)
- {
- WaitHandle waitHandle = waitHandles[i];
- if (waitHandle == null)
- {
- throw new ArgumentNullException("waitHandles[" + i + ']', SR.ArgumentNull_ArrayElement);
- }
-
- SafeWaitHandle safeWaitHandle = waitHandle._waitHandle ??
- // Throw ObjectDisposedException for backward compatibility even though it is not representative of the issue
- throw new ObjectDisposedException(null, SR.ObjectDisposed_Generic);
-
- lastSafeWaitHandle = safeWaitHandle;
- lastSuccess = false;
- safeWaitHandle.DangerousAddRef(ref lastSuccess);
- safeWaitHandles[i] = safeWaitHandle;
- unsafeWaitHandles[i] = safeWaitHandle.DangerousGetHandle();
- }
- }
- catch
- {
- for (int i = 0; i < waitHandles.Length; ++i)
- {
- SafeWaitHandle? safeWaitHandle = safeWaitHandles[i];
- if (safeWaitHandle == null)
- {
- break;
- }
- safeWaitHandle.DangerousRelease();
- safeWaitHandles[i] = null;
- if (safeWaitHandle == lastSafeWaitHandle)
- {
- lastSafeWaitHandle = null;
- lastSuccess = true;
- }
- }
-
- if (!lastSuccess)
- {
- Debug.Assert(lastSafeWaitHandle != null);
- lastSafeWaitHandle.DangerousRelease();
- }
-
- throw;
- }
- }
-
- private static int WaitMultiple(WaitHandle[] waitHandles, bool waitAll, int millisecondsTimeout)
- {
- if (waitHandles == null)
- {
- throw new ArgumentNullException(nameof(waitHandles), SR.ArgumentNull_Waithandles);
- }
-
- return WaitMultiple(new ReadOnlySpan<WaitHandle>(waitHandles), waitAll, millisecondsTimeout);
- }
-
- private static int WaitMultiple(ReadOnlySpan<WaitHandle> waitHandles, bool waitAll, int millisecondsTimeout)
- {
- if (waitHandles.Length == 0)
- {
- //
- // Some history: in CLR 1.0 and 1.1, we threw ArgumentException in this case, which was correct.
- // Somehow, in 2.0, this became ArgumentNullException. This was not fixed until Silverlight 2,
- // which went back to ArgumentException.
- //
- // Now we're in a bit of a bind. Backward-compatibility requires us to keep throwing ArgumentException
- // in CoreCLR, and ArgumentNullException in the desktop CLR. This is ugly, but so is breaking
- // user code.
- //
- throw new ArgumentException(SR.Argument_EmptyWaithandleArray, nameof(waitHandles));
- }
- if (waitHandles.Length > MaxWaitHandles)
- {
- throw new NotSupportedException(SR.NotSupported_MaxWaitHandles);
- }
- if (millisecondsTimeout < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- }
-
- SynchronizationContext? context = SynchronizationContext.Current;
- bool useWaitContext = context != null && context.IsWaitNotificationRequired();
- SafeWaitHandle?[]? safeWaitHandles = RentSafeWaitHandleArray(waitHandles.Length);
-
- try
- {
- int waitResult;
-
- if (useWaitContext)
- {
- IntPtr[] unsafeWaitHandles = new IntPtr[waitHandles.Length];
- ObtainSafeWaitHandles(waitHandles, safeWaitHandles, unsafeWaitHandles);
- waitResult = context!.Wait(unsafeWaitHandles, waitAll, millisecondsTimeout);
- }
- else
- {
- Span<IntPtr> unsafeWaitHandles = stackalloc IntPtr[waitHandles.Length];
- ObtainSafeWaitHandles(waitHandles, safeWaitHandles, unsafeWaitHandles);
- waitResult = WaitMultipleIgnoringSyncContext(unsafeWaitHandles, waitAll, millisecondsTimeout);
- }
-
- if (waitResult >= WaitAbandoned && waitResult < WaitAbandoned + waitHandles.Length)
- {
- if (waitAll)
- {
- // In the case of WaitAll the OS will only provide the information that mutex was abandoned.
- // It won't tell us which one. So we can't set the Index or provide access to the Mutex
- throw new AbandonedMutexException();
- }
-
- waitResult -= WaitAbandoned;
- throw new AbandonedMutexException(waitResult, waitHandles[waitResult]);
- }
-
- return waitResult;
- }
- finally
- {
- for (int i = 0; i < waitHandles.Length; ++i)
- {
- if (safeWaitHandles[i] != null)
- {
- safeWaitHandles[i]!.DangerousRelease(); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- safeWaitHandles[i] = null;
- }
- }
-
- ReturnSafeWaitHandleArray(safeWaitHandles);
- }
- }
-
- private static bool SignalAndWait(WaitHandle toSignal, WaitHandle toWaitOn, int millisecondsTimeout)
- {
- if (toSignal == null)
- {
- throw new ArgumentNullException(nameof(toSignal));
- }
- if (toWaitOn == null)
- {
- throw new ArgumentNullException(nameof(toWaitOn));
- }
- if (millisecondsTimeout < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- }
-
- // The field value is modifiable via the public <see cref="WaitHandle.SafeWaitHandle"/> property, save it locally
- // to ensure that one instance is used in all places in this method
- SafeWaitHandle? safeWaitHandleToSignal = toSignal._waitHandle;
- SafeWaitHandle? safeWaitHandleToWaitOn = toWaitOn._waitHandle;
- if (safeWaitHandleToSignal == null || safeWaitHandleToWaitOn == null)
- {
- // Throw ObjectDisposedException for backward compatibility even though it is not be representative of the issue
- throw new ObjectDisposedException(null, SR.ObjectDisposed_Generic);
- }
-
- bool successSignal = false, successWait = false;
- try
- {
- safeWaitHandleToSignal.DangerousAddRef(ref successSignal);
- safeWaitHandleToWaitOn.DangerousAddRef(ref successWait);
-
- int ret = SignalAndWaitCore(
- safeWaitHandleToSignal.DangerousGetHandle(),
- safeWaitHandleToWaitOn.DangerousGetHandle(),
- millisecondsTimeout);
-
- if (ret == WaitAbandoned)
- {
- throw new AbandonedMutexException();
- }
-
- return ret != WaitTimeout;
- }
- finally
- {
- if (successWait)
- {
- safeWaitHandleToWaitOn.DangerousRelease();
- }
- if (successSignal)
- {
- safeWaitHandleToSignal.DangerousRelease();
- }
- }
- }
-
- public virtual bool WaitOne(TimeSpan timeout) => WaitOneNoCheck(ToTimeoutMilliseconds(timeout));
- public virtual bool WaitOne() => WaitOneNoCheck(-1);
- public virtual bool WaitOne(int millisecondsTimeout, bool exitContext) => WaitOne(millisecondsTimeout);
- public virtual bool WaitOne(TimeSpan timeout, bool exitContext) => WaitOneNoCheck(ToTimeoutMilliseconds(timeout));
-
- public static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout) =>
- WaitMultiple(waitHandles, true, millisecondsTimeout) != WaitTimeout;
- public static bool WaitAll(WaitHandle[] waitHandles, TimeSpan timeout) =>
- WaitMultiple(waitHandles, true, ToTimeoutMilliseconds(timeout)) != WaitTimeout;
- public static bool WaitAll(WaitHandle[] waitHandles) =>
- WaitMultiple(waitHandles, true, -1) != WaitTimeout;
- public static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) =>
- WaitMultiple(waitHandles, true, millisecondsTimeout) != WaitTimeout;
- public static bool WaitAll(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext) =>
- WaitMultiple(waitHandles, true, ToTimeoutMilliseconds(timeout)) != WaitTimeout;
-
- public static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout) =>
- WaitMultiple(waitHandles, false, millisecondsTimeout);
- public static int WaitAny(WaitHandle[] waitHandles, TimeSpan timeout) =>
- WaitMultiple(waitHandles, false, ToTimeoutMilliseconds(timeout));
- public static int WaitAny(WaitHandle[] waitHandles) =>
- WaitMultiple(waitHandles, false, -1);
- public static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) =>
- WaitMultiple(waitHandles, false, millisecondsTimeout);
- public static int WaitAny(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext) =>
- WaitMultiple(waitHandles, false, ToTimeoutMilliseconds(timeout));
-
- public static bool SignalAndWait(WaitHandle toSignal, WaitHandle toWaitOn) =>
- SignalAndWait(toSignal, toWaitOn, -1);
- public static bool SignalAndWait(WaitHandle toSignal, WaitHandle toWaitOn, TimeSpan timeout, bool exitContext) =>
- SignalAndWait(toSignal, toWaitOn, ToTimeoutMilliseconds(timeout));
- public static bool SignalAndWait(WaitHandle toSignal, WaitHandle toWaitOn, int millisecondsTimeout, bool exitContext) =>
- SignalAndWait(toSignal, toWaitOn, millisecondsTimeout);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/WaitHandleCannotBeOpenedException.cs b/netcore/System.Private.CoreLib/shared/System/Threading/WaitHandleCannotBeOpenedException.cs
deleted file mode 100644
index f273456e49d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Threading/WaitHandleCannotBeOpenedException.cs
+++ /dev/null
@@ -1,32 +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 System.Runtime.Serialization;
-
-namespace System.Threading
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class WaitHandleCannotBeOpenedException : ApplicationException
- {
- public WaitHandleCannotBeOpenedException() : base(SR.Threading_WaitHandleCannotBeOpenedException)
- {
- HResult = HResults.COR_E_WAITHANDLECANNOTBEOPENED;
- }
-
- public WaitHandleCannotBeOpenedException(string? message) : base(message)
- {
- HResult = HResults.COR_E_WAITHANDLECANNOTBEOPENED;
- }
-
- public WaitHandleCannotBeOpenedException(string? message, Exception? innerException) : base(message, innerException)
- {
- HResult = HResults.COR_E_WAITHANDLECANNOTBEOPENED;
- }
-
- protected WaitHandleCannotBeOpenedException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ThrowHelper.cs b/netcore/System.Private.CoreLib/shared/System/ThrowHelper.cs
deleted file mode 100644
index d233e40acf4..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ThrowHelper.cs
+++ /dev/null
@@ -1,1009 +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.
-
-
-// This file defines an internal class used to throw exceptions in BCL code.
-// The main purpose is to reduce code size.
-//
-// The old way to throw an exception generates quite a lot IL code and assembly code.
-// Following is an example:
-// C# source
-// throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
-// IL code:
-// IL_0003: ldstr "key"
-// IL_0008: ldstr "ArgumentNull_Key"
-// IL_000d: call string System.Environment::GetResourceString(string)
-// IL_0012: newobj instance void System.ArgumentNullException::.ctor(string,string)
-// IL_0017: throw
-// which is 21bytes in IL.
-//
-// So we want to get rid of the ldstr and call to Environment.GetResource in IL.
-// In order to do that, I created two enums: ExceptionResource, ExceptionArgument to represent the
-// argument name and resource name in a small integer. The source code will be changed to
-// ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key, ExceptionResource.ArgumentNull_Key);
-//
-// The IL code will be 7 bytes.
-// IL_0008: ldc.i4.4
-// IL_0009: ldc.i4.4
-// IL_000a: call void System.ThrowHelper::ThrowArgumentNullException(valuetype System.ExceptionArgument)
-// IL_000f: ldarg.0
-//
-// This will also reduce the Jitted code size a lot.
-//
-// It is very important we do this for generic classes because we can easily generate the same code
-// multiple times for different instantiation.
-//
-
-using System.Buffers;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-
-namespace System
-{
- [StackTraceHidden]
- internal static class ThrowHelper
- {
- [DoesNotReturn]
- internal static void ThrowArrayTypeMismatchException()
- {
- throw new ArrayTypeMismatchException();
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidTypeWithPointersNotSupported(Type targetType)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, targetType));
- }
-
- [DoesNotReturn]
- internal static void ThrowIndexOutOfRangeException()
- {
- throw new IndexOutOfRangeException();
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentOutOfRangeException()
- {
- throw new ArgumentOutOfRangeException();
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentException_DestinationTooShort()
- {
- throw new ArgumentException(SR.Argument_DestinationTooShort, "destination");
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentException_OverlapAlignmentMismatch()
- {
- throw new ArgumentException(SR.Argument_OverlapAlignmentMismatch);
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentException_CannotExtractScalar(ExceptionArgument argument)
- {
- throw GetArgumentException(ExceptionResource.Argument_CannotExtractScalar, argument);
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentOutOfRange_IndexException()
- {
- throw GetArgumentOutOfRangeException(ExceptionArgument.index,
- ExceptionResource.ArgumentOutOfRange_Index);
- }
-
- [DoesNotReturn]
- internal static void ThrowIndexArgumentOutOfRange_NeedNonNegNumException()
- {
- throw GetArgumentOutOfRangeException(ExceptionArgument.index,
- ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- [DoesNotReturn]
- internal static void ThrowValueArgumentOutOfRange_NeedNonNegNumException()
- {
- throw GetArgumentOutOfRangeException(ExceptionArgument.value,
- ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- [DoesNotReturn]
- internal static void ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum()
- {
- throw GetArgumentOutOfRangeException(ExceptionArgument.length,
- ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
-
- [DoesNotReturn]
- internal static void ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index()
- {
- throw GetArgumentOutOfRangeException(ExceptionArgument.startIndex,
- ExceptionResource.ArgumentOutOfRange_Index);
- }
-
- [DoesNotReturn]
- internal static void ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count()
- {
- throw GetArgumentOutOfRangeException(ExceptionArgument.count,
- ExceptionResource.ArgumentOutOfRange_Count);
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentOutOfRange_Year()
- {
- throw GetArgumentOutOfRangeException(ExceptionArgument.year,
- ExceptionResource.ArgumentOutOfRange_Year);
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentOutOfRange_BadYearMonthDay()
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadYearMonthDay);
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentOutOfRange_BadHourMinuteSecond()
- {
- throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_BadHourMinuteSecond);
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentOutOfRange_TimeSpanTooLong()
- {
- throw new ArgumentOutOfRangeException(null, SR.Overflow_TimeSpanTooLong);
- }
-
- [DoesNotReturn]
- internal static void ThrowWrongKeyTypeArgumentException<T>(T key, Type targetType)
- {
- // Generic key to move the boxing to the right hand side of throw
- throw GetWrongKeyTypeArgumentException((object?)key, targetType);
- }
-
- [DoesNotReturn]
- internal static void ThrowWrongValueTypeArgumentException<T>(T value, Type targetType)
- {
- // Generic key to move the boxing to the right hand side of throw
- throw GetWrongValueTypeArgumentException((object?)value, targetType);
- }
-
- private static ArgumentException GetAddingDuplicateWithKeyArgumentException(object? key)
- {
- return new ArgumentException(SR.Format(SR.Argument_AddingDuplicateWithKey, key));
- }
-
- [DoesNotReturn]
- internal static void ThrowAddingDuplicateWithKeyArgumentException<T>(T key)
- {
- // Generic key to move the boxing to the right hand side of throw
- throw GetAddingDuplicateWithKeyArgumentException((object?)key);
- }
-
- [DoesNotReturn]
- internal static void ThrowKeyNotFoundException<T>(T key)
- {
- // Generic key to move the boxing to the right hand side of throw
- throw GetKeyNotFoundException((object?)key);
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentException(ExceptionResource resource)
- {
- throw GetArgumentException(resource);
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentException(ExceptionResource resource, ExceptionArgument argument)
- {
- throw GetArgumentException(resource, argument);
- }
-
- private static ArgumentNullException GetArgumentNullException(ExceptionArgument argument)
- {
- return new ArgumentNullException(GetArgumentName(argument));
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentNullException(ExceptionArgument argument)
- {
- throw GetArgumentNullException(argument);
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentNullException(ExceptionResource resource)
- {
- throw new ArgumentNullException(GetResourceString(resource));
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentNullException(ExceptionArgument argument, ExceptionResource resource)
- {
- throw new ArgumentNullException(GetArgumentName(argument), GetResourceString(resource));
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument)
- {
- throw new ArgumentOutOfRangeException(GetArgumentName(argument));
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
- {
- throw GetArgumentOutOfRangeException(argument, resource);
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, int paramNumber, ExceptionResource resource)
- {
- throw GetArgumentOutOfRangeException(argument, paramNumber, resource);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException()
- {
- throw new InvalidOperationException();
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException(ExceptionResource resource)
- {
- throw GetInvalidOperationException(resource);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException_OutstandingReferences()
- {
- throw new InvalidOperationException(SR.Memory_OutstandingReferences);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException(ExceptionResource resource, Exception e)
- {
- throw new InvalidOperationException(GetResourceString(resource), e);
- }
-
- [DoesNotReturn]
- internal static void ThrowSerializationException(ExceptionResource resource)
- {
- throw new SerializationException(GetResourceString(resource));
- }
-
- [DoesNotReturn]
- internal static void ThrowSecurityException(ExceptionResource resource)
- {
- throw new System.Security.SecurityException(GetResourceString(resource));
- }
-
- [DoesNotReturn]
- internal static void ThrowRankException(ExceptionResource resource)
- {
- throw new RankException(GetResourceString(resource));
- }
-
- [DoesNotReturn]
- internal static void ThrowNotSupportedException(ExceptionResource resource)
- {
- throw new NotSupportedException(GetResourceString(resource));
- }
-
- [DoesNotReturn]
- internal static void ThrowUnauthorizedAccessException(ExceptionResource resource)
- {
- throw new UnauthorizedAccessException(GetResourceString(resource));
- }
-
- [DoesNotReturn]
- internal static void ThrowObjectDisposedException(string objectName, ExceptionResource resource)
- {
- throw new ObjectDisposedException(objectName, GetResourceString(resource));
- }
-
- [DoesNotReturn]
- internal static void ThrowObjectDisposedException(ExceptionResource resource)
- {
- throw new ObjectDisposedException(null, GetResourceString(resource));
- }
-
- [DoesNotReturn]
- internal static void ThrowNotSupportedException()
- {
- throw new NotSupportedException();
- }
-
- [DoesNotReturn]
- internal static void ThrowAggregateException(List<Exception> exceptions)
- {
- throw new AggregateException(exceptions);
- }
-
- [DoesNotReturn]
- internal static void ThrowOutOfMemoryException()
- {
- throw new OutOfMemoryException();
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentException_Argument_InvalidArrayType()
- {
- throw new ArgumentException(SR.Argument_InvalidArrayType);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException_InvalidOperation_EnumNotStarted()
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException_InvalidOperation_EnumEnded()
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumEnded);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException_EnumCurrent(int index)
- {
- throw GetInvalidOperationException_EnumCurrent(index);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion()
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen()
- {
- throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException_InvalidOperation_NoValue()
- {
- throw new InvalidOperationException(SR.InvalidOperation_NoValue);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException_ConcurrentOperationsNotSupported()
- {
- throw new InvalidOperationException(SR.InvalidOperation_ConcurrentOperationsNotSupported);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException_HandleIsNotInitialized()
- {
- throw new InvalidOperationException(SR.InvalidOperation_HandleIsNotInitialized);
- }
-
- [DoesNotReturn]
- internal static void ThrowInvalidOperationException_HandleIsNotPinned()
- {
- throw new InvalidOperationException(SR.InvalidOperation_HandleIsNotPinned);
- }
-
- [DoesNotReturn]
- internal static void ThrowArraySegmentCtorValidationFailedExceptions(Array? array, int offset, int count)
- {
- throw GetArraySegmentCtorValidationFailedException(array, offset, count);
- }
-
- [DoesNotReturn]
- internal static void ThrowFormatException_BadFormatSpecifier()
- {
- throw new FormatException(SR.Argument_BadFormatSpecifier);
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentOutOfRangeException_PrecisionTooLarge()
- {
- throw new ArgumentOutOfRangeException("precision", SR.Format(SR.Argument_PrecisionTooLarge, StandardFormat.MaxPrecision));
- }
-
- [DoesNotReturn]
- internal static void ThrowArgumentOutOfRangeException_SymbolDoesNotFit()
- {
- throw new ArgumentOutOfRangeException("symbol", SR.Argument_BadFormatSpecifier);
- }
-
- private static Exception GetArraySegmentCtorValidationFailedException(Array? array, int offset, int count)
- {
- if (array == null)
- return new ArgumentNullException(nameof(array));
- if (offset < 0)
- return new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (count < 0)
- return new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- Debug.Assert(array.Length - offset < count);
- return new ArgumentException(SR.Argument_InvalidOffLen);
- }
-
- private static ArgumentException GetArgumentException(ExceptionResource resource)
- {
- return new ArgumentException(GetResourceString(resource));
- }
-
- private static InvalidOperationException GetInvalidOperationException(ExceptionResource resource)
- {
- return new InvalidOperationException(GetResourceString(resource));
- }
-
- private static ArgumentException GetWrongKeyTypeArgumentException(object? key, Type targetType)
- {
- return new ArgumentException(SR.Format(SR.Arg_WrongType, key, targetType), nameof(key));
- }
-
- private static ArgumentException GetWrongValueTypeArgumentException(object? value, Type targetType)
- {
- return new ArgumentException(SR.Format(SR.Arg_WrongType, value, targetType), nameof(value));
- }
-
- private static KeyNotFoundException GetKeyNotFoundException(object? key)
- {
- return new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key));
- }
-
- private static ArgumentOutOfRangeException GetArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
- {
- return new ArgumentOutOfRangeException(GetArgumentName(argument), GetResourceString(resource));
- }
-
- private static ArgumentException GetArgumentException(ExceptionResource resource, ExceptionArgument argument)
- {
- return new ArgumentException(GetResourceString(resource), GetArgumentName(argument));
- }
-
- private static ArgumentOutOfRangeException GetArgumentOutOfRangeException(ExceptionArgument argument, int paramNumber, ExceptionResource resource)
- {
- return new ArgumentOutOfRangeException(GetArgumentName(argument) + "[" + paramNumber.ToString() + "]", GetResourceString(resource));
- }
-
- private static InvalidOperationException GetInvalidOperationException_EnumCurrent(int index)
- {
- return new InvalidOperationException(
- index < 0 ?
- SR.InvalidOperation_EnumNotStarted :
- SR.InvalidOperation_EnumEnded);
- }
-
- // Allow nulls for reference types and Nullable<U>, but not for value types.
- // Aggressively inline so the jit evaluates the if in place and either drops the call altogether
- // Or just leaves null test and call to the Non-returning ThrowHelper.ThrowArgumentNullException
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void IfNullAndNullsAreIllegalThenThrow<T>(object? value, ExceptionArgument argName)
- {
- // Note that default(T) is not equal to null for value types except when T is Nullable<U>.
- if (!(default(T)! == null) && value == null) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
- ThrowHelper.ThrowArgumentNullException(argName);
- }
-
- // Throws if 'T' is disallowed in Vector<T> / Vector128<T> / other related types in the
- // Numerics or Intrinsics namespaces. If 'T' is allowed, no-ops. JIT will elide the method
- // entirely if 'T' is supported and we're on an optimized release build.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void ThrowForUnsupportedVectorBaseType<T>() where T : struct
- {
- if (typeof(T) != typeof(byte) && typeof(T) != typeof(sbyte) &&
- typeof(T) != typeof(short) && typeof(T) != typeof(ushort) &&
- typeof(T) != typeof(int) && typeof(T) != typeof(uint) &&
- typeof(T) != typeof(long) && typeof(T) != typeof(ulong) &&
- typeof(T) != typeof(float) && typeof(T) != typeof(double))
- {
- ThrowNotSupportedException(ExceptionResource.Arg_TypeNotSupported);
- }
- }
-
-#if false // Reflection-based implementation does not work for CoreRT/ProjectN
- // This function will convert an ExceptionArgument enum value to the argument name string.
- [MethodImpl(MethodImplOptions.NoInlining)]
- private static string GetArgumentName(ExceptionArgument argument)
- {
- Debug.Assert(Enum.IsDefined(typeof(ExceptionArgument), argument),
- "The enum value is not defined, please check the ExceptionArgument Enum.");
-
- return argument.ToString();
- }
-#endif
-
- private static string GetArgumentName(ExceptionArgument argument)
- {
- switch (argument)
- {
- case ExceptionArgument.obj:
- return "obj";
- case ExceptionArgument.dictionary:
- return "dictionary";
- case ExceptionArgument.array:
- return "array";
- case ExceptionArgument.info:
- return "info";
- case ExceptionArgument.key:
- return "key";
- case ExceptionArgument.text:
- return "text";
- case ExceptionArgument.values:
- return "values";
- case ExceptionArgument.value:
- return "value";
- case ExceptionArgument.startIndex:
- return "startIndex";
- case ExceptionArgument.task:
- return "task";
- case ExceptionArgument.bytes:
- return "bytes";
- case ExceptionArgument.byteIndex:
- return "byteIndex";
- case ExceptionArgument.byteCount:
- return "byteCount";
- case ExceptionArgument.ch:
- return "ch";
- case ExceptionArgument.chars:
- return "chars";
- case ExceptionArgument.charIndex:
- return "charIndex";
- case ExceptionArgument.charCount:
- return "charCount";
- case ExceptionArgument.s:
- return "s";
- case ExceptionArgument.input:
- return "input";
- case ExceptionArgument.ownedMemory:
- return "ownedMemory";
- case ExceptionArgument.list:
- return "list";
- case ExceptionArgument.index:
- return "index";
- case ExceptionArgument.capacity:
- return "capacity";
- case ExceptionArgument.collection:
- return "collection";
- case ExceptionArgument.item:
- return "item";
- case ExceptionArgument.converter:
- return "converter";
- case ExceptionArgument.match:
- return "match";
- case ExceptionArgument.count:
- return "count";
- case ExceptionArgument.action:
- return "action";
- case ExceptionArgument.comparison:
- return "comparison";
- case ExceptionArgument.exceptions:
- return "exceptions";
- case ExceptionArgument.exception:
- return "exception";
- case ExceptionArgument.pointer:
- return "pointer";
- case ExceptionArgument.start:
- return "start";
- case ExceptionArgument.format:
- return "format";
- case ExceptionArgument.culture:
- return "culture";
- case ExceptionArgument.comparer:
- return "comparer";
- case ExceptionArgument.comparable:
- return "comparable";
- case ExceptionArgument.source:
- return "source";
- case ExceptionArgument.state:
- return "state";
- case ExceptionArgument.length:
- return "length";
- case ExceptionArgument.comparisonType:
- return "comparisonType";
- case ExceptionArgument.manager:
- return "manager";
- case ExceptionArgument.sourceBytesToCopy:
- return "sourceBytesToCopy";
- case ExceptionArgument.callBack:
- return "callBack";
- case ExceptionArgument.creationOptions:
- return "creationOptions";
- case ExceptionArgument.function:
- return "function";
- case ExceptionArgument.scheduler:
- return "scheduler";
- case ExceptionArgument.continuationAction:
- return "continuationAction";
- case ExceptionArgument.continuationFunction:
- return "continuationFunction";
- case ExceptionArgument.tasks:
- return "tasks";
- case ExceptionArgument.asyncResult:
- return "asyncResult";
- case ExceptionArgument.beginMethod:
- return "beginMethod";
- case ExceptionArgument.endMethod:
- return "endMethod";
- case ExceptionArgument.endFunction:
- return "endFunction";
- case ExceptionArgument.cancellationToken:
- return "cancellationToken";
- case ExceptionArgument.continuationOptions:
- return "continuationOptions";
- case ExceptionArgument.delay:
- return "delay";
- case ExceptionArgument.millisecondsDelay:
- return "millisecondsDelay";
- case ExceptionArgument.millisecondsTimeout:
- return "millisecondsTimeout";
- case ExceptionArgument.stateMachine:
- return "stateMachine";
- case ExceptionArgument.timeout:
- return "timeout";
- case ExceptionArgument.type:
- return "type";
- case ExceptionArgument.sourceIndex:
- return "sourceIndex";
- case ExceptionArgument.sourceArray:
- return "sourceArray";
- case ExceptionArgument.destinationIndex:
- return "destinationIndex";
- case ExceptionArgument.destinationArray:
- return "destinationArray";
- case ExceptionArgument.pHandle:
- return "pHandle";
- case ExceptionArgument.other:
- return "other";
- case ExceptionArgument.newSize:
- return "newSize";
- case ExceptionArgument.lowerBounds:
- return "lowerBounds";
- case ExceptionArgument.lengths:
- return "lengths";
- case ExceptionArgument.len:
- return "len";
- case ExceptionArgument.keys:
- return "keys";
- case ExceptionArgument.indices:
- return "indices";
- case ExceptionArgument.index1:
- return "index1";
- case ExceptionArgument.index2:
- return "index2";
- case ExceptionArgument.index3:
- return "index3";
- case ExceptionArgument.length1:
- return "length1";
- case ExceptionArgument.length2:
- return "length2";
- case ExceptionArgument.length3:
- return "length3";
- case ExceptionArgument.endIndex:
- return "endIndex";
- case ExceptionArgument.elementType:
- return "elementType";
- case ExceptionArgument.arrayIndex:
- return "arrayIndex";
- case ExceptionArgument.year:
- return "year";
- default:
- Debug.Fail("The enum value is not defined, please check the ExceptionArgument Enum.");
- return "";
- }
- }
-
-#if false // Reflection-based implementation does not work for CoreRT/ProjectN
- // This function will convert an ExceptionResource enum value to the resource string.
- [MethodImpl(MethodImplOptions.NoInlining)]
- private static string GetResourceString(ExceptionResource resource)
- {
- Debug.Assert(Enum.IsDefined(typeof(ExceptionResource), resource),
- "The enum value is not defined, please check the ExceptionResource Enum.");
-
- return SR.GetResourceString(resource.ToString());
- }
-#endif
-
- private static string GetResourceString(ExceptionResource resource)
- {
- switch (resource)
- {
- case ExceptionResource.ArgumentOutOfRange_Index:
- return SR.ArgumentOutOfRange_Index;
- case ExceptionResource.ArgumentOutOfRange_IndexCount:
- return SR.ArgumentOutOfRange_IndexCount;
- case ExceptionResource.ArgumentOutOfRange_IndexCountBuffer:
- return SR.ArgumentOutOfRange_IndexCountBuffer;
- case ExceptionResource.ArgumentOutOfRange_Count:
- return SR.ArgumentOutOfRange_Count;
- case ExceptionResource.ArgumentOutOfRange_Year:
- return SR.ArgumentOutOfRange_Year;
- case ExceptionResource.Arg_ArrayPlusOffTooSmall:
- return SR.Arg_ArrayPlusOffTooSmall;
- case ExceptionResource.NotSupported_ReadOnlyCollection:
- return SR.NotSupported_ReadOnlyCollection;
- case ExceptionResource.Arg_RankMultiDimNotSupported:
- return SR.Arg_RankMultiDimNotSupported;
- case ExceptionResource.Arg_NonZeroLowerBound:
- return SR.Arg_NonZeroLowerBound;
- case ExceptionResource.ArgumentOutOfRange_ListInsert:
- return SR.ArgumentOutOfRange_ListInsert;
- case ExceptionResource.ArgumentOutOfRange_NeedNonNegNum:
- return SR.ArgumentOutOfRange_NeedNonNegNum;
- case ExceptionResource.ArgumentOutOfRange_SmallCapacity:
- return SR.ArgumentOutOfRange_SmallCapacity;
- case ExceptionResource.Argument_InvalidOffLen:
- return SR.Argument_InvalidOffLen;
- case ExceptionResource.Argument_CannotExtractScalar:
- return SR.Argument_CannotExtractScalar;
- case ExceptionResource.ArgumentOutOfRange_BiggerThanCollection:
- return SR.ArgumentOutOfRange_BiggerThanCollection;
- case ExceptionResource.Serialization_MissingKeys:
- return SR.Serialization_MissingKeys;
- case ExceptionResource.Serialization_NullKey:
- return SR.Serialization_NullKey;
- case ExceptionResource.NotSupported_KeyCollectionSet:
- return SR.NotSupported_KeyCollectionSet;
- case ExceptionResource.NotSupported_ValueCollectionSet:
- return SR.NotSupported_ValueCollectionSet;
- case ExceptionResource.InvalidOperation_NullArray:
- return SR.InvalidOperation_NullArray;
- case ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted:
- return SR.TaskT_TransitionToFinal_AlreadyCompleted;
- case ExceptionResource.TaskCompletionSourceT_TrySetException_NullException:
- return SR.TaskCompletionSourceT_TrySetException_NullException;
- case ExceptionResource.TaskCompletionSourceT_TrySetException_NoExceptions:
- return SR.TaskCompletionSourceT_TrySetException_NoExceptions;
- case ExceptionResource.NotSupported_StringComparison:
- return SR.NotSupported_StringComparison;
- case ExceptionResource.ConcurrentCollection_SyncRoot_NotSupported:
- return SR.ConcurrentCollection_SyncRoot_NotSupported;
- case ExceptionResource.Task_MultiTaskContinuation_NullTask:
- return SR.Task_MultiTaskContinuation_NullTask;
- case ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple:
- return SR.InvalidOperation_WrongAsyncResultOrEndCalledMultiple;
- case ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList:
- return SR.Task_MultiTaskContinuation_EmptyTaskList;
- case ExceptionResource.Task_Start_TaskCompleted:
- return SR.Task_Start_TaskCompleted;
- case ExceptionResource.Task_Start_Promise:
- return SR.Task_Start_Promise;
- case ExceptionResource.Task_Start_ContinuationTask:
- return SR.Task_Start_ContinuationTask;
- case ExceptionResource.Task_Start_AlreadyStarted:
- return SR.Task_Start_AlreadyStarted;
- case ExceptionResource.Task_RunSynchronously_Continuation:
- return SR.Task_RunSynchronously_Continuation;
- case ExceptionResource.Task_RunSynchronously_Promise:
- return SR.Task_RunSynchronously_Promise;
- case ExceptionResource.Task_RunSynchronously_TaskCompleted:
- return SR.Task_RunSynchronously_TaskCompleted;
- case ExceptionResource.Task_RunSynchronously_AlreadyStarted:
- return SR.Task_RunSynchronously_AlreadyStarted;
- case ExceptionResource.AsyncMethodBuilder_InstanceNotInitialized:
- return SR.AsyncMethodBuilder_InstanceNotInitialized;
- case ExceptionResource.Task_ContinueWith_ESandLR:
- return SR.Task_ContinueWith_ESandLR;
- case ExceptionResource.Task_ContinueWith_NotOnAnything:
- return SR.Task_ContinueWith_NotOnAnything;
- case ExceptionResource.Task_Delay_InvalidDelay:
- return SR.Task_Delay_InvalidDelay;
- case ExceptionResource.Task_Delay_InvalidMillisecondsDelay:
- return SR.Task_Delay_InvalidMillisecondsDelay;
- case ExceptionResource.Task_Dispose_NotCompleted:
- return SR.Task_Dispose_NotCompleted;
- case ExceptionResource.Task_ThrowIfDisposed:
- return SR.Task_ThrowIfDisposed;
- case ExceptionResource.Task_WaitMulti_NullTask:
- return SR.Task_WaitMulti_NullTask;
- case ExceptionResource.ArgumentException_OtherNotArrayOfCorrectLength:
- return SR.ArgumentException_OtherNotArrayOfCorrectLength;
- case ExceptionResource.ArgumentNull_Array:
- return SR.ArgumentNull_Array;
- case ExceptionResource.ArgumentNull_SafeHandle:
- return SR.ArgumentNull_SafeHandle;
- case ExceptionResource.ArgumentOutOfRange_EndIndexStartIndex:
- return SR.ArgumentOutOfRange_EndIndexStartIndex;
- case ExceptionResource.ArgumentOutOfRange_Enum:
- return SR.ArgumentOutOfRange_Enum;
- case ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported:
- return SR.ArgumentOutOfRange_HugeArrayNotSupported;
- case ExceptionResource.Argument_AddingDuplicate:
- return SR.Argument_AddingDuplicate;
- case ExceptionResource.Argument_InvalidArgumentForComparison:
- return SR.Argument_InvalidArgumentForComparison;
- case ExceptionResource.Arg_LowerBoundsMustMatch:
- return SR.Arg_LowerBoundsMustMatch;
- case ExceptionResource.Arg_MustBeType:
- return SR.Arg_MustBeType;
- case ExceptionResource.Arg_Need1DArray:
- return SR.Arg_Need1DArray;
- case ExceptionResource.Arg_Need2DArray:
- return SR.Arg_Need2DArray;
- case ExceptionResource.Arg_Need3DArray:
- return SR.Arg_Need3DArray;
- case ExceptionResource.Arg_NeedAtLeast1Rank:
- return SR.Arg_NeedAtLeast1Rank;
- case ExceptionResource.Arg_RankIndices:
- return SR.Arg_RankIndices;
- case ExceptionResource.Arg_RanksAndBounds:
- return SR.Arg_RanksAndBounds;
- case ExceptionResource.InvalidOperation_IComparerFailed:
- return SR.InvalidOperation_IComparerFailed;
- case ExceptionResource.NotSupported_FixedSizeCollection:
- return SR.NotSupported_FixedSizeCollection;
- case ExceptionResource.Rank_MultiDimNotSupported:
- return SR.Rank_MultiDimNotSupported;
- case ExceptionResource.Arg_TypeNotSupported:
- return SR.Arg_TypeNotSupported;
- case ExceptionResource.Argument_SpansMustHaveSameLength:
- return SR.Argument_SpansMustHaveSameLength;
- default:
- Debug.Fail("The enum value is not defined, please check the ExceptionResource Enum.");
- return "";
- }
- }
- }
-
- //
- // The convention for this enum is using the argument name as the enum name
- //
- internal enum ExceptionArgument
- {
- obj,
- dictionary,
- array,
- info,
- key,
- text,
- values,
- value,
- startIndex,
- task,
- bytes,
- byteIndex,
- byteCount,
- ch,
- chars,
- charIndex,
- charCount,
- s,
- input,
- ownedMemory,
- list,
- index,
- capacity,
- collection,
- item,
- converter,
- match,
- count,
- action,
- comparison,
- exceptions,
- exception,
- pointer,
- start,
- format,
- culture,
- comparer,
- comparable,
- source,
- state,
- length,
- comparisonType,
- manager,
- sourceBytesToCopy,
- callBack,
- creationOptions,
- function,
- scheduler,
- continuationAction,
- continuationFunction,
- tasks,
- asyncResult,
- beginMethod,
- endMethod,
- endFunction,
- cancellationToken,
- continuationOptions,
- delay,
- millisecondsDelay,
- millisecondsTimeout,
- stateMachine,
- timeout,
- type,
- sourceIndex,
- sourceArray,
- destinationIndex,
- destinationArray,
- pHandle,
- other,
- newSize,
- lowerBounds,
- lengths,
- len,
- keys,
- indices,
- index1,
- index2,
- index3,
- length1,
- length2,
- length3,
- endIndex,
- elementType,
- arrayIndex,
- year,
- }
-
- //
- // The convention for this enum is using the resource name as the enum name
- //
- internal enum ExceptionResource
- {
- ArgumentOutOfRange_Index,
- ArgumentOutOfRange_IndexCount,
- ArgumentOutOfRange_IndexCountBuffer,
- ArgumentOutOfRange_Count,
- ArgumentOutOfRange_Year,
- Arg_ArrayPlusOffTooSmall,
- NotSupported_ReadOnlyCollection,
- Arg_RankMultiDimNotSupported,
- Arg_NonZeroLowerBound,
- ArgumentOutOfRange_ListInsert,
- ArgumentOutOfRange_NeedNonNegNum,
- ArgumentOutOfRange_SmallCapacity,
- Argument_InvalidOffLen,
- Argument_CannotExtractScalar,
- ArgumentOutOfRange_BiggerThanCollection,
- Serialization_MissingKeys,
- Serialization_NullKey,
- NotSupported_KeyCollectionSet,
- NotSupported_ValueCollectionSet,
- InvalidOperation_NullArray,
- TaskT_TransitionToFinal_AlreadyCompleted,
- TaskCompletionSourceT_TrySetException_NullException,
- TaskCompletionSourceT_TrySetException_NoExceptions,
- NotSupported_StringComparison,
- ConcurrentCollection_SyncRoot_NotSupported,
- Task_MultiTaskContinuation_NullTask,
- InvalidOperation_WrongAsyncResultOrEndCalledMultiple,
- Task_MultiTaskContinuation_EmptyTaskList,
- Task_Start_TaskCompleted,
- Task_Start_Promise,
- Task_Start_ContinuationTask,
- Task_Start_AlreadyStarted,
- Task_RunSynchronously_Continuation,
- Task_RunSynchronously_Promise,
- Task_RunSynchronously_TaskCompleted,
- Task_RunSynchronously_AlreadyStarted,
- AsyncMethodBuilder_InstanceNotInitialized,
- Task_ContinueWith_ESandLR,
- Task_ContinueWith_NotOnAnything,
- Task_Delay_InvalidDelay,
- Task_Delay_InvalidMillisecondsDelay,
- Task_Dispose_NotCompleted,
- Task_ThrowIfDisposed,
- Task_WaitMulti_NullTask,
- ArgumentException_OtherNotArrayOfCorrectLength,
- ArgumentNull_Array,
- ArgumentNull_SafeHandle,
- ArgumentOutOfRange_EndIndexStartIndex,
- ArgumentOutOfRange_Enum,
- ArgumentOutOfRange_HugeArrayNotSupported,
- Argument_AddingDuplicate,
- Argument_InvalidArgumentForComparison,
- Arg_LowerBoundsMustMatch,
- Arg_MustBeType,
- Arg_Need1DArray,
- Arg_Need2DArray,
- Arg_Need3DArray,
- Arg_NeedAtLeast1Rank,
- Arg_RankIndices,
- Arg_RanksAndBounds,
- InvalidOperation_IComparerFailed,
- NotSupported_FixedSizeCollection,
- Rank_MultiDimNotSupported,
- Arg_TypeNotSupported,
- Argument_SpansMustHaveSameLength,
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeSpan.cs b/netcore/System.Private.CoreLib/shared/System/TimeSpan.cs
deleted file mode 100644
index 5cbd473875e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TimeSpan.cs
+++ /dev/null
@@ -1,494 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- // TimeSpan represents a duration of time. A TimeSpan can be negative
- // or positive.
- //
- // TimeSpan is internally represented as a number of milliseconds. While
- // this maps well into units of time such as hours and days, any
- // periods longer than that aren't representable in a nice fashion.
- // For instance, a month can be between 28 and 31 days, while a year
- // can contain 365 or 364 days. A decade can have between 1 and 3 leapyears,
- // depending on when you map the TimeSpan into the calendar. This is why
- // we do not provide Years() or Months().
- //
- // Note: System.TimeSpan needs to interop with the WinRT structure
- // type Windows::Foundation:TimeSpan. These types are currently binary-compatible in
- // memory so no custom marshalling is required. If at any point the implementation
- // details of this type should change, or new fields added, we need to remember to add
- // an appropriate custom ILMarshaler to keep WInRT interop scenarios enabled.
- //
- [Serializable]
- public readonly struct TimeSpan : IComparable, IComparable<TimeSpan>, IEquatable<TimeSpan>, IFormattable, ISpanFormattable
- {
- public const long TicksPerMillisecond = 10000;
-
- public const long TicksPerSecond = TicksPerMillisecond * 1000; // 10,000,000
-
- public const long TicksPerMinute = TicksPerSecond * 60; // 600,000,000
-
- public const long TicksPerHour = TicksPerMinute * 60; // 36,000,000,000
-
- public const long TicksPerDay = TicksPerHour * 24; // 864,000,000,000
-
- internal const long MaxSeconds = long.MaxValue / TicksPerSecond;
- internal const long MinSeconds = long.MinValue / TicksPerSecond;
-
- internal const long MaxMilliSeconds = long.MaxValue / TicksPerMillisecond;
- internal const long MinMilliSeconds = long.MinValue / TicksPerMillisecond;
-
- internal const long TicksPerTenthSecond = TicksPerMillisecond * 100;
-
- public static readonly TimeSpan Zero = new TimeSpan(0);
-
- public static readonly TimeSpan MaxValue = new TimeSpan(long.MaxValue);
- public static readonly TimeSpan MinValue = new TimeSpan(long.MinValue);
-
- // internal so that DateTime doesn't have to call an extra get
- // method for some arithmetic operations.
- internal readonly long _ticks; // Do not rename (binary serialization)
-
- public TimeSpan(long ticks)
- {
- this._ticks = ticks;
- }
-
- public TimeSpan(int hours, int minutes, int seconds)
- {
- _ticks = TimeToTicks(hours, minutes, seconds);
- }
-
- public TimeSpan(int days, int hours, int minutes, int seconds)
- : this(days, hours, minutes, seconds, 0)
- {
- }
-
- public TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds)
- {
- long totalMilliSeconds = ((long)days * 3600 * 24 + (long)hours * 3600 + (long)minutes * 60 + seconds) * 1000 + milliseconds;
- if (totalMilliSeconds > MaxMilliSeconds || totalMilliSeconds < MinMilliSeconds)
- throw new ArgumentOutOfRangeException(null, SR.Overflow_TimeSpanTooLong);
- _ticks = (long)totalMilliSeconds * TicksPerMillisecond;
- }
-
- public long Ticks => _ticks;
-
- public int Days => (int)(_ticks / TicksPerDay);
-
- public int Hours => (int)((_ticks / TicksPerHour) % 24);
-
- public int Milliseconds => (int)((_ticks / TicksPerMillisecond) % 1000);
-
- public int Minutes => (int)((_ticks / TicksPerMinute) % 60);
-
- public int Seconds => (int)((_ticks / TicksPerSecond) % 60);
-
- public double TotalDays => ((double)_ticks) / TicksPerDay;
-
- public double TotalHours => (double)_ticks / TicksPerHour;
-
- public double TotalMilliseconds
- {
- get
- {
- double temp = (double)_ticks / TicksPerMillisecond;
- if (temp > MaxMilliSeconds)
- return (double)MaxMilliSeconds;
-
- if (temp < MinMilliSeconds)
- return (double)MinMilliSeconds;
-
- return temp;
- }
- }
-
- public double TotalMinutes => (double)_ticks / TicksPerMinute;
-
- public double TotalSeconds => (double)_ticks / TicksPerSecond;
-
- public TimeSpan Add(TimeSpan ts)
- {
- long result = _ticks + ts._ticks;
- // Overflow if signs of operands was identical and result's
- // sign was opposite.
- // >> 63 gives the sign bit (either 64 1's or 64 0's).
- if ((_ticks >> 63 == ts._ticks >> 63) && (_ticks >> 63 != result >> 63))
- throw new OverflowException(SR.Overflow_TimeSpanTooLong);
- return new TimeSpan(result);
- }
-
-
- // Compares two TimeSpan values, returning an integer that indicates their
- // relationship.
- //
- public static int Compare(TimeSpan t1, TimeSpan t2)
- {
- if (t1._ticks > t2._ticks) return 1;
- if (t1._ticks < t2._ticks) return -1;
- return 0;
- }
-
- // Returns a value less than zero if this object
- public int CompareTo(object? value)
- {
- if (value == null) return 1;
- if (!(value is TimeSpan))
- throw new ArgumentException(SR.Arg_MustBeTimeSpan);
- long t = ((TimeSpan)value)._ticks;
- if (_ticks > t) return 1;
- if (_ticks < t) return -1;
- return 0;
- }
-
- public int CompareTo(TimeSpan value)
- {
- long t = value._ticks;
- if (_ticks > t) return 1;
- if (_ticks < t) return -1;
- return 0;
- }
-
- public static TimeSpan FromDays(double value)
- {
- return Interval(value, TicksPerDay);
- }
-
- public TimeSpan Duration()
- {
- if (Ticks == TimeSpan.MinValue.Ticks)
- throw new OverflowException(SR.Overflow_Duration);
- return new TimeSpan(_ticks >= 0 ? _ticks : -_ticks);
- }
-
- public override bool Equals(object? value)
- {
- if (value is TimeSpan)
- {
- return _ticks == ((TimeSpan)value)._ticks;
- }
- return false;
- }
-
- public bool Equals(TimeSpan obj)
- {
- return _ticks == obj._ticks;
- }
-
- public static bool Equals(TimeSpan t1, TimeSpan t2)
- {
- return t1._ticks == t2._ticks;
- }
-
- public override int GetHashCode()
- {
- return (int)_ticks ^ (int)(_ticks >> 32);
- }
-
- public static TimeSpan FromHours(double value)
- {
- return Interval(value, TicksPerHour);
- }
-
- private static TimeSpan Interval(double value, double scale)
- {
- if (double.IsNaN(value))
- throw new ArgumentException(SR.Arg_CannotBeNaN);
- double ticks = value * scale;
- if ((ticks > long.MaxValue) || (ticks < long.MinValue))
- throw new OverflowException(SR.Overflow_TimeSpanTooLong);
- return new TimeSpan((long)ticks);
- }
-
- public static TimeSpan FromMilliseconds(double value)
- {
- return Interval(value, TicksPerMillisecond);
- }
-
- public static TimeSpan FromMinutes(double value)
- {
- return Interval(value, TicksPerMinute);
- }
-
- public TimeSpan Negate()
- {
- if (Ticks == TimeSpan.MinValue.Ticks)
- throw new OverflowException(SR.Overflow_NegateTwosCompNum);
- return new TimeSpan(-_ticks);
- }
-
- public static TimeSpan FromSeconds(double value)
- {
- return Interval(value, TicksPerSecond);
- }
-
- public TimeSpan Subtract(TimeSpan ts)
- {
- long result = _ticks - ts._ticks;
- // Overflow if signs of operands was different and result's
- // sign was opposite from the first argument's sign.
- // >> 63 gives the sign bit (either 64 1's or 64 0's).
- if ((_ticks >> 63 != ts._ticks >> 63) && (_ticks >> 63 != result >> 63))
- throw new OverflowException(SR.Overflow_TimeSpanTooLong);
- return new TimeSpan(result);
- }
-
- public TimeSpan Multiply(double factor) => this * factor;
-
- public TimeSpan Divide(double divisor) => this / divisor;
-
- public double Divide(TimeSpan ts) => this / ts;
-
- public static TimeSpan FromTicks(long value)
- {
- return new TimeSpan(value);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static long TimeToTicks(int hour, int minute, int second)
- {
- // totalSeconds is bounded by 2^31 * 2^12 + 2^31 * 2^8 + 2^31,
- // which is less than 2^44, meaning we won't overflow totalSeconds.
- long totalSeconds = (long)hour * 3600 + (long)minute * 60 + (long)second;
- if (totalSeconds > MaxSeconds || totalSeconds < MinSeconds)
- ThrowHelper.ThrowArgumentOutOfRange_TimeSpanTooLong();
- return totalSeconds * TicksPerSecond;
- }
-
- // See System.Globalization.TimeSpanParse and System.Globalization.TimeSpanFormat
- #region ParseAndFormat
- private static void ValidateStyles(TimeSpanStyles style, string parameterName)
- {
- if (style != TimeSpanStyles.None && style != TimeSpanStyles.AssumeNegative)
- throw new ArgumentException(SR.Argument_InvalidTimeSpanStyles, parameterName);
- }
- public static TimeSpan Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
- /* Constructs a TimeSpan from a string. Leading and trailing white space characters are allowed. */
- return TimeSpanParse.Parse(s, null);
- }
- public static TimeSpan Parse(string input, IFormatProvider? formatProvider)
- {
- if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
- return TimeSpanParse.Parse(input, formatProvider);
- }
- public static TimeSpan Parse(ReadOnlySpan<char> input, IFormatProvider? formatProvider = null)
- {
- return TimeSpanParse.Parse(input, formatProvider);
- }
- public static TimeSpan ParseExact(string input, string format, IFormatProvider? formatProvider)
- {
- if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
- if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format);
- return TimeSpanParse.ParseExact(input, format, formatProvider, TimeSpanStyles.None);
- }
- public static TimeSpan ParseExact(string input, string[] formats, IFormatProvider? formatProvider)
- {
- if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
- return TimeSpanParse.ParseExactMultiple(input, formats, formatProvider, TimeSpanStyles.None);
- }
- public static TimeSpan ParseExact(string input, string format, IFormatProvider? formatProvider, TimeSpanStyles styles)
- {
- ValidateStyles(styles, nameof(styles));
- if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
- if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format);
- return TimeSpanParse.ParseExact(input, format, formatProvider, styles);
- }
-
- public static TimeSpan ParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, TimeSpanStyles styles = TimeSpanStyles.None)
- {
- ValidateStyles(styles, nameof(styles));
- return TimeSpanParse.ParseExact(input, format, formatProvider, styles);
- }
- public static TimeSpan ParseExact(string input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles)
- {
- ValidateStyles(styles, nameof(styles));
- if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
- return TimeSpanParse.ParseExactMultiple(input, formats, formatProvider, styles);
- }
- public static TimeSpan ParseExact(ReadOnlySpan<char> input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles = TimeSpanStyles.None)
- {
- ValidateStyles(styles, nameof(styles));
- return TimeSpanParse.ParseExactMultiple(input, formats, formatProvider, styles);
- }
- public static bool TryParse(string? s, out TimeSpan result)
- {
- if (s == null)
- {
- result = default;
- return false;
- }
- return TimeSpanParse.TryParse(s, null, out result);
- }
- public static bool TryParse(ReadOnlySpan<char> s, out TimeSpan result)
- {
- return TimeSpanParse.TryParse(s, null, out result);
- }
-
- public static bool TryParse(string? input, IFormatProvider? formatProvider, out TimeSpan result)
- {
- if (input == null)
- {
- result = default;
- return false;
- }
- return TimeSpanParse.TryParse(input, formatProvider, out result);
- }
- public static bool TryParse(ReadOnlySpan<char> input, IFormatProvider? formatProvider, out TimeSpan result)
- {
- return TimeSpanParse.TryParse(input, formatProvider, out result);
- }
- public static bool TryParseExact(string? input, string format, IFormatProvider? formatProvider, out TimeSpan result)
- {
- if (input == null || format == null)
- {
- result = default;
- return false;
- }
- return TimeSpanParse.TryParseExact(input, format, formatProvider, TimeSpanStyles.None, out result);
- }
-
- public static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, out TimeSpan result)
- {
- return TimeSpanParse.TryParseExact(input, format, formatProvider, TimeSpanStyles.None, out result);
- }
- public static bool TryParseExact(string? input, string[] formats, IFormatProvider? formatProvider, out TimeSpan result)
- {
- if (input == null)
- {
- result = default;
- return false;
- }
- return TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, TimeSpanStyles.None, out result);
- }
- public static bool TryParseExact(ReadOnlySpan<char> input, string[] formats, IFormatProvider? formatProvider, out TimeSpan result)
- {
- return TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, TimeSpanStyles.None, out result);
- }
-
- public static bool TryParseExact(string? input, string format, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result)
- {
- ValidateStyles(styles, nameof(styles));
- if (input == null || format == null)
- {
- result = default;
- return false;
- }
-
- return TimeSpanParse.TryParseExact(input, format, formatProvider, styles, out result);
- }
-
- public static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result)
- {
- ValidateStyles(styles, nameof(styles));
- return TimeSpanParse.TryParseExact(input, format, formatProvider, styles, out result);
- }
- public static bool TryParseExact(string? input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result)
- {
- ValidateStyles(styles, nameof(styles));
- if (input == null)
- {
- result = default;
- return false;
- }
- return TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, styles, out result);
- }
-
- public static bool TryParseExact(ReadOnlySpan<char> input, string[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result)
- {
- ValidateStyles(styles, nameof(styles));
- return TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, styles, out result);
- }
- public override string ToString()
- {
- return TimeSpanFormat.FormatC(this);
- }
- public string ToString(string? format)
- {
- return TimeSpanFormat.Format(this, format, null);
- }
- public string ToString(string? format, IFormatProvider? formatProvider)
- {
- return TimeSpanFormat.Format(this, format, formatProvider);
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? formatProvider = null)
- {
- return TimeSpanFormat.TryFormat(this, destination, out charsWritten, format, formatProvider);
- }
- #endregion
-
- public static TimeSpan operator -(TimeSpan t)
- {
- if (t._ticks == TimeSpan.MinValue._ticks)
- throw new OverflowException(SR.Overflow_NegateTwosCompNum);
- return new TimeSpan(-t._ticks);
- }
-
- public static TimeSpan operator -(TimeSpan t1, TimeSpan t2) => t1.Subtract(t2);
-
- public static TimeSpan operator +(TimeSpan t) => t;
-
- public static TimeSpan operator +(TimeSpan t1, TimeSpan t2) => t1.Add(t2);
-
- public static TimeSpan operator *(TimeSpan timeSpan, double factor)
- {
- if (double.IsNaN(factor))
- {
- throw new ArgumentException(SR.Arg_CannotBeNaN, nameof(factor));
- }
-
- // Rounding to the nearest tick is as close to the result we would have with unlimited
- // precision as possible, and so likely to have the least potential to surprise.
- double ticks = Math.Round(timeSpan.Ticks * factor);
- if (ticks > long.MaxValue || ticks < long.MinValue)
- {
- throw new OverflowException(SR.Overflow_TimeSpanTooLong);
- }
-
- return FromTicks((long)ticks);
- }
-
- public static TimeSpan operator *(double factor, TimeSpan timeSpan) => timeSpan * factor;
-
- public static TimeSpan operator /(TimeSpan timeSpan, double divisor)
- {
- if (double.IsNaN(divisor))
- {
- throw new ArgumentException(SR.Arg_CannotBeNaN, nameof(divisor));
- }
-
- double ticks = Math.Round(timeSpan.Ticks / divisor);
- if (ticks > long.MaxValue || ticks < long.MinValue || double.IsNaN(ticks))
- {
- throw new OverflowException(SR.Overflow_TimeSpanTooLong);
- }
-
- return FromTicks((long)ticks);
- }
-
- // Using floating-point arithmetic directly means that infinities can be returned, which is reasonable
- // if we consider TimeSpan.FromHours(1) / TimeSpan.Zero asks how many zero-second intervals there are in
- // an hour for which infinity is the mathematic correct answer. Having TimeSpan.Zero / TimeSpan.Zero return NaN
- // is perhaps less useful, but no less useful than an exception.
- public static double operator /(TimeSpan t1, TimeSpan t2) => t1.Ticks / (double)t2.Ticks;
-
- public static bool operator ==(TimeSpan t1, TimeSpan t2) => t1._ticks == t2._ticks;
-
- public static bool operator !=(TimeSpan t1, TimeSpan t2) => t1._ticks != t2._ticks;
-
- public static bool operator <(TimeSpan t1, TimeSpan t2) => t1._ticks < t2._ticks;
-
- public static bool operator <=(TimeSpan t1, TimeSpan t2) => t1._ticks <= t2._ticks;
-
- public static bool operator >(TimeSpan t1, TimeSpan t2) => t1._ticks > t2._ticks;
-
- public static bool operator >=(TimeSpan t1, TimeSpan t2) => t1._ticks >= t2._ticks;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZone.cs b/netcore/System.Private.CoreLib/shared/System/TimeZone.cs
deleted file mode 100644
index a1a5df6bb5f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TimeZone.cs
+++ /dev/null
@@ -1,274 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose:
-** This class is used to represent a TimeZone. It
-** has methods for converting a DateTime to UTC from local time
-** and to local time from UTC and methods for getting the
-** standard name and daylight name of the time zone.
-**
-** The only TimeZone that we support in version 1 is the
-** CurrentTimeZone as determined by the system timezone.
-**
-**
-============================================================*/
-
-using System.Threading;
-using System.Globalization;
-
-namespace System
-{
- [Obsolete("System.TimeZone has been deprecated. Please investigate the use of System.TimeZoneInfo instead.")]
- public abstract class TimeZone
- {
- private static volatile TimeZone? currentTimeZone = null;
-
- // Private object for locking instead of locking on a public type for SQL reliability work.
- private static object? s_InternalSyncObject;
- private static object InternalSyncObject
- {
- get
- {
- if (s_InternalSyncObject == null)
- {
- object o = new object();
- Interlocked.CompareExchange<object?>(ref s_InternalSyncObject, o, null);
- }
- return s_InternalSyncObject;
- }
- }
-
- protected TimeZone()
- {
- }
-
- public static TimeZone CurrentTimeZone
- {
- get
- {
- // Grabbing the cached value is required at the top of this function so that
- // we don't incur a race condition with the ResetTimeZone method below.
- TimeZone? tz = currentTimeZone;
- if (tz == null)
- {
- lock (InternalSyncObject)
- {
- currentTimeZone ??= new CurrentSystemTimeZone();
- tz = currentTimeZone;
- }
- }
-
- return tz;
- }
- }
-
- // This method is called by CultureInfo.ClearCachedData in response to control panel
- // change events. It must be synchronized because otherwise there is a race condition
- // with the CurrentTimeZone property above.
- internal static void ResetTimeZone()
- {
- if (currentTimeZone != null)
- {
- lock (InternalSyncObject)
- {
- currentTimeZone = null;
- }
- }
- }
-
- public abstract string StandardName
- {
- get;
- }
-
- public abstract string DaylightName
- {
- get;
- }
-
- public abstract TimeSpan GetUtcOffset(DateTime time);
-
- //
- // Converts the specified datatime to the Universal time base on the current timezone
- //
- public virtual DateTime ToUniversalTime(DateTime time)
- {
- if (time.Kind == DateTimeKind.Utc)
- {
- return time;
- }
- long tickCount = time.Ticks - GetUtcOffset(time).Ticks;
- if (tickCount > DateTime.MaxTicks)
- {
- return new DateTime(DateTime.MaxTicks, DateTimeKind.Utc);
- }
- if (tickCount < DateTime.MinTicks)
- {
- return new DateTime(DateTime.MinTicks, DateTimeKind.Utc);
- }
- return new DateTime(tickCount, DateTimeKind.Utc);
- }
-
- //
- // Convert the specified datetime value from UTC to the local time based on the time zone.
- //
- public virtual DateTime ToLocalTime(DateTime time)
- {
- if (time.Kind == DateTimeKind.Local)
- {
- return time;
- }
- bool isAmbiguousLocalDst = false;
- long offset = ((CurrentSystemTimeZone)(TimeZone.CurrentTimeZone)).GetUtcOffsetFromUniversalTime(time, ref isAmbiguousLocalDst);
- return new DateTime(time.Ticks + offset, DateTimeKind.Local, isAmbiguousLocalDst);
- }
-
- // Return an array of DaylightTime which reflects the daylight saving periods in a particular year.
- // We currently only support having one DaylightSavingTime per year.
- // If daylight saving time is not used in this timezone, null will be returned.
- public abstract DaylightTime GetDaylightChanges(int year);
-
- public virtual bool IsDaylightSavingTime(DateTime time)
- {
- return IsDaylightSavingTime(time, GetDaylightChanges(time.Year));
- }
-
- // Check if the specified time is in a daylight saving time. Allows the user to
- // specify the array of Daylight Saving Times.
- public static bool IsDaylightSavingTime(DateTime time, DaylightTime daylightTimes)
- {
- return CalculateUtcOffset(time, daylightTimes) != TimeSpan.Zero;
- }
-
- //
- // NOTENOTE: Implementation detail
- // In the transition from standard time to daylight saving time,
- // if we convert local time to Universal time, we can have the
- // following (take PST as an example):
- // Local Universal UTC Offset
- // ----- --------- ----------
- // 01:00AM 09:00 -8:00
- // 02:00 (=> 03:00) 10:00 -8:00 [This time doesn't actually exist, but it can be created from DateTime]
- // 03:00 10:00 -7:00
- // 04:00 11:00 -7:00
- // 05:00 12:00 -7:00
- //
- // So from 02:00 - 02:59:59, we should return the standard offset, instead of the daylight saving offset.
- //
- // In the transition from daylight saving time to standard time,
- // if we convert local time to Universal time, we can have the
- // following (take PST as an example):
- // Local Universal UTC Offset
- // ----- --------- ----------
- // 01:00AM 08:00 -7:00
- // 02:00 (=> 01:00) 09:00 -8:00
- // 02:00 10:00 -8:00
- // 03:00 11:00 -8:00
- // 04:00 12:00 -8:00
- //
- // So in this case, the 02:00 does exist after the first 2:00 rolls back to 01:00. We don't need to special case this.
- // But note that there are two 01:00 in the local time.
-
- //
- // And imagine if the daylight saving offset is negative (although this does not exist in real life)
- // In the transition from standard time to daylight saving time,
- // if we convert local time to Universal time, we can have the
- // following (take PST as an example, but the daylight saving offset is -01:00):
- // Local Universal UTC Offset
- // ----- --------- ----------
- // 01:00AM 09:00 -8:00
- // 02:00 (=> 01:00) 10:00 -9:00
- // 02:00 11:00 -9:00
- // 03:00 12:00 -9:00
- // 04:00 13:00 -9:00
- // 05:00 14:00 -9:00
- //
- // So in this case, the 02:00 does exist after the first 2:00 rolls back to 01:00. We don't need to special case this.
- //
- // In the transition from daylight saving time to standard time,
- // if we convert local time to Universal time, we can have the
- // following (take PST as an example, daylight saving offset is -01:00):
- //
- // Local Universal UTC Offset
- // ----- --------- ----------
- // 01:00AM 10:00 -9:00
- // 02:00 (=> 03:00) 11:00 -9:00
- // 03:00 11:00 -8:00
- // 04:00 12:00 -8:00
- // 05:00 13:00 -8:00
- // 06:00 14:00 -8:00
- //
- // So from 02:00 - 02:59:59, we should return the daylight saving offset, instead of the standard offset.
- //
- internal static TimeSpan CalculateUtcOffset(DateTime time, DaylightTime daylightTimes)
- {
- if (daylightTimes == null)
- {
- return TimeSpan.Zero;
- }
- DateTimeKind kind = time.Kind;
- if (kind == DateTimeKind.Utc)
- {
- return TimeSpan.Zero;
- }
-
- DateTime startTime;
- DateTime endTime;
-
- // startTime and endTime represent the period from either the start of DST to the end and includes the
- // potentially overlapped times
- startTime = daylightTimes.Start + daylightTimes.Delta;
- endTime = daylightTimes.End;
-
- // For normal time zones, the ambiguous hour is the last hour of daylight saving when you wind the
- // clock back. It is theoretically possible to have a positive delta, (which would really be daylight
- // reduction time), where you would have to wind the clock back in the begnning.
- DateTime ambiguousStart;
- DateTime ambiguousEnd;
- if (daylightTimes.Delta.Ticks > 0)
- {
- ambiguousStart = endTime - daylightTimes.Delta;
- ambiguousEnd = endTime;
- }
- else
- {
- ambiguousStart = startTime;
- ambiguousEnd = startTime - daylightTimes.Delta;
- }
-
- bool isDst = false;
- if (startTime > endTime)
- {
- // In southern hemisphere, the daylight saving time starts later in the year, and ends in the beginning of next year.
- // Note, the summer in the southern hemisphere begins late in the year.
- if (time >= startTime || time < endTime)
- {
- isDst = true;
- }
- }
- else if (time >= startTime && time < endTime)
- {
- // In northern hemisphere, the daylight saving time starts in the middle of the year.
- isDst = true;
- }
-
- // If this date was previously converted from a UTC date and we were able to detect that the local
- // DateTime would be ambiguous, this data is stored in the DateTime to resolve this ambiguity.
- if (isDst && time >= ambiguousStart && time < ambiguousEnd)
- {
- isDst = time.IsAmbiguousDaylightSavingTime();
- }
-
- if (isDst)
- {
- return daylightTimes.Delta;
- }
- return TimeSpan.Zero;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.AdjustmentRule.cs b/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.AdjustmentRule.cs
deleted file mode 100644
index a698a68207a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.AdjustmentRule.cs
+++ /dev/null
@@ -1,275 +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 System.Runtime.Serialization;
-
-namespace System
-{
- public sealed partial class TimeZoneInfo
- {
- [Serializable]
- public sealed class AdjustmentRule :
-#nullable disable // see comment on String
- IEquatable<AdjustmentRule>,
-#nullable restore
- ISerializable, IDeserializationCallback
- {
- private static readonly TimeSpan DaylightDeltaAdjustment = TimeSpan.FromHours(24.0);
- private static readonly TimeSpan MaxDaylightDelta = TimeSpan.FromHours(12.0);
- private readonly DateTime _dateStart;
- private readonly DateTime _dateEnd;
- private readonly TimeSpan _daylightDelta;
- private readonly TransitionTime _daylightTransitionStart;
- private readonly TransitionTime _daylightTransitionEnd;
- private readonly TimeSpan _baseUtcOffsetDelta; // delta from the default Utc offset (utcOffset = defaultUtcOffset + _baseUtcOffsetDelta)
- private readonly bool _noDaylightTransitions;
-
- public DateTime DateStart => _dateStart;
-
- public DateTime DateEnd => _dateEnd;
-
- public TimeSpan DaylightDelta => _daylightDelta;
-
- public TransitionTime DaylightTransitionStart => _daylightTransitionStart;
-
- public TransitionTime DaylightTransitionEnd => _daylightTransitionEnd;
-
- internal TimeSpan BaseUtcOffsetDelta => _baseUtcOffsetDelta;
-
- /// <summary>
- /// Gets a value indicating that this AdjustmentRule fixes the time zone offset
- /// from DateStart to DateEnd without any daylight transitions in between.
- /// </summary>
- internal bool NoDaylightTransitions => _noDaylightTransitions;
-
- internal bool HasDaylightSaving =>
- DaylightDelta != TimeSpan.Zero ||
- (DaylightTransitionStart != default && DaylightTransitionStart.TimeOfDay != DateTime.MinValue) ||
- (DaylightTransitionEnd != default && DaylightTransitionEnd.TimeOfDay != DateTime.MinValue.AddMilliseconds(1));
-
- public bool Equals(AdjustmentRule? other) =>
- other != null &&
- _dateStart == other._dateStart &&
- _dateEnd == other._dateEnd &&
- _daylightDelta == other._daylightDelta &&
- _baseUtcOffsetDelta == other._baseUtcOffsetDelta &&
- _daylightTransitionEnd.Equals(other._daylightTransitionEnd) &&
- _daylightTransitionStart.Equals(other._daylightTransitionStart);
-
- public override int GetHashCode() => _dateStart.GetHashCode();
-
- private AdjustmentRule(
- DateTime dateStart,
- DateTime dateEnd,
- TimeSpan daylightDelta,
- TransitionTime daylightTransitionStart,
- TransitionTime daylightTransitionEnd,
- TimeSpan baseUtcOffsetDelta,
- bool noDaylightTransitions)
- {
- ValidateAdjustmentRule(dateStart, dateEnd, daylightDelta,
- daylightTransitionStart, daylightTransitionEnd, noDaylightTransitions);
-
- _dateStart = dateStart;
- _dateEnd = dateEnd;
- _daylightDelta = daylightDelta;
- _daylightTransitionStart = daylightTransitionStart;
- _daylightTransitionEnd = daylightTransitionEnd;
- _baseUtcOffsetDelta = baseUtcOffsetDelta;
- _noDaylightTransitions = noDaylightTransitions;
- }
-
- public static AdjustmentRule CreateAdjustmentRule(
- DateTime dateStart,
- DateTime dateEnd,
- TimeSpan daylightDelta,
- TransitionTime daylightTransitionStart,
- TransitionTime daylightTransitionEnd)
- {
- return new AdjustmentRule(
- dateStart,
- dateEnd,
- daylightDelta,
- daylightTransitionStart,
- daylightTransitionEnd,
- baseUtcOffsetDelta: TimeSpan.Zero,
- noDaylightTransitions: false);
- }
-
- internal static AdjustmentRule CreateAdjustmentRule(
- DateTime dateStart,
- DateTime dateEnd,
- TimeSpan daylightDelta,
- TransitionTime daylightTransitionStart,
- TransitionTime daylightTransitionEnd,
- TimeSpan baseUtcOffsetDelta,
- bool noDaylightTransitions)
- {
- AdjustDaylightDeltaToExpectedRange(ref daylightDelta, ref baseUtcOffsetDelta);
- return new AdjustmentRule(
- dateStart,
- dateEnd,
- daylightDelta,
- daylightTransitionStart,
- daylightTransitionEnd,
- baseUtcOffsetDelta,
- noDaylightTransitions);
- }
-
- //
- // When Windows sets the daylight transition start Jan 1st at 12:00 AM, it means the year starts with the daylight saving on.
- // We have to special case this value and not adjust it when checking if any date is in the daylight saving period.
- //
- internal bool IsStartDateMarkerForBeginningOfYear() =>
- !NoDaylightTransitions &&
- DaylightTransitionStart.Month == 1 && DaylightTransitionStart.Day == 1 && DaylightTransitionStart.TimeOfDay.Hour == 0 &&
- DaylightTransitionStart.TimeOfDay.Minute == 0 && DaylightTransitionStart.TimeOfDay.Second == 0 &&
- _dateStart.Year == _dateEnd.Year;
-
- //
- // When Windows sets the daylight transition end Jan 1st at 12:00 AM, it means the year ends with the daylight saving on.
- // We have to special case this value and not adjust it when checking if any date is in the daylight saving period.
- //
- internal bool IsEndDateMarkerForEndOfYear() =>
- !NoDaylightTransitions &&
- DaylightTransitionEnd.Month == 1 && DaylightTransitionEnd.Day == 1 && DaylightTransitionEnd.TimeOfDay.Hour == 0 &&
- DaylightTransitionEnd.TimeOfDay.Minute == 0 && DaylightTransitionEnd.TimeOfDay.Second == 0 &&
- _dateStart.Year == _dateEnd.Year;
-
- /// <summary>
- /// Helper function that performs all of the validation checks for the factory methods and deserialization callback.
- /// </summary>
- private static void ValidateAdjustmentRule(
- DateTime dateStart,
- DateTime dateEnd,
- TimeSpan daylightDelta,
- TransitionTime daylightTransitionStart,
- TransitionTime daylightTransitionEnd,
- bool noDaylightTransitions)
- {
- if (dateStart.Kind != DateTimeKind.Unspecified && dateStart.Kind != DateTimeKind.Utc)
- {
- throw new ArgumentException(SR.Argument_DateTimeKindMustBeUnspecifiedOrUtc, nameof(dateStart));
- }
-
- if (dateEnd.Kind != DateTimeKind.Unspecified && dateEnd.Kind != DateTimeKind.Utc)
- {
- throw new ArgumentException(SR.Argument_DateTimeKindMustBeUnspecifiedOrUtc, nameof(dateEnd));
- }
-
- if (daylightTransitionStart.Equals(daylightTransitionEnd) && !noDaylightTransitions)
- {
- throw new ArgumentException(SR.Argument_TransitionTimesAreIdentical, nameof(daylightTransitionEnd));
- }
-
- if (dateStart > dateEnd)
- {
- throw new ArgumentException(SR.Argument_OutOfOrderDateTimes, nameof(dateStart));
- }
-
- // This cannot use UtcOffsetOutOfRange to account for the scenario where Samoa moved across the International Date Line,
- // which caused their current BaseUtcOffset to be +13. But on the other side of the line it was UTC-11 (+1 for daylight).
- // So when trying to describe DaylightDeltas for those times, the DaylightDelta needs
- // to be -23 (what it takes to go from UTC+13 to UTC-10)
- if (daylightDelta.TotalHours < -23.0 || daylightDelta.TotalHours > 14.0)
- {
- throw new ArgumentOutOfRangeException(nameof(daylightDelta), daylightDelta, SR.ArgumentOutOfRange_UtcOffset);
- }
-
- if (daylightDelta.Ticks % TimeSpan.TicksPerMinute != 0)
- {
- throw new ArgumentException(SR.Argument_TimeSpanHasSeconds, nameof(daylightDelta));
- }
-
- if (dateStart != DateTime.MinValue && dateStart.Kind == DateTimeKind.Unspecified && dateStart.TimeOfDay != TimeSpan.Zero)
- {
- throw new ArgumentException(SR.Argument_DateTimeHasTimeOfDay, nameof(dateStart));
- }
-
- if (dateEnd != DateTime.MaxValue && dateEnd.Kind == DateTimeKind.Unspecified && dateEnd.TimeOfDay != TimeSpan.Zero)
- {
- throw new ArgumentException(SR.Argument_DateTimeHasTimeOfDay, nameof(dateEnd));
- }
- }
-
- /// <summary>
- /// Ensures the daylight delta is within [-12, 12] hours
- /// </summary>>
- private static void AdjustDaylightDeltaToExpectedRange(ref TimeSpan daylightDelta, ref TimeSpan baseUtcOffsetDelta)
- {
- if (daylightDelta > MaxDaylightDelta)
- {
- daylightDelta -= DaylightDeltaAdjustment;
- baseUtcOffsetDelta += DaylightDeltaAdjustment;
- }
- else if (daylightDelta < -MaxDaylightDelta)
- {
- daylightDelta += DaylightDeltaAdjustment;
- baseUtcOffsetDelta -= DaylightDeltaAdjustment;
- }
-
- System.Diagnostics.Debug.Assert(daylightDelta <= MaxDaylightDelta && daylightDelta >= -MaxDaylightDelta,
- "DaylightDelta should not ever be more than 24h");
- }
-
- void IDeserializationCallback.OnDeserialization(object? sender)
- {
- // OnDeserialization is called after each instance of this class is deserialized.
- // This callback method performs AdjustmentRule validation after being deserialized.
-
- try
- {
- ValidateAdjustmentRule(_dateStart, _dateEnd, _daylightDelta,
- _daylightTransitionStart, _daylightTransitionEnd, _noDaylightTransitions);
- }
- catch (ArgumentException e)
- {
- throw new SerializationException(SR.Serialization_InvalidData, e);
- }
- }
-
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- info.AddValue("DateStart", _dateStart); // Do not rename (binary serialization)
- info.AddValue("DateEnd", _dateEnd); // Do not rename (binary serialization)
- info.AddValue("DaylightDelta", _daylightDelta); // Do not rename (binary serialization)
- info.AddValue("DaylightTransitionStart", _daylightTransitionStart); // Do not rename (binary serialization)
- info.AddValue("DaylightTransitionEnd", _daylightTransitionEnd); // Do not rename (binary serialization)
- info.AddValue("BaseUtcOffsetDelta", _baseUtcOffsetDelta); // Do not rename (binary serialization)
- info.AddValue("NoDaylightTransitions", _noDaylightTransitions); // Do not rename (binary serialization)
- }
-
- private AdjustmentRule(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- _dateStart = (DateTime)info.GetValue("DateStart", typeof(DateTime))!; // Do not rename (binary serialization)
- _dateEnd = (DateTime)info.GetValue("DateEnd", typeof(DateTime))!; // Do not rename (binary serialization)
- _daylightDelta = (TimeSpan)info.GetValue("DaylightDelta", typeof(TimeSpan))!; // Do not rename (binary serialization)
- _daylightTransitionStart = (TransitionTime)info.GetValue("DaylightTransitionStart", typeof(TransitionTime))!; // Do not rename (binary serialization)
- _daylightTransitionEnd = (TransitionTime)info.GetValue("DaylightTransitionEnd", typeof(TransitionTime))!; // Do not rename (binary serialization)
-
- object? o = info.GetValueNoThrow("BaseUtcOffsetDelta", typeof(TimeSpan)); // Do not rename (binary serialization)
- if (o != null)
- {
- _baseUtcOffsetDelta = (TimeSpan)o;
- }
-
- o = info.GetValueNoThrow("NoDaylightTransitions", typeof(bool)); // Do not rename (binary serialization)
- if (o != null)
- {
- _noDaylightTransitions = (bool)o;
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.StringSerializer.cs b/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.StringSerializer.cs
deleted file mode 100644
index feea5de3f17..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.StringSerializer.cs
+++ /dev/null
@@ -1,625 +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 System.Collections.Generic;
-using System.Globalization;
-using System.Runtime.Serialization;
-using System.Text;
-
-namespace System
-{
- public sealed partial class TimeZoneInfo
- {
- /// <summary>
- /// Used to serialize and deserialize TimeZoneInfo objects based on the custom string serialization format.
- /// </summary>
- private struct StringSerializer
- {
- private enum State
- {
- Escaped = 0,
- NotEscaped = 1,
- StartOfToken = 2,
- EndOfLine = 3
- }
-
- private readonly string _serializedText;
- private int _currentTokenStartIndex;
- private State _state;
-
- // the majority of the strings contained in the OS time zones fit in 64 chars
- private const int InitialCapacityForString = 64;
- private const char Esc = '\\';
- private const char Sep = ';';
- private const char Lhs = '[';
- private const char Rhs = ']';
- private const string DateTimeFormat = "MM:dd:yyyy";
- private const string TimeOfDayFormat = "HH:mm:ss.FFF";
-
- /// <summary>
- /// Creates the custom serialized string representation of a TimeZoneInfo instance.
- /// </summary>
- public static string GetSerializedString(TimeZoneInfo zone)
- {
- var serializedText = new ValueStringBuilder(stackalloc char[InitialCapacityForString]);
-
- //
- // <_id>;<_baseUtcOffset>;<_displayName>;<_standardDisplayName>;<_daylightDispayName>
- //
- SerializeSubstitute(zone.Id, ref serializedText);
- serializedText.Append(Sep);
- serializedText.AppendSpanFormattable(zone.BaseUtcOffset.TotalMinutes, format: default, CultureInfo.InvariantCulture);
- serializedText.Append(Sep);
- SerializeSubstitute(zone.DisplayName, ref serializedText);
- serializedText.Append(Sep);
- SerializeSubstitute(zone.StandardName, ref serializedText);
- serializedText.Append(Sep);
- SerializeSubstitute(zone.DaylightName, ref serializedText);
- serializedText.Append(Sep);
-
- AdjustmentRule[] rules = zone.GetAdjustmentRules();
- foreach (AdjustmentRule rule in rules)
- {
- serializedText.Append(Lhs);
- serializedText.AppendSpanFormattable(rule.DateStart, DateTimeFormat, DateTimeFormatInfo.InvariantInfo);
- serializedText.Append(Sep);
- serializedText.AppendSpanFormattable(rule.DateEnd, DateTimeFormat, DateTimeFormatInfo.InvariantInfo);
- serializedText.Append(Sep);
- serializedText.AppendSpanFormattable(rule.DaylightDelta.TotalMinutes, format: default, CultureInfo.InvariantCulture);
- serializedText.Append(Sep);
- // serialize the TransitionTime's
- SerializeTransitionTime(rule.DaylightTransitionStart, ref serializedText);
- serializedText.Append(Sep);
- SerializeTransitionTime(rule.DaylightTransitionEnd, ref serializedText);
- serializedText.Append(Sep);
- if (rule.BaseUtcOffsetDelta != TimeSpan.Zero)
- {
- // Serialize it only when BaseUtcOffsetDelta has a value to reduce the impact of adding rule.BaseUtcOffsetDelta
- serializedText.AppendSpanFormattable(rule.BaseUtcOffsetDelta.TotalMinutes, format: default, CultureInfo.InvariantCulture);
- serializedText.Append(Sep);
- }
- if (rule.NoDaylightTransitions)
- {
- // Serialize it only when NoDaylightTransitions is true to reduce the impact of adding rule.NoDaylightTransitions
- serializedText.Append('1');
- serializedText.Append(Sep);
- }
- serializedText.Append(Rhs);
- }
- serializedText.Append(Sep);
-
- return serializedText.ToString();
- }
-
- /// <summary>
- /// Instantiates a TimeZoneInfo from a custom serialized string.
- /// </summary>
- public static TimeZoneInfo GetDeserializedTimeZoneInfo(string source)
- {
- StringSerializer s = new StringSerializer(source);
-
- string id = s.GetNextStringValue();
- TimeSpan baseUtcOffset = s.GetNextTimeSpanValue();
- string displayName = s.GetNextStringValue();
- string standardName = s.GetNextStringValue();
- string daylightName = s.GetNextStringValue();
- AdjustmentRule[]? rules = s.GetNextAdjustmentRuleArrayValue();
-
- try
- {
- return new TimeZoneInfo(id, baseUtcOffset, displayName, standardName, daylightName, rules, disableDaylightSavingTime: false);
- }
- catch (ArgumentException ex)
- {
- throw new SerializationException(SR.Serialization_InvalidData, ex);
- }
- catch (InvalidTimeZoneException ex)
- {
- throw new SerializationException(SR.Serialization_InvalidData, ex);
- }
- }
-
- private StringSerializer(string str)
- {
- _serializedText = str;
- _currentTokenStartIndex = 0;
- _state = State.StartOfToken;
- }
-
- /// <summary>
- /// Appends the String to the StringBuilder with all of the reserved chars escaped.
- ///
- /// ";" -> "\;"
- /// "[" -> "\["
- /// "]" -> "\]"
- /// "\" -> "\\"
- /// </summary>
- private static void SerializeSubstitute(string text, ref ValueStringBuilder serializedText)
- {
- foreach (char c in text)
- {
- if (c == Esc || c == Lhs || c == Rhs || c == Sep)
- {
- serializedText.Append('\\');
- }
- serializedText.Append(c);
- }
- }
-
- /// <summary>
- /// Helper method to serialize a TimeZoneInfo.TransitionTime object.
- /// </summary>
- private static void SerializeTransitionTime(TransitionTime time, ref ValueStringBuilder serializedText)
- {
- serializedText.Append(Lhs);
- serializedText.Append(time.IsFixedDateRule ? '1' : '0');
- serializedText.Append(Sep);
- serializedText.AppendSpanFormattable(time.TimeOfDay, TimeOfDayFormat, DateTimeFormatInfo.InvariantInfo);
- serializedText.Append(Sep);
- serializedText.AppendSpanFormattable(time.Month, format: default, CultureInfo.InvariantCulture);
- serializedText.Append(Sep);
- if (time.IsFixedDateRule)
- {
- serializedText.AppendSpanFormattable(time.Day, format: default, CultureInfo.InvariantCulture);
- serializedText.Append(Sep);
- }
- else
- {
- serializedText.AppendSpanFormattable(time.Week, format: default, CultureInfo.InvariantCulture);
- serializedText.Append(Sep);
- serializedText.AppendSpanFormattable((int)time.DayOfWeek, format: default, CultureInfo.InvariantCulture);
- serializedText.Append(Sep);
- }
- serializedText.Append(Rhs);
- }
-
- /// <summary>
- /// Helper function to determine if the passed in string token is allowed to be preceded by an escape sequence token.
- /// </summary>
- private static void VerifyIsEscapableCharacter(char c)
- {
- if (c != Esc && c != Sep && c != Lhs && c != Rhs)
- {
- throw new SerializationException(SR.Format(SR.Serialization_InvalidEscapeSequence, c));
- }
- }
-
- /// <summary>
- /// Helper function that reads past "v.Next" data fields. Receives a "depth" parameter indicating the
- /// current relative nested bracket depth that _currentTokenStartIndex is at. The function ends
- /// successfully when "depth" returns to zero (0).
- /// </summary>
- private void SkipVersionNextDataFields(int depth /* starting depth in the nested brackets ('[', ']')*/)
- {
- if (_currentTokenStartIndex < 0 || _currentTokenStartIndex >= _serializedText.Length)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
- State tokenState = State.NotEscaped;
-
- // walk the serialized text, building up the token as we go...
- for (int i = _currentTokenStartIndex; i < _serializedText.Length; i++)
- {
- if (tokenState == State.Escaped)
- {
- VerifyIsEscapableCharacter(_serializedText[i]);
- tokenState = State.NotEscaped;
- }
- else if (tokenState == State.NotEscaped)
- {
- switch (_serializedText[i])
- {
- case Esc:
- tokenState = State.Escaped;
- break;
-
- case Lhs:
- depth++;
- break;
- case Rhs:
- depth--;
- if (depth == 0)
- {
- _currentTokenStartIndex = i + 1;
- if (_currentTokenStartIndex >= _serializedText.Length)
- {
- _state = State.EndOfLine;
- }
- else
- {
- _state = State.StartOfToken;
- }
- return;
- }
- break;
-
- case '\0':
- // invalid character
- throw new SerializationException(SR.Serialization_InvalidData);
-
- default:
- break;
- }
- }
- }
-
- throw new SerializationException(SR.Serialization_InvalidData);
- }
-
- /// <summary>
- /// Helper function that reads a string token from the serialized text. The function
- /// updates <see cref="_currentTokenStartIndex"/> to point to the next token on exit.
- /// Also <see cref="_state"/> is set to either <see cref="State.StartOfToken"/> or
- /// <see cref="State.EndOfLine"/> on exit.
- /// </summary>
- private string GetNextStringValue()
- {
- // first verify the internal state of the object
- if (_state == State.EndOfLine)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
- if (_currentTokenStartIndex < 0 || _currentTokenStartIndex >= _serializedText.Length)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
- State tokenState = State.NotEscaped;
- var token = new ValueStringBuilder(stackalloc char[InitialCapacityForString]);
-
- // walk the serialized text, building up the token as we go...
- for (int i = _currentTokenStartIndex; i < _serializedText.Length; i++)
- {
- if (tokenState == State.Escaped)
- {
- VerifyIsEscapableCharacter(_serializedText[i]);
- token.Append(_serializedText[i]);
- tokenState = State.NotEscaped;
- }
- else if (tokenState == State.NotEscaped)
- {
- switch (_serializedText[i])
- {
- case Esc:
- tokenState = State.Escaped;
- break;
-
- case Lhs:
- // '[' is an unexpected character
- throw new SerializationException(SR.Serialization_InvalidData);
-
- case Rhs:
- // ']' is an unexpected character
- throw new SerializationException(SR.Serialization_InvalidData);
-
- case Sep:
- _currentTokenStartIndex = i + 1;
- if (_currentTokenStartIndex >= _serializedText.Length)
- {
- _state = State.EndOfLine;
- }
- else
- {
- _state = State.StartOfToken;
- }
- return token.ToString();
-
- case '\0':
- // invalid character
- throw new SerializationException(SR.Serialization_InvalidData);
-
- default:
- token.Append(_serializedText[i]);
- break;
- }
- }
- }
- //
- // we are at the end of the line
- //
- if (tokenState == State.Escaped)
- {
- // we are at the end of the serialized text but we are in an escaped state
- throw new SerializationException(SR.Format(SR.Serialization_InvalidEscapeSequence, string.Empty));
- }
-
- throw new SerializationException(SR.Serialization_InvalidData);
- }
-
- /// <summary>
- /// Helper function to read a DateTime token.
- /// </summary>
- private DateTime GetNextDateTimeValue(string format)
- {
- string token = GetNextStringValue();
- DateTime time;
- if (!DateTime.TryParseExact(token, format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out time))
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
- return time;
- }
-
- /// <summary>
- /// Helper function to read a TimeSpan token.
- /// </summary>
- private TimeSpan GetNextTimeSpanValue()
- {
- int token = GetNextInt32Value();
- try
- {
- return new TimeSpan(hours: 0, minutes: token, seconds: 0);
- }
- catch (ArgumentOutOfRangeException e)
- {
- throw new SerializationException(SR.Serialization_InvalidData, e);
- }
- }
-
- /// <summary>
- /// Helper function to read an Int32 token.
- /// </summary>
- private int GetNextInt32Value()
- {
- string token = GetNextStringValue();
- int value;
- if (!int.TryParse(token, NumberStyles.AllowLeadingSign /* "[sign]digits" */, CultureInfo.InvariantCulture, out value))
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
- return value;
- }
-
- /// <summary>
- /// Helper function to read an AdjustmentRule[] token.
- /// </summary>
- private AdjustmentRule[]? GetNextAdjustmentRuleArrayValue()
- {
- List<AdjustmentRule> rules = new List<AdjustmentRule>(1);
- int count = 0;
-
- // individual AdjustmentRule array elements do not require semicolons
- AdjustmentRule? rule = GetNextAdjustmentRuleValue();
- while (rule != null)
- {
- rules.Add(rule);
- count++;
-
- rule = GetNextAdjustmentRuleValue();
- }
-
- // the AdjustmentRule array must end with a separator
- if (_state == State.EndOfLine)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
- if (_currentTokenStartIndex < 0 || _currentTokenStartIndex >= _serializedText.Length)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
-
- return count != 0 ? rules.ToArray() : null;
- }
-
- /// <summary>
- /// Helper function to read an AdjustmentRule token.
- /// </summary>
- private AdjustmentRule? GetNextAdjustmentRuleValue()
- {
- // first verify the internal state of the object
- if (_state == State.EndOfLine)
- {
- return null;
- }
-
- if (_currentTokenStartIndex < 0 || _currentTokenStartIndex >= _serializedText.Length)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
-
- // check to see if the very first token we see is the separator
- if (_serializedText[_currentTokenStartIndex] == Sep)
- {
- return null;
- }
-
- // verify the current token is a left-hand-side marker ("[")
- if (_serializedText[_currentTokenStartIndex] != Lhs)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
- _currentTokenStartIndex++;
-
- DateTime dateStart = GetNextDateTimeValue(DateTimeFormat);
- DateTime dateEnd = GetNextDateTimeValue(DateTimeFormat);
- TimeSpan daylightDelta = GetNextTimeSpanValue();
- TransitionTime daylightStart = GetNextTransitionTimeValue();
- TransitionTime daylightEnd = GetNextTransitionTimeValue();
- TimeSpan baseUtcOffsetDelta = TimeSpan.Zero;
- int noDaylightTransitions = 0;
-
- // verify that the string is now at the right-hand-side marker ("]") ...
-
- if (_state == State.EndOfLine || _currentTokenStartIndex >= _serializedText.Length)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
-
- // Check if we have baseUtcOffsetDelta in the serialized string and then deserialize it
- if ((_serializedText[_currentTokenStartIndex] >= '0' && _serializedText[_currentTokenStartIndex] <= '9') ||
- _serializedText[_currentTokenStartIndex] == '-' || _serializedText[_currentTokenStartIndex] == '+')
- {
- baseUtcOffsetDelta = GetNextTimeSpanValue();
- }
-
- // Check if we have NoDaylightTransitions in the serialized string and then deserialize it
- if (_serializedText[_currentTokenStartIndex] >= '0' && _serializedText[_currentTokenStartIndex] <= '1')
- {
- noDaylightTransitions = GetNextInt32Value();
- }
-
- if (_state == State.EndOfLine || _currentTokenStartIndex >= _serializedText.Length)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
-
- if (_serializedText[_currentTokenStartIndex] != Rhs)
- {
- // skip ahead of any "v.Next" data at the end of the AdjustmentRule
- //
- // FUTURE: if the serialization format is extended in the future then this
- // code section will need to be changed to read the new fields rather
- // than just skipping the data at the end of the [AdjustmentRule].
- SkipVersionNextDataFields(1);
- }
- else
- {
- _currentTokenStartIndex++;
- }
-
- // create the AdjustmentRule from the deserialized fields ...
-
- AdjustmentRule rule;
- try
- {
- rule = AdjustmentRule.CreateAdjustmentRule(dateStart, dateEnd, daylightDelta, daylightStart, daylightEnd, baseUtcOffsetDelta, noDaylightTransitions > 0);
- }
- catch (ArgumentException e)
- {
- throw new SerializationException(SR.Serialization_InvalidData, e);
- }
-
- // finally set the state to either EndOfLine or StartOfToken for the next caller
- if (_currentTokenStartIndex >= _serializedText.Length)
- {
- _state = State.EndOfLine;
- }
- else
- {
- _state = State.StartOfToken;
- }
- return rule;
- }
-
- /// <summary>
- /// Helper function to read a TransitionTime token.
- /// </summary>
- private TransitionTime GetNextTransitionTimeValue()
- {
- // first verify the internal state of the object
-
- if (_state == State.EndOfLine ||
- (_currentTokenStartIndex < _serializedText.Length && _serializedText[_currentTokenStartIndex] == Rhs))
- {
- //
- // we are at the end of the line or we are starting at a "]" character
- //
- throw new SerializationException(SR.Serialization_InvalidData);
- }
-
- if (_currentTokenStartIndex < 0 || _currentTokenStartIndex >= _serializedText.Length)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
-
- // verify the current token is a left-hand-side marker ("[")
-
- if (_serializedText[_currentTokenStartIndex] != Lhs)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
- _currentTokenStartIndex++;
-
- int isFixedDate = GetNextInt32Value();
-
- if (isFixedDate != 0 && isFixedDate != 1)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
-
- TransitionTime transition;
-
- DateTime timeOfDay = GetNextDateTimeValue(TimeOfDayFormat);
- timeOfDay = new DateTime(1, 1, 1, timeOfDay.Hour, timeOfDay.Minute, timeOfDay.Second, timeOfDay.Millisecond);
-
- int month = GetNextInt32Value();
-
- if (isFixedDate == 1)
- {
- int day = GetNextInt32Value();
-
- try
- {
- transition = TransitionTime.CreateFixedDateRule(timeOfDay, month, day);
- }
- catch (ArgumentException e)
- {
- throw new SerializationException(SR.Serialization_InvalidData, e);
- }
- }
- else
- {
- int week = GetNextInt32Value();
- int dayOfWeek = GetNextInt32Value();
-
- try
- {
- transition = TransitionTime.CreateFloatingDateRule(timeOfDay, month, week, (DayOfWeek)dayOfWeek);
- }
- catch (ArgumentException e)
- {
- throw new SerializationException(SR.Serialization_InvalidData, e);
- }
- }
-
- // verify that the string is now at the right-hand-side marker ("]") ...
-
- if (_state == State.EndOfLine || _currentTokenStartIndex >= _serializedText.Length)
- {
- throw new SerializationException(SR.Serialization_InvalidData);
- }
-
- if (_serializedText[_currentTokenStartIndex] != Rhs)
- {
- // skip ahead of any "v.Next" data at the end of the AdjustmentRule
- //
- // FUTURE: if the serialization format is extended in the future then this
- // code section will need to be changed to read the new fields rather
- // than just skipping the data at the end of the [TransitionTime].
- SkipVersionNextDataFields(1);
- }
- else
- {
- _currentTokenStartIndex++;
- }
-
- // check to see if the string is now at the separator (";") ...
- bool sepFound = false;
- if (_currentTokenStartIndex < _serializedText.Length &&
- _serializedText[_currentTokenStartIndex] == Sep)
- {
- // handle the case where we ended on a ";"
- _currentTokenStartIndex++;
- sepFound = true;
- }
-
- if (!sepFound)
- {
- // we MUST end on a separator
- throw new SerializationException(SR.Serialization_InvalidData);
- }
-
- // finally set the state to either EndOfLine or StartOfToken for the next caller
- if (_currentTokenStartIndex >= _serializedText.Length)
- {
- _state = State.EndOfLine;
- }
- else
- {
- _state = State.StartOfToken;
- }
- return transition;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.TransitionTime.cs b/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.TransitionTime.cs
deleted file mode 100644
index 141b621f5cf..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.TransitionTime.cs
+++ /dev/null
@@ -1,161 +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 System.Runtime.Serialization;
-
-namespace System
-{
- public sealed partial class TimeZoneInfo
- {
- [Serializable]
- public readonly struct TransitionTime : IEquatable<TransitionTime>, ISerializable, IDeserializationCallback
- {
- private readonly DateTime _timeOfDay;
- private readonly byte _month;
- private readonly byte _week;
- private readonly byte _day;
- private readonly DayOfWeek _dayOfWeek;
- private readonly bool _isFixedDateRule;
-
- public DateTime TimeOfDay => _timeOfDay;
-
- public int Month => _month;
-
- public int Week => _week;
-
- public int Day => _day;
-
- public DayOfWeek DayOfWeek => _dayOfWeek;
-
- public bool IsFixedDateRule => _isFixedDateRule;
-
- public override bool Equals(object? obj) =>
- obj is TransitionTime && Equals((TransitionTime)obj);
-
- public static bool operator ==(TransitionTime t1, TransitionTime t2) => t1.Equals(t2);
-
- public static bool operator !=(TransitionTime t1, TransitionTime t2) => !t1.Equals(t2);
-
- public bool Equals(TransitionTime other) =>
- _isFixedDateRule == other._isFixedDateRule &&
- _timeOfDay == other._timeOfDay &&
- _month == other._month &&
- (other._isFixedDateRule ?
- _day == other._day :
- _week == other._week && _dayOfWeek == other._dayOfWeek);
-
- public override int GetHashCode() => (int)_month ^ (int)_week << 8;
-
- private TransitionTime(DateTime timeOfDay, int month, int week, int day, DayOfWeek dayOfWeek, bool isFixedDateRule)
- {
- ValidateTransitionTime(timeOfDay, month, week, day, dayOfWeek);
-
- _timeOfDay = timeOfDay;
- _month = (byte)month;
- _week = (byte)week;
- _day = (byte)day;
- _dayOfWeek = dayOfWeek;
- _isFixedDateRule = isFixedDateRule;
- }
-
- public static TransitionTime CreateFixedDateRule(DateTime timeOfDay, int month, int day) =>
- new TransitionTime(timeOfDay, month, 1, day, DayOfWeek.Sunday, isFixedDateRule: true);
-
- public static TransitionTime CreateFloatingDateRule(DateTime timeOfDay, int month, int week, DayOfWeek dayOfWeek) =>
- new TransitionTime(timeOfDay, month, week, 1, dayOfWeek, isFixedDateRule: false);
-
- /// <summary>
- /// Helper function that validates a TransitionTime instance.
- /// </summary>
- private static void ValidateTransitionTime(DateTime timeOfDay, int month, int week, int day, DayOfWeek dayOfWeek)
- {
- if (timeOfDay.Kind != DateTimeKind.Unspecified)
- {
- throw new ArgumentException(SR.Argument_DateTimeKindMustBeUnspecified, nameof(timeOfDay));
- }
-
- // Month range 1-12
- if (month < 1 || month > 12)
- {
- throw new ArgumentOutOfRangeException(nameof(month), SR.ArgumentOutOfRange_MonthParam);
- }
-
- // Day range 1-31
- if (day < 1 || day > 31)
- {
- throw new ArgumentOutOfRangeException(nameof(day), SR.ArgumentOutOfRange_DayParam);
- }
-
- // Week range 1-5
- if (week < 1 || week > 5)
- {
- throw new ArgumentOutOfRangeException(nameof(week), SR.ArgumentOutOfRange_Week);
- }
-
- // DayOfWeek range 0-6
- if ((int)dayOfWeek < 0 || (int)dayOfWeek > 6)
- {
- throw new ArgumentOutOfRangeException(nameof(dayOfWeek), SR.ArgumentOutOfRange_DayOfWeek);
- }
-
- timeOfDay.GetDatePart(out int timeOfDayYear, out int timeOfDayMonth, out int timeOfDayDay);
- if (timeOfDayYear != 1 || timeOfDayMonth != 1 || timeOfDayDay != 1 || (timeOfDay.Ticks % TimeSpan.TicksPerMillisecond != 0))
- {
- throw new ArgumentException(SR.Argument_DateTimeHasTicks, nameof(timeOfDay));
- }
- }
-
- void IDeserializationCallback.OnDeserialization(object? sender)
- {
- // OnDeserialization is called after each instance of this class is deserialized.
- // This callback method performs TransitionTime validation after being deserialized.
-
- // On Unix, TimeZoneInfos are created with empty/default TransitionTimes, since
- // TransitionTimes are not used on Unix. When deserializing TransitionTimes, only
- // validate it if it isn't an empty/default instance.
- if (this != default)
- {
- try
- {
- ValidateTransitionTime(_timeOfDay, _month, _week, _day, _dayOfWeek);
- }
- catch (ArgumentException e)
- {
- throw new SerializationException(SR.Serialization_InvalidData, e);
- }
- }
- }
-
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- info.AddValue("TimeOfDay", _timeOfDay); // Do not rename (binary serialization)
- info.AddValue("Month", _month); // Do not rename (binary serialization)
- info.AddValue("Week", _week); // Do not rename (binary serialization)
- info.AddValue("Day", _day); // Do not rename (binary serialization)
- info.AddValue("DayOfWeek", _dayOfWeek); // Do not rename (binary serialization)
- info.AddValue("IsFixedDateRule", _isFixedDateRule); // Do not rename (binary serialization)
- }
-
- private TransitionTime(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- _timeOfDay = (DateTime)info.GetValue("TimeOfDay", typeof(DateTime))!; // Do not rename (binary serialization)
- _month = (byte)info.GetValue("Month", typeof(byte))!; // Do not rename (binary serialization)
- _week = (byte)info.GetValue("Week", typeof(byte))!; // Do not rename (binary serialization)
- _day = (byte)info.GetValue("Day", typeof(byte))!; // Do not rename (binary serialization)
- _dayOfWeek = (DayOfWeek)info.GetValue("DayOfWeek", typeof(DayOfWeek))!; // Do not rename (binary serialization)
- _isFixedDateRule = (bool)info.GetValue("IsFixedDateRule", typeof(bool))!; // Do not rename (binary serialization)
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs b/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs
deleted file mode 100644
index 6d18ec47ff2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs
+++ /dev/null
@@ -1,1745 +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 System.Buffers;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.IO;
-using System.Text;
-using System.Threading;
-using System.Security;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-using Internal.IO;
-
-namespace System
-{
- public sealed partial class TimeZoneInfo
- {
- private const string DefaultTimeZoneDirectory = "/usr/share/zoneinfo/";
- private const string ZoneTabFileName = "zone.tab";
- private const string TimeZoneEnvironmentVariable = "TZ";
- private const string TimeZoneDirectoryEnvironmentVariable = "TZDIR";
-
- private TimeZoneInfo(byte[] data, string id, bool dstDisabled)
- {
- TZifHead t;
- DateTime[] dts;
- byte[] typeOfLocalTime;
- TZifType[] transitionType;
- string zoneAbbreviations;
- bool[] StandardTime;
- bool[] GmtTime;
- string? futureTransitionsPosixFormat;
-
- // parse the raw TZif bytes; this method can throw ArgumentException when the data is malformed.
- TZif_ParseRaw(data, out t, out dts, out typeOfLocalTime, out transitionType, out zoneAbbreviations, out StandardTime, out GmtTime, out futureTransitionsPosixFormat);
-
- _id = id;
- _displayName = LocalId;
- _baseUtcOffset = TimeSpan.Zero;
-
- // find the best matching baseUtcOffset and display strings based on the current utcNow value.
- // NOTE: read the display strings from the tzfile now in case they can't be loaded later
- // from the globalization data.
- DateTime utcNow = DateTime.UtcNow;
- for (int i = 0; i < dts.Length && dts[i] <= utcNow; i++)
- {
- int type = typeOfLocalTime[i];
- if (!transitionType[type].IsDst)
- {
- _baseUtcOffset = transitionType[type].UtcOffset;
- _standardDisplayName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[type].AbbreviationIndex);
- }
- else
- {
- _daylightDisplayName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[type].AbbreviationIndex);
- }
- }
-
- if (dts.Length == 0)
- {
- // time zones like Africa/Bujumbura and Etc/GMT* have no transition times but still contain
- // TZifType entries that may contain a baseUtcOffset and display strings
- for (int i = 0; i < transitionType.Length; i++)
- {
- if (!transitionType[i].IsDst)
- {
- _baseUtcOffset = transitionType[i].UtcOffset;
- _standardDisplayName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[i].AbbreviationIndex);
- }
- else
- {
- _daylightDisplayName = TZif_GetZoneAbbreviation(zoneAbbreviations, transitionType[i].AbbreviationIndex);
- }
- }
- }
- _displayName = _standardDisplayName;
-
- GetDisplayName(Interop.Globalization.TimeZoneDisplayNameType.Generic, ref _displayName);
- GetDisplayName(Interop.Globalization.TimeZoneDisplayNameType.Standard, ref _standardDisplayName);
- GetDisplayName(Interop.Globalization.TimeZoneDisplayNameType.DaylightSavings, ref _daylightDisplayName);
-
- if (_standardDisplayName == _displayName)
- {
- if (_baseUtcOffset >= TimeSpan.Zero)
- _displayName = $"(UTC+{_baseUtcOffset:hh\\:mm}) {_standardDisplayName}";
- else
- _displayName = $"(UTC-{_baseUtcOffset:hh\\:mm}) {_standardDisplayName}";
- }
-
- // TZif supports seconds-level granularity with offsets but TimeZoneInfo only supports minutes since it aligns
- // with DateTimeOffset, SQL Server, and the W3C XML Specification
- if (_baseUtcOffset.Ticks % TimeSpan.TicksPerMinute != 0)
- {
- _baseUtcOffset = new TimeSpan(_baseUtcOffset.Hours, _baseUtcOffset.Minutes, 0);
- }
-
- if (!dstDisabled)
- {
- // only create the adjustment rule if DST is enabled
- TZif_GenerateAdjustmentRules(out _adjustmentRules, _baseUtcOffset, dts, typeOfLocalTime, transitionType, StandardTime, GmtTime, futureTransitionsPosixFormat);
- }
-
- ValidateTimeZoneInfo(_id, _baseUtcOffset, _adjustmentRules, out _supportsDaylightSavingTime);
- }
-
- private unsafe void GetDisplayName(Interop.Globalization.TimeZoneDisplayNameType nameType, ref string? displayName)
- {
- if (GlobalizationMode.Invariant)
- {
- displayName = _standardDisplayName;
- return;
- }
-
- string? timeZoneDisplayName;
- bool result = Interop.CallStringMethod(
- (buffer, locale, id, type) =>
- {
- fixed (char* bufferPtr = buffer)
- {
- return Interop.Globalization.GetTimeZoneDisplayName(locale, id, type, bufferPtr, buffer.Length);
- }
- },
- CultureInfo.CurrentUICulture.Name,
- _id,
- nameType,
- out timeZoneDisplayName);
-
- // If there is an unknown error, don't set the displayName field.
- // It will be set to the abbreviation that was read out of the tzfile.
- if (result)
- {
- displayName = timeZoneDisplayName;
- }
- }
-
- /// <summary>
- /// Returns a cloned array of AdjustmentRule objects
- /// </summary>
- public AdjustmentRule[] GetAdjustmentRules()
- {
- if (_adjustmentRules == null)
- {
- return Array.Empty<AdjustmentRule>();
- }
-
- // The rules we use in Unix care mostly about the start and end dates but don't fill the transition start and end info.
- // as the rules now is public, we should fill it properly so the caller doesn't have to know how we use it internally
- // and can use it as it is used in Windows
-
- AdjustmentRule[] rules = new AdjustmentRule[_adjustmentRules.Length];
-
- for (int i = 0; i < _adjustmentRules.Length; i++)
- {
- var rule = _adjustmentRules[i];
- var start = rule.DateStart.Kind == DateTimeKind.Utc ?
- // At the daylight start we didn't start the daylight saving yet then we convert to Local time
- // by adding the _baseUtcOffset to the UTC time
- new DateTime(rule.DateStart.Ticks + _baseUtcOffset.Ticks, DateTimeKind.Unspecified) :
- rule.DateStart;
- var end = rule.DateEnd.Kind == DateTimeKind.Utc ?
- // At the daylight saving end, the UTC time is mapped to local time which is already shifted by the daylight delta
- // we calculate the local time by adding _baseUtcOffset + DaylightDelta to the UTC time
- new DateTime(rule.DateEnd.Ticks + _baseUtcOffset.Ticks + rule.DaylightDelta.Ticks, DateTimeKind.Unspecified) :
- rule.DateEnd;
-
- var startTransition = TimeZoneInfo.TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, start.Hour, start.Minute, start.Second), start.Month, start.Day);
- var endTransition = TimeZoneInfo.TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, end.Hour, end.Minute, end.Second), end.Month, end.Day);
-
- rules[i] = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(start.Date, end.Date, rule.DaylightDelta, startTransition, endTransition);
- }
-
- return rules;
- }
-
- private static void PopulateAllSystemTimeZones(CachedData cachedData)
- {
- Debug.Assert(Monitor.IsEntered(cachedData));
-
- string timeZoneDirectory = GetTimeZoneDirectory();
- foreach (string timeZoneId in GetTimeZoneIds(timeZoneDirectory))
- {
- TryGetTimeZone(timeZoneId, false, out _, out _, cachedData, alwaysFallbackToLocalMachine: true); // populate the cache
- }
- }
-
- /// <summary>
- /// Helper function for retrieving the local system time zone.
- /// May throw COMException, TimeZoneNotFoundException, InvalidTimeZoneException.
- /// Assumes cachedData lock is taken.
- /// </summary>
- /// <returns>A new TimeZoneInfo instance.</returns>
- private static TimeZoneInfo GetLocalTimeZone(CachedData cachedData)
- {
- Debug.Assert(Monitor.IsEntered(cachedData));
-
- // Without Registry support, create the TimeZoneInfo from a TZ file
- return GetLocalTimeZoneFromTzFile();
- }
-
- private static TimeZoneInfoResult TryGetTimeZoneFromLocalMachine(string id, out TimeZoneInfo? value, out Exception? e)
- {
- value = null;
- e = null;
-
- string timeZoneDirectory = GetTimeZoneDirectory();
- string timeZoneFilePath = Path.Combine(timeZoneDirectory, id);
- byte[] rawData;
- try
- {
- rawData = File.ReadAllBytes(timeZoneFilePath);
- }
- catch (UnauthorizedAccessException ex)
- {
- e = ex;
- return TimeZoneInfoResult.SecurityException;
- }
- catch (FileNotFoundException ex)
- {
- e = ex;
- return TimeZoneInfoResult.TimeZoneNotFoundException;
- }
- catch (DirectoryNotFoundException ex)
- {
- e = ex;
- return TimeZoneInfoResult.TimeZoneNotFoundException;
- }
- catch (IOException ex)
- {
- e = new InvalidTimeZoneException(SR.Format(SR.InvalidTimeZone_InvalidFileData, id, timeZoneFilePath), ex);
- return TimeZoneInfoResult.InvalidTimeZoneException;
- }
-
- value = GetTimeZoneFromTzData(rawData, id);
-
- if (value == null)
- {
- e = new InvalidTimeZoneException(SR.Format(SR.InvalidTimeZone_InvalidFileData, id, timeZoneFilePath));
- return TimeZoneInfoResult.InvalidTimeZoneException;
- }
-
- return TimeZoneInfoResult.Success;
- }
-
- /// <summary>
- /// Returns a collection of TimeZone Id values from the zone.tab file in the timeZoneDirectory.
- /// </summary>
- /// <remarks>
- /// Lines that start with # are comments and are skipped.
- /// </remarks>
- private static List<string> GetTimeZoneIds(string timeZoneDirectory)
- {
- List<string> timeZoneIds = new List<string>();
-
- try
- {
- using (StreamReader sr = new StreamReader(Path.Combine(timeZoneDirectory, ZoneTabFileName), Encoding.UTF8))
- {
- string? zoneTabFileLine;
- while ((zoneTabFileLine = sr.ReadLine()) != null)
- {
- if (!string.IsNullOrEmpty(zoneTabFileLine) && zoneTabFileLine[0] != '#')
- {
- // the format of the line is "country-code \t coordinates \t TimeZone Id \t comments"
-
- int firstTabIndex = zoneTabFileLine.IndexOf('\t');
- if (firstTabIndex != -1)
- {
- int secondTabIndex = zoneTabFileLine.IndexOf('\t', firstTabIndex + 1);
- if (secondTabIndex != -1)
- {
- string timeZoneId;
- int startIndex = secondTabIndex + 1;
- int thirdTabIndex = zoneTabFileLine.IndexOf('\t', startIndex);
- if (thirdTabIndex != -1)
- {
- int length = thirdTabIndex - startIndex;
- timeZoneId = zoneTabFileLine.Substring(startIndex, length);
- }
- else
- {
- timeZoneId = zoneTabFileLine.Substring(startIndex);
- }
-
- if (!string.IsNullOrEmpty(timeZoneId))
- {
- timeZoneIds.Add(timeZoneId);
- }
- }
- }
- }
- }
- }
- }
- catch (IOException) { }
- catch (UnauthorizedAccessException) { }
-
- return timeZoneIds;
- }
-
- /// <summary>
- /// Gets the tzfile raw data for the current 'local' time zone using the following rules.
- /// 1. Read the TZ environment variable. If it is set, use it.
- /// 2. Look for the data in /etc/localtime.
- /// 3. Look for the data in GetTimeZoneDirectory()/localtime.
- /// 4. Use UTC if all else fails.
- /// </summary>
- private static bool TryGetLocalTzFile([NotNullWhen(true)] out byte[]? rawData, [NotNullWhen(true)] out string? id)
- {
- rawData = null;
- id = null;
- string? tzVariable = GetTzEnvironmentVariable();
-
- // If the env var is null, use the localtime file
- if (tzVariable == null)
- {
- return
- TryLoadTzFile("/etc/localtime", ref rawData, ref id) ||
- TryLoadTzFile(Path.Combine(GetTimeZoneDirectory(), "localtime"), ref rawData, ref id);
- }
-
- // If it's empty, use UTC (TryGetLocalTzFile() should return false).
- if (tzVariable.Length == 0)
- {
- return false;
- }
-
- // Otherwise, use the path from the env var. If it's not absolute, make it relative
- // to the system timezone directory
- string tzFilePath;
- if (tzVariable[0] != '/')
- {
- id = tzVariable;
- tzFilePath = Path.Combine(GetTimeZoneDirectory(), tzVariable);
- }
- else
- {
- tzFilePath = tzVariable;
- }
- return TryLoadTzFile(tzFilePath, ref rawData, ref id);
- }
-
- private static string? GetTzEnvironmentVariable()
- {
- string? result = Environment.GetEnvironmentVariable(TimeZoneEnvironmentVariable);
- if (!string.IsNullOrEmpty(result))
- {
- if (result[0] == ':')
- {
- // strip off the ':' prefix
- result = result.Substring(1);
- }
- }
-
- return result;
- }
-
- private static bool TryLoadTzFile(string tzFilePath, [NotNullWhen(true)] ref byte[]? rawData, [NotNullWhen(true)] ref string? id)
- {
- if (File.Exists(tzFilePath))
- {
- try
- {
- rawData = File.ReadAllBytes(tzFilePath);
- if (string.IsNullOrEmpty(id))
- {
- id = FindTimeZoneIdUsingReadLink(tzFilePath);
-
- if (string.IsNullOrEmpty(id))
- {
- id = FindTimeZoneId(rawData);
- }
- }
- return true;
- }
- catch (IOException) { }
- catch (SecurityException) { }
- catch (UnauthorizedAccessException) { }
- }
- return false;
- }
-
- /// <summary>
- /// Finds the time zone id by using 'readlink' on the path to see if tzFilePath is
- /// a symlink to a file.
- /// </summary>
- private static string? FindTimeZoneIdUsingReadLink(string tzFilePath)
- {
- string? id = null;
-
- string? symlinkPath = Interop.Sys.ReadLink(tzFilePath);
- if (symlinkPath != null)
- {
- // symlinkPath can be relative path, use Path to get the full absolute path.
- symlinkPath = Path.GetFullPath(symlinkPath, Path.GetDirectoryName(tzFilePath)!);
-
- string timeZoneDirectory = GetTimeZoneDirectory();
- if (symlinkPath.StartsWith(timeZoneDirectory, StringComparison.Ordinal))
- {
- id = symlinkPath.Substring(timeZoneDirectory.Length);
- }
- }
-
- return id;
- }
-
- private static string? GetDirectoryEntryFullPath(ref Interop.Sys.DirectoryEntry dirent, string currentPath)
- {
- ReadOnlySpan<char> direntName = dirent.GetName(stackalloc char[Interop.Sys.DirectoryEntry.NameBufferSize]);
-
- if ((direntName.Length == 1 && direntName[0] == '.') ||
- (direntName.Length == 2 && direntName[0] == '.' && direntName[1] == '.'))
- return null;
-
- return Path.Join(currentPath.AsSpan(), direntName);
- }
-
- /// <summary>
- /// Enumerate files
- /// </summary>
- private static unsafe void EnumerateFilesRecursively(string path, Predicate<string> condition)
- {
- List<string>? toExplore = null; // List used as a stack
-
- int bufferSize = Interop.Sys.GetReadDirRBufferSize();
- byte[]? dirBuffer = null;
- try
- {
- dirBuffer = ArrayPool<byte>.Shared.Rent(bufferSize);
- string currentPath = path;
-
- fixed (byte* dirBufferPtr = dirBuffer)
- {
- while (true)
- {
- IntPtr dirHandle = Interop.Sys.OpenDir(currentPath);
- if (dirHandle == IntPtr.Zero)
- {
- throw Interop.GetExceptionForIoErrno(Interop.Sys.GetLastErrorInfo(), currentPath, isDirectory: true);
- }
-
- try
- {
- // Read each entry from the enumerator
- Interop.Sys.DirectoryEntry dirent;
- while (Interop.Sys.ReadDirR(dirHandle, dirBufferPtr, bufferSize, out dirent) == 0)
- {
- string? fullPath = GetDirectoryEntryFullPath(ref dirent, currentPath);
- if (fullPath == null)
- continue;
-
- // Get from the dir entry whether the entry is a file or directory.
- // We classify everything as a file unless we know it to be a directory.
- bool isDir;
- if (dirent.InodeType == Interop.Sys.NodeType.DT_DIR)
- {
- // We know it's a directory.
- isDir = true;
- }
- else if (dirent.InodeType == Interop.Sys.NodeType.DT_LNK || dirent.InodeType == Interop.Sys.NodeType.DT_UNKNOWN)
- {
- // It's a symlink or unknown: stat to it to see if we can resolve it to a directory.
- // If we can't (e.g. symlink to a file, broken symlink, etc.), we'll just treat it as a file.
-
- Interop.Sys.FileStatus fileinfo;
- if (Interop.Sys.Stat(fullPath, out fileinfo) >= 0)
- {
- isDir = (fileinfo.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR;
- }
- else
- {
- isDir = false;
- }
- }
- else
- {
- // Otherwise, treat it as a file. This includes regular files, FIFOs, etc.
- isDir = false;
- }
-
- // Yield the result if the user has asked for it. In the case of directories,
- // always explore it by pushing it onto the stack, regardless of whether
- // we're returning directories.
- if (isDir)
- {
- toExplore ??= new List<string>();
- toExplore.Add(fullPath);
- }
- else if (condition(fullPath))
- {
- return;
- }
- }
- }
- finally
- {
- if (dirHandle != IntPtr.Zero)
- Interop.Sys.CloseDir(dirHandle);
- }
-
- if (toExplore == null || toExplore.Count == 0)
- break;
-
- currentPath = toExplore[toExplore.Count - 1];
- toExplore.RemoveAt(toExplore.Count - 1);
- }
- }
- }
- finally
- {
- if (dirBuffer != null)
- ArrayPool<byte>.Shared.Return(dirBuffer);
- }
- }
-
- /// <summary>
- /// Find the time zone id by searching all the tzfiles for the one that matches rawData
- /// and return its file name.
- /// </summary>
- private static string FindTimeZoneId(byte[] rawData)
- {
- // default to "Local" if we can't find the right tzfile
- string id = LocalId;
- string timeZoneDirectory = GetTimeZoneDirectory();
- string localtimeFilePath = Path.Combine(timeZoneDirectory, "localtime");
- string posixrulesFilePath = Path.Combine(timeZoneDirectory, "posixrules");
- byte[] buffer = new byte[rawData.Length];
-
- try
- {
- EnumerateFilesRecursively(timeZoneDirectory, (string filePath) =>
- {
- // skip the localtime and posixrules file, since they won't give us the correct id
- if (!string.Equals(filePath, localtimeFilePath, StringComparison.OrdinalIgnoreCase)
- && !string.Equals(filePath, posixrulesFilePath, StringComparison.OrdinalIgnoreCase))
- {
- if (CompareTimeZoneFile(filePath, buffer, rawData))
- {
- // if all bytes are the same, this must be the right tz file
- id = filePath;
-
- // strip off the root time zone directory
- if (id.StartsWith(timeZoneDirectory, StringComparison.Ordinal))
- {
- id = id.Substring(timeZoneDirectory.Length);
- }
- return true;
- }
- }
- return false;
- });
- }
- catch (IOException) { }
- catch (SecurityException) { }
- catch (UnauthorizedAccessException) { }
-
- return id;
- }
-
- private static bool CompareTimeZoneFile(string filePath, byte[] buffer, byte[] rawData)
- {
- try
- {
- // bufferSize == 1 used to avoid unnecessary buffer in FileStream
- using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 1))
- {
- if (stream.Length == rawData.Length)
- {
- int index = 0;
- int count = rawData.Length;
-
- while (count > 0)
- {
- int n = stream.Read(buffer, index, count);
- if (n == 0)
- throw Error.GetEndOfFile();
-
- int end = index + n;
- for (; index < end; index++)
- {
- if (buffer[index] != rawData[index])
- {
- return false;
- }
- }
-
- count -= n;
- }
-
- return true;
- }
- }
- }
- catch (IOException) { }
- catch (SecurityException) { }
- catch (UnauthorizedAccessException) { }
-
- return false;
- }
-
- /// <summary>
- /// Helper function used by 'GetLocalTimeZone()' - this function wraps the call
- /// for loading time zone data from computers without Registry support.
- ///
- /// The TryGetLocalTzFile() call returns a Byte[] containing the compiled tzfile.
- /// </summary>
- private static TimeZoneInfo GetLocalTimeZoneFromTzFile()
- {
- byte[]? rawData;
- string? id;
- if (TryGetLocalTzFile(out rawData, out id))
- {
- TimeZoneInfo? result = GetTimeZoneFromTzData(rawData, id);
- if (result != null)
- {
- return result;
- }
- }
-
- // if we can't find a local time zone, return UTC
- return Utc;
- }
-
- private static TimeZoneInfo? GetTimeZoneFromTzData(byte[]? rawData, string id)
- {
- if (rawData != null)
- {
- try
- {
- return new TimeZoneInfo(rawData, id, dstDisabled: false); // create a TimeZoneInfo instance from the TZif data w/ DST support
- }
- catch (ArgumentException) { }
- catch (InvalidTimeZoneException) { }
-
- try
- {
- return new TimeZoneInfo(rawData, id, dstDisabled: true); // create a TimeZoneInfo instance from the TZif data w/o DST support
- }
- catch (ArgumentException) { }
- catch (InvalidTimeZoneException) { }
- }
- return null;
- }
-
- private static string GetTimeZoneDirectory()
- {
- string? tzDirectory = Environment.GetEnvironmentVariable(TimeZoneDirectoryEnvironmentVariable);
-
- if (tzDirectory == null)
- {
- tzDirectory = DefaultTimeZoneDirectory;
- }
- else if (!tzDirectory.EndsWith(Path.DirectorySeparatorChar))
- {
- tzDirectory += PathInternal.DirectorySeparatorCharAsString;
- }
-
- return tzDirectory;
- }
-
- /// <summary>
- /// Helper function for retrieving a TimeZoneInfo object by time_zone_name.
- /// This function wraps the logic necessary to keep the private
- /// SystemTimeZones cache in working order
- ///
- /// This function will either return a valid TimeZoneInfo instance or
- /// it will throw 'InvalidTimeZoneException' / 'TimeZoneNotFoundException'.
- /// </summary>
- public static TimeZoneInfo FindSystemTimeZoneById(string id)
- {
- // Special case for Utc as it will not exist in the dictionary with the rest
- // of the system time zones. There is no need to do this check for Local.Id
- // since Local is a real time zone that exists in the dictionary cache
- if (string.Equals(id, UtcId, StringComparison.OrdinalIgnoreCase))
- {
- return Utc;
- }
-
- if (id == null)
- {
- throw new ArgumentNullException(nameof(id));
- }
- else if (id.Length == 0 || id.Contains('\0'))
- {
- throw new TimeZoneNotFoundException(SR.Format(SR.TimeZoneNotFound_MissingData, id));
- }
-
- TimeZoneInfo? value;
- Exception? e;
-
- TimeZoneInfoResult result;
-
- CachedData cachedData = s_cachedData;
-
- lock (cachedData)
- {
- result = TryGetTimeZone(id, false, out value, out e, cachedData, alwaysFallbackToLocalMachine: true);
- }
-
- if (result == TimeZoneInfoResult.Success)
- {
- return value!;
- }
- else if (result == TimeZoneInfoResult.InvalidTimeZoneException)
- {
- Debug.Assert(e is InvalidTimeZoneException,
- "TryGetTimeZone must create an InvalidTimeZoneException when it returns TimeZoneInfoResult.InvalidTimeZoneException");
- throw e;
- }
- else if (result == TimeZoneInfoResult.SecurityException)
- {
- throw new SecurityException(SR.Format(SR.Security_CannotReadFileData, id), e);
- }
- else
- {
- throw new TimeZoneNotFoundException(SR.Format(SR.TimeZoneNotFound_MissingData, id), e);
- }
- }
-
- // DateTime.Now fast path that avoids allocating an historically accurate TimeZoneInfo.Local and just creates a 1-year (current year) accurate time zone
- internal static TimeSpan GetDateTimeNowUtcOffsetFromUtc(DateTime time, out bool isAmbiguousLocalDst)
- {
- bool isDaylightSavings;
- // Use the standard code path for Unix since there isn't a faster way of handling current-year-only time zones
- return GetUtcOffsetFromUtc(time, Local, out isDaylightSavings, out isAmbiguousLocalDst);
- }
-
- // TZFILE(5) BSD File Formats Manual TZFILE(5)
- //
- // NAME
- // tzfile -- timezone information
- //
- // SYNOPSIS
- // #include "/usr/src/lib/libc/stdtime/tzfile.h"
- //
- // DESCRIPTION
- // The time zone information files used by tzset(3) begin with the magic
- // characters ``TZif'' to identify them as time zone information files, fol-
- // lowed by sixteen bytes reserved for future use, followed by four four-
- // byte values written in a ``standard'' byte order (the high-order byte of
- // the value is written first). These values are, in order:
- //
- // tzh_ttisgmtcnt The number of UTC/local indicators stored in the file.
- // tzh_ttisstdcnt The number of standard/wall indicators stored in the
- // file.
- // tzh_leapcnt The number of leap seconds for which data is stored in
- // the file.
- // tzh_timecnt The number of ``transition times'' for which data is
- // stored in the file.
- // tzh_typecnt The number of ``local time types'' for which data is
- // stored in the file (must not be zero).
- // tzh_charcnt The number of characters of ``time zone abbreviation
- // strings'' stored in the file.
- //
- // The above header is followed by tzh_timecnt four-byte values of type
- // long, sorted in ascending order. These values are written in ``stan-
- // dard'' byte order. Each is used as a transition time (as returned by
- // time(3)) at which the rules for computing local time change. Next come
- // tzh_timecnt one-byte values of type unsigned char; each one tells which
- // of the different types of ``local time'' types described in the file is
- // associated with the same-indexed transition time. These values serve as
- // indices into an array of ttinfo structures that appears next in the file;
- // these structures are defined as follows:
- //
- // struct ttinfo {
- // long tt_gmtoff;
- // int tt_isdst;
- // unsigned int tt_abbrind;
- // };
- //
- // Each structure is written as a four-byte value for tt_gmtoff of type
- // long, in a standard byte order, followed by a one-byte value for tt_isdst
- // and a one-byte value for tt_abbrind. In each structure, tt_gmtoff gives
- // the number of seconds to be added to UTC, tt_isdst tells whether tm_isdst
- // should be set by localtime(3) and tt_abbrind serves as an index into the
- // array of time zone abbreviation characters that follow the ttinfo struc-
- // ture(s) in the file.
- //
- // Then there are tzh_leapcnt pairs of four-byte values, written in standard
- // byte order; the first value of each pair gives the time (as returned by
- // time(3)) at which a leap second occurs; the second gives the total number
- // of leap seconds to be applied after the given time. The pairs of values
- // are sorted in ascending order by time.b
- //
- // Then there are tzh_ttisstdcnt standard/wall indicators, each stored as a
- // one-byte value; they tell whether the transition times associated with
- // local time types were specified as standard time or wall clock time, and
- // are used when a time zone file is used in handling POSIX-style time zone
- // environment variables.
- //
- // Finally there are tzh_ttisgmtcnt UTC/local indicators, each stored as a
- // one-byte value; they tell whether the transition times associated with
- // local time types were specified as UTC or local time, and are used when a
- // time zone file is used in handling POSIX-style time zone environment
- // variables.
- //
- // localtime uses the first standard-time ttinfo structure in the file (or
- // simply the first ttinfo structure in the absence of a standard-time
- // structure) if either tzh_timecnt is zero or the time argument is less
- // than the first transition time recorded in the file.
- //
- // SEE ALSO
- // ctime(3), time2posix(3), zic(8)
- //
- // BSD September 13, 1994 BSD
- //
- //
- //
- // TIME(3) BSD Library Functions Manual TIME(3)
- //
- // NAME
- // time -- get time of day
- //
- // LIBRARY
- // Standard C Library (libc, -lc)
- //
- // SYNOPSIS
- // #include <time.h>
- //
- // time_t
- // time(time_t *tloc);
- //
- // DESCRIPTION
- // The time() function returns the value of time in seconds since 0 hours, 0
- // minutes, 0 seconds, January 1, 1970, Coordinated Universal Time, without
- // including leap seconds. If an error occurs, time() returns the value
- // (time_t)-1.
- //
- // The return value is also stored in *tloc, provided that tloc is non-null.
- //
- // ERRORS
- // The time() function may fail for any of the reasons described in
- // gettimeofday(2).
- //
- // SEE ALSO
- // gettimeofday(2), ctime(3)
- //
- // STANDARDS
- // The time function conforms to IEEE Std 1003.1-2001 (``POSIX.1'').
- //
- // BUGS
- // Neither ISO/IEC 9899:1999 (``ISO C99'') nor IEEE Std 1003.1-2001
- // (``POSIX.1'') requires time() to set errno on failure; thus, it is impos-
- // sible for an application to distinguish the valid time value -1 (repre-
- // senting the last UTC second of 1969) from the error return value.
- //
- // Systems conforming to earlier versions of the C and POSIX standards
- // (including older versions of FreeBSD) did not set *tloc in the error
- // case.
- //
- // HISTORY
- // A time() function appeared in Version 6 AT&T UNIX.
- //
- // BSD July 18, 2003 BSD
- //
- //
- private static void TZif_GenerateAdjustmentRules(out AdjustmentRule[]? rules, TimeSpan baseUtcOffset, DateTime[] dts, byte[] typeOfLocalTime,
- TZifType[] transitionType, bool[] StandardTime, bool[] GmtTime, string? futureTransitionsPosixFormat)
- {
- rules = null;
-
- if (dts.Length > 0)
- {
- int index = 0;
- List<AdjustmentRule> rulesList = new List<AdjustmentRule>();
-
- while (index <= dts.Length)
- {
- TZif_GenerateAdjustmentRule(ref index, baseUtcOffset, rulesList, dts, typeOfLocalTime, transitionType, StandardTime, GmtTime, futureTransitionsPosixFormat);
- }
-
- rules = rulesList.ToArray();
- if (rules != null && rules.Length == 0)
- {
- rules = null;
- }
- }
- }
-
- private static void TZif_GenerateAdjustmentRule(ref int index, TimeSpan timeZoneBaseUtcOffset, List<AdjustmentRule> rulesList, DateTime[] dts,
- byte[] typeOfLocalTime, TZifType[] transitionTypes, bool[] StandardTime, bool[] GmtTime, string? futureTransitionsPosixFormat)
- {
- // To generate AdjustmentRules, use the following approach:
- // The first AdjustmentRule will go from DateTime.MinValue to the first transition time greater than DateTime.MinValue.
- // Each middle AdjustmentRule wil go from dts[index-1] to dts[index].
- // The last AdjustmentRule will go from dts[dts.Length-1] to Datetime.MaxValue.
-
- // 0. Skip any DateTime.MinValue transition times. In newer versions of the tzfile, there
- // is a "big bang" transition time, which is before the year 0001. Since any times before year 0001
- // cannot be represented by DateTime, there is no reason to make AdjustmentRules for these unrepresentable time periods.
- // 1. If there are no DateTime.MinValue times, the first AdjustmentRule goes from DateTime.MinValue
- // to the first transition and uses the first standard transitionType (or the first transitionType if none of them are standard)
- // 2. Create an AdjustmentRule for each transition, i.e. from dts[index - 1] to dts[index].
- // This rule uses the transitionType[index - 1] and the whole AdjustmentRule only describes a single offset - either
- // all daylight savings, or all stanard time.
- // 3. After all the transitions are filled out, the last AdjustmentRule is created from either:
- // a. a POSIX-style timezone description ("futureTransitionsPosixFormat"), if there is one or
- // b. continue the last transition offset until DateTime.Max
-
- while (index < dts.Length && dts[index] == DateTime.MinValue)
- {
- index++;
- }
-
- if (rulesList.Count == 0 && index < dts.Length)
- {
- TZifType transitionType = TZif_GetEarlyDateTransitionType(transitionTypes);
- DateTime endTransitionDate = dts[index];
-
- TimeSpan transitionOffset = TZif_CalculateTransitionOffsetFromBase(transitionType.UtcOffset, timeZoneBaseUtcOffset);
- TimeSpan daylightDelta = transitionType.IsDst ? transitionOffset : TimeSpan.Zero;
- TimeSpan baseUtcDelta = transitionType.IsDst ? TimeSpan.Zero : transitionOffset;
-
- AdjustmentRule r = AdjustmentRule.CreateAdjustmentRule(
- DateTime.MinValue,
- endTransitionDate.AddTicks(-1),
- daylightDelta,
- default(TransitionTime),
- default(TransitionTime),
- baseUtcDelta,
- noDaylightTransitions: true);
-
- if (!IsValidAdjustmentRuleOffest(timeZoneBaseUtcOffset, r))
- {
- NormalizeAdjustmentRuleOffset(timeZoneBaseUtcOffset, ref r);
- }
-
- rulesList.Add(r);
- }
- else if (index < dts.Length)
- {
- DateTime startTransitionDate = dts[index - 1];
- TZifType startTransitionType = transitionTypes[typeOfLocalTime[index - 1]];
-
- DateTime endTransitionDate = dts[index];
-
- TimeSpan transitionOffset = TZif_CalculateTransitionOffsetFromBase(startTransitionType.UtcOffset, timeZoneBaseUtcOffset);
- TimeSpan daylightDelta = startTransitionType.IsDst ? transitionOffset : TimeSpan.Zero;
- TimeSpan baseUtcDelta = startTransitionType.IsDst ? TimeSpan.Zero : transitionOffset;
-
- TransitionTime dstStart;
- if (startTransitionType.IsDst)
- {
- // the TransitionTime fields are not used when AdjustmentRule.NoDaylightTransitions == true.
- // However, there are some cases in the past where DST = true, and the daylight savings offset
- // now equals what the current BaseUtcOffset is. In that case, the AdjustmentRule.DaylightOffset
- // is going to be TimeSpan.Zero. But we still need to return 'true' from AdjustmentRule.HasDaylightSaving.
- // To ensure we always return true from HasDaylightSaving, make a "special" dstStart that will make the logic
- // in HasDaylightSaving return true.
- dstStart = TransitionTime.CreateFixedDateRule(DateTime.MinValue.AddMilliseconds(2), 1, 1);
- }
- else
- {
- dstStart = default(TransitionTime);
- }
-
- AdjustmentRule r = AdjustmentRule.CreateAdjustmentRule(
- startTransitionDate,
- endTransitionDate.AddTicks(-1),
- daylightDelta,
- dstStart,
- default(TransitionTime),
- baseUtcDelta,
- noDaylightTransitions: true);
-
- if (!IsValidAdjustmentRuleOffest(timeZoneBaseUtcOffset, r))
- {
- NormalizeAdjustmentRuleOffset(timeZoneBaseUtcOffset, ref r);
- }
-
- rulesList.Add(r);
- }
- else
- {
- // create the AdjustmentRule that will be used for all DateTimes after the last transition
-
- // NOTE: index == dts.Length
- DateTime startTransitionDate = dts[index - 1];
-
- if (!string.IsNullOrEmpty(futureTransitionsPosixFormat))
- {
- AdjustmentRule? r = TZif_CreateAdjustmentRuleForPosixFormat(futureTransitionsPosixFormat, startTransitionDate, timeZoneBaseUtcOffset);
-
- if (r != null)
- {
- if (!IsValidAdjustmentRuleOffest(timeZoneBaseUtcOffset, r))
- {
- NormalizeAdjustmentRuleOffset(timeZoneBaseUtcOffset, ref r);
- }
-
- rulesList.Add(r);
- }
- }
- else
- {
- // just use the last transition as the rule which will be used until the end of time
-
- TZifType transitionType = transitionTypes[typeOfLocalTime[index - 1]];
- TimeSpan transitionOffset = TZif_CalculateTransitionOffsetFromBase(transitionType.UtcOffset, timeZoneBaseUtcOffset);
- TimeSpan daylightDelta = transitionType.IsDst ? transitionOffset : TimeSpan.Zero;
- TimeSpan baseUtcDelta = transitionType.IsDst ? TimeSpan.Zero : transitionOffset;
-
- AdjustmentRule r = AdjustmentRule.CreateAdjustmentRule(
- startTransitionDate,
- DateTime.MaxValue,
- daylightDelta,
- default(TransitionTime),
- default(TransitionTime),
- baseUtcDelta,
- noDaylightTransitions: true);
-
- if (!IsValidAdjustmentRuleOffest(timeZoneBaseUtcOffset, r))
- {
- NormalizeAdjustmentRuleOffset(timeZoneBaseUtcOffset, ref r);
- }
-
- rulesList.Add(r);
- }
- }
-
- index++;
- }
-
- private static TimeSpan TZif_CalculateTransitionOffsetFromBase(TimeSpan transitionOffset, TimeSpan timeZoneBaseUtcOffset)
- {
- TimeSpan result = transitionOffset - timeZoneBaseUtcOffset;
-
- // TZif supports seconds-level granularity with offsets but TimeZoneInfo only supports minutes since it aligns
- // with DateTimeOffset, SQL Server, and the W3C XML Specification
- if (result.Ticks % TimeSpan.TicksPerMinute != 0)
- {
- result = new TimeSpan(result.Hours, result.Minutes, 0);
- }
-
- return result;
- }
-
- /// <summary>
- /// Gets the first standard-time transition type, or simply the first transition type
- /// if there are no standard transition types.
- /// </summary>>
- /// <remarks>
- /// from 'man tzfile':
- /// localtime(3) uses the first standard-time ttinfo structure in the file
- /// (or simply the first ttinfo structure in the absence of a standard-time
- /// structure) if either tzh_timecnt is zero or the time argument is less
- /// than the first transition time recorded in the file.
- /// </remarks>
- private static TZifType TZif_GetEarlyDateTransitionType(TZifType[] transitionTypes)
- {
- foreach (TZifType transitionType in transitionTypes)
- {
- if (!transitionType.IsDst)
- {
- return transitionType;
- }
- }
-
- if (transitionTypes.Length > 0)
- {
- return transitionTypes[0];
- }
-
- throw new InvalidTimeZoneException(SR.InvalidTimeZone_NoTTInfoStructures);
- }
-
- /// <summary>
- /// Creates an AdjustmentRule given the POSIX TZ environment variable string.
- /// </summary>
- /// <remarks>
- /// See http://man7.org/linux/man-pages/man3/tzset.3.html for the format and semantics of this POSX string.
- /// </remarks>
- private static AdjustmentRule? TZif_CreateAdjustmentRuleForPosixFormat(string posixFormat, DateTime startTransitionDate, TimeSpan timeZoneBaseUtcOffset)
- {
- if (TZif_ParsePosixFormat(posixFormat,
- out ReadOnlySpan<char> standardName,
- out ReadOnlySpan<char> standardOffset,
- out ReadOnlySpan<char> daylightSavingsName,
- out ReadOnlySpan<char> daylightSavingsOffset,
- out ReadOnlySpan<char> start,
- out ReadOnlySpan<char> startTime,
- out ReadOnlySpan<char> end,
- out ReadOnlySpan<char> endTime))
- {
- // a valid posixFormat has at least standardName and standardOffset
-
- TimeSpan? parsedBaseOffset = TZif_ParseOffsetString(standardOffset);
- if (parsedBaseOffset.HasValue)
- {
- TimeSpan baseOffset = parsedBaseOffset.GetValueOrDefault().Negate(); // offsets are backwards in POSIX notation
- baseOffset = TZif_CalculateTransitionOffsetFromBase(baseOffset, timeZoneBaseUtcOffset);
-
- // having a daylightSavingsName means there is a DST rule
- if (!daylightSavingsName.IsEmpty)
- {
- TimeSpan? parsedDaylightSavings = TZif_ParseOffsetString(daylightSavingsOffset);
- TimeSpan daylightSavingsTimeSpan;
- if (!parsedDaylightSavings.HasValue)
- {
- // default DST to 1 hour if it isn't specified
- daylightSavingsTimeSpan = new TimeSpan(1, 0, 0);
- }
- else
- {
- daylightSavingsTimeSpan = parsedDaylightSavings.GetValueOrDefault().Negate(); // offsets are backwards in POSIX notation
- daylightSavingsTimeSpan = TZif_CalculateTransitionOffsetFromBase(daylightSavingsTimeSpan, timeZoneBaseUtcOffset);
- daylightSavingsTimeSpan = TZif_CalculateTransitionOffsetFromBase(daylightSavingsTimeSpan, baseOffset);
- }
-
- TransitionTime dstStart = TZif_CreateTransitionTimeFromPosixRule(start, startTime);
- TransitionTime dstEnd = TZif_CreateTransitionTimeFromPosixRule(end, endTime);
-
- return AdjustmentRule.CreateAdjustmentRule(
- startTransitionDate,
- DateTime.MaxValue,
- daylightSavingsTimeSpan,
- dstStart,
- dstEnd,
- baseOffset,
- noDaylightTransitions: false);
- }
- else
- {
- // if there is no daylightSavingsName, the whole AdjustmentRule should be with no transitions - just the baseOffset
- return AdjustmentRule.CreateAdjustmentRule(
- startTransitionDate,
- DateTime.MaxValue,
- TimeSpan.Zero,
- default(TransitionTime),
- default(TransitionTime),
- baseOffset,
- noDaylightTransitions: true);
- }
- }
- }
-
- return null;
- }
-
- private static TimeSpan? TZif_ParseOffsetString(ReadOnlySpan<char> offset)
- {
- TimeSpan? result = null;
-
- if (offset.Length > 0)
- {
- bool negative = offset[0] == '-';
- if (negative || offset[0] == '+')
- {
- offset = offset.Slice(1);
- }
-
- // Try parsing just hours first.
- // Note, TimeSpan.TryParseExact "%h" can't be used here because some time zones using values
- // like "26" or "144" and TimeSpan parsing would turn that into 26 or 144 *days* instead of hours.
- int hours;
- if (int.TryParse(offset, out hours))
- {
- result = new TimeSpan(hours, 0, 0);
- }
- else
- {
- TimeSpan parsedTimeSpan;
- if (TimeSpan.TryParseExact(offset, "g", CultureInfo.InvariantCulture, out parsedTimeSpan))
- {
- result = parsedTimeSpan;
- }
- }
-
- if (result.HasValue && negative)
- {
- result = result.GetValueOrDefault().Negate();
- }
- }
-
- return result;
- }
-
- private static DateTime ParseTimeOfDay(ReadOnlySpan<char> time)
- {
- DateTime timeOfDay;
- TimeSpan? timeOffset = TZif_ParseOffsetString(time);
- if (timeOffset.HasValue)
- {
- // This logic isn't correct and can't be corrected until https://github.com/dotnet/corefx/issues/2618 is fixed.
- // Some time zones use time values like, "26", "144", or "-2".
- // This allows the week to sometimes be week 4 and sometimes week 5 in the month.
- // For now, strip off any 'days' in the offset, and just get the time of day correct
- timeOffset = new TimeSpan(timeOffset.GetValueOrDefault().Hours, timeOffset.GetValueOrDefault().Minutes, timeOffset.GetValueOrDefault().Seconds);
- if (timeOffset.GetValueOrDefault() < TimeSpan.Zero)
- {
- timeOfDay = new DateTime(1, 1, 2, 0, 0, 0);
- }
- else
- {
- timeOfDay = new DateTime(1, 1, 1, 0, 0, 0);
- }
-
- timeOfDay += timeOffset.GetValueOrDefault();
- }
- else
- {
- // default to 2AM.
- timeOfDay = new DateTime(1, 1, 1, 2, 0, 0);
- }
-
- return timeOfDay;
- }
-
- private static TransitionTime TZif_CreateTransitionTimeFromPosixRule(ReadOnlySpan<char> date, ReadOnlySpan<char> time)
- {
- if (date.IsEmpty)
- {
- return default;
- }
-
- if (date[0] == 'M')
- {
- // Mm.w.d
- // This specifies day d of week w of month m. The day d must be between 0(Sunday) and 6.The week w must be between 1 and 5;
- // week 1 is the first week in which day d occurs, and week 5 specifies the last d day in the month. The month m should be between 1 and 12.
-
- int month;
- int week;
- DayOfWeek day;
- if (!TZif_ParseMDateRule(date, out month, out week, out day))
- {
- throw new InvalidTimeZoneException(SR.Format(SR.InvalidTimeZone_UnparseablePosixMDateString, date.ToString()));
- }
-
- return TransitionTime.CreateFloatingDateRule(ParseTimeOfDay(time), month, week, day);
- }
- else
- {
- if (date[0] != 'J')
- {
- // should be n Julian day format which we don't support.
- //
- // This specifies the Julian day, with n between 0 and 365. February 29 is counted in leap years.
- //
- // n would be a relative number from the begining of the year. which should handle if the
- // the year is a leap year or not.
- //
- // In leap year, n would be counted as:
- //
- // 0 30 31 59 60 90 335 365
- // |-------Jan--------|-------Feb--------|-------Mar--------|....|-------Dec--------|
- //
- // while in non leap year we'll have
- //
- // 0 30 31 58 59 89 334 364
- // |-------Jan--------|-------Feb--------|-------Mar--------|....|-------Dec--------|
- //
- //
- // For example if n is specified as 60, this means in leap year the rule will start at Mar 1,
- // while in non leap year the rule will start at Mar 2.
- //
- // If we need to support n format, we'll have to have a floating adjustment rule support this case.
-
- throw new InvalidTimeZoneException(SR.InvalidTimeZone_NJulianDayNotSupported);
- }
-
- // Julian day
- TZif_ParseJulianDay(date, out int month, out int day);
- return TransitionTime.CreateFixedDateRule(ParseTimeOfDay(time), month, day);
- }
- }
-
- /// <summary>
- /// Parses a string like Jn or n into month and day values.
- /// </summary>
- private static void TZif_ParseJulianDay(ReadOnlySpan<char> date, out int month, out int day)
- {
- // Jn
- // This specifies the Julian day, with n between 1 and 365.February 29 is never counted, even in leap years.
- Debug.Assert(!date.IsEmpty);
- Debug.Assert(date[0] == 'J');
- month = day = 0;
-
- int index = 1;
-
- if (index >= date.Length || ((uint)(date[index] - '0') > '9'-'0'))
- {
- throw new InvalidTimeZoneException(SR.InvalidTimeZone_InvalidJulianDay);
- }
-
- int julianDay = 0;
-
- do
- {
- julianDay = julianDay * 10 + (int) (date[index] - '0');
- index++;
- } while (index < date.Length && ((uint)(date[index] - '0') <= '9'-'0'));
-
- int[] days = GregorianCalendarHelper.DaysToMonth365;
-
- if (julianDay == 0 || julianDay > days[days.Length - 1])
- {
- throw new InvalidTimeZoneException(SR.InvalidTimeZone_InvalidJulianDay);
- }
-
- int i = 1;
- while (i < days.Length && julianDay > days[i])
- {
- i++;
- }
-
- Debug.Assert(i > 0 && i < days.Length);
-
- month = i;
- day = julianDay - days[i - 1];
- }
-
- /// <summary>
- /// Parses a string like Mm.w.d into month, week and DayOfWeek values.
- /// </summary>
- /// <returns>
- /// true if the parsing succeeded; otherwise, false.
- /// </returns>
- private static bool TZif_ParseMDateRule(ReadOnlySpan<char> dateRule, out int month, out int week, out DayOfWeek dayOfWeek)
- {
- if (dateRule[0] == 'M')
- {
- int monthWeekDotIndex = dateRule.IndexOf('.');
- if (monthWeekDotIndex > 0)
- {
- ReadOnlySpan<char> weekDaySpan = dateRule.Slice(monthWeekDotIndex + 1);
- int weekDayDotIndex = weekDaySpan.IndexOf('.');
- if (weekDayDotIndex > 0)
- {
- if (int.TryParse(dateRule.Slice(1, monthWeekDotIndex - 1), out month) &&
- int.TryParse(weekDaySpan.Slice(0, weekDayDotIndex), out week) &&
- int.TryParse(weekDaySpan.Slice(weekDayDotIndex + 1), out int day))
- {
- dayOfWeek = (DayOfWeek)day;
- return true;
- }
- }
- }
- }
-
- month = 0;
- week = 0;
- dayOfWeek = default(DayOfWeek);
- return false;
- }
-
- private static bool TZif_ParsePosixFormat(
- ReadOnlySpan<char> posixFormat,
- out ReadOnlySpan<char> standardName,
- out ReadOnlySpan<char> standardOffset,
- out ReadOnlySpan<char> daylightSavingsName,
- out ReadOnlySpan<char> daylightSavingsOffset,
- out ReadOnlySpan<char> start,
- out ReadOnlySpan<char> startTime,
- out ReadOnlySpan<char> end,
- out ReadOnlySpan<char> endTime)
- {
- standardName = null;
- standardOffset = null;
- daylightSavingsName = null;
- daylightSavingsOffset = null;
- start = null;
- startTime = null;
- end = null;
- endTime = null;
-
- int index = 0;
- standardName = TZif_ParsePosixName(posixFormat, ref index);
- standardOffset = TZif_ParsePosixOffset(posixFormat, ref index);
-
- daylightSavingsName = TZif_ParsePosixName(posixFormat, ref index);
- if (!daylightSavingsName.IsEmpty)
- {
- daylightSavingsOffset = TZif_ParsePosixOffset(posixFormat, ref index);
-
- if (index < posixFormat.Length && posixFormat[index] == ',')
- {
- index++;
- TZif_ParsePosixDateTime(posixFormat, ref index, out start, out startTime);
-
- if (index < posixFormat.Length && posixFormat[index] == ',')
- {
- index++;
- TZif_ParsePosixDateTime(posixFormat, ref index, out end, out endTime);
- }
- }
- }
-
- return !standardName.IsEmpty && !standardOffset.IsEmpty;
- }
-
- private static ReadOnlySpan<char> TZif_ParsePosixName(ReadOnlySpan<char> posixFormat, ref int index)
- {
- bool isBracketEnclosed = index < posixFormat.Length && posixFormat[index] == '<';
- if (isBracketEnclosed)
- {
- // move past the opening bracket
- index++;
-
- ReadOnlySpan<char> result = TZif_ParsePosixString(posixFormat, ref index, c => c == '>');
-
- // move past the closing bracket
- if (index < posixFormat.Length && posixFormat[index] == '>')
- {
- index++;
- }
-
- return result;
- }
- else
- {
- return TZif_ParsePosixString(
- posixFormat,
- ref index,
- c => char.IsDigit(c) || c == '+' || c == '-' || c == ',');
- }
- }
-
- private static ReadOnlySpan<char> TZif_ParsePosixOffset(ReadOnlySpan<char> posixFormat, ref int index) =>
- TZif_ParsePosixString(posixFormat, ref index, c => !char.IsDigit(c) && c != '+' && c != '-' && c != ':');
-
- private static void TZif_ParsePosixDateTime(ReadOnlySpan<char> posixFormat, ref int index, out ReadOnlySpan<char> date, out ReadOnlySpan<char> time)
- {
- time = null;
-
- date = TZif_ParsePosixDate(posixFormat, ref index);
- if (index < posixFormat.Length && posixFormat[index] == '/')
- {
- index++;
- time = TZif_ParsePosixTime(posixFormat, ref index);
- }
- }
-
- private static ReadOnlySpan<char> TZif_ParsePosixDate(ReadOnlySpan<char> posixFormat, ref int index) =>
- TZif_ParsePosixString(posixFormat, ref index, c => c == '/' || c == ',');
-
- private static ReadOnlySpan<char> TZif_ParsePosixTime(ReadOnlySpan<char> posixFormat, ref int index) =>
- TZif_ParsePosixString(posixFormat, ref index, c => c == ',');
-
- private static ReadOnlySpan<char> TZif_ParsePosixString(ReadOnlySpan<char> posixFormat, ref int index, Func<char, bool> breakCondition)
- {
- int startIndex = index;
- for (; index < posixFormat.Length; index++)
- {
- char current = posixFormat[index];
- if (breakCondition(current))
- {
- break;
- }
- }
-
- return posixFormat.Slice(startIndex, index - startIndex);
- }
-
- // Returns the Substring from zoneAbbreviations starting at index and ending at '\0'
- // zoneAbbreviations is expected to be in the form: "PST\0PDT\0PWT\0\PPT"
- private static string TZif_GetZoneAbbreviation(string zoneAbbreviations, int index)
- {
- int lastIndex = zoneAbbreviations.IndexOf('\0', index);
- return lastIndex > 0 ?
- zoneAbbreviations.Substring(index, lastIndex - index) :
- zoneAbbreviations.Substring(index);
- }
-
- // Converts an array of bytes into an int - always using standard byte order (Big Endian)
- // per TZif file standard
- private static unsafe int TZif_ToInt32(byte[] value, int startIndex)
- {
- fixed (byte* pbyte = &value[startIndex])
- {
- return (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3));
- }
- }
-
- // Converts an array of bytes into a long - always using standard byte order (Big Endian)
- // per TZif file standard
- private static unsafe long TZif_ToInt64(byte[] value, int startIndex)
- {
- fixed (byte* pbyte = &value[startIndex])
- {
- int i1 = (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3));
- int i2 = (*(pbyte + 4) << 24) | (*(pbyte + 5) << 16) | (*(pbyte + 6) << 8) | (*(pbyte + 7));
- return (uint)i2 | ((long)i1 << 32);
- }
- }
-
- private static long TZif_ToUnixTime(byte[] value, int startIndex, TZVersion version) =>
- version != TZVersion.V1 ?
- TZif_ToInt64(value, startIndex) :
- TZif_ToInt32(value, startIndex);
-
- private static DateTime TZif_UnixTimeToDateTime(long unixTime) =>
- unixTime < DateTimeOffset.UnixMinSeconds ? DateTime.MinValue :
- unixTime > DateTimeOffset.UnixMaxSeconds ? DateTime.MaxValue :
- DateTimeOffset.FromUnixTimeSeconds(unixTime).UtcDateTime;
-
- private static void TZif_ParseRaw(byte[] data, out TZifHead t, out DateTime[] dts, out byte[] typeOfLocalTime, out TZifType[] transitionType,
- out string zoneAbbreviations, out bool[] StandardTime, out bool[] GmtTime, out string? futureTransitionsPosixFormat)
- {
- // initialize the out parameters in case the TZifHead ctor throws
- dts = null!;
- typeOfLocalTime = null!;
- transitionType = null!;
- zoneAbbreviations = string.Empty;
- StandardTime = null!;
- GmtTime = null!;
- futureTransitionsPosixFormat = null;
-
- // read in the 44-byte TZ header containing the count/length fields
- //
- int index = 0;
- t = new TZifHead(data, index);
- index += TZifHead.Length;
-
- int timeValuesLength = 4; // the first version uses 4-bytes to specify times
- if (t.Version != TZVersion.V1)
- {
- // move index past the V1 information to read the V2 information
- index += (int)((timeValuesLength * t.TimeCount) + t.TimeCount + (6 * t.TypeCount) + ((timeValuesLength + 4) * t.LeapCount) + t.IsStdCount + t.IsGmtCount + t.CharCount);
-
- // read the V2 header
- t = new TZifHead(data, index);
- index += TZifHead.Length;
- timeValuesLength = 8; // the second version uses 8-bytes
- }
-
- // initialize the containers for the rest of the TZ data
- dts = new DateTime[t.TimeCount];
- typeOfLocalTime = new byte[t.TimeCount];
- transitionType = new TZifType[t.TypeCount];
- zoneAbbreviations = string.Empty;
- StandardTime = new bool[t.TypeCount];
- GmtTime = new bool[t.TypeCount];
-
- // read in the UTC transition points and convert them to Windows
- //
- for (int i = 0; i < t.TimeCount; i++)
- {
- long unixTime = TZif_ToUnixTime(data, index, t.Version);
- dts[i] = TZif_UnixTimeToDateTime(unixTime);
- index += timeValuesLength;
- }
-
- // read in the Type Indices; there is a 1:1 mapping of UTC transition points to Type Indices
- // these indices directly map to the array index in the transitionType array below
- //
- for (int i = 0; i < t.TimeCount; i++)
- {
- typeOfLocalTime[i] = data[index];
- index++;
- }
-
- // read in the Type table. Each 6-byte entry represents
- // {UtcOffset, IsDst, AbbreviationIndex}
- //
- // each AbbreviationIndex is a character index into the zoneAbbreviations string below
- //
- for (int i = 0; i < t.TypeCount; i++)
- {
- transitionType[i] = new TZifType(data, index);
- index += 6;
- }
-
- // read in the Abbreviation ASCII string. This string will be in the form:
- // "PST\0PDT\0PWT\0\PPT"
- //
- Encoding enc = Encoding.UTF8;
- zoneAbbreviations = enc.GetString(data, index, (int)t.CharCount);
- index += (int)t.CharCount;
-
- // skip ahead of the Leap-Seconds Adjustment data. In a future release, consider adding
- // support for Leap-Seconds
- //
- index += (int)(t.LeapCount * (timeValuesLength + 4)); // skip the leap second transition times
-
- // read in the Standard Time table. There should be a 1:1 mapping between Type-Index and Standard
- // Time table entries.
- //
- // TRUE = transition time is standard time
- // FALSE = transition time is wall clock time
- // ABSENT = transition time is wall clock time
- //
- for (int i = 0; i < t.IsStdCount && i < t.TypeCount && index < data.Length; i++)
- {
- StandardTime[i] = (data[index++] != 0);
- }
-
- // read in the GMT Time table. There should be a 1:1 mapping between Type-Index and GMT Time table
- // entries.
- //
- // TRUE = transition time is UTC
- // FALSE = transition time is local time
- // ABSENT = transition time is local time
- //
- for (int i = 0; i < t.IsGmtCount && i < t.TypeCount && index < data.Length; i++)
- {
- GmtTime[i] = (data[index++] != 0);
- }
-
- if (t.Version != TZVersion.V1)
- {
- // read the POSIX-style format, which should be wrapped in newlines with the last newline at the end of the file
- if (data[index++] == '\n' && data[data.Length - 1] == '\n')
- {
- futureTransitionsPosixFormat = enc.GetString(data, index, data.Length - index - 1);
- }
- }
- }
-
- /// <summary>
- /// Normalize adjustment rule offset so that it is within valid range
- /// This method should not be called at all but is here in case something changes in the future
- /// or if really old time zones are present on the OS (no combination is known at the moment)
- /// </summary>
- private static void NormalizeAdjustmentRuleOffset(TimeSpan baseUtcOffset, [NotNull] ref AdjustmentRule adjustmentRule)
- {
- // Certain time zones such as:
- // Time Zone start date end date offset
- // -----------------------------------------------------
- // America/Yakutat 0001-01-01 1867-10-18 14:41:00
- // America/Yakutat 1867-10-18 1900-08-20 14:41:00
- // America/Sitka 0001-01-01 1867-10-18 14:58:00
- // America/Sitka 1867-10-18 1900-08-20 14:58:00
- // Asia/Manila 0001-01-01 1844-12-31 -15:56:00
- // Pacific/Guam 0001-01-01 1845-01-01 -14:21:00
- // Pacific/Saipan 0001-01-01 1845-01-01 -14:21:00
- //
- // have larger offset than currently supported by framework.
- // If for whatever reason we find that time zone exceeding max
- // offset of 14h this function will truncate it to the max valid offset.
- // Updating max offset may cause problems with interacting with SQL server
- // which uses SQL DATETIMEOFFSET field type which was originally designed to be
- // bit-for-bit compatible with DateTimeOffset.
-
- TimeSpan utcOffset = GetUtcOffset(baseUtcOffset, adjustmentRule);
-
- // utc base offset delta increment
- TimeSpan adjustment = TimeSpan.Zero;
-
- if (utcOffset > MaxOffset)
- {
- adjustment = MaxOffset - utcOffset;
- }
- else if (utcOffset < MinOffset)
- {
- adjustment = MinOffset - utcOffset;
- }
-
- if (adjustment != TimeSpan.Zero)
- {
- adjustmentRule = AdjustmentRule.CreateAdjustmentRule(
- adjustmentRule.DateStart,
- adjustmentRule.DateEnd,
- adjustmentRule.DaylightDelta,
- adjustmentRule.DaylightTransitionStart,
- adjustmentRule.DaylightTransitionEnd,
- adjustmentRule.BaseUtcOffsetDelta + adjustment,
- adjustmentRule.NoDaylightTransitions);
- }
- }
-
- private struct TZifType
- {
- public const int Length = 6;
-
- public readonly TimeSpan UtcOffset;
- public readonly bool IsDst;
- public readonly byte AbbreviationIndex;
-
- public TZifType(byte[] data, int index)
- {
- if (data == null || data.Length < index + Length)
- {
- throw new ArgumentException(SR.Argument_TimeZoneInfoInvalidTZif, nameof(data));
- }
- UtcOffset = new TimeSpan(0, 0, TZif_ToInt32(data, index + 00));
- IsDst = (data[index + 4] != 0);
- AbbreviationIndex = data[index + 5];
- }
- }
-
- private struct TZifHead
- {
- public const int Length = 44;
-
- public readonly uint Magic; // TZ_MAGIC "TZif"
- public readonly TZVersion Version; // 1 byte for a \0 or 2 or 3
- // public byte[15] Reserved; // reserved for future use
- public readonly uint IsGmtCount; // number of transition time flags
- public readonly uint IsStdCount; // number of transition time flags
- public readonly uint LeapCount; // number of leap seconds
- public readonly uint TimeCount; // number of transition times
- public readonly uint TypeCount; // number of local time types
- public readonly uint CharCount; // number of abbreviated characters
-
- public TZifHead(byte[] data, int index)
- {
- if (data == null || data.Length < Length)
- {
- throw new ArgumentException("bad data", nameof(data));
- }
-
- Magic = (uint)TZif_ToInt32(data, index + 00);
-
- if (Magic != 0x545A6966)
- {
- // 0x545A6966 = {0x54, 0x5A, 0x69, 0x66} = "TZif"
- throw new ArgumentException(SR.Argument_TimeZoneInfoBadTZif, nameof(data));
- }
-
- byte version = data[index + 04];
- Version =
- version == '2' ? TZVersion.V2 :
- version == '3' ? TZVersion.V3 :
- TZVersion.V1; // default/fallback to V1 to guard against future, unsupported version numbers
-
- // skip the 15 byte reserved field
-
- // don't use the BitConverter class which parses data
- // based on the Endianess of the machine architecture.
- // this data is expected to always be in "standard byte order",
- // regardless of the machine it is being processed on.
-
- IsGmtCount = (uint)TZif_ToInt32(data, index + 20);
- IsStdCount = (uint)TZif_ToInt32(data, index + 24);
- LeapCount = (uint)TZif_ToInt32(data, index + 28);
- TimeCount = (uint)TZif_ToInt32(data, index + 32);
- TypeCount = (uint)TZif_ToInt32(data, index + 36);
- CharCount = (uint)TZif_ToInt32(data, index + 40);
- }
- }
-
- private enum TZVersion : byte
- {
- V1 = 0,
- V2,
- V3,
- // when adding more versions, ensure all the logic using TZVersion is still correct
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs b/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs
deleted file mode 100644
index c265600a75f..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs
+++ /dev/null
@@ -1,980 +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 System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-using System.Security;
-using System.Threading;
-
-using Microsoft.Win32.SafeHandles;
-
-using Internal.Win32;
-
-using REG_TZI_FORMAT = Interop.Kernel32.REG_TZI_FORMAT;
-using TIME_ZONE_INFORMATION = Interop.Kernel32.TIME_ZONE_INFORMATION;
-using TIME_DYNAMIC_ZONE_INFORMATION = Interop.Kernel32.TIME_DYNAMIC_ZONE_INFORMATION;
-
-namespace System
-{
- public sealed partial class TimeZoneInfo
- {
- // registry constants for the 'Time Zones' hive
- //
- private const string TimeZonesRegistryHive = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones";
- private const string DisplayValue = "Display";
- private const string DaylightValue = "Dlt";
- private const string StandardValue = "Std";
- private const string MuiDisplayValue = "MUI_Display";
- private const string MuiDaylightValue = "MUI_Dlt";
- private const string MuiStandardValue = "MUI_Std";
- private const string TimeZoneInfoValue = "TZI";
- private const string FirstEntryValue = "FirstEntry";
- private const string LastEntryValue = "LastEntry";
-
- private const int MaxKeyLength = 255;
-
- private sealed partial class CachedData
- {
- private static TimeZoneInfo GetCurrentOneYearLocal()
- {
- // load the data from the OS
- TIME_ZONE_INFORMATION timeZoneInformation;
- uint result = Interop.Kernel32.GetTimeZoneInformation(out timeZoneInformation);
- return result == Interop.Kernel32.TIME_ZONE_ID_INVALID ?
- CreateCustomTimeZone(LocalId, TimeSpan.Zero, LocalId, LocalId) :
- GetLocalTimeZoneFromWin32Data(timeZoneInformation, dstDisabled: false);
- }
-
- private volatile OffsetAndRule? _oneYearLocalFromUtc;
-
- public OffsetAndRule GetOneYearLocalFromUtc(int year)
- {
- OffsetAndRule? oneYearLocFromUtc = _oneYearLocalFromUtc;
- if (oneYearLocFromUtc == null || oneYearLocFromUtc.Year != year)
- {
- TimeZoneInfo currentYear = GetCurrentOneYearLocal();
- AdjustmentRule? rule = currentYear._adjustmentRules?[0];
- oneYearLocFromUtc = new OffsetAndRule(year, currentYear.BaseUtcOffset, rule);
- _oneYearLocalFromUtc = oneYearLocFromUtc;
- }
- return oneYearLocFromUtc;
- }
- }
-
- private sealed class OffsetAndRule
- {
- public readonly int Year;
- public readonly TimeSpan Offset;
- public readonly AdjustmentRule? Rule;
-
- public OffsetAndRule(int year, TimeSpan offset, AdjustmentRule? rule)
- {
- Year = year;
- Offset = offset;
- Rule = rule;
- }
- }
-
- /// <summary>
- /// Returns a cloned array of AdjustmentRule objects
- /// </summary>
- public AdjustmentRule[] GetAdjustmentRules()
- {
- if (_adjustmentRules == null)
- {
- return Array.Empty<AdjustmentRule>();
- }
-
- return (AdjustmentRule[])_adjustmentRules.Clone();
- }
-
- private static void PopulateAllSystemTimeZones(CachedData cachedData)
- {
- Debug.Assert(Monitor.IsEntered(cachedData));
-
- using (RegistryKey? reg = Registry.LocalMachine.OpenSubKey(TimeZonesRegistryHive, writable: false))
- {
- if (reg != null)
- {
- foreach (string keyName in reg.GetSubKeyNames())
- {
- TryGetTimeZone(keyName, false, out _, out _, cachedData); // populate the cache
- }
- }
- }
- }
-
- private TimeZoneInfo(in TIME_ZONE_INFORMATION zone, bool dstDisabled)
- {
- string standardName = zone.GetStandardName();
- if (standardName.Length == 0)
- {
- _id = LocalId; // the ID must contain at least 1 character - initialize _id to "Local"
- }
- else
- {
- _id = standardName;
- }
- _baseUtcOffset = new TimeSpan(0, -(zone.Bias), 0);
-
- if (!dstDisabled)
- {
- // only create the adjustment rule if DST is enabled
- REG_TZI_FORMAT regZone = new REG_TZI_FORMAT(zone);
- AdjustmentRule? rule = CreateAdjustmentRuleFromTimeZoneInformation(regZone, DateTime.MinValue.Date, DateTime.MaxValue.Date, zone.Bias);
- if (rule != null)
- {
- _adjustmentRules = new[] { rule };
- }
- }
-
- ValidateTimeZoneInfo(_id, _baseUtcOffset, _adjustmentRules, out _supportsDaylightSavingTime);
- _displayName = standardName;
- _standardDisplayName = standardName;
- _daylightDisplayName = zone.GetDaylightName();
- }
-
- /// <summary>
- /// Helper function to check if the current TimeZoneInformation struct does not support DST.
- /// This check returns true when the DaylightDate == StandardDate.
- /// This check is only meant to be used for "Local".
- /// </summary>
- private static bool CheckDaylightSavingTimeNotSupported(in TIME_ZONE_INFORMATION timeZone) =>
- timeZone.DaylightDate.Equals(timeZone.StandardDate);
-
- /// <summary>
- /// Converts a REG_TZI_FORMAT struct to an AdjustmentRule.
- /// </summary>
- private static AdjustmentRule? CreateAdjustmentRuleFromTimeZoneInformation(in REG_TZI_FORMAT timeZoneInformation, DateTime startDate, DateTime endDate, int defaultBaseUtcOffset)
- {
- bool supportsDst = timeZoneInformation.StandardDate.Month != 0;
-
- if (!supportsDst)
- {
- if (timeZoneInformation.Bias == defaultBaseUtcOffset)
- {
- // this rule will not contain any information to be used to adjust dates. just ignore it
- return null;
- }
-
- return AdjustmentRule.CreateAdjustmentRule(
- startDate,
- endDate,
- TimeSpan.Zero, // no daylight saving transition
- TransitionTime.CreateFixedDateRule(DateTime.MinValue, 1, 1),
- TransitionTime.CreateFixedDateRule(DateTime.MinValue.AddMilliseconds(1), 1, 1),
- new TimeSpan(0, defaultBaseUtcOffset - timeZoneInformation.Bias, 0), // Bias delta is all what we need from this rule
- noDaylightTransitions: false);
- }
-
- //
- // Create an AdjustmentRule with TransitionTime objects
- //
- TransitionTime daylightTransitionStart;
- if (!TransitionTimeFromTimeZoneInformation(timeZoneInformation, out daylightTransitionStart, readStartDate: true))
- {
- return null;
- }
-
- TransitionTime daylightTransitionEnd;
- if (!TransitionTimeFromTimeZoneInformation(timeZoneInformation, out daylightTransitionEnd, readStartDate: false))
- {
- return null;
- }
-
- if (daylightTransitionStart.Equals(daylightTransitionEnd))
- {
- // this happens when the time zone does support DST but the OS has DST disabled
- return null;
- }
-
- return AdjustmentRule.CreateAdjustmentRule(
- startDate,
- endDate,
- new TimeSpan(0, -timeZoneInformation.DaylightBias, 0),
- daylightTransitionStart,
- daylightTransitionEnd,
- new TimeSpan(0, defaultBaseUtcOffset - timeZoneInformation.Bias, 0),
- noDaylightTransitions: false);
- }
-
- /// <summary>
- /// Helper function that searches the registry for a time zone entry
- /// that matches the TimeZoneInformation struct.
- /// </summary>
- private static string? FindIdFromTimeZoneInformation(in TIME_ZONE_INFORMATION timeZone, out bool dstDisabled)
- {
- dstDisabled = false;
-
- using (RegistryKey? key = Registry.LocalMachine.OpenSubKey(TimeZonesRegistryHive, writable: false))
- {
- if (key == null)
- {
- return null;
- }
-
- foreach (string keyName in key.GetSubKeyNames())
- {
- if (TryCompareTimeZoneInformationToRegistry(timeZone, keyName, out dstDisabled))
- {
- return keyName;
- }
- }
- }
-
- return null;
- }
-
- /// <summary>
- /// Helper function for retrieving the local system time zone.
- /// May throw COMException, TimeZoneNotFoundException, InvalidTimeZoneException.
- /// Assumes cachedData lock is taken.
- /// </summary>
- /// <returns>A new TimeZoneInfo instance.</returns>
- private static TimeZoneInfo GetLocalTimeZone(CachedData cachedData)
- {
- Debug.Assert(Monitor.IsEntered(cachedData));
-
- //
- // Try using the "kernel32!GetDynamicTimeZoneInformation" API to get the "id"
- //
-
- TIME_DYNAMIC_ZONE_INFORMATION dynamicTimeZoneInformation;
- // call kernel32!GetDynamicTimeZoneInformation...
- uint result = Interop.Kernel32.GetDynamicTimeZoneInformation(out dynamicTimeZoneInformation);
- if (result == Interop.Kernel32.TIME_ZONE_ID_INVALID)
- {
- // return a dummy entry
- return CreateCustomTimeZone(LocalId, TimeSpan.Zero, LocalId, LocalId);
- }
-
- // check to see if we can use the key name returned from the API call
- string dynamicTimeZoneKeyName = dynamicTimeZoneInformation.GetTimeZoneKeyName();
- if (dynamicTimeZoneKeyName.Length != 0)
- {
- if (TryGetTimeZone(dynamicTimeZoneKeyName, dynamicTimeZoneInformation.DynamicDaylightTimeDisabled != 0, out TimeZoneInfo? zone, out _, cachedData) == TimeZoneInfoResult.Success)
- {
- // successfully loaded the time zone from the registry
- return zone!;
- }
- }
-
- var timeZoneInformation = new TIME_ZONE_INFORMATION(dynamicTimeZoneInformation);
-
- // the key name was not returned or it pointed to a bogus entry - search for the entry ourselves
- string? id = FindIdFromTimeZoneInformation(timeZoneInformation, out bool dstDisabled);
-
- if (id != null)
- {
- if (TryGetTimeZone(id, dstDisabled, out TimeZoneInfo? zone, out _, cachedData) == TimeZoneInfoResult.Success)
- {
- // successfully loaded the time zone from the registry
- return zone!;
- }
- }
-
- // We could not find the data in the registry. Fall back to using
- // the data from the Win32 API
- return GetLocalTimeZoneFromWin32Data(timeZoneInformation, dstDisabled);
- }
-
- /// <summary>
- /// Helper function used by 'GetLocalTimeZone()' - this function wraps a bunch of
- /// try/catch logic for handling the TimeZoneInfo private constructor that takes
- /// a TIME_ZONE_INFORMATION structure.
- /// </summary>
- private static TimeZoneInfo GetLocalTimeZoneFromWin32Data(in TIME_ZONE_INFORMATION timeZoneInformation, bool dstDisabled)
- {
- // first try to create the TimeZoneInfo with the original 'dstDisabled' flag
- try
- {
- return new TimeZoneInfo(timeZoneInformation, dstDisabled);
- }
- catch (ArgumentException) { }
- catch (InvalidTimeZoneException) { }
-
- // if 'dstDisabled' was false then try passing in 'true' as a last ditch effort
- if (!dstDisabled)
- {
- try
- {
- return new TimeZoneInfo(timeZoneInformation, dstDisabled: true);
- }
- catch (ArgumentException) { }
- catch (InvalidTimeZoneException) { }
- }
-
- // the data returned from Windows is completely bogus; return a dummy entry
- return CreateCustomTimeZone(LocalId, TimeSpan.Zero, LocalId, LocalId);
- }
-
- /// <summary>
- /// Helper function for retrieving a TimeZoneInfo object by time_zone_name.
- /// This function wraps the logic necessary to keep the private
- /// SystemTimeZones cache in working order
- ///
- /// This function will either return a valid TimeZoneInfo instance or
- /// it will throw 'InvalidTimeZoneException' / 'TimeZoneNotFoundException'.
- /// </summary>
- public static TimeZoneInfo FindSystemTimeZoneById(string id)
- {
- // Special case for Utc to avoid having TryGetTimeZone creating a new Utc object
- if (string.Equals(id, UtcId, StringComparison.OrdinalIgnoreCase))
- {
- return Utc;
- }
-
- if (id == null)
- {
- throw new ArgumentNullException(nameof(id));
- }
- if (id.Length == 0 || id.Length > MaxKeyLength || id.Contains('\0'))
- {
- throw new TimeZoneNotFoundException(SR.Format(SR.TimeZoneNotFound_MissingData, id));
- }
-
- TimeZoneInfo? value;
- Exception? e;
-
- TimeZoneInfoResult result;
-
- CachedData cachedData = s_cachedData;
-
- lock (cachedData)
- {
- result = TryGetTimeZone(id, false, out value, out e, cachedData);
- }
-
- if (result == TimeZoneInfoResult.Success)
- {
- return value!;
- }
- else if (result == TimeZoneInfoResult.InvalidTimeZoneException)
- {
- throw new InvalidTimeZoneException(SR.Format(SR.InvalidTimeZone_InvalidRegistryData, id), e);
- }
- else if (result == TimeZoneInfoResult.SecurityException)
- {
- throw new SecurityException(SR.Format(SR.Security_CannotReadRegistryData, id), e);
- }
- else
- {
- throw new TimeZoneNotFoundException(SR.Format(SR.TimeZoneNotFound_MissingData, id), e);
- }
- }
-
- // DateTime.Now fast path that avoids allocating an historically accurate TimeZoneInfo.Local and just creates a 1-year (current year) accurate time zone
- internal static TimeSpan GetDateTimeNowUtcOffsetFromUtc(DateTime time, out bool isAmbiguousLocalDst)
- {
- isAmbiguousLocalDst = false;
- int timeYear = time.Year;
-
- OffsetAndRule match = s_cachedData.GetOneYearLocalFromUtc(timeYear);
- TimeSpan baseOffset = match.Offset;
-
- if (match.Rule != null)
- {
- baseOffset += match.Rule.BaseUtcOffsetDelta;
- if (match.Rule.HasDaylightSaving)
- {
- bool isDaylightSavings = GetIsDaylightSavingsFromUtc(time, timeYear, match.Offset, match.Rule, null, out isAmbiguousLocalDst, Local);
- baseOffset += (isDaylightSavings ? match.Rule.DaylightDelta : TimeSpan.Zero /* FUTURE: rule.StandardDelta */);
- }
- }
-
- return baseOffset;
- }
-
- /// <summary>
- /// Converts a REG_TZI_FORMAT struct to a TransitionTime
- /// - When the argument 'readStart' is true the corresponding daylightTransitionTimeStart field is read
- /// - When the argument 'readStart' is false the corresponding dayightTransitionTimeEnd field is read
- /// </summary>
- private static bool TransitionTimeFromTimeZoneInformation(in REG_TZI_FORMAT timeZoneInformation, out TransitionTime transitionTime, bool readStartDate)
- {
- //
- // SYSTEMTIME -
- //
- // If the time zone does not support daylight saving time or if the caller needs
- // to disable daylight saving time, the wMonth member in the SYSTEMTIME structure
- // must be zero. If this date is specified, the DaylightDate value in the
- // TIME_ZONE_INFORMATION structure must also be specified. Otherwise, the system
- // assumes the time zone data is invalid and no changes will be applied.
- //
- bool supportsDst = (timeZoneInformation.StandardDate.Month != 0);
-
- if (!supportsDst)
- {
- transitionTime = default;
- return false;
- }
-
- //
- // SYSTEMTIME -
- //
- // * FixedDateRule -
- // If the Year member is not zero, the transition date is absolute; it will only occur one time
- //
- // * FloatingDateRule -
- // To select the correct day in the month, set the Year member to zero, the Hour and Minute
- // members to the transition time, the DayOfWeek member to the appropriate weekday, and the
- // Day member to indicate the occurence of the day of the week within the month (first through fifth).
- //
- // Using this notation, specify the 2:00a.m. on the first Sunday in April as follows:
- // Hour = 2,
- // Month = 4,
- // DayOfWeek = 0,
- // Day = 1.
- //
- // Specify 2:00a.m. on the last Thursday in October as follows:
- // Hour = 2,
- // Month = 10,
- // DayOfWeek = 4,
- // Day = 5.
- //
- if (readStartDate)
- {
- //
- // read the "daylightTransitionStart"
- //
- if (timeZoneInformation.DaylightDate.Year == 0)
- {
- transitionTime = TransitionTime.CreateFloatingDateRule(
- new DateTime(1, /* year */
- 1, /* month */
- 1, /* day */
- timeZoneInformation.DaylightDate.Hour,
- timeZoneInformation.DaylightDate.Minute,
- timeZoneInformation.DaylightDate.Second,
- timeZoneInformation.DaylightDate.Milliseconds),
- timeZoneInformation.DaylightDate.Month,
- timeZoneInformation.DaylightDate.Day, /* Week 1-5 */
- (DayOfWeek)timeZoneInformation.DaylightDate.DayOfWeek);
- }
- else
- {
- transitionTime = TransitionTime.CreateFixedDateRule(
- new DateTime(1, /* year */
- 1, /* month */
- 1, /* day */
- timeZoneInformation.DaylightDate.Hour,
- timeZoneInformation.DaylightDate.Minute,
- timeZoneInformation.DaylightDate.Second,
- timeZoneInformation.DaylightDate.Milliseconds),
- timeZoneInformation.DaylightDate.Month,
- timeZoneInformation.DaylightDate.Day);
- }
- }
- else
- {
- //
- // read the "daylightTransitionEnd"
- //
- if (timeZoneInformation.StandardDate.Year == 0)
- {
- transitionTime = TransitionTime.CreateFloatingDateRule(
- new DateTime(1, /* year */
- 1, /* month */
- 1, /* day */
- timeZoneInformation.StandardDate.Hour,
- timeZoneInformation.StandardDate.Minute,
- timeZoneInformation.StandardDate.Second,
- timeZoneInformation.StandardDate.Milliseconds),
- timeZoneInformation.StandardDate.Month,
- timeZoneInformation.StandardDate.Day, /* Week 1-5 */
- (DayOfWeek)timeZoneInformation.StandardDate.DayOfWeek);
- }
- else
- {
- transitionTime = TransitionTime.CreateFixedDateRule(
- new DateTime(1, /* year */
- 1, /* month */
- 1, /* day */
- timeZoneInformation.StandardDate.Hour,
- timeZoneInformation.StandardDate.Minute,
- timeZoneInformation.StandardDate.Second,
- timeZoneInformation.StandardDate.Milliseconds),
- timeZoneInformation.StandardDate.Month,
- timeZoneInformation.StandardDate.Day);
- }
- }
-
- return true;
- }
-
- /// <summary>
- /// Helper function that takes:
- /// 1. A string representing a time_zone_name registry key name.
- /// 2. A REG_TZI_FORMAT struct containing the default rule.
- /// 3. An AdjustmentRule[] out-parameter.
- /// </summary>
- private static bool TryCreateAdjustmentRules(string id, in REG_TZI_FORMAT defaultTimeZoneInformation, out AdjustmentRule[]? rules, out Exception? e, int defaultBaseUtcOffset)
- {
- rules = null;
- e = null;
-
- try
- {
- // Optional, Dynamic Time Zone Registry Data
- // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- //
- // HKLM
- // Software
- // Microsoft
- // Windows NT
- // CurrentVersion
- // Time Zones
- // <time_zone_name>
- // Dynamic DST
- // * "FirstEntry" REG_DWORD "1980"
- // First year in the table. If the current year is less than this value,
- // this entry will be used for DST boundaries
- // * "LastEntry" REG_DWORD "2038"
- // Last year in the table. If the current year is greater than this value,
- // this entry will be used for DST boundaries"
- // * "<year1>" REG_BINARY REG_TZI_FORMAT
- // * "<year2>" REG_BINARY REG_TZI_FORMAT
- // * "<year3>" REG_BINARY REG_TZI_FORMAT
- //
- using (RegistryKey? dynamicKey = Registry.LocalMachine.OpenSubKey(TimeZonesRegistryHive + "\\" + id + "\\Dynamic DST", writable: false))
- {
- if (dynamicKey == null)
- {
- AdjustmentRule? rule = CreateAdjustmentRuleFromTimeZoneInformation(
- defaultTimeZoneInformation, DateTime.MinValue.Date, DateTime.MaxValue.Date, defaultBaseUtcOffset);
- if (rule != null)
- {
- rules = new[] { rule };
- }
- return true;
- }
-
- //
- // loop over all of the "<time_zone_name>\Dynamic DST" hive entries
- //
- // read FirstEntry {MinValue - (year1, 12, 31)}
- // read MiddleEntry {(yearN, 1, 1) - (yearN, 12, 31)}
- // read LastEntry {(yearN, 1, 1) - MaxValue }
-
- // read the FirstEntry and LastEntry key values (ex: "1980", "2038")
- int first = (int)dynamicKey.GetValue(FirstEntryValue, -1);
- int last = (int)dynamicKey.GetValue(LastEntryValue, -1);
-
- if (first == -1 || last == -1 || first > last)
- {
- return false;
- }
-
- // read the first year entry
- REG_TZI_FORMAT dtzi;
-
- if (!TryGetTimeZoneEntryFromRegistry(dynamicKey, first.ToString(CultureInfo.InvariantCulture), out dtzi))
- {
- return false;
- }
-
- if (first == last)
- {
- // there is just 1 dynamic rule for this time zone.
- AdjustmentRule? rule = CreateAdjustmentRuleFromTimeZoneInformation(dtzi, DateTime.MinValue.Date, DateTime.MaxValue.Date, defaultBaseUtcOffset);
- if (rule != null)
- {
- rules = new[] { rule };
- }
- return true;
- }
-
- List<AdjustmentRule> rulesList = new List<AdjustmentRule>(1);
-
- // there are more than 1 dynamic rules for this time zone.
- AdjustmentRule? firstRule = CreateAdjustmentRuleFromTimeZoneInformation(
- dtzi,
- DateTime.MinValue.Date, // MinValue
- new DateTime(first, 12, 31), // December 31, <FirstYear>
- defaultBaseUtcOffset);
-
- if (firstRule != null)
- {
- rulesList.Add(firstRule);
- }
-
- // read the middle year entries
- for (int i = first + 1; i < last; i++)
- {
- if (!TryGetTimeZoneEntryFromRegistry(dynamicKey, i.ToString(CultureInfo.InvariantCulture), out dtzi))
- {
- return false;
- }
- AdjustmentRule? middleRule = CreateAdjustmentRuleFromTimeZoneInformation(
- dtzi,
- new DateTime(i, 1, 1), // January 01, <Year>
- new DateTime(i, 12, 31), // December 31, <Year>
- defaultBaseUtcOffset);
-
- if (middleRule != null)
- {
- rulesList.Add(middleRule);
- }
- }
-
- // read the last year entry
- if (!TryGetTimeZoneEntryFromRegistry(dynamicKey, last.ToString(CultureInfo.InvariantCulture), out dtzi))
- {
- return false;
- }
- AdjustmentRule? lastRule = CreateAdjustmentRuleFromTimeZoneInformation(
- dtzi,
- new DateTime(last, 1, 1), // January 01, <LastYear>
- DateTime.MaxValue.Date, // MaxValue
- defaultBaseUtcOffset);
-
- if (lastRule != null)
- {
- rulesList.Add(lastRule);
- }
-
- // convert the List to an AdjustmentRule array
- if (rulesList.Count != 0)
- {
- rules = rulesList.ToArray();
- }
- } // end of: using (RegistryKey dynamicKey...
- }
- catch (InvalidCastException ex)
- {
- // one of the RegistryKey.GetValue calls could not be cast to an expected value type
- e = ex;
- return false;
- }
- catch (ArgumentOutOfRangeException ex)
- {
- e = ex;
- return false;
- }
- catch (ArgumentException ex)
- {
- e = ex;
- return false;
- }
- return true;
- }
-
- private static unsafe bool TryGetTimeZoneEntryFromRegistry(RegistryKey key, string name, out REG_TZI_FORMAT dtzi)
- {
- if (!(key.GetValue(name, null) is byte[] regValue) || regValue.Length != sizeof(REG_TZI_FORMAT))
- {
- dtzi = default;
- return false;
- }
- fixed (byte* pBytes = &regValue[0])
- dtzi = *(REG_TZI_FORMAT*)pBytes;
- return true;
- }
-
- /// <summary>
- /// Helper function that compares the StandardBias and StandardDate portion a
- /// TimeZoneInformation struct to a time zone registry entry.
- /// </summary>
- private static bool TryCompareStandardDate(in TIME_ZONE_INFORMATION timeZone, in REG_TZI_FORMAT registryTimeZoneInfo) =>
- timeZone.Bias == registryTimeZoneInfo.Bias &&
- timeZone.StandardBias == registryTimeZoneInfo.StandardBias &&
- timeZone.StandardDate.Equals(registryTimeZoneInfo.StandardDate);
-
- /// <summary>
- /// Helper function that compares a TimeZoneInformation struct to a time zone registry entry.
- /// </summary>
- private static bool TryCompareTimeZoneInformationToRegistry(in TIME_ZONE_INFORMATION timeZone, string id, out bool dstDisabled)
- {
- dstDisabled = false;
-
- using (RegistryKey? key = Registry.LocalMachine.OpenSubKey(TimeZonesRegistryHive + "\\" + id, writable: false))
- {
- if (key == null)
- {
- return false;
- }
-
- REG_TZI_FORMAT registryTimeZoneInfo;
- if (!TryGetTimeZoneEntryFromRegistry(key, TimeZoneInfoValue, out registryTimeZoneInfo))
- {
- return false;
- }
-
- //
- // first compare the bias and standard date information between the data from the Win32 API
- // and the data from the registry...
- //
- bool result = TryCompareStandardDate(timeZone, registryTimeZoneInfo);
-
- if (!result)
- {
- return false;
- }
-
- result = dstDisabled || CheckDaylightSavingTimeNotSupported(timeZone) ||
- //
- // since Daylight Saving Time is not "disabled", do a straight comparision between
- // the Win32 API data and the registry data ...
- //
- (timeZone.DaylightBias == registryTimeZoneInfo.DaylightBias &&
- timeZone.DaylightDate.Equals(registryTimeZoneInfo.DaylightDate));
-
- // Finally compare the "StandardName" string value...
- //
- // we do not compare "DaylightName" as this TimeZoneInformation field may contain
- // either "StandardName" or "DaylightName" depending on the time of year and current machine settings
- //
- if (result)
- {
- string? registryStandardName = key.GetValue(StandardValue, string.Empty) as string;
- result = string.Equals(registryStandardName, timeZone.GetStandardName(), StringComparison.Ordinal);
- }
- return result;
- }
- }
-
- /// <summary>
- /// Helper function for retrieving a localized string resource via MUI.
- /// The function expects a string in the form: "@resource.dll, -123"
- ///
- /// "resource.dll" is a language-neutral portable executable (LNPE) file in
- /// the %windir%\system32 directory. The OS is queried to find the best-fit
- /// localized resource file for this LNPE (ex: %windir%\system32\en-us\resource.dll.mui).
- /// If a localized resource file exists, we LoadString resource ID "123" and
- /// return it to our caller.
- /// </summary>
- private static string TryGetLocalizedNameByMuiNativeResource(string resource)
- {
- if (string.IsNullOrEmpty(resource))
- {
- return string.Empty;
- }
-
- // parse "@tzres.dll, -100"
- //
- // filePath = "C:\Windows\System32\tzres.dll"
- // resourceId = -100
- //
- string[] resources = resource.Split(',');
- if (resources.Length != 2)
- {
- return string.Empty;
- }
-
- string filePath;
- int resourceId;
-
- // get the path to Windows\System32
- string system32 = Environment.SystemDirectory;
-
- // trim the string "@tzres.dll" => "tzres.dll"
- string tzresDll = resources[0].TrimStart('@');
-
- try
- {
- filePath = Path.Combine(system32, tzresDll);
- }
- catch (ArgumentException)
- {
- // there were probably illegal characters in the path
- return string.Empty;
- }
-
- if (!int.TryParse(resources[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out resourceId))
- {
- return string.Empty;
- }
- resourceId = -resourceId;
-
- try
- {
- unsafe
- {
- char* fileMuiPath = stackalloc char[Interop.Kernel32.MAX_PATH];
- int fileMuiPathLength = Interop.Kernel32.MAX_PATH;
- int languageLength = 0;
- long enumerator = 0;
-
- bool succeeded = Interop.Kernel32.GetFileMUIPath(
- Interop.Kernel32.MUI_PREFERRED_UI_LANGUAGES,
- filePath, null /* language */, ref languageLength,
- fileMuiPath, ref fileMuiPathLength, ref enumerator);
- return succeeded ?
- TryGetLocalizedNameByNativeResource(new string(fileMuiPath, 0, fileMuiPathLength), resourceId) :
- string.Empty;
- }
- }
- catch (EntryPointNotFoundException)
- {
- return string.Empty;
- }
- }
-
- /// <summary>
- /// Helper function for retrieving a localized string resource via a native resource DLL.
- /// The function expects a string in the form: "C:\Windows\System32\en-us\resource.dll"
- ///
- /// "resource.dll" is a language-specific resource DLL.
- /// If the localized resource DLL exists, LoadString(resource) is returned.
- /// </summary>
- private static unsafe string TryGetLocalizedNameByNativeResource(string filePath, int resource)
- {
- using (SafeLibraryHandle handle = Interop.Kernel32.LoadLibraryEx(filePath, IntPtr.Zero, Interop.Kernel32.LOAD_LIBRARY_AS_DATAFILE))
- {
- if (!handle.IsInvalid)
- {
- const int LoadStringMaxLength = 500;
- char* localizedResource = stackalloc char[LoadStringMaxLength];
-
- int charsWritten = Interop.User32.LoadString(handle, (uint)resource, localizedResource, LoadStringMaxLength);
- if (charsWritten != 0)
- {
- return new string(localizedResource, 0, charsWritten);
- }
- }
- }
-
- return string.Empty;
- }
-
- /// <summary>
- /// Helper function for retrieving the DisplayName, StandardName, and DaylightName from the registry
- ///
- /// The function first checks the MUI_ key-values, and if they exist, it loads the strings from the MUI
- /// resource dll(s). When the keys do not exist, the function falls back to reading from the standard
- /// key-values
- /// </summary>
- private static void GetLocalizedNamesByRegistryKey(RegistryKey key, out string? displayName, out string? standardName, out string? daylightName)
- {
- displayName = string.Empty;
- standardName = string.Empty;
- daylightName = string.Empty;
-
- // read the MUI_ registry keys
- string? displayNameMuiResource = key.GetValue(MuiDisplayValue, string.Empty) as string;
- string? standardNameMuiResource = key.GetValue(MuiStandardValue, string.Empty) as string;
- string? daylightNameMuiResource = key.GetValue(MuiDaylightValue, string.Empty) as string;
-
- // try to load the strings from the native resource DLL(s)
- if (!string.IsNullOrEmpty(displayNameMuiResource))
- {
- displayName = TryGetLocalizedNameByMuiNativeResource(displayNameMuiResource);
- }
-
- if (!string.IsNullOrEmpty(standardNameMuiResource))
- {
- standardName = TryGetLocalizedNameByMuiNativeResource(standardNameMuiResource);
- }
-
- if (!string.IsNullOrEmpty(daylightNameMuiResource))
- {
- daylightName = TryGetLocalizedNameByMuiNativeResource(daylightNameMuiResource);
- }
-
- // fallback to using the standard registry keys
- if (string.IsNullOrEmpty(displayName))
- {
- displayName = key.GetValue(DisplayValue, string.Empty) as string;
- }
- if (string.IsNullOrEmpty(standardName))
- {
- standardName = key.GetValue(StandardValue, string.Empty) as string;
- }
- if (string.IsNullOrEmpty(daylightName))
- {
- daylightName = key.GetValue(DaylightValue, string.Empty) as string;
- }
- }
-
- /// <summary>
- /// Helper function that takes a string representing a time_zone_name registry key name
- /// and returns a TimeZoneInfo instance.
- /// </summary>
- private static TimeZoneInfoResult TryGetTimeZoneFromLocalMachine(string id, out TimeZoneInfo? value, out Exception? e)
- {
- e = null;
-
- // Standard Time Zone Registry Data
- // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- // HKLM
- // Software
- // Microsoft
- // Windows NT
- // CurrentVersion
- // Time Zones
- // <time_zone_name>
- // * STD, REG_SZ "Standard Time Name"
- // (For OS installed zones, this will always be English)
- // * MUI_STD, REG_SZ "@tzres.dll,-1234"
- // Indirect string to localized resource for Standard Time,
- // add "%windir%\system32\" after "@"
- // * DLT, REG_SZ "Daylight Time Name"
- // (For OS installed zones, this will always be English)
- // * MUI_DLT, REG_SZ "@tzres.dll,-1234"
- // Indirect string to localized resource for Daylight Time,
- // add "%windir%\system32\" after "@"
- // * Display, REG_SZ "Display Name like (GMT-8:00) Pacific Time..."
- // * MUI_Display, REG_SZ "@tzres.dll,-1234"
- // Indirect string to localized resource for the Display,
- // add "%windir%\system32\" after "@"
- // * TZI, REG_BINARY REG_TZI_FORMAT
- //
- using (RegistryKey? key = Registry.LocalMachine.OpenSubKey(TimeZonesRegistryHive + "\\" + id, writable: false))
- {
- if (key == null)
- {
- value = null;
- return TimeZoneInfoResult.TimeZoneNotFoundException;
- }
-
- REG_TZI_FORMAT defaultTimeZoneInformation;
- if (!TryGetTimeZoneEntryFromRegistry(key, TimeZoneInfoValue, out defaultTimeZoneInformation))
- {
- // the registry value could not be cast to a byte array
- value = null;
- return TimeZoneInfoResult.InvalidTimeZoneException;
- }
-
- AdjustmentRule[]? adjustmentRules;
- if (!TryCreateAdjustmentRules(id, defaultTimeZoneInformation, out adjustmentRules, out e, defaultTimeZoneInformation.Bias))
- {
- value = null;
- return TimeZoneInfoResult.InvalidTimeZoneException;
- }
-
- GetLocalizedNamesByRegistryKey(key, out string? displayName, out string? standardName, out string? daylightName);
-
- try
- {
- value = new TimeZoneInfo(
- id,
- new TimeSpan(0, -(defaultTimeZoneInformation.Bias), 0),
- displayName,
- standardName,
- daylightName,
- adjustmentRules,
- disableDaylightSavingTime: false);
-
- return TimeZoneInfoResult.Success;
- }
- catch (ArgumentException ex)
- {
- // TimeZoneInfo constructor can throw ArgumentException and InvalidTimeZoneException
- value = null;
- e = ex;
- return TimeZoneInfoResult.InvalidTimeZoneException;
- }
- catch (InvalidTimeZoneException ex)
- {
- // TimeZoneInfo constructor can throw ArgumentException and InvalidTimeZoneException
- value = null;
- e = ex;
- return TimeZoneInfoResult.InvalidTimeZoneException;
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.cs b/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.cs
deleted file mode 100644
index 8e04fd2d27e..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.cs
+++ /dev/null
@@ -1,2002 +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 System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.Runtime.Serialization;
-using System.Threading;
-
-namespace System
-{
- //
- // DateTime uses TimeZoneInfo under the hood for IsDaylightSavingTime, IsAmbiguousTime, and GetUtcOffset.
- // These TimeZoneInfo APIs can throw ArgumentException when an Invalid-Time is passed in. To avoid this
- // unwanted behavior in DateTime public APIs, DateTime internally passes the
- // TimeZoneInfoOptions.NoThrowOnInvalidTime flag to internal TimeZoneInfo APIs.
- //
- // In the future we can consider exposing similar options on the public TimeZoneInfo APIs if there is enough
- // demand for this alternate behavior.
- //
- [Flags]
- internal enum TimeZoneInfoOptions
- {
- None = 1,
- NoThrowOnInvalidTime = 2
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed partial class TimeZoneInfo :
-#nullable disable // see comment on String
- IEquatable<TimeZoneInfo>,
-#nullable restore
- ISerializable, IDeserializationCallback
- {
- private enum TimeZoneInfoResult
- {
- Success = 0,
- TimeZoneNotFoundException = 1,
- InvalidTimeZoneException = 2,
- SecurityException = 3
- }
-
- private readonly string _id;
- private readonly string? _displayName;
- private readonly string? _standardDisplayName;
- private readonly string? _daylightDisplayName;
- private readonly TimeSpan _baseUtcOffset;
- private readonly bool _supportsDaylightSavingTime;
- private readonly AdjustmentRule[]? _adjustmentRules;
-
- // constants for TimeZoneInfo.Local and TimeZoneInfo.Utc
- private const string UtcId = "UTC";
- private const string LocalId = "Local";
-
- private static readonly TimeZoneInfo s_utcTimeZone = CreateCustomTimeZone(UtcId, TimeSpan.Zero, "(UTC) Coordinated Universal Time", "Coordinated Universal Time");
-
- private static CachedData s_cachedData = new CachedData();
-
- //
- // All cached data are encapsulated in a helper class to allow consistent view even when the data are refreshed using ClearCachedData()
- //
- // For example, TimeZoneInfo.Local can be cleared by another thread calling TimeZoneInfo.ClearCachedData. Without the consistent snapshot,
- // there is a chance that the internal ConvertTime calls will throw since 'source' won't be reference equal to the new TimeZoneInfo.Local.
- //
- private sealed partial class CachedData
- {
- private volatile TimeZoneInfo? _localTimeZone;
-
- private TimeZoneInfo CreateLocal()
- {
- lock (this)
- {
- TimeZoneInfo? timeZone = _localTimeZone;
- if (timeZone == null)
- {
- timeZone = GetLocalTimeZone(this);
-
- // this step is to break the reference equality
- // between TimeZoneInfo.Local and a second time zone
- // such as "Pacific Standard Time"
- timeZone = new TimeZoneInfo(
- timeZone._id,
- timeZone._baseUtcOffset,
- timeZone._displayName,
- timeZone._standardDisplayName,
- timeZone._daylightDisplayName,
- timeZone._adjustmentRules,
- disableDaylightSavingTime: false);
-
- _localTimeZone = timeZone;
- }
- return timeZone;
- }
- }
-
- public TimeZoneInfo Local => _localTimeZone ?? CreateLocal();
-
- /// <summary>
- /// Helper function that returns the corresponding DateTimeKind for this TimeZoneInfo.
- /// </summary>
- public DateTimeKind GetCorrespondingKind(TimeZoneInfo? timeZone)
- {
- // We check reference equality to see if 'this' is the same as
- // TimeZoneInfo.Local or TimeZoneInfo.Utc. This check is needed to
- // support setting the DateTime Kind property to 'Local' or
- // 'Utc' on the ConverTime(...) return value.
- //
- // Using reference equality instead of value equality was a
- // performance based design compromise. The reference equality
- // has much greater performance, but it reduces the number of
- // returned DateTime's that can be properly set as 'Local' or 'Utc'.
- //
- // For example, the user could be converting to the TimeZoneInfo returned
- // by FindSystemTimeZoneById("Pacific Standard Time") and their local
- // machine may be in Pacific time. If we used value equality to determine
- // the corresponding Kind then this conversion would be tagged as 'Local';
- // where as we are currently tagging the returned DateTime as 'Unspecified'
- // in this example. Only when the user passes in TimeZoneInfo.Local or
- // TimeZoneInfo.Utc to the ConvertTime(...) methods will this check succeed.
- //
- return
- ReferenceEquals(timeZone, s_utcTimeZone) ? DateTimeKind.Utc :
- ReferenceEquals(timeZone, _localTimeZone) ? DateTimeKind.Local :
- DateTimeKind.Unspecified;
- }
-
- public Dictionary<string, TimeZoneInfo>? _systemTimeZones;
- public ReadOnlyCollection<TimeZoneInfo>? _readOnlySystemTimeZones;
- public bool _allSystemTimeZonesRead;
- }
-
- // used by GetUtcOffsetFromUtc (DateTime.Now, DateTime.ToLocalTime) for max/min whole-day range checks
- private static readonly DateTime s_maxDateOnly = new DateTime(9999, 12, 31);
- private static readonly DateTime s_minDateOnly = new DateTime(1, 1, 2);
-
- public string Id => _id;
-
- public string DisplayName => _displayName ?? string.Empty;
-
- public string StandardName => _standardDisplayName ?? string.Empty;
-
- public string DaylightName => _daylightDisplayName ?? string.Empty;
-
- public TimeSpan BaseUtcOffset => _baseUtcOffset;
-
- public bool SupportsDaylightSavingTime => _supportsDaylightSavingTime;
-
- /// <summary>
- /// Returns an array of TimeSpan objects representing all of
- /// possible UTC offset values for this ambiguous time.
- /// </summary>
- public TimeSpan[] GetAmbiguousTimeOffsets(DateTimeOffset dateTimeOffset)
- {
- if (!SupportsDaylightSavingTime)
- {
- throw new ArgumentException(SR.Argument_DateTimeOffsetIsNotAmbiguous, nameof(dateTimeOffset));
- }
-
- DateTime adjustedTime = ConvertTime(dateTimeOffset, this).DateTime;
-
- bool isAmbiguous = false;
- int? ruleIndex;
- AdjustmentRule? rule = GetAdjustmentRuleForAmbiguousOffsets(adjustedTime, out ruleIndex);
- if (rule != null && rule.HasDaylightSaving)
- {
- DaylightTimeStruct daylightTime = GetDaylightTime(adjustedTime.Year, rule, ruleIndex);
- isAmbiguous = GetIsAmbiguousTime(adjustedTime, rule, daylightTime);
- }
-
- if (!isAmbiguous)
- {
- throw new ArgumentException(SR.Argument_DateTimeOffsetIsNotAmbiguous, nameof(dateTimeOffset));
- }
-
- // the passed in dateTime is ambiguous in this TimeZoneInfo instance
- TimeSpan[] timeSpans = new TimeSpan[2];
-
- TimeSpan actualUtcOffset = _baseUtcOffset + rule!.BaseUtcOffsetDelta;
-
- // the TimeSpan array must be sorted from least to greatest
- if (rule.DaylightDelta > TimeSpan.Zero)
- {
- timeSpans[0] = actualUtcOffset; // FUTURE: + rule.StandardDelta;
- timeSpans[1] = actualUtcOffset + rule.DaylightDelta;
- }
- else
- {
- timeSpans[0] = actualUtcOffset + rule.DaylightDelta;
- timeSpans[1] = actualUtcOffset; // FUTURE: + rule.StandardDelta;
- }
- return timeSpans;
- }
-
- /// <summary>
- /// Returns an array of TimeSpan objects representing all of
- /// possible UTC offset values for this ambiguous time.
- /// </summary>
- public TimeSpan[] GetAmbiguousTimeOffsets(DateTime dateTime)
- {
- if (!SupportsDaylightSavingTime)
- {
- throw new ArgumentException(SR.Argument_DateTimeIsNotAmbiguous, nameof(dateTime));
- }
-
- DateTime adjustedTime;
- if (dateTime.Kind == DateTimeKind.Local)
- {
- CachedData cachedData = s_cachedData;
- adjustedTime = ConvertTime(dateTime, cachedData.Local, this, TimeZoneInfoOptions.None, cachedData);
- }
- else if (dateTime.Kind == DateTimeKind.Utc)
- {
- CachedData cachedData = s_cachedData;
- adjustedTime = ConvertTime(dateTime, s_utcTimeZone, this, TimeZoneInfoOptions.None, cachedData);
- }
- else
- {
- adjustedTime = dateTime;
- }
-
- bool isAmbiguous = false;
- int? ruleIndex;
- AdjustmentRule? rule = GetAdjustmentRuleForAmbiguousOffsets(adjustedTime, out ruleIndex);
- if (rule != null && rule.HasDaylightSaving)
- {
- DaylightTimeStruct daylightTime = GetDaylightTime(adjustedTime.Year, rule, ruleIndex);
- isAmbiguous = GetIsAmbiguousTime(adjustedTime, rule, daylightTime);
- }
-
- if (!isAmbiguous)
- {
- throw new ArgumentException(SR.Argument_DateTimeIsNotAmbiguous, nameof(dateTime));
- }
-
- // the passed in dateTime is ambiguous in this TimeZoneInfo instance
- TimeSpan[] timeSpans = new TimeSpan[2];
- TimeSpan actualUtcOffset = _baseUtcOffset + rule!.BaseUtcOffsetDelta;
-
- // the TimeSpan array must be sorted from least to greatest
- if (rule.DaylightDelta > TimeSpan.Zero)
- {
- timeSpans[0] = actualUtcOffset; // FUTURE: + rule.StandardDelta;
- timeSpans[1] = actualUtcOffset + rule.DaylightDelta;
- }
- else
- {
- timeSpans[0] = actualUtcOffset + rule.DaylightDelta;
- timeSpans[1] = actualUtcOffset; // FUTURE: + rule.StandardDelta;
- }
- return timeSpans;
- }
-
- // note the time is already adjusted
- private AdjustmentRule? GetAdjustmentRuleForAmbiguousOffsets(DateTime adjustedTime, out int? ruleIndex)
- {
- AdjustmentRule? rule = GetAdjustmentRuleForTime(adjustedTime, out ruleIndex);
- if (rule != null && rule.NoDaylightTransitions && !rule.HasDaylightSaving)
- {
- // When using NoDaylightTransitions rules, each rule is only for one offset.
- // When looking for the Daylight savings rules, and we found the non-DST rule,
- // then we get the rule right before this rule.
- return GetPreviousAdjustmentRule(rule, ruleIndex);
- }
-
- return rule;
- }
-
- /// <summary>
- /// Gets the AdjustmentRule that is immediately preceding the specified rule.
- /// If the specified rule is the first AdjustmentRule, or it isn't in _adjustmentRules,
- /// then the specified rule is returned.
- /// </summary>
- private AdjustmentRule GetPreviousAdjustmentRule(AdjustmentRule rule, int? ruleIndex)
- {
- Debug.Assert(rule.NoDaylightTransitions, "GetPreviousAdjustmentRule should only be used with NoDaylightTransitions rules.");
- Debug.Assert(_adjustmentRules != null);
-
- if (ruleIndex.HasValue && 0 < ruleIndex.GetValueOrDefault() && ruleIndex.GetValueOrDefault() < _adjustmentRules.Length)
- {
- return _adjustmentRules[ruleIndex.GetValueOrDefault() - 1];
- }
-
- AdjustmentRule result = rule;
- for (int i = 1; i < _adjustmentRules.Length; i++)
- {
- // use ReferenceEquals here instead of AdjustmentRule.Equals because
- // ReferenceEquals is much faster. This is safe because all the callers
- // of GetPreviousAdjustmentRule pass in a rule that was retrieved from
- // _adjustmentRules. A different approach will be needed if this ever changes.
- if (ReferenceEquals(rule, _adjustmentRules[i]))
- {
- result = _adjustmentRules[i - 1];
- break;
- }
- }
- return result;
- }
-
- /// <summary>
- /// Returns the Universal Coordinated Time (UTC) Offset for the current TimeZoneInfo instance.
- /// </summary>
- public TimeSpan GetUtcOffset(DateTimeOffset dateTimeOffset) =>
- GetUtcOffsetFromUtc(dateTimeOffset.UtcDateTime, this);
-
- /// <summary>
- /// Returns the Universal Coordinated Time (UTC) Offset for the current TimeZoneInfo instance.
- /// </summary>
- public TimeSpan GetUtcOffset(DateTime dateTime) =>
- GetUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime, s_cachedData);
-
- // Shortcut for TimeZoneInfo.Local.GetUtcOffset
- internal static TimeSpan GetLocalUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags)
- {
- CachedData cachedData = s_cachedData;
- return cachedData.Local.GetUtcOffset(dateTime, flags, cachedData);
- }
-
- /// <summary>
- /// Returns the Universal Coordinated Time (UTC) Offset for the current TimeZoneInfo instance.
- /// </summary>
- internal TimeSpan GetUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags) =>
- GetUtcOffset(dateTime, flags, s_cachedData);
-
- private TimeSpan GetUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags, CachedData cachedData)
- {
- if (dateTime.Kind == DateTimeKind.Local)
- {
- if (cachedData.GetCorrespondingKind(this) != DateTimeKind.Local)
- {
- //
- // normal case of converting from Local to Utc and then getting the offset from the UTC DateTime
- //
- DateTime adjustedTime = ConvertTime(dateTime, cachedData.Local, s_utcTimeZone, flags);
- return GetUtcOffsetFromUtc(adjustedTime, this);
- }
-
- //
- // Fall through for TimeZoneInfo.Local.GetUtcOffset(date)
- // to handle an edge case with Invalid-Times for DateTime formatting:
- //
- // Consider the invalid PST time "2007-03-11T02:00:00.0000000-08:00"
- //
- // By directly calling GetUtcOffset instead of converting to UTC and then calling GetUtcOffsetFromUtc
- // the correct invalid offset of "-08:00" is returned. In the normal case of converting to UTC as an
- // interim-step, the invalid time is adjusted into a *valid* UTC time which causes a change in output:
- //
- // 1) invalid PST time "2007-03-11T02:00:00.0000000-08:00"
- // 2) converted to UTC "2007-03-11T10:00:00.0000000Z"
- // 3) offset returned "2007-03-11T03:00:00.0000000-07:00"
- //
- }
- else if (dateTime.Kind == DateTimeKind.Utc)
- {
- if (cachedData.GetCorrespondingKind(this) == DateTimeKind.Utc)
- {
- return _baseUtcOffset;
- }
- else
- {
- //
- // passing in a UTC dateTime to a non-UTC TimeZoneInfo instance is a
- // special Loss-Less case.
- //
- return GetUtcOffsetFromUtc(dateTime, this);
- }
- }
-
- return GetUtcOffset(dateTime, this);
- }
-
- /// <summary>
- /// Returns true if the time is during the ambiguous time period
- /// for the current TimeZoneInfo instance.
- /// </summary>
- public bool IsAmbiguousTime(DateTimeOffset dateTimeOffset)
- {
- if (!_supportsDaylightSavingTime)
- {
- return false;
- }
-
- DateTimeOffset adjustedTime = ConvertTime(dateTimeOffset, this);
- return IsAmbiguousTime(adjustedTime.DateTime);
- }
-
- /// <summary>
- /// Returns true if the time is during the ambiguous time period
- /// for the current TimeZoneInfo instance.
- /// </summary>
- public bool IsAmbiguousTime(DateTime dateTime) =>
- IsAmbiguousTime(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
-
- /// <summary>
- /// Returns true if the time is during the ambiguous time period
- /// for the current TimeZoneInfo instance.
- /// </summary>
- internal bool IsAmbiguousTime(DateTime dateTime, TimeZoneInfoOptions flags)
- {
- if (!_supportsDaylightSavingTime)
- {
- return false;
- }
-
- CachedData cachedData = s_cachedData;
- DateTime adjustedTime =
- dateTime.Kind == DateTimeKind.Local ? ConvertTime(dateTime, cachedData.Local, this, flags, cachedData) :
- dateTime.Kind == DateTimeKind.Utc ? ConvertTime(dateTime, s_utcTimeZone, this, flags, cachedData) :
- dateTime;
-
- int? ruleIndex;
- AdjustmentRule? rule = GetAdjustmentRuleForTime(adjustedTime, out ruleIndex);
- if (rule != null && rule.HasDaylightSaving)
- {
- DaylightTimeStruct daylightTime = GetDaylightTime(adjustedTime.Year, rule, ruleIndex);
- return GetIsAmbiguousTime(adjustedTime, rule, daylightTime);
- }
- return false;
- }
-
- /// <summary>
- /// Returns true if the time is during Daylight Saving time for the current TimeZoneInfo instance.
- /// </summary>
- public bool IsDaylightSavingTime(DateTimeOffset dateTimeOffset)
- {
- bool isDaylightSavingTime;
- GetUtcOffsetFromUtc(dateTimeOffset.UtcDateTime, this, out isDaylightSavingTime);
- return isDaylightSavingTime;
- }
-
- /// <summary>
- /// Returns true if the time is during Daylight Saving time for the current TimeZoneInfo instance.
- /// </summary>
- public bool IsDaylightSavingTime(DateTime dateTime) =>
- IsDaylightSavingTime(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime, s_cachedData);
-
- /// <summary>
- /// Returns true if the time is during Daylight Saving time for the current TimeZoneInfo instance.
- /// </summary>
- internal bool IsDaylightSavingTime(DateTime dateTime, TimeZoneInfoOptions flags) =>
- IsDaylightSavingTime(dateTime, flags, s_cachedData);
-
- private bool IsDaylightSavingTime(DateTime dateTime, TimeZoneInfoOptions flags, CachedData cachedData)
- {
- //
- // dateTime.Kind is UTC, then time will be converted from UTC
- // into current instance's timezone
- // dateTime.Kind is Local, then time will be converted from Local
- // into current instance's timezone
- // dateTime.Kind is UnSpecified, then time is already in
- // current instance's timezone
- //
- // Our DateTime handles ambiguous times, (one is in the daylight and
- // one is in standard.) If a new DateTime is constructed during ambiguous
- // time, it is defaulted to "Standard" (i.e. this will return false).
- // For Invalid times, we will return false
-
- if (!_supportsDaylightSavingTime || _adjustmentRules == null)
- {
- return false;
- }
-
- DateTime adjustedTime;
- //
- // handle any Local/Utc special cases...
- //
- if (dateTime.Kind == DateTimeKind.Local)
- {
- adjustedTime = ConvertTime(dateTime, cachedData.Local, this, flags, cachedData);
- }
- else if (dateTime.Kind == DateTimeKind.Utc)
- {
- if (cachedData.GetCorrespondingKind(this) == DateTimeKind.Utc)
- {
- // simple always false case: TimeZoneInfo.Utc.IsDaylightSavingTime(dateTime, flags);
- return false;
- }
- else
- {
- //
- // passing in a UTC dateTime to a non-UTC TimeZoneInfo instance is a
- // special Loss-Less case.
- //
- bool isDaylightSavings;
- GetUtcOffsetFromUtc(dateTime, this, out isDaylightSavings);
- return isDaylightSavings;
- }
- }
- else
- {
- adjustedTime = dateTime;
- }
-
- //
- // handle the normal cases...
- //
- int? ruleIndex;
- AdjustmentRule? rule = GetAdjustmentRuleForTime(adjustedTime, out ruleIndex);
- if (rule != null && rule.HasDaylightSaving)
- {
- DaylightTimeStruct daylightTime = GetDaylightTime(adjustedTime.Year, rule, ruleIndex);
- return GetIsDaylightSavings(adjustedTime, rule, daylightTime);
- }
- else
- {
- return false;
- }
- }
-
- /// <summary>
- /// Returns true when dateTime falls into a "hole in time".
- /// </summary>
- public bool IsInvalidTime(DateTime dateTime)
- {
- bool isInvalid = false;
-
- if ((dateTime.Kind == DateTimeKind.Unspecified) ||
- (dateTime.Kind == DateTimeKind.Local && s_cachedData.GetCorrespondingKind(this) == DateTimeKind.Local))
- {
- // only check Unspecified and (Local when this TimeZoneInfo instance is Local)
- int? ruleIndex;
- AdjustmentRule? rule = GetAdjustmentRuleForTime(dateTime, out ruleIndex);
-
- if (rule != null && rule.HasDaylightSaving)
- {
- DaylightTimeStruct daylightTime = GetDaylightTime(dateTime.Year, rule, ruleIndex);
- isInvalid = GetIsInvalidTime(dateTime, rule, daylightTime);
- }
- else
- {
- isInvalid = false;
- }
- }
-
- return isInvalid;
- }
-
- /// <summary>
- /// Clears data from static members.
- /// </summary>
- public static void ClearCachedData()
- {
- // Clear a fresh instance of cached data
- s_cachedData = new CachedData();
- }
-
- /// <summary>
- /// Converts the value of a DateTime object from sourceTimeZone to destinationTimeZone.
- /// </summary>
- public static DateTimeOffset ConvertTimeBySystemTimeZoneId(DateTimeOffset dateTimeOffset, string destinationTimeZoneId) =>
- ConvertTime(dateTimeOffset, FindSystemTimeZoneById(destinationTimeZoneId));
-
- /// <summary>
- /// Converts the value of a DateTime object from sourceTimeZone to destinationTimeZone.
- /// </summary>
- public static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string destinationTimeZoneId) =>
- ConvertTime(dateTime, FindSystemTimeZoneById(destinationTimeZoneId));
-
- /// <summary>
- /// Converts the value of a DateTime object from sourceTimeZone to destinationTimeZone.
- /// </summary>
- public static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string sourceTimeZoneId, string destinationTimeZoneId)
- {
- if (dateTime.Kind == DateTimeKind.Local && string.Equals(sourceTimeZoneId, Local.Id, StringComparison.OrdinalIgnoreCase))
- {
- // TimeZoneInfo.Local can be cleared by another thread calling TimeZoneInfo.ClearCachedData.
- // Take snapshot of cached data to guarantee this method will not be impacted by the ClearCachedData call.
- // Without the snapshot, there is a chance that ConvertTime will throw since 'source' won't
- // be reference equal to the new TimeZoneInfo.Local
- //
- CachedData cachedData = s_cachedData;
- return ConvertTime(dateTime, cachedData.Local, FindSystemTimeZoneById(destinationTimeZoneId), TimeZoneInfoOptions.None, cachedData);
- }
- else if (dateTime.Kind == DateTimeKind.Utc && string.Equals(sourceTimeZoneId, Utc.Id, StringComparison.OrdinalIgnoreCase))
- {
- return ConvertTime(dateTime, s_utcTimeZone, FindSystemTimeZoneById(destinationTimeZoneId), TimeZoneInfoOptions.None, s_cachedData);
- }
- else
- {
- return ConvertTime(dateTime, FindSystemTimeZoneById(sourceTimeZoneId), FindSystemTimeZoneById(destinationTimeZoneId));
- }
- }
-
- /// <summary>
- /// Converts the value of the dateTime object from sourceTimeZone to destinationTimeZone
- /// </summary>
- public static DateTimeOffset ConvertTime(DateTimeOffset dateTimeOffset, TimeZoneInfo destinationTimeZone)
- {
- if (destinationTimeZone == null)
- {
- throw new ArgumentNullException(nameof(destinationTimeZone));
- }
-
- // calculate the destination time zone offset
- DateTime utcDateTime = dateTimeOffset.UtcDateTime;
- TimeSpan destinationOffset = GetUtcOffsetFromUtc(utcDateTime, destinationTimeZone);
-
- // check for overflow
- long ticks = utcDateTime.Ticks + destinationOffset.Ticks;
-
- return
- ticks > DateTimeOffset.MaxValue.Ticks ? DateTimeOffset.MaxValue :
- ticks < DateTimeOffset.MinValue.Ticks ? DateTimeOffset.MinValue :
- new DateTimeOffset(ticks, destinationOffset);
- }
-
- /// <summary>
- /// Converts the value of the dateTime object from sourceTimeZone to destinationTimeZone
- /// </summary>
- public static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo destinationTimeZone)
- {
- if (destinationTimeZone == null)
- {
- throw new ArgumentNullException(nameof(destinationTimeZone));
- }
-
- // Special case to give a way clearing the cache without exposing ClearCachedData()
- if (dateTime.Ticks == 0)
- {
- ClearCachedData();
- }
- CachedData cachedData = s_cachedData;
- TimeZoneInfo sourceTimeZone = dateTime.Kind == DateTimeKind.Utc ? s_utcTimeZone : cachedData.Local;
- return ConvertTime(dateTime, sourceTimeZone, destinationTimeZone, TimeZoneInfoOptions.None, cachedData);
- }
-
- /// <summary>
- /// Converts the value of the dateTime object from sourceTimeZone to destinationTimeZone
- /// </summary>
- public static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone) =>
- ConvertTime(dateTime, sourceTimeZone, destinationTimeZone, TimeZoneInfoOptions.None, s_cachedData);
-
- /// <summary>
- /// Converts the value of the dateTime object from sourceTimeZone to destinationTimeZone
- /// </summary>
- internal static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags) =>
- ConvertTime(dateTime, sourceTimeZone, destinationTimeZone, flags, s_cachedData);
-
- private static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags, CachedData cachedData)
- {
- if (sourceTimeZone == null)
- {
- throw new ArgumentNullException(nameof(sourceTimeZone));
- }
-
- if (destinationTimeZone == null)
- {
- throw new ArgumentNullException(nameof(destinationTimeZone));
- }
-
- DateTimeKind sourceKind = cachedData.GetCorrespondingKind(sourceTimeZone);
- if (((flags & TimeZoneInfoOptions.NoThrowOnInvalidTime) == 0) && (dateTime.Kind != DateTimeKind.Unspecified) && (dateTime.Kind != sourceKind))
- {
- throw new ArgumentException(SR.Argument_ConvertMismatch, nameof(sourceTimeZone));
- }
-
- //
- // check to see if the DateTime is in an invalid time range. This check
- // requires the current AdjustmentRule and DaylightTime - which are also
- // needed to calculate 'sourceOffset' in the normal conversion case.
- // By calculating the 'sourceOffset' here we improve the
- // performance for the normal case at the expense of the 'ArgumentException'
- // case and Loss-less Local special cases.
- //
- int? sourceRuleIndex;
- AdjustmentRule? sourceRule = sourceTimeZone.GetAdjustmentRuleForTime(dateTime, out sourceRuleIndex);
- TimeSpan sourceOffset = sourceTimeZone.BaseUtcOffset;
-
- if (sourceRule != null)
- {
- sourceOffset += sourceRule.BaseUtcOffsetDelta;
- if (sourceRule.HasDaylightSaving)
- {
- bool sourceIsDaylightSavings = false;
- DaylightTimeStruct sourceDaylightTime = sourceTimeZone.GetDaylightTime(dateTime.Year, sourceRule, sourceRuleIndex);
-
- // 'dateTime' might be in an invalid time range since it is in an AdjustmentRule
- // period that supports DST
- if (((flags & TimeZoneInfoOptions.NoThrowOnInvalidTime) == 0) && GetIsInvalidTime(dateTime, sourceRule, sourceDaylightTime))
- {
- throw new ArgumentException(SR.Argument_DateTimeIsInvalid, nameof(dateTime));
- }
- sourceIsDaylightSavings = GetIsDaylightSavings(dateTime, sourceRule, sourceDaylightTime);
-
- // adjust the sourceOffset according to the Adjustment Rule / Daylight Saving Rule
- sourceOffset += (sourceIsDaylightSavings ? sourceRule.DaylightDelta : TimeSpan.Zero /*FUTURE: sourceRule.StandardDelta*/);
- }
- }
-
- DateTimeKind targetKind = cachedData.GetCorrespondingKind(destinationTimeZone);
-
- // handle the special case of Loss-less Local->Local and UTC->UTC)
- if (dateTime.Kind != DateTimeKind.Unspecified && sourceKind != DateTimeKind.Unspecified && sourceKind == targetKind)
- {
- return dateTime;
- }
-
- long utcTicks = dateTime.Ticks - sourceOffset.Ticks;
-
- // handle the normal case by converting from 'source' to UTC and then to 'target'
- bool isAmbiguousLocalDst;
- DateTime targetConverted = ConvertUtcToTimeZone(utcTicks, destinationTimeZone, out isAmbiguousLocalDst);
-
- if (targetKind == DateTimeKind.Local)
- {
- // Because the ticks conversion between UTC and local is lossy, we need to capture whether the
- // time is in a repeated hour so that it can be passed to the DateTime constructor.
- return new DateTime(targetConverted.Ticks, DateTimeKind.Local, isAmbiguousLocalDst);
- }
- else
- {
- return new DateTime(targetConverted.Ticks, targetKind);
- }
- }
-
- /// <summary>
- /// Converts the value of a DateTime object from Coordinated Universal Time (UTC) to the destinationTimeZone.
- /// </summary>
- public static DateTime ConvertTimeFromUtc(DateTime dateTime, TimeZoneInfo destinationTimeZone) =>
- ConvertTime(dateTime, s_utcTimeZone, destinationTimeZone, TimeZoneInfoOptions.None, s_cachedData);
-
- /// <summary>
- /// Converts the value of a DateTime object to Coordinated Universal Time (UTC).
- /// </summary>
- public static DateTime ConvertTimeToUtc(DateTime dateTime)
- {
- if (dateTime.Kind == DateTimeKind.Utc)
- {
- return dateTime;
- }
- CachedData cachedData = s_cachedData;
- return ConvertTime(dateTime, cachedData.Local, s_utcTimeZone, TimeZoneInfoOptions.None, cachedData);
- }
-
- /// <summary>
- /// Converts the value of a DateTime object to Coordinated Universal Time (UTC).
- /// </summary>
- internal static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfoOptions flags)
- {
- if (dateTime.Kind == DateTimeKind.Utc)
- {
- return dateTime;
- }
- CachedData cachedData = s_cachedData;
- return ConvertTime(dateTime, cachedData.Local, s_utcTimeZone, flags, cachedData);
- }
-
- /// <summary>
- /// Converts the value of a DateTime object to Coordinated Universal Time (UTC).
- /// </summary>
- public static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfo sourceTimeZone) =>
- ConvertTime(dateTime, sourceTimeZone, s_utcTimeZone, TimeZoneInfoOptions.None, s_cachedData);
-
- /// <summary>
- /// Returns value equality. Equals does not compare any localizable
- /// String objects (DisplayName, StandardName, DaylightName).
- /// </summary>
- public bool Equals(TimeZoneInfo? other) =>
- other != null &&
- string.Equals(_id, other._id, StringComparison.OrdinalIgnoreCase) &&
- HasSameRules(other);
-
- public override bool Equals(object? obj) => Equals(obj as TimeZoneInfo);
-
- public static TimeZoneInfo FromSerializedString(string source)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
- if (source.Length == 0)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidSerializedString, source), nameof(source));
- }
-
- return StringSerializer.GetDeserializedTimeZoneInfo(source);
- }
-
- public override int GetHashCode() => StringComparer.OrdinalIgnoreCase.GetHashCode(_id);
-
- /// <summary>
- /// Returns a <see cref="ReadOnlyCollection{TimeZoneInfo}"/> containing all valid TimeZone's
- /// from the local machine. The entries in the collection are sorted by
- /// <see cref="DisplayName"/>.
- /// This method does *not* throw TimeZoneNotFoundException or InvalidTimeZoneException.
- /// </summary>
- public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones()
- {
- CachedData cachedData = s_cachedData;
-
- lock (cachedData)
- {
- if (cachedData._readOnlySystemTimeZones == null)
- {
- PopulateAllSystemTimeZones(cachedData);
- cachedData._allSystemTimeZonesRead = true;
-
- List<TimeZoneInfo> list;
- if (cachedData._systemTimeZones != null)
- {
- // return a collection of the cached system time zones
- list = new List<TimeZoneInfo>(cachedData._systemTimeZones.Values);
- }
- else
- {
- // return an empty collection
- list = new List<TimeZoneInfo>();
- }
-
- // sort and copy the TimeZoneInfo's into a ReadOnlyCollection for the user
- list.Sort((x, y) =>
- {
- // sort by BaseUtcOffset first and by DisplayName second - this is similar to the Windows Date/Time control panel
- int comparison = x.BaseUtcOffset.CompareTo(y.BaseUtcOffset);
- return comparison == 0 ? string.CompareOrdinal(x.DisplayName, y.DisplayName) : comparison;
- });
-
- cachedData._readOnlySystemTimeZones = new ReadOnlyCollection<TimeZoneInfo>(list);
- }
- }
- return cachedData._readOnlySystemTimeZones;
- }
-
- /// <summary>
- /// Value equality on the "adjustmentRules" array
- /// </summary>
- public bool HasSameRules(TimeZoneInfo other)
- {
- if (other == null)
- {
- throw new ArgumentNullException(nameof(other));
- }
-
- // check the utcOffset and supportsDaylightSavingTime members
- if (_baseUtcOffset != other._baseUtcOffset ||
- _supportsDaylightSavingTime != other._supportsDaylightSavingTime)
- {
- return false;
- }
-
- bool sameRules;
- AdjustmentRule[]? currentRules = _adjustmentRules;
- AdjustmentRule[]? otherRules = other._adjustmentRules;
-
- sameRules =
- (currentRules == null && otherRules == null) ||
- (currentRules != null && otherRules != null);
-
- if (!sameRules)
- {
- // AdjustmentRule array mismatch
- return false;
- }
-
- if (currentRules != null)
- {
- if (currentRules.Length != otherRules!.Length)
- {
- // AdjustmentRule array length mismatch
- return false;
- }
-
- for (int i = 0; i < currentRules.Length; i++)
- {
- if (!(currentRules[i]).Equals(otherRules[i]))
- {
- // AdjustmentRule value-equality mismatch
- return false;
- }
- }
- }
- return sameRules;
- }
-
- /// <summary>
- /// Returns a TimeZoneInfo instance that represents the local time on the machine.
- /// Accessing this property may throw InvalidTimeZoneException or COMException
- /// if the machine is in an unstable or corrupt state.
- /// </summary>
- public static TimeZoneInfo Local => s_cachedData.Local;
-
- //
- // ToSerializedString -
- //
- // "TimeZoneInfo" := TimeZoneInfo Data;[AdjustmentRule Data 1];...;[AdjustmentRule Data N]
- //
- // "TimeZoneInfo Data" := <_id>;<_baseUtcOffset>;<_displayName>;
- // <_standardDisplayName>;<_daylightDispayName>;
- //
- // "AdjustmentRule Data" := <DateStart>;<DateEnd>;<DaylightDelta>;
- // [TransitionTime Data DST Start]
- // [TransitionTime Data DST End]
- //
- // "TransitionTime Data" += <DaylightStartTimeOfDat>;<Month>;<Week>;<DayOfWeek>;<Day>
- //
- public string ToSerializedString() => StringSerializer.GetSerializedString(this);
-
- /// <summary>
- /// Returns the <see cref="DisplayName"/>: "(GMT-08:00) Pacific Time (US &amp; Canada); Tijuana"
- /// </summary>
- public override string ToString() => DisplayName;
-
- /// <summary>
- /// Returns a TimeZoneInfo instance that represents Universal Coordinated Time (UTC)
- /// </summary>
- public static TimeZoneInfo Utc => s_utcTimeZone;
-
- private TimeZoneInfo(
- string id,
- TimeSpan baseUtcOffset,
- string? displayName,
- string? standardDisplayName,
- string? daylightDisplayName,
- AdjustmentRule[]? adjustmentRules,
- bool disableDaylightSavingTime)
- {
- bool adjustmentRulesSupportDst;
- ValidateTimeZoneInfo(id, baseUtcOffset, adjustmentRules, out adjustmentRulesSupportDst);
-
- _id = id;
- _baseUtcOffset = baseUtcOffset;
- _displayName = displayName;
- _standardDisplayName = standardDisplayName;
- _daylightDisplayName = disableDaylightSavingTime ? null : daylightDisplayName;
- _supportsDaylightSavingTime = adjustmentRulesSupportDst && !disableDaylightSavingTime;
- _adjustmentRules = adjustmentRules;
- }
-
- /// <summary>
- /// Returns a simple TimeZoneInfo instance that does not support Daylight Saving Time.
- /// </summary>
- public static TimeZoneInfo CreateCustomTimeZone(
- string id,
- TimeSpan baseUtcOffset,
- string? displayName,
- string? standardDisplayName)
- {
- return new TimeZoneInfo(
- id,
- baseUtcOffset,
- displayName,
- standardDisplayName,
- standardDisplayName,
- adjustmentRules: null,
- disableDaylightSavingTime: false);
- }
-
- /// <summary>
- /// Returns a TimeZoneInfo instance that may support Daylight Saving Time.
- /// </summary>
- public static TimeZoneInfo CreateCustomTimeZone(
- string id,
- TimeSpan baseUtcOffset,
- string? displayName,
- string? standardDisplayName,
- string? daylightDisplayName,
- AdjustmentRule[]? adjustmentRules)
- {
- return CreateCustomTimeZone(
- id,
- baseUtcOffset,
- displayName,
- standardDisplayName,
- daylightDisplayName,
- adjustmentRules,
- disableDaylightSavingTime: false);
- }
-
- /// <summary>
- /// Returns a TimeZoneInfo instance that may support Daylight Saving Time.
- /// </summary>
- public static TimeZoneInfo CreateCustomTimeZone(
- string id,
- TimeSpan baseUtcOffset,
- string? displayName,
- string? standardDisplayName,
- string? daylightDisplayName,
- AdjustmentRule[]? adjustmentRules,
- bool disableDaylightSavingTime)
- {
- if (!disableDaylightSavingTime && adjustmentRules?.Length > 0)
- {
- adjustmentRules = (AdjustmentRule[])adjustmentRules.Clone();
- }
-
- return new TimeZoneInfo(
- id,
- baseUtcOffset,
- displayName,
- standardDisplayName,
- daylightDisplayName,
- adjustmentRules,
- disableDaylightSavingTime);
- }
-
- void IDeserializationCallback.OnDeserialization(object? sender)
- {
- try
- {
- bool adjustmentRulesSupportDst;
- ValidateTimeZoneInfo(_id, _baseUtcOffset, _adjustmentRules, out adjustmentRulesSupportDst);
-
- if (adjustmentRulesSupportDst != _supportsDaylightSavingTime)
- {
- throw new SerializationException(SR.Format(SR.Serialization_CorruptField, "SupportsDaylightSavingTime"));
- }
- }
- catch (ArgumentException e)
- {
- throw new SerializationException(SR.Serialization_InvalidData, e);
- }
- catch (InvalidTimeZoneException e)
- {
- throw new SerializationException(SR.Serialization_InvalidData, e);
- }
- }
-
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- info.AddValue("Id", _id); // Do not rename (binary serialization)
- info.AddValue("DisplayName", _displayName); // Do not rename (binary serialization)
- info.AddValue("StandardName", _standardDisplayName); // Do not rename (binary serialization)
- info.AddValue("DaylightName", _daylightDisplayName); // Do not rename (binary serialization)
- info.AddValue("BaseUtcOffset", _baseUtcOffset); // Do not rename (binary serialization)
- info.AddValue("AdjustmentRules", _adjustmentRules); // Do not rename (binary serialization)
- info.AddValue("SupportsDaylightSavingTime", _supportsDaylightSavingTime); // Do not rename (binary serialization)
- }
-
- private TimeZoneInfo(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- _id = (string)info.GetValue("Id", typeof(string))!; // Do not rename (binary serialization)
- _displayName = (string?)info.GetValue("DisplayName", typeof(string)); // Do not rename (binary serialization)
- _standardDisplayName = (string?)info.GetValue("StandardName", typeof(string)); // Do not rename (binary serialization)
- _daylightDisplayName = (string?)info.GetValue("DaylightName", typeof(string)); // Do not rename (binary serialization)
- _baseUtcOffset = (TimeSpan)info.GetValue("BaseUtcOffset", typeof(TimeSpan))!; // Do not rename (binary serialization)
- _adjustmentRules = (AdjustmentRule[]?)info.GetValue("AdjustmentRules", typeof(AdjustmentRule[])); // Do not rename (binary serialization)
- _supportsDaylightSavingTime = (bool)info.GetValue("SupportsDaylightSavingTime", typeof(bool))!; // Do not rename (binary serialization)
- }
-
- private AdjustmentRule? GetAdjustmentRuleForTime(DateTime dateTime, out int? ruleIndex)
- {
- AdjustmentRule? result = GetAdjustmentRuleForTime(dateTime, dateTimeisUtc: false, ruleIndex: out ruleIndex);
- Debug.Assert(result == null || ruleIndex.HasValue, "If an AdjustmentRule was found, ruleIndex should also be set.");
-
- return result;
- }
-
- private AdjustmentRule? GetAdjustmentRuleForTime(DateTime dateTime, bool dateTimeisUtc, out int? ruleIndex)
- {
- if (_adjustmentRules == null || _adjustmentRules.Length == 0)
- {
- ruleIndex = null;
- return null;
- }
-
- // Only check the whole-date portion of the dateTime for DateTimeKind.Unspecified rules -
- // This is because the AdjustmentRule DateStart & DateEnd are stored as
- // Date-only values {4/2/2006 - 10/28/2006} but actually represent the
- // time span {4/2/2006@00:00:00.00000 - 10/28/2006@23:59:59.99999}
- DateTime date = dateTimeisUtc ?
- (dateTime + BaseUtcOffset).Date :
- dateTime.Date;
-
- int low = 0;
- int high = _adjustmentRules.Length - 1;
-
- while (low <= high)
- {
- int median = low + ((high - low) >> 1);
-
- AdjustmentRule rule = _adjustmentRules[median];
- AdjustmentRule previousRule = median > 0 ? _adjustmentRules[median - 1] : rule;
-
- int compareResult = CompareAdjustmentRuleToDateTime(rule, previousRule, dateTime, date, dateTimeisUtc);
- if (compareResult == 0)
- {
- ruleIndex = median;
- return rule;
- }
- else if (compareResult < 0)
- {
- low = median + 1;
- }
- else
- {
- high = median - 1;
- }
- }
-
- ruleIndex = null;
- return null;
- }
-
- /// <summary>
- /// Determines if 'rule' is the correct AdjustmentRule for the given dateTime.
- /// </summary>
- /// <returns>
- /// A value less than zero if rule is for times before dateTime.
- /// Zero if rule is correct for dateTime.
- /// A value greater than zero if rule is for times after dateTime.
- /// </returns>
- private int CompareAdjustmentRuleToDateTime(AdjustmentRule rule, AdjustmentRule previousRule,
- DateTime dateTime, DateTime dateOnly, bool dateTimeisUtc)
- {
- bool isAfterStart;
- if (rule.DateStart.Kind == DateTimeKind.Utc)
- {
- DateTime dateTimeToCompare = dateTimeisUtc ?
- dateTime :
- // use the previous rule to compute the dateTimeToCompare, since the time daylight savings "switches"
- // is based on the previous rule's offset
- ConvertToUtc(dateTime, previousRule.DaylightDelta, previousRule.BaseUtcOffsetDelta);
-
- isAfterStart = dateTimeToCompare >= rule.DateStart;
- }
- else
- {
- // if the rule's DateStart is Unspecified, then use the whole-date portion
- isAfterStart = dateOnly >= rule.DateStart;
- }
-
- if (!isAfterStart)
- {
- return 1;
- }
-
- bool isBeforeEnd;
- if (rule.DateEnd.Kind == DateTimeKind.Utc)
- {
- DateTime dateTimeToCompare = dateTimeisUtc ?
- dateTime :
- ConvertToUtc(dateTime, rule.DaylightDelta, rule.BaseUtcOffsetDelta);
-
- isBeforeEnd = dateTimeToCompare <= rule.DateEnd;
- }
- else
- {
- // if the rule's DateEnd is Unspecified, then use the whole-date portion
- isBeforeEnd = dateOnly <= rule.DateEnd;
- }
-
- return isBeforeEnd ? 0 : -1;
- }
-
- /// <summary>
- /// Converts the dateTime to UTC using the specified deltas.
- /// </summary>
- private DateTime ConvertToUtc(DateTime dateTime, TimeSpan daylightDelta, TimeSpan baseUtcOffsetDelta) =>
- ConvertToFromUtc(dateTime, daylightDelta, baseUtcOffsetDelta, convertToUtc: true);
-
- /// <summary>
- /// Converts the dateTime from UTC using the specified deltas.
- /// </summary>
- private DateTime ConvertFromUtc(DateTime dateTime, TimeSpan daylightDelta, TimeSpan baseUtcOffsetDelta) =>
- ConvertToFromUtc(dateTime, daylightDelta, baseUtcOffsetDelta, convertToUtc: false);
-
- /// <summary>
- /// Converts the dateTime to or from UTC using the specified deltas.
- /// </summary>
- private DateTime ConvertToFromUtc(DateTime dateTime, TimeSpan daylightDelta, TimeSpan baseUtcOffsetDelta, bool convertToUtc)
- {
- TimeSpan offset = BaseUtcOffset + daylightDelta + baseUtcOffsetDelta;
- if (convertToUtc)
- {
- offset = offset.Negate();
- }
-
- long ticks = dateTime.Ticks + offset.Ticks;
-
- return
- ticks > DateTime.MaxValue.Ticks ? DateTime.MaxValue :
- ticks < DateTime.MinValue.Ticks ? DateTime.MinValue :
- new DateTime(ticks);
- }
-
- /// <summary>
- /// Helper function that converts a dateTime from UTC into the destinationTimeZone
- /// - Returns DateTime.MaxValue when the converted value is too large.
- /// - Returns DateTime.MinValue when the converted value is too small.
- /// </summary>
- private static DateTime ConvertUtcToTimeZone(long ticks, TimeZoneInfo destinationTimeZone, out bool isAmbiguousLocalDst)
- {
- // used to calculate the UTC offset in the destinationTimeZone
- DateTime utcConverted =
- ticks > DateTime.MaxValue.Ticks ? DateTime.MaxValue :
- ticks < DateTime.MinValue.Ticks ? DateTime.MinValue :
- new DateTime(ticks);
-
- // verify the time is between MinValue and MaxValue in the new time zone
- TimeSpan offset = GetUtcOffsetFromUtc(utcConverted, destinationTimeZone, out isAmbiguousLocalDst);
- ticks += offset.Ticks;
-
- return
- ticks > DateTime.MaxValue.Ticks ? DateTime.MaxValue :
- ticks < DateTime.MinValue.Ticks ? DateTime.MinValue :
- new DateTime(ticks);
- }
-
- /// <summary>
- /// Helper function that returns a DaylightTime from a year and AdjustmentRule.
- /// </summary>
- private DaylightTimeStruct GetDaylightTime(int year, AdjustmentRule rule, int? ruleIndex)
- {
- TimeSpan delta = rule.DaylightDelta;
- DateTime startTime;
- DateTime endTime;
- if (rule.NoDaylightTransitions)
- {
- // NoDaylightTransitions rules don't use DaylightTransition Start and End, instead
- // the DateStart and DateEnd are UTC times that represent when daylight savings time changes.
- // Convert the UTC times into adjusted time zone times.
-
- // use the previous rule to calculate the startTime, since the DST change happens w.r.t. the previous rule
- AdjustmentRule previousRule = GetPreviousAdjustmentRule(rule, ruleIndex);
- startTime = ConvertFromUtc(rule.DateStart, previousRule.DaylightDelta, previousRule.BaseUtcOffsetDelta);
-
- endTime = ConvertFromUtc(rule.DateEnd, rule.DaylightDelta, rule.BaseUtcOffsetDelta);
- }
- else
- {
- startTime = TransitionTimeToDateTime(year, rule.DaylightTransitionStart);
- endTime = TransitionTimeToDateTime(year, rule.DaylightTransitionEnd);
- }
- return new DaylightTimeStruct(startTime, endTime, delta);
- }
-
- /// <summary>
- /// Helper function that checks if a given dateTime is in Daylight Saving Time (DST).
- /// This function assumes the dateTime and AdjustmentRule are both in the same time zone.
- /// </summary>
- private static bool GetIsDaylightSavings(DateTime time, AdjustmentRule rule, DaylightTimeStruct daylightTime)
- {
- if (rule == null)
- {
- return false;
- }
-
- DateTime startTime;
- DateTime endTime;
-
- if (time.Kind == DateTimeKind.Local)
- {
- // startTime and endTime represent the period from either the start of
- // DST to the end and ***includes*** the potentially overlapped times
- startTime = rule.IsStartDateMarkerForBeginningOfYear() ?
- new DateTime(daylightTime.Start.Year, 1, 1, 0, 0, 0) :
- daylightTime.Start + daylightTime.Delta;
-
- endTime = rule.IsEndDateMarkerForEndOfYear() ?
- new DateTime(daylightTime.End.Year + 1, 1, 1, 0, 0, 0).AddTicks(-1) :
- daylightTime.End;
- }
- else
- {
- // startTime and endTime represent the period from either the start of DST to the end and
- // ***does not include*** the potentially overlapped times
- //
- // -=-=-=-=-=- Pacific Standard Time -=-=-=-=-=-=-
- // April 2, 2006 October 29, 2006
- // 2AM 3AM 1AM 2AM
- // | +1 hr | | -1 hr |
- // | <invalid time> | | <ambiguous time> |
- // [========== DST ========>)
- //
- // -=-=-=-=-=- Some Weird Time Zone -=-=-=-=-=-=-
- // April 2, 2006 October 29, 2006
- // 1AM 2AM 2AM 3AM
- // | -1 hr | | +1 hr |
- // | <ambiguous time> | | <invalid time> |
- // [======== DST ========>)
- //
- bool invalidAtStart = rule.DaylightDelta > TimeSpan.Zero;
-
- startTime = rule.IsStartDateMarkerForBeginningOfYear() ?
- new DateTime(daylightTime.Start.Year, 1, 1, 0, 0, 0) :
- daylightTime.Start + (invalidAtStart ? rule.DaylightDelta : TimeSpan.Zero); /* FUTURE: - rule.StandardDelta; */
-
- endTime = rule.IsEndDateMarkerForEndOfYear() ?
- new DateTime(daylightTime.End.Year + 1, 1, 1, 0, 0, 0).AddTicks(-1) :
- daylightTime.End + (invalidAtStart ? -rule.DaylightDelta : TimeSpan.Zero);
- }
-
- bool isDst = CheckIsDst(startTime, time, endTime, false, rule);
-
- // If this date was previously converted from a UTC date and we were able to detect that the local
- // DateTime would be ambiguous, this data is stored in the DateTime to resolve this ambiguity.
- if (isDst && time.Kind == DateTimeKind.Local)
- {
- // For normal time zones, the ambiguous hour is the last hour of daylight saving when you wind the
- // clock back. It is theoretically possible to have a positive delta, (which would really be daylight
- // reduction time), where you would have to wind the clock back in the begnning.
- if (GetIsAmbiguousTime(time, rule, daylightTime))
- {
- isDst = time.IsAmbiguousDaylightSavingTime();
- }
- }
-
- return isDst;
- }
-
- /// <summary>
- /// Gets the offset that should be used to calculate DST start times from a UTC time.
- /// </summary>
- private TimeSpan GetDaylightSavingsStartOffsetFromUtc(TimeSpan baseUtcOffset, AdjustmentRule rule, int? ruleIndex)
- {
- if (rule.NoDaylightTransitions)
- {
- // use the previous rule to calculate the startTime, since the DST change happens w.r.t. the previous rule
- AdjustmentRule previousRule = GetPreviousAdjustmentRule(rule, ruleIndex);
- return baseUtcOffset + previousRule.BaseUtcOffsetDelta + previousRule.DaylightDelta;
- }
- else
- {
- return baseUtcOffset + rule.BaseUtcOffsetDelta; /* FUTURE: + rule.StandardDelta; */
- }
- }
-
- /// <summary>
- /// Gets the offset that should be used to calculate DST end times from a UTC time.
- /// </summary>
- private TimeSpan GetDaylightSavingsEndOffsetFromUtc(TimeSpan baseUtcOffset, AdjustmentRule rule)
- {
- // NOTE: even NoDaylightTransitions rules use this logic since DST ends w.r.t. the current rule
- return baseUtcOffset + rule.BaseUtcOffsetDelta + rule.DaylightDelta; /* FUTURE: + rule.StandardDelta; */
- }
-
- /// <summary>
- /// Helper function that checks if a given dateTime is in Daylight Saving Time (DST).
- /// This function assumes the dateTime is in UTC and AdjustmentRule is in a different time zone.
- /// </summary>
- private static bool GetIsDaylightSavingsFromUtc(DateTime time, int year, TimeSpan utc, AdjustmentRule rule, int? ruleIndex, out bool isAmbiguousLocalDst, TimeZoneInfo zone)
- {
- isAmbiguousLocalDst = false;
-
- if (rule == null)
- {
- return false;
- }
-
- // Get the daylight changes for the year of the specified time.
- DaylightTimeStruct daylightTime = zone.GetDaylightTime(year, rule, ruleIndex);
-
- // The start and end times represent the range of universal times that are in DST for that year.
- // Within that there is an ambiguous hour, usually right at the end, but at the beginning in
- // the unusual case of a negative daylight savings delta.
- // We need to handle the case if the current rule has daylight saving end by the end of year. If so, we need to check if next year starts with daylight saving on
- // and get the actual daylight saving end time. Here is example for such case:
- // Converting the UTC datetime "12/31/2011 8:00:00 PM" to "(UTC+03:00) Moscow, St. Petersburg, Volgograd (RTZ 2)" zone.
- // In 2011 the daylight saving will go through the end of the year. If we use the end of 2011 as the daylight saving end,
- // that will fail the conversion because the UTC time +4 hours (3 hours for the zone UTC offset and 1 hour for daylight saving) will move us to the next year "1/1/2012 12:00 AM",
- // checking against the end of 2011 will tell we are not in daylight saving which is wrong and the conversion will be off by one hour.
- // Note we handle the similar case when rule year start with daylight saving and previous year end with daylight saving.
-
- bool ignoreYearAdjustment = false;
- TimeSpan dstStartOffset = zone.GetDaylightSavingsStartOffsetFromUtc(utc, rule, ruleIndex);
- DateTime startTime;
- if (rule.IsStartDateMarkerForBeginningOfYear() && daylightTime.Start.Year > DateTime.MinValue.Year)
- {
- int? previousYearRuleIndex;
- AdjustmentRule? previousYearRule = zone.GetAdjustmentRuleForTime(
- new DateTime(daylightTime.Start.Year - 1, 12, 31),
- out previousYearRuleIndex);
- if (previousYearRule != null && previousYearRule.IsEndDateMarkerForEndOfYear())
- {
- DaylightTimeStruct previousDaylightTime = zone.GetDaylightTime(
- daylightTime.Start.Year - 1,
- previousYearRule,
- previousYearRuleIndex);
- startTime = previousDaylightTime.Start - utc - previousYearRule.BaseUtcOffsetDelta;
- ignoreYearAdjustment = true;
- }
- else
- {
- startTime = new DateTime(daylightTime.Start.Year, 1, 1, 0, 0, 0) - dstStartOffset;
- }
- }
- else
- {
- startTime = daylightTime.Start - dstStartOffset;
- }
-
- TimeSpan dstEndOffset = zone.GetDaylightSavingsEndOffsetFromUtc(utc, rule);
- DateTime endTime;
- if (rule.IsEndDateMarkerForEndOfYear() && daylightTime.End.Year < DateTime.MaxValue.Year)
- {
- int? nextYearRuleIndex;
- AdjustmentRule? nextYearRule = zone.GetAdjustmentRuleForTime(
- new DateTime(daylightTime.End.Year + 1, 1, 1),
- out nextYearRuleIndex);
- if (nextYearRule != null && nextYearRule.IsStartDateMarkerForBeginningOfYear())
- {
- if (nextYearRule.IsEndDateMarkerForEndOfYear())
- {
- // next year end with daylight saving on too
- endTime = new DateTime(daylightTime.End.Year + 1, 12, 31) - utc - nextYearRule.BaseUtcOffsetDelta - nextYearRule.DaylightDelta;
- }
- else
- {
- DaylightTimeStruct nextdaylightTime = zone.GetDaylightTime(
- daylightTime.End.Year + 1,
- nextYearRule,
- nextYearRuleIndex);
- endTime = nextdaylightTime.End - utc - nextYearRule.BaseUtcOffsetDelta - nextYearRule.DaylightDelta;
- }
- ignoreYearAdjustment = true;
- }
- else
- {
- endTime = new DateTime(daylightTime.End.Year + 1, 1, 1, 0, 0, 0).AddTicks(-1) - dstEndOffset;
- }
- }
- else
- {
- endTime = daylightTime.End - dstEndOffset;
- }
-
- DateTime ambiguousStart;
- DateTime ambiguousEnd;
- if (daylightTime.Delta.Ticks > 0)
- {
- ambiguousStart = endTime - daylightTime.Delta;
- ambiguousEnd = endTime;
- }
- else
- {
- ambiguousStart = startTime;
- ambiguousEnd = startTime - daylightTime.Delta;
- }
-
- bool isDst = CheckIsDst(startTime, time, endTime, ignoreYearAdjustment, rule);
-
- // See if the resulting local time becomes ambiguous. This must be captured here or the
- // DateTime will not be able to round-trip back to UTC accurately.
- if (isDst)
- {
- isAmbiguousLocalDst = (time >= ambiguousStart && time < ambiguousEnd);
-
- if (!isAmbiguousLocalDst && ambiguousStart.Year != ambiguousEnd.Year)
- {
- // there exists an extreme corner case where the start or end period is on a year boundary and
- // because of this the comparison above might have been performed for a year-early or a year-later
- // than it should have been.
- DateTime ambiguousStartModified;
- DateTime ambiguousEndModified;
- try
- {
- ambiguousStartModified = ambiguousStart.AddYears(1);
- ambiguousEndModified = ambiguousEnd.AddYears(1);
- isAmbiguousLocalDst = (time >= ambiguousStartModified && time < ambiguousEndModified);
- }
- catch (ArgumentOutOfRangeException) { }
-
- if (!isAmbiguousLocalDst)
- {
- try
- {
- ambiguousStartModified = ambiguousStart.AddYears(-1);
- ambiguousEndModified = ambiguousEnd.AddYears(-1);
- isAmbiguousLocalDst = (time >= ambiguousStartModified && time < ambiguousEndModified);
- }
- catch (ArgumentOutOfRangeException) { }
- }
- }
- }
-
- return isDst;
- }
-
- private static bool CheckIsDst(DateTime startTime, DateTime time, DateTime endTime, bool ignoreYearAdjustment, AdjustmentRule rule)
- {
- // NoDaylightTransitions AdjustmentRules should never get their year adjusted since they adjust the offset for the
- // entire time period - which may be for multiple years
- if (!ignoreYearAdjustment && !rule.NoDaylightTransitions)
- {
- int startTimeYear = startTime.Year;
- int endTimeYear = endTime.Year;
-
- if (startTimeYear != endTimeYear)
- {
- endTime = endTime.AddYears(startTimeYear - endTimeYear);
- }
-
- int timeYear = time.Year;
-
- if (startTimeYear != timeYear)
- {
- time = time.AddYears(startTimeYear - timeYear);
- }
- }
-
- if (startTime > endTime)
- {
- // In southern hemisphere, the daylight saving time starts later in the year, and ends in the beginning of next year.
- // Note, the summer in the southern hemisphere begins late in the year.
- return time < endTime || time >= startTime;
- }
- else if (rule.NoDaylightTransitions)
- {
- // In NoDaylightTransitions AdjustmentRules, the startTime is always before the endTime,
- // and both the start and end times are inclusive
- return time >= startTime && time <= endTime;
- }
- else
- {
- // In northern hemisphere, the daylight saving time starts in the middle of the year.
- return time >= startTime && time < endTime;
- }
- }
-
- /// <summary>
- /// Returns true when the dateTime falls into an ambiguous time range.
- ///
- /// For example, in Pacific Standard Time on Sunday, October 29, 2006 time jumps from
- /// 2AM to 1AM. This means the timeline on Sunday proceeds as follows:
- /// 12AM ... [1AM ... 1:59:59AM -> 1AM ... 1:59:59AM] 2AM ... 3AM ...
- ///
- /// In this example, any DateTime values that fall into the [1AM - 1:59:59AM] range
- /// are ambiguous; as it is unclear if these times are in Daylight Saving Time.
- /// </summary>
- private static bool GetIsAmbiguousTime(DateTime time, AdjustmentRule rule, DaylightTimeStruct daylightTime)
- {
- bool isAmbiguous = false;
- if (rule == null || rule.DaylightDelta == TimeSpan.Zero)
- {
- return isAmbiguous;
- }
-
- DateTime startAmbiguousTime;
- DateTime endAmbiguousTime;
-
- // if at DST start we transition forward in time then there is an ambiguous time range at the DST end
- if (rule.DaylightDelta > TimeSpan.Zero)
- {
- if (rule.IsEndDateMarkerForEndOfYear())
- { // year end with daylight on so there is no ambiguous time
- return false;
- }
- startAmbiguousTime = daylightTime.End;
- endAmbiguousTime = daylightTime.End - rule.DaylightDelta; /* FUTURE: + rule.StandardDelta; */
- }
- else
- {
- if (rule.IsStartDateMarkerForBeginningOfYear())
- { // year start with daylight on so there is no ambiguous time
- return false;
- }
- startAmbiguousTime = daylightTime.Start;
- endAmbiguousTime = daylightTime.Start + rule.DaylightDelta; /* FUTURE: - rule.StandardDelta; */
- }
-
- isAmbiguous = (time >= endAmbiguousTime && time < startAmbiguousTime);
-
- if (!isAmbiguous && startAmbiguousTime.Year != endAmbiguousTime.Year)
- {
- // there exists an extreme corner case where the start or end period is on a year boundary and
- // because of this the comparison above might have been performed for a year-early or a year-later
- // than it should have been.
- DateTime startModifiedAmbiguousTime;
- DateTime endModifiedAmbiguousTime;
- try
- {
- startModifiedAmbiguousTime = startAmbiguousTime.AddYears(1);
- endModifiedAmbiguousTime = endAmbiguousTime.AddYears(1);
- isAmbiguous = (time >= endModifiedAmbiguousTime && time < startModifiedAmbiguousTime);
- }
- catch (ArgumentOutOfRangeException) { }
-
- if (!isAmbiguous)
- {
- try
- {
- startModifiedAmbiguousTime = startAmbiguousTime.AddYears(-1);
- endModifiedAmbiguousTime = endAmbiguousTime.AddYears(-1);
- isAmbiguous = (time >= endModifiedAmbiguousTime && time < startModifiedAmbiguousTime);
- }
- catch (ArgumentOutOfRangeException) { }
- }
- }
- return isAmbiguous;
- }
-
- /// <summary>
- /// Helper function that checks if a given DateTime is in an invalid time ("time hole")
- /// A "time hole" occurs at a DST transition point when time jumps forward;
- /// For example, in Pacific Standard Time on Sunday, April 2, 2006 time jumps from
- /// 1:59:59.9999999 to 3AM. The time range 2AM to 2:59:59.9999999AM is the "time hole".
- /// A "time hole" is not limited to only occurring at the start of DST, and may occur at
- /// the end of DST as well.
- /// </summary>
- private static bool GetIsInvalidTime(DateTime time, AdjustmentRule rule, DaylightTimeStruct daylightTime)
- {
- bool isInvalid = false;
- if (rule == null || rule.DaylightDelta == TimeSpan.Zero)
- {
- return isInvalid;
- }
-
- DateTime startInvalidTime;
- DateTime endInvalidTime;
-
- // if at DST start we transition forward in time then there is an ambiguous time range at the DST end
- if (rule.DaylightDelta < TimeSpan.Zero)
- {
- // if the year ends with daylight saving on then there cannot be any time-hole's in that year.
- if (rule.IsEndDateMarkerForEndOfYear())
- return false;
-
- startInvalidTime = daylightTime.End;
- endInvalidTime = daylightTime.End - rule.DaylightDelta; /* FUTURE: + rule.StandardDelta; */
- }
- else
- {
- // if the year starts with daylight saving on then there cannot be any time-hole's in that year.
- if (rule.IsStartDateMarkerForBeginningOfYear())
- return false;
-
- startInvalidTime = daylightTime.Start;
- endInvalidTime = daylightTime.Start + rule.DaylightDelta; /* FUTURE: - rule.StandardDelta; */
- }
-
- isInvalid = (time >= startInvalidTime && time < endInvalidTime);
-
- if (!isInvalid && startInvalidTime.Year != endInvalidTime.Year)
- {
- // there exists an extreme corner case where the start or end period is on a year boundary and
- // because of this the comparison above might have been performed for a year-early or a year-later
- // than it should have been.
- DateTime startModifiedInvalidTime;
- DateTime endModifiedInvalidTime;
- try
- {
- startModifiedInvalidTime = startInvalidTime.AddYears(1);
- endModifiedInvalidTime = endInvalidTime.AddYears(1);
- isInvalid = (time >= startModifiedInvalidTime && time < endModifiedInvalidTime);
- }
- catch (ArgumentOutOfRangeException) { }
-
- if (!isInvalid)
- {
- try
- {
- startModifiedInvalidTime = startInvalidTime.AddYears(-1);
- endModifiedInvalidTime = endInvalidTime.AddYears(-1);
- isInvalid = (time >= startModifiedInvalidTime && time < endModifiedInvalidTime);
- }
- catch (ArgumentOutOfRangeException) { }
- }
- }
- return isInvalid;
- }
-
- /// <summary>
- /// Helper function that calculates the UTC offset for a dateTime in a timeZone.
- /// This function assumes that the dateTime is already converted into the timeZone.
- /// </summary>
- private static TimeSpan GetUtcOffset(DateTime time, TimeZoneInfo zone)
- {
- TimeSpan baseOffset = zone.BaseUtcOffset;
- int? ruleIndex;
- AdjustmentRule? rule = zone.GetAdjustmentRuleForTime(time, out ruleIndex);
-
- if (rule != null)
- {
- baseOffset += rule.BaseUtcOffsetDelta;
- if (rule.HasDaylightSaving)
- {
- DaylightTimeStruct daylightTime = zone.GetDaylightTime(time.Year, rule, ruleIndex);
- bool isDaylightSavings = GetIsDaylightSavings(time, rule, daylightTime);
- baseOffset += (isDaylightSavings ? rule.DaylightDelta : TimeSpan.Zero /* FUTURE: rule.StandardDelta */);
- }
- }
-
- return baseOffset;
- }
-
- /// <summary>
- /// Helper function that calculates the UTC offset for a UTC-dateTime in a timeZone.
- /// This function assumes that the dateTime is represented in UTC and has *not* already been converted into the timeZone.
- /// </summary>
- private static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone) =>
- GetUtcOffsetFromUtc(time, zone, out _);
-
- /// <summary>
- /// Helper function that calculates the UTC offset for a UTC-dateTime in a timeZone.
- /// This function assumes that the dateTime is represented in UTC and has *not* already been converted into the timeZone.
- /// </summary>
- private static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone, out bool isDaylightSavings) =>
- GetUtcOffsetFromUtc(time, zone, out isDaylightSavings, out _);
-
- /// <summary>
- /// Helper function that calculates the UTC offset for a UTC-dateTime in a timeZone.
- /// This function assumes that the dateTime is represented in UTC and has *not* already been converted into the timeZone.
- /// </summary>
- internal static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone, out bool isDaylightSavings, out bool isAmbiguousLocalDst)
- {
- isDaylightSavings = false;
- isAmbiguousLocalDst = false;
- TimeSpan baseOffset = zone.BaseUtcOffset;
- int year;
- int? ruleIndex;
- AdjustmentRule? rule;
-
- if (time > s_maxDateOnly)
- {
- rule = zone.GetAdjustmentRuleForTime(DateTime.MaxValue, out ruleIndex);
- year = 9999;
- }
- else if (time < s_minDateOnly)
- {
- rule = zone.GetAdjustmentRuleForTime(DateTime.MinValue, out ruleIndex);
- year = 1;
- }
- else
- {
- rule = zone.GetAdjustmentRuleForTime(time, dateTimeisUtc: true, ruleIndex: out ruleIndex);
- Debug.Assert(rule == null || ruleIndex.HasValue,
- "If GetAdjustmentRuleForTime returned an AdjustmentRule, ruleIndex should also be set.");
-
- // As we get the associated rule using the adjusted targetTime, we should use the adjusted year (targetTime.Year) too as after adding the baseOffset,
- // sometimes the year value can change if the input datetime was very close to the beginning or the end of the year. Examples of such cases:
- // Libya Standard Time when used with the date 2011-12-31T23:59:59.9999999Z
- // "W. Australia Standard Time" used with date 2005-12-31T23:59:00.0000000Z
- DateTime targetTime = time + baseOffset;
- year = targetTime.Year;
- }
-
- if (rule != null)
- {
- baseOffset += rule.BaseUtcOffsetDelta;
- if (rule.HasDaylightSaving)
- {
- isDaylightSavings = GetIsDaylightSavingsFromUtc(time, year, zone._baseUtcOffset, rule, ruleIndex, out isAmbiguousLocalDst, zone);
- baseOffset += (isDaylightSavings ? rule.DaylightDelta : TimeSpan.Zero /* FUTURE: rule.StandardDelta */);
- }
- }
-
- return baseOffset;
- }
-
- /// <summary>
- /// Helper function that converts a year and TransitionTime into a DateTime.
- /// </summary>
- internal static DateTime TransitionTimeToDateTime(int year, TransitionTime transitionTime)
- {
- DateTime value;
- DateTime timeOfDay = transitionTime.TimeOfDay;
-
- if (transitionTime.IsFixedDateRule)
- {
- // create a DateTime from the passed in year and the properties on the transitionTime
-
- // if the day is out of range for the month then use the last day of the month
- int day = DateTime.DaysInMonth(year, transitionTime.Month);
-
- value = new DateTime(year, transitionTime.Month, (day < transitionTime.Day) ? day : transitionTime.Day,
- timeOfDay.Hour, timeOfDay.Minute, timeOfDay.Second, timeOfDay.Millisecond);
- }
- else
- {
- if (transitionTime.Week <= 4)
- {
- //
- // Get the (transitionTime.Week)th Sunday.
- //
- value = new DateTime(year, transitionTime.Month, 1,
- timeOfDay.Hour, timeOfDay.Minute, timeOfDay.Second, timeOfDay.Millisecond);
-
- int dayOfWeek = (int)value.DayOfWeek;
- int delta = (int)transitionTime.DayOfWeek - dayOfWeek;
- if (delta < 0)
- {
- delta += 7;
- }
- delta += 7 * (transitionTime.Week - 1);
-
- if (delta > 0)
- {
- value = value.AddDays(delta);
- }
- }
- else
- {
- //
- // If TransitionWeek is greater than 4, we will get the last week.
- //
- int daysInMonth = DateTime.DaysInMonth(year, transitionTime.Month);
- value = new DateTime(year, transitionTime.Month, daysInMonth,
- timeOfDay.Hour, timeOfDay.Minute, timeOfDay.Second, timeOfDay.Millisecond);
-
- // This is the day of week for the last day of the month.
- int dayOfWeek = (int)value.DayOfWeek;
- int delta = dayOfWeek - (int)transitionTime.DayOfWeek;
- if (delta < 0)
- {
- delta += 7;
- }
-
- if (delta > 0)
- {
- value = value.AddDays(-delta);
- }
- }
- }
- return value;
- }
-
- /// <summary>
- /// Helper function for retrieving a TimeZoneInfo object by time_zone_name.
- ///
- /// This function may return null.
- ///
- /// assumes cachedData lock is taken
- /// </summary>
- private static TimeZoneInfoResult TryGetTimeZone(string id, bool dstDisabled, out TimeZoneInfo? value, out Exception? e, CachedData cachedData, bool alwaysFallbackToLocalMachine = false)
- {
- Debug.Assert(Monitor.IsEntered(cachedData));
-
- TimeZoneInfoResult result = TimeZoneInfoResult.Success;
- e = null;
-
- // check the cache
- if (cachedData._systemTimeZones != null)
- {
- if (cachedData._systemTimeZones.TryGetValue(id, out TimeZoneInfo? match))
- {
- if (dstDisabled && match._supportsDaylightSavingTime)
- {
- // we found a cache hit but we want a time zone without DST and this one has DST data
- value = CreateCustomTimeZone(match._id, match._baseUtcOffset, match._displayName, match._standardDisplayName);
- }
- else
- {
- value = new TimeZoneInfo(match._id, match._baseUtcOffset, match._displayName, match._standardDisplayName,
- match._daylightDisplayName, match._adjustmentRules, disableDaylightSavingTime: false);
- }
-
- return result;
- }
- }
-
- // Fall back to reading from the local machine when the cache is not fully populated.
- // On UNIX, there may be some tzfiles that aren't in the zones.tab file, and thus aren't returned from GetSystemTimeZones().
- // If a caller asks for one of these zones before calling GetSystemTimeZones(), the time zone is returned successfully. But if
- // GetSystemTimeZones() is called first, FindSystemTimeZoneById will throw TimeZoneNotFoundException, which is inconsistent.
- // To fix this, when 'alwaysFallbackToLocalMachine' is true, even if _allSystemTimeZonesRead is true, try reading the tzfile
- // from disk, but don't add the time zone to the list returned from GetSystemTimeZones(). These time zones will only be
- // available if asked for directly.
- if (!cachedData._allSystemTimeZonesRead || alwaysFallbackToLocalMachine)
- {
- result = TryGetTimeZoneFromLocalMachine(id, dstDisabled, out value, out e, cachedData);
- }
- else
- {
- result = TimeZoneInfoResult.TimeZoneNotFoundException;
- value = null;
- }
-
- return result;
- }
-
- private static TimeZoneInfoResult TryGetTimeZoneFromLocalMachine(string id, bool dstDisabled, out TimeZoneInfo? value, out Exception? e, CachedData cachedData)
- {
- TimeZoneInfoResult result;
- TimeZoneInfo? match;
-
- result = TryGetTimeZoneFromLocalMachine(id, out match, out e);
-
- if (result == TimeZoneInfoResult.Success)
- {
- cachedData._systemTimeZones ??= new Dictionary<string, TimeZoneInfo>(StringComparer.OrdinalIgnoreCase)
- {
- { UtcId, s_utcTimeZone }
- };
-
- // Avoid using multiple Utc objects to ensure consistency and correctness as we have some code
- // uses reference equality with the Utc object.
- if (!id.Equals(UtcId, StringComparison.OrdinalIgnoreCase))
- {
- cachedData._systemTimeZones.Add(id, match!);
- }
-
- if (dstDisabled && match!._supportsDaylightSavingTime)
- {
- // we found a cache hit but we want a time zone without DST and this one has DST data
- value = CreateCustomTimeZone(match._id, match._baseUtcOffset, match._displayName, match._standardDisplayName);
- }
- else
- {
- value = new TimeZoneInfo(match!._id, match._baseUtcOffset, match._displayName, match._standardDisplayName,
- match._daylightDisplayName, match._adjustmentRules, disableDaylightSavingTime: false);
- }
- }
- else
- {
- value = null;
- }
-
- return result;
- }
-
- /// <summary>
- /// Helper function that performs all of the validation checks for the
- /// factory methods and deserialization callback.
- /// </summary>
- private static void ValidateTimeZoneInfo(string id, TimeSpan baseUtcOffset, AdjustmentRule[]? adjustmentRules, out bool adjustmentRulesSupportDst)
- {
- if (id == null)
- {
- throw new ArgumentNullException(nameof(id));
- }
-
- if (id.Length == 0)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidId, id), nameof(id));
- }
-
- if (UtcOffsetOutOfRange(baseUtcOffset))
- {
- throw new ArgumentOutOfRangeException(nameof(baseUtcOffset), SR.ArgumentOutOfRange_UtcOffset);
- }
-
- if (baseUtcOffset.Ticks % TimeSpan.TicksPerMinute != 0)
- {
- throw new ArgumentException(SR.Argument_TimeSpanHasSeconds, nameof(baseUtcOffset));
- }
-
- adjustmentRulesSupportDst = false;
-
- //
- // "adjustmentRules" can either be null or a valid array of AdjustmentRule objects.
- // A valid array is one that does not contain any null elements and all elements
- // are sorted in chronological order
- //
-
- if (adjustmentRules != null && adjustmentRules.Length != 0)
- {
- adjustmentRulesSupportDst = true;
- AdjustmentRule? prev = null;
- AdjustmentRule? current = null;
- for (int i = 0; i < adjustmentRules.Length; i++)
- {
- prev = current;
- current = adjustmentRules[i];
-
- if (current == null)
- {
- throw new InvalidTimeZoneException(SR.Argument_AdjustmentRulesNoNulls);
- }
-
- if (!IsValidAdjustmentRuleOffest(baseUtcOffset, current))
- {
- throw new InvalidTimeZoneException(SR.ArgumentOutOfRange_UtcOffsetAndDaylightDelta);
- }
-
- if (prev != null && current.DateStart <= prev.DateEnd)
- {
- // verify the rules are in chronological order and the DateStart/DateEnd do not overlap
- throw new InvalidTimeZoneException(SR.Argument_AdjustmentRulesOutOfOrder);
- }
- }
- }
- }
-
- private static readonly TimeSpan MaxOffset = TimeSpan.FromHours(14.0);
- private static readonly TimeSpan MinOffset = -MaxOffset;
-
- /// <summary>
- /// Helper function that validates the TimeSpan is within +/- 14.0 hours
- /// </summary>
- internal static bool UtcOffsetOutOfRange(TimeSpan offset) =>
- offset < MinOffset || offset > MaxOffset;
-
- private static TimeSpan GetUtcOffset(TimeSpan baseUtcOffset, AdjustmentRule adjustmentRule)
- {
- return baseUtcOffset
- + adjustmentRule.BaseUtcOffsetDelta
- + (adjustmentRule.HasDaylightSaving ? adjustmentRule.DaylightDelta : TimeSpan.Zero);
- }
-
- /// <summary>
- /// Helper function that performs adjustment rule validation
- /// </summary>
- private static bool IsValidAdjustmentRuleOffest(TimeSpan baseUtcOffset, AdjustmentRule adjustmentRule)
- {
- TimeSpan utcOffset = GetUtcOffset(baseUtcOffset, adjustmentRule);
- return !UtcOffsetOutOfRange(utcOffset);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZoneNotFoundException.cs b/netcore/System.Private.CoreLib/shared/System/TimeZoneNotFoundException.cs
deleted file mode 100644
index 40bd636be94..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TimeZoneNotFoundException.cs
+++ /dev/null
@@ -1,31 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class TimeZoneNotFoundException : Exception
- {
- public TimeZoneNotFoundException()
- {
- }
-
- public TimeZoneNotFoundException(string? message)
- : base(message)
- {
- }
-
- public TimeZoneNotFoundException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- }
-
- protected TimeZoneNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TimeoutException.cs b/netcore/System.Private.CoreLib/shared/System/TimeoutException.cs
deleted file mode 100644
index 3e96cb8e3c9..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TimeoutException.cs
+++ /dev/null
@@ -1,44 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: Exception class for Timeout
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class TimeoutException : SystemException
- {
- public TimeoutException()
- : base(SR.Arg_TimeoutException)
- {
- HResult = HResults.COR_E_TIMEOUT;
- }
-
- public TimeoutException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_TIMEOUT;
- }
-
- public TimeoutException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_TIMEOUT;
- }
-
- protected TimeoutException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Tuple.cs b/netcore/System.Private.CoreLib/shared/System/Tuple.cs
deleted file mode 100644
index dc00f29c9d8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Tuple.cs
+++ /dev/null
@@ -1,1142 +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 System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System
-{
- /// <summary>
- /// Helper so we can call some tuple methods recursively without knowing the underlying types.
- /// </summary>
- internal interface ITupleInternal : ITuple
- {
- string ToString(StringBuilder sb);
- int GetHashCode(IEqualityComparer comparer);
- }
-
- public static class Tuple
- {
- public static Tuple<T1> Create<T1>(T1 item1)
- {
- return new Tuple<T1>(item1);
- }
-
- public static Tuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2)
- {
- return new Tuple<T1, T2>(item1, item2);
- }
-
- public static Tuple<T1, T2, T3> Create<T1, T2, T3>(T1 item1, T2 item2, T3 item3)
- {
- return new Tuple<T1, T2, T3>(item1, item2, item3);
- }
-
- public static Tuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 item1, T2 item2, T3 item3, T4 item4)
- {
- return new Tuple<T1, T2, T3, T4>(item1, item2, item3, item4);
- }
-
- public static Tuple<T1, T2, T3, T4, T5> Create<T1, T2, T3, T4, T5>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)
- {
- return new Tuple<T1, T2, T3, T4, T5>(item1, item2, item3, item4, item5);
- }
-
- public static Tuple<T1, T2, T3, T4, T5, T6> Create<T1, T2, T3, T4, T5, T6>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)
- {
- return new Tuple<T1, T2, T3, T4, T5, T6>(item1, item2, item3, item4, item5, item6);
- }
-
- public static Tuple<T1, T2, T3, T4, T5, T6, T7> Create<T1, T2, T3, T4, T5, T6, T7>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
- {
- return new Tuple<T1, T2, T3, T4, T5, T6, T7>(item1, item2, item3, item4, item5, item6, item7);
- }
-
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>> Create<T1, T2, T3, T4, T5, T6, T7, T8>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8)
- {
- return new Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>>(item1, item2, item3, item4, item5, item6, item7, new Tuple<T8>(item8));
- }
-
- // Note: F# compiler depends on the exact tuple hashing algorithm. Do not ever change it.
-
- // From System.Web.Util.HashCodeCombiner
- internal static int CombineHashCodes(int h1, int h2)
- {
- return ((h1 << 5) + h1) ^ h2;
- }
-
- internal static int CombineHashCodes(int h1, int h2, int h3)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2), h3);
- }
-
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4));
- }
-
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), h5);
- }
-
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6));
- }
-
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7));
- }
-
- internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7, int h8)
- {
- return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7, h8));
- }
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
-
- public T1 Item1 => m_Item1;
-
- public Tuple(T1 item1)
- {
- m_Item1 = item1;
- }
-
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
-
- if (!(other is Tuple<T1> objTuple))
- {
- return false;
- }
-
- return comparer.Equals(m_Item1, objTuple.m_Item1);
- }
-
- int IComparable.CompareTo(object? obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is Tuple<T1> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
-
- return comparer.Compare(m_Item1, objTuple.m_Item1);
- }
-
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return comparer.GetHashCode(m_Item1!);
- }
-
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
-
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(')');
- return sb.ToString();
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 1;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index]
- {
- get
- {
- if (index != 0)
- {
- throw new IndexOutOfRangeException();
- }
- return Item1;
- }
- }
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
-
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
-
- public Tuple(T1 item1, T2 item2)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- }
-
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
-
- if (!(other is Tuple<T1, T2> objTuple))
- {
- return false;
- }
-
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2);
- }
-
- int IComparable.CompareTo(object? obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is Tuple<T1, T2> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
-
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
-
- if (c != 0) return c;
-
- return comparer.Compare(m_Item2, objTuple.m_Item2);
- }
-
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!));
- }
-
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
-
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(')');
- return sb.ToString();
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 2;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
-
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
-
- public Tuple(T1 item1, T2 item2, T3 item3)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- }
-
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
-
- if (!(other is Tuple<T1, T2, T3> objTuple))
- {
- return false;
- }
-
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3);
- }
-
- int IComparable.CompareTo(object? obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is Tuple<T1, T2, T3> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
-
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
-
- if (c != 0) return c;
-
- return comparer.Compare(m_Item3, objTuple.m_Item3);
- }
-
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!));
- }
-
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
-
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(')');
- return sb.ToString();
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 3;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
- private readonly T4 m_Item4; // Do not rename (binary serialization)
-
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
- public T4 Item4 => m_Item4;
-
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- m_Item4 = item4;
- }
-
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
-
- if (!(other is Tuple<T1, T2, T3, T4> objTuple))
- {
- return false;
- }
-
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4);
- }
-
- int IComparable.CompareTo(object? obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is Tuple<T1, T2, T3, T4> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
-
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item3, objTuple.m_Item3);
-
- if (c != 0) return c;
-
- return comparer.Compare(m_Item4, objTuple.m_Item4);
- }
-
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!));
- }
-
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
-
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(", ");
- sb.Append(m_Item4);
- sb.Append(')');
- return sb.ToString();
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 4;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
- private readonly T4 m_Item4; // Do not rename (binary serialization)
- private readonly T5 m_Item5; // Do not rename (binary serialization)
-
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
- public T4 Item4 => m_Item4;
- public T5 Item5 => m_Item5;
-
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- m_Item4 = item4;
- m_Item5 = item5;
- }
-
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
-
- if (!(other is Tuple<T1, T2, T3, T4, T5> objTuple))
- {
- return false;
- }
-
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_Item5);
- }
-
- int IComparable.CompareTo(object? obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is Tuple<T1, T2, T3, T4, T5> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
-
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item3, objTuple.m_Item3);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item4, objTuple.m_Item4);
-
- if (c != 0) return c;
-
- return comparer.Compare(m_Item5, objTuple.m_Item5);
- }
-
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!));
- }
-
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
-
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(", ");
- sb.Append(m_Item4);
- sb.Append(", ");
- sb.Append(m_Item5);
- sb.Append(')');
- return sb.ToString();
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 5;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
- private readonly T4 m_Item4; // Do not rename (binary serialization)
- private readonly T5 m_Item5; // Do not rename (binary serialization)
- private readonly T6 m_Item6; // Do not rename (binary serialization)
-
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
- public T4 Item4 => m_Item4;
- public T5 Item5 => m_Item5;
- public T6 Item6 => m_Item6;
-
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- m_Item4 = item4;
- m_Item5 = item5;
- m_Item6 = item6;
- }
-
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
-
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6> objTuple))
- {
- return false;
- }
-
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_Item5) && comparer.Equals(m_Item6, objTuple.m_Item6);
- }
-
- int IComparable.CompareTo(object? obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
-
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item3, objTuple.m_Item3);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item4, objTuple.m_Item4);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item5, objTuple.m_Item5);
-
- if (c != 0) return c;
-
- return comparer.Compare(m_Item6, objTuple.m_Item6);
- }
-
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!));
- }
-
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
-
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(", ");
- sb.Append(m_Item4);
- sb.Append(", ");
- sb.Append(m_Item5);
- sb.Append(", ");
- sb.Append(m_Item6);
- sb.Append(')');
- return sb.ToString();
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 6;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
- private readonly T4 m_Item4; // Do not rename (binary serialization)
- private readonly T5 m_Item5; // Do not rename (binary serialization)
- private readonly T6 m_Item6; // Do not rename (binary serialization)
- private readonly T7 m_Item7; // Do not rename (binary serialization)
-
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
- public T4 Item4 => m_Item4;
- public T5 Item5 => m_Item5;
- public T6 Item6 => m_Item6;
- public T7 Item7 => m_Item7;
-
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
- {
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- m_Item4 = item4;
- m_Item5 = item5;
- m_Item6 = item6;
- m_Item7 = item7;
- }
-
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
-
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7> objTuple))
- {
- return false;
- }
-
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_Item5) && comparer.Equals(m_Item6, objTuple.m_Item6) && comparer.Equals(m_Item7, objTuple.m_Item7);
- }
-
- int IComparable.CompareTo(object? obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
-
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item3, objTuple.m_Item3);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item4, objTuple.m_Item4);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item5, objTuple.m_Item5);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item6, objTuple.m_Item6);
-
- if (c != 0) return c;
-
- return comparer.Compare(m_Item7, objTuple.m_Item7);
- }
-
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!));
- }
-
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
-
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(", ");
- sb.Append(m_Item4);
- sb.Append(", ");
- sb.Append(m_Item5);
- sb.Append(", ");
- sb.Append(m_Item6);
- sb.Append(", ");
- sb.Append(m_Item7);
- sb.Append(')');
- return sb.ToString();
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 7;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- 6 => Item7,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple where TRest : notnull
- {
- private readonly T1 m_Item1; // Do not rename (binary serialization)
- private readonly T2 m_Item2; // Do not rename (binary serialization)
- private readonly T3 m_Item3; // Do not rename (binary serialization)
- private readonly T4 m_Item4; // Do not rename (binary serialization)
- private readonly T5 m_Item5; // Do not rename (binary serialization)
- private readonly T6 m_Item6; // Do not rename (binary serialization)
- private readonly T7 m_Item7; // Do not rename (binary serialization)
- private readonly TRest m_Rest; // Do not rename (binary serialization)
-
- public T1 Item1 => m_Item1;
- public T2 Item2 => m_Item2;
- public T3 Item3 => m_Item3;
- public T4 Item4 => m_Item4;
- public T5 Item5 => m_Item5;
- public T6 Item6 => m_Item6;
- public T7 Item7 => m_Item7;
- public TRest Rest => m_Rest;
-
- public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest)
- {
- if (!(rest is ITupleInternal))
- {
- throw new ArgumentException(SR.ArgumentException_TupleLastArgumentNotATuple);
- }
-
- m_Item1 = item1;
- m_Item2 = item2;
- m_Item3 = item3;
- m_Item4 = item4;
- m_Item5 = item5;
- m_Item6 = item6;
- m_Item7 = item7;
- m_Rest = rest;
- }
-
- public override bool Equals(object? obj)
- {
- return ((IStructuralEquatable)this).Equals(obj, EqualityComparer<object>.Default);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null) return false;
-
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> objTuple))
- {
- return false;
- }
-
- return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_Item5) && comparer.Equals(m_Item6, objTuple.m_Item6) && comparer.Equals(m_Item7, objTuple.m_Item7) && comparer.Equals(m_Rest, objTuple.m_Rest);
- }
-
- int IComparable.CompareTo(object? obj)
- {
- return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> objTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));
- }
-
- int c = comparer.Compare(m_Item1, objTuple.m_Item1);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item2, objTuple.m_Item2);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item3, objTuple.m_Item3);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item4, objTuple.m_Item4);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item5, objTuple.m_Item5);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item6, objTuple.m_Item6);
-
- if (c != 0) return c;
-
- c = comparer.Compare(m_Item7, objTuple.m_Item7);
-
- if (c != 0) return c;
-
- return comparer.Compare(m_Rest, objTuple.m_Rest);
- }
-
- public override int GetHashCode()
- {
- return ((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- // We want to have a limited hash in this case. We'll use the last 8 elements of the tuple
- ITupleInternal t = (ITupleInternal)m_Rest;
- if (t.Length >= 8) { return t.GetHashCode(comparer); }
-
- // In this case, the m_Rest member has fewer than 8 elements so we need to combine our elements with the elements in m_Rest.
- int k = 8 - t.Length;
- switch (k)
- {
- case 1:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 2:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 3:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 4:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 5:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 6:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- case 7:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));
- }
- Debug.Fail("Missed all cases for computing Tuple hash code");
- return -1;
- }
-
- int ITupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return ((IStructuralEquatable)this).GetHashCode(comparer);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append('(');
- return ((ITupleInternal)this).ToString(sb);
- }
-
- string ITupleInternal.ToString(StringBuilder sb)
- {
- sb.Append(m_Item1);
- sb.Append(", ");
- sb.Append(m_Item2);
- sb.Append(", ");
- sb.Append(m_Item3);
- sb.Append(", ");
- sb.Append(m_Item4);
- sb.Append(", ");
- sb.Append(m_Item5);
- sb.Append(", ");
- sb.Append(m_Item6);
- sb.Append(", ");
- sb.Append(m_Item7);
- sb.Append(", ");
- return ((ITupleInternal)m_Rest).ToString(sb);
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 7 + ((ITupleInternal)Rest).Length;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- 6 => Item7,
-
- _ => ((ITupleInternal)Rest)[index - 7],
- };
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TupleExtensions.cs b/netcore/System.Private.CoreLib/shared/System/TupleExtensions.cs
deleted file mode 100644
index 58547fc6fb2..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TupleExtensions.cs
+++ /dev/null
@@ -1,932 +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.
-
-#pragma warning disable SA1141 // explicitly not using tuple syntax in tuple implementation
-
-using System.ComponentModel;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- /// <summary>
- /// Provides extension methods for <see cref="Tuple"/> instances to interop with C# tuples features (deconstruction syntax, converting from and to <see cref="ValueTuple"/>).
- /// </summary>
- public static class TupleExtensions
- {
- #region Deconstruct
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 1 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1>(
- this Tuple<T1> value,
- out T1 item1)
- {
- item1 = value.Item1;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 2 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2>(
- this Tuple<T1, T2> value,
- out T1 item1, out T2 item2)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 3 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3>(
- this Tuple<T1, T2, T3> value,
- out T1 item1, out T2 item2, out T3 item3)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 4 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4>(
- this Tuple<T1, T2, T3, T4> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 5 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5>(
- this Tuple<T1, T2, T3, T4, T5> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 6 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6>(
- this Tuple<T1, T2, T3, T4, T5, T6> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 7 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 8 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 9 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 10 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 11 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10, out T11 item11)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- item11 = value.Rest.Item4;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 12 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10, out T11 item11, out T12 item12)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- item11 = value.Rest.Item4;
- item12 = value.Rest.Item5;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 13 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10, out T11 item11, out T12 item12, out T13 item13)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- item11 = value.Rest.Item4;
- item12 = value.Rest.Item5;
- item13 = value.Rest.Item6;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 14 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10, out T11 item11, out T12 item12, out T13 item13, out T14 item14)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- item11 = value.Rest.Item4;
- item12 = value.Rest.Item5;
- item13 = value.Rest.Item6;
- item14 = value.Rest.Item7;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 15 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15>>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10, out T11 item11, out T12 item12, out T13 item13, out T14 item14, out T15 item15)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- item11 = value.Rest.Item4;
- item12 = value.Rest.Item5;
- item13 = value.Rest.Item6;
- item14 = value.Rest.Item7;
- item15 = value.Rest.Rest.Item1;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 16 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16>>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10, out T11 item11, out T12 item12, out T13 item13, out T14 item14, out T15 item15, out T16 item16)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- item11 = value.Rest.Item4;
- item12 = value.Rest.Item5;
- item13 = value.Rest.Item6;
- item14 = value.Rest.Item7;
- item15 = value.Rest.Rest.Item1;
- item16 = value.Rest.Rest.Item2;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 17 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17>>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10, out T11 item11, out T12 item12, out T13 item13, out T14 item14, out T15 item15, out T16 item16, out T17 item17)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- item11 = value.Rest.Item4;
- item12 = value.Rest.Item5;
- item13 = value.Rest.Item6;
- item14 = value.Rest.Item7;
- item15 = value.Rest.Rest.Item1;
- item16 = value.Rest.Rest.Item2;
- item17 = value.Rest.Rest.Item3;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 18 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18>>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10, out T11 item11, out T12 item12, out T13 item13, out T14 item14, out T15 item15, out T16 item16, out T17 item17, out T18 item18)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- item11 = value.Rest.Item4;
- item12 = value.Rest.Item5;
- item13 = value.Rest.Item6;
- item14 = value.Rest.Item7;
- item15 = value.Rest.Rest.Item1;
- item16 = value.Rest.Rest.Item2;
- item17 = value.Rest.Rest.Item3;
- item18 = value.Rest.Rest.Item4;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 19 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18, T19>>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10, out T11 item11, out T12 item12, out T13 item13, out T14 item14, out T15 item15, out T16 item16, out T17 item17, out T18 item18, out T19 item19)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- item11 = value.Rest.Item4;
- item12 = value.Rest.Item5;
- item13 = value.Rest.Item6;
- item14 = value.Rest.Item7;
- item15 = value.Rest.Rest.Item1;
- item16 = value.Rest.Rest.Item2;
- item17 = value.Rest.Rest.Item3;
- item18 = value.Rest.Rest.Item4;
- item19 = value.Rest.Rest.Item5;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 20 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18, T19, T20>>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10, out T11 item11, out T12 item12, out T13 item13, out T14 item14, out T15 item15, out T16 item16, out T17 item17, out T18 item18, out T19 item19, out T20 item20)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- item11 = value.Rest.Item4;
- item12 = value.Rest.Item5;
- item13 = value.Rest.Item6;
- item14 = value.Rest.Item7;
- item15 = value.Rest.Rest.Item1;
- item16 = value.Rest.Rest.Item2;
- item17 = value.Rest.Rest.Item3;
- item18 = value.Rest.Rest.Item4;
- item19 = value.Rest.Rest.Item5;
- item20 = value.Rest.Rest.Item6;
- }
-
- /// <summary>
- /// Deconstruct a properly nested <see cref="Tuple"/> with 21 elements.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18, T19, T20, T21>>> value,
- out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9, out T10 item10, out T11 item11, out T12 item12, out T13 item13, out T14 item14, out T15 item15, out T16 item16, out T17 item17, out T18 item18, out T19 item19, out T20 item20, out T21 item21)
- {
- item1 = value.Item1;
- item2 = value.Item2;
- item3 = value.Item3;
- item4 = value.Item4;
- item5 = value.Item5;
- item6 = value.Item6;
- item7 = value.Item7;
- item8 = value.Rest.Item1;
- item9 = value.Rest.Item2;
- item10 = value.Rest.Item3;
- item11 = value.Rest.Item4;
- item12 = value.Rest.Item5;
- item13 = value.Rest.Item6;
- item14 = value.Rest.Item7;
- item15 = value.Rest.Rest.Item1;
- item16 = value.Rest.Rest.Item2;
- item17 = value.Rest.Rest.Item3;
- item18 = value.Rest.Rest.Item4;
- item19 = value.Rest.Rest.Item5;
- item20 = value.Rest.Rest.Item6;
- item21 = value.Rest.Rest.Item7;
- }
- #endregion
-
- #region ToValueTuple
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 1 element.
- /// </summary>
- public static ValueTuple<T1>
- ToValueTuple<T1>(
- this Tuple<T1> value)
- {
- return ValueTuple.Create(value.Item1);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 2 elements.
- /// </summary>
- public static ValueTuple<T1, T2>
- ToValueTuple<T1, T2>(
- this Tuple<T1, T2> value)
- {
- return ValueTuple.Create(value.Item1, value.Item2);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 3 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3>
- ToValueTuple<T1, T2, T3>(
- this Tuple<T1, T2, T3> value)
- {
- return ValueTuple.Create(value.Item1, value.Item2, value.Item3);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 4 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4>
- ToValueTuple<T1, T2, T3, T4>(
- this Tuple<T1, T2, T3, T4> value)
- {
- return ValueTuple.Create(value.Item1, value.Item2, value.Item3, value.Item4);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 5 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5>
- ToValueTuple<T1, T2, T3, T4, T5>(
- this Tuple<T1, T2, T3, T4, T5> value)
- {
- return ValueTuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 6 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6>
- ToValueTuple<T1, T2, T3, T4, T5, T6>(
- this Tuple<T1, T2, T3, T4, T5, T6> value)
- {
- return ValueTuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 7 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7> value)
- {
- return ValueTuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 8 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- ValueTuple.Create(value.Rest.Item1));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 9 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- ValueTuple.Create(value.Rest.Item1, value.Rest.Item2));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 10 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- ValueTuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 11 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- ValueTuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 12 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- ValueTuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 13 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- ValueTuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 14 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- ValueTuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 15 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15>>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15>>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLong(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- ValueTuple.Create(value.Rest.Rest.Item1)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 16 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16>>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16>>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLong(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- ValueTuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 17 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16, T17>>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17>>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLong(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- ValueTuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2, value.Rest.Rest.Item3)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 18 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16, T17, T18>>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18>>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLong(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- ValueTuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2, value.Rest.Rest.Item3, value.Rest.Rest.Item4)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 19 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16, T17, T18, T19>>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18, T19>>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLong(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- ValueTuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2, value.Rest.Rest.Item3, value.Rest.Rest.Item4, value.Rest.Rest.Item5)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 20 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16, T17, T18, T19, T20>>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18, T19, T20>>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLong(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- ValueTuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2, value.Rest.Rest.Item3, value.Rest.Rest.Item4, value.Rest.Rest.Item5, value.Rest.Rest.Item6)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="ValueTuple"/> from a properly nested <see cref="Tuple"/> with 21 elements.
- /// </summary>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16, T17, T18, T19, T20, T21>>>
- ToValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21>(
- this Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18, T19, T20, T21>>> value)
- {
- return CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLong(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- ValueTuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2, value.Rest.Rest.Item3, value.Rest.Rest.Item4, value.Rest.Rest.Item5, value.Rest.Rest.Item6, value.Rest.Rest.Item7)));
- }
- #endregion
-
- #region ToTuple
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 1 element.
- /// </summary>
- public static Tuple<T1>
- ToTuple<T1>(
- this ValueTuple<T1> value)
- {
- return Tuple.Create(value.Item1);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 2 elements.
- /// </summary>
- public static Tuple<T1, T2>
- ToTuple<T1, T2>(
- this ValueTuple<T1, T2> value)
- {
- return Tuple.Create(value.Item1, value.Item2);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 3 elements.
- /// </summary>
- public static Tuple<T1, T2, T3>
- ToTuple<T1, T2, T3>(
- this ValueTuple<T1, T2, T3> value)
- {
- return Tuple.Create(value.Item1, value.Item2, value.Item3);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 4 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4>
- ToTuple<T1, T2, T3, T4>(
- this ValueTuple<T1, T2, T3, T4> value)
- {
- return Tuple.Create(value.Item1, value.Item2, value.Item3, value.Item4);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 5 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5>
- ToTuple<T1, T2, T3, T4, T5>(
- this ValueTuple<T1, T2, T3, T4, T5> value)
- {
- return Tuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 6 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6>
- ToTuple<T1, T2, T3, T4, T5, T6>(
- this ValueTuple<T1, T2, T3, T4, T5, T6> value)
- {
- return Tuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 7 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7>
- ToTuple<T1, T2, T3, T4, T5, T6, T7>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7> value)
- {
- return Tuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7);
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 8 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- Tuple.Create(value.Rest.Item1));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 9 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- Tuple.Create(value.Rest.Item1, value.Rest.Item2));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 10 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- Tuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 11 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- Tuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 12 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- Tuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 13 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- Tuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 14 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- Tuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 15 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15>>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15>>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLongRef(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- Tuple.Create(value.Rest.Rest.Item1)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 16 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16>>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16>>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLongRef(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- Tuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 17 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17>>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16, T17>>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLongRef(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- Tuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2, value.Rest.Rest.Item3)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 18 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18>>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16, T17, T18>>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLongRef(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- Tuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2, value.Rest.Rest.Item3, value.Rest.Rest.Item4)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 19 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18, T19>>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16, T17, T18, T19>>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLongRef(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- Tuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2, value.Rest.Rest.Item3, value.Rest.Rest.Item4, value.Rest.Rest.Item5)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 20 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18, T19, T20>>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16, T17, T18, T19, T20>>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLongRef(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- Tuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2, value.Rest.Rest.Item3, value.Rest.Rest.Item4, value.Rest.Rest.Item5, value.Rest.Rest.Item6)));
- }
-
- /// <summary>
- /// Make a properly nested <see cref="Tuple"/> from a properly nested <see cref="ValueTuple"/> with 21 elements.
- /// </summary>
- public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15, T16, T17, T18, T19, T20, T21>>>
- ToTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21>(
- this ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8, T9, T10, T11, T12, T13, T14, ValueTuple<T15, T16, T17, T18, T19, T20, T21>>> value)
- {
- return CreateLongRef(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
- CreateLongRef(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7,
- Tuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2, value.Rest.Rest.Item3, value.Rest.Rest.Item4, value.Rest.Rest.Item5, value.Rest.Rest.Item6, value.Rest.Rest.Item7)));
- }
- #endregion
-
- private static ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> CreateLong<T1, T2, T3, T4, T5, T6, T7, TRest>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest) where TRest : struct, ITuple =>
- new ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>(item1, item2, item3, item4, item5, item6, item7, rest);
-
- private static Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> CreateLongRef<T1, T2, T3, T4, T5, T6, T7, TRest>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest) where TRest : ITuple =>
- new Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>(item1, item2, item3, item4, item5, item6, item7, rest);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Type.Enum.cs b/netcore/System.Private.CoreLib/shared/System/Type.Enum.cs
deleted file mode 100644
index ee9e158eecc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Type.Enum.cs
+++ /dev/null
@@ -1,183 +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 System.Reflection;
-using System.Collections;
-using System.Collections.Generic;
-
-namespace System
-{
- //
- // This file collects a set of Enum-related apis that run when the Type is subclassed by an application.
- // None of it runs on normal Type objects supplied by the runtime (as those types override these methods.)
- //
- // Since app-subclassed Types are "untrusted classes" that may or may not implement the complete surface area correctly,
- // this code should be considered brittle and not changed lightly.
- //
- public abstract partial class Type
- {
- public virtual bool IsEnumDefined(object value)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- if (!IsEnum)
- throw new ArgumentException(SR.Arg_MustBeEnum, "enumType");
-
- // Check if both of them are of the same type
- Type valueType = value.GetType();
-
- // If the value is an Enum then we need to extract the underlying value from it
- if (valueType.IsEnum)
- {
- if (!valueType.IsEquivalentTo(this))
- throw new ArgumentException(SR.Format(SR.Arg_EnumAndObjectMustBeSameType, valueType, this));
-
- valueType = valueType.GetEnumUnderlyingType();
- }
-
- // If a string is passed in
- if (valueType == typeof(string))
- {
- string[] names = GetEnumNames();
- if (Array.IndexOf(names, value) >= 0)
- return true;
- else
- return false;
- }
-
- // If an enum or integer value is passed in
- if (Type.IsIntegerType(valueType))
- {
- Type underlyingType = GetEnumUnderlyingType();
- // We cannot compare the types directly because valueType is always a runtime type but underlyingType might not be.
- if (underlyingType.GetTypeCodeImpl() != valueType.GetTypeCodeImpl())
- throw new ArgumentException(SR.Format(SR.Arg_EnumUnderlyingTypeAndObjectMustBeSameType, valueType, underlyingType));
-
- Array values = GetEnumRawConstantValues();
- return BinarySearch(values, value) >= 0;
- }
- else
- {
- throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
- }
- }
-
- public virtual string? GetEnumName(object value)
- {
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- if (!IsEnum)
- throw new ArgumentException(SR.Arg_MustBeEnum, "enumType");
-
- Type valueType = value.GetType();
-
- if (!(valueType.IsEnum || Type.IsIntegerType(valueType)))
- throw new ArgumentException(SR.Arg_MustBeEnumBaseTypeOrEnum, nameof(value));
-
- Array values = GetEnumRawConstantValues();
- int index = BinarySearch(values, value);
-
- if (index >= 0)
- {
- string[] names = GetEnumNames();
- return names[index];
- }
-
- return null;
- }
-
- public virtual string[] GetEnumNames()
- {
- if (!IsEnum)
- throw new ArgumentException(SR.Arg_MustBeEnum, "enumType");
-
- string[] names;
- Array values;
- GetEnumData(out names, out values);
- return names;
- }
-
- // Returns the enum values as an object array.
- private Array GetEnumRawConstantValues()
- {
- GetEnumData(out _, out Array values);
- return values;
- }
-
- // This will return enumValues and enumNames sorted by the values.
- private void GetEnumData(out string[] enumNames, out Array enumValues)
- {
- FieldInfo[] flds = GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
-
- object[] values = new object[flds.Length];
- string[] names = new string[flds.Length];
-
- for (int i = 0; i < flds.Length; i++)
- {
- names[i] = flds[i].Name;
- values[i] = flds[i].GetRawConstantValue()!;
- }
-
- // Insertion Sort these values in ascending order.
- // We use this O(n^2) algorithm, but it turns out that most of the time the elements are already in sorted order and
- // the common case performance will be faster than quick sorting this.
- IComparer comparer = Comparer<object>.Default;
- for (int i = 1; i < values.Length; i++)
- {
- int j = i;
- string tempStr = names[i];
- object val = values[i];
- bool exchanged = false;
-
- // Since the elements are sorted we only need to do one comparision, we keep the check for j inside the loop.
- while (comparer.Compare(values[j - 1], val) > 0)
- {
- names[j] = names[j - 1];
- values[j] = values[j - 1];
- j--;
- exchanged = true;
- if (j == 0)
- break;
- }
-
- if (exchanged)
- {
- names[j] = tempStr;
- values[j] = val;
- }
- }
-
- enumNames = names;
- enumValues = values;
- }
-
- // Convert everything to ulong then perform a binary search.
- private static int BinarySearch(Array array, object value)
- {
- ulong[] ulArray = new ulong[array.Length];
- for (int i = 0; i < array.Length; ++i)
- ulArray[i] = Enum.ToUInt64(array.GetValue(i)!);
-
- ulong ulValue = Enum.ToUInt64(value);
-
- return Array.BinarySearch(ulArray, ulValue);
- }
-
- internal static bool IsIntegerType(Type t)
- {
- return t == typeof(int) ||
- t == typeof(short) ||
- t == typeof(ushort) ||
- t == typeof(byte) ||
- t == typeof(sbyte) ||
- t == typeof(uint) ||
- t == typeof(long) ||
- t == typeof(ulong) ||
- t == typeof(char) ||
- t == typeof(bool);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Type.Helpers.cs b/netcore/System.Private.CoreLib/shared/System/Type.Helpers.cs
deleted file mode 100644
index 20e41d9c5bc..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Type.Helpers.cs
+++ /dev/null
@@ -1,502 +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 System.Reflection;
-
-namespace System
-{
- // This file collects the longer methods of Type to make the main Type class more readable.
- public abstract partial class Type : MemberInfo, IReflect
- {
- public virtual bool IsSerializable
- {
- get
- {
- if ((GetAttributeFlagsImpl() & TypeAttributes.Serializable) != 0)
- return true;
-
- Type? underlyingType = UnderlyingSystemType;
- if (underlyingType.IsRuntimeImplemented())
- {
- do
- {
- // In all sane cases we only need to compare the direct level base type with
- // System.Enum and System.MulticastDelegate. However, a generic parameter can
- // have a base type constraint that is Delegate or even a real delegate type.
- // Let's maintain compatibility and return true for them.
- if (underlyingType == typeof(Delegate) || underlyingType == typeof(Enum))
- return true;
-
- underlyingType = underlyingType.BaseType;
- }
- while (underlyingType != null);
- }
-
- return false;
- }
- }
-
- public virtual bool ContainsGenericParameters
- {
- get
- {
- if (HasElementType)
- return GetRootElementType().ContainsGenericParameters;
-
- if (IsGenericParameter)
- return true;
-
- if (!IsGenericType)
- return false;
-
- Type[] genericArguments = GetGenericArguments();
- for (int i = 0; i < genericArguments.Length; i++)
- {
- if (genericArguments[i].ContainsGenericParameters)
- return true;
- }
-
- return false;
- }
- }
-
- internal Type GetRootElementType()
- {
- Type rootElementType = this;
-
- while (rootElementType.HasElementType)
- rootElementType = rootElementType.GetElementType()!;
-
- return rootElementType;
- }
-
- public bool IsVisible
- {
- get
- {
-#if CORECLR
- if (this is RuntimeType rt)
- return RuntimeTypeHandle.IsVisible(rt);
-#endif //CORECLR
-
- if (IsGenericParameter)
- return true;
-
- if (HasElementType)
- return GetElementType()!.IsVisible;
-
- Type type = this;
- while (type.IsNested)
- {
- if (!type.IsNestedPublic)
- return false;
-
- // this should be null for non-nested types.
- type = type.DeclaringType!;
- }
-
- // Now "type" should be a top level type
- if (!type.IsPublic)
- return false;
-
- if (IsGenericType && !IsGenericTypeDefinition)
- {
- foreach (Type t in GetGenericArguments())
- {
- if (!t.IsVisible)
- return false;
- }
- }
-
- return true;
- }
- }
-
- public virtual Type[] FindInterfaces(TypeFilter filter, object? filterCriteria)
- {
- if (filter == null)
- throw new ArgumentNullException(nameof(filter));
-
- Type?[] c = GetInterfaces();
- int cnt = 0;
- for (int i = 0; i < c.Length; i++)
- {
- if (!filter(c[i]!, filterCriteria))
- c[i] = null;
- else
- cnt++;
- }
- if (cnt == c.Length)
- return c!;
-
- Type[] ret = new Type[cnt];
- cnt = 0;
- for (int i = 0; i < c.Length; i++)
- {
- if (c[i] != null)
- ret[cnt++] = c[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- }
- return ret;
- }
-
- public virtual MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bindingAttr, MemberFilter? filter, object? filterCriteria)
- {
- // Define the work arrays
- MethodInfo?[]? m = null;
- ConstructorInfo?[]? c = null;
- FieldInfo?[]? f = null;
- PropertyInfo?[]? p = null;
- EventInfo?[]? e = null;
- Type?[]? t = null;
-
- int i;
- int cnt = 0; // Total Matchs
-
- // Check the methods
- if ((memberType & MemberTypes.Method) != 0)
- {
- m = GetMethods(bindingAttr);
- if (filter != null)
- {
- for (i = 0; i < m.Length; i++)
- if (!filter(m[i]!, filterCriteria))
- m[i] = null;
- else
- cnt++;
- }
- else
- {
- cnt += m.Length;
- }
- }
-
- // Check the constructors
- if ((memberType & MemberTypes.Constructor) != 0)
- {
- c = GetConstructors(bindingAttr);
- if (filter != null)
- {
- for (i = 0; i < c.Length; i++)
- if (!filter(c[i]!, filterCriteria))
- c[i] = null;
- else
- cnt++;
- }
- else
- {
- cnt += c.Length;
- }
- }
-
- // Check the fields
- if ((memberType & MemberTypes.Field) != 0)
- {
- f = GetFields(bindingAttr);
- if (filter != null)
- {
- for (i = 0; i < f.Length; i++)
- if (!filter(f[i]!, filterCriteria))
- f[i] = null;
- else
- cnt++;
- }
- else
- {
- cnt += f.Length;
- }
- }
-
- // Check the Properties
- if ((memberType & MemberTypes.Property) != 0)
- {
- p = GetProperties(bindingAttr);
- if (filter != null)
- {
- for (i = 0; i < p.Length; i++)
- if (!filter(p[i]!, filterCriteria))
- p[i] = null;
- else
- cnt++;
- }
- else
- {
- cnt += p.Length;
- }
- }
-
- // Check the Events
- if ((memberType & MemberTypes.Event) != 0)
- {
- e = GetEvents(bindingAttr);
- if (filter != null)
- {
- for (i = 0; i < e.Length; i++)
- if (!filter(e[i]!, filterCriteria))
- e[i] = null;
- else
- cnt++;
- }
- else
- {
- cnt += e.Length;
- }
- }
-
- // Check the Types
- if ((memberType & MemberTypes.NestedType) != 0)
- {
- t = GetNestedTypes(bindingAttr);
- if (filter != null)
- {
- for (i = 0; i < t.Length; i++)
- if (!filter(t[i]!, filterCriteria))
- t[i] = null;
- else
- cnt++;
- }
- else
- {
- cnt += t.Length;
- }
- }
-
- // Allocate the Member Info
- MemberInfo[] ret = new MemberInfo[cnt];
-
- // Copy the Methods
- cnt = 0;
- if (m != null)
- {
- for (i = 0; i < m.Length; i++)
- if (m[i] != null)
- ret[cnt++] = m[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- }
-
- // Copy the Constructors
- if (c != null)
- {
- for (i = 0; i < c.Length; i++)
- if (c[i] != null)
- ret[cnt++] = c[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- }
-
- // Copy the Fields
- if (f != null)
- {
- for (i = 0; i < f.Length; i++)
- if (f[i] != null)
- ret[cnt++] = f[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- }
-
- // Copy the Properties
- if (p != null)
- {
- for (i = 0; i < p.Length; i++)
- if (p[i] != null)
- ret[cnt++] = p[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- }
-
- // Copy the Events
- if (e != null)
- {
- for (i = 0; i < e.Length; i++)
- if (e[i] != null)
- ret[cnt++] = e[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- }
-
- // Copy the Types
- if (t != null)
- {
- for (i = 0; i < t.Length; i++)
- if (t[i] != null)
- ret[cnt++] = t[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
- }
-
- return ret;
- }
-
- public virtual bool IsSubclassOf(Type c)
- {
- Type? p = this;
- if (p == c)
- return false;
- while (p != null)
- {
- if (p == c)
- return true;
- p = p.BaseType;
- }
- return false;
- }
-
- public virtual bool IsAssignableFrom(Type? c)
- {
- if (c == null)
- return false;
-
- if (this == c)
- return true;
-
- // For backward-compatibility, we need to special case for the types
- // whose UnderlyingSystemType are runtime implemented.
- Type toType = this.UnderlyingSystemType;
- if (toType?.IsRuntimeImplemented() == true)
- return toType.IsAssignableFrom(c);
-
- // If c is a subclass of this class, then c can be cast to this type.
- if (c.IsSubclassOf(this))
- return true;
-
- if (this.IsInterface)
- {
- return c.ImplementInterface(this);
- }
- else if (IsGenericParameter)
- {
- Type[] constraints = GetGenericParameterConstraints();
- for (int i = 0; i < constraints.Length; i++)
- if (!constraints[i].IsAssignableFrom(c))
- return false;
-
- return true;
- }
-
- return false;
- }
-
- internal bool ImplementInterface(Type ifaceType)
- {
- Type? t = this;
- while (t != null)
- {
- Type[] interfaces = t.GetInterfaces();
- if (interfaces != null)
- {
- for (int i = 0; i < interfaces.Length; i++)
- {
- // Interfaces don't derive from other interfaces, they implement them.
- // So instead of IsSubclassOf, we should use ImplementInterface instead.
- if (interfaces[i] == ifaceType ||
- (interfaces[i] != null && interfaces[i].ImplementInterface(ifaceType)))
- return true;
- }
- }
-
- t = t.BaseType;
- }
-
- return false;
- }
-
- // FilterAttribute
- // This method will search for a member based upon the attribute passed in.
- // filterCriteria -- an Int32 representing the attribute
- private static bool FilterAttributeImpl(MemberInfo m, object filterCriteria)
- {
- // Check that the criteria object is an Integer object
- if (filterCriteria == null)
- throw new InvalidFilterCriteriaException(SR.InvalidFilterCriteriaException_CritInt);
-
- switch (m.MemberType)
- {
- case MemberTypes.Constructor:
- case MemberTypes.Method:
- {
- MethodAttributes criteria = 0;
- try
- {
- int i = (int)filterCriteria;
- criteria = (MethodAttributes)i;
- }
- catch
- {
- throw new InvalidFilterCriteriaException(SR.InvalidFilterCriteriaException_CritInt);
- }
-
-
- MethodAttributes attr;
- if (m.MemberType == MemberTypes.Method)
- attr = ((MethodInfo)m).Attributes;
- else
- attr = ((ConstructorInfo)m).Attributes;
-
- if (((criteria & MethodAttributes.MemberAccessMask) != 0) && (attr & MethodAttributes.MemberAccessMask) != (criteria & MethodAttributes.MemberAccessMask))
- return false;
- if (((criteria & MethodAttributes.Static) != 0) && (attr & MethodAttributes.Static) == 0)
- return false;
- if (((criteria & MethodAttributes.Final) != 0) && (attr & MethodAttributes.Final) == 0)
- return false;
- if (((criteria & MethodAttributes.Virtual) != 0) && (attr & MethodAttributes.Virtual) == 0)
- return false;
- if (((criteria & MethodAttributes.Abstract) != 0) && (attr & MethodAttributes.Abstract) == 0)
- return false;
- if (((criteria & MethodAttributes.SpecialName) != 0) && (attr & MethodAttributes.SpecialName) == 0)
- return false;
- return true;
- }
- case MemberTypes.Field:
- {
- FieldAttributes criteria = 0;
- try
- {
- int i = (int)filterCriteria;
- criteria = (FieldAttributes)i;
- }
- catch
- {
- throw new InvalidFilterCriteriaException(SR.InvalidFilterCriteriaException_CritInt);
- }
-
- FieldAttributes attr = ((FieldInfo)m).Attributes;
- if (((criteria & FieldAttributes.FieldAccessMask) != 0) && (attr & FieldAttributes.FieldAccessMask) != (criteria & FieldAttributes.FieldAccessMask))
- return false;
- if (((criteria & FieldAttributes.Static) != 0) && (attr & FieldAttributes.Static) == 0)
- return false;
- if (((criteria & FieldAttributes.InitOnly) != 0) && (attr & FieldAttributes.InitOnly) == 0)
- return false;
- if (((criteria & FieldAttributes.Literal) != 0) && (attr & FieldAttributes.Literal) == 0)
- return false;
- if (((criteria & FieldAttributes.NotSerialized) != 0) && (attr & FieldAttributes.NotSerialized) == 0)
- return false;
- if (((criteria & FieldAttributes.PinvokeImpl) != 0) && (attr & FieldAttributes.PinvokeImpl) == 0)
- return false;
- return true;
- }
- }
-
- return false;
- }
-
- // FilterName
- // This method will filter based upon the name. A partial wildcard
- // at the end of the string is supported.
- // filterCriteria -- This is the string name
- private static bool FilterNameImpl(MemberInfo m, object filterCriteria, StringComparison comparison)
- {
- // Check that the criteria object is a String object
- if (!(filterCriteria is string filterCriteriaString))
- {
- throw new InvalidFilterCriteriaException(SR.InvalidFilterCriteriaException_CritString);
- }
-
- ReadOnlySpan<char> str = filterCriteriaString.AsSpan().Trim();
- ReadOnlySpan<char> name = m.Name;
-
- // Get the nested class name only, as opposed to the mangled one
- if (m.MemberType == MemberTypes.NestedType)
- {
- name = name.Slice(name.LastIndexOf('+') + 1);
- }
-
- // Check to see if this is a prefix or exact match requirement
- if (str.Length > 0 && str[str.Length - 1] == '*')
- {
- str = str.Slice(0, str.Length - 1);
- return name.StartsWith(str, comparison);
- }
-
- return name.Equals(str, comparison);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Type.cs b/netcore/System.Private.CoreLib/shared/System/Type.cs
deleted file mode 100644
index c525497dcd8..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Type.cs
+++ /dev/null
@@ -1,413 +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 System.Threading;
-using System.Reflection;
-using System.Diagnostics;
-using System.Globalization;
-using System.Runtime.InteropServices;
-
-namespace System
-{
- public abstract partial class Type : MemberInfo, IReflect
- {
- protected Type() { }
-
- public override MemberTypes MemberType => MemberTypes.TypeInfo;
-
- public new Type GetType() => base.GetType();
-
- public abstract string? Namespace { get; }
- public abstract string? AssemblyQualifiedName { get; }
- public abstract string? FullName { get; }
-
- public abstract Assembly Assembly { get; }
- public new abstract Module Module { get; }
-
- public bool IsNested => DeclaringType != null;
- public override Type? DeclaringType => null;
- public virtual MethodBase? DeclaringMethod => null;
-
- public override Type? ReflectedType => null;
- public abstract Type UnderlyingSystemType { get; }
-
- public virtual bool IsTypeDefinition => throw NotImplemented.ByDesign;
- public bool IsArray => IsArrayImpl();
- protected abstract bool IsArrayImpl();
- public bool IsByRef => IsByRefImpl();
- protected abstract bool IsByRefImpl();
- public bool IsPointer => IsPointerImpl();
- protected abstract bool IsPointerImpl();
- public virtual bool IsConstructedGenericType => throw NotImplemented.ByDesign;
- public virtual bool IsGenericParameter => false;
- public virtual bool IsGenericTypeParameter => IsGenericParameter && DeclaringMethod is null;
- public virtual bool IsGenericMethodParameter => IsGenericParameter && DeclaringMethod != null;
- public virtual bool IsGenericType => false;
- public virtual bool IsGenericTypeDefinition => false;
-
- public virtual bool IsSZArray => throw NotImplemented.ByDesign;
- public virtual bool IsVariableBoundArray => IsArray && !IsSZArray;
-
- public virtual bool IsByRefLike => throw new NotSupportedException(SR.NotSupported_SubclassOverride);
-
- public bool HasElementType => HasElementTypeImpl();
- protected abstract bool HasElementTypeImpl();
- public abstract Type? GetElementType();
-
- public virtual int GetArrayRank() => throw new NotSupportedException(SR.NotSupported_SubclassOverride);
-
- public virtual Type GetGenericTypeDefinition() => throw new NotSupportedException(SR.NotSupported_SubclassOverride);
- public virtual Type[] GenericTypeArguments => (IsGenericType && !IsGenericTypeDefinition) ? GetGenericArguments() : Array.Empty<Type>();
- public virtual Type[] GetGenericArguments() => throw new NotSupportedException(SR.NotSupported_SubclassOverride);
-
- public virtual int GenericParameterPosition => throw new InvalidOperationException(SR.Arg_NotGenericParameter);
- public virtual GenericParameterAttributes GenericParameterAttributes => throw new NotSupportedException();
- public virtual Type[] GetGenericParameterConstraints()
- {
- if (!IsGenericParameter)
- throw new InvalidOperationException(SR.Arg_NotGenericParameter);
- throw new InvalidOperationException();
- }
-
- public TypeAttributes Attributes => GetAttributeFlagsImpl();
- protected abstract TypeAttributes GetAttributeFlagsImpl();
-
- public bool IsAbstract => (GetAttributeFlagsImpl() & TypeAttributes.Abstract) != 0;
- public bool IsImport => (GetAttributeFlagsImpl() & TypeAttributes.Import) != 0;
- public bool IsSealed => (GetAttributeFlagsImpl() & TypeAttributes.Sealed) != 0;
- public bool IsSpecialName => (GetAttributeFlagsImpl() & TypeAttributes.SpecialName) != 0;
-
- public bool IsClass => (GetAttributeFlagsImpl() & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class && !IsValueType;
-
- public bool IsNestedAssembly => (GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
- public bool IsNestedFamANDAssem => (GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem;
- public bool IsNestedFamily => (GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily;
- public bool IsNestedFamORAssem => (GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem;
- public bool IsNestedPrivate => (GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate;
- public bool IsNestedPublic => (GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
- public bool IsNotPublic => (GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic;
- public bool IsPublic => (GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.Public;
-
- public bool IsAutoLayout => (GetAttributeFlagsImpl() & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout;
- public bool IsExplicitLayout => (GetAttributeFlagsImpl() & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
- public bool IsLayoutSequential => (GetAttributeFlagsImpl() & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
-
- public bool IsAnsiClass => (GetAttributeFlagsImpl() & TypeAttributes.StringFormatMask) == TypeAttributes.AnsiClass;
- public bool IsAutoClass => (GetAttributeFlagsImpl() & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass;
- public bool IsUnicodeClass => (GetAttributeFlagsImpl() & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass;
-
- public bool IsCOMObject => IsCOMObjectImpl();
- protected abstract bool IsCOMObjectImpl();
- public bool IsContextful => IsContextfulImpl();
- protected virtual bool IsContextfulImpl() => false;
-
- public virtual bool IsEnum => IsSubclassOf(typeof(Enum));
- public bool IsMarshalByRef => IsMarshalByRefImpl();
- protected virtual bool IsMarshalByRefImpl() => false;
- public bool IsPrimitive => IsPrimitiveImpl();
- protected abstract bool IsPrimitiveImpl();
- public bool IsValueType => IsValueTypeImpl();
- protected virtual bool IsValueTypeImpl() => IsSubclassOf(typeof(ValueType));
-
- public virtual bool IsSignatureType => false;
-
- public virtual bool IsSecurityCritical => throw NotImplemented.ByDesign;
- public virtual bool IsSecuritySafeCritical => throw NotImplemented.ByDesign;
- public virtual bool IsSecurityTransparent => throw NotImplemented.ByDesign;
-
- public virtual StructLayoutAttribute? StructLayoutAttribute => throw new NotSupportedException();
- public ConstructorInfo? TypeInitializer => GetConstructorImpl(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, CallingConventions.Any, Type.EmptyTypes, null);
-
- public ConstructorInfo? GetConstructor(Type[] types) => GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, types, null);
- public ConstructorInfo? GetConstructor(BindingFlags bindingAttr, Binder? binder, Type[] types, ParameterModifier[]? modifiers) => GetConstructor(bindingAttr, binder, CallingConventions.Any, types, modifiers);
- public ConstructorInfo? GetConstructor(BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers)
- {
- if (types == null)
- throw new ArgumentNullException(nameof(types));
- for (int i = 0; i < types.Length; i++)
- {
- if (types[i] == null)
- throw new ArgumentNullException(nameof(types));
- }
- return GetConstructorImpl(bindingAttr, binder, callConvention, types, modifiers);
- }
- protected abstract ConstructorInfo? GetConstructorImpl(BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers);
-
- public ConstructorInfo[] GetConstructors() => GetConstructors(BindingFlags.Public | BindingFlags.Instance);
- public abstract ConstructorInfo[] GetConstructors(BindingFlags bindingAttr);
-
- public EventInfo? GetEvent(string name) => GetEvent(name, Type.DefaultLookup);
- public abstract EventInfo? GetEvent(string name, BindingFlags bindingAttr);
-
- public virtual EventInfo[] GetEvents() => GetEvents(Type.DefaultLookup);
- public abstract EventInfo[] GetEvents(BindingFlags bindingAttr);
-
- public FieldInfo? GetField(string name) => GetField(name, Type.DefaultLookup);
- public abstract FieldInfo? GetField(string name, BindingFlags bindingAttr);
-
- public FieldInfo[] GetFields() => GetFields(Type.DefaultLookup);
- public abstract FieldInfo[] GetFields(BindingFlags bindingAttr);
-
- public MemberInfo[] GetMember(string name) => GetMember(name, Type.DefaultLookup);
- public virtual MemberInfo[] GetMember(string name, BindingFlags bindingAttr) => GetMember(name, MemberTypes.All, bindingAttr);
- public virtual MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr) => throw new NotSupportedException(SR.NotSupported_SubclassOverride);
-
- public MemberInfo[] GetMembers() => GetMembers(Type.DefaultLookup);
- public abstract MemberInfo[] GetMembers(BindingFlags bindingAttr);
-
- public MethodInfo? GetMethod(string name) => GetMethod(name, Type.DefaultLookup);
- public MethodInfo? GetMethod(string name, BindingFlags bindingAttr)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- return GetMethodImpl(name, bindingAttr, null, CallingConventions.Any, null, null);
- }
-
- public MethodInfo? GetMethod(string name, Type[] types) => GetMethod(name, types, null);
- public MethodInfo? GetMethod(string name, Type[] types, ParameterModifier[]? modifiers) => GetMethod(name, Type.DefaultLookup, null, types, modifiers);
- public MethodInfo? GetMethod(string name, BindingFlags bindingAttr, Binder? binder, Type[] types, ParameterModifier[]? modifiers) => GetMethod(name, bindingAttr, binder, CallingConventions.Any, types, modifiers);
- public MethodInfo? GetMethod(string name, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- if (types == null)
- throw new ArgumentNullException(nameof(types));
- for (int i = 0; i < types.Length; i++)
- {
- if (types[i] == null)
- throw new ArgumentNullException(nameof(types));
- }
- return GetMethodImpl(name, bindingAttr, binder, callConvention, types, modifiers);
- }
-
- protected abstract MethodInfo? GetMethodImpl(string name, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[]? types, ParameterModifier[]? modifiers);
-
- public MethodInfo? GetMethod(string name, int genericParameterCount, Type[] types) => GetMethod(name, genericParameterCount, types, null);
- public MethodInfo? GetMethod(string name, int genericParameterCount, Type[] types, ParameterModifier[]? modifiers) => GetMethod(name, genericParameterCount, Type.DefaultLookup, null, types, modifiers);
- public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Binder? binder, Type[] types, ParameterModifier[]? modifiers) => GetMethod(name, genericParameterCount, bindingAttr, binder, CallingConventions.Any, types, modifiers);
- public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- if (genericParameterCount < 0)
- throw new ArgumentException(SR.ArgumentOutOfRange_NeedNonNegNum, nameof(genericParameterCount));
- if (types == null)
- throw new ArgumentNullException(nameof(types));
- for (int i = 0; i < types.Length; i++)
- {
- if (types[i] == null)
- throw new ArgumentNullException(nameof(types));
- }
- return GetMethodImpl(name, genericParameterCount, bindingAttr, binder, callConvention, types, modifiers);
- }
-
- protected virtual MethodInfo? GetMethodImpl(string name, int genericParameterCount, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[]? types, ParameterModifier[]? modifiers) => throw new NotSupportedException();
-
- public MethodInfo[] GetMethods() => GetMethods(Type.DefaultLookup);
- public abstract MethodInfo[] GetMethods(BindingFlags bindingAttr);
-
- public Type? GetNestedType(string name) => GetNestedType(name, Type.DefaultLookup);
- public abstract Type? GetNestedType(string name, BindingFlags bindingAttr);
-
- public Type[] GetNestedTypes() => GetNestedTypes(Type.DefaultLookup);
- public abstract Type[] GetNestedTypes(BindingFlags bindingAttr);
-
- public PropertyInfo? GetProperty(string name) => GetProperty(name, Type.DefaultLookup);
- public PropertyInfo? GetProperty(string name, BindingFlags bindingAttr)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- return GetPropertyImpl(name, bindingAttr, null, null, null, null);
- }
-
- public PropertyInfo? GetProperty(string name, Type? returnType)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- return GetPropertyImpl(name, Type.DefaultLookup, null, returnType, null, null);
- }
-
- public PropertyInfo? GetProperty(string name, Type[] types) => GetProperty(name, null, types);
- public PropertyInfo? GetProperty(string name, Type? returnType, Type[] types) => GetProperty(name, returnType, types, null);
- public PropertyInfo? GetProperty(string name, Type? returnType, Type[] types, ParameterModifier[]? modifiers) => GetProperty(name, Type.DefaultLookup, null, returnType, types, modifiers);
- public PropertyInfo? GetProperty(string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[] types, ParameterModifier[]? modifiers)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- if (types == null)
- throw new ArgumentNullException(nameof(types));
- return GetPropertyImpl(name, bindingAttr, binder, returnType, types, modifiers);
- }
-
- protected abstract PropertyInfo? GetPropertyImpl(string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers);
-
- public PropertyInfo[] GetProperties() => GetProperties(Type.DefaultLookup);
- public abstract PropertyInfo[] GetProperties(BindingFlags bindingAttr);
-
- public virtual MemberInfo[] GetDefaultMembers() => throw NotImplemented.ByDesign;
-
- public virtual RuntimeTypeHandle TypeHandle => throw new NotSupportedException();
- public static RuntimeTypeHandle GetTypeHandle(object o)
- {
- if (o == null)
- throw new ArgumentNullException(null, SR.Arg_InvalidHandle);
- Type type = o.GetType();
- return type.TypeHandle;
- }
-
- public static Type[] GetTypeArray(object[] args)
- {
- if (args == null)
- throw new ArgumentNullException(nameof(args));
-
- Type[] cls = new Type[args.Length];
- for (int i = 0; i < cls.Length; i++)
- {
- if (args[i] == null)
- throw new ArgumentNullException();
- cls[i] = args[i].GetType();
- }
- return cls;
- }
-
- public static TypeCode GetTypeCode(Type? type)
- {
- if (type == null)
- return TypeCode.Empty;
- return type.GetTypeCodeImpl();
- }
- protected virtual TypeCode GetTypeCodeImpl()
- {
- Type systemType = UnderlyingSystemType;
- if (this != systemType && systemType != null)
- return Type.GetTypeCode(systemType);
-
- return TypeCode.Object;
- }
-
- public abstract Guid GUID { get; }
-
- public static Type? GetTypeFromCLSID(Guid clsid) => GetTypeFromCLSID(clsid, null, throwOnError: false);
- public static Type? GetTypeFromCLSID(Guid clsid, bool throwOnError) => GetTypeFromCLSID(clsid, null, throwOnError: throwOnError);
- public static Type? GetTypeFromCLSID(Guid clsid, string? server) => GetTypeFromCLSID(clsid, server, throwOnError: false);
-
- public static Type? GetTypeFromProgID(string progID) => GetTypeFromProgID(progID, null, throwOnError: false);
- public static Type? GetTypeFromProgID(string progID, bool throwOnError) => GetTypeFromProgID(progID, null, throwOnError: throwOnError);
- public static Type? GetTypeFromProgID(string progID, string? server) => GetTypeFromProgID(progID, server, throwOnError: false);
-
- public abstract Type? BaseType { get; }
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args) => InvokeMember(name, invokeAttr, binder, target, args, null, null, null);
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, CultureInfo? culture) => InvokeMember(name, invokeAttr, binder, target, args, null, culture, null);
- public abstract object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters);
-
- public Type? GetInterface(string name) => GetInterface(name, ignoreCase: false);
- public abstract Type? GetInterface(string name, bool ignoreCase);
- public abstract Type[] GetInterfaces();
-
- public virtual InterfaceMapping GetInterfaceMap(Type interfaceType) => throw new NotSupportedException(SR.NotSupported_SubclassOverride);
-
- public virtual bool IsInstanceOfType(object? o) => o == null ? false : IsAssignableFrom(o.GetType());
- public virtual bool IsEquivalentTo(Type? other) => this == other;
-
- public virtual Type GetEnumUnderlyingType()
- {
- if (!IsEnum)
- throw new ArgumentException(SR.Arg_MustBeEnum, "enumType");
-
- FieldInfo[] fields = GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
- if (fields == null || fields.Length != 1)
- throw new ArgumentException(SR.Argument_InvalidEnum, "enumType");
-
- return fields[0].FieldType;
- }
- public virtual Array GetEnumValues()
- {
- if (!IsEnum)
- throw new ArgumentException(SR.Arg_MustBeEnum, "enumType");
-
- // We don't support GetEnumValues in the default implementation because we cannot create an array of
- // a non-runtime type. If there is strong need we can consider returning an object or int64 array.
- throw NotImplemented.ByDesign;
- }
-
- public virtual Type MakeArrayType() => throw new NotSupportedException();
- public virtual Type MakeArrayType(int rank) => throw new NotSupportedException();
- public virtual Type MakeByRefType() => throw new NotSupportedException();
- public virtual Type MakeGenericType(params Type[] typeArguments) => throw new NotSupportedException(SR.NotSupported_SubclassOverride);
- public virtual Type MakePointerType() => throw new NotSupportedException();
-
- public static Type MakeGenericSignatureType(Type genericTypeDefinition, params Type[] typeArguments) => new SignatureConstructedGenericType(genericTypeDefinition, typeArguments);
-
- public static Type MakeGenericMethodParameter(int position)
- {
- if (position < 0)
- throw new ArgumentException(SR.ArgumentOutOfRange_NeedNonNegNum, nameof(position));
- return new SignatureGenericMethodParameterType(position);
- }
-
- // This is used by the ToString() overrides of all reflection types. The legacy behavior has the following problems:
- // 1. Use only Name for nested types, which can be confused with global types and generic parameters of the same name.
- // 2. Use only Name for generic parameters, which can be confused with nested types and global types of the same name.
- // 3. Use only Name for all primitive types, void and TypedReference
- // 4. MethodBase.ToString() use "ByRef" for byref parameters which is different than Type.ToString().
- // 5. ConstructorInfo.ToString() outputs "Void" as the return type. Why Void?
- internal string FormatTypeName()
- {
- Type elementType = GetRootElementType();
-
- if (elementType.IsPrimitive ||
- elementType.IsNested ||
- elementType == typeof(void) ||
- elementType == typeof(TypedReference))
- return Name;
-
- return ToString();
- }
-
- public override string ToString() => "Type: " + Name; // Why do we add the "Type: " prefix?
-
- public override bool Equals(object? o) => o == null ? false : Equals(o as Type);
- public override int GetHashCode()
- {
- Type systemType = UnderlyingSystemType;
- if (!object.ReferenceEquals(systemType, this))
- return systemType.GetHashCode();
- return base.GetHashCode();
- }
- public virtual bool Equals(Type? o) => o == null ? false : object.ReferenceEquals(this.UnderlyingSystemType, o.UnderlyingSystemType);
-
- public static Type? ReflectionOnlyGetType(string typeName, bool throwIfNotFound, bool ignoreCase) => throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly);
-
- public static Binder DefaultBinder
- {
- get
- {
- if (s_defaultBinder == null)
- {
- DefaultBinder binder = new DefaultBinder();
- Interlocked.CompareExchange<Binder?>(ref s_defaultBinder, binder, null);
- }
- return s_defaultBinder!;
- }
- }
-
- private static volatile Binder? s_defaultBinder;
-
- public static readonly char Delimiter = '.';
- public static readonly Type[] EmptyTypes = Array.Empty<Type>();
- public static readonly object Missing = System.Reflection.Missing.Value;
-
- public static readonly MemberFilter FilterAttribute = FilterAttributeImpl!;
- public static readonly MemberFilter FilterName = (m, c) => FilterNameImpl(m, c!, StringComparison.Ordinal);
- public static readonly MemberFilter FilterNameIgnoreCase = (m, c) => FilterNameImpl(m, c!, StringComparison.OrdinalIgnoreCase);
-
- private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TypeAccessException.cs b/netcore/System.Private.CoreLib/shared/System/TypeAccessException.cs
deleted file mode 100644
index d804b408d6c..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TypeAccessException.cs
+++ /dev/null
@@ -1,37 +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 System.Runtime.Serialization;
-
-namespace System
-{
- // TypeAccessException derives from TypeLoadException rather than MemberAccessException because in
- // pre-v4 releases of the runtime TypeLoadException was used in lieu of a TypeAccessException.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class TypeAccessException : TypeLoadException
- {
- public TypeAccessException()
- : base(SR.Arg_TypeAccessException)
- {
- HResult = HResults.COR_E_TYPEACCESS;
- }
-
- public TypeAccessException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_TYPEACCESS;
- }
-
- public TypeAccessException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_TYPEACCESS;
- }
-
- protected TypeAccessException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TypeCode.cs b/netcore/System.Private.CoreLib/shared/System/TypeCode.cs
deleted file mode 100644
index 296198656b7..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TypeCode.cs
+++ /dev/null
@@ -1,47 +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.
-
-// The TypeCode enum represents the type code of an object. To obtain the
-// TypeCode for a given object, use the Value.GetTypeCode() method. The
-// TypeCode.Empty value represents a null object reference. The TypeCode.Object
-// value represents an object that doesn't implement the IConvertible interface. The
-// TypeCode.DBNull value represents the database null, which is distinct and
-// different from a null reference. The other type codes represent values that
-// use the given simple type encoding.
-//
-// Note that when an object has a given TypeCode, there is no guarantee that
-// the object is an instance of the corresponding System.XXX value class. For
-// example, an object with the type code TypeCode.Int32 might actually be an
-// instance of a nullable 32-bit integer type (with a value that isn't the
-// database null).
-//
-// There are no type codes for "Missing", "Error", "IDispatch", and "IUnknown".
-// These types of values are instead represented as classes. When the type code
-// of an object is TypeCode.Object, a further instance-of check can be used to
-// determine if the object is one of these values.
-
-namespace System
-{
- public enum TypeCode
- {
- Empty = 0, // Null reference
- Object = 1, // Instance that isn't a value
- DBNull = 2, // Database null value
- Boolean = 3, // Boolean
- Char = 4, // Unicode character
- SByte = 5, // Signed 8-bit integer
- Byte = 6, // Unsigned 8-bit integer
- Int16 = 7, // Signed 16-bit integer
- UInt16 = 8, // Unsigned 16-bit integer
- Int32 = 9, // Signed 32-bit integer
- UInt32 = 10, // Unsigned 32-bit integer
- Int64 = 11, // Signed 64-bit integer
- UInt64 = 12, // Unsigned 64-bit integer
- Single = 13, // IEEE 32-bit float
- Double = 14, // IEEE 64-bit double
- Decimal = 15, // Decimal
- DateTime = 16, // DateTime
- String = 18, // Unicode character string
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TypeInitializationException.cs b/netcore/System.Private.CoreLib/shared/System/TypeInitializationException.cs
deleted file mode 100644
index d061cb70678..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TypeInitializationException.cs
+++ /dev/null
@@ -1,69 +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.
-
-/*=============================================================================
-**
-**
-**
-** Purpose: The exception class to wrap exceptions thrown by
-** a type's class initializer (.cctor). This is sufficiently
-** distinct from a TypeLoadException, which means we couldn't
-** find the type.
-**
-**
-=============================================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class TypeInitializationException : SystemException
- {
- private readonly string? _typeName;
-
- // This exception is not creatable without specifying the
- // inner exception.
- private TypeInitializationException()
- : base(SR.TypeInitialization_Default)
- {
- HResult = HResults.COR_E_TYPEINITIALIZATION;
- }
-
-
- public TypeInitializationException(string? fullTypeName, Exception? innerException)
- : this(fullTypeName, SR.Format(SR.TypeInitialization_Type, fullTypeName), innerException)
- {
- }
-
- // This is called from within the runtime. I believe this is necessary
- // for Interop only, though it's not particularly useful.
- internal TypeInitializationException(string? message) : base(message)
- {
- HResult = HResults.COR_E_TYPEINITIALIZATION;
- }
-
- internal TypeInitializationException(string? fullTypeName, string? message, Exception? innerException)
- : base(message, innerException)
- {
- _typeName = fullTypeName;
- HResult = HResults.COR_E_TYPEINITIALIZATION;
- }
-
- private TypeInitializationException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- _typeName = info.GetString("TypeName");
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("TypeName", TypeName, typeof(string));
- }
-
- public string TypeName => _typeName ?? string.Empty;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TypeLoadException.cs b/netcore/System.Private.CoreLib/shared/System/TypeLoadException.cs
deleted file mode 100644
index d18c84aa964..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TypeLoadException.cs
+++ /dev/null
@@ -1,67 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public partial class TypeLoadException : SystemException, ISerializable
- {
- public TypeLoadException()
- : base(SR.Arg_TypeLoadException)
- {
- HResult = HResults.COR_E_TYPELOAD;
- }
-
- public TypeLoadException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_TYPELOAD;
- }
-
- public TypeLoadException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_TYPELOAD;
- }
-
- public override string Message
- {
- get
- {
- SetMessageField();
- return _message!;
- }
- }
-
- public string TypeName => _className ?? string.Empty;
-
- protected TypeLoadException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- _className = info.GetString("TypeLoadClassName");
- _assemblyName = info.GetString("TypeLoadAssemblyName");
- _messageArg = info.GetString("TypeLoadMessageArg");
- _resourceId = info.GetInt32("TypeLoadResourceID");
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("TypeLoadClassName", _className, typeof(string));
- info.AddValue("TypeLoadAssemblyName", _assemblyName, typeof(string));
- info.AddValue("TypeLoadMessageArg", _messageArg, typeof(string));
- info.AddValue("TypeLoadResourceID", _resourceId);
- }
-
- // If ClassName != null, GetMessage will construct on the fly using it
- // and ResourceId (mscorrc.dll). This allows customization of the
- // class name format depending on the language environment.
- private string? _className;
- private string? _assemblyName;
- private readonly string? _messageArg;
- private readonly int _resourceId;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/TypeUnloadedException.cs b/netcore/System.Private.CoreLib/shared/System/TypeUnloadedException.cs
deleted file mode 100644
index a1d8e4da8f6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/TypeUnloadedException.cs
+++ /dev/null
@@ -1,36 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class TypeUnloadedException : SystemException
- {
- public TypeUnloadedException()
- : base(SR.Arg_TypeUnloadedException)
- {
- HResult = HResults.COR_E_TYPEUNLOADED;
- }
-
- public TypeUnloadedException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_TYPEUNLOADED;
- }
-
- public TypeUnloadedException(string? message, Exception? innerException)
- : base(message, innerException)
- {
- HResult = HResults.COR_E_TYPEUNLOADED;
- }
-
- protected TypeUnloadedException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/UInt16.cs b/netcore/System.Private.CoreLib/shared/System/UInt16.cs
deleted file mode 100644
index c0b2900f8e6..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/UInt16.cs
+++ /dev/null
@@ -1,278 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- [Serializable]
- [CLSCompliant(false)]
- [StructLayout(LayoutKind.Sequential)]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct UInt16 : IComparable, IConvertible, IFormattable, IComparable<ushort>, IEquatable<ushort>, ISpanFormattable
- {
- private readonly ushort m_value; // Do not rename (binary serialization)
-
- public const ushort MaxValue = (ushort)0xFFFF;
- public const ushort MinValue = 0;
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type UInt16, this method throws an ArgumentException.
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
- if (value is ushort)
- {
- return (int)m_value - (int)(((ushort)value).m_value);
- }
- throw new ArgumentException(SR.Arg_MustBeUInt16);
- }
-
- public int CompareTo(ushort value)
- {
- return (int)m_value - (int)value;
- }
-
- public override bool Equals(object? obj)
- {
- if (!(obj is ushort))
- {
- return false;
- }
- return m_value == ((ushort)obj).m_value;
- }
-
- [NonVersionable]
- public bool Equals(ushort obj)
- {
- return m_value == obj;
- }
-
- // Returns a HashCode for the UInt16
- public override int GetHashCode()
- {
- return (int)m_value;
- }
-
- // Converts the current value to a String in base-10 with no extra padding.
- public override string ToString()
- {
- return Number.UInt32ToDecStr(m_value, -1);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return Number.FormatUInt32(m_value, null, provider);
- }
-
- public string ToString(string? format)
- {
- return Number.FormatUInt32(m_value, format, null);
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- return Number.FormatUInt32(m_value, format, provider);
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
- {
- return Number.TryFormatUInt32(m_value, format, provider, destination, out charsWritten);
- }
-
- [CLSCompliant(false)]
- public static ushort Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static ushort Parse(string s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, style, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static ushort Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static ushort Parse(string s, NumberStyles style, IFormatProvider? provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Parse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static ushort Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- private static ushort Parse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info)
- {
- Number.ParsingStatus status = Number.TryParseUInt32(s, style, info, out uint i);
- if (status != Number.ParsingStatus.OK)
- {
- Number.ThrowOverflowOrFormatException(status, TypeCode.UInt16);
- }
-
- if (i > MaxValue) Number.ThrowOverflowException(TypeCode.UInt16);
- return (ushort)i;
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(string? s, out ushort result)
- {
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<char> s, out ushort result)
- {
- return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out ushort result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
-
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return TryParse((ReadOnlySpan<char>)s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out ushort result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- private static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info, out ushort result)
- {
- if (Number.TryParseUInt32(s, style, info, out uint i) != Number.ParsingStatus.OK
- || i > MaxValue)
- {
- result = 0;
- return false;
- }
- result = (ushort)i;
- return true;
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.UInt16;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return m_value;
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt16", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/UInt32.cs b/netcore/System.Private.CoreLib/shared/System/UInt32.cs
deleted file mode 100644
index f4ef1c6ecf3..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/UInt32.cs
+++ /dev/null
@@ -1,264 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- [Serializable]
- [CLSCompliant(false)]
- [StructLayout(LayoutKind.Sequential)]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct UInt32 : IComparable, IConvertible, IFormattable, IComparable<uint>, IEquatable<uint>, ISpanFormattable
- {
- private readonly uint m_value; // Do not rename (binary serialization)
-
- public const uint MaxValue = (uint)0xffffffff;
- public const uint MinValue = 0U;
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type UInt32, this method throws an ArgumentException.
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
-
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- if (value is uint i)
- {
- if (m_value < i) return -1;
- if (m_value > i) return 1;
- return 0;
- }
-
- throw new ArgumentException(SR.Arg_MustBeUInt32);
- }
-
- public int CompareTo(uint value)
- {
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- if (m_value < value) return -1;
- if (m_value > value) return 1;
- return 0;
- }
-
- public override bool Equals(object? obj)
- {
- if (!(obj is uint))
- {
- return false;
- }
- return m_value == ((uint)obj).m_value;
- }
-
- [NonVersionable]
- public bool Equals(uint obj)
- {
- return m_value == obj;
- }
-
- // The absolute value of the int contained.
- public override int GetHashCode()
- {
- return (int)m_value;
- }
-
- // The base 10 representation of the number with no extra padding.
- public override string ToString()
- {
- return Number.UInt32ToDecStr(m_value, -1);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return Number.FormatUInt32(m_value, null, provider);
- }
-
- public string ToString(string? format)
- {
- return Number.FormatUInt32(m_value, format, null);
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- return Number.FormatUInt32(m_value, format, provider);
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
- {
- return Number.TryFormatUInt32(m_value, format, provider, destination, out charsWritten);
- }
-
- [CLSCompliant(false)]
- public static uint Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseUInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static uint Parse(string s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseUInt32(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static uint Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseUInt32(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static uint Parse(string s, NumberStyles style, IFormatProvider? provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseUInt32(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static uint Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseUInt32(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(string? s, out uint result)
- {
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return Number.TryParseUInt32IntegerStyle(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result) == Number.ParsingStatus.OK;
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<char> s, out uint result)
- {
- return Number.TryParseUInt32IntegerStyle(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result) == Number.ParsingStatus.OK;
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out uint result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
-
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return Number.TryParseUInt32(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK;
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out uint result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.TryParseUInt32(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK;
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.UInt32;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return m_value;
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt32", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/UInt64.cs b/netcore/System.Private.CoreLib/shared/System/UInt64.cs
deleted file mode 100644
index 927d807b387..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/UInt64.cs
+++ /dev/null
@@ -1,263 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
-
-namespace System
-{
- [Serializable]
- [CLSCompliant(false)]
- [StructLayout(LayoutKind.Sequential)]
- [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct UInt64 : IComparable, IConvertible, IFormattable, IComparable<ulong>, IEquatable<ulong>, ISpanFormattable
- {
- private readonly ulong m_value; // Do not rename (binary serialization)
-
- public const ulong MaxValue = (ulong)0xffffffffffffffffL;
- public const ulong MinValue = 0x0;
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type UInt64, this method throws an ArgumentException.
- //
- public int CompareTo(object? value)
- {
- if (value == null)
- {
- return 1;
- }
-
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- if (value is ulong i)
- {
- if (m_value < i) return -1;
- if (m_value > i) return 1;
- return 0;
- }
-
- throw new ArgumentException(SR.Arg_MustBeUInt64);
- }
-
- public int CompareTo(ulong value)
- {
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- if (m_value < value) return -1;
- if (m_value > value) return 1;
- return 0;
- }
-
- public override bool Equals(object? obj)
- {
- if (!(obj is ulong))
- {
- return false;
- }
- return m_value == ((ulong)obj).m_value;
- }
-
- [NonVersionable]
- public bool Equals(ulong obj)
- {
- return m_value == obj;
- }
-
- // The value of the lower 32 bits XORed with the uppper 32 bits.
- public override int GetHashCode()
- {
- return ((int)m_value) ^ (int)(m_value >> 32);
- }
-
- public override string ToString()
- {
- return Number.UInt64ToDecStr(m_value, -1);
- }
-
- public string ToString(IFormatProvider? provider)
- {
- return Number.FormatUInt64(m_value, null, provider);
- }
-
- public string ToString(string? format)
- {
- return Number.FormatUInt64(m_value, format, null);
- }
-
- public string ToString(string? format, IFormatProvider? provider)
- {
- return Number.FormatUInt64(m_value, format, provider);
- }
-
- public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
- {
- return Number.TryFormatUInt64(m_value, format, provider, destination, out charsWritten);
- }
-
- [CLSCompliant(false)]
- public static ulong Parse(string s)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseUInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static ulong Parse(string s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseUInt64(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static ulong Parse(string s, IFormatProvider? provider)
- {
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseUInt64(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static ulong Parse(string s, NumberStyles style, IFormatProvider? provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
- return Number.ParseUInt64(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static ulong Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseUInt64(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(string? s, out ulong result)
- {
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return Number.TryParseUInt64IntegerStyle(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result) == Number.ParsingStatus.OK;
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<char> s, out ulong result)
- {
- return Number.TryParseUInt64IntegerStyle(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result) == Number.ParsingStatus.OK;
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out ulong result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
-
- if (s == null)
- {
- result = 0;
- return false;
- }
-
- return Number.TryParseUInt64(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK;
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out ulong result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.TryParseUInt64(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK;
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.UInt64;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider? provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider? provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider? provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider? provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider? provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider? provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider? provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider? provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider? provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider? provider)
- {
- return m_value;
- }
-
- float IConvertible.ToSingle(IFormatProvider? provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider? provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- decimal IConvertible.ToDecimal(IFormatProvider? provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider? provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt64", "DateTime"));
- }
-
- object IConvertible.ToType(Type type, IFormatProvider? provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/UIntPtr.cs b/netcore/System.Private.CoreLib/shared/System/UIntPtr.cs
deleted file mode 100644
index 754fc5e412d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/UIntPtr.cs
+++ /dev/null
@@ -1,185 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-using System.Runtime.Versioning;
-
-#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- [Serializable]
- [CLSCompliant(false)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public readonly struct UIntPtr : IEquatable<UIntPtr>, ISerializable
- {
- private readonly unsafe void* _value; // Do not rename (binary serialization)
-
- [Intrinsic]
- public static readonly UIntPtr Zero;
-
- [Intrinsic]
- [NonVersionable]
- public unsafe UIntPtr(uint value)
- {
- _value = (void*)value;
- }
-
- [Intrinsic]
- [NonVersionable]
- public unsafe UIntPtr(ulong value)
- {
-#if BIT64
- _value = (void*)value;
-#else
- _value = (void*)checked((uint)value);
-#endif
- }
-
- [Intrinsic]
- [NonVersionable]
- public unsafe UIntPtr(void* value)
- {
- _value = value;
- }
-
- private unsafe UIntPtr(SerializationInfo info, StreamingContext context)
- {
- ulong l = info.GetUInt64("value");
-
- if (Size == 4 && l > uint.MaxValue)
- throw new ArgumentException(SR.Serialization_InvalidPtrValue);
-
- _value = (void*)l;
- }
-
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- throw new ArgumentNullException(nameof(info));
-
- info.AddValue("value", ToUInt64());
- }
-
- public override unsafe bool Equals(object? obj)
- {
- if (obj is UIntPtr)
- {
- return _value == ((UIntPtr)obj)._value;
- }
- return false;
- }
-
- unsafe bool IEquatable<UIntPtr>.Equals(UIntPtr other) =>
- _value == other._value;
-
- public override unsafe int GetHashCode()
- {
-#if BIT64
- ulong l = (ulong)_value;
- return unchecked((int)l) ^ (int)(l >> 32);
-#else
- return unchecked((int)_value);
-#endif
- }
-
- [Intrinsic]
- [NonVersionable]
- public unsafe uint ToUInt32()
- {
-#if BIT64
- return checked((uint)_value);
-#else
- return (uint)_value;
-#endif
- }
-
- [Intrinsic]
- [NonVersionable]
- public unsafe ulong ToUInt64() => (ulong)_value;
-
- [Intrinsic]
- [NonVersionable]
- public static explicit operator UIntPtr(uint value) =>
- new UIntPtr(value);
-
- [Intrinsic]
- [NonVersionable]
- public static explicit operator UIntPtr(ulong value) =>
- new UIntPtr(value);
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe explicit operator UIntPtr(void* value) =>
- new UIntPtr(value);
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe explicit operator void*(UIntPtr value) =>
- value._value;
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe explicit operator uint(UIntPtr value) =>
-#if BIT64
- checked((uint)value._value);
-#else
- (uint)value._value;
-#endif
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe explicit operator ulong(UIntPtr value) =>
- (ulong)value._value;
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe bool operator ==(UIntPtr value1, UIntPtr value2) =>
- value1._value == value2._value;
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe bool operator !=(UIntPtr value1, UIntPtr value2) =>
- value1._value != value2._value;
-
- [NonVersionable]
- public static UIntPtr Add(UIntPtr pointer, int offset) =>
- pointer + offset;
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe UIntPtr operator +(UIntPtr pointer, int offset) =>
- new UIntPtr((nuint)pointer._value + (nuint)offset);
-
- [NonVersionable]
- public static UIntPtr Subtract(UIntPtr pointer, int offset) =>
- pointer - offset;
-
- [Intrinsic]
- [NonVersionable]
- public static unsafe UIntPtr operator -(UIntPtr pointer, int offset) =>
- new UIntPtr((nuint)pointer._value - (nuint)offset);
-
- public static int Size
- {
- [Intrinsic]
- [NonVersionable]
- get => sizeof(nuint);
- }
-
- [Intrinsic]
- [NonVersionable]
- public unsafe void* ToPointer() => _value;
-
- public override unsafe string ToString() =>
- ((nuint)_value).ToString(CultureInfo.InvariantCulture);
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/UnauthorizedAccessException.cs b/netcore/System.Private.CoreLib/shared/System/UnauthorizedAccessException.cs
deleted file mode 100644
index 4942eb760c1..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/UnauthorizedAccessException.cs
+++ /dev/null
@@ -1,48 +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.
-
-/*============================================================
-**
-**
-**
-** Purpose: An exception for OS 'access denied' types of
-** errors, including IO and limited security types
-** of errors.
-**
-**
-===========================================================*/
-
-using System.Runtime.Serialization;
-
-namespace System
-{
- // The UnauthorizedAccessException is thrown when access errors
- // occur from IO or other OS methods.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class UnauthorizedAccessException : SystemException
- {
- public UnauthorizedAccessException()
- : base(SR.Arg_UnauthorizedAccessException)
- {
- HResult = HResults.COR_E_UNAUTHORIZEDACCESS;
- }
-
- public UnauthorizedAccessException(string? message)
- : base(message)
- {
- HResult = HResults.COR_E_UNAUTHORIZEDACCESS;
- }
-
- public UnauthorizedAccessException(string? message, Exception? inner)
- : base(message, inner)
- {
- HResult = HResults.COR_E_UNAUTHORIZEDACCESS;
- }
-
- protected UnauthorizedAccessException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/UnhandledExceptionEventArgs.cs b/netcore/System.Private.CoreLib/shared/System/UnhandledExceptionEventArgs.cs
deleted file mode 100644
index 0971cc1fd47..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/UnhandledExceptionEventArgs.cs
+++ /dev/null
@@ -1,22 +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.
-
-namespace System
-{
- public class UnhandledExceptionEventArgs : EventArgs
- {
- private readonly object _exception;
- private readonly bool _isTerminating;
-
- public UnhandledExceptionEventArgs(object exception, bool isTerminating)
- {
- _exception = exception;
- _isTerminating = isTerminating;
- }
-
- public object ExceptionObject => _exception;
-
- public bool IsTerminating => _isTerminating;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/UnhandledExceptionEventHandler.cs b/netcore/System.Private.CoreLib/shared/System/UnhandledExceptionEventHandler.cs
deleted file mode 100644
index 58f1eb5145d..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/UnhandledExceptionEventHandler.cs
+++ /dev/null
@@ -1,8 +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.
-
-namespace System
-{
- public delegate void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e);
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/UnitySerializationHolder.cs b/netcore/System.Private.CoreLib/shared/System/UnitySerializationHolder.cs
deleted file mode 100644
index ac90cf152ab..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/UnitySerializationHolder.cs
+++ /dev/null
@@ -1,64 +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 System.Runtime.Serialization;
-
-namespace System
-{
- /// <summary>
- /// Holds Null class for which we guarantee that there is only ever one instance of.
- /// This only exists for compatibility with .NET Framework.
- /// </summary>
- [Serializable]
- // Needs to be public to support binary serialization compatibility
- public sealed class UnitySerializationHolder : ISerializable, IObjectReference
- {
- internal const int NullUnity = 0x0002;
- private readonly int _unityType;
- private readonly string? _data;
-
- /// <summary>
- /// A helper method that returns the SerializationInfo that a class utilizing
- /// UnitySerializationHelper should return from a call to GetObjectData. It contains
- /// the unityType (defined above) and any optional data (used only for the reflection types).
- /// </summary>
- internal static void GetUnitySerializationInfo(SerializationInfo info, int unityType)
- {
- info.SetType(typeof(UnitySerializationHolder));
- info.AddValue("Data", null, typeof(string));
- info.AddValue("UnityType", unityType);
- info.AddValue("AssemblyName", string.Empty);
- }
-
-#pragma warning disable CA2229 // public for compat
- public UnitySerializationHolder(SerializationInfo info, StreamingContext context)
-#pragma warning restore CA2229
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- // We are ignoring any other serialization input as we are only concerned about DBNull.
- // We also store data and use it for erorr logging.
- _unityType = info.GetInt32("UnityType");
- _data = info.GetString("Data");
- }
-
- public void GetObjectData(SerializationInfo info, StreamingContext context) =>
- throw new NotSupportedException(SR.NotSupported_UnitySerHolder);
-
- public object GetRealObject(StreamingContext context)
- {
- // We are only support deserializing DBNull and throwing for everything else.
- if (_unityType != NullUnity)
- {
- throw new ArgumentException(SR.Format(SR.Argument_InvalidUnity, _data ?? "UnityType"));
- }
-
- // We are always returning the same DBNull instance.
- return DBNull.Value;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/ValueTuple.cs b/netcore/System.Private.CoreLib/shared/System/ValueTuple.cs
deleted file mode 100644
index 4e449e74e89..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/ValueTuple.cs
+++ /dev/null
@@ -1,2246 +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.
-
-#pragma warning disable SA1141 // explicitly not using tuple syntax in tuple implementation
-
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- /// <summary>
- /// Helper so we can call some tuple methods recursively without knowing the underlying types.
- /// </summary>
- internal interface IValueTupleInternal : ITuple
- {
- int GetHashCode(IEqualityComparer comparer);
- string ToStringEnd();
- }
-
- /// <summary>
- /// The ValueTuple types (from arity 0 to 8) comprise the runtime implementation that underlies tuples in C# and struct tuples in F#.
- /// Aside from created via language syntax, they are most easily created via the ValueTuple.Create factory methods.
- /// The System.ValueTuple types differ from the System.Tuple types in that:
- /// - they are structs rather than classes,
- /// - they are mutable rather than readonly, and
- /// - their members (such as Item1, Item2, etc) are fields rather than properties.
- /// </summary>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple
- : IEquatable<ValueTuple>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if <paramref name="obj"/> is a <see cref="ValueTuple"/>.</returns>
- public override bool Equals(object? obj)
- {
- return obj is ValueTuple;
- }
-
- /// <summary>Returns a value indicating whether this instance is equal to a specified value.</summary>
- /// <param name="other">An instance to compare to this instance.</param>
- /// <returns>true if <paramref name="other"/> has the same value as this instance; otherwise, false.</returns>
- public bool Equals(ValueTuple other)
- {
- return true;
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- return other is ValueTuple;
- }
-
- int IComparable.CompareTo(object? other)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- return 0;
- }
-
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple other)
- {
- return 0;
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- return 0;
- }
-
- /// <summary>Returns the hash code for this instance.</summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return 0;
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return 0;
- }
-
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return 0;
- }
-
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>()</c>.
- /// </remarks>
- public override string ToString()
- {
- return "()";
- }
-
- string IValueTupleInternal.ToStringEnd()
- {
- return ")";
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 0;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] => throw new IndexOutOfRangeException();
-
- /// <summary>Creates a new struct 0-tuple.</summary>
- /// <returns>A 0-tuple.</returns>
- public static ValueTuple Create() =>
- default;
-
- /// <summary>Creates a new struct 1-tuple, or singleton.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <returns>A 1-tuple (singleton) whose value is (item1).</returns>
- public static ValueTuple<T1> Create<T1>(T1 item1) =>
- new ValueTuple<T1>(item1);
-
- /// <summary>Creates a new struct 2-tuple, or pair.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <returns>A 2-tuple (pair) whose value is (item1, item2).</returns>
- public static ValueTuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2) =>
- new ValueTuple<T1, T2>(item1, item2);
-
- /// <summary>Creates a new struct 3-tuple, or triple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <returns>A 3-tuple (triple) whose value is (item1, item2, item3).</returns>
- public static ValueTuple<T1, T2, T3> Create<T1, T2, T3>(T1 item1, T2 item2, T3 item3) =>
- new ValueTuple<T1, T2, T3>(item1, item2, item3);
-
- /// <summary>Creates a new struct 4-tuple, or quadruple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <typeparam name="T4">The type of the fourth component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <param name="item4">The value of the fourth component of the tuple.</param>
- /// <returns>A 4-tuple (quadruple) whose value is (item1, item2, item3, item4).</returns>
- public static ValueTuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 item1, T2 item2, T3 item3, T4 item4) =>
- new ValueTuple<T1, T2, T3, T4>(item1, item2, item3, item4);
-
- /// <summary>Creates a new struct 5-tuple, or quintuple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <typeparam name="T4">The type of the fourth component of the tuple.</typeparam>
- /// <typeparam name="T5">The type of the fifth component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <param name="item4">The value of the fourth component of the tuple.</param>
- /// <param name="item5">The value of the fifth component of the tuple.</param>
- /// <returns>A 5-tuple (quintuple) whose value is (item1, item2, item3, item4, item5).</returns>
- public static ValueTuple<T1, T2, T3, T4, T5> Create<T1, T2, T3, T4, T5>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) =>
- new ValueTuple<T1, T2, T3, T4, T5>(item1, item2, item3, item4, item5);
-
- /// <summary>Creates a new struct 6-tuple, or sextuple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <typeparam name="T4">The type of the fourth component of the tuple.</typeparam>
- /// <typeparam name="T5">The type of the fifth component of the tuple.</typeparam>
- /// <typeparam name="T6">The type of the sixth component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <param name="item4">The value of the fourth component of the tuple.</param>
- /// <param name="item5">The value of the fifth component of the tuple.</param>
- /// <param name="item6">The value of the sixth component of the tuple.</param>
- /// <returns>A 6-tuple (sextuple) whose value is (item1, item2, item3, item4, item5, item6).</returns>
- public static ValueTuple<T1, T2, T3, T4, T5, T6> Create<T1, T2, T3, T4, T5, T6>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) =>
- new ValueTuple<T1, T2, T3, T4, T5, T6>(item1, item2, item3, item4, item5, item6);
-
- /// <summary>Creates a new struct 7-tuple, or septuple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <typeparam name="T4">The type of the fourth component of the tuple.</typeparam>
- /// <typeparam name="T5">The type of the fifth component of the tuple.</typeparam>
- /// <typeparam name="T6">The type of the sixth component of the tuple.</typeparam>
- /// <typeparam name="T7">The type of the seventh component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <param name="item4">The value of the fourth component of the tuple.</param>
- /// <param name="item5">The value of the fifth component of the tuple.</param>
- /// <param name="item6">The value of the sixth component of the tuple.</param>
- /// <param name="item7">The value of the seventh component of the tuple.</param>
- /// <returns>A 7-tuple (septuple) whose value is (item1, item2, item3, item4, item5, item6, item7).</returns>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7> Create<T1, T2, T3, T4, T5, T6, T7>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) =>
- new ValueTuple<T1, T2, T3, T4, T5, T6, T7>(item1, item2, item3, item4, item5, item6, item7);
-
- /// <summary>Creates a new struct 8-tuple, or octuple.</summary>
- /// <typeparam name="T1">The type of the first component of the tuple.</typeparam>
- /// <typeparam name="T2">The type of the second component of the tuple.</typeparam>
- /// <typeparam name="T3">The type of the third component of the tuple.</typeparam>
- /// <typeparam name="T4">The type of the fourth component of the tuple.</typeparam>
- /// <typeparam name="T5">The type of the fifth component of the tuple.</typeparam>
- /// <typeparam name="T6">The type of the sixth component of the tuple.</typeparam>
- /// <typeparam name="T7">The type of the seventh component of the tuple.</typeparam>
- /// <typeparam name="T8">The type of the eighth component of the tuple.</typeparam>
- /// <param name="item1">The value of the first component of the tuple.</param>
- /// <param name="item2">The value of the second component of the tuple.</param>
- /// <param name="item3">The value of the third component of the tuple.</param>
- /// <param name="item4">The value of the fourth component of the tuple.</param>
- /// <param name="item5">The value of the fifth component of the tuple.</param>
- /// <param name="item6">The value of the sixth component of the tuple.</param>
- /// <param name="item7">The value of the seventh component of the tuple.</param>
- /// <param name="item8">The value of the eighth component of the tuple.</param>
- /// <returns>An 8-tuple (octuple) whose value is (item1, item2, item3, item4, item5, item6, item7, item8).</returns>
- public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8>> Create<T1, T2, T3, T4, T5, T6, T7, T8>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8) =>
- new ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8>>(item1, item2, item3, item4, item5, item6, item7, ValueTuple.Create(item8));
- }
-
- /// <summary>Represents a 1-tuple, or singleton, as a value type.</summary>
- /// <typeparam name="T1">The type of the tuple's only component.</typeparam>
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1>
- : IEquatable<ValueTuple<T1>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1}"/> instance's first component.
- /// </summary>
- public T1 Item1;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- public ValueTuple(T1 item1)
- {
- Item1 = item1;
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object? obj)
- {
- return obj is ValueTuple<T1> && Equals((ValueTuple<T1>)obj);
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its field
- /// is equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1>)) return false;
-
- var objTuple = (ValueTuple<T1>)other;
-
- return comparer.Equals(Item1, objTuple.Item1);
- }
-
- int IComparable.CompareTo(object? other)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- var objTuple = (ValueTuple<T1>)other;
-
- return Comparer<T1>.Default.Compare(Item1, objTuple.Item1);
- }
-
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1> other)
- {
- return Comparer<T1>.Default.Compare(Item1, other.Item1);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- var objTuple = (ValueTuple<T1>)other;
-
- return comparer.Compare(Item1, objTuple.Item1);
- }
-
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return Item1?.GetHashCode() ?? 0;
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return comparer.GetHashCode(Item1!);
- }
-
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return comparer.GetHashCode(Item1!);
- }
-
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1)</c>,
- /// where <c>Item1</c> represents the value of <see cref="Item1"/>. If the field is <see langword="null"/>,
- /// it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ")";
- }
-
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ")";
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 1;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index]
- {
- get
- {
- if (index != 0)
- {
- throw new IndexOutOfRangeException();
- }
- return Item1;
- }
- }
- }
-
- /// <summary>
- /// Represents a 2-tuple, or pair, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2>
- : IEquatable<ValueTuple<T1, T2>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2}"/> instance's first component.
- /// </summary>
- public T1 Item1;
-
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2}"/> instance's second component.
- /// </summary>
- public T2 Item2;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- public ValueTuple(T1 item1, T2 item2)
- {
- Item1 = item1;
- Item2 = item2;
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- ///
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object? obj)
- {
- return obj is ValueTuple<T1, T2> && Equals((ValueTuple<T1, T2>)obj);
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2}"/> instance is equal to a specified <see cref="ValueTuple{T1, T2}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2);
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2}"/> instance is equal to a specified object based on a specified comparison method.
- /// </summary>
- /// <param name="other">The object to compare with this instance.</param>
- /// <param name="comparer">An object that defines the method to use to evaluate whether the two objects are equal.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- ///
- /// <remarks>
- /// This member is an explicit interface member implementation. It can be used only when the
- /// <see cref="ValueTuple{T1, T2}"/> instance is cast to an <see cref="IStructuralEquatable"/> interface.
- ///
- /// The <see cref="IEqualityComparer.Equals"/> implementation is called only if <c>other</c> is not <see langword="null"/>,
- /// and if it can be successfully cast (in C#) or converted (in Visual Basic) to a <see cref="ValueTuple{T1, T2}"/>
- /// whose components are of the same types as those of the current instance. The IStructuralEquatable.Equals(Object, IEqualityComparer) method
- /// first passes the <see cref="Item1"/> values of the <see cref="ValueTuple{T1, T2}"/> objects to be compared to the
- /// <see cref="IEqualityComparer.Equals"/> implementation. If this method call returns <see langword="true"/>, the method is
- /// called again and passed the <see cref="Item2"/> values of the two <see cref="ValueTuple{T1, T2}"/> instances.
- /// </remarks>
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2>)) return false;
-
- var objTuple = (ValueTuple<T1, T2>)other;
-
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2);
- }
-
- int IComparable.CompareTo(object? other)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- return CompareTo((ValueTuple<T1, T2>)other);
- }
-
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
-
- return Comparer<T2>.Default.Compare(Item2, other.Item2);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- var objTuple = (ValueTuple<T1, T2>)other;
-
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
-
- return comparer.Compare(Item2, objTuple.Item2);
- }
-
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return HashCode.Combine(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return HashCode.Combine(comparer.GetHashCode(Item1!),
- comparer.GetHashCode(Item2!));
- }
-
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2)</c>,
- /// where <c>Item1</c> and <c>Item2</c> represent the values of the <see cref="Item1"/>
- /// and <see cref="Item2"/> fields. If either field value is <see langword="null"/>,
- /// it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ")";
- }
-
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ")";
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 2;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- /// <summary>
- /// Represents a 3-tuple, or triple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3>
- : IEquatable<ValueTuple<T1, T2, T3>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3}"/> instance's third component.
- /// </summary>
- public T3 Item3;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3)
- {
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object? obj)
- {
- return obj is ValueTuple<T1, T2, T3> && Equals((ValueTuple<T1, T2, T3>)obj);
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3>)) return false;
-
- var objTuple = (ValueTuple<T1, T2, T3>)other;
-
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3);
- }
-
- int IComparable.CompareTo(object? other)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- return CompareTo((ValueTuple<T1, T2, T3>)other);
- }
-
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
-
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
-
- return Comparer<T3>.Default.Compare(Item3, other.Item3);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- var objTuple = (ValueTuple<T1, T2, T3>)other;
-
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
-
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
-
- return comparer.Compare(Item3, objTuple.Item3);
- }
-
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return HashCode.Combine(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return HashCode.Combine(comparer.GetHashCode(Item1!),
- comparer.GetHashCode(Item2!),
- comparer.GetHashCode(Item3!));
- }
-
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ")";
- }
-
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ")";
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 3;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- /// <summary>
- /// Represents a 4-tuple, or quadruple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3, T4>
- : IEquatable<ValueTuple<T1, T2, T3, T4>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3, T4>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance's third component.
- /// </summary>
- public T3 Item3;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance's fourth component.
- /// </summary>
- public T4 Item4;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3, T4}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- /// <param name="item4">The value of the tuple's fourth component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4)
- {
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- Item4 = item4;
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3, T4}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object? obj)
- {
- return obj is ValueTuple<T1, T2, T3, T4> && Equals((ValueTuple<T1, T2, T3, T4>)obj);
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3, T4}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3, T4> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3)
- && EqualityComparer<T4>.Default.Equals(Item4, other.Item4);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3, T4>)) return false;
-
- var objTuple = (ValueTuple<T1, T2, T3, T4>)other;
-
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3)
- && comparer.Equals(Item4, objTuple.Item4);
- }
-
- int IComparable.CompareTo(object? other)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3, T4>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- return CompareTo((ValueTuple<T1, T2, T3, T4>)other);
- }
-
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3, T4> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
-
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
-
- c = Comparer<T3>.Default.Compare(Item3, other.Item3);
- if (c != 0) return c;
-
- return Comparer<T4>.Default.Compare(Item4, other.Item4);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3, T4>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- var objTuple = (ValueTuple<T1, T2, T3, T4>)other;
-
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
-
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
-
- c = comparer.Compare(Item3, objTuple.Item3);
- if (c != 0) return c;
-
- return comparer.Compare(Item4, objTuple.Item4);
- }
-
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3, T4}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return HashCode.Combine(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return HashCode.Combine(comparer.GetHashCode(Item1!),
- comparer.GetHashCode(Item2!),
- comparer.GetHashCode(Item3!),
- comparer.GetHashCode(Item4!));
- }
-
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3, T4}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3, T4}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3, Item4)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ")";
- }
-
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ")";
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 4;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- /// <summary>
- /// Represents a 5-tuple, or quintuple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
- /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3, T4, T5>
- : IEquatable<ValueTuple<T1, T2, T3, T4, T5>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3, T4, T5>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance's third component.
- /// </summary>
- public T3 Item3;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance's fourth component.
- /// </summary>
- public T4 Item4;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance's fifth component.
- /// </summary>
- public T5 Item5;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- /// <param name="item4">The value of the tuple's fourth component.</param>
- /// <param name="item5">The value of the tuple's fifth component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)
- {
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- Item4 = item4;
- Item5 = item5;
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object? obj)
- {
- return obj is ValueTuple<T1, T2, T3, T4, T5> && Equals((ValueTuple<T1, T2, T3, T4, T5>)obj);
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3, T4, T5}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3, T4, T5> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3)
- && EqualityComparer<T4>.Default.Equals(Item4, other.Item4)
- && EqualityComparer<T5>.Default.Equals(Item5, other.Item5);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3, T4, T5>)) return false;
-
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5>)other;
-
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3)
- && comparer.Equals(Item4, objTuple.Item4)
- && comparer.Equals(Item5, objTuple.Item5);
- }
-
- int IComparable.CompareTo(object? other)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3, T4, T5>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- return CompareTo((ValueTuple<T1, T2, T3, T4, T5>)other);
- }
-
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3, T4, T5> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
-
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
-
- c = Comparer<T3>.Default.Compare(Item3, other.Item3);
- if (c != 0) return c;
-
- c = Comparer<T4>.Default.Compare(Item4, other.Item4);
- if (c != 0) return c;
-
- return Comparer<T5>.Default.Compare(Item5, other.Item5);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3, T4, T5>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5>)other;
-
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
-
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
-
- c = comparer.Compare(Item3, objTuple.Item3);
- if (c != 0) return c;
-
- c = comparer.Compare(Item4, objTuple.Item4);
- if (c != 0) return c;
-
- return comparer.Compare(Item5, objTuple.Item5);
- }
-
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return HashCode.Combine(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return HashCode.Combine(comparer.GetHashCode(Item1!),
- comparer.GetHashCode(Item2!),
- comparer.GetHashCode(Item3!),
- comparer.GetHashCode(Item4!),
- comparer.GetHashCode(Item5!));
- }
-
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3, T4, T5}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3, Item4, Item5)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ")";
- }
-
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ")";
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 5;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- /// <summary>
- /// Represents a 6-tuple, or sixtuple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
- /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
- /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3, T4, T5, T6>
- : IEquatable<ValueTuple<T1, T2, T3, T4, T5, T6>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3, T4, T5, T6>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's third component.
- /// </summary>
- public T3 Item3;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's fourth component.
- /// </summary>
- public T4 Item4;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's fifth component.
- /// </summary>
- public T5 Item5;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance's sixth component.
- /// </summary>
- public T6 Item6;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- /// <param name="item4">The value of the tuple's fourth component.</param>
- /// <param name="item5">The value of the tuple's fifth component.</param>
- /// <param name="item6">The value of the tuple's sixth component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)
- {
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- Item4 = item4;
- Item5 = item5;
- Item6 = item6;
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object? obj)
- {
- return obj is ValueTuple<T1, T2, T3, T4, T5, T6> && Equals((ValueTuple<T1, T2, T3, T4, T5, T6>)obj);
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3, T4, T5, T6> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3)
- && EqualityComparer<T4>.Default.Equals(Item4, other.Item4)
- && EqualityComparer<T5>.Default.Equals(Item5, other.Item5)
- && EqualityComparer<T6>.Default.Equals(Item6, other.Item6);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3, T4, T5, T6>)) return false;
-
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6>)other;
-
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3)
- && comparer.Equals(Item4, objTuple.Item4)
- && comparer.Equals(Item5, objTuple.Item5)
- && comparer.Equals(Item6, objTuple.Item6);
- }
-
- int IComparable.CompareTo(object? other)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- return CompareTo((ValueTuple<T1, T2, T3, T4, T5, T6>)other);
- }
-
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3, T4, T5, T6> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
-
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
-
- c = Comparer<T3>.Default.Compare(Item3, other.Item3);
- if (c != 0) return c;
-
- c = Comparer<T4>.Default.Compare(Item4, other.Item4);
- if (c != 0) return c;
-
- c = Comparer<T5>.Default.Compare(Item5, other.Item5);
- if (c != 0) return c;
-
- return Comparer<T6>.Default.Compare(Item6, other.Item6);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6>)other;
-
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
-
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
-
- c = comparer.Compare(Item3, objTuple.Item3);
- if (c != 0) return c;
-
- c = comparer.Compare(Item4, objTuple.Item4);
- if (c != 0) return c;
-
- c = comparer.Compare(Item5, objTuple.Item5);
- if (c != 0) return c;
-
- return comparer.Compare(Item6, objTuple.Item6);
- }
-
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return HashCode.Combine(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return HashCode.Combine(comparer.GetHashCode(Item1!),
- comparer.GetHashCode(Item2!),
- comparer.GetHashCode(Item3!),
- comparer.GetHashCode(Item4!),
- comparer.GetHashCode(Item5!),
- comparer.GetHashCode(Item6!));
- }
-
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3, Item4, Item5, Item6)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ")";
- }
-
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ")";
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 6;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- /// <summary>
- /// Represents a 7-tuple, or sentuple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
- /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
- /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
- /// <typeparam name="T7">The type of the tuple's seventh component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3, T4, T5, T6, T7>
- : IEquatable<ValueTuple<T1, T2, T3, T4, T5, T6, T7>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3, T4, T5, T6, T7>>, IValueTupleInternal, ITuple
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's third component.
- /// </summary>
- public T3 Item3;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's fourth component.
- /// </summary>
- public T4 Item4;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's fifth component.
- /// </summary>
- public T5 Item5;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's sixth component.
- /// </summary>
- public T6 Item6;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance's seventh component.
- /// </summary>
- public T7 Item7;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- /// <param name="item4">The value of the tuple's fourth component.</param>
- /// <param name="item5">The value of the tuple's fifth component.</param>
- /// <param name="item6">The value of the tuple's sixth component.</param>
- /// <param name="item7">The value of the tuple's seventh component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)
- {
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- Item4 = item4;
- Item5 = item5;
- Item6 = item6;
- Item7 = item7;
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object? obj)
- {
- return obj is ValueTuple<T1, T2, T3, T4, T5, T6, T7> && Equals((ValueTuple<T1, T2, T3, T4, T5, T6, T7>)obj);
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3, T4, T5, T6, T7> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3)
- && EqualityComparer<T4>.Default.Equals(Item4, other.Item4)
- && EqualityComparer<T5>.Default.Equals(Item5, other.Item5)
- && EqualityComparer<T6>.Default.Equals(Item6, other.Item6)
- && EqualityComparer<T7>.Default.Equals(Item7, other.Item7);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7>)) return false;
-
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6, T7>)other;
-
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3)
- && comparer.Equals(Item4, objTuple.Item4)
- && comparer.Equals(Item5, objTuple.Item5)
- && comparer.Equals(Item6, objTuple.Item6)
- && comparer.Equals(Item7, objTuple.Item7);
- }
-
- int IComparable.CompareTo(object? other)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- return CompareTo((ValueTuple<T1, T2, T3, T4, T5, T6, T7>)other);
- }
-
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3, T4, T5, T6, T7> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
-
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
-
- c = Comparer<T3>.Default.Compare(Item3, other.Item3);
- if (c != 0) return c;
-
- c = Comparer<T4>.Default.Compare(Item4, other.Item4);
- if (c != 0) return c;
-
- c = Comparer<T5>.Default.Compare(Item5, other.Item5);
- if (c != 0) return c;
-
- c = Comparer<T6>.Default.Compare(Item6, other.Item6);
- if (c != 0) return c;
-
- return Comparer<T7>.Default.Compare(Item7, other.Item7);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6, T7>)other;
-
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
-
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
-
- c = comparer.Compare(Item3, objTuple.Item3);
- if (c != 0) return c;
-
- c = comparer.Compare(Item4, objTuple.Item4);
- if (c != 0) return c;
-
- c = comparer.Compare(Item5, objTuple.Item5);
- if (c != 0) return c;
-
- c = comparer.Compare(Item6, objTuple.Item6);
- if (c != 0) return c;
-
- return comparer.Compare(Item7, objTuple.Item7);
- }
-
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- return HashCode.Combine(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0);
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- return HashCode.Combine(comparer.GetHashCode(Item1!),
- comparer.GetHashCode(Item2!),
- comparer.GetHashCode(Item3!),
- comparer.GetHashCode(Item4!),
- comparer.GetHashCode(Item5!),
- comparer.GetHashCode(Item6!),
- comparer.GetHashCode(Item7!));
- }
-
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3, Item4, Item5, Item6, Item7)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ")";
- }
-
- string IValueTupleInternal.ToStringEnd()
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ")";
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => 7;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index] =>
- index switch
- {
- 0 => Item1,
- 1 => Item2,
- 2 => Item3,
- 3 => Item4,
- 4 => Item5,
- 5 => Item6,
- 6 => Item7,
- _ => throw new IndexOutOfRangeException(),
- };
- }
-
- /// <summary>
- /// Represents an 8-tuple, or octuple, as a value type.
- /// </summary>
- /// <typeparam name="T1">The type of the tuple's first component.</typeparam>
- /// <typeparam name="T2">The type of the tuple's second component.</typeparam>
- /// <typeparam name="T3">The type of the tuple's third component.</typeparam>
- /// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
- /// <typeparam name="T5">The type of the tuple's fifth component.</typeparam>
- /// <typeparam name="T6">The type of the tuple's sixth component.</typeparam>
- /// <typeparam name="T7">The type of the tuple's seventh component.</typeparam>
- /// <typeparam name="TRest">The type of the tuple's eighth component.</typeparam>
- [Serializable]
- [StructLayout(LayoutKind.Auto)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>
- : IEquatable<ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>>, IStructuralEquatable, IStructuralComparable, IComparable, IComparable<ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>>, IValueTupleInternal, ITuple
- where TRest : struct
- {
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's first component.
- /// </summary>
- public T1 Item1;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's second component.
- /// </summary>
- public T2 Item2;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's third component.
- /// </summary>
- public T3 Item3;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's fourth component.
- /// </summary>
- public T4 Item4;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's fifth component.
- /// </summary>
- public T5 Item5;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's sixth component.
- /// </summary>
- public T6 Item6;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's seventh component.
- /// </summary>
- public T7 Item7;
- /// <summary>
- /// The current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance's eighth component.
- /// </summary>
- public TRest Rest;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> value type.
- /// </summary>
- /// <param name="item1">The value of the tuple's first component.</param>
- /// <param name="item2">The value of the tuple's second component.</param>
- /// <param name="item3">The value of the tuple's third component.</param>
- /// <param name="item4">The value of the tuple's fourth component.</param>
- /// <param name="item5">The value of the tuple's fifth component.</param>
- /// <param name="item6">The value of the tuple's sixth component.</param>
- /// <param name="item7">The value of the tuple's seventh component.</param>
- /// <param name="rest">The value of the tuple's eight component.</param>
- public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest)
- {
- if (!(rest is IValueTupleInternal))
- {
- throw new ArgumentException(SR.ArgumentException_ValueTupleLastArgumentNotAValueTuple);
- }
-
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- Item4 = item4;
- Item5 = item5;
- Item6 = item6;
- Item7 = item7;
- Rest = rest;
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance is equal to a specified object.
- /// </summary>
- /// <param name="obj">The object to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified object; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="obj"/> parameter is considered to be equal to the current instance under the following conditions:
- /// <list type="bullet">
- /// <item><description>It is a <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> value type.</description></item>
- /// <item><description>Its components are of the same types as those of the current instance.</description></item>
- /// <item><description>Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.</description></item>
- /// </list>
- /// </remarks>
- public override bool Equals(object? obj)
- {
- return obj is ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> && Equals((ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)obj);
- }
-
- /// <summary>
- /// Returns a value that indicates whether the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/>
- /// instance is equal to a specified <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/>.
- /// </summary>
- /// <param name="other">The tuple to compare with this instance.</param>
- /// <returns><see langword="true"/> if the current instance is equal to the specified tuple; otherwise, <see langword="false"/>.</returns>
- /// <remarks>
- /// The <paramref name="other"/> parameter is considered to be equal to the current instance if each of its fields
- /// are equal to that of the current instance, using the default comparer for that field's type.
- /// </remarks>
- public bool Equals(ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> other)
- {
- return EqualityComparer<T1>.Default.Equals(Item1, other.Item1)
- && EqualityComparer<T2>.Default.Equals(Item2, other.Item2)
- && EqualityComparer<T3>.Default.Equals(Item3, other.Item3)
- && EqualityComparer<T4>.Default.Equals(Item4, other.Item4)
- && EqualityComparer<T5>.Default.Equals(Item5, other.Item5)
- && EqualityComparer<T6>.Default.Equals(Item6, other.Item6)
- && EqualityComparer<T7>.Default.Equals(Item7, other.Item7)
- && EqualityComparer<TRest>.Default.Equals(Rest, other.Rest);
- }
-
- bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
- {
- if (other == null || !(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)) return false;
-
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other;
-
- return comparer.Equals(Item1, objTuple.Item1)
- && comparer.Equals(Item2, objTuple.Item2)
- && comparer.Equals(Item3, objTuple.Item3)
- && comparer.Equals(Item4, objTuple.Item4)
- && comparer.Equals(Item5, objTuple.Item5)
- && comparer.Equals(Item6, objTuple.Item6)
- && comparer.Equals(Item7, objTuple.Item7)
- && comparer.Equals(Rest, objTuple.Rest);
- }
-
- int IComparable.CompareTo(object? other)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- return CompareTo((ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other);
- }
-
- /// <summary>Compares this instance to a specified instance and returns an indication of their relative values.</summary>
- /// <param name="other">An instance to compare.</param>
- /// <returns>
- /// A signed number indicating the relative values of this instance and <paramref name="other"/>.
- /// Returns less than zero if this instance is less than <paramref name="other"/>, zero if this
- /// instance is equal to <paramref name="other"/>, and greater than zero if this instance is greater
- /// than <paramref name="other"/>.
- /// </returns>
- public int CompareTo(ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> other)
- {
- int c = Comparer<T1>.Default.Compare(Item1, other.Item1);
- if (c != 0) return c;
-
- c = Comparer<T2>.Default.Compare(Item2, other.Item2);
- if (c != 0) return c;
-
- c = Comparer<T3>.Default.Compare(Item3, other.Item3);
- if (c != 0) return c;
-
- c = Comparer<T4>.Default.Compare(Item4, other.Item4);
- if (c != 0) return c;
-
- c = Comparer<T5>.Default.Compare(Item5, other.Item5);
- if (c != 0) return c;
-
- c = Comparer<T6>.Default.Compare(Item6, other.Item6);
- if (c != 0) return c;
-
- c = Comparer<T7>.Default.Compare(Item7, other.Item7);
- if (c != 0) return c;
-
- return Comparer<TRest>.Default.Compare(Rest, other.Rest);
- }
-
- int IStructuralComparable.CompareTo(object? other, IComparer comparer)
- {
- if (other == null) return 1;
-
- if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>))
- {
- throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
- }
-
- var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other;
-
- int c = comparer.Compare(Item1, objTuple.Item1);
- if (c != 0) return c;
-
- c = comparer.Compare(Item2, objTuple.Item2);
- if (c != 0) return c;
-
- c = comparer.Compare(Item3, objTuple.Item3);
- if (c != 0) return c;
-
- c = comparer.Compare(Item4, objTuple.Item4);
- if (c != 0) return c;
-
- c = comparer.Compare(Item5, objTuple.Item5);
- if (c != 0) return c;
-
- c = comparer.Compare(Item6, objTuple.Item6);
- if (c != 0) return c;
-
- c = comparer.Compare(Item7, objTuple.Item7);
- if (c != 0) return c;
-
- return comparer.Compare(Rest, objTuple.Rest);
- }
-
- /// <summary>
- /// Returns the hash code for the current <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance.
- /// </summary>
- /// <returns>A 32-bit signed integer hash code.</returns>
- public override int GetHashCode()
- {
- // We want to have a limited hash in this case. We'll use the first 7 elements of the tuple
- if (!(Rest is IValueTupleInternal))
- {
- return HashCode.Combine(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0);
- }
-
- int size = ((IValueTupleInternal)Rest).Length;
- int restHashCode = Rest.GetHashCode();
- if (size >= 8)
- {
- return restHashCode;
- }
-
- // In this case, the rest member has less than 8 elements so we need to combine some of our elements with the elements in rest
- int k = 8 - size;
- switch (k)
- {
- case 1:
- return HashCode.Combine(Item7?.GetHashCode() ?? 0,
- restHashCode);
- case 2:
- return HashCode.Combine(Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- restHashCode);
- case 3:
- return HashCode.Combine(Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- restHashCode);
- case 4:
- return HashCode.Combine(Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- restHashCode);
- case 5:
- return HashCode.Combine(Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- restHashCode);
- case 6:
- return HashCode.Combine(Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- restHashCode);
- case 7:
- case 8:
- return HashCode.Combine(Item1?.GetHashCode() ?? 0,
- Item2?.GetHashCode() ?? 0,
- Item3?.GetHashCode() ?? 0,
- Item4?.GetHashCode() ?? 0,
- Item5?.GetHashCode() ?? 0,
- Item6?.GetHashCode() ?? 0,
- Item7?.GetHashCode() ?? 0,
- restHashCode);
- }
-
- Debug.Fail("Missed all cases for computing ValueTuple hash code");
- return -1;
- }
-
- int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- private int GetHashCodeCore(IEqualityComparer comparer)
- {
- // We want to have a limited hash in this case. We'll use the first 7 elements of the tuple
- if (!(Rest is IValueTupleInternal rest))
- {
- return HashCode.Combine(comparer.GetHashCode(Item1!), comparer.GetHashCode(Item2!), comparer.GetHashCode(Item3!),
- comparer.GetHashCode(Item4!), comparer.GetHashCode(Item5!), comparer.GetHashCode(Item6!),
- comparer.GetHashCode(Item7!));
- }
-
- int size = rest.Length;
- int restHashCode = rest.GetHashCode(comparer);
- if (size >= 8)
- {
- return restHashCode;
- }
-
- // In this case, the rest member has less than 8 elements so we need to combine some our elements with the elements in rest
- int k = 8 - size;
- switch (k)
- {
- case 1:
- return HashCode.Combine(comparer.GetHashCode(Item7!),
- restHashCode);
- case 2:
- return HashCode.Combine(comparer.GetHashCode(Item6!),
- comparer.GetHashCode(Item7!),
- restHashCode);
- case 3:
- return HashCode.Combine(comparer.GetHashCode(Item5!),
- comparer.GetHashCode(Item6!),
- comparer.GetHashCode(Item7!),
- restHashCode);
- case 4:
- return HashCode.Combine(comparer.GetHashCode(Item4!),
- comparer.GetHashCode(Item5!),
- comparer.GetHashCode(Item6!),
- comparer.GetHashCode(Item7!),
- restHashCode);
- case 5:
- return HashCode.Combine(comparer.GetHashCode(Item3!),
- comparer.GetHashCode(Item4!),
- comparer.GetHashCode(Item5!),
- comparer.GetHashCode(Item6!),
- comparer.GetHashCode(Item7!),
- restHashCode);
- case 6:
- return HashCode.Combine(comparer.GetHashCode(Item2!),
- comparer.GetHashCode(Item3!),
- comparer.GetHashCode(Item4!),
- comparer.GetHashCode(Item5!),
- comparer.GetHashCode(Item6!),
- comparer.GetHashCode(Item7!),
- restHashCode);
- case 7:
- case 8:
- return HashCode.Combine(comparer.GetHashCode(Item1!),
- comparer.GetHashCode(Item2!),
- comparer.GetHashCode(Item3!),
- comparer.GetHashCode(Item4!),
- comparer.GetHashCode(Item5!),
- comparer.GetHashCode(Item6!),
- comparer.GetHashCode(Item7!),
- restHashCode);
- }
-
- Debug.Fail("Missed all cases for computing ValueTuple hash code");
- return -1;
- }
-
- int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
- {
- return GetHashCodeCore(comparer);
- }
-
- /// <summary>
- /// Returns a string that represents the value of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance.
- /// </summary>
- /// <returns>The string representation of this <see cref="ValueTuple{T1, T2, T3, T4, T5, T6, T7, TRest}"/> instance.</returns>
- /// <remarks>
- /// The string returned by this method takes the form <c>(Item1, Item2, Item3, Item4, Item5, Item6, Item7, Rest)</c>.
- /// If any field value is <see langword="null"/>, it is represented as <see cref="string.Empty"/>.
- /// </remarks>
- public override string ToString()
- {
- if (Rest is IValueTupleInternal)
- {
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + ((IValueTupleInternal)Rest).ToStringEnd();
- }
-
- return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + Rest.ToString() + ")";
- }
-
- string IValueTupleInternal.ToStringEnd()
- {
- if (Rest is IValueTupleInternal)
- {
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + ((IValueTupleInternal)Rest).ToStringEnd();
- }
-
- return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + Rest.ToString() + ")";
- }
-
- /// <summary>
- /// The number of positions in this data structure.
- /// </summary>
- int ITuple.Length => Rest is IValueTupleInternal ? 7 + ((IValueTupleInternal)Rest).Length : 8;
-
- /// <summary>
- /// Get the element at position <param name="index"/>.
- /// </summary>
- object? ITuple.this[int index]
- {
- get
- {
- switch (index)
- {
- case 0:
- return Item1;
- case 1:
- return Item2;
- case 2:
- return Item3;
- case 3:
- return Item4;
- case 4:
- return Item5;
- case 5:
- return Item6;
- case 6:
- return Item7;
- }
-
- if (Rest is IValueTupleInternal)
- {
- return ((IValueTupleInternal)Rest)[index - 7];
- }
-
-
- if (index == 7)
- {
- return Rest;
- }
-
- throw new IndexOutOfRangeException();
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Version.cs b/netcore/System.Private.CoreLib/shared/System/Version.cs
deleted file mode 100644
index c02fc174f88..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Version.cs
+++ /dev/null
@@ -1,436 +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 System.Globalization;
-using System.Diagnostics;
-using System.Text;
-using System.Runtime.CompilerServices;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System
-{
- // A Version object contains four hierarchical numeric components: major, minor,
- // build and revision. Build and revision may be unspecified, which is represented
- // internally as a -1. By definition, an unspecified component matches anything
- // (both unspecified and specified), and an unspecified component is "less than" any
- // specified component.
-
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public sealed class Version : ICloneable, IComparable, IComparable<Version?>,
-#nullable disable // see comment on String
- IEquatable<Version>,
-#nullable restore
- ISpanFormattable
- {
- // AssemblyName depends on the order staying the same
- private readonly int _Major; // Do not rename (binary serialization)
- private readonly int _Minor; // Do not rename (binary serialization)
- private readonly int _Build = -1; // Do not rename (binary serialization)
- private readonly int _Revision = -1; // Do not rename (binary serialization)
-
- public Version(int major, int minor, int build, int revision)
- {
- if (major < 0)
- throw new ArgumentOutOfRangeException(nameof(major), SR.ArgumentOutOfRange_Version);
-
- if (minor < 0)
- throw new ArgumentOutOfRangeException(nameof(minor), SR.ArgumentOutOfRange_Version);
-
- if (build < 0)
- throw new ArgumentOutOfRangeException(nameof(build), SR.ArgumentOutOfRange_Version);
-
- if (revision < 0)
- throw new ArgumentOutOfRangeException(nameof(revision), SR.ArgumentOutOfRange_Version);
-
- _Major = major;
- _Minor = minor;
- _Build = build;
- _Revision = revision;
- }
-
- public Version(int major, int minor, int build)
- {
- if (major < 0)
- throw new ArgumentOutOfRangeException(nameof(major), SR.ArgumentOutOfRange_Version);
-
- if (minor < 0)
- throw new ArgumentOutOfRangeException(nameof(minor), SR.ArgumentOutOfRange_Version);
-
- if (build < 0)
- throw new ArgumentOutOfRangeException(nameof(build), SR.ArgumentOutOfRange_Version);
-
- _Major = major;
- _Minor = minor;
- _Build = build;
- }
-
- public Version(int major, int minor)
- {
- if (major < 0)
- throw new ArgumentOutOfRangeException(nameof(major), SR.ArgumentOutOfRange_Version);
-
- if (minor < 0)
- throw new ArgumentOutOfRangeException(nameof(minor), SR.ArgumentOutOfRange_Version);
-
- _Major = major;
- _Minor = minor;
- }
-
- public Version(string version)
- {
- Version v = Version.Parse(version);
- _Major = v.Major;
- _Minor = v.Minor;
- _Build = v.Build;
- _Revision = v.Revision;
- }
-
- public Version()
- {
- _Major = 0;
- _Minor = 0;
- }
-
- private Version(Version version)
- {
- Debug.Assert(version != null);
-
- _Major = version._Major;
- _Minor = version._Minor;
- _Build = version._Build;
- _Revision = version._Revision;
- }
-
- public object Clone()
- {
- return new Version(this);
- }
-
- // Properties for setting and getting version numbers
- public int Major => _Major;
-
- public int Minor => _Minor;
-
- public int Build => _Build;
-
- public int Revision => _Revision;
-
- public short MajorRevision => (short)(_Revision >> 16);
-
- public short MinorRevision => (short)(_Revision & 0xFFFF);
-
- public int CompareTo(object? version)
- {
- if (version == null)
- {
- return 1;
- }
-
- if (version is Version v)
- {
- return CompareTo(v);
- }
-
- throw new ArgumentException(SR.Arg_MustBeVersion);
- }
-
- public int CompareTo(Version? value)
- {
- return
- object.ReferenceEquals(value, this) ? 0 :
- value is null ? 1 :
- _Major != value._Major ? (_Major > value._Major ? 1 : -1) :
- _Minor != value._Minor ? (_Minor > value._Minor ? 1 : -1) :
- _Build != value._Build ? (_Build > value._Build ? 1 : -1) :
- _Revision != value._Revision ? (_Revision > value._Revision ? 1 : -1) :
- 0;
- }
-
- public override bool Equals(object? obj)
- {
- return Equals(obj as Version);
- }
-
- public bool Equals(Version? obj)
- {
- return object.ReferenceEquals(obj, this) ||
- (!(obj is null) &&
- _Major == obj._Major &&
- _Minor == obj._Minor &&
- _Build == obj._Build &&
- _Revision == obj._Revision);
- }
-
- public override int GetHashCode()
- {
- // Let's assume that most version numbers will be pretty small and just
- // OR some lower order bits together.
-
- int accumulator = 0;
-
- accumulator |= (_Major & 0x0000000F) << 28;
- accumulator |= (_Minor & 0x000000FF) << 20;
- accumulator |= (_Build & 0x000000FF) << 12;
- accumulator |= (_Revision & 0x00000FFF);
-
- return accumulator;
- }
-
- public override string ToString() =>
- ToString(DefaultFormatFieldCount);
-
- public string ToString(int fieldCount) =>
- fieldCount == 0 ? string.Empty :
- fieldCount == 1 ? _Major.ToString() :
- StringBuilderCache.GetStringAndRelease(ToCachedStringBuilder(fieldCount));
-
- public bool TryFormat(Span<char> destination, out int charsWritten) =>
- TryFormat(destination, DefaultFormatFieldCount, out charsWritten);
-
- public bool TryFormat(Span<char> destination, int fieldCount, out int charsWritten)
- {
- if (fieldCount == 0)
- {
- charsWritten = 0;
- return true;
- }
- else if (fieldCount == 1)
- {
- return _Major.TryFormat(destination, out charsWritten);
- }
-
- StringBuilder sb = ToCachedStringBuilder(fieldCount);
- if (sb.Length <= destination.Length)
- {
- sb.CopyTo(0, destination, sb.Length);
- StringBuilderCache.Release(sb);
- charsWritten = sb.Length;
- return true;
- }
-
- StringBuilderCache.Release(sb);
- charsWritten = 0;
- return false;
- }
-
- bool ISpanFormattable.TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
- {
- // format and provider are ignored.
- return TryFormat(destination, out charsWritten);
- }
-
- private int DefaultFormatFieldCount =>
- _Build == -1 ? 2 :
- _Revision == -1 ? 3 :
- 4;
-
- private StringBuilder ToCachedStringBuilder(int fieldCount)
- {
- // Note: As we always have positive numbers then it is safe to convert the number to string
- // regardless of the current culture as we'll not have any punctuation marks in the number.
-
- if (fieldCount == 2)
- {
- StringBuilder sb = StringBuilderCache.Acquire();
- sb.Append(_Major);
- sb.Append('.');
- sb.Append(_Minor);
- return sb;
- }
- else
- {
- if (_Build == -1)
- {
- throw new ArgumentException(SR.Format(SR.ArgumentOutOfRange_Bounds_Lower_Upper, "0", "2"), nameof(fieldCount));
- }
-
- if (fieldCount == 3)
- {
- StringBuilder sb = StringBuilderCache.Acquire();
- sb.Append(_Major);
- sb.Append('.');
- sb.Append(_Minor);
- sb.Append('.');
- sb.Append(_Build);
- return sb;
- }
-
- if (_Revision == -1)
- {
- throw new ArgumentException(SR.Format(SR.ArgumentOutOfRange_Bounds_Lower_Upper, "0", "3"), nameof(fieldCount));
- }
-
- if (fieldCount == 4)
- {
- StringBuilder sb = StringBuilderCache.Acquire();
- sb.Append(_Major);
- sb.Append('.');
- sb.Append(_Minor);
- sb.Append('.');
- sb.Append(_Build);
- sb.Append('.');
- sb.Append(_Revision);
- return sb;
- }
-
- throw new ArgumentException(SR.Format(SR.ArgumentOutOfRange_Bounds_Lower_Upper, "0", "4"), nameof(fieldCount));
- }
- }
-
- public static Version Parse(string input)
- {
- if (input == null)
- {
- throw new ArgumentNullException(nameof(input));
- }
-
- return ParseVersion(input.AsSpan(), throwOnFailure: true)!;
- }
-
- public static Version Parse(ReadOnlySpan<char> input) =>
- ParseVersion(input, throwOnFailure: true)!;
-
- public static bool TryParse(string? input, [NotNullWhen(true)] out Version? result)
- {
- if (input == null)
- {
- result = null;
- return false;
- }
-
- return (result = ParseVersion(input.AsSpan(), throwOnFailure: false)) != null;
- }
-
- public static bool TryParse(ReadOnlySpan<char> input, [NotNullWhen(true)] out Version? result) =>
- (result = ParseVersion(input, throwOnFailure: false)) != null;
-
- private static Version? ParseVersion(ReadOnlySpan<char> input, bool throwOnFailure)
- {
- // Find the separator between major and minor. It must exist.
- int majorEnd = input.IndexOf('.');
- if (majorEnd < 0)
- {
- if (throwOnFailure) throw new ArgumentException(SR.Arg_VersionString, nameof(input));
- return null;
- }
-
- // Find the ends of the optional minor and build portions.
- // We musn't have any separators after build.
- int buildEnd = -1;
- int minorEnd = input.Slice(majorEnd + 1).IndexOf('.');
- if (minorEnd != -1)
- {
- minorEnd += (majorEnd + 1);
- buildEnd = input.Slice(minorEnd + 1).IndexOf('.');
- if (buildEnd != -1)
- {
- buildEnd += (minorEnd + 1);
- if (input.Slice(buildEnd + 1).Contains('.'))
- {
- if (throwOnFailure) throw new ArgumentException(SR.Arg_VersionString, nameof(input));
- return null;
- }
- }
- }
-
- int minor, build, revision;
-
- // Parse the major version
- if (!TryParseComponent(input.Slice(0, majorEnd), nameof(input), throwOnFailure, out int major))
- {
- return null;
- }
-
- if (minorEnd != -1)
- {
- // If there's more than a major and minor, parse the minor, too.
- if (!TryParseComponent(input.Slice(majorEnd + 1, minorEnd - majorEnd - 1), nameof(input), throwOnFailure, out minor))
- {
- return null;
- }
-
- if (buildEnd != -1)
- {
- // major.minor.build.revision
- return
- TryParseComponent(input.Slice(minorEnd + 1, buildEnd - minorEnd - 1), nameof(build), throwOnFailure, out build) &&
- TryParseComponent(input.Slice(buildEnd + 1), nameof(revision), throwOnFailure, out revision) ?
- new Version(major, minor, build, revision) :
- null;
- }
- else
- {
- // major.minor.build
- return TryParseComponent(input.Slice(minorEnd + 1), nameof(build), throwOnFailure, out build) ?
- new Version(major, minor, build) :
- null;
- }
- }
- else
- {
- // major.minor
- return TryParseComponent(input.Slice(majorEnd + 1), nameof(input), throwOnFailure, out minor) ?
- new Version(major, minor) :
- null;
- }
- }
-
- private static bool TryParseComponent(ReadOnlySpan<char> component, string componentName, bool throwOnFailure, out int parsedComponent)
- {
- if (throwOnFailure)
- {
- if ((parsedComponent = int.Parse(component, NumberStyles.Integer, CultureInfo.InvariantCulture)) < 0)
- {
- throw new ArgumentOutOfRangeException(componentName, SR.ArgumentOutOfRange_Version);
- }
- return true;
- }
-
- return int.TryParse(component, NumberStyles.Integer, CultureInfo.InvariantCulture, out parsedComponent) && parsedComponent >= 0;
- }
-
- // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Version? v1, Version? v2)
- {
- // Test "right" first to allow branch elimination when inlined for null checks (== null)
- // so it can become a simple test
- if (v2 is null)
- {
- // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
- return (v1 is null) ? true : false;
- }
-
- // Quick reference equality test prior to calling the virtual Equality
- return ReferenceEquals(v2, v1) ? true : v2.Equals(v1);
- }
-
- public static bool operator !=(Version? v1, Version? v2) => !(v1 == v2);
-
- public static bool operator <(Version? v1, Version? v2)
- {
- if (v1 is null)
- {
- return !(v2 is null);
- }
-
- return v1.CompareTo(v2) < 0;
- }
-
- public static bool operator <=(Version? v1, Version? v2)
- {
- if (v1 is null)
- {
- return true;
- }
-
- return v1.CompareTo(v2) <= 0;
- }
-
- public static bool operator >(Version? v1, Version? v2) => v2 < v1;
-
- public static bool operator >=(Version? v1, Version? v2) => v2 <= v1;
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/Void.cs b/netcore/System.Private.CoreLib/shared/System/Void.cs
deleted file mode 100644
index 5162e6ad02a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/Void.cs
+++ /dev/null
@@ -1,16 +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.
-
-////////////////////////////////////////////////////////////////////////////////
-// Void
-// This class represents the void return type
-////////////////////////////////////////////////////////////////////////////////
-
-namespace System
-{
- // This class represents the void return type
- public struct Void
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/WeakReference.T.cs b/netcore/System.Private.CoreLib/shared/System/WeakReference.T.cs
deleted file mode 100644
index 864ad5b7916..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/WeakReference.T.cs
+++ /dev/null
@@ -1,74 +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 System.Runtime.Serialization;
-using System.Runtime.CompilerServices;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- // This class is sealed to mitigate security issues caused by Object::MemberwiseClone.
- public sealed partial class WeakReference<T> : ISerializable
- where T : class?
- {
- // If you fix bugs here, please fix them in WeakReference at the same time.
-
- // Creates a new WeakReference that keeps track of target.
- // Assumes a Short Weak Reference (ie TrackResurrection is false.)
- //
- public WeakReference(T target)
- : this(target, false)
- {
- }
-
- // Creates a new WeakReference that keeps track of target.
- //
- public WeakReference(T target, bool trackResurrection)
- {
- Create(target, trackResurrection);
- }
-
- private WeakReference(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- T target = (T)info.GetValue("TrackedObject", typeof(T))!; // Do not rename (binary serialization)
- bool trackResurrection = info.GetBoolean("TrackResurrection"); // Do not rename (binary serialization)
-
- Create(target, trackResurrection);
- }
-
- //
- // We are exposing TryGetTarget instead of a simple getter to avoid a common problem where people write incorrect code like:
- //
- // WeakReference ref = ...;
- // if (ref.Target != null)
- // DoSomething(ref.Target)
- //
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool TryGetTarget([MaybeNullWhen(false), NotNullWhen(true)] out T target)
- {
- // Call the worker method that has more performant but less user friendly signature.
- T o = this.Target;
- target = o;
- return o != null;
- }
-
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- info.AddValue("TrackedObject", this.Target, typeof(T)); // Do not rename (binary serialization)
- info.AddValue("TrackResurrection", IsTrackResurrection()); // Do not rename (binary serialization)
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/WeakReference.cs b/netcore/System.Private.CoreLib/shared/System/WeakReference.cs
deleted file mode 100644
index bb436e69eea..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/WeakReference.cs
+++ /dev/null
@@ -1,51 +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 System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public partial class WeakReference : ISerializable
- {
- // If you fix bugs here, please fix them in WeakReference<T> at the same time.
-
- // Creates a new WeakReference that keeps track of target.
- // Assumes a Short Weak Reference (ie TrackResurrection is false.)
- //
- public WeakReference(object? target)
- : this(target, false)
- {
- }
-
- public WeakReference(object? target, bool trackResurrection)
- {
- Create(target, trackResurrection);
- }
-
- protected WeakReference(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
-
- object? target = info.GetValue("TrackedObject", typeof(object)); // Do not rename (binary serialization)
- bool trackResurrection = info.GetBoolean("TrackResurrection"); // Do not rename (binary serialization)
-
- Create(target, trackResurrection);
- }
-
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
- info.AddValue("TrackedObject", Target, typeof(object)); // Do not rename (binary serialization)
- info.AddValue("TrackResurrection", IsTrackResurrection()); // Do not rename (binary serialization)
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/shared/System/WinRTFolderPaths.cs b/netcore/System.Private.CoreLib/shared/System/WinRTFolderPaths.cs
deleted file mode 100644
index f773ebd7b6a..00000000000
--- a/netcore/System.Private.CoreLib/shared/System/WinRTFolderPaths.cs
+++ /dev/null
@@ -1,104 +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 Windows.Foundation.Metadata;
-using Windows.Storage;
-using System.IO;
-using static System.Environment;
-
-namespace System
-{
- internal static class WinRTFolderPaths
- {
- public static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
- {
- // For testing we'll fall back if the needed APIs aren't present.
- //
- // We're not honoring the special folder options (noverify/create) for a few reasons. One, most of the
- // folders always exist (e.g. it is moot). Two, most locations are inaccessible from an appcontainer
- // currently - making it impossible to answer the question of existence or create if necessary. Thirdly,
- // the Win32 API would create these folders with very specific ACLs, which even in the cases we can create
- // are a significant compat risk (trying to replicate internal Windows behavior- it is documented that they
- // set specific ACLs, but not which ones).
- if (ApiInformation.IsTypePresent("Windows.Storage.UserDataPaths"))
- {
- return GetFolderPathCoreCurrent(folder);
- }
- else
- {
- return GetFolderPathCoreFallBack(folder);
- }
- }
-
- private static string GetFolderPathCoreCurrent(SpecialFolder folder) =>
- // While all of these give back real paths, most of them are not accessible
- // from an appcontainer currently (they will give access denied)
- folder switch
- {
- SpecialFolder.ApplicationData => UserDataPaths.GetDefault().RoamingAppData,
- SpecialFolder.CommonApplicationData => AppDataPaths.GetDefault().ProgramData,
- SpecialFolder.LocalApplicationData => AppDataPaths.GetDefault().LocalAppData,
- SpecialFolder.Cookies => AppDataPaths.GetDefault().Cookies,
- SpecialFolder.Desktop => AppDataPaths.GetDefault().Desktop,
- SpecialFolder.Favorites => AppDataPaths.GetDefault().Favorites,
- SpecialFolder.History => AppDataPaths.GetDefault().History,
- SpecialFolder.InternetCache => AppDataPaths.GetDefault().InternetCache,
- SpecialFolder.MyMusic => UserDataPaths.GetDefault().Music,
- SpecialFolder.MyPictures => UserDataPaths.GetDefault().Pictures,
- SpecialFolder.MyVideos => UserDataPaths.GetDefault().Videos,
- SpecialFolder.Recent => UserDataPaths.GetDefault().Recent,
- SpecialFolder.System => SystemDataPaths.GetDefault().System,
- SpecialFolder.Templates => UserDataPaths.GetDefault().Templates,
- SpecialFolder.DesktopDirectory => UserDataPaths.GetDefault().Desktop,
- SpecialFolder.Personal => UserDataPaths.GetDefault().Documents,
- SpecialFolder.CommonDocuments => SystemDataPaths.GetDefault().PublicDocuments,
- SpecialFolder.CommonMusic => SystemDataPaths.GetDefault().PublicMusic,
- SpecialFolder.CommonPictures => SystemDataPaths.GetDefault().PublicPictures,
- SpecialFolder.CommonDesktopDirectory => SystemDataPaths.GetDefault().PublicDesktop,
- SpecialFolder.CommonVideos => SystemDataPaths.GetDefault().PublicVideos,
- SpecialFolder.UserProfile => UserDataPaths.GetDefault().Profile,
- SpecialFolder.SystemX86 => SystemDataPaths.GetDefault().SystemX86,
- SpecialFolder.Windows => SystemDataPaths.GetDefault().Windows,
-
- // The following aren't available on WinRT. Our default behavior
- // is string.Empty for paths that aren't available:
- // SpecialFolder.Programs
- // SpecialFolder.MyComputer
- // SpecialFolder.SendTo
- // SpecialFolder.StartMenu
- // SpecialFolder.Startup
- // SpecialFolder.ProgramFiles
- // SpecialFolder.CommonProgramFiles
- // SpecialFolder.AdminTools
- // SpecialFolder.CDBurning
- // SpecialFolder.CommonAdminTools
- // SpecialFolder.CommonOemLinks
- // SpecialFolder.CommonStartMenu
- // SpecialFolder.CommonPrograms
- // SpecialFolder.CommonStartup
- // SpecialFolder.CommonTemplates
- // SpecialFolder.Fonts
- // SpecialFolder.NetworkShortcuts
- // SpecialFolder.PrinterShortcuts
- // SpecialFolder.CommonProgramFilesX86
- // SpecialFolder.ProgramFilesX86
- // SpecialFolder.Resources
- // SpecialFolder.LocalizedResources
-
- _ => string.Empty,
- };
-
- private static string GetFolderPathCoreFallBack(SpecialFolder folder) =>
- // For testing without the new WinRT APIs. We cannot use Win32 APIs for
- // special folders as they are not in the WACK.
- folder switch
- {
- SpecialFolder.ApplicationData => ApplicationData.Current.RoamingFolder?.Path ?? string.Empty,
- SpecialFolder.LocalApplicationData => ApplicationData.Current.LocalFolder?.Path ?? string.Empty,
- SpecialFolder.System => SystemDirectory,
- SpecialFolder.Windows => Path.GetDirectoryName(SystemDirectory)!,
- _ => string.Empty,
- };
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/LinkerDescriptor/System.Private.CoreLib.xml b/netcore/System.Private.CoreLib/src/LinkerDescriptor/System.Private.CoreLib.xml
deleted file mode 100644
index a91ced25a85..00000000000
--- a/netcore/System.Private.CoreLib/src/LinkerDescriptor/System.Private.CoreLib.xml
+++ /dev/null
@@ -1,735 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<linker>
- <assembly fullname="System.Private.CoreLib">
-
- <!-- domain.c: mono_defaults.appdomain_class -->
- <type fullname="Mono.MonoDomain">
- <field name="_mono_app_domain"/>
- <field name="UnhandledException"/>
- </type>
-
- <!-- appdomain.c: mono_runtime_init -->
- <type fullname="Mono.MonoDomainSetup" preserve="fields" >
- <!-- appdomain.c mono_object_new_checked in mono_domain_create_appdomain_checked -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- assembly-load-context.c: -->
- <type fullname="System.Runtime.Loader.AssemblyLoadContext">
- <!-- assembly-load-context.c: mono_alc_invoke_resolve_using_load -->
- <method name="MonoResolveUsingLoad" />
- <!-- assembly-load-context.c: mono_alc_invoke_resolve_using_resolving_event -->
- <method name="MonoResolveUsingResolvingEvent" />
- <!-- assembly-load-context.c: mono_alc_invoke_resolve_using_resolve_satellite -->
- <method name="MonoResolveUsingResolveSatelliteAssembly" />
- <!-- appdomain.c: mono_try_assembly_resolve_handle () -->
- <method name="OnAssemblyResolve"/>
- <!-- appdomain.c: mono_domain_fire_assembly_load_event () -->
- <method name="OnAssemblyLoad"/>
- <!-- native-library.c: netcore_resolve_with_load () -->
- <method name="MonoResolveUnmanagedDll"/>
- <!-- native-library.c: netcore_resolve_with_resolving_event () -->
- <method name="MonoResolveUnmanagedDllUsingEvent"/>
- <!-- appdomain.c: mono_domain_fire_assembly_load_event -->
- <method name="OnAssemblyLoad"/>
- </type>
-
- <!-- marshal.c: emit_marshal_custom (should not be used on devices)
- <type fullname="System.ApplicationException" />
- -->
-
- <!-- exception.c (mono_get_exception_argument) -->
- <type fullname="System.ArgumentException">
- <!-- mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- <!-- create_exception_two_strings -->
- <method signature="System.Void .ctor(System.String, System.String)" />
- </type>
-
- <!-- exception.c (mono_get_exception_argument_null) -->
- <type fullname="System.ArgumentNullException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- <!-- create_exception_two_strings -->
- <method signature="System.Void .ctor(System.String, System.String)" />
- </type>
-
- <!-- exception.c (mono_get_exception_argument_out_of_range) -->
- <type fullname="System.ArgumentOutOfRangeException">
- <!-- mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- <!-- create_exception_two_strings -->
- <method signature="System.Void .ctor(System.String, System.String)" />
- </type>
-
- <!-- exception.c (mono_get_exception_arithmetic) -->
- <type fullname="System.ArithmeticException">
- <!-- mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <type fullname="System.Security.VerificationException" >
- <!-- mini.c:mini_method_verify -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- domain.c: mono_defaults.array_class -->
- <type fullname="System.Array">
- <!-- InternalArray__%s_%s is used in aot-compiler.c -->
- <method name="InternalArray__ICollection_get_Count" />
- <method name="InternalArray__ICollection_get_IsReadOnly" />
- <method name="InternalArray__IEnumerable_GetEnumerator" />
- <method name="InternalArray__ICollection_Clear" />
- <method name="InternalArray__ICollection_Add" />
- <method name="InternalArray__ICollection_Remove" />
- <method name="InternalArray__ICollection_Contains" />
- <method name="InternalArray__ICollection_CopyTo" />
- <method name="InternalArray__Insert" />
- <method name="InternalArray__RemoveAt" />
- <method name="InternalArray__IndexOf" />
- <method name="InternalArray__get_Item" />
- <method name="InternalArray__set_Item" />
- <method name="InternalArray__IReadOnlyList_get_Item" />
- <method name="InternalArray__IReadOnlyCollection_get_Count" />
- </type>
-
- <!-- mono/metadata/exception.c mono/metadata/marshal.c ... -->
- <!-- exception.c (mono_get_exception_array_type_mismatch) -->
- <type fullname="System.ArrayTypeMismatchException">
- <!-- mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- domain.c: mono_defaults.attribute_class -->
- <!-- used in reflection.c to create array of attributes (no need to preserve everything beside the type itself) -->
- <type fullname="System.Attribute" preserve="nothing" />
-
- <!-- exception.c / mono-error.c -->
- <type fullname="System.BadImageFormatException">
- <!-- mono_get_exception_bad_image_format / mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- <!-- mono_get_exception_bad_image_format2 / mono_exception_from_name_two_strings -->
- <method signature="System.Void .ctor(System.String,System.String)" />
- </type>
-
- <!-- domain.c: mono_defaults.boolean_class -->
- <type fullname="System.Boolean">
- <field name="m_value"/>
- </type>
-
- <!-- domain.c: mono_defaults.byte_class -->
- <type fullname="System.Byte">
- <field name="m_value"/>
- </type>
-
- <!-- domain.c: mono_defaults.char_class -->
- <type fullname="System.Char">
- <field name="m_value"/>
- </type>
-
- <!-- marshal.c: emit_marshal_vtype -->
- <type fullname="System.DateTime" preserve="fields" />
-
- <!-- reflection.c: mono_get_dbnull_object / comment: Used as the value for ParameterInfo.DefaultValue -->
- <type fullname="System.DBNull">
- <field name="Value" />
- </type>
-
- <!-- domain.c: mono_defaults.delegate_class -->
- <type fullname="System.Delegate" preserve="fields" />
-
- <!-- domain.c: mono_defaults.stack_frame_class -->
- <!-- used in mini-exceptions.c to create array and MonoStackFrame instance, i.e. only fields are required to be preserved -->
- <type fullname="System.Diagnostics.StackFrame" preserve="fields" >
- <!-- threads.c mono_object_new_checked in mono_threads_get_thread_dump -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- debugger-agent.c: create_event_list -->
- <type fullname="System.Diagnostics.DebuggerNonUserCodeAttribute"/>
- <type fullname="System.Diagnostics.DebuggerHiddenAttribute"/>
- <type fullname="System.Diagnostics.DebuggerStepThroughAttribute"/>
-
- <!-- exception.c (mono_get_exception_divide_by_zero) -->
- <type fullname="System.DivideByZeroException">
- <!-- mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- loader.c: returned (as a string) from mono_lookup_pinvoke_call and used in
- icall.c: prelink_method / mono_exception_from_name_msg
- marshal.c: mono_delegate_to_ftnptr and mono_marshal_get_native_wrapper
- -->
- <type fullname="System.DllNotFoundException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- domain.c: mono_defaults.double_class -->
- <type fullname="System.Double">
- <field name="m_value"/>
- </type>
-
- <!-- domain.c: mono_defaults.enum_class -->
- <type fullname="System.Enum" preserve="fields" />
-
- <!-- loader.c: returned (as a string) from mono_lookup_pinvoke_call and used in … -->
- <type fullname="System.EntryPointNotFoundException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <type fullname="System.Environment">
- <!-- appdomain.c: mono_get_corlib_version -->
- <field name="mono_corlib_version" />
- <method name="get_StackTrace" />
- </type>
-
- <!-- domain.c: mono_defaults.exception_class and fields are defined in object-internals.h -->
- <type fullname="System.Exception" preserve="fields">
- <!-- used in mini-exceptions.c (if trace is enabled) -->
- <method name="get_Message" />
- </type>
-
- <!-- exception.c (mono_get_exception_execution_engine) -->
- <type fullname="System.ExecutionEngineException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <type fullname="System.FieldAccessException">
- <!-- exception.c: mono_get_exception_field_access / mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- <!-- exception.c: mono_get_exception_field_access_msg / mono_exception_from_name_msg -->
- <!-- mini.c (mono_jit_compiler_method_inner) mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <type fullname="System.FormatException">
- <!-- icall.c (base64_to_byte_array) mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- exception.c: mono_get_exception_index_out_of_range - used by many in icall.c and in socket-io.c -->
- <type fullname="System.IndexOutOfRangeException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- domain.c: mono_defaults.int16_class -->
- <type fullname="System.Int16">
- <field name="m_value"/>
- </type>
-
- <!-- domain.c: mono_defaults.int32_class -->
- <type fullname="System.Int32">
- <field name="m_value"/>
- </type>
-
- <!-- domain.c: mono_defaults.int64_class -->
- <type fullname="System.Int64">
- <field name="m_value"/>
- </type>
-
- <!-- domain.c: mono_defaults.int_class -->
- <type fullname="System.IntPtr">
- <field name="m_value"/>
- </type>
-
- <!-- exception.c (mono_get_exception_invalid_cast) -->
- <type fullname="System.InvalidCastException">
- <!-- mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- marshal.c: emit several times using mono_mb_emit_exception_full -->
- <!-- exception.c (mono_get_exception_invalid_operation) -->
- <type fullname="System.InvalidOperationException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- mini.c: mono_jit_compile_method_inner (looks like one case is JITted, AOT too) -->
- <type fullname="System.InvalidProgramException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- reflection.c mono_get_reflection_missing_object -->
- <type fullname="System.Reflection.Missing">
- <field name="Value" />
- </type>
-
- <type fullname="System.MethodAccessException">
- <!-- exception.c: mono_get_exception_method_access / mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- <!-- exception.c: mono_get_exception_method_access_msg / mono_exception_from_name_msg -->
- <!-- mini.c (mono_jit_compiler_method_inner) mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- mini.c (mono_jit_compiler_method_inner) / mono-error.c -->
- <type fullname="System.MissingFieldException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <type fullname="System.MissingMethodException">
- <!-- mini.c (mono_jit_compiler_method_inner) mono_exception_from_name_msg -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- mono-mlist.c (managed list): used in threadpool.c and gc.c -->
- <type fullname="System.MonoListItem" preserve="fields" />
-
- <!-- domain.c: mono_defaults.type_class -->
- <type fullname="System.MonoType" preserve="nothing" />
-
- <!-- domain.c: mono_defaults.multicastdelegate_class -->
- <type fullname="System.MulticastDelegate" preserve="fields" />
-
- <!-- exception.c (mono_get_exception_not_implemented) -->
- <type fullname="System.NotImplementedException">
- <!-- mono_get_exception_not_implemented -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- exception.c (mono_get_exception_not_supported) -->
- <type fullname="System.NotSupportedException">
- <!-- mono_get_exception_not_implemented -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- mono-error.c (mono_error_set_ambiguous_implementation) -->
- <type fullname="System.Runtime.AmbiguousImplementationException">
- <!-- mono_error_set_ambiguous_implementation -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- appdomain.c (create_domain_objects) domain->null_reference_ex -->
- <!-- exception.c (mono_get_exception_null_reference) -->
- <type fullname="System.NullReferenceException">
- <!-- exception.c: mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- <!-- appdomain.c: mono_exception_from_name_two_strings (only one string in the signature since NULL is used as the 2nd parameter) -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- domain.c: mono_defaults.nullable_class -->
- <type fullname="System.Nullable`1" preserve="fields">
- <!-- method-to-ir.c (handle_box) -->
- <method name="Box" />
- <!-- method-to-ir.c (handle_unbox_nullable) -->
- <method name="Unbox" />
- <!-- method-to-ir.c (handle_unbox_nullable) -->
- <method name="UnboxExact" />
- </type>
-
- <!-- domain.c: mono_defaults.object_class -->
- <type fullname="System.Object">
- <!-- class.c: initialize_object_slots -->
- <method name="Finalize" />
- <method name="GetHashCode" />
- </type>
-
- <!-- appdomain.c (create_domain_objects) domain->out_of_memory_ex -->
- <type fullname="System.OutOfMemoryException">
- <!-- mono_exception_from_name_two_strings (only one string in the signature since NULL is used as the 2nd parameter) -->
- <method signature="System.Void .ctor(System.String)" />
- <!-- exception.c: mono_get_exception_out_of_memory / mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- exception.c (mono_get_exception_overflow) -->
- <type fullname="System.OverflowException">
- <!-- mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- domain.c: mono_defaults.argumenthandle_class -->
- <type fullname="System.RuntimeArgumentHandle" preserve="fields" />
-
- <!-- domain.c: mono_defaults.typefield_class -->
- <type fullname="System.RuntimeFieldHandle" preserve="fields" />
-
- <!-- domain.c: mono_defaults.methodhandle_class -->
- <type fullname="System.RuntimeMethodHandle" preserve="fields" />
-
- <!-- domain.c: mono_defaults.runtimetype_class -->
- <!-- under mono, this has no runtime visible fields -->
- <type fullname="System.RuntimeType" preserve="nothing" />
-
- <!-- domain.c: mono_defaults.typehandle_class -->
- <type fullname="System.RuntimeTypeHandle" preserve="fields" />
-
- <!-- domain.c: mono_defaults.sbyte_class -->
- <type fullname="System.SByte">
- <field name="m_value"/>
- </type>
-
- <!-- domain.c: mono_defaults.single_class -->
- <type fullname="System.Single">
- <field name="m_value"/>
- </type>
-
- <!-- appdomain.c (create_domain_objects) domain->stack_overflow_ex -->
- <type fullname="System.StackOverflowException">
- <!-- mono_exception_from_name_two_strings (only one string in the signature since NULL is used as the 2nd parameter) -->
- <method signature="System.Void .ctor(System.String)" />
- <!-- exception.c: mono_get_exception_stack_overflow / mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- domain.c: mono_defaults.string_class -->
- <type fullname="System.String" preserve="fields">
- <!-- method-to-ir.c: mini_redirect_call -->
- <method name="FastAllocateString" />
- <!-- method-to-it.c: mini_emit_initobj -->
- <method name="memset" />
- <!-- mini-generic-sharing.c: class_type_info
- All patterns bellow
- -->
- <method name="bzero" />
- <method name="bzero_aligned_1" />
- <method name="bzero_aligned_2" />
- <method name="bzero_aligned_4" />
- <method name="bzero_aligned_8" />
- <method name="memcpy" />
- <method name="memcpy_aligned_1" />
- <method name="memcpy_aligned_2" />
- <method name="memcpy_aligned_4" />
- <method name="memcpy_aligned_8" />
-
- <!-- marshal.c: mono_marshal_get_native_wrapper -->
- <method name="Ctor"/>
- </type>
-
- <!-- socket-io.c: created/raised several time -->
- <type fullname="System.SystemException">
- <!-- mono_exception_from_nameg -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- domain.c: mono_defaults.systemtype_class -->
- <type fullname="System.Type">
- <field name="_impl"/>
- <!-- marshal.c (mono_marshal_get_synchronized_wrapper) -->
- <method name="GetTypeFromHandle" />
- <!-- sre.c (mono_reflection_type_get_underlying_system_type) -->
- <method name="get_UnderlyingSystemType" feature="sre" />
- </type>
-
- <!-- exception.c (mono_get_exception_type_initialization) -->
- <type fullname="System.TypeInitializationException">
- <!-- iterates to find the (only) 2 parameters .ctor -->
- <method signature="System.Void .ctor(System.String,System.Exception)" />
- </type>
-
- <!-- exception.c (mono_get_exception_type_load) -->
- <type fullname="System.TypeLoadException">
- <!-- mini.c (mono_jit_compiler_method_inner) mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- <!-- mono_exception_from_name_two_strings -->
- <method signature="System.Void .ctor(System.String,System.String)" />
- </type>
-
- <!-- domain.c: mono_defaults.typed_reference_class -->
- <type fullname="System.TypedReference" preserve="fields" />
-
- <!-- domain.c: mono_defaults.uint16_class -->
- <type fullname="System.UInt16">
- <field name="m_value"/>
- </type>
-
- <!-- domain.c: mono_defaults.uint32_class -->
- <type fullname="System.UInt32">
- <field name="m_value"/>
- </type>
-
- <!-- domain.c: mono_defaults.uint64_class -->
- <type fullname="System.UInt64">
- <field name="m_value"/>
- </type>
-
- <!-- domain.c: mono_defaults.uint_class -->
- <type fullname="System.UIntPtr">
- <field name="m_value"/>
- </type>
-
- <!-- object.c: create_unhandled_exception_eventargs (assert) -->
- <type fullname="System.UnhandledExceptionEventArgs">
- <method signature="System.Void .ctor(System.Object,System.Boolean)" />
- </type>
-
- <!-- class.c: make_generic_param_class -->
- <type fullname="System.ValueType" preserve="nothing" />
-
- <!-- icall.c: create_version is used by
- * ves_icall_System_Reflection_Assembly_GetReferencedAssemblies
- * fill_reflection_assembly_name
- * ves_icall_System_Reflection_Assembly_FillName
- * ves_icall_System_Reflection_Assembly_InternalGetAssemblyName
- * ves_icall_System_Reflection_AssemblyName_ParseName
- -->
- <type fullname="System.Version">
- <method signature="System.Void .ctor(System.Int32,System.Int32,System.Int32,System.Int32)" />
- </type>
-
- <!-- domain.c: mono_defaults.void_class -->
- <type fullname="System.Void" preserve="nothing" />
-
- <!-- class.c: generic_array_methods -->
- <type fullname="System.Collections.Generic.ICollection`1" />
- <type fullname="System.Collections.Generic.IEnumerable`1" />
- <type fullname="System.Collections.Generic.IReadOnlyList`1" />
- <type fullname="System.Collections.Generic.IReadOnlyCollection`1" />
-
- <!-- domain.c: mono_defaults.generic_ilist_class -->
- <type fullname="System.Collections.Generic.IList`1" />
-
- <!-- aot-compiler.c: add_generic_instances and add_generic_class_with_depth -->
- <type fullname="System.Collections.Generic.GenericEqualityComparer`1">
- <method name=".ctor" />
- </type>
-
- <!-- aot-compiler.c: add_generic_instances and add_generic_class_with_depth -->
- <type fullname="System.Collections.Generic.GenericComparer`1">
- <method name=".ctor" />
- </type>
-
- <type fullname="System.IO.FileNotFoundException">
- <!-- mini.c (mono_jit_compiler_method_inner) mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- <!-- exception.c (mono_get_exception_file_not_found and mono_get_exception_file_not_found) -->
- <!-- mono_exception_from_name_two_strings -->
- <method signature="System.Void .ctor(System.String,System.String)" />
- </type>
-
- <!-- exception.c (mono_get_exception_io) -->
- <type fullname="System.IO.IOException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- appdomain.c (ves_icall_System_Runtime_Loader_AssemblyLoadContext_InternalGetLoadedAssemblies) -->
- <type fullname="System.Reflection.Assembly" preserve="fields"/>
-
- <type fullname="System.Reflection.AssemblyName" preserve="fields" />
-
- <type fullname="System.Reflection.EventInfo" preserve="fields">
- <method name="AddEventFrame" />
- <method name="StaticAddEventAdapterFrame" />
- </type>
-
- <!-- reflection.c: mono_method_body_get_object -->
- <type fullname="System.Reflection.ExceptionHandlingClause" preserve="fields" >
- <!-- reflection.c mono_object_new_checked in add_exception_handling_clause_to_array -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- domain.c: mono_defaults.field_info_class -->
- <type fullname="System.Reflection.FieldInfo" preserve="nothing" />
-
- <!-- reflection.c: mono_method_body_get_object -->
- <type fullname="System.Reflection.RuntimeLocalVariableInfo" preserve="fields" >
- <!-- reflection.c mono_object_new_checked in add_local_var_info_to_array -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- domain.c: mono_defaults.method_info_class -->
- <type fullname="System.Reflection.MethodInfo" preserve="nothing" />
-
- <type fullname="System.Reflection.RuntimeModule" preserve="fields" >
- <method name=".ctor" />
- </type>
-
- <type fullname="System.Reflection.RuntimeAssembly" preserve="fields">
- <method name=".ctor" />
- </type>
-
- <type fullname="System.Reflection.RuntimeConstructorInfo" preserve="fields" >
- <!-- reflection.c mono_object_new_checked in method_object_construct -->
- <method signature="System.Void .ctor()" />
- </type>
- <type fullname="System.Reflection.MonoEventInfo" preserve="fields" />
- <type fullname="System.Reflection.RuntimeEventInfo" preserve="fields" >
- <!-- reflection.c mono_object_new_checked in event_object_construct -->
- <method signature="System.Void .ctor()" />
- </type>
- <type fullname="System.Reflection.RuntimeFieldInfo" preserve="fields" >
- <!-- reflection.c mono_object_new_checked in field_object_construct -->
- <method signature="System.Void .ctor()" />
- </type>
- <type fullname="System.Reflection.RuntimeMethodInfo" preserve="fields" >
- <!-- reflection.c mono_object_new_checked in method_object_construct -->
- <method signature="System.Void .ctor()" />
- </type>
- <type fullname="System.Reflection.MonoMethodInfo" preserve="fields" />
- <type fullname="System.Reflection.MonoPropertyInfo" preserve="fields" />
-
- <type fullname="System.Reflection.RuntimePropertyInfo" preserve="fields">
- <method name="GetterAdapterFrame" />
- <method name="StaticGetterAdapterFrame" />
- <!-- reflection.c mono_object_new_checked in add_parameter_object_to_array -->
- <method signature="System.Void .ctor()" />
- </type>
- <type fullname="System.Reflection.ParameterInfo" preserve="fields" />
- <!-- reflection.c: ves_icall_get_parameter_info -->
- <type fullname="System.Reflection.RuntimeParameterInfo" >
- <!-- reflection.c mono_object_new_checked in event_object_construct -->
- <method signature="System.Void .ctor()" />
- <!-- reflection.c add_parameter_object_to_array -->
- <method signature="System.Void .ctor(System.String,System.Type,System.Int32,System.Int32,System.Object,System.Reflection.MemberInfo,System.Runtime.InteropServices.MarshalAsAttribute)" />
- </type>
-
- <!-- object.c: mono_field_get_value_object and mono_runtime_invoke_array -->
- <type fullname="System.Reflection.Pointer" >
- <method name="Box" />
- </type>
-
- <!-- exception.c (mono_get_exception_reflection_type_load) -->
- <type fullname="System.Reflection.ReflectionTypeLoadException">
- <method signature="System.Void .ctor(System.Type[],System.Exception[])" />
- </type>
-
- <!-- icall.c: ves_icall_InternalInvoke -->
- <type fullname="System.Reflection.TargetException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- icall.c: ves_icall_InternalInvoke -->
- <type fullname="System.Reflection.TargetParameterCountException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <type fullname="System.Reflection.Emit.AssemblyBuilder" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.ConstructorBuilder" preserve="fields" required="false" feature="sre"/>
- <type fullname="System.Reflection.Emit.DynamicMethod" preserve="fields" required="false" feature="sre" />
- <!-- mono_dynamic_image_register_token -->
- <type fullname="System.Reflection.Emit.EnumBuilder" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.EventBuilder" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.FieldBuilder" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.GenericTypeParameterBuilder" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.ILExceptionBlock" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.ILExceptionInfo" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.ILGenerator" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.LocalBuilder" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.MethodBuilder" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.ModuleBuilder" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.ParameterBuilder" preserve="nothing" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.PropertyBuilder" preserve="nothing" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.SignatureHelper" preserve="nothing" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.TypeBuilder" preserve="fields" required="false" feature="sre">
- <method name="SetCharSet" feature="sre" />
- <!-- reflection.c mono_reflection_call_is_assignable_to () -->
- <method name="IsAssignableTo" feature="sre" />
- </type>
- <type fullname="System.Reflection.Emit.UnmanagedMarshal" preserve="fields" required="false" feature="sre" >
- <method name="DefineCustom" feature="sre" />
- <method name="DefineLPArrayInternal" feature="sre" />
- </type>
- <type fullname="System.Reflection.Emit.ArrayType" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.ByRefType" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.PointerType" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.FieldOnTypeBuilderInst" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.MethodOnTypeBuilderInst" preserve="fields" required="false" feature="sre" />
- <type fullname="System.Reflection.Emit.ConstructorOnTypeBuilderInst" preserve="fields" required="false" feature="sre" />
-
- <!-- exception.c: mono_get_exception_runtime_wrapped () -->
- <type fullname="System.Runtime.CompilerServices.RuntimeWrappedException">
- <method signature="System.Void .ctor(System.Object)" />
- </type>
-
- <!-- marshal.c: emit_marshal_custom (DISABLE_JIT is not defined for the AOT compiler, only the ARM runtimes) -->
- <type fullname="System.Runtime.InteropServices.ICustomMarshaler" />
-
- <!-- domain.c: mono_defaults.marshal_class -->
- <type fullname="System.Runtime.InteropServices.Marshal" preserve="fields" >
- <!-- marshal.c (mono_marshal_get_struct_to_ptr) -->
- <method name="StructureToPtr" />
- </type>
-
- <!-- domain.c: mono_defaults.safehandle_class -->
- <type fullname="System.Runtime.InteropServices.SafeHandle" preserve="fields">
- <!-- marshal.c (init_safe_handle) -->
- <method name="DangerousAddRef" />
- <method name="DangerousRelease" />
- </type>
-
- <!-- marshal.c: mono_mb_emit_exception_marshal_directive -->
- <type fullname="System.Runtime.InteropServices.MarshalDirectiveException">
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- native-library.c: mono_class_get_native_library_class -->
- <type fullname="System.Runtime.InteropServices.NativeLibrary">
- <method name="MonoLoadLibraryCallbackStub" />
- <method name="MonoResolveUnmanagedDll" />
- <method name="MonoResolveUnmanagedDllUsingEvent" />
- </type>
-
- <!-- domain.c: mono_defaults.monitor_class -->
- <!-- monitor.c / method-to-ir.c: Enter and Exit are only string comparison (safe to link) -->
- <type fullname="System.Threading.Monitor">
- <!-- marshal.c: mono_marshal_get_synchronized_wrapper-->
- <method name="Enter" />
- <method name="Exit" />
- </type>
-
- <!-- exception.c (mono_get_exception_synchronization_lock) -->
- <type fullname="System.Threading.SynchronizationLockException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <!-- domain.c: mono_defaults.thread_class -->
- <!-- FIXME: -->
- <type fullname="System.Threading.Thread" preserve="fields">
- <method name="get_CurrentContext" />
- </type>
-
- <!-- domain.c: mono_defaults.threadabortexception_class -->
- <!-- exception.c (mono_get_exception_thread_abort) -->
- <type fullname="System.Threading.ThreadAbortException">
- <!-- mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- exception.c (ThreadInterruptedException) -->
- <type fullname="System.Threading.ThreadInterruptedException">
- <!-- mono_exception_from_name -->
- <method signature="System.Void .ctor()" />
- </type>
-
- <!-- exception.c (mono_get_exception_thread_abort) -->
- <type fullname="System.Threading.ThreadStateException">
- <!-- mono_exception_from_name_msg -->
- <method signature="System.Void .ctor(System.String)" />
- </type>
-
- <type fullname="System.Threading.WasmRuntime"/>
-
- <!-- mini-generic-sharing.c -->
- <type fullname="Mono.ValueTuple" preserve="fields"/>
- <type fullname="Mono.ValueTuple`1" preserve="fields"/>
- <type fullname="Mono.ValueTuple`2" preserve="fields"/>
- <type fullname="Mono.ValueTuple`3" preserve="fields"/>
- <type fullname="Mono.ValueTuple`4" preserve="fields"/>
- <type fullname="Mono.ValueTuple`5" preserve="fields"/>
-
- <type fullname="System.AppContext">
- <!-- appdomain.c: mono_runtime_install_appctx_properties -->
- <method name="Setup"/>
- <method name="OnProcessExit"/>
- <!-- appdomain.c: get_app_context_base_directory -->
- <method name="get_BaseDirectory"/>
- </type>
-
- <typename fullname="Mono.NullByRefReturnException">
- <!-- marshal-ilgen.c:emit_invoke_call -->
- <method signature="System.Void .ctor()" />
- </typename>
- </assembly>
-</linker>
diff --git a/netcore/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.Unix.Mono.cs b/netcore/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.Unix.Mono.cs
deleted file mode 100644
index 607853e37f6..00000000000
--- a/netcore/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.Unix.Mono.cs
+++ /dev/null
@@ -1,22 +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 System;
-using System.Threading;
-using System.Runtime.CompilerServices;
-
-namespace Microsoft.Win32.SafeHandles
-{
- partial class SafeWaitHandle
- {
- protected override bool ReleaseHandle ()
- {
- CloseEventInternal (handle);
- return true;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern void CloseEventInternal (IntPtr handle);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs b/netcore/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs
deleted file mode 100644
index aa57db9fc7a..00000000000
--- a/netcore/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs
+++ /dev/null
@@ -1,50 +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 System;
-using System.Runtime.InteropServices;
-
-namespace Microsoft.Win32
-{
- static class UnsafeNativeMethods
- {
- internal static unsafe class ManifestEtw
- {
- internal unsafe delegate void EtwEnableCallback(
- [In] ref Guid sourceId,
- [In] int isEnabled,
- [In] byte level,
- [In] long matchAnyKeywords,
- [In] long matchAllKeywords,
- [In] EVENT_FILTER_DESCRIPTOR* filterData,
- [In] void* callbackContext
- );
-
- [StructLayout(LayoutKind.Sequential)]
- unsafe internal struct EVENT_FILTER_DESCRIPTOR
- {
- public long Ptr;
- public int Size;
- public int Type;
- }
-
- internal enum ActivityControl : uint
- {
- EVENT_ACTIVITY_CTRL_GET_ID = 1,
- EVENT_ACTIVITY_CTRL_SET_ID = 2,
- EVENT_ACTIVITY_CTRL_CREATE_ID = 3,
- EVENT_ACTIVITY_CTRL_GET_SET_ID = 4,
- EVENT_ACTIVITY_CTRL_CREATE_SET_ID = 5
- }
-
- internal const int ERROR_ARITHMETIC_OVERFLOW = 534;
- internal const int ERROR_NOT_ENOUGH_MEMORY = 8;
- internal const int ERROR_MORE_DATA = 0xEA;
-
- internal const int EVENT_CONTROL_CODE_DISABLE_PROVIDER = 0;
- internal const int EVENT_CONTROL_CODE_ENABLE_PROVIDER = 1;
- internal const int EVENT_CONTROL_CODE_CAPTURE_STATE = 2;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/Mono/MonoDomain.cs b/netcore/System.Private.CoreLib/src/Mono/MonoDomain.cs
deleted file mode 100644
index f98f250abc1..00000000000
--- a/netcore/System.Private.CoreLib/src/Mono/MonoDomain.cs
+++ /dev/null
@@ -1,24 +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 System;
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-namespace Mono
-{
- [StructLayout (LayoutKind.Sequential)]
- internal sealed partial class MonoDomain
- {
- #pragma warning disable 169
- #region Sync with object-internals.h
- IntPtr _mono_app_domain;
- #endregion
- #pragma warning restore 169
-
- public event UnhandledExceptionEventHandler UnhandledException;
-
- public event EventHandler ProcessExit;
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/Mono/MonoDomainSetup.cs b/netcore/System.Private.CoreLib/src/Mono/MonoDomainSetup.cs
deleted file mode 100644
index 1f261b25110..00000000000
--- a/netcore/System.Private.CoreLib/src/Mono/MonoDomainSetup.cs
+++ /dev/null
@@ -1,45 +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.
-
-#nullable disable
-using System.Runtime.InteropServices;
-
-namespace Mono
-{
- [StructLayout (LayoutKind.Sequential)]
- internal sealed class MonoDomainSetup
- {
- #region Sync with object-internals.h
- string application_base;
- string application_name;
- string cache_path;
- string configuration_file;
- string dynamic_base;
- string license_file;
- string private_bin_path;
- string private_bin_path_probe;
- string shadow_copy_directories;
- string shadow_copy_files;
- bool publisher_policy;
- private bool path_changed;
- private int loader_optimization;
- bool disallow_binding_redirects;
- bool disallow_code_downloads;
-
- object _activationArguments;
- object domain_initializer;
- object application_trust;
- string [] domain_initializer_args;
-
- bool disallow_appbase_probe;
- byte [] configuration_bytes;
-
- byte [] serialized_non_primitives;
- #endregion
-
- public MonoDomainSetup ()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/Mono/MonoListItem.cs b/netcore/System.Private.CoreLib/src/Mono/MonoListItem.cs
deleted file mode 100644
index 4c93afe2e14..00000000000
--- a/netcore/System.Private.CoreLib/src/Mono/MonoListItem.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace Mono
-{
- // Internal type used by Mono runtime only
- internal sealed class MonoListItem
- {
- public MonoListItem next;
- public object data;
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/Mono/RuntimeHandles.cs b/netcore/System.Private.CoreLib/src/Mono/RuntimeHandles.cs
deleted file mode 100644
index 2ea23029c2d..00000000000
--- a/netcore/System.Private.CoreLib/src/Mono/RuntimeHandles.cs
+++ /dev/null
@@ -1,240 +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 System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-namespace Mono
-{
- unsafe struct RuntimeClassHandle
- {
- RuntimeStructs.MonoClass* value;
-
- internal RuntimeClassHandle (RuntimeStructs.MonoClass* value)
- {
- this.value = value;
- }
-
- internal RuntimeClassHandle (IntPtr ptr)
- {
- this.value = (RuntimeStructs.MonoClass*) ptr;
- }
-
- internal RuntimeStructs.MonoClass* Value => value;
-
- public override bool Equals (object? obj)
- {
- if (obj == null || GetType () != obj.GetType ())
- return false;
-
- return value == ((RuntimeClassHandle)obj).Value;
- }
-
- public override int GetHashCode () => ((IntPtr)value).GetHashCode ();
-
- public bool Equals (RuntimeClassHandle handle)
- {
- return value == handle.Value;
- }
-
- public static bool operator == (RuntimeClassHandle left, object? right)
- {
- return right != null && right is RuntimeClassHandle rch && left.Equals (rch);
- }
-
- public static bool operator != (RuntimeClassHandle left, object? right)
- {
- return !(left == right);
- }
-
- public static bool operator == (object? left, RuntimeClassHandle right)
- {
- return left != null && left is RuntimeClassHandle rch && rch.Equals (right);
- }
-
- public static bool operator != (object? left, RuntimeClassHandle right)
- {
- return !(left == right);
- }
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- internal unsafe extern static IntPtr GetTypeFromClass (RuntimeStructs.MonoClass *klass);
-
- internal RuntimeTypeHandle GetTypeHandle () => new RuntimeTypeHandle (GetTypeFromClass (value));
- }
-
- unsafe struct RuntimeRemoteClassHandle
- {
- RuntimeStructs.RemoteClass* value;
-
- internal RuntimeRemoteClassHandle (RuntimeStructs.RemoteClass* value)
- {
- this.value = value;
- }
-
- internal RuntimeClassHandle ProxyClass {
- get {
- return new RuntimeClassHandle (value->proxy_class);
- }
- }
- }
-
- unsafe struct RuntimeGenericParamInfoHandle
- {
- RuntimeStructs.GenericParamInfo* value;
-
- internal RuntimeGenericParamInfoHandle (RuntimeStructs.GenericParamInfo* value)
- {
- this.value = value;
- }
-
- internal RuntimeGenericParamInfoHandle (IntPtr ptr)
- {
- this.value = (RuntimeStructs.GenericParamInfo*) ptr;
- }
-
- internal Type[] Constraints => GetConstraints ();
-
- internal GenericParameterAttributes Attributes => (GenericParameterAttributes) value->flags;
-
- Type[] GetConstraints ()
- {
- int n = GetConstraintsCount ();
- var a = new Type [n];
- for (int i = 0; i < n; i++) {
- RuntimeClassHandle c = new RuntimeClassHandle (value->constraints[i]);
- a[i] = Type.GetTypeFromHandle (c.GetTypeHandle ());
- }
-
- return a;
- }
-
- int GetConstraintsCount ()
- {
- int i = 0;
- RuntimeStructs.MonoClass** p = value->constraints;
- while (p != null && *p != null) {
- p++; i++;
- }
- return i;
- }
- }
-
- internal struct RuntimeEventHandle
- {
- IntPtr value;
-
- internal RuntimeEventHandle (IntPtr v)
- {
- value = v;
- }
-
- public IntPtr Value => value;
-
- public override bool Equals (object? obj)
- {
- if (obj == null || GetType () != obj.GetType ())
- return false;
-
- return value == ((RuntimeEventHandle)obj).Value;
- }
-
- public bool Equals (RuntimeEventHandle handle)
- {
- return value == handle.Value;
- }
-
- public override int GetHashCode ()
- {
- return value.GetHashCode ();
- }
-
- public static bool operator == (RuntimeEventHandle left, RuntimeEventHandle right)
- {
- return left.Equals (right);
- }
-
- public static bool operator != (RuntimeEventHandle left, RuntimeEventHandle right)
- {
- return !left.Equals (right);
- }
- }
-
- internal struct RuntimePropertyHandle
- {
- IntPtr value;
-
- internal RuntimePropertyHandle (IntPtr v)
- {
- value = v;
- }
-
- public IntPtr Value => value;
-
- public override bool Equals (object? obj)
- {
- if (obj == null || GetType () != obj.GetType ())
- return false;
-
- return value == ((RuntimePropertyHandle)obj).Value;
- }
-
- public bool Equals (RuntimePropertyHandle handle)
- {
- return value == handle.Value;
- }
-
- public override int GetHashCode ()
- {
- return value.GetHashCode ();
- }
-
- public static bool operator == (RuntimePropertyHandle left, RuntimePropertyHandle right)
- {
- return left.Equals (right);
- }
-
- public static bool operator != (RuntimePropertyHandle left, RuntimePropertyHandle right)
- {
- return !left.Equals (right);
- }
- }
-
- unsafe struct RuntimeGPtrArrayHandle
- {
- RuntimeStructs.GPtrArray* value;
-
- internal RuntimeGPtrArrayHandle (RuntimeStructs.GPtrArray* value)
- {
- this.value = value;
- }
-
- internal RuntimeGPtrArrayHandle (IntPtr ptr)
- {
- this.value = (RuntimeStructs.GPtrArray*) ptr;
- }
-
- internal int Length => value->len;
-
- internal IntPtr this [int i] => Lookup (i);
-
- internal IntPtr Lookup (int i)
- {
- if (i >= 0 && i < Length) {
- return value->data[i];
- } else
- throw new IndexOutOfRangeException ();
- }
-
- [MethodImpl(MethodImplOptions.InternalCall)]
- extern static void GPtrArrayFree (RuntimeStructs.GPtrArray* value);
-
- internal static void DestroyAndFree (ref RuntimeGPtrArrayHandle h)
- {
- GPtrArrayFree (h.value);
- h.value = null;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/Mono/RuntimeMarshal.cs b/netcore/System.Private.CoreLib/src/Mono/RuntimeMarshal.cs
deleted file mode 100644
index 28124b21aaf..00000000000
--- a/netcore/System.Private.CoreLib/src/Mono/RuntimeMarshal.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-
-namespace Mono {
- internal static class RuntimeMarshal {
- internal static string PtrToUtf8String (IntPtr ptr)
- {
- unsafe {
- if (ptr == IntPtr.Zero)
- return string.Empty;
-
- byte* bytes = (byte*)ptr;
- int length = 0;
-
- try {
- while (bytes++ [0] != 0)
- length++;
- } catch (NullReferenceException) {
- throw new ArgumentOutOfRangeException ("ptr", "Value does not refer to a valid string.");
- }
-
- return new String ((sbyte*)ptr, 0, length, System.Text.Encoding.UTF8);
- }
- }
-
- internal static SafeStringMarshal MarshalString (string str)
- {
- return new SafeStringMarshal (str);
- }
-
- static int DecodeBlobSize (IntPtr in_ptr, out IntPtr out_ptr)
- {
- uint size;
- unsafe {
- byte *ptr = (byte*)in_ptr;
-
- if ((*ptr & 0x80) == 0) {
- size = (uint)(ptr [0] & 0x7f);
- ptr++;
- } else if ((*ptr & 0x40) == 0){
- size = (uint)(((ptr [0] & 0x3f) << 8) + ptr [1]);
- ptr += 2;
- } else {
- size = (uint)(((ptr [0] & 0x1f) << 24) +
- (ptr [1] << 16) +
- (ptr [2] << 8) +
- ptr [3]);
- ptr += 4;
- }
- out_ptr = (IntPtr)ptr;
- }
-
- return (int)size;
- }
-
- internal static byte[] DecodeBlobArray (IntPtr ptr)
- {
- IntPtr out_ptr;
- int size = DecodeBlobSize (ptr, out out_ptr);
- byte[] res = new byte [size];
- Marshal.Copy (out_ptr, res, 0, size);
- return res;
- }
-
- internal static int AsciHexDigitValue (int c)
- {
- if (c >= '0' && c <= '9')
- return c - '0';
- if (c >= 'a' && c <= 'f')
- return c - 'a' + 10;
- return c - 'A' + 10;
- }
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- internal static extern void FreeAssemblyName (ref MonoAssemblyName name, bool freeStruct);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/Mono/RuntimeStructs.cs b/netcore/System.Private.CoreLib/src/Mono/RuntimeStructs.cs
deleted file mode 100644
index ae0255124d4..00000000000
--- a/netcore/System.Private.CoreLib/src/Mono/RuntimeStructs.cs
+++ /dev/null
@@ -1,123 +0,0 @@
-//
-// Mono runtime native structs surfaced to managed code.
-//
-// Authors:
-// Aleksey Kliger <aleksey@xamarin.com>
-// Rodrigo Kumpera <kumpera@xamarin.com>
-//
-// Copyright 2016 Dot net foundation.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
-
-using System;
-using System.Runtime.InteropServices;
-
-#pragma warning disable 169
-
-namespace Mono {
- //
- // Managed representations of mono runtime types
- //
- internal static class RuntimeStructs {
- // class-internals.h MonoRemoteClass
- [StructLayout(LayoutKind.Sequential)]
- internal unsafe struct RemoteClass {
- internal IntPtr default_vtable;
- internal IntPtr xdomain_vtable;
- internal MonoClass* proxy_class;
- internal IntPtr proxy_class_name;
- internal uint interface_count;
- // FIXME: How to represent variable-length array struct member?
- // MonoClass* interfaces [];
- }
-
- internal struct MonoClass {
- }
-
- // class-internals.h MonoGenericParamInfo
- internal unsafe struct GenericParamInfo {
- internal MonoClass* pklass;
- internal IntPtr name;
- internal ushort flags;
- internal uint token;
- internal MonoClass** constraints; /* NULL terminated */
- }
-
- // glib.h GPtrArray
- internal unsafe struct GPtrArray {
- internal IntPtr* data;
- internal int len;
- }
- }
-
- //Maps to metadata-internals.h:: MonoAssemblyName
- internal unsafe struct MonoAssemblyName
- {
- const int MONO_PUBLIC_KEY_TOKEN_LENGTH = 17;
-
- internal IntPtr name;
- internal IntPtr culture;
- internal IntPtr hash_value;
- internal IntPtr public_key;
- internal fixed byte public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
- internal uint hash_alg;
- internal uint hash_len;
- internal uint flags;
-#if NETCORE
- internal int major, minor, build, revision;
-#else
- internal ushort major, minor, build, revision;
-#endif
- internal ushort arch;
- }
-
- // Used to implement generic sharing
- // See mini-generic-sharing.c
- // We use these instead of the normal ValueTuple types to avoid linking in the
- // c# methods belonging to those types
- internal struct ValueTuple
- {
- }
-
- internal struct ValueTuple<T1>
- {
- public T1 Item1;
- }
-
- internal struct ValueTuple<T1, T2>
- {
- public T1 Item1;
- public T2 Item2;
- }
-
- internal struct ValueTuple<T1, T2, T3>
- {
- public T1 Item1;
- public T2 Item2;
- public T3 Item3;
- }
-
- internal struct ValueTuple<T1, T2, T3, T4>
- {
- public T1 Item1;
- public T2 Item2;
- public T3 Item3;
- public T4 Item4;
- }
-
- internal struct ValueTuple<T1, T2, T3, T4, T5>
- {
- public T1 Item1;
- public T2 Item2;
- public T3 Item3;
- public T4 Item4;
- public T5 Item5;
- }
-
- internal class NullByRefReturnException : Exception
- {
- public NullByRefReturnException ()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/Mono/SafeGPtrArrayHandle.cs b/netcore/System.Private.CoreLib/src/Mono/SafeGPtrArrayHandle.cs
deleted file mode 100644
index 0441c9b8bd8..00000000000
--- a/netcore/System.Private.CoreLib/src/Mono/SafeGPtrArrayHandle.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-//
-// Safe handle class for Mono.RuntimeGPtrArrayHandle
-//
-// Authors:
-// Aleksey Kliger <aleksey@xamarin.com>
-// Rodrigo Kumpera <kumpera@xamarin.com>
-//
-// Copyright 2016 Dot net foundation.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
-
-using System;
-using System.Runtime.CompilerServices;
-
-namespace Mono {
- internal struct SafeGPtrArrayHandle : IDisposable {
- RuntimeGPtrArrayHandle handle;
-
- internal SafeGPtrArrayHandle (IntPtr ptr)
- {
- handle = new RuntimeGPtrArrayHandle (ptr);
- }
-
- public void Dispose () {
- RuntimeGPtrArrayHandle.DestroyAndFree (ref handle);
- }
-
- internal int Length {
- get {
- return handle.Length;
- }
- }
-
- internal IntPtr this[int i] => handle[i];
- }
-
-
-}
diff --git a/netcore/System.Private.CoreLib/src/Mono/SafeStringMarshal.cs b/netcore/System.Private.CoreLib/src/Mono/SafeStringMarshal.cs
deleted file mode 100644
index d21829d5dc9..00000000000
--- a/netcore/System.Private.CoreLib/src/Mono/SafeStringMarshal.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-//
-// Safe wrapper for a string and its UTF8 encoding
-//
-// Authors:
-// Aleksey Kliger <aleksey@xamarin.com>
-// Rodrigo Kumpera <kumpera@xamarin.com>
-//
-// Copyright 2016 Dot net foundation.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
-
-using System;
-using System.Runtime.CompilerServices;
-
-namespace Mono {
- internal struct SafeStringMarshal : IDisposable {
- readonly string str;
- IntPtr marshaled_string;
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern static IntPtr StringToUtf8_icall (ref string str);
-
- public static IntPtr StringToUtf8 (string str)
- {
- return StringToUtf8_icall (ref str);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public extern static void GFree (IntPtr ptr);
-
- public SafeStringMarshal (string str) {
- this.str = str;
- this.marshaled_string = IntPtr.Zero;
- }
-
- public IntPtr Value {
- get {
- if (marshaled_string == IntPtr.Zero && str != null)
- marshaled_string = StringToUtf8 (str);
- return marshaled_string;
- }
- }
-
- public void Dispose () {
- if (marshaled_string != IntPtr.Zero) {
- GFree (marshaled_string);
- marshaled_string = IntPtr.Zero;
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/ArgIterator.cs b/netcore/System.Private.CoreLib/src/System/ArgIterator.cs
deleted file mode 100644
index 3b4d0a88050..00000000000
--- a/netcore/System.Private.CoreLib/src/System/ArgIterator.cs
+++ /dev/null
@@ -1,104 +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 System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System
-{
- [StructLayout (LayoutKind.Auto)]
- public ref struct ArgIterator
- {
-#pragma warning disable 169, 414
- IntPtr sig;
- IntPtr args;
- int next_arg;
- int num_args;
-#pragma warning restore 169, 414
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- extern void Setup (IntPtr argsp, IntPtr start);
-
- public ArgIterator (RuntimeArgumentHandle arglist)
- {
- sig = IntPtr.Zero;
- args = IntPtr.Zero;
- next_arg = num_args = 0;
- if (arglist.args == IntPtr.Zero)
- throw new PlatformNotSupportedException ();
- Setup (arglist.args, IntPtr.Zero);
- }
-
- [CLSCompliant (false)]
- unsafe public ArgIterator (RuntimeArgumentHandle arglist, void *ptr)
- {
- sig = IntPtr.Zero;
- args = IntPtr.Zero;
- next_arg = num_args = 0;
- if (arglist.args == IntPtr.Zero)
- throw new PlatformNotSupportedException ();
- Setup (arglist.args, (IntPtr) ptr);
- }
-
- public void End ()
- {
- next_arg = num_args;
- }
-
- public override bool Equals (object? o)
- {
- throw new NotSupportedException ("ArgIterator does not support Equals.");
- }
-
- public override int GetHashCode ()
- {
- return sig.GetHashCode ();
- }
-
- [CLSCompliant (false)]
- public TypedReference GetNextArg ()
- {
- if (num_args == next_arg)
- throw new InvalidOperationException ("Invalid iterator position.");
- TypedReference result = new TypedReference ();
- unsafe {
- IntGetNextArg (&result);
- }
- return result;
- }
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- extern unsafe void IntGetNextArg (void *res);
-
- [CLSCompliant (false)]
- public TypedReference GetNextArg (RuntimeTypeHandle rth)
- {
- if (num_args == next_arg)
- throw new InvalidOperationException ("Invalid iterator position.");
- TypedReference result = new TypedReference ();
- unsafe {
- IntGetNextArgWithType (&result, rth.Value);
- }
- return result;
- }
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- extern unsafe void IntGetNextArgWithType (void *res, IntPtr rth);
-
- public RuntimeTypeHandle GetNextArgType ()
- {
- if (num_args == next_arg)
- throw new InvalidOperationException ("Invalid iterator position.");
- return new RuntimeTypeHandle (IntGetNextArgType ());
- }
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- extern IntPtr IntGetNextArgType ();
-
- public int GetRemainingCount ()
- {
- return num_args - next_arg;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Array.Mono.cs b/netcore/System.Private.CoreLib/src/System/Array.Mono.cs
deleted file mode 100644
index e65df0c13da..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Array.Mono.cs
+++ /dev/null
@@ -1,632 +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 Internal.Runtime.CompilerServices;
-using System.Collections;
-using System.Collections.Generic;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using Mono;
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- partial class Array
- {
- [StructLayout(LayoutKind.Sequential)]
- private class RawData
- {
- public IntPtr Bounds;
- public IntPtr Count;
- public byte Data;
- }
-
- public int Length {
- [Intrinsic]
- get => Length;
- }
-
- public long LongLength {
- get {
- long length = GetLength (0);
-
- for (int i = 1; i < Rank; i++) {
- length *= GetLength (i);
- }
- return length;
- }
- }
-
- public int Rank {
- [Intrinsic]
- get => Rank;
- }
-
- public static unsafe void Clear (Array array, int index, int length)
- {
- if (array == null)
- ThrowHelper.ThrowArgumentNullException (ExceptionArgument.array);
-
- int lowerBound = array.GetLowerBound (0);
- int elementSize = array.GetElementSize ();
- nuint numComponents = (nuint) Unsafe.As<RawData> (array).Count;
-
- int offset = index - lowerBound;
-
- if (index < lowerBound || offset < 0 || length < 0 || (uint) (offset + length) > numComponents)
- ThrowHelper.ThrowIndexOutOfRangeException ();
-
- ref byte ptr = ref Unsafe.AddByteOffset (ref array.GetRawSzArrayData(), (uint) offset * (nuint) elementSize);
- nuint byteLength = (uint) length * (nuint) elementSize;
-
- if (RuntimeHelpers.ObjectHasReferences (array))
- SpanHelpers.ClearWithReferences (ref Unsafe.As<byte, IntPtr> (ref ptr), byteLength / (uint)sizeof (IntPtr));
- else
- SpanHelpers.ClearWithoutReferences (ref ptr, byteLength);
- }
-
- public static void ConstrainedCopy (Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
- {
- Copy (sourceArray, sourceIndex, destinationArray, destinationIndex, length, true);
- }
-
- public static void Copy (Array sourceArray, Array destinationArray, int length)
- {
- if (sourceArray == null)
- throw new ArgumentNullException ("sourceArray");
-
- if (destinationArray == null)
- throw new ArgumentNullException ("destinationArray");
-
- Copy (sourceArray, sourceArray.GetLowerBound (0), destinationArray,
- destinationArray.GetLowerBound (0), length);
- }
-
- public static void Copy (Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
- {
- Copy (sourceArray, sourceIndex, destinationArray, destinationIndex, length, false);
- }
-
- private static void Copy (Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable)
- {
- if (sourceArray == null)
- throw new ArgumentNullException (nameof (sourceArray));
-
- if (destinationArray == null)
- throw new ArgumentNullException (nameof (destinationArray));
-
- if (length < 0)
- throw new ArgumentOutOfRangeException (nameof (length), "Value has to be >= 0.");
-
- if (sourceArray.Rank != destinationArray.Rank)
- throw new RankException(SR.Rank_MultiDimNotSupported);
-
- if (sourceIndex < 0)
- throw new ArgumentOutOfRangeException (nameof (sourceIndex), "Value has to be >= 0.");
-
- if (destinationIndex < 0)
- throw new ArgumentOutOfRangeException (nameof (destinationIndex), "Value has to be >= 0.");
-
- if (FastCopy (sourceArray, sourceIndex, destinationArray, destinationIndex, length))
- return;
-
- int source_pos = sourceIndex - sourceArray.GetLowerBound (0);
- int dest_pos = destinationIndex - destinationArray.GetLowerBound (0);
-
- if (source_pos < 0)
- throw new ArgumentOutOfRangeException (nameof (sourceIndex), "Index was less than the array's lower bound in the first dimension.");
-
- if (dest_pos < 0)
- throw new ArgumentOutOfRangeException (nameof (destinationIndex), "Index was less than the array's lower bound in the first dimension.");
-
- // re-ordered to avoid possible integer overflow
- if (source_pos > sourceArray.Length - length)
- throw new ArgumentException (SR.Arg_LongerThanSrcArray, nameof (sourceArray));
-
- if (dest_pos > destinationArray.Length - length) {
- throw new ArgumentException ("Destination array was not long enough. Check destIndex and length, and the array's lower bounds", nameof (destinationArray));
- }
-
- Type src_type = sourceArray.GetType ().GetElementType ()!;
- Type dst_type = destinationArray.GetType ().GetElementType ()!;
- var dst_type_vt = dst_type.IsValueType && Nullable.GetUnderlyingType (dst_type) == null;
-
- bool src_is_enum = src_type.IsEnum;
- bool dst_is_enum = dst_type.IsEnum;
-
- if (src_is_enum)
- src_type = Enum.GetUnderlyingType (src_type);
- if (dst_is_enum)
- dst_type = Enum.GetUnderlyingType (dst_type);
-
- if (reliable) {
- if (!dst_type.Equals (src_type) &&
- !(dst_type.IsPrimitive && src_type.IsPrimitive && CanChangePrimitive(ref dst_type, ref src_type, true))) {
- throw new ArrayTypeMismatchException (SR.ArrayTypeMismatch_CantAssignType);
- }
- } else {
- if (!CanAssignArrayElement (src_type, dst_type)) {
- throw new ArrayTypeMismatchException (SR.ArrayTypeMismatch_CantAssignType);
- }
- }
-
- if (!Object.ReferenceEquals (sourceArray, destinationArray) || source_pos > dest_pos) {
- for (int i = 0; i < length; i++) {
- Object srcval = sourceArray.GetValueImpl (source_pos + i);
-
- if (!src_type.IsValueType && dst_is_enum)
- throw new InvalidCastException (SR.InvalidCast_DownCastArrayElement);
-
- if (dst_type_vt && (srcval == null || (src_type == typeof (object) && srcval.GetType () != dst_type)))
- throw new InvalidCastException ();
-
- try {
- destinationArray.SetValueRelaxedImpl (srcval, dest_pos + i);
- } catch (ArgumentException) {
- throw CreateArrayTypeMismatchException ();
- }
- }
- } else {
- for (int i = length - 1; i >= 0; i--) {
- Object srcval = sourceArray.GetValueImpl (source_pos + i);
-
- try {
- destinationArray.SetValueRelaxedImpl (srcval, dest_pos + i);
- } catch (ArgumentException) {
- throw CreateArrayTypeMismatchException ();
- }
- }
- }
- }
-
- static ArrayTypeMismatchException CreateArrayTypeMismatchException ()
- {
- return new ArrayTypeMismatchException ();
- }
-
- static bool CanAssignArrayElement (Type source, Type target)
- {
- if (!target.IsValueType && !target.IsPointer) {
- if (!source.IsValueType && !source.IsPointer) {
- // Reference to reference copy
- return
- source.IsInterface || target.IsInterface ||
- source.IsAssignableFrom (target) || target.IsAssignableFrom (source);
- } else {
- // Value to reference copy
- if (source.IsPointer)
- return false;
- return target.IsAssignableFrom (source);
- }
- } else {
- if (source.IsEquivalentTo (target)) {
- return true;
- } else if (source.IsPointer && target.IsPointer) {
- return true;
- } else if (source.IsPrimitive && target.IsPrimitive) {
-
- // Allow primitive type widening
- return CanChangePrimitive (ref source, ref target, false);
- } else if (!source.IsValueType && !source.IsPointer) {
- // Source is base class or interface of destination type
- if (target.IsPointer)
- return false;
- return source.IsAssignableFrom (target);
- }
- }
-
- return false;
- }
-
- public static unsafe Array CreateInstance (Type elementType, int length)
- {
- if (elementType is null)
- ThrowHelper.ThrowArgumentNullException (ExceptionArgument.elementType);
- if (length < 0)
- ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum ();
-
- RuntimeType? runtimeType = elementType.UnderlyingSystemType as RuntimeType;
- if (runtimeType == null)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
-
- Array array = null;
- InternalCreate (ref array, runtimeType._impl.Value, 1, &length, null);
- GC.KeepAlive (runtimeType);
- return array;
- }
-
- public static unsafe Array CreateInstance (Type elementType, int length1, int length2)
- {
- if (elementType is null)
- ThrowHelper.ThrowArgumentNullException (ExceptionArgument.elementType);
- if (length1 < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException (ExceptionArgument.length1, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- if (length2 < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException (ExceptionArgument.length2, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
-
- RuntimeType? runtimeType = elementType.UnderlyingSystemType as RuntimeType;
- if (runtimeType == null)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
-
- int* lengths = stackalloc int [] { length1, length2 };
- Array array = null;
- InternalCreate (ref array, runtimeType._impl.Value, 2, lengths, null);
- GC.KeepAlive (runtimeType);
- return array;
- }
-
- public static unsafe Array CreateInstance (Type elementType, int length1, int length2, int length3)
- {
- if (elementType is null)
- ThrowHelper.ThrowArgumentNullException (ExceptionArgument.elementType);
- if (length1 < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException (ExceptionArgument.length1, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- if (length2 < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException (ExceptionArgument.length2, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- if (length3 < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException (ExceptionArgument.length3, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
-
- RuntimeType? runtimeType = elementType.UnderlyingSystemType as RuntimeType;
- if (runtimeType == null)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
-
- int* lengths = stackalloc int [] { length1, length2, length3 };
- Array array = null;
- InternalCreate (ref array, runtimeType._impl.Value, 3, lengths, null);
- GC.KeepAlive (runtimeType);
- return array;
- }
-
- public static unsafe Array CreateInstance (Type elementType, params int[] lengths)
- {
- if (elementType is null)
- ThrowHelper.ThrowArgumentNullException (ExceptionArgument.elementType);
- if (lengths == null)
- ThrowHelper.ThrowArgumentNullException (ExceptionArgument.lengths);
- if (lengths.Length == 0)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_NeedAtLeast1Rank);
-
- RuntimeType? runtimeType = elementType.UnderlyingSystemType as RuntimeType;
- if (runtimeType == null)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
-
- for (int i = 0; i < lengths.Length; i++)
- if (lengths [i] < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException (ExceptionArgument.lengths, i, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
-
- Array array = null;
- fixed (int* pLengths = &lengths [0])
- InternalCreate (ref array, runtimeType._impl.Value, lengths.Length, pLengths, null);
- GC.KeepAlive (runtimeType);
- return array;
- }
-
- public static unsafe Array CreateInstance (Type elementType, int[] lengths, int[] lowerBounds)
- {
- if (elementType == null)
- ThrowHelper.ThrowArgumentNullException (ExceptionArgument.elementType);
- if (lengths == null)
- ThrowHelper.ThrowArgumentNullException (ExceptionArgument.lengths);
- if (lowerBounds == null)
- ThrowHelper.ThrowArgumentNullException (ExceptionArgument.lowerBounds);
- if (lengths.Length != lowerBounds!.Length)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_RanksAndBounds);
- if (lengths.Length == 0)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_NeedAtLeast1Rank);
-
- for (int i = 0; i < lengths.Length; i++)
- if (lengths [i] < 0)
- ThrowHelper.ThrowArgumentOutOfRangeException (ExceptionArgument.lengths, i, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
-
- RuntimeType? runtimeType = elementType.UnderlyingSystemType as RuntimeType;
- if (runtimeType == null)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
-
- Array array = null;
- fixed (int* pLengths = &lengths [0])
- fixed (int* pLowerBounds = &lowerBounds [0])
- InternalCreate (ref array, runtimeType._impl.Value, lengths.Length, pLengths, pLowerBounds);
- GC.KeepAlive (runtimeType);
- return array;
- }
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern unsafe void InternalCreate (ref Array result, IntPtr elementType, int rank, int* lengths, int* lowerBounds);
-
- public object GetValue (int index)
- {
- if (Rank != 1)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_Need1DArray);
-
- var lb = GetLowerBound (0);
- if (index < lb || index > GetUpperBound (0))
- throw new IndexOutOfRangeException ("Index has to be between upper and lower bound of the array.");
-
- if (GetType ().GetElementType ()!.IsPointer)
- throw new NotSupportedException (SR.NotSupported_Type);
-
- return GetValueImpl (index - lb);
- }
-
- public object GetValue (int index1, int index2)
- {
- if (Rank != 2)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_Need2DArray);
-
- int[] ind = {index1, index2};
- return GetValue (ind);
- }
-
- public object GetValue (int index1, int index2, int index3)
- {
- if (Rank != 3)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_Need3DArray);
-
- int[] ind = {index1, index2, index3};
- return GetValue (ind);
- }
-
- public void Initialize ()
- {
- }
-
- static int IndexOfImpl<T>(T[] array, T value, int startIndex, int count)
- {
- return EqualityComparer<T>.Default.IndexOf (array, value, startIndex, count);
- }
-
- static int LastIndexOfImpl<T>(T[] array, T value, int startIndex, int count)
- {
- return EqualityComparer<T>.Default.LastIndexOf (array, value, startIndex, count);
- }
-
- public void SetValue (object? value, int index)
- {
- if (Rank != 1)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_Need1DArray);
-
- var lb = GetLowerBound (0);
- if (index < lb || index > GetUpperBound (0))
- throw new IndexOutOfRangeException ("Index has to be >= lower bound and <= upper bound of the array.");
-
- if (GetType ().GetElementType ()!.IsPointer)
- throw new NotSupportedException (SR.NotSupported_Type);
-
- SetValueImpl (value, index - lb);
- }
-
- public void SetValue (object? value, int index1, int index2)
- {
- if (Rank != 2)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_Need2DArray);
-
- int[] ind = {index1, index2};
- SetValue (value, ind);
- }
-
- public void SetValue (object? value, int index1, int index2, int index3)
- {
- if (Rank != 3)
- ThrowHelper.ThrowArgumentException (ExceptionResource.Arg_Need3DArray);
-
- int[] ind = {index1, index2, index3};
- SetValue (value, ind);
- }
-
- static bool TrySZBinarySearch (Array sourceArray, int sourceIndex, int count, object? value, out int retVal)
- {
- retVal = default;
- return false;
- }
-
- static bool TrySZIndexOf (Array sourceArray, int sourceIndex, int count, object? value, out int retVal)
- {
- retVal = default;
- return false;
- }
-
- static bool TrySZLastIndexOf (Array sourceArray, int sourceIndex, int count, object? value, out int retVal)
- {
- retVal = default;
- return false;
- }
-
- static bool TrySZReverse (Array array, int index, int count) => false;
-
- public int GetUpperBound (int dimension)
- {
- return GetLowerBound (dimension) + GetLength (dimension) - 1;
- }
-
- [Intrinsic]
- [MethodImpl (MethodImplOptions.AggressiveInlining)]
- internal ref byte GetRawSzArrayData ()
- {
- // TODO: Missing intrinsic in interpreter
- return ref Unsafe.As<RawData>(this).Data;
- }
-
- [Intrinsic]
- [MethodImpl (MethodImplOptions.AggressiveInlining)]
- internal ref byte GetRawArrayData ()
- {
- // TODO: Missing intrinsic in interpreter
- return ref Unsafe.As<RawData>(this).Data;
- }
-
- [Intrinsic]
- internal int GetElementSize () => GetElementSize ();
-
- [Intrinsic]
- public bool IsPrimitive () => IsPrimitive ();
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- internal extern CorElementType GetCorElementTypeOfElementType();
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- extern bool IsValueOfElementType(object value);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static bool CanChangePrimitive (ref Type srcType, ref Type dstType, bool reliable);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static bool FastCopy (Array source, int source_idx, Array dest, int dest_idx, int length);
-
- [Intrinsic] // when dimension is `0` constant
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern int GetLength (int dimension);
-
- [Intrinsic] // when dimension is `0` constant
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern int GetLowerBound (int dimension);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern object GetValue (params int[] indices);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern void SetValue (object? value, params int[] indices);
-
- // CAUTION! No bounds checking!
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void GetGenericValue_icall<T> (ref Array self, int pos, out T value);
-
- // CAUTION! No bounds checking!
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern object GetValueImpl (int pos);
-
- // CAUTION! No bounds checking!
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void SetGenericValue_icall<T> (ref Array self, int pos, ref T value);
-
- [Intrinsic]
- void GetGenericValueImpl<T> (int pos, out T value)
- {
- var self = this;
- GetGenericValue_icall (ref self, pos, out value);
- }
-
- [Intrinsic]
- void SetGenericValueImpl<T> (int pos, ref T value)
- {
- var self = this;
- SetGenericValue_icall (ref self, pos, ref value);
- }
-
- // CAUTION! No bounds checking!
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern void SetValueImpl (object? value, int pos);
-
- // CAUTION! No bounds checking!
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern void SetValueRelaxedImpl (object? value, int pos);
-
- /*
- * These methods are used to implement the implicit generic interfaces
- * implemented by arrays in NET 2.0.
- * Only make those methods generic which really need it, to avoid
- * creating useless instantiations.
- */
- internal int InternalArray__ICollection_get_Count ()
- {
- return Length;
- }
-
- internal bool InternalArray__ICollection_get_IsReadOnly ()
- {
- return true;
- }
-
- internal IEnumerator<T> InternalArray__IEnumerable_GetEnumerator<T> ()
- {
- return Length == 0 ? SZGenericArrayEnumerator<T>.Empty : new SZGenericArrayEnumerator<T> (Unsafe.As<T[]> (this));
- }
-
- internal void InternalArray__ICollection_Clear ()
- {
- ThrowHelper.ThrowNotSupportedException (ExceptionResource.NotSupported_ReadOnlyCollection);
- }
-
- internal void InternalArray__ICollection_Add<T> (T item)
- {
- ThrowHelper.ThrowNotSupportedException (ExceptionResource.NotSupported_FixedSizeCollection);
- }
-
- internal bool InternalArray__ICollection_Remove<T> (T item)
- {
- ThrowHelper.ThrowNotSupportedException (ExceptionResource.NotSupported_FixedSizeCollection);
- return default;
- }
-
- internal bool InternalArray__ICollection_Contains<T> (T item)
- {
- return IndexOf ((T[])this, item, 0, Length) >= 0;
- }
-
- internal void InternalArray__ICollection_CopyTo<T> (T[] array, int arrayIndex)
- {
- Copy (this, GetLowerBound (0), array, arrayIndex, Length);
- }
-
- internal T InternalArray__IReadOnlyList_get_Item<T> (int index)
- {
- if ((uint)index >= (uint)Length)
- ThrowHelper.ThrowArgumentOutOfRange_IndexException ();
-
- T value;
- // Do not change this to call GetGenericValue_icall directly, due to special casing in the runtime.
- GetGenericValueImpl (index, out value);
- return value;
- }
-
- internal int InternalArray__IReadOnlyCollection_get_Count ()
- {
- return Length;
- }
-
- internal void InternalArray__Insert<T> (int index, T item)
- {
- ThrowHelper.ThrowNotSupportedException (ExceptionResource.NotSupported_FixedSizeCollection);
- }
-
- internal void InternalArray__RemoveAt (int index)
- {
- ThrowHelper.ThrowNotSupportedException (ExceptionResource.NotSupported_FixedSizeCollection);
- }
-
- internal int InternalArray__IndexOf<T> (T item)
- {
- return IndexOf ((T[])this, item, 0, Length);
- }
-
- internal T InternalArray__get_Item<T> (int index)
- {
- if ((uint)index >= (uint)Length)
- ThrowHelper.ThrowArgumentOutOfRange_IndexException ();
-
- T value;
- // Do not change this to call GetGenericValue_icall directly, due to special casing in the runtime.
- GetGenericValueImpl (index, out value);
- return value;
- }
-
- internal void InternalArray__set_Item<T> (int index, T item)
- {
- if ((uint)index >= (uint)Length)
- ThrowHelper.ThrowArgumentOutOfRange_IndexException();
-
- if (this is object[] oarray) {
- oarray! [index] = (object)item;
- return;
- }
-
- // Do not change this to call SetGenericValue_icall directly, due to special casing in the runtime.
- SetGenericValueImpl (index, ref item);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Attribute.Mono.cs b/netcore/System.Private.CoreLib/src/System/Attribute.Mono.cs
deleted file mode 100644
index 3a67f4d1b92..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Attribute.Mono.cs
+++ /dev/null
@@ -1,62 +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.
-
-#nullable disable
-using System.Reflection;
-
-namespace System
-{
- partial class Attribute
- {
- static Attribute? GetAttr (ICustomAttributeProvider element, Type attributeType, bool inherit)
- {
- if (attributeType == null)
- throw new ArgumentNullException (nameof (attributeType));
- if (!attributeType.IsSubclassOf (typeof (Attribute)) && attributeType != typeof (Attribute) && attributeType != typeof (CustomAttribute))
- throw new ArgumentException (SR.Argument_MustHaveAttributeBaseClass + " " + attributeType.FullName);
-
- var attrs = CustomAttribute.GetCustomAttributes (element, attributeType, inherit);
- if (attrs == null || attrs.Length == 0)
- return null;
- if (attrs.Length != 1)
- throw new AmbiguousMatchException ();
- return (Attribute)(attrs [0]);
- }
-
- public static Attribute GetCustomAttribute (Assembly element, Type attributeType) => GetAttr (element, attributeType, true);
- public static Attribute GetCustomAttribute(Assembly element, Type attributeType, bool inherit) => GetAttr (element, attributeType, inherit);
- public static Attribute GetCustomAttribute(MemberInfo element, Type attributeType) => GetAttr (element, attributeType, true);
- public static Attribute GetCustomAttribute(MemberInfo element, Type attributeType, bool inherit) => GetAttr (element, attributeType, inherit);
- public static Attribute GetCustomAttribute(Module element, Type attributeType) => GetAttr (element, attributeType, true);
- public static Attribute GetCustomAttribute(Module element, Type attributeType, bool inherit) => GetAttr (element, attributeType, inherit);
- public static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType) => GetAttr (element, attributeType, true);
- public static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType, bool inherit) => GetAttr (element, attributeType, inherit);
-
- public static Attribute[] GetCustomAttributes (Assembly element) => (Attribute[])CustomAttribute.GetCustomAttributes (element, true);
- public static Attribute[] GetCustomAttributes (Assembly element, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes (element, inherit);
- public static Attribute[] GetCustomAttributes (Assembly element, Type attributeType) => (Attribute[])CustomAttribute.GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
- public static Attribute[] GetCustomAttributes (Assembly element, Type attributeType, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
- public static Attribute[] GetCustomAttributes (MemberInfo element) => (Attribute[])CustomAttribute.GetCustomAttributes (element, true);
- public static Attribute[] GetCustomAttributes (MemberInfo element, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes (element, inherit);
- public static Attribute[] GetCustomAttributes (MemberInfo element, Type attributeType) => (Attribute[])CustomAttribute.GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
- public static Attribute[] GetCustomAttributes (MemberInfo element, Type attributeType, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
- public static Attribute[] GetCustomAttributes (Module element) => (Attribute[])CustomAttribute.GetCustomAttributes (element, true);
- public static Attribute[] GetCustomAttributes (Module element, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes (element, inherit);
- public static Attribute[] GetCustomAttributes (Module element, Type attributeType) => (Attribute[])CustomAttribute.GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
- public static Attribute[] GetCustomAttributes (Module element, Type attributeType, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
- public static Attribute[] GetCustomAttributes (ParameterInfo element) => (Attribute[])CustomAttribute.GetCustomAttributes (element, true);
- public static Attribute[] GetCustomAttributes (ParameterInfo element, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes (element, inherit);
- public static Attribute[] GetCustomAttributes (ParameterInfo element, Type attributeType) => (Attribute[])CustomAttribute.GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
- public static Attribute[] GetCustomAttributes (ParameterInfo element, Type attributeType, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
-
- public static bool IsDefined (Assembly element, Type attributeType) => CustomAttribute.IsDefined ((ICustomAttributeProvider)element, attributeType, true);
- public static bool IsDefined (Assembly element, Type attributeType, bool inherit) => CustomAttribute.IsDefined ((ICustomAttributeProvider)element, attributeType, inherit);
- public static bool IsDefined (MemberInfo element, Type attributeType) => CustomAttribute.IsDefined ((ICustomAttributeProvider)element, attributeType, true);
- public static bool IsDefined (MemberInfo element, Type attributeType, bool inherit) => CustomAttribute.IsDefined ((ICustomAttributeProvider)element, attributeType, inherit);
- public static bool IsDefined (Module element, Type attributeType) => CustomAttribute.IsDefined ((ICustomAttributeProvider)element, attributeType, true);
- public static bool IsDefined (Module element, Type attributeType, bool inherit) => CustomAttribute.IsDefined ((ICustomAttributeProvider)element, attributeType, inherit);
- public static bool IsDefined (ParameterInfo element, Type attributeType) => CustomAttribute.IsDefined ((ICustomAttributeProvider)element, attributeType, true);
- public static bool IsDefined (ParameterInfo element, Type attributeType, bool inherit) => CustomAttribute.IsDefined ((ICustomAttributeProvider)element, attributeType, inherit);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Buffer.Mono.cs b/netcore/System.Private.CoreLib/src/System/Buffer.Mono.cs
deleted file mode 100644
index c22504abb11..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Buffer.Mono.cs
+++ /dev/null
@@ -1,38 +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 System.Runtime.CompilerServices;
-
-#if BIT64
-using nuint = System.UInt64;
-#else
-using nuint = System.UInt32;
-#endif
-
-namespace System
-{
- partial class Buffer
- {
- static bool IsPrimitiveTypeArray (Array array) => array.IsPrimitive ();
-
- internal static unsafe void Memcpy (byte* dest, byte* src, int len) => Memmove (dest, src, (nuint) len);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern unsafe void __Memmove (byte* dest, byte* src, nuint len);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern void BulkMoveWithWriteBarrier (ref byte dmem, ref byte smem, nuint size);
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- internal static unsafe void _ZeroMemory(ref byte b, nuint byteLength)
- {
- fixed (byte* bytePointer = &b) {
- __ZeroMemory (bytePointer, byteLength);
- }
- }
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern unsafe void __ZeroMemory (void* p, nuint byteLength);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.Mono.cs b/netcore/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.Mono.cs
deleted file mode 100644
index 238b880dcc5..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.Mono.cs
+++ /dev/null
@@ -1,16 +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.
-
-namespace System.Collections.Generic
-{
- partial class ArraySortHelper<T>
- {
- public static ArraySortHelper<T> Default { get; } = new ArraySortHelper<T>();
- }
-
- partial class ArraySortHelper<TKey, TValue>
- {
- public static ArraySortHelper<TKey, TValue> Default { get; } = new ArraySortHelper<TKey, TValue>();
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Collections/Generic/Comparer.Mono.cs b/netcore/System.Private.CoreLib/src/System/Collections/Generic/Comparer.Mono.cs
deleted file mode 100644
index 61d15e94618..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Collections/Generic/Comparer.Mono.cs
+++ /dev/null
@@ -1,50 +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 System.Runtime.CompilerServices;
-
-namespace System.Collections.Generic
-{
- partial class Comparer<T>
- {
- static volatile Comparer<T> defaultComparer;
-
- public static Comparer<T> Default {
- get {
- Comparer<T> comparer = defaultComparer;
- if (comparer == null) {
- comparer = CreateComparer();
- defaultComparer = comparer;
- }
- return comparer;
- }
- }
-
- static Comparer<T> CreateComparer() {
- RuntimeType t = (RuntimeType)typeof(T);
-
- if (typeof(IComparable<T>).IsAssignableFrom(t))
- return (Comparer<T>)RuntimeType.CreateInstanceForAnotherGenericParameter (typeof(GenericComparer<>), t);
-
- // If T is a Nullable<U> where U implements IComparable<U> return a NullableComparer<U>
- if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>)) {
- RuntimeType u = (RuntimeType)t.GetGenericArguments()[0];
- if (typeof(IComparable<>).MakeGenericType (u).IsAssignableFrom (u))
- return (Comparer<T>)RuntimeType.CreateInstanceForAnotherGenericParameter (typeof(NullableComparer<>), u);
- }
-
- if (t.IsEnum)
- return (Comparer<T>)RuntimeType.CreateInstanceForAnotherGenericParameter (typeof(EnumComparer<>), t);
-
- // Otherwise return an ObjectComparer<T>
- return new ObjectComparer<T> ();
- }
- }
-
- partial class EnumComparer<T>
- {
- [MethodImpl (MethodImplOptions.AggressiveInlining)]
- public override int Compare (T x, T y) => JitHelpers.EnumCompareTo (x, y);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.Mono.cs b/netcore/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.Mono.cs
deleted file mode 100644
index 614a9888fe8..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.Mono.cs
+++ /dev/null
@@ -1,84 +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 System.Runtime.CompilerServices;
-
-namespace System.Collections.Generic
-{
- partial class EqualityComparer<T>
- {
- static volatile EqualityComparer<T> defaultComparer;
-
- public static EqualityComparer<T> Default {
- [MethodImplAttribute (MethodImplOptions.AggressiveInlining)]
- get {
- EqualityComparer<T> comparer = defaultComparer;
- if (comparer == null) {
- comparer = CreateComparer();
- defaultComparer = comparer;
- }
- return comparer;
- }
- }
-
- static EqualityComparer<T> CreateComparer ()
- {
- RuntimeType t = (RuntimeType)typeof(T);
-
- /////////////////////////////////////////////////
- // KEEP THIS IN SYNC WITH THE DEVIRT CODE
- // IN METHOD-TO-IR.C
- /////////////////////////////////////////////////
-
- if (t == typeof(byte)) {
- return (EqualityComparer<T>)(object)(new ByteEqualityComparer());
- }
-
- if (typeof(IEquatable<T>).IsAssignableFrom(t)) {
- return (EqualityComparer<T>)RuntimeType.CreateInstanceForAnotherGenericParameter (typeof(GenericEqualityComparer<>), t);
- }
-
- if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>)) {
- RuntimeType u = (RuntimeType)t.GetGenericArguments()[0];
- if (typeof(IEquatable<>).MakeGenericType(u).IsAssignableFrom(u)) {
- return (EqualityComparer<T>)RuntimeType.CreateInstanceForAnotherGenericParameter (typeof(NullableEqualityComparer<>), u);
- }
- }
-
- if (t.IsEnum) {
- return (EqualityComparer<T>)RuntimeType.CreateInstanceForAnotherGenericParameter (typeof(EnumEqualityComparer<>), t);
- }
-
- return new ObjectEqualityComparer<T>();
- }
-
- // MONOTODO: Add specialized versions
- internal virtual int IndexOf (T[] array, T value, int startIndex, int count)
- {
- int endIndex = startIndex + count;
- for (int i = startIndex; i < endIndex; i++) {
- if (Equals (array[i], value))
- return i;
- }
- return -1;
- }
-
- internal virtual int LastIndexOf (T[] array, T value, int startIndex, int count)
- {
- int endIndex = startIndex - count + 1;
- for (int i = startIndex; i >= endIndex; i--) {
- if (Equals (array[i], value))
- return i;
- }
- return -1;
- }
-
- }
-
- partial class EnumEqualityComparer<T>
- {
- [MethodImpl (MethodImplOptions.AggressiveInlining)]
- public override bool Equals (T x, T y) => JitHelpers.EnumEquals (x, y);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs b/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs
deleted file mode 100644
index 09fec9904ae..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs
+++ /dev/null
@@ -1,525 +0,0 @@
-//
-// Authors:
-// Miguel de Icaza (miguel@ximian.com)
-// Daniel Stodden (stodden@in.tum.de)
-// Dietmar Maurer (dietmar@ximian.com)
-// Marek Safar (marek.safar@gmail.com)
-//
-// (C) Ximian, Inc. http://www.ximian.com
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-// Copyright 2014 Xamarin, Inc (http://www.xamarin.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Serialization;
-
-namespace System
-{
- /* Contains the rarely used fields of Delegate */
- sealed class DelegateData
- {
- public Type? target_type;
- public string? method_name;
- public bool curried_first_arg;
- }
-
- [StructLayout (LayoutKind.Sequential)]
- partial class Delegate
- {
- #region Sync with object-internals.h
- IntPtr method_ptr;
- IntPtr invoke_impl;
- object? _target;
- IntPtr method;
- IntPtr delegate_trampoline;
- IntPtr extra_arg;
- IntPtr method_code;
- IntPtr interp_method;
- IntPtr interp_invoke_impl;
- MethodInfo? method_info;
-
- // Keep a ref of the MethodInfo passed to CreateDelegate.
- // Used to keep DynamicMethods alive.
- MethodInfo? original_method_info;
-
- DelegateData data;
-
- bool method_is_virtual;
- #endregion
-
- protected Delegate (object target, string method)
- {
- if (target is null)
- throw new ArgumentNullException (nameof (target));
-
- if (method is null)
- throw new ArgumentNullException (nameof (method));
-
- this._target = target;
- this.data = new DelegateData () {
- method_name = method
- };
- }
-
- protected Delegate (Type target, string method)
- {
- if (target is null)
- throw new ArgumentNullException (nameof (target));
-
- if (target.ContainsGenericParameters)
- throw new ArgumentException (SR.Arg_UnboundGenParam, nameof (target));
-
- if (method is null)
- throw new ArgumentNullException (nameof (method));
-
- if (!target.IsRuntimeImplemented ())
- throw new ArgumentException (SR.Argument_MustBeRuntimeType, nameof (target));
-
- this.data = new DelegateData () {
- method_name = method,
- target_type = target
- };
- }
-
- public object? Target => GetTarget ();
-
- internal virtual object? GetTarget () => _target;
-
- public static Delegate CreateDelegate (Type type, object? firstArgument, MethodInfo method, bool throwOnBindFailure)
- {
- return CreateDelegate (type, firstArgument, method, throwOnBindFailure, true)!;
- }
-
- public static Delegate? CreateDelegate (Type type, MethodInfo method, bool throwOnBindFailure)
- {
- return CreateDelegate (type, null, method, throwOnBindFailure, false);
- }
-
- static Delegate? CreateDelegate (Type type, object? firstArgument, MethodInfo method, bool throwOnBindFailure, bool allowClosed)
- {
- if (type is null)
- throw new ArgumentNullException (nameof (type));
- if (method is null)
- throw new ArgumentNullException (nameof (method));
-
- if (!(type is RuntimeType rtType))
- throw new ArgumentException (SR.Argument_MustBeRuntimeType, nameof (type));
- if (!(method is RuntimeMethodInfo || method is System.Reflection.Emit.DynamicMethod))
- throw new ArgumentException (SR.Argument_MustBeRuntimeMethodInfo, nameof (method));
-
- if (!rtType.IsDelegate ())
- throw new ArgumentException (SR.Arg_MustBeDelegate, nameof (type));
-
- if (!IsMatchingCandidate (type, firstArgument, method, allowClosed, out DelegateData? delegate_data)) {
- if (throwOnBindFailure)
- throw new ArgumentException (SR.Arg_DlgtTargMeth);
-
- return null;
- }
-
- Delegate? d = CreateDelegate_internal (type, firstArgument, method, throwOnBindFailure);
- if (d != null) {
- d.original_method_info = method;
- d.data = delegate_data!;
- }
-
- return d;
- }
-
- public static Delegate? CreateDelegate (Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure)
- {
- if (type is null)
- throw new ArgumentNullException (nameof (type));
- if (target is null)
- throw new ArgumentNullException (nameof (target));
- if (method is null)
- throw new ArgumentNullException (nameof (method));
-
- if (!(type is RuntimeType rtType))
- throw new ArgumentException (SR.Argument_MustBeRuntimeType, nameof (type));
- if (!rtType.IsDelegate ())
- throw new ArgumentException (SR.Arg_MustBeDelegate, nameof (type));
-
- MethodInfo? info = GetCandidateMethod (type, target.GetType (), method, BindingFlags.Instance, ignoreCase);
- if (info is null) {
- if (throwOnBindFailure)
- throw new ArgumentException (SR.Arg_DlgtTargMeth);
-
- return null;
- }
-
- return CreateDelegate_internal (type, null, info, throwOnBindFailure);
- }
-
- public static Delegate? CreateDelegate (Type type, Type target, string method, bool ignoreCase, bool throwOnBindFailure)
- {
- if (type is null)
- throw new ArgumentNullException (nameof (type));
- if (target is null)
- throw new ArgumentNullException (nameof (target));
- if (target.ContainsGenericParameters)
- throw new ArgumentException (SR.Arg_UnboundGenParam, nameof (target));
- if (method is null)
- throw new ArgumentNullException (nameof (method));
-
- if (!(type is RuntimeType rtType))
- throw new ArgumentException (SR.Argument_MustBeRuntimeType, nameof (type));
-
- if (!target.IsRuntimeImplemented ())
- throw new ArgumentException (SR.Argument_MustBeRuntimeType, nameof (target));
- if (!rtType.IsDelegate ())
- throw new ArgumentException (SR.Arg_MustBeDelegate, nameof (type));
-
- MethodInfo? info = GetCandidateMethod (type, target, method, BindingFlags.Static, ignoreCase);
- if (info is null) {
- if (throwOnBindFailure)
- throw new ArgumentException (SR.Arg_DlgtTargMeth);
-
- return null;
- }
-
- return CreateDelegate_internal (type, null, info, throwOnBindFailure);
- }
-
- static MethodInfo? GetCandidateMethod (Type type, Type target, string method, BindingFlags bflags, bool ignoreCase)
- {
- MethodInfo? invoke = type.GetMethod ("Invoke");
- if (invoke is null)
- return null;
-
- ParameterInfo [] delargs = invoke.GetParametersInternal ();
- Type[] delargtypes = new Type [delargs.Length];
-
- for (int i = 0; i < delargs.Length; i++)
- delargtypes [i] = delargs [i].ParameterType;
-
- /*
- * since we need to walk the inheritance chain anyway to
- * find private methods, adjust the bindingflags to ignore
- * inherited methods
- */
- BindingFlags flags = BindingFlags.ExactBinding |
- BindingFlags.Public | BindingFlags.NonPublic |
- BindingFlags.DeclaredOnly | bflags;
-
- if (ignoreCase)
- flags |= BindingFlags.IgnoreCase;
-
- for (Type? targetType = target; targetType != null; targetType = targetType.BaseType) {
- MethodInfo? mi = targetType.GetMethod (method, flags, null, delargtypes, Array.Empty<ParameterModifier>());
-
- if (mi != null && IsReturnTypeMatch (invoke.ReturnType!, mi.ReturnType!)) {
- return mi;
- }
- }
-
- return null;
- }
-
- static bool IsMatchingCandidate (Type type, object? target, MethodInfo method, bool allowClosed, out DelegateData? delegateData)
- {
- MethodInfo? invoke = type.GetMethod ("Invoke");
-
- if (invoke == null || !IsReturnTypeMatch (invoke.ReturnType!, method.ReturnType!)) {
- delegateData = null;
- return false;
- }
-
- ParameterInfo[] delargs = invoke.GetParametersInternal ();
- ParameterInfo[] args = method.GetParametersInternal ();
-
- bool argLengthMatch;
-
- if (target != null) {
- // delegate closed over target
- if (!method.IsStatic)
- // target is passed as this
- argLengthMatch = (args.Length == delargs.Length);
- else
- // target is passed as the first argument to the static method
- argLengthMatch = (args.Length == delargs.Length + 1);
- } else {
- if (!method.IsStatic) {
- //
- // Net 2.0 feature. The first argument of the delegate is passed
- // as the 'this' argument to the method.
- //
- argLengthMatch = (args.Length + 1 == delargs.Length);
-
- if (!argLengthMatch)
- // closed over a null reference
- argLengthMatch = (args.Length == delargs.Length);
- } else {
- argLengthMatch = (args.Length == delargs.Length);
-
- if (!argLengthMatch)
- // closed over a null reference
- argLengthMatch = args.Length == delargs.Length + 1;
- }
- }
-
- if (!argLengthMatch) {
- delegateData = null;
- return false;
- }
-
- bool argsMatch;
- delegateData = new DelegateData ();
-
- if (target != null) {
- if (!method.IsStatic) {
- argsMatch = IsArgumentTypeMatchWithThis (target.GetType (), method.DeclaringType!, true);
- for (int i = 0; i < args.Length; i++)
- argsMatch &= IsArgumentTypeMatch (delargs [i].ParameterType, args [i].ParameterType);
- } else {
- argsMatch = IsArgumentTypeMatch (target.GetType (), args [0].ParameterType);
- for (int i = 1; i < args.Length; i++)
- argsMatch &= IsArgumentTypeMatch (delargs [i - 1].ParameterType, args [i].ParameterType);
-
- delegateData.curried_first_arg = true;
- }
- } else {
- if (!method.IsStatic) {
- if (args.Length + 1 == delargs.Length) {
- // The first argument should match this
- argsMatch = IsArgumentTypeMatchWithThis (delargs [0].ParameterType, method.DeclaringType!, false);
- for (int i = 0; i < args.Length; i++)
- argsMatch &= IsArgumentTypeMatch (delargs [i + 1].ParameterType, args [i].ParameterType);
- } else {
- // closed over a null reference
- argsMatch = allowClosed;
- for (int i = 0; i < args.Length; i++)
- argsMatch &= IsArgumentTypeMatch (delargs [i].ParameterType, args [i].ParameterType);
- }
- } else {
- if (delargs.Length + 1 == args.Length) {
- // closed over a null reference
- argsMatch = !(args [0].ParameterType.IsValueType || args [0].ParameterType.IsByRef) && allowClosed;
- for (int i = 0; i < delargs.Length; i++)
- argsMatch &= IsArgumentTypeMatch (delargs [i].ParameterType, args [i + 1].ParameterType);
-
- delegateData.curried_first_arg = true;
- } else {
- argsMatch = true;
- for (int i = 0; i < args.Length; i++)
- argsMatch &= IsArgumentTypeMatch (delargs [i].ParameterType, args [i].ParameterType);
- }
- }
- }
-
- return argsMatch;
- }
-
- static bool IsReturnTypeMatch (Type delReturnType, Type returnType)
- {
- bool returnMatch = returnType == delReturnType;
-
- if (!returnMatch) {
- // Delegate covariance
- if (!returnType.IsValueType && delReturnType.IsAssignableFrom (returnType))
- returnMatch = true;
- else
- {
- bool isDelArgEnum = delReturnType.IsEnum;
- bool isArgEnum = returnType.IsEnum;
- if (isArgEnum && isDelArgEnum)
- returnMatch = Enum.GetUnderlyingType (delReturnType) == Enum.GetUnderlyingType (returnType);
- else if (isDelArgEnum && Enum.GetUnderlyingType (delReturnType) == returnType)
- returnMatch = true;
- else if (isArgEnum && Enum.GetUnderlyingType (returnType) == delReturnType)
- returnMatch = true;
- }
- }
-
- return returnMatch;
- }
-
- static bool IsArgumentTypeMatch (Type delArgType, Type argType)
- {
- bool match = delArgType == argType;
-
- // Delegate contravariance
- if (!match) {
- if (!argType.IsValueType && argType.IsAssignableFrom (delArgType))
- match = true;
- }
- // enum basetypes
- if (!match) {
- if (delArgType.IsEnum && Enum.GetUnderlyingType (delArgType) == argType)
- match = true;
- else if (argType.IsEnum && Enum.GetUnderlyingType (argType) == delArgType)
- match = true;
- }
-
- return match;
- }
-
- static bool IsArgumentTypeMatchWithThis (Type delArgType, Type argType, bool boxedThis)
- {
- bool match;
- if (argType.IsValueType)
- match = delArgType.IsByRef && delArgType.GetElementType () == argType ||
- (boxedThis && delArgType == argType);
- else
- match = delArgType == argType || argType.IsAssignableFrom (delArgType);
-
- return match;
- }
-
- protected virtual object? DynamicInvokeImpl (object?[]? args)
- {
- if (Method is null) {
-#nullable disable
- // FIXME: This code cannot handle null argument values
- Type[] mtypes = new Type [args.Length];
- for (int i = 0; i < args.Length; ++i) {
- mtypes [i] = args [i].GetType ();
- }
- method_info = _target.GetType ().GetMethod (data.method_name, mtypes);
-#nullable restore
- }
-
- var target = _target;
-
- if (data is null)
- data = CreateDelegateData ();
-
- // replace all Type.Missing with default values defined on parameters of the delegate if any
- MethodInfo? invoke = GetType ().GetMethod ("Invoke");
- if (invoke != null && args != null) {
- ParameterInfo[] delegateParameters = invoke.GetParameters ();
- for (int i = 0; i < args.Length; i++) {
- if (args [i] == Type.Missing) {
- ParameterInfo dlgParam = delegateParameters [i];
- if (dlgParam.HasDefaultValue) {
- args [i] = dlgParam.DefaultValue;
- }
- }
- }
- }
-
- if (Method.IsStatic) {
- //
- // The delegate is bound to _target
- //
- if (data.curried_first_arg) {
- if (args is null) {
- args = new object?[] { target };
- } else {
- Array.Resize (ref args, args.Length + 1);
- Array.Copy (args, 0, args, 1, args.Length - 1);
- args [0] = target;
- }
-
- target = null;
- }
- } else {
- if (_target is null && args?.Length > 0) {
- target = args [0];
- Array.Copy (args, 1, args, 0, args.Length - 1);
- Array.Resize (ref args, args.Length - 1);
- }
- }
-
- return Method.Invoke (target, args);
- }
-
- public override bool Equals (object? obj)
- {
- if (!(obj is Delegate d) || !InternalEqualTypes (this, obj))
- return false;
-
- // Do not compare method_ptr, since it can point to a trampoline
- if (d._target == _target && d.Method == Method) {
- if (d.data != null || data != null) {
- /* Uncommon case */
- if (d.data != null && data != null)
- return (d.data.target_type == data.target_type && d.data.method_name == data.method_name);
- else {
- if (d.data != null)
- return d.data.target_type is null;
- if (data != null)
- return data.target_type is null;
- return false;
- }
- }
- return true;
- }
-
- return false;
- }
-
- public override int GetHashCode ()
- {
- MethodInfo? m = Method;
-
- return (m != null ? m.GetHashCode () : GetType ().GetHashCode ()) ^ RuntimeHelpers.GetHashCode (_target);
- }
-
- protected virtual MethodInfo GetMethodImpl ()
- {
- if (method_info != null)
- return method_info;
-
- if (method != IntPtr.Zero) {
- if (!method_is_virtual)
- method_info = (MethodInfo) RuntimeMethodInfo.GetMethodFromHandleNoGenericCheck (new RuntimeMethodHandle (method));
- else
- method_info = GetVirtualMethod_internal ();
- }
-
- return method_info;
- }
-
- DelegateData CreateDelegateData ()
- {
- DelegateData delegate_data = new DelegateData ();
- if (method_info.IsStatic) {
- if (_target != null) {
- delegate_data.curried_first_arg = true;
- } else {
- MethodInfo? invoke = GetType ().GetMethod ("Invoke");
- if (invoke != null && invoke.GetParametersCount () + 1 == method_info.GetParametersCount ())
- delegate_data.curried_first_arg = true;
- }
- }
-
- return delegate_data;
- }
-
- static bool InternalEqualTypes (object source, object value)
- {
- return source.GetType () == value.GetType ();
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- private protected extern static MulticastDelegate AllocDelegateLike_internal (Delegate d);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern Delegate? CreateDelegate_internal (Type type, object? target, MethodInfo info, bool throwOnBindFailure);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern MethodInfo GetVirtualMethod_internal ();
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Diagnostics/Debugger.cs b/netcore/System.Private.CoreLib/src/System/Diagnostics/Debugger.cs
deleted file mode 100644
index 1692021801c..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Diagnostics/Debugger.cs
+++ /dev/null
@@ -1,44 +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 System.Runtime.CompilerServices;
-
-namespace System.Diagnostics
-{
- public static class Debugger
- {
- public static readonly string DefaultCategory = "";
-
- public static bool IsAttached => IsAttached_internal ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static bool IsAttached_internal ();
-
- [Intrinsic]
- public static void Break ()
- {
- // The JIT inserts a breakpoint on the caller.
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public static extern bool IsLogging();
-
- public static bool Launch ()
- {
- throw new NotImplementedException ();
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern void Log_icall (int level, ref string category, ref string message);
-
- public static void Log (int level, string category, string message)
- {
- Log_icall (level, ref category, ref message);
- }
-
- public static void NotifyOfCrossThreadDependency ()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Diagnostics/StackFrame.Mono.cs b/netcore/System.Private.CoreLib/src/System/Diagnostics/StackFrame.Mono.cs
deleted file mode 100644
index 35bada2fb23..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Diagnostics/StackFrame.Mono.cs
+++ /dev/null
@@ -1,54 +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 System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace System.Diagnostics
-{
- partial class StackFrame
- {
- internal StackFrame (MonoStackFrame monoStackFrame, bool needFileInfo)
- {
- _method = monoStackFrame.methodBase;
- _nativeOffset = monoStackFrame.nativeOffset;
- _ilOffset = monoStackFrame.ilOffset;
-
- if (needFileInfo) {
- _fileName = monoStackFrame.fileName;
- _lineNumber = monoStackFrame.lineNumber;
- _columnNumber = monoStackFrame.columnNumber;
- }
-
- _isLastFrameFromForeignExceptionStackTrace = monoStackFrame.isLastFrameFromForeignException;
- }
-
- [MethodImplAttribute (MethodImplOptions.NoInlining)]
- void BuildStackFrame (int skipFrames, bool needFileInfo)
- {
- const int SystemDiagnosticsStackDepth = 3;
-
- if (skipFrames + SystemDiagnosticsStackDepth < 0 || !get_frame_info (skipFrames + SystemDiagnosticsStackDepth, needFileInfo, out var method, out var ilOffset, out var nativeOffset, out var fileName, out var line, out var column))
- return;
-
- _method = method;
- _ilOffset = ilOffset;
- _nativeOffset = nativeOffset;
-
- if (needFileInfo) {
- _fileName = fileName;
- _lineNumber = line;
- _columnNumber = column;
- }
- }
-
- bool AppendStackFrameWithoutMethodBase (StringBuilder sb) => false;
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern bool get_frame_info (int skipFrames, bool needFileInfo,
- out MethodBase method, out int ilOffset, out int nativeOffset, out string file, out int line, out int column);
-
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Diagnostics/StackTrace.Mono.cs b/netcore/System.Private.CoreLib/src/System/Diagnostics/StackTrace.Mono.cs
deleted file mode 100644
index 07d417a8c9f..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Diagnostics/StackTrace.Mono.cs
+++ /dev/null
@@ -1,86 +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 System.Collections.Generic;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Diagnostics
-{
- // Need our own stackframe class since the shared version has its own fields
- [StructLayout (LayoutKind.Sequential)]
- class MonoStackFrame
- {
- #region Keep in sync with object-internals.h
- internal int ilOffset;
- internal int nativeOffset;
- // Unused
- internal long methodAddress;
- // Unused
- internal uint methodIndex;
- internal MethodBase methodBase;
- internal string fileName;
- internal int lineNumber;
- internal int columnNumber;
- // Unused
- internal string internalMethodName;
- #endregion
-
- internal bool isLastFrameFromForeignException;
- }
-
- partial class StackTrace
- {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern MonoStackFrame[] get_trace (Exception e, int skipFrames, bool needFileInfo);
-
- [MethodImplAttribute (MethodImplOptions.NoInlining)]
- void InitializeForCurrentThread (int skipFrames, bool needFileInfo)
- {
- skipFrames += 2; // Current method + parent ctor
-
- StackFrame sf;
- var frames = new List<StackFrame> ();
- while (skipFrames >= 0) {
- sf = new StackFrame (skipFrames, needFileInfo);
- if (sf.GetMethod () == null) {
- break;
- }
- frames.Add (sf);
- skipFrames++;
- }
-
- _stackFrames = frames.ToArray ();
- _numOfFrames = _stackFrames.Length;
- }
-
- void InitializeForException (Exception e, int skipFrames, bool needFileInfo)
- {
- var frames = get_trace (e, skipFrames, needFileInfo);
- _numOfFrames = frames.Length;
-
- int foreignFrames;
- MonoStackFrame[] foreignExceptions = e.foreignExceptionsFrames;
-
- if (foreignExceptions != null) {
- foreignFrames = foreignExceptions.Length;
- _numOfFrames += foreignFrames;
-
- _stackFrames = new StackFrame [_numOfFrames];
-
- for (int i = 0; i < foreignExceptions.Length; ++i) {
- _stackFrames [i] = new StackFrame (foreignExceptions [i], needFileInfo);
- }
- } else {
- _stackFrames = new StackFrame [_numOfFrames];
- foreignFrames = 0;
- }
-
- for (int i = 0; i < frames.Length; ++i) {
- _stackFrames [foreignFrames + i] = new StackFrame (frames [i], needFileInfo);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Enum.Mono.cs b/netcore/System.Private.CoreLib/src/System/Enum.Mono.cs
deleted file mode 100644
index ec9c508fd36..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Enum.Mono.cs
+++ /dev/null
@@ -1,132 +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 System.Reflection;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- partial class Enum
- {
- internal sealed class EnumInfo
- {
- public readonly bool HasFlagsAttribute;
- public readonly ulong[] Values;
- public readonly string[] Names;
-
- // Each entry contains a list of sorted pair of enum field names and values, sorted by values
- public EnumInfo (bool hasFlagsAttribute, ulong[] values, string[] names)
- {
- HasFlagsAttribute = hasFlagsAttribute;
- Values = values;
- Names = names;
- }
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern bool InternalHasFlag (Enum flags);
-
- [Intrinsic]
- public bool HasFlag (Enum flag)
- {
- if (flag is null)
- throw new ArgumentNullException (nameof (flag));
- if (!this.GetType ().IsEquivalentTo (flag.GetType ()))
- throw new ArgumentException (SR.Format (SR.Argument_EnumTypeDoesNotMatch, flag.GetType (), this.GetType ()));
-
- return InternalHasFlag (flag);
- }
-
- public static string? GetName (Type enumType, object value)
- {
- if (enumType is null)
- throw new ArgumentNullException (nameof(enumType));
-
- return enumType.GetEnumName (value);
- }
-
- public static string[] GetNames (Type enumType)
- {
- if (enumType is null)
- throw new ArgumentNullException (nameof (enumType));
-
- return enumType.GetEnumNames ();
- }
-
- public static Type GetUnderlyingType (Type enumType)
- {
- if (enumType is null)
- throw new ArgumentNullException (nameof (enumType));
-
- return enumType.GetEnumUnderlyingType ();
- }
-
- public static Array GetValues (Type enumType)
- {
- if (enumType is null)
- throw new ArgumentNullException (nameof (enumType));
-
- return enumType.GetEnumValues ();
- }
-
- public static bool IsDefined (Type enumType, object value)
- {
- if (enumType is null)
- throw new ArgumentNullException (nameof (enumType));
-
- return enumType.IsEnumDefined (value);
- }
-
- internal static ulong[] InternalGetValues (RuntimeType enumType)
- {
- // Get all of the values
- return GetEnumInfo (enumType, false).Values;
- }
-
- internal static string[] InternalGetNames (RuntimeType enumType)
- {
- // Get all of the names
- return GetEnumInfo (enumType, true).Names;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern bool GetEnumValuesAndNames (RuntimeType enumType, out ulong[] values, out string[] names);
-
- static EnumInfo GetEnumInfo (RuntimeType enumType, bool getNames = true)
- {
- var entry = enumType.Cache.EnumInfo;
-
- if (entry == null || (getNames && entry.Names == null)) {
- if (!GetEnumValuesAndNames (enumType, out var values, out var names))
- Array.Sort (values, names, System.Collections.Generic.Comparer<ulong>.Default);
-
- bool hasFlagsAttribute = enumType.IsDefined (typeof (FlagsAttribute), inherit: false);
- entry = new EnumInfo (hasFlagsAttribute, values, names);
- enumType.Cache.EnumInfo = entry;
- }
-
- return entry;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern object InternalBoxEnum (RuntimeType enumType, long value);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern CorElementType InternalGetCorElementType ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern RuntimeType InternalGetUnderlyingType (RuntimeType enumType);
-
- static RuntimeType ValidateRuntimeType (Type enumType)
- {
- if (enumType is null)
- throw new ArgumentNullException (nameof (enumType));
- if (!enumType.IsEnum)
- throw new ArgumentException (SR.Arg_MustBeEnum, nameof (enumType));
- if (!(enumType is RuntimeType rtType))
- throw new ArgumentException (SR.Arg_MustBeType, nameof (enumType));
- return rtType;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Environment.Mono.in b/netcore/System.Private.CoreLib/src/System/Environment.Mono.in
deleted file mode 100644
index dd4c3eed22c..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Environment.Mono.in
+++ /dev/null
@@ -1,84 +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 System.Collections;
-using System.Globalization;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Threading;
-
-namespace System
-{
- partial class Environment
- {
- const string mono_corlib_version = "@MONO_CORLIB_VERSION@";
-
- public static int CurrentManagedThreadId => Thread.CurrentThread.ManagedThreadId;
-
- public extern static int ExitCode {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- get;
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- set;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern int GetProcessorCount ();
-
- public static string StackTrace {
- [MethodImpl (MethodImplOptions.NoInlining)] // Prevent inlining from affecting where the stacktrace starts
- get => new StackTrace (true).ToString (System.Diagnostics.StackTrace.TraceFormat.Normal);
- }
-
- public extern static int TickCount {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- get;
- }
-
- public extern static long TickCount64 {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- get;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void Exit (int exitCode);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static string[] GetCommandLineArgs ();
-
- public static void FailFast (string message)
- {
- FailFast (message, null, null);
- }
-
- public static void FailFast(string message, Exception exception)
- {
- FailFast (message, exception, null);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void FailFast (string message, Exception exception, string errorSource);
- }
-
-#region referencesource dependencies - to be removed
-
- partial class Environment
- {
- internal static string GetResourceString (string key)
- {
- return key;
- }
-
- internal static string GetResourceString (string key, CultureInfo culture)
- {
- return key;
- }
-
- internal static string GetResourceString (string key, params object[] values)
- {
- return string.Format (CultureInfo.InvariantCulture, key, values);
- }
- }
-#endregion
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Environment.Unix.Mono.cs b/netcore/System.Private.CoreLib/src/System/Environment.Unix.Mono.cs
deleted file mode 100644
index 6b186fd13cd..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Environment.Unix.Mono.cs
+++ /dev/null
@@ -1,103 +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 System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Threading;
-using Mono;
-
-namespace System
-{
- partial class Environment
- {
- private static Dictionary<string, string> s_environment;
-
- static string GetEnvironmentVariableCore (string variable)
- {
- Debug.Assert(variable != null);
-
- if (s_environment == null) {
- using (var h = RuntimeMarshal.MarshalString (variable)) {
- return internalGetEnvironmentVariable_native (h.Value);
- }
- }
-
- variable = TrimStringOnFirstZero (variable);
- lock (s_environment) {
- s_environment.TryGetValue (variable, out string value);
- return value;
- }
- }
-
- static unsafe void SetEnvironmentVariableCore (string variable, string? value)
- {
- Debug.Assert(variable != null);
-
- EnsureEnvironmentCached ();
- lock (s_environment) {
- variable = TrimStringOnFirstZero (variable);
- value = value == null ? null : TrimStringOnFirstZero (value);
- if (string.IsNullOrEmpty (value)) {
- s_environment.Remove (variable);
- } else {
- s_environment[variable] = value;
- }
- }
- }
-
- public static IDictionary GetEnvironmentVariables ()
- {
- var results = new Hashtable();
-
- EnsureEnvironmentCached();
- lock (s_environment) {
- foreach (var keyValuePair in s_environment) {
- results.Add(keyValuePair.Key, keyValuePair.Value);
- }
- }
-
- return results;
- }
-
- private static string TrimStringOnFirstZero (string value)
- {
- int index = value.IndexOf ('\0');
- if (index >= 0) {
- return value.Substring (0, index);
- }
- return value;
- }
-
- private static void EnsureEnvironmentCached ()
- {
- if (s_environment == null) {
- Interlocked.CompareExchange (ref s_environment, GetSystemEnvironmentVariables (), null);
- }
- }
-
- private static Dictionary<string, string> GetSystemEnvironmentVariables ()
- {
- var results = new Dictionary<string, string>();
-
- foreach (string name in GetEnvironmentVariableNames ()) {
- if (name != null) {
- using (var h = RuntimeMarshal.MarshalString (name)) {
- results.Add (name, internalGetEnvironmentVariable_native (h.Value));
- }
- }
- }
-
- return results;
- }
-
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static string internalGetEnvironmentVariable_native (IntPtr variable);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- private extern static string [] GetEnvironmentVariableNames ();
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Exception.Mono.cs b/netcore/System.Private.CoreLib/src/System/Exception.Mono.cs
deleted file mode 100644
index 9d1f9a402cb..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Exception.Mono.cs
+++ /dev/null
@@ -1,146 +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 System.Collections;
-using System.Reflection;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System
-{
- [StructLayout (LayoutKind.Sequential)]
- partial class Exception
- {
- internal readonly struct DispatchState
- {
- public readonly MonoStackFrame[] StackFrames;
-
- public DispatchState (MonoStackFrame[] stackFrames)
- {
- StackFrames = stackFrames;
- }
- }
-
- # region Keep in sync with MonoException in object-internals.h
- string? _unused1;
- internal string _message;
- IDictionary _data;
- Exception _innerException;
- string _helpURL;
- object _traceIPs;
- string? _stackTraceString;
- string? _remoteStackTraceString;
- int _unused4;
- object _dynamicMethods; // Dynamic methods referenced by the stack trace
- int _HResult;
- string _source;
- object? _unused6;
- internal MonoStackFrame[] foreignExceptionsFrames;
- IntPtr[] native_trace_ips;
- int caught_in_unmanaged;
- #endregion
-
- public MethodBase? TargetSite {
- get {
- StackTrace st = new StackTrace (this, true);
- if (st.FrameCount > 0)
- return st.GetFrame (0)?.GetMethod ();
-
- return null;
- }
- }
-
- public virtual string? StackTrace => GetStackTrace (true);
-
- string? GetStackTrace (bool needFileInfo)
- {
- string? stackTraceString = _stackTraceString;
- string? remoteStackTraceString = _remoteStackTraceString;
-
- if (stackTraceString != null)
- return remoteStackTraceString + stackTraceString;
- if (_traceIPs == null)
- return remoteStackTraceString;
-
- return remoteStackTraceString + new StackTrace (this, needFileInfo).ToString (System.Diagnostics.StackTrace.TraceFormat.Normal);
- }
-
- internal DispatchState CaptureDispatchState ()
- {
- MonoStackFrame[] stackFrames;
-
- if (_traceIPs != null) {
- stackFrames = System.Diagnostics.StackTrace.get_trace (this, 0, true);
- stackFrames [stackFrames.Length - 1].isLastFrameFromForeignException = true;
-
- if (foreignExceptionsFrames != null) {
- var combinedStackFrames = new MonoStackFrame [stackFrames.Length + foreignExceptionsFrames.Length];
- Array.Copy (foreignExceptionsFrames, 0, combinedStackFrames, 0, foreignExceptionsFrames.Length);
- Array.Copy (stackFrames, 0, combinedStackFrames, foreignExceptionsFrames.Length, stackFrames.Length);
-
- stackFrames = combinedStackFrames;
- }
- } else {
- stackFrames = foreignExceptionsFrames;
- }
-
- return new DispatchState (stackFrames);
- }
-
- internal void RestoreDispatchState (in DispatchState state)
- {
- foreignExceptionsFrames = state.StackFrames;
-
- _stackTraceString = null;
- }
-
- [StackTraceHidden]
- internal void SetCurrentStackTrace ()
- {
- // Check to see if the exception already has a stack set in it.
- if (_traceIPs != null || _stackTraceString != null || _remoteStackTraceString != null) {
- ThrowHelper.ThrowInvalidOperationException ();
- }
-
- // Store the current stack trace into the "remote" stack trace, which was originally introduced to support
- // remoting of exceptions cross app-domain boundaries, and is thus concatenated into Exception.StackTrace
- // when it's retrieved.
- var sb = new StringBuilder (256);
- new StackTrace (fNeedFileInfo: true).ToString (System.Diagnostics.StackTrace.TraceFormat.TrailingNewLine, sb);
- sb.AppendLine (SR.Exception_EndStackTraceFromPreviousThrow);
- _remoteStackTraceString = sb.ToString ();
- }
-
- string? CreateSourceName ()
- {
- var st = new StackTrace (this, fNeedFileInfo: false);
- if (st.FrameCount > 0) {
- StackFrame sf = st.GetFrame (0)!;
- MethodBase method = sf.GetMethod ();
-
- Module module = method.Module;
- RuntimeModule rtModule = module as RuntimeModule;
-
- if (rtModule == null) {
- var moduleBuilder = module as System.Reflection.Emit.ModuleBuilder;
- if (moduleBuilder != null)
- throw new NotImplementedException (); // TODO: rtModule = moduleBuilder.InternalModule;
- else
- throw new ArgumentException (SR.Argument_MustBeRuntimeReflectionObject);
- }
-
- return rtModule.GetRuntimeAssembly ().GetName ().Name; // TODO: GetSimpleName ();
- }
-
- return null;
- }
-
- static IDictionary CreateDataContainer () => new ListDictionaryInternal ();
-
- static string? SerializationWatsonBuckets => null;
- string? SerializationRemoteStackTraceString => _remoteStackTraceString;
- string? SerializationStackTraceString => GetStackTrace (true);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/GC.Mono.cs b/netcore/System.Private.CoreLib/src/System/GC.Mono.cs
deleted file mode 100644
index e5efe52cc40..00000000000
--- a/netcore/System.Private.CoreLib/src/System/GC.Mono.cs
+++ /dev/null
@@ -1,268 +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 System.Runtime.CompilerServices;
-using System.Diagnostics;
-
-namespace System
-{
- public enum GCCollectionMode
- {
- Default = 0,
- Forced = 1,
- Optimized = 2
- }
-
- public enum GCNotificationStatus
- {
- Succeeded = 0,
- Failed = 1,
- Canceled = 2,
- Timeout = 3,
- NotApplicable = 4
- }
-
- public static partial class GC
- {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static int GetCollectionCount (int generation);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static int GetMaxGeneration ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void InternalCollect (int generation);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void RecordPressure (long bytesAllocated);
-
- // TODO: Move following to ConditionalWeakTable
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static void register_ephemeron_array (Ephemeron[] array);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static object get_ephemeron_tombstone ();
-
- internal static readonly object EPHEMERON_TOMBSTONE = get_ephemeron_tombstone ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public static extern long GetAllocatedBytesForCurrentThread ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public static extern long GetTotalAllocatedBytes (bool precise = false);
-
- public static void AddMemoryPressure (long bytesAllocated)
- {
- if (bytesAllocated <= 0)
- throw new ArgumentOutOfRangeException (nameof (bytesAllocated), SR.ArgumentOutOfRange_NeedPosNum);
- if (IntPtr.Size == 4 && bytesAllocated > Int32.MaxValue)
- throw new ArgumentOutOfRangeException (nameof (bytesAllocated), SR.ArgumentOutOfRange_MustBeNonNegInt32);
- RecordPressure (bytesAllocated);
- }
-
- public static void RemoveMemoryPressure (long bytesAllocated)
- {
- if (bytesAllocated <= 0)
- throw new ArgumentOutOfRangeException (nameof (bytesAllocated), SR.ArgumentOutOfRange_NeedPosNum);
- if (IntPtr.Size == 4 && bytesAllocated > Int32.MaxValue)
- throw new ArgumentOutOfRangeException (nameof (bytesAllocated), SR.ArgumentOutOfRange_MustBeNonNegInt32);
- RecordPressure (-bytesAllocated);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public static extern int GetGeneration (object obj);
-
- public static void Collect (int generation)
- {
- Collect (generation, GCCollectionMode.Default);
- }
-
- public static void Collect ()
- {
- InternalCollect (MaxGeneration);
- }
-
- public static void Collect (int generation, GCCollectionMode mode) => Collect (generation, mode, true);
-
- public static void Collect (int generation, GCCollectionMode mode, bool blocking) => Collect (generation, mode, blocking, false);
-
- public static void Collect (int generation, GCCollectionMode mode, bool blocking, bool compacting)
- {
- if (generation < 0)
- throw new ArgumentOutOfRangeException (nameof (generation), "generation", SR.ArgumentOutOfRange_GenericPositive);
- if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized))
- throw new ArgumentOutOfRangeException (nameof (mode), SR.ArgumentOutOfRange_Enum);
-
- InternalCollect (generation);
- }
-
- public static int CollectionCount (int generation)
- {
- if (generation < 0)
- throw new ArgumentOutOfRangeException (nameof (generation), SR.ArgumentOutOfRange_GenericPositive);
- return GetCollectionCount (generation);
- }
-
- [MethodImplAttribute (MethodImplOptions.NoInlining)] // disable optimizations
- public static void KeepAlive (object obj)
- {
- }
-
- public static int GetGeneration (WeakReference wo)
- {
- object obj = wo.Target;
- if (obj == null)
- throw new ArgumentException ();
- return GetGeneration (obj);
- }
-
- public static int MaxGeneration {
- get {
- return GetMaxGeneration ();
- }
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public static extern void WaitForPendingFinalizers ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern void _SuppressFinalize (object o);
-
- public static void SuppressFinalize (object obj)
- {
- if (obj == null)
- throw new ArgumentNullException (nameof (obj));
- _SuppressFinalize (obj);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern void _ReRegisterForFinalize (object o);
-
- public static void ReRegisterForFinalize (object obj)
- {
- if (obj == null)
- throw new ArgumentNullException (nameof (obj));
- _ReRegisterForFinalize (obj);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static long GetTotalMemory (bool forceFullCollection);
-
- static bool _RegisterForFullGCNotification (int maxGenerationPercentage, int largeObjectHeapPercentage)
- {
- throw new NotImplementedException ();
- }
-
- static bool _CancelFullGCNotification ()
- {
- throw new NotImplementedException ();
- }
-
- static GCNotificationStatus _WaitForFullGCApproach (int millisecondsTimeout)
- {
- throw new NotImplementedException ();
- }
-
- static GCNotificationStatus _WaitForFullGCComplete (int millisecondsTimeout)
- {
- throw new NotImplementedException ();
- }
-
- public static void RegisterForFullGCNotification (int maxGenerationThreshold, int largeObjectHeapThreshold)
- {
- if ((maxGenerationThreshold <= 0) || (maxGenerationThreshold >= 100))
- throw new ArgumentOutOfRangeException (nameof (maxGenerationThreshold),
- SR.Format (SR.ArgumentOutOfRange_Bounds_Lower_Upper, 1, 99));
- if ((largeObjectHeapThreshold <= 0) || (largeObjectHeapThreshold >= 100))
- throw new ArgumentOutOfRangeException (nameof (largeObjectHeapThreshold),
- SR.Format (SR.ArgumentOutOfRange_Bounds_Lower_Upper, 1, 99));
-
- if (!_RegisterForFullGCNotification (maxGenerationThreshold, largeObjectHeapThreshold))
- throw new InvalidOperationException (SR.InvalidOperation_NotWithConcurrentGC);
- }
-
- public static void CancelFullGCNotification ()
- {
- if (!_CancelFullGCNotification ())
- throw new InvalidOperationException (SR.InvalidOperation_NotWithConcurrentGC);
- }
-
- public static GCNotificationStatus WaitForFullGCApproach ()
- {
- return (GCNotificationStatus) _WaitForFullGCApproach (-1);
- }
-
- public static GCNotificationStatus WaitForFullGCApproach (int millisecondsTimeout)
- {
- if (millisecondsTimeout < -1)
- throw new ArgumentOutOfRangeException (nameof (millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
-
- return _WaitForFullGCApproach (millisecondsTimeout);
- }
-
- public static GCNotificationStatus WaitForFullGCComplete ()
- {
- return _WaitForFullGCComplete (-1);
- }
-
- public static GCNotificationStatus WaitForFullGCComplete (int millisecondsTimeout)
- {
- if (millisecondsTimeout < -1)
- throw new ArgumentOutOfRangeException (nameof (millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- return _WaitForFullGCComplete (millisecondsTimeout);
- }
-
- static bool StartNoGCRegion (long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC)
- {
- throw new NotImplementedException ();
- }
-
- public static bool TryStartNoGCRegion (long totalSize) => StartNoGCRegion (totalSize, false, 0, false);
-
- public static bool TryStartNoGCRegion (long totalSize, long lohSize) => StartNoGCRegion (totalSize, true, lohSize, false);
-
- public static bool TryStartNoGCRegion (long totalSize, bool disallowFullBlockingGC) => StartNoGCRegion (totalSize, false, 0, disallowFullBlockingGC);
-
- public static bool TryStartNoGCRegion (long totalSize, long lohSize, bool disallowFullBlockingGC) => StartNoGCRegion (totalSize, true, lohSize, disallowFullBlockingGC);
-
- public static void EndNoGCRegion ()
- {
- throw new NotImplementedException ();
- }
-
- internal static ulong GetSegmentSize ()
- {
- // coreclr default
- return 1024 * 1024 * 16;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern void _GetGCMemoryInfo (out long highMemoryLoadThresholdBytes,
- out long memoryLoadBytes,
- out long totalAvailableMemoryBytes,
- out long heapSizeBytes,
- out long fragmentedBytes);
-
- public static GCMemoryInfo GetGCMemoryInfo ()
- {
- _GetGCMemoryInfo(out long highMemoryLoadThresholdBytes,
- out long memoryLoadBytes,
- out long totalAvailableMemoryBytes,
- out long heapSizeBytes,
- out long fragmentedBytes );
-
- return new GCMemoryInfo(highMemoryLoadThresholdBytes, memoryLoadBytes, totalAvailableMemoryBytes, heapSizeBytes, fragmentedBytes);
- }
-
- internal static T[] AllocateUninitializedArray<T> (int length)
- {
- // Mono only does explicit zeroning if the array is to big for the nursery, but less than 1 Mb - 4 kb.
- // If it is bigger than that, we grab memoroy directly from the OS which comes pre-zeroed.
- // Experimentation shows that if we just skip the zeroing in this case, we do not save a measurable
- // amount of time. So we just allocate the normal way here.
- // Revist if we change LOS implementation.
- return new T [length];
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs b/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs
deleted file mode 100644
index 58b99e0ccc6..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Mono.cs
+++ /dev/null
@@ -1,20 +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 System.Runtime.CompilerServices;
-
-namespace System.Globalization
-{
- internal static partial class GlobalizationMode
- {
- internal static bool Invariant { get; } = GetGlobalizationInvariantMode ();
-
- static bool GetInvariantSwitchValue ()
- {
- var val = Environment.GetEnvironmentVariable ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT");
- if (val != null)
- return Boolean.IsTrueStringIgnoreCase (val) || val.Equals ("1");
- return false;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.Mono.cs b/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.Mono.cs
deleted file mode 100644
index bdf132ea933..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.Mono.cs
+++ /dev/null
@@ -1,33 +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 System.Runtime.CompilerServices;
-
-namespace System.Globalization
-{
- partial class GlobalizationMode
- {
- static bool GetGlobalizationInvariantMode ()
- {
- bool invariantEnabled = GetInvariantSwitchValue ();
- if (invariantEnabled)
- return true;
-
- LoadICU ();
- return false;
- }
-
- // Keep this in a separate method to avoid loading the native lib in invariant mode
- [MethodImplAttribute (MethodImplOptions.NoInlining)]
- static void LoadICU ()
- {
- int res = Interop.Globalization.LoadICU ();
- if (res == 0) {
- string message = "Couldn't find a valid ICU package installed on the system. " +
- "Set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support.";
- Environment.FailFast (message);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Windows.Mono.cs b/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Windows.Mono.cs
deleted file mode 100644
index 26261423358..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Windows.Mono.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Globalization
-{
- partial class GlobalizationMode
- {
- static bool GetGlobalizationInvariantMode () {
- return GetInvariantSwitchValue ();
- }
- }
-} \ No newline at end of file
diff --git a/netcore/System.Private.CoreLib/src/System/IO/FileLoadException.Mono.cs b/netcore/System.Private.CoreLib/src/System/IO/FileLoadException.Mono.cs
deleted file mode 100644
index 0ec54d3b998..00000000000
--- a/netcore/System.Private.CoreLib/src/System/IO/FileLoadException.Mono.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System.IO
-{
- partial class FileLoadException
- {
- internal static string FormatFileLoadExceptionMessage (string fileName, int hResult)
- {
- return "";
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/IO/MonoIOError.cs b/netcore/System.Private.CoreLib/src/System/IO/MonoIOError.cs
deleted file mode 100644
index eec82154854..00000000000
--- a/netcore/System.Private.CoreLib/src/System/IO/MonoIOError.cs
+++ /dev/null
@@ -1,1827 +0,0 @@
-//
-// System.IO.MonoIOError.cs: Win32 error codes. Yuck.
-//
-// Author:
-// Dan Lewis (dihlewis@yahoo.co.uk)
-//
-// (C) 2002
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-
-namespace System.IO
-{
- internal enum MonoIOError: int {
- ERROR_SUCCESS = 0,
- /* ERROR_INVALID_FUNCTION = 1,
- */ ERROR_FILE_NOT_FOUND = 2,
- ERROR_PATH_NOT_FOUND = 3,
- ERROR_TOO_MANY_OPEN_FILES = 4,
- ERROR_ACCESS_DENIED = 5,
- ERROR_INVALID_HANDLE = 6,
- /* ERROR_ARENA_TRASHED = 7,
- ERROR_NOT_ENOUGH_MEMORY = 8,
- ERROR_INVALID_BLOCK = 9,
- ERROR_BAD_ENVIRONMENT = 10,
- ERROR_BAD_FORMAT = 11,
- ERROR_INVALID_ACCESS = 12,
- ERROR_INVALID_DATA = 13,
- ERROR_OUTOFMEMORY = 14,
- */ ERROR_INVALID_DRIVE = 15,
- /* ERROR_CURRENT_DIRECTORY = 16,
- */ ERROR_NOT_SAME_DEVICE = 17,
- ERROR_NO_MORE_FILES = 18,
- /* ERROR_WRITE_PROTECT = 19,
- ERROR_BAD_UNIT = 20,
- */
- ERROR_NOT_READY = 21,
- /*
- ERROR_BAD_COMMAND = 22,
- ERROR_CRC = 23,
- ERROR_BAD_LENGTH = 24,
- ERROR_SEEK = 25,
- ERROR_NOT_DOS_DISK = 26,
- ERROR_SECTOR_NOT_FOUND = 27,
- ERROR_OUT_OF_PAPER = 28,*/
- ERROR_WRITE_FAULT = 29,
- ERROR_READ_FAULT = 30,
- ERROR_GEN_FAILURE = 31,
- ERROR_SHARING_VIOLATION = 32,
- ERROR_LOCK_VIOLATION = 33,
- /* ERROR_WRONG_DISK = 34,
- ERROR_SHARING_BUFFER_EXCEEDED = 36,
- ERROR_HANDLE_EOF = 38,
- */ ERROR_HANDLE_DISK_FULL = 39,
- ERROR_NOT_SUPPORTED = 50,
- /* ERROR_REM_NOT_LIST = 51,
- ERROR_DUP_NAME = 52,
- ERROR_BAD_NETPATH = 53,
- ERROR_NETWORK_BUSY = 54,
- ERROR_DEV_NOT_EXIST = 55,
- ERROR_TOO_MANY_CMDS = 56,
- ERROR_ADAP_HDW_ERR = 57,
- ERROR_BAD_NET_RESP = 58,
- ERROR_UNEXP_NET_ERR = 59,
- ERROR_BAD_REM_ADAP = 60,
- ERROR_PRINTQ_FULL = 61,
- ERROR_NO_SPOOL_SPACE = 62,
- ERROR_PRINT_CANCELLED = 63,
- ERROR_NETNAME_DELETED = 64,
- ERROR_NETWORK_ACCESS_DENIED = 65,
- ERROR_BAD_DEV_TYPE = 66,
- ERROR_BAD_NET_NAME = 67,
- ERROR_TOO_MANY_NAMES = 68,
- ERROR_TOO_MANY_SESS = 69,
- ERROR_SHARING_PAUSED = 70,
- ERROR_REQ_NOT_ACCEP = 71,
- ERROR_REDIR_PAUSED = 72,
- */ ERROR_FILE_EXISTS = 80,
- ERROR_CANNOT_MAKE = 82,
- /* ERROR_FAIL_I24 = 83,
- ERROR_OUT_OF_STRUCTURES = 84,
- ERROR_ALREADY_ASSIGNED = 85,
- ERROR_INVALID_PASSWORD = 86,
- */ ERROR_INVALID_PARAMETER = 87,
- /* ERROR_NET_WRITE_FAULT = 88,
- ERROR_NO_PROC_SLOTS = 89,
- ERROR_TOO_MANY_SEMAPHORES = 100,
- ERROR_EXCL_SEM_ALREADY_OWNED = 101,
- ERROR_SEM_IS_SET = 102,
- ERROR_TOO_MANY_SEM_REQUESTS = 103,
- ERROR_INVALID_AT_INTERRUPT_TIME = 104,
- ERROR_SEM_OWNER_DIED = 105,
- ERROR_SEM_USER_LIMIT = 106,
- ERROR_DISK_CHANGE = 107,
- ERROR_DRIVE_LOCKED = 108,
- */ ERROR_BROKEN_PIPE = 109,
- /* ERROR_OPEN_FAILED = 110,
- ERROR_BUFFER_OVERFLOW = 111,
- ERROR_DISK_FULL = 112,
- ERROR_NO_MORE_SEARCH_HANDLES = 113,
- ERROR_INVALID_TARGET_HANDLE = 114,
- ERROR_INVALID_CATEGORY = 117,
- ERROR_INVALID_VERIFY_SWITCH = 118,
- ERROR_BAD_DRIVER_LEVEL = 119,
- ERROR_CALL_NOT_IMPLEMENTED = 120,
- ERROR_SEM_TIMEOUT = 121,
- ERROR_INSUFFICIENT_BUFFER = 122,
- */ ERROR_INVALID_NAME = 123,
- /* ERROR_INVALID_LEVEL = 124,
- ERROR_NO_VOLUME_LABEL = 125,
- ERROR_MOD_NOT_FOUND = 126,
- ERROR_PROC_NOT_FOUND = 127,
- ERROR_WAIT_NO_CHILDREN = 128,
- ERROR_CHILD_NOT_COMPLETE = 129,
- ERROR_DIRECT_ACCESS_HANDLE = 130,
- ERROR_NEGATIVE_SEEK = 131,
- ERROR_SEEK_ON_DEVICE = 132,
- ERROR_IS_JOIN_TARGET = 133,
- ERROR_IS_JOINED = 134,
- ERROR_IS_SUBSTED = 135,
- ERROR_NOT_JOINED = 136,
- ERROR_NOT_SUBSTED = 137,
- ERROR_JOIN_TO_JOIN = 138,
- ERROR_SUBST_TO_SUBST = 139,
- ERROR_JOIN_TO_SUBST = 140,
- ERROR_SUBST_TO_JOIN = 141,
- ERROR_BUSY_DRIVE = 142,
- ERROR_SAME_DRIVE = 143,
- ERROR_DIR_NOT_ROOT = 144,
- */
- ERROR_DIR_NOT_EMPTY = 145,
- /*
- ERROR_IS_SUBST_PATH = 146,
- ERROR_IS_JOIN_PATH = 147,
- ERROR_PATH_BUSY = 148,
- ERROR_IS_SUBST_TARGET = 149,
- ERROR_SYSTEM_TRACE = 150,
- ERROR_INVALID_EVENT_COUNT = 151,
- ERROR_TOO_MANY_MUXWAITERS = 152,
- ERROR_INVALID_LIST_FORMAT = 153,
- ERROR_LABEL_TOO_LONG = 154,
- ERROR_TOO_MANY_TCBS = 155,
- ERROR_SIGNAL_REFUSED = 156,
- ERROR_DISCARDED = 157,
- ERROR_NOT_LOCKED = 158,
- ERROR_BAD_THREADID_ADDR = 159,
- ERROR_BAD_ARGUMENTS = 160,
- ERROR_BAD_PATHNAME = 161,
- ERROR_SIGNAL_PENDING = 162,
- ERROR_MAX_THRDS_REACHED = 164,
- ERROR_LOCK_FAILED = 167,
- ERROR_BUSY = 170,
- ERROR_CANCEL_VIOLATION = 173,
- ERROR_ATOMIC_LOCKS_NOT_SUPPORTED = 174,
- ERROR_INVALID_SEGMENT_NUMBER = 180,
- ERROR_INVALID_ORDINAL = 182,
- */ ERROR_ALREADY_EXISTS = 183,
- /* ERROR_INVALID_FLAG_NUMBER = 186,
- ERROR_SEM_NOT_FOUND = 187,
- ERROR_INVALID_STARTING_CODESEG = 188,
- ERROR_INVALID_STACKSEG = 189,
- ERROR_INVALID_MODULETYPE = 190,
- ERROR_INVALID_EXE_SIGNATURE = 191,
- ERROR_EXE_MARKED_INVALID = 192,
- ERROR_BAD_EXE_FORMAT = 193,
- ERROR_ITERATED_DATA_EXCEEDS_64k = 194,
- ERROR_INVALID_MINALLOCSIZE = 195,
- ERROR_DYNLINK_FROM_INVALID_RING = 196,
- ERROR_IOPL_NOT_ENABLED = 197,
- ERROR_INVALID_SEGDPL = 198,
- ERROR_AUTODATASEG_EXCEEDS_64k = 199,
- ERROR_RING2SEG_MUST_BE_MOVABLE = 200,
- ERROR_RELOC_CHAIN_XEEDS_SEGLIM = 201,
- ERROR_INFLOOP_IN_RELOC_CHAIN = 202,
- ERROR_ENVVAR_NOT_FOUND = 203,
- ERROR_NO_SIGNAL_SENT = 205,
- */ ERROR_FILENAME_EXCED_RANGE = 206,
- /* ERROR_RING2_STACK_IN_USE = 207,
- ERROR_META_EXPANSION_TOO_LONG = 208,
- ERROR_INVALID_SIGNAL_NUMBER = 209,
- ERROR_THREAD_1_INACTIVE = 210,
- ERROR_LOCKED = 212,
- ERROR_TOO_MANY_MODULES = 214,
- ERROR_NESTING_NOT_ALLOWED = 215,
- ERROR_EXE_MACHINE_TYPE_MISMATCH = 216,
- ERROR_BAD_PIPE = 230,
- ERROR_PIPE_BUSY = 231,
- ERROR_NO_DATA = 232,
- ERROR_PIPE_NOT_CONNECTED = 233,
- ERROR_MORE_DATA = 234,
- ERROR_VC_DISCONNECTED = 240,
- ERROR_INVALID_EA_NAME = 254,
- ERROR_EA_LIST_INCONSISTENT = 255,
- WAIT_TIMEOUT = 258,
- ERROR_NO_MORE_ITEMS = 259,
- ERROR_CANNOT_COPY = 266,
- */ ERROR_DIRECTORY = 267,
- /* ERROR_EAS_DIDNT_FIT = 275,
- ERROR_EA_FILE_CORRUPT = 276,
- ERROR_EA_TABLE_FULL = 277,
- ERROR_INVALID_EA_HANDLE = 278,
- ERROR_EAS_NOT_SUPPORTED = 282,
- ERROR_NOT_OWNER = 288,
- ERROR_TOO_MANY_POSTS = 298,
- ERROR_PARTIAL_COPY = 299,
- ERROR_OPLOCK_NOT_GRANTED = 300,
- ERROR_INVALID_OPLOCK_PROTOCOL = 301,
- ERROR_DISK_TOO_FRAGMENTED = 302,
- ERROR_DELETE_PENDING = 303,
- ERROR_MR_MID_NOT_FOUND = 317,
- ERROR_INVALID_ADDRESS = 487,
- ERROR_ARITHMETIC_OVERFLOW = 534,
- ERROR_PIPE_CONNECTED = 535,
- ERROR_PIPE_LISTENING = 536,
- ERROR_EA_ACCESS_DENIED = 994,
- ERROR_OPERATION_ABORTED = 995,
- ERROR_IO_INCOMPLETE = 996,
- ERROR_IO_PENDING = 997,
- ERROR_NOACCESS = 998,
- ERROR_SWAPERROR = 999,
- ERROR_STACK_OVERFLOW = 1001,
- ERROR_INVALID_MESSAGE = 1002,
- ERROR_CAN_NOT_COMPLETE = 1003,
- ERROR_INVALID_FLAGS = 1004,
- ERROR_UNRECOGNIZED_VOLUME = 1005,
- ERROR_FILE_INVALID = 1006,
- ERROR_FULLSCREEN_MODE = 1007,
- ERROR_NO_TOKEN = 1008,
- ERROR_BADDB = 1009,
- ERROR_BADKEY = 1010,
- ERROR_CANTOPEN = 1011,
- ERROR_CANTREAD = 1012,
- ERROR_CANTWRITE = 1013,
- ERROR_REGISTRY_RECOVERED = 1014,
- ERROR_REGISTRY_CORRUPT = 1015,
- ERROR_REGISTRY_IO_FAILED = 1016,
- ERROR_NOT_REGISTRY_FILE = 1017,
- ERROR_KEY_DELETED = 1018,
- ERROR_NO_LOG_SPACE = 1019,
- ERROR_KEY_HAS_CHILDREN = 1020,
- ERROR_CHILD_MUST_BE_VOLATILE = 1021,
- ERROR_NOTIFY_ENUM_DIR = 1022,
- ERROR_DEPENDENT_SERVICES_RUNNING = 1051,
- ERROR_INVALID_SERVICE_CONTROL = 1052,
- ERROR_SERVICE_REQUEST_TIMEOUT = 1053,
- ERROR_SERVICE_NO_THREAD = 1054,
- ERROR_SERVICE_DATABASE_LOCKED = 1055,
- ERROR_SERVICE_ALREADY_RUNNING = 1056,
- ERROR_INVALID_SERVICE_ACCOUNT = 1057,
- ERROR_SERVICE_DISABLED = 1058,
- ERROR_CIRCULAR_DEPENDENCY = 1059,
- ERROR_SERVICE_DOES_NOT_EXIST = 1060,
- ERROR_SERVICE_CANNOT_ACCEPT_CTRL = 1061,
- ERROR_SERVICE_NOT_ACTIVE = 1062,
- ERROR_FAILED_SERVICE_CONTROLLER_CONNECT = 1063,
- ERROR_EXCEPTION_IN_SERVICE = 1064,
- ERROR_DATABASE_DOES_NOT_EXIST = 1065,
- ERROR_SERVICE_SPECIFIC_ERROR = 1066,
- ERROR_PROCESS_ABORTED = 1067,
- ERROR_SERVICE_DEPENDENCY_FAIL = 1068,
- ERROR_SERVICE_LOGON_FAILED = 1069,
- ERROR_SERVICE_START_HANG = 1070,
- ERROR_INVALID_SERVICE_LOCK = 1071,
- ERROR_SERVICE_MARKED_FOR_DELETE = 1072,
- ERROR_SERVICE_EXISTS = 1073,
- ERROR_ALREADY_RUNNING_LKG = 1074,
- ERROR_SERVICE_DEPENDENCY_DELETED = 1075,
- ERROR_BOOT_ALREADY_ACCEPTED = 1076,
- ERROR_SERVICE_NEVER_STARTED = 1077,
- ERROR_DUPLICATE_SERVICE_NAME = 1078,
- ERROR_DIFFERENT_SERVICE_ACCOUNT = 1079,
- ERROR_CANNOT_DETECT_DRIVER_FAILURE = 1080,
- ERROR_CANNOT_DETECT_PROCESS_ABORT = 1081,
- ERROR_NO_RECOVERY_PROGRAM = 1082,
- ERROR_SERVICE_NOT_IN_EXE = 1083,
- ERROR_NOT_SAFEBOOT_SERVICE = 1084,
- ERROR_END_OF_MEDIA = 1100,
- ERROR_FILEMARK_DETECTED = 1101,
- ERROR_BEGINNING_OF_MEDIA = 1102,
- ERROR_SETMARK_DETECTED = 1103,
- ERROR_NO_DATA_DETECTED = 1104,
- ERROR_PARTITION_FAILURE = 1105,
- ERROR_INVALID_BLOCK_LENGTH = 1106,
- ERROR_DEVICE_NOT_PARTITIONED = 1107,
- ERROR_UNABLE_TO_LOCK_MEDIA = 1108,
- ERROR_UNABLE_TO_UNLOAD_MEDIA = 1109,
- ERROR_MEDIA_CHANGED = 1110,
- ERROR_BUS_RESET = 1111,
- ERROR_NO_MEDIA_IN_DRIVE = 1112,
- ERROR_NO_UNICODE_TRANSLATION = 1113,
- ERROR_DLL_INIT_FAILED = 1114,
- ERROR_SHUTDOWN_IN_PROGRESS = 1115,
- ERROR_NO_SHUTDOWN_IN_PROGRESS = 1116,
- ERROR_IO_DEVICE = 1117,
- ERROR_SERIAL_NO_DEVICE = 1118,
- ERROR_IRQ_BUSY = 1119,
- ERROR_MORE_WRITES = 1120,
- ERROR_COUNTER_TIMEOUT = 1121,
- ERROR_FLOPPY_ID_MARK_NOT_FOUND = 1122,
- ERROR_FLOPPY_WRONG_CYLINDER = 1123,
- ERROR_FLOPPY_UNKNOWN_ERROR = 1124,
- ERROR_FLOPPY_BAD_REGISTERS = 1125,
- ERROR_DISK_RECALIBRATE_FAILED = 1126,
- ERROR_DISK_OPERATION_FAILED = 1127,
- ERROR_DISK_RESET_FAILED = 1128,
- ERROR_EOM_OVERFLOW = 1129,
- ERROR_NOT_ENOUGH_SERVER_MEMORY = 1130,
- ERROR_POSSIBLE_DEADLOCK = 1131,
- ERROR_MAPPED_ALIGNMENT = 1132,
- ERROR_SET_POWER_STATE_VETOED = 1140,
- ERROR_SET_POWER_STATE_FAILED = 1141,
- ERROR_TOO_MANY_LINKS = 1142,
- ERROR_OLD_WIN_VERSION = 1150,
- ERROR_APP_WRONG_OS = 1151,
- ERROR_SINGLE_INSTANCE_APP = 1152,
- ERROR_RMODE_APP = 1153,
- ERROR_INVALID_DLL = 1154,
- ERROR_NO_ASSOCIATION = 1155,
- ERROR_DDE_FAIL = 1156,
- ERROR_DLL_NOT_FOUND = 1157,
- ERROR_NO_MORE_USER_HANDLES = 1158,
- ERROR_MESSAGE_SYNC_ONLY = 1159,
- ERROR_SOURCE_ELEMENT_EMPTY = 1160,
- ERROR_DESTINATION_ELEMENT_FULL = 1161,
- ERROR_ILLEGAL_ELEMENT_ADDRESS = 1162,
- ERROR_MAGAZINE_NOT_PRESENT = 1163,
- ERROR_DEVICE_REINITIALIZATION_NEEDED = 1164,
- ERROR_DEVICE_REQUIRES_CLEANING = 1165,
- ERROR_DEVICE_DOOR_OPEN = 1166,
- ERROR_DEVICE_NOT_CONNECTED = 1167,
- ERROR_NOT_FOUND = 1168,
- ERROR_NO_MATCH = 1169,
- ERROR_SET_NOT_FOUND = 1170,
- ERROR_POINT_NOT_FOUND = 1171,
- ERROR_NO_TRACKING_SERVICE = 1172,
- ERROR_NO_VOLUME_ID = 1173,
- ERROR_UNABLE_TO_REMOVE_REPLACED = 1175,
- ERROR_UNABLE_TO_MOVE_REPLACEMENT = 1176,
- ERROR_UNABLE_TO_MOVE_REPLACEMENT_2 = 1177,
- ERROR_JOURNAL_DELETE_IN_PROGRESS = 1178,
- ERROR_JOURNAL_NOT_ACTIVE = 1179,
- ERROR_POTENTIAL_FILE_FOUND = 1180,
- ERROR_JOURNAL_ENTRY_DELETED = 1181,
- ERROR_BAD_DEVICE = 1200,
- ERROR_CONNECTION_UNAVAIL = 1201,
- ERROR_DEVICE_ALREADY_REMEMBERED = 1202,
- ERROR_NO_NET_OR_BAD_PATH = 1203,
- ERROR_BAD_PROVIDER = 1204,
- ERROR_CANNOT_OPEN_PROFILE = 1205,
- ERROR_BAD_PROFILE = 1206,
- ERROR_NOT_CONTAINER = 1207,
- ERROR_EXTENDED_ERROR = 1208,
- ERROR_INVALID_GROUPNAME = 1209,
- ERROR_INVALID_COMPUTERNAME = 1210,
- ERROR_INVALID_EVENTNAME = 1211,
- ERROR_INVALID_DOMAINNAME = 1212,
- ERROR_INVALID_SERVICENAME = 1213,
- ERROR_INVALID_NETNAME = 1214,
- ERROR_INVALID_SHARENAME = 1215,
- ERROR_INVALID_PASSWORDNAME = 1216,
- ERROR_INVALID_MESSAGENAME = 1217,
- ERROR_INVALID_MESSAGEDEST = 1218,
- ERROR_SESSION_CREDENTIAL_CONFLICT = 1219,
- ERROR_REMOTE_SESSION_LIMIT_EXCEEDED = 1220,
- ERROR_DUP_DOMAINNAME = 1221,
- ERROR_NO_NETWORK = 1222,
- ERROR_CANCELLED = 1223,
- ERROR_USER_MAPPED_FILE = 1224,
- ERROR_CONNECTION_REFUSED = 1225,
- ERROR_GRACEFUL_DISCONNECT = 1226,
- ERROR_ADDRESS_ALREADY_ASSOCIATED = 1227,
- ERROR_ADDRESS_NOT_ASSOCIATED = 1228,
- ERROR_CONNECTION_INVALID = 1229,
- ERROR_CONNECTION_ACTIVE = 1230,
- ERROR_NETWORK_UNREACHABLE = 1231,
- ERROR_HOST_UNREACHABLE = 1232,
- ERROR_PROTOCOL_UNREACHABLE = 1233,
- ERROR_PORT_UNREACHABLE = 1234,
- ERROR_REQUEST_ABORTED = 1235,
- ERROR_CONNECTION_ABORTED = 1236,
- ERROR_RETRY = 1237,
- ERROR_CONNECTION_COUNT_LIMIT = 1238,
- ERROR_LOGIN_TIME_RESTRICTION = 1239,
- ERROR_LOGIN_WKSTA_RESTRICTION = 1240,
- ERROR_INCORRECT_ADDRESS = 1241,
- ERROR_ALREADY_REGISTERED = 1242,
- ERROR_SERVICE_NOT_FOUND = 1243,
- ERROR_NOT_AUTHENTICATED = 1244,
- ERROR_NOT_LOGGED_ON = 1245,
- ERROR_CONTINUE = 1246,
- ERROR_ALREADY_INITIALIZED = 1247,
- ERROR_NO_MORE_DEVICES = 1248,
- ERROR_NO_SUCH_SITE = 1249,
- ERROR_DOMAIN_CONTROLLER_EXISTS = 1250,
- ERROR_ONLY_IF_CONNECTED = 1251,
- ERROR_OVERRIDE_NOCHANGES = 1252,
- ERROR_BAD_USER_PROFILE = 1253,
- ERROR_NOT_SUPPORTED_ON_SBS = 1254,
- ERROR_SERVER_SHUTDOWN_IN_PROGRESS = 1255,
- ERROR_HOST_DOWN = 1256,
- ERROR_NON_ACCOUNT_SID = 1257,
- ERROR_NON_DOMAIN_SID = 1258,
- ERROR_APPHELP_BLOCK = 1259,
- ERROR_ACCESS_DISABLED_BY_POLICY = 1260,
- ERROR_REG_NAT_CONSUMPTION = 1261,
- ERROR_CSCSHARE_OFFLINE = 1262,
- ERROR_PKINIT_FAILURE = 1263,
- ERROR_SMARTCARD_SUBSYSTEM_FAILURE = 1264,
- ERROR_DOWNGRADE_DETECTED = 1265,
- SEC_E_SMARTCARD_CERT_REVOKED = 1266,
- SEC_E_ISSUING_CA_UNTRUSTED = 1267,
- SEC_E_REVOCATION_OFFLINE_C = 1268,
- SEC_E_PKINIT_CLIENT_FAILUR = 1269,
- SEC_E_SMARTCARD_CERT_EXPIRED = 1270,
- ERROR_MACHINE_LOCKED = 1271,
- ERROR_CALLBACK_SUPPLIED_INVALID_DATA = 1273,
- ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED = 1274,
- ERROR_DRIVER_BLOCKED = 1275,
- ERROR_INVALID_IMPORT_OF_NON_DLL = 1276,
- ERROR_NOT_ALL_ASSIGNED = 1300,
- ERROR_SOME_NOT_MAPPED = 1301,
- ERROR_NO_QUOTAS_FOR_ACCOUNT = 1302,
- ERROR_LOCAL_USER_SESSION_KEY = 1303,
- ERROR_NULL_LM_PASSWORD = 1304,
- ERROR_UNKNOWN_REVISION = 1305,
- ERROR_REVISION_MISMATCH = 1306,
- ERROR_INVALID_OWNER = 1307,
- ERROR_INVALID_PRIMARY_GROUP = 1308,
- ERROR_NO_IMPERSONATION_TOKEN = 1309,
- ERROR_CANT_DISABLE_MANDATORY = 1310,
- ERROR_NO_LOGON_SERVERS = 1311,
- ERROR_NO_SUCH_LOGON_SESSION = 1312,
- ERROR_NO_SUCH_PRIVILEGE = 1313,
- ERROR_PRIVILEGE_NOT_HELD = 1314,
- ERROR_INVALID_ACCOUNT_NAME = 1315,
- ERROR_USER_EXISTS = 1316,
- ERROR_NO_SUCH_USER = 1317,
- ERROR_GROUP_EXISTS = 1318,
- ERROR_NO_SUCH_GROUP = 1319,
- ERROR_MEMBER_IN_GROUP = 1320,
- ERROR_MEMBER_NOT_IN_GROUP = 1321,
- ERROR_LAST_ADMIN = 1322,
- ERROR_WRONG_PASSWORD = 1323,
- ERROR_ILL_FORMED_PASSWORD = 1324,
- ERROR_PASSWORD_RESTRICTION = 1325,
- ERROR_LOGON_FAILURE = 1326,
- ERROR_ACCOUNT_RESTRICTION = 1327,
- ERROR_INVALID_LOGON_HOURS = 1328,
- ERROR_INVALID_WORKSTATION = 1329,
- ERROR_PASSWORD_EXPIRED = 1330,
- ERROR_ACCOUNT_DISABLED = 1331,
- ERROR_NONE_MAPPED = 1332,
- ERROR_TOO_MANY_LUIDS_REQUESTED = 1333,
- ERROR_LUIDS_EXHAUSTED = 1334,
- ERROR_INVALID_SUB_AUTHORITY = 1335,
- ERROR_INVALID_ACL = 1336,
- ERROR_INVALID_SID = 1337,
- ERROR_INVALID_SECURITY_DESCR = 1338,
- ERROR_BAD_INHERITANCE_ACL = 1340,
- ERROR_SERVER_DISABLED = 1341,
- ERROR_SERVER_NOT_DISABLED = 1342,
- ERROR_INVALID_ID_AUTHORITY = 1343,
- ERROR_ALLOTTED_SPACE_EXCEEDED = 1344,
- ERROR_INVALID_GROUP_ATTRIBUTES = 1345,
- ERROR_BAD_IMPERSONATION_LEVEL = 1346,
- ERROR_CANT_OPEN_ANONYMOUS = 1347,
- ERROR_BAD_VALIDATION_CLASS = 1348,
- ERROR_BAD_TOKEN_TYPE = 1349,
- ERROR_NO_SECURITY_ON_OBJECT = 1350,
- ERROR_CANT_ACCESS_DOMAIN_INFO = 1351,
- ERROR_INVALID_SERVER_STATE = 1352,
- ERROR_INVALID_DOMAIN_STATE = 1353,
- ERROR_INVALID_DOMAIN_ROLE = 1354,
- ERROR_NO_SUCH_DOMAIN = 1355,
- ERROR_DOMAIN_EXISTS = 1356,
- ERROR_DOMAIN_LIMIT_EXCEEDED = 1357,
- ERROR_INTERNAL_DB_CORRUPTION = 1358,
- ERROR_INTERNAL_ERROR = 1359,
- ERROR_GENERIC_NOT_MAPPED = 1360,
- ERROR_BAD_DESCRIPTOR_FORMAT = 1361,
- ERROR_NOT_LOGON_PROCESS = 1362,
- ERROR_LOGON_SESSION_EXISTS = 1363,
- ERROR_NO_SUCH_PACKAGE = 1364,
- ERROR_BAD_LOGON_SESSION_STATE = 1365,
- ERROR_LOGON_SESSION_COLLISION = 1366,
- ERROR_INVALID_LOGON_TYPE = 1367,
- ERROR_CANNOT_IMPERSONATE = 1368,
- ERROR_RXACT_INVALID_STATE = 1369,
- ERROR_RXACT_COMMIT_FAILURE = 1370,
- ERROR_SPECIAL_ACCOUNT = 1371,
- ERROR_SPECIAL_GROUP = 1372,
- ERROR_SPECIAL_USER = 1373,
- ERROR_MEMBERS_PRIMARY_GROUP = 1374,
- ERROR_TOKEN_ALREADY_IN_USE = 1375,
- ERROR_NO_SUCH_ALIAS = 1376,
- ERROR_MEMBER_NOT_IN_ALIAS = 1377,
- ERROR_MEMBER_IN_ALIAS = 1378,
- ERROR_ALIAS_EXISTS = 1379,
- ERROR_LOGON_NOT_GRANTED = 1380,
- ERROR_TOO_MANY_SECRETS = 1381,
- ERROR_SECRET_TOO_LONG = 1382,
- ERROR_INTERNAL_DB_ERROR = 1383,
- ERROR_TOO_MANY_CONTEXT_IDS = 1384,
- ERROR_LOGON_TYPE_NOT_GRANTED = 1385,
- ERROR_NT_CROSS_ENCRYPTION_REQUIRED = 1386,
- ERROR_NO_SUCH_MEMBER = 1387,
- ERROR_INVALID_MEMBER = 1388,
- ERROR_TOO_MANY_SIDS = 1389,
- ERROR_LM_CROSS_ENCRYPTION_REQUIRED = 1390,
- ERROR_NO_INHERITANCE = 1391,
- ERROR_FILE_CORRUPT = 1392,
- ERROR_DISK_CORRUPT = 1393,
- ERROR_NO_USER_SESSION_KEY = 1394,
- ERROR_LICENSE_QUOTA_EXCEEDED = 1395,
- ERROR_WRONG_TARGET_NAME = 1396,
- ERROR_MUTUAL_AUTH_FAILED = 1397,
- ERROR_TIME_SKEW = 1398,
- ERROR_CURRENT_DOMAIN_NOT_ALLOWED = 1399,
- ERROR_INVALID_WINDOW_HANDLE = 1400,
- ERROR_INVALID_MENU_HANDLE = 1401,
- ERROR_INVALID_CURSOR_HANDLE = 1402,
- ERROR_INVALID_ACCEL_HANDLE = 1403,
- ERROR_INVALID_HOOK_HANDLE = 1404,
- ERROR_INVALID_DWP_HANDLE = 1405,
- ERROR_TLW_WITH_WSCHILD = 1406,
- ERROR_CANNOT_FIND_WND_CLASS = 1407,
- ERROR_WINDOW_OF_OTHER_THREAD = 1408,
- ERROR_HOTKEY_ALREADY_REGISTERED = 1409,
- ERROR_CLASS_ALREADY_EXISTS = 1410,
- ERROR_CLASS_DOES_NOT_EXIST = 1411,
- ERROR_CLASS_HAS_WINDOWS = 1412,
- ERROR_INVALID_INDEX = 1413,
- ERROR_INVALID_ICON_HANDLE = 1414,
- ERROR_PRIVATE_DIALOG_INDEX = 1415,
- ERROR_LISTBOX_ID_NOT_FOUND = 1416,
- ERROR_NO_WILDCARD_CHARACTERS = 1417,
- ERROR_CLIPBOARD_NOT_OPEN = 1418,
- ERROR_HOTKEY_NOT_REGISTERED = 1419,
- ERROR_WINDOW_NOT_DIALOG = 1420,
- ERROR_CONTROL_ID_NOT_FOUND = 1421,
- ERROR_INVALID_COMBOBOX_MESSAGE = 1422,
- ERROR_WINDOW_NOT_COMBOBOX = 1423,
- ERROR_INVALID_EDIT_HEIGHT = 1424,
- ERROR_DC_NOT_FOUND = 1425,
- ERROR_INVALID_HOOK_FILTER = 1426,
- ERROR_INVALID_FILTER_PROC = 1427,
- ERROR_HOOK_NEEDS_HMOD = 1428,
- ERROR_GLOBAL_ONLY_HOOK = 1429,
- ERROR_JOURNAL_HOOK_SET = 1430,
- ERROR_HOOK_NOT_INSTALLED = 1431,
- ERROR_INVALID_LB_MESSAGE = 1432,
- ERROR_SETCOUNT_ON_BAD_LB = 1433,
- ERROR_LB_WITHOUT_TABSTOPS = 1434,
- ERROR_DESTROY_OBJECT_OF_OTHER_THREAD = 1435,
- ERROR_CHILD_WINDOW_MENU = 1436,
- ERROR_NO_SYSTEM_MENU = 1437,
- ERROR_INVALID_MSGBOX_STYLE = 1438,
- ERROR_INVALID_SPI_VALUE = 1439,
- ERROR_SCREEN_ALREADY_LOCKED = 1440,
- ERROR_HWNDS_HAVE_DIFF_PARENT = 1441,
- ERROR_NOT_CHILD_WINDOW = 1442,
- ERROR_INVALID_GW_COMMAND = 1443,
- ERROR_INVALID_THREAD_ID = 1444,
- ERROR_NON_MDICHILD_WINDOW = 1445,
- ERROR_POPUP_ALREADY_ACTIVE = 1446,
- ERROR_NO_SCROLLBARS = 1447,
- ERROR_INVALID_SCROLLBAR_RANGE = 1448,
- ERROR_INVALID_SHOWWIN_COMMAND = 1449,
- ERROR_NO_SYSTEM_RESOURCES = 1450,
- ERROR_NONPAGED_SYSTEM_RESOURCES = 1451,
- ERROR_PAGED_SYSTEM_RESOURCES = 1452,
- ERROR_WORKING_SET_QUOTA = 1453,
- ERROR_PAGEFILE_QUOTA = 1454,
- ERROR_COMMITMENT_LIMIT = 1455,
- ERROR_MENU_ITEM_NOT_FOUND = 1456,
- ERROR_INVALID_KEYBOARD_HANDLE = 1457,
- ERROR_HOOK_TYPE_NOT_ALLOWED = 1458,
- ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION = 1459,
- ERROR_TIMEOUT = 1460,
- ERROR_INVALID_MONITOR_HANDLE = 1461,
- ERROR_EVENTLOG_FILE_CORRUPT = 1500,
- ERROR_EVENTLOG_CANT_START = 1501,
- ERROR_LOG_FILE_FULL = 1502,
- ERROR_EVENTLOG_FILE_CHANGED = 1503,
- ERROR_INSTALL_SERVICE_FAILURE = 1601,
- ERROR_INSTALL_USEREXIT = 1602,
- ERROR_INSTALL_FAILURE = 1603,
- ERROR_INSTALL_SUSPEND = 1604,
- ERROR_UNKNOWN_PRODUCT = 1605,
- ERROR_UNKNOWN_FEATURE = 1606,
- ERROR_UNKNOWN_COMPONENT = 1607,
- ERROR_UNKNOWN_PROPERTY = 1608,
- ERROR_INVALID_HANDLE_STATE = 1609,
- ERROR_BAD_CONFIGURATION = 1610,
- ERROR_INDEX_ABSENT = 1611,
- ERROR_INSTALL_SOURCE_ABSENT = 1612,
- ERROR_INSTALL_PACKAGE_VERSION = 1613,
- ERROR_PRODUCT_UNINSTALLED = 1614,
- ERROR_BAD_QUERY_SYNTAX = 1615,
- ERROR_INVALID_FIELD = 1616,
- ERROR_DEVICE_REMOVED = 1617,
- ERROR_INSTALL_ALREADY_RUNNING = 1618,
- ERROR_INSTALL_PACKAGE_OPEN_FAILED = 1619,
- ERROR_INSTALL_PACKAGE_INVALID = 1620,
- ERROR_INSTALL_UI_FAILURE = 1621,
- ERROR_INSTALL_LOG_FAILURE = 1622,
- ERROR_INSTALL_LANGUAGE_UNSUPPORTED = 1623,
- ERROR_INSTALL_TRANSFORM_FAILURE = 1624,
- ERROR_INSTALL_PACKAGE_REJECTED = 1625,
- ERROR_FUNCTION_NOT_CALLED = 1626,
- ERROR_FUNCTION_FAILED = 1627,
- ERROR_INVALID_TABLE = 1628,
- ERROR_DATATYPE_MISMATCH = 1629,
- ERROR_UNSUPPORTED_TYPE = 1630,
- ERROR_CREATE_FAILED = 1631,
- ERROR_INSTALL_TEMP_UNWRITABLE = 1632,
- ERROR_INSTALL_PLATFORM_UNSUPPORTED = 1633,
- ERROR_INSTALL_NOTUSED = 1634,
- ERROR_PATCH_PACKAGE_OPEN_FAILED = 1635,
- ERROR_PATCH_PACKAGE_INVALID = 1636,
- ERROR_PATCH_PACKAGE_UNSUPPORTED = 1637,
- ERROR_PRODUCT_VERSION = 1638,
- ERROR_INVALID_COMMAND_LINE = 1639,
- ERROR_INSTALL_REMOTE_DISALLOWED = 1640,
- ERROR_SUCCESS_REBOOT_INITIATED = 1641,
- ERROR_PATCH_TARGET_NOT_FOUND = 1642,
- ERROR_PATCH_PACKAGE_REJECTED = 1643,
- ERROR_INSTALL_TRANSFORM_REJECTED = 1644,
- RPC_S_INVALID_STRING_BINDING = 1700,
- RPC_S_WRONG_KIND_OF_BINDING = 1701,
- RPC_S_INVALID_BINDING = 1702,
- RPC_S_PROTSEQ_NOT_SUPPORTED = 1703,
- RPC_S_INVALID_RPC_PROTSEQ = 1704,
- RPC_S_INVALID_STRING_UUID = 1705,
- RPC_S_INVALID_ENDPOINT_FORMAT = 1706,
- RPC_S_INVALID_NET_ADDR = 1707,
- RPC_S_NO_ENDPOINT_FOUND = 1708,
- RPC_S_INVALID_TIMEOUT = 1709,
- RPC_S_OBJECT_NOT_FOUND = 1710,
- RPC_S_ALREADY_REGISTERED = 1711,
- RPC_S_TYPE_ALREADY_REGISTERED = 1712,
- RPC_S_ALREADY_LISTENING = 1713,
- RPC_S_NO_PROTSEQS_REGISTERED = 1714,
- RPC_S_NOT_LISTENING = 1715,
- RPC_S_UNKNOWN_MGR_TYPE = 1716,
- RPC_S_UNKNOWN_IF = 1717,
- RPC_S_NO_BINDINGS = 1718,
- RPC_S_NO_PROTSEQS = 1719,
- RPC_S_CANT_CREATE_ENDPOINT = 1720,
- RPC_S_OUT_OF_RESOURCES = 1721,
- RPC_S_SERVER_UNAVAILABLE = 1722,
- RPC_S_SERVER_TOO_BUSY = 1723,
- RPC_S_INVALID_NETWORK_OPTIONS = 1724,
- RPC_S_NO_CALL_ACTIVE = 1725,
- RPC_S_CALL_FAILED = 1726,
- RPC_S_CALL_FAILED_DNE = 1727,
- RPC_S_PROTOCOL_ERROR = 1728,
- RPC_S_UNSUPPORTED_TRANS_SYN = 1730,
- RPC_S_UNSUPPORTED_TYPE = 1732,
- RPC_S_INVALID_TAG = 1733,
- RPC_S_INVALID_BOUND = 1734,
- RPC_S_NO_ENTRY_NAME = 1735,
- RPC_S_INVALID_NAME_SYNTAX = 1736,
- RPC_S_UNSUPPORTED_NAME_SYNTAX = 1737,
- RPC_S_UUID_NO_ADDRESS = 1739,
- RPC_S_DUPLICATE_ENDPOINT = 1740,
- RPC_S_UNKNOWN_AUTHN_TYPE = 1741,
- RPC_S_MAX_CALLS_TOO_SMALL = 1742,
- RPC_S_STRING_TOO_LONG = 1743,
- RPC_S_PROTSEQ_NOT_FOUND = 1744,
- RPC_S_PROCNUM_OUT_OF_RANGE = 1745,
- RPC_S_BINDING_HAS_NO_AUTH = 1746,
- RPC_S_UNKNOWN_AUTHN_SERVICE = 1747,
- RPC_S_UNKNOWN_AUTHN_LEVEL = 1748,
- RPC_S_INVALID_AUTH_IDENTITY = 1749,
- RPC_S_UNKNOWN_AUTHZ_SERVICE = 1750,
- EPT_S_INVALID_ENTRY = 1751,
- EPT_S_CANT_PERFORM_OP = 1752,
- EPT_S_NOT_REGISTERED = 1753,
- RPC_S_NOTHING_TO_EXPORT = 1754,
- RPC_S_INCOMPLETE_NAME = 1755,
- RPC_S_INVALID_VERS_OPTION = 1756,
- RPC_S_NO_MORE_MEMBERS = 1757,
- RPC_S_NOT_ALL_OBJS_UNEXPORTED = 1758,
- RPC_S_INTERFACE_NOT_FOUND = 1759,
- RPC_S_ENTRY_ALREADY_EXISTS = 1760,
- RPC_S_ENTRY_NOT_FOUND = 1761,
- RPC_S_NAME_SERVICE_UNAVAILABLE = 1762,
- RPC_S_INVALID_NAF_ID = 1763,
- RPC_S_CANNOT_SUPPORT = 1764,
- RPC_S_NO_CONTEXT_AVAILABLE = 1765,
- RPC_S_INTERNAL_ERROR = 1766,
- RPC_S_ZERO_DIVIDE = 1767,
- RPC_S_ADDRESS_ERROR = 1768,
- RPC_S_FP_DIV_ZERO = 1769,
- RPC_S_FP_UNDERFLOW = 1770,
- RPC_S_FP_OVERFLOW = 1771,
- RPC_X_NO_MORE_ENTRIES = 1772,
- RPC_X_SS_CHAR_TRANS_OPEN_FAIL = 1773,
- RPC_X_SS_CHAR_TRANS_SHORT_FILE = 1774,
- RPC_X_SS_IN_NULL_CONTEXT = 1775,
- RPC_X_SS_CONTEXT_DAMAGED = 1777,
- RPC_X_SS_HANDLES_MISMATCH = 1778,
- RPC_X_SS_CANNOT_GET_CALL_HANDLE = 1779,
- RPC_X_NULL_REF_POINTER = 1780,
- RPC_X_ENUM_VALUE_OUT_OF_RANGE = 1781,
- RPC_X_BYTE_COUNT_TOO_SMALL = 1782,
- RPC_X_BAD_STUB_DATA = 1783,
- ERROR_INVALID_USER_BUFFER = 1784,
- ERROR_UNRECOGNIZED_MEDIA = 1785,
- ERROR_NO_TRUST_LSA_SECRET = 1786,
- ERROR_NO_TRUST_SAM_ACCOUNT = 1787,
- ERROR_TRUSTED_DOMAIN_FAILURE = 1788,
- ERROR_TRUSTED_RELATIONSHIP_FAILURE = 1789,
- ERROR_TRUST_FAILURE = 1790,
- RPC_S_CALL_IN_PROGRESS = 1791,
- ERROR_NETLOGON_NOT_STARTED = 1792,
- ERROR_ACCOUNT_EXPIRED = 1793,
- ERROR_REDIRECTOR_HAS_OPEN_HANDLES = 1794,
- ERROR_PRINTER_DRIVER_ALREADY_INSTALLED = 1795,
- ERROR_UNKNOWN_PORT = 1796,
- ERROR_UNKNOWN_PRINTER_DRIVER = 1797,
- ERROR_UNKNOWN_PRINTPROCESSOR = 1798,
- ERROR_INVALID_SEPARATOR_FILE = 1799,
- ERROR_INVALID_PRIORITY = 1800,
- ERROR_INVALID_PRINTER_NAME = 1801,
- ERROR_PRINTER_ALREADY_EXISTS = 1802,
- ERROR_INVALID_PRINTER_COMMAND = 1803,
- ERROR_INVALID_DATATYPE = 1804,
- ERROR_INVALID_ENVIRONMENT = 1805,
- RPC_S_NO_MORE_BINDINGS = 1806,
- ERROR_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT = 1807,
- ERROR_NOLOGON_WORKSTATION_TRUST_ACCOUNT = 1808,
- ERROR_NOLOGON_SERVER_TRUST_ACCOUNT = 1809,
- ERROR_DOMAIN_TRUST_INCONSISTENT = 1810,
- ERROR_SERVER_HAS_OPEN_HANDLES = 1811,
- ERROR_RESOURCE_DATA_NOT_FOUND = 1812,
- ERROR_RESOURCE_TYPE_NOT_FOUND = 1813,
- ERROR_RESOURCE_NAME_NOT_FOUND = 1814,
- ERROR_RESOURCE_LANG_NOT_FOUND = 1815,
- ERROR_NOT_ENOUGH_QUOTA = 1816,
- RPC_S_NO_INTERFACES = 1817,
- RPC_S_CALL_CANCELLED = 1818,
- RPC_S_BINDING_INCOMPLETE = 1819,
- RPC_S_COMM_FAILURE = 1820,
- RPC_S_UNSUPPORTED_AUTHN_LEVEL = 1821,
- RPC_S_NO_PRINC_NAME = 1822,
- RPC_S_NOT_RPC_ERROR = 1823,
- RPC_S_UUID_LOCAL_ONLY = 1824,
- RPC_S_SEC_PKG_ERROR = 1825,
- RPC_S_NOT_CANCELLED = 1826,
- RPC_X_INVALID_ES_ACTION = 1827,
- RPC_X_WRONG_ES_VERSION = 1828,
- RPC_X_WRONG_STUB_VERSION = 1829,
- RPC_X_INVALID_PIPE_OBJECT = 1830,
- RPC_X_WRONG_PIPE_ORDER = 1831,
- RPC_X_WRONG_PIPE_VERSION = 1832,
- RPC_S_GROUP_MEMBER_NOT_FOUND = 1898,
- EPT_S_CANT_CREATE = 1899,
- RPC_S_INVALID_OBJECT = 1900,
- ERROR_INVALID_TIME = 1901,
- ERROR_INVALID_FORM_NAME = 1902,
- ERROR_INVALID_FORM_SIZE = 1903,
- ERROR_ALREADY_WAITING = 1904,
- ERROR_PRINTER_DELETED = 1905,
- ERROR_INVALID_PRINTER_STATE = 1906,
- ERROR_PASSWORD_MUST_CHANGE = 1907,
- ERROR_DOMAIN_CONTROLLER_NOT_FOUND = 1908,
- ERROR_ACCOUNT_LOCKED_OUT = 1909,
- OR_INVALID_OXID = 1910,
- OR_INVALID_OID = 1911,
- OR_INVALID_SET = 1912,
- RPC_S_SEND_INCOMPLETE = 1913,
- RPC_S_INVALID_ASYNC_HANDLE = 1914,
- RPC_S_INVALID_ASYNC_CALL = 1915,
- RPC_X_PIPE_CLOSED = 1916,
- RPC_X_PIPE_DISCIPLINE_ERROR = 1917,
- RPC_X_PIPE_EMPTY = 1918,
- ERROR_NO_SITENAME = 1919,
- ERROR_CANT_ACCESS_FILE = 1920,
- ERROR_CANT_RESOLVE_FILENAME = 1921,
- RPC_S_ENTRY_TYPE_MISMATCH = 1922,
- RPC_S_NOT_ALL_OBJS_EXPORTED = 1923,
- RPC_S_INTERFACE_NOT_EXPORTED = 1924,
- RPC_S_PROFILE_NOT_ADDED = 1925,
- RPC_S_PRF_ELT_NOT_ADDED = 1926,
- RPC_S_PRF_ELT_NOT_REMOVED = 1927,
- RPC_S_GRP_ELT_NOT_ADDED = 1928,
- RPC_S_GRP_ELT_NOT_REMOVED = 1929,
- ERROR_KM_DRIVER_BLOCKED = 1930,
- ERROR_CONTEXT_EXPIRED = 1931,
- ERROR_INVALID_PIXEL_FORMAT = 2000,
- ERROR_BAD_DRIVER = 2001,
- ERROR_INVALID_WINDOW_STYLE = 2002,
- ERROR_METAFILE_NOT_SUPPORTED = 2003,
- ERROR_TRANSFORM_NOT_SUPPORTED = 2004,
- ERROR_CLIPPING_NOT_SUPPORTED = 2005,
- ERROR_INVALID_CMM = 2010,
- ERROR_INVALID_PROFILE = 2011,
- ERROR_TAG_NOT_FOUND = 2012,
- ERROR_TAG_NOT_PRESENT = 2013,
- ERROR_DUPLICATE_TAG = 2014,
- ERROR_PROFILE_NOT_ASSOCIATED_WITH_DEVICE = 2015,
- ERROR_PROFILE_NOT_FOUND = 2016,
- ERROR_INVALID_COLORSPACE = 2017,
- ERROR_ICM_NOT_ENABLED = 2018,
- ERROR_DELETING_ICM_XFORM = 2019,
- ERROR_INVALID_TRANSFORM = 2020,
- ERROR_COLORSPACE_MISMATCH = 2021,
- ERROR_INVALID_COLORINDEX = 2022,
- ERROR_CONNECTED_OTHER_PASSWORD = 2108,
- ERROR_CONNECTED_OTHER_PASSWORD_DEFAULT = 2109,
- ERROR_BAD_USERNAME = 2202,
- ERROR_NOT_CONNECTED = 2250,
- ERROR_OPEN_FILES = 2401,
- ERROR_ACTIVE_CONNECTIONS = 2402,
- ERROR_DEVICE_IN_USE = 2404,
- ERROR_UNKNOWN_PRINT_MONITOR = 3000,
- ERROR_PRINTER_DRIVER_IN_USE = 3001,
- ERROR_SPOOL_FILE_NOT_FOUND = 3002,
- ERROR_SPL_NO_STARTDOC = 3003,
- ERROR_SPL_NO_ADDJOB = 3004,
- ERROR_PRINT_PROCESSOR_ALREADY_INSTALLED = 3005,
- ERROR_PRINT_MONITOR_ALREADY_INSTALLED = 3006,
- ERROR_INVALID_PRINT_MONITOR = 3007,
- ERROR_PRINT_MONITOR_IN_USE = 3008,
- ERROR_PRINTER_HAS_JOBS_QUEUED = 3009,
- ERROR_SUCCESS_REBOOT_REQUIRED = 3010,
- ERROR_SUCCESS_RESTART_REQUIRED = 3011,
- ERROR_PRINTER_NOT_FOUND = 3012,
- ERROR_PRINTER_DRIVER_WARNED = 3013,
- ERROR_PRINTER_DRIVER_BLOCKED = 3014,
- ERROR_WINS_INTERNAL = 4000,
- ERROR_CAN_NOT_DEL_LOCAL_WINS = 4001,
- ERROR_STATIC_INIT = 4002,
- ERROR_INC_BACKUP = 4003,
- ERROR_FULL_BACKUP = 4004,
- ERROR_REC_NON_EXISTENT = 4005,
- ERROR_RPL_NOT_ALLOWED = 4006,
- ERROR_DHCP_ADDRESS_CONFLICT = 4100,
- ERROR_WMI_GUID_NOT_FOUND = 4200,
- ERROR_WMI_INSTANCE_NOT_FOUND = 4201,
- ERROR_WMI_ITEMID_NOT_FOUND = 4202,
- ERROR_WMI_TRY_AGAIN = 4203,
- ERROR_WMI_DP_NOT_FOUND = 4204,
- ERROR_WMI_UNRESOLVED_INSTANCE_REF = 4205,
- ERROR_WMI_ALREADY_ENABLED = 4206,
- ERROR_WMI_GUID_DISCONNECTED = 4207,
- ERROR_WMI_SERVER_UNAVAILABLE = 4208,
- ERROR_WMI_DP_FAILED = 4209,
- ERROR_WMI_INVALID_MOF = 4210,
- ERROR_WMI_INVALID_REGINFO = 4211,
- ERROR_WMI_ALREADY_DISABLED = 4212,
- ERROR_WMI_READ_ONLY = 4213,
- ERROR_WMI_SET_FAILURE = 4214,
- ERROR_INVALID_MEDIA = 4300,
- ERROR_INVALID_LIBRARY = 4301,
- ERROR_INVALID_MEDIA_POOL = 4302,
- ERROR_DRIVE_MEDIA_MISMATCH = 4303,
- ERROR_MEDIA_OFFLINE = 4304,
- ERROR_LIBRARY_OFFLINE = 4305,
- ERROR_EMPTY = 4306,
- ERROR_NOT_EMPTY = 4307,
- ERROR_MEDIA_UNAVAILABLE = 4308,
- ERROR_RESOURCE_DISABLED = 4309,
- ERROR_INVALID_CLEANER = 4310,
- ERROR_UNABLE_TO_CLEAN = 4311,
- ERROR_OBJECT_NOT_FOUND = 4312,
- ERROR_DATABASE_FAILURE = 4313,
- ERROR_DATABASE_FULL = 4314,
- ERROR_MEDIA_INCOMPATIBLE = 4315,
- ERROR_RESOURCE_NOT_PRESENT = 4316,
- ERROR_INVALID_OPERATION = 4317,
- ERROR_MEDIA_NOT_AVAILABLE = 4318,
- ERROR_DEVICE_NOT_AVAILABLE = 4319,
- ERROR_REQUEST_REFUSED = 4320,
- ERROR_INVALID_DRIVE_OBJECT = 4321,
- ERROR_LIBRARY_FULL = 4322,
- ERROR_MEDIUM_NOT_ACCESSIBLE = 4323,
- ERROR_UNABLE_TO_LOAD_MEDIUM = 4324,
- ERROR_UNABLE_TO_INVENTORY_DRIVE = 4325,
- ERROR_UNABLE_TO_INVENTORY_SLOT = 4326,
- ERROR_UNABLE_TO_INVENTORY_TRANSPORT = 4327,
- ERROR_TRANSPORT_FULL = 4328,
- ERROR_CONTROLLING_IEPORT = 4329,
- ERROR_UNABLE_TO_EJECT_MOUNTED_MEDIA = 4330,
- ERROR_CLEANER_SLOT_SET = 4331,
- ERROR_CLEANER_SLOT_NOT_SET = 4332,
- ERROR_CLEANER_CARTRIDGE_SPENT = 4333,
- ERROR_UNEXPECTED_OMID = 4334,
- ERROR_CANT_DELETE_LAST_ITEM = 4335,
- ERROR_MESSAGE_EXCEEDS_MAX_SIZE = 4336,
- ERROR_VOLUME_CONTAINS_SYS_FILES = 4337,
- ERROR_INDIGENOUS_TYPE = 4338,
- ERROR_NO_SUPPORTING_DRIVES = 4339,
- ERROR_CLEANER_CARTRIDGE_INSTALLED = 4340,
- ERROR_FILE_OFFLINE = 4350,
- ERROR_REMOTE_STORAGE_NOT_ACTIVE = 4351,
- ERROR_REMOTE_STORAGE_MEDIA_ERROR = 4352,
- ERROR_NOT_A_REPARSE_POINT = 4390,
- ERROR_REPARSE_ATTRIBUTE_CONFLICT = 4391,
- ERROR_INVALID_REPARSE_DATA = 4392,
- ERROR_REPARSE_TAG_INVALID = 4393,
- ERROR_REPARSE_TAG_MISMATCH = 4394,
- ERROR_VOLUME_NOT_SIS_ENABLED = 4500,
- ERROR_DEPENDENT_RESOURCE_EXISTS = 5001,
- ERROR_DEPENDENCY_NOT_FOUND = 5002,
- ERROR_DEPENDENCY_ALREADY_EXISTS = 5003,
- ERROR_RESOURCE_NOT_ONLINE = 5004,
- ERROR_HOST_NODE_NOT_AVAILABLE = 5005,
- ERROR_RESOURCE_NOT_AVAILABLE = 5006,
- ERROR_RESOURCE_NOT_FOUND = 5007,
- ERROR_SHUTDOWN_CLUSTER = 5008,
- ERROR_CANT_EVICT_ACTIVE_NODE = 5009,
- ERROR_OBJECT_ALREADY_EXISTS = 5010,
- ERROR_OBJECT_IN_LIST = 5011,
- ERROR_GROUP_NOT_AVAILABLE = 5012,
- ERROR_GROUP_NOT_FOUND = 5013,
- ERROR_GROUP_NOT_ONLINE = 5014,
- ERROR_HOST_NODE_NOT_RESOURCE_OWNER = 5015,
- ERROR_HOST_NODE_NOT_GROUP_OWNER = 5016,
- ERROR_RESMON_CREATE_FAILED = 5017,
- ERROR_RESMON_ONLINE_FAILED = 5018,
- ERROR_RESOURCE_ONLINE = 5019,
- ERROR_QUORUM_RESOURCE = 5020,
- ERROR_NOT_QUORUM_CAPABLE = 5021,
- ERROR_CLUSTER_SHUTTING_DOWN = 5022,
- ERROR_INVALID_STATE = 5023,
- ERROR_RESOURCE_PROPERTIES_STORED = 5024,
- ERROR_NOT_QUORUM_CLASS = 5025,
- ERROR_CORE_RESOURCE = 5026,
- ERROR_QUORUM_RESOURCE_ONLINE_FAILED = 5027,
- ERROR_QUORUMLOG_OPEN_FAILED = 5028,
- ERROR_CLUSTERLOG_CORRUPT = 5029,
- ERROR_CLUSTERLOG_RECORD_EXCEEDS_MAXSIZE = 5030,
- ERROR_CLUSTERLOG_EXCEEDS_MAXSIZE = 5031,
- ERROR_CLUSTERLOG_CHKPOINT_NOT_FOUND = 5032,
- ERROR_CLUSTERLOG_NOT_ENOUGH_SPACE = 5033,
- ERROR_QUORUM_OWNER_ALIVE = 5034,
- ERROR_NETWORK_NOT_AVAILABLE = 5035,
- ERROR_NODE_NOT_AVAILABLE = 5036,
- ERROR_ALL_NODES_NOT_AVAILABLE = 5037,
- ERROR_RESOURCE_FAILED = 5038,
- ERROR_CLUSTER_INVALID_NODE = 5039,
- ERROR_CLUSTER_NODE_EXISTS = 5040,
- ERROR_CLUSTER_JOIN_IN_PROGRESS = 5041,
- ERROR_CLUSTER_NODE_NOT_FOUND = 5042,
- ERROR_CLUSTER_LOCAL_NODE_NOT_FOUND = 5043,
- ERROR_CLUSTER_NETWORK_EXISTS = 5044,
- ERROR_CLUSTER_NETWORK_NOT_FOUND = 5045,
- ERROR_CLUSTER_NETINTERFACE_EXISTS = 5046,
- ERROR_CLUSTER_NETINTERFACE_NOT_FOUND = 5047,
- ERROR_CLUSTER_INVALID_REQUEST = 5048,
- ERROR_CLUSTER_INVALID_NETWORK_PROVIDER = 5049,
- ERROR_CLUSTER_NODE_DOWN = 5050,
- ERROR_CLUSTER_NODE_UNREACHABLE = 5051,
- ERROR_CLUSTER_NODE_NOT_MEMBER = 5052,
- ERROR_CLUSTER_JOIN_NOT_IN_PROGRESS = 5053,
- ERROR_CLUSTER_INVALID_NETWORK = 5054,
- ERROR_CLUSTER_NODE_UP = 5056,
- ERROR_CLUSTER_IPADDR_IN_USE = 5057,
- ERROR_CLUSTER_NODE_NOT_PAUSED = 5058,
- ERROR_CLUSTER_NO_SECURITY_CONTEXT = 5059,
- ERROR_CLUSTER_NETWORK_NOT_INTERNAL = 5060,
- ERROR_CLUSTER_NODE_ALREADY_UP = 5061,
- ERROR_CLUSTER_NODE_ALREADY_DOWN = 5062,
- ERROR_CLUSTER_NETWORK_ALREADY_ONLINE = 5063,
- ERROR_CLUSTER_NETWORK_ALREADY_OFFLINE = 5064,
- ERROR_CLUSTER_NODE_ALREADY_MEMBER = 5065,
- ERROR_CLUSTER_LAST_INTERNAL_NETWORK = 5066,
- ERROR_CLUSTER_NETWORK_HAS_DEPENDENTS = 5067,
- ERROR_INVALID_OPERATION_ON_QUORUM = 5068,
- ERROR_DEPENDENCY_NOT_ALLOWED = 5069,
- ERROR_CLUSTER_NODE_PAUSED = 5070,
- ERROR_NODE_CANT_HOST_RESOURCE = 5071,
- ERROR_CLUSTER_NODE_NOT_READY = 5072,
- ERROR_CLUSTER_NODE_SHUTTING_DOWN = 5073,
- ERROR_CLUSTER_JOIN_ABORTED = 5074,
- ERROR_CLUSTER_INCOMPATIBLE_VERSIONS = 5075,
- ERROR_CLUSTER_MAXNUM_OF_RESOURCES_EXCEEDED = 5076,
- ERROR_CLUSTER_SYSTEM_CONFIG_CHANGED = 5077,
- ERROR_CLUSTER_RESOURCE_TYPE_NOT_FOUND = 5078,
- ERROR_CLUSTER_RESTYPE_NOT_SUPPORTED = 5079,
- ERROR_CLUSTER_RESNAME_NOT_FOUND = 5080,
- ERROR_CLUSTER_NO_RPC_PACKAGES_REGISTERED = 5081,
- ERROR_CLUSTER_OWNER_NOT_IN_PREFLIST = 5082,
- ERROR_CLUSTER_DATABASE_SEQMISMATCH = 5083,
- ERROR_RESMON_INVALID_STATE = 5084,
- ERROR_CLUSTER_GUM_NOT_LOCKER = 5085,
- ERROR_QUORUM_DISK_NOT_FOUND = 5086,
- ERROR_DATABASE_BACKUP_CORRUPT = 5087,
- ERROR_CLUSTER_NODE_ALREADY_HAS_DFS_ROOT = 5088,
- ERROR_RESOURCE_PROPERTY_UNCHANGEABLE = 5089,
- ERROR_CLUSTER_MEMBERSHIP_INVALID_STATE = 5890,
- ERROR_CLUSTER_QUORUMLOG_NOT_FOUND = 5891,
- ERROR_CLUSTER_MEMBERSHIP_HALT = 5892,
- ERROR_CLUSTER_INSTANCE_ID_MISMATCH = 5893,
- ERROR_CLUSTER_NETWORK_NOT_FOUND_FOR_IP = 5894,
- ERROR_CLUSTER_PROPERTY_DATA_TYPE_MISMATCH = 5895,
- ERROR_CLUSTER_EVICT_WITHOUT_CLEANUP = 5896,
- ERROR_CLUSTER_PARAMETER_MISMATCH = 5897,
- ERROR_NODE_CANNOT_BE_CLUSTERED = 5898,
- ERROR_CLUSTER_WRONG_OS_VERSION = 5899,
- ERROR_CLUSTER_CANT_CREATE_DUP_CLUSTER_NAME = 5900,
- */
- ERROR_ENCRYPTION_FAILED = 6000,
- /*
- ERROR_DECRYPTION_FAILED = 6001,
- ERROR_FILE_ENCRYPTED = 6002,
- ERROR_NO_RECOVERY_POLICY = 6003,
- ERROR_NO_EFS = 6004,
- ERROR_WRONG_EFS = 6005,
- ERROR_NO_USER_KEYS = 6006,
- ERROR_FILE_NOT_ENCRYPTED = 6007,
- ERROR_NOT_EXPORT_FORMAT = 6008,
- ERROR_FILE_READ_ONLY = 6009,
- ERROR_DIR_EFS_DISALLOWED = 6010,
- ERROR_EFS_SERVER_NOT_TRUSTED = 6011,
- ERROR_BAD_RECOVERY_POLICY = 6012,
- ERROR_EFS_ALG_BLOB_TOO_BIG = 6013,
- ERROR_VOLUME_NOT_SUPPORT_EFS = 6014,
- ERROR_EFS_DISABLED = 6015,
- ERROR_EFS_VERSION_NOT_SUPPORT = 6016,
- ERROR_NO_BROWSER_SERVERS_FOUND = 6118,
- SCHED_E_SERVICE_NOT_LOCALSYSTEM = 6200,
- ERROR_CTX_WINSTATION_NAME_INVALID = 7001,
- ERROR_CTX_INVALID_PD = 7002,
- ERROR_CTX_PD_NOT_FOUND = 7003,
- ERROR_CTX_WD_NOT_FOUND = 7004,
- ERROR_CTX_CANNOT_MAKE_EVENTLOG_ENTRY = 7005,
- ERROR_CTX_SERVICE_NAME_COLLISION = 7006,
- ERROR_CTX_CLOSE_PENDING = 7007,
- ERROR_CTX_NO_OUTBUF = 7008,
- ERROR_CTX_MODEM_INF_NOT_FOUND = 7009,
- ERROR_CTX_INVALID_MODEMNAME = 7010,
- ERROR_CTX_MODEM_RESPONSE_ERROR = 7011,
- ERROR_CTX_MODEM_RESPONSE_TIMEOUT = 7012,
- ERROR_CTX_MODEM_RESPONSE_NO_CARRIER = 7013,
- ERROR_CTX_MODEM_RESPONSE_NO_DIALTONE = 7014,
- ERROR_CTX_MODEM_RESPONSE_BUSY = 7015,
- ERROR_CTX_MODEM_RESPONSE_VOICE = 7016,
- ERROR_CTX_TD_ERROR = 7017,
- ERROR_CTX_WINSTATION_NOT_FOUND = 7022,
- ERROR_CTX_WINSTATION_ALREADY_EXISTS = 7023,
- ERROR_CTX_WINSTATION_BUSY = 7024,
- ERROR_CTX_BAD_VIDEO_MODE = 7025,
- ERROR_CTX_GRAPHICS_INVALID = 7035,
- ERROR_CTX_LOGON_DISABLED = 7037,
- ERROR_CTX_NOT_CONSOLE = 7038,
- ERROR_CTX_CLIENT_QUERY_TIMEOUT = 7040,
- ERROR_CTX_CONSOLE_DISCONNECT = 7041,
- ERROR_CTX_CONSOLE_CONNECT = 7042,
- ERROR_CTX_SHADOW_DENIED = 7044,
- ERROR_CTX_WINSTATION_ACCESS_DENIED = 7045,
- ERROR_CTX_INVALID_WD = 7049,
- ERROR_CTX_SHADOW_INVALID = 7050,
- ERROR_CTX_SHADOW_DISABLED = 7051,
- ERROR_CTX_CLIENT_LICENSE_IN_USE = 7052,
- ERROR_CTX_CLIENT_LICENSE_NOT_SET = 7053,
- ERROR_CTX_LICENSE_NOT_AVAILABLE = 7054,
- ERROR_CTX_LICENSE_CLIENT_INVALID = 7055,
- ERROR_CTX_LICENSE_EXPIRED = 7056,
- ERROR_CTX_SHADOW_NOT_RUNNING = 7057,
- ERROR_CTX_SHADOW_ENDED_BY_MODE_CHANGE = 7058,
- FRS_ERR_INVALID_API_SEQUENCE = 8001,
- FRS_ERR_STARTING_SERVICE = 8002,
- FRS_ERR_STOPPING_SERVICE = 8003,
- FRS_ERR_INTERNAL_API = 8004,
- FRS_ERR_INTERNAL = 8005,
- FRS_ERR_SERVICE_COMM = 8006,
- FRS_ERR_INSUFFICIENT_PRIV = 8007,
- FRS_ERR_AUTHENTICATION = 8008,
- FRS_ERR_PARENT_INSUFFICIENT_PRIV = 8009,
- FRS_ERR_PARENT_AUTHENTICATION = 8010,
- FRS_ERR_CHILD_TO_PARENT_COMM = 8011,
- FRS_ERR_PARENT_TO_CHILD_COMM = 8012,
- FRS_ERR_SYSVOL_POPULATE = 8013,
- FRS_ERR_SYSVOL_POPULATE_TIMEOUT = 8014,
- FRS_ERR_SYSVOL_IS_BUSY = 8015,
- FRS_ERR_SYSVOL_DEMOTE = 8016,
- FRS_ERR_INVALID_SERVICE_PARAMETER = 8017,
- ERROR_DS_NOT_INSTALLED = 8200,
- ERROR_DS_MEMBERSHIP_EVALUATED_LOCALLY = 8201,
- ERROR_DS_NO_ATTRIBUTE_OR_VALUE = 8202,
- ERROR_DS_INVALID_ATTRIBUTE_SYNTAX = 8203,
- ERROR_DS_ATTRIBUTE_TYPE_UNDEFINED = 8204,
- ERROR_DS_ATTRIBUTE_OR_VALUE_EXISTS = 8205,
- ERROR_DS_BUSY = 8206,
- ERROR_DS_UNAVAILABLE = 8207,
- ERROR_DS_NO_RIDS_ALLOCATED = 8208,
- ERROR_DS_NO_MORE_RIDS = 8209,
- ERROR_DS_INCORRECT_ROLE_OWNER = 8210,
- ERROR_DS_RIDMGR_INIT_ERROR = 8211,
- ERROR_DS_OBJ_CLASS_VIOLATION = 8212,
- ERROR_DS_CANT_ON_NON_LEAF = 8213,
- ERROR_DS_CANT_ON_RDN = 8214,
- ERROR_DS_CANT_MOD_OBJ_CLASS = 8215,
- ERROR_DS_CROSS_DOM_MOVE_ERROR = 8216,
- ERROR_DS_GC_NOT_AVAILABLE = 8217,
- ERROR_SHARED_POLICY = 8218,
- ERROR_POLICY_OBJECT_NOT_FOUND = 8219,
- ERROR_POLICY_ONLY_IN_DS = 8220,
- ERROR_PROMOTION_ACTIVE = 8221,
- ERROR_NO_PROMOTION_ACTIVE = 8222,
- ERROR_DS_OPERATIONS_ERROR = 8224,
- ERROR_DS_PROTOCOL_ERROR = 8225,
- ERROR_DS_TIMELIMIT_EXCEEDED = 8226,
- ERROR_DS_SIZELIMIT_EXCEEDED = 8227,
- ERROR_DS_ADMIN_LIMIT_EXCEEDED = 8228,
- ERROR_DS_COMPARE_FALSE = 8229,
- ERROR_DS_COMPARE_TRUE = 8230,
- ERROR_DS_AUTH_METHOD_NOT_SUPPORTED = 8231,
- ERROR_DS_STRONG_AUTH_REQUIRED = 8232,
- ERROR_DS_INAPPROPRIATE_AUTH = 8233,
- ERROR_DS_AUTH_UNKNOWN = 8234,
- ERROR_DS_REFERRAL = 8235,
- ERROR_DS_UNAVAILABLE_CRIT_EXTENSION = 8236,
- ERROR_DS_CONFIDENTIALITY_REQUIRED = 8237,
- ERROR_DS_INAPPROPRIATE_MATCHING = 8238,
- ERROR_DS_CONSTRAINT_VIOLATION = 8239,
- ERROR_DS_NO_SUCH_OBJECT = 8240,
- ERROR_DS_ALIAS_PROBLEM = 8241,
- ERROR_DS_INVALID_DN_SYNTAX = 8242,
- ERROR_DS_IS_LEAF = 8243,
- ERROR_DS_ALIAS_DEREF_PROBLEM = 8244,
- ERROR_DS_UNWILLING_TO_PERFORM = 8245,
- ERROR_DS_LOOP_DETECT = 8246,
- ERROR_DS_NAMING_VIOLATION = 8247,
- ERROR_DS_OBJECT_RESULTS_TOO_LARGE = 8248,
- ERROR_DS_AFFECTS_MULTIPLE_DSAS = 8249,
- ERROR_DS_SERVER_DOWN = 8250,
- ERROR_DS_LOCAL_ERROR = 8251,
- ERROR_DS_ENCODING_ERROR = 8252,
- ERROR_DS_DECODING_ERROR = 8253,
- ERROR_DS_FILTER_UNKNOWN = 8254,
- ERROR_DS_PARAM_ERROR = 8255,
- ERROR_DS_NOT_SUPPORTED = 8256,
- ERROR_DS_NO_RESULTS_RETURNED = 8257,
- ERROR_DS_CONTROL_NOT_FOUND = 8258,
- ERROR_DS_CLIENT_LOOP = 8259,
- ERROR_DS_REFERRAL_LIMIT_EXCEEDED = 8260,
- ERROR_DS_SORT_CONTROL_MISSING = 8261,
- ERROR_DS_OFFSET_RANGE_ERROR = 8262,
- ERROR_DS_ROOT_MUST_BE_NC = 8301,
- ERROR_DS_ADD_REPLICA_INHIBITED = 8302,
- ERROR_DS_ATT_NOT_DEF_IN_SCHEMA = 8303,
- ERROR_DS_MAX_OBJ_SIZE_EXCEEDED = 8304,
- ERROR_DS_OBJ_STRING_NAME_EXISTS = 8305,
- ERROR_DS_NO_RDN_DEFINED_IN_SCHEMA = 8306,
- ERROR_DS_RDN_DOESNT_MATCH_SCHEMA = 8307,
- ERROR_DS_NO_REQUESTED_ATTS_FOUND = 8308,
- ERROR_DS_USER_BUFFER_TO_SMALL = 8309,
- ERROR_DS_ATT_IS_NOT_ON_OBJ = 8310,
- ERROR_DS_ILLEGAL_MOD_OPERATION = 8311,
- ERROR_DS_OBJ_TOO_LARGE = 8312,
- ERROR_DS_BAD_INSTANCE_TYPE = 8313,
- ERROR_DS_MASTERDSA_REQUIRED = 8314,
- ERROR_DS_OBJECT_CLASS_REQUIRED = 8315,
- ERROR_DS_MISSING_REQUIRED_ATT = 8316,
- ERROR_DS_ATT_NOT_DEF_FOR_CLASS = 8317,
- ERROR_DS_ATT_ALREADY_EXISTS = 8318,
- ERROR_DS_CANT_ADD_ATT_VALUES = 8320,
- ERROR_DS_SINGLE_VALUE_CONSTRAINT = 8321,
- ERROR_DS_RANGE_CONSTRAINT = 8322,
- ERROR_DS_ATT_VAL_ALREADY_EXISTS = 8323,
- ERROR_DS_CANT_REM_MISSING_ATT = 8324,
- ERROR_DS_CANT_REM_MISSING_ATT_VAL = 8325,
- ERROR_DS_ROOT_CANT_BE_SUBREF = 8326,
- ERROR_DS_NO_CHAINING = 8327,
- ERROR_DS_NO_CHAINED_EVAL = 8328,
- ERROR_DS_NO_PARENT_OBJECT = 8329,
- ERROR_DS_PARENT_IS_AN_ALIAS = 8330,
- ERROR_DS_CANT_MIX_MASTER_AND_REPS = 8331,
- ERROR_DS_CHILDREN_EXIST = 8332,
- ERROR_DS_OBJ_NOT_FOUND = 8333,
- ERROR_DS_ALIASED_OBJ_MISSING = 8334,
- ERROR_DS_BAD_NAME_SYNTAX = 8335,
- ERROR_DS_ALIAS_POINTS_TO_ALIAS = 8336,
- ERROR_DS_CANT_DEREF_ALIAS = 8337,
- ERROR_DS_OUT_OF_SCOPE = 8338,
- ERROR_DS_OBJECT_BEING_REMOVED = 8339,
- ERROR_DS_CANT_DELETE_DSA_OBJ = 8340,
- ERROR_DS_GENERIC_ERROR = 8341,
- ERROR_DS_DSA_MUST_BE_INT_MASTER = 8342,
- ERROR_DS_CLASS_NOT_DSA = 8343,
- ERROR_DS_INSUFF_ACCESS_RIGHTS = 8344,
- ERROR_DS_ILLEGAL_SUPERIOR = 8345,
- ERROR_DS_ATTRIBUTE_OWNED_BY_SAM = 8346,
- ERROR_DS_NAME_TOO_MANY_PARTS = 8347,
- ERROR_DS_NAME_TOO_LONG = 8348,
- ERROR_DS_NAME_VALUE_TOO_LONG = 8349,
- ERROR_DS_NAME_UNPARSEABLE = 8350,
- ERROR_DS_NAME_TYPE_UNKNOWN = 8351,
- ERROR_DS_NOT_AN_OBJECT = 8352,
- ERROR_DS_SEC_DESC_TOO_SHORT = 8353,
- ERROR_DS_SEC_DESC_INVALID = 8354,
- ERROR_DS_NO_DELETED_NAME = 8355,
- ERROR_DS_SUBREF_MUST_HAVE_PARENT = 8356,
- ERROR_DS_NCNAME_MUST_BE_NC = 8357,
- ERROR_DS_CANT_ADD_SYSTEM_ONLY = 8358,
- ERROR_DS_CLASS_MUST_BE_CONCRETE = 8359,
- ERROR_DS_INVALID_DMD = 8360,
- ERROR_DS_OBJ_GUID_EXISTS = 8361,
- ERROR_DS_NOT_ON_BACKLINK = 8362,
- ERROR_DS_NO_CROSSREF_FOR_NC = 8363,
- ERROR_DS_SHUTTING_DOWN = 8364,
- ERROR_DS_UNKNOWN_OPERATION = 8365,
- ERROR_DS_INVALID_ROLE_OWNER = 8366,
- ERROR_DS_COULDNT_CONTACT_FSMO = 8367,
- ERROR_DS_CROSS_NC_DN_RENAME = 8368,
- ERROR_DS_CANT_MOD_SYSTEM_ONLY = 8369,
- ERROR_DS_REPLICATOR_ONLY = 8370,
- ERROR_DS_OBJ_CLASS_NOT_DEFINED = 8371,
- ERROR_DS_OBJ_CLASS_NOT_SUBCLASS = 8372,
- ERROR_DS_NAME_REFERENCE_INVALID = 8373,
- ERROR_DS_CROSS_REF_EXISTS = 8374,
- ERROR_DS_CANT_DEL_MASTER_CROSSREF = 8375,
- ERROR_DS_SUBTREE_NOTIFY_NOT_NC_HEAD = 8376,
- ERROR_DS_NOTIFY_FILTER_TOO_COMPLEX = 8377,
- ERROR_DS_DUP_RDN = 8378,
- ERROR_DS_DUP_OID = 8379,
- ERROR_DS_DUP_MAPI_ID = 8380,
- ERROR_DS_DUP_SCHEMA_ID_GUID = 8381,
- ERROR_DS_DUP_LDAP_DISPLAY_NAME = 8382,
- ERROR_DS_SEMANTIC_ATT_TEST = 8383,
- ERROR_DS_SYNTAX_MISMATCH = 8384,
- ERROR_DS_EXISTS_IN_MUST_HAVE = 8385,
- ERROR_DS_EXISTS_IN_MAY_HAVE = 8386,
- ERROR_DS_NONEXISTENT_MAY_HAVE = 8387,
- ERROR_DS_NONEXISTENT_MUST_HAVE = 8388,
- ERROR_DS_AUX_CLS_TEST_FAIL = 8389,
- ERROR_DS_NONEXISTENT_POSS_SUP = 8390,
- ERROR_DS_SUB_CLS_TEST_FAIL = 8391,
- ERROR_DS_BAD_RDN_ATT_ID_SYNTAX = 8392,
- ERROR_DS_EXISTS_IN_AUX_CLS = 8393,
- ERROR_DS_EXISTS_IN_SUB_CLS = 8394,
- ERROR_DS_EXISTS_IN_POSS_SUP = 8395,
- ERROR_DS_RECALCSCHEMA_FAILED = 8396,
- ERROR_DS_TREE_DELETE_NOT_FINISHED = 8397,
- ERROR_DS_CANT_DELETE = 8398,
- ERROR_DS_ATT_SCHEMA_REQ_ID = 8399,
- ERROR_DS_BAD_ATT_SCHEMA_SYNTAX = 8400,
- ERROR_DS_CANT_CACHE_ATT = 8401,
- ERROR_DS_CANT_CACHE_CLASS = 8402,
- ERROR_DS_CANT_REMOVE_ATT_CACHE = 8403,
- ERROR_DS_CANT_REMOVE_CLASS_CACHE = 8404,
- ERROR_DS_CANT_RETRIEVE_DN = 8405,
- ERROR_DS_MISSING_SUPREF = 8406,
- ERROR_DS_CANT_RETRIEVE_INSTANCE = 8407,
- ERROR_DS_CODE_INCONSISTENCY = 8408,
- ERROR_DS_DATABASE_ERROR = 8409,
- ERROR_DS_GOVERNSID_MISSING = 8410,
- ERROR_DS_MISSING_EXPECTED_ATT = 8411,
- ERROR_DS_NCNAME_MISSING_CR_REF = 8412,
- ERROR_DS_SECURITY_CHECKING_ERROR = 8413,
- ERROR_DS_SCHEMA_NOT_LOADED = 8414,
- ERROR_DS_SCHEMA_ALLOC_FAILED = 8415,
- ERROR_DS_ATT_SCHEMA_REQ_SYNTAX = 8416,
- ERROR_DS_GCVERIFY_ERROR = 8417,
- ERROR_DS_DRA_SCHEMA_MISMATCH = 8418,
- ERROR_DS_CANT_FIND_DSA_OBJ = 8419,
- ERROR_DS_CANT_FIND_EXPECTED_NC = 8420,
- ERROR_DS_CANT_FIND_NC_IN_CACHE = 8421,
- ERROR_DS_CANT_RETRIEVE_CHILD = 8422,
- ERROR_DS_SECURITY_ILLEGAL_MODIFY = 8423,
- ERROR_DS_CANT_REPLACE_HIDDEN_REC = 8424,
- ERROR_DS_BAD_HIERARCHY_FILE = 8425,
- ERROR_DS_BUILD_HIERARCHY_TABLE_FAILED = 8426,
- ERROR_DS_CONFIG_PARAM_MISSING = 8427,
- ERROR_DS_COUNTING_AB_INDICES_FAILED = 8428,
- ERROR_DS_HIERARCHY_TABLE_MALLOC_FAILED = 8429,
- ERROR_DS_INTERNAL_FAILURE = 8430,
- ERROR_DS_UNKNOWN_ERROR = 8431,
- ERROR_DS_ROOT_REQUIRES_CLASS_TOP = 8432,
- ERROR_DS_REFUSING_FSMO_ROLES = 8433,
- ERROR_DS_MISSING_FSMO_SETTINGS = 8434,
- ERROR_DS_UNABLE_TO_SURRENDER_ROLES = 8435,
- ERROR_DS_DRA_GENERIC = 8436,
- ERROR_DS_DRA_INVALID_PARAMETER = 8437,
- ERROR_DS_DRA_BUSY = 8438,
- ERROR_DS_DRA_BAD_DN = 8439,
- ERROR_DS_DRA_BAD_NC = 8440,
- ERROR_DS_DRA_DN_EXISTS = 8441,
- ERROR_DS_DRA_INTERNAL_ERROR = 8442,
- ERROR_DS_DRA_INCONSISTENT_DIT = 8443,
- ERROR_DS_DRA_CONNECTION_FAILED = 8444,
- ERROR_DS_DRA_BAD_INSTANCE_TYPE = 8445,
- ERROR_DS_DRA_OUT_OF_MEM = 8446,
- ERROR_DS_DRA_MAIL_PROBLEM = 8447,
- ERROR_DS_DRA_REF_ALREADY_EXISTS = 8448,
- ERROR_DS_DRA_REF_NOT_FOUND = 8449,
- ERROR_DS_DRA_OBJ_IS_REP_SOURCE = 8450,
- ERROR_DS_DRA_DB_ERROR = 8451,
- ERROR_DS_DRA_NO_REPLICA = 8452,
- ERROR_DS_DRA_ACCESS_DENIED = 8453,
- ERROR_DS_DRA_NOT_SUPPORTED = 8454,
- ERROR_DS_DRA_RPC_CANCELLED = 8455,
- ERROR_DS_DRA_SOURCE_DISABLED = 8456,
- ERROR_DS_DRA_SINK_DISABLED = 8457,
- ERROR_DS_DRA_NAME_COLLISION = 8458,
- ERROR_DS_DRA_SOURCE_REINSTALLED = 8459,
- ERROR_DS_DRA_MISSING_PARENT = 8460,
- ERROR_DS_DRA_PREEMPTED = 8461,
- ERROR_DS_DRA_ABANDON_SYNC = 8462,
- ERROR_DS_DRA_SHUTDOWN = 8463,
- ERROR_DS_DRA_INCOMPATIBLE_PARTIAL_SET = 8464,
- ERROR_DS_DRA_SOURCE_IS_PARTIAL_REPLICA = 8465,
- ERROR_DS_DRA_EXTN_CONNECTION_FAILED = 8466,
- ERROR_DS_INSTALL_SCHEMA_MISMATCH = 8467,
- ERROR_DS_DUP_LINK_ID = 8468,
- ERROR_DS_NAME_ERROR_RESOLVING = 8469,
- ERROR_DS_NAME_ERROR_NOT_FOUND = 8470,
- ERROR_DS_NAME_ERROR_NOT_UNIQUE = 8471,
- ERROR_DS_NAME_ERROR_NO_MAPPING = 8472,
- ERROR_DS_NAME_ERROR_DOMAIN_ONLY = 8473,
- ERROR_DS_NAME_ERROR_NO_SYNTACTICAL_MAPPING = 8474,
- ERROR_DS_CONSTRUCTED_ATT_MOD = 8475,
- ERROR_DS_WRONG_OM_OBJ_CLASS = 8476,
- ERROR_DS_DRA_REPL_PENDING = 8477,
- ERROR_DS_DS_REQUIRED = 8478,
- ERROR_DS_INVALID_LDAP_DISPLAY_NAME = 8479,
- ERROR_DS_NON_BASE_SEARCH = 8480,
- ERROR_DS_CANT_RETRIEVE_ATTS = 8481,
- ERROR_DS_BACKLINK_WITHOUT_LINK = 8482,
- ERROR_DS_EPOCH_MISMATCH = 8483,
- ERROR_DS_SRC_NAME_MISMATCH = 8484,
- ERROR_DS_SRC_AND_DST_NC_IDENTICAL = 8485,
- ERROR_DS_DST_NC_MISMATCH = 8486,
- ERROR_DS_NOT_AUTHORITIVE_FOR_DST_NC = 8487,
- ERROR_DS_SRC_GUID_MISMATCH = 8488,
- ERROR_DS_CANT_MOVE_DELETED_OBJECT = 8489,
- ERROR_DS_PDC_OPERATION_IN_PROGRESS = 8490,
- ERROR_DS_CROSS_DOMAIN_CLEANUP_REQD = 8491,
- ERROR_DS_ILLEGAL_XDOM_MOVE_OPERATION = 8492,
- ERROR_DS_CANT_WITH_ACCT_GROUP_MEMBERSHPS = 8493,
- ERROR_DS_NC_MUST_HAVE_NC_PARENT = 8494,
- ERROR_DS_DST_DOMAIN_NOT_NATIVE = 8496,
- ERROR_DS_MISSING_INFRASTRUCTURE_CONTAINER = 8497,
- ERROR_DS_CANT_MOVE_ACCOUNT_GROUP = 8498,
- ERROR_DS_CANT_MOVE_RESOURCE_GROUP = 8499,
- ERROR_DS_INVALID_SEARCH_FLAG = 8500,
- ERROR_DS_NO_TREE_DELETE_ABOVE_NC = 8501,
- ERROR_DS_COULDNT_LOCK_TREE_FOR_DELETE = 8502,
- ERROR_DS_COULDNT_IDENTIFY_OBJECTS_FOR_TREE_DELETE = 8503,
- ERROR_DS_SAM_INIT_FAILURE = 8504,
- ERROR_DS_SENSITIVE_GROUP_VIOLATION = 8505,
- ERROR_DS_CANT_MOD_PRIMARYGROUPID = 8506,
- ERROR_DS_ILLEGAL_BASE_SCHEMA_MOD = 8507,
- ERROR_DS_NONSAFE_SCHEMA_CHANGE = 8508,
- ERROR_DS_SCHEMA_UPDATE_DISALLOWED = 8509,
- ERROR_DS_CANT_CREATE_UNDER_SCHEMA = 8510,
- ERROR_DS_INSTALL_NO_SRC_SCH_VERSION = 8511,
- ERROR_DS_INSTALL_NO_SCH_VERSION_IN_INIFILE = 8512,
- ERROR_DS_INVALID_GROUP_TYPE = 8513,
- ERROR_DS_NO_NEST_GLOBALGROUP_IN_MIXEDDOMAIN = 8514,
- ERROR_DS_NO_NEST_LOCALGROUP_IN_MIXEDDOMAIN = 8515,
- ERROR_DS_GLOBAL_CANT_HAVE_LOCAL_MEMBER = 8516,
- ERROR_DS_GLOBAL_CANT_HAVE_UNIVERSAL_MEMBER = 8517,
- ERROR_DS_UNIVERSAL_CANT_HAVE_LOCAL_MEMBER = 8518,
- ERROR_DS_GLOBAL_CANT_HAVE_CROSSDOMAIN_MEMBER = 8519,
- ERROR_DS_LOCAL_CANT_HAVE_CROSSDOMAIN_LOCAL_MEMBER = 8520,
- ERROR_DS_HAVE_PRIMARY_MEMBERS = 8521,
- ERROR_DS_STRING_SD_CONVERSION_FAILED = 8522,
- ERROR_DS_NAMING_MASTER_GC = 8523,
- ERROR_DS_LOOKUP_FAILURE = 8524,
- ERROR_DS_COULDNT_UPDATE_SPNS = 8525,
- ERROR_DS_CANT_RETRIEVE_SD = 8526,
- ERROR_DS_KEY_NOT_UNIQUE = 8527,
- ERROR_DS_WRONG_LINKED_ATT_SYNTAX = 8528,
- ERROR_DS_SAM_NEED_BOOTKEY_PASSWORD = 8529,
- ERROR_DS_SAM_NEED_BOOTKEY_FLOPPY = 8530,
- ERROR_DS_CANT_START = 8531,
- ERROR_DS_INIT_FAILURE = 8532,
- ERROR_DS_NO_PKT_PRIVACY_ON_CONNECTION = 8533,
- ERROR_DS_SOURCE_DOMAIN_IN_FOREST = 8534,
- ERROR_DS_DESTINATION_DOMAIN_NOT_IN_FOREST = 8535,
- ERROR_DS_DESTINATION_AUDITING_NOT_ENABLED = 8536,
- ERROR_DS_CANT_FIND_DC_FOR_SRC_DOMAIN = 8537,
- ERROR_DS_SRC_OBJ_NOT_GROUP_OR_USER = 8538,
- ERROR_DS_SRC_SID_EXISTS_IN_FOREST = 8539,
- ERROR_DS_SRC_AND_DST_OBJECT_CLASS_MISMATCH = 8540,
- ERROR_SAM_INIT_FAILURE = 8541,
- ERROR_DS_DRA_SCHEMA_INFO_SHIP = 8542,
- ERROR_DS_DRA_SCHEMA_CONFLICT = 8543,
- ERROR_DS_DRA_EARLIER_SCHEMA_CONLICT = 8544,
- ERROR_DS_DRA_OBJ_NC_MISMATCH = 8545,
- ERROR_DS_NC_STILL_HAS_DSAS = 8546,
- ERROR_DS_GC_REQUIRED = 8547,
- ERROR_DS_LOCAL_MEMBER_OF_LOCAL_ONLY = 8548,
- ERROR_DS_NO_FPO_IN_UNIVERSAL_GROUPS = 8549,
- ERROR_DS_CANT_ADD_TO_GC = 8550,
- ERROR_DS_NO_CHECKPOINT_WITH_PDC = 8551,
- ERROR_DS_SOURCE_AUDITING_NOT_ENABLED = 8552,
- ERROR_DS_CANT_CREATE_IN_NONDOMAIN_NC = 8553,
- ERROR_DS_INVALID_NAME_FOR_SPN = 8554,
- ERROR_DS_FILTER_USES_CONTRUCTED_ATTRS = 8555,
- ERROR_DS_UNICODEPWD_NOT_IN_QUOTES = 8556,
- ERROR_DS_MACHINE_ACCOUNT_QUOTA_EXCEEDED = 8557,
- ERROR_DS_MUST_BE_RUN_ON_DST_DC = 8558,
- ERROR_DS_SRC_DC_MUST_BE_SP4_OR_GREATER = 8559,
- ERROR_DS_CANT_TREE_DELETE_CRITICAL_OBJ = 8560,
- ERROR_DS_INIT_FAILURE_CONSOLE = 8561,
- ERROR_DS_SAM_INIT_FAILURE_CONSOLE = 8562,
- ERROR_DS_FOREST_VERSION_TOO_HIGH = 8563,
- ERROR_DS_DOMAIN_VERSION_TOO_HIGH = 8564,
- ERROR_DS_FOREST_VERSION_TOO_LOW = 8565,
- ERROR_DS_DOMAIN_VERSION_TOO_LOW = 8566,
- ERROR_DS_INCOMPATIBLE_VERSION = 8567,
- ERROR_DS_LOW_DSA_VERSION = 8568,
- ERROR_DS_NO_BEHAVIOR_VERSION_IN_MIXEDDOMAIN = 8569,
- ERROR_DS_NOT_SUPPORTED_SORT_ORDER = 8570,
- ERROR_DS_NAME_NOT_UNIQUE = 8571,
- ERROR_DS_MACHINE_ACCOUNT_CREATED_PRENT4 = 8572,
- ERROR_DS_OUT_OF_VERSION_STORE = 8573,
- ERROR_DS_INCOMPATIBLE_CONTROLS_USED = 8574,
- ERROR_DS_NO_REF_DOMAIN = 8575,
- ERROR_DS_RESERVED_LINK_ID = 8576,
- ERROR_DS_LINK_ID_NOT_AVAILABLE = 8577,
- ERROR_DS_AG_CANT_HAVE_UNIVERSAL_MEMBER = 8578,
- ERROR_DS_MODIFYDN_DISALLOWED_BY_INSTANCE_TYPE = 8579,
- ERROR_DS_NO_OBJECT_MOVE_IN_SCHEMA_NC = 8580,
- ERROR_DS_MODIFYDN_DISALLOWED_BY_FLAG = 8581,
- ERROR_DS_MODIFYDN_WRONG_GRANDPARENT = 8582,
- ERROR_DS_NAME_ERROR_TRUST_REFERRAL = 8583,
- ERROR_NOT_SUPPORTED_ON_STANDARD_SERVER = 8584,
- ERROR_DS_CANT_ACCESS_REMOTE_PART_OF_AD = 8585,
- ERROR_DS_CR_IMPOSSIBLE_TO_VALIDATE = 8586,
- ERROR_DS_THREAD_LIMIT_EXCEEDED = 8587,
- ERROR_DS_NOT_CLOSEST = 8588,
- ERROR_DS_CANT_DERIVE_SPN_WITHOUT_SERVER_REF = 8589,
- ERROR_DS_SINGLE_USER_MODE_FAILED = 8590,
- ERROR_DS_NTDSCRIPT_SYNTAX_ERROR = 8591,
- ERROR_DS_NTDSCRIPT_PROCESS_ERROR = 8592,
- ERROR_DS_DIFFERENT_REPL_EPOCHS = 8593,
- ERROR_DS_DRS_EXTENSIONS_CHANGED = 8594,
- ERROR_DS_REPLICA_SET_CHANGE_NOT_ALLOWED_ON_DISABLED_CR = 8595,
- ERROR_DS_NO_MSDS_INTID = 8596,
- ERROR_DS_DUP_MSDS_INTID = 8597,
- ERROR_DS_EXISTS_IN_RDNATTID = 8598,
- ERROR_DS_AUTHORIZATION_FAILED = 8599,
- ERROR_DS_INVALID_SCRIPT = 8600,
- ERROR_DS_REMOTE_CROSSREF_OP_FAILED = 8601,
- DNS_ERROR_RCODE_FORMAT_ERROR = 9001,
- DNS_ERROR_RCODE_SERVER_FAILURE = 9002,
- DNS_ERROR_RCODE_NAME_ERROR = 9003,
- DNS_ERROR_RCODE_NOT_IMPLEMENTED = 9004,
- DNS_ERROR_RCODE_REFUSED = 9005,
- DNS_ERROR_RCODE_YXDOMAIN = 9006,
- DNS_ERROR_RCODE_YXRRSET = 9007,
- DNS_ERROR_RCODE_NXRRSET = 9008,
- DNS_ERROR_RCODE_NOTAUTH = 9009,
- DNS_ERROR_RCODE_NOTZONE = 9010,
- DNS_ERROR_RCODE_BADSIG = 9016,
- DNS_ERROR_RCODE_BADKEY = 9017,
- DNS_ERROR_RCODE_BADTIME = 9018,
- DNS_INFO_NO_RECORDS = 9501,
- DNS_ERROR_BAD_PACKET = 9502,
- DNS_ERROR_NO_PACKET = 9503,
- DNS_ERROR_RCODE = 9504,
- DNS_ERROR_UNSECURE_PACKET = 9505,
- DNS_ERROR_INVALID_TYPE = 9551,
- DNS_ERROR_INVALID_IP_ADDRESS = 9552,
- DNS_ERROR_INVALID_PROPERTY = 9553,
- DNS_ERROR_TRY_AGAIN_LATER = 9554,
- DNS_ERROR_NOT_UNIQUE = 9555,
- DNS_ERROR_NON_RFC_NAME = 9556,
- DNS_STATUS_FQDN = 9557,
- DNS_STATUS_DOTTED_NAME = 9558,
- DNS_STATUS_SINGLE_PART_NAME = 9559,
- DNS_ERROR_INVALID_NAME_CHAR = 9560,
- DNS_ERROR_NUMERIC_NAME = 9561,
- DNS_ERROR_NOT_ALLOWED_ON_ROOT_SERVER = 9562,
- DNS_ERROR_ZONE_DOES_NOT_EXIST = 9601,
- DNS_ERROR_NO_ZONE_INFO = 9602,
- DNS_ERROR_INVALID_ZONE_OPERATION = 9603,
- DNS_ERROR_ZONE_CONFIGURATION_ERROR = 9604,
- DNS_ERROR_ZONE_HAS_NO_SOA_RECORD = 9605,
- DNS_ERROR_ZONE_HAS_NO_NS_RECORDS = 9606,
- DNS_ERROR_ZONE_LOCKED = 9607,
- DNS_ERROR_ZONE_CREATION_FAILED = 9608,
- DNS_ERROR_ZONE_ALREADY_EXISTS = 9609,
- DNS_ERROR_AUTOZONE_ALREADY_EXISTS = 9610,
- DNS_ERROR_INVALID_ZONE_TYPE = 9611,
- DNS_ERROR_SECONDARY_REQUIRES_MASTER_IP = 9612,
- DNS_ERROR_ZONE_NOT_SECONDARY = 9613,
- DNS_ERROR_NEED_SECONDARY_ADDRESSES = 9614,
- DNS_ERROR_WINS_INIT_FAILED = 9615,
- DNS_ERROR_NEED_WINS_SERVERS = 9616,
- DNS_ERROR_NBSTAT_INIT_FAILED = 9617,
- DNS_ERROR_SOA_DELETE_INVALID = 9618,
- DNS_ERROR_FORWARDER_ALREADY_EXISTS = 9619,
- DNS_ERROR_ZONE_REQUIRES_MASTER_IP = 9620,
- DNS_ERROR_ZONE_IS_SHUTDOWN = 9621,
- DNS_ERROR_PRIMARY_REQUIRES_DATAFILE = 9651,
- DNS_ERROR_INVALID_DATAFILE_NAME = 9652,
- DNS_ERROR_DATAFILE_OPEN_FAILURE = 9653,
- DNS_ERROR_FILE_WRITEBACK_FAILED = 9654,
- DNS_ERROR_DATAFILE_PARSING = 9655,
- DNS_ERROR_RECORD_DOES_NOT_EXIST = 9701,
- DNS_ERROR_RECORD_FORMAT = 9702,
- DNS_ERROR_NODE_CREATION_FAILED = 9703,
- DNS_ERROR_UNKNOWN_RECORD_TYPE = 9704,
- DNS_ERROR_RECORD_TIMED_OUT = 9705,
- DNS_ERROR_NAME_NOT_IN_ZONE = 9706,
- DNS_ERROR_CNAME_LOOP = 9707,
- DNS_ERROR_NODE_IS_CNAME = 9708,
- DNS_ERROR_CNAME_COLLISION = 9709,
- DNS_ERROR_RECORD_ONLY_AT_ZONE_ROOT = 9710,
- DNS_ERROR_RECORD_ALREADY_EXISTS = 9711,
- DNS_ERROR_SECONDARY_DATA = 9712,
- DNS_ERROR_NO_CREATE_CACHE_DATA = 9713,
- DNS_ERROR_NAME_DOES_NOT_EXIST = 9714,
- DNS_WARNING_PTR_CREATE_FAILED = 9715,
- DNS_WARNING_DOMAIN_UNDELETED = 9716,
- DNS_ERROR_DS_UNAVAILABLE = 9717,
- DNS_ERROR_DS_ZONE_ALREADY_EXISTS = 9718,
- DNS_ERROR_NO_BOOTFILE_IF_DS_ZONE = 9719,
- DNS_INFO_AXFR_COMPLETE = 9751,
- DNS_ERROR_AXFR = 9752,
- DNS_INFO_ADDED_LOCAL_WINS = 9753,
- DNS_STATUS_CONTINUE_NEEDED = 9801,
- DNS_ERROR_NO_TCPIP = 9851,
- DNS_ERROR_NO_DNS_SERVERS = 9852,
- DNS_ERROR_DP_DOES_NOT_EXIST = 9901,
- DNS_ERROR_DP_ALREADY_EXISTS = 9902,
- DNS_ERROR_DP_NOT_ENLISTED = 9903,
- DNS_ERROR_DP_ALREADY_ENLISTED = 9904,
- WSAEINTR = 10004,
- WSAEBADF = 10009,
- WSAEACCES = 10013,
- WSAEFAULT = 10014,
- WSAEINVAL = 10022,
- WSAEMFILE = 10024,
- WSAEWOULDBLOCK = 10035,
- WSAEINPROGRESS = 10036,
- WSAEALREADY = 10037,
- WSAENOTSOCK = 10038,
- WSAEDESTADDRREQ = 10039,
- WSAEMSGSIZE = 10040,
- WSAEPROTOTYPE = 10041,
- WSAENOPROTOOPT = 10042,
- WSAEPROTONOSUPPORT = 10043,
- WSAESOCKTNOSUPPORT = 10044,
- WSAEOPNOTSUPP = 10045,
- WSAEPFNOSUPPORT = 10046,
- WSAEAFNOSUPPORT = 10047,
- WSAEADDRINUSE = 10048,
- WSAEADDRNOTAVAIL = 10049,
- WSAENETDOWN = 10050,
- WSAENETUNREACH = 10051,
- WSAENETRESET = 10052,
- WSAECONNABORTED = 10053,
- WSAECONNRESET = 10054,
- WSAENOBUFS = 10055,
- WSAEISCONN = 10056,
- WSAENOTCONN = 10057,
- WSAESHUTDOWN = 10058,
- WSAETOOMANYREFS = 10059,
- WSAETIMEDOUT = 10060,
- WSAECONNREFUSED = 10061,
- WSAELOOP = 10062,
- WSAENAMETOOLONG = 10063,
- WSAEHOSTDOWN = 10064,
- WSAEHOSTUNREACH = 10065,
- WSAENOTEMPTY = 10066,
- WSAEPROCLIM = 10067,
- WSAEUSERS = 10068,
- WSAEDQUOT = 10069,
- WSAESTALE = 10070,
- WSAEREMOTE = 10071,
- WSASYSNOTREADY = 10091,
- WSAVERNOTSUPPORTED = 10092,
- WSANOTINITIALISED = 10093,
- WSAEDISCON = 10101,
- WSAENOMORE = 10102,
- WSAECANCELLED = 10103,
- WSAEINVALIDPROCTABLE = 10104,
- WSAEINVALIDPROVIDER = 10105,
- WSAEPROVIDERFAILEDINIT = 10106,
- WSASYSCALLFAILURE = 10107,
- WSASERVICE_NOT_FOUND = 10108,
- WSATYPE_NOT_FOUND = 10109,
- WSA_E_NO_MORE = 10110,
- WSA_E_CANCELLED = 10111,
- WSAEREFUSED = 10112,
- WSAHOST_NOT_FOUND = 11001,
- WSATRY_AGAIN = 11002,
- WSANO_RECOVERY = 11003,
- WSANO_DATA = 11004,
- WSA_QOS_RECEIVERS = 11005,
- WSA_QOS_SENDERS = 11006,
- WSA_QOS_NO_SENDERS = 11007,
- WSA_QOS_NO_RECEIVERS = 11008,
- WSA_QOS_REQUEST_CONFIRMED = 11009,
- WSA_QOS_ADMISSION_FAILURE = 11010,
- WSA_QOS_POLICY_FAILURE = 11011,
- WSA_QOS_BAD_STYLE = 11012,
- WSA_QOS_BAD_OBJECT = 11013,
- WSA_QOS_TRAFFIC_CTRL_ERROR = 11014,
- WSA_QOS_GENERIC_ERROR = 11015,
- WSA_QOS_ESERVICETYPE = 11016,
- WSA_QOS_EFLOWSPEC = 11017,
- WSA_QOS_EPROVSPECBUF = 11018,
- WSA_QOS_EFILTERSTYLE = 11019,
- WSA_QOS_EFILTERTYPE = 11020,
- WSA_QOS_EFILTERCOUNT = 11021,
- WSA_QOS_EOBJLENGTH = 11022,
- WSA_QOS_EFLOWCOUNT = 11023,
- WSA_QOS_EUNKNOWNPSOBJ = 11024,
- WSA_QOS_EPOLICYOBJ = 11025,
- WSA_QOS_EFLOWDESC = 11026,
- WSA_QOS_EPSFLOWSPEC = 11027,
- WSA_QOS_EPSFILTERSPEC = 11028,
- WSA_QOS_ESDMODEOBJ = 11029,
- WSA_QOS_ESHAPERATEOBJ = 11030,
- WSA_QOS_RESERVED_PETYPE = 11031,
- ERROR_IPSEC_QM_POLICY_EXISTS = 13000,
- ERROR_IPSEC_QM_POLICY_NOT_FOUND = 13001,
- ERROR_IPSEC_QM_POLICY_IN_USE = 13002,
- ERROR_IPSEC_MM_POLICY_EXISTS = 13003,
- ERROR_IPSEC_MM_POLICY_NOT_FOUND = 13004,
- ERROR_IPSEC_MM_POLICY_IN_USE = 13005,
- ERROR_IPSEC_MM_FILTER_EXISTS = 13006,
- ERROR_IPSEC_MM_FILTER_NOT_FOUND = 13007,
- ERROR_IPSEC_TRANSPORT_FILTER_EXISTS = 13008,
- ERROR_IPSEC_TRANSPORT_FILTER_NOT_FOUND = 13009,
- ERROR_IPSEC_MM_AUTH_EXISTS = 13010,
- ERROR_IPSEC_MM_AUTH_NOT_FOUND = 13011,
- ERROR_IPSEC_MM_AUTH_IN_USE = 13012,
- ERROR_IPSEC_DEFAULT_MM_POLICY_NOT_FOUND = 13013,
- ERROR_IPSEC_DEFAULT_MM_AUTH_NOT_FOUND = 13014,
- ERROR_IPSEC_DEFAULT_QM_POLICY_NOT_FOUND = 13015,
- ERROR_IPSEC_TUNNEL_FILTER_EXISTS = 13016,
- ERROR_IPSEC_TUNNEL_FILTER_NOT_FOUND = 13017,
- ERROR_IPSEC_MM_FILTER_PENDING_DELETION = 13018,
- ERROR_IPSEC_TRANSPORT_FILTER_PENDING_DELETION = 13019,
- ERROR_IPSEC_TUNNEL_FILTER_PENDING_DELETION = 13020,
- ERROR_IPSEC_MM_POLICY_PENDING_DELETION = 13021,
- ERROR_IPSEC_MM_AUTH_PENDING_DELETION = 13022,
- ERROR_IPSEC_QM_POLICY_PENDING_DELETION = 13023,
- ERROR_IPSEC_IKE_AUTH_FAIL = 13801,
- ERROR_IPSEC_IKE_ATTRIB_FAIL = 13802,
- ERROR_IPSEC_IKE_NEGOTIATION_PENDING = 13803,
- ERROR_IPSEC_IKE_GENERAL_PROCESSING_ERROR = 13804,
- ERROR_IPSEC_IKE_TIMED_OUT = 13805,
- ERROR_IPSEC_IKE_NO_CERT = 13806,
- ERROR_IPSEC_IKE_SA_DELETED = 13807,
- ERROR_IPSEC_IKE_SA_REAPED = 13808,
- ERROR_IPSEC_IKE_MM_ACQUIRE_DROP = 13809,
- ERROR_IPSEC_IKE_QM_ACQUIRE_DROP = 13810,
- ERROR_IPSEC_IKE_QUEUE_DROP_MM = 13811,
- ERROR_IPSEC_IKE_QUEUE_DROP_NO_MM = 13812,
- ERROR_IPSEC_IKE_DROP_NO_RESPONSE = 13813,
- ERROR_IPSEC_IKE_MM_DELAY_DROP = 13814,
- ERROR_IPSEC_IKE_QM_DELAY_DROP = 13815,
- ERROR_IPSEC_IKE_ERROR = 13816,
- ERROR_IPSEC_IKE_CRL_FAILED = 13817,
- ERROR_IPSEC_IKE_INVALID_KEY_USAGE = 13818,
- ERROR_IPSEC_IKE_INVALID_CERT_TYPE = 13819,
- ERROR_IPSEC_IKE_NO_PRIVATE_KEY = 13820,
- ERROR_IPSEC_IKE_DH_FAIL = 13822,
- ERROR_IPSEC_IKE_INVALID_HEADER = 13824,
- ERROR_IPSEC_IKE_NO_POLICY = 13825,
- ERROR_IPSEC_IKE_INVALID_SIGNATURE = 13826,
- ERROR_IPSEC_IKE_KERBEROS_ERROR = 13827,
- ERROR_IPSEC_IKE_NO_PUBLIC_KEY = 13828,
- ERROR_IPSEC_IKE_PROCESS_ERR = 13829,
- ERROR_IPSEC_IKE_PROCESS_ERR_SA = 13830,
- ERROR_IPSEC_IKE_PROCESS_ERR_PROP = 13831,
- ERROR_IPSEC_IKE_PROCESS_ERR_TRANS = 13832,
- ERROR_IPSEC_IKE_PROCESS_ERR_KE = 13833,
- ERROR_IPSEC_IKE_PROCESS_ERR_ID = 13834,
- ERROR_IPSEC_IKE_PROCESS_ERR_CERT = 13835,
- ERROR_IPSEC_IKE_PROCESS_ERR_CERT_REQ = 13836,
- ERROR_IPSEC_IKE_PROCESS_ERR_HASH = 13837,
- ERROR_IPSEC_IKE_PROCESS_ERR_SIG = 13838,
- ERROR_IPSEC_IKE_PROCESS_ERR_NONCE = 13839,
- ERROR_IPSEC_IKE_PROCESS_ERR_NOTIFY = 13840,
- ERROR_IPSEC_IKE_PROCESS_ERR_DELETE = 13841,
- ERROR_IPSEC_IKE_PROCESS_ERR_VENDOR = 13842,
- ERROR_IPSEC_IKE_INVALID_PAYLOAD = 13843,
- ERROR_IPSEC_IKE_LOAD_SOFT_SA = 13844,
- ERROR_IPSEC_IKE_SOFT_SA_TORN_DOWN = 13845,
- ERROR_IPSEC_IKE_INVALID_COOKIE = 13846,
- ERROR_IPSEC_IKE_NO_PEER_CERT = 13847,
- ERROR_IPSEC_IKE_PEER_CRL_FAILED = 13848,
- ERROR_IPSEC_IKE_POLICY_CHANGE = 13849,
- ERROR_IPSEC_IKE_NO_MM_POLICY = 13850,
- ERROR_IPSEC_IKE_NOTCBPRIV = 13851,
- ERROR_IPSEC_IKE_SECLOADFAIL = 13852,
- ERROR_IPSEC_IKE_FAILSSPINIT = 13853,
- ERROR_IPSEC_IKE_FAILQUERYSSP = 13854,
- ERROR_IPSEC_IKE_SRVACQFAIL = 13855,
- ERROR_IPSEC_IKE_SRVQUERYCRED = 13856,
- ERROR_IPSEC_IKE_GETSPIFAIL = 13857,
- ERROR_IPSEC_IKE_INVALID_FILTER = 13858,
- ERROR_IPSEC_IKE_OUT_OF_MEMORY = 13859,
- ERROR_IPSEC_IKE_ADD_UPDATE_KEY_FAILED = 13860,
- ERROR_IPSEC_IKE_INVALID_POLICY = 13861,
- ERROR_IPSEC_IKE_UNKNOWN_DOI = 13862,
- ERROR_IPSEC_IKE_INVALID_SITUATION = 13863,
- ERROR_IPSEC_IKE_DH_FAILURE = 13864,
- ERROR_IPSEC_IKE_INVALID_GROUP = 13865,
- ERROR_IPSEC_IKE_ENCRYPT = 13866,
- ERROR_IPSEC_IKE_DECRYPT = 13867,
- ERROR_IPSEC_IKE_POLICY_MATCH = 13868,
- ERROR_IPSEC_IKE_UNSUPPORTED_ID = 13869,
- ERROR_IPSEC_IKE_INVALID_HASH = 13870,
- ERROR_IPSEC_IKE_INVALID_HASH_ALG = 13871,
- ERROR_IPSEC_IKE_INVALID_HASH_SIZE = 13872,
- ERROR_IPSEC_IKE_INVALID_ENCRYPT_ALG = 13873,
- ERROR_IPSEC_IKE_INVALID_AUTH_ALG = 13874,
- ERROR_IPSEC_IKE_INVALID_SIG = 13875,
- ERROR_IPSEC_IKE_LOAD_FAILED = 13876,
- ERROR_IPSEC_IKE_RPC_DELETE = 13877,
- ERROR_IPSEC_IKE_BENIGN_REINIT = 13878,
- ERROR_IPSEC_IKE_INVALID_RESPONDER_LIFETIME_NOTIFY = 13879,
- ERROR_IPSEC_IKE_INVALID_CERT_KEYLEN = 13881,
- ERROR_IPSEC_IKE_MM_LIMIT = 13882,
- ERROR_IPSEC_IKE_NEGOTIATION_DISABLED = 13883,
- ERROR_IPSEC_IKE_NEG_STATUS_END = 13884,
- ERROR_SXS_SECTION_NOT_FOUND = 14000,
- ERROR_SXS_CANT_GEN_ACTCTX = 14001,
- ERROR_SXS_INVALID_ACTCTXDATA_FORMAT = 14002,
- ERROR_SXS_ASSEMBLY_NOT_FOUND = 14003,
- ERROR_SXS_MANIFEST_FORMAT_ERROR = 14004,
- ERROR_SXS_MANIFEST_PARSE_ERROR = 14005,
- ERROR_SXS_ACTIVATION_CONTEXT_DISABLED = 14006,
- ERROR_SXS_KEY_NOT_FOUND = 14007,
- ERROR_SXS_VERSION_CONFLICT = 14008,
- ERROR_SXS_WRONG_SECTION_TYPE = 14009,
- ERROR_SXS_THREAD_QUERIES_DISABLED = 14010,
- ERROR_SXS_PROCESS_DEFAULT_ALREADY_SET = 14011,
- ERROR_SXS_UNKNOWN_ENCODING_GROUP = 14012,
- ERROR_SXS_UNKNOWN_ENCODING = 14013,
- ERROR_SXS_INVALID_XML_NAMESPACE_URI = 14014,
- ERROR_SXS_ROOT_MANIFEST_DEPENDENCY_NOT_INSTALLED = 14015,
- ERROR_SXS_LEAF_MANIFEST_DEPENDENCY_NOT_INSTALLED = 14016,
- ERROR_SXS_INVALID_ASSEMBLY_IDENTITY_ATTRIBUTE = 14017,
- ERROR_SXS_MANIFEST_MISSING_REQUIRED_DEFAULT_NAMESPACE = 14018,
- ERROR_SXS_MANIFEST_INVALID_REQUIRED_DEFAULT_NAMESPACE = 14019,
- ERROR_SXS_PRIVATE_MANIFEST_CROSS_PATH_WITH_REPARSE_POINT = 14020,
- ERROR_SXS_DUPLICATE_DLL_NAME = 14021,
- ERROR_SXS_DUPLICATE_WINDOWCLASS_NAME = 14022,
- ERROR_SXS_DUPLICATE_CLSID = 14023,
- ERROR_SXS_DUPLICATE_IID = 14024,
- ERROR_SXS_DUPLICATE_TLBID = 14025,
- ERROR_SXS_DUPLICATE_PROGID = 14026,
- ERROR_SXS_DUPLICATE_ASSEMBLY_NAME = 14027,
- ERROR_SXS_FILE_HASH_MISMATCH = 14028,
- ERROR_SXS_POLICY_PARSE_ERROR = 14029,
- ERROR_SXS_XML_E_MISSINGQUOTE = 14030,
- ERROR_SXS_XML_E_COMMENTSYNTAX = 14031,
- ERROR_SXS_XML_E_BADSTARTNAMECHAR = 14032,
- ERROR_SXS_XML_E_BADNAMECHAR = 14033,
- ERROR_SXS_XML_E_BADCHARINSTRING = 14034,
- ERROR_SXS_XML_E_XMLDECLSYNTAX = 14035,
- ERROR_SXS_XML_E_BADCHARDATA = 14036,
- ERROR_SXS_XML_E_MISSINGWHITESPACE = 14037,
- ERROR_SXS_XML_E_EXPECTINGTAGEND = 14038,
- ERROR_SXS_XML_E_MISSINGSEMICOLON = 14039,
- ERROR_SXS_XML_E_UNBALANCEDPAREN = 14040,
- ERROR_SXS_XML_E_INTERNALERROR = 14041,
- ERROR_SXS_XML_E_UNEXPECTED_WHITESPACE = 14042,
- ERROR_SXS_XML_E_INCOMPLETE_ENCODING = 14043,
- ERROR_SXS_XML_E_MISSING_PAREN = 14044,
- ERROR_SXS_XML_E_EXPECTINGCLOSEQUOTE = 14045,
- ERROR_SXS_XML_E_MULTIPLE_COLONS = 14046,
- ERROR_SXS_XML_E_INVALID_DECIMAL = 14047,
- ERROR_SXS_XML_E_INVALID_HEXIDECIMAL = 14048,
- ERROR_SXS_XML_E_INVALID_UNICODE = 14049,
- ERROR_SXS_XML_E_WHITESPACEORQUESTIONMARK = 14050,
- ERROR_SXS_XML_E_UNEXPECTEDENDTAG = 14051,
- ERROR_SXS_XML_E_UNCLOSEDTAG = 14052,
- ERROR_SXS_XML_E_DUPLICATEATTRIBUTE = 14053,
- ERROR_SXS_XML_E_MULTIPLEROOTS = 14054,
- ERROR_SXS_XML_E_INVALIDATROOTLEVEL = 14055,
- ERROR_SXS_XML_E_BADXMLDECL = 14056,
- ERROR_SXS_XML_E_MISSINGROOT = 14057,
- ERROR_SXS_XML_E_UNEXPECTEDEOF = 14058,
- ERROR_SXS_XML_E_BADPEREFINSUBSET = 14059,
- ERROR_SXS_XML_E_UNCLOSEDSTARTTAG = 14060,
- ERROR_SXS_XML_E_UNCLOSEDENDTAG = 14061,
- ERROR_SXS_XML_E_UNCLOSEDSTRING = 14062,
- ERROR_SXS_XML_E_UNCLOSEDCOMMENT = 14063,
- ERROR_SXS_XML_E_UNCLOSEDDECL = 14064,
- ERROR_SXS_XML_E_UNCLOSEDCDATA = 14065,
- ERROR_SXS_XML_E_RESERVEDNAMESPACE = 14066,
- ERROR_SXS_XML_E_INVALIDENCODING = 14067,
- ERROR_SXS_XML_E_INVALIDSWITCH = 14068,
- ERROR_SXS_XML_E_BADXMLCASE = 14069,
- ERROR_SXS_XML_E_INVALID_STANDALONE = 14070,
- ERROR_SXS_XML_E_UNEXPECTED_STANDALONE = 14071,
- ERROR_SXS_XML_E_INVALID_VERSION = 14072,
- ERROR_SXS_XML_E_MISSINGEQUALS = 14073,
- ERROR_SXS_PROTECTION_RECOVERY_FAILED = 14074,
- ERROR_SXS_PROTECTION_PUBLIC_KEY_TOO_SHORT = 14075,
- ERROR_SXS_PROTECTION_CATALOG_NOT_VALID = 14076,
- ERROR_SXS_UNTRANSLATABLE_HRESULT = 14077,
- ERROR_SXS_PROTECTION_CATALOG_FILE_MISSING = 14078,
- ERROR_SXS_MISSING_ASSEMBLY_IDENTITY_ATTRIBUTE = 14079,
- ERROR_SXS_INVALID_ASSEMBLY_IDENTITY_ATTRIBUTE_NAME = 14080 */
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/IO/Stream.Mono.cs b/netcore/System.Private.CoreLib/src/System/IO/Stream.Mono.cs
deleted file mode 100644
index 3e0c4e47a02..00000000000
--- a/netcore/System.Private.CoreLib/src/System/IO/Stream.Mono.cs
+++ /dev/null
@@ -1,17 +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 System.Runtime.CompilerServices;
-
-namespace System.IO
-{
- partial class Stream
- {
- [MethodImpl (MethodImplOptions.InternalCall)]
- extern bool HasOverriddenBeginEndRead ();
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- extern bool HasOverriddenBeginEndWrite ();
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Math.Mono.cs b/netcore/System.Private.CoreLib/src/System/Math.Mono.cs
deleted file mode 100644
index 6f6fe9eb724..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Math.Mono.cs
+++ /dev/null
@@ -1,99 +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 System.Runtime.CompilerServices;
-
-namespace System
-{
- partial class Math
- {
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Abs (double value);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Abs (float value);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Acos (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Acosh (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Asin (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Asinh (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Atan (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Atan2 (double y, double x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Atanh (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Cbrt (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Ceiling (double a);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Cos (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Cosh (double value);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Exp (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Floor (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Log (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Log10 (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Pow (double x, double y);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Sin (double a);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Sinh (double value);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Sqrt (double d);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Tan (double a);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Tanh (double value);
-
- [Intrinsic]
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double FusedMultiplyAdd (double x, double y, double z);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern int ILogB (double x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double Log2 (double x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern double ScaleB (double x, int n);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern double FMod(double x, double y);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern unsafe double ModF(double x, double* intptr);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/MathF.Mono.cs b/netcore/System.Private.CoreLib/src/System/MathF.Mono.cs
deleted file mode 100644
index 16d04343814..00000000000
--- a/netcore/System.Private.CoreLib/src/System/MathF.Mono.cs
+++ /dev/null
@@ -1,93 +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 System.Runtime.CompilerServices;
-
-namespace System
-{
- partial class MathF
- {
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Acos (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Acosh (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Asin (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Asinh (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Atan (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Atan2 (float y, float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Atanh (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Cbrt (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Ceiling (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Cos (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Cosh (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Exp (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Floor (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Log (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Log10 (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Pow (float x, float y);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Sin (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Sinh (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Sqrt (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Tan (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Tanh (float x);
-
- [Intrinsic]
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float FusedMultiplyAdd (float x, float y, float z);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern int ILogB (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float Log2 (float x);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- public static extern float ScaleB (float x, int n);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern float FMod (float x, float y);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern unsafe float ModF (float x, float* intptr);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/MissingMemberException.Mono.cs b/netcore/System.Private.CoreLib/src/System/MissingMemberException.Mono.cs
deleted file mode 100644
index a346eea450b..00000000000
--- a/netcore/System.Private.CoreLib/src/System/MissingMemberException.Mono.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System
-{
- partial class MissingMemberException
- {
- internal static string FormatSignature (byte[] signature)
- {
- return "";
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/ModuleHandle.cs b/netcore/System.Private.CoreLib/src/System/ModuleHandle.cs
deleted file mode 100644
index ce0e6a1e4dd..00000000000
--- a/netcore/System.Private.CoreLib/src/System/ModuleHandle.cs
+++ /dev/null
@@ -1,142 +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 System.Reflection;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- public struct ModuleHandle
- {
- readonly IntPtr value;
-
- public static readonly ModuleHandle EmptyHandle = new ModuleHandle (IntPtr.Zero);
-
- internal ModuleHandle (IntPtr v)
- {
- value = v;
- }
-
- internal IntPtr Value {
- get {
- return value;
- }
- }
-
- public int MDStreamVersion {
- get {
- if (value == IntPtr.Zero)
- throw new ArgumentNullException (String.Empty, "Invalid handle");
- return RuntimeModule.GetMDStreamVersion (value);
- }
- }
-
- public RuntimeFieldHandle ResolveFieldHandle (int fieldToken)
- {
- return ResolveFieldHandle (fieldToken, null, null);
- }
-
- public RuntimeMethodHandle ResolveMethodHandle (int methodToken)
- {
- return ResolveMethodHandle (methodToken, null, null);
- }
-
- public RuntimeTypeHandle ResolveTypeHandle (int typeToken)
- {
- return ResolveTypeHandle (typeToken, null, null);
- }
-
- static IntPtr[]? ptrs_from_handles (RuntimeTypeHandle[]? handles)
- {
- if (handles == null)
- return null;
-
- var res = new IntPtr [handles.Length];
- for (int i = 0; i < handles.Length; ++i)
- res [i] = handles [i].Value;
- return res;
- }
-
- public RuntimeTypeHandle ResolveTypeHandle (int typeToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
- {
- ResolveTokenError error;
- if (value == IntPtr.Zero)
- throw new ArgumentNullException (String.Empty, "Invalid handle");
- IntPtr res = RuntimeModule.ResolveTypeToken (value, typeToken, ptrs_from_handles (typeInstantiationContext), ptrs_from_handles (methodInstantiationContext), out error);
- if (res == IntPtr.Zero)
- throw new TypeLoadException (String.Format ("Could not load type '0x{0:x}' from assembly '0x{1:x}'", typeToken, value.ToInt64 ()));
- else
- return new RuntimeTypeHandle (res);
- }
-
- public RuntimeMethodHandle ResolveMethodHandle (int methodToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
- {
- ResolveTokenError error;
- if (value == IntPtr.Zero)
- throw new ArgumentNullException (String.Empty, "Invalid handle");
- IntPtr res = RuntimeModule.ResolveMethodToken (value, methodToken, ptrs_from_handles (typeInstantiationContext), ptrs_from_handles (methodInstantiationContext), out error);
- if (res == IntPtr.Zero)
- throw new Exception (String.Format ("Could not load method '0x{0:x}' from assembly '0x{1:x}'", methodToken, value.ToInt64 ()));
- else
- return new RuntimeMethodHandle (res);
- }
-
- public RuntimeFieldHandle ResolveFieldHandle (int fieldToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
- {
- ResolveTokenError error;
- if (value == IntPtr.Zero)
- throw new ArgumentNullException (String.Empty, "Invalid handle");
-
- IntPtr res = RuntimeModule.ResolveFieldToken (value, fieldToken, ptrs_from_handles (typeInstantiationContext), ptrs_from_handles (methodInstantiationContext), out error);
- if (res == IntPtr.Zero)
- throw new Exception (String.Format ("Could not load field '0x{0:x}' from assembly '0x{1:x}'", fieldToken, value.ToInt64 ()));
- else
- return new RuntimeFieldHandle (res);
- }
-
- public RuntimeFieldHandle GetRuntimeFieldHandleFromMetadataToken (int fieldToken)
- {
- return ResolveFieldHandle (fieldToken);
- }
-
- public RuntimeMethodHandle GetRuntimeMethodHandleFromMetadataToken (int methodToken)
- {
- return ResolveMethodHandle (methodToken);
- }
-
- public RuntimeTypeHandle GetRuntimeTypeHandleFromMetadataToken (int typeToken)
- {
- return ResolveTypeHandle (typeToken);
- }
-
- public override bool Equals (object? obj)
- {
- if (obj == null || GetType () != obj.GetType ())
- return false;
-
- return value == ((ModuleHandle)obj).Value;
- }
-
- public bool Equals (ModuleHandle handle)
- {
- return value == handle.Value;
- }
-
- public override int GetHashCode ()
- {
- return value.GetHashCode ();
- }
-
- public static bool operator == (ModuleHandle left, ModuleHandle right)
- {
- return Equals (left, right);
- }
-
- public static bool operator != (ModuleHandle left, ModuleHandle right)
- {
- return !Equals (left, right);
- }
- }
-}
-
diff --git a/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs b/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs
deleted file mode 100644
index 5205ef060e2..00000000000
--- a/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs
+++ /dev/null
@@ -1,262 +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 System.Collections.Generic;
-using System.Reflection;
-using System.Runtime.Serialization;
-using System.Runtime.InteropServices;
-
-namespace System
-{
- [StructLayout (LayoutKind.Sequential)]
- public abstract class MulticastDelegate : Delegate
- {
- Delegate[]? delegates;
-
- protected MulticastDelegate (object target, string method)
- : base (target, method)
- {
- }
-
- protected MulticastDelegate (Type target, string method)
- : base (target, method)
- {
- }
-
- public override void GetObjectData (SerializationInfo info, StreamingContext context)
- {
- throw new SerializationException (SR.Serialization_DelegatesNotSupported);
- }
-
- protected sealed override object? DynamicInvokeImpl (object?[]? args)
- {
- if (delegates == null) {
- return base.DynamicInvokeImpl (args);
- } else {
- object r;
- int i = 0, len = delegates.Length;
- do {
- r = delegates [i].DynamicInvoke (args);
- } while (++i < len);
- return r;
- }
- }
-
- // Some high-performance applications use this internal property
- // to avoid using a slow path to determine if there is more than one handler
- // This brings an API that we removed in f410e545e2db0e0dc338673a6b10a5cfd2d3340f
- // which some users depeneded on
- //
- // This is an example of code that used this:
- // https://gist.github.com/migueldeicaza/cd99938c2a4372e7e5d5
- //
- // Do not remove this API
- internal bool HasSingleTarget {
- get { return delegates == null; }
- }
-
- // <remarks>
- // Equals: two multicast delegates are equal if their base is equal
- // and their invocations list is equal.
- // </remarks>
- public sealed override bool Equals (object? obj)
- {
- if (!base.Equals (obj))
- return false;
-
- if (!(obj is MulticastDelegate d))
- return false;
-
- if (delegates == null && d.delegates == null) {
- return true;
- } else if (delegates == null ^ d.delegates == null) {
- return false;
- } else {
- if (delegates.Length != d.delegates.Length)
- return false;
-
- for (int i = 0; i < delegates.Length; ++i) {
- if (!delegates [i].Equals (d.delegates [i]))
- return false;
- }
-
- return true;
- }
- }
-
- //
- // FIXME: This could use some improvements.
- //
- public sealed override int GetHashCode ()
- {
- return base.GetHashCode ();
- }
-
- protected override MethodInfo GetMethodImpl ()
- {
- if (delegates != null)
- return delegates [delegates.Length - 1].Method;
-
- return base.GetMethodImpl ();
- }
-
- // <summary>
- // Return, in order of invocation, the invocation list
- // of a MulticastDelegate
- // </summary>
- public sealed override Delegate[] GetInvocationList ()
- {
- if (delegates != null)
- return (Delegate[]) delegates.Clone ();
- else
- return new Delegate[1] { this };
- }
-
- // <summary>
- // Combines this MulticastDelegate with the (Multicast)Delegate `follow'.
- // This does _not_ combine with Delegates. ECMA states the whole delegate
- // thing should have better been a simple System.Delegate class.
- // Compiler generated delegates are always MulticastDelegates.
- // </summary>
- protected sealed override Delegate CombineImpl (Delegate? follow)
- {
- if (follow == null)
- return this;
-
- MulticastDelegate other = (MulticastDelegate) follow;
-
- MulticastDelegate ret = AllocDelegateLike_internal (this);
-
- if (delegates == null && other.delegates == null) {
- ret.delegates = new Delegate [2] { this, other };
- } else if (delegates == null) {
- ret.delegates = new Delegate [1 + other.delegates.Length];
-
- ret.delegates [0] = this;
- Array.Copy (other.delegates, 0, ret.delegates, 1, other.delegates.Length);
- } else if (other.delegates == null) {
- ret.delegates = new Delegate [delegates.Length + 1];
-
- Array.Copy (delegates, 0, ret.delegates, 0, delegates.Length);
- ret.delegates [ret.delegates.Length - 1] = other;
- } else {
- ret.delegates = new Delegate [delegates.Length + other.delegates.Length];
-
- Array.Copy (delegates, 0, ret.delegates, 0, delegates.Length);
- Array.Copy (other.delegates, 0, ret.delegates, delegates.Length, other.delegates.Length);
- }
-
- return ret;
- }
-
- /* Based on the Boyer–Moore string search algorithm */
- int LastIndexOf (Delegate[] haystack, Delegate[] needle)
- {
- if (haystack.Length < needle.Length)
- return -1;
-
- if (haystack.Length == needle.Length) {
- for (int i = 0; i < haystack.Length; ++i)
- if (!haystack [i].Equals (needle [i]))
- return -1;
-
- return 0;
- }
-
- for (int i = haystack.Length - needle.Length, j; i >= 0;) {
- for (j = 0; needle [j].Equals (haystack [i]); ++i, ++j) {
- if (j == needle.Length - 1)
- return i - j;
- }
-
- i -= j + 1;
- }
-
- return -1;
- }
-
- protected sealed override Delegate RemoveImpl (Delegate value)
- {
- if (value == null)
- return this;
-
- MulticastDelegate other = (MulticastDelegate) value;
-
- if (delegates == null && other.delegates == null) {
- /* if they are not equal and the current one is not
- * a multicastdelegate then we cannot delete it */
- return this.Equals (other) ? null : this;
- } else if (delegates == null) {
- foreach (var d in other.delegates) {
- if (this.Equals (d))
- return null;
- }
- return this;
- } else if (other.delegates == null) {
- int idx = Array.LastIndexOf (delegates, other);
- if (idx == -1)
- return this;
-
- if (delegates.Length <= 1) {
- /* delegates.Length should never be equal or
- * lower than 1, it should be 2 or greater */
- throw new InvalidOperationException ();
- }
-
- if (delegates.Length == 2)
- return delegates [idx == 0 ? 1 : 0];
-
- MulticastDelegate ret = AllocDelegateLike_internal (this);
- ret.delegates = new Delegate [delegates.Length - 1];
-
- Array.Copy (delegates, ret.delegates, idx);
- Array.Copy (delegates, idx + 1, ret.delegates, idx, delegates.Length - idx - 1);
-
- return ret;
- } else {
- /* wild case : remove MulticastDelegate from MulticastDelegate
- * complexity is O(m + n), with n the number of elements in
- * this.delegates and m the number of elements in other.delegates */
-
- if (delegates.Equals (other.delegates))
- return null;
-
- /* we need to remove elements from the end to the beginning, as
- * the addition and removal of delegates behaves like a stack */
- int idx = LastIndexOf (delegates, other.delegates);
- if (idx == -1)
- return this;
-
- MulticastDelegate ret = AllocDelegateLike_internal (this);
- ret.delegates = new Delegate [delegates.Length - other.delegates.Length];
-
- Array.Copy (delegates, ret.delegates, idx);
- Array.Copy (delegates, idx + other.delegates.Length, ret.delegates, idx, delegates.Length - idx - other.delegates.Length);
-
- return ret;
- }
- }
-
- public static bool operator == (MulticastDelegate d1, MulticastDelegate d2)
- {
- if (d1 == null)
- return d2 == null;
-
- return d1.Equals (d2);
- }
-
- public static bool operator != (MulticastDelegate d1, MulticastDelegate d2)
- {
- if (d1 == null)
- return d2 != null;
-
- return !d1.Equals (d2);
- }
-
- internal override object GetTarget()
- {
- return delegates?.Length > 0 ? delegates [delegates.Length - 1].GetTarget () : base.GetTarget ();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/NotImplemented.cs b/netcore/System.Private.CoreLib/src/System/NotImplemented.cs
deleted file mode 100644
index 5a2690e97f6..00000000000
--- a/netcore/System.Private.CoreLib/src/System/NotImplemented.cs
+++ /dev/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.
-
-namespace System
-{
- //
- // This simple class enables one to throw a NotImplementedException using the following
- // idiom:
- //
- // throw NotImplemented.ByDesign;
- //
- // Used by methods whose intended implementation is to throw a NotImplementedException (typically
- // virtual methods in public abstract classes that intended to be subclassed by third parties.)
- //
- // This makes it distinguishable both from human eyes and CCI from NYI's that truly represent undone work.
- //
- internal static class NotImplemented
- {
- internal static Exception ByDesign
- {
- get
- {
- return new NotImplementedException();
- }
- }
- }
-}
-
diff --git a/netcore/System.Private.CoreLib/src/System/Nullable.Mono.cs b/netcore/System.Private.CoreLib/src/System/Nullable.Mono.cs
deleted file mode 100644
index 8958c0fab8b..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Nullable.Mono.cs
+++ /dev/null
@@ -1,41 +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.
-
-namespace System
-{
- partial struct Nullable<T>
- {
- //
- // These are called by the JIT
- //
-
- //
- // JIT implementation of box valuetype System.Nullable`1<T>
- //
- static object? Box (T? o)
- {
- if (!o.hasValue)
- return null;
-
- return o.value;
- }
-
- static T? Unbox (object o)
- {
- if (o == null)
- return null;
- return (T) o;
- }
-
- static T? UnboxExact (object o)
- {
- if (o == null)
- return null;
- if (o.GetType() != typeof (T))
- throw new InvalidCastException();
-
- return (T) o;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Object.Mono.cs b/netcore/System.Private.CoreLib/src/System/Object.Mono.cs
deleted file mode 100644
index a34de194d20..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Object.Mono.cs
+++ /dev/null
@@ -1,22 +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 System.Runtime.CompilerServices;
-
-namespace System
-{
- partial class Object
- {
- [Intrinsic]
- public Type GetType () => GetType ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- protected extern object MemberwiseClone ();
-
- [Intrinsic]
- internal ref byte GetRawData () => ref GetRawData ();
-
- internal object CloneInternal () => MemberwiseClone ();
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs
deleted file mode 100644
index a8ac7339b9c..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs
+++ /dev/null
@@ -1,97 +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 System.IO;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Loader;
-using System.Threading;
-
-namespace System.Reflection
-{
- [StructLayout (LayoutKind.Sequential)]
- partial class Assembly
- {
- internal bool IsRuntimeImplemented () => this is RuntimeAssembly;
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly? LoadWithPartialName (string partialName)
- {
- if (partialName == null)
- throw new ArgumentNullException (nameof (partialName));
-
- if (partialName.Length == 0 || partialName [0] == '\0')
- throw new ArgumentException (SR.Format_StringZeroLength, nameof (partialName));
-
- try {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return RuntimeAssembly.InternalLoad (partialName, ref stackMark, IntPtr.Zero);
- } catch (FileNotFoundException) {
- return null;
- }
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly GetExecutingAssembly()
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return GetExecutingAssembly(ref stackMark);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern RuntimeAssembly GetExecutingAssembly (ref StackCrawlMark stackMark);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public static extern Assembly GetCallingAssembly ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern Assembly GetEntryAssemblyNative ();
-
- private static Assembly? GetEntryAssemblyInternal ()
- {
- return GetEntryAssemblyNative ();
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly Load (string assemblyString)
- {
- if (assemblyString == null)
- throw new ArgumentNullException (nameof (assemblyString));
-
- var name = new AssemblyName (assemblyString);
- // TODO: trigger assemblyFromResolveEvent
-
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return Load (name, ref stackMark, AssemblyLoadContext.CurrentContextualReflectionContext);
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly Load (AssemblyName assemblyRef)
- {
- if (assemblyRef == null)
- throw new ArgumentNullException (nameof (assemblyRef));
-
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return Load (assemblyRef, ref stackMark, AssemblyLoadContext.CurrentContextualReflectionContext);
- }
-
- internal static Assembly Load (AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext assemblyLoadContext)
- {
- // TODO: pass AssemblyName
- var assembly = InternalLoad (assemblyRef.FullName, ref stackMark, assemblyLoadContext != null ? assemblyLoadContext.NativeALC : IntPtr.Zero);
- if (assembly == null)
- throw new FileNotFoundException (null, assemblyRef.Name);
- return assembly;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern Assembly InternalLoad (string assemblyName, ref StackCrawlMark stackMark, IntPtr ptrLoadContextBinder);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern Type InternalGetType (Module module, string name, bool throwOnError, bool ignoreCase);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static void InternalGetAssemblyName (string assemblyFile, out Mono.MonoAssemblyName aname, out string codebase);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/AssemblyName.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/AssemblyName.Mono.cs
deleted file mode 100644
index 5d93f5c7262..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/AssemblyName.Mono.cs
+++ /dev/null
@@ -1,135 +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 Mono;
-using System.Configuration.Assemblies;
-using System.Globalization;
-using System.IO;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection
-{
- [StructLayout (LayoutKind.Sequential)]
- partial class AssemblyName
- {
- public AssemblyName (string assemblyName)
- {
- if (assemblyName == null)
- throw new ArgumentNullException (nameof (assemblyName));
- if (assemblyName.Length == 0 || assemblyName [0] == '\0')
- throw new ArgumentException (SR.Format_StringZeroLength);
-
- using (var name = RuntimeMarshal.MarshalString (assemblyName)) {
- // TODO: Should use CoreRT AssemblyNameParser
- if (!ParseAssemblyName (name.Value, out var nativeName, out var isVersionDefined, out var isTokenDefined))
- throw new FileLoadException ("The assembly name is invalid.");
-
- try {
- unsafe {
- FillName (&nativeName, null, isVersionDefined, false, isTokenDefined);
- }
- } finally {
- RuntimeMarshal.FreeAssemblyName (ref nativeName, false);
- }
- }
- }
-
- unsafe byte [] ComputePublicKeyToken ()
- {
- if (_publicKey == null)
- return null;
- if (_publicKey.Length == 0)
- return Array.Empty<byte>();
-
- var token = new byte [8];
- fixed (byte* pkt = token)
- fixed (byte *pk = _publicKey)
- get_public_token (pkt, pk, _publicKey.Length);
- return token;
- }
-
- internal static AssemblyName Create (IntPtr monoAssembly, string codeBase)
- {
- AssemblyName aname = new AssemblyName ();
- unsafe {
- MonoAssemblyName *native = GetNativeName (monoAssembly);
- aname.FillName (native, codeBase, true, true, true);
- }
- return aname;
- }
-
- internal unsafe void FillName (MonoAssemblyName *native, string codeBase, bool addVersion, bool addPublickey, bool defaultToken)
- {
- _name = RuntimeMarshal.PtrToUtf8String (native->name);
-
- _flags = (AssemblyNameFlags) native->flags;
-
- _hashAlgorithm = (AssemblyHashAlgorithm) native->hash_alg;
-
- _versionCompatibility = AssemblyVersionCompatibility.SameMachine;
-
- if (addVersion) {
- var build = native->build == 65535 ? -1 : native->build;
- var revision = native->revision == 65535 ? -1 : native->revision;
-
- if (build == -1)
- _version = new Version (native->major, native->minor);
- else if (revision == -1)
- _version = new Version (native->major, native->minor, build);
- else
- _version = new Version (native->major, native->minor, build, revision);
- }
-
- _codeBase = codeBase;
-
- if (native->culture != IntPtr.Zero)
- _cultureInfo = CultureInfo.GetCultureInfo (RuntimeMarshal.PtrToUtf8String (native->culture));
-
- if (native->public_key != IntPtr.Zero) {
- _publicKey = RuntimeMarshal.DecodeBlobArray (native->public_key);
- _flags |= AssemblyNameFlags.PublicKey;
- } else if (addPublickey) {
- _publicKey = Array.Empty<byte> ();
- _flags |= AssemblyNameFlags.PublicKey;
- }
-
- // MonoAssemblyName keeps the public key token as an hexadecimal string
- if (native->public_key_token [0] != 0) {
- var keyToken = new byte [8];
- for (int i = 0, j = 0; i < 8; ++i) {
- keyToken [i] = (byte) (RuntimeMarshal.AsciHexDigitValue (native->public_key_token [j++]) << 4);
- keyToken [i] |= (byte) RuntimeMarshal.AsciHexDigitValue (native->public_key_token [j++]);
- }
- _publicKeyToken = keyToken;
- } else if (defaultToken) {
- _publicKeyToken = Array.Empty<byte> ();
- }
- }
-
- static AssemblyName GetFileInformationCore (string assemblyFile)
- {
- unsafe {
- Assembly.InternalGetAssemblyName (Path.GetFullPath (assemblyFile), out var nativeName, out var codebase);
-
- var aname = new AssemblyName ();
- try {
- aname.FillName (&nativeName, codebase, true, false, true);
- return aname;
- } finally {
- RuntimeMarshal.FreeAssemblyName (ref nativeName, false);
- }
- }
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern unsafe void get_public_token (byte* token, byte* pubkey, int len);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern unsafe MonoAssemblyName* GetNativeName (IntPtr assemblyPtr);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern bool ParseAssemblyName (IntPtr name, out MonoAssemblyName aname, out bool is_version_definited, out bool is_token_defined);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
deleted file mode 100644
index 03880d38c87..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
+++ /dev/null
@@ -1,720 +0,0 @@
-//
-// (c) 2002,2003 Ximian, Inc. (http://www.ximian.com)
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-// Copyright (C) 2013 Xamarin, Inc (http://www.xamarin.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Reflection;
-using System.Collections;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-using System.Collections.Generic;
-
-namespace System.Reflection
-{
- static class CustomAttribute
- {
- static Assembly corlib;
- [ThreadStatic]
- static Dictionary<Type, AttributeUsageAttribute> usage_cache;
-
- /* Treat as user types all corlib types extending System.Type that are not RuntimeType and TypeBuilder */
- static bool IsUserCattrProvider (object obj)
- {
- Type type = obj as Type;
- if ((type is RuntimeType) || (RuntimeFeature.IsDynamicCodeSupported && type?.IsTypeBuilder () == true))
- return false;
- if ((obj is Type))
- return true;
- if (corlib == null)
- corlib = typeof (int).Assembly;
- return obj.GetType ().Assembly != corlib;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern Attribute[] GetCustomAttributesInternal (ICustomAttributeProvider obj, Type attributeType, bool pseudoAttrs);
-
- internal static object[] GetPseudoCustomAttributes (ICustomAttributeProvider obj, Type attributeType) {
- object[] pseudoAttrs = null;
- /* FIXME: Add other types */
- if (obj is RuntimeMethodInfo monoMethod)
- pseudoAttrs = monoMethod.GetPseudoCustomAttributes ();
- else if (obj is RuntimeFieldInfo fieldInfo)
- pseudoAttrs = fieldInfo.GetPseudoCustomAttributes ();
- else if (obj is RuntimeParameterInfo monoParamInfo)
- pseudoAttrs = monoParamInfo.GetPseudoCustomAttributes ();
- else if (obj is Type t)
- pseudoAttrs = GetPseudoCustomAttributes (t);
-
- if ((attributeType != null) && (pseudoAttrs != null)) {
- for (int i = 0; i < pseudoAttrs.Length; ++i)
- if (attributeType.IsAssignableFrom (pseudoAttrs [i].GetType ()))
- if (pseudoAttrs.Length == 1)
- return pseudoAttrs;
- else
- return new object [] { pseudoAttrs [i] };
- return Array.Empty<object> ();
- }
-
- return pseudoAttrs;
- }
-
- static object[] GetPseudoCustomAttributes (Type type)
- {
- int count = 0;
- var Attributes = type.Attributes;
-
- /* IsSerializable returns true for delegates/enums as well */
- if ((Attributes & TypeAttributes.Serializable) != 0)
- count ++;
- if ((Attributes & TypeAttributes.Import) != 0)
- count ++;
-
- if (count == 0)
- return null;
- object[] attrs = new object [count];
- count = 0;
-
- if ((Attributes & TypeAttributes.Serializable) != 0)
- attrs [count ++] = new SerializableAttribute ();
- if ((Attributes & TypeAttributes.Import) != 0)
- attrs [count ++] = new ComImportAttribute ();
-
- return attrs;
- }
-
- internal static object[] GetCustomAttributesBase (ICustomAttributeProvider obj, Type attributeType, bool inheritedOnly)
- {
- object[] attrs;
-
- if (IsUserCattrProvider (obj))
- attrs = obj.GetCustomAttributes (attributeType, true);
- else
- attrs = GetCustomAttributesInternal (obj, attributeType, false);
-
- //
- // All pseudo custom attributes are Inherited = false hence we can avoid
- // building attributes array which would be discarded by inherited checks
- //
- if (!inheritedOnly) {
- object[] pseudoAttrs = GetPseudoCustomAttributes (obj, attributeType);
- if (pseudoAttrs != null) {
- object[] res = new Attribute [attrs.Length + pseudoAttrs.Length];
- System.Array.Copy (attrs, res, attrs.Length);
- System.Array.Copy (pseudoAttrs, 0, res, attrs.Length, pseudoAttrs.Length);
- return res;
- }
- }
-
- return attrs;
- }
-
- internal static object[] GetCustomAttributes (ICustomAttributeProvider obj, Type attributeType, bool inherit)
- {
- if (obj == null)
- throw new ArgumentNullException (nameof (obj));
- if (attributeType == null)
- throw new ArgumentNullException (nameof (attributeType));
- if (!attributeType.IsSubclassOf (typeof (Attribute)) && attributeType != typeof (Attribute)&& attributeType != typeof (CustomAttribute) && attributeType != typeof (System.Object))
- throw new ArgumentException (SR.Argument_MustHaveAttributeBaseClass + " " + attributeType.FullName);
-
- if (attributeType == typeof (CustomAttribute))
- attributeType = null;
- if (attributeType == typeof (Attribute))
- attributeType = null;
- if (attributeType == typeof (System.Object))
- attributeType = null;
-
- object[] r;
- object[] res = GetCustomAttributesBase (obj, attributeType, false);
- // shortcut
- if (!inherit && res.Length == 1) {
- if (res [0] == null)
- throw new CustomAttributeFormatException ("Invalid custom attribute format");
-
- if (attributeType != null) {
- if (attributeType.IsAssignableFrom (res[0].GetType ())) {
- r = (object[]) Array.CreateInstance (attributeType, 1);
- r[0] = res[0];
- } else {
- r = (object[]) Array.CreateInstance (attributeType, 0);
- }
- } else {
- r = (object[]) Array.CreateInstance (res[0].GetType (), 1);
- r[0] = res[0];
- }
- return r;
- }
-
- if (inherit && GetBase (obj) == null)
- inherit = false;
-
- // if AttributeType is sealed, and Inherited is set to false, then
- // there's no use in scanning base types
- if ((attributeType != null && attributeType.IsSealed) && inherit) {
- AttributeUsageAttribute usageAttribute = RetrieveAttributeUsage (
- attributeType);
- if (!usageAttribute.Inherited)
- inherit = false;
- }
-
- var initialSize = Math.Max (res.Length, 16);
- List<Object> a = null;
- ICustomAttributeProvider btype = obj;
- object[] array;
-
- /* Non-inherit case */
- if (!inherit) {
- if (attributeType == null) {
- foreach (object attr in res) {
- if (attr == null)
- throw new CustomAttributeFormatException ("Invalid custom attribute format");
- }
- var result = new Attribute [res.Length];
- res.CopyTo (result, 0);
- return result;
- }
-
- a = new List<object> (initialSize);
- foreach (object attr in res) {
- if (attr == null)
- throw new CustomAttributeFormatException ("Invalid custom attribute format");
-
- Type attrType = attr.GetType ();
- if (attributeType != null && !attributeType.IsAssignableFrom (attrType))
- continue;
- a.Add (attr);
- }
-
- if (attributeType == null || attributeType.IsValueType)
- array = new Attribute [a.Count];
- else
- array = Array.CreateInstance (attributeType, a.Count) as object[];
- a.CopyTo (array, 0);
- return array;
- }
-
- /* Inherit case */
- var attributeInfos = new Dictionary<Type, AttributeInfo> (initialSize);
- int inheritanceLevel = 0;
- a = new List<object> (initialSize);
-
- do {
- foreach (object attr in res) {
- AttributeUsageAttribute usage;
- if (attr == null)
- throw new CustomAttributeFormatException ("Invalid custom attribute format");
-
- Type attrType = attr.GetType ();
- if (attributeType != null) {
- if (!attributeType.IsAssignableFrom (attrType))
- continue;
- }
-
- AttributeInfo firstAttribute;
- if (attributeInfos.TryGetValue (attrType, out firstAttribute))
- usage = firstAttribute.Usage;
- else
- usage = RetrieveAttributeUsage (attrType);
-
- // only add attribute to the list of attributes if
- // - we are on the first inheritance level, or the attribute can be inherited anyway
- // and (
- // - multiple attributes of the type are allowed
- // or (
- // - this is the first attribute we've discovered
- // or
- // - the attribute is on same inheritance level than the first
- // attribute that was discovered for this attribute type ))
- if ((inheritanceLevel == 0 || usage.Inherited) && (usage.AllowMultiple ||
- (firstAttribute == null || (firstAttribute != null
- && firstAttribute.InheritanceLevel == inheritanceLevel))))
- a.Add (attr);
-
- if (firstAttribute == null)
- attributeInfos.Add (attrType, new AttributeInfo (usage, inheritanceLevel));
- }
-
- if ((btype = GetBase (btype)) != null) {
- inheritanceLevel++;
- res = GetCustomAttributesBase (btype, attributeType, true);
- }
- } while (inherit && btype != null);
-
- if (attributeType == null || attributeType.IsValueType)
- array = new Attribute [a.Count];
- else
- array = Array.CreateInstance (attributeType, a.Count) as object[];
-
- // copy attributes to array
- a.CopyTo (array, 0);
-
- return array;
- }
-
- internal static object[] GetCustomAttributes (ICustomAttributeProvider obj, bool inherit)
- {
- if (obj == null)
- throw new ArgumentNullException ("obj");
-
- if (!inherit)
- return (object[]) GetCustomAttributesBase (obj, null, false).Clone ();
-
- return GetCustomAttributes (obj, typeof (CustomAttribute), inherit);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- [PreserveDependency(".ctor(System.Reflection.ConstructorInfo,System.Reflection.Assembly,System.IntPtr,System.UInt32)", "System.Reflection.CustomAttributeData")]
- [PreserveDependency(".ctor(System.Reflection.MemberInfo,System.Object)", "System.Reflection.CustomAttributeNamedArgument")]
- [PreserveDependency(".ctor(System.Type,System.Object)", "System.Reflection.CustomAttributeTypedArgument")]
- static extern CustomAttributeData [] GetCustomAttributesDataInternal (ICustomAttributeProvider obj);
-
- internal static IList<CustomAttributeData> GetCustomAttributesData (ICustomAttributeProvider obj, bool inherit = false)
- {
- if (obj == null)
- throw new ArgumentNullException (nameof (obj));
-
- if (!inherit)
- return GetCustomAttributesDataBase (obj, null, false);
-
- return GetCustomAttributesData (obj, typeof (CustomAttribute), inherit);
- }
-
- internal static IList<CustomAttributeData> GetCustomAttributesData (ICustomAttributeProvider obj, Type attributeType, bool inherit)
- {
- if (obj == null)
- throw new ArgumentNullException (nameof (obj));
- if (attributeType == null)
- throw new ArgumentNullException (nameof (attributeType));
-
- if (attributeType == typeof (CustomAttribute))
- attributeType = null;
-
- const string Message = "Invalid custom attribute data format";
- IList<CustomAttributeData> r;
- IList<CustomAttributeData> res = GetCustomAttributesDataBase (obj, attributeType, false);
- // shortcut
- if (!inherit && res.Count == 1) {
- if (res [0] == null)
- throw new CustomAttributeFormatException (Message);
- if (attributeType != null) {
- if (attributeType.IsAssignableFrom (res [0].AttributeType))
- r = new CustomAttributeData[] { res [0] };
- else
- r = Array.Empty<CustomAttributeData> ();
- } else {
- r = new CustomAttributeData[] { res [0] };
- }
-
- return r;
- }
-
- if (inherit && GetBase (obj) == null)
- inherit = false;
-
- // if AttributeType is sealed, and Inherited is set to false, then
- // there's no use in scanning base types
- if ((attributeType != null && attributeType.IsSealed) && inherit) {
- var usageAttribute = RetrieveAttributeUsage (attributeType);
- if (!usageAttribute.Inherited)
- inherit = false;
- }
-
- var initialSize = Math.Max (res.Count, 16);
- List<CustomAttributeData> a = null;
- ICustomAttributeProvider btype = obj;
-
- /* Non-inherit case */
- if (!inherit) {
- if (attributeType == null) {
- foreach (CustomAttributeData attrData in res) {
- if (attrData == null)
- throw new CustomAttributeFormatException (Message);
- }
-
- var result = new CustomAttributeData [res.Count];
- res.CopyTo (result, 0);
- return result;
- } else {
- a = new List<CustomAttributeData> (initialSize);
- foreach (CustomAttributeData attrData in res) {
- if (attrData == null)
- throw new CustomAttributeFormatException (Message);
- if (!attributeType.IsAssignableFrom (attrData.AttributeType))
- continue;
- a.Add (attrData);
- }
-
- return a.ToArray ();
- }
- }
-
- /* Inherit case */
- var attributeInfos = new Dictionary<Type, AttributeInfo> (initialSize);
- int inheritanceLevel = 0;
- a = new List<CustomAttributeData> (initialSize);
-
- do {
- foreach (CustomAttributeData attrData in res) {
- AttributeUsageAttribute usage;
- if (attrData == null)
- throw new CustomAttributeFormatException (Message);
-
- Type attrType = attrData.AttributeType;
- if (attributeType != null) {
- if (!attributeType.IsAssignableFrom (attrType))
- continue;
- }
-
- AttributeInfo firstAttribute;
- if (attributeInfos.TryGetValue (attrType, out firstAttribute))
- usage = firstAttribute.Usage;
- else
- usage = RetrieveAttributeUsage (attrType);
-
- // The same as for CustomAttributes.
- //
- // Only add attribute to the list of attributes if
- // - we are on the first inheritance level, or the attribute can be inherited anyway
- // and (
- // - multiple attributes of the type are allowed
- // or (
- // - this is the first attribute we've discovered
- // or
- // - the attribute is on same inheritance level than the first
- // attribute that was discovered for this attribute type ))
- if ((inheritanceLevel == 0 || usage.Inherited) && (usage.AllowMultiple ||
- (firstAttribute == null || (firstAttribute != null
- && firstAttribute.InheritanceLevel == inheritanceLevel))))
- a.Add(attrData);
-
- if (firstAttribute == null)
- attributeInfos.Add (attrType, new AttributeInfo (usage, inheritanceLevel));
- }
-
- if ((btype = GetBase (btype)) != null) {
- inheritanceLevel++;
- res = GetCustomAttributesDataBase (btype, attributeType, true);
- }
- } while (inherit && btype != null);
-
- return a.ToArray ();
- }
-
- internal static IList<CustomAttributeData> GetCustomAttributesDataBase (ICustomAttributeProvider obj, Type attributeType, bool inheritedOnly)
- {
- CustomAttributeData[] attrsData;
- if (IsUserCattrProvider (obj)) {
- //FIXME resolve this case if it makes sense. Assign empty array for now.
- //attrsData = obj.GetCustomAttributesData(attributeType, true);
- attrsData = Array.Empty<CustomAttributeData> ();
- } else
- attrsData = GetCustomAttributesDataInternal (obj);
-
- //
- // All pseudo custom attributes are Inherited = false hence we can avoid
- // building attributes data array which would be discarded by inherited checks
- //
- if (!inheritedOnly) {
- CustomAttributeData[] pseudoAttrsData = GetPseudoCustomAttributesData (obj, attributeType);
- if (pseudoAttrsData != null) {
- if (attrsData.Length == 0)
- return Array.AsReadOnly (pseudoAttrsData);
- CustomAttributeData[] res = new CustomAttributeData [attrsData.Length + pseudoAttrsData.Length];
- Array.Copy (attrsData, res, attrsData.Length);
- Array.Copy (pseudoAttrsData, 0, res, attrsData.Length, pseudoAttrsData.Length);
- return Array.AsReadOnly (res);
- }
- }
-
- return Array.AsReadOnly (attrsData);
- }
-
- internal static CustomAttributeData[] GetPseudoCustomAttributesData (ICustomAttributeProvider obj, Type attributeType)
- {
- CustomAttributeData[] pseudoAttrsData = null;
-
- /* FIXME: Add other types */
- if (obj is RuntimeMethodInfo monoMethod)
- pseudoAttrsData = monoMethod.GetPseudoCustomAttributesData ();
- else if (obj is RuntimeFieldInfo fieldInfo)
- pseudoAttrsData = fieldInfo.GetPseudoCustomAttributesData ();
- else if (obj is RuntimeParameterInfo monoParamInfo)
- pseudoAttrsData = monoParamInfo.GetPseudoCustomAttributesData ();
- else if (obj is Type t)
- pseudoAttrsData = GetPseudoCustomAttributesData (t);
-
- if ((attributeType != null) && (pseudoAttrsData != null)) {
- for (int i = 0; i < pseudoAttrsData.Length; ++i) {
- if (attributeType.IsAssignableFrom (pseudoAttrsData [i].AttributeType)) {
- if (pseudoAttrsData.Length == 1)
- return pseudoAttrsData;
- else
- return new CustomAttributeData[] { pseudoAttrsData[i] };
- }
- }
-
- return Array.Empty<CustomAttributeData> ();
- }
-
- return pseudoAttrsData;
- }
-
- static CustomAttributeData[] GetPseudoCustomAttributesData (Type type)
- {
- int count = 0;
- var Attributes = type.Attributes;
-
- /* IsSerializable returns true for delegates/enums as well */
- if ((Attributes & TypeAttributes.Serializable) != 0)
- count++;
- if ((Attributes & TypeAttributes.Import) != 0)
- count++;
-
- if (count == 0)
- return null;
- CustomAttributeData[] attrsData = new CustomAttributeData [count];
- count = 0;
-
- if ((Attributes & TypeAttributes.Serializable) != 0)
- attrsData [count++] = new CustomAttributeData ((typeof (SerializableAttribute)).GetConstructor (Type.EmptyTypes));
- if ((Attributes & TypeAttributes.Import) != 0)
- attrsData [count++] = new CustomAttributeData ((typeof (ComImportAttribute)).GetConstructor (Type.EmptyTypes));
-
- return attrsData;
- }
-
- internal static bool IsDefined (ICustomAttributeProvider obj, Type attributeType, bool inherit)
- {
- if (attributeType == null)
- throw new ArgumentNullException (nameof (attributeType));
- if (!attributeType.IsSubclassOf (typeof (Attribute)) && attributeType != typeof (Attribute))
- throw new ArgumentException (SR.Argument_MustHaveAttributeBaseClass + " " + attributeType.FullName);
-
- AttributeUsageAttribute usage = null;
- do {
- if (IsUserCattrProvider (obj))
- return obj.IsDefined (attributeType, inherit);
-
- if (IsDefinedInternal (obj, attributeType))
- return true;
-
- object[] pseudoAttrs = GetPseudoCustomAttributes (obj, attributeType);
- if (pseudoAttrs != null) {
- for (int i = 0; i < pseudoAttrs.Length; ++i)
- if (attributeType.IsAssignableFrom (pseudoAttrs[i].GetType ()))
- return true;
- }
-
- if (usage == null) {
- if (!inherit)
- return false;
-
- usage = RetrieveAttributeUsage (attributeType);
- if (!usage.Inherited)
- return false;
- }
-
- obj = GetBase (obj);
- } while (obj != null);
-
- return false;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern bool IsDefinedInternal (ICustomAttributeProvider obj, Type AttributeType);
-
- static PropertyInfo GetBasePropertyDefinition (RuntimePropertyInfo property)
- {
- MethodInfo method = property.GetGetMethod (true);
- if (method == null || !method.IsVirtual)
- method = property.GetSetMethod (true);
- if (method == null || !method.IsVirtual)
- return null;
-
- MethodInfo baseMethod = ((RuntimeMethodInfo)method).GetBaseMethod ();
- if (baseMethod != null && baseMethod != method) {
- ParameterInfo[] parameters = property.GetIndexParameters ();
- if (parameters != null && parameters.Length > 0) {
- Type[] paramTypes = new Type[parameters.Length];
- for (int i=0; i < paramTypes.Length; i++)
- paramTypes[i] = parameters[i].ParameterType;
- return baseMethod.DeclaringType.GetProperty (property.Name, property.PropertyType,
- paramTypes);
- } else {
- return baseMethod.DeclaringType.GetProperty (property.Name, property.PropertyType);
- }
- }
- return null;
-
- }
-
- static EventInfo GetBaseEventDefinition (RuntimeEventInfo evt)
- {
- MethodInfo method = evt.GetAddMethod (true);
- if (method == null || !method.IsVirtual)
- method = evt.GetRaiseMethod (true);
- if (method == null || !method.IsVirtual)
- method = evt.GetRemoveMethod (true);
- if (method == null || !method.IsVirtual)
- return null;
-
- MethodInfo baseMethod = ((RuntimeMethodInfo)method).GetBaseMethod ();
- if (baseMethod != null && baseMethod != method) {
- BindingFlags flags = method.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
- flags |= method.IsStatic ? BindingFlags.Static : BindingFlags.Instance;
-
- return baseMethod.DeclaringType.GetEvent (evt.Name, flags);
- }
- return null;
- }
-
- // Handles Type, RuntimePropertyInfo and RuntimeMethodInfo.
- // The runtime has also cases for RuntimeEventInfo, RuntimeFieldInfo, Assembly and ParameterInfo,
- // but for those we return null here.
- static ICustomAttributeProvider GetBase (ICustomAttributeProvider obj)
- {
- if (obj == null)
- return null;
-
- if (obj is Type)
- return ((Type) obj).BaseType;
-
- MethodInfo method = null;
- if (obj is RuntimePropertyInfo)
- return GetBasePropertyDefinition ((RuntimePropertyInfo) obj);
- else if (obj is RuntimeEventInfo)
- return GetBaseEventDefinition ((RuntimeEventInfo)obj);
- else if (obj is RuntimeMethodInfo)
- method = (MethodInfo) obj;
- if (obj is RuntimeParameterInfo parinfo) {
- var member = parinfo.Member;
- if (member is MethodInfo) {
- method = (MethodInfo)member;
- MethodInfo bmethod = ((RuntimeMethodInfo)method).GetBaseMethod ();
- if (bmethod == method)
- return null;
- return bmethod.GetParameters ()[parinfo.Position];
- }
- }
- /*
- * ParameterInfo -> null
- * Assembly -> null
- * RuntimeEventInfo -> null
- * RuntimeFieldInfo -> null
- */
- if (method == null || !method.IsVirtual)
- return null;
-
- MethodInfo baseMethod = ((RuntimeMethodInfo)method).GetBaseMethod ();
- if (baseMethod == method)
- return null;
-
- return baseMethod;
- }
-
- private static AttributeUsageAttribute RetrieveAttributeUsageNoCache (Type attributeType)
- {
- if (attributeType == typeof (AttributeUsageAttribute))
- /* Avoid endless recursion */
- return new AttributeUsageAttribute (AttributeTargets.Class);
-
- AttributeUsageAttribute usageAttribute = null;
- object[] attribs = GetCustomAttributes (attributeType, typeof(AttributeUsageAttribute), false);
- if (attribs.Length == 0)
- {
- // if no AttributeUsage was defined on the attribute level, then
- // try to retrieve if from its base type
- if (attributeType.BaseType != null)
- {
- usageAttribute = RetrieveAttributeUsage (attributeType.BaseType);
-
- }
- if (usageAttribute != null)
- {
- // return AttributeUsage of base class
- return usageAttribute;
-
- }
- // return default AttributeUsageAttribute if no AttributeUsage
- // was defined on attribute, or its base class
- return DefaultAttributeUsage;
- }
- // check if more than one AttributeUsageAttribute has been specified
- // on the type
- // NOTE: compilers should prevent this, but that doesn't prevent
- // anyone from using IL ofcourse
- if (attribs.Length > 1)
- {
- throw new FormatException ("Duplicate AttributeUsageAttribute cannot be specified on an attribute type.");
- }
-
- return ((AttributeUsageAttribute) attribs[0]);
- }
-
- static AttributeUsageAttribute RetrieveAttributeUsage (Type attributeType)
- {
- AttributeUsageAttribute usageAttribute = null;
- /* Usage a thread-local cache to speed this up, since it is called a lot from GetCustomAttributes () */
- if (usage_cache == null)
- usage_cache = new Dictionary<Type, AttributeUsageAttribute> ();
- if (usage_cache.TryGetValue (attributeType, out usageAttribute))
- return usageAttribute;
- usageAttribute = RetrieveAttributeUsageNoCache (attributeType);
- usage_cache [attributeType] = usageAttribute;
- return usageAttribute;
- }
-
- private static readonly AttributeUsageAttribute DefaultAttributeUsage =
- new AttributeUsageAttribute (AttributeTargets.All);
-
- private class AttributeInfo
- {
- private AttributeUsageAttribute _usage;
- private int _inheritanceLevel;
-
- public AttributeInfo (AttributeUsageAttribute usage, int inheritanceLevel)
- {
- _usage = usage;
- _inheritanceLevel = inheritanceLevel;
- }
-
- public AttributeUsageAttribute Usage
- {
- get
- {
- return _usage;
- }
- }
-
- public int InheritanceLevel
- {
- get
- {
- return _inheritanceLevel;
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeData.cs b/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeData.cs
deleted file mode 100644
index 979a5215091..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeData.cs
+++ /dev/null
@@ -1,187 +0,0 @@
-//
-// Author:
-// Zoltan Varga (vargaz@gmail.com)
-// Carlos Alberto Cortez (calberto.cortez@gmail.com)
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System.Reflection
-{
- public class CustomAttributeData
- {
- class LazyCAttrData {
- internal Assembly assembly;
- internal IntPtr data;
- internal uint data_length;
- }
-
- ConstructorInfo ctorInfo;
- IList<CustomAttributeTypedArgument> ctorArgs;
- IList<CustomAttributeNamedArgument> namedArgs;
- LazyCAttrData lazyData;
-
- protected CustomAttributeData ()
- {
- }
-
- // custom-attrs.c:create_custom_attr_data ()
- internal CustomAttributeData (ConstructorInfo ctorInfo, Assembly assembly, IntPtr data, uint data_length)
- {
- this.ctorInfo = ctorInfo;
- this.lazyData = new LazyCAttrData ();
- this.lazyData.assembly = assembly;
- this.lazyData.data = data;
- this.lazyData.data_length = data_length;
- }
-
- internal CustomAttributeData (ConstructorInfo ctorInfo)
- : this (ctorInfo, Array.Empty<CustomAttributeTypedArgument> (), Array.Empty<CustomAttributeNamedArgument> ())
- {
- }
-
- internal CustomAttributeData (ConstructorInfo ctorInfo, IList<CustomAttributeTypedArgument> ctorArgs, IList<CustomAttributeNamedArgument> namedArgs)
- {
- this.ctorInfo = ctorInfo;
- this.ctorArgs = ctorArgs;
- this.namedArgs = namedArgs;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern void ResolveArgumentsInternal (ConstructorInfo ctor, Assembly assembly, IntPtr data, uint data_length, out object[] ctorArgs, out object[] namedArgs);
-
- void ResolveArguments ()
- {
- object[] ctor_args, named_args;
- if (lazyData == null)
- return;
-
- ResolveArgumentsInternal (ctorInfo, lazyData.assembly, lazyData.data, lazyData.data_length, out ctor_args, out named_args);
-
- this.ctorArgs = Array.AsReadOnly<CustomAttributeTypedArgument>
- (ctor_args != null ? UnboxValues<CustomAttributeTypedArgument> (ctor_args) : Array.Empty<CustomAttributeTypedArgument>());
- this.namedArgs = Array.AsReadOnly<CustomAttributeNamedArgument>
- (named_args != null ? UnboxValues<CustomAttributeNamedArgument> (named_args) : Array.Empty<CustomAttributeNamedArgument>());
-
- lazyData = null;
- }
-
- public
- virtual
- ConstructorInfo Constructor {
- get {
- return ctorInfo;
- }
- }
-
- public
- virtual
- IList<CustomAttributeTypedArgument> ConstructorArguments {
- get {
- ResolveArguments ();
- return ctorArgs;
- }
- }
-
- public
- virtual
- IList<CustomAttributeNamedArgument> NamedArguments {
- get {
- ResolveArguments ();
- return namedArgs;
- }
- }
-
- public static IList<CustomAttributeData> GetCustomAttributes (Assembly target) {
- return CustomAttribute.GetCustomAttributesData (target);
- }
-
- public static IList<CustomAttributeData> GetCustomAttributes (MemberInfo target) {
- return CustomAttribute.GetCustomAttributesData (target);
- }
-
- internal static IList<CustomAttributeData> GetCustomAttributesInternal (RuntimeType target) {
- return CustomAttribute.GetCustomAttributesData (target);
- }
-
- public static IList<CustomAttributeData> GetCustomAttributes (Module target) {
- return CustomAttribute.GetCustomAttributesData (target);
- }
-
- public static IList<CustomAttributeData> GetCustomAttributes (ParameterInfo target) {
- return CustomAttribute.GetCustomAttributesData (target);
- }
-
- virtual public Type AttributeType {
- get { return ctorInfo.DeclaringType; }
- }
-
- public override string ToString ()
- {
- ResolveArguments ();
-
- StringBuilder sb = new StringBuilder ();
-
- sb.Append ("[" + ctorInfo.DeclaringType.FullName + "(");
- for (int i = 0; i < ctorArgs.Count; i++) {
- sb.Append (ctorArgs [i].ToString ());
- if (i + 1 < ctorArgs.Count)
- sb.Append (", ");
- }
-
- if (namedArgs.Count > 0)
- sb.Append (", ");
-
- for (int j = 0; j < namedArgs.Count; j++) {
- sb.Append (namedArgs [j].ToString ());
- if (j + 1 < namedArgs.Count)
- sb.Append (", ");
- }
- sb.AppendFormat (")]");
-
- return sb.ToString ();
- }
-
- static T [] UnboxValues<T> (object [] values)
- {
- T [] retval = new T [values.Length];
- for (int i = 0; i < values.Length; i++)
- retval [i] = (T) values [i];
-
- return retval;
- }
-
- public override int GetHashCode () => base.GetHashCode ();
-
- public override bool Equals (object? obj)
- {
- return obj == (object)this;
- }
- }
-
-}
-
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.Mono.cs
deleted file mode 100644
index 27b08f8372a..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttributeTypedArgument.Mono.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Reflection
-{
- partial struct CustomAttributeTypedArgument
- {
- static object CanonicalizeValue (object value)
- {
- if (value.GetType ().IsEnum)
- return ((Enum) value).GetValue ();
-
- return value;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs
deleted file mode 100644
index f15997d5823..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs
+++ /dev/null
@@ -1,591 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit/AssemblyBuilder.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Reflection;
-using System.IO;
-using System.Runtime.Serialization;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Collections;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Security;
-using System.Security.Cryptography;
-using System.Threading;
-
-namespace System.Reflection.Emit
-{
- internal class GenericInstanceKey {
- Type gtd;
- internal Type[] args;
- int hash_code;
-
- internal GenericInstanceKey (Type gtd, Type[] args)
- {
- this.gtd = gtd;
- this.args = args;
-
- hash_code = gtd.GetHashCode ();
- for (int i = 0; i < args.Length; ++i)
- hash_code ^= args [i].GetHashCode ();
- }
-
- static bool IsBoundedVector (Type type) {
- ArrayType at = type as ArrayType;
- if (at != null)
- return at.GetEffectiveRank () == 1;
- return type.ToString ().EndsWith ("[*]", StringComparison.Ordinal); /*Super uggly hack, SR doesn't allow one to query for it */
- }
-
- static bool TypeEquals (Type a, Type b) {
- if (a == b)
- return true;
-
- if (a.HasElementType) {
- if (!b.HasElementType)
- return false;
- if (!TypeEquals (a.GetElementType (), b.GetElementType ()))
- return false;
- if (a.IsArray) {
- if (!b.IsArray)
- return false;
- int rank = a.GetArrayRank ();
- if (rank != b.GetArrayRank ())
- return false;
- if (rank == 1 && IsBoundedVector (a) != IsBoundedVector (b))
- return false;
- } else if (a.IsByRef) {
- if (!b.IsByRef)
- return false;
- } else if (a.IsPointer) {
- if (!b.IsPointer)
- return false;
- }
- return true;
- }
-
- if (a.IsGenericType) {
- if (!b.IsGenericType)
- return false;
- if (a.IsGenericParameter)
- return a == b;
- if (a.IsGenericParameter) //previous test should have caught it
- return false;
-
- if (a.IsGenericTypeDefinition) {
- if (!b.IsGenericTypeDefinition)
- return false;
- } else {
- if (b.IsGenericTypeDefinition)
- return false;
- if (!TypeEquals (a.GetGenericTypeDefinition (), b.GetGenericTypeDefinition ()))
- return false;
-
- Type[] argsA = a.GetGenericArguments ();
- Type[] argsB = b.GetGenericArguments ();
- for (int i = 0; i < argsA.Length; ++i) {
- if (!TypeEquals (argsA [i], argsB [i]))
- return false;
- }
- }
- }
-
- /*
- Now only non-generic, non compound types are left. To properly deal with user
- types we would have to call UnderlyingSystemType, but we let them have their
- own instantiation as this is MS behavior and mcs (pre C# 4.0, at least) doesn't
- depend on proper UT canonicalization.
- */
- return a == b;
- }
-
- public override bool Equals (object obj)
- {
- GenericInstanceKey other = obj as GenericInstanceKey;
- if (other == null)
- return false;
- if (gtd != other.gtd)
- return false;
- for (int i = 0; i < args.Length; ++i) {
- Type a = args [i];
- Type b = other.args [i];
- /*
- We must cannonicalize as much as we can. Using equals means that some resulting types
- won't have the exact same types as the argument ones.
- For example, flyweight types used array, pointer and byref will should this behavior.
- MCS seens to be resilient to this problem so hopefully this won't show up.
- */
- if (a != b && !a.Equals (b))
- return false;
- }
- return true;
- }
-
- public override int GetHashCode ()
- {
- return hash_code;
- }
- }
-
- [StructLayout (LayoutKind.Sequential)]
- public sealed partial class AssemblyBuilder : Assembly
- {
- //
- // AssemblyBuilder inherits from Assembly, but the runtime thinks its layout inherits from RuntimeAssembly
- //
- #region Sync with RuntimeAssembly.cs and ReflectionAssembly in object-internals.h
-#pragma warning disable 649
- internal IntPtr _mono_assembly;
-#pragma warning restore 649
- object _evidence;
- #endregion
-
-#pragma warning disable 169, 414, 649
- #region Sync with object-internals.h
- private UIntPtr dynamic_assembly; /* GC-tracked */
- private MethodInfo entry_point;
- private ModuleBuilder[] modules;
- private string name;
- private string dir;
- private CustomAttributeBuilder[] cattrs;
- private object resources;
- byte[] public_key;
- string version;
- string culture;
- uint algid;
- uint flags;
- PEFileKinds pekind = PEFileKinds.Dll;
- bool delay_sign;
- uint access;
- Module[] loaded_modules;
- object win32_resources;
- private object permissions_minimum;
- private object permissions_optional;
- private object permissions_refused;
- PortableExecutableKinds peKind;
- ImageFileMachine machine;
- bool corlib_internal;
- Type[] type_forwarders;
- byte[] pktoken;
- #endregion
-#pragma warning restore 169, 414, 649
-
- AssemblyName aname;
- string assemblyName;
- bool created;
- string versioninfo_culture;
- ModuleBuilder manifest_module;
- bool manifest_module_used;
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern void basic_init (AssemblyBuilder ab);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern void UpdateNativeCustomAttributes (AssemblyBuilder ab);
-
- [PreserveDependency ("RuntimeResolve", "System.Reflection.Emit.ModuleBuilder")]
- internal AssemblyBuilder (AssemblyName n, string directory, AssemblyBuilderAccess access, bool corlib_internal)
- {
- aname = (AssemblyName)n.Clone ();
-
- if (!Enum.IsDefined (typeof (AssemblyBuilderAccess), access))
- throw new ArgumentException (string.Format (CultureInfo.InvariantCulture,
- "Argument value {0} is not valid.", (int) access),
- "access");
-
- name = n.Name;
- this.access = (uint)access;
- flags = (uint) n.Flags;
-
- dir = directory;
-
- /* Set defaults from n */
- if (n.CultureInfo != null) {
- culture = n.CultureInfo.Name;
- versioninfo_culture = n.CultureInfo.Name;
- }
- Version v = n.Version;
- if (v != null) {
- version = v.ToString ();
- }
-
- basic_init (this);
-
- // Netcore only allows one module per assembly
- manifest_module = new ModuleBuilder (this, "RefEmit_InMemoryManifestModule", false);
- modules = new ModuleBuilder [] { manifest_module };
- }
-
- public override string CodeBase {
- get { throw not_supported (); }
- }
-
- public override MethodInfo EntryPoint {
- get {
- return entry_point;
- }
- }
-
- public override string Location {
- get {
- throw not_supported ();
- }
- }
-
- public override bool ReflectionOnly {
- get { return base.ReflectionOnly; }
- }
-
- public static AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access)
- {
- if (name == null)
- throw new ArgumentNullException ("name");
-
- return new AssemblyBuilder (name, null, access, false);
- }
-
- public static AssemblyBuilder DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
- {
- var ab = DefineDynamicAssembly (name, access);
- if (assemblyAttributes != null) {
- foreach (var attr in assemblyAttributes)
- ab.SetCustomAttribute (attr);
- }
-
- return ab;
- }
-
- public ModuleBuilder DefineDynamicModule (string name)
- {
- return DefineDynamicModule (name, false);
- }
-
- public ModuleBuilder DefineDynamicModule (string name, bool emitSymbolInfo)
- {
- if (name == null)
- throw new ArgumentNullException ("name");
- if (name.Length == 0)
- throw new ArgumentException ("Empty name is not legal.", "name");
- if (name[0] == '\0')
- throw new ArgumentException (SR.Argument_InvalidName, nameof (name));
-
- if (manifest_module_used)
- throw new InvalidOperationException (SR.InvalidOperation_NoMultiModuleAssembly);
- manifest_module_used = true;
- return manifest_module;
- }
-
- public ModuleBuilder GetDynamicModule (string name)
- {
- if (name == null)
- throw new ArgumentNullException ("name");
- if (name.Length == 0)
- throw new ArgumentException ("Empty name is not legal.", "name");
-
- if (modules != null)
- for (int i = 0; i < modules.Length; ++i)
- if (modules [i].name == name)
- return modules [i];
- return null;
- }
-
- public override Type[] GetExportedTypes ()
- {
- throw not_supported ();
- }
-
- public override FileStream GetFile (string name)
- {
- throw not_supported ();
- }
-
- public override FileStream[] GetFiles(bool getResourceModules) {
- throw not_supported ();
- }
-
- public override ManifestResourceInfo GetManifestResourceInfo(string resourceName) {
- throw not_supported ();
- }
-
- public override string[] GetManifestResourceNames() {
- throw not_supported ();
- }
-
- public override Stream GetManifestResourceStream(string name) {
- throw not_supported ();
- }
- public override Stream GetManifestResourceStream(Type type, string name) {
- throw not_supported ();
- }
-
- public override bool IsCollectible {
- get {
- return access == (uint)AssemblyBuilderAccess.RunAndCollect;
- }
- }
-
- internal string AssemblyDir {
- get {
- return dir;
- }
- }
-
- public void SetCustomAttribute( CustomAttributeBuilder customBuilder)
- {
- if (customBuilder == null)
- throw new ArgumentNullException ("customBuilder");
-
- if (cattrs != null) {
- CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
- cattrs.CopyTo (new_array, 0);
- new_array [cattrs.Length] = customBuilder;
- cattrs = new_array;
- } else {
- cattrs = new CustomAttributeBuilder [1];
- cattrs [0] = customBuilder;
- }
-
- /*
- Only update the native list of custom attributes if we're adding one that is known to change dynamic execution behavior.
- */
- if (customBuilder.Ctor != null && customBuilder.Ctor.DeclaringType == typeof (System.Runtime.CompilerServices.RuntimeCompatibilityAttribute))
- UpdateNativeCustomAttributes (this);
- }
-
- [ComVisible (true)]
- public void SetCustomAttribute ( ConstructorInfo con, byte[] binaryAttribute) {
- if (con == null)
- throw new ArgumentNullException ("con");
- if (binaryAttribute == null)
- throw new ArgumentNullException ("binaryAttribute");
-
- SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
- }
-
- private Exception not_supported () {
- // Strange message but this is what MS.NET prints...
- return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
- }
-
- private String create_assembly_version (String version) {
- String[] parts = version.Split ('.');
- int[] ver = new int [4] { 0, 0, 0, 0 };
-
- if ((parts.Length < 0) || (parts.Length > 4))
- throw new ArgumentException ("The version specified '" + version + "' is invalid");
-
- for (int i = 0; i < parts.Length; ++i) {
- if (parts [i] == "*") {
- DateTime now = DateTime.Now;
-
- if (i == 2) {
- ver [2] = (now - new DateTime (2000, 1, 1)).Days;
- if (parts.Length == 3)
- ver [3] = (now.Second + (now.Minute * 60) + (now.Hour * 3600)) / 2;
- }
- else
- if (i == 3)
- ver [3] = (now.Second + (now.Minute * 60) + (now.Hour * 3600)) / 2;
- else
- throw new ArgumentException ("The version specified '" + version + "' is invalid");
- }
- else {
- try {
- ver [i] = Int32.Parse (parts [i]);
- }
- catch (FormatException) {
- throw new ArgumentException ("The version specified '" + version + "' is invalid");
- }
- }
- }
-
- return ver [0] + "." + ver [1] + "." + ver [2] + "." + ver [3];
- }
-
- private string GetCultureString (string str)
- {
- return (str == "neutral" ? String.Empty : str);
- }
-
- /*Warning, @typeArguments must be a mscorlib internal array. So make a copy before passing it in*/
- internal Type MakeGenericType (Type gtd, Type[] typeArguments)
- {
- return new TypeBuilderInstantiation (gtd, typeArguments);
- }
-
- public override Type GetType (string name, bool throwOnError, bool ignoreCase)
- {
- if (name == null)
- throw new ArgumentNullException (name);
- if (name.Length == 0)
- throw new ArgumentException ("Name cannot be empty", nameof (name));
-
- var res = InternalGetType (null, name, throwOnError, ignoreCase);
- if (res is TypeBuilder) {
- if (throwOnError)
- throw new TypeLoadException (string.Format ("Could not load type '{0}' from assembly '{1}'", name, this.name));
- return null;
- }
- return res;
- }
-
- public override Module GetModule (String name)
- {
- if (name == null)
- throw new ArgumentNullException ("name");
- if (name.Length == 0)
- throw new ArgumentException ("Name can't be empty");
-
- if (modules == null)
- return null;
-
- foreach (Module module in modules) {
- if (module.ScopeName == name)
- return module;
- }
-
- return null;
- }
-
- public override Module[] GetModules (bool getResourceModules)
- {
- return (Module[])modules.Clone ();
- }
-
- public override AssemblyName GetName (bool copiedName)
- {
- return AssemblyName.Create (_mono_assembly, null);
- }
-
- // FIXME: "This always returns an empty array"
- public override AssemblyName[] GetReferencedAssemblies ()
- {
- throw new NotImplementedException ();
-#if FALSE
- return GetReferencedAssemblies (this);
-#endif
- }
-
- public override Module[] GetLoadedModules (bool getResourceModules)
- {
- return GetModules (getResourceModules);
- }
-
- //FIXME MS has issues loading satelite assemblies from SRE
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public override Assembly GetSatelliteAssembly (CultureInfo culture)
- {
- throw new NotImplementedException ();
-#if FALSE
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return GetSatelliteAssembly (culture, null, true, ref stackMark);
-#endif
- }
-
- //FIXME MS has issues loading satelite assemblies from SRE
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public override Assembly GetSatelliteAssembly (CultureInfo culture, Version version)
- {
- throw new NotImplementedException ();
-#if FALSE
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return GetSatelliteAssembly (culture, version, true, ref stackMark);
-#endif
- }
-
- public override Module ManifestModule {
- get {
- return manifest_module;
- }
- }
-
- public override bool GlobalAssemblyCache {
- get {
- return false;
- }
- }
-
- public override bool IsDynamic {
- get { return true; }
- }
-
- public override bool Equals (object obj)
- {
- return base.Equals (obj);
- }
-
- public override int GetHashCode ()
- {
- return base.GetHashCode ();
- }
-
- public override string ToString ()
- {
- if (assemblyName != null)
- return assemblyName;
-
- assemblyName = FullName;
- return assemblyName;
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- return CustomAttribute.IsDefined (this, attributeType, inherit);
- }
-
- public override object[] GetCustomAttributes (bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, inherit);
- }
-
- public override object[] GetCustomAttributes (Type attributeType, bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
- }
-
- public override IList<CustomAttributeData> GetCustomAttributesData ()
- {
- return CustomAttributeData.GetCustomAttributes (this);
- }
-
- public override string FullName {
- get {
- return aname.ToString ();
- }
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs
deleted file mode 100644
index 7874748a0a2..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs
+++ /dev/null
@@ -1,373 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit.ConstructorBuilder.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Globalization;
-using System.Runtime.InteropServices;
-using System.Diagnostics.SymbolStore;
-
-namespace System.Reflection.Emit {
- [StructLayout (LayoutKind.Sequential)]
- public sealed partial class ConstructorBuilder : ConstructorInfo {
-
-#pragma warning disable 169, 414
- private RuntimeMethodHandle mhandle;
- private ILGenerator ilgen;
- internal Type[] parameters;
- private MethodAttributes attrs;
- private MethodImplAttributes iattrs;
- private int table_idx;
- private CallingConventions call_conv;
- private TypeBuilder type;
- internal ParameterBuilder[] pinfo;
- private CustomAttributeBuilder[] cattrs;
- private bool init_locals = true;
- private Type[][] paramModReq;
- private Type[][] paramModOpt;
- private object permissions;
-#pragma warning restore 169, 414
- internal bool finished;
-
- internal ConstructorBuilder (TypeBuilder tb, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Type[][] paramModReq, Type[][] paramModOpt)
- {
- attrs = attributes | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName;
- call_conv = callingConvention;
- if (parameterTypes != null) {
- for (int i = 0; i < parameterTypes.Length; ++i)
- if (parameterTypes [i] == null)
- throw new ArgumentException ("Elements of the parameterTypes array cannot be null", "parameterTypes");
-
- this.parameters = new Type [parameterTypes.Length];
- System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
- }
- type = tb;
- this.paramModReq = paramModReq;
- this.paramModOpt = paramModOpt;
- table_idx = get_next_table_index (this, 0x06, 1);
-
- ((ModuleBuilder) tb.Module).RegisterToken (this, GetToken ().Token);
- }
-
- // FIXME:
- public override CallingConventions CallingConvention {
- get {
- return call_conv;
- }
- }
-
- public bool InitLocals {
- get {
- return init_locals;
- }
- set {
- init_locals = value;
- }
- }
-
- internal TypeBuilder TypeBuilder {
- get {
- return type;
- }
- }
-
- public override MethodImplAttributes GetMethodImplementationFlags ()
- {
- return iattrs;
- }
-
- public override ParameterInfo[] GetParameters ()
- {
- if (!type.is_created)
- throw not_created ();
-
- return GetParametersInternal ();
- }
-
- internal override ParameterInfo [] GetParametersInternal ()
- {
- if (parameters == null)
- return Array.Empty<ParameterInfo> ();
-
- ParameterInfo [] retval = new ParameterInfo [parameters.Length];
- for (int i = 0; i < parameters.Length; i++)
- retval [i] = RuntimeParameterInfo.New (pinfo?[i + 1], parameters [i], this, i + 1);
-
- return retval;
- }
-
- internal override int GetParametersCount ()
- {
- if (parameters == null)
- return 0;
-
- return parameters.Length;
- }
-
- internal override Type GetParameterType (int pos) {
- return parameters [pos];
- }
-
- internal MethodBase RuntimeResolve () {
- return type.RuntimeResolve ().GetConstructor (this);
- }
-
- public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
- {
- throw not_supported ();
- }
-
- public override object Invoke (BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
- {
- throw not_supported ();
- }
-
- public override RuntimeMethodHandle MethodHandle {
- get {
- throw not_supported ();
- }
- }
-
- public override MethodAttributes Attributes {
- get {
- return attrs;
- }
- }
-
- public override Type ReflectedType {
- get {
- return type;
- }
- }
-
- public override Type DeclaringType {
- get {
- return type;
- }
- }
-
- public override string Name {
- get {
- return (attrs & MethodAttributes.Static) != 0 ? ConstructorInfo.TypeConstructorName : ConstructorInfo.ConstructorName;
- }
- }
-
- public string Signature {
- get {
- return "constructor signature";
- }
- }
-
- public ParameterBuilder DefineParameter (int iSequence, ParameterAttributes attributes, string strParamName)
- {
- // The 0th ParameterBuilder does not correspond to an
- // actual parameter, but .NETFramework lets you define
- // it anyway. It is not useful.
- if (iSequence < 0 || iSequence > GetParametersCount ())
- throw new ArgumentOutOfRangeException ("iSequence");
- if (type.is_created)
- throw not_after_created ();
-
- ParameterBuilder pb = new ParameterBuilder (this, iSequence, attributes, strParamName);
- if (pinfo == null)
- pinfo = new ParameterBuilder [parameters.Length + 1];
- pinfo [iSequence] = pb;
- return pb;
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- throw not_supported ();
- }
-
- public override object [] GetCustomAttributes (bool inherit)
- {
- throw not_supported ();
- }
-
- public override object [] GetCustomAttributes (Type attributeType, bool inherit)
- {
- throw not_supported ();
- }
-
- public ILGenerator GetILGenerator ()
- {
- return GetILGenerator (64);
- }
-
- public ILGenerator GetILGenerator (int streamSize)
- {
- if (finished)
- throw new InvalidOperationException ();
- if (ilgen != null)
- return ilgen;
- if (!(((attrs & (MethodAttributes.Abstract | MethodAttributes.PinvokeImpl)) == 0) && ((iattrs & (MethodImplAttributes.Runtime | MethodImplAttributes.InternalCall)) == 0)))
- throw new InvalidOperationException ();
- ilgen = new ILGenerator (type.Module, ((ModuleBuilder)type.Module).GetTokenGenerator (), streamSize);
- return ilgen;
- }
-
- public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
- {
- if (customBuilder == null)
- throw new ArgumentNullException ("customBuilder");
-
- string attrname = customBuilder.Ctor.ReflectedType.FullName;
- if (attrname == "System.Runtime.CompilerServices.MethodImplAttribute") {
- byte[] data = customBuilder.Data;
- int impla; // the (stupid) ctor takes a short or an int ...
- impla = (int)data [2];
- impla |= ((int)data [3]) << 8;
- SetImplementationFlags ((MethodImplAttributes)impla);
- return;
- }
- if (cattrs != null) {
- CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
- cattrs.CopyTo (new_array, 0);
- new_array [cattrs.Length] = customBuilder;
- cattrs = new_array;
- } else {
- cattrs = new CustomAttributeBuilder [1];
- cattrs [0] = customBuilder;
- }
- }
-
- [ComVisible (true)]
- public void SetCustomAttribute (ConstructorInfo con, byte[] binaryAttribute)
- {
- if (con == null)
- throw new ArgumentNullException ("con");
- if (binaryAttribute == null)
- throw new ArgumentNullException ("binaryAttribute");
-
- SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
- }
-
- public void SetImplementationFlags (MethodImplAttributes attributes)
- {
- if (type.is_created)
- throw not_after_created ();
-
- iattrs = attributes;
- }
-
- public Module GetModule ()
- {
- return type.Module;
- }
-
- public MethodToken GetToken ()
- {
- return new MethodToken (0x06000000 | table_idx);
- }
-
- public override Module Module {
- get {
- return GetModule ();
- }
- }
-
- public override string ToString ()
- {
- return "ConstructorBuilder ['" + type.Name + "']";
- }
-
- internal void fixup ()
- {
- if (((attrs & (MethodAttributes.Abstract | MethodAttributes.PinvokeImpl)) == 0) && ((iattrs & (MethodImplAttributes.Runtime | MethodImplAttributes.InternalCall)) == 0)) {
- if ((ilgen == null) || (ilgen.ILOffset == 0))
- throw new InvalidOperationException ("Method '" + Name + "' does not have a method body.");
- }
- if (IsStatic &&
- ((call_conv & CallingConventions.VarArgs) != 0 ||
- (call_conv & CallingConventions.HasThis) != 0))
- throw new TypeLoadException ();
- if (ilgen != null)
- ilgen.label_fixup (this);
- }
-
- internal void ResolveUserTypes () {
- TypeBuilder.ResolveUserTypes (parameters);
- if (paramModReq != null) {
- foreach (var types in paramModReq)
- TypeBuilder.ResolveUserTypes (types);
- }
- if (paramModOpt != null) {
- foreach (var types in paramModOpt)
- TypeBuilder.ResolveUserTypes (types);
- }
- }
-/*
- internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
- {
- if (ilgen != null && ilgen.HasDebugInfo) {
- SymbolToken token = new SymbolToken (GetToken().Token);
- symbolWriter.OpenMethod (token);
- symbolWriter.SetSymAttribute (token, "__name", System.Text.Encoding.UTF8.GetBytes (Name));
- ilgen.GenerateDebugInfo (symbolWriter);
- symbolWriter.CloseMethod ();
- }
- }
-*/
- internal override int get_next_table_index (object obj, int table, int count)
- {
- return type.get_next_table_index (obj, table, count);
- }
-
- private void RejectIfCreated ()
- {
- if (type.is_created)
- throw new InvalidOperationException ("Type definition of the method is complete.");
- }
-
- private Exception not_supported ()
- {
- return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
- }
-
- private Exception not_after_created ()
- {
- return new InvalidOperationException ("Unable to change after type has been created.");
- }
-
- private Exception not_created ()
- {
- return new NotSupportedException ("The type is not yet created.");
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorOnTypeBuilderInst.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorOnTypeBuilderInst.cs
deleted file mode 100644
index 835f161f25b..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorOnTypeBuilderInst.cs
+++ /dev/null
@@ -1,227 +0,0 @@
-#nullable disable
-//
-// System.Reflection.Emit/ConstructorOnTypeBuilderInst.cs
-//
-// Author:
-// Zoltan Varga (vargaz@gmail.com)
-//
-//
-// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Globalization;
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit
-{
- /*
- * This class represents a ctor of an instantiation of a generic type builder.
- */
- [StructLayout (LayoutKind.Sequential)]
- internal class ConstructorOnTypeBuilderInst : ConstructorInfo
- {
- #region Keep in sync with object-internals.h
- internal TypeBuilderInstantiation instantiation;
- internal ConstructorInfo cb;
- #endregion
-
- public ConstructorOnTypeBuilderInst (TypeBuilderInstantiation instantiation, ConstructorInfo cb)
- {
- this.instantiation = instantiation;
- this.cb = cb;
- }
-
- //
- // MemberInfo members
- //
-
- public override Type DeclaringType {
- get {
- return instantiation;
- }
- }
-
- public override string Name {
- get {
- return cb.Name;
- }
- }
-
- public override Type ReflectedType {
- get {
- return instantiation;
- }
- }
-
- public override Module Module {
- get {
- return cb.Module;
- }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- return cb.IsDefined (attributeType, inherit);
- }
-
- public override object [] GetCustomAttributes (bool inherit)
- {
- return cb.GetCustomAttributes (inherit);
- }
-
- public override object [] GetCustomAttributes (Type attributeType, bool inherit)
- {
- return cb.GetCustomAttributes (attributeType, inherit);
- }
-
- //
- // MethodBase members
- //
-
- public override MethodImplAttributes GetMethodImplementationFlags ()
- {
- return cb.GetMethodImplementationFlags ();
- }
-
- public override ParameterInfo[] GetParameters ()
- {
- /*FIXME, maybe the right thing to do when the type is creates is to retrieve from the inflated type*/
- if (!instantiation.IsCreated)
- throw new NotSupportedException ();
-
- return GetParametersInternal ();
- }
-
- internal override ParameterInfo[] GetParametersInternal ()
- {
- ParameterInfo [] res;
- if (cb is ConstructorBuilder) {
- ConstructorBuilder cbuilder = (ConstructorBuilder)cb;
- res = new ParameterInfo [cbuilder.parameters.Length];
- for (int i = 0; i < cbuilder.parameters.Length; i++) {
- Type type = instantiation.InflateType (cbuilder.parameters [i]);
- res [i] = RuntimeParameterInfo.New (cbuilder.pinfo?[i], type, this, i + 1);
- }
- } else {
- ParameterInfo[] parms = cb.GetParameters ();
- res = new ParameterInfo [parms.Length];
- for (int i = 0; i < parms.Length; i++) {
- Type type = instantiation.InflateType (parms [i].ParameterType);
- res [i] = RuntimeParameterInfo.New (parms [i], type, this, i + 1);
- }
- }
- return res;
- }
-
- internal override Type[] GetParameterTypes () {
- if (cb is ConstructorBuilder) {
- return (cb as ConstructorBuilder).parameters;
- } else {
- ParameterInfo[] parms = cb.GetParameters ();
- var res = new Type [parms.Length];
- for (int i = 0; i < parms.Length; i++) {
- res [i] = parms [i].ParameterType;
- }
- return res;
- }
- }
-
- // Called from the runtime to return the corresponding finished ConstructorInfo object
- internal ConstructorInfo RuntimeResolve () {
- var type = instantiation.InternalResolve ();
- return type.GetConstructor (cb);
- }
-
- public override int MetadataToken {
- get {
- return base.MetadataToken;
- }
- }
-
- internal override int GetParametersCount ()
- {
- return cb.GetParametersCount ();
- }
-
- public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
- {
- return cb.Invoke (obj, invokeAttr, binder, parameters,
- culture);
- }
-
- public override RuntimeMethodHandle MethodHandle {
- get {
- return cb.MethodHandle;
- }
- }
-
- public override MethodAttributes Attributes {
- get {
- return cb.Attributes;
- }
- }
-
- public override CallingConventions CallingConvention {
- get {
- return cb.CallingConvention;
- }
- }
-
- public override Type [] GetGenericArguments ()
- {
- return cb.GetGenericArguments ();
- }
-
- public override bool ContainsGenericParameters {
- get {
- return false;
- }
- }
-
- public override bool IsGenericMethodDefinition {
- get {
- return false;
- }
- }
-
- public override bool IsGenericMethod {
- get {
- return false;
- }
- }
-
- //
- // MethodBase members
- //
-
- public override object Invoke (BindingFlags invokeAttr, Binder binder, object[] parameters,
- CultureInfo culture)
- {
- throw new InvalidOperationException ();
- }
- }
-}
-
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs
deleted file mode 100644
index 8c75be019e8..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs
+++ /dev/null
@@ -1,552 +0,0 @@
-#nullable disable
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//
-// System.Reflection.Emit/CustomAttributeBuilder.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit {
- [StructLayout (LayoutKind.Sequential)]
- public partial class CustomAttributeBuilder {
- ConstructorInfo ctor;
- byte[] data;
- object [] args;
- PropertyInfo [] namedProperties;
- object [] propertyValues;
- FieldInfo [] namedFields;
- object [] fieldValues;
-
- internal ConstructorInfo Ctor {
- get {return ctor;}
- }
-
- internal byte[] Data {
- get {return data;}
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern byte[] GetBlob(Assembly asmb, ConstructorInfo con, object[] constructorArgs, PropertyInfo[] namedProperties, object[] propertyValues, FieldInfo[] namedFields, object[] fieldValues);
-
- internal object Invoke ()
- {
- object result = ctor.Invoke (args);
-
- for (int i=0; i < namedFields.Length; i++)
- namedFields [i].SetValue (result, fieldValues [i]);
-
- for (int i=0; i < namedProperties.Length; i++)
- namedProperties [i].SetValue (result, propertyValues [i]);
-
- return result;
- }
-
- internal CustomAttributeBuilder( ConstructorInfo con, byte[] binaryAttribute) {
- if (con == null)
- throw new ArgumentNullException ("con");
- if (binaryAttribute == null)
- throw new ArgumentNullException ("binaryAttribute");
- ctor = con;
- data = (byte[])binaryAttribute.Clone ();
- /* should we check that the user supplied data is correct? */
- }
-
- public CustomAttributeBuilder( ConstructorInfo con, object[] constructorArgs)
- {
- Initialize (con, constructorArgs, new PropertyInfo [0], new object [0],
- new FieldInfo [0], new object [0]);
- }
- public CustomAttributeBuilder( ConstructorInfo con, object[] constructorArgs,
- FieldInfo[] namedFields, object[] fieldValues)
- {
- Initialize (con, constructorArgs, new PropertyInfo [0], new object [0],
- namedFields, fieldValues);
- }
- public CustomAttributeBuilder( ConstructorInfo con, object[] constructorArgs,
- PropertyInfo[] namedProperties, object[] propertyValues)
- {
- Initialize (con, constructorArgs, namedProperties, propertyValues, new FieldInfo [0],
- new object [0]);
- }
- public CustomAttributeBuilder( ConstructorInfo con, object[] constructorArgs,
- PropertyInfo[] namedProperties, object[] propertyValues,
- FieldInfo[] namedFields, object[] fieldValues)
- {
- Initialize (con, constructorArgs, namedProperties, propertyValues, namedFields, fieldValues);
- }
-
- private bool IsValidType (Type t)
- {
- /* FIXME: Add more checks */
- if (t.IsArray && t.GetArrayRank () > 1)
- return false;
- if (t is TypeBuilder && t.IsEnum) {
- // Check that the enum is properly constructed, the unmanaged code
- // depends on this
- Enum.GetUnderlyingType (t);
- }
- if (t.IsClass && !(t.IsArray || t == typeof (object) || t == typeof (Type) || t == typeof (string) || t.Assembly.GetName ().Name == "mscorlib"))
- return false;
- if (t.IsValueType && !(t.IsPrimitive || t.IsEnum || ((t.Assembly is AssemblyBuilder) && t.Assembly.GetName ().Name == "mscorlib")))
- return false;
- return true;
- }
-
- private bool IsValidParam (object o, Type paramType)
- {
- Type t = o.GetType ();
- if (!IsValidType (t))
- return false;
- if (paramType == typeof (object)) {
- if (t.IsArray && t.GetArrayRank () == 1)
- return IsValidType (t.GetElementType ());
- if (!t.IsPrimitive && !typeof (Type).IsAssignableFrom (t) && t != typeof (string) && !t.IsEnum)
- return false;
- }
- return true;
- }
-
- static bool IsValidValue (Type type, object value) {
- if (type.IsValueType && value == null)
- return false;
- if (type.IsArray && type.GetElementType ().IsValueType) {
- foreach (var v in (Array)value) {
- if (v == null)
- return false;
- }
- }
- return true;
- }
-
- private void Initialize (ConstructorInfo con, object [] constructorArgs,
- PropertyInfo [] namedProperties, object [] propertyValues,
- FieldInfo [] namedFields, object [] fieldValues)
- {
- ctor = con;
- args = constructorArgs;
- this.namedProperties = namedProperties;
- this.propertyValues = propertyValues;
- this.namedFields = namedFields;
- this.fieldValues = fieldValues;
-
- if (con == null)
- throw new ArgumentNullException ("con");
- if (constructorArgs == null)
- throw new ArgumentNullException ("constructorArgs");
- if (namedProperties == null)
- throw new ArgumentNullException ("namedProperties");
- if (propertyValues == null)
- throw new ArgumentNullException ("propertyValues");
- if (namedFields == null)
- throw new ArgumentNullException ("namedFields");
- if (fieldValues == null)
- throw new ArgumentNullException ("fieldValues");
- if (con.GetParametersCount () != constructorArgs.Length)
- throw new ArgumentException ("Parameter count does not match " +
- "passed in argument value count.");
- if (namedProperties.Length != propertyValues.Length)
- throw new ArgumentException ("Array lengths must be the same.",
- "namedProperties, propertyValues");
- if (namedFields.Length != fieldValues.Length)
- throw new ArgumentException ("Array lengths must be the same.",
- "namedFields, fieldValues");
- if ((con.Attributes & MethodAttributes.Static) == MethodAttributes.Static ||
- (con.Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private)
- throw new ArgumentException ("Cannot have private or static constructor.");
-
- Type atype = ctor.DeclaringType;
- int i;
- i = 0;
- foreach (FieldInfo fi in namedFields) {
- Type t = fi.DeclaringType;
- if ((atype != t) && (!t.IsSubclassOf (atype)) && (!atype.IsSubclassOf (t)))
- throw new ArgumentException ("Field '" + fi.Name + "' does not belong to the same class as the constructor");
- if (!IsValidType (fi.FieldType))
- throw new ArgumentException ("Field '" + fi.Name + "' does not have a valid type.");
- if (!IsValidValue (fi.FieldType, fieldValues [i]))
- throw new ArgumentException ("Field " + fi.Name + " is not a valid value.");
- // FIXME: Check enums and TypeBuilders as well
- if (fieldValues [i] != null)
- // IsEnum does not seem to work on TypeBuilders
- if (!(fi.FieldType is TypeBuilder) && !fi.FieldType.IsEnum && !fi.FieldType.IsInstanceOfType (fieldValues [i])) {
- //
- // mcs allways uses object[] for array types and
- // MS.NET allows this
- //
- if (!fi.FieldType.IsArray)
- throw new ArgumentException ("Value of field '" + fi.Name + "' does not match field type: " + fi.FieldType);
- }
- i ++;
- }
-
- i = 0;
- foreach (PropertyInfo pi in namedProperties) {
- if (!pi.CanWrite)
- throw new ArgumentException ("Property '" + pi.Name + "' does not have a setter.");
- Type t = pi.DeclaringType;
- if ((atype != t) && (!t.IsSubclassOf (atype)) && (!atype.IsSubclassOf (t)))
- throw new ArgumentException ("Property '" + pi.Name + "' does not belong to the same class as the constructor");
- if (!IsValidType (pi.PropertyType))
- throw new ArgumentException ("Property '" + pi.Name + "' does not have a valid type.");
- if (!IsValidValue (pi.PropertyType, propertyValues [i]))
- throw new ArgumentException ("Property " + pi.Name + " is not a valid value.");
- if (propertyValues [i] != null) {
- if (!(pi.PropertyType is TypeBuilder) && !pi.PropertyType.IsEnum && !pi.PropertyType.IsInstanceOfType (propertyValues [i]))
- if (!pi.PropertyType.IsArray)
- throw new ArgumentException ("Value of property '" + pi.Name + "' does not match property type: " + pi.PropertyType + " -> " + propertyValues [i]);
- }
- i ++;
- }
-
- i = 0;
- foreach (ParameterInfo pi in GetParameters (con)) {
- if (pi != null) {
- Type paramType = pi.ParameterType;
- if (!IsValidType (paramType))
- throw new ArgumentException ("Parameter " + i + " does not have a valid type.");
- if (!IsValidValue (paramType, constructorArgs [i]))
- throw new ArgumentException ("Parameter " + i + " is not a valid value.");
-
- if (constructorArgs [i] != null) {
- if (!(paramType is TypeBuilder) && !paramType.IsEnum && !paramType.IsInstanceOfType (constructorArgs [i]))
- if (!paramType.IsArray)
- throw new ArgumentException ("Value of argument " + i + " does not match parameter type: " + paramType + " -> " + constructorArgs [i]);
- if (!IsValidParam (constructorArgs [i], paramType))
- throw new ArgumentException ("Cannot emit a CustomAttribute with argument of type " + constructorArgs [i].GetType () + ".");
- }
- }
- i ++;
- }
-
- data = GetBlob (atype.Assembly, con, constructorArgs, namedProperties, propertyValues, namedFields, fieldValues);
- }
-
- /* helper methods */
- internal static int decode_len (byte[] data, int pos, out int rpos) {
- int len = 0;
- if ((data [pos] & 0x80) == 0) {
- len = (int)(data [pos++] & 0x7f);
- } else if ((data [pos] & 0x40) == 0) {
- len = ((data [pos] & 0x3f) << 8) + data [pos + 1];
- pos += 2;
- } else {
- len = ((data [pos] & 0x1f) << 24) + (data [pos + 1] << 16) + (data [pos + 2] << 8) + data [pos + 3];
- pos += 4;
- }
- rpos = pos;
- return len;
- }
-
- internal static string string_from_bytes (byte[] data, int pos, int len)
- {
- return System.Text.Encoding.UTF8.GetString(data, pos, len);
- }
-
- internal static string decode_string (byte [] data, int pos, out int rpos)
- {
- if (data [pos] == 0xff) {
- rpos = pos + 1;
- return null;
- } else {
- int len = decode_len (data, pos, out pos);
- string s = string_from_bytes (data, pos, len);
- pos += len;
- rpos = pos;
- return s;
- }
- }
-
- internal string string_arg ()
- {
- int pos = 2;
- return decode_string (data, pos, out pos);
- }
-
- internal static UnmanagedMarshal get_umarshal (CustomAttributeBuilder customBuilder, bool is_field) {
- byte[] data = customBuilder.Data;
- UnmanagedType subtype = (UnmanagedType)0x50; /* NATIVE_MAX */
- int sizeConst = -1;
- int sizeParamIndex = -1;
- bool hasSize = false;
- int value;
- int utype; /* the (stupid) ctor takes a short or an enum ... */
- string marshalTypeName = null;
- Type marshalTypeRef = null;
- string marshalCookie = String.Empty;
- utype = (int)data [2];
- utype |= ((int)data [3]) << 8;
-
- string first_type_name = GetParameters (customBuilder.Ctor) [0].ParameterType.FullName;
- int pos = 6;
- if (first_type_name == "System.Int16")
- pos = 4;
- int nnamed = (int)data [pos++];
- nnamed |= ((int)data [pos++]) << 8;
-
- for (int i = 0; i < nnamed; ++i) {
- int paramType; // What is this ?
-
- /* Skip field/property signature */
- int fieldPropSig = (int)data [pos ++];
- /* Read type */
- paramType = ((int)data [pos++]);
- if (paramType == 0x55) {
- /* enums, the value is preceeded by the type */
- decode_string (data, pos, out pos);
- }
- string named_name = decode_string (data, pos, out pos);
-
- switch (named_name) {
- case "ArraySubType":
- value = (int)data [pos++];
- value |= ((int)data [pos++]) << 8;
- value |= ((int)data [pos++]) << 16;
- value |= ((int)data [pos++]) << 24;
- subtype = (UnmanagedType)value;
- break;
- case "SizeConst":
- value = (int)data [pos++];
- value |= ((int)data [pos++]) << 8;
- value |= ((int)data [pos++]) << 16;
- value |= ((int)data [pos++]) << 24;
- sizeConst = value;
- hasSize = true;
- break;
- case "SafeArraySubType":
- value = (int)data[pos++];
- value |= ((int)data[pos++]) << 8;
- value |= ((int)data[pos++]) << 16;
- value |= ((int)data[pos++]) << 24;
- subtype = (UnmanagedType)value;
- break;
- case "IidParameterIndex":
- pos += 4;
- break;
- case "SafeArrayUserDefinedSubType":
- decode_string (data, pos, out pos);
- break;
- case "SizeParamIndex":
- value = (int)data [pos++];
- value |= ((int)data [pos++]) << 8;
- sizeParamIndex = value;
- hasSize = true;
- break;
- case "MarshalType":
- marshalTypeName = decode_string (data, pos, out pos);
- break;
- case "MarshalTypeRef":
- marshalTypeName = decode_string (data, pos, out pos);
- if (marshalTypeName != null)
- marshalTypeRef = Type.GetType (marshalTypeName);
- break;
- case "MarshalCookie":
- marshalCookie = decode_string (data, pos, out pos);
- break;
- default:
- throw new Exception ("Unknown MarshalAsAttribute field: " + named_name);
- }
- }
-
- switch ((UnmanagedType)utype) {
- case UnmanagedType.LPArray:
- if (hasSize)
- return UnmanagedMarshal.DefineLPArrayInternal (subtype, sizeConst, sizeParamIndex);
- else
- return UnmanagedMarshal.DefineLPArray (subtype);
-#if FEATURE_COMINTEROP
- case UnmanagedType.SafeArray:
- return UnmanagedMarshal.DefineSafeArray (subtype);
-#endif
- case UnmanagedType.ByValArray:
- if (!is_field)
- throw new ArgumentException ("Specified unmanaged type is only valid on fields");
-
- return UnmanagedMarshal.DefineByValArray (sizeConst);
- case UnmanagedType.ByValTStr:
- return UnmanagedMarshal.DefineByValTStr (sizeConst);
-#if FEATURE_COMINTEROP
- case UnmanagedType.CustomMarshaler:
- return UnmanagedMarshal.DefineCustom (marshalTypeRef, marshalCookie, marshalTypeName, Guid.Empty);
-#endif
- default:
- return UnmanagedMarshal.DefineUnmanagedMarshal ((UnmanagedType)utype);
- }
- }
-
- static Type elementTypeToType (int elementType) {
- /* Partition II, section 23.1.16 */
- switch (elementType) {
- case 0x02:
- return typeof (bool);
- case 0x03:
- return typeof (char);
- case 0x04:
- return typeof (sbyte);
- case 0x05:
- return typeof (byte);
- case 0x06:
- return typeof (short);
- case 0x07:
- return typeof (ushort);
- case 0x08:
- return typeof (int);
- case 0x09:
- return typeof (uint);
- case 0x0a:
- return typeof (long);
- case 0x0b:
- return typeof (ulong);
- case 0x0c:
- return typeof (float);
- case 0x0d:
- return typeof (double);
- case 0x0e:
- return typeof (string);
- default:
- throw new Exception ("Unknown element type '" + elementType + "'");
- }
- }
-
- static object decode_cattr_value (Type t, byte[] data, int pos, out int rpos) {
- switch (Type.GetTypeCode (t)) {
- case TypeCode.String:
- if (data [pos] == 0xff) {
- rpos = pos + 1;
- return null;
- }
- int len = decode_len (data, pos, out pos);
- rpos = pos + len;
- return string_from_bytes (data, pos, len);
- case TypeCode.Int32:
- rpos = pos + 4;
- return data [pos] + (data [pos + 1] << 8) + (data [pos + 2] << 16) + (data [pos + 3] << 24);
- case TypeCode.Boolean:
- rpos = pos + 1;
- return (data [pos] == 0) ? false : true;
- case TypeCode.Object:
- int subtype = data [pos];
- pos += 1;
-
- if (subtype >= 0x02 && subtype <= 0x0e)
- return decode_cattr_value (elementTypeToType (subtype), data, pos, out rpos);
- else
- throw new Exception ("Subtype '" + subtype + "' of type object not yet handled in decode_cattr_value");
- default:
- throw new Exception ("FIXME: Type " + t + " not yet handled in decode_cattr_value.");
- }
- }
-
- internal struct CustomAttributeInfo {
- public ConstructorInfo ctor;
- public object[] ctorArgs;
- public string[] namedParamNames;
- public object[] namedParamValues;
- }
-
- internal static CustomAttributeInfo decode_cattr (CustomAttributeBuilder customBuilder) {
- byte[] data = customBuilder.Data;
- ConstructorInfo ctor = customBuilder.Ctor;
- int pos = 0;
-
- CustomAttributeInfo info = new CustomAttributeInfo ();
-
- // Prolog
- if (data.Length < 2)
- throw new Exception ("Custom attr length is only '" + data.Length + "'");
- if ((data [0] != 0x1) || (data [1] != 0x00))
- throw new Exception ("Prolog invalid");
- pos = 2;
-
- ParameterInfo [] pi = GetParameters (ctor);
- info.ctor = ctor;
- info.ctorArgs = new object [pi.Length];
- for (int i = 0; i < pi.Length; ++i)
- info.ctorArgs [i] = decode_cattr_value (pi [i].ParameterType, data, pos, out pos);
-
- int num_named = data [pos] + (data [pos + 1] * 256);
- pos += 2;
-
- info.namedParamNames = new string [num_named];
- info.namedParamValues = new object [num_named];
- for (int i = 0; i < num_named; ++i) {
- int named_type = data [pos++];
- int data_type = data [pos++];
- string enum_type_name = null;
-
- if (data_type == 0x55) {
- int len2 = decode_len (data, pos, out pos);
- enum_type_name = string_from_bytes (data, pos, len2);
- pos += len2;
- }
-
- int len = decode_len (data, pos, out pos);
- string name = string_from_bytes (data, pos, len);
- info.namedParamNames [i] = name;
- pos += len;
-
- if (named_type == 0x53) {
- /* Field */
- FieldInfo fi = ctor.DeclaringType.GetField (name, BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance);
- if (fi == null)
- throw new Exception ("Custom attribute type '" + ctor.DeclaringType + "' doesn't contain a field named '" + name + "'");
-
- object val = decode_cattr_value (fi.FieldType, data, pos, out pos);
- if (enum_type_name != null) {
- Type enumType = Type.GetType (enum_type_name);
- val = Enum.ToObject (enumType, val);
- }
-
- info.namedParamValues [i] = val;
- }
- else
- // FIXME:
- throw new Exception ("Unknown named type: " + named_type);
- }
-
- return info;
- }
-
- static ParameterInfo [] GetParameters (ConstructorInfo ctor)
- {
- ConstructorBuilder cb = ctor as ConstructorBuilder;
- if (cb != null)
- return cb.GetParametersInternal ();
-
- return ctor.GetParametersInternal ();
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs
deleted file mode 100644
index 4b0361ce699..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs
+++ /dev/null
@@ -1,470 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit.DerivedTypes.cs
-//
-// Authors:
-// Rodrigo Kumpera <rkumpera@novell.com>
-//
-//
-// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Collections;
-using System.Runtime.CompilerServices;
-using System.Globalization;
-using System.Runtime.InteropServices;
-using System.Runtime.Serialization;
-using System.Text;
-
-
-namespace System.Reflection.Emit
-{
- [StructLayout (LayoutKind.Sequential)]
- abstract partial class SymbolType : TypeInfo
- {
- internal Type m_baseType;
-
- internal SymbolType (Type elementType)
- {
- this.m_baseType = elementType;
- }
-
- internal abstract String FormatName (string elementName);
-
- protected override bool IsArrayImpl ()
- {
- return false;
- }
-
- protected override bool IsByRefImpl ()
- {
- return false;
- }
-
- protected override bool IsPointerImpl ()
- {
- return false;
- }
-
- public override Type MakeArrayType ()
- {
- return new ArrayType (this, 0);
- }
-
- public override Type MakeArrayType (int rank)
- {
- if (rank < 1)
- throw new IndexOutOfRangeException ();
- return new ArrayType (this, rank);
- }
-
- public override Type MakeByRefType ()
- {
- return new ByRefType (this);
- }
-
- public override Type MakePointerType ()
- {
- return new PointerType (this);
- }
-
- public override string ToString ()
- {
- return FormatName (m_baseType.ToString ());
- }
-
- public override string AssemblyQualifiedName {
- get {
- string fullName = FormatName (m_baseType.FullName);
- if (fullName == null)
- return null;
- return fullName + ", " + m_baseType.Assembly.FullName;
- }
- }
-
-
- public override string FullName {
- get {
- return FormatName (m_baseType.FullName);
- }
- }
-
- public override string Name {
- get {
- return FormatName (m_baseType.Name);
- }
- }
-
- public override Type UnderlyingSystemType {
- get {
- return this;
- }
- }
-
- internal override bool IsUserType {
- get {
- return m_baseType.IsUserType;
- }
- }
-
- // Called from the runtime to return the corresponding finished Type object
- internal override Type RuntimeResolve () {
- return InternalResolve ();
- }
-
- public override Guid GUID
- {
- get { throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType")); }
- }
-
- public override Object InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target,
- Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override Module Module
- {
- get
- {
- Type baseType;
-
- for (baseType = m_baseType; baseType is SymbolType; baseType = ((SymbolType) baseType).m_baseType);
-
- return baseType.Module;
- }
- }
- public override Assembly Assembly
- {
- get
- {
- Type baseType;
-
- for (baseType = m_baseType; baseType is SymbolType; baseType = ((SymbolType) baseType).m_baseType);
-
- return baseType.Assembly;
- }
- }
-
- public override RuntimeTypeHandle TypeHandle
- {
- get { throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType")); }
- }
-
- public override String Namespace
- {
- get { return m_baseType.Namespace; }
- }
-
- public override Type BaseType
- {
- get { return typeof(System.Array); }
- }
-
- protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr,Binder binder,
- CallingConventions callConvention, Type[] types,ParameterModifier[] modifiers)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- protected override MethodInfo GetMethodImpl(String name,BindingFlags bindingAttr,Binder binder,
- CallingConventions callConvention, Type[] types,ParameterModifier[] modifiers)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override MethodInfo[] GetMethods(BindingFlags bindingAttr)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override FieldInfo GetField(String name, BindingFlags bindingAttr)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override FieldInfo[] GetFields(BindingFlags bindingAttr)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override Type GetInterface(String name,bool ignoreCase)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override Type[] GetInterfaces()
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override EventInfo GetEvent(String name,BindingFlags bindingAttr)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override EventInfo[] GetEvents()
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- protected override PropertyInfo GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder,
- Type returnType, Type[] types, ParameterModifier[] modifiers)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override PropertyInfo[] GetProperties(BindingFlags bindingAttr)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override Type[] GetNestedTypes(BindingFlags bindingAttr)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override Type GetNestedType(String name, BindingFlags bindingAttr)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override MemberInfo[] GetMember(String name, MemberTypes type, BindingFlags bindingAttr)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override InterfaceMapping GetInterfaceMap(Type interfaceType)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override EventInfo[] GetEvents(BindingFlags bindingAttr)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- protected override TypeAttributes GetAttributeFlagsImpl()
- {
- // Return the attribute flags of the base type?
- Type baseType;
- for (baseType = m_baseType; baseType is SymbolType; baseType = ((SymbolType)baseType).m_baseType);
- return baseType.Attributes;
- }
-
- protected override bool IsPrimitiveImpl()
- {
- return false;
- }
-
- protected override bool IsValueTypeImpl()
- {
- return false;
- }
-
- protected override bool IsCOMObjectImpl()
- {
- return false;
- }
-
- public override bool IsConstructedGenericType
- {
- get
- {
- return false;
- }
- }
-
- public override Type GetElementType()
- {
- return m_baseType;
- }
-
- protected override bool HasElementTypeImpl()
- {
- return m_baseType != null;
- }
-
- public override Object[] GetCustomAttributes(bool inherit)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override Object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NonReflectedType"));
- }
- }
-
- [StructLayout (LayoutKind.Sequential)]
- internal class ArrayType : SymbolType
- {
- int rank;
-
- internal ArrayType (Type elementType, int rank) : base (elementType)
- {
- this.rank = rank;
- }
-
- internal int GetEffectiveRank ()
- {
- return rank;
- }
-
- internal override Type InternalResolve ()
- {
- Type et = m_baseType.InternalResolve ();
- if (rank == 0)
- return et.MakeArrayType ();
- return et.MakeArrayType (rank);
- }
-
- internal override Type RuntimeResolve ()
- {
- Type et = m_baseType.RuntimeResolve ();
- if (rank == 0)
- return et.MakeArrayType ();
- return et.MakeArrayType (rank);
- }
-
- protected override bool IsArrayImpl ()
- {
- return true;
- }
-
- public override bool IsSZArray {
- get {
- return rank == 0;
- }
- }
-
- public override int GetArrayRank ()
- {
- return (rank == 0) ? 1 : rank;
- }
-
- internal override String FormatName (string elementName)
- {
- if (elementName == null)
- return null;
- StringBuilder sb = new StringBuilder (elementName);
- sb.Append ("[");
- for (int i = 1; i < rank; ++i)
- sb.Append (",");
- if (rank == 1)
- sb.Append ("*");
- sb.Append ("]");
- return sb.ToString ();
- }
- }
-
- [StructLayout (LayoutKind.Sequential)]
- internal class ByRefType : SymbolType
- {
- internal ByRefType (Type elementType) : base (elementType)
- {
- }
-
- internal override Type InternalResolve ()
- {
- return m_baseType.InternalResolve ().MakeByRefType ();
- }
-
- protected override bool IsByRefImpl ()
- {
- return true;
- }
-
- internal override String FormatName (string elementName)
- {
- if (elementName == null)
- return null;
- return elementName + "&";
- }
-
- public override Type MakeArrayType ()
- {
- throw new ArgumentException ("Cannot create an array type of a byref type");
- }
-
- public override Type MakeArrayType (int rank)
- {
- throw new ArgumentException ("Cannot create an array type of a byref type");
- }
-
- public override Type MakeByRefType ()
- {
- throw new ArgumentException ("Cannot create a byref type of an already byref type");
- }
-
- public override Type MakePointerType ()
- {
- throw new ArgumentException ("Cannot create a pointer type of a byref type");
- }
- }
-
- [StructLayout (LayoutKind.Sequential)]
- internal class PointerType : SymbolType
- {
- internal PointerType (Type elementType) : base (elementType)
- {
- }
-
- internal override Type InternalResolve ()
- {
- return m_baseType.InternalResolve ().MakePointerType ();
- }
-
- protected override bool IsPointerImpl ()
- {
- return true;
- }
-
- internal override String FormatName (string elementName)
- {
- if (elementName == null)
- return null;
- return elementName + "*";
- }
- }
-
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILInfo.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILInfo.cs
deleted file mode 100644
index 9501a83f44b..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILInfo.cs
+++ /dev/null
@@ -1,133 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit/DynamicILInfo.cs
-//
-// Author:
-// Zoltan Varga (vargaz@gmail.com)
-//
-// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit {
-
- [ComVisible (true)]
- public class DynamicILInfo {
-
- DynamicMethod method;
-
- internal DynamicILInfo ()
- {
- }
-
- internal DynamicILInfo (DynamicMethod method)
- {
- this.method = method;
- }
-
- public DynamicMethod DynamicMethod {
- get {
- return method;
- }
- }
-
- // FIXME:
- public int GetTokenFor (byte[] signature) {
- throw new NotImplementedException ();
- }
-
- public int GetTokenFor (DynamicMethod method) {
- return this.method.GetILGenerator ().TokenGenerator.GetToken (method, false);
- }
-
- public int GetTokenFor (RuntimeFieldHandle field) {
- return this.method.GetILGenerator ().TokenGenerator.GetToken (FieldInfo.GetFieldFromHandle (field), false);
- }
-
- public int GetTokenFor (RuntimeMethodHandle method) {
- MethodBase mi = MethodBase.GetMethodFromHandle (method);
- return this.method.GetILGenerator ().TokenGenerator.GetToken (mi, false);
- }
-
- public int GetTokenFor (RuntimeTypeHandle type) {
- Type t = Type.GetTypeFromHandle (type);
- return this.method.GetILGenerator ().TokenGenerator.GetToken (t, false);
- }
-
- public int GetTokenFor (string literal) {
- return method.GetILGenerator ().TokenGenerator.GetToken (literal);
- }
-
- // FIXME:
- public int GetTokenFor (RuntimeMethodHandle method, RuntimeTypeHandle contextType) {
- throw new NotImplementedException ();
- }
-
- // FIXME:
- public int GetTokenFor (RuntimeFieldHandle field, RuntimeTypeHandle contextType) {
- throw new NotImplementedException ();
- }
-
- public void SetCode (byte[] code, int maxStackSize) {
- if (code == null)
- throw new ArgumentNullException ("code");
- method.GetILGenerator ().SetCode (code, maxStackSize);
- }
-
- [CLSCompliantAttribute(false)]
- public unsafe void SetCode (byte* code, int codeSize, int maxStackSize) {
- if (code == null)
- throw new ArgumentNullException ("code");
- method.GetILGenerator ().SetCode (code, codeSize, maxStackSize);
- }
-
- // FIXME:
- public void SetExceptions (byte[] exceptions) {
- throw new NotImplementedException ();
- }
-
- // FIXME:
- [CLSCompliantAttribute(false)]
- public unsafe void SetExceptions (byte* exceptions, int exceptionsSize) {
- throw new NotImplementedException ();
- }
-
- // FIXME:
- public void SetLocalSignature (byte[] localSignature) {
- throw new NotImplementedException ();
- }
-
- [CLSCompliantAttribute(false)]
- public unsafe void SetLocalSignature (byte* localSignature, int signatureSize) {
- byte[] b = new byte [signatureSize];
- for (int i = 0; i < signatureSize; ++i)
- b [i] = localSignature [i];
- }
- }
-}
-
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
deleted file mode 100644
index 13589e2c1cb..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs
+++ /dev/null
@@ -1,481 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit.DynamicMethod.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-// Zoltan Varga (vargaz@freemail.hu)
-//
-// (C) 2003 Ximian, Inc. http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-
-using System;
-using System.Text;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit {
-
- [ComVisible (true)]
- [StructLayout (LayoutKind.Sequential)]
- public sealed class DynamicMethod : MethodInfo {
-
-#pragma warning disable 169, 414, 649
- #region Sync with reflection.h
- private RuntimeMethodHandle mhandle;
- private string name;
- private Type returnType;
- private Type[] parameters;
- private MethodAttributes attributes;
- private CallingConventions callingConvention;
- private Module module;
- private bool skipVisibility;
- private bool init_locals = true;
- private ILGenerator ilgen;
- private int nrefs;
- private object[] refs;
- private IntPtr referenced_by;
- private Type owner;
- #endregion
-#pragma warning restore 169, 414, 649
-
- private Delegate deleg;
- private RuntimeMethodInfo method;
- private ParameterBuilder[] pinfo;
- internal bool creating;
- private DynamicILInfo il_info;
-
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Module m) : this (name, returnType, parameterTypes, m, false) {
- }
-
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Type owner) : this (name, returnType, parameterTypes, owner, false) {
- }
-
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Module m, bool skipVisibility) : this (name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, m, skipVisibility) {
- }
-
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility) : this (name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, owner, skipVisibility) {
- }
-
- public DynamicMethod (string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility) : this (name, attributes, callingConvention, returnType, parameterTypes, owner, owner != null ? owner.Module : null, skipVisibility, false, true) {
- }
-
- public DynamicMethod (string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Module m, bool skipVisibility) : this (name, attributes, callingConvention, returnType, parameterTypes, null, m, skipVisibility, false, false) {
- }
-
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes) : this (name, returnType, parameterTypes, false) {
- }
-
- // FIXME: "Visibility is not restricted"
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes, bool restrictedSkipVisibility)
- : this (name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, null, null, restrictedSkipVisibility, true, false)
- {
- }
-
- DynamicMethod (string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type [] parameterTypes, Type owner, Module m, bool skipVisibility, bool anonHosted, bool typeOwner)
- {
- if (name == null)
- throw new ArgumentNullException (nameof (name));
- if (returnType == null)
- returnType = typeof (void);
- if (owner == null && typeOwner)
- throw new ArgumentNullException (nameof (owner));
- if ((m == null) && !anonHosted)
- throw new ArgumentNullException (nameof (m));
- if (parameterTypes != null) {
- for (int i = 0; i < parameterTypes.Length; ++i)
- if (parameterTypes [i] == null)
- throw new ArgumentException ($"Parameter {i} is null");
- }
- if (owner != null && (owner.IsArray || owner.IsInterface)) {
- throw new ArgumentException ("Owner can't be an array or an interface.");
- }
-
- if (m == null)
- m = AnonHostModuleHolder.AnonHostModule;
-
- this.name = name;
- this.attributes = attributes | MethodAttributes.Static;
- this.callingConvention = callingConvention;
- this.returnType = returnType;
- this.parameters = parameterTypes;
- this.owner = owner;
- this.module = m;
- this.skipVisibility = skipVisibility;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern void create_dynamic_method (DynamicMethod m);
-
- private void CreateDynMethod () {
- // Clearing of ilgen in create_dynamic_method is not yet synchronized for multiple threads
- lock (this) {
- if (mhandle.Value == IntPtr.Zero) {
- if (ilgen == null || ilgen.ILOffset == 0)
- throw new InvalidOperationException ("Method '" + name + "' does not have a method body.");
-
- ilgen.label_fixup (this);
-
- // Have to create all DynamicMethods referenced by this one
- try {
- // Used to avoid cycles
- creating = true;
- if (refs != null) {
- for (int i = 0; i < refs.Length; ++i) {
- if (refs [i] is DynamicMethod) {
- DynamicMethod m = (DynamicMethod)refs [i];
- if (!m.creating)
- m.CreateDynMethod ();
- }
- }
- }
- } finally {
- creating = false;
- }
- create_dynamic_method (this);
- ilgen = null;
- }
- }
- }
-
- [ComVisible (true)]
- sealed override
- public Delegate CreateDelegate (Type delegateType)
- {
- if (delegateType == null)
- throw new ArgumentNullException ("delegateType");
- if (deleg != null)
- return deleg;
-
- CreateDynMethod ();
-
- deleg = Delegate.CreateDelegate (delegateType, null, this);
- return deleg;
- }
-
- [ComVisible (true)]
- sealed override
- public Delegate CreateDelegate (Type delegateType, object target)
- {
- if (delegateType == null)
- throw new ArgumentNullException ("delegateType");
-
- CreateDynMethod ();
-
- /* Can't cache the delegate since it is different for each target */
- return Delegate.CreateDelegate (delegateType, target, this);
- }
-
- public ParameterBuilder DefineParameter (int position, ParameterAttributes attributes, string parameterName)
- {
- //
- // Extension: Mono allows position == 0 for the return attribute
- //
- if ((position < 0) || (position > parameters.Length))
- throw new ArgumentOutOfRangeException ("position");
-
- RejectIfCreated ();
-
- ParameterBuilder pb = new ParameterBuilder (this, position, attributes, parameterName);
- if (pinfo == null)
- pinfo = new ParameterBuilder [parameters.Length + 1];
- pinfo [position] = pb;
- return pb;
- }
-
- public override MethodInfo GetBaseDefinition () {
- return this;
- }
-
- public override object[] GetCustomAttributes (bool inherit) {
- // support for MethodImplAttribute PCA
- return new Object[] { new MethodImplAttribute((MethodImplOptions)GetMethodImplementationFlags()) };
- }
-
- public override object[] GetCustomAttributes (Type attributeType,
- bool inherit) {
- if (attributeType == null)
- throw new ArgumentNullException ("attributeType");
-
- if (attributeType.IsAssignableFrom (typeof (MethodImplAttribute)))
- return new Object[] { new MethodImplAttribute ((MethodImplOptions)GetMethodImplementationFlags()) };
- else
- return Array.Empty<object> ();
- }
-
- public DynamicILInfo GetDynamicILInfo () {
- if (il_info == null)
- il_info = new DynamicILInfo (this);
- return il_info;
- }
-
- public ILGenerator GetILGenerator () {
- return GetILGenerator (64);
- }
-
- public ILGenerator GetILGenerator (int streamSize) {
- if (((GetMethodImplementationFlags () & MethodImplAttributes.CodeTypeMask) !=
- MethodImplAttributes.IL) ||
- ((GetMethodImplementationFlags () & MethodImplAttributes.ManagedMask) !=
- MethodImplAttributes.Managed))
- throw new InvalidOperationException ("Method body should not exist.");
- if (ilgen != null)
- return ilgen;
- ilgen = new ILGenerator (Module, new DynamicMethodTokenGenerator (this), streamSize);
- return ilgen;
- }
-
- public override MethodImplAttributes GetMethodImplementationFlags () {
- return MethodImplAttributes.IL | MethodImplAttributes.Managed | MethodImplAttributes.NoInlining;
- }
-
- public override ParameterInfo[] GetParameters ()
- {
- return GetParametersInternal ();
- }
-
- internal override ParameterInfo[] GetParametersInternal ()
- {
- if (parameters == null)
- return Array.Empty<ParameterInfo> ();
-
- ParameterInfo[] retval = new ParameterInfo [parameters.Length];
- for (int i = 0; i < parameters.Length; i++) {
- retval [i] = RuntimeParameterInfo.New (pinfo?[i + 1], parameters [i], this, i + 1);
- }
- return retval;
- }
-
- internal override int GetParametersCount ()
- {
- return parameters == null ? 0 : parameters.Length;
- }
-
- internal override Type GetParameterType (int pos) {
- return parameters [pos];
- }
-
- /*
- public override object Invoke (object obj, object[] parameters) {
- CreateDynMethod ();
- if (method == null)
- method = new RuntimeMethodInfo (mhandle);
- return method.Invoke (obj, parameters);
- }
- */
-
- public override object Invoke (object obj, BindingFlags invokeAttr,
- Binder binder, object[] parameters,
- CultureInfo culture)
- {
- try {
- CreateDynMethod ();
- if (method == null)
- method = new RuntimeMethodInfo (mhandle);
-
- return method.Invoke (obj, invokeAttr, binder, parameters, culture);
- }
- catch (MethodAccessException mae) {
- throw new TargetInvocationException ("Method cannot be invoked.", mae);
- }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit) {
- if (attributeType == null)
- throw new ArgumentNullException ("attributeType");
-
- if (attributeType.IsAssignableFrom (typeof (MethodImplAttribute)))
- return true;
- else
- return false;
- }
-
- public override string ToString () {
- var sbName = new ValueStringBuilder (MethodNameBufferSize);
- sbName.Append (ReturnType.FormatTypeName ());
- sbName.Append (' ');
- sbName.Append (Name);
- sbName.Append ('(');
- AppendParameters (ref sbName, parameters ?? Array.Empty<Type> (), CallingConvention);
- sbName.Append (')');
- return sbName.ToString ();
- }
-
- public override MethodAttributes Attributes {
- get {
- return attributes;
- }
- }
-
- public override CallingConventions CallingConvention {
- get {
- return callingConvention;
- }
- }
-
- public override Type DeclaringType {
- get {
- return null;
- }
- }
-
- public bool InitLocals {
- get {
- return init_locals;
- }
- set {
- init_locals = value;
- }
- }
-
- public override RuntimeMethodHandle MethodHandle {
- get {
- return mhandle;
- }
- }
-
- public override Module Module {
- get {
- return module;
- }
- }
-
- public override string Name {
- get {
- return name;
- }
- }
-
- public override Type ReflectedType {
- get {
- return null;
- }
- }
-
- public override ParameterInfo ReturnParameter {
- get {
- if (deleg == null) {
- return new RuntimeParameterInfo ((ParameterBuilder) null, returnType, this, -1);
- }
- return deleg.Method.ReturnParameter;
- }
- }
-
- public override Type ReturnType {
- get {
- return returnType;
- }
- }
-
- // FIXME: "Not implemented"
- public override ICustomAttributeProvider ReturnTypeCustomAttributes {
- get {
- throw new NotImplementedException ();
- }
- }
-
-/*
- public override int MetadataToken {
- get {
- return 0;
- }
- }
-*/
-
- private void RejectIfCreated () {
- if (mhandle.Value != IntPtr.Zero)
- throw new InvalidOperationException ("Type definition of the method is complete.");
- }
-
- internal int AddRef (object reference) {
- if (refs == null)
- refs = new object [4];
- if (nrefs >= refs.Length - 1) {
- object [] new_refs = new object [refs.Length * 2];
- System.Array.Copy (refs, new_refs, refs.Length);
- refs = new_refs;
- }
- refs [nrefs] = reference;
- /* Reserved by the runtime */
- refs [nrefs + 1] = null;
- nrefs += 2;
- return nrefs - 1;
- }
-
- // This class takes care of constructing the module in a thread safe manner
- static class AnonHostModuleHolder
- {
- public static readonly Module anon_host_module;
-
- static AnonHostModuleHolder () {
- AssemblyName aname = new AssemblyName ();
- aname.Name = "Anonymously Hosted DynamicMethods Assembly";
- AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly (aname, AssemblyBuilderAccess.Run);
-
- anon_host_module = ab.ManifestModule;
- }
-
- public static Module AnonHostModule {
- get {
- return anon_host_module;
- }
- }
- }
- }
-
- internal class DynamicMethodTokenGenerator : TokenGenerator {
-
- private DynamicMethod m;
-
- public DynamicMethodTokenGenerator (DynamicMethod m) {
- this.m = m;
- }
-
- public int GetToken (string str) {
- return m.AddRef (str);
- }
-
- public int GetToken (MethodBase method, Type[] opt_param_types) {
- throw new InvalidOperationException ();
- }
-
- public int GetToken (MemberInfo member, bool create_open_instance) {
- return m.AddRef (member);
- }
-
- public int GetToken (SignatureHelper helper) {
- return m.AddRef (helper);
- }
- }
-}
-
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.notsupported.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.notsupported.cs
deleted file mode 100644
index 825790bd32b..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.notsupported.cs
+++ /dev/null
@@ -1,156 +0,0 @@
-#nullable disable
-
-//
-// DynamicMethod.cs
-//
-// Authors:
-// Marek Safar (marek.safar@gmail.com)
-//
-// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if !MONO_FEATURE_SRE
-
-using System.Globalization;
-
-namespace System.Reflection.Emit
-{
- public sealed class DynamicMethod : MethodInfo
- {
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes, bool restrictedSkipVisibility)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Module m)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Type owner)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Module m, bool skipVisibility)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public DynamicMethod (string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Module m, bool skipVisibility)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public DynamicMethod (string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public override MethodAttributes Attributes {
- get {
- throw new PlatformNotSupportedException ();
- }
- }
-
- public override CallingConventions CallingConvention {
- get {
- throw new PlatformNotSupportedException ();
- }
- }
-
- public override Type DeclaringType {
- get {
- throw new PlatformNotSupportedException ();
- }
- }
-
- public bool InitLocals { get; set; }
-
- public override MethodImplAttributes MethodImplementationFlags {
- get {
- throw new PlatformNotSupportedException ();
- }
- }
-
- public override string Name {
- get {
- throw new PlatformNotSupportedException ();
- }
- }
-
- public override ParameterInfo ReturnParameter {
- get {
- throw new PlatformNotSupportedException ();
- }
- }
-
- public override Type ReturnType {
- get {
- throw new PlatformNotSupportedException ();
- }
- }
-
- public ILGenerator GetILGenerator ()
- {
- throw new PlatformNotSupportedException ();
- }
-
- public ILGenerator GetILGenerator (int streamSize)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public override ParameterInfo[] GetParameters ()
- {
- throw new PlatformNotSupportedException ();
- }
-
- public override RuntimeMethodHandle MethodHandle { get { throw new PlatformNotSupportedException (); } }
- public override Type ReflectedType { get { throw new PlatformNotSupportedException (); } }
- public override ICustomAttributeProvider ReturnTypeCustomAttributes { get { throw new PlatformNotSupportedException (); } }
-
- public override object[] GetCustomAttributes (bool inherit) { throw new PlatformNotSupportedException (); }
- public override object[] GetCustomAttributes (Type attributeType, bool inherit) { throw new PlatformNotSupportedException (); }
- public override MethodImplAttributes GetMethodImplementationFlags () { throw new PlatformNotSupportedException (); }
- public override MethodInfo GetBaseDefinition () { throw new PlatformNotSupportedException (); }
-
- public override object Invoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { throw new PlatformNotSupportedException (); }
-
- public override bool IsDefined (Type attributeType, bool inherit) { throw new PlatformNotSupportedException (); }
-
- public ParameterBuilder DefineParameter (int position, ParameterAttributes attributes, string parameterName) => throw new PlatformNotSupportedException ();
- public DynamicILInfo GetDynamicILInfo () => throw new PlatformNotSupportedException ();
- }
-}
-
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs
deleted file mode 100644
index 961ea6ad69c..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs
+++ /dev/null
@@ -1,432 +0,0 @@
-#nullable disable
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//
-// System.Reflection.Emit/EnumBuilder.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit {
- public sealed partial class EnumBuilder : TypeInfo
- {
- private TypeBuilder _tb;
- private FieldBuilder _underlyingField;
- private Type _underlyingType;
-
- internal EnumBuilder (ModuleBuilder mb, string name, TypeAttributes visibility, Type underlyingType)
- {
- if ((visibility & ~TypeAttributes.VisibilityMask) != 0)
- throw new ArgumentException (SR.Argument_ShouldOnlySetVisibilityFlags, nameof (name));
- if ((visibility & TypeAttributes.VisibilityMask) >= TypeAttributes.NestedPublic && (visibility & TypeAttributes.VisibilityMask) <= TypeAttributes.NestedFamORAssem)
- throw new ArgumentException ();
- _tb = new TypeBuilder (mb, name, (visibility | TypeAttributes.Sealed),
- typeof(Enum), null, PackingSize.Unspecified, 0, null);
- _underlyingType = underlyingType;
- _underlyingField = _tb.DefineField ("value__", underlyingType,
- (FieldAttributes.SpecialName | FieldAttributes.Private | FieldAttributes.RTSpecialName));
- setup_enum_type (_tb);
- }
-
- internal TypeBuilder GetTypeBuilder ()
- {
- return _tb;
- }
-
- internal override Type InternalResolve ()
- {
- return _tb.InternalResolve ();
- }
-
- internal override Type RuntimeResolve () {
- return _tb.RuntimeResolve ();
- }
-
- public override Assembly Assembly {
- get {
- return _tb.Assembly;
- }
- }
-
- public override string AssemblyQualifiedName {
- get {
- return _tb.AssemblyQualifiedName;
- }
- }
-
- public override Type BaseType {
- get {
- return _tb.BaseType;
- }
- }
-
- public override Type DeclaringType {
- get {
- return _tb.DeclaringType;
- }
- }
-
- public override string FullName {
- get {
- return _tb.FullName;
- }
- }
-
- public override Guid GUID {
- get {
- return _tb.GUID;
- }
- }
-
- public override Module Module {
- get {
- return _tb.Module;
- }
- }
-
- public override string Name {
- get {
- return _tb.Name;
- }
- }
-
- public override string Namespace {
- get {
- return _tb.Namespace;
- }
- }
-
- public override Type ReflectedType {
- get {
- return _tb.ReflectedType;
- }
- }
-
- public override RuntimeTypeHandle TypeHandle {
- get {
- return _tb.TypeHandle;
- }
- }
-
- public TypeToken TypeToken {
- get {
- return _tb.TypeToken;
- }
- }
-
- public FieldBuilder UnderlyingField {
- get {
- return _underlyingField;
- }
- }
-
- public override Type UnderlyingSystemType {
- get {
- return _underlyingType;
- }
- }
-
- public Type CreateType ()
- {
- Type res = _tb.CreateType ();
- return res;
- }
-
- public TypeInfo CreateTypeInfo()
- {
- return _tb.CreateTypeInfo ();
- }
-
- public override Type GetEnumUnderlyingType ()
- {
- return _underlyingType;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private extern void setup_enum_type (Type t);
-
- public FieldBuilder DefineLiteral (string literalName, object literalValue)
- {
- Type fieldType = this;
- FieldBuilder fieldBuilder = _tb.DefineField (literalName,
- fieldType, (FieldAttributes.Literal |
- (FieldAttributes.Static | FieldAttributes.Public)));
- fieldBuilder.SetConstant (literalValue);
- return fieldBuilder;
- }
-
- protected override TypeAttributes GetAttributeFlagsImpl ()
- {
- return _tb.attrs;
- }
-
- protected override ConstructorInfo GetConstructorImpl (
- BindingFlags bindingAttr, Binder binder, CallingConventions callConvention,
- Type[] types, ParameterModifier[] modifiers)
- {
- return _tb.GetConstructor (bindingAttr, binder, callConvention, types,
- modifiers);
- }
-
- [ComVisible (true)]
- public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
- {
- return _tb.GetConstructors (bindingAttr);
- }
-
- public override object[] GetCustomAttributes(bool inherit)
- {
- return _tb.GetCustomAttributes (inherit);
- }
-
- public override object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- if (attributeType == null)
- return _tb.GetCustomAttributes (inherit);
- else
- return _tb.GetCustomAttributes (attributeType, inherit);
- }
-
- public override Type GetElementType()
- {
- return _tb.GetElementType ();
- }
-
- public override EventInfo GetEvent( string name, BindingFlags bindingAttr)
- {
- return _tb.GetEvent (name, bindingAttr);
- }
-
- public override EventInfo[] GetEvents()
- {
- return _tb.GetEvents ();
- }
-
- public override EventInfo[] GetEvents( BindingFlags bindingAttr)
- {
- return _tb.GetEvents (bindingAttr);
- }
-
- public override FieldInfo GetField( string name, BindingFlags bindingAttr)
- {
- return _tb.GetField (name, bindingAttr);
- }
-
- public override FieldInfo[] GetFields( BindingFlags bindingAttr)
- {
- return _tb.GetFields (bindingAttr);
- }
-
- public override Type GetInterface (string name, bool ignoreCase)
- {
- return _tb.GetInterface (name, ignoreCase);
- }
-
- [ComVisible (true)]
- public override InterfaceMapping GetInterfaceMap (Type interfaceType)
- {
- return _tb.GetInterfaceMap (interfaceType);
- }
-
- public override Type[] GetInterfaces()
- {
- return _tb.GetInterfaces ();
- }
-
- public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
- {
- return _tb.GetMember (name, type, bindingAttr);
- }
-
- public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
- {
- return _tb.GetMembers (bindingAttr);
- }
-
- protected override MethodInfo GetMethodImpl (
- string name, BindingFlags bindingAttr, Binder binder,
- CallingConventions callConvention, Type[] types,
- ParameterModifier[] modifiers)
- {
- if (types == null) {
- return _tb.GetMethod (name, bindingAttr);
- }
-
- return _tb.GetMethod (name, bindingAttr, binder,
- callConvention, types, modifiers);
- }
-
- public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
- {
- return _tb.GetMethods (bindingAttr);
- }
-
- public override Type GetNestedType (string name, BindingFlags bindingAttr)
- {
- return _tb.GetNestedType (name, bindingAttr);
- }
-
- public override Type[] GetNestedTypes (BindingFlags bindingAttr)
- {
- return _tb.GetNestedTypes (bindingAttr);
- }
-
- public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
- {
- return _tb.GetProperties (bindingAttr);
- }
-
- protected override PropertyInfo GetPropertyImpl (
- string name, BindingFlags bindingAttr, Binder binder,
- Type returnType, Type[] types,
- ParameterModifier[] modifiers)
- {
- throw CreateNotSupportedException ();
- }
-
- protected override bool HasElementTypeImpl ()
- {
- return _tb.HasElementType;
- }
-
- public override object InvokeMember (
- string name, BindingFlags invokeAttr, Binder binder,
- object target, object[] args,
- ParameterModifier[] modifiers, CultureInfo culture,
- string[] namedParameters)
- {
- return _tb.InvokeMember (name, invokeAttr, binder, target,
- args, modifiers, culture, namedParameters);
- }
-
- protected override bool IsArrayImpl()
- {
- return false;
- }
-
- protected override bool IsByRefImpl()
- {
- return false;
- }
-
- protected override bool IsCOMObjectImpl()
- {
- return false;
- }
-
- protected override bool IsPointerImpl()
- {
- return false;
- }
-
- protected override bool IsPrimitiveImpl()
- {
- return false;
- }
-
- protected override bool IsValueTypeImpl()
- {
- return true;
- }
-
- public override bool IsSZArray {
- get {
- return false;
- }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- return _tb.IsDefined (attributeType, inherit);
- }
-
- public override Type MakeArrayType ()
- {
- return new ArrayType (this, 0);
- }
-
- public override Type MakeArrayType (int rank)
- {
- if (rank < 1)
- throw new IndexOutOfRangeException ();
- return new ArrayType (this, rank);
- }
-
- public override Type MakeByRefType ()
- {
- return new ByRefType (this);
- }
-
- public override Type MakePointerType ()
- {
- return new PointerType (this);
- }
-
- public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
- {
- _tb.SetCustomAttribute (customBuilder);
- }
-
- [ComVisible (true)]
- public void SetCustomAttribute (ConstructorInfo con, byte[] binaryAttribute)
- {
- SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
- }
-
- private Exception CreateNotSupportedException ()
- {
- return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
- }
-
- internal override bool IsUserType {
- get {
- return false;
- }
- }
-
- public override bool IsConstructedGenericType {
- get { return false; }
- }
-
- public override bool IsAssignableFrom (TypeInfo typeInfo)
- {
- return base.IsAssignableFrom (typeInfo);
- }
-
- public override bool IsTypeDefinition => true;
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs
deleted file mode 100644
index 5957bce7ed1..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs
+++ /dev/null
@@ -1,143 +0,0 @@
-#nullable disable
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//
-// System.Reflection.Emit/EventBuilder.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit {
- [StructLayout (LayoutKind.Sequential)]
- public sealed partial class EventBuilder {
-#pragma warning disable 169, 414
- internal string name;
- Type type;
- TypeBuilder typeb;
- CustomAttributeBuilder[] cattrs;
- internal MethodBuilder add_method;
- internal MethodBuilder remove_method;
- internal MethodBuilder raise_method;
- internal MethodBuilder[] other_methods;
- internal EventAttributes attrs;
- int table_idx;
-#pragma warning restore 169, 414
-
- internal EventBuilder (TypeBuilder tb, string eventName, EventAttributes eventAttrs, Type eventType) {
- name = eventName;
- attrs = eventAttrs;
- type = eventType;
- typeb = tb;
- table_idx = get_next_table_index (this, 0x14, 1);
- }
-
- internal int get_next_table_index (object obj, int table, int count) {
- return typeb.get_next_table_index (obj, table, count);
- }
-
- public void AddOtherMethod( MethodBuilder mdBuilder) {
- if (mdBuilder == null)
- throw new ArgumentNullException ("mdBuilder");
- RejectIfCreated ();
- if (other_methods != null) {
- MethodBuilder[] newv = new MethodBuilder [other_methods.Length + 1];
- other_methods.CopyTo (newv, 0);
- other_methods = newv;
- } else {
- other_methods = new MethodBuilder [1];
- }
- other_methods [other_methods.Length - 1] = mdBuilder;
- }
-
- public EventToken GetEventToken () {
- return new EventToken (0x14000000 | table_idx);
- }
- public void SetAddOnMethod( MethodBuilder mdBuilder) {
- if (mdBuilder == null)
- throw new ArgumentNullException ("mdBuilder");
- RejectIfCreated ();
- add_method = mdBuilder;
- }
- public void SetRaiseMethod( MethodBuilder mdBuilder) {
- if (mdBuilder == null)
- throw new ArgumentNullException ("mdBuilder");
- RejectIfCreated ();
- raise_method = mdBuilder;
- }
- public void SetRemoveOnMethod( MethodBuilder mdBuilder) {
- if (mdBuilder == null)
- throw new ArgumentNullException ("mdBuilder");
- RejectIfCreated ();
- remove_method = mdBuilder;
- }
-
- public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
- if (customBuilder == null)
- throw new ArgumentNullException ("customBuilder");
- RejectIfCreated ();
- string attrname = customBuilder.Ctor.ReflectedType.FullName;
- if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
- attrs |= EventAttributes.SpecialName;
- return;
- }
- if (cattrs != null) {
- CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
- cattrs.CopyTo (new_array, 0);
- new_array [cattrs.Length] = customBuilder;
- cattrs = new_array;
- } else {
- cattrs = new CustomAttributeBuilder [1];
- cattrs [0] = customBuilder;
- }
- }
-
- [ComVisible (true)]
- public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
- if (con == null)
- throw new ArgumentNullException ("con");
- if (binaryAttribute == null)
- throw new ArgumentNullException ("binaryAttribute");
- SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
- }
-
- private void RejectIfCreated () {
- if (typeb.is_created)
- throw new InvalidOperationException ("Type definition of the method is complete.");
- }
- }
-}
-
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventOnTypeBuilderInst.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventOnTypeBuilderInst.cs
deleted file mode 100644
index a1dff8fc9db..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EventOnTypeBuilderInst.cs
+++ /dev/null
@@ -1,135 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit/EventOnTypeBuilderInst.cs
-//
-// Author:
-// Rodrigo Kumpera (rkumpera@novell.com)
-//
-//
-// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Collections;
-using System.Globalization;
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit
-{
- /*
- * This class represents an event of an instantiation of a generic type builder.
- */
- [StructLayout (LayoutKind.Sequential)]
- internal class EventOnTypeBuilderInst : EventInfo
- {
- TypeBuilderInstantiation instantiation;
- EventBuilder event_builder;
- EventInfo event_info;
-
- internal EventOnTypeBuilderInst (TypeBuilderInstantiation instantiation, EventBuilder evt)
- {
- this.instantiation = instantiation;
- this.event_builder = evt;
- }
-
- internal EventOnTypeBuilderInst (TypeBuilderInstantiation instantiation, EventInfo evt)
- {
- this.instantiation = instantiation;
- this.event_info = evt;
- }
-
- public override EventAttributes Attributes {
- get { return event_builder != null ? event_builder.attrs : event_info.Attributes; }
- }
-
- public override MethodInfo GetAddMethod (bool nonPublic)
- {
- MethodInfo add = event_builder != null ? event_builder.add_method : event_info.GetAddMethod (nonPublic);
- if (add == null || (!nonPublic && !add.IsPublic))
- return null;
- return TypeBuilder.GetMethod (instantiation, add);
- }
-
- public override MethodInfo GetRaiseMethod (bool nonPublic)
- {
- MethodInfo raise = event_builder != null ? event_builder.raise_method : event_info.GetRaiseMethod (nonPublic);
- if (raise == null || (!nonPublic && !raise.IsPublic))
- return null;
- return TypeBuilder.GetMethod (instantiation, raise);
- }
-
- public override MethodInfo GetRemoveMethod (bool nonPublic)
- {
- MethodInfo remove = event_builder != null ? event_builder.remove_method : event_info.GetRemoveMethod (nonPublic);
- if (remove == null || (!nonPublic && !remove.IsPublic))
- return null;
- return TypeBuilder.GetMethod (instantiation, remove);
- }
-
- public override MethodInfo[] GetOtherMethods (bool nonPublic)
- {
- MethodInfo[] other = event_builder != null ? event_builder.other_methods : event_info.GetOtherMethods (nonPublic);
- if (other == null)
- return new MethodInfo [0];
-
- ArrayList ar = new ArrayList ();
- foreach (MethodInfo method in other) {
- if (nonPublic || method.IsPublic)
- ar.Add (TypeBuilder.GetMethod (instantiation, method));
- }
- MethodInfo[] res = new MethodInfo [ar.Count];
- ar.CopyTo (res, 0);
- return res;
- }
-
- public override Type DeclaringType {
- get { return instantiation; }
- }
-
- public override string Name {
- get { return event_builder != null ? event_builder.name : event_info.Name; }
- }
-
- public override Type ReflectedType {
- get { return instantiation; }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- throw new NotSupportedException ();
- }
-
- public override object [] GetCustomAttributes (bool inherit)
- {
- throw new NotSupportedException ();
- }
-
- public override object [] GetCustomAttributes (Type attributeType, bool inherit)
- {
- throw new NotSupportedException ();
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs
deleted file mode 100644
index a16592e68a7..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs
+++ /dev/null
@@ -1,241 +0,0 @@
-#nullable disable
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//
-// System.Reflection.Emit/FieldBuilder.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001-2002 Ximian, Inc. http://www.ximian.com
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit {
- [StructLayout (LayoutKind.Sequential)]
- public sealed partial class FieldBuilder : FieldInfo {
-
-#pragma warning disable 169, 414
- private FieldAttributes attrs;
- private Type type;
- private String name;
- private object def_value;
- private int offset;
- internal TypeBuilder typeb;
- private byte[] rva_data;
- private CustomAttributeBuilder[] cattrs;
- private UnmanagedMarshal marshal_info;
- private RuntimeFieldHandle handle;
- private Type[] modReq;
- private Type[] modOpt;
-#pragma warning restore 169, 414
-
- internal FieldBuilder (TypeBuilder tb, string fieldName, Type type, FieldAttributes attributes, Type[] modReq, Type[] modOpt)
- {
- if (type == null)
- throw new ArgumentNullException ("type");
-
- attrs = attributes;
- name = fieldName;
- this.type = type;
- this.modReq = modReq;
- this.modOpt = modOpt;
- offset = -1;
- typeb = tb;
-
- ((ModuleBuilder) tb.Module).RegisterToken (this, GetToken ().Token);
- }
-
- public override FieldAttributes Attributes {
- get { return attrs; }
- }
-
- public override Type DeclaringType {
- get { return typeb; }
- }
-
- public override RuntimeFieldHandle FieldHandle {
- get {
- throw CreateNotSupportedException ();
- }
- }
-
- public override Type FieldType {
- get { return type; }
- }
-
- public override string Name {
- get { return name; }
- }
-
- public override Type ReflectedType {
- get { return typeb; }
- }
-
- public override object[] GetCustomAttributes(bool inherit) {
- /*
- * On MS.NET, this always returns not_supported, but we can't do this
- * since there would be no way to obtain custom attributes of
- * dynamically created ctors.
- */
- if (typeb.is_created)
- return CustomAttribute.GetCustomAttributes (this, inherit);
- else
- throw CreateNotSupportedException ();
- }
-
- public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
- if (typeb.is_created)
- return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
- else
- throw CreateNotSupportedException ();
- }
-
- public override int MetadataToken { get { return ((ModuleBuilder) typeb.Module).GetToken (this); } }
-
- public FieldToken GetToken() {
- return new FieldToken (MetadataToken, type);
- }
-
- public override object GetValue(object obj) {
- throw CreateNotSupportedException ();
- }
-
- public override bool IsDefined( Type attributeType, bool inherit) {
- throw CreateNotSupportedException ();
- }
-
- internal override int GetFieldOffset () {
- /* FIXME: */
- return 0;
- }
-
- internal void SetRVAData (byte[] data) {
- rva_data = (byte[])data.Clone ();
- }
-
- public void SetConstant( object defaultValue) {
- RejectIfCreated ();
-
- /*if (defaultValue.GetType() != type)
- throw new ArgumentException ("Constant doesn't match field type");*/
- def_value = defaultValue;
- }
-
- public void SetCustomAttribute (CustomAttributeBuilder customBuilder) {
- RejectIfCreated ();
-
- if (customBuilder == null)
- throw new ArgumentNullException ("customBuilder");
-
- string attrname = customBuilder.Ctor.ReflectedType.FullName;
- if (attrname == "System.Runtime.InteropServices.FieldOffsetAttribute") {
- byte[] data = customBuilder.Data;
- offset = (int)data [2];
- offset |= ((int)data [3]) << 8;
- offset |= ((int)data [4]) << 16;
- offset |= ((int)data [5]) << 24;
- return;
- } else if (attrname == "System.NonSerializedAttribute") {
- attrs |= FieldAttributes.NotSerialized;
- return;
- } else if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
- attrs |= FieldAttributes.SpecialName;
- return;
- } else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute") {
- attrs |= FieldAttributes.HasFieldMarshal;
- marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, true);
- /* FIXME: check for errors */
- return;
- }
- if (cattrs != null) {
- CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
- cattrs.CopyTo (new_array, 0);
- new_array [cattrs.Length] = customBuilder;
- cattrs = new_array;
- } else {
- cattrs = new CustomAttributeBuilder [1];
- cattrs [0] = customBuilder;
- }
- }
-
- [ComVisible (true)]
- public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
- RejectIfCreated ();
- SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
- }
-
- public void SetOffset( int iOffset) {
- RejectIfCreated ();
- if (iOffset < 0)
- throw new ArgumentException ("Negative field offset is not allowed");
- offset = iOffset;
- }
-
- public override void SetValue( object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture) {
- throw CreateNotSupportedException ();
- }
-
- private Exception CreateNotSupportedException ()
- {
- return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
- }
-
- private void RejectIfCreated ()
- {
- if (typeb.is_created)
- throw new InvalidOperationException ("Unable to change after type has been created.");
- }
-
- internal void ResolveUserTypes () {
- type = TypeBuilder.ResolveUserType (type);
- TypeBuilder.ResolveUserTypes (modReq);
- TypeBuilder.ResolveUserTypes (modOpt);
- if (marshal_info != null)
- marshal_info.marshaltyperef = TypeBuilder.ResolveUserType (marshal_info.marshaltyperef);
- }
-
- internal FieldInfo RuntimeResolve () {
- // typeb.CreateType() populates this.handle
- var type_handle = new RuntimeTypeHandle (typeb.CreateType () as RuntimeType);
- return FieldInfo.GetFieldFromHandle (handle, type_handle);
- }
-
- public override Module Module {
- get {
- return base.Module;
- }
- }
- }
-}
-
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldOnTypeBuilderInst.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldOnTypeBuilderInst.cs
deleted file mode 100644
index a9fc114d4cd..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldOnTypeBuilderInst.cs
+++ /dev/null
@@ -1,140 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit/FieldOnTypeBuilderInst.cs
-//
-// Author:
-// Zoltan Varga (vargaz@gmail.com)
-//
-//
-// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Globalization;
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit
-{
- /*
- * This class represents a field of an instantiation of a generic type builder.
- */
- [StructLayout (LayoutKind.Sequential)]
- internal class FieldOnTypeBuilderInst : FieldInfo
- {
- #region Keep in sync with object-internals.h
- internal TypeBuilderInstantiation instantiation;
- internal FieldInfo fb;
- #endregion
-
- public FieldOnTypeBuilderInst (TypeBuilderInstantiation instantiation, FieldInfo fb) {
- this.instantiation = instantiation;
- this.fb = fb;
- }
-
- //
- // MemberInfo members
- //
-
- public override Type DeclaringType {
- get {
- return instantiation;
- }
- }
-
- public override string Name {
- get {
- return fb.Name;
- }
- }
-
- public override Type ReflectedType {
- get {
- return instantiation;
- }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- throw new NotSupportedException ();
- }
-
- public override object [] GetCustomAttributes (bool inherit)
- {
- throw new NotSupportedException ();
- }
-
- public override object [] GetCustomAttributes (Type attributeType, bool inherit)
- {
- throw new NotSupportedException ();
- }
-
- public override string ToString ()
- {
- return fb.FieldType.ToString () + " " + Name;
- }
- //
- // FieldInfo members
- //
-
- public override FieldAttributes Attributes {
- get {
- return fb.Attributes;
- }
- }
-
- public override RuntimeFieldHandle FieldHandle {
- get {
- throw new NotSupportedException ();
- }
- }
-
- public override int MetadataToken {
- get {
- throw new InvalidOperationException ();
- }
- }
-
- public override Type FieldType {
- get {
- throw new NotSupportedException ();
- }
- }
-
- public override object GetValue(object obj) {
- throw new NotSupportedException ();
- }
-
- public override void SetValue (object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture) {
- throw new NotSupportedException ();
- }
-
- // Called from the runtime to return the corresponding finished FieldInfo object
- internal FieldInfo RuntimeResolve () {
- var type = instantiation.RuntimeResolve ();
- return type.GetField (fb);
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs
deleted file mode 100644
index 4d78390b2e1..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs
+++ /dev/null
@@ -1,476 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit.GenericTypeParameterBuilder
-//
-// Martin Baulig (martin@ximian.com)
-//
-// (C) 2004 Novell, Inc.
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Collections;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Globalization;
-using System.Runtime.Serialization;
-
-namespace System.Reflection.Emit
-{
- [ComVisible (true)]
- [StructLayout (LayoutKind.Sequential)]
- public sealed class GenericTypeParameterBuilder :
- TypeInfo
- {
- #region Sync with reflection.h
- private TypeBuilder tbuilder;
- private MethodBuilder mbuilder;
- private string name;
- private int index;
- private Type base_type;
-#pragma warning disable 414
- private Type[] iface_constraints;
- private CustomAttributeBuilder[] cattrs;
- private GenericParameterAttributes attrs;
-#pragma warning restore
- #endregion
-
- public void SetBaseTypeConstraint (Type baseTypeConstraint)
- {
- this.base_type = baseTypeConstraint ?? typeof (object);
- }
-
- [ComVisible (true)]
- public void SetInterfaceConstraints (params Type[] interfaceConstraints)
- {
- this.iface_constraints = interfaceConstraints;
- }
-
- public void SetGenericParameterAttributes (GenericParameterAttributes genericParameterAttributes)
- {
- this.attrs = genericParameterAttributes;
- }
-
- internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
- MethodBuilder mbuilder,
- string name, int index)
- {
- this.tbuilder = tbuilder;
- this.mbuilder = mbuilder;
- this.name = name;
- this.index = index;
- }
-
- internal override Type InternalResolve ()
- {
- if (mbuilder != null)
- return MethodBase.GetMethodFromHandle (mbuilder.MethodHandleInternal, mbuilder.TypeBuilder.InternalResolve ().TypeHandle).GetGenericArguments () [index];
- return tbuilder.InternalResolve ().GetGenericArguments () [index];
- }
-
- internal override Type RuntimeResolve ()
- {
- if (mbuilder != null)
- return MethodBase.GetMethodFromHandle (mbuilder.MethodHandleInternal, mbuilder.TypeBuilder.RuntimeResolve ().TypeHandle).GetGenericArguments () [index];
- return tbuilder.RuntimeResolve ().GetGenericArguments () [index];
- }
-
- [ComVisible (true)]
- public override bool IsSubclassOf (Type c)
- {
- throw not_supported ();
- }
-
- protected override TypeAttributes GetAttributeFlagsImpl ()
- {
- return TypeAttributes.Public;
- }
-
- protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
- Binder binder,
- CallingConventions callConvention,
- Type[] types,
- ParameterModifier[] modifiers)
- {
- throw not_supported ();
- }
-
- [ComVisible (true)]
- public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
- {
- throw not_supported ();
- }
-
- public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
- {
- throw not_supported ();
- }
-
- public override EventInfo[] GetEvents ()
- {
- throw not_supported ();
- }
-
- public override EventInfo[] GetEvents (BindingFlags bindingAttr)
- {
- throw not_supported ();
- }
-
- public override FieldInfo GetField (string name, BindingFlags bindingAttr)
- {
- throw not_supported ();
- }
-
- public override FieldInfo[] GetFields (BindingFlags bindingAttr)
- {
- throw not_supported ();
- }
-
- public override Type GetInterface (string name, bool ignoreCase)
- {
- throw not_supported ();
- }
-
- public override Type[] GetInterfaces ()
- {
- throw not_supported ();
- }
-
- public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
- {
- throw not_supported ();
- }
-
- public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
- {
- throw not_supported ();
- }
-
- public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
- {
- throw not_supported ();
- }
-
- protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
- Binder binder,
- CallingConventions callConvention,
- Type[] types, ParameterModifier[] modifiers)
- {
- throw not_supported ();
- }
-
- public override Type GetNestedType (string name, BindingFlags bindingAttr)
- {
- throw not_supported ();
- }
-
- public override Type[] GetNestedTypes (BindingFlags bindingAttr)
- {
- throw not_supported ();
- }
-
- public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
- {
- throw not_supported ();
- }
-
- protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
- Binder binder, Type returnType,
- Type[] types,
- ParameterModifier[] modifiers)
- {
- throw not_supported ();
- }
-
- protected override bool HasElementTypeImpl ()
- {
- return false;
- }
-
- public override bool IsAssignableFrom (Type c)
- {
- throw not_supported ();
- }
-
- public override bool IsAssignableFrom (TypeInfo typeInfo)
- {
- if (typeInfo == null)
- return false;
-
- return IsAssignableFrom (typeInfo.AsType ());
- }
-
- public override bool IsInstanceOfType (object o)
- {
- throw not_supported ();
- }
-
- protected override bool IsArrayImpl ()
- {
- return false;
- }
-
- protected override bool IsByRefImpl ()
- {
- return false;
- }
-
- protected override bool IsCOMObjectImpl ()
- {
- return false;
- }
-
- protected override bool IsPointerImpl ()
- {
- return false;
- }
-
- protected override bool IsPrimitiveImpl ()
- {
- return false;
- }
-
- protected override bool IsValueTypeImpl ()
- {
- return base_type != null ? base_type.IsValueType : false;
- }
-
- public override bool IsSZArray {
- get {
- return false;
- }
- }
-
- public override object InvokeMember (string name, BindingFlags invokeAttr,
- Binder binder, object target, object[] args,
- ParameterModifier[] modifiers,
- CultureInfo culture, string[] namedParameters)
- {
- throw not_supported ();
- }
-
- public override Type GetElementType ()
- {
- throw not_supported ();
- }
-
- public override Type UnderlyingSystemType {
- get {
- return this;
- }
- }
-
- public override Assembly Assembly {
- get { return tbuilder.Assembly; }
- }
-
- public override string AssemblyQualifiedName {
- get { return null; }
- }
-
- public override Type BaseType {
- get { return base_type; }
- }
-
- public override string FullName {
- get { return null; }
- }
-
- public override Guid GUID {
- get { throw not_supported (); }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- throw not_supported ();
- }
-
- public override object[] GetCustomAttributes (bool inherit)
- {
- throw not_supported ();
- }
-
- public override object[] GetCustomAttributes (Type attributeType, bool inherit)
- {
- throw not_supported ();
- }
-
- [ComVisible (true)]
- public override InterfaceMapping GetInterfaceMap (Type interfaceType)
- {
- throw not_supported ();
- }
-
- public override string Name {
- get { return name; }
- }
-
- public override string Namespace {
- get { return null; }
- }
-
- public override Module Module {
- get { return tbuilder.Module; }
- }
-
- public override Type DeclaringType {
- get { return mbuilder != null ? mbuilder.DeclaringType : tbuilder; }
- }
-
- public override Type ReflectedType {
- get { return DeclaringType; }
- }
-
- public override RuntimeTypeHandle TypeHandle {
- get { throw not_supported (); }
- }
-
- public override Type[] GetGenericArguments ()
- {
- throw new InvalidOperationException ();
- }
-
- public override Type GetGenericTypeDefinition ()
- {
- throw new InvalidOperationException ();
- }
-
- public override bool ContainsGenericParameters {
- get { return true; }
- }
-
- public override bool IsGenericParameter {
- get { return true; }
- }
-
- public override bool IsGenericType {
- get { return false; }
- }
-
- public override bool IsGenericTypeDefinition {
- get { return false; }
- }
-
- public override GenericParameterAttributes GenericParameterAttributes {
- get {
- return attrs;
- }
- }
-
- public override int GenericParameterPosition {
- get { return index; }
- }
-
- public override Type[] GetGenericParameterConstraints ()
- {
- throw new InvalidOperationException ();
- }
-
- public override MethodBase DeclaringMethod {
- get { return mbuilder; }
- }
-
- public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
- {
- if (customBuilder == null)
- throw new ArgumentNullException ("customBuilder");
-
- if (cattrs != null) {
- CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
- cattrs.CopyTo (new_array, 0);
- new_array [cattrs.Length] = customBuilder;
- cattrs = new_array;
- } else {
- cattrs = new CustomAttributeBuilder [1];
- cattrs [0] = customBuilder;
- }
- }
-
- // FIXME: "unverified implementation"
- public void SetCustomAttribute (ConstructorInfo con, byte [] binaryAttribute)
- {
- SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
- }
-
- private Exception not_supported ()
- {
- return new NotSupportedException ();
- }
-
- public override string ToString ()
- {
- return name;
- }
-
- // FIXME:
- public override bool Equals (object o)
- {
- return base.Equals (o);
- }
-
- // FIXME:
- public override int GetHashCode ()
- {
- return base.GetHashCode ();
- }
-
- public override Type MakeArrayType ()
- {
- return new ArrayType (this, 0);
- }
-
- public override Type MakeArrayType (int rank)
- {
- if (rank < 1)
- throw new IndexOutOfRangeException ();
- return new ArrayType (this, rank);
- }
-
- public override Type MakeByRefType ()
- {
- return new ByRefType (this);
- }
-
- public override Type MakeGenericType (params Type[] typeArguments)
- {
- throw new InvalidOperationException (Environment.GetResourceString ("Arg_NotGenericTypeDefinition"));
- }
-
- public override Type MakePointerType ()
- {
- return new PointerType (this);
- }
-
- internal override bool IsUserType {
- get {
- return false;
- }
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs
deleted file mode 100644
index 4a513c5d22c..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs
+++ /dev/null
@@ -1,1173 +0,0 @@
-#nullable disable
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//
-// System.Reflection.Emit/ILGenerator.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Collections.Generic;
-using System.Diagnostics.SymbolStore;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit {
-
- internal struct ILExceptionBlock {
- public const int CATCH = 0;
- public const int FILTER = 1;
- public const int FINALLY = 2;
- public const int FAULT = 4;
- public const int FILTER_START = -1;
-
- internal Type extype;
- internal int type;
- internal int start;
- internal int len;
- internal int filter_offset;
-
- internal void Debug () {
-#if FALSE
- System.Console.Write ("\ttype="+type.ToString()+" start="+start.ToString()+" len="+len.ToString());
- if (extype != null)
- System.Console.WriteLine (" extype="+extype.ToString());
- else
- System.Console.WriteLine (String.Empty);
-#endif
- }
- }
- internal struct ILExceptionInfo {
-#pragma warning disable 169
-#pragma warning disable 414
- internal ILExceptionBlock[] handlers;
- internal int start;
- internal int len;
- internal Label end;
-#pragma warning restore 169
-#pragma warning restore 414
-
- internal int NumHandlers ()
- {
- return handlers.Length;
- }
-
- internal void AddCatch (Type extype, int offset)
- {
- int i;
- End (offset);
- add_block (offset);
- i = handlers.Length - 1;
- handlers [i].type = ILExceptionBlock.CATCH;
- handlers [i].start = offset;
- handlers [i].extype = extype;
- }
-
- internal void AddFinally (int offset)
- {
- int i;
- End (offset);
- add_block (offset);
- i = handlers.Length - 1;
- handlers [i].type = ILExceptionBlock.FINALLY;
- handlers [i].start = offset;
- handlers [i].extype = null;
- }
-
- internal void AddFault (int offset)
- {
- int i;
- End (offset);
- add_block (offset);
- i = handlers.Length - 1;
- handlers [i].type = ILExceptionBlock.FAULT;
- handlers [i].start = offset;
- handlers [i].extype = null;
- }
-
- internal void AddFilter (int offset)
- {
- int i;
- End (offset);
- add_block (offset);
- i = handlers.Length - 1;
- handlers [i].type = ILExceptionBlock.FILTER_START;
- handlers [i].extype = null;
- handlers [i].filter_offset = offset;
- }
-
- internal void End (int offset)
- {
- if (handlers == null)
- return;
- int i = handlers.Length - 1;
- if (i >= 0)
- handlers [i].len = offset - handlers [i].start;
- }
-
- internal int LastClauseType ()
- {
- if (handlers != null)
- return handlers [handlers.Length-1].type;
- else
- return ILExceptionBlock.CATCH;
- }
-
- internal void PatchFilterClause (int start)
- {
- if (handlers != null && handlers.Length > 0) {
- handlers [handlers.Length - 1].start = start;
- handlers [handlers.Length - 1].type = ILExceptionBlock.FILTER;
- }
- }
-
- internal void Debug (int b)
- {
-#if FALSE
- System.Console.WriteLine ("Handler {0} at {1}, len: {2}", b, start, len);
- for (int i = 0; i < handlers.Length; ++i)
- handlers [i].Debug ();
-#endif
- }
-
- void add_block (int offset)
- {
- if (handlers != null) {
- int i = handlers.Length;
- ILExceptionBlock[] new_b = new ILExceptionBlock [i + 1];
- System.Array.Copy (handlers, new_b, i);
- handlers = new_b;
- handlers [i].len = offset - handlers [i].start;
- } else {
- handlers = new ILExceptionBlock [1];
- len = offset - start;
- }
- }
- }
-
- internal struct ILTokenInfo {
- public MemberInfo member;
- public int code_pos;
- }
-
- internal interface TokenGenerator {
- int GetToken (string str);
-
- int GetToken (MemberInfo member, bool create_open_instance);
-
- int GetToken (MethodBase method, Type[] opt_param_types);
-
- int GetToken (SignatureHelper helper);
- }
-
- [StructLayout (LayoutKind.Sequential)]
- public partial class ILGenerator {
- private struct LabelFixup {
- public int offset; // The number of bytes between pos and the
- // offset of the jump
- public int pos; // Where offset of the label is placed
- public int label_idx; // The label to jump to
- };
-
- struct LabelData {
- public LabelData (int addr, int maxStack)
- {
- this.addr = addr;
- this.maxStack = maxStack;
- }
-
- public int addr;
- public int maxStack;
- }
-
- #region Sync with reflection.h
- private byte[] code;
- private int code_len;
- private int max_stack;
- private int cur_stack;
- private LocalBuilder[] locals;
- private ILExceptionInfo[] ex_handlers;
- private int num_token_fixups;
- private object token_fixups;
- #endregion
-
- private LabelData [] labels;
- private int num_labels;
- private LabelFixup[] fixups;
- private int num_fixups;
- internal Module module;
- private int cur_block;
- private Stack open_blocks;
- private TokenGenerator token_gen;
-
- const int defaultFixupSize = 4;
- const int defaultLabelsSize = 4;
- const int defaultExceptionStackSize = 2;
-
- List<SequencePointList> sequencePointLists;
- SequencePointList currentSequence;
-
- internal ILGenerator (Module m, TokenGenerator token_gen, int size)
- {
- if (size < 0)
- size = 128;
- code = new byte [size];
- module = m;
- this.token_gen = token_gen;
- }
-
- private void make_room (int nbytes)
- {
- if (code_len + nbytes < code.Length)
- return;
- byte[] new_code = new byte [(code_len + nbytes) * 2 + 128];
- System.Array.Copy (code, 0, new_code, 0, code.Length);
- code = new_code;
- }
-
- private void emit_int (int val)
- {
- code [code_len++] = (byte) (val & 0xFF);
- code [code_len++] = (byte) ((val >> 8) & 0xFF);
- code [code_len++] = (byte) ((val >> 16) & 0xFF);
- code [code_len++] = (byte) ((val >> 24) & 0xFF);
- }
-
- /* change to pass by ref to avoid copy */
- private void ll_emit (OpCode opcode)
- {
- /*
- * there is already enough room allocated in code.
- */
- if (opcode.Size == 2)
- code [code_len++] = (byte)(opcode.Value >> 8);
- code [code_len++] = (byte)(opcode.Value & 0xff);
- /*
- * We should probably keep track of stack needs here.
- * Or we may want to run the verifier on the code before saving it
- * (this may be needed anyway when the ILGenerator is not used...).
- */
- switch (opcode.StackBehaviourPush) {
- case StackBehaviour.Push1:
- case StackBehaviour.Pushi:
- case StackBehaviour.Pushi8:
- case StackBehaviour.Pushr4:
- case StackBehaviour.Pushr8:
- case StackBehaviour.Pushref:
- case StackBehaviour.Varpush: /* again we are conservative and assume it pushes 1 */
- cur_stack ++;
- break;
- case StackBehaviour.Push1_push1:
- cur_stack += 2;
- break;
- }
- if (max_stack < cur_stack)
- max_stack = cur_stack;
-
- /*
- * Note that we adjust for the pop behaviour _after_ setting max_stack.
- */
- switch (opcode.StackBehaviourPop) {
- case StackBehaviour.Varpop:
- break; /* we are conservative and assume it doesn't decrease the stack needs */
- case StackBehaviour.Pop1:
- case StackBehaviour.Popi:
- case StackBehaviour.Popref:
- cur_stack --;
- break;
- case StackBehaviour.Pop1_pop1:
- case StackBehaviour.Popi_pop1:
- case StackBehaviour.Popi_popi:
- case StackBehaviour.Popi_popi8:
- case StackBehaviour.Popi_popr4:
- case StackBehaviour.Popi_popr8:
- case StackBehaviour.Popref_pop1:
- case StackBehaviour.Popref_popi:
- cur_stack -= 2;
- break;
- case StackBehaviour.Popi_popi_popi:
- case StackBehaviour.Popref_popi_popi:
- case StackBehaviour.Popref_popi_popi8:
- case StackBehaviour.Popref_popi_popr4:
- case StackBehaviour.Popref_popi_popr8:
- case StackBehaviour.Popref_popi_popref:
- cur_stack -= 3;
- break;
- }
- }
-
- private static int target_len (OpCode opcode)
- {
- if (opcode.OperandType == OperandType.InlineBrTarget)
- return 4;
- return 1;
- }
-
- private void InternalEndClause ()
- {
- switch (ex_handlers [cur_block].LastClauseType ()) {
- case ILExceptionBlock.CATCH:
- case ILExceptionBlock.FILTER:
- case ILExceptionBlock.FILTER_START:
- // how could we optimize code size here?
- Emit (OpCodes.Leave, ex_handlers [cur_block].end);
- break;
- case ILExceptionBlock.FAULT:
- case ILExceptionBlock.FINALLY:
- Emit (OpCodes.Endfinally);
- break;
- }
- }
-
- public virtual void BeginCatchBlock (Type exceptionType)
- {
- if (open_blocks == null)
- open_blocks = new Stack (defaultExceptionStackSize);
-
- if (open_blocks.Count <= 0)
- throw new NotSupportedException ("Not in an exception block");
- if (exceptionType != null && exceptionType.IsUserType)
- throw new NotSupportedException ("User defined subclasses of System.Type are not yet supported.");
- if (ex_handlers [cur_block].LastClauseType () == ILExceptionBlock.FILTER_START) {
- if (exceptionType != null)
- throw new ArgumentException ("Do not supply an exception type for filter clause");
- Emit (OpCodes.Endfilter);
- ex_handlers [cur_block].PatchFilterClause (code_len);
- } else {
- InternalEndClause ();
- ex_handlers [cur_block].AddCatch (exceptionType, code_len);
- }
-
- cur_stack = 1; // the exception object is on the stack by default
- if (max_stack < cur_stack)
- max_stack = cur_stack;
-
- //System.Console.WriteLine ("Begin catch Block: {0} {1}",exceptionType.ToString(), max_stack);
- }
-
- public virtual void BeginExceptFilterBlock ()
- {
- if (open_blocks == null)
- open_blocks = new Stack (defaultExceptionStackSize);
-
- if (open_blocks.Count <= 0)
- throw new NotSupportedException ("Not in an exception block");
- InternalEndClause ();
-
- ex_handlers [cur_block].AddFilter (code_len);
- }
-
- public virtual Label BeginExceptionBlock ()
- {
- //System.Console.WriteLine ("Begin Block");
- if (open_blocks == null)
- open_blocks = new Stack (defaultExceptionStackSize);
-
- if (ex_handlers != null) {
- cur_block = ex_handlers.Length;
- ILExceptionInfo[] new_ex = new ILExceptionInfo [cur_block + 1];
- System.Array.Copy (ex_handlers, new_ex, cur_block);
- ex_handlers = new_ex;
- } else {
- ex_handlers = new ILExceptionInfo [1];
- cur_block = 0;
- }
- open_blocks.Push (cur_block);
- ex_handlers [cur_block].start = code_len;
- return ex_handlers [cur_block].end = DefineLabel ();
- }
-
- public virtual void BeginFaultBlock()
- {
- if (open_blocks == null)
- open_blocks = new Stack (defaultExceptionStackSize);
-
- if (open_blocks.Count <= 0)
- throw new NotSupportedException ("Not in an exception block");
-
- if (ex_handlers [cur_block].LastClauseType () == ILExceptionBlock.FILTER_START) {
- Emit (OpCodes.Leave, ex_handlers [cur_block].end);
- ex_handlers [cur_block].PatchFilterClause (code_len);
- }
-
- InternalEndClause ();
- //System.Console.WriteLine ("Begin fault Block");
- ex_handlers [cur_block].AddFault (code_len);
- }
-
- public virtual void BeginFinallyBlock()
- {
- if (open_blocks == null)
- open_blocks = new Stack (defaultExceptionStackSize);
-
- if (open_blocks.Count <= 0)
- throw new NotSupportedException ("Not in an exception block");
-
- InternalEndClause ();
-
- if (ex_handlers [cur_block].LastClauseType () == ILExceptionBlock.FILTER_START) {
- Emit (OpCodes.Leave, ex_handlers [cur_block].end);
- ex_handlers [cur_block].PatchFilterClause (code_len);
- }
-
- //System.Console.WriteLine ("Begin finally Block");
- ex_handlers [cur_block].AddFinally (code_len);
- }
-
- public virtual void BeginScope ()
- { }
-
- public virtual LocalBuilder DeclareLocal (Type localType)
- {
- return DeclareLocal (localType, false);
- }
-
-
- public virtual LocalBuilder DeclareLocal (Type localType, bool pinned)
- {
- if (localType == null)
- throw new ArgumentNullException ("localType");
- if (localType.IsUserType)
- throw new NotSupportedException ("User defined subclasses of System.Type are not yet supported.");
- LocalBuilder res = new LocalBuilder (localType, this);
- res.is_pinned = pinned;
-
- if (locals != null) {
- LocalBuilder[] new_l = new LocalBuilder [locals.Length + 1];
- System.Array.Copy (locals, new_l, locals.Length);
- new_l [locals.Length] = res;
- locals = new_l;
- } else {
- locals = new LocalBuilder [1];
- locals [0] = res;
- }
- res.position = (ushort)(locals.Length - 1);
- return res;
- }
-
- public virtual Label DefineLabel ()
- {
- if (labels == null)
- labels = new LabelData [defaultLabelsSize];
- else if (num_labels >= labels.Length) {
- LabelData [] t = new LabelData [labels.Length * 2];
- Array.Copy (labels, t, labels.Length);
- labels = t;
- }
-
- labels [num_labels] = new LabelData (-1, 0);
-
- return new Label (num_labels++);
- }
-
- public virtual void Emit (OpCode opcode)
- {
- make_room (2);
- ll_emit (opcode);
- }
-
- public virtual void Emit (OpCode opcode, Byte arg)
- {
- make_room (3);
- ll_emit (opcode);
- code [code_len++] = arg;
- }
-
- [ComVisible (true)]
- public virtual void Emit (OpCode opcode, ConstructorInfo con)
- {
- int token = token_gen.GetToken (con, true);
- make_room (6);
- ll_emit (opcode);
- emit_int (token);
-
- if (opcode.StackBehaviourPop == StackBehaviour.Varpop)
- cur_stack -= con.GetParametersCount ();
- }
-
- public virtual void Emit (OpCode opcode, double arg)
- {
- byte[] s = System.BitConverter.GetBytes (arg);
- make_room (10);
- ll_emit (opcode);
- if (BitConverter.IsLittleEndian){
- System.Array.Copy (s, 0, code, code_len, 8);
- code_len += 8;
- } else {
- code [code_len++] = s [7];
- code [code_len++] = s [6];
- code [code_len++] = s [5];
- code [code_len++] = s [4];
- code [code_len++] = s [3];
- code [code_len++] = s [2];
- code [code_len++] = s [1];
- code [code_len++] = s [0];
- }
- }
-
- public virtual void Emit (OpCode opcode, FieldInfo field)
- {
- int token = token_gen.GetToken (field, true);
- make_room (6);
- ll_emit (opcode);
- emit_int (token);
- }
-
- public virtual void Emit (OpCode opcode, Int16 arg)
- {
- make_room (4);
- ll_emit (opcode);
- code [code_len++] = (byte) (arg & 0xFF);
- code [code_len++] = (byte) ((arg >> 8) & 0xFF);
- }
-
- public virtual void Emit (OpCode opcode, int arg)
- {
- make_room (6);
- ll_emit (opcode);
- emit_int (arg);
- }
-
- public virtual void Emit (OpCode opcode, long arg)
- {
- make_room (10);
- ll_emit (opcode);
- code [code_len++] = (byte) (arg & 0xFF);
- code [code_len++] = (byte) ((arg >> 8) & 0xFF);
- code [code_len++] = (byte) ((arg >> 16) & 0xFF);
- code [code_len++] = (byte) ((arg >> 24) & 0xFF);
- code [code_len++] = (byte) ((arg >> 32) & 0xFF);
- code [code_len++] = (byte) ((arg >> 40) & 0xFF);
- code [code_len++] = (byte) ((arg >> 48) & 0xFF);
- code [code_len++] = (byte) ((arg >> 56) & 0xFF);
- }
-
- public virtual void Emit (OpCode opcode, Label label)
- {
- int tlen = target_len (opcode);
- make_room (6);
- ll_emit (opcode);
- if (cur_stack > labels [label.m_label].maxStack)
- labels [label.m_label].maxStack = cur_stack;
-
- if (fixups == null)
- fixups = new LabelFixup [defaultFixupSize];
- else if (num_fixups >= fixups.Length) {
- LabelFixup[] newf = new LabelFixup [fixups.Length * 2];
- System.Array.Copy (fixups, newf, fixups.Length);
- fixups = newf;
- }
- fixups [num_fixups].offset = tlen;
- fixups [num_fixups].pos = code_len;
- fixups [num_fixups].label_idx = label.m_label;
- num_fixups++;
- code_len += tlen;
-
- }
-
- public virtual void Emit (OpCode opcode, Label[] labels)
- {
- if (labels == null)
- throw new ArgumentNullException ("labels");
-
- /* opcode needs to be switch. */
- int count = labels.Length;
- make_room (6 + count * 4);
- ll_emit (opcode);
-
- for (int i = 0; i < count; ++i)
- if (cur_stack > this.labels [labels [i].m_label].maxStack)
- this.labels [labels [i].m_label].maxStack = cur_stack;
-
- emit_int (count);
- if (fixups == null)
- fixups = new LabelFixup [defaultFixupSize + count];
- else if (num_fixups + count >= fixups.Length) {
- LabelFixup[] newf = new LabelFixup [count + fixups.Length * 2];
- System.Array.Copy (fixups, newf, fixups.Length);
- fixups = newf;
- }
-
- // ECMA 335, Partition III, p94 (7-10)
- //
- // The switch instruction implements a jump table. The format of
- // the instruction is an unsigned int32 representing the number of targets N,
- // followed by N int32 values specifying jump targets: these targets are
- // represented as offsets (positive or negative) from the beginning of the
- // instruction following this switch instruction.
- //
- // We must make sure it gets an offset from the *end* of the last label
- // (eg, the beginning of the instruction following this).
- //
- // remaining is the number of bytes from the current instruction to the
- // instruction that will be emitted.
-
- for (int i = 0, remaining = count * 4; i < count; ++i, remaining -= 4) {
- fixups [num_fixups].offset = remaining;
- fixups [num_fixups].pos = code_len;
- fixups [num_fixups].label_idx = labels [i].m_label;
- num_fixups++;
- code_len += 4;
- }
- }
-
- public virtual void Emit (OpCode opcode, LocalBuilder local)
- {
- if (local == null)
- throw new ArgumentNullException ("local");
- if (local.ilgen != this)
- throw new ArgumentException ("Trying to emit a local from a different ILGenerator.");
-
- uint pos = local.position;
- bool load_addr = false;
- bool is_store = false;
- bool is_load = false;
- make_room (6);
-
- /* inline the code from ll_emit () to optimize il code size */
- if (opcode.StackBehaviourPop == StackBehaviour.Pop1) {
- cur_stack --;
- is_store = true;
- } else if (opcode.StackBehaviourPush == StackBehaviour.Push1 || opcode.StackBehaviourPush == StackBehaviour.Pushi) {
- cur_stack++;
- is_load = true;
- if (cur_stack > max_stack)
- max_stack = cur_stack;
- load_addr = opcode.StackBehaviourPush == StackBehaviour.Pushi;
- }
- if (load_addr) {
- if (pos < 256) {
- code [code_len++] = (byte)0x12;
- code [code_len++] = (byte)pos;
- } else {
- code [code_len++] = (byte)0xfe;
- code [code_len++] = (byte)0x0d;
- code [code_len++] = (byte)(pos & 0xff);
- code [code_len++] = (byte)((pos >> 8) & 0xff);
- }
- } else {
- if (is_store) {
- if (pos < 4) {
- code [code_len++] = (byte)(0x0a + pos);
- } else if (pos < 256) {
- code [code_len++] = (byte)0x13;
- code [code_len++] = (byte)pos;
- } else {
- code [code_len++] = (byte)0xfe;
- code [code_len++] = (byte)0x0e;
- code [code_len++] = (byte)(pos & 0xff);
- code [code_len++] = (byte)((pos >> 8) & 0xff);
- }
- } else if (is_load) {
- if (pos < 4) {
- code [code_len++] = (byte)(0x06 + pos);
- } else if (pos < 256) {
- code [code_len++] = (byte)0x11;
- code [code_len++] = (byte)pos;
- } else {
- code [code_len++] = (byte)0xfe;
- code [code_len++] = (byte)0x0c;
- code [code_len++] = (byte)(pos & 0xff);
- code [code_len++] = (byte)((pos >> 8) & 0xff);
- }
- } else {
- ll_emit (opcode);
- }
- }
- }
-
- public virtual void Emit (OpCode opcode, MethodInfo meth)
- {
- if (meth == null)
- throw new ArgumentNullException ("meth");
-
- // For compatibility with MS
- if ((meth is DynamicMethod) && ((opcode == OpCodes.Ldftn) || (opcode == OpCodes.Ldvirtftn) || (opcode == OpCodes.Ldtoken)))
- throw new ArgumentException ("Ldtoken, Ldftn and Ldvirtftn OpCodes cannot target DynamicMethods.");
-
- int token = token_gen.GetToken (meth, true);
- make_room (6);
- ll_emit (opcode);
- Type declaringType = meth.DeclaringType;
- emit_int (token);
- if (meth.ReturnType != typeof (void))
- cur_stack ++;
-
- if (opcode.StackBehaviourPop == StackBehaviour.Varpop)
- cur_stack -= meth.GetParametersCount ();
- }
-
- private void Emit (OpCode opcode, MethodInfo method, int token)
- {
- make_room (6);
- ll_emit (opcode);
- emit_int (token);
- if (method.ReturnType != typeof (void))
- cur_stack ++;
-
- if (opcode.StackBehaviourPop == StackBehaviour.Varpop)
- cur_stack -= method.GetParametersCount ();
- }
-
- [CLSCompliant(false)]
- public void Emit (OpCode opcode, sbyte arg)
- {
- make_room (3);
- ll_emit (opcode);
- code [code_len++] = (byte)arg;
- }
-
- public virtual void Emit (OpCode opcode, SignatureHelper signature)
- {
- int token = token_gen.GetToken (signature);
- make_room (6);
- ll_emit (opcode);
- emit_int (token);
- }
-
- public virtual void Emit (OpCode opcode, float arg)
- {
- byte[] s = System.BitConverter.GetBytes (arg);
- make_room (6);
- ll_emit (opcode);
- if (BitConverter.IsLittleEndian){
- System.Array.Copy (s, 0, code, code_len, 4);
- code_len += 4;
- } else {
- code [code_len++] = s [3];
- code [code_len++] = s [2];
- code [code_len++] = s [1];
- code [code_len++] = s [0];
- }
- }
-
- public virtual void Emit (OpCode opcode, string str)
- {
- int token = token_gen.GetToken (str);
- make_room (6);
- ll_emit (opcode);
- emit_int (token);
- }
-
- public virtual void Emit (OpCode opcode, Type cls)
- {
- if (cls != null && cls.IsByRef)
- throw new ArgumentException ("Cannot get TypeToken for a ByRef type.");
-
- make_room (6);
- ll_emit (opcode);
- int token = token_gen.GetToken (cls, opcode != OpCodes.Ldtoken);
- emit_int (token);
- }
-
- // FIXME: vararg methods are not supported
- public virtual void EmitCall (OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes)
- {
- if (methodInfo == null)
- throw new ArgumentNullException ("methodInfo");
- short value = opcode.Value;
- if (!(value == OpCodes.Call.Value || value == OpCodes.Callvirt.Value))
- throw new NotSupportedException ("Only Call and CallVirt are allowed");
- if ((methodInfo.CallingConvention & CallingConventions.VarArgs) == 0)
- optionalParameterTypes = null;
- if (optionalParameterTypes != null){
- if ((methodInfo.CallingConvention & CallingConventions.VarArgs) == 0){
- throw new InvalidOperationException ("Method is not VarArgs method and optional types were passed");
- }
-
- int token = token_gen.GetToken (methodInfo, optionalParameterTypes);
- Emit (opcode, methodInfo, token);
- return;
- }
- Emit (opcode, methodInfo);
- }
-
- public virtual void EmitCalli (OpCode opcode, CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes)
- {
- // GetMethodSigHelper expects a ModuleBuilder or null, and module might be
- // a normal module when using dynamic methods.
- SignatureHelper helper = SignatureHelper.GetMethodSigHelper (module as ModuleBuilder, 0, unmanagedCallConv, returnType, parameterTypes);
- Emit (opcode, helper);
- }
-
- public virtual void EmitCalli (OpCode opcode, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes)
- {
- if (optionalParameterTypes != null)
- throw new NotImplementedException ();
-
- SignatureHelper helper = SignatureHelper.GetMethodSigHelper (module as ModuleBuilder, callingConvention, 0, returnType, parameterTypes);
- Emit (opcode, helper);
- }
-
- static Type GetConsoleType ()
- {
- return Type.GetType ("System.Console, System.Console", throwOnError: true);
- }
-
- public virtual void EmitWriteLine (FieldInfo fld)
- {
- if (fld == null)
- throw new ArgumentNullException ("fld");
-
- // The MS implementation does not check for valuetypes here but it
- // should. Also, it should check that if the field is not static,
- // then it is a member of this type.
- if (fld.IsStatic)
- Emit (OpCodes.Ldsfld, fld);
- else {
- Emit (OpCodes.Ldarg_0);
- Emit (OpCodes.Ldfld, fld);
- }
- Emit (OpCodes.Call, GetConsoleType ().GetMethod ("WriteLine", new Type[1] { fld.FieldType }));
- }
-
- public virtual void EmitWriteLine (LocalBuilder localBuilder)
- {
- if (localBuilder == null)
- throw new ArgumentNullException ("localBuilder");
- if (localBuilder.LocalType is TypeBuilder)
- throw new ArgumentException ("Output streams do not support TypeBuilders.");
- // The MS implementation does not check for valuetypes here but it
- // should.
- Emit (OpCodes.Ldloc, localBuilder);
- Emit (OpCodes.Call, GetConsoleType ().GetMethod ("WriteLine", new Type[1] { localBuilder.LocalType }));
- }
-
- public virtual void EmitWriteLine (string value)
- {
- Emit (OpCodes.Ldstr, value);
- Emit (OpCodes.Call, GetConsoleType ().GetMethod ("WriteLine", new Type[1] { typeof(string)}));
- }
-
- public virtual void EndExceptionBlock ()
- {
- if (open_blocks == null)
- open_blocks = new Stack (defaultExceptionStackSize);
-
- if (open_blocks.Count <= 0)
- throw new NotSupportedException ("Not in an exception block");
-
- if (ex_handlers [cur_block].LastClauseType () == ILExceptionBlock.FILTER_START)
- throw new InvalidOperationException ("Incorrect code generation for exception block.");
-
- InternalEndClause ();
- MarkLabel (ex_handlers [cur_block].end);
- ex_handlers [cur_block].End (code_len);
- ex_handlers [cur_block].Debug (cur_block);
- //System.Console.WriteLine ("End Block {0} (handlers: {1})", cur_block, ex_handlers [cur_block].NumHandlers ());
- open_blocks.Pop ();
- if (open_blocks.Count > 0)
- cur_block = (int)open_blocks.Peek ();
- //Console.WriteLine ("curblock restored to {0}", cur_block);
- //throw new NotImplementedException ();
- }
-
- public virtual void EndScope ()
- { }
-
- public virtual void MarkLabel (Label loc)
- {
- if (loc.m_label < 0 || loc.m_label >= num_labels)
- throw new System.ArgumentException ("The label is not valid");
- if (labels [loc.m_label].addr >= 0)
- throw new System.ArgumentException ("The label was already defined");
- labels [loc.m_label].addr = code_len;
- if (labels [loc.m_label].maxStack > cur_stack)
- cur_stack = labels [loc.m_label].maxStack;
- }
-
- public virtual void MarkSequencePoint (ISymbolDocumentWriter document, int startLine,
- int startColumn, int endLine, int endColumn)
- {
- if (currentSequence == null || currentSequence.Document != document) {
- if (sequencePointLists == null)
- sequencePointLists = new List<SequencePointList> ();
- currentSequence = new SequencePointList (document);
- sequencePointLists.Add (currentSequence);
- }
-
- currentSequence.AddSequencePoint (code_len, startLine, startColumn, endLine, endColumn);
- }
-
-/*
- internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
- {
- if (sequencePointLists != null) {
- SequencePointList first = (SequencePointList) sequencePointLists [0];
- SequencePointList last = (SequencePointList) sequencePointLists [sequencePointLists.Count - 1];
- symbolWriter.SetMethodSourceRange (first.Document, first.StartLine, first.StartColumn, last.Document, last.EndLine, last.EndColumn);
-
- foreach (SequencePointList list in sequencePointLists)
- symbolWriter.DefineSequencePoints (list.Document, list.GetOffsets(), list.GetLines(), list.GetColumns(), list.GetEndLines(), list.GetEndColumns());
-
- if (locals != null) {
- foreach (LocalBuilder local in locals) {
- if (local.Name != null && local.Name.Length > 0) {
- SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (module as ModuleBuilder);
- sighelper.AddArgument (local.LocalType);
- byte[] signature = sighelper.GetSignature ();
- symbolWriter.DefineLocalVariable (local.Name, FieldAttributes.Public, signature, SymAddressKind.ILOffset, local.position, 0, 0, local.StartOffset, local.EndOffset);
- }
- }
- }
- sequencePointLists = null;
- }
- }
-*/
-
- internal bool HasDebugInfo
- {
- get { return sequencePointLists != null; }
- }
-
- public virtual void ThrowException (Type excType)
- {
- if (excType == null)
- throw new ArgumentNullException ("excType");
- if (! ((excType == typeof (Exception)) ||
- excType.IsSubclassOf (typeof (Exception))))
- throw new ArgumentException ("Type should be an exception type", "excType");
- ConstructorInfo ctor = excType.GetConstructor (Type.EmptyTypes);
- if (ctor == null)
- throw new ArgumentException ("Type should have a default constructor", "excType");
- Emit (OpCodes.Newobj, ctor);
- Emit (OpCodes.Throw);
- }
-
- // FIXME: "Not implemented"
- public virtual void UsingNamespace (String usingNamespace)
- {
- throw new NotImplementedException ();
- }
-
- internal void label_fixup (MethodBase mb)
- {
- for (int i = 0; i < num_fixups; ++i) {
- if (labels [fixups [i].label_idx].addr < 0)
- throw new ArgumentException (string.Format ("Label #{0} is not marked in method `{1}'", fixups [i].label_idx + 1, mb.Name));
- // Diff is the offset from the end of the jump instruction to the address of the label
- int diff = labels [fixups [i].label_idx].addr - (fixups [i].pos + fixups [i].offset);
- if (fixups [i].offset == 1) {
- code [fixups [i].pos] = (byte)((sbyte) diff);
- } else {
- int old_cl = code_len;
- code_len = fixups [i].pos;
- emit_int (diff);
- code_len = old_cl;
- }
- }
- }
-
- // Used by DynamicILGenerator and MethodBuilder.SetMethodBody
- internal void SetCode (byte[] code, int max_stack) {
- // Make a copy to avoid possible security problems
- this.code = (byte[])code.Clone ();
- this.code_len = code.Length;
- this.max_stack = max_stack;
- this.cur_stack = 0;
- }
-
- internal unsafe void SetCode (byte *code, int code_size, int max_stack) {
- // Make a copy to avoid possible security problems
- this.code = new byte [code_size];
- for (int i = 0; i < code_size; ++i)
- this.code [i] = code [i];
- this.code_len = code_size;
- this.max_stack = max_stack;
- this.cur_stack = 0;
- }
-
- internal TokenGenerator TokenGenerator {
- get {
- return token_gen;
- }
- }
-
- public virtual int ILOffset {
- get { return code_len; }
- }
- }
-
- internal class SequencePointList
- {
- ISymbolDocumentWriter doc;
- SequencePoint[] points;
- int count;
- const int arrayGrow = 10;
-
- public SequencePointList (ISymbolDocumentWriter doc)
- {
- this.doc = doc;
- }
-
- public ISymbolDocumentWriter Document {
- get { return doc; }
- }
-
- public int[] GetOffsets()
- {
- int[] data = new int [count];
- for (int n=0; n<count; n++) data [n] = points[n].Offset;
- return data;
- }
- public int[] GetLines()
- {
- int[] data = new int [count];
- for (int n=0; n<count; n++) data [n] = points[n].Line;
- return data;
- }
- public int[] GetColumns()
- {
- int[] data = new int [count];
- for (int n=0; n<count; n++) data [n] = points[n].Col;
- return data;
- }
- public int[] GetEndLines()
- {
- int[] data = new int [count];
- for (int n=0; n<count; n++) data [n] = points[n].EndLine;
- return data;
- }
- public int[] GetEndColumns()
- {
- int[] data = new int [count];
- for (int n=0; n<count; n++) data [n] = points[n].EndCol;
- return data;
- }
- public int StartLine {
- get { return points[0].Line; }
- }
- public int EndLine {
- get { return points[count - 1].Line; }
- }
- public int StartColumn {
- get { return points[0].Col; }
- }
- public int EndColumn {
- get { return points[count - 1].Col; }
- }
-
- public void AddSequencePoint (int offset, int line, int col, int endLine, int endCol)
- {
- SequencePoint s = new SequencePoint ();
- s.Offset = offset;
- s.Line = line;
- s.Col = col;
- s.EndLine = endLine;
- s.EndCol = endCol;
-
- if (points == null) {
- points = new SequencePoint [arrayGrow];
- } else if (count >= points.Length) {
- SequencePoint[] temp = new SequencePoint [count + arrayGrow];
- Array.Copy (points, temp, points.Length);
- points = temp;
- }
-
- points [count] = s;
- count++;
- }
- }
-
- struct SequencePoint {
- public int Offset;
- public int Line;
- public int Col;
- public int EndLine;
- public int EndCol;
- }
-
- class Stack
- {
- Object[] _array;
- int _size;
- int _version;
-
- private const int _defaultCapacity = 10;
-
- public Stack()
- {
- _array = new Object[_defaultCapacity];
- _size = 0;
- _version = 0;
- }
-
- public Stack(int initialCapacity)
- {
- if (initialCapacity < 0)
- throw new ArgumentOutOfRangeException(nameof(initialCapacity), SR.ArgumentOutOfRange_NeedNonNegNum);
-
- if (initialCapacity < _defaultCapacity)
- initialCapacity = _defaultCapacity;
- _array = new Object[initialCapacity];
- _size = 0;
- _version = 0;
- }
-
- public virtual int Count
- {
- get
- {
- return _size;
- }
- }
-
- public virtual Object Peek()
- {
- if (_size == 0)
- throw new InvalidOperationException ();
-
- return _array[_size - 1];
- }
-
- public virtual Object Pop()
- {
- if (_size == 0)
- throw new InvalidOperationException ();
-
- _version++;
- Object obj = _array[--_size];
- _array[_size] = null;
- return obj;
- }
-
- public virtual void Push(Object obj)
- {
- if (_size == _array.Length)
- {
- Object[] newArray = new Object[2 * _array.Length];
- Array.Copy(_array, 0, newArray, 0, _size);
- _array = newArray;
- }
- _array[_size++] = obj;
- _version++;
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/LocalBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/LocalBuilder.Mono.cs
deleted file mode 100644
index 583600a2575..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/LocalBuilder.Mono.cs
+++ /dev/null
@@ -1,111 +0,0 @@
-#nullable disable
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//
-// System.Reflection.Emit/LocalBuilder.cs
-//
-// Authors:
-// Paolo Molaro (lupus@ximian.com)
-// Martin Baulig (martin@gnome.org)
-// Miguel de Icaza (miguel@ximian.com)
-//
-// (C) 2001, 2002 Ximian, Inc. http://www.ximian.com
-//
-
-using System;
-using System.Reflection;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Diagnostics.SymbolStore;
-
-namespace System.Reflection.Emit {
- [StructLayout (LayoutKind.Sequential)]
- public sealed partial class LocalBuilder : LocalVariableInfo
- {
- // Needs to have the same layout as RuntimeLocalVariableInfo
- #region Sync with reflection.h
- internal Type type;
- internal bool is_pinned;
- internal ushort position;
- private string name;
- #endregion
-
- internal ILGenerator ilgen;
- int startOffset;
- int endOffset;
-
- internal LocalBuilder (Type t, ILGenerator ilgen)
- {
- this.type = t;
- this.ilgen = ilgen;
- }
-
- public void SetLocalSymInfo (string name, int startOffset, int endOffset)
- {
- this.name = name;
- this.startOffset = startOffset;
- this.endOffset = endOffset;
- }
-
- public void SetLocalSymInfo (string name)
- {
- SetLocalSymInfo (name, 0, 0);
- }
-
- public override Type LocalType
- {
- get {
- return type;
- }
- }
-
- public override bool IsPinned
- {
- get {
- return is_pinned;
- }
- }
-
- public override int LocalIndex
- {
- get {
- return position;
- }
- }
-
- internal string Name {
- get { return name; }
- }
-
- internal int StartOffset {
- get { return startOffset; }
- }
-
- internal int EndOffset {
- get { return endOffset; }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs
deleted file mode 100644
index 8d2caaf23dc..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs
+++ /dev/null
@@ -1,743 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit/MethodBuilder.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Diagnostics.SymbolStore;
-using System.Collections.Generic;
-
-namespace System.Reflection.Emit
-{
- [StructLayout (LayoutKind.Sequential)]
- public sealed partial class MethodBuilder : MethodInfo
- {
-#pragma warning disable 169, 414
- private RuntimeMethodHandle mhandle;
- private Type rtype;
- internal Type[] parameters;
- private MethodAttributes attrs; /* It's used directly by MCS */
- private MethodImplAttributes iattrs;
- private string name;
- private int table_idx;
- private byte[] code;
- private ILGenerator ilgen;
- private TypeBuilder type;
- internal ParameterBuilder[] pinfo;
- private CustomAttributeBuilder[] cattrs;
- private MethodInfo[] override_methods;
- private string pi_dll;
- private string pi_entry;
- private CharSet charset;
- private uint extra_flags; /* this encodes set_last_error etc */
- private CallingConvention native_cc;
- private CallingConventions call_conv;
- private bool init_locals = true;
- private IntPtr generic_container;
- internal GenericTypeParameterBuilder[] generic_params;
- private Type[] returnModReq;
- private Type[] returnModOpt;
- private Type[][] paramModReq;
- private Type[][] paramModOpt;
- private object permissions;
-#pragma warning restore 169, 414
- RuntimeMethodInfo created;
-
- internal MethodBuilder (TypeBuilder tb, string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnModReq, Type[] returnModOpt, Type[] parameterTypes, Type[][] paramModReq, Type[][] paramModOpt)
- {
- this.name = name;
- this.attrs = attributes;
- this.call_conv = callingConvention;
- this.rtype = returnType;
- this.returnModReq = returnModReq;
- this.returnModOpt = returnModOpt;
- this.paramModReq = paramModReq;
- this.paramModOpt = paramModOpt;
- // The MSDN docs does not specify this, but the MS MethodBuilder
- // appends a HasThis flag if the method is not static
- if ((attributes & MethodAttributes.Static) == 0)
- this.call_conv |= CallingConventions.HasThis;
- if (parameterTypes != null) {
- for (int i = 0; i < parameterTypes.Length; ++i)
- if (parameterTypes [i] == null)
- throw new ArgumentException ("Elements of the parameterTypes array cannot be null", "parameterTypes");
-
- this.parameters = new Type [parameterTypes.Length];
- System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
- }
- type = tb;
- table_idx = get_next_table_index (this, 0x06, 1);
-
- ((ModuleBuilder)tb.Module).RegisterToken (this, GetToken ().Token);
- }
-
- internal MethodBuilder (TypeBuilder tb, string name, MethodAttributes attributes,
- CallingConventions callingConvention, Type returnType, Type[] returnModReq, Type[] returnModOpt, Type[] parameterTypes, Type[][] paramModReq, Type[][] paramModOpt,
- String dllName, String entryName, CallingConvention nativeCConv, CharSet nativeCharset)
- : this (tb, name, attributes, callingConvention, returnType, returnModReq, returnModOpt, parameterTypes, paramModReq, paramModOpt)
- {
- pi_dll = dllName;
- pi_entry = entryName;
- native_cc = nativeCConv;
- charset = nativeCharset;
- }
-
- public override bool ContainsGenericParameters {
- get { throw new NotSupportedException (); }
- }
-
- public bool InitLocals {
- get {return init_locals;}
- set {init_locals = value;}
- }
-
- internal TypeBuilder TypeBuilder {
- get {return type;}
- }
-
- public override RuntimeMethodHandle MethodHandle {
- get {
- throw NotSupported ();
- }
- }
-
- internal RuntimeMethodHandle MethodHandleInternal {
- get {
- return mhandle;
- }
- }
-
- public override Type ReturnType {
- get { return rtype; }
- }
-
- public override Type ReflectedType {
- get { return type; }
- }
-
- public override Type DeclaringType {
- get { return type; }
- }
-
- public override string Name {
- get { return name; }
- }
-
- public override MethodAttributes Attributes {
- get { return attrs; }
- }
-
- public override ICustomAttributeProvider ReturnTypeCustomAttributes {
- get { return null; }
- }
-
- public override CallingConventions CallingConvention {
- get { return call_conv; }
- }
-
- // FIXME: "Not implemented"
- public string Signature {
- get {
- throw new NotImplementedException ();
- }
- }
-
- /* Used by mcs */
- internal bool BestFitMapping {
- set {
- extra_flags = (uint) ((extra_flags & ~0x30) | (uint)(value ? 0x10 : 0x20));
- }
- }
-
- /* Used by mcs */
- internal bool ThrowOnUnmappableChar {
- set {
- extra_flags = (uint) ((extra_flags & ~0x3000) | (uint)(value ? 0x1000 : 0x2000));
- }
- }
-
- /* Used by mcs */
- internal bool ExactSpelling {
- set {
- extra_flags = (uint) ((extra_flags & ~0x01) | (uint)(value ? 0x01 : 0x00));
- }
- }
-
- /* Used by mcs */
- internal bool SetLastError {
- set {
- extra_flags = (uint) ((extra_flags & ~0x40) | (uint)(value ? 0x40 : 0x00));
- }
- }
-
- public MethodToken GetToken()
- {
- return new MethodToken(0x06000000 | table_idx);
- }
-
- public override MethodInfo GetBaseDefinition()
- {
- return this;
- }
-
- public override MethodImplAttributes GetMethodImplementationFlags()
- {
- return iattrs;
- }
-
- public override ParameterInfo[] GetParameters()
- {
- if (!type.is_created)
- throw NotSupported ();
-
- return GetParametersInternal ();
- }
-
- internal override ParameterInfo[] GetParametersInternal ()
- {
- if (parameters == null)
- return null;
-
- ParameterInfo[] retval = new ParameterInfo [parameters.Length];
- for (int i = 0; i < parameters.Length; i++) {
- retval [i] = RuntimeParameterInfo.New (pinfo?[i + 1], parameters [i], this, i + 1);
- }
- return retval;
- }
-
- internal override int GetParametersCount ()
- {
- if (parameters == null)
- return 0;
-
- return parameters.Length;
- }
-
- internal override Type GetParameterType (int pos) {
- return parameters [pos];
- }
-
- internal MethodBase RuntimeResolve () {
- return type.RuntimeResolve ().GetMethod (this);
- }
-
- public Module GetModule ()
- {
- return type.Module;
- }
-
- public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
- {
- throw NotSupported ();
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- throw NotSupported ();
- }
-
- public override object[] GetCustomAttributes (bool inherit)
- {
- /*
- * On MS.NET, this always returns not_supported, but we can't do this
- * since there would be no way to obtain custom attributes of
- * dynamically created ctors.
- */
- if (type.is_created)
- return CustomAttribute.GetCustomAttributes (this, inherit);
- else
- throw NotSupported ();
- }
-
- public override object[] GetCustomAttributes (Type attributeType, bool inherit)
- {
- if (type.is_created)
- return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
- else
- throw NotSupported ();
- }
-
- public ILGenerator GetILGenerator ()
- {
- return GetILGenerator (64);
- }
-
- public ILGenerator GetILGenerator (int size)
- {
- if (((iattrs & MethodImplAttributes.CodeTypeMask) !=
- MethodImplAttributes.IL) ||
- ((iattrs & MethodImplAttributes.ManagedMask) !=
- MethodImplAttributes.Managed))
- throw new InvalidOperationException ("Method body should not exist.");
- if (ilgen != null)
- return ilgen;
- ilgen = new ILGenerator (type.Module, ((ModuleBuilder)type.Module).GetTokenGenerator (), size);
- return ilgen;
- }
-
- public ParameterBuilder DefineParameter (int position, ParameterAttributes attributes, string strParamName)
- {
- RejectIfCreated ();
-
- //
- // Extension: Mono allows position == 0 for the return attribute
- //
- if ((position < 0) || parameters == null || (position > parameters.Length))
- throw new ArgumentOutOfRangeException ("position");
-
- ParameterBuilder pb = new ParameterBuilder (this, position, attributes, strParamName);
- if (pinfo == null)
- pinfo = new ParameterBuilder [parameters.Length + 1];
- pinfo [position] = pb;
- return pb;
- }
-
- internal void check_override ()
- {
- if (override_methods != null) {
- foreach (var m in override_methods) {
- if (m.IsVirtual && !IsVirtual)
- throw new TypeLoadException (String.Format("Method '{0}' override '{1}' but it is not virtual", name, m));
- }
- }
- }
-
- internal void fixup ()
- {
- if (((attrs & (MethodAttributes.Abstract | MethodAttributes.PinvokeImpl)) == 0) && ((iattrs & (MethodImplAttributes.Runtime | MethodImplAttributes.InternalCall)) == 0)) {
- // do not allow zero length method body on MS.NET 2.0 (and higher)
- if (((ilgen == null) || (ilgen.ILOffset == 0)) && (code == null || code.Length == 0))
- throw new InvalidOperationException (
- String.Format ("Method '{0}.{1}' does not have a method body.",
- DeclaringType.FullName, Name));
- }
- if (ilgen != null)
- ilgen.label_fixup (this);
- }
-
- internal void ResolveUserTypes () {
- rtype = TypeBuilder.ResolveUserType (rtype);
- TypeBuilder.ResolveUserTypes (parameters);
- TypeBuilder.ResolveUserTypes (returnModReq);
- TypeBuilder.ResolveUserTypes (returnModOpt);
- if (paramModReq != null) {
- foreach (var types in paramModReq)
- TypeBuilder.ResolveUserTypes (types);
- }
- if (paramModOpt != null) {
- foreach (var types in paramModOpt)
- TypeBuilder.ResolveUserTypes (types);
- }
- }
-/*
- internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
- {
- if (ilgen != null && ilgen.HasDebugInfo) {
- SymbolToken token = new SymbolToken (GetToken().Token);
- symbolWriter.OpenMethod (token);
- symbolWriter.SetSymAttribute (token, "__name", System.Text.Encoding.UTF8.GetBytes (Name));
- ilgen.GenerateDebugInfo (symbolWriter);
- symbolWriter.CloseMethod ();
- }
- }
-*/
- public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
- {
- if (customBuilder == null)
- throw new ArgumentNullException ("customBuilder");
-
- switch (customBuilder.Ctor.ReflectedType.FullName) {
- case "System.Runtime.CompilerServices.MethodImplAttribute":
- byte[] data = customBuilder.Data;
- int impla; // the (stupid) ctor takes a short or an int ...
- impla = (int)data [2];
- impla |= ((int)data [3]) << 8;
- iattrs |= (MethodImplAttributes)impla;
- return;
-
- case "System.Runtime.InteropServices.DllImportAttribute":
- CustomAttributeBuilder.CustomAttributeInfo attr = CustomAttributeBuilder.decode_cattr (customBuilder);
- bool preserveSig = true;
-
- /*
- * It would be easier to construct a DllImportAttribute from
- * the custom attribute builder, but the DllImportAttribute
- * does not contain all the information required here, ie.
- * - some parameters, like BestFitMapping has three values
- * ("on", "off", "missing"), but DllImportAttribute only
- * contains two (on/off).
- * - PreserveSig is true by default, while it is false by
- * default in DllImportAttribute.
- */
-
- pi_dll = (string)attr.ctorArgs[0];
- if (pi_dll == null || pi_dll.Length == 0)
- throw new ArgumentException ("DllName cannot be empty");
-
- native_cc = System.Runtime.InteropServices.CallingConvention.Winapi;
-
- for (int i = 0; i < attr.namedParamNames.Length; ++i) {
- string name = attr.namedParamNames [i];
- object value = attr.namedParamValues [i];
-
- if (name == "CallingConvention")
- native_cc = (CallingConvention)value;
- else if (name == "CharSet")
- charset = (CharSet)value;
- else if (name == "EntryPoint")
- pi_entry = (string)value;
- else if (name == "ExactSpelling")
- ExactSpelling = (bool)value;
- else if (name == "SetLastError")
- SetLastError = (bool)value;
- else if (name == "PreserveSig")
- preserveSig = (bool)value;
- else if (name == "BestFitMapping")
- BestFitMapping = (bool)value;
- else if (name == "ThrowOnUnmappableChar")
- ThrowOnUnmappableChar = (bool)value;
- }
-
- attrs |= MethodAttributes.PinvokeImpl;
- if (preserveSig)
- iattrs |= MethodImplAttributes.PreserveSig;
- return;
-
- case "System.Runtime.InteropServices.PreserveSigAttribute":
- iattrs |= MethodImplAttributes.PreserveSig;
- return;
- case "System.Runtime.CompilerServices.SpecialNameAttribute":
- attrs |= MethodAttributes.SpecialName;
- return;
- case "System.Security.SuppressUnmanagedCodeSecurityAttribute":
- attrs |= MethodAttributes.HasSecurity;
- break;
- }
-
- if (cattrs != null) {
- CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
- cattrs.CopyTo (new_array, 0);
- new_array [cattrs.Length] = customBuilder;
- cattrs = new_array;
- } else {
- cattrs = new CustomAttributeBuilder [1];
- cattrs [0] = customBuilder;
- }
- }
-
- [ComVisible (true)]
- public void SetCustomAttribute (ConstructorInfo con, byte[] binaryAttribute)
- {
- if (con == null)
- throw new ArgumentNullException ("con");
- if (binaryAttribute == null)
- throw new ArgumentNullException ("binaryAttribute");
- SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
- }
-
- public void SetImplementationFlags (MethodImplAttributes attributes)
- {
- RejectIfCreated ();
- iattrs = attributes;
- }
-
- public override string ToString()
- {
- return "MethodBuilder [" + type.Name + "::" + name + "]";
- }
-
- // FIXME:
- public override bool Equals (object obj)
- {
- return base.Equals (obj);
- }
-
- public override int GetHashCode ()
- {
- return name.GetHashCode ();
- }
-
- internal override int get_next_table_index (object obj, int table, int count)
- {
- return type.get_next_table_index (obj, table, count);
- }
-
- void ExtendArray<T> (ref T[] array, T elem) {
- if (array == null) {
- array = new T [1];
- } else {
- var newa = new T [array.Length + 1];
- Array.Copy (array, newa, array.Length);
- array = newa;
- }
- array [array.Length - 1] = elem;
- }
-
- internal void set_override (MethodInfo mdecl)
- {
- ExtendArray<MethodInfo> (ref override_methods, mdecl);
- }
-
- private void RejectIfCreated ()
- {
- if (type.is_created)
- throw new InvalidOperationException ("Type definition of the method is complete.");
- }
-
- private Exception NotSupported ()
- {
- return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
- }
-
- public override MethodInfo MakeGenericMethod (params Type [] typeArguments)
- {
- if (!IsGenericMethodDefinition)
- throw new InvalidOperationException ("Method is not a generic method definition");
- if (typeArguments == null)
- throw new ArgumentNullException ("typeArguments");
- if (generic_params.Length != typeArguments.Length)
- throw new ArgumentException ("Incorrect length", "typeArguments");
- foreach (Type type in typeArguments) {
- if (type == null)
- throw new ArgumentNullException ("typeArguments");
- }
-
- return new MethodOnTypeBuilderInst (this, typeArguments);
- }
-
- public override bool IsGenericMethodDefinition {
- get {
- return generic_params != null;
- }
- }
-
- public override bool IsGenericMethod {
- get {
- return generic_params != null;
- }
- }
-
- public override MethodInfo GetGenericMethodDefinition ()
- {
- if (!IsGenericMethodDefinition)
- throw new InvalidOperationException ();
-
- return this;
- }
-
- public override Type[] GetGenericArguments ()
- {
- if (generic_params == null)
- return null;
-
- Type[] result = new Type [generic_params.Length];
- for (int i = 0; i < generic_params.Length; i++)
- result [i] = generic_params [i];
-
- return result;
- }
-
- public GenericTypeParameterBuilder[] DefineGenericParameters (params string[] names)
- {
- if (names == null)
- throw new ArgumentNullException ("names");
- if (names.Length == 0)
- throw new ArgumentException ("", "names");
- type.check_not_created ();
- generic_params = new GenericTypeParameterBuilder [names.Length];
- for (int i = 0; i < names.Length; i++) {
- string item = names [i];
- if (item == null)
- throw new ArgumentNullException ("names");
- generic_params [i] = new GenericTypeParameterBuilder (type, this, item, i);
- }
-
- return generic_params;
- }
-
- public void SetReturnType (Type returnType)
- {
- rtype = returnType;
- }
-
- public void SetParameters (params Type[] parameterTypes)
- {
- if (parameterTypes != null) {
- for (int i = 0; i < parameterTypes.Length; ++i)
- if (parameterTypes [i] == null)
- throw new ArgumentNullException (nameof (parameterTypes), "Elements of the parameterTypes array cannot be null");
-
- this.parameters = new Type [parameterTypes.Length];
- System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
- }
- }
-
- public void SetSignature (Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
- {
- SetReturnType (returnType);
- SetParameters (parameterTypes);
- this.returnModReq = returnTypeRequiredCustomModifiers;
- this.returnModOpt = returnTypeOptionalCustomModifiers;
- this.paramModReq = parameterTypeRequiredCustomModifiers;
- this.paramModOpt = parameterTypeOptionalCustomModifiers;
- }
-
- public override Module Module {
- get {
- return GetModule ();
- }
- }
-
- public override ParameterInfo ReturnParameter {
- get {
- if (!type.is_created)
- throw new InvalidOperationException (SR.InvalidOperation_TypeNotCreated);
- if (created == null)
- created = (RuntimeMethodInfo)MethodBase.GetMethodFromHandle (mhandle);
- return created.ReturnParameter;
- }
- }
- }
-
- [StructLayout(LayoutKind.Sequential)]
- readonly struct ExceptionHandler : IEquatable<ExceptionHandler>
- {
- internal readonly int m_exceptionClass;
- internal readonly int m_tryStartOffset;
- internal readonly int m_tryEndOffset;
- internal readonly int m_filterOffset;
- internal readonly int m_handlerStartOffset;
- internal readonly int m_handlerEndOffset;
- internal readonly ExceptionHandlingClauseOptions m_kind;
-
- public int ExceptionTypeToken
- {
- get { return m_exceptionClass; }
- }
-
- public int TryOffset
- {
- get { return m_tryStartOffset; }
- }
-
- public int TryLength
- {
- get { return m_tryEndOffset - m_tryStartOffset; }
- }
-
- public int FilterOffset
- {
- get { return m_filterOffset; }
- }
-
- public int HandlerOffset
- {
- get { return m_handlerStartOffset; }
- }
-
- public int HandlerLength
- {
- get { return m_handlerEndOffset - m_handlerStartOffset; }
- }
-
- public ExceptionHandlingClauseOptions Kind
- {
- get { return m_kind; }
- }
-
- internal ExceptionHandler(int tryStartOffset, int tryEndOffset, int filterOffset, int handlerStartOffset, int handlerEndOffset,
- int kind, int exceptionTypeToken)
- {
- m_tryStartOffset = tryStartOffset;
- m_tryEndOffset = tryEndOffset;
- m_filterOffset = filterOffset;
- m_handlerStartOffset = handlerStartOffset;
- m_handlerEndOffset = handlerEndOffset;
- m_kind = (ExceptionHandlingClauseOptions)kind;
- m_exceptionClass = exceptionTypeToken;
- }
-
- private static bool IsValidKind(ExceptionHandlingClauseOptions kind)
- {
- switch (kind)
- {
- case ExceptionHandlingClauseOptions.Clause:
- case ExceptionHandlingClauseOptions.Filter:
- case ExceptionHandlingClauseOptions.Finally:
- case ExceptionHandlingClauseOptions.Fault:
- return true;
-
- default:
- return false;
- }
- }
-
- public override int GetHashCode()
- {
- return m_exceptionClass ^ m_tryStartOffset ^ m_tryEndOffset ^ m_filterOffset ^ m_handlerStartOffset ^ m_handlerEndOffset ^ (int)m_kind;
- }
-
- public override bool Equals(Object obj)
- {
- return obj is ExceptionHandler && Equals((ExceptionHandler)obj);
- }
-
- public bool Equals(ExceptionHandler other)
- {
- return
- other.m_exceptionClass == m_exceptionClass &&
- other.m_tryStartOffset == m_tryStartOffset &&
- other.m_tryEndOffset == m_tryEndOffset &&
- other.m_filterOffset == m_filterOffset &&
- other.m_handlerStartOffset == m_handlerStartOffset &&
- other.m_handlerEndOffset == m_handlerEndOffset &&
- other.m_kind == m_kind;
- }
-
- public static bool operator ==(ExceptionHandler left, ExceptionHandler right)
- {
- return left.Equals(right);
- }
-
- public static bool operator !=(ExceptionHandler left, ExceptionHandler right)
- {
- return !left.Equals(right);
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs
deleted file mode 100644
index 49b2d39e962..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs
+++ /dev/null
@@ -1,315 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit/MethodOnTypeBuilderInst.cs
-//
-// Author:
-// Zoltan Varga (vargaz@gmail.com)
-//
-//
-// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Globalization;
-using System.Reflection;
-using System.Text;
-using System.Runtime.InteropServices;
-
-
-namespace System.Reflection.Emit
-{
- /*
- * This class represents a method of an instantiation of a generic type builder.
- */
- [StructLayout (LayoutKind.Sequential)]
- internal class MethodOnTypeBuilderInst : MethodInfo
- {
- #region Keep in sync with object-internals.h
- Type instantiation;
- MethodInfo base_method; /*This is the base method definition, it must be non-inflated and belong to a non-inflated type.*/
- Type[] method_arguments;
- #endregion
- MethodInfo generic_method_definition;
-
- public MethodOnTypeBuilderInst (TypeBuilderInstantiation instantiation, MethodInfo base_method)
- {
- this.instantiation = instantiation;
- this.base_method = base_method;
- }
-
- internal MethodOnTypeBuilderInst (MethodOnTypeBuilderInst gmd, Type[] typeArguments)
- {
- this.instantiation = gmd.instantiation;
- this.base_method = gmd.base_method;
- this.method_arguments = new Type [typeArguments.Length];
- typeArguments.CopyTo (this.method_arguments, 0);
- this.generic_method_definition = gmd;
- }
-
- internal MethodOnTypeBuilderInst (MethodInfo method, Type[] typeArguments)
- {
- this.instantiation = method.DeclaringType;
- this.base_method = ExtractBaseMethod (method);
- this.method_arguments = new Type [typeArguments.Length];
- typeArguments.CopyTo (this.method_arguments, 0);
- if (base_method != method)
- this.generic_method_definition = method;
- }
-
- static MethodInfo ExtractBaseMethod (MethodInfo info)
- {
- if (info is MethodBuilder)
- return info;
- if (info is MethodOnTypeBuilderInst)
- return ((MethodOnTypeBuilderInst)info).base_method;
-
- if (info.IsGenericMethod)
- info = info.GetGenericMethodDefinition ();
-
- Type t = info.DeclaringType;
- if (!t.IsGenericType || t.IsGenericTypeDefinition)
- return info;
-
- return (MethodInfo)t.Module.ResolveMethod (info.MetadataToken);
- }
-
- internal Type[] GetTypeArgs ()
- {
- if (!instantiation.IsGenericType || instantiation.IsGenericParameter)
- return null;
-
- return instantiation.GetGenericArguments ();
- }
-
- // Called from the runtime to return the corresponding finished MethodInfo object
- internal MethodInfo RuntimeResolve () {
- var type = instantiation.InternalResolve ();
- var m = type.GetMethod (base_method);
- if (method_arguments != null) {
- var args = new Type [method_arguments.Length];
- for (int i = 0; i < method_arguments.Length; ++i)
- args [i] = method_arguments [i].InternalResolve ();
- m = m.MakeGenericMethod (args);
- }
- return m;
- }
-
- //
- // MemberInfo members
- //
-
- public override Type DeclaringType {
- get {
- return instantiation;
- }
- }
-
- public override string Name {
- get {
- return base_method.Name;
- }
- }
-
- public override Type ReflectedType {
- get {
- return instantiation;
- }
- }
-
- public override Type ReturnType {
- get {
- return base_method.ReturnType;
- }
- }
-
- public override Module Module {
- get {
- return base_method.Module;
- }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- throw new NotSupportedException ();
- }
-
- public override object [] GetCustomAttributes (bool inherit)
- {
- throw new NotSupportedException ();
- }
-
- public override object [] GetCustomAttributes (Type attributeType, bool inherit)
- {
- throw new NotSupportedException ();
- }
-
- public override string ToString ()
- {
- //IEnumerable`1 get_Item(TKey)
- StringBuilder sb = new StringBuilder (ReturnType.ToString ());
- sb.Append (" ");
- sb.Append (base_method.Name);
- sb.Append ("(");
- sb.Append (")");
- return sb.ToString ();
- }
- //
- // MethodBase members
- //
-
- public override MethodImplAttributes GetMethodImplementationFlags ()
- {
- return base_method.GetMethodImplementationFlags ();
- }
-
- public override ParameterInfo [] GetParameters ()
- {
- return GetParametersInternal ();
- }
-
- internal override ParameterInfo [] GetParametersInternal ()
- {
- throw new NotSupportedException ();
- }
-
- public override int MetadataToken {
- get {
- return base.MetadataToken;
- }
- }
-
- internal override int GetParametersCount ()
- {
- return base_method.GetParametersCount ();
- }
-
- public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
- {
- throw new NotSupportedException ();
- }
-
- public override RuntimeMethodHandle MethodHandle {
- get {
- throw new NotSupportedException ();
- }
- }
-
- public override MethodAttributes Attributes {
- get {
- return base_method.Attributes;
- }
- }
-
- public override CallingConventions CallingConvention {
- get {
- return base_method.CallingConvention;
- }
- }
-
- public override MethodInfo MakeGenericMethod (params Type [] methodInstantiation)
- {
- if (!base_method.IsGenericMethodDefinition || (method_arguments != null))
- throw new InvalidOperationException ("Method is not a generic method definition");
-
- if (methodInstantiation == null)
- throw new ArgumentNullException ("methodInstantiation");
-
- if (base_method.GetGenericArguments ().Length != methodInstantiation.Length)
- throw new ArgumentException ("Incorrect length", "methodInstantiation");
-
- foreach (Type type in methodInstantiation) {
- if (type == null)
- throw new ArgumentNullException ("methodInstantiation");
- }
-
- return new MethodOnTypeBuilderInst (this, methodInstantiation);
- }
-
- public override Type [] GetGenericArguments ()
- {
- if (!base_method.IsGenericMethodDefinition)
- return null;
- Type[] source = method_arguments ?? base_method.GetGenericArguments ();
- Type[] result = new Type [source.Length];
- source.CopyTo (result, 0);
- return result;
- }
-
- public override MethodInfo GetGenericMethodDefinition ()
- {
- return generic_method_definition ?? base_method;
- }
-
- public override bool ContainsGenericParameters {
- get {
- if (base_method.ContainsGenericParameters)
- return true;
- if (!base_method.IsGenericMethodDefinition)
- throw new NotSupportedException ();
- if (method_arguments == null)
- return true;
- foreach (Type t in method_arguments) {
- if (t.ContainsGenericParameters)
- return true;
- }
- return false;
- }
- }
-
- public override bool IsGenericMethodDefinition {
- get {
- return base_method.IsGenericMethodDefinition && method_arguments == null;
- }
- }
-
- public override bool IsGenericMethod {
- get {
- return base_method.IsGenericMethodDefinition;
- }
- }
-
- //
- // MethodInfo members
- //
-
- public override MethodInfo GetBaseDefinition ()
- {
- throw new NotSupportedException ();
- }
-
- public override ParameterInfo ReturnParameter {
- get {
- throw new NotSupportedException();
- }
- }
-
- public override ICustomAttributeProvider ReturnTypeCustomAttributes {
- get {
- throw new NotSupportedException ();
- }
- }
- }
-}
-
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs
deleted file mode 100644
index 9df938b13c6..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs
+++ /dev/null
@@ -1,932 +0,0 @@
-#nullable disable
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//
-// System.Reflection.Emit/ModuleBuilder.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Reflection;
-using System.Collections;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Diagnostics.SymbolStore;
-using System.IO;
-using System.Globalization;
-
-namespace System.Reflection.Emit {
- [StructLayout (LayoutKind.Sequential)]
- public partial class ModuleBuilder : Module {
-
-#pragma warning disable 169, 414
- #region Sync with object-internals.h
- // This class inherits from Module, but the runtime expects it to have the same layout as MonoModule
- #region Sync with MonoModule
- internal IntPtr _impl; /* a pointer to a MonoImage */
- internal Assembly assembly;
- internal string fqname;
- internal string name;
- internal string scopename;
- internal bool is_resource;
- internal int token;
- #endregion
- private UIntPtr dynamic_image; /* GC-tracked */
- private int num_types;
- private TypeBuilder[] types;
- private CustomAttributeBuilder[] cattrs;
- private byte[] guid;
- private int table_idx;
- internal AssemblyBuilder assemblyb;
- private MethodBuilder[] global_methods;
- private FieldBuilder[] global_fields;
- bool is_main;
- private object resources;
- private IntPtr unparented_classes;
- private int[] table_indexes;
- #endregion
-#pragma warning restore 169, 414
-
- private TypeBuilder global_type;
- private Type global_type_created;
- // name_cache keys are display names
- Dictionary<TypeName, TypeBuilder> name_cache;
- Dictionary<string, int> us_string_cache;
- ModuleBuilderTokenGenerator token_gen;
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern void basic_init (ModuleBuilder ab);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern void set_wrappers_type (ModuleBuilder mb, Type ab);
-
- internal ModuleBuilder (AssemblyBuilder assb, string name, bool emitSymbolInfo) {
- this.name = this.scopename = name;
- this.fqname = name;
- this.assembly = this.assemblyb = assb;
- guid = Guid.NewGuid ().ToByteArray ();
- table_idx = get_next_table_index (this, 0x00, 1);
- name_cache = new Dictionary<TypeName, TypeBuilder> ();
- us_string_cache = new Dictionary<string, int> (512);
-
- basic_init (this);
-
- CreateGlobalType ();
-
- TypeBuilder tb = new TypeBuilder (this, TypeAttributes.Abstract, 0xFFFFFF); /*last valid token*/
- Type type = tb.CreateType ();
- set_wrappers_type (this, type);
- }
-
- public override string FullyQualifiedName {
- get {
- string fullyQualifiedName = fqname;
- if (fullyQualifiedName == null)
- return null;
- if (assemblyb.AssemblyDir != null) {
- fullyQualifiedName = Path.Combine (assemblyb.AssemblyDir, fullyQualifiedName);
- fullyQualifiedName = Path.GetFullPath (fullyQualifiedName);
- }
-
- return fullyQualifiedName;
- }
- }
-
- public bool IsTransient () {
- return true;
- }
-
- public void CreateGlobalFunctions ()
- {
- if (global_type_created != null)
- throw new InvalidOperationException ("global methods already created");
- if (global_type != null)
- global_type_created = global_type.CreateType ();
- }
-
- public FieldBuilder DefineInitializedData( string name, byte[] data, FieldAttributes attributes) {
- if (data == null)
- throw new ArgumentNullException ("data");
-
- var maskedAttributes = attributes & ~FieldAttributes.ReservedMask;
- FieldBuilder fb = DefineDataImpl (name, data.Length, maskedAttributes | FieldAttributes.HasFieldRVA);
- fb.SetRVAData (data);
-
- return fb;
- }
-
- public FieldBuilder DefineUninitializedData (string name, int size, FieldAttributes attributes)
- {
- return DefineDataImpl (name, size, attributes & ~FieldAttributes.ReservedMask);
- }
-
- private FieldBuilder DefineDataImpl (string name, int size, FieldAttributes attributes)
- {
- if (name == null)
- throw new ArgumentNullException ("name");
- if (name == String.Empty)
- throw new ArgumentException ("name cannot be empty", "name");
- if (global_type_created != null)
- throw new InvalidOperationException ("global fields already created");
- if ((size <= 0) || (size >= 0x3f0000))
- throw new ArgumentException ("Data size must be > 0 and < 0x3f0000", null as string);
-
- CreateGlobalType ();
-
- string typeName = "$ArrayType$" + size;
- Type datablobtype = GetType (typeName, false, false);
- if (datablobtype == null) {
- TypeBuilder tb = DefineType (typeName,
- TypeAttributes.Public|TypeAttributes.ExplicitLayout|TypeAttributes.Sealed,
- typeof (ValueType), null, PackingSize.Size1, size);
- tb.CreateType ();
- datablobtype = tb;
- }
- FieldBuilder fb = global_type.DefineField (name, datablobtype, attributes|FieldAttributes.Static);
-
- if (global_fields != null) {
- FieldBuilder[] new_fields = new FieldBuilder [global_fields.Length+1];
- System.Array.Copy (global_fields, new_fields, global_fields.Length);
- new_fields [global_fields.Length] = fb;
- global_fields = new_fields;
- } else {
- global_fields = new FieldBuilder [1];
- global_fields [0] = fb;
- }
- return fb;
- }
-
- private void addGlobalMethod (MethodBuilder mb) {
- if (global_methods != null) {
- MethodBuilder[] new_methods = new MethodBuilder [global_methods.Length+1];
- System.Array.Copy (global_methods, new_methods, global_methods.Length);
- new_methods [global_methods.Length] = mb;
- global_methods = new_methods;
- } else {
- global_methods = new MethodBuilder [1];
- global_methods [0] = mb;
- }
- }
-
- public MethodBuilder DefineGlobalMethod (string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes)
- {
- return DefineGlobalMethod (name, attributes, CallingConventions.Standard, returnType, parameterTypes);
- }
-
- public MethodBuilder DefineGlobalMethod (string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
- return DefineGlobalMethod (name, attributes, callingConvention, returnType, null, null, parameterTypes, null, null);
- }
-
- public MethodBuilder DefineGlobalMethod (string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers, Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers)
- {
- if (name == null)
- throw new ArgumentNullException ("name");
- if ((attributes & MethodAttributes.Static) == 0)
- throw new ArgumentException ("global methods must be static");
- if (global_type_created != null)
- throw new InvalidOperationException ("global methods already created");
- CreateGlobalType ();
- MethodBuilder mb = global_type.DefineMethod (name, attributes, callingConvention, returnType, requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers, parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers);
-
- addGlobalMethod (mb);
- return mb;
- }
-
- public MethodBuilder DefinePInvokeMethod (string name, string dllName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet) {
- return DefinePInvokeMethod (name, dllName, name, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet);
- }
-
- public MethodBuilder DefinePInvokeMethod (string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet) {
- if (name == null)
- throw new ArgumentNullException ("name");
- if ((attributes & MethodAttributes.Static) == 0)
- throw new ArgumentException ("global methods must be static");
- if (global_type_created != null)
- throw new InvalidOperationException ("global methods already created");
- CreateGlobalType ();
- MethodBuilder mb = global_type.DefinePInvokeMethod (name, dllName, entryName, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet);
-
- addGlobalMethod (mb);
- return mb;
- }
-
- public TypeBuilder DefineType (string name) {
- return DefineType (name, 0);
- }
-
- public TypeBuilder DefineType (string name, TypeAttributes attr) {
- if ((attr & TypeAttributes.Interface) != 0)
- return DefineType (name, attr, null, null);
- return DefineType (name, attr, typeof(object), null);
- }
-
- public TypeBuilder DefineType (string name, TypeAttributes attr, Type parent) {
- return DefineType (name, attr, parent, null);
- }
-
- private void AddType (TypeBuilder tb)
- {
- if (types != null) {
- if (types.Length == num_types) {
- TypeBuilder[] new_types = new TypeBuilder [types.Length * 2];
- System.Array.Copy (types, new_types, num_types);
- types = new_types;
- }
- } else {
- types = new TypeBuilder [1];
- }
- types [num_types] = tb;
- num_types ++;
- }
-
- private TypeBuilder DefineType (string name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packingSize, int typesize) {
- if (name == null)
- throw new ArgumentNullException ("fullname");
- TypeIdentifier ident = TypeIdentifiers.FromInternal (name);
- if (name_cache.ContainsKey (ident))
- throw new ArgumentException ("Duplicate type name within an assembly.");
- TypeBuilder res = new TypeBuilder (this, name, attr, parent, interfaces, packingSize, typesize, null);
- AddType (res);
-
- name_cache.Add (ident, res);
-
- return res;
- }
-
- internal void RegisterTypeName (TypeBuilder tb, TypeName name)
- {
- name_cache.Add (name, tb);
- }
-
- internal TypeBuilder GetRegisteredType (TypeName name)
- {
- TypeBuilder result = null;
- name_cache.TryGetValue (name, out result);
- return result;
- }
-
- [ComVisible (true)]
- public TypeBuilder DefineType (string name, TypeAttributes attr, Type parent, Type[] interfaces) {
- return DefineType (name, attr, parent, interfaces, PackingSize.Unspecified, TypeBuilder.UnspecifiedTypeSize);
- }
-
- public TypeBuilder DefineType (string name, TypeAttributes attr, Type parent, int typesize) {
- return DefineType (name, attr, parent, null, PackingSize.Unspecified, typesize);
- }
-
- public TypeBuilder DefineType (string name, TypeAttributes attr, Type parent, PackingSize packsize) {
- return DefineType (name, attr, parent, null, packsize, TypeBuilder.UnspecifiedTypeSize);
- }
-
- public TypeBuilder DefineType (string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize) {
- return DefineType (name, attr, parent, null, packingSize, typesize);
- }
-
- public MethodInfo GetArrayMethod( Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
- return new MonoArrayMethod (arrayClass, methodName, callingConvention, returnType, parameterTypes);
- }
-
- public EnumBuilder DefineEnum( string name, TypeAttributes visibility, Type underlyingType) {
- TypeIdentifier ident = TypeIdentifiers.FromInternal (name);
- if (name_cache.ContainsKey (ident))
- throw new ArgumentException ("Duplicate type name within an assembly.");
-
- EnumBuilder eb = new EnumBuilder (this, name, visibility, underlyingType);
- TypeBuilder res = eb.GetTypeBuilder ();
- AddType (res);
- name_cache.Add (ident, res);
- return eb;
- }
-
- [ComVisible (true)]
- public override Type GetType( string className) {
- return GetType (className, false, false);
- }
-
- [ComVisible (true)]
- public override Type GetType( string className, bool ignoreCase) {
- return GetType (className, false, ignoreCase);
- }
-
- private TypeBuilder search_in_array (TypeBuilder[] arr, int validElementsInArray, TypeName className) {
- int i;
- for (i = 0; i < validElementsInArray; ++i) {
- if (String.Compare (className.DisplayName, arr [i].FullName, true, CultureInfo.InvariantCulture) == 0) {
- return arr [i];
- }
- }
- return null;
- }
-
- private TypeBuilder search_nested_in_array (TypeBuilder[] arr, int validElementsInArray, TypeName className) {
- int i;
- for (i = 0; i < validElementsInArray; ++i) {
- if (String.Compare (className.DisplayName, arr [i].Name, true, CultureInfo.InvariantCulture) == 0)
- return arr [i];
- }
- return null;
- }
-
- private TypeBuilder GetMaybeNested (TypeBuilder t, IEnumerable<TypeName> nested) {
- TypeBuilder result = t;
-
- foreach (TypeName pname in nested) {
- if (result.subtypes == null)
- return null;
- result = search_nested_in_array(result.subtypes, result.subtypes.Length, pname);
- if (result == null)
- return null;
- }
- return result;
- }
-
- [ComVisible (true)]
- public override Type GetType (string className, bool throwOnError, bool ignoreCase)
- {
- if (className == null)
- throw new ArgumentNullException ("className");
- if (className.Length == 0)
- throw new ArgumentException ("className");
-
- TypeBuilder result = null;
-
- if (types == null && throwOnError)
- throw new TypeLoadException (className);
-
- TypeSpec ts = TypeSpec.Parse (className);
-
- if (!ignoreCase) {
- var displayNestedName = ts.TypeNameWithoutModifiers();
- name_cache.TryGetValue (displayNestedName, out result);
- } else {
- if (types != null)
- result = search_in_array (types, num_types, ts.Name);
- if (!ts.IsNested && result != null) {
- result = GetMaybeNested (result, ts.Nested);
- }
- }
- if ((result == null) && throwOnError)
- throw new TypeLoadException (className);
- if (result != null && (ts.HasModifiers || ts.IsByRef)) {
- Type mt = result;
- if (result is TypeBuilder) {
- var tb = result as TypeBuilder;
- if (tb.is_created)
- mt = tb.CreateType ();
- }
- foreach (var mod in ts.Modifiers) {
- if (mod is PointerSpec)
- mt = mt.MakePointerType ();
- else if (mod is ArraySpec) {
- var spec = mod as ArraySpec;
- if (spec.IsBound)
- return null;
- if (spec.Rank == 1)
- mt = mt.MakeArrayType ();
- else
- mt = mt.MakeArrayType (spec.Rank);
- }
- }
- if (ts.IsByRef)
- mt = mt.MakeByRefType ();
- result = mt as TypeBuilder;
- if (result == null)
- return mt;
- }
- if (result != null && result.is_created)
- return result.CreateType ();
- else
- return result;
- }
-
- internal int get_next_table_index (object obj, int table, int count) {
- if (table_indexes == null) {
- table_indexes = new int [64];
- for (int i=0; i < 64; ++i)
- table_indexes [i] = 1;
- /* allow room for .<Module> in TypeDef table */
- table_indexes [0x02] = 2;
- }
- // Console.WriteLine ("getindex for table "+table.ToString()+" got "+table_indexes [table].ToString());
- var index = table_indexes [table];
- table_indexes [table] += count;
- return index;
- }
-
- public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
- {
- if (customBuilder == null)
- throw new ArgumentNullException (nameof (customBuilder));
- if (cattrs != null) {
- CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
- cattrs.CopyTo (new_array, 0);
- new_array [cattrs.Length] = customBuilder;
- cattrs = new_array;
- } else {
- cattrs = new CustomAttributeBuilder [1];
- cattrs [0] = customBuilder;
- }
- }
-
- [ComVisible (true)]
- public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
- SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
- }
-/*
- internal ISymbolDocumentWriter DefineDocument (string url, Guid language, Guid languageVendor, Guid documentType)
- {
- if (symbolWriter != null)
- return symbolWriter.DefineDocument (url, language, languageVendor, documentType);
- else
- return null;
- }
-*/
- public override Type [] GetTypes ()
- {
- if (types == null)
- return Type.EmptyTypes;
-
- int n = num_types;
- Type [] copy = new Type [n];
- Array.Copy (types, copy, n);
-
- // MS replaces the typebuilders with their created types
- for (int i = 0; i < copy.Length; ++i)
- if (types [i].is_created)
- copy [i] = types [i].CreateType ();
-
- return copy;
- }
-
- public MethodToken GetMethodToken (MethodInfo method)
- {
- if (method == null)
- throw new ArgumentNullException ("method");
-
- return new MethodToken (GetToken (method));
- }
-
- public MethodToken GetArrayMethodToken (Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
- {
- return GetMethodToken (GetArrayMethod (arrayClass, methodName, callingConvention, returnType, parameterTypes));
- }
-
- [ComVisible (true)]
- public MethodToken GetConstructorToken (ConstructorInfo con)
- {
- if (con == null)
- throw new ArgumentNullException ("con");
-
- return new MethodToken (GetToken (con));
- }
-
- public FieldToken GetFieldToken (FieldInfo field)
- {
- if (field == null)
- throw new ArgumentNullException ("field");
-
- throw new NotImplementedException ();
- //return new FieldToken (GetToken (field));
- }
-
- // FIXME:
- public SignatureToken GetSignatureToken (byte[] sigBytes, int sigLength)
- {
- throw new NotImplementedException ();
- }
-
- public SignatureToken GetSignatureToken (SignatureHelper sigHelper)
- {
- if (sigHelper == null)
- throw new ArgumentNullException ("sigHelper");
- return new SignatureToken (GetToken (sigHelper));
- }
-
- public StringToken GetStringConstant (string str)
- {
- if (str == null)
- throw new ArgumentNullException ("str");
- return new StringToken (GetToken (str));
- }
-
- public TypeToken GetTypeToken (Type type)
- {
- if (type == null)
- throw new ArgumentNullException ("type");
- if (type.IsByRef)
- throw new ArgumentException ("type can't be a byref type", "type");
- if (!IsTransient () && (type.Module is ModuleBuilder) && ((ModuleBuilder)type.Module).IsTransient ())
- throw new InvalidOperationException ("a non-transient module can't reference a transient module");
- return new TypeToken (GetToken (type));
- }
-
- public TypeToken GetTypeToken (string name)
- {
- return GetTypeToken (GetType (name));
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern int getUSIndex (ModuleBuilder mb, string str);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern int getToken (ModuleBuilder mb, object obj, bool create_open_instance);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern int getMethodToken (ModuleBuilder mb, MethodBase method,
- Type[] opt_param_types);
-
- internal int GetToken (string str)
- {
- int result;
- if (!us_string_cache.TryGetValue (str, out result)) {
- result = getUSIndex (this, str);
- us_string_cache [str] = result;
- }
-
- return result;
- }
-
- static int typeref_tokengen = 0x01ffffff;
- static int typedef_tokengen = 0x02ffffff;
- static int typespec_tokengen = 0x1bffffff;
- static int memberref_tokengen = 0x0affffff;
- static int methoddef_tokengen = 0x06ffffff;
- Dictionary<MemberInfo, int> inst_tokens, inst_tokens_open;
-
- //
- // Assign a pseudo token to the various TypeBuilderInst objects, so the runtime
- // doesn't have to deal with them.
- // For Run assemblies, the tokens will not be fixed up, so the runtime will
- // still encounter these objects, it will resolve them by calling their
- // RuntimeResolve () methods.
- //
- int GetPseudoToken (MemberInfo member, bool create_open_instance)
- {
- int token;
- var dict = create_open_instance ? inst_tokens_open : inst_tokens;
- if (dict == null) {
- dict = new Dictionary<MemberInfo, int> (ReferenceEqualityComparer<MemberInfo>.Instance);
- if (create_open_instance)
- inst_tokens_open = dict;
- else
- inst_tokens = dict;
- } else if (dict.TryGetValue (member, out token)) {
- return token;
- }
-
- // Count backwards to avoid collisions with the tokens
- // allocated by the runtime
- if (member is TypeBuilderInstantiation || member is SymbolType)
- token = typespec_tokengen --;
- else if (member is FieldOnTypeBuilderInst)
- token = memberref_tokengen --;
- else if (member is ConstructorOnTypeBuilderInst)
- token = memberref_tokengen --;
- else if (member is MethodOnTypeBuilderInst)
- token = memberref_tokengen --;
- else if (member is FieldBuilder)
- token = memberref_tokengen --;
- else if (member is TypeBuilder) {
- if (create_open_instance && (member as TypeBuilder).ContainsGenericParameters)
- token = typespec_tokengen --;
- else if (member.Module == this)
- token = typedef_tokengen --;
- else
- token = typeref_tokengen --;
- } else if (member is EnumBuilder) {
- token = GetPseudoToken ((member as EnumBuilder).GetTypeBuilder(), create_open_instance);
- dict[member] = token;
- // n.b. don't register with the runtime, the TypeBuilder already did it.
- return token;
- } else if (member is ConstructorBuilder) {
- if (member.Module == this && !(member as ConstructorBuilder).TypeBuilder.ContainsGenericParameters)
- token = methoddef_tokengen --;
- else
- token = memberref_tokengen --;
- } else if (member is MethodBuilder) {
- var mb = member as MethodBuilder;
- if (member.Module == this && !mb.TypeBuilder.ContainsGenericParameters && !mb.IsGenericMethodDefinition)
- token = methoddef_tokengen --;
- else
- token = memberref_tokengen --;
- } else if (member is GenericTypeParameterBuilder) {
- token = typespec_tokengen --;
- } else
- throw new NotImplementedException ();
-
- dict [member] = token;
- RegisterToken (member, token);
- return token;
- }
-
- internal int GetToken (MemberInfo member) {
- if (member is ConstructorBuilder || member is MethodBuilder || member is FieldBuilder)
- return GetPseudoToken (member, false);
- return getToken (this, member, true);
- }
-
- internal int GetToken (MemberInfo member, bool create_open_instance) {
- if (member is TypeBuilderInstantiation || member is FieldOnTypeBuilderInst || member is ConstructorOnTypeBuilderInst || member is MethodOnTypeBuilderInst || member is SymbolType || member is FieldBuilder || member is TypeBuilder || member is ConstructorBuilder || member is MethodBuilder || member is GenericTypeParameterBuilder ||
- member is EnumBuilder)
- return GetPseudoToken (member, create_open_instance);
- return getToken (this, member, create_open_instance);
- }
-
- internal int GetToken (MethodBase method, IEnumerable<Type> opt_param_types) {
- if (method is ConstructorBuilder || method is MethodBuilder)
- return GetPseudoToken (method, false);
-
- if (opt_param_types == null)
- return getToken (this, method, true);
-
- var optParamTypes = new List<Type> (opt_param_types);
- return getMethodToken (this, method, optParamTypes.ToArray ());
- }
-
- internal int GetToken (MethodBase method, Type[] opt_param_types) {
- if (method is ConstructorBuilder || method is MethodBuilder)
- return GetPseudoToken (method, false);
- return getMethodToken (this, method, opt_param_types);
- }
-
- internal int GetToken (SignatureHelper helper) {
- return getToken (this, helper, true);
- }
-
- /*
- * Register the token->obj mapping with the runtime so the Module.Resolve...
- * methods will work for obj.
- */
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal extern void RegisterToken (object obj, int token);
-
- /*
- * Returns MemberInfo registered with the given token.
- */
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal extern object GetRegisteredToken (int token);
-
- internal TokenGenerator GetTokenGenerator () {
- if (token_gen == null)
- token_gen = new ModuleBuilderTokenGenerator (this);
- return token_gen;
- }
-
- // Called from the runtime to return the corresponding finished reflection object
- internal static object RuntimeResolve (object obj) {
- if (obj is MethodBuilder)
- return (obj as MethodBuilder).RuntimeResolve ();
- if (obj is ConstructorBuilder)
- return (obj as ConstructorBuilder).RuntimeResolve ();
- if (obj is FieldBuilder)
- return (obj as FieldBuilder).RuntimeResolve ();
- if (obj is GenericTypeParameterBuilder)
- return (obj as GenericTypeParameterBuilder).RuntimeResolve ();
- if (obj is FieldOnTypeBuilderInst)
- return (obj as FieldOnTypeBuilderInst).RuntimeResolve ();
- if (obj is MethodOnTypeBuilderInst)
- return (obj as MethodOnTypeBuilderInst).RuntimeResolve ();
- if (obj is ConstructorOnTypeBuilderInst)
- return (obj as ConstructorOnTypeBuilderInst).RuntimeResolve ();
- if (obj is Type)
- return (obj as Type).RuntimeResolve ();
- throw new NotImplementedException (obj.GetType ().FullName);
- }
-
- internal string FileName {
- get {
- return fqname;
- }
- }
-
- internal bool IsMain {
- set {
- is_main = value;
- }
- }
-
- internal void CreateGlobalType () {
- if (global_type == null)
- global_type = new TypeBuilder (this, 0, 1);
- }
-
- public override Assembly Assembly {
- get { return assemblyb; }
- }
-
- public override string Name {
- get { return name; }
- }
-
- public override string ScopeName {
- get { return name; }
- }
-
- public override Guid ModuleVersionId {
- get {
- return new Guid (guid);
- }
- }
-
- public override bool IsResource ()
- {
- return false;
- }
-
- protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
- {
- if (global_type_created == null)
- return null;
- if (types == null)
- return global_type_created.GetMethod (name);
- return global_type_created.GetMethod (name, bindingAttr, binder, callConvention, types, modifiers);
- }
-
- public override FieldInfo ResolveField (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- return RuntimeModule.ResolveField (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
- }
-
- public override MemberInfo ResolveMember (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- return RuntimeModule.ResolveMember (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
- }
-
- internal MemberInfo ResolveOrGetRegisteredToken (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments)
- {
- ResolveTokenError error;
- MemberInfo m = RuntimeModule.ResolveMemberToken (_impl, metadataToken, RuntimeModule.ptrs_from_types (genericTypeArguments), RuntimeModule.ptrs_from_types (genericMethodArguments), out error);
- if (m != null)
- return m;
-
- m = GetRegisteredToken (metadataToken) as MemberInfo;
- if (m == null)
- throw RuntimeModule.resolve_token_exception (Name, metadataToken, error, "MemberInfo");
- else
- return m;
- }
-
- public override MethodBase ResolveMethod (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- return RuntimeModule.ResolveMethod (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
- }
-
- public override string ResolveString (int metadataToken) {
- return RuntimeModule.ResolveString (this, _impl, metadataToken);
- }
-
- public override byte[] ResolveSignature (int metadataToken) {
- return RuntimeModule.ResolveSignature (this, _impl, metadataToken);
- }
-
- public override Type ResolveType (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- return RuntimeModule.ResolveType (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
- }
-
- public override bool Equals (object obj)
- {
- return base.Equals (obj);
- }
-
- public override int GetHashCode ()
- {
- return base.GetHashCode ();
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- return base.IsDefined (attributeType, inherit);
- }
-
- public override object[] GetCustomAttributes (bool inherit)
- {
- return GetCustomAttributes (null, inherit);
- }
-
- public override object[] GetCustomAttributes (Type attributeType, bool inherit)
- {
- if (cattrs == null || cattrs.Length == 0)
- return Array.Empty<object> ();
-
- if (attributeType is TypeBuilder)
- throw new InvalidOperationException ("First argument to GetCustomAttributes can't be a TypeBuilder");
-
- List<object> results = new List<object> ();
- for (int i=0; i < cattrs.Length; i++) {
- Type t = cattrs [i].Ctor.GetType ();
-
- if (t is TypeBuilder)
- throw new InvalidOperationException ("Can't construct custom attribute for TypeBuilder type");
-
- if (attributeType == null || attributeType.IsAssignableFrom (t))
- results.Add (cattrs [i].Invoke ());
- }
-
- return results.ToArray ();
- }
-
- public override IList<CustomAttributeData> GetCustomAttributesData ()
- {
- return CustomAttributeData.GetCustomAttributes (this);
- }
-
- public override FieldInfo GetField (string name, BindingFlags bindingAttr)
- {
- if (global_type_created == null)
- throw new InvalidOperationException ("Module-level fields cannot be retrieved until after the CreateGlobalFunctions method has been called for the module.");
- return global_type_created.GetField (name, bindingAttr);
- }
-
- public override FieldInfo[] GetFields (BindingFlags bindingFlags)
- {
- if (global_type_created == null)
- throw new InvalidOperationException ("Module-level fields cannot be retrieved until after the CreateGlobalFunctions method has been called for the module.");
- return global_type_created.GetFields (bindingFlags);
- }
-
- public override MethodInfo[] GetMethods (BindingFlags bindingFlags)
- {
- if (global_type_created == null)
- throw new InvalidOperationException ("Module-level methods cannot be retrieved until after the CreateGlobalFunctions method has been called for the module.");
- return global_type_created.GetMethods (bindingFlags);
- }
-
- public override int MetadataToken {
- get {
- return RuntimeModule.get_MetadataToken (this);
- }
- }
- }
-
- internal class ModuleBuilderTokenGenerator : TokenGenerator {
-
- private ModuleBuilder mb;
-
- public ModuleBuilderTokenGenerator (ModuleBuilder mb) {
- this.mb = mb;
- }
-
- public int GetToken (string str) {
- return mb.GetToken (str);
- }
-
- public int GetToken (MemberInfo member, bool create_open_instance) {
- return mb.GetToken (member, create_open_instance);
- }
-
- public int GetToken (MethodBase method, Type[] opt_param_types) {
- return mb.GetToken (method, opt_param_types);
- }
-
- public int GetToken (SignatureHelper helper) {
- return mb.GetToken (helper);
- }
- }
-
- internal sealed class ReferenceEqualityComparer<T> : IEqualityComparer<T> where T : class
- {
- internal static readonly ReferenceEqualityComparer<T> Instance = new ReferenceEqualityComparer<T>();
-
- private ReferenceEqualityComparer()
- {
- }
-
- public bool Equals(T x, T y)
- {
- return ReferenceEquals (x, y);
- }
-
- public int GetHashCode(T obj)
- {
- return RuntimeHelpers.GetHashCode (obj);
- }
- }
-
-}
-
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MonoArrayMethod.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MonoArrayMethod.cs
deleted file mode 100644
index eebe6efc687..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MonoArrayMethod.cs
+++ /dev/null
@@ -1,158 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection/MonoMethod.cs
-// The class used to represent methods from the mono runtime.
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection {
- [StructLayout (LayoutKind.Sequential)]
- internal class MonoArrayMethod: MethodInfo {
-#pragma warning disable 649
- internal RuntimeMethodHandle mhandle;
- internal Type parent;
- internal Type ret;
- internal Type[] parameters;
- internal string name;
- internal int table_idx;
- internal CallingConventions call_conv;
-#pragma warning restore 649
-
- internal MonoArrayMethod (Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
- name = methodName;
- parent = arrayClass;
- ret = returnType;
- parameters = (Type[])parameterTypes.Clone();
- call_conv = callingConvention;
- }
-
- // FIXME: "Always returns this"
- public override MethodInfo GetBaseDefinition() {
- return this; /* FIXME */
- }
- public override Type ReturnType {
- get {
- return ret;
- }
- }
-
- // FIXME: "Not implemented. Always returns null"
- public override ICustomAttributeProvider ReturnTypeCustomAttributes {
- get {return null;}
- }
-
- // FIXME: "Not implemented. Always returns zero"
- public override MethodImplAttributes GetMethodImplementationFlags() {
- return (MethodImplAttributes)0;
- }
-
- // FIXME: "Not implemented. Always returns an empty array"
- public override ParameterInfo[] GetParameters()
- {
- return GetParametersInternal ();
- }
-
- internal override ParameterInfo[] GetParametersInternal ()
- {
- return Array.Empty<ParameterInfo> ();
- }
-
- // FIXME: "Not implemented. Always returns 0"
- internal override int GetParametersCount ()
- {
- return 0;
- }
-
- // FIXME: "Not implemented"
- public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
- throw new NotImplementedException ();
- }
-
- public override RuntimeMethodHandle MethodHandle {
- get {return mhandle;}
- }
-
- // FIXME: "Not implemented. Always returns zero"
- public override MethodAttributes Attributes {
- get {
- return (MethodAttributes)0;
- }
- }
-
- public override Type ReflectedType {
- get {
- return parent;
- }
- }
- public override Type DeclaringType {
- get {
- return parent;
- }
- }
- public override string Name {
- get {
- return name;
- }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit) {
- return CustomAttribute.IsDefined (this, attributeType, inherit);
- }
-
- public override object[] GetCustomAttributes( bool inherit) {
- return CustomAttribute.GetCustomAttributes (this, inherit);
- }
- public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
- return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
- }
-
- public override string ToString () {
- string parms = String.Empty;
- ParameterInfo[] p = GetParameters ();
- for (int i = 0; i < p.Length; ++i) {
- if (i > 0)
- parms = parms + ", ";
- parms = parms + p [i].ParameterType.Name;
- }
- if (ReturnType != null)
- return ReturnType.Name+" "+Name+"("+parms+")";
- else
- return "void "+Name+"("+parms+")";
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.Mono.cs
deleted file mode 100644
index 70a8fad0456..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ParameterBuilder.Mono.cs
+++ /dev/null
@@ -1,146 +0,0 @@
-#nullable disable
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-
-//
-// System.Reflection.Emit/ParameterBuilder.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit {
- [StructLayout (LayoutKind.Sequential)]
- public partial class ParameterBuilder
- {
-#pragma warning disable 169, 414
- private MethodBase methodb; /* MethodBuilder, ConstructorBuilder or DynamicMethod */
- private string name;
- private CustomAttributeBuilder[] cattrs;
- private UnmanagedMarshal marshal_info;
- private ParameterAttributes attrs;
- private int position;
- private int table_idx;
- object def_value;
-#pragma warning restore 169, 414
-
- internal ParameterBuilder (MethodBase mb, int pos, ParameterAttributes attributes, string strParamName) {
- name = strParamName;
- position = pos;
- attrs = attributes;
- methodb = mb;
- if (mb is DynamicMethod)
- table_idx = 0;
- else
- table_idx = mb.get_next_table_index (this, 0x08, 1);
- }
-
- public virtual int Attributes {
- get {return (int)attrs;}
- }
- public bool IsIn {
- get {return ((int)attrs & (int)ParameterAttributes.In) != 0;}
- }
- public bool IsOut {
- get {return ((int)attrs & (int)ParameterAttributes.Out) != 0;}
- }
- public bool IsOptional {
- get {return ((int)attrs & (int)ParameterAttributes.Optional) != 0;}
- }
- public virtual string Name {
- get {return name;}
- }
- public virtual int Position {
- get {return position;}
- }
-
- public virtual ParameterToken GetToken() {
- return new ParameterToken (0x08 | table_idx);
- }
-
- public virtual void SetConstant (object defaultValue)
- {
- if (position > 0) {
- TypeBuilder.SetConstantValue (methodb.GetParameterType (position - 1),
- defaultValue, ref defaultValue);
- }
-
- def_value = defaultValue;
- attrs |= ParameterAttributes.HasDefault;
- }
-
- public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
- string attrname = customBuilder.Ctor.ReflectedType.FullName;
- if (attrname == "System.Runtime.InteropServices.InAttribute") {
- attrs |= ParameterAttributes.In;
- return;
- } else if (attrname == "System.Runtime.InteropServices.OutAttribute") {
- attrs |= ParameterAttributes.Out;
- return;
- } else if (attrname == "System.Runtime.InteropServices.OptionalAttribute") {
- attrs |= ParameterAttributes.Optional;
- return;
- } else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute") {
- attrs |= ParameterAttributes.HasFieldMarshal;
- marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, false);
- /* FIXME: check for errors */
- return;
- } else if (attrname == "System.Runtime.InteropServices.DefaultParameterValueAttribute") {
- /* MS.NET doesn't handle this attribute but we handle it for consistency */
- CustomAttributeBuilder.CustomAttributeInfo cinfo = CustomAttributeBuilder.decode_cattr (customBuilder);
- /* FIXME: check for type compatibility */
- SetConstant (cinfo.ctorArgs [0]);
- return;
- }
-
- if (cattrs != null) {
- CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
- cattrs.CopyTo (new_array, 0);
- new_array [cattrs.Length] = customBuilder;
- cattrs = new_array;
- } else {
- cattrs = new CustomAttributeBuilder [1];
- cattrs [0] = customBuilder;
- }
- }
-
- [ComVisible (true)]
- public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
- SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
- }
- }
-}
-
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs
deleted file mode 100644
index 5cd1b5b160e..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs
+++ /dev/null
@@ -1,218 +0,0 @@
-#nullable disable
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//
-// System.Reflection.Emit/PropertyBuilder.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit {
- [StructLayout (LayoutKind.Sequential)]
- public sealed partial class PropertyBuilder : PropertyInfo {
-
-// Managed version of MonoReflectionPropertyBuilder
-#pragma warning disable 169, 414
- private PropertyAttributes attrs;
- private string name;
- private Type type;
- private Type[] parameters;
- private CustomAttributeBuilder[] cattrs;
- private object def_value;
- private MethodBuilder set_method;
- private MethodBuilder get_method;
- private int table_idx = 0;
- internal TypeBuilder typeb;
- private Type[] returnModReq;
- private Type[] returnModOpt;
- private Type[][] paramModReq;
- private Type[][] paramModOpt;
- CallingConventions callingConvention;
-#pragma warning restore 169, 414
-
- internal PropertyBuilder (TypeBuilder tb, string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnModReq, Type[] returnModOpt, Type[] parameterTypes, Type[][] paramModReq, Type[][] paramModOpt)
- {
- this.name = name;
- this.attrs = attributes;
- this.callingConvention = callingConvention;
- this.type = returnType;
- this.returnModReq = returnModReq;
- this.returnModOpt = returnModOpt;
- this.paramModReq = paramModReq;
- this.paramModOpt = paramModOpt;
- if (parameterTypes != null) {
- this.parameters = new Type [parameterTypes.Length];
- System.Array.Copy (parameterTypes, this.parameters, this.parameters.Length);
- }
- typeb = tb;
- table_idx = tb.get_next_table_index (this, 0x17, 1);
- }
-
- public override PropertyAttributes Attributes {
- get {return attrs;}
- }
- public override bool CanRead {
- get {return get_method != null;}
- }
- public override bool CanWrite {
- get {return set_method != null;}
- }
- public override Type DeclaringType {
- get {return typeb;}
- }
- public override string Name {
- get {return name;}
- }
- public PropertyToken PropertyToken {
- get {return new PropertyToken ();}
- }
- public override Type PropertyType {
- get {return type;}
- }
- public override Type ReflectedType {
- get {return typeb;}
- }
-
- public void AddOtherMethod (MethodBuilder mdBuilder)
- {
- if (mdBuilder == null)
- throw new ArgumentNullException (nameof (mdBuilder));
- typeb.check_not_created ();
- }
-
- public override MethodInfo[] GetAccessors( bool nonPublic) {
- return null;
- }
- public override object[] GetCustomAttributes(bool inherit) {
- throw not_supported ();
- }
- public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
- throw not_supported ();
- }
- public override MethodInfo GetGetMethod( bool nonPublic) {
- return get_method;
- }
- public override ParameterInfo[] GetIndexParameters() {
- throw not_supported ();
- }
- public override MethodInfo GetSetMethod( bool nonPublic) {
- return set_method;
- }
-
- public override object GetValue (object obj, object[] index)
- {
- throw not_supported ();
- }
-
- public override object GetValue (object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
- {
- throw not_supported ();
- }
- public override bool IsDefined( Type attributeType, bool inherit) {
- throw not_supported ();
- }
- public void SetConstant (object defaultValue)
- {
- typeb.check_not_created ();
- def_value = defaultValue;
- }
-
- public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
- {
- if (customBuilder == null)
- throw new ArgumentNullException (nameof (customBuilder));
- typeb.check_not_created ();
- string attrname = customBuilder.Ctor.ReflectedType.FullName;
- if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
- attrs |= PropertyAttributes.SpecialName;
- return;
- }
-
- if (cattrs != null) {
- CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
- cattrs.CopyTo (new_array, 0);
- new_array [cattrs.Length] = customBuilder;
- cattrs = new_array;
- } else {
- cattrs = new CustomAttributeBuilder [1];
- cattrs [0] = customBuilder;
- }
- }
-
- [ComVisible (true)]
- public void SetCustomAttribute (ConstructorInfo con, byte[] binaryAttribute) {
- SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
- }
-
- public void SetGetMethod (MethodBuilder mdBuilder)
- {
- typeb.check_not_created ();
- if (mdBuilder == null)
- throw new ArgumentNullException (nameof (mdBuilder));
- get_method = mdBuilder;
- }
-
- public void SetSetMethod (MethodBuilder mdBuilder)
- {
- if (mdBuilder == null)
- throw new ArgumentNullException (nameof (mdBuilder));
- set_method = mdBuilder;
- }
-
- public override void SetValue (object obj, object value, object[] index)
- {
- throw not_supported ();
- }
-
- public override void SetValue (object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
- {
- throw not_supported ();
- }
-
- public override Module Module {
- get {
- return base.Module;
- }
- }
-
- private Exception not_supported ()
- {
- return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
- }
- }
-}
-
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs
deleted file mode 100644
index d705521b990..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs
+++ /dev/null
@@ -1,165 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit/PropertyOnTypeBuilderInst.cs
-//
-// Author:
-// Rodrigo Kumpera (rkumpera@novell.com)
-//
-//
-// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Globalization;
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit
-{
- /*
- * This class represents a property of an instantiation of a generic type builder.
- */
- [StructLayout (LayoutKind.Sequential)]
- internal class PropertyOnTypeBuilderInst : PropertyInfo
- {
- TypeBuilderInstantiation instantiation;
- PropertyInfo prop;
-
- internal PropertyOnTypeBuilderInst (TypeBuilderInstantiation instantiation, PropertyInfo prop)
- {
- this.instantiation = instantiation;
- this.prop = prop;
- }
-
- public override PropertyAttributes Attributes {
- get { throw new NotSupportedException (); }
- }
-
- public override bool CanRead {
- get { throw new NotSupportedException (); }
- }
-
- public override bool CanWrite {
- get { throw new NotSupportedException (); }
- }
-
- public override Type PropertyType {
- get { return instantiation.InflateType (prop.PropertyType); }
- }
-
- public override Type DeclaringType {
- get { return instantiation.InflateType (prop.DeclaringType); }
- }
-
- public override Type ReflectedType {
- get { return instantiation; }
- }
-
- public override string Name {
- get { return prop.Name; }
- }
-
- public override MethodInfo[] GetAccessors (bool nonPublic)
- {
- MethodInfo getter = GetGetMethod (nonPublic);
- MethodInfo setter = GetSetMethod (nonPublic);
-
- int methods = 0;
- if (getter != null)
- ++methods;
- if (setter != null)
- ++methods;
-
- MethodInfo[] res = new MethodInfo [methods];
-
- methods = 0;
- if (getter != null)
- res [methods++] = getter;
- if (setter != null)
- res [methods] = setter;
-
- return res;
- }
-
-
- public override MethodInfo GetGetMethod (bool nonPublic)
- {
- MethodInfo mi = prop.GetGetMethod (nonPublic);
- if (mi != null && prop.DeclaringType == instantiation.generic_type) {
- mi = TypeBuilder.GetMethod (instantiation, mi);
- }
- return mi;
- }
-
- public override ParameterInfo[] GetIndexParameters()
- {
- MethodInfo method = GetGetMethod (true);
- if (method != null)
- return method.GetParameters ();
-
- return Array.Empty<ParameterInfo> ();
- }
-
- public override MethodInfo GetSetMethod (bool nonPublic)
- {
- MethodInfo mi = prop.GetSetMethod (nonPublic);
- if (mi != null && prop.DeclaringType == instantiation.generic_type) {
- mi = TypeBuilder.GetMethod (instantiation, mi);
- }
- return mi;
- }
-
- public override string ToString ()
- {
- return String.Format("{0} {1}", PropertyType, Name);
- }
-
- public override object GetValue (object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
- {
- throw new NotSupportedException ();
- }
-
- public override void SetValue (object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
- {
- throw new NotSupportedException ();
- }
-
- public override bool IsDefined( Type attributeType, bool inherit)
- {
- throw new NotSupportedException ();
- }
-
- public override object[] GetCustomAttributes(bool inherit)
- {
- throw new NotSupportedException ();
- }
-
- public override object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- throw new NotSupportedException ();
- }
- }
-}
-
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs
deleted file mode 100644
index 078d9354d9d..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs
+++ /dev/null
@@ -1,410 +0,0 @@
-#nullable disable
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//
-// System.Reflection.Emit/SignatureHelper.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit {
- [StructLayout (LayoutKind.Sequential)]
- public sealed class SignatureHelper {
- internal enum SignatureHelperType {
- HELPER_FIELD,
- HELPER_LOCAL,
- HELPER_METHOD,
- HELPER_PROPERTY
- }
-
- private ModuleBuilder module; // can be null in 2.0
- private Type[] arguments;
- private SignatureHelperType type;
- private Type returnType;
- private CallingConventions callConv;
- private CallingConvention unmanagedCallConv;
-#pragma warning disable 649
- private Type[][] modreqs;
- private Type[][] modopts;
-#pragma warning restore 649
-
- internal SignatureHelper (ModuleBuilder module, SignatureHelperType type)
- {
- this.type = type;
- this.module = module;
- }
-
- public static SignatureHelper GetFieldSigHelper (Module mod)
- {
- if (mod != null && !(mod is ModuleBuilder))
- throw new ArgumentException ("ModuleBuilder is expected");
-
- return new SignatureHelper ((ModuleBuilder) mod, SignatureHelperType.HELPER_FIELD);
- }
-
- public static SignatureHelper GetLocalVarSigHelper (Module mod)
- {
- if (mod != null && !(mod is ModuleBuilder))
- throw new ArgumentException ("ModuleBuilder is expected");
-
- return new SignatureHelper ((ModuleBuilder) mod, SignatureHelperType.HELPER_LOCAL);
- }
-
- public static SignatureHelper GetLocalVarSigHelper ()
- {
- return new SignatureHelper (null, SignatureHelperType.HELPER_LOCAL);
- }
-
- public static SignatureHelper GetMethodSigHelper (CallingConventions callingConvention, Type returnType)
- {
- return GetMethodSigHelper (null, callingConvention, (CallingConvention)0, returnType, null);
- }
-
- public static SignatureHelper GetMethodSigHelper (CallingConvention unmanagedCallingConvention, Type returnType)
- {
- return GetMethodSigHelper (null, CallingConventions.Standard, unmanagedCallingConvention, returnType, null);
- }
-
- public static SignatureHelper GetMethodSigHelper (Module mod, CallingConventions callingConvention, Type returnType)
- {
- return GetMethodSigHelper (mod, callingConvention, (CallingConvention)0, returnType, null);
- }
-
- public static SignatureHelper GetMethodSigHelper (Module mod, CallingConvention unmanagedCallConv, Type returnType)
- {
- return GetMethodSigHelper (mod, CallingConventions.Standard, unmanagedCallConv, returnType, null);
- }
-
- public static SignatureHelper GetMethodSigHelper (Module mod, Type returnType, Type[] parameterTypes)
- {
- return GetMethodSigHelper (mod, CallingConventions.Standard, (CallingConvention)0, returnType, parameterTypes);
- }
-
- // FIXME: "Not implemented"
- public static SignatureHelper GetPropertySigHelper (Module mod, Type returnType, Type[] parameterTypes)
- {
- throw new NotImplementedException ();
- }
-
- // FIXME: "Not implemented"
- public static SignatureHelper GetPropertySigHelper (Module mod, Type returnType,
- Type [] requiredReturnTypeCustomModifiers,
- Type [] optionalReturnTypeCustomModifiers,
- Type [] parameterTypes,
- Type [] [] requiredParameterTypeCustomModifiers,
- Type [] [] optionalParameterTypeCustomModifiers)
- {
- throw new NotImplementedException ();
- }
-
- // FIXME: "Not implemented"
- public static SignatureHelper GetPropertySigHelper (Module mod,
- CallingConventions callingConvention,
- Type returnType,
- Type [] requiredReturnTypeCustomModifiers,
- Type [] optionalReturnTypeCustomModifiers,
- Type [] parameterTypes,
- Type [] [] requiredParameterTypeCustomModifiers,
- Type [] [] optionalParameterTypeCustomModifiers)
- {
- throw new NotImplementedException ();
- }
-
- //
- // Grows the given array, and returns the index where the element
- // was added
- //
- static int AppendArray (ref Type [] array, Type t)
- {
- if (array != null) {
- Type[] new_a = new Type [array.Length + 1];
- System.Array.Copy (array, new_a, array.Length);
- new_a [array.Length] = t;
- array = new_a;
- return array.Length-1;
- } else {
- array = new Type [1];
- array [0] = t;
- return 0;
- }
- }
-
- //
- // Appends the given type array @t into the @array passed at
- // position @pos. If there is no array, it gets created
- //
- // This allows adding data to a null array at position 5 for
- // example, creating 4 empty slots before the slot where @t
- // is stored.
- //
- //
- static void AppendArrayAt (ref Type [][] array, Type [] t, int pos)
- {
- int top = Math.Max (pos, array == null ? 0 : array.Length);
- Type[][] new_a = new Type [top+1][];
- if (array != null)
- System.Array.Copy (array, new_a, top);
- new_a [pos] = t;
- array = new_a;
- }
-
- static void ValidateParameterModifiers (string name, Type [] parameter_modifiers)
- {
- foreach (Type modifier in parameter_modifiers){
- if (modifier == null)
- throw new ArgumentNullException (name);
- if (modifier.IsArray)
- throw new ArgumentException ("Array type not permitted", name);
- if (modifier.ContainsGenericParameters)
- throw new ArgumentException ("Open Generic Type not permitted", name);
- }
- }
-
- static void ValidateCustomModifier (int n, Type [][] custom_modifiers, string name)
- {
- if (custom_modifiers == null)
- return;
-
- if (custom_modifiers.Length != n)
- throw new ArgumentException (String.Format ("Custom modifiers length `{0}' does not match the size of the arguments"));
-
- foreach (Type [] parameter_modifiers in custom_modifiers){
- if (parameter_modifiers == null)
- continue;
-
- ValidateParameterModifiers (name, parameter_modifiers);
- }
- }
-
- static Exception MissingFeature ()
- {
- throw new NotImplementedException ("Mono does not currently support setting modOpt/modReq through SignatureHelper");
- }
-
- // FIXME: "Currently we ignore requiredCustomModifiers and optionalCustomModifiers"
- public void AddArguments (Type[] arguments, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)
- {
- if (arguments == null)
- throw new ArgumentNullException ("arguments");
-
- // For now
- if (requiredCustomModifiers != null || optionalCustomModifiers != null){
- throw MissingFeature();
- }
-
- ValidateCustomModifier (arguments.Length, requiredCustomModifiers, "requiredCustomModifiers");
- ValidateCustomModifier (arguments.Length, optionalCustomModifiers, "optionalCustomModifiers");
-
- for (int i = 0; i < arguments.Length; i++){
- AddArgument (arguments [i],
- requiredCustomModifiers != null ? requiredCustomModifiers [i] : null,
- optionalCustomModifiers != null ? optionalCustomModifiers [i] : null);
- }
- }
-
- // FIXME: "pinned is ignored"
- public void AddArgument (Type argument, bool pinned)
- {
- AddArgument (argument);
- }
-
- public void AddArgument (Type argument, Type [] requiredCustomModifiers, Type [] optionalCustomModifiers)
- {
- if (argument == null)
- throw new ArgumentNullException ("argument");
-
- if (requiredCustomModifiers != null)
- ValidateParameterModifiers ("requiredCustomModifiers", requiredCustomModifiers);
- if (optionalCustomModifiers != null)
- ValidateParameterModifiers ("optionalCustomModifiers", optionalCustomModifiers);
-
- int p = AppendArray (ref arguments, argument);
- if (requiredCustomModifiers != null)
- AppendArrayAt (ref modreqs, requiredCustomModifiers, p);
- if (optionalCustomModifiers != null)
- AppendArrayAt (ref modopts, optionalCustomModifiers, p);
- }
-
- public void AddArgument (Type clsArgument)
- {
- if (clsArgument == null)
- throw new ArgumentNullException ("clsArgument");
-
- AppendArray (ref arguments, clsArgument);
- }
-
- // FIXME: "Not implemented"
- public void AddSentinel ()
- {
- throw new NotImplementedException ();
- }
-
- static bool CompareOK (Type [][] one, Type [][] two)
- {
- if (one == null){
- if (two == null)
- return true;
- return false;
- } else if (two == null)
- return false;
-
- if (one.Length != two.Length)
- return false;
-
- for (int i = 0; i < one.Length; i++){
- Type [] tone = one [i];
- Type [] ttwo = two [i];
-
- if (tone == null){
- if (ttwo == null)
- continue;
- } else if (ttwo == null)
- return false;
-
- if (tone.Length != ttwo.Length)
- return false;
-
- for (int j = 0; j < tone.Length; j++){
- Type uone = tone [j];
- Type utwo = ttwo [j];
-
- if (uone == null){
- if (utwo == null)
- continue;
- return false;
- } else if (utwo == null)
- return false;
-
- if (!uone.Equals (utwo))
- return false;
- }
- }
- return true;
- }
-
- public override bool Equals (object obj)
- {
- SignatureHelper other = obj as SignatureHelper;
- if (other == null)
- return false;
-
- if (other.module != module ||
- other.returnType != returnType ||
- other.callConv != callConv ||
- other.unmanagedCallConv != unmanagedCallConv)
- return false;
-
- if (arguments != null){
- if (other.arguments == null)
- return false;
- if (arguments.Length != other.arguments.Length)
- return false;
-
- for (int i = 0; i < arguments.Length; i++)
- if (!other.arguments [i].Equals (arguments [i]))
- return false;
- } else if (other.arguments != null)
- return false;
-
- return CompareOK (other.modreqs, modreqs) && CompareOK (other.modopts, modopts);
- }
-
- public override int GetHashCode ()
- {
- // Lame, but easy, and will work, and chances are
- // you will only need a few of these.
- return 0;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal extern byte[] get_signature_local ();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal extern byte[] get_signature_field ();
-
- public byte[] GetSignature ()
- {
- TypeBuilder.ResolveUserTypes (arguments);
-
- switch (type) {
- case SignatureHelperType.HELPER_LOCAL:
- return get_signature_local ();
- case SignatureHelperType.HELPER_FIELD:
- return get_signature_field ();
- default:
- throw new NotImplementedException ();
- }
- }
-
- public override string ToString() {
- return "SignatureHelper";
- }
-
- internal static SignatureHelper GetMethodSigHelper (Module mod, CallingConventions callingConvention, CallingConvention unmanagedCallingConvention, Type returnType,
- Type [] parameters)
- {
- if (mod != null && !(mod is ModuleBuilder))
- throw new ArgumentException ("ModuleBuilder is expected");
-
- if (returnType == null)
- returnType = typeof (void);
-
- if (returnType.IsUserType)
- throw new NotSupportedException ("User defined subclasses of System.Type are not yet supported.");
- if (parameters != null) {
- for (int i = 0; i < parameters.Length; ++i)
- if (parameters [i].IsUserType)
- throw new NotSupportedException ("User defined subclasses of System.Type are not yet supported.");
-
- }
-
- SignatureHelper helper =
- new SignatureHelper ((ModuleBuilder)mod, SignatureHelperType.HELPER_METHOD);
- helper.returnType = returnType;
- helper.callConv = callingConvention;
- helper.unmanagedCallConv = unmanagedCallingConvention;
-
- if (parameters != null) {
- helper.arguments = new Type [parameters.Length];
- for (int i = 0; i < parameters.Length; ++i)
- helper.arguments [i] = parameters [i];
- }
-
- return helper;
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs
deleted file mode 100644
index 7c7255daa7a..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs
+++ /dev/null
@@ -1,1892 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit.TypeBuilder.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-// Marek Safar (marek.safar@gmail.com)
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System;
-using System.Text;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Globalization;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics.SymbolStore;
-
-namespace System.Reflection.Emit
-{
- [StructLayout (LayoutKind.Sequential)]
- public sealed partial class TypeBuilder : TypeInfo
- {
-#pragma warning disable 169
- #region Sync with reflection.h
- private string tname; // name in internal form
- private string nspace; // namespace in internal form
- private Type parent;
- private Type nesting_type;
- internal Type[] interfaces;
- internal int num_methods;
- internal MethodBuilder[] methods;
- internal ConstructorBuilder[] ctors;
- internal PropertyBuilder[] properties;
- internal int num_fields;
- internal FieldBuilder[] fields;
- internal EventBuilder[] events;
- private CustomAttributeBuilder[] cattrs;
- internal TypeBuilder[] subtypes;
- internal TypeAttributes attrs;
- private int table_idx;
- private ModuleBuilder pmodule;
- private int class_size;
- private PackingSize packing_size;
- private IntPtr generic_container;
- private GenericTypeParameterBuilder[] generic_params;
- private object permissions;
- private TypeInfo created;
- private int state;
- #endregion
-#pragma warning restore 169
-
- TypeName fullname;
- bool createTypeCalled;
- private Type underlying_type;
-
- public const int UnspecifiedTypeSize = 0;
-
- protected override TypeAttributes GetAttributeFlagsImpl ()
- {
- return attrs;
- }
-
- internal TypeBuilder (ModuleBuilder mb, TypeAttributes attr, int table_idx)
- {
- this.parent = null;
- this.attrs = attr;
- this.class_size = UnspecifiedTypeSize;
- this.table_idx = table_idx;
- this.tname = table_idx == 1 ? "<Module>" : "type_" + table_idx.ToString ();
- this.nspace = String.Empty;
- this.fullname = TypeIdentifiers.WithoutEscape(this.tname);
- pmodule = mb;
- }
-
- internal TypeBuilder (ModuleBuilder mb, string name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packing_size, int type_size, Type nesting_type)
- {
- int sep_index;
- this.parent = ResolveUserType (parent);
- this.attrs = attr;
- this.class_size = type_size;
- this.packing_size = packing_size;
- this.nesting_type = nesting_type;
-
- check_name ("fullname", name);
-
- if (parent == null && (attr & TypeAttributes.Interface) != 0 && (attr & TypeAttributes.Abstract) == 0)
- throw new InvalidOperationException ("Interface must be declared abstract.");
-
- sep_index = name.LastIndexOf('.');
- if (sep_index != -1) {
- this.tname = name.Substring (sep_index + 1);
- this.nspace = name.Substring (0, sep_index);
- } else {
- this.tname = name;
- this.nspace = String.Empty;
- }
- if (interfaces != null) {
- this.interfaces = new Type[interfaces.Length];
- System.Array.Copy (interfaces, this.interfaces, interfaces.Length);
- }
- pmodule = mb;
-
- if (((attr & TypeAttributes.Interface) == 0) && (parent == null))
- this.parent = typeof (object);
-
- // skip .<Module> ?
- table_idx = mb.get_next_table_index (this, 0x02, 1);
- fullname = GetFullName ();
- }
-
- public override Assembly Assembly {
- get {return pmodule.Assembly;}
- }
-
- public override string AssemblyQualifiedName {
- get {
- return fullname.DisplayName + ", " + Assembly.FullName;
- }
- }
-
- public override Type BaseType {
- get {
- return parent;
- }
- }
-
- public override Type DeclaringType {
- get { return nesting_type; }
- }
-
- [ComVisible (true)]
- public override bool IsSubclassOf (Type c)
- {
- Type t;
- if (c == null)
- return false;
- if (c == this)
- return false;
- t = parent;
- while (t != null) {
- if (c == t)
- return true;
- t = t.BaseType;
- }
- return false;
- }
-
- public override Type UnderlyingSystemType {
- get {
- if (is_created)
- return created.UnderlyingSystemType;
-
- if (IsEnum) {
- if (underlying_type != null)
- return underlying_type;
- throw new InvalidOperationException (
- "Enumeration type is not defined.");
- }
-
- return this;
- }
- }
-
- TypeName GetFullName ()
- {
- TypeIdentifier ident = TypeIdentifiers.FromInternal (tname);
- if (nesting_type != null)
- return TypeNames.FromDisplay (nesting_type.FullName).NestedName (ident);
- if ((nspace != null) && (nspace.Length > 0))
- return TypeIdentifiers.FromInternal (nspace, ident);
- return ident;
- }
-
- public override string FullName {
- get {
- return fullname.DisplayName;
- }
- }
-
- public override Guid GUID {
- get {
- check_created ();
- return created.GUID;
- }
- }
-
- public override Module Module {
- get {return pmodule;}
- }
-
- public override string Name {
- get {return tname;}
- }
-
- public override string Namespace {
- get {return nspace;}
- }
-
- public PackingSize PackingSize {
- get {return packing_size;}
- }
-
- public int Size {
- get { return class_size; }
- }
-
- public override Type ReflectedType {
- get { return nesting_type; }
- }
-
- [ComVisible (true)]
- public void AddInterfaceImplementation (Type interfaceType)
- {
- if (interfaceType == null)
- throw new ArgumentNullException ("interfaceType");
- if (interfaceType.IsByRef)
- throw new ArgumentException (nameof (interfaceType));
- check_not_created ();
-
- if (interfaces != null) {
- // Check for duplicates
- foreach (Type t in interfaces)
- if (t == interfaceType)
- return;
-
- Type[] ifnew = new Type [interfaces.Length + 1];
- interfaces.CopyTo (ifnew, 0);
- ifnew [interfaces.Length] = interfaceType;
- interfaces = ifnew;
- } else {
- interfaces = new Type [1];
- interfaces [0] = interfaceType;
- }
- }
-
- protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr, Binder binder,
- CallingConventions callConvention, Type[] types,
- ParameterModifier[] modifiers)
- {
- check_created ();
-
- if (created == typeof (object)) {
- /*
- * This happens when building corlib. Calling created.GetConstructor
- * would return constructors from the real mscorlib, instead of the
- * newly built one.
- */
-
- if (ctors == null)
- return null;
-
- ConstructorBuilder found = null;
- int count = 0;
-
- foreach (ConstructorBuilder cb in ctors) {
- if (callConvention != CallingConventions.Any && cb.CallingConvention != callConvention)
- continue;
- found = cb;
- count++;
- }
-
- if (count == 0)
- return null;
- if (types == null) {
- if (count > 1)
- throw new AmbiguousMatchException ();
- return found;
- }
- MethodBase[] match = new MethodBase [count];
- if (count == 1)
- match [0] = found;
- else {
- count = 0;
- foreach (ConstructorInfo m in ctors) {
- if (callConvention != CallingConventions.Any && m.CallingConvention != callConvention)
- continue;
- match [count++] = m;
- }
- }
- if (binder == null)
- binder = DefaultBinder;
- return (ConstructorInfo) binder.SelectMethod (bindingAttr, match,
- types, modifiers);
- }
-
- return created.GetConstructor (bindingAttr, binder,
- callConvention, types, modifiers);
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- if (!is_created)
- throw new NotSupportedException ();
- /*
- * MS throws NotSupported here, but we can't because some corlib
- * classes make calls to IsDefined.
- */
- return CustomAttribute.IsDefined (this, attributeType, inherit);
- }
-
- public override object[] GetCustomAttributes(bool inherit)
- {
- check_created ();
-
- return created.GetCustomAttributes (inherit);
- }
-
- public override object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- check_created ();
-
- return created.GetCustomAttributes (attributeType, inherit);
- }
-
- public TypeBuilder DefineNestedType (string name)
- {
- return DefineNestedType (name, TypeAttributes.NestedPrivate,
- typeof (object), null);
- }
-
- public TypeBuilder DefineNestedType (string name, TypeAttributes attr)
- {
- return DefineNestedType (name, attr, typeof (object), null);
- }
-
- public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent)
- {
- return DefineNestedType (name, attr, parent, null);
- }
-
- private TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, Type[] interfaces,
- PackingSize packSize, int typeSize)
- {
- // Visibility must be NestedXXX
- /* This breaks mcs
- if (((attrs & TypeAttributes.VisibilityMask) == TypeAttributes.Public) ||
- ((attrs & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic))
- throw new ArgumentException ("attr", "Bad type flags for nested type.");
- */
- if (interfaces != null) {
- foreach (Type iface in interfaces) {
- if (iface == null)
- throw new ArgumentNullException ("interfaces");
- if (iface.IsByRef)
- throw new ArgumentException (nameof (interfaces));
- }
- }
-
- TypeBuilder res = new TypeBuilder (pmodule, name, attr, parent, interfaces, packSize, typeSize, this);
- res.fullname = res.GetFullName ();
- pmodule.RegisterTypeName (res, res.fullname);
- if (subtypes != null) {
- TypeBuilder[] new_types = new TypeBuilder [subtypes.Length + 1];
- System.Array.Copy (subtypes, new_types, subtypes.Length);
- new_types [subtypes.Length] = res;
- subtypes = new_types;
- } else {
- subtypes = new TypeBuilder [1];
- subtypes [0] = res;
- }
- return res;
- }
-
- [ComVisible (true)]
- public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, Type[] interfaces)
- {
- return DefineNestedType (name, attr, parent, interfaces, PackingSize.Unspecified, UnspecifiedTypeSize);
- }
-
- public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, int typeSize)
- {
- return DefineNestedType (name, attr, parent, null, PackingSize.Unspecified, typeSize);
- }
-
- public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, PackingSize packSize)
- {
- return DefineNestedType (name, attr, parent, null, packSize, UnspecifiedTypeSize);
- }
-
- public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, PackingSize packSize,
- int typeSize)
- {
- return DefineNestedType (name, attr, parent, null, packSize, typeSize);
- }
-
- [ComVisible (true)]
- public ConstructorBuilder DefineConstructor (MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes)
- {
- return DefineConstructor (attributes, callingConvention, parameterTypes, null, null);
- }
-
- [ComVisible (true)]
- public ConstructorBuilder DefineConstructor (MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)
- {
- check_not_created ();
- if (IsInterface && (attributes & MethodAttributes.Static) == 0)
- throw new InvalidOperationException ();
- ConstructorBuilder cb = new ConstructorBuilder (this, attributes,
- callingConvention, parameterTypes, requiredCustomModifiers,
- optionalCustomModifiers);
- if (ctors != null) {
- ConstructorBuilder[] new_ctors = new ConstructorBuilder [ctors.Length+1];
- System.Array.Copy (ctors, new_ctors, ctors.Length);
- new_ctors [ctors.Length] = cb;
- ctors = new_ctors;
- } else {
- ctors = new ConstructorBuilder [1];
- ctors [0] = cb;
- }
- return cb;
- }
-
- [ComVisible (true)]
- public ConstructorBuilder DefineDefaultConstructor (MethodAttributes attributes)
- {
- Type parent_type, old_parent_type;
-
- if (IsInterface)
- throw new InvalidOperationException ();
- if ((attributes & (MethodAttributes.Static|MethodAttributes.Virtual)) > 0)
- throw new ArgumentException (nameof (attributes));
-
- if (parent != null)
- parent_type = parent;
- else
- parent_type = typeof (object);
-
- old_parent_type = parent_type;
- parent_type = parent_type.InternalResolve ();
- /*This avoids corlib to have self references.*/
- if (parent_type == typeof (object) || parent_type == typeof (ValueType))
- parent_type = old_parent_type;
-
- ConstructorInfo parent_constructor =
- parent_type.GetConstructor (
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
- null, Type.EmptyTypes, null);
- if (parent_constructor == null) {
- throw new NotSupportedException ("Parent does"
- + " not have a default constructor."
- + " The default constructor must be"
- + " explicitly defined.");
- }
-
- ConstructorBuilder cb = DefineConstructor (attributes,
- CallingConventions.Standard, Type.EmptyTypes);
- ILGenerator ig = cb.GetILGenerator ();
- ig.Emit (OpCodes.Ldarg_0);
- ig.Emit (OpCodes.Call, parent_constructor);
- ig.Emit (OpCodes.Ret);
- cb.finished = true;
- return cb;
- }
-
- private void append_method (MethodBuilder mb)
- {
- if (methods != null) {
- if (methods.Length == num_methods) {
- MethodBuilder[] new_methods = new MethodBuilder [methods.Length * 2];
- System.Array.Copy (methods, new_methods, num_methods);
- methods = new_methods;
- }
- } else {
- methods = new MethodBuilder [1];
- }
- methods [num_methods] = mb;
- num_methods ++;
- }
-
- public MethodBuilder DefineMethod (string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes)
- {
- return DefineMethod (name, attributes, CallingConventions.Standard,
- returnType, parameterTypes);
- }
-
- public MethodBuilder DefineMethod (string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
- {
- return DefineMethod (name, attributes, callingConvention, returnType,
- null, null, parameterTypes, null, null);
- }
-
- public MethodBuilder DefineMethod (string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
- {
- check_name ("name", name);
- check_not_created ();
- if (IsInterface && (
- !((attributes & MethodAttributes.Abstract) != 0) ||
- !((attributes & MethodAttributes.Virtual) != 0)) &&
- !(((attributes & MethodAttributes.Static) != 0)))
- throw new ArgumentException ("Interface method must be abstract and virtual.");
-
- if (returnType == null)
- returnType = typeof (void);
- MethodBuilder res = new MethodBuilder (this, name, attributes,
- callingConvention, returnType,
- returnTypeRequiredCustomModifiers,
- returnTypeOptionalCustomModifiers, parameterTypes,
- parameterTypeRequiredCustomModifiers,
- parameterTypeOptionalCustomModifiers);
- append_method (res);
- return res;
- }
-
- public MethodBuilder DefinePInvokeMethod (string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
- {
- return DefinePInvokeMethod (name, dllName, entryName, attributes,
- callingConvention, returnType, null, null, parameterTypes,
- null, null, nativeCallConv, nativeCharSet);
- }
-
- public MethodBuilder DefinePInvokeMethod (
- string name,
- string dllName,
- string entryName, MethodAttributes attributes,
- CallingConventions callingConvention,
- Type returnType,
- Type[] returnTypeRequiredCustomModifiers,
- Type[] returnTypeOptionalCustomModifiers,
- Type[] parameterTypes,
- Type[][] parameterTypeRequiredCustomModifiers,
- Type[][] parameterTypeOptionalCustomModifiers,
- CallingConvention nativeCallConv,
- CharSet nativeCharSet)
- {
- check_name ("name", name);
- check_name ("dllName", dllName);
- check_name ("entryName", entryName);
- if ((attributes & MethodAttributes.Abstract) != 0)
- throw new ArgumentException ("PInvoke methods must be static and native and cannot be abstract.");
- if (IsInterface)
- throw new ArgumentException ("PInvoke methods cannot exist on interfaces.");
- check_not_created ();
-
- MethodBuilder res
- = new MethodBuilder (
- this,
- name,
- attributes,
- callingConvention,
- returnType,
- returnTypeRequiredCustomModifiers,
- returnTypeOptionalCustomModifiers,
- parameterTypes,
- parameterTypeRequiredCustomModifiers,
- parameterTypeOptionalCustomModifiers,
- dllName,
- entryName,
- nativeCallConv,
- nativeCharSet);
- append_method (res);
- return res;
- }
-
- public MethodBuilder DefinePInvokeMethod (string name, string dllName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet) {
- return DefinePInvokeMethod (name, dllName, name, attributes, callingConvention, returnType, parameterTypes,
- nativeCallConv, nativeCharSet);
- }
-
- public MethodBuilder DefineMethod (string name, MethodAttributes attributes)
- {
- return DefineMethod (name, attributes, CallingConventions.Standard);
- }
-
- public MethodBuilder DefineMethod (string name, MethodAttributes attributes, CallingConventions callingConvention)
- {
- return DefineMethod (name, attributes, callingConvention, null, null);
- }
-
- public void DefineMethodOverride (MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration)
- {
- if (methodInfoBody == null)
- throw new ArgumentNullException ("methodInfoBody");
- if (methodInfoDeclaration == null)
- throw new ArgumentNullException ("methodInfoDeclaration");
- check_not_created ();
- if (methodInfoBody.DeclaringType != this)
- throw new ArgumentException ("method body must belong to this type");
-
- if (methodInfoBody is MethodBuilder) {
- MethodBuilder mb = (MethodBuilder)methodInfoBody;
- mb.set_override (methodInfoDeclaration);
- }
- }
-
- public FieldBuilder DefineField (string fieldName, Type type, FieldAttributes attributes)
- {
- return DefineField (fieldName, type, null, null, attributes);
- }
-
- public FieldBuilder DefineField (string fieldName, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes)
- {
- check_name ("fieldName", fieldName);
- if (type == typeof (void))
- throw new ArgumentException ("Bad field type in defining field.");
- check_not_created ();
-
- FieldBuilder res = new FieldBuilder (this, fieldName, type, attributes, requiredCustomModifiers, optionalCustomModifiers);
- if (fields != null) {
- if (fields.Length == num_fields) {
- FieldBuilder[] new_fields = new FieldBuilder [fields.Length * 2];
- System.Array.Copy (fields, new_fields, num_fields);
- fields = new_fields;
- }
- fields [num_fields] = res;
- num_fields ++;
- } else {
- fields = new FieldBuilder [1];
- fields [0] = res;
- num_fields ++;
- }
-
- if (IsEnum) {
- if (underlying_type == null && (attributes & FieldAttributes.Static) == 0)
- underlying_type = type;
- }
-
- return res;
- }
-
- public PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes)
- {
- return DefineProperty (name, attributes, 0, returnType, null, null, parameterTypes, null, null);
- }
-
- public PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
- {
- return DefineProperty (name, attributes, callingConvention, returnType , null, null, parameterTypes, null, null);
- }
-
- public PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
- {
- return DefineProperty (name, attributes, 0, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
- }
-
- public PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
- {
- check_name ("name", name);
- if (parameterTypes != null)
- foreach (Type param in parameterTypes)
- if (param == null)
- throw new ArgumentNullException ("parameterTypes");
- check_not_created ();
-
- PropertyBuilder res = new PropertyBuilder (this, name, attributes, callingConvention, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
-
- if (properties != null) {
- Array.Resize (ref properties, properties.Length + 1);
- properties [properties.Length - 1] = res;
- } else {
- properties = new PropertyBuilder [1] { res };
- }
- return res;
- }
-
- [ComVisible (true)]
- public ConstructorBuilder DefineTypeInitializer()
- {
- return DefineConstructor (MethodAttributes.Public |
- MethodAttributes.Static | MethodAttributes.SpecialName |
- MethodAttributes.RTSpecialName, CallingConventions.Standard,
- null);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private extern TypeInfo create_runtime_class ();
-
- private bool is_nested_in (Type t)
- {
- while (t != null) {
- if (t == this)
- return true;
- else
- t = t.DeclaringType;
- }
- return false;
- }
-
- // Return whenever this type has a ctor defined using DefineMethod ()
- private bool has_ctor_method () {
- MethodAttributes ctor_attrs = MethodAttributes.SpecialName | MethodAttributes.RTSpecialName;
-
- for (int i = 0; i < num_methods; ++i) {
- MethodBuilder mb = (MethodBuilder)(methods[i]);
-
- if (mb.Name == ConstructorInfo.ConstructorName && (mb.Attributes & ctor_attrs) == ctor_attrs)
- return true;
- }
-
- return false;
- }
-
- public Type CreateType ()
- {
- return CreateTypeInfo ();
- }
-
- public
- TypeInfo CreateTypeInfo ()
- {
- /* handle nesting_type */
- if (createTypeCalled)
- return created;
-
- if (!IsInterface && (parent == null) && (this != typeof (object)) && (FullName != "<Module>")) {
- SetParent (typeof (object));
- }
-
- // Fire TypeResolve events for fields whose type is an unfinished
- // value type.
- if (fields != null) {
- foreach (FieldBuilder fb in fields) {
- if (fb == null)
- continue;
- Type ft = fb.FieldType;
- if (!fb.IsStatic && (ft is TypeBuilder) && ft.IsValueType && (ft != this) && is_nested_in (ft)) {
- TypeBuilder tb = (TypeBuilder)ft;
- if (!tb.is_created) {
- throw new NotImplementedException ();
- }
- }
- }
- }
-
- if (parent != null) {
- if (parent.IsByRef)
- throw new ArgumentException ();
- if (IsInterface)
- throw new TypeLoadException ();
- }
-
- //
- // On classes, define a default constructor if not provided
- //
- if (!(IsInterface || IsValueType) && (ctors == null) && (tname != "<Module>") &&
- (GetAttributeFlagsImpl () & TypeAttributes.Abstract | TypeAttributes.Sealed) != (TypeAttributes.Abstract | TypeAttributes.Sealed) && !has_ctor_method ())
- DefineDefaultConstructor (MethodAttributes.Public);
-
- createTypeCalled = true;
-
- if (parent != null) {
- if (parent.IsSealed)
- throw new TypeLoadException ("Could not load type '" + FullName + "' from assembly '" + Assembly + "' because the parent type is sealed.");
- if (parent.IsGenericTypeDefinition)
- throw new BadImageFormatException ();
- }
-
- if (parent == typeof (Enum) && methods != null)
- throw new TypeLoadException ("Could not load type '" + FullName + "' from assembly '" + Assembly + "' because it is an enum with methods.");
- if (interfaces != null) {
- foreach (var iface in interfaces) {
- if (iface.IsNestedPrivate && iface.Assembly != Assembly)
- throw new TypeLoadException ("Could not load type '" + FullName + "' from assembly '" + Assembly + "' because it is implements the inaccessible interface '" + iface.FullName + "'.");
- if (iface.IsGenericTypeDefinition)
- throw new BadImageFormatException ();
- if (!iface.IsInterface)
- throw new TypeLoadException ();
- if (iface is TypeBuilder && !((TypeBuilder)iface).is_created)
- throw new TypeLoadException ();
- }
- }
-
- if (fields != null) {
- foreach (FieldBuilder fb in fields) {
- if (fb == null)
- continue;
- if (fb.FieldType.IsByRef)
- throw new COMException ();
- }
- }
-
- if (methods != null) {
- bool is_concrete = !IsAbstract;
- for (int i = 0; i < num_methods; ++i) {
- MethodBuilder mb = (MethodBuilder)(methods[i]);
- if (is_concrete && mb.IsAbstract)
- throw new InvalidOperationException ("Type is concrete but has abstract method " + mb);
- mb.check_override ();
- mb.fixup ();
- }
- }
-
- if (ctors != null){
- foreach (ConstructorBuilder ctor in ctors)
- ctor.fixup ();
- }
-
- ResolveUserTypes ();
-
- created = create_runtime_class ();
- if (created != null)
- return created;
- return this;
- }
-
- void ResolveUserTypes () {
- parent = ResolveUserType (parent);
- ResolveUserTypes (interfaces);
- if (fields != null) {
- foreach (var fb in fields) {
- if (fb != null)
- fb.ResolveUserTypes ();
- }
- }
- if (methods != null) {
- foreach (var mb in methods) {
- if (mb != null)
- mb.ResolveUserTypes ();
- }
- }
- if (ctors != null) {
- foreach (var cb in ctors) {
- if (cb != null)
- cb.ResolveUserTypes ();
- }
- }
- }
-
- static internal void ResolveUserTypes (Type[] types) {
- if (types != null)
- for (int i = 0; i < types.Length; ++i)
- types [i] = ResolveUserType (types [i]);
- }
-
- static internal Type ResolveUserType (Type t) {
- if (t != null && ((t.GetType ().Assembly != typeof (int).Assembly) || (t is TypeDelegator))) {
- t = t.UnderlyingSystemType;
- if (t != null && ((t.GetType ().Assembly != typeof (int).Assembly) || (t is TypeDelegator)))
- throw new NotSupportedException ("User defined subclasses of System.Type are not yet supported.");
- return t;
- } else {
- return t;
- }
- }
-/*
- internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
- {
- symbolWriter.OpenNamespace (this.Namespace);
-
- if (methods != null) {
- for (int i = 0; i < num_methods; ++i) {
- MethodBuilder metb = (MethodBuilder) methods[i];
- metb.GenerateDebugInfo (symbolWriter);
- }
- }
-
- if (ctors != null) {
- foreach (ConstructorBuilder ctor in ctors)
- ctor.GenerateDebugInfo (symbolWriter);
- }
-
- symbolWriter.CloseNamespace ();
-
- if (subtypes != null) {
- for (int i = 0; i < subtypes.Length; ++i)
- subtypes [i].GenerateDebugInfo (symbolWriter);
- }
- }
-*/
- [ComVisible (true)]
- public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
- {
- if (is_created)
- return created.GetConstructors (bindingAttr);
-
- throw new NotSupportedException ();
- }
-
- internal ConstructorInfo[] GetConstructorsInternal (BindingFlags bindingAttr)
- {
- if (ctors == null)
- return new ConstructorInfo [0];
- ArrayList l = new ArrayList ();
- bool match;
- MethodAttributes mattrs;
-
- foreach (ConstructorBuilder c in ctors) {
- match = false;
- mattrs = c.Attributes;
- if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
- if ((bindingAttr & BindingFlags.Public) != 0)
- match = true;
- } else {
- if ((bindingAttr & BindingFlags.NonPublic) != 0)
- match = true;
- }
- if (!match)
- continue;
- match = false;
- if ((mattrs & MethodAttributes.Static) != 0) {
- if ((bindingAttr & BindingFlags.Static) != 0)
- match = true;
- } else {
- if ((bindingAttr & BindingFlags.Instance) != 0)
- match = true;
- }
- if (!match)
- continue;
- l.Add (c);
- }
- ConstructorInfo[] result = new ConstructorInfo [l.Count];
- l.CopyTo (result);
- return result;
- }
-
- public override Type GetElementType ()
- {
- throw new NotSupportedException ();
- }
-
- public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
- {
- check_created ();
- return created.GetEvent (name, bindingAttr);
- }
-
- /* Needed to keep signature compatibility with MS.NET */
- public override EventInfo[] GetEvents ()
- {
- const BindingFlags DefaultBindingFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
- return GetEvents (DefaultBindingFlags);
- }
-
- public override EventInfo[] GetEvents (BindingFlags bindingAttr)
- {
- if (is_created)
- return created.GetEvents (bindingAttr);
- throw new NotSupportedException ();
- }
-
- public override FieldInfo GetField (string name, BindingFlags bindingAttr)
- {
- check_created ();
- return created.GetField (name, bindingAttr);
- }
-
- public override FieldInfo[] GetFields (BindingFlags bindingAttr)
- {
- check_created ();
- return created.GetFields (bindingAttr);
- }
-
- public override Type GetInterface (string name, bool ignoreCase)
- {
- check_created ();
- return created.GetInterface (name, ignoreCase);
- }
-
- public override Type[] GetInterfaces ()
- {
- if (is_created)
- return created.GetInterfaces ();
-
- if (interfaces != null) {
- Type[] ret = new Type [interfaces.Length];
- interfaces.CopyTo (ret, 0);
- return ret;
- } else {
- return Type.EmptyTypes;
- }
- }
-
- public override MemberInfo[] GetMember (string name, MemberTypes type,
- BindingFlags bindingAttr)
- {
- check_created ();
- return created.GetMember (name, type, bindingAttr);
- }
-
- public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
- {
- check_created ();
- return created.GetMembers (bindingAttr);
- }
-
- private MethodInfo[] GetMethodsByName (string name, BindingFlags bindingAttr, bool ignoreCase, Type reflected_type)
- {
- MethodInfo[] candidates;
- bool match;
- MethodAttributes mattrs;
-
- if (((bindingAttr & BindingFlags.DeclaredOnly) == 0) && (parent != null)) {
- MethodInfo [] parent_methods = parent.GetMethods (bindingAttr);
- ArrayList parent_candidates = new ArrayList (parent_methods.Length);
-
- bool flatten = (bindingAttr & BindingFlags.FlattenHierarchy) != 0;
-
- for (int i = 0; i < parent_methods.Length; i++) {
- MethodInfo m = parent_methods [i];
-
- mattrs = m.Attributes;
-
- if (m.IsStatic && !flatten)
- continue;
-
- switch (mattrs & MethodAttributes.MemberAccessMask) {
- case MethodAttributes.Public:
- match = (bindingAttr & BindingFlags.Public) != 0;
- break;
- case MethodAttributes.Assembly:
- match = (bindingAttr & BindingFlags.NonPublic) != 0;
- break;
- case MethodAttributes.Private:
- match = false;
- break;
- default:
- match = (bindingAttr & BindingFlags.NonPublic) != 0;
- break;
- }
-
- if (match)
- parent_candidates.Add (m);
- }
-
- if (methods == null) {
- candidates = new MethodInfo [parent_candidates.Count];
- parent_candidates.CopyTo (candidates);
- } else {
- candidates = new MethodInfo [methods.Length + parent_candidates.Count];
- parent_candidates.CopyTo (candidates, 0);
- methods.CopyTo (candidates, parent_candidates.Count);
- }
- }
- else
- candidates = methods;
-
- if (candidates == null)
- return new MethodInfo [0];
-
- ArrayList l = new ArrayList ();
-
- foreach (MethodInfo c in candidates) {
- if (c == null)
- continue;
- if (name != null) {
- if (String.Compare (c.Name, name, ignoreCase) != 0)
- continue;
- }
- match = false;
- mattrs = c.Attributes;
- if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
- if ((bindingAttr & BindingFlags.Public) != 0)
- match = true;
- } else {
- if ((bindingAttr & BindingFlags.NonPublic) != 0)
- match = true;
- }
- if (!match)
- continue;
- match = false;
- if ((mattrs & MethodAttributes.Static) != 0) {
- if ((bindingAttr & BindingFlags.Static) != 0)
- match = true;
- } else {
- if ((bindingAttr & BindingFlags.Instance) != 0)
- match = true;
- }
- if (!match)
- continue;
- l.Add (c);
- }
-
- MethodInfo[] result = new MethodInfo [l.Count];
- l.CopyTo (result);
- return result;
- }
-
- public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
- {
- check_created ();
-
- return GetMethodsByName (null, bindingAttr, false, this);
- }
-
- protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
- Binder binder,
- CallingConventions callConvention,
- Type[] types, ParameterModifier[] modifiers)
- {
- check_created ();
-
- if (types == null)
- return created.GetMethod (name, bindingAttr);
-
- return created.GetMethod (name, bindingAttr, binder, callConvention, types, modifiers);
- }
-
- public override Type GetNestedType (string name, BindingFlags bindingAttr)
- {
- check_created ();
-
- if (subtypes == null)
- return null;
-
- foreach (TypeBuilder t in subtypes) {
- if (!t.is_created)
- continue;
- if ((t.attrs & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic) {
- if ((bindingAttr & BindingFlags.Public) == 0)
- continue;
- } else {
- if ((bindingAttr & BindingFlags.NonPublic) == 0)
- continue;
- }
- if (t.Name == name)
- return t.created;
- }
-
- return null;
- }
-
- public override Type[] GetNestedTypes (BindingFlags bindingAttr)
- {
- if (!is_created)
- throw new NotSupportedException ();
-
- bool match;
- ArrayList result = new ArrayList ();
-
- if (subtypes == null)
- return Type.EmptyTypes;
- foreach (TypeBuilder t in subtypes) {
- match = false;
- if ((t.attrs & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic) {
- if ((bindingAttr & BindingFlags.Public) != 0)
- match = true;
- } else {
- if ((bindingAttr & BindingFlags.NonPublic) != 0)
- match = true;
- }
- if (!match)
- continue;
- result.Add (t);
- }
- Type[] r = new Type [result.Count];
- result.CopyTo (r);
- return r;
- }
-
- public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
- {
- check_created ();
- return created.GetProperties (bindingAttr);
- }
-
- protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
- {
- throw not_supported ();
- }
-
- protected override bool HasElementTypeImpl ()
- {
- // a TypeBuilder can never represent an array, pointer
- if (!is_created)
- return false;
-
- return created.HasElementType;
- }
-
- public override object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
- {
- check_created ();
- return created.InvokeMember (name, invokeAttr, binder, target, args, modifiers, culture, namedParameters);
- }
-
- protected override bool IsArrayImpl ()
- {
- return false; /*A TypeBuilder never represents a non typedef type.*/
- }
-
- protected override bool IsByRefImpl ()
- {
- return false; /*A TypeBuilder never represents a non typedef type.*/
- }
-
- protected override bool IsCOMObjectImpl ()
- {
- return ((GetAttributeFlagsImpl () & TypeAttributes.Import) != 0);
- }
-
- protected override bool IsPointerImpl ()
- {
- return false; /*A TypeBuilder never represents a non typedef type.*/
- }
-
- protected override bool IsPrimitiveImpl ()
- {
- // FIXME
- return false;
- }
-
- // FIXME: I doubt just removing this still works.
- protected override bool IsValueTypeImpl ()
- {
- Type parent_type = parent;
- while (parent_type != null) {
- if (parent_type == typeof (ValueType))
- return true;
- parent_type = parent_type.BaseType;
- }
- return false;
- }
-
- public override bool IsSZArray {
- get {
- return false;
- }
- }
-
- public override Type MakeArrayType ()
- {
- return new ArrayType (this, 0);
- }
-
- public override Type MakeArrayType (int rank)
- {
- if (rank < 1)
- throw new IndexOutOfRangeException ();
- return new ArrayType (this, rank);
- }
-
- public override Type MakeByRefType ()
- {
- return new ByRefType (this);
- }
-
- public override Type MakeGenericType (params Type [] typeArguments)
- {
- //return base.MakeGenericType (typeArguments);
-
- if (!IsGenericTypeDefinition)
- throw new InvalidOperationException ("not a generic type definition");
- if (typeArguments == null)
- throw new ArgumentNullException ("typeArguments");
-
- if (generic_params.Length != typeArguments.Length)
- throw new ArgumentException (String.Format ("The type or method has {0} generic parameter(s) but {1} generic argument(s) where provided. A generic argument must be provided for each generic parameter.", generic_params.Length, typeArguments.Length), "typeArguments");
-
- foreach (Type t in typeArguments) {
- if (t == null)
- throw new ArgumentNullException ("typeArguments");
- }
-
- Type[] copy = new Type [typeArguments.Length];
- typeArguments.CopyTo (copy, 0);
- return pmodule.assemblyb.MakeGenericType (this, copy);
- }
-
- public override Type MakePointerType ()
- {
- return new PointerType (this);
- }
-
- public override RuntimeTypeHandle TypeHandle {
- get {
- check_created ();
- return created.TypeHandle;
- }
- }
-
- public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
- {
- if (customBuilder == null)
- throw new ArgumentNullException ("customBuilder");
-
- string attrname = customBuilder.Ctor.ReflectedType.FullName;
- if (attrname == "System.Runtime.InteropServices.StructLayoutAttribute") {
- byte[] data = customBuilder.Data;
- int layout_kind; /* the (stupid) ctor takes a short or an int ... */
- layout_kind = (int)data [2];
- layout_kind |= ((int)data [3]) << 8;
- attrs &= ~TypeAttributes.LayoutMask;
- switch ((LayoutKind)layout_kind) {
- case LayoutKind.Auto:
- attrs |= TypeAttributes.AutoLayout;
- break;
- case LayoutKind.Explicit:
- attrs |= TypeAttributes.ExplicitLayout;
- break;
- case LayoutKind.Sequential:
- attrs |= TypeAttributes.SequentialLayout;
- break;
- default:
- // we should ignore it since it can be any value anyway...
- throw new Exception ("Error in customattr");
- }
-
- var ctor_type = customBuilder.Ctor is ConstructorBuilder ? ((ConstructorBuilder)customBuilder.Ctor).parameters[0] : customBuilder.Ctor.GetParametersInternal()[0].ParameterType;
- int pos = 6;
- if (ctor_type.FullName == "System.Int16")
- pos = 4;
- int nnamed = (int)data [pos++];
- nnamed |= ((int)data [pos++]) << 8;
- for (int i = 0; i < nnamed; ++i) {
- //byte named_type = data [pos++];
- pos ++;
- byte type = data [pos++];
- int len;
- string named_name;
-
- if (type == 0x55) {
- len = CustomAttributeBuilder.decode_len (data, pos, out pos);
- //string named_typename =
- CustomAttributeBuilder.string_from_bytes (data, pos, len);
- pos += len;
- // FIXME: Check that 'named_type' and 'named_typename' match, etc.
- // See related code/FIXME in mono/mono/metadata/reflection.c
- }
-
- len = CustomAttributeBuilder.decode_len (data, pos, out pos);
- named_name = CustomAttributeBuilder.string_from_bytes (data, pos, len);
- pos += len;
- /* all the fields are integers in StructLayout */
- int value = (int)data [pos++];
- value |= ((int)data [pos++]) << 8;
- value |= ((int)data [pos++]) << 16;
- value |= ((int)data [pos++]) << 24;
- switch (named_name) {
- case "CharSet":
- switch ((CharSet)value) {
- case CharSet.None:
- case CharSet.Ansi:
- attrs &= ~(TypeAttributes.UnicodeClass | TypeAttributes.AutoClass);
- break;
- case CharSet.Unicode:
- attrs &= ~TypeAttributes.AutoClass;
- attrs |= TypeAttributes.UnicodeClass;
- break;
- case CharSet.Auto:
- attrs &= ~TypeAttributes.UnicodeClass;
- attrs |= TypeAttributes.AutoClass;
- break;
- default:
- break; // error out...
- }
- break;
- case "Pack":
- packing_size = (PackingSize)value;
- break;
- case "Size":
- class_size = value;
- break;
- default:
- break; // error out...
- }
- }
- return;
- } else if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
- attrs |= TypeAttributes.SpecialName;
- return;
- } else if (attrname == "System.SerializableAttribute") {
- attrs |= TypeAttributes.Serializable;
- return;
- } else if (attrname == "System.Runtime.InteropServices.ComImportAttribute") {
- attrs |= TypeAttributes.Import;
- return;
- } else if (attrname == "System.Security.SuppressUnmanagedCodeSecurityAttribute") {
- attrs |= TypeAttributes.HasSecurity;
- }
-
- if (cattrs != null) {
- CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
- cattrs.CopyTo (new_array, 0);
- new_array [cattrs.Length] = customBuilder;
- cattrs = new_array;
- } else {
- cattrs = new CustomAttributeBuilder [1];
- cattrs [0] = customBuilder;
- }
- }
-
- [ComVisible (true)]
- public void SetCustomAttribute (ConstructorInfo con, byte[] binaryAttribute)
- {
- SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
- }
-
- public EventBuilder DefineEvent (string name, EventAttributes attributes, Type eventtype)
- {
- check_name ("name", name);
- if (eventtype == null)
- throw new ArgumentNullException ("type");
- check_not_created ();
- if (eventtype.IsByRef)
- throw new ArgumentException (nameof (eventtype));
- EventBuilder res = new EventBuilder (this, name, attributes, eventtype);
- if (events != null) {
- EventBuilder[] new_events = new EventBuilder [events.Length+1];
- System.Array.Copy (events, new_events, events.Length);
- new_events [events.Length] = res;
- events = new_events;
- } else {
- events = new EventBuilder [1];
- events [0] = res;
- }
- return res;
- }
-
- public FieldBuilder DefineInitializedData (string name, byte[] data, FieldAttributes attributes) {
- if (data == null)
- throw new ArgumentNullException ("data");
-
- FieldBuilder res = DefineUninitializedData (name, data.Length, attributes);
- res.SetRVAData (data);
- return res;
- }
-
- public FieldBuilder DefineUninitializedData (string name, int size, FieldAttributes attributes)
- {
- if (name == null)
- throw new ArgumentNullException ("name");
- if (name.Length == 0)
- throw new ArgumentException ("Empty name is not legal", "name");
- if ((size <= 0) || (size > 0x3f0000))
- throw new ArgumentException ("Data size must be > 0 and < 0x3f0000");
- check_not_created ();
-
- string typeName = "$ArrayType$" + size;
- TypeIdentifier ident = TypeIdentifiers.WithoutEscape (typeName);
- Type datablobtype = pmodule.GetRegisteredType (fullname.NestedName(ident));
- if (datablobtype == null) {
- TypeBuilder tb = DefineNestedType (typeName,
- TypeAttributes.NestedPrivate|TypeAttributes.ExplicitLayout|TypeAttributes.Sealed,
- typeof (ValueType), null, PackingSize.Size1, size);
- tb.CreateType ();
- datablobtype = tb;
- }
- return DefineField (name, datablobtype, attributes|FieldAttributes.Static|FieldAttributes.HasFieldRVA);
- }
-
- public TypeToken TypeToken {
- get {
- return new TypeToken (0x02000000 | table_idx);
- }
- }
-
- public void SetParent (Type parent)
- {
- check_not_created ();
-
- if (parent == null) {
- if ((attrs & TypeAttributes.Interface) != 0) {
- if ((attrs & TypeAttributes.Abstract) == 0)
- throw new InvalidOperationException ("Interface must be declared abstract.");
- this.parent = null;
- } else {
- this.parent = typeof (object);
- }
- } else {
- if (parent.IsInterface)
- throw new ArgumentException (nameof (parent));
- this.parent = parent;
- }
- this.parent = ResolveUserType (this.parent);
- }
-
- internal int get_next_table_index (object obj, int table, int count) {
- return pmodule.get_next_table_index (obj, table, count);
- }
-
- [ComVisible (true)]
- public override InterfaceMapping GetInterfaceMap (Type interfaceType)
- {
- if (created == null)
- throw new NotSupportedException ("This method is not implemented for incomplete types.");
-
- return created.GetInterfaceMap (interfaceType);
- }
-
- internal override Type InternalResolve ()
- {
- check_created ();
- return created;
- }
-
- internal override Type RuntimeResolve ()
- {
- check_created ();
- return created;
- }
-
- internal bool is_created {
- get {
- return createTypeCalled;
- }
- }
-
- private Exception not_supported ()
- {
- return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
- }
-
- internal void check_not_created ()
- {
- if (is_created)
- throw new InvalidOperationException ("Unable to change after type has been created.");
- }
-
- private void check_created ()
- {
- if (!is_created)
- throw not_supported ();
- }
-
- private void check_name (string argName, string name)
- {
- if (name == null)
- throw new ArgumentNullException (argName);
- if (name.Length == 0)
- throw new ArgumentException ("Empty name is not legal", argName);
- if (name [0] == ((char)0))
- throw new ArgumentException ("Illegal name", argName);
- }
-
- public override String ToString ()
- {
- return FullName;
- }
-
- // FIXME:
- public override bool IsAssignableFrom (Type c)
- {
- return base.IsAssignableFrom (c);
- }
-
- // FIXME: "arrays"
- internal bool IsAssignableTo (Type c)
- {
- if (c == this)
- return true;
-
- if (c.IsInterface) {
- if (parent != null && is_created) {
- if (c.IsAssignableFrom (parent))
- return true;
- }
-
- if (interfaces == null)
- return false;
- foreach (Type t in interfaces)
- if (c.IsAssignableFrom (t))
- return true;
- if (!is_created)
- return false;
- }
-
- if (parent == null)
- return c == typeof (object);
- else
- return c.IsAssignableFrom (parent);
- }
-
- public bool IsCreated ()
- {
- return is_created;
- }
-
- public override Type[] GetGenericArguments ()
- {
- if (generic_params == null)
- return null;
- Type[] args = new Type [generic_params.Length];
- generic_params.CopyTo (args, 0);
- return args;
- }
-
- public override Type GetGenericTypeDefinition ()
- {
- if (generic_params == null)
- throw new InvalidOperationException ("Type is not generic");
- return this;
- }
-
- public override bool ContainsGenericParameters {
- get {
- return generic_params != null;
- }
- }
-
- public override bool IsGenericParameter {
- get {
- return false;
- }
- }
-
- public override GenericParameterAttributes GenericParameterAttributes {
- get { return GenericParameterAttributes.None; }
- }
-
- public override bool IsGenericTypeDefinition {
- get {
- return generic_params != null;
- }
- }
-
- public override bool IsGenericType {
- get { return IsGenericTypeDefinition; }
- }
-
- // FIXME:
- public override int GenericParameterPosition {
- get {
- return 0;
- }
- }
-
- public override MethodBase DeclaringMethod {
- get {
- return null;
- }
- }
-
- public GenericTypeParameterBuilder[] DefineGenericParameters (params string[] names)
- {
- if (names == null)
- throw new ArgumentNullException ("names");
- if (names.Length == 0)
- throw new ArgumentException ("names");
-
- generic_params = new GenericTypeParameterBuilder [names.Length];
- for (int i = 0; i < names.Length; i++) {
- string item = names [i];
- if (item == null)
- throw new ArgumentNullException ("names");
- generic_params [i] = new GenericTypeParameterBuilder (this, null, item, i);
- }
-
- return generic_params;
- }
-
- public static ConstructorInfo GetConstructor (Type type, ConstructorInfo constructor)
- {
- /*FIXME I would expect the same checks of GetMethod here*/
- if (type == null)
- throw new ArgumentException ("Type is not generic", "type");
-
- if (!type.IsGenericType)
- throw new ArgumentException ("Type is not a generic type", "type");
-
- if (type.IsGenericTypeDefinition)
- throw new ArgumentException ("Type cannot be a generic type definition", "type");
-
- if (constructor == null)
- throw new NullReferenceException (); //MS raises this instead of an ArgumentNullException
-
- if (!constructor.DeclaringType.IsGenericTypeDefinition)
- throw new ArgumentException ("constructor declaring type is not a generic type definition", "constructor");
- if (constructor.DeclaringType != type.GetGenericTypeDefinition ())
- throw new ArgumentException ("constructor declaring type is not the generic type definition of type", "constructor");
-
- ConstructorInfo res = type.GetConstructor (constructor);
- if (res == null)
- throw new ArgumentException ("constructor not found");
-
- return res;
- }
-
- static bool IsValidGetMethodType (Type type)
- {
- if (type is TypeBuilder || type is TypeBuilderInstantiation)
- return true;
- /*GetMethod() must work with TypeBuilders after CreateType() was called.*/
- if (type.Module is ModuleBuilder)
- return true;
- if (type.IsGenericParameter)
- return false;
-
- Type[] inst = type.GetGenericArguments ();
- if (inst == null)
- return false;
- for (int i = 0; i < inst.Length; ++i) {
- if (IsValidGetMethodType (inst [i]))
- return true;
- }
- return false;
- }
-
- public static MethodInfo GetMethod (Type type, MethodInfo method)
- {
- if (!IsValidGetMethodType (type))
- throw new ArgumentException ("type is not TypeBuilder but " + type.GetType (), "type");
-
- if (type is TypeBuilder && type.ContainsGenericParameters)
- type = type.MakeGenericType (type.GetGenericArguments ());
-
- if (!type.IsGenericType)
- throw new ArgumentException ("type is not a generic type", "type");
-
- if (!method.DeclaringType.IsGenericTypeDefinition)
- throw new ArgumentException ("method declaring type is not a generic type definition", "method");
- if (method.DeclaringType != type.GetGenericTypeDefinition ())
- throw new ArgumentException ("method declaring type is not the generic type definition of type", "method");
- if (method == null)
- throw new NullReferenceException (); //MS raises this instead of an ArgumentNullException
-
- MethodInfo res = type.GetMethod (method);
- if (res == null)
- throw new ArgumentException (String.Format ("method {0} not found in type {1}", method.Name, type));
-
- return res;
- }
-
- public static FieldInfo GetField (Type type, FieldInfo field)
- {
- if (!type.IsGenericType)
- throw new ArgumentException ("Type is not a generic type", "type");
-
- if (type.IsGenericTypeDefinition)
- throw new ArgumentException ("Type cannot be a generic type definition", "type");
-
- if (field is FieldOnTypeBuilderInst)
- throw new ArgumentException ("The specified field must be declared on a generic type definition.", "field");
-
- if (field.DeclaringType != type.GetGenericTypeDefinition ())
- throw new ArgumentException ("field declaring type is not the generic type definition of type", "method");
-
- FieldInfo res = type.GetField (field);
- if (res == null)
- throw new System.Exception ("field not found");
- else
- return res;
- }
-
- internal override bool IsUserType {
- get {
- return false;
- }
- }
-
- internal override bool IsTypeBuilder () => true;
-
- public override bool IsConstructedGenericType {
- get { return false; }
- }
-
- public override bool IsAssignableFrom (TypeInfo typeInfo)
- {
- return base.IsAssignableFrom (typeInfo);
- }
-
- internal static bool SetConstantValue (Type destType, Object value, ref Object destValue)
- {
- // Mono: This is based on the CoreCLR
- // TypeBuilder.SetConstantValue except it writes to an
- // out argument instead of doing an icall, and it uses
- // TypeCode instead of CorElementType (like
- // MonoTypeEnum) which we don't have in our corlib and
- // our member fields are different.
-
- // This is a helper function that is used by ParameterBuilder, PropertyBuilder,
- // and FieldBuilder to validate a default value and save it in the meta-data.
-
- if (value != null) {
- Type type = value.GetType ();
-
- // We should allow setting a constant value on a ByRef parameter
- if (destType.IsByRef)
- destType = destType.GetElementType ();
-
- // Convert nullable types to their underlying type.
- // This is necessary for nullable enum types to pass the IsEnum check that's coming next.
- destType = Nullable.GetUnderlyingType (destType) ?? destType;
-
- if (destType.IsEnum)
- {
- // | UnderlyingSystemType | Enum.GetUnderlyingType() | IsEnum
- // ----------------------------------|---------------------------|---------------------------|---------
- // runtime Enum Type | self | underlying type of enum | TRUE
- // EnumBuilder | underlying type of enum | underlying type of enum* | TRUE
- // TypeBuilder of enum types** | underlying type of enum | Exception | TRUE
- // TypeBuilder of enum types (baked) | runtime enum type | Exception | TRUE
-
- // *: the behavior of Enum.GetUnderlyingType(EnumBuilder) might change in the future
- // so let's not depend on it.
- // **: created with System.Enum as the parent type.
-
- // The above behaviors might not be the most consistent but we have to live with them.
-
- Type underlyingType;
- EnumBuilder enumBldr;
- TypeBuilder typeBldr;
- if ((enumBldr = destType as EnumBuilder) != null) {
- underlyingType = enumBldr.GetEnumUnderlyingType ();
-
- // The constant value supplied should match either the baked enum type or its underlying type
- // we don't need to compare it with the EnumBuilder itself because you can never have an object of that type
- if (!((enumBldr.GetTypeBuilder ().is_created && type == enumBldr.GetTypeBuilder ().created) ||
- type == underlyingType))
- throw_argument_ConstantDoesntMatch ();
- } else if ((typeBldr = destType as TypeBuilder) != null) {
- underlyingType = typeBldr.underlying_type;
-
- // The constant value supplied should match either the baked enum type or its underlying type
- // typeBldr.m_enumUnderlyingType is null if the user hasn't created a "value__" field on the enum
- if (underlyingType == null || (type != typeBldr.UnderlyingSystemType && type != underlyingType))
- throw_argument_ConstantDoesntMatch ();
- } else {
- // must be a runtime Enum Type
-
- // Debug.Assert(destType is RuntimeType, "destType is not a runtime type, an EnumBuilder, or a TypeBuilder.");
-
- underlyingType = Enum.GetUnderlyingType (destType);
-
- // The constant value supplied should match either the enum itself or its underlying type
- if (type != destType && type != underlyingType)
- throw_argument_ConstantDoesntMatch ();
- }
-
- type = underlyingType;
- } else {
- // Note that it is non CLS compliant if destType != type. But RefEmit never guarantees CLS-Compliance.
- if (!destType.IsAssignableFrom (type))
- throw_argument_ConstantDoesntMatch ();
- }
-
- TypeCode corType = Type.GetTypeCode (type);
-
- switch (corType)
- {
- case TypeCode.Byte:
- case TypeCode.SByte:
- case TypeCode.Boolean:
- case TypeCode.Int16:
- case TypeCode.UInt16:
- case TypeCode.Char:
- case TypeCode.Int32:
- case TypeCode.UInt32:
- case TypeCode.Single:
- case TypeCode.Int64:
- case TypeCode.UInt64:
- case TypeCode.Double:
- destValue = value;
- return true;
- case TypeCode.String:
- destValue = value;
- return true;
- case TypeCode.DateTime:
- //date is a I8 representation
- long ticks = ((DateTime)value).Ticks;
- destValue = ticks;
- return true;
- default:
- throw new ArgumentException(type.ToString() + " is not a supported constant type.");
- }
- } else {
- // A null default value in metadata is permissible even for non-nullable value types.
- // (See ECMA-335 II.15.4.1.4 "The .param directive" and II.22.9 "Constant" for details.)
- // This is how the Roslyn compilers generally encode `default(TValueType)` default values.
-
- destValue = null;
- return true;
- }
- }
-
- private static void throw_argument_ConstantDoesntMatch ()
- {
- throw new ArgumentException("Constant does not match the defined type.");
- }
-
- public override bool IsTypeDefinition => true;
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
deleted file mode 100644
index 00b5432b33a..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
+++ /dev/null
@@ -1,512 +0,0 @@
-#nullable disable
-
-//
-// System.Reflection.Emit.TypeBuilderInstantiation
-//
-// Sean MacIsaac (macisaac@ximian.com)
-// Paolo Molaro (lupus@ximian.com)
-// Patrik Torstensson (patrik.torstensson@labs2.com)
-//
-// (C) 2001 Ximian, Inc.
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if MONO_FEATURE_SRE
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Collections;
-using System.Runtime.CompilerServices;
-using System.Globalization;
-using System.Runtime.Serialization;
-using System.Text;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Emit
-{
- /*
- * TypeBuilderInstantiation represents an instantiation of a generic TypeBuilder.
- */
- [StructLayout (LayoutKind.Sequential)]
- sealed class TypeBuilderInstantiation :
- TypeInfo
- {
- #region Keep in sync with object-internals.h MonoReflectionGenericClass
-#pragma warning disable 649
- internal Type generic_type;
- Type[] type_arguments;
-#pragma warning restore 649
- #endregion
-
- Hashtable fields, ctors, methods;
-
- internal TypeBuilderInstantiation ()
- {
- // this should not be used
- throw new InvalidOperationException ();
- }
-
- internal TypeBuilderInstantiation (Type tb, Type[] args)
- {
- this.generic_type = tb;
- this.type_arguments = args;
- }
-
- internal override Type InternalResolve ()
- {
- Type gtd = generic_type.InternalResolve ();
- Type[] args = new Type [type_arguments.Length];
- for (int i = 0; i < type_arguments.Length; ++i)
- args [i] = type_arguments [i].InternalResolve ();
- return gtd.MakeGenericType (args);
- }
-
- // Called from the runtime to return the corresponding finished Type object
- internal override Type RuntimeResolve ()
- {
- if (generic_type is TypeBuilder && !(generic_type as TypeBuilder).IsCreated ())
- throw new NotImplementedException ();
- for (int i = 0; i < type_arguments.Length; ++i) {
- var t = type_arguments [i];
- if (t is TypeBuilder && !(t as TypeBuilder).IsCreated ())
- throw new NotImplementedException ();
- }
- return InternalResolve ();
- }
-
- internal bool IsCreated {
- get {
- TypeBuilder tb = generic_type as TypeBuilder;
- return tb != null ? tb.is_created : true;
- }
- }
-
- private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
- BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
-
- Type GetParentType ()
- {
- return InflateType (generic_type.BaseType);
- }
-
- internal Type InflateType (Type type)
- {
- return InflateType (type, type_arguments, null);
- }
-
- internal Type InflateType (Type type, Type[] method_args)
- {
- return InflateType (type, type_arguments, method_args);
- }
-
- internal static Type InflateType (Type type, Type[] type_args, Type[] method_args)
- {
- if (type == null)
- return null;
- if (!type.IsGenericParameter && !type.ContainsGenericParameters)
- return type;
- if (type.IsGenericParameter) {
- if (type.DeclaringMethod == null)
- return type_args == null ? type : type_args [type.GenericParameterPosition];
- return method_args == null ? type : method_args [type.GenericParameterPosition];
- }
- if (type.IsPointer)
- return InflateType (type.GetElementType (), type_args, method_args).MakePointerType ();
- if (type.IsByRef)
- return InflateType (type.GetElementType (), type_args, method_args).MakeByRefType ();
- if (type.IsArray) {
- if (type.GetArrayRank () > 1)
- return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (type.GetArrayRank ());
-
- if (type.ToString ().EndsWith ("[*]", StringComparison.Ordinal)) /*FIXME, the reflection API doesn't offer a way around this*/
- return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (1);
- return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType ();
- }
-
- Type[] args = type.GetGenericArguments ();
- for (int i = 0; i < args.Length; ++i)
- args [i] = InflateType (args [i], type_args, method_args);
-
- Type gtd = type.IsGenericTypeDefinition ? type : type.GetGenericTypeDefinition ();
- return gtd.MakeGenericType (args);
- }
-
- public override Type BaseType {
- get { return generic_type.BaseType; }
- }
-
- public override Type[] GetInterfaces ()
- {
- throw new NotSupportedException ();
- }
-
- protected override bool IsValueTypeImpl ()
- {
- return generic_type.IsValueType;
- }
-
- internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
- {
- if (methods == null)
- methods = new Hashtable ();
- if (!methods.ContainsKey (fromNoninstanciated))
- methods [fromNoninstanciated] = new MethodOnTypeBuilderInst (this, fromNoninstanciated);
- return (MethodInfo)methods [fromNoninstanciated];
- }
-
- internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
- {
- if (ctors == null)
- ctors = new Hashtable ();
- if (!ctors.ContainsKey (fromNoninstanciated))
- ctors [fromNoninstanciated] = new ConstructorOnTypeBuilderInst (this, fromNoninstanciated);
- return (ConstructorInfo)ctors [fromNoninstanciated];
- }
-
- internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
- {
- if (fields == null)
- fields = new Hashtable ();
- if (!fields.ContainsKey (fromNoninstanciated))
- fields [fromNoninstanciated] = new FieldOnTypeBuilderInst (this, fromNoninstanciated);
- return (FieldInfo)fields [fromNoninstanciated];
- }
-
- public override MethodInfo[] GetMethods (BindingFlags bf)
- {
- throw new NotSupportedException ();
- }
-
- public override ConstructorInfo[] GetConstructors (BindingFlags bf)
- {
- throw new NotSupportedException ();
- }
-
- public override FieldInfo[] GetFields (BindingFlags bf)
- {
- throw new NotSupportedException ();
- }
-
- public override PropertyInfo[] GetProperties (BindingFlags bf)
- {
- throw new NotSupportedException ();
- }
-
- public override EventInfo[] GetEvents (BindingFlags bf)
- {
- throw new NotSupportedException ();
- }
-
- public override Type[] GetNestedTypes (BindingFlags bf)
- {
- throw new NotSupportedException ();
- }
-
- public override bool IsAssignableFrom (Type c)
- {
- throw new NotSupportedException ();
- }
-
- public override Type UnderlyingSystemType {
- get { return this; }
- }
-
- public override Assembly Assembly {
- get { return generic_type.Assembly; }
- }
-
- public override Module Module {
- get { return generic_type.Module; }
- }
-
- public override string Name {
- get { return generic_type.Name; }
- }
-
- public override string Namespace {
- get { return generic_type.Namespace; }
- }
-
- public override string FullName {
- get { return format_name (true, false); }
- }
-
- public override string AssemblyQualifiedName {
- get { return format_name (true, true); }
- }
-
- public override Guid GUID {
- get { throw new NotSupportedException (); }
- }
-
- string format_name (bool full_name, bool assembly_qualified)
- {
- StringBuilder sb = new StringBuilder (generic_type.FullName);
-
- sb.Append ("[");
- for (int i = 0; i < type_arguments.Length; ++i) {
- if (i > 0)
- sb.Append (",");
-
- string name;
- if (full_name) {
- string assemblyName = type_arguments [i].Assembly.FullName;
- name = type_arguments [i].FullName;
- if (name != null && assemblyName != null)
- name = name + ", " + assemblyName;
- } else {
- name = type_arguments [i].ToString ();
- }
- if (name == null) {
- return null;
- }
- if (full_name)
- sb.Append ("[");
- sb.Append (name);
- if (full_name)
- sb.Append ("]");
- }
- sb.Append ("]");
- if (assembly_qualified) {
- sb.Append (", ");
- sb.Append (generic_type.Assembly.FullName);
- }
- return sb.ToString ();
- }
-
- public override string ToString ()
- {
- return format_name (false, false);
- }
-
- public override Type GetGenericTypeDefinition ()
- {
- return generic_type;
- }
-
- public override Type[] GetGenericArguments ()
- {
- Type[] ret = new Type [type_arguments.Length];
- type_arguments.CopyTo (ret, 0);
- return ret;
- }
-
- public override bool ContainsGenericParameters {
- get {
- foreach (Type t in type_arguments) {
- if (t.ContainsGenericParameters)
- return true;
- }
- return false;
- }
- }
-
- public override bool IsGenericTypeDefinition {
- get { return false; }
- }
-
- public override bool IsGenericType {
- get { return true; }
- }
-
- public override Type DeclaringType {
- get { return generic_type.DeclaringType; }
- }
-
- public override RuntimeTypeHandle TypeHandle {
- get {
- throw new NotSupportedException ();
- }
- }
-
- public override Type MakeArrayType ()
- {
- return new ArrayType (this, 0);
- }
-
- public override Type MakeArrayType (int rank)
- {
- if (rank < 1)
- throw new IndexOutOfRangeException ();
- return new ArrayType (this, rank);
- }
-
- public override Type MakeByRefType ()
- {
- return new ByRefType (this);
- }
-
- public override Type MakePointerType ()
- {
- return new PointerType (this);
- }
-
- public override Type GetElementType ()
- {
- throw new NotSupportedException ();
- }
-
- protected override bool HasElementTypeImpl ()
- {
- return false;
- }
-
- protected override bool IsCOMObjectImpl ()
- {
- return false;
- }
-
- protected override bool IsPrimitiveImpl ()
- {
- return false;
- }
-
- protected override bool IsArrayImpl ()
- {
- return false;
- }
-
- protected override bool IsByRefImpl ()
- {
- return false;
- }
-
- protected override bool IsPointerImpl ()
- {
- return false;
- }
-
- protected override TypeAttributes GetAttributeFlagsImpl ()
- {
- return generic_type.Attributes;
- }
-
- //stuff that throws
- public override Type GetInterface (string name, bool ignoreCase)
- {
- throw new NotSupportedException ();
- }
-
- public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
- {
- throw new NotSupportedException ();
- }
-
- public override FieldInfo GetField( string name, BindingFlags bindingAttr)
- {
- throw new NotSupportedException ();
- }
-
- public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
- {
- throw new NotSupportedException ();
- }
-
- public override Type GetNestedType (string name, BindingFlags bindingAttr)
- {
- throw new NotSupportedException ();
- }
-
- public override object InvokeMember (string name, BindingFlags invokeAttr,
- Binder binder, object target, object[] args,
- ParameterModifier[] modifiers,
- CultureInfo culture, string[] namedParameters)
- {
- throw new NotSupportedException ();
- }
-
- protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
- CallingConventions callConvention, Type[] types,
- ParameterModifier[] modifiers)
- {
- throw new NotSupportedException ();
- }
-
- protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
- Type returnType, Type[] types, ParameterModifier[] modifiers)
- {
- throw new NotSupportedException ();
- }
-
- protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
- Binder binder,
- CallingConventions callConvention,
- Type[] types,
- ParameterModifier[] modifiers)
- {
- throw new NotSupportedException ();
- }
-
- //MemberInfo
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- throw new NotSupportedException ();
- }
-
- public override object [] GetCustomAttributes (bool inherit)
- {
- if (IsCreated)
- return generic_type.GetCustomAttributes (inherit);
- throw new NotSupportedException ();
- }
-
- public override object [] GetCustomAttributes (Type attributeType, bool inherit)
- {
- if (IsCreated)
- return generic_type.GetCustomAttributes (attributeType, inherit);
- throw new NotSupportedException ();
- }
-
- internal override bool IsUserType {
- get {
- foreach (var t in type_arguments) {
- if (t.IsUserType)
- return true;
- }
- return false;
- }
- }
-
- internal static Type MakeGenericType (Type type, Type[] typeArguments)
- {
- return new TypeBuilderInstantiation (type, typeArguments);
- }
-
- public override bool IsTypeDefinition => false;
-
- public override bool IsConstructedGenericType => true;
- }
-}
-#else
-namespace System.Reflection.Emit
-{
- abstract class TypeBuilderInstantiation : TypeInfo
- {
- internal static Type MakeGenericType (Type type, Type[] typeArguments)
- {
- throw new NotSupportedException ("User types are not supported under full aot");
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/UnmanagedMarshal.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Emit/UnmanagedMarshal.cs
deleted file mode 100644
index bbe9c3894ed..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Emit/UnmanagedMarshal.cs
+++ /dev/null
@@ -1,138 +0,0 @@
-#nullable disable
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//
-// System.Reflection.Emit/UnmanagedMarshal.cs
-//
-// Author:
-// Paolo Molaro (lupus@ximian.com)
-//
-// (C) 2001-2002 Ximian, Inc. http://www.ximian.com
-//
-
-#if MONO_FEATURE_SRE
-using System.Reflection.Emit;
-using System.Runtime.InteropServices;
-using System;
-
-namespace System.Reflection.Emit {
-
- [Obsolete ("An alternate API is available: Emit the MarshalAs custom attribute instead.")]
- [ComVisible (true)]
- [Serializable]
- [StructLayout (LayoutKind.Sequential)]
- public sealed class UnmanagedMarshal {
-#pragma warning disable 169, 414
- private int count;
- private UnmanagedType t;
- private UnmanagedType tbase;
- string guid;
- string mcookie;
- string marshaltype;
- internal Type marshaltyperef;
- private int param_num;
- private bool has_size;
-#pragma warning restore 169, 414
-
- private UnmanagedMarshal (UnmanagedType maint, int cnt) {
- count = cnt;
- t = maint;
- tbase = maint;
- }
- private UnmanagedMarshal (UnmanagedType maint, UnmanagedType elemt) {
- count = 0;
- t = maint;
- tbase = elemt;
- }
-
- public UnmanagedType BaseType {
- get {
- if (t == UnmanagedType.LPArray)
- throw new ArgumentException ();
-
-#if FEATURE_COMINTEROP
- if (t == UnmanagedType.SafeArray)
- throw new ArgumentException ();
-#endif
- return tbase;
- }
- }
-
- public int ElementCount {
- get {return count;}
- }
-
- public UnmanagedType GetUnmanagedType {
- get {return t;}
- }
-
- public Guid IIDGuid {
- get {return new Guid (guid);}
- }
-
- public static UnmanagedMarshal DefineByValArray( int elemCount) {
- return new UnmanagedMarshal (UnmanagedType.ByValArray, elemCount);
- }
-
- public static UnmanagedMarshal DefineByValTStr( int elemCount) {
- return new UnmanagedMarshal (UnmanagedType.ByValTStr, elemCount);
- }
-
- public static UnmanagedMarshal DefineLPArray( UnmanagedType elemType) {
- return new UnmanagedMarshal (UnmanagedType.LPArray, elemType);
- }
-#if FEATURE_COMINTEROP
- public static UnmanagedMarshal DefineSafeArray( UnmanagedType elemType) {
- return new UnmanagedMarshal (UnmanagedType.SafeArray, elemType);
- }
-#endif
- public static UnmanagedMarshal DefineUnmanagedMarshal( UnmanagedType unmanagedType) {
- return new UnmanagedMarshal (unmanagedType, unmanagedType);
- }
-#if FEATURE_COMINTEROP
- internal static UnmanagedMarshal DefineCustom (Type typeref, string cookie, string mtype, Guid id) {
- UnmanagedMarshal res = new UnmanagedMarshal (UnmanagedType.CustomMarshaler, UnmanagedType.CustomMarshaler);
- res.mcookie = cookie;
- res.marshaltype = mtype;
- res.marshaltyperef = typeref;
- if (id == Guid.Empty)
- res.guid = String.Empty;
- else
- res.guid = id.ToString ();
- return res;
- }
-#endif
- // sizeConst and sizeParamIndex can be -1 meaning they are not specified
- internal static UnmanagedMarshal DefineLPArrayInternal (UnmanagedType elemType, int sizeConst, int sizeParamIndex) {
- UnmanagedMarshal res = new UnmanagedMarshal (UnmanagedType.LPArray, elemType);
- res.count = sizeConst;
- res.param_num = sizeParamIndex;
- res.has_size = true;
-
- return res;
- }
- }
-}
-#endif
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs
deleted file mode 100644
index ae68d8a40da..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs
+++ /dev/null
@@ -1,109 +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 System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection
-{
- partial class FieldInfo
- {
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern FieldInfo internal_from_handle_type (IntPtr field_handle, IntPtr type_handle);
-
- public static FieldInfo GetFieldFromHandle (RuntimeFieldHandle handle)
- {
- if (handle.IsNullHandle ())
- throw new ArgumentException (SR.Argument_InvalidHandle);
- return internal_from_handle_type (handle.Value, IntPtr.Zero);
- }
-
- public static FieldInfo GetFieldFromHandle (RuntimeFieldHandle handle, RuntimeTypeHandle declaringType)
- {
- if (handle.IsNullHandle ())
- throw new ArgumentException (SR.Argument_InvalidHandle);
- FieldInfo fi = internal_from_handle_type (handle.Value, declaringType.Value);
- if (fi == null)
- throw new ArgumentException ("The field handle and the type handle are incompatible.");
- return fi;
- }
-
- internal virtual int GetFieldOffset ()
- {
- throw NotImplemented.ByDesign;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private extern MarshalAsAttribute get_marshal_info ();
-
- internal object[] GetPseudoCustomAttributes ()
- {
- int count = 0;
-
- if (IsNotSerialized)
- count ++;
-
- if (DeclaringType.IsExplicitLayout)
- count ++;
-
- MarshalAsAttribute marshalAs = get_marshal_info ();
- if (marshalAs != null)
- count ++;
-
- if (count == 0)
- return null;
- object[] attrs = new object [count];
- count = 0;
-
- if (IsNotSerialized)
- attrs [count ++] = new NonSerializedAttribute ();
- if (DeclaringType.IsExplicitLayout)
- attrs [count ++] = new FieldOffsetAttribute (GetFieldOffset ());
- if (marshalAs != null)
- attrs [count ++] = marshalAs;
-
- return attrs;
- }
-
- internal CustomAttributeData[] GetPseudoCustomAttributesData ()
- {
- int count = 0;
-
- if (IsNotSerialized)
- count++;
-
- if (DeclaringType.IsExplicitLayout)
- count++;
-
- MarshalAsAttribute marshalAs = get_marshal_info ();
- if (marshalAs != null)
- count++;
-
- if (count == 0)
- return null;
- CustomAttributeData[] attrsData = new CustomAttributeData [count];
- count = 0;
-
- if (IsNotSerialized)
- attrsData [count++] = new CustomAttributeData ((typeof (NonSerializedAttribute)).GetConstructor (Type.EmptyTypes));
- if (DeclaringType.IsExplicitLayout) {
- var ctorArgs = new CustomAttributeTypedArgument[] { new CustomAttributeTypedArgument (typeof (int), GetFieldOffset ()) };
- attrsData [count++] = new CustomAttributeData (
- (typeof (FieldOffsetAttribute)).GetConstructor (new[] { typeof (int) }),
- ctorArgs,
- Array.Empty<CustomAttributeNamedArgument> ());
- }
-
- if (marshalAs != null) {
- var ctorArgs = new CustomAttributeTypedArgument[] { new CustomAttributeTypedArgument (typeof (UnmanagedType), marshalAs.Value) };
- attrsData [count++] = new CustomAttributeData (
- (typeof (MarshalAsAttribute)).GetConstructor (new[] { typeof (UnmanagedType) }),
- ctorArgs,
- Array.Empty<CustomAttributeNamedArgument> ());//FIXME Get named params
- }
-
- return attrsData;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/MemberInfo.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/MemberInfo.Mono.cs
deleted file mode 100644
index c385d9ec5e8..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/MemberInfo.Mono.cs
+++ /dev/null
@@ -1,28 +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.
-
-namespace System.Reflection
-{
- public abstract partial class MemberInfo
- {
- internal bool HasSameMetadataDefinitionAsCore<TOther>(MemberInfo other) where TOther : MemberInfo
- {
- if (other == null)
- throw new ArgumentNullException(nameof(other));
-
- // Ensure that "other" is a runtime-implemented MemberInfo. Do this check before calling any methods on it!
- if (!(other is TOther))
- return false;
-
- if (MetadataToken != other.MetadataToken)
- return false;
-
- if (!(Module.Equals(other.Module)))
- return false;
-
- return true;
- }
- }
-}
-
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/Metadata/AssemblyExtensions.cs b/netcore/System.Private.CoreLib/src/System/Reflection/Metadata/AssemblyExtensions.cs
deleted file mode 100644
index 3d759589a7d..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/Metadata/AssemblyExtensions.cs
+++ /dev/null
@@ -1,12 +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.
-
-namespace System.Reflection.Metadata
-{
- public static class AssemblyExtensions
- {
- [CLSCompliant(false)]
- public static unsafe bool TryGetRawMetadata (this Assembly assembly, out byte* blob, out int length) => throw new NotImplementedException ();
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/MethodBase.Mono.cs b/netcore/System.Private.CoreLib/src/System/Reflection/MethodBase.Mono.cs
deleted file mode 100644
index b219e9f919f..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/MethodBase.Mono.cs
+++ /dev/null
@@ -1,78 +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 System.Runtime.CompilerServices;
-using System.Reflection.Emit;
-
-namespace System.Reflection
-{
- partial class MethodBase
- {
- public static MethodBase GetMethodFromHandle (RuntimeMethodHandle handle)
- {
- if (handle.IsNullHandle ())
- throw new ArgumentException (SR.Argument_InvalidHandle);
-
- MethodBase m = RuntimeMethodInfo.GetMethodFromHandleInternalType (handle.Value, IntPtr.Zero);
- if (m == null)
- throw new ArgumentException (SR.Argument_InvalidHandle);
-
- Type declaringType = m.DeclaringType;
- if (declaringType != null && declaringType.IsGenericType)
- throw new ArgumentException (String.Format (SR.Argument_MethodDeclaringTypeGeneric,
- m, declaringType.GetGenericTypeDefinition ()));
-
- return m;
- }
-
- public static MethodBase GetMethodFromHandle (RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
- {
- if (handle.IsNullHandle ())
- throw new ArgumentException (SR.Argument_InvalidHandle);
- MethodBase m = RuntimeMethodInfo.GetMethodFromHandleInternalType (handle.Value, declaringType.Value);
- if (m == null)
- throw new ArgumentException (SR.Argument_InvalidHandle);
- return m;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static MethodBase GetCurrentMethod ();
-
- internal virtual ParameterInfo[] GetParametersNoCopy ()
- {
- return GetParametersInternal ();
- }
-
- internal virtual ParameterInfo[] GetParametersInternal ()
- {
- throw new NotImplementedException ();
- }
-
- internal virtual int GetParametersCount ()
- {
- throw new NotImplementedException ();
- }
-
- internal virtual Type GetParameterType (int pos)
- {
- throw new NotImplementedException ();
- }
-
- internal virtual Type[] GetParameterTypes ()
- {
- ParameterInfo[] paramInfo = GetParametersNoCopy ();
-
- Type[] parameterTypes = new Type [paramInfo.Length];
- for (int i = 0; i < paramInfo.Length; i++)
- parameterTypes [i] = paramInfo [i].ParameterType;
-
- return parameterTypes;
- }
-
- internal virtual int get_next_table_index (object obj, int table, int count)
- {
- throw new NotImplementedException ();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
deleted file mode 100644
index 9a264739e36..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
+++ /dev/null
@@ -1,451 +0,0 @@
-//
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#nullable disable
-using System.IO;
-using System.Globalization;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Loader;
-using System.Threading;
-
-namespace System.Reflection
-{
- [StructLayout (LayoutKind.Sequential)]
- sealed class RuntimeAssembly : Assembly
- {
- private sealed class ResolveEventHolder
- {
- public event ModuleResolveEventHandler ModuleResolve;
- }
-
- private sealed class UnmanagedMemoryStreamForModule : UnmanagedMemoryStream
- {
- Module module;
-
- public unsafe UnmanagedMemoryStreamForModule (byte* pointer, long length, Module module)
- : base (pointer, length)
- {
- this.module = module;
- }
- }
-
- //
- // KEEP IN SYNC WITH mcs/class/corlib/System.Reflection/RuntimeAssembly.cs
- //
- #region VM dependency
- IntPtr _mono_assembly;
- object _evidence; // Unused, kept for layout compatibility
- #endregion
-
- ResolveEventHolder resolve_event_holder;
-
- public override extern MethodInfo? EntryPoint {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- get;
- }
-
- public override bool ReflectionOnly => false;
-
- public override string? CodeBase {
- get {
- return get_code_base (this, false);
- }
- }
-
- public override string? FullName {
- get {
- return get_fullname (this);
- }
- }
-
- //
- // We can't store the event directly in this class, since the
- // compiler would silently insert the fields before _mono_assembly
- //
- public override event ModuleResolveEventHandler ModuleResolve {
- add {
- resolve_event_holder.ModuleResolve += value;
- }
- remove {
- resolve_event_holder.ModuleResolve -= value;
- }
- }
-
- public override Module? ManifestModule => GetManifestModuleInternal ();
-
- public override bool GlobalAssemblyCache => false;
-
- public override long HostContext => 0;
-
- public override string ImageRuntimeVersion => InternalImageRuntimeVersion (this);
-
- public override string Location {
- get {
- return get_location ();
- }
- }
-
- // TODO:
- public override bool IsCollectible => false;
-
- internal static AssemblyName CreateAssemblyName (string assemblyString, out RuntimeAssembly assemblyFromResolveEvent)
- {
- if (assemblyString == null)
- throw new ArgumentNullException (nameof (assemblyString));
-
- if ((assemblyString.Length == 0) ||
- (assemblyString[0] == '\0'))
- throw new ArgumentException (SR.Format_StringZeroLength);
-
- assemblyFromResolveEvent = null;
- try {
- return new AssemblyName (assemblyString);
- } catch (Exception) {
- assemblyFromResolveEvent = (RuntimeAssembly)AssemblyLoadContext.DoAssemblyResolve (assemblyString);
- if (assemblyFromResolveEvent == null)
- throw new FileLoadException (assemblyString);
- return null;
- }
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public override extern String[] GetManifestResourceNames ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public override extern Type[] GetExportedTypes ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern Type[] GetTopLevelForwardedTypes ();
-
- public override Type[] GetForwardedTypes () {
- Type[] topLevelTypes = GetTopLevelForwardedTypes ();
- List<Type> forwardedTypes = new List<Type> (topLevelTypes);
- List<Exception> exceptions = new List<Exception> ();
-
- foreach (Type t in topLevelTypes)
- AddPublicNestedTypes (t, forwardedTypes, exceptions);
-
- if (exceptions.Count > 0) {
- forwardedTypes.AddRange (new Type [exceptions.Count]); // add one null Type for each exception
- exceptions.InsertRange (0, new Exception [forwardedTypes.Count]); // align the Exceptions with the null Types
- throw new ReflectionTypeLoadException (forwardedTypes.ToArray (), exceptions.ToArray ());
- }
-
- return forwardedTypes.ToArray ();
- }
-
- private static void AddPublicNestedTypes (Type type, List<Type> types, List<Exception> exceptions)
- {
- Type[] nestedTypes;
-
- try {
- nestedTypes = type.GetNestedTypes (BindingFlags.Public);
- }
- catch (FileLoadException e) { exceptions.Add (e); return; }
- catch (FileNotFoundException e) { exceptions.Add (e); return; }
- catch (TypeLoadException e) { exceptions.Add (e); return; }
- catch (IOException e) { exceptions.Add (e); return; }
- catch (UnauthorizedAccessException e) { exceptions.Add (e); return; }
-
- foreach (Type nestedType in nestedTypes) {
- types.Add(nestedType);
- AddPublicNestedTypes(nestedType, types, exceptions);
- }
- }
-
- public override ManifestResourceInfo GetManifestResourceInfo (string resourceName)
- {
- if (resourceName == null)
- throw new ArgumentNullException ("resourceName");
- if (resourceName.Length == 0)
- throw new ArgumentException ("String cannot have zero length.");
- ManifestResourceInfo result = new ManifestResourceInfo (null, null, 0);
- bool found = GetManifestResourceInfoInternal (resourceName, result);
- if (found)
- return result;
- else
- return null;
- }
-
- public override Stream GetManifestResourceStream (string name)
- {
- if (name == null)
- throw new ArgumentNullException (nameof (name));
-
- if (name.Length == 0)
- throw new ArgumentException ("String cannot have zero length.",
- "name");
-
- unsafe {
- byte* data = (byte*) GetManifestResourceInternal (name, out int length, out Module resourceModule);
- if (data == null)
- return null;
-
- // It cannot use SafeBuffer mode because not all methods are supported in this
- // mode (e.g. UnmanagedMemoryStream.get_PositionPointer)
- return new UnmanagedMemoryStreamForModule (data, length, resourceModule);
- }
- }
-
- public override Stream GetManifestResourceStream (Type type, string name)
- {
- if (type == null && name == null)
- throw new ArgumentNullException (nameof (type));
-
- string nameSpace = type?.Namespace;
-
- string resourceName = nameSpace != null && name != null ?
- nameSpace + Type.Delimiter + name :
- nameSpace + name;
-
- return GetManifestResourceStream (resourceName);
- }
-
- public override AssemblyName GetName (bool copiedName)
- {
- return AssemblyName.Create (_mono_assembly, CodeBase);
- }
-
- public override Type GetType (string name, bool throwOnError, bool ignoreCase)
- {
- if (name == null)
- throw new ArgumentNullException (nameof (name));
-
- if (name.Length == 0)
- throw new ArgumentException ("Name cannot be empty");
-
- return InternalGetType (null, name, throwOnError, ignoreCase);
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- return CustomAttribute.IsDefined (this, attributeType, inherit);
- }
-
- public override IList<CustomAttributeData> GetCustomAttributesData ()
- {
- return CustomAttributeData.GetCustomAttributes (this);
- }
-
- public override object[] GetCustomAttributes (bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, inherit);
- }
-
- public override object[] GetCustomAttributes (Type attributeType, bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
- }
-
- public override Module GetModule (string name)
- {
- if (name == null)
- throw new ArgumentNullException ("name");
- if (name.Length == 0)
- throw new ArgumentException ("Name can't be empty");
-
- Module[] modules = GetModules (true);
- foreach (Module module in modules) {
- if (module.ScopeName == name)
- return module;
- }
-
- return null;
- }
-
- public override Module[] GetModules (bool getResourceModules)
- {
- Module[] modules = GetModulesInternal ();
-
- if (!getResourceModules) {
- var result = new List<Module> (modules.Length);
- foreach (Module m in modules)
- if (!m.IsResource ())
- result.Add (m);
- return result.ToArray ();
- }
- else
- return modules;
- }
-
- public override Module[] GetLoadedModules (bool getResourceModules)
- {
- return GetModules (getResourceModules);
- }
-
- public override AssemblyName[] GetReferencedAssemblies ()
- {
- using (var nativeNames = new Mono.SafeGPtrArrayHandle (InternalGetReferencedAssemblies (this))) {
- var numAssemblies = nativeNames.Length;
- try {
- AssemblyName [] result = new AssemblyName[numAssemblies];
- const bool addVersion = true;
- const bool addPublicKey = false;
- const bool defaultToken = true;
- for (int i = 0; i < numAssemblies; i++) {
- AssemblyName name = new AssemblyName ();
- unsafe {
- Mono.MonoAssemblyName *nativeName = (Mono.MonoAssemblyName*) nativeNames[i];
- name.FillName (nativeName, null, addVersion, addPublicKey, defaultToken);
- result[i] = name;
- }
- }
- return result;
- } finally {
- for (int i = 0; i < numAssemblies; i++) {
- unsafe {
- Mono.MonoAssemblyName* nativeName = (Mono.MonoAssemblyName*) nativeNames[i];
- Mono.RuntimeMarshal.FreeAssemblyName (ref *nativeName, true);
- }
- }
- }
- }
- }
-
- public override Assembly GetSatelliteAssembly (CultureInfo culture)
- {
- return GetSatelliteAssembly (culture, null);
- }
-
- public override Assembly GetSatelliteAssembly (CultureInfo culture, Version version)
- {
- if (culture == null)
- throw new ArgumentNullException (nameof (culture));
-
- return InternalGetSatelliteAssembly (culture, version, true);
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- internal Assembly InternalGetSatelliteAssembly (CultureInfo culture, Version version, bool throwOnFileNotFound)
- {
- var aname = GetName ();
-
- var an = new AssemblyName ();
- if (version == null)
- an.Version = aname.Version;
- else
- an.Version = version;
-
- an.CultureInfo = culture;
- an.Name = aname.Name + ".resources";
-
- Assembly res = null;
- try {
- StackCrawlMark unused = default;
- res = Assembly.Load (an, ref unused, null);
- } catch {
- }
-
- if (res == this)
- res = null;
- if (res == null && throwOnFileNotFound)
- throw new FileNotFoundException (String.Format (culture, SR.IO_FileNotFound_FileName, an.Name));
- return res;
- }
-
- public override FileStream GetFile (string name)
- {
- if (name == null)
- throw new ArgumentNullException (nameof (name), SR.ArgumentNull_FileName);
- if (name.Length == 0)
- throw new ArgumentException (SR.Argument_EmptyFileName);
-
- string location = Location;
- if (location != null && Path.GetFileName (location) == name)
- return new FileStream (location, FileMode.Open, FileAccess.Read);
- string filename = (string)GetFilesInternal (name, true);
- if (filename != null)
- return new FileStream (filename, FileMode.Open, FileAccess.Read);
- else
- return null;
- }
-
- public override FileStream[] GetFiles (bool getResourceModules)
- {
- string[] names = (string[]) GetFilesInternal (null, getResourceModules);
- if (names == null)
- return Array.Empty<FileStream> ();
-
- string location = Location;
-
- FileStream[] res;
- if (location != String.Empty) {
- res = new FileStream [names.Length + 1];
- res [0] = new FileStream (location, FileMode.Open, FileAccess.Read);
- for (int i = 0; i < names.Length; ++i)
- res [i + 1] = new FileStream (names [i], FileMode.Open, FileAccess.Read);
- } else {
- res = new FileStream [names.Length];
- for (int i = 0; i < names.Length; ++i)
- res [i] = new FileStream (names [i], FileMode.Open, FileAccess.Read);
- }
- return res;
- }
-
- internal static RuntimeAssembly InternalLoadAssemblyName (AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext assemblyLoadContext)
- {
- // TODO: Use assemblyLoadContext
- return (RuntimeAssembly) InternalLoad (assemblyRef.FullName, ref stackMark, IntPtr.Zero);
- }
-
- // FIXME: Merge some of these
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern string get_location ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static string get_code_base (Assembly a, bool escaped);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static string get_fullname (Assembly a);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static string InternalImageRuntimeVersion (Assembly a);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern bool GetManifestResourceInfoInternal (string name, ManifestResourceInfo info);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern IntPtr /* byte* */ GetManifestResourceInternal (string name, out int size, out Module module);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern Module GetManifestModuleInternal ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern Module[] GetModulesInternal ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern IntPtr InternalGetReferencedAssemblies (Assembly module);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- private extern object GetFilesInternal (String name, bool getResourceModules);
-
- internal string? GetSimpleName ()
- {
- // TODO: Make this cheaper and faster
- return GetName ().Name;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs b/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs
deleted file mode 100644
index d2e178f702b..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs
+++ /dev/null
@@ -1,220 +0,0 @@
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-// Copyright (C) 2004, 2009 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#nullable disable
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection
-{
- internal struct MonoEventInfo
- {
- public Type declaring_type;
- public Type reflected_type;
- public String name;
- public MethodInfo add_method;
- public MethodInfo remove_method;
- public MethodInfo raise_method;
- public EventAttributes attrs;
- public MethodInfo[] other_methods;
- }
-
- [StructLayout (LayoutKind.Sequential)]
- internal sealed class RuntimeEventInfo : EventInfo
- {
-#pragma warning disable 169
- IntPtr klass;
- IntPtr handle;
-#pragma warning restore 169
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern void get_event_info (RuntimeEventInfo ev, out MonoEventInfo info);
-
- internal static MonoEventInfo GetEventInfo (RuntimeEventInfo ev)
- {
- MonoEventInfo mei;
- get_event_info (ev, out mei);
- return mei;
- }
-
- public override Module Module {
- get {
- return GetRuntimeModule ();
- }
- }
-
- internal BindingFlags BindingFlags {
- get {
- return GetBindingFlags ();
- }
- }
-
- internal RuntimeType GetDeclaringTypeInternal ()
- {
- return (RuntimeType) DeclaringType;
- }
-
- RuntimeType ReflectedTypeInternal {
- get {
- return (RuntimeType) ReflectedType;
- }
- }
-
- internal RuntimeModule GetRuntimeModule ()
- {
- return GetDeclaringTypeInternal ().GetRuntimeModule ();
- }
-
- internal BindingFlags GetBindingFlags ()
- {
- MonoEventInfo info = GetEventInfo (this);
-
- MethodInfo method = info.add_method;
- if (method == null)
- method = info.remove_method;
- if (method == null)
- method = info.raise_method;
-
- return RuntimeType.FilterPreCalculate (method != null && method.IsPublic, GetDeclaringTypeInternal () != ReflectedType , method != null && method.IsStatic);
- }
-
- public override EventAttributes Attributes {
- get {
- return GetEventInfo (this).attrs;
- }
- }
-
- public override MethodInfo GetAddMethod (bool nonPublic)
- {
- MonoEventInfo info = GetEventInfo (this);
- if (nonPublic || (info.add_method != null && info.add_method.IsPublic))
- return info.add_method;
- return null;
- }
-
- public override MethodInfo GetRaiseMethod (bool nonPublic)
- {
- MonoEventInfo info = GetEventInfo (this);
- if (nonPublic || (info.raise_method != null && info.raise_method.IsPublic))
- return info.raise_method;
- return null;
- }
-
- public override MethodInfo GetRemoveMethod (bool nonPublic)
- {
- MonoEventInfo info = GetEventInfo (this);
- if (nonPublic || (info.remove_method != null && info.remove_method.IsPublic))
- return info.remove_method;
- return null;
- }
-
- public override MethodInfo[] GetOtherMethods (bool nonPublic)
- {
- MonoEventInfo info = GetEventInfo (this);
- if (nonPublic)
- return info.other_methods;
- int num_public = 0;
- foreach (MethodInfo m in info.other_methods) {
- if (m.IsPublic)
- num_public++;
- }
- if (num_public == info.other_methods.Length)
- return info.other_methods;
- MethodInfo[] res = new MethodInfo [num_public];
- num_public = 0;
- foreach (MethodInfo m in info.other_methods) {
- if (m.IsPublic)
- res [num_public++] = m;
- }
- return res;
- }
-
- public override Type DeclaringType {
- get {
- return GetEventInfo (this).declaring_type;
- }
- }
-
- public override Type ReflectedType {
- get {
- return GetEventInfo (this).reflected_type;
- }
- }
-
- public override string Name {
- get {
- return GetEventInfo (this).name;
- }
- }
-
- public override string ToString ()
- {
- return EventHandlerType + " " + Name;
- }
-
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- return CustomAttribute.IsDefined (this, attributeType, inherit);
- }
-
- public override object[] GetCustomAttributes( bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, inherit);
- }
-
- public override object[] GetCustomAttributes( Type attributeType, bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
- }
-
- public override IList<CustomAttributeData> GetCustomAttributesData () {
- return CustomAttributeData.GetCustomAttributes (this);
- }
-
- public override int MetadataToken {
- get {
- return get_metadata_token (this);
- }
- }
-
- public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeEventInfo> (other);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern int get_metadata_token (RuntimeEventInfo monoEvent);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern EventInfo internal_from_handle_type (IntPtr event_handle, IntPtr type_handle);
-
- internal static EventInfo GetEventFromHandle (Mono.RuntimeEventHandle handle, RuntimeTypeHandle reflectedType)
- {
- if (handle.Value == IntPtr.Zero)
- throw new ArgumentException ("The handle is invalid.");
- EventInfo ei = internal_from_handle_type (handle.Value, reflectedType.Value);
- if (ei == null)
- throw new ArgumentException ("The event handle and the type handle are incompatible.");
- return ei;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeExceptionHandlingClause.cs b/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeExceptionHandlingClause.cs
deleted file mode 100644
index 75f6ac2a4a1..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeExceptionHandlingClause.cs
+++ /dev/null
@@ -1,31 +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 System.Runtime.InteropServices;
-
-namespace System.Reflection
-{
- [StructLayout (LayoutKind.Sequential)]
- internal sealed class RuntimeExceptionHandlingClause : ExceptionHandlingClause
- {
- #region Keep in sync with MonoReflectionExceptionHandlingClause in object-internals.h
- internal Type catch_type;
- internal int filter_offset;
- internal ExceptionHandlingClauseOptions flags;
- internal int try_offset;
- internal int try_length;
- internal int handler_offset;
- internal int handler_length;
- #endregion
-
- public override ExceptionHandlingClauseOptions Flags => flags;
- public override int TryOffset => try_offset;
- public override int TryLength => try_length;
- public override int HandlerOffset => handler_offset;
- public override int HandlerLength => handler_length;
- public override int FilterOffset => filter_offset;
- public override Type? CatchType => catch_type;
- }
-
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs b/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs
deleted file mode 100644
index 56a82717a6d..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs
+++ /dev/null
@@ -1,289 +0,0 @@
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#nullable disable
-using System.Collections.Generic;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Diagnostics;
-
-namespace System.Reflection
-{
- abstract class RtFieldInfo : FieldInfo
- {
- internal abstract object UnsafeGetValue (object obj);
- internal abstract void UnsafeSetValue (Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture);
- internal abstract void CheckConsistency(Object target);
- }
-
- [StructLayout (LayoutKind.Sequential)]
- class RuntimeFieldInfo : RtFieldInfo
- {
-#pragma warning disable 649
- internal IntPtr klass;
- internal RuntimeFieldHandle fhandle;
- string name;
- Type type;
- FieldAttributes attrs;
-#pragma warning restore 649
-
- internal BindingFlags BindingFlags {
- get {
- return 0;
- }
- }
-
- public override Module Module {
- get {
- return GetRuntimeModule ();
- }
- }
-
- internal RuntimeType GetDeclaringTypeInternal ()
- {
- return (RuntimeType) DeclaringType;
- }
-
- RuntimeType ReflectedTypeInternal {
- get {
- return (RuntimeType) ReflectedType;
- }
- }
-
- internal RuntimeModule GetRuntimeModule ()
- {
- return GetDeclaringTypeInternal ().GetRuntimeModule ();
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal override extern object UnsafeGetValue (object obj);
-
- internal override void CheckConsistency(Object target)
- {
- // only test instance fields
- if ((Attributes & FieldAttributes.Static) != FieldAttributes.Static)
- {
- if (!DeclaringType.IsInstanceOfType(target))
- {
- if (target == null)
- {
- throw new TargetException(Environment.GetResourceString("RFLCT.Targ_StatFldReqTarg"));
- }
- else
- {
- throw new ArgumentException(
- String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_FieldDeclTarget"),
- Name, DeclaringType, target.GetType()));
- }
- }
- }
- }
-
- [DebuggerStepThroughAttribute]
- [Diagnostics.DebuggerHidden]
- internal override void UnsafeSetValue (Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
- {
- bool domainInitialized = false;
- RuntimeFieldHandle.SetValue (this, obj, value, null, Attributes, null, ref domainInitialized);
- }
-
- [DebuggerStepThroughAttribute]
- [Diagnostics.DebuggerHidden]
- public override void SetValueDirect(TypedReference obj, Object value)
- {
- if (obj.IsNull)
- throw new ArgumentException(Environment.GetResourceString("Arg_TypedReference_Null"));
-
- unsafe
- {
- // Passing TypedReference by reference is easier to make correct in native code
- RuntimeFieldHandle.SetValueDirect(this, (RuntimeType)FieldType, &obj, value, (RuntimeType)DeclaringType);
- }
- }
-
- [DebuggerStepThroughAttribute]
- [Diagnostics.DebuggerHidden]
- public override Object GetValueDirect(TypedReference obj)
- {
- if (obj.IsNull)
- throw new ArgumentException(Environment.GetResourceString("Arg_TypedReference_Null"));
-
- unsafe
- {
- // Passing TypedReference by reference is easier to make correct in native code
- return RuntimeFieldHandle.GetValueDirect(this, (RuntimeType)FieldType, &obj, (RuntimeType)DeclaringType);
- }
- }
-
- public override FieldAttributes Attributes {
- get {
- return attrs;
- }
- }
- public override RuntimeFieldHandle FieldHandle {
- get {
- return fhandle;
- }
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern Type ResolveType ();
-
- public override Type FieldType {
- get {
- if (type == null)
- type = ResolveType ();
- return type;
- }
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private extern Type GetParentType (bool declaring);
-
- public override Type ReflectedType {
- get {
- return GetParentType (false);
- }
- }
- public override Type DeclaringType {
- get {
- Type parentType = GetParentType (true);
- return parentType.Name != "<Module>" ? parentType : null;
- }
- }
- public override string Name {
- get {
- return name;
- }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit) {
- return CustomAttribute.IsDefined (this, attributeType, inherit);
- }
-
- public override object[] GetCustomAttributes( bool inherit) {
- return CustomAttribute.GetCustomAttributes (this, inherit);
- }
- public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
- return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal override extern int GetFieldOffset ();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private extern object GetValueInternal (object obj);
-
- public override object GetValue (object obj)
- {
- if (!IsStatic) {
- if (obj == null)
- throw new TargetException ("Non-static field requires a target");
- if (!DeclaringType.IsAssignableFrom (obj.GetType ()))
- throw new ArgumentException (string.Format (
- "Field {0} defined on type {1} is not a field on the target object which is of type {2}.",
- Name, DeclaringType, obj.GetType ()),
- "obj");
- }
-
- if (!IsLiteral)
- CheckGeneric ();
- return GetValueInternal (obj);
- }
-
- public override string ToString () {
- return String.Format ("{0} {1}", FieldType, name);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern void SetValueInternal (FieldInfo fi, object obj, object value);
-
- public override void SetValue (object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
- {
- if (!IsStatic) {
- if (obj == null)
- throw new TargetException ("Non-static field requires a target");
- if (!DeclaringType.IsAssignableFrom (obj.GetType ()))
- throw new ArgumentException (string.Format (
- "Field {0} defined on type {1} is not a field on the target object which is of type {2}.",
- Name, DeclaringType, obj.GetType ()),
- "obj");
- }
- if (IsLiteral)
- throw new FieldAccessException ("Cannot set a constant field");
- if (binder == null)
- binder = Type.DefaultBinder;
- CheckGeneric ();
- if (val != null) {
- RuntimeType fieldType = (RuntimeType) FieldType;
- val = fieldType.CheckValue (val, binder, culture, invokeAttr);
- }
- SetValueInternal (this, obj, val);
- }
-
- internal RuntimeFieldInfo Clone (string newName)
- {
- RuntimeFieldInfo field = new RuntimeFieldInfo ();
- field.name = newName;
- field.type = type;
- field.attrs = attrs;
- field.klass = klass;
- field.fhandle = fhandle;
- return field;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public override extern object GetRawConstantValue ();
-
- public override IList<CustomAttributeData> GetCustomAttributesData () {
- return CustomAttributeData.GetCustomAttributes (this);
- }
-
- void CheckGeneric () {
- Type declaringType = DeclaringType;
- if (declaringType != null && declaringType.ContainsGenericParameters)
- throw new InvalidOperationException ("Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true.");
- }
-
- public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeFieldInfo> (other);
-
- public override int MetadataToken {
- get {
- return get_metadata_token (this);
- }
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern int get_metadata_token (RuntimeFieldInfo monoField);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern Type[] GetTypeModifiers (bool optional);
-
- public override Type[] GetOptionalCustomModifiers () => GetCustomModifiers (true);
-
- public override Type[] GetRequiredCustomModifiers () => GetCustomModifiers (false);
-
- private Type[] GetCustomModifiers (bool optional) => GetTypeModifiers (optional) ?? Type.EmptyTypes;
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeLocalVariableInfo.cs b/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeLocalVariableInfo.cs
deleted file mode 100644
index 6681ef929ee..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeLocalVariableInfo.cs
+++ /dev/null
@@ -1,26 +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 System;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection {
- [StructLayout (LayoutKind.Sequential)]
- internal sealed class RuntimeLocalVariableInfo : LocalVariableInfo {
- #region Keep in sync with MonoReflectionLocalVariableInfo in object-internals.h
- internal Type type;
- internal bool is_pinned;
- internal ushort position;
- #endregion
-
- public override bool IsPinned => is_pinned;
-
- public override int LocalIndex => position;
-
- public override Type LocalType => type;
- }
-
-}
-
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs b/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs
deleted file mode 100644
index 7ded1e13589..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs
+++ /dev/null
@@ -1,43 +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 System;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection {
-
- internal sealed class RuntimeMethodBody : MethodBody
- {
- ExceptionHandlingClause[] clauses;
- LocalVariableInfo[] locals;
- byte[] il;
- bool init_locals;
- int sig_token;
- int max_stack;
-
- // Called by the runtime
- internal RuntimeMethodBody (ExceptionHandlingClause[] clauses, LocalVariableInfo[] locals,
- byte[] il, bool init_locals, int sig_token, int max_stack)
- {
- this.clauses = clauses;
- this.locals = locals;
- this.il = il;
- this.init_locals = init_locals;
- this.sig_token = sig_token;
- this.max_stack = max_stack;
- }
-
- public override int LocalSignatureMetadataToken => sig_token;
- public override IList<LocalVariableInfo> LocalVariables => Array.AsReadOnly (locals);
- public override int MaxStackSize => max_stack;
- public override bool InitLocals => init_locals;
- public override byte[] GetILAsByteArray() => il;
- public override IList<ExceptionHandlingClause> ExceptionHandlingClauses => Array.AsReadOnly (clauses);
- }
-
-}
-
-
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs b/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
deleted file mode 100644
index 763b4a52d11..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
+++ /dev/null
@@ -1,913 +0,0 @@
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
-// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#nullable disable
-using System.Collections.Generic;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Reflection.Emit;
-using System.Text;
-using System.Diagnostics;
-using InteropServicesCallingConvention = System.Runtime.InteropServices.CallingConvention;
-
-namespace System.Reflection
-{
-
- [Flags]
- internal enum PInvokeAttributes
- {
- NoMangle = 0x0001,
-
- CharSetMask = 0x0006,
- CharSetNotSpec = 0x0000,
- CharSetAnsi = 0x0002,
- CharSetUnicode = 0x0004,
- CharSetAuto = 0x0006,
-
- BestFitUseAssem = 0x0000,
- BestFitEnabled = 0x0010,
- BestFitDisabled = 0x0020,
- BestFitMask = 0x0030,
-
- ThrowOnUnmappableCharUseAssem = 0x0000,
- ThrowOnUnmappableCharEnabled = 0x1000,
- ThrowOnUnmappableCharDisabled = 0x2000,
- ThrowOnUnmappableCharMask = 0x3000,
-
- SupportsLastError = 0x0040,
-
- CallConvMask = 0x0700,
- CallConvWinapi = 0x0100,
- CallConvCdecl = 0x0200,
- CallConvStdcall = 0x0300,
- CallConvThiscall = 0x0400,
- CallConvFastcall = 0x0500,
-
- MaxValue = 0xFFFF,
- }
-
- internal struct MonoMethodInfo
- {
-#pragma warning disable 649
- private Type parent;
- private Type ret;
- internal MethodAttributes attrs;
- internal MethodImplAttributes iattrs;
- private CallingConventions callconv;
-#pragma warning restore 649
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern void get_method_info (IntPtr handle, out MonoMethodInfo info);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern int get_method_attributes (IntPtr handle);
-
- internal static MonoMethodInfo GetMethodInfo (IntPtr handle)
- {
- MonoMethodInfo info;
- MonoMethodInfo.get_method_info (handle, out info);
- return info;
- }
-
- internal static Type GetDeclaringType (IntPtr handle)
- {
- return GetMethodInfo (handle).parent;
- }
-
- internal static Type GetReturnType (IntPtr handle)
- {
- return GetMethodInfo (handle).ret;
- }
-
- internal static MethodAttributes GetAttributes (IntPtr handle)
- {
- return (MethodAttributes)get_method_attributes (handle);
- }
-
- internal static CallingConventions GetCallingConvention (IntPtr handle)
- {
- return GetMethodInfo (handle).callconv;
- }
-
- internal static MethodImplAttributes GetMethodImplementationFlags (IntPtr handle)
- {
- return GetMethodInfo (handle).iattrs;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern ParameterInfo[] get_parameter_info (IntPtr handle, MemberInfo member);
-
- static internal ParameterInfo[] GetParametersInfo (IntPtr handle, MemberInfo member)
- {
- return get_parameter_info (handle, member);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern MarshalAsAttribute get_retval_marshal (IntPtr handle);
-
- static internal ParameterInfo GetReturnParameterInfo (RuntimeMethodInfo method)
- {
- return RuntimeParameterInfo.New (GetReturnType (method.mhandle), method, get_retval_marshal (method.mhandle));
- }
- }
-
- [StructLayout (LayoutKind.Sequential)]
- class RuntimeMethodInfo : MethodInfo
- {
-#pragma warning disable 649
- internal IntPtr mhandle;
- string name;
- Type reftype;
-#pragma warning restore 649
-
- internal BindingFlags BindingFlags {
- get {
- return 0;
- }
- }
-
- public override Module Module {
- get {
- return GetRuntimeModule ();
- }
- }
-
- RuntimeType ReflectedTypeInternal {
- get {
- return (RuntimeType) ReflectedType;
- }
- }
-
- string FormatNameAndSig ()
- {
- // Serialization uses ToString to resolve MethodInfo overloads.
- StringBuilder sbName = new StringBuilder(Name);
-
- if (IsGenericMethod)
- sbName.Append(RuntimeMethodHandle.ConstructInstantiation(this, TypeNameFormatFlags.FormatBasic));
-
- sbName.Append("(");
- RuntimeParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention);
- sbName.Append(")");
-
- return sbName.ToString();
- }
-
- public override Delegate CreateDelegate (Type delegateType)
- {
- return Delegate.CreateDelegate (delegateType, this);
- }
-
- public override Delegate CreateDelegate (Type delegateType, object target)
- {
- return Delegate.CreateDelegate (delegateType, target, this);
- }
-
- public override String ToString()
- {
- return ReturnType.FormatTypeName() + " " + FormatNameAndSig();
- }
-
- internal RuntimeModule GetRuntimeModule ()
- {
- return ((RuntimeType)DeclaringType).GetRuntimeModule();
- }
-
- internal static MethodBase GetMethodFromHandleNoGenericCheck (RuntimeMethodHandle handle)
- {
- return GetMethodFromHandleInternalType_native (handle.Value, IntPtr.Zero, false);
- }
-
- internal static MethodBase GetMethodFromHandleNoGenericCheck (RuntimeMethodHandle handle, RuntimeTypeHandle reflectedType)
- {
- return GetMethodFromHandleInternalType_native (handle.Value, reflectedType.Value, false);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- [PreserveDependency(".ctor(System.Reflection.ExceptionHandlingClause[],System.Reflection.LocalVariableInfo[],System.Byte[],System.Boolean,System.Int32,System.Int32)", "System.Reflection.RuntimeMethodBody")]
- internal extern static MethodBody GetMethodBodyInternal (IntPtr handle);
-
- internal static MethodBody GetMethodBody (IntPtr handle)
- {
- return GetMethodBodyInternal (handle);
- }
-
- internal static MethodBase GetMethodFromHandleInternalType (IntPtr method_handle, IntPtr type_handle) {
- return GetMethodFromHandleInternalType_native (method_handle, type_handle, true);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static MethodBase GetMethodFromHandleInternalType_native (IntPtr method_handle, IntPtr type_handle, bool genericCheck);
-
- internal RuntimeMethodInfo () {
- }
-
- internal RuntimeMethodInfo (RuntimeMethodHandle mhandle) {
- this.mhandle = mhandle.Value;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern string get_name (MethodBase method);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern RuntimeMethodInfo get_base_method (RuntimeMethodInfo method, bool definition);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern int get_metadata_token (RuntimeMethodInfo method);
-
- public override MethodInfo GetBaseDefinition ()
- {
- return get_base_method (this, true);
- }
-
- // TODO: Remove, needed only for MonoCustomAttribute
- internal MethodInfo GetBaseMethod ()
- {
- return get_base_method (this, false);
- }
-
- public override ParameterInfo ReturnParameter {
- get {
- return MonoMethodInfo.GetReturnParameterInfo (this);
- }
- }
-
- public override Type ReturnType {
- get {
- return MonoMethodInfo.GetReturnType (mhandle);
- }
- }
- public override ICustomAttributeProvider ReturnTypeCustomAttributes {
- get {
- return MonoMethodInfo.GetReturnParameterInfo (this);
- }
- }
-
- public override int MetadataToken {
- get {
- return get_metadata_token (this);
- }
- }
-
- public override MethodImplAttributes GetMethodImplementationFlags ()
- {
- return MonoMethodInfo.GetMethodImplementationFlags (mhandle);
- }
-
- public override ParameterInfo[] GetParameters ()
- {
- var src = MonoMethodInfo.GetParametersInfo (mhandle, this);
- if (src.Length == 0)
- return src;
-
- // Have to clone because GetParametersInfo icall returns cached value
- var dest = new ParameterInfo [src.Length];
- Array.FastCopy (src, 0, dest, 0, src.Length);
- return dest;
- }
-
- internal override ParameterInfo[] GetParametersInternal ()
- {
- return MonoMethodInfo.GetParametersInfo (mhandle, this);
- }
-
- internal override int GetParametersCount ()
- {
- return MonoMethodInfo.GetParametersInfo (mhandle, this).Length;
- }
-
- /*
- * InternalInvoke() receives the parameters correctly converted by the
- * binder to match the types of the method signature.
- * The exc argument is used to capture exceptions thrown by the icall.
- * Exceptions thrown by the called method propagate normally.
- */
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern Object InternalInvoke (Object obj, Object[] parameters, out Exception exc);
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
- {
- if (!IsStatic) {
- if (!DeclaringType.IsInstanceOfType (obj)) {
- if (obj == null)
- throw new TargetException ("Non-static method requires a target.");
- else
- throw new TargetException ("Object does not match target type.");
- }
- }
-
- if (binder == null)
- binder = Type.DefaultBinder;
-
- /*Avoid allocating an array every time*/
- ParameterInfo[] pinfo = GetParametersInternal ();
- ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
-
- if (ContainsGenericParameters)
- throw new InvalidOperationException ("Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.");
-
- Exception exc;
- object o = null;
-
- if ((invokeAttr & BindingFlags.DoNotWrapExceptions) == 0) {
- try {
- o = InternalInvoke (obj, parameters, out exc);
- } catch (Mono.NullByRefReturnException) {
- throw new NullReferenceException ();
- } catch (OverflowException) {
- throw;
- } catch (Exception e) {
- throw new TargetInvocationException (e);
- }
- }
- else
- {
- try {
- o = InternalInvoke (obj, parameters, out exc);
- } catch (Mono.NullByRefReturnException) {
- throw new NullReferenceException ();
- }
- }
-
- if (exc != null)
- throw exc;
- return o;
- }
-
- internal static void ConvertValues (Binder binder, object[] args, ParameterInfo[] pinfo, CultureInfo culture, BindingFlags invokeAttr)
- {
- if (args == null) {
- if (pinfo.Length == 0)
- return;
-
- throw new TargetParameterCountException ();
- }
-
- if (pinfo.Length != args.Length)
- throw new TargetParameterCountException ();
-
- for (int i = 0; i < args.Length; ++i) {
- var arg = args [i];
- var pi = pinfo [i];
- if (arg == Type.Missing) {
- if (pi.DefaultValue == System.DBNull.Value)
- throw new ArgumentException(Environment.GetResourceString("Arg_VarMissNull"),"parameters");
-
- args [i] = pi.DefaultValue;
- continue;
- }
-
- var rt = (RuntimeType) pi.ParameterType;
- args [i] = rt.CheckValue (arg, binder, culture, invokeAttr);
- }
- }
-
- public override RuntimeMethodHandle MethodHandle {
- get {
- return new RuntimeMethodHandle (mhandle);
- }
- }
-
- public override MethodAttributes Attributes {
- get {
- return MonoMethodInfo.GetAttributes (mhandle);
- }
- }
-
- public override CallingConventions CallingConvention {
- get {
- return MonoMethodInfo.GetCallingConvention (mhandle);
- }
- }
-
- public override Type ReflectedType {
- get {
- return reftype;
- }
- }
- public override Type DeclaringType {
- get {
- return MonoMethodInfo.GetDeclaringType (mhandle);
- }
- }
- public override string Name {
- get {
- if (name != null)
- return name;
- return get_name (this);
- }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit) {
- return CustomAttribute.IsDefined (this, attributeType, inherit);
- }
-
- public override object[] GetCustomAttributes( bool inherit) {
- return CustomAttribute.GetCustomAttributes (this, inherit);
- }
- public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
- return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal extern void GetPInvoke (out PInvokeAttributes flags, out string entryPoint, out string dllName);
-
- internal object[] GetPseudoCustomAttributes ()
- {
- int count = 0;
-
- /* MS.NET doesn't report MethodImplAttribute */
-
- MonoMethodInfo info = MonoMethodInfo.GetMethodInfo (mhandle);
- if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
- count ++;
- if ((info.attrs & MethodAttributes.PinvokeImpl) != 0)
- count ++;
-
- if (count == 0)
- return null;
- object[] attrs = new object [count];
- count = 0;
-
- if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
- attrs [count ++] = new PreserveSigAttribute ();
- if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) {
- attrs [count ++] = GetDllImportAttribute ();
- }
-
- return attrs;
- }
-
- Attribute GetDllImportAttribute ()
- {
- string entryPoint, dllName = null;
- int token = MetadataToken;
- PInvokeAttributes flags = 0;
-
- GetPInvoke (out flags, out entryPoint, out dllName);
-
- CharSet charSet = CharSet.None;
-
- switch (flags & PInvokeAttributes.CharSetMask) {
- case PInvokeAttributes.CharSetNotSpec: charSet = CharSet.None; break;
- case PInvokeAttributes.CharSetAnsi: charSet = CharSet.Ansi; break;
- case PInvokeAttributes.CharSetUnicode: charSet = CharSet.Unicode; break;
- case PInvokeAttributes.CharSetAuto: charSet = CharSet.Auto; break;
-
- // Invalid: default to CharSet.None
- default: break;
- }
-
- CallingConvention callingConvention = InteropServicesCallingConvention.Cdecl;
-
- switch (flags & PInvokeAttributes.CallConvMask) {
- case PInvokeAttributes.CallConvWinapi: callingConvention = InteropServicesCallingConvention.Winapi; break;
- case PInvokeAttributes.CallConvCdecl: callingConvention = InteropServicesCallingConvention.Cdecl; break;
- case PInvokeAttributes.CallConvStdcall: callingConvention = InteropServicesCallingConvention.StdCall; break;
- case PInvokeAttributes.CallConvThiscall: callingConvention = InteropServicesCallingConvention.ThisCall; break;
- case PInvokeAttributes.CallConvFastcall: callingConvention = InteropServicesCallingConvention.FastCall; break;
-
- // Invalid: default to CallingConvention.Cdecl
- default: break;
- }
-
- bool exactSpelling = (flags & PInvokeAttributes.NoMangle) != 0;
- bool setLastError = (flags & PInvokeAttributes.SupportsLastError) != 0;
- bool bestFitMapping = (flags & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
- bool throwOnUnmappableChar = (flags & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
- bool preserveSig = (GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;
-
- return new DllImportAttribute (dllName) { EntryPoint = entryPoint, CharSet = charSet, SetLastError = setLastError,
- ExactSpelling = exactSpelling, PreserveSig = preserveSig, BestFitMapping = bestFitMapping,
- ThrowOnUnmappableChar = throwOnUnmappableChar, CallingConvention = callingConvention };
- }
-
- internal CustomAttributeData[] GetPseudoCustomAttributesData ()
- {
- int count = 0;
-
- /* MS.NET doesn't report MethodImplAttribute */
-
- MonoMethodInfo info = MonoMethodInfo.GetMethodInfo (mhandle);
- if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
- count++;
- if ((info.attrs & MethodAttributes.PinvokeImpl) != 0)
- count++;
-
- if (count == 0)
- return null;
- CustomAttributeData[] attrsData = new CustomAttributeData [count];
- count = 0;
-
- if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
- attrsData [count++] = new CustomAttributeData ((typeof (PreserveSigAttribute)).GetConstructor (Type.EmptyTypes));
- if ((info.attrs & MethodAttributes.PinvokeImpl) != 0)
- attrsData [count++] = GetDllImportAttributeData ();
-
- return attrsData;
- }
-
- private CustomAttributeData GetDllImportAttributeData ()
- {
- if ((Attributes & MethodAttributes.PinvokeImpl) == 0)
- return null;
-
- string entryPoint, dllName = null;
- PInvokeAttributes flags = 0;
-
- GetPInvoke (out flags, out entryPoint, out dllName);
-
- CharSet charSet;
-
- switch (flags & PInvokeAttributes.CharSetMask) {
- case PInvokeAttributes.CharSetNotSpec:
- charSet = CharSet.None;
- break;
- case PInvokeAttributes.CharSetAnsi:
- charSet = CharSet.Ansi;
- break;
- case PInvokeAttributes.CharSetUnicode:
- charSet = CharSet.Unicode;
- break;
- case PInvokeAttributes.CharSetAuto:
- charSet = CharSet.Auto;
- break;
- // Invalid: default to CharSet.None
- default:
- charSet = CharSet.None;
- break;
- }
-
- InteropServicesCallingConvention callingConvention;
-
- switch (flags & PInvokeAttributes.CallConvMask) {
- case PInvokeAttributes.CallConvWinapi:
- callingConvention = InteropServicesCallingConvention.Winapi;
- break;
- case PInvokeAttributes.CallConvCdecl:
- callingConvention = InteropServicesCallingConvention.Cdecl;
- break;
- case PInvokeAttributes.CallConvStdcall:
- callingConvention = InteropServicesCallingConvention.StdCall;
- break;
- case PInvokeAttributes.CallConvThiscall:
- callingConvention = InteropServicesCallingConvention.ThisCall;
- break;
- case PInvokeAttributes.CallConvFastcall:
- callingConvention = InteropServicesCallingConvention.FastCall;
- break;
- // Invalid: default to CallingConvention.Cdecl
- default:
- callingConvention = InteropServicesCallingConvention.Cdecl;
- break;
- }
-
- bool exactSpelling = (flags & PInvokeAttributes.NoMangle) != 0;
- bool setLastError = (flags & PInvokeAttributes.SupportsLastError) != 0;
- bool bestFitMapping = (flags & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
- bool throwOnUnmappableChar = (flags & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
- bool preserveSig = (GetMethodImplementationFlags () & MethodImplAttributes.PreserveSig) != 0;
-
- var ctorArgs = new CustomAttributeTypedArgument [] {
- new CustomAttributeTypedArgument (typeof (string), dllName),
- };
-
- var attrType = typeof (DllImportAttribute);
-
- var namedArgs = new CustomAttributeNamedArgument [] {
- new CustomAttributeNamedArgument (attrType.GetField ("EntryPoint"), entryPoint),
- new CustomAttributeNamedArgument (attrType.GetField ("CharSet"), charSet),
- new CustomAttributeNamedArgument (attrType.GetField ("ExactSpelling"), exactSpelling),
- new CustomAttributeNamedArgument (attrType.GetField ("SetLastError"), setLastError),
- new CustomAttributeNamedArgument (attrType.GetField ("PreserveSig"), preserveSig),
- new CustomAttributeNamedArgument (attrType.GetField ("CallingConvention"), callingConvention),
- new CustomAttributeNamedArgument (attrType.GetField ("BestFitMapping"), bestFitMapping),
- new CustomAttributeNamedArgument (attrType.GetField ("ThrowOnUnmappableChar"), throwOnUnmappableChar)
- };
-
- return new CustomAttributeData (
- attrType.GetConstructor (new[] { typeof (string) }),
- ctorArgs,
- namedArgs);
- }
-
- public override MethodInfo MakeGenericMethod (Type [] methodInstantiation)
- {
- if (methodInstantiation == null)
- throw new ArgumentNullException ("methodInstantiation");
-
- if (!IsGenericMethodDefinition)
- throw new InvalidOperationException ("not a generic method definition");
-
- /*FIXME add GetGenericArgumentsLength() internal vcall to speed this up*/
- if (GetGenericArguments ().Length != methodInstantiation.Length)
- throw new ArgumentException ("Incorrect length");
-
- bool hasUserType = false;
- foreach (Type type in methodInstantiation) {
- if (type == null)
- throw new ArgumentNullException ();
- if (!(type is RuntimeType))
- hasUserType = true;
- }
-
- if (hasUserType) {
- if (RuntimeFeature.IsDynamicCodeSupported)
- return new MethodOnTypeBuilderInst (this, methodInstantiation);
-
- throw new NotSupportedException ("User types are not supported under full aot");
- }
-
- MethodInfo ret = MakeGenericMethod_impl (methodInstantiation);
- if (ret == null)
- throw new ArgumentException (String.Format ("The method has {0} generic parameter(s) but {1} generic argument(s) were provided.", GetGenericArguments ().Length, methodInstantiation.Length));
- return ret;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern MethodInfo MakeGenericMethod_impl (Type [] types);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public override extern Type [] GetGenericArguments ();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern MethodInfo GetGenericMethodDefinition_impl ();
-
- public override MethodInfo GetGenericMethodDefinition ()
- {
- MethodInfo res = GetGenericMethodDefinition_impl ();
- if (res == null)
- throw new InvalidOperationException ();
-
- return res;
- }
-
- public override extern bool IsGenericMethodDefinition {
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- get;
- }
-
- public override extern bool IsGenericMethod {
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- get;
- }
-
- public override bool ContainsGenericParameters {
- get {
- if (IsGenericMethod) {
- foreach (Type arg in GetGenericArguments ())
- if (arg.ContainsGenericParameters)
- return true;
- }
- return DeclaringType.ContainsGenericParameters;
- }
- }
-
- public override MethodBody GetMethodBody () {
- return GetMethodBody (mhandle);
- }
-
- public override IList<CustomAttributeData> GetCustomAttributesData () {
- return CustomAttributeData.GetCustomAttributes (this);
- }
-
- public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeMethodInfo> (other);
- }
-
- [StructLayout (LayoutKind.Sequential)]
- class RuntimeConstructorInfo : ConstructorInfo
- {
-#pragma warning disable 649
- internal IntPtr mhandle;
- string name;
- Type reftype;
-#pragma warning restore 649
-
- public override Module Module {
- get {
- return GetRuntimeModule ();
- }
- }
-
- internal RuntimeModule GetRuntimeModule ()
- {
- return RuntimeTypeHandle.GetModule((RuntimeType)DeclaringType);
- }
-
- internal BindingFlags BindingFlags {
- get {
- return 0;
- }
- }
-
- RuntimeType ReflectedTypeInternal {
- get {
- return (RuntimeType) ReflectedType;
- }
- }
-
- public override MethodImplAttributes GetMethodImplementationFlags ()
- {
- return MonoMethodInfo.GetMethodImplementationFlags (mhandle);
- }
-
- public override ParameterInfo[] GetParameters ()
- {
- return MonoMethodInfo.GetParametersInfo (mhandle, this);
- }
-
- internal override ParameterInfo[] GetParametersInternal ()
- {
- return MonoMethodInfo.GetParametersInfo (mhandle, this);
- }
-
- internal override int GetParametersCount ()
- {
- var pi = MonoMethodInfo.GetParametersInfo (mhandle, this);
- return pi == null ? 0 : pi.Length;
- }
-
- /*
- * InternalInvoke() receives the parameters correctly converted by the binder
- * to match the types of the method signature.
- */
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal extern Object InternalInvoke (Object obj, Object[] parameters, out Exception exc);
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public override object Invoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
- {
- if (obj == null) {
- if (!IsStatic)
- throw new TargetException ("Instance constructor requires a target");
- } else if (!DeclaringType.IsInstanceOfType (obj)) {
- throw new TargetException ("Constructor does not match target type");
- }
-
- return DoInvoke (obj, invokeAttr, binder, parameters, culture);
- }
-
- object DoInvoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
- {
- if (binder == null)
- binder = Type.DefaultBinder;
-
- ParameterInfo[] pinfo = MonoMethodInfo.GetParametersInfo (mhandle, this);
-
- RuntimeMethodInfo.ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
-
- if (obj == null && DeclaringType.ContainsGenericParameters)
- throw new MemberAccessException ("Cannot create an instance of " + DeclaringType + " because Type.ContainsGenericParameters is true.");
-
- if ((invokeAttr & BindingFlags.CreateInstance) != 0 && DeclaringType.IsAbstract) {
- throw new MemberAccessException (String.Format ("Cannot create an instance of {0} because it is an abstract class", DeclaringType));
- }
-
- return InternalInvoke (obj, parameters, (invokeAttr & BindingFlags.DoNotWrapExceptions) == 0);
- }
-
- public object InternalInvoke (object obj, object[] parameters, bool wrapExceptions)
- {
- Exception exc;
- object o = null;
-
- if (wrapExceptions) {
- try {
- o = InternalInvoke (obj, parameters, out exc);
- } catch (MethodAccessException) {
- throw;
- } catch (OverflowException) {
- throw;
- } catch (Exception e) {
- throw new TargetInvocationException (e);
- }
- } else {
- o = InternalInvoke (obj, parameters, out exc);
- }
-
- if (exc != null)
- throw exc;
-
- return obj == null ? o : null;
- }
-
- [DebuggerHidden]
- [DebuggerStepThrough]
- public override Object Invoke (BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
- {
- return DoInvoke (null, invokeAttr, binder, parameters, culture);
- }
-
- public override RuntimeMethodHandle MethodHandle {
- get {
- return new RuntimeMethodHandle (mhandle);
- }
- }
-
- public override MethodAttributes Attributes {
- get {
- return MonoMethodInfo.GetAttributes (mhandle);
- }
- }
-
- public override CallingConventions CallingConvention {
- get {
- return MonoMethodInfo.GetCallingConvention (mhandle);
- }
- }
-
- public override bool ContainsGenericParameters {
- get {
- return DeclaringType.ContainsGenericParameters;
- }
- }
-
- public override Type ReflectedType {
- get {
- return reftype;
- }
- }
- public override Type DeclaringType {
- get {
- return MonoMethodInfo.GetDeclaringType (mhandle);
- }
- }
- public override string Name {
- get {
- if (name != null)
- return name;
- return RuntimeMethodInfo.get_name (this);
- }
- }
-
- public override bool IsDefined (Type attributeType, bool inherit) {
- return CustomAttribute.IsDefined (this, attributeType, inherit);
- }
-
- public override object[] GetCustomAttributes( bool inherit) {
- return CustomAttribute.GetCustomAttributes (this, inherit);
- }
-
- public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
- return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
- }
-
- public override MethodBody GetMethodBody () {
- return RuntimeMethodInfo.GetMethodBody (mhandle);
- }
-
- public override string ToString ()
- {
- StringBuilder sbName = new StringBuilder(Name);
- sbName.Append ("Void ");
-
- sbName.Append("(");
- RuntimeParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention);
- sbName.Append(")");
-
- return sbName.ToString();
- }
-
- public override IList<CustomAttributeData> GetCustomAttributesData ()
- {
- return CustomAttributeData.GetCustomAttributes (this);
- }
-
- public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeConstructorInfo> (other);
-
- public override int MetadataToken {
- get {
- return get_metadata_token (this);
- }
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern int get_metadata_token (RuntimeConstructorInfo method);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs b/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs
deleted file mode 100644
index 60e6708eaf7..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs
+++ /dev/null
@@ -1,391 +0,0 @@
-//
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#nullable disable
-using System.Collections;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-
-namespace System.Reflection {
-
- [StructLayout (LayoutKind.Sequential)]
- class RuntimeModule : Module
- {
-#pragma warning disable 649
- #region Sync with object-internals.h
- #region Sync with ModuleBuilder
- internal IntPtr _impl; /* a pointer to a MonoImage */
- internal Assembly assembly;
- internal string fqname;
- internal string name;
- internal string scopename;
- internal bool is_resource;
- internal int token;
- #endregion
- #endregion
-#pragma warning restore 649
-
- public
- override
- Assembly Assembly {
- get { return assembly; }
- }
-
- public
- override
- // Note: we do not ask for PathDiscovery because no path is returned here.
- // However MS Fx requires it (see FDBK23572 for details).
- string Name {
- get { return name; }
- }
-
- public
- override
- string ScopeName {
- get { return scopename; }
- }
-
- public
- override
- int MDStreamVersion {
- get {
- if (_impl == IntPtr.Zero)
- throw new NotSupportedException ();
- return GetMDStreamVersion (_impl);
- }
- }
-
- public
- override
- Guid ModuleVersionId {
- get {
- return GetModuleVersionId ();
- }
- }
-
- public override
- string FullyQualifiedName {
- get {
- return fqname;
- }
- }
-
- public
- override
- bool IsResource()
- {
- return is_resource;
- }
-
- public override
- Type[] FindTypes(TypeFilter filter, object filterCriteria)
- {
- var filtered = new List<Type> ();
- Type[] types = GetTypes ();
- foreach (Type t in types)
- if (filter (t, filterCriteria))
- filtered.Add (t);
- return filtered.ToArray ();
- }
-
- public override
- object[] GetCustomAttributes(bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, inherit);
- }
-
- public override
- object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
- }
-
- public override
- FieldInfo GetField (string name, BindingFlags bindingAttr)
- {
- if (name == null)
- throw new ArgumentNullException("name");
-
- if (IsResource ())
- return null;
-
- Type globalType = GetGlobalType (_impl);
- return (globalType != null) ? globalType.GetField (name, bindingAttr) : null;
- }
-
- public override
- FieldInfo[] GetFields (BindingFlags bindingFlags)
- {
- if (IsResource ())
- return new FieldInfo [0];
-
- Type globalType = GetGlobalType (_impl);
- return (globalType != null) ? globalType.GetFields (bindingFlags) : new FieldInfo [0];
- }
-
- public override
- int MetadataToken {
- get {
- return get_MetadataToken (this);
- }
- }
-
- protected
- override
- MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
- {
- if (IsResource ())
- return null;
-
- Type globalType = GetGlobalType (_impl);
- if (globalType == null)
- return null;
- if (types == null)
- return globalType.GetMethod (name);
- return globalType.GetMethod (name, bindingAttr, binder, callConvention, types, modifiers);
- }
-
- public
- override
- MethodInfo[] GetMethods (BindingFlags bindingFlags) {
- if (IsResource ())
- return new MethodInfo [0];
-
- Type globalType = GetGlobalType (_impl);
- return (globalType != null) ? globalType.GetMethods (bindingFlags) : new MethodInfo [0];
- }
-
- public override
- void GetPEKind (out PortableExecutableKinds peKind, out ImageFileMachine machine) {
- RuntimeModule.GetPEKind (_impl, out peKind, out machine);
- }
-
- public override
- Type GetType(string className, bool throwOnError, bool ignoreCase)
- {
- if (className == null)
- throw new ArgumentNullException ("className");
- if (className == String.Empty)
- throw new ArgumentException ("Type name can't be empty");
- return assembly.InternalGetType (this, className, throwOnError, ignoreCase);
- }
-
- public override
- bool IsDefined (Type attributeType, bool inherit)
- {
- return CustomAttribute.IsDefined (this, attributeType, inherit);
- }
-
- public
- override
- FieldInfo ResolveField (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- return ResolveField (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
- }
-
- internal static FieldInfo ResolveField (Module module, IntPtr monoModule, int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- ResolveTokenError error;
-
- IntPtr handle = ResolveFieldToken (monoModule, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
- if (handle == IntPtr.Zero)
- throw resolve_token_exception (module.Name, metadataToken, error, "Field");
- else
- return FieldInfo.GetFieldFromHandle (new RuntimeFieldHandle (handle));
- }
-
- public
- override
- MemberInfo ResolveMember (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- return ResolveMember (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
- }
-
- internal static MemberInfo ResolveMember (Module module, IntPtr monoModule, int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- ResolveTokenError error;
-
- MemberInfo m = ResolveMemberToken (monoModule, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
- if (m == null)
- throw resolve_token_exception (module.Name, metadataToken, error, "MemberInfo");
- else
- return m;
- }
-
- public
- override
- MethodBase ResolveMethod (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- return ResolveMethod (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
- }
-
- internal static MethodBase ResolveMethod (Module module, IntPtr monoModule, int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- ResolveTokenError error;
-
- IntPtr handle = ResolveMethodToken (monoModule, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
- if (handle == IntPtr.Zero)
- throw resolve_token_exception (module.Name, metadataToken, error, "MethodBase");
- else
- return RuntimeMethodInfo.GetMethodFromHandleNoGenericCheck (new RuntimeMethodHandle (handle));
- }
-
- public
- override
- string ResolveString (int metadataToken) {
- return ResolveString (this, _impl, metadataToken);
- }
-
- internal static string ResolveString (Module module, IntPtr monoModule, int metadataToken) {
- ResolveTokenError error;
-
- string s = ResolveStringToken (monoModule, metadataToken, out error);
- if (s == null)
- throw resolve_token_exception (module.Name, metadataToken, error, "string");
- else
- return s;
- }
-
- public
- override
- Type ResolveType (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- return ResolveType (this, _impl, metadataToken, genericTypeArguments, genericMethodArguments);
- }
-
- internal static Type ResolveType (Module module, IntPtr monoModule, int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments) {
- ResolveTokenError error;
-
- IntPtr handle = ResolveTypeToken (monoModule, metadataToken, ptrs_from_types (genericTypeArguments), ptrs_from_types (genericMethodArguments), out error);
- if (handle == IntPtr.Zero)
- throw resolve_token_exception (module.Name, metadataToken, error, "Type");
- else
- return Type.GetTypeFromHandle (new RuntimeTypeHandle (handle));
- }
-
- public
- override
- byte[] ResolveSignature (int metadataToken) {
- return ResolveSignature (this, _impl, metadataToken);
- }
-
- internal static byte[] ResolveSignature (Module module, IntPtr monoModule, int metadataToken) {
- ResolveTokenError error;
-
- byte[] res = ResolveSignature (monoModule, metadataToken, out error);
- if (res == null)
- throw resolve_token_exception (module.Name, metadataToken, error, "signature");
- else
- return res;
- }
-
- public override
- Type[] GetTypes()
- {
- return InternalGetTypes (_impl);
- }
-
- public override IList<CustomAttributeData> GetCustomAttributesData () {
- return CustomAttributeData.GetCustomAttributes (this);
- }
-
- internal RuntimeAssembly GetRuntimeAssembly ()
- {
- return (RuntimeAssembly)assembly;
- }
-
- internal IntPtr MonoModule {
- get {
- return _impl;
- }
- }
-
- internal Guid GetModuleVersionId ()
- {
- var guid = new byte [16];
- GetGuidInternal (_impl, guid);
- return new Guid (guid);
- }
-
- internal static Exception resolve_token_exception (string name, int metadataToken, ResolveTokenError error, string tokenType) {
- if (error == ResolveTokenError.OutOfRange)
- return new ArgumentOutOfRangeException ("metadataToken", String.Format ("Token 0x{0:x} is not valid in the scope of module {1}", metadataToken, name));
- else
- return new ArgumentException (String.Format ("Token 0x{0:x} is not a valid {1} token in the scope of module {2}", metadataToken, tokenType, name), "metadataToken");
- }
-
- internal static IntPtr[] ptrs_from_types (Type[] types) {
- if (types == null)
- return null;
- else {
- IntPtr[] res = new IntPtr [types.Length];
- for (int i = 0; i < types.Length; ++i) {
- if (types [i] == null)
- throw new ArgumentException ();
- res [i] = types [i].TypeHandle.Value;
- }
- return res;
- }
- }
-
- // This calls ves_icall_reflection_get_token, so needs a Module argument
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern int get_MetadataToken (Module module);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern int GetMDStreamVersion (IntPtr module);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern Type[] InternalGetTypes (IntPtr module);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern IntPtr GetHINSTANCE (IntPtr module);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- private static extern void GetGuidInternal (IntPtr module, byte[] guid);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern Type GetGlobalType (IntPtr module);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern IntPtr ResolveTypeToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern IntPtr ResolveMethodToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern IntPtr ResolveFieldToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern string ResolveStringToken (IntPtr module, int token, out ResolveTokenError error);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern MemberInfo ResolveMemberToken (IntPtr module, int token, IntPtr[] type_args, IntPtr[] method_args, out ResolveTokenError error);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern byte[] ResolveSignature (IntPtr module, int metadataToken, out ResolveTokenError error);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern void GetPEKind (IntPtr module, out PortableExecutableKinds peKind, out ImageFileMachine machine);
- }
-
- internal enum ResolveTokenError {
- OutOfRange,
- BadTable,
- Other
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs b/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs
deleted file mode 100644
index 2d6f842a786..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs
+++ /dev/null
@@ -1,294 +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.
-
-#nullable disable
-using System.Reflection.Emit;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Collections.Generic;
-using System.Text;
-
-namespace System.Reflection
-{
- class RuntimeParameterInfo : ParameterInfo
- {
- internal MarshalAsAttribute marshalAs;
-
- // Called by the runtime
- internal RuntimeParameterInfo (string name, Type type, int position, int attrs, object defaultValue, MemberInfo member, MarshalAsAttribute marshalAs) {
- NameImpl = name;
- ClassImpl = type;
- PositionImpl = position;
- AttrsImpl = (ParameterAttributes)attrs;
- DefaultValueImpl = defaultValue;
- MemberImpl = member;
- this.marshalAs = marshalAs;
- }
-
- internal static void FormatParameters (StringBuilder sb, ParameterInfo[] p, CallingConventions callingConvention)
- {
- for (int i = 0; i < p.Length; ++i) {
- if (i > 0)
- sb.Append (", ");
-
- Type t = p[i].ParameterType;
-
- string typeName = t.FormatTypeName ();
-
- // Legacy: Why use "ByRef" for by ref parameters? What language is this?
- // VB uses "ByRef" but it should precede (not follow) the parameter name.
- // Why don't we just use "&"?
- if (t.IsByRef) {
- sb.Append (typeName.TrimEnd (new char[] { '&' }));
- sb.Append (" ByRef");
- } else {
- sb.Append (typeName);
- }
- }
-
- if ((callingConvention & CallingConventions.VarArgs) != 0) {
- if (p.Length > 0)
- sb.Append (", ");
- sb.Append ("...");
- }
- }
-
- internal RuntimeParameterInfo (ParameterBuilder pb, Type type, MemberInfo member, int position) {
- this.ClassImpl = type;
- this.MemberImpl = member;
- if (pb != null) {
- this.NameImpl = pb.Name;
- this.PositionImpl = pb.Position - 1; // ParameterInfo.Position is zero-based
- this.AttrsImpl = (ParameterAttributes) pb.Attributes;
- } else {
- this.NameImpl = null;
- this.PositionImpl = position - 1;
- this.AttrsImpl = ParameterAttributes.None;
- }
- }
-
- internal static ParameterInfo New (ParameterBuilder pb, Type type, MemberInfo member, int position)
- {
- return new RuntimeParameterInfo (pb, type, member, position);
- }
-
- /*FIXME this constructor looks very broken in the position parameter*/
- internal RuntimeParameterInfo (ParameterInfo pinfo, Type type, MemberInfo member, int position) {
- this.ClassImpl = type;
- this.MemberImpl = member;
- if (pinfo != null) {
- this.NameImpl = pinfo.Name;
- this.PositionImpl = pinfo.Position - 1; // ParameterInfo.Position is zero-based
- this.AttrsImpl = (ParameterAttributes) pinfo.Attributes;
- } else {
- this.NameImpl = null;
- this.PositionImpl = position - 1;
- this.AttrsImpl = ParameterAttributes.None;
- }
- }
-
- internal RuntimeParameterInfo (ParameterInfo pinfo, MemberInfo member) {
- this.ClassImpl = pinfo.ParameterType;
- this.MemberImpl = member;
- this.NameImpl = pinfo.Name;
- this.PositionImpl = pinfo.Position;
- this.AttrsImpl = pinfo.Attributes;
- this.DefaultValueImpl = GetDefaultValueImpl (pinfo);
- }
-
- /* to build a ParameterInfo for the return type of a method */
- internal RuntimeParameterInfo (Type type, MemberInfo member, MarshalAsAttribute marshalAs) {
- this.ClassImpl = type;
- this.MemberImpl = member;
- this.NameImpl = null;
- this.PositionImpl = -1; // since parameter positions are zero-based, return type pos is -1
- this.AttrsImpl = ParameterAttributes.Retval;
- this.marshalAs = marshalAs;
- }
-
- public override
- object DefaultValue {
- get {
- if (ClassImpl == typeof (Decimal) || ClassImpl == typeof (Decimal?)) {
- /* default values for decimals are encoded using a custom attribute */
- DecimalConstantAttribute[] attrs = (DecimalConstantAttribute[])GetCustomAttributes (typeof (DecimalConstantAttribute), false);
- if (attrs.Length > 0)
- return attrs [0].Value;
- } else if (ClassImpl == typeof (DateTime) || ClassImpl == typeof (DateTime?)) {
- /* default values for DateTime are encoded using a custom attribute */
- DateTimeConstantAttribute[] attrs = (DateTimeConstantAttribute[])GetCustomAttributes (typeof (DateTimeConstantAttribute), false);
- if (attrs.Length > 0)
- return attrs [0].Value;
- }
- return DefaultValueImpl;
- }
- }
-
- public override
- object RawDefaultValue {
- get {
- if (DefaultValue != null && DefaultValue.GetType ().IsEnum)
- return ((Enum)DefaultValue).GetValue ();
- /*FIXME right now DefaultValue doesn't throw for reflection-only assemblies. Change this once the former is fixed.*/
- return DefaultValue;
- }
- }
-
- public
- override
- int MetadataToken {
- get {
- if (MemberImpl is PropertyInfo) {
- PropertyInfo prop = (PropertyInfo)MemberImpl;
- MethodInfo mi = prop.GetGetMethod (true);
- if (mi == null)
- mi = prop.GetSetMethod (true);
-
- return mi.GetParametersInternal () [PositionImpl].MetadataToken;
- } else if (MemberImpl is MethodBase) {
- return GetMetadataToken ();
- }
- throw new ArgumentException ("Can't produce MetadataToken for member of type " + MemberImpl.GetType ());
- }
- }
-
-
- public
- override
- object[] GetCustomAttributes (bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, inherit);
- }
-
- public
- override
- object[] GetCustomAttributes (Type attributeType, bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
- }
-
- internal object GetDefaultValueImpl (ParameterInfo pinfo)
- {
- FieldInfo field = typeof (ParameterInfo).GetField ("DefaultValueImpl", BindingFlags.Instance | BindingFlags.NonPublic);
- return field.GetValue (pinfo);
- }
-
- public
- override
- bool IsDefined( Type attributeType, bool inherit) {
- return CustomAttribute.IsDefined (this, attributeType, inherit);
- }
-
- public override IList<CustomAttributeData> GetCustomAttributesData () {
- return CustomAttributeData.GetCustomAttributes (this);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern int GetMetadataToken ();
-
- public override Type[] GetOptionalCustomModifiers () => GetCustomModifiers (true);
-
- internal object[] GetPseudoCustomAttributes ()
- {
- int count = 0;
-
- if (IsIn)
- count ++;
- if (IsOut)
- count ++;
- if (IsOptional)
- count ++;
- if (marshalAs != null)
- count ++;
-
- if (count == 0)
- return null;
- object[] attrs = new object [count];
- count = 0;
-
- if (IsIn)
- attrs [count ++] = new InAttribute ();
- if (IsOut)
- attrs [count ++] = new OutAttribute ();
- if (IsOptional)
- attrs [count ++] = new OptionalAttribute ();
-
- if (marshalAs != null) {
- attrs [count ++] = (MarshalAsAttribute)marshalAs.CloneInternal ();
- }
-
- return attrs;
- }
-
- internal CustomAttributeData[] GetPseudoCustomAttributesData ()
- {
- int count = 0;
-
- if (IsIn)
- count++;
- if (IsOut)
- count++;
- if (IsOptional)
- count++;
- if (marshalAs != null)
- count++;
-
- if (count == 0)
- return null;
- CustomAttributeData[] attrsData = new CustomAttributeData [count];
- count = 0;
-
- if (IsIn)
- attrsData [count++] = new CustomAttributeData ((typeof (InAttribute)).GetConstructor (Type.EmptyTypes));
- if (IsOut)
- attrsData [count++] = new CustomAttributeData ((typeof (OutAttribute)).GetConstructor (Type.EmptyTypes));
- if (IsOptional)
- attrsData [count++] = new CustomAttributeData ((typeof (OptionalAttribute)).GetConstructor (Type.EmptyTypes));
- if (marshalAs != null) {
- var ctorArgs = new CustomAttributeTypedArgument[] { new CustomAttributeTypedArgument (typeof (UnmanagedType), marshalAs.Value) };
- attrsData [count++] = new CustomAttributeData (
- (typeof (MarshalAsAttribute)).GetConstructor (new[] { typeof (UnmanagedType) }),
- ctorArgs,
- Array.Empty<CustomAttributeNamedArgument> ());//FIXME Get named params
- }
-
- return attrsData;
- }
-
- public override Type[] GetRequiredCustomModifiers () => GetCustomModifiers (false);
-
- public override bool HasDefaultValue {
- get {
- object defaultValue = DefaultValue;
- if (defaultValue == null)
- return true;
-
- if (defaultValue.GetType () == typeof(DBNull) || defaultValue.GetType () == typeof(Missing))
- return false;
-
- return true;
- }
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern Type[] GetTypeModifiers (Type type, MemberInfo member, int position, bool optional);
-
- internal static ParameterInfo New (ParameterInfo pinfo, Type type, MemberInfo member, int position)
- {
- return new RuntimeParameterInfo (pinfo, type, member, position);
- }
-
- internal static ParameterInfo New (ParameterInfo pinfo, MemberInfo member)
- {
- return new RuntimeParameterInfo (pinfo, member);
- }
-
- internal static ParameterInfo New (Type type, MemberInfo member, MarshalAsAttribute marshalAs)
- {
- return new RuntimeParameterInfo (type, member, marshalAs);
- }
-
- private Type[] GetCustomModifiers (bool optional) => GetTypeModifiers (ParameterType, Member, Position, optional) ?? Type.EmptyTypes;
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs b/netcore/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs
deleted file mode 100644
index d2c8abb949e..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs
+++ /dev/null
@@ -1,459 +0,0 @@
-//
-// (C) 2001 Ximian, Inc. http://www.ximian.com
-// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
-// Copyright 2013 Xamarin, Inc (http://www.xamarin.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#nullable disable
-using System.Collections.Generic;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-using Mono;
-
-namespace System.Reflection
-{
- internal struct MonoPropertyInfo {
- public Type parent;
- public Type declaring_type;
- public String name;
- public MethodInfo get_method;
- public MethodInfo set_method;
- public PropertyAttributes attrs;
- }
-
- [Flags]
- internal enum PInfo {
- Attributes = 1,
- GetMethod = 1 << 1,
- SetMethod = 1 << 2,
- ReflectedType = 1 << 3,
- DeclaringType = 1 << 4,
- Name = 1 << 5
-
- }
-
- internal delegate object GetterAdapter (object _this);
- internal delegate R Getter<T,R> (T _this);
-
- [StructLayout (LayoutKind.Sequential)]
- internal class RuntimePropertyInfo : PropertyInfo
- {
-#pragma warning disable 649
- internal IntPtr klass;
- internal IntPtr prop;
- MonoPropertyInfo info;
- PInfo cached;
- GetterAdapter cached_getter;
-#pragma warning restore 649
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern void get_property_info (RuntimePropertyInfo prop, ref MonoPropertyInfo info,
- PInfo req_info);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern Type[] GetTypeModifiers (RuntimePropertyInfo prop, bool optional);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern object get_default_value (RuntimePropertyInfo prop);
-
-
- internal BindingFlags BindingFlags {
- get {
- CachePropertyInfo (PInfo.GetMethod | PInfo.SetMethod);
- bool isPublic = info.set_method?.IsPublic == true || info.get_method?.IsPublic == true;
- bool isStatic = info.set_method?.IsStatic == true || info.get_method?.IsStatic == true;
- bool isInherited = DeclaringType != ReflectedType;
- return FilterPreCalculate (isPublic, isInherited, isStatic);
- }
- }
-
- // Copied from https://github.com/dotnet/coreclr/blob/7a24a538cd265993e5864179f51781398c28ecdf/src/System.Private.CoreLib/src/System/RtType.cs#L2022
- static BindingFlags FilterPreCalculate (bool isPublic, bool isInherited, bool isStatic)
- {
- BindingFlags bindingFlags = isPublic ? BindingFlags.Public : BindingFlags.NonPublic;
- if (isInherited) {
- // We arrange things so the DeclaredOnly flag means "include inherited members"
- bindingFlags |= BindingFlags.DeclaredOnly;
- if (isStatic)
- bindingFlags |= BindingFlags.Static | BindingFlags.FlattenHierarchy;
- else
- bindingFlags |= BindingFlags.Instance;
- }
- else {
- if (isStatic)
- bindingFlags |= BindingFlags.Static;
- else
- bindingFlags |= BindingFlags.Instance;
- }
- return bindingFlags;
- }
-
- public override Module Module {
- get {
- return GetRuntimeModule ();
- }
- }
-
- internal RuntimeType GetDeclaringTypeInternal ()
- {
- return (RuntimeType) DeclaringType;
- }
-
- RuntimeType ReflectedTypeInternal {
- get {
- return (RuntimeType) ReflectedType;
- }
- }
-
- internal RuntimeModule GetRuntimeModule ()
- {
- return GetDeclaringTypeInternal ().GetRuntimeModule ();
- }
-
- #region Object Overrides
- public override String ToString()
- {
- return FormatNameAndSig();
- }
-
- private string FormatNameAndSig()
- {
- StringBuilder sbName = new StringBuilder(PropertyType.FormatTypeName());
-
- sbName.Append(" ");
- sbName.Append(Name);
-
- var pi = GetIndexParameters ();
- if (pi.Length > 0) {
- sbName.Append (" [");
- RuntimeParameterInfo.FormatParameters (sbName, pi, 0);
- sbName.Append ("]");
- }
-
- return sbName.ToString();
- }
- #endregion
-
- void CachePropertyInfo (PInfo flags)
- {
- if ((cached & flags) != flags) {
- get_property_info (this, ref info, flags);
- cached |= flags;
- }
- }
-
- public override PropertyAttributes Attributes {
- get {
- CachePropertyInfo (PInfo.Attributes);
- return info.attrs;
- }
- }
-
- public override bool CanRead {
- get {
- CachePropertyInfo (PInfo.GetMethod);
- return (info.get_method != null);
- }
- }
-
- public override bool CanWrite {
- get {
- CachePropertyInfo (PInfo.SetMethod);
- return (info.set_method != null);
- }
- }
-
- public override Type PropertyType {
- get {
- CachePropertyInfo (PInfo.GetMethod | PInfo.SetMethod);
-
- if (info.get_method != null) {
- return info.get_method.ReturnType;
- } else {
- ParameterInfo[] parameters = info.set_method.GetParametersInternal ();
- if (parameters.Length == 0)
- throw new ArgumentException (SR.SetterHasNoParams, "indexer");
-
- return parameters [parameters.Length - 1].ParameterType;
- }
- }
- }
-
- public override Type ReflectedType {
- get {
- CachePropertyInfo (PInfo.ReflectedType);
- return info.parent;
- }
- }
-
- public override Type DeclaringType {
- get {
- CachePropertyInfo (PInfo.DeclaringType);
- return info.declaring_type;
- }
- }
-
- public override string Name {
- get {
- CachePropertyInfo (PInfo.Name);
- return info.name;
- }
- }
-
- public override MethodInfo[] GetAccessors (bool nonPublic)
- {
- int nget = 0;
- int nset = 0;
-
- CachePropertyInfo (PInfo.GetMethod | PInfo.SetMethod);
-
- if (info.set_method != null && (nonPublic || info.set_method.IsPublic))
- nset = 1;
- if (info.get_method != null && (nonPublic || info.get_method.IsPublic))
- nget = 1;
-
- MethodInfo[] res = new MethodInfo [nget + nset];
- int n = 0;
- if (nset != 0)
- res [n++] = info.set_method;
- if (nget != 0)
- res [n++] = info.get_method;
- return res;
- }
-
- public override MethodInfo GetGetMethod (bool nonPublic)
- {
- CachePropertyInfo (PInfo.GetMethod);
- if (info.get_method != null && (nonPublic || info.get_method.IsPublic))
- return info.get_method;
- else
- return null;
- }
-
- public override ParameterInfo[] GetIndexParameters ()
- {
- CachePropertyInfo (PInfo.GetMethod | PInfo.SetMethod);
- ParameterInfo[] src;
- int length;
- if (info.get_method != null) {
- src = info.get_method.GetParametersInternal ();
- length = src.Length;
- } else if (info.set_method != null) {
- src = info.set_method.GetParametersInternal ();
- length = src.Length - 1;
- } else
- return Array.Empty<ParameterInfo> ();
-
- var dest = new ParameterInfo [length];
- for (int i = 0; i < length; ++i) {
- dest [i] = RuntimeParameterInfo.New (src [i], this);
- }
- return dest;
- }
-
- public override MethodInfo GetSetMethod (bool nonPublic)
- {
- CachePropertyInfo (PInfo.SetMethod);
- if (info.set_method != null && (nonPublic || info.set_method.IsPublic))
- return info.set_method;
- else
- return null;
- }
-
-
- /*TODO verify for attribute based default values, just like ParameterInfo*/
- public override object GetConstantValue ()
- {
- return get_default_value (this);
- }
-
- public override object GetRawConstantValue() {
- return get_default_value (this);
- }
-
- // According to MSDN the inherit parameter is ignored here and
- // the behavior always defaults to inherit = false
- //
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- return CustomAttribute.IsDefined (this, attributeType, false);
- }
-
- public override object[] GetCustomAttributes (bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, false);
- }
-
- public override object[] GetCustomAttributes (Type attributeType, bool inherit)
- {
- return CustomAttribute.GetCustomAttributes (this, attributeType, false);
- }
-
-
- delegate object GetterAdapter (object _this);
- delegate R Getter<T,R> (T _this);
- delegate R StaticGetter<R> ();
-
-#pragma warning disable 169
- // Used via reflection
- static object GetterAdapterFrame<T,R> (Getter<T,R> getter, object obj)
- {
- return getter ((T)obj);
- }
-
- static object StaticGetterAdapterFrame<R> (StaticGetter<R> getter, object obj)
- {
- return getter ();
- }
-#pragma warning restore 169
-
- /*
- * The idea behing this optimization is to use a pair of delegates to simulate the same effect of doing a reflection call.
- * The first delegate cast the this argument to the right type and the second does points to the target method.
- */
- static GetterAdapter CreateGetterDelegate (MethodInfo method)
- {
- Type[] typeVector;
- Type getterType;
- object getterDelegate;
- MethodInfo adapterFrame;
- Type getterDelegateType;
- string frameName;
-
- if (method.IsStatic) {
- typeVector = new Type[] { method.ReturnType };
- getterDelegateType = typeof (StaticGetter<>);
- frameName = "StaticGetterAdapterFrame";
- } else {
- typeVector = new Type[] { method.DeclaringType, method.ReturnType };
- getterDelegateType = typeof (Getter<,>);
- frameName = "GetterAdapterFrame";
- }
-
- getterType = getterDelegateType.MakeGenericType (typeVector);
- getterDelegate = Delegate.CreateDelegate (getterType, method);
- adapterFrame = typeof (RuntimePropertyInfo).GetMethod (frameName, BindingFlags.Static | BindingFlags.NonPublic);
- adapterFrame = adapterFrame.MakeGenericMethod (typeVector);
- return (GetterAdapter)Delegate.CreateDelegate (typeof (GetterAdapter), getterDelegate, adapterFrame, true);
- }
-
- public override object GetValue (object obj, object[] index)
- {
- if ((index == null || index.Length == 0) && RuntimeFeature.IsDynamicCodeSupported) {
- /*FIXME we should check if the number of arguments matches the expected one, otherwise the error message will be pretty criptic.*/
- if (cached_getter == null) {
- MethodInfo method = GetGetMethod (true);
- if (method == null)
- throw new ArgumentException ($"Get Method not found for '{Name}'");
- if (!DeclaringType.IsValueType && !PropertyType.IsByRef && !method.ContainsGenericParameters) { //FIXME find a way to build an invoke delegate for value types.
- cached_getter = CreateGetterDelegate (method);
- // The try-catch preserves the .Invoke () behaviour
- try {
- return cached_getter (obj);
- } catch (Exception ex) {
- throw new TargetInvocationException (ex);
- }
- }
- } else {
- try {
- return cached_getter (obj);
- } catch (Exception ex) {
- throw new TargetInvocationException (ex);
- }
- }
- }
-
- return GetValue (obj, BindingFlags.Default, null, index, null);
- }
-
- public override object GetValue (object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
- {
- object ret = null;
-
- MethodInfo method = GetGetMethod (true);
- if (method == null)
- throw new ArgumentException ($"Get Method not found for '{Name}'");
-
- if (index == null || index.Length == 0)
- ret = method.Invoke (obj, invokeAttr, binder, null, culture);
- else
- ret = method.Invoke (obj, invokeAttr, binder, index, culture);
-
- return ret;
- }
-
- public override void SetValue (object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
- {
- MethodInfo method = GetSetMethod (true);
- if (method == null)
- throw new ArgumentException ("Set Method not found for '" + Name + "'");
-
- object [] parms;
- if (index == null || index.Length == 0)
- parms = new object [] {value};
- else {
- int ilen = index.Length;
- parms = new object [ilen+ 1];
- index.CopyTo (parms, 0);
- parms [ilen] = value;
- }
-
- method.Invoke (obj, invokeAttr, binder, parms, culture);
- }
-
- public override Type[] GetOptionalCustomModifiers () => GetCustomModifiers (true);
-
- public override Type[] GetRequiredCustomModifiers () => GetCustomModifiers (false);
-
- private Type[] GetCustomModifiers (bool optional) => GetTypeModifiers (this, optional) ?? Type.EmptyTypes;
-
- public override IList<CustomAttributeData> GetCustomAttributesData () {
- return CustomAttributeData.GetCustomAttributes (this);
- }
-
- public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimePropertyInfo> (other);
-
- public override int MetadataToken {
- get {
- return get_metadata_token (this);
- }
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern int get_metadata_token (RuntimePropertyInfo monoProperty);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern PropertyInfo internal_from_handle_type (IntPtr event_handle, IntPtr type_handle);
-
- internal static PropertyInfo GetPropertyFromHandle (RuntimePropertyHandle handle, RuntimeTypeHandle reflectedType)
- {
- if (handle.Value == IntPtr.Zero)
- throw new ArgumentException ("The handle is invalid.");
- PropertyInfo pi = internal_from_handle_type (handle.Value, reflectedType.Value);
- if (pi == null)
- throw new ArgumentException ("The property handle and the type handle are incompatible.");
- return pi;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.Mono.cs b/netcore/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.Mono.cs
deleted file mode 100644
index c62ffdb3720..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.Mono.cs
+++ /dev/null
@@ -1,17 +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 System.Globalization;
-using System.Reflection;
-
-namespace System.Resources
-{
- partial class ManifestBasedResourceGroveler
- {
- static Assembly InternalGetSatelliteAssembly (Assembly mainAssembly, CultureInfo culture, Version version)
- {
- return ((RuntimeAssembly)mainAssembly).InternalGetSatelliteAssembly (culture, version, throwOnFileNotFound: false);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/DependentHandle.cs b/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/DependentHandle.cs
deleted file mode 100644
index c70be1bb984..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/DependentHandle.cs
+++ /dev/null
@@ -1,73 +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.
-
-namespace System.Runtime.CompilerServices
-{
- struct Ephemeron
- {
- public object key;
- public object value;
- }
-
- //
- // Instead of dependent handles, mono uses arrays of Ephemeron objects.
- //
- struct DependentHandle
- {
- Ephemeron[] data;
-
- public DependentHandle (object primary, object secondary)
- {
- data = new Ephemeron [1];
- data [0].key = primary;
- data [0].value = secondary;
- GC.register_ephemeron_array (data);
- }
-
- public bool IsAllocated => data != null;
-
- // Getting the secondary object is more expensive than getting the first so
- // we provide a separate primary-only accessor for those times we only want the
- // primary.
- public object GetPrimary ()
- {
- if (!IsAllocated)
- throw new NotSupportedException ();
- if (data [0].key == GC.EPHEMERON_TOMBSTONE)
- return null;
- return data [0].key;
- }
-
- public object GetPrimaryAndSecondary (out object secondary)
- {
- if (!IsAllocated)
- throw new NotSupportedException ();
- if (data [0].key == GC.EPHEMERON_TOMBSTONE) {
- secondary = null;
- return null;
- }
- secondary = data [0].value;
- return data [0].key;
- }
-
- public void SetPrimary (object primary)
- {
- if (!IsAllocated)
- throw new NotSupportedException ();
- data [0].key = primary;
- }
-
- public void SetSecondary (object secondary)
- {
- if (!IsAllocated)
- throw new NotSupportedException ();
- data [0].value = secondary;
- }
-
- public void Free ()
- {
- data = null;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/JitHelpers.cs b/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/JitHelpers.cs
deleted file mode 100644
index 8c23159dd41..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/JitHelpers.cs
+++ /dev/null
@@ -1,15 +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.
-
-namespace System.Runtime.CompilerServices
-{
- static class JitHelpers
- {
- [Intrinsic]
- public static bool EnumEquals<T> (T x, T y) where T : struct, Enum => throw new NotImplementedException ();
-
- [Intrinsic]
- public static int EnumCompareTo<T> (T x, T y) where T : struct, Enum => throw new NotImplementedException ();
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/PreserveDependencyAttribute.cs b/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/PreserveDependencyAttribute.cs
deleted file mode 100644
index e68473a63ed..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/PreserveDependencyAttribute.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-//
-// PreserveDependencyAttribute.cs
-//
-// Authors:
-// Marek Safar <marek.safar@gmail.com>
-//
-// Copyright (C) 2018 Microsoft Corporation
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-namespace System.Runtime.CompilerServices {
- [AttributeUsage (AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field, AllowMultiple = true)]
- /*public*/ sealed class PreserveDependencyAttribute : Attribute {
- public PreserveDependencyAttribute (string memberSignature)
- {
- }
-
- public PreserveDependencyAttribute (string memberSignature, string typeName)
- {
- }
-
- public PreserveDependencyAttribute (string memberSignature, string typeName, string assembly)
- {
- }
-
- public string Condition { get; set; }
- }
-} \ No newline at end of file
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.Mono.cs b/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.Mono.cs
deleted file mode 100644
index 00b5c981419..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.Mono.cs
+++ /dev/null
@@ -1,19 +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.
-
-namespace System.Runtime.CompilerServices
-{
- partial class RuntimeFeature
- {
- public static bool IsDynamicCodeSupported {
- [Intrinsic] // the JIT/AOT compiler will change this flag to false for FullAOT scenarios, otherwise true
- get => IsDynamicCodeSupported;
- }
-
- public static bool IsDynamicCodeCompiled {
- [Intrinsic] // the JIT/AOT compiler will change this flag to false for FullAOT scenarios, otherwise true
- get => IsDynamicCodeCompiled;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs b/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs
deleted file mode 100644
index 43efbaa9de6..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs
+++ /dev/null
@@ -1,141 +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.
-
-namespace System.Runtime.CompilerServices
-{
- partial class RuntimeHelpers
- {
- public static void InitializeArray (Array array, RuntimeFieldHandle fldHandle)
- {
- if (array == null || fldHandle.Value == IntPtr.Zero)
- throw new ArgumentNullException ();
-
- InitializeArray (array, fldHandle.Value);
- }
-
- public static int OffsetToStringData {
- [Intrinsic]
- get => OffsetToStringData;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern int InternalGetHashCode (object o);
-
- public static int GetHashCode (object o)
- {
- return InternalGetHashCode (o);
- }
-
- public static new bool Equals (object? o1, object? o2)
- {
- if (o1 == o2)
- return true;
-
- if (o1 == null || o2 == null)
- return false;
-
- if (o1 is ValueType)
- return ValueType.DefaultEquals (o1, o2);
-
- return false;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public static extern object GetObjectValue (object obj);
-
- public static void RunClassConstructor (RuntimeTypeHandle type)
- {
- if (type.Value == IntPtr.Zero)
- throw new ArgumentException ("Handle is not initialized.", "type");
-
- RunClassConstructor (type.Value);
- }
-
- public static void EnsureSufficientExecutionStack ()
- {
- if (SufficientExecutionStack ())
- return;
-
- throw new InsufficientExecutionStackException ();
- }
-
- public static bool TryEnsureSufficientExecutionStack ()
- {
- return SufficientExecutionStack ();
- }
-
- public static void PrepareDelegate (Delegate d)
- {
- }
-
- public static void PrepareMethod (RuntimeMethodHandle method)
- {
- if (method.IsNullHandle ())
- throw new ArgumentException (SR.Argument_InvalidHandle);
- unsafe {
- PrepareMethod (method.Value, null, 0);
- }
- }
-
- public static void PrepareMethod (RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation)
- {
- if (method.IsNullHandle ())
- throw new ArgumentException (SR.Argument_InvalidHandle);
- unsafe {
- IntPtr[] instantiations = RuntimeTypeHandle.CopyRuntimeTypeHandles (instantiation, out int length);
- fixed (IntPtr* pinst = instantiations) {
- PrepareMethod (method.Value, pinst, length);
- GC.KeepAlive (instantiation);
- }
- }
- }
-
- public static void RunModuleConstructor (ModuleHandle module)
- {
- if (module == ModuleHandle.EmptyHandle)
- throw new ArgumentException ("Handle is not initialized.", "module");
-
- RunModuleConstructor (module.Value);
- }
-
- [Intrinsic]
- public static bool IsReferenceOrContainsReferences<T> () => IsReferenceOrContainsReferences<T> ();
-
- [Intrinsic]
- internal static bool IsBitwiseEquatable<T> () => IsBitwiseEquatable<T> ();
-
- [Intrinsic]
- internal static bool ObjectHasComponentSize (object obj) => ObjectHasComponentSize (obj);
-
- [Intrinsic]
- internal static bool ObjectHasReferences (object obj)
- {
- // TODO: Missing intrinsic in interpreter
- return RuntimeTypeHandle.HasReferences (obj.GetType () as RuntimeType);
- }
-
- static object GetUninitializedObjectInternal (Type type)
- {
- return GetUninitializedObjectInternal (new RuntimeTypeHandle ((RuntimeType)type).Value);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern unsafe void PrepareMethod (IntPtr method, IntPtr* instantiations, int ninst);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern object GetUninitializedObjectInternal (IntPtr type);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern void InitializeArray (Array array, IntPtr fldHandle);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern void RunClassConstructor (IntPtr type);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern void RunModuleConstructor (IntPtr module);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern bool SufficientExecutionStack ();
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/GCSettings.Mono.cs b/netcore/System.Private.CoreLib/src/System/Runtime/GCSettings.Mono.cs
deleted file mode 100644
index c7374f93975..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/GCSettings.Mono.cs
+++ /dev/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.
-
-namespace System.Runtime
-{
- partial class GCSettings
- {
- public static bool IsServerGC => false;
-
- static GCLatencyMode GetGCLatencyMode() => GCLatencyMode.Batch;
-
- static SetLatencyModeStatus SetGCLatencyMode(GCLatencyMode newLatencyMode)
- {
- if (newLatencyMode != GCLatencyMode.Batch)
- throw new PlatformNotSupportedException ();
-
- return SetLatencyModeStatus.Succeeded;
- }
-
- static GCLargeObjectHeapCompactionMode GetLOHCompactionMode() => GCLargeObjectHeapCompactionMode.Default;
-
- static void SetLOHCompactionMode (GCLargeObjectHeapCompactionMode newLOHCompactionMode)
- {
- if (newLOHCompactionMode != GCLargeObjectHeapCompactionMode.Default)
- throw new PlatformNotSupportedException ();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.Mono.cs b/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.Mono.cs
deleted file mode 100644
index 9dc17ee4aaa..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.Mono.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Runtime.InteropServices
-{
- partial class CriticalHandle
- {
- void ReleaseHandleFailed ()
- {
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.Mono.cs b/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.Mono.cs
deleted file mode 100644
index 08038b4c648..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.Mono.cs
+++ /dev/null
@@ -1,23 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.InteropServices
-{
- partial struct GCHandle
- {
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern IntPtr InternalAlloc (object value, GCHandleType type);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern void InternalFree (IntPtr handle);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern object InternalGet (IntPtr handle);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern void InternalSet (IntPtr handle, object value);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs b/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs
deleted file mode 100644
index 40bf279960a..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs
+++ /dev/null
@@ -1,448 +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 System.Collections.Generic;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-namespace System.Runtime.InteropServices
-{
- partial class Marshal
- {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static IntPtr AllocCoTaskMem (int cb);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static IntPtr AllocHGlobal (IntPtr cb);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void FreeBSTR (IntPtr ptr);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void FreeCoTaskMem (IntPtr ptr);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void FreeHGlobal (IntPtr hglobal);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public static extern int GetLastWin32Error ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void DestroyStructure (IntPtr ptr, Type structuretype);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static IntPtr OffsetOf (Type t, string fieldName);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static string PtrToStringBSTR (IntPtr ptr);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static IntPtr ReAllocCoTaskMem (IntPtr pv, int cb);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public extern static IntPtr ReAllocHGlobal (IntPtr pv, IntPtr cb);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void StructureToPtr (object structure, IntPtr ptr, bool fDeleteOld);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern unsafe static IntPtr BufferToBSTR (char* ptr, int slen);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern static bool IsPinnableType (Type type);
-
- internal static bool IsPinnable (object obj)
- {
- if (obj == null || obj is string)
- return true;
- return IsPinnableType (obj.GetType ());
- //Type type = obj.GetType ();
- //return !type.IsValueType || RuntimeTypeHandle.HasReferences (type as RuntimeType);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern void SetLastWin32Error (int error);
-
- static Exception GetExceptionForHRInternal (int errorCode, IntPtr errorInfo)
- {
- switch (errorCode) {
- case HResults.S_OK:
- case HResults.S_FALSE:
- return null;
- case HResults.COR_E_AMBIGUOUSMATCH:
- return new System.Reflection.AmbiguousMatchException ();
- case HResults.COR_E_APPLICATION:
- return new System.ApplicationException ();
- case HResults.COR_E_ARGUMENT:
- return new System.ArgumentException ();
- case HResults.COR_E_ARGUMENTOUTOFRANGE:
- return new System.ArgumentOutOfRangeException ();
- case HResults.COR_E_ARITHMETIC:
- return new System.ArithmeticException ();
- case HResults.COR_E_ARRAYTYPEMISMATCH:
- return new System.ArrayTypeMismatchException ();
- case HResults.COR_E_BADEXEFORMAT:
- return new System.BadImageFormatException ();
- case HResults.COR_E_BADIMAGEFORMAT:
- return new System.BadImageFormatException ();
- //case HResults.COR_E_CODECONTRACTFAILED:
- //return new System.Diagnostics.Contracts.ContractException ();
- //case HResults.COR_E_COMEMULATE:
- case HResults.COR_E_CUSTOMATTRIBUTEFORMAT:
- return new System.Reflection.CustomAttributeFormatException ();
- case HResults.COR_E_DATAMISALIGNED:
- return new System.DataMisalignedException ();
- case HResults.COR_E_DIRECTORYNOTFOUND:
- return new System.IO.DirectoryNotFoundException ();
- case HResults.COR_E_DIVIDEBYZERO:
- return new System.DivideByZeroException ();
- case HResults.COR_E_DLLNOTFOUND:
- return new System.DllNotFoundException ();
- case HResults.COR_E_DUPLICATEWAITOBJECT:
- return new System.DuplicateWaitObjectException ();
- case HResults.COR_E_ENDOFSTREAM:
- return new System.IO.EndOfStreamException ();
- case HResults.COR_E_ENTRYPOINTNOTFOUND:
- return new System.EntryPointNotFoundException ();
- case HResults.COR_E_EXCEPTION:
- return new System.Exception ();
- case HResults.COR_E_EXECUTIONENGINE:
- return new System.ExecutionEngineException ();
- case HResults.COR_E_FIELDACCESS:
- return new System.FieldAccessException ();
- case HResults.COR_E_FILELOAD:
- return new System.IO.FileLoadException ();
- case HResults.COR_E_FILENOTFOUND:
- return new System.IO.FileNotFoundException ();
- case HResults.COR_E_FORMAT:
- return new System.FormatException ();
- case HResults.COR_E_INDEXOUTOFRANGE:
- return new System.IndexOutOfRangeException ();
- case HResults.COR_E_INSUFFICIENTEXECUTIONSTACK:
- return new System.InsufficientExecutionStackException ();
- case HResults.COR_E_INVALIDCAST:
- return new System.InvalidCastException ();
- case HResults.COR_E_INVALIDFILTERCRITERIA:
- return new System.Reflection.InvalidFilterCriteriaException ();
- case HResults.COR_E_INVALIDOLEVARIANTTYPE:
- return new System.Runtime.InteropServices.InvalidOleVariantTypeException ();
- case HResults.COR_E_INVALIDOPERATION:
- return new System.InvalidOperationException ();
- case HResults.COR_E_INVALIDPROGRAM:
- return new System.InvalidProgramException ();
- case HResults.COR_E_IO:
- return new System.IO.IOException ();
- case HResults.COR_E_MARSHALDIRECTIVE:
- return new System.Runtime.InteropServices.MarshalDirectiveException ();
- case HResults.COR_E_MEMBERACCESS:
- return new System.MemberAccessException ();
- case HResults.COR_E_METHODACCESS:
- return new System.MethodAccessException ();
- case HResults.COR_E_MISSINGFIELD:
- return new System.MissingFieldException ();
- case HResults.COR_E_MISSINGMANIFESTRESOURCE:
- return new System.Resources.MissingManifestResourceException ();
- case HResults.COR_E_MISSINGMEMBER:
- return new System.MissingMemberException ();
- case HResults.COR_E_MISSINGMETHOD:
- return new System.MissingMethodException ();
- case HResults.COR_E_MULTICASTNOTSUPPORTED:
- return new System.MulticastNotSupportedException ();
- case HResults.COR_E_NOTFINITENUMBER:
- return new System.NotFiniteNumberException ();
- case HResults.COR_E_NOTSUPPORTED:
- return new System.NotSupportedException ();
- case HResults.COR_E_NULLREFERENCE:
- return new System.NullReferenceException ();
- case HResults.COR_E_OBJECTDISPOSED:
- return new System.ObjectDisposedException ("");
- case HResults.COR_E_OPERATIONCANCELED:
- return new System.OperationCanceledException ();
- case HResults.COR_E_OUTOFMEMORY:
- return new System.OutOfMemoryException ();
- case HResults.COR_E_OVERFLOW:
- return new System.OverflowException ();
- case HResults.COR_E_PATHTOOLONG:
- return new System.IO.PathTooLongException ();
- case HResults.COR_E_PLATFORMNOTSUPPORTED:
- return new System.PlatformNotSupportedException ();
- case HResults.COR_E_RANK:
- return new System.RankException ();
- case HResults.COR_E_REFLECTIONTYPELOAD:
- return new System.MissingMethodException ();
- case HResults.COR_E_RUNTIMEWRAPPED:
- return new System.MissingMethodException ();
- case HResults.COR_E_SECURITY:
- return new System.Security.SecurityException ();
- case HResults.COR_E_SERIALIZATION:
- return new System.Runtime.Serialization.SerializationException ();
- case HResults.COR_E_STACKOVERFLOW:
- return new System.StackOverflowException ();
- case HResults.COR_E_SYNCHRONIZATIONLOCK:
- return new System.Threading.SynchronizationLockException ();
- case HResults.COR_E_SYSTEM:
- return new System.SystemException ();
- case HResults.COR_E_TARGET:
- return new System.Reflection.TargetException ();
- case HResults.COR_E_TARGETINVOCATION:
- return new System.MissingMethodException ();
- case HResults.COR_E_TARGETPARAMCOUNT:
- return new System.Reflection.TargetParameterCountException ();
- case HResults.COR_E_THREADABORTED:
- return new System.Threading.ThreadAbortException ();
- case HResults.COR_E_THREADINTERRUPTED:
- return new System.Threading.ThreadInterruptedException ();
- case HResults.COR_E_THREADSTART:
- return new System.Threading.ThreadStartException ();
- case HResults.COR_E_THREADSTATE:
- return new System.Threading.ThreadStateException ();
- case HResults.COR_E_TYPEACCESS:
- return new System.TypeAccessException ();
- case HResults.COR_E_TYPEINITIALIZATION:
- return new System.TypeInitializationException ("");
- case HResults.COR_E_TYPELOAD:
- return new System.TypeLoadException ();
- case HResults.COR_E_TYPEUNLOADED:
- return new System.TypeUnloadedException ();
- case HResults.COR_E_UNAUTHORIZEDACCESS:
- return new System.UnauthorizedAccessException ();
- //case HResults.COR_E_UNSUPPORTEDFORMAT:
- case HResults.COR_E_VERIFICATION:
- return new System.Security.VerificationException ();
- //case HResults.E_INVALIDARG:
- case HResults.E_NOTIMPL:
- return new System.NotImplementedException ();
- //case HResults.E_POINTER:
- case HResults.RO_E_CLOSED:
- return new System.ObjectDisposedException ("");
- case HResults.COR_E_ABANDONEDMUTEX:
- case HResults.COR_E_AMBIGUOUSIMPLEMENTATION:
- case HResults.COR_E_CANNOTUNLOADAPPDOMAIN:
- case HResults.COR_E_CONTEXTMARSHAL:
- case HResults.COR_E_HOSTPROTECTION:
- case HResults.COR_E_INSUFFICIENTMEMORY:
- case HResults.COR_E_INVALIDCOMOBJECT:
- case HResults.COR_E_KEYNOTFOUND:
- case HResults.COR_E_MISSINGSATELLITEASSEMBLY:
- case HResults.COR_E_SAFEARRAYRANKMISMATCH:
- case HResults.COR_E_SAFEARRAYTYPEMISMATCH:
- case HResults.COR_E_SAFEHANDLEMISSINGATTRIBUTE:
- case HResults.COR_E_SEMAPHOREFULL:
- case HResults.COR_E_THREADSTOP:
- case HResults.COR_E_TIMEOUT:
- case HResults.COR_E_WAITHANDLECANNOTBEOPENED:
- case HResults.DISP_E_OVERFLOW:
- case HResults.E_BOUNDS:
- case HResults.E_CHANGED_STATE:
- case HResults.E_FAIL:
- case HResults.E_HANDLE:
- case HResults.ERROR_MRM_MAP_NOT_FOUND:
- case HResults.TYPE_E_TYPEMISMATCH:
- case HResults.CO_E_NOTINITIALIZED:
- case HResults.RPC_E_CHANGED_MODE:
- return new COMException ("", errorCode);
-
- case HResults.STG_E_PATHNOTFOUND:
- case HResults.CTL_E_PATHNOTFOUND: {
- return new System.IO.DirectoryNotFoundException {
- HResult = errorCode
- };
- }
- case HResults.FUSION_E_INVALID_PRIVATE_ASM_LOCATION:
- case HResults.FUSION_E_SIGNATURE_CHECK_FAILED:
- case HResults.FUSION_E_LOADFROM_BLOCKED:
- case HResults.FUSION_E_CACHEFILE_FAILED:
- case HResults.FUSION_E_ASM_MODULE_MISSING:
- case HResults.FUSION_E_INVALID_NAME:
- case HResults.FUSION_E_PRIVATE_ASM_DISALLOWED:
- case HResults.FUSION_E_HOST_GAC_ASM_MISMATCH:
- case HResults.COR_E_MODULE_HASH_CHECK_FAILED:
- case HResults.FUSION_E_REF_DEF_MISMATCH:
- case HResults.SECURITY_E_INCOMPATIBLE_SHARE:
- case HResults.SECURITY_E_INCOMPATIBLE_EVIDENCE:
- case HResults.SECURITY_E_UNVERIFIABLE:
- case HResults.COR_E_FIXUPSINEXE:
- case HResults.ERROR_TOO_MANY_OPEN_FILES:
- case HResults.ERROR_SHARING_VIOLATION:
- case HResults.ERROR_LOCK_VIOLATION:
- case HResults.ERROR_OPEN_FAILED:
- case HResults.ERROR_DISK_CORRUPT:
- case HResults.ERROR_UNRECOGNIZED_VOLUME:
- case HResults.ERROR_DLL_INIT_FAILED:
- case HResults.FUSION_E_CODE_DOWNLOAD_DISABLED:
- case HResults.CORSEC_E_MISSING_STRONGNAME:
- case HResults.MSEE_E_ASSEMBLYLOADINPROGRESS:
- case HResults.ERROR_FILE_INVALID: {
- return new System.IO.FileLoadException {
- HResult = errorCode
- };
- }
- case HResults.CTL_E_FILENOTFOUND: {
- return new System.IO.FileNotFoundException {
- HResult = errorCode
- };
- }
- default:
- return new COMException ("", errorCode);
- }
- }
-
- static void PrelinkCore (MethodInfo m)
- {
- if (!(m is RuntimeMethodInfo))
- {
- throw new ArgumentException (SR.Argument_MustBeRuntimeMethodInfo, nameof(m));
- }
-
- PrelinkInternal (m);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern static void PtrToStructureInternal (IntPtr ptr, object structure, bool allowValueClasses);
-
- static void PtrToStructureHelper (IntPtr ptr, object structure, bool allowValueClasses)
- {
- if (structure == null)
- throw new ArgumentNullException (nameof (structure));
- PtrToStructureInternal (ptr, structure, allowValueClasses);
- }
-
- static object PtrToStructureHelper (IntPtr ptr, Type structureType)
- {
- var obj = Activator.CreateInstance (structureType);
- PtrToStructureHelper (ptr, obj, true);
- return obj;
- }
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern Delegate GetDelegateForFunctionPointerInternal (IntPtr ptr, Type t);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern IntPtr GetFunctionPointerForDelegateInternal (Delegate d);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void PrelinkInternal (MethodInfo m);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern int SizeOfHelper (Type t, bool throwIfNotMarshalable);
-
- public static IntPtr GetExceptionPointers ()
- {
- throw new PlatformNotSupportedException ();
- }
-
- internal unsafe static IntPtr AllocBSTR (int length)
- {
- var res = BufferToBSTR ((char*)IntPtr.Zero, length);
- if (res == IntPtr.Zero)
- throw new OutOfMemoryException ();
- return res;
- }
-
- public unsafe static IntPtr StringToBSTR (string s)
- {
- if (s == null)
- return IntPtr.Zero;
- fixed (char* fixed_s = s)
- return BufferToBSTR (fixed_s, s.Length);
- }
-
- #region PlatformNotSupported
-
- public static int GetExceptionCode()
- {
- // Obsolete
- throw new PlatformNotSupportedException ();
- }
-
- public static byte ReadByte(Object ptr, int ofs)
- {
- // Obsolete
- throw new PlatformNotSupportedException ();
- }
-
- public static short ReadInt16(Object ptr, int ofs)
- {
- // Obsolete
- throw new PlatformNotSupportedException ();
- }
-
- public static int ReadInt32(Object ptr, int ofs)
- {
- // Obsolete
- throw new PlatformNotSupportedException ();
- }
-
- public static long ReadInt64(Object ptr, int ofs)
- {
- // Obsolete
- throw new PlatformNotSupportedException ();
- }
-
- public static void WriteByte(Object ptr, int ofs, byte val)
- {
- // Obsolete
- throw new PlatformNotSupportedException ();
- }
-
- public static void WriteInt16(Object ptr, int ofs, short val)
- {
- // Obsolete
- throw new PlatformNotSupportedException ();
- }
-
- public static void WriteInt32(Object ptr, int ofs, int val)
- {
- // Obsolete
- throw new PlatformNotSupportedException ();
- }
-
- public static void WriteInt64(Object ptr, int ofs, long val)
- {
- // Obsolete
- throw new PlatformNotSupportedException ();
- }
-
- #endregion
- }
-}
-
-namespace System
-{
- internal static partial class HResults
- {
- // DirectoryNotFoundException
- public const int STG_E_PATHNOTFOUND = unchecked((int)0x80030003);
- public const int CTL_E_PATHNOTFOUND = unchecked((int)0x800A004C);
-
- // FileNotFoundException
- public const int CTL_E_FILENOTFOUND = unchecked((int)0x800A0035);
-
- public const int FUSION_E_INVALID_PRIVATE_ASM_LOCATION = unchecked((int)0x80131041);
- public const int FUSION_E_SIGNATURE_CHECK_FAILED = unchecked((int)0x80131045);
- public const int FUSION_E_LOADFROM_BLOCKED = unchecked((int)0x80131051);
- public const int FUSION_E_CACHEFILE_FAILED = unchecked((int)0x80131052);
- public const int FUSION_E_ASM_MODULE_MISSING = unchecked((int)0x80131042);
- public const int FUSION_E_INVALID_NAME = unchecked((int)0x80131047);
- public const int FUSION_E_PRIVATE_ASM_DISALLOWED = unchecked((int)0x80131044);
- public const int FUSION_E_HOST_GAC_ASM_MISMATCH = unchecked((int)0x80131050);
- public const int COR_E_MODULE_HASH_CHECK_FAILED = unchecked((int)0x80131039);
- public const int FUSION_E_REF_DEF_MISMATCH = unchecked((int)0x80131040);
- public const int SECURITY_E_INCOMPATIBLE_SHARE = unchecked((int)0x80131401);
- public const int SECURITY_E_INCOMPATIBLE_EVIDENCE = unchecked((int)0x80131403);
- public const int SECURITY_E_UNVERIFIABLE = unchecked((int)0x80131402);
- public const int COR_E_FIXUPSINEXE = unchecked((int)0x80131019);
- public const int ERROR_TOO_MANY_OPEN_FILES = unchecked((int)0x80070004);
- public const int ERROR_SHARING_VIOLATION = unchecked((int)0x80070020);
- public const int ERROR_LOCK_VIOLATION = unchecked((int)0x80070021);
- public const int ERROR_OPEN_FAILED = unchecked((int)0x8007006E);
- public const int ERROR_DISK_CORRUPT = unchecked((int)0x80070571);
- public const int ERROR_UNRECOGNIZED_VOLUME = unchecked((int)0x800703ED);
- public const int ERROR_DLL_INIT_FAILED = unchecked((int)0x8007045A);
- public const int FUSION_E_CODE_DOWNLOAD_DISABLED = unchecked((int)0x80131048);
- public const int CORSEC_E_MISSING_STRONGNAME = unchecked((int)0x8013141b);
- public const int MSEE_E_ASSEMBLYLOADINPROGRESS = unchecked((int)0x80131016);
- public const int ERROR_FILE_INVALID = unchecked((int)0x800703EE);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/MarshalAsAttribute.Mono.cs b/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/MarshalAsAttribute.Mono.cs
deleted file mode 100644
index 89353dbdd21..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/MarshalAsAttribute.Mono.cs
+++ /dev/null
@@ -1,11 +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.
-
-namespace System.Runtime.InteropServices
-{
- [StructLayout (LayoutKind.Sequential)]
- partial class MarshalAsAttribute
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.Mono.cs b/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.Mono.cs
deleted file mode 100644
index 32605afc5e1..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.Mono.cs
+++ /dev/null
@@ -1,39 +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 System.IO;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-namespace System.Runtime.InteropServices
-{
- partial class NativeLibrary
- {
- static IntPtr LoadLibraryByName (string libraryName, Assembly assembly, DllImportSearchPath? searchPath, bool throwOnError)
- {
- return LoadByName (libraryName,
- (RuntimeAssembly)assembly,
- searchPath.HasValue,
- (uint)searchPath.GetValueOrDefault(),
- throwOnError);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static IntPtr LoadFromPath (string libraryName, bool throwOnError);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static IntPtr LoadByName (string libraryName, RuntimeAssembly callingAssembly, bool hasDllImportSearchPathFlag, uint dllImportSearchPathFlag, bool throwOnError);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void FreeLib (IntPtr handle);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static IntPtr GetSymbol (IntPtr handle, string symbolName, bool throwOnError);
-
- private static void MonoLoadLibraryCallbackStub (string libraryName, Assembly assembly, bool hasDllImportSearchPathFlags, uint dllImportSearchPathFlags, ref IntPtr dll)
- {
- dll = LoadLibraryCallbackStub (libraryName, assembly, hasDllImportSearchPathFlags, dllImportSearchPathFlags);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeHandle.Mono.cs b/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeHandle.Mono.cs
deleted file mode 100644
index c9910f92714..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeHandle.Mono.cs
+++ /dev/null
@@ -1,14 +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 System.Runtime.CompilerServices;
-
-namespace System.Runtime.InteropServices
-{
- // Mono runtime relies on exact layout
- [StructLayout (LayoutKind.Sequential)]
- public abstract partial class SafeHandle
- {
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs b/netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs
deleted file mode 100644
index bed62bbae92..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs
+++ /dev/null
@@ -1,23 +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.
-
-namespace System.Runtime.Loader
-{
- public sealed class AssemblyDependencyResolver
- {
- public AssemblyDependencyResolver (string componentAssemblyPath)
- {
- }
-
- public string ResolveAssemblyToPath (System.Reflection.AssemblyName assemblyName)
- {
- throw new NotImplementedException ();
- }
-
- public string ResolveUnmanagedDllToPath (string unmanagedDllName)
- {
- throw new NotImplementedException ();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs b/netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs
deleted file mode 100644
index eea013780c8..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs
+++ /dev/null
@@ -1,159 +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 System.IO;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-namespace System.Runtime.Loader
-{
- partial class AssemblyLoadContext
- {
- internal IntPtr NativeALC {
- get {
- return _nativeAssemblyLoadContext;
- }
- }
-
- static IntPtr InitializeAssemblyLoadContext (IntPtr thisHandlePtr, bool representsTPALoadContext, bool isCollectible)
- {
- return InternalInitializeNativeALC (thisHandlePtr, representsTPALoadContext, isCollectible);
- }
-
- static void PrepareForAssemblyLoadContextRelease (IntPtr nativeAssemblyLoadContext, IntPtr assemblyLoadContextStrong)
- {
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- Assembly InternalLoadFromPath (string assemblyPath, string nativeImagePath)
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
-
- assemblyPath = assemblyPath.Replace ('\\', Path.DirectorySeparatorChar);
- // TODO: Handle nativeImagePath
- return InternalLoadFile (NativeALC, assemblyPath, ref stackMark);
- }
-
- internal Assembly InternalLoad (byte[] arrAssembly, byte[] arrSymbols)
- {
- unsafe {
- int symbolsLength = arrSymbols?.Length ?? 0;
- fixed (byte* ptrAssembly = arrAssembly, ptrSymbols = arrSymbols)
- {
- return InternalLoadFromStream (NativeALC, new IntPtr (ptrAssembly), arrAssembly.Length,
- new IntPtr (ptrSymbols), symbolsLength);
- }
- }
- }
-
- internal static Assembly[] GetLoadedAssemblies ()
- {
- return InternalGetLoadedAssemblies ();
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static IntPtr GetLoadContextForAssembly (RuntimeAssembly rtAsm);
-
- // Returns the load context in which the specified assembly has been loaded
- public static AssemblyLoadContext? GetLoadContext (Assembly assembly)
- {
- if (assembly == null)
- throw new ArgumentNullException (nameof (assembly));
-
- AssemblyLoadContext? loadContextForAssembly = null;
-
- RuntimeAssembly? rtAsm = assembly as RuntimeAssembly;
-
- // We only support looking up load context for runtime assemblies.
- if (rtAsm != null) {
- RuntimeAssembly runtimeAssembly = rtAsm;
- IntPtr ptrAssemblyLoadContext = GetLoadContextForAssembly (runtimeAssembly);
- loadContextForAssembly = GetAssemblyLoadContext (ptrAssemblyLoadContext);
- }
-
- return loadContextForAssembly;
- }
-
- public void SetProfileOptimizationRoot (string directoryPath)
- {
- }
-
- public void StartProfileOptimization (string profile)
- {
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static Assembly InternalLoadFile (IntPtr nativeAssemblyLoadContext, string assemblyFile, ref StackCrawlMark stackMark);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static IntPtr InternalInitializeNativeALC (IntPtr thisHandlePtr, bool representsTPALoadContext, bool isCollectible);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static Assembly InternalLoadFromStream (IntPtr nativeAssemblyLoadContext, IntPtr assm, int assmLength, IntPtr symbols, int symbolsLength);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static Assembly[] InternalGetLoadedAssemblies ();
-
- internal static Assembly DoAssemblyResolve (string name)
- {
- return AssemblyResolve (null, new ResolveEventArgs (name));
- }
-
- // Invoked by Mono to resolve using the load method.
- static Assembly? MonoResolveUsingLoad (IntPtr gchALC, string assemblyName)
- {
- return Resolve (gchALC, new AssemblyName (assemblyName));
- }
-
- // Invoked by Mono to resolve using the Resolving event after
- // trying the Load override and default load context without
- // success.
- static Assembly? MonoResolveUsingResolvingEvent (IntPtr gchALC, string assemblyName)
- {
- return ResolveUsingResolvingEvent (gchALC, new AssemblyName (assemblyName));
- }
-
- // Invoked by Mono to resolve requests to load satellite assemblies.
- static Assembly? MonoResolveUsingResolveSatelliteAssembly (IntPtr gchALC, string assemblyName)
- {
- return ResolveSatelliteAssembly (gchALC, new AssemblyName (assemblyName));
- }
-
- private static AssemblyLoadContext GetAssemblyLoadContext (IntPtr gchManagedAssemblyLoadContext)
- {
- AssemblyLoadContext context;
- // This check exists because the function can be called early in startup, before the default ALC is initialized
- if (gchManagedAssemblyLoadContext == IntPtr.Zero)
- context = AssemblyLoadContext.Default;
- else
- context = (AssemblyLoadContext)(GCHandle.FromIntPtr (gchManagedAssemblyLoadContext).Target)!;
- return context;
- }
-
- private static void MonoResolveUnmanagedDll (string unmanagedDllName, IntPtr gchManagedAssemblyLoadContext, ref IntPtr dll)
- {
- AssemblyLoadContext context = GetAssemblyLoadContext (gchManagedAssemblyLoadContext);
- dll = context.LoadUnmanagedDll(unmanagedDllName);
- }
-
- private static void MonoResolveUnmanagedDllUsingEvent (string unmanagedDllName, Assembly assembly, IntPtr gchManagedAssemblyLoadContext, ref IntPtr dll)
- {
- AssemblyLoadContext context = GetAssemblyLoadContext (gchManagedAssemblyLoadContext);
- dll = context.GetResolvedUnmanagedDll(assembly, unmanagedDllName);
- }
-
-#region Copied from AssemblyLoadContext.CoreCLR.cs, modified until our AssemblyBuilder implementation is functional
- private static RuntimeAssembly? GetRuntimeAssembly(Assembly? asm)
- {
- return
- asm == null ? null :
- asm is RuntimeAssembly rtAssembly ? rtAssembly :
- //asm is System.Reflection.Emit.AssemblyBuilder ab ? ab.InternalAssembly :
- null;
- }
-#endregion
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Runtime/Remoting/Contexts/Context.cs b/netcore/System.Private.CoreLib/src/System/Runtime/Remoting/Contexts/Context.cs
deleted file mode 100644
index 33064066db8..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Runtime/Remoting/Contexts/Context.cs
+++ /dev/null
@@ -1,44 +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 System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-
-namespace System.Runtime.Remoting.Contexts {
-
- [StructLayout (LayoutKind.Sequential)]
- /* FIXME: Mono: this was public in mscorlib */
- internal class Context
- {
-#pragma warning disable 169, 414
- #region Sync with domain-internals.h
- int domain_id;
- int context_id;
- UIntPtr static_data; /* GC-tracked */
- UIntPtr data;
- #endregion
-#pragma warning restore 169, 414
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- extern static void RegisterContext (Context ctx);
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- extern static void ReleaseContext (Context ctx);
-
- public Context ()
- {
-#if false
- domain_id = Thread.GetDomainID();
- context_id = Interlocked.Increment (ref global_count);
-
- RegisterContext (this);
-#endif
- }
-
- ~Context ()
- {
- ReleaseContext (this);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/RuntimeArgumentHandle.cs b/netcore/System.Private.CoreLib/src/System/RuntimeArgumentHandle.cs
deleted file mode 100644
index 983606c90b2..00000000000
--- a/netcore/System.Private.CoreLib/src/System/RuntimeArgumentHandle.cs
+++ /dev/null
@@ -1,12 +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.
-//
-
-namespace System
-{
- public ref struct RuntimeArgumentHandle
- {
- internal IntPtr args;
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/RuntimeFieldHandle.cs b/netcore/System.Private.CoreLib/src/System/RuntimeFieldHandle.cs
deleted file mode 100644
index 46fff28b4cc..00000000000
--- a/netcore/System.Private.CoreLib/src/System/RuntimeFieldHandle.cs
+++ /dev/null
@@ -1,85 +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 System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-
-namespace System
-{
- [Serializable]
- public struct RuntimeFieldHandle : ISerializable
- {
- readonly IntPtr value;
-
- internal RuntimeFieldHandle (IntPtr v)
- {
- value = v;
- }
-
- RuntimeFieldHandle (SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public void GetObjectData (SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public IntPtr Value {
- get {
- return value;
- }
- }
-
- internal bool IsNullHandle ()
- {
- return value == IntPtr.Zero;
- }
-
- public override bool Equals (object? obj)
- {
- if (obj == null || GetType () != obj.GetType ())
- return false;
-
- return value == ((RuntimeFieldHandle)obj).Value;
- }
-
- public bool Equals (RuntimeFieldHandle handle)
- {
- return value == handle.Value;
- }
-
- public override int GetHashCode ()
- {
- return value.GetHashCode ();
- }
-
- public static bool operator == (RuntimeFieldHandle left, RuntimeFieldHandle right)
- {
- return left.Equals (right);
- }
-
- public static bool operator != (RuntimeFieldHandle left, RuntimeFieldHandle right)
- {
- return !left.Equals (right);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern void SetValueInternal (FieldInfo fi, object obj, object value);
-
- internal static void SetValue (RuntimeFieldInfo field, Object obj, Object value, RuntimeType fieldType, FieldAttributes fieldAttr, RuntimeType declaringType, ref bool domainInitialized)
- {
- SetValueInternal (field, obj, value);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static unsafe extern internal Object GetValueDirect (RuntimeFieldInfo field, RuntimeType fieldType, void *pTypedRef, RuntimeType contextType);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static unsafe extern internal void SetValueDirect (RuntimeFieldInfo field, RuntimeType fieldType, void* pTypedRef, Object value, RuntimeType contextType);
- }
-
-}
diff --git a/netcore/System.Private.CoreLib/src/System/RuntimeMethodHandle.cs b/netcore/System.Private.CoreLib/src/System/RuntimeMethodHandle.cs
deleted file mode 100644
index 2e48cb4c686..00000000000
--- a/netcore/System.Private.CoreLib/src/System/RuntimeMethodHandle.cs
+++ /dev/null
@@ -1,90 +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 System.Reflection;
-using System.Runtime.Serialization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System
-{
- [Serializable]
- public struct RuntimeMethodHandle : ISerializable
- {
- readonly IntPtr value;
-
- internal RuntimeMethodHandle (IntPtr v)
- {
- value = v;
- }
-
- RuntimeMethodHandle (SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public IntPtr Value => value;
-
- public void GetObjectData (SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException ();
- }
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern IntPtr GetFunctionPointer (IntPtr m);
-
- public IntPtr GetFunctionPointer ()
- {
- return GetFunctionPointer (value);
- }
-
- public override bool Equals (object? obj)
- {
- if (obj == null || GetType () != obj.GetType ())
- return false;
-
- return value == ((RuntimeMethodHandle)obj).Value;
- }
-
- public bool Equals (RuntimeMethodHandle handle)
- {
- return value == handle.Value;
- }
-
- public override int GetHashCode ()
- {
- return value.GetHashCode ();
- }
-
- public static bool operator == (RuntimeMethodHandle left, RuntimeMethodHandle right)
- {
- return left.Equals (right);
- }
-
- public static bool operator != (RuntimeMethodHandle left, RuntimeMethodHandle right)
- {
- return !left.Equals (right);
- }
-
- internal static string ConstructInstantiation (RuntimeMethodInfo method, TypeNameFormatFlags format)
- {
- var sb = new StringBuilder ();
- var gen_params = method.GetGenericArguments ();
- sb.Append ("[");
- for (int j = 0; j < gen_params.Length; j++) {
- if (j > 0)
- sb.Append (",");
- sb.Append (gen_params [j].Name);
- }
- sb.Append ("]");
- return sb.ToString ();
- }
-
- internal bool IsNullHandle ()
- {
- return value == IntPtr.Zero;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs
deleted file mode 100644
index e7a2bf579e0..00000000000
--- a/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs
+++ /dev/null
@@ -1,2565 +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 System.Reflection;
-using System.Globalization;
-using System.Threading;
-using System.Collections.Generic;
-using System.Runtime.Serialization;
-using System.Runtime.CompilerServices;
-using System.Diagnostics.Contracts;
-using System.Runtime.InteropServices;
-using System.Diagnostics;
-
-namespace System
-{
- // Keep this in sync with FormatFlags defined in typestring.h
- internal enum TypeNameFormatFlags
- {
- FormatBasic = 0x00000000, // Not a bitmask, simply the tersest flag settings possible
- FormatNamespace = 0x00000001, // Include namespace and/or enclosing class names in type names
- FormatFullInst = 0x00000002, // Include namespace and assembly in generic types (regardless of other flag settings)
- FormatAssembly = 0x00000004, // Include assembly display name in type names
- FormatSignature = 0x00000008, // Include signature in method names
- FormatNoVersion = 0x00000010, // Suppress version and culture information in all assembly names
-#if _DEBUG
- FormatDebug = 0x00000020, // For debug printing of types only
-#endif
- FormatAngleBrackets = 0x00000040, // Whether generic types are C<T> or C[T]
- FormatStubInfo = 0x00000080, // Include stub info like {unbox-stub}
- FormatGenericParam = 0x00000100, // Use !name and !!name for generic type and method parameters
-
- // If we want to be able to distinguish between overloads whose parameter types have the same name but come from different assemblies,
- // we can add FormatAssembly | FormatNoVersion to FormatSerialization. But we are omitting it because it is not a useful scenario
- // and including the assembly name will normally increase the size of the serialized data and also decrease the performance.
- FormatSerialization = FormatNamespace |
- FormatGenericParam |
- FormatFullInst
- }
-
- internal enum TypeNameKind
- {
- Name,
- ToString,
- SerializationName,
- FullName,
- }
-
- partial class RuntimeType
- {
- #region Definitions
-
- internal enum MemberListType
- {
- All,
- CaseSensitive,
- CaseInsensitive,
- HandleToInfo
- }
-
- // Helper to build lists of MemberInfos. Special cased to avoid allocations for lists of one element.
- private struct ListBuilder<T> where T : class
- {
- T[] _items;
- T _item;
- int _count;
- int _capacity;
-
- public ListBuilder(int capacity)
- {
- _items = null;
- _item = null;
- _count = 0;
- _capacity = capacity;
- }
-
- public T this[int index]
- {
- get
- {
- Contract.Requires(index < Count);
- return (_items != null) ? _items[index] : _item;
- }
- }
-
- public T[] ToArray()
- {
- if (_count == 0)
- return Array.Empty<T> ();
- if (_count == 1)
- return new T[1] { _item };
-
- Array.Resize(ref _items, _count);
- _capacity = _count;
- return _items;
- }
-
- public void CopyTo(Object[] array, int index)
- {
- if (_count == 0)
- return;
-
- if (_count == 1)
- {
- array[index] = _item;
- return;
- }
-
- Array.Copy(_items, 0, array, index, _count);
- }
-
- public int Count
- {
- get
- {
- return _count;
- }
- }
-
- public void Add(T item)
- {
- if (_count == 0)
- {
- _item = item;
- }
- else
- {
- if (_count == 1)
- {
- if (_capacity < 2)
- _capacity = 4;
- _items = new T[_capacity];
- _items[0] = _item;
- }
- else
- if (_capacity == _count)
- {
- int newCapacity = 2 * _capacity;
- Array.Resize(ref _items, newCapacity);
- _capacity = newCapacity;
- }
-
- _items[_count] = item;
- }
- _count++;
- }
- }
-
- #endregion
-
- #region Static Members
-
- #region Internal
-
- internal static RuntimeType GetType(String typeName, bool throwOnError, bool ignoreCase, bool reflectionOnly,
- ref StackCrawlMark stackMark)
- {
- if (typeName == null)
- throw new ArgumentNullException("typeName");
- Contract.EndContractBlock();
-
- return RuntimeTypeHandle.GetTypeByName(
- typeName, throwOnError, ignoreCase, reflectionOnly, ref stackMark, false);
- }
-
- private static void ThrowIfTypeNeverValidGenericArgument(RuntimeType type)
- {
- if (type.IsPointer || type.IsByRef || type == typeof(void))
- throw new ArgumentException(
- Environment.GetResourceString("Argument_NeverValidGenericArgument", type.ToString()));
- }
-
- internal static void SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
- {
- if (genericArguments == null)
- throw new ArgumentNullException();
- Contract.EndContractBlock();
-
- for(int i = 0; i < genericArguments.Length; i++)
- {
- if (genericArguments[i] == null)
- throw new ArgumentNullException();
-
- ThrowIfTypeNeverValidGenericArgument(genericArguments[i]);
- }
-
- if (genericArguments.Length != genericParamters.Length)
- throw new ArgumentException(
- Environment.GetResourceString("Argument_NotEnoughGenArguments", genericArguments.Length, genericParamters.Length));
- }
-
- private static void SplitName(string fullname, out string name, out string ns)
- {
- name = null;
- ns = null;
-
- if (fullname == null)
- return;
-
- // Get namespace
- int nsDelimiter = fullname.LastIndexOf(".", StringComparison.Ordinal);
- if (nsDelimiter != -1 )
- {
- ns = fullname.Substring(0, nsDelimiter);
- int nameLength = fullname.Length - ns.Length - 1;
- if (nameLength != 0)
- name = fullname.Substring(nsDelimiter + 1, nameLength);
- else
- name = "";
- Contract.Assert(fullname.Equals(ns + "." + name));
- }
- else
- {
- name = fullname;
- }
-
- }
- #endregion
-
- #region Filters
- internal static BindingFlags FilterPreCalculate(bool isPublic, bool isInherited, bool isStatic)
- {
- BindingFlags bindingFlags = isPublic ? BindingFlags.Public : BindingFlags.NonPublic;
-
- if (isInherited)
- {
- // We arrange things so the DeclaredOnly flag means "include inherited members"
- bindingFlags |= BindingFlags.DeclaredOnly;
-
- if (isStatic)
- {
- bindingFlags |= BindingFlags.Static | BindingFlags.FlattenHierarchy;
- }
- else
- {
- bindingFlags |= BindingFlags.Instance;
- }
- }
- else
- {
- if (isStatic)
- {
- bindingFlags |= BindingFlags.Static;
- }
- else
- {
- bindingFlags |= BindingFlags.Instance;
- }
- }
-
- return bindingFlags;
- }
-
- // Calculate prefixLookup, ignoreCase, and listType for use by GetXXXCandidates
- private static void FilterHelper(
- BindingFlags bindingFlags, ref string name, bool allowPrefixLookup, out bool prefixLookup,
- out bool ignoreCase, out MemberListType listType)
- {
- prefixLookup = false;
- ignoreCase = false;
-
- if (name != null)
- {
- if ((bindingFlags & BindingFlags.IgnoreCase) != 0)
- {
- name = name.ToLower(CultureInfo.InvariantCulture);
- ignoreCase = true;
- listType = MemberListType.CaseInsensitive;
- }
- else
- {
- listType = MemberListType.CaseSensitive;
- }
-
- if (allowPrefixLookup && name.EndsWith("*", StringComparison.Ordinal))
- {
- // We set prefixLookup to true if name ends with a "*".
- // We will also set listType to All so that all members are included in
- // the candidates which are later filtered by FilterApplyPrefixLookup.
- name = name.Substring(0, name.Length - 1);
- prefixLookup = true;
- listType = MemberListType.All;
- }
- }
- else
- {
- listType = MemberListType.All;
- }
- }
-
- // Used by the singular GetXXX APIs (Event, Field, Interface, NestedType) where prefixLookup is not supported.
- private static void FilterHelper(BindingFlags bindingFlags, ref string name, out bool ignoreCase, out MemberListType listType)
- {
- bool prefixLookup;
- FilterHelper(bindingFlags, ref name, false, out prefixLookup, out ignoreCase, out listType);
- }
-
- // Only called by GetXXXCandidates, GetInterfaces, and GetNestedTypes when FilterHelper has set "prefixLookup" to true.
- // Most of the plural GetXXX methods allow prefix lookups while the singular GetXXX methods mostly do not.
- private static bool FilterApplyPrefixLookup(MemberInfo memberInfo, string name, bool ignoreCase)
- {
- Contract.Assert(name != null);
-
- if (ignoreCase)
- {
- if (!memberInfo.Name.StartsWith(name, StringComparison.OrdinalIgnoreCase))
- return false;
- }
- else
- {
- if (!memberInfo.Name.StartsWith(name, StringComparison.Ordinal))
- return false;
- }
-
- return true;
- }
-
-
- // Used by FilterApplyType to perform all the filtering based on name and BindingFlags
- private static bool FilterApplyBase(
- MemberInfo memberInfo, BindingFlags bindingFlags, bool isPublic, bool isNonProtectedInternal, bool isStatic,
- string name, bool prefixLookup)
- {
- #region Preconditions
- Contract.Requires(memberInfo != null);
- Contract.Requires(name == null || (bindingFlags & BindingFlags.IgnoreCase) == 0 || (name.ToLower(CultureInfo.InvariantCulture).Equals(name)));
- #endregion
-
- #region Filter by Public & Private
- if (isPublic)
- {
- if ((bindingFlags & BindingFlags.Public) == 0)
- return false;
- }
- else
- {
- if ((bindingFlags & BindingFlags.NonPublic) == 0)
- return false;
- }
- #endregion
-
- bool isInherited = !Object.ReferenceEquals(memberInfo.DeclaringType, memberInfo.ReflectedType);
-
- #region Filter by DeclaredOnly
- if ((bindingFlags & BindingFlags.DeclaredOnly) != 0 && isInherited)
- return false;
- #endregion
-
- #region Filter by Static & Instance
- if (memberInfo.MemberType != MemberTypes.TypeInfo &&
- memberInfo.MemberType != MemberTypes.NestedType)
- {
- if (isStatic)
- {
- if ((bindingFlags & BindingFlags.FlattenHierarchy) == 0 && isInherited)
- return false;
-
- if ((bindingFlags & BindingFlags.Static) == 0)
- return false;
- }
- else
- {
- if ((bindingFlags & BindingFlags.Instance) == 0)
- return false;
- }
- }
- #endregion
-
- #region Filter by name wrt prefixLookup and implicitly by case sensitivity
- if (prefixLookup == true)
- {
- if (!FilterApplyPrefixLookup(memberInfo, name, (bindingFlags & BindingFlags.IgnoreCase) != 0))
- return false;
- }
- #endregion
-
- #region Asymmetries
- // @Asymmetry - Internal, inherited, instance, non-protected, non-virtual, non-abstract members returned
- // iff BindingFlags !DeclaredOnly, Instance and Public are present except for fields
- if (((bindingFlags & BindingFlags.DeclaredOnly) == 0) && // DeclaredOnly not present
- isInherited && // Is inherited Member
-
- (isNonProtectedInternal) && // Is non-protected internal member
- ((bindingFlags & BindingFlags.NonPublic) != 0) && // BindingFlag.NonPublic present
-
- (!isStatic) && // Is instance member
- ((bindingFlags & BindingFlags.Instance) != 0)) // BindingFlag.Instance present
- {
- MethodInfo methodInfo = memberInfo as MethodInfo;
-
- if (methodInfo == null)
- return false;
-
- if (!methodInfo.IsVirtual && !methodInfo.IsAbstract)
- return false;
- }
- #endregion
-
- return true;
- }
-
-
- // Used by GetInterface and GetNestedType(s) which don't need parameter type filtering.
- private static bool FilterApplyType(
- Type type, BindingFlags bindingFlags, string name, bool prefixLookup, string ns)
- {
- Contract.Requires((object)type != null);
- Contract.Assert(type is RuntimeType);
-
- bool isPublic = type.IsNestedPublic || type.IsPublic;
- bool isStatic = false;
-
- if (!FilterApplyBase(type, bindingFlags, isPublic, type.IsNestedAssembly, isStatic, name, prefixLookup))
- return false;
-
- if (ns != null && ns != type.Namespace)
- return false;
-
- return true;
- }
-
-
- private static bool FilterApplyMethodInfo(
- RuntimeMethodInfo method, BindingFlags bindingFlags, CallingConventions callConv, Type[] argumentTypes)
- {
- // Optimization: Pre-Calculate the method binding flags to avoid casting.
- return FilterApplyMethodBase(method, method.BindingFlags, bindingFlags, callConv, argumentTypes);
- }
-
- private static bool FilterApplyConstructorInfo(
- RuntimeConstructorInfo constructor, BindingFlags bindingFlags, CallingConventions callConv, Type[] argumentTypes)
- {
- // Optimization: Pre-Calculate the method binding flags to avoid casting.
- return FilterApplyMethodBase(constructor, constructor.BindingFlags, bindingFlags, callConv, argumentTypes);
- }
-
- // Used by GetMethodCandidates/GetConstructorCandidates, InvokeMember, and CreateInstanceImpl to perform the necessary filtering.
- // Should only be called by FilterApplyMethodInfo and FilterApplyConstructorInfo.
- private static bool FilterApplyMethodBase(
- MethodBase methodBase, BindingFlags methodFlags, BindingFlags bindingFlags, CallingConventions callConv, Type[] argumentTypes)
- {
- Contract.Requires(methodBase != null);
-
- bindingFlags ^= BindingFlags.DeclaredOnly;
- #region Check CallingConvention
- if ((callConv & CallingConventions.Any) == 0)
- {
- if ((callConv & CallingConventions.VarArgs) != 0 &&
- (methodBase.CallingConvention & CallingConventions.VarArgs) == 0)
- return false;
-
- if ((callConv & CallingConventions.Standard) != 0 &&
- (methodBase.CallingConvention & CallingConventions.Standard) == 0)
- return false;
- }
- #endregion
-
- #region If argumentTypes supplied
- if (argumentTypes != null)
- {
- ParameterInfo[] parameterInfos = methodBase.GetParametersNoCopy();
-
- if (argumentTypes.Length != parameterInfos.Length)
- {
- #region Invoke Member, Get\Set & Create Instance specific case
- // If the number of supplied arguments differs than the number in the signature AND
- // we are not filtering for a dynamic call -- InvokeMethod or CreateInstance -- filter out the method.
- if ((bindingFlags &
- (BindingFlags.InvokeMethod | BindingFlags.CreateInstance | BindingFlags.GetProperty | BindingFlags.SetProperty)) == 0)
- return false;
-
- bool testForParamArray = false;
- bool excessSuppliedArguments = argumentTypes.Length > parameterInfos.Length;
-
- if (excessSuppliedArguments)
- { // more supplied arguments than parameters, additional arguments could be vararg
- #region Varargs
- // If method is not vararg, additional arguments can not be passed as vararg
- if ((methodBase.CallingConvention & CallingConventions.VarArgs) == 0)
- {
- testForParamArray = true;
- }
- else
- {
- // If Binding flags did not include varargs we would have filtered this vararg method.
- // This Invariant established during callConv check.
- Contract.Assert((callConv & CallingConventions.VarArgs) != 0);
- }
- #endregion
- }
- else
- {// fewer supplied arguments than parameters, missing arguments could be optional
- #region OptionalParamBinding
- if ((bindingFlags & BindingFlags.OptionalParamBinding) == 0)
- {
- testForParamArray = true;
- }
- else
- {
- // From our existing code, our policy here is that if a parameterInfo
- // is optional then all subsequent parameterInfos shall be optional.
-
- // Thus, iff the first parameterInfo is not optional then this MethodInfo is no longer a canidate.
- if (!parameterInfos[argumentTypes.Length].IsOptional)
- testForParamArray = true;
- }
- #endregion
- }
-
- #region ParamArray
- if (testForParamArray)
- {
- if (parameterInfos.Length == 0)
- return false;
-
- // The last argument of the signature could be a param array.
- bool shortByMoreThanOneSuppliedArgument = argumentTypes.Length < parameterInfos.Length - 1;
-
- if (shortByMoreThanOneSuppliedArgument)
- return false;
-
- ParameterInfo lastParameter = parameterInfos[parameterInfos.Length - 1];
-
- if (!lastParameter.ParameterType.IsArray)
- return false;
-
- if (!lastParameter.IsDefined(typeof(ParamArrayAttribute), false))
- return false;
- }
- #endregion
-
- #endregion
- }
- else
- {
- #region Exact Binding
- if ((bindingFlags & BindingFlags.ExactBinding) != 0)
- {
- // Legacy behavior is to ignore ExactBinding when InvokeMember is specified.
- // Why filter by InvokeMember? If the answer is we leave this to the binder then why not leave
- // all the rest of this to the binder too? Further, what other semanitc would the binder
- // use for BindingFlags.ExactBinding besides this one? Further, why not include CreateInstance
- // in this if statement? That's just InvokeMethod with a constructor, right?
- if ((bindingFlags & (BindingFlags.InvokeMethod)) == 0)
- {
- for(int i = 0; i < parameterInfos.Length; i ++)
- {
- // a null argument type implies a null arg which is always a perfect match
- if ((object)argumentTypes[i] != null && !argumentTypes[i].MatchesParameterTypeExactly(parameterInfos[i]))
- return false;
- }
- }
- }
- #endregion
- }
- }
- #endregion
-
- return true;
- }
-
- #endregion
-
- #endregion
-
- #region Private Data Members
-
- internal static readonly RuntimeType ValueType = (RuntimeType)typeof(System.ValueType);
- internal static readonly RuntimeType EnumType = (RuntimeType)typeof(System.Enum);
-
- private static readonly RuntimeType ObjectType = (RuntimeType)typeof(System.Object);
- private static readonly RuntimeType StringType = (RuntimeType)typeof(System.String);
- private static readonly RuntimeType DelegateType = (RuntimeType)typeof(System.Delegate);
-
- #endregion
-
- #region Constructor
- internal RuntimeType() { throw new NotSupportedException(); }
- #endregion
-
- #region Type Overrides
-
- #region Get XXXInfo Candidates
- private ListBuilder<MethodInfo> GetMethodCandidates(
- String name, BindingFlags bindingAttr, CallingConventions callConv,
- Type[] types, int genericParamCount, bool allowPrefixLookup)
- {
- bool prefixLookup, ignoreCase;
- MemberListType listType;
- FilterHelper(bindingAttr, ref name, allowPrefixLookup, out prefixLookup, out ignoreCase, out listType);
-
- RuntimeMethodInfo[] cache = GetMethodsByName (name, bindingAttr, listType, this);
- ListBuilder<MethodInfo> candidates = new ListBuilder<MethodInfo>(cache.Length);
-
- for (int i = 0; i < cache.Length; i++)
- {
- RuntimeMethodInfo methodInfo = cache[i];
- if (genericParamCount != -1) {
- bool is_generic = methodInfo.IsGenericMethod;
- if (genericParamCount == 0 && is_generic)
- continue;
- else if (genericParamCount > 0 && !is_generic)
- continue;
- var args = methodInfo.GetGenericArguments ();
- if (args.Length != genericParamCount)
- continue;
- }
- if (FilterApplyMethodInfo(methodInfo, bindingAttr, callConv, types) &&
- (!prefixLookup || FilterApplyPrefixLookup(methodInfo, name, ignoreCase)))
- {
- candidates.Add(methodInfo);
- }
- }
-
- return candidates;
- }
-
- private ListBuilder<ConstructorInfo> GetConstructorCandidates(
- string name, BindingFlags bindingAttr, CallingConventions callConv,
- Type[] types, bool allowPrefixLookup)
- {
- bool prefixLookup, ignoreCase;
- MemberListType listType;
- FilterHelper(bindingAttr, ref name, allowPrefixLookup, out prefixLookup, out ignoreCase, out listType);
-
- if (!string.IsNullOrEmpty (name) && name != ConstructorInfo.ConstructorName && name != ConstructorInfo.TypeConstructorName)
- return new ListBuilder<ConstructorInfo> (0);
- RuntimeConstructorInfo[] cache = GetConstructors_internal (bindingAttr, this);
- ListBuilder<ConstructorInfo> candidates = new ListBuilder<ConstructorInfo>(cache.Length);
- for (int i = 0; i < cache.Length; i++)
- {
- RuntimeConstructorInfo constructorInfo = cache[i];
- if (FilterApplyConstructorInfo(constructorInfo, bindingAttr, callConv, types) &&
- (!prefixLookup || FilterApplyPrefixLookup(constructorInfo, name, ignoreCase)))
- {
- candidates.Add(constructorInfo);
- }
- }
-
- return candidates;
- }
-
-
- private ListBuilder<PropertyInfo> GetPropertyCandidates(
- String name, BindingFlags bindingAttr, Type[] types, bool allowPrefixLookup)
- {
- bool prefixLookup, ignoreCase;
- MemberListType listType;
- FilterHelper(bindingAttr, ref name, allowPrefixLookup, out prefixLookup, out ignoreCase, out listType);
-
- RuntimePropertyInfo[] cache = GetPropertiesByName (name, bindingAttr, listType, this);
- bindingAttr ^= BindingFlags.DeclaredOnly;
-
- ListBuilder<PropertyInfo> candidates = new ListBuilder<PropertyInfo>(cache.Length);
- for (int i = 0; i < cache.Length; i++)
- {
- RuntimePropertyInfo propertyInfo = cache[i];
- if ((bindingAttr & propertyInfo.BindingFlags) == propertyInfo.BindingFlags &&
- (!prefixLookup || FilterApplyPrefixLookup(propertyInfo, name, ignoreCase)) &&
- (types == null || (propertyInfo.GetIndexParameters().Length == types.Length)))
- {
- candidates.Add(propertyInfo);
- }
- }
-
- return candidates;
- }
-
- private ListBuilder<EventInfo> GetEventCandidates(String name, BindingFlags bindingAttr, bool allowPrefixLookup)
- {
- bool prefixLookup, ignoreCase;
- MemberListType listType;
- FilterHelper(bindingAttr, ref name, allowPrefixLookup, out prefixLookup, out ignoreCase, out listType);
-
- RuntimeEventInfo[] cache = GetEvents_internal (name, bindingAttr, listType, this);
- bindingAttr ^= BindingFlags.DeclaredOnly;
-
- ListBuilder<EventInfo> candidates = new ListBuilder<EventInfo>(cache.Length);
- for (int i = 0; i < cache.Length; i++)
- {
- RuntimeEventInfo eventInfo = cache[i];
- if ((bindingAttr & eventInfo.BindingFlags) == eventInfo.BindingFlags &&
- (!prefixLookup || FilterApplyPrefixLookup(eventInfo, name, ignoreCase)))
- {
- candidates.Add(eventInfo);
- }
- }
-
- return candidates;
- }
-
- private ListBuilder<FieldInfo> GetFieldCandidates(String name, BindingFlags bindingAttr, bool allowPrefixLookup)
- {
- bool prefixLookup, ignoreCase;
- MemberListType listType;
- FilterHelper(bindingAttr, ref name, allowPrefixLookup, out prefixLookup, out ignoreCase, out listType);
-
- RuntimeFieldInfo[] cache = GetFields_internal (name, bindingAttr, listType, this);
- bindingAttr ^= BindingFlags.DeclaredOnly;
-
- ListBuilder<FieldInfo> candidates = new ListBuilder<FieldInfo>(cache.Length);
- for (int i = 0; i < cache.Length; i++)
- {
- RuntimeFieldInfo fieldInfo = cache[i];
- if ((bindingAttr & fieldInfo.BindingFlags) == fieldInfo.BindingFlags &&
- (!prefixLookup || FilterApplyPrefixLookup(fieldInfo, name, ignoreCase)))
- {
- candidates.Add(fieldInfo);
- }
- }
-
- return candidates;
- }
-
- private ListBuilder<Type> GetNestedTypeCandidates(String fullname, BindingFlags bindingAttr, bool allowPrefixLookup)
- {
- bool prefixLookup, ignoreCase;
- bindingAttr &= ~BindingFlags.Static;
- string name, ns;
- MemberListType listType;
- SplitName(fullname, out name, out ns);
- FilterHelper(bindingAttr, ref name, allowPrefixLookup, out prefixLookup, out ignoreCase, out listType);
-
- RuntimeType[] cache = GetNestedTypes_internal (name, bindingAttr, listType);
- ListBuilder<Type> candidates = new ListBuilder<Type>(cache.Length);
- for (int i = 0; i < cache.Length; i++)
- {
- RuntimeType nestedClass = cache[i];
- if (FilterApplyType(nestedClass, bindingAttr, name, prefixLookup, ns))
- {
- candidates.Add(nestedClass);
- }
- }
-
- return candidates;
- }
-
- #endregion
-
- #region Get All XXXInfos
- public override MethodInfo[] GetMethods(BindingFlags bindingAttr)
- {
- return GetMethodCandidates(null, bindingAttr, CallingConventions.Any, null, -1, false).ToArray();
- }
-
- [ComVisible(true)]
- public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
- {
- return GetConstructorCandidates(null, bindingAttr, CallingConventions.Any, null, false).ToArray();
- }
-
- public override PropertyInfo[] GetProperties(BindingFlags bindingAttr)
- {
- return GetPropertyCandidates(null, bindingAttr, null, false).ToArray();
- }
-
- public override EventInfo[] GetEvents(BindingFlags bindingAttr)
- {
- return GetEventCandidates(null, bindingAttr, false).ToArray();
- }
-
- public override FieldInfo[] GetFields(BindingFlags bindingAttr)
- {
- return GetFieldCandidates(null, bindingAttr, false).ToArray();
- }
-
- public override Type[] GetNestedTypes(BindingFlags bindingAttr)
- {
- return GetNestedTypeCandidates(null, bindingAttr, false).ToArray();
- }
-
- public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
- {
- ListBuilder<MethodInfo> methods = GetMethodCandidates(null, bindingAttr, CallingConventions.Any, null, -1, false);
- ListBuilder<ConstructorInfo> constructors = GetConstructorCandidates(null, bindingAttr, CallingConventions.Any, null, false);
- ListBuilder<PropertyInfo> properties = GetPropertyCandidates(null, bindingAttr, null, false);
- ListBuilder<EventInfo> events = GetEventCandidates(null, bindingAttr, false);
- ListBuilder<FieldInfo> fields = GetFieldCandidates(null, bindingAttr, false);
- ListBuilder<Type> nestedTypes = GetNestedTypeCandidates(null, bindingAttr, false);
- // Interfaces are excluded from the result of GetMembers
-
- MemberInfo[] members = new MemberInfo[
- methods.Count +
- constructors.Count +
- properties.Count +
- events.Count +
- fields.Count +
- nestedTypes.Count];
-
- int i = 0;
- methods.CopyTo(members, i); i += methods.Count;
- constructors.CopyTo(members, i); i += constructors.Count;
- properties.CopyTo(members, i); i += properties.Count;
- events.CopyTo(members, i); i += events.Count;
- fields.CopyTo(members, i); i += fields.Count;
- nestedTypes.CopyTo(members, i); i += nestedTypes.Count;
- Contract.Assert(i == members.Length);
-
- return members;
- }
-
- #endregion
-
- protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[]? types, ParameterModifier[]? modifiers)
- {
- return GetMethodImpl (name, -1, bindingAttr, binder, callConvention, types, modifiers);
- }
-
- protected override MethodInfo GetMethodImpl(String name, int genericParamCount,
- BindingFlags bindingAttr, Binder? binder, CallingConventions callConv,
- Type[]? types, ParameterModifier[]? modifiers)
- {
- ListBuilder<MethodInfo> candidates = GetMethodCandidates(name, bindingAttr, callConv, types, genericParamCount, false);
- if (candidates.Count == 0)
- return null;
-
- if (types == null || types.Length == 0)
- {
- MethodInfo firstCandidate = candidates[0];
-
- if (candidates.Count == 1)
- {
- return firstCandidate;
- }
- else if (types == null)
- {
- for (int j = 1; j < candidates.Count; j++)
- {
- MethodInfo methodInfo = candidates[j];
- if (!System.DefaultBinder.CompareMethodSig (methodInfo, firstCandidate))
- throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
- }
-
- // All the methods have the exact same name and sig so return the most derived one.
- return System.DefaultBinder.FindMostDerivedNewSlotMeth(candidates.ToArray(), candidates.Count) as MethodInfo;
- }
- }
-
- if (binder == null)
- binder = DefaultBinder;
-
- return binder.SelectMethod(bindingAttr, candidates.ToArray(), types, modifiers) as MethodInfo;
- }
-
- protected override ConstructorInfo GetConstructorImpl(
- BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention,
- Type[] types, ParameterModifier[]? modifiers)
- {
- ListBuilder<ConstructorInfo> candidates = GetConstructorCandidates(null, bindingAttr, CallingConventions.Any, types, false);
-
- if (candidates.Count == 0)
- return null;
-
- if (types.Length == 0 && candidates.Count == 1)
- {
- ConstructorInfo firstCandidate = candidates[0];
-
- ParameterInfo[] parameters = firstCandidate.GetParametersNoCopy();
- if (parameters == null || parameters.Length == 0)
- {
- return firstCandidate;
- }
- }
-
- if ((bindingAttr & BindingFlags.ExactBinding) != 0)
- return System.DefaultBinder.ExactBinding(candidates.ToArray(), types, modifiers) as ConstructorInfo;
-
- if (binder == null)
- binder = DefaultBinder;
-
- return binder.SelectMethod(bindingAttr, candidates.ToArray(), types, modifiers) as ConstructorInfo;
- }
-
-
- protected override PropertyInfo GetPropertyImpl(
- String name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
- {
- if (name == null) throw new ArgumentNullException();
- Contract.EndContractBlock();
-
- ListBuilder<PropertyInfo> candidates = GetPropertyCandidates(name, bindingAttr, types, false);
-
- if (candidates.Count == 0)
- return null;
-
- if (types == null || types.Length == 0)
- {
- // no arguments
- if (candidates.Count == 1)
- {
- PropertyInfo firstCandidate = candidates[0];
-
- if ((object)returnType != null && !returnType.IsEquivalentTo(firstCandidate.PropertyType))
- return null;
-
- return firstCandidate;
- }
- else
- {
- if ((object)returnType == null)
- // if we are here we have no args or property type to select over and we have more than one property with that name
- throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
- }
- }
-
- if ((bindingAttr & BindingFlags.ExactBinding) != 0)
- return System.DefaultBinder.ExactPropertyBinding(candidates.ToArray(), returnType, types, modifiers);
-
- if (binder == null)
- binder = DefaultBinder;
-
- return binder.SelectProperty(bindingAttr, candidates.ToArray(), returnType, types, modifiers);
- }
-
- public override EventInfo GetEvent(String name, BindingFlags bindingAttr)
- {
- if (name == null) throw new ArgumentNullException();
- Contract.EndContractBlock();
-
- bool ignoreCase;
- MemberListType listType;
- FilterHelper(bindingAttr, ref name, out ignoreCase, out listType);
-
- RuntimeEventInfo[] cache = GetEvents_internal (name, bindingAttr, listType, this);
- EventInfo match = null;
-
- bindingAttr ^= BindingFlags.DeclaredOnly;
-
- for (int i = 0; i < cache.Length; i++)
- {
- RuntimeEventInfo eventInfo = cache[i];
- if ((bindingAttr & eventInfo.BindingFlags) == eventInfo.BindingFlags)
- {
- if (match != null)
- throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
-
- match = eventInfo;
- }
- }
-
- return match;
- }
-
- public override FieldInfo GetField(String name, BindingFlags bindingAttr)
- {
- if (name == null) throw new ArgumentNullException();
- Contract.EndContractBlock();
-
- bool ignoreCase;
- MemberListType listType;
- FilterHelper(bindingAttr, ref name, out ignoreCase, out listType);
-
- RuntimeFieldInfo[] cache = GetFields_internal (name, bindingAttr, listType, this);
- FieldInfo match = null;
-
- bindingAttr ^= BindingFlags.DeclaredOnly;
- bool multipleStaticFieldMatches = false;
-
- for (int i = 0; i < cache.Length; i++)
- {
- RuntimeFieldInfo fieldInfo = cache[i];
- if ((bindingAttr & fieldInfo.BindingFlags) == fieldInfo.BindingFlags)
- {
- if (match != null)
- {
- if (Object.ReferenceEquals(fieldInfo.DeclaringType, match.DeclaringType))
- throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
-
- if ((match.DeclaringType.IsInterface == true) && (fieldInfo.DeclaringType.IsInterface == true))
- multipleStaticFieldMatches = true;
- }
-
- if (match == null || fieldInfo.DeclaringType.IsSubclassOf(match.DeclaringType) || match.DeclaringType.IsInterface)
- match = fieldInfo;
- }
- }
-
- if (multipleStaticFieldMatches && match.DeclaringType.IsInterface)
- throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
-
- return match;
- }
-
- public override Type GetInterface(String fullname, bool ignoreCase)
- {
- if (fullname == null) throw new ArgumentNullException();
- Contract.EndContractBlock();
-
- BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.NonPublic;
-
- bindingAttr &= ~BindingFlags.Static;
-
- if (ignoreCase)
- bindingAttr |= BindingFlags.IgnoreCase;
-
- string name, ns;
- MemberListType listType;
- SplitName(fullname, out name, out ns);
- FilterHelper(bindingAttr, ref name, out ignoreCase, out listType);
-
- List<RuntimeType> list = null;
- var nameComparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
- foreach (RuntimeType t in GetInterfaces ()) {
-
- if (!String.Equals(t.Name, name, nameComparison)) {
- continue;
- }
-
- if (list == null)
- list = new List<RuntimeType> (2);
-
- list.Add (t);
- }
-
- if (list == null)
- return null;
-
- var cache = list.ToArray ();
- RuntimeType match = null;
-
- for (int i = 0; i < cache.Length; i++)
- {
- RuntimeType iface = cache[i];
- if (FilterApplyType(iface, bindingAttr, name, false, ns))
- {
- if (match != null)
- throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
-
- match = iface;
- }
- }
-
- return match;
- }
-
- public override Type GetNestedType(String fullname, BindingFlags bindingAttr)
- {
- if (fullname == null) throw new ArgumentNullException();
- Contract.EndContractBlock();
-
- bool ignoreCase;
- bindingAttr &= ~BindingFlags.Static;
- string name, ns;
- MemberListType listType;
- SplitName(fullname, out name, out ns);
- FilterHelper(bindingAttr, ref name, out ignoreCase, out listType);
- RuntimeType[] cache = GetNestedTypes_internal (name, bindingAttr, listType);
- RuntimeType match = null;
-
- for (int i = 0; i < cache.Length; i++)
- {
- RuntimeType nestedType = cache[i];
- if (FilterApplyType(nestedType, bindingAttr, name, false, ns))
- {
- if (match != null)
- throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
-
- match = nestedType;
- }
- }
-
- return match;
- }
-
- public override MemberInfo[] GetMember(String name, MemberTypes type, BindingFlags bindingAttr)
- {
- if (name == null) throw new ArgumentNullException();
- Contract.EndContractBlock();
-
- ListBuilder<MethodInfo> methods = new ListBuilder<MethodInfo>();
- ListBuilder<ConstructorInfo> constructors = new ListBuilder<ConstructorInfo>();
- ListBuilder<PropertyInfo> properties = new ListBuilder<PropertyInfo>();
- ListBuilder<EventInfo> events = new ListBuilder<EventInfo>();
- ListBuilder<FieldInfo> fields = new ListBuilder<FieldInfo>();
- ListBuilder<Type> nestedTypes = new ListBuilder<Type>();
-
- int totalCount = 0;
-
- // Methods
- if ((type & MemberTypes.Method) != 0)
- {
- methods = GetMethodCandidates(name, bindingAttr, CallingConventions.Any, null, -1, true);
- if (type == MemberTypes.Method)
- return methods.ToArray();
- totalCount += methods.Count;
- }
-
- // Constructors
- if ((type & MemberTypes.Constructor) != 0)
- {
- constructors = GetConstructorCandidates(name, bindingAttr, CallingConventions.Any, null, true);
- if (type == MemberTypes.Constructor)
- return constructors.ToArray();
- totalCount += constructors.Count;
- }
-
- // Properties
- if ((type & MemberTypes.Property) != 0)
- {
- properties = GetPropertyCandidates(name, bindingAttr, null, true);
- if (type == MemberTypes.Property)
- return properties.ToArray();
- totalCount += properties.Count;
- }
-
- // Events
- if ((type & MemberTypes.Event) != 0)
- {
- events = GetEventCandidates(name, bindingAttr, true);
- if (type == MemberTypes.Event)
- return events.ToArray();
- totalCount += events.Count;
- }
-
- // Fields
- if ((type & MemberTypes.Field) != 0)
- {
- fields = GetFieldCandidates(name, bindingAttr, true);
- if (type == MemberTypes.Field)
- return fields.ToArray();
- totalCount += fields.Count;
- }
-
- // NestedTypes
- if ((type & (MemberTypes.NestedType | MemberTypes.TypeInfo)) != 0)
- {
- nestedTypes = GetNestedTypeCandidates(name, bindingAttr, true);
- if (type == MemberTypes.NestedType || type == MemberTypes.TypeInfo)
- return nestedTypes.ToArray();
- totalCount += nestedTypes.Count;
- }
-
- MemberInfo[] compressMembers = (type == (MemberTypes.Method | MemberTypes.Constructor)) ?
- new MethodBase[totalCount] : new MemberInfo[totalCount];
-
- int i = 0;
- methods.CopyTo(compressMembers, i); i += methods.Count;
- constructors.CopyTo(compressMembers, i); i += constructors.Count;
- properties.CopyTo(compressMembers, i); i += properties.Count;
- events.CopyTo(compressMembers, i); i += events.Count;
- fields.CopyTo(compressMembers, i); i += fields.Count;
- nestedTypes.CopyTo(compressMembers, i); i += nestedTypes.Count;
- Contract.Assert(i == compressMembers.Length);
-
- return compressMembers;
- }
- #endregion
-
-
- #region Hierarchy
-
- // Reflexive, symmetric, transitive.
- public override bool IsEquivalentTo(Type? other)
- {
- RuntimeType otherRtType = other as RuntimeType;
- if ((object)otherRtType == null)
- return false;
-
- if (otherRtType == this)
- return true;
-
- // It's not worth trying to perform further checks in managed
- // as they would lead to FCalls anyway.
- return RuntimeTypeHandle.IsEquivalentTo(this, otherRtType);
- }
-
- #endregion
-
- #region Attributes
-
- internal bool IsDelegate()
- {
- return GetBaseType() == typeof(System.MulticastDelegate);
- }
-
- public override bool IsEnum => GetBaseType() == EnumType;
-
- public override GenericParameterAttributes GenericParameterAttributes
- {
- get
- {
- if (!IsGenericParameter)
- throw new InvalidOperationException(Environment.GetResourceString("Arg_NotGenericParameter"));
- Contract.EndContractBlock();
-
- return GetGenericParameterAttributes ();
- }
- }
-
- #endregion
-
- #region Generics
-
- internal RuntimeType[] GetGenericArgumentsInternal()
- {
- return (RuntimeType[]) GetGenericArgumentsInternal (true);
- }
-
- public override Type[] GetGenericArguments()
- {
- Type[] types = GetGenericArgumentsInternal (false);
-
- if (types == null)
- types = Array.Empty<Type> ();
-
- return types;
- }
-
- public override Type MakeGenericType(Type[] instantiation)
- {
- if (instantiation == null)
- throw new ArgumentNullException("instantiation");
- Contract.EndContractBlock();
-
- RuntimeType[] instantiationRuntimeType = new RuntimeType[instantiation.Length];
-
- if (!IsGenericTypeDefinition)
- throw new InvalidOperationException(
- Environment.GetResourceString("Arg_NotGenericTypeDefinition", this));
-
- if (GetGenericArguments().Length != instantiation.Length)
- throw new ArgumentException(Environment.GetResourceString("Argument_GenericArgsCount"), "instantiation");
-
- for (int i = 0; i < instantiation.Length; i ++)
- {
- Type instantiationElem = instantiation[i];
- if (instantiationElem == null)
- throw new ArgumentNullException();
-
- RuntimeType rtInstantiationElem = instantiationElem as RuntimeType;
-
- if (rtInstantiationElem == null)
- {
- if (instantiationElem.IsSignatureType)
- return MakeGenericSignatureType (this, instantiation);
- Type[] instantiationCopy = new Type[instantiation.Length];
- for (int iCopy = 0; iCopy < instantiation.Length; iCopy++)
- instantiationCopy[iCopy] = instantiation[iCopy];
- instantiation = instantiationCopy;
-
- throw new NotImplementedException ();
- }
-
- instantiationRuntimeType[i] = rtInstantiationElem;
- }
-
- RuntimeType[] genericParameters = GetGenericArgumentsInternal();
-
- SanityCheckGenericArguments(instantiationRuntimeType, genericParameters);
-
- Type ret = null;
- ret = MakeGenericType (this, instantiationRuntimeType);
- if (ret == null)
- throw new TypeLoadException ();
- return ret;
- }
-
- public override int GenericParameterPosition
- {
- get
- {
- if (!IsGenericParameter)
- throw new InvalidOperationException(Environment.GetResourceString("Arg_NotGenericParameter"));
- Contract.EndContractBlock();
- return GetGenericParameterPosition ();
- }
- }
-
- #endregion
-
- #region Invoke Member
- private const BindingFlags MemberBindingMask = (BindingFlags)0x000000FF;
- private const BindingFlags InvocationMask = (BindingFlags)0x0000FF00;
- private const BindingFlags BinderNonCreateInstance = BindingFlags.InvokeMethod | BinderGetSetField | BinderGetSetProperty;
- private const BindingFlags BinderGetSetProperty = BindingFlags.GetProperty | BindingFlags.SetProperty;
- private const BindingFlags BinderSetInvokeProperty = BindingFlags.InvokeMethod | BindingFlags.SetProperty;
- private const BindingFlags BinderGetSetField = BindingFlags.GetField | BindingFlags.SetField;
- private const BindingFlags BinderSetInvokeField = BindingFlags.SetField | BindingFlags.InvokeMethod;
- private const BindingFlags BinderNonFieldGetSet = (BindingFlags)0x00FFF300;
- private const BindingFlags ClassicBindingMask =
- BindingFlags.InvokeMethod | BindingFlags.GetProperty | BindingFlags.SetProperty |
- BindingFlags.PutDispProperty | BindingFlags.PutRefDispProperty;
- private static RuntimeType s_typedRef = (RuntimeType)typeof(TypedReference);
-
-
- [DebuggerStepThroughAttribute]
- [Diagnostics.DebuggerHidden]
- public override Object InvokeMember(
- String name, BindingFlags bindingFlags, Binder? binder, Object? target,
- Object?[]? providedArgs, ParameterModifier[]? modifiers, CultureInfo? culture, String[]? namedParams)
- {
- if (IsGenericParameter)
- throw new InvalidOperationException(Environment.GetResourceString("Arg_GenericParameter"));
- Contract.EndContractBlock();
-
- #region Preconditions
- if ((bindingFlags & InvocationMask) == 0)
- // "Must specify binding flags describing the invoke operation required."
- throw new ArgumentException(Environment.GetResourceString("Arg_NoAccessSpec"),"bindingFlags");
-
- // Provide a default binding mask if none is provided
- if ((bindingFlags & MemberBindingMask) == 0)
- {
- bindingFlags |= BindingFlags.Instance | BindingFlags.Public;
-
- if ((bindingFlags & BindingFlags.CreateInstance) == 0)
- bindingFlags |= BindingFlags.Static;
- }
-
- // There must not be more named parameters than provided arguments
- if (namedParams != null)
- {
- if (providedArgs != null)
- {
- if (namedParams.Length > providedArgs.Length)
- // "Named parameter array can not be bigger than argument array."
- throw new ArgumentException(Environment.GetResourceString("Arg_NamedParamTooBig"), "namedParams");
- }
- else
- {
- if (namedParams.Length != 0)
- // "Named parameter array can not be bigger than argument array."
- throw new ArgumentException(Environment.GetResourceString("Arg_NamedParamTooBig"), "namedParams");
- }
- }
- #endregion
-
- #region Check that any named paramters are not null
- if (namedParams != null && Array.IndexOf(namedParams, null) != -1)
- // "Named parameter value must not be null."
- throw new ArgumentException(Environment.GetResourceString("Arg_NamedParamNull"),"namedParams");
- #endregion
-
- int argCnt = (providedArgs != null) ? providedArgs.Length : 0;
-
- #region Get a Binder
- if (binder == null)
- binder = DefaultBinder;
-
- #endregion
-
- #region Delegate to Activator.CreateInstance
- if ((bindingFlags & BindingFlags.CreateInstance) != 0)
- {
- if ((bindingFlags & BindingFlags.CreateInstance) != 0 && (bindingFlags & BinderNonCreateInstance) != 0)
- // "Can not specify both CreateInstance and another access type."
- throw new ArgumentException(Environment.GetResourceString("Arg_CreatInstAccess"),"bindingFlags");
-
- return Activator.CreateInstance(this, bindingFlags, binder, providedArgs, culture);
- }
- #endregion
-
- // PutDispProperty and\or PutRefDispProperty ==> SetProperty.
- if ((bindingFlags & (BindingFlags.PutDispProperty | BindingFlags.PutRefDispProperty)) != 0)
- bindingFlags |= BindingFlags.SetProperty;
-
- #region Name
- if (name == null)
- throw new ArgumentNullException("name");
-
- if (name.Length == 0 || name.Equals(@"[DISPID=0]"))
- {
- name = GetDefaultMemberName();
-
- if (name == null)
- {
- // in InvokeMember we always pretend there is a default member if none is provided and we make it ToString
- name = "ToString";
- }
- }
- #endregion
-
- #region GetField or SetField
- bool IsGetField = (bindingFlags & BindingFlags.GetField) != 0;
- bool IsSetField = (bindingFlags & BindingFlags.SetField) != 0;
-
- if (IsGetField || IsSetField)
- {
- #region Preconditions
- if (IsGetField)
- {
- if (IsSetField)
- // "Can not specify both Get and Set on a field."
- throw new ArgumentException(Environment.GetResourceString("Arg_FldSetGet"),"bindingFlags");
-
- if ((bindingFlags & BindingFlags.SetProperty) != 0)
- // "Can not specify both GetField and SetProperty."
- throw new ArgumentException(Environment.GetResourceString("Arg_FldGetPropSet"),"bindingFlags");
- }
- else
- {
- Contract.Assert(IsSetField);
-
- if (providedArgs == null)
- throw new ArgumentNullException("providedArgs");
-
- if ((bindingFlags & BindingFlags.GetProperty) != 0)
- // "Can not specify both SetField and GetProperty."
- throw new ArgumentException(Environment.GetResourceString("Arg_FldSetPropGet"),"bindingFlags");
-
- if ((bindingFlags & BindingFlags.InvokeMethod) != 0)
- // "Can not specify Set on a Field and Invoke on a method."
- throw new ArgumentException(Environment.GetResourceString("Arg_FldSetInvoke"),"bindingFlags");
- }
- #endregion
-
- #region Lookup Field
- FieldInfo selFld = null;
- FieldInfo[] flds = GetMember(name, MemberTypes.Field, bindingFlags) as FieldInfo[];
-
- Contract.Assert(flds != null);
-
- if (flds.Length == 1)
- {
- selFld = flds[0];
- }
- else if (flds.Length > 0)
- {
- selFld = binder.BindToField(bindingFlags, flds, IsGetField ? Empty.Value : providedArgs[0], culture);
- }
- #endregion
-
- if (selFld != null)
- {
- #region Invocation on a field
- if (selFld.FieldType.IsArray || Object.ReferenceEquals(selFld.FieldType, typeof(System.Array)))
- {
- #region Invocation of an array Field
- int idxCnt;
-
- if ((bindingFlags & BindingFlags.GetField) != 0)
- {
- idxCnt = argCnt;
- }
- else
- {
- idxCnt = argCnt - 1;
- }
-
- if (idxCnt > 0)
- {
- // Verify that all of the index values are ints
- int[] idx = new int[idxCnt];
- for (int i=0;i<idxCnt;i++)
- {
- try
- {
- idx[i] = ((IConvertible)providedArgs[i]).ToInt32(null);
- }
- catch (InvalidCastException)
- {
- throw new ArgumentException(Environment.GetResourceString("Arg_IndexMustBeInt"));
- }
- }
-
- // Set or get the value...
- Array a = (Array) selFld.GetValue(target);
-
- // Set or get the value in the array
- if ((bindingFlags & BindingFlags.GetField) != 0)
- {
- return a.GetValue(idx);
- }
- else
- {
- a.SetValue(providedArgs[idxCnt],idx);
- return null;
- }
- }
- #endregion
- }
-
- if (IsGetField)
- {
- #region Get the field value
- if (argCnt != 0)
- throw new ArgumentException(Environment.GetResourceString("Arg_FldGetArgErr"),"bindingFlags");
-
- return selFld.GetValue(target);
- #endregion
- }
- else
- {
- #region Set the field Value
- if (argCnt != 1)
- throw new ArgumentException(Environment.GetResourceString("Arg_FldSetArgErr"),"bindingFlags");
-
- selFld.SetValue(target,providedArgs[0],bindingFlags,binder,culture);
-
- return null;
- #endregion
- }
- #endregion
- }
-
- if ((bindingFlags & BinderNonFieldGetSet) == 0)
- throw new MissingFieldException(FullName, name);
- }
- #endregion
-
- #region Caching Logic
- /*
- bool useCache = false;
-
- // Note that when we add something to the cache, we are careful to ensure
- // that the actual providedArgs matches the parameters of the method. Otherwise,
- // some default argument processing has occurred. We don't want anyone
- // else with the same (insufficient) number of actual arguments to get a
- // cache hit because then they would bypass the default argument processing
- // and the invocation would fail.
- if (bDefaultBinder && namedParams == null && argCnt < 6)
- useCache = true;
-
- if (useCache)
- {
- MethodBase invokeMethod = GetMethodFromCache (name, bindingFlags, argCnt, providedArgs);
-
- if (invokeMethod != null)
- return ((MethodInfo) invokeMethod).Invoke(target, bindingFlags, binder, providedArgs, culture);
- }
- */
- #endregion
-
- #region Property PreConditions
- // @Legacy - This is RTM behavior
- bool isGetProperty = (bindingFlags & BindingFlags.GetProperty) != 0;
- bool isSetProperty = (bindingFlags & BindingFlags.SetProperty) != 0;
-
- if (isGetProperty || isSetProperty)
- {
- #region Preconditions
- if (isGetProperty)
- {
- Contract.Assert(!IsSetField);
-
- if (isSetProperty)
- throw new ArgumentException(Environment.GetResourceString("Arg_PropSetGet"), "bindingFlags");
- }
- else
- {
- Contract.Assert(isSetProperty);
-
- Contract.Assert(!IsGetField);
-
- if ((bindingFlags & BindingFlags.InvokeMethod) != 0)
- throw new ArgumentException(Environment.GetResourceString("Arg_PropSetInvoke"), "bindingFlags");
- }
- #endregion
- }
- #endregion
-
- MethodInfo[] finalists = null;
- MethodInfo finalist = null;
-
- #region BindingFlags.InvokeMethod
- if ((bindingFlags & BindingFlags.InvokeMethod) != 0)
- {
- #region Lookup Methods
- MethodInfo[] semiFinalists = GetMember(name, MemberTypes.Method, bindingFlags) as MethodInfo[];
- List<MethodInfo> results = null;
-
- for(int i = 0; i < semiFinalists.Length; i ++)
- {
- MethodInfo semiFinalist = semiFinalists[i];
- Contract.Assert(semiFinalist != null);
-
- if (!FilterApplyMethodInfo((RuntimeMethodInfo)semiFinalist, bindingFlags, CallingConventions.Any, new Type[argCnt]))
- continue;
-
- if (finalist == null)
- {
- finalist = semiFinalist;
- }
- else
- {
- if (results == null)
- {
- results = new List<MethodInfo>(semiFinalists.Length);
- results.Add(finalist);
- }
-
- results.Add(semiFinalist);
- }
- }
-
- if (results != null)
- {
- Contract.Assert(results.Count > 1);
- finalists = new MethodInfo[results.Count];
- results.CopyTo(finalists);
- }
- #endregion
- }
- #endregion
-
- Contract.Assert(finalists == null || finalist != null);
-
- #region BindingFlags.GetProperty or BindingFlags.SetProperty
- if (finalist == null && isGetProperty || isSetProperty)
- {
- #region Lookup Property
- PropertyInfo[] semiFinalists = GetMember(name, MemberTypes.Property, bindingFlags) as PropertyInfo[];
- List<MethodInfo> results = null;
-
- for(int i = 0; i < semiFinalists.Length; i ++)
- {
- MethodInfo semiFinalist = null;
-
- if (isSetProperty)
- {
- semiFinalist = semiFinalists[i].GetSetMethod(true);
- }
- else
- {
- semiFinalist = semiFinalists[i].GetGetMethod(true);
- }
-
- if (semiFinalist == null)
- continue;
-
- if (!FilterApplyMethodInfo((RuntimeMethodInfo)semiFinalist, bindingFlags, CallingConventions.Any, new Type[argCnt]))
- continue;
-
- if (finalist == null)
- {
- finalist = semiFinalist;
- }
- else
- {
- if (results == null)
- {
- results = new List<MethodInfo>(semiFinalists.Length);
- results.Add(finalist);
- }
-
- results.Add(semiFinalist);
- }
- }
-
- if (results != null)
- {
- Contract.Assert(results.Count > 1);
- finalists = new MethodInfo[results.Count];
- results.CopyTo(finalists);
- }
- #endregion
- }
- #endregion
-
- if (finalist != null)
- {
- #region Invoke
- if (finalists == null &&
- argCnt == 0 &&
- finalist.GetParametersNoCopy().Length == 0 &&
- (bindingFlags & BindingFlags.OptionalParamBinding) == 0)
- {
- //if (useCache && argCnt == props[0].GetParameters().Length)
- // AddMethodToCache(name, bindingFlags, argCnt, providedArgs, props[0]);
-
- return finalist.Invoke(target, bindingFlags, binder, providedArgs, culture);
- }
-
- if (finalists == null)
- finalists = new MethodInfo[] { finalist };
-
- if (providedArgs == null)
- providedArgs = Array.Empty<Object>();
-
- Object state = null;
-
-
- MethodBase invokeMethod = null;
-
- try { invokeMethod = binder.BindToMethod(bindingFlags, finalists, ref providedArgs, modifiers, culture, namedParams, out state); }
- catch(MissingMethodException) { }
-
- if (invokeMethod == null)
- throw new MissingMethodException(FullName, name);
-
- //if (useCache && argCnt == invokeMethod.GetParameters().Length)
- // AddMethodToCache(name, bindingFlags, argCnt, providedArgs, invokeMethod);
-
- Object result = ((MethodInfo)invokeMethod).Invoke(target, bindingFlags, binder, providedArgs, culture);
-
- if (state != null)
- binder.ReorderArgumentArray(ref providedArgs, state);
-
- return result;
- #endregion
- }
-
- throw new MissingMethodException(FullName, name);
- }
- #endregion
-
- public static bool operator ==(RuntimeType left, RuntimeType right)
- {
- return object.ReferenceEquals(left, right);
- }
-
- public static bool operator !=(RuntimeType left, RuntimeType right)
- {
- return !object.ReferenceEquals(left, right);
- }
-
- #region Legacy Internal
- private void CreateInstanceCheckThis()
- {
- if (ContainsGenericParameters)
- throw new ArgumentException(
- Environment.GetResourceString("Acc_CreateGenericEx", this));
- Contract.EndContractBlock();
-
- Type elementType = this.GetRootElementType();
-
- if (Object.ReferenceEquals(elementType, typeof(ArgIterator)))
- throw new NotSupportedException(Environment.GetResourceString("Acc_CreateArgIterator"));
-
- if (Object.ReferenceEquals(elementType, typeof(void)))
- throw new NotSupportedException(Environment.GetResourceString("Acc_CreateVoid"));
- }
-
- internal Object CreateInstanceImpl(
- BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
- {
- CreateInstanceCheckThis();
-
- Object server = null;
-
- try
- {
- try
- {
- if (args == null)
- args = Array.Empty<Object> ();
-
- int argCnt = args.Length;
-
- // Without a binder we need to do use the default binder...
- if (binder == null)
- binder = DefaultBinder;
-
- // deal with the __COMObject case first. It is very special because from a reflection point of view it has no ctors
- // so a call to GetMemberCons would fail
- bool publicOnly = (bindingAttr & BindingFlags.NonPublic) == 0;
- bool wrapExceptions = (bindingAttr & BindingFlags.DoNotWrapExceptions) == 0;
- if (argCnt == 0 && (bindingAttr & BindingFlags.Public) != 0 && (bindingAttr & BindingFlags.Instance) != 0
- && (IsValueType))
- {
- server = CreateInstanceDefaultCtor(publicOnly, false, true, wrapExceptions);
- }
- else
- {
- ConstructorInfo[] candidates = GetConstructors(bindingAttr);
- List<MethodBase> matches = new List<MethodBase>(candidates.Length);
-
- // We cannot use Type.GetTypeArray here because some of the args might be null
- Type[] argsType = new Type[argCnt];
- for (int i = 0; i < argCnt; i++)
- {
- if (args[i] != null)
- {
- argsType[i] = args[i].GetType();
- }
- }
-
- for(int i = 0; i < candidates.Length; i ++)
- {
- if (FilterApplyConstructorInfo((RuntimeConstructorInfo)candidates[i], bindingAttr, CallingConventions.Any, argsType))
- matches.Add(candidates[i]);
- }
-
- MethodBase[] cons = new MethodBase[matches.Count];
- matches.CopyTo(cons);
- if (cons != null && cons.Length == 0)
- cons = null;
-
- if (cons == null)
- {
- throw new MissingMethodException(Environment.GetResourceString("MissingConstructor_Name", FullName));
- }
-
- MethodBase invokeMethod;
- Object state = null;
-
- try
- {
- invokeMethod = binder.BindToMethod(bindingAttr, cons, ref args, null, culture, null, out state);
- }
- catch (MissingMethodException) { invokeMethod = null; }
-
- if (invokeMethod == null)
- {
- throw new MissingMethodException(Environment.GetResourceString("MissingConstructor_Name", FullName));
- }
-
- if (invokeMethod.GetParametersNoCopy().Length == 0)
- {
- if (args.Length != 0)
- {
-
- Contract.Assert((invokeMethod.CallingConvention & CallingConventions.VarArgs) ==
- CallingConventions.VarArgs);
- throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture,
- Environment.GetResourceString("NotSupported_CallToVarArg")));
- }
-
- // fast path??
- server = Activator.CreateInstance(this, nonPublic: true, wrapExceptions: wrapExceptions);
- }
- else
- {
- server = ((ConstructorInfo)invokeMethod).Invoke(bindingAttr, binder, args, culture);
- if (state != null)
- binder.ReorderArgumentArray(ref args, state);
- }
- }
- }
- finally
- {
- }
- }
- catch (Exception)
- {
- throw;
- }
-
- //Console.WriteLine(server);
- return server;
- }
-
- // Helper to invoke the default (parameterless) ctor.
- // fillCache is set in the SL2/3 compat mode or when called from Marshal.PtrToStructure.
- [DebuggerStepThroughAttribute]
- [Diagnostics.DebuggerHidden]
- internal Object CreateInstanceDefaultCtor(bool publicOnly, bool skipCheckThis, bool fillCache, bool wrapExceptions)
- {
- if (IsByRefLike)
- throw new NotSupportedException (SR.NotSupported_ByRefLike);
-
- return CreateInstanceSlow(publicOnly, wrapExceptions, skipCheckThis, fillCache);
- }
-
- #endregion
-
- TypeCache cache;
-
- internal TypeCache Cache {
- get {
- if (cache == null)
- LazyInitializer.EnsureInitialized (ref cache, () => new TypeCache ());
-
- return cache;
- }
- }
-
- internal sealed class TypeCache
- {
- public Enum.EnumInfo EnumInfo;
- public TypeCode TypeCode;
- // this is the displayed form: special characters
- // ,+*&*[]\ in the identifier portions of the names
- // have been escaped with a leading backslash (\)
- public string full_name;
- public bool default_ctor_cached;
- public RuntimeConstructorInfo default_ctor;
- }
-
-
- internal RuntimeType (Object obj)
- {
- throw new NotImplementedException ();
- }
-
- internal RuntimeConstructorInfo GetDefaultConstructor ()
- {
- var cache = Cache;
- RuntimeConstructorInfo ctor = null;
-
- if (Volatile.Read (ref cache.default_ctor_cached))
- return cache.default_ctor;
-
- var ctors = GetConstructorCandidates (
- null,
- BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly, CallingConventions.Any,
- Array.Empty<Type> (), false);
-
- if (ctors.Count == 1)
- cache.default_ctor = ctor = (RuntimeConstructorInfo) ctors [0];
-
- // Note down even if we found no constructors
- Volatile.Write (ref cache.default_ctor_cached, true);
-
- return ctor;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern MethodInfo GetCorrespondingInflatedMethod (MethodInfo generic);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern ConstructorInfo GetCorrespondingInflatedConstructor (ConstructorInfo generic);
-
- internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
- {
- if (fromNoninstanciated == null)
- throw new ArgumentNullException ("fromNoninstanciated");
- return GetCorrespondingInflatedMethod (fromNoninstanciated);
- }
-
- internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
- {
- if (fromNoninstanciated == null)
- throw new ArgumentNullException ("fromNoninstanciated");
- return GetCorrespondingInflatedConstructor (fromNoninstanciated);
- }
-
- internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
- {
- /* create sensible flags from given FieldInfo */
- BindingFlags flags = fromNoninstanciated.IsStatic ? BindingFlags.Static : BindingFlags.Instance;
- flags |= fromNoninstanciated.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
- return GetField (fromNoninstanciated.Name, flags);
- }
-
- string GetDefaultMemberName ()
- {
- object [] att = GetCustomAttributes (typeof (DefaultMemberAttribute), true);
- return att.Length != 0 ? ((DefaultMemberAttribute) att [0]).MemberName : null;
- }
-
- RuntimeConstructorInfo m_serializationCtor;
- internal RuntimeConstructorInfo GetSerializationCtor()
- {
- if (m_serializationCtor == null) {
- var s_SICtorParamTypes = new Type[] { typeof(SerializationInfo), typeof(StreamingContext) };
-
- m_serializationCtor = GetConstructor(
- BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
- null,
- CallingConventions.Any,
- s_SICtorParamTypes,
- null) as RuntimeConstructorInfo;
- }
-
- return m_serializationCtor;
- }
-
- internal Object CreateInstanceSlow(bool publicOnly, bool wrapExceptions, bool skipCheckThis, bool fillCache)
- {
- //bool bNeedSecurityCheck = true;
- //bool bCanBeCached = false;
- //bool bSecurityCheckOff = false;
-
- if (!skipCheckThis)
- CreateInstanceCheckThis();
-
- //if (!fillCache)
- // bSecurityCheckOff = true;
-
- return CreateInstanceMono (!publicOnly, wrapExceptions);
- }
-
- object CreateInstanceMono (bool nonPublic, bool wrapExceptions)
- {
- var ctor = GetDefaultConstructor ();
- if (!nonPublic && ctor != null && !ctor.IsPublic) {
- throw new MissingMethodException(SR.Format(SR.Arg_NoDefCTor, FullName));
- }
-
- if (ctor == null) {
- Type elementType = this.GetRootElementType();
- if (ReferenceEquals (elementType, typeof (TypedReference)) || ReferenceEquals (elementType, typeof (RuntimeArgumentHandle)))
- throw new NotSupportedException (Environment.GetResourceString ("NotSupported_ContainsStackPtr"));
-
- if (IsValueType)
- return CreateInstanceInternal (this);
-
- throw new MissingMethodException ("Default constructor not found for type " + FullName);
- }
-
- // TODO: .net does more checks in unmanaged land in RuntimeTypeHandle::CreateInstance
- if (IsAbstract) {
- throw new MissingMethodException ("Cannot create an abstract class '{0}'.", FullName);
- }
-
- return ctor.InternalInvoke (null, null, wrapExceptions);
- }
-
- internal Object CheckValue (Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
- {
- bool failed = false;
- var res = TryConvertToType (value, ref failed);
- if (!failed)
- return res;
-
- if ((invokeAttr & BindingFlags.ExactBinding) == BindingFlags.ExactBinding)
- throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_ObjObjEx"), value.GetType(), this));
-
- if (binder != null && binder != Type.DefaultBinder)
- return binder.ChangeType (value, this, culture);
-
- throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_ObjObjEx"), value.GetType(), this));
- }
-
- object TryConvertToType (object value, ref bool failed)
- {
- if (IsInstanceOfType (value)) {
- return value;
- }
-
- if (IsByRef) {
- var elementType = GetElementType ();
- if (value == null || elementType.IsInstanceOfType (value)) {
- return value;
- }
- }
-
- if (value == null)
- return value;
-
- if (IsEnum) {
- var type = Enum.GetUnderlyingType (this);
- if (type == value.GetType ())
- return value;
- var res = IsConvertibleToPrimitiveType (value, this);
- if (res != null)
- return res;
- } else if (IsPrimitive) {
- var res = IsConvertibleToPrimitiveType (value, this);
- if (res != null)
- return res;
- } else if (IsPointer) {
- var vtype = value.GetType ();
- if (vtype == typeof (IntPtr) || vtype == typeof (UIntPtr))
- return value;
- if (value is Pointer pointer) {
- Type pointerType = pointer.GetPointerType ();
- if (pointerType == this)
- return pointer.GetPointerValue ();
- }
- }
-
- failed = true;
- return null;
- }
-
- // Binder uses some incompatible conversion rules. For example
- // int value cannot be used with decimal parameter but in other
- // ways it's more flexible than normal convertor, for example
- // long value can be used with int based enum
- static object IsConvertibleToPrimitiveType (object value, Type targetType)
- {
- var type = value.GetType ();
- if (type.IsEnum) {
- type = Enum.GetUnderlyingType (type);
- if (type == targetType)
- return value;
- }
-
- var from = Type.GetTypeCode (type);
- var to = Type.GetTypeCode (targetType);
-
- switch (to) {
- case TypeCode.Char:
- switch (from) {
- case TypeCode.Byte:
- return (Char) (Byte) value;
- case TypeCode.UInt16:
- return value;
- }
- break;
- case TypeCode.Int16:
- switch (from) {
- case TypeCode.Byte:
- return (Int16) (Byte) value;
- case TypeCode.SByte:
- return (Int16) (SByte) value;
- }
- break;
- case TypeCode.UInt16:
- switch (from) {
- case TypeCode.Byte:
- return (UInt16) (Byte) value;
- case TypeCode.Char:
- return value;
- }
- break;
- case TypeCode.Int32:
- switch (from) {
- case TypeCode.Byte:
- return (Int32) (Byte) value;
- case TypeCode.SByte:
- return (Int32) (SByte) value;
- case TypeCode.Char:
- return (Int32) (Char) value;
- case TypeCode.Int16:
- return (Int32) (Int16) value;
- case TypeCode.UInt16:
- return (Int32) (UInt16) value;
- }
- break;
- case TypeCode.UInt32:
- switch (from) {
- case TypeCode.Byte:
- return (UInt32) (Byte) value;
- case TypeCode.Char:
- return (UInt32) (Char) value;
- case TypeCode.UInt16:
- return (UInt32) (UInt16) value;
- }
- break;
- case TypeCode.Int64:
- switch (from) {
- case TypeCode.Byte:
- return (Int64) (Byte) value;
- case TypeCode.SByte:
- return (Int64) (SByte) value;
- case TypeCode.Int16:
- return (Int64) (Int16) value;
- case TypeCode.Char:
- return (Int64) (Char) value;
- case TypeCode.UInt16:
- return (Int64) (UInt16) value;
- case TypeCode.Int32:
- return (Int64) (Int32) value;
- case TypeCode.UInt32:
- return (Int64) (UInt32) value;
- }
- break;
- case TypeCode.UInt64:
- switch (from) {
- case TypeCode.Byte:
- return (UInt64) (Byte) value;
- case TypeCode.Char:
- return (UInt64) (Char) value;
- case TypeCode.UInt16:
- return (UInt64) (UInt16) value;
- case TypeCode.UInt32:
- return (UInt64) (UInt32) value;
- }
- break;
- case TypeCode.Single:
- switch (from) {
- case TypeCode.Byte:
- return (Single) (Byte) value;
- case TypeCode.SByte:
- return (Single) (SByte) value;
- case TypeCode.Int16:
- return (Single) (Int16) value;
- case TypeCode.Char:
- return (Single) (Char) value;
- case TypeCode.UInt16:
- return (Single) (UInt16) value;
- case TypeCode.Int32:
- return (Single) (Int32) value;
- case TypeCode.UInt32:
- return (Single) (UInt32) value;
- case TypeCode.Int64:
- return (Single) (Int64) value;
- case TypeCode.UInt64:
- return (Single) (UInt64) value;
- }
- break;
- case TypeCode.Double:
- switch (from) {
- case TypeCode.Byte:
- return (Double) (Byte) value;
- case TypeCode.SByte:
- return (Double) (SByte) value;
- case TypeCode.Char:
- return (Double) (Char) value;
- case TypeCode.Int16:
- return (Double) (Int16) value;
- case TypeCode.UInt16:
- return (Double) (UInt16) value;
- case TypeCode.Int32:
- return (Double) (Int32) value;
- case TypeCode.UInt32:
- return (Double) (UInt32) value;
- case TypeCode.Int64:
- return (Double) (Int64) value;
- case TypeCode.UInt64:
- return (Double) (UInt64) value;
- case TypeCode.Single:
- return (Double) (Single) value;
- }
- break;
- }
-
- // Everything else is rejected
- return null;
- }
-
- string GetCachedName (TypeNameKind kind)
- {
- switch (kind) {
- case TypeNameKind.SerializationName:
- return ToString ();
- default:
- throw new NotImplementedException ();
- }
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern Type make_array_type (int rank);
-
- public override Type MakeArrayType ()
- {
- return make_array_type (0);
- }
-
- public override Type MakeArrayType (int rank)
- {
- if (rank < 1 || rank > 255)
- throw new IndexOutOfRangeException ();
- return make_array_type (rank);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern Type make_byref_type ();
-
- public override Type MakeByRefType ()
- {
- if (IsByRef)
- throw new TypeLoadException ("Can not call MakeByRefType on a ByRef type");
- return make_byref_type ();
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern Type MakePointerType (Type type);
-
- public override Type MakePointerType ()
- {
- if (IsByRef)
- throw new TypeLoadException ($"Could not load type '{GetType()}' from assembly '{AssemblyQualifiedName}");
- return MakePointerType (this);
- }
-
- public override StructLayoutAttribute? StructLayoutAttribute {
- get {
- return GetStructLayoutAttribute ();
- }
- }
-
- public override bool ContainsGenericParameters {
- get {
- if (IsGenericParameter)
- return true;
-
- if (IsGenericType) {
- foreach (Type arg in GetGenericArguments ())
- if (arg.ContainsGenericParameters)
- return true;
- }
-
- if (HasElementType)
- return GetElementType ().ContainsGenericParameters;
-
- return false;
- }
- }
-
- public override Type[] GetGenericParameterConstraints ()
- {
- if (!IsGenericParameter)
- throw new InvalidOperationException(Environment.GetResourceString("Arg_NotGenericParameter"));
-
- var paramInfo = new Mono.RuntimeGenericParamInfoHandle (RuntimeTypeHandle.GetGenericParameterInfo (this));
- Type[] constraints = paramInfo.Constraints;
-
- return constraints ?? Array.Empty<Type> ();
- }
-
- internal static object CreateInstanceForAnotherGenericParameter (Type genericType, RuntimeType genericArgument)
- {
- var gt = (RuntimeType) MakeGenericType (genericType, new Type [] { genericArgument });
- var ctor = gt.GetDefaultConstructor ();
- return ctor.InternalInvoke (null, null, wrapExceptions: true);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern Type MakeGenericType (Type gt, Type [] types);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal extern IntPtr GetMethodsByName_native (IntPtr namePtr, BindingFlags bindingAttr, MemberListType listType);
-
- internal RuntimeMethodInfo[] GetMethodsByName (string name, BindingFlags bindingAttr, MemberListType listType, RuntimeType reflectedType)
- {
- var refh = new RuntimeTypeHandle (reflectedType);
- using (var namePtr = new Mono.SafeStringMarshal (name))
- using (var h = new Mono.SafeGPtrArrayHandle (GetMethodsByName_native (namePtr.Value, bindingAttr, listType))) {
- var n = h.Length;
- var a = new RuntimeMethodInfo [n];
- for (int i = 0; i < n; i++) {
- var mh = new RuntimeMethodHandle (h[i]);
- a[i] = (RuntimeMethodInfo) RuntimeMethodInfo.GetMethodFromHandleNoGenericCheck (mh, refh);
- }
- return a;
- }
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern IntPtr GetPropertiesByName_native (IntPtr name, BindingFlags bindingAttr, MemberListType listType);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern IntPtr GetConstructors_native (BindingFlags bindingAttr);
-
- RuntimeConstructorInfo[] GetConstructors_internal (BindingFlags bindingAttr, RuntimeType reflectedType)
- {
- var refh = new RuntimeTypeHandle (reflectedType);
- using (var h = new Mono.SafeGPtrArrayHandle (GetConstructors_native (bindingAttr))) {
- var n = h.Length;
- var a = new RuntimeConstructorInfo [n];
- for (int i = 0; i < n; i++) {
- var mh = new RuntimeMethodHandle (h[i]);
- a[i] = (RuntimeConstructorInfo) RuntimeMethodInfo.GetMethodFromHandleNoGenericCheck (mh, refh);
- }
- return a;
- }
- }
-
- RuntimePropertyInfo[] GetPropertiesByName (string name, BindingFlags bindingAttr, MemberListType listType, RuntimeType reflectedType)
- {
- var refh = new RuntimeTypeHandle (reflectedType);
- using (var namePtr = new Mono.SafeStringMarshal (name))
- using (var h = new Mono.SafeGPtrArrayHandle (GetPropertiesByName_native (namePtr.Value, bindingAttr, listType))) {
- var n = h.Length;
- var a = new RuntimePropertyInfo [n];
- for (int i = 0; i < n; i++) {
- var ph = new Mono.RuntimePropertyHandle (h[i]);
- a[i] = (RuntimePropertyInfo) RuntimePropertyInfo.GetPropertyFromHandle (ph, refh);
- }
- return a;
- }
- }
-
- public override InterfaceMapping GetInterfaceMap (Type ifaceType)
- {
- if (IsGenericParameter)
- throw new InvalidOperationException(Environment.GetResourceString("Arg_GenericParameter"));
-
- if ((object)ifaceType == null)
- throw new ArgumentNullException("ifaceType");
-
- RuntimeType ifaceRtType = ifaceType as RuntimeType;
-
- if (ifaceRtType == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "ifaceType");
-
- InterfaceMapping res;
- if (!ifaceType.IsInterface)
- throw new ArgumentException ("Argument must be an interface.", "ifaceType");
- if (IsInterface)
- throw new ArgumentException ("'this' type cannot be an interface itself");
- res.TargetType = this;
- res.InterfaceType = ifaceType;
- GetInterfaceMapData (this, ifaceType, out res.TargetMethods, out res.InterfaceMethods);
- if (res.TargetMethods == null)
- throw new ArgumentException ("Interface not found", "ifaceType");
-
- return res;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern void GetInterfaceMapData (Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods);
-
- public override Guid GUID {
- get {
- object[] att = GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true);
- if (att.Length == 0)
- return Guid.Empty;
- return new Guid(((System.Runtime.InteropServices.GuidAttribute)att[0]).Value);
- }
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal extern void GetPacking (out int packing, out int size);
-
- public override string ToString()
- {
- return getFullName (false, false);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern object CreateInstanceInternal (Type type);
-
- public extern override MethodBase? DeclaringMethod {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- get;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal extern string getFullName(bool full_name, bool assembly_qualified);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern Type[] GetGenericArgumentsInternal (bool runtimeArray);
-
- GenericParameterAttributes GetGenericParameterAttributes () {
- return (new Mono.RuntimeGenericParamInfoHandle (RuntimeTypeHandle.GetGenericParameterInfo (this))).Attributes;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern int GetGenericParameterPosition ();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern IntPtr GetEvents_native (IntPtr name, MemberListType listType);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern IntPtr GetFields_native (IntPtr name, BindingFlags bindingAttr, MemberListType listType);
-
- RuntimeFieldInfo[] GetFields_internal (string name, BindingFlags bindingAttr, MemberListType listType, RuntimeType reflectedType)
- {
- var refh = new RuntimeTypeHandle (reflectedType);
- using (var namePtr = new Mono.SafeStringMarshal (name))
- using (var h = new Mono.SafeGPtrArrayHandle (GetFields_native (namePtr.Value, bindingAttr, listType))) {
- int n = h.Length;
- var a = new RuntimeFieldInfo[n];
- for (int i = 0; i < n; i++) {
- var fh = new RuntimeFieldHandle (h[i]);
- a[i] = (RuntimeFieldInfo) FieldInfo.GetFieldFromHandle (fh, refh);
- }
- return a;
- }
- }
-
- RuntimeEventInfo[] GetEvents_internal (string name, BindingFlags bindingAttr, MemberListType listType, RuntimeType reflectedType)
- {
- var refh = new RuntimeTypeHandle (reflectedType);
- using (var namePtr = new Mono.SafeStringMarshal (name))
- using (var h = new Mono.SafeGPtrArrayHandle (GetEvents_native (namePtr.Value, listType))) {
- int n = h.Length;
- var a = new RuntimeEventInfo[n];
- for (int i = 0; i < n; i++) {
- var eh = new Mono.RuntimeEventHandle (h[i]);
- a[i] = (RuntimeEventInfo) RuntimeEventInfo.GetEventFromHandle (eh, refh);
- }
- return a;
- }
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public extern override Type[] GetInterfaces();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern IntPtr GetNestedTypes_native (IntPtr name, BindingFlags bindingAttr, MemberListType listType);
-
- RuntimeType[] GetNestedTypes_internal (string displayName, BindingFlags bindingAttr, MemberListType listType)
- {
- string internalName = null;
- if (displayName != null)
- internalName = displayName;
- using (var namePtr = new Mono.SafeStringMarshal (internalName))
- using (var h = new Mono.SafeGPtrArrayHandle (GetNestedTypes_native (namePtr.Value, bindingAttr, listType))) {
- int n = h.Length;
- var a = new RuntimeType [n];
- for (int i = 0; i < n; i++) {
- var th = new RuntimeTypeHandle (h[i]);
- a[i] = (RuntimeType) Type.GetTypeFromHandle (th);
- }
- return a;
- }
- }
-
- public override string? AssemblyQualifiedName {
- get {
- return getFullName (true, true);
- }
- }
-
- public extern override Type? DeclaringType {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- get;
- }
-
- public extern override string Name {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- get;
- }
-
- public extern override string? Namespace {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- get;
- }
-
- public override string? FullName {
- get {
- // See https://github.com/mono/mono/issues/18180 and
- // https://github.com/dotnet/runtime/blob/f23e2796ab5f6fea71c9fdacac024822280253db/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs#L1468-L1472
- if (ContainsGenericParameters && !GetRootElementType().IsGenericTypeDefinition)
- return null;
-
- string fullName;
- var cache = Cache;
- if ((fullName = cache.full_name) == null)
- fullName = cache.full_name = getFullName (true, false);
-
- return fullName;
- }
- }
-
- public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeType> (other);
-
- public override bool IsSZArray {
- get {
- return RuntimeTypeHandle.IsSzArray (this);
- }
- }
-
- internal override bool IsUserType {
- get {
- return false;
- }
- }
-
- public override bool IsSubclassOf(Type type)
- {
- if ((object)type == null)
- throw new ArgumentNullException("type");
-
- RuntimeType rtType = type as RuntimeType;
- if (rtType == null)
- return false;
-
- return RuntimeTypeHandle.IsSubclassOf (this, rtType);
- }
-
- private const int DEFAULT_PACKING_SIZE = 8;
-
- internal StructLayoutAttribute GetStructLayoutAttribute ()
- {
- if (IsInterface || HasElementType || IsGenericParameter)
- return null;
-
- int pack = 0, size = 0;
- LayoutKind layoutKind = LayoutKind.Auto;
- switch (Attributes & TypeAttributes.LayoutMask)
- {
- case TypeAttributes.ExplicitLayout: layoutKind = LayoutKind.Explicit; break;
- case TypeAttributes.AutoLayout: layoutKind = LayoutKind.Auto; break;
- case TypeAttributes.SequentialLayout: layoutKind = LayoutKind.Sequential; break;
- default: break;
- }
-
- CharSet charSet = CharSet.None;
- switch (Attributes & TypeAttributes.StringFormatMask)
- {
- case TypeAttributes.AnsiClass: charSet = CharSet.Ansi; break;
- case TypeAttributes.AutoClass: charSet = CharSet.Auto; break;
- case TypeAttributes.UnicodeClass: charSet = CharSet.Unicode; break;
- default: break;
- }
-
- GetPacking (out pack, out size);
-
- // Metadata parameter checking should not have allowed 0 for packing size.
- // The runtime later converts a packing size of 0 to 8 so do the same here
- // because it's more useful from a user perspective.
- if (pack == 0)
- pack = DEFAULT_PACKING_SIZE;
-
- return new StructLayoutAttribute (layoutKind) { Pack = pack, Size = size, CharSet = charSet };
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs
deleted file mode 100644
index f0c194d3898..00000000000
--- a/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs
+++ /dev/null
@@ -1,332 +0,0 @@
-//
-// Authors:
-// Miguel de Icaza (miguel@ximian.com)
-// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
-//
-// (C) Ximian, Inc. http://www.ximian.com
-//
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.Runtime.Serialization;
-using System.Runtime.CompilerServices;
-using System.Reflection;
-using System.Threading;
-
-namespace System
-{
- [Serializable]
- public struct RuntimeTypeHandle : ISerializable
- {
- readonly IntPtr value;
-
- internal RuntimeTypeHandle (IntPtr val)
- {
- value = val;
- }
-
- internal RuntimeTypeHandle (RuntimeType type)
- : this (type._impl.value)
- {
- }
-
- RuntimeTypeHandle (SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public IntPtr Value {
- get {
- return value;
- }
- }
-
- public void GetObjectData (SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException ();
- }
-
- public override bool Equals (object? obj)
- {
- if (obj == null || GetType () != obj.GetType ())
- return false;
-
- return value == ((RuntimeTypeHandle)obj).Value;
- }
-
- public bool Equals (RuntimeTypeHandle handle)
- {
- return value == handle.Value;
- }
-
- public override int GetHashCode ()
- {
- return value.GetHashCode ();
- }
-
- public static bool operator == (RuntimeTypeHandle left, Object right)
- {
- return (right != null) && (right is RuntimeTypeHandle) && left.Equals ((RuntimeTypeHandle)right);
- }
-
- public static bool operator != (RuntimeTypeHandle left, Object right)
- {
- return (right == null) || !(right is RuntimeTypeHandle) || !left.Equals ((RuntimeTypeHandle)right);
- }
-
- public static bool operator == (Object left, RuntimeTypeHandle right)
- {
- return (left != null) && (left is RuntimeTypeHandle) && ((RuntimeTypeHandle)left).Equals (right);
- }
-
- public static bool operator != (Object left, RuntimeTypeHandle right)
- {
- return (left == null) || !(left is RuntimeTypeHandle) || !((RuntimeTypeHandle)left).Equals (right);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern TypeAttributes GetAttributes (RuntimeType type);
-
- [CLSCompliant (false)]
- public ModuleHandle GetModuleHandle ()
- {
- // Although MS' runtime is crashing here, we prefer throwing an exception.
- // The check is needed because Type.GetTypeFromHandle returns null
- // for zero handles.
- if (value == IntPtr.Zero)
- throw new InvalidOperationException ("Object fields may not be properly initialized");
-
- return Type.GetTypeFromHandle (this).Module.ModuleHandle;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern int GetMetadataToken (RuntimeType type);
-
- internal static int GetToken (RuntimeType type)
- {
- return GetMetadataToken (type);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static Type GetGenericTypeDefinition_impl (RuntimeType type);
-
- internal static Type GetGenericTypeDefinition (RuntimeType type)
- {
- return GetGenericTypeDefinition_impl (type);
- }
-
- internal static bool IsPrimitive (RuntimeType type)
- {
- CorElementType corElemType = GetCorElementType (type);
- return (corElemType >= CorElementType.ELEMENT_TYPE_BOOLEAN && corElemType <= CorElementType.ELEMENT_TYPE_R8) ||
- corElemType == CorElementType.ELEMENT_TYPE_I ||
- corElemType == CorElementType.ELEMENT_TYPE_U;
- }
-
- internal static bool IsByRef (RuntimeType type)
- {
- CorElementType corElemType = GetCorElementType (type);
- return corElemType == CorElementType.ELEMENT_TYPE_BYREF;
- }
-
- internal static bool IsPointer (RuntimeType type)
- {
- CorElementType corElemType = GetCorElementType (type);
- return corElemType == CorElementType.ELEMENT_TYPE_PTR;
- }
-
- internal static bool IsArray (RuntimeType type)
- {
- CorElementType corElemType = GetCorElementType (type);
- return corElemType == CorElementType.ELEMENT_TYPE_ARRAY || corElemType == CorElementType.ELEMENT_TYPE_SZARRAY;
- }
-
- internal static bool IsSzArray (RuntimeType type)
- {
- CorElementType corElemType = GetCorElementType (type);
- return corElemType == CorElementType.ELEMENT_TYPE_SZARRAY;
- }
-
- internal static bool HasElementType (RuntimeType type)
- {
- CorElementType corElemType = GetCorElementType(type);
-
- return ((corElemType == CorElementType.ELEMENT_TYPE_ARRAY || corElemType == CorElementType.ELEMENT_TYPE_SZARRAY) // IsArray
- || (corElemType == CorElementType.ELEMENT_TYPE_PTR) // IsPointer
- || (corElemType == CorElementType.ELEMENT_TYPE_BYREF)); // IsByRef
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern CorElementType GetCorElementType (RuntimeType type);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static bool HasInstantiation (RuntimeType type);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static bool IsComObject (RuntimeType type);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static bool IsInstanceOfType (RuntimeType type, Object o);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static bool HasReferences (RuntimeType type);
-
- internal static bool IsComObject (RuntimeType type, bool isGenericCOM)
- {
- return isGenericCOM ? false : IsComObject (type);
- }
-
- internal static bool IsContextful (RuntimeType type)
- {
- return false;
- }
-
- internal static bool IsEquivalentTo (RuntimeType rtType1, RuntimeType rtType2)
- {
- // refence check is done earlier and we don't recognize anything else
- return false;
- }
-
- internal static bool IsInterface (RuntimeType type)
- {
- return (type.Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static int GetArrayRank(RuntimeType type);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static RuntimeAssembly GetAssembly (RuntimeType type);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static RuntimeType GetElementType (RuntimeType type);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static RuntimeModule GetModule (RuntimeType type);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static bool IsGenericVariable (RuntimeType type);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static RuntimeType GetBaseType (RuntimeType type);
-
- internal static bool CanCastTo (RuntimeType type, RuntimeType target)
- {
- return type_is_assignable_from (target, type);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern bool type_is_assignable_from (Type a, Type b);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static bool IsGenericTypeDefinition (RuntimeType type);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static IntPtr GetGenericParameterInfo (RuntimeType type);
-
- internal static bool IsSubclassOf (RuntimeType childType, RuntimeType baseType)
- {
- return is_subclass_of (childType._impl.Value, baseType._impl.Value);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static bool is_subclass_of (IntPtr childType, IntPtr baseType);
-
- [PreserveDependency (".ctor()", "System.Runtime.CompilerServices.IsByRefLikeAttribute")]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static bool IsByRefLike (RuntimeType type);
-
- internal static bool IsTypeDefinition (RuntimeType type)
- {
- // That's how it has been done on CoreFX but we have no GetCorElementType method implementation
- // see https://github.com/dotnet/coreclr/pull/11355
-
- // CorElementType corElemType = GetCorElementType (type);
- // if (!((corElemType >= CorElementType.Void && corElemType < CorElementType.Ptr) ||
- // corElemType == CorElementType.ValueType ||
- // corElemType == CorElementType.Class ||
- // corElemType == CorElementType.TypedByRef ||
- // corElemType == CorElementType.I ||
- // corElemType == CorElementType.U ||
- // corElemType == CorElementType.Object))
- // return false;
- // if (HasInstantiation (type) && !IsGenericTypeDefinition (type))
- // return false;
- // return true;
-
- // It's like a workaround mentioned in https://github.com/dotnet/corefx/issues/17345
- return !type.HasElementType && !type.IsConstructedGenericType && !type.IsGenericParameter;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern RuntimeType internal_from_name (string name, ref StackCrawlMark stackMark, Assembly callerAssembly, bool throwOnError, bool ignoreCase, bool reflectionOnly);
-
- internal static RuntimeType GetTypeByName (string typeName, bool throwOnError, bool ignoreCase, bool reflectionOnly, ref StackCrawlMark stackMark,
- bool loadTypeFromPartialName)
- {
- if (typeName == null)
- throw new ArgumentNullException ("typeName");
-
- if (typeName == String.Empty)
- if (throwOnError)
- throw new TypeLoadException ("A null or zero length string does not represent a valid Type.");
- else
- return null;
-
- if (reflectionOnly) {
- int idx = typeName.IndexOf (',');
- if (idx < 0 || idx == 0 || idx == typeName.Length - 1)
- throw new ArgumentException ("Assembly qualifed type name is required", "typeName");
- string an = typeName.Substring (idx + 1);
- Assembly a;
- try {
- a = Assembly.ReflectionOnlyLoad (an);
- } catch {
- if (throwOnError)
- throw;
- return null;
- }
- return (RuntimeType)a.GetType (typeName.Substring (0, idx), throwOnError, ignoreCase);
- }
-
- var t = internal_from_name (typeName, ref stackMark, null, throwOnError, ignoreCase, false);
- if (throwOnError && t == null)
- throw new TypeLoadException ("Error loading '" + typeName + "'");
- return t;
- }
-
- internal static IntPtr[] CopyRuntimeTypeHandles (RuntimeTypeHandle[] inHandles, out int length)
- {
- if (inHandles == null || inHandles.Length == 0) {
- length = 0;
- return null;
- }
-
- IntPtr[] outHandles = new IntPtr [inHandles.Length];
- for (int i = 0; i < inHandles.Length; i++)
- outHandles [i] = inHandles [i].Value;
- length = outHandles.Length;
- return outHandles;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Security/DynamicSecurityMethodAttribute.cs b/netcore/System.Private.CoreLib/src/System/Security/DynamicSecurityMethodAttribute.cs
deleted file mode 100644
index 83be902a2c5..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Security/DynamicSecurityMethodAttribute.cs
+++ /dev/null
@@ -1,21 +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 System.Runtime.InteropServices;
-
-namespace System.Security
-{
- // DynamicSecurityMethodAttribute:
- // All methods that use StackCrawlMark should be marked with this attribute. This attribute
- // disables inlining of the calling method to allow stackwalking to find the exact caller.
- //
- // This attribute used to indicate that the target method requires space for a security object
- // to be allocated on the callers stack. It is not used for this purpose anymore because of security
- // stackwalks are not ever done in CoreCLR.
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = true, Inherited = false)]
- internal sealed class DynamicSecurityMethodAttribute : Attribute
- {
- public DynamicSecurityMethodAttribute() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/String.Mono.cs b/netcore/System.Private.CoreLib/src/System/String.Mono.cs
deleted file mode 100644
index c103a1e8ac0..00000000000
--- a/netcore/System.Private.CoreLib/src/System/String.Mono.cs
+++ /dev/null
@@ -1,144 +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 System.Runtime.CompilerServices;
-using Internal.Runtime.CompilerServices;
-
-namespace System
-{
- partial class String
- {
- [Intrinsic]
- public static readonly String Empty;
-
- public int Length {
- [Intrinsic]
- get => _stringLength;
- }
-
- [IndexerName ("Chars")]
- public char this [int index] {
- [Intrinsic]
- get => this [index];
- }
-
- public static String Intern (String str)
- {
- if (str == null)
- throw new ArgumentNullException(nameof(str));
-
- return InternalIntern (str);
- }
-
- public static String IsInterned (String str)
- {
- if (str == null)
- throw new ArgumentNullException(nameof(str));
-
- return InternalIsInterned (str);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static String FastAllocateString (int length);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static String InternalIsInterned (String str);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static String InternalIntern (String str);
-
- // TODO: Should be pointing to Buffer instead
- #region Runtime method-to-ir dependencies
-
- static unsafe void memset (byte *dest, int val, int len)
- {
- if (len < 8) {
- while (len != 0) {
- *dest = (byte)val;
- ++dest;
- --len;
- }
- return;
- }
- if (val != 0) {
- val = val | (val << 8);
- val = val | (val << 16);
- }
- // align to 4
- int rest = (int)dest & 3;
- if (rest != 0) {
- rest = 4 - rest;
- len -= rest;
- do {
- *dest = (byte)val;
- ++dest;
- --rest;
- } while (rest != 0);
- }
- while (len >= 16) {
- ((int*)dest) [0] = val;
- ((int*)dest) [1] = val;
- ((int*)dest) [2] = val;
- ((int*)dest) [3] = val;
- dest += 16;
- len -= 16;
- }
- while (len >= 4) {
- ((int*)dest) [0] = val;
- dest += 4;
- len -= 4;
- }
- // tail bytes
- while (len > 0) {
- *dest = (byte)val;
- dest++;
- len--;
- }
- }
-
- static unsafe void memcpy (byte *dest, byte *src, int size)
- {
- Buffer.Memcpy (dest, src, size);
- }
-
- /* Used by the runtime */
- internal static unsafe void bzero (byte *dest, int len) {
- memset (dest, 0, len);
- }
-
- internal static unsafe void bzero_aligned_1 (byte *dest, int len) {
- ((byte*)dest) [0] = 0;
- }
-
- internal static unsafe void bzero_aligned_2 (byte *dest, int len) {
- ((short*)dest) [0] = 0;
- }
-
- internal static unsafe void bzero_aligned_4 (byte *dest, int len) {
- ((int*)dest) [0] = 0;
- }
-
- internal static unsafe void bzero_aligned_8 (byte *dest, int len) {
- ((long*)dest) [0] = 0;
- }
-
- internal static unsafe void memcpy_aligned_1 (byte *dest, byte *src, int size) {
- ((byte*)dest) [0] = ((byte*)src) [0];
- }
-
- internal static unsafe void memcpy_aligned_2 (byte *dest, byte *src, int size) {
- ((short*)dest) [0] = ((short*)src) [0];
- }
-
- internal static unsafe void memcpy_aligned_4 (byte *dest, byte *src, int size) {
- ((int*)dest) [0] = ((int*)src) [0];
- }
-
- internal static unsafe void memcpy_aligned_8 (byte *dest, byte *src, int size) {
- ((long*)dest) [0] = ((long*)src) [0];
- }
-
- #endregion
- }
-} \ No newline at end of file
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Unix.Mono.cs b/netcore/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Unix.Mono.cs
deleted file mode 100644
index 5318ecbfbda..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Unix.Mono.cs
+++ /dev/null
@@ -1,91 +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.Runtime.CompilerServices;
-
-namespace System.Threading
-{
- partial class EventWaitHandle
- {
- public bool Set ()
- {
- SafeWaitHandle handle = ValidateHandle (out bool release);
-
- try {
- return SetEventInternal (handle.DangerousGetHandle ());
- } finally {
- if (release)
- handle.DangerousRelease ();
- }
- }
-
- public bool Reset ()
- {
- SafeWaitHandle handle = ValidateHandle (out bool release);
-
- try {
- return ResetEventInternal (handle.DangerousGetHandle ());
- } finally {
- if (release)
- handle.DangerousRelease ();
- }
- }
-
- unsafe void CreateEventCore (bool initialState, EventResetMode mode, string name, out bool createdNew)
- {
- if (name != null)
- throw new PlatformNotSupportedException (SR.PlatformNotSupported_NamedSynchronizationPrimitives);
-
- SafeWaitHandle handle = new SafeWaitHandle (CreateEventInternal (mode == EventResetMode.ManualReset, initialState, null, 0, out int errorCode), ownsHandle: true);
- if (errorCode != 0)
- throw new NotImplementedException ("errorCode");
- SafeWaitHandle = handle;
-
- createdNew = true;
- }
-
- static OpenExistingResult OpenExistingWorker (string name, out EventWaitHandle result)
- {
- throw new PlatformNotSupportedException (SR.PlatformNotSupported_NamedSynchronizationPrimitives);
- }
-
- internal static bool Set (SafeWaitHandle waitHandle)
- {
- bool release = false;
- try {
- waitHandle.DangerousAddRef (ref release);
- return SetEventInternal (waitHandle.DangerousGetHandle ());
- } finally {
- if (release)
- waitHandle.DangerousRelease ();
- }
- }
-
- SafeWaitHandle ValidateHandle (out bool success)
- {
- // The field value is modifiable via the public <see cref="WaitHandle.SafeWaitHandle"/> property, save it locally
- // to ensure that one instance is used in all places in this method
- SafeWaitHandle waitHandle = SafeWaitHandle;
- if (waitHandle.IsInvalid)
- {
- throw new InvalidOperationException ();
- }
-
- success = false;
- waitHandle.DangerousAddRef (ref success);
- return waitHandle;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- unsafe static extern IntPtr CreateEventInternal (bool manual, bool initialState, char *name, int name_length, out int errorCode);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern bool ResetEventInternal (IntPtr handle);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern bool SetEventInternal (IntPtr handle);
-
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/Interlocked.cs b/netcore/System.Private.CoreLib/src/System/Threading/Interlocked.cs
deleted file mode 100644
index cbc041c7d35..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/Interlocked.cs
+++ /dev/null
@@ -1,165 +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 System.Runtime.CompilerServices;
-using Internal.Runtime.CompilerServices;
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Threading
-{
- public static class Interlocked
- {
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static int CompareExchange (ref int location1, int value, int comparand);
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void CompareExchange (ref object location1, ref object value, ref object comparand, ref object result);
-
- [Intrinsic]
- public static object CompareExchange (ref object location1, object value, object comparand)
- {
- // This avoids coop handles, esp. on the output which would be particularly inefficient.
- // Passing everything by ref is equivalent to coop handles -- ref to locals at least.
- //
- // location1's treatment is unclear. But note that passing it by handle would be incorrect,
- // as it would use a local alias, which the coop marshaling does, to avoid the unclarity here,
- // that of a ref being to a managed frame vs. a native frame. Perhaps that could be revisited.
- //
- // So there a hole here, that of calling this function with location1 being in a native frame.
- // Usually it will be to a field, static or not, and not even to managed stack.
- //
- // This is usually intrinsified. Ideally it is always intrinisified.
- //
- object result = null;
- CompareExchange (ref location1, ref value, ref comparand, ref result);
- return result;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public extern static float CompareExchange (ref float location1, float value, float comparand);
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static int Decrement (ref int location);
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static long Decrement (ref long location);
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static int Increment (ref int location);
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static long Increment (ref long location);
-
- [Intrinsic]
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public extern static int Exchange (ref int location1, int value);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern static void Exchange (ref object location1, ref object value, ref object result);
-
- public static object Exchange (ref object location1, object value)
- {
- // See CompareExchange(object) for comments.
- object result = null;
- Exchange (ref location1, ref value, ref result);
- return result;
- }
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static float Exchange (ref float location1, float value);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public extern static long CompareExchange (ref long location1, long value, long comparand);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public extern static IntPtr CompareExchange (ref IntPtr location1, IntPtr value, IntPtr comparand);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public extern static double CompareExchange (ref double location1, double value, double comparand);
-
- [return: NotNullIfNotNull("location1")]
- [Intrinsic]
- public static T CompareExchange<T> (ref T location1, T value, T comparand) where T : class?
- {
- unsafe {
- if (Unsafe.AsPointer (ref location1) == null)
- throw new NullReferenceException ();
- }
- // Besides avoiding coop handles for efficiency,
- // and correctness, this also appears needed to
- // avoid an assertion failure in the runtime, related to
- // coop handles over generics.
- //
- // See CompareExchange(object) for comments.
- //
- // This is not entirely convincing due to lack of volatile.
- //
-#pragma warning disable 8654 // null problems; is there another way?
- T result = null;
-#pragma warning restore 8654
- // T : class so call the object overload.
- CompareExchange (ref Unsafe.As<T, object?> (ref location1), ref Unsafe.As<T, object?>(ref value), ref Unsafe.As<T, object?>(ref comparand), ref Unsafe.As<T, object?>(ref result));
- return result;
- }
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static long Exchange (ref long location1, long value);
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static IntPtr Exchange (ref IntPtr location1, IntPtr value);
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static double Exchange (ref double location1, double value);
-
- [return: NotNullIfNotNull("location1")]
- [Intrinsic]
- public static T Exchange<T> (ref T location1, T value) where T : class?
- {
- unsafe {
- if (Unsafe.AsPointer (ref location1) == null)
- throw new NullReferenceException ();
- }
- // See CompareExchange(T) for comments.
- //
- // This is not entirely convincing due to lack of volatile.
- //
-#pragma warning disable 8654 // null problems; is there another way?
- T result = null;
-#pragma warning restore 8654
- // T : class so call the object overload.
- Exchange (ref Unsafe.As<T,object?>(ref location1), ref Unsafe.As<T, object?>(ref value), ref Unsafe.As<T, object?>(ref result));
- return result;
- }
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static long Read (ref long location);
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static int Add (ref int location1, int value);
-
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static long Add (ref long location1, long value);
-
- [Intrinsic]
- public static void MemoryBarrier ()
- {
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public extern static void MemoryBarrierProcessWide ();
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Unix.Mono.cs b/netcore/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Unix.Mono.cs
deleted file mode 100644
index b43b6cd4d51..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Unix.Mono.cs
+++ /dev/null
@@ -1,131 +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 Internal.Runtime.CompilerServices;
-
-namespace System.Threading
-{
- internal unsafe sealed partial class LowLevelLifoSemaphore : IDisposable
- {
- struct WaitEntry
- {
- public object condition;
- public bool signaled;
- public void* previous;
- public void* next;
- }
-
- private object mutex;
- private void* head;
- private uint pending_signals;
-
- private void Create (int maximumSignalCount)
- {
- mutex = new object();
- head = null;
- pending_signals = 0;
- }
-
- public void Dispose ()
- {
- }
-
- private bool WaitCore (int timeoutMs)
- {
- WaitEntry wait_entry = new WaitEntry ();
- bool mutexLocked = false;
- bool waitEntryLocked = false;
-
- try {
- Monitor.try_enter_with_atomic_var (mutex, Timeout.Infinite, false, ref mutexLocked);
-
- if (pending_signals > 0) {
- --pending_signals;
- return true;
- }
-
- wait_entry.condition = new object();
- wait_entry.previous = null;
- wait_entry.next = head;
- if (head != null) {
- Unsafe.AsRef<WaitEntry> (head).previous = Unsafe.AsPointer<WaitEntry> (ref wait_entry);
- }
- head = Unsafe.AsPointer<WaitEntry> (ref wait_entry);
- }
- finally {
- if (mutexLocked) {
- Monitor.Exit (mutex);
- }
- }
-
- try {
- Monitor.try_enter_with_atomic_var (wait_entry.condition, Timeout.Infinite, false, ref waitEntryLocked);
- if (!wait_entry.signaled) {
- Monitor.Monitor_wait (wait_entry.condition, timeoutMs, false);
- }
- }
- finally {
- if (waitEntryLocked)
- Monitor.Exit (wait_entry.condition);
- }
-
- mutexLocked = false;
- try {
- Monitor.try_enter_with_atomic_var (mutex, Timeout.Infinite, false, ref mutexLocked);
-
- if (!wait_entry.signaled) {
- if (head == Unsafe.AsPointer<WaitEntry> (ref wait_entry)) {
- head = wait_entry.next;
- }
- if (wait_entry.next != null) {
- Unsafe.AsRef<WaitEntry> (wait_entry.next).previous = wait_entry.previous;
- }
- if (wait_entry.previous != null) {
- Unsafe.AsRef<WaitEntry> (wait_entry.previous).next = wait_entry.next;
- }
- }
- }
- finally {
- if (mutexLocked) {
- Monitor.Exit (mutex);
- }
- }
-
- return wait_entry.signaled;
- }
-
- private void ReleaseCore (int count)
- {
- bool mutexLocked = false;
- try {
- Monitor.try_enter_with_atomic_var (mutex, Timeout.Infinite, false, ref mutexLocked);
- while (count > 0) {
- if (head != null) {
- ref WaitEntry wait_entry = ref Unsafe.AsRef<WaitEntry> (head);
- head = wait_entry.next;
- if (head != null) {
- Unsafe.AsRef<WaitEntry> (head).previous = null;
- }
- wait_entry.previous = null;
- wait_entry.next = null;
- lock (wait_entry.condition)
- {
- wait_entry.signaled = true;
- Monitor.Pulse (wait_entry.condition);
- }
- --count;
- } else {
- pending_signals += (uint)count;
- count = 0;
- }
- }
- }
- finally {
- if (mutexLocked) {
- Monitor.Exit (mutex);
- }
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/LowLevelLock.cs b/netcore/System.Private.CoreLib/src/System/Threading/LowLevelLock.cs
deleted file mode 100644
index d2fc5cfedeb..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/LowLevelLock.cs
+++ /dev/null
@@ -1,41 +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 System.Diagnostics;
-
-namespace System.Threading
-{
- // This class provides implementation of uninterruptible lock for internal
- // use by thread pool.
- internal class LowLevelLock : IDisposable
- {
- public void Dispose ()
- {
- }
-
- public bool TryAcquire()
- {
- bool lockTaken = false;
- Monitor.try_enter_with_atomic_var (this, 0, false, ref lockTaken);
- return lockTaken;
- }
-
- public void Acquire()
- {
- bool lockTaken = false;
- Monitor.try_enter_with_atomic_var (this, Timeout.Infinite, false, ref lockTaken);
- }
-
- public void Release()
- {
- Monitor.Exit (this);
- }
-
- [Conditional("DEBUG")]
- public void VerifyIsLocked()
- {
- Debug.Assert (Monitor.IsEntered (this));
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/LowLevelSpinWaiter.cs b/netcore/System.Private.CoreLib/src/System/Threading/LowLevelSpinWaiter.cs
deleted file mode 100644
index f5d52223768..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/LowLevelSpinWaiter.cs
+++ /dev/null
@@ -1,55 +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 System.Diagnostics;
-
-namespace System.Threading
-{
- internal struct LowLevelSpinWaiter
- {
- public static void Wait (int spinIndex, int sleep0Threshold, int processorCount)
- {
- Debug.Assert (spinIndex >= 0);
- Debug.Assert (sleep0Threshold >= 0);
-
- // Wait
- //
- // (spinIndex - Sleep0Threshold) % 2 != 0: The purpose of this check is to interleave Thread.Yield/Sleep(0) with
- // Thread.SpinWait. Otherwise, the following issues occur:
- // - When there are no threads to switch to, Yield and Sleep(0) become no-op and it turns the spin loop into a
- // busy-spin that may quickly reach the max spin count and cause the thread to enter a wait state. Completing the
- // spin loop too early can cause excessive context switcing from the wait.
- // - If there are multiple threads doing Yield and Sleep(0) (typically from the same spin loop due to contention),
- // they may switch between one another, delaying work that can make progress.
- if (processorCount > 1 && (spinIndex < sleep0Threshold || (spinIndex - sleep0Threshold) % 2 != 0)) {
- // Cap the maximum spin count to a value such that many thousands of CPU cycles would not be wasted doing
- // the equivalent of YieldProcessor(), as that that point SwitchToThread/Sleep(0) are more likely to be able to
- // allow other useful work to run. Long YieldProcessor() loops can help to reduce contention, but Sleep(1) is
- // usually better for that.
- //
- // Thread.OptimalMaxSpinWaitsPerSpinIteration:
- // - See Thread::InitializeYieldProcessorNormalized(), which describes and calculates this value.
- //
- int n = Thread.OptimalMaxSpinWaitsPerSpinIteration;
- if (spinIndex <= 30 && (1 << spinIndex) < n)
- {
- n = 1 << spinIndex;
- }
- Thread.SpinWait (n);
- return;
- }
-
- // Thread.Sleep(int) is interruptible. The current operation may not allow thread interrupt
- // (for instance, LowLevelLock.Acquire as part of EventWaitHandle.Set). Use the
- // uninterruptible version of Sleep(0). Not doing Thread.Yield, it does not seem to have any
- // benefit over Sleep(0).
- Thread.UninterruptibleSleep0 ();
-
- // Don't want to Sleep(1) in this spin wait:
- // - Don't want to spin for that long, since a proper wait will follow when the spin wait fails
- // - Sleep(1) would put the thread into a wait state, and a proper wait will follow when the spin wait fails
- // anyway (the intended use for this class), so it's preferable to put the thread into the proper wait state
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs b/netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs
deleted file mode 100644
index 5c94a164ca7..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs
+++ /dev/null
@@ -1,178 +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 System.Runtime.CompilerServices;
-
-namespace System.Threading
-{
- public static class Monitor
- {
- [Intrinsic]
- [MethodImplAttribute (MethodImplOptions.InternalCall)] // Interpreter is missing this intrinsic
- public static void Enter (object obj) => Enter (obj);
-
- [Intrinsic]
- public static void Enter (object obj, ref bool lockTaken)
- {
- // TODO: Interpreter is missing this intrinsic
- if (lockTaken)
- throw new ArgumentException (SR.Argument_MustBeFalse, nameof (lockTaken));
-
- ReliableEnterTimeout (obj, (int) Timeout.Infinite, ref lockTaken);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- public static extern void Exit (object obj);
-
- public static bool TryEnter (object obj)
- {
- bool lockTaken = false;
- TryEnter (obj, 0, ref lockTaken);
- return lockTaken;
- }
-
- public static void TryEnter (object obj, ref bool lockTaken)
- {
- if (lockTaken)
- throw new ArgumentException (SR.Argument_MustBeFalse, nameof (lockTaken));
-
- ReliableEnterTimeout (obj, 0, ref lockTaken);
- }
-
- public static bool TryEnter (object obj, int millisecondsTimeout)
- {
- bool lockTaken = false;
- TryEnter (obj, millisecondsTimeout, ref lockTaken);
- return lockTaken;
- }
-
- static int MillisecondsTimeoutFromTimeSpan (TimeSpan timeout)
- {
- long tm = (long) timeout.TotalMilliseconds;
- if (tm < -1 || tm > (long) int.MaxValue)
- throw new ArgumentOutOfRangeException (nameof (timeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- return (int) tm;
- }
-
- public static bool TryEnter (object obj, TimeSpan timeout)
- {
- return TryEnter (obj, MillisecondsTimeoutFromTimeSpan (timeout));
- }
-
- public static void TryEnter (object obj, int millisecondsTimeout, ref bool lockTaken)
- {
- if (lockTaken)
- throw new ArgumentException (SR.Argument_MustBeFalse, nameof (lockTaken));
- ReliableEnterTimeout (obj, millisecondsTimeout, ref lockTaken);
- }
-
- public static void TryEnter(object obj, TimeSpan timeout, ref bool lockTaken)
- {
- if (lockTaken)
- throw new ArgumentException (SR.Argument_MustBeFalse, nameof (lockTaken));
- ReliableEnterTimeout (obj, MillisecondsTimeoutFromTimeSpan (timeout), ref lockTaken);
- }
-
- public static bool IsEntered (object obj)
- {
- if (obj == null)
- throw new ArgumentNullException (nameof (obj));
- return IsEnteredNative (obj);
- }
-
- public static bool Wait (object obj, int millisecondsTimeout, bool exitContext)
- {
- if (obj == null)
- throw new ArgumentNullException (nameof (obj));
- return ObjWait (exitContext, millisecondsTimeout, obj);
- }
-
- public static bool Wait (object obj, TimeSpan timeout, bool exitContext) => Wait (obj, MillisecondsTimeoutFromTimeSpan (timeout), exitContext);
-
- public static bool Wait (object obj, int millisecondsTimeout) => Wait (obj, millisecondsTimeout, false);
-
- public static bool Wait(object obj, TimeSpan timeout) => Wait (obj, MillisecondsTimeoutFromTimeSpan (timeout), false);
-
- public static bool Wait(object obj) => Wait (obj, Timeout.Infinite, false);
-
- public static void Pulse (object obj)
- {
- if (obj == null)
- throw new ArgumentNullException (nameof (obj));
- ObjPulse (obj);
- }
-
- public static void PulseAll (object obj)
- {
- if (obj == null)
- throw new ArgumentNullException (nameof (obj));
- ObjPulseAll (obj);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static bool Monitor_test_synchronised (object obj);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void Monitor_pulse (object obj);
-
- static void ObjPulse (object obj)
- {
- if (!Monitor_test_synchronised (obj))
- throw new SynchronizationLockException ("Object is not synchronized");
-
- Monitor_pulse (obj);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void Monitor_pulse_all (object obj);
-
- static void ObjPulseAll (object obj)
- {
- if (!Monitor_test_synchronised (obj))
- throw new SynchronizationLockException ("Object is not synchronized");
-
- Monitor_pulse_all (obj);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static bool Monitor_wait (object obj, int ms, bool allowInterruption);
-
- static bool ObjWait (bool exitContext, int millisecondsTimeout, object obj)
- {
- if (millisecondsTimeout < 0 && millisecondsTimeout != (int) Timeout.Infinite)
- throw new ArgumentOutOfRangeException ("millisecondsTimeout");
- if (!Monitor_test_synchronised (obj))
- throw new SynchronizationLockException ("Object is not synchronized");
-
- return Monitor_wait (obj, millisecondsTimeout, true);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern static void try_enter_with_atomic_var (object obj, int millisecondsTimeout, bool allowInterruption, ref bool lockTaken);
-
- static void ReliableEnterTimeout (object obj, int timeout, ref bool lockTaken)
- {
- if (obj == null)
- throw new ArgumentNullException (nameof (obj));
-
- if (timeout < 0 && timeout != (int) Timeout.Infinite)
- throw new ArgumentOutOfRangeException (nameof (timeout));
-
- try_enter_with_atomic_var (obj, timeout, true, ref lockTaken);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static bool Monitor_test_owner (object obj);
-
- static bool IsEnteredNative (object obj)
- {
- return Monitor_test_owner (obj);
- }
-
- public extern static long LockContentionCount {
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- get;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/Mutex.Unix.Mono.cs b/netcore/System.Private.CoreLib/src/System/Threading/Mutex.Unix.Mono.cs
deleted file mode 100644
index d5065da3547..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/Mutex.Unix.Mono.cs
+++ /dev/null
@@ -1,72 +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 System.Runtime.CompilerServices;
-using System.IO;
-
-namespace System.Threading
-{
- partial class Mutex
- {
- Mutex (IntPtr handle) => Handle = handle;
-
- public void ReleaseMutex ()
- {
- if (!ReleaseMutex_internal (Handle))
- throw new ApplicationException (SR.Arg_SynchronizationLockException);
- }
-
- void CreateMutexCore (bool initiallyOwned, string name, out bool createdNew) =>
- Handle = CreateMutex_internal (initiallyOwned, name, out createdNew);
-
- unsafe static IntPtr CreateMutex_internal (bool initiallyOwned, string name, out bool created)
- {
- fixed (char *fixed_name = name)
- return CreateMutex_icall (initiallyOwned, fixed_name,
- name?.Length ?? 0, out created);
- }
-
- static OpenExistingResult OpenExistingWorker (string name, out Mutex result)
- {
- if (name == null)
- throw new ArgumentNullException (nameof (name));
-
- result = null;
- if ((name.Length == 0) ||
- (name.Length > 260)) {
- return OpenExistingResult.NameInvalid;
- }
-
- MonoIOError error;
- IntPtr handle = OpenMutex_internal (name, out error);
- if (handle == IntPtr.Zero) {
- if (error == MonoIOError.ERROR_FILE_NOT_FOUND) {
- return OpenExistingResult.NameNotFound;
- } else if (error == MonoIOError.ERROR_ACCESS_DENIED) {
- throw new UnauthorizedAccessException ();
- } else {
- return OpenExistingResult.PathNotFound;
- }
- }
-
- result = new Mutex (handle);
- return OpenExistingResult.Success;
- }
-
- unsafe static IntPtr OpenMutex_internal (string name, out MonoIOError error)
- {
- fixed (char *fixed_name = name)
- return OpenMutex_icall (fixed_name, name?.Length ?? 0, 0x000001 /* MutexRights.Modify */, out error);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private unsafe static extern IntPtr CreateMutex_icall (bool initiallyOwned, char *name, int name_length, out bool created);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private unsafe static extern IntPtr OpenMutex_icall (char *name, int name_length, int rights, out MonoIOError error);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern bool ReleaseMutex_internal (IntPtr handle);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/Overlapped.cs b/netcore/System.Private.CoreLib/src/System/Threading/Overlapped.cs
deleted file mode 100644
index 321207172d4..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/Overlapped.cs
+++ /dev/null
@@ -1,320 +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 System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- #region class _IOCompletionCallback
-
- internal unsafe class _IOCompletionCallback
- {
- private IOCompletionCallback _ioCompletionCallback;
- private ExecutionContext _executionContext;
- private uint _errorCode; // Error code
- private uint _numBytes; // No. of bytes transferred
- private NativeOverlapped* _pNativeOverlapped;
-
- internal _IOCompletionCallback(IOCompletionCallback ioCompletionCallback, ExecutionContext executionContext)
- {
- _ioCompletionCallback = ioCompletionCallback;
- _executionContext = executionContext;
- }
-
- // Context callback: same sig for SendOrPostCallback and ContextCallback
- internal static ContextCallback s_ccb = new ContextCallback(IOCompletionCallback_Context);
- private static void IOCompletionCallback_Context(object? state)
- {
- _IOCompletionCallback helper = (_IOCompletionCallback)state!;
- Debug.Assert(helper != null, "_IOCompletionCallback cannot be null");
- helper._ioCompletionCallback(helper._errorCode, helper._numBytes, helper._pNativeOverlapped);
- }
-
- //TODO: call from ThreadPool
- internal static unsafe void PerformIOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped* pNativeOverlapped)
- {
- do
- {
- OverlappedData overlapped = OverlappedData.GetOverlappedFromNative(pNativeOverlapped);
-
- if (overlapped._callback is IOCompletionCallback iocb)
- {
- // We got here because of UnsafePack (or) Pack with EC flow suppressed
- iocb(errorCode, numBytes, pNativeOverlapped);
- }
- else
- {
- // We got here because of Pack
- var helper = (_IOCompletionCallback)overlapped._callback;
- helper._errorCode = errorCode;
- helper._numBytes = numBytes;
- helper._pNativeOverlapped = pNativeOverlapped;
- ExecutionContext.Run(helper._executionContext, s_ccb, helper);
- }
-
- //Quickly check the VM again, to see if a packet has arrived.
- //OverlappedData.CheckVMForIOPacket(out pOVERLAP, out errorCode, out numBytes);
- pNativeOverlapped = null;
- } while (pNativeOverlapped != null);
- }
- }
-
- #endregion class _IOCompletionCallback
-
- #region class OverlappedData
-
- internal unsafe sealed class OverlappedData
- {
- internal IAsyncResult _asyncResult;
- internal object _callback; // IOCompletionCallback or _IOCompletionCallback
- internal Overlapped _overlapped;
- private object _userObject;
- private NativeOverlapped * _pNativeOverlapped;
- private IntPtr _eventHandle;
- private int _offsetLow;
- private int _offsetHigh;
- private GCHandle[] _pinnedData;
-
- internal ref IAsyncResult AsyncResult => ref _asyncResult;
-
- internal ref int OffsetLow => ref (_pNativeOverlapped != null) ? ref _pNativeOverlapped->OffsetLow : ref _offsetLow;
- internal ref int OffsetHigh => ref (_pNativeOverlapped != null) ? ref _pNativeOverlapped->OffsetHigh : ref _offsetHigh;
- internal ref IntPtr EventHandle => ref (_pNativeOverlapped != null) ? ref _pNativeOverlapped->EventHandle : ref _eventHandle;
-
- internal unsafe NativeOverlapped* Pack(IOCompletionCallback iocb, object userData)
- {
- if (_pNativeOverlapped != null)
- {
- throw new InvalidOperationException(SR.InvalidOperation_Overlapped_Pack);
- }
-
- if (iocb != null)
- {
- ExecutionContext ec = ExecutionContext.Capture();
- _callback = (ec != null && !ec.IsDefault) ? new _IOCompletionCallback(iocb, ec) : (object)iocb;
- }
- else
- {
- _callback = null;
- }
- _userObject = userData;
- return AllocateNativeOverlapped();
- }
-
- internal unsafe NativeOverlapped* UnsafePack(IOCompletionCallback iocb, object userData)
- {
- if (_pNativeOverlapped != null)
- {
- throw new InvalidOperationException(SR.InvalidOperation_Overlapped_Pack);
- }
- _userObject = userData;
- _callback = iocb;
- return AllocateNativeOverlapped();
- }
-
- private unsafe NativeOverlapped* AllocateNativeOverlapped()
- {
- Debug.Assert(_pinnedData == null);
-
- bool success = false;
- try
- {
- if (_userObject != null)
- {
- if (_userObject.GetType() == typeof(object[]))
- {
- object[] objArray = (object[])_userObject;
-
- _pinnedData = new GCHandle[objArray.Length];
- for (int i = 0; i < objArray.Length; i++)
- {
- _pinnedData[i] = GCHandle.Alloc(objArray[i], GCHandleType.Pinned);
- }
- }
- else
- {
- _pinnedData = new GCHandle[1];
- _pinnedData[0] = GCHandle.Alloc(_userObject, GCHandleType.Pinned);
- }
- }
-
- //CORERT: NativeOverlapped* pNativeOverlapped = (NativeOverlapped*)Interop.MemAlloc((UIntPtr)(sizeof(NativeOverlapped) + sizeof(GCHandle)));
- NativeOverlapped* pNativeOverlapped = (NativeOverlapped*) Marshal.AllocHGlobal((IntPtr) (sizeof(NativeOverlapped) + sizeof(GCHandle)));
-
- *(GCHandle*)(pNativeOverlapped + 1) = default(GCHandle);
- _pNativeOverlapped = pNativeOverlapped;
-
- _pNativeOverlapped->InternalLow = default;
- _pNativeOverlapped->InternalHigh = default;
- _pNativeOverlapped->OffsetLow = _offsetLow;
- _pNativeOverlapped->OffsetHigh = _offsetHigh;
- _pNativeOverlapped->EventHandle = _eventHandle;
-
- *(GCHandle*)(_pNativeOverlapped + 1) = GCHandle.Alloc(this);
-
- success = true;
- return _pNativeOverlapped;
- }
- finally
- {
- if (!success)
- FreeNativeOverlapped();
- }
- }
-
- internal static unsafe void FreeNativeOverlapped(NativeOverlapped* nativeOverlappedPtr)
- {
- OverlappedData overlappedData = OverlappedData.GetOverlappedFromNative(nativeOverlappedPtr);
- overlappedData.FreeNativeOverlapped();
- }
-
- private void FreeNativeOverlapped()
- {
- if (_pinnedData != null)
- {
- for (int i = 0; i < _pinnedData.Length; i++)
- {
- if (_pinnedData[i].IsAllocated)
- {
- _pinnedData[i].Free();
- }
- }
- _pinnedData = null;
- }
-
- if (_pNativeOverlapped != null)
- {
- GCHandle handle = *(GCHandle*)(_pNativeOverlapped + 1);
- if (handle.IsAllocated)
- handle.Free();
-
- Marshal.FreeHGlobal((IntPtr)_pNativeOverlapped);
- //CORERT: Interop.MemFree((IntPtr)_pNativeOverlapped);
- _pNativeOverlapped = null;
- }
- }
-
- internal static unsafe OverlappedData GetOverlappedFromNative(NativeOverlapped* pNativeOverlapped)
- {
- GCHandle handle = *(GCHandle*)(pNativeOverlapped + 1);
- return (OverlappedData)handle.Target;
- }
- }
-
- #endregion class OverlappedData
-
- #region class Overlapped
-
- public class Overlapped
- {
- private OverlappedData _overlappedData;
-
- public Overlapped()
- {
- _overlappedData = new OverlappedData();
- _overlappedData._overlapped = this;
- }
-
- public Overlapped(int offsetLo, int offsetHi, IntPtr hEvent, IAsyncResult ar) : this()
- {
- _overlappedData.OffsetLow = offsetLo;
- _overlappedData.OffsetHigh = offsetHi;
- _overlappedData.EventHandle = hEvent;
- _overlappedData.AsyncResult = ar;
- }
-
- [Obsolete("This constructor is not 64-bit compatible. Use the constructor that takes an IntPtr for the event handle. http://go.microsoft.com/fwlink/?linkid=14202")]
- public Overlapped(int offsetLo, int offsetHi, int hEvent, IAsyncResult ar) : this(offsetLo, offsetHi, new IntPtr(hEvent), ar)
- {
- }
-
- public IAsyncResult AsyncResult
- {
- get { return _overlappedData.AsyncResult; }
- set { _overlappedData.AsyncResult = value; }
- }
-
- public int OffsetLow
- {
- get { return _overlappedData.OffsetLow; }
- set { _overlappedData.OffsetLow = value; }
- }
-
- public int OffsetHigh
- {
- get { return _overlappedData.OffsetHigh; }
- set { _overlappedData.OffsetHigh = value; }
- }
-
- [Obsolete("This property is not 64-bit compatible. Use EventHandleIntPtr instead. http://go.microsoft.com/fwlink/?linkid=14202")]
- public int EventHandle
- {
- get { return EventHandleIntPtr.ToInt32(); }
- set { EventHandleIntPtr = new IntPtr(value); }
- }
-
- public IntPtr EventHandleIntPtr
- {
- get { return _overlappedData.EventHandle; }
- set { _overlappedData.EventHandle = value; }
- }
-
- /*====================================================================
- * Packs a managed overlapped class into native Overlapped struct.
- * Roots the iocb and stores it in the ReservedCOR field of native Overlapped
- * Pins the native Overlapped struct and returns the pinned index.
- ====================================================================*/
- [Obsolete("This method is not safe. Use Pack (iocb, userData) instead. http://go.microsoft.com/fwlink/?linkid=14202")]
- [CLSCompliant(false)]
- public unsafe NativeOverlapped* Pack(IOCompletionCallback iocb)
- {
- return Pack(iocb, null);
- }
-
- [CLSCompliant(false)]
- public unsafe NativeOverlapped* Pack(IOCompletionCallback iocb, object userData)
- {
- return _overlappedData.Pack(iocb, userData);
- }
-
- [Obsolete("This method is not safe. Use UnsafePack (iocb, userData) instead. http://go.microsoft.com/fwlink/?linkid=14202")]
- [CLSCompliant(false)]
- public unsafe NativeOverlapped* UnsafePack(IOCompletionCallback iocb)
- {
- return UnsafePack(iocb, null);
- }
-
- [CLSCompliant(false)]
- public unsafe NativeOverlapped* UnsafePack(IOCompletionCallback iocb, object userData)
- {
- return _overlappedData.UnsafePack(iocb, userData);
- }
-
- /*====================================================================
- * Unpacks an unmanaged native Overlapped struct.
- * Unpins the native Overlapped struct
- ====================================================================*/
- [CLSCompliant(false)]
- public static unsafe Overlapped Unpack(NativeOverlapped* nativeOverlappedPtr)
- {
- if (nativeOverlappedPtr == null)
- throw new ArgumentNullException(nameof(nativeOverlappedPtr));
-
- return OverlappedData.GetOverlappedFromNative(nativeOverlappedPtr)._overlapped;
- }
-
- [CLSCompliant(false)]
- public static unsafe void Free(NativeOverlapped* nativeOverlappedPtr)
- {
- if (nativeOverlappedPtr == null)
- throw new ArgumentNullException(nameof(nativeOverlappedPtr));
-
- OverlappedData.GetOverlappedFromNative(nativeOverlappedPtr)._overlapped._overlappedData = null;
- OverlappedData.FreeNativeOverlapped(nativeOverlappedPtr);
- }
- }
-
- #endregion class Overlapped
-} \ No newline at end of file
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/PreAllocatedOverlapped.cs b/netcore/System.Private.CoreLib/src/System/Threading/PreAllocatedOverlapped.cs
deleted file mode 100644
index 580bda2b692..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/PreAllocatedOverlapped.cs
+++ /dev/null
@@ -1,13 +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.
-
-namespace System.Threading
-{
- public sealed class PreAllocatedOverlapped : System.IDisposable
- {
- [System.CLSCompliantAttribute(false)]
- public PreAllocatedOverlapped(System.Threading.IOCompletionCallback callback, object state, object pinData) { }
- public void Dispose() { }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/Semaphore.Unix.Mono.cs b/netcore/System.Private.CoreLib/src/System/Threading/Semaphore.Unix.Mono.cs
deleted file mode 100644
index fe0426cb510..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/Semaphore.Unix.Mono.cs
+++ /dev/null
@@ -1,102 +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 System.Runtime.CompilerServices;
-using Microsoft.Win32.SafeHandles;
-using System.IO;
-
-namespace System.Threading
-{
- partial class Semaphore
- {
- const int MAX_PATH = 260;
-
- Semaphore (SafeWaitHandle handle) => this.SafeWaitHandle = handle;
-
- int ReleaseCore (int releaseCount)
- {
- if (!ReleaseSemaphore_internal (SafeWaitHandle.DangerousGetHandle (), releaseCount, out int previousCount))
- throw new SemaphoreFullException ();
-
- return previousCount;
- }
-
- static OpenExistingResult OpenExistingWorker (string name, out Semaphore result)
- {
- if (name == null)
- throw new ArgumentNullException (nameof (name));
-
- if (name.Length == 0)
- throw new ArgumentException (SR.Argument_StringZeroLength, nameof (name));
-
- if (name.Length > MAX_PATH)
- throw new ArgumentException (SR.Argument_WaitHandleNameTooLong);
-
- var myHandle = new SafeWaitHandle (OpenSemaphore_internal (name,
- /*SemaphoreRights.Modify | SemaphoreRights.Synchronize*/ 0x000002 | 0x100000,
- out MonoIOError errorCode), true);
-
- if (myHandle.IsInvalid) {
- result = null;
- switch (errorCode) {
- case MonoIOError.ERROR_FILE_NOT_FOUND:
- case MonoIOError.ERROR_INVALID_NAME:
- return OpenExistingResult.NameNotFound;
- case MonoIOError.ERROR_PATH_NOT_FOUND:
- return OpenExistingResult.PathNotFound;
- case MonoIOError.ERROR_INVALID_HANDLE when !string.IsNullOrEmpty (name):
- return OpenExistingResult.NameInvalid;
- default:
- //this is for passed through NativeMethods Errors
- throw new IOException ($"Unknown Error '{errorCode}'");
- }
- }
-
- result = new Semaphore (myHandle);
- return OpenExistingResult.Success;
- }
-
- void CreateSemaphoreCore (int initialCount, int maximumCount, string name, out bool createdNew)
- {
- if (name?.Length > MAX_PATH)
- throw new ArgumentException (SR.Argument_WaitHandleNameTooLong);
-
- var myHandle = new SafeWaitHandle (CreateSemaphore_internal (initialCount, maximumCount, name, out MonoIOError errorCode), true);
-
- if (myHandle.IsInvalid) {
- if (errorCode == MonoIOError.ERROR_INVALID_HANDLE && !string.IsNullOrEmpty (name))
- throw new WaitHandleCannotBeOpenedException (SR.Format (SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));
-
- throw new IOException ($"Unknown Error '{errorCode}'");
- }
-
- this.SafeWaitHandle = myHandle;
- createdNew = errorCode != MonoIOError.ERROR_ALREADY_EXISTS;
- }
-
- unsafe static IntPtr CreateSemaphore_internal (int initialCount, int maximumCount, string name, out MonoIOError errorCode)
- {
- // FIXME Check for embedded nuls in name.
- fixed (char *fixed_name = name)
- return CreateSemaphore_icall (initialCount, maximumCount,
- fixed_name, name?.Length ?? 0, out errorCode);
- }
-
- unsafe static IntPtr OpenSemaphore_internal (string name, int rights, out MonoIOError errorCode)
- {
- // FIXME Check for embedded nuls in name.
- fixed (char *fixed_name = name)
- return OpenSemaphore_icall (fixed_name, name?.Length ?? 0, rights, out errorCode);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- unsafe static extern IntPtr CreateSemaphore_icall (int initialCount, int maximumCount, char* name, int nameLength, out MonoIOError errorCode);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- unsafe static extern IntPtr OpenSemaphore_icall (char* name, int nameLength, int rights, out MonoIOError errorCode);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern bool ReleaseSemaphore_internal (IntPtr handle, int releaseCount, out int previousCount);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs b/netcore/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs
deleted file mode 100644
index ebcd9d8e5f9..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs
+++ /dev/null
@@ -1,17 +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.
-
-namespace System.Threading
-{
- // declaring a local var of this enum type and passing it by ref into a function that needs to do a
- // stack crawl will both prevent inlining of the calle and pass an ESP point to stack crawl to
- // Declaring these in EH clauses is illegal; they must declared in the main method body
- internal enum StackCrawlMark
- {
- LookForMe = 0,
- LookForMyCaller = 1,
- LookForMyCallersCaller = 2,
- LookForThread = 3
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs b/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs
deleted file mode 100644
index 202225aa64f..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs
+++ /dev/null
@@ -1,356 +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 System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- //
- // Under netcore, there is only one thread object per thread
- //
- [StructLayout (LayoutKind.Sequential)]
- partial class Thread
- {
-#pragma warning disable 169, 414, 649
- #region Sync with metadata/object-internals.h and InternalThread in mcs/class/corlib/System.Threading/Thread.cs
- int lock_thread_id;
- // stores a thread handle
- IntPtr handle;
- IntPtr native_handle; // used only on Win32
- /* accessed only from unmanaged code */
- private IntPtr name;
- private int name_free; // bool
- private int name_length;
- private ThreadState state;
- private object abort_exc;
- private int abort_state_handle;
- /* thread_id is only accessed from unmanaged code */
- internal Int64 thread_id;
- private IntPtr debugger_thread; // FIXME switch to bool as soon as CI testing with corlib version bump works
- private UIntPtr static_data; /* GC-tracked */
- private IntPtr runtime_thread_info;
- /* current System.Runtime.Remoting.Contexts.Context instance
- keep as an object to avoid triggering its class constructor when not needed */
- private object current_appcontext;
- private object root_domain_thread;
- internal byte[] _serialized_principal;
- internal int _serialized_principal_version;
- private IntPtr appdomain_refs;
- private int interruption_requested;
- private IntPtr longlived;
- internal bool threadpool_thread;
- private bool thread_interrupt_requested;
- /* These are used from managed code */
- internal int stack_size;
- internal byte apartment_state;
- internal volatile int critical_region_level;
- internal int managed_id;
- private int small_id;
- private IntPtr manage_callback;
- private IntPtr flags;
- private IntPtr thread_pinning_ref;
- private IntPtr abort_protected_block_count;
- private int priority;
- private IntPtr owned_mutex;
- private IntPtr suspended_event;
- private int self_suspended;
- private IntPtr thread_state;
-
- private Thread self;
- private object pending_exception;
- private object start_obj;
-
- /* This is used only to check that we are in sync between the representation
- * of MonoInternalThread in native and InternalThread in managed
- *
- * DO NOT RENAME! DO NOT ADD FIELDS AFTER! */
- private IntPtr last;
- #endregion
-#pragma warning restore 169, 414, 649
-
- string _name;
- Delegate m_start;
- object m_start_arg;
- CultureInfo culture, ui_culture;
- internal ExecutionContext _executionContext;
- internal SynchronizationContext _synchronizationContext;
-
- Thread ()
- {
- InitInternal (this);
- }
-
- ~Thread ()
- {
- FreeInternal ();
- }
-
- internal static ulong CurrentOSThreadId {
- get {
- return GetCurrentOSThreadId ();
- }
- }
-
- public bool IsAlive {
- get {
- var state = GetState (this);
- return (state & (ThreadState.Unstarted | ThreadState.Stopped | ThreadState.Aborted)) == 0;
- }
- }
-
- public bool IsBackground {
- get {
- var state = ValidateThreadState ();
- return (state & ThreadState.Background) != 0;
- }
- set {
- ValidateThreadState ();
- if (value) {
- SetState (this, ThreadState.Background);
- } else {
- ClrState (this, ThreadState.Background);
- }
- }
- }
-
- public bool IsThreadPoolThread {
- get {
- ValidateThreadState ();
- return threadpool_thread;
- }
- internal set {
- threadpool_thread = value;
- }
- }
-
- public int ManagedThreadId => managed_id;
-
- internal static int OptimalMaxSpinWaitsPerSpinIteration {
- get {
- // Default from coreclr (src/utilcode/yieldprocessornormalized.cpp)
- return 7;
- }
- }
-
- public ThreadPriority Priority {
- get {
- ValidateThreadState ();
- return (ThreadPriority) priority;
- }
- set {
- // TODO: arguments check
- SetPriority (this, (int) value);
- }
- }
-
- public ThreadState ThreadState => GetState (this);
-
- void Create (ThreadStart start) => SetStartHelper ((Delegate) start, 0); // 0 will setup Thread with default stackSize
-
- void Create (ThreadStart start, int maxStackSize) => SetStartHelper ((Delegate) start, maxStackSize);
-
- void Create (ParameterizedThreadStart start) => SetStartHelper ((Delegate) start, 0);
-
- void Create (ParameterizedThreadStart start, int maxStackSize) => SetStartHelper ((Delegate) start, maxStackSize);
-
- public ApartmentState GetApartmentState () => ApartmentState.Unknown;
-
- public void DisableComObjectEagerCleanup ()
- {
- // no-op
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern static int GetCurrentProcessorNumber ();
-
- public static int GetCurrentProcessorId ()
- {
- int id = GetCurrentProcessorNumber ();
-
- if (id < 0)
- id = Environment.CurrentManagedThreadId;
-
- return id;
- }
-
- public void Interrupt ()
- {
- InterruptInternal (this);
- }
-
- public bool Join (int millisecondsTimeout)
- {
- if (millisecondsTimeout < Timeout.Infinite)
- throw new ArgumentOutOfRangeException (nameof (millisecondsTimeout), millisecondsTimeout, SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
- return JoinInternal (this, millisecondsTimeout);
- }
-
- internal void ResetThreadPoolThread ()
- {
- if (_name != null)
- Name = null;
-
- if ((state & ThreadState.Background) == 0)
- IsBackground = true;
-
- if ((ThreadPriority) priority != ThreadPriority.Normal)
- Priority = ThreadPriority.Normal;
- }
-
- void SetCultureOnUnstartedThreadNoCheck (CultureInfo value, bool uiCulture)
- {
- if (uiCulture)
- ui_culture = value;
- else
- culture = value;
- }
-
- void SetStartHelper (Delegate start, int maxStackSize)
- {
- m_start = start;
- stack_size = maxStackSize;
- }
-
- public static void SpinWait (int iterations)
- {
- if (iterations < 0)
- return;
-
- while (iterations-- > 0)
- SpinWait_nop ();
- }
-
- public static void Sleep (int millisecondsTimeout)
- {
- if (millisecondsTimeout < Timeout.Infinite)
- throw new ArgumentOutOfRangeException (nameof (millisecondsTimeout), millisecondsTimeout, SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
-
- SleepInternal (millisecondsTimeout, true);
- }
-
- internal static void UninterruptibleSleep0 () => SleepInternal (0, false);
-
- public void Start ()
- {
- StartInternal (this);
- }
-
- public void Start (object parameter)
- {
- if (m_start is ThreadStart)
- throw new InvalidOperationException (SR.InvalidOperation_ThreadWrongThreadStart);
-
- m_start_arg = parameter;
- StartInternal (this);
- }
-
- // Called from the runtime
- internal void StartCallback ()
- {
- if (culture != null)
- CurrentCulture = culture;
- if (ui_culture != null)
- CurrentUICulture = ui_culture;
- if (m_start is ThreadStart del) {
- m_start = null;
- del ();
- } else {
- var pdel = (ParameterizedThreadStart) m_start;
- var arg = m_start_arg;
- m_start = null;
- m_start_arg = null;
- pdel (arg);
- }
- }
-
- partial void ThreadNameChanged (string value)
- {
- // TODO: Should only raise the events
- SetName (this, value);
- }
-
- public static bool Yield ()
- {
- return YieldInternal ();
- }
-
- bool TrySetApartmentStateUnchecked (ApartmentState state) => state == ApartmentState.Unknown;
-
- ThreadState ValidateThreadState ()
- {
- var state = GetState (this);
- if ((state & ThreadState.Stopped) != 0)
- throw new ThreadStateException ("Thread is dead; state can not be accessed.");
- return state;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- private extern static ulong GetCurrentOSThreadId ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void InitInternal (Thread thread);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private extern static void InitializeCurrentThread_icall (ref Thread thread);
-
- [MethodImpl (MethodImplOptions.NoInlining)]
- static Thread InitializeCurrentThread () {
- Thread thread = null;
- InitializeCurrentThread_icall (ref thread);
- return thread;
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern void FreeInternal ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static ThreadState GetState (Thread thread);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void SetState (Thread thread, ThreadState set);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void ClrState (Thread thread, ThreadState clr);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern static string GetName (Thread thread);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static unsafe extern void SetName_icall (Thread thread, char *name, int nameLength);
-
- static unsafe void SetName (Thread thread, String name)
- {
- fixed (char* fixed_name = name)
- SetName_icall (thread, fixed_name, name?.Length ?? 0);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern static bool YieldInternal ();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern static void SleepInternal (int millisecondsTimeout, bool allowInterruption);
-
- [Intrinsic]
- static void SpinWait_nop ()
- {
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static Thread CreateInternal ();
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static void StartInternal (Thread runtime_thread);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern static bool JoinInternal (Thread thread, int millisecondsTimeout);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern static void InterruptInternal (Thread thread);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern static void SetPriority (Thread thread, int priority);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs b/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs
deleted file mode 100644
index b3b3039bc59..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs
+++ /dev/null
@@ -1,49 +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 System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- public static partial class ThreadPool
- {
- private static void EnsureInitialized()
- {
- ThreadPoolGlobals.threadPoolInitialized = true;
- ThreadPoolGlobals.enableWorkerTracking = false;
- }
-
- internal static void ReportThreadStatus(bool isWorking)
- {
- }
-
- unsafe private static void NativeOverlappedCallback(object? obj)
- {
- NativeOverlapped* overlapped = (NativeOverlapped*)(IntPtr)obj!;
- _IOCompletionCallback.PerformIOCompletionCallback (0, 0, overlapped);
- }
-
- [CLSCompliant(false)]
- unsafe public static bool UnsafeQueueNativeOverlapped(NativeOverlapped* overlapped)
- {
- // OS doesn't signal handle, so do it here (CoreCLR does this assignment in ThreadPoolNative::CorPostQueuedCompletionStatus)
- overlapped->InternalLow = (IntPtr)0;
- // Both types of callbacks are executed on the same thread pool
- return UnsafeQueueUserWorkItem (NativeOverlappedCallback, (IntPtr)overlapped);
- }
-
- [Obsolete("ThreadPool.BindHandle(IntPtr) has been deprecated. Please use ThreadPool.BindHandle(SafeHandle) instead.", false)]
- public static bool BindHandle(IntPtr osHandle)
- {
- throw new PlatformNotSupportedException (SR.Arg_PlatformNotSupported); // Replaced by ThreadPoolBoundHandle.BindHandle
- }
-
- public static bool BindHandle(SafeHandle osHandle)
- {
- throw new PlatformNotSupportedException (SR.Arg_PlatformNotSupported); // Replaced by ThreadPoolBoundHandle.BindHandle
- }
-
- private static long PendingUnmanagedWorkItemCount => 0;
- }
-} \ No newline at end of file
diff --git a/netcore/System.Private.CoreLib/src/System/Threading/WaitHandle.Mono.cs b/netcore/System.Private.CoreLib/src/System/Threading/WaitHandle.Mono.cs
deleted file mode 100644
index fb11248a402..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Threading/WaitHandle.Mono.cs
+++ /dev/null
@@ -1,51 +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 System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace System.Threading
-{
- partial class WaitHandle
- {
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe static extern int Wait_internal(IntPtr* handles, int numHandles, bool waitAll, int ms);
-
- static int WaitOneCore (IntPtr waitHandle, int millisecondsTimeout)
- {
- unsafe {
- return Wait_internal (&waitHandle, 1, false, millisecondsTimeout);
- }
- }
-
- [MethodImpl (MethodImplOptions.InternalCall)]
- static extern int SignalAndWait_Internal (IntPtr waitHandleToSignal, IntPtr waitHandleToWaitOn, int millisecondsTimeout);
-
- const int ERROR_TOO_MANY_POSTS = 0x12A;
- const int ERROR_NOT_OWNED_BY_CALLER = 0x12B;
-
- static int SignalAndWaitCore (IntPtr waitHandleToSignal, IntPtr waitHandleToWaitOn, int millisecondsTimeout)
- {
- int ret = SignalAndWait_Internal (waitHandleToSignal, waitHandleToWaitOn, millisecondsTimeout);
- if (ret == ERROR_TOO_MANY_POSTS)
- throw new InvalidOperationException (SR.Threading_WaitHandleTooManyPosts);
- if (ret == ERROR_NOT_OWNED_BY_CALLER)
- throw new ApplicationException("Attempt to release mutex not owned by caller");
- return ret;
- }
-
- internal static int WaitMultipleIgnoringSyncContext (Span<IntPtr> waitHandles, bool waitAll, int millisecondsTimeout)
- {
- unsafe {
- fixed (IntPtr* handles = &MemoryMarshal.GetReference (waitHandles)) {
- return Wait_internal (handles, waitHandles.Length, waitAll, millisecondsTimeout);
- }
- }
- }
-
- // FIXME: Move to shared
- internal static int WaitAny (ReadOnlySpan<WaitHandle> waitHandles, int millisecondsTimeout) =>
- WaitMultiple (waitHandles, false, millisecondsTimeout);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/Type.Mono.cs b/netcore/System.Private.CoreLib/src/System/Type.Mono.cs
deleted file mode 100644
index a5f4fa1feea..00000000000
--- a/netcore/System.Private.CoreLib/src/System/Type.Mono.cs
+++ /dev/null
@@ -1,135 +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 System.Text;
-using System.IO;
-using System.Reflection;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-namespace System
-{
- partial class Type
- {
- #region keep in sync with object-internals.h
- internal RuntimeTypeHandle _impl;
- #endregion
-
- internal bool IsRuntimeImplemented () => this.UnderlyingSystemType is RuntimeType;
-
- internal virtual bool IsTypeBuilder () => false;
-
- public bool IsInterface {
- get {
- if (this is RuntimeType rt)
- return RuntimeTypeHandle.IsInterface (rt);
-
- return (GetAttributeFlagsImpl () & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
- }
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Type GetType (string typeName, bool throwOnError, bool ignoreCase)
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return RuntimeType.GetType (typeName, throwOnError, ignoreCase, false, ref stackMark);
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Type GetType (string typeName, bool throwOnError)
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return RuntimeType.GetType (typeName, throwOnError, false, false, ref stackMark);
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Type GetType (string typeName)
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return RuntimeType.GetType (typeName, false, false, false, ref stackMark);
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Type GetType (string typeName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver)
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return RuntimeType.GetType (typeName, assemblyResolver, typeResolver, false, false, ref stackMark);
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Type GetType (string typeName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError)
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return RuntimeType.GetType (typeName, assemblyResolver, typeResolver, throwOnError, false, ref stackMark);
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Type GetType (string typeName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase)
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return RuntimeType.GetType (typeName, assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
- }
-
- static Type GetType (string typeName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) {
- return TypeNameParser.GetType (typeName, assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
- }
-
- public static Type? GetTypeFromHandle (RuntimeTypeHandle handle)
- {
- if (handle.Value == IntPtr.Zero)
- return null;
-
- return internal_from_handle (handle.Value);
- }
-
- public static Type GetTypeFromCLSID (Guid clsid, string? server, bool throwOnError) => throw new PlatformNotSupportedException ();
-
- public static Type GetTypeFromProgID (string progID, string? server, bool throwOnError) => throw new PlatformNotSupportedException ();
-
- internal virtual Type InternalResolve ()
- {
- return UnderlyingSystemType;
- }
-
- // Called from the runtime to return the corresponding finished Type object
- internal virtual Type RuntimeResolve ()
- {
- throw new NotImplementedException ();
- }
-
- internal virtual bool IsUserType {
- get {
- return true;
- }
- }
-
- internal virtual MethodInfo GetMethod (MethodInfo fromNoninstanciated)
- {
- throw new InvalidOperationException ("can only be called in generic type");
- }
-
- internal virtual ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
- {
- throw new InvalidOperationException ("can only be called in generic type");
- }
-
- internal virtual FieldInfo GetField (FieldInfo fromNoninstanciated)
- {
- throw new InvalidOperationException ("can only be called in generic type");
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- static extern Type internal_from_handle (IntPtr handle);
-
- [Intrinsic]
- public static bool operator == (Type? left, Type? right) => left == right;
-
- public static bool operator != (Type? left, Type? right)
- {
- return !(left == right);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs b/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs
deleted file mode 100644
index 0460777d058..00000000000
--- a/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs
+++ /dev/null
@@ -1,221 +0,0 @@
-//
-// Copyright (C) 2015 Xamarin, Inc (http://www.xamarin.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-namespace System
-{
- // A TypeName is wrapper around type names in display form
- // (that is, with special characters escaped).
- //
- // Note that in general if you unescape a type name, you will
- // lose information: If the type name's DisplayName is
- // Foo\+Bar+Baz (outer class ``Foo+Bar``, inner class Baz)
- // unescaping the first plus will give you (outer class Foo,
- // inner class Bar, innermost class Baz).
- //
- // The correct way to take a TypeName apart is to feed its
- // DisplayName to TypeSpec.Parse()
- //
- interface TypeName : IEquatable<TypeName>
- {
- string DisplayName {
- get;
- }
-
- // add a nested name under this one.
- TypeName NestedName (TypeIdentifier innerName);
- }
-
- // A type identifier is a single component of a type name.
- // Unlike a general typename, a type identifier can be be
- // converted to internal form without loss of information.
- interface TypeIdentifier : TypeName
- {
- string InternalName {
- get;
- }
- }
-
- static class TypeNames
- {
- internal static TypeName FromDisplay (string displayName)
- {
- return new Display (displayName);
- }
-
- internal abstract class ATypeName : TypeName
- {
- public abstract string DisplayName { get; }
-
- public abstract TypeName NestedName (TypeIdentifier innerName);
-
- public bool Equals (TypeName other)
- {
- return other != null && DisplayName == other.DisplayName;
- }
-
- public override int GetHashCode ()
- {
- return DisplayName.GetHashCode ();
- }
-
- public override bool Equals (object? other)
- {
- return Equals (other as TypeName);
- }
- }
-
- private class Display : ATypeName
- {
- string displayName;
-
- internal Display (string displayName)
- {
- this.displayName = displayName;
- }
-
- public override string DisplayName { get { return displayName; } }
-
- public override TypeName NestedName (TypeIdentifier innerName)
- {
- return new Display (DisplayName + "+" + innerName.DisplayName);
- }
-
- }
- }
-
- static class TypeIdentifiers
- {
- internal static TypeIdentifier FromDisplay (string displayName)
- {
- return new Display (displayName);
- }
-
- internal static TypeIdentifier FromInternal (string internalName)
- {
- return new Internal (internalName);
- }
-
- internal static TypeIdentifier FromInternal (string internalNameSpace, TypeIdentifier typeName)
- {
- return new Internal (internalNameSpace, typeName);
- }
-
- // Only use if simpleName is certain not to contain
- // unexpected characters that ordinarily require
- // escaping: ,+*&[]\
- internal static TypeIdentifier WithoutEscape (string simpleName)
- {
- return new NoEscape (simpleName);
- }
-
- private class Display : TypeNames.ATypeName, TypeIdentifier
- {
- string displayName;
- string internal_name; //cached
-
- internal Display (string displayName)
- {
- this.displayName = displayName;
- }
-
- public override string DisplayName {
- get { return displayName; }
- }
-
- public string InternalName {
- get {
- if (internal_name == null)
- internal_name = GetInternalName ();
- return internal_name;
- }
- }
-
- private string GetInternalName ()
- {
- return TypeSpec.UnescapeInternalName (displayName);
- }
-
- public override TypeName NestedName (TypeIdentifier innerName)
- {
- return TypeNames.FromDisplay (DisplayName + "+" + innerName.DisplayName);
- }
- }
-
-
- private class Internal : TypeNames.ATypeName, TypeIdentifier
- {
- string internalName;
- string display_name; //cached
-
- internal Internal (string internalName)
- {
- this.internalName = internalName;
- }
-
- internal Internal (string nameSpaceInternal, TypeIdentifier typeName)
- {
- this.internalName = nameSpaceInternal + "." + typeName.InternalName;
- }
-
- public override string DisplayName {
- get {
- if (display_name == null)
- display_name = GetDisplayName ();
- return display_name;
- }
- }
-
- public string InternalName {
- get { return internalName; }
- }
-
- private string GetDisplayName ()
- {
- return TypeSpec.EscapeDisplayName (internalName);
- }
-
- public override TypeName NestedName (TypeIdentifier innerName)
- {
- return TypeNames.FromDisplay (DisplayName + "+" + innerName.DisplayName);
- }
-
- }
-
- private class NoEscape : TypeNames.ATypeName, TypeIdentifier
- {
- string simpleName;
- internal NoEscape (string simpleName)
- {
- this.simpleName = simpleName;
- }
-
- public override string DisplayName { get { return simpleName; } }
- public string InternalName { get { return simpleName; } }
-
- public override TypeName NestedName (TypeIdentifier innerName)
- {
- return TypeNames.FromDisplay (DisplayName + "+" + innerName.DisplayName);
- }
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs b/netcore/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs
deleted file mode 100644
index e8f8f13c729..00000000000
--- a/netcore/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs
+++ /dev/null
@@ -1,30 +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.
-
-namespace System
-{
- partial class TypeLoadException
- {
- // Called by runtime
- internal TypeLoadException (string className, string assemblyName)
- : this (null)
- {
- _className = className;
- _assemblyName = assemblyName;
- }
-
- void SetMessageField ()
- {
- if (_message != null)
- return;
-
- if (_className == null) {
- _message = SR.Arg_TypeLoadException;
- return;
- }
-
- _message = SR.Format ("Could not load type '{0}' from assembly '{1}'.", _className, _assemblyName ?? SR.IO_UnknownFileName);
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/TypeNameParser.cs b/netcore/System.Private.CoreLib/src/System/TypeNameParser.cs
deleted file mode 100644
index a4f01a7624d..00000000000
--- a/netcore/System.Private.CoreLib/src/System/TypeNameParser.cs
+++ /dev/null
@@ -1,409 +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 System.Text;
-using System.IO;
-using System.Reflection;
-using System.Collections.Generic;
-using System.Threading;
-
-namespace System
-{
- internal static class TypeNameParser
- {
- static readonly char[] SPECIAL_CHARS = {',', '[', ']', '&', '*', '+', '\\'};
-
- internal static Type GetType (
- string typeName,
- Func<AssemblyName, Assembly> assemblyResolver,
- Func<Assembly, string, bool, Type> typeResolver,
- bool throwOnError,
- bool ignoreCase,
- ref StackCrawlMark stackMark)
- {
- if (typeName == null)
- throw new ArgumentNullException (nameof (typeName));
-
- ParsedName pname = ParseName (typeName, false, 0, out int end_pos);
- if (pname == null) {
- if (throwOnError)
- throw new ArgumentException ();
- return null;
- }
-
- return ConstructType (pname, assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
- }
-
- static Type ConstructType (
- ParsedName pname,
- Func<AssemblyName, Assembly> assemblyResolver,
- Func<Assembly, string, bool, Type> typeResolver,
- bool throwOnError,
- bool ignoreCase,
- ref StackCrawlMark stackMark)
- {
- // Resolve assembly
- Assembly assembly = null;
- if (pname.AssemblyName != null) {
- assembly = ResolveAssembly (pname.AssemblyName, assemblyResolver, throwOnError, ref stackMark);
- if (assembly == null)
- // If throwOnError is true, an exception was already thrown
- return null;
- }
-
- // Resolve base type
- var type = ResolveType (assembly, pname.Names, typeResolver, throwOnError, ignoreCase, ref stackMark);
- if (type == null)
- return null;
-
- // Resolve type arguments
- if (pname.TypeArguments != null) {
- var args = new Type [pname.TypeArguments.Count];
- for (int i = 0; i < pname.TypeArguments.Count; ++i) {
- args [i] = ConstructType (pname.TypeArguments [i], assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
- if (args [i] == null)
- return null;
- }
- type = type.MakeGenericType (args);
- }
-
- // Resolve modifiers
- if (pname.Modifiers != null) {
- bool bounded = false;
- foreach (var mod in pname.Modifiers) {
- switch (mod) {
- case 0:
- type = type.MakeByRefType ();
- break;
- case -1:
- type = type.MakePointerType ();
- break;
- case -2:
- bounded = true;
- break;
- case 1:
- if (bounded)
- type = type.MakeArrayType (1);
- else
- type = type.MakeArrayType ();
- break;
- default:
- type = type.MakeArrayType (mod);
- break;
- }
- }
- }
-
- return type;
- }
-
- static Assembly ResolveAssembly (string name, Func<AssemblyName, Assembly> assemblyResolver, bool throwOnError,
- ref StackCrawlMark stackMark)
- {
- var aname = new AssemblyName (name);
-
- if (assemblyResolver == null) {
- if (throwOnError) {
- return Assembly.Load (aname, ref stackMark, null);
- } else {
- try {
- return Assembly.Load (aname, ref stackMark, null);
- } catch (FileNotFoundException) {
- return null;
- }
- }
- } else {
- var assembly = assemblyResolver (aname);
- if (assembly == null && throwOnError)
- throw new FileNotFoundException (SR.FileNotFound_ResolveAssembly, name);
- return assembly;
- }
- }
-
- static Type ResolveType (Assembly assembly, List<string> names, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark)
- {
- Type type = null;
-
- string name = EscapeTypeName (names [0]);
- // Resolve the top level type.
- if (typeResolver != null) {
- type = typeResolver (assembly, name, ignoreCase);
- if (type == null && throwOnError) {
- if (assembly == null)
- throw new TypeLoadException (SR.Format (SR.TypeLoad_ResolveType, name));
- else
- throw new TypeLoadException (SR.Format (SR.TypeLoad_ResolveTypeFromAssembly, name, assembly.FullName));
- }
- } else {
- if (assembly == null)
- type = RuntimeType.GetType (name, throwOnError, ignoreCase, false, ref stackMark);
- else
- type = assembly.GetType (name, throwOnError, ignoreCase);
- }
-
- if (type == null)
- return null;
-
- // Resolve nested types.
- BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public;
- if (ignoreCase)
- bindingFlags |= BindingFlags.IgnoreCase;
-
- for (int i = 1; i < names.Count; ++i) {
- type = type.GetNestedType (names[i], bindingFlags);
- if (type == null) {
- if (throwOnError)
- throw new TypeLoadException (SR.Format (SR.TypeLoad_ResolveNestedType, names[i], names[i-1]));
- else
- break;
- }
- }
- return type;
- }
-
- static string EscapeTypeName (string name)
- {
- if (name.IndexOfAny (SPECIAL_CHARS) < 0)
- return name;
-
- var sb = new StringBuilder (name.Length);
- foreach (char c in name) {
- if (Array.IndexOf<char> (SPECIAL_CHARS, c) >= 0)
- sb.Append ('\\');
- sb.Append (c);
- }
-
- return sb.ToString ();
- }
-
- static string UnescapeTypeName (string name)
- {
- if (name.IndexOfAny (SPECIAL_CHARS) < 0)
- return name;
-
- var sb = new StringBuilder (name.Length - 1);
- for (int i = 0; i < name.Length; ++i) {
- if (name [i] == '\\' && i + 1 < name.Length)
- i++;
- sb.Append (name [i]);
- }
-
- return sb.ToString ();
- }
-
- class ParsedName {
- public List<string> Names;
- public List<ParsedName> TypeArguments;
- public List<int> Modifiers;
- public string AssemblyName;
-
- /* For debugging
- public override string ToString () {
- var sb = new StringBuilder ();
- sb.Append (Names [0]);
- if (TypeArguments != null) {
- sb.Append ("[");
- for (int i = 0; i < TypeArguments.Count; ++i) {
- if (TypeArguments [i].AssemblyName != null)
- sb.Append ('[');
- sb.Append (TypeArguments [i].ToString ());
- if (TypeArguments [i].AssemblyName != null)
- sb.Append (']');
- if (i < TypeArguments.Count - 1)
- sb.Append (", ");
- }
- sb.Append ("]");
- }
- if (AssemblyName != null)
- sb.Append ($", {AssemblyName}");
- return sb.ToString ();
- }
- */
- }
-
- // Ported from the C version in mono_reflection_parse_type_checked ()
- // Entries to the Names list are unescaped to internal form while AssemblyName is not, in an effort to maintain
- // consistency with our native parser. Since this function is just called recursively, that should also be true
- // for ParsedNames in TypeArguments.
- static ParsedName ParseName (string name, bool recursed, int pos, out int end_pos)
- {
- end_pos = 0;
-
- while (pos < name.Length && name [pos] == ' ')
- pos ++;
-
- var res = new ParsedName () { Names = new List<string> () };
-
- int start = pos;
- int name_start = pos;
- bool in_modifiers = false;
- while (pos < name.Length) {
- switch (name [pos]) {
- case '+':
- res.Names.Add (UnescapeTypeName (name.Substring (name_start, pos - name_start)));
- name_start = pos + 1;
- break;
- case '\\':
- pos ++;
- break;
- case '&':
- case '*':
- case '[':
- case ',':
- case ']':
- in_modifiers = true;
- break;
- default:
- break;
- }
- if (in_modifiers)
- break;
- pos ++;
- }
-
- res.Names.Add (UnescapeTypeName (name.Substring (name_start, pos - name_start)));
-
- bool isbyref = false;
- bool isptr = false;
- int rank = -1;
-
- bool end = false;
- while (pos < name.Length && !end) {
- switch (name [pos]) {
- case '&':
- if (isbyref)
- return null;
- pos ++;
- isbyref = true;
- isptr = false;
- if (res.Modifiers == null)
- res.Modifiers = new List<int> ();
- res.Modifiers.Add (0);
- break;
- case '*':
- if (isbyref)
- return null;
- pos ++;
- if (res.Modifiers == null)
- res.Modifiers = new List<int> ();
- res.Modifiers.Add (-1);
- isptr = true;
- break;
- case '[':
- // An array or generic arguments
- if (isbyref)
- return null;
- pos ++;
- if (pos == name.Length)
- return null;
-
- if (name [pos] == ',' || name [pos] == '*' || name [pos] == ']') {
- // Array
- bool bounded = false;
- isptr = false;
- rank = 1;
- while (pos < name.Length) {
- if (name [pos] == ']')
- break;
- if (name [pos] == ',')
- rank ++;
- else if (name [pos] == '*') /* '*' means unknown lower bound */
- bounded = true;
- else
- return null;
- pos ++;
- }
- if (pos == name.Length)
- return null;
- if (name [pos] != ']')
- return null;
- pos ++;
- /* bounded only allowed when rank == 1 */
- if (bounded && rank > 1)
- return null;
- /* n.b. bounded needs both modifiers: -2 == bounded, 1 == rank 1 array */
- if (res.Modifiers == null)
- res.Modifiers = new List<int> ();
- if (bounded)
- res.Modifiers.Add (-2);
- res.Modifiers.Add (rank);
- } else {
- // Generic args
- if (rank > 0 || isptr)
- return null;
- isptr = false;
- res.TypeArguments = new List<ParsedName> ();
- while (pos < name.Length) {
- while (pos < name.Length && name [pos] == ' ')
- pos ++;
- bool fqname = false;
- if (pos < name.Length && name [pos] == '[') {
- pos ++;
- fqname = true;
- }
-
- var arg = ParseName (name, true, pos, out pos);
- if (arg == null)
- return null;
- res.TypeArguments.Add (arg);
-
- /*MS is lenient on [] delimited parameters that aren't fqn - and F# uses them.*/
- if (fqname && pos < name.Length && name [pos] != ']') {
- if (name [pos] != ',')
- return null;
- pos ++;
- int aname_start = pos;
- while (pos < name.Length && name [pos] != ']')
- pos ++;
- if (pos == name.Length)
- return null;
- while (Char.IsWhiteSpace (name [aname_start]))
- aname_start ++;
- if (aname_start == pos)
- return null;
- arg.AssemblyName = name.Substring (aname_start, pos - aname_start);
- pos ++;
- } else if (fqname && pos < name.Length && name [pos] == ']') {
- pos ++;
- }
- if (pos < name.Length && name [pos] == ']') {
- pos ++;
- break;
- } else if (pos == name.Length)
- return null;
- pos ++;
- }
- }
- break;
- case ']':
- if (recursed) {
- end = true;
- break;
- }
- return null;
- case ',':
- if (recursed) {
- end = true;
- break;
- }
- pos ++;
- while (pos < name.Length && Char.IsWhiteSpace (name [pos]))
- pos ++;
- if (pos == name.Length)
- return null;
- res.AssemblyName = name.Substring (pos);
- end = true;
- break;
- default:
- return null;
- }
- if (end)
- break;
- }
-
- end_pos = pos;
- return res;
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/TypeSpec.cs b/netcore/System.Private.CoreLib/src/System/TypeSpec.cs
deleted file mode 100644
index 3391c1fd343..00000000000
--- a/netcore/System.Private.CoreLib/src/System/TypeSpec.cs
+++ /dev/null
@@ -1,620 +0,0 @@
-//
-// System.Type.cs
-//
-// Author:
-// Rodrigo Kumpera <kumpera@gmail.com>
-//
-//
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.Collections.Generic;
-using System.IO;
-using System.Reflection;
-using System.Threading;
-
-namespace System {
- internal interface ModifierSpec {
- Type Resolve (Type type);
- Text.StringBuilder Append (Text.StringBuilder sb);
- }
- internal class ArraySpec : ModifierSpec
- {
- // dimensions == 1 and bound, or dimensions > 1 and !bound
- int dimensions;
- bool bound;
-
- internal ArraySpec (int dimensions, bool bound)
- {
- this.dimensions = dimensions;
- this.bound = bound;
- }
-
- public Type Resolve (Type type)
- {
- if (bound)
- return type.MakeArrayType (1);
- else if (dimensions == 1)
- return type.MakeArrayType ();
- return type.MakeArrayType (dimensions);
- }
-
- public Text.StringBuilder Append (Text.StringBuilder sb)
- {
- if (bound)
- return sb.Append ("[*]");
- return sb.Append ('[')
- .Append (',', dimensions - 1)
- .Append (']');
-
- }
- public override string ToString ()
- {
- return Append (new Text.StringBuilder ()).ToString ();
- }
-
- public int Rank {
- get {
- return dimensions;
- }
- }
-
- public bool IsBound {
- get {
- return bound;
- }
- }
- }
-
- internal class PointerSpec : ModifierSpec
- {
- int pointer_level;
-
- internal PointerSpec (int pointer_level) {
- this.pointer_level = pointer_level;
- }
-
- public Type Resolve (Type type) {
- for (int i = 0; i < pointer_level; ++i)
- type = type.MakePointerType ();
- return type;
- }
-
- public Text.StringBuilder Append (Text.StringBuilder sb)
- {
- return sb.Append ('*', pointer_level);
- }
-
- public override string ToString () {
- return Append (new Text.StringBuilder ()).ToString ();
- }
-
- }
-
- internal class TypeSpec
- {
- TypeIdentifier name;
- string assembly_name;
- List<TypeIdentifier> nested;
- List<TypeSpec> generic_params;
- List<ModifierSpec> modifier_spec;
- bool is_byref;
-
- string display_fullname; // cache
-
- internal bool HasModifiers {
- get { return modifier_spec != null; }
- }
-
- internal bool IsNested {
- get { return nested != null && nested.Count > 0; }
- }
-
- internal bool IsByRef {
- get { return is_byref; }
- }
-
- internal TypeName Name {
- get { return name; }
- }
-
- internal IEnumerable<TypeName> Nested {
- get {
- if (nested != null)
- return nested;
- else
- return Array.Empty<TypeName> ();
- }
- }
-
- internal IEnumerable<ModifierSpec> Modifiers {
- get {
- if (modifier_spec != null)
- return modifier_spec;
- else
- return Array.Empty<ModifierSpec> ();
- }
- }
-
- [Flags]
- internal enum DisplayNameFormat {
- Default = 0x0,
- WANT_ASSEMBLY = 0x1,
- NO_MODIFIERS = 0x2,
- }
-#if DEBUG
- public override string ToString () {
- return GetDisplayFullName (DisplayNameFormat.WANT_ASSEMBLY);
- }
-#endif
-
- string GetDisplayFullName (DisplayNameFormat flags)
- {
- bool wantAssembly = (flags & DisplayNameFormat.WANT_ASSEMBLY) != 0;
- bool wantModifiers = (flags & DisplayNameFormat.NO_MODIFIERS) == 0;
- var sb = new Text.StringBuilder(name.DisplayName);
- if (nested != null) {
- foreach (var n in nested)
- sb.Append ('+').Append (n.DisplayName);
- }
-
- if (generic_params != null) {
- sb.Append ('[');
- for (int i = 0; i < generic_params.Count; ++i) {
- if (i > 0)
- sb.Append (", ");
- if (generic_params [i].assembly_name != null)
- sb.Append ('[').Append (generic_params [i].DisplayFullName).Append (']');
- else
- sb.Append (generic_params [i].DisplayFullName);
- }
- sb.Append (']');
- }
-
- if (wantModifiers)
- GetModifierString (sb);
-
- if (assembly_name != null && wantAssembly)
- sb.Append (", ").Append (assembly_name);
-
- return sb.ToString();
- }
-
- internal string ModifierString ()
- {
- return GetModifierString (new Text.StringBuilder ()).ToString ();
- }
-
- private Text.StringBuilder GetModifierString (Text.StringBuilder sb)
- {
- if (modifier_spec != null) {
- foreach (var md in modifier_spec)
- md.Append (sb);
- }
-
- if (is_byref)
- sb.Append ('&');
-
- return sb;
- }
-
- internal string DisplayFullName {
- get {
- if (display_fullname == null)
- display_fullname = GetDisplayFullName (DisplayNameFormat.Default);
- return display_fullname;
- }
- }
-
- internal static TypeSpec Parse (string typeName)
- {
- int pos = 0;
- if (typeName == null)
- throw new ArgumentNullException ("typeName");
-
- TypeSpec res = Parse (typeName, ref pos, false, true);
- if (pos < typeName.Length)
- throw new ArgumentException ("Count not parse the whole type name", "typeName");
- return res;
- }
-
- internal static string EscapeDisplayName(string internalName)
- {
- // initial capacity = length of internalName.
- // Maybe we won't have to escape anything.
- var res = new Text.StringBuilder (internalName.Length);
- foreach (char c in internalName)
- {
- switch (c) {
- case '+':
- case ',':
- case '[':
- case ']':
- case '*':
- case '&':
- case '\\':
- res.Append ('\\').Append (c);
- break;
- default:
- res.Append (c);
- break;
- }
- }
- return res.ToString ();
- }
-
- internal static string UnescapeInternalName(string displayName)
- {
- var res = new Text.StringBuilder (displayName.Length);
- for (int i = 0; i < displayName.Length; ++i)
- {
- char c = displayName[i];
- if (c == '\\')
- if (++i < displayName.Length)
- c = displayName[i];
- res.Append (c);
- }
- return res.ToString ();
- }
-
- internal static bool NeedsEscaping (string internalName)
- {
- foreach (char c in internalName)
- {
- switch (c) {
- case ',':
- case '+':
- case '*':
- case '&':
- case '[':
- case ']':
- case '\\':
- return true;
- default:
- break;
- }
- }
- return false;
- }
-
- internal Type Resolve (Func<AssemblyName,Assembly> assemblyResolver, Func<Assembly,string,bool,Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark)
- {
- Assembly asm = null;
- if (assemblyResolver == null && typeResolver == null)
- return RuntimeType.GetType (DisplayFullName, throwOnError, ignoreCase, false, ref stackMark);
-
- if (assembly_name != null) {
- if (assemblyResolver != null)
- asm = assemblyResolver (new AssemblyName (assembly_name));
- else
- asm = Assembly.Load (assembly_name);
-
- if (asm == null) {
- if (throwOnError)
- throw new FileNotFoundException ("Could not resolve assembly '" + assembly_name + "'");
- return null;
- }
- }
-
- Type type = null;
- if (typeResolver != null)
- type = typeResolver (asm, name.DisplayName, ignoreCase);
- else
- type = asm.GetType (name.DisplayName, false, ignoreCase);
- if (type == null) {
- if (throwOnError)
- throw new TypeLoadException ("Could not resolve type '" + name + "'");
- return null;
- }
-
- if (nested != null) {
- foreach (var n in nested) {
- var tmp = type.GetNestedType (n.DisplayName, BindingFlags.Public | BindingFlags.NonPublic);
- if (tmp == null) {
- if (throwOnError)
- throw new TypeLoadException ("Could not resolve type '" + n + "'");
- return null;
- }
- type = tmp;
- }
- }
-
- if (generic_params != null) {
- Type[] args = new Type [generic_params.Count];
- for (int i = 0; i < args.Length; ++i) {
- var tmp = generic_params [i].Resolve (assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
- if (tmp == null) {
- if (throwOnError)
- throw new TypeLoadException ("Could not resolve type '" + generic_params [i].name + "'");
- return null;
- }
- args [i] = tmp;
- }
- type = type.MakeGenericType (args);
- }
-
- if (modifier_spec != null) {
- foreach (var md in modifier_spec)
- type = md.Resolve (type);
- }
-
- if (is_byref)
- type = type.MakeByRefType ();
-
- return type;
- }
-
- void AddName (string type_name)
- {
- if (name == null) {
- name = ParsedTypeIdentifier(type_name);
- } else {
- if (nested == null)
- nested = new List <TypeIdentifier> ();
- nested.Add (ParsedTypeIdentifier(type_name));
- }
- }
-
- void AddModifier (ModifierSpec md)
- {
- if (modifier_spec == null)
- modifier_spec = new List<ModifierSpec> ();
- modifier_spec.Add (md);
- }
-
- static void SkipSpace (string name, ref int pos)
- {
- int p = pos;
- while (p < name.Length && Char.IsWhiteSpace (name [p]))
- ++p;
- pos = p;
- }
-
- static void BoundCheck (int idx, string s)
- {
- if (idx >= s.Length)
- throw new ArgumentException ("Invalid generic arguments spec", "typeName");
- }
-
- static TypeIdentifier ParsedTypeIdentifier (string displayName)
- {
- return TypeIdentifiers.FromDisplay(displayName);
- }
-
- static TypeSpec Parse (string name, ref int p, bool is_recurse, bool allow_aqn)
- {
- // Invariants:
- // - On exit p, is updated to pos the current unconsumed character.
- //
- // - The callee peeks at but does not consume delimiters following
- // recurisve parse (so for a recursive call like the args of "Foo[P,Q]"
- // we'll return with p either on ',' or on ']'. If the name was aqn'd
- // "Foo[[P,assmblystuff],Q]" on return p with be on the ']' just
- // after the "assmblystuff")
- //
- // - If allow_aqn is True, assembly qualification is optional.
- // If allow_aqn is False, assembly qualification is prohibited.
- int pos = p;
- int name_start;
- bool in_modifiers = false;
- TypeSpec data = new TypeSpec ();
-
- SkipSpace (name, ref pos);
-
- name_start = pos;
-
- for (; pos < name.Length; ++pos) {
- switch (name [pos]) {
- case '+':
- data.AddName (name.Substring (name_start, pos - name_start));
- name_start = pos + 1;
- break;
- case ',':
- case ']':
- data.AddName (name.Substring (name_start, pos - name_start));
- name_start = pos + 1;
- in_modifiers = true;
- if (is_recurse && !allow_aqn) {
- p = pos;
- return data;
- }
- break;
- case '&':
- case '*':
- case '[':
- if (name [pos] != '[' && is_recurse)
- throw new ArgumentException ("Generic argument can't be byref or pointer type", "typeName");
- data.AddName (name.Substring (name_start, pos - name_start));
- name_start = pos + 1;
- in_modifiers = true;
- break;
- case '\\':
- pos++;
- break;
- }
- if (in_modifiers)
- break;
- }
-
- if (name_start < pos)
- data.AddName (name.Substring (name_start, pos - name_start));
- else if (name_start == pos)
- data.AddName (String.Empty);
-
- if (in_modifiers) {
- for (; pos < name.Length; ++pos) {
-
- switch (name [pos]) {
- case '&':
- if (data.is_byref)
- throw new ArgumentException ("Can't have a byref of a byref", "typeName");
-
- data.is_byref = true;
- break;
- case '*':
- if (data.is_byref)
- throw new ArgumentException ("Can't have a pointer to a byref type", "typeName");
- // take subsequent '*'s too
- int pointer_level = 1;
- while (pos+1 < name.Length && name[pos+1] == '*') {
- ++pos;
- ++pointer_level;
- }
- data.AddModifier (new PointerSpec(pointer_level));
- break;
- case ',':
- if (is_recurse && allow_aqn) {
- int end = pos;
- while (end < name.Length && name [end] != ']')
- ++end;
- if (end >= name.Length)
- throw new ArgumentException ("Unmatched ']' while parsing generic argument assembly name");
- data.assembly_name = name.Substring (pos + 1, end - pos - 1).Trim ();
- p = end;
- return data;
- }
- if (is_recurse) {
- p = pos;
- return data;
- }
- if (allow_aqn) {
- data.assembly_name = name.Substring (pos + 1).Trim ();
- pos = name.Length;
- }
- break;
- case '[':
- if (data.is_byref)
- throw new ArgumentException ("Byref qualifier must be the last one of a type", "typeName");
- ++pos;
- if (pos >= name.Length)
- throw new ArgumentException ("Invalid array/generic spec", "typeName");
- SkipSpace (name, ref pos);
-
- if (name [pos] != ',' && name [pos] != '*' && name [pos] != ']') {//generic args
- List<TypeSpec> args = new List <TypeSpec> ();
- if (data.HasModifiers)
- throw new ArgumentException ("generic args after array spec or pointer type", "typeName");
-
- while (pos < name.Length) {
- SkipSpace (name, ref pos);
- bool aqn = name [pos] == '[';
- if (aqn)
- ++pos; //skip '[' to the start of the type
- args.Add (Parse (name, ref pos, true, aqn));
- BoundCheck (pos, name);
- if (aqn) {
- if (name [pos] == ']')
- ++pos;
- else
- throw new ArgumentException ("Unclosed assembly-qualified type name at " + name[pos], "typeName");
- BoundCheck (pos, name);
-}
-
- if (name [pos] == ']')
- break;
- if (name [pos] == ',')
- ++pos; // skip ',' to the start of the next arg
- else
- throw new ArgumentException ("Invalid generic arguments separator " + name [pos], "typeName");
-
- }
- if (pos >= name.Length || name [pos] != ']')
- throw new ArgumentException ("Error parsing generic params spec", "typeName");
- data.generic_params = args;
- } else { //array spec
- int dimensions = 1;
- bool bound = false;
- while (pos < name.Length && name [pos] != ']') {
- if (name [pos] == '*') {
- if (bound)
- throw new ArgumentException ("Array spec cannot have 2 bound dimensions", "typeName");
- bound = true;
- }
- else if (name [pos] != ',')
- throw new ArgumentException ("Invalid character in array spec " + name [pos], "typeName");
- else
- ++dimensions;
-
- ++pos;
- SkipSpace (name, ref pos);
- }
- if (pos >= name.Length || name [pos] != ']')
- throw new ArgumentException ("Error parsing array spec", "typeName");
- if (dimensions > 1 && bound)
- throw new ArgumentException ("Invalid array spec, multi-dimensional array cannot be bound", "typeName");
- data.AddModifier (new ArraySpec (dimensions, bound));
- }
-
- break;
- case ']':
- if (is_recurse) {
- p = pos;
- return data;
- }
- throw new ArgumentException ("Unmatched ']'", "typeName");
- default:
- throw new ArgumentException ("Bad type def, can't handle '" + name [pos]+"'" + " at " + pos, "typeName");
- }
- }
- }
-
- p = pos;
- return data;
- }
-
- internal TypeName TypeNameWithoutModifiers ()
- {
- return new TypeSpecTypeName (this, false);
- }
-
- internal TypeName TypeName {
- get { return new TypeSpecTypeName (this, true); }
- }
-
- private class TypeSpecTypeName : TypeNames.ATypeName, TypeName {
- TypeSpec ts;
- bool want_modifiers;
-
- internal TypeSpecTypeName (TypeSpec ts, bool wantModifiers)
- {
- this.ts = ts;
- this.want_modifiers = wantModifiers;
- }
-
- public override string DisplayName {
- get {
- if (want_modifiers)
- return ts.DisplayFullName;
- else
- return ts.GetDisplayFullName (DisplayNameFormat.NO_MODIFIERS);
- }
- }
-
- public override TypeName NestedName (TypeIdentifier innerName)
- {
- return TypeNames.FromDisplay(DisplayName + "+" + innerName.DisplayName);
- }
- }
-
- }
-}
-
diff --git a/netcore/System.Private.CoreLib/src/System/TypedReference.cs b/netcore/System.Private.CoreLib/src/System/TypedReference.cs
deleted file mode 100644
index 74a92a54997..00000000000
--- a/netcore/System.Private.CoreLib/src/System/TypedReference.cs
+++ /dev/null
@@ -1,108 +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 System.Reflection;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- [CLSCompliantAttribute (false)]
- public ref struct TypedReference
- {
- #region sync with object-internals.h
- RuntimeTypeHandle type;
- IntPtr Value;
- IntPtr Type;
- #endregion
-
- [CLSCompliant (false)]
- public static TypedReference MakeTypedReference (object target, FieldInfo[] flds)
- {
- if (target == null)
- throw new ArgumentNullException (nameof (target));
- if (flds == null)
- throw new ArgumentNullException (nameof (flds));
- if (flds.Length == 0)
- throw new ArgumentException (SR.Arg_ArrayZeroError, nameof (flds));
-
- var fields = new IntPtr [flds.Length];
- var targetType = (RuntimeType)target.GetType ();
- for (int i = 0; i < flds.Length; i++) {
- var field = flds [i] as RuntimeFieldInfo;
- if (field == null)
- throw new ArgumentException (SR.Argument_MustBeRuntimeFieldInfo);
- if (field.IsStatic)
- throw new ArgumentException (SR.Argument_TypedReferenceInvalidField);
-
- if (targetType != field.GetDeclaringTypeInternal () && !targetType.IsSubclassOf (field.GetDeclaringTypeInternal ()))
- throw new MissingMemberException (SR.MissingMemberTypeRef);
-
- var fieldType = (RuntimeType)field.FieldType;
- if (fieldType.IsPrimitive)
- throw new ArgumentException (SR.Arg_TypeRefPrimitve);
- if (i < (flds.Length - 1) && !fieldType.IsValueType)
- throw new MissingMemberException (SR.MissingMemberNestErr);
-
- fields[i] = field.FieldHandle.Value;
- targetType = fieldType;
- }
-
- var result = new TypedReference ();
-
- unsafe {
- InternalMakeTypedReference (&result, target, fields, targetType);
- }
- return result;
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- unsafe static extern void InternalMakeTypedReference (void* result, Object target, IntPtr[] flds, RuntimeType lastFieldType);
-
- public override int GetHashCode ()
- {
- if (Type == IntPtr.Zero)
- return 0;
- else
- return __reftype (this).GetHashCode ();
- }
-
- public override bool Equals (object? o)
- {
- throw new NotSupportedException (SR.NotSupported_NYI);
- }
-
- [CLSCompliant (false)]
- public unsafe static object ToObject (TypedReference value)
- {
- return InternalToObject (&value);
- }
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- unsafe extern static object InternalToObject (void * value);
-
- internal bool IsNull {
- get {
- return Value == IntPtr.Zero && Type == IntPtr.Zero;
- }
- }
-
- [CLSCompliant (false)]
- public static Type GetTargetType (TypedReference value)
- {
- return __reftype (value);
- }
-
- [CLSCompliant (false)]
- public static RuntimeTypeHandle TargetTypeToken (TypedReference value)
- {
- return __reftype (value).TypeHandle;
- }
-
- [CLSCompliant (false)]
- public unsafe static void SetTypedReference (TypedReference target, Object value)
- {
- throw new NotSupportedException ();
- }
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/ValueType.cs b/netcore/System.Private.CoreLib/src/System/ValueType.cs
deleted file mode 100644
index 86c86625a6e..00000000000
--- a/netcore/System.Private.CoreLib/src/System/ValueType.cs
+++ /dev/null
@@ -1,77 +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 System.Reflection;
-using System.Runtime.CompilerServices;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom ("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public abstract class ValueType
- {
- // This is also used by RuntimeHelpers
- internal static bool DefaultEquals (object o1, object o2)
- {
- RuntimeType o1_type = (RuntimeType) o1.GetType ();
- RuntimeType o2_type = (RuntimeType) o2.GetType ();
-
- if (o1_type != o2_type)
- return false;
-
- object[] fields;
- bool res = InternalEquals (o1, o2, out fields);
- if (fields == null)
- return res;
-
- for (int i = 0; i < fields.Length; i += 2) {
- object meVal = fields [i];
- object youVal = fields [i + 1];
- if (meVal == null) {
- if (youVal == null)
- continue;
-
- return false;
- }
-
- if (!meVal.Equals (youVal))
- return false;
- }
-
- return true;
- }
-
- public override bool Equals (object? obj)
- {
- if (obj == null)
- return false;
-
- return DefaultEquals (this, obj);
- }
-
- public override int GetHashCode ()
- {
- int result = InternalGetHashCode (this, out var fields);
-
- if (fields != null)
- for (int i = 0; i < fields.Length; ++i)
- if (fields [i] != null)
- result ^= fields [i].GetHashCode ();
-
- return result;
- }
-
- public override string ToString ()
- {
- return GetType ().ToString ();
- }
-
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static int InternalGetHashCode (object o, out object[]? fields);
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static bool InternalEquals (object o1, object o2, out object[] fields);
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/WeakReference.Mono.cs b/netcore/System.Private.CoreLib/src/System/WeakReference.Mono.cs
deleted file mode 100644
index 8f25c35596c..00000000000
--- a/netcore/System.Private.CoreLib/src/System/WeakReference.Mono.cs
+++ /dev/null
@@ -1,46 +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 System.Runtime.InteropServices;
-
-namespace System
-{
- partial class WeakReference
- {
- bool trackResurrection;
- GCHandle handle;
-
- public virtual bool IsAlive => Target != null;
-
- public virtual object Target {
- get {
- if (!handle.IsAllocated)
- return null;
- return handle.Target;
- }
- set {
- handle.Target = value;
- }
- }
-
- public virtual bool TrackResurrection => IsTrackResurrection ();
-
- ~WeakReference ()
- {
- handle.Free ();
- }
-
- void Create (object target, bool trackResurrection)
- {
- if (trackResurrection) {
- this.trackResurrection = true;
- handle = GCHandle.Alloc (target, GCHandleType.WeakTrackResurrection);
- } else {
- handle = GCHandle.Alloc (target, GCHandleType.Weak);
- }
- }
-
- bool IsTrackResurrection () => trackResurrection;
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/WeakReference.T.Mono.cs b/netcore/System.Private.CoreLib/src/System/WeakReference.T.Mono.cs
deleted file mode 100644
index a108f52769a..00000000000
--- a/netcore/System.Private.CoreLib/src/System/WeakReference.T.Mono.cs
+++ /dev/null
@@ -1,43 +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 System.Runtime.InteropServices;
-
-namespace System
-{
- partial class WeakReference<T>
- {
- GCHandle handle;
- bool trackResurrection;
-
- T Target {
- get {
- GCHandle h = handle;
- return h.IsAllocated ? (T) h.Target : null;
- }
- }
-
- ~WeakReference ()
- {
- handle.Free ();
- }
-
- void Create (T target, bool trackResurrection)
- {
- if (trackResurrection) {
- trackResurrection = true;
- handle = GCHandle.Alloc (target, GCHandleType.WeakTrackResurrection);
- } else {
- handle = GCHandle.Alloc (target, GCHandleType.Weak);
- }
- }
-
- public void SetTarget (T target)
- {
- handle.Target = target;
- }
-
- bool IsTrackResurrection () => trackResurrection;
- }
-}
diff --git a/netcore/System.Private.CoreLib/src/System/__ComObject.cs b/netcore/System.Private.CoreLib/src/System/__ComObject.cs
deleted file mode 100644
index 3676d0905ef..00000000000
--- a/netcore/System.Private.CoreLib/src/System/__ComObject.cs
+++ /dev/null
@@ -1,14 +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.
-
-namespace System
-{
- internal class __ComObject
- {
- __ComObject ()
- {
- throw new NotSupportedException ();
- }
- }
-}
diff --git a/netcore/build.cmd b/netcore/build.cmd
deleted file mode 100644
index e48800de024..00000000000
--- a/netcore/build.cmd
+++ /dev/null
@@ -1,2 +0,0 @@
-@echo off
-powershell -NoProfile -NoLogo -ExecutionPolicy ByPass -command "& """%~dp0build.ps1""" %*" \ No newline at end of file
diff --git a/netcore/build.ps1 b/netcore/build.ps1
deleted file mode 100644
index 27a096852e9..00000000000
--- a/netcore/build.ps1
+++ /dev/null
@@ -1,148 +0,0 @@
-[CmdletBinding(PositionalBinding=$false)]
-Param(
- [string][Alias('c')]$configuration = "Debug",
- [switch] $pack,
- [switch][Alias('t')]$test,
- [switch] $rebuild,
- [switch] $clean,
- [switch] $llvm,
- [switch] $skipnative,
- [switch] $skipmscorlib,
- [switch] $ci,
- [switch][Alias('h')]$help,
- [Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
-)
-
-. ../eng/common/pipeline-logging-functions.ps1
-
-function Print-Usage() {
- Write-Host "Common settings:"
- Write-Host " -configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)"
- Write-Host " -help Print help and exit (short: -h)"
- Write-Host ""
-
- Write-Host "Actions:"
- Write-Host " -pack Package build outputs into NuGet packages"
- Write-Host " -test Run all unit tests in the solution (short: -t)"
- Write-Host " -rebuild Clean only runtime build"
- Write-Host " -clean Clean all and exit"
- Write-Host " -llvm Enable LLVM support"
- Write-Host " -skipnative Do not build runtime"
- Write-Host " -skipmscorlib Do not build System.Private.CoreLib"
- Write-Host " -ci Enable Azure DevOps telemetry decoration"
-
- Write-Host "Command line arguments not listed above are passed thru to msbuild."
- Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)."
-}
-
-try {
- if ($help) {
- Print-Usage
- exit 0
- }
-
- $temp_file = [IO.Path]::GetTempFileName()
- cmd.exe /c " ""$PSScriptRoot\..\msvc\setup-vs-msbuild-env.bat"" && set " > $temp_file
- Get-Content $temp_file | Foreach-Object {
- if ($_ -match "^(.*?)=(.*)$") {
- Set-Content "env:\$($matches[1])" $matches[2]
- }
- }
- Remove-Item $temp_file
-
- $enable_llvm="false"
- if ($llvm) {
- $enable_llvm="true"
- }
-
- # clean all
- if ($clean) {
- MSBuild "$PSScriptRoot\build.targets" `
- "/t:Clean" `
- "/p:Configuration=$configuration"
-
- if ($LastExitCode -ne 0) {
- Write-PipelineTelemetryError -Category "runtime" -Message "Error cleaning"
- exit 1
- }
-
- exit 0
- }
-
- # rebuild mono runtime
- if ($rebuild) {
- MSBuild "$PSScriptRoot\build.targets" `
- "/t:build-runtime" `
- "/p:Configuration=$configuration" `
- "/p:RuntimeBuildTarget=clean"
-
- if ($LastExitCode -ne 0) {
- Write-PipelineTelemetryError -Category "runtime" -Message "Error cleaning unmanaged runtime"
- exit 1
- }
- }
-
- # build mono runtime
- if (!$skipnative) {
- MSBuild "$PSScriptRoot\build.targets" `
- "/t:build-runtime" `
- "/p:Configuration=$configuration" `
- "/p:MONO_ENABLE_LLVM=$enable_llvm"
-
- if ($LastExitCode -ne 0) {
- Write-PipelineTelemetryError -Category "runtime" -Message "Error building unmanaged runtime"
- exit 1
- }
- }
-
- # build System.Private.CoreLib
- if (!$skipmscorlib) {
- MSBuild "$PSScriptRoot\build.targets" `
- "/t:bcl" `
- "/p:Configuration=$configuration"
-
- if ($LastExitCode -ne 0) {
- Write-PipelineTelemetryError -Category "bcl" -Message "Error building System.Private.CoreLib"
- exit 1
- }
- }
-
- if ($pack) {
- Write-PipelineTelemetryError -Category "nupkg" -Message "Error packing NuGet package (Not Implemented)"
- exit 1
- }
-
- # run all xunit tests
- if ($test) {
- MSBuild "$PSScriptRoot\build.targets" `
- "/t:update-tests-corefx" `
- "/p:Configuration=$configuration"
-
- if ($LastExitCode -ne 0) {
- Write-PipelineTelemetryError -Category "tests-download" -Message "Error downloading tests"
- exit 1
- }
-
- $timeout=-1
- if ($ci) {
- $timeout=600
- }
-
- MSBuild "$PSScriptRoot\build.targets" `
- "/t:run-tests-corefx" `
- "/p:Configuration=$configuration" `
- "/p:CoreFxTestTimeout=$timeout"
-
- if ($LastExitCode -ne 0) {
- Write-PipelineTelemetryError -Category "tests" -Message "Error running tests"
- exit 1
- }
- }
-}
-catch {
- Write-Host $_.ScriptStackTrace
- Write-PipelineTelemetryError -Category "build" -Message $_
- exit 1
-}
-
-exit 0
diff --git a/netcore/build.sh b/netcore/build.sh
deleted file mode 100755
index a57401e8195..00000000000
--- a/netcore/build.sh
+++ /dev/null
@@ -1,163 +0,0 @@
-#!/usr/bin/env bash
-
-# Stop script if unbound variable found (use ${var:-} if intentional)
-set -u
-
-# Stop script if command returns non-zero exit code.
-# Prevents hidden errors caused by missing error code propagation.
-set -e
-
-# Handle being in the "wrong" directory
-cd "${BASH_SOURCE%/*}/"
-
-# Include VSTS logging helpers
-. ../eng/common/pipeline-logging-functions.sh
-
-usage()
-{
- echo "Common settings:"
- echo " --configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)"
- echo " --help Print help and exit (short: -h)"
- echo ""
-
- echo "Actions:"
- echo " --pack Package build outputs into NuGet packages"
- echo " --test Run all unit tests in the solution (short: -t)"
- echo " --interpreter Run tests with interpreter"
- echo " --rebuild Run ../.autogen.sh"
- echo " --llvm Enable LLVM support"
- echo " --skipnative Do not build runtime"
- echo " --skipmscorlib Do not build System.Private.CoreLib"
- echo " --ci Enable Azure DevOps telemetry decoration"
- echo ""
-
- echo "Command line arguments starting with '/p:' are passed through to MSBuild."
- echo "Arguments can also be passed in with a single hyphen."
-}
-
-pack=false
-configuration='Debug'
-test_mono_flags=''
-test_xunit_flags=''
-properties=''
-force_rebuild=false
-test=false
-skipmscorlib=false
-skipnative=false
-llvm=false
-autogen_params=''
-ci=false
-
-while [[ $# > 0 ]]; do
- opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
- case "$opt" in
- -help|-h)
- usage
- exit 0
- ;;
- -configuration|-c)
- properties="$properties $1 $2"
- configuration=$2
- shift
- ;;
- -pack)
- pack=true
- ;;
- -test|-t)
- test=true
- ;;
- -interpreter)
- test_mono_flags="$test_mono_flags --interpreter"
- test_xunit_flags="$test_xunit_flags @../../../../CoreFX.issues_interpreter.rsp -parallel none"
- ;;
- -rebuild)
- force_rebuild=true
- ;;
- -skipmscorlib)
- skipmscorlib=true
- ;;
- -skipnative)
- skipnative=true
- ;;
- -llvm)
- llvm=true
- test_mono_flags="$test_mono_flags --llvm"
- ;;
- -ci)
- ci=true
- ;;
- -p:*|/p:*)
- properties="$properties $1"
- ;;
- -m:*|/m:*)
- properties="$properties $1"
- ;;
- -bl:*|/bl:*)
- properties="$properties $1"
- ;;
- -dl:*|/dl:*)
- properties="$properties $1"
- ;;
- *)
- echo "Invalid argument: $1"
- usage
- exit 1
- ;;
- esac
-
- shift
-done
-
-CPU_COUNT=$(getconf _NPROCESSORS_ONLN || echo 4)
-
-if [[ "$configuration" == "Debug" ]]; then
- EXTRA_CFLAGS="-O0 -ggdb3 -fno-omit-frame-pointer"
- EXTRA_CXXFLAGS="-O0 -ggdb3 -fno-omit-frame-pointer"
-elif [[ "$configuration" == "Release" ]]; then
- EXTRA_CFLAGS="-O2 -g"
- EXTRA_CXXFLAGS="-O2 -g"
-fi
-
-if [ "$llvm" = "true" ]; then
- git submodule update --init -- ../external/llvm-project || (Write-PipelineTelemetryError -c "git" -e 1 "Error fetching LLVM submodule" && exit 1)
- autogen_params="$autogen_params --enable-llvm"
-fi
-
-if [[ "$configuration" == "Debug" ]]; then
- autogen_params="$autogen_params --enable-checked-build=private_types"
-fi
-
-# run .././autogen.sh only once or if "--rebuild" argument is provided
-if [[ "$force_rebuild" == "true" || ! -f .configured ]]; then
- (cd .. && ./autogen.sh --with-core=only $autogen_params CFLAGS="$EXTRA_CFLAGS" CXXFLAGS="$EXTRA_CXXFLAGS") || (Write-PipelineTelemetryError -c "configure" -e 1 "Error running autogen" && exit 1)
- touch .configured
-fi
-
-# build mono runtime
-if [ "$skipnative" = "false" ]; then
- make runtime -j$CPU_COUNT || (Write-PipelineTelemetryError -c "runtime" -e 1 "Error building unmanaged runtime" && exit 1)
-fi
-
-# build System.Private.CoreLib (../mcs/class/System.Private.CoreLib)
-if [ "$skipmscorlib" = "false" ]; then
- make bcl CORLIB_BUILD_FLAGS="$properties" || (Write-PipelineTelemetryError -c "bcl" -e 1 "Error building System.Private.CoreLib" && exit 1)
-fi
-
-# create a nupkg with runtime and System.Private.CoreLib
-if [ "$pack" = "true" ]; then
- if [ "$llvm" = "true" ]; then
- make nupkg-llvm || (Write-PipelineTelemetryError -c "nupkg" -e 1 "Error packing NuGet package" && exit 1)
- else
- make nupkg || (Write-PipelineTelemetryError -c "nupkg" -e 1 "Error packing NuGet package" && exit 1)
- fi
-fi
-
-# run all xunit tests
-if [ "$test" = "true" ]; then
- make update-tests-corefx || (Write-PipelineTelemetryError -c "tests-download" -e 1 "Error downloading tests" && exit 1)
- if [ "$ci" = "true" ]; then
- make run-tests-corefx XUNIT_MONO_ENV_OPTIONS="$test_mono_flags" XUNIT_ARGS="$test_xunit_flags" USE_TIMEOUT=1 || (Write-PipelineTelemetryError -c "tests" -e 1 "Error running tests" && exit 1)
- else
- make run-tests-corefx XUNIT_MONO_ENV_OPTIONS="$test_mono_flags" XUNIT_ARGS="$test_xunit_flags"
- fi
-fi
diff --git a/netcore/build.targets b/netcore/build.targets
deleted file mode 100644
index 80c47f9f121..00000000000
--- a/netcore/build.targets
+++ /dev/null
@@ -1,200 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-
- <UsingTask TaskName="ReplaceInFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
- <ParameterGroup>
- <Input ParameterType="System.String" Required="true" />
- <Output ParameterType="System.String" Required="true" />
- <Match ParameterType="System.String" Required="true" />
- <Replace ParameterType="System.String" Required="true" />
- </ParameterGroup>
- <Task>
- <Reference Include="System.Core" />
- <Using Namespace="System" />
- <Using Namespace="System.IO" />
- <Using Namespace="System.Text.RegularExpressions" />
- <Code Type="Fragment" Language="cs">
- <![CDATA[
- File.WriteAllText(Output, Regex.Replace(File.ReadAllText(Input), Match, Replace));
- ]]>
- </Code>
- </Task>
- </UsingTask>
-
- <Import Project="$(MSBuildThisFileDirectory)..\eng\Versions.props"/>
- <Import Project="$(MSBuildThisFileDirectory)..\msvc\mono.winconfig.targets"/>
-
- <PropertyGroup>
- <Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
- <MONO_ENABLE_LLVM Condition="'$(MONO_ENABLE_LLVM)' == ''">false</MONO_ENABLE_LLVM>
- <DOTNET>$(MSBuildThisFileDirectory)..\.dotnet\dotnet</DOTNET>
- <ROSLYN_VERSION>$(MicrosoftNetCompilersVersion)</ROSLYN_VERSION>
- <NETCORETESTS_VERSION>$(MicrosoftPrivateCoreFxNETCoreAppVersion)</NETCORETESTS_VERSION>
- <NETCOREAPP_VERSION>$(MicrosoftNETCoreAppVersion)</NETCOREAPP_VERSION>
- <COREARCH Condition="'$(COREARCH)' == ''">x64</COREARCH>
- <RID Condition="'$(RID)' == ''">win-x64</RID>
- <CORLIB_BUILD_FLAGS Condition="'$(CORLIB_BUILD_FLAGS)' == ''">-c $(Configuration)</CORLIB_BUILD_FLAGS>
- <NETCORESDK_FILE>dotnet-runtime-$(NETCOREAPP_VERSION)-$(RID).zip</NETCORESDK_FILE>
- <NETCORE_URL>https://dotnetcli.blob.core.windows.net/dotnet/Runtime/$(NETCOREAPP_VERSION)/$(NETCORESDK_FILE)</NETCORE_URL>
- <SHAREDRUNTIME>shared\Microsoft.NETCore.App\$(NETCOREAPP_VERSION)\</SHAREDRUNTIME>
- <FEED_BASE_URL>https://dotnetfeed.blob.core.windows.net/dotnet-core</FEED_BASE_URL>
- <TEST_ASSETS_PATH>corefx-tests/$(NETCORETESTS_VERSION)/Windows_NT.x64/netcoreapp/corefx-test-assets.xml</TEST_ASSETS_PATH>
- <MONO_RUNTIME_BUILD_DIR>$(MSBuildThisFileDirectory)..\msvc\build\sgen\$(COREARCH)\Bin\$(Configuration)\</MONO_RUNTIME_BUILD_DIR>
- <MONO_PRIVATE_CORLIB_BUILD_DIR>$(MSBuildThisFileDirectory)System.Private.CoreLib\bin\$(COREARCH)\</MONO_PRIVATE_CORLIB_BUILD_DIR>
- </PropertyGroup>
-
- <Target Name="configure-mono-environment-source"
- Inputs="$(MSBuildThisFileDirectory)..\configure.ac;$(MSBuildThisFileDirectory)System.Private.CoreLib\src\System\Environment.Mono.in"
- Outputs="$(MSBuildThisFileDirectory)System.Private.CoreLib\src\System\Environment.Mono.cs">
- <GetVersionsFromConfigureAC ConfigFileRoot="$(MSBuildThisFileDirectory)..\">
- <Output TaskParameter="MonoVersion" PropertyName="_MonoVersion" />
- <Output TaskParameter="MonoCorlibVersion" PropertyName="_MonoCorlibVersion" />
- </GetVersionsFromConfigureAC>
-
- <ReplaceInFile
- Input="$(MSBuildThisFileDirectory)System.Private.CoreLib\src\System\Environment.Mono.in"
- Output="$(MSBuildThisFileDirectory)System.Private.CoreLib\src\System\Environment.Mono.cs"
- Match="@MONO_CORLIB_VERSION@"
- Replace="$(_MonoCorlibVersion)" />
- </Target>
-
- <Target Name="init-tools">
- <Exec Command="powershell -NoProfile -NoLogo -ExecutionPolicy ByPass -Command &quot;$(MSBuildThisFileDirectory)init-tools.ps1&quot;">
- <Output TaskParameter="ExitCode" PropertyName="_ExitCode" />
- </Exec>
- </Target>
-
- <Target Name="update-roslyn"
- Condition="!Exists('$(MSBuildThisFileDirectory)roslyn\packages\microsoft.net.compilers.toolset\$(ROSLYN_VERSION)\microsoft.net.compilers.toolset.nuspec')"
- DependsOnTargets="init-tools">
- <PropertyGroup>
- <_UpdateRoslynArgs>&quot;$(MSBuildThisFileDirectory)roslyn-restore.csproj&quot;</_UpdateRoslynArgs>
- <_UpdateRoslynArgs>$(_UpdateRoslynArgs) -p:RoslynVersion=$(ROSLYN_VERSION)</_UpdateRoslynArgs>
- <_UpdateRoslynArgs>$(_UpdateRoslynArgs) --packages &quot;$(MSBuildThisFileDirectory)roslyn\packages&quot;</_UpdateRoslynArgs>
- <_UpdateRoslynArgs>$(_UpdateRoslynArgs) -p:OutputPath=&quot;$(MSBuildThisFileDirectory)roslyn\restore&quot;</_UpdateRoslynArgs>
- </PropertyGroup>
- <Exec Command="$(DOTNET) restore $(_UpdateRoslynArgs)">
- <Output TaskParameter="ExitCode" PropertyName="_ExitCode" />
- </Exec>
- </Target>
-
- <Target Name="update-corefx"
- Inputs="$(MSBuildThisFileDirectory)corefx-restore.csproj"
- Outputs="$(MSBuildThisFileDirectory)corefx\.stamp-dl-corefx-$(NETCORETESTS_VERSION)"
- DependsOnTargets="init-tools">
- <PropertyGroup>
- <_UpdateCoreFxArgs>&quot;$(MSBuildThisFileDirectory)corefx-restore.csproj&quot;</_UpdateCoreFxArgs>
- <_UpdateCoreFxArgs>$(_UpdateCoreFxArgs) --runtime $(RID)</_UpdateCoreFxArgs>
- <_UpdateCoreFxArgs>$(_UpdateCoreFxArgs) --packages &quot;$(MSBuildThisFileDirectory)corefx\packages&quot;</_UpdateCoreFxArgs>
- <_UpdateCoreFxArgs>$(_UpdateCoreFxArgs) -p:MicrosoftPrivateCoreFxNETCoreAppVersion=$(NETCORETESTS_VERSION)</_UpdateCoreFxArgs>
- <_UpdateCoreFxArgs>$(_UpdateCoreFxArgs) -p:OutputPath=&quot;$(MSBuildThisFileDirectory)corefx\restore&quot;</_UpdateCoreFxArgs>
- </PropertyGroup>
- <Exec Command="$(DOTNET) build $(_UpdateCoreFxArgs)">
- <Output TaskParameter="ExitCode" PropertyName="_ExitCode" />
- </Exec>
- <Touch Files="$(MSBuildThisFileDirectory)corefx\.stamp-dl-corefx-$(NETCORETESTS_VERSION)" AlwaysCreate="true" />
- </Target>
-
- <Target Name="download-unzip-netcore-sdk"
- Condition="!Exists('$(MSBuildThisFileDirectory)$(NETCORESDK_FILE)')">
- <DownloadFile SourceUrl="$(NETCORE_URL)" DestinationFolder="$(MSBuildThisFileDirectory)" DestinationFileName="$(NETCORESDK_FILE)" />
- <Unzip SourceFiles="$(MSBuildThisFileDirectory)$(NETCORESDK_FILE)" DestinationFolder="$(MSBuildThisFileDirectory)" OverwriteReadOnlyFiles="true" />
- </Target>
-
- <Target Name="update-netcore-sdk"
- Condition="!Exists('$(MSBuildThisFileDirectory)$(NETCORESDK_FILE)')">
- <PropertyGroup>
- <_UpdateNetCoreSdkArgs>&quot;$(MSBuildThisFileDirectory)build.targets&quot;</_UpdateNetCoreSdkArgs>
- <_UpdateNetCoreSdkArgs>$(_UpdateNetCoreSdkArgs) /t:download-unzip-netcore-sdk</_UpdateNetCoreSdkArgs>
- </PropertyGroup>
- <RemoveDir Directories="$(MSBuildThisFileDirectory)shared\Microsoft.NETCore.App" />
- <Exec Command="$(DOTNET) msbuild $(_UpdateNetCoreSdkArgs)">
- <Output TaskParameter="ExitCode" PropertyName="_ExitCode" />
- </Exec>
- </Target>
-
- <Target Name="update-tests-corefx"
- Inputs="$(MSBuildThisFileDirectory)corefx-tests-restore.proj"
- Outputs="$(MSBuildThisFileDirectory)corefx\.stamp-dl-corefx-tests-$(NETCORETESTS_VERSION)"
- DependsOnTargets="init-tools">
- <PropertyGroup>
- <_UpdateTestsCoreFxArgs>&quot;$(MSBuildThisFileDirectory)corefx-tests-restore.proj&quot;</_UpdateTestsCoreFxArgs>
- <_UpdateTestsCoreFxArgs>$(_UpdateTestsCoreFxArgs) -m</_UpdateTestsCoreFxArgs>
- <_UpdateTestsCoreFxArgs>$(_UpdateTestsCoreFxArgs) -t:DownloadAllTests</_UpdateTestsCoreFxArgs>
- <_UpdateTestsCoreFxArgs>$(_UpdateTestsCoreFxArgs) -p:TEST_ASSETS_PATH=&quot;$(TEST_ASSETS_PATH)&quot;</_UpdateTestsCoreFxArgs>
- <_UpdateTestsCoreFxArgs>$(_UpdateTestsCoreFxArgs) -p:FEED_BASE_URL=&quot;$(FEED_BASE_URL)&quot;</_UpdateTestsCoreFxArgs>
- </PropertyGroup>
- <RemoveDir Directories="$(MSBuildThisFileDirectory)corefx\tests" />
- <Exec Command="$(DOTNET) msbuild $(_UpdateTestsCoreFxArgs)">
- <Output TaskParameter="ExitCode" PropertyName="_ExitCode" />
- </Exec>
- <RemoveDir Directories="$(MSBuildThisFileDirectory)corefx\tests\extracted\System.Utf8String.Experimental.Tests" />
- <Touch Files="$(MSBuildThisFileDirectory)corefx\.stamp-dl-corefx-tests-$(NETCORETESTS_VERSION)" AlwaysCreate="true" />
- </Target>
-
- <Target Name="bcl" DependsOnTargets="init-tools;update-roslyn;configure-mono-environment-source">
- <PropertyGroup>
- <_CorlibBuildArgs>-p:TargetsWindows=true</_CorlibBuildArgs>
- <_CorlibBuildArgs>$(_CorlibBuildArgs) $(CORLIB_BUILD_FLAGS)</_CorlibBuildArgs>
- <_CorlibBuildArgs>$(_CorlibBuildArgs) -p:BuildArch=$(COREARCH)</_CorlibBuildArgs>
- <_CorlibBuildArgs>$(_CorlibBuildArgs) -p:OutputPath=bin\$(COREARCH)</_CorlibBuildArgs>
- <_CorlibBuildArgs>$(_CorlibBuildArgs) -p:RoslynPropsFile=&quot;$(MSBuildThisFileDirectory)\roslyn\packages\microsoft.net.compilers.toolset\$(ROSLYN_VERSION)\build\Microsoft.Net.Compilers.Toolset.props&quot;</_CorlibBuildArgs>
- <_CorlibBuildArgs>$(_CorlibBuildArgs) &quot;$(MSBuildThisFileDirectory)System.Private.CoreLib\System.Private.CoreLib.csproj&quot;</_CorlibBuildArgs>
- </PropertyGroup>
-
- <Exec Command="$(DOTNET) build $(_CorlibBuildArgs)">
- <Output TaskParameter="ExitCode" PropertyName="_ExitCode" />
- </Exec>
- </Target>
-
- <Target Name="build-runtime">
- <PropertyGroup>
- <RuntimeBuildTarget Condition="'$(RuntimeBuildTarget)' == ''">build</RuntimeBuildTarget>
- </PropertyGroup>
- <MSBuild Projects="$(MSBuildThisFileDirectory)..\msvc\mono.sln" Targets="$(RuntimeBuildTarget)" Properties="Platform=$(COREARCH);Configuration=$(Configuration);MONO_TARGET_GC=sgen;MONO_ENABLE_LLVM=$(MONO_ENABLE_LLVM);MONO_ENABLE_NETCORE=true"/>
- </Target>
-
- <Target Name="link-mono">
- <Error Text="Missing Mono MSVC runtime build." Condition="!Exists('$(MONO_RUNTIME_BUILD_DIR)mono-2.0-sgen.dll')" />
- <Error Text="Missing Mono System.Private.CoreLib build." Condition="!Exists('$(MONO_PRIVATE_CORLIB_BUILD_DIR)System.Private.CoreLib.dll')" />
- <Copy SourceFiles="$(MONO_RUNTIME_BUILD_DIR)mono-2.0-sgen.dll" DestinationFiles="$(SHAREDRUNTIME)coreclr.dll" SkipUnchangedFiles="true" />
- <Copy SourceFiles="$(MONO_RUNTIME_BUILD_DIR)mono-2.0-sgen.pdb" DestinationFiles="$(SHAREDRUNTIME)coreclr.pdb" SkipUnchangedFiles="true" />
- <Copy SourceFiles="$(MONO_PRIVATE_CORLIB_BUILD_DIR)System.Private.CoreLib.dll" DestinationFiles="$(SHAREDRUNTIME)System.Private.CoreLib.dll" SkipUnchangedFiles="true" />
- <Copy SourceFiles="$(MONO_PRIVATE_CORLIB_BUILD_DIR)System.Private.CoreLib.pdb" DestinationFiles="$(SHAREDRUNTIME)System.Private.CoreLib.pdb" SkipUnchangedFiles="true" />
- </Target>
-
- <Target Name="prepare" DependsOnTargets="update-netcore-sdk;update-corefx;update-roslyn;link-mono" />
-
- <!-- To run an individual test, set property CoreFxTests to the name of the test to execute -->
- <Target Name="run-tests-corefx" DependsOnTargets="prepare;update-tests-corefx">
- <PropertyGroup>
- <CoreFxTests Condition="'$(CoreFxTests)' == ''">*</CoreFxTests>
- <CoreFxTestTimeout Condition="'$(CoreFxTestTimeout)' == ''">-1</CoreFxTestTimeout>
- <_RunTestsCoreFxArgs>(set MONO_ENV_OPTIONS=&quot;--debug&quot;) &amp; (set COMPlus_DebugWriteToStdErr=1) &amp; </_RunTestsCoreFxArgs>
- <_RunTestsCoreFxArgs>$(_RunTestsCoreFxArgs) powershell -NoProfile -NoLogo -ExecutionPolicy ByPass -Command &quot;$(MSBuildThisFileDirectory)run-tests-corefx.ps1&quot;</_RunTestsCoreFxArgs>
- <_RunTestsCoreFxArgs>$(_RunTestsCoreFxArgs) -fxversion &quot;$(NETCOREAPP_VERSION)&quot; -timeout $(CoreFxTestTimeout) -corefxtests &quot;$(CoreFxTests)&quot;</_RunTestsCoreFxArgs>
- </PropertyGroup>
-
- <Exec Command="$(_RunTestsCoreFxArgs)">
- <Output TaskParameter="ExitCode" PropertyName="_ExitCode" />
- </Exec>
- </Target>
-
- <Target Name="Clean">
- <RemoveDir Directories="$(MSBuildThisFileDirectory)..\.dotnet" />
- <RemoveDir Directories="$(MSBuildThisFileDirectory)sdk" />
- <RemoveDir Directories="$(MSBuildThisFileDirectory)shared" />
- <RemoveDir Directories="$(MSBuildThisFileDirectory)host" />
- <RemoveDir Directories="$(MSBuildThisFileDirectory)dotnet" />
- <RemoveDir Directories="$(MSBuildThisFileDirectory)corefx" />
- <RemoveDir Directories="$(MSBuildThisFileDirectory)roslyn" />
- <RemoveDir Directories="$(MSBuildThisFileDirectory)System.Private.CoreLib\bin" />
- <Delete Files="$(MSBuildThisFileDirectory)$(NETCORESDK_FILE)" />
- <Delete Files="$(MSBuildThisFileDirectory)LICENSE.txt" />
- <Delete Files="$(MSBuildThisFileDirectory)ThirdPartyNotices.txt" />
- <Delete Files="$(MSBuildThisFileDirectory).failures" />
- </Target>
-
- <Target Name="Build" DependsOnTargets="prepare;bcl" />
-
-</Project> \ No newline at end of file
diff --git a/netcore/corefx-restore.csproj b/netcore/corefx-restore.csproj
deleted file mode 100644
index a51ac53635a..00000000000
--- a/netcore/corefx-restore.csproj
+++ /dev/null
@@ -1,14 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Library</OutputType>
- <TargetFramework>netcoreapp5.0</TargetFramework>
- <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
- <EnableDefaultItems>false</EnableDefaultItems>
- <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
- </PropertyGroup>
- <ItemGroup>
- <PackageReference Include="Microsoft.Diagnostics.Runtime" Version="1.0.5" />
- <PackageReference Include="Microsoft.Private.CoreFx.NETCoreApp" Version="$(MicrosoftPrivateCoreFxNETCoreAppVersion)" />
- <PackageReference Include="Microsoft.Private.CoreFx.OOB" Version="$(MicrosoftPrivateCoreFxNETCoreAppVersion)" />
- </ItemGroup>
-</Project>
diff --git a/netcore/corefx-tests-restore.proj b/netcore/corefx-tests-restore.proj
deleted file mode 100644
index 1cd7b8f207a..00000000000
--- a/netcore/corefx-tests-restore.proj
+++ /dev/null
@@ -1,39 +0,0 @@
-<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-
- <Target Name="DownloadTest">
- <DownloadFile
- SourceUrl="$(FEED_BASE_URL)/$(TestFile)"
- DestinationFolder="$(MSBuildProjectDirectory)/corefx/tests"
- Retries="3">
- <Output TaskParameter="DownloadedFile" ItemName="Content" />
- </DownloadFile>
- </Target>
-
- <Target Name="DownloadTestsList">
- <DownloadFile
- SourceUrl="$(FEED_BASE_URL)/$(TEST_ASSETS_PATH)"
- DestinationFolder="$(MSBuildProjectDirectory)/corefx/tests"
- Retries="3">
- <Output TaskParameter="DownloadedFile" ItemName="Content" />
- </DownloadFile>
- <XmlPeek
- XmlInputPath="$(MSBuildProjectDirectory)/corefx/tests/corefx-test-assets.xml"
- Query="/Build/Blob/@Id">
- <Output TaskParameter="Result" ItemName="AllTests" />
- </XmlPeek>
- </Target>
-
- <Target Name="DownloadAllTests" DependsOnTargets="DownloadTestsList">
- <ItemGroup>
- <TempProjects Include="$(MSBuildProjectFile)">
- <Properties>TestFile=%(AllTests.Identity)</Properties>
- </TempProjects>
- </ItemGroup>
- <MSBuild Projects="@(TempProjects)" BuildInParallel="true" StopOnFirstFailure="true" Targets="DownloadTest" />
- <Message Text="Extracting CoreFX tests..." Importance="high" />
- <Unzip
- SourceFiles="$(MSBuildProjectDirectory)/corefx/tests/$([System.IO.Path]::GetFileName('%(AllTests.Identity)'))"
- DestinationFolder="$(MSBuildProjectDirectory)/corefx/tests/extracted/$([System.IO.Path]::GetFileNameWithoutExtension('%(AllTests.Identity)'))" />
- </Target>
-
-</Project>
diff --git a/netcore/corerun/.gitignore b/netcore/corerun/.gitignore
deleted file mode 100644
index 43904f30704..00000000000
--- a/netcore/corerun/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/corerun
-/Makefile
diff --git a/netcore/corerun/Makefile.am b/netcore/corerun/Makefile.am
deleted file mode 100644
index e6acc3c0f93..00000000000
--- a/netcore/corerun/Makefile.am
+++ /dev/null
@@ -1,9 +0,0 @@
-if !HOST_WIN32
-# Files copied from coreclr/src/coreclr/hosts/unixcorerun repo
-
-AM_CPPFLAGS = $(SHARED_CFLAGS)
-
-bin_PROGRAMS = corerun
-
-corerun_SOURCES = corerun.cpp coreruncommon.cpp coreruncommon.h coreclrhost.h
-endif \ No newline at end of file
diff --git a/netcore/corerun/coreclrhost.h b/netcore/corerun/coreclrhost.h
deleted file mode 100644
index d1ec7249741..00000000000
--- a/netcore/corerun/coreclrhost.h
+++ /dev/null
@@ -1,125 +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.
-
-//
-// APIs for hosting CoreCLR
-//
-
-#ifndef __CORECLR_HOST_H__
-#define __CORECLR_HOST_H__
-
-#if defined(_WIN32) && defined(_M_IX86)
-#define CORECLR_CALLING_CONVENTION __stdcall
-#else
-#define CORECLR_CALLING_CONVENTION
-#endif
-
-// For each hosting API, we define a function prototype and a function pointer
-// The prototype is useful for implicit linking against the dynamic coreclr
-// library and the pointer for explicit dynamic loading (dlopen, LoadLibrary)
-#define CORECLR_HOSTING_API(function, ...) \
- extern "C" int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \
- typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__)
-
-//
-// Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain
-//
-// Parameters:
-// exePath - Absolute path of the executable that invoked the ExecuteAssembly (the native host application)
-// appDomainFriendlyName - Friendly name of the app domain that will be created to execute the assembly
-// propertyCount - Number of properties (elements of the following two arguments)
-// propertyKeys - Keys of properties of the app domain
-// propertyValues - Values of properties of the app domain
-// hostHandle - Output parameter, handle of the created host
-// domainId - Output parameter, id of the created app domain
-//
-// Returns:
-// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
-//
-CORECLR_HOSTING_API(coreclr_initialize,
- const char* exePath,
- const char* appDomainFriendlyName,
- int propertyCount,
- const char** propertyKeys,
- const char** propertyValues,
- void** hostHandle,
- unsigned int* domainId);
-
-//
-// Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host.
-//
-// Parameters:
-// hostHandle - Handle of the host
-// domainId - Id of the domain
-//
-// Returns:
-// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
-//
-CORECLR_HOSTING_API(coreclr_shutdown,
- void* hostHandle,
- unsigned int domainId);
-
-//
-// Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host.
-//
-// Parameters:
-// hostHandle - Handle of the host
-// domainId - Id of the domain
-// latchedExitCode - Latched exit code after domain unloaded
-//
-// Returns:
-// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
-//
-CORECLR_HOSTING_API(coreclr_shutdown_2,
- void* hostHandle,
- unsigned int domainId,
- int* latchedExitCode);
-
-//
-// Create a native callable function pointer for a managed method.
-//
-// Parameters:
-// hostHandle - Handle of the host
-// domainId - Id of the domain
-// entryPointAssemblyName - Name of the assembly which holds the custom entry point
-// entryPointTypeName - Name of the type which holds the custom entry point
-// entryPointMethodName - Name of the method which is the custom entry point
-// delegate - Output parameter, the function stores a native callable function pointer to the delegate at the specified address
-//
-// Returns:
-// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
-//
-CORECLR_HOSTING_API(coreclr_create_delegate,
- void* hostHandle,
- unsigned int domainId,
- const char* entryPointAssemblyName,
- const char* entryPointTypeName,
- const char* entryPointMethodName,
- void** delegate);
-
-//
-// Execute a managed assembly with given arguments
-//
-// Parameters:
-// hostHandle - Handle of the host
-// domainId - Id of the domain
-// argc - Number of arguments passed to the executed assembly
-// argv - Array of arguments passed to the executed assembly
-// managedAssemblyPath - Path of the managed assembly to execute (or NULL if using a custom entrypoint).
-// exitCode - Exit code returned by the executed assembly
-//
-// Returns:
-// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
-//
-CORECLR_HOSTING_API(coreclr_execute_assembly,
- void* hostHandle,
- unsigned int domainId,
- int argc,
- const char** argv,
- const char* managedAssemblyPath,
- unsigned int* exitCode);
-
-#undef CORECLR_HOSTING_API
-
-#endif // __CORECLR_HOST_H__
diff --git a/netcore/corerun/corerun.cpp b/netcore/corerun/corerun.cpp
deleted file mode 100644
index 4e5c9d9839e..00000000000
--- a/netcore/corerun/corerun.cpp
+++ /dev/null
@@ -1,162 +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.
-
-#include <coreruncommon.h>
-#include <string>
-#include <string.h>
-#include <sys/stat.h>
-
-// Display the command line options
-void DisplayUsage()
-{
- fprintf(
- stderr,
- "Usage: corerun [OPTIONS] assembly [ARGUMENTS]\n"
- "Execute the specified managed assembly with the passed in arguments\n\n"
- "Options:\n"
- "-c, --clr-path path to the libcoreclr.so and the managed CLR assemblies\n");
-}
-
-// Parse the command line arguments
-bool ParseArguments(
- const int argc,
- const char* argv[],
- const char** clrFilesPath,
- const char** managedAssemblyPath,
- int* managedAssemblyArgc,
- const char*** managedAssemblyArgv)
-{
- bool success = false;
-
- *clrFilesPath = nullptr;
- *managedAssemblyPath = nullptr;
- *managedAssemblyArgv = nullptr;
- *managedAssemblyArgc = 0;
-
- // The command line must contain at least the current exe name and the managed assembly path
- if (argc >= 2)
- {
- for (int i = 1; i < argc; i++)
- {
- // Check for an option
- if (argv[i][0] == '-')
- {
- // Path to the libcoreclr.so and the managed CLR assemblies
- if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--clr-path") == 0)
- {
- i++;
- if (i < argc)
- {
- *clrFilesPath = argv[i];
- }
- else
- {
- fprintf(stderr, "Option %s: missing path\n", argv[i - 1]);
- break;
- }
- }
- else if (strcmp(argv[i], "-?") == 0 || strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
- {
- DisplayUsage();
- break;
- }
- else
- {
- fprintf(stderr, "Unknown option %s\n", argv[i]);
- break;
- }
- }
- else
- {
- // First argument that is not an option is the managed assembly to execute
- *managedAssemblyPath = argv[i];
-
- int managedArgvOffset = (i + 1);
- *managedAssemblyArgc = argc - managedArgvOffset;
- if (*managedAssemblyArgc != 0)
- {
- *managedAssemblyArgv = &argv[managedArgvOffset];
- }
- success = true;
- break;
- }
- }
- }
- else
- {
- DisplayUsage();
- }
-
- return success;
-}
-
-int corerun(const int argc, const char* argv[])
-{
- const char* clrFilesPath;
- const char* managedAssemblyPath;
- const char** managedAssemblyArgv;
- int managedAssemblyArgc;
-
- if (!ParseArguments(
- argc,
- argv,
- &clrFilesPath,
- &managedAssemblyPath,
- &managedAssemblyArgc,
- &managedAssemblyArgv))
- {
- // Invalid command line
- return -1;
- }
-
- // Check if the specified managed assembly file exists
- struct stat sb;
- if (stat(managedAssemblyPath, &sb) == -1)
- {
- perror("Managed assembly not found");
- return -1;
- }
-
- // Verify that the managed assembly path points to a file
- if (!S_ISREG(sb.st_mode))
- {
- fprintf(stderr, "The specified managed assembly is not a file\n");
- return -1;
- }
-
- // Make sure we have a full path for argv[0].
- std::string argv0AbsolutePath;
- if (!GetEntrypointExecutableAbsolutePath(argv0AbsolutePath))
- {
- perror("Could not get full path");
- return -1;
- }
-
- std::string clrFilesAbsolutePath;
- if(!GetClrFilesAbsolutePath(argv0AbsolutePath.c_str(), clrFilesPath, clrFilesAbsolutePath))
- {
- return -1;
- }
-
- std::string managedAssemblyAbsolutePath;
- if (!GetAbsolutePath(managedAssemblyPath, managedAssemblyAbsolutePath))
- {
- perror("Failed to convert managed assembly path to absolute path");
- return -1;
- }
-
- int exitCode = ExecuteManagedAssembly(
- argv0AbsolutePath.c_str(),
- clrFilesAbsolutePath.c_str(),
- managedAssemblyAbsolutePath.c_str(),
- managedAssemblyArgc,
- managedAssemblyArgv);
-
- return exitCode;
-}
-
-int main(const int argc, const char* argv[])
-{
- return corerun(argc, argv);
-}
diff --git a/netcore/corerun/coreruncommon.cpp b/netcore/corerun/coreruncommon.cpp
deleted file mode 100644
index 25007bb3fd9..00000000000
--- a/netcore/corerun/coreruncommon.cpp
+++ /dev/null
@@ -1,520 +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.
-
-//
-// Code that is used by both the Unix corerun and coreconsole.
-//
-
-#include "config.h"
-
-#include <cstdlib>
-#include <cstring>
-#include <assert.h>
-#include <dirent.h>
-#include <dlfcn.h>
-#include <limits.h>
-#include <set>
-#include <string>
-#include <string.h>
-#include <sys/stat.h>
-#if defined(__FreeBSD__)
-#include <sys/types.h>
-#include <sys/param.h>
-#endif
-#if HAVE_GETAUXVAL
-#include <sys/auxv.h>
-#endif
-#if defined(HAVE_SYS_SYSCTL_H) || defined(__FreeBSD__)
-#include <sys/sysctl.h>
-#endif
-#include "coreruncommon.h"
-#include "coreclrhost.h"
-#include <unistd.h>
-#ifndef SUCCEEDED
-#define SUCCEEDED(Status) ((Status) >= 0)
-#endif // !SUCCEEDED
-
-// Name of the environment variable controlling server GC.
-// If set to 1, server GC is enabled on startup. If 0, server GC is
-// disabled. Server GC is off by default.
-static const char* serverGcVar = "COMPlus_gcServer";
-
-// Name of environment variable to control "System.Globalization.Invariant"
-// Set to 1 for Globalization Invariant mode to be true. Default is false.
-static const char* globalizationInvariantVar = "CORECLR_GLOBAL_INVARIANT";
-
-#if defined(__linux__)
-#define symlinkEntrypointExecutable "/proc/self/exe"
-#elif !defined(__APPLE__)
-#define symlinkEntrypointExecutable "/proc/curproc/exe"
-#endif
-
-bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable)
-{
- bool result = false;
-
- entrypointExecutable.clear();
-
- // Get path to the executable for the current process using
- // platform specific means.
-#if defined(__APPLE__)
-
- // On Mac, we ask the OS for the absolute path to the entrypoint executable
- uint32_t lenActualPath = 0;
- if (_NSGetExecutablePath(nullptr, &lenActualPath) == -1)
- {
- // OSX has placed the actual path length in lenActualPath,
- // so re-attempt the operation
- std::string resizedPath(lenActualPath, '\0');
- char *pResizedPath = const_cast<char *>(resizedPath.c_str());
- if (_NSGetExecutablePath(pResizedPath, &lenActualPath) == 0)
- {
- entrypointExecutable.assign(pResizedPath);
- result = true;
- }
- }
-#elif defined (__FreeBSD__)
- static const int name[] = {
- CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1
- };
- char path[PATH_MAX];
- size_t len;
-
- len = sizeof(path);
- if (sysctl(name, 4, path, &len, nullptr, 0) == 0)
- {
- entrypointExecutable.assign(path);
- result = true;
- }
- else
- {
- // ENOMEM
- result = false;
- }
-#elif defined(__NetBSD__) && defined(KERN_PROC_PATHNAME)
- static const int name[] = {
- CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME,
- };
- char path[MAXPATHLEN];
- size_t len;
-
- len = sizeof(path);
- if (sysctl(name, __arraycount(name), path, &len, NULL, 0) != -1)
- {
- entrypointExecutable.assign(path);
- result = true;
- }
- else
- {
- result = false;
- }
-#else
-
-#if HAVE_GETAUXVAL && defined(AT_EXECFN)
- const char *execfn = (const char *)getauxval(AT_EXECFN);
-
- if (execfn)
- {
- entrypointExecutable.assign(execfn);
- result = true;
- }
- else
-#endif
- // On other OSs, return the symlink that will be resolved by GetAbsolutePath
- // to fetch the entrypoint EXE absolute path, inclusive of filename.
- result = GetAbsolutePath(symlinkEntrypointExecutable, entrypointExecutable);
-#endif
-
- return result;
-}
-
-bool GetAbsolutePath(const char* path, std::string& absolutePath)
-{
- bool result = false;
-
- char realPath[PATH_MAX];
- if (realpath(path, realPath) != nullptr && realPath[0] != '\0')
- {
- absolutePath.assign(realPath);
- // realpath should return canonicalized path without the trailing slash
- assert(absolutePath.back() != '/');
-
- result = true;
- }
-
- return result;
-}
-
-bool GetDirectory(const char* absolutePath, std::string& directory)
-{
- directory.assign(absolutePath);
- size_t lastSlash = directory.rfind('/');
- if (lastSlash != std::string::npos)
- {
- directory.erase(lastSlash);
- return true;
- }
-
- return false;
-}
-
-bool GetClrFilesAbsolutePath(const char* currentExePath, const char* clrFilesPath, std::string& clrFilesAbsolutePath)
-{
- std::string clrFilesRelativePath;
- const char* clrFilesPathLocal = clrFilesPath;
- if (clrFilesPathLocal == nullptr)
- {
- // There was no CLR files path specified, use the folder of the corerun/coreconsole
- if (!GetDirectory(currentExePath, clrFilesRelativePath))
- {
- perror("Failed to get directory from argv[0]");
- return false;
- }
-
- clrFilesPathLocal = clrFilesRelativePath.c_str();
-
- // TODO: consider using an env variable (if defined) as a fall-back.
- // The windows version of the corerun uses core_root env variable
- }
-
- if (!GetAbsolutePath(clrFilesPathLocal, clrFilesAbsolutePath))
- {
- perror("Failed to convert CLR files path to absolute path");
- return false;
- }
-
- return true;
-}
-
-void AddFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList)
-{
- const char * const tpaExtensions[] = {
- ".ni.dll", // Probe for .ni.dll first so that it's preferred if ni and il coexist in the same dir
- ".dll",
- ".ni.exe",
- ".exe",
- };
-
- DIR* dir = opendir(directory);
- if (dir == nullptr)
- {
- return;
- }
-
- std::set<std::string> addedAssemblies;
-
- // Walk the directory for each extension separately so that we first get files with .ni.dll extension,
- // then files with .dll extension, etc.
- for (size_t extIndex = 0; extIndex < sizeof(tpaExtensions) / sizeof(tpaExtensions[0]); extIndex++)
- {
- const char* ext = tpaExtensions[extIndex];
- int extLength = strlen(ext);
-
- struct dirent* entry;
-
- // For all entries in the directory
- while ((entry = readdir(dir)) != nullptr)
- {
- // We are interested in files only
- switch (entry->d_type)
- {
- case DT_REG:
- break;
-
- // Handle symlinks and file systems that do not support d_type
- case DT_LNK:
- case DT_UNKNOWN:
- {
- std::string fullFilename;
-
- fullFilename.append(directory);
- fullFilename.append("/");
- fullFilename.append(entry->d_name);
-
- struct stat sb;
- if (stat(fullFilename.c_str(), &sb) == -1)
- {
- continue;
- }
-
- if (!S_ISREG(sb.st_mode))
- {
- continue;
- }
- }
- break;
-
- default:
- continue;
- }
-
- std::string filename(entry->d_name);
-
- // Check if the extension matches the one we are looking for
- int extPos = filename.length() - extLength;
- if ((extPos <= 0) || (filename.compare(extPos, extLength, ext) != 0))
- {
- continue;
- }
-
- std::string filenameWithoutExt(filename.substr(0, extPos));
-
- // Make sure if we have an assembly with multiple extensions present,
- // we insert only one version of it.
- if (addedAssemblies.find(filenameWithoutExt) == addedAssemblies.end())
- {
- addedAssemblies.insert(filenameWithoutExt);
-
- tpaList.append(directory);
- tpaList.append("/");
- tpaList.append(filename);
- tpaList.append(":");
- }
- }
-
- // Rewind the directory stream to be able to iterate over it for the next extension
- rewinddir(dir);
- }
-
- closedir(dir);
-}
-
-const char* GetEnvValueBoolean(const char* envVariable)
-{
- const char* envValue = std::getenv(envVariable);
- if (envValue == nullptr)
- {
- envValue = "0";
- }
- // CoreCLR expects strings "true" and "false" instead of "1" and "0".
- return (std::strcmp(envValue, "1") == 0 || strcasecmp(envValue, "true") == 0) ? "true" : "false";
-}
-
-static void *TryLoadHostPolicy(const char *hostPolicyPath)
-{
-#if defined(__APPLE__)
- static const char LibrarySuffix[] = ".dylib";
-#else // Various Linux-related OS-es
- static const char LibrarySuffix[] = ".so";
-#endif
-
- std::string hostPolicyCompletePath(hostPolicyPath);
- hostPolicyCompletePath.append(LibrarySuffix);
-
- void *libraryPtr = dlopen(hostPolicyCompletePath.c_str(), RTLD_LAZY);
- if (libraryPtr == nullptr)
- {
- fprintf(stderr, "Failed to load mock hostpolicy at path '%s'. Error: %s", hostPolicyCompletePath.c_str(), dlerror());
- }
-
- return libraryPtr;
-}
-
-int ExecuteManagedAssembly(
- const char* currentExeAbsolutePath,
- const char* clrFilesAbsolutePath,
- const char* managedAssemblyAbsolutePath,
- int managedAssemblyArgc,
- const char** managedAssemblyArgv)
-{
- // Indicates failure
- int exitCode = -1;
-
-#ifdef _ARM_
- // libunwind library is used to unwind stack frame, but libunwind for ARM
- // does not support ARM vfpv3/NEON registers in DWARF format correctly.
- // Therefore let's disable stack unwinding using DWARF information
- // See https://github.com/dotnet/coreclr/issues/6698
- //
- // libunwind use following methods to unwind stack frame.
- // UNW_ARM_METHOD_ALL 0xFF
- // UNW_ARM_METHOD_DWARF 0x01
- // UNW_ARM_METHOD_FRAME 0x02
- // UNW_ARM_METHOD_EXIDX 0x04
- putenv(const_cast<char *>("UNW_ARM_UNWIND_METHOD=6"));
-#endif // _ARM_
-
- std::string coreClrDllPath(clrFilesAbsolutePath);
- coreClrDllPath.append("/");
- coreClrDllPath.append(coreClrDll);
-
- if (coreClrDllPath.length() >= PATH_MAX)
- {
- fprintf(stderr, "Absolute path to libcoreclr.so too long\n");
- return -1;
- }
-
- // Get just the path component of the managed assembly path
- std::string appPath;
- GetDirectory(managedAssemblyAbsolutePath, appPath);
-
- std::string tpaList;
- if (strlen(managedAssemblyAbsolutePath) > 0)
- {
- // Target assembly should be added to the tpa list. Otherwise corerun.exe
- // may find wrong assembly to execute.
- // Details can be found at https://github.com/dotnet/coreclr/issues/5631
- tpaList = managedAssemblyAbsolutePath;
- tpaList.append(":");
- }
-
- // Construct native search directory paths
- std::string nativeDllSearchDirs(appPath);
- char *coreLibraries = getenv("CORE_LIBRARIES");
- if (coreLibraries)
- {
- nativeDllSearchDirs.append(":");
- nativeDllSearchDirs.append(coreLibraries);
- if (std::strcmp(coreLibraries, clrFilesAbsolutePath) != 0)
- {
- AddFilesFromDirectoryToTpaList(coreLibraries, tpaList);
- }
- }
-
- nativeDllSearchDirs.append(":");
- nativeDllSearchDirs.append(clrFilesAbsolutePath);
-
- void* hostpolicyLib = nullptr;
- char* mockHostpolicyPath = getenv("MOCK_HOSTPOLICY");
- if (mockHostpolicyPath)
- {
- hostpolicyLib = TryLoadHostPolicy(mockHostpolicyPath);
- if (hostpolicyLib == nullptr)
- {
- return -1;
- }
- }
-
- AddFilesFromDirectoryToTpaList(clrFilesAbsolutePath, tpaList);
-
- void* coreclrLib = dlopen(coreClrDllPath.c_str(), RTLD_NOW | RTLD_LOCAL);
- if (coreclrLib != nullptr)
- {
- coreclr_initialize_ptr initializeCoreCLR = (coreclr_initialize_ptr)dlsym(coreclrLib, "coreclr_initialize");
- coreclr_execute_assembly_ptr executeAssembly = (coreclr_execute_assembly_ptr)dlsym(coreclrLib, "coreclr_execute_assembly");
- coreclr_shutdown_2_ptr shutdownCoreCLR = (coreclr_shutdown_2_ptr)dlsym(coreclrLib, "coreclr_shutdown_2");
-
- if (initializeCoreCLR == nullptr)
- {
- fprintf(stderr, "Function coreclr_initialize not found in the libcoreclr.so\n");
- }
- else if (executeAssembly == nullptr)
- {
- fprintf(stderr, "Function coreclr_execute_assembly not found in the libcoreclr.so\n");
- }
- else if (shutdownCoreCLR == nullptr)
- {
- fprintf(stderr, "Function coreclr_shutdown_2 not found in the libcoreclr.so\n");
- }
- else
- {
- // Check whether we are enabling server GC (off by default)
- const char* useServerGc = GetEnvValueBoolean(serverGcVar);
-
- // Check Globalization Invariant mode (false by default)
- const char* globalizationInvariant = GetEnvValueBoolean(globalizationInvariantVar);
-
- // Allowed property names:
- // APPBASE
- // - The base path of the application from which the exe and other assemblies will be loaded
- //
- // TRUSTED_PLATFORM_ASSEMBLIES
- // - The list of complete paths to each of the fully trusted assemblies
- //
- // APP_PATHS
- // - The list of paths which will be probed by the assembly loader
- //
- // APP_NI_PATHS
- // - The list of additional paths that the assembly loader will probe for ngen images
- //
- // NATIVE_DLL_SEARCH_DIRECTORIES
- // - The list of paths that will be probed for native DLLs called by PInvoke
- //
- const char *propertyKeys[] = {
- "TRUSTED_PLATFORM_ASSEMBLIES",
- "APP_PATHS",
- "APP_NI_PATHS",
- "NATIVE_DLL_SEARCH_DIRECTORIES",
- "System.GC.Server",
- "System.Globalization.Invariant",
- };
- const char *propertyValues[] = {
- // TRUSTED_PLATFORM_ASSEMBLIES
- tpaList.c_str(),
- // APP_PATHS
- appPath.c_str(),
- // APP_NI_PATHS
- appPath.c_str(),
- // NATIVE_DLL_SEARCH_DIRECTORIES
- nativeDllSearchDirs.c_str(),
- // System.GC.Server
- useServerGc,
- // System.Globalization.Invariant
- globalizationInvariant,
- };
-
- void* hostHandle;
- unsigned int domainId;
-
- int st = initializeCoreCLR(
- currentExeAbsolutePath,
- "unixcorerun",
- sizeof(propertyKeys) / sizeof(propertyKeys[0]),
- propertyKeys,
- propertyValues,
- &hostHandle,
- &domainId);
-
- if (!SUCCEEDED(st))
- {
- fprintf(stderr, "coreclr_initialize failed - status: 0x%08x\n", st);
- exitCode = -1;
- }
- else
- {
- st = executeAssembly(
- hostHandle,
- domainId,
- managedAssemblyArgc,
- managedAssemblyArgv,
- managedAssemblyAbsolutePath,
- (unsigned int*)&exitCode);
-
- if (!SUCCEEDED(st))
- {
- fprintf(stderr, "coreclr_execute_assembly failed - status: 0x%08x\n", st);
- exitCode = -1;
- }
-
- int latchedExitCode = 0;
- st = shutdownCoreCLR(hostHandle, domainId, &latchedExitCode);
- if (!SUCCEEDED(st))
- {
- fprintf(stderr, "coreclr_shutdown failed - status: 0x%08x\n", st);
- exitCode = -1;
- }
-
- if (exitCode != -1)
- {
- exitCode = latchedExitCode;
- }
- }
- }
- }
- else
- {
- const char* error = dlerror();
- fprintf(stderr, "dlopen failed to open the libcoreclr.so with error %s\n", error);
- }
-
- if (hostpolicyLib)
- {
- if(dlclose(hostpolicyLib) != 0)
- {
- fprintf(stderr, "Warning - dlclose of mock hostpolicy failed.\n");
- }
- }
-
- return exitCode;
-}
diff --git a/netcore/corerun/coreruncommon.h b/netcore/corerun/coreruncommon.h
deleted file mode 100644
index fb7f6730b9d..00000000000
--- a/netcore/corerun/coreruncommon.h
+++ /dev/null
@@ -1,56 +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.
-
-#include <string>
-
-// Get the path to entrypoint executable
-bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable);
-
-// Get absolute path from the specified path.
-// Return true in case of a success, false otherwise.
-bool GetAbsolutePath(const char* path, std::string& absolutePath);
-
-// Get directory of the specified path.
-// Return true in case of a success, false otherwise.
-bool GetDirectory(const char* absolutePath, std::string& directory);
-
-//
-// Get the absolute path to use to locate libcoreclr.so and the CLR assemblies are stored. If clrFilesPath is provided,
-// this function will return the absolute path to it. Otherwise, the directory of the current executable is used.
-//
-// Return true in case of a success, false otherwise.
-//
-bool GetClrFilesAbsolutePath(const char* currentExePath, const char* clrFilesPath, std::string& clrFilesAbsolutePath);
-
-// Add all *.dll, *.ni.dll, *.exe, and *.ni.exe files from the specified directory to the tpaList string.
-void AddFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList);
-
-//
-// Execute the specified managed assembly.
-//
-// Parameters:
-// currentExePath - Path to the current executable
-// clrFilesAbsolutePath - Absolute path to the folder where the libcoreclr.so and CLR managed assemblies are stored
-// managedAssemblyPath - Path to the managed assembly to execute
-// managedAssemblyArgc - Number of arguments passed to the executed assembly
-// managedAssemblyArgv - Array of arguments passed to the executed assembly
-//
-// Returns:
-// ExitCode of the assembly
-//
-int ExecuteManagedAssembly(
- const char* currentExeAbsolutePath,
- const char* clrFilesAbsolutePath,
- const char* managedAssemblyAbsolutePath,
- int managedAssemblyArgc,
- const char** managedAssemblyArgv);
-
-
-#if defined(__APPLE__)
-#include <mach-o/dyld.h>
-static const char * const coreClrDll = "libcoreclr.dylib";
-#else
-static const char * const coreClrDll = "libcoreclr.so";
-#endif
-
diff --git a/netcore/gen-xunit-runner/Program.cs b/netcore/gen-xunit-runner/Program.cs
deleted file mode 100644
index 9eadb61df7c..00000000000
--- a/netcore/gen-xunit-runner/Program.cs
+++ /dev/null
@@ -1,467 +0,0 @@
-//
-// NOTES:
-// - If xunit can't laod a trait discoverer assembly, it silently ignores the error.
-// - the RemoteTestExecutor code used by corefx only seems to work if
-// the app is executed from the binary dir using dotnet ./<dllname>.
-// If ran using dotnet run, it seems to invoke itself instead of
-// RemoteExecutorConsoleApp.exe.
-// If ran using dotnet bin/.../<dllname>, it fails with:
-// No executable found matching command "dotnet-<dir>/RemoteExecutorConsoleApp.exe"
-//
-
-using System;
-using System.Runtime.Loader;
-using System.Linq;
-using System.Threading;
-using System.IO;
-using System.Reflection;
-using System.Collections;
-using System.Collections.Generic;
-using Xunit;
-using Xunit.Sdk;
-using Xunit.Abstractions;
-using Xunit.ConsoleClient;
-
-using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis;
-
-class MsgSink : IMessageSink {
-
- public bool OnMessage (IMessageSinkMessage message) {
- Console.WriteLine (((Xunit.Sdk.DiagnosticMessage)message).Message);
- return true;
- }
-
- public bool OnMessageWithTypes (IMessageSinkMessage message, HashSet<string> messageTypes) {
- Console.WriteLine ("m2");
- return true;
- }
-}
-
-class Program
-{
- static int nskipped = 0;
-
- // The template for the whole progeam
- const string runner_template = @"
-using System;
-using System.Reflection;
-
-public class RunTests
-{
- static int nrun = 0;
- static int nfailed = 0;
-
- public static void Run()
- {
- }
-
- public static int Main()
- {
- Run ();
- Console.WriteLine(""RUN: "" + nrun);
- Console.WriteLine(""FAILURES: "" + nfailed);
- Console.WriteLine(""SKIPPED: "" + #NSKIPPED#);
- if (nfailed == 0)
- return 0;
- else
- return 1;
- }
-}
-";
- // Template for calling 1 testcase instance
- // Only the code block matters
- const string case_template = @"
-class Foo { void Run () {
-Console.WriteLine(""#MSG#"");
-nrun = (nrun + #NRUN#);
-try {
-unchecked {
- CALL();
-}
- }
- catch (System.Exception ex) {
- nfailed = (nfailed + 1);
- Console.WriteLine(""FAILED: "" + ex);
- }
-}}
-";
-
- static string GetTypeName (Type t)
- {
- if (t == typeof (void))
- return "void";
- if (t.IsNested)
- return t.DeclaringType.FullName + "." + t.Name;
- else
- return t.FullName;
- }
-
- static void ComputeTraits (Assembly assembly, XunitTestCase tc)
- {
- // Traits are not set because of some assembly loading problems i.e. Assembly.Load (new AssemblyName ("Microsoft.DotNet.XUnitExtensions")) fails
- // So load them manually
- foreach (ReflectionAttributeInfo attr in ((ReflectionMethodInfo)tc.Method).GetCustomAttributes (typeof (ITraitAttribute))) {
- var discovererAttr = attr.GetCustomAttributes (typeof (TraitDiscovererAttribute)).FirstOrDefault();
- if (discovererAttr != null) {
- var discoverer_args = discovererAttr.GetConstructorArguments().Cast<string>().ToList();
- var disc_assembly = Assembly.LoadFrom (Path.Combine (Path.GetDirectoryName (assembly.Location), discoverer_args [1]) + ".dll");
- var disc_type = disc_assembly.GetType (discoverer_args [0]);
- var disc_obj = (ITraitDiscoverer)Activator.CreateInstance (disc_type);
- foreach (var trait in disc_obj.GetTraits (attr)) {
- if (!tc.Traits.ContainsKey (trait.Key))
- tc.Traits [trait.Key] = new List<string> ();
- tc.Traits [trait.Key].Add (trait.Value);
- }
- }
- }
- }
-
- class TcCase {
- public object[] Values;
- public MethodInfo MemberDataMethod;
- }
-
- static ExpressionSyntax EncodeValue (object val, Type expectedType)
- {
- ExpressionSyntax result = null;
-
- if (val == null)
- return LiteralExpression (SyntaxKind.NullLiteralExpression);
-
- if (val is Enum) {
- TypeCode typeCode = Convert.GetTypeCode (val);
- ExpressionSyntax lit;
-
- long l = 0;
- ulong ul = 0;
- if (typeCode == TypeCode.UInt64) {
- ul = UInt64.Parse (((Enum)val).ToString ("D"));
- lit = LiteralExpression (SyntaxKind.NumericLiteralExpression, Literal (ul));
- } else {
- l = Int64.Parse (((Enum)val).ToString ("D"));
- if (l < 0)
- //lit = ParenthesizedExpression (PrefixUnaryExpression (SyntaxKind.UnaryMinusExpression, LiteralExpression (SyntaxKind.NumericLiteralExpression, Literal (l))));
- lit = CastExpression (PredefinedType (Token (SyntaxKind.LongKeyword)), LiteralExpression (SyntaxKind.NumericLiteralExpression, Literal ((ulong)l)));
- else
- lit = LiteralExpression (SyntaxKind.NumericLiteralExpression, Literal (l));
- }
- result = CastExpression (IdentifierName (GetTypeName (val.GetType ())), lit);
- return result;
- }
-
- if (val is Type) {
- Type t = (Type)val;
- if (t.IsGenericType)
- return null;
- return TypeOfExpression (IdentifierName (GetTypeName ((Type)val)));
- }
-
- ExpressionSyntax LiteralWithCast (string type, SyntaxToken literal) =>
- CastExpression(IdentifierName (type), LiteralExpression (SyntaxKind.NumericLiteralExpression, literal));
-
- switch (Type.GetTypeCode (val.GetType ())) {
- case TypeCode.Boolean:
- if ((bool)val)
- result = LiteralExpression (SyntaxKind.TrueLiteralExpression);
- else
- result = LiteralExpression (SyntaxKind.FalseLiteralExpression);
- break;
- case TypeCode.Char:
- result = LiteralWithCast ("char", Literal ((char)val));
- break;
- case TypeCode.SByte:
- result = LiteralWithCast ("sbyte", Literal ((sbyte)val));
- break;
- case TypeCode.Byte:
- result = LiteralWithCast ("byte", Literal ((byte)val));
- break;
- case TypeCode.Int16:
- result = LiteralWithCast ("short", Literal ((short)val));
- break;
- case TypeCode.UInt16:
- result = LiteralWithCast ("ushort", Literal ((ushort)val));
- break;
- case TypeCode.Int32:
- result = LiteralExpression (SyntaxKind.NumericLiteralExpression, Literal ((int)val));
- break;
- case TypeCode.UInt32:
- result = LiteralWithCast ("uint", Literal ((uint)val));
- break;
- case TypeCode.Int64:
- result = LiteralExpression (SyntaxKind.NumericLiteralExpression, Literal ((long)val));
- break;
- case TypeCode.UInt64:
- result = LiteralExpression (SyntaxKind.NumericLiteralExpression, Literal ((ulong)val));
- break;
- case TypeCode.Decimal:
- result = LiteralExpression (SyntaxKind.NumericLiteralExpression, Literal ((decimal)val));
- break;
- case TypeCode.Single:
- result = LiteralExpression (SyntaxKind.NumericLiteralExpression, Literal ((float)val));
- break;
- case TypeCode.Double:
- result = LiteralExpression (SyntaxKind.NumericLiteralExpression, Literal ((double)val));
- break;
- case TypeCode.String:
- result = LiteralExpression (SyntaxKind.NumericLiteralExpression, Literal ((string)val));
- break;
- }
-
- if (val is Array) {
- var arr = (IEnumerable)val;
-
- var etype = val.GetType ().GetElementType ();
- var type_node = ArrayType (IdentifierName (etype.FullName))
- .WithRankSpecifiers(
- SingletonList<ArrayRankSpecifierSyntax>(
- ArrayRankSpecifier(
- SingletonSeparatedList<ExpressionSyntax>(
- OmittedArraySizeExpression()))));
- var elems = new List<ExpressionSyntax> ();
- foreach (var elem in arr) {
- var encoded = EncodeValue (elem, null);
- if (encoded == null)
- return null;
- elems.Add (encoded);
- }
- result = ArrayCreationExpression (type_node).WithInitializer (InitializerExpression (SyntaxKind.ArrayInitializerExpression, SeparatedList<ExpressionSyntax> (elems.ToArray ())));
- return result;
- }
-
- if (val is Guid guid) {
- var argumentList = SeparatedList (new[] { Argument(LiteralExpression (SyntaxKind.StringLiteralExpression, Literal (guid.ToString ()))) });
- var guidParse = MemberAccessExpression (SyntaxKind.SimpleMemberAccessExpression, IdentifierName ("Guid"), IdentifierName ("Parse"));
- result = InvocationExpression (guidParse, ArgumentList (argumentList));
- }
-
- if (val is IntPtr ptr) {
- result = LiteralWithCast (nameof (IntPtr), Literal ((ulong) ptr));
- }
-
- if (val is UIntPtr uptr) {
- result = LiteralWithCast (nameof (UIntPtr), Literal ((ulong) uptr));
- }
-
- if (result == null) {
- Console.WriteLine ($"Unhandled value: {val} ({val?.GetType()})");
- return null;
- }
-
- if (val != null && expectedType != null && Nullable.GetUnderlyingType(expectedType) == null && val.GetType () != expectedType && !expectedType.IsGenericParameter)
- result = CastExpression (IdentifierName (GetTypeName (expectedType)), ParenthesizedExpression (result));
- return result;
- }
-
- static int Main (string[] args)
- {
- if (args.Length < 3) {
- Console.WriteLine ("Usage: <out-dir> <corefx dir> <test assembly filename> <xunit console options>");
- return 1;
- }
-
- var testAssemblyName = Path.GetFileNameWithoutExtension (args [2]);
- var testAssemblyFull = Path.GetFullPath (args[2]);
- var outdir_name = Path.Combine (args [0], testAssemblyName);
- var sdkdir = args [1] + "/artifacts/bin/runtime/netcoreapp-OSX-Debug-x64";
- args = args.Skip (2).ToArray ();
- // Response file support
- var extra_args = new List<string> ();
- for (int i = 0; i < args.Length; ++i) {
- var arg = args [i];
- if (arg [0] == '@') {
- foreach (var line in File.ReadAllLines (arg.Substring (1))) {
- if (line.Length == 0 || line [0] == '#')
- continue;
- extra_args.AddRange (line.Split (' '));
- }
- args [i] = "";
- }
- }
- args = args.Where (s => s != String.Empty).Concat (extra_args).ToArray ();
-
- // Despite a lot of effort, couldn't get dotnet to load these assemblies from the sdk dir, so copy them to our binary dir
-// File.Copy ($"{sdkdir}/Microsoft.DotNet.PlatformAbstractions.dll", AppContext.BaseDirectory, true);
- File.Copy ($"{sdkdir}/CoreFx.Private.TestUtilities.dll", AppContext.BaseDirectory, true);
- File.Copy ($"{sdkdir}/Microsoft.DotNet.XUnitExtensions.dll", AppContext.BaseDirectory, true);
-
- var cmdline = CommandLine.Parse (args);
-
- // Ditto
- File.Copy (cmdline.Project.Assemblies.First ().AssemblyFilename, AppContext.BaseDirectory, true);
-
- var assembly = Assembly.LoadFrom (Path.Combine (AppContext.BaseDirectory, Path.GetFileName (cmdline.Project.Assemblies.First ().AssemblyFilename)));
-
- var msg_sink = new MsgSink ();
- var xunit2 = new Xunit2Discoverer (AppDomainSupport.Denied, new NullSourceInformationProvider (), new ReflectionAssemblyInfo (assembly), null, null, msg_sink);
- var sink = new TestDiscoverySink ();
- var config = new TestAssemblyConfiguration () { DiagnosticMessages = true, InternalDiagnosticMessages = true, PreEnumerateTheories = false };
- xunit2.Find (false, sink, TestFrameworkOptions.ForDiscovery (config));
- sink.Finished.WaitOne ();
-
- foreach (XunitTestCase tc in sink.TestCases)
- ComputeTraits (assembly, tc);
-
- // Compute testcase data
- var tc_data = new Dictionary<XunitTestCase, List<TcCase>> ();
- foreach (XunitTestCase tc in sink.TestCases) {
- var m = ((ReflectionMethodInfo)tc.Method).MethodInfo;
- var t = m.ReflectedType;
-
- var cases = new List<TcCase> ();
-
- if (m.GetParameters ().Length > 0) {
- foreach (var cattr in m.GetCustomAttributes (true))
- if (cattr is InlineDataAttribute) {
- var data = ((InlineDataAttribute)cattr).GetData (null).First ();
- if (data == null)
- data = new object [m.GetParameters ().Length];
- if (data.Length != m.GetParameters ().Length)
- throw new Exception ();
-
- bool unhandled = false;
- foreach (var val in data) {
- if (val is float || val is double)
- unhandled = true;
- if (val is Type) {
- var type = val as Type;
- if (!type.IsVisible)
- unhandled = true;
- }
- if (val is Enum) {
- if (!val.GetType ().IsPublic)
- unhandled = true;
- }
- }
- if (!unhandled)
- cases.Add (new TcCase () { Values = data });
- } else if (cattr is MemberDataAttribute memberData && memberData.Parameters.Length == 0) {
- MethodInfo testDataMethod = m.DeclaringType.GetMethod (memberData.MemberName);
- if (testDataMethod == null)
- continue;
- cases.Add (new TcCase { MemberDataMethod = testDataMethod });
- }
- } else {
- cases.Add (new TcCase ());
- }
- tc_data [tc] = cases;
- }
-
- var filters = cmdline.Project.Filters;
-
- //
- // Generate code using the roslyn syntax apis
- // Creating syntax nodes one-by-one is very cumbersome, so use
- // CSharpSyntaxTree.ParseText () to create them and ReplaceNode () to insert them into syntax trees.
- //
- var blocks = new List<BlockSyntax> ();
- foreach (XunitTestCase tc in sink.TestCases) {
- var m = ((ReflectionMethodInfo)tc.Method).MethodInfo;
- //Console.WriteLine ("" + m.ReflectedType + " " + m + " " + (tc.TestMethodArguments == null));
- var t = m.ReflectedType;
- if (t.IsGenericType) {
- nskipped ++;
- continue;
- }
- if (!filters.Filter (tc)) {
- nskipped ++;
- continue;
- }
-
- var cases = tc_data [tc];
-
- int caseindex = 0;
- foreach (var test in cases) {
- string typename = GetTypeName (t);
- string msg;
-
- if (cases.Count > 1)
- msg = $"{typename}.{m.Name}[{caseindex}] ...";
- else
- msg = $"{typename}.{m.Name} ...";
- caseindex ++;
-
- var block = ParseText<BlockSyntax> (case_template
- .Replace ("#MSG#", msg)
- .Replace ("#NRUN#", test.MemberDataMethod == null ? "1" : ((IEnumerable) test.MemberDataMethod.Invoke (null, null)).Cast<object> ().Count ().ToString ()));
- // Obtain the node for the CALL () line
- var try_body_node = block.DescendantNodes ().OfType<ExpressionStatementSyntax> ().Skip (2).First ().Parent;
- // Replace with the generated call code
- var stmts = GenerateTcCall (t, test, m);
- blocks.Add (block.ReplaceNode (try_body_node, Block (stmts.ToArray ())));
- }
- }
-
- var cu = CSharpSyntaxTree.ParseText (runner_template.Replace ("#NSKIPPED#", nskipped.ToString ())).GetRoot ();
-
- // Replace the body of the Run () method with the generated body
- var run_body = cu.DescendantNodes ().OfType<MethodDeclarationSyntax> ().First ().DescendantNodes ().OfType<BlockSyntax> ().First ();
- cu = cu.ReplaceNode (run_body, Block (blocks.ToArray ()));
-
- // Create runner.cs
- Directory.CreateDirectory (outdir_name);
- var outfile_name = Path.Combine (outdir_name, "runner.cs");
- File.WriteAllText (outfile_name, cu.NormalizeWhitespace ().ToString ());
-
- // Generate csproj file
- var csproj_template = File.ReadAllText ("gen-test.csproj.template");
- csproj_template = csproj_template.Replace ("#XUNIT_LOCATION#", sdkdir);
- csproj_template = csproj_template.Replace ("#TEST_ASSEMBLY#", testAssemblyName);
- csproj_template = csproj_template.Replace ("#TEST_ASSEMBLY_LOCATION#", testAssemblyFull);
-
- File.WriteAllText (Path.Combine (outdir_name, testAssemblyName + "-runner.csproj"), csproj_template);
-
- return 0;
- }
-
- static TSyntax ParseText<TSyntax> (string code)
- {
- return CSharpSyntaxTree.ParseText (code).GetRoot().DescendantNodes().OfType<TSyntax> ().First ();
- }
-
- static List<StatementSyntax> GenerateTcCall (Type t, TcCase test, MethodInfo m) {
- var stmts = new List<StatementSyntax> ();
- if (!m.IsStatic) {
- var newobj_template = @"class Foo { void Run () { var o = new #CLASS# (); }}";
-
- // FIXME: Disposable
- stmts.Add (ParseText<LocalDeclarationStatementSyntax> (newobj_template.Replace ("#CLASS#", t.FullName)));
- }
- if (!m.IsPublic) {
- // FIXME:
- nskipped ++;
- return stmts;
- }
- string callstr;
- StatementSyntax node = null;
-
- var tname = GetTypeName (t);
- if (test.MemberDataMethod != null) {
- callstr = $"class Foo {{ void Run () {{ foreach (var row in {tname}.{test.MemberDataMethod.Name} ()) typeof ({tname}).GetMethod (\"{m.Name}\").Invoke ({(m.IsStatic ? "null" : "o")}, (object []) row); }}";
- node = ParseText<StatementSyntax> (callstr);
- } else {
- callstr = $"class Foo {{ void Run () {{ {(m.IsStatic ? tname : "o")}.{m.Name} (); }}";
- node = ParseText<ExpressionStatementSyntax> (callstr);
- }
-
- if (test.Values != null && test.MemberDataMethod == null) {
- var parameters = m.GetParameters ();
- var arg_nodes = new List<ArgumentSyntax> ();
- for (var index = 0; index < test.Values.Length; index++) {
- var val_node = EncodeValue (test.Values [index], parameters [index].ParameterType);
- if (val_node == null) {
- nskipped ++;
- return stmts;
- }
- arg_nodes.Add (Argument (val_node));
- }
- var args_node = node.DescendantNodes ().OfType<ArgumentListSyntax> ().First ();
- node = node.ReplaceNode (args_node, ArgumentList (SeparatedList (arg_nodes.ToArray ())));
- }
-
- stmts.Add (node);
- return stmts;
- }
-}
diff --git a/netcore/gen-xunit-runner/README.md b/netcore/gen-xunit-runner/README.md
deleted file mode 100644
index 145065b09ac..00000000000
--- a/netcore/gen-xunit-runner/README.md
+++ /dev/null
@@ -1,46 +0,0 @@
-# Introduction
-
-This is a small netcore app to convert a corefx test assembly into a console app which runs the tests without any xunit framework code.
-
-# Usage
-
-## Project Runner Generator
-
-```
-dotnet run ../output ~/git/corefx/ ~/git/corefx/artifacts/bin/System.Runtime.Tests/netcoreapp-Unix-Debug/System.Runtime.Tests.dll -notrait category=nonosxtests -notrait category=failing -notrait category=Outerloop -stoponfail
-```
-
-There is support for response files, i.e.
-```
-dotnet run ../output ~/git/corefx/ ~/git/corefx/artifacts/bin/System.Runtime.Tests/netcoreapp-Unix-Debug/System.Runtime.Tests.dll @excludes.rsp
-```
-
-
-## Tests Runner Build
-
-Go to for example `../output` from the example above and do
-
-```
-dotnet build
-```
-
-## Tests Execution
-
-This assumes you have sucesfully ran HelloWorld sample before
-
-```
-../../sample/dotnet --fx-version "3.0.0-preview-27408-5" bin/Debug/netcoreapp3.0/{name-of-the-test-dll}.dll
-```
-
-The test dll will usually be in the format `System.Runtime.Tests-runner.dll`
-
-
-# Notes
-
-- If xunit can't load a trait discoverer assembly, it silently ignores the error.
-- The RemoteTestExecutor code used by corefx only seems to work if
-the app is executed from the binary dir using dotnet ./<dllname>.
-If ran using dotnet run, it seems to invoke itself instead of
-RemoteExecutorConsoleApp.exe.
-If ran using dotnet bin/.../<dllname>, it fails with:
-No executable found matching command "dotnet-<dir>/RemoteExecutorConsoleApp.exe"
diff --git a/netcore/gen-xunit-runner/gen-test.csproj.template b/netcore/gen-xunit-runner/gen-test.csproj.template
deleted file mode 100644
index 8c687ecafb6..00000000000
--- a/netcore/gen-xunit-runner/gen-test.csproj.template
+++ /dev/null
@@ -1,36 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <TargetFramework>netcoreapp3.0</TargetFramework>
- </PropertyGroup>
-
- <ItemGroup>
- <Reference Include="xunit.core">
- <HintPath>#XUNIT_LOCATION#/xunit.core.dll</HintPath>
- </Reference>
-
- <Reference Include="xunit.assert">
- <HintPath>#XUNIT_LOCATION#/xunit.assert.dll</HintPath>
- </Reference>
-
- <Reference Include="CoreFx.Private.TestUtilities">
- <HintPath>#XUNIT_LOCATION#/CoreFx.Private.TestUtilities.dll</HintPath>
- </Reference>
-
- <Reference Include="System.Runtime.CompilerServices.Unsafe">
- <HintPath>#XUNIT_LOCATION#/System.Runtime.CompilerServices.Unsafe.dll</HintPath>
- </Reference>
-
- <Reference Include="Microsoft.DotNet.XUnitExtensions">
- <HintPath>#XUNIT_LOCATION#/Microsoft.DotNet.XUnitExtensions.dll</HintPath>
- </Reference>
- </ItemGroup>
-
- <ItemGroup>
- <Reference Include="#TEST_ASSEMBLY#">
- <HintPath>#TEST_ASSEMBLY_LOCATION#</HintPath>
- </Reference>
- </ItemGroup>
-
-</Project>
diff --git a/netcore/gen-xunit-runner/gen-xunit-runner.csproj b/netcore/gen-xunit-runner/gen-xunit-runner.csproj
deleted file mode 100644
index db5d7ffbac9..00000000000
--- a/netcore/gen-xunit-runner/gen-xunit-runner.csproj
+++ /dev/null
@@ -1,22 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <TargetFramework>netcoreapp3.0</TargetFramework>
- <EnableDefaultItems>false</EnableDefaultItems>
- </PropertyGroup>
-
- <ItemGroup>
- <Compile Include="Program.cs" />
- </ItemGroup>
-
- <ItemGroup>
- <PackageReference Include="Microsoft.CodeAnalysis.Compilers" Version="2.10.0" />
- <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />
- <PackageReference Include="xunit.abstractions" Version="2.0.3" />
- <PackageReference Include="xunit.console" Version="2.4.1" />
- <PackageReference Include="xunit.core" Version="2.4.1" />
- <PackageReference Include="xunit.runner.utility" Version="2.4.1" />
- </ItemGroup>
-
-</Project>
diff --git a/netcore/init-tools.ps1 b/netcore/init-tools.ps1
deleted file mode 100644
index e440ec87d1b..00000000000
--- a/netcore/init-tools.ps1
+++ /dev/null
@@ -1,5 +0,0 @@
-function Write-Host {}
-
-. "..\eng\common\tools.ps1"
-
-InitializeDotNetCli $true \ No newline at end of file
diff --git a/netcore/init-tools.sh b/netcore/init-tools.sh
deleted file mode 100755
index b544b3fad83..00000000000
--- a/netcore/init-tools.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env bash
-
-# always ignore system dotnet
-export use_installed_dotnet_cli=false
-
-. "../eng/common/tools.sh"
-
-InitializeDotNetCli true
-
-which dotnet \ No newline at end of file
diff --git a/netcore/metapackage-llvm.nuspec b/netcore/metapackage-llvm.nuspec
deleted file mode 100644
index e1babad482b..00000000000
--- a/netcore/metapackage-llvm.nuspec
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
- <metadata>
- <id>Microsoft.NETCore.Runtime.MonoLLVM</id>
- <version>$VERSION$</version>
- <description>Internal implementation package not meant for direct consumption. Please do not reference directly.
-The Mono runtime, and the base library, called mscorlib. It includes the garbage collector, JIT compiler, base .NET data types and many low-level classes.</description>
- <authors>Microsoft</authors>
- <copyright>(c) Microsoft Corporation. All rights reserved.</copyright>
- <projectUrl>https://www.mono-project.com/</projectUrl>
- <licenseUrl>https://github.com/mono/mono/blob/master/LICENSE</licenseUrl>
- <dependencies>
- <dependency id="runtime.linux-x64.Microsoft.NETCore.Runtime.MonoLLVM" version="$VERSION$" />
- </dependencies>
- </metadata>
- <files>
- </files>
-</package>
diff --git a/netcore/metapackage.nuspec b/netcore/metapackage.nuspec
deleted file mode 100644
index 55fce5b0f21..00000000000
--- a/netcore/metapackage.nuspec
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
- <metadata>
- <id>Microsoft.NETCore.Runtime.Mono</id>
- <version>$VERSION$</version>
- <description>Internal implementation package not meant for direct consumption. Please do not reference directly.
-The Mono runtime, and the base library, called mscorlib. It includes the garbage collector, JIT compiler, base .NET data types and many low-level classes.</description>
- <authors>Microsoft</authors>
- <copyright>(c) Microsoft Corporation. All rights reserved.</copyright>
- <projectUrl>https://www.mono-project.com/</projectUrl>
- <licenseUrl>https://github.com/mono/mono/blob/master/LICENSE</licenseUrl>
- <dependencies>
- <dependency id="runtime.win-x64.Microsoft.NETCore.Runtime.Mono" version="$VERSION$" />
- <dependency id="runtime.osx-x64.Microsoft.NETCore.Runtime.Mono" version="$VERSION$" />
- <dependency id="runtime.linux-x64.Microsoft.NETCore.Runtime.Mono" version="$VERSION$" />
- </dependencies>
- </metadata>
- <files>
- </files>
-</package>
diff --git a/netcore/roslyn-restore.csproj b/netcore/roslyn-restore.csproj
deleted file mode 100644
index 84680ef314a..00000000000
--- a/netcore/roslyn-restore.csproj
+++ /dev/null
@@ -1,13 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Library</OutputType>
- <TargetFramework>netcoreapp3.0</TargetFramework>
- <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
- <EnableDefaultItems>false</EnableDefaultItems>
- <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
- <SkipImportRoslynProps>true</SkipImportRoslynProps>
- </PropertyGroup>
- <ItemGroup>
- <PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="$(RoslynVersion)" />
- </ItemGroup>
-</Project>
diff --git a/netcore/run-tests-corefx.ps1 b/netcore/run-tests-corefx.ps1
deleted file mode 100644
index 91e79452cd2..00000000000
--- a/netcore/run-tests-corefx.ps1
+++ /dev/null
@@ -1,120 +0,0 @@
-[CmdletBinding(PositionalBinding=$false)]
-Param(
- [string]$fxversion,
- [int]$timeout = -1,
- [string]$corefxtests = "*",
- [switch][Alias('h')]$help
-)
-
-function Print-Usage() {
- Write-Host "Common settings:"
- Write-Host " -fxversion Version passed to dotnet.exe"
- Write-Host " -timeout Individual test timeout (default -1)"
- Write-Host " -corefxtests CoreFx test to run, all or individual (defaul *)"
- Write-Host " -help Print help and exit (short: -h)"
- Write-Host ""
-
- Write-Host "The above arguments can be shortened as much as to be unambiguous."
-}
-
-function RunCoreFxTest($_netcore_version, $_timeout, $_testname, $_counter, $_tests_count) {
-
- Write-Host ""
- Write-Host "***************** $($_testname) $($_counter) / $($_tests_count) *********************"
- Copy-Item -Path "$PSScriptRoot\corefx\restore\corefx-restore.deps.json" -Destination "$PSScriptRoot\corefx\tests\extracted\$_testname\$_testname.deps.json" -Force
- Copy-Item -Path "$PSScriptRoot\corefx\restore\corefx-restore.runtimeconfig.dev.json" -Destination "$PSScriptRoot\corefx\tests\extracted\$_testname\$_testname.runtimeconfig.dev.json" -Force
- Copy-Item -Path "$PSScriptRoot\corefx\restore\corefx-restore.dll" -Destination "$PSScriptRoot\corefx\tests\extracted\$_testname\corefx-restore.dll" -Force
- (Get-Content "$PSScriptRoot\corefx\tests\extracted\$_testname\$_testname.runtimeconfig.json").replace("""5.0.0""", """$_netcore_version""") | Set-Content "$PSScriptRoot\corefx\tests\extracted\$_testname\$_testname.runtimeconfig.json"
-
- if ((Test-Path "$PSScriptRoot\corefx\tests\TestResult-$_testname.html" -PathType Leaf)) {
- Remove-Item -Path "$PSScriptRoot\corefx\tests\TestResult-$_testname.html" -Force
- }
-
- if ((Test-Path "$PSScriptRoot\corefx\tests\TestResult-$_testname-netcore-xunit.xml" -PathType Leaf)) {
- Remove-Item -Path "$PSScriptRoot\corefx\tests\TestResult-$_testname-netcore-xunit.xml" -Force
- }
-
- $_process_path = "$PSScriptRoot\dotnet.exe"
- $_argument_list = "exec"
- $_argument_list = $_argument_list + " --runtimeconfig $_testname.runtimeconfig.json"
- $_argument_list = $_argument_list + " --additional-deps $_testname.deps.json"
- $_argument_list = $_argument_list + " --fx-version ""$_netcore_version"""
- $_argument_list = $_argument_list + " xunit.console.dll $_testname.dll"
- $_argument_list = $_argument_list + " -html ""$PSScriptRoot\corefx\tests\TestResult-$_testname.html"""
- $_argument_list = $_argument_list + " -xml ""$PSScriptRoot\corefx\tests\TestResult-$_testname-netcore-xunit.xml"""
- $_argument_list = $_argument_list + " -notrait category=nonwindowstests ""@$PSScriptRoot\CoreFX.issues_windows.rsp"" ""@$PSScriptRoot\CoreFX.issues.rsp"""
-
- $_process = Start-Process -filePath $_process_path -ArgumentList $_argument_list -workingdirectory "$PSScriptRoot\corefx\tests\extracted\$_testname" -PassThru -NoNewWindow
- if ($_timeout -eq -1) {
- Wait-Process -InputObject $_process
- } else {
- Wait-Process -InputObject $_process -Timeout $_timeout -ErrorAction SilentlyContinue -ErrorVariable _process_error
-
- if ($_process_error) {
- $_process | kill
- Write-Host "Error running $_testname, timeout"
- return 1
- }
- }
-
- $_process_exit = $_process.ExitCode
- if ($_process_exit -ne 0) {
- Write-Host "Error running $_testname, ExitCode=$($_process_exit)"
- return $_process_exit
- }
-
- # Check for xunit XML file, if missing, treat as failure.
- if (-Not (Test-Path "$PSScriptRoot\corefx\tests\TestResult-$_testname-netcore-xunit.xml" -PathType Leaf)) {
- Write-Host "Error running $_testname, missing xunit XML file"
- return 1
- }
-
- return 0
-}
-
-$exit_code = 0
-if ($help) {
- Print-Usage
- exit $exit_code
-}
-
-if ($corefxtests -eq "*") {
- if ((Test-Path "$PSScriptRoot\.failures" -PathType Leaf)) {
- Remove-Item -Path "$PSScriptRoot\.failures" -Force
- }
-
- $tests = Get-ChildItem "$PSScriptRoot\corefx\tests\extracted\"
- $tests_count = $tests.Count
- $counter = 0
- for ($i=0; $i -lt $tests_count; $i++) {
- $counter=$counter + 1
- $testname=$tests[$i].Name
-
- $result = RunCoreFxTest $fxversion $timeout $testname $counter $tests_count
- if ($result -ne 0) {
- Add-Content -Path "$PSScriptRoot\.failures" -Value "$testname"
- $exit_code = 1
- }
- }
- if (Get-Command "python.exe" -ErrorAction SilentlyContinue) {
- python.exe "$PSScriptRoot\xunit-summary.py" "$PSScriptRoot\corefx\tests"
- } else {
- Write-Host "Couldn't locate python.exe, skiping xunit-summary.py"
- }
- if ((Test-Path "$PSScriptRoot\.failures" -PathType Leaf)) {
- Write-Host ""
- Write-Host "Failures in test suites:"
- type "$PSScriptRoot\.failures"
- Write-Host ""
- $exit_code = 1
- }
-} else {
- if (-Not (Test-Path "$PSScriptRoot\corefx\tests\extracted\$corefxtests" -PathType Container)) {
- Write-Host "Uknown test: $corefxtests"
- $exit_code = 1
- } else {
- $exit_code = RunCoreFxTest $fxversion $timeout $corefxtests 1 1
- }
-}
-
-exit $exit_code \ No newline at end of file
diff --git a/netcore/runtime-llvm.nuspec b/netcore/runtime-llvm.nuspec
deleted file mode 100644
index 09395805071..00000000000
--- a/netcore/runtime-llvm.nuspec
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
- <metadata>
- <id>runtime.$RID$.Microsoft.NETCore.Runtime.MonoLLVM</id>
- <version>$VERSION$</version>
- <description>Internal implementation package not meant for direct consumption. Please do not reference directly.
-The Mono runtime, and the base library, called mscorlib. It includes the garbage collector, JIT compiler, base .NET data types and many low-level classes.</description>
- <authors>Microsoft</authors>
- <copyright>(c) Microsoft Corporation. All rights reserved.</copyright>
- <projectUrl>https://www.mono-project.com/</projectUrl>
- <licenseUrl>https://github.com/mono/mono/blob/master/LICENSE</licenseUrl>
- </metadata>
- <files>
- <file src="System.Private.CoreLib\bin\$COREARCH$\System.Private.CoreLib.dll" target="runtimes\$RID$\native" />
- <file src="..\mono\mini\.libs\$PLATFORM_AOT_PREFIX$monosgen-2.0$PLATFORM_AOT_SUFFIX$" target="runtimes\$RID$\native" />
- </files>
-</package>
diff --git a/netcore/runtime.nuspec b/netcore/runtime.nuspec
deleted file mode 100644
index b351c67074a..00000000000
--- a/netcore/runtime.nuspec
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
- <metadata>
- <id>runtime.$RID$.Microsoft.NETCore.Runtime.Mono</id>
- <version>$VERSION$</version>
- <description>Internal implementation package not meant for direct consumption. Please do not reference directly.
-The Mono runtime, and the base library, called mscorlib. It includes the garbage collector, JIT compiler, base .NET data types and many low-level classes.</description>
- <authors>Microsoft</authors>
- <copyright>(c) Microsoft Corporation. All rights reserved.</copyright>
- <projectUrl>https://www.mono-project.com/</projectUrl>
- <licenseUrl>https://github.com/mono/mono/blob/master/LICENSE</licenseUrl>
- </metadata>
- <files>
- <file src="System.Private.CoreLib\bin\$COREARCH$\System.Private.CoreLib.dll" target="runtimes\$RID$\native" />
- <file src="..\mono\mini\.libs\$PLATFORM_AOT_PREFIX$monosgen-2.0$PLATFORM_AOT_SUFFIX$" target="runtimes\$RID$\native" />
- </files>
-</package>
diff --git a/netcore/sample/AspNetCore/AspNetCore.csproj b/netcore/sample/AspNetCore/AspNetCore.csproj
deleted file mode 100644
index bb9ffced156..00000000000
--- a/netcore/sample/AspNetCore/AspNetCore.csproj
+++ /dev/null
@@ -1,7 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk.Web">
-
- <PropertyGroup>
- <TargetFramework>netcoreapp3.0</TargetFramework>
- </PropertyGroup>
-
-</Project>
diff --git a/netcore/sample/AspNetCore/Program.cs b/netcore/sample/AspNetCore/Program.cs
deleted file mode 100644
index e5a1c706ded..00000000000
--- a/netcore/sample/AspNetCore/Program.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Hosting;
-using Microsoft.Extensions.Logging;
-
-namespace AspNetCore
-{
- public class Program
- {
- public static void Main(string[] args)
- {
- CreateHostBuilder(args).Build().Run();
- }
-
- public static IHostBuilder CreateHostBuilder(string[] args) =>
- Host.CreateDefaultBuilder(args)
- .ConfigureWebHostDefaults(webBuilder =>
- {
- webBuilder.UseStartup<Startup>();
- });
- }
-}
diff --git a/netcore/sample/AspNetCore/Properties/launchSettings.json b/netcore/sample/AspNetCore/Properties/launchSettings.json
deleted file mode 100644
index 592c5908f22..00000000000
--- a/netcore/sample/AspNetCore/Properties/launchSettings.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "iisSettings": {
- "windowsAuthentication": false,
- "anonymousAuthentication": true,
- "iisExpress": {
- "applicationUrl": "http://localhost:35206",
- "sslPort": 44375
- }
- },
- "profiles": {
- "IIS Express": {
- "commandName": "IISExpress",
- "launchBrowser": true,
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
- }
- },
- "AspNetCore": {
- "commandName": "Project",
- "launchBrowser": true,
- "applicationUrl": "https://localhost:5001;http://localhost:5000",
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
- }
- }
- }
-} \ No newline at end of file
diff --git a/netcore/sample/AspNetCore/Startup.cs b/netcore/sample/AspNetCore/Startup.cs
deleted file mode 100644
index 5aacdd6208c..00000000000
--- a/netcore/sample/AspNetCore/Startup.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.Http;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Hosting;
-
-namespace AspNetCore
-{
- public class Startup
- {
- // This method gets called by the runtime. Use this method to add services to the container.
- // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
- public void ConfigureServices(IServiceCollection services)
- {
- }
-
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
-
- app.UseRouting();
-
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapGet("/", async context =>
- {
- bool isMono = typeof(object).Assembly.GetType("Mono.RuntimeStructs") != null;
- await context.Response.WriteAsync("Hello World " + (isMono ? "from mono!\n" : "from CoreCLR"));
- });
- });
- }
- }
-}
diff --git a/netcore/sample/AspNetCore/appsettings.Development.json b/netcore/sample/AspNetCore/appsettings.Development.json
deleted file mode 100644
index a2880cbf124..00000000000
--- a/netcore/sample/AspNetCore/appsettings.Development.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "Logging": {
- "LogLevel": {
- "Default": "Debug",
- "System": "Information",
- "Microsoft": "Information"
- }
- }
-}
diff --git a/netcore/sample/AspNetCore/appsettings.json b/netcore/sample/AspNetCore/appsettings.json
deleted file mode 100644
index 81ff877711d..00000000000
--- a/netcore/sample/AspNetCore/appsettings.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "Logging": {
- "LogLevel": {
- "Default": "Information",
- "Microsoft": "Warning",
- "Microsoft.Hosting.Lifetime": "Information"
- }
- },
- "AllowedHosts": "*"
-}
diff --git a/netcore/sample/HelloWorld/HelloWorld.csproj b/netcore/sample/HelloWorld/HelloWorld.csproj
deleted file mode 100644
index fb690cf9012..00000000000
--- a/netcore/sample/HelloWorld/HelloWorld.csproj
+++ /dev/null
@@ -1,11 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <OutputPath>bin</OutputPath>
- <TargetFramework>netcoreapp3.0</TargetFramework>
- <DebugType>full</DebugType>
- <EnableSourceControlManagerQueries>false</EnableSourceControlManagerQueries>
- </PropertyGroup>
-
-</Project>
diff --git a/netcore/sample/HelloWorld/Program.cs b/netcore/sample/HelloWorld/Program.cs
deleted file mode 100644
index 45d83b35c78..00000000000
--- a/netcore/sample/HelloWorld/Program.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System;
-
-namespace HelloWorld
-{
- class Program
- {
- static void Main(string[] args)
- {
- bool isMono = typeof(object).Assembly.GetType("Mono.RuntimeStructs") != null;
- Console.WriteLine("Hello World " + (isMono ? "from Mono!" : "from CoreCLR!"));
- Console.WriteLine(typeof(object).Assembly.FullName);
- Console.WriteLine(System.Reflection.Assembly.GetEntryAssembly ());
- Console.WriteLine(System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
- }
- }
-}
diff --git a/netcore/tests/HwIntrinsics/HwIntrinsics.csproj b/netcore/tests/HwIntrinsics/HwIntrinsics.csproj
deleted file mode 100644
index 08cba7b3151..00000000000
--- a/netcore/tests/HwIntrinsics/HwIntrinsics.csproj
+++ /dev/null
@@ -1,11 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <Optimize>True</Optimize>
- <DebugType>Full</DebugType>
- <OutputPath>bin</OutputPath>
- <TargetFramework>netcoreapp3.0</TargetFramework>
- <EnableSourceControlManagerQueries>false</EnableSourceControlManagerQueries>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- </PropertyGroup>
-</Project>
diff --git a/netcore/tests/HwIntrinsics/Program.cs b/netcore/tests/HwIntrinsics/Program.cs
deleted file mode 100644
index a906f23969a..00000000000
--- a/netcore/tests/HwIntrinsics/Program.cs
+++ /dev/null
@@ -1,844 +0,0 @@
-using System;
-using System.IO;
-using System.Linq;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using System.Text;
-
-class HWIntrinsicsTests
-{
- static void Main ()
- {
- bool generateReferenceData = false; // enable to update SRI-reference-data.txt (e.g. on CoreCLR for Mono)
- int failures = 0;
- string refDataFile = Path.Combine (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location), "../../SRI-reference-data.txt");
- string [] refData = null;
-
- if (generateReferenceData)
- File.Delete (refDataFile);
- else
- refData = File.ReadAllLines (refDataFile);
-
- int sse1Methods = typeof (Sse).GetMethods ().Length;
- int sse2Methods = typeof (Sse2).GetMethods ().Length;
- int sse3Methods = typeof (Sse3).GetMethods ().Length;
- int ssse3Methods = typeof (Ssse3).GetMethods ().Length;
- int sse41Methods = typeof (Sse41).GetMethods ().Length;
- int sse42Methods = typeof (Sse42).GetMethods ().Length;
-
- Console.WriteLine ($"Sse: {sse1Methods} methods");
- Console.WriteLine ($"Sse2: {sse2Methods} methods");
- Console.WriteLine ($"Sse3: {sse3Methods} methods");
- Console.WriteLine ($"Ssse3: {ssse3Methods} methods");
- Console.WriteLine ($"Sse41: {sse41Methods} methods");
- Console.WriteLine ($"Sse42: {sse42Methods} methods");
- Console.WriteLine ();
-
- if (sse1Methods != 92)
- throw new Exception ("New changes in Sse (don't forget to update simd-intrinsics-netcore.c if necessary)");
- if (sse2Methods != 302)
- throw new Exception ("New changes in Sse2 (don't forget to update simd-intrinsics-netcore.c if necessary)");
- if (sse3Methods != 23)
- throw new Exception ("New changes in Sse3 (don't forget to update simd-intrinsics-netcore.c if necessary)");
- if (ssse3Methods != 29)
- throw new Exception ("New changes in Ssse3 (don't forget to update simd-intrinsics-netcore.c if necessary)");
- if (sse41Methods != 144)
- throw new Exception ("New changes in Sse41 (don't forget to update simd-intrinsics-netcore.c if necessary)");
- if (sse42Methods != 9)
- throw new Exception ("New changes in Sse42 (don't forget to update simd-intrinsics-netcore.c if necessary)");
-
- int skipped = 0;
- var tests = new SseTests ();
- foreach (var method in typeof (SseTests).GetMethods ()
- .OrderBy (m => m.Name) // TODO: the default order is different in Mono
- .Where (m => m.GetParameters ().Length == 0 && m.DeclaringType == typeof (SseTests)))
- {
- try
- {
- // clear test data each iteration
- tests.ReloadArrays ();
- var obj = method.Invoke (tests, null);
- string array2Data = tests.GetArray2Data ();
- string actualResult = $"{method.Name}: {obj}. array2: ({array2Data})\n";
- if (generateReferenceData)
- {
- File.AppendAllText (refDataFile, actualResult);
- }
- else
- {
- var expectedResult = refData.FirstOrDefault (l => l.StartsWith (method.Name));
- if (expectedResult.Trim ('\r', '\n', ' ') != actualResult.Trim ('\r', '\n', ' '))
- {
- Console.WriteLine ($"[FAIL] Expected: {expectedResult}, Actual: {actualResult}");
- failures++;
- }
- }
- }
- catch (TargetInvocationException e)
- {
- if (e.GetBaseException () is PlatformNotSupportedException) // Not supported by Mono yet
- {
- skipped++;
- continue;
- }
- throw;
- }
- }
-
- Console.WriteLine ();
- Console.WriteLine ("Skipped: " + skipped);
- Console.WriteLine ("Done.");
-
- if (failures != 0)
- throw new Exception ("Test failed.");
- }
-}
-
-public unsafe class SseTests
-{
- Random rand = new Random (42);
- float* pArray1Float = null;
- float* pArray2Float = null;
- double* pArray1Double = null;
- double* pArray2Double = null;
- byte* pArray1 = null;
- byte* pArray2 = null;
-
- // some SRI methods require memory to be aligned to 16bytes boundary (in case of Vector128)
- static T* AllocateAligned<T> (int elements) where T : unmanaged
- {
- IntPtr ptr = Marshal.AllocHGlobal (elements * sizeof (T) + 15);
- return (T*)(16 * (((long)ptr + 15) / 16));
- }
-
- public void ReloadArrays ()
- {
- if (pArray1Float == null)
- {
- pArray1Float = AllocateAligned<float> (4);
- pArray2Float = AllocateAligned<float> (4);
- pArray1Double = AllocateAligned<double> (2);
- pArray2Double = AllocateAligned<double> (2);
- pArray1 = AllocateAligned<byte> (16);
- pArray2 = AllocateAligned<byte> (16);
- }
-
- for (byte i = 0; i < 16; i++)
- {
- pArray1 [i] = i;
- pArray2 [i] = 0;
- }
-
- for (int i = 0; i < 4; i++)
- {
- pArray1Float [i] = i / 2f;
- pArray2Float [i] = 0;
- }
-
- for (int i = 0; i < 2; i++)
- {
- pArray1Double [i] = i / 3f;
- pArray2Double [i] = 0;
- }
- }
-
- private bool IsEmpty<T> (T* array) where T : unmanaged
- {
- for (var i = 0; i < Vector128<T>.Count; i++)
- {
- var item = array [i];
- if (item is float f && f != 0.0f)
- return false;
- if (item is double d && d != 0.0f)
- return false;
- if (item is byte b && b != 0)
- return false;
- }
- return true;
- }
-
- private string PrintArray<T> (T* array) where T : unmanaged
- {
- var sb = new StringBuilder ();
- sb.Append ("<");
- for (var i = 0; i < Vector128<T>.Count; i++)
- sb.Append (array [i]).Append (", ");
- sb.Append (">");
- return sb.ToString ().Replace (", >", ">");
- }
-
- public string GetArray2Data ()
- {
- if (!IsEmpty (pArray2))
- return PrintArray (pArray2);
- if (!IsEmpty (pArray2Float))
- return PrintArray (pArray2Float);
- if (!IsEmpty (pArray2Double))
- return PrintArray (pArray2Double);
- return "";
- }
-
- [MethodImpl (MethodImplOptions.NoInlining)]
- Vector128<T> GetV128<T> () where T : unmanaged
- {
- int randMult = 1;
- int rand0_10 = rand.Next (0, 11);
- if (rand0_10 % 3 == 0)
- randMult = -1;
- else if (rand0_10 > 8)
- randMult = 0;
-
- if (typeof(T) == typeof (float))
- {
- return Vector128.Create (
- (float)(rand.Next () * randMult) / 2.0f,
- (float)(rand.Next () * randMult) / 3.0f,
- (float)(rand.Next () * randMult) / 4.0f,
- (float)(rand.Next () * randMult) / 5.0f).As<float, T> ();
- }
- else if (typeof(T) == typeof (double))
- {
- return Vector128.Create (
- (double)(rand.Next () * randMult),
- (double)(rand.Next () * randMult)).As<double, T> ();
- }
-
- return Vector128.Create (
- rand.Next (0, int.MaxValue) * randMult,
- rand.Next (0, int.MaxValue) * randMult,
- rand.Next (0, int.MaxValue) * randMult,
- rand.Next (0, int.MaxValue) * randMult).As<int, T> ();
- }
-
- T Get<T> ()
- {
- int randMult = 1;
- int rand0_10 = rand.Next (0, 11);
- if (rand0_10 % 3 == 0)
- randMult = -1;
- else if (rand0_10 > 8)
- randMult = 0;
-
- if (typeof (T) == typeof (float))
- return (T)(object)(float)((rand.Next() * randMult) / 2.0f);
- if (typeof (T) == typeof (double))
- return (T)(object)(double)((rand.Next() * randMult) / 2.0);
- if (typeof (T) == typeof (byte))
- return (T)(object)(byte)((rand.Next (byte.MinValue, byte.MaxValue + 1)));
- if (typeof (T) == typeof (sbyte))
- return (T)(object)(sbyte)((rand.Next (sbyte.MinValue, sbyte.MaxValue + 1)));
- if (typeof (T) == typeof (short))
- return (T)(object)(short)((rand.Next (short.MinValue, short.MaxValue + 1)));
- if (typeof (T) == typeof (ushort))
- return (T)(object)(ushort)((rand.Next (ushort.MinValue, ushort.MaxValue + 1)));
- if (typeof (T) == typeof (int))
- return (T)(object)(int)((rand.Next (int.MinValue, int.MaxValue)));
- if (typeof (T) == typeof (uint))
- return (T)(object)(uint)((rand.Next (int.MinValue, int.MaxValue)));
- if (typeof (T) == typeof (long))
- return (T)(object)(long)((rand.Next (int.MinValue, int.MaxValue)));
- if (typeof (T) == typeof (ulong))
- return (T)(object)(ulong)((rand.Next (int.MinValue, int.MaxValue)));
- throw new NotSupportedException ();
- }
-
- public Vector128<Single> Sse_Add_0() => Sse.Add(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_AddScalar_1() => Sse.AddScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_And_2() => Sse.And(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_AndNot_3() => Sse.AndNot(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareEqual_4() => Sse.CompareEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareGreaterThan_5() => Sse.CompareGreaterThan(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareGreaterThanOrEqual_6() => Sse.CompareGreaterThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareLessThan_7() => Sse.CompareLessThan(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareLessThanOrEqual_8() => Sse.CompareLessThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareNotEqual_9() => Sse.CompareNotEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareNotGreaterThan_10() => Sse.CompareNotGreaterThan(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareNotGreaterThanOrEqual_11() => Sse.CompareNotGreaterThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareNotLessThan_12() => Sse.CompareNotLessThan(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareNotLessThanOrEqual_13() => Sse.CompareNotLessThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareOrdered_14() => Sse.CompareOrdered(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarEqual_15() => Sse.CompareScalarEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarGreaterThan_16() => Sse.CompareScalarGreaterThan(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarGreaterThanOrEqual_17() => Sse.CompareScalarGreaterThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarLessThan_18() => Sse.CompareScalarLessThan(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarLessThanOrEqual_19() => Sse.CompareScalarLessThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarNotEqual_20() => Sse.CompareScalarNotEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarNotGreaterThan_21() => Sse.CompareScalarNotGreaterThan(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarNotGreaterThanOrEqual_22() => Sse.CompareScalarNotGreaterThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarNotLessThan_23() => Sse.CompareScalarNotLessThan(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarNotLessThanOrEqual_24() => Sse.CompareScalarNotLessThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarOrdered_25() => Sse.CompareScalarOrdered(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarOrderedEqual_26() => Sse.CompareScalarOrderedEqual(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarOrderedGreaterThan_27() => Sse.CompareScalarOrderedGreaterThan(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarOrderedGreaterThanOrEqual_28() => Sse.CompareScalarOrderedGreaterThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarOrderedLessThan_29() => Sse.CompareScalarOrderedLessThan(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarOrderedLessThanOrEqual_30() => Sse.CompareScalarOrderedLessThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarOrderedNotEqual_31() => Sse.CompareScalarOrderedNotEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareScalarUnordered_32() => Sse.CompareScalarUnordered(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarUnorderedEqual_33() => Sse.CompareScalarUnorderedEqual(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarUnorderedGreaterThan_34() => Sse.CompareScalarUnorderedGreaterThan(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarUnorderedGreaterThanOrEqual_35() => Sse.CompareScalarUnorderedGreaterThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarUnorderedLessThan_36() => Sse.CompareScalarUnorderedLessThan(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarUnorderedLessThanOrEqual_37() => Sse.CompareScalarUnorderedLessThanOrEqual(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse_CompareScalarUnorderedNotEqual_38() => Sse.CompareScalarUnorderedNotEqual(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_CompareUnordered_39() => Sse.CompareUnordered(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_ConvertScalarToVector128Single_40() => Sse.ConvertScalarToVector128Single(GetV128<Single>(), Get<System.Int32>());
- public Int32 Sse_ConvertToInt32_41() => Sse.ConvertToInt32(GetV128<Single>());
- public Int32 Sse_ConvertToInt32WithTruncation_42() => Sse.ConvertToInt32WithTruncation(GetV128<Single>());
- public Vector128<Single> Sse_Divide_43() => Sse.Divide(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_DivideScalar_44() => Sse.DivideScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_LoadAlignedVector128_46() => Sse.LoadAlignedVector128((pArray1Float));
- public Vector128<Single> Sse_LoadHigh_47() => Sse.LoadHigh(GetV128<Single>(), pArray1Float);
- public Vector128<Single> Sse_LoadLow_48() => Sse.LoadLow(GetV128<Single>(), pArray1Float);
- public Vector128<Single> Sse_LoadScalarVector128_49() => Sse.LoadScalarVector128(pArray1Float);
- public Vector128<Single> Sse_LoadVector128_50() => Sse.LoadVector128(pArray1Float);
- public Vector128<Single> Sse_Max_51() => Sse.Max(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_MaxScalar_52() => Sse.MaxScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_Min_53() => Sse.Min(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_MinScalar_54() => Sse.MinScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_MoveHighToLow_55() => Sse.MoveHighToLow(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_MoveLowToHigh_56() => Sse.MoveLowToHigh(GetV128<Single>(), GetV128<Single>());
- public Int32 Sse_MoveMask_57() => Sse.MoveMask(GetV128<Single>());
- public Vector128<Single> Sse_MoveScalar_58() => Sse.MoveScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_Multiply_59() => Sse.Multiply(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_MultiplyScalar_60() => Sse.MultiplyScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_Or_61() => Sse.Or(GetV128<Single>(), GetV128<Single>());
- public void Sse_Prefetch0_62() => Sse.Prefetch0(pArray1);
- public void Sse_Prefetch1_63() => Sse.Prefetch1(pArray1);
- public void Sse_Prefetch2_64() => Sse.Prefetch2(pArray1);
- public void Sse_PrefetchNonTemporal_65() => Sse.PrefetchNonTemporal(pArray1);
- public Vector128<Single> Sse_Reciprocal_66() => Sse.Reciprocal(GetV128<Single>());
- public Vector128<Single> Sse_ReciprocalScalar_67() => Sse.ReciprocalScalar(GetV128<Single>());
- public Vector128<Single> Sse_ReciprocalScalar_68() => Sse.ReciprocalScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_ReciprocalSqrt_69() => Sse.ReciprocalSqrt(GetV128<Single>());
- public Vector128<Single> Sse_ReciprocalSqrtScalar_70() => Sse.ReciprocalSqrtScalar(GetV128<Single>());
- public Vector128<Single> Sse_ReciprocalSqrtScalar_71() => Sse.ReciprocalSqrtScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_Shuffle_72() => Sse.Shuffle(GetV128<Single>(), GetV128<Single>(), 22);
- public Vector128<Single> Sse_Sqrt_73() => Sse.Sqrt(GetV128<Single>());
- public Vector128<Single> Sse_SqrtScalar_74() => Sse.SqrtScalar(GetV128<Single>());
- public Vector128<Single> Sse_SqrtScalar_75() => Sse.SqrtScalar(GetV128<Single>(), GetV128<Single>());
- public void Sse_Store_76() => Sse.Store(pArray2Float, GetV128<Single>());
- public void Sse_StoreAligned_77() => Sse.StoreAligned((pArray2Float), GetV128<Single>());
- public void Sse_StoreAlignedNonTemporal_78() => Sse.StoreAlignedNonTemporal((pArray2Float), GetV128<Single>());
- public void Sse_StoreFence_79() => Sse.StoreFence();
- public void Sse_StoreHigh_80() => Sse.StoreHigh(pArray2Float, GetV128<Single>());
- public void Sse_StoreLow_81() => Sse.StoreLow(pArray2Float, GetV128<Single>());
- public void Sse_StoreScalar_82() => Sse.StoreScalar(pArray2Float, GetV128<Single>());
- public Vector128<Single> Sse_Subtract_83() => Sse.Subtract(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_SubtractScalar_84() => Sse.SubtractScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_UnpackHigh_85() => Sse.UnpackHigh(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_UnpackLow_86() => Sse.UnpackLow(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse_Xor_87() => Sse.Xor(GetV128<Single>(), GetV128<Single>());
- public Vector128<Byte> Sse2_Add_0() => Sse2.Add(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<SByte> Sse2_Add_1() => Sse2.Add(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Sse2_Add_2() => Sse2.Add(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_Add_3() => Sse2.Add(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse2_Add_4() => Sse2.Add(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse2_Add_5() => Sse2.Add(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Int64> Sse2_Add_6() => Sse2.Add(GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse2_Add_7() => Sse2.Add(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Double> Sse2_Add_8() => Sse2.Add(GetV128<Double>(), GetV128<Double>());
- public Vector128<SByte> Sse2_AddSaturate_9() => Sse2.AddSaturate(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Byte> Sse2_AddSaturate_10() => Sse2.AddSaturate(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<Int16> Sse2_AddSaturate_11() => Sse2.AddSaturate(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_AddSaturate_12() => Sse2.AddSaturate(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Double> Sse2_AddScalar_13() => Sse2.AddScalar(GetV128<Double>(), GetV128<Double>());
- public Vector128<Byte> Sse2_And_14() => Sse2.And(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<SByte> Sse2_And_15() => Sse2.And(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Sse2_And_16() => Sse2.And(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_And_17() => Sse2.And(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse2_And_18() => Sse2.And(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse2_And_19() => Sse2.And(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Int64> Sse2_And_20() => Sse2.And(GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse2_And_21() => Sse2.And(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Double> Sse2_And_22() => Sse2.And(GetV128<Double>(), GetV128<Double>());
- public Vector128<Byte> Sse2_AndNot_23() => Sse2.AndNot(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<SByte> Sse2_AndNot_24() => Sse2.AndNot(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Sse2_AndNot_25() => Sse2.AndNot(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_AndNot_26() => Sse2.AndNot(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse2_AndNot_27() => Sse2.AndNot(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse2_AndNot_28() => Sse2.AndNot(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Int64> Sse2_AndNot_29() => Sse2.AndNot(GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse2_AndNot_30() => Sse2.AndNot(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Double> Sse2_AndNot_31() => Sse2.AndNot(GetV128<Double>(), GetV128<Double>());
- public Vector128<Byte> Sse2_Average_32() => Sse2.Average(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<UInt16> Sse2_Average_33() => Sse2.Average(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<SByte> Sse2_CompareEqual_34() => Sse2.CompareEqual(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Byte> Sse2_CompareEqual_35() => Sse2.CompareEqual(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<Int16> Sse2_CompareEqual_36() => Sse2.CompareEqual(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_CompareEqual_37() => Sse2.CompareEqual(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse2_CompareEqual_38() => Sse2.CompareEqual(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse2_CompareEqual_39() => Sse2.CompareEqual(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Double> Sse2_CompareEqual_40() => Sse2.CompareEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<SByte> Sse2_CompareGreaterThan_41() => Sse2.CompareGreaterThan(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Sse2_CompareGreaterThan_42() => Sse2.CompareGreaterThan(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Int32> Sse2_CompareGreaterThan_43() => Sse2.CompareGreaterThan(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<Double> Sse2_CompareGreaterThan_44() => Sse2.CompareGreaterThan(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareGreaterThanOrEqual_45() => Sse2.CompareGreaterThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<SByte> Sse2_CompareLessThan_46() => Sse2.CompareLessThan(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Sse2_CompareLessThan_47() => Sse2.CompareLessThan(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Int32> Sse2_CompareLessThan_48() => Sse2.CompareLessThan(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<Double> Sse2_CompareLessThan_49() => Sse2.CompareLessThan(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareLessThanOrEqual_50() => Sse2.CompareLessThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareNotEqual_51() => Sse2.CompareNotEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareNotGreaterThan_52() => Sse2.CompareNotGreaterThan(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareNotGreaterThanOrEqual_53() => Sse2.CompareNotGreaterThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareNotLessThan_54() => Sse2.CompareNotLessThan(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareNotLessThanOrEqual_55() => Sse2.CompareNotLessThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareOrdered_56() => Sse2.CompareOrdered(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarEqual_57() => Sse2.CompareScalarEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarGreaterThan_58() => Sse2.CompareScalarGreaterThan(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarGreaterThanOrEqual_59() => Sse2.CompareScalarGreaterThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarLessThan_60() => Sse2.CompareScalarLessThan(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarLessThanOrEqual_61() => Sse2.CompareScalarLessThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarNotEqual_62() => Sse2.CompareScalarNotEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarNotGreaterThan_63() => Sse2.CompareScalarNotGreaterThan(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarNotGreaterThanOrEqual_64() => Sse2.CompareScalarNotGreaterThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarNotLessThan_65() => Sse2.CompareScalarNotLessThan(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarNotLessThanOrEqual_66() => Sse2.CompareScalarNotLessThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarOrdered_67() => Sse2.CompareScalarOrdered(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarOrderedEqual_68() => Sse2.CompareScalarOrderedEqual(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarOrderedGreaterThan_69() => Sse2.CompareScalarOrderedGreaterThan(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarOrderedGreaterThanOrEqual_70() => Sse2.CompareScalarOrderedGreaterThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarOrderedLessThan_71() => Sse2.CompareScalarOrderedLessThan(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarOrderedLessThanOrEqual_72() => Sse2.CompareScalarOrderedLessThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarOrderedNotEqual_73() => Sse2.CompareScalarOrderedNotEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareScalarUnordered_74() => Sse2.CompareScalarUnordered(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarUnorderedEqual_75() => Sse2.CompareScalarUnorderedEqual(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarUnorderedGreaterThan_76() => Sse2.CompareScalarUnorderedGreaterThan(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarUnorderedGreaterThanOrEqual_77() => Sse2.CompareScalarUnorderedGreaterThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarUnorderedLessThan_78() => Sse2.CompareScalarUnorderedLessThan(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarUnorderedLessThanOrEqual_79() => Sse2.CompareScalarUnorderedLessThanOrEqual(GetV128<Double>(), GetV128<Double>());
- public Boolean Sse2_CompareScalarUnorderedNotEqual_80() => Sse2.CompareScalarUnorderedNotEqual(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_CompareUnordered_81() => Sse2.CompareUnordered(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_ConvertScalarToVector128Double_82() => Sse2.ConvertScalarToVector128Double(GetV128<Double>(), Get<System.Int32>());
- public Vector128<Double> Sse2_ConvertScalarToVector128Double_83() => Sse2.ConvertScalarToVector128Double(GetV128<Double>(), GetV128<Single>());
- public Vector128<Int32> Sse2_ConvertScalarToVector128Int32_84() => Sse2.ConvertScalarToVector128Int32(Get<System.Int32>());
- public Vector128<Single> Sse2_ConvertScalarToVector128Single_85() => Sse2.ConvertScalarToVector128Single(GetV128<Single>(), GetV128<Double>());
- public Vector128<UInt32> Sse2_ConvertScalarToVector128UInt32_86() => Sse2.ConvertScalarToVector128UInt32(Get<System.UInt32>());
- public Int32 Sse2_ConvertToInt32_87() => Sse2.ConvertToInt32(GetV128<Double>());
- public Int32 Sse2_ConvertToInt32_88() => Sse2.ConvertToInt32(GetV128<Int32>());
- public Int32 Sse2_ConvertToInt32WithTruncation_89() => Sse2.ConvertToInt32WithTruncation(GetV128<Double>());
- public UInt32 Sse2_ConvertToUInt32_90() => Sse2.ConvertToUInt32(GetV128<UInt32>());
- public Vector128<Double> Sse2_ConvertToVector128Double_91() => Sse2.ConvertToVector128Double(GetV128<Int32>());
- public Vector128<Double> Sse2_ConvertToVector128Double_92() => Sse2.ConvertToVector128Double(GetV128<Single>());
- public Vector128<Int32> Sse2_ConvertToVector128Int32_93() => Sse2.ConvertToVector128Int32(GetV128<Single>());
- public Vector128<Int32> Sse2_ConvertToVector128Int32_94() => Sse2.ConvertToVector128Int32(GetV128<Double>());
- public Vector128<Int32> Sse2_ConvertToVector128Int32WithTruncation_95() => Sse2.ConvertToVector128Int32WithTruncation(GetV128<Single>());
- public Vector128<Int32> Sse2_ConvertToVector128Int32WithTruncation_96() => Sse2.ConvertToVector128Int32WithTruncation(GetV128<Double>());
- public Vector128<Single> Sse2_ConvertToVector128Single_97() => Sse2.ConvertToVector128Single(GetV128<Int32>());
- public Vector128<Single> Sse2_ConvertToVector128Single_98() => Sse2.ConvertToVector128Single(GetV128<Double>());
- public Vector128<Double> Sse2_Divide_99() => Sse2.Divide(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_DivideScalar_100() => Sse2.DivideScalar(GetV128<Double>(), GetV128<Double>());
- public UInt16 Sse2_Extract_101() => Sse2.Extract(GetV128<UInt16>(), Get<System.Byte>());
- public Vector128<Int16> Sse2_Insert_103() => Sse2.Insert(GetV128<Int16>(), Get<System.Int16>(), Get<System.Byte>());
- public Vector128<UInt16> Sse2_Insert_104() => Sse2.Insert(GetV128<UInt16>(), Get<System.UInt16>(), Get<System.Byte>());
- public Vector128<SByte> Sse2_LoadAlignedVector128_105() => Sse2.LoadAlignedVector128(((sbyte*)pArray1));
- public Vector128<Byte> Sse2_LoadAlignedVector128_106() => Sse2.LoadAlignedVector128(((byte*)pArray1));
- public Vector128<Int16> Sse2_LoadAlignedVector128_107() => Sse2.LoadAlignedVector128(((short*)pArray1));
- public Vector128<UInt16> Sse2_LoadAlignedVector128_108() => Sse2.LoadAlignedVector128(((ushort*)pArray1));
- public Vector128<Int32> Sse2_LoadAlignedVector128_109() => Sse2.LoadAlignedVector128(((int*)pArray1));
- public Vector128<UInt32> Sse2_LoadAlignedVector128_110() => Sse2.LoadAlignedVector128(((uint*)pArray1));
- public Vector128<Int64> Sse2_LoadAlignedVector128_111() => Sse2.LoadAlignedVector128(((long*)pArray1));
- public Vector128<UInt64> Sse2_LoadAlignedVector128_112() => Sse2.LoadAlignedVector128(((ulong*)pArray1));
- public Vector128<Double> Sse2_LoadAlignedVector128_113() => Sse2.LoadAlignedVector128((pArray1Double));
- public void Sse2_LoadFence_114() => Sse2.LoadFence();
- public Vector128<Double> Sse2_LoadHigh_115() => Sse2.LoadHigh(GetV128<Double>(), pArray1Double);
- public Vector128<Double> Sse2_LoadLow_116() => Sse2.LoadLow(GetV128<Double>(), pArray1Double);
- public Vector128<Double> Sse2_LoadScalarVector128_117() => Sse2.LoadScalarVector128(pArray1Double);
- public Vector128<Int32> Sse2_LoadScalarVector128_118() => Sse2.LoadScalarVector128((int*)pArray1);
- public Vector128<UInt32> Sse2_LoadScalarVector128_119() => Sse2.LoadScalarVector128((uint*)pArray1);
- public Vector128<Int64> Sse2_LoadScalarVector128_120() => Sse2.LoadScalarVector128((long*)pArray1);
- public Vector128<UInt64> Sse2_LoadScalarVector128_121() => Sse2.LoadScalarVector128((ulong*)pArray1);
- public Vector128<SByte> Sse2_LoadVector128_122() => Sse2.LoadVector128((sbyte*)pArray1);
- public Vector128<Byte> Sse2_LoadVector128_123() => Sse2.LoadVector128((byte*)pArray1);
- public Vector128<Int16> Sse2_LoadVector128_124() => Sse2.LoadVector128((short*)pArray1);
- public Vector128<UInt16> Sse2_LoadVector128_125() => Sse2.LoadVector128((ushort*)pArray1);
- public Vector128<Int32> Sse2_LoadVector128_126() => Sse2.LoadVector128((int*)pArray1);
- public Vector128<UInt32> Sse2_LoadVector128_127() => Sse2.LoadVector128((uint*)pArray1);
- public Vector128<Int64> Sse2_LoadVector128_128() => Sse2.LoadVector128((long*)pArray1);
- public Vector128<UInt64> Sse2_LoadVector128_129() => Sse2.LoadVector128((ulong*)pArray1);
- public Vector128<Double> Sse2_LoadVector128_130() => Sse2.LoadVector128(pArray1Double);
- public void Sse2_MaskMove_131() => Sse2.MaskMove(GetV128<SByte>(), GetV128<SByte>(), (sbyte*)pArray1);
- public void Sse2_MaskMove_132() => Sse2.MaskMove(GetV128<Byte>(), GetV128<Byte>(), (byte*)pArray1);
- public Vector128<Byte> Sse2_Max_133() => Sse2.Max(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<Int16> Sse2_Max_134() => Sse2.Max(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Double> Sse2_Max_135() => Sse2.Max(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_MaxScalar_136() => Sse2.MaxScalar(GetV128<Double>(), GetV128<Double>());
- public void Sse2_MemoryFence_137() => Sse2.MemoryFence();
- public Vector128<Byte> Sse2_Min_138() => Sse2.Min(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<Int16> Sse2_Min_139() => Sse2.Min(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Double> Sse2_Min_140() => Sse2.Min(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse2_MinScalar_141() => Sse2.MinScalar(GetV128<Double>(), GetV128<Double>());
- public Int32 Sse2_MoveMask_142() => Sse2.MoveMask(GetV128<SByte>());
- public Int32 Sse2_MoveMask_143() => Sse2.MoveMask(GetV128<Byte>());
- public Int32 Sse2_MoveMask_144() => Sse2.MoveMask(GetV128<Double>());
- public Vector128<Double> Sse2_MoveScalar_145() => Sse2.MoveScalar(GetV128<Double>(), GetV128<Double>());
- public Vector128<Int64> Sse2_MoveScalar_146() => Sse2.MoveScalar(GetV128<Int64>());
- public Vector128<UInt64> Sse2_MoveScalar_147() => Sse2.MoveScalar(GetV128<UInt64>());
- public Vector128<UInt64> Sse2_Multiply_148() => Sse2.Multiply(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Double> Sse2_Multiply_149() => Sse2.Multiply(GetV128<Double>(), GetV128<Double>());
- public Vector128<Int32> Sse2_MultiplyAddAdjacent_150() => Sse2.MultiplyAddAdjacent(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Int16> Sse2_MultiplyHigh_151() => Sse2.MultiplyHigh(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_MultiplyHigh_152() => Sse2.MultiplyHigh(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int16> Sse2_MultiplyLow_153() => Sse2.MultiplyLow(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_MultiplyLow_154() => Sse2.MultiplyLow(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Double> Sse2_MultiplyScalar_155() => Sse2.MultiplyScalar(GetV128<Double>(), GetV128<Double>());
- public Vector128<Byte> Sse2_Or_156() => Sse2.Or(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<SByte> Sse2_Or_157() => Sse2.Or(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Sse2_Or_158() => Sse2.Or(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_Or_159() => Sse2.Or(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse2_Or_160() => Sse2.Or(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse2_Or_161() => Sse2.Or(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Int64> Sse2_Or_162() => Sse2.Or(GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse2_Or_163() => Sse2.Or(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Double> Sse2_Or_164() => Sse2.Or(GetV128<Double>(), GetV128<Double>());
- public Vector128<SByte> Sse2_PackSignedSaturate_165() => Sse2.PackSignedSaturate(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Int16> Sse2_PackSignedSaturate_166() => Sse2.PackSignedSaturate(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<Byte> Sse2_PackUnsignedSaturate_167() => Sse2.PackUnsignedSaturate(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Int16> Sse2_ShiftLeftLogical_168() => Sse2.ShiftLeftLogical(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_ShiftLeftLogical_169() => Sse2.ShiftLeftLogical(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse2_ShiftLeftLogical_170() => Sse2.ShiftLeftLogical(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse2_ShiftLeftLogical_171() => Sse2.ShiftLeftLogical(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Int64> Sse2_ShiftLeftLogical_172() => Sse2.ShiftLeftLogical(GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse2_ShiftLeftLogical_173() => Sse2.ShiftLeftLogical(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Int16> Sse2_ShiftLeftLogical_174() => Sse2.ShiftLeftLogical(GetV128<Int16>(), Get<System.Byte>());
- public Vector128<UInt16> Sse2_ShiftLeftLogical_175() => Sse2.ShiftLeftLogical(GetV128<UInt16>(), Get<System.Byte>());
- public Vector128<Int32> Sse2_ShiftLeftLogical_176() => Sse2.ShiftLeftLogical(GetV128<Int32>(), Get<System.Byte>());
- public Vector128<UInt32> Sse2_ShiftLeftLogical_177() => Sse2.ShiftLeftLogical(GetV128<UInt32>(), Get<System.Byte>());
- public Vector128<Int64> Sse2_ShiftLeftLogical_178() => Sse2.ShiftLeftLogical(GetV128<Int64>(), Get<System.Byte>());
- public Vector128<UInt64> Sse2_ShiftLeftLogical_179() => Sse2.ShiftLeftLogical(GetV128<UInt64>(), Get<System.Byte>());
- public Vector128<SByte> Sse2_ShiftLeftLogical128BitLane_180() => Sse2.ShiftLeftLogical128BitLane(GetV128<SByte>(), Get<System.Byte>());
- public Vector128<Byte> Sse2_ShiftLeftLogical128BitLane_181() => Sse2.ShiftLeftLogical128BitLane(GetV128<Byte>(), Get<System.Byte>());
- public Vector128<Int16> Sse2_ShiftLeftLogical128BitLane_182() => Sse2.ShiftLeftLogical128BitLane(GetV128<Int16>(), Get<System.Byte>());
- public Vector128<UInt16> Sse2_ShiftLeftLogical128BitLane_183() => Sse2.ShiftLeftLogical128BitLane(GetV128<UInt16>(), Get<System.Byte>());
- public Vector128<Int32> Sse2_ShiftLeftLogical128BitLane_184() => Sse2.ShiftLeftLogical128BitLane(GetV128<Int32>(), Get<System.Byte>());
- public Vector128<UInt32> Sse2_ShiftLeftLogical128BitLane_185() => Sse2.ShiftLeftLogical128BitLane(GetV128<UInt32>(), Get<System.Byte>());
- public Vector128<Int64> Sse2_ShiftLeftLogical128BitLane_186() => Sse2.ShiftLeftLogical128BitLane(GetV128<Int64>(), Get<System.Byte>());
- public Vector128<UInt64> Sse2_ShiftLeftLogical128BitLane_187() => Sse2.ShiftLeftLogical128BitLane(GetV128<UInt64>(), Get<System.Byte>());
- public Vector128<Int16> Sse2_ShiftRightArithmetic_188() => Sse2.ShiftRightArithmetic(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Int32> Sse2_ShiftRightArithmetic_189() => Sse2.ShiftRightArithmetic(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<Int16> Sse2_ShiftRightArithmetic_190() => Sse2.ShiftRightArithmetic(GetV128<Int16>(), Get<System.Byte>());
- public Vector128<Int32> Sse2_ShiftRightArithmetic_191() => Sse2.ShiftRightArithmetic(GetV128<Int32>(), Get<System.Byte>());
- public Vector128<Int16> Sse2_ShiftRightLogical_192() => Sse2.ShiftRightLogical(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_ShiftRightLogical_193() => Sse2.ShiftRightLogical(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse2_ShiftRightLogical_194() => Sse2.ShiftRightLogical(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse2_ShiftRightLogical_195() => Sse2.ShiftRightLogical(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Int64> Sse2_ShiftRightLogical_196() => Sse2.ShiftRightLogical(GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse2_ShiftRightLogical_197() => Sse2.ShiftRightLogical(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Int16> Sse2_ShiftRightLogical_198() => Sse2.ShiftRightLogical(GetV128<Int16>(), Get<System.Byte>());
- public Vector128<UInt16> Sse2_ShiftRightLogical_199() => Sse2.ShiftRightLogical(GetV128<UInt16>(), Get<System.Byte>());
- public Vector128<Int32> Sse2_ShiftRightLogical_200() => Sse2.ShiftRightLogical(GetV128<Int32>(), Get<System.Byte>());
- public Vector128<UInt32> Sse2_ShiftRightLogical_201() => Sse2.ShiftRightLogical(GetV128<UInt32>(), Get<System.Byte>());
- public Vector128<Int64> Sse2_ShiftRightLogical_202() => Sse2.ShiftRightLogical(GetV128<Int64>(), Get<System.Byte>());
- public Vector128<UInt64> Sse2_ShiftRightLogical_203() => Sse2.ShiftRightLogical(GetV128<UInt64>(), Get<System.Byte>());
- public Vector128<SByte> Sse2_ShiftRightLogical128BitLane_204() => Sse2.ShiftRightLogical128BitLane(GetV128<SByte>(), Get<System.Byte>());
- public Vector128<Byte> Sse2_ShiftRightLogical128BitLane_205() => Sse2.ShiftRightLogical128BitLane(GetV128<Byte>(), Get<System.Byte>());
- public Vector128<Int16> Sse2_ShiftRightLogical128BitLane_206() => Sse2.ShiftRightLogical128BitLane(GetV128<Int16>(), Get<System.Byte>());
- public Vector128<UInt16> Sse2_ShiftRightLogical128BitLane_207() => Sse2.ShiftRightLogical128BitLane(GetV128<UInt16>(), Get<System.Byte>());
- public Vector128<Int32> Sse2_ShiftRightLogical128BitLane_208() => Sse2.ShiftRightLogical128BitLane(GetV128<Int32>(), Get<System.Byte>());
- public Vector128<UInt32> Sse2_ShiftRightLogical128BitLane_209() => Sse2.ShiftRightLogical128BitLane(GetV128<UInt32>(), Get<System.Byte>());
- public Vector128<Int64> Sse2_ShiftRightLogical128BitLane_210() => Sse2.ShiftRightLogical128BitLane(GetV128<Int64>(), Get<System.Byte>());
- public Vector128<UInt64> Sse2_ShiftRightLogical128BitLane_211() => Sse2.ShiftRightLogical128BitLane(GetV128<UInt64>(), Get<System.Byte>());
- public Vector128<UInt32> Sse2_Shuffle_212() => Sse2.Shuffle(GetV128<UInt32>(), 12);
- public Vector128<Double> Sse2_Shuffle_213() => Sse2.Shuffle(GetV128<Double>(), GetV128<Double>(), 3);
- public Vector128<Int32> Sse2_Shuffle_214() => Sse2.Shuffle(GetV128<Int32>(), 42);
- public Vector128<Int16> Sse2_ShuffleHigh_215() => Sse2.ShuffleHigh(GetV128<Int16>(), 23);
- public Vector128<UInt16> Sse2_ShuffleHigh_216() => Sse2.ShuffleHigh(GetV128<UInt16>(), 12);
- public Vector128<Int16> Sse2_ShuffleLow_217() => Sse2.ShuffleLow(GetV128<Int16>(), 5);
- public Vector128<UInt16> Sse2_ShuffleLow_218() => Sse2.ShuffleLow(GetV128<UInt16>(), 3);
- public Vector128<Double> Sse2_Sqrt_219() => Sse2.Sqrt(GetV128<Double>());
- public Vector128<Double> Sse2_SqrtScalar_220() => Sse2.SqrtScalar(GetV128<Double>());
- public Vector128<Double> Sse2_SqrtScalar_221() => Sse2.SqrtScalar(GetV128<Double>(), GetV128<Double>());
- public void Sse2_Store_222() => Sse2.Store((sbyte*)pArray2, GetV128<SByte>());
- public void Sse2_Store_223() => Sse2.Store((byte*)pArray2, GetV128<Byte>());
- public void Sse2_Store_224() => Sse2.Store((short*)pArray2, GetV128<Int16>());
- public void Sse2_Store_225() => Sse2.Store((ushort*)pArray2, GetV128<UInt16>());
- public void Sse2_Store_226() => Sse2.Store((int*)pArray2, GetV128<Int32>());
- public void Sse2_Store_227() => Sse2.Store((uint*)pArray2, GetV128<UInt32>());
- public void Sse2_Store_228() => Sse2.Store((long*)pArray2, GetV128<Int64>());
- public void Sse2_Store_229() => Sse2.Store((ulong*)pArray2, GetV128<UInt64>());
- public void Sse2_Store_230() => Sse2.Store(pArray1Double, GetV128<Double>());
- public void Sse2_StoreAligned_231() => Sse2.StoreAligned(((sbyte*)pArray2), GetV128<SByte>());
- public void Sse2_StoreAligned_232() => Sse2.StoreAligned(((byte*)pArray2), GetV128<Byte>());
- public void Sse2_StoreAligned_233() => Sse2.StoreAligned(((short*)pArray2), GetV128<Int16>());
- public void Sse2_StoreAligned_234() => Sse2.StoreAligned(((ushort*)pArray2), GetV128<UInt16>());
- public void Sse2_StoreAligned_235() => Sse2.StoreAligned(((int*)pArray2), GetV128<Int32>());
- public void Sse2_StoreAligned_236() => Sse2.StoreAligned(((uint*)pArray2), GetV128<UInt32>());
- public void Sse2_StoreAligned_237() => Sse2.StoreAligned(((long*)pArray2), GetV128<Int64>());
- public void Sse2_StoreAligned_238() => Sse2.StoreAligned(((ulong*)pArray2), GetV128<UInt64>());
- public void Sse2_StoreAligned_239() => Sse2.StoreAligned((pArray2Double), GetV128<Double>());
- public void Sse2_StoreAlignedNonTemporal_240() => Sse2.StoreAlignedNonTemporal(((sbyte*)pArray2), GetV128<SByte>());
- public void Sse2_StoreAlignedNonTemporal_241() => Sse2.StoreAlignedNonTemporal(((byte*)pArray2), GetV128<Byte>());
- public void Sse2_StoreAlignedNonTemporal_242() => Sse2.StoreAlignedNonTemporal(((short*)pArray2), GetV128<Int16>());
- public void Sse2_StoreAlignedNonTemporal_243() => Sse2.StoreAlignedNonTemporal(((ushort*)pArray2), GetV128<UInt16>());
- public void Sse2_StoreAlignedNonTemporal_244() => Sse2.StoreAlignedNonTemporal(((int*)pArray2), GetV128<Int32>());
- public void Sse2_StoreAlignedNonTemporal_245() => Sse2.StoreAlignedNonTemporal(((uint*)pArray2), GetV128<UInt32>());
- public void Sse2_StoreAlignedNonTemporal_246() => Sse2.StoreAlignedNonTemporal(((long*)pArray2), GetV128<Int64>());
- public void Sse2_StoreAlignedNonTemporal_247() => Sse2.StoreAlignedNonTemporal(((ulong*)pArray2), GetV128<UInt64>());
- public void Sse2_StoreAlignedNonTemporal_248() => Sse2.StoreAlignedNonTemporal((pArray2Double), GetV128<Double>());
- public void Sse2_StoreHigh_249() => Sse2.StoreHigh(pArray2Double, GetV128<Double>());
- public void Sse2_StoreLow_250() => Sse2.StoreLow(pArray2Double, GetV128<Double>());
- public void Sse2_StoreNonTemporal_251() => Sse2.StoreNonTemporal((int*)pArray2, Get<System.Int32>());
- public void Sse2_StoreNonTemporal_252() => Sse2.StoreNonTemporal((uint*)pArray2, Get<System.UInt32>());
- public void Sse2_StoreScalar_253() => Sse2.StoreScalar(pArray2Double, GetV128<Double>());
- public void Sse2_StoreScalar_254() => Sse2.StoreScalar((long*)pArray2, GetV128<Int64>());
- public void Sse2_StoreScalar_255() => Sse2.StoreScalar((ulong*)pArray2, GetV128<UInt64>());
- public Vector128<Byte> Sse2_Subtract_256() => Sse2.Subtract(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<SByte> Sse2_Subtract_257() => Sse2.Subtract(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Sse2_Subtract_258() => Sse2.Subtract(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_Subtract_259() => Sse2.Subtract(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse2_Subtract_260() => Sse2.Subtract(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse2_Subtract_261() => Sse2.Subtract(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Int64> Sse2_Subtract_262() => Sse2.Subtract(GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse2_Subtract_263() => Sse2.Subtract(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Double> Sse2_Subtract_264() => Sse2.Subtract(GetV128<Double>(), GetV128<Double>());
- public Vector128<SByte> Sse2_SubtractSaturate_265() => Sse2.SubtractSaturate(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Sse2_SubtractSaturate_266() => Sse2.SubtractSaturate(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Byte> Sse2_SubtractSaturate_267() => Sse2.SubtractSaturate(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<UInt16> Sse2_SubtractSaturate_268() => Sse2.SubtractSaturate(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Double> Sse2_SubtractScalar_269() => Sse2.SubtractScalar(GetV128<Double>(), GetV128<Double>());
- public Vector128<UInt16> Sse2_SumAbsoluteDifferences_270() => Sse2.SumAbsoluteDifferences(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<Byte> Sse2_UnpackHigh_271() => Sse2.UnpackHigh(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<SByte> Sse2_UnpackHigh_272() => Sse2.UnpackHigh(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Sse2_UnpackHigh_273() => Sse2.UnpackHigh(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_UnpackHigh_274() => Sse2.UnpackHigh(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse2_UnpackHigh_275() => Sse2.UnpackHigh(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse2_UnpackHigh_276() => Sse2.UnpackHigh(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Int64> Sse2_UnpackHigh_277() => Sse2.UnpackHigh(GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse2_UnpackHigh_278() => Sse2.UnpackHigh(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Double> Sse2_UnpackHigh_279() => Sse2.UnpackHigh(GetV128<Double>(), GetV128<Double>());
- public Vector128<Byte> Sse2_UnpackLow_280() => Sse2.UnpackLow(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<SByte> Sse2_UnpackLow_281() => Sse2.UnpackLow(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Sse2_UnpackLow_282() => Sse2.UnpackLow(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_UnpackLow_283() => Sse2.UnpackLow(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse2_UnpackLow_284() => Sse2.UnpackLow(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse2_UnpackLow_285() => Sse2.UnpackLow(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Int64> Sse2_UnpackLow_286() => Sse2.UnpackLow(GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse2_UnpackLow_287() => Sse2.UnpackLow(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Double> Sse2_UnpackLow_288() => Sse2.UnpackLow(GetV128<Double>(), GetV128<Double>());
- public Vector128<Byte> Sse2_Xor_289() => Sse2.Xor(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<SByte> Sse2_Xor_290() => Sse2.Xor(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Sse2_Xor_291() => Sse2.Xor(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse2_Xor_292() => Sse2.Xor(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse2_Xor_293() => Sse2.Xor(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse2_Xor_294() => Sse2.Xor(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Int64> Sse2_Xor_295() => Sse2.Xor(GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse2_Xor_296() => Sse2.Xor(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Double> Sse2_Xor_297() => Sse2.Xor(GetV128<Double>(), GetV128<Double>());
- public Vector128<Single> Sse3_AddSubtract_0() => Sse3.AddSubtract(GetV128<Single>(), GetV128<Single>());
- public Vector128<Double> Sse3_AddSubtract_1() => Sse3.AddSubtract(GetV128<Double>(), GetV128<Double>());
- public Vector128<Single> Sse3_HorizontalAdd_3() => Sse3.HorizontalAdd(GetV128<Single>(), GetV128<Single>());
- public Vector128<Double> Sse3_HorizontalAdd_4() => Sse3.HorizontalAdd(GetV128<Double>(), GetV128<Double>());
- public Vector128<Single> Sse3_HorizontalSubtract_5() => Sse3.HorizontalSubtract(GetV128<Single>(), GetV128<Single>());
- public Vector128<Double> Sse3_HorizontalSubtract_6() => Sse3.HorizontalSubtract(GetV128<Double>(), GetV128<Double>());
- public Vector128<Double> Sse3_LoadAndDuplicateToVector128_7() => Sse3.LoadAndDuplicateToVector128(pArray1Double);
- public Vector128<SByte> Sse3_LoadDquVector128_8() => Sse3.LoadDquVector128((sbyte*)pArray1);
- public Vector128<Byte> Sse3_LoadDquVector128_9() => Sse3.LoadDquVector128((byte*)pArray1);
- public Vector128<Int16> Sse3_LoadDquVector128_10() => Sse3.LoadDquVector128((short*)pArray1);
- public Vector128<UInt16> Sse3_LoadDquVector128_11() => Sse3.LoadDquVector128((ushort*)pArray1);
- public Vector128<Int32> Sse3_LoadDquVector128_12() => Sse3.LoadDquVector128((int*)pArray1);
- public Vector128<UInt32> Sse3_LoadDquVector128_13() => Sse3.LoadDquVector128((uint*)pArray1);
- public Vector128<Int64> Sse3_LoadDquVector128_14() => Sse3.LoadDquVector128((long*)pArray1);
- public Vector128<UInt64> Sse3_LoadDquVector128_15() => Sse3.LoadDquVector128((ulong*)pArray1);
- public Vector128<Double> Sse3_MoveAndDuplicate_16() => Sse3.MoveAndDuplicate(GetV128<Double>());
- public Vector128<Single> Sse3_MoveHighAndDuplicate_17() => Sse3.MoveHighAndDuplicate(GetV128<Single>());
- public Vector128<Single> Sse3_MoveLowAndDuplicate_18() => Sse3.MoveLowAndDuplicate(GetV128<Single>());
- public Vector128<Byte> Ssse3_Abs_0() => Ssse3.Abs(GetV128<SByte>());
- public Vector128<UInt16> Ssse3_Abs_1() => Ssse3.Abs(GetV128<Int16>());
- public Vector128<UInt32> Ssse3_Abs_2() => Ssse3.Abs(GetV128<Int32>());
- public Vector128<SByte> Ssse3_AlignRight_3() => Ssse3.AlignRight(GetV128<SByte>(), GetV128<SByte>(), Get<System.Byte>());
- public Vector128<Byte> Ssse3_AlignRight_4() => Ssse3.AlignRight(GetV128<Byte>(), GetV128<Byte>(), Get<System.Byte>());
- public Vector128<Int16> Ssse3_AlignRight_5() => Ssse3.AlignRight(GetV128<Int16>(), GetV128<Int16>(), Get<System.Byte>());
- public Vector128<UInt16> Ssse3_AlignRight_6() => Ssse3.AlignRight(GetV128<UInt16>(), GetV128<UInt16>(), Get<System.Byte>());
- public Vector128<Int32> Ssse3_AlignRight_7() => Ssse3.AlignRight(GetV128<Int32>(), GetV128<Int32>(), Get<System.Byte>());
- public Vector128<UInt32> Ssse3_AlignRight_8() => Ssse3.AlignRight(GetV128<UInt32>(), GetV128<UInt32>(), Get<System.Byte>());
- public Vector128<Int64> Ssse3_AlignRight_9() => Ssse3.AlignRight(GetV128<Int64>(), GetV128<Int64>(), Get<System.Byte>());
- public Vector128<UInt64> Ssse3_AlignRight_10() => Ssse3.AlignRight(GetV128<UInt64>(), GetV128<UInt64>(), Get<System.Byte>());
- public Vector128<Int16> Ssse3_HorizontalAdd_12() => Ssse3.HorizontalAdd(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Int32> Ssse3_HorizontalAdd_13() => Ssse3.HorizontalAdd(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<Int16> Ssse3_HorizontalAddSaturate_14() => Ssse3.HorizontalAddSaturate(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Int16> Ssse3_HorizontalSubtract_15() => Ssse3.HorizontalSubtract(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Int32> Ssse3_HorizontalSubtract_16() => Ssse3.HorizontalSubtract(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<Int16> Ssse3_HorizontalSubtractSaturate_17() => Ssse3.HorizontalSubtractSaturate(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Int16> Ssse3_MultiplyAddAdjacent_18() => Ssse3.MultiplyAddAdjacent(GetV128<Byte>(), GetV128<SByte>());
- public Vector128<Int16> Ssse3_MultiplyHighRoundScale_19() => Ssse3.MultiplyHighRoundScale(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<SByte> Ssse3_Shuffle_20() => Ssse3.Shuffle(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Byte> Ssse3_Shuffle_21() => Ssse3.Shuffle(GetV128<Byte>(), GetV128<Byte>());
- public Vector128<SByte> Ssse3_Sign_22() => Ssse3.Sign(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Int16> Ssse3_Sign_23() => Ssse3.Sign(GetV128<Int16>(), GetV128<Int16>());
- public Vector128<Int32> Ssse3_Sign_24() => Ssse3.Sign(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<Int16> Sse41_Blend_0() => Sse41.Blend(GetV128<Int16>(), GetV128<Int16>(), Get<System.Byte>());
- public Vector128<UInt16> Sse41_Blend_1() => Sse41.Blend(GetV128<UInt16>(), GetV128<UInt16>(), Get<System.Byte>());
- public Vector128<Single> Sse41_Blend_2() => Sse41.Blend(GetV128<Single>(), GetV128<Single>(), Get<System.Byte>());
- public Vector128<Double> Sse41_Blend_3() => Sse41.Blend(GetV128<Double>(), GetV128<Double>(), Get<System.Byte>());
- public Vector128<SByte> Sse41_BlendVariable_4() => Sse41.BlendVariable(GetV128<SByte>(), GetV128<SByte>(), GetV128<SByte>());
- public Vector128<Byte> Sse41_BlendVariable_5() => Sse41.BlendVariable(GetV128<Byte>(), GetV128<Byte>(), GetV128<Byte>());
- public Vector128<Int16> Sse41_BlendVariable_6() => Sse41.BlendVariable(GetV128<Int16>(), GetV128<Int16>(), GetV128<Int16>());
- public Vector128<UInt16> Sse41_BlendVariable_7() => Sse41.BlendVariable(GetV128<UInt16>(), GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse41_BlendVariable_8() => Sse41.BlendVariable(GetV128<Int32>(), GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse41_BlendVariable_9() => Sse41.BlendVariable(GetV128<UInt32>(), GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<Int64> Sse41_BlendVariable_10() => Sse41.BlendVariable(GetV128<Int64>(), GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse41_BlendVariable_11() => Sse41.BlendVariable(GetV128<UInt64>(), GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Single> Sse41_BlendVariable_12() => Sse41.BlendVariable(GetV128<Single>(), GetV128<Single>(), GetV128<Single>());
- public Vector128<Double> Sse41_BlendVariable_13() => Sse41.BlendVariable(GetV128<Double>(), GetV128<Double>(), GetV128<Double>());
- public Vector128<Single> Sse41_Ceiling_14() => Sse41.Ceiling(GetV128<Single>());
- public Vector128<Double> Sse41_Ceiling_15() => Sse41.Ceiling(GetV128<Double>());
- public Vector128<Double> Sse41_CeilingScalar_16() => Sse41.CeilingScalar(GetV128<Double>());
- public Vector128<Single> Sse41_CeilingScalar_17() => Sse41.CeilingScalar(GetV128<Single>());
- public Vector128<Double> Sse41_CeilingScalar_18() => Sse41.CeilingScalar(GetV128<Double>(), GetV128<Double>());
- public Vector128<Single> Sse41_CeilingScalar_19() => Sse41.CeilingScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Int64> Sse41_CompareEqual_20() => Sse41.CompareEqual(GetV128<Int64>(), GetV128<Int64>());
- public Vector128<UInt64> Sse41_CompareEqual_21() => Sse41.CompareEqual(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Int16> Sse41_ConvertToVector128Int16_22() => Sse41.ConvertToVector128Int16(GetV128<SByte>());
- public Vector128<Int16> Sse41_ConvertToVector128Int16_23() => Sse41.ConvertToVector128Int16(GetV128<Byte>());
- public Vector128<Int16> Sse41_ConvertToVector128Int16_24() => Sse41.ConvertToVector128Int16((sbyte*)pArray1);
- public Vector128<Int16> Sse41_ConvertToVector128Int16_25() => Sse41.ConvertToVector128Int16((byte*)pArray1);
- public Vector128<Int32> Sse41_ConvertToVector128Int32_26() => Sse41.ConvertToVector128Int32(GetV128<SByte>());
- public Vector128<Int32> Sse41_ConvertToVector128Int32_27() => Sse41.ConvertToVector128Int32(GetV128<Byte>());
- public Vector128<Int32> Sse41_ConvertToVector128Int32_28() => Sse41.ConvertToVector128Int32(GetV128<Int16>());
- public Vector128<Int32> Sse41_ConvertToVector128Int32_29() => Sse41.ConvertToVector128Int32(GetV128<UInt16>());
- public Vector128<Int32> Sse41_ConvertToVector128Int32_30() => Sse41.ConvertToVector128Int32((sbyte*)pArray1);
- public Vector128<Int32> Sse41_ConvertToVector128Int32_31() => Sse41.ConvertToVector128Int32((byte*)pArray1);
- public Vector128<Int32> Sse41_ConvertToVector128Int32_32() => Sse41.ConvertToVector128Int32((short*)pArray1);
- public Vector128<Int32> Sse41_ConvertToVector128Int32_33() => Sse41.ConvertToVector128Int32((ushort*)pArray1);
- public Vector128<Int64> Sse41_ConvertToVector128Int64_34() => Sse41.ConvertToVector128Int64(GetV128<SByte>());
- public Vector128<Int64> Sse41_ConvertToVector128Int64_35() => Sse41.ConvertToVector128Int64(GetV128<Byte>());
- public Vector128<Int64> Sse41_ConvertToVector128Int64_36() => Sse41.ConvertToVector128Int64(GetV128<Int16>());
- public Vector128<Int64> Sse41_ConvertToVector128Int64_37() => Sse41.ConvertToVector128Int64(GetV128<UInt16>());
- public Vector128<Int64> Sse41_ConvertToVector128Int64_38() => Sse41.ConvertToVector128Int64(GetV128<Int32>());
- public Vector128<Int64> Sse41_ConvertToVector128Int64_39() => Sse41.ConvertToVector128Int64(GetV128<UInt32>());
- public Vector128<Int64> Sse41_ConvertToVector128Int64_40() => Sse41.ConvertToVector128Int64((sbyte*)pArray1);
- public Vector128<Int64> Sse41_ConvertToVector128Int64_41() => Sse41.ConvertToVector128Int64((byte*)pArray1);
- public Vector128<Int64> Sse41_ConvertToVector128Int64_42() => Sse41.ConvertToVector128Int64((short*)pArray1);
- public Vector128<Int64> Sse41_ConvertToVector128Int64_43() => Sse41.ConvertToVector128Int64((ushort*)pArray1);
- public Vector128<Int64> Sse41_ConvertToVector128Int64_44() => Sse41.ConvertToVector128Int64((int*)pArray1);
- public Vector128<Int64> Sse41_ConvertToVector128Int64_45() => Sse41.ConvertToVector128Int64((uint*)pArray1);
- public Vector128<Single> Sse41_DotProduct_46() => Sse41.DotProduct(GetV128<Single>(), GetV128<Single>(), Get<System.Byte>());
- public Vector128<Double> Sse41_DotProduct_47() => Sse41.DotProduct(GetV128<Double>(), GetV128<Double>(), Get<System.Byte>());
- public Byte Sse41_Extract_48() => Sse41.Extract(GetV128<Byte>(), Get<System.Byte>());
- public Int32 Sse41_Extract_49() => Sse41.Extract(GetV128<Int32>(), Get<System.Byte>());
- public UInt32 Sse41_Extract_50() => Sse41.Extract(GetV128<UInt32>(), Get<System.Byte>());
- public Single Sse41_Extract_51() => Sse41.Extract(GetV128<Single>(), Get<System.Byte>());
- public Vector128<Single> Sse41_Floor_52() => Sse41.Floor(GetV128<Single>());
- public Vector128<Double> Sse41_Floor_53() => Sse41.Floor(GetV128<Double>());
- public Vector128<Double> Sse41_FloorScalar_54() => Sse41.FloorScalar(GetV128<Double>());
- public Vector128<Single> Sse41_FloorScalar_55() => Sse41.FloorScalar(GetV128<Single>());
- public Vector128<Double> Sse41_FloorScalar_56() => Sse41.FloorScalar(GetV128<Double>(), GetV128<Double>());
- public Vector128<Single> Sse41_FloorScalar_57() => Sse41.FloorScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<SByte> Sse41_Insert_59() => Sse41.Insert(GetV128<SByte>(), Get<System.SByte>(), 4);
- public Vector128<Byte> Sse41_Insert_60() => Sse41.Insert(GetV128<Byte>(), Get<System.Byte>(), 3);
- public Vector128<Int32> Sse41_Insert_61() => Sse41.Insert(GetV128<Int32>(), Get<System.Int32>(), 2);
- public Vector128<UInt32> Sse41_Insert_62() => Sse41.Insert(GetV128<UInt32>(), Get<System.UInt32>(), 1);
- public Vector128<Single> Sse41_Insert_63() => Sse41.Insert(GetV128<Single>(), GetV128<Single>(), 0x10);
- public Vector128<SByte> Sse41_LoadAlignedVector128NonTemporal_64() => Sse41.LoadAlignedVector128NonTemporal(((sbyte*)pArray1));
- public Vector128<Byte> Sse41_LoadAlignedVector128NonTemporal_65() => Sse41.LoadAlignedVector128NonTemporal(((byte*)pArray1));
- public Vector128<Int16> Sse41_LoadAlignedVector128NonTemporal_66() => Sse41.LoadAlignedVector128NonTemporal(((short*)pArray1));
- public Vector128<UInt16> Sse41_LoadAlignedVector128NonTemporal_67() => Sse41.LoadAlignedVector128NonTemporal(((ushort*)pArray1));
- public Vector128<Int32> Sse41_LoadAlignedVector128NonTemporal_68() => Sse41.LoadAlignedVector128NonTemporal(((int*)pArray1));
- public Vector128<UInt32> Sse41_LoadAlignedVector128NonTemporal_69() => Sse41.LoadAlignedVector128NonTemporal(((uint*)pArray1));
- public Vector128<Int64> Sse41_LoadAlignedVector128NonTemporal_70() => Sse41.LoadAlignedVector128NonTemporal(((long*)pArray1));
- public Vector128<UInt64> Sse41_LoadAlignedVector128NonTemporal_71() => Sse41.LoadAlignedVector128NonTemporal(((ulong*)pArray1));
- public Vector128<SByte> Sse41_Max_72() => Sse41.Max(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<UInt16> Sse41_Max_73() => Sse41.Max(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse41_Max_74() => Sse41.Max(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse41_Max_75() => Sse41.Max(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<SByte> Sse41_Min_76() => Sse41.Min(GetV128<SByte>(), GetV128<SByte>());
- public Vector128<UInt16> Sse41_Min_77() => Sse41.Min(GetV128<UInt16>(), GetV128<UInt16>());
- public Vector128<Int32> Sse41_Min_78() => Sse41.Min(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse41_Min_79() => Sse41.Min(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<UInt16> Sse41_MinHorizontal_80() => Sse41.MinHorizontal(GetV128<UInt16>());
- public Vector128<UInt16> Sse41_MultipleSumAbsoluteDifferences_81() => Sse41.MultipleSumAbsoluteDifferences(GetV128<Byte>(), GetV128<Byte>(), Get<System.Byte>());
- public Vector128<Int64> Sse41_Multiply_82() => Sse41.Multiply(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<Int32> Sse41_MultiplyLow_83() => Sse41.MultiplyLow(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<UInt32> Sse41_MultiplyLow_84() => Sse41.MultiplyLow(GetV128<UInt32>(), GetV128<UInt32>());
- public Vector128<UInt16> Sse41_PackUnsignedSaturate_85() => Sse41.PackUnsignedSaturate(GetV128<Int32>(), GetV128<Int32>());
- public Vector128<Double> Sse41_RoundCurrentDirection_86() => Sse41.RoundCurrentDirection(GetV128<Double>());
- public Vector128<Single> Sse41_RoundCurrentDirection_87() => Sse41.RoundCurrentDirection(GetV128<Single>());
- public Vector128<Double> Sse41_RoundCurrentDirectionScalar_88() => Sse41.RoundCurrentDirectionScalar(GetV128<Double>());
- public Vector128<Double> Sse41_RoundCurrentDirectionScalar_89() => Sse41.RoundCurrentDirectionScalar(GetV128<Double>(), GetV128<Double>());
- public Vector128<Single> Sse41_RoundCurrentDirectionScalar_90() => Sse41.RoundCurrentDirectionScalar(GetV128<Single>());
- public Vector128<Single> Sse41_RoundCurrentDirectionScalar_91() => Sse41.RoundCurrentDirectionScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse41_RoundToNearestInteger_92() => Sse41.RoundToNearestInteger(GetV128<Single>());
- public Vector128<Double> Sse41_RoundToNearestInteger_93() => Sse41.RoundToNearestInteger(GetV128<Double>());
- public Vector128<Double> Sse41_RoundToNearestIntegerScalar_94() => Sse41.RoundToNearestIntegerScalar(GetV128<Double>());
- public Vector128<Double> Sse41_RoundToNearestIntegerScalar_95() => Sse41.RoundToNearestIntegerScalar(GetV128<Double>(), GetV128<Double>());
- public Vector128<Single> Sse41_RoundToNearestIntegerScalar_96() => Sse41.RoundToNearestIntegerScalar(GetV128<Single>());
- public Vector128<Single> Sse41_RoundToNearestIntegerScalar_97() => Sse41.RoundToNearestIntegerScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Single> Sse41_RoundToNegativeInfinity_98() => Sse41.RoundToNegativeInfinity(GetV128<Single>());
- public Vector128<Double> Sse41_RoundToNegativeInfinity_99() => Sse41.RoundToNegativeInfinity(GetV128<Double>());
- public Vector128<Double> Sse41_RoundToNegativeInfinityScalar_100() => Sse41.RoundToNegativeInfinityScalar(GetV128<Double>());
- public Vector128<Double> Sse41_RoundToNegativeInfinityScalar_101() => Sse41.RoundToNegativeInfinityScalar(GetV128<Double>(), GetV128<Double>());
- public Vector128<Single> Sse41_RoundToNegativeInfinityScalar_102() => Sse41.RoundToNegativeInfinityScalar(GetV128<Single>());
- public Vector128<Single> Sse41_RoundToNegativeInfinityScalar_103() => Sse41.RoundToNegativeInfinityScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Double> Sse41_RoundToPositiveInfinity_104() => Sse41.RoundToPositiveInfinity(GetV128<Double>());
- public Vector128<Single> Sse41_RoundToPositiveInfinity_105() => Sse41.RoundToPositiveInfinity(GetV128<Single>());
- public Vector128<Double> Sse41_RoundToPositiveInfinityScalar_106() => Sse41.RoundToPositiveInfinityScalar(GetV128<Double>());
- public Vector128<Double> Sse41_RoundToPositiveInfinityScalar_107() => Sse41.RoundToPositiveInfinityScalar(GetV128<Double>(), GetV128<Double>());
- public Vector128<Single> Sse41_RoundToPositiveInfinityScalar_108() => Sse41.RoundToPositiveInfinityScalar(GetV128<Single>());
- public Vector128<Single> Sse41_RoundToPositiveInfinityScalar_109() => Sse41.RoundToPositiveInfinityScalar(GetV128<Single>(), GetV128<Single>());
- public Vector128<Double> Sse41_RoundToZero_110() => Sse41.RoundToZero(GetV128<Double>());
- public Vector128<Single> Sse41_RoundToZero_111() => Sse41.RoundToZero(GetV128<Single>());
- public Vector128<Double> Sse41_RoundToZeroScalar_112() => Sse41.RoundToZeroScalar(GetV128<Double>());
- public Vector128<Double> Sse41_RoundToZeroScalar_113() => Sse41.RoundToZeroScalar(GetV128<Double>(), GetV128<Double>());
- public Vector128<Single> Sse41_RoundToZeroScalar_114() => Sse41.RoundToZeroScalar(GetV128<Single>());
- public Vector128<Single> Sse41_RoundToZeroScalar_115() => Sse41.RoundToZeroScalar(GetV128<Single>(), GetV128<Single>());
- public Boolean Sse41_TestC_116() => Sse41.TestC(GetV128<SByte>(), GetV128<SByte>());
- public Boolean Sse41_TestC_117() => Sse41.TestC(GetV128<Byte>(), GetV128<Byte>());
- public Boolean Sse41_TestC_118() => Sse41.TestC(GetV128<Int16>(), GetV128<Int16>());
- public Boolean Sse41_TestC_119() => Sse41.TestC(GetV128<UInt16>(), GetV128<UInt16>());
- public Boolean Sse41_TestC_120() => Sse41.TestC(GetV128<Int32>(), GetV128<Int32>());
- public Boolean Sse41_TestC_121() => Sse41.TestC(GetV128<UInt32>(), GetV128<UInt32>());
- public Boolean Sse41_TestC_122() => Sse41.TestC(GetV128<Int64>(), GetV128<Int64>());
- public Boolean Sse41_TestC_123() => Sse41.TestC(GetV128<UInt64>(), GetV128<UInt64>());
- public Boolean Sse41_TestNotZAndNotC_124() => Sse41.TestNotZAndNotC(GetV128<SByte>(), GetV128<SByte>());
- public Boolean Sse41_TestNotZAndNotC_125() => Sse41.TestNotZAndNotC(GetV128<Byte>(), GetV128<Byte>());
- public Boolean Sse41_TestNotZAndNotC_126() => Sse41.TestNotZAndNotC(GetV128<Int16>(), GetV128<Int16>());
- public Boolean Sse41_TestNotZAndNotC_127() => Sse41.TestNotZAndNotC(GetV128<UInt16>(), GetV128<UInt16>());
- public Boolean Sse41_TestNotZAndNotC_128() => Sse41.TestNotZAndNotC(GetV128<Int32>(), GetV128<Int32>());
- public Boolean Sse41_TestNotZAndNotC_129() => Sse41.TestNotZAndNotC(GetV128<UInt32>(), GetV128<UInt32>());
- public Boolean Sse41_TestNotZAndNotC_130() => Sse41.TestNotZAndNotC(GetV128<Int64>(), GetV128<Int64>());
- public Boolean Sse41_TestNotZAndNotC_131() => Sse41.TestNotZAndNotC(GetV128<UInt64>(), GetV128<UInt64>());
- public Boolean Sse41_TestZ_132() => Sse41.TestZ(GetV128<SByte>(), GetV128<SByte>());
- public Boolean Sse41_TestZ_133() => Sse41.TestZ(GetV128<Byte>(), GetV128<Byte>());
- public Boolean Sse41_TestZ_134() => Sse41.TestZ(GetV128<Int16>(), GetV128<Int16>());
- public Boolean Sse41_TestZ_135() => Sse41.TestZ(GetV128<UInt16>(), GetV128<UInt16>());
- public Boolean Sse41_TestZ_136() => Sse41.TestZ(GetV128<Int32>(), GetV128<Int32>());
- public Boolean Sse41_TestZ_137() => Sse41.TestZ(GetV128<UInt32>(), GetV128<UInt32>());
- public Boolean Sse41_TestZ_138() => Sse41.TestZ(GetV128<Int64>(), GetV128<Int64>());
- public Boolean Sse41_TestZ_139() => Sse41.TestZ(GetV128<UInt64>(), GetV128<UInt64>());
- public Vector128<Int64> Sse42_CompareGreaterThan_0() => Sse42.CompareGreaterThan(GetV128<Int64>(), GetV128<Int64>());
- public UInt32 Sse42_Crc32_1() => Sse42.Crc32(Get<System.UInt32>(), Get<System.Byte>());
- public UInt32 Sse42_Crc32_2() => Sse42.Crc32(Get<System.UInt32>(), Get<System.UInt16>());
- public UInt32 Sse42_Crc32_3() => Sse42.Crc32(Get<System.UInt32>(), Get<System.UInt32>());
-
- public Vector128<byte> Vector128_Create_1() => Vector128.Create(Get<byte>());
- public Vector128<sbyte> Vector128_Create_2() => Vector128.Create(Get<sbyte>());
- public Vector128<short> Vector128_Create_3() => Vector128.Create(Get<short>());
- public Vector128<ushort> Vector128_Create_4() => Vector128.Create(Get<ushort>());
- public Vector128<int> Vector128_Create_5() => Vector128.Create(Get<int>());
- public Vector128<uint> Vector128_Create_6() => Vector128.Create(Get<uint>());
- public Vector128<long> Vector128_Create_7() => Vector128.Create(Get<long>());
- public Vector128<ulong> Vector128_Create_8() => Vector128.Create(Get<ulong>());
- public Vector128<float> Vector128_Create_9() => Vector128.Create(Get<float>());
- public Vector128<double> Vector128_Create_10() => Vector128.Create(Get<double>());
- public Vector128<double> Vector128_Create_11() => Vector128.Create(Get<double>(), Get<double>());
- public Vector128<long> Vector128_Create_12() => Vector128.Create(Get<long>(), Get<long>());
- public Vector128<ulong> Vector128_Create_13() => Vector128.Create(Get<ulong>(), Get<ulong>());
- public Vector128<float> Vector128_Create_14() => Vector128.Create(Get<float>(), Get<float>(), Get<float>(), Get<float>());
- public Vector128<int> Vector128_Create_15() => Vector128.Create(Get<int>(), Get<int>(), Get<int>(), Get<int>());
- public Vector128<uint> Vector128_Create_16() => Vector128.Create(Get<uint>(), Get<uint>(), Get<uint>(), Get<uint>());
- public Vector128<ushort> Vector128_Create_17() => Vector128.Create(Get<ushort>(), Get<ushort>(), Get<ushort>(), Get<ushort>(), Get<ushort>(), Get<ushort>(), Get<ushort>(), Get<ushort>());
- public Vector128<short> Vector128_Create_18() => Vector128.Create(Get<short>(), Get<short>(), Get<short>(), Get<short>(), Get<short>(), Get<short>(), Get<short>(), Get<short>());
- public Vector128<sbyte> Vector128_Create_20() => Vector128.Create(Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>(), Get<sbyte>());
-
- public int Vector128_CreateScalarUnsafe_1() => Sse2.Add(Vector128.CreateScalarUnsafe(42), Vector128.CreateScalarUnsafe(8)).GetElement(0);
- public double Vector128_CreateScalarUnsafe_2() => Sse2.Add(Vector128.CreateScalarUnsafe(42.0), Vector128.CreateScalarUnsafe(8.0)).GetElement(0);
-
- public Vector128<byte> Vector128_int_to_byte() => Vector128_Create_15().AsByte();
- public Vector128<ulong> Vector128_int_to_ulong() => Vector128_Create_15().AsUInt64();
- public Vector128<int> Vector128_byte_to_int() => Vector128_Create_20().AsInt32();
-} \ No newline at end of file
diff --git a/netcore/tests/HwIntrinsics/SRI-reference-data.txt b/netcore/tests/HwIntrinsics/SRI-reference-data.txt
deleted file mode 100644
index f28524ffd8f..00000000000
--- a/netcore/tests/HwIntrinsics/SRI-reference-data.txt
+++ /dev/null
@@ -1,595 +0,0 @@
-GetArray2Data: . array2: ()
-ReloadArrays: . array2: ()
-Sse_Add_0: <929125630, 457013920, 373885180, 399296580>. array2: ()
-Sse_AddScalar_1: <831905660, 361925120, 171923890, 163625200>. array2: ()
-Sse_And_2: <37962244, 63456256, 77604050, 337699840>. array2: ()
-Sse_AndNot_3: <-7.530605E-39, -9.442987E-38, -1.5179037E-36, -2.3605184E-38>. array2: ()
-Sse_CompareEqual_4: <0, 0, 0, 0>. array2: ()
-Sse_CompareGreaterThan_5: <0, 0, 0, 0>. array2: ()
-Sse_CompareGreaterThanOrEqual_6: <0, 0, NaN, 0>. array2: ()
-Sse_CompareLessThan_7: <0, 0, 0, 0>. array2: ()
-Sse_CompareLessThanOrEqual_8: <0, 0, 0, 0>. array2: ()
-Sse_CompareNotEqual_9: <NaN, NaN, NaN, NaN>. array2: ()
-Sse_CompareNotGreaterThan_10: <0, NaN, 0, NaN>. array2: ()
-Sse_CompareNotGreaterThanOrEqual_11: <0, 0, 0, 0>. array2: ()
-Sse_CompareNotLessThan_12: <0, NaN, NaN, 0>. array2: ()
-Sse_CompareNotLessThanOrEqual_13: <0, 0, 0, 0>. array2: ()
-Sse_CompareOrdered_14: <NaN, NaN, NaN, NaN>. array2: ()
-Sse_CompareScalarEqual_15: <0, 165247660, 501148420, 424096580>. array2: ()
-Sse_CompareScalarGreaterThan_16: <0, -510012770, -65459412, -256915410>. array2: ()
-Sse_CompareScalarGreaterThanOrEqual_17: <NaN, 678421950, 435046200, 55114016>. array2: ()
-Sse_CompareScalarLessThan_18: <0, 286352260, 67081924, 391137340>. array2: ()
-Sse_CompareScalarLessThanOrEqual_19: <NaN, -588649900, -401212100, -120477656>. array2: ()
-Sse_CompareScalarNotEqual_20: <NaN, 198373810, 122680850, 358035900>. array2: ()
-Sse_CompareScalarNotGreaterThan_21: <0, 675093900, 250508290, 382580160>. array2: ()
-Sse_CompareScalarNotGreaterThanOrEqual_22: <NaN, 79479856, 432719200, 149407550>. array2: ()
-Sse_CompareScalarNotLessThan_23: <0, -669115970, -28078068, -23915620>. array2: ()
-Sse_CompareScalarNotLessThanOrEqual_24: <0, -263062030, -243626220, -327881220>. array2: ()
-Sse_CompareScalarOrdered_25: <NaN, 424523140, 329012580, 166258130>. array2: ()
-Sse_CompareScalarOrderedEqual_26: False. array2: ()
-Sse_CompareScalarOrderedGreaterThan_27: True. array2: ()
-Sse_CompareScalarOrderedGreaterThanOrEqual_28: False. array2: ()
-Sse_CompareScalarOrderedLessThan_29: False. array2: ()
-Sse_CompareScalarOrderedLessThanOrEqual_30: True. array2: ()
-Sse_CompareScalarOrderedNotEqual_31: True. array2: ()
-Sse_CompareScalarUnordered_32: <0, 0, 0, 0>. array2: ()
-Sse_CompareScalarUnorderedEqual_33: False. array2: ()
-Sse_CompareScalarUnorderedGreaterThan_34: False. array2: ()
-Sse_CompareScalarUnorderedGreaterThanOrEqual_35: True. array2: ()
-Sse_CompareScalarUnorderedLessThan_36: False. array2: ()
-Sse_CompareScalarUnorderedLessThanOrEqual_37: False. array2: ()
-Sse_CompareScalarUnorderedNotEqual_38: True. array2: ()
-Sse_CompareUnordered_39: <0, 0, 0, 0>. array2: ()
-Sse_ConvertScalarToVector128Single_40: <1.7130938E+09, 673981570, 435517900, 284626240>. array2: ()
-Sse_ConvertToInt32_41: -200472784. array2: ()
-Sse_ConvertToInt32WithTruncation_42: 476591168. array2: ()
-Sse_Divide_43: <0.4255711, 1.6555679, 1.080426, 2.3567653>. array2: ()
-Sse_DivideScalar_44: <Infinity, 94416510, 474155170, 220063580>. array2: ()
-Sse_LoadAlignedVector128_46: <0, 0.5, 1, 1.5>. array2: ()
-Sse_LoadHigh_47: <213905200, 534451330, 0, 0.5>. array2: ()
-Sse_LoadLow_48: <0, 0.5, 526352540, 304848960>. array2: ()
-Sse_LoadScalarVector128_49: <0, 0, 0, 0>. array2: ()
-Sse_LoadVector128_50: <0, 0.5, 1, 1.5>. array2: ()
-Sse_Max_51: <-304293300, -344651520, -332293340, -228331310>. array2: ()
-Sse_MaxScalar_52: <0, 0, 0, 0>. array2: ()
-Sse_Min_53: <-659012200, -329070240, -410852960, -194900770>. array2: ()
-Sse_MinScalar_54: <303572000, 262783810, 75313750, 48754888>. array2: ()
-Sse_MoveHighToLow_55: <152952030, 120658176, 416098600, 151711410>. array2: ()
-Sse_MoveLowToHigh_56: <594499460, 78836810, 799263700, 431919140>. array2: ()
-Sse_MoveMask_57: 0. array2: ()
-Sse_MoveScalar_58: <581809900, 70783160, 158188660, 309818560>. array2: ()
-Sse_Multiply_59: <-8.335214E+16, -4.255089E+16, -7.327157E+16, -2.6699806E+15>. array2: ()
-Sse_MultiplyScalar_60: <1.7725418E+17, 160780880, 114840160, 312372350>. array2: ()
-Sse_Or_61: <-1.0672764E+09, -8.5731497E+09, -307076030, -389938500>. array2: ()
-Sse_Prefetch0_62: . array2: ()
-Sse_Prefetch1_63: . array2: ()
-Sse_Prefetch2_64: . array2: ()
-Sse_PrefetchNonTemporal_65: . array2: ()
-Sse_Reciprocal_66: <-1.2159944E-08, -1.1204975E-08, -1.8821993E-09, -7.841663E-09>. array2: ()
-Sse_ReciprocalScalar_67: <3.4578989E-09, 56211220, 81027630, 106894210>. array2: ()
-Sse_ReciprocalScalar_68: <1.2871624E-09, 448893340, 230181550, 34451628>. array2: ()
-Sse_ReciprocalSqrt_69: <4.287809E-05, 0.0001977086, 4.4345856E-05, 8.9362264E-05>. array2: ()
-Sse_ReciprocalSqrtScalar_70: <NaN, -647177900, -458123200, -197744160>. array2: ()
-Sse_ReciprocalSqrtScalar_71: <NaN, 437562400, 312167300, 75870080>. array2: ()
-Sse_Shuffle_72: <103318530, 633020600, 519279620, 446014980>. array2: ()
-Sse_Sqrt_73: <32375.541, 18467.787, 10546.897, 13361.126>. array2: ()
-Sse_SqrtScalar_74: <NaN, -127137670, -374733950, -304894900>. array2: ()
-Sse_SqrtScalar_75: <0, -161208180, -370718370, -192715920>. array2: ()
-Sse_Store_76: . array2: (<524471360, 692894400, 517360540, 111962010>)
-Sse_StoreAligned_77: . array2: (<668176450, 603658900, 34112764, 33997604>)
-Sse_StoreAlignedNonTemporal_78: . array2: (<411258080, 295905300, 370917700, 136368000>)
-Sse_StoreFence_79: . array2: ()
-Sse_StoreHigh_80: . array2: (<-89017680, -350302900, 0, 0>)
-Sse_StoreLow_81: . array2: (<-934469570, -384415970, 0, 0>)
-Sse_StoreScalar_82: . array2: (<630363700, 0, 0, 0>)
-Sse_Subtract_83: <388175420, -28251904, -262372130, -16946368>. array2: ()
-Sse_SubtractScalar_84: <1.2341728E+09, 81653990, 332236930, 231184850>. array2: ()
-Sse_UnpackHigh_85: <234336190, -201399150, 11366093, -227744130>. array2: ()
-Sse_UnpackLow_86: <-460082180, 976768400, -71266130, 684022100>. array2: ()
-Sse_Xor_87: <5.454208E-37, 7.558558E-37, 2.2277044E-38, 3.4608778E-35>. array2: ()
-Sse2_Add_0: <157, 30, 117, 68, 254, 250, 198, 109, 226, 191, 114, 70, 98, 64, 124, 115>. array2: ()
-Sse2_Add_1: <111, -100, 31, 18, -104, 36, 62, 15, 116, -33, -46, -39, -31, -69, 75, -12>. array2: ()
-Sse2_Add_2: <-17349, 32646, 27366, 17847, -14439, 23263, -28227, 26507>. array2: ()
-Sse2_Add_3: <48597, 44533, 11015, 30391, 1888, 41608, 61458, 29007>. array2: ()
-Sse2_Add_4: <-2099012909, -1214463057, 748055490, 587046172>. array2: ()
-Sse2_Add_5: <2692053887, 675414813, 2668354831, 2361717631>. array2: ()
-Sse2_Add_6: <-5569845745187161295, 8239220397857138507>. array2: ()
-Sse2_Add_7: <313415891815243217, 1695776975936769365>. array2: ()
-Sse2_Add_8: <-1377217479, -1656960814>. array2: ()
-Sse2_AddSaturate_10: <255, 255, 255, 255, 180, 229, 94, 255, 255, 255, 255, 255, 255, 255, 245, 223>. array2: ()
-Sse2_AddSaturate_11: <32767, 22517, -782, 24849, 21420, 11609, 15738, 32767>. array2: ()
-Sse2_AddSaturate_12: <65535, 65535, 64391, 65535, 65535, 65535, 65535, 65535>. array2: ()
-Sse2_AddSaturate_9: <30, -24, 56, -11, 39, 80, 124, -91, -30, -63, 34, -24, 49, 33, 116, -108>. array2: ()
-Sse2_AddScalar_13: <1949344437, 759608663>. array2: ()
-Sse2_And_14: <225, 216, 33, 65, 4, 90, 0, 20, 64, 0, 0, 0, 121, 64, 24, 28>. array2: ()
-Sse2_And_15: <-62, 40, 32, 68, 91, 8, 66, 20, 0, 32, -108, 1, 16, 64, 36, 17>. array2: ()
-Sse2_And_16: <8280, 2066, 10244, 17476, 2112, 668, 1248, 108>. array2: ()
-Sse2_And_17: <17713, 8192, 51449, 4120, 1280, 770, 8738, 608>. array2: ()
-Sse2_And_18: <1485444, 603982148, 9310754, 1078465665>. array2: ()
-Sse2_And_19: <2674703, 537657472, 176440336, 142610944>. array2: ()
-Sse2_And_20: <2459037974327738368, 2396479261679681876>. array2: ()
-Sse2_And_21: <5332368611468922716, 576462964233077344>. array2: ()
-Sse2_And_22: <1343127624, 1688764441>. array2: ()
-Sse2_AndNot_23: <0, 65, 217, 228, 14, 22, 64, 132, 136, 129, 61, 192, 36, 32, 198, 140>. array2: ()
-Sse2_AndNot_24: <4, -117, 73, 64, 26, -84, 36, 32, 1, 4, 80, 6, -128, 3, -96, 4>. array2: ()
-Sse2_AndNot_25: <-32112, 2875, 15473, 14848, 6145, 5914, 66, 10025>. array2: ()
-Sse2_AndNot_26: <4117, 2596, 32778, 1472, 40198, 16402, 228, 4164>. array2: ()
-Sse2_AndNot_27: <134387840, 1703968, 705053332, 190873920>. array2: ()
-Sse2_AndNot_28: <2217877536, 2487419010, 2370521409, 2158904832>. array2: ()
-Sse2_AndNot_29: <-8914749681309833840, -7200969722687336402>. array2: ()
-Sse2_AndNot_30: <2901470452777135120, 2596364778247046146>. array2: ()
-Sse2_AndNot_31: <-2.308464469769642E-308, -4.5392050050569185E-306>. array2: ()
-Sse2_Average_32: <121, 65, 144, 155, 187, 250, 52, 133, 208, 55, 114, 135, 121, 199, 49, 158>. array2: ()
-Sse2_Average_33: <29628, 1975, 15380, 11051, 12362, 8455, 11592, 6841>. array2: ()
-Sse2_CompareEqual_34: <0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_CompareEqual_35: <0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_CompareEqual_36: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_CompareEqual_37: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_CompareEqual_38: <0, 0, 0, 0>. array2: ()
-Sse2_CompareEqual_39: <0, 0, 0, 0>. array2: ()
-Sse2_CompareEqual_40: <0, 0>. array2: ()
-Sse2_CompareGreaterThan_41: <-1, -1, 0, 0, -1, -1, -1, 0, 0, 0, -1, 0, 0, -1, -1, 0>. array2: ()
-Sse2_CompareGreaterThan_42: <0, -1, -1, -1, -1, -1, 0, -1>. array2: ()
-Sse2_CompareGreaterThan_43: <-1, -1, -1, -1>. array2: ()
-Sse2_CompareGreaterThan_44: <0, NaN>. array2: ()
-Sse2_CompareGreaterThanOrEqual_45: <0, 0>. array2: ()
-Sse2_CompareLessThan_46: <0, 0, 0, 0, 0, -1, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_CompareLessThan_47: <-1, 0, 0, 0, -1, 0, -1, 0>. array2: ()
-Sse2_CompareLessThan_48: <0, 0, 0, 0>. array2: ()
-Sse2_CompareLessThan_49: <0, 0>. array2: ()
-Sse2_CompareLessThanOrEqual_50: <NaN, NaN>. array2: ()
-Sse2_CompareNotEqual_51: <NaN, NaN>. array2: ()
-Sse2_CompareNotGreaterThan_52: <NaN, NaN>. array2: ()
-Sse2_CompareNotGreaterThanOrEqual_53: <0, 0>. array2: ()
-Sse2_CompareNotLessThan_54: <0, 0>. array2: ()
-Sse2_CompareNotLessThanOrEqual_55: <NaN, NaN>. array2: ()
-Sse2_CompareOrdered_56: <NaN, NaN>. array2: ()
-Sse2_CompareScalarEqual_57: <0, 2083712820>. array2: ()
-Sse2_CompareScalarGreaterThan_58: <0, 1650780952>. array2: ()
-Sse2_CompareScalarGreaterThanOrEqual_59: <NaN, 708005949>. array2: ()
-Sse2_CompareScalarLessThan_60: <0, 1627148431>. array2: ()
-Sse2_CompareScalarLessThanOrEqual_61: <0, 1720855119>. array2: ()
-Sse2_CompareScalarNotEqual_62: <NaN, 1203562733>. array2: ()
-Sse2_CompareScalarNotGreaterThan_63: <0, 743511762>. array2: ()
-Sse2_CompareScalarNotGreaterThanOrEqual_64: <0, 2122767112>. array2: ()
-Sse2_CompareScalarNotLessThan_65: <0, -495948320>. array2: ()
-Sse2_CompareScalarNotLessThanOrEqual_66: <NaN, 308710313>. array2: ()
-Sse2_CompareScalarOrdered_67: <NaN, 406820521>. array2: ()
-Sse2_CompareScalarOrderedEqual_68: False. array2: ()
-Sse2_CompareScalarOrderedGreaterThan_69: False. array2: ()
-Sse2_CompareScalarOrderedGreaterThanOrEqual_70: True. array2: ()
-Sse2_CompareScalarOrderedLessThan_71: False. array2: ()
-Sse2_CompareScalarOrderedLessThanOrEqual_72: False. array2: ()
-Sse2_CompareScalarOrderedNotEqual_73: True. array2: ()
-Sse2_CompareScalarUnordered_74: <0, 1260970130>. array2: ()
-Sse2_CompareScalarUnorderedEqual_75: False. array2: ()
-Sse2_CompareScalarUnorderedGreaterThan_76: False. array2: ()
-Sse2_CompareScalarUnorderedGreaterThanOrEqual_77: False. array2: ()
-Sse2_CompareScalarUnorderedLessThan_78: False. array2: ()
-Sse2_CompareScalarUnorderedLessThanOrEqual_79: False. array2: ()
-Sse2_CompareScalarUnorderedNotEqual_80: True. array2: ()
-Sse2_CompareUnordered_81: <0, 0>. array2: ()
-Sse2_ConvertScalarToVector128Double_82: <-593819705, -1566865401>. array2: ()
-Sse2_ConvertScalarToVector128Double_83: <264559328, 0>. array2: ()
-Sse2_ConvertScalarToVector128Int32_84: <1234688916, 0, 0, 0>. array2: ()
-Sse2_ConvertScalarToVector128Single_85: <336991780, 0, 0, 0>. array2: ()
-Sse2_ConvertScalarToVector128UInt32_86: <3853626177, 0, 0, 0>. array2: ()
-Sse2_ConvertToInt32_87: 1026923545. array2: ()
-Sse2_ConvertToInt32_88: 1003953677. array2: ()
-Sse2_ConvertToInt32WithTruncation_89: -1221922084. array2: ()
-Sse2_ConvertToUInt32_90: 2969051109. array2: ()
-Sse2_ConvertToVector128Double_91: <-324237430, -610879060>. array2: ()
-Sse2_ConvertToVector128Double_92: <0, 0>. array2: ()
-Sse2_ConvertToVector128Int32_93: <401491456, 32911600, 307468416, 3629614>. array2: ()
-Sse2_ConvertToVector128Int32_94: <695640577, 175680099, 0, 0>. array2: ()
-Sse2_ConvertToVector128Int32WithTruncation_95: <-341060096, -260400640, -35966700, -315059424>. array2: ()
-Sse2_ConvertToVector128Int32WithTruncation_96: <605491771, 1198610225, 0, 0>. array2: ()
-Sse2_ConvertToVector128Single_97: <1.8590148E+09, 741157630, 88313440, 1.6104324E+09>. array2: ()
-Sse2_ConvertToVector128Single_98: <861460740, 2.0822572E+09, 0, 0>. array2: ()
-Sse2_Divide_99: <-0.41013863773247955, -2.2583900973508606>. array2: ()
-Sse2_DivideScalar_100: <0.23868365208310682, 453983282>. array2: ()
-Sse2_Extract_101: 9206. array2: ()
-Sse2_Insert_103: <0, 0, -10045, 0, 0, 0, 0, 0>. array2: ()
-Sse2_Insert_104: <20620, 35164, 54090, 58235, 16240, 65465, 19696, 17652>. array2: ()
-Sse2_LoadAlignedVector128_105: <0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15>. array2: ()
-Sse2_LoadAlignedVector128_106: <0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15>. array2: ()
-Sse2_LoadAlignedVector128_107: <256, 770, 1284, 1798, 2312, 2826, 3340, 3854>. array2: ()
-Sse2_LoadAlignedVector128_108: <256, 770, 1284, 1798, 2312, 2826, 3340, 3854>. array2: ()
-Sse2_LoadAlignedVector128_109: <50462976, 117835012, 185207048, 252579084>. array2: ()
-Sse2_LoadAlignedVector128_110: <50462976, 117835012, 185207048, 252579084>. array2: ()
-Sse2_LoadAlignedVector128_111: <506097522914230528, 1084818905618843912>. array2: ()
-Sse2_LoadAlignedVector128_112: <506097522914230528, 1084818905618843912>. array2: ()
-Sse2_LoadAlignedVector128_113: <0, 0.3333333432674408>. array2: ()
-Sse2_LoadFence_114: . array2: ()
-Sse2_LoadHigh_115: <242191237, 0>. array2: ()
-Sse2_LoadLow_116: <0, 0>. array2: ()
-Sse2_LoadScalarVector128_117: <0, 0>. array2: ()
-Sse2_LoadScalarVector128_118: <50462976, 0, 0, 0>. array2: ()
-Sse2_LoadScalarVector128_119: <50462976, 0, 0, 0>. array2: ()
-Sse2_LoadScalarVector128_120: <506097522914230528, 0>. array2: ()
-Sse2_LoadScalarVector128_121: <506097522914230528, 0>. array2: ()
-Sse2_LoadVector128_122: <0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15>. array2: ()
-Sse2_LoadVector128_123: <0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15>. array2: ()
-Sse2_LoadVector128_124: <256, 770, 1284, 1798, 2312, 2826, 3340, 3854>. array2: ()
-Sse2_LoadVector128_125: <256, 770, 1284, 1798, 2312, 2826, 3340, 3854>. array2: ()
-Sse2_LoadVector128_126: <50462976, 117835012, 185207048, 252579084>. array2: ()
-Sse2_LoadVector128_127: <50462976, 117835012, 185207048, 252579084>. array2: ()
-Sse2_LoadVector128_128: <506097522914230528, 1084818905618843912>. array2: ()
-Sse2_LoadVector128_129: <506097522914230528, 1084818905618843912>. array2: ()
-Sse2_LoadVector128_130: <0, 0.3333333432674408>. array2: ()
-Sse2_MaskMove_131: . array2: ()
-Sse2_MaskMove_132: . array2: ()
-Sse2_Max_133: <46, 154, 117, 221, 251, 245, 249, 212, 128, 167, 140, 244, 205, 138, 224, 238>. array2: ()
-Sse2_Max_134: <17360, 32429, 18775, 858, 14102, 30506, -5851, 30258>. array2: ()
-Sse2_Max_135: <0, 0>. array2: ()
-Sse2_MaxScalar_136: <1355081192, 371420829>. array2: ()
-Sse2_MemoryFence_137: . array2: ()
-Sse2_Min_138: <117, 60, 0, 28, 52, 46, 24, 73, 91, 55, 124, 123, 212, 167, 206, 71>. array2: ()
-Sse2_Min_139: <4773, -26258, -31045, -14134, -19902, -7278, 200, -20325>. array2: ()
-Sse2_Min_140: <-498292418, -287844603>. array2: ()
-Sse2_MinScalar_141: <-719494121, 556225841>. array2: ()
-Sse2_MoveMask_142: 0. array2: ()
-Sse2_MoveMask_143: 17749. array2: ()
-Sse2_MoveMask_144: 3. array2: ()
-Sse2_MoveScalar_145: <358216876, 14573030>. array2: ()
-Sse2_MoveScalar_146: <8026354353478850732, 0>. array2: ()
-Sse2_MoveScalar_147: <11960848426434193404, 0>. array2: ()
-Sse2_Multiply_148: <946464580954712675, 1322844109440369358>. array2: ()
-Sse2_Multiply_149: <3.889913259521027E+18, 4.28768515710415E+17>. array2: ()
-Sse2_MultiplyAddAdjacent_150: <0, 0, 0, 0>. array2: ()
-Sse2_MultiplyHigh_151: <-136, -665, -3509, -2039, 681, -3653, -2098, -2340>. array2: ()
-Sse2_MultiplyHigh_152: <26601, 1648, 2913, 1028, 2499, 1409, 42537, 3604>. array2: ()
-Sse2_MultiplyLow_153: <18244, -27954, -20206, 24690, 3356, 12024, -31581, -73>. array2: ()
-Sse2_MultiplyLow_154: <47482, 14636, 24333, 13435, 33030, 46832, 57179, 12537>. array2: ()
-Sse2_MultiplyScalar_155: <-5.863772895193802E+17, 1111050795>. array2: ()
-Sse2_Or_156: <247, 124, 221, 191, 116, 178, 185, 249, 127, 223, 127, 207, 185, 211, 231, 131>. array2: ()
-Sse2_Or_157: <-3, -68, -69, -65, 65, 89, -1, -23, -39, -20, -41, -2, -1, -11, -12, -1>. array2: ()
-Sse2_Or_158: <-1159, -16514, 32723, -4130, 18431, -1, 24238, -16525>. array2: ()
-Sse2_Or_159: <64282, 25131, 53526, 24527, 15801, 20397, 6444, 9233>. array2: ()
-Sse2_Or_160: <-1363169726, -427819146, -16777987, -123350034>. array2: ()
-Sse2_Or_161: <4021272047, 3992975279, 3681512439, 4277138431>. array2: ()
-Sse2_Or_162: <8070443587545201599, 9219844371637592951>. array2: ()
-Sse2_Or_163: <9104447756691958458, 8610876712411787262>. array2: ()
-Sse2_Or_164: <6406789608, 2012196350>. array2: ()
-Sse2_PackSignedSaturate_165: <-128, -128, 127, -128, 127, -128, 127, -128, 127, 127, 127, 127, -128, 127, 127, 127>. array2: ()
-Sse2_PackSignedSaturate_166: <-32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768>. array2: ()
-Sse2_PackUnsignedSaturate_167: <0, 0, 255, 0, 255, 0, 0, 0, 0, 0, 255, 0, 255, 0, 255, 0>. array2: ()
-Sse2_ShiftLeftLogical_168: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical_169: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical_170: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical_171: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical_172: <0, 0>. array2: ()
-Sse2_ShiftLeftLogical_173: <0, 0>. array2: ()
-Sse2_ShiftLeftLogical_174: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical_175: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical_176: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical_177: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical_178: <0, 0>. array2: ()
-Sse2_ShiftLeftLogical_179: <0, 0>. array2: ()
-Sse2_ShiftLeftLogical128BitLane_180: <0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical128BitLane_181: <0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical128BitLane_182: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical128BitLane_183: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical128BitLane_184: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftLeftLogical128BitLane_185: <0, 2927165440, 1053439790, 1500076848>. array2: ()
-Sse2_ShiftLeftLogical128BitLane_186: <0, 0>. array2: ()
-Sse2_ShiftLeftLogical128BitLane_187: <0, 0>. array2: ()
-Sse2_ShiftRightArithmetic_188: <-1, 0, 0, 0, -1, 0, -1, 0>. array2: ()
-Sse2_ShiftRightArithmetic_189: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightArithmetic_190: <-1, 0, -1, 0, -1, 0, -1, 0>. array2: ()
-Sse2_ShiftRightArithmetic_191: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical_192: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical_193: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical_194: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical_195: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical_196: <5844001493094162482, 6955472380474049021>. array2: ()
-Sse2_ShiftRightLogical_197: <0, 0>. array2: ()
-Sse2_ShiftRightLogical_198: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical_199: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical_200: <607, 772, 805, 541>. array2: ()
-Sse2_ShiftRightLogical_201: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical_202: <0, 0>. array2: ()
-Sse2_ShiftRightLogical_203: <0, 0>. array2: ()
-Sse2_ShiftRightLogical128BitLane_204: <-122, 120, 50, -69, -84, 56, 111, 51, -56, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical128BitLane_205: <0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical128BitLane_206: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical128BitLane_207: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical128BitLane_208: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical128BitLane_209: <0, 0, 0, 0>. array2: ()
-Sse2_ShiftRightLogical128BitLane_210: <0, 0>. array2: ()
-Sse2_ShiftRightLogical128BitLane_211: <0, 0>. array2: ()
-Sse2_Shuffle_212: <170398073, 1558314255, 170398073, 170398073>. array2: ()
-Sse2_Shuffle_213: <1028956739, 400946704>. array2: ()
-Sse2_Shuffle_214: <525659078, 525659078, 525659078, 836067957>. array2: ()
-Sse2_ShuffleHigh_215: <-30644, 9774, 5424, 9064, 22189, 20978, 20978, -13303>. array2: ()
-Sse2_ShuffleHigh_216: <15529, 15138, 12456, 25850, 11624, 18411, 11624, 11624>. array2: ()
-Sse2_ShuffleLow_217: <2167, 2167, 11159, 11159, -6897, 30123, -28312, 31844>. array2: ()
-Sse2_ShuffleLow_218: <20074, 15183, 15183, 15183, 61168, 15156, 23107, 363>. array2: ()
-Sse2_Sqrt_219: <0, 0>. array2: ()
-Sse2_SqrtScalar_220: <NaN, -857790740>. array2: ()
-Sse2_SqrtScalar_221: <NaN, 0>. array2: ()
-Sse2_Store_222: . array2: (<195, 45, 98, 147, 221, 239, 202, 231, 116, 155, 244, 160, 200, 64, 32, 146>)
-Sse2_Store_223: . array2: (<70, 19, 250, 175, 238, 14, 37, 240, 49, 43, 250, 176, 136, 252, 84, 230>)
-Sse2_Store_224: . array2: (<194, 151, 9, 235, 109, 26, 11, 183, 67, 160, 63, 166, 253, 115, 188, 164>)
-Sse2_Store_225: . array2: (<29, 146, 117, 106, 149, 161, 240, 52, 127, 242, 243, 123, 51, 244, 106, 99>)
-Sse2_Store_226: . array2: ()
-Sse2_Store_227: . array2: (<66, 56, 184, 20, 228, 16, 141, 35, 174, 186, 42, 75, 156, 29, 56, 110>)
-Sse2_Store_228: . array2: (<21, 186, 82, 120, 252, 42, 165, 83, 89, 127, 91, 41, 164, 226, 131, 91>)
-Sse2_Store_229: . array2: ()
-Sse2_Store_230: . array2: ()
-Sse2_StoreAligned_231: . array2: (<88, 151, 180, 106, 64, 107, 212, 36, 30, 113, 136, 60, 9, 52, 122, 99>)
-Sse2_StoreAligned_232: . array2: (<230, 220, 156, 17, 238, 140, 116, 98, 25, 209, 206, 34, 210, 128, 191, 39>)
-Sse2_StoreAligned_233: . array2: (<94, 50, 184, 106, 112, 183, 9, 15, 238, 235, 206, 126, 16, 245, 237, 21>)
-Sse2_StoreAligned_234: . array2: (<70, 255, 10, 176, 95, 53, 17, 165, 42, 36, 135, 211, 157, 201, 79, 187>)
-Sse2_StoreAligned_235: . array2: (<126, 69, 112, 12, 192, 218, 117, 81, 65, 61, 81, 65, 58, 102, 153, 31>)
-Sse2_StoreAligned_236: . array2: ()
-Sse2_StoreAligned_237: . array2: (<172, 114, 6, 101, 164, 156, 202, 79, 13, 12, 132, 107, 143, 185, 42, 16>)
-Sse2_StoreAligned_238: . array2: (<141, 73, 143, 71, 95, 77, 98, 97, 56, 4, 62, 49, 211, 195, 175, 75>)
-Sse2_StoreAligned_239: . array2: (<197365934, 1785457888>)
-Sse2_StoreAlignedNonTemporal_240: . array2: (<165, 74, 54, 189, 6, 179, 92, 193, 204, 212, 133, 179, 238, 167, 91, 137>)
-Sse2_StoreAlignedNonTemporal_241: . array2: (<227, 130, 78, 213, 121, 107, 223, 218, 55, 146, 69, 180, 80, 90, 20, 174>)
-Sse2_StoreAlignedNonTemporal_242: . array2: (<65, 206, 151, 81, 65, 231, 51, 81, 152, 188, 62, 25, 254, 45, 131, 99>)
-Sse2_StoreAlignedNonTemporal_243: . array2: (<240, 182, 61, 101, 14, 5, 13, 114, 24, 180, 10, 9, 173, 39, 88, 21>)
-Sse2_StoreAlignedNonTemporal_244: . array2: (<189, 198, 116, 82, 244, 2, 213, 43, 186, 149, 237, 26, 98, 171, 133, 35>)
-Sse2_StoreAlignedNonTemporal_245: . array2: (<171, 142, 164, 129, 207, 153, 231, 212, 166, 76, 109, 145, 151, 57, 79, 214>)
-Sse2_StoreAlignedNonTemporal_246: . array2: (<155, 88, 34, 11, 132, 38, 10, 85, 157, 88, 4, 34, 125, 161, 226, 0>)
-Sse2_StoreAlignedNonTemporal_247: . array2: ()
-Sse2_StoreAlignedNonTemporal_248: . array2: (<448427980, 160451659>)
-Sse2_StoreHigh_249: . array2: (<434912716, 0>)
-Sse2_StoreLow_250: . array2: (<2119419681, 0>)
-Sse2_StoreNonTemporal_251: . array2: (<183, 178, 255, 179, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>)
-Sse2_StoreNonTemporal_252: . array2: (<255, 104, 107, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>)
-Sse2_StoreScalar_253: . array2: ()
-Sse2_StoreScalar_254: . array2: (<77, 218, 255, 247, 122, 145, 210, 182, 0, 0, 0, 0, 0, 0, 0, 0>)
-Sse2_StoreScalar_255: . array2: (<173, 141, 34, 113, 223, 110, 135, 91, 0, 0, 0, 0, 0, 0, 0, 0>)
-Sse2_Subtract_256: <160, 230, 233, 215, 157, 62, 50, 132, 126, 224, 96, 124, 24, 75, 156, 27>. array2: ()
-Sse2_Subtract_257: <-73, -25, 74, 103, 80, -70, -44, 55, 30, -39, -89, 91, 37, 8, -85, -90>. array2: ()
-Sse2_Subtract_258: <21645, -29975, 1094, 17601, -13472, -9964, 11560, -24249>. array2: ()
-Sse2_Subtract_259: <26186, 3481, 38415, 7518, 17321, 4039, 44038, 26103>. array2: ()
-Sse2_Subtract_260: <1752063807, -2120203365, 1228453705, -2119657212>. array2: ()
-Sse2_Subtract_261: <3969082326, 2184163409, 4081145663, 4176352062>. array2: ()
-Sse2_Subtract_262: <-4910781699293484746, -3370418193084307290>. array2: ()
-Sse2_Subtract_263: <14342934063833242115, 17414808663155410193>. array2: ()
-Sse2_Subtract_264: <193503084, 843643408>. array2: ()
-Sse2_SubtractSaturate_265: <21, 1, 71, 127, -128, 68, 48, 127, -80, -19, 127, 105, 3, -128, 10, 53>. array2: ()
-Sse2_SubtractSaturate_266: <23654, 9415, -29015, -26904, -32768, -7444, 32767, -19469>. array2: ()
-Sse2_SubtractSaturate_267: <63, 171, 105, 0, 9, 0, 148, 1, 120, 0, 0, 45, 0, 59, 0, 39>. array2: ()
-Sse2_SubtractSaturate_268: <0, 0, 0, 0, 7195, 0, 0, 0>. array2: ()
-Sse2_SubtractScalar_269: <1970504049, 1505837714>. array2: ()
-Sse2_SumAbsoluteDifferences_270: <1022, 0, 0, 0, 992, 0, 0, 0>. array2: ()
-Sse2_UnpackHigh_271: <81, 59, 45, 174, 151, 115, 109, 178, 220, 64, 156, 107, 96, 28, 86, 177>. array2: ()
-Sse2_UnpackHigh_272: <4, -78, 15, 97, 85, -39, 70, 39, 85, -3, 114, 51, -86, 63, 19, 68>. array2: ()
-Sse2_UnpackHigh_273: <-24344, 10928, 20063, 8655, -23489, 23439, 12848, 27682>. array2: ()
-Sse2_UnpackHigh_274: <56624, 49657, 6555, 16770, 54792, 47497, 12329, 10935>. array2: ()
-Sse2_UnpackHigh_275: <-825727960, 1120004366, -1677873319, 440059928>. array2: ()
-Sse2_UnpackHigh_276: <3319442934, 996575506, 3072538177, 547440493>. array2: ()
-Sse2_UnpackHigh_277: <3425509541459654197, 0>. array2: ()
-Sse2_UnpackHigh_278: <9433075728538032088, 1802401848097591360>. array2: ()
-Sse2_UnpackHigh_279: <-1940783574, -88790362>. array2: ()
-Sse2_UnpackLow_280: <185, 20, 19, 134, 60, 169, 6, 226, 112, 116, 19, 133, 191, 30, 80, 223>. array2: ()
-Sse2_UnpackLow_281: <-24, -31, -112, -62, -57, 45, 120, -90, 17, 42, -63, 47, -83, -12, 1, -19>. array2: ()
-Sse2_UnpackLow_282: <12424, -6520, -32517, -20374, -22126, -7716, -15631, -8804>. array2: ()
-Sse2_UnpackLow_283: <55838, 34857, 45686, 46119, 7765, 50349, 47937, 63597>. array2: ()
-Sse2_UnpackLow_284: <1887548648, -106265407, 1948132023, -30817730>. array2: ()
-Sse2_UnpackLow_285: <1638019327, 1227734346, 291565234, 1511475018>. array2: ()
-Sse2_UnpackLow_286: <7967186738692185031, 6300179238364950333>. array2: ()
-Sse2_UnpackLow_287: <4302923488072565196, 1107715779998428353>. array2: ()
-Sse2_UnpackLow_288: <0, -1169211751>. array2: ()
-Sse2_Xor_289: <123, 176, 95, 128, 70, 47, 227, 174, 227, 215, 80, 165, 213, 114, 45, 254>. array2: ()
-Sse2_Xor_290: <12, 93, -36, -8, 125, 111, -58, -28, -48, 90, -44, -97, 7, -47, 41, -123>. array2: ()
-Sse2_Xor_291: <-29920, -4133, 13956, -16810, -24522, -15331, -17686, -32266>. array2: ()
-Sse2_Xor_292: <3063, 22132, 38842, 28704, 25905, 32058, 39706, 26936>. array2: ()
-Sse2_Xor_293: <755389418, 769245143, 76269295, 1263766898>. array2: ()
-Sse2_Xor_294: <2382442687, 3163532978, 2204809151, 4234290081>. array2: ()
-Sse2_Xor_295: <2709152929969082560, 6804690265923088076>. array2: ()
-Sse2_Xor_296: <10966841827685851620, 17485109639731884102>. array2: ()
-Sse2_Xor_297: <1.3179603345489727E-306, 2.7753908835538394E-306>. array2: ()
-Sse3_AddSubtract_0: <-288245800, 485282300, -148528380, 175195780>. array2: ()
-Sse3_AddSubtract_1: <377350428, 2880251686>. array2: ()
-Sse3_HorizontalAdd_3: <-1.4537478E+09, -608964740, 932101440, 317462530>. array2: ()
-Sse3_HorizontalAdd_4: <0, -1011215482>. array2: ()
-Sse3_HorizontalSubtract_5: <134859580, 290265800, -410409730, 225053500>. array2: ()
-Sse3_HorizontalSubtract_6: <-39981208, 772075022>. array2: ()
-Sse3_LoadAndDuplicateToVector128_7: <0, 0>. array2: ()
-Sse3_LoadDquVector128_10: <256, 770, 1284, 1798, 2312, 2826, 3340, 3854>. array2: ()
-Sse3_LoadDquVector128_11: <256, 770, 1284, 1798, 2312, 2826, 3340, 3854>. array2: ()
-Sse3_LoadDquVector128_12: <50462976, 117835012, 185207048, 252579084>. array2: ()
-Sse3_LoadDquVector128_13: <50462976, 117835012, 185207048, 252579084>. array2: ()
-Sse3_LoadDquVector128_14: <506097522914230528, 1084818905618843912>. array2: ()
-Sse3_LoadDquVector128_15: <506097522914230528, 1084818905618843912>. array2: ()
-Sse3_LoadDquVector128_8: <0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15>. array2: ()
-Sse3_LoadDquVector128_9: <0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15>. array2: ()
-Sse3_MoveAndDuplicate_16: <422894897, 422894897>. array2: ()
-Sse3_MoveHighAndDuplicate_17: <571501200, 571501200, 329727360, 329727360>. array2: ()
-Sse3_MoveLowAndDuplicate_18: <-189382530, -189382530, -201301700, -201301700>. array2: ()
-Sse41_Blend_0: <-28181, 8056, -26435, 1838, 18747, 5118, 1458, -6560>. array2: ()
-Sse41_Blend_1: <14880, 34662, 8325, 12447, 3177, 16199, 6880, 7815>. array2: ()
-Sse41_Blend_2: <491788830, 7742888, 361228860, 142832030>. array2: ()
-Sse41_Blend_3: <1824188881, -718259854>. array2: ()
-Sse41_BlendVariable_10: <-4986989475177804591, -3411647568405592666>. array2: ()
-Sse41_BlendVariable_11: <16427713610026539347, 17248869451145481562>. array2: ()
-Sse41_BlendVariable_12: <114734470, 113439390, 161092800, 334321300>. array2: ()
-Sse41_BlendVariable_13: <1271945793, 621651665>. array2: ()
-Sse41_BlendVariable_4: <-17, 87, 20, 53, 10, -33, 0, 65, 18, 7, 89, 73, -61, -105, -73, 48>. array2: ()
-Sse41_BlendVariable_5: <102, 26, 159, 80, 223, 125, 208, 80, 109, 87, 34, 5, 251, 3, 71, 85>. array2: ()
-Sse41_BlendVariable_6: <-31512, 848, -24102, 17728, 13830, 4091, 11118, 31413>. array2: ()
-Sse41_BlendVariable_7: <60928, 0, 6153, 5, 0, 13, 61440, 188>. array2: ()
-Sse41_BlendVariable_8: <1417959254, 237094035, 1139339792, 1710903878>. array2: ()
-Sse41_BlendVariable_9: <1936970067, 1287167484, 861093958, 1596488650>. array2: ()
-Sse41_Ceiling_14: <976807230, 387127940, 231049630, 95996256>. array2: ()
-Sse41_Ceiling_15: <-1271902475, -1320771022>. array2: ()
-Sse41_CeilingScalar_16: <596644776, 576770326>. array2: ()
-Sse41_CeilingScalar_17: <-996174700, -26349984, -199809980, -374892500>. array2: ()
-Sse41_CeilingScalar_18: <-1474400142, 1343022939>. array2: ()
-Sse41_CeilingScalar_19: <841868900, -645329300, -447306460, -27179420>. array2: ()
-Sse41_CompareEqual_20: <0, 0>. array2: ()
-Sse41_CompareEqual_21: <0, 0>. array2: ()
-Sse41_ConvertToVector128Int16_22: <-75, -56, 63, 60, -92, -10, -36, 7>. array2: ()
-Sse41_ConvertToVector128Int16_23: <242, 81, 177, 67, 109, 131, 246, 49>. array2: ()
-Sse41_ConvertToVector128Int16_24: <0, 1, 2, 3, 4, 5, 6, 7>. array2: ()
-Sse41_ConvertToVector128Int16_25: <0, 1, 2, 3, 4, 5, 6, 7>. array2: ()
-Sse41_ConvertToVector128Int32_26: <-58, 119, 104, -119>. array2: ()
-Sse41_ConvertToVector128Int32_27: <161, 95, 181, 45>. array2: ()
-Sse41_ConvertToVector128Int32_28: <-20353, -28133, -5483, -2632>. array2: ()
-Sse41_ConvertToVector128Int32_29: <58696, 60254, 11748, 60669>. array2: ()
-Sse41_ConvertToVector128Int32_30: <0, 1, 2, 3>. array2: ()
-Sse41_ConvertToVector128Int32_31: <0, 1, 2, 3>. array2: ()
-Sse41_ConvertToVector128Int32_32: <256, 770, 1284, 1798>. array2: ()
-Sse41_ConvertToVector128Int32_33: <256, 770, 1284, 1798>. array2: ()
-Sse41_ConvertToVector128Int64_34: <-89, -82>. array2: ()
-Sse41_ConvertToVector128Int64_35: <231, 107>. array2: ()
-Sse41_ConvertToVector128Int64_36: <18053, -15316>. array2: ()
-Sse41_ConvertToVector128Int64_37: <30546, 35535>. array2: ()
-Sse41_ConvertToVector128Int64_38: <2005088466, 1180082193>. array2: ()
-Sse41_ConvertToVector128Int64_39: <0, 0>. array2: ()
-Sse41_ConvertToVector128Int64_40: <0, 1>. array2: ()
-Sse41_ConvertToVector128Int64_41: <0, 1>. array2: ()
-Sse41_ConvertToVector128Int64_42: <256, 770>. array2: ()
-Sse41_ConvertToVector128Int64_43: <256, 770>. array2: ()
-Sse41_ConvertToVector128Int64_44: <50462976, 117835012>. array2: ()
-Sse41_ConvertToVector128Int64_45: <50462976, 117835012>. array2: ()
-Sse41_DotProduct_46: <0, 0, 0, 0>. array2: ()
-Sse41_DotProduct_47: <0, 0>. array2: ()
-Sse41_Extract_48: 0. array2: ()
-Sse41_Extract_49: 205898021. array2: ()
-Sse41_Extract_50: 2010097471. array2: ()
-Sse41_Extract_51: 443243500. array2: ()
-Sse41_Floor_52: <386100000, 207527100, 495481120, 19563034>. array2: ()
-Sse41_Floor_53: <1749484095, 254253946>. array2: ()
-Sse41_FloorScalar_54: <2105495297, 1615400991>. array2: ()
-Sse41_FloorScalar_55: <600926660, 470214500, 195817310, 346740700>. array2: ()
-Sse41_FloorScalar_56: <751097772, 0>. array2: ()
-Sse41_FloorScalar_57: <938370050, -39845504, -43406284, -151803180>. array2: ()
-Sse41_Insert_59: <-1, -27, 59, 87, -116, -128, -32, 82, 126, -109, -14, 83, -108, 61, 90, 39>. array2: ()
-Sse41_Insert_60: <50, 137, 132, 245, 172, 251, 139, 204, 26, 85, 175, 202, 195, 167, 175, 133>. array2: ()
-Sse41_Insert_61: <113469686, 366453791, -1696173006, 1426620191>. array2: ()
-Sse41_Insert_62: <3319556977, 1821918078, 2572121724, 2432579270>. array2: ()
-Sse41_Insert_63: <794284160, -10099458, 440350530, 106081200>. array2: ()
-Sse41_LoadAlignedVector128NonTemporal_64: <0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15>. array2: ()
-Sse41_LoadAlignedVector128NonTemporal_65: <0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15>. array2: ()
-Sse41_LoadAlignedVector128NonTemporal_66: <256, 770, 1284, 1798, 2312, 2826, 3340, 3854>. array2: ()
-Sse41_LoadAlignedVector128NonTemporal_67: <256, 770, 1284, 1798, 2312, 2826, 3340, 3854>. array2: ()
-Sse41_LoadAlignedVector128NonTemporal_68: <50462976, 117835012, 185207048, 252579084>. array2: ()
-Sse41_LoadAlignedVector128NonTemporal_69: <50462976, 117835012, 185207048, 252579084>. array2: ()
-Sse41_LoadAlignedVector128NonTemporal_70: <506097522914230528, 1084818905618843912>. array2: ()
-Sse41_LoadAlignedVector128NonTemporal_71: <506097522914230528, 1084818905618843912>. array2: ()
-Sse41_Max_72: <0, 62, 14, 0, 0, 23, 0, 0, 0, 44, 0, 0, 60, 0, 18, 0>. array2: ()
-Sse41_Max_73: <64529, 24246, 60292, 11349, 52920, 7767, 46095, 16553>. array2: ()
-Sse41_Max_74: <1468978862, 1260319873, 1553029212, 1159805043>. array2: ()
-Sse41_Max_75: <3303376326, 2933272066, 2724997452, 3968450988>. array2: ()
-Sse41_Min_76: <-24, -70, 89, 50, -41, -78, -86, 4, 4, 2, -54, 70, -63, -34, 67, 19>. array2: ()
-Sse41_Min_77: <19072, 10363, 7372, 16990, 17907, 25895, 25631, 8780>. array2: ()
-Sse41_Min_78: <227355155, 833264934, 182554724, 552275494>. array2: ()
-Sse41_Min_79: <1682696560, 1415080162, 1093433754, 1402296729>. array2: ()
-Sse41_MinHorizontal_80: <7625, 4, 0, 0, 0, 0, 0, 0>. array2: ()
-Sse41_MultipleSumAbsoluteDifferences_81: <510, 411, 458, 485, 446, 477, 418, 429>. array2: ()
-Sse41_Multiply_82: <0, 0>. array2: ()
-Sse41_MultiplyLow_83: <-444023120, -1604807418, -513618072, 364285130>. array2: ()
-Sse41_MultiplyLow_84: <2842399402, 3219790566, 82485812, 798265648>. array2: ()
-Sse41_PackUnsignedSaturate_85: <65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535>. array2: ()
-Sse41_RoundCurrentDirection_86: <1439949737, 982687573>. array2: ()
-Sse41_RoundCurrentDirection_87: <94789504, 306488300, 300036380, 200679310>. array2: ()
-Sse41_RoundCurrentDirectionScalar_88: <-514290506, -975606360>. array2: ()
-Sse41_RoundCurrentDirectionScalar_89: <-151982141, 1381285838>. array2: ()
-Sse41_RoundCurrentDirectionScalar_90: <1.0009005E+09, 82311576, 420004580, 377080260>. array2: ()
-Sse41_RoundCurrentDirectionScalar_91: <908986750, 0, 0, 0>. array2: ()
-Sse41_RoundToNearestInteger_92: <971570600, 342674340, 84637136, 279661020>. array2: ()
-Sse41_RoundToNearestInteger_93: <0, 0>. array2: ()
-Sse41_RoundToNearestIntegerScalar_94: <1503033702, 1356128743>. array2: ()
-Sse41_RoundToNearestIntegerScalar_95: <1958960619, 397956293>. array2: ()
-Sse41_RoundToNearestIntegerScalar_96: <115528456, 284659620, 172975940, 167663550>. array2: ()
-Sse41_RoundToNearestIntegerScalar_97: <-829306000, 0, 0, 0>. array2: ()
-Sse41_RoundToNegativeInfinity_98: <613514000, 556777100, 409394500, 70652570>. array2: ()
-Sse41_RoundToNegativeInfinity_99: <901160652, 699665279>. array2: ()
-Sse41_RoundToNegativeInfinityScalar_100: <0, 0>. array2: ()
-Sse41_RoundToNegativeInfinityScalar_101: <1083911923, -369574546>. array2: ()
-Sse41_RoundToNegativeInfinityScalar_102: <1.0058966E+09, 224250110, 97383590, 256521380>. array2: ()
-Sse41_RoundToNegativeInfinityScalar_103: <569111040, -706565950, -134511490, -170974940>. array2: ()
-Sse41_RoundToPositiveInfinity_104: <-1346950085, -1061512967>. array2: ()
-Sse41_RoundToPositiveInfinity_105: <-437554370, -688066100, -401424450, -24426856>. array2: ()
-Sse41_RoundToPositiveInfinityScalar_106: <1678875284, 1006413517>. array2: ()
-Sse41_RoundToPositiveInfinityScalar_107: <0, 1793942551>. array2: ()
-Sse41_RoundToPositiveInfinityScalar_108: <-949690750, -20584142, -125257490, -132031256>. array2: ()
-Sse41_RoundToPositiveInfinityScalar_109: <0, -7623213.5, -369909760, -333072740>. array2: ()
-Sse41_RoundToZero_110: <-164666379, -6857492>. array2: ()
-Sse41_RoundToZero_111: <-727772600, -644844740, -52200804, -334492600>. array2: ()
-Sse41_RoundToZeroScalar_112: <0, 0>. array2: ()
-Sse41_RoundToZeroScalar_113: <325755288, 284278557>. array2: ()
-Sse41_RoundToZeroScalar_114: <370526980, 450870270, 114232630, 101882510>. array2: ()
-Sse41_RoundToZeroScalar_115: <199417310, 575768600, 454732830, 146941410>. array2: ()
-Sse41_TestC_116: False. array2: ()
-Sse41_TestC_117: False. array2: ()
-Sse41_TestC_118: False. array2: ()
-Sse41_TestC_119: False. array2: ()
-Sse41_TestC_120: False. array2: ()
-Sse41_TestC_121: False. array2: ()
-Sse41_TestC_122: False. array2: ()
-Sse41_TestC_123: False. array2: ()
-Sse41_TestNotZAndNotC_124: True. array2: ()
-Sse41_TestNotZAndNotC_125: True. array2: ()
-Sse41_TestNotZAndNotC_126: True. array2: ()
-Sse41_TestNotZAndNotC_127: True. array2: ()
-Sse41_TestNotZAndNotC_128: True. array2: ()
-Sse41_TestNotZAndNotC_129: True. array2: ()
-Sse41_TestNotZAndNotC_130: False. array2: ()
-Sse41_TestNotZAndNotC_131: True. array2: ()
-Sse41_TestZ_132: False. array2: ()
-Sse41_TestZ_133: False. array2: ()
-Sse41_TestZ_134: True. array2: ()
-Sse41_TestZ_135: False. array2: ()
-Sse41_TestZ_136: False. array2: ()
-Sse41_TestZ_137: True. array2: ()
-Sse41_TestZ_138: True. array2: ()
-Sse41_TestZ_139: True. array2: ()
-Sse42_CompareGreaterThan_0: <-1, -1>. array2: ()
-Sse42_Crc32_1: 3048296493. array2: ()
-Sse42_Crc32_2: 720008765. array2: ()
-Sse42_Crc32_3: 1709792733. array2: ()
-Ssse3_Abs_0: <20, 123, 42, 117, 5, 108, 125, 122, 2, 74, 125, 98, 15, 83, 90, 120>. array2: ()
-Ssse3_Abs_1: <15049, 32579, 12411, 18332, 19344, 20844, 19247, 7169>. array2: ()
-Ssse3_Abs_2: <1289855926, 1521543026, 1209975474, 1048481122>. array2: ()
-Ssse3_AlignRight_10: <0, 0>. array2: ()
-Ssse3_AlignRight_3: <0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Ssse3_AlignRight_4: <0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Ssse3_AlignRight_5: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Ssse3_AlignRight_6: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Ssse3_AlignRight_7: <-588188473, -861861738, -970398219, 0>. array2: ()
-Ssse3_AlignRight_8: <0, 0, 0, 0>. array2: ()
-Ssse3_AlignRight_9: <0, 0>. array2: ()
-Ssse3_HorizontalAdd_12: <-28016, -14356, -25639, -6147, 29319, 31790, 19886, -11366>. array2: ()
-Ssse3_HorizontalAdd_13: <0, 0, 0, 0>. array2: ()
-Ssse3_HorizontalAddSaturate_14: <30343, 25832, 71, 3968, 25111, 5416, 13362, -27366>. array2: ()
-Ssse3_HorizontalSubtract_15: <-17693, -24059, 14090, 11294, -30328, 3313, -3245, -31852>. array2: ()
-Ssse3_HorizontalSubtract_16: <1423497201, 543575668, -141636812, 445982764>. array2: ()
-Ssse3_HorizontalSubtractSaturate_17: <-32768, -23864, -11719, -32768, -18996, -16034, 7266, -21252>. array2: ()
-Ssse3_MultiplyAddAdjacent_18: <-8018, -6804, 12098, -25160, 26653, -13540, 32767, 5758>. array2: ()
-Ssse3_MultiplyHighRoundScale_19: <0, 0, 0, 0, 0, 0, 0, 0>. array2: ()
-Ssse3_Shuffle_20: <41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41>. array2: ()
-Ssse3_Shuffle_21: <131, 180, 36, 211, 140, 71, 0, 36, 0, 0, 32, 252, 250, 5, 0, 245>. array2: ()
-Ssse3_Sign_22: <114, -57, 105, -103, -101, 43, -3, -94, -64, -80, -24, -55, 57, 70, -96, -85>. array2: ()
-Ssse3_Sign_23: <8146, 23251, -5348, 13795, 16285, 31796, -1712, 19564>. array2: ()
-Ssse3_Sign_24: <-1690542095, -1073268168, -1839363387, -426479517>. array2: ()
-Vector128_byte_to_int: <1881994049, -584023631, -1957556255, 1248354443>. array2: ()
-Vector128_Create_1: <37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37>. array2: ()
-Vector128_Create_10: <-112905214.5, -112905214.5>. array2: ()
-Vector128_Create_11: <1043346112.5, -989284283>. array2: ()
-Vector128_Create_12: <-1494540230, -1006562512>. array2: ()
-Vector128_Create_13: <1739630930, 18446744073526515366>. array2: ()
-Vector128_Create_14: <706899800, -723907460, -320707740, 634857800>. array2: ()
-Vector128_Create_15: <-1325323419, 815439320, -1175553948, -2143918760>. array2: ()
-Vector128_Create_16: <380379792, 702957838, 734971347, 975465225>. array2: ()
-Vector128_Create_17: <36832, 33999, 43142, 4384, 48727, 60061, 19158, 56428>. array2: ()
-Vector128_Create_18: <3028, -26498, -7017, -2304, -23167, 20218, 23682, 25060>. array2: ()
-Vector128_Create_2: <-48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48>. array2: ()
-Vector128_Create_20: <81, -49, 50, 110, -51, -100, -120, 55, -25, -37, -18, 47, 40, 62, 104, 42>. array2: ()
-Vector128_Create_3: <11289, 11289, 11289, 11289, 11289, 11289, 11289, 11289>. array2: ()
-Vector128_Create_4: <17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230>. array2: ()
-Vector128_Create_5: <1644952972, 1644952972, 1644952972, 1644952972>. array2: ()
-Vector128_Create_6: <687315921, 687315921, 687315921, 687315921>. array2: ()
-Vector128_Create_7: <-1945223177, -1945223177>. array2: ()
-Vector128_Create_8: <2012609464, 2012609464>. array2: ()
-Vector128_Create_9: <7037300, 7037300, 7037300, 7037300>. array2: ()
-Vector128_CreateScalarUnsafe_1: 50. array2: ()
-Vector128_CreateScalarUnsafe_2: 50. array2: ()
-Vector128_int_to_byte: <39, 29, 58, 30, 232, 148, 103, 159, 80, 53, 164, 98, 116, 134, 103, 206>. array2: ()
-Vector128_int_to_ulong: <15148853770521024483, 12898404362374625286>. array2: ()
diff --git a/netcore/tools/jitdiff/jitdiff.cs b/netcore/tools/jitdiff/jitdiff.cs
deleted file mode 100644
index 4daab1da58b..00000000000
--- a/netcore/tools/jitdiff/jitdiff.cs
+++ /dev/null
@@ -1,216 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text.RegularExpressions;
-using System.IO;
-using System.Linq;
-
-namespace JitDiffTools
-{
- class Program
- {
- static void Main (string [] args)
- {
- if (args?.Length != 2)
- {
- Console.WriteLine ("usage:\n\tjitdiff folder1 folder2");
- return;
- }
-
- string [] filesBefore = Directory.GetFiles (args [0], "*.dasm");
- string [] filesAfter = Directory.GetFiles (args [1], "*.dasm");
- var pairs = new List<Tuple<string, string>> ();
-
- foreach (string fileBefore in filesBefore)
- {
- string fileName = Path.GetFileName (fileBefore);
- string fileAfter = filesAfter.FirstOrDefault (f =>
- Path.GetFileName (f).Equals (fileName, StringComparison.InvariantCultureIgnoreCase));
-
- if (fileAfter != null)
- pairs.Add (new Tuple<string, string> (fileBefore, fileAfter));
- }
-
- long totalFileDiff = 0;
- Console.WriteLine ();
- foreach (var pair in pairs)
- {
- long sizeBefore = new FileInfo (pair.Item1).Length;
- long sizeAfter = new FileInfo (pair.Item2).Length;
- long diff = sizeAfter - sizeBefore;
- totalFileDiff += diff;
- if (diff != 0)
- Console.WriteLine ($"Total diff for {Path.GetFileName (pair.Item1)}: {diff} bytes");
- }
- if (totalFileDiff != 0)
- Console.WriteLine ($"Total diff for all files: {totalFileDiff} bytes");
-
- Console.WriteLine ("\n=====================\n= Per-method diffs (may take a while):\n=====================\n");
- foreach (var pair in pairs)
- {
- PrintDiffs (pair.Item1, pair.Item2);
- }
- Console.WriteLine ("Done.");
- }
-
- static void PrintDiffs (string fileBefore, string fileAfter)
- {
- List<DiffItem> diff = GetDiffs (fileBefore, fileAfter);
-
- int totalRegression = 0, totalImprovement = 0;
- int methodRegressed = 0, methodImproved = 0;
- foreach (var diffItem in diff.OrderByDescending (d => d.DiffPercentage))
- {
- if (diffItem.HasChanges)
- {
- Console.WriteLine (diffItem);
- if (diffItem.Diff > 0)
- {
- totalRegression += diffItem.Diff;
- methodRegressed++;
- }
- else
- {
- totalImprovement += diffItem.Diff;
- methodImproved++;
- }
- }
- }
-
- if (methodRegressed == 0 && methodImproved == 0)
- return;
-
- Console.WriteLine ("\n");
- Console.WriteLine (Path.GetFileNameWithoutExtension (fileBefore));
- Console.WriteLine ($"Methods \"regressed\": {methodRegressed}");
- Console.WriteLine ($"Methods \"improved\": {methodImproved}");
- Console.WriteLine ($"Total regression: {totalRegression} lines, Total improvement: {totalImprovement} lines.");
- Console.WriteLine ("\n");
- }
-
- static List<DiffItem> GetDiffs (string file1, string file2)
- {
- List<FunctionInfo> file1Functions = ParseFunctions (file1);
- List<FunctionInfo> file2Functions = ParseFunctions (file2);
-
- var diffItems = new List<DiffItem> (); // diffs
-
- foreach (FunctionInfo file1Function in file1Functions)
- {
- // SingleOrDefault to make sure functions are unique
- FunctionInfo file2Function = file2Functions.FirstOrDefault (f => f.Name == file1Function.Name);
- diffItems.Add (new DiffItem (file1Function, file2Function)); // file2Function can be null here - means function was removed in file2
- }
-
- foreach (FunctionInfo file2Function in file2Functions)
- {
- // SingleOrDefault to make sure functions are unique
- FunctionInfo file1Function = file1Functions.FirstOrDefault (f => f.Name == file2Function.Name);
- if (file1Function == null)
- diffItems.Add (new DiffItem (null, file2Function)); // function was added in file2
- }
-
- return diffItems;
- }
-
- static bool TryParseFunctionName (string str, out string name)
- {
- // depends on objdump, let's use the whole line as a name if it ends with `:`
- if (str.EndsWith (':'))
- {
- // Possible formats:
- // 1) func_name:
- // 2) p_%var%_func_name:
- // 3) %var% <func_name>:
- // 4) %var% <p_%var%_func_name>:
- name = Regex.Replace (str, @"\b([a-f0-9]+)\b", m => "");
- name = Regex.Replace (name, @"(p_\d+_)?", m => "");
- return true;
- }
- name = null;
- return false;
- }
-
- static List<FunctionInfo> ParseFunctions (string file)
- {
- string [] lines = File.ReadAllLines (file)
- .Select (l => l.Trim (' ', '\t', '\r', '\n'))
- .Where (l => !string.IsNullOrEmpty (l))
- .ToArray ();
-
- var result = new List<FunctionInfo> ();
- FunctionInfo current = null;
- foreach (string line in lines)
- {
- if (TryParseFunctionName (line, out string name))
- {
- current = new FunctionInfo (name);
- result.Add (current);
- }
- current?.Body.Add (line);
- }
- return result;
- }
- }
-
- public class FunctionInfo
- {
- public FunctionInfo (string name)
- {
- if (string.IsNullOrWhiteSpace (name))
- throw new ArgumentException ("Function name should not be empty", nameof (name));
- Name = name;
- }
-
- public string Name { get; }
-
- public List<string> Body { get; set; } = new List<string>();
-
- public override string ToString () => $"{Name} (lines:{Body?.Count})";
- }
-
- public class DiffItem
- {
- public DiffItem (FunctionInfo before, FunctionInfo after)
- {
- if (before == null && after == null)
- throw new ArgumentException ("Both Before and After can not be null at the same time");
- if (before != null && after != null && before.Name != after.Name)
- throw new ArgumentException ("After.Name != Before.Name");
- Before = before;
- After = after;
- Name = before != null ? before.Name : after.Name;
- }
-
- public string Name { get; }
-
- public FunctionInfo Before { get; }
-
- public FunctionInfo After { get; }
-
- public int Diff => CalculateBytes (After) - CalculateBytes (Before);
-
- static int CalculateBytes (FunctionInfo info)
- {
- // TODO: calculate bytes
- return info?.Body?.Count ?? 0;
- }
-
- public bool HasChanges => Diff != 0;
-
- public double DiffPercentage
- {
- get
- {
- int b = Before?.Body?.Count ?? 0;
- int a = (After?.Body?.Count ?? 0) * 100;
- if (a == 0 && b == 0)
- return 0;
- if (a > 0 && b == 0)
- return -100;
- return -(100 - a / b);
- }
- }
-
- public override string ToString () => $"Diff for {Name}: {Diff} lines ({DiffPercentage:F1}%)";
- }
-} \ No newline at end of file
diff --git a/netcore/tools/jitdiff/jitdiff.csproj b/netcore/tools/jitdiff/jitdiff.csproj
deleted file mode 100755
index 074afffcc18..00000000000
--- a/netcore/tools/jitdiff/jitdiff.csproj
+++ /dev/null
@@ -1,7 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <TargetFramework>netcoreapp5.0</TargetFramework>
- <EnableSourceControlManagerQueries>false</EnableSourceControlManagerQueries>
- </PropertyGroup>
-</Project>
diff --git a/netcore/xunit-summary.py b/netcore/xunit-summary.py
deleted file mode 100755
index 7c20c6e8d22..00000000000
--- a/netcore/xunit-summary.py
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/usr/bin/env python3
-
-import xml.etree.ElementTree as ET
-import os
-import glob
-import ntpath
-import sys
-
-if len(sys.argv) < 1:
- print("Usage: xunit-summary.py <path to xunit results (*.xml)>")
- sys.exit(1)
-test_dir = sys.argv [1]
-
-class AssemblyTestResults():
- def __init__(self, name, total, passed, failed, skipped, errors, time):
- self.name = name
- self.total = total
- self.passed = passed
- self.failed = failed + errors
- self.skipped = skipped
- self.time = time
-
-class TestInfo():
- def __init__(self, name, time):
- self.name = name
- self.time = time
-
-test_assemblies = []
-test_items = []
-
-for testfile in glob.glob(test_dir + "/*-xunit.xml"):
- assemblies = ET.parse(testfile).getroot()
- for assembly in assemblies:
- test_name = assembly.attrib.get("name")
- if test_name is None:
- print("WARNING: %s has no tests!" % ntpath.basename(testfile))
- continue
- test_assemblies.append(AssemblyTestResults(test_name,
- int(assembly.attrib["total"]),
- int(assembly.attrib["passed"]),
- int(assembly.attrib["failed"]),
- int(assembly.attrib["skipped"]),
- int(assembly.attrib["errors"]),
- float(assembly.attrib["time"])))
- for collection in assembly.iter("collection"):
- for test in collection.iter("test"):
- test_items.append(TestInfo(test.attrib["name"],
- float(test.attrib["time"])))
-
-test_assemblies.sort(key=lambda item: (item.failed, item.name), reverse=True)
-test_items.sort(key=lambda item: (item.time), reverse=True)
-
-print("")
-print("")
-print("=" * 105)
-for t in test_assemblies:
- #if t.failed > 0: # uncomment to list only test suits with failures
- print("{0:<60} Total:{1:<6} Failed:{2:<6} Time:{3} sec".format(t.name, t.total, t.failed, round(t.time, 1)))
-print("=" * 105)
-print("")
-print("Total test suites: %d" % len(test_assemblies))
-print("Total tests run: %d" % sum(x.total for x in test_assemblies))
-print("Total tests passed: %d" % sum(x.passed for x in test_assemblies))
-print("Total tests failed: %d" % sum(x.failed for x in test_assemblies))
-print("Total tests skipped: %d" % sum(x.skipped for x in test_assemblies))
-print("Total duration: %d min" % (sum(x.time for x in test_assemblies) / 60))
-print("")
-print("")
-print("Top 20 slowest tests:")
-print("=" * 105)
-for t in test_items[:20]:
- print("{0:<89} Time:{1} sec".format(t.name[:88], round(t.time, 1)))
-print("") \ No newline at end of file